Use the new erase_completed_specials() function for towns too

This commit is contained in:
2018-02-17 18:46:53 -05:00
parent e9490ac9d1
commit 03c19fa7ec
7 changed files with 20 additions and 33 deletions

View File

@@ -1214,34 +1214,14 @@ void bash_door(location where,short pc_num) {
void erase_town_specials() {
location where;
short sd1,sd2;
cSpecial sn;
if((is_combat()) && (which_combat_type == 0))
return;
if(!is_town() && !is_combat())
return;
for(short k = 0; k < univ.town->special_locs.size(); k++) {
if(univ.town->special_locs[k].spec < 0 || univ.town->special_locs[k].spec >= univ.town->specials.size())
continue;
sn = univ.town->specials[univ.town->special_locs[k].spec];
sd1 = sn.sd1; sd2 = sn.sd2;
if((univ.party.sd_legit(sd1,sd2)) && (PSD[sd1][sd2] == 250)) {
long spec = univ.town->special_locs[k].spec;
where = univ.town->special_locs[k];
if(spec >= 0 && (where.x > univ.town->max_dim || where.y > univ.town->max_dim || where.x < 0 || where.y < 0)) {
beep();
add_string_to_buf("Town corrupt. Problem fixed.");
print_nums(where.x,where.y,k);
univ.town->special_locs[k].spec = -1;
}
if(spec >= 0) {
univ.town.set_spot(where.x,where.y,false);
}
}
}
erase_completed_specials(*univ.town, [](location where){
univ.town.set_spot(where.x, where.y, false);
});
}
void erase_out_specials() {
@@ -1252,7 +1232,9 @@ void erase_out_specials() {
erase_hidden_towns(sector, i, j);
erase_completed_specials(sector);
erase_completed_specials(sector, [&sector](location where){
sector.special_spot[where.x][where.y] = false;
});
}
}
}
@@ -1278,7 +1260,7 @@ void erase_hidden_towns(cOutdoors& sector, int quadrant_x, int quadrant_y) {
}
}
void erase_completed_specials(cOutdoors& sector) {
void erase_completed_specials(cArea& sector, std::function<void(location)> clear_spot) {
for(auto tile_index = 0; tile_index < sector.special_locs.size(); tile_index++) {
if(sector.special_locs[tile_index].spec < 0 ||
sector.special_locs[tile_index].spec >= sector.specials.size())
@@ -1289,11 +1271,12 @@ void erase_completed_specials(cOutdoors& sector) {
auto completed_special = sector.special_locs[tile_index];
if(!sector.is_on_map(completed_special)) {
beep();
add_string_to_buf("Outdoor section corrupt. Problem fixed.");
sector.special_locs[tile_index].spec = -1; // TODO: Again, was there a reason for commenting this out?
add_string_to_buf("Area corrupt. Problem fixed.");
print_nums(completed_special.x, completed_special.y, tile_index);
sector.special_locs[tile_index].spec = -1;
}
sector.special_spot[completed_special.x][completed_special.y] = false;
clear_spot(completed_special);
}
}
}

View File

@@ -23,7 +23,7 @@ void pick_lock(location where,short pc_num);
void bash_door(location where,short pc_num);
void erase_town_specials();
void erase_hidden_towns(cOutdoors& sector, int quadrant_x, int quadrant_y);
void erase_completed_specials(cOutdoors& sector);
void erase_completed_specials(cArea& sector, std::function<void(location)> clear_spot);
void erase_out_specials();
bool does_location_have_special(cOutdoors& sector, location loc, eTerSpec type);
void clear_map();

View File

@@ -33,6 +33,7 @@ public:
std::vector<spec_loc_t> special_locs;
std::vector<sign_loc_t> sign_locs;
std::vector<info_rect_t> area_desc;
std::vector<cSpecial> specials;
std::string name;
// Persistent data for saved games
std::vector<boost::dynamic_bitset<>> maps;

View File

@@ -63,7 +63,6 @@ public:
std::vector<spec_loc_t> city_locs;
std::array<cWandering,4> wandering, special_enc;
std::array<location,4> wandering_locs;
std::vector<cSpecial> specials;
std::string comment;
std::vector<std::string> spec_strs;
bool special_spot[48][48];

View File

@@ -87,7 +87,6 @@ public:
short spec_on_entry,spec_on_entry_if_dead;
short spec_on_hostile;
std::array<cTimer,8> timers;
std::vector<cSpecial> specials;
bool strong_barriers, defy_mapping, defy_scrying;
bool is_hidden, has_tavern;
short difficulty;

View File

@@ -101,6 +101,10 @@ cTown* cCurTown::operator -> (){
return record();
}
cTown& cCurTown::operator * (){
return *record();
}
void cCurTown::place_preset_fields() {
// Initialize barriers, etc. Note non-sfx gets forgotten if this is a town recently visited.
for(int i = 0; i < 64; i++)

View File

@@ -53,6 +53,7 @@ public:
void import_legacy(legacy::big_tr_type& old);
cTown* operator -> ();
cTown& operator * ();
explicit cCurTown(cUniverse& univ);
short countMonsters();
cSpeech& cur_talk(); // Get the currently loaded speech