game: try to improve the code of find_clear_spot

This commit is contained in:
ALONSO Laurent
2022-01-26 10:46:00 +01:00
committed by Celtic Minstrel
parent 485e401781
commit b2eda18529
2 changed files with 13 additions and 15 deletions

View File

@@ -687,26 +687,25 @@ bool combat_move_monster(short which,location destination) {
// TODO: THIS MAKES NO ADJUSTMENTS FOR BIG MONSTERS!!! // TODO: THIS MAKES NO ADJUSTMENTS FOR BIG MONSTERS!!!
//mode; // 0 - normal 1 - prefer adjacent space //mode; // 0 - normal 1 - prefer adjacent space
location find_clear_spot(location from_where,short mode) { location find_clear_spot(location from_where,short mode) {
location loc,store_loc; location loc, store_loc(0,0);
short num_tries = 0,r1;
// Here 254 indicates the low byte of the town fields, minus explored spaces (which is lowest bit). // Here 254 indicates the low byte of the town fields, minus explored spaces (which is lowest bit).
unsigned long blocking_fields = SPECIAL_SPOT | OBJECT_CRATE | OBJECT_BARREL | OBJECT_BLOCK | FIELD_QUICKFIRE | 254; unsigned long const blocking_fields = SPECIAL_SPOT | OBJECT_CRATE | OBJECT_BARREL | OBJECT_BLOCK | FIELD_QUICKFIRE | 254;
int listPositions[25];
while(num_tries < 75) { for (int i=0; i<25; ++i) listPositions[i]=i;
num_tries++; for (int step=0; step<25; ++step) {
short w=get_ran(1,step,24);
std::swap(listPositions[w],listPositions[step]);
loc = from_where; loc = from_where;
r1 = get_ran(1,-2,2); loc.x += listPositions[step]/5-2;
loc.x = loc.x + r1; loc.y += listPositions[step]%5-2;
r1 = get_ran(1,-2,2);
loc.y = loc.y + r1;
if(!loc_off_act_area(loc) && !is_blocked(loc) if(!loc_off_act_area(loc) && !is_blocked(loc)
&& can_see_light(from_where,loc,combat_obscurity) == 0 && can_see_light(from_where,loc,combat_obscurity) == 0
&& (!is_combat() || univ.target_there(loc,TARG_PC) == nullptr) && (!is_combat() || univ.target_there(loc,TARG_PC) == nullptr)
&& (!is_town() || loc != univ.party.town_loc) && (!is_town() || loc != univ.party.town_loc)
&& (!is_town() || !(univ.town.fields[loc.x][loc.y] & blocking_fields))) { && (!is_town() || !(univ.town.fields[loc.x][loc.y] & blocking_fields))) {
if((mode == 0) || ((mode == 1) && (adjacent(from_where,loc)))) if(mode == 0 || (mode == 1 && adjacent(from_where,loc)))
return loc; return loc;
else store_loc = loc; store_loc = loc;
} }
} }
return store_loc; return store_loc;
@@ -759,7 +758,7 @@ bool monster_placid(short m_num) {
} }
// This damages a monster by any fields it's in, and destroys any barrels or crates // This damages a monster by any fields it's in, and destroys any barrels or crates
// it's stiing on. // it's siting on.
void monst_inflict_fields(short which_monst) { void monst_inflict_fields(short which_monst) {
short r1; short r1;
location where_check; location where_check;

View File

@@ -67,7 +67,6 @@ void start_town_mode(short which_town, short entry_dir) {
short former_town; short former_town;
bool monsters_loaded = false; bool monsters_loaded = false;
location loc; location loc;
unsigned short temp;
bool play_town_sound = false; bool play_town_sound = false;
if(town_force < 200) if(town_force < 200)
@@ -158,7 +157,7 @@ void start_town_mode(short which_town, short entry_dir) {
for(short j = 0; j < univ.town->max_dim; j++) for(short j = 0; j < univ.town->max_dim; j++)
for(short k = 0; k < univ.town->max_dim; k++) { // now load in saved setup, for(short k = 0; k < univ.town->max_dim; k++) { // now load in saved setup,
temp = univ.party.setup[i][j][k] << 8; unsigned long temp = univ.party.setup[i][j][k] << 8;
temp &= ~(OBJECT_CRATE | OBJECT_BARREL | OBJECT_BLOCK); temp &= ~(OBJECT_CRATE | OBJECT_BARREL | OBJECT_BLOCK);
univ.town.fields[j][k] |= temp; univ.town.fields[j][k] |= temp;
} }