Skip to content

Commit

Permalink
Fix #5302
Browse files Browse the repository at this point in the history
  • Loading branch information
ashdnazg committed Jul 16, 2016
1 parent ea75a8a commit 0354b34
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
11 changes: 4 additions & 7 deletions rts/Sim/MoveTypes/MoveDefHandler.cpp
Expand Up @@ -350,13 +350,10 @@ bool MoveDef::TestMoveSquare(

// GetPosSpeedMod only checks *one* square of terrain
// (heightmap/slopemap/typemap), not the blocking-map
for (int z = zMin; (z <= zMax) && retTestMove; z++) {
for (int x = xMin; (x <= xMax) && retTestMove; x++) {
const CMoveMath::BlockType blockBits = CMoveMath::SquareIsBlocked(*this, xTestMoveSqr + x, zTestMoveSqr + z, collider);

maxBlockBit |= blockBits;
retTestMove &= (!testObjects || (blockBits & CMoveMath::BLOCK_STRUCTURE) == 0);
}
if (retTestMove) {
const CMoveMath::BlockType blockBits = CMoveMath::RangeIsBlocked(*this, xTestMoveSqr + xMin, xTestMoveSqr + xMax, zTestMoveSqr + zMin, zTestMoveSqr + zMax, collider);
maxBlockBit |= blockBits;
retTestMove &= (!testObjects || (blockBits & CMoveMath::BLOCK_STRUCTURE) == 0);
}

// don't use std::min or |= because the values might be garbage
Expand Down
34 changes: 33 additions & 1 deletion rts/Sim/MoveTypes/MoveMath/MoveMath.cpp
Expand Up @@ -106,14 +106,14 @@ float CMoveMath::GetPosSpeedMod(const MoveDef& moveDef, unsigned xSquare, unsign
/* Check if a given square-position is accessable by the MoveDef footprint. */
CMoveMath::BlockType CMoveMath::IsBlockedNoSpeedModCheck(const MoveDef& moveDef, int xSquare, int zSquare, const CSolidObject* collider)
{
BlockType ret = BLOCK_NONE;
const int xmin = xSquare - moveDef.xsizeh, xmax = xSquare + moveDef.xsizeh;
if ((unsigned)xmin >= mapDims.mapx || (unsigned)xmax >= mapDims.mapx)
return BLOCK_IMPASSABLE;
const int zmin = zSquare - moveDef.zsizeh, zmax = zSquare + moveDef.zsizeh;
if ((unsigned)zmin >= mapDims.mapy || (unsigned)zmax >= mapDims.mapy)
return BLOCK_IMPASSABLE;

BlockType ret = BLOCK_NONE;
const int xstep = 2, zstep = 2;

// (footprints are point-symmetric around <xSquare, zSquare>)
Expand Down Expand Up @@ -252,3 +252,35 @@ CMoveMath::BlockType CMoveMath::SquareIsBlocked(const MoveDef& moveDef, int xSqu
return r;
}

CMoveMath::BlockType CMoveMath::RangeIsBlocked(const MoveDef& moveDef, int xmin, int xmax, int zmin, int zmax, const CSolidObject* collider)
{
if ((unsigned)xmin >= mapDims.mapx || (unsigned)xmax >= mapDims.mapx)
return BLOCK_IMPASSABLE;

if ((unsigned)zmin >= mapDims.mapy || (unsigned)zmax >= mapDims.mapy)
return BLOCK_IMPASSABLE;

BlockType ret = BLOCK_NONE;
const int xstep = 2, zstep = 2;
const int tempNum = gs->GetTempNum();

// (footprints are point-symmetric around <xSquare, zSquare>)
for (int z = zmin; z <= zmax; z += zstep) {
const int zOffset = z * mapDims.mapx;
for (int x = xmin; x <= xmax; x += xstep) {
const BlockingMapCell& cell = groundBlockingObjectMap->GetCellUnsafeConst(zOffset + x);
for (CSolidObject* collidee: cell) {
if (collidee->tempNum == tempNum)
continue;

collidee->tempNum = tempNum;
ret |= ObjectBlockType(moveDef, collidee, collider);
if (ret & BLOCK_STRUCTURE)
return ret;
}
}
}

return ret;
}

1 change: 1 addition & 0 deletions rts/Sim/MoveTypes/MoveMath/MoveMath.h
Expand Up @@ -70,6 +70,7 @@ class CMoveMath {
static BlockType SquareIsBlocked(const MoveDef& moveDef, const float3& pos, const CSolidObject* collider) {
return (SquareIsBlocked(moveDef, pos.x / SQUARE_SIZE, pos.z / SQUARE_SIZE, collider));
}
static BlockType RangeIsBlocked(const MoveDef& moveDef, int xmin, int xmax, int zmin, int zmax, const CSolidObject* collider);

public:
static bool noHoverWaterMove;
Expand Down

0 comments on commit 0354b34

Please sign in to comment.