Make ClonesProducedUnits Conditional.
This commit is contained in:
committed by
reaperrr
parent
1ed36da107
commit
e007568e17
@@ -18,34 +18,36 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Cnc.Traits
|
namespace OpenRA.Mods.Cnc.Traits
|
||||||
{
|
{
|
||||||
[Desc("Creates a free duplicate of produced units.")]
|
[Desc("Creates a free duplicate of produced units.")]
|
||||||
public class ClonesProducedUnitsInfo : ITraitInfo, Requires<ProductionInfo>, Requires<ExitInfo>
|
public class ClonesProducedUnitsInfo : ConditionalTraitInfo, Requires<ProductionInfo>, Requires<ExitInfo>
|
||||||
{
|
{
|
||||||
[FieldLoader.Require]
|
[FieldLoader.Require]
|
||||||
[Desc("Uses the \"Cloneable\" trait to determine whether or not we should clone a produced unit.")]
|
[Desc("Uses the \"Cloneable\" trait to determine whether or not we should clone a produced unit.")]
|
||||||
public readonly BitSet<CloneableType> CloneableTypes = default(BitSet<CloneableType>);
|
public readonly BitSet<CloneableType> CloneableTypes = default(BitSet<CloneableType>);
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new ClonesProducedUnits(init, this); }
|
public override object Create(ActorInitializer init) { return new ClonesProducedUnits(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ClonesProducedUnits : INotifyOtherProduction
|
public class ClonesProducedUnits : ConditionalTrait<ClonesProducedUnitsInfo>, INotifyOtherProduction
|
||||||
{
|
{
|
||||||
readonly ClonesProducedUnitsInfo info;
|
|
||||||
readonly Production[] productionTraits;
|
readonly Production[] productionTraits;
|
||||||
|
|
||||||
public ClonesProducedUnits(ActorInitializer init, ClonesProducedUnitsInfo info)
|
public ClonesProducedUnits(ActorInitializer init, ClonesProducedUnitsInfo info)
|
||||||
|
: base(info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
|
||||||
productionTraits = init.Self.TraitsImplementing<Production>().ToArray();
|
productionTraits = init.Self.TraitsImplementing<Production>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnitProducedByOther(Actor self, Actor producer, Actor produced, string productionType, TypeDictionary init)
|
public void UnitProducedByOther(Actor self, Actor producer, Actor produced, string productionType, TypeDictionary init)
|
||||||
{
|
{
|
||||||
|
if (IsTraitDisabled)
|
||||||
|
return;
|
||||||
|
|
||||||
// No recursive cloning!
|
// No recursive cloning!
|
||||||
if (producer.Owner != self.Owner || producer.Info.HasTraitInfo<ClonesProducedUnitsInfo>())
|
if (producer.Owner != self.Owner || producer.Info.HasTraitInfo<ClonesProducedUnitsInfo>())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var ci = produced.Info.TraitInfoOrDefault<CloneableInfo>();
|
var ci = produced.Info.TraitInfoOrDefault<CloneableInfo>();
|
||||||
if (ci == null || !info.CloneableTypes.Overlaps(ci.Types))
|
if (ci == null || !Info.CloneableTypes.Overlaps(ci.Types))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var factionInit = init.GetOrDefault<FactionInit>();
|
var factionInit = init.GetOrDefault<FactionInit>();
|
||||||
|
|||||||
Reference in New Issue
Block a user