OSDN Git Service

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