diff options
author | Nicola Mettifogo | 2009-02-24 08:42:46 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2009-02-24 08:42:46 +0000 |
commit | 659c9fb901bcbc3db1252ed0c9a7eb49c09853b4 (patch) | |
tree | 10f839dd9044d8edbfdb633fad65d19c0a853f4a /engines | |
parent | d19ba951e825ce8ee4ae7c1c058ba517c678eb68 (diff) | |
download | scummvm-rg350-659c9fb901bcbc3db1252ed0c9a7eb49c09853b4.tar.gz scummvm-rg350-659c9fb901bcbc3db1252ed0c9a7eb49c09853b4.tar.bz2 scummvm-rg350-659c9fb901bcbc3db1252ed0c9a7eb49c09853b4.zip |
Changed interface to walk code, to better handle the differences between games. Moreover:
* merged PathBuilder_BR into PathWalker_BR
* implemented checkTrap routine for BRA
svn-id: r38836
Diffstat (limited to 'engines')
-rw-r--r-- | engines/parallaction/exec_br.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/exec_ns.cpp | 4 | ||||
-rw-r--r-- | engines/parallaction/input.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/objects.cpp | 15 | ||||
-rw-r--r-- | engines/parallaction/objects.h | 3 | ||||
-rw-r--r-- | engines/parallaction/parallaction.cpp | 37 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 30 | ||||
-rw-r--r-- | engines/parallaction/parallaction_br.cpp | 24 | ||||
-rw-r--r-- | engines/parallaction/parallaction_ns.cpp | 25 | ||||
-rw-r--r-- | engines/parallaction/parser.h | 1 | ||||
-rw-r--r-- | engines/parallaction/walk.cpp | 207 | ||||
-rw-r--r-- | engines/parallaction/walk.h | 63 |
12 files changed, 260 insertions, 153 deletions
diff --git a/engines/parallaction/exec_br.cpp b/engines/parallaction/exec_br.cpp index 5ed47dc010..adc89b8e94 100644 --- a/engines/parallaction/exec_br.cpp +++ b/engines/parallaction/exec_br.cpp @@ -154,7 +154,7 @@ DECLARE_COMMAND_OPCODE(drop) { DECLARE_COMMAND_OPCODE(move) { - _vm->_char.scheduleWalk(_ctxt.cmd->u._move.x, _ctxt.cmd->u._move.y); + _vm->scheduleWalk(_ctxt.cmd->u._move.x, _ctxt.cmd->u._move.y); suspend(); } diff --git a/engines/parallaction/exec_ns.cpp b/engines/parallaction/exec_ns.cpp index 861ddec82b..b2922cedae 100644 --- a/engines/parallaction/exec_ns.cpp +++ b/engines/parallaction/exec_ns.cpp @@ -175,7 +175,7 @@ DECLARE_INSTRUCTION_OPCODE(move) { int16 x = inst->_opA.getValue(); int16 y = inst->_opB.getValue(); - _vm->_char.scheduleWalk(x, y); + _vm->scheduleWalk(x, y); } DECLARE_INSTRUCTION_OPCODE(endscript) { @@ -286,7 +286,7 @@ DECLARE_COMMAND_OPCODE(quit) { DECLARE_COMMAND_OPCODE(move) { - _vm->_char.scheduleWalk(_ctxt.cmd->u._move.x, _ctxt.cmd->u._move.y); + _vm->scheduleWalk(_ctxt.cmd->u._move.x, _ctxt.cmd->u._move.y); } diff --git a/engines/parallaction/input.cpp b/engines/parallaction/input.cpp index 0967484513..b2bee2fce1 100644 --- a/engines/parallaction/input.cpp +++ b/engines/parallaction/input.cpp @@ -269,7 +269,7 @@ void Input::takeAction(ZonePtr z) { void Input::walkTo(const Common::Point &dest) { stopHovering(); setArrowCursor(); - _vm->_char.scheduleWalk(dest.x, dest.y); + _vm->scheduleWalk(dest.x, dest.y); } bool Input::translateGameInput() { diff --git a/engines/parallaction/objects.cpp b/engines/parallaction/objects.cpp index d132da4dcc..4dc3922207 100644 --- a/engines/parallaction/objects.cpp +++ b/engines/parallaction/objects.cpp @@ -112,6 +112,21 @@ void Animation::forceXYZF(int16 x, int16 y, int16 z, int16 f) { _frame = f; } +void Animation::getFoot(Common::Point &foot) { + Common::Rect rect; + gfxobj->getRect(_frame, rect); + foot.x = getX() + (rect.left + rect.width() / 2); + foot.y = getY() + (rect.top + rect.height()); +} + +void Animation::setFoot(const Common::Point &foot) { + Common::Rect rect; + gfxobj->getRect(_frame, rect); + + setX(foot.x - (rect.left + rect.width() / 2)); + setY(foot.y - (rect.top + rect.height())); +} + #define NUM_LOCALS 10 char _localNames[NUM_LOCALS][10]; diff --git a/engines/parallaction/objects.h b/engines/parallaction/objects.h index 034caa56b1..aa11165b33 100644 --- a/engines/parallaction/objects.h +++ b/engines/parallaction/objects.h @@ -538,6 +538,9 @@ public: int16 getF() { return _frame; } void setF(int16 value); + + void getFoot(Common::Point &foot); + void setFoot(const Common::Point &foot); }; class Table { diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index e26d9233eb..6ab94d3c54 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -38,6 +38,7 @@ #include "parallaction/debug.h" #include "parallaction/saveload.h" #include "parallaction/sound.h" +#include "parallaction/walk.h" @@ -337,7 +338,7 @@ void Parallaction::runGameFrame(int event) { _programExec->runScripts(_location._programs.begin(), _location._programs.end()); _char._ani->resetZ(); - _char._walker->walk(); + updateWalkers(); updateZones(); } @@ -867,23 +868,10 @@ Character::Character(Parallaction *vm) : _vm(vm), _ani(new Animation) { _ani->_flags = kFlagsActive | kFlagsNoName | kFlagsCharacter; _ani->_type = kZoneYou; strncpy(_ani->_name, "yourself", ZONENAME_LENGTH); - - // TODO: move creation into Parallaction. Needs to make Character a pointer first. - if (_vm->getGameType() == GType_Nippon) { - _builder = new PathBuilder_NS(this); - _walker = new PathWalker_NS(this); - } else { - _builder = new PathBuilder_BR(this); - _walker = new PathWalker_BR(this); - } } Character::~Character() { - delete _builder; - _builder = 0; - delete _walker; - _walker = 0; } void Character::getFoot(Common::Point &foot) { @@ -902,27 +890,6 @@ void Character::setFoot(const Common::Point &foot) { _ani->setY(foot.y - (rect.top + rect.height())); } -#if 0 -void dumpPath(const PointList &list, const char* text) { - for (PointList::iterator it = list.begin(); it != list.end(); it++) - printf("node (%i, %i)\n", it->x, it->y); - - return; -} -#endif - -void Character::scheduleWalk(int16 x, int16 y) { - if ((_ani->_flags & kFlagsRemove) || (_ani->_flags & kFlagsActive) == 0) { - return; - } - - _builder->buildPath(x, y); -#if 0 - dumpPath(_walkPath, _name); -#endif - _engineFlags |= kEngineWalking; -} - void Character::setName(const char *name) { _name.bind(name); diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index d106a1829a..c332c5d860 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -40,7 +40,6 @@ #include "parallaction/parser.h" #include "parallaction/objects.h" #include "parallaction/disk.h" -#include "parallaction/walk.h" #define PATH_LEN 200 @@ -122,6 +121,9 @@ class SoundMan; class Input; class DialogueManager; class MenuInputHelper; +class PathBuilder_NS; +class PathWalker_NS; +class PathWalker_BR; struct Location { @@ -198,8 +200,6 @@ struct Character { AnimationPtr _ani; GfxObj *_head; GfxObj *_talk; - PathBuilder *_builder; - PathWalker *_walker; PointList _walkPath; Character(Parallaction *vm); @@ -207,7 +207,6 @@ struct Character { void getFoot(Common::Point &foot); void setFoot(const Common::Point &foot); - void scheduleWalk(int16 x, int16 y); protected: CharacterName _name; @@ -367,6 +366,8 @@ public: virtual void callFunction(uint index, void* parm) = 0; virtual void runPendingZones() = 0; virtual void cleanupGame() = 0; + virtual void updateWalkers() = 0; + virtual void scheduleWalk(int16 x, int16 y) = 0; virtual DialogueManager *createDialogueManager(ZonePtr z) = 0; }; @@ -383,12 +384,14 @@ public: virtual Common::Error go(); public: - virtual void parseLocation(const char *filename); - virtual void changeLocation(char *location); - virtual void changeCharacter(const char *name); - virtual void callFunction(uint index, void* parm); - virtual void runPendingZones(); - virtual void cleanupGame(); + virtual void parseLocation(const char *filename); + virtual void changeLocation(char *location); + virtual void changeCharacter(const char *name); + virtual void callFunction(uint index, void* parm); + virtual void runPendingZones(); + virtual void cleanupGame(); + virtual void updateWalkers(); + virtual void scheduleWalk(int16 x, int16 y); virtual DialogueManager *createDialogueManager(ZonePtr z); @@ -429,6 +432,9 @@ private: static const Callable _dosCallables[25]; static const Callable _amigaCallables[25]; + PathBuilder_NS *_builder; + PathWalker_NS *_walker; + // common callables void _c_play_boogie(void*); void _c_startIntro(void*); @@ -483,6 +489,8 @@ public: virtual void callFunction(uint index, void* parm); virtual void runPendingZones(); virtual void cleanupGame(); + virtual void updateWalkers(); + virtual void scheduleWalk(int16 x, int16 y); virtual DialogueManager *createDialogueManager(ZonePtr z); @@ -529,6 +537,8 @@ private: const Callable *_callables; static const Callable _dosCallables[6]; + PathWalker_BR *_walker; + // dos callables void _c_blufade(void*); void _c_resetpalette(void*); diff --git a/engines/parallaction/parallaction_br.cpp b/engines/parallaction/parallaction_br.cpp index 403d425bd8..4bb239d197 100644 --- a/engines/parallaction/parallaction_br.cpp +++ b/engines/parallaction/parallaction_br.cpp @@ -30,6 +30,7 @@ #include "parallaction/input.h" #include "parallaction/saveload.h" #include "parallaction/sound.h" +#include "parallaction/walk.h" namespace Parallaction { @@ -84,6 +85,8 @@ Common::Error Parallaction_br::init() { _programExec = new ProgramExec_br(this); _programExec->init(); + _walker = new PathWalker_BR; + _part = -1; _subtitle[0] = -1; @@ -104,6 +107,8 @@ Parallaction_br::~Parallaction_br() { delete _locationParser; delete _programParser; + + delete _walker; } void Parallaction_br::callFunction(uint index, void* parm) { @@ -392,6 +397,25 @@ void Parallaction_br::testCounterCondition(const Common::String &name, int op, i } } +void Parallaction_br::updateWalkers() { + _walker->walk(); +} + +void Parallaction_br::scheduleWalk(int16 x, int16 y) { + AnimationPtr a = _char._ani; + + if ((a->_flags & kFlagsRemove) || (a->_flags & kFlagsActive) == 0) { + return; + } + + _walker->setCharacterPath(a, x, y); +#if 0 + if (_follower && _userEvent) { + _walker->setFollowerPath(_follower, x, y); + } +#endif + _engineFlags |= kEngineWalking; +} } // namespace Parallaction diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp index 40be52c211..23df87b903 100644 --- a/engines/parallaction/parallaction_ns.cpp +++ b/engines/parallaction/parallaction_ns.cpp @@ -31,6 +31,7 @@ #include "parallaction/input.h" #include "parallaction/saveload.h" #include "parallaction/sound.h" +#include "parallaction/walk.h" namespace Parallaction { @@ -184,6 +185,9 @@ Common::Error Parallaction_ns::init() { _programExec = new ProgramExec_ns(this); _programExec->init(); + _builder = new PathBuilder_NS(&_char); + _walker = new PathWalker_NS(&_char); + _sarcophagusDeltaX = 0; _movingSarcophagus = false; _freeSarcophagusSlotX = INITIAL_FREE_SARCOPHAGUS_SLOT_X; @@ -211,6 +215,9 @@ Parallaction_ns::~Parallaction_ns() { freeLocation(true); _location._animations.remove(_char._ani); + + delete _builder; + delete _walker; } @@ -485,4 +492,20 @@ void Parallaction_ns::cleanupGame() { _movingSarcophagus = false; } -} // namespace Parallaction +void Parallaction_ns::updateWalkers() { + _walker->walk(); +} + + +void Parallaction_ns::scheduleWalk(int16 x, int16 y) { + AnimationPtr a = _char._ani; + + if ((a->_flags & kFlagsRemove) || (a->_flags & kFlagsActive) == 0) { + return; + } + + _builder->buildPath(x, y); + _engineFlags |= kEngineWalking; +} + +}// namespace Parallaction diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h index 65e07aee03..13129b0aac 100644 --- a/engines/parallaction/parser.h +++ b/engines/parallaction/parser.h @@ -29,7 +29,6 @@ #include "common/stream.h" #include "common/stack.h" #include "parallaction/objects.h" -#include "parallaction/walk.h" namespace Parallaction { diff --git a/engines/parallaction/walk.cpp b/engines/parallaction/walk.cpp index 2cc3d2faa7..6807884c7a 100644 --- a/engines/parallaction/walk.cpp +++ b/engines/parallaction/walk.cpp @@ -24,6 +24,7 @@ */ #include "parallaction/parallaction.h" +#include "parallaction/walk.h" namespace Parallaction { @@ -343,7 +344,7 @@ PathBuilder_NS::PathBuilder_NS(Character *ch) : PathBuilder(ch) { } -bool PathBuilder_BR::directPathExists(const Common::Point &from, const Common::Point &to) { +bool PathWalker_BR::directPathExists(const Common::Point &from, const Common::Point &to) { Common::Point copy(from); Common::Point p(copy); @@ -365,17 +366,37 @@ bool PathBuilder_BR::directPathExists(const Common::Point &from, const Common::P return true; } -void PathBuilder_BR::buildPath(uint16 x, uint16 y) { +void PathWalker_BR::setCharacterPath(AnimationPtr a, uint16 x, uint16 y) { + _character._a = a; + _ch = _character; + buildPath(x, y); + _character._active = true; +} + +void PathWalker_BR::setFollowerPath(AnimationPtr a, uint16 x, uint16 y) { + _follower._a = a; + _ch = _follower; + buildPath(x, y); + _follower._active = true; +} + +void PathWalker_BR::stopFollower() { + _follower._a.reset(); + _follower._active = false; +} + + +void PathWalker_BR::buildPath(uint16 x, uint16 y) { Common::Point foot; - _ch->getFoot(foot); + _ch._a->getFoot(foot); debugC(1, kDebugWalk, "buildPath: from (%i, %i) to (%i, %i)", foot.x, foot.y, x, y); - _ch->_walkPath.clear(); + _ch._walkPath.clear(); // look for easy path first Common::Point dest(x, y); if (directPathExists(foot, dest)) { - _ch->_walkPath.push_back(dest); + _ch._walkPath.push_back(dest); debugC(3, kDebugWalk, "buildPath: direct path found"); return; } @@ -383,13 +404,13 @@ void PathBuilder_BR::buildPath(uint16 x, uint16 y) { // look for short circuit cases ZonePtr z0 = _vm->hitZone(kZonePath, x, y); if (!z0) { - _ch->_walkPath.push_back(dest); + _ch._walkPath.push_back(dest); debugC(3, kDebugWalk, "buildPath: corner case 0"); return; } ZonePtr z1 = _vm->hitZone(kZonePath, foot.x, foot.y); if (!z1 || z1 == z0) { - _ch->_walkPath.push_back(dest); + _ch._walkPath.push_back(dest); debugC(3, kDebugWalk, "buildPath: corner case 1"); return; } @@ -398,7 +419,7 @@ void PathBuilder_BR::buildPath(uint16 x, uint16 y) { int id = atoi(z0->_name); if (z1->u.path->_lists[id].empty()) { - _ch->_walkPath.clear(); + _ch._walkPath.clear(); debugC(3, kDebugWalk, "buildPath: no path"); return; } @@ -406,24 +427,20 @@ void PathBuilder_BR::buildPath(uint16 x, uint16 y) { PointList::iterator b = z1->u.path->_lists[id].begin(); PointList::iterator e = z1->u.path->_lists[id].end(); for ( ; b != e; b++) { - _ch->_walkPath.push_front(*b); + _ch._walkPath.push_front(*b); } - _ch->_walkPath.push_back(dest); + _ch._walkPath.push_back(dest); debugC(3, kDebugWalk, "buildPath: complex path"); - - return; } -PathBuilder_BR::PathBuilder_BR(Character *ch) : PathBuilder(ch) { -} void PathWalker_BR::finalizeWalk() { _engineFlags &= ~kEngineWalking; - _first = true; - _fieldC = 1; + _ch._first = true; + _ch._fieldC = 1; Common::Point foot; - _ch->getFoot(foot); + _ch._a->getFoot(foot); ZonePtr z = _vm->hitZone(kZoneDoor, foot.x, foot.y); if (z && ((z->_flags & kFlagsClosed) == 0)) { @@ -454,14 +471,14 @@ void PathWalker_BR::finalizeWalk() { // a merge between the two Path managers is the right solution if (_engineFlags & FINAL_WALK_FRAME) { // this flag is set in readInput() _engineFlags &= ~FINAL_WALK_FRAME; - _char.ani->_frame = _moveToF; // from readInput()... + _ch._a->_frame = _moveToF; // from readInput()... } else { - _char.ani->_frame = _dirFrame; // from walk() + _ch._a->_frame = _dirFrame; // from walk() } - _char.setFoot(foot); + _ch._a->setFoot(foot); #endif - _ch->_ani->setF(_dirFrame); // temporary solution + _ch._a->setF(_ch._dirFrame); // temporary solution #if 0 // TODO: support scrolling ;) @@ -474,12 +491,52 @@ void PathWalker_BR::finalizeWalk() { return; } - void PathWalker_BR::walk() { if ((_engineFlags & kEngineWalking) == 0) { return; } + bool finalize = doWalk(_character); + doWalk(_follower); + + if (finalize) { + finalizeWalk(); + } +} + +void PathWalker_BR::checkTrap(const Common::Point &p) { + ZonePtr z = _vm->hitZone(kZoneTrap, p.x, p.y); + + if (z && z != _vm->_zoneTrap) { + if (z->_flags & kFlagsIsAnimation) { + z->_flags |= kFlagsActing; + } else { + _vm->setLocationFlags(kFlagsExit); + _vm->_cmdExec->run(z->_commands, z); + _vm->clearLocationFlags(kFlagsExit); + } + } + + if (_vm->_zoneTrap && _vm->_zoneTrap != z) { + if (_vm->_zoneTrap->_flags & kFlagsIsAnimation) { + _vm->_zoneTrap->_flags &= ~kFlagsActing; + } else { + _vm->setLocationFlags(kFlagsEnter); + _vm->_cmdExec->run(_vm->_zoneTrap->_commands, _vm->_zoneTrap); + _vm->clearLocationFlags(kFlagsEnter); + } + } + + _vm->_zoneTrap = z; +} + +bool PathWalker_BR::doWalk(State &s) { + if (!s._active) { + return false; + } + + _ch = s; + #if 0 // TODO: support delays in walking. This requires extending Input::walkIo(). if (ch._walkDelay > 0) { @@ -490,118 +547,118 @@ void PathWalker_BR::walk() { Script *script = findScript(_ch._ani->_scriptName); script->_nextCommand = script->firstCommand; } - return; + return false; } #endif - if (_fieldC == 0) { - _ch->_walkPath.erase(_ch->_walkPath.begin()); + if (_ch._fieldC == 0) { + _ch._walkPath.erase(_ch._walkPath.begin()); - if (_ch->_walkPath.empty()) { - finalizeWalk(); + if (_ch._walkPath.empty()) { debugC(3, kDebugWalk, "PathWalker_BR::walk, case 0"); - return; + return true; } else { debugC(3, kDebugWalk, "PathWalker_BR::walk, moving to next node"); } } - _ch->getFoot(_startFoot); + _ch._a->getFoot(_ch._startFoot); - uint scale = _vm->_location.getScale(_startFoot.y); + uint scale = _vm->_location.getScale(_ch._startFoot.y); int xStep = (scale * 16) / 100 + 1; int yStep = (scale * 10) / 100 + 1; debugC(9, kDebugWalk, "calculated step: (%i, %i)", xStep, yStep); - _fieldC = 0; - _step++; - _step %= 8; + _ch._fieldC = 0; + _ch._step++; + _ch._step %= 8; int maxX = _vm->_gfx->_backgroundInfo->width; int minX = 0; int maxY = _vm->_gfx->_backgroundInfo->height; int minY = 0; - int walkFrame = _step; - _dirFrame = 0; - Common::Point newpos(_startFoot), delta; + int walkFrame = _ch._step; + _ch._dirFrame = 0; + Common::Point newpos(_ch._startFoot), delta; - Common::Point p(*_ch->_walkPath.begin()); + Common::Point p(*_ch._walkPath.begin()); - if (_startFoot.y < p.y && _startFoot.y < maxY && IS_PATH_CLEAR(_startFoot.x, yStep + _startFoot.y)) { - if (yStep + _startFoot.y <= p.y) { - _fieldC = 1; + if (_ch._startFoot.y < p.y && _ch._startFoot.y < maxY && IS_PATH_CLEAR(_ch._startFoot.x, yStep + _ch._startFoot.y)) { + if (yStep + _ch._startFoot.y <= p.y) { + _ch._fieldC = 1; delta.y = yStep; - newpos.y = yStep + _startFoot.y; + newpos.y = yStep + _ch._startFoot.y; } else { - delta.y = p.y - _startFoot.y; + delta.y = p.y - _ch._startFoot.y; newpos.y = p.y; } - _dirFrame = 9; + _ch._dirFrame = 9; } else - if (_startFoot.y > p.y && _startFoot.y > minY && IS_PATH_CLEAR(_startFoot.x, _startFoot.y - yStep)) { - if (_startFoot.y - yStep >= p.y) { - _fieldC = 1; + if (_ch._startFoot.y > p.y && _ch._startFoot.y > minY && IS_PATH_CLEAR(_ch._startFoot.x, _ch._startFoot.y - yStep)) { + if (_ch._startFoot.y - yStep >= p.y) { + _ch._fieldC = 1; delta.y = yStep; - newpos.y = _startFoot.y - yStep; + newpos.y = _ch._startFoot.y - yStep; } else { - delta.y = _startFoot.y - p.y; + delta.y = _ch._startFoot.y - p.y; newpos.y = p.y; } - _dirFrame = 0; + _ch._dirFrame = 0; } - if (_startFoot.x < p.x && _startFoot.x < maxX && IS_PATH_CLEAR(_startFoot.x + xStep, _startFoot.y)) { - if (_startFoot.x + xStep <= p.x) { - _fieldC = 1; + if (_ch._startFoot.x < p.x && _ch._startFoot.x < maxX && IS_PATH_CLEAR(_ch._startFoot.x + xStep, _ch._startFoot.y)) { + if (_ch._startFoot.x + xStep <= p.x) { + _ch._fieldC = 1; delta.x = xStep; - newpos.x = xStep + _startFoot.x; + newpos.x = xStep + _ch._startFoot.x; } else { - delta.x = p.x - _startFoot.x; + delta.x = p.x - _ch._startFoot.x; newpos.x = p.x; } if (delta.y < delta.x) { - _dirFrame = 18; // right + _ch._dirFrame = 18; // right } } else - if (_startFoot.x > p.x && _startFoot.x > minX && IS_PATH_CLEAR(_startFoot.x - xStep, _startFoot.y)) { - if (_startFoot.x - xStep >= p.x) { - _fieldC = 1; + if (_ch._startFoot.x > p.x && _ch._startFoot.x > minX && IS_PATH_CLEAR(_ch._startFoot.x - xStep, _ch._startFoot.y)) { + if (_ch._startFoot.x - xStep >= p.x) { + _ch._fieldC = 1; delta.x = xStep; - newpos.x = _startFoot.x - xStep; + newpos.x = _ch._startFoot.x - xStep; } else { - delta.x = _startFoot.x - p.x; + delta.x = _ch._startFoot.x - p.x; newpos.x = p.x; } if (delta.y < delta.x) { - _dirFrame = 27; // left + _ch._dirFrame = 27; // left } } - debugC(9, kDebugWalk, "foot (%i, %i) dest (%i, %i) deltas = %i/%i ", _startFoot.x, _startFoot.y, p.x, p.y, delta.x, delta.y); + debugC(9, kDebugWalk, "foot (%i, %i) dest (%i, %i) deltas = %i/%i ", _ch._startFoot.x, _ch._startFoot.y, p.x, p.y, delta.x, delta.y); - if (_fieldC) { - debugC(9, kDebugWalk, "PathWalker_BR::walk, foot moved from (%i, %i) to (%i, %i)", _startFoot.x, _startFoot.y, newpos.x, newpos.y); - _ch->_ani->setF(walkFrame + _dirFrame + 1); - _startFoot.x = newpos.x; - _startFoot.y = newpos.y; - _ch->setFoot(_startFoot); - _ch->_ani->setZ(newpos.y); + if (_ch._fieldC) { + debugC(9, kDebugWalk, "PathWalker_BR::walk, foot moved from (%i, %i) to (%i, %i)", _ch._startFoot.x, _ch._startFoot.y, newpos.x, newpos.y); + _ch._a->setF(walkFrame + _ch._dirFrame + 1); + _ch._startFoot.x = newpos.x; + _ch._startFoot.y = newpos.y; + _ch._a->setFoot(_ch._startFoot); + _ch._a->setZ(newpos.y); } - if (_fieldC || !_ch->_walkPath.empty()) { -// checkTrap(); + if (_ch._fieldC || !_ch._walkPath.empty()) { + Common::Point p; + _ch._a->getFoot(p); + checkTrap(p); debugC(3, kDebugWalk, "PathWalker_BR::walk, case 1"); - return; + return false; } debugC(3, kDebugWalk, "PathWalker_BR::walk, case 2"); - finalizeWalk(); - return; + return true; } -PathWalker_BR::PathWalker_BR(Character *ch) : PathWalker(ch), _fieldC(1), _first(true) { +PathWalker_BR::PathWalker_BR() : _ch(_character) { } diff --git a/engines/parallaction/walk.h b/engines/parallaction/walk.h index 1ffd538bab..aebfea7975 100644 --- a/engines/parallaction/walk.h +++ b/engines/parallaction/walk.h @@ -48,6 +48,16 @@ public: virtual void buildPath(uint16 x, uint16 y) = 0; }; +class PathWalker { +protected: + Character *_ch; +public: + PathWalker(Character *ch) : _ch(ch) { } + virtual ~PathWalker() { } + virtual void walk() = 0; +}; + + class PathBuilder_NS : public PathBuilder { @@ -62,25 +72,6 @@ public: void buildPath(uint16 x, uint16 y); }; - -class PathBuilder_BR : public PathBuilder { - - bool directPathExists(const Common::Point &from, const Common::Point &to); - -public: - PathBuilder_BR(Character *ch); - void buildPath(uint16 x, uint16 y); -}; - -class PathWalker { -protected: - Character *_ch; -public: - PathWalker(Character *ch) : _ch(ch) { } - virtual ~PathWalker() { } - virtual void walk() = 0; -}; - class PathWalker_NS : public PathWalker { @@ -94,21 +85,39 @@ public: }; -class PathWalker_BR : public PathWalker { +class PathWalker_BR { + struct State { + bool _active; + AnimationPtr _a; + int _walkDelay; + int _fieldC; + Common::Point _startFoot; + bool _first; + int _step; + int _dirFrame; + PointList _walkPath; + }; - int _walkDelay; - int _fieldC; - Common::Point _startFoot; - bool _first; - int _step; + State _character; + State _follower; - int _dirFrame; + State &_ch; void finalizeWalk(); + bool directPathExists(const Common::Point &from, const Common::Point &to); + void buildPath(uint16 x, uint16 y); + bool doWalk(State &s); + void checkTrap(const Common::Point &p); public: - PathWalker_BR(Character *ch); + PathWalker_BR(); + ~PathWalker_BR() { } + + void setCharacterPath(AnimationPtr a, uint16 x, uint16 y); + void setFollowerPath(AnimationPtr a, uint16 x, uint16 y); + void stopFollower(); + void walk(); }; |