Infrastructure for removing Categories and UnitCategory. Also, changed defensive structures to be in the same build-queue as normal structures. (mod it if you don't like it)

This commit is contained in:
Bob
2010-01-14 14:13:49 +13:00
parent b1d04d5737
commit 73f6d5c71c
10 changed files with 240 additions and 228 deletions

View File

@@ -47,7 +47,7 @@ namespace OpenRa.Game
// Build Palette tabs // Build Palette tabs
string currentTab = "Building"; string currentTab = "Building";
bool paletteOpen = false; bool paletteOpen = false;
static string[] groups = new string[] { "Building", "Defense", "Infantry", "Vehicle", "Plane", "Ship" }; static string[] groups = new string[] { "Building", "Infantry", "Vehicle", "Plane", "Ship" };
readonly Dictionary<string, string[]> tabImageNames; readonly Dictionary<string, string[]> tabImageNames;
readonly Dictionary<string, Sprite> tabSprites; readonly Dictionary<string, Sprite> tabSprites;
@@ -530,10 +530,10 @@ namespace OpenRa.Game
var buildableItems = Rules.TechTree.BuildableItems(Game.LocalPlayer, queueName).ToArray(); var buildableItems = Rules.TechTree.BuildableItems(Game.LocalPlayer, queueName).ToArray();
var allItems = Rules.TechTree.AllItems(Game.LocalPlayer, queueName) var allBuildables = Rules.TechTree.AllBuildables(Game.LocalPlayer, queueName)
.Where(a => Rules.NewUnitInfo[a].Traits.Contains<BuildableInfo>()) .Where(a => a.Traits.Contains<BuildableInfo>())
.Where(a => Rules.NewUnitInfo[a].Traits.Get<BuildableInfo>().Owner.Contains(Game.LocalPlayer.Race)) .Where(a => a.Traits.Get<BuildableInfo>().Owner.Contains(Game.LocalPlayer.Race))
.OrderBy(a => Rules.NewUnitInfo[a].Traits.Get<BuildableInfo>().TechLevel); .OrderBy(a => a.Traits.Get<BuildableInfo>().TechLevel);
var queue = Game.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>(); var queue = Game.LocalPlayer.PlayerActor.traits.Get<Traits.ProductionQueue>();
@@ -546,7 +546,7 @@ namespace OpenRa.Game
// Draw the icons // Draw the icons
int lasty = -1; int lasty = -1;
foreach (var item in allItems) foreach (var item in allBuildables)
{ {
// Draw the background for this row // Draw the background for this row
if (y != lasty) if (y != lasty)
@@ -560,12 +560,12 @@ namespace OpenRa.Game
var drawPos = Game.viewport.Location + new float2(rect.Location); var drawPos = Game.viewport.Location + new float2(rect.Location);
var isBuildingSomething = queue.CurrentItem(queueName) != null; var isBuildingSomething = queue.CurrentItem(queueName) != null;
shpRenderer.DrawSprite(tabSprites[item], drawPos, PaletteType.Chrome); shpRenderer.DrawSprite(tabSprites[item.Name], drawPos, PaletteType.Chrome);
var firstOfThis = queue.AllItems(queueName).FirstOrDefault(a => a.Item == item); var firstOfThis = queue.AllItems(queueName).FirstOrDefault(a => a.Item == item.Name);
if (rect.Contains(lastMousePos.ToPoint())) if (rect.Contains(lastMousePos.ToPoint()))
tooltipItem = item; tooltipItem = item.Name;
var overlayPos = drawPos + new float2((64 - ready.Image.size.X) / 2, 2); var overlayPos = drawPos + new float2((64 - ready.Image.size.X) / 2, 2);
@@ -589,7 +589,7 @@ namespace OpenRa.Game
overlayBits.Add(Pair.New(ready.Image, overlayPos)); overlayBits.Add(Pair.New(ready.Image, overlayPos));
} }
var repeats = queue.AllItems(queueName).Count(a => a.Item == item); var repeats = queue.AllItems(queueName).Count(a => a.Item == item.Name);
if (repeats > 1 || queue.CurrentItem(queueName) != firstOfThis) if (repeats > 1 || queue.CurrentItem(queueName) != firstOfThis)
{ {
var offset = -22; var offset = -22;
@@ -604,11 +604,11 @@ namespace OpenRa.Game
} }
} }
else else
if (!buildableItems.Contains(item) || isBuildingSomething) if (!buildableItems.Contains(item.Name) || isBuildingSomething)
overlayBits.Add(Pair.New(cantBuild.Image, drawPos)); overlayBits.Add(Pair.New(cantBuild.Image, drawPos));
var closureItem = item; var closureItemName = item.Name;
AddButton(rect, isLmb => HandleBuildPalette(closureItem, isLmb)); AddButton(rect, isLmb => HandleBuildPalette(closureItemName, isLmb));
if (++x == columns) { x = 0; y++; } if (++x == columns) { x = 0; y++; }
@@ -645,7 +645,7 @@ namespace OpenRa.Game
void StartProduction( string item ) void StartProduction( string item )
{ {
var group = Rules.UnitCategory[item]; var group = Rules.UnitCategory[item];
Sound.Play((group == "Building" || group == "Defense") ? "abldgin1.aud" : "train1.aud"); Sound.Play((group == "Building") ? "abldgin1.aud" : "train1.aud");
Game.controller.AddOrder(Order.StartProduction(Game.LocalPlayer, item)); Game.controller.AddOrder(Order.StartProduction(Game.LocalPlayer, item));
} }
@@ -664,7 +664,7 @@ namespace OpenRa.Game
{ {
if (producing.Done) if (producing.Done)
{ {
if (group == "Building" || group == "Defense") if (group == "Building")
Game.controller.orderGenerator = new PlaceBuildingOrderGenerator(player.PlayerActor, item); Game.controller.orderGenerator = new PlaceBuildingOrderGenerator(player.PlayerActor, item);
return; return;
} }

View File

@@ -8,15 +8,24 @@ namespace OpenRa.Game.GameRules
{ {
class NewUnitInfo class NewUnitInfo
{ {
public readonly TypeDictionary Traits = new TypeDictionary();
public readonly string Name; public readonly string Name;
public readonly string Category;
public readonly TypeDictionary Traits = new TypeDictionary();
public NewUnitInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits ) public NewUnitInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{ {
Name = name; var mergedNode = MergeWithParent( node, allUnits ).Nodes;
foreach( var t in MergeWithParent( node, allUnits ).Nodes ) Name = name;
if( t.Key != "Inherits" ) MiniYaml categoryNode;
if( mergedNode.TryGetValue( "Category", out categoryNode ) )
Category = categoryNode.Value;
if( Rules.UnitCategory.ContainsKey( name ) && Category != Rules.UnitCategory[ name ] )
throw new NotImplementedException( "wrong category");
foreach( var t in mergedNode )
if( t.Key != "Inherits" && t.Key != "Category" )
Traits.Add( LoadTraitInfo( t.Key, t.Value ) ); Traits.Add( LoadTraitInfo( t.Key, t.Value ) );
} }

View File

@@ -56,7 +56,6 @@ namespace OpenRa.Game
LoadCategories( LoadCategories(
"Building", "Building",
"Defense",
"Infantry", "Infantry",
"Vehicle", "Vehicle",
"Ship", "Ship",

View File

@@ -11,9 +11,8 @@ namespace OpenRa.Game.GameRules
public TechTree() public TechTree()
{ {
foreach( var b in Rules.Categories[ "Building" ] ) foreach( var info in Rules.NewUnitInfo.Values )
{ {
var info = Rules.NewUnitInfo[ b ];
var pi = info.Traits.GetOrDefault<ProductionInfo>(); var pi = info.Traits.GetOrDefault<ProductionInfo>();
if (pi != null) if (pi != null)
foreach( var p in pi.Produces ) foreach( var p in pi.Produces )
@@ -51,19 +50,22 @@ namespace OpenRa.Game.GameRules
return false; return false;
return true; return true;
} }
public IEnumerable<string> BuildableItems( Player player, params string[] categories ) public IEnumerable<string> BuildableItems( Player player, params string[] categories )
{ {
var playerBuildings = GatherBuildings( player ); var playerBuildings = GatherBuildings( player );
foreach( var unit in categories.SelectMany( x => Rules.Categories[ x ] ).Select( x => Rules.NewUnitInfo[ x ] ) ) foreach( var unit in AllBuildables( player, categories ) )
if( CanBuild( unit, player, playerBuildings ) ) if( CanBuild( unit, player, playerBuildings ) )
yield return unit.Name; yield return unit.Name;
} }
public IEnumerable<string> AllItems(Player player, params string[] categories) public IEnumerable<NewUnitInfo> AllBuildables(Player player, params string[] categories)
{ {
return categories.SelectMany(x => Rules.Categories[x]).Select(x => Rules.NewUnitInfo[x].Name); return Rules.NewUnitInfo.Values
.Where( x => x.Name[ 0 ] != '^' )
.Where( x => categories.Contains( Rules.UnitCategory[ x.Name ] ) )
.Where( x => x.Traits.Contains<BuildableInfo>() );
} }
public IEnumerable<NewUnitInfo> UnitBuiltAt( NewUnitInfo info ) public IEnumerable<NewUnitInfo> UnitBuiltAt( NewUnitInfo info )

View File

@@ -52,7 +52,7 @@ namespace OpenRa.Game.Traits
() => Game.world.AddFrameEndTask( () => Game.world.AddFrameEndTask(
_ => _ =>
{ {
var isBuilding = group == "Building" || group == "Defense"; var isBuilding = group == "Building";
if( !hasPlayedSound && order.Player == Game.LocalPlayer ) if( !hasPlayedSound && order.Player == Game.LocalPlayer )
{ {
Sound.Play( isBuilding ? "conscmp1.aud" : "unitrdy1.aud" ); Sound.Play( isBuilding ? "conscmp1.aud" : "unitrdy1.aud" );

View File

@@ -26,12 +26,11 @@ namespace RulesConverter
var categoryMap = new Dictionary<string,Pair<string,string>> var categoryMap = new Dictionary<string,Pair<string,string>>
{ {
{ "VehicleTypes", Pair.New( "DefaultVehicle", "Vehicle" ) }, { "VehicleTypes", Pair.New( "^Vehicle", "Vehicle" ) },
{ "ShipTypes", Pair.New( "DefaultShip", "Ship" ) }, { "ShipTypes", Pair.New( "^Ship", "Ship" ) },
{ "PlaneTypes", Pair.New( "DefaultPlane", "Plane" ) }, { "PlaneTypes", Pair.New( "^Plane", "Plane" ) },
{ "DefenseTypes", Pair.New( "DefaultDefense", "Defense" ) }, { "BuildingTypes", Pair.New( "^Building", "Building" ) },
{ "BuildingTypes", Pair.New( "DefaultBuilding", "Building" ) }, { "InfantryTypes", Pair.New( "^Infantry", "Infantry" ) },
{ "InfantryTypes", Pair.New( "DefaultInfantry", "Infantry" ) },
}; };
var traitMap = new Dictionary<string, PL> var traitMap = new Dictionary<string, PL>
@@ -173,6 +172,7 @@ namespace RulesConverter
var iniSection = rules.GetSection(item); var iniSection = rules.GetSection(item);
writer.WriteLine("{0}:", item); writer.WriteLine("{0}:", item);
writer.WriteLine("\tInherits: {0}", cat.Value.First); writer.WriteLine("\tInherits: {0}", cat.Value.First);
writer.WriteLine("\tCategory: {0}", cat.Value.Second);
var traits = iniSection.GetValue("Traits", "") var traits = iniSection.GetValue("Traits", "")
.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); .Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();

View File

@@ -1,5 +1,5 @@
STNK: STNK:
Inherits: DefaultVehicle Inherits: ^Vehicle
Unit: Unit:
HP: 200 HP: 200
Armor: heavy Armor: heavy
@@ -16,7 +16,7 @@ STNK:
Cloak: Cloak:
TTNK: TTNK:
Inherits: DefaultVehicle Inherits: ^Vehicle
Buildable: Buildable:
TechLevel: 8 TechLevel: 8
Tab: Vehicle Tab: Vehicle
@@ -37,7 +37,7 @@ TTNK:
RenderUnitSpinner: RenderUnitSpinner:
CTNK: CTNK:
Inherits: DefaultVehicle Inherits: ^Vehicle
Buildable: Buildable:
TechLevel: 12 TechLevel: 12
Tab: Vehicle Tab: Vehicle
@@ -58,7 +58,7 @@ CTNK:
ChronoshiftDeploy: ChronoshiftDeploy:
DTRK: DTRK:
Inherits: DefaultVehicle Inherits: ^Vehicle
Buildable: Buildable:
TechLevel: 13 TechLevel: 13
Tab: Vehicle Tab: Vehicle
@@ -77,7 +77,7 @@ DTRK:
DemoTruck: DemoTruck:
QTNK: QTNK:
Inherits: DefaultVehicle Inherits: ^Vehicle
Buildable: Buildable:
TechLevel: 10 TechLevel: 10
Tab: Vehicle Tab: Vehicle
@@ -96,7 +96,7 @@ QTNK:
RenderUnit: RenderUnit:
MSUB: MSUB:
Inherits: DefaultShip Inherits: ^Ship
Buildable: Buildable:
TechLevel: 9 TechLevel: 9
Tab: Ship Tab: Ship
@@ -120,7 +120,7 @@ MSUB:
Chronoshiftable: Chronoshiftable:
SHOK: SHOK:
Inherits: DefaultInfantry Inherits: ^Infantry
Buildable: Buildable:
TechLevel: 7 TechLevel: 7
Tab: Infantry Tab: Infantry
@@ -138,7 +138,7 @@ SHOK:
TakeCover: TakeCover:
MECH: MECH:
Inherits: DefaultInfantry Inherits: ^Infantry
Buildable: Buildable:
TechLevel: 7 TechLevel: 7
Tab: Infantry Tab: Infantry

View File

@@ -1,4 +1,5 @@
DefaultVehicle: ^Vehicle:
Category: Vehicle
Unit: Unit:
ROT: 5 ROT: 5
Mobile: Mobile:
@@ -10,7 +11,8 @@ DefaultVehicle:
Passenger: Passenger:
IronCurtainable: IronCurtainable:
DefaultInfantry: ^Infantry:
Category: Infantry
Unit: Unit:
Armor: none Armor: none
Sight: 4 Sight: 4
@@ -20,17 +22,20 @@ DefaultInfantry:
RenderInfantry: RenderInfantry:
Passenger: Passenger:
DefaultShip: ^Ship:
Category: Ship
Unit: Unit:
Mobile: Mobile:
MovementType: Float MovementType: Float
Selectable: Selectable:
DefaultPlane: ^Plane:
Category: Plane
Unit: Unit:
Selectable: Selectable:
DefaultBuilding: ^Building:
Category: Building
Selectable: Selectable:
Priority: 3 Priority: 3
Building: Building:

285
ra.yaml

File diff suppressed because it is too large Load Diff

View File

@@ -210,7 +210,8 @@ LongDesc=Helicopter Gunship with Chainguns.\n Strong vs Infantry, Light Vehicle
[DefenseTypes]
[BuildingTypes]
IRON IRON
PDOX PDOX
PBOX PBOX
@@ -226,7 +227,41 @@ MSLO
; BRIK ; BRIK
; FENC ; FENC
ATEK
WEAP
SYRD
SPEN
FACT
PROC
SILO
HPAD
DOME
AFLD
POWR
APWR
STEK
BARR
TENT
KENN
FIX
FACF
WEAF
SYRF
SPEF
DOMF
; pseudo-buildings
MINP
MINV
; `Dimensions` is the size of a box that will include the whole building, excluding bib.
; ("bib-ness" can be altered in rules.ini; we can't expect people to change this, too)
; `Footprint` is the pathability and buildability of each cell occupied by the building
; _ : Not occupied by the building (e.g: the holes in the refinery and the service depot)
; x : Solid. cannot be walked on or built on.
; = : Occupied by a building, but can be walked on normally. (e.g: the drop-off point on the refinery)
; `Produces` is a category of objects that this building can produce.
[PBOX] [PBOX]
Description=Pillbox Description=Pillbox
Traits=Building, Turreted, RenderBuilding, AttackTurreted, AutoTarget, IronCurtainable Traits=Building, Turreted, RenderBuilding, AttackTurreted, AutoTarget, IronCurtainable
@@ -279,7 +314,6 @@ Dimensions=2,1
Footprint=xx Footprint=xx
SelectionPriority=3 SelectionPriority=3
LongDesc=Anti-Air base defense.\n Strong vs Aircraft\n Weak vs Infantry, Tanks LongDesc=Anti-Air base defense.\n Strong vs Aircraft\n Weak vs Infantry, Tanks
[MSLO] [MSLO]
Description=Missile Silo Description=Missile Silo
Traits=Building, RenderBuilding, IronCurtainable Traits=Building, RenderBuilding, IronCurtainable
@@ -308,44 +342,6 @@ Dimensions=1,2
Footprint=_ x Footprint=_ x
SelectionPriority=3 SelectionPriority=3
LongDesc=Regenerates the Fog of War nearby, \nobscuring the area.\n Unarmed LongDesc=Regenerates the Fog of War nearby, \nobscuring the area.\n Unarmed
[BuildingTypes]
ATEK
WEAP
SYRD
SPEN
FACT
PROC
SILO
HPAD
DOME
AFLD
POWR
APWR
STEK
BARR
TENT
KENN
FIX
FACF
WEAF
SYRF
SPEF
DOMF
; pseudo-buildings
MINP
MINV
; `Dimensions` is the size of a box that will include the whole building, excluding bib.
; ("bib-ness" can be altered in rules.ini; we can't expect people to change this, too)
; `Footprint` is the pathability and buildability of each cell occupied by the building
; _ : Not occupied by the building (e.g: the holes in the refinery and the service depot)
; x : Solid. cannot be walked on or built on.
; = : Occupied by a building, but can be walked on normally. (e.g: the drop-off point on the refinery)
; `Produces` is a category of objects that this building can produce.
[ATEK] [ATEK]
Description=Allied Tech Center Description=Allied Tech Center
Traits=Building, RenderBuilding, IronCurtainable, GpsLaunchSite Traits=Building, RenderBuilding, IronCurtainable, GpsLaunchSite