Merge pull request #11520 from reaperrr/IdleWander
Make civilians wander around when idle
This commit is contained in:
@@ -273,7 +273,7 @@
|
||||
<Compile Include="Traits\Attack\AttackOmni.cs" />
|
||||
<Compile Include="Traits\Attack\AttackSuicides.cs" />
|
||||
<Compile Include="Traits\Attack\AttackTurreted.cs" />
|
||||
<Compile Include="Traits\Attack\AttackWander.cs" />
|
||||
<Compile Include="Traits\AttackWander.cs" />
|
||||
<Compile Include="Traits\AutoTarget.cs" />
|
||||
<Compile Include="Traits\BlocksProjectiles.cs" />
|
||||
<Compile Include="Traits\Buildable.cs" />
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public AttackWander(Actor self, AttackWanderInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
attackMove = self.TraitOrDefault<AttackMove>();
|
||||
attackMove = self.Trait<AttackMove>();
|
||||
}
|
||||
|
||||
public override void DoAction(Actor self, CPos targetCell)
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Wanders around aimlessly while idle.")]
|
||||
public abstract class WandersInfo : ITraitInfo
|
||||
public class WandersInfo : UpgradableTraitInfo, Requires<IMoveInfo>
|
||||
{
|
||||
public readonly int WanderMoveRadius = 1;
|
||||
|
||||
@@ -28,13 +28,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Maximum amount of ticks the actor will sit idly before starting to wander.")]
|
||||
public readonly int MaxMoveDelay = 0;
|
||||
|
||||
public abstract object Create(ActorInitializer init);
|
||||
public override object Create(ActorInitializer init) { return new Wanders(init.Self, this); }
|
||||
}
|
||||
|
||||
public class Wanders : INotifyIdle, INotifyBecomingIdle
|
||||
public class Wanders : UpgradableTrait<WandersInfo>, INotifyCreated, INotifyIdle, INotifyBecomingIdle
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly WandersInfo info;
|
||||
IResolveOrder move;
|
||||
|
||||
int countdown;
|
||||
int ticksIdle;
|
||||
@@ -42,12 +43,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
bool firstTick = true;
|
||||
|
||||
public Wanders(Actor self, WandersInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
effectiveMoveRadius = info.WanderMoveRadius;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
move = self.Trait<IMove>() as IResolveOrder;
|
||||
}
|
||||
|
||||
public virtual void OnBecomingIdle(Actor self)
|
||||
{
|
||||
countdown = self.World.SharedRandom.Next(info.MinMoveDelay, info.MaxMoveDelay);
|
||||
@@ -55,9 +62,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public virtual void TickIdle(Actor self)
|
||||
{
|
||||
// The countdown has not have been set at this point, so don't check yet
|
||||
if (IsTraitDisabled)
|
||||
return;
|
||||
|
||||
// OnBecomingIdle has not been called yet at this point, so set the initial countdown here
|
||||
if (firstTick)
|
||||
{
|
||||
countdown = self.World.SharedRandom.Next(info.MinMoveDelay, info.MaxMoveDelay);
|
||||
firstTick = false;
|
||||
return;
|
||||
}
|
||||
@@ -92,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public virtual void DoAction(Actor self, CPos targetCell)
|
||||
{
|
||||
throw new NotImplementedException("Base class Wanders does not implement method DoAction!");
|
||||
move.ResolveOrder(self, new Order("Move", self, false) { TargetLocation = targetCell });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user