diff options
author | Nicola Mettifogo | 2008-08-31 06:14:45 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2008-08-31 06:14:45 +0000 |
commit | 1fd91e2bb0ee5fa56c7e078d18f6d338d5985cfd (patch) | |
tree | bb83f0ef2c90ce7fb535405cc63cdac5928170ab /engines | |
parent | 983863bef3f72b81cd0c1211241c64670c4e3e18 (diff) | |
download | scummvm-rg350-1fd91e2bb0ee5fa56c7e078d18f6d338d5985cfd.tar.gz scummvm-rg350-1fd91e2bb0ee5fa56c7e078d18f6d338d5985cfd.tar.bz2 scummvm-rg350-1fd91e2bb0ee5fa56c7e078d18f6d338d5985cfd.zip |
Moved save/load code into SaveLoad class.
svn-id: r34220
Diffstat (limited to 'engines')
-rw-r--r-- | engines/parallaction/callables_ns.cpp | 3 | ||||
-rw-r--r-- | engines/parallaction/gui_br.cpp | 3 | ||||
-rw-r--r-- | engines/parallaction/gui_ns.cpp | 5 | ||||
-rw-r--r-- | engines/parallaction/parallaction.cpp | 5 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 25 | ||||
-rw-r--r-- | engines/parallaction/parallaction_br.cpp | 3 | ||||
-rw-r--r-- | engines/parallaction/parallaction_ns.cpp | 9 | ||||
-rw-r--r-- | engines/parallaction/saveload.cpp | 137 | ||||
-rw-r--r-- | engines/parallaction/saveload.h | 96 |
9 files changed, 198 insertions, 88 deletions
diff --git a/engines/parallaction/callables_ns.cpp b/engines/parallaction/callables_ns.cpp index cb761e0ffe..7915daa0b8 100644 --- a/engines/parallaction/callables_ns.cpp +++ b/engines/parallaction/callables_ns.cpp @@ -32,6 +32,7 @@ #include "parallaction/input.h" #include "parallaction/parallaction.h" +#include "parallaction/saveload.h" #include "parallaction/sound.h" @@ -341,7 +342,7 @@ void Parallaction_ns::_c_frankenstein(void *parm) { void Parallaction_ns::_c_finito(void *parm) { - setPartComplete(_char); + _saveLoad->setPartComplete(_char.getBaseName()); cleanInventory(); cleanupGame(); diff --git a/engines/parallaction/gui_br.cpp b/engines/parallaction/gui_br.cpp index 163e3a5b45..4c98cc4634 100644 --- a/engines/parallaction/gui_br.cpp +++ b/engines/parallaction/gui_br.cpp @@ -28,6 +28,7 @@ #include "parallaction/gui.h" #include "parallaction/input.h" #include "parallaction/parallaction.h" +#include "parallaction/saveload.h" namespace Parallaction { @@ -223,7 +224,7 @@ public: _availItems = 4; bool complete[3]; - _vm->getGamePartProgress(complete, 3); + _vm->_saveLoad->getGamePartProgress(complete, 3); for (int i = 0; i < 3 && complete[i]; i++, _availItems++) ; // TODO: keep track of and destroy menu item frames/surfaces diff --git a/engines/parallaction/gui_ns.cpp b/engines/parallaction/gui_ns.cpp index 2807f6790f..5d7425fb1f 100644 --- a/engines/parallaction/gui_ns.cpp +++ b/engines/parallaction/gui_ns.cpp @@ -29,6 +29,7 @@ #include "parallaction/gui.h" #include "parallaction/input.h" #include "parallaction/parallaction.h" +#include "parallaction/saveload.h" #include "parallaction/sound.h" @@ -284,7 +285,7 @@ public: } virtual void enter() { - _result = _vm->loadGame(); + _result = _vm->_saveLoad->loadGame(); } }; @@ -759,7 +760,7 @@ public: virtual void enter() { bool completed[3]; - _vm->getGamePartProgress(completed, 3); + _vm->_saveLoad->getGamePartProgress(completed, 3); _allPartsComplete = (completed[0] && completed[1] && completed[2]); _vm->_input->setMouseState(MOUSE_DISABLED); diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index d0700232d1..c02c9b7ce6 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -35,6 +35,7 @@ #include "parallaction/input.h" #include "parallaction/parallaction.h" #include "parallaction/debug.h" +#include "parallaction/saveload.h" #include "parallaction/sound.h" @@ -307,13 +308,13 @@ void Parallaction::processInput(int event) { switch (event) { case kEvSaveGame: _input->stopHovering(); - saveGame(); + _saveLoad->saveGame(); _input->setArrowCursor(); break; case kEvLoadGame: _input->stopHovering(); - loadGame(); + _saveLoad->loadGame(); _input->setArrowCursor(); break; diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index 63cdc9cfc5..c74f479de2 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -205,6 +205,7 @@ public: }; +class SaveLoad; #define NUM_LOCATIONS 120 @@ -218,9 +219,6 @@ public: int init(); - virtual bool loadGame() = 0; - virtual bool saveGame() = 0; - Input *_input; void processInput(int event); @@ -296,10 +294,10 @@ public: Debugger *_debugger; + char _characterName1[50]; // only used in changeCharacter protected: // data uint32 _baseTime; - char _characterName1[50]; // only used in changeCharacter Common::String _saveFileName; @@ -322,7 +320,6 @@ protected: // members bool pickupItem(ZonePtr z); - public: void scheduleLocationSwitch(const char *location); virtual void changeCharacter(const char *name) = 0; @@ -339,9 +336,9 @@ public: void showSlide(const char *name, int x = 0, int y = 0); ZonePtr _zoneTrap; + SaveLoad *_saveLoad; virtual void cleanupGame() = 0; - virtual void getGamePartProgress(bool *complete, int size) = 0; public: void highlightInventoryItem(ItemPosition pos); @@ -443,13 +440,9 @@ public: virtual void callFunction(uint index, void* parm); - bool loadGame(); - bool saveGame(); - void switchBackground(const char* background, const char* mask); void cleanupGame(); - void getGamePartProgress(bool *complete, int size); private: bool _inTestResult; @@ -459,22 +452,12 @@ private: void initFonts(); void freeFonts(); - void renameOldSavefiles(); - Common::String genSaveFileName(uint slot, bool oldStyle = false); - Common::InSaveFile *getInSaveFile(uint slot); - Common::OutSaveFile *getOutSaveFile(uint slot); - void setPartComplete(const Character& character); private: void changeLocation(char *location); void changeCharacter(const char *name); void runPendingZones(); - void doLoadGame(uint16 slot); - void doSaveGame(uint16 slot, const char* name); - int buildSaveFileList(Common::StringList& l); - int selectSaveFile(uint16 arg_0, const char* caption, const char* button); - void initResources(); static const Callable _dosCallables[25]; @@ -560,8 +543,6 @@ public: void setupSubtitles(char *s, char *s2, int y); void clearSubtitles(); - void getGamePartProgress(bool *complete, int size); - public: Table *_countersNames; diff --git a/engines/parallaction/parallaction_br.cpp b/engines/parallaction/parallaction_br.cpp index 61e01b79be..62553aa175 100644 --- a/engines/parallaction/parallaction_br.cpp +++ b/engines/parallaction/parallaction_br.cpp @@ -28,6 +28,7 @@ #include "parallaction/parallaction.h" #include "parallaction/input.h" +#include "parallaction/saveload.h" #include "parallaction/sound.h" namespace Parallaction { @@ -82,6 +83,8 @@ int Parallaction_br::init() { _subtitle[0] = -1; _subtitle[1] = -1; + _saveLoad = new SaveLoad_br(this, _saveFileMan); + Parallaction::init(); return 0; diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp index e363e665eb..ec12306d92 100644 --- a/engines/parallaction/parallaction_ns.cpp +++ b/engines/parallaction/parallaction_ns.cpp @@ -29,6 +29,7 @@ #include "parallaction/parallaction.h" #include "parallaction/input.h" +#include "parallaction/saveload.h" #include "parallaction/sound.h" @@ -149,6 +150,8 @@ int Parallaction_ns::init() { _location._animations.push_front(_char._ani); + _saveLoad = new SaveLoad_ns(this, _saveFileMan); + Parallaction::init(); return 0; @@ -183,7 +186,7 @@ void Parallaction_ns::callFunction(uint index, void* parm) { int Parallaction_ns::go() { - renameOldSavefiles(); + _saveLoad->renameOldSavefiles(); _globalFlagsNames = _disk->loadTable("global"); @@ -410,6 +413,10 @@ void Parallaction_ns::cleanupGame() { _location._animations.push_front(_char._ani); _score = 0; + _soundMan->stopMusic(); + _introSarcData3 = 200; + _introSarcData2 = 1; + return; } diff --git a/engines/parallaction/saveload.cpp b/engines/parallaction/saveload.cpp index 7fccd38df3..5620001d7d 100644 --- a/engines/parallaction/saveload.cpp +++ b/engines/parallaction/saveload.cpp @@ -31,6 +31,7 @@ #include "gui/message.h" #include "parallaction/parallaction.h" +#include "parallaction/saveload.h" #include "parallaction/sound.h" @@ -57,12 +58,11 @@ protected: GUI::StaticTextWidget *_time; GUI::StaticTextWidget *_playtime; GUI::ContainerWidget *_container; - Parallaction_ns *_vm; uint8 _fillR, _fillG, _fillB; public: - SaveLoadChooser(const String &title, const String &buttonLabel, Parallaction_ns *engine); + SaveLoadChooser(const String &title, const String &buttonLabel); ~SaveLoadChooser(); virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); @@ -73,34 +73,39 @@ public: virtual void reflowLayout(); }; -Common::String Parallaction_ns::genSaveFileName(uint slot, bool oldStyle) { +Common::String SaveLoad_ns::genOldSaveFileName(uint slot) { assert(slot < NUM_SAVESLOTS || slot == SPECIAL_SAVESLOT); char s[20]; - sprintf(s, (oldStyle ? "game.%i" : "nippon.%.3d"), slot ); + sprintf(s, "game.%i", slot); return Common::String(s); } -Common::InSaveFile *Parallaction_ns::getInSaveFile(uint slot) { + +Common::String SaveLoad::genSaveFileName(uint slot) { + assert(slot < NUM_SAVESLOTS || slot == SPECIAL_SAVESLOT); + + char s[20]; + sprintf(s, "%s.%.3d", _saveFilePrefix.c_str(), slot); + + return Common::String(s); +} + +Common::InSaveFile *SaveLoad::getInSaveFile(uint slot) { Common::String name = genSaveFileName(slot); return _saveFileMan->openForLoading(name.c_str()); } -Common::OutSaveFile *Parallaction_ns::getOutSaveFile(uint slot) { +Common::OutSaveFile *SaveLoad::getOutSaveFile(uint slot) { Common::String name = genSaveFileName(slot); return _saveFileMan->openForSaving(name.c_str()); } -void Parallaction_ns::doLoadGame(uint16 slot) { - - _soundMan->stopMusic(); +void SaveLoad_ns::doLoadGame(uint16 slot) { - cleanupGame(); - - _introSarcData3 = 200; - _introSarcData2 = 1; + _vm->cleanupGame(); Common::InSaveFile *f = getInSaveFile(slot); if (!f) return; @@ -116,10 +121,10 @@ void Parallaction_ns::doLoadGame(uint16 slot) { f->readLine(l, 15); f->readLine(s, 15); - _location._startPosition.x = atoi(s); + _vm->_location._startPosition.x = atoi(s); f->readLine(s, 15); - _location._startPosition.y = atoi(s); + _vm->_location._startPosition.y = atoi(s); f->readLine(s, 15); _score = atoi(s); @@ -135,23 +140,23 @@ void Parallaction_ns::doLoadGame(uint16 slot) { // need to invoke freeZones here with kEngineQuit set, because the // call in changeLocation preserve certain zones. _engineFlags |= kEngineQuit; - freeZones(); + _vm->freeZones(); _engineFlags &= ~kEngineQuit; - _numLocations = atoi(s); + _vm->_numLocations = atoi(s); uint16 _si; - for (_si = 0; _si < _numLocations; _si++) { + for (_si = 0; _si < _vm->_numLocations; _si++) { f->readLine(s, 20); s[strlen(s)] = '\0'; - strcpy(_locationNames[_si], s); + strcpy(_vm->_locationNames[_si], s); f->readLine(s, 15); - _localFlags[_si] = atoi(s); + _vm->_localFlags[_si] = atoi(s); } - cleanInventory(false); + _vm->cleanInventory(false); ItemName name; uint32 value; @@ -162,24 +167,24 @@ void Parallaction_ns::doLoadGame(uint16 slot) { f->readLine(s, 15); name = atoi(s); - addInventoryItem(name, value); + _vm->addInventoryItem(name, value); } delete f; // force reload of character to solve inventory // bugs, but it's a good maneuver anyway - strcpy(_characterName1, "null"); + strcpy(_vm->_characterName1, "null"); char tmp[PATH_LEN]; sprintf(tmp, "%s.%s" , l, n); - scheduleLocationSwitch(tmp); + _vm->scheduleLocationSwitch(tmp); return; } -void Parallaction_ns::doSaveGame(uint16 slot, const char* name) { +void SaveLoad_ns::doSaveGame(uint16 slot, const char* name) { Common::OutSaveFile *f = getOutSaveFile(slot); if (f == 0) { @@ -202,30 +207,30 @@ void Parallaction_ns::doSaveGame(uint16 slot, const char* name) { f->writeString(s); f->writeString("\n"); - sprintf(s, "%s\n", _char.getFullName()); + sprintf(s, "%s\n", _vm->_char.getFullName()); f->writeString(s); sprintf(s, "%s\n", _saveData1); f->writeString(s); - sprintf(s, "%d\n", _char._ani->getX()); + sprintf(s, "%d\n", _vm->_char._ani->getX()); f->writeString(s); - sprintf(s, "%d\n", _char._ani->getY()); + sprintf(s, "%d\n", _vm->_char._ani->getY()); f->writeString(s); sprintf(s, "%d\n", _score); f->writeString(s); sprintf(s, "%u\n", _globalFlags); f->writeString(s); - sprintf(s, "%d\n", _numLocations); + sprintf(s, "%d\n", _vm->_numLocations); f->writeString(s); - for (uint16 _si = 0; _si < _numLocations; _si++) { - sprintf(s, "%s\n%u\n", _locationNames[_si], _localFlags[_si]); + for (uint16 _si = 0; _si < _vm->_numLocations; _si++) { + sprintf(s, "%s\n%u\n", _vm->_locationNames[_si], _vm->_localFlags[_si]); f->writeString(s); } const InventoryItem *item; for (uint16 _si = 0; _si < 30; _si++) { - item = getInventoryItem(_si); + item = _vm->getInventoryItem(_si); sprintf(s, "%u\n%d\n", item->_id, item->_index); f->writeString(s); } @@ -247,8 +252,8 @@ enum { }; -SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, Parallaction_ns *engine) - : Dialog("scummsaveload"), _list(0), _chooseButton(0), _gfxWidget(0), _vm(engine) { +SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel) + : Dialog("scummsaveload"), _list(0), _chooseButton(0), _gfxWidget(0) { // _drawingHints |= GUI::THEME_HINT_SPECIAL_COLOR; @@ -335,7 +340,7 @@ void SaveLoadChooser::reflowLayout() { Dialog::reflowLayout(); } -int Parallaction_ns::buildSaveFileList(Common::StringList& l) { +int SaveLoad_ns::buildSaveFileList(Common::StringList& l) { char buf[200]; @@ -359,9 +364,9 @@ int Parallaction_ns::buildSaveFileList(Common::StringList& l) { } -int Parallaction_ns::selectSaveFile(uint16 arg_0, const char* caption, const char* button) { +int SaveLoad_ns::selectSaveFile(uint16 arg_0, const char* caption, const char* button) { - SaveLoadChooser* slc = new SaveLoadChooser(caption, button, this); + SaveLoadChooser* slc = new SaveLoadChooser(caption, button); Common::StringList l; @@ -380,7 +385,7 @@ int Parallaction_ns::selectSaveFile(uint16 arg_0, const char* caption, const cha -bool Parallaction_ns::loadGame() { +bool SaveLoad_ns::loadGame() { int _di = selectSaveFile( 0, "Load file", "Load" ); if (_di == -1) { @@ -392,15 +397,15 @@ bool Parallaction_ns::loadGame() { GUI::TimedMessageDialog dialog("Loading game...", 1500); dialog.runModal(); - _input->setArrowCursor(); + _vm->_input->setArrowCursor(); return true; } -bool Parallaction_ns::saveGame() { +bool SaveLoad_ns::saveGame() { - if (!scumm_stricmp(_location._name, "caveau")) { + if (!scumm_stricmp(_vm->_location._name, "caveau")) { return false; } @@ -418,7 +423,7 @@ bool Parallaction_ns::saveGame() { } -void Parallaction_ns::setPartComplete(const Character& character) { +void SaveLoad_ns::setPartComplete(const char *part) { char buf[30]; bool alreadyPresent = false; @@ -429,7 +434,7 @@ void Parallaction_ns::setPartComplete(const Character& character) { inFile->readLine(buf, 29); delete inFile; - if (strstr(buf, character.getBaseName())) { + if (strstr(buf, part)) { alreadyPresent = true; } } @@ -437,7 +442,7 @@ void Parallaction_ns::setPartComplete(const Character& character) { if (!alreadyPresent) { Common::OutSaveFile *outFile = getOutSaveFile(SPECIAL_SAVESLOT); outFile->writeString(buf); - outFile->writeString(character.getBaseName()); + outFile->writeString(part); outFile->finalize(); delete outFile; } @@ -445,7 +450,7 @@ void Parallaction_ns::setPartComplete(const Character& character) { return; } -void Parallaction_ns::getGamePartProgress(bool *complete, int size) { +void SaveLoad_ns::getGamePartProgress(bool *complete, int size) { assert(complete && size >= 3); char buf[30]; @@ -458,17 +463,7 @@ void Parallaction_ns::getGamePartProgress(bool *complete, int size) { complete[2] = strstr(buf, "dough"); } -void Parallaction_br::getGamePartProgress(bool *complete, int size) { - assert(complete && size >= 3); - - // TODO: implement progress loading - - complete[0] = true; - complete[1] = true; - complete[2] = true; -} - -void Parallaction_ns::renameOldSavefiles() { +void SaveLoad_ns::renameOldSavefiles() { bool exists[NUM_SAVESLOTS]; uint num = 0; @@ -476,7 +471,7 @@ void Parallaction_ns::renameOldSavefiles() { for (i = 0; i < NUM_SAVESLOTS; i++) { exists[i] = false; - Common::String name = genSaveFileName(i, true); + Common::String name = genOldSaveFileName(i); Common::InSaveFile *f = _saveFileMan->openForLoading(name.c_str()); if (f) { exists[i] = true; @@ -504,8 +499,8 @@ void Parallaction_ns::renameOldSavefiles() { uint success = 0; for (i = 0; i < NUM_SAVESLOTS; i++) { if (exists[i]) { - Common::String oldName = genSaveFileName(i, true); - Common::String newName = genSaveFileName(i, false); + Common::String oldName = genOldSaveFileName(i); + Common::String newName = genSaveFileName(i); if (_saveFileMan->renameSavefile(oldName.c_str(), newName.c_str())) { success++; } else { @@ -531,4 +526,28 @@ void Parallaction_ns::renameOldSavefiles() { } +bool SaveLoad_br::loadGame() { + // TODO: implement loadgame + return false; +} + +bool SaveLoad_br::saveGame() { + // TODO: implement savegame + return false; +} + +void SaveLoad_br::getGamePartProgress(bool *complete, int size) { + assert(complete && size >= 3); + + // TODO: implement progress loading + + complete[0] = true; + complete[1] = true; + complete[2] = true; +} + +void SaveLoad_br::setPartComplete(const char *part) { + // TODO: implement progress saving +} + } // namespace Parallaction diff --git a/engines/parallaction/saveload.h b/engines/parallaction/saveload.h new file mode 100644 index 0000000000..ef2d13f48e --- /dev/null +++ b/engines/parallaction/saveload.h @@ -0,0 +1,96 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + + +#ifndef PARALLACTION_SAVELOAD_H +#define PARALLACTION_SAVELOAD_H + +namespace Parallaction { + +struct Character; + + +class SaveLoad { + +protected: + Common::SaveFileManager *_saveFileMan; + Common::String _saveFilePrefix; + + Common::String genSaveFileName(uint slot); + Common::InSaveFile *getInSaveFile(uint slot); + Common::OutSaveFile *getOutSaveFile(uint slot); + +public: + SaveLoad(Common::SaveFileManager* saveFileMan, const char *prefix) : _saveFileMan(saveFileMan), _saveFilePrefix(prefix) { } + virtual ~SaveLoad() { } + + virtual bool loadGame() = 0; + virtual bool saveGame() = 0; + virtual void getGamePartProgress(bool *complete, int size) = 0; + virtual void setPartComplete(const char *part) = 0; + + virtual void renameOldSavefiles() { } +}; + +class SaveLoad_ns : public SaveLoad { + + Parallaction_ns *_vm; + + Common::String _saveFileName; + Common::String genOldSaveFileName(uint slot); + +protected: + void renameOldSavefiles(); + void doLoadGame(uint16 slot); + void doSaveGame(uint16 slot, const char* name); + int buildSaveFileList(Common::StringList& l); + int selectSaveFile(uint16 arg_0, const char* caption, const char* button); + +public: + SaveLoad_ns(Parallaction_ns *vm, Common::SaveFileManager *saveFileMan) : SaveLoad(saveFileMan, "nippon"), _vm(vm) { } + + virtual bool loadGame(); + virtual bool saveGame(); + virtual void getGamePartProgress(bool *complete, int size); + virtual void setPartComplete(const char *part); +}; + +class SaveLoad_br : public SaveLoad { + + Parallaction_br *_vm; + +public: + SaveLoad_br(Parallaction_br *vm, Common::SaveFileManager *saveFileMan) : SaveLoad(saveFileMan, "bra"), _vm(vm) { } + + virtual bool loadGame(); + virtual bool saveGame(); + virtual void getGamePartProgress(bool *complete, int size); + virtual void setPartComplete(const char *part); +}; + + +}; // namespace Parallaction + +#endif |