OSDN Git Service

[Refactor] #3286 Removed player-redraw-types.h
[hengbandforosx/hengbandosx.git] / src / spell-kind / spells-fetcher.cpp
index 2be9600..dacbb39 100644 (file)
@@ -1,6 +1,4 @@
 #include "spell-kind/spells-fetcher.h"
-#include "core/player-redraw-types.h"
-#include "core/player-update-types.h"
 #include "core/stuff-handler.h"
 #include "flavor/flavor-describer.h"
 #include "flavor/object-flavor-types.h"
@@ -9,20 +7,24 @@
 #include "grid/feature-flag-types.h"
 #include "grid/grid.h"
 #include "monster-race/monster-race.h"
+#include "monster-race/race-brightness-mask.h"
 #include "monster-race/race-flags7.h"
 #include "monster/monster-describer.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-update.h"
 #include "system/floor-type-definition.h"
 #include "system/grid-type-definition.h"
-#include "system/object-type-definition.h"
-#include "system/monster-race-definition.h"
-#include "system/monster-type-definition.h"
+#include "system/item-entity.h"
+#include "system/monster-entity.h"
+#include "system/monster-race-info.h"
 #include "system/player-type-definition.h"
+#include "system/redrawing-flags-updater.h"
 #include "target/projection-path-calculator.h"
 #include "target/target-checker.h"
 #include "target/target-setter.h"
 #include "target/target-types.h"
+#include "timed-effect/player-hallucination.h"
+#include "timed-effect/timed-effects.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
 
  * @param wgt 許容重量
  * @param require_los 射線の通りを要求するならばTRUE
  */
