From 4fd482e41813f32359eb91a2b62867605af0382c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 28 Apr 2016 21:07:41 -0400 Subject: TITANIC: Implement checks for whether NPCs can be summoned --- engines/titanic/core/saveable_object.cpp | 4 +-- engines/titanic/messages/messages.h | 2 +- engines/titanic/pet_control/pet_control.cpp | 40 +++++++++++++++++++++++ engines/titanic/pet_control/pet_control.h | 12 +++++++ engines/titanic/pet_control/pet_conversations.cpp | 5 ++- engines/titanic/pet_control/pet_conversations.h | 4 +-- 6 files changed, 58 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp index 4a57959b57..00a48ea435 100644 --- a/engines/titanic/core/saveable_object.cpp +++ b/engines/titanic/core/saveable_object.cpp @@ -917,7 +917,7 @@ DEFFN(CSUBTransition) DEFFN(CSubTurnOffMsg) DEFFN(CSubTurnOnMsg) DEFFN(CSummonBotMsg) -DEFFN(CSummonBotQuerryMsg) +DEFFN(CSummonBotQueryMsg) DEFFN(CTakeHeadPieceMsg) DEFFN(CTextInputMsg) DEFFN(CTimeDilationMsg) @@ -1503,7 +1503,7 @@ void CSaveableObject::initClassList() { ADDFN(CSubTurnOffMsg, CMessage); ADDFN(CSubTurnOnMsg, CMessage); ADDFN(CSummonBotMsg, CMessage); - ADDFN(CSummonBotQuerryMsg, CMessage); + ADDFN(CSummonBotQueryMsg, CMessage); ADDFN(CTakeHeadPieceMsg, CMessage); ADDFN(CTextInputMsg, CMessage); ADDFN(CTimeDilationMsg, CMessage); diff --git a/engines/titanic/messages/messages.h b/engines/titanic/messages/messages.h index ae66af1780..3af65c29da 100644 --- a/engines/titanic/messages/messages.h +++ b/engines/titanic/messages/messages.h @@ -343,7 +343,7 @@ MESSAGE0(CSUBTransition); MESSAGE0(CSubTurnOffMsg); MESSAGE0(CSubTurnOnMsg); MESSAGE2(CSummonBotMsg, CString, strValue, "", int, numValue, 0); -MESSAGE1(CSummonBotQuerryMsg, CString, value, ""); +MESSAGE1(CSummonBotQueryMsg, CString, npcName, ""); MESSAGE1(CTakeHeadPieceMsg, CString, value, "NULL"); MESSAGE2(CTextInputMsg, CString, value1, "", CString, value2, ""); MESSAGE1(CTimeDilationMsg, int, value, 0); diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index 98887f60d2..e9a8e79b8b 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -23,6 +23,7 @@ #include "titanic/pet_control/pet_control.h" #include "titanic/carry/carry.h" #include "titanic/core/project_item.h" +#include "titanic/messages/messages.h" #include "titanic/messages/pet_messages.h" #include "titanic/game_manager.h" #include "titanic/game_state.h" @@ -436,4 +437,43 @@ CString CPetControl::getRoomName() const { return room ? room->getName() : CString(); } +int CPetControl::canSummonNPC(const CString &name) { + // If player is the very same view as the NPC, then it's already present + if (isNPCInView(name)) + return SUMMON_CAN; + + // Get the room + CGameManager *gameManager = getGameManager(); + if (!gameManager) + return SUMMON_CANT; + CRoomItem *room = gameManager->getRoom(); + if (!room) + return SUMMON_CANT; + + // Query current room to see whether the bot can be summoned to it + CSummonBotQueryMsg queryMsg(name); + return queryMsg.execute(room) ? SUMMON_CAN : SUMMON_CANT; +} + +bool CPetControl::isNPCInView(const CString &name) const { + CGameManager *gameManager = getGameManager(); + if (!gameManager) + return false; + CViewItem *view = gameManager->getView(); + if (!view) + return false; + + // Iterate to find NPC + for (CTreeItem *child = view->getFirstChild(); child; child = child->scan(view)) { + CGameObject *gameObject = static_cast(child); + if (gameObject) { + if (!gameObject->getName().compareToIgnoreCase(name)) + return true; + } + } + + return false; +} + + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index 78cfb61864..4cde477704 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -39,6 +39,8 @@ namespace Titanic { +enum SummonResult { SUMMON_CANT = 0, SUMMON_PRESENT = 1, SUMMON_CAN = 2 }; + class CPetControl : public CGameObject { DECLARE_MESSAGE_MAP private: @@ -88,6 +90,11 @@ private: bool containsPt(const Common::Point &pt) const; bool getC0() const; + + /** + * Checks whether a designated NPC in present in the current view + */ + bool isNPCInView(const CString &name) const; protected: bool MouseButtonDownMsg(CMouseButtonDownMsg *msg); bool MouseDragStartMsg(CMouseDragStartMsg *msg); @@ -250,6 +257,11 @@ public: * Get the room name */ CString getRoomName() const; + + /** + * Check whether an NPC can be summoned + */ + int canSummonNPC(const CString &name); }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_conversations.cpp b/engines/titanic/pet_control/pet_conversations.cpp index d5f4da41c6..1012403727 100644 --- a/engines/titanic/pet_control/pet_conversations.cpp +++ b/engines/titanic/pet_control/pet_conversations.cpp @@ -158,9 +158,8 @@ void CPetConversations::scrollToBottom() { _field414 = true; } -SummonResult CPetConversations::canSummonNPC(const CString &name) { - warning("TODO: canSummonNPC"); - return SUMMON_ABORT; +int CPetConversations::canSummonNPC(const CString &name) { + return _petControl ? _petControl->canSummonNPC(name) : SUMMON_CANT; } void CPetConversations::summonNPC(const CString &name) { diff --git a/engines/titanic/pet_control/pet_conversations.h b/engines/titanic/pet_control/pet_conversations.h index d04e9834d1..3f396c828a 100644 --- a/engines/titanic/pet_control/pet_conversations.h +++ b/engines/titanic/pet_control/pet_conversations.h @@ -29,8 +29,6 @@ namespace Titanic { -enum SummonResult { SUMMON_CANT = 0, SUMMON_CAN = 1, SUMMON_ABORT = 2 }; - class CPetConversations : public CPetSection { private: CPetGfxElement _scrollUp; @@ -76,7 +74,7 @@ private: /** * Check whether an NPC can be summoned */ - SummonResult canSummonNPC(const CString &name); + int canSummonNPC(const CString &name); /** * Summon an NPC -- cgit v1.2.3