Rules.Categories
This commit is contained in:
@@ -10,7 +10,8 @@ namespace OpenRa.Game
|
||||
static class Rules
|
||||
{
|
||||
public static IniFile AllRules;
|
||||
public static Dictionary<string, List<String>> Categories;
|
||||
public static Dictionary<string, List<string>> Categories = new Dictionary<string,List<string>>();
|
||||
public static Dictionary<string, string> UnitCategory;
|
||||
public static InfoLoader<UnitInfo> UnitInfo;
|
||||
public static InfoLoader<WeaponInfo> WeaponInfo;
|
||||
public static InfoLoader<WarheadInfo> 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<string, string>( y, x.Key ) ) ).ToDictionary( x => x.Key, x => x.Value );
|
||||
|
||||
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)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "VehicleTypes", s => new UnitInfo.VehicleInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "ShipTypes", s => new UnitInfo.VehicleInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "PlaneTypes", s => new UnitInfo.VehicleInfo(s)));
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Building", s => new UnitInfo.BuildingInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Infantry", s => new UnitInfo.InfantryInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Vehicle", s => new UnitInfo.VehicleInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Ship", s => new UnitInfo.VehicleInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Plane", s => new UnitInfo.VehicleInfo(s)));
|
||||
|
||||
LoadCategories(
|
||||
"Weapon",
|
||||
"Warhead",
|
||||
"Projectile" );
|
||||
|
||||
WeaponInfo = new InfoLoader<WeaponInfo>(
|
||||
Pair.New<string,Func<string,WeaponInfo>>("WeaponTypes", _ => new WeaponInfo()));
|
||||
Pair.New<string,Func<string,WeaponInfo>>("Weapon", _ => new WeaponInfo()));
|
||||
WarheadInfo = new InfoLoader<WarheadInfo>(
|
||||
Pair.New<string,Func<string,WarheadInfo>>("WarheadTypes", _ => new WarheadInfo()));
|
||||
Pair.New<string,Func<string,WarheadInfo>>("Warhead", _ => new WarheadInfo()));
|
||||
|
||||
ProjectileInfo = new InfoLoader<ProjectileInfo>(
|
||||
Pair.New<string, Func<string, ProjectileInfo>>("ProjectileTypes", _ => new ProjectileInfo()));
|
||||
Pair.New<string, Func<string, ProjectileInfo>>("Projectile", _ => new ProjectileInfo()));
|
||||
}
|
||||
|
||||
static Dictionary<string, List<string>> LoadCategories( params string[] types )
|
||||
static void 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;
|
||||
Categories[ t ] = AllRules.GetSection( t + "Types" ).Select( x => x.Key.ToLowerInvariant() ).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace OpenRa.Game
|
||||
|
||||
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
|
||||
|
||||
List<SidebarItem> items = new List<SidebarItem>();
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" );
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user