diff options
-rw-r--r-- | engines/glk/advsys/advsys.cpp | 2 | ||||
-rw-r--r-- | engines/glk/advsys/game.cpp | 35 | ||||
-rw-r--r-- | engines/glk/advsys/game.h | 58 |
3 files changed, 83 insertions, 12 deletions
diff --git a/engines/glk/advsys/advsys.cpp b/engines/glk/advsys/advsys.cpp index 5664bc8bc0..5d0f20b1bb 100644 --- a/engines/glk/advsys/advsys.cpp +++ b/engines/glk/advsys/advsys.cpp @@ -45,7 +45,7 @@ bool AdvSys::initialize() { return false; // Load the game's header - if (!load(_gameFile)) + if (!Game::init(_gameFile)) return false; return true; diff --git a/engines/glk/advsys/game.cpp b/engines/glk/advsys/game.cpp index d1862b7299..69dc6e4bbc 100644 --- a/engines/glk/advsys/game.cpp +++ b/engines/glk/advsys/game.cpp @@ -35,7 +35,7 @@ void Decrypter::decrypt(byte *data, size_t size) { #define HEADER_SIZE 62 -bool Header::load(Common::ReadStream &s) { +bool Header::init(Common::ReadStream &s) { _valid = false; byte data[HEADER_SIZE]; @@ -80,10 +80,10 @@ bool Header::load(Common::ReadStream &s) { #define MAX_VERSION 102 -bool Game::load(Common::SeekableReadStream &s) { +bool Game::init(Common::SeekableReadStream &s) { // Load the header s.seek(0); - if (!Header::load(s)) + if (!Header::init(s)) return false; if (_headerVersion < 101 || _headerVersion > MAX_VERSION) @@ -108,9 +108,38 @@ bool Game::load(Common::SeekableReadStream &s) { _dataSpace = &_data[_dataSpaceOffset]; _codeSpace = &_data[_codeSpaceOffset]; + _wordCount = READ_LE_UINT16(_wordTable); + _objectCount = READ_LE_UINT16(_objectTable); + _actionCount = READ_LE_UINT16(_actionTable); + _variableCount = READ_LE_UINT16(_variableTable); + + setVariable(V_OCOUNT, _objectCount); return true; } +void Game::restart(Common::SeekableReadStream& s) { + s.seek(_residentOffset + _saveAreaOffset); + s.read(_saveArea, _saveSize); +} + +void Game::saveGameData(Common::WriteStream& ws) { + ws.write(_saveArea, _saveSize); +} + +void Game::loadGameData(Common::ReadStream& rs) { + rs.read(_saveArea, _saveSize); +} + +void Game::setVariable(uint variableNum, int value) { + assert(variableNum < _variableCount); + WRITE_LE_UINT16(_variableTable + variableNum * 2, value); +} + +int Game::getVariable(uint variableNum) { + assert(variableNum < _variableCount); + return READ_LE_UINT16(_variableTable + variableNum * 2); +} + } // End of namespace AdvSys } // End of namespace Glk diff --git a/engines/glk/advsys/game.h b/engines/glk/advsys/game.h index 9011dacf18..1c7222df8f 100644 --- a/engines/glk/advsys/game.h +++ b/engines/glk/advsys/game.h @@ -30,6 +30,18 @@ namespace Glk { namespace AdvSys { /** + * Built-in variables + */ +enum Variable { + V_ACTOR = 1, ///< Actor noun phrase number + V_ACTION = 2, ///< Action from phrase + V_DOBJECT = 3, ///< First direct object noun phrase number + V_NDOBJECTS = 4, ///< Number of direct object noun phrases + V_IOBJECT = 5, ///< Indirect object noun phrase number + V_OCOUNT = 6 ///< Total object count +}; + +/** * Data decryption */ class Decrypter { @@ -81,23 +93,27 @@ public: * Constructor */ Header(Common::ReadStream &s) { - load(s); + init(s); } /** - * Load the header + * init the header */ - bool load(Common::ReadStream &s); + bool init(Common::ReadStream &s); }; /** * Game abstraction class */ class Game : public Header { -private: - uint _residentOffset; public: Common::Array<byte> _data; + uint _residentOffset; + uint _wordCount; + uint _objectCount; + uint _actionCount; + uint _variableCount; + byte* _residentBase; byte* _wordTable; byte* _wordTypeTable; @@ -111,14 +127,40 @@ public: /** * Constructor */ - Game() : Header(), _residentOffset(0), _residentBase(nullptr), _wordTable(nullptr), + Game() : Header(), _residentOffset(0), _wordCount(0), _objectCount(0), _actionCount(0), + _variableCount(0), _residentBase(nullptr), _wordTable(nullptr), _wordTypeTable(nullptr), _objectTable(nullptr), _actionTable(nullptr), _variableTable(nullptr), _saveArea(nullptr) {} /** - * Load data for the game + * init data for the game + */ + bool init(Common::SeekableReadStream &s); + + /** + * Restore savegame data from the game to it's initial state + */ + void restart(Common::SeekableReadStream& s); + + /** + * Save the game data to a savegame + */ + void saveGameData(Common::WriteStream& ws); + + /** + * Restore the game data from a savegame + */ + void loadGameData(Common::ReadStream& rs); + + /** + * Set a variable value + */ + void setVariable(uint variableNum, int value); + + /** + * Get a variable value */ - bool load(Common::SeekableReadStream &s); + int getVariable(uint variableNum); }; } // End of namespace AdvSys |