diff options
Diffstat (limited to 'engines/access/resources.cpp')
-rw-r--r-- | engines/access/resources.cpp | 169 |
1 files changed, 141 insertions, 28 deletions
diff --git a/engines/access/resources.cpp b/engines/access/resources.cpp index 4157cdfc0d..096fb15b35 100644 --- a/engines/access/resources.cpp +++ b/engines/access/resources.cpp @@ -22,9 +22,140 @@ #include "access/resources.h" #include "access/access.h" +#include "access/amazon/amazon_resources.h" +#include "access/martian/martian_resources.h" namespace Access { +Resources *Resources::init(AccessEngine *vm) { + if (vm->getGameID() == GType_Amazon) + return new Amazon::AmazonResources(vm); + else if (vm->getGameID() == GType_MartianMemorandum) + return new Martian::MartianResources(vm); + + error("Unknown game"); +} + +bool Resources::load(Common::String &errorMessage) { + Common::File f; + if (!f.open("access.dat")) { + errorMessage = "Could not locate required access.dat file"; + return false; + } + + // Check for the magic identifier + char buffer[4]; + f.read(buffer, 4); + if (strncmp(buffer, "SVMA", 4)) { + errorMessage = "Located access.dat file had invalid contents"; + return false; + } + + // Validate the version number + uint expectedVersion = 1; + uint version = f.readUint16LE(); + if (version != expectedVersion) { + errorMessage = Common::String::format( + "Incorrect version of access.dat found. Expected %d but got %d", + expectedVersion, version); + return false; + } + + // Load in the index + uint count = f.readUint16LE(); + _datIndex.resize(count); + for (uint idx = 0; idx < _datIndex.size(); ++idx) { + _datIndex[idx]._gameId = f.readByte(); + _datIndex[idx]._discType = f.readByte(); + _datIndex[idx]._demoType = f.readByte(); + _datIndex[idx]._language = (Common::Language)f.readByte(); + _datIndex[idx]._fileOffset = f.readUint32LE(); + } + + // Load in the data for the game + load(f); + + return true; +} + +void Resources::load(Common::SeekableReadStream &s) { + uint count; + + // Get the offset of the data for the game + uint entryOffset = findEntry(_vm->getGameID(), _vm->isCD() ? 1 : 0, + _vm->isDemo() ? 1 : 0, _vm->getLanguage()); + s.seek(entryOffset); + + // Load filename list + count = s.readUint16LE(); + FILENAMES.resize(count); + for (uint idx = 0; idx < count; ++idx) + FILENAMES[idx] = readString(s); + + // Load the character data + count = s.readUint16LE(); + CHARTBL.resize(count); + for (uint idx = 0; idx < count; ++idx) { + uint count2 = s.readUint16LE(); + CHARTBL[idx].resize(count2); + if (count2 > 0) + s.read(&CHARTBL[idx][0], count2); + } + + // Load the room data + count = s.readUint16LE(); + ROOMTBL.resize(count); + for (uint idx = 0; idx < count; ++idx) { + ROOMTBL[idx]._desc = readString(s); + ROOMTBL[idx]._travelPos.x = s.readSint16LE(); + ROOMTBL[idx]._travelPos.y = s.readSint16LE(); + uint count2 = s.readUint16LE(); + ROOMTBL[idx]._data.resize(count2); + if (count2 > 0) + s.read(&ROOMTBL[idx]._data[0], count2); + } + + // Load the deaths list + count = s.readUint16LE(); + DEATHS.resize(count); + for (uint idx = 0; idx < count; ++idx) { + DEATHS[idx]._screenId = s.readByte(); + DEATHS[idx]._msg = readString(s); + } + + // Load in the inventory list + count = s.readUint16LE(); + INVENTORY.resize(count); + for (uint idx = 0; idx < count; ++idx) { + INVENTORY[idx]._desc = readString(s); + for (uint idx2 = 0; idx2 < 4; ++idx2) + INVENTORY[idx]._combo[idx2] = s.readSint16LE(); + } +} + +uint Resources::findEntry(byte gameId, byte discType, byte demoType, Common::Language language) { + for (uint idx = 0; idx < _datIndex.size(); ++idx) { + DATEntry &de = _datIndex[idx]; + if (de._gameId == gameId && de._discType == discType && + de._demoType == demoType && de._language == language) + return de._fileOffset; + } + + error("Could not locate appropriate access.dat entry"); +} + +Common::String Resources::readString(Common::SeekableReadStream &s) { + Common::String result; + char c; + + while ((c = s.readByte()) != 0) + result += c; + + return result; +} + +/*------------------------------------------------------------------------*/ + const byte INITIAL_PALETTE[18 * 3] = { 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, @@ -46,35 +177,17 @@ const byte INITIAL_PALETTE[18 * 3] = { 0x00, 0x00, 0x00 }; -const int SIDEOFFR[] = { 5, 5, 5, 5, 5, 5, 5, 5, 0 }; -const int SIDEOFFL[] = { 5, 5, 5, 5, 5, 5, 5, 5, 0 }; -const int SIDEOFFU[] = { 2, 2, 2, 2, 2, 2, 2, 2, 0 }; -const int SIDEOFFD[] = { 2, 2, 2, 2, 2, 2, 2, 2, 0 }; -const int DIAGOFFURX[] = { 4, 5, 2, 2, 3, 4, 2, 2, 0 }; -const int DIAGOFFURY[] = { 2, 3, 2, 2, 2, 3, 1, 1, 0 }; -const int DIAGOFFDRX[] = { 4, 5, 4, 3, 5, 4, 5, 1, 0 }; -const int DIAGOFFDRY[] = { 3, 2, 1, 2, 2, 1, 2, 1, 0 }; -const int DIAGOFFULX[] = { 4, 5, 4, 3, 3, 2, 2, 2, 0 }; -const int DIAGOFFULY[] = { 3, 3, 1, 2, 2, 1, 1, 1, 0 }; -const int DIAGOFFDLX[] = { 4, 5, 3, 3, 5, 4, 6, 1, 0 }; -const int DIAGOFFDLY[] = { 2, 2, 1, 2, 3, 1, 2, 1, 0 }; - -const int RMOUSE[10][2] = { - { 0, 35 }, { 0, 0 }, { 36, 70 }, { 71, 106 }, { 107, 141 }, - { 142, 177 }, { 178, 212 }, { 213, 248 }, { 249, 283 }, { 284, 318 } -}; - -const char *const LOOK_MESSAGE = "LOOKING THERE REVEALS NOTHING OF INTEREST."; -const char *const GET_MESSAGE = "YOU CAN'T TAKE THAT."; -const char *const OPEN_MESSAGE = "THAT DOESN'T OPEN."; -const char *const MOVE_MESSAGE = "THAT WON'T MOVE."; -const char *const USE_MESSAGE = "THAT DOESN'T SEEM TO WORK."; -const char *const GO_MESSAGE = "YOU CAN'T CLIMB THAT."; -const char *const HELP_MESSAGE = "THIS OBJECT REQUIRES NO HINTS"; -const char *const TALK_MESSAGE = "THERE SEEMS TO BE NO RESPONSE."; const char *const GENERAL_MESSAGES[] = { - LOOK_MESSAGE, OPEN_MESSAGE, MOVE_MESSAGE, GET_MESSAGE, USE_MESSAGE, - GO_MESSAGE, TALK_MESSAGE, HELP_MESSAGE, HELP_MESSAGE, USE_MESSAGE + "LOOKING THERE REVEALS NOTHING OF INTEREST.", // LOOK_MESSAGE + "THAT DOESN'T OPEN.", // OPEN_MESSAGE + "THAT WON'T MOVE.", // MOVE_MESSAGE + "YOU CAN'T TAKE THAT.", // GET_MESSAGE + "THAT DOESN'T SEEM TO WORK.", // USE_MESSAGE + "YOU CAN'T CLIMB THAT.", // GO_MESSAGE + "THERE SEEMS TO BE NO RESPONSE.", // TALK_MESSAGE + "THIS OBJECT REQUIRES NO HINTS", // HELP_MESSAGE + "THIS OBJECT REQUIRES NO HINTS", // HELP_MESSAGE + "THAT DOESN'T SEEM TO WORK." // USE_MESSAGE }; const int INVCOORDS[][4] = { |