From cde18221e678fadb92e0b9c695978c1b66a95d3a Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Sat, 3 Nov 2018 14:58:59 +0000 Subject: [PATCH] Add Lua API support for actors with multiple Production traits. --- .../Properties/ProductionProperties.cs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs index f651f60065..84f734e1e4 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs @@ -24,12 +24,12 @@ namespace OpenRA.Mods.Common.Scripting [ScriptPropertyGroup("Production")] public class ProductionProperties : ScriptActorProperties, Requires { - readonly Production p; + readonly Production[] productionTraits; public ProductionProperties(ScriptContext context, Actor self) : base(context, self) { - p = self.Trait(); + productionTraits = self.TraitsImplementing().ToArray(); } [ScriptActorPropertyActivity] @@ -41,14 +41,27 @@ namespace OpenRA.Mods.Common.Scripting if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out actorInfo)) throw new LuaException("Unknown actor type '{0}'".F(actorType)); - var faction = factionVariant ?? BuildableInfo.GetInitialFaction(actorInfo, p.Faction); - var inits = new TypeDictionary + Self.QueueActivity(new WaitFor(() => { - new OwnerInit(Self.Owner), - new FactionInit(faction) - }; + // Go through all available traits and see which one successfully produces + foreach (var p in productionTraits) + { + if (!string.IsNullOrEmpty(productionType) && !p.Info.Produces.Contains(productionType)) + continue; - Self.QueueActivity(new WaitFor(() => p.Produce(Self, actorInfo, productionType, inits))); + var inits = new TypeDictionary + { + new OwnerInit(Self.Owner), + new FactionInit(factionVariant ?? BuildableInfo.GetInitialFaction(actorInfo, p.Faction)) + }; + + if (p.Produce(Self, actorInfo, productionType, inits)) + return true; + } + + // We didn't produce anything, wait until we do + return false; + })); } }