2016-06-13 20:29:08 +02:00
|
|
|
#include "macventure/world.h"
|
|
|
|
|
|
|
|
#include "common/file.h"
|
|
|
|
|
|
|
|
namespace MacVenture {
|
|
|
|
|
2016-06-14 00:16:02 +02:00
|
|
|
World::World(MacVentureEngine *engine, Common::MacResManager *resMan) {
|
2016-06-13 20:29:08 +02:00
|
|
|
_resourceManager = resMan;
|
|
|
|
_engine = engine;
|
|
|
|
|
|
|
|
if (!loadStartGameFileName())
|
|
|
|
error("Could not load initial game configuration");
|
|
|
|
|
|
|
|
Common::File saveGameFile;
|
|
|
|
if (!saveGameFile.open(_startGameFileName))
|
|
|
|
error("Could not load initial game configuration");
|
|
|
|
|
|
|
|
Common::SeekableReadStream *saveGameRes = saveGameFile.readStream(saveGameFile.size());
|
|
|
|
|
2016-06-16 23:04:10 +02:00
|
|
|
_saveGame = new SaveGame(_engine, saveGameRes);
|
2016-06-16 18:17:45 +02:00
|
|
|
_objectConstants = new Container(_engine->getFilePath(kObjectPathID).c_str());
|
2016-06-17 15:55:23 +02:00
|
|
|
//_gameText = new Container(_engine->getFilePath(kTextPathID).c_str());
|
|
|
|
_gameText = new Container("Shadowgate II/Shadow Text");
|
|
|
|
|
|
|
|
ObjID tid = (ObjID)1;
|
|
|
|
TextAsset test = TextAsset(tid, _gameText, _engine->isOldText(), _engine->getDecodingHuffman());
|
|
|
|
|
2016-06-13 20:29:08 +02:00
|
|
|
delete saveGameRes;
|
|
|
|
saveGameFile.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
World::~World() {
|
|
|
|
|
|
|
|
if (_saveGame)
|
|
|
|
delete _saveGame;
|
2016-06-14 00:16:02 +02:00
|
|
|
|
|
|
|
if (_objectConstants)
|
|
|
|
delete _objectConstants;
|
2016-06-13 20:29:08 +02:00
|
|
|
}
|
|
|
|
|
2016-06-16 20:33:02 +02:00
|
|
|
|
2016-06-16 23:04:10 +02:00
|
|
|
uint32 World::getObjAttr(ObjID objID, uint32 attrID) {
|
2016-06-16 20:33:02 +02:00
|
|
|
uint32 res;
|
|
|
|
uint32 index = _engine->getGlobalSettings().attrIndices[attrID];
|
|
|
|
if (!(index & 0x80)) { // It's not a constant
|
|
|
|
res = _saveGame->getGroups()[attrID][objID];
|
|
|
|
} else {
|
|
|
|
Common::SeekableReadStream *objStream = _objectConstants->getItem(objID);
|
|
|
|
index &= 0x7F;
|
|
|
|
objStream->skip((index * 2) - 1);
|
|
|
|
res = objStream->readUint16BE();
|
|
|
|
}
|
|
|
|
res &= _engine->getGlobalSettings().attrMasks[attrID];
|
|
|
|
res >>= _engine->getGlobalSettings().attrShifts[attrID];
|
|
|
|
debug(11, "Attribute %x from object %x is %x", attrID, objID, res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-06-16 23:04:10 +02:00
|
|
|
bool MacVenture::World::isObjActive(ObjID obj) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-13 20:29:08 +02:00
|
|
|
bool World::loadStartGameFileName() {
|
|
|
|
Common::SeekableReadStream *res;
|
|
|
|
|
|
|
|
res = _resourceManager->getResource(MKTAG('S', 'T', 'R', ' '), kStartGameFilenameID);
|
|
|
|
if (!res)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
byte length = res->readByte();
|
|
|
|
char *fileName = new char[length + 1];
|
|
|
|
res->read(fileName, length);
|
|
|
|
fileName[length] = '\0';
|
|
|
|
_startGameFileName = Common::String(fileName, length);
|
2016-06-15 00:21:57 +02:00
|
|
|
_startGameFileName.replace(_startGameFileName.end(), _startGameFileName.end(), ".bin");
|
2016-06-13 20:29:08 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveGame
|
|
|
|
SaveGame::SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res) {
|
|
|
|
_groups = Common::Array<AttributeGroup>();
|
|
|
|
loadGroups(engine, res);
|
|
|
|
_globals = Common::Array<uint16>();
|
|
|
|
loadGlobals(engine, res);
|
|
|
|
_text = Common::String();
|
|
|
|
loadText(engine, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveGame::~SaveGame() {
|
|
|
|
}
|
|
|
|
|
|
|
|
const Common::Array<AttributeGroup>& MacVenture::SaveGame::getGroups() {
|
|
|
|
return _groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Common::Array<uint16>& MacVenture::SaveGame::getGlobals() {
|
|
|
|
return _globals;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Common::String & MacVenture::SaveGame::getText() {
|
|
|
|
return _text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveGame::loadGroups(MacVentureEngine *engine, Common::SeekableReadStream * res) {
|
|
|
|
GlobalSettings settings = engine->getGlobalSettings();
|
|
|
|
for (int i = 0; i < settings.numGroups; ++i) {
|
|
|
|
AttributeGroup g;
|
|
|
|
for (int j = 0; j < settings.numObjects; ++j)
|
|
|
|
g.push_back(res->readUint16BE());
|
|
|
|
|
|
|
|
_groups.push_back(g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveGame::loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream * res) {
|
|
|
|
GlobalSettings settings = engine->getGlobalSettings();
|
|
|
|
for (int i = 0; i < settings.numGlobals; ++i) {
|
|
|
|
_globals.push_back(res->readUint16BE());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveGame::loadText(MacVentureEngine *engine, Common::SeekableReadStream * res) {
|
|
|
|
_text = "Placeholder Console Text";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // End of namespace MacVenture
|