From c164ec8c8c23ea2654e2a13135ea0ddeec37560e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 23 Jul 2014 11:58:58 +1200 Subject: [PATCH] Add Buildable.BuildAtProduction. This allows actors to be restricted to specific production structures. --- OpenRA.Mods.RA/Buildable.cs | 3 +++ OpenRA.Mods.RA/Player/ClassicProductionQueue.cs | 10 ++++++++-- OpenRA.Mods.RA/Player/ProductionQueue.cs | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.RA/Buildable.cs b/OpenRA.Mods.RA/Buildable.cs index c8002105fc..260b3ad565 100755 --- a/OpenRA.Mods.RA/Buildable.cs +++ b/OpenRA.Mods.RA/Buildable.cs @@ -27,6 +27,9 @@ namespace OpenRA.Mods.RA [Desc("Production queue(s) that can produce this.")] public readonly string[] Queue = { }; + [Desc("Override the production structure type (from the Production Produces list) that this unit should be built at.")] + public readonly string BuildAtProductionType = null; + [Desc("Disable production when there are more than this many of this actor on the battlefield. Set to 0 to disable.")] public readonly int BuildLimit = 0; diff --git a/OpenRA.Mods.RA/Player/ClassicProductionQueue.cs b/OpenRA.Mods.RA/Player/ClassicProductionQueue.cs index b914006e6b..c61a30fb9f 100644 --- a/OpenRA.Mods.RA/Player/ClassicProductionQueue.cs +++ b/OpenRA.Mods.RA/Player/ClassicProductionQueue.cs @@ -76,9 +76,15 @@ namespace OpenRA.Mods.RA protected override bool BuildUnit(string name) { // Find a production structure to build this actor + var info = self.World.Map.Rules.Actors[name]; + var bi = info.Traits.GetOrDefault(); + + // Some units may request a specific production type, which is ignored if the AllTech cheat is enabled + var type = bi == null || developerMode.AllTech ? Info.Type : bi.BuildAtProductionType ?? Info.Type; + var producers = self.World.ActorsWithTrait() .Where(x => x.Actor.Owner == self.Owner - && x.Trait.Info.Produces.Contains(Info.Type)) + && x.Trait.Info.Produces.Contains(type)) .OrderByDescending(x => x.Actor.IsPrimaryBuilding()) .ThenByDescending(x => x.Actor.ActorID); @@ -90,7 +96,7 @@ namespace OpenRA.Mods.RA foreach (var p in producers.Where(p => !p.Actor.IsDisabled())) { - if (p.Trait.Produce(p.Actor, self.World.Map.Rules.Actors[name], Race)) + if (p.Trait.Produce(p.Actor, info, Race)) { FinishProduction(); return true; diff --git a/OpenRA.Mods.RA/Player/ProductionQueue.cs b/OpenRA.Mods.RA/Player/ProductionQueue.cs index b719c72862..fca8f15a63 100644 --- a/OpenRA.Mods.RA/Player/ProductionQueue.cs +++ b/OpenRA.Mods.RA/Player/ProductionQueue.cs @@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA // Will change if the owner changes PowerManager playerPower; PlayerResources playerResources; - DeveloperMode developerMode; + protected DeveloperMode developerMode; // A list of things we could possibly build Dictionary produceable;