diff --git a/engines/ultima/shared/core/ultima.cpp b/engines/ultima/shared/core/ultima.cpp index bba3e7c29d7..571455619d2 100644 --- a/engines/ultima/shared/core/ultima.cpp +++ b/engines/ultima/shared/core/ultima.cpp @@ -73,7 +73,7 @@ void UltimaEngine::GUIError(const Common::String &msg) { } bool UltimaEngine::autoSaveCheck(int lastSaveTime) { - if (shouldPerformAutoSave(lastSaveTime) && canSaveGameStateCurrently()) { + if (shouldPerformAutoSave(lastSaveTime) && canSaveGameState(true)) { saveGameState(0, _("Autosave")); return true; } diff --git a/engines/ultima/shared/core/ultima.h b/engines/ultima/shared/core/ultima.h index a4075cc4537..ed0d4ab7472 100644 --- a/engines/ultima/shared/core/ultima.h +++ b/engines/ultima/shared/core/ultima.h @@ -121,6 +121,32 @@ public: * Shows the ScummVM Restore dialog, allowing users to restore a game */ virtual bool loadGame(); + + /** + * Indicates whether a game state can be loaded. + * @param isAutosave Flags whether it's an autosave check + */ + virtual bool canLoadGameState(bool isAutosave = false) = 0; + + /** + * Indicates whether a game state can be loaded. + */ + virtual bool canLoadGameStateCurrently() override { + return canLoadGameState(false); + } + + /** + * Indicates whether a game state can be saved. + * @param isAutosave Flags whether it's an autosave check + */ + virtual bool canSaveGameState(bool isAutosave = false) = 0; + + /** + * Indicates whether a game state can be saved. + */ + virtual bool canSaveGameStateCurrently() override { + return canSaveGameState(false); + } }; extern UltimaEngine *g_ultima; diff --git a/engines/ultima/ultima6/files/nuvie_io_file.cpp b/engines/ultima/ultima6/files/nuvie_io_file.cpp index 746d6eee05f..ace207a8204 100644 --- a/engines/ultima/ultima6/files/nuvie_io_file.cpp +++ b/engines/ultima/ultima6/files/nuvie_io_file.cpp @@ -69,7 +69,7 @@ void NuvieIOFileRead::close() { } void NuvieIOFileRead::seek(uint32 new_pos) { - if (isOpen() && new_pos <= _file->size()) { + if (isOpen() && (int)new_pos <= _file->size()) { _file->seek(new_pos); pos = new_pos; } diff --git a/engines/ultima/ultima6/ultima6.cpp b/engines/ultima/ultima6/ultima6.cpp index 1b3165f86e5..94b1e063272 100644 --- a/engines/ultima/ultima6/ultima6.cpp +++ b/engines/ultima/ultima6/ultima6.cpp @@ -234,7 +234,7 @@ bool Ultima6Engine::checkDataDir() { return true; } -bool Ultima6Engine::canLoadGameStateCurrently() { +bool Ultima6Engine::canLoadGameState(bool isAutosave) { if (_events == nullptr) return false; @@ -242,24 +242,30 @@ bool Ultima6Engine::canLoadGameStateCurrently() { // the save dialog will result in active gumps being closed Events *events = static_cast(_events); MapWindow *mapWindow = _game->get_map_window(); - events->close_gumps(); + + if (isAutosave) { + return events->get_mode() == MOVE_MODE; + + } else { + events->close_gumps(); - switch (events->get_mode()) { - case EQUIP_MODE: - events->cancelAction(); - return false; - case MOVE_MODE: - mapWindow->set_looking(false); - mapWindow->set_walking(false); - return true; - default: - // Saving/loading only available in standard move mode in-game - return false; + switch (events->get_mode()) { + case EQUIP_MODE: + events->cancelAction(); + return false; + case MOVE_MODE: + mapWindow->set_looking(false); + mapWindow->set_walking(false); + return true; + default: + // Saving/loading only available in standard move mode in-game + return false; + } } } -bool Ultima6Engine::canSaveGameStateCurrently() { - if (!canLoadGameStateCurrently()) +bool Ultima6Engine::canSaveGameState(bool isAutosave) { + if (!canLoadGameState(isAutosave)) return false; // Further checks against saving @@ -267,10 +273,12 @@ bool Ultima6Engine::canSaveGameStateCurrently() { MsgScroll *scroll = _game->get_scroll(); if (_game->is_armageddon()) { - scroll->message("Can't save. You killed everyone!\n\n"); + if (!isAutosave) + scroll->message("Can't save. You killed everyone!\n\n"); return false; } else if (events->using_control_cheat()) { - scroll->message(" Can't save while using control cheat\n\n"); + if (!isAutosave) + scroll->message(" Can't save while using control cheat\n\n"); return false; } diff --git a/engines/ultima/ultima6/ultima6.h b/engines/ultima/ultima6/ultima6.h index dad6410e7dd..31c800ca725 100644 --- a/engines/ultima/ultima6/ultima6.h +++ b/engines/ultima/ultima6/ultima6.h @@ -71,13 +71,15 @@ public: /** * Indicates whether a game state can be loaded. + * @param isAutosave Flags whether it's an autosave check */ - virtual bool canLoadGameStateCurrently() override; + virtual bool canLoadGameState(bool isAutosave = false) override; /** * Indicates whether a game state can be saved. + * @param isAutosave Flags whether it's an autosave check */ - virtual bool canSaveGameStateCurrently() override; + virtual bool canSaveGameState(bool isAutosave = false) override; /** * Load a game state. diff --git a/engines/ultima/ultima8/ultima8.cpp b/engines/ultima/ultima8/ultima8.cpp index d187fa7a342..5a776f68900 100644 --- a/engines/ultima/ultima8/ultima8.cpp +++ b/engines/ultima/ultima8/ultima8.cpp @@ -1296,7 +1296,7 @@ void Ultima8Engine::writeSaveInfo(ODataSource *ods) { } bool Ultima8Engine::saveGame() { - if (!canSaveGameStateCurrently()) + if (!canSaveGameState()) return false; GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true); @@ -1322,7 +1322,7 @@ bool Ultima8Engine::saveGame() { return result; } -bool Ultima8Engine::canSaveGameStateCurrently() { +bool Ultima8Engine::canSaveGameState(bool isAutosave) { if (desktopGump->FindGump()) // Can't save when a modal gump is open return false; diff --git a/engines/ultima/ultima8/ultima8.h b/engines/ultima/ultima8/ultima8.h index e7eb9b9d64a..3e7eac313c6 100644 --- a/engines/ultima/ultima8/ultima8.h +++ b/engines/ultima/ultima8/ultima8.h @@ -311,12 +311,12 @@ public: /** * Returns true if a savegame can be loaded */ - virtual bool canLoadGameStateCurrently() { return true; } + virtual bool canLoadGameState(bool isAutosave = false) { return true; } /** * Returns true if the game can be saved */ - virtual bool canSaveGameStateCurrently(); + virtual bool canSaveGameState(bool isAutosave = false) override; virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc);