2008-06-07 19:40:43 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
|
|
|
|
2008-06-07 19:40:43 +00:00
|
|
|
#include "drascula/drascula.h"
|
|
|
|
|
|
|
|
namespace Drascula {
|
|
|
|
|
2011-08-24 07:39:05 +00:00
|
|
|
/**
|
|
|
|
* Loads the save names from the EPA index file.
|
|
|
|
*
|
|
|
|
* TODO: We should move the save names in their respective save files and get
|
|
|
|
* rid of this completely. A good example is the sword1 engine, which also used
|
|
|
|
* to have an index file for its saves, that has been removed.
|
|
|
|
* sword1 contains code that converts the old index-based saves into the new
|
|
|
|
* format without the index file, so we could apply this idea to drascula as
|
|
|
|
* well.
|
|
|
|
*/
|
|
|
|
void DrasculaEngine::loadSaveNames() {
|
2008-06-07 19:40:43 +00:00
|
|
|
Common::InSaveFile *sav;
|
2011-06-02 01:53:48 +00:00
|
|
|
Common::String fileEpa = Common::String::format("%s.epa", _targetName.c_str());
|
2011-08-24 07:39:05 +00:00
|
|
|
|
|
|
|
// Create and initialize the index file, if it doesn't exist
|
2008-06-07 19:40:43 +00:00
|
|
|
if (!(sav = _saveFileMan->openForLoading(fileEpa))) {
|
|
|
|
Common::OutSaveFile *epa;
|
|
|
|
if (!(epa = _saveFileMan->openForSaving(fileEpa)))
|
2011-06-02 01:53:48 +00:00
|
|
|
error("Can't open %s file", fileEpa.c_str());
|
2011-08-24 07:39:05 +00:00
|
|
|
for (int n = 0; n < NUM_SAVES; n++)
|
2008-06-07 19:40:43 +00:00
|
|
|
epa->writeString("*\n");
|
|
|
|
epa->finalize();
|
|
|
|
delete epa;
|
|
|
|
if (!(sav = _saveFileMan->openForLoading(fileEpa))) {
|
2011-06-02 01:53:48 +00:00
|
|
|
error("Can't open %s file", fileEpa.c_str());
|
2008-06-07 19:40:43 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-24 07:39:05 +00:00
|
|
|
|
|
|
|
// Load the index file
|
|
|
|
for (int n = 0; n < NUM_SAVES; n++) {
|
|
|
|
strncpy(_saveNames[n], sav->readLine().c_str(), 23);
|
|
|
|
_saveNames[n][22] = '\0'; // make sure the savegame name is 0-terminated
|
2008-12-03 08:59:12 +00:00
|
|
|
}
|
2008-06-07 19:40:43 +00:00
|
|
|
delete sav;
|
2011-08-24 07:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the save names into the EPA index file.
|
|
|
|
*
|
|
|
|
* TODO: We should move the save names in their respective save files and get
|
|
|
|
* rid of this completely. A good example is the sword1 engine, which also used
|
|
|
|
* to have an index file for its saves, that has been removed.
|
|
|
|
* sword1 contains code that converts the old index-based saves into the new
|
|
|
|
* format without the index file, so we could apply this idea to drascula as
|
|
|
|
* well.
|
|
|
|
*/
|
|
|
|
void DrasculaEngine::saveSaveNames() {
|
|
|
|
Common::OutSaveFile *tsav;
|
|
|
|
Common::String fileEpa = Common::String::format("%s.epa", _targetName.c_str());
|
|
|
|
|
|
|
|
if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
|
|
|
|
error("Can't open %s file", fileEpa.c_str());
|
|
|
|
}
|
|
|
|
for (int n = 0; n < NUM_SAVES; n++) {
|
|
|
|
tsav->writeString(_saveNames[n]);
|
|
|
|
tsav->writeString("\n");
|
|
|
|
}
|
|
|
|
tsav->finalize();
|
|
|
|
delete tsav;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrasculaEngine::saveLoadScreen() {
|
|
|
|
Common::String file;
|
|
|
|
int n, n2, num_sav = 0, y = 27;
|
|
|
|
|
|
|
|
clearRoom();
|
|
|
|
|
|
|
|
loadSaveNames();
|
2008-06-07 19:40:43 +00:00
|
|
|
|
2008-06-10 18:54:32 +00:00
|
|
|
loadPic("savescr.alg", bgSurface, HALF_PAL);
|
2008-06-07 19:40:43 +00:00
|
|
|
|
|
|
|
color_abc(kColorLightGreen);
|
|
|
|
|
|
|
|
select[0] = 0;
|
|
|
|
|
2008-08-10 17:13:24 +00:00
|
|
|
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
|
2008-09-11 09:31:45 +00:00
|
|
|
setCursor(kCursorCrosshair);
|
2008-08-10 17:13:24 +00:00
|
|
|
|
2011-01-28 08:07:50 +00:00
|
|
|
while (!shouldQuit()) {
|
2008-06-07 19:40:43 +00:00
|
|
|
y = 27;
|
2008-08-26 08:21:21 +00:00
|
|
|
copyBackground();
|
2008-06-07 19:40:43 +00:00
|
|
|
for (n = 0; n < NUM_SAVES; n++) {
|
2011-08-24 07:39:05 +00:00
|
|
|
print_abc(_saveNames[n], 116, y);
|
2008-06-07 19:40:43 +00:00
|
|
|
y = y + 9;
|
|
|
|
}
|
|
|
|
print_abc(select, 117, 15);
|
|
|
|
updateScreen();
|
|
|
|
y = 27;
|
|
|
|
|
|
|
|
updateEvents();
|
|
|
|
|
|
|
|
if (leftMouseButton == 1) {
|
|
|
|
delay(50);
|
|
|
|
for (n = 0; n < NUM_SAVES; n++) {
|
|
|
|
if (mouseX > 115 && mouseY > y + (9 * n) && mouseX < 115 + 175 && mouseY < y + 10 + (9 * n)) {
|
2011-08-24 07:39:05 +00:00
|
|
|
strcpy(select, _saveNames[n]);
|
2008-06-07 19:40:43 +00:00
|
|
|
|
|
|
|
if (strcmp(select, "*"))
|
|
|
|
selectionMade = 1;
|
|
|
|
else {
|
|
|
|
enterName();
|
2011-08-24 07:39:05 +00:00
|
|
|
strcpy(_saveNames[n], select);
|
2008-06-07 19:40:43 +00:00
|
|
|
if (selectionMade == 1) {
|
2011-06-02 01:53:48 +00:00
|
|
|
file = Common::String::format("%s%02d", _targetName.c_str(), n + 1);
|
|
|
|
saveGame(file.c_str());
|
2011-08-24 07:39:05 +00:00
|
|
|
saveSaveNames();
|
2008-06-07 19:40:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print_abc(select, 117, 15);
|
|
|
|
y = 27;
|
|
|
|
for (n2 = 0; n2 < NUM_SAVES; n2++) {
|
2011-08-24 07:39:05 +00:00
|
|
|
print_abc(_saveNames[n2], 116, y);
|
2008-06-07 19:40:43 +00:00
|
|
|
y = y + 9;
|
|
|
|
}
|
|
|
|
if (selectionMade == 1) {
|
2011-06-02 01:53:48 +00:00
|
|
|
file = Common::String::format("%s%02d", _targetName.c_str(), n + 1);
|
2008-06-07 19:40:43 +00:00
|
|
|
}
|
|
|
|
num_sav = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mouseX > 117 && mouseY > 15 && mouseX < 295 && mouseY < 24 && selectionMade == 1) {
|
|
|
|
enterName();
|
2011-08-24 07:39:05 +00:00
|
|
|
strcpy(_saveNames[num_sav], select);
|
2008-06-07 19:40:43 +00:00
|
|
|
print_abc(select, 117, 15);
|
|
|
|
y = 27;
|
|
|
|
for (n2 = 0; n2 < NUM_SAVES; n2++) {
|
2011-08-24 07:39:05 +00:00
|
|
|
print_abc(_saveNames[n2], 116, y);
|
2008-06-07 19:40:43 +00:00
|
|
|
y = y + 9;
|
|
|
|
}
|
2008-06-10 22:41:41 +00:00
|
|
|
|
|
|
|
if (selectionMade == 1) {
|
2011-06-02 01:53:48 +00:00
|
|
|
file = Common::String::format("%s%02d", _targetName.c_str(), n + 1);
|
|
|
|
saveGame(file.c_str());
|
2011-08-24 07:39:05 +00:00
|
|
|
saveSaveNames();
|
2008-06-10 22:41:41 +00:00
|
|
|
}
|
2008-06-07 19:40:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mouseX > 125 && mouseY > 123 && mouseX < 199 && mouseY < 149 && selectionMade == 1) {
|
2011-06-02 01:53:48 +00:00
|
|
|
if (!loadGame(file.c_str())) {
|
2008-08-10 17:13:24 +00:00
|
|
|
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
|
2008-06-07 19:40:43 +00:00
|
|
|
return false;
|
2008-08-10 17:13:24 +00:00
|
|
|
}
|
2008-06-07 19:40:43 +00:00
|
|
|
break;
|
|
|
|
} else if (mouseX > 208 && mouseY > 123 && mouseX < 282 && mouseY < 149 && selectionMade == 1) {
|
2011-06-02 01:53:48 +00:00
|
|
|
saveGame(file.c_str());
|
2011-08-24 07:39:05 +00:00
|
|
|
saveSaveNames();
|
2008-06-07 19:40:43 +00:00
|
|
|
} else if (mouseX > 168 && mouseY > 154 && mouseX < 242 && mouseY < 180)
|
|
|
|
break;
|
|
|
|
else if (selectionMade == 0) {
|
|
|
|
print_abc("Please select a slot", 117, 15);
|
|
|
|
}
|
|
|
|
updateScreen();
|
|
|
|
delay(200);
|
|
|
|
}
|
|
|
|
y = 26;
|
|
|
|
|
|
|
|
delay(5);
|
|
|
|
}
|
|
|
|
|
2009-05-12 10:02:18 +00:00
|
|
|
selectVerb(kVerbNone);
|
2008-09-11 09:31:45 +00:00
|
|
|
|
2008-06-07 19:40:43 +00:00
|
|
|
clearRoom();
|
2008-06-10 18:54:32 +00:00
|
|
|
loadPic(roomNumber, bgSurface, HALF_PAL);
|
2008-06-07 19:40:43 +00:00
|
|
|
selectionMade = 0;
|
|
|
|
|
2008-08-10 17:13:24 +00:00
|
|
|
_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
|
|
|
|
|
2008-06-07 19:40:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrasculaEngine::loadGame(const char *gameName) {
|
|
|
|
int l, savedChapter, roomNum = 0;
|
|
|
|
Common::InSaveFile *sav;
|
|
|
|
|
|
|
|
previousMusic = roomMusic;
|
2009-05-13 11:59:49 +00:00
|
|
|
_menuScreen = false;
|
2008-06-07 19:40:43 +00:00
|
|
|
if (currentChapter != 1)
|
|
|
|
clearRoom();
|
|
|
|
|
|
|
|
if (!(sav = _saveFileMan->openForLoading(gameName))) {
|
|
|
|
error("missing savegame file");
|
|
|
|
}
|
|
|
|
|
|
|
|
savedChapter = sav->readSint32LE();
|
|
|
|
if (savedChapter != currentChapter) {
|
|
|
|
strcpy(saveName, gameName);
|
|
|
|
currentChapter = savedChapter - 1;
|
2008-09-11 09:31:45 +00:00
|
|
|
loadedDifferentChapter = 1;
|
2008-06-07 19:40:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sav->read(currentData, 20);
|
|
|
|
curX = sav->readSint32LE();
|
|
|
|
curY = sav->readSint32LE();
|
|
|
|
trackProtagonist = sav->readSint32LE();
|
|
|
|
|
2010-09-21 17:18:32 +00:00
|
|
|
for (l = 1; l < ARRAYSIZE(inventoryObjects); l++) {
|
2008-06-07 19:40:43 +00:00
|
|
|
inventoryObjects[l] = sav->readSint32LE();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (l = 0; l < NUM_FLAGS; l++) {
|
|
|
|
flags[l] = sav->readSint32LE();
|
|
|
|
}
|
|
|
|
|
|
|
|
takeObject = sav->readSint32LE();
|
|
|
|
pickedObject = sav->readSint32LE();
|
2008-09-11 09:31:45 +00:00
|
|
|
loadedDifferentChapter = 0;
|
2010-10-15 09:08:54 +00:00
|
|
|
if (!sscanf(currentData, "%d.ald", &roomNum)) {
|
|
|
|
error("Bad save format");
|
|
|
|
}
|
2008-06-07 19:40:43 +00:00
|
|
|
enterRoom(roomNum);
|
2009-05-12 10:02:18 +00:00
|
|
|
selectVerb(kVerbNone);
|
2008-06-07 19:40:43 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-02 01:53:48 +00:00
|
|
|
void DrasculaEngine::saveGame(const char *gameName) {
|
2008-06-07 19:40:43 +00:00
|
|
|
Common::OutSaveFile *out;
|
|
|
|
int l;
|
|
|
|
|
|
|
|
if (!(out = _saveFileMan->openForSaving(gameName))) {
|
|
|
|
error("Unable to open the file");
|
|
|
|
}
|
|
|
|
out->writeSint32LE(currentChapter);
|
|
|
|
out->write(currentData, 20);
|
|
|
|
out->writeSint32LE(curX);
|
|
|
|
out->writeSint32LE(curY);
|
|
|
|
out->writeSint32LE(trackProtagonist);
|
|
|
|
|
2010-09-21 17:18:32 +00:00
|
|
|
for (l = 1; l < ARRAYSIZE(inventoryObjects); l++) {
|
2008-06-07 19:40:43 +00:00
|
|
|
out->writeSint32LE(inventoryObjects[l]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (l = 0; l < NUM_FLAGS; l++) {
|
|
|
|
out->writeSint32LE(flags[l]);
|
|
|
|
}
|
|
|
|
|
|
|
|
out->writeSint32LE(takeObject);
|
|
|
|
out->writeSint32LE(pickedObject);
|
|
|
|
|
|
|
|
out->finalize();
|
2009-05-19 11:42:14 +00:00
|
|
|
if (out->err())
|
2008-06-07 19:40:43 +00:00
|
|
|
warning("Can't write file '%s'. (Disk full?)", gameName);
|
|
|
|
|
|
|
|
delete out;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Drascula
|