Add a delay before wandering, use it on viceroids
Add a Min and Max delay and make it random
This commit is contained in:
@@ -13,22 +13,29 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.RA.Traits
|
namespace OpenRA.Mods.RA.Traits
|
||||||
{
|
{
|
||||||
[Desc("Wanders around aimlesly when idle.")]
|
[Desc("Wanders around aimlessly while idle.")]
|
||||||
abstract class WandersInfo : ITraitInfo
|
abstract class WandersInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly int WanderMoveRadius = 10;
|
public readonly int WanderMoveRadius = 10;
|
||||||
|
|
||||||
[Desc("Number of ticks to wait until decreasing the effective move radius.")]
|
[Desc("Number of ticks to wait before decreasing the effective move radius.")]
|
||||||
public readonly int MoveReductionRadiusScale = 5;
|
public readonly int TicksToWaitBeforeReducingMoveRadius = 5;
|
||||||
|
|
||||||
|
[Desc("Mimimum ammount of ticks the actor will sit idly before starting to wander.")]
|
||||||
|
public readonly int MinMoveDelayInTicks = 0;
|
||||||
|
|
||||||
|
[Desc("Maximum ammount of ticks the actor will sit idly before starting to wander.")]
|
||||||
|
public readonly int MaxMoveDelayInTicks = 0;
|
||||||
|
|
||||||
public abstract object Create(ActorInitializer init);
|
public abstract object Create(ActorInitializer init);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Wanders : INotifyAddedToWorld, INotifyBecomingIdle
|
class Wanders : INotifyIdle, INotifyBecomingIdle
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly WandersInfo info;
|
readonly WandersInfo info;
|
||||||
|
|
||||||
|
int countdown;
|
||||||
int ticksIdle;
|
int ticksIdle;
|
||||||
int effectiveMoveRadius;
|
int effectiveMoveRadius;
|
||||||
|
|
||||||
@@ -39,13 +46,16 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
effectiveMoveRadius = info.WanderMoveRadius;
|
effectiveMoveRadius = info.WanderMoveRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddedToWorld(Actor self)
|
|
||||||
{
|
|
||||||
OnBecomingIdle(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnBecomingIdle(Actor self)
|
public void OnBecomingIdle(Actor self)
|
||||||
{
|
{
|
||||||
|
countdown = self.World.SharedRandom.Next(info.MinMoveDelayInTicks, info.MaxMoveDelayInTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TickIdle(Actor self)
|
||||||
|
{
|
||||||
|
if (--countdown > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
var targetPos = PickTargetLocation();
|
var targetPos = PickTargetLocation();
|
||||||
if (targetPos != CPos.Zero)
|
if (targetPos != CPos.Zero)
|
||||||
DoAction(self, targetPos);
|
DoAction(self, targetPos);
|
||||||
@@ -59,7 +69,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
if (!self.World.Map.Contains(targetCell))
|
if (!self.World.Map.Contains(targetCell))
|
||||||
{
|
{
|
||||||
// If MoveRadius is too big there might not be a valid cell to order the attack to (if actor is on a small island and can't leave)
|
// If MoveRadius is too big there might not be a valid cell to order the attack to (if actor is on a small island and can't leave)
|
||||||
if (++ticksIdle % info.MoveReductionRadiusScale == 0)
|
if (++ticksIdle % info.TicksToWaitBeforeReducingMoveRadius == 0)
|
||||||
effectiveMoveRadius--;
|
effectiveMoveRadius--;
|
||||||
|
|
||||||
return CPos.Zero; // We'll be back the next tick; better to sit idle for a few seconds than prolong this tick indefinitely with a loop
|
return CPos.Zero; // We'll be back the next tick; better to sit idle for a few seconds than prolong this tick indefinitely with a loop
|
||||||
|
|||||||
@@ -459,6 +459,8 @@ VICE:
|
|||||||
AttackFrontal:
|
AttackFrontal:
|
||||||
AttackWander:
|
AttackWander:
|
||||||
WanderMoveRadius: 2
|
WanderMoveRadius: 2
|
||||||
|
MinMoveDelayInTicks: 25
|
||||||
|
MaxMoveDelayInTicks: 45
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash:
|
||||||
SplitFacings: true
|
SplitFacings: true
|
||||||
|
|||||||
@@ -584,6 +584,8 @@ DOGGIE:
|
|||||||
AttackFrontal:
|
AttackFrontal:
|
||||||
AttackWander:
|
AttackWander:
|
||||||
WanderMoveRadius: 2
|
WanderMoveRadius: 2
|
||||||
|
MinMoveDelayInTicks: 25
|
||||||
|
MaxMoveDelayInTicks: 45
|
||||||
|
|
||||||
VISSML:
|
VISSML:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
|
|||||||
Reference in New Issue
Block a user