diff --git a/src/game/boe.town.cpp b/src/game/boe.town.cpp index e7caceee..95a3b494 100644 --- a/src/game/boe.town.cpp +++ b/src/game/boe.town.cpp @@ -1257,11 +1257,10 @@ void erase_out_specials() { } } -void erase_hidden_towns(cOutdoors& sector, int quadrant_x, int quadrant_y) -{ - for (short tile_index = 0; tile_index < sector.city_locs.size(); tile_index++) { +void erase_hidden_towns(cOutdoors& sector, int quadrant_x, int quadrant_y) { + for(short tile_index = 0; tile_index < sector.city_locs.size(); tile_index++) { auto city_loc = sector.city_locs[tile_index]; - if (!univ.scenario.is_town_entrance_valid(city_loc) || + if(!univ.scenario.is_town_entrance_valid(city_loc) || !does_location_have_special(sector, city_loc, eTerSpec::TOWN_ENTRANCE) || !sector.is_on_map(city_loc)) { continue; @@ -1271,7 +1270,7 @@ void erase_hidden_towns(cOutdoors& sector, int quadrant_x, int quadrant_y) auto spec_pos_x = sector.city_locs[tile_index].x; auto spec_pos_y = sector.city_locs[tile_index].y; auto area_index = sector.terrain[spec_pos_x][spec_pos_y]; - if (!univ.scenario.towns[sector.city_locs[tile_index].spec]->can_find) { + if(!univ.scenario.towns[sector.city_locs[tile_index].spec]->can_find) { univ.out[town_pos_x][town_pos_y] = univ.scenario.ter_types[area_index].flag1; } else { univ.out[town_pos_x][town_pos_y] = area_index; @@ -1279,17 +1278,16 @@ void erase_hidden_towns(cOutdoors& sector, int quadrant_x, int quadrant_y) } } -void erase_completed_specials(cOutdoors& sector) -{ - for (auto tile_index = 0; tile_index < sector.special_locs.size(); tile_index++) { - if (sector.special_locs[tile_index].spec < 0 || +void erase_completed_specials(cOutdoors& sector) { + 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()) continue; auto sn = sector.specials[sector.special_locs[tile_index].spec]; - if (univ.party.sd_legit(sn.sd1, sn.sd2) && PSD[sn.sd1][sn.sd2] == SDF_COMPLETE) { + if(univ.party.sd_legit(sn.sd1, sn.sd2) && PSD[sn.sd1][sn.sd2] == SDF_COMPLETE) { auto completed_special = sector.special_locs[tile_index]; - if (!sector.is_on_map(completed_special)) { + 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? @@ -1300,8 +1298,7 @@ void erase_completed_specials(cOutdoors& sector) } } -bool does_location_have_special(cOutdoors& sector, location loc, eTerSpec special) -{ +bool does_location_have_special(cOutdoors& sector, location loc, eTerSpec special) { auto terrain_index = sector.terrain[loc.x][loc.y]; return univ.scenario.ter_types[terrain_index].special == special; } diff --git a/src/scenario/area.hpp b/src/scenario/area.hpp index feb0bce8..dc401280 100644 --- a/src/scenario/area.hpp +++ b/src/scenario/area.hpp @@ -43,8 +43,7 @@ public: , maps(dim, boost::dynamic_bitset<>(dim)) {} - bool is_on_map(location loc) const - { + bool is_on_map(location loc) const { return loc.x < max_dim && loc.y < max_dim && loc.x >= 0 && loc.y >= 0; } }; diff --git a/src/scenario/scenario.cpp b/src/scenario/scenario.cpp index 84143167..5d4ef5a7 100644 --- a/src/scenario/scenario.cpp +++ b/src/scenario/scenario.cpp @@ -529,13 +529,11 @@ cItem cScenario::return_treasure(int loot, bool allow_junk) { return treas; } -cOutdoors& cScenario::get_sector(int x, int y) -{ +cOutdoors& cScenario::get_sector(int x, int y) { return *outdoors[x][y]; } -bool cScenario::is_town_entrance_valid(spec_loc_t loc) const -{ +bool cScenario::is_town_entrance_valid(spec_loc_t loc) const { auto towns_in_scenario = towns.size(); return loc.spec >= 0 && loc.spec < towns_in_scenario; }