Infrastructure for removing Categories and UnitCategory. Also, changed defensive structures to be in the same build-queue as normal structures. (mod it if you don't like it)

This commit is contained in:
Bob
2010-01-14 14:13:49 +13:00
parent b1d04d5737
commit 73f6d5c71c
10 changed files with 240 additions and 228 deletions

View File

@@ -8,15 +8,24 @@ namespace OpenRa.Game.GameRules
{
class NewUnitInfo
{
public readonly TypeDictionary Traits = new TypeDictionary();
public readonly string Name;
public readonly string Category;
public readonly TypeDictionary Traits = new TypeDictionary();
public NewUnitInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{
Name = name;
var mergedNode = MergeWithParent( node, allUnits ).Nodes;
foreach( var t in MergeWithParent( node, allUnits ).Nodes )
if( t.Key != "Inherits" )
Name = name;
MiniYaml categoryNode;
if( mergedNode.TryGetValue( "Category", out categoryNode ) )
Category = categoryNode.Value;
if( Rules.UnitCategory.ContainsKey( name ) && Category != Rules.UnitCategory[ name ] )
throw new NotImplementedException( "wrong category");
foreach( var t in mergedNode )
if( t.Key != "Inherits" && t.Key != "Category" )
Traits.Add( LoadTraitInfo( t.Key, t.Value ) );
}

View File

@@ -56,7 +56,6 @@ namespace OpenRa.Game
LoadCategories(
"Building",
"Defense",
"Infantry",
"Vehicle",
"Ship",

View File

@@ -11,9 +11,8 @@ namespace OpenRa.Game.GameRules
public TechTree()
{
foreach( var b in Rules.Categories[ "Building" ] )
foreach( var info in Rules.NewUnitInfo.Values )
{
var info = Rules.NewUnitInfo[ b ];
var pi = info.Traits.GetOrDefault<ProductionInfo>();
if (pi != null)
foreach( var p in pi.Produces )
@@ -51,19 +50,22 @@ namespace OpenRa.Game.GameRules
return false;
return true;
}
}
public IEnumerable<string> BuildableItems( Player player, params string[] categories )
{
var playerBuildings = GatherBuildings( player );
foreach( var unit in categories.SelectMany( x => Rules.Categories[ x ] ).Select( x => Rules.NewUnitInfo[ x ] ) )
foreach( var unit in AllBuildables( player, categories ) )
if( CanBuild( unit, player, playerBuildings ) )
yield return unit.Name;
}
public IEnumerable<string> AllItems(Player player, params string[] categories)
public IEnumerable<NewUnitInfo> AllBuildables(Player player, params string[] categories)
{
return categories.SelectMany(x => Rules.Categories[x]).Select(x => Rules.NewUnitInfo[x].Name);
return Rules.NewUnitInfo.Values
.Where( x => x.Name[ 0 ] != '^' )
.Where( x => categories.Contains( Rules.UnitCategory[ x.Name ] ) )
.Where( x => x.Traits.Contains<BuildableInfo>() );
}
public IEnumerable<NewUnitInfo> UnitBuiltAt( NewUnitInfo info )