AGI: Switched to Common::String in the save/load code
This commit is contained in:
parent
c8777b774f
commit
0e4b35a8e8
4 changed files with 35 additions and 42 deletions
|
@ -809,8 +809,8 @@ public:
|
|||
virtual void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
|
||||
int16 p4, int16 p5, int16 p6, int16 p7) = 0;
|
||||
virtual void releaseImageStack() = 0;
|
||||
virtual int saveGame(const char *fileName, const char *saveName) = 0;
|
||||
virtual int loadGame(const char *fileName, bool checkId = true) = 0;
|
||||
virtual int saveGame(Common::String fileName, Common::String saveName) = 0;
|
||||
virtual int loadGame(Common::String fileName, bool checkId = true) = 0;
|
||||
|
||||
int _soundemu;
|
||||
|
||||
|
@ -881,13 +881,13 @@ public:
|
|||
|
||||
StringData _stringdata;
|
||||
|
||||
void getSavegameFilename(int num, char *fileName);
|
||||
Common::String getSavegameFilename(int num);
|
||||
void getSavegameDescription(int num, char *buf, bool showEmpty = true);
|
||||
int selectSlot();
|
||||
int saveGame(const char *fileName, const char *saveName);
|
||||
int saveGame(Common::String fileName, Common::String saveName);
|
||||
int loadGame(Common::String fileName, bool checkId = true);
|
||||
int saveGameDialog();
|
||||
int saveGameSimple();
|
||||
int loadGame(const char *fileName, bool checkId = true);
|
||||
int loadGameDialog();
|
||||
int loadGameSimple();
|
||||
|
||||
|
|
|
@ -361,9 +361,7 @@ int AgiEngine::playGame() {
|
|||
}
|
||||
|
||||
if (shouldPerformAutoSave(_lastSaveTime)) {
|
||||
char fileName[MAXPATHLEN];
|
||||
getSavegameFilename(0, fileName);
|
||||
saveGame(fileName, "Autosave");
|
||||
saveGame(getSavegameFilename(0), "Autosave");
|
||||
}
|
||||
|
||||
} while (!(shouldQuit() || _restartGame));
|
||||
|
|
|
@ -73,8 +73,8 @@ protected:
|
|||
void replayImageStackCall(uint8 type, int16 p1, int16 p2, int16 p3,
|
||||
int16 p4, int16 p5, int16 p6, int16 p7) {}
|
||||
void releaseImageStack() {}
|
||||
int saveGame(const char *fileName, const char *saveName) { return -1; }
|
||||
int loadGame(const char *fileName, bool checkId = true) { return -1; }
|
||||
int saveGame(Common::String fileName, Common::String saveName) { return -1; }
|
||||
int loadGame(Common::String fileName, bool checkId = true) { return -1; }
|
||||
|
||||
// Game
|
||||
Common::String getTargetName() { return _targetName; }
|
||||
|
|
|
@ -53,22 +53,22 @@ namespace Agi {
|
|||
|
||||
static const uint32 AGIflag = MKTAG('A','G','I',':');
|
||||
|
||||
int AgiEngine::saveGame(const char *fileName, const char *description) {
|
||||
int AgiEngine::saveGame(Common::String fileName, Common::String description) {
|
||||
char gameIDstring[8] = "gameIDX";
|
||||
int i;
|
||||
Common::OutSaveFile *out;
|
||||
int result = errOK;
|
||||
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "AgiEngine::saveGame(%s, %s)", fileName, description);
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "AgiEngine::saveGame(%s, %s)", fileName.c_str(), description);
|
||||
if (!(out = _saveFileMan->openForSaving(fileName))) {
|
||||
warning("Can't create file '%s', game not saved", fileName);
|
||||
warning("Can't create file '%s', game not saved", fileName.c_str());
|
||||
return errBadFileOpen;
|
||||
} else {
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "Successfully opened %s for writing", fileName);
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "Successfully opened %s for writing", fileName.c_str());
|
||||
}
|
||||
|
||||
out->writeUint32BE(AGIflag);
|
||||
out->write(description, 31);
|
||||
out->write(description.c_str(), 31);
|
||||
|
||||
out->writeByte(SAVEGAME_VERSION);
|
||||
debugC(5, kDebugLevelMain | kDebugLevelSavegame, "Writing save game version (%d)", SAVEGAME_VERSION);
|
||||
|
@ -239,33 +239,33 @@ int AgiEngine::saveGame(const char *fileName, const char *description) {
|
|||
|
||||
out->finalize();
|
||||
if (out->err()) {
|
||||
warning("Can't write file '%s'. (Disk full?)", fileName);
|
||||
warning("Can't write file '%s'. (Disk full?)", fileName.c_str());
|
||||
result = errIOError;
|
||||
} else
|
||||
debugC(1, kDebugLevelMain | kDebugLevelSavegame, "Saved game %s in file %s", description, fileName);
|
||||
debugC(1, kDebugLevelMain | kDebugLevelSavegame, "Saved game %s in file %s", description, fileName.c_str());
|
||||
|
||||
delete out;
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "Closed %s", fileName);
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "Closed %s", fileName.c_str());
|
||||
|
||||
_lastSaveTime = _system->getMillis();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int AgiEngine::loadGame(const char *fileName, bool checkId) {
|
||||
int AgiEngine::loadGame(Common::String fileName, bool checkId) {
|
||||
char description[31], saveVersion, loadId[8];
|
||||
int i, vtEntries = MAX_VIEWTABLE;
|
||||
uint8 t;
|
||||
int16 parm[7];
|
||||
Common::InSaveFile *in;
|
||||
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "AgiEngine::loadGame(%s)", fileName);
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "AgiEngine::loadGame(%s)", fileName.c_str());
|
||||
|
||||
if (!(in = _saveFileMan->openForLoading(fileName))) {
|
||||
warning("Can't open file '%s', game not loaded", fileName);
|
||||
warning("Can't open file '%s', game not loaded", fileName.c_str());
|
||||
return errBadFileOpen;
|
||||
} else {
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "Successfully opened %s for reading", fileName);
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "Successfully opened %s for reading", fileName.c_str());
|
||||
}
|
||||
|
||||
uint32 typea = in->readUint32BE();
|
||||
|
@ -527,7 +527,7 @@ int AgiEngine::loadGame(const char *fileName, bool checkId) {
|
|||
_gfx->setAGIPal(in->readSint16BE());
|
||||
|
||||
delete in;
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "Closed %s", fileName);
|
||||
debugC(3, kDebugLevelMain | kDebugLevelSavegame, "Closed %s", fileName.c_str());
|
||||
|
||||
setflag(fRestoreJustRan, true);
|
||||
|
||||
|
@ -546,28 +546,27 @@ int AgiEngine::loadGame(const char *fileName, bool checkId) {
|
|||
#define NUM_SLOTS 100
|
||||
#define NUM_VISIBLE_SLOTS 12
|
||||
|
||||
void AgiEngine::getSavegameFilename(int num, char *fileName) {
|
||||
Common::String AgiEngine::getSavegameFilename(int num) {
|
||||
Common::String saveLoadSlot = _targetName;
|
||||
saveLoadSlot += Common::String::format(".%.3d", num);
|
||||
strcpy(fileName, saveLoadSlot.c_str());
|
||||
return saveLoadSlot;
|
||||
}
|
||||
|
||||
void AgiEngine::getSavegameDescription(int num, char *buf, bool showEmpty) {
|
||||
char fileName[MAXPATHLEN];
|
||||
Common::InSaveFile *in;
|
||||
Common::String fileName = getSavegameFilename(num);
|
||||
|
||||
debugC(4, kDebugLevelMain | kDebugLevelSavegame, "Current game id is %s", _targetName.c_str());
|
||||
getSavegameFilename(num, fileName);
|
||||
|
||||
if (!(in = _saveFileMan->openForLoading(fileName))) {
|
||||
debugC(4, kDebugLevelMain | kDebugLevelSavegame, "File %s does not exist", fileName);
|
||||
debugC(4, kDebugLevelMain | kDebugLevelSavegame, "File %s does not exist", fileName.c_str());
|
||||
|
||||
if (showEmpty)
|
||||
strcpy(buf, " (empty slot)");
|
||||
else
|
||||
*buf = 0;
|
||||
} else {
|
||||
debugC(4, kDebugLevelMain | kDebugLevelSavegame, "Successfully opened %s for reading", fileName);
|
||||
debugC(4, kDebugLevelMain | kDebugLevelSavegame, "Successfully opened %s for reading", fileName.c_str());
|
||||
|
||||
uint32 type = in->readUint32BE();
|
||||
|
||||
|
@ -783,7 +782,6 @@ getout:
|
|||
}
|
||||
|
||||
int AgiEngine::saveGameDialog() {
|
||||
char fileName[MAXPATHLEN];
|
||||
char *desc;
|
||||
const char *buttons[] = { "Do as I say!", "I regret", NULL };
|
||||
char dstr[200];
|
||||
|
@ -853,14 +851,14 @@ int AgiEngine::saveGameDialog() {
|
|||
return errOK;
|
||||
}
|
||||
|
||||
getSavegameFilename(_firstSlot + slot, fileName);
|
||||
debugC(8, kDebugLevelMain | kDebugLevelResources, "file is [%s]", fileName);
|
||||
Common::String fileName = getSavegameFilename(_firstSlot + slot);
|
||||
debugC(8, kDebugLevelMain | kDebugLevelResources, "file is [%s]", fileName.c_str());
|
||||
|
||||
// Make sure all graphics was blitted to screen. This fixes bug
|
||||
// #2960567: "AGI: Ego partly erased in Load/Save thumbnails"
|
||||
_gfx->doUpdate();
|
||||
|
||||
int result = saveGame(fileName, desc);
|
||||
int result = saveGame(fileName.c_str(), desc);
|
||||
|
||||
if (result == errOK)
|
||||
messageBox("Game saved.");
|
||||
|
@ -871,17 +869,15 @@ int AgiEngine::saveGameDialog() {
|
|||
}
|
||||
|
||||
int AgiEngine::saveGameSimple() {
|
||||
char fileName[MAXPATHLEN];
|
||||
getSavegameFilename(0, fileName);
|
||||
Common::String fileName = getSavegameFilename(0);
|
||||
|
||||
int result = saveGame(fileName, "Default savegame");
|
||||
int result = saveGame(fileName.c_str(), "Default savegame");
|
||||
if (result != errOK)
|
||||
messageBox("Error saving game.");
|
||||
return result;
|
||||
}
|
||||
|
||||
int AgiEngine::loadGameDialog() {
|
||||
char fileName[MAXPATHLEN];
|
||||
int rc, slot = 0;
|
||||
int hm, vm, hp, vp; // box margins
|
||||
int w;
|
||||
|
@ -908,9 +904,9 @@ int AgiEngine::loadGameDialog() {
|
|||
return errOK;
|
||||
}
|
||||
|
||||
getSavegameFilename(_firstSlot + slot, fileName);
|
||||
Common::String fileName = getSavegameFilename(_firstSlot + slot);
|
||||
|
||||
if ((rc = loadGame(fileName)) == errOK) {
|
||||
if ((rc = loadGame(fileName.c_str())) == errOK) {
|
||||
messageBox("Game restored.");
|
||||
_game.exitAllLogics = 1;
|
||||
_menu->enableAll();
|
||||
|
@ -922,16 +918,15 @@ int AgiEngine::loadGameDialog() {
|
|||
}
|
||||
|
||||
int AgiEngine::loadGameSimple() {
|
||||
char fileName[MAXPATHLEN];
|
||||
int rc = 0;
|
||||
|
||||
getSavegameFilename(0, fileName);
|
||||
Common::String fileName = getSavegameFilename(0);
|
||||
|
||||
_sprites->eraseBoth();
|
||||
_sound->stopSound();
|
||||
closeWindow();
|
||||
|
||||
if ((rc = loadGame(fileName)) == errOK) {
|
||||
if ((rc = loadGame(fileName.c_str())) == errOK) {
|
||||
messageBox("Game restored.");
|
||||
_game.exitAllLogics = 1;
|
||||
_menu->enableAll();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue