diff options
-rw-r--r-- | engines/parallaction/parallaction.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 12 | ||||
-rw-r--r-- | engines/parallaction/walk.cpp | 96 |
3 files changed, 50 insertions, 60 deletions
diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index 295f10820f..d03d61fc59 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -390,7 +390,7 @@ void Parallaction::runGame() { if (_char._ani->gfxobj) { _char._ani->gfxobj->z = _char._ani->_z; } - walk(); + walk(_char); drawAnimations(); } diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index 13c56cf57b..2d0a201686 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -261,9 +261,9 @@ public: void pauseJobs(); void resumeJobs(); - void finalizeWalk(WalkNodeList *list); - int16 selectWalkFrame(const Common::Point& pos, const WalkNodePtr from); - void clipMove(Common::Point& pos, const WalkNodePtr from); + void finalizeWalk(Character &character); + int16 selectWalkFrame(Character &character, const Common::Point& pos, const WalkNodePtr to); + void clipMove(Common::Point& pos, const WalkNodePtr to); ZonePtr findZone(const char *name); ZonePtr hitZone(uint32 type, uint16 x, uint16 y); @@ -357,7 +357,7 @@ protected: // members void displayComment(ExamineData *data); - uint16 checkDoor(); + void checkDoor(Character &character); void freeCharacter(); @@ -379,7 +379,7 @@ public: void updateDoor(ZonePtr z); - virtual void walk() = 0; + virtual void walk(Character &character) = 0; virtual void drawAnimations() = 0; void beep(); @@ -575,7 +575,7 @@ private: const Callable *_callables; protected: - void walk(); + void walk(Character &character); void drawAnimations(); void parseLocation(const char *filename); diff --git a/engines/parallaction/walk.cpp b/engines/parallaction/walk.cpp index 7d74dd0e0a..7a16960cbf 100644 --- a/engines/parallaction/walk.cpp +++ b/engines/parallaction/walk.cpp @@ -27,9 +27,11 @@ namespace Parallaction { +// should be reset on location switch static uint16 _doorData1 = 1000; static ZonePtr _zoneTrap; +// should be reset on character switch static uint16 walkData1 = 0; static uint16 walkData2 = 0; // next walk frame @@ -259,30 +261,30 @@ uint16 PathBuilder::walkFunc1(int16 x, int16 y, WalkNodePtr Node) { return 1; } -void Parallaction::clipMove(Common::Point& pos, const WalkNodePtr from) { +void Parallaction::clipMove(Common::Point& pos, const WalkNodePtr to) { - if ((pos.x < from->_x) && (pos.x < _pathBuffer->w) && (_pathBuffer->getValue(pos.x + 2, pos.y) != 0)) { - pos.x = (pos.x + 2 < from->_x) ? pos.x + 2 : from->_x; + if ((pos.x < to->_x) && (pos.x < _pathBuffer->w) && (_pathBuffer->getValue(pos.x + 2, pos.y) != 0)) { + pos.x = (pos.x + 2 < to->_x) ? pos.x + 2 : to->_x; } - if ((pos.x > from->_x) && (pos.x > 0) && (_pathBuffer->getValue(pos.x - 2, pos.y) != 0)) { - pos.x = (pos.x - 2 > from->_x) ? pos.x - 2 : from->_x; + if ((pos.x > to->_x) && (pos.x > 0) && (_pathBuffer->getValue(pos.x - 2, pos.y) != 0)) { + pos.x = (pos.x - 2 > to->_x) ? pos.x - 2 : to->_x; } - if ((pos.y < from->_y) && (pos.y < _pathBuffer->h) && (_pathBuffer->getValue(pos.x, pos.y + 2) != 0)) { - pos.y = (pos.y + 2 <= from->_y) ? pos.y + 2 : from->_y; + if ((pos.y < to->_y) && (pos.y < _pathBuffer->h) && (_pathBuffer->getValue(pos.x, pos.y + 2) != 0)) { + pos.y = (pos.y + 2 <= to->_y) ? pos.y + 2 : to->_y; } - if ((pos.y > from->_y) && (pos.y > 0) && (_pathBuffer->getValue(pos.x, pos.y - 2) != 0)) { - pos.y = (pos.y - 2 >= from->_y) ? pos.y - 2 :from->_y; + if ((pos.y > to->_y) && (pos.y > 0) && (_pathBuffer->getValue(pos.x, pos.y - 2) != 0)) { + pos.y = (pos.y - 2 >= to->_y) ? pos.y - 2 : to->_y; } return; } -int16 Parallaction::selectWalkFrame(const Common::Point& pos, const WalkNodePtr from) { +int16 Parallaction::selectWalkFrame(Character &character, const Common::Point& pos, const WalkNodePtr to) { - Common::Point dist(from->_x - pos.x, from->_y - pos.y); + Common::Point dist(to->_x - pos.x, to->_y - pos.y); if (dist.x < 0) dist.x = -dist.x; @@ -293,14 +295,14 @@ int16 Parallaction::selectWalkFrame(const Common::Point& pos, const WalkNodePtr // walk frame selection int16 v16; - if (_char._ani->getFrameNum() == 20) { + if (character._ani->getFrameNum() == 20) { if (dist.x > dist.y) { - walkData2 = (from->_x > pos.x) ? 0 : 7; + walkData2 = (to->_x > pos.x) ? 0 : 7; walkData1 %= 12; v16 = walkData1 / 2; } else { - walkData2 = (from->_y > pos.y) ? 14 : 17; + walkData2 = (to->_y > pos.y) ? 14 : 17; walkData1 %= 8; v16 = walkData1 / 4; } @@ -308,11 +310,11 @@ int16 Parallaction::selectWalkFrame(const Common::Point& pos, const WalkNodePtr } else { if (dist.x > dist.y) { - walkData2 = (from->_x > pos.x) ? 0 : 9; + walkData2 = (to->_x > pos.x) ? 0 : 9; walkData1 %= 16; v16 = walkData1 / 2; } else { - walkData2 = (from->_y > pos.y) ? 18 : 21; + walkData2 = (to->_y > pos.y) ? 18 : 21; walkData1 %= 8; v16 = walkData1 / 4; } @@ -322,9 +324,7 @@ int16 Parallaction::selectWalkFrame(const Common::Point& pos, const WalkNodePtr return v16; } -uint16 Parallaction::checkDoor() { -// printf("checkDoor()..."); - +void Parallaction::checkDoor(Character &character) { if (_currentLocationIndex != _doorData1) { _doorData1 = _currentLocationIndex; _zoneTrap = nullZonePtr; @@ -334,7 +334,7 @@ uint16 Parallaction::checkDoor() { Common::Point foot; - _char.getFoot(foot); + character.getFoot(foot); ZonePtr z = hitZone(kZoneDoor, foot.x, foot.y); if (z) { @@ -351,7 +351,7 @@ uint16 Parallaction::checkDoor() { } } - _char.getFoot(foot); + character.getFoot(foot); z = hitZone(kZoneTrap, foot.x, foot.y); if (z) { @@ -367,61 +367,51 @@ uint16 Parallaction::checkDoor() { _zoneTrap = nullZonePtr; } -// printf("done\n"); - - _char._ani->_frame = walkData2; - return _char._ani->_frame; } -void Parallaction::finalizeWalk(WalkNodeList *list) { - checkDoor(); - delete list; +void Parallaction::finalizeWalk(Character &character) { + checkDoor(character); + delete character._walkPath; + character._walkPath = 0; + + character._ani->_frame = walkData2; } -void Parallaction_ns::walk() { +void Parallaction_ns::walk(Character &character) { if ((_engineFlags & kEngineWalking) == 0) { return; } - WalkNodeList *list = _char._walkPath; + Common::Point curPos; + character.getFoot(curPos); - _char._ani->_oldPos.x = _char._ani->_left; - _char._ani->_oldPos.y = _char._ani->_top; + WalkNodeList::iterator it = character._walkPath->begin(); - Common::Point pos; - _char.getFoot(pos); - - WalkNodeList::iterator it = list->begin(); - - if (it != list->end()) { - if ((*it)->_x == pos.x && (*it)->_y == pos.y) { + if (it != character._walkPath->end()) { + if ((*it)->_x == curPos.x && (*it)->_y == curPos.y) { debugC(1, kDebugWalk, "walk reached node (%i, %i)", (*it)->_x, (*it)->_y); - it = list->erase(it); + it = character._walkPath->erase(it); } } - if (it == list->end()) { + if (it == character._walkPath->end()) { debugC(1, kDebugWalk, "walk reached last node"); -// j->_finished = 1; - finalizeWalk(list); + finalizeWalk(character); return; } - _char._walkPath = list; // selectWalkFrame must be performed before position is changed by clipMove - int16 v16 = selectWalkFrame(pos, *it); - clipMove(pos, *it); - - _char.setFoot(pos); + int16 walkFrame = selectWalkFrame(character, curPos, *it); - Common::Point newpos(_char._ani->_left, _char._ani->_top); + Common::Point newPos(curPos); + clipMove(newPos, *it); + character.setFoot(newPos); - if (newpos == _char._ani->_oldPos) { + if (newPos == curPos) { debugC(1, kDebugWalk, "walk was blocked by an unforeseen obstacle"); -// j->_finished = 1; - finalizeWalk(list); + finalizeWalk(character); } else { - _char._ani->_frame = v16 + walkData2 + 1; + character._ani->_frame = walkFrame + walkData2 + 1; } return; |