Add AvoidTerrainTypes to ScaredyCat.
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
@@ -28,6 +30,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Chance (out of 100) the unit has to enter panic mode when attacking.")]
|
[Desc("Chance (out of 100) the unit has to enter panic mode when attacking.")]
|
||||||
public readonly int AttackPanicChance = 20;
|
public readonly int AttackPanicChance = 20;
|
||||||
|
|
||||||
|
[Desc("The terrain types that this actor should avoid running on to while panicking.")]
|
||||||
|
public readonly HashSet<string> AvoidTerrainTypes = new HashSet<string>();
|
||||||
|
|
||||||
[SequenceReference(prefix: true)]
|
[SequenceReference(prefix: true)]
|
||||||
public readonly string PanicSequencePrefix = "panic-";
|
public readonly string PanicSequencePrefix = "panic-";
|
||||||
|
|
||||||
@@ -39,6 +44,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly ScaredyCatInfo info;
|
readonly ScaredyCatInfo info;
|
||||||
readonly Mobile mobile;
|
readonly Mobile mobile;
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
|
readonly Func<CPos, bool> avoidTerrainFilter;
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
int panicStartedTick;
|
int panicStartedTick;
|
||||||
@@ -52,6 +58,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
this.self = self;
|
this.self = self;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
|
|
||||||
|
if (info.AvoidTerrainTypes.Count > 0)
|
||||||
|
avoidTerrainFilter = c => info.AvoidTerrainTypes.Contains(self.World.Map.GetTerrainInfo(c).Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Panic()
|
public void Panic()
|
||||||
@@ -79,7 +88,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!Panicking)
|
if (!Panicking)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mobile.Nudge(self);
|
// Note: This is just a modified copy of Mobile.Nudge
|
||||||
|
var cell = mobile.GetAdjacentCell(self.Location, avoidTerrainFilter);
|
||||||
|
if (cell != null)
|
||||||
|
self.QueueActivity(false, mobile.MoveTo(cell.Value, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyDamage.Damaged(Actor self, AttackInfo e)
|
void INotifyDamage.Damaged(Actor self, AttackInfo e)
|
||||||
|
|||||||
@@ -364,14 +364,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.QueueActivity(false, MoveTo(cell.Value, 0));
|
self.QueueActivity(false, MoveTo(cell.Value, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPos? GetAdjacentCell(CPos nextCell)
|
public CPos? GetAdjacentCell(CPos nextCell, Func<CPos, bool> preferToAvoid = null)
|
||||||
{
|
{
|
||||||
var availCells = new List<CPos>();
|
var availCells = new List<CPos>();
|
||||||
var notStupidCells = new List<CPos>();
|
var notStupidCells = new List<CPos>();
|
||||||
foreach (CVec direction in CVec.Directions)
|
foreach (CVec direction in CVec.Directions)
|
||||||
{
|
{
|
||||||
var p = ToCell + direction;
|
var p = ToCell + direction;
|
||||||
if (CanEnterCell(p) && CanStayInCell(p))
|
if (CanEnterCell(p) && CanStayInCell(p) && (preferToAvoid == null || !preferToAvoid(p)))
|
||||||
availCells.Add(p);
|
availCells.Add(p);
|
||||||
else if (p != nextCell && p != ToCell)
|
else if (p != nextCell && p != ToCell)
|
||||||
notStupidCells.Add(p);
|
notStupidCells.Add(p);
|
||||||
|
|||||||
Reference in New Issue
Block a user