diff --git a/OpenRa.Game/GameRules/Rules.cs b/OpenRa.Game/GameRules/Rules.cs index cc98ade92f..a138cca4c3 100755 --- a/OpenRa.Game/GameRules/Rules.cs +++ b/OpenRa.Game/GameRules/Rules.cs @@ -10,7 +10,8 @@ namespace OpenRa.Game static class Rules { public static IniFile AllRules; - public static Dictionary> Categories; + public static Dictionary> Categories = new Dictionary>(); + public static Dictionary UnitCategory; public static InfoLoader UnitInfo; public static InfoLoader WeaponInfo; public static InfoLoader WarheadInfo; @@ -24,39 +25,39 @@ namespace OpenRa.Game FileSystem.Open( "units.ini" ), FileSystem.Open( "campaignUnits.ini" ) ); - Categories = LoadCategories( - "BuildingTypes", - "InfantryTypes", - "VehicleTypes", - "ShipTypes", - "PlaneTypes", - "WeaponTypes", - "WarheadTypes", - "ProjectileTypes" ); + 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 ); UnitInfo = new InfoLoader( - Pair.New>( "BuildingTypes", s => new UnitInfo.BuildingInfo(s)), - Pair.New>( "InfantryTypes", s => new UnitInfo.InfantryInfo(s)), - Pair.New>( "VehicleTypes", s => new UnitInfo.VehicleInfo(s)), - Pair.New>( "ShipTypes", s => new UnitInfo.VehicleInfo(s)), - Pair.New>( "PlaneTypes", s => new UnitInfo.VehicleInfo(s))); + Pair.New>( "Building", s => new UnitInfo.BuildingInfo(s)), + Pair.New>( "Infantry", s => new UnitInfo.InfantryInfo(s)), + Pair.New>( "Vehicle", s => new UnitInfo.VehicleInfo(s)), + Pair.New>( "Ship", s => new UnitInfo.VehicleInfo(s)), + Pair.New>( "Plane", s => new UnitInfo.VehicleInfo(s))); + + LoadCategories( + "Weapon", + "Warhead", + "Projectile" ); WeaponInfo = new InfoLoader( - Pair.New>("WeaponTypes", _ => new WeaponInfo())); + Pair.New>("Weapon", _ => new WeaponInfo())); WarheadInfo = new InfoLoader( - Pair.New>("WarheadTypes", _ => new WarheadInfo())); + Pair.New>("Warhead", _ => new WarheadInfo())); ProjectileInfo = new InfoLoader( - Pair.New>("ProjectileTypes", _ => new ProjectileInfo())); + Pair.New>("Projectile", _ => new ProjectileInfo())); } - static Dictionary> LoadCategories( params string[] types ) + static void 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; + Categories[ t ] = AllRules.GetSection( t + "Types" ).Select( x => x.Key.ToLowerInvariant() ).ToList(); } } } diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 881d2df6b8..fc8b6708b8 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -27,7 +27,6 @@ namespace OpenRa.Game static string[] groups = new string[] { "Building", "Vehicle", "Ship", "Infantry", "Plane" }; - Dictionary itemGroups = new Dictionary(); //item->group Dictionary clockAnimations = new Dictionary(); //group->clockAnimation List items = new List(); @@ -78,13 +77,12 @@ namespace OpenRa.Game void LoadSprites( string group ) { - foreach( var u in Rules.Categories[ group + "Types" ] ) + foreach( var u in Rules.Categories[ group ] ) { var unit = Rules.UnitInfo[ u ]; if( unit.TechLevel != -1 ) sprites.Add( unit.Name, SpriteSheetBuilder.LoadSprite( unit.Name + "icon", ".shp" ) ); - itemGroups.Add( unit.Name, group ); } } @@ -129,7 +127,7 @@ namespace OpenRa.Game { foreach( SidebarItem i in items ) { - var group = itemGroups[ i.techTreeItem.tag ]; + var group = Rules.UnitCategory[ i.techTreeItem.tag ]; var producing = player.Producing( group ); if( producing != null && producing.Item == i.techTreeItem.tag ) { @@ -163,7 +161,7 @@ namespace OpenRa.Game var item = GetItem(point); if (item != null) { - string group = itemGroups[item.techTreeItem.tag]; + string group = Rules.UnitCategory[ item.techTreeItem.tag ]; if (player.Producing(group) == null) { player.BeginProduction( group, new ProductionItem( item.techTreeItem.tag, 25, 0 ) ); @@ -177,7 +175,7 @@ namespace OpenRa.Game var item = GetItem(point); if( item != null ) { - string group = itemGroups[ item.techTreeItem.tag ]; + string group = Rules.UnitCategory[ item.techTreeItem.tag ]; player.CancelProduction( group ); } } diff --git a/OpenRa.Game/TechTree/Item.cs b/OpenRa.Game/TechTree/Item.cs index d7443157a8..d95f447ab4 100755 --- a/OpenRa.Game/TechTree/Item.cs +++ b/OpenRa.Game/TechTree/Item.cs @@ -50,7 +50,7 @@ namespace OpenRa.TechTree if (soviet.Remove("tent")) soviet.Add("barr"); if (allied.Remove("barr")) allied.Add("tent"); - if( Rules.Categories[ "InfantryTypes" ].Contains( tag ) ) + if( Rules.UnitCategory[ tag ] == "Infantry" ) { if( !allied.Contains( "tent" ) ) allied.Add( "tent" ); if( !soviet.Contains( "barr" ) ) soviet.Add( "barr" ); diff --git a/OpenRa.Game/TechTree/TechTree.cs b/OpenRa.Game/TechTree/TechTree.cs index 0d424e9de9..4682c58f42 100644 --- a/OpenRa.Game/TechTree/TechTree.cs +++ b/OpenRa.Game/TechTree/TechTree.cs @@ -34,10 +34,8 @@ namespace OpenRa.TechTree void LoadRules() { - 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 ) ) ); + objects.Add( unit.Key, new Item( unit.Key, unit.Value, Rules.UnitCategory[ unit.Key ] == "Building" ) ); } public bool Build(string key, bool force)