diff options
Diffstat (limited to 'engines/lure/hotspots.cpp')
-rw-r--r-- | engines/lure/hotspots.cpp | 295 |
1 files changed, 149 insertions, 146 deletions
diff --git a/engines/lure/hotspots.cpp b/engines/lure/hotspots.cpp index 207c125a0c..2f6d0f23aa 100644 --- a/engines/lure/hotspots.cpp +++ b/engines/lure/hotspots.cpp @@ -4164,6 +4164,7 @@ PathFinderResult PathFinder::process() { bool altFlag; uint16 *pCurrent; PathFinderResult result = PF_UNFINISHED; + bool skipToFinalStep = false; if (!_inProgress) { // Following code only done during first call to method @@ -4186,188 +4187,190 @@ PathFinderResult PathFinder::process() { _inProgress = false; result = PF_OK; - goto final_step; - } - - // Path finding + skipToFinalStep = true; + } else { + // Path finding - _destX >>= 3; - _destY >>= 3; - _pSrc = &_layer[(_yCurrent + 1) * DECODED_PATHS_WIDTH + 1 + _xCurrent]; - _pDest = &_layer[(_yDestCurrent + 1) * DECODED_PATHS_WIDTH + 1 + _xDestCurrent]; + _destX >>= 3; + _destY >>= 3; + _pSrc = &_layer[(_yCurrent + 1) * DECODED_PATHS_WIDTH + 1 + _xCurrent]; + _pDest = &_layer[(_yDestCurrent + 1) * DECODED_PATHS_WIDTH + 1 + _xDestCurrent]; - // Flag starting/ending cells - *_pSrc = 1; - _destOccupied = *_pDest != 0; - result = _destOccupied ? PF_DEST_OCCUPIED : PF_OK; - *_pDest = 0; + // Flag starting/ending cells + *_pSrc = 1; + _destOccupied = *_pDest != 0; + result = _destOccupied ? PF_DEST_OCCUPIED : PF_OK; + *_pDest = 0; - // Set up the current pointer, adjusting away from edges if necessary + // Set up the current pointer, adjusting away from edges if necessary - if (_xCurrent >= _xDestCurrent) { - _xChangeInc = -1; - _xChangeStart = ROOM_PATHS_WIDTH; - } else { - _xChangeInc = 1; - _xChangeStart = 1; - } + if (_xCurrent >= _xDestCurrent) { + _xChangeInc = -1; + _xChangeStart = ROOM_PATHS_WIDTH; + } else { + _xChangeInc = 1; + _xChangeStart = 1; + } - if (_yCurrent >= _yDestCurrent) { - _yChangeInc = -1; - _yChangeStart = ROOM_PATHS_HEIGHT; - } else { - _yChangeInc = 1; - _yChangeStart = 1; + if (_yCurrent >= _yDestCurrent) { + _yChangeInc = -1; + _yChangeStart = ROOM_PATHS_HEIGHT; + } else { + _yChangeInc = 1; + _yChangeStart = 1; + } } } - // Major loop to populate data - _cellPopulated = false; - - while (1) { - // Loop through to process cells in the given area - if (!returnFlag) _yCtr = 0; - while (returnFlag || (_yCtr < ROOM_PATHS_HEIGHT)) { - if (!returnFlag) _xCtr = 0; + if (!skipToFinalStep) { + // Major loop to populate data + _cellPopulated = false; - while (returnFlag || (_xCtr < ROOM_PATHS_WIDTH)) { - if (!returnFlag) { - processCell(&_layer[(_yChangeStart + _yCtr * _yChangeInc) * DECODED_PATHS_WIDTH + - (_xChangeStart + _xCtr * _xChangeInc)]); - if (breakFlag && (_countdownCtr <= 0)) return PF_UNFINISHED; - } else { - returnFlag = false; + while (1) { + // Loop through to process cells in the given area + if (!returnFlag) _yCtr = 0; + while (returnFlag || (_yCtr < ROOM_PATHS_HEIGHT)) { + if (!returnFlag) _xCtr = 0; + + while (returnFlag || (_xCtr < ROOM_PATHS_WIDTH)) { + if (!returnFlag) { + processCell(&_layer[(_yChangeStart + _yCtr * _yChangeInc) * DECODED_PATHS_WIDTH + + (_xChangeStart + _xCtr * _xChangeInc)]); + if (breakFlag && (_countdownCtr <= 0)) return PF_UNFINISHED; + } else { + returnFlag = false; + } + ++_xCtr; } - ++_xCtr; + ++_yCtr; } - ++_yCtr; - } - // If the destination cell has been filled in, then break out of loop - if (*_pDest != 0) break; + // If the destination cell has been filled in, then break out of loop + if (*_pDest != 0) break; - if (_cellPopulated) { - // At least one cell populated, so go repeat loop - _cellPopulated = false; - } else { - result = PF_PART_PATH; - scanFlag = true; - break; + if (_cellPopulated) { + // At least one cell populated, so go repeat loop + _cellPopulated = false; + } else { + result = PF_PART_PATH; + scanFlag = true; + break; + } } - } - _inProgress = false; + _inProgress = false; - if (scanFlag || _destOccupied) { - // Adjust the end point if necessary to stop character walking into occupied area + if (scanFlag || _destOccupied) { + // Adjust the end point if necessary to stop character walking into occupied area - // Restore destination's occupied state if necessary - if (_destOccupied) { - *_pDest = 0xffff; - _destOccupied = false; - } + // Restore destination's occupied state if necessary + if (_destOccupied) { + *_pDest = 0xffff; + _destOccupied = false; + } - // Scan through lines - v = 0xff; - pTemp = _pDest; - scanLine(_destX, -1, pTemp, v); - scanLine(ROOM_PATHS_WIDTH - _destX, 1, pTemp, v); - scanLine(_destY, -DECODED_PATHS_WIDTH, pTemp, v); - scanLine(ROOM_PATHS_HEIGHT - _destY, DECODED_PATHS_WIDTH, pTemp, v); + // Scan through lines + v = 0xff; + pTemp = _pDest; + scanLine(_destX, -1, pTemp, v); + scanLine(ROOM_PATHS_WIDTH - _destX, 1, pTemp, v); + scanLine(_destY, -DECODED_PATHS_WIDTH, pTemp, v); + scanLine(ROOM_PATHS_HEIGHT - _destY, DECODED_PATHS_WIDTH, pTemp, v); + + if (pTemp == _pDest) { + clear(); + return PF_NO_WALK; + } - if (pTemp == _pDest) { - clear(); - return PF_NO_WALK; + _pDest = pTemp; } - _pDest = pTemp; - } + // ****DEBUG**** + if (_hotspot->hotspotId() == PLAYER_ID) { + for (int ctr = 0; ctr < DECODED_PATHS_WIDTH * DECODED_PATHS_HEIGHT; ++ctr) + Room::getReference().tempLayer[ctr] = _layer[ctr]; + } - // ****DEBUG**** - if (_hotspot->hotspotId() == PLAYER_ID) { - for (int ctr = 0; ctr < DECODED_PATHS_WIDTH * DECODED_PATHS_HEIGHT; ++ctr) - Room::getReference().tempLayer[ctr] = _layer[ctr]; - } + // Determine the walk path by working backwards from the destination, adding in the + // walking steps in reverse order until source is reached + int stageCtr; + for (stageCtr = 0; stageCtr < 3; ++stageCtr) { + // Clear out any previously determined directions + clear(); - // Determine the walk path by working backwards from the destination, adding in the - // walking steps in reverse order until source is reached - int stageCtr; - for (stageCtr = 0; stageCtr < 3; ++stageCtr) { - // Clear out any previously determined directions - clear(); + altFlag = stageCtr == 1; + pCurrent = _pDest; + + numSteps = 0; + currDirection = NO_DIRECTION; + while (1) { + v = *pCurrent - 1; + if (v == 0) break; + + newDirection = NO_DIRECTION; + if (!altFlag && (currDirection != LEFT) && (currDirection != RIGHT)) { + // Standard order direction checking + if (*(pCurrent - DECODED_PATHS_WIDTH) == v) newDirection = DOWN; + else if (*(pCurrent + DECODED_PATHS_WIDTH) == v) newDirection = UP; + else if (*(pCurrent + 1) == v) newDirection = LEFT; + else if (*(pCurrent - 1) == v) newDirection = RIGHT; + } else { + // Alternate order direction checking + if (*(pCurrent + 1) == v) newDirection = LEFT; + else if (*(pCurrent - 1) == v) newDirection = RIGHT; + else if (*(pCurrent - DECODED_PATHS_WIDTH) == v) newDirection = DOWN; + else if (*(pCurrent + DECODED_PATHS_WIDTH) == v) newDirection = UP; + } + if (newDirection == NO_DIRECTION) + error("Path finding process failed"); - altFlag = stageCtr == 1; - pCurrent = _pDest; + // Process for the specified direction + if (newDirection != currDirection) add(newDirection, 0); - numSteps = 0; - currDirection = NO_DIRECTION; - while (1) { - v = *pCurrent - 1; - if (v == 0) break; - - newDirection = NO_DIRECTION; - if (!altFlag && (currDirection != LEFT) && (currDirection != RIGHT)) { - // Standard order direction checking - if (*(pCurrent - DECODED_PATHS_WIDTH) == v) newDirection = DOWN; - else if (*(pCurrent + DECODED_PATHS_WIDTH) == v) newDirection = UP; - else if (*(pCurrent + 1) == v) newDirection = LEFT; - else if (*(pCurrent - 1) == v) newDirection = RIGHT; - } else { - // Alternate order direction checking - if (*(pCurrent + 1) == v) newDirection = LEFT; - else if (*(pCurrent - 1) == v) newDirection = RIGHT; - else if (*(pCurrent - DECODED_PATHS_WIDTH) == v) newDirection = DOWN; - else if (*(pCurrent + DECODED_PATHS_WIDTH) == v) newDirection = UP; - } - if (newDirection == NO_DIRECTION) - error("Path finding process failed"); - - // Process for the specified direction - if (newDirection != currDirection) add(newDirection, 0); + switch (newDirection) { + case UP: + pCurrent += DECODED_PATHS_WIDTH; + break; - switch (newDirection) { - case UP: - pCurrent += DECODED_PATHS_WIDTH; - break; + case DOWN: + pCurrent -= DECODED_PATHS_WIDTH; + break; - case DOWN: - pCurrent -= DECODED_PATHS_WIDTH; - break; + case LEFT: + ++pCurrent; + break; - case LEFT: - ++pCurrent; - break; + case RIGHT: + --pCurrent; + break; - case RIGHT: - --pCurrent; - break; + default: + break; + } - default: - break; + ++numSteps; + top().rawSteps() += 8; + currDirection = newDirection; } - ++numSteps; - top().rawSteps() += 8; - currDirection = newDirection; + if (stageCtr == 0) + // Save the number of steps needed + savedSteps = numSteps; + if ((stageCtr == 1) && (numSteps <= savedSteps)) + // Less steps were needed, so break out + break; } - if (stageCtr == 0) - // Save the number of steps needed - savedSteps = numSteps; - if ((stageCtr == 1) && (numSteps <= savedSteps)) - // Less steps were needed, so break out - break; - } - - // Add final movement if necessary + // Add final movement if necessary - if (result == PF_OK) { - if (_xDestPos < 0) - addBack(LEFT, -_xDestPos); - else if (_xDestPos > 0) - addBack(RIGHT, _xDestPos); + if (result == PF_OK) { + if (_xDestPos < 0) + addBack(LEFT, -_xDestPos); + else if (_xDestPos > 0) + addBack(RIGHT, _xDestPos); + } } -final_step: + // Final Step if (_xPos < 0) add(RIGHT, -_xPos); else if (_xPos > 0) add(LEFT, _xPos); |