production/techtree starting to port

This commit is contained in:
Chris Forbes
2010-01-11 19:13:14 +13:00
parent 5faa1ea724
commit 66a1ab0e4e
6 changed files with 512 additions and 13 deletions

View File

@@ -90,14 +90,14 @@ namespace OpenRa.Game
SupportPowerInfo = new InfoLoader<SupportPowerInfo>(
Pair.New<string, Func<string, SupportPowerInfo>>("SupportPower", _ => new SupportPowerInfo()));
NewUnitInfo = new Dictionary<string, NewUnitInfo>();
foreach (var kv in MiniYaml.FromFile("ra.yaml"))
NewUnitInfo.Add(kv.Key.ToLowerInvariant(), new NewUnitInfo(kv.Key.ToLowerInvariant(), kv.Value));
TechTree = new TechTree();
Map = new Map( AllRules );
FileSystem.MountTemporary( new Package( Rules.Map.Theater + ".mix" ) );
TileSet = new TileSet( Map.TileSuffix );
NewUnitInfo = new Dictionary<string, NewUnitInfo>();
foreach( var kv in MiniYaml.FromFile( "ra.yaml" ) )
NewUnitInfo.Add(kv.Key.ToLowerInvariant(), new NewUnitInfo(kv.Key.ToLowerInvariant(), kv.Value));
}
static void LoadCategories(params string[] types)

View File

@@ -7,15 +7,17 @@ namespace OpenRa.Game.GameRules
{
class TechTree
{
readonly Cache<string, List<LegacyUnitInfo>> producesIndex = new Cache<string, List<LegacyUnitInfo>>( x => new List<LegacyUnitInfo>() );
readonly Cache<string, List<NewUnitInfo>> producesIndex = new Cache<string, List<NewUnitInfo>>(x => new List<NewUnitInfo>());
public TechTree()
{
foreach( var b in Rules.Categories[ "Building" ] )
{
var info = (LegacyBuildingInfo)Rules.UnitInfo[ b ];
foreach( var p in info.Produces )
producesIndex[ p ].Add( info );
var info = Rules.NewUnitInfo[ b ];
var pi = info.Traits.WithInterface<ProductionInfo>().FirstOrDefault();
if (pi != null)
foreach( var p in pi.Produces )
producesIndex[ p ].Add( info );
}
}
@@ -60,10 +62,10 @@ namespace OpenRa.Game.GameRules
.Where(x => Rules.UnitInfo[x].Owner.Contains(player.Race)); /* todo: fix for dual-race scenarios (captured buildings) */
}
public IEnumerable<LegacyUnitInfo> UnitBuiltAt( LegacyUnitInfo info )
public IEnumerable<NewUnitInfo> UnitBuiltAt( LegacyUnitInfo info )
{
if( info.BuiltAt.Length != 0 )
return info.BuiltAt.Select( x => Rules.UnitInfo[ x.ToLowerInvariant() ] );
return info.BuiltAt.Select( x => Rules.NewUnitInfo[ x.ToLowerInvariant() ] );
else
return producesIndex[ Rules.UnitCategory[ info.Name ] ];
}

View File

@@ -7,6 +7,7 @@ namespace OpenRa.Game.Traits
class ProductionInfo : ITraitInfo
{
public readonly int[] SpawnOffset = null;
public readonly string[] Produces = { };
public object Create(Actor self) { return new Production(self); }
}

View File

@@ -133,7 +133,7 @@ namespace OpenRa.Game.Traits
// Prioritise primary structure in build order
var primaryProducers = Game.world.Actors
.Where(x => x.traits.Contains<Production>()
&& producerTypes.Contains(x.LegacyInfo)
&& producerTypes.Contains(x.Info)
&& x.Owner == self.Owner
&& x.traits.Get<Production>().IsPrimary == true);
@@ -153,7 +153,7 @@ namespace OpenRa.Game.Traits
if (producer == null)
{
producer = Game.world.Actors
.Where( x => producerTypes.Contains( x.LegacyInfo ) && x.Owner == self.Owner )
.Where( x => producerTypes.Contains( x.Info ) && x.Owner == self.Owner )
.FirstOrDefault();
}