Add a subCell parameter to IPositionableInfo.CanEnterCell

This commit is contained in:
abcdefg30
2019-10-12 12:07:02 +02:00
committed by teinarss
parent 980c1e1b6a
commit 4717e98c48
8 changed files with 19 additions and 14 deletions

View File

@@ -324,7 +324,7 @@ namespace OpenRA.Traits
public interface IPositionableInfo : IOccupySpaceInfo
{
bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All);
bool CanEnterCell(World world, Actor self, CPos cell, SubCell subCell = SubCell.FullCell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All);
}
public interface IPositionable : IOccupySpace

View File

@@ -47,12 +47,9 @@ namespace OpenRA.Mods.Cnc.Traits
bool IOccupySpaceInfo.SharesCell { get { return false; } }
// Used to determine if actor can spawn
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
public bool CanEnterCell(World world, Actor self, CPos cell, SubCell subCell = SubCell.FullCell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
{
if (!world.Map.Contains(cell))
return false;
return true;
return world.Map.Contains(cell);
}
}

View File

@@ -158,7 +158,7 @@ namespace OpenRA.Mods.Common.Traits
bool IOccupySpaceInfo.SharesCell { get { return false; } }
// Used to determine if an aircraft can spawn landed
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
public bool CanEnterCell(World world, Actor self, CPos cell, SubCell subCell = SubCell.FullCell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
{
if (!world.Map.Contains(cell))
return false;
@@ -173,6 +173,7 @@ namespace OpenRA.Mods.Common.Traits
if (check == BlockedByActor.None)
return true;
// Since aircraft don't share cells, we don't pass the subCell parameter
return !world.ActorMap.GetActorsAt(cell).Any(x => x != ignoreActor);
}

View File

@@ -40,8 +40,9 @@ namespace OpenRA.Mods.Common.Traits
bool IOccupySpaceInfo.SharesCell { get { return false; } }
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
public bool CanEnterCell(World world, Actor self, CPos cell, SubCell subCell = SubCell.FullCell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
{
// Since crates don't share cells and GetAvailableSubCell only returns SubCell.Full or SubCell.Invalid, we ignore the subCell parameter
return GetAvailableSubCell(world, cell, ignoreActor, check) != SubCell.Invalid;
}

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
bool IOccupySpaceInfo.SharesCell { get { return false; } }
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
public bool CanEnterCell(World world, Actor self, CPos cell, SubCell subCell = SubCell.FullCell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
{
// IPositionable*Info*.CanEnterCell is only ever used for things like exiting production facilities,
// all places relevant for husks check IPositionable.CanEnterCell instead, so we can safely set this to true.

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits
// initialized and used by CanEnterCell
Locomotor locomotor;
public bool CanEnterCell(World world, Actor self, CPos cell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
public bool CanEnterCell(World world, Actor self, CPos cell, SubCell subCell = SubCell.FullCell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
{
// PERF: Avoid repeated trait queries on the hot path
if (locomotor == null)
@@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits
if (locomotor.MovementCostForCell(cell) == short.MaxValue)
return false;
return locomotor.CanMoveFreelyInto(self, cell, check, ignoreActor);
return locomotor.CanMoveFreelyInto(self, cell, subCell, check, ignoreActor);
}
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
@@ -501,7 +501,7 @@ namespace OpenRA.Mods.Common.Traits
public bool CanEnterCell(CPos cell, Actor ignoreActor = null, BlockedByActor check = BlockedByActor.All)
{
return Info.CanEnterCell(self.World, self, cell, ignoreActor, check);
return Info.CanEnterCell(self.World, self, cell, SubCell.FullCell, ignoreActor, check);
}
#endregion

View File

@@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits
self.NotifyBlocker(self.Location + s.ExitCell);
return mobileInfo == null ||
mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, self);
mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, ignoreActor: self);
}
}
}

View File

@@ -246,6 +246,11 @@ namespace OpenRA.Mods.Common.Traits
// Determines whether the actor is blocked by other Actors
public bool CanMoveFreelyInto(Actor actor, CPos cell, BlockedByActor check, Actor ignoreActor)
{
return CanMoveFreelyInto(actor, cell, SubCell.FullCell, check, ignoreActor);
}
public bool CanMoveFreelyInto(Actor actor, CPos cell, SubCell subCell, BlockedByActor check, Actor ignoreActor)
{
var cellCache = GetCache(cell);
var cellFlag = cellCache.CellFlag;
@@ -296,7 +301,8 @@ namespace OpenRA.Mods.Common.Traits
return false;
}
foreach (var otherActor in world.ActorMap.GetActorsAt(cell))
var otherActors = subCell == SubCell.FullCell ? world.ActorMap.GetActorsAt(cell) : world.ActorMap.GetActorsAt(cell, subCell);
foreach (var otherActor in otherActors)
if (IsBlockedBy(actor, otherActor, ignoreActor, check, cellFlag))
return false;