From 7892f070169eaec21145a7ecef7711996898dfd4 Mon Sep 17 00:00:00 2001 From: Hourier Date: Mon, 2 Aug 2021 22:30:09 +0900 Subject: [PATCH] [Refactor] #921 Separated search_room_to_run() from check_hiding_grid() --- src/monster-floor/monster-sweep-grid.cpp | 70 ++++++++++++++++++-------------- src/monster-floor/monster-sweep-grid.h | 1 + 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/monster-floor/monster-sweep-grid.cpp b/src/monster-floor/monster-sweep-grid.cpp index f32012c44..7b28bc1d0 100644 --- a/src/monster-floor/monster-sweep-grid.cpp +++ b/src/monster-floor/monster-sweep-grid.cpp @@ -165,36 +165,7 @@ void MonsterSweepGrid::check_hiding_grid(POSITION *y, POSITION *x, POSITION *y2, } } - if (any_bits(r_ptr->flags3, RF3_ANIMAL) && !this->can_pass_wall && !any_bits(r_ptr->flags2, RF2_KILL_WALL)) { - auto room = 0; - for (auto i = 0; i < 8; i++) { - auto xx = this->target_ptr->x + ddx_ddd[i]; - auto yy = this->target_ptr->y + ddy_ddd[i]; - if (!in_bounds2(floor_ptr, yy, xx)) { - continue; - } - - auto *g_ptr = &floor_ptr->grid_array[yy][xx]; - if (monster_can_cross_terrain(this->target_ptr, g_ptr->feat, r_ptr, 0)) { - room++; - } - } - - if (any_bits(floor_ptr->grid_array[this->target_ptr->y][this->target_ptr->x].info, CAVE_ROOM)) { - room -= 2; - } - - if (r_ptr->ability_flags.none()) { - room -= 2; - } - - if (room < (8 * (this->target_ptr->chp + this->target_ptr->csp)) / (this->target_ptr->mhp + this->target_ptr->msp)) { - if (find_hiding(this->target_ptr, this->m_idx, y, x)) { - this->done = true; - } - } - } - + this->search_room_to_run(y, x); if (this->done || (grid_dist(&floor_ptr->grid_array[m_ptr->fy][m_ptr->fx], r_ptr) >= 3)) { return; } @@ -220,6 +191,45 @@ void MonsterSweepGrid::check_hiding_grid(POSITION *y, POSITION *x, POSITION *y2, this->done = true; } +void MonsterSweepGrid::search_room_to_run(POSITION *y, POSITION *x) +{ + auto *floor_ptr = this->target_ptr->current_floor_ptr; + auto *r_ptr = &r_info[floor_ptr->m_list[this->m_idx].r_idx]; + if (none_bits(r_ptr->flags3, RF3_ANIMAL) || this->can_pass_wall || any_bits(r_ptr->flags2, RF2_KILL_WALL)) { + return; + } + + auto room = 0; + for (auto i = 0; i < 8; i++) { + auto xx = this->target_ptr->x + ddx_ddd[i]; + auto yy = this->target_ptr->y + ddy_ddd[i]; + if (!in_bounds2(floor_ptr, yy, xx)) { + continue; + } + + auto *g_ptr = &floor_ptr->grid_array[yy][xx]; + if (monster_can_cross_terrain(this->target_ptr, g_ptr->feat, r_ptr, 0)) { + room++; + } + } + + if (any_bits(floor_ptr->grid_array[this->target_ptr->y][this->target_ptr->x].info, CAVE_ROOM)) { + room -= 2; + } + + if (r_ptr->ability_flags.none()) { + room -= 2; + } + + if (room >= (8 * (this->target_ptr->chp + this->target_ptr->csp)) / (this->target_ptr->mhp + this->target_ptr->msp)) { + return; + } + + if (find_hiding(this->target_ptr, this->m_idx, y, x)) { + this->done = true; + } +} + /*! * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する / * Choose the "best" direction for "flowing" diff --git a/src/monster-floor/monster-sweep-grid.h b/src/monster-floor/monster-sweep-grid.h index f4e8ae083..ac479375d 100644 --- a/src/monster-floor/monster-sweep-grid.h +++ b/src/monster-floor/monster-sweep-grid.h @@ -23,4 +23,5 @@ private: bool sweep_ranged_attack_grid(POSITION *yp, POSITION *xp); bool sweep_runnable_away_grid(POSITION *yp, POSITION *xp); void check_hiding_grid(POSITION *y, POSITION *x, POSITION *y2, POSITION *x2); + void search_room_to_run(POSITION *y, POSITION *x); }; -- 2.11.0