aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohndoe1232011-07-11 08:25:24 +0000
committerWillem Jan Palenstijn2013-05-08 20:38:47 +0200
commit6d81ef0199e3213a97c4ff8856322341ac231022 (patch)
tree0d4943e65713d3c6e2a3b0260b48307a2c852bb1
parented863b65b506fac9b55b83a4afa0a30c4bb8da8a (diff)
downloadscummvm-rg350-6d81ef0199e3213a97c4ff8856322341ac231022.tar.gz
scummvm-rg350-6d81ef0199e3213a97c4ff8856322341ac231022.tar.bz2
scummvm-rg350-6d81ef0199e3213a97c4ff8856322341ac231022.zip
NEVERHOOD: Implement game vars
-rw-r--r--engines/neverhood/entity.h17
-rw-r--r--engines/neverhood/gamemodule.cpp4
-rw-r--r--engines/neverhood/gamevars.cpp105
-rw-r--r--engines/neverhood/gamevars.h57
-rw-r--r--engines/neverhood/module.mk1
-rw-r--r--engines/neverhood/module1000.cpp26
-rw-r--r--engines/neverhood/neverhood.cpp26
-rw-r--r--engines/neverhood/neverhood.h7
-rw-r--r--engines/neverhood/smackerscene.cpp6
9 files changed, 204 insertions, 45 deletions
diff --git a/engines/neverhood/entity.h b/engines/neverhood/entity.h
index c570084e56..7538b36ce2 100644
--- a/engines/neverhood/entity.h
+++ b/engines/neverhood/entity.h
@@ -24,6 +24,7 @@
#define NEVERHOOD_ENTITY_H
#include "neverhood/neverhood.h"
+#include "neverhood/gamevars.h"
#include "neverhood/graphics.h"
namespace Neverhood {
@@ -104,6 +105,22 @@ public:
return sendMessage(messageNum, MessageParam((Entity*)param), sender);
}
int getPriority() const { return _priority; }
+ // Shortcuts for game variable access
+ uint32 getGlobalVar(uint32 nameHash) {
+ return _vm->_gameVars->getGlobalVar(nameHash);
+ }
+ void setGlobalVar(uint32 nameHash, uint32 value) {
+ _vm->_gameVars->setGlobalVar(nameHash, value);
+ }
+ uint32 getSubVar(uint32 nameHash, uint32 subNameHash) {
+ return _vm->_gameVars->getSubVar(nameHash, subNameHash);
+ }
+ void setSubVar(uint32 nameHash, uint32 subNameHash, uint32 value) {
+ _vm->_gameVars->setSubVar(nameHash, subNameHash, value);
+ }
+ void incGlobalVar(uint32 nameHash, int incrValue) {
+ setGlobalVar(nameHash, getGlobalVar(nameHash) + incrValue);
+ }
protected:
void (Entity::*_updateHandlerCb)();
uint32 (Entity::*_messageHandlerCb)(int messageNum, const MessageParam &param, Entity *sender);
diff --git a/engines/neverhood/gamemodule.cpp b/engines/neverhood/gamemodule.cpp
index 47fff17cda..9989bba727 100644
--- a/engines/neverhood/gamemodule.cpp
+++ b/engines/neverhood/gamemodule.cpp
@@ -103,7 +103,7 @@ void GameModule::startup() {
void GameModule::createModule1500(int which) {
_someFlag1 = false;
- _vm->setGlobalVar(0x91080831, 0x00F10114);
+ setGlobalVar(0x91080831, 0x00F10114);
_childObject = new Module1500(_vm, this, which, true);
SetUpdateHandler(&GameModule::updateModule1500);
}
@@ -122,7 +122,7 @@ void GameModule::updateModule1500() {
}
void GameModule::createModule1000(int which) {
- _vm->setGlobalVar(0x91080831, 0x03294419);
+ setGlobalVar(0x91080831, 0x03294419);
_childObject = new Module1000(_vm, this, which);
SetUpdateHandler(&GameModule::updateModule1000);
}
diff --git a/engines/neverhood/gamevars.cpp b/engines/neverhood/gamevars.cpp
new file mode 100644
index 0000000000..98ae709cfd
--- /dev/null
+++ b/engines/neverhood/gamevars.cpp
@@ -0,0 +1,105 @@
+/* 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 "neverhood/gamevars.h"
+
+namespace Neverhood {
+
+GameVars::GameVars() {
+ addVar(0, 0);
+}
+
+GameVars::~GameVars() {
+}
+
+uint32 GameVars::getGlobalVar(uint32 nameHash) {
+ debug("GameVars::getGlobalVar(%08X)", nameHash);
+ int16 varIndex = findSubVarIndex(0, nameHash);
+ return varIndex != -1 ? _vars[varIndex].value : 0;
+}
+
+void GameVars::setGlobalVar(uint32 nameHash, uint32 value) {
+ debug("GameVars::setGlobalVar(%08X, %d)", nameHash, value);
+ _vars[getSubVarIndex(0, nameHash)].value = value;
+}
+
+uint32 GameVars::getSubVar(uint32 nameHash, uint32 subNameHash) {
+ debug("GameVars::getSubVar(%08X, %08X)", nameHash, subNameHash);
+ uint32 value = 0;
+ int16 varIndex = findSubVarIndex(0, nameHash);
+ if (varIndex != -1) {
+ int16 subVarIndex = findSubVarIndex(varIndex, subNameHash);
+ if (subVarIndex != -1) {
+ value = _vars[subVarIndex].value;
+ }
+ }
+ return value;
+}
+
+void GameVars::setSubVar(uint32 nameHash, uint32 subNameHash, uint32 value) {
+ debug("GameVars::setSubVar(%08X, %08X, %d)", nameHash, subNameHash, value);
+ _vars[getSubVarIndex(getSubVarIndex(0, nameHash), subNameHash)].value = value;
+}
+
+int16 GameVars::addVar(uint32 nameHash, uint32 value) {
+ debug("GameVars::addVar(%08X, %d)", nameHash, value);
+ GameVar gameVar;
+ gameVar.nameHash = nameHash;
+ gameVar.value = value;
+ gameVar.firstIndex = -1;
+ gameVar.nextIndex = -1;
+ _vars.push_back(gameVar);
+ return _vars.size() - 1;
+}
+
+int16 GameVars::findSubVarIndex(int16 varIndex, uint32 subNameHash) {
+ debug("GameVars::findSubVarIndex(%d, %08X)", varIndex, subNameHash);
+ for (int16 nextIndex = _vars[varIndex].firstIndex; nextIndex != -1; nextIndex = _vars[nextIndex].nextIndex) {
+ if (_vars[nextIndex].nameHash == subNameHash)
+ return nextIndex;
+ }
+ return -1;
+}
+
+int16 GameVars::addSubVar(int16 varIndex, uint32 subNameHash, uint32 value) {
+ debug("GameVars::addSubVar(%d, %08X, %d)", varIndex, subNameHash, value);
+ int16 nextIndex = _vars[varIndex].firstIndex;
+ if (nextIndex == -1) {
+ _vars[varIndex].firstIndex = addVar(subNameHash, value);
+ return _vars[varIndex].firstIndex;
+ } else {
+ while (_vars[nextIndex].nextIndex != -1)
+ nextIndex = _vars[nextIndex].nextIndex;
+ _vars[nextIndex].nextIndex = addVar(subNameHash, value);
+ return _vars[nextIndex].nextIndex;
+ }
+}
+
+int16 GameVars::getSubVarIndex(int16 varIndex, uint32 subNameHash) {
+ debug("GameVars::getSubVarIndex(%d, %08X)", varIndex, subNameHash);
+ int16 subVarIndex = findSubVarIndex(varIndex, subNameHash);
+ if (subVarIndex == -1)
+ subVarIndex = addSubVar(varIndex, subNameHash, 0);
+ return subVarIndex;
+}
+
+} // End of namespace Neverhood
diff --git a/engines/neverhood/gamevars.h b/engines/neverhood/gamevars.h
new file mode 100644
index 0000000000..863aa1b2c1
--- /dev/null
+++ b/engines/neverhood/gamevars.h
@@ -0,0 +1,57 @@
+/* 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 NEVERHOOD_GAMEVARS_H
+#define NEVERHOOD_GAMEVARS_H
+
+#include "common/array.h"
+#include "neverhood/neverhood.h"
+
+namespace Neverhood {
+
+struct GameVar {
+ uint32 nameHash;
+ uint32 value;
+ int16 firstIndex, nextIndex;
+};
+
+class GameVars {
+public:
+ GameVars();
+ ~GameVars();
+ // TODO void load(???);
+ // TODO void save(???);
+ uint32 getGlobalVar(uint32 nameHash);
+ void setGlobalVar(uint32 nameHash, uint32 value);
+ uint32 getSubVar(uint32 nameHash, uint32 subNameHash);
+ void setSubVar(uint32 nameHash, uint32 subNameHash, uint32 value);
+protected:
+ Common::Array<GameVar> _vars;
+ int16 addVar(uint32 nameHash, uint32 value);
+ int16 findSubVarIndex(int16 varIndex, uint32 subNameHash);
+ int16 addSubVar(int16 varIndex, uint32 subNameHash, uint32 value);
+ int16 getSubVarIndex(int16 varIndex, uint32 subNameHash);
+};
+
+} // End of namespace Neverhood
+
+#endif /* NEVERHOOD_GAMEVARS_H */
diff --git a/engines/neverhood/module.mk b/engines/neverhood/module.mk
index eb656def42..7961bc9a2a 100644
--- a/engines/neverhood/module.mk
+++ b/engines/neverhood/module.mk
@@ -6,6 +6,7 @@ MODULE_OBJS = \
collisionman.o \
detection.o \
gamemodule.o \
+ gamevars.o \
graphics.o \
klayman.o \
module.o \
diff --git a/engines/neverhood/module1000.cpp b/engines/neverhood/module1000.cpp
index 0d727bac8c..b3c07c9b51 100644
--- a/engines/neverhood/module1000.cpp
+++ b/engines/neverhood/module1000.cpp
@@ -29,7 +29,7 @@ Module1000::Module1000(NeverhoodEngine *vm, Module *parentModule, int which)
debug("Create Module1000(%d)", which);
- _musicFileHash = _vm->getGlobalVar(0xD0A14D10) ? 0x81106480 : 0x00103144;
+ _musicFileHash = getGlobalVar(0xD0A14D10) ? 0x81106480 : 0x00103144;
// TODO Music18hList_add(0x03294419, 0x061880C6);
// TODO Music18hList_add(0x03294419, _musicFileHash);
@@ -256,7 +256,7 @@ uint32 AsScene1001Door::handleMessage(int messageNum, const MessageParam &param,
}
void AsScene1001Door::handleMessage2000h() {
- switch (_vm->getGlobalVar(0x52371C95)) {
+ switch (getGlobalVar(0x52371C95)) {
case 0:
case 1:
_soundResource1.play(0x65482F03);
@@ -272,11 +272,11 @@ void AsScene1001Door::handleMessage2000h() {
// Nothing
break;
}
- _vm->incGlobalVar(0x52371C95, 1);
+ incGlobalVar(0x52371C95, 1);
}
void AsScene1001Door::callback1() {
- switch (_vm->getGlobalVar(0x52371C95)) {
+ switch (getGlobalVar(0x52371C95)) {
case 1:
setFileHash(0x624C0498, 4, -1);
_newHashListIndex = 4;
@@ -297,7 +297,7 @@ void AsScene1001Door::callback1() {
}
void AsScene1001Door::callback2() {
- _vm->setGlobalVar(0xD217189D, 1);
+ setGlobalVar(0xD217189D, 1);
setFileHash(0x624C0498, 6, 6);
SetAnimationCallback3(&AsScene1001Door::callback3);
_x = 30;
@@ -367,7 +367,7 @@ uint32 AsScene1001Window::handleMessage(int messageNum, const MessageParam &para
break;
case 0x3002:
SetMessageHandler(NULL);
- _vm->setGlobalVar(0x03C698DA, 1);
+ setGlobalVar(0x03C698DA, 1);
_surface->setVisible(false);
break;
}
@@ -474,7 +474,7 @@ Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which)
setMessageList(0x004B4898);
} else if (which == 2) {
setRectList(0x004B49F0);
- if (_vm->getGlobalVar(0xC0418A02)) {
+ if (getGlobalVar(0xC0418A02)) {
_klayman = new KmScene1001(_vm, this, 390, 433);
_klayman->setDoDeltaX(1);
} else {
@@ -496,7 +496,7 @@ Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which)
_klayman->getSurface()->getClipRect().x2 = staticSprite1->getSurface()->getDrawRect().x + staticSprite1->getSurface()->getDrawRect().width;
_klayman->getSurface()->getClipRect().y2 = 480;
- if (_vm->getGlobalVar(0xD217189D) == 0) {
+ if (getGlobalVar(0xD217189D) == 0) {
_asDoor = addSprite(new AsScene1001Door(_vm));
_asDoor->getSurface()->getClipRect().x1 = 0;
_asDoor->getSurface()->getClipRect().y1 = 0;
@@ -513,7 +513,7 @@ Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which)
_ssButton = addSprite(new SsCommonButtonSprite(_vm, this, 0x15288120, 100, 0));
- if (_vm->getGlobalVar(0x03C698DA) == 0) {
+ if (getGlobalVar(0x03C698DA) == 0) {
staticSprite1 = addSprite(new StaticSprite(_vm, 0x8C066150, 200));
_asWindow = addSprite(new AsScene1001Window(_vm));
_asWindow->getSurface()->getClipRect().x1 = staticSprite1->getSurface()->getDrawRect().x;
@@ -529,7 +529,7 @@ Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which)
}
Scene1001::~Scene1001() {
- // TODO _vm->setGlobalVar(0xC0418A02, _klayman->_doDeltaX);
+ // TODO setGlobalVar(0xC0418A02, _klayman->_doDeltaX);
}
uint32 Scene1001::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
@@ -538,7 +538,7 @@ uint32 Scene1001::handleMessage(int messageNum, const MessageParam &param, Entit
Scene::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x0001:
- if (param.asPoint().x == 0 && _vm->getGlobalVar(0xA4014072)) {
+ if (param.asPoint().x == 0 && getGlobalVar(0xA4014072)) {
_parentModule->sendMessage(0x1009, 0, this);
}
break;
@@ -554,7 +554,7 @@ uint32 Scene1001::handleMessage(int messageNum, const MessageParam &param, Entit
setMessageList2(0x004B4910);
messageResult = 1;
} else if (param.asInteger() == 0x21E64A00) {
- if (_vm->getGlobalVar(0xD217189D)) {
+ if (getGlobalVar(0xD217189D)) {
setMessageList(0x004B48A8);
} else {
setMessageList(0x004B48C8);
@@ -563,7 +563,7 @@ uint32 Scene1001::handleMessage(int messageNum, const MessageParam &param, Entit
} else if (param.asInteger() == 0x040424D0) {
_klayman->sendMessage(0x1014, _ssButton, this);
} else if (param.asInteger() == 0x80006358) {
- if (_vm->getGlobalVar(0x03C698DA)) {
+ if (getGlobalVar(0x03C698DA)) {
setMessageList(0x004B4938);
} else {
setMessageList(0x004B4960);
diff --git a/engines/neverhood/neverhood.cpp b/engines/neverhood/neverhood.cpp
index 9c029190cb..77483c52ca 100644
--- a/engines/neverhood/neverhood.cpp
+++ b/engines/neverhood/neverhood.cpp
@@ -30,6 +30,7 @@
#include "neverhood/blbarchive.h"
#include "neverhood/collisionman.h"
#include "neverhood/gamemodule.h"
+#include "neverhood/gamevars.h"
#include "neverhood/graphics.h"
#include "neverhood/resourceman.h"
#include "neverhood/resource.h"
@@ -67,6 +68,8 @@ Common::Error NeverhoodEngine::run() {
_staticData = new StaticData();
_staticData->load("neverhood.dat");
+ _gameVars = new GameVars();
+
_screen = new Screen(this);
_res = new ResourceMan();
@@ -198,6 +201,7 @@ Common::Error NeverhoodEngine::run() {
delete _res;
delete _screen;
+ delete _gameVars;
delete _staticData;
debug("Ok.");
@@ -205,26 +209,4 @@ Common::Error NeverhoodEngine::run() {
return Common::kNoError;
}
-uint32 NeverhoodEngine::getGlobalVar(uint32 nameHash) {
- // TODO
- return 0;
-}
-
-void NeverhoodEngine::setGlobalVar(uint32 nameHash, uint32 value) {
- // TODO
-}
-
-void NeverhoodEngine::incGlobalVar(uint32 nameHash, int incrValue) {
- setGlobalVar(nameHash, getGlobalVar(nameHash) - incrValue);
-}
-
-uint32 NeverhoodEngine::getSubVar(uint32 nameHash, uint32 subNameHash) {
- // TODO
- return 0;
-}
-
-void NeverhoodEngine::setSubVar(uint32 nameHash, uint32 subNameHash, uint32 value) {
- // TODO
-}
-
} // End of namespace Neverhood
diff --git a/engines/neverhood/neverhood.h b/engines/neverhood/neverhood.h
index 952a99d768..0070f0867e 100644
--- a/engines/neverhood/neverhood.h
+++ b/engines/neverhood/neverhood.h
@@ -41,6 +41,7 @@ struct NeverhoodGameDescription;
class CollisionMan;
class GameModule;
+class GameVars;
class ResourceMan;
class Screen;
class StaticData;
@@ -73,6 +74,7 @@ public:
uint16 _buttonState;
GameState _gameState;
+ GameVars *_gameVars;
Screen *_screen;
ResourceMan *_res;
GameModule *_gameModule;
@@ -114,11 +116,6 @@ public:
#endif
GameState& gameState() { return _gameState; }
- uint32 getGlobalVar(uint32 nameHash);
- void setGlobalVar(uint32 nameHash, uint32 value);
- void incGlobalVar(uint32 nameHash, int incrValue);
- uint32 getSubVar(uint32 nameHash, uint32 subNameHash);
- void setSubVar(uint32 nameHash, uint32 subNameHash, uint32 value);
public:
diff --git a/engines/neverhood/smackerscene.cpp b/engines/neverhood/smackerscene.cpp
index d47dbb0394..1584ac32d9 100644
--- a/engines/neverhood/smackerscene.cpp
+++ b/engines/neverhood/smackerscene.cpp
@@ -32,7 +32,7 @@ SmackerScene::SmackerScene(NeverhoodEngine *vm, Module *parentModule, bool doubl
// NOTE: Merged from SmackerScene::init, maybe split again if needed (incl. parameter flags)
- if (_vm->getGlobalVar(0x06C02850)) {
+ if (getGlobalVar(0x06C02850)) {
_flag1 = true;
_canAbort = true;
}
@@ -76,9 +76,9 @@ void SmackerScene::nextVideo() {
_parentModule->sendMessage(0x1009, 0, this);
return;
}
- _fieldDF = _vm->getSubVar(0x00800410, smackerFileHash);
+ _fieldDF = getSubVar(0x00800410, smackerFileHash);
if (!_fieldDF) {
- _vm->setSubVar(0x00800410, smackerFileHash, 1);
+ setSubVar(0x00800410, smackerFileHash, 1);
}
if (_fileHashListIndex == 0) {
_smackerPlayer = new SmackerPlayer(_vm, this, smackerFileHash, _doubleSurface, false);