Add AttackMove support for AssaultMove orders and condition granting.

This commit is contained in:
Paul Chote
2017-09-09 15:02:01 +01:00
committed by reaperrr
parent 1e4640dc0b
commit ffee45cd76

View File

@@ -20,10 +20,18 @@ namespace OpenRA.Mods.Common.Traits
{ {
[VoiceReference] public readonly string Voice = "Action"; [VoiceReference] public readonly string Voice = "Action";
[GrantedConditionReference]
[Desc("The condition to grant to self while scanning for targets during an attack-move.")]
public readonly string AttackMoveScanCondition = null;
[GrantedConditionReference]
[Desc("The condition to grant to self while scanning for targets during an assault-move.")]
public readonly string AssaultMoveScanCondition = null;
public object Create(ActorInitializer init) { return new AttackMove(init.Self, this); } public object Create(ActorInitializer init) { return new AttackMove(init.Self, this); }
} }
class AttackMove : IResolveOrder, IOrderVoice, INotifyIdle, ISync class AttackMove : INotifyCreated, ITick, IResolveOrder, IOrderVoice, INotifyIdle, ISync
{ {
[Sync] public CPos _targetLocation { get { return TargetLocation.HasValue ? TargetLocation.Value : CPos.Zero; } } [Sync] public CPos _targetLocation { get { return TargetLocation.HasValue ? TargetLocation.Value : CPos.Zero; } }
public CPos? TargetLocation = null; public CPos? TargetLocation = null;
@@ -31,22 +39,53 @@ namespace OpenRA.Mods.Common.Traits
readonly IMove move; readonly IMove move;
readonly AttackMoveInfo info; readonly AttackMoveInfo info;
ConditionManager conditionManager;
int attackMoveToken = ConditionManager.InvalidConditionToken;
int assaultMoveToken = ConditionManager.InvalidConditionToken;
bool assaultMoving = false;
public AttackMove(Actor self, AttackMoveInfo info) public AttackMove(Actor self, AttackMoveInfo info)
{ {
move = self.Trait<IMove>(); move = self.Trait<IMove>();
this.info = info; this.info = info;
} }
void INotifyCreated.Created(Actor self)
{
conditionManager = self.TraitOrDefault<ConditionManager>();
}
void ITick.Tick(Actor self)
{
if (conditionManager == null)
return;
var activity = self.CurrentActivity as AttackMoveActivity;
var attackActive = activity != null && !assaultMoving;
var assaultActive = activity != null && assaultMoving;
if (attackActive && attackMoveToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.AttackMoveScanCondition))
attackMoveToken = conditionManager.GrantCondition(self, info.AttackMoveScanCondition);
else if (!attackActive && attackMoveToken != ConditionManager.InvalidConditionToken)
attackMoveToken = conditionManager.RevokeCondition(self, attackMoveToken);
if (assaultActive && assaultMoveToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.AssaultMoveScanCondition))
assaultMoveToken = conditionManager.GrantCondition(self, info.AssaultMoveScanCondition);
else if (!assaultActive && assaultMoveToken != ConditionManager.InvalidConditionToken)
assaultMoveToken = conditionManager.RevokeCondition(self, assaultMoveToken);
}
public string VoicePhraseForOrder(Actor self, Order order) public string VoicePhraseForOrder(Actor self, Order order)
{ {
if (order.OrderString == "AttackMove") if (order.OrderString == "AttackMove" || order.OrderString == "AssaultMove")
return info.Voice; return info.Voice;
return null; return null;
} }
void Activate(Actor self) void Activate(Actor self, bool assaultMove)
{ {
assaultMoving = assaultMove;
self.QueueActivity(new AttackMoveActivity(self, move.MoveTo(TargetLocation.Value, 1))); self.QueueActivity(new AttackMoveActivity(self, move.MoveTo(TargetLocation.Value, 1)));
} }
@@ -54,21 +93,21 @@ namespace OpenRA.Mods.Common.Traits
{ {
// This might cause the actor to be stuck if the target location is unreachable // This might cause the actor to be stuck if the target location is unreachable
if (TargetLocation.HasValue && self.Location != TargetLocation.Value) if (TargetLocation.HasValue && self.Location != TargetLocation.Value)
Activate(self); Activate(self, assaultMoving);
} }
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)
{ {
TargetLocation = null; TargetLocation = null;
if (order.OrderString == "AttackMove") if (order.OrderString == "AttackMove" || order.OrderString == "AssaultMove")
{ {
if (!order.Queued) if (!order.Queued)
self.CancelActivity(); self.CancelActivity();
TargetLocation = move.NearestMoveableCell(order.TargetLocation); TargetLocation = move.NearestMoveableCell(order.TargetLocation);
self.SetTargetLine(Target.FromCell(self.World, TargetLocation.Value), Color.Red); self.SetTargetLine(Target.FromCell(self.World, TargetLocation.Value), Color.Red);
Activate(self); Activate(self, order.OrderString == "AssaultMove");
} }
} }
} }