Refactored erase_out_specials();

This commit is contained in:
Mark Clark
2018-02-17 17:10:34 -05:00
parent 05b6a9689f
commit a2dc641f31
6 changed files with 82 additions and 47 deletions

View File

@@ -21,13 +21,11 @@
#include "boe.specials.hpp"
#include "boe.infodlg.hpp"
#include "mathutil.hpp"
#include "boe.main.hpp"
#include "render_image.hpp"
#include "render_shapes.hpp"
#include "render_text.hpp"
#include "tiling.hpp"
#include "strdlog.hpp"
#include "fileio.hpp"
#include "winutil.hpp"
#include "res_image.hpp"
@@ -1247,52 +1245,64 @@ void erase_specials() {
}
void erase_out_specials() {
short out_num;
cSpecial sn;
short sd1,sd2;
location where;
for(short i = 0; i < 2; i++)
for(short j = 0; j < 2; j++)
if(quadrant_legal(i,j)) {
cOutdoors& sector = *univ.scenario.outdoors[univ.party.outdoor_corner.x + i][univ.party.outdoor_corner.y + j];
for(short k = 0; k < sector.city_locs.size(); k++) {
if(sector.city_locs[k].spec >= 0 && sector.city_locs[k].x < 48 &&
univ.scenario.ter_types[sector.terrain[sector.city_locs[k].x][sector.city_locs[k].y]].special == eTerSpec::TOWN_ENTRANCE &&
(sector.city_locs[k].x == minmax(0,47,sector.city_locs[k].x)) &&
(sector.city_locs[k].y == minmax(0,47,sector.city_locs[k].y))) {
if(sector.city_locs[k].spec < 0 || sector.city_locs[k].spec >= univ.scenario.towns.size())
continue;
if(!univ.scenario.towns[sector.city_locs[k].spec]->can_find) {
univ.out[48 * i + sector.city_locs[k].x][48 * j + sector.city_locs[k].y] =
univ.scenario.ter_types[sector.terrain[sector.city_locs[k].x][sector.city_locs[k].y]].flag1;
}
else if(univ.scenario.towns[sector.city_locs[k].spec]->can_find) {
univ.out[48 * i + sector.city_locs[k].x][48 * j + sector.city_locs[k].y] =
sector.terrain[sector.city_locs[k].x][sector.city_locs[k].y];
}
}
}
for(int k = 0; k < sector.special_locs.size(); k++) {
if(sector.special_locs[k].spec < 0) continue; // TODO: Is this needed? Seems to be important, so why was it commented out?
out_num = univ.scenario.outdoors.width() * (univ.party.outdoor_corner.y + j) + univ.party.outdoor_corner.x + i;
sn = sector.specials[sector.special_locs[k].spec];
sd1 = sn.sd1; sd2 = sn.sd2;
if((univ.party.sd_legit(sd1,sd2)) && (PSD[sd1][sd2] == 250)) {
where = sector.special_locs[k];
if(where.x > 48 || where.y > 48 || where.x < 0 || where.y < 0) {
beep();
add_string_to_buf("Outdoor section corrupt. Problem fixed.");
sector.special_locs[k].spec = -1; // TODO: Again, was there a reason for commenting this out?
}
sector.special_spot[where.x][where.y] = false;
}
}
for(short i = 0; i < 2; i++) {
for (short j = 0; j < 2; j++) {
if (!quadrant_legal(i, j)) continue;
auto& sector = univ.scenario.get_sector(univ.party.outdoor_corner.x + i, univ.party.outdoor_corner.y + j);
erase_hidden_towns(sector, i, j);
erase_completed_specials(sector);
}
}
}
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) ||
!does_location_have_special(sector, city_loc, eTerSpec::TOWN_ENTRANCE) ||
!sector.is_on_map(city_loc)) {
continue;
}
auto town_pos_x = AREA_MEDIUM * quadrant_x + sector.city_locs[tile_index].x;
auto town_pos_y = AREA_MEDIUM * quadrant_y + sector.city_locs[tile_index].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) {
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;
}
}
}
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)
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) {
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?
}
sector.special_spot[completed_special.x][completed_special.y] = false;
}
}
}
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;
}
// TODO: I don't think we need this

View File

@@ -1,5 +1,6 @@
#include <SFML/Graphics.hpp>
#include "outdoors.hpp"
void force_town_enter(short which_town,location where_start);
void start_town_mode(short which_town, short entry_dir);
@@ -21,7 +22,10 @@ void dump_gold(short print_mes);
void pick_lock(location where,short pc_num);
void bash_door(location where,short pc_num);
void erase_specials();
void erase_hidden_towns(cOutdoors& sector, int quadrant_x, int quadrant_y);
void erase_completed_specials(cOutdoors& sector);
void erase_out_specials();
bool does_location_have_special(cOutdoors& sector, location loc, eTerSpec type);
void clear_map();
void draw_map(bool need_refresh);
bool is_door(location destination);

View File

@@ -16,6 +16,7 @@
#include "vector2d.hpp"
#include "location.hpp"
#include "special.hpp"
#include "mathutil.hpp"
enum {
AREA_TINY = 24,
@@ -41,6 +42,11 @@ public:
, terrain(dim, dim)
, maps(dim, boost::dynamic_bitset<>(dim))
{}
bool is_on_map(location loc) const
{
return loc.x < max_dim && loc.y < max_dim && loc.x >= 0 && loc.y >= 0;
}
};
#endif

View File

@@ -528,3 +528,14 @@ cItem cScenario::return_treasure(int loot, bool allow_junk) {
treas.value = 0;
return treas;
}
cOutdoors& cScenario::get_sector(int x, int y)
{
return *outdoors[x][y];
}
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;
}

View File

@@ -103,6 +103,8 @@ public:
ter_num_t get_ground_from_ter(ter_num_t ter);
ter_num_t get_ter_from_ground(unsigned short ground);
ter_num_t get_trim_terrain(unsigned short ground, unsigned short trim_g, eTrimType trim);
cOutdoors& get_sector(int x, int y);
bool is_town_entrance_valid(spec_loc_t loc) const;
bool is_ter_used(ter_num_t ter);
bool is_monst_used(mon_num_t monst);

View File

@@ -16,6 +16,8 @@
namespace legacy { struct special_node_type; };
static const short SDF_COMPLETE = 250;
// TODO: Add win/lose option to END_SCENARIO
// TODO: Allow OUT_MOVE_PARTY to change the current sector
enum class eSpecType {