From: Hourier Date: Sat, 18 Jan 2020 13:12:11 +0000 (+0900) Subject: [Refactor] #38997 関数マクロcave_empty_bold*() を普通の関数に展開し、player-type * 引数を追加 / Changed... X-Git-Url: http://git.osdn.net/view?p=hengband%2Fhengband.git;a=commitdiff_plain;h=b6117bc7f9a0ecc8b8c66c9f3c1e6736bbf0b3c7 [Refactor] #38997 関数マクロcave_empty_bold*() を普通の関数に展開し、player-type * 引数を追加 / Changed macro function cave_empty_bold*() to normal function and added player_type * argument --- diff --git a/src/chest.c b/src/chest.c index 2351612aa..1cfc5f360 100644 --- a/src/chest.c +++ b/src/chest.c @@ -99,7 +99,7 @@ void chest_death(player_type *owner_ptr, bool scatter, POSITION y, POSITION x, O x = randint0(MAX_WID); /* Must be an empty floor. */ - if (!cave_empty_bold(floor_ptr, y, x)) continue; + if (!is_cave_empty_bold(owner_ptr, y, x)) continue; /* Place the object there. */ (void)drop_near(owner_ptr, q_ptr, -1, y, x); diff --git a/src/combat/shoot.c b/src/combat/shoot.c index c39d5903a..4815ee0b3 100644 --- a/src/combat/shoot.c +++ b/src/combat/shoot.c @@ -786,7 +786,7 @@ void exe_fire(player_type *shooter_ptr, INVENTORY_IDX item, object_type *j_ptr, if (!player_can_enter(shooter_ptr, shooter_ptr->current_floor_ptr->grid_array[ny][nx].feat, 0)) break; /* Stopped by monsters */ - if (!cave_empty_bold(shooter_ptr->current_floor_ptr, ny, nx)) break; + if (!is_cave_empty_bold(shooter_ptr, ny, nx)) break; shooter_ptr->current_floor_ptr->grid_array[ny][nx].m_idx = m_idx; shooter_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = 0; diff --git a/src/floor-save.c b/src/floor-save.c index a2ff81fdb..cea5893f0 100644 --- a/src/floor-save.c +++ b/src/floor-save.c @@ -738,7 +738,7 @@ static void get_out_monster(player_type *protected_ptr) if (!in_bounds(floor_ptr, ny, nx)) continue; /* Require "empty" floor space */ - if (!cave_empty_bold(floor_ptr, ny, nx)) continue; + if (!is_cave_empty_bold(protected_ptr, ny, nx)) continue; /* Hack -- no teleport onto glyph of warding */ if (is_glyph_grid(&floor_ptr->grid_array[ny][nx])) continue; diff --git a/src/floor.c b/src/floor.c index c9ff4ff38..1415eabf2 100644 --- a/src/floor.c +++ b/src/floor.c @@ -45,6 +45,39 @@ bool pattern_tile(floor_type *floor_ptr, POSITION y, POSITION x) } +/* + * Determine if a "legal" grid is an "empty" floor grid + * Determine if monsters are allowed to move into a grid + * + * Line 1 -- forbid non-placement grids + * Line 2 -- forbid normal monsters + * Line 3 -- forbid the player + */ +bool is_cave_empty_bold(player_type *player_ptr, POSITION x, POSITION y) +{ + floor_type *floor_ptr = player_ptr->current_floor_ptr; + bool is_empty_grid = cave_have_flag_bold(floor_ptr, y, x, FF_PLACE); + is_empty_grid &= !(floor_ptr->grid_array[y][x].m_idx); + is_empty_grid &= !player_bold(player_ptr, y, x); + return is_empty_grid; +} + + +/* + * Determine if a "legal" grid is an "empty" floor grid + * Determine if monster generation is allowed in a grid + * + * Line 1 -- forbid non-empty grids + * Line 2 -- forbid trees while dungeon generation + */ +bool is_cave_empty_bold2(player_type *player_ptr, POSITION y, POSITION x) +{ + bool is_empty_grid = is_cave_empty_bold(player_ptr, y, x); + is_empty_grid &= current_world_ptr->character_dungeon || !cave_have_flag_bold(player_ptr->current_floor_ptr, y, x, FF_TREE); + return is_empty_grid; +} + + /*! * @brief 鍵のかかったドアを配置する * @param player_ptr プレーヤーへの参照ポインタ diff --git a/src/floor.h b/src/floor.h index f9b263ddd..f033af03b 100644 --- a/src/floor.h +++ b/src/floor.h @@ -255,32 +255,6 @@ extern floor_type floor_info; /* - * Determine if a "legal" grid is an "empty" floor grid - * Determine if monsters are allowed to move into a grid - * - * Line 1 -- forbid non-placement grids - * Line 2 -- forbid normal monsters - * Line 3 -- forbid the player - */ -#define cave_empty_bold(F,Y,X) \ - (cave_have_flag_bold((F), (Y), (X), FF_PLACE) && \ - !((F)->grid_array[Y][X].m_idx) && \ - !player_bold(p_ptr, Y,X)) - - -/* - * Determine if a "legal" grid is an "empty" floor grid - * Determine if monster generation is allowed in a grid - * - * Line 1 -- forbid non-empty grids - * Line 2 -- forbid trees while dungeon generation - */ -#define cave_empty_bold2(F,Y,X) \ - (cave_empty_bold(F,Y,X) && \ - (current_world_ptr->character_dungeon || !cave_have_flag_bold((F), (Y), (X), FF_TREE))) - - -/* * Determine if a "legal" grid is an "naked" floor grid * * Line 1 -- forbid non-clean gird @@ -363,6 +337,8 @@ extern saved_floor_type saved_floors[MAX_SAVED_FLOORS]; ((int)((G) % 256U)) extern bool pattern_tile(floor_type *floor_ptr, POSITION y, POSITION x); +extern bool is_cave_empty_bold(player_type *player_ptr, POSITION x, POSITION y); +extern bool is_cave_empty_bold2(player_type *player_ptr, POSITION x, POSITION y); extern void update_smell(floor_type *floor_ptr, player_type *subject_ptr); extern void add_door(player_type *player_ptr, POSITION x, POSITION y); diff --git a/src/mind.c b/src/mind.c index de5887e33..b73af3d4d 100644 --- a/src/mind.c +++ b/src/mind.c @@ -1663,7 +1663,7 @@ static bool cast_ninja_spell(player_type *caster_ptr, int spell) POSITION nx = GRID_X(path_g[i]); grid_type *g_ptr = &floor_ptr->grid_array[ny][nx]; - if (in_bounds(floor_ptr, ny, nx) && cave_empty_bold(floor_ptr, ny, nx) && + if (in_bounds(floor_ptr, ny, nx) && is_cave_empty_bold(caster_ptr, ny, nx) && !(g_ptr->info & CAVE_OBJECT) && !pattern_tile(floor_ptr, ny, nx)) { diff --git a/src/monster1.c b/src/monster1.c index 62f3bbff9..2a0ee4d16 100644 --- a/src/monster1.c +++ b/src/monster1.c @@ -2583,7 +2583,7 @@ void monster_death(player_type *player_ptr, MONSTER_IDX m_idx, bool drop_item) do { scatter(player_ptr, &wy, &wx, y, x, 20, 0); - } while (!(in_bounds(floor_ptr, wy, wx) && cave_empty_bold2(floor_ptr, wy, wx)) && --attempts); + } while (!(in_bounds(floor_ptr, wy, wx) && is_cave_empty_bold2(player_ptr, wy, wx)) && --attempts); if (attempts <= 0) break; diff --git a/src/monster2.c b/src/monster2.c index bab36fe31..8b4281fa0 100644 --- a/src/monster2.c +++ b/src/monster2.c @@ -2873,7 +2873,7 @@ static bool mon_scatter(player_type *player_ptr, MONRACE_IDX r_idx, POSITION *yp else { /* Walls and Monsters block flow */ - if (!cave_empty_bold2(floor_ptr, ny, nx)) continue; + if (!is_cave_empty_bold2(player_ptr, ny, nx)) continue; /* ... nor on the Pattern */ if (pattern_tile(floor_ptr, ny, nx)) continue; @@ -2972,7 +2972,7 @@ static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITI scatter(player_ptr, &my, &mx, hy, hx, 4, 0); /* Walls and Monsters block flow */ - if (!cave_empty_bold2(floor_ptr, my, mx)) continue; + if (!is_cave_empty_bold2(player_ptr, my, mx)) continue; /* Attempt to place another monster */ if (place_monster_one(player_ptr, who, my, mx, r_idx, mode)) @@ -3122,7 +3122,7 @@ bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POS scatter(player_ptr, &ny, &nx, y, x, d, 0); /* Require empty grids */ - if (!cave_empty_bold2(player_ptr->current_floor_ptr, ny, nx)) continue; + if (!is_cave_empty_bold2(player_ptr, ny, nx)) continue; get_mon_num_prep(player_ptr, place_monster_can_escort, get_monster_hook2(player_ptr, ny, nx)); /* Pick a random race */ @@ -3260,7 +3260,7 @@ bool alloc_guardian(player_type *player_ptr, bool def_val) POSITION ox = randint1(floor_ptr->width - 4) + 2; /* Is it a good spot ? */ - if (!cave_empty_bold2(floor_ptr, oy, ox)) + if (!is_cave_empty_bold2(player_ptr, oy, ox)) { try_count++; continue; @@ -3310,11 +3310,11 @@ bool alloc_monster(player_type *player_ptr, POSITION dis, BIT_FLAGS mode) /* Require empty floor grid (was "naked") */ if (floor_ptr->dun_level) { - if (!cave_empty_bold2(floor_ptr, y, x)) continue; + if (!is_cave_empty_bold2(player_ptr, y, x)) continue; } else { - if (!cave_empty_bold(floor_ptr, y, x)) continue; + if (!is_cave_empty_bold(player_ptr, y, x)) continue; } /* Accept far away grids */ diff --git a/src/mspells1.c b/src/mspells1.c index 002262824..1caa7e454 100644 --- a/src/mspells1.c +++ b/src/mspells1.c @@ -394,7 +394,7 @@ bool summon_possible(player_type *target_ptr, POSITION y1, POSITION x1) if (pattern_tile(floor_ptr, y, x)) continue; /* Require empty floor grid in line of projection */ - if (cave_empty_bold(floor_ptr, y, x) && projectable(target_ptr, y1, x1, y, x) && projectable(target_ptr, y, x, y1, x1)) return TRUE; + if (is_cave_empty_bold(target_ptr, y, x) && projectable(target_ptr, y1, x1, y, x) && projectable(target_ptr, y, x, y1, x1)) return TRUE; } } diff --git a/src/mspells4.c b/src/mspells4.c index 43fed0f53..bf261dbcd 100644 --- a/src/mspells4.c +++ b/src/mspells4.c @@ -3395,23 +3395,22 @@ MONSTER_NUMBER summon_NAZGUL(player_type *target_ptr, POSITION y, POSITION x, MO msg_print(NULL); - floor_type *floor_ptr = target_ptr->current_floor_ptr; int count = 0; for (int k = 0; k < 30; k++) { - if (!summon_possible(target_ptr, cy, cx) || !cave_empty_bold(floor_ptr, cy, cx)) + if (!summon_possible(target_ptr, cy, cx) || !is_cave_empty_bold(target_ptr, cy, cx)) { int j; for (j = 100; j > 0; j--) { scatter(target_ptr, &cy, &cx, y, x, 2, 0); - if (cave_empty_bold(floor_ptr, cy, cx)) break; + if (is_cave_empty_bold(target_ptr, cy, cx)) break; } if (!j) break; } - if (!cave_empty_bold(floor_ptr, cy, cx)) continue; + if (!is_cave_empty_bold(target_ptr, cy, cx)) continue; if (!summon_named_creature(target_ptr, m_idx, cy, cx, MON_NAZGUL, mode)) continue; diff --git a/src/realm-crusade.c b/src/realm-crusade.c index b89ebb11d..32863044f 100644 --- a/src/realm-crusade.c +++ b/src/realm-crusade.c @@ -562,7 +562,7 @@ concptr do_crusade_spell(player_type *caster_ptr, SPELL_IDX spell, BIT_FLAGS mod scatter(caster_ptr, &my, &mx, caster_ptr->y, caster_ptr->x, 4, 0); /* Require empty grids */ - if (cave_empty_bold2(caster_ptr->current_floor_ptr, my, mx)) break; + if (is_cave_empty_bold2(caster_ptr, my, mx)) break; } if (attempt < 0) continue; summon_specific(caster_ptr, -1, my, mx, plev, SUMMON_KNIGHTS, (PM_ALLOW_GROUP | PM_FORCE_PET | PM_HASTE)); diff --git a/src/realm-hex.c b/src/realm-hex.c index 79fa510c6..6e2a937d6 100644 --- a/src/realm-hex.c +++ b/src/realm-hex.c @@ -1026,7 +1026,7 @@ concptr do_hex_spell(player_type *caster_ptr, SPELL_IDX spell, BIT_FLAGS mode) if (caster_ptr->current_floor_ptr->grid_array[dy][dx].m_idx) flag = TRUE; } - if (!cave_empty_bold(caster_ptr->current_floor_ptr, y, x) || (caster_ptr->current_floor_ptr->grid_array[y][x].info & CAVE_ICKY) || + if (!is_cave_empty_bold(caster_ptr, y, x) || (caster_ptr->current_floor_ptr->grid_array[y][x].info & CAVE_ICKY) || (distance(y, x, caster_ptr->y, caster_ptr->x) > plev + 2)) { msg_print(_("そこには移動できない。", "Can not teleport to there.")); diff --git a/src/realm-hissatsu.c b/src/realm-hissatsu.c index c18c7c034..34287a711 100644 --- a/src/realm-hissatsu.c +++ b/src/realm-hissatsu.c @@ -313,7 +313,7 @@ concptr do_hissatsu_spell(player_type *caster_ptr, SPELL_IDX spell, BIT_FLAGS mo { y += ddy[dir]; x += ddx[dir]; - if (cave_empty_bold(caster_ptr->current_floor_ptr, y, x)) + if (is_cave_empty_bold(caster_ptr, y, x)) { ty = y; tx = x; diff --git a/src/spells-floor.c b/src/spells-floor.c index 961f6159f..5df07da74 100644 --- a/src/spells-floor.c +++ b/src/spells-floor.c @@ -800,7 +800,7 @@ bool earthquake(player_type *caster_ptr, POSITION cy, POSITION cx, POSITION r, M x = caster_ptr->x + ddx_ddd[i]; /* Skip non-empty grids */ - if (!cave_empty_bold(floor_ptr, y, x)) continue; + if (!is_cave_empty_bold(caster_ptr, y, x)) continue; /* Important -- Skip "quake" grids */ if (map[16 + y - cy][16 + x - cx]) continue; @@ -949,7 +949,7 @@ bool earthquake(player_type *caster_ptr, POSITION cy, POSITION cx, POSITION r, M x = xx + ddx_ddd[i]; /* Skip non-empty grids */ - if (!cave_empty_bold(floor_ptr, y, x)) continue; + if (!is_cave_empty_bold(caster_ptr, y, x)) continue; /* Hack -- no safety on glyph of warding */ if (is_glyph_grid(&floor_ptr->grid_array[y][x])) continue; diff --git a/src/spells2.c b/src/spells2.c index 6c0c393c9..b49c921ce 100644 --- a/src/spells2.c +++ b/src/spells2.c @@ -3104,7 +3104,7 @@ bool rush_attack(player_type *attacker_ptr, bool *mdeath) int ny = GRID_Y(path_g[i]); int nx = GRID_X(path_g[i]); - if (cave_empty_bold(floor_ptr, ny, nx) && player_can_enter(attacker_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) + if (is_cave_empty_bold(attacker_ptr, ny, nx) && player_can_enter(attacker_ptr, floor_ptr->grid_array[ny][nx].feat, 0)) { ty = ny; tx = nx; diff --git a/src/spells3.c b/src/spells3.c index a79dee6d9..80c14d384 100644 --- a/src/spells3.c +++ b/src/spells3.c @@ -3215,7 +3215,7 @@ bool shock_power(player_type *caster_ptr) { y += ddy[dir]; x += ddx[dir]; - if (cave_empty_bold(caster_ptr->current_floor_ptr, y, x)) + if (is_cave_empty_bold(caster_ptr, y, x)) { ty = y; tx = x; diff --git a/src/wizard2.c b/src/wizard2.c index 7a339c9ac..ab8d599dd 100644 --- a/src/wizard2.c +++ b/src/wizard2.c @@ -197,7 +197,7 @@ static void do_cmd_summon_horde(player_type *caster_ptr) while (--attempts) { scatter(caster_ptr, &wy, &wx, caster_ptr->y, caster_ptr->x, 3, 0); - if (cave_empty_bold(caster_ptr->current_floor_ptr, wy, wx)) break; + if (is_cave_empty_bold(caster_ptr, wy, wx)) break; } (void)alloc_horde(caster_ptr, wy, wx);