diff options
author | johndoe123 | 2011-07-13 18:38:40 +0000 |
---|---|---|
committer | Willem Jan Palenstijn | 2013-05-08 20:38:47 +0200 |
commit | 436f8952bbd168c53481bd19f9d79372dd0561c9 (patch) | |
tree | 94147d8897b9c2706ca848d038b89eaec20726d1 /engines/neverhood | |
parent | b611b65bf42a3f2d710199fa69428ec1012a0108 (diff) | |
download | scummvm-rg350-436f8952bbd168c53481bd19f9d79372dd0561c9.tar.gz scummvm-rg350-436f8952bbd168c53481bd19f9d79372dd0561c9.tar.bz2 scummvm-rg350-436f8952bbd168c53481bd19f9d79372dd0561c9.zip |
NEVERHOOD: More work on Scene1002, Klayman and the rest
- Add "heavy debug" output to Entity (display which update/message handler is called)
- Also add more debug output
- Error out when a StaticData resource could not be found
Diffstat (limited to 'engines/neverhood')
-rw-r--r-- | engines/neverhood/collisionman.cpp | 19 | ||||
-rw-r--r-- | engines/neverhood/collisionman.h | 1 | ||||
-rw-r--r-- | engines/neverhood/entity.h | 11 | ||||
-rw-r--r-- | engines/neverhood/klayman.cpp | 947 | ||||
-rw-r--r-- | engines/neverhood/klayman.h | 71 | ||||
-rw-r--r-- | engines/neverhood/module1000.cpp | 580 | ||||
-rw-r--r-- | engines/neverhood/module1000.h | 82 | ||||
-rw-r--r-- | engines/neverhood/mouse.cpp | 16 | ||||
-rw-r--r-- | engines/neverhood/resource.cpp | 10 | ||||
-rw-r--r-- | engines/neverhood/scene.cpp | 4 | ||||
-rw-r--r-- | engines/neverhood/sprite.cpp | 7 | ||||
-rw-r--r-- | engines/neverhood/sprite.h | 20 | ||||
-rw-r--r-- | engines/neverhood/staticdata.cpp | 6 |
13 files changed, 1701 insertions, 73 deletions
diff --git a/engines/neverhood/collisionman.cpp b/engines/neverhood/collisionman.cpp index 31bc16d23c..87ec0cdcad 100644 --- a/engines/neverhood/collisionman.cpp +++ b/engines/neverhood/collisionman.cpp @@ -39,6 +39,16 @@ void CollisionMan::setHitRects(uint32 id) { void CollisionMan::setHitRects(HitRectList *hitRects) { _hitRects = hitRects; + + // DEBUG + if (_hitRects) { + debug("CollisionMan::setHitRects() count = %d", _hitRects->size()); + for (HitRectList::iterator it = _hitRects->begin(); it != _hitRects->end(); it++) { + HitRect *hitRect = &(*it); + debug("(%d, %d, %d, %d) -> %04X", hitRect->rect.x1, hitRect->rect.y1, hitRect->rect.x2, hitRect->rect.y2, hitRect->type); + } + } + } void CollisionMan::clearHitRects() { @@ -79,6 +89,15 @@ void CollisionMan::clearSprites() { _sprites.clear(); } +void CollisionMan::checkCollision(Sprite *sprite, uint16 flags, int messageNum, uint32 messageParam) { + for (Common::Array<Sprite*>::iterator iter = _sprites.begin(); iter != _sprites.end(); iter++) { + Sprite *collSprite = *iter; + if ((sprite->getFlags() & flags) && collSprite->checkCollision(sprite->getRect())) { + collSprite->sendMessage(messageNum, messageParam, sprite); + } + } +} + void CollisionMan::save() { // TODO } diff --git a/engines/neverhood/collisionman.h b/engines/neverhood/collisionman.h index 155859923b..86359525b0 100644 --- a/engines/neverhood/collisionman.h +++ b/engines/neverhood/collisionman.h @@ -40,6 +40,7 @@ public: void addSprite(Sprite *sprite); void removeSprite(Sprite *sprite); void clearSprites(); + void checkCollision(Sprite *sprite, uint16 flags, int messageNum, uint32 messageParam); void save(); void restore(); uint getSpriteCount() const { return _sprites.size(); } diff --git a/engines/neverhood/entity.h b/engines/neverhood/entity.h index 7538b36ce2..18c6b7e7b9 100644 --- a/engines/neverhood/entity.h +++ b/engines/neverhood/entity.h @@ -23,6 +23,7 @@ #ifndef NEVERHOOD_ENTITY_H #define NEVERHOOD_ENTITY_H +#include "common/str.h" #include "neverhood/neverhood.h" #include "neverhood/gamevars.h" #include "neverhood/graphics.h" @@ -71,12 +72,16 @@ protected: // TODO: Constructors for the param types... }; -#define SetUpdateHandler(handler) _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler) -#define SetMessageHandler(handler) _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam ¶m, Entity *sender)> (handler) +// TODO: Disable heavy debug stuff in release mode + +#define SetUpdateHandler(handler) _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler); debug("SetUpdateHandler(" #handler ")"); _updateHandlerCbName = #handler +#define SetMessageHandler(handler) _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam ¶m, Entity *sender)> (handler); debug("SetMessageHandler(" #handler ")"); _messageHandlerCbName = #handler class Entity { public: Common::String _name; // Entity name for debugging purposes + Common::String _updateHandlerCbName; + Common::String _messageHandlerCbName; Entity(NeverhoodEngine *vm, int priority) : _vm(vm), _updateHandlerCb(NULL), _messageHandlerCb(NULL), _priority(priority), _name("Entity") { } @@ -86,11 +91,13 @@ public: } void handleUpdate() { //debug("Entity(%s).handleUpdate", _name.c_str()); + debug(2, "handleUpdate() -> [%s]", _updateHandlerCbName.c_str()); if (_updateHandlerCb) (this->*_updateHandlerCb)(); } bool hasMessageHandler() const { return _messageHandlerCb != NULL; } uint32 sendMessage(int messageNum, const MessageParam ¶m, Entity *sender) { + debug(2, "sendMessage(%04X) -> [%s]", messageNum, _messageHandlerCbName.c_str()); return _messageHandlerCb ? (this->*_messageHandlerCb)(messageNum, param, sender) : 0; } // NOTE: These were overloaded before for the various message parameter types diff --git a/engines/neverhood/klayman.cpp b/engines/neverhood/klayman.cpp index 9acda937e2..51dde55548 100644 --- a/engines/neverhood/klayman.cpp +++ b/engines/neverhood/klayman.cpp @@ -58,7 +58,7 @@ Klayman::Klayman(NeverhoodEngine *vm, Entity *parentScene, int16 x, int16 y, int _status3(1), _parentScene(parentScene), _flagE2(false), _flagE3(false), _flagF6(false), _flagF7(false), _flagFA(false), _statusE0(0), _field114(0), _resourceHandle(-1), _soundFlag(false) { - // TODO + // TODO DirtySurface createSurface(surfacePriority, 320, 200); _x = x; _y = y; @@ -84,6 +84,7 @@ uint32 Klayman::xHandleMessage(int messageNum, const MessageParam ¶m) { setCallback2(AnimationCallback(&Klayman::sub41FC80)); break; case 0x4818: + debug("TODO sub41C930"); // TODO sub41C930(_rectResource.getRectangle1(param.asInteger()).x, false); break; } @@ -304,7 +305,8 @@ bool Klayman::sub41CF10(AnimationCb callback) { return false; } - void Klayman::sub41C7B0() { +void Klayman::sub41C7B0() { + debug("Klayman::sub41C7B0()"); if (_callback1Cb) { AnimationCb cb = _callback1Cb; _callback1Cb = NULL; @@ -334,6 +336,7 @@ void Klayman::sub41C790() { } void Klayman::sub41FC80() { + //ok if (!sub41CF10(AnimationCallback(&Klayman::sub41FC80))) { _status2 = 1; _flagE5 = true; @@ -430,6 +433,7 @@ uint32 Klayman::handleMessage41D480(int messageNum, const MessageParam ¶m, E } void Klayman::sub41FCF0() { + //ok _status2 = 1; _flagE5 = true; setFileHash(0x5420E254, 0, -1); @@ -505,6 +509,7 @@ void Klayman::sub4211B0() { } uint32 Klayman::handleMessage41E920(int messageNum, const MessageParam ¶m, Entity *sender) { + //ok debug("Klayman::handleMessage41E920(%04X)", messageNum); uint32 messageResult = handleMessage41D360(messageNum, param, sender); switch (messageNum) { @@ -587,7 +592,8 @@ void Klayman::spriteUpdate41F5F0() { HitRect *hitRectPrev = _vm->_collisionMan->findHitRectAtPos(_x, _y); _x += xdiff; if (_field114) { - // TODO KlaymanSprite_sub_41CF70 + error("// TODO Klayman_sub_41CF70"); + // TODO Klayman_sub_41CF70 } else { HitRect *hitRectNext = _vm->_collisionMan->findHitRectAtPos(_x, _y); if (hitRectNext->type == 0x5002) { @@ -818,7 +824,7 @@ void Klayman::spriteUpdate41F320() { _x += xdelta; if (_field114) { debug("_field114"); - // TODO KlaymanSprite_sub_41CF70 + // TODO Klayman_sub_41CF70 } else { HitRect *hitRectNext = _vm->_collisionMan->findHitRectAtPos(_x, _y); if (hitRectNext->type == 0x5002) { @@ -1059,8 +1065,8 @@ void Klayman::spriteUpdate41F780() { HitRect *hitRectPrev = _vm->_collisionMan->findHitRectAtPos(_x, _y); _x += xdiff; if (_field114) { - debug("// TODO KlaymanSprite_sub_41CF70();"); - // TODO KlaymanSprite_sub_41CF70(); + error("// TODO Klayman_sub_41CF70();"); + // TODO Klayman_sub_41CF70(); } else { HitRect *hitRectNext = _vm->_collisionMan->findHitRectAtPos(_x, _y); if (hitRectNext->type == 0x5002) { @@ -1164,6 +1170,405 @@ void Klayman::sub420830() { SetSpriteCallback(NULL); } +void Klayman::sub41FC40() { + _status2 = 1; + _flagE5 = true; + setFileHash(0xAC20C012, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E3C0); + SetSpriteCallback(NULL); +} + +uint32 Klayman::handleMessage41E3C0(int messageNum, const MessageParam ¶m, Entity *sender) { + switch (messageNum) { + case 0x1008: + debug("case 0x1008"); +#if 0 // TODO + if (_frameIndex < getHashListIndexByString("SpeedUp")) { + setFileHash(0xAC20C012, getHashListIndexByString("SpeedUp"), -1) + _y = 435; + } +#endif + return 0; + case 0x100D: + if (param.asInteger() == 0x32180101) { + _soundResource1.play(0x405002D8); + } else if (param.asInteger() == 0x0A2A9098) { + _soundResource1.play(0x0460E2FA); + } + break; + } + return handleMessage41D480(messageNum, param, sender); +} + +void Klayman::sub420210() { + if (!sub41CEB0(AnimationCallback(&Klayman::sub420210))) { + _status2 = 0; + setFileHash(0xD82890BA, 0, -1); + sub4201C0(); + } +} + +void Klayman::sub4201C0() { + _flagE5 = false; + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41D790); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + SetAnimationCallback3(&Klayman::sub420340); + _attachedSprite->sendMessage(0x482B, 0, this); +} + +uint32 Klayman::handleMessage41D790(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = handleMessage41D480(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x168050A0) { + if (_attachedSprite) { + _attachedSprite->sendMessage(0x4806, 0, this); + } + _flagE5 = true; + } else if (param.asInteger() == 0x320AC306) { + _soundResource1.play(0x5860C640); + } else if (param.asInteger() == 0x4AB28209) { + _attachedSprite->sendMessage(0x482A, 0, this); + } else if (param.asInteger() == 0x88001184) { + _attachedSprite->sendMessage(0x482B, 0, this); + } + break; + } + return messageResult; +} + +void Klayman::spriteUpdate41F230() { + AnimatedSprite::updateDeltaXY(); + _x4 = _x; +} + +void Klayman::sub420340() { + _status2 = 0; + _flagE5 = true; + setFileHash(0x4829E0B8, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41D360); + SetSpriteCallback(NULL); +} + +void Klayman::sub420250() { + if (!sub41CEB0(AnimationCallback(&Klayman::sub420250))) { + _status2 = 0; + setFileHash(0x900980B2, 0, -1); + sub4201C0(); + } +} + +void Klayman::sub420290() { + if (!sub41CEB0(AnimationCallback(&Klayman::sub420290))) { + _status2 = 0; + _flagE5 = false; + setFileHash(0xBA1910B2, 0, -1); + SetUpdateHandler(&Klayman::update); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + SetMessageHandler(&Klayman::handleMessage41D880); + SetAnimationCallback3(&Klayman::sub420380); + _attachedSprite->sendMessage(0x482B, 0, this); + } +} + +uint32 Klayman::handleMessage41D880(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = handleMessage41D480(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x168050A0) { + if (_attachedSprite) { + _attachedSprite->sendMessage(0x4806, 0, this); + } + } else if (param.asInteger() == 0x320AC306) { + _soundResource1.play(0x5860C640); + } else if (param.asInteger() == 0x4AB28209) { + _attachedSprite->sendMessage(0x482A, 0, this); + } else if (param.asInteger() == 0x88001184) { + _attachedSprite->sendMessage(0x482B, 0, this); + } + break; + } + return messageResult; +} + +void Klayman::sub420380() { + _status2 = 0; + _flagE5 = true; + setFileHash(0x4A293FB0, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41DAA0); + SetSpriteCallback(NULL); +} + +uint32 Klayman::handleMessage41DAA0(int messageNum, const MessageParam ¶m, Entity *sender) { + if (messageNum == 0x1008) { + sub4203C0(); + return 0; + } + return handleMessage41D360(messageNum, param, sender); +} + +void Klayman::sub4203C0() { + _status2 = 1; + _flagE5 = false; + if (_attachedSprite) { + _attachedSprite->sendMessage(0x4807, 0, this); + _attachedSprite = NULL; + } + setFileHash(0xB869A4B9, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41D480); + SetSpriteCallback(NULL); +} + +void Klayman::sub420300() { + if (!sub41CEB0(AnimationCallback(&Klayman::sub420300))) { + _status2 = 0; + setFileHash(0xB8699832, 0, -1); + sub4201C0(); + } +} + +void Klayman::sub41CCE0(int16 x) { + sub41CC40(((Sprite*)_attachedSprite)->getX(), x); +} + +void Klayman::sub420970() { + _status2 = 0; + _flagE5 = true; + _statusE0 = 3; + setFileHash2(0x3A292504, 0x01084280, 0); + _fileHash4 = 0x01084280; + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41D360); + SetSpriteCallback(NULL); + sub41C7B0(); +} + +void Klayman::sub4209D0() { + if (!sub41CEB0(AnimationCallback(&Klayman::sub4209D0))) { + _status2 = 0; + if (_y4 < _y) { + if (_statusE0 == 1) { + _statusE0 = 2; + sub420BC0(); + } else { + sub41C7B0(); + } + } else if (_statusE0 == 0) { + _statusE0 = 2; + _flagE5 = false; + setFileHash(0x122D1505, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E0D0); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + } else if (_statusE0 == 3) { + _statusE0 = 2; + _flagE5 = false; + setFileHash2(0x122D1505, 0x01084280, 0); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E0D0); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + } else if (_statusE0 == 1) { + _statusE0 = 2; + _flagE5 = true; + setFileHash(0x122D1505, 29 - _frameIndex, -1); + } + } +} + +void Klayman::sub420BC0() { + _status2 = 2; + if (_statusE0 == 1) { + _statusE0 = 0; + _flagE5 = false; + setFileHash2(0x3A292504, 0x02421405, 0); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41DFD0); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + } else if (_statusE0 == 1) { + _statusE0 = 0; + _flagE5 = false; + setFileHash2(0x122D1505, 0x02421405, 0); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41DFD0); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + } else { + sub41C7B0(); + } +} + +uint32 Klayman::handleMessage41DFD0(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = handleMessage41D480(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x489B025C) { + _soundResource1.play(0x52C4C2D7); + } else if (param.asInteger() == 0x400A0E64) { + _soundResource1.play(0x50E081D9); + } else if (param.asInteger() == 0x32180101) { + _soundResource1.play(0x405002D8); + } else if (param.asInteger() == 0x0A2A9098) { + _soundResource1.play(0x0460E2FA); + } + break; + } + return messageResult; +} + +uint32 Klayman::handleMessage41E0D0(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = handleMessage41D360(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x01084280) { + _flagE5 = true; + } else if (param.asInteger() == 0x489B025C) { + _soundResource1.play(0x52C4C2D7); + } else if (param.asInteger() == 0x400A0E64) { + _soundResource1.play(0x50E081D9); + } else if (param.asInteger() == 0x02421405) { + if (_statusE0 == 1) { + setFileHash2(0x3A292504, 0x01084280, 0); + } else { + setFileHash2(0x122D1505, 0x01084280, 0); + } + if (_statusE0 == 1) { + if (_y4 >= _y - 30) { + sendMessage(0x1019, 0, this); + } + } else { + if (_y4 <= _y) { + sendMessage(0x1019, 0, this); + } + } + } + break; + } + return messageResult; +} + +void Klayman::sub420AD0() { + if (!sub41CEB0(AnimationCallback(&Klayman::sub420AD0))) { + _status2 = 0; + if (_y4 >= _y - 30) { + sub41C7B0(); + } else if (_statusE0 == 0) { + _statusE0 = 1; + _flagE5 = false; + setFileHash(0x3A292504, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E0D0); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + } else if (_statusE0 == 3) { + _statusE0 = 1; + _flagE5 = true; + setFileHash2(0x3A292504, 0x01084280, 0); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E0D0); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + } else if (_statusE0 == 2) { + _statusE0 = 1; + _flagE5 = true; + setFileHash(0x3A292504, 29 - _frameIndex, -1); + } + } +} + +void Klayman::sub421030() { + _status2 = 2; + _flagE5 = false; + setFileHash2(0xF229C003, 0x14884392, 0); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E490); + SetSpriteCallback(&Klayman::spriteUpdate41F230); +} + +uint32 Klayman::handleMessage41E490(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = handleMessage41D480(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x80C110B5) { + _parentScene->sendMessage(0x482A, 0, this); + } else if (param.asInteger() == 0x110010D1) { + _parentScene->sendMessage(0x482B, 0, this); + } else if (param.asInteger() == 0x32180101) { + if (_soundFlag) { + _soundResource1.play(0x48498E46); + } else { + _soundResource1.play(0x405002D8); + } + } else if (param.asInteger() == 0x0A2A9098) { + if (_soundFlag) { + _soundResource1.play(0x50399F64); + } else { + _soundResource1.play(0x0460E2FA); + } + } + break; + } + return messageResult; +} + +void Klayman::sub420FE0() { + if (!sub41CEB0(AnimationCallback(&Klayman::sub420FE0))) { + _status2 = 2; + _flagE5 = false; + setFileHash(0xF229C003, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E490); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + } +} + +void Klayman::sub4210C0() { + if (!sub41CEB0(AnimationCallback(&Klayman::sub4210C0))) { + _status2 = 0; + _flagE5 = false; + setFileHash2(0xCA221107, 0x8520108C, 0); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E490); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + } +} + +void Klayman::sub421070() { + if (!sub41CEB0(AnimationCallback(&Klayman::sub421070))) { + _status2 = 2; + _flagE5 = false; + setFileHash(0xCA221107, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E490); + SetSpriteCallback(&Klayman::spriteUpdate41F230); + } +} + +void Klayman::sub420420() { + _status2 = 1; + _flagE5 = true; + setFileHash(0x18118554, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&Klayman::handleMessage41E290); + SetSpriteCallback(NULL); +} + +uint32 Klayman::handleMessage41E290(int messageNum, const MessageParam ¶m, Entity *sender) { + + uint32 messageResult = handleMessage41D480(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x320AC306) { + _soundResource1.play(0x5860C640); + } + break; + } + return messageResult; +} + +//############################################################################## + // KmScene1001 KmScene1001::KmScene1001(NeverhoodEngine *vm, Entity *parentScene, int16 x, int16 y) @@ -1210,8 +1615,7 @@ uint32 KmScene1001::xHandleMessage(int messageNum, const MessageParam ¶m) { if (param.asPoint().x != 0) { sub41CC40(param.asPoint().x, param.asPoint().y); } else { - error("// TODO sub41CCE0(param.asPoint().y);"); - // TODO sub41CCE0(param.asPoint().y); + sub41CCE0(param.asPoint().y); } break; @@ -1277,5 +1681,532 @@ uint32 KmScene1001::handleMessage44FA00(int messageNum, const MessageParam ¶ return messageResult; } +// KmScene1002 + +KmScene1002::KmScene1002(NeverhoodEngine *vm, Entity *parentScene, Sprite *class599, Sprite *ssLadderArch, int16 x, int16 y) + : Klayman(vm, parentScene, x, y, 1000, 1000), _class599(class599), _ssLadderArch(ssLadderArch), _otherSprite(NULL), + _status(0) { + + setKlaymanTable1(); + +} + +void KmScene1002::xUpdate() { + if (_x >= 250 && _x <= 435 && _y >= 420) { + if (_status == 0) { + // TODO setKlaymanTable(stru_4B44C8); + _status = 1; + } + } else if (_status == 1) { + setKlaymanTable1(); + _status = 0; + } +} + +uint32 KmScene1002::xHandleMessage(int messageNum, const MessageParam ¶m) { + //ok + debug("KmScene1002::xHandleMessage(%04X)", messageNum); + if (messageNum == 0x100D) + debug("-> %08X", param.asInteger()); + switch (messageNum) { + case 0x2001: + setCallback2(AnimationCallback(&KmScene1002::sub449E90)); + break; + case 0x2007: + _otherSprite = (Sprite*)param.asEntity(); + break; + case 0x4001: + case 0x4800: + sub41C930(param.asPoint().x, false); + break; + case 0x4004: + setCallback2(AnimationCallback(&Klayman::sub41FC80)); + break; + case 0x4803: + if (param.asInteger() == 1) { + setCallback2(AnimationCallback(&KmScene1002::sub44A250)); + } else if (param.asInteger() == 2) { + setCallback2(AnimationCallback(&KmScene1002::sub44A2C0)); + } + break; + case 0x4804: + setCallback2(AnimationCallback(&Klayman::sub41FC40)); + break; + case 0x4805: + switch (param.asInteger()) { + case 1: + setCallback2(AnimationCallback(&Klayman::sub420210)); + break; + case 2: + setCallback2(AnimationCallback(&Klayman::sub420250)); + break; + case 3: + setCallback2(AnimationCallback(&Klayman::sub420290)); + break; + case 4: + setCallback2(AnimationCallback(&Klayman::sub420300)); + break; + } + break; + case 0x480A: + setCallback2(AnimationCallback(&KmScene1002::sub44A3E0)); + break; + case 0x480D: + setCallback2(AnimationCallback(&KmScene1002::sub449E20)); + break; + case 0x4816: + if (param.asInteger() == 0) { + setCallback2(AnimationCallback(&KmScene1002::sub44A330)); + } + break; + case 0x4817: + setDoDeltaX(param.asInteger()); + sub41C7B0(); + break; + case 0x481B: + sub41CCE0(param.asInteger()); + break; + case 0x4820: + _parentScene->sendMessage(0x2005, 0, this); + setCallback2(AnimationCallback(&Klayman::sub420970)); + break; + case 0x4821: + _parentScene->sendMessage(0x2005, 0, this); + _y4 = param.asInteger(); + setCallback2(AnimationCallback(&Klayman::sub4209D0)); + break; + case 0x4822: + _parentScene->sendMessage(0x2005, 0, this); + _y4 = param.asInteger(); + setCallback2(AnimationCallback(&Klayman::sub420AD0)); + break; + case 0x4823: + _parentScene->sendMessage(0x2006, 0, this); + setCallback2(AnimationCallback(&Klayman::sub420BC0)); + break; + case 0x482E: + if (param.asInteger() == 1) { + setCallback2(AnimationCallback(&Klayman::sub421030)); + } else { + setCallback2(AnimationCallback(&Klayman::sub420FE0)); + } + break; + case 0x482F: + if (param.asInteger() == 1) { + setCallback2(AnimationCallback(&Klayman::sub4210C0)); + } else { + setCallback2(AnimationCallback(&Klayman::sub421070)); + } + break; + case 0x483F: + sub41CD00(param.asInteger()); + break; + case 0x4840: + sub41CD70(param.asInteger()); + break; + } + return 0; +} + +void KmScene1002::update4497D0() { + debug("KmScene1002::update4497D0()"); + Klayman::update(); + if (_counter1 != 0 && (--_counter1 == 0)) { + _surface->setVisible(true); + SetUpdateHandler(&Klayman::update); + } +} + +uint32 KmScene1002::handleMessage449800(int messageNum, const MessageParam ¶m, Entity *sender) { + //ok + uint32 messageResult = handleMessage41D480(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x168050A0) { + if (_attachedSprite) { + _attachedSprite->sendMessage(0x480F, 0, this); + } + } else if (param.asInteger() == 0x586B0300) { + if (_otherSprite) { + _otherSprite->sendMessage(0x480E, 1, this); + } + } else if (param.asInteger() == 0x4AB28209) { + if (_attachedSprite) { + _attachedSprite->sendMessage(0x482A, 0, this); + } + } else if (param.asInteger() == 0x88001184) { + if (_attachedSprite) { + _attachedSprite->sendMessage(0x482B, 0, this); + } + } + break; + } + return messageResult; +} + +uint32 KmScene1002::handleMessage4498E0(int messageNum, const MessageParam ¶m, Entity *sender) { + //ok + switch (messageNum) { + case 0x4811: + _soundResource1.play(0x5252A0E4); + setDoDeltaX(((Sprite*)sender)->isDoDeltaX() ? 1 : 0); + if (_doDeltaX) { + _x = ((Sprite*)sender)->getX() - 75; + } else { + _x = ((Sprite*)sender)->getX() + 75; + } + _y = ((Sprite*)sender)->getY() - 200; + + debug("&&&&&&&&&&& param.asInteger() = %d", param.asInteger()); + + if (param.asInteger() == 0) { + sub449EF0(); + } else if (param.asInteger() == 1) { + sub44A0D0(); + } else if (param.asInteger() == 2) { + sub44A050(); + } + break; + } + return 0; +} + +uint32 KmScene1002::handleMessage449990(int messageNum, const MessageParam ¶m, Entity *sender) { + //ok + uint32 messageResult = handleMessage41D480(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x942D2081) { + _flagE5 = false; + _attachedSprite->sendMessage(0x2003, 0, this); + } else if (param.asInteger() == 0xDA600012) { + sub44A370(); + } else if (param.asInteger() == 0x0D01B294) { + _flagE5 = false; + _attachedSprite->sendMessage(0x480B, 0, this); + } + break; + } + return messageResult; +} + +uint32 KmScene1002::handleMessage449A30(int messageNum, const MessageParam ¶m, Entity *sender) { + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x01084280) { + if (_attachedSprite) { + _attachedSprite->sendMessage(0x480B, (uint32)_doDeltaX, this); + } + } else if (param.asInteger() == 0x02421405) { + if (_flagE4) { + if (_attachedSprite) { + if (_attachedSprite->sendMessage(0x480C, (uint32)_doDeltaX, this) != 0) { + sub44A460(); + } + } + } else { + SetMessageHandler(&KmScene1002::handleMessage449BA0); + } + } else if (param.asInteger() == 0x4AB28209) { + _attachedSprite->sendMessage(0x482A, 0, this); + } else if (param.asInteger() == 0x88001184) { + _attachedSprite->sendMessage(0x482B, 0, this); + } else if (param.asInteger() == 0x32180101) { + _soundResource1.play(0x405002D8); + } else if (param.asInteger() == 0x0A2A9098) { + _soundResource1.play(0x0460E2FA); + } + break; + case 0x480A: + _flagE4 = true; + return 0; + } + return handleMessage41D480(messageNum, param, sender); +} + +uint32 KmScene1002::handleMessage449BA0(int messageNum, const MessageParam ¶m, Entity *sender) { + //ok + uint32 messageResult = handleMessage41D480(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x4AB28209) { + _attachedSprite->sendMessage(0x482A, 0, this); + } else if (param.asInteger() == 0x88001184) { + _attachedSprite->sendMessage(0x482B, 0, this); + } else if (param.asInteger() == 0x32180101) { + _soundResource1.play(0x405002D8); + } else if (param.asInteger() == 0x0A2A9098) { + _soundResource1.play(0x0460E2FA); + } + break; + } + return messageResult; +} + +uint32 KmScene1002::handleMessage449C90(int messageNum, const MessageParam ¶m, Entity *sender) { + //ok + uint32 messageResult = handleMessage41D480(messageNum, param, sender); + switch (messageNum) { + case 0x1008: + debug("case 0x1008"); +#if 0 // TODO + if (_frameIndex < getHashListIndexByString("SpeedUp")) { + setFileHash(0x35AA8059, getHashListIndexByString("SpeedUp"), -1) + _y = 435; + } +#endif + messageResult = 0; + break; + case 0x100D: + if (param.asInteger() == 0x1A1A0785) { + _soundResource1.play(0x40F0A342); + } else if (param.asInteger() == 0x60428026) { + _soundResource1.play(0x40608A59); + } + break; + } + return messageResult; +} + +uint32 KmScene1002::handleMessage449D60(int messageNum, const MessageParam ¶m, Entity *sender) { + //ok + uint32 messageResult = handleMessage41D360(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x1307050A) { + _soundResource1.play(0x40428A09); + } + break; + } + return messageResult; +} + +void KmScene1002::spriteUpdate449DC0() { + debug("KmScene1002::spriteUpdate449DC0()"); + AnimatedSprite::updateDeltaXY(); + HitRect *hitRect = _vm->_collisionMan->findHitRectAtPos(_x, _y + 10); + debug("$$$ hitRect->type = %04X", hitRect->type); + if (hitRect->type == 0x5001) { + _y = hitRect->rect.y1; + processDelta(); + sendMessage(0x1019, 0, this); + } + _vm->_collisionMan->checkCollision(this, 0xFFFF, 0x4810, 0); +} + +void KmScene1002::sub449E20() { + debug("KmScene1002::sub449E20()"); + if (!sub41CEB0(AnimationCallback(&KmScene1002::sub449E20))) { + _status2 = 2; + _flagE5 = false; + setFileHash(0x584984B4, 0, -1); + SetUpdateHandler(&Klayman::update); + SetSpriteCallback(&AnimatedSprite::updateDeltaXY); + SetMessageHandler(&KmScene1002::handleMessage449800); + SetAnimationCallback3(&Klayman::sub420420); + _attachedSprite->sendMessage(0x482B, 0, this); + } +} + +void KmScene1002::sub449E90() { + debug("KmScene1002::sub449E90()"); + _soundResource1.play(0x56548280); + _status2 = 0; + _flagE5 = false; + _surface->setVisible(false); + setFileHash(0x5420E254, 0, -1); + SetUpdateHandler(&Klayman::update); + SetSpriteCallback(NULL); + SetMessageHandler(&KmScene1002::handleMessage4498E0); +} + +void KmScene1002::sub449EF0() { + //ok + debug("KmScene1002::sub449EF0()"); + _counter1 = 1; + _status2 = 0; + _flagE5 = false; + setFileHash(0x000BAB02, 0, -1); + SetUpdateHandler(&KmScene1002::update4497D0); + + // Weird stuff happening + SetMessageHandler(&Klayman::handleMessage41D360); + //SetMessageHandler(&Klayman::handleMessage41D480); + + SetSpriteCallback(&KmScene1002::spriteUpdate449DC0); + SetAnimationCallback3(&KmScene1002::sub449F70); + _class599->sendMessage(0x482A, 0, this); + _ssLadderArch->sendMessage(0x482A, 0, this); +} + +void KmScene1002::sub449F70() { + //ok + debug("KmScene1002::sub449F70()"); + _parentScene->sendMessage(0x1024, 1, this); + _soundResource1.play(0x41648271); + _status2 = 1; + _flagE5 = false; + _flagE1 = false; + setFileHash2(0x000BAB02, 0x88003000, 0); + SetUpdateHandler(&Klayman::update); + SetSpriteCallback(NULL); + SetMessageHandler(&KmScene1002::handleMessage41D480); + SetAnimationCallback3(&KmScene1002::sub44A230); + _parentScene->sendMessage(0x2002, 0, this); + // TODO _callbackList = NULL; + _attachedSprite = NULL; + _class599->sendMessage(0x482B, 0, this); + _ssLadderArch->sendMessage(0x482B, 0, this); +} + +void KmScene1002::sub44A050() { + //ok + debug("KmScene1002::sub44A050()"); + _counter1 = 1; + _status2 = 0; + _flagE5 = false; + setFileHash(0x9308C132, 0, -1); + SetUpdateHandler(&KmScene1002::update4497D0); + SetSpriteCallback(&KmScene1002::spriteUpdate449DC0); + SetMessageHandler(&Klayman::handleMessage41D480); + SetAnimationCallback3(&KmScene1002::sub449F70); + _class599->sendMessage(0x482A, 0, this); + _ssLadderArch->sendMessage(0x482A, 0, this); +} + +void KmScene1002::sub44A0D0() { + //ok + debug("KmScene1002::sub44A0D0()"); + _counter1 = 1; + _status2 = 0; + _flagE5 = false; + setFileHash(0x0013A206, 0, -1); + SetUpdateHandler(&KmScene1002::update4497D0); + SetMessageHandler(&Klayman::handleMessage41D360); + SetSpriteCallback(&KmScene1002::spriteUpdate449DC0); + SetAnimationCallback3(&KmScene1002::sub44A150); + _class599->sendMessage(0x482A, 0, this); + _ssLadderArch->sendMessage(0x482A, 0, this); +} + +void KmScene1002::sub44A150() { + //ok + debug("KmScene1002::sub44A150()"); + _parentScene->sendMessage(0x1024, 1, this); + _soundResource1.play(0x41648271); + _status2 = 1; + _flagE5 = false; + _flagE1 = false; + setFileHash2(0x0013A206, 0x88003000, 0); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&KmScene1002::handleMessage41D480); + SetSpriteCallback(NULL); + SetAnimationCallback3(&KmScene1002::sub44A230); + _parentScene->sendMessage(0x2002, 0, this); + // TODO _callbackList = NULL; + _attachedSprite = NULL; + _class599->sendMessage(0x482B, 0, this); + _ssLadderArch->sendMessage(0x482B, 0, this); +} + +void KmScene1002::sub44A230() { + //ok + debug("KmScene1002::sub44A230()"); + setDoDeltaX(2); + sub41FC80(); +} + +void KmScene1002::sub44A250() { + //ok + debug("KmScene1002::sub44A250()"); + if (!sub41CEB0(AnimationCallback(&KmScene1002::sub44A250))) { + _parentScene->sendMessage(0x1024, 3, this); + _status2 = 2; + _flagE5 = false; + setFileHash(0xB93AB151, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&KmScene1002::handleMessage449D60); + SetSpriteCallback(&KmScene1002::spriteUpdate449DC0); + SetAnimationCallback3(&Klayman::sub420420); + } +} + +void KmScene1002::sub44A2C0() { + //ok + debug("KmScene1002::sub44A2C0()"); + if (_attachedSprite) { + _x = ((Sprite*)_attachedSprite)->getX(); + _attachedSprite->sendMessage(0x4807, 0, this); + _attachedSprite = NULL; + } + _status2 = 2; + _flagE5 = false; + setFileHash(0x586984B1, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&KmScene1002::handleMessage41D360); + SetSpriteCallback(&KmScene1002::spriteUpdate449DC0); + SetAnimationCallback3(&Klayman::sub420420); +} + +void KmScene1002::sub44A330() { + //ok + debug("KmScene1002::sub44A330()"); + _status2 = 2; + _flagE5 = true; + setDoDeltaX(0); + setFileHash(0x1CD89029, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&KmScene1002::handleMessage449990); + SetSpriteCallback(&Klayman::spriteUpdate41F250); +} + +void KmScene1002::sub44A370() { + //ok + debug("KmScene1002::sub44A370()"); + _status2 = 1; + _flagE5 = false; + setFileHash(0x35AA8059, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&KmScene1002::handleMessage449C90); + SetSpriteCallback(&AnimatedSprite::updateDeltaXY); + setCallback1(AnimationCallback(&KmScene1002::sub44A3C0)); +} + +void KmScene1002::sub44A3C0() { + debug("KmScene1002::sub44A3C0()"); + _parentScene->sendMessage(0x1024, 1, this); +} + +void KmScene1002::sub44A3E0() { + //ok + debug("KmScene1002::sub44A3E0()"); + if (!sub41CEB0(AnimationCallback(&KmScene1002::sub44A3E0))) { + _status2 = 2; + _flagE4 = false; + _flagE5 = true; + setDoDeltaX(((Sprite*)_attachedSprite)->getX() < _x ? 1 : 0); + setFileHash(0x5C01A870, 0, -1); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&KmScene1002::handleMessage449A30); + SetSpriteCallback(&AnimatedSprite::updateDeltaXY); + setCallback1(AnimationCallback(&KmScene1002::sub44A4B0)); + } +} + +void KmScene1002::sub44A460() { + //ok + debug("KmScene1002::sub44A460()"); + _flagE4 = false; + _flagE5 = true; + setFileHash2(0x5C01A870, 0x01084280, 0); + SetUpdateHandler(&Klayman::update); + SetMessageHandler(&KmScene1002::handleMessage449A30); + SetSpriteCallback(&AnimatedSprite::updateDeltaXY); + setCallback1(AnimationCallback(&KmScene1002::sub44A4B0)); +} + +void KmScene1002::sub44A4B0() { + _attachedSprite->sendMessage(0x482A, 0, this); +} } // End of namespace Neverhood diff --git a/engines/neverhood/klayman.h b/engines/neverhood/klayman.h index 24f70e1fdf..20d0e885cd 100644 --- a/engines/neverhood/klayman.h +++ b/engines/neverhood/klayman.h @@ -63,10 +63,32 @@ public: void sub4208F0(); void sub420930(); void sub420830(); + void sub41FC40(); + void sub420210(); + void sub4201C0(); + void sub420340(); + void sub420250(); + void sub420290(); + void sub420380(); + void sub4203C0(); + void sub420300(); + void sub420970(); + void sub4209D0(); + void sub420BC0(); + void sub420AD0(); + void sub421030(); + void sub420FE0(); + void sub4210C0(); + void sub421070(); + void sub420420(); void spriteUpdate41F250(); void spriteUpdate41F5F0(); void spriteUpdate41F780(); + void spriteUpdate41F230(); + + uint32 handleMessage41D360(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage41D480(int messageNum, const MessageParam ¶m, Entity *sender); protected: Entity *_parentScene; @@ -133,10 +155,8 @@ protected: void sub41C790(); void update41D0F0(); - uint32 handleMessage41D360(int messageNum, const MessageParam ¶m, Entity *sender); void sub41FF00(); - uint32 handleMessage41D480(int messageNum, const MessageParam ¶m, Entity *sender); void sub41FCF0(); @@ -171,11 +191,19 @@ protected: void sub41CD00(int16 x); void sub41CC40(int16 x1, int16 x2); void sub41CAC0(int16 x); + void sub41CCE0(int16 x); void sub41FC30(); uint32 handleMessage41DF10(int messageNum, const MessageParam ¶m, Entity *sender); - uint32 handleMessage41EEF0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage41E3C0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage41D790(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage41D880(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage41DAA0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage41DFD0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage41E0D0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage41E490(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage41E290(int messageNum, const MessageParam ¶m, Entity *sender); }; @@ -188,6 +216,43 @@ protected: uint32 handleMessage44FA00(int messageNum, const MessageParam ¶m, Entity *sender); }; +class KmScene1002 : public Klayman { +public: + KmScene1002(NeverhoodEngine *vm, Entity *parentScene, Sprite *class599, Sprite *ssLadderArch, int16 x, int16 y); +protected: + Sprite *_class599; + Sprite *_ssLadderArch; + Sprite *_otherSprite; + int _status; + void xUpdate(); + uint32 xHandleMessage(int messageNum, const MessageParam ¶m); + void update4497D0(); + uint32 handleMessage449800(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage4498E0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage449990(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage449A30(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage449BA0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage449C90(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage449D60(int messageNum, const MessageParam ¶m, Entity *sender); + void spriteUpdate449DC0(); + void sub449E20(); + void sub449E90(); + void sub449EF0(); + void sub449F70(); + void sub44A050(); + void sub44A0D0(); + void sub44A150(); + void sub44A230(); + void sub44A250(); + void sub44A2C0(); + void sub44A330(); + void sub44A370(); + void sub44A3C0(); + void sub44A3E0(); + void sub44A460(); + void sub44A4B0(); +}; + } // End of namespace Neverhood #endif /* NEVERHOOD_KLAYMAN_H */ diff --git a/engines/neverhood/module1000.cpp b/engines/neverhood/module1000.cpp index 703796e51f..529cbeab07 100644 --- a/engines/neverhood/module1000.cpp +++ b/engines/neverhood/module1000.cpp @@ -381,10 +381,10 @@ uint32 AsScene1001Lever::handleMessage(int messageNum, const MessageParam ¶m setFileHash(0x04A98C36, 0, -1); break; case 0x482A: - _parentScene->sendMessage(0x1022, 0x3DE, this); + _parentScene->sendMessage(0x1022, 990, this); break; case 0x482B: - _parentScene->sendMessage(0x1022, 0x3F2, this); + _parentScene->sendMessage(0x1022, 1010, this); break; } return messageResult; @@ -428,7 +428,7 @@ Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which) SetMessageHandler(&Scene1001::handleMessage); - _vm->_collisionMan->setHitRects(0x004B4858); + _vm->_collisionMan->setHitRects(0x004B4860); _surfaceFlag = false; _background = addBackground(new DirtyBackground(_vm, 0x4086520E, 0, 0)); _palette = new Palette(_vm, 0x4086520E); @@ -822,15 +822,520 @@ void AsScene1002Door::spriteUpdate447D40() { } } +Class505::Class505(NeverhoodEngine *vm) + : AnimatedSprite(vm, 1400) { + + createSurface(1025, 88, 165); + _surface->setVisible(false); + SetUpdateHandler(&AnimatedSprite::update); + SetMessageHandler(&Class505::handleMessage); +} + +uint32 Class505::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x2004: + _x = ((Sprite*)sender)->getX() - 98; + _y = ((Sprite*)sender)->getY() - 111; + setFileHash(0x0422255A, 0, -1); + _surface->setVisible(true); + break; + case 0x3002: + setFileHash1(); + _surface->setVisible(false); + break; + } + return messageResult; +} + +AsScene1002DoorSpy::AsScene1002DoorSpy(NeverhoodEngine *vm, NRect &clipRect, Scene *parentScene, Sprite *asDoor, Sprite *class505) + : AnimatedSprite(vm, 1300), _rect(clipRect), _parentScene(parentScene), _asDoor(asDoor), _class505(class505), + _soundResource(vm) { + + SetUpdateHandler(&AnimatedSprite::update); + SetMessageHandler(&AsScene1002DoorSpy::handleMessage4489D0); + SetSpriteCallback(&AsScene1002DoorSpy::spriteUpdate448AA0); + + createSurface(800, 136, 147); + _surface->getClipRect() = clipRect; + + spriteUpdate448AA0(); + + // TODO _soundResource.load(0xC0C40298); + + setFileHash(0x586C1D48, 0, 0); + +} + +uint32 AsScene1002DoorSpy::handleMessage4489D0(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0xA61CA1C2) { + _class505->sendMessage(0x2004, 0, this); + } else if (param.asInteger() == 0x14CE0620) { + // TODO _soundResource.play(); + } + break; + case 0x2003: + sub448B10(); + break; + } + return messageResult; +} + +uint32 AsScene1002DoorSpy::handleMessage448A60(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = handleMessage4489D0(messageNum, param, sender); + switch (messageNum) { + case 0x3002: + removeCallbacks(); + break; + } + return messageResult; +} + +void AsScene1002DoorSpy::spriteUpdate448AA0() { + _x = _asDoor->getX() + 34; + _y = _asDoor->getY() + 175; +} + +void AsScene1002DoorSpy::sub448AC0() { + _surface->getClipRect() = _rect; + _parentScene->setSurfacePriority(getSurface(), 800); + setFileHash(0x586C1D48, 0, 0); + SetMessageHandler(&AsScene1002DoorSpy::handleMessage4489D0); +} + +void AsScene1002DoorSpy::sub448B10() { + _surface->getClipRect().x1 = 0; + _surface->getClipRect().y1 = 0; + _surface->getClipRect().x2 = 640; + _surface->getClipRect().y2 = 480; + _parentScene->setSurfacePriority(getSurface(), 1200); + setFileHash(0x586C1D48, 1, -1); + SetMessageHandler(&AsScene1002DoorSpy::handleMessage448A60); + SetAnimationCallback3(&AsScene1002DoorSpy::sub448AC0); +} + +Class426::Class426(NeverhoodEngine *vm, Scene *parentScene, uint32 fileHash1, uint32 fileHash2, int surfacePriority, uint32 soundFileHash) + : StaticSprite(vm, 1100), _parentScene(parentScene), _soundResource(vm), _status(0) { + + _soundFileHash = soundFileHash != 0 ? soundFileHash : 0x44141000; + + _fileHashes[0] = fileHash1; + _fileHashes[1] = fileHash2; + + _spriteResource.load2(fileHash1); + createSurface(surfacePriority, 40, 40); + + _surface->getDrawRect().x = 0; + _surface->getDrawRect().y = 0; + _surface->getDrawRect().width = _spriteResource.getDimensions().width; + _surface->getDrawRect().height = _spriteResource.getDimensions().height; + _x = _spriteResource.getPosition().x; + _y = _spriteResource.getPosition().y; + + _surface->setVisible(false); + _needRefresh = true; + + SetUpdateHandler(&Class426::update); + SetMessageHandler(&Class426::handleMessage); + +} + +void Class426::update() { + if (_countdown != 0 && (--_countdown) == 0) { + if (_status == 1) { + _status = 2; + _spriteResource.load2(_fileHashes[1]); + _surface->getDrawRect().x = 0; + _surface->getDrawRect().y = 0; + _surface->getDrawRect().width = _spriteResource.getDimensions().width; + _surface->getDrawRect().height = _spriteResource.getDimensions().height; + _x = _spriteResource.getPosition().x; + _y = _spriteResource.getPosition().y; + _needRefresh = true; + StaticSprite::update(); + _countdown = 4; + } else if (_status == 2) { + _status = 3; + _spriteResource.load2(_fileHashes[0]); + _surface->getDrawRect().x = 0; + _surface->getDrawRect().y = 0; + _surface->getDrawRect().width = _spriteResource.getDimensions().width; + _surface->getDrawRect().height = _spriteResource.getDimensions().height; + _x = _spriteResource.getPosition().x; + _y = _spriteResource.getPosition().y; + _needRefresh = true; + StaticSprite::update(); + _countdown = 4; + } else if (_status == 3) { + _status = 0; + _surface->setVisible(false); + } + } +} + +uint32 Class426::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x480B: + _parentScene->sendMessage(0x480B, 0, this); + _status = 1; + _countdown = 4; + _surface->setVisible(true); + _soundResource.play(_soundFileHash); + break; + } + return messageResult; +} + +AsScene1002VenusFlyTrap::AsScene1002VenusFlyTrap(NeverhoodEngine *vm, Scene *parentScene, Sprite *klayman, bool flag) + : AnimatedSprite(vm, 1100), _soundResource(vm), _parentScene(parentScene), _klayman(klayman), + _flag(flag), _countdown(0) { + + createSurface(995, 175, 195); + + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage448000); + SetSpriteCallback(&AnimatedSprite::updateDeltaXY); + + if (!flag) { + if (getGlobalVar(0x8306F218)) { + setDoDeltaX(1); + _x = 366; + _y = 435; + sub4485F0(); + } else { + _x = 174 + getGlobalVar(0x1B144052) * 32; + _y = 435; + sub448660(); + } + } else { + _x = 186 + getGlobalVar(0x86341E88) * 32; + _y = 364; + if (getGlobalVar(0x13206309) || getGlobalVar(0x80101B1E)) { + sub4485F0(); + } else { + sub448660(); + } + } + + _flags = 4; +} + +void AsScene1002VenusFlyTrap::update() { + if (_countdown != 0 && (--_countdown == 0)) { + removeCallbacks(); + } + AnimatedSprite::update(); +} + +void AsScene1002VenusFlyTrap::update447FB0() { + if (_countdown == 0 && _klayman->getX() - 20 > _x) { + setDoDeltaX(1); + } else if (_klayman->getX() + 20 < _x) { + setDoDeltaX(0); + } + update(); +} + +uint32 AsScene1002VenusFlyTrap::handleMessage448000(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x000890C4) { + _soundResource.play(0xC21190D8); + } else if (param.asInteger() == 0x522200A0) { + _soundResource.play(0x931080C8); + } + break; + case 0x1011: + if (_flag) { + if (_x >= 154 && _x <= 346) { + _parentScene->sendMessage(0x2000, 0, this); + messageResult = 1; + } + } else { + if (_x >= 174 && _x <= 430) { + _parentScene->sendMessage(0x2000, 0, this); + messageResult = 1; + } + } + break; + case 0x480B: + setDoDeltaX(param.asInteger() != 0 ? 1 : 0); + if (_flag) { + if (getGlobalVar(0x8306F218)) { + sub448560(); + } else { + sub448530(); + } + } else { + if (getGlobalVar(0x13206309) || getGlobalVar(0x80101B1E)) { + sub448560(); + } else { + sub448530(); + } + } + break; + case 0x480C: + if (_flag) { + if (_x >= 154 && _x <= 346) + messageResult = 1; + else + messageResult = 0; + } else { + if (_x >= 174 && _x <= 430) + messageResult = 1; + else + messageResult = 0; + } + break; + case 0x480E: + if (param.asInteger() == 1) { + sub4485B0(); + } + break; + case 0x4810: + debug("trap collision"); + sub448780(); + break; + case 0x482A: + _parentScene->sendMessage(0x1022, 995, this); + break; + case 0x482B: + _parentScene->sendMessage(0x1022, 1015, this); + break; + } + return messageResult; +} + +uint32 AsScene1002VenusFlyTrap::handleMessage4482E0(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = handleMessage448000(messageNum, param, sender); + switch (messageNum) { + case 0x3002: + removeCallbacks(); + break; + } + return messageResult; +} + +uint32 AsScene1002VenusFlyTrap::handleMessage448320(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param.asInteger() == 0x000890C4) { + _soundResource.play(0xC21190D8); + } else if (param.asInteger() == 0x41881801) { + if (_flag) { + if (_x > 330) { + _klayman->sendMessage(0x4811, 2, this); + } else if (_x > 265) { + _klayman->sendMessage(0x4811, 0, this); + } else { + _klayman->sendMessage(0x4811, 0, this); + } + } else { + _klayman->sendMessage(0x4811, 0, this); + } + } else if (param.asInteger() == 0x522200A0) { + _soundResource.play(0x931080C8); + } + break; + case 0x3002: + removeCallbacks(); + break; + case 0x482A: + _parentScene->sendMessage(0x1022, 995, this); + break; + case 0x482B: + _parentScene->sendMessage(0x1022, 1015, this); + break; + } + return messageResult; +} + +void AsScene1002VenusFlyTrap::sub4484F0() { + //ok + setDoDeltaX(2); + setFileHash(0xC4080034, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage448320); + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub448660); +} + +void AsScene1002VenusFlyTrap::sub448530() { + //ok + setFileHash(0xC4080034, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage4482E0); + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub448660); +} + +void AsScene1002VenusFlyTrap::sub448560() { + //ok + _parentScene->sendMessage(0x4807, 0, this); + setFileHash(0x82292851, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage4482E0); + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub448660); +} + +void AsScene1002VenusFlyTrap::sub4485B0() { + //ok + setDoDeltaX(1); + setFileHash(0x86A82A11, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage4482E0); + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub4485F0); +} + +void AsScene1002VenusFlyTrap::sub4485F0() { + //ok + setFileHash(0xB5A86034, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage448000); +} + +void AsScene1002VenusFlyTrap::sub448620() { + //ok + setFileHash(0x31303094, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(NULL); + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub448720); + _countdown = 24; +} + +void AsScene1002VenusFlyTrap::sub448660() { + setFileHash(0xC8204250, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update447FB0); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage448000); + if (_flag) { + if (_x >= 154 && _x <= 346) { + setGlobalVar(0x86341E88, (_x - 186) / 32); + } else { + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub4484F0); + _countdown = 12; + } + } else { + if (_x >= 174 && _x <= 430) { + setGlobalVar(0x1B144052, (_x - 174) / 32); + } else { + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub4484F0); + _countdown = 12; + } + } +} + +void AsScene1002VenusFlyTrap::sub448720() { + //ok + setFileHash(0x152920C4, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage448320); + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub448750); +} + +void AsScene1002VenusFlyTrap::sub448750() { + //ok + setFileHash(0x84001117, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage448320); + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub448660); +} + +void AsScene1002VenusFlyTrap::sub448780() { +debug("AsScene1002VenusFlyTrap::sub448780()"); + if (_x - 15 < _klayman->getX() && _x + 15 > _klayman->getX()) { + if (_flag) { + setDoDeltaX(_x > 265 && _x < 330 ? 1 : 0); + } else { + setDoDeltaX(_x > 320 ? 1 : 0); + } + _klayman->sendMessage(0x2001, 0, this); + setFileHash(0x8C2C80D4, 0, -1); + SetUpdateHandler(&AsScene1002VenusFlyTrap::update); + SetMessageHandler(&AsScene1002VenusFlyTrap::handleMessage448320); + SetAnimationCallback3(&AsScene1002VenusFlyTrap::sub448620); + } +} + +Class506::Class506(NeverhoodEngine *vm) + : AnimatedSprite(vm, 1200), _countdown(0) { + + createSurface(850, 186, 212); + _x = 320; + _y = 240; + if (getGlobalVar(0x8306F218)) { + setFileHash(0x004A4495, -1, -1); + _newHashListIndex = -2; + } else { + _surface->setVisible(false); + } + SetUpdateHandler(&Class506::update); + SetMessageHandler(&Class506::handleMessage4491B0); +} + +void Class506::update() { + if (_countdown != 0 && (--_countdown == 0)) { + if (_flag) { + sub449280(); + } else { + sub449250(); + } + } + AnimatedSprite::update(); +} + +uint32 Class506::handleMessage4491B0(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageResult) { + case 0x4808: + _flag = false; + _countdown = 2; + break; + case 0x4809: + _flag = true; + _countdown = 2; + break; + } + return messageResult; +} + +uint32 Class506::handleMessage449210(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = handleMessage4491B0(messageNum, param, sender); + switch (messageResult) { + case 0x3002: + removeCallbacks(); + break; + } + return messageResult; +} + +void Class506::sub449250() { + setFileHash(0x004A4495, 0, -1); + SetMessageHandler(&Class506::handleMessage4491B0); + _newHashListIndex = -2; + _surface->setVisible(true); +} + +void Class506::sub449280() { + setFileHash(0x004A4495, -1, -1); + _playBackwards = true; + SetMessageHandler(&Class506::handleMessage449210); + SetAnimationCallback3(&Class506::sub4492C0); + _surface->setVisible(true); +} + +void Class506::sub4492C0() { + _surface->setVisible(false); + setFileHash1(); +} + Scene1002::Scene1002(NeverhoodEngine *vm, Module *parentModule, int which) : Scene(vm, parentModule, true), _soundResource1(vm), _soundResource2(vm), _soundResource3(vm), _flag1B4(false), _flag1BE(false) { - static const uint32 kClass426FileHashList[] = { - 0x00412692, - 0x140B60BE - }; - NRect tempClipRect; Sprite *tempSprite; @@ -848,7 +1353,7 @@ Scene1002::Scene1002(NeverhoodEngine *vm, Module *parentModule, int which) SetUpdateHandler(&Scene1002::update); SetMessageHandler(&Scene1002::handleMessage); - _vm->_collisionMan->setHitRects(0x004B4134); + _vm->_collisionMan->setHitRects(0x004B4138); _surfaceFlag = true; @@ -868,46 +1373,46 @@ Scene1002::Scene1002(NeverhoodEngine *vm, Module *parentModule, int which) _class599 = addSprite(new Class599(_vm, this)); -#if 0 if (which < 0) { if (_vm->_gameState.field2 == 0) { - _klayman = addSprite(new KmScene1002(_vm, this, _class599, _ssLadderArch, 90, 226)); - _class478 = addSprite(new Class478(_vm, _klayman)); + _klayman = new KmScene1002(_vm, this, _class599, _ssLadderArch, 90, 226); + //_class478 = addSprite(new Class478(_vm, _klayman)); setMessageList(0x004B4270); // TODO // TODO _klayman->setRepl(64, 0); } else { - _klayman = addSprite(new KmScene1002(_vm, this, _class599, _ssLadderArch, 379, 435)); - _class478 = addSprite(new Class478(_vm, _klayman)); + _klayman = new KmScene1002(_vm, this, _class599, _ssLadderArch, 379, 435); + //_class478 = addSprite(new Class478(_vm, _klayman)); setMessageList(0x004B4270); // TODO } } else { if (which == 1) { - _klayman = addSprite(new KmScene1002(_vm, this, _class599, _ssLadderArch, 650, 435)); - _class478 = addSprite(new Class478(_vm, _klayman)); + _klayman = new KmScene1002(_vm, this, _class599, _ssLadderArch, 650, 435); + //_class478 = addSprite(new Class478(_vm, _klayman)); setMessageList(0x004B4478); // TODO _vm->_gameState.field2 = 1; } else if (which == 2) { - _klayman = addSprite(new KmScene1002(_vm, this, _class599, _ssLadderArch, 68, 645)); - _class478 = addSprite(new Class478(_vm, _klayman)); + _klayman = new KmScene1002(_vm, this, _class599, _ssLadderArch, 68, 645); + //_class478 = addSprite(new Class478(_vm, _klayman)); setMessageList(0x004B4298); // TODO _vm->_gameState.field2 = 1; _klayman->sendMessage(0x4820, 0, this); } else { - _klayman = addSprite(new KmScene1002(_vm, this, _class599, _ssLadderArch, 90, 226)); - _class478 = addSprite(new Class478(_vm, _klayman)); + _klayman = new KmScene1002(_vm, this, _class599, _ssLadderArch, 90, 226); + //_class478 = addSprite(new Class478(_vm, _klayman)); setMessageList(0x004B4470); // TODO - _class479 = addSprite(new Class479(_vm, this, _klayman)); + //_class479 = addSprite(new Class479(_vm, this, _klayman)); // TODO // TODO _klayman->setRepl(64, 0); _vm->_gameState.field2 = 0; } } -#endif + + addSprite(_klayman); _mouseCursor = addSprite(new Mouse433(_vm, 0x23303124, NULL)); @@ -925,22 +1430,21 @@ Scene1002::Scene1002(NeverhoodEngine *vm, Module *parentModule, int which) _asDoor = addSprite(new AsScene1002Door(_vm, tempClipRect)); -#if 0 + tempSprite = addSprite(new Class505(_vm)); - tempSprite = addSprite(new Class505(_vm, tempClipRect)); - - _class504 = addSprite(new Class504(_vm, tempClipRect, this, _asDoor, tempSprite)); - _class426 = addSprite(new Class426(_vm, this, kClass426FileHashList, 800, 0)); - _class503 = addSprite(new Class503(_vm, this, _klayman, false)); + _asDoorSpy = addSprite(new AsScene1002DoorSpy(_vm, tempClipRect, this, _asDoor, tempSprite)); + + _class426 = addSprite(new Class426(_vm, this, 0x00412692, 0x140B60BE, 800, 0)); + _asVenusFlyTrap = addSprite(new AsScene1002VenusFlyTrap(_vm, this, _klayman, false)); - _vm->_collisionMan->addSprite(_class503); - _klayman->sendEntityMessage(0x2007, _class503, this); + _vm->_collisionMan->addSprite(_asVenusFlyTrap); + + _klayman->sendEntityMessage(0x2007, _asVenusFlyTrap, this); _class506 = addSprite(new Class506(_vm)); setRectList(0x004B43A0); -#endif #if 0 // TODO _soundResource2.load(0x60755842); @@ -954,11 +1458,10 @@ Scene1002::~Scene1002() { void Scene1002::update() { Scene::update(); -#if 0 // TODO: Waiting for Klayman... if (!_flag1B4 && _klayman->getY() > 230) { // TODO deleteSprite(&_ssLadderArchPart3); - _klayman->clearRepl(); + // TODO _klayman->clearRepl(); _flag1B4 = true; _vm->_gameState.field2 = 1; } @@ -968,11 +1471,10 @@ void Scene1002::update() { _flag1BE = false; } -#endif - } uint32 Scene1002::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { + debug("Scene1002::handleMessage(%04X)", messageNum); uint32 messageResult = 0; Scene::handleMessage(messageNum, param, sender); switch (messageNum) { @@ -1011,7 +1513,7 @@ uint32 Scene1002::handleMessage(int messageNum, const MessageParam ¶m, Entit setMessageList(0x004B44B8); } else { _klayman->sendEntityMessage(0x1014, _asRing3, this); - if (_class503->getX() - 10 < 366 && _class503->getX() + 10 > 366) { + if (_asVenusFlyTrap->getX() - 10 < 366 && _asVenusFlyTrap->getX() + 10 > 366) { setGlobalVar(0x2B514304, 1); setMessageList(0x004B44A8); } else { @@ -1043,7 +1545,7 @@ uint32 Scene1002::handleMessage(int messageNum, const MessageParam ¶m, Entit setMessageList2(0x004B43D0); } else { if (_klayman->getY() > 420) { - _klayman->sendEntityMessage(0x1014, _class503, this); + _klayman->sendEntityMessage(0x1014, _asVenusFlyTrap, this); setMessageList2(0x004B4480); } else if (_klayman->getY() > 227) { setMessageList2(0x004B41E0); @@ -1090,14 +1592,14 @@ uint32 Scene1002::handleMessage(int messageNum, const MessageParam ¶m, Entit _soundResource3.play(); _asDoor->sendMessage(0x4809, 0, this); _class506->sendMessage(0x4809, 0, this); - } else if (sender == _class503) { + } else if (sender == _asVenusFlyTrap) { if (getGlobalVar(0x8306F218)) { _asRing3->sendMessage(0x4807, 0, this); } } break; case 0x480B: - _klayman->sendEntityMessage(0x1014, _class504, this); + _klayman->sendEntityMessage(0x1014, _asDoorSpy, this); break; case 0x480F: setGlobalVar(0x4DE80AC0, 0); diff --git a/engines/neverhood/module1000.h b/engines/neverhood/module1000.h index c78658f31e..79a4985ffc 100644 --- a/engines/neverhood/module1000.h +++ b/engines/neverhood/module1000.h @@ -176,6 +176,84 @@ protected: void spriteUpdate447D40(); }; +class Class505 : public AnimatedSprite { +public: + Class505(NeverhoodEngine *vm); +protected: + uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); +}; + +class AsScene1002DoorSpy : public AnimatedSprite { +public: + AsScene1002DoorSpy(NeverhoodEngine *vm, NRect &clipRect, Scene *parentScene, Sprite *asDoor, Sprite *class505); +protected: + Scene *_parentScene; + Sprite *_asDoor; + Sprite *_class505; + SoundResource _soundResource; + NRect _rect; + uint32 handleMessage4489D0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage448A60(int messageNum, const MessageParam ¶m, Entity *sender); + void spriteUpdate448AA0(); + void sub448AC0(); + void sub448B10(); +}; + +class Class426 : public StaticSprite { +public: + Class426(NeverhoodEngine *vm, Scene *parentScene, uint32 fileHash1, uint32 fileHash2, int surfacePriority, uint32 soundFileHash); + // TODO Class426_sub433660 (not used yet) +protected: + Scene *_parentScene; + int _countdown; + uint32 _fileHashes[2]; + int _status; + SoundResource _soundResource; + uint32 _soundFileHash; + void update(); + uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); +}; + +class AsScene1002VenusFlyTrap : public AnimatedSprite { +public: + AsScene1002VenusFlyTrap(NeverhoodEngine *vm, Scene *parentScene, Sprite *klayman, bool flag); +protected: + Scene *_parentScene; + Sprite *_klayman; + int _countdown; + SoundResource _soundResource; + bool _flag; + void update(); + void update447FB0(); + uint32 handleMessage448000(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage4482E0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage448320(int messageNum, const MessageParam ¶m, Entity *sender); + void sub4484F0(); + void sub448530(); + void sub448560(); + void sub4485B0(); + void sub4485F0(); + void sub448620(); + void sub448660(); + void sub448720(); + void sub448750(); + void sub448780(); +}; + +class Class506 : public AnimatedSprite { +public: + Class506(NeverhoodEngine *vm); +protected: + int _countdown; + bool _flag; + void update(); + uint32 handleMessage4491B0(int messageNum, const MessageParam ¶m, Entity *sender); + uint32 handleMessage449210(int messageNum, const MessageParam ¶m, Entity *sender); + void sub449250(); + void sub449280(); + void sub4492C0(); +}; + class Scene1002 : public Scene { public: Scene1002(NeverhoodEngine *vm, Module *parentModule, int which); @@ -195,8 +273,8 @@ protected: Sprite *_asRing4; Sprite *_asRing5; Sprite *_asDoor; - Sprite *_class504; - Sprite *_class503; + Sprite *_asDoorSpy; + Sprite *_asVenusFlyTrap; Sprite *_ssLadderArch; Sprite *_ssLadderArchPart1; Sprite *_ssLadderArchPart2; diff --git a/engines/neverhood/mouse.cpp b/engines/neverhood/mouse.cpp index c753183269..381f4a7186 100644 --- a/engines/neverhood/mouse.cpp +++ b/engines/neverhood/mouse.cpp @@ -29,7 +29,7 @@ namespace Neverhood { Mouse433::Mouse433(NeverhoodEngine *vm, uint32 fileHash, NRect *mouseRect) : StaticSprite(vm, 2000), _mouseCursorResource(vm), _frameNum(0) { - debug("Mouse433::Mouse433(%08X)", fileHash); + debug(7, "Mouse433::Mouse433(%08X)", fileHash); if (mouseRect) { _mouseRect = *mouseRect; @@ -70,7 +70,7 @@ void Mouse433::load(uint32 fileHash) { } void Mouse433::update() { - debug("Mouse433::update()"); + debug(7, "Mouse433::update()"); updateCursor(); _frameNum++; if (_frameNum >= 6) @@ -79,7 +79,7 @@ void Mouse433::update() { } uint32 Mouse433::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { - debug("Mouse433::handleMessage(%04X)", messageNum); + debug(7, "Mouse433::handleMessage(%04X)", messageNum); uint32 messageResult = 0; if (messageNum != 5) { messageResult = Sprite::handleMessage(messageNum, param, sender); @@ -103,7 +103,7 @@ uint32 Mouse433::handleMessage(int messageNum, const MessageParam ¶m, Entity } void Mouse433::updateCursor() { - debug("Mouse433::updateCursor()"); + debug(7, "Mouse433::updateCursor()"); if (!_surface) return; @@ -131,7 +131,7 @@ void Mouse433::updateCursor() { Mouse435::Mouse435(NeverhoodEngine *vm, uint32 fileHash, int16 x1, int16 x2) : StaticSprite(vm, 2000), _mouseCursorResource(vm), _frameNum(0), _x1(x1), _x2(x2) { - debug("Mouse435::Mouse435(%08X)", fileHash); + debug(7, "Mouse435::Mouse435(%08X)", fileHash); _mouseCursorResource.load(fileHash); _x = _vm->getMouseX(); @@ -165,7 +165,7 @@ void Mouse435::load(uint32 fileHash) { } void Mouse435::update() { - debug("Mouse435::update()"); + debug(7, "Mouse435::update()"); updateCursor(); _frameNum++; if (_frameNum >= 6) @@ -174,7 +174,7 @@ void Mouse435::update() { } uint32 Mouse435::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { - debug("Mouse435::handleMessage(%04X)", messageNum); + debug(7, "Mouse435::handleMessage(%04X)", messageNum); uint32 messageResult = 0; if (messageNum != 5) { messageResult = Sprite::handleMessage(messageNum, param, sender); @@ -199,7 +199,7 @@ uint32 Mouse435::handleMessage(int messageNum, const MessageParam ¶m, Entity } void Mouse435::updateCursor() { - debug("Mouse435::updateCursor()"); + debug(7, "Mouse435::updateCursor()"); if (!_surface) return; diff --git a/engines/neverhood/resource.cpp b/engines/neverhood/resource.cpp index 841827a4bd..dde80ebe79 100644 --- a/engines/neverhood/resource.cpp +++ b/engines/neverhood/resource.cpp @@ -291,10 +291,14 @@ void AnimResource::unloadInternal() { } int16 AnimResource::getFrameIndex(uint32 frameHash) { + int16 frameIndex = -1; for (uint i = 0; i < _frames.size(); i++) - if (_frames[i].frameHash == frameHash) - return (int16)i; - return -1; + if (_frames[i].frameHash == frameHash) { + frameIndex = (int16)i; + break; + } + debug("AnimResource::getFrameIndex(%08X) -> %d", frameHash, frameIndex); + return frameIndex; } MouseCursorResource::MouseCursorResource(NeverhoodEngine *vm) diff --git a/engines/neverhood/scene.cpp b/engines/neverhood/scene.cpp index 3851cfa3ad..7252e391a0 100644 --- a/engines/neverhood/scene.cpp +++ b/engines/neverhood/scene.cpp @@ -416,7 +416,7 @@ bool Scene::setMessageList2(MessageList *messageList, bool messageListFlag, bool } void Scene::runMessageList() { - debug("Scene::runMessageList() _messageListFlag2 = %d; _messageListFlag1 = %d", _messageListFlag2, _messageListFlag1); + debug(7, "Scene::runMessageList() _messageListFlag2 = %d; _messageListFlag1 = %d", _messageListFlag2, _messageListFlag1); if (_messageListFlag2 || _messageListFlag1) return; @@ -434,7 +434,7 @@ void Scene::runMessageList() { int messageNum = (*_messageList)[_messageListIndex].messageNum; uint32 messageParam = (*_messageList)[_messageListIndex].messageValue; - //debug("Scene::runMessageList() %04X, %08X", messageNum, messageParam); + debug("Scene::runMessageList() %04X, %08X", messageNum, messageParam); _messageListIndex++; if (_messageListIndex == _messageListCount) { diff --git a/engines/neverhood/sprite.cpp b/engines/neverhood/sprite.cpp index 222368c94a..155d3254ec 100644 --- a/engines/neverhood/sprite.cpp +++ b/engines/neverhood/sprite.cpp @@ -72,6 +72,10 @@ bool Sprite::isPointInside(int16 x, int16 y) { return x >= _rect.x1 && x <= _rect.x2 && y >= _rect.y1 && y <= _rect.y2; } +bool Sprite::checkCollision(NRect &rect) { + return (_rect.x1 < rect.x2) && (rect.x1 < _rect.x2) && (_rect.y1 < rect.y2) && (rect.y1 < _rect.y2); +} + uint32 Sprite::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { switch (messageNum) { case 0x0005: @@ -373,6 +377,7 @@ void AnimatedSprite::updatePosition() { void AnimatedSprite::updateFrameIndex() { if (!_playBackwards) { + debug("%08X ### _frameIndex = %d; _frameIndex2 = %d", _fileHash3, _frameIndex, _frameIndex2); if (_frameIndex < _frameIndex2) { _frameIndex++; } else { @@ -441,6 +446,7 @@ void AnimatedSprite::setFileHash1() { } void AnimatedSprite::setFileHash2(uint32 fileHash, uint32 fileHash6, uint32 fileHash5) { + debug("AnimatedSprite::setFileHash2(%08X, %08X, %08X)", fileHash, fileHash6, fileHash5); _fileHash1 = fileHash; _fileHash6 = fileHash6; _fileHash5 = fileHash5; @@ -498,6 +504,7 @@ void AnimatedSprite::removeCallbacks() { if (_callback3Cb) { _callback2Cb = _callback3Cb; _callback3Cb = NULL; + debug("Fire _callback3Cb '%s'", _callback3CbName.c_str()); (this->*_callback2Cb)(); #if 0 // TODO } else if (_callbackList) { diff --git a/engines/neverhood/sprite.h b/engines/neverhood/sprite.h index 0368d2d3a6..996c063b42 100644 --- a/engines/neverhood/sprite.h +++ b/engines/neverhood/sprite.h @@ -30,9 +30,9 @@ namespace Neverhood { -#define SetSpriteCallback(callback) _spriteUpdateCb = static_cast <void (Sprite::*)(void)> (callback) -#define SetFilterX(callback) _filterXCb = static_cast <int16 (Sprite::*)(int16)> (callback) -#define SetFilterY(callback) _filterYCb = static_cast <int16 (Sprite::*)(int16)> (callback) +#define SetSpriteCallback(callback) _spriteUpdateCb = static_cast <void (Sprite::*)(void)> (callback); debug("SetSpriteCallback(" #callback ")"); _spriteUpdateCbName = #callback +#define SetFilterX(callback) _filterXCb = static_cast <int16 (Sprite::*)(int16)> (callback); debug("SetFilterX(" #callback ")") +#define SetFilterY(callback) _filterYCb = static_cast <int16 (Sprite::*)(int16)> (callback); debug("SetFilterY(" #callback ")") const int16 kDefPosition = -32768; @@ -45,12 +45,16 @@ public: void setDoDeltaX(int type); void setDoDeltaY(int type); bool isPointInside(int16 x, int16 y); + bool checkCollision(NRect &rect); int16 getX() const { return _x; } int16 getY() const { return _y; } + uint16 getFlags() const { return _flags; } bool isDoDeltaX() const { return _doDeltaX; } bool isDoDeltaY() const { return _doDeltaY; } + NRect& getRect() { return _rect; } protected: void (Sprite::*_spriteUpdateCb)(); + Common::String _spriteUpdateCbName; // For debugging purposes int16 (Sprite::*_filterXCb)(int16); int16 (Sprite::*_filterYCb)(int16); BaseSurface *_surface; @@ -92,9 +96,9 @@ protected: void update(); }; -#define SetAnimationCallback1(callback) _callback1Cb = static_cast <void (AnimatedSprite::*)(void)> (callback) -#define SetAnimationCallback2(callback) _callback2Cb = static_cast <void (AnimatedSprite::*)(void)> (callback) -#define SetAnimationCallback3(callback) _callback3Cb = static_cast <void (AnimatedSprite::*)(void)> (callback) +#define SetAnimationCallback1(callback) _callback1Cb = static_cast <void (AnimatedSprite::*)(void)> (callback); debug("SetAnimationCallback1(" #callback ")"); _callback1CbName = #callback +#define SetAnimationCallback2(callback) _callback2Cb = static_cast <void (AnimatedSprite::*)(void)> (callback); debug("SetAnimationCallback2(" #callback ")"); _callback2CbName = #callback +#define SetAnimationCallback3(callback) _callback3Cb = static_cast <void (AnimatedSprite::*)(void)> (callback); debug("SetAnimationCallback3(" #callback ")"); _callback3CbName = #callback #define AnimationCallback(callback) static_cast <void (AnimatedSprite::*)()> (callback) class AnimatedSprite : public Sprite { @@ -133,6 +137,10 @@ protected: AnimationCb _callback1Cb; AnimationCb _callback2Cb; AnimationCb _callback3Cb; + // For debugging purposes + Common::String _callback1CbName; + Common::String _callback2CbName; + Common::String _callback3CbName; void init(); void updateAnim(); void updatePosition(); diff --git a/engines/neverhood/staticdata.cpp b/engines/neverhood/staticdata.cpp index 4cd1d30251..b9ac232707 100644 --- a/engines/neverhood/staticdata.cpp +++ b/engines/neverhood/staticdata.cpp @@ -107,14 +107,20 @@ void StaticData::load(const char *filename) { } HitRectList *StaticData::getHitRectList(uint32 id) { + if (!_hitRectLists[id]) + error("StaticData::getHitRectList() HitRectList with id %08X not found", id); return _hitRectLists[id]; } RectList *StaticData::getRectList(uint32 id) { + if (!_rectLists[id]) + error("StaticData::getRectList() RectList with id %08X not found", id); return _rectLists[id]; } MessageList *StaticData::getMessageList(uint32 id) { + if (!_messageLists[id]) + error("StaticData::getMessageList() MessageList with id %08X not found", id); return _messageLists[id]; } |