Add AvoidTerrainTypes to Wanders.
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -27,6 +29,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Maximum amount of ticks the actor will sit idly before starting to wander.")]
|
[Desc("Maximum amount of ticks the actor will sit idly before starting to wander.")]
|
||||||
public readonly int MaxMoveDelay = 0;
|
public readonly int MaxMoveDelay = 0;
|
||||||
|
|
||||||
|
[Desc("The terrain types that this actor should avoid wandering on to.")]
|
||||||
|
public readonly HashSet<string> AvoidTerrainTypes = new HashSet<string>();
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new Wanders(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new Wanders(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +80,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var targetCell = PickTargetLocation();
|
var targetCell = PickTargetLocation();
|
||||||
if (targetCell != CPos.Zero)
|
if (targetCell.HasValue)
|
||||||
DoAction(self, targetCell);
|
DoAction(self, targetCell.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyIdle.TickIdle(Actor self)
|
void INotifyIdle.TickIdle(Actor self)
|
||||||
@@ -84,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
TickIdle(self);
|
TickIdle(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPos PickTargetLocation()
|
CPos? PickTargetLocation()
|
||||||
{
|
{
|
||||||
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);
|
||||||
@@ -95,7 +100,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (++ticksIdle % info.ReduceMoveRadiusDelay == 0)
|
if (++ticksIdle % info.ReduceMoveRadiusDelay == 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
|
// We'll be back the next tick; better to sit idle for a few seconds than prolong this tick indefinitely with a loop
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.AvoidTerrainTypes.Count > 0)
|
||||||
|
{
|
||||||
|
var terrainType = self.World.Map.GetTerrainInfo(targetCell).Type;
|
||||||
|
if (Info.AvoidTerrainTypes.Contains(terrainType))
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ticksIdle = 0;
|
ticksIdle = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user