diff options
Diffstat (limited to 'engines/titanic/core')
-rw-r--r-- | engines/titanic/core/node_item.cpp | 6 | ||||
-rw-r--r-- | engines/titanic/core/node_item.h | 5 | ||||
-rw-r--r-- | engines/titanic/core/project_item.cpp | 64 | ||||
-rw-r--r-- | engines/titanic/core/project_item.h | 15 | ||||
-rw-r--r-- | engines/titanic/core/saveable_object.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/core/saveable_object.h | 2 | ||||
-rw-r--r-- | engines/titanic/core/tree_item.cpp | 20 | ||||
-rw-r--r-- | engines/titanic/core/tree_item.h | 10 | ||||
-rw-r--r-- | engines/titanic/core/view_item.cpp | 6 | ||||
-rw-r--r-- | engines/titanic/core/view_item.h | 3 |
10 files changed, 110 insertions, 25 deletions
diff --git a/engines/titanic/core/node_item.cpp b/engines/titanic/core/node_item.cpp index f44be6ddaf..22c9b9b37f 100644 --- a/engines/titanic/core/node_item.cpp +++ b/engines/titanic/core/node_item.cpp @@ -24,7 +24,7 @@ namespace Titanic { -CNodeItem::CNodeItem() : CNamedItem(), _field24(0), _field28(0), _field2C(0) { +CNodeItem::CNodeItem() : CNamedItem(), _field24(0), _field28(0), _nodeNumber(0) { } void CNodeItem::save(SimpleFile *file, int indent) const { @@ -34,7 +34,7 @@ void CNodeItem::save(SimpleFile *file, int indent) const { file->writeNumberLine(_field28, indent + 1); file->writeQuotedLine("N", indent); - file->writeNumberLine(_field2C, indent + 1); + file->writeNumberLine(_nodeNumber, indent + 1); CNamedItem::save(file, indent); } @@ -46,7 +46,7 @@ void CNodeItem::load(SimpleFile *file) { _field28 = file->readNumber(); file->readBuffer(); - _field2C = file->readNumber(); + _nodeNumber = file->readNumber(); CNamedItem::load(file); } diff --git a/engines/titanic/core/node_item.h b/engines/titanic/core/node_item.h index 45309a1891..4f0391ae88 100644 --- a/engines/titanic/core/node_item.h +++ b/engines/titanic/core/node_item.h @@ -28,10 +28,11 @@ namespace Titanic { class CNodeItem : public CNamedItem { -private: +protected: int _field24; int _field28; - int _field2C; +public: + int _nodeNumber; public: CLASSDEF CNodeItem(); diff --git a/engines/titanic/core/project_item.cpp b/engines/titanic/core/project_item.cpp index 18b0c42815..bf31388963 100644 --- a/engines/titanic/core/project_item.cpp +++ b/engines/titanic/core/project_item.cpp @@ -25,7 +25,9 @@ #include "titanic/game_manager.h" #include "titanic/titanic.h" #include "titanic/core/dont_save_file_item.h" +#include "titanic/core/node_item.h" #include "titanic/core/project_item.h" +#include "titanic/core/view_item.h" #include "titanic/pet_control/pet_control.h" namespace Titanic { @@ -177,7 +179,7 @@ void CProjectItem::loadGame(int slotId) { newProject->destroyAll(); // Post-load processing - gameLoaded(); + postLoad(); } void CProjectItem::saveGame(int slotId) { @@ -251,7 +253,6 @@ void CProjectItem::saveData(SimpleFile *file, CTreeItem *item) const { item->saveHeader(file, 0); item->save(file, 1); item->saveFooter(file, 0); - CTreeItem *child = item->getFirstChild(); if (child) { @@ -271,14 +272,14 @@ void CProjectItem::saveData(SimpleFile *file, CTreeItem *item) const { } } -void CProjectItem::gameLoaded() { +void CProjectItem::postLoad() { CGameManager *gameManager = getGameManager(); if (gameManager) - gameManager->gameLoaded(); + gameManager->postLoad(this); CPetControl *petControl = getPetControl(); if (petControl) - petControl->gameLoaded(); + petControl->postLoad(); } CPetControl *CProjectItem::getPetControl() const { @@ -300,10 +301,10 @@ CPetControl *CProjectItem::getPetControl() const { } CRoomItem *CProjectItem::findFirstRoom() const { - return dynamic_cast<CRoomItem *>(findChildInstance(*CRoomItem::_type)); + return dynamic_cast<CRoomItem *>(findChildInstance(CRoomItem::_type)); } -CTreeItem *CProjectItem::findChildInstance(ClassDef &classDef) const { +CTreeItem *CProjectItem::findChildInstance(ClassDef *classDef) const { CTreeItem *treeItem = getFirstChild(); if (treeItem == nullptr) return nullptr; @@ -322,10 +323,10 @@ CTreeItem *CProjectItem::findChildInstance(ClassDef &classDef) const { } CRoomItem *CProjectItem::findNextRoom(CRoomItem *priorRoom) const { - return dynamic_cast<CRoomItem *>(findSiblingInstanceOf(*CRoomItem::_type, priorRoom)); + return dynamic_cast<CRoomItem *>(findSiblingInstanceOf(CRoomItem::_type, priorRoom)); } -CTreeItem *CProjectItem::findSiblingInstanceOf(ClassDef &classDef, CTreeItem *startItem) const { +CTreeItem *CProjectItem::findSiblingInstanceOf(ClassDef *classDef, CTreeItem *startItem) const { CTreeItem *treeItem = startItem->getParent()->getNextSibling(); if (treeItem == nullptr) return nullptr; @@ -335,7 +336,7 @@ CTreeItem *CProjectItem::findSiblingInstanceOf(ClassDef &classDef, CTreeItem *st CDontSaveFileItem *CProjectItem::getDontSaveFileItem() const { for (CTreeItem *treeItem = getFirstChild(); treeItem; treeItem = treeItem->getNextSibling()) { - if (treeItem->isInstanceOf(*CDontSaveFileItem::_type)) + if (treeItem->isInstanceOf(CDontSaveFileItem::_type)) return dynamic_cast<CDontSaveFileItem *>(treeItem); } @@ -346,4 +347,47 @@ CRoomItem *CProjectItem::findHiddenRoom() { return dynamic_cast<CRoomItem *>(findByName("HiddenRoom")); } +CViewItem *CProjectItem::findView(int roomNumber, int nodeNumber, int viewNumber) { + CTreeItem *treeItem = getFirstChild(); + CRoomItem *roomItem = nullptr; + + // Scan for the specified room + if (treeItem) { + do { + CTreeItem *childItem = treeItem->getFirstChild(); + CRoomItem *rItem = dynamic_cast<CRoomItem *>(childItem); + if (rItem && rItem->_roomNumber == roomNumber) { + roomItem = rItem; + break; + } + } while ((treeItem = treeItem->getNextSibling()) != nullptr); + } + if (!roomItem) + return nullptr; + + // Scan for the specified node within the room + CNodeItem *nodeItem = nullptr; + + CNodeItem *nItem = dynamic_cast<CNodeItem *>( + roomItem->findChildInstanceOf(CNodeItem::_type)); + for (; nItem && !nodeItem; nItem = dynamic_cast<CNodeItem *>( + findNextInstanceOf(CNodeItem::_type, nItem))) { + if (nItem->_nodeNumber == nodeNumber) + nodeItem = nItem; + } + if (!nodeItem) + return nullptr; + + // Scan for the specified view within the node + CViewItem *viewItem = dynamic_cast<CViewItem *>( + nodeItem->findChildInstanceOf(CViewItem::_type)); + for (; viewItem; viewItem = dynamic_cast<CViewItem *>( + findNextInstanceOf(CViewItem::_type, viewItem))) { + if (viewItem->_viewNumber == viewNumber) + return viewItem; + } + + return nullptr; +} + } // End of namespace Titanic diff --git a/engines/titanic/core/project_item.h b/engines/titanic/core/project_item.h index f4148b0678..65fe8b88bd 100644 --- a/engines/titanic/core/project_item.h +++ b/engines/titanic/core/project_item.h @@ -34,6 +34,7 @@ namespace Titanic { class CGameManager; class CPetControl; +class CViewItem; /** * File list item @@ -81,12 +82,12 @@ private: /** * Finds the first child instance of a given class type */ - CTreeItem *findChildInstance(ClassDef &classDef) const; + CTreeItem *findChildInstance(ClassDef *classDef) const; /** * Finds the next sibling occurance of a given class type */ - CTreeItem *findSiblingInstanceOf(ClassDef &classDef, CTreeItem *startItem) const; + CTreeItem *findSiblingInstanceOf(ClassDef *classDef, CTreeItem *startItem) const; private: /** * Load project data from the passed file @@ -101,7 +102,7 @@ private: /** * Does post-loading processing */ - void gameLoaded(); + void postLoad(); public: CLASSDEF CProjectItem(); @@ -171,7 +172,15 @@ public: */ CDontSaveFileItem *getDontSaveFileItem() const; + /** + * Finds the hidden room node of the project + */ CRoomItem *findHiddenRoom(); + + /** + * Finds a view + */ + CViewItem *findView(int roomNumber, int nodeNumber, int viewNumber); }; } // End of namespace Titanic diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp index 8e3ab1e067..8e9ec4e1d6 100644 --- a/engines/titanic/core/saveable_object.cpp +++ b/engines/titanic/core/saveable_object.cpp @@ -1581,9 +1581,9 @@ void CSaveableObject::saveFooter(SimpleFile *file, int indent) const { file->writeClassEnd(indent); } -bool CSaveableObject::isInstanceOf(const ClassDef &classDef) { +bool CSaveableObject::isInstanceOf(const ClassDef *classDef) { for (ClassDef *def = getType(); def != nullptr; def = def->_parent) { - if (def == &classDef) + if (def == classDef) return true; } diff --git a/engines/titanic/core/saveable_object.h b/engines/titanic/core/saveable_object.h index c4615c52b2..1fb509bf20 100644 --- a/engines/titanic/core/saveable_object.h +++ b/engines/titanic/core/saveable_object.h @@ -80,7 +80,7 @@ public: CLASSDEF virtual ~CSaveableObject() {} - bool isInstanceOf(const ClassDef &classDef); + bool isInstanceOf(const ClassDef *classDef); /** * Save the data for the class to file diff --git a/engines/titanic/core/tree_item.cpp b/engines/titanic/core/tree_item.cpp index 31deab860d..ffcee40c6a 100644 --- a/engines/titanic/core/tree_item.cpp +++ b/engines/titanic/core/tree_item.cpp @@ -88,6 +88,26 @@ CTreeItem *CTreeItem::scan(CTreeItem *item) const { return nullptr; } +CTreeItem *CTreeItem::findChildInstanceOf(ClassDef *classDef) const { + for (CTreeItem *treeItem = _firstChild; treeItem; treeItem = treeItem->getNextSibling()) { + if (treeItem->isInstanceOf(classDef)) + return treeItem; + } + + return nullptr; +} + +CTreeItem *CTreeItem::findNextInstanceOf(ClassDef *classDef, CTreeItem *startItem) const { + CTreeItem *treeItem = startItem ? startItem->getNextSibling() : getFirstChild(); + + for (; treeItem; treeItem = treeItem->getNextSibling()) { + if (treeItem->isInstanceOf(classDef)) + return treeItem; + } + + return nullptr; +} + void CTreeItem::addUnder(CTreeItem *newParent) { if (newParent->_firstChild) addSibling(newParent->getLastSibling()); diff --git a/engines/titanic/core/tree_item.h b/engines/titanic/core/tree_item.h index afca5254df..e218cf3dbb 100644 --- a/engines/titanic/core/tree_item.h +++ b/engines/titanic/core/tree_item.h @@ -119,6 +119,16 @@ public: CTreeItem *scan(CTreeItem *item) const; /** + * Find the first child item that is of a given type + */ + CTreeItem *findChildInstanceOf(ClassDef *classDef) const; + + /** + * Find the next sibling item that is of the given type + */ + CTreeItem *findNextInstanceOf(ClassDef *classDef, CTreeItem *startItem) const; + + /** * Adds the item under another tree item */ void addUnder(CTreeItem *newParent); diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp index e64229e3d3..5253f24749 100644 --- a/engines/titanic/core/view_item.cpp +++ b/engines/titanic/core/view_item.cpp @@ -27,7 +27,7 @@ namespace Titanic { CViewItem::CViewItem() : CNamedItem() { _field24 = 0; _field28 = 0.0; - _field30 = 0; + _viewNumber = 0; _field50 = 0; _field54 = 0; setData(0.0); @@ -44,7 +44,7 @@ void CViewItem::save(SimpleFile *file, int indent) const { _resourceKey.save(file, indent); file->writeQuotedLine("V", indent); file->writeFloatLine(_field28, indent + 1); - file->writeNumberLine(_field30, indent + 1); + file->writeNumberLine(_viewNumber, indent + 1); CNamedItem::save(file, indent); } @@ -60,7 +60,7 @@ void CViewItem::load(SimpleFile *file) { default: file->readBuffer(); setData(file->readFloat()); - _field30 = file->readNumber(); + _viewNumber = file->readNumber(); break; } diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h index a5ce575171..805b7a4f9c 100644 --- a/engines/titanic/core/view_item.h +++ b/engines/titanic/core/view_item.h @@ -34,11 +34,12 @@ private: protected: int _field24; double _field28; - int _field30; CResourceKey _resourceKey; int _field50; int _field54; public: + int _viewNumber; +public: CLASSDEF CViewItem(); |