diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/core/view_item.cpp | 61 | ||||
-rw-r--r-- | engines/titanic/core/view_item.h | 14 | ||||
-rw-r--r-- | engines/titanic/game/gondolier/gondolier_mixer.cpp | 6 | ||||
-rw-r--r-- | engines/titanic/game_state.cpp | 13 | ||||
-rw-r--r-- | engines/titanic/game_state.h | 9 | ||||
-rw-r--r-- | engines/titanic/main_game_window.cpp | 9 | ||||
-rw-r--r-- | engines/titanic/messages/messages.h | 30 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_control.cpp | 18 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_control.h | 12 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_control_sub_base.h | 8 |
10 files changed, 144 insertions, 36 deletions
diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp index 60463545d3..c632458939 100644 --- a/engines/titanic/core/view_item.cpp +++ b/engines/titanic/core/view_item.cpp @@ -20,9 +20,12 @@ * */ +#include "titanic/game_manager.h" +#include "titanic/core/project_item.h" +#include "titanic/core/room_item.h" #include "titanic/core/view_item.h" #include "titanic/messages/messages.h" -#include "titanic/game_manager.h" +#include "titanic/pet_control/pet_control.h" namespace Titanic { @@ -75,7 +78,7 @@ bool CViewItem::getResourceKey(CResourceKey *key) { return !filename.empty(); } -void CViewItem::viewChange(CViewItem *newView) { +void CViewItem::leaveView(CViewItem *newView) { // Only do the processing if we've been passed a view, and it's not the same if (newView && newView != this) { CLeaveViewMsg viewMsg(this, newView); @@ -101,4 +104,58 @@ void CViewItem::viewChange(CViewItem *newView) { } } +void CViewItem::preEnterView(CViewItem *newView) { + // Only do the processing if we've been passed a view, and it's not the same + if (newView && newView != this) { + CPreEnterViewMsg viewMsg(this, newView); + viewMsg.execute(this, nullptr, MSGFLAG_SCAN); + + CNodeItem *oldNode = findNode(); + CNodeItem *newNode = newView->findNode(); + if (newNode != oldNode) { + CPreEnterNodeMsg nodeMsg(oldNode, newNode); + nodeMsg.execute(oldNode, nullptr, MSGFLAG_SCAN); + + CRoomItem *oldRoom = oldNode->findRoom(); + CRoomItem *newRoom = newNode->findRoom(); + if (newRoom != oldRoom) { + CPreEnterRoomMsg roomMsg(oldRoom, newRoom); + roomMsg.execute(oldRoom, nullptr, MSGFLAG_SCAN); + } + } + } +} + +void CViewItem::enterView(CViewItem *newView) { + // Only do the processing if we've been passed a view, and it's not the same + if (newView && newView != this) { + CEnterViewMsg viewMsg(this, newView); + viewMsg.execute(this, nullptr, MSGFLAG_SCAN); + + CNodeItem *oldNode = findNode(); + CNodeItem *newNode = newView->findNode(); + if (newNode != oldNode) { + CEnterNodeMsg nodeMsg(oldNode, newNode); + nodeMsg.execute(oldNode, nullptr, MSGFLAG_SCAN); + + CRoomItem *oldRoom = oldNode->findRoom(); + CRoomItem *newRoom = newNode->findRoom(); + + CPetControl *petControl = nullptr; + if (newRoom != nullptr) { + petControl = newRoom->getRoot()->getPetControl(); + petControl->enterNode(newNode); + } + + if (newRoom != oldRoom) { + CEnterRoomMsg roomMsg(oldRoom, newRoom); + roomMsg.execute(oldRoom, nullptr, MSGFLAG_SCAN); + + if (petControl) + petControl->enterRoom(newRoom); + } + } + } +} + } // End of namespace Titanic diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h index 632c8e7358..ad09ed69e6 100644 --- a/engines/titanic/core/view_item.h +++ b/engines/titanic/core/view_item.h @@ -59,9 +59,19 @@ public: bool getResourceKey(CResourceKey *key); /** - * Called when changing from one view to another + * Called when leaving the view */ - void viewChange(CViewItem *newView); + void leaveView(CViewItem *newView); + + /** + * Called on an old view just left, and about to enter a new view + */ + void preEnterView(CViewItem *newView); + + /** + * Called when a new view is being entered + */ + void enterView(CViewItem *newView); }; } // End of namespace Titanic diff --git a/engines/titanic/game/gondolier/gondolier_mixer.cpp b/engines/titanic/game/gondolier/gondolier_mixer.cpp index f4fb655cf2..b647a31ac2 100644 --- a/engines/titanic/game/gondolier/gondolier_mixer.cpp +++ b/engines/titanic/game/gondolier/gondolier_mixer.cpp @@ -57,9 +57,9 @@ void CGondolierMixer::load(SimpleFile *file) { } bool CGondolierMixer::handleEvent(CEnterRoomMsg &msg) { - CTreeItem *parent = getParent(); - if (parent == msg._room) - msg.execute(parent); + CTreeItem *parentRoom = getParent(); + if (parentRoom == msg._newRoom) + msg.execute(parentRoom); return true; } diff --git a/engines/titanic/game_state.cpp b/engines/titanic/game_state.cpp index 30185fc5f6..d0baf21599 100644 --- a/engines/titanic/game_state.cpp +++ b/engines/titanic/game_state.cpp @@ -21,6 +21,7 @@ */ #include "titanic/game_state.h" +#include "titanic/titanic.h" #include "titanic/game_manager.h" #include "titanic/screen_manager.h" @@ -29,8 +30,8 @@ namespace Titanic { CGameState::CGameState(CGameManager *gameManager) : _gameManager(gameManager), _gameLocation(this), _field8(0), _fieldC(0), _mode(GSMODE_0), _field14(0), _field18(0), - _field1C(0), _field20(0), _field24(0), _field28(0), _field2C(0), - _field38(0) { + _field1C(0), _field20(0), _field24(0), _nodeChangeCtr(0), + _nodeEnterTicks(0), _field38(0) { } void CGameState::save(SimpleFile *file) const { @@ -54,7 +55,8 @@ void CGameState::load(SimpleFile *file) { _gameLocation.load(file); _field1C = file->readNumber(); - _field28 = _field2C = 0; + _nodeChangeCtr = 0; + _nodeEnterTicks = 0; } void CGameState::setMode(GameStateMode newMode) { @@ -82,4 +84,9 @@ void CGameState::setMousePos(const Common::Point &pt) { _mousePos = pt; } +void CGameState::enterNode() { + ++_nodeChangeCtr; + _nodeEnterTicks = g_vm->_events->getTicksCount(); +} + } // End of namespace Titanic z diff --git a/engines/titanic/game_state.h b/engines/titanic/game_state.h index 1c0b750a44..10b87b5f9a 100644 --- a/engines/titanic/game_state.h +++ b/engines/titanic/game_state.h @@ -54,8 +54,8 @@ public: int _field1C; int _field20; int _field24; - int _field28; - int _field2C; + uint _nodeChangeCtr; + uint32 _nodeEnterTicks; Common::Point _mousePos; int _field38; public: @@ -80,6 +80,11 @@ public: * Sets the current mouse position */ void setMousePos(const Common::Point &pt); + + /** + * Called by the PET when a new node is entered + */ + void enterNode(); }; } // End of namespace Titanic diff --git a/engines/titanic/main_game_window.cpp b/engines/titanic/main_game_window.cpp index a6a5dcabf5..0c80149173 100644 --- a/engines/titanic/main_game_window.cpp +++ b/engines/titanic/main_game_window.cpp @@ -70,17 +70,18 @@ void CMainGameWindow::applicationStarting() { // TODO: Cursor/image - // Generate starting messages + // Generate starting messages for entering the view, node, and room. + // Note the old fields are nullptr, since there's no previous view/node/room CViewItem *view = _gameManager->_gameState._gameLocation.getView(); - CEnterViewMsg enterViewMsg(view); + CEnterViewMsg enterViewMsg(nullptr, view); enterViewMsg.execute(view, nullptr, MSGFLAG_SCAN); CNodeItem *node = view->findNode(); - CEnterNodeMsg enterNodeMsg(node); + CEnterNodeMsg enterNodeMsg(nullptr, node); enterNodeMsg.execute(node, nullptr, MSGFLAG_SCAN); CRoomItem *room = view->findRoom(); - CEnterRoomMsg enterRoomMsg(room); + CEnterRoomMsg enterRoomMsg(nullptr, room); enterRoomMsg.execute(room, nullptr, MSGFLAG_SCAN); _gameManager->initBounds(); diff --git a/engines/titanic/messages/messages.h b/engines/titanic/messages/messages.h index 4e00648f1b..0776ab9493 100644 --- a/engines/titanic/messages/messages.h +++ b/engines/titanic/messages/messages.h @@ -196,9 +196,9 @@ public: } } #define MESSAGE2(NAME, F1, N1, V1, F2, N2, V2) MSGTARGET(NAME); \ class NAME: public CMessage { \ - public: F1 _N1; F2 _N2; \ - NAME() : CMessage(), _N1(V1), _N2(V2) {} \ - NAME(F1 N1, F2 N2) : CMessage(), _N1(N1), _N2(N2) {} \ + public: F1 _##N1; F2 _##N2; \ + NAME() : CMessage(), _##N1(V1), _##N2(V2) {} \ + NAME(F1 N1, F2 N2) : CMessage(), _##N1(N1), _##N2(N2) {} \ CLASSDEF \ virtual bool handleMessage(const NAME &msg) { return false; } \ virtual bool perform(CTreeItem *treeItem) { \ @@ -207,9 +207,9 @@ public: } } #define MESSAGE3(NAME, F1, N1, V1, F2, N2, V2, F3, N3, V3) MSGTARGET(NAME); \ class NAME: public CMessage { \ - public: F1 _N1; F2 _N2; F3 _N3; \ - NAME() : CMessage(), _N1(V1), _N2(V2), _N3(V3) {} \ - NAME(F1 N1, F2 N2, F3 N3) : CMessage(), _N1(N1), _N2(N2), _N3(N3) {} \ + public: F1 _##N1; F2 _##N2; F3 _##N3; \ + NAME() : CMessage(), _##N1(V1), _##N2(V2), _##N3(V3) {} \ + NAME(F1 N1, F2 N2, F3 N3) : CMessage(), _##N1(N1), _##N2(N2), _##N3(N3) {} \ CLASSDEF \ virtual bool handleMessage(const NAME &msg) { return false; } \ virtual bool perform(CTreeItem *treeItem) { \ @@ -218,9 +218,9 @@ public: } } #define MESSAGE4(NAME, F1, N1, V1, F2, N2, V2, F3, N3, V3, F4, N4, V4) MSGTARGET(NAME); \ class NAME: public CMessage { \ - public: F1 _N1; F2 _N2; F3 _N3; F4 _N4; \ - NAME() : CMessage(), _N1(V1), _N2(V2), _N3(V3), _N4(V4) {} \ - NAME(F1 N1, F2 N2, F3 N3, F4 N4) : CMessage(), _N1(N1), _N2(N2), _N3(N3), _N4(N4) {} \ + public: F1 _##N1; F2 _##N2; F3 _##N3; F4 _##N4; \ + NAME() : CMessage(), _##N1(V1), _##N2(V2), _##N3(V3), _##N4(V4) {} \ + NAME(F1 N1, F2 N2, F3 N3, F4 N4) : CMessage(), _##N1(N1), _##N2(N2), _##N3(N3), _##N4(N4) {} \ CLASSDEF \ virtual bool handleMessage(const NAME &msg) { return false; } \ virtual bool perform(CTreeItem *treeItem) { \ @@ -259,12 +259,12 @@ MESSAGE1(CDropobjectMsg, int, value, 0); MESSAGE1(CDropZoneGotObjectMsg, int, value, 0); MESSAGE1(CDropZoneLostObjectMsg, int, value, 0); MESSAGE1(CEjectCylinderMsg, int, value, 0); -MESSAGE1(CPreEnterNodeMsg, CNodeItem *, node, nullptr); -MESSAGE1(CPreEnterRoomMsg, CRoomItem *, room, nullptr); -MESSAGE1(CPreEnterViewMsg, CViewItem *, view, nullptr); -MESSAGE1(CEnterNodeMsg, CNodeItem *, node, nullptr); -MESSAGE1(CEnterRoomMsg, CRoomItem *, room, nullptr); -MESSAGE1(CEnterViewMsg, CViewItem *, view, nullptr); +MESSAGE2(CPreEnterNodeMsg, CNodeItem *, oldNode, nullptr, CNodeItem *, newNode, nullptr); +MESSAGE2(CPreEnterRoomMsg, CRoomItem *, oldRoom, nullptr, CRoomItem *, newRoom, nullptr); +MESSAGE2(CPreEnterViewMsg, CViewItem *, oldView, nullptr, CViewItem *, newView, nullptr); +MESSAGE2(CEnterNodeMsg, CNodeItem *, oldNode, nullptr, CNodeItem *, newNode, nullptr); +MESSAGE2(CEnterRoomMsg, CRoomItem *, oldRoom, nullptr, CRoomItem *, newRoom, nullptr); +MESSAGE2(CEnterViewMsg, CViewItem *, oldView, nullptr, CViewItem *, newView, nullptr); MESSAGE0(CErasePhonographCylinderMsg); MESSAGE2(CFreshenCookieMsg, int, value1, 0, int, value2, 0); MESSAGE1(CGetChevClassBits, int, value, 0); diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index 7ed223d595..a61773d319 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -21,6 +21,8 @@ */ #include "titanic/pet_control/pet_control.h" +#include "titanic/game_manager.h" +#include "titanic/game_state.h" namespace Titanic { @@ -49,10 +51,6 @@ void CPetControl::load(SimpleFile *file) { CGameObject::load(file); } -void CPetControl::postLoad() { - // TODO -} - bool CPetControl::isValid() const { return _sub1.isValid() && _sub2.isValid() && _sub3.isValid() && _sub4.isValid() @@ -82,5 +80,17 @@ void CPetControl::saveSubObjects(SimpleFile *file, int indent) const { _sub8.save(file, indent); } +void CPetControl::postLoad() { + warning("TODO: CPetControl::postLoad"); +} + +void CPetControl::enterNode(CNodeItem *node) { + getGameManager()->_gameState.enterNode(); +} + +void CPetControl::enterRoom(CRoomItem *room) { + _sub2.enterRoom(room); + _sub3.enterRoom(room); +} } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index 70f6850bc7..f1e4bb2a10 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -24,6 +24,8 @@ #define TITANIC_PET_CONTROL_H #include "titanic/core/game_object.h" +#include "titanic/core/node_item.h" +#include "titanic/core/room_item.h" #include "titanic/pet_control/pet_control_sub1.h" #include "titanic/pet_control/pet_control_sub2.h" #include "titanic/pet_control/pet_control_sub3.h" @@ -80,6 +82,16 @@ public: * Called after loading a game has finished */ void postLoad(); + + /** + * Called when a new node is entered + */ + void enterNode(CNodeItem *node); + + /** + * Called when a new room is entered + */ + void enterRoom(CRoomItem *room); }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control_sub_base.h b/engines/titanic/pet_control/pet_control_sub_base.h index b59c85b30a..f95e1a98f5 100644 --- a/engines/titanic/pet_control/pet_control_sub_base.h +++ b/engines/titanic/pet_control/pet_control_sub_base.h @@ -24,6 +24,7 @@ #define TITANIC_PET_CONTROL_SUB_BASE_H #include "titanic/simple_file.h" +#include "titanic/core/room_item.h" namespace Titanic { @@ -81,7 +82,12 @@ public: virtual void proc21() {} virtual void proc22() {} virtual void proc23() {} - virtual void proc24() {} + + /** + * Called when a new room is entered + */ + virtual void enterRoom(CRoomItem *room) {} + virtual void proc25(); virtual int proc26() { return 0; } virtual void proc27(); |