1 #include "system/angband.h"
4 #include "dungeon/dungeon.h"
5 #include "floor/floor.h"
6 #include "floor/floor-events.h"
8 #include "monster/monster.h"
9 #include "monster/monster-status.h"
10 #include "dungeon/quest.h"
11 #include "object/object-hook.h"
12 #include "object/object-mark-types.h"
13 #include "object/special-object-flags.h"
14 #include "player/player-move.h"
15 #include "world/world.h"
16 #include "player/player-effects.h"
17 #include "object/object-kind.h"
18 #include "object/object-ego.h"
20 #include "view/display-main-window.h"
22 static bool mon_invis;
23 static POSITION mon_fy, mon_fx;
24 byte get_dungeon_feeling(player_type *subject_ptr);
26 void day_break(player_type *subject_ptr)
29 msg_print(_("夜が明けた。", "The sun has risen."));
31 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
32 if (!subject_ptr->wild_mode)
34 /* Hack -- Scan the town */
35 for (y = 0; y < floor_ptr->height; y++)
37 for (x = 0; x < floor_ptr->width; x++)
39 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
42 g_ptr->info |= (CAVE_GLOW);
44 /* Hack -- Memorize lit grids if allowed */
45 if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
47 note_spot(subject_ptr, y, x);
52 subject_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
53 subject_ptr->redraw |= (PR_MAP);
54 subject_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
56 if (subject_ptr->special_defense & NINJA_S_STEALTH)
58 if (floor_ptr->grid_array[subject_ptr->y][subject_ptr->x].info & CAVE_GLOW) set_superstealth(subject_ptr, FALSE);
63 void night_falls(player_type *subject_ptr)
66 msg_print(_("日が沈んだ。", "The sun has fallen."));
68 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
69 if (!subject_ptr->wild_mode)
71 /* Hack -- Scan the town */
72 for (y = 0; y < floor_ptr->height; y++)
74 for (x = 0; x < floor_ptr->width; x++)
76 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
78 /* Feature code (applying "mimic" field) */
79 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
81 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
82 !have_flag(f_ptr->flags, FF_ENTRANCE))
85 g_ptr->info &= ~(CAVE_GLOW);
87 if (!have_flag(f_ptr->flags, FF_REMEMBER))
89 /* Forget the normal floor grid */
90 g_ptr->info &= ~(CAVE_MARK);
92 note_spot(subject_ptr, y, x);
97 glow_deep_lava_and_bldg(subject_ptr);
101 subject_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
102 subject_ptr->redraw |= (PR_MAP);
103 subject_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
105 if (subject_ptr->special_defense & NINJA_S_STEALTH)
107 if (floor_ptr->grid_array[subject_ptr->y][subject_ptr->x].info & CAVE_GLOW) set_superstealth(subject_ptr, FALSE);
113 * @brief 現在フロアに残っている敵モンスターの数を返す /
114 * @return 現在の敵モンスターの数
116 MONSTER_NUMBER count_all_hostile_monsters(floor_type *floor_ptr)
118 MONSTER_NUMBER number_mon = 0;
120 for (POSITION x = 0; x < floor_ptr->width; ++x)
122 for (POSITION y = 0; y < floor_ptr->height; ++y)
124 MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
126 if (m_idx > 0 && is_hostile(&floor_ptr->m_list[m_idx]))
137 * ダンジョンの雰囲気を計算するための非線形基準値 / Dungeon rating is no longer linear
139 #define RATING_BOOST(delta) (delta * delta + 50 * delta)
142 * @brief ダンジョンの雰囲気を算出する。
143 * / Examine all monsters and unidentified objects, and get the feeling of current dungeon floor
144 * @return 算出されたダンジョンの雰囲気ランク
146 byte get_dungeon_feeling(player_type *subject_ptr)
148 /* Hack -- no feeling in the town */
149 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
150 if (!floor_ptr->dun_level) return 0;
152 /* Examine each monster */
155 for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++)
157 monster_type *m_ptr = &floor_ptr->m_list[i];
160 if (!monster_is_valid(m_ptr)) continue;
162 if (is_pet(m_ptr)) continue;
164 r_ptr = &r_info[m_ptr->r_idx];
166 if (r_ptr->flags1 & (RF1_UNIQUE))
168 /* Nearly out-of-depth unique monsters */
169 if (r_ptr->level + 10 > floor_ptr->dun_level)
171 /* Boost rating by twice delta-depth */
172 delta += (r_ptr->level + 10 - floor_ptr->dun_level) * 2 * base;
177 /* Out-of-depth monsters */
178 if (r_ptr->level > floor_ptr->dun_level)
180 /* Boost rating by delta-depth */
181 delta += (r_ptr->level - floor_ptr->dun_level) * base;
185 /* Unusually crowded monsters get a little bit of rating boost */
186 if (r_ptr->flags1 & RF1_FRIENDS)
188 if (5 <= get_monster_crowd_number(subject_ptr, i)) delta += 1;
192 if (2 <= get_monster_crowd_number(subject_ptr, i)) delta += 1;
196 rating += RATING_BOOST(delta);
199 /* Examine each unidentified object */
200 for (MONSTER_IDX i = 1; i < floor_ptr->o_max; i++)
202 object_type *o_ptr = &floor_ptr->o_list[i];
203 object_kind *k_ptr = &k_info[o_ptr->k_idx];
206 if (!OBJECT_IS_VALID(o_ptr)) continue;
208 /* Skip known objects */
209 if (object_is_known(o_ptr))
212 if (o_ptr->marked & OM_TOUCHED) continue;
215 /* Skip pseudo-known objects */
216 if (o_ptr->ident & IDENT_SENSE) continue;
219 if (object_is_ego(o_ptr))
221 ego_item_type *e_ptr = &e_info[o_ptr->name2];
223 delta += e_ptr->rating * base;
227 if (object_is_artifact(o_ptr))
229 PRICE cost = object_value_real(o_ptr);
232 if (cost > 10000L) delta += 10 * base;
233 if (cost > 50000L) delta += 10 * base;
234 if (cost > 100000L) delta += 10 * base;
236 /* Special feeling */
237 if (!preserve_mode) return 1;
240 if (o_ptr->tval == TV_DRAG_ARMOR) delta += 30 * base;
241 if (o_ptr->tval == TV_SHIELD && o_ptr->sval == SV_DRAGON_SHIELD) delta += 5 * base;
242 if (o_ptr->tval == TV_GLOVES && o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) delta += 5 * base;
243 if (o_ptr->tval == TV_BOOTS && o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) delta += 5 * base;
244 if (o_ptr->tval == TV_HELM && o_ptr->sval == SV_DRAGON_HELM) delta += 5 * base;
245 if (o_ptr->tval == TV_RING && o_ptr->sval == SV_RING_SPEED && !object_is_cursed(o_ptr)) delta += 25 * base;
246 if (o_ptr->tval == TV_RING && o_ptr->sval == SV_RING_LORDLY && !object_is_cursed(o_ptr)) delta += 15 * base;
247 if (o_ptr->tval == TV_AMULET && o_ptr->sval == SV_AMULET_THE_MAGI && !object_is_cursed(o_ptr)) delta += 15 * base;
249 /* Out-of-depth objects */
250 if (!object_is_cursed(o_ptr) && !object_is_broken(o_ptr) && k_ptr->level > floor_ptr->dun_level)
252 /* Rating increase */
253 delta += (k_ptr->level - floor_ptr->dun_level) * base;
256 rating += RATING_BOOST(delta);
260 if (rating > RATING_BOOST(1000)) return 2;
261 if (rating > RATING_BOOST(800)) return 3;
262 if (rating > RATING_BOOST(600)) return 4;
263 if (rating > RATING_BOOST(400)) return 5;
264 if (rating > RATING_BOOST(300)) return 6;
265 if (rating > RATING_BOOST(200)) return 7;
266 if (rating > RATING_BOOST(100)) return 8;
267 if (rating > RATING_BOOST(0)) return 9;
272 * @brief ダンジョンの雰囲気を更新し、変化があった場合メッセージを表示する
273 * / Update dungeon feeling, and announce it if changed
276 void update_dungeon_feeling(player_type *subject_ptr)
278 /* No feeling on the surface */
279 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
280 if (!floor_ptr->dun_level) return;
282 /* No feeling in the arena */
283 if (subject_ptr->phase_out) return;
285 /* Extract delay time */
286 int delay = MAX(10, 150 - subject_ptr->skill_fos) * (150 - floor_ptr->dun_level) * TURNS_PER_TICK / 100;
288 /* Not yet felt anything */
289 if (current_world_ptr->game_turn < subject_ptr->feeling_turn + delay && !cheat_xtra) return;
291 /* Extract quest number (if any) */
292 int quest_num = quest_number(subject_ptr, floor_ptr->dun_level);
294 /* No feeling in a quest */
296 (is_fixed_quest_idx(quest_num) &&
297 !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
298 !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) return;
301 /* Get new dungeon feeling */
302 byte new_feeling = get_dungeon_feeling(subject_ptr);
304 /* Remember last time updated */
305 subject_ptr->feeling_turn = current_world_ptr->game_turn;
308 if (subject_ptr->feeling == new_feeling) return;
310 /* Dungeon feeling is changed */
311 subject_ptr->feeling = new_feeling;
313 /* Announce feeling */
314 do_cmd_feeling(subject_ptr);
316 select_floor_music(subject_ptr);
318 /* Update the level indicator */
319 subject_ptr->redraw |= (PR_DEPTH);
321 if (disturb_minor) disturb(subject_ptr, FALSE, FALSE);
326 * Glow deep lava and building entrances in the floor
328 void glow_deep_lava_and_bldg(player_type *subject_ptr)
330 /* Not in the darkness dungeon */
331 if (d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) return;
333 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
334 for (POSITION y = 0; y < floor_ptr->height; y++)
336 for (POSITION x = 0; x < floor_ptr->width; x++)
339 g_ptr = &floor_ptr->grid_array[y][x];
341 if (!have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_GLOW))
344 for (DIRECTION i = 0; i < 9; i++)
346 POSITION yy = y + ddy_ddd[i];
347 POSITION xx = x + ddx_ddd[i];
348 if (!in_bounds2(floor_ptr, yy, xx)) continue;
349 floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
354 subject_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
355 subject_ptr->redraw |= (PR_MAP);
360 * Actually erase the entire "lite" array, redrawing every grid
362 void forget_lite(floor_type *floor_ptr)
365 if (!floor_ptr->lite_n) return;
368 for (int i = 0; i < floor_ptr->lite_n; i++)
370 POSITION y = floor_ptr->lite_y[i];
371 POSITION x = floor_ptr->lite_x[i];
373 /* Forget "LITE" flag */
374 floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
377 floor_ptr->lite_n = 0;
382 * Update the set of grids "illuminated" by the player's lite.
384 * This routine needs to use the results of "update_view()"
386 * Note that "blindness" does NOT affect "torch lite". Be careful!
388 * We optimize most lites (all non-artifact lites) by using "obvious"
389 * facts about the results of "small" lite radius, and we attempt to
390 * list the "nearby" grids before the more "distant" ones in the
391 * array of torch-lit grids.
393 * We assume that "radius zero" lite is in fact no lite at all.
395 * Torch Lantern Artifacts
405 void update_lite(player_type *subject_ptr)
407 POSITION p = subject_ptr->cur_lite;
410 /*** Save the old "lite" grids for later ***/
413 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
414 for (int i = 0; i < floor_ptr->lite_n; i++)
416 POSITION y = floor_ptr->lite_y[i];
417 POSITION x = floor_ptr->lite_x[i];
419 /* Mark the grid as not "lite" */
420 floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
422 /* Mark the grid as "seen" */
423 floor_ptr->grid_array[y][x].info |= (CAVE_TEMP);
425 /* Add it to the "seen" set */
426 tmp_pos.y[tmp_pos.n] = y;
427 tmp_pos.x[tmp_pos.n] = x;
432 floor_ptr->lite_n = 0;
435 /*** Collect the new "lite" grids ***/
437 /* Radius 1 -- torch radius */
441 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x);
444 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x);
445 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x);
446 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x + 1);
447 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x - 1);
450 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x + 1);
451 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x - 1);
452 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x + 1);
453 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x - 1);
456 /* Radius 2 -- lantern radius */
459 /* South of the player */
460 if (cave_los_bold(floor_ptr, subject_ptr->y + 1, subject_ptr->x))
462 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x);
463 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x + 1);
464 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x - 1);
467 /* North of the player */
468 if (cave_los_bold(floor_ptr, subject_ptr->y - 1, subject_ptr->x))
470 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x);
471 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x + 1);
472 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x - 1);
475 /* East of the player */
476 if (cave_los_bold(floor_ptr, subject_ptr->y, subject_ptr->x + 1))
478 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x + 2);
479 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x + 2);
480 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x + 2);
483 /* West of the player */
484 if (cave_los_bold(floor_ptr, subject_ptr->y, subject_ptr->x - 1))
486 cave_lite_hack(floor_ptr, subject_ptr->y, subject_ptr->x - 2);
487 cave_lite_hack(floor_ptr, subject_ptr->y + 1, subject_ptr->x - 2);
488 cave_lite_hack(floor_ptr, subject_ptr->y - 1, subject_ptr->x - 2);
492 /* Radius 3+ -- artifact radius */
497 /* Paranoia -- see "LITE_MAX" */
500 /* South-East of the player */
501 if (cave_los_bold(floor_ptr, subject_ptr->y + 1, subject_ptr->x + 1))
503 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x + 2);
506 /* South-West of the player */
507 if (cave_los_bold(floor_ptr, subject_ptr->y + 1, subject_ptr->x - 1))
509 cave_lite_hack(floor_ptr, subject_ptr->y + 2, subject_ptr->x - 2);
512 /* North-East of the player */
513 if (cave_los_bold(floor_ptr, subject_ptr->y - 1, subject_ptr->x + 1))
515 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x + 2);
518 /* North-West of the player */
519 if (cave_los_bold(floor_ptr, subject_ptr->y - 1, subject_ptr->x - 1))
521 cave_lite_hack(floor_ptr, subject_ptr->y - 2, subject_ptr->x - 2);
525 POSITION min_y = subject_ptr->y - p;
526 if (min_y < 0) min_y = 0;
529 POSITION max_y = subject_ptr->y + p;
530 if (max_y > floor_ptr->height - 1) max_y = floor_ptr->height - 1;
533 POSITION min_x = subject_ptr->x - p;
534 if (min_x < 0) min_x = 0;
537 POSITION max_x = subject_ptr->x + p;
538 if (max_x > floor_ptr->width - 1) max_x = floor_ptr->width - 1;
540 /* Scan the maximal box */
541 for (POSITION y = min_y; y <= max_y; y++)
543 for (POSITION x = min_x; x <= max_x; x++)
545 int dy = (subject_ptr->y > y) ? (subject_ptr->y - y) : (y - subject_ptr->y);
546 int dx = (subject_ptr->x > x) ? (subject_ptr->x - x) : (x - subject_ptr->x);
548 /* Skip the "central" grids (above) */
549 if ((dy <= 2) && (dx <= 2)) continue;
551 /* Hack -- approximate the distance */
552 d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
554 /* Skip distant grids */
557 /* Viewable, nearby, grids get "torch lit" */
558 if (floor_ptr->grid_array[y][x].info & CAVE_VIEW)
560 /* This grid is "torch lit" */
561 cave_lite_hack(floor_ptr, y, x);
568 /*** Complete the algorithm ***/
570 /* Draw the new grids */
571 for (int i = 0; i < floor_ptr->lite_n; i++)
573 POSITION y = floor_ptr->lite_y[i];
574 POSITION x = floor_ptr->lite_x[i];
576 g_ptr = &floor_ptr->grid_array[y][x];
578 /* Update fresh grids */
579 if (g_ptr->info & (CAVE_TEMP)) continue;
581 /* Add it to later visual update */
582 cave_note_and_redraw_later(floor_ptr, g_ptr, y, x);
586 for (int i = 0; i < tmp_pos.n; i++)
588 POSITION y = tmp_pos.y[i];
589 POSITION x = tmp_pos.x[i];
591 g_ptr = &floor_ptr->grid_array[y][x];
593 /* No longer in the array */
594 g_ptr->info &= ~(CAVE_TEMP);
596 /* Update stale grids */
597 if (g_ptr->info & (CAVE_LITE)) continue;
599 /* Add it to later visual update */
600 cave_redraw_later(floor_ptr, g_ptr, y, x);
604 subject_ptr->update |= (PU_DELAY_VIS);
609 * Clear the viewable space
611 void forget_view(floor_type *floor_ptr)
614 if (!floor_ptr->view_n) return;
617 for (int i = 0; i < floor_ptr->view_n; i++)
619 POSITION y = floor_ptr->view_y[i];
620 POSITION x = floor_ptr->view_x[i];
622 g_ptr = &floor_ptr->grid_array[y][x];
624 /* Forget that the grid is viewable */
625 g_ptr->info &= ~(CAVE_VIEW);
628 floor_ptr->view_n = 0;
633 * Helper function for "update_view()" below
635 * We are checking the "viewability" of grid (y,x) by the player.
637 * This function assumes that (y,x) is legal (i.e. on the map).
639 * Grid (y1,x1) is on the "diagonal" between (subject_ptr->y,subject_ptr->x) and (y,x)
640 * Grid (y2,x2) is "adjacent", also between (subject_ptr->y,subject_ptr->x) and (y,x).
642 * Note that we are using the "CAVE_XTRA" field for marking grids as
643 * "easily viewable". This bit is cleared at the end of "update_view()".
645 * This function adds (y,x) to the "viewable set" if necessary.
647 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
649 static bool update_view_aux(player_type *subject_ptr, POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
651 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
654 g1_c_ptr = &floor_ptr->grid_array[y1][x1];
655 g2_c_ptr = &floor_ptr->grid_array[y2][x2];
657 /* Check for walls */
658 bool f1 = (cave_los_grid(g1_c_ptr));
659 bool f2 = (cave_los_grid(g2_c_ptr));
661 /* Totally blocked by physical walls */
662 if (!f1 && !f2) return TRUE;
664 /* Check for visibility */
665 bool v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
666 bool v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
668 /* Totally blocked by "unviewable neighbors" */
669 if (!v1 && !v2) return TRUE;
672 g_ptr = &floor_ptr->grid_array[y][x];
674 /* Check for walls */
675 bool wall = (!cave_los_grid(g_ptr));
677 /* Check the "ease" of visibility */
678 bool z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
679 bool z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
681 /* Hack -- "easy" plus "easy" yields "easy" */
684 g_ptr->info |= (CAVE_XTRA);
685 cave_view_hack(floor_ptr, g_ptr, y, x);
689 /* Hack -- primary "easy" yields "viewed" */
692 cave_view_hack(floor_ptr, g_ptr, y, x);
696 /* Hack -- "view" plus "view" yields "view" */
699 cave_view_hack(floor_ptr, g_ptr, y, x);
703 /* Mega-Hack -- the "los()" function works poorly on walls */
706 cave_view_hack(floor_ptr, g_ptr, y, x);
710 /* Hack -- check line of sight */
711 if (los(subject_ptr, subject_ptr->y, subject_ptr->x, y, x))
713 cave_view_hack(floor_ptr, g_ptr, y, x);
722 * Calculate the viewable space
724 * 1: Process the player
725 * 1a: The player is always (easily) viewable
726 * 2: Process the diagonals
727 * 2a: The diagonals are (easily) viewable up to the first wall
728 * 2b: But never go more than 2/3 of the "full" distance
729 * 3: Process the main axes
730 * 3a: The main axes are (easily) viewable up to the first wall
731 * 3b: But never go more than the "full" distance
732 * 4: Process sequential "strips" in each of the eight octants
733 * 4a: Each strip runs along the previous strip
734 * 4b: The main axes are "previous" to the first strip
735 * 4c: Process both "sides" of each "direction" of each strip
736 * 4c1: Each side aborts as soon as possible
737 * 4c2: Each side tells the next strip how far it has to check
739 * Note that the octant processing involves some pretty interesting
740 * observations involving when a grid might possibly be viewable from
741 * a given grid, and on the order in which the strips are processed.
743 * Note the use of the mathematical facts shown below, which derive
744 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
745 * hypotenuse of a right triangle is primarily determined by the length
746 * of the longest side, when one side is small, and is strictly less
747 * than one-and-a-half times as long as the longest side when both of
748 * the sides are large.
750 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
751 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
753 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
755 * These observations are important because the calculation of the actual
756 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
757 * while for small values (up to about 20 or so), the approximations above
758 * are correct to within an error of at most one grid or so.
760 * Observe the use of "full" and "over" in the code below, and the use of
761 * the specialized calculation involving "limit", all of which derive from
762 * the observations given above. Basically, we note that the "circle" of
763 * view is completely contained in an "octagon" whose bounds are easy to
764 * determine, and that only a few steps are needed to derive the actual
765 * bounds of the circle given the bounds of the octagon.
767 * Note that by skipping all the grids in the corners of the octagon, we
768 * place an upper limit on the number of grids in the field of view, given
769 * that "full" is never more than 20. Of the 1681 grids in the "square" of
770 * view, only about 1475 of these are in the "octagon" of view, and even
771 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
772 * entries to completely contain the actual field of view.
774 * Note also the care taken to prevent "running off the map". The use of
775 * explicit checks on the "validity" of the "diagonal", and the fact that
776 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
777 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
778 * of multiple checks on the validity of grids.
780 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
781 * "ws","wn" variables. They work like this: While travelling down the
782 * south-bound strip just to the east of the main south axis, as soon as
783 * we get to a grid which does not "transmit" viewing, if all of the strips
784 * preceding us (in this case, just the main axis) had terminated at or before
785 * the same point, then we can stop, and reset the "max distance" to ourself.
786 * So, each strip (named by major axis plus offset, thus "se" in this case)
787 * maintains a "blockage" variable, initialized during the main axis step,
788 * and checks it whenever a blockage is observed. After processing each
789 * strip as far as the previous strip told us to process, the next strip is
790 * told not to go farther than the current strip's farthest viewable grid,
791 * unless open space is still available. This uses the "k" variable.
793 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
794 * macro is a replacement for "cave_los_bold()" which takes a pointer to
795 * a grid instead of its location. The "cave_view_hack()" macro is a
796 * chunk of code which adds the given location to the "view" array if it
797 * is not already there, using both the actual location and a pointer to
798 * the grid. See above.
800 * By the way, the purpose of this code is to reduce the dependancy on the
801 * "los()" function which is slow, and, in some cases, not very accurate.
803 * It is very possible that I am the only person who fully understands this
804 * function, and for that I am truly sorry, but efficiency was very important
805 * and the "simple" version of this function was just not fast enough. I am
806 * more than willing to replace this function with a simpler one, if it is
807 * equally efficient, and especially willing if the new function happens to
808 * derive "reverse-line-of-sight" at the same time, since currently monsters
809 * just use an optimized hack of "you see me, so I see you", and then use the
810 * actual "projectable()" function to check spell attacks.
812 void update_view(player_type *subject_ptr)
817 int se, sw, ne, nw, es, en, ws, wn;
821 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
822 POSITION y_max = floor_ptr->height - 1;
823 POSITION x_max = floor_ptr->width - 1;
830 if (view_reduce_view && !floor_ptr->dun_level)
832 /* Full radius (10) */
833 full = MAX_SIGHT / 2;
835 /* Octagon factor (15) */
836 over = MAX_SIGHT * 3 / 4;
842 /* Full radius (20) */
845 /* Octagon factor (30) */
846 over = MAX_SIGHT * 3 / 2;
850 /*** Step 0 -- Begin ***/
852 /* Save the old "view" grids for later */
853 for (n = 0; n < floor_ptr->view_n; n++)
855 y = floor_ptr->view_y[n];
856 x = floor_ptr->view_x[n];
857 g_ptr = &floor_ptr->grid_array[y][x];
859 /* Mark the grid as not in "view" */
860 g_ptr->info &= ~(CAVE_VIEW);
862 /* Mark the grid as "seen" */
863 g_ptr->info |= (CAVE_TEMP);
865 /* Add it to the "seen" set */
866 tmp_pos.y[tmp_pos.n] = y;
867 tmp_pos.x[tmp_pos.n] = x;
871 /* Start over with the "view" array */
872 floor_ptr->view_n = 0;
874 /*** Step 1 -- adjacent grids ***/
876 /* Now start on the player */
879 g_ptr = &floor_ptr->grid_array[y][x];
881 /* Assume the player grid is easily viewable */
882 g_ptr->info |= (CAVE_XTRA);
884 /* Assume the player grid is viewable */
885 cave_view_hack(floor_ptr, g_ptr, y, x);
888 /*** Step 2 -- Major Diagonals ***/
893 /* Scan south-east */
894 for (d = 1; d <= z; d++)
896 g_ptr = &floor_ptr->grid_array[y + d][x + d];
897 g_ptr->info |= (CAVE_XTRA);
898 cave_view_hack(floor_ptr, g_ptr, y + d, x + d);
899 if (!cave_los_grid(g_ptr)) break;
902 /* Scan south-west */
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 north-east */
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-west */
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 /*** Step 3 -- major axes ***/
932 for (d = 1; d <= full; d++)
934 g_ptr = &floor_ptr->grid_array[y + d][x];
935 g_ptr->info |= (CAVE_XTRA);
936 cave_view_hack(floor_ptr, g_ptr, y + d, x);
937 if (!cave_los_grid(g_ptr)) break;
940 /* Initialize the "south strips" */
944 for (d = 1; d <= full; d++)
946 g_ptr = &floor_ptr->grid_array[y - d][x];
947 g_ptr->info |= (CAVE_XTRA);
948 cave_view_hack(floor_ptr, g_ptr, y - d, x);
949 if (!cave_los_grid(g_ptr)) break;
952 /* Initialize the "north strips" */
956 for (d = 1; d <= full; d++)
958 g_ptr = &floor_ptr->grid_array[y][x + d];
959 g_ptr->info |= (CAVE_XTRA);
960 cave_view_hack(floor_ptr, g_ptr, y, x + d);
961 if (!cave_los_grid(g_ptr)) break;
964 /* Initialize the "east strips" */
968 for (d = 1; d <= full; d++)
970 g_ptr = &floor_ptr->grid_array[y][x - d];
971 g_ptr->info |= (CAVE_XTRA);
972 cave_view_hack(floor_ptr, g_ptr, y, x - d);
973 if (!cave_los_grid(g_ptr)) break;
976 /* Initialize the "west strips" */
980 /*** Step 4 -- Divide each "octant" into "strips" ***/
982 /* Now check each "diagonal" (in parallel) */
983 for (n = 1; n <= over / 2; n++)
985 POSITION ypn, ymn, xpn, xmn;
987 /* Acquire the "bounds" of the maximal circle */
989 if (z > full - n) z = full - n;
990 while ((z + n + (n >> 1)) > full) z--;
992 /* Access the four diagonal grids */
1001 /* Maximum distance */
1002 m = MIN(z, y_max - ypn);
1005 if ((xpn <= x_max) && (n < se))
1008 for (k = n, d = 1; d <= m; d++)
1010 /* Check grid "d" in strip "n", notice "blockage" */
1011 if (update_view_aux(subject_ptr, ypn + d, xpn, ypn + d - 1, xpn - 1, ypn + d - 1, xpn))
1013 if (n + d >= se) break;
1016 /* Track most distant "non-blockage" */
1023 /* Limit the next strip */
1028 if ((xmn >= 0) && (n < sw))
1031 for (k = n, d = 1; d <= m; d++)
1033 /* Check grid "d" in strip "n", notice "blockage" */
1034 if (update_view_aux(subject_ptr, ypn + d, xmn, ypn + d - 1, xmn + 1, ypn + d - 1, xmn))
1036 if (n + d >= sw) break;
1039 /* Track most distant "non-blockage" */
1046 /* Limit the next strip */
1054 /* Maximum distance */
1058 if ((xpn <= x_max) && (n < ne))
1061 for (k = n, d = 1; d <= m; d++)
1063 /* Check grid "d" in strip "n", notice "blockage" */
1064 if (update_view_aux(subject_ptr, ymn - d, xpn, ymn - d + 1, xpn - 1, ymn - d + 1, xpn))
1066 if (n + d >= ne) break;
1069 /* Track most distant "non-blockage" */
1076 /* Limit the next strip */
1081 if ((xmn >= 0) && (n < nw))
1084 for (k = n, d = 1; d <= m; d++)
1086 /* Check grid "d" in strip "n", notice "blockage" */
1087 if (update_view_aux(subject_ptr, ymn - d, xmn, ymn - d + 1, xmn + 1, ymn - d + 1, xmn))
1089 if (n + d >= nw) break;
1092 /* Track most distant "non-blockage" */
1099 /* Limit the next strip */
1107 /* Maximum distance */
1108 m = MIN(z, x_max - xpn);
1111 if ((ypn <= x_max) && (n < es))
1114 for (k = n, d = 1; d <= m; d++)
1116 /* Check grid "d" in strip "n", notice "blockage" */
1117 if (update_view_aux(subject_ptr, ypn, xpn + d, ypn - 1, xpn + d - 1, ypn, xpn + d - 1))
1119 if (n + d >= es) break;
1122 /* Track most distant "non-blockage" */
1129 /* Limit the next strip */
1134 if ((ymn >= 0) && (n < en))
1137 for (k = n, d = 1; d <= m; d++)
1139 /* Check grid "d" in strip "n", notice "blockage" */
1140 if (update_view_aux(subject_ptr, ymn, xpn + d, ymn + 1, xpn + d - 1, ymn, xpn + d - 1))
1142 if (n + d >= en) break;
1145 /* Track most distant "non-blockage" */
1152 /* Limit the next strip */
1160 /* Maximum distance */
1164 if ((ypn <= y_max) && (n < ws))
1167 for (k = n, d = 1; d <= m; d++)
1169 /* Check grid "d" in strip "n", notice "blockage" */
1170 if (update_view_aux(subject_ptr, ypn, xmn - d, ypn - 1, xmn - d + 1, ypn, xmn - d + 1))
1172 if (n + d >= ws) break;
1175 /* Track most distant "non-blockage" */
1182 /* Limit the next strip */
1187 if ((ymn >= 0) && (n < wn))
1190 for (k = n, d = 1; d <= m; d++)
1192 /* Check grid "d" in strip "n", notice "blockage" */
1193 if (update_view_aux(subject_ptr, ymn, xmn - d, ymn + 1, xmn - d + 1, ymn, xmn - d + 1))
1195 if (n + d >= wn) break;
1198 /* Track most distant "non-blockage" */
1205 /* Limit the next strip */
1211 /*** Step 5 -- Complete the algorithm ***/
1213 /* Update all the new grids */
1214 for (n = 0; n < floor_ptr->view_n; n++)
1216 y = floor_ptr->view_y[n];
1217 x = floor_ptr->view_x[n];
1218 g_ptr = &floor_ptr->grid_array[y][x];
1220 /* Clear the "CAVE_XTRA" flag */
1221 g_ptr->info &= ~(CAVE_XTRA);
1223 /* Update only newly viewed grids */
1224 if (g_ptr->info & (CAVE_TEMP)) continue;
1226 /* Add it to later visual update */
1227 cave_note_and_redraw_later(floor_ptr, g_ptr, y, x);
1230 /* Wipe the old grids, update as needed */
1231 for (n = 0; n < tmp_pos.n; n++)
1235 g_ptr = &floor_ptr->grid_array[y][x];
1237 /* No longer in the array */
1238 g_ptr->info &= ~(CAVE_TEMP);
1240 /* Update only non-viewable grids */
1241 if (g_ptr->info & (CAVE_VIEW)) continue;
1243 /* Add it to later visual update */
1244 cave_redraw_later(floor_ptr, g_ptr, y, x);
1248 subject_ptr->update |= (PU_DELAY_VIS);
1253 * @brief モンスターによる光量状態更新 / Add a square to the changes array
1254 * @param subject_ptr 主観となるクリーチャーの参照ポインタ
1258 static void mon_lite_hack(player_type *subject_ptr, POSITION y, POSITION x)
1264 /* We trust this grid is in bounds */
1265 /* if (!in_bounds2(y, x)) return; */
1267 g_ptr = &subject_ptr->current_floor_ptr->grid_array[y][x];
1269 /* Want a unlit square in view of the player */
1270 if ((g_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
1272 if (!cave_los_grid(g_ptr))
1274 /* Hack -- Prevent monster lite leakage in walls */
1276 /* Horizontal walls between player and a monster */
1277 if (((y < subject_ptr->y) && (y > mon_fy)) || ((y > subject_ptr->y) && (y < mon_fy)))
1279 dpf = subject_ptr->y - mon_fy;
1281 midpoint = mon_fx + ((subject_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
1283 /* Only first wall viewed from mid-x is lit */
1286 if (!cave_los_bold(subject_ptr->current_floor_ptr, y, x + 1)) return;
1288 else if (x > midpoint)
1290 if (!cave_los_bold(subject_ptr->current_floor_ptr, y, x - 1)) return;
1293 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1294 else if (mon_invis) return;
1297 /* Vertical walls between player and a monster */
1298 if (((x < subject_ptr->x) && (x > mon_fx)) || ((x > subject_ptr->x) && (x < mon_fx)))
1300 dpf = subject_ptr->x - mon_fx;
1302 midpoint = mon_fy + ((subject_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
1304 /* Only first wall viewed from mid-y is lit */
1307 if (!cave_los_bold(subject_ptr->current_floor_ptr, y + 1, x)) return;
1309 else if (y > midpoint)
1311 if (!cave_los_bold(subject_ptr->current_floor_ptr, y - 1, x)) return;
1314 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1315 else if (mon_invis) return;
1319 /* We trust tmp_pos.n does not exceed TEMP_MAX */
1322 if (!(g_ptr->info & CAVE_MNDK))
1324 /* Save this square */
1325 tmp_pos.x[tmp_pos.n] = x;
1326 tmp_pos.y[tmp_pos.n] = y;
1333 /* No longer dark */
1334 g_ptr->info &= ~(CAVE_MNDK);
1338 g_ptr->info |= CAVE_MNLT;
1343 * Add a square to the changes array
1345 static void mon_dark_hack(player_type *subject_ptr, POSITION y, POSITION x)
1348 int midpoint, dpf, d;
1350 /* We trust this grid is in bounds */
1351 /* if (!in_bounds2(y, x)) return; */
1353 g_ptr = &subject_ptr->current_floor_ptr->grid_array[y][x];
1355 /* Want a unlit and undarkened square in view of the player */
1356 if ((g_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
1358 if (!cave_los_grid(g_ptr) && !cave_have_flag_grid(g_ptr, FF_PROJECT))
1360 /* Hack -- Prevent monster dark lite leakage in walls */
1362 /* Horizontal walls between player and a monster */
1363 if (((y < subject_ptr->y) && (y > mon_fy)) || ((y > subject_ptr->y) && (y < mon_fy)))
1365 dpf = subject_ptr->y - mon_fy;
1367 midpoint = mon_fx + ((subject_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
1369 /* Only first wall viewed from mid-x is lit */
1372 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;
1374 else if (x > midpoint)
1376 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;
1379 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1380 else if (mon_invis) return;
1383 /* Vertical walls between player and a monster */
1384 if (((x < subject_ptr->x) && (x > mon_fx)) || ((x > subject_ptr->x) && (x < mon_fx)))
1386 dpf = subject_ptr->x - mon_fx;
1388 midpoint = mon_fy + ((subject_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
1390 /* Only first wall viewed from mid-y is lit */
1393 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;
1395 else if (y > midpoint)
1397 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;
1400 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1401 else if (mon_invis) return;
1405 /* We trust tmp_pos.n does not exceed TEMP_MAX */
1407 /* Save this square */
1408 tmp_pos.x[tmp_pos.n] = x;
1409 tmp_pos.y[tmp_pos.n] = y;
1413 g_ptr->info |= CAVE_MNDK;
1418 * Update squares illuminated or darkened by monsters.
1420 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
1421 * denote squares illuminated by monsters.
1423 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
1424 * updating. Only squares in view of the player, whos state
1425 * changes are drawn via lite_spot().
1427 void update_mon_lite(player_type *subject_ptr)
1429 void(*add_mon_lite)(player_type *, POSITION, POSITION);
1431 /* Non-Ninja player in the darkness */
1432 int dis_lim = ((d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !subject_ptr->see_nocto) ?
1433 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
1435 /* Clear all monster lit squares */
1436 floor_type *floor_ptr = subject_ptr->current_floor_ptr;
1437 for (int i = 0; i < floor_ptr->mon_lite_n; i++)
1440 g_ptr = &floor_ptr->grid_array[floor_ptr->mon_lite_y[i]][floor_ptr->mon_lite_x[i]];
1442 /* Set temp or xtra flag */
1443 g_ptr->info |= (g_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
1445 /* Clear monster illumination flag */
1446 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
1449 /* Empty temp list of new squares to lite up */
1452 /* If a monster stops time, don't process */
1453 if (!current_world_ptr->timewalk_m_idx)
1455 monster_type *m_ptr;
1456 monster_race *r_ptr;
1458 /* Loop through monsters, adding newly lit squares to changes list */
1459 for (int i = 1; i < floor_ptr->m_max; i++)
1461 m_ptr = &floor_ptr->m_list[i];
1462 r_ptr = &r_info[m_ptr->r_idx];
1463 if (!monster_is_valid(m_ptr)) continue;
1465 /* Is it too far away? */
1466 if (m_ptr->cdis > dis_lim) continue;
1468 /* Get lite radius */
1471 /* Note the radii are cumulative */
1472 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
1473 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
1474 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
1475 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
1477 /* Exit if has no light */
1483 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;
1484 if (d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) rad = 1;
1485 add_mon_lite = mon_lite_hack;
1490 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!floor_ptr->dun_level && !is_daytime()))) continue;
1491 add_mon_lite = mon_dark_hack;
1492 f_flag = FF_PROJECT;
1493 rad = -rad; /* Use absolute value */
1499 /* Is the monster visible? */
1500 mon_invis = !(floor_ptr->grid_array[mon_fy][mon_fx].info & CAVE_VIEW);
1502 /* The square it is on */
1503 add_mon_lite(subject_ptr, mon_fy, mon_fx);
1505 /* Adjacent squares */
1506 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx);
1507 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx);
1508 add_mon_lite(subject_ptr, mon_fy, mon_fx + 1);
1509 add_mon_lite(subject_ptr, mon_fy, mon_fx - 1);
1510 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx + 1);
1511 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx - 1);
1512 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx + 1);
1513 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx - 1);
1516 if (rad < 2) continue;
1518 /* South of the monster */
1520 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy + 1, mon_fx, f_flag))
1522 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx + 1);
1523 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx);
1524 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx - 1);
1526 g_ptr = &floor_ptr->grid_array[mon_fy + 2][mon_fx];
1529 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1531 add_mon_lite(subject_ptr, mon_fy + 3, mon_fx + 1);
1532 add_mon_lite(subject_ptr, mon_fy + 3, mon_fx);
1533 add_mon_lite(subject_ptr, mon_fy + 3, mon_fx - 1);
1537 /* North of the monster */
1538 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy - 1, mon_fx, f_flag))
1540 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx + 1);
1541 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx);
1542 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx - 1);
1544 g_ptr = &floor_ptr->grid_array[mon_fy - 2][mon_fx];
1547 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1549 add_mon_lite(subject_ptr, mon_fy - 3, mon_fx + 1);
1550 add_mon_lite(subject_ptr, mon_fy - 3, mon_fx);
1551 add_mon_lite(subject_ptr, mon_fy - 3, mon_fx - 1);
1555 /* East of the monster */
1556 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy, mon_fx + 1, f_flag))
1558 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx + 2);
1559 add_mon_lite(subject_ptr, mon_fy, mon_fx + 2);
1560 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx + 2);
1562 g_ptr = &floor_ptr->grid_array[mon_fy][mon_fx + 2];
1565 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1567 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx + 3);
1568 add_mon_lite(subject_ptr, mon_fy, mon_fx + 3);
1569 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx + 3);
1573 /* West of the monster */
1574 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy, mon_fx - 1, f_flag))
1576 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx - 2);
1577 add_mon_lite(subject_ptr, mon_fy, mon_fx - 2);
1578 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx - 2);
1580 g_ptr = &floor_ptr->grid_array[mon_fy][mon_fx - 2];
1583 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1585 add_mon_lite(subject_ptr, mon_fy + 1, mon_fx - 3);
1586 add_mon_lite(subject_ptr, mon_fy, mon_fx - 3);
1587 add_mon_lite(subject_ptr, mon_fy - 1, mon_fx - 3);
1592 if (rad != 3) continue;
1594 /* South-East of the monster */
1595 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy + 1, mon_fx + 1, f_flag))
1597 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx + 2);
1600 /* South-West of the monster */
1601 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy + 1, mon_fx - 1, f_flag))
1603 add_mon_lite(subject_ptr, mon_fy + 2, mon_fx - 2);
1606 /* North-East of the monster */
1607 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy - 1, mon_fx + 1, f_flag))
1609 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx + 2);
1612 /* North-West of the monster */
1613 if (cave_have_flag_bold(subject_ptr->current_floor_ptr, mon_fy - 1, mon_fx - 1, f_flag))
1615 add_mon_lite(subject_ptr, mon_fy - 2, mon_fx - 2);
1620 /* Save end of list of new squares */
1621 s16b end_temp = tmp_pos.n;
1624 * Look at old set flags to see if there are any changes.
1626 for (int i = 0; i < floor_ptr->mon_lite_n; i++)
1628 POSITION fx = floor_ptr->mon_lite_x[i];
1629 POSITION fy = floor_ptr->mon_lite_y[i];
1632 g_ptr = &floor_ptr->grid_array[fy][fx];
1634 if (g_ptr->info & CAVE_TEMP) /* Pervious lit */
1636 /* It it no longer lit? */
1637 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
1639 /* It is now unlit */
1640 /* Add it to later visual update */
1641 cave_note_and_redraw_later(floor_ptr, g_ptr, fy, fx);
1644 else /* Pervious darkened */
1646 /* It it no longer darken? */
1647 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
1649 /* It is now undarken */
1650 /* Add it to later visual update */
1651 cave_note_and_redraw_later(floor_ptr, g_ptr, fy, fx);
1655 /* Add to end of temp array */
1656 tmp_pos.x[tmp_pos.n] = fx;
1657 tmp_pos.y[tmp_pos.n] = fy;
1661 /* Clear the lite array */
1662 floor_ptr->mon_lite_n = 0;
1664 /* Copy the temp array into the lit array lighting the new squares. */
1665 for (int i = 0; i < end_temp; i++)
1667 POSITION fx = tmp_pos.x[i];
1668 POSITION fy = tmp_pos.y[i];
1671 g_ptr = &floor_ptr->grid_array[fy][fx];
1673 if (g_ptr->info & CAVE_MNLT) /* Lit */
1675 /* The is the square newly lit and visible? */
1676 if ((g_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
1679 /* Add it to later visual update */
1680 cave_note_and_redraw_later(floor_ptr, g_ptr, fy, fx);
1685 /* The is the square newly darkened and visible? */
1686 if ((g_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
1688 /* It is now darkened */
1689 /* Add it to later visual update */
1690 cave_note_and_redraw_later(floor_ptr, g_ptr, fy, fx);
1694 /* Save in the monster lit or darkened array */
1695 floor_ptr->mon_lite_x[floor_ptr->mon_lite_n] = fx;
1696 floor_ptr->mon_lite_y[floor_ptr->mon_lite_n] = fy;
1697 floor_ptr->mon_lite_n++;
1700 /* Clear the temp flag for the old lit or darken grids */
1701 for (int i = end_temp; i < tmp_pos.n; i++)
1703 /* We trust this grid is in bounds */
1705 floor_ptr->grid_array[tmp_pos.y[i]][tmp_pos.x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
1710 /* Mega-Hack -- Visual update later */
1711 subject_ptr->update |= (PU_DELAY_VIS);
1713 subject_ptr->monlite = (floor_ptr->grid_array[subject_ptr->y][subject_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
1715 if (!(subject_ptr->special_defense & NINJA_S_STEALTH))
1717 subject_ptr->old_monlite = subject_ptr->monlite;
1721 if (subject_ptr->old_monlite == subject_ptr->monlite)
1723 subject_ptr->old_monlite = subject_ptr->monlite;
1727 if (subject_ptr->monlite)
1729 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow becomes thin."));
1733 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow is restored to its original darkness."));
1736 subject_ptr->old_monlite = subject_ptr->monlite;
1740 void clear_mon_lite(floor_type *floor_ptr)
1742 /* Clear all monster lit squares */
1743 for (int i = 0; i < floor_ptr->mon_lite_n; i++)
1747 g_ptr = &floor_ptr->grid_array[floor_ptr->mon_lite_y[i]][floor_ptr->mon_lite_x[i]];
1749 /* Clear monster illumination flag */
1750 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
1753 /* Empty the array */
1754 floor_ptr->mon_lite_n = 0;