aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/pet_control/pet_control.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-28 21:07:41 -0400
committerPaul Gilbert2016-07-10 16:22:37 -0400
commit4fd482e41813f32359eb91a2b62867605af0382c (patch)
treec313e8d26fa0ae0fa00aacb051ac3f22e5f9d538 /engines/titanic/pet_control/pet_control.cpp
parentff72fc594bae10cd4ac5083d0cf2ca6c412d0f9f (diff)
downloadscummvm-rg350-4fd482e41813f32359eb91a2b62867605af0382c.tar.gz
scummvm-rg350-4fd482e41813f32359eb91a2b62867605af0382c.tar.bz2
scummvm-rg350-4fd482e41813f32359eb91a2b62867605af0382c.zip
TITANIC: Implement checks for whether NPCs can be summoned
Diffstat (limited to 'engines/titanic/pet_control/pet_control.cpp')
-rw-r--r--engines/titanic/pet_control/pet_control.cpp40
1 files changed, 40 insertions, 0 deletions
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<CGameObject *>(child);
+ if (gameObject) {
+ if (!gameObject->getName().compareToIgnoreCase(name))
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
} // End of namespace Titanic