Fix HackyAI in cnc

This commit is contained in:
Paul Chote
2010-10-16 11:49:27 +13:00
parent 5694c113be
commit b64dcbf502
3 changed files with 87 additions and 35 deletions

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
using XRandom = OpenRA.Thirdparty.Random; using XRandom = OpenRA.Thirdparty.Random;
using OpenRA.FileFormats;
//TODO: //TODO:
@@ -31,7 +32,32 @@ using XRandom = OpenRA.Thirdparty.Random;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class HackyAIInfo : TraitInfo<HackyAI> { } class HackyAIInfo : ITraitInfo
{
[FieldLoader.LoadUsing( "LoadUnits" )]
public readonly Dictionary<string, float> UnitsToBuild;
[FieldLoader.LoadUsing( "LoadBuildings" )]
public readonly Dictionary<string, float> BuildingFractions;
static object LoadUnits( MiniYaml y )
{
Dictionary<string,float> ret = new Dictionary<string, float>();
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<string,float> ret = new Dictionary<string, float>();
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. */ /* 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; } } World world { get { return p.PlayerActor.World; } }
Dictionary<string, float> unitsToBuild = new Dictionary<string, float> readonly HackyAIInfo Info;
{ public HackyAI(HackyAIInfo Info)
{"e1", .0f},
{"e2", .0f},
{"e3", .0f},
{"1tnk", .0f},
{"2tnk", .0f},
{"3tnk", .0f}
};
Dictionary<string, float> buildingFractions = new Dictionary<string, float>
{ {
{ "proc", .2f }, this.Info = Info;
{ "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 },
};
enum BuildState enum BuildState
{ {
ChooseItem, ChooseItem,
@@ -145,7 +145,7 @@ namespace OpenRA.Mods.RA
.Select( a => a.Actor.Info.Name ).ToArray(); .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 (buildableThings.Any(b => b.Name == frac.Key))
if (myBuildings.Count(a => a == frac.Key) < frac.Value * myBuildings.Length) if (myBuildings.Count(a => a == frac.Key) < frac.Value * myBuildings.Length)
return Rules.Info[frac.Key]; return Rules.Info[frac.Key];
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.RA
var myBuildings = p.World.Queries.OwnedBy[p].WithTrait<Building>() var myBuildings = p.World.Queries.OwnedBy[p].WithTrait<Building>()
.Select(a => a.Actor.Info.Name).ToArray(); .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 (buildableThings.Any(b => b.Name == frac.Key))
if (myBuildings.Count(a => a == frac.Key) < frac.Value * myBuildings.Length) if (myBuildings.Count(a => a == frac.Key) < frac.Value * myBuildings.Length)
return Rules.Info[frac.Key]; return Rules.Info[frac.Key];
@@ -369,7 +369,7 @@ namespace OpenRA.Mods.RA
Boolean found = false; Boolean found = false;
if (unit != null) if (unit != null)
{ {
foreach (var un in unitsToBuild) foreach (var un in Info.UnitsToBuild)
{ {
if (un.Key == unit.Name) if (un.Key == unit.Name)
{ {

View File

@@ -37,6 +37,34 @@ Player:
ActorGroupProxy: ActorGroupProxy:
DeveloperMode: DeveloperMode:
HackyAI: 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: PlayerColorPalette:
BasePalette: terrain BasePalette: terrain
PaletteFormat: cnc PaletteFormat: cnc

View File

@@ -98,6 +98,30 @@ Player:
ActorGroupProxy: ActorGroupProxy:
DeveloperMode: DeveloperMode:
HackyAI: 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: PlayerColorPalette:
BasePalette: terrain BasePalette: terrain