From 6d2edf2b993283513c3ccaeb583bf0e8a9321a2f Mon Sep 17 00:00:00 2001 From: rt Date: Sun, 25 Mar 2018 22:27:02 +0200 Subject: [PATCH] fix #5939 --- rts/Sim/MoveTypes/GroundMoveType.cpp | 45 +++++++++++++--------------- rts/Sim/MoveTypes/MoveDefHandler.cpp | 8 ++--- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/rts/Sim/MoveTypes/GroundMoveType.cpp b/rts/Sim/MoveTypes/GroundMoveType.cpp index 21d12a9c854..0cc799dbfa7 100644 --- a/rts/Sim/MoveTypes/GroundMoveType.cpp +++ b/rts/Sim/MoveTypes/GroundMoveType.cpp @@ -371,9 +371,9 @@ void CGroundMoveType::UpdateOwnerSpeedAndHeading() void CGroundMoveType::SlowUpdate() { if (owner->GetTransporter() != nullptr) { - if (progressState == Active) { + if (progressState == Active) StopEngine(false); - } + } else { if (progressState == Active) { if (pathID != 0) { @@ -400,18 +400,15 @@ void CGroundMoveType::SlowUpdate() LOG_L(L_DEBUG, "SlowUpdate: unit %i has no path", owner->id); ReRequestPath(true); } - if (wantRepath) { + + if (wantRepath) ReRequestPath(true); - } } - if (!owner->IsFlying()) { - // move us into the map, and update - // to prevent any extreme changes in - if (!owner->pos.IsInBounds()) { - owner->Move(oldPos = owner->pos.cClampInBounds(), false); - } - } + // move us into the map, and update + // to prevent any extreme changes in + if (!owner->IsFlying() && !owner->pos.IsInBounds()) + owner->Move(oldPos = owner->pos.cClampInBounds(), false); } AMoveType::SlowUpdate(); @@ -1405,8 +1402,8 @@ bool CGroundMoveType::CanGetNextWayPoint() { const MoveDef* ownerMD = owner->moveDef; - for (int x = xmin; x < xmax; x++) { - for (int z = zmin; z < zmax; z++) { + for (int z = zmin; z < zmax; z++) { + for (int x = xmin; x < xmax; x++) { if (ownerMD->TestMoveSquare(owner, x, z, owner->speed, true, true, true)) continue; @@ -1600,7 +1597,7 @@ void CGroundMoveType::HandleObjectCollisions() // _minimally bounding_ the footprint (assuming square shape) // const float colliderSpeed = collider->speed.w; - const float colliderRadius = colliderMD->CalcFootPrintRadius(1.0f); + const float colliderRadius = colliderMD->CalcFootPrintRadius(0.75f); HandleUnitCollisions(collider, colliderSpeed, colliderRadius, colliderUD, colliderMD); HandleFeatureCollisions(collider, colliderSpeed, colliderRadius, colliderUD, colliderMD); @@ -1612,9 +1609,10 @@ void CGroundMoveType::HandleObjectCollisions() const bool squareChange = (CGround::GetSquare(owner->pos + owner->speed) != CGround::GetSquare(owner->pos)); const bool checkAllowed = ((collider->id & 1) == (gs->frameNum & 1)); - if (squareChange || checkAllowed) { - HandleStaticObjectCollision(owner, owner, owner->moveDef, colliderRadius, 0.0f, ZeroVector, true, false, true); - } + if (!squareChange && !checkAllowed) + return; + + HandleStaticObjectCollision(owner, owner, owner->moveDef, colliderRadius, 0.0f, ZeroVector, true, false, true); } } @@ -1754,7 +1752,7 @@ void CGroundMoveType::HandleStaticObjectCollision( if (colliderMD->TestMoveSquare(collider, collider->pos + strafeVec + bounceVec, collider->speed, checkTerrain, checkYardMap, checkTerrain)) { collider->Move(strafeVec + bounceVec, true); } else { - collider->Move(oldPos - collider->pos, wantRequestPath = true); + collider->Move(oldPos - collider->pos, true); } } @@ -1784,18 +1782,17 @@ void CGroundMoveType::HandleStaticObjectCollision( // this means deltaSpeed will be non-zero if stuck on an impassable square and hence // the new speedvector which is constructed from deltaSpeed --> we would simply keep // moving forward through obstacles if not counteracted by this - if (collider->frontdir.dot(separationVector) < 0.25f) { - collider->Move(oldPos - collider->pos, wantRequestPath = true); - } + collider->Move((oldPos - collider->pos) * (collider->frontdir.dot(separationVector) < 0.25f), true); } // same here wantRequestPath = (penDistance < 0.0f); } - if (canRequestPath && wantRequestPath) { - ReRequestPath(false); - } + if (!canRequestPath || !wantRequestPath) + return; + + ReRequestPath(false); } diff --git a/rts/Sim/MoveTypes/MoveDefHandler.cpp b/rts/Sim/MoveTypes/MoveDefHandler.cpp index c0876682c7d..2147a961b45 100644 --- a/rts/Sim/MoveTypes/MoveDefHandler.cpp +++ b/rts/Sim/MoveTypes/MoveDefHandler.cpp @@ -333,16 +333,16 @@ bool MoveDef::TestMoveSquare( assert(testTerrain || testObjects); - float minSpeedMod = std::numeric_limits::max();; - CMoveMath::BlockType maxBlockBit = CMoveMath::BLOCK_NONE; + float minSpeedMod = std::numeric_limits::max(); + int maxBlockBit = CMoveMath::BLOCK_NONE; const int zMin = -zsizeh * (1 - centerOnly), zMax = zsizeh * (1 - centerOnly); const int xMin = -xsizeh * (1 - centerOnly), xMax = xsizeh * (1 - centerOnly); const float3 testMoveDir2D = (testMoveDir * XZVector).SafeNormalize2D(); - for (int z = zMin; z <= zMax && retTestMove; z++) { - for (int x = xMin; x <= xMax && retTestMove; x++) { + for (int z = zMin; retTestMove && z <= zMax; z += 1) { + for (int x = xMin; retTestMove && x <= xMax; x += 1) { const float speedMod = CMoveMath::GetPosSpeedMod(*this, xTestMoveSqr + x, zTestMoveSqr + z, testMoveDir2D); minSpeedMod = std::min(minSpeedMod, speedMod);