From df3e545976f401e4be999eb1c8fa9726b9dfcb38 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 22 Aug 2016 21:52:29 -0400 Subject: TITANIC: Implemented more game classes --- engines/titanic/carry/hose.cpp | 71 ++++++++++++++++++-- engines/titanic/carry/hose.h | 11 +++- engines/titanic/carry/key.cpp | 20 ++++++ engines/titanic/carry/key.h | 3 + engines/titanic/core/game_object.cpp | 6 +- engines/titanic/core/game_object.h | 9 ++- engines/titanic/game/idle_summoner.cpp | 79 +++++++++++++++++++++-- engines/titanic/game/idle_summoner.h | 7 +- engines/titanic/game/lemon_dispensor.cpp | 78 +++++++++++++++++++--- engines/titanic/game/lemon_dispensor.h | 15 ++++- engines/titanic/game/placeholder/lemon_on_bar.cpp | 17 ++++- engines/titanic/game/placeholder/lemon_on_bar.h | 4 +- engines/titanic/npcs/parrot_succubus.cpp | 2 +- engines/titanic/npcs/true_talk_npc.cpp | 4 -- engines/titanic/npcs/true_talk_npc.h | 5 -- engines/titanic/titanic.cpp | 2 + 16 files changed, 293 insertions(+), 40 deletions(-) diff --git a/engines/titanic/carry/hose.cpp b/engines/titanic/carry/hose.cpp index 747d58c339..e90119138a 100644 --- a/engines/titanic/carry/hose.cpp +++ b/engines/titanic/carry/hose.cpp @@ -21,9 +21,18 @@ */ #include "titanic/carry/hose.h" +#include "titanic/npcs/succubus.h" namespace Titanic { +BEGIN_MESSAGE_MAP(CHose, CCarry) + ON_MESSAGE(DropZoneGotObjectMsg) + ON_MESSAGE(PumpingMsg) + ON_MESSAGE(UseWithCharMsg) + ON_MESSAGE(HoseConnectedMsg) + ON_MESSAGE(DropZoneLostObjectMsg) +END_MESSAGE_MAP() + CHoseStatics *CHose::_statics; void CHose::init() { @@ -40,18 +49,72 @@ CHose::CHose() : CCarry(), void CHose::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); - file->writeNumberLine(_statics->_v1, indent); - file->writeQuotedLine(_statics->_v2, indent); + file->writeNumberLine(_statics->_actionVal, indent); + file->writeQuotedLine(_statics->_actionTarget, indent); file->writeQuotedLine(_string6, indent); CCarry::save(file, indent); } void CHose::load(SimpleFile *file) { file->readNumber(); - _statics->_v1 = file->readNumber(); - _statics->_v2 = file->readString(); + _statics->_actionVal = file->readNumber(); + _statics->_actionTarget = file->readString(); _string6 = file->readString(); CCarry::load(file); } +bool CHose::DropZoneGotObjectMsg(CDropZoneGotObjectMsg *msg) { + _statics->_actionTarget = msg->_object->getName(); + CPumpingMsg pumpingMsg; + pumpingMsg._value = _statics->_actionVal; + pumpingMsg.execute(_statics->_actionTarget); + CHoseConnectedMsg connectedMsg; + connectedMsg._value = 1; + connectedMsg.execute(this); + + return true; +} + +bool CHose::PumpingMsg(CPumpingMsg *msg) { + _statics->_actionVal = msg->_value; + if (!_statics->_actionTarget.empty()) { + CPumpingMsg pumpingMsg; + pumpingMsg._value = _statics->_actionVal; + pumpingMsg.execute(_statics->_actionTarget); + } + + return true; +} + +bool CHose::UseWithCharMsg(CUseWithCharMsg *msg) { + CSuccUBus *succubus = dynamic_cast(msg->_character); + if (!_statics->_actionVal && succubus) { + CHoseConnectedMsg connectedMsg(1, this); + if (connectedMsg.execute(succubus)) + return true; + } + + return CCarry::UseWithCharMsg(msg); +} + +bool CHose::HoseConnectedMsg(CHoseConnectedMsg *msg) { + if (msg->_value) { + CHose *hose = dynamic_cast(findChildInstanceOf(CHose::_type)); + if (hose) { + setVisible(true); + petAddToInventory(); + } + } + + return true; +} + +bool CHose::DropZoneLostObjectMsg(CDropZoneLostObjectMsg *msg) { + CPumpingMsg pumpingMsg; + pumpingMsg._value = 0; + pumpingMsg.execute(msg->_object); + + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/carry/hose.h b/engines/titanic/carry/hose.h index 77ab437b8b..3c8c1549c1 100644 --- a/engines/titanic/carry/hose.h +++ b/engines/titanic/carry/hose.h @@ -28,11 +28,18 @@ namespace Titanic { struct CHoseStatics { - int _v1; - CString _v2; + int _actionVal; + CString _actionTarget; + CHoseStatics() : _actionVal(0) {} }; class CHose : public CCarry { + DECLARE_MESSAGE_MAP; + bool DropZoneGotObjectMsg(CDropZoneGotObjectMsg *msg); + bool PumpingMsg(CPumpingMsg *msg); + bool UseWithCharMsg(CUseWithCharMsg *msg); + bool HoseConnectedMsg(CHoseConnectedMsg *msg); + bool DropZoneLostObjectMsg(CDropZoneLostObjectMsg *msg); protected: CString _string6; public: diff --git a/engines/titanic/carry/key.cpp b/engines/titanic/carry/key.cpp index 6e947464f1..187ff1b6c3 100644 --- a/engines/titanic/carry/key.cpp +++ b/engines/titanic/carry/key.cpp @@ -24,6 +24,11 @@ namespace Titanic { +BEGIN_MESSAGE_MAP(CKey, CCarry) + ON_MESSAGE(PuzzleSolvedMsg) + ON_MESSAGE(UseWithOtherMsg) +END_MESSAGE_MAP() + CKey::CKey() : CCarry() { } @@ -37,4 +42,19 @@ void CKey::load(SimpleFile *file) { CCarry::load(file); } +bool CKey::PuzzleSolvedMsg(CPuzzleSolvedMsg *msg) { + _fieldE0 = 1; + setVisible(true); + return true; +} + +bool CKey::UseWithOtherMsg(CUseWithOtherMsg *msg) { + if (msg->_other->getName() == "1stClassPhono") { + CActMsg actMsg("Unlock"); + actMsg.execute(msg->_other); + } + + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/carry/key.h b/engines/titanic/carry/key.h index 8f1600f2b3..9d3957937c 100644 --- a/engines/titanic/carry/key.h +++ b/engines/titanic/carry/key.h @@ -28,6 +28,9 @@ namespace Titanic { class CKey : public CCarry { + DECLARE_MESSAGE_MAP; + bool PuzzleSolvedMsg(CPuzzleSolvedMsg *msg); + bool UseWithOtherMsg(CUseWithOtherMsg *msg); public: CLASSDEF; CKey(); diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 29a6fd2209..3126aac228 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -797,6 +797,10 @@ int CGameObject::addTimer(uint firstDuration, uint repeatDuration) { return timer->_id; } +void CGameObject::stopTimer(int id) { + getGameManager()->stopTimer(id); +} + int CGameObject::startAnimTimer(const CString &action, uint firstDuration, uint repeatDuration) { CTimeEventInfo *timer = new CTimeEventInfo(getTicksCount(), repeatDuration > 0, firstDuration, repeatDuration, this, 0, action); @@ -805,7 +809,7 @@ int CGameObject::startAnimTimer(const CString &action, uint firstDuration, uint return timer->_id; } -void CGameObject::stopTimer(int id) { +void CGameObject::stopAnimTimer(int id) { getGameManager()->stopTimer(id); } diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index e2170a81d5..cb6a8529fb 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -260,15 +260,20 @@ protected: */ int addTimer(uint firstDuration, uint repeatDuration = 0); + /** + * Stops a timer + */ + void stopTimer(int id); + /** * Start an animation timer */ int startAnimTimer(const CString &action, uint firstDuration, uint repeatDuration = 0); /** - * Stops a timer + * Stop an animation timer */ - void stopTimer(int id); + void stopAnimTimer(int id); /** * Causes the game to sleep for the specified time diff --git a/engines/titanic/game/idle_summoner.cpp b/engines/titanic/game/idle_summoner.cpp index 19d760a8db..5ca3209e28 100644 --- a/engines/titanic/game/idle_summoner.cpp +++ b/engines/titanic/game/idle_summoner.cpp @@ -24,10 +24,16 @@ namespace Titanic { -CIdleSummoner::CIdleSummoner() : CGameObject(), _fieldBC(0x57E40), - _fieldC0(0xEA60), _fieldC4(0x57E40), _fieldC8(0xEA60), - _fieldCC(0xEA60), _fieldD0(0xEA60), _fieldD4(0xEA60), - _fieldD8(0xEA60), _fieldDC(0xEA60) { +BEGIN_MESSAGE_MAP(CIdleSummoner, CGameObject) + ON_MESSAGE(EnterViewMsg) + ON_MESSAGE(TimerMsg) + ON_MESSAGE(ActMsg) + ON_MESSAGE(LoadSuccessMsg) +END_MESSAGE_MAP() + +CIdleSummoner::CIdleSummoner() : CGameObject(), _fieldBC(360000), + _fieldC0(60000), _fieldC4(360000), _fieldC8(60000), + _fieldCC(0), _fieldD0(0), _fieldD4(0), _fieldD8(0), _ticks(0) { } void CIdleSummoner::save(SimpleFile *file, int indent) { @@ -40,7 +46,7 @@ void CIdleSummoner::save(SimpleFile *file, int indent) { file->writeNumberLine(_fieldD0, indent); file->writeNumberLine(_fieldD4, indent); file->writeNumberLine(_fieldD8, indent); - file->writeNumberLine(_fieldDC, indent); + file->writeNumberLine(_ticks, indent); CGameObject::save(file, indent); } @@ -55,9 +61,70 @@ void CIdleSummoner::load(SimpleFile *file) { _fieldD0 = file->readNumber(); _fieldD4 = file->readNumber(); _fieldD8 = file->readNumber(); - _fieldDC = file->readNumber(); + _ticks = file->readNumber(); CGameObject::load(file); } +bool CIdleSummoner::EnterViewMsg(CEnterViewMsg *msg) { + CActMsg actMsg("Enable"); + actMsg.execute(this); + return true; +} + +bool CIdleSummoner::TimerMsg(CTimerMsg *msg) { + uint nodesCtr = getNodeChangedCtr(); + if (msg->_actionVal == 1 && !petDoorOrBellbotPresent() + && nodesCtr > 0 && _fieldD8) { + if (!compareRoomNameTo("TopOfWell") && !compareRoomNameTo("EmbLobby")) + return true; + + int region = talkGetDialRegion("BellBot", 1); + uint delay = region == 1 ? 15000 : 12000; + uint enterTicks = MIN(getNodeEnterTicks(), _ticks); + + CString name; + uint ticks = getTicksCount() - enterTicks; + if (ticks > delay) { + if (region == 1 || getRandomNumber(1) == 1) { + name = "BellBot"; + } else { + name = "DoorBot"; + } + _fieldD8 = nodesCtr; + + if (getRoom()) { + CSummonBotQueryMsg queryMsg(name); + if (queryMsg.execute(this)) { + CSummonBotMsg summonMsg(name, 1); + summonMsg.execute(this); + } + } + } + } + + return true; +} + +bool CIdleSummoner::ActMsg(CActMsg *msg) { + if (msg->_action == "Enable") { + if (!_fieldD4) + _fieldD4 = addTimer(15000, 15000); + } else if (msg->_action == "Disable") { + if (_fieldD4 > 0) { + stopAnimTimer(_fieldD4); + _fieldD4 = 0; + } + } else if (msg->_action == "DoorbotDismissed" || msg->_action == "BellbotDismissed") { + _ticks = getTicksCount(); + } + + return true; +} + +bool CIdleSummoner::LoadSuccessMsg(CLoadSuccessMsg *msg) { + _ticks = getTicksCount(); + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/idle_summoner.h b/engines/titanic/game/idle_summoner.h index 1d9fcdd176..0066694b68 100644 --- a/engines/titanic/game/idle_summoner.h +++ b/engines/titanic/game/idle_summoner.h @@ -28,6 +28,11 @@ namespace Titanic { class CIdleSummoner : public CGameObject { + DECLARE_MESSAGE_MAP; + bool EnterViewMsg(CEnterViewMsg *msg); + bool TimerMsg(CTimerMsg *msg); + bool ActMsg(CActMsg *msg); + bool LoadSuccessMsg(CLoadSuccessMsg *msg); public: int _fieldBC; int _fieldC0; @@ -37,7 +42,7 @@ public: int _fieldD0; int _fieldD4; int _fieldD8; - int _fieldDC; + uint _ticks; public: CIdleSummoner(); CLASSDEF; diff --git a/engines/titanic/game/lemon_dispensor.cpp b/engines/titanic/game/lemon_dispensor.cpp index 8e1674cb2d..31a04cbeca 100644 --- a/engines/titanic/game/lemon_dispensor.cpp +++ b/engines/titanic/game/lemon_dispensor.cpp @@ -24,22 +24,36 @@ namespace Titanic { -int CLemonDispensor::_v1; +BEGIN_MESSAGE_MAP(CLemonDispensor, CBackground) + ON_MESSAGE(FrameMsg) + ON_MESSAGE(ChangeSeasonMsg) + ON_MESSAGE(LeaveViewMsg) +END_MESSAGE_MAP() + +bool CLemonDispensor::_isSummer; int CLemonDispensor::_v2; int CLemonDispensor::_v3; +CGameObject *CLemonDispensor::_draggingObject; CLemonDispensor::CLemonDispensor() : CBackground(), - _fieldE0(0), _fieldE4(9), _fieldE8(15), _fieldEC(0) { + _fieldE0(0), _origPt(Point(9, 15)), _fieldEC(0) { +} + +void CLemonDispensor::init() { + _isSummer = false; + _v2 = 0; + _v3 = 0; + _draggingObject = nullptr; } void CLemonDispensor::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); - file->writeNumberLine(_v1, indent); + file->writeNumberLine(_isSummer, indent); file->writeNumberLine(_v2, indent); file->writeNumberLine(_v3, indent); file->writeNumberLine(_fieldE0, indent); - file->writeNumberLine(_fieldE4, indent); - file->writeNumberLine(_fieldE8, indent); + file->writeNumberLine(_origPt.x, indent); + file->writeNumberLine(_origPt.y, indent); file->writeNumberLine(_fieldEC, indent); CBackground::save(file, indent); @@ -47,15 +61,63 @@ void CLemonDispensor::save(SimpleFile *file, int indent) { void CLemonDispensor::load(SimpleFile *file) { file->readNumber(); - _v1 = file->readNumber(); + _isSummer = file->readNumber(); _v2 = file->readNumber(); _v3 = file->readNumber(); _fieldE0 = file->readNumber(); - _fieldE4 = file->readNumber(); - _fieldE8 = file->readNumber(); + _origPt.x = file->readNumber(); + _origPt.y = file->readNumber(); _fieldEC = file->readNumber(); CBackground::load(file); } +bool CLemonDispensor::FrameMsg(CFrameMsg *msg) { + if (_v2 || !_isSummer) + return true; + + if (!_draggingObject) { + CGameObject *obj = getDraggingObject(); + if (obj && getView() == findView()) { + if (obj->isEquals("Perch")) { + petDisplayMessage(1, "This stick is too short to reach the branches."); + return true; + } + + if (obj->isEquals("LongStick")) + _draggingObject = obj; + } + } + + if (_draggingObject) { + Point pt(_origPt.x + _draggingObject->_bounds.left, + _origPt.y + _draggingObject->_bounds.top); + bool flag = checkPoint(pt, true); + + if (_fieldEC == 0) { + if (flag && ++_v3 > 10) { + CLemonFallsFromTreeMsg lemonMsg(pt); + lemonMsg.execute("Lemon"); + _v2 = 1; + } + } else if (_fieldEC == 1 && !flag) { + _fieldEC = 0; + } + } + + return true; +} + +bool CLemonDispensor::ChangeSeasonMsg(CChangeSeasonMsg *msg) { + _isSummer = msg->_season == "Summer"; + return true; +} + +bool CLemonDispensor::LeaveViewMsg(CLeaveViewMsg *msg) { + _draggingObject = nullptr; + _v3 = 0; + _fieldEC = 0; + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/lemon_dispensor.h b/engines/titanic/game/lemon_dispensor.h index d6315ed620..933e0b6af0 100644 --- a/engines/titanic/game/lemon_dispensor.h +++ b/engines/titanic/game/lemon_dispensor.h @@ -28,19 +28,28 @@ namespace Titanic { class CLemonDispensor : public CBackground { + DECLARE_MESSAGE_MAP; + bool FrameMsg(CFrameMsg *msg); + bool ChangeSeasonMsg(CChangeSeasonMsg *msg); + bool LeaveViewMsg(CLeaveViewMsg *msg); private: - static int _v1; + static bool _isSummer; static int _v2; static int _v3; + static CGameObject *_draggingObject; int _fieldE0; - int _fieldE4; - int _fieldE8; + Point _origPt; int _fieldEC; public: CLASSDEF; CLemonDispensor(); + /** + * Initialize statics + */ + static void init(); + /** * Save the data for the class to file */ diff --git a/engines/titanic/game/placeholder/lemon_on_bar.cpp b/engines/titanic/game/placeholder/lemon_on_bar.cpp index 08d686e81a..917c751e67 100644 --- a/engines/titanic/game/placeholder/lemon_on_bar.cpp +++ b/engines/titanic/game/placeholder/lemon_on_bar.cpp @@ -24,16 +24,29 @@ namespace Titanic { +BEGIN_MESSAGE_MAP(CLemonOnBar, CPlaceHolderItem) + ON_MESSAGE(VisibleMsg) +END_MESSAGE_MAP() + void CLemonOnBar::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); - file->writePoint(_pos1, indent); + file->writePoint(_lemonPos, indent); CPlaceHolderItem::save(file, indent); } void CLemonOnBar::load(SimpleFile *file) { file->readNumber(); - _pos1 = file->readPoint(); + _lemonPos = file->readPoint(); CPlaceHolderItem::load(file); } +bool CLemonOnBar::VisibleMsg(CVisibleMsg *msg) { + setVisible(msg->_visible); + if (msg->_visible) + setPosition(_lemonPos); + else + setPosition(Point(0, 0)); + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/placeholder/lemon_on_bar.h b/engines/titanic/game/placeholder/lemon_on_bar.h index 92dd54c49b..af5d5e67c8 100644 --- a/engines/titanic/game/placeholder/lemon_on_bar.h +++ b/engines/titanic/game/placeholder/lemon_on_bar.h @@ -28,8 +28,10 @@ namespace Titanic { class CLemonOnBar : public CPlaceHolderItem { + DECLARE_MESSAGE_MAP; + bool VisibleMsg(CVisibleMsg *msg); private: - Point _pos1; + Point _lemonPos; public: CLASSDEF; diff --git a/engines/titanic/npcs/parrot_succubus.cpp b/engines/titanic/npcs/parrot_succubus.cpp index 5f67b8f44c..d285c219b5 100644 --- a/engines/titanic/npcs/parrot_succubus.cpp +++ b/engines/titanic/npcs/parrot_succubus.cpp @@ -138,7 +138,7 @@ bool CParrotSuccUBus::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { bool CParrotSuccUBus::LeaveNodeMsg(CLeaveNodeMsg *msg) { if (_field1DC) { getHiddenObject(_string3); - if (CHose::_statics->_v2.empty()) { + if (CHose::_statics->_actionTarget.empty()) { playSound("z#51.wav"); CHoseConnectedMsg hoseMsg; hoseMsg._value = 0; diff --git a/engines/titanic/npcs/true_talk_npc.cpp b/engines/titanic/npcs/true_talk_npc.cpp index c2705bf483..5ba68aafbe 100644 --- a/engines/titanic/npcs/true_talk_npc.cpp +++ b/engines/titanic/npcs/true_talk_npc.cpp @@ -198,10 +198,6 @@ void CTrueTalkNPC::processInput(CTextInputMsg *msg, CViewItem *view) { talkManager->processInput(this, msg, view); } -void CTrueTalkNPC::stopAnimTimer(int id) { - getGameManager()->stopTimer(id); -} - void CTrueTalkNPC::setView(CViewItem *view) { CTrueTalkManager *talkManager = getGameManager()->getTalkManager(); if (talkManager) diff --git a/engines/titanic/npcs/true_talk_npc.h b/engines/titanic/npcs/true_talk_npc.h index ea6cbb3f84..1eade1966d 100644 --- a/engines/titanic/npcs/true_talk_npc.h +++ b/engines/titanic/npcs/true_talk_npc.h @@ -67,11 +67,6 @@ protected: protected: void processInput(CTextInputMsg *msg, CViewItem *view); - /** - * Stop an animation timer - */ - void stopAnimTimer(int id); - /** * Perform an action */ diff --git a/engines/titanic/titanic.cpp b/engines/titanic/titanic.cpp index af894d6997..3a721b6095 100644 --- a/engines/titanic/titanic.cpp +++ b/engines/titanic/titanic.cpp @@ -33,6 +33,7 @@ #include "titanic/carry/hose.h" #include "titanic/core/saveable_object.h" #include "titanic/game/get_lift_eye2.h" +#include "titanic/game/lemon_dispensor.h" #include "titanic/game/television.h" #include "titanic/game/parrot/parrot_lobby_object.h" #include "titanic/game/sgt/sgt_navigation.h" @@ -91,6 +92,7 @@ void TitanicEngine::initialize() { CGameObject::init(); CGetLiftEye2::init(); CHose::init(); + CLemonDispensor::init(); CMovie::init(); CParrotLobbyObject::init(); CSGTNavigation::init(); -- cgit v1.2.3