MACVENTURE: Add save game loading

This commit is contained in:
Borja Lorente 2016-06-13 20:29:08 +02:00
parent 9564866ec3
commit 5719ea3076
7 changed files with 275 additions and 7 deletions

View File

@ -37,12 +37,6 @@ enum {
kMaxMenuTitleLength = 30
};
enum {
kGlobalSettingsID = 0x80,
kDiplomaGeometryID = 0x81,
kTextHuffmanTableID = 0x83
};
MacVentureEngine::MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst) {
_gameDescription = gameDesc;
_rnd = new Common::RandomSource("macventure");
@ -79,6 +73,7 @@ Common::Error MacVentureEngine::run() {
error("Could not load the engine settings");
_gui = new Gui(this, _resourceManager);
_world = new World(this, _resourceManager);
_shouldQuit = false;
while (!_shouldQuit) {

View File

@ -31,12 +31,14 @@
#include "gui/debugger.h"
#include "macventure/gui.h"
#include "macventure/world.h"
struct ADGameDescription;
namespace MacVenture {
class Console;
class World;
enum {
kScreenWidth = 512,
@ -50,6 +52,19 @@ enum {
// the current limitation is 32 debug levels (1 << 31 is the last one)
};
enum {
kGlobalSettingsID = 0x80,
kDiplomaGeometryID = 0x81,
kTextHuffmanTableID = 0x83
};
enum {
kSaveGameStrID = 0x82,
kDiplomaFilenameID = 0x83,
kClickToContinueTextID = 0x84,
kStartGameFilenameID = 0x85
};
struct GlobalSettings {
uint16 numObjects; // number of game objects defined
uint16 numGlobals; // number of globals defined
@ -102,6 +117,7 @@ private: // Attributes
Console *_debugger;
Gui *_gui;
World *_world;
// Engine state
GlobalSettings _globalSettings;

View File

@ -3,7 +3,9 @@ MODULE := engines/macventure
MODULE_OBJS := \
detection.o \
gui.o \
macventure.o
object.o \
macventure.o \
world.o \
MODULE_DIRS += \
engines/macventure

View File

@ -0,0 +1,30 @@
/* 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 "macventure/object.h"
namespace MacVenture {
Object::Object() {}
Object::~Object() {}
} // End of namespace MacVenture

View File

@ -0,0 +1,54 @@
/* 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 MACVENTURE_OBJECT_H
#define MACVENTURE_OBJECT_H
#include "macventure/macventure.h"
namespace MacVenture {
struct ContainerHeader {
uint32 header;
};
struct ObjectGroup {
uint32 bitOffset; // Actually uint24, but we don't have that
uint32 offset;
};
struct ContainerSubHeader {
uint16 numObjects;
uint16 *huff;
uint8 *lengths;
ObjectGroup *groups;
};
class Object {
public:
Object();
~Object();
};
} // End of namespace MacVenture
#endif

View File

@ -0,0 +1,98 @@
#include "macventure/world.h"
#include "common/file.h"
namespace MacVenture {
World::World(MacVentureEngine *engine, Common::MacResManager *resMan) {
_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());
_saveGame = new SaveGame(_engine, saveGameRes);
delete saveGameRes;
saveGameFile.close();
}
World::~World() {
if (_saveGame)
delete _saveGame;
}
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);
_startGameFileName.replace(_startGameFileName.end(), _startGameFileName.end(), ".TXT");
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

View File

@ -0,0 +1,73 @@
/* 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 MACVENTURE_WORLD_H
#define MACVENTURE_WORLD_H
#include "macventure/macventure.h"
namespace MacVenture {
typedef Common::Array<uint16> AttributeGroup;
class SaveGame {
public:
SaveGame(MacVentureEngine *engine, Common::SeekableReadStream *res);
~SaveGame();
const Common::Array<AttributeGroup> &getGroups();
const Common::Array<uint16> &getGlobals();
const Common::String &getText();
private:
void loadGroups(MacVentureEngine *engine, Common::SeekableReadStream *res);
void loadGlobals(MacVentureEngine *engine, Common::SeekableReadStream *res);
void loadText(MacVentureEngine *engine, Common::SeekableReadStream *res);
private:
Common::Array<AttributeGroup> _groups;
Common::Array<uint16> _globals;
Common::String _text;
};
class World {
public:
World(MacVentureEngine *engine, Common::MacResManager *resMan);
~World();
private:
bool loadStartGameFileName();
private:
MacVentureEngine *_engine;
Common::MacResManager *_resourceManager;
Common::String _startGameFileName;
SaveGame *_saveGame;
};
} // End of namespace MacVenture
#endif