diff --git a/OpenRA.Mods.RA/HackyAI.cs b/OpenRA.Mods.RA/HackyAI.cs index 75a8ccc88b..0930606016 100644 --- a/OpenRA.Mods.RA/HackyAI.cs +++ b/OpenRA.Mods.RA/HackyAI.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Traits; using XRandom = OpenRA.Thirdparty.Random; +using OpenRA.FileFormats; //TODO: @@ -31,7 +32,32 @@ using XRandom = OpenRA.Thirdparty.Random; namespace OpenRA.Mods.RA { - class HackyAIInfo : TraitInfo { } + class HackyAIInfo : ITraitInfo + { + [FieldLoader.LoadUsing( "LoadUnits" )] + public readonly Dictionary UnitsToBuild; + + [FieldLoader.LoadUsing( "LoadBuildings" )] + public readonly Dictionary BuildingFractions; + + static object LoadUnits( MiniYaml y ) + { + Dictionary ret = new Dictionary(); + foreach (var t in y.NodesDict["UnitsToBuild"].Nodes) + ret.Add(t.Key, (float)FieldLoader.GetValue("units", typeof(float), t.Value.Value)); + return ret; + } + + static object LoadBuildings( MiniYaml y ) + { + Dictionary ret = new Dictionary(); + foreach (var t in y.NodesDict["BuildingFractions"].Nodes) + ret.Add(t.Key, (float)FieldLoader.GetValue("units", typeof(float), t.Value.Value)); + return ret; + } + + public object Create(ActorInitializer init) { return new HackyAI(this); } + } /* a pile of hacks, which control a local player on the host. */ @@ -47,38 +73,12 @@ namespace OpenRA.Mods.RA World world { get { return p.PlayerActor.World; } } - Dictionary unitsToBuild = new Dictionary - { - {"e1", .0f}, - {"e2", .0f}, - {"e3", .0f}, - {"1tnk", .0f}, - {"2tnk", .0f}, - {"3tnk", .0f} - }; - - Dictionary buildingFractions = new Dictionary + readonly HackyAIInfo Info; + public HackyAI(HackyAIInfo Info) { - { "proc", .2f }, - { "barr", .05f }, - { "tent", .05f }, - { "weap", .05f }, - { "pbox", .05f }, - { "hbox", .05f }, - { "gun", .05f }, - { "tsla", .05f }, - { "ftur", .05f }, - { "agun", .01f }, - { "sam", .01f }, - { "atek", .01f }, - { "stek", .01f }, - { "silo", .05f }, - { "fix", .01f }, - //{ "hpad", .01f }, - //{ "afld", .01f }, - { "dome", .01f }, - }; - + this.Info = Info; + } + enum BuildState { ChooseItem, @@ -145,7 +145,7 @@ namespace OpenRA.Mods.RA .Select( a => a.Actor.Info.Name ).ToArray(); - foreach (var frac in buildingFractions) + foreach (var frac in Info.BuildingFractions) if (buildableThings.Any(b => b.Name == frac.Key)) if (myBuildings.Count(a => a == frac.Key) < frac.Value * myBuildings.Length) return Rules.Info[frac.Key]; @@ -160,7 +160,7 @@ namespace OpenRA.Mods.RA var myBuildings = p.World.Queries.OwnedBy[p].WithTrait() .Select(a => a.Actor.Info.Name).ToArray(); - foreach (var frac in buildingFractions) + foreach (var frac in Info.BuildingFractions) if (buildableThings.Any(b => b.Name == frac.Key)) if (myBuildings.Count(a => a == frac.Key) < frac.Value * myBuildings.Length) return Rules.Info[frac.Key]; @@ -369,7 +369,7 @@ namespace OpenRA.Mods.RA Boolean found = false; if (unit != null) { - foreach (var un in unitsToBuild) + foreach (var un in Info.UnitsToBuild) { if (un.Key == unit.Name) { diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index ca3116db82..b03b05132f 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -37,6 +37,34 @@ Player: ActorGroupProxy: DeveloperMode: HackyAI: + BuildingFractions: + proc: 20% + pyle: 5% + hand: 5% + weap: 5% + hq: 2% + afld: 5% + gtwr: 5% + gun: 5% + atwr: 5% + obli: 5% + sam: 1% + eye: 1% + tmpl: 1% + silo: 5% + fix: 1% + UnitsToBuild: + e1: 0% + e2: 0% + e3: 0% + e4: 0% + e5: 0% + bggy: 0% + bike: 0% + 1tnk: 0% + jeep: 0% + mtnk: 0% + arty: 0% PlayerColorPalette: BasePalette: terrain PaletteFormat: cnc diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index 0d0cb09c3a..71719fc0a9 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -98,6 +98,30 @@ Player: ActorGroupProxy: DeveloperMode: HackyAI: + BuildingFractions: + proc: 20% + barr: 5% + tent: 5% + weap: 5% + pbox: 5% + hbox: 5% + gun: 5% + tsla: 5% + ftur: 5% + agun: 1% + sam: 1% + atek: 1% + stek: 1% + silo: 5% + fix: 1% + dome: 1% + UnitsToBuild: + e1: 0% + e2: 0% + e3: 0% + 1tnk: 0% + 2tnk: 0% + 3tnk: 0% PlayerColorPalette: BasePalette: terrain