From fef06cadecae29d94268d88b95641229bdd1e466 Mon Sep 17 00:00:00 2001 From: ALONSO Laurent Date: Thu, 23 Sep 2021 13:12:42 +0200 Subject: [PATCH] legacy[save]: try to improve the loading of a save... --- src/fileio/fileio_party.cpp | 9 ++++----- src/universe/party.cpp | 11 ++++++++++- src/universe/universe.cpp | 34 +++++++++++++++++++--------------- src/universe/universe.hpp | 5 ++--- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/fileio/fileio_party.cpp b/src/fileio/fileio_party.cpp index c1b7cbc1..60ad6fc0 100644 --- a/src/fileio/fileio_party.cpp +++ b/src/fileio/fileio_party.cpp @@ -145,7 +145,6 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor legacy::stored_items_list_type stored_items[3]; legacy::stored_town_maps_type town_maps; legacy::stored_outdoor_maps_type o_maps; - unsigned char misc_i[64][64], sfx[64][64]; char *party_ptr; char *pc_ptr; long len,store_len,count; @@ -211,11 +210,11 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor fin.read((char*)&o_maps, len); } - // LOAD SFX & MISC_I + // SKIP SFX & MISC_I len = (long) (64 * 64); - fin.read((char*)sfx, len); + fin.seekg(len, std::fstream::cur); // sfx - fin.read((char*)misc_i, len); + fin.seekg(len, std::fstream::cur); // misc_i } // end if_scen @@ -254,7 +253,7 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor univ.party.import_legacy(stored_items[i],i); univ.import_legacy(town_maps); univ.import_legacy(o_maps); - univ.town.import_legacy(sfx, misc_i); + univ.town.import_reset_fields_legacy(); if(town_restore) // 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++) { diff --git a/src/universe/party.cpp b/src/universe/party.cpp index 5e3bf0f7..c31d4e33 100644 --- a/src/universe/party.cpp +++ b/src/universe/party.cpp @@ -236,8 +236,15 @@ void cParty::import_legacy(legacy::party_record_type& old, cUniverse& univ){ t.node = old.node_to_call[i]; party_event_timers.push_back(t); } + std::set seen_towns; for(short i = 0; i < 4; i++){ creature_save[i].import_legacy(old.creature_save[i]); + // check if the town has already been saved, if yes, sets it to unknown: 200 + // ie. old save can have many towns 0, we want only to use the first one + if (seen_towns.find(creature_save[i].which_town)!=seen_towns.end()) + creature_save[i].which_town=200; + else + seen_towns.insert(creature_save[i].which_town); imprisoned_monst[i] = old.imprisoned_monst[i]; } in_boat = old.in_boat; @@ -297,7 +304,9 @@ void cParty::import_legacy(legacy::setup_save_type& old){ for(int n = 0; n < 4; n++) for(int i = 0; i < 64; i++) for(int j = 0; j < 64; j++) - setup[n][i][j] = old.setup[n][i][j]; + // boe stored here misc_i, ... + // unsure maybe we want here (old&0xfe)<<8 + setup[n][i][j] = (old.setup[n][i][j]<<8); } void cParty::cConvers::import_legacy(legacy::talk_save_type old, const cScenario& scenario){ diff --git a/src/universe/universe.cpp b/src/universe/universe.cpp index c3f5f469..51228573 100644 --- a/src/universe/universe.cpp +++ b/src/universe/universe.cpp @@ -23,7 +23,7 @@ void cCurOut::import_legacy(legacy::out_info_type& old){ for(int i = 0; i < 96; i++) for(int j = 0; j < 96; j++) - expl[i][j] = old.expl[i][j]; + out_e[i][j] = old.expl[i][j]; } void cCurTown::import_legacy(legacy::current_town_type& old){ @@ -84,17 +84,24 @@ void cUniverse::import_legacy(legacy::stored_outdoor_maps_type& old){ scenario.outdoors[x][y]->maps[i][j] = old.outdoor_maps[onm(x,y,scenario.outdoors.width())][i / 8][j] & (1 << i % 8); } -void cCurTown::import_legacy(unsigned char(& old_sfx)[64][64], unsigned char(& old_misc_i)[64][64]){ - for(int i = 0; i < 64; i++) - for(int j = 0; j < 64; j++){ - unsigned long tmp_sfx, tmp_misc_i; - tmp_sfx = old_sfx[i][j]; - tmp_misc_i = old_misc_i[i][j]; - tmp_sfx <<= 16; - tmp_misc_i <<= 8; - fields[i][j] |= tmp_sfx; - fields[i][j] |= tmp_misc_i; - } +void cCurTown::import_reset_fields_legacy(){ + // boe does not use the stored sfx and misc_i + // but discard them and recompute their values + for (auto const &f : record()->preset_fields) { + if (f.loc.x<0 || f.loc.x>=64 || f.loc.y<0 || f.loc.y>=64) continue; + // only 08 && f.type<17) || (f.type>=30 & f.type<=37)) + fields[f.loc.x][f.loc.y]|=f.type; + } + auto const &terrain=record()->terrain; + auto const &maxTerrain=univ.scenario.ter_types.max_size(); + for (auto const &spec : record()->special_locs) { + if (spec.spec<0 || spec.x<0 || spec.x>=terrain.width() || + spec.y<0 || spec.y>=terrain.height()) continue; + ter_num_t id=terrain[spec.x][spec.y]; + if (id>=0 && id (){ @@ -775,7 +782,6 @@ ter_num_t& cCurOut::operator [] (location loc) { } void cCurOut::writeTo(std::ostream& file) const { - writeArray(file, expl, 96, 96); writeArray(file, out, 96, 96); writeArray(file, out_e, 96, 96); // file << "OUTDOORS 0 0" << std::endl; @@ -790,7 +796,6 @@ void cCurOut::writeTo(std::ostream& file) const { } void cCurOut::readFrom(std::istream& file) { - readArray(file, expl, 96, 96); readArray(file, out, 96, 96); readArray(file, out_e, 96, 96); } @@ -958,7 +963,6 @@ void cUniverse::swap(cUniverse& other) { } void cCurOut::copy(const cCurOut& other) { - memcpy(expl, other.expl, sizeof(expl)); memcpy(out, other.out, sizeof(out)); memcpy(out_e, other.out_e, sizeof(out_e)); } diff --git a/src/universe/universe.hpp b/src/universe/universe.hpp index c33e77b7..da1a8e70 100644 --- a/src/universe/universe.hpp +++ b/src/universe/universe.hpp @@ -49,7 +49,7 @@ public: void import_legacy(legacy::current_town_type& old); void import_legacy(legacy::town_item_list& old); - void import_legacy(unsigned char(& old_sfx)[64][64], unsigned char(& old_misc_i)[64][64]); + void import_reset_fields_legacy(); void import_legacy(legacy::big_tr_type& old); cTown* operator -> (); @@ -134,9 +134,8 @@ public: class cCurOut { cUniverse& univ; public: - char expl[96][96]; // formerly out_info_type ter_num_t out[96][96]; - unsigned char out_e[96][96]; + unsigned char out_e[96][96]; // formerly out_info_type; // These take global coords (ie 0..95) bool is_spot(int x, int y);