aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2016-02-23 20:59:57 -0500
committerPaul Gilbert2016-02-23 20:59:57 -0500
commita0dbab62b99afa331b5162a8c81a4db391cbd09e (patch)
treece8748d5ddab902815f33ef15501bd199cff48ab /engines
parent938316b7dfdbbdf00b2b6e50ea2f05d856e15593 (diff)
downloadscummvm-rg350-a0dbab62b99afa331b5162a8c81a4db391cbd09e.tar.gz
scummvm-rg350-a0dbab62b99afa331b5162a8c81a4db391cbd09e.tar.bz2
scummvm-rg350-a0dbab62b99afa331b5162a8c81a4db391cbd09e.zip
TITANIC: Major fleshing out of game loading code
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/game_manager.cpp8
-rw-r--r--engines/titanic/game_manager.h11
-rw-r--r--engines/titanic/module.mk4
-rw-r--r--engines/titanic/objects/dont_save_file_item.cpp35
-rw-r--r--engines/titanic/objects/dont_save_file_item.h50
-rw-r--r--engines/titanic/objects/file_item.cpp19
-rw-r--r--engines/titanic/objects/file_item.h32
-rw-r--r--engines/titanic/objects/game_object.cpp27
-rw-r--r--engines/titanic/objects/game_object.h35
-rw-r--r--engines/titanic/objects/list.cpp62
-rw-r--r--engines/titanic/objects/list.h86
-rw-r--r--engines/titanic/objects/message_target.cpp10
-rw-r--r--engines/titanic/objects/message_target.h16
-rw-r--r--engines/titanic/objects/named_item.cpp28
-rw-r--r--engines/titanic/objects/named_item.h35
-rw-r--r--engines/titanic/objects/pet_control.cpp31
-rw-r--r--engines/titanic/objects/pet_control.h40
-rw-r--r--engines/titanic/objects/project_item.cpp124
-rw-r--r--engines/titanic/objects/project_item.h67
-rw-r--r--engines/titanic/objects/saveable_object.cpp8
-rw-r--r--engines/titanic/objects/tree_item.cpp68
-rw-r--r--engines/titanic/objects/tree_item.h38
22 files changed, 728 insertions, 106 deletions
diff --git a/engines/titanic/game_manager.cpp b/engines/titanic/game_manager.cpp
index d29180ff6b..5e6496218f 100644
--- a/engines/titanic/game_manager.cpp
+++ b/engines/titanic/game_manager.cpp
@@ -30,4 +30,12 @@ CGameManager::CGameManager(CProjectItem *project, CGameView *gameView):
// TODO
}
+void CGameManager::load(SimpleFile *file) {
+ // TODO
+}
+
+void CGameManager::gameLoaded() {
+ // TODO
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/game_manager.h b/engines/titanic/game_manager.h
index 0c1374e9a3..d776c00048 100644
--- a/engines/titanic/game_manager.h
+++ b/engines/titanic/game_manager.h
@@ -24,6 +24,7 @@
#define TITANIC_GAME_MANAGER_H
#include "common/scummsys.h"
+#include "titanic/simple_file.h"
namespace Titanic {
@@ -36,6 +37,16 @@ private:
CGameView *_gameView;
public:
CGameManager(CProjectItem *project, CGameView *gameView);
+
+ /**
+ * Load data from a save file
+ */
+ void load(SimpleFile *file);
+
+ /**
+ * Called after loading a game has finished
+ */
+ void gameLoaded();
};
} // End of namespace Titanic
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk
index fc855d2df0..6d1e5461f5 100644
--- a/engines/titanic/module.mk
+++ b/engines/titanic/module.mk
@@ -15,9 +15,13 @@ MODULE_OBJS := \
string.o \
titanic.o \
video_surface.o \
+ objects/dont_save_file_item.o \
objects/file_item.o \
+ objects/game_object.o \
objects/list.o \
objects/message_target.o \
+ objects/named_item.o \
+ objects/pet_control.o \
objects/project_item.o \
objects/saveable_object.o \
objects/tree_item.o
diff --git a/engines/titanic/objects/dont_save_file_item.cpp b/engines/titanic/objects/dont_save_file_item.cpp
new file mode 100644
index 0000000000..bca66da521
--- /dev/null
+++ b/engines/titanic/objects/dont_save_file_item.cpp
@@ -0,0 +1,35 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "titanic/objects/dont_save_file_item.h"
+
+namespace Titanic {
+
+void CDontSaveFileItem::save(SimpleFile *file, int indent) const {
+ file->writeNumberLine(0, indent);
+}
+
+void CDontSaveFileItem::load(SimpleFile *file) {
+ file->readNumber();
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/objects/dont_save_file_item.h b/engines/titanic/objects/dont_save_file_item.h
new file mode 100644
index 0000000000..99deacc88c
--- /dev/null
+++ b/engines/titanic/objects/dont_save_file_item.h
@@ -0,0 +1,50 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_DONT_SAVE_FILE_ITEM_H
+#define TITANIC_DONT_SAVE_FILE_ITEM_H
+
+#include "titanic/objects/file_item.h"
+
+namespace Titanic {
+
+class CDontSaveFileItem : public CFileItem {
+public:
+ /**
+ * Return the class name
+ */
+ virtual const char *getClassName() const { return "CDontSaveFileItem"; }
+
+ /**
+ * Save the data for the class to file
+ */
+ virtual void save(SimpleFile *file, int indent) const;
+
+ /**
+ * Load the data for the class from file
+ */
+ virtual void load(SimpleFile *file);
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_DONT_SAVE_FILE_ITEM_H */
diff --git a/engines/titanic/objects/file_item.cpp b/engines/titanic/objects/file_item.cpp
index d49df71fcc..925fc4d000 100644
--- a/engines/titanic/objects/file_item.cpp
+++ b/engines/titanic/objects/file_item.cpp
@@ -24,5 +24,24 @@
namespace Titanic {
+void CFileItem::save(SimpleFile *file, int indent) const {
+ file->writeNumberLine(0, indent);
+ CTreeItem::save(file, indent);
+}
+
+void CFileItem::load(SimpleFile *file) {
+ file->readNumber();
+
+ CTreeItem::load(file);
+}
+
+CString CFileItem::formFilename() const {
+ return "";
+}
+
+CString CFileItem::getFilename() const {
+ //dynamic_cast<CFileItem *>(getRoot())->formDataPath();
+ return _filename;
+}
} // End of namespace Titanic
diff --git a/engines/titanic/objects/file_item.h b/engines/titanic/objects/file_item.h
index 2261598ea8..94dd053ae8 100644
--- a/engines/titanic/objects/file_item.h
+++ b/engines/titanic/objects/file_item.h
@@ -23,13 +23,45 @@
#ifndef TITANIC_FILE_ITEM_H
#define TITANIC_FILE_ITEM_H
+#include "titanic/string.h"
#include "titanic/objects/list.h"
#include "titanic/objects/tree_item.h"
namespace Titanic {
class CFileItem: public CTreeItem {
+private:
+ CString _filename;
public:
+ /**
+ * Return the class name
+ */
+ virtual const char *getClassName() const { return "CFileItem"; }
+
+ /**
+ * Save the data for the class to file
+ */
+ virtual void save(SimpleFile *file, int indent) const;
+
+ /**
+ * Load the data for the class from file
+ */
+ virtual void load(SimpleFile *file);
+
+ /**
+ * Returns true if the item is a file item
+ */
+ virtual bool isFileItem() const { return true; }
+
+ /**
+ * Form a filename for the file item
+ */
+ CString formFilename() const;
+
+ /**
+ * Get a string?
+ */
+ CString getFilename() const;
};
} // End of namespace Titanic
diff --git a/engines/titanic/objects/game_object.cpp b/engines/titanic/objects/game_object.cpp
new file mode 100644
index 0000000000..a1e1faccce
--- /dev/null
+++ b/engines/titanic/objects/game_object.cpp
@@ -0,0 +1,27 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "titanic/objects/game_object.h"
+
+namespace Titanic {
+
+} // End of namespace Titanic
diff --git a/engines/titanic/objects/game_object.h b/engines/titanic/objects/game_object.h
new file mode 100644
index 0000000000..7e0fba6e87
--- /dev/null
+++ b/engines/titanic/objects/game_object.h
@@ -0,0 +1,35 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_GAME_OBJECT_H
+#define TITANIC_GAME_OBJECT_H
+
+#include "titanic/objects/named_item.h"
+
+namespace Titanic {
+
+class CGameObject : public CNamedItem {
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_PET_CONTROL_H */
diff --git a/engines/titanic/objects/list.cpp b/engines/titanic/objects/list.cpp
index 1ebffac51b..4e0178d31c 100644
--- a/engines/titanic/objects/list.cpp
+++ b/engines/titanic/objects/list.cpp
@@ -25,73 +25,11 @@
namespace Titanic {
void ListItem::save(SimpleFile *file, int indent) const {
- // Should always be overriden in descendents, so just write a dummy value
file->writeNumberLine(0, indent);
}
void ListItem::load(SimpleFile *file) {
- // Should always be overriden in descendents, so just read the dummy value
file->readNumber();
}
-/*------------------------------------------------------------------------*/
-
-List::List() {
-}
-
-void List::save(SimpleFile *file, int indent) const {
- file->writeNumberLine(0, indent);
- saveItems(file, indent);
-}
-
-void List::load(SimpleFile *file) {
- file->readNumber();
- loadItems(file);
-}
-
-void List::saveItems(SimpleFile *file, int indent) const {
- // Write out number of items
- file->writeQuotedLine("L", indent);
- file->writeNumberLine(size(), indent);
-
- // Iterate through writing entries
- List::const_iterator i;
- for (i = begin(); i != end(); ++i) {
- const ListItem *item = *i;
- item->saveHeader(file, indent);
- item->save(file, indent + 1);
- item->saveFooter(file, indent);
- }
-}
-
-void List::loadItems(SimpleFile *file) {
- file->readBuffer();
- uint count = file->readNumber();
-
- for (uint idx = 0; idx < count; ++idx) {
- // Validate the class start header
- if (!file->IsClassStart())
- error("Unexpected class end");
-
- // Get item's class name and use it to instantiate an item
- CString className = file->readString();
- CSaveableObject *newItem = CSaveableObject::createInstance(className);
- if (!newItem)
- error("Could not create instance of %s", className.c_str());
-
- // Validate the class end footer
- if (file->IsClassStart())
- error("Unexpected class start");
- }
-}
-
-void List::destroyContents() {
- for (iterator i = begin(); i != end(); ++i) {
- CSaveableObject *obj = *i;
- delete obj;
- }
-
- clear();
-}
-
} // End of namespace Titanic
diff --git a/engines/titanic/objects/list.h b/engines/titanic/objects/list.h
index ceb471534d..1842d2b5f8 100644
--- a/engines/titanic/objects/list.h
+++ b/engines/titanic/objects/list.h
@@ -25,10 +25,14 @@
#include "common/scummsys.h"
#include "common/list.h"
+#include "titanic/simple_file.h"
#include "titanic/objects/saveable_object.h"
namespace Titanic {
+/**
+ * Base list item class
+ */
class ListItem: public CSaveableObject {
public:
/**
@@ -47,39 +51,87 @@ public:
virtual void load(SimpleFile *file);
};
-class List : public CSaveableObject, Common::List<ListItem *> {
-private:
- /**
- * Write out the contents of the list
- */
- void saveItems(SimpleFile *file, int indent) const;
-
- /**
- * Read in the contents of a list
- */
- void loadItems(SimpleFile *file);
+template<typename T>
+class List : public CSaveableObject, public Common::List<T *> {
public:
- List();
-
/**
* Return the class name
*/
- virtual const char *getClassName() const { return "List"; }
+ virtual const char *getClassName() const { return nullptr; }
/**
* Save the data for the class to file
*/
- virtual void save(SimpleFile *file, int indent) const;
+ virtual void save(SimpleFile *file, int indent) const {
+ file->writeNumberLine(0, indent);
+
+ // Write out number of items
+ file->writeQuotedLine("L", indent);
+ file->writeNumberLine(Common::List<T *>::size(), indent);
+
+ // Iterate through writing entries
+ Common::List<T *>::const_iterator i;
+ for (i = Common::List<T *>::begin(); i != Common::List<T *>::end(); ++i) {
+ const ListItem *item = *i;
+ item->saveHeader(file, indent);
+ item->save(file, indent + 1);
+ item->saveFooter(file, indent);
+ }
+
+ }
/**
* Load the data for the class from file
*/
- virtual void load(SimpleFile *file);
+ virtual void load(SimpleFile *file) {
+ file->readNumber();
+ file->readBuffer();
+
+ Common::List<T *>::clear();
+ uint count = file->readNumber();
+
+ for (uint idx = 0; idx < count; ++idx) {
+ // Validate the class start header
+ if (!file->IsClassStart())
+ error("Unexpected class end");
+
+ // Get item's class name and use it to instantiate an item
+ CString className = file->readString();
+ T *newItem = dynamic_cast<T *>(CSaveableObject::createInstance(className));
+ if (!newItem)
+ error("Could not create instance of %s", className.c_str());
+
+ // Load the item's data and add it to the list
+ newItem->load(file);
+ Common::List<T *>::push_back(newItem);
+
+ // Validate the class end footer
+ if (file->IsClassStart())
+ error("Unexpected class start");
+ }
+ }
/**
* Clear the list and destroy any items in it
*/
- void destroyContents();
+ void destroyContents() {
+ for (Common::List<T *>::iterator i = Common::List<T *>::begin();
+ i != Common::List<T *>::end(); ++i) {
+ CSaveableObject *obj = *i;
+ delete obj;
+ }
+
+ Common::List<T *>::clear();
+ }
+
+ /**
+ * Add a new item to the list of the type the list contains
+ */
+ T *List::add() {
+ T *item = new T();
+ Common::List<T *>::push_back(item);
+ return item;
+ }
};
} // End of namespace Titanic
diff --git a/engines/titanic/objects/message_target.cpp b/engines/titanic/objects/message_target.cpp
index 1e727a3686..bd162ff9eb 100644
--- a/engines/titanic/objects/message_target.cpp
+++ b/engines/titanic/objects/message_target.cpp
@@ -23,5 +23,15 @@
#include "titanic/objects/message_target.h"
namespace Titanic {
+
+void CMessageTarget::save(SimpleFile *file, int indent) const {
+ file->writeNumberLine(0, indent);
+ CSaveableObject::save(file, indent);
+}
+
+void CMessageTarget::load(SimpleFile *file) {
+ file->readNumber();
+ CSaveableObject::load(file);
+}
} // End of namespace Titanic
diff --git a/engines/titanic/objects/message_target.h b/engines/titanic/objects/message_target.h
index 6afd709211..5e29ddaf78 100644
--- a/engines/titanic/objects/message_target.h
+++ b/engines/titanic/objects/message_target.h
@@ -28,6 +28,22 @@
namespace Titanic {
class CMessageTarget: public CSaveableObject {
+public:
+ /**
+ * Return the class name
+ */
+ virtual const char *getClassName() const { return "CMessageTarget"; }
+
+ /**
+ * Save the data for the class to file
+ */
+ virtual void save(SimpleFile *file, int indent) const;
+
+ /**
+ * Load the data for the class from file
+ */
+ virtual void load(SimpleFile *file);
+
};
} // End of namespace Titanic
diff --git a/engines/titanic/objects/named_item.cpp b/engines/titanic/objects/named_item.cpp
new file mode 100644
index 0000000000..34db645590
--- /dev/null
+++ b/engines/titanic/objects/named_item.cpp
@@ -0,0 +1,28 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "titanic/objects/named_item.h"
+
+namespace Titanic {
+
+
+} // End of namespace Titanic
diff --git a/engines/titanic/objects/named_item.h b/engines/titanic/objects/named_item.h
new file mode 100644
index 0000000000..ee4ad352ed
--- /dev/null
+++ b/engines/titanic/objects/named_item.h
@@ -0,0 +1,35 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_NAMED_ITEM_H
+#define TITANIC_NAMED_ITEM_H
+
+#include "titanic/objects/tree_item.h"
+
+namespace Titanic {
+
+class CNamedItem: public CTreeItem {
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_NAMED_ITEM_H */
diff --git a/engines/titanic/objects/pet_control.cpp b/engines/titanic/objects/pet_control.cpp
new file mode 100644
index 0000000000..73ef957e78
--- /dev/null
+++ b/engines/titanic/objects/pet_control.cpp
@@ -0,0 +1,31 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "titanic/objects/pet_control.h"
+
+namespace Titanic {
+
+void CPetControl::gameLoaded() {
+ // TODO
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/objects/pet_control.h b/engines/titanic/objects/pet_control.h
new file mode 100644
index 0000000000..f6c9707df8
--- /dev/null
+++ b/engines/titanic/objects/pet_control.h
@@ -0,0 +1,40 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_PET_CONTROL_H
+#define TITANIC_PET_CONTROL_H
+
+#include "titanic/objects/game_object.h"
+
+namespace Titanic {
+
+class CPetControl : public CGameObject {
+public:
+ /**
+ * Called after loading a game has finished
+ */
+ void gameLoaded();
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_PET_CONTROL_H */
diff --git a/engines/titanic/objects/project_item.cpp b/engines/titanic/objects/project_item.cpp
index 8211854407..2bd75156d8 100644
--- a/engines/titanic/objects/project_item.cpp
+++ b/engines/titanic/objects/project_item.cpp
@@ -21,50 +21,89 @@
*/
#include "common/savefile.h"
+#include "titanic/game_manager.h"
#include "titanic/titanic.h"
#include "titanic/compressed_file.h"
+#include "titanic/objects/dont_save_file_item.h"
+#include "titanic/objects/pet_control.h"
#include "titanic/objects/project_item.h"
namespace Titanic {
-CProjectItem::CProjectItem() : _field34(0), _field38(0), _field3C(0) {
+void CFileListItem::save(SimpleFile *file, int indent) const {
+ file->writeNumberLine(0, indent);
+ file->writeQuotedLine(_name, indent);
+
+ ListItem::save(file, indent);
+}
+
+void CFileListItem::load(SimpleFile *file) {
+ file->readNumber();
+ _name = file->readString();
+
+ ListItem::load(file);
+}
+
+/*------------------------------------------------------------------------*/
+
+CProjectItem::CProjectItem() : _nextRoomNumber(0), _nextMessageNumber(0),
+ _nextObjectNumber(0), _gameManager(nullptr) {
}
void CProjectItem::save(SimpleFile *file, int indent) const {
file->writeNumberLine(6, indent);
+ file->writeQuotedLine("Next Avail. Object Number", indent);
+ file->writeNumberLine(_nextObjectNumber, indent);
+ file->writeQuotedLine("Next Avail. Message Number", indent);
+ file->writeNumberLine(_nextMessageNumber, indent);
+ file->writeQuotedLine("Next Avail. Room Number", indent);
+ file->writeNumberLine(_nextRoomNumber, indent);
+
+ CTreeItem::save(file, indent);
+}
+
+void CProjectItem::buildFilesList() {
+ _files.destroyContents();
+ CTreeItem *treeItem = getFirstChild();
+ while (treeItem) {
+ if (treeItem->isFileItem()) {
+ CString name = static_cast<CFileItem *>(treeItem)->getFilename();
+ _files.add()->_name = name;
+ }
+
+ treeItem = getNextSibling();
+ }
}
void CProjectItem::load(SimpleFile *file) {
int val = file->readNumber();
- load2(file, val);
-}
-
-void CProjectItem::load2(SimpleFile *file, int val) {
+ _files.destroyContents();
int count;
- _items.destroyContents();
switch (val) {
case 1:
file->readBuffer();
- _field34 = file->readNumber();
+ _nextRoomNumber = file->readNumber();
// Deliberate fall-through
case 0:
+ // Load the list of files
count = file->readNumber();
for (int idx = 0; idx < count; ++idx) {
-
+ CString name = file->readString();
+ _files.add()->_name = name;
}
break;
case 6:
file->readBuffer();
- _field3C = file->readNumber();
+ _nextObjectNumber = file->readNumber();
// Deliberate fall-through
case 5:
file->readBuffer();
- _field38 = file->readNumber();
+ _nextMessageNumber = file->readNumber();
// Deliberate fall-through
case 4:
@@ -73,9 +112,9 @@ void CProjectItem::load2(SimpleFile *file, int val) {
case 2:
case 3:
- _items.load(file);
+ _files.load(file);
file->readBuffer();
- _field34 = file->readNumber();
+ _nextRoomNumber = file->readNumber();
break;
default:
@@ -85,6 +124,14 @@ void CProjectItem::load2(SimpleFile *file, int val) {
CTreeItem::load(file);
}
+CGameManager *CProjectItem::getGameManager() {
+ return _gameManager;
+}
+
+void CProjectItem::resetGameManager() {
+ _gameManager = nullptr;
+}
+
void CProjectItem::loadGame(int slotId) {
CompressedFile file;
Common::InSaveFile *saveFile = nullptr;
@@ -102,9 +149,27 @@ void CProjectItem::loadGame(int slotId) {
}
// Load the contents in
- loadData(&file);
+ CProjectItem *newProject = loadData(&file);
+ file.IsClassStart();
+ getGameManager()->load(&file);
file.close();
+
+ // Clear existing project
+ clear();
+
+ // Detach each item under the loaded project, and re-attach them
+ // to the existing project instance (this)
+ CTreeItem *item;
+ while ((item = newProject->getFirstChild()) != nullptr) {
+ item->detach();
+ item->addUnder(this);
+ }
+ // Loaded project instance is no longer needed
+ newProject->destroyAll();
+
+ // Post-load processing
+ gameLoaded();
}
void CProjectItem::saveGame(int slotId) {
@@ -120,7 +185,9 @@ void CProjectItem::saveGame(int slotId) {
}
void CProjectItem::clear() {
-
+ CTreeItem *item;
+ while ((item = getFirstChild()) != nullptr)
+ item->destroyAll();
}
CProjectItem *CProjectItem::loadData(SimpleFile *file) {
@@ -156,7 +223,6 @@ CProjectItem *CProjectItem::loadData(SimpleFile *file) {
// Already created root project
item->addUnder(parent);
} else {
- // TODO: Validate this is correct
root = dynamic_cast<CProjectItem *>(item);
assert(root);
root->_filename = _filename;
@@ -197,4 +263,32 @@ void CProjectItem::saveData(SimpleFile *file, CTreeItem *item) const {
}
}
+void CProjectItem::gameLoaded() {
+ CGameManager *gameManager = getGameManager();
+ if (gameManager)
+ gameManager->gameLoaded();
+
+ CPetControl *petControl = getPetControl();
+ if (petControl)
+ petControl->gameLoaded();
+}
+
+CPetControl *CProjectItem::getPetControl() {
+ CDontSaveFileItem *fileItem = getDontSaveFileItem();
+ CTreeItem *treeItem;
+
+ if (!fileItem || (treeItem = fileItem->getLastChild()) == nullptr)
+ return nullptr;
+
+ while (treeItem) {
+ CPetControl *petControl = dynamic_cast<CPetControl *>(treeItem);
+ if (petControl)
+ return petControl;
+
+ treeItem = treeItem->getPriorSibling();
+ }
+
+ return nullptr;
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/objects/project_item.h b/engines/titanic/objects/project_item.h
index d769f3dd0f..066dbf69e0 100644
--- a/engines/titanic/objects/project_item.h
+++ b/engines/titanic/objects/project_item.h
@@ -26,21 +26,56 @@
#include "common/scummsys.h"
#include "titanic/simple_file.h"
#include "titanic/objects/file_item.h"
+#include "titanic/objects/list.h"
namespace Titanic {
+class CGameManager;
+class CPetControl;
+
+/**
+ * File list item
+ */
+class CFileListItem : public ListItem {
+public:
+ CString _name;
+
+ virtual const char *getClassName() const { return "CFileListItem"; }
+
+ /**
+ * Save the data for the class to file
+ */
+ virtual void save(SimpleFile *file, int indent) const;
+
+ /**
+ * Load the data for the class from file
+ */
+ virtual void load(SimpleFile *file);
+
+};
+
+/**
+ * Filename list
+ */
+class CFileList: public List<CFileListItem> {
+public:
+ virtual const char *getClassName() const { return "CFileList"; }
+};
+
+
class CProjectItem : public CFileItem {
private:
CString _filename;
- List _items;
- int _field34;
- int _field38;
- int _field3C;
+ CFileList _files;
+ int _nextRoomNumber;
+ int _nextMessageNumber;
+ int _nextObjectNumber;
+ CGameManager *_gameManager;
/**
- * Load data for the project
+ * Called during save, iterates through the children to do some stuff
*/
- void load2(SimpleFile *file, int val);
+ void buildFilesList();
private:
/**
* Load project data from the passed file
@@ -51,6 +86,11 @@ private:
* Save project data to the passed file
*/
void saveData(SimpleFile *file, CTreeItem *item) const;
+
+ /**
+ * Does post-loading processing
+ */
+ void gameLoaded();
public:
CProjectItem();
@@ -70,6 +110,21 @@ public:
virtual void load(SimpleFile *file);
/**
+ * Get the game manager for the project
+ */
+ virtual CGameManager *getGameManager();
+
+ /**
+ * Get a reference to the PET control
+ */
+ CPetControl *getPetControl();
+
+ /**
+ * Resets the game manager field
+ */
+ void resetGameManager();
+
+ /**
* Load the entire project data for a given slot Id
*/
void loadGame(int slotId);
diff --git a/engines/titanic/objects/saveable_object.cpp b/engines/titanic/objects/saveable_object.cpp
index 201fe1085e..45f9e132d9 100644
--- a/engines/titanic/objects/saveable_object.cpp
+++ b/engines/titanic/objects/saveable_object.cpp
@@ -35,8 +35,7 @@ Common::HashMap<Common::String, CSaveableObject::CreateFunction> *
#define DEFFN(T) CSaveableObject *Function##T() { return new T(); }
#define ADDFN(T) (*_classList)[#T] = Function##T
-DEFFN(List);
-DEFFN(ListItem);
+DEFFN(CFileListItem);
DEFFN(CMessageTarget);
DEFFN(CTreeItem);
DEFFN(CFileItem);
@@ -44,8 +43,7 @@ DEFFN(CProjectItem);
void CSaveableObject::initClassList() {
_classList = new Common::HashMap<Common::String, CreateFunction>();
- ADDFN(List);
- ADDFN(ListItem);
+ ADDFN(CFileListItem);
ADDFN(CMessageTarget);
ADDFN(CTreeItem);
ADDFN(CFileItem);
@@ -61,12 +59,10 @@ CSaveableObject *CSaveableObject::createInstance(const Common::String &name) {
}
void CSaveableObject::save(SimpleFile *file, int indent) const {
- // Should always be overriden in descendents, so just write a dummy value
file->writeNumberLine(0, indent);
}
void CSaveableObject::load(SimpleFile *file) {
- // Should always be overriden in descendents, so just read the dummy value
file->readNumber();
}
diff --git a/engines/titanic/objects/tree_item.cpp b/engines/titanic/objects/tree_item.cpp
index bf0ae3e735..3902df3d3a 100644
--- a/engines/titanic/objects/tree_item.cpp
+++ b/engines/titanic/objects/tree_item.cpp
@@ -21,6 +21,8 @@
*/
#include "titanic/objects/tree_item.h"
+#include "titanic/objects/dont_save_file_item.h"
+#include "titanic/objects/file_item.h"
namespace Titanic {
@@ -38,6 +40,22 @@ void CTreeItem::load(SimpleFile *file) {
CMessageTarget::load(file);
}
+CGameManager *CTreeItem::getGameManager() {
+ return _parent ? _parent->getGameManager() : nullptr;
+}
+
+CTreeItem *CTreeItem::getRoot() const {
+ CTreeItem *parent = getParent();
+
+ if (parent) {
+ do {
+ parent = parent->getParent();
+ } while (parent->getParent());
+ }
+
+ return parent;
+}
+
CTreeItem *CTreeItem::getLastSibling() {
CTreeItem *item = this;
while (item->getNextSibling())
@@ -52,6 +70,17 @@ CTreeItem *CTreeItem::getLastChild() {
return _firstChild->getLastSibling();
}
+CDontSaveFileItem *CTreeItem::getDontSaveFileItem() {
+ CTreeItem *item = getFirstChild();
+ while (item) {
+ CDontSaveFileItem *fileItem = dynamic_cast<CDontSaveFileItem *>(item);
+ if (fileItem)
+ return fileItem;
+
+ item = item->getNextSibling();
+ }
+}
+
void CTreeItem::addUnder(CTreeItem *newParent) {
if (newParent->_firstChild)
addSibling(newParent->getLastSibling());
@@ -79,5 +108,44 @@ void CTreeItem::addSibling(CTreeItem *item) {
item->_nextSibling = this;
}
+void CTreeItem::destroyAll() {
+ destroyOthers();
+ detach();
+ delete this;
+}
+
+int CTreeItem::destroyOthers() {
+ if (!_firstChild)
+ return 0;
+
+ CTreeItem *item = this, *child, *nextSibling;
+ int total = 0;
+
+ do {
+ child = item->_firstChild;
+ nextSibling = item->_nextSibling;
+
+ if (child)
+ total += child->destroyOthers();
+ child->detach();
+ delete child;
+ ++total;
+ } while ((item = nextSibling) != nullptr);
+
+ return total;
+}
+
+void CTreeItem::detach() {
+ // Delink this item from any prior and/or next siblings
+ if (_priorSibling)
+ _priorSibling->_nextSibling = _nextSibling;
+ if (_nextSibling)
+ _nextSibling->_priorSibling = _priorSibling;
+
+ if (_parent && _parent->_firstChild == this)
+ _parent->_firstChild = _nextSibling;
+
+ _priorSibling = _nextSibling = _parent = nullptr;
+}
} // End of namespace Titanic
diff --git a/engines/titanic/objects/tree_item.h b/engines/titanic/objects/tree_item.h
index d3c1d34911..d6450e313a 100644
--- a/engines/titanic/objects/tree_item.h
+++ b/engines/titanic/objects/tree_item.h
@@ -27,6 +27,9 @@
namespace Titanic {
+class CGameManager;
+class CDontSaveFileItem;
+
class CTreeItem: public CMessageTarget {
private:
CTreeItem *_parent;
@@ -53,11 +56,26 @@ public:
virtual void load(SimpleFile *file);
/**
+ * Get the game manager for the project
+ */
+ virtual CGameManager *getGameManager();
+
+ /**
+ * Returns true if the item is a file item
+ */
+ virtual bool isFileItem() const { return false; }
+
+ /**
* Get the parent for the given item
*/
CTreeItem *getParent() const { return _parent; }
/**
+ * Jumps up through the parents to find the sub-root item
+ */
+ CTreeItem *getRoot() const;
+
+ /**
* Get the next sibling
*/
CTreeItem *getNextSibling() { return _nextSibling; }
@@ -83,6 +101,11 @@ public:
CTreeItem *getLastChild();
/**
+ * Get any dont save file item in the immediate children
+ */
+ CDontSaveFileItem *getDontSaveFileItem();
+
+ /**
* Adds the item under another tree item
*/
void addUnder(CTreeItem *newParent);
@@ -96,6 +119,21 @@ public:
* Adds the item as a sibling of another item
*/
void addSibling(CTreeItem *item);
+
+ /**
+ * Destroys both the item as well as any of it's children
+ */
+ void destroyAll();
+
+ /**
+ * Destroys all tree items around the given one
+ */
+ int destroyOthers();
+
+ /**
+ * Detach the tree item from any other associated tree items
+ */
+ void detach();
};
} // End of namespace Titanic