diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gob/goblin_v1.cpp | 6 | ||||
-rw-r--r-- | engines/gob/goblin_v2.cpp | 12 | ||||
-rw-r--r-- | engines/gob/map.cpp | 164 | ||||
-rw-r--r-- | engines/gob/map.h | 26 |
4 files changed, 94 insertions, 114 deletions
diff --git a/engines/gob/goblin_v1.cpp b/engines/gob/goblin_v1.cpp index f55fec433c..ec3d724624 100644 --- a/engines/gob/goblin_v1.cpp +++ b/engines/gob/goblin_v1.cpp @@ -173,10 +173,10 @@ void Goblin_v1::movePathFind(Mult::Mult_Object *obj, _pathExistence = 0; } - nextAct = _vm->_map->getDirection(_vm->_map->_curGoblinX, + nextAct = (int16) _vm->_map->getDirection(_vm->_map->_curGoblinX, _vm->_map->_curGoblinY, _vm->_map->_destX, _vm->_map->_destY); - if (nextAct == 0) + if (nextAct == Map::kDirNone) _pathExistence = 0; } else if (_pathExistence == 3) { _vm->_map->_curGoblinX = _gobPositions[_currentGoblin].x; @@ -229,7 +229,7 @@ void Goblin_v1::movePathFind(Mult::Mult_Object *obj, } } } - nextAct = _vm->_map->getDirection(_vm->_map->_curGoblinX, + nextAct = (int16) _vm->_map->getDirection(_vm->_map->_curGoblinX, _vm->_map->_curGoblinY, _vm->_map->_destX, _vm->_map->_destY); } } diff --git a/engines/gob/goblin_v2.cpp b/engines/gob/goblin_v2.cpp index 4aadb2f82e..0ea3003e96 100644 --- a/engines/gob/goblin_v2.cpp +++ b/engines/gob/goblin_v2.cpp @@ -39,10 +39,10 @@ namespace Gob { Goblin_v2::Goblin_v2(GobEngine *vm) : Goblin_v1(vm) { _gobsCount = -1; - _rotStates[0][0] = 0; _rotStates[0][1] = 18; _rotStates[0][2] = 19; _rotStates[0][3] = 20; - _rotStates[1][0] = 13; _rotStates[1][1] = 2; _rotStates[1][2] = 12; _rotStates[1][3] = 14; - _rotStates[2][0] = 16; _rotStates[2][1] = 15; _rotStates[2][2] = 4; _rotStates[2][3] = 17; - _rotStates[3][0] = 23; _rotStates[3][1] = 21; _rotStates[3][2] = 22; _rotStates[3][3] = 6; + _rotStates[0][0] = 0; _rotStates[0][1] = 18; _rotStates[0][2] = 19; _rotStates[0][3] = 20; + _rotStates[1][0] = 13; _rotStates[1][1] = 2; _rotStates[1][2] = 12; _rotStates[1][3] = 14; + _rotStates[2][0] = 16; _rotStates[2][1] = 15; _rotStates[2][2] = 4; _rotStates[2][3] = 17; + _rotStates[3][0] = 23; _rotStates[3][1] = 21; _rotStates[3][2] = 22; _rotStates[3][3] = 6; } void Goblin_v2::freeObjects() { @@ -142,12 +142,12 @@ void Goblin_v2::movePathFind(Mult::Mult_Object *obj, Gob_Object *gobDesc, int16 animData->destY = gobDestY; animData->order = gobY; - int16 dir = 0; + Map::Direction dir = Map::kDirNone; if (animData->pathExistence == 1) { dir = _vm->_map->getDirection(gobX, gobY, destX, destY); - if (dir == 0) + if (dir == Map::kDirNone) animData->pathExistence = 0; if ((gobX == gobDestX) && (gobY == gobDestY)) animData->pathExistence = 4; diff --git a/engines/gob/map.cpp b/engines/gob/map.cpp index dcd22bcc8b..4fc642572c 100644 --- a/engines/gob/map.cpp +++ b/engines/gob/map.cpp @@ -90,14 +90,14 @@ enum { kDown = (1 << 3) }; -int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { +Map::Direction Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { if ((x0 == x1) && (y0 == y1)) // Already at the destination - return 0; + return kDirNone; if ((x1 < 0) || (x1 > _mapWidth) || (y1 < 0) || (y1 > _mapHeight)) // Destination out of range - return 0; + return kDirNone; int16 dir = 0; @@ -134,7 +134,7 @@ int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return kDirW; // Can't go - return 0; + return kDirNone; } // Want to go left @@ -144,7 +144,7 @@ int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return kDirE; // Can't go - return 0; + return kDirNone; } @@ -163,7 +163,7 @@ int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return kDirNE; // Can't go at all - return 0; + return kDirNone; } // Want to go down @@ -181,7 +181,7 @@ int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return kDirSE; // Can't go at all - return 0; + return kDirNone; } @@ -200,7 +200,7 @@ int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return kDirE; // Can't go at all - return 0; + return kDirNone; } // Want to go down and right @@ -218,7 +218,7 @@ int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return kDirE; // Can't go at all - return 0; + return kDirNone; } // Want to go up and left @@ -236,7 +236,7 @@ int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return kDirW; // Can't go at all - return 0; + return kDirNone; } // Want to go left and down @@ -254,11 +254,11 @@ int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return kDirW; // Can't go at all - return 0; + return kDirNone; } warning("Map::getDirection(): Invalid direction?!?"); - return -1; + return kDirNone; } int16 Map::findNearestWayPoint(int16 x, int16 y) { @@ -350,13 +350,57 @@ void Map::findNearestWalkable(int16 &gobDestX, int16 &gobDestY, gobDestY -= distance; } -int16 Map::checkDirectPath(Mult::Mult_Object *obj, - int16 x0, int16 y0, int16 x1, int16 y1) { +void Map::moveDirection(Direction dir, int16 &x, int16 &y) { + switch (dir) { + case kDirNW: + x--; + y--; + break; + + case kDirN: + y--; + break; + + case kDirNE: + x++; + y--; + break; + + case kDirW: + x--; + break; + + case kDirE: + x++; + break; + + case kDirSW: + x--; + y++; + break; + + case kDirS: + y++; + break; + + case kDirSE: + x++; + y++; + break; + + default: + break; + } +} + +int16 Map::checkDirectPath(Mult::Mult_Object *obj, int16 x0, int16 y0, int16 x1, int16 y1) { while (1) { - uint16 dir = getDirection(x0, y0, x1, y1); + Direction dir = getDirection(x0, y0, x1, y1); if (obj) { + // Check for a blocking waypoint + if (obj->nearestWayPoint < obj->nearestDest) if ((obj->nearestWayPoint + 1) < _wayPointsCount) if (_wayPoints[obj->nearestWayPoint + 1].notWalkable == 1) @@ -369,54 +413,18 @@ int16 Map::checkDirectPath(Mult::Mult_Object *obj, } if ((x0 == x1) && (y0 == y1)) + // Successfully reached the destination return 1; - if (dir == 0) + if (dir == kDirNone) + // No way return 3; - switch (dir) { - case kDirNW: - x0--; - y0--; - break; - - case kDirN: - y0--; - break; - - case kDirNE: - x0++; - y0--; - break; - - case kDirW: - x0--; - break; - - case kDirE: - x0++; - break; - - case kDirSW: - x0--; - y0++; - break; - - case kDirS: - y0++; - break; - - case kDirSE: - x0++; - y0++; - break; - } + moveDirection(dir, x0, y0); } } -int16 Map::checkLongPath(int16 x0, int16 y0, - int16 x1, int16 y1, int16 i0, int16 i1) { - uint16 dir = 0; +int16 Map::checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) { int16 curX = x0; int16 curY = y0; int16 nextLink = 1; @@ -449,47 +457,13 @@ int16 Map::checkLongPath(int16 x0, int16 y0, return 1; return 0; } - dir = getDirection(x0, y0, curX, curY); - switch (dir) { - case 0: - return 0; - - case kDirNW: - x0--; - y0--; - break; - - case kDirN: - y0--; - break; - - case kDirNE: - x0++; - y0--; - break; - - case kDirW: - x0--; - break; - - case kDirE: - x0++; - break; - - case kDirSW: - x0--; - y0++; - break; - case kDirS: - y0++; - break; + Direction dir = getDirection(x0, y0, curX, curY); + if (dir == kDirNone) + // No way + return 0; - case kDirSE: - x0++; - y0++; - break; - } + moveDirection(dir, x0, y0); } } diff --git a/engines/gob/map.h b/engines/gob/map.h index 0593c663cc..c268fbaca5 100644 --- a/engines/gob/map.h +++ b/engines/gob/map.h @@ -34,15 +34,16 @@ namespace Gob { class Map { public: - enum { - kDirNW = 0x4700, - kDirN = 0x4800, - kDirNE = 0x4900, - kDirW = 0x4B00, - kDirE = 0x4D00, - kDirSW = 0x4F00, - kDirS = 0x5000, - kDirSE = 0x5100 + enum Direction { + kDirNone = 0x0000, + kDirNW = 0x4700, + kDirN = 0x4800, + kDirNE = 0x4900, + kDirW = 0x4B00, + kDirE = 0x4D00, + kDirSW = 0x4F00, + kDirS = 0x5000, + kDirSE = 0x5100 }; #include "common/pack-start.h" // START STRUCT PACKING @@ -94,7 +95,8 @@ public: void placeItem(int16 x, int16 y, int16 id); - int16 getDirection(int16 x0, int16 y0, int16 x1, int16 y1); + Direction getDirection(int16 x0, int16 y0, int16 x1, int16 y1); + int16 checkDirectPath(Mult::Mult_Object *obj, int16 x0, int16 y0, int16 x1, int16 y1); int16 checkLongPath(int16 x0, int16 y0, @@ -122,6 +124,10 @@ protected: GobEngine *_vm; int16 findNearestWayPoint(int16 x, int16 y); + +private: + // Move the x and y values according to the direction + void moveDirection(Direction dir, int16 &x, int16 &y); }; class Map_v1 : public Map { |