Save unlocked doors. (Fix #207)

This commit is contained in:
2025-05-04 11:29:04 -05:00
parent 10791fc25a
commit 2aaad3b4a8
4 changed files with 19 additions and 1 deletions

View File

@@ -1368,6 +1368,7 @@ void cast_town_spell(location where) {
add_string_to_buf(" Door unlocked.");
play_sound(9);
univ.town->terrain(where.x,where.y) = univ.scenario.ter_types[ter].flag1;
univ.town->door_unlocked.push_back(where);
}
else {
play_sound(41);

View File

@@ -123,6 +123,13 @@ void start_town_mode(short which_town, short entry_dir, bool debug_enter) {
// TODO: This means cleared webs reappear, for example. Is that right?
univ.town.place_preset_fields();
for(location unlocked : univ.town->door_unlocked){
if(is_unlockable(unlocked)){
ter_num_t terrain = univ.town->terrain(unlocked.x,unlocked.y);
univ.town->terrain(unlocked.x,unlocked.y) = univ.scenario.ter_types[terrain].flag1;
}
}
univ.town.belt_present = false;
// Set up map, using stored map
for(short i = 0; i < univ.town->max_dim; i++)
@@ -1181,6 +1188,7 @@ void pick_lock(location where,short pc_num) {
add_string_to_buf(" Door unlocked.");
play_sound(9);
univ.town->terrain(where.x,where.y) = univ.scenario.ter_types[terrain].flag1;
univ.town->door_unlocked.push_back(where);
}
}
@@ -1205,6 +1213,7 @@ void bash_door(location where,short pc_num) {
add_string_to_buf(" Lock breaks.");
play_sound(9);
univ.town->terrain(where.x,where.y) = univ.scenario.ter_types[terrain].flag1;
univ.town->door_unlocked.push_back(where);
}
}

View File

@@ -544,6 +544,8 @@ void cScenario::writeTo(cTagFile& file) const {
for(int i = 0; i < towns.size(); i++) {
if(towns[i]->item_taken.any())
page["ITEMTAKEN"] << i << towns[i]->item_taken;
if(!towns[i]->door_unlocked.empty())
page["DOORUNLOCKED"] << i << towns[i]->door_unlocked;
if(towns[i]->can_find)
page["TOWNVISIBLE"] << i;
else page["TOWNHIDDEN"] << i;
@@ -554,9 +556,12 @@ void cScenario::writeTo(cTagFile& file) const {
void cScenario::readFrom(const cTagFile& file){
std::map<int, boost::dynamic_bitset<>> taken;
std::map<int, std::vector<location>> unlocked;
std::vector<size_t> visible, hidden, slaughter;
auto& page = file[0];
page["ITEMTAKEN"].extractSparse(taken);
if(page.contains("DOORUNLOCKED"))
page["DOORUNLOCKED"].extractSparse(unlocked);
page["TOWNVISIBLE"].extract(visible);
page["TOWNHIDDEN"].extract(hidden);
page["TOWNSLAUGHTER"].extractSparse(slaughter);
@@ -565,6 +570,8 @@ void cScenario::readFrom(const cTagFile& file){
for(size_t i = 0; i < towns.size(); i++) {
if(taken.find(i) != taken.end()) towns[i]->item_taken = taken[i];
else towns[i]->item_taken.clear();
if(unlocked.find(i) != unlocked.end()) towns[i]->door_unlocked = unlocked[i];
else towns[i]->door_unlocked.clear();
if(i < slaughter.size()) towns[i]->m_killed = slaughter[i];
else towns[i]->m_killed = 0;
if(std::binary_search(visible.begin(), visible.end(), i)) {

View File

@@ -101,6 +101,7 @@ private:
// Persistent data for saved games
boost::dynamic_bitset<> item_taken;
public:
std::vector<location> door_unlocked;
bool can_find;
long m_killed = 0;