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")]
|
[ScriptPropertyGroup("Production")]
|
||||||
public class ProductionProperties : ScriptActorProperties, Requires<ProductionInfo>
|
public class ProductionProperties : ScriptActorProperties, Requires<ProductionInfo>
|
||||||
{
|
{
|
||||||
readonly Production p;
|
readonly Production[] productionTraits;
|
||||||
|
|
||||||
public ProductionProperties(ScriptContext context, Actor self)
|
public ProductionProperties(ScriptContext context, Actor self)
|
||||||
: base(context, self)
|
: base(context, self)
|
||||||
{
|
{
|
||||||
p = self.Trait<Production>();
|
productionTraits = self.TraitsImplementing<Production>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScriptActorPropertyActivity]
|
[ScriptActorPropertyActivity]
|
||||||
@@ -41,14 +41,27 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out actorInfo))
|
if (!Self.World.Map.Rules.Actors.TryGetValue(actorType, out actorInfo))
|
||||||
throw new LuaException("Unknown actor type '{0}'".F(actorType));
|
throw new LuaException("Unknown actor type '{0}'".F(actorType));
|
||||||
|
|
||||||
var faction = factionVariant ?? BuildableInfo.GetInitialFaction(actorInfo, p.Faction);
|
Self.QueueActivity(new WaitFor(() =>
|
||||||
var inits = new TypeDictionary
|
|
||||||
{
|
{
|
||||||
new OwnerInit(Self.Owner),
|
// Go through all available traits and see which one successfully produces
|
||||||
new FactionInit(faction)
|
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;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user