Fix several issues with saving and loading games

- PC's internal reference to the party was clobbered on load
- Several dynamic structures still made assumptions about their size, causing crashes
- Issues with town maps due to treating all towns as 64x64
- Town maps were saved only if you are in town
This commit is contained in:
2016-10-01 17:52:05 -04:00
parent 8edc156496
commit c1bfc99164
2 changed files with 19 additions and 8 deletions

View File

@@ -309,6 +309,8 @@ bool load_party_v2(fs::path file_to_load, cUniverse& real_univ){
return false;
}
univ.party[i].readFrom(fin);
// Do this to make sure the PC's internal party reference is correct
univ.party[i].join_party(univ.party);
}
// Including stored PCs
@@ -344,7 +346,7 @@ bool load_party_v2(fs::path file_to_load, cUniverse& real_univ){
// Read town maps
std::istream& fin2 = partyIn.getFile("save/townmaps.dat");
for(int i = 0; i < univ.scenario.towns.size(); i++)
for(int j = 0; j < 64; j++)
for(int j = 0; j < univ.scenario.towns[i]->max_dim; j++)
fin2 >> univ.scenario.towns[i]->maps[j];
} else univ.party.town_num = 200;
@@ -420,11 +422,13 @@ bool save_party(fs::path dest_file, const cUniverse& univ) {
if(univ.party.town_num < 200) {
// Write the current town data
univ.town.writeTo(partyOut.newFile("save/town.txt"));
}
{
// Write the town map data
std::ostream& fout = partyOut.newFile("save/townmaps.dat");
for(int i = 0; i < univ.scenario.towns.size(); i++)
for(int j = 0; j < 64; j++)
for(int j = 0; j < univ.scenario.towns[i]->max_dim; j++)
fout << univ.scenario.towns[i]->maps[j] << '\n';
}