ULTIMA6: Improved handling of autosave checks

This commit is contained in:
Paul Gilbert authored and Paul Gilbert committed 2020-02-01 13:13:51 -08:00
1 parent d76e1bd8b6
commit 77e91e613d
7 files changed
+61 -25

No files matched your search

+1 -1
View File
@@ -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;
}
+26
View File
@@ -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;
@@ -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;
}
+25 -17
View File
@@ -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 *>(_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;
}
+4 -2
View File
@@ -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.
+2 -2
View File
@@ -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<ModalGump>())
// Can't save when a modal gump is open
return false;
+2 -2
View File
@@ -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);