From dc91d30b76ded7ed7a648a0b0b43d8fe99c00cf6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 18 Aug 2016 22:45:58 -0400 Subject: TITANIC: Implementing game classes --- engines/titanic/carry/chicken.h | 2 +- engines/titanic/carry/crushed_tv.cpp | 1 - engines/titanic/core/click_responder.cpp | 21 ++- engines/titanic/core/click_responder.h | 4 +- engines/titanic/game/chicken_cooler.cpp | 33 ++++- engines/titanic/game/chicken_cooler.h | 2 + engines/titanic/game/chicken_dispensor.cpp | 141 +++++++++++++++++++++ engines/titanic/game/chicken_dispensor.h | 8 ++ engines/titanic/game/close_broken_pel.cpp | 14 +- engines/titanic/game/close_broken_pel.h | 4 +- engines/titanic/game/cookie.cpp | 17 +++ engines/titanic/game/cookie.h | 3 + engines/titanic/game/credits.cpp | 35 +++++ engines/titanic/game/credits.h | 3 + engines/titanic/game/credits_button.cpp | 20 +++ engines/titanic/game/credits_button.h | 3 + engines/titanic/game/null_port_hole.cpp | 12 +- engines/titanic/game/sgt/sgt_upper_doors_sound.cpp | 6 +- engines/titanic/gfx/chev_switch.cpp | 40 +++++- engines/titanic/gfx/chev_switch.h | 6 + engines/titanic/gfx/toggle_switch.h | 2 +- 21 files changed, 355 insertions(+), 22 deletions(-) diff --git a/engines/titanic/carry/chicken.h b/engines/titanic/carry/chicken.h index 65fe30fd81..e64ae458a4 100644 --- a/engines/titanic/carry/chicken.h +++ b/engines/titanic/carry/chicken.h @@ -41,7 +41,7 @@ class CChicken : public CCarry { bool MouseDragEndMsg(CMouseDragEndMsg *msg); bool PETObjectStateMsg(CPETObjectStateMsg *msg); bool PETLostObjectMsg(CPETLostObjectMsg *msg); -private: +public: static int _v1; public: int _field12C; diff --git a/engines/titanic/carry/crushed_tv.cpp b/engines/titanic/carry/crushed_tv.cpp index a265b611a9..486537d28e 100644 --- a/engines/titanic/carry/crushed_tv.cpp +++ b/engines/titanic/carry/crushed_tv.cpp @@ -76,5 +76,4 @@ bool CCrushedTV::MouseDragStartMsg(CMouseDragStartMsg *msg) { return CCarry::MouseDragStartMsg(msg); } - } // End of namespace Titanic diff --git a/engines/titanic/core/click_responder.cpp b/engines/titanic/core/click_responder.cpp index f9694557df..9a0e0de7ab 100644 --- a/engines/titanic/core/click_responder.cpp +++ b/engines/titanic/core/click_responder.cpp @@ -24,20 +24,33 @@ namespace Titanic { +BEGIN_MESSAGE_MAP(CClickResponder, CGameObject) + ON_MESSAGE(MouseButtonDownMsg) +END_MESSAGE_MAP() + void CClickResponder::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); - file->writeQuotedLine(_string1, indent); - file->writeQuotedLine(_string2, indent); + file->writeQuotedLine(_message, indent); + file->writeQuotedLine(_soundName, indent); CGameObject::save(file, indent); } void CClickResponder::load(SimpleFile *file) { file->readNumber(); - _string1 = file->readString(); - _string2 = file->readString(); + _message = file->readString(); + _soundName = file->readString(); CGameObject::load(file); } +bool CClickResponder::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { + if (!_soundName.empty()) + playSound(_soundName); + if (!_message.empty()) + petDisplayMessage(_message); + + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/core/click_responder.h b/engines/titanic/core/click_responder.h index 78381b9948..40f22d7906 100644 --- a/engines/titanic/core/click_responder.h +++ b/engines/titanic/core/click_responder.h @@ -28,8 +28,10 @@ namespace Titanic { class CClickResponder : public CGameObject { + DECLARE_MESSAGE_MAP; + bool MouseButtonDownMsg(CMouseButtonDownMsg *msg); protected: - CString _string1, _string2; + CString _message, _soundName; public: CLASSDEF; diff --git a/engines/titanic/game/chicken_cooler.cpp b/engines/titanic/game/chicken_cooler.cpp index 29232e10bf..d10405de38 100644 --- a/engines/titanic/game/chicken_cooler.cpp +++ b/engines/titanic/game/chicken_cooler.cpp @@ -21,9 +21,15 @@ */ #include "titanic/game/chicken_cooler.h" +#include "titanic/carry/chicken.h" namespace Titanic { +BEGIN_MESSAGE_MAP(CChickenCooler, CGameObject) + ON_MESSAGE(EnterRoomMsg) + ON_MESSAGE(EnterViewMsg) +END_MESSAGE_MAP() + void CChickenCooler::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); file->writeNumberLine(_fieldBC, indent); @@ -41,7 +47,32 @@ void CChickenCooler::load(SimpleFile *file) { } bool CChickenCooler::EnterRoomMsg(CEnterRoomMsg *msg) { - warning("CChickenCoolor::handlEvent"); + if (_fieldC0) { + CGameObject *obj = getMailManFirstObject(); + if (obj) { + // WORKAROUND: Redundant loop for chicken in originalhere + } else { + getNextMail(nullptr); + if (CChicken::_v1 > _fieldBC) + CChicken::_v1 = _fieldBC; + } + } + + return true; +} + +bool CChickenCooler::EnterViewMsg(CEnterViewMsg *msg) { + if (!_fieldC0) { + for (CGameObject *obj = getMailManFirstObject(); obj; + obj = getNextMail(obj)) { + if (obj->isEquals("Chicken")) + return true; + } + + if (CChicken::_v1 > _fieldBC) + CChicken::_v1 = _fieldBC; + } + return true; } diff --git a/engines/titanic/game/chicken_cooler.h b/engines/titanic/game/chicken_cooler.h index 724727b905..54dba90686 100644 --- a/engines/titanic/game/chicken_cooler.h +++ b/engines/titanic/game/chicken_cooler.h @@ -29,7 +29,9 @@ namespace Titanic { class CChickenCooler : public CGameObject { + DECLARE_MESSAGE_MAP; bool EnterRoomMsg(CEnterRoomMsg *msg); + bool EnterViewMsg(CEnterViewMsg *msg); private: int _fieldBC; int _fieldC0; diff --git a/engines/titanic/game/chicken_dispensor.cpp b/engines/titanic/game/chicken_dispensor.cpp index a9bf576765..7fb8fefcda 100644 --- a/engines/titanic/game/chicken_dispensor.cpp +++ b/engines/titanic/game/chicken_dispensor.cpp @@ -21,9 +21,21 @@ */ #include "titanic/game/chicken_dispensor.h" +#include "titanic/core/project_item.h" +#include "titanic/pet_control/pet_control.h" namespace Titanic { +BEGIN_MESSAGE_MAP(CChickenDispensor, CBackground) + ON_MESSAGE(StatusChangeMsg) + ON_MESSAGE(MovieEndMsg) + ON_MESSAGE(ActMsg) + ON_MESSAGE(LeaveViewMsg) + ON_MESSAGE(EnterViewMsg) + ON_MESSAGE(MouseDragStartMsg) + ON_MESSAGE(TurnOff) +END_MESSAGE_MAP() + CChickenDispensor::CChickenDispensor() : CBackground(), _fieldE0(0), _fieldE4(0), _fieldE8(0) { } @@ -45,4 +57,133 @@ void CChickenDispensor::load(SimpleFile *file) { CBackground::load(file); } +bool CChickenDispensor::StatusChangeMsg(CStatusChangeMsg *msg) { + msg->execute("SGTRestLeverAnimation"); + int v1 = _fieldE8 ? 0 : _fieldE4; + CPetControl *pet = getPetControl(); + CGameObject *obj; + + for (obj = pet->getFirstObject(); obj; obj = pet->getNextObject(obj)) { + if (obj->isEquals("Chicken")) { + petDisplayMessage(1, "Chickens are allocated on a one-per-customer basis."); + return true; + } + } + + for (obj = getMailManFirstObject(); obj; obj = getNextMail(obj)) { + if (obj->isEquals("Chicken")) { + petDisplayMessage(1, "Chickens are allocated on a one-per-customer basis."); + return true; + } + } + + if (v1 == 1 || v1 == 2) + _fieldE8 = 1; + + switch (v1) { + case 0: + petDisplayMessage(1, "Only one piece of chicken per passenger. Thank you."); + break; + case 1: + setVisible(true); + if (_fieldE0) { + playMovie(0, 12, MOVIE_NOTIFY_OBJECT | MOVIE_GAMESTATE); + playSound("z#400.wav"); + _fieldE4 = 0; + } else { + playMovie(12, 16, MOVIE_NOTIFY_OBJECT | MOVIE_GAMESTATE); + _fieldE8 = 1; + _fieldE4 = 0; + } + break; + + case 2: + setVisible(true); + if (_fieldE0) { + playMovie(0, 12, MOVIE_NOTIFY_OBJECT | MOVIE_GAMESTATE); + playSound("z#400.wav"); + } else { + playMovie(12, 16, MOVIE_NOTIFY_OBJECT | MOVIE_GAMESTATE); + _fieldE8 = 1; + } + break; + + default: + break; + } + + return true; +} + +bool CChickenDispensor::MovieEndMsg(CMovieEndMsg *msg) { + if (getMovieFrame() == 16) { + playSound("b#50.wav", 50); + CActMsg actMsg("Dispense Chicken"); + actMsg.execute("Chicken"); + } else if (_fieldE8) { + _cursorId = CURSOR_ARROW; + loadFrame(0); + setVisible(false); + if (_fieldE4 == 2) + _fieldE8 = 0; + } else { + loadFrame(0); + setVisible(false); + changeView("SgtLobby.Node 1.N"); + } + + return true; +} + +bool CChickenDispensor::ActMsg(CActMsg *msg) { + if (msg->_action == "EnableObject") + _fieldE0 = 0; + else if (msg->_action == "DisableObject") + _fieldE0 = 1; + else if (msg->_action == "IncreaseQuantity") + _fieldE4 = 2; + else if (msg->_action == "DecreaseQuantity") + _fieldE4 = 1; + + return true; +} + +bool CChickenDispensor::LeaveViewMsg(CLeaveViewMsg *msg) { + return true; +} + +bool CChickenDispensor::EnterViewMsg(CEnterViewMsg *msg) { + playSound("b#51.wav"); + _fieldE8 = 0; + _cursorId = CURSOR_ARROW; + return true; +} + +bool CChickenDispensor::MouseDragStartMsg(CMouseDragStartMsg *msg) { + if (getMovieFrame() == 16) { + setVisible(false); + loadFrame(0); + _cursorId = CURSOR_ARROW; + _fieldE8 = 1; + + CVisibleMsg visibleMsg; + visibleMsg.execute("Chicken"); + CPassOnDragStartMsg passMsg(msg->_mousePos, 1); + passMsg.execute("Chicken"); + + msg->_dragItem = getRoot()->findByName("Chicken"); + } + + return true; +} + +bool CChickenDispensor::TurnOff(CTurnOff *msg) { + if (getMovieFrame() == 16) + setVisible(false); + playMovie(16, 12, MOVIE_NOTIFY_OBJECT | MOVIE_GAMESTATE); + _fieldE8 = 0; + + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/chicken_dispensor.h b/engines/titanic/game/chicken_dispensor.h index d86b850871..5e3ba47ee8 100644 --- a/engines/titanic/game/chicken_dispensor.h +++ b/engines/titanic/game/chicken_dispensor.h @@ -28,6 +28,14 @@ namespace Titanic { class CChickenDispensor : public CBackground { + DECLARE_MESSAGE_MAP; + bool StatusChangeMsg(CStatusChangeMsg *msg); + bool MovieEndMsg(CMovieEndMsg *msg); + bool ActMsg(CActMsg *msg); + bool LeaveViewMsg(CLeaveViewMsg *msg); + bool EnterViewMsg(CEnterViewMsg *msg); + bool MouseDragStartMsg(CMouseDragStartMsg *msg); + bool TurnOff(CTurnOff *msg); public: int _fieldE0; int _fieldE4; diff --git a/engines/titanic/game/close_broken_pel.cpp b/engines/titanic/game/close_broken_pel.cpp index d27441ac96..c234590849 100644 --- a/engines/titanic/game/close_broken_pel.cpp +++ b/engines/titanic/game/close_broken_pel.cpp @@ -24,16 +24,26 @@ namespace Titanic { +BEGIN_MESSAGE_MAP(CCloseBrokenPel, CBackground) + ON_MESSAGE(MouseButtonDownMsg) +END_MESSAGE_MAP() + void CCloseBrokenPel::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); - file->writeQuotedLine(_string3, indent); + file->writeQuotedLine(_target, indent); CBackground::save(file, indent); } void CCloseBrokenPel::load(SimpleFile *file) { file->readNumber(); - _string3 = file->readString(); + _target = file->readString(); CBackground::load(file); } +bool CCloseBrokenPel::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { + CActMsg actMsg("Close"); + actMsg.execute(_target); + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/close_broken_pel.h b/engines/titanic/game/close_broken_pel.h index aacda6c002..4bd66255df 100644 --- a/engines/titanic/game/close_broken_pel.h +++ b/engines/titanic/game/close_broken_pel.h @@ -28,8 +28,10 @@ namespace Titanic { class CCloseBrokenPel : public CBackground { + DECLARE_MESSAGE_MAP; + bool MouseButtonDownMsg(CMouseButtonDownMsg *msg); public: - CString _string3; + CString _target; public: CLASSDEF; diff --git a/engines/titanic/game/cookie.cpp b/engines/titanic/game/cookie.cpp index 915bb93b4a..96edca4058 100644 --- a/engines/titanic/game/cookie.cpp +++ b/engines/titanic/game/cookie.cpp @@ -24,6 +24,11 @@ namespace Titanic { +BEGIN_MESSAGE_MAP(CCookie, CGameObject) + ON_MESSAGE(LeaveNodeMsg) + ON_MESSAGE(FreshenCookieMsg) +END_MESSAGE_MAP() + void CCookie::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); file->writeNumberLine(_value1, indent); @@ -40,4 +45,16 @@ void CCookie::load(SimpleFile *file) { CGameObject::load(file); } +bool CCookie::LeaveNodeMsg(CLeaveNodeMsg *msg) { + if (_value2) + _value1 = 1; + return true; +} + +bool CCookie::FreshenCookieMsg(CFreshenCookieMsg *msg) { + _value1 = msg->_value2; + _value2 = msg->_value1; + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/cookie.h b/engines/titanic/game/cookie.h index 7ae04f1144..2018deeb3e 100644 --- a/engines/titanic/game/cookie.h +++ b/engines/titanic/game/cookie.h @@ -28,6 +28,9 @@ namespace Titanic { class CCookie : public CGameObject { + DECLARE_MESSAGE_MAP; + bool LeaveNodeMsg(CLeaveNodeMsg *msg); + bool FreshenCookieMsg(CFreshenCookieMsg *msg); public: int _value1; int _value2; diff --git a/engines/titanic/game/credits.cpp b/engines/titanic/game/credits.cpp index 7078d41a17..d9149f6dd2 100644 --- a/engines/titanic/game/credits.cpp +++ b/engines/titanic/game/credits.cpp @@ -24,6 +24,11 @@ namespace Titanic { +BEGIN_MESSAGE_MAP(CCredits, CGameObject) + ON_MESSAGE(SignalObject) + ON_MESSAGE(TimerMsg) +END_MESSAGE_MAP() + CCredits::CCredits() : CGameObject(), _fieldBC(-1), _fieldC0(1) { } @@ -43,4 +48,34 @@ void CCredits::load(SimpleFile *file) { CGameObject::load(file); } +bool CCredits::SignalObject(CSignalObject *msg) { + petHide(); + disableMouse(); + addTimer(50); + return true; +} + +bool CCredits::TimerMsg(CTimerMsg *msg) { + stopGlobalSound(true, -1); + setVisible(true); + loadSound("a#16.wav"); + loadSound("a#24.wav"); + + playCutscene(0, 18); + playGlobalSound("a#16.wav", -1, false, false, 0); + playCutscene(19, 642); + playSound("a#24.wav"); + playCutscene(643, 750); + + COpeningCreditsMsg creditsMsg; + creditsMsg.execute("Service Elevator Entity"); + changeView("EmbLobby.Node 6.S"); + + setVisible(false); + petShow(); + enableMouse(); + stopGlobalSound(true, -1); + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/credits.h b/engines/titanic/game/credits.h index fa9794b6de..23fd25584d 100644 --- a/engines/titanic/game/credits.h +++ b/engines/titanic/game/credits.h @@ -28,6 +28,9 @@ namespace Titanic { class CCredits : public CGameObject { + DECLARE_MESSAGE_MAP; + bool SignalObject(CSignalObject *msg); + bool TimerMsg(CTimerMsg *msg); public: int _fieldBC, _fieldC0; public: diff --git a/engines/titanic/game/credits_button.cpp b/engines/titanic/game/credits_button.cpp index 90bb1b5ebe..ee8f7bb329 100644 --- a/engines/titanic/game/credits_button.cpp +++ b/engines/titanic/game/credits_button.cpp @@ -24,6 +24,11 @@ namespace Titanic { +BEGIN_MESSAGE_MAP(CCreditsButton, CBackground) + ON_MESSAGE(MouseButtonUpMsg) + ON_MESSAGE(MouseButtonDownMsg) +END_MESSAGE_MAP() + CCreditsButton::CCreditsButton() : CBackground(), _fieldE0(1) { } @@ -39,4 +44,19 @@ void CCreditsButton::load(SimpleFile *file) { CBackground::load(file); } +bool CCreditsButton::MouseButtonUpMsg(CMouseButtonUpMsg *msg) { + return true; +} + +bool CCreditsButton::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { + if (_fieldE0) { + playSound("a#20.wav"); + CSignalObject signalMsg; + signalMsg._numValue = 1; + signalMsg.execute("CreditsPlayer"); + } + + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/credits_button.h b/engines/titanic/game/credits_button.h index 5e0bf96677..4a53083195 100644 --- a/engines/titanic/game/credits_button.h +++ b/engines/titanic/game/credits_button.h @@ -28,6 +28,9 @@ namespace Titanic { class CCreditsButton : public CBackground { + DECLARE_MESSAGE_MAP; + bool MouseButtonUpMsg(CMouseButtonUpMsg *msg); + bool MouseButtonDownMsg(CMouseButtonDownMsg *msg); public: int _fieldE0; public: diff --git a/engines/titanic/game/null_port_hole.cpp b/engines/titanic/game/null_port_hole.cpp index e651b1b59f..b1514c7cbf 100644 --- a/engines/titanic/game/null_port_hole.cpp +++ b/engines/titanic/game/null_port_hole.cpp @@ -27,22 +27,22 @@ namespace Titanic { EMPTY_MESSAGE_MAP(CNullPortHole, CClickResponder); CNullPortHole::CNullPortHole() : CClickResponder() { - _string1 = "For a better view, why not visit the Promenade Deck?"; - _string2 = "b#48.wav"; + _message = "For a better view, why not visit the Promenade Deck?"; + _soundName = "b#48.wav"; } void CNullPortHole::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); - file->writeQuotedLine(_string2, indent); - file->writeQuotedLine(_string1, indent); + file->writeQuotedLine(_soundName, indent); + file->writeQuotedLine(_message, indent); CClickResponder::save(file, indent); } void CNullPortHole::load(SimpleFile *file) { file->readNumber(); - _string2 = file->readString(); - _string1 = file->readString(); + _soundName = file->readString(); + _message = file->readString(); CClickResponder::load(file); } diff --git a/engines/titanic/game/sgt/sgt_upper_doors_sound.cpp b/engines/titanic/game/sgt/sgt_upper_doors_sound.cpp index ed37b0a5c7..72cd7f9037 100644 --- a/engines/titanic/game/sgt/sgt_upper_doors_sound.cpp +++ b/engines/titanic/game/sgt/sgt_upper_doors_sound.cpp @@ -25,19 +25,19 @@ namespace Titanic { CSGTUpperDoorsSound::CSGTUpperDoorsSound() { - _string2 = "b#53.wav"; + _soundName = "b#53.wav"; } void CSGTUpperDoorsSound::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); - file->writeQuotedLine(_string2, indent); + file->writeQuotedLine(_soundName, indent); CClickResponder::save(file, indent); } void CSGTUpperDoorsSound::load(SimpleFile *file) { file->readNumber(); - _string2 = file->readString(); + _soundName = file->readString(); CClickResponder::load(file); } diff --git a/engines/titanic/gfx/chev_switch.cpp b/engines/titanic/gfx/chev_switch.cpp index a6ce93098c..177f0ada76 100644 --- a/engines/titanic/gfx/chev_switch.cpp +++ b/engines/titanic/gfx/chev_switch.cpp @@ -24,7 +24,13 @@ namespace Titanic { -CChevSwitch::CChevSwitch() : CToggleSwitch() { +BEGIN_MESSAGE_MAP(CChevSwitch, CToggleSwitch) + ON_MESSAGE(MouseButtonUpMsg) + ON_MESSAGE(SetChevButtonImageMsg) + ON_MESSAGE(MouseButtonDownMsg) +END_MESSAGE_MAP() + +CChevSwitch::CChevSwitch() : CToggleSwitch(), _value(0) { } void CChevSwitch::save(SimpleFile *file, int indent) { @@ -37,4 +43,36 @@ void CChevSwitch::load(SimpleFile *file) { CToggleSwitch::load(file); } +bool CChevSwitch::MouseButtonUpMsg(CMouseButtonUpMsg *msg) { + return true; +} + +bool CChevSwitch::SetChevButtonImageMsg(CSetChevButtonImageMsg *msg) { + if (msg->_value2 && getParent()) { + error("TODO: Don't know parent type"); + } + + _fieldBC = msg->_value1; + if (_fieldBC) { + loadImage((_value & 1) ? "on_odd.tga" : "on_even.tga"); + } else { + loadImage((_value & 1) ? "off_odd.tga" : "off_even.tga"); + } + + return true; +} + +bool CChevSwitch::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { + _fieldBC ^= 1; + if (getParent()) { + CSetChevPanelBitMsg bitMsg(_value, _fieldBC); + bitMsg.execute(getParent()); + } + + CSetChevButtonImageMsg chevMsg(_fieldBC, 0); + chevMsg.execute(this); + + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/gfx/chev_switch.h b/engines/titanic/gfx/chev_switch.h index 0305a6ca83..01da53c854 100644 --- a/engines/titanic/gfx/chev_switch.h +++ b/engines/titanic/gfx/chev_switch.h @@ -28,6 +28,12 @@ namespace Titanic { class CChevSwitch : public CToggleSwitch { + DECLARE_MESSAGE_MAP; + bool MouseButtonUpMsg(CMouseButtonUpMsg *msg); + bool SetChevButtonImageMsg(CSetChevButtonImageMsg *msg); + bool MouseButtonDownMsg(CMouseButtonDownMsg *msg); +public: + int _value; public: CLASSDEF; CChevSwitch(); diff --git a/engines/titanic/gfx/toggle_switch.h b/engines/titanic/gfx/toggle_switch.h index ae96c75ebd..8e7d057d8c 100644 --- a/engines/titanic/gfx/toggle_switch.h +++ b/engines/titanic/gfx/toggle_switch.h @@ -28,7 +28,7 @@ namespace Titanic { class CToggleSwitch : public CGameObject { -private: +protected: int _fieldBC; Point _pos1; public: -- cgit v1.2.3