diff options
author | Paul Gilbert | 2016-04-07 23:39:26 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-04-07 23:39:26 -0400 |
commit | e7f2cb1ecbf2637db8dd7be3fe97d485a7c56bc8 (patch) | |
tree | fba43657861ad5f088db01ae504cc6db2d6aa4d8 /engines/titanic/core | |
parent | 9f1bab55972b8a6f88b83c2391c40a038ffb509d (diff) | |
download | scummvm-rg350-e7f2cb1ecbf2637db8dd7be3fe97d485a7c56bc8.tar.gz scummvm-rg350-e7f2cb1ecbf2637db8dd7be3fe97d485a7c56bc8.tar.bz2 scummvm-rg350-e7f2cb1ecbf2637db8dd7be3fe97d485a7c56bc8.zip |
TITANIC: Add CComputer messages, more view change logic
Diffstat (limited to 'engines/titanic/core')
-rw-r--r-- | engines/titanic/core/game_object.cpp | 73 | ||||
-rw-r--r-- | engines/titanic/core/game_object.h | 11 | ||||
-rw-r--r-- | engines/titanic/core/link_item.cpp | 9 | ||||
-rw-r--r-- | engines/titanic/core/link_item.h | 5 | ||||
-rw-r--r-- | engines/titanic/core/tree_item.h | 6 | ||||
-rw-r--r-- | engines/titanic/core/view_item.cpp | 11 | ||||
-rw-r--r-- | engines/titanic/core/view_item.h | 6 |
7 files changed, 121 insertions, 0 deletions
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 0570008a09..02a64dcad2 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -424,4 +424,77 @@ void CGameObject::soundProximity(const CString &name, CProximity &prox) { } } +void CGameObject::gotoView(const CString &viewName, const CString &clipName) { + CViewItem *newView = parseView(viewName); + CGameManager *gameManager = getGameManager(); + CViewItem *oldView = gameManager ? gameManager->getView() : newView; + if (!oldView || !newView) + return; + + CMovieClip *clip = nullptr; + if (clipName.empty()) { + CLinkItem *link = oldView->findLink(newView); + if (link) + clip = link->getClip(); + } else { + clip = oldView->findNode()->findRoom()->findClip(clipName); + } + + // Change the view + gameManager->_gameState.changeView(newView, clip); +} + +CViewItem *CGameObject::parseView(const CString &viewString) { + int firstIndex = viewString.indexOf('.'); + int lastIndex = viewString.lastIndexOf('.'); + CString roomName, nodeName, viewName; + + if (firstIndex == -1) { + roomName = viewString; + } else { + roomName = viewString.left(firstIndex); + + if (lastIndex > firstIndex) { + nodeName = viewString.mid(firstIndex + 1, lastIndex - firstIndex - 1); + viewName = viewString.mid(lastIndex + 1); + } else { + nodeName = viewString.mid(firstIndex + 1); + } + } + + CGameManager *gameManager = getGameManager(); + if (!gameManager) + return nullptr; + + CRoomItem *room = gameManager->getRoom(); + CProjectItem *project = room->getRoot(); + + // Ensure we have the specified room + if (project) { + if (room->getName() != roomName) { + // Scan for the correct room + for (room = project->findFirstRoom(); room && room->getName() != roomName; + room = project->findNextRoom(room)) ; + } + } + if (!room) + return nullptr; + + // Find the designated node within the room + CNodeItem *node = static_cast<CNodeItem *>(room->findChildInstanceOf(CNodeItem::_type)); + while (node && node->getName() != nodeName) + node = static_cast<CNodeItem *>(room->findNextInstanceOf(CNodeItem::_type, node)); + if (!node) + return nullptr; + + CViewItem *view = static_cast<CViewItem *>(node->findChildInstanceOf(CViewItem::_type)); + while (view && view->getName() != viewName) + view = static_cast<CViewItem *>(node->findNextInstanceOf(CViewItem::_type, view)); + if (!view) + return nullptr; + + // Find the view, so return it + return view; +} + } // End of namespace Titanic diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index 72192425f4..2fc047e523 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -112,6 +112,17 @@ protected: */ void setPetArea(PetArea newArea) const; + /** + * Goto a new view + */ + void gotoView(const CString &viewName, const CString &clipName); + + /** + * Parses a view into it's components of room, node, and view, + * and locates the designated view + */ + CViewItem * parseView(const CString &viewString); + bool soundFn1(int val); void soundFn2(int val, int val2); void setVisible(bool val); diff --git a/engines/titanic/core/link_item.cpp b/engines/titanic/core/link_item.cpp index 285838b692..b172b9b4d0 100644 --- a/engines/titanic/core/link_item.cpp +++ b/engines/titanic/core/link_item.cpp @@ -108,6 +108,15 @@ void CLinkItem::load(SimpleFile *file) { } } +bool CLinkItem::connectsTo(CViewItem *destView) const { + CNodeItem *destNode = destView->findNode(); + CRoomItem *destRoom = destNode->findRoom(); + + return _viewNumber == destView->_viewNumber && + _nodeNumber == destNode->_nodeNumber && + _roomNumber == destRoom->_roomNumber; +} + void CLinkItem::setDestination(int roomNumber, int nodeNumber, int viewNumber, int v) { _roomNumber = roomNumber; diff --git a/engines/titanic/core/link_item.h b/engines/titanic/core/link_item.h index 72829720d7..25de74104b 100644 --- a/engines/titanic/core/link_item.h +++ b/engines/titanic/core/link_item.h @@ -63,6 +63,11 @@ public: virtual void load(SimpleFile *file); /** + * Returns true if the given item connects to another specified view + */ + virtual bool connectsTo(CViewItem *destView) const; + + /** * Set the destination for the link item */ virtual void setDestination(int roomNumber, int nodeNumber, diff --git a/engines/titanic/core/tree_item.h b/engines/titanic/core/tree_item.h index d34f963584..4de030f387 100644 --- a/engines/titanic/core/tree_item.h +++ b/engines/titanic/core/tree_item.h @@ -35,6 +35,7 @@ class CPetControl; class CProjectItem; class CScreenManager; class CRoomItem; +class CViewItem; class CTreeItem: public CMessageTarget { friend class CMessage; @@ -126,6 +127,11 @@ public: virtual int compareTo(const CString &name, int maxLen) const { return false; } /** + * Returns true if the given item connects to another specified view + */ + virtual bool connectsTo(CViewItem *destView) const { return false; } + + /** * Allows the item to draw itself */ virtual void draw(CScreenManager *screenManager) {} diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp index 3f6d5d5cff..b829ae5a70 100644 --- a/engines/titanic/core/view_item.cpp +++ b/engines/titanic/core/view_item.cpp @@ -168,6 +168,17 @@ void CViewItem::enterView(CViewItem *newView) { } } +CLinkItem *CViewItem::findLink(CViewItem *newView) { + for (CTreeItem *treeItem = getFirstChild(); treeItem; + treeItem = scan(treeItem)) { + CLinkItem *link = static_cast<CLinkItem *>(treeItem); + if (link && link->connectsTo(newView)) + return link; + } + + return nullptr; +} + bool CViewItem::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { if (msg->_buttons & MB_LEFT) { if (!handleMouseMsg(msg, true)) { diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h index 5abcf1d012..67b2113142 100644 --- a/engines/titanic/core/view_item.h +++ b/engines/titanic/core/view_item.h @@ -23,6 +23,7 @@ #ifndef TITANIC_VIEW_ITEM_H #define TITANIC_VIEW_ITEM_H +#include "titanic/core/link_item.h" #include "titanic/core/named_item.h" #include "titanic/core/resource_key.h" #include "titanic/messages/mouse_messages.h" @@ -90,6 +91,11 @@ public: * Called when a new view is being entered */ void enterView(CViewItem *newView); + + /** + * Finds a link which connects to another designated view + */ + CLinkItem *findLink(CViewItem *newView); }; } // End of namespace Titanic |