HOPKINS: Beginnings of save/load implementation

This commit is contained in:
Paul Gilbert 2012-10-27 22:16:54 +11:00
parent 1651bb07d9
commit ec0a33b949
6 changed files with 191 additions and 106 deletions

View File

@ -538,9 +538,7 @@ void DialogsManager::TEST_INVENT() {
// Load Game
void DialogsManager::CHARGE_PARTIE() {
int v1;
char v3;
byte *v4;
int v5;
char slotNumber;
Common::String s;
Common::String v8;
char v9;
@ -586,18 +584,15 @@ void DialogsManager::CHARGE_PARTIE() {
if (f.open(_vm->_globals.NFICHIER)) {
f.close();
v3 = _vm->_globals.SAUVEGARDE->data[svField10];
slotNumber = _vm->_globals.SAUVEGARDE->data[svField10];
_vm->_fileManager.CONSTRUIT_LINUX(v8);
_vm->_fileManager.bload(_vm->_globals.NFICHIER, &_vm->_globals.SAUVEGARDE->data[0]);
v4 = &_vm->_globals.SAUVEGARDE->data[svField1300];
v5 = 0;
do {
_vm->_globals.INVENTAIRE[v5] = (int16)READ_LE_UINT16(v4 + 2 * v5);
++v5;
} while (v5 <= 34);
// Load the inventory
for (int i = 0; i < 35; ++i)
_vm->_globals.INVENTAIRE[i] = _vm->_globals.SAUVEGARDE->inventory[i];
_vm->_globals.SAUVEGARDE->data[svField10] = v3;
_vm->_globals.SAUVEGARDE->data[svField10] = slotNumber;
_vm->_globals.SORTIE = _vm->_globals.SAUVEGARDE->data[svField5];
_vm->_globals.SAUVEGARDE->data[svField6] = 0;
_vm->_globals.ECRAN = 0;
@ -609,31 +604,19 @@ void DialogsManager::CHARGE_PARTIE() {
// Save Game
void DialogsManager::SAUVE_PARTIE() {
byte *v1;
int slotNumber;
byte *invItemP;
int v4;
Common::String s;
Common::String v7;
char v12;
char v13;
char v14;
char v15;
char v16;
Common::String saveName;
_vm->_eventsManager.VBL();
v1 = _vm->_globals.dos_malloc2(0x2DB4u);
_vm->_graphicsManager.Reduc_Ecran(_vm->_graphicsManager.VESA_BUFFER, v1, _vm->_eventsManager.start_x, 20,
SCREEN_WIDTH, SCREEN_HEIGHT - 40, 80);
_vm->_graphicsManager.INIT_TABLE(45, 80, _vm->_graphicsManager.Palette);
_vm->_graphicsManager.Trans_bloc2(v1, _vm->_graphicsManager.TABLE_COUL, 11136);
LOAD_SAUVE(1);
do {
do {
slotNumber = CHERCHE_PARTIE();
_vm->_eventsManager.VBL();
} while (_vm->_eventsManager.BMOUSE() != 1);
} while (!slotNumber);
} while (!_vm->shouldQuit() && _vm->_eventsManager.BMOUSE() != 1);
} while (!_vm->shouldQuit() && !slotNumber);
_vm->_objectsManager.SL_FLAG = 0;
_vm->_graphicsManager.SCOPY(_vm->_graphicsManager.VESA_SCREEN, _vm->_eventsManager.start_x + 183, 60, 274, 353, _vm->_graphicsManager.VESA_BUFFER, _vm->_eventsManager.start_x + 183, 60);
_vm->_graphicsManager.Ajoute_Segment_Vesa(_vm->_eventsManager.start_x + 183, 60, _vm->_eventsManager.start_x + 457, 413);
@ -648,34 +631,24 @@ void DialogsManager::SAUVE_PARTIE() {
_vm->_globals.SAUVEGARDE->data[svField10] = slotNumber;
// Set up the inventory
invItemP = &_vm->_globals.SAUVEGARDE->data[svField1300];
v4 = 0;
do {
WRITE_LE_UINT16(invItemP + 2 * v4, _vm->_globals.INVENTAIRE[v4]);
++v4;
} while (v4 <= 34);
for (int i = 0; i < 35; ++i)
_vm->_globals.SAUVEGARDE->inventory[i] = _vm->_globals.INVENTAIRE[i];
_vm->_fileManager.CONSTRUIT_LINUX(v7);
// SAUVE_FICHIER(_vm->_globals.NFICHIER, &_vm->_globals.SAUVEGARDE->data[0], 0x7D0u);
v12 = 46;
v13 = 69;
v14 = 67;
v15 = 82;
v16 = 0;
_vm->_fileManager.CONSTRUIT_LINUX(v7);
_vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, v1, 0x2B80u);
// Since the original GUI doesn't support save names, use a default name
saveName = Common::String::format("Save #%d", slotNumber);
// Save the game
_vm->_saveLoadManager.save(slotNumber, saveName);
}
_vm->_globals.dos_free2(v1);
}
// Load Save
void DialogsManager::LOAD_SAUVE(int a1) {
int v1;
// byte *v2;
// byte *v3;
Common::String s;
Common::File f;
int slotNumber;
hopkinsSavegameHeader header;
Common::InSaveFile *in;
byte *thumb;
switch (_vm->_globals.FR) {
case 0:
@ -706,32 +679,35 @@ void DialogsManager::LOAD_SAUVE(int a1) {
_vm->_graphicsManager.Sprite_Vesa(_vm->_graphicsManager.VESA_BUFFER, _vm->_objectsManager.SL_SPR, _vm->_eventsManager.start_x + 539, 372, 2);
}
v1 = 1;
do {
s = Common::String::format("ART%d.ECR", v1);
for (slotNumber = 1; slotNumber <= 6; ++slotNumber) {
if (_vm->_saveLoadManager.readSavegameHeader(slotNumber, header)) {
thumb = (byte *)header.thumbnail->pixels;
_vm->_fileManager.CONSTRUIT_LINUX(s);
/* TODO: Get from save file manager as part of save files
if (f.exists(_vm->_globals.NFICHIER)) {
v2 = _vm->_fileManager.CHARGE_FICHIER(_vm->_globals.NFICHIER);
v3 = v2;
if (v1 == 1)
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, v2, _vm->_eventsManager.start_x + 190, 112, 0x80u, 87);
if (v1 == 2)
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, v3, _vm->_eventsManager.start_x + 323, 112, 0x80u, 87);
if (v1 == 3)
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, v3, _vm->_eventsManager.start_x + 190, 203, 0x80u, 87);
if (v1 == 4)
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, v3, _vm->_eventsManager.start_x + 323, 203, 0x80u, 87);
if (v1 == 5)
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, v3, _vm->_eventsManager.start_x + 190, 294, 0x80u, 87);
if (v1 == 6)
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, v3, _vm->_eventsManager.start_x + 323, 294, 0x80u, 87);
_vm->_globals.dos_free2(v3);
switch (slotNumber) {
case 1:
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, thumb, _vm->_eventsManager.start_x + 190, 112, 0x80u, 87);
break;
case 2:
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, thumb, _vm->_eventsManager.start_x + 323, 112, 0x80u, 87);
break;
case 3:
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, thumb, _vm->_eventsManager.start_x + 190, 203, 0x80u, 87);
break;
case 4:
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, thumb, _vm->_eventsManager.start_x + 323, 203, 0x80u, 87);
break;
case 5:
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, thumb, _vm->_eventsManager.start_x + 190, 294, 0x80u, 87);
break;
case 6:
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, thumb, _vm->_eventsManager.start_x + 323, 294, 0x80u, 87);
break;
}
delete header.thumbnail;
}
*/
++v1;
} while (v1 <= 6);
}
_vm->_graphicsManager.Capture_Mem(_vm->_graphicsManager.VESA_BUFFER, _vm->_objectsManager.SL_SPR, _vm->_eventsManager.start_x + 183, 60, 0x112u, 353);
_vm->_objectsManager.SL_FLAG = 1;
_vm->_objectsManager.SL_MODE = a1;
@ -741,63 +717,64 @@ void DialogsManager::LOAD_SAUVE(int a1) {
// Search Game
int DialogsManager::CHERCHE_PARTIE() {
int v0;
int v1;
int v2;
int slotNumber;
int xp;
int yp;
slotNumber = 0;
xp = _vm->_eventsManager.XMOUSE();
yp = _vm->_eventsManager.YMOUSE();
v0 = 0;
v1 = _vm->_eventsManager.XMOUSE();
v2 = _vm->_eventsManager.YMOUSE();
_vm->_graphicsManager.ofscroll = _vm->_eventsManager.start_x;
if ((uint16)(v2 - 112) <= 0x56u) {
if (v1 > _vm->_eventsManager.start_x + 189 && v1 < _vm->_eventsManager.start_x + 318)
v0 = 1;
if ((uint16)(v2 - 112) <= 0x56u && v1 > _vm->_graphicsManager.ofscroll + 322 && v1 < _vm->_graphicsManager.ofscroll + 452)
v0 = 2;
if ((uint16)(yp - 112) <= 0x56u) {
if (xp > _vm->_eventsManager.start_x + 189 && xp < _vm->_eventsManager.start_x + 318)
slotNumber = 1;
if ((uint16)(yp - 112) <= 0x56u && xp > _vm->_graphicsManager.ofscroll + 322 && xp < _vm->_graphicsManager.ofscroll + 452)
slotNumber = 2;
}
if ((uint16)(v2 - 203) <= 0x56u) {
if (v1 > _vm->_graphicsManager.ofscroll + 189 && v1 < _vm->_graphicsManager.ofscroll + 318)
v0 = 3;
if ((uint16)(v2 - 203) <= 0x56u && v1 > _vm->_graphicsManager.ofscroll + 322 && v1 < _vm->_graphicsManager.ofscroll + 452)
v0 = 4;
if ((uint16)(yp - 203) <= 0x56u) {
if (xp > _vm->_graphicsManager.ofscroll + 189 && xp < _vm->_graphicsManager.ofscroll + 318)
slotNumber = 3;
if ((uint16)(yp - 203) <= 0x56u && xp > _vm->_graphicsManager.ofscroll + 322 && xp < _vm->_graphicsManager.ofscroll + 452)
slotNumber = 4;
}
if ((uint16)(v2 - 294) <= 0x56u) {
if (v1 > _vm->_graphicsManager.ofscroll + 189 && v1 < _vm->_graphicsManager.ofscroll + 318)
v0 = 5;
if ((uint16)(v2 - 294) <= 0x56u && v1 > _vm->_graphicsManager.ofscroll + 322 && v1 < _vm->_graphicsManager.ofscroll + 452)
v0 = 6;
if ((uint16)(yp - 294) <= 0x56u) {
if (xp > _vm->_graphicsManager.ofscroll + 189 && xp < _vm->_graphicsManager.ofscroll + 318)
slotNumber = 5;
if ((uint16)(yp - 294) <= 0x56u && xp > _vm->_graphicsManager.ofscroll + 322 && xp < _vm->_graphicsManager.ofscroll + 452)
slotNumber = 6;
}
if ((uint16)(v2 - 388) <= 0x10u && v1 > _vm->_graphicsManager.ofscroll + 273 && v1 < _vm->_graphicsManager.ofscroll + 355)
v0 = 7;
if (v0 == 1) {
if ((uint16)(yp - 388) <= 0x10u && xp > _vm->_graphicsManager.ofscroll + 273 && xp < _vm->_graphicsManager.ofscroll + 355)
slotNumber = 7;
if (slotNumber == 1) {
_vm->_objectsManager.SL_X = 189;
_vm->_objectsManager.SL_Y = 111;
}
if (v0 == 2) {
if (slotNumber == 2) {
_vm->_objectsManager.SL_X = 322;
_vm->_objectsManager.SL_Y = 111;
}
if (v0 == 3) {
if (slotNumber == 3) {
_vm->_objectsManager.SL_X = 189;
_vm->_objectsManager.SL_Y = 202;
}
if (v0 == 4) {
if (slotNumber == 4) {
_vm->_objectsManager.SL_X = 322;
_vm->_objectsManager.SL_Y = 202;
}
if (v0 == 5) {
if (slotNumber == 5) {
_vm->_objectsManager.SL_X = 189;
_vm->_objectsManager.SL_Y = 293;
}
if (v0 == 6) {
if (slotNumber == 6) {
_vm->_objectsManager.SL_X = 322;
_vm->_objectsManager.SL_Y = 293;
}
if (v0 == 7 || !v0) {
if (slotNumber == 7 || !slotNumber) {
_vm->_objectsManager.SL_X = 0;
_vm->_objectsManager.SL_Y = 0;
}
return v0;
return slotNumber;
}
} // End of namespace Hopkins

View File

@ -272,7 +272,6 @@ enum SauvegardeOffset {
, svField357 = 357
, svField399 = 399
, svField401 = 401
, svField1300 = 1300
};
// TODO: Sauvegrade1 fields should really be mapped into data array
@ -281,6 +280,7 @@ struct Sauvegarde {
Sauvegarde1 field360;
Sauvegarde1 field370;
Sauvegarde1 field380;
int16 inventory[35]; // Originally at offset 1300 of data array
};
class HopkinsEngine;

View File

@ -956,4 +956,8 @@ void HopkinsEngine::PUBQUIT() {
_graphicsManager.FADE_OUTW();
}
Common::String HopkinsEngine::generateSaveName(int slot) {
return Common::String::format("%s.%03d", _targetName.c_str(), slot);
}
} // End of namespace Hopkins

View File

@ -124,6 +124,7 @@ public:
bool shouldQuit() const;
int getRandomNumber(int maxNumber);
Common::String generateSaveName(int slotNumber);
/**
* Run the introduction sequence

View File

@ -121,7 +121,7 @@ void SaveLoadManager::writeSavegameHeader(Common::OutSaveFile *out, hopkinsSaveg
// Create a thumbnail and save it
Graphics::Surface *thumb = new Graphics::Surface();
// ::createThumbnail(thumb, _vm->_graphicsManager.VESA_SCREEN, SCREEN_WIDTH, SCREEN_HEIGHT, NULL);
createThumbnail(thumb);
Graphics::saveThumbnail(*out, *thumb);
thumb->free();
delete thumb;
@ -137,4 +137,100 @@ void SaveLoadManager::writeSavegameHeader(Common::OutSaveFile *out, hopkinsSaveg
out->writeUint32LE(_vm->_eventsManager._gameCounter);
}
Common::Error SaveLoadManager::save(int slot, const Common::String &saveName) {
// Try and create the save file
Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(
_vm->generateSaveName(slot));
if (!saveFile)
return Common::kCreatingFileFailed;
// Set up the serializer
Common::Serializer serializer(NULL, saveFile);
// Write out the savegame header
hopkinsSavegameHeader header;
header.saveName = saveName;
header.version = HOPKINS_SAVEGAME_VERSION;
writeSavegameHeader(saveFile, header);
// Write out the savegame data
syncSavegameData(serializer);
// Save file complete
saveFile->finalize();
delete saveFile;
return Common::kNoError;
}
Common::Error SaveLoadManager::restore(int slot) {
// Try and open the save file for reading
Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(
_vm->generateSaveName(slot));
if (!saveFile)
return Common::kReadingFailed;
// Set up the serializer
Common::Serializer serializer(saveFile, NULL);
// Read in the savegame header
hopkinsSavegameHeader header;
readSavegameHeader(saveFile, header);
if (header.thumbnail)
header.thumbnail->free();
delete header.thumbnail;
// Read in the savegame data
syncSavegameData(serializer);
// Loading save file complete
delete saveFile;
return Common::kNoError;
}
bool SaveLoadManager::readSavegameHeader(int slot, hopkinsSavegameHeader &header) {
// Try and open the save file for reading
Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(
g_vm->generateSaveName(slot));
if (!saveFile)
return false;
bool result = readSavegameHeader(saveFile, header);
delete saveFile;
return result;
}
#define REDUCE_AMOUNT 80
void SaveLoadManager::createThumbnail(Graphics::Surface *s) {
int w = _vm->_graphicsManager.Reel_Reduc(SCREEN_WIDTH, REDUCE_AMOUNT);
int h = _vm->_graphicsManager.Reel_Reduc(SCREEN_HEIGHT - 40, REDUCE_AMOUNT);
s->create(w, h, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
_vm->_graphicsManager.Reduc_Ecran(_vm->_graphicsManager.VESA_BUFFER, (byte *)s->pixels,
_vm->_eventsManager.start_x, 20, SCREEN_WIDTH, SCREEN_HEIGHT - 40, 80);
_vm->_graphicsManager.INIT_TABLE(45, 80, _vm->_graphicsManager.Palette);
_vm->_graphicsManager.Trans_bloc2((byte *)s->pixels, _vm->_graphicsManager.TABLE_COUL, 11136);
}
void SaveLoadManager::syncSavegameData(Common::Serializer &s) {
s.syncBytes(&_vm->_globals.SAUVEGARDE->data[0], 0x802);
syncSauvegarde1(s, _vm->_globals.SAUVEGARDE->field360);
syncSauvegarde1(s, _vm->_globals.SAUVEGARDE->field370);
syncSauvegarde1(s, _vm->_globals.SAUVEGARDE->field380);
for (int i = 0; i < 35; ++i)
s.syncAsSint16LE(_vm->_globals.SAUVEGARDE->inventory[i]);
}
void SaveLoadManager::syncSauvegarde1(Common::Serializer &s, Sauvegarde1 &item) {
s.syncAsSint16LE(item.field0);
s.syncAsSint16LE(item.field1);
s.syncAsSint16LE(item.field2);
s.syncAsSint16LE(item.field3);
s.syncAsSint16LE(item.field4);
}
} // End of namespace Hopkins

View File

@ -25,7 +25,9 @@
#include "common/scummsys.h"
#include "common/savefile.h"
#include "common/serializer.h"
#include "common/str.h"
#include "hopkins/globals.h"
namespace Hopkins {
@ -45,6 +47,10 @@ struct hopkinsSavegameHeader {
class SaveLoadManager {
private:
HopkinsEngine *_vm;
void createThumbnail(Graphics::Surface *s);
void syncSavegameData(Common::Serializer &s);
void syncSauvegarde1(Common::Serializer &s, Sauvegarde1 &item);
public:
void setParent(HopkinsEngine *vm);
@ -55,6 +61,7 @@ public:
static bool readSavegameHeader(Common::InSaveFile *in, hopkinsSavegameHeader &header);
void writeSavegameHeader(Common::OutSaveFile *out, hopkinsSavegameHeader &header);
static bool readSavegameHeader(int slot, hopkinsSavegameHeader &header);
Common::Error save(int slot, const Common::String &saveName);
Common::Error restore(int slot);
};