diff --git a/OpenRa.Game/GameRules/InfoLoader.cs b/OpenRa.Game/GameRules/InfoLoader.cs index 7e4cf6931a..8ce668a69c 100644 --- a/OpenRa.Game/GameRules/InfoLoader.cs +++ b/OpenRa.Game/GameRules/InfoLoader.cs @@ -15,9 +15,8 @@ namespace OpenRa.Game.GameRules public InfoLoader(params Pair>[] srcs) { foreach (var src in srcs) - foreach (var s in Rules.AllRules.GetSection(src.First)) + foreach (var name in Rules.Categories[src.First]) { - var name = s.Key.ToLowerInvariant(); var t = src.Second(name); FieldLoader.Load(t, Rules.AllRules.GetSection(name)); infos[name] = t; diff --git a/OpenRa.Game/GameRules/Rules.cs b/OpenRa.Game/GameRules/Rules.cs index bb36ee500f..cc98ade92f 100755 --- a/OpenRa.Game/GameRules/Rules.cs +++ b/OpenRa.Game/GameRules/Rules.cs @@ -10,6 +10,7 @@ namespace OpenRa.Game static class Rules { public static IniFile AllRules; + public static Dictionary> Categories; public static InfoLoader UnitInfo; public static InfoLoader WeaponInfo; public static InfoLoader WarheadInfo; @@ -23,6 +24,16 @@ namespace OpenRa.Game FileSystem.Open( "units.ini" ), FileSystem.Open( "campaignUnits.ini" ) ); + Categories = LoadCategories( + "BuildingTypes", + "InfantryTypes", + "VehicleTypes", + "ShipTypes", + "PlaneTypes", + "WeaponTypes", + "WarheadTypes", + "ProjectileTypes" ); + UnitInfo = new InfoLoader( Pair.New>( "BuildingTypes", s => new UnitInfo.BuildingInfo(s)), Pair.New>( "InfantryTypes", s => new UnitInfo.InfantryInfo(s)), @@ -38,5 +49,14 @@ namespace OpenRa.Game ProjectileInfo = new InfoLoader( Pair.New>("ProjectileTypes", _ => new ProjectileInfo())); } + + static Dictionary> LoadCategories( params string[] types ) + { + var ret = new Dictionary>(); + foreach( var t in types ) + ret[ t ] = AllRules.GetSection( t ).Select( x => x.Key.ToLowerInvariant() ).ToList(); + + return ret; + } } } diff --git a/OpenRa.Game/Player.cs b/OpenRa.Game/Player.cs index 7193edd52a..117635cd82 100644 --- a/OpenRa.Game/Player.cs +++ b/OpenRa.Game/Player.cs @@ -43,7 +43,7 @@ namespace OpenRa.Game } } - // Key: Production category. Categories are: building, infantry, vehicle, ship, plane (and one per super, if they're done in here) + // Key: Production category. Categories are: Building, Infantry, Vehicle, Ship, Plane (and one per super, if they're done in here) readonly Dictionary production = new Dictionary(); public void ProductionInit( string category ) diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 74550b8f35..881d2df6b8 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -25,7 +25,7 @@ namespace OpenRa.Game Dictionary sprites = new Dictionary(); const int spriteWidth = 64, spriteHeight = 48; - static string[] groups = new string[] { "building", "vehicle", "ship", "infantry", "plane" }; + static string[] groups = new string[] { "Building", "Vehicle", "Ship", "Infantry", "Plane" }; Dictionary itemGroups = new Dictionary(); //item->group Dictionary clockAnimations = new Dictionary(); //group->clockAnimation @@ -41,11 +41,8 @@ namespace OpenRa.Game spriteRenderer = new SpriteRenderer(renderer, false); clockRenderer = new SpriteRenderer(renderer, true); - LoadSprites( "BuildingTypes", "building" ); - LoadSprites( "VehicleTypes", "vehicle" ); - LoadSprites( "InfantryTypes", "infantry" ); - LoadSprites( "ShipTypes", "ship" ); - LoadSprites( "PlaneTypes", "plane" ); + for( int i = 0 ; i < groups.Length ; i++ ) + LoadSprites( groups[ i ] ); foreach (string group in groups) { @@ -79,11 +76,11 @@ namespace OpenRa.Game Game.controller.AddOrder(Order.BuildUnit(player, item.techTreeItem.tag.ToLowerInvariant())); } - void LoadSprites( string category, string group ) + void LoadSprites( string group ) { - foreach( var u in Rules.AllRules.GetSection( category ) ) + foreach( var u in Rules.Categories[ group + "Types" ] ) { - var unit = Rules.UnitInfo[ u.Key ]; + var unit = Rules.UnitInfo[ u ]; if( unit.TechLevel != -1 ) sprites.Add( unit.Name, SpriteSheetBuilder.LoadSprite( unit.Name + "icon", ".shp" ) ); diff --git a/OpenRa.Game/TechTree/Item.cs b/OpenRa.Game/TechTree/Item.cs index 3b56fc23e1..d7443157a8 100755 --- a/OpenRa.Game/TechTree/Item.cs +++ b/OpenRa.Game/TechTree/Item.cs @@ -4,6 +4,7 @@ using System.Linq; using OpenRa.FileFormats; using OpenRa.Game.GameRules; using IjwFramework.Types; +using OpenRa.Game; namespace OpenRa.TechTree { @@ -49,11 +50,10 @@ namespace OpenRa.TechTree if (soviet.Remove("tent")) soviet.Add("barr"); if (allied.Remove("barr")) allied.Add("tent"); - // TODO: rewrite this based on "InfantryTypes" in units.ini - if ((tag.Length == 2 && tag[0] == 'e') || tag == "medi" || tag == "thf" || tag == "spy") + if( Rules.Categories[ "InfantryTypes" ].Contains( tag ) ) { - if (!allied.Contains("tent")) allied.Add("tent"); - if (!soviet.Contains("barr")) soviet.Add("barr"); + if( !allied.Contains( "tent" ) ) allied.Add( "tent" ); + if( !soviet.Contains( "barr" ) ) soviet.Add( "barr" ); } if (tag == "lst") diff --git a/OpenRa.Game/TechTree/TechTree.cs b/OpenRa.Game/TechTree/TechTree.cs index 884037a1fc..0d424e9de9 100644 --- a/OpenRa.Game/TechTree/TechTree.cs +++ b/OpenRa.Game/TechTree/TechTree.cs @@ -34,7 +34,7 @@ namespace OpenRa.TechTree void LoadRules() { - var allBuildings = Rules.AllRules.GetSection( "BuildingTypes" ).Select( x => x.Key.ToLowerInvariant() ).ToList(); + var allBuildings = Rules.Categories["BuildingTypes"]; foreach( var unit in Rules.UnitInfo ) objects.Add( unit.Key, new Item( unit.Key, unit.Value, allBuildings.Contains( unit.Key ) ) );