-void fetch_item(player_type *player_ptr, DIRECTION dir, WEIGHT wgt, bool require_los)
+void fetch_item(PlayerType *player_ptr, DIRECTION dir, WEIGHT wgt, bool require_los)
 {
-    grid_type *g_ptr;
-    object_type *o_ptr;
-    GAME_TEXT o_name[MAX_NLEN];
-
-    if (!player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].o_idx_list.empty()) {
+    auto *floor_ptr = player_ptr->current_floor_ptr;
+    if (!floor_ptr->grid_array[player_ptr->y][player_ptr->x].o_idx_list.empty()) {
         msg_print(_("自分の足の下にある物は取れません。", "You can't fetch when you're already standing on something."));
         return;
     }
 
     POSITION ty, tx;
+    grid_type *g_ptr;
     if (dir == 5 && target_okay(player_ptr)) {
         tx = target_col;
         ty = target_row;
@@ -55,7 +55,7 @@ void fetch_item(player_type *player_ptr, DIRECTION dir, WEIGHT wgt, bool require
             return;
         }
 
-        g_ptr = &player_ptr->current_floor_ptr->grid_array[ty][tx];
+        g_ptr = &floor_ptr->grid_array[ty][tx];
         if (g_ptr->o_idx_list.empty()) {
             msg_print(_("そこには何もありません。", "There is no object there."));
             return;
@@ -79,20 +79,23 @@ void fetch_item(player_type *player_ptr, DIRECTION dir, WEIGHT wgt, bool require
         ty = player_ptr->y;
         tx = player_ptr->x;
         bool is_first_loop = true;
-        g_ptr = &player_ptr->current_floor_ptr->grid_array[ty][tx];
+        g_ptr = &floor_ptr->grid_array[ty][tx];
         while (is_first_loop || g_ptr->o_idx_list.empty()) {
             is_first_loop = false;
             ty += ddy[dir];
             tx += ddx[dir];
-            g_ptr = &player_ptr->current_floor_ptr->grid_array[ty][tx];
+            g_ptr = &floor_ptr->grid_array[ty][tx];
+            if ((distance(player_ptr->y, player_ptr->x, ty, tx) > get_max_range(player_ptr))) {
+                return;
+            }
 
-            if ((distance(player_ptr->y, player_ptr->x, ty, tx) > get_max_range(player_ptr))
-                || !cave_has_flag_bold(player_ptr->current_floor_ptr, ty, tx, FF::PROJECT))
+            if (!cave_has_flag_bold(floor_ptr, ty, tx, TerrainCharacteristics::PROJECT)) {
                 return;
+            }
         }
     }
 
-    o_ptr = &player_ptr->current_floor_ptr->o_list[g_ptr->o_idx_list.front()];
+    auto *o_ptr = &floor_ptr->o_list[g_ptr->o_idx_list.front()];
     if (o_ptr->weight > wgt) {
         msg_print(_("そのアイテムは重過ぎます。", "The object is too heavy."));
         return;
@@ -100,72 +103,67 @@ void fetch_item(player_type *player_ptr, DIRECTION dir, WEIGHT wgt, bool require
 
     OBJECT_IDX i = g_ptr->o_idx_list.front();
     g_ptr->o_idx_list.pop_front();
-    player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].o_idx_list.add(player_ptr->current_floor_ptr, i); /* 'move' it */
-
+    floor_ptr->grid_array[player_ptr->y][player_ptr->x].o_idx_list.add(floor_ptr, i); /* 'move' it */
     o_ptr->iy = player_ptr->y;
     o_ptr->ix = player_ptr->x;
 
-    describe_flavor(player_ptr, o_name, o_ptr, OD_NAME_ONLY);
-    msg_format(_("%^sがあなたの足元に飛んできた。", "%^s flies through the air to your feet."), o_name);
-
+    const auto item_name = describe_flavor(player_ptr, o_ptr, OD_NAME_ONLY);
+    msg_format(_("%s^があなたの足元に飛んできた。", "%s^ flies through the air to your feet."), item_name.data());
     note_spot(player_ptr, player_ptr->y, player_ptr->x);
-    player_ptr->redraw |= PR_MAP;
+    RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::MAP);
 }
 
-bool fetch_monster(player_type *player_ptr)
+bool fetch_monster(PlayerType *player_ptr)
 {
-    monster_type *m_ptr;
-    MONSTER_IDX m_idx;
-    GAME_TEXT m_name[MAX_NLEN];
-    int i;
-    int path_n;
-    uint16_t path_g[512];
-    POSITION ty, tx;
-
-    if (!target_set(player_ptr, TARGET_KILL))
+    if (!target_set(player_ptr, TARGET_KILL)) {
         return false;
+    }
 
-    m_idx = player_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx;
-    if (!m_idx)
+    auto *floor_ptr = player_ptr->current_floor_ptr;
+    auto m_idx = floor_ptr->grid_array[target_row][target_col].m_idx;
+    if (!m_idx) {
         return false;
-    if (m_idx == player_ptr->riding)
+    }
+    if (m_idx == player_ptr->riding) {
         return false;
-    if (!player_has_los_bold(player_ptr, target_row, target_col))
+    }
+    if (!player_has_los_bold(player_ptr, target_row, target_col)) {
         return false;
-    if (!projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col))
+    }
+    if (!projectable(player_ptr, player_ptr->y, player_ptr->x, target_row, target_col)) {
         return false;
+    }
+
+    auto *m_ptr = &floor_ptr->m_list[m_idx];
+    const auto m_name = monster_desc(player_ptr, m_ptr, 0);
+    msg_format(_("%sを引き戻した。", "You pull back %s."), m_name.data());
+    projection_path path_g(player_ptr, get_max_range(player_ptr), target_row, target_col, player_ptr->y, player_ptr->x, 0);
+    auto ty = target_row, tx = target_col;
+    for (const auto &[ny, nx] : path_g) {
+        auto *g_ptr = &floor_ptr->grid_array[ny][nx];
 
-    m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
-    monster_desc(player_ptr, m_name, m_ptr, 0);
-    msg_format(_("%sを引き戻した。", "You pull back %s."), m_name);
-    path_n = projection_path(player_ptr, path_g, get_max_range(player_ptr), target_row, target_col, player_ptr->y, player_ptr->x, 0);
-    ty = target_row, tx = target_col;
-    for (i = 1; i < path_n; i++) {
-        POSITION ny = get_grid_y(path_g[i]);
-        POSITION nx = get_grid_x(path_g[i]);
-        grid_type *g_ptr = &player_ptr->current_floor_ptr->grid_array[ny][nx];
-
-        if (in_bounds(player_ptr->current_floor_ptr, ny, nx) && is_cave_empty_bold(player_ptr, ny, nx) && !g_ptr->is_object()
-            && !pattern_tile(player_ptr->current_floor_ptr, ny, nx)) {
+        if (in_bounds(floor_ptr, ny, nx) && is_cave_empty_bold(player_ptr, ny, nx) && !g_ptr->is_object() && !pattern_tile(floor_ptr, ny, nx)) {
             ty = ny;
             tx = nx;
         }
     }
 
-    player_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx = 0;
-    player_ptr->current_floor_ptr->grid_array[ty][tx].m_idx = m_idx;
+    floor_ptr->grid_array[target_row][target_col].m_idx = 0;
+    floor_ptr->grid_array[ty][tx].m_idx = m_idx;
     m_ptr->fy = ty;
     m_ptr->fx = tx;
     (void)set_monster_csleep(player_ptr, m_idx, 0);
     update_monster(player_ptr, m_idx, true);
     lite_spot(player_ptr, target_row, target_col);
     lite_spot(player_ptr, ty, tx);
-    if (r_info[m_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
-        player_ptr->update |= (PU_MON_LITE);
+    if (monraces_info[m_ptr->r_idx].brightness_flags.has_any_of(ld_mask)) {
+        RedrawingFlagsUpdater::get_instance().set_flag(StatusRedrawingFlag::MONSTER_LITE);
+    }
 
     if (m_ptr->ml) {
-        if (!player_ptr->image)
+        if (!player_ptr->effects()->hallucination()->is_hallucinated()) {
             monster_race_track(player_ptr, m_ptr->ap_r_idx);
+        }
 
         health_track(player_ptr, m_idx);
     }