Add a subCell parameter to IPositionableInfo.CanEnterCell
This commit is contained in:
@@ -324,7 +324,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public interface IPositionableInfo : IOccupySpaceInfo
|
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
|
public interface IPositionable : IOccupySpace
|
||||||
|
|||||||
@@ -47,12 +47,9 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
||||||
|
|
||||||
// Used to determine if actor can spawn
|
// 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 world.Map.Contains(cell);
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
||||||
|
|
||||||
// Used to determine if an aircraft can spawn landed
|
// 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))
|
if (!world.Map.Contains(cell))
|
||||||
return false;
|
return false;
|
||||||
@@ -173,6 +173,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (check == BlockedByActor.None)
|
if (check == BlockedByActor.None)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// Since aircraft don't share cells, we don't pass the subCell parameter
|
||||||
return !world.ActorMap.GetActorsAt(cell).Any(x => x != ignoreActor);
|
return !world.ActorMap.GetActorsAt(cell).Any(x => x != ignoreActor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
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;
|
return GetAvailableSubCell(world, cell, ignoreActor, check) != SubCell.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
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,
|
// 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.
|
// all places relevant for husks check IPositionable.CanEnterCell instead, so we can safely set this to true.
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
// initialized and used by CanEnterCell
|
// initialized and used by CanEnterCell
|
||||||
Locomotor locomotor;
|
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
|
// PERF: Avoid repeated trait queries on the hot path
|
||||||
if (locomotor == null)
|
if (locomotor == null)
|
||||||
@@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (locomotor.MovementCostForCell(cell) == short.MaxValue)
|
if (locomotor.MovementCostForCell(cell) == short.MaxValue)
|
||||||
return false;
|
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)
|
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)
|
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
|
#endregion
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self.NotifyBlocker(self.Location + s.ExitCell);
|
self.NotifyBlocker(self.Location + s.ExitCell);
|
||||||
|
|
||||||
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, ignoreActor: self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,6 +246,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
// Determines whether the actor is blocked by other Actors
|
// Determines whether the actor is blocked by other Actors
|
||||||
public bool CanMoveFreelyInto(Actor actor, CPos cell, BlockedByActor check, Actor ignoreActor)
|
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 cellCache = GetCache(cell);
|
||||||
var cellFlag = cellCache.CellFlag;
|
var cellFlag = cellCache.CellFlag;
|
||||||
@@ -296,7 +301,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return false;
|
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))
|
if (IsBlockedBy(actor, otherActor, ignoreActor, check, cellFlag))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user