Make Wanders and AttackWander queue activities instead of resolving orders

This commit is contained in:
abcdefg30
2023-02-06 19:54:52 +01:00
committed by Matthias Mailänder
parent 4500d964b3
commit 040fbf9694
2 changed files with 9 additions and 14 deletions

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using OpenRA.Mods.Common.Activities;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -32,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
public override void DoAction(Actor self, CPos targetCell) public override void DoAction(Actor self, CPos targetCell)
{ {
attackMove.ResolveOrder(self, new Order("AttackMove", self, Target.FromCell(self.World, targetCell), false)); self.QueueActivity(new AttackMoveActivity(self, () => Move.MoveTo(targetCell, targetLineColor: attackMove.Info.TargetLineColor), false));
} }
} }
} }

View File

@@ -36,9 +36,9 @@ namespace OpenRA.Mods.Common.Traits
public class Wanders : ConditionalTrait<WandersInfo>, INotifyIdle, INotifyBecomingIdle public class Wanders : ConditionalTrait<WandersInfo>, INotifyIdle, INotifyBecomingIdle
{ {
readonly Actor self;
readonly WandersInfo info; readonly WandersInfo info;
IResolveOrder move; readonly IMoveInfo moveInfo;
protected readonly IMove Move;
int countdown; int countdown;
int ticksIdle; int ticksIdle;
@@ -47,17 +47,11 @@ namespace OpenRA.Mods.Common.Traits
public Wanders(Actor self, WandersInfo info) public Wanders(Actor self, WandersInfo info)
: base(info) : base(info)
{ {
this.self = self;
this.info = info; this.info = info;
effectiveMoveRadius = info.WanderMoveRadius; effectiveMoveRadius = info.WanderMoveRadius;
countdown = self.World.SharedRandom.Next(info.MinMoveDelay, info.MaxMoveDelay); countdown = self.World.SharedRandom.Next(info.MinMoveDelay, info.MaxMoveDelay);
} Move = self.Trait<IMove>();
moveInfo = self.Info.TraitInfo<IMoveInfo>();
protected override void Created(Actor self)
{
move = self.Trait<IMove>() as IResolveOrder;
base.Created(self);
} }
protected virtual void OnBecomingIdle(Actor self) protected virtual void OnBecomingIdle(Actor self)
@@ -78,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits
if (--countdown > 0) if (--countdown > 0)
return; return;
var targetCell = PickTargetLocation(); var targetCell = PickTargetLocation(self);
if (targetCell.HasValue) if (targetCell.HasValue)
DoAction(self, targetCell.Value); DoAction(self, targetCell.Value);
} }
@@ -88,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
TickIdle(self); TickIdle(self);
} }
CPos? PickTargetLocation() CPos? PickTargetLocation(Actor self)
{ {
var target = self.CenterPosition + new WVec(0, -1024 * effectiveMoveRadius, 0).Rotate(WRot.FromFacing(self.World.SharedRandom.Next(255))); var target = self.CenterPosition + new WVec(0, -1024 * effectiveMoveRadius, 0).Rotate(WRot.FromFacing(self.World.SharedRandom.Next(255)));
var targetCell = self.World.Map.CellContaining(target); var targetCell = self.World.Map.CellContaining(target);
@@ -118,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual void DoAction(Actor self, CPos targetCell) public virtual void DoAction(Actor self, CPos targetCell)
{ {
move.ResolveOrder(self, new Order("Move", self, Target.FromCell(self.World, targetCell), false)); self.QueueActivity(Move.MoveTo(targetCell, targetLineColor: moveInfo.GetTargetLineColor()));
} }
} }
} }