OSDN Git Service

[Refactor] #919 Removed cave_los_grid() and moved cave_has_los_grid() from cave.cpp...
[hengbandforosx/hengbandosx.git] / src / io / cursor.cpp
1 #include "io/cursor.h"
2 #include "core/player-redraw-types.h"
3 #include "core/player-update-types.h"
4 #include "core/stuff-handler.h"
5 #include "effect/effect-characteristics.h"
6 #include "effect/spells-effect-util.h"
7 #include "floor/cave.h"
8 #include "game-option/map-screen-options.h"
9 #include "game-option/special-options.h"
10 #include "grid/feature.h"
11 #include "io/screen-util.h"
12 #include "player/player-status.h"
13 #include "system/floor-type-definition.h"
14 #include "system/grid-type-definition.h"
15 #include "system/monster-type-definition.h"
16 #include "system/player-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(player_type *player_ptr, POSITION y, POSITION x)
39 {
40     u16b path_g[512];
41     byte default_color = TERM_SLATE;
42
43     if (!display_path || (project_length == -1))
44         return;
45
46     floor_type *floor_ptr = player_ptr->current_floor_ptr;
47     int path_n = projection_path(
48         player_ptr, path_g, (project_length ? project_length : get_max_range(player_ptr)), player_ptr->y, player_ptr->x, y, x, PROJECT_PATH | PROJECT_THRU);
49     player_ptr->redraw |= (PR_MAP);
50     handle_stuff(player_ptr);
51     for (int i = 0; i < path_n; i++) {
52         POSITION ny = get_grid_y(path_g[i]);
53         POSITION nx = get_grid_x(path_g[i]);
54         grid_type *g_ptr = &floor_ptr->grid_array[ny][nx];
55         if (panel_contains(ny, nx)) {
56             TERM_COLOR a = default_color;
57             SYMBOL_CODE c;
58
59             TERM_COLOR ta = default_color;
60             SYMBOL_CODE tc = '*';
61
62             if (g_ptr->m_idx && floor_ptr->m_list[g_ptr->m_idx].ml) {
63                 map_info(player_ptr, ny, nx, &a, &c, &ta, &tc);
64
65                 if (!is_ascii_graphics(a))
66                     a = default_color;
67                 else if (c == '.' && (a == TERM_WHITE || a == TERM_L_WHITE))
68                     a = default_color;
69                 else if (a == default_color)
70                     a = TERM_WHITE;
71             }
72
73             if (!use_graphics) {
74                 if (current_world_ptr->timewalk_m_idx)
75                     a = TERM_DARK;
76                 else if (is_invuln(player_ptr) || player_ptr->timewalk)
77                     a = TERM_WHITE;
78                 else if (player_ptr->wraith_form)
79                     a = TERM_L_DARK;
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(FF_PROJECT))
87             break;
88
89         if (nx == x && ny == y)
90             default_color = TERM_L_DARK;
91     }
92 }
93
94 /*!
95  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
96  * @param creature_ptr プレーヤーへの参照ポインタ
97  * @param dy 変更先のフロアY座標
98  * @param dx 変更先のフロアX座標
99  * Handle a request to change the current panel
100  * Return TRUE if the panel was changed.
101  * Also used in do_cmd_locate
102  * @return 実際に再描画が必要だった場合TRUEを返す
103  */
104 bool change_panel(player_type *player_ptr, POSITION dy, POSITION dx)
105 {
106     TERM_LEN wid, hgt;
107     get_screen_size(&wid, &hgt);
108
109     POSITION y = panel_row_min + dy * hgt / 2;
110     POSITION x = panel_col_min + dx * wid / 2;
111
112     floor_type *floor_ptr = player_ptr->current_floor_ptr;
113     if (y > floor_ptr->height - hgt)
114         y = floor_ptr->height - hgt;
115     if (y < 0)
116         y = 0;
117
118     if (x > floor_ptr->width - wid)
119         x = floor_ptr->width - wid;
120     if (x < 0)
121         x = 0;
122
123     if ((y == panel_row_min) && (x == panel_col_min))
124         return false;
125
126     panel_row_min = y;
127     panel_col_min = x;
128     panel_bounds_center();
129
130     player_ptr->update |= (PU_MONSTERS);
131     player_ptr->redraw |= (PR_MAP);
132     handle_stuff(player_ptr);
133     return true;
134 }
135
136 /*!
137  * @brief コンソール上におけるマップ表示の左上位置を返す /
138  * Calculates current boundaries Called below and from "do_cmd_locate()".
139  */
140 void panel_bounds_center(void)
141 {
142     TERM_LEN wid, hgt;
143     get_screen_size(&wid, &hgt);
144     panel_row_max = panel_row_min + hgt - 1;
145     panel_row_prt = panel_row_min - 1;
146     panel_col_max = panel_col_min + wid - 1;
147     panel_col_prt = panel_col_min - 13;
148 }