OSDN Git Service

Merge remote-tracking branch 'remotes/hengbandosx/english-mind-edits' into feature...
[hengband/hengband.git] / src / io / cursor.c
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 "grid/grid.h"
12 #include "io/screen-util.h"
13 #include "system/floor-type-definition.h"
14 #include "target/projection-path-calculator.h"
15 #include "term/term-color-types.h"
16 #include "view/display-map.h"
17 #include "window/main-window-util.h"
18 #include "world/world.h"
19
20 /*
21  * Moves the cursor to a given MAP (y,x) location
22  */
23 void move_cursor_relative(int row, int col)
24 {
25     row -= panel_row_prt;
26     term_gotoxy(panel_col_of(col), row);
27 }
28
29 /*
30  * @brief 矢などの軌跡を*で表示する / print project path
31  * @param player_ptr プレーヤーへの参照ポインタ
32  * @param y 目標地点のY座標
33  * @param x 目標地点のX座標
34  * @return なし
35  */
36 void print_path(player_type *player_ptr, POSITION y, POSITION x)
37 {
38     u16b path_g[512];
39     byte default_color = TERM_SLATE;
40
41     if (!display_path || (project_length == -1))
42         return;
43
44     floor_type *floor_ptr = player_ptr->current_floor_ptr;
45     int path_n = projection_path(
46         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);
47     player_ptr->redraw |= (PR_MAP);
48     handle_stuff(player_ptr);
49     for (int i = 0; i < path_n; i++) {
50         POSITION ny = get_grid_y(path_g[i]);
51         POSITION nx = get_grid_x(path_g[i]);
52         grid_type *g_ptr = &floor_ptr->grid_array[ny][nx];
53         if (panel_contains(ny, nx)) {
54             TERM_COLOR a = default_color;
55             SYMBOL_CODE c;
56
57             TERM_COLOR ta = default_color;
58             SYMBOL_CODE tc = '*';
59
60             if (g_ptr->m_idx && 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             if (!use_graphics) {
72                 if (current_world_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             c = '*';
81             term_queue_bigchar(panel_col_of(nx), ny - panel_row_prt, a, c, ta, tc);
82         }
83
84         if ((g_ptr->info & CAVE_MARK) && !cave_has_flag_grid(g_ptr, FF_PROJECT))
85             break;
86
87         if (nx == x && ny == y)
88             default_color = TERM_L_DARK;
89     }
90 }
91
92 /*!
93  * @brief フォーカスを当てるべきマップ描画の基準座標を指定する(サブルーチン)
94  * @param creature_ptr プレーヤーへの参照ポインタ
95  * @param dy 変更先のフロアY座標
96  * @param dx 変更先のフロアX座標
97  * Handle a request to change the current panel
98  * Return TRUE if the panel was changed.
99  * Also used in do_cmd_locate
100  * @return 実際に再描画が必要だった場合TRUEを返す
101  */
102 bool change_panel(player_type *player_ptr, POSITION dy, POSITION dx)
103 {
104     TERM_LEN wid, hgt;
105     get_screen_size(&wid, &hgt);
106
107     POSITION y = panel_row_min + dy * hgt / 2;
108     POSITION x = panel_col_min + dx * wid / 2;
109
110     floor_type *floor_ptr = player_ptr->current_floor_ptr;
111     if (y > floor_ptr->height - hgt)
112         y = floor_ptr->height - hgt;
113     if (y < 0)
114         y = 0;
115
116     if (x > floor_ptr->width - wid)
117         x = floor_ptr->width - wid;
118     if (x < 0)
119         x = 0;
120
121     if ((y == panel_row_min) && (x == panel_col_min))
122         return FALSE;
123
124     panel_row_min = y;
125     panel_col_min = x;
126     panel_bounds_center();
127
128     player_ptr->update |= (PU_MONSTERS);
129     player_ptr->redraw |= (PR_MAP);
130     handle_stuff(player_ptr);
131     return TRUE;
132 }
133
134 /*!
135  * @brief コンソール上におけるマップ表示の左上位置を返す /
136  * Calculates current boundaries Called below and from "do_cmd_locate()".
137  * @return なし
138  */
139 void panel_bounds_center(void)
140 {
141     TERM_LEN wid, hgt;
142     get_screen_size(&wid, &hgt);
143     panel_row_max = panel_row_min + hgt - 1;
144     panel_row_prt = panel_row_min - 1;
145     panel_col_max = panel_col_min + wid - 1;
146     panel_col_prt = panel_col_min - 13;
147 }