Skip to content

Commit

Permalink
SaveLoad: Only save game on map load when save_onload=true
Browse files Browse the repository at this point in the history
Fixes #1886

This fixes a regression where saving the fog-of-war layers during map
transition would also save the player character regardless of
save_onload.
  • Loading branch information
dorkster committed Nov 1, 2024
1 parent 7b1bed8 commit 77490ad
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 36 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Engine fixes:
* Fix single-frame "back_forth" animations taking an extra frame to complete.
* Fix not being able to pick up loot with the mouse if the loot animation was looped.
* Fix invisible icons in Powers menu when using gamepad/touch controls.
* Fix regression that caused save_onload=false to have no effect.
* Android: Fix 'Flare' directory not being automatically created.
* Android: Added a dialog to direct the player to the wiki page for installing if no game data is found.

Expand Down
2 changes: 1 addition & 1 deletion src/GameStatePlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void GameStatePlay::checkTeleport() {
inpt->lock_all = (teleport_mapname == "maps/spawn.txt");
mapr->executeOnMapExitEvents();
showLoading();
save_load->saveGame();
save_load->saveFOW(); // TODO handle save_onload/save_onexit?
mapr->load(teleport_mapname);
setLoadingFrame();

Expand Down
77 changes: 43 additions & 34 deletions src/SaveLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,40 +248,8 @@ void SaveLoad::saveGame() {
}
}

// Save fow dark layer
if (mapr->fogofwar && mapr->save_fogofwar && !mapr->getFilename().empty() && fow->dark_layer_id < mapr->layernames.size()) {
ss.str("");
ss << settings->path_user << "saves/" << eset->misc.save_prefix << "/" << game_slot << "/fow/" << Utils::hashString(mapr->getFilename()) << ".txt";

outfile.open(Filesystem::convertSlashes(ss.str()).c_str(), std::ios::out);

if (outfile.is_open()) {
outfile << "# " << mapr->getFilename() << std::endl;
outfile << "[layer]" << std::endl;
outfile << "type=" << mapr->layernames[fow->dark_layer_id] << std::endl;
outfile << "data=" << std::endl;

std::string layer = "";
for (int line = 0; line < mapr->h; line++) {
std::stringstream map_row;
for (int tile = 0; tile < mapr->w; tile++) {
unsigned short val = mapr->layers[fow->dark_layer_id][tile][line];
map_row << val << ",";
}
layer += map_row.str();
layer += '\n';
}
layer.erase(layer.end()-2, layer.end());
layer += '\n';
outfile << layer << std::endl;

if (outfile.bad()) Utils::logError("SaveLoad: Unable to save map data. No write access or disk is full!");
outfile.close();
outfile.clear();

platform.FSCommit();
}
}
// save fog-of-war layers
saveFOW();

// Save extended Items
ss.str("");
Expand Down Expand Up @@ -717,3 +685,44 @@ void SaveLoad::loadPowerTree() {
// fall back to the default power tree
menu->pow->loadPowerTree("powers/trees/default.txt");
}

void SaveLoad::saveFOW() {
std::ofstream outfile;
std::stringstream ss;

// Save fow dark layer
if (mapr->fogofwar && mapr->save_fogofwar && !mapr->getFilename().empty() && fow->dark_layer_id < mapr->layernames.size()) {
ss.str("");
ss << settings->path_user << "saves/" << eset->misc.save_prefix << "/" << game_slot << "/fow/" << Utils::hashString(mapr->getFilename()) << ".txt";

outfile.open(Filesystem::convertSlashes(ss.str()).c_str(), std::ios::out);

if (outfile.is_open()) {
outfile << "# " << mapr->getFilename() << std::endl;
outfile << "[layer]" << std::endl;
outfile << "type=" << mapr->layernames[fow->dark_layer_id] << std::endl;
outfile << "data=" << std::endl;

std::string layer = "";
for (int line = 0; line < mapr->h; line++) {
std::stringstream map_row;
for (int tile = 0; tile < mapr->w; tile++) {
unsigned short val = mapr->layers[fow->dark_layer_id][tile][line];
map_row << val << ",";
}
layer += map_row.str();
layer += '\n';
}
layer.erase(layer.end()-2, layer.end());
layer += '\n';
outfile << layer << std::endl;

if (outfile.bad()) Utils::logError("SaveLoad: Unable to save map data. No write access or disk is full!");
outfile.close();
outfile.clear();

platform.FSCommit();
}
}

}
1 change: 1 addition & 0 deletions src/SaveLoad.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SaveLoad {
void loadGame();
void loadClass(int index);
void loadStash();
void saveFOW();

private:
void applyPlayerData();
Expand Down
2 changes: 1 addition & 1 deletion src/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/

#include <SDL.h>

Version VersionInfo::ENGINE(1, 14, 70);
Version VersionInfo::ENGINE(1, 14, 71);
Version VersionInfo::MIN(0, 0, 0);
Version VersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);

Expand Down

0 comments on commit 77490ad

Please sign in to comment.