From afda3a09f5bc5a1c7be4d3f769c87d7dc68dc6f6 Mon Sep 17 00:00:00 2001 From: ALONSO Laurent Date: Mon, 20 Sep 2021 11:54:38 +0200 Subject: [PATCH] save[legacy]: try to solve many problem + force monst.which_town to be set ( to fix a problem when saving context) --- src/fileio/fileio_party.cpp | 2 ++ src/oldstructs.hpp | 2 ++ src/porting.cpp | 31 ++++++++++++++++++++++++++----- src/porting.hpp | 3 +++ src/universe/party.cpp | 4 ++++ src/universe/universe.cpp | 8 +++++--- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/fileio/fileio_party.cpp b/src/fileio/fileio_party.cpp index 608ffb16..c1b7cbc1 100644 --- a/src/fileio/fileio_party.cpp +++ b/src/fileio/fileio_party.cpp @@ -192,12 +192,14 @@ bool load_party_v1(fs::path file_to_load, cUniverse& real_univ, bool town_restor len = (long) sizeof(legacy::town_item_list); fin.read((char*)&t_i, len); + if(must_port) port_t_i(&t_i); } // LOAD STORED ITEMS for(int i = 0; i < 3; i++) { len = (long) sizeof(legacy::stored_items_list_type); fin.read((char*)&stored_items[i], len); + if(must_port) port_stored_items_list(&stored_items[i]); } // LOAD SAVED MAPS diff --git a/src/oldstructs.hpp b/src/oldstructs.hpp index 5d583190..64dfa166 100644 --- a/src/oldstructs.hpp +++ b/src/oldstructs.hpp @@ -346,8 +346,10 @@ namespace legacy { town_record_type town; int8_t explored[64][64]; Boolean hostile; + pad_t pad1; creature_list_type monst; Boolean in_boat; + pad_t pad2; location p_loc; }; diff --git a/src/porting.cpp b/src/porting.cpp index 465aee14..b82ee4c7 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -68,6 +68,22 @@ void port_t_d(legacy::big_tr_type* old) { } } +void port_t_i(legacy::town_item_list* old) +{ + if(cur_scen_is_mac != mac_is_intel) + return; + for(short i = 0; i < 115; i++) + port_item_record(&(old->items[i])); +} + +void port_stored_items_list(legacy::stored_items_list_type *old) +{ + if(cur_scen_is_mac != mac_is_intel) + return; + for(short i = 0; i < 115; i++) + port_item_record(&(old->items[i])); +} + void port_ave_t(legacy::ave_tr_type* old) { if(cur_scen_is_mac != mac_is_intel) return; @@ -178,16 +194,21 @@ void port_scenario(legacy::scenario_data_type* temp_scenario) { flip_short(&temp_scenario->last_town_edited); } +void port_item_record(legacy::item_record_type *old) { + if(cur_scen_is_mac != mac_is_intel) + return; + + flip_short(&(old->variety)); + flip_short(&(old->item_level)); + flip_short(&(old->value)); +} void port_item_list(legacy::scen_item_data_type* old){ if(cur_scen_is_mac != mac_is_intel) return; - for(short i = 0; i < 400; i++) { - flip_short(&(old->scen_items[i].variety)); - flip_short(&(old->scen_items[i].item_level)); - flip_short(&(old->scen_items[i].value)); - } + for(short i = 0; i < 400; i++) + port_item_record(&(old->scen_items[i])); } void port_out(legacy::outdoor_record_type *out) { diff --git a/src/porting.hpp b/src/porting.hpp index 16159631..16615fd4 100644 --- a/src/porting.hpp +++ b/src/porting.hpp @@ -15,11 +15,14 @@ void flip_spec_node(legacy::special_node_type *spec); void flip_short(int16_t *s); void flip_rect(legacy::Rect* s); +void port_t_i(legacy::town_item_list* old); void port_t_d(legacy::big_tr_type* old); void port_ave_t(legacy::ave_tr_type* old); void port_tiny_t(legacy::tiny_tr_type* old); void port_scenario(legacy::scenario_data_type* old); +void port_item_record(legacy::item_record_type *old); void port_item_list(legacy::scen_item_data_type* old); +void port_stored_items_list(legacy::stored_items_list_type *old); void port_out(legacy::outdoor_record_type* out); void port_talk_nodes(legacy::talking_record_type* dummy_talk_ptr); void port_town(legacy::town_record_type* dummy_town_ptr); diff --git a/src/universe/party.cpp b/src/universe/party.cpp index e91e0324..5e3bf0f7 100644 --- a/src/universe/party.cpp +++ b/src/universe/party.cpp @@ -269,6 +269,10 @@ void cParty::import_legacy(legacy::party_record_type& old, cUniverse& univ){ at_which_save_slot = old.at_which_save_slot; for(short i = 0; i < 20 ; i++) alchemy[i] = old.alchemy[i]; + for (short i=0; i<50; i++) { + if (old.spec_items[i]>0) + spec_items.insert(i); + } for(short i = 0; i < univ.scenario.towns.size(); i++){ univ.scenario.towns[i]->can_find = old.can_find_town[i]; univ.scenario.towns[i]->m_killed = old.m_killed[i]; diff --git a/src/universe/universe.cpp b/src/universe/universe.cpp index 17de05fd..c3f5f469 100644 --- a/src/universe/universe.cpp +++ b/src/universe/universe.cpp @@ -67,8 +67,8 @@ void cCurTown::import_legacy(legacy::town_item_list& old){ void cUniverse::import_legacy(legacy::stored_town_maps_type& old){ for(int n = 0; n < scenario.towns.size(); n++) - for(int i = 0; i < 64; i++) - for(int j = 0; j < 64; j++) + for(size_t j = 0; j < scenario.towns[n]->maps.size(); j++) + for(int i = 0; i < scenario.towns[n]->maps[j].size(); i++) scenario.towns[n]->maps[j][i] = old.town_maps[n][i / 8][j] & (1 << (i % 8)); } @@ -834,8 +834,10 @@ void cCurTown::readFrom(std::istream& file){ getline(bin, cur); sin.str(cur); sin >> cur; - if(cur == "TOWN") + if(cur == "TOWN") { sin >> univ.party.town_num; + monst.which_town=univ.party.town_num; // OSNOLA, checkme: to fix the creature save + } else if(cur == "DIFFICULTY") sin >> difficulty; else if(cur == "HOSTILE")