Prefer to call is_on_map() for terrain bounds checking whenever possible
Fix some cCurTown field functions not having bound checking Scenario editor now takes better advantage of cTown and cOutdoors sharing a superclass
This commit is contained in:
@@ -738,8 +738,7 @@ void draw_terrain(short mode) {
|
||||
where_draw.y += j - 6;
|
||||
if(!(is_out()))
|
||||
light_area[i][j] = (is_town()) ? pt_in_light(view_loc,where_draw) : combat_pt_in_light(where_draw);
|
||||
if(!(is_out()) && ((where_draw.x < 0) || (where_draw.x > univ.town->max_dim - 1)
|
||||
|| (where_draw.y < 0) || (where_draw.y > univ.town->max_dim - 1)))
|
||||
if(!is_out() && !univ.town.is_on_map(where_draw.x, where_draw.y))
|
||||
unexplored_area[i][j] = 0;
|
||||
else unexplored_area[i][j] = 1 - is_explored(where_draw.x,where_draw.y);
|
||||
}
|
||||
@@ -753,8 +752,7 @@ void draw_terrain(short mode) {
|
||||
off_terrain = false;
|
||||
|
||||
draw_frills = true;
|
||||
if(!(is_out()) && ((where_draw.x < 0) || (where_draw.x > univ.town->max_dim - 1)
|
||||
|| (where_draw.y < 0) || (where_draw.y > univ.town->max_dim - 1))) {
|
||||
if(!is_out() && !univ.town.is_on_map(where_draw.x, where_draw.y)) {
|
||||
draw_frills = false;
|
||||
// Warning - this section changes where_draw
|
||||
if(where_draw.x < 0)
|
||||
@@ -771,8 +769,7 @@ void draw_terrain(short mode) {
|
||||
spec_terrain = 0;
|
||||
}
|
||||
else if(is_out()) {
|
||||
if((where_draw.x < 0) || (where_draw.x > 95)
|
||||
|| (where_draw.y < 0) || (where_draw.y > 95))
|
||||
if(!univ.out.is_on_map(where_draw.x, where_draw.y))
|
||||
can_draw = 0;
|
||||
else {
|
||||
spec_terrain = univ.out[where_draw.x][where_draw.y];
|
||||
@@ -962,6 +959,7 @@ void place_trim(short q,short r,location where,ter_num_t ter_type) {
|
||||
}
|
||||
else {
|
||||
// TODO: Shouldn't we subtract one here?
|
||||
// The outdoors case (above) does subtract 1, so one of them must be wrong...
|
||||
if(where.x == univ.town->max_dim)
|
||||
at_right = true;
|
||||
if(where.y == univ.town->max_dim)
|
||||
|
@@ -134,9 +134,7 @@ location local_to_global(location local) {
|
||||
return global;
|
||||
}
|
||||
bool loc_off_world(location p1) {
|
||||
if((p1.x < 0) || (p1.x > univ.town->max_dim) || (p1.y < 0) || (p1.y > univ.town->max_dim))
|
||||
return true;
|
||||
else return false;
|
||||
return !univ.town.is_on_map(p1.x, p1.y);
|
||||
}
|
||||
|
||||
bool loc_off_act_area(location p1) {
|
||||
@@ -215,16 +213,11 @@ short combat_obscurity(short x, short y) {
|
||||
}
|
||||
|
||||
ter_num_t coord_to_ter(short x,short y) {
|
||||
if(x < 0 || y < 0) return 0;
|
||||
if(is_out()) {
|
||||
if(x >= univ.out.max_dim || y >= univ.out.max_dim) {
|
||||
return 0;
|
||||
}
|
||||
if(!univ.out.is_on_map(x, y)) return 0;
|
||||
return univ.out[x][y];
|
||||
}
|
||||
if(x >= univ.town->max_dim || y >= univ.town->max_dim) {
|
||||
return 0;
|
||||
}
|
||||
if(!univ.town.is_on_map(x, y)) return 0;
|
||||
return univ.town->terrain(x,y);
|
||||
}
|
||||
|
||||
@@ -250,7 +243,7 @@ void update_explored(const location dest) {
|
||||
univ.out.out_e[dest.x][dest.y] = 2;
|
||||
for(look.x = dest.x - 4; look.x < dest.x + 5; look.x++)
|
||||
for(look.y = dest.y - 4; look.y < dest.y + 5; look.y++) {
|
||||
if((look.x == minmax(0,univ.out.max_dim-1,(int)look.x)) && (look.y == minmax(0,univ.out.max_dim-1,(int)look.y))) {
|
||||
if(univ.out.is_on_map(look.x, look.y)) {
|
||||
if(univ.out.out_e[look.x][look.y] == 0) {
|
||||
if(can_see_light(dest, look, sight_obscurity) < 5) {
|
||||
univ.out.out_e[look.x][look.y] = 1;
|
||||
@@ -271,9 +264,8 @@ void update_explored(const location dest) {
|
||||
|
||||
// All purpose function to check is spot is free for travel into.
|
||||
bool is_blocked(location to_check) {
|
||||
if(to_check.x < 0 || to_check.y < 0) return true;
|
||||
if(is_out()) {
|
||||
if(to_check.x >= univ.out.max_dim || to_check.y >= univ.out.max_dim)
|
||||
if(!univ.out.is_on_map(to_check.x, to_check.y))
|
||||
return true;
|
||||
if(impassable(univ.out[to_check.x][to_check.y])) {
|
||||
return true;
|
||||
@@ -288,7 +280,7 @@ bool is_blocked(location to_check) {
|
||||
}
|
||||
|
||||
if((is_town()) || (is_combat())) {
|
||||
if(to_check.x >= univ.town->max_dim || to_check.y >= univ.town->max_dim)
|
||||
if(!univ.town.is_on_map(to_check.x, to_check.y))
|
||||
return true;
|
||||
ter_num_t ter = univ.town->terrain(to_check.x,to_check.y);
|
||||
|
||||
@@ -404,7 +396,7 @@ bool can_see_monst(location l,short m_num) {
|
||||
|
||||
bool outd_is_blocked(location to_check) {
|
||||
if(overall_mode == MODE_OUTDOORS) {
|
||||
if(to_check.x < 0 || to_check.y < 0 || to_check.x >= univ.out.max_dim || to_check.y >= univ.out.max_dim)
|
||||
if(!univ.out.is_on_map(to_check.x, to_check.y))
|
||||
return true;
|
||||
if(impassable(univ.out[to_check.x][to_check.y])) {
|
||||
return true;
|
||||
@@ -484,8 +476,7 @@ bool pt_in_light(location from_where,location to_where) { // Assumes, of course,
|
||||
|
||||
if(univ.town->lighting_type == 0)
|
||||
return true;
|
||||
if((to_where.x < 0) || (to_where.x >= univ.town->max_dim)
|
||||
|| (to_where.y < 0) || (to_where.y >= univ.town->max_dim))
|
||||
if(!univ.town.is_on_map(to_where.x, to_where.y))
|
||||
return true;
|
||||
if(univ.town->lighting[to_where.x][to_where.y])
|
||||
return true;
|
||||
@@ -501,8 +492,7 @@ bool combat_pt_in_light(location to_where) {
|
||||
|
||||
if((univ.town->lighting_type == 0) || (which_combat_type == 0))
|
||||
return true;
|
||||
if((to_where.x < 0) || (to_where.x >= univ.town->max_dim)
|
||||
|| (to_where.y < 0) || (to_where.y >= univ.town->max_dim))
|
||||
if(!univ.town.is_on_map(to_where.x, to_where.y))
|
||||
return true;
|
||||
if(univ.town->lighting[to_where.x][to_where.y])
|
||||
return true;
|
||||
|
@@ -4248,7 +4248,7 @@ void townmode_spec(const runtime_state& ctx) {
|
||||
if(x == 0 && y == 0)
|
||||
continue;
|
||||
location next(l.x+x,l.y+y);
|
||||
if(next.x < 0 || next.y < 0 || next.x >= univ.town->max_dim || next.y >= univ.town->max_dim)
|
||||
if(!univ.town.is_on_map(next.x, next.y))
|
||||
continue;
|
||||
if(!checked.count(next))
|
||||
to_check.push(next);
|
||||
|
Reference in New Issue
Block a user