Add plumbing to support ownership checks in MobileInfo.CanEnterCell.

This commit is contained in:
Paul Chote
2011-07-10 16:54:56 +12:00
parent 47ba4cb285
commit 64b88819a9
9 changed files with 25 additions and 23 deletions

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Mods.RA.Move
{SubCell.FullCell, new int2(0,0)},
};
public bool CanEnterCell(World world, int2 cell, Actor ignoreActor, bool checkTransientActors)
public bool CanEnterCell(World world, Player owner, int2 cell, Actor ignoreActor, bool checkTransientActors)
{
if (MovementCostForCell(world, cell) == int.MaxValue)
return false;
@@ -326,7 +326,7 @@ namespace OpenRA.Mods.RA.Move
public bool CanEnterCell(int2 cell, Actor ignoreActor, bool checkTransientActors)
{
return Info.CanEnterCell(self.World, cell, ignoreActor, checkTransientActors);
return Info.CanEnterCell(self.World, self.Owner, cell, ignoreActor, checkTransientActors);
}
public void FinishedMoving(Actor self)

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Move
{
this.getPath = (self,mobile) =>
self.World.WorldActor.Trait<PathFinder>().FindPath(
PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, destination, false )
PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, destination, false )
.WithoutLaneBias());
this.destination = destination;
this.nearEnough = 0;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Move
{
this.getPath = (self,mobile) =>
self.World.WorldActor.Trait<PathFinder>().FindPath(
PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, destination, false )
PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, destination, false )
.WithIgnoredBuilding( ignoreBuilding ));
this.destination = destination;

View File

@@ -54,8 +54,8 @@ namespace OpenRA.Mods.RA.Move
var mi = self.Info.Traits.Get<MobileInfo>();
var pb = FindBidiPath(
PathSearch.FromPoint(world, mi, target, from, true),
PathSearch.FromPoint(world, mi, from, target, true)
PathSearch.FromPoint(world, mi, self.Owner, target, from, true),
PathSearch.FromPoint(world, mi, self.Owner, from, target, true)
.InReverse());
CheckSanePath2(pb, from, target);
@@ -72,11 +72,11 @@ namespace OpenRA.Mods.RA.Move
{
var mi = self.Info.Traits.Get<MobileInfo>();
var tilesInRange = world.FindTilesInCircle(target, range)
.Where( t => mi.CanEnterCell(self.World, t, null, true));
.Where( t => mi.CanEnterCell(self.World, self.Owner, t, null, true));
var path = FindBidiPath(
PathSearch.FromPoints(world, mi, tilesInRange, src, true),
PathSearch.FromPoint(world, mi, src, target, true)
PathSearch.FromPoints(world, mi, self.Owner, tilesInRange, src, true),
PathSearch.FromPoint(world, mi, self.Owner, src, target, true)
.InReverse());
return path;

View File

@@ -27,12 +27,14 @@ namespace OpenRA.Mods.RA.Move
public bool inReverse;
MobileInfo mobileInfo;
Player owner;
public PathSearch(World world, MobileInfo mobileInfo)
public PathSearch(World world, MobileInfo mobileInfo, Player owner)
{
this.world = world;
cellInfo = InitCellInfo();
this.mobileInfo = mobileInfo;
this.owner = owner;
queue = new PriorityQueue<PathDistance>();
}
@@ -103,7 +105,7 @@ namespace OpenRA.Mods.RA.Move
if (costHere == int.MaxValue)
continue;
if (!mobileInfo.CanEnterCell(world, newHere, ignoreBuilding, checkForBlocked))
if (!mobileInfo.CanEnterCell(world, owner, newHere, ignoreBuilding, checkForBlocked))
continue;
if (customBlock != null && customBlock(newHere))
@@ -160,16 +162,16 @@ namespace OpenRA.Mods.RA.Move
queue.Add( new PathDistance( heuristic( location ), location ) );
}
public static PathSearch Search( World world, MobileInfo mi, bool checkForBlocked )
public static PathSearch Search( World world, MobileInfo mi, Player owner, bool checkForBlocked )
{
var search = new PathSearch(world, mi) {
var search = new PathSearch(world, mi, owner) {
checkForBlocked = checkForBlocked };
return search;
}
public static PathSearch FromPoint( World world, MobileInfo mi, int2 from, int2 target, bool checkForBlocked )
public static PathSearch FromPoint( World world, MobileInfo mi, Player owner, int2 from, int2 target, bool checkForBlocked )
{
var search = new PathSearch(world, mi) {
var search = new PathSearch(world, mi, owner) {
heuristic = DefaultEstimator( target ),
checkForBlocked = checkForBlocked };
@@ -177,9 +179,9 @@ namespace OpenRA.Mods.RA.Move
return search;
}
public static PathSearch FromPoints(World world, MobileInfo mi, IEnumerable<int2> froms, int2 target, bool checkForBlocked)
public static PathSearch FromPoints(World world, MobileInfo mi, Player owner, IEnumerable<int2> froms, int2 target, bool checkForBlocked)
{
var search = new PathSearch(world, mi)
var search = new PathSearch(world, mi, owner)
{
heuristic = DefaultEstimator(target),
checkForBlocked = checkForBlocked