aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-03-13 15:07:27 -0400
committerPaul Gilbert2016-03-13 15:07:27 -0400
commitc92bf22f0331fbdbc7e440b43ae1973b679befb3 (patch)
treed51ee3848bb6606cf8a99421d257ad0bca641828
parentf0d992d8548ee8bacae72ecc15e69f9de4187549 (diff)
downloadscummvm-rg350-c92bf22f0331fbdbc7e440b43ae1973b679befb3.tar.gz
scummvm-rg350-c92bf22f0331fbdbc7e440b43ae1973b679befb3.tar.bz2
scummvm-rg350-c92bf22f0331fbdbc7e440b43ae1973b679befb3.zip
TITANIC: Changed CGameStateSub to CGameLocation, properly implemented it
-rw-r--r--engines/titanic/core/named_item.cpp22
-rw-r--r--engines/titanic/core/named_item.h18
-rw-r--r--engines/titanic/core/project_item.h2
-rw-r--r--engines/titanic/core/room_item.cpp (renamed from engines/titanic/game/room_item.cpp)2
-rw-r--r--engines/titanic/core/room_item.h (renamed from engines/titanic/game/room_item.h)0
-rw-r--r--engines/titanic/core/saveable_object.cpp6
-rw-r--r--engines/titanic/core/tree_item.cpp2
-rw-r--r--engines/titanic/game_location.cpp94
-rw-r--r--engines/titanic/game_location.h (renamed from engines/titanic/game_state_sub.h)38
-rw-r--r--engines/titanic/game_manager.cpp6
-rw-r--r--engines/titanic/game_manager.h2
-rw-r--r--engines/titanic/game_state.cpp6
-rw-r--r--engines/titanic/game_state.h4
-rw-r--r--engines/titanic/game_state_sub.cpp50
-rw-r--r--engines/titanic/game_view.cpp4
-rw-r--r--engines/titanic/game_view.h12
-rw-r--r--engines/titanic/main_game_window.cpp2
-rw-r--r--engines/titanic/main_game_window.h5
-rw-r--r--engines/titanic/module.mk4
19 files changed, 190 insertions, 89 deletions
diff --git a/engines/titanic/core/named_item.cpp b/engines/titanic/core/named_item.cpp
index 641efbd249..cd798a297e 100644
--- a/engines/titanic/core/named_item.cpp
+++ b/engines/titanic/core/named_item.cpp
@@ -21,6 +21,8 @@
*/
#include "titanic/core/named_item.h"
+#include "titanic/core/node_item.h"
+#include "titanic/core/room_item.h"
namespace Titanic {
@@ -47,4 +49,24 @@ int CNamedItem::compareTo(const CString &name, int maxLen) const {
}
}
+CNodeItem *CNamedItem::findNode() const {
+ for (CTreeItem *parent = getParent(); parent; parent = parent->getParent()) {
+ CNodeItem *node = dynamic_cast<CNodeItem *>(parent);
+ if (node)
+ return node;
+ }
+
+ error("Couldn't find parent node");
+}
+
+CRoomItem *CNamedItem::findRoom() const {
+ for (CTreeItem *parent = getParent(); parent; parent = parent->getParent()) {
+ CRoomItem *room = dynamic_cast<CRoomItem *>(parent);
+ if (room)
+ return room;
+ }
+
+ error("Couldn't find parent node");
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/core/named_item.h b/engines/titanic/core/named_item.h
index 0afbf709c5..6e6178edd4 100644
--- a/engines/titanic/core/named_item.h
+++ b/engines/titanic/core/named_item.h
@@ -27,6 +27,9 @@
namespace Titanic {
+class CNodeItem;
+class CRoomItem;
+
class CNamedItem: public CTreeItem {
public:
CString _name;
@@ -44,11 +47,6 @@ public:
virtual void load(SimpleFile *file);
/**
- * Returns true if the item is a named item
- */
- virtual bool isNamedItem() const { return true; }
-
- /**
* Gets the name of the item, if any
*/
virtual const CString getName() const { return _name; }
@@ -57,6 +55,16 @@ public:
* Compares the name of the item to a passed name
*/
virtual int compareTo(const CString &name, int maxLen) const;
+
+ /**
+ * Find a parent node for the item
+ */
+ virtual CNodeItem *findNode() const;
+
+ /**
+ * Find a parent room item for the item
+ */
+ virtual CRoomItem *findRoom() const;
};
} // End of namespace Titanic
diff --git a/engines/titanic/core/project_item.h b/engines/titanic/core/project_item.h
index 65fe8b88bd..bb96f81245 100644
--- a/engines/titanic/core/project_item.h
+++ b/engines/titanic/core/project_item.h
@@ -28,7 +28,7 @@
#include "titanic/core/dont_save_file_item.h"
#include "titanic/core/file_item.h"
#include "titanic/core/list.h"
-#include "titanic/game/room_item.h"
+#include "titanic/core/room_item.h"
namespace Titanic {
diff --git a/engines/titanic/game/room_item.cpp b/engines/titanic/core/room_item.cpp
index 17e0ffca2d..b0cefcaf74 100644
--- a/engines/titanic/game/room_item.cpp
+++ b/engines/titanic/core/room_item.cpp
@@ -20,7 +20,7 @@
*
*/
-#include "titanic/game/room_item.h"
+#include "titanic/core/room_item.h"
namespace Titanic {
diff --git a/engines/titanic/game/room_item.h b/engines/titanic/core/room_item.h
index 2235f6a5d2..2235f6a5d2 100644
--- a/engines/titanic/game/room_item.h
+++ b/engines/titanic/core/room_item.h
diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp
index 95175ca174..449eb9a5fb 100644
--- a/engines/titanic/core/saveable_object.cpp
+++ b/engines/titanic/core/saveable_object.cpp
@@ -73,6 +73,7 @@
#include "titanic/core/multi_drop_target.h"
#include "titanic/core/node_item.h"
#include "titanic/core/project_item.h"
+#include "titanic/core/room_item.h"
#include "titanic/core/saveable_object.h"
#include "titanic/core/static_image.h"
#include "titanic/core/turn_on_object.h"
@@ -181,7 +182,6 @@
#include "titanic/game/reserved_table.h"
#include "titanic/game/restaurant_cylinder_holder.h"
#include "titanic/game/restaurant_phonograph.h"
-#include "titanic/game/room_item.h"
#include "titanic/game/sauce_dispensor.h"
#include "titanic/game/search_point.h"
#include "titanic/game/season_background.h"
@@ -479,6 +479,7 @@ DEFFN(CNamedItem)
DEFFN(CNodeItem)
DEFFN(CProjectItem)
DEFFN(CResourceKey)
+DEFFN(CRoomItem)
DEFFN(CSaveableObject)
DEFFN(CStaticImage)
DEFFN(CTurnOnObject)
@@ -587,7 +588,6 @@ DEFFN(CReplacementEar)
DEFFN(CReservedTable)
DEFFN(CRestaurantCylinderHolder)
DEFFN(CRestaurantPhonograph)
-DEFFN(CRoomItem)
DEFFN(CSauceDispensor)
DEFFN(CSearchPoint)
DEFFN(CSeasonBackground)
@@ -1044,6 +1044,7 @@ void CSaveableObject::initClassList() {
ADDFN(CNodeItem, CNamedItem);
ADDFN(CProjectItem, CFileItem);
ADDFN(CResourceKey, CSaveableObject);
+ ADDFN(CRoomItem, CNamedItem);
ADDFN(CSaveableObject, CSaveableObject);
ADDFN(CStaticImage, CGameObject);
ADDFN(CTurnOnObject, CBackground);
@@ -1153,7 +1154,6 @@ void CSaveableObject::initClassList() {
ADDFN(CReservedTable, CGameObject);
ADDFN(CRestaurantCylinderHolder, CDropTarget);
ADDFN(CRestaurantPhonograph, CPhonograph);
- ADDFN(CRoomItem, CNamedItem);
ADDFN(CSauceDispensor, CBackground);
ADDFN(CSearchPoint, CGameObject);
ADDFN(CSeasonBackground, CBackground);
diff --git a/engines/titanic/core/tree_item.cpp b/engines/titanic/core/tree_item.cpp
index 127a95071a..3599732080 100644
--- a/engines/titanic/core/tree_item.cpp
+++ b/engines/titanic/core/tree_item.cpp
@@ -29,7 +29,7 @@
#include "titanic/core/named_item.h"
#include "titanic/core/node_item.h"
#include "titanic/core/view_item.h"
-#include "titanic/game/room_item.h"
+#include "titanic/core/room_item.h"
namespace Titanic {
diff --git a/engines/titanic/game_location.cpp b/engines/titanic/game_location.cpp
new file mode 100644
index 0000000000..cd4481ed31
--- /dev/null
+++ b/engines/titanic/game_location.cpp
@@ -0,0 +1,94 @@
+/* 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/game_location.h"
+#include "titanic/game_manager.h"
+#include "titanic/game_state.h"
+#include "titanic/core/project_item.h"
+
+namespace Titanic {
+
+#define STARTING_ROOM 3
+#define STARTING_NODE 1
+#define STARTING_VIEW 4
+
+CGameLocation::CGameLocation(CGameState *owner) : _gameState(owner),
+ _view(nullptr), _roomNumber(STARTING_ROOM),
+ _nodeNumber(STARTING_NODE), _viewNumber(STARTING_VIEW) {
+}
+
+void CGameLocation::save(SimpleFile *file) const {
+ file->writeNumber(_roomNumber);
+ file->writeNumber(_nodeNumber);
+ file->writeNumber(_viewNumber);
+}
+
+void CGameLocation::load(SimpleFile *file) {
+ _view = nullptr;
+ _roomNumber = file->readNumber();
+ _nodeNumber = file->readNumber();
+ _viewNumber = file->readNumber();
+}
+
+CViewItem *CGameLocation::getView() {
+ if (!_view) {
+ CGameManager *gm = _gameState->_gameManager;
+ _view = gm->_project->findView(_roomNumber, _nodeNumber, _viewNumber);
+
+ if (!_view) {
+ // Fallback if view not found
+ _view = gm->_project->findView(STARTING_ROOM,
+ STARTING_NODE, STARTING_VIEW);
+
+ if (!_view) {
+ // Fallback for the fallback
+ for (int idx = 0; idx < 99 && !_view; ++idx) {
+ _view = gm->_project->findView(idx, 1, 1);
+ }
+ }
+ }
+ }
+
+ if (!_view) {
+ // Okay seriously, yet another fallback if view not found
+ _viewNumber = _nodeNumber = _roomNumber = -1;
+ _view = nullptr;
+ } else {
+ _viewNumber = _view->_viewNumber;
+ _nodeNumber = getNode()->_nodeNumber;
+ _roomNumber = getRoom()->_roomNumber;
+ }
+
+ return _view;
+}
+
+CNodeItem *CGameLocation::getNode() {
+ CViewItem *view = getView();
+ return !view ? nullptr : view->findNode();
+}
+
+CRoomItem *CGameLocation::getRoom() {
+ CViewItem *view = getView();
+ return !view ? nullptr : view->findRoom();
+}
+
+} // End of namespace Titanic z
diff --git a/engines/titanic/game_state_sub.h b/engines/titanic/game_location.h
index 82917d9021..94cea799e8 100644
--- a/engines/titanic/game_state_sub.h
+++ b/engines/titanic/game_location.h
@@ -20,25 +20,28 @@
*
*/
-#ifndef TITANIC_GAME_STATE_SUB_H
-#define TITANIC_GAME_STATE_SUB_H
+#ifndef TITANIC_GAME_LOCATION_H
+#define TITANIC_GAME_LOCATION_H
#include "titanic/simple_file.h"
+#include "titanic/core/node_item.h"
+#include "titanic/core/room_item.h"
+#include "titanic/core/view_item.h"
namespace Titanic {
class CGameState;
-class CGameStateSub {
+class CGameLocation {
private:
CGameState *_gameState;
+ CViewItem *_view;
+
+ int _roomNumber;
+ int _nodeNumber;
+ int _viewNumber;
public:
- int _field0;
- int _field4;
- int _field8;
- int _fieldC;
-public:
- CGameStateSub(CGameState *owner);
+ CGameLocation(CGameState *owner);
/**
* Save the data for the class to file
@@ -50,9 +53,22 @@ public:
*/
void load(SimpleFile *file);
- int fn2();
+ /**
+ * Get the current view
+ */
+ CViewItem *getView();
+
+ /**
+ * Get the current node
+ */
+ CNodeItem *getNode();
+
+ /**
+ * Get the current room
+ */
+ CRoomItem *getRoom();
};
} // End of namespace Titanic
-#endif /* TITANIC_GAME_STATE_SUB_H */
+#endif /* TITANIC_GAME_LOCATION_H */
diff --git a/engines/titanic/game_manager.cpp b/engines/titanic/game_manager.cpp
index d8409e6864..53e7b34409 100644
--- a/engines/titanic/game_manager.cpp
+++ b/engines/titanic/game_manager.cpp
@@ -66,9 +66,9 @@ void CGameManager::postLoad(CProjectItem *project) {
_gameView->postLoad();
if (!_gameView->_fieldC) {
- int v = fn2();
- if (v)
- _gameView->proc3(v);
+ CViewItem *view = getView();
+ if (view)
+ _gameView->setView(view);
}
}
diff --git a/engines/titanic/game_manager.h b/engines/titanic/game_manager.h
index d53a611a72..394bb6777a 100644
--- a/engines/titanic/game_manager.h
+++ b/engines/titanic/game_manager.h
@@ -86,7 +86,7 @@ public:
*/
void postLoad(CProjectItem *project);
- int fn2() { return _gameState._sub.fn2(); }
+ CViewItem *getView() { return _gameState._gameLocation.getView(); }
/**
* Lock the input handler
diff --git a/engines/titanic/game_state.cpp b/engines/titanic/game_state.cpp
index 41c4388f64..b8b5ec1362 100644
--- a/engines/titanic/game_state.cpp
+++ b/engines/titanic/game_state.cpp
@@ -27,7 +27,7 @@
namespace Titanic {
CGameState::CGameState(CGameManager *gameManager) :
- _gameManager(gameManager), _sub(this),
+ _gameManager(gameManager), _gameLocation(this),
_field8(0), _fieldC(0), _mode(10), _field14(0), _field18(0),
_field1C(0), _field20(0), _field24(0), _field28(0), _field2C(0),
_field30(0), _field34(0), _field38(0) {
@@ -40,7 +40,7 @@ void CGameState::save(SimpleFile *file) const {
file->writeNumber(_field14);
file->writeNumber(_field24);
file->writeNumber(_field38);
- _sub.save(file);
+ _gameLocation.save(file);
file->writeNumber(_field1C);
}
@@ -51,7 +51,7 @@ void CGameState::load(SimpleFile *file) {
_field14 = file->readNumber();
_field24 = file->readNumber();
_field38 = file->readNumber();
- _sub.load(file);
+ _gameLocation.load(file);
_field1C = file->readNumber();
_field28 = _field2C = 0;
diff --git a/engines/titanic/game_state.h b/engines/titanic/game_state.h
index 1f93f693c8..f08216383e 100644
--- a/engines/titanic/game_state.h
+++ b/engines/titanic/game_state.h
@@ -25,7 +25,7 @@
#include "titanic/core/list.h"
#include "titanic/simple_file.h"
-#include "titanic/game_state_sub.h"
+#include "titanic/game_location.h"
namespace Titanic {
@@ -42,7 +42,7 @@ public:
class CGameState {
public:
CGameManager *_gameManager;
- CGameStateSub _sub;
+ CGameLocation _gameLocation;
CGameStateList _list;
int _field8;
int _fieldC;
diff --git a/engines/titanic/game_state_sub.cpp b/engines/titanic/game_state_sub.cpp
deleted file mode 100644
index 2e379a0edd..0000000000
--- a/engines/titanic/game_state_sub.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/* 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/game_state_sub.h"
-#include "titanic/game_state.h"
-
-namespace Titanic {
-
-CGameStateSub::CGameStateSub(CGameState *owner) : _gameState(owner),
- _field0(0), _field4(0), _field8(0), _fieldC(0) {
-}
-
-void CGameStateSub::save(SimpleFile *file) const {
- file->writeNumber(_field4);
- file->writeNumber(_field8);
- file->writeNumber(_fieldC);
-}
-
-void CGameStateSub::load(SimpleFile *file) {
- _field0 = 0;
- _field4 = file->readNumber();
- _field8 = file->readNumber();
- _fieldC = file->readNumber();
-}
-
-int CGameStateSub::fn2() {
- warning("TODO");
- return 0;
-}
-
-} // End of namespace Titanic z
diff --git a/engines/titanic/game_view.cpp b/engines/titanic/game_view.cpp
index a0542b548f..a8b8a02530 100644
--- a/engines/titanic/game_view.cpp
+++ b/engines/titanic/game_view.cpp
@@ -54,8 +54,8 @@ CSTGameView::CSTGameView(CMainGameWindow *gameWindow) :
CGameView(), _gameWindow(gameWindow) {
}
-void CSTGameView::proc3(int v) {
- _gameWindow->fn1(v);
+void CSTGameView::setView(CViewItem *view) {
+ _gameWindow->setActiveView(view);
}
void CSTGameView::proc4() {
diff --git a/engines/titanic/game_view.h b/engines/titanic/game_view.h
index 5a2c04a9c8..2e4f700ad5 100644
--- a/engines/titanic/game_view.h
+++ b/engines/titanic/game_view.h
@@ -52,7 +52,11 @@ public:
virtual void deleteView(int roomNumber, int nodeNumber, int viewNumber);
- virtual void proc3(int v) = 0;
+ /**
+ * Set the currently active view
+ */
+ virtual void setView(CViewItem *item) = 0;
+
virtual void proc4() = 0;
};
@@ -62,7 +66,11 @@ private:
public:
CSTGameView(CMainGameWindow *gameWindow);
- virtual void proc3(int v);
+ /**
+ * Set the currently active view
+ */
+ virtual void setView(CViewItem *item);
+
virtual void proc4();
};
diff --git a/engines/titanic/main_game_window.cpp b/engines/titanic/main_game_window.cpp
index 32647051d7..18f8dca984 100644
--- a/engines/titanic/main_game_window.cpp
+++ b/engines/titanic/main_game_window.cpp
@@ -80,7 +80,7 @@ int CMainGameWindow::selectSavegame() {
return -1;
}
-void CMainGameWindow::fn1(int v) {
+void CMainGameWindow::setActiveView(CViewItem *view) {
warning("TODO");
}
diff --git a/engines/titanic/main_game_window.h b/engines/titanic/main_game_window.h
index e6e724191a..ec8eff3ec6 100644
--- a/engines/titanic/main_game_window.h
+++ b/engines/titanic/main_game_window.h
@@ -69,7 +69,10 @@ public:
*/
void applicationStarting();
- void fn1(int v);
+ /**
+ * Sets the view to be shown
+ */
+ void setActiveView(CViewItem *view);
void fn2();
};
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk
index 3c82bdba99..48f6ce640b 100644
--- a/engines/titanic/module.mk
+++ b/engines/titanic/module.mk
@@ -4,9 +4,9 @@ MODULE_OBJS := \
detection.o \
direct_draw.o \
font.o \
+ game_location.o \
game_manager.o \
game_state.o \
- game_state_sub.o \
game_view.o \
image.o \
input_handler.o \
@@ -72,6 +72,7 @@ MODULE_OBJS := \
core/node_item.o \
core/project_item.o \
core/resource_key.o \
+ core/room_item.o \
core/saveable_object.o \
core/static_image.o \
core/turn_on_object.o \
@@ -180,7 +181,6 @@ MODULE_OBJS := \
game/reserved_table.o \
game/restaurant_cylinder_holder.o \
game/restaurant_phonograph.o \
- game/room_item.o \
game/sauce_dispensor.o \
game/search_point.o \
game/season_background.o \