From 5a34d20ec857ab6142baea9d021cb9ff84196589 Mon Sep 17 00:00:00 2001 From: johndoe123 Date: Wed, 6 Jul 2011 19:56:15 +0000 Subject: [PATCH] NEVERHOOD: More work on Scene1001, also give sprites classes and vars some better names --- engines/neverhood/module1000.cpp | 247 ++++++++++++++++++++++++------- engines/neverhood/module1000.h | 47 ++++-- engines/neverhood/neverhood.cpp | 5 +- 3 files changed, 233 insertions(+), 66 deletions(-) diff --git a/engines/neverhood/module1000.cpp b/engines/neverhood/module1000.cpp index c3aa0c9ccdb..d5b7b034813 100644 --- a/engines/neverhood/module1000.cpp +++ b/engines/neverhood/module1000.cpp @@ -132,30 +132,23 @@ void Module1000::updateScene1005() { // Scene1001 -Class509::Class509(NeverhoodEngine *vm) +AsScene1001Door::AsScene1001Door(NeverhoodEngine *vm) : AnimatedSprite(vm, 1100), _soundResource1(vm), _soundResource2(vm) { - _name = "Class509"; - createSurface(800, 137, 242); - _x = 726; _y = 440; - callback1(); - #if 0 _soundResource2.set(0xED403E03); _soundResource2.load(); _soundResource2.createSoundBuffer(); #endif - SetUpdateHandler(&AnimatedSprite::update); - SetMessageHandler(&Class509::handleMessage); - + SetMessageHandler(&AsScene1001Door::handleMessage); } -uint32 Class509::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { +uint32 AsScene1001Door::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { Sprite::handleMessage(messageNum, param, sender); switch (messageNum) { case 0x2000: @@ -168,18 +161,9 @@ uint32 Class509::handleMessage(int messageNum, const MessageParam ¶m, Entity return 0; } -void Class509::handleMessage2000h() { - +void AsScene1001Door::handleMessage2000h() { switch (_vm->getGlobalVar(0x52371C95)) { case 0: -#if 0 - _soundResource1.set(0x65482F03); - _soundResource1.load(); - _soundResource1.play(false); -#endif - setFileHash(0x624C0498, 1, 3); - SetAnimationCallback3(&Class509::callback1); - break; case 1: #if 0 _soundResource1.set(0x65482F03); @@ -187,25 +171,23 @@ void Class509::handleMessage2000h() { _soundResource1.play(false); #endif setFileHash(0x624C0498, 1, 3); - SetAnimationCallback3(&Class509::callback1); + SetAnimationCallback3(&AsScene1001Door::callback1); break; case 2: #if 0 _soundResource2.play(false); #endif setFileHash(0x624C0498, 6, 6); - SetAnimationCallback3(&Class509::callback2); + SetAnimationCallback3(&AsScene1001Door::callback2); break; default: // Nothing break; } - _vm->incGlobalVar(0x52371C95, 1); - } -void Class509::callback1() { +void AsScene1001Door::callback1() { switch (_vm->getGlobalVar(0x52371C95)) { case 1: setFileHash(0x624C0498, 4, -1); @@ -226,14 +208,14 @@ void Class509::callback1() { } } -void Class509::callback2() { +void AsScene1001Door::callback2() { _vm->setGlobalVar(0xD217189D, 1); setFileHash(0x624C0498, 6, 6); - SetAnimationCallback3(&Class509::callback3); + SetAnimationCallback3(&AsScene1001Door::callback3); _x = 30; } -void Class509::callback3() { +void AsScene1001Door::callback3() { #if 0 _soundResource1.play(false); #endif @@ -241,7 +223,84 @@ void Class509::callback3() { _surface->setVisible(false); } -Class511::Class511(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y, int deltaXType) +AsScene1001Hammer::AsScene1001Hammer(NeverhoodEngine *vm, Sprite *asDoor) + : AnimatedSprite(vm, 1100), _soundResource(vm), _asDoor(asDoor) { + + _x = 547; + _y = 206; + createSurface(900, 177, 192); + setFileHash(0x022C90D4, -1, -1); + _newHashListIndex = -2; + SetUpdateHandler(&AnimatedSprite::update); + SetMessageHandler(&AsScene1001Hammer::handleMessage); +} + +uint32 AsScene1001Hammer::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { + Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param._integer == 0x00352100) { + if (_asDoor) { + _asDoor->sendMessage(0x2000, 0, this); + } + } else if (param._integer == 0x0A1A0109) { +#if 0 + _soundResource.set(0x66410886); + _soundResource.load(); + _soundResource.play(false); +#endif + } + break; + case 0x2000: + setFileHash(0x022C90D4, 1, -1); +#if 0 + _soundResource.set(0xE741020A); + _soundResource.load(); + _soundResource.play(false); +#endif + _newHashListIndex = -2; + break; + } + return 0; +} + +AsScene1001Window::AsScene1001Window(NeverhoodEngine *vm) + : AnimatedSprite(vm, 1200), _soundResource(vm) { + + _x = 320; + _y = 240; + createSurface(100, 66, 129); + setFileHash(0xC68C2299, 0, -1); + _newHashListIndex = 0; + SetUpdateHandler(&AnimatedSprite::update); + SetMessageHandler(&AsScene1001Window::handleMessage); +} + +uint32 AsScene1001Window::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { + Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param._integer == 0x0E0A1410) { +#if 0 + _soundResource.set(0x60803F10); + _soundResource.load(); + _soundResource.play(false); +#endif + } + break; + case 0x2001: + setFileHash(0xC68C2299, 0, -1); + break; + case 0x3002: + SetMessageHandler(NULL); + _vm->setGlobalVar(0x03C698DA, 1); + _surface->setVisible(false); + break; + } + return 0; +} + +AsScene1001Lever::AsScene1001Lever(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y, int deltaXType) : AnimatedSprite(vm, 1100), _soundResource(vm), _parentScene(parentScene) { createSurface(1010, 71, 73); @@ -251,10 +310,10 @@ Class511::Class511(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y, in _x = x; _y = y; SetUpdateHandler(&AnimatedSprite::update); - SetMessageHandler(&Class511::handleMessage); + SetMessageHandler(&AsScene1001Lever::handleMessage); } -uint32 Class511::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { +uint32 AsScene1001Lever::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); switch (messageNum) { case 0x100D: @@ -288,7 +347,40 @@ uint32 Class511::handleMessage(int messageNum, const MessageParam ¶m, Entity } return messageResult; } - + +SsCommonButtonSprite::SsCommonButtonSprite(NeverhoodEngine *vm, Scene *parentScene, uint32 fileHash, int surfacePriority, uint32 soundFileHash) + : StaticSprite(vm, fileHash, surfacePriority), _parentScene(parentScene), _soundResource(vm), _countdown(0) { + + _priority = 1100; + _soundFileHash = soundFileHash != 0 ? soundFileHash : 0x44141000; + _surface->setVisible(false); + SetUpdateHandler(&SsCommonButtonSprite::update); + SetMessageHandler(&SsCommonButtonSprite::handleMessage); +} + +void SsCommonButtonSprite::update() { + if (_countdown != 0 && (--_countdown) == 0) { + _surface->setVisible(false); + } +} + +uint32 SsCommonButtonSprite::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x480B: + _parentScene->sendMessage(0x480B, 0, this); + _surface->setVisible(true); + _countdown = 8; +#if 0 + _soundResource.set(_soundFileHash); + _soundResource.load(); + _soundResource.play(false); +#endif + break; + } + return messageResult; +} + Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which) : Scene(vm, parentModule, true), _fieldE4(-1), _fieldE6(-1) { @@ -346,47 +438,90 @@ Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which) #endif if (_vm->getGlobalVar(0xD217189D) == 0) { - _class509 = addSprite(new Class509(_vm)); - _class509->getSurface()->getClipRect().x1 = 0; - _class509->getSurface()->getClipRect().y1 = 0; - _class509->getSurface()->getClipRect().x2 = staticSprite1->getSurface()->getDrawRect().x + staticSprite1->getSurface()->getDrawRect().width; - _class509->getSurface()->getClipRect().y2 = 480; + _asDoor = addSprite(new AsScene1001Door(_vm)); + _asDoor->getSurface()->getClipRect().x1 = 0; + _asDoor->getSurface()->getClipRect().y1 = 0; + _asDoor->getSurface()->getClipRect().x2 = staticSprite1->getSurface()->getDrawRect().x + staticSprite1->getSurface()->getDrawRect().width; + _asDoor->getSurface()->getClipRect().y2 = 480; } else { - _class509 = NULL; + _asDoor = NULL; } - _class511 = addSprite(new Class511(_vm, this, 150, 433, 1)); + _asLever = addSprite(new AsScene1001Lever(_vm, this, 150, 433, 1)); addSprite(new StaticSprite(_vm, 0x809861A6, 950)); addSprite(new StaticSprite(_vm, 0x89C03848, 1100)); -#if 0 - _class608 = addSprite(new Class608(_vm, 0x15288120, 100, 0)); -#endif + _ssButton = addSprite(new SsCommonButtonSprite(_vm, this, 0x15288120, 100, 0)); if (_vm->getGlobalVar(0x03C698DA) == 0) { staticSprite1 = addSprite(new StaticSprite(_vm, 0x8C066150, 200)); -#if 0 - _class510 = addSprite(new Class510(_vm)); - _class510->getSurface()->getClipRect().x1 = staticSprite1->getSurface()->getDrawRect().x; - _class510->getSurface()->getClipRect().y1 = staticSprite1->getSurface()->getDrawRect().y; - _class510->getSurface()->getClipRect().x2 = staticSprite1->getSurface()->getDrawRect().x + staticSprite1->getSurface()->getDrawRect().width; - _class510->getSurface()->getClipRect().y2 = staticSprite1->getSurface()->getDrawRect().y + staticSprite1->getSurface()->getDrawRect().height; -#endif + _asWindow = addSprite(new AsScene1001Window(_vm)); + _asWindow->getSurface()->getClipRect().x1 = staticSprite1->getSurface()->getDrawRect().x; + _asWindow->getSurface()->getClipRect().y1 = staticSprite1->getSurface()->getDrawRect().y; + _asWindow->getSurface()->getClipRect().x2 = staticSprite1->getSurface()->getDrawRect().x + staticSprite1->getSurface()->getDrawRect().width; + _asWindow->getSurface()->getClipRect().y2 = staticSprite1->getSurface()->getDrawRect().y + staticSprite1->getSurface()->getDrawRect().height; } else { - _class510= NULL; + _asWindow = NULL; } -#if 0 - _class508 = addSprite(new Class508(_vm, _class509)); -#endif - - _class511->sendMessage(0x480F, 0, this); + _asHammer = addSprite(new AsScene1001Hammer(_vm, _asDoor)); } uint32 Scene1001::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { - return 0; + uint32 messageResult = 0; + Scene::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x0001: + if (param._point.x == 0 && _vm->getGlobalVar(0xA4014072)) { + _parentModule->sendMessage(0x1009, 0, this); + } + break; + case 0x000D: + if (param._integer == 0x188B2105) { + _parentModule->sendMessage(0x1009, 0, this); + messageResult = 1; + } + break; + case 0x100D: + if (param._integer == 0x00342624) { + // TODO _playerSprite->sendMessage(0x1014, _asLever, this); + // TODO setMessageList2(0x004B4910, true, false); + messageResult = 1; + } else if (param._integer == 0x21E64A00) { + if (_vm->getGlobalVar(0xD217189D)) { + // TODO setMessageList(0x004B48A8, true, false); + messageResult = 1; + } else { + // TODO setMessageList(0x004B48C8, true, false); + messageResult = 1; + } + } else if (param._integer == 0x040424D0) { + // TODO _playerSprite->sendMessage(0x1014, _ssButton, this); + } else if (param._integer == 0x80006358) { + if (_vm->getGlobalVar(0x03C698DA)) { + // TODO setMessageList(0x004B4938, true, false); + } else { + // TODO setMessageList(0x004B4960, true, false); + } + } + break; + case 0x2002: + // TODO setRectList(0x004B49F0); + break; + case 0x480B: + if (_asWindow) { + _asWindow->sendMessage(0x2001, 0, this); + } + break; + case 0x480F: + if (_asHammer) { + _asHammer->sendMessage(0x2000, 0, this); + } + break; + } + return messageResult; } } // End of namespace Neverhood diff --git a/engines/neverhood/module1000.h b/engines/neverhood/module1000.h index 219448a2bf2..82c2feab137 100644 --- a/engines/neverhood/module1000.h +++ b/engines/neverhood/module1000.h @@ -55,9 +55,9 @@ protected: // Scene1001 -class Class509 : public AnimatedSprite { +class AsScene1001Door : public AnimatedSprite { public: - Class509(NeverhoodEngine *vm); + AsScene1001Door(NeverhoodEngine *vm); protected: SoundResource _soundResource1; SoundResource _soundResource2; @@ -68,24 +68,53 @@ protected: void callback3(); }; -class Class511 : public AnimatedSprite { +class AsScene1001Hammer : public AnimatedSprite { public: - Class511(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y, int deltaXType); + AsScene1001Hammer(NeverhoodEngine *vm, Sprite *asDoor); +protected: + Sprite *_asDoor; + SoundResource _soundResource; + uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); +}; + +class AsScene1001Window : public AnimatedSprite { +public: + AsScene1001Window(NeverhoodEngine *vm); +protected: + SoundResource _soundResource; + uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); +}; + +class AsScene1001Lever : public AnimatedSprite { +public: + AsScene1001Lever(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y, int deltaXType); protected: Scene *_parentScene; SoundResource _soundResource; uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); }; +class SsCommonButtonSprite : public StaticSprite { +public: + SsCommonButtonSprite(NeverhoodEngine *vm, Scene *parentScene, uint32 fileHash, int surfacePriority, uint32 soundFileHash); +protected: + Scene *_parentScene; + SoundResource _soundResource; + uint32 _soundFileHash; + int16 _countdown; + void update(); + uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); +}; + class Scene1001 : public Scene { public: Scene1001(NeverhoodEngine *vm, Module *parentModule, int which); protected: - Sprite *_class508; - Sprite *_class509; - Sprite *_class510; - Sprite *_class511; - Sprite *_class608; + Sprite *_asHammer; + Sprite *_asDoor; + Sprite *_asWindow; + Sprite *_asLever; + Sprite *_ssButton; int16 _fieldE4; int16 _fieldE6; uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); diff --git a/engines/neverhood/neverhood.cpp b/engines/neverhood/neverhood.cpp index 1ba2c988609..4c80c402749 100644 --- a/engines/neverhood/neverhood.cpp +++ b/engines/neverhood/neverhood.cpp @@ -133,7 +133,7 @@ Common::Error NeverhoodEngine::run() { _gameModule = new GameModule(this); // Preliminary main loop, needs some more work but works for testing - while (1) { + while (!shouldQuit()) { Common::Event event; Common::EventManager *eventMan = _system->getEventManager(); @@ -141,6 +141,9 @@ Common::Error NeverhoodEngine::run() { switch (event.type) { case Common::EVENT_KEYDOWN: _keyState = event.kbd.keycode; + + // DEBUG gameModule->sendMessage(0x480F, 0, NULL); + break; case Common::EVENT_KEYUP: _keyState = Common::KEYCODE_INVALID;