diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/gob/game.cpp | 141 | ||||
-rw-r--r-- | engines/gob/game.h | 37 | ||||
-rw-r--r-- | engines/gob/game_v6.cpp | 26 |
3 files changed, 108 insertions, 96 deletions
diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp index 9a5825a475..fe48f645ab 100644 --- a/engines/gob/game.cpp +++ b/engines/gob/game.cpp @@ -31,6 +31,7 @@ #include "gob/global.h" #include "gob/util.h" #include "gob/dataio.h" +#include "gob/variables.h" #include "gob/script.h" #include "gob/resources.h" #include "gob/inter.h" @@ -41,6 +42,47 @@ namespace Gob { +Game::Environment::Environment(GobEngine *vm) : _vm(vm) { + _cursorHotspotX = 0; + _cursorHotspotY = 0; + _variables = 0; + _script = 0; + _resources = 0; + _curTotFile[0] = '\0'; +} + +Game::Environment::~Environment() { + if (_script != _vm->_game->_script) + delete _script; + if (_resources != _vm->_game->_resources) + delete _resources; + if (_variables != _vm->_inter->_variables) + delete _variables; +} + +void Game::Environment::set() { + _cursorHotspotX = _vm->_draw->_cursorHotspotXVar; + _cursorHotspotY = _vm->_draw->_cursorHotspotYVar; + _script = _vm->_game->_script; + _resources = _vm->_game->_resources; + _variables = _vm->_inter->_variables; + strncpy(_curTotFile, _vm->_game->_curTotFile, 14); +} + +void Game::Environment::get() { + _vm->_draw->_cursorHotspotXVar = _cursorHotspotX; + _vm->_draw->_cursorHotspotYVar = _cursorHotspotY; + _vm->_game->_script = _script; + _vm->_game->_resources = _resources; + _vm->_inter->_variables = _variables; + strncpy(_vm->_game->_curTotFile, _curTotFile, 14); +} + +const char *Game::Environment::getTotFile() const { + return _curTotFile; +} + + Game::Game(GobEngine *vm) : _vm(vm) { _collisionAreas = 0; _shouldPushColls = 0; @@ -78,34 +120,19 @@ Game::Game(GobEngine *vm) : _vm(vm) { _tempStr[0] = 0; _collStr[0] = 0; - _backupedCount = 0; - _curBackupPos = 0; + _numEnvironments = 0; + _curEnvironment = 0; - for (int i = 0; i < 5; i++) { - _cursorHotspotXArray[i] = 0; - _cursorHotspotYArray[i] = 0; - _variablesArray[i] = 0; - _curTotFileArray[i][0] = 0; - _scriptArray[i] = 0; - _resourcesArray[i] = 0; - } + for (int i = 0; i < kMaxEnvironments; i++) + _environments[i] = new Environment(_vm); _script = new Script(_vm); _resources = new Resources(_vm); } Game::~Game() { - for (int i = 0; i < 5; i++) { - warning("%d", i); - if (_scriptArray[i] != _script) { - warning("DELETE (%d)", _scriptArray[i] != 0); - delete _scriptArray[i]; - } - if (_resourcesArray[i] != _resources) { - warning("DELETE (%d)", _resourcesArray[i] != 0); - delete _resourcesArray[i]; - } - } + for (int i = 0; i < kMaxEnvironments; i++) + delete _environments[i]; delete _script; delete _resources; @@ -297,19 +324,14 @@ void Game::start(void) { void Game::totSub(int8 flags, const char *newTotFile) { int8 curBackupPos; - if (_backupedCount >= 5) + if (_numEnvironments >= kMaxEnvironments) return; - _cursorHotspotXArray[_backupedCount] = _vm->_draw->_cursorHotspotXVar; - _cursorHotspotYArray[_backupedCount] = _vm->_draw->_cursorHotspotYVar; - _scriptArray[_backupedCount] = _script; - _resourcesArray[_backupedCount] = _resources; - _variablesArray[_backupedCount] = _vm->_inter->_variables; - strcpy(_curTotFileArray[_backupedCount], _curTotFile); + _environments[_numEnvironments]->set(); - curBackupPos = _curBackupPos; - _backupedCount++; - _curBackupPos = _backupedCount; + curBackupPos = _curEnvironment; + _numEnvironments++; + _curEnvironment = _numEnvironments; _script = new Script(_vm); _resources = new Resources(_vm); @@ -341,52 +363,40 @@ void Game::totSub(int8 flags, const char *newTotFile) { _vm->_inter->delocateVars(); } - _backupedCount--; - _curBackupPos = curBackupPos; + _numEnvironments--; + _curEnvironment = curBackupPos; - _vm->_draw->_cursorHotspotXVar = _cursorHotspotXArray[_backupedCount]; - _vm->_draw->_cursorHotspotYVar = _cursorHotspotYArray[_backupedCount]; - _script = _scriptArray[_backupedCount]; - _resources = _resourcesArray[_backupedCount]; - _vm->_inter->_variables = _variablesArray[_backupedCount]; - strcpy(_curTotFile, _curTotFileArray[_backupedCount]); + _environments[_numEnvironments]->get(); } void Game::switchTotSub(int16 index, int16 skipPlay) { int16 backupedCount; int16 curBackupPos; - if ((_backupedCount - index) < 1) + if ((_numEnvironments - index) < 1) + return; + + int16 newPos = _curEnvironment - index - ((index >= 0) ? 1 : 0); + if (newPos >= kMaxEnvironments) return; - int16 newPos = _curBackupPos - index - ((index >= 0) ? 1 : 0); // WORKAROUND: Some versions don't make the MOVEMENT menu item unselectable // in the dreamland screen, resulting in a crash when it's clicked. if ((_vm->getGameType() == kGameTypeGob2) && (index == -1) && (skipPlay == 7) && - !scumm_stricmp(_curTotFileArray[newPos], "gob06.tot")) + !scumm_stricmp(_environments[newPos]->getTotFile(), "gob06.tot")) return; - curBackupPos = _curBackupPos; - backupedCount = _backupedCount; - if (_curBackupPos == _backupedCount) { - _cursorHotspotXArray[_backupedCount] = _vm->_draw->_cursorHotspotXVar; - _cursorHotspotYArray[_backupedCount] = _vm->_draw->_cursorHotspotYVar; - _scriptArray[_backupedCount] = _script; - _resourcesArray[_backupedCount] = _resources; - _variablesArray[_backupedCount] = _vm->_inter->_variables; - strcpy(_curTotFileArray[_backupedCount], _curTotFile); - _backupedCount++; + curBackupPos = _curEnvironment; + backupedCount = _numEnvironments; + if (_curEnvironment == _numEnvironments) { + _environments[_numEnvironments]->set(); + _numEnvironments++; } - _curBackupPos -= index; + _curEnvironment -= index; if (index >= 0) - _curBackupPos--; + _curEnvironment--; - _vm->_draw->_cursorHotspotXVar = _cursorHotspotXArray[_curBackupPos]; - _vm->_draw->_cursorHotspotYVar = _cursorHotspotYArray[_curBackupPos]; - _script = _scriptArray[_curBackupPos]; - _resources = _resourcesArray[_curBackupPos]; - _vm->_inter->_variables = _variablesArray[_curBackupPos]; - strcpy(_curTotFile, _curTotFileArray[_curBackupPos]); + _environments[_curEnvironment]->get(); if (_vm->_inter->_terminate != 0) return; @@ -399,14 +409,9 @@ void Game::switchTotSub(int16 index, int16 skipPlay) { popCollisions(); - _curBackupPos = curBackupPos; - _backupedCount = backupedCount; - _vm->_draw->_cursorHotspotXVar = _cursorHotspotXArray[_curBackupPos]; - _vm->_draw->_cursorHotspotYVar = _cursorHotspotYArray[_curBackupPos]; - _script = _scriptArray[_curBackupPos]; - _resources = _resourcesArray[_curBackupPos]; - _vm->_inter->_variables = _variablesArray[_curBackupPos]; - strcpy(_curTotFile, _curTotFileArray[_curBackupPos]); + _curEnvironment = curBackupPos; + _numEnvironments = backupedCount; + _environments[_curEnvironment]->get(); } void Game::setCollisions(byte arg_0) { diff --git a/engines/gob/game.h b/engines/gob/game.h index bf66312f6a..e01fe53641 100644 --- a/engines/gob/game.h +++ b/engines/gob/game.h @@ -26,12 +26,11 @@ #ifndef GOB_GAME_H #define GOB_GAME_H -#include "gob/variables.h" - namespace Gob { class Script; class Resources; +class Variables; class Game { public: @@ -121,6 +120,29 @@ public: virtual void popCollisions(void) = 0; protected: + static const int kMaxEnvironments = 5; + + class Environment { + public: + Environment(GobEngine *vm); + ~Environment(); + + void set(); + void get(); + + const char *getTotFile() const; + + private: + GobEngine *_vm; + + int16 _cursorHotspotX; + int16 _cursorHotspotY; + char _curTotFile[14]; + Variables *_variables; + Script *_script; + Resources *_resources; + }; + int16 _lastCollKey; int16 _lastCollAreaIndex; int16 _lastCollId; @@ -145,14 +167,9 @@ protected: char _collStr[256]; // For totSub() - int8 _backupedCount; - int8 _curBackupPos; - int16 _cursorHotspotXArray[5]; - int16 _cursorHotspotYArray[5]; - Variables *_variablesArray[5]; - char _curTotFileArray[5][14]; - Script *_scriptArray[5]; - Resources *_resourcesArray[5]; + int8 _curEnvironment; + int8 _numEnvironments; + Environment *_environments[kMaxEnvironments]; GobEngine *_vm; diff --git a/engines/gob/game_v6.cpp b/engines/gob/game_v6.cpp index 4d3233a4f5..78579b8c38 100644 --- a/engines/gob/game_v6.cpp +++ b/engines/gob/game_v6.cpp @@ -49,19 +49,14 @@ void Game_v6::totSub(int8 flags, const char *newTotFile) { if ((flags == 16) || (flags == 17)) warning("Urban Stub: Game_v6::totSub(), flags == %d", flags); - if (_backupedCount >= 5) + if (_numEnvironments >= kMaxEnvironments) return; - _cursorHotspotXArray[_backupedCount] = _vm->_draw->_cursorHotspotXVar; - _cursorHotspotYArray[_backupedCount] = _vm->_draw->_cursorHotspotYVar; - _scriptArray[_backupedCount] = _script; - _resourcesArray[_backupedCount] = _resources; - _variablesArray[_backupedCount] = _vm->_inter->_variables; - strcpy(_curTotFileArray[_backupedCount], _curTotFile); + _environments[_numEnvironments]->set(); - curBackupPos = _curBackupPos; - _backupedCount++; - _curBackupPos = _backupedCount; + curBackupPos = _curEnvironment; + _numEnvironments++; + _curEnvironment = _numEnvironments; _script = new Script(_vm); _resources = new Resources(_vm); @@ -95,15 +90,10 @@ void Game_v6::totSub(int8 flags, const char *newTotFile) { _vm->_inter->delocateVars(); } - _backupedCount--; - _curBackupPos = curBackupPos; + _numEnvironments--; + _curEnvironment = curBackupPos; - _vm->_draw->_cursorHotspotXVar = _cursorHotspotXArray[_backupedCount]; - _vm->_draw->_cursorHotspotYVar = _cursorHotspotYArray[_backupedCount]; - _script = _scriptArray[_backupedCount]; - _resources = _resourcesArray[_backupedCount]; - _vm->_inter->_variables = _variablesArray[_backupedCount]; - strcpy(_curTotFile, _curTotFileArray[_backupedCount]); + _environments[_numEnvironments]->get(); } int16 Game_v6::addNewCollision(int16 id, uint16 left, uint16 top, |