diff options
author | Paul Gilbert | 2018-11-03 23:04:32 -0700 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | 0ea7f92b67a8ba18c2b0420390db50d0352995b2 (patch) | |
tree | 2cb0e66e17aff421a0a2a0526559375878bb89e1 | |
parent | d2554a73fb586166c774b7197f8e05d4c85387a2 (diff) | |
download | scummvm-rg350-0ea7f92b67a8ba18c2b0420390db50d0352995b2.tar.gz scummvm-rg350-0ea7f92b67a8ba18c2b0420390db50d0352995b2.tar.bz2 scummvm-rg350-0ea7f92b67a8ba18c2b0420390db50d0352995b2.zip |
GLK: SCOTT: Added saveGameState and loadGameState
-rw-r--r-- | engines/gargoyle/gargoyle.h | 10 | ||||
-rw-r--r-- | engines/gargoyle/scott/scott.cpp | 67 | ||||
-rw-r--r-- | engines/gargoyle/scott/scott.h | 10 |
3 files changed, 66 insertions, 21 deletions
diff --git a/engines/gargoyle/gargoyle.h b/engines/gargoyle/gargoyle.h index 5ec804e7db..373bf4c95e 100644 --- a/engines/gargoyle/gargoyle.h +++ b/engines/gargoyle/gargoyle.h @@ -127,6 +127,16 @@ public: virtual ~GargoyleEngine(); /** + * Returns true if a savegame can be loaded + */ + virtual bool canLoadGameStateCurrently() override { return true; } + + /** + * Returns true if the game can be saved + */ + virtual bool canSaveGameStateCurrently() override { return true; } + + /** * Returns the bitset of game features */ uint32 getFeatures() const; diff --git a/engines/gargoyle/scott/scott.cpp b/engines/gargoyle/scott/scott.cpp index a19fb00693..6f1b9efcf1 100644 --- a/engines/gargoyle/scott/scott.cpp +++ b/engines/gargoyle/scott/scott.cpp @@ -526,19 +526,29 @@ void Scott::lineInput(char *buf, size_t n) { } void Scott::saveGame(void) { - strid_t file; - frefid_t ref; - int ct; - Common::String msg; - - ref = glk_fileref_create_by_prompt(fileusage_TextMode | fileusage_SavedGame, filemode_Write, 0); - if (ref == nullptr) return; + frefid_t ref = glk_fileref_create_by_prompt(fileusage_TextMode | fileusage_SavedGame, + filemode_Write, 0); + if (ref == nullptr) + return; - file = glk_stream_open_file(ref, filemode_Write, 0); + int slot = ref->_slotNumber; + Common::String desc = ref->_description; glk_fileref_destroy(ref); - if (file == nullptr) return; - for (ct = 0; ct < 16; ct++) { + saveGameState(slot, desc); +} + +Common::Error Scott::saveGameState(int slot, const Common::String &desc) { + Common::String msg; + FileReference ref; + ref._slotNumber = slot; + ref._description = desc; + + strid_t file = glk_stream_open_file(&ref, filemode_Write, 0); + if (file == nullptr) + return Common::kWritingFailed; + + for (int ct = 0; ct < 16; ct++) { msg = Common::String::format("%d %d\n", Counters[ct], RoomSaved[ct]); glk_put_string_stream(file, msg.c_str()); } @@ -548,29 +558,42 @@ void Scott::saveGame(void) { MyLoc, CurrentCounter, SavedRoom, GameHeader.LightTime); glk_put_string_stream(file, msg.c_str()); - for (ct = 0; ct <= GameHeader.NumItems; ct++) { + for (int ct = 0; ct <= GameHeader.NumItems; ct++) { msg = Common::String::format("%hd\n", (short)Items[ct].Location); glk_put_string_stream(file, msg.c_str()); } glk_stream_close(file, nullptr); output("Saved.\n"); + + return Common::kNoError; } void Scott::loadGame(void) { + frefid_t ref = glk_fileref_create_by_prompt(fileusage_TextMode | fileusage_SavedGame, + filemode_Read, 0); + if (ref == nullptr) + return; + + int slotNumber = ref->_slotNumber; + glk_fileref_destroy(ref); + + loadGameState(slotNumber); +} + +Common::Error Scott::loadGameState(int slot) { strid_t file; - frefid_t ref; char buf[128]; int ct = 0; short lo; - short DarkFlag; + short darkFlag; - ref = glk_fileref_create_by_prompt(fileusage_TextMode | fileusage_SavedGame, filemode_Read, 0); - if (ref == nullptr) return; + FileReference ref; + ref._slotNumber = slot; - file = glk_stream_open_file(ref, filemode_Read, 0); - glk_fileref_destroy(ref); - if (file == nullptr) return; + file = glk_stream_open_file(&ref, filemode_Read, 0); + if (file == nullptr) + return Common::kReadingFailed; for (ct = 0; ct<16; ct++) { glk_get_line_stream(file, buf, sizeof buf); @@ -579,17 +602,19 @@ void Scott::loadGame(void) { glk_get_line_stream(file, buf, sizeof buf); sscanf(buf, "%ld %hd %d %d %d %d\n", - &BitFlags, &DarkFlag, &MyLoc, &CurrentCounter, &SavedRoom, + &BitFlags, &darkFlag, &MyLoc, &CurrentCounter, &SavedRoom, &GameHeader.LightTime); - /* Backward compatibility */ - if (DarkFlag) + // Backward compatibility + if (darkFlag) BitFlags |= (1 << 15); for (ct = 0; ct <= GameHeader.NumItems; ct++) { glk_get_line_stream(file, buf, sizeof buf); sscanf(buf, "%hd\n", &lo); Items[ct].Location = (unsigned char)lo; } + + return Common::kNoError; } int Scott::getInput(int *vb, int *no) { diff --git a/engines/gargoyle/scott/scott.h b/engines/gargoyle/scott/scott.h index f2fe7699be..81847cce3f 100644 --- a/engines/gargoyle/scott/scott.h +++ b/engines/gargoyle/scott/scott.h @@ -172,6 +172,16 @@ public: * Execute the game */ virtual void runGame(Common::SeekableReadStream *gameFile) override; + + /** + * Load a savegame + */ + virtual Common::Error loadGameState(int slot) override; + + /** + * Save the game + */ + virtual Common::Error saveGameState(int slot, const Common::String &desc) override; }; } // End of namespace Scott |