Rules.Categories
This commit is contained in:
@@ -15,9 +15,8 @@ namespace OpenRa.Game.GameRules
|
|||||||
public InfoLoader(params Pair<string, Func<string,T>>[] srcs)
|
public InfoLoader(params Pair<string, Func<string,T>>[] srcs)
|
||||||
{
|
{
|
||||||
foreach (var src in 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);
|
var t = src.Second(name);
|
||||||
FieldLoader.Load(t, Rules.AllRules.GetSection(name));
|
FieldLoader.Load(t, Rules.AllRules.GetSection(name));
|
||||||
infos[name] = t;
|
infos[name] = t;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace OpenRa.Game
|
|||||||
static class Rules
|
static class Rules
|
||||||
{
|
{
|
||||||
public static IniFile AllRules;
|
public static IniFile AllRules;
|
||||||
|
public static Dictionary<string, List<String>> Categories;
|
||||||
public static InfoLoader<UnitInfo> UnitInfo;
|
public static InfoLoader<UnitInfo> UnitInfo;
|
||||||
public static InfoLoader<WeaponInfo> WeaponInfo;
|
public static InfoLoader<WeaponInfo> WeaponInfo;
|
||||||
public static InfoLoader<WarheadInfo> WarheadInfo;
|
public static InfoLoader<WarheadInfo> WarheadInfo;
|
||||||
@@ -23,6 +24,16 @@ namespace OpenRa.Game
|
|||||||
FileSystem.Open( "units.ini" ),
|
FileSystem.Open( "units.ini" ),
|
||||||
FileSystem.Open( "campaignUnits.ini" ) );
|
FileSystem.Open( "campaignUnits.ini" ) );
|
||||||
|
|
||||||
|
Categories = LoadCategories(
|
||||||
|
"BuildingTypes",
|
||||||
|
"InfantryTypes",
|
||||||
|
"VehicleTypes",
|
||||||
|
"ShipTypes",
|
||||||
|
"PlaneTypes",
|
||||||
|
"WeaponTypes",
|
||||||
|
"WarheadTypes",
|
||||||
|
"ProjectileTypes" );
|
||||||
|
|
||||||
UnitInfo = new InfoLoader<UnitInfo>(
|
UnitInfo = new InfoLoader<UnitInfo>(
|
||||||
Pair.New<string,Func<string,UnitInfo>>( "BuildingTypes", s => new UnitInfo.BuildingInfo(s)),
|
Pair.New<string,Func<string,UnitInfo>>( "BuildingTypes", s => new UnitInfo.BuildingInfo(s)),
|
||||||
Pair.New<string,Func<string,UnitInfo>>( "InfantryTypes", s => new UnitInfo.InfantryInfo(s)),
|
Pair.New<string,Func<string,UnitInfo>>( "InfantryTypes", s => new UnitInfo.InfantryInfo(s)),
|
||||||
@@ -38,5 +49,14 @@ namespace OpenRa.Game
|
|||||||
ProjectileInfo = new InfoLoader<ProjectileInfo>(
|
ProjectileInfo = new InfoLoader<ProjectileInfo>(
|
||||||
Pair.New<string, Func<string, ProjectileInfo>>("ProjectileTypes", _ => new 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>();
|
readonly Dictionary<string, ProductionItem> production = new Dictionary<string, ProductionItem>();
|
||||||
|
|
||||||
public void ProductionInit( string category )
|
public void ProductionInit( string category )
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace OpenRa.Game
|
|||||||
Dictionary<string, Sprite> sprites = new Dictionary<string,Sprite>();
|
Dictionary<string, Sprite> sprites = new Dictionary<string,Sprite>();
|
||||||
const int spriteWidth = 64, spriteHeight = 48;
|
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, string> itemGroups = new Dictionary<string,string>(); //item->group
|
||||||
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //group->clockAnimation
|
Dictionary<string, Animation> clockAnimations = new Dictionary<string,Animation>(); //group->clockAnimation
|
||||||
@@ -41,11 +41,8 @@ namespace OpenRa.Game
|
|||||||
spriteRenderer = new SpriteRenderer(renderer, false);
|
spriteRenderer = new SpriteRenderer(renderer, false);
|
||||||
clockRenderer = new SpriteRenderer(renderer, true);
|
clockRenderer = new SpriteRenderer(renderer, true);
|
||||||
|
|
||||||
LoadSprites( "BuildingTypes", "building" );
|
for( int i = 0 ; i < groups.Length ; i++ )
|
||||||
LoadSprites( "VehicleTypes", "vehicle" );
|
LoadSprites( groups[ i ] );
|
||||||
LoadSprites( "InfantryTypes", "infantry" );
|
|
||||||
LoadSprites( "ShipTypes", "ship" );
|
|
||||||
LoadSprites( "PlaneTypes", "plane" );
|
|
||||||
|
|
||||||
foreach (string group in groups)
|
foreach (string group in groups)
|
||||||
{
|
{
|
||||||
@@ -79,11 +76,11 @@ namespace OpenRa.Game
|
|||||||
Game.controller.AddOrder(Order.BuildUnit(player, item.techTreeItem.tag.ToLowerInvariant()));
|
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 )
|
if( unit.TechLevel != -1 )
|
||||||
sprites.Add( unit.Name, SpriteSheetBuilder.LoadSprite( unit.Name + "icon", ".shp" ) );
|
sprites.Add( unit.Name, SpriteSheetBuilder.LoadSprite( unit.Name + "icon", ".shp" ) );
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
using OpenRa.Game.GameRules;
|
using OpenRa.Game.GameRules;
|
||||||
using IjwFramework.Types;
|
using IjwFramework.Types;
|
||||||
|
using OpenRa.Game;
|
||||||
|
|
||||||
namespace OpenRa.TechTree
|
namespace OpenRa.TechTree
|
||||||
{
|
{
|
||||||
@@ -49,8 +50,7 @@ namespace OpenRa.TechTree
|
|||||||
if (soviet.Remove("tent")) soviet.Add("barr");
|
if (soviet.Remove("tent")) soviet.Add("barr");
|
||||||
if (allied.Remove("barr")) allied.Add("tent");
|
if (allied.Remove("barr")) allied.Add("tent");
|
||||||
|
|
||||||
// TODO: rewrite this based on "InfantryTypes" in units.ini
|
if( Rules.Categories[ "InfantryTypes" ].Contains( tag ) )
|
||||||
if ((tag.Length == 2 && tag[0] == 'e') || tag == "medi" || tag == "thf" || tag == "spy")
|
|
||||||
{
|
{
|
||||||
if( !allied.Contains( "tent" ) ) allied.Add( "tent" );
|
if( !allied.Contains( "tent" ) ) allied.Add( "tent" );
|
||||||
if( !soviet.Contains( "barr" ) ) soviet.Add( "barr" );
|
if( !soviet.Contains( "barr" ) ) soviet.Add( "barr" );
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRa.TechTree
|
|||||||
|
|
||||||
void LoadRules()
|
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 )
|
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, allBuildings.Contains( unit.Key ) ) );
|
||||||
|
|||||||
Reference in New Issue
Block a user