diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index 3f068e4db6..19d67f2cb9 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -82,7 +82,7 @@ namespace OpenRa.Game static Size powerSize = new Size(138,5); public Chrome(Renderer r) - { + { this.renderer = r; rgbaRenderer = new SpriteRenderer(renderer, true, renderer.RgbaSpriteShader); lineRenderer = new LineRenderer(renderer); @@ -110,12 +110,12 @@ namespace OpenRa.Game optionsBottomRight = SpriteSheetBuilder.LoadAllSprites("dd-crnr")[3]; optionsBackground = SpriteSheetBuilder.LoadAllSprites("dd-bkgnd")[Game.CosmeticRandom.Next(4)]; - tabSprites = groups - .SelectMany(g => Rules.Categories[g]) - .Where(u => Rules.NewUnitInfo[u].Traits.Contains()) + tabSprites = Rules.NewUnitInfo.Values + .Where(x => groups.Contains(x.Category)) + .Where(u => u.Traits.Contains()) .ToDictionary( - u => u, - u => SpriteSheetBuilder.LoadAllSprites(Rules.NewUnitInfo[u].Traits.Get().Icon ?? (u + "icon"))[0]); + u => u.Name, + u => SpriteSheetBuilder.LoadAllSprites(u.Traits.Get().Icon ?? (u.Name + "icon"))[0]); spsprites = Rules.SupportPowerInfo .ToDictionary( @@ -644,7 +644,7 @@ namespace OpenRa.Game void StartProduction( string item ) { - var group = Rules.UnitCategory[item]; + var group = Rules.NewUnitInfo[item].Category; Sound.Play((group == "Building") ? "abldgin1.aud" : "train1.aud"); Game.controller.AddOrder(Order.StartProduction(Game.LocalPlayer, item)); } @@ -652,7 +652,7 @@ namespace OpenRa.Game void HandleBuildPalette(string item, bool isLmb) { var player = Game.LocalPlayer; - var group = Rules.UnitCategory[item]; + var group = Rules.NewUnitInfo[item].Category; var queue = player.PlayerActor.traits.Get(); var producing = queue.AllItems(group).FirstOrDefault( a => a.Item == item ); diff --git a/OpenRa.Game/GameRules/NewUnitInfo.cs b/OpenRa.Game/GameRules/NewUnitInfo.cs index 3d0de8314c..e49b76ac82 100755 --- a/OpenRa.Game/GameRules/NewUnitInfo.cs +++ b/OpenRa.Game/GameRules/NewUnitInfo.cs @@ -21,9 +21,6 @@ namespace OpenRa.Game.GameRules 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 ) ); diff --git a/OpenRa.Game/GameRules/Rules.cs b/OpenRa.Game/GameRules/Rules.cs index 29f48cedcc..5271c9683c 100755 --- a/OpenRa.Game/GameRules/Rules.cs +++ b/OpenRa.Game/GameRules/Rules.cs @@ -12,7 +12,6 @@ namespace OpenRa.Game { public static IniFile AllRules; public static Dictionary> Categories = new Dictionary>(); - public static Dictionary UnitCategory; public static InfoLoader WeaponInfo; public static InfoLoader WarheadInfo; public static InfoLoader ProjectileInfo; @@ -54,14 +53,6 @@ namespace OpenRa.Game if (useAftermath) FieldLoader.Load(Aftermath, AllRules.GetSection("Aftermath")); - LoadCategories( - "Building", - "Infantry", - "Vehicle", - "Ship", - "Plane"); - UnitCategory = Categories.SelectMany(x => x.Value.Select(y => new KeyValuePair(y, x.Key))).ToDictionary(x => x.Key, x => x.Value); - LoadCategories( "Weapon", "Warhead", diff --git a/OpenRa.Game/GameRules/TechTree.cs b/OpenRa.Game/GameRules/TechTree.cs index ed6285aa32..4c1019c7ff 100755 --- a/OpenRa.Game/GameRules/TechTree.cs +++ b/OpenRa.Game/GameRules/TechTree.cs @@ -46,7 +46,7 @@ namespace OpenRa.Game.GameRules if( playerBuildings[ p ].Count == 0 ) 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 true; @@ -64,7 +64,7 @@ namespace OpenRa.Game.GameRules { return Rules.NewUnitInfo.Values .Where( x => x.Name[ 0 ] != '^' ) - .Where( x => categories.Contains( Rules.UnitCategory[ x.Name ] ) ) + .Where( x => categories.Contains( x.Category ) ) .Where( x => x.Traits.Contains() ); } @@ -74,7 +74,7 @@ namespace OpenRa.Game.GameRules if( builtAt.Length != 0 ) return builtAt.Select( x => Rules.NewUnitInfo[ x.ToLowerInvariant() ] ); else - return producesIndex[ Rules.UnitCategory[ info.Name ] ]; + return producesIndex[ info.Category ]; } } } diff --git a/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs b/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs index 1377bbc5ec..a2887ebcac 100644 --- a/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRa.Game/Orders/PlaceBuildingOrderGenerator.cs @@ -41,7 +41,7 @@ namespace OpenRa.Game.Orders public void Tick() { - var producing = Producer.traits.Get().CurrentItem( Rules.UnitCategory[ Building ] ); + var producing = Producer.traits.Get().CurrentItem( Rules.NewUnitInfo[ Building ].Category ); if (producing == null || producing.Item != Building || producing.RemainingTime != 0) Game.controller.CancelInputMode(); } diff --git a/OpenRa.Game/Orders/UnitOrders.cs b/OpenRa.Game/Orders/UnitOrders.cs index 177a48386b..8426610329 100644 --- a/OpenRa.Game/Orders/UnitOrders.cs +++ b/OpenRa.Game/Orders/UnitOrders.cs @@ -16,18 +16,19 @@ namespace OpenRa.Game.Orders Game.world.AddFrameEndTask( _ => { var queue = order.Player.PlayerActor.traits.Get(); - 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 ) return; - Game.world.Add( new Actor( order.TargetString, order.TargetLocation - Footprint.AdjustForBuildingSize( Rules.NewUnitInfo[ order.TargetString ].Traits.Get() ), order.Player ) ); + Game.world.Add( new Actor( order.TargetString, order.TargetLocation - Footprint.AdjustForBuildingSize( unit.Traits.Get() ), order.Player ) ); if (order.Player == Game.LocalPlayer) { Sound.Play("placbldg.aud"); Sound.Play("build5.aud"); } - queue.FinishProduction(Rules.UnitCategory[order.TargetString]); + queue.FinishProduction(unit.Category); } ); break; } diff --git a/OpenRa.Game/Traits/ProductionQueue.cs b/OpenRa.Game/Traits/ProductionQueue.cs index 7e31ef3918..a213a30154 100755 --- a/OpenRa.Game/Traits/ProductionQueue.cs +++ b/OpenRa.Game/Traits/ProductionQueue.cs @@ -33,7 +33,7 @@ namespace OpenRa.Game.Traits { case "StartProduction": { - string group = Rules.UnitCategory[ order.TargetString ]; + string group = Rules.NewUnitInfo[ order.TargetString ].Category; var ui = Rules.NewUnitInfo[ order.TargetString ].Traits.Get(); var time = ui.Cost * Rules.General.BuildSpeed /* todo: country-specific build speed bonus */ @@ -65,7 +65,7 @@ namespace OpenRa.Game.Traits } case "PauseProduction": { - var producing = CurrentItem( Rules.UnitCategory[ order.TargetString ] ); + var producing = CurrentItem( Rules.NewUnitInfo[ order.TargetString ].Category ); if( producing != null && producing.Item == order.TargetString ) producing.Paused = ( order.TargetLocation.X != 0 ); break; @@ -95,7 +95,7 @@ namespace OpenRa.Game.Traits public void CancelProduction( string itemName ) { - var category = Rules.UnitCategory[itemName]; + var category = Rules.NewUnitInfo[itemName].Category; var queue = production[ category ]; if (queue.Count == 0) return; @@ -160,12 +160,12 @@ namespace OpenRa.Game.Traits // Something went wrong somewhere... if( producer == null ) { - CancelProduction( Rules.UnitCategory[ name ] ); + CancelProduction( newUnitType.Category ); return; } if( producer.traits.WithInterface().Any( p => p.Produce( producer, newUnitType ) ) ) - FinishProduction( Rules.UnitCategory[ name ] ); + FinishProduction( newUnitType.Category ); } } }