aboutsummaryrefslogtreecommitdiff
path: root/engines/dm
diff options
context:
space:
mode:
authorStrangerke2016-08-30 23:31:04 +0200
committerStrangerke2016-08-30 23:31:04 +0200
commitff96b8eeb6f5f6e17f630cbf3705b3ae73a5f61b (patch)
tree28198b2587e0168a8563e068fcf83409c257764c /engines/dm
parent95272838e16bb62f708cc37cf13713580b296b5d (diff)
downloadscummvm-rg350-ff96b8eeb6f5f6e17f630cbf3705b3ae73a5f61b.tar.gz
scummvm-rg350-ff96b8eeb6f5f6e17f630cbf3705b3ae73a5f61b.tar.bz2
scummvm-rg350-ff96b8eeb6f5f6e17f630cbf3705b3ae73a5f61b.zip
DM: Refactor a couple of 'if' nightmares in getDistanceBetweenUnblockedSquares
Diffstat (limited to 'engines/dm')
-rw-r--r--engines/dm/group.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/engines/dm/group.cpp b/engines/dm/group.cpp
index 9d453b8ee4..6fd4692543 100644
--- a/engines/dm/group.cpp
+++ b/engines/dm/group.cpp
@@ -1204,13 +1204,24 @@ int16 GroupMan::getDistanceBetweenUnblockedSquares(int16 srcMapX, int16 srcMapY,
|| (CALL_MEMBER_FN(*_vm->_groupMan, isBlocked))(pathMapX = pathMapX + axisStepX, pathMapY = pathMapY + axisStepY))
return 0;
} else {
- if ((valueA = ((largestAxisDistance = (isDistanceXSmallerThanDistanceY ? ((largestAxisDistance = pathMapY - srcMapY) ? ((pathMapX + axisStepX - srcMapX) << 6) / largestAxisDistance : 128) : ((largestAxisDistance = pathMapX + axisStepX - srcMapX) ? ((pathMapY - srcMapY) << 6) / largestAxisDistance : 128)) - valueC) < 0) ? -largestAxisDistance : largestAxisDistance) < (valueB = ((largestAxisDistance = (isDistanceXSmallerThanDistanceY ? ((largestAxisDistance = pathMapY + axisStepY - srcMapY) ? ((pathMapX - srcMapX) << 6) / largestAxisDistance : 128) : ((largestAxisDistance = pathMapX - srcMapX) ? ((pathMapY + axisStepY - srcMapY) << 6) / largestAxisDistance : 128)) - valueC) < 0) ? -largestAxisDistance : largestAxisDistance)) {
- pathMapX += axisStepX;
+ if (isDistanceXSmallerThanDistanceY) {
+ valueA = ABS(((pathMapY - srcMapY) ? ((pathMapX + axisStepX - srcMapX) << 6) / largestAxisDistance : 128) - valueC);
+ valueB = ABS(((pathMapY + axisStepY - srcMapY) ? ((pathMapX - srcMapX) << 6) / largestAxisDistance : 128) - valueC);
} else {
- pathMapY += axisStepY;
+ valueA = ABS(((pathMapX + axisStepX - srcMapX) ? ((pathMapY - srcMapY) << 6) / largestAxisDistance : 128) - valueC);
+ valueB = ABS(((pathMapX - srcMapX) ? ((pathMapY + axisStepY - srcMapY) << 6) / largestAxisDistance : 128) - valueC);
}
- if ((CALL_MEMBER_FN(*_vm->_groupMan, isBlocked))(pathMapX, pathMapY) && ((valueA != valueB) || (CALL_MEMBER_FN(*_vm->_groupMan, isBlocked))(pathMapX = pathMapX + axisStepX, pathMapY = pathMapY - axisStepY))) {
- return 0;
+
+ if (valueA < valueB)
+ pathMapX += axisStepX;
+ else
+ pathMapY += axisStepY;
+
+ if ((CALL_MEMBER_FN(*_vm->_groupMan, isBlocked))(pathMapX, pathMapY)) {
+ pathMapX += axisStepX;
+ pathMapY -= axisStepY;
+ if (((valueA != valueB) || (CALL_MEMBER_FN(*_vm->_groupMan, isBlocked))(pathMapX, pathMapY)))
+ return 0;
}
}
} while (getDistance(pathMapX, pathMapY, srcMapX, srcMapY) > 1);