Update Production's Faction when its owner changes

This commit is contained in:
michaeldgg2
2023-11-17 18:34:33 +01:00
committed by Gustas
parent c39d10b780
commit 2612e7f297

View File

@@ -23,14 +23,17 @@ namespace OpenRA.Mods.Common.Traits
[Desc("e.g. Infantry, Vehicles, Aircraft, Buildings")]
public readonly string[] Produces = Array.Empty<string>();
[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<ProductionInfo>
public class Production : PausableConditionalTrait<ProductionInfo>, 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<CPos[]>, ISingleInstanceInit