From b096671acb76eb9cbbfc72fd8fc8970c70281af6 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Sun, 17 May 2015 19:44:19 +0200 Subject: [PATCH] Add an ActorInit for unit stances --- OpenRA.Mods.Common/Traits/AutoTarget.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index 7a511e8340..4c85995474 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -16,7 +16,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { [Desc("The actor will automatically engage the enemy when it is in range.")] - public class AutoTargetInfo : ITraitInfo, Requires + public class AutoTargetInfo : ITraitInfo, Requires, UsesInit { [Desc("It will try to hunt down the enemy if it is not set to defend.")] public readonly bool AllowMovement = true; @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits public readonly bool TargetWhenDamaged = true; - public object Create(ActorInitializer init) { return new AutoTarget(init.Self, this); } + public object Create(ActorInitializer init) { return new AutoTarget(init, this); } } public enum UnitStance { HoldFire, ReturnFire, Defend, AttackAnything } @@ -63,11 +63,17 @@ namespace OpenRA.Mods.Common.Traits // NOT SYNCED: do not refer to this anywhere other than UI code public UnitStance PredictedStance; - public AutoTarget(Actor self, AutoTargetInfo info) + public AutoTarget(ActorInitializer init, AutoTargetInfo info) { + var self = init.Self; this.info = info; attack = self.Trait(); - Stance = self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance; + + if (init.Contains()) + Stance = init.Get(); + else + Stance = self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance; + PredictedStance = Stance; at = self.TraitOrDefault(); } @@ -202,4 +208,12 @@ namespace OpenRA.Mods.Common.Traits [Desc("Will not get automatically targeted by enemy (like walls)")] class AutoTargetIgnoreInfo : TraitInfo { } class AutoTargetIgnore { } + + public class StanceInit : IActorInit + { + [FieldFromYamlKey] readonly UnitStance value = UnitStance.AttackAnything; + public StanceInit() { } + public StanceInit(UnitStance init) { value = init; } + public UnitStance Value(World world) { return value; } + } }