Merge pull request #6550 from pchote/more-bounds-fixes

More map-bounds fixes
This commit is contained in:
Matthias Mailänder
2014-09-24 21:23:50 +02:00
2 changed files with 17 additions and 2 deletions

View File

@@ -119,22 +119,31 @@ namespace OpenRA.Traits
// NOTE: always includes transients with influence // NOTE: always includes transients with influence
public bool AnyUnitsAt(CPos a) public bool AnyUnitsAt(CPos a)
{ {
if (!map.Contains(a))
return false;
return influence[a] != null; return influence[a] != null;
} }
// NOTE: can not check aircraft // NOTE: can not check aircraft
public bool AnyUnitsAt(CPos a, SubCell sub, bool checkTransient = true) public bool AnyUnitsAt(CPos a, SubCell sub, bool checkTransient = true)
{ {
bool always = sub == SubCell.FullCell || sub == SubCell.Any; if (!map.Contains(a))
return false;
var always = sub == SubCell.FullCell || sub == SubCell.Any;
for (var i = influence[a]; i != null; i = i.Next) for (var i = influence[a]; i != null; i = i.Next)
{
if (always || i.SubCell == sub || i.SubCell == SubCell.FullCell) if (always || i.SubCell == sub || i.SubCell == SubCell.FullCell)
{ {
if (checkTransient) if (checkTransient)
return true; return true;
var pos = i.Actor.TraitOrDefault<IPositionable>(); var pos = i.Actor.TraitOrDefault<IPositionable>();
if (pos == null || !pos.IsLeavingCell(a, i.SubCell)) if (pos == null || !pos.IsLeavingCell(a, i.SubCell))
return true; return true;
} }
}
return false; return false;
} }
@@ -142,7 +151,10 @@ namespace OpenRA.Traits
// NOTE: can not check aircraft // NOTE: can not check aircraft
public bool AnyUnitsAt(CPos a, SubCell sub, Func<Actor, bool> withCondition) public bool AnyUnitsAt(CPos a, SubCell sub, Func<Actor, bool> withCondition)
{ {
bool always = sub == SubCell.FullCell || sub == SubCell.Any; if (!map.Contains(a))
return false;
var always = sub == SubCell.FullCell || sub == SubCell.Any;
for (var i = influence[a]; i != null; i = i.Next) for (var i = influence[a]; i != null; i = i.Next)
if (always || i.SubCell == sub || i.SubCell == SubCell.FullCell) if (always || i.SubCell == sub || i.SubCell == SubCell.FullCell)
if (withCondition(i.Actor)) if (withCondition(i.Actor))

View File

@@ -95,6 +95,9 @@ namespace OpenRA.Mods.RA
{ {
var world = firedBy.World; var world = firedBy.World;
var targetTile = world.Map.CellContaining(pos); var targetTile = world.Map.CellContaining(pos);
if (!world.Map.Contains(targetTile))
return false;
var impactType = GetImpactType(world, targetTile, pos); var impactType = GetImpactType(world, targetTile, pos);
if (!ValidImpactTypes.HasFlag(impactType) || InvalidImpactTypes.HasFlag(impactType)) if (!ValidImpactTypes.HasFlag(impactType) || InvalidImpactTypes.HasFlag(impactType))
return false; return false;