removed UnitCategory. removed the last unit-based use of Categories (Categories is still used for weapons)

This commit is contained in:
Bob
2010-01-14 14:30:51 +13:00
parent 73f6d5c71c
commit 8aae1ff7d5
7 changed files with 21 additions and 32 deletions

View File

@@ -82,7 +82,7 @@ namespace OpenRa.Game
static Size powerSize = new Size(138,5); static Size powerSize = new Size(138,5);
public Chrome(Renderer r) public Chrome(Renderer r)
{ {
this.renderer = r; this.renderer = r;
rgbaRenderer = new SpriteRenderer(renderer, true, renderer.RgbaSpriteShader); rgbaRenderer = new SpriteRenderer(renderer, true, renderer.RgbaSpriteShader);
lineRenderer = new LineRenderer(renderer); lineRenderer = new LineRenderer(renderer);
@@ -110,12 +110,12 @@ namespace OpenRa.Game
optionsBottomRight = SpriteSheetBuilder.LoadAllSprites("dd-crnr")[3]; optionsBottomRight = SpriteSheetBuilder.LoadAllSprites("dd-crnr")[3];
optionsBackground = SpriteSheetBuilder.LoadAllSprites("dd-bkgnd")[Game.CosmeticRandom.Next(4)]; optionsBackground = SpriteSheetBuilder.LoadAllSprites("dd-bkgnd")[Game.CosmeticRandom.Next(4)];
tabSprites = groups tabSprites = Rules.NewUnitInfo.Values
.SelectMany(g => Rules.Categories[g]) .Where(x => groups.Contains(x.Category))
.Where(u => Rules.NewUnitInfo[u].Traits.Contains<BuildableInfo>()) .Where(u => u.Traits.Contains<BuildableInfo>())
.ToDictionary( .ToDictionary(
u => u, u => u.Name,
u => SpriteSheetBuilder.LoadAllSprites(Rules.NewUnitInfo[u].Traits.Get<BuildableInfo>().Icon ?? (u + "icon"))[0]); u => SpriteSheetBuilder.LoadAllSprites(u.Traits.Get<BuildableInfo>().Icon ?? (u.Name + "icon"))[0]);
spsprites = Rules.SupportPowerInfo spsprites = Rules.SupportPowerInfo
.ToDictionary( .ToDictionary(
@@ -644,7 +644,7 @@ namespace OpenRa.Game
void StartProduction( string item ) void StartProduction( string item )
{ {
var group = Rules.UnitCategory[item]; var group = Rules.NewUnitInfo[item].Category;
Sound.Play((group == "Building") ? "abldgin1.aud" : "train1.aud"); Sound.Play((group == "Building") ? "abldgin1.aud" : "train1.aud");
Game.controller.AddOrder(Order.StartProduction(Game.LocalPlayer, item)); Game.controller.AddOrder(Order.StartProduction(Game.LocalPlayer, item));
} }
@@ -652,7 +652,7 @@ namespace OpenRa.Game
void HandleBuildPalette(string item, bool isLmb) void HandleBuildPalette(string item, bool isLmb)
{ {
var player = Game.LocalPlayer; var player = Game.LocalPlayer;
var group = Rules.UnitCategory[item]; var group = Rules.NewUnitInfo[item].Category;
var queue = player.PlayerActor.traits.Get<Traits.ProductionQueue>(); var queue = player.PlayerActor.traits.Get<Traits.ProductionQueue>();
var producing = queue.AllItems(group).FirstOrDefault( a => a.Item == item ); var producing = queue.AllItems(group).FirstOrDefault( a => a.Item == item );

View File

@@ -21,9 +21,6 @@ namespace OpenRa.Game.GameRules
if( mergedNode.TryGetValue( "Category", out categoryNode ) ) if( mergedNode.TryGetValue( "Category", out categoryNode ) )
Category = categoryNode.Value; Category = categoryNode.Value;
if( Rules.UnitCategory.ContainsKey( name ) && Category != Rules.UnitCategory[ name ] )
throw new NotImplementedException( "wrong category");
foreach( var t in mergedNode ) foreach( var t in mergedNode )
if( t.Key != "Inherits" && t.Key != "Category" ) if( t.Key != "Inherits" && t.Key != "Category" )
Traits.Add( LoadTraitInfo( t.Key, t.Value ) ); Traits.Add( LoadTraitInfo( t.Key, t.Value ) );

View File

@@ -12,7 +12,6 @@ namespace OpenRa.Game
{ {
public static IniFile AllRules; public static IniFile AllRules;
public static Dictionary<string, List<string>> Categories = new Dictionary<string, List<string>>(); public static Dictionary<string, List<string>> Categories = new Dictionary<string, List<string>>();
public static Dictionary<string, string> UnitCategory;
public static InfoLoader<WeaponInfo> WeaponInfo; public static InfoLoader<WeaponInfo> WeaponInfo;
public static InfoLoader<WarheadInfo> WarheadInfo; public static InfoLoader<WarheadInfo> WarheadInfo;
public static InfoLoader<ProjectileInfo> ProjectileInfo; public static InfoLoader<ProjectileInfo> ProjectileInfo;
@@ -54,14 +53,6 @@ namespace OpenRa.Game
if (useAftermath) if (useAftermath)
FieldLoader.Load(Aftermath, AllRules.GetSection("Aftermath")); FieldLoader.Load(Aftermath, AllRules.GetSection("Aftermath"));
LoadCategories(
"Building",
"Infantry",
"Vehicle",
"Ship",
"Plane");
UnitCategory = Categories.SelectMany(x => x.Value.Select(y => new KeyValuePair<string, string>(y, x.Key))).ToDictionary(x => x.Key, x => x.Value);
LoadCategories( LoadCategories(
"Weapon", "Weapon",
"Warhead", "Warhead",

View File

@@ -46,7 +46,7 @@ namespace OpenRa.Game.GameRules
if( playerBuildings[ p ].Count == 0 ) if( playerBuildings[ p ].Count == 0 )
return false; return false;
if( producesIndex[ Rules.UnitCategory[ info.Name ] ].All( x => playerBuildings[ x.Name ].Count == 0 ) ) if( producesIndex[ info.Category ].All( x => playerBuildings[ x.Name ].Count == 0 ) )
return false; return false;
return true; return true;
@@ -64,7 +64,7 @@ namespace OpenRa.Game.GameRules
{ {
return Rules.NewUnitInfo.Values return Rules.NewUnitInfo.Values
.Where( x => x.Name[ 0 ] != '^' ) .Where( x => x.Name[ 0 ] != '^' )
.Where( x => categories.Contains( Rules.UnitCategory[ x.Name ] ) ) .Where( x => categories.Contains( x.Category ) )
.Where( x => x.Traits.Contains<BuildableInfo>() ); .Where( x => x.Traits.Contains<BuildableInfo>() );
} }
@@ -74,7 +74,7 @@ namespace OpenRa.Game.GameRules
if( builtAt.Length != 0 ) if( builtAt.Length != 0 )
return builtAt.Select( x => Rules.NewUnitInfo[ x.ToLowerInvariant() ] ); return builtAt.Select( x => Rules.NewUnitInfo[ x.ToLowerInvariant() ] );
else else
return producesIndex[ Rules.UnitCategory[ info.Name ] ]; return producesIndex[ info.Category ];
} }
} }
} }

View File

@@ -41,7 +41,7 @@ namespace OpenRa.Game.Orders
public void Tick() public void Tick()
{ {
var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.UnitCategory[ Building ] ); var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem( Rules.NewUnitInfo[ Building ].Category );
if (producing == null || producing.Item != Building || producing.RemainingTime != 0) if (producing == null || producing.Item != Building || producing.RemainingTime != 0)
Game.controller.CancelInputMode(); Game.controller.CancelInputMode();
} }

View File

@@ -16,18 +16,19 @@ namespace OpenRa.Game.Orders
Game.world.AddFrameEndTask( _ => Game.world.AddFrameEndTask( _ =>
{ {
var queue = order.Player.PlayerActor.traits.Get<ProductionQueue>(); var queue = order.Player.PlayerActor.traits.Get<ProductionQueue>();
var producing = queue.CurrentItem(Rules.UnitCategory[order.TargetString]); var unit = Rules.NewUnitInfo[ order.TargetString ];
var producing = queue.CurrentItem(unit.Category);
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 ) if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
return; return;
Game.world.Add( new Actor( order.TargetString, order.TargetLocation - Footprint.AdjustForBuildingSize( Rules.NewUnitInfo[ order.TargetString ].Traits.Get<BuildingInfo>() ), order.Player ) ); Game.world.Add( new Actor( order.TargetString, order.TargetLocation - Footprint.AdjustForBuildingSize( unit.Traits.Get<BuildingInfo>() ), order.Player ) );
if (order.Player == Game.LocalPlayer) if (order.Player == Game.LocalPlayer)
{ {
Sound.Play("placbldg.aud"); Sound.Play("placbldg.aud");
Sound.Play("build5.aud"); Sound.Play("build5.aud");
} }
queue.FinishProduction(Rules.UnitCategory[order.TargetString]); queue.FinishProduction(unit.Category);
} ); } );
break; break;
} }

