From f7e7a45f12351e07851a960c814411de94b346f1 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 24 Apr 2016 12:10:43 +0200 Subject: GNAP: Refactor scene 39 --- engines/gnap/gnap.h | 7 -- engines/gnap/scenes/scene38.h | 2 - engines/gnap/scenes/scene39.cpp | 205 +++++++++++++++++++------------------- engines/gnap/scenes/scene39.h | 50 ++++++++++ engines/gnap/scenes/scenecore.cpp | 9 +- 5 files changed, 158 insertions(+), 115 deletions(-) create mode 100644 engines/gnap/scenes/scene39.h (limited to 'engines') diff --git a/engines/gnap/gnap.h b/engines/gnap/gnap.h index 4bcf7fc981..fe641ceb86 100644 --- a/engines/gnap/gnap.h +++ b/engines/gnap/gnap.h @@ -606,13 +606,6 @@ public: // Shared by scenes 17 & 18 int _s18_garbageCanPos; - // Scene 39 - int _s39_currGuySequenceId, _s39_nextGuySequenceId; - int scene39_init(); - void scene39_updateHotspots(); - void scene39_run(); - void scene39_updateAnimations(); - // Scene 40 int scene40_init(); void scene40_updateHotspots(); diff --git a/engines/gnap/scenes/scene38.h b/engines/gnap/scenes/scene38.h index 7cc90b75e7..8ad8e73fa3 100644 --- a/engines/gnap/scenes/scene38.h +++ b/engines/gnap/scenes/scene38.h @@ -40,8 +40,6 @@ public: virtual void run(); virtual void updateAnimations(); virtual void updateAnimationsCb() {}; - -private: }; } // End of namespace Gnap diff --git a/engines/gnap/scenes/scene39.cpp b/engines/gnap/scenes/scene39.cpp index bc506c1bcf..cfbdd5721a 100644 --- a/engines/gnap/scenes/scene39.cpp +++ b/engines/gnap/scenes/scene39.cpp @@ -23,6 +23,7 @@ #include "gnap/gnap.h" #include "gnap/gamesys.h" #include "gnap/resource.h" +#include "gnap/scenes/scene39.h" namespace Gnap { @@ -40,86 +41,89 @@ enum { kASLeaveScene = 0 }; -int GnapEngine::scene39_init() { - _gameSys->setAnimation(0, 0, 0); - _gameSys->setAnimation(0, 0, 1); - return 0x35; +Scene39::Scene39(GnapEngine *vm) : Scene(vm) { + _s39_currGuySequenceId = -1; + _s39_nextGuySequenceId = -1; } -void GnapEngine::scene39_updateHotspots() { - setHotspot(kHSPlatypus, 0, 0, 0, 0, SF_WALKABLE | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR); - setHotspot(kHSExitInsideHouse, 0, 0, 140, 206, SF_EXIT_U_CURSOR, 4, 8); - setHotspot(kHSExitUfoParty, 360, 204, 480, 430, SF_EXIT_R_CURSOR, 6, 8); - setHotspot(kHSSign, 528, 232, 607, 397, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 7, 3); - setHotspot(kHSWalkArea1, 0, 0, 800, 466); - setHotspot(kHSWalkArea2, 502, 466, 800, 600); - setDeviceHotspot(kHSDevice, -1, -1, -1, -1); - _hotspotsCount = 7; +int Scene39::init() { + _vm->_gameSys->setAnimation(0, 0, 0); + _vm->_gameSys->setAnimation(0, 0, 1); + return 0x35; } -void GnapEngine::scene39_run() { +void Scene39::updateHotspots() { + _vm->setHotspot(kHSPlatypus, 0, 0, 0, 0, SF_WALKABLE | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR); + _vm->setHotspot(kHSExitInsideHouse, 0, 0, 140, 206, SF_EXIT_U_CURSOR, 4, 8); + _vm->setHotspot(kHSExitUfoParty, 360, 204, 480, 430, SF_EXIT_R_CURSOR, 6, 8); + _vm->setHotspot(kHSSign, 528, 232, 607, 397, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 7, 3); + _vm->setHotspot(kHSWalkArea1, 0, 0, 800, 466); + _vm->setHotspot(kHSWalkArea2, 502, 466, 800, 600); + _vm->setDeviceHotspot(kHSDevice, -1, -1, -1, -1); + _vm->_hotspotsCount = 7; +} - _timers[5] = 0; // Bug in the original? Timer was never intiailized. +void Scene39::run() { + // Bug in the original? Timer was never initialized. + _vm->_timers[5] = 0; - queueInsertDeviceIcon(); + _vm->queueInsertDeviceIcon(); _s39_currGuySequenceId = 0x33; - _gameSys->setAnimation(0x33, 21, 3); - _gameSys->insertSequence(_s39_currGuySequenceId, 21, 0, 0, kSeqNone, 0, 0, 0); - _gameSys->insertSequence(0x34, 21, 0, 0, kSeqLoop, 0, 0, 0); + _vm->_gameSys->setAnimation(0x33, 21, 3); + _vm->_gameSys->insertSequence(_s39_currGuySequenceId, 21, 0, 0, kSeqNone, 0, 0, 0); + _vm->_gameSys->insertSequence(0x34, 21, 0, 0, kSeqLoop, 0, 0, 0); _s39_nextGuySequenceId = -1; - if (_prevSceneNum == 38) { - initGnapPos(3, 7, kDirUpRight); - initPlatypusPos(2, 7, kDirUpLeft); - endSceneInit(); + if (_vm->_prevSceneNum == 38) { + _vm->initGnapPos(3, 7, kDirUpRight); + _vm->initPlatypusPos(2, 7, kDirUpLeft); + _vm->endSceneInit(); } else { - initGnapPos(4, 7, kDirBottomRight); - initPlatypusPos(5, 7, kDirNone); - endSceneInit(); + _vm->initGnapPos(4, 7, kDirBottomRight); + _vm->initPlatypusPos(5, 7, kDirNone); + _vm->endSceneInit(); } - while (!_sceneDone) { - - if (!isSoundPlaying(0x1094B)) { - playSound(0x1094B, true); - setSoundVolume(0x1094B, 60); + while (!_vm->_sceneDone) { + if (!_vm->isSoundPlaying(0x1094B)) { + _vm->playSound(0x1094B, true); + _vm->setSoundVolume(0x1094B, 60); } - updateMouseCursor(); - updateCursorByHotspot(); + _vm->updateMouseCursor(); + _vm->updateCursorByHotspot(); - testWalk(0, 0, -1, -1, -1, -1); - - _sceneClickedHotspot = getClickedHotspotId(); - updateGrabCursorSprite(0, 0); + _vm->testWalk(0, 0, -1, -1, -1, -1); - switch (_sceneClickedHotspot) { + _vm->_sceneClickedHotspot = _vm->getClickedHotspotId(); + _vm->updateGrabCursorSprite(0, 0); + switch (_vm->_sceneClickedHotspot) { case kHSDevice: - runMenu(); - scene39_updateHotspots(); - _timers[5] = getRandom(20) + 50; + _vm->runMenu(); + updateHotspots(); + _vm->_timers[5] = _vm->getRandom(20) + 50; break; case kHSPlatypus: - if (_gnapActionStatus < 0) { - if (_grabCursorSpriteIndex >= 0) { - playGnapImpossible(_platX, _platY); + if (_vm->_gnapActionStatus < 0) { + if (_vm->_grabCursorSpriteIndex >= 0) { + _vm->playGnapImpossible(_vm->_platX, _vm->_platY); } else { - switch (_verbCursor) { + switch (_vm->_verbCursor) { case LOOK_CURSOR: - playGnapMoan1(_platX, _platY); + _vm->playGnapMoan1(_vm->_platX, _vm->_platY); break; case GRAB_CURSOR: - gnapKissPlatypus(0); + _vm->gnapKissPlatypus(0); break; case TALK_CURSOR: - playGnapBrainPulsating(_platX, _platY); - playPlatypusSequence(getPlatypusSequenceId()); + _vm->playGnapBrainPulsating(_vm->_platX, _vm->_platY); + _vm->playPlatypusSequence(_vm->getPlatypusSequenceId()); break; case PLAT_CURSOR: - playGnapImpossible(_platX, _platY); + _vm->playGnapImpossible(_vm->_platX, _vm->_platY); break; } } @@ -127,30 +131,30 @@ void GnapEngine::scene39_run() { break; case kHSExitUfoParty: - if (_gnapActionStatus < 0) { - _isLeavingScene = true; - _sceneDone = true; - gnapWalkTo(_gnapX, _gnapY, 0, 0x107AB, 1); - _gnapActionStatus = kASLeaveScene; - _newSceneNum = 40; + if (_vm->_gnapActionStatus < 0) { + _vm->_isLeavingScene = true; + _vm->_sceneDone = true; + _vm->gnapWalkTo(_vm->_gnapX, _vm->_gnapY, 0, 0x107AB, 1); + _vm->_gnapActionStatus = kASLeaveScene; + _vm->_newSceneNum = 40; } break; case kHSSign: - if (_gnapActionStatus < 0) { - if (_grabCursorSpriteIndex >= 0) { - playGnapImpossible(0, 0); + if (_vm->_gnapActionStatus < 0) { + if (_vm->_grabCursorSpriteIndex >= 0) { + _vm->playGnapImpossible(0, 0); } else { - switch (_verbCursor) { + switch (_vm->_verbCursor) { case LOOK_CURSOR: - gnapWalkTo(_hotspotsWalkPos[kHSSign].x, _hotspotsWalkPos[kHSSign].y, 0, -1, 1); - playGnapIdle(_hotspotsWalkPos[kHSSign].x, _hotspotsWalkPos[kHSSign].y); - showFullScreenSprite(0x1C); + _vm->gnapWalkTo(_vm->_hotspotsWalkPos[kHSSign].x, _vm->_hotspotsWalkPos[kHSSign].y, 0, -1, 1); + _vm->playGnapIdle(_vm->_hotspotsWalkPos[kHSSign].x, _vm->_hotspotsWalkPos[kHSSign].y); + _vm->showFullScreenSprite(0x1C); break; case GRAB_CURSOR: case TALK_CURSOR: case PLAT_CURSOR: - playGnapImpossible(0, 0); + _vm->playGnapImpossible(0, 0); break; } } @@ -158,38 +162,37 @@ void GnapEngine::scene39_run() { break; case kHSExitInsideHouse: - if (_gnapActionStatus < 0) { - _sceneDone = true; - _isLeavingScene = true; - _newSceneNum = 38; + if (_vm->_gnapActionStatus < 0) { + _vm->_sceneDone = true; + _vm->_isLeavingScene = true; + _vm->_newSceneNum = 38; } break; case kHSWalkArea1: case kHSWalkArea2: - if (_gnapActionStatus < 0) - gnapWalkTo(-1, -1, -1, -1, 1); + if (_vm->_gnapActionStatus < 0) + _vm->gnapWalkTo(-1, -1, -1, -1, 1); break; default: - if (_mouseClickState._left && _gnapActionStatus < 0) { - gnapWalkTo(-1, -1, -1, -1, 1); - _mouseClickState._left = false; + if (_vm->_mouseClickState._left && _vm->_gnapActionStatus < 0) { + _vm->gnapWalkTo(-1, -1, -1, -1, 1); + _vm->_mouseClickState._left = false; } break; - } - scene39_updateAnimations(); + updateAnimations(); - if (!_isLeavingScene) { - if (_platypusActionStatus < 0) - updatePlatypusIdleSequence(); - if (_gnapActionStatus < 0) - updateGnapIdleSequence(); - if (!_timers[5]) { - _timers[5] = getRandom(20) + 50; - switch (getRandom(4)) { + if (!_vm->_isLeavingScene) { + if (_vm->_platypusActionStatus < 0) + _vm->updatePlatypusIdleSequence(); + if (_vm->_gnapActionStatus < 0) + _vm->updateGnapIdleSequence(); + if (!_vm->_timers[5]) { + _vm->_timers[5] = _vm->getRandom(20) + 50; + switch (_vm->getRandom(4)) { case 0: _s39_nextGuySequenceId = 0x30; break; @@ -206,38 +209,34 @@ void GnapEngine::scene39_run() { } } - checkGameKeys(); + _vm->checkGameKeys(); - if (isKeyStatus1(8)) { - clearKeyStatus1(8); - runMenu(); - scene39_updateHotspots(); - _timers[5] = getRandom(20) + 50; + if (_vm->isKeyStatus1(8)) { + _vm->clearKeyStatus1(8); + _vm->runMenu(); + updateHotspots(); + _vm->_timers[5] = _vm->getRandom(20) + 50; } - gameUpdateTick(); - + _vm->gameUpdateTick(); } - } -void GnapEngine::scene39_updateAnimations() { - - if (_gameSys->getAnimationStatus(0) == 2) { - _gameSys->setAnimation(0, 0, 0); - if (_gnapActionStatus == kASLeaveScene) - _sceneDone = true; +void Scene39::updateAnimations() { + if (_vm->_gameSys->getAnimationStatus(0) == 2) { + _vm->_gameSys->setAnimation(0, 0, 0); + if (_vm->_gnapActionStatus == kASLeaveScene) + _vm->_sceneDone = true; else - _gnapActionStatus = -1; + _vm->_gnapActionStatus = -1; } - if (_gameSys->getAnimationStatus(3) == 2 && _s39_nextGuySequenceId != -1) { - _gameSys->setAnimation(_s39_nextGuySequenceId, 21, 3); - _gameSys->insertSequence(_s39_nextGuySequenceId, 21, _s39_currGuySequenceId, 21, kSeqSyncWait, 0, 0, 0); + if (_vm->_gameSys->getAnimationStatus(3) == 2 && _s39_nextGuySequenceId != -1) { + _vm->_gameSys->setAnimation(_s39_nextGuySequenceId, 21, 3); + _vm->_gameSys->insertSequence(_s39_nextGuySequenceId, 21, _s39_currGuySequenceId, 21, kSeqSyncWait, 0, 0, 0); _s39_currGuySequenceId = _s39_nextGuySequenceId; _s39_nextGuySequenceId = -1; } - } } // End of namespace Gnap diff --git a/engines/gnap/scenes/scene39.h b/engines/gnap/scenes/scene39.h new file mode 100644 index 0000000000..68dfdfd8e4 --- /dev/null +++ b/engines/gnap/scenes/scene39.h @@ -0,0 +1,50 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef GNAP_SCENE39_H +#define GNAP_SCENE39_H + +#include "gnap/debugger.h" +#include "gnap/scenes/scenecore.h" + +namespace Gnap { + +class GnapEngine; + +class Scene39: public Scene { +public: + Scene39(GnapEngine *vm); + ~Scene39() {} + + virtual int init(); + virtual void updateHotspots(); + virtual void run(); + virtual void updateAnimations(); + virtual void updateAnimationsCb() {}; + +private: + int _s39_currGuySequenceId; + int _s39_nextGuySequenceId; +}; + +} // End of namespace Gnap +#endif // GNAP_SCENE39_H diff --git a/engines/gnap/scenes/scenecore.cpp b/engines/gnap/scenes/scenecore.cpp index 75a1f572a6..cd793fd8e3 100644 --- a/engines/gnap/scenes/scenecore.cpp +++ b/engines/gnap/scenes/scenecore.cpp @@ -60,6 +60,7 @@ #include "gnap/scenes/scene32.h" #include "gnap/scenes/scene33.h" #include "gnap/scenes/scene38.h" +#include "gnap/scenes/scene39.h" #include "gnap/scenes/scene47.h" #include "gnap/scenes/scene48.h" #include "gnap/scenes/scene54.h" @@ -340,8 +341,9 @@ int GnapEngine::initSceneLogic() { initSceneGrid(21, 146, 11, 10); break; case 39: - backgroundId = scene39_init(); - scene39_updateHotspots(); + _scene = new Scene39(this); + backgroundId = _scene->init(); + _scene->updateHotspots(); _gameSys->setScaleValues(0, 500, 1, 1000); initSceneGrid(21, 146, 11, 10); break; @@ -658,7 +660,8 @@ void GnapEngine::runSceneLogic() { _newSceneNum = 37; break; case 39: - scene39_run(); + _scene->run(); + delete _scene; if (_newSceneNum == 55) _newSceneNum = 37; break; -- cgit v1.2.3