Category dies in a fire

This commit is contained in:
Paul Chote
2010-08-27 00:32:00 +12:00
parent cedfeab63c
commit 226fd167e7
11 changed files with 58 additions and 60 deletions

View File

@@ -19,7 +19,6 @@ namespace OpenRA
public class ActorInfo
{
public readonly string Name;
public readonly string Category;
public readonly TypeDictionary Traits = new TypeDictionary();
public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
@@ -27,12 +26,8 @@ namespace OpenRA
var mergedNode = MergeWithParent( node, allUnits ).Nodes;
Name = name;
MiniYaml categoryNode;
if( mergedNode.TryGetValue( "Category", out categoryNode ) )
Category = categoryNode.Value;
foreach( var t in mergedNode )
if( t.Key != "Inherits" && t.Key != "Category" && !t.Key.StartsWith("-") )
if( t.Key != "Inherits" && !t.Key.StartsWith("-") )
Traits.Add( LoadTraitInfo( t.Key.Split('@')[0], t.Value ) );
}

View File

@@ -50,10 +50,5 @@ namespace OpenRA
var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(dict,MiniYaml.Merge);
return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, y));
}
public static IEnumerable<string> Categories()
{
return Info.Values.Select( x => x.Category ).Distinct().Where( g => g != null ).ToList();
}
}
}

View File

@@ -62,7 +62,7 @@ namespace OpenRA.GameRules
if( playerBuildings[ p ].Count == 0 )
return false;
if( producesIndex[ info.Category ].All( x => playerBuildings[ x.Name ].Count == 0 ) )
if( producesIndex[ bi.Queue ].All( x => playerBuildings[ x.Name ].Count == 0 ) )
return false;
return true;
@@ -83,17 +83,18 @@ namespace OpenRA.GameRules
{
return Rules.Info.Values
.Where( x => x.Name[ 0 ] != '^' )
.Where( x => categories.Contains( x.Category ) )
.Where( x => x.Traits.Contains<BuildableInfo>() );
.Where( x => x.Traits.Contains<BuildableInfo>() )
.Where( x => categories.Contains(x.Traits.Get<BuildableInfo>().Queue) );
}
public IEnumerable<ActorInfo> UnitBuiltAt( ActorInfo info )
{
var builtAt = info.Traits.Get<BuildableInfo>().BuiltAt;
var bi = info.Traits.Get<BuildableInfo>();
var builtAt = bi.BuiltAt;
if( builtAt.Length != 0 )
return builtAt.Select( x => Rules.Info[ x.ToLowerInvariant() ] );
else
return producesIndex[ info.Category ];
return producesIndex[ bi.Queue ];
}
}
}

View File

@@ -33,6 +33,8 @@ namespace OpenRA.Traits
public readonly string[] BuiltAt = { };
public readonly string[] Owner = { };
public readonly string Queue;
// todo: UI fluff; doesn't belong here
public readonly int BuildPaletteOrder = 9999;

View File

@@ -85,8 +85,12 @@ namespace OpenRA.Traits
// finds a construction yard (or equivalent) and runs its "build" animation.
static void PlayBuildAnim( Actor self, ActorInfo unit )
{
var bi = unit.Traits.GetOrDefault<BuildableInfo>();
if (bi == null)
return;
var producers = self.World.Queries.OwnedBy[ self.Owner ].WithTrait<Production>()
.Where( x => x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains( unit.Category ) )
.Where( x => x.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains( bi.Queue ) )
.ToList();
var producer = producers.Where( x => x.Actor.IsPrimaryBuilding() ).Concat( producers )
.FirstOrDefault();
@@ -98,7 +102,11 @@ namespace OpenRA.Traits
static int GetNumBuildables(Player p)
{
if (p != p.World.LocalPlayer) return 0; // this only matters for local players.
return Rules.TechTree.BuildableItems(p, Rules.Categories().ToArray()).Count();
// todo: this will simplify once queues know about what they can build
var queues = p.World.Queries.WithTraitMultiple<ProductionQueue>().Where(a => a.Actor.Owner == p)
.Select(a => a.Trait.Info.Type).Distinct().ToArray();
return Rules.TechTree.BuildableItems(p, queues).Count();
}
}
}

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Traits
return Producing.ElementAtOrDefault(0);
}
public IEnumerable<ProductionItem> AllItems()
public IEnumerable<ProductionItem> AllQueued()
{
return Producing;
}
@@ -64,13 +64,14 @@ namespace OpenRA.Traits
case "StartProduction":
{
var unit = Rules.Info[order.TargetString];
if (unit.Category != Info.Type)
var bi = unit.Traits.Get<BuildableInfo>();
if (bi.Queue != Info.Type)
return; /* Not built by this queue */
var cost = unit.Traits.Contains<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0;
var time = GetBuildTime(order.TargetString);
if (!Rules.TechTree.BuildableItems(order.Player, unit.Category).Contains(order.TargetString))
if (!Rules.TechTree.BuildableItems(order.Player, bi.Queue).Contains(order.TargetString))
return; /* you can't build that!! */
bool hasPlayedSound = false;
@@ -96,9 +97,6 @@ namespace OpenRA.Traits
}
case "PauseProduction":
{
if (Rules.Info[ order.TargetString ].Category != Info.Type)
return; /* Not built by this queue */
if( Producing.Count > 0 && Producing[0].Item == order.TargetString )
Producing[0].Paused = ( order.TargetLocation.X != 0 );
break;
@@ -127,10 +125,8 @@ namespace OpenRA.Traits
}
void CancelProduction( string itemName )
{
var category = Rules.Info[itemName].Category;
if (category != Info.Type || Producing.Count == 0)
{
if (Producing.Count == 0)
return; // Nothing to do here
var lastIndex = Producing.FindLastIndex( a => a.Item == itemName );