diff --git a/OpenRA.Mods.Common/Traits/Production.cs b/OpenRA.Mods.Common/Traits/Production.cs index 7d6f7f202f..73a9ac2281 100644 --- a/OpenRA.Mods.Common/Traits/Production.cs +++ b/OpenRA.Mods.Common/Traits/Production.cs @@ -23,14 +23,17 @@ namespace OpenRA.Mods.Common.Traits [Desc("e.g. Infantry, Vehicles, Aircraft, Buildings")] public readonly string[] Produces = Array.Empty(); + [Desc("When owner is changed, should the Faction be updated to the new owner's faction?")] + public readonly bool UpdateFactionOnOwnerChange = false; + public override object Create(ActorInitializer init) { return new Production(init, this); } } - public class Production : PausableConditionalTrait + public class Production : PausableConditionalTrait, INotifyOwnerChanged { RallyPoint rp; - public string Faction { get; } + public string Faction { get; private set; } public Production(ActorInitializer init, ProductionInfo info) : base(info) @@ -138,6 +141,12 @@ namespace OpenRA.Mods.Common.Traits return mobileInfo == null || mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, ignoreActor: self); } + + void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) + { + if (Info.UpdateFactionOnOwnerChange) + Faction = self.Owner.Faction.InternalName; + } } public class RallyPointInit : ValueActorInit, ISingleInstanceInit