View File

@@ -33,7 +33,7 @@ namespace OpenRa.Game.Traits
{ {
case "StartProduction": case "StartProduction":
{ {
string group = Rules.UnitCategory[ order.TargetString ]; string group = Rules.NewUnitInfo[ order.TargetString ].Category;
var ui = Rules.NewUnitInfo[ order.TargetString ].Traits.Get<BuildableInfo>(); var ui = Rules.NewUnitInfo[ order.TargetString ].Traits.Get<BuildableInfo>();
var time = ui.Cost var time = ui.Cost
* Rules.General.BuildSpeed /* todo: country-specific build speed bonus */ * Rules.General.BuildSpeed /* todo: country-specific build speed bonus */
@@ -65,7 +65,7 @@ namespace OpenRa.Game.Traits
} }
case "PauseProduction": case "PauseProduction":
{ {
var producing = CurrentItem( Rules.UnitCategory[ order.TargetString ] ); var producing = CurrentItem( Rules.NewUnitInfo[ order.TargetString ].Category );
if( producing != null && producing.Item == order.TargetString ) if( producing != null && producing.Item == order.TargetString )
producing.Paused = ( order.TargetLocation.X != 0 ); producing.Paused = ( order.TargetLocation.X != 0 );
break; break;
@@ -95,7 +95,7 @@ namespace OpenRa.Game.Traits
public void CancelProduction( string itemName ) public void CancelProduction( string itemName )
{ {
var category = Rules.UnitCategory[itemName]; var category = Rules.NewUnitInfo[itemName].Category;
var queue = production[ category ]; var queue = production[ category ];
if (queue.Count == 0) return; if (queue.Count == 0) return;
@@ -160,12 +160,12 @@ namespace OpenRa.Game.Traits
// Something went wrong somewhere... // Something went wrong somewhere...
if( producer == null ) if( producer == null )
{ {
CancelProduction( Rules.UnitCategory[ name ] ); CancelProduction( newUnitType.Category );
return; return;
} }
if( producer.traits.WithInterface<IProducer>().Any( p => p.Produce( producer, newUnitType ) ) ) if( producer.traits.WithInterface<IProducer>().Any( p => p.Produce( producer, newUnitType ) ) )
FinishProduction( Rules.UnitCategory[ name ] ); FinishProduction( newUnitType.Category );
} }
} }
} }