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

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Activities
var mobile = self.Trait<Mobile>();
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
var res = self.World.WorldActor.Trait<ResourceLayer>();
var path = self.World.WorldActor.Trait<PathFinder>().FindPath(PathSearch.Search(self.World, mobileInfo, true)
var path = self.World.WorldActor.Trait<PathFinder>().FindPath(PathSearch.Search(self.World, mobileInfo, self.Owner, true)
.WithHeuristic(loc => (res.GetResource(loc) != null && harvInfo.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1)
.FromPoint(self.Location));

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Activities
cells = new OpenRA.FileFormats.Pair<int2, SubCell>[] {
Pair.New(target.Location, SubCell.FullCell) };
var ps1 = new PathSearch( self.World, mobile.Info )
var ps1 = new PathSearch( self.World, mobile.Info, self.Owner )
{
checkForBlocked = true,
heuristic = location => 0,
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Activities
}
ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell );
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, target.Location, true );
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, target.Location, true );
var ret = self.World.WorldActor.Trait<PathFinder>().FindBidiPath( ps1, ps2 );
if( ret.Count > 0 )
ret.RemoveAt( 0 );

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Crates
var mi = Rules.Info[Info.Unit].Traits.GetOrDefault<MobileInfo>();
for (var i = -1; i < 2; i++)
for (var j = -1; j < 2; j++)
if (mi.CanEnterCell(self.World, near + new int2(i, j), null, true))
if (mi.CanEnterCell(self.World, self.Owner, near + new int2(i, j), null, true))
yield return near + new int2(i, j);
}

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Mods.RA
.ToList();
var mi = self.Info.Traits.Get<MobileInfo>();
var path = self.World.WorldActor.Trait<PathFinder>().FindPath(
PathSearch.FromPoints(self.World, mi,
PathSearch.FromPoints(self.World, mi, self.Owner,
refs.Select(r => r.Actor.Location + r.Trait.DeliverOffset),
self.Location, false));
path.Reverse();

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

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.RA
var mobileInfo = producee.Traits.GetOrDefault<MobileInfo>();
return mobileInfo == null ||
mobileInfo.CanEnterCell(self.World, self.Location + s.ExitCell, self, true);
mobileInfo.CanEnterCell(self.World, self.Owner, self.Location + s.ExitCell, self, true);
}
}
}