Rules.Categories
This commit is contained in:
@@ -15,9 +15,8 @@ namespace OpenRa.Game.GameRules
|
||||
public InfoLoader(params Pair<string, Func<string,T>>[] 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;
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace OpenRa.Game
|
||||
static class Rules
|
||||
{
|
||||
public static IniFile AllRules;
|
||||
public static Dictionary<string, List<String>> Categories;
|
||||
public static InfoLoader<UnitInfo> UnitInfo;
|
||||
public static InfoLoader<WeaponInfo> WeaponInfo;
|
||||
public static InfoLoader<WarheadInfo> 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<UnitInfo>(
|
||||
Pair.New<string,Func<string,UnitInfo>>( "BuildingTypes", s => new UnitInfo.BuildingInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "InfantryTypes", s => new UnitInfo.InfantryInfo(s)),
|
||||
@@ -38,5 +49,14 @@ namespace OpenRa.Game
|
||||
ProjectileInfo = new InfoLoader<ProjectileInfo>(
|
||||
Pair.New<string, Func<string, ProjectileInfo>>("ProjectileTypes", _ => new ProjectileInfo()));
|
||||
}
|
||||
|
||||
static Dictionary<string, List<string>> LoadCategories( params string[] types )
|
||||
{
|
||||
var ret = new Dictionary<string, List<string>>();
|
||||
foreach( var t in types )
|
||||
ret[ t ] = AllRules.GetSection( t ).Select( x => x.Key.ToLowerInvariant() ).ToList();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string, ProductionItem> production = new Dictionary<string, ProductionItem>();
|
||||
|
||||
public void ProductionInit( string category )
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRa.Game
|
||||
Dictionary<string, Sprite> sprites = new Dictionary<string,Sprite>();
|
||||
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<string, string> itemGroups = new Dictionary<string,string>(); //item->group
|
||||
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //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" ) );
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using OpenRa.FileFormats;
|
||||
using OpenRa.Game.GameRules;
|
||||
using IjwFramework.Types;
|
||||
using OpenRa.Game;
|
||||
|
||||
namespace OpenRa.TechTree
|
||||
{
|
||||
@@ -49,8 +50,7 @@ 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" );
|
||||
|
||||
@@ -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 ) ) );
|
||||
|
||||
Reference in New Issue
Block a user