6 #include "floor-events.h"
9 #include "monster-status.h"
11 #include "object-hook.h"
12 #include "player-move.h"
14 #include "player-effects.h"
15 #include "objectkind.h"
16 #include "object-ego.h"
18 #include "view-mainwindow.h"
20 static bool mon_invis;
21 static POSITION mon_fy, mon_fx;
23 void day_break(player_type *subject_ptr)
26 msg_print(_("夜が明けた。", "The sun has risen."));
28 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
29 if (!subject_ptr->wild_mode)
31 /* Hack -- Scan the town */
32 for (y = 0; y < floor_ptr->height; y++)
34 for (x = 0; x < floor_ptr->width; x++)
36 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
39 g_ptr->info |= (CAVE_GLOW);
41 /* Hack -- Memorize lit grids if allowed */
42 if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
49 subject_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
50 subject_ptr->redraw |= (PR_MAP);
51 subject_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
53 if (subject_ptr->special_defense & NINJA_S_STEALTH)
55 if (floor_ptr->grid_array[subject_ptr->y][subject_ptr->x].info & CAVE_GLOW) set_superstealth(subject_ptr, FALSE);
60 void night_falls(player_type *subject_ptr)
63 msg_print(_("日が沈んだ。", "The sun has fallen."));
65 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
66 if (!subject_ptr->wild_mode)
68 /* Hack -- Scan the town */
69 for (y = 0; y < floor_ptr->height; y++)
71 for (x = 0; x < floor_ptr->width; x++)
73 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
75 /* Feature code (applying "mimic" field) */
76 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
78 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
79 !have_flag(f_ptr->flags, FF_ENTRANCE))
82 g_ptr->info &= ~(CAVE_GLOW);
84 if (!have_flag(f_ptr->flags, FF_REMEMBER))
86 /* Forget the normal floor grid */
87 g_ptr->info &= ~(CAVE_MARK);
94 glow_deep_lava_and_bldg(subject_ptr);
98 subject_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
99 subject_ptr->redraw |= (PR_MAP);
100 subject_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
102 if (subject_ptr->special_defense & NINJA_S_STEALTH)
104 if (floor_ptr->grid_array[subject_ptr->y][subject_ptr->x].info & CAVE_GLOW) set_superstealth(subject_ptr, FALSE);
110 * @brief 現在フロアに残っている敵モンスターの数を返す /
111 * @return 現在の敵モンスターの数
113 MONSTER_NUMBER count_all_hostile_monsters(floor_type *floor_ptr)
115 MONSTER_NUMBER number_mon = 0;
117 for (POSITION x = 0; x < floor_ptr->width; ++x)
119 for (POSITION y = 0; y < floor_ptr->height; ++y)
121 MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
123 if (m_idx > 0 && is_hostile(&floor_ptr->m_list[m_idx]))
134 * ダンジョンの雰囲気を計算するための非線形基準値 / Dungeon rating is no longer linear
136 #define RATING_BOOST(delta) (delta * delta + 50 * delta)
139 * @brief ダンジョンの雰囲気を算出する。
140 * / Examine all monsters and unidentified objects, and get the feeling of current dungeon floor
141 * @return 算出されたダンジョンの雰囲気ランク
143 byte get_dungeon_feeling(floor_type *floor_ptr)
145 /* Hack -- no feeling in the town */
146 if (!floor_ptr->dun_level) return 0;
148 /* Examine each monster */
151 for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++)
153 monster_type *m_ptr = &floor_ptr->m_list[i];
156 if (!monster_is_valid(m_ptr)) continue;
158 if (is_pet(m_ptr)) continue;
160 r_ptr = &r_info[m_ptr->r_idx];
162 if (r_ptr->flags1 & (RF1_UNIQUE))
164 /* Nearly out-of-depth unique monsters */
165 if (r_ptr->level + 10 > floor_ptr->dun_level)
167 /* Boost rating by twice delta-depth */
168 delta += (r_ptr->level + 10 - floor_ptr->dun_level) * 2 * base;
173 /* Out-of-depth monsters */
174 if (r_ptr->level > floor_ptr->dun_level)
176 /* Boost rating by delta-depth */
177 delta += (r_ptr->level - floor_ptr->dun_level) * base;
181 /* Unusually crowded monsters get a little bit of rating boost */
182 if (r_ptr->flags1 & RF1_FRIENDS)
184 if (5 <= get_monster_crowd_number(i)) delta += 1;
188 if (2 <= get_monster_crowd_number(i)) delta += 1;
192 rating += RATING_BOOST(delta);
195 /* Examine each unidentified object */
196 for (MONSTER_IDX i = 1; i < floor_ptr->o_max; i++)
198 object_type *o_ptr = &floor_ptr->o_list[i];
199 object_kind *k_ptr = &k_info[o_ptr->k_idx];
202 if (!OBJECT_IS_VALID(o_ptr)) continue;
204 /* Skip known objects */
205 if (object_is_known(o_ptr))
208 if (o_ptr->marked & OM_TOUCHED) continue;
211 /* Skip pseudo-known objects */
212 if (o_ptr->ident & IDENT_SENSE) continue;
215 if (object_is_ego(o_ptr))
217 ego_item_type *e_ptr = &e_info[o_ptr->name2];
219 delta += e_ptr->rating * base;
223 if (object_is_artifact(o_ptr))
225 PRICE cost = object_value_real(o_ptr);
228 if (cost > 10000L) delta += 10 * base;
229 if (cost > 50000L) delta += 10 * base;
230 if (cost > 100000L) delta += 10 * base;
232 /* Special feeling */
233 if (!preserve_mode) return 1;
236 if (o_ptr->tval == TV_DRAG_ARMOR) delta += 30 * base;
237 if (o_ptr->tval == TV_SHIELD && o_ptr->sval == SV_DRAGON_SHIELD) delta += 5 * base;
238 if (o_ptr->tval == TV_GLOVES && o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) delta += 5 * base;
239 if (o_ptr->tval == TV_BOOTS && o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) delta += 5 * base;
240 if (o_ptr->tval == TV_HELM && o_ptr->sval == SV_DRAGON_HELM) delta += 5 * base;
241 if (o_ptr->tval == TV_RING && o_ptr->sval == SV_RING_SPEED && !object_is_cursed(o_ptr)) delta += 25 * base;
242 if (o_ptr->tval == TV_RING && o_ptr->sval == SV_RING_LORDLY && !object_is_cursed(o_ptr)) delta += 15 * base;
243 if (o_ptr->tval == TV_AMULET && o_ptr->sval == SV_AMULET_THE_MAGI && !object_is_cursed(o_ptr)) delta += 15 * base;
245 /* Out-of-depth objects */
246 if (!object_is_cursed(o_ptr) && !object_is_broken(o_ptr) && k_ptr->level > floor_ptr->dun_level)
248 /* Rating increase */
249 delta += (k_ptr->level - floor_ptr->dun_level) * base;
252 rating += RATING_BOOST(delta);
256 if (rating > RATING_BOOST(1000)) return 2;
257 if (rating > RATING_BOOST(800)) return 3;
258 if (rating > RATING_BOOST(600)) return 4;
259 if (rating > RATING_BOOST(400)) return 5;
260 if (rating > RATING_BOOST(300)) return 6;
261 if (rating > RATING_BOOST(200)) return 7;
262 if (rating > RATING_BOOST(100)) return 8;
263 if (rating > RATING_BOOST(0)) return 9;
268 * @brief ダンジョンの雰囲気を更新し、変化があった場合メッセージを表示する
269 * / Update dungeon feeling, and announce it if changed
272 void update_dungeon_feeling(player_type *subject_ptr)
274 /* No feeling on the surface */
275 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
276 if (!floor_ptr->dun_level) return;
278 /* No feeling in the arena */
279 if (subject_ptr->phase_out) return;
281 /* Extract delay time */
282 int delay = MAX(10, 150 - subject_ptr->skill_fos) * (150 - floor_ptr->dun_level) * TURNS_PER_TICK / 100;
284 /* Not yet felt anything */
285 if (current_world_ptr->game_turn < subject_ptr->feeling_turn + delay && !cheat_xtra) return;
287 /* Extract quest number (if any) */
288 int quest_num = quest_number(subject_ptr, floor_ptr->dun_level);
290 /* No feeling in a quest */
292 (is_fixed_quest_idx(quest_num) &&
293 !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
294 !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) return;
297 /* Get new dungeon feeling */
298 byte new_feeling = get_dungeon_feeling(floor_ptr);
300 /* Remember last time updated */
301 subject_ptr->feeling_turn = current_world_ptr->game_turn;
304 if (subject_ptr->feeling == new_feeling) return;
306 /* Dungeon feeling is changed */
307 subject_ptr->feeling = new_feeling;
309 /* Announce feeling */
310 do_cmd_feeling(subject_ptr);
312 select_floor_music(subject_ptr);
314 /* Update the level indicator */
315 subject_ptr->redraw |= (PR_DEPTH);
317 if (disturb_minor) disturb(subject_ptr, FALSE, FALSE);
322 * Glow deep lava and building entrances in the floor
324 void glow_deep_lava_and_bldg(player_type *subject_ptr)
326 /* Not in the darkness dungeon */
327 if (d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) return;
329 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
330 for (POSITION y = 0; y < floor_ptr->height; y++)
332 for (POSITION x = 0; x < floor_ptr->width; x++)
335 g_ptr = &floor_ptr->grid_array[y][x];
337 if (!have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_GLOW))
340 for (DIRECTION i = 0; i < 9; i++)
342 POSITION yy = y + ddy_ddd[i];
343 POSITION xx = x + ddx_ddd[i];
344 if (!in_bounds2(floor_ptr, yy, xx)) continue;
345 floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
350 subject_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
351 subject_ptr->redraw |= (PR_MAP);
356 * Actually erase the entire "lite" array, redrawing every grid
358 void forget_lite(floor_type *floor_ptr)
361 if (!floor_ptr->lite_n) return;
364 for (int i = 0; i < floor_ptr->lite_n; i++)
366 POSITION y = floor_ptr->lite_y[i];
367 POSITION x = floor_ptr->lite_x[i];
369 /* Forget "LITE" flag */
370 floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
373 floor_ptr->lite_n = 0;
378 * Update the set of grids "illuminated" by the player's lite.
380 * This routine needs to use the results of "update_view()"
382 * Note that "blindness" does NOT affect "torch lite". Be careful!
384 * We optimize most lites (all non-artifact lites) by using "obvious"
385 * facts about the results of "small" lite radius, and we attempt to
386 * list the "nearby" grids before the more "distant" ones in the
387 * array of torch-lit grids.
389 * We assume that "radius zero" lite is in fact no lite at all.
391 * Torch Lantern Artifacts
401 void update_lite(player_type *subject_ptr)
403 POSITION p = subject_ptr->cur_lite;
406 /*** Special case ***/
409 /* Hack -- Player has no lite */
412 /* Forget the old lite */
413 /* forget_lite(); Perhaps don't need? */
415 /* Add it to later visual update */
416 cave_redraw_later(floor_ptr, &floor_ptr->grid_array[subject_ptr->y][subject_ptr->x], subject_ptr->y, subject_ptr->x);
420 /*** Save the old "lite" grids for later ***/
423 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
424 for (int i = 0; i < floor_ptr->lite_n; i++)
426 POSITION y = floor_ptr->lite_y[i];
427 POSITION x = floor_ptr->lite_x[i];
429 /* Mark the grid as not "lite" */
430 floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
432 /* Mark the grid as "seen" */
433 floor_ptr->grid_array[y][x].info |= (CAVE_TEMP);
435 /* Add it to the "seen" set */
436 tmp_pos.y[tmp_pos.n] = y;
437 tmp_pos.x[tmp_pos.n] = x;
442 floor_ptr->lite_n = 0;
445 /*** Collect the new "lite" grids ***/
447 /* Radius 1 -- torch radius */
451 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x);
454 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x);
455 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x);
456 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x + 1);
457 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x - 1);
460 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x + 1);
461 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x - 1);
462 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x + 1);
463 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x - 1);
466 /* Radius 2 -- lantern radius */
469 /* South of the player */
470 if (cave_los_bold(floor_ptr, subject_ptr->y + 1, subject_ptr->x))
472 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x);
473 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x + 1);
474 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x - 1);
477 /* North of the player */
478 if (cave_los_bold(floor_ptr, subject_ptr->y - 1, subject_ptr->x))
480 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x);
481 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x + 1);
482 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x - 1);
485 /* East of the player */
486 if (cave_los_bold(floor_ptr, subject_ptr->y, subject_ptr->x + 1))
488 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x + 2);
489 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x + 2);
490 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x + 2);
493 /* West of the player */
494 if (cave_los_bold(floor_ptr, subject_ptr->y, subject_ptr->x - 1))
496 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x - 2);
497 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x - 2);
498 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x - 2);
502 /* Radius 3+ -- artifact radius */
507 /* Paranoia -- see "LITE_MAX" */
510 /* South-East of the player */
511 if (cave_los_bold(floor_ptr, subject_ptr->y + 1, subject_ptr->x + 1))
513 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x + 2);
516 /* South-West of the player */
517 if (cave_los_bold(floor_ptr, subject_ptr->y + 1, subject_ptr->x - 1))
519 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x - 2);
522 /* North-East of the player */
523 if (cave_los_bold(floor_ptr, subject_ptr->y - 1, subject_ptr->x + 1))
525 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x + 2);
528 /* North-West of the player */
529 if (cave_los_bold(floor_ptr, subject_ptr->y - 1, subject_ptr->x - 1))
531 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x - 2);
535 POSITION min_y = subject_ptr->y - p;
536 if (min_y < 0) min_y = 0;
539 POSITION max_y = subject_ptr->y + p;
540 if (max_y > floor_ptr->height - 1) max_y = floor_ptr->height - 1;
543 POSITION min_x = subject_ptr->x - p;
544 if (min_x < 0) min_x = 0;
547 POSITION max_x = subject_ptr->x + p;
548 if (max_x > floor_ptr->width - 1) max_x = floor_ptr->width - 1;
550 /* Scan the maximal box */
551 for (POSITION y = min_y; y <= max_y; y++)
553 for (POSITION x = min_x; x <= max_x; x++)
555 int dy = (subject_ptr->y > y) ? (subject_ptr->y - y) : (y - subject_ptr->y);
556 int dx = (subject_ptr->x > x) ? (subject_ptr->x - x) : (x - subject_ptr->x);
558 /* Skip the "central" grids (above) */
559 if ((dy <= 2) && (dx <= 2)) continue;
561 /* Hack -- approximate the distance */
562 d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
564 /* Skip distant grids */
567 /* Viewable, nearby, grids get "torch lit" */
568 if (floor_ptr->grid_array[y][x].info & CAVE_VIEW)
570 /* This grid is "torch lit" */
571 cave_lite_hack(floor_ptr, y, x);
578 /*** Complete the algorithm ***/
580 /* Draw the new grids */
581 for (int i = 0; i < floor_ptr->lite_n; i++)
583 POSITION y = floor_ptr->lite_y[i];
584 POSITION x = floor_ptr->lite_x[i];
586 g_ptr = &floor_ptr->grid_array[y][x];
588 /* Update fresh grids */
589 if (g_ptr->info & (CAVE_TEMP)) continue;
591 /* Add it to later visual update */
592 cave_note_and_redraw_later(floor_ptr, g_ptr, y, x);
596 for (int i = 0; i < tmp_pos.n; i++)
598 POSITION y = tmp_pos.y[i];
599 POSITION x = tmp_pos.x[i];
601 g_ptr = &floor_ptr->grid_array[y][x];
603 /* No longer in the array */
604 g_ptr->info &= ~(CAVE_TEMP);
606 /* Update stale grids */
607 if (g_ptr->info & (CAVE_LITE)) continue;
609 /* Add it to later visual update */
610 cave_redraw_later(floor_ptr, g_ptr, y, x);
614 subject_ptr->update |= (PU_DELAY_VIS);
619 * Clear the viewable space
621 void forget_view(floor_type *floor_ptr)
624 if (!floor_ptr->view_n) return;
627 for (int i = 0; i < floor_ptr->view_n; i++)
629 POSITION y = floor_ptr->view_y[i];
630 POSITION x = floor_ptr->view_x[i];
632 g_ptr = &floor_ptr->grid_array[y][x];
634 /* Forget that the grid is viewable */
635 g_ptr->info &= ~(CAVE_VIEW);
638 floor_ptr->view_n = 0;
643 * Helper function for "update_view()" below
645 * We are checking the "viewability" of grid (y,x) by the player.
647 * This function assumes that (y,x) is legal (i.e. on the map).
649 * Grid (y1,x1) is on the "diagonal" between (subject_ptr->y,subject_ptr->x) and (y,x)
650 * Grid (y2,x2) is "adjacent", also between (subject_ptr->y,subject_ptr->x) and (y,x).
652 * Note that we are using the "CAVE_XTRA" field for marking grids as
653 * "easily viewable". This bit is cleared at the end of "update_view()".
655 * This function adds (y,x) to the "viewable set" if necessary.
657 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
659 static bool update_view_aux(player_type *subject_ptr, POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
661 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
664 g1_c_ptr = &floor_ptr->grid_array[y1][x1];
665 g2_c_ptr = &floor_ptr->grid_array[y2][x2];
667 /* Check for walls */
668 bool f1 = (cave_los_grid(g1_c_ptr));
669 bool f2 = (cave_los_grid(g2_c_ptr));
671 /* Totally blocked by physical walls */
672 if (!f1 && !f2) return TRUE;
674 /* Check for visibility */
675 bool v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
676 bool v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
678 /* Totally blocked by "unviewable neighbors" */
679 if (!v1 && !v2) return TRUE;
682 g_ptr = &floor_ptr->grid_array[y][x];
684 /* Check for walls */
685 bool wall = (!cave_los_grid(g_ptr));
687 /* Check the "ease" of visibility */
688 bool z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
689 bool z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
691 /* Hack -- "easy" plus "easy" yields "easy" */
694 g_ptr->info |= (CAVE_XTRA);
695 cave_view_hack(floor_ptr, g_ptr, y, x);
699 /* Hack -- primary "easy" yields "viewed" */
702 cave_view_hack(floor_ptr, g_ptr, y, x);
706 /* Hack -- "view" plus "view" yields "view" */
709 cave_view_hack(floor_ptr, g_ptr, y, x);
713 /* Mega-Hack -- the "los()" function works poorly on walls */
716 cave_view_hack(floor_ptr, g_ptr, y, x);
720 /* Hack -- check line of sight */
721 if (los(floor_ptr, subject_ptr->y, subject_ptr->x, y, x))
723 cave_view_hack(floor_ptr, g_ptr, y, x);
732 * Calculate the viewable space
734 * 1: Process the player
735 * 1a: The player is always (easily) viewable
736 * 2: Process the diagonals
737 * 2a: The diagonals are (easily) viewable up to the first wall
738 * 2b: But never go more than 2/3 of the "full" distance
739 * 3: Process the main axes
740 * 3a: The main axes are (easily) viewable up to the first wall
741 * 3b: But never go more than the "full" distance
742 * 4: Process sequential "strips" in each of the eight octants
743 * 4a: Each strip runs along the previous strip
744 * 4b: The main axes are "previous" to the first strip
745 * 4c: Process both "sides" of each "direction" of each strip
746 * 4c1: Each side aborts as soon as possible
747 * 4c2: Each side tells the next strip how far it has to check
749 * Note that the octant processing involves some pretty interesting
750 * observations involving when a grid might possibly be viewable from
751 * a given grid, and on the order in which the strips are processed.
753 * Note the use of the mathematical facts shown below, which derive
754 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
755 * hypotenuse of a right triangle is primarily determined by the length
756 * of the longest side, when one side is small, and is strictly less
757 * than one-and-a-half times as long as the longest side when both of
758 * the sides are large.
760 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
761 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
763 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
765 * These observations are important because the calculation of the actual
766 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
767 * while for small values (up to about 20 or so), the approximations above
768 * are correct to within an error of at most one grid or so.
770 * Observe the use of "full" and "over" in the code below, and the use of
771 * the specialized calculation involving "limit", all of which derive from
772 * the observations given above. Basically, we note that the "circle" of
773 * view is completely contained in an "octagon" whose bounds are easy to
774 * determine, and that only a few steps are needed to derive the actual
775 * bounds of the circle given the bounds of the octagon.
777 * Note that by skipping all the grids in the corners of the octagon, we
778 * place an upper limit on the number of grids in the field of view, given
779 * that "full" is never more than 20. Of the 1681 grids in the "square" of
780 * view, only about 1475 of these are in the "octagon" of view, and even
781 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
782 * entries to completely contain the actual field of view.
784 * Note also the care taken to prevent "running off the map". The use of
785 * explicit checks on the "validity" of the "diagonal", and the fact that
786 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
787 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
788 * of multiple checks on the validity of grids.
790 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
791 * "ws","wn" variables. They work like this: While travelling down the
792 * south-bound strip just to the east of the main south axis, as soon as
793 * we get to a grid which does not "transmit" viewing, if all of the strips
794 * preceding us (in this case, just the main axis) had terminated at or before
795 * the same point, then we can stop, and reset the "max distance" to ourself.
796 * So, each strip (named by major axis plus offset, thus "se" in this case)
797 * maintains a "blockage" variable, initialized during the main axis step,
798 * and checks it whenever a blockage is observed. After processing each
799 * strip as far as the previous strip told us to process, the next strip is
800 * told not to go farther than the current strip's farthest viewable grid,
801 * unless open space is still available. This uses the "k" variable.
803 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
804 * macro is a replacement for "cave_los_bold()" which takes a pointer to
805 * a grid instead of its location. The "cave_view_hack()" macro is a
806 * chunk of code which adds the given location to the "view" array if it
807 * is not already there, using both the actual location and a pointer to
808 * the grid. See above.
810 * By the way, the purpose of this code is to reduce the dependancy on the
811 * "los()" function which is slow, and, in some cases, not very accurate.
813 * It is very possible that I am the only person who fully understands this
814 * function, and for that I am truly sorry, but efficiency was very important
815 * and the "simple" version of this function was just not fast enough. I am
816 * more than willing to replace this function with a simpler one, if it is
817 * equally efficient, and especially willing if the new function happens to
818 * derive "reverse-line-of-sight" at the same time, since currently monsters
819 * just use an optimized hack of "you see me, so I see you", and then use the
820 * actual "projectable()" function to check spell attacks.
822 void update_view(player_type *subject_ptr, floor_type *floor_ptr)
827 int se, sw, ne, nw, es, en, ws, wn;
831 POSITION y_max = floor_ptr->height - 1;
832 POSITION x_max = floor_ptr->width - 1;
839 if (view_reduce_view && !floor_ptr->dun_level)
841 /* Full radius (10) */
842 full = MAX_SIGHT / 2;
844 /* Octagon factor (15) */
845 over = MAX_SIGHT * 3 / 4;
851 /* Full radius (20) */
854 /* Octagon factor (30) */
855 over = MAX_SIGHT * 3 / 2;
859 /*** Step 0 -- Begin ***/
861 /* Save the old "view" grids for later */
862 for (n = 0; n < floor_ptr->view_n; n++)
864 y = floor_ptr->view_y[n];
865 x = floor_ptr->view_x[n];
866 g_ptr = &floor_ptr->grid_array[y][x];
868 /* Mark the grid as not in "view" */
869 g_ptr->info &= ~(CAVE_VIEW);
871 /* Mark the grid as "seen" */
872 g_ptr->info |= (CAVE_TEMP);
874 /* Add it to the "seen" set */
875 tmp_pos.y[tmp_pos.n] = y;
876 tmp_pos.x[tmp_pos.n] = x;
880 /* Start over with the "view" array */
881 floor_ptr->view_n = 0;
883 /*** Step 1 -- adjacent grids ***/
885 /* Now start on the player */
888 g_ptr = &floor_ptr->grid_array[y][x];
890 /* Assume the player grid is easily viewable */
891 g_ptr->info |= (CAVE_XTRA);
893 /* Assume the player grid is viewable */
894 cave_view_hack(floor_ptr, g_ptr, y, x);
897 /*** Step 2 -- Major Diagonals ***/
902 /* Scan south-east */
903 for (d = 1; d <= z; d++)
905 g_ptr = &floor_ptr->grid_array[y + d][x + d];
906 g_ptr->info |= (CAVE_XTRA);
907 cave_view_hack(floor_ptr, g_ptr, y + d, x + d);
908 if (!cave_los_grid(g_ptr)) break;
911 /* Scan south-west */
912 for (d = 1; d <= z; d++)
914 g_ptr = &floor_ptr->grid_array[y + d][x - d];
915 g_ptr->info |= (CAVE_XTRA);
916 cave_view_hack(floor_ptr, g_ptr, y + d, x - d);
917 if (!cave_los_grid(g_ptr)) break;
920 /* Scan north-east */
921 for (d = 1; d <= z; d++)
923 g_ptr = &floor_ptr->grid_array[y - d][x + d];
924 g_ptr->info |= (CAVE_XTRA);
925 cave_view_hack(floor_ptr, g_ptr, y - d, x + d);
926 if (!cave_los_grid(g_ptr)) break;
929 /* Scan north-west */
930 for (d = 1; d <= z; d++)
932 g_ptr = &floor_ptr->grid_array[y - d][x - d];
933 g_ptr->info |= (CAVE_XTRA);
934 cave_view_hack(floor_ptr, g_ptr, y - d, x - d);
935 if (!cave_los_grid(g_ptr)) break;
938 /*** Step 3 -- major axes ***/
941 for (d = 1; d <= full; d++)
943 g_ptr = &floor_ptr->grid_array[y + d][x];
944 g_ptr->info |= (CAVE_XTRA);
945 cave_view_hack(floor_ptr, g_ptr, y + d, x);
946 if (!cave_los_grid(g_ptr)) break;
949 /* Initialize the "south strips" */
953 for (d = 1; d <= full; d++)
955 g_ptr = &floor_ptr->grid_array[y - d][x];
956 g_ptr->info |= (CAVE_XTRA);
957 cave_view_hack(floor_ptr, g_ptr, y - d, x);
958 if (!cave_los_grid(g_ptr)) break;
961 /* Initialize the "north strips" */
965 for (d = 1; d <= full; d++)
967 g_ptr = &floor_ptr->grid_array[y][x + d];
968 g_ptr->info |= (CAVE_XTRA);
969 cave_view_hack(floor_ptr, g_ptr, y, x + d);
970 if (!cave_los_grid(g_ptr)) break;
973 /* Initialize the "east strips" */
977 for (d = 1; d <= full; d++)
979 g_ptr = &floor_ptr->grid_array[y][x - d];
980 g_ptr->info |= (CAVE_XTRA);
981 cave_view_hack(floor_ptr, g_ptr, y, x - d);
982 if (!cave_los_grid(g_ptr)) break;
985 /* Initialize the "west strips" */
989 /*** Step 4 -- Divide each "octant" into "strips" ***/
991 /* Now check each "diagonal" (in parallel) */
992 for (n = 1; n <= over / 2; n++)
994 POSITION ypn, ymn, xpn, xmn;
996 /* Acquire the "bounds" of the maximal circle */
998 if (z > full - n) z = full - n;
999 while ((z + n + (n >> 1)) > full) z--;
1001 /* Access the four diagonal grids */
1010 /* Maximum distance */
1011 m = MIN(z, y_max - ypn);
1014 if ((xpn <= x_max) && (n < se))
1017 for (k = n, d = 1; d <= m; d++)
1019 /* Check grid "d" in strip "n", notice "blockage" */
1020 if (update_view_aux(subject_ptr, ypn + d, xpn, ypn + d - 1, xpn - 1, ypn + d - 1, xpn))
1022 if (n + d >= se) break;
1025 /* Track most distant "non-blockage" */
1032 /* Limit the next strip */
1037 if ((xmn >= 0) && (n < sw))
1040 for (k = n, d = 1; d <= m; d++)
1042 /* Check grid "d" in strip "n", notice "blockage" */
1043 if (update_view_aux(subject_ptr, ypn + d, xmn, ypn + d - 1, xmn + 1, ypn + d - 1, xmn))
1045 if (n + d >= sw) break;
1048 /* Track most distant "non-blockage" */
1055 /* Limit the next strip */
1063 /* Maximum distance */
1067 if ((xpn <= x_max) && (n < ne))
1070 for (k = n, d = 1; d <= m; d++)
1072 /* Check grid "d" in strip "n", notice "blockage" */
1073 if (update_view_aux(subject_ptr, ymn - d, xpn, ymn - d + 1, xpn - 1, ymn - d + 1, xpn))
1075 if (n + d >= ne) break;
1078 /* Track most distant "non-blockage" */
1085 /* Limit the next strip */
1090 if ((xmn >= 0) && (n < nw))
1093 for (k = n, d = 1; d <= m; d++)
1095 /* Check grid "d" in strip "n", notice "blockage" */
1096 if (update_view_aux(subject_ptr, ymn - d, xmn, ymn - d + 1, xmn + 1, ymn - d + 1, xmn))
1098 if (n + d >= nw) break;
1101 /* Track most distant "non-blockage" */
1108 /* Limit the next strip */
1116 /* Maximum distance */
1117 m = MIN(z, x_max - xpn);
1120 if ((ypn <= x_max) && (n < es))
1123 for (k = n, d = 1; d <= m; d++)
1125 /* Check grid "d" in strip "n", notice "blockage" */
1126 if (update_view_aux(subject_ptr, ypn, xpn + d, ypn - 1, xpn + d - 1, ypn, xpn + d - 1))
1128 if (n + d >= es) break;
1131 /* Track most distant "non-blockage" */
1138 /* Limit the next strip */
1143 if ((ymn >= 0) && (n < en))
1146 for (k = n, d = 1; d <= m; d++)
1148 /* Check grid "d" in strip "n", notice "blockage" */
1149 if (update_view_aux(subject_ptr, ymn, xpn + d, ymn + 1, xpn + d - 1, ymn, xpn + d - 1))
1151 if (n + d >= en) break;
1154 /* Track most distant "non-blockage" */
1161 /* Limit the next strip */
1169 /* Maximum distance */
1173 if ((ypn <= y_max) && (n < ws))
1176 for (k = n, d = 1; d <= m; d++)
1178 /* Check grid "d" in strip "n", notice "blockage" */
1179 if (update_view_aux(subject_ptr, ypn, xmn - d, ypn - 1, xmn - d + 1, ypn, xmn - d + 1))
1181 if (n + d >= ws) break;
1184 /* Track most distant "non-blockage" */
1191 /* Limit the next strip */
1196 if ((ymn >= 0) && (n < wn))
1199 for (k = n, d = 1; d <= m; d++)
1201 /* Check grid "d" in strip "n", notice "blockage" */
1202 if (update_view_aux(subject_ptr, ymn, xmn - d, ymn + 1, xmn - d + 1, ymn, xmn - d + 1))
1204 if (n + d >= wn) break;
1207 /* Track most distant "non-blockage" */
1214 /* Limit the next strip */
1220 /*** Step 5 -- Complete the algorithm ***/
1222 /* Update all the new grids */
1223 for (n = 0; n < floor_ptr->view_n; n++)
1225 y = floor_ptr->view_y[n];
1226 x = floor_ptr->view_x[n];
1227 g_ptr = &floor_ptr->grid_array[y][x];
1229 /* Clear the "CAVE_XTRA" flag */
1230 g_ptr->info &= ~(CAVE_XTRA);
1232 /* Update only newly viewed grids */
1233 if (g_ptr->info & (CAVE_TEMP)) continue;
1235 /* Add it to later visual update */
1236 cave_note_and_redraw_later(floor_ptr, g_ptr, y, x);
1239 /* Wipe the old grids, update as needed */
1240 for (n = 0; n < tmp_pos.n; n++)
1244 g_ptr = &floor_ptr->grid_array[y][x];
1246 /* No longer in the array */
1247 g_ptr->info &= ~(CAVE_TEMP);
1249 /* Update only non-viewable grids */
1250 if (g_ptr->info & (CAVE_VIEW)) continue;
1252 /* Add it to later visual update */
1253 cave_redraw_later(floor_ptr, g_ptr, y, x);
1257 subject_ptr->update |= (PU_DELAY_VIS);
1262 * @brief モンスターによる光量状態更新 / Add a square to the changes array
1263 * @param subject_ptr 主観となるクリーチャーの参照ポインタ
1267 static void mon_lite_hack(player_type *subject_ptr, POSITION y, POSITION x)
1273 /* We trust this grid is in bounds */
1274 /* if (!in_bounds2(y, x)) return; */
1276 g_ptr = &subject_ptr->current_floor_ptr->grid_array[y][x];
1278 /* Want a unlit square in view of the player */
1279 if ((g_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
1281 if (!cave_los_grid(g_ptr))
1283 /* Hack -- Prevent monster lite leakage in walls */
1285 /* Horizontal walls between player and a monster */
1286 if (((y < subject_ptr->y) && (y > mon_fy)) || ((y > subject_ptr->y) && (y < mon_fy)))
1288 dpf = subject_ptr->y - mon_fy;
1290 midpoint = mon_fx + ((subject_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
1292 /* Only first wall viewed from mid-x is lit */
1295 if (!cave_los_bold(subject_ptr->current_floor_ptr, y, x + 1)) return;
1297 else if (x > midpoint)
1299 if (!cave_los_bold(subject_ptr->current_floor_ptr, y, x - 1)) return;
1302 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1303 else if (mon_invis) return;
1306 /* Vertical walls between player and a monster */
1307 if (((x < subject_ptr->x) && (x > mon_fx)) || ((x > subject_ptr->x) && (x < mon_fx)))
1309 dpf = subject_ptr->x - mon_fx;
1311 midpoint = mon_fy + ((subject_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
1313 /* Only first wall viewed from mid-y is lit */
1316 if (!cave_los_bold(subject_ptr->current_floor_ptr, y + 1, x)) return;
1318 else if (y > midpoint)
1320 if (!cave_los_bold(subject_ptr->current_floor_ptr, y - 1, x)) return;
1323 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1324 else if (mon_invis) return;
1328 /* We trust tmp_pos.n does not exceed TEMP_MAX */
1331 if (!(g_ptr->info & CAVE_MNDK))
1333 /* Save this square */
1334 tmp_pos.x[tmp_pos.n] = x;
1335 tmp_pos.y[tmp_pos.n] = y;
1342 /* No longer dark */
1343 g_ptr->info &= ~(CAVE_MNDK);
1347 g_ptr->info |= CAVE_MNLT;
1352 * Add a square to the changes array
1354 static void mon_dark_hack(player_type *subject_ptr, POSITION y, POSITION x)
1357 int midpoint, dpf, d;
1359 /* We trust this grid is in bounds */
1360 /* if (!in_bounds2(y, x)) return; */
1362 g_ptr = &subject_ptr->current_floor_ptr->grid_array[y][x];
1364 /* Want a unlit and undarkened square in view of the player */
1365 if ((g_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
1367 if (!cave_los_grid(g_ptr) && !cave_have_flag_grid(g_ptr, FF_PROJECT))
1369 /* Hack -- Prevent monster dark lite leakage in walls */
1371 /* Horizontal walls between player and a monster */
1372 if (((y < subject_ptr->y) && (y > mon_fy)) || ((y > subject_ptr->y) && (y < mon_fy)))
1374 dpf = subject_ptr->y - mon_fy;
1376 midpoint = mon_fx + ((subject_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
1378 /* Only first wall viewed from mid-x is lit */
1381 if (!cave_los_bold(subject_ptr->current_floor_ptr, y, x + 1) && !cave_have_flag_bold(subject_ptr->current_floor_ptr, y, x + 1, FF_PROJECT)) return;
1383 else if (x > midpoint)
1385 if (!cave_los_bold(subject_ptr->current_floor_ptr, y, x - 1) && !cave_have_flag_bold(subject_ptr->current_floor_ptr, y, x - 1, FF_PROJECT)) return;
1388 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1389 else if (mon_invis) return;
1392 /* Vertical walls between player and a monster */
1393 if (((x < subject_ptr->x) && (x > mon_fx)) || ((x > subject_ptr->x) && (x < mon_fx)))
1395 dpf = subject_ptr->x - mon_fx;
1397 midpoint = mon_fy + ((subject_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
1399 /* Only first wall viewed from mid-y is lit */
1402 if (!cave_los_bold(subject_ptr->current_floor_ptr, y + 1, x) && !cave_have_flag_bold(subject_ptr->current_floor_ptr, y + 1, x, FF_PROJECT)) return;
1404 else if (y > midpoint)
1406 if (!cave_los_bold(subject_ptr->current_floor_ptr, y - 1, x) && !cave_have_flag_bold(subject_ptr->current_floor_ptr, y - 1, x, FF_PROJECT)) return;
1409 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1410 else if (mon_invis) return;
1414 /* We trust tmp_pos.n does not exceed TEMP_MAX */
1416 /* Save this square */
1417 tmp_pos.x[tmp_pos.n] = x;
1418 tmp_pos.y[tmp_pos.n] = y;
1422 g_ptr->info |= CAVE_MNDK;
1427 * Update squares illuminated or darkened by monsters.
1429 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
1430 * denote squares illuminated by monsters.
1432 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
1433 * updating. Only squares in view of the player, whos state
1434 * changes are drawn via lite_spot().
1436 void update_mon_lite(player_type *subject_ptr)
1438 void(*add_mon_lite)(player_type *, POSITION, POSITION);
1440 /* Non-Ninja player in the darkness */
1441 int dis_lim = ((d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !subject_ptr->see_nocto) ?
1442 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
1444 /* Clear all monster lit squares */
1445 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
1446 for (int i = 0; i < floor_ptr->mon_lite_n; i++)
1449 g_ptr = &floor_ptr->grid_array[floor_ptr->mon_lite_y[i]][floor_ptr->mon_lite_x[i]];
1451 /* Set temp or xtra flag */
1452 g_ptr->info |= (g_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
1454 /* Clear monster illumination flag */
1455 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
1458 /* Empty temp list of new squares to lite up */
1461 /* If a monster stops time, don't process */
1462 if (!current_world_ptr->timewalk_m_idx)
1464 monster_type *m_ptr;
1465 monster_race *r_ptr;
1467 /* Loop through monsters, adding newly lit squares to changes list */
1468 for (int i = 1; i < floor_ptr->m_max; i++)
1470 m_ptr = &floor_ptr->m_list[i];
1471 r_ptr = &r_info[m_ptr->r_idx];
1472 if (!monster_is_valid(m_ptr)) continue;
1474 /* Is it too far away? */
1475 if (m_ptr->cdis > dis_lim) continue;
1477 /* Get lite radius */
1480 /* Note the radii are cumulative */
1481 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
1482 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
1483 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
1484 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
1486 /* Exit if has no light */
1492 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (MON_CSLEEP(m_ptr) || (!floor_ptr->dun_level && is_daytime()) || subject_ptr->phase_out)) continue;
1493 if (d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) rad = 1;
1494 add_mon_lite = mon_lite_hack;
1499 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!floor_ptr->dun_level && !is_daytime()))) continue;
1500 add_mon_lite = mon_dark_hack;
1501 f_flag = FF_PROJECT;
1502 rad = -rad; /* Use absolute value */
1508 /* Is the monster visible? */
1509 mon_invis = !(floor_ptr->grid_array[mon_fy][mon_fx].info & CAVE_VIEW);
1511 /* The square it is on */
1512 add_mon_lite(subject_ptr, mon_fy, mon_fx);
1514 /* Adjacent squares */
1515 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx);
1516 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx);
1517 add_mon_lite(subject_ptr, mon_fy, mon_fx + 1);
1518 add_mon_lite(subject_ptr, mon_fy, mon_fx - 1);
1519 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx + 1);
1520 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx - 1);
1521 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx + 1);
1522 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx - 1);
1525 if (rad < 2) continue;
1527 /* South of the monster */
1529 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy + 1, mon_fx, f_flag))
1531 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx + 1);
1532 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx);
1533 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx - 1);
1535 g_ptr = &floor_ptr->grid_array[mon_fy + 2][mon_fx];
1538 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1540 add_mon_lite(subject_ptr, mon_fy + 3, mon_fx + 1);
1541 add_mon_lite(subject_ptr, mon_fy + 3, mon_fx);
1542 add_mon_lite(subject_ptr, mon_fy + 3, mon_fx - 1);
1546 /* North of the monster */
1547 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy - 1, mon_fx, f_flag))
1549 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx + 1);
1550 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx);
1551 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx - 1);
1553 g_ptr = &floor_ptr->grid_array[mon_fy - 2][mon_fx];
1556 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1558 add_mon_lite(subject_ptr, mon_fy - 3, mon_fx + 1);
1559 add_mon_lite(subject_ptr, mon_fy - 3, mon_fx);
1560 add_mon_lite(subject_ptr, mon_fy - 3, mon_fx - 1);
1564 /* East of the monster */
1565 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy, mon_fx + 1, f_flag))
1567 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx + 2);
1568 add_mon_lite(subject_ptr, mon_fy, mon_fx + 2);
1569 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx + 2);
1571 g_ptr = &floor_ptr->grid_array[mon_fy][mon_fx + 2];
1574 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1576 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx + 3);
1577 add_mon_lite(subject_ptr, mon_fy, mon_fx + 3);
1578 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx + 3);
1582 /* West of the monster */
1583 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy, mon_fx - 1, f_flag))
1585 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx - 2);
1586 add_mon_lite(subject_ptr, mon_fy, mon_fx - 2);
1587 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx - 2);
1589 g_ptr = &floor_ptr->grid_array[mon_fy][mon_fx - 2];
1592 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1594 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx - 3);
1595 add_mon_lite(subject_ptr, mon_fy, mon_fx - 3);
1596 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx - 3);
1601 if (rad != 3) continue;
1603 /* South-East of the monster */
1604 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy + 1, mon_fx + 1, f_flag))
1606 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx + 2);
1609 /* South-West of the monster */
1610 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy + 1, mon_fx - 1, f_flag))
1612 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx - 2);
1615 /* North-East of the monster */
1616 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy - 1, mon_fx + 1, f_flag))
1618 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx + 2);
1621 /* North-West of the monster */
1622 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy - 1, mon_fx - 1, f_flag))
1624 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx - 2);
1629 /* Save end of list of new squares */
1630 s16b end_temp = tmp_pos.n;
1633 * Look at old set flags to see if there are any changes.
1635 for (int i = 0; i < floor_ptr->mon_lite_n; i++)
1637 POSITION fx = floor_ptr->mon_lite_x[i];
1638 POSITION fy = floor_ptr->mon_lite_y[i];
1641 g_ptr = &floor_ptr->grid_array[fy][fx];
1643 if (g_ptr->info & CAVE_TEMP) /* Pervious lit */
1645 /* It it no longer lit? */
1646 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
1648 /* It is now unlit */
1649 /* Add it to later visual update */
1650 cave_note_and_redraw_later(floor_ptr, g_ptr, fy, fx);
1653 else /* Pervious darkened */
1655 /* It it no longer darken? */
1656 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
1658 /* It is now undarken */
1659 /* Add it to later visual update */
1660 cave_note_and_redraw_later(floor_ptr, g_ptr, fy, fx);
1664 /* Add to end of temp array */
1665 tmp_pos.x[tmp_pos.n] = fx;
1666 tmp_pos.y[tmp_pos.n] = fy;
1670 /* Clear the lite array */
1671 floor_ptr->mon_lite_n = 0;
1673 /* Copy the temp array into the lit array lighting the new squares. */
1674 for (int i = 0; i < end_temp; i++)
1676 POSITION fx = tmp_pos.x[i];
1677 POSITION fy = tmp_pos.y[i];
1680 g_ptr = &floor_ptr->grid_array[fy][fx];
1682 if (g_ptr->info & CAVE_MNLT) /* Lit */
1684 /* The is the square newly lit and visible? */
1685 if ((g_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
1688 /* Add it to later visual update */
1689 cave_note_and_redraw_later(floor_ptr, g_ptr, fy, fx);
1694 /* The is the square newly darkened and visible? */
1695 if ((g_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
1697 /* It is now darkened */
1698 /* Add it to later visual update */
1699 cave_note_and_redraw_later(floor_ptr, g_ptr, fy, fx);
1703 /* Save in the monster lit or darkened array */
1704 floor_ptr->mon_lite_x[floor_ptr->mon_lite_n] = fx;
1705 floor_ptr->mon_lite_y[floor_ptr->mon_lite_n] = fy;
1706 floor_ptr->mon_lite_n++;
1709 /* Clear the temp flag for the old lit or darken grids */
1710 for (int i = end_temp; i < tmp_pos.n; i++)
1712 /* We trust this grid is in bounds */
1714 floor_ptr->grid_array[tmp_pos.y[i]][tmp_pos.x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
1719 /* Mega-Hack -- Visual update later */
1720 subject_ptr->update |= (PU_DELAY_VIS);
1722 subject_ptr->monlite = (floor_ptr->grid_array[subject_ptr->y][subject_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
1724 if (!(subject_ptr->special_defense & NINJA_S_STEALTH))
1726 subject_ptr->old_monlite = subject_ptr->monlite;
1730 if (subject_ptr->old_monlite == subject_ptr->monlite)
1732 subject_ptr->old_monlite = subject_ptr->monlite;
1736 if (subject_ptr->monlite)
1738 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
1742 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
1745 subject_ptr->old_monlite = subject_ptr->monlite;
1749 void clear_mon_lite(floor_type *floor_ptr)
1751 /* Clear all monster lit squares */
1752 for (int i = 0; i < floor_ptr->mon_lite_n; i++)
1756 g_ptr = &floor_ptr->grid_array[floor_ptr->mon_lite_y[i]][floor_ptr->mon_lite_x[i]];
1758 /* Clear monster illumination flag */
1759 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
1762 /* Empty the array */
1763 floor_ptr->mon_lite_n = 0;