NotifyBlocker extension method for Actor
This commit is contained in:
@@ -202,16 +202,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
throw new InvalidOperationException("(Move) Sanity check failed");
|
throw new InvalidOperationException("(Move) Sanity check failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void NotifyBlocker(Actor self, CPos nextCell)
|
|
||||||
{
|
|
||||||
foreach (var blocker in self.World.ActorMap.GetUnitsAt(nextCell))
|
|
||||||
{
|
|
||||||
// Notify the blocker that he's blocking our move:
|
|
||||||
foreach (var moveBlocked in blocker.TraitsImplementing<INotifyBlockingMove>())
|
|
||||||
moveBlocked.OnNotifyBlockingMove(blocker, self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Pair<CPos, SubCell>? PopPath(Actor self, Mobile mobile)
|
Pair<CPos, SubCell>? PopPath(Actor self, Mobile mobile)
|
||||||
{
|
{
|
||||||
if (path.Count == 0)
|
if (path.Count == 0)
|
||||||
@@ -233,7 +223,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
// See if they will move
|
// See if they will move
|
||||||
if (!hasNotifiedBlocker)
|
if (!hasNotifiedBlocker)
|
||||||
{
|
{
|
||||||
NotifyBlocker(self, nextCell);
|
self.NotifyBlocker(nextCell);
|
||||||
hasNotifiedBlocker = true;
|
hasNotifiedBlocker = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,11 +68,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var exitSubCell = ChooseExitSubCell(actor);
|
var exitSubCell = ChooseExitSubCell(actor);
|
||||||
if (exitSubCell == null)
|
if (exitSubCell == null)
|
||||||
{
|
{
|
||||||
foreach (var blocker in BlockedExitCells(actor).SelectMany(p => self.World.ActorMap.GetUnitsAt(p)))
|
self.NotifyBlocker(BlockedExitCells(actor));
|
||||||
{
|
|
||||||
foreach (var nbm in blocker.TraitsImplementing<INotifyBlockingMove>())
|
|
||||||
nbm.OnNotifyBlockingMove(blocker, self);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Util.SequenceActivities(new Wait(10), this);
|
return Util.SequenceActivities(new Wait(10), this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -77,5 +79,24 @@ namespace OpenRA.Mods.Common
|
|||||||
|
|
||||||
return Target.Invalid;
|
return Target.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void NotifyBlocker(this Actor self, IEnumerable<Actor> blockers)
|
||||||
|
{
|
||||||
|
foreach (var blocker in blockers)
|
||||||
|
{
|
||||||
|
foreach (var moveBlocked in blocker.TraitsImplementing<INotifyBlockingMove>())
|
||||||
|
moveBlocked.OnNotifyBlockingMove(blocker, self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void NotifyBlocker(this Actor self, CPos position)
|
||||||
|
{
|
||||||
|
NotifyBlocker(self, self.World.ActorMap.GetUnitsAt(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void NotifyBlocker(this Actor self, IEnumerable<CPos> positions)
|
||||||
|
{
|
||||||
|
NotifyBlocker(self, positions.SelectMany(p => self.World.ActorMap.GetUnitsAt(p)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ using System;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
|
using OpenRA.Mods.Common;
|
||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Mods.RA.Activities;
|
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
@@ -119,12 +119,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
{
|
{
|
||||||
var mobileInfo = producee.Traits.GetOrDefault<MobileInfo>();
|
var mobileInfo = producee.Traits.GetOrDefault<MobileInfo>();
|
||||||
|
|
||||||
foreach (var blocker in self.World.ActorMap.GetUnitsAt(self.Location + s.ExitCell))
|
self.NotifyBlocker(self.Location + s.ExitCell);
|
||||||
{
|
|
||||||
// Notify the blocker that he's blocking our move:
|
|
||||||
foreach (var moveBlocked in blocker.TraitsImplementing<INotifyBlockingMove>())
|
|
||||||
moveBlocked.OnNotifyBlockingMove(blocker, self);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mobileInfo == null ||
|
return mobileInfo == null ||
|
||||||
mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, self);
|
mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, self);
|
||||||
|
|||||||
Reference in New Issue
Block a user