1 #include "player/player-view.h"
2 #include "core/player-update-types.h"
3 #include "floor/cave.h"
4 #include "floor/line-of-sight.h"
5 #include "game-option/map-screen-options.h"
7 #include "system/floor-type-definition.h"
10 * Helper function for "update_view()" below
12 * We are checking the "viewability" of grid (y,x) by the player.
14 * This function assumes that (y,x) is legal (i.e. on the map).
16 * Grid (y1,x1) is on the "diagonal" between (subject_ptr->y,subject_ptr->x) and (y,x)
17 * Grid (y2,x2) is "adjacent", also between (subject_ptr->y,subject_ptr->x) and (y,x).
19 * Note that we are using the "CAVE_XTRA" field for marking grids as
20 * "easily viewable". This bit is cleared at the end of "update_view()".
22 * This function adds (y,x) to the "viewable set" if necessary.
24 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
26 static bool update_view_aux(player_type *subject_ptr, POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
28 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
31 g1_c_ptr = &floor_ptr->grid_array[y1][x1];
32 g2_c_ptr = &floor_ptr->grid_array[y2][x2];
33 bool f1 = (cave_los_grid(g1_c_ptr));
34 bool f2 = (cave_los_grid(g2_c_ptr));
38 bool v1 = (f1 && (g1_c_ptr->info & CAVE_VIEW));
39 bool v2 = (f2 && (g2_c_ptr->info & CAVE_VIEW));
44 g_ptr = &floor_ptr->grid_array[y][x];
45 bool wall = (!cave_los_grid(g_ptr));
46 bool z1 = (v1 && (g1_c_ptr->info & CAVE_XTRA));
47 bool z2 = (v2 && (g2_c_ptr->info & CAVE_XTRA));
49 g_ptr->info |= CAVE_XTRA;
50 cave_view_hack(floor_ptr, g_ptr, y, x);
55 cave_view_hack(floor_ptr, g_ptr, y, x);
60 cave_view_hack(floor_ptr, g_ptr, y, x);
65 cave_view_hack(floor_ptr, g_ptr, y, x);
69 if (los(subject_ptr, subject_ptr->y, subject_ptr->x, y, x)) {
70 cave_view_hack(floor_ptr, g_ptr, y, x);
78 * Calculate the viewable space
80 * 1: Process the player
81 * 1a: The player is always (easily) viewable
82 * 2: Process the diagonals
83 * 2a: The diagonals are (easily) viewable up to the first wall
84 * 2b: But never go more than 2/3 of the "full" distance
85 * 3: Process the main axes
86 * 3a: The main axes are (easily) viewable up to the first wall
87 * 3b: But never go more than the "full" distance
88 * 4: Process sequential "strips" in each of the eight octants
89 * 4a: Each strip runs along the previous strip
90 * 4b: The main axes are "previous" to the first strip
91 * 4c: Process both "sides" of each "direction" of each strip
92 * 4c1: Each side aborts as soon as possible
93 * 4c2: Each side tells the next strip how far it has to check
95 void update_view(player_type *subject_ptr)
100 int se, sw, ne, nw, es, en, ws, wn;
104 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
105 POSITION y_max = floor_ptr->height - 1;
106 POSITION x_max = floor_ptr->width - 1;
109 if (view_reduce_view && !floor_ptr->dun_level) {
110 full = MAX_SIGHT / 2;
111 over = MAX_SIGHT * 3 / 4;
114 over = MAX_SIGHT * 3 / 2;
117 for (n = 0; n < floor_ptr->view_n; n++) {
118 y = floor_ptr->view_y[n];
119 x = floor_ptr->view_x[n];
120 g_ptr = &floor_ptr->grid_array[y][x];
121 g_ptr->info &= ~(CAVE_VIEW);
122 g_ptr->info |= CAVE_TEMP;
123 tmp_pos.y[tmp_pos.n] = y;
124 tmp_pos.x[tmp_pos.n] = x;
128 floor_ptr->view_n = 0;
131 g_ptr = &floor_ptr->grid_array[y][x];
132 g_ptr->info |= CAVE_XTRA;
133 cave_view_hack(floor_ptr, g_ptr, y, x);
136 for (d = 1; d <= z; d++) {
137 g_ptr = &floor_ptr->grid_array[y + d][x + d];
138 g_ptr->info |= CAVE_XTRA;
139 cave_view_hack(floor_ptr, g_ptr, y + d, x + d);
140 if (!cave_los_grid(g_ptr))
144 for (d = 1; d <= z; d++) {
145 g_ptr = &floor_ptr->grid_array[y + d][x - d];
146 g_ptr->info |= CAVE_XTRA;
147 cave_view_hack(floor_ptr, g_ptr, y + d, x - d);
148 if (!cave_los_grid(g_ptr))
152 for (d = 1; d <= z; d++) {
153 g_ptr = &floor_ptr->grid_array[y - d][x + d];
154 g_ptr->info |= CAVE_XTRA;
155 cave_view_hack(floor_ptr, g_ptr, y - d, x + d);
156 if (!cave_los_grid(g_ptr))
160 for (d = 1; d <= z; d++) {
161 g_ptr = &floor_ptr->grid_array[y - d][x - d];
162 g_ptr->info |= CAVE_XTRA;
163 cave_view_hack(floor_ptr, g_ptr, y - d, x - d);
164 if (!cave_los_grid(g_ptr))
168 for (d = 1; d <= full; d++) {
169 g_ptr = &floor_ptr->grid_array[y + d][x];
170 g_ptr->info |= CAVE_XTRA;
171 cave_view_hack(floor_ptr, g_ptr, y + d, x);
172 if (!cave_los_grid(g_ptr))
177 for (d = 1; d <= full; d++) {
178 g_ptr = &floor_ptr->grid_array[y - d][x];
179 g_ptr->info |= CAVE_XTRA;
180 cave_view_hack(floor_ptr, g_ptr, y - d, x);
181 if (!cave_los_grid(g_ptr))
186 for (d = 1; d <= full; d++) {
187 g_ptr = &floor_ptr->grid_array[y][x + d];
188 g_ptr->info |= CAVE_XTRA;
189 cave_view_hack(floor_ptr, g_ptr, y, x + d);
190 if (!cave_los_grid(g_ptr))
195 for (d = 1; d <= full; d++) {
196 g_ptr = &floor_ptr->grid_array[y][x - d];
197 g_ptr->info |= CAVE_XTRA;
198 cave_view_hack(floor_ptr, g_ptr, y, x - d);
199 if (!cave_los_grid(g_ptr))
204 for (n = 1; n <= over / 2; n++) {
205 POSITION ypn, ymn, xpn, xmn;
210 while ((z + n + (n >> 1)) > full)
218 m = MIN(z, y_max - ypn);
219 if ((xpn <= x_max) && (n < se)) {
220 for (k = n, d = 1; d <= m; d++) {
221 if (update_view_aux(subject_ptr, ypn + d, xpn, ypn + d - 1, xpn - 1, ypn + d - 1, xpn)) {
231 if ((xmn >= 0) && (n < sw)) {
232 for (k = n, d = 1; d <= m; d++) {
233 if (update_view_aux(subject_ptr, ypn + d, xmn, ypn + d - 1, xmn + 1, ypn + d - 1, xmn)) {
246 if ((xpn <= x_max) && (n < ne)) {
247 for (k = n, d = 1; d <= m; d++) {
248 if (update_view_aux(subject_ptr, ymn - d, xpn, ymn - d + 1, xpn - 1, ymn - d + 1, xpn)) {
258 if ((xmn >= 0) && (n < nw)) {
259 for (k = n, d = 1; d <= m; d++) {
260 if (update_view_aux(subject_ptr, ymn - d, xmn, ymn - d + 1, xmn + 1, ymn - d + 1, xmn)) {
272 m = MIN(z, x_max - xpn);
273 if ((ypn <= x_max) && (n < es)) {
274 for (k = n, d = 1; d <= m; d++) {
275 if (update_view_aux(subject_ptr, ypn, xpn + d, ypn - 1, xpn + d - 1, ypn, xpn + d - 1)) {
285 if ((ymn >= 0) && (n < en)) {
286 for (k = n, d = 1; d <= m; d++) {
287 if (update_view_aux(subject_ptr, ymn, xpn + d, ymn + 1, xpn + d - 1, ymn, xpn + d - 1)) {
300 if ((ypn <= y_max) && (n < ws)) {
301 for (k = n, d = 1; d <= m; d++) {
302 if (update_view_aux(subject_ptr, ypn, xmn - d, ypn - 1, xmn - d + 1, ypn, xmn - d + 1)) {
312 if ((ymn >= 0) && (n < wn)) {
313 for (k = n, d = 1; d <= m; d++) {
314 if (update_view_aux(subject_ptr, ymn, xmn - d, ymn + 1, xmn - d + 1, ymn, xmn - d + 1)) {
326 for (n = 0; n < floor_ptr->view_n; n++) {
327 y = floor_ptr->view_y[n];
328 x = floor_ptr->view_x[n];
329 g_ptr = &floor_ptr->grid_array[y][x];
330 g_ptr->info &= ~(CAVE_XTRA);
331 if (g_ptr->info & CAVE_TEMP)
334 cave_note_and_redraw_later(floor_ptr, g_ptr, y, x);
337 for (n = 0; n < tmp_pos.n; n++) {
340 g_ptr = &floor_ptr->grid_array[y][x];
341 g_ptr->info &= ~(CAVE_TEMP);
342 if (g_ptr->info & CAVE_VIEW)
345 cave_redraw_later(floor_ptr, g_ptr, y, x);
349 subject_ptr->update |= PU_DELAY_VIS;