OSDN Git Service

[Refactor] Grid::has_monster()の定義
[hengbandforosx/hengbandosx.git] / src / io / cursor.cpp
1 #include "io/cursor.h"
2 #include "core/stuff-handler.h"
3 #include "effect/effect-characteristics.h"
4 #include "effect/spells-effect-util.h"
5 #include "floor/cave.h"
6 #include "game-option/map-screen-options.h"
7 #include "game-option/special-options.h"
8 #include "grid/feature.h"
9 #include "io/screen-util.h"
10 #include "player/player-status.h"
11 #include "system/angband-system.h"
12 #include "system/floor-type-definition.h"
13 #include "system/grid-type-definition.h"
14 #include "system/monster-entity.h"
15 #include "system/player-type-definition.h"
16 #include "system/redrawing-flags-updater.h"
17 #include "system/terrain-type-definition.h"
18 #include "target/projection-path-calculator.h"
19 #include "term/term-color-types.h"
20 #include "view/display-map.h"
21 #include "window/main-window-util.h"
22 #include "world/world.h"
23
24 /*
25  * Moves the cursor to a given MAP (y,x) location
26  */
27 void move_cursor_relative(int row, int col)
28 {
29     row -= panel_row_prt;
30     term_gotoxy(panel_col_of(col), row);
31 }
32
33 /*
34  * @brief 矢などの軌跡を*で表示する / print project path
35  * @param player_ptr プレイヤーへの参照ポインタ
36  * @param y 目標地点のY座標
37  * @param x 目標地点のX座標
38  */
39 void print_path(PlayerType *player_ptr, POSITION y, POSITION x)
40 {
41     byte default_color = TERM_SLATE;
42
43     if (!display_path || (project_length == -1)) {
44         return;
45     }
46
47     auto *floor_ptr = player_ptr->current_floor_ptr;
48     projection_path path_g(player_ptr, (project_length ? project_length : AngbandSystem::get_instance().get_max_range()), player_ptr->y, player_ptr->x, y, x, PROJECT_PATH | PROJECT_THRU);
49     RedrawingFlagsUpdater::get_instance().set_flag(MainWindowRedrawingFlag::MAP);
50     handle_stuff(player_ptr);
51     for (const auto &[ny, nx] : path_g) {
52         auto *g_ptr = &floor_ptr->grid_array[ny][nx];
53         if (panel_contains(ny, nx)) {
54             TERM_COLOR a = default_color;
55             char c;
56
57             TERM_COLOR ta = default_color;
58             auto tc = '*';
59
60             if (g_ptr->has_monster() && floor_ptr->m_list[g_ptr->m_idx].ml) {
61                 map_info(player_ptr, ny, nx, &a, &c, &ta, &tc);
62
63                 if (!is_ascii_graphics(a)) {
64                     a = default_color;
65                 } else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE)) {
66                     a = default_color;
67                 } else if (a == default_color) {
68                     a = TERM_WHITE;
69                 }
70             }
71
72             if (!use_graphics) {
73                 if (w_ptr->timewalk_m_idx) {
74                     a = TERM_DARK;
75                 } else if (is_invuln(player_ptr) || player_ptr->timewalk) {
76                     a = TERM_WHITE;
77                 } else if (player_ptr->wraith_form) {
78                     a = TERM_L_DARK;
79                 }
80             }
81
82             c = '*';
83             term_queue_bigchar(panel_col_of(nx), ny - panel_row_prt, a, c, ta, tc);
84         }
85
86         if (g_ptr->is_mark() && !g_ptr->cave_has_flag(TerrainCharacteristics::PROJECT)) {
87             break;
88         }
89
90         if (nx == x && ny == y) {
91             default_color = TERM_L_DARK;
92         }
93     }
94 }
95
96 /*!
97  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
98  * @param player_ptr プレイヤーへの参照ポインタ
99  * @param dy 変更先のフロアY座標
100  * @param dx 変更先のフロアX座標
101  * Handle a request to change the current panel
102  * Return TRUE if the panel was changed.
103  * Also used in do_cmd_locate
104  * @return 実際に再描画が必要だった場合TRUEを返す
105  */
106 bool change_panel(PlayerType *player_ptr, POSITION dy, POSITION dx)
107 {
108     const auto &[wid, hgt] = get_screen_size();
109     POSITION y = panel_row_min + dy * hgt / 2;
110     POSITION x = panel_col_min + dx * wid / 2;
111
112     auto *floor_ptr = player_ptr->current_floor_ptr;
113     if (y > floor_ptr->height - hgt) {
114         y = floor_ptr->height - hgt;
115     }
116     if (y < 0) {
117         y = 0;
118     }
119
120     if (x > floor_ptr->width - wid) {
121         x = floor_ptr->width - wid;
122     }
123     if (x < 0) {
124         x = 0;
125     }
126
127     if ((y == panel_row_min) && (x == panel_col_min)) {
128         return false;
129     }
130
131     panel_row_min = y;
132     panel_col_min = x;
133     panel_bounds_center();
134     auto &rfu = RedrawingFlagsUpdater::get_instance();
135     rfu.set_flag(StatusRecalculatingFlag::MONSTER_STATUSES);
136     rfu.set_flag(MainWindowRedrawingFlag::MAP);
137     handle_stuff(player_ptr);
138     return true;
139 }
140
141 /*!
142  * @brief コンソール上におけるマップ表示の左上位置を返す /
143  * Calculates current boundaries Called below and from "do_cmd_locate()".
144  */
145 void panel_bounds_center(void)
146 {
147     const auto &[wid, hgt] = get_screen_size();
148     panel_row_max = panel_row_min + hgt - 1;
149     panel_row_prt = panel_row_min - 1;
150     panel_col_max = panel_col_min + wid - 1;
151     panel_col_prt = panel_col_min - 13;
152 }