Fix some issues with loading saved games

This commit is contained in:
2015-09-14 15:51:04 -04:00
parent 0c8d69c48e
commit 350479ddbb
4 changed files with 15 additions and 14 deletions

View File

@@ -85,13 +85,6 @@ void finish_load_party(){
return; return;
} }
fs::path path;
path = progDir/"Blades of Exile Scenarios";
path /= univ.party.scen_name;
std::cout<<"Searching for scenario at:\n"<<path<<'\n';
if(!load_scenario(path, univ.scenario))
return;
// Saved creatures may not have had their monster attributes saved // Saved creatures may not have had their monster attributes saved
// Make sure that they know what they are! // Make sure that they know what they are!
// Cast to cMonster base class and assign, to avoid clobbering other attributes // Cast to cMonster base class and assign, to avoid clobbering other attributes

View File

@@ -47,8 +47,10 @@ cParty::cParty(cUniverse& univ, long party_preset) : univ(univ) {
} }
cParty::~cParty() { cParty::~cParty() {
for(int i = 0; i < 6; i++) for(int i = 0; i < 6; i++) {
delete adven[i]; delete adven[i];
adven[i] = nullptr;
}
} }
void cParty::append(legacy::party_record_type& old){ void cParty::append(legacy::party_record_type& old){
@@ -821,8 +823,8 @@ void cParty::readFrom(std::istream& file){
} else if(cur == "TOWNSAVE") { } else if(cur == "TOWNSAVE") {
int i; int i;
std::string str; std::string str;
bin >> i; sin >> i;
bin >> creature_save[i].which_town >> str; sin >> creature_save[i].which_town >> str;
creature_save[i].hostile = str == "HOSTILE"; creature_save[i].hostile = str == "HOSTILE";
} else if(cur == "TOWNVISIBLE") { } else if(cur == "TOWNVISIBLE") {
int i; int i;

View File

@@ -282,6 +282,7 @@ bool load_party_v1(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
return true; return true;
} }
extern fs::path scenDir;
bool load_party_v2(fs::path file_to_load, cUniverse& univ, bool town_restore, bool in_scen, bool maps_there){ bool load_party_v2(fs::path file_to_load, cUniverse& univ, bool town_restore, bool in_scen, bool maps_there){
if(!fs::exists(tempDir)) fs::create_directories(tempDir); if(!fs::exists(tempDir)) fs::create_directories(tempDir);
fs::path tempPath = tempDir/"loadtemp.exg"; fs::path tempPath = tempDir/"loadtemp.exg";
@@ -354,6 +355,8 @@ bool load_party_v2(fs::path file_to_load, cUniverse& univ, bool town_restore, bo
if(in_scen) { if(in_scen) {
fs::path path; fs::path path;
path = scenDir/univ.party.scen_name;
if(!fs::exists(path))
path = progDir/"Blades of Exile Scenarios"/univ.party.scen_name; path = progDir/"Blades of Exile Scenarios"/univ.party.scen_name;
if(!load_scenario(path, univ.scenario)) if(!load_scenario(path, univ.scenario))

View File

@@ -64,14 +64,14 @@ bool load_scenario(fs::path file_to_load, cScenario& scenario, bool only_header)
// Before loading a scenario, we may need to pop scenario resource paths. // Before loading a scenario, we may need to pop scenario resource paths.
fs::path graphics_path = ResMgr::popPath<ImageRsrc>(); fs::path graphics_path = ResMgr::popPath<ImageRsrc>();
for(auto p : graphics_path) { for(auto p : graphics_path) {
if(p.string() == "graphics") { if(p.string() == "data") {
ResMgr::pushPath<ImageRsrc>(graphics_path); ResMgr::pushPath<ImageRsrc>(graphics_path);
break; break;
} }
} }
fs::path sounds_path = ResMgr::popPath<SoundRsrc>(); fs::path sounds_path = ResMgr::popPath<SoundRsrc>();
for(auto p : sounds_path) { for(auto p : sounds_path) {
if(p.string() == "sounds") { if(p.string() == "data") {
ResMgr::pushPath<SoundRsrc>(sounds_path); ResMgr::pushPath<SoundRsrc>(sounds_path);
break; break;
} }
@@ -80,7 +80,10 @@ bool load_scenario(fs::path file_to_load, cScenario& scenario, bool only_header)
std::string fname = file_to_load.filename().string(); std::string fname = file_to_load.filename().string();
std::transform(fname.begin(), fname.end(), fname.begin(), tolower); std::transform(fname.begin(), fname.end(), fname.begin(), tolower);
size_t dot = fname.find_last_of('.'); size_t dot = fname.find_last_of('.');
try { if(dot == std::string::npos) {
showError("That is not a Blades of Exile scenario.");
return false;
} else try {
if(fname.substr(dot) == ".boes") if(fname.substr(dot) == ".boes")
return load_scenario_v2(file_to_load, scenario, only_header); return load_scenario_v2(file_to_load, scenario, only_header);
else if(fname.substr(dot) == ".exs") else if(fname.substr(dot) == ".exs")