Add Lua API support for actors with multiple Production traits.
This commit is contained in:
@@ -24,12 +24,12 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
[ScriptPropertyGroup("Production")]
|
||||
public class ProductionProperties : ScriptActorProperties, Requires<ProductionInfo>
|
||||
{
|
||||
readonly Production p;
|
||||
readonly Production[] productionTraits;
|
||||
|
||||
public ProductionProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
p = self.Trait<Production>();
|
||||
productionTraits = self.TraitsImplementing<Production>().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);
|
||||
Self.QueueActivity(new WaitFor(() =>
|
||||
{
|
||||
// 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;
|
||||
|
||||
var inits = new TypeDictionary
|
||||
{
|
||||
new OwnerInit(Self.Owner),
|
||||
new FactionInit(faction)
|
||||
new FactionInit(factionVariant ?? BuildableInfo.GetInitialFaction(actorInfo, p.Faction))
|
||||
};
|
||||
|
||||
Self.QueueActivity(new WaitFor(() => p.Produce(Self, actorInfo, productionType, inits)));
|
||||
if (p.Produce(Self, actorInfo, productionType, inits))
|
||||
return true;
|
||||
}
|
||||
|
||||
// We didn't produce anything, wait until we do
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user