Properly implement copying for universe and scenario

This allows a failed load to not clobber the currently-loaded save or scenario.
This commit is contained in:
2016-09-02 18:56:47 -04:00
parent e969da6fc1
commit 20f22d7952
16 changed files with 635 additions and 22 deletions

View File

@@ -131,7 +131,7 @@ bool load_party(fs::path file_to_load, cUniverse& univ){
return true;
}
bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bool in_scen, bool maps_there, bool must_port){
bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restore, bool in_scen, bool maps_there, bool must_port){
std::ifstream fin(file_to_load.c_str(), std::ios_base::binary);
fin.seekg(3*sizeof(short),std::ios_base::beg); // skip the header, which is 6 bytes in the old format
@@ -192,7 +192,7 @@ bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
len = (long) sizeof(legacy::town_item_list);
fin.read((char*)&t_i, len);
}else univ.party.town_num = 200;
}
// LOAD STORED ITEMS
for(int i = 0; i < 3; i++) {
@@ -219,8 +219,7 @@ bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
fin.close();
univ.~cUniverse();
new(&univ) cUniverse(' ');
cUniverse univ;
if(in_scen){
fs::path path;
@@ -248,6 +247,7 @@ bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
univ.import_legacy(town_maps);
univ.import_legacy(o_maps);
univ.town.import_legacy(sfx, misc_i);
if(!town_restore) univ.party.town_num = 200;
// Check items in crates/barrels
for(int i = 0; i < univ.town->max_dim(); i++) {
for(int j = 0; j < univ.town->max_dim(); j++) {
@@ -261,18 +261,18 @@ bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
}
}
real_univ = std::move(univ);
return true;
}
extern fs::path scenDir;
bool load_party_v2(fs::path file_to_load, cUniverse& univ){
bool load_party_v2(fs::path file_to_load, cUniverse& real_univ){
igzstream zin(file_to_load.string().c_str());
tarball partyIn;
partyIn.readFrom(zin);
zin.close();
univ.~cUniverse();
new(&univ) cUniverse(' ');
cUniverse univ;
{ // Load main party data first
std::istream& fin = partyIn.getFile("save/party.txt");
@@ -375,6 +375,7 @@ bool load_party_v2(fs::path file_to_load, cUniverse& univ){
} else showWarning("There was an error loading the party custom graphics.");
}
real_univ = std::move(univ);
return true;
}

View File

@@ -162,6 +162,7 @@ public:
return data.empty();
}
vector2d() : w(0), h(0) {}
vector2d(size_t w, size_t h) : w(w), h(h) {}
};
#endif