3 #include "floor-events.h"
6 #include "monster-status.h"
8 #include "object-hook.h"
9 #include "player-move.h"
11 #include "player-effects.h"
13 static bool mon_invis;
14 static POSITION mon_fy, mon_fx;
19 msg_print(_("夜が明けた。", "The sun has risen."));
21 if (!p_ptr->wild_mode)
23 /* Hack -- Scan the town */
24 for (y = 0; y < current_floor_ptr->height; y++)
26 for (x = 0; x < current_floor_ptr->width; x++)
28 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
31 g_ptr->info |= (CAVE_GLOW);
33 /* Hack -- Memorize lit grids if allowed */
34 if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
36 /* Hack -- Notice spot */
42 p_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
43 p_ptr->redraw |= (PR_MAP);
44 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
46 if (p_ptr->special_defense & NINJA_S_STEALTH)
48 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
53 void night_falls(void)
56 msg_print(_("日が沈んだ。", "The sun has fallen."));
58 if (!p_ptr->wild_mode)
60 /* Hack -- Scan the town */
61 for (y = 0; y < current_floor_ptr->height; y++)
63 for (x = 0; x < current_floor_ptr->width; x++)
65 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
67 /* Feature code (applying "mimic" field) */
68 feature_type *f_ptr = &f_info[get_feat_mimic(g_ptr)];
70 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
71 !have_flag(f_ptr->flags, FF_ENTRANCE))
74 g_ptr->info &= ~(CAVE_GLOW);
76 if (!have_flag(f_ptr->flags, FF_REMEMBER))
78 /* Forget the normal floor grid */
79 g_ptr->info &= ~(CAVE_MARK);
81 /* Hack -- Notice spot */
87 /* Glow deep lava and building entrances */
88 glow_deep_lava_and_bldg();
92 p_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
93 p_ptr->redraw |= (PR_MAP);
94 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
96 if (p_ptr->special_defense & NINJA_S_STEALTH)
98 if (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
104 * @brief 現在フロアに残っている敵モンスターの数を返す /
105 * @return 現在の敵モンスターの数
107 MONSTER_NUMBER count_all_hostile_monsters(void)
110 MONSTER_NUMBER number_mon = 0;
112 for (x = 0; x < current_floor_ptr->width; ++x)
114 for (y = 0; y < current_floor_ptr->height; ++y)
116 MONSTER_IDX m_idx = current_floor_ptr->grid_array[y][x].m_idx;
118 if (m_idx > 0 && is_hostile(¤t_floor_ptr->m_list[m_idx]))
131 * ダンジョンの雰囲気を計算するための非線形基準値 / Dungeon rating is no longer linear
133 #define RATING_BOOST(delta) (delta * delta + 50 * delta)
136 * @brief ダンジョンの雰囲気を算出する。
137 * / Examine all monsters and unidentified objects, and get the feeling of current dungeon floor
138 * @return 算出されたダンジョンの雰囲気ランク
140 byte get_dungeon_feeling(void)
146 /* Hack -- no feeling in the town */
147 if (!current_floor_ptr->dun_level) return 0;
149 /* Examine each monster */
150 for (i = 1; i < m_max; i++)
152 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
155 if (!monster_is_valid(m_ptr)) continue;
157 if (is_pet(m_ptr)) continue;
159 r_ptr = &r_info[m_ptr->r_idx];
161 if (r_ptr->flags1 & (RF1_UNIQUE))
163 /* Nearly out-of-depth unique monsters */
164 if (r_ptr->level + 10 > current_floor_ptr->dun_level)
166 /* Boost rating by twice delta-depth */
167 delta += (r_ptr->level + 10 - current_floor_ptr->dun_level) * 2 * base;
172 /* Out-of-depth monsters */
173 if (r_ptr->level > current_floor_ptr->dun_level)
175 /* Boost rating by delta-depth */
176 delta += (r_ptr->level - current_floor_ptr->dun_level) * base;
180 /* Unusually crowded monsters get a little bit of rating boost */
181 if (r_ptr->flags1 & RF1_FRIENDS)
183 if (5 <= get_monster_crowd_number(i)) delta += 1;
187 if (2 <= get_monster_crowd_number(i)) delta += 1;
191 rating += RATING_BOOST(delta);
194 /* Examine each unidentified object */
195 for (i = 1; i < o_max; i++)
197 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
198 object_kind *k_ptr = &k_info[o_ptr->k_idx];
201 /* Skip dead objects */
202 if (!o_ptr->k_idx) 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 > current_floor_ptr->dun_level)
248 /* Rating increase */
249 delta += (k_ptr->level - current_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;
269 * @brief ダンジョンの雰囲気を更新し、変化があった場合メッセージを表示する
270 * / Update dungeon feeling, and announce it if changed
273 void update_dungeon_feeling(void)
279 /* No feeling on the surface */
280 if (!current_floor_ptr->dun_level) return;
282 /* No feeling in the arena */
283 if (p_ptr->inside_battle) return;
285 /* Extract delay time */
286 delay = MAX(10, 150 - p_ptr->skill_fos) * (150 - current_floor_ptr->dun_level) * TURNS_PER_TICK / 100;
288 /* Not yet felt anything */
289 if (current_world_ptr->game_turn < p_ptr->feeling_turn + delay && !cheat_xtra) return;
291 /* Extract quest number (if any) */
292 quest_num = quest_number(current_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 new_feeling = get_dungeon_feeling();
304 /* Remember last time updated */
305 p_ptr->feeling_turn = current_world_ptr->game_turn;
308 if (p_ptr->feeling == new_feeling) return;
310 /* Dungeon feeling is changed */
311 p_ptr->feeling = new_feeling;
313 /* Announce feeling */
316 select_floor_music();
318 /* Update the level indicator */
319 p_ptr->redraw |= (PR_DEPTH);
321 if (disturb_minor) disturb(FALSE, FALSE);
326 * Glow deep lava and building entrances in the floor
328 void glow_deep_lava_and_bldg(void)
330 POSITION y, x, yy, xx;
334 /* Not in the darkness dungeon */
335 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) return;
337 for (y = 0; y < current_floor_ptr->height; y++)
339 for (x = 0; x < current_floor_ptr->width; x++)
341 g_ptr = ¤t_floor_ptr->grid_array[y][x];
343 /* Feature code (applying "mimic" field) */
345 if (have_flag(f_info[get_feat_mimic(g_ptr)].flags, FF_GLOW))
347 for (i = 0; i < 9; i++)
351 if (!in_bounds2(yy, xx)) continue;
352 current_floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
358 /* Update the view and lite */
359 p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
361 p_ptr->redraw |= (PR_MAP);
365 * Actually erase the entire "lite" array, redrawing every grid
367 void forget_lite(void)
373 if (!current_floor_ptr->lite_n) return;
376 for (i = 0; i < current_floor_ptr->lite_n; i++)
378 y = current_floor_ptr->lite_y[i];
379 x = current_floor_ptr->lite_x[i];
381 /* Forget "LITE" flag */
382 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
384 /* lite_spot(y, x); Perhaps don't need? */
388 current_floor_ptr->lite_n = 0;
394 * Update the set of grids "illuminated" by the player's lite.
396 * This routine needs to use the results of "update_view()"
398 * Note that "blindness" does NOT affect "torch lite". Be careful!
400 * We optimize most lites (all non-artifact lites) by using "obvious"
401 * facts about the results of "small" lite radius, and we attempt to
402 * list the "nearby" grids before the more "distant" ones in the
403 * array of torch-lit grids.
405 * We assume that "radius zero" lite is in fact no lite at all.
407 * Torch Lantern Artifacts
417 void update_lite(void)
420 POSITION x, y, min_x, max_x, min_y, max_y;
421 POSITION p = p_ptr->cur_lite;
424 /*** Special case ***/
427 /* Hack -- Player has no lite */
430 /* Forget the old lite */
431 /* forget_lite(); Perhaps don't need? */
433 /* Add it to later visual update */
434 cave_redraw_later(¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x], p_ptr->y, p_ptr->x);
438 /*** Save the old "lite" grids for later ***/
441 for (i = 0; i < current_floor_ptr->lite_n; i++)
443 y = current_floor_ptr->lite_y[i];
444 x = current_floor_ptr->lite_x[i];
446 /* Mark the grid as not "lite" */
447 current_floor_ptr->grid_array[y][x].info &= ~(CAVE_LITE);
449 /* Mark the grid as "seen" */
450 current_floor_ptr->grid_array[y][x].info |= (CAVE_TEMP);
452 /* Add it to the "seen" set */
453 tmp_pos.y[tmp_pos.n] = y;
454 tmp_pos.x[tmp_pos.n] = x;
459 current_floor_ptr->lite_n = 0;
462 /*** Collect the new "lite" grids ***/
464 /* Radius 1 -- torch radius */
468 cave_lite_hack(p_ptr->y, p_ptr->x);
471 cave_lite_hack(p_ptr->y + 1, p_ptr->x);
472 cave_lite_hack(p_ptr->y - 1, p_ptr->x);
473 cave_lite_hack(p_ptr->y, p_ptr->x + 1);
474 cave_lite_hack(p_ptr->y, p_ptr->x - 1);
477 cave_lite_hack(p_ptr->y + 1, p_ptr->x + 1);
478 cave_lite_hack(p_ptr->y + 1, p_ptr->x - 1);
479 cave_lite_hack(p_ptr->y - 1, p_ptr->x + 1);
480 cave_lite_hack(p_ptr->y - 1, p_ptr->x - 1);
483 /* Radius 2 -- lantern radius */
486 /* South of the player */
487 if (cave_los_bold(p_ptr->y + 1, p_ptr->x))
489 cave_lite_hack(p_ptr->y + 2, p_ptr->x);
490 cave_lite_hack(p_ptr->y + 2, p_ptr->x + 1);
491 cave_lite_hack(p_ptr->y + 2, p_ptr->x - 1);
494 /* North of the player */
495 if (cave_los_bold(p_ptr->y - 1, p_ptr->x))
497 cave_lite_hack(p_ptr->y - 2, p_ptr->x);
498 cave_lite_hack(p_ptr->y - 2, p_ptr->x + 1);
499 cave_lite_hack(p_ptr->y - 2, p_ptr->x - 1);
502 /* East of the player */
503 if (cave_los_bold(p_ptr->y, p_ptr->x + 1))
505 cave_lite_hack(p_ptr->y, p_ptr->x + 2);
506 cave_lite_hack(p_ptr->y + 1, p_ptr->x + 2);
507 cave_lite_hack(p_ptr->y - 1, p_ptr->x + 2);
510 /* West of the player */
511 if (cave_los_bold(p_ptr->y, p_ptr->x - 1))
513 cave_lite_hack(p_ptr->y, p_ptr->x - 2);
514 cave_lite_hack(p_ptr->y + 1, p_ptr->x - 2);
515 cave_lite_hack(p_ptr->y - 1, p_ptr->x - 2);
519 /* Radius 3+ -- artifact radius */
524 /* Paranoia -- see "LITE_MAX" */
527 /* South-East of the player */
528 if (cave_los_bold(p_ptr->y + 1, p_ptr->x + 1))
530 cave_lite_hack(p_ptr->y + 2, p_ptr->x + 2);
533 /* South-West of the player */
534 if (cave_los_bold(p_ptr->y + 1, p_ptr->x - 1))
536 cave_lite_hack(p_ptr->y + 2, p_ptr->x - 2);
539 /* North-East of the player */
540 if (cave_los_bold(p_ptr->y - 1, p_ptr->x + 1))
542 cave_lite_hack(p_ptr->y - 2, p_ptr->x + 2);
545 /* North-West of the player */
546 if (cave_los_bold(p_ptr->y - 1, p_ptr->x - 1))
548 cave_lite_hack(p_ptr->y - 2, p_ptr->x - 2);
552 min_y = p_ptr->y - p;
553 if (min_y < 0) min_y = 0;
556 max_y = p_ptr->y + p;
557 if (max_y > current_floor_ptr->height - 1) max_y = current_floor_ptr->height - 1;
560 min_x = p_ptr->x - p;
561 if (min_x < 0) min_x = 0;
564 max_x = p_ptr->x + p;
565 if (max_x > current_floor_ptr->width - 1) max_x = current_floor_ptr->width - 1;
567 /* Scan the maximal box */
568 for (y = min_y; y <= max_y; y++)
570 for (x = min_x; x <= max_x; x++)
572 int dy = (p_ptr->y > y) ? (p_ptr->y - y) : (y - p_ptr->y);
573 int dx = (p_ptr->x > x) ? (p_ptr->x - x) : (x - p_ptr->x);
575 /* Skip the "central" grids (above) */
576 if ((dy <= 2) && (dx <= 2)) continue;
578 /* Hack -- approximate the distance */
579 d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
581 /* Skip distant grids */
584 /* Viewable, nearby, grids get "torch lit" */
585 if (current_floor_ptr->grid_array[y][x].info & CAVE_VIEW)
587 /* This grid is "torch lit" */
588 cave_lite_hack(y, x);
595 /*** Complete the algorithm ***/
597 /* Draw the new grids */
598 for (i = 0; i < current_floor_ptr->lite_n; i++)
600 y = current_floor_ptr->lite_y[i];
601 x = current_floor_ptr->lite_x[i];
603 g_ptr = ¤t_floor_ptr->grid_array[y][x];
605 /* Update fresh grids */
606 if (g_ptr->info & (CAVE_TEMP)) continue;
608 /* Add it to later visual update */
609 cave_note_and_redraw_later(g_ptr, y, x);
613 for (i = 0; i < tmp_pos.n; i++)
618 g_ptr = ¤t_floor_ptr->grid_array[y][x];
620 /* No longer in the array */
621 g_ptr->info &= ~(CAVE_TEMP);
623 /* Update stale grids */
624 if (g_ptr->info & (CAVE_LITE)) continue;
626 /* Add it to later visual update */
627 cave_redraw_later(g_ptr, y, x);
633 /* Mega-Hack -- Visual update later */
634 p_ptr->update |= (PU_DELAY_VIS);
639 * Clear the viewable space
641 void forget_view(void)
648 if (!current_floor_ptr->view_n) return;
651 for (i = 0; i < current_floor_ptr->view_n; i++)
653 POSITION y = current_floor_ptr->view_y[i];
654 POSITION x = current_floor_ptr->view_x[i];
655 g_ptr = ¤t_floor_ptr->grid_array[y][x];
657 /* Forget that the grid is viewable */
658 g_ptr->info &= ~(CAVE_VIEW);
660 /* if (!panel_contains(y, x)) continue; */
662 /* Update the screen */
663 /* lite_spot(y, x); Perhaps don't need? */
667 current_floor_ptr->view_n = 0;
673 * Helper function for "update_view()" below
675 * We are checking the "viewability" of grid (y,x) by the player.
677 * This function assumes that (y,x) is legal (i.e. on the map).
679 * Grid (y1,x1) is on the "diagonal" between (p_ptr->y,p_ptr->x) and (y,x)
680 * Grid (y2,x2) is "adjacent", also between (p_ptr->y,p_ptr->x) and (y,x).
682 * Note that we are using the "CAVE_XTRA" field for marking grids as
683 * "easily viewable". This bit is cleared at the end of "update_view()".
685 * This function adds (y,x) to the "viewable set" if necessary.
687 * This function now returns "TRUE" if vision is "blocked" by grid (y,x).
689 static bool update_view_aux(POSITION y, POSITION x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
691 bool f1, f2, v1, v2, z1, z2, wall;
698 /* Access the grids */
699 g1_c_ptr = ¤t_floor_ptr->grid_array[y1][x1];
700 g2_c_ptr = ¤t_floor_ptr->grid_array[y2][x2];
703 /* Check for walls */
704 f1 = (cave_los_grid(g1_c_ptr));
705 f2 = (cave_los_grid(g2_c_ptr));
707 /* Totally blocked by physical walls */
708 if (!f1 && !f2) return (TRUE);
711 /* Check for visibility */
712 v1 = (f1 && (g1_c_ptr->info & (CAVE_VIEW)));
713 v2 = (f2 && (g2_c_ptr->info & (CAVE_VIEW)));
715 /* Totally blocked by "unviewable neighbors" */
716 if (!v1 && !v2) return (TRUE);
718 g_ptr = ¤t_floor_ptr->grid_array[y][x];
721 /* Check for walls */
722 wall = (!cave_los_grid(g_ptr));
725 /* Check the "ease" of visibility */
726 z1 = (v1 && (g1_c_ptr->info & (CAVE_XTRA)));
727 z2 = (v2 && (g2_c_ptr->info & (CAVE_XTRA)));
729 /* Hack -- "easy" plus "easy" yields "easy" */
732 g_ptr->info |= (CAVE_XTRA);
734 cave_view_hack(g_ptr, y, x);
739 /* Hack -- primary "easy" yields "viewed" */
742 cave_view_hack(g_ptr, y, x);
747 /* Hack -- "view" plus "view" yields "view" */
750 /* g_ptr->info |= (CAVE_XTRA); */
752 cave_view_hack(g_ptr, y, x);
758 /* Mega-Hack -- the "los()" function works poorly on walls */
761 cave_view_hack(g_ptr, y, x);
767 /* Hack -- check line of sight */
768 if (los(p_ptr->y, p_ptr->x, y, x))
770 cave_view_hack(g_ptr, y, x);
776 /* Assume no line of sight. */
782 * Calculate the viewable space
784 * 1: Process the player
785 * 1a: The player is always (easily) viewable
786 * 2: Process the diagonals
787 * 2a: The diagonals are (easily) viewable up to the first wall
788 * 2b: But never go more than 2/3 of the "full" distance
789 * 3: Process the main axes
790 * 3a: The main axes are (easily) viewable up to the first wall
791 * 3b: But never go more than the "full" distance
792 * 4: Process sequential "strips" in each of the eight octants
793 * 4a: Each strip runs along the previous strip
794 * 4b: The main axes are "previous" to the first strip
795 * 4c: Process both "sides" of each "direction" of each strip
796 * 4c1: Each side aborts as soon as possible
797 * 4c2: Each side tells the next strip how far it has to check
799 * Note that the octant processing involves some pretty interesting
800 * observations involving when a grid might possibly be viewable from
801 * a given grid, and on the order in which the strips are processed.
803 * Note the use of the mathematical facts shown below, which derive
804 * from the fact that (1 < sqrt(2) < 1.5), and that the length of the
805 * hypotenuse of a right triangle is primarily determined by the length
806 * of the longest side, when one side is small, and is strictly less
807 * than one-and-a-half times as long as the longest side when both of
808 * the sides are large.
810 * if (manhatten(dy,dx) < R) then (hypot(dy,dx) < R)
811 * if (manhatten(dy,dx) > R*3/2) then (hypot(dy,dx) > R)
813 * hypot(dy,dx) is approximated by (dx+dy+MAX(dx,dy)) / 2
815 * These observations are important because the calculation of the actual
816 * value of "hypot(dx,dy)" is extremely expensive, involving square roots,
817 * while for small values (up to about 20 or so), the approximations above
818 * are correct to within an error of at most one grid or so.
820 * Observe the use of "full" and "over" in the code below, and the use of
821 * the specialized calculation involving "limit", all of which derive from
822 * the observations given above. Basically, we note that the "circle" of
823 * view is completely contained in an "octagon" whose bounds are easy to
824 * determine, and that only a few steps are needed to derive the actual
825 * bounds of the circle given the bounds of the octagon.
827 * Note that by skipping all the grids in the corners of the octagon, we
828 * place an upper limit on the number of grids in the field of view, given
829 * that "full" is never more than 20. Of the 1681 grids in the "square" of
830 * view, only about 1475 of these are in the "octagon" of view, and even
831 * fewer are in the "circle" of view, so 1500 or 1536 is more than enough
832 * entries to completely contain the actual field of view.
834 * Note also the care taken to prevent "running off the map". The use of
835 * explicit checks on the "validity" of the "diagonal", and the fact that
836 * the loops are never allowed to "leave" the map, lets "update_view_aux()"
837 * use the optimized "cave_los_bold()" macro, and to avoid the overhead
838 * of multiple checks on the validity of grids.
840 * Note the "optimizations" involving the "se","sw","ne","nw","es","en",
841 * "ws","wn" variables. They work like this: While travelling down the
842 * south-bound strip just to the east of the main south axis, as soon as
843 * we get to a grid which does not "transmit" viewing, if all of the strips
844 * preceding us (in this case, just the main axis) had terminated at or before
845 * the same point, then we can stop, and reset the "max distance" to ourself.
846 * So, each strip (named by major axis plus offset, thus "se" in this case)
847 * maintains a "blockage" variable, initialized during the main axis step,
848 * and checks it whenever a blockage is observed. After processing each
849 * strip as far as the previous strip told us to process, the next strip is
850 * told not to go farther than the current strip's farthest viewable grid,
851 * unless open space is still available. This uses the "k" variable.
853 * Note the use of "inline" macros for efficiency. The "cave_los_grid()"
854 * macro is a replacement for "cave_los_bold()" which takes a pointer to
855 * a grid instead of its location. The "cave_view_hack()" macro is a
856 * chunk of code which adds the given location to the "view" array if it
857 * is not already there, using both the actual location and a pointer to
858 * the grid. See above.
860 * By the way, the purpose of this code is to reduce the dependancy on the
861 * "los()" function which is slow, and, in some cases, not very accurate.
863 * It is very possible that I am the only person who fully understands this
864 * function, and for that I am truly sorry, but efficiency was very important
865 * and the "simple" version of this function was just not fast enough. I am
866 * more than willing to replace this function with a simpler one, if it is
867 * equally efficient, and especially willing if the new function happens to
868 * derive "reverse-line-of-sight" at the same time, since currently monsters
869 * just use an optimized hack of "you see me, so I see you", and then use the
870 * actual "projectable()" function to check spell attacks.
872 void update_view(void)
877 int se, sw, ne, nw, es, en, ws, wn;
881 POSITION y_max = current_floor_ptr->height - 1;
882 POSITION x_max = current_floor_ptr->width - 1;
889 if (view_reduce_view && !current_floor_ptr->dun_level)
891 /* Full radius (10) */
892 full = MAX_SIGHT / 2;
894 /* Octagon factor (15) */
895 over = MAX_SIGHT * 3 / 4;
901 /* Full radius (20) */
904 /* Octagon factor (30) */
905 over = MAX_SIGHT * 3 / 2;
909 /*** Step 0 -- Begin ***/
911 /* Save the old "view" grids for later */
912 for (n = 0; n < current_floor_ptr->view_n; n++)
914 y = current_floor_ptr->view_y[n];
915 x = current_floor_ptr->view_x[n];
916 g_ptr = ¤t_floor_ptr->grid_array[y][x];
918 /* Mark the grid as not in "view" */
919 g_ptr->info &= ~(CAVE_VIEW);
921 /* Mark the grid as "seen" */
922 g_ptr->info |= (CAVE_TEMP);
924 /* Add it to the "seen" set */
925 tmp_pos.y[tmp_pos.n] = y;
926 tmp_pos.x[tmp_pos.n] = x;
930 /* Start over with the "view" array */
931 current_floor_ptr->view_n = 0;
933 /*** Step 1 -- adjacent grids ***/
935 /* Now start on the player */
938 g_ptr = ¤t_floor_ptr->grid_array[y][x];
940 /* Assume the player grid is easily viewable */
941 g_ptr->info |= (CAVE_XTRA);
943 /* Assume the player grid is viewable */
944 cave_view_hack(g_ptr, y, x);
947 /*** Step 2 -- Major Diagonals ***/
952 /* Scan south-east */
953 for (d = 1; d <= z; d++)
955 g_ptr = ¤t_floor_ptr->grid_array[y + d][x + d];
956 g_ptr->info |= (CAVE_XTRA);
957 cave_view_hack(g_ptr, y + d, x + d);
958 if (!cave_los_grid(g_ptr)) break;
961 /* Scan south-west */
962 for (d = 1; d <= z; d++)
964 g_ptr = ¤t_floor_ptr->grid_array[y + d][x - d];
965 g_ptr->info |= (CAVE_XTRA);
966 cave_view_hack(g_ptr, y + d, x - d);
967 if (!cave_los_grid(g_ptr)) break;
970 /* Scan north-east */
971 for (d = 1; d <= z; d++)
973 g_ptr = ¤t_floor_ptr->grid_array[y - d][x + d];
974 g_ptr->info |= (CAVE_XTRA);
975 cave_view_hack(g_ptr, y - d, x + d);
976 if (!cave_los_grid(g_ptr)) break;
979 /* Scan north-west */
980 for (d = 1; d <= z; d++)
982 g_ptr = ¤t_floor_ptr->grid_array[y - d][x - d];
983 g_ptr->info |= (CAVE_XTRA);
984 cave_view_hack(g_ptr, y - d, x - d);
985 if (!cave_los_grid(g_ptr)) break;
988 /*** Step 3 -- major axes ***/
991 for (d = 1; d <= full; d++)
993 g_ptr = ¤t_floor_ptr->grid_array[y + d][x];
994 g_ptr->info |= (CAVE_XTRA);
995 cave_view_hack(g_ptr, y + d, x);
996 if (!cave_los_grid(g_ptr)) break;
999 /* Initialize the "south strips" */
1003 for (d = 1; d <= full; d++)
1005 g_ptr = ¤t_floor_ptr->grid_array[y - d][x];
1006 g_ptr->info |= (CAVE_XTRA);
1007 cave_view_hack(g_ptr, y - d, x);
1008 if (!cave_los_grid(g_ptr)) break;
1011 /* Initialize the "north strips" */
1015 for (d = 1; d <= full; d++)
1017 g_ptr = ¤t_floor_ptr->grid_array[y][x + d];
1018 g_ptr->info |= (CAVE_XTRA);
1019 cave_view_hack(g_ptr, y, x + d);
1020 if (!cave_los_grid(g_ptr)) break;
1023 /* Initialize the "east strips" */
1027 for (d = 1; d <= full; d++)
1029 g_ptr = ¤t_floor_ptr->grid_array[y][x - d];
1030 g_ptr->info |= (CAVE_XTRA);
1031 cave_view_hack(g_ptr, y, x - d);
1032 if (!cave_los_grid(g_ptr)) break;
1035 /* Initialize the "west strips" */
1039 /*** Step 4 -- Divide each "octant" into "strips" ***/
1041 /* Now check each "diagonal" (in parallel) */
1042 for (n = 1; n <= over / 2; n++)
1044 POSITION ypn, ymn, xpn, xmn;
1046 /* Acquire the "bounds" of the maximal circle */
1048 if (z > full - n) z = full - n;
1049 while ((z + n + (n >> 1)) > full) z--;
1052 /* Access the four diagonal grids */
1062 /* Maximum distance */
1063 m = MIN(z, y_max - ypn);
1066 if ((xpn <= x_max) && (n < se))
1069 for (k = n, d = 1; d <= m; d++)
1071 /* Check grid "d" in strip "n", notice "blockage" */
1072 if (update_view_aux(ypn + d, xpn, ypn + d - 1, xpn - 1, ypn + d - 1, xpn))
1074 if (n + d >= se) break;
1077 /* Track most distant "non-blockage" */
1084 /* Limit the next strip */
1089 if ((xmn >= 0) && (n < sw))
1092 for (k = n, d = 1; d <= m; d++)
1094 /* Check grid "d" in strip "n", notice "blockage" */
1095 if (update_view_aux(ypn + d, xmn, ypn + d - 1, xmn + 1, ypn + d - 1, xmn))
1097 if (n + d >= sw) break;
1100 /* Track most distant "non-blockage" */
1107 /* Limit the next strip */
1116 /* Maximum distance */
1120 if ((xpn <= x_max) && (n < ne))
1123 for (k = n, d = 1; d <= m; d++)
1125 /* Check grid "d" in strip "n", notice "blockage" */
1126 if (update_view_aux(ymn - d, xpn, ymn - d + 1, xpn - 1, ymn - d + 1, xpn))
1128 if (n + d >= ne) break;
1131 /* Track most distant "non-blockage" */
1138 /* Limit the next strip */
1143 if ((xmn >= 0) && (n < nw))
1146 for (k = n, d = 1; d <= m; d++)
1148 /* Check grid "d" in strip "n", notice "blockage" */
1149 if (update_view_aux(ymn - d, xmn, ymn - d + 1, xmn + 1, ymn - d + 1, xmn))
1151 if (n + d >= nw) break;
1154 /* Track most distant "non-blockage" */
1161 /* Limit the next strip */
1170 /* Maximum distance */
1171 m = MIN(z, x_max - xpn);
1174 if ((ypn <= x_max) && (n < es))
1177 for (k = n, d = 1; d <= m; d++)
1179 /* Check grid "d" in strip "n", notice "blockage" */
1180 if (update_view_aux(ypn, xpn + d, ypn - 1, xpn + d - 1, ypn, xpn + d - 1))
1182 if (n + d >= es) break;
1185 /* Track most distant "non-blockage" */
1192 /* Limit the next strip */
1197 if ((ymn >= 0) && (n < en))
1200 for (k = n, d = 1; d <= m; d++)
1202 /* Check grid "d" in strip "n", notice "blockage" */
1203 if (update_view_aux(ymn, xpn + d, ymn + 1, xpn + d - 1, ymn, xpn + d - 1))
1205 if (n + d >= en) break;
1208 /* Track most distant "non-blockage" */
1215 /* Limit the next strip */
1224 /* Maximum distance */
1228 if ((ypn <= y_max) && (n < ws))
1231 for (k = n, d = 1; d <= m; d++)
1233 /* Check grid "d" in strip "n", notice "blockage" */
1234 if (update_view_aux(ypn, xmn - d, ypn - 1, xmn - d + 1, ypn, xmn - d + 1))
1236 if (n + d >= ws) break;
1239 /* Track most distant "non-blockage" */
1246 /* Limit the next strip */
1251 if ((ymn >= 0) && (n < wn))
1254 for (k = n, d = 1; d <= m; d++)
1256 /* Check grid "d" in strip "n", notice "blockage" */
1257 if (update_view_aux(ymn, xmn - d, ymn + 1, xmn - d + 1, ymn, xmn - d + 1))
1259 if (n + d >= wn) break;
1262 /* Track most distant "non-blockage" */
1269 /* Limit the next strip */
1276 /*** Step 5 -- Complete the algorithm ***/
1278 /* Update all the new grids */
1279 for (n = 0; n < current_floor_ptr->view_n; n++)
1281 y = current_floor_ptr->view_y[n];
1282 x = current_floor_ptr->view_x[n];
1283 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1285 /* Clear the "CAVE_XTRA" flag */
1286 g_ptr->info &= ~(CAVE_XTRA);
1288 /* Update only newly viewed grids */
1289 if (g_ptr->info & (CAVE_TEMP)) continue;
1291 /* Add it to later visual update */
1292 cave_note_and_redraw_later(g_ptr, y, x);
1295 /* Wipe the old grids, update as needed */
1296 for (n = 0; n < tmp_pos.n; n++)
1300 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1302 /* No longer in the array */
1303 g_ptr->info &= ~(CAVE_TEMP);
1305 /* Update only non-viewable grids */
1306 if (g_ptr->info & (CAVE_VIEW)) continue;
1308 /* Add it to later visual update */
1309 cave_redraw_later(g_ptr, y, x);
1315 /* Mega-Hack -- Visual update later */
1316 p_ptr->update |= (PU_DELAY_VIS);
1321 * Add a square to the changes array
1323 static void mon_lite_hack(POSITION y, POSITION x)
1329 /* We trust this grid is in bounds */
1330 /* if (!in_bounds2(y, x)) return; */
1332 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1334 /* Want a unlit square in view of the player */
1335 if ((g_ptr->info & (CAVE_MNLT | CAVE_VIEW)) != CAVE_VIEW) return;
1337 if (!cave_los_grid(g_ptr))
1339 /* Hack -- Prevent monster lite leakage in walls */
1341 /* Horizontal walls between player and a monster */
1342 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
1344 dpf = p_ptr->y - mon_fy;
1346 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
1348 /* Only first wall viewed from mid-x is lit */
1351 if (!cave_los_bold(y, x + 1)) return;
1353 else if (x > midpoint)
1355 if (!cave_los_bold(y, x - 1)) return;
1358 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1359 else if (mon_invis) return;
1362 /* Vertical walls between player and a monster */
1363 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
1365 dpf = p_ptr->x - mon_fx;
1367 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
1369 /* Only first wall viewed from mid-y is lit */
1372 if (!cave_los_bold(y + 1, x)) return;
1374 else if (y > midpoint)
1376 if (!cave_los_bold(y - 1, x)) return;
1379 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1380 else if (mon_invis) return;
1384 /* We trust tmp_pos.n does not exceed TEMP_MAX */
1387 if (!(g_ptr->info & CAVE_MNDK))
1389 /* Save this square */
1390 tmp_pos.x[tmp_pos.n] = x;
1391 tmp_pos.y[tmp_pos.n] = y;
1398 /* No longer dark */
1399 g_ptr->info &= ~(CAVE_MNDK);
1403 g_ptr->info |= CAVE_MNLT;
1408 * Add a square to the changes array
1410 static void mon_dark_hack(POSITION y, POSITION x)
1413 int midpoint, dpf, d;
1415 /* We trust this grid is in bounds */
1416 /* if (!in_bounds2(y, x)) return; */
1418 g_ptr = ¤t_floor_ptr->grid_array[y][x];
1420 /* Want a unlit and undarkened square in view of the player */
1421 if ((g_ptr->info & (CAVE_LITE | CAVE_MNLT | CAVE_MNDK | CAVE_VIEW)) != CAVE_VIEW) return;
1423 if (!cave_los_grid(g_ptr) && !cave_have_flag_grid(g_ptr, FF_PROJECT))
1425 /* Hack -- Prevent monster dark lite leakage in walls */
1427 /* Horizontal walls between player and a monster */
1428 if (((y < p_ptr->y) && (y > mon_fy)) || ((y > p_ptr->y) && (y < mon_fy)))
1430 dpf = p_ptr->y - mon_fy;
1432 midpoint = mon_fx + ((p_ptr->x - mon_fx) * ABS(d)) / ABS(dpf);
1434 /* Only first wall viewed from mid-x is lit */
1437 if (!cave_los_bold(y, x + 1) && !cave_have_flag_bold(y, x + 1, FF_PROJECT)) return;
1439 else if (x > midpoint)
1441 if (!cave_los_bold(y, x - 1) && !cave_have_flag_bold(y, x - 1, FF_PROJECT)) return;
1444 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1445 else if (mon_invis) return;
1448 /* Vertical walls between player and a monster */
1449 if (((x < p_ptr->x) && (x > mon_fx)) || ((x > p_ptr->x) && (x < mon_fx)))
1451 dpf = p_ptr->x - mon_fx;
1453 midpoint = mon_fy + ((p_ptr->y - mon_fy) * ABS(d)) / ABS(dpf);
1455 /* Only first wall viewed from mid-y is lit */
1458 if (!cave_los_bold(y + 1, x) && !cave_have_flag_bold(y + 1, x, FF_PROJECT)) return;
1460 else if (y > midpoint)
1462 if (!cave_los_bold(y - 1, x) && !cave_have_flag_bold(y - 1, x, FF_PROJECT)) return;
1465 /* Hack XXX XXX - Is it a wall and monster not in LOS? */
1466 else if (mon_invis) return;
1470 /* We trust tmp_pos.n does not exceed TEMP_MAX */
1472 /* Save this square */
1473 tmp_pos.x[tmp_pos.n] = x;
1474 tmp_pos.y[tmp_pos.n] = y;
1478 g_ptr->info |= CAVE_MNDK;
1482 * Update squares illuminated or darkened by monsters.
1484 * Hack - use the CAVE_ROOM flag (renamed to be CAVE_MNLT) to
1485 * denote squares illuminated by monsters.
1487 * The CAVE_TEMP and CAVE_XTRA flag are used to store the state during the
1488 * updating. Only squares in view of the player, whos state
1489 * changes are drawn via lite_spot().
1491 void update_mon_lite(void)
1497 void(*add_mon_lite)(POSITION, POSITION);
1502 /* Non-Ninja player in the darkness */
1503 int dis_lim = ((d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto) ?
1504 (MAX_SIGHT / 2 + 1) : (MAX_SIGHT + 3);
1506 /* Clear all monster lit squares */
1507 for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
1510 g_ptr = ¤t_floor_ptr->grid_array[current_floor_ptr->mon_lite_y[i]][current_floor_ptr->mon_lite_x[i]];
1512 /* Set temp or xtra flag */
1513 g_ptr->info |= (g_ptr->info & CAVE_MNLT) ? CAVE_TEMP : CAVE_XTRA;
1515 /* Clear monster illumination flag */
1516 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
1519 /* Empty temp list of new squares to lite up */
1522 /* If a monster stops time, don't process */
1523 if (!current_world_ptr->timewalk_m_idx)
1525 monster_type *m_ptr;
1526 monster_race *r_ptr;
1528 /* Loop through monsters, adding newly lit squares to changes list */
1529 for (i = 1; i < m_max; i++)
1531 m_ptr = ¤t_floor_ptr->m_list[i];
1532 r_ptr = &r_info[m_ptr->r_idx];
1533 if (!monster_is_valid(m_ptr)) continue;
1535 /* Is it too far away? */
1536 if (m_ptr->cdis > dis_lim) continue;
1538 /* Get lite radius */
1541 /* Note the radii are cumulative */
1542 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_SELF_LITE_1)) rad++;
1543 if (r_ptr->flags7 & (RF7_HAS_LITE_2 | RF7_SELF_LITE_2)) rad += 2;
1544 if (r_ptr->flags7 & (RF7_HAS_DARK_1 | RF7_SELF_DARK_1)) rad--;
1545 if (r_ptr->flags7 & (RF7_HAS_DARK_2 | RF7_SELF_DARK_2)) rad -= 2;
1547 /* Exit if has no light */
1551 if (!(r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) && (MON_CSLEEP(m_ptr) || (!current_floor_ptr->dun_level && is_daytime()) || p_ptr->inside_battle)) continue;
1552 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) rad = 1;
1553 add_mon_lite = mon_lite_hack;
1558 if (!(r_ptr->flags7 & (RF7_SELF_DARK_1 | RF7_SELF_DARK_2)) && (MON_CSLEEP(m_ptr) || (!current_floor_ptr->dun_level && !is_daytime()))) continue;
1559 add_mon_lite = mon_dark_hack;
1560 f_flag = FF_PROJECT;
1561 rad = -rad; /* Use absolute value */
1567 /* Is the monster visible? */
1568 mon_invis = !(current_floor_ptr->grid_array[mon_fy][mon_fx].info & CAVE_VIEW);
1570 /* The square it is on */
1571 add_mon_lite(mon_fy, mon_fx);
1573 /* Adjacent squares */
1574 add_mon_lite(mon_fy + 1, mon_fx);
1575 add_mon_lite(mon_fy - 1, mon_fx);
1576 add_mon_lite(mon_fy, mon_fx + 1);
1577 add_mon_lite(mon_fy, mon_fx - 1);
1578 add_mon_lite(mon_fy + 1, mon_fx + 1);
1579 add_mon_lite(mon_fy + 1, mon_fx - 1);
1580 add_mon_lite(mon_fy - 1, mon_fx + 1);
1581 add_mon_lite(mon_fy - 1, mon_fx - 1);
1586 /* South of the monster */
1587 if (cave_have_flag_bold(mon_fy + 1, mon_fx, f_flag))
1589 add_mon_lite(mon_fy + 2, mon_fx + 1);
1590 add_mon_lite(mon_fy + 2, mon_fx);
1591 add_mon_lite(mon_fy + 2, mon_fx - 1);
1593 g_ptr = ¤t_floor_ptr->grid_array[mon_fy + 2][mon_fx];
1596 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1598 add_mon_lite(mon_fy + 3, mon_fx + 1);
1599 add_mon_lite(mon_fy + 3, mon_fx);
1600 add_mon_lite(mon_fy + 3, mon_fx - 1);
1604 /* North of the monster */
1605 if (cave_have_flag_bold(mon_fy - 1, mon_fx, f_flag))
1607 add_mon_lite(mon_fy - 2, mon_fx + 1);
1608 add_mon_lite(mon_fy - 2, mon_fx);
1609 add_mon_lite(mon_fy - 2, mon_fx - 1);
1611 g_ptr = ¤t_floor_ptr->grid_array[mon_fy - 2][mon_fx];
1614 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1616 add_mon_lite(mon_fy - 3, mon_fx + 1);
1617 add_mon_lite(mon_fy - 3, mon_fx);
1618 add_mon_lite(mon_fy - 3, mon_fx - 1);
1622 /* East of the monster */
1623 if (cave_have_flag_bold(mon_fy, mon_fx + 1, f_flag))
1625 add_mon_lite(mon_fy + 1, mon_fx + 2);
1626 add_mon_lite(mon_fy, mon_fx + 2);
1627 add_mon_lite(mon_fy - 1, mon_fx + 2);
1629 g_ptr = ¤t_floor_ptr->grid_array[mon_fy][mon_fx + 2];
1632 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1634 add_mon_lite(mon_fy + 1, mon_fx + 3);
1635 add_mon_lite(mon_fy, mon_fx + 3);
1636 add_mon_lite(mon_fy - 1, mon_fx + 3);
1640 /* West of the monster */
1641 if (cave_have_flag_bold(mon_fy, mon_fx - 1, f_flag))
1643 add_mon_lite(mon_fy + 1, mon_fx - 2);
1644 add_mon_lite(mon_fy, mon_fx - 2);
1645 add_mon_lite(mon_fy - 1, mon_fx - 2);
1647 g_ptr = ¤t_floor_ptr->grid_array[mon_fy][mon_fx - 2];
1650 if ((rad == 3) && cave_have_flag_grid(g_ptr, f_flag))
1652 add_mon_lite(mon_fy + 1, mon_fx - 3);
1653 add_mon_lite(mon_fy, mon_fx - 3);
1654 add_mon_lite(mon_fy - 1, mon_fx - 3);
1662 /* South-East of the monster */
1663 if (cave_have_flag_bold(mon_fy + 1, mon_fx + 1, f_flag))
1665 add_mon_lite(mon_fy + 2, mon_fx + 2);
1668 /* South-West of the monster */
1669 if (cave_have_flag_bold(mon_fy + 1, mon_fx - 1, f_flag))
1671 add_mon_lite(mon_fy + 2, mon_fx - 2);
1674 /* North-East of the monster */
1675 if (cave_have_flag_bold(mon_fy - 1, mon_fx + 1, f_flag))
1677 add_mon_lite(mon_fy - 2, mon_fx + 2);
1680 /* North-West of the monster */
1681 if (cave_have_flag_bold(mon_fy - 1, mon_fx - 1, f_flag))
1683 add_mon_lite(mon_fy - 2, mon_fx - 2);
1689 /* Save end of list of new squares */
1690 end_temp = tmp_pos.n;
1693 * Look at old set flags to see if there are any changes.
1695 for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
1697 fx = current_floor_ptr->mon_lite_x[i];
1698 fy = current_floor_ptr->mon_lite_y[i];
1700 /* We trust this grid is in bounds */
1703 g_ptr = ¤t_floor_ptr->grid_array[fy][fx];
1705 if (g_ptr->info & CAVE_TEMP) /* Pervious lit */
1707 /* It it no longer lit? */
1708 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNLT)) == CAVE_VIEW)
1710 /* It is now unlit */
1711 /* Add it to later visual update */
1712 cave_note_and_redraw_later(g_ptr, fy, fx);
1715 else /* Pervious darkened */
1717 /* It it no longer darken? */
1718 if ((g_ptr->info & (CAVE_VIEW | CAVE_MNDK)) == CAVE_VIEW)
1720 /* It is now undarken */
1721 /* Add it to later visual update */
1722 cave_note_and_redraw_later(g_ptr, fy, fx);
1726 /* Add to end of temp array */
1727 tmp_pos.x[tmp_pos.n] = fx;
1728 tmp_pos.y[tmp_pos.n] = fy;
1732 /* Clear the lite array */
1733 current_floor_ptr->mon_lite_n = 0;
1735 /* Copy the temp array into the lit array lighting the new squares. */
1736 for (i = 0; i < end_temp; i++)
1741 /* We trust this grid is in bounds */
1744 g_ptr = ¤t_floor_ptr->grid_array[fy][fx];
1746 if (g_ptr->info & CAVE_MNLT) /* Lit */
1748 /* The is the square newly lit and visible? */
1749 if ((g_ptr->info & (CAVE_VIEW | CAVE_TEMP)) == CAVE_VIEW)
1752 /* Add it to later visual update */
1753 cave_note_and_redraw_later(g_ptr, fy, fx);
1758 /* The is the square newly darkened and visible? */
1759 if ((g_ptr->info & (CAVE_VIEW | CAVE_XTRA)) == CAVE_VIEW)
1761 /* It is now darkened */
1762 /* Add it to later visual update */
1763 cave_note_and_redraw_later(g_ptr, fy, fx);
1767 /* Save in the monster lit or darkened array */
1768 current_floor_ptr->mon_lite_x[current_floor_ptr->mon_lite_n] = fx;
1769 current_floor_ptr->mon_lite_y[current_floor_ptr->mon_lite_n] = fy;
1770 current_floor_ptr->mon_lite_n++;
1773 /* Clear the temp flag for the old lit or darken grids */
1774 for (i = end_temp; i < tmp_pos.n; i++)
1776 /* We trust this grid is in bounds */
1778 current_floor_ptr->grid_array[tmp_pos.y[i]][tmp_pos.x[i]].info &= ~(CAVE_TEMP | CAVE_XTRA);
1781 /* Finished with tmp_pos.n */
1784 /* Mega-Hack -- Visual update later */
1785 p_ptr->update |= (PU_DELAY_VIS);
1787 p_ptr->monlite = (current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_MNLT) ? TRUE : FALSE;
1789 if (p_ptr->special_defense & NINJA_S_STEALTH)
1791 if (p_ptr->old_monlite != p_ptr->monlite)
1795 msg_print(_("影の覆いが薄れた気がする。", "Your mantle of shadow become thin."));
1799 msg_print(_("影の覆いが濃くなった!", "Your mantle of shadow restored its original darkness."));
1803 p_ptr->old_monlite = p_ptr->monlite;
1806 void clear_mon_lite(void)
1811 /* Clear all monster lit squares */
1812 for (i = 0; i < current_floor_ptr->mon_lite_n; i++)
1815 g_ptr = ¤t_floor_ptr->grid_array[current_floor_ptr->mon_lite_y[i]][current_floor_ptr->mon_lite_x[i]];
1817 /* Clear monster illumination flag */
1818 g_ptr->info &= ~(CAVE_MNLT | CAVE_MNDK);
1821 /* Empty the array */
1822 current_floor_ptr->mon_lite_n = 0;