diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/draci/game.cpp | 64 | ||||
-rw-r--r-- | engines/draci/game.h | 13 | ||||
-rw-r--r-- | engines/draci/script.cpp | 30 |
3 files changed, 56 insertions, 51 deletions
diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index 13246585be..d5701c3eae 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -282,17 +282,17 @@ void Game::loop() { _objUnderCursor = kObjectNotFound; if (!obj->_imLook) { - if (obj->_lookDir == -1) { - walkHero(x, y); + if (obj->_lookDir == kDirectionLast) { + walkHero(x, y, obj->_lookDir); } else { - walkHero(obj->_lookX, obj->_lookY); + walkHero(obj->_lookX, obj->_lookY, obj->_lookDir); } } _vm->_script->run(obj->_program, obj->_look); _vm->_mouse->cursorOn(); } else { - walkHero(x, y); + walkHero(x, y, kDirectionLast); } } } @@ -310,17 +310,17 @@ void Game::loop() { _objUnderCursor = kObjectNotFound; if (!obj->_imUse) { - if (obj->_useDir == -1) { - walkHero(x, y); + if (obj->_useDir == kDirectionLast) { + walkHero(x, y, obj->_useDir); } else { - walkHero(obj->_useX, obj->_useY); + walkHero(obj->_useX, obj->_useY, obj->_useDir); } } _vm->_script->run(obj->_program, obj->_use); _vm->_mouse->cursorOn(); } else { - walkHero(x, y); + walkHero(x, y, kDirectionLast); } } else { if (_vm->_script->testExpression(_currentRoom._program, _currentRoom._canUse)) { @@ -332,7 +332,7 @@ void Game::loop() { _vm->_script->run(_currentRoom._program, _currentRoom._use); _vm->_mouse->cursorOn(); } else { - walkHero(x, y); + walkHero(x, y, kDirectionLast); } } } @@ -940,7 +940,16 @@ int Game::getCurrentDialogueOffset() const { return _dialogueOffsets[_currentDialogue]; } -void Game::walkHero(int x, int y) { +void Game::playHeroAnimation(int anim_index) { + const GameObject *dragon = getObject(kDragonObject); + const int animID = dragon->_anim[anim_index]; + Animation *anim = _vm->_anims->getAnimation(animID); + stopObjectAnimations(dragon); + positionAnimAsHero(anim); + _vm->_anims->play(animID); +} + +void Game::walkHero(int x, int y, SightDirection dir) { // Needed for the map room with empty walking map. For some reason, // findNearestWalkable() takes several seconds with 100% CPU to finish // (correctly). @@ -948,23 +957,28 @@ void Game::walkHero(int x, int y) { return; Surface *surface = _vm->_screen->getSurface(); - _hero = _currentRoom._walkingMap.findNearestWalkable(x, y, surface->getRect()); - - GameObject *dragon = getObject(kDragonObject); - stopObjectAnimations(dragon); - debugC(3, kDraciLogicDebugLevel, "Walk to x: %d y: %d", _hero.x, _hero.y); - - // Fetch dragon's animation ID // FIXME: Need to add proper walking (this only warps the dragon to position) - int animID = dragon->_anim[kStopRight]; - - Animation *anim = _vm->_anims->getAnimation(animID); - positionAnimAsHero(anim); - // Play the animation - _vm->_anims->play(animID); + Movement movement = kStopRight; + switch (dir) { + case kDirectionLeft: + movement = kStopLeft; + break; + case kDirectionRight: + movement = kStopRight; + break; + default: { + const GameObject *dragon = getObject(kDragonObject); + const int anim_index = playingObjectAnimation(dragon); + if (anim_index >= 0) { + movement = static_cast<Movement> (anim_index); + } + break; + } + } + playHeroAnimation(movement); } void Game::loadItem(int itemID) { @@ -1200,8 +1214,8 @@ void Game::loadObject(uint objNum) { obj->_lookY = objReader.readUint16LE(); obj->_useX = objReader.readUint16LE(); obj->_useY = objReader.readUint16LE(); - obj->_lookDir = objReader.readByte() - 1; - obj->_useDir = objReader.readByte() - 1; + obj->_lookDir = static_cast<SightDirection> (objReader.readByte()); + obj->_useDir = static_cast<SightDirection> (objReader.readByte()); obj->_absNum = objNum; diff --git a/engines/draci/game.h b/engines/draci/game.h index 420f5dc719..826f5599f2 100644 --- a/engines/draci/game.h +++ b/engines/draci/game.h @@ -132,13 +132,21 @@ private: const byte *_data; }; +/* + * Enumerates the directions the dragon can look into when arrived. + */ +enum SightDirection { + kDirectionLast, kDirectionMouse, kDirectionUnknown, + kDirectionRight, kDirectionLeft, kDirectionIntelligent +}; + struct GameObject { uint _init, _look, _use, _canUse; bool _imInit, _imLook, _imUse; int _walkDir; byte _z; uint _lookX, _lookY, _useX, _useY; - int _lookDir, _useDir; + SightDirection _lookDir, _useDir; uint _absNum; Common::Array<int> _anim; GPL2Program _program; @@ -255,10 +263,11 @@ public: return n; } - void walkHero(int x, int y); + void walkHero(int x, int y, SightDirection dir); int getHeroX() const; int getHeroY() const; void positionAnimAsHero(Animation *anim); + void playHeroAnimation(int anim_index); int loadAnimation(uint animNum, uint z); void loadOverlays(); diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp index 192ed9881b..4ab75f1291 100644 --- a/engines/draci/script.cpp +++ b/engines/draci/script.cpp @@ -479,43 +479,25 @@ void Script::startPlay(Common::Queue<int> ¶ms) { void Script::justTalk(Common::Queue<int> ¶ms) { const GameObject *dragon = _vm->_game->getObject(kDragonObject); const int last_anim = static_cast<Movement> (_vm->_game->playingObjectAnimation(dragon)); - if (last_anim >= 0) { - _vm->_game->stopObjectAnimations(dragon); - } int new_anim; if (last_anim == kSpeakRight || last_anim == kStopRight) { new_anim = kSpeakRight; } else { new_anim = kSpeakLeft; } - - const int animID = dragon->_anim[new_anim]; - - Animation *anim = _vm->_anims->getAnimation(animID); - _vm->_game->positionAnimAsHero(anim); - - _vm->_anims->play(animID); + _vm->_game->playHeroAnimation(new_anim); } void Script::justStay(Common::Queue<int> ¶ms) { const GameObject *dragon = _vm->_game->getObject(kDragonObject); const int last_anim = static_cast<Movement> (_vm->_game->playingObjectAnimation(dragon)); - if (last_anim >= 0) { - _vm->_game->stopObjectAnimations(dragon); - } int new_anim; if (last_anim == kSpeakRight || last_anim == kStopRight) { new_anim = kStopRight; } else { new_anim = kStopLeft; } - - const int animID = dragon->_anim[new_anim]; - - Animation *anim = _vm->_anims->getAnimation(animID); - _vm->_game->positionAnimAsHero(anim); - - _vm->_anims->play(animID); + _vm->_game->playHeroAnimation(new_anim); } void Script::c_If(Common::Queue<int> ¶ms) { @@ -662,9 +644,9 @@ void Script::walkOn(Common::Queue<int> ¶ms) { int x = params.pop(); int y = params.pop(); - params.pop(); // facing direction, not used yet + SightDirection dir = static_cast<SightDirection> (params.pop()); - _vm->_game->walkHero(x, y); + _vm->_game->walkHero(x, y, dir); } void Script::walkOnPlay(Common::Queue<int> ¶ms) { @@ -674,12 +656,12 @@ void Script::walkOnPlay(Common::Queue<int> ¶ms) { int x = params.pop(); int y = params.pop(); - params.pop(); // facing direction, not used yet + SightDirection dir = static_cast<SightDirection> (params.pop()); // HACK: This should be an onDest action when hero walking is properly implemented _vm->_game->setExitLoop(true); - _vm->_game->walkHero(x, y); + _vm->_game->walkHero(x, y, dir); _vm->_game->setLoopSubstatus(kSubstatusStrange); _vm->_game->loop(); |