Add some terrain bounds checking and some named constants
This commit is contained in:
@@ -1913,12 +1913,12 @@ bool handle_keystroke(const sf::Event& event){
|
||||
case 'Q':
|
||||
if(!univ.debug_mode) break;
|
||||
if(overall_mode == MODE_OUTDOORS) {
|
||||
for(short i = 0; i < 96; i++)
|
||||
for(short j = 0; j < 96; j++)
|
||||
for(short i = 0; i < univ.out.max_dim; i++)
|
||||
for(short j = 0; j < univ.out.max_dim; j++)
|
||||
make_explored(i,j);
|
||||
} else {
|
||||
for(short i = 0; i < 64; i++)
|
||||
for(short j = 0; j < 64; j++)
|
||||
for(short i = 0; i < univ.town->max_dim; i++)
|
||||
for(short j = 0; j < univ.town->max_dim; j++)
|
||||
make_explored(i,j);
|
||||
}
|
||||
clear_map();
|
||||
|
@@ -132,21 +132,21 @@ void shift_universe_left() {
|
||||
save_outdoor_maps();
|
||||
univ.party.outdoor_corner.x--;
|
||||
univ.party.i_w_c.x++;
|
||||
univ.party.out_loc.x += 48;
|
||||
univ.party.out_loc.x += univ.out.half_dim;
|
||||
|
||||
for(short i = 48; i < 96; i++)
|
||||
for(short j = 0; j < 96; j++)
|
||||
univ.out.out_e[i][j] = univ.out.out_e[i - 48][j];
|
||||
for(short i = univ.out.half_dim; i < univ.out.max_dim; i++)
|
||||
for(short j = 0; j < univ.out.max_dim; j++)
|
||||
univ.out.out_e[i][j] = univ.out.out_e[i - univ.out.half_dim][j];
|
||||
|
||||
for(short i = 0; i < 48; i++)
|
||||
for(short j = 0; j < 96; j++)
|
||||
for(short i = 0; i < univ.out.half_dim; i++)
|
||||
for(short j = 0; j < univ.out.max_dim; j++)
|
||||
univ.out.out_e[i][j] = 0;
|
||||
|
||||
for(short i = 0; i < 10; i++) {
|
||||
if(univ.party.out_c[i].m_loc.x > 48)
|
||||
for(short i = 0; i < univ.party.out_c.size(); i++) {
|
||||
if(univ.party.out_c[i].m_loc.x > univ.out.half_dim)
|
||||
univ.party.out_c[i].exists = false;
|
||||
if(univ.party.out_c[i].exists)
|
||||
univ.party.out_c[i].m_loc.x += 48;
|
||||
univ.party.out_c[i].m_loc.x += univ.out.half_dim;
|
||||
}
|
||||
|
||||
build_outdoors();
|
||||
@@ -159,20 +159,20 @@ void shift_universe_right() {
|
||||
save_outdoor_maps();
|
||||
univ.party.outdoor_corner.x++;
|
||||
univ.party.i_w_c.x--;
|
||||
univ.party.out_loc.x -= 48;
|
||||
for(short i = 0; i < 48; i++)
|
||||
for(short j = 0; j < 96; j++)
|
||||
univ.out.out_e[i][j] = univ.out.out_e[i + 48][j];
|
||||
for(short i = 48; i < 96; i++)
|
||||
for(short j = 0; j < 96; j++)
|
||||
univ.party.out_loc.x -= univ.out.half_dim;
|
||||
for(short i = 0; i < univ.out.half_dim; i++)
|
||||
for(short j = 0; j < univ.out.max_dim; j++)
|
||||
univ.out.out_e[i][j] = univ.out.out_e[i + univ.out.half_dim][j];
|
||||
for(short i = univ.out.half_dim; i < univ.out.max_dim; i++)
|
||||
for(short j = 0; j < univ.out.max_dim; j++)
|
||||
univ.out.out_e[i][j] = 0;
|
||||
|
||||
|
||||
for(short i = 0; i < 10; i++) {
|
||||
if(univ.party.out_c[i].m_loc.x < 48)
|
||||
for(short i = 0; i < univ.party.out_c.size(); i++) {
|
||||
if(univ.party.out_c[i].m_loc.x < univ.out.half_dim)
|
||||
univ.party.out_c[i].exists = false;
|
||||
if(univ.party.out_c[i].exists)
|
||||
univ.party.out_c[i].m_loc.x -= 48;
|
||||
univ.party.out_c[i].m_loc.x -= univ.out.half_dim;
|
||||
}
|
||||
build_outdoors();
|
||||
restore_cursor();
|
||||
@@ -184,20 +184,20 @@ void shift_universe_up() {
|
||||
save_outdoor_maps();
|
||||
univ.party.outdoor_corner.y--;
|
||||
univ.party.i_w_c.y++;
|
||||
univ.party.out_loc.y += 48;
|
||||
univ.party.out_loc.y += univ.out.half_dim;
|
||||
|
||||
for(short i = 0; i < 96; i++)
|
||||
for(short j = 48; j < 96; j++)
|
||||
univ.out.out_e[i][j] = univ.out.out_e[i][j - 48];
|
||||
for(short i = 0; i < 96; i++)
|
||||
for(short j = 0; j < 48; j++)
|
||||
for(short i = 0; i < univ.out.max_dim; i++)
|
||||
for(short j = univ.out.half_dim; j < univ.out.max_dim; j++)
|
||||
univ.out.out_e[i][j] = univ.out.out_e[i][j - univ.out.half_dim];
|
||||
for(short i = 0; i < univ.out.max_dim; i++)
|
||||
for(short j = 0; j < univ.out.half_dim; j++)
|
||||
univ.out.out_e[i][j] = 0;
|
||||
|
||||
for(short i = 0; i < 10; i++) {
|
||||
if(univ.party.out_c[i].m_loc.y > 48)
|
||||
for(short i = 0; i < univ.party.out_c.size(); i++) {
|
||||
if(univ.party.out_c[i].m_loc.y > univ.out.half_dim)
|
||||
univ.party.out_c[i].exists = false;
|
||||
if(univ.party.out_c[i].exists)
|
||||
univ.party.out_c[i].m_loc.y += 48;
|
||||
univ.party.out_c[i].m_loc.y += univ.out.half_dim;
|
||||
}
|
||||
|
||||
build_outdoors();
|
||||
@@ -211,20 +211,20 @@ void shift_universe_down() {
|
||||
save_outdoor_maps();
|
||||
univ.party.outdoor_corner.y++;
|
||||
univ.party.i_w_c.y--;
|
||||
univ.party.out_loc.y = univ.party.out_loc.y - 48;
|
||||
univ.party.out_loc.y = univ.party.out_loc.y - univ.out.half_dim;
|
||||
|
||||
for(short i = 0; i < 96; i++)
|
||||
for(short j = 0; j < 48; j++)
|
||||
univ.out.out_e[i][j] = univ.out.out_e[i][j + 48];
|
||||
for(short i = 0; i < 96; i++)
|
||||
for(short j = 48; j < 96; j++)
|
||||
for(short i = 0; i < univ.out.max_dim; i++)
|
||||
for(short j = 0; j < univ.out.half_dim; j++)
|
||||
univ.out.out_e[i][j] = univ.out.out_e[i][j + univ.out.half_dim];
|
||||
for(short i = 0; i < univ.out.max_dim; i++)
|
||||
for(short j = univ.out.half_dim; j < univ.out.max_dim; j++)
|
||||
univ.out.out_e[i][j] = 0;
|
||||
|
||||
for(short i = 0; i < 10; i++) {
|
||||
if(univ.party.out_c[i].m_loc.y < 48)
|
||||
for(short i = 0; i < univ.party.out_c.size(); i++) {
|
||||
if(univ.party.out_c[i].m_loc.y < univ.out.half_dim)
|
||||
univ.party.out_c[i].exists = false;
|
||||
if(univ.party.out_c[i].exists)
|
||||
univ.party.out_c[i].m_loc.y = univ.party.out_c[i].m_loc.y - 48;
|
||||
univ.party.out_c[i].m_loc.y = univ.party.out_c[i].m_loc.y - univ.out.half_dim;
|
||||
}
|
||||
|
||||
build_outdoors();
|
||||
@@ -251,10 +251,10 @@ void position_party(short out_x,short out_y,short pc_pos_x,short pc_pos_y) {
|
||||
}
|
||||
univ.party.i_w_c.x = (univ.party.out_loc.x > 47) ? 1 : 0;
|
||||
univ.party.i_w_c.y = (univ.party.out_loc.y > 47) ? 1 : 0;
|
||||
for(short i = 0; i < 10; i++)
|
||||
for(short i = 0; i < univ.party.out_c.size(); i++)
|
||||
univ.party.out_c[i].exists = false;
|
||||
for(short i = 0; i < 96; i++)
|
||||
for(short j = 0; j < 96; j++)
|
||||
for(short i = 0; i < univ.out.max_dim; i++)
|
||||
for(short j = 0; j < univ.out.max_dim; j++)
|
||||
univ.out.out_e[i][j] = 0;
|
||||
build_outdoors();
|
||||
}
|
||||
|
@@ -215,16 +215,25 @@ short combat_obscurity(short x, short y) {
|
||||
}
|
||||
|
||||
ter_num_t coord_to_ter(short x,short y) {
|
||||
return is_out() ? univ.out[x][y] : univ.town->terrain(x,y);
|
||||
if(x < 0 || y < 0) return 0;
|
||||
if(is_out()) {
|
||||
if(x >= univ.out.max_dim || y >= univ.out.max_dim) {
|
||||
return 0;
|
||||
}
|
||||
return univ.out[x][y];
|
||||
}
|
||||
if(x >= univ.town->max_dim || y >= univ.town->max_dim) {
|
||||
return 0;
|
||||
}
|
||||
return univ.town->terrain(x,y);
|
||||
}
|
||||
|
||||
////
|
||||
bool is_container(location loc) {
|
||||
ter_num_t ter;
|
||||
|
||||
if(loc.x < 0 || loc.y < 0) return false;
|
||||
if((univ.town.is_barrel(loc.x,loc.y)) || (univ.town.is_crate(loc.x,loc.y)))
|
||||
return true;
|
||||
ter = coord_to_ter(loc.x,loc.y);
|
||||
ter_num_t ter = coord_to_ter(loc.x,loc.y);
|
||||
if(univ.scenario.ter_types[ter].special == eTerSpec::IS_A_CONTAINER)
|
||||
return true;
|
||||
return false;
|
||||
@@ -266,10 +275,10 @@ void update_explored(location dest) {
|
||||
|
||||
// All purpose function to check is spot is free for travel into.
|
||||
bool is_blocked(location to_check) {
|
||||
short gr;
|
||||
ter_num_t ter;
|
||||
|
||||
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)
|
||||
return true;
|
||||
if(impassable(univ.out[to_check.x][to_check.y])) {
|
||||
return true;
|
||||
}
|
||||
@@ -283,8 +292,9 @@ bool is_blocked(location to_check) {
|
||||
}
|
||||
|
||||
if((is_town()) || (is_combat())) {
|
||||
ter = univ.town->terrain(to_check.x,to_check.y);
|
||||
gr = univ.scenario.ter_types[ter].picture;
|
||||
if(to_check.x >= univ.town->max_dim || to_check.y >= univ.town->max_dim)
|
||||
return true;
|
||||
ter_num_t ter = univ.town->terrain(to_check.x,to_check.y);
|
||||
|
||||
// Terrain blocking?
|
||||
if(impassable(ter)) {
|
||||
@@ -398,6 +408,8 @@ 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)
|
||||
return true;
|
||||
if(impassable(univ.out[to_check.x][to_check.y])) {
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user