3 * @brief ¥â¥ó¥¹¥¿¡¼¤ÎÆü쵻ǽ¤È°ÜÆ°½èÍý/ Monster spells and movement
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7 * This software may be copied and distributed for educational, research,\n
8 * and not for profit purposes provided that this copyright and statement\n
9 * are included in all such copies. Other copyrights may also apply.\n
10 * 2014 Deskull rearranged comment for Doxygen.\n
12 * This file has several additions to it by Keldon Jones (keldon@umr.edu)
13 * to improve the general quality of the AI (version 0.1.1).
18 #define SPEAK_CHANCE 8
23 * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨¤ËÀ᤹ܶ¤ë¤¿¤á¤ÎÊý¸þ¤ò·è¤á¤ë /
24 * Calculate the direction to the next enemy
25 * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
26 * @param mm °ÜÆ°¤¹¤ë¤Ù¤Êý³ÑID¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
27 * @return Êý¸þ¤¬³ÎÄꤷ¤¿¾ì¹çTRUE¡¢À᤹ܶ¤ëŨ¤¬¤½¤â¤½¤â¤¤¤Ê¤¤¾ì¹çFALSE¤òÊÖ¤¹
29 static bool get_enemy_dir(int m_idx, int *mm)
37 monster_type *m_ptr = &m_list[m_idx];
38 monster_race *r_ptr = &r_info[m_ptr->r_idx];
42 if (riding_t_m_idx && player_bold(m_ptr->fy, m_ptr->fx))
44 y = m_list[riding_t_m_idx].fy;
45 x = m_list[riding_t_m_idx].fx;
47 else if (is_pet(m_ptr) && pet_t_m_idx)
49 y = m_list[pet_t_m_idx].fy;
50 x = m_list[pet_t_m_idx].fx;
54 if (p_ptr->inside_battle)
56 start = randint1(m_max-1)+m_max;
57 if(randint0(2)) plus = -1;
59 else start = m_max + 1;
61 /* Scan thru all monsters */
62 for (i = start; ((i < start + m_max) && (i > start - m_max)); i+=plus)
64 int dummy = (i % m_max);
69 t_ptr = &m_list[t_idx];
71 /* The monster itself isn't a target */
72 if (t_ptr == m_ptr) continue;
74 /* Paranoia -- Skip dead monsters */
75 if (!t_ptr->r_idx) continue;
79 /* Hack -- only fight away from player */
80 if (p_ptr->pet_follow_distance < 0)
82 /* No fighting near player */
83 if (t_ptr->cdis <= (0 - p_ptr->pet_follow_distance))
88 /* Hack -- no fighting away from player */
89 else if ((m_ptr->cdis < t_ptr->cdis) &&
90 (t_ptr->cdis > p_ptr->pet_follow_distance))
95 if (r_ptr->aaf < t_ptr->cdis) continue;
98 /* Monster must be 'an enemy' */
99 if (!are_enemies(m_ptr, t_ptr)) continue;
101 /* Monster must be projectable if we can't pass through walls */
102 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) ||
103 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding)))
105 if (!in_disintegration_range(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
109 if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
112 /* OK -- we've got a target */
118 if (!x && !y) return FALSE;
121 /* Extract the direction */
126 if ((y < 0) && (x == 0))
133 else if ((y > 0) && (x == 0))
140 else if ((x > 0) && (y == 0))
147 else if ((x < 0) && (y == 0))
154 else if ((y < 0) && (x < 0))
161 else if ((y < 0) && (x > 0))
168 else if ((y > 0) && (x < 0))
175 else if ((y > 0) && (x > 0))
182 /* Found a monster */
188 * @brief ¥â¥ó¥¹¥¿¡¼¤¬Å¨¥â¥ó¥¹¥¿¡¼¤Ë¹Ô¤¦ÂÇ·â½èÍý /
189 * Hack, based on mon_take_hit... perhaps all monster attacks on other monsters should use this?
190 * @param m_idx ÌÜɸ¤È¤Ê¤ë¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
191 * @param dam ¥À¥á¡¼¥¸ÎÌ
192 * @param fear ÌÜɸ¤È¤Ê¤ë¥â¥ó¥¹¥¿¡¼¤Î¶²¹²¾õÂÖ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
193 * @param note ÌÜɸ¥â¥ó¥¹¥¿¡¼¤¬»àË´¤·¤¿¾ì¹ç¤ÎÆÃÊÌ¥á¥Ã¥»¡¼¥¸(NULL¤Ê¤é¤Ðɸ½àɽ¼¨¤ò¹Ô¤¦)
194 * @param who ÂÇ·â¤ò¹Ô¤Ã¤¿¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
197 void mon_take_hit_mon(int m_idx, int dam, bool *fear, cptr note, int who)
199 monster_type *m_ptr = &m_list[m_idx];
201 monster_race *r_ptr = &r_info[m_ptr->r_idx];
205 bool seen = is_seen(m_ptr);
207 /* Can the player be aware of this attack? */
208 bool known = (m_ptr->cdis <= MAX_SIGHT);
210 /* Extract monster name */
211 monster_desc(m_name, m_ptr, 0);
213 /* Redraw (later) if needed */
216 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
217 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
221 (void)set_monster_csleep(m_idx, 0);
223 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 1);
225 if (MON_INVULNER(m_ptr) && randint0(PENETRATE_INVULNERABILITY))
230 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
232 msg_format("%^s is unharmed.", m_name);
240 if (r_ptr->flagsr & RFR_RES_ALL)
245 if((dam == 0) && one_in_(3)) dam = 1;
252 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
254 msg_format("%^s is unharmed.", m_name);
265 /* It is dead now... or is it? */
268 if (((r_ptr->flags1 & (RF1_UNIQUE | RF1_QUESTOR)) ||
269 (r_ptr->flags7 & RF7_NAZGUL)) &&
270 !p_ptr->inside_battle)
277 if (!monster_living(r_ptr))
288 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
289 /* Unseen death by normal attack */
294 /* Death by special attack */
298 msg_format("%^s%s", m_name, note);
300 msg_format("%^s%s", m_name, note);
304 /* Death by normal attack -- nonliving monster */
305 else if (!monster_living(r_ptr))
308 msg_format("%^s¤ÏÇ˲õ¤µ¤ì¤¿¡£", m_name);
310 msg_format("%^s is destroyed.", m_name);
314 /* Death by normal attack -- living monster */
318 msg_format("%^s¤Ï»¦¤µ¤ì¤¿¡£", m_name);
320 msg_format("%^s is killed.", m_name);
326 monster_gain_exp(who, m_ptr->r_idx);
328 /* Generate treasure */
329 monster_death(m_idx, FALSE);
331 /* Delete the monster */
332 delete_monster_idx(m_idx);
337 /* Monster is dead */
344 /* Mega-Hack -- Pain cancels fear */
345 if (MON_MONFEAR(m_ptr) && (dam > 0))
348 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam / 4)))
355 /* Sometimes a monster gets scared by damage */
356 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & RF3_NO_FEAR))
358 /* Percentage of fully healthy */
359 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
362 * Run (sometimes) if at 10% or less of max hit points,
363 * or (usually) when hit for half its current hit points
365 if (((percentage <= 10) && (randint0(10) < percentage)) ||
366 ((dam >= m_ptr->hp) && (randint0(100) < 80)))
368 /* Hack -- note fear */
371 /* XXX XXX XXX Hack -- Add some timed fear */
372 (void)set_monster_monfear(m_idx, (randint1(10) +
373 (((dam >= m_ptr->hp) && (percentage > 7)) ?
374 20 : ((11 - percentage) * 5))));
378 #endif /* ALLOW_FEAR */
380 if ((dam > 0) && !is_pet(m_ptr) && !is_friendly(m_ptr) && (who != m_idx))
382 if (is_pet(&m_list[who]) && !player_bold(m_ptr->target_y, m_ptr->target_x))
384 set_target(m_ptr, m_list[who].fy, m_list[who].fx);
388 if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
392 /* Extract monster name */
393 monster_desc(m_name, m_ptr, 0);
395 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
396 if (rakuba((dam > 200) ? 200 : dam, FALSE))
399 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
401 msg_format("You have thrown off from %s!", m_name);
412 * @brief ¥â¥ó¥¹¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤«¤éƨÁö¤¹¤ë¤«¤É¤¦¤«¤òÊÖ¤¹ /
413 * Returns whether a given monster will try to run from the player.
414 * @param m_idx ƨÁö¤¹¤ë¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
415 * @return ¥â¥ó¥¹¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤«¤éƨÁö¤¹¤ë¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
417 * Monsters will attempt to avoid very powerful players. See below.\n
419 * Because this function is called so often, little details are important\n
420 * for efficiency. Like not using "mod" or "div" when possible. And\n
421 * attempting to check the conditions in an optimal order. Note that\n
422 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.\n
424 * Note that this function is responsible for about one to five percent\n
425 * of the processor use in normal conditions...\n
427 static int mon_will_run(int m_idx)
429 monster_type *m_ptr = &m_list[m_idx];
433 monster_race *r_ptr = &r_info[m_ptr->r_idx];
442 /* Friends can be commanded to avoid the player */
445 /* Are we trying to avoid the player? */
446 return ((p_ptr->pet_follow_distance < 0) &&
447 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
450 /* Keep monsters from running too far away */
451 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
453 /* All "afraid" monsters will run away */
454 if (MON_MONFEAR(m_ptr)) return (TRUE);
458 /* Nearby monsters will not become terrified */
459 if (m_ptr->cdis <= 5) return (FALSE);
461 /* Examine player power (level) */
464 /* Examine monster power (level plus morale) */
465 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
467 /* Optimize extreme cases below */
468 if (m_lev > p_lev + 4) return (FALSE);
469 if (m_lev + 4 <= p_lev) return (TRUE);
471 /* Examine player health */
475 /* Examine monster health */
477 m_mhp = m_ptr->maxhp;
479 /* Prepare to optimize the calculation */
480 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
481 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
483 /* Strong players scare strong monsters */
484 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
488 /* Assume no terror */
494 * @brief ¥â¥ó¥¹¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤Ë¸þ¤±¤Æ±óµ÷Î¥¹¶·â¤ò¹Ô¤¦¤³¤È¤¬²Äǽ¤Ê¥Þ¥¹¤òÁöºº¤¹¤ë /
495 * Search spell castable grid
496 * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
497 * @param yp Ŭ¤·¤¿¥Þ¥¹¤ÎYºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
498 * @param xp Ŭ¤·¤¿¥Þ¥¹¤ÎXºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
499 * @return ͸ú¤Ê¥Þ¥¹¤¬¤¢¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
501 static bool get_moves_aux2(int m_idx, int *yp, int *xp)
503 int i, y, x, y1, x1, best = 999;
506 bool can_open_door = FALSE;
509 monster_type *m_ptr = &m_list[m_idx];
510 monster_race *r_ptr = &r_info[m_ptr->r_idx];
512 /* Monster location */
516 /* Monster can already cast spell to player */
517 if (projectable(y1, x1, py, px)) return (FALSE);
519 /* Set current grid cost */
520 now_cost = cave[y1][x1].cost;
521 if (now_cost == 0) now_cost = 999;
523 /* Can monster bash or open doors? */
524 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
526 can_open_door = TRUE;
529 /* Check nearby grids, diagonals first */
530 for (i = 7; i >= 0; i--)
534 /* Get the location */
538 /* Ignore locations off of edge */
539 if (!in_bounds2(y, x)) continue;
541 /* Simply move to player */
542 if (player_bold(y, x)) return (FALSE);
548 /* Monster cannot kill or pass walls */
549 if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) || ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))))
551 if (cost == 0) continue;
552 if (!can_open_door && is_closed_door(c_ptr->feat)) continue;
555 /* Hack -- for kill or pass wall monster.. */
556 if (cost == 0) cost = 998;
558 if (now_cost < cost) continue;
560 if (!projectable(y, x, py, px)) continue;
562 /* Accept louder sounds */
563 if (best < cost) continue;
566 (*yp) = y1 + ddy_ddd[i];
567 (*xp) = x1 + ddx_ddd[i];
570 /* No legal move (?) */
571 if (best == 999) return (FALSE);
579 * @brief ¥â¥ó¥¹¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤Ë¸þ¤±¤ÆÀ᤹ܶ¤ë¤³¤È¤¬²Äǽ¤Ê¥Þ¥¹¤òÁöºº¤¹¤ë /
580 * Choose the "best" direction for "flowing"
581 * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
582 * @param yp °ÜÆ°Àè¤Î¥Þ¥¹¤ÎYºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
583 * @param xp °ÜÆ°Àè¤Î¥Þ¥¹¤ÎXºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
584 * @param no_flow ¥â¥ó¥¹¥¿¡¼¤ËFLOW¥Õ¥é¥°¤¬·Ð¤Ã¤Æ¤¤¤Ê¤¤¾õÂÖ¤ÇTRUE
585 * @return ͸ú¤Ê¥Þ¥¹¤¬¤¢¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
587 * Note that ghosts and rock-eaters are never allowed to "flow",\n
588 * since they should move directly towards the player.\n
590 * Prefer "non-diagonal" directions, but twiddle them a little\n
591 * to angle slightly towards the player's actual location.\n
593 * Allow very perceptive monsters to track old "spoor" left by\n
594 * previous locations occupied by the player. This will tend\n
595 * to have monsters end up either near the player or on a grid\n
596 * recently occupied by the player (and left via "teleport").\n
598 * Note that if "smell" is turned on, all monsters get vicious.\n
600 * Also note that teleporting away from a location will cause\n
601 * the monsters who were chasing you to converge on that location\n
602 * as long as you are still near enough to "annoy" them without\n
603 * being close enough to chase directly. I have no idea what will\n
604 * happen if you combine "smell" with low "aaf" values.\n
606 static bool get_moves_aux(int m_idx, int *yp, int *xp, bool no_flow)
608 int i, y, x, y1, x1, best;
611 bool use_scent = FALSE;
613 monster_type *m_ptr = &m_list[m_idx];
614 monster_race *r_ptr = &r_info[m_ptr->r_idx];
616 /* Can monster cast attack spell? */
617 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
618 r_ptr->flags5 & (RF5_ATTACK_MASK) ||
619 r_ptr->flags6 & (RF6_ATTACK_MASK))
621 /* Can move spell castable grid? */
622 if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
625 /* Monster can't flow */
626 if (no_flow) return (FALSE);
628 /* Monster can go through rocks */
629 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) return (FALSE);
630 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding)) return (FALSE);
632 /* Monster location */
636 /* Hack -- Player can see us, run towards him */
637 if (player_has_los_bold(y1, x1) && projectable(py, px, y1, x1)) return (FALSE);
640 c_ptr = &cave[y1][x1];
642 /* If we can hear noises, advance towards them */
648 /* Otherwise, try to follow a scent trail */
649 else if (c_ptr->when)
652 if (cave[py][px].when - c_ptr->when > 127) return (FALSE);
658 /* Otherwise, advance blindly */
664 /* Check nearby grids, diagonals first */
665 for (i = 7; i >= 0; i--)
667 /* Get the location */
671 /* Ignore locations off of edge */
672 if (!in_bounds2(y, x)) continue;
676 /* We're following a scent trail */
679 int when = c_ptr->when;
681 /* Accept younger scent */
682 if (best > when) continue;
686 /* We're using sound */
691 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
693 else cost = c_ptr->cost;
695 /* Accept louder sounds */
696 if ((cost == 0) || (best < cost)) continue;
700 /* Hack -- Save the "twiddled" location */
701 (*yp) = py + 16 * ddy_ddd[i];
702 (*xp) = px + 16 * ddx_ddd[i];
705 /* No legal move (?) */
706 if (best == 999 || best == 0) return (FALSE);
714 * @brief ¥â¥ó¥¹¥¿¡¼¤¬¥×¥ì¥¤¥ä¡¼¤«¤éƨÁö¤¹¤ë¤³¤È¤¬²Äǽ¤Ê¥Þ¥¹¤òÁöºº¤¹¤ë /
715 * Provide a location to flee to, but give the player a wide berth.
716 * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
717 * @param yp °ÜÆ°Àè¤Î¥Þ¥¹¤ÎYºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
718 * @param xp °ÜÆ°Àè¤Î¥Þ¥¹¤ÎXºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
719 * @return ͸ú¤Ê¥Þ¥¹¤¬¤¢¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
721 * A monster may wish to flee to a location that is behind the player,\n
722 * but instead of heading directly for it, the monster should "swerve"\n
723 * around the player so that he has a smaller chance of getting hit.\n
725 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
727 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
731 monster_type *m_ptr = &m_list[m_idx];
733 /* Monster location */
737 /* Desired destination */
741 /* Check nearby grids, diagonals first */
742 for (i = 7; i >= 0; i--)
746 /* Get the location */
750 /* Ignore locations off of edge */
751 if (!in_bounds2(y, x)) continue;
753 /* Don't move toward player */
754 /* if (cave[y][x].dist < 3) continue; */ /* Hmm.. Need it? */
756 /* Calculate distance of this grid from our destination */
757 dis = distance(y, x, y1, x1);
759 /* Score this grid */
760 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
762 /* No negative scores */
765 /* Ignore lower scores */
766 if (s < score) continue;
768 /* Save the score and time */
771 /* Save the location */
776 /* No legal move (?) */
777 if (score == -1) return (FALSE);
788 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
791 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
792 * offsets of all the locations with a distance of n from a central point,
793 * with an offset of (0,0) indicating no more offsets at this distance.
795 * This is, of course, fairly unreadable, but it eliminates multiple loops
796 * from the previous version.
798 * It is probably better to replace these arrays with code to compute
799 * the relevant arrays, even if the storage is pre-allocated in hard
800 * coded sizes. At the very least, code should be included which is
801 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
803 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
805 * These arrays could be combined into two big arrays, using sub-arrays
806 * to hold the offsets and lengths of each portion of the sub-arrays, and
807 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
811 static sint d_off_y_0[] =
814 static sint d_off_x_0[] =
818 static sint d_off_y_1[] =
819 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
821 static sint d_off_x_1[] =
822 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
825 static sint d_off_y_2[] =
826 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
828 static sint d_off_x_2[] =
829 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
832 static sint d_off_y_3[] =
833 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
836 static sint d_off_x_3[] =
837 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
841 static sint d_off_y_4[] =
842 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
843 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
845 static sint d_off_x_4[] =
846 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
847 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
850 static sint d_off_y_5[] =
851 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
852 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
855 static sint d_off_x_5[] =
856 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
857 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
861 static sint d_off_y_6[] =
862 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
863 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
866 static sint d_off_x_6[] =
867 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
868 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
869 -3, 2, 3, -1, 0, 1, 0 };
872 static sint d_off_y_7[] =
873 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
874 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
875 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
877 static sint d_off_x_7[] =
878 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
879 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
880 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
884 static sint d_off_y_8[] =
885 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
886 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
887 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
890 static sint d_off_x_8[] =
891 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
892 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
893 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
897 static sint d_off_y_9[] =
898 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
899 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
900 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
901 7, 8, 8, 8, 8, 9, 9, 9, 0 };
903 static sint d_off_x_9[] =
904 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
905 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
906 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
907 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
910 static sint *dist_offsets_y[10] =
912 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
913 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
916 static sint *dist_offsets_x[10] =
918 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
919 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
923 * @brief ¥â¥ó¥¹¥¿¡¼¤¬Æ¨¤²¹þ¤á¤ë°ÂÁ´¤ÊÃÏÅÀ¤òÊÖ¤¹ /
924 * Choose a "safe" location near a monster for it to run toward.
925 * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
926 * @param yp °ÜÆ°Àè¤Î¥Þ¥¹¤ÎYºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
927 * @param xp °ÜÆ°Àè¤Î¥Þ¥¹¤ÎXºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
928 * @return ͸ú¤Ê¥Þ¥¹¤¬¤¢¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
930 * A location is "safe" if it can be reached quickly and the player\n
931 * is not able to fire into it (it isn't a "clean shot"). So, this will\n
932 * cause monsters to "duck" behind walls. Hopefully, monsters will also\n
933 * try to run towards corridor openings if they are in a room.\n
935 * This function may take lots of CPU time if lots of monsters are\n
938 * Return TRUE if a safe location is available.\n
940 static bool find_safety(int m_idx, int *yp, int *xp)
942 monster_type *m_ptr = &m_list[m_idx];
947 int y, x, dy, dx, d, dis, i;
948 int gy = 0, gx = 0, gdis = 0;
955 /* Start with adjacent locations, spread further */
956 for (d = 1; d < 10; d++)
958 /* Get the lists of points with a distance d from (fx, fy) */
959 y_offsets = dist_offsets_y[d];
960 x_offsets = dist_offsets_x[d];
962 /* Check the locations */
963 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
965 i++, dx = x_offsets[i], dy = y_offsets[i])
970 /* Skip illegal locations */
971 if (!in_bounds(y, x)) continue;
975 /* Skip locations in a wall */
976 if (!monster_can_cross_terrain(c_ptr->feat, &r_info[m_ptr->r_idx], (m_idx == p_ptr->riding) ? CEM_RIDING : 0)) continue;
978 /* Check for "availability" (if monsters can flow) */
979 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
981 /* Ignore grids very far from the player */
982 if (c_ptr->dist == 0) continue;
984 /* Ignore too-distant grids */
985 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
988 /* Check for absence of shot (more or less) */
989 if (!projectable(py, px, y, x))
991 /* Calculate distance from player */
992 dis = distance(y, x, py, px);
994 /* Remember if further than previous */
1004 /* Check for success */
1011 /* Found safe place */
1022 * @brief ¥â¥ó¥¹¥¿¡¼¤¬±£¤ìÀø¤á¤ëÃÏÅÀ¤òÊÖ¤¹ /
1023 * Choose a good hiding place near a monster for it to run toward.
1024 * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
1025 * @param yp °ÜÆ°Àè¤Î¥Þ¥¹¤ÎYºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
1026 * @param xp °ÜÆ°Àè¤Î¥Þ¥¹¤ÎXºÂɸ¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
1027 * @return ͸ú¤Ê¥Þ¥¹¤¬¤¢¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
1029 * Pack monsters will use this to "ambush" the player and lure him out\n
1030 * of corridors into open space so they can swarm him.\n
1032 * Return TRUE if a good location is available.\n
1034 static bool find_hiding(int m_idx, int *yp, int *xp)
1036 monster_type *m_ptr = &m_list[m_idx];
1037 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1042 int y, x, dy, dx, d, dis, i;
1043 int gy = 0, gx = 0, gdis = 999;
1045 sint *y_offsets, *x_offsets;
1047 /* Start with adjacent locations, spread further */
1048 for (d = 1; d < 10; d++)
1050 /* Get the lists of points with a distance d from (fx, fy) */
1051 y_offsets = dist_offsets_y[d];
1052 x_offsets = dist_offsets_x[d];
1054 /* Check the locations */
1055 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
1057 i++, dx = x_offsets[i], dy = y_offsets[i])
1062 /* Skip illegal locations */
1063 if (!in_bounds(y, x)) continue;
1065 /* Skip occupied locations */
1066 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
1068 /* Check for hidden, available grid */
1069 if (!projectable(py, px, y, x) && clean_shot(fy, fx, y, x, FALSE))
1071 /* Calculate distance from player */
1072 dis = distance(y, x, py, px);
1074 /* Remember if closer than previous */
1075 if (dis < gdis && dis >= 2)
1084 /* Check for success */
1091 /* Found good place */
1102 * @brief ¥â¥ó¥¹¥¿¡¼¤Î°ÜÆ°Êý¸þ¤òÊÖ¤¹ /
1103 * Choose "logical" directions for monster movement
1104 * @param m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
1105 * @param mm °ÜÆ°Êý¸þ¤òÊÖ¤¹Êý¸þID¤Î»²¾È¥Ý¥¤¥ó¥¿
1106 * @return ͸úÊý¸þ¤¬¤¢¤Ã¤¿¾ì¹çTRUE¤òÊÖ¤¹
1108 static bool get_moves(int m_idx, int *mm)
1110 monster_type *m_ptr = &m_list[m_idx];
1111 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1117 bool will_run = mon_will_run(m_idx);
1119 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1120 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall));
1122 /* Counter attack to an enemy monster */
1123 if (!will_run && m_ptr->target_y)
1125 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
1127 /* The monster must be an enemy, and in LOS */
1129 are_enemies(m_ptr, &m_list[t_m_idx]) &&
1130 los(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
1131 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1133 /* Extract the "pseudo-direction" */
1134 y = m_ptr->fy - m_ptr->target_y;
1135 x = m_ptr->fx - m_ptr->target_x;
1140 if (!done && !will_run && is_hostile(m_ptr) &&
1141 (r_ptr->flags1 & RF1_FRIENDS) &&
1142 ((los(m_ptr->fy, m_ptr->fx, py, px) && projectable(m_ptr->fy, m_ptr->fx, py, px)) ||
1143 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1146 * Animal packs try to get the player out of corridors
1147 * (...unless they can move through walls -- TY)
1149 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1150 !(r_ptr->flags2 & RF2_KILL_WALL))
1154 /* Count room grids next to player */
1155 for (i = 0; i < 8; i++)
1157 int xx = px + ddx_ddd[i];
1158 int yy = py + ddy_ddd[i];
1160 if (!in_bounds2(yy, xx)) continue;
1162 c_ptr = &cave[yy][xx];
1165 if (monster_can_cross_terrain(c_ptr->feat, r_ptr, 0))
1167 /* One more room grid */
1171 if (cave[py][px].info & CAVE_ROOM) room -= 2;
1172 if (!r_ptr->flags4 && !r_ptr->flags5 && !r_ptr->flags6) room -= 2;
1174 /* Not in a room and strong player */
1175 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
1176 (p_ptr->mhp + p_ptr->msp))
1178 /* Find hiding place */
1179 if (find_hiding(m_idx, &y, &x)) done = TRUE;
1183 /* Monster groups try to surround the player */
1184 if (!done && (cave[m_ptr->fy][m_ptr->fx].dist < 3))
1188 /* Find an empty square near the player to fill */
1189 for (i = 0; i < 8; i++)
1191 /* Pick squares near player (semi-randomly) */
1192 y2 = py + ddy_ddd[(m_idx + i) & 7];
1193 x2 = px + ddx_ddd[(m_idx + i) & 7];
1195 /* Already there? */
1196 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
1198 /* Attack the player */
1205 if (!in_bounds2(y2, x2)) continue;
1207 /* Ignore filled grids */
1208 if (!monster_can_enter(y2, x2, r_ptr, 0)) continue;
1210 /* Try to fill this hole */
1214 /* Extract the new "pseudo-direction" */
1225 /* Flow towards the player */
1226 (void)get_moves_aux(m_idx, &y2, &x2, no_flow);
1228 /* Extract the "pseudo-direction" */
1235 /* Apply fear if possible and necessary */
1236 if (is_pet(m_ptr) && will_run)
1238 /* XXX XXX Not very "smart" */
1243 if (!done && will_run)
1248 /* Try to find safe place */
1249 if (find_safety(m_idx, &y, &x))
1251 /* Attempt to avoid the player */
1254 /* Adjust movement */
1255 if (get_fear_moves_aux(m_idx, &y, &x)) done = TRUE;
1261 /* This is not a very "smart" method XXX XXX */
1269 /* Check for no move */
1270 if (!x && !y) return (FALSE);
1273 /* Extract the "absolute distances" */
1277 /* Do something weird */
1278 if (y < 0) move_val += 8;
1279 if (x > 0) move_val += 4;
1281 /* Prevent the diamond maneuvre */
1282 if (ay > (ax << 1)) move_val += 2;
1283 else if (ax > (ay << 1)) move_val++;
1285 /* Extract some directions */
1430 /* Wants to move... */
1436 * @brief ¥â¥ó¥¹¥¿¡¼¤«¤éŨ¥â¥ó¥¹¥¿¡¼¤Ø¤ÎÌ¿ÃæȽÄê
1437 * @param power ÂÇ·â°À¤Ë¤è¤ë´ðËÜÌ¿ÃæÃÍ
1438 * @param level ¹¶·â¦¥â¥ó¥¹¥¿¡¼¤Î¥ì¥Ù¥ë
1439 * @param ac ÌÜɸ¥â¥ó¥¹¥¿¡¼¤ÎAC
1440 * @param stun ¹¶·â¦¥â¥ó¥¹¥¿¡¼¤¬Û¯Û°¾õÂ֤ʤéTRUE¤òÊÖ¤¹
1441 * @return Ì¿Ãæ¤Ê¤é¤ÐTRUE¤òÊÖ¤¹
1443 static int check_hit2(int power, int level, int ac, int stun)
1447 /* Percentile dice */
1450 if (stun && one_in_(2)) return FALSE;
1452 /* Hack -- Always miss or hit */
1453 if (k < 10) return (k < 5);
1455 /* Calculate the "attack quality" */
1456 i = (power + (level * 3));
1458 /* Power and Level compete against Armor */
1459 if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
1466 #define BLOW_EFFECT_TYPE_NONE 0
1467 #define BLOW_EFFECT_TYPE_FEAR 1
1468 #define BLOW_EFFECT_TYPE_SLEEP 2
1469 #define BLOW_EFFECT_TYPE_HEAL 3
1473 * @brief ¥â¥ó¥¹¥¿¡¼¤«¤éŨ¥â¥ó¥¹¥¿¡¼¤Ø¤ÎÂǷ⹶·â½èÍý
1474 * @param m_idx ¹¶·â¦¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
1475 * @param t_idx ÌÜɸ¦¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
1476 * @return ¼ÂºÝ¤ËÂÇ·â½èÍý¤¬¹Ô¤ï¤ì¤¿¾ì¹çTRUE¤òÊÖ¤¹
1478 static bool monst_attack_monst(int m_idx, int t_idx)
1480 monster_type *m_ptr = &m_list[m_idx];
1481 monster_type *t_ptr = &m_list[t_idx];
1483 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1484 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1488 char m_name[80], t_name[80];
1489 char temp[MAX_NLEN];
1491 bool explode = FALSE, touched = FALSE, fear = FALSE;
1492 int y_saver = t_ptr->fy;
1493 int x_saver = t_ptr->fx;
1496 bool see_m = is_seen(m_ptr);
1497 bool see_t = is_seen(t_ptr);
1498 bool see_either = see_m || see_t;
1500 /* Can the player be aware of this attack? */
1501 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1502 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1504 /* Cannot attack self */
1505 if (m_idx == t_idx) return FALSE;
1507 /* Not allowed to attack */
1508 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1510 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1515 /* Extract the effective monster level */
1516 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1518 /* Get the monster name (or "it") */
1519 monster_desc(m_name, m_ptr, 0);
1521 /* Get the monster name (or "it") */
1522 monster_desc(t_name, t_ptr, 0);
1524 /* Assume no blink */
1527 if (!see_either && known)
1532 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 1);
1534 /* Scan through all four blows */
1535 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1537 bool obvious = FALSE;
1544 /* Extract the attack infomation */
1545 int effect = r_ptr->blow[ap_cnt].effect;
1546 int method = r_ptr->blow[ap_cnt].method;
1547 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1548 int d_side = r_ptr->blow[ap_cnt].d_side;
1550 if (!m_ptr->r_idx) break;
1552 /* Stop attacking if the target dies! */
1553 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1556 /* Hack -- no more attacks */
1559 if (method == RBM_SHOOT) continue;
1561 /* Extract the attack "power" */
1562 power = mbe_info[effect].power;
1565 if (!effect || check_hit2(power, rlev, ac, MON_STUNNED(m_ptr)))
1568 (void)set_monster_csleep(t_idx, 0);
1572 /* Redraw the health bar */
1573 if (p_ptr->health_who == t_idx) p_ptr->redraw |= (PR_HEALTH);
1574 if (p_ptr->riding == t_idx) p_ptr->redraw |= (PR_UHEALTH);
1577 /* Describe the attack method */
1583 act = "%s¤ò²¥¤Ã¤¿¡£";
1595 act = "%s¤ò¿¨¤Ã¤¿¡£";
1597 act = "touches %s.";
1607 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1609 act = "punches %s.";
1619 act = "%s¤ò½³¤Ã¤¿¡£";
1631 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1643 act = "%s¤ò³ú¤ó¤À¡£";
1655 act = "%s¤ò»É¤·¤¿¡£";
1667 act = "%s¤ò»Â¤Ã¤¿¡£";
1669 act = "slashes %s.";
1678 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1690 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1692 act = "crushes %s.";
1702 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1704 act = "engulfs %s.";
1714 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1716 act = "charges %s.";
1726 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1728 act = "crawls on %s.";
1738 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1740 act = "drools on %s.";
1750 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1752 act = "spits on %s.";
1761 if (see_either) disturb(1, 1);
1776 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1778 act = "gazes at %s.";
1788 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1790 act = "wails at %s.";
1800 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1802 act = "releases spores at %s.";
1812 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1814 act = "projects XXX4's at %s.";
1824 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1826 act = "begs %s for money.";
1836 act = "%s¤òÉî¿«¤·¤¿¡£";
1838 act = "insults %s.";
1848 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1850 act = "moans at %s.";
1860 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1862 act = "sings to %s.";
1871 if (act && see_either)
1874 if (do_silly_attack) act = silly_attacks2[randint0(MAX_SILLY_ATTACK)];
1875 strfmt(temp, act, t_name);
1876 msg_format("%^s¤Ï%s", m_name, temp);
1878 if (do_silly_attack)
1880 act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
1881 strfmt(temp, "%s %s.", act, t_name);
1883 else strfmt(temp, act, t_name);
1884 msg_format("%^s %s", m_name, temp);
1888 /* Hack -- assume all attacks are obvious */
1891 /* Roll out the damage */
1892 damage = damroll(d_dice, d_side);
1894 /* Assume no effect */
1895 effect_type = BLOW_EFFECT_TYPE_NONE;
1899 /* Apply appropriate damage */
1908 if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13))
1910 int tmp_damage = damage - (damage * ((ac < 150) ? ac : 150) / 250);
1911 damage = MAX(damage, tmp_damage * 2);
1918 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1933 if ((p_ptr->riding != m_idx) && one_in_(2)) blinked = TRUE;
1969 effect_type = BLOW_EFFECT_TYPE_FEAR;
1973 effect_type = BLOW_EFFECT_TYPE_SLEEP;
1977 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1978 if (damage > 23) earthquake_aux(m_ptr->fy, m_ptr->fx, 8, m_idx);
1994 effect_type = BLOW_EFFECT_TYPE_HEAL;
2012 /* Do damage if not exploding */
2015 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
2016 damage, pt, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2019 switch (effect_type)
2021 case BLOW_EFFECT_TYPE_FEAR:
2022 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
2023 damage, GF_TURN_ALL, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2026 case BLOW_EFFECT_TYPE_SLEEP:
2027 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
2028 r_ptr->level, GF_OLD_SLEEP, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2031 case BLOW_EFFECT_TYPE_HEAL:
2032 if ((monster_living(tr_ptr)) && (damage > 2))
2034 bool did_heal = FALSE;
2036 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
2039 m_ptr->hp += damroll(4, damage / 6);
2040 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
2042 /* Redraw (later) if needed */
2043 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2044 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2046 /* Special message */
2047 if (see_m && did_heal)
2050 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
2052 msg_format("%^s appears healthier.", m_name);
2062 if ((tr_ptr->flags2 & RF2_AURA_FIRE) && m_ptr->r_idx)
2064 if (!(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
2069 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2071 msg_format("%^s is suddenly very hot!", m_name);
2074 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2075 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2076 damroll (1 + ((tr_ptr->level) / 26),
2077 1 + ((tr_ptr->level) / 17)),
2078 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2082 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
2087 if ((tr_ptr->flags3 & RF3_AURA_COLD) && m_ptr->r_idx)
2089 if (!(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK))
2094 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2096 msg_format("%^s is suddenly very cold!", m_name);
2099 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags3 |= RF3_AURA_COLD;
2100 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2101 damroll (1 + ((tr_ptr->level) / 26),
2102 1 + ((tr_ptr->level) / 17)),
2103 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2107 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
2112 if ((tr_ptr->flags2 & RF2_AURA_ELEC) && m_ptr->r_idx)
2114 if (!(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK))
2119 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2121 msg_format("%^s gets zapped!", m_name);
2124 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_ELEC;
2125 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2126 damroll (1 + ((tr_ptr->level) / 26),
2127 1 + ((tr_ptr->level) / 17)),
2128 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2132 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
2139 /* Monster missed player */
2142 /* Analyze failed attacks */
2159 (void)set_monster_csleep(t_idx, 0);
2161 /* Visible monsters */
2166 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2168 msg_format("%^s misses %s.", m_name, t_name);
2178 /* Analyze "visible" monsters only */
2179 if (is_original_ap_and_seen(m_ptr) && !do_silly_attack)
2181 /* Count "obvious" attacks (and ones that cause damage) */
2182 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2184 /* Count attacks of this type */
2185 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2187 r_ptr->r_blows[ap_cnt]++;
2195 sound(SOUND_EXPLODE);
2197 /* Cancel Invulnerability */
2198 (void)set_monster_invulner(m_idx, 0, FALSE);
2201 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2203 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2210 if (blinked && m_ptr->r_idx)
2212 if (teleport_barrier(m_idx))
2217 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²...¤è¤¦¤È¤·¤¿¤¬¥Ð¥ê¥¢¤ËËɤ¬¤ì¤¿¡£");
2219 msg_print("The thief flees laughing...? But magic barrier obstructs it.");
2232 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2234 msg_print("The thief flees laughing!");
2242 teleport_away(m_idx, MAX_SIGHT * 2 + 5, 0L);
2250 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
2252 return !have_flag(f_ptr->flags, FF_GLASS) ||
2253 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
2254 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
2259 * @brief ¥â¥ó¥¹¥¿¡¼Ã±ÂΤΣ±¥¿¡¼¥ó¹ÔÆ°½èÍý¥á¥¤¥ó¥ë¡¼¥Á¥ó /
2261 * @param m_idx ¹ÔÆ°¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
2264 * The monster is known to be within 100 grids of the player\n
2266 * In several cases, we directly update the monster lore\n
2268 * Note that a monster is only allowed to "reproduce" if there\n
2269 * are a limited number of "reproducing" monsters on the current\n
2270 * level. This should prevent the level from being "swamped" by\n
2271 * reproducing monsters. It also allows a large mass of mice to\n
2272 * prevent a louse from multiplying, but this is a small price to\n
2273 * pay for a simple multiplication method.\n
2275 * XXX Monster fear is slightly odd, in particular, monsters will\n
2276 * fixate on opening a door even if they cannot open it. Actually,\n
2277 * the same thing happens to normal monsters when they hit a door\n
2279 * XXX XXX XXX In addition, monsters which *cannot* open or bash\n
2280 * down a door will still stand there trying to open it...\n
2282 * XXX Technically, need to check for monster in the way\n
2283 * combined with that monster being in a wall (or door?)\n
2285 * A "direction" of "5" means "pick a random direction".\n
2287 static void process_monster(int m_idx)
2289 monster_type *m_ptr = &m_list[m_idx];
2290 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2291 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2293 int i, d, oy, ox, ny, nx;
2298 feature_type *f_ptr;
2300 monster_type *y_ptr;
2305 bool must_alter_to_move;
2314 bool gets_angry = FALSE;
2320 bool is_riding_mon = (m_idx == p_ptr->riding);
2322 bool see_m = is_seen(m_ptr);
2324 if (is_riding_mon && !(r_ptr->flags7 & RF7_RIDING))
2326 if (rakuba(0, TRUE))
2329 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2332 monster_desc(m_name, &m_list[p_ptr->riding], 0);
2333 msg_format("You have fallen from %s.", m_name);
2338 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
2340 choose_new_monster(m_idx, FALSE, 0);
2341 r_ptr = &r_info[m_ptr->r_idx];
2344 /* Players hidden in shadow are almost imperceptable. -LM- */
2345 if (p_ptr->special_defense & NINJA_S_STEALTH)
2347 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
2348 if (p_ptr->monlite) tmp /= 3;
2349 if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
2350 if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
2351 /* Low-level monsters will find it difficult to locate the player. */
2352 if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
2355 /* Are there its parent? */
2356 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
2358 /* Its parent have gone, it also goes away. */
2364 /* Acquire the monster name */
2365 monster_desc(m_name, m_ptr, 0);
2368 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2370 msg_format("%^s disappears!", m_name);
2374 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
2378 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
2379 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
2382 /* Delete the monster */
2383 delete_monster_idx(m_idx);
2388 /* Quantum monsters are odd */
2389 if (r_ptr->flags2 & (RF2_QUANTUM))
2391 /* Sometimes skip move */
2392 if (!randint0(2)) return;
2395 if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2399 if (is_pet(m_ptr) && !(m_ptr->ml))
2406 /* Acquire the monster name */
2407 monster_desc(m_name, m_ptr, 0);
2411 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2413 msg_format("%^s disappears!", m_name);
2417 /* Generate treasure, etc */
2418 monster_death(m_idx, FALSE);
2420 /* Delete the monster */
2421 delete_monster_idx(m_idx);
2426 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2428 msg_print("You feel sad for a moment.");
2436 if (m_ptr->r_idx == MON_SHURYUUDAN)
2438 mon_take_hit_mon(m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2440 mon_take_hit_mon(m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2443 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) && !p_ptr->inside_battle)
2445 static int riding_pinch = 0;
2447 if (m_ptr->hp < m_ptr->maxhp/3)
2450 monster_desc(m_name, m_ptr, 0);
2452 if (is_riding_mon && riding_pinch < 2)
2455 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2457 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
2467 msg_format("%s¤Ï¤¢¤Ê¤¿¤Î«Çû¤«¤éæ½Ð¤·¤¿¡£", m_name);
2469 msg_format("%^s succeeded to escape from your restriction!", m_name);
2471 if (rakuba(-1, FALSE))
2474 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2476 msg_print("You have fallen from riding pet.");
2483 if ((r_ptr->flags2 & RF2_CAN_SPEAK) && (m_ptr->r_idx != MON_GRIP) && (m_ptr->r_idx != MON_WOLF) && (m_ptr->r_idx != MON_FANG) &&
2484 player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(m_ptr->fy, m_ptr->fx, py, px))
2487 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2489 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2493 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2494 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2496 msg_format("%^s read a scroll of teleport level.", m_name);
2497 msg_format("%^s disappears.", m_name);
2501 if (is_riding_mon && rakuba(-1, FALSE))
2504 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2506 msg_print("You have fallen from riding pet.");
2510 /* Check for quest completion */
2511 check_quest_completion(m_ptr);
2513 delete_monster_idx(m_idx);
2520 /* Reset the counter */
2521 if (is_riding_mon) riding_pinch = 0;
2525 /* Handle "sleep" */
2526 if (MON_CSLEEP(m_ptr))
2528 /* Handle non-aggravation - Still sleeping */
2529 if (!(p_ptr->cursed & TRC_AGGRAVATE)) return;
2531 /* Handle aggravation */
2533 /* Reset sleep counter */
2534 (void)set_monster_csleep(m_idx, 0);
2536 /* Notice the "waking up" */
2541 /* Acquire the monster name */
2542 monster_desc(m_name, m_ptr, 0);
2544 /* Dump a message */
2546 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
2548 msg_format("%^s wakes up.", m_name);
2552 /* Hack -- Count the wakings */
2553 if (is_original_ap_and_seen(m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
2560 if (MON_STUNNED(m_ptr))
2562 /* Sometimes skip move */
2563 if (one_in_(2)) return;
2568 p_ptr->update |= (PU_BONUS);
2571 /* No one wants to be your friend if you're aggravating */
2572 if (is_friendly(m_ptr) && (p_ptr->cursed & TRC_AGGRAVATE))
2575 /* Paranoia... no pet uniques outside wizard mode -- TY */
2576 if (is_pet(m_ptr) &&
2577 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
2578 monster_has_hostile_align(NULL, 10, -10, r_ptr))
2579 || (r_ptr->flagsr & RFR_RES_ALL)))
2584 if (p_ptr->inside_battle) gets_angry = FALSE;
2588 if (is_pet(m_ptr) || see_m)
2591 monster_desc(m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
2593 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2595 msg_format("%^s suddenly becomes hostile!", m_name);
2602 /* Get the origin */
2607 /* Attempt to "multiply" if able and allowed */
2608 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2612 /* Count the adjacent monsters */
2613 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2615 for (x = ox - 1; x <= ox + 1; x++)
2617 /* Ignore locations off of edge */
2618 if (!in_bounds2(y, x)) continue;
2620 if (cave[y][x].m_idx) k++;
2625 if (multiply_barrier(m_idx)) k = 8;
2627 /* Hack -- multiply slower in crowded areas */
2628 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2630 /* Try to multiply */
2631 if (multiply_monster(m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
2633 /* Take note if visible */
2634 if (m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(m_ptr))
2636 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2639 /* Multiplying takes energy */
2646 if (r_ptr->flags6 & RF6_SPECIAL)
2648 /* Hack -- Ohmu scatters molds! */
2649 if (m_ptr->r_idx == MON_OHMU)
2651 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
2653 if (r_ptr->freq_spell && (randint1(100) <= r_ptr->freq_spell))
2656 int rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
2657 u32b p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
2659 for (k = 0; k < 6; k++)
2661 if (summon_specific(m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_BIZARRE1, (PM_ALLOW_GROUP | p_mode)))
2663 if (m_list[hack_m_idx_ii].ml) count++;
2667 if (count && is_original_ap_and_seen(m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
2674 if (!p_ptr->inside_battle)
2676 /* Hack! "Cyber" monster makes noise... */
2677 if (m_ptr->ap_r_idx == MON_CYBER &&
2678 one_in_(CYBERNOISE) &&
2679 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2681 if (disturb_minor) disturb(FALSE, FALSE);
2683 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2685 msg_print("You hear heavy steps.");
2689 /* Some monsters can speak */
2690 if ((ap_r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2691 one_in_(SPEAK_CHANCE) &&
2692 player_has_los_bold(oy, ox) &&
2693 projectable(oy, ox, py, px))
2696 char monmessage[1024];
2699 /* Acquire the monster name/poss */
2701 monster_desc(m_name, m_ptr, 0);
2704 strcpy(m_name, "¤½¤ì");
2706 strcpy(m_name, "It");
2709 /* Select the file for monster quotes */
2710 if (MON_MONFEAR(m_ptr))
2712 filename = "monfear_j.txt";
2714 filename = "monfear.txt";
2716 else if (is_pet(m_ptr))
2718 filename = "monpet_j.txt";
2720 filename = "monpet.txt";
2722 else if (is_friendly(m_ptr))
2724 filename = "monfrien_j.txt";
2726 filename = "monfrien.txt";
2730 filename = "monspeak_j.txt";
2732 filename = "monspeak.txt";
2734 /* Get the monster line */
2735 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
2739 msg_format("%^s%s", m_name, monmessage);
2741 msg_format("%^s %s", m_name, monmessage);
2748 /* Try to cast spell occasionally */
2749 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
2751 bool counterattack = FALSE;
2753 /* Give priority to counter attack? */
2754 if (m_ptr->target_y)
2756 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
2758 /* The monster must be an enemy, and projectable */
2760 are_enemies(m_ptr, &m_list[t_m_idx]) &&
2761 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
2763 counterattack = TRUE;
2769 /* Attempt to cast a spell */
2770 if (aware && make_attack_spell(m_idx)) return;
2773 * Attempt to cast a spell at an enemy other than the player
2774 * (may slow the game a smidgeon, but I haven't noticed.)
2776 if (monst_spell_monst(m_idx)) return;
2780 /* Attempt to do counter attack at first */
2781 if (monst_spell_monst(m_idx)) return;
2783 if (aware && make_attack_spell(m_idx)) return;
2787 /* Hack -- Assume no movement */
2788 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2789 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2792 /* Confused -- 100% random */
2793 if (MON_CONFUSED(m_ptr) || !aware)
2795 /* Try four "random" directions */
2796 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2799 /* 75% random movement */
2800 else if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) &&
2801 (randint0(100) < 75))
2803 /* Memorize flags */
2804 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
2806 /* Try four "random" directions */
2807 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2810 /* 50% random movement */
2811 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2812 (randint0(100) < 50))
2814 /* Memorize flags */
2815 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
2817 /* Try four "random" directions */
2818 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2821 /* 25% random movement */
2822 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2823 (randint0(100) < 25))
2825 /* Memorize flags */
2826 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
2828 /* Try four "random" directions */
2829 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2832 /* Can't reach player - find something else to hit */
2833 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2835 /* Try four "random" directions */
2836 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2838 /* Look for an enemy */
2839 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2840 get_enemy_dir(m_idx, mm);
2844 /* Pets will follow the player */
2845 else if (is_pet(m_ptr))
2847 /* Are we trying to avoid the player? */
2848 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
2849 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2851 /* Do we want to find the player? */
2852 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2854 /* Should we find the player if we can't find a monster? */
2855 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2857 /* by default, move randomly */
2858 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2860 /* Look for an enemy */
2861 if (!get_enemy_dir(m_idx, mm))
2863 /* Find the player if necessary */
2864 if (avoid || lonely || distant)
2866 /* Remember the leash length */
2867 int dis = p_ptr->pet_follow_distance;
2869 /* Hack -- adjust follow distance temporarily */
2870 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2872 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2875 /* Find the player */
2876 (void)get_moves(m_idx, mm);
2878 /* Restore the leash */
2879 p_ptr->pet_follow_distance = dis;
2884 /* Friendly monster movement */
2885 else if (!is_hostile(m_ptr))
2887 /* by default, move randomly */
2888 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2890 /* Look for an enemy */
2891 get_enemy_dir(m_idx, mm);
2893 /* Normal movement */
2896 /* Logical moves, may do nothing */
2897 if (!get_moves(m_idx, mm)) return;
2900 /* Assume nothing */
2904 must_alter_to_move = FALSE;
2906 /* Assume nothing */
2907 did_open_door = FALSE;
2908 did_bash_door = FALSE;
2909 did_take_item = FALSE;
2910 did_kill_item = FALSE;
2911 did_move_body = FALSE;
2912 did_pass_wall = FALSE;
2913 did_kill_wall = FALSE;
2916 /* Take a zero-terminated array of "directions" */
2917 for (i = 0; mm[i]; i++)
2919 /* Get the direction */
2922 /* Hack -- allow "randomized" motion */
2923 if (d == 5) d = ddd[randint0(8)];
2925 /* Get the destination */
2929 /* Ignore locations off of edge */
2930 if (!in_bounds2(ny, nx)) continue;
2932 /* Access that cave grid */
2933 c_ptr = &cave[ny][nx];
2934 f_ptr = &f_info[c_ptr->feat];
2935 can_cross = monster_can_cross_terrain(c_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0);
2937 /* Access that cave grid's contents */
2938 y_ptr = &m_list[c_ptr->m_idx];
2940 /* Hack -- player 'in' wall */
2941 if (player_bold(ny, nx))
2946 /* Possibly a monster to attack */
2947 else if (c_ptr->m_idx)
2952 /* Monster destroys walls (and doors) */
2953 else if ((r_ptr->flags2 & RF2_KILL_WALL) &&
2954 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !is_riding_mon) &&
2955 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
2956 check_hp_for_feat_destruction(f_ptr, m_ptr))
2958 /* Eat through walls/doors/rubble */
2960 if (!can_cross) must_alter_to_move = TRUE;
2962 /* Monster destroyed a wall (later) */
2963 did_kill_wall = TRUE;
2966 /* Floor is open? */
2969 /* Go ahead and move */
2972 /* Monster moves through walls (and doors) */
2973 if ((r_ptr->flags2 & RF2_PASS_WALL) && (!is_riding_mon || p_ptr->pass_wall) &&
2974 have_flag(f_ptr->flags, FF_CAN_PASS))
2976 /* Monster went through a wall */
2977 did_pass_wall = TRUE;
2981 /* Handle doors and secret doors */
2982 else if (is_closed_door(c_ptr->feat))
2984 bool may_bash = TRUE;
2986 /* Assume no move allowed */
2989 /* Creature can open doors. */
2990 if ((r_ptr->flags2 & RF2_OPEN_DOOR) && have_flag(f_ptr->flags, FF_OPEN) &&
2991 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2996 /* The door is open */
2997 did_open_door = TRUE;
2999 /* Do not bash the door */
3006 /* Locked doors (not jammed) */
3009 /* Try to unlock it XXX XXX XXX */
3010 if (randint0(m_ptr->hp / 10) > f_ptr->power)
3012 /* Unlock the door */
3013 cave_alter_feat(ny, nx, FF_DISARM);
3015 /* Do not bash the door */
3024 /* Stuck doors -- attempt to bash them down if allowed */
3025 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) && have_flag(f_ptr->flags, FF_BASH) &&
3026 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3028 /* Attempt to Bash XXX XXX XXX */
3029 if (check_hp_for_feat_destruction(f_ptr, m_ptr) && (randint0(m_ptr->hp / 10) > f_ptr->power))
3032 if (have_flag(f_ptr->flags, FF_GLASS))
3034 msg_print("¥¬¥é¥¹¤¬ºÕ¤±¤ë²»¤¬¤·¤¿¡ª");
3036 msg_print("You hear a glass was crashed!");
3040 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
3042 msg_print("You hear a door burst open!");
3045 /* Disturb (sometimes) */
3046 if (disturb_minor) disturb(0, 0);
3048 /* The door was bashed open */
3049 did_bash_door = TRUE;
3051 /* Hack -- fall into doorway */
3053 must_alter_to_move = TRUE;
3058 /* Deal with doors in the way */
3059 if (did_open_door || did_bash_door)
3061 /* Break down the door */
3062 if (did_bash_door && ((randint0(100) < 50) || (feat_state(c_ptr->feat, FF_OPEN) == c_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
3064 cave_alter_feat(ny, nx, FF_BASH);
3066 if (!m_ptr->r_idx) /* Killed by shards of glass, etc. */
3068 /* Update some things */
3069 p_ptr->update |= (PU_FLOW);
3070 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3071 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3080 cave_alter_feat(ny, nx, FF_OPEN);
3083 f_ptr = &f_info[c_ptr->feat];
3085 /* Handle viewable doors */
3090 /* Hack -- check for Glyph of Warding */
3091 if (do_move && is_glyph_grid(c_ptr) &&
3092 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3094 /* Assume no move allowed */
3097 /* Break the ward */
3098 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
3100 /* Describe observable breakage */
3101 if (c_ptr->info & CAVE_MARK)
3104 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3106 msg_print("The rune of protection is broken!");
3110 /* Forget the rune */
3111 c_ptr->info &= ~(CAVE_MARK);
3113 /* Break the rune */
3114 c_ptr->info &= ~(CAVE_OBJECT);
3117 /* Allow movement */
3124 else if (do_move && is_explosive_rune_grid(c_ptr) &&
3125 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3127 /* Assume no move allowed */
3130 /* Break the ward */
3133 /* Break the ward */
3134 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3136 /* Describe observable breakage */
3137 if (c_ptr->info & CAVE_MARK)
3140 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3142 msg_print("The rune explodes!");
3145 project(0, 2, ny, nx, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
3151 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3153 msg_print("An explosive rune was disarmed.");
3157 /* Forget the rune */
3158 c_ptr->info &= ~(CAVE_MARK);
3160 /* Break the rune */
3161 c_ptr->info &= ~(CAVE_OBJECT);
3167 if (!m_ptr->r_idx) return;
3168 /* Allow movement */
3173 /* The player is in the way */
3174 if (do_move && player_bold(ny, nx))
3176 /* Some monsters never attack */
3177 if (r_ptr->flags1 & RF1_NEVER_BLOW)
3179 /* Hack -- memorize lack of attacks */
3180 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3186 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
3187 if (do_move && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3189 if (!MON_CONFUSED(m_ptr))
3191 if (!(r_ptr->flags2 & RF2_STUPID)) do_move = FALSE;
3194 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
3199 /* The player is in the way. Attack him. */
3202 if (!p_ptr->riding || one_in_(2))
3205 (void)make_attack_normal(m_idx);
3216 /* A monster is in the way */
3217 if (do_move && c_ptr->m_idx)
3219 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3221 /* Assume no movement */
3224 /* Attack 'enemies' */
3225 if (((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW) &&
3226 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3227 can_cross && (c_ptr->m_idx != p_ptr->riding)) ||
3228 are_enemies(m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
3230 if (!(r_ptr->flags1 & RF1_NEVER_BLOW))
3232 if (r_ptr->flags2 & RF2_KILL_BODY)
3234 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3238 if (y_ptr->r_idx && (y_ptr->hp >= 0))
3240 if (monst_attack_monst(m_idx, c_ptr->m_idx)) return;
3242 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
3243 else if (d_info[dungeon_type].flags1 & DF1_NO_MELEE)
3245 if (MON_CONFUSED(m_ptr)) return;
3246 else if (r_ptr->flags2 & RF2_STUPID)
3248 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
3256 /* Push past weaker monsters (unless leaving a wall) */
3257 else if ((r_ptr->flags2 & RF2_MOVE_BODY) && !(r_ptr->flags1 & RF1_NEVER_MOVE) &&
3258 (r_ptr->mexp > z_ptr->mexp) &&
3259 can_cross && (c_ptr->m_idx != p_ptr->riding) &&
3260 monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
3262 /* Allow movement */
3265 /* Monster pushed past another monster */
3266 did_move_body = TRUE;
3268 /* Wake up the moved monster */
3269 (void)set_monster_csleep(c_ptr->m_idx, 0);
3271 /* XXX XXX XXX Message */
3277 if (!p_ptr->riding_ryoute && !MON_MONFEAR(&m_list[p_ptr->riding])) do_move = FALSE;
3280 if (did_kill_wall && do_move)
3282 if (one_in_(GRINDNOISE))
3284 if (have_flag(f_ptr->flags, FF_GLASS))
3286 msg_print("²¿¤«¤ÎºÕ¤±¤ë²»¤¬Ê¹¤³¤¨¤ë¡£");
3288 msg_print("There is a crashing sound.");
3292 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
3294 msg_print("There is a grinding sound.");
3298 cave_alter_feat(ny, nx, FF_HURT_DISI);
3300 if (!m_ptr->r_idx) /* Killed by shards of glass, etc. */
3302 /* Update some things */
3303 p_ptr->update |= (PU_FLOW);
3304 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3305 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3310 f_ptr = &f_info[c_ptr->feat];
3312 /* Note changes to viewable region */
3319 if (must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
3321 if (!monster_can_cross_terrain(c_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0))
3323 /* Assume no move allowed */
3329 * Check if monster can cross terrain
3330 * This is checked after the normal attacks
3331 * to allow monsters to attack an enemy,
3332 * even if it can't enter the terrain.
3334 if (do_move && !can_cross && !did_kill_wall && !did_bash_door)
3336 /* Assume no move allowed */
3340 /* Some monsters never move */
3341 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3343 /* Hack -- memorize lack of moves */
3344 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3350 /* Creature has been allowed move */
3356 if (have_flag(f_ptr->flags, FF_TREE))
3358 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3360 m_ptr->energy_need += ENERGY_NEED();
3366 /* Hack -- Update the old location */
3367 cave[oy][ox].m_idx = c_ptr->m_idx;
3369 /* Mega-Hack -- move the old monster, if any */
3372 /* Move the old monster */
3376 /* Update the old monster */
3377 update_mon(c_ptr->m_idx, TRUE);
3380 /* Hack -- Update the new location */
3381 c_ptr->m_idx = m_idx;
3383 /* Move the monster */
3387 /* Update the monster */
3388 update_mon(m_idx, TRUE);
3390 /* Redraw the old grid */
3393 /* Redraw the new grid */
3399 /* sound(SOUND_WALK); */
3401 /* Move the player */
3402 if (!move_player_effect(ny, nx, MPE_DONT_PICKUP)) break;
3405 /* Possible disturb */
3408 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(py, px, m_ptr->fy, m_ptr->fx)) ||
3409 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)))
3412 if (is_hostile(m_ptr))
3416 /* Take or Kill objects on the floor */
3417 if (c_ptr->o_idx && (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3418 (!is_pet(m_ptr) || ((p_ptr->pet_extra_flags & PF_PICKUP_ITEMS) && (r_ptr->flags2 & RF2_TAKE_ITEM))))
3420 s16b this_o_idx, next_o_idx;
3421 bool do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) ? TRUE : FALSE;
3423 /* Scan all objects in the grid */
3424 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3426 u32b flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
3427 char m_name[80], o_name[MAX_NLEN];
3429 /* Acquire object */
3430 object_type *o_ptr = &o_list[this_o_idx];
3432 /* Acquire next object */
3433 next_o_idx = o_ptr->next_o_idx;
3438 if (o_ptr->tval == TV_GOLD) continue;
3441 * Skip "real" corpses and statues, to avoid extreme
3442 * silliness like a novice rogue pockets full of statues
3445 if ((o_ptr->tval == TV_CORPSE) ||
3446 (o_ptr->tval == TV_STATUE)) continue;
3449 /* Extract some flags */
3450 object_flags(o_ptr, flgs);
3452 /* Acquire the object name */
3453 object_desc(o_name, o_ptr, 0);
3455 /* Acquire the monster name */
3456 monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
3458 /* React to objects that hurt the monster */
3459 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
3460 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
3461 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
3462 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
3463 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
3464 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
3465 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
3466 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
3467 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
3468 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
3469 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
3470 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
3471 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
3472 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
3473 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
3474 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
3475 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
3476 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
3477 if (have_flag(flgs, TR_BRAND_ACID)) flgr |= (RFR_IM_ACID);
3478 if (have_flag(flgs, TR_BRAND_ELEC)) flgr |= (RFR_IM_ELEC);
3479 if (have_flag(flgs, TR_BRAND_FIRE)) flgr |= (RFR_IM_FIRE);
3480 if (have_flag(flgs, TR_BRAND_COLD)) flgr |= (RFR_IM_COLD);
3481 if (have_flag(flgs, TR_BRAND_POIS)) flgr |= (RFR_IM_POIS);
3483 /* The object cannot be picked up by the monster */
3484 if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
3485 ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
3487 /* Only give a message for "take_item" */
3488 if (do_take && (r_ptr->flags2 & RF2_STUPID))
3491 did_take_item = TRUE;
3493 /* Describe observable situations */
3494 if (m_ptr->ml && player_can_see_bold(ny, nx))
3496 /* Dump a message */
3498 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£", m_name, o_name);
3500 msg_format("%^s tries to pick up %s, but fails.", m_name, o_name);
3506 /* Pick up the item */
3510 did_take_item = TRUE;
3512 /* Describe observable situations */
3513 if (player_can_see_bold(ny, nx))
3515 /* Dump a message */
3517 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3519 msg_format("%^s picks up %s.", m_name, o_name);
3523 /* Excise the object */
3524 excise_object_idx(this_o_idx);
3527 o_ptr->marked &= OM_TOUCHED;
3529 /* Forget location */
3530 o_ptr->iy = o_ptr->ix = 0;
3532 /* Memorize monster */
3533 o_ptr->held_m_idx = m_idx;
3536 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3539 m_ptr->hold_o_idx = this_o_idx;
3542 /* Destroy the item if not a pet */
3543 else if (!is_pet(m_ptr))
3546 did_kill_item = TRUE;
3548 /* Describe observable situations */
3549 if (player_has_los_bold(ny, nx))
3551 /* Dump a message */
3553 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3555 msg_format("%^s destroys %s.", m_name, o_name);
3559 /* Delete the object */
3560 delete_object_idx(this_o_idx);
3566 /* Stop when done */
3571 * Forward movements failed, but now received LOS attack!
3572 * Try to flow by smell.
3574 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3575 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3577 /* If we haven't done anything, try casting a spell again */
3578 if (!do_turn && !do_move && !MON_MONFEAR(m_ptr) && !is_riding_mon && aware)
3580 /* Try to cast spell again */
3581 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
3583 if (make_attack_spell(m_idx)) return;
3588 /* Notice changes in view */
3591 /* Update some things */
3592 p_ptr->update |= (PU_FLOW);
3595 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3598 /* Notice changes in view */
3599 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
3600 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !p_ptr->inside_battle)))
3602 /* Update some things */
3603 p_ptr->update |= (PU_MON_LITE);
3606 /* Learn things from observable monster */
3607 if (is_original_ap_and_seen(m_ptr))
3609 /* Monster opened a door */
3610 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3612 /* Monster bashed a door */
3613 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3615 /* Monster tried to pick something up */
3616 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3618 /* Monster tried to crush something */
3619 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3621 /* Monster pushed past another monster */
3622 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3624 /* Monster passed through a wall */
3625 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3627 /* Monster destroyed a wall */
3628 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3632 /* Hack -- get "bold" if out of options */
3633 if (!do_turn && !do_move && MON_MONFEAR(m_ptr) && aware)
3635 /* No longer afraid */
3636 (void)set_monster_monfear(m_idx, 0);
3638 /* Message if seen */
3643 /* Acquire the monster name */
3644 monster_desc(m_name, m_ptr, 0);
3646 /* Dump a message */
3648 msg_format("%^s¤ÏÀ襤¤ò·è°Õ¤·¤¿¡ª", m_name);
3650 msg_format("%^s turns to fight!", m_name);
3654 if (m_ptr->ml) chg_virtue(V_COMPASSION, -1);
3656 /* XXX XXX XXX Actually do something now (?) */
3661 * @brief Á´¥â¥ó¥¹¥¿¡¼¤Î¥¿¡¼¥ó´ÉÍý¥á¥¤¥ó¥ë¡¼¥Á¥ó /
3662 * Process all the "live" monsters, once per game turn.
3665 * During each game turn, we scan through the list of all the "live" monsters,\n
3666 * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
3667 * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
3669 * Note that monsters can never move in the monster array (except when the\n
3670 * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
3672 * This function is responsible for at least half of the processor time\n
3673 * on a normal system with a "normal" amount of monsters and a player doing\n
3676 * When the player is resting, virtually 90% of the processor time is spent\n
3677 * in this function, and its children, "process_monster()" and "make_move()".\n
3679 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
3680 * especially when the player is running.\n
3682 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
3683 * monsters while they are still being "born". A monster is "fresh" only\n
3684 * during the turn in which it is created, and we use the "hack_m_idx" to\n
3685 * determine if the monster is yet to be processed during the current turn.\n
3687 * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
3688 * move before any "nasty" monsters get to use their spell attacks.\n
3690 * Note that when the "knowledge" about the currently tracked monster\n
3691 * changes (flags, attacks, spells), we induce a redraw of the monster\n
3694 void process_monsters(void)
3701 monster_type *m_ptr;
3702 monster_race *r_ptr;
3704 int old_monster_race_idx;
3706 u32b old_r_flags1 = 0L;
3707 u32b old_r_flags2 = 0L;
3708 u32b old_r_flags3 = 0L;
3709 u32b old_r_flags4 = 0L;
3710 u32b old_r_flags5 = 0L;
3711 u32b old_r_flags6 = 0L;
3712 u32b old_r_flagsr = 0L;
3714 byte old_r_blows0 = 0;
3715 byte old_r_blows1 = 0;
3716 byte old_r_blows2 = 0;
3717 byte old_r_blows3 = 0;
3719 byte old_r_cast_spell = 0;
3723 /* Clear monster fighting indicator */
3726 /* Memorize old race */
3727 old_monster_race_idx = p_ptr->monster_race_idx;
3729 /* Acquire knowledge */
3730 if (p_ptr->monster_race_idx)
3732 /* Acquire current monster */
3733 r_ptr = &r_info[p_ptr->monster_race_idx];
3735 /* Memorize flags */
3736 old_r_flags1 = r_ptr->r_flags1;
3737 old_r_flags2 = r_ptr->r_flags2;
3738 old_r_flags3 = r_ptr->r_flags3;
3739 old_r_flags4 = r_ptr->r_flags4;
3740 old_r_flags5 = r_ptr->r_flags5;
3741 old_r_flags6 = r_ptr->r_flags6;
3742 old_r_flagsr = r_ptr->r_flagsr;
3744 /* Memorize blows */
3745 old_r_blows0 = r_ptr->r_blows[0];
3746 old_r_blows1 = r_ptr->r_blows[1];
3747 old_r_blows2 = r_ptr->r_blows[2];
3748 old_r_blows3 = r_ptr->r_blows[3];
3750 /* Memorize castings */
3751 old_r_cast_spell = r_ptr->r_cast_spell;
3755 /* Process the monsters (backwards) */
3756 for (i = m_max - 1; i >= 1; i--)
3758 /* Access the monster */
3760 r_ptr = &r_info[m_ptr->r_idx];
3762 /* Handle "leaving" */
3763 if (p_ptr->leaving) break;
3765 /* Ignore "dead" monsters */
3766 if (!m_ptr->r_idx) continue;
3768 if (p_ptr->wild_mode) continue;
3771 /* Handle "fresh" monsters */
3772 if (m_ptr->mflag & MFLAG_BORN)
3774 /* No longer "fresh" */
3775 m_ptr->mflag &= ~(MFLAG_BORN);
3781 /* Hack -- Require proximity */
3782 if (m_ptr->cdis >= AAF_LIMIT) continue;
3785 /* Access the location */
3789 /* Flow by smell is allowed */
3790 if (!p_ptr->no_flowed)
3792 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3795 /* Assume no move */
3798 /* Handle "sensing radius" */
3799 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
3801 /* We can "sense" the player */
3805 /* Handle "sight" and "aggravation" */
3806 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3807 (player_has_los_bold(fy, fx) || (p_ptr->cursed & TRC_AGGRAVATE)))
3809 /* We can "see" or "feel" the player */
3813 #if 0 /* (cave[py][px].when == cave[fy][fx].when) is always FALSE... */
3814 /* Hack -- Monsters can "smell" the player from far away */
3815 /* Note that most monsters have "aaf" of "20" or so */
3816 else if (!(m_ptr->mflag2 & MFLAG2_NOFLOW) &&
3817 cave_have_flag_bold(py, px, FF_MOVE) &&
3818 (cave[py][px].when == cave[fy][fx].when) &&
3819 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3820 (cave[fy][fx].dist < r_ptr->aaf))
3822 /* We can "smell" the player */
3826 else if (m_ptr->target_y) test = TRUE;
3829 if (!test) continue;
3832 if (p_ptr->riding == i)
3833 speed = p_ptr->pspeed;
3836 speed = m_ptr->mspeed;
3838 /* Monsters move quickly in Nightmare mode */
3839 if (ironman_nightmare) speed += 5;
3841 if (MON_FAST(m_ptr)) speed += 10;
3842 if (MON_SLOW(m_ptr)) speed -= 10;
3845 /* Give this monster some energy */
3846 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
3848 /* Not enough energy to move */
3849 if (m_ptr->energy_need > 0) continue;
3851 /* Use up "some" energy */
3852 m_ptr->energy_need += ENERGY_NEED();
3855 /* Save global index */
3858 /* Process the monster */
3861 reset_target(m_ptr);
3863 /* Give up flow_by_smell when it might useless */
3864 if (p_ptr->no_flowed && one_in_(3))
3865 m_ptr->mflag2 |= MFLAG2_NOFLOW;
3867 /* Hack -- notice death or departure */
3868 if (!p_ptr->playing || p_ptr->is_dead) break;
3870 /* Notice leaving */
3871 if (p_ptr->leaving) break;
3874 /* Reset global index */
3878 /* Tracking a monster race (the same one we were before) */
3879 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3881 /* Acquire monster race */
3882 r_ptr = &r_info[p_ptr->monster_race_idx];
3884 /* Check for knowledge change */
3885 if ((old_r_flags1 != r_ptr->r_flags1) ||
3886 (old_r_flags2 != r_ptr->r_flags2) ||
3887 (old_r_flags3 != r_ptr->r_flags3) ||
3888 (old_r_flags4 != r_ptr->r_flags4) ||
3889 (old_r_flags5 != r_ptr->r_flags5) ||
3890 (old_r_flags6 != r_ptr->r_flags6) ||
3891 (old_r_flagsr != r_ptr->r_flagsr) ||
3892 (old_r_blows0 != r_ptr->r_blows[0]) ||
3893 (old_r_blows1 != r_ptr->r_blows[1]) ||
3894 (old_r_blows2 != r_ptr->r_blows[2]) ||
3895 (old_r_blows3 != r_ptr->r_blows[3]) ||
3896 (old_r_cast_spell != r_ptr->r_cast_spell))
3899 p_ptr->window |= (PW_MONSTER);
3905 * @brief ¥â¥ó¥¹¥¿¡¼¤Î»þ¸Â¥¹¥Æ¡¼¥¿¥¹¤ò¼èÆÀ¤¹¤ë
3906 * @return m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
3907 * @return mproc_type ¥â¥ó¥¹¥¿¡¼¤Î»þ¸Â¥¹¥Æ¡¼¥¿¥¹ID
3908 * @return »Ä¤ê¥¿¡¼¥óÃÍ
3910 int get_mproc_idx(int m_idx, int mproc_type)
3912 s16b *cur_mproc_list = mproc_list[mproc_type];
3915 for (i = mproc_max[mproc_type] - 1; i >= 0; i--)
3917 if (cur_mproc_list[i] == m_idx) return i;
3924 * @brief ¥â¥ó¥¹¥¿¡¼¤Î»þ¸Â¥¹¥Æ¡¼¥¿¥¹¥ê¥¹¥È¤òÄɲ乤ë
3925 * @return m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
3926 * @return mproc_type Äɲä·¤¿¤¤¥â¥ó¥¹¥¿¡¼¤Î»þ¸Â¥¹¥Æ¡¼¥¿¥¹ID
3929 static void mproc_add(int m_idx, int mproc_type)
3931 if (mproc_max[mproc_type] < max_m_idx) mproc_list[mproc_type][mproc_max[mproc_type]++] = m_idx;
3936 * @brief ¥â¥ó¥¹¥¿¡¼¤Î»þ¸Â¥¹¥Æ¡¼¥¿¥¹¥ê¥¹¥È¤òºï½ü
3937 * @return m_idx ¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
3938 * @return mproc_type ºï½ü¤·¤¿¤¤¥â¥ó¥¹¥¿¡¼¤Î»þ¸Â¥¹¥Æ¡¼¥¿¥¹ID
3941 static void mproc_remove(int m_idx, int mproc_type)
3943 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
3944 if (mproc_idx >= 0) mproc_list[mproc_type][mproc_idx] = mproc_list[mproc_type][--mproc_max[mproc_type]];
3949 * @brief ¥â¥ó¥¹¥¿¡¼¤Î»þ¸Â¥¹¥Æ¡¼¥¿¥¹¥ê¥¹¥È¤ò½é´ü²½¤¹¤ë / Initialize monster process
3952 void mproc_init(void)
3954 monster_type *m_ptr;
3957 /* Reset "mproc_max[]" */
3958 for (cmi = 0; cmi < MAX_MTIMED; cmi++) mproc_max[cmi] = 0;
3960 /* Process the monsters (backwards) */
3961 for (i = m_max - 1; i >= 1; i--)
3963 /* Access the monster */
3966 /* Ignore "dead" monsters */
3967 if (!m_ptr->r_idx) continue;
3969 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
3971 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
3978 * @brief ¥â¥ó¥¹¥¿¡¼¤Î¿ç̲¾õÂÖÃͤò¥»¥Ã¥È¤¹¤ë /
3979 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
3980 * @param m_idx ¥â¥ó¥¹¥¿¡¼»²¾ÈID
3981 * @param v ¥»¥Ã¥È¤¹¤ëÃÍ
3982 * @return ÊÌÅÓ¹¹¿·½èÍý¤¬É¬Íפʾì¹çTRUE¤òÊÖ¤¹
3984 bool set_monster_csleep(int m_idx, int v)
3986 monster_type *m_ptr = &m_list[m_idx];
3987 bool notice = FALSE;
3989 /* Hack -- Force good values */
3990 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
3995 if (!MON_CSLEEP(m_ptr))
3997 mproc_add(m_idx, MTIMED_CSLEEP);
4005 if (MON_CSLEEP(m_ptr))
4007 mproc_remove(m_idx, MTIMED_CSLEEP);
4013 m_ptr->mtimed[MTIMED_CSLEEP] = v;
4015 if (!notice) return FALSE;
4019 /* Update health bar as needed */
4020 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
4021 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
4024 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
4031 * @brief ¥â¥ó¥¹¥¿¡¼¤Î²Ã®¾õÂÖÃͤò¥»¥Ã¥È /
4032 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
4033 * @param m_idx ¥â¥ó¥¹¥¿¡¼»²¾ÈID
4034 * @param v ¥»¥Ã¥È¤¹¤ëÃÍ
4035 * @return ÊÌÅÓ¹¹¿·½èÍý¤¬É¬Íפʾì¹çTRUE¤òÊÖ¤¹
4037 bool set_monster_fast(int m_idx, int v)
4039 monster_type *m_ptr = &m_list[m_idx];
4040 bool notice = FALSE;
4042 /* Hack -- Force good values */
4043 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4048 if (!MON_FAST(m_ptr))
4050 mproc_add(m_idx, MTIMED_FAST);
4058 if (MON_FAST(m_ptr))
4060 mproc_remove(m_idx, MTIMED_FAST);
4066 m_ptr->mtimed[MTIMED_FAST] = v;
4068 if (!notice) return FALSE;
4070 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
4077 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
4079 bool set_monster_slow(int m_idx, int v)
4081 monster_type *m_ptr = &m_list[m_idx];
4082 bool notice = FALSE;
4084 /* Hack -- Force good values */
4085 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4090 if (!MON_SLOW(m_ptr))
4092 mproc_add(m_idx, MTIMED_SLOW);
4100 if (MON_SLOW(m_ptr))
4102 mproc_remove(m_idx, MTIMED_SLOW);
4108 m_ptr->mtimed[MTIMED_SLOW] = v;
4110 if (!notice) return FALSE;
4112 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
4119 * @brief ¥â¥ó¥¹¥¿¡¼¤ÎÛ¯Û°¾õÂÖÃͤò¥»¥Ã¥È /
4120 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
4121 * @param m_idx ¥â¥ó¥¹¥¿¡¼»²¾ÈID
4122 * @param v ¥»¥Ã¥È¤¹¤ëÃÍ
4123 * @return ÊÌÅÓ¹¹¿·½èÍý¤¬É¬Íפʾì¹çTRUE¤òÊÖ¤¹
4125 bool set_monster_stunned(int m_idx, int v)
4127 monster_type *m_ptr = &m_list[m_idx];
4128 bool notice = FALSE;
4130 /* Hack -- Force good values */
4131 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4136 if (!MON_STUNNED(m_ptr))
4138 mproc_add(m_idx, MTIMED_STUNNED);
4146 if (MON_STUNNED(m_ptr))
4148 mproc_remove(m_idx, MTIMED_STUNNED);
4154 m_ptr->mtimed[MTIMED_STUNNED] = v;
4161 * @brief ¥â¥ó¥¹¥¿¡¼¤Îº®Íð¾õÂÖÃͤò¥»¥Ã¥È /
4162 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
4163 * @param m_idx ¥â¥ó¥¹¥¿¡¼»²¾ÈID
4164 * @param v ¥»¥Ã¥È¤¹¤ëÃÍ
4165 * @return ÊÌÅÓ¹¹¿·½èÍý¤¬É¬Íפʾì¹çTRUE¤òÊÖ¤¹
4167 bool set_monster_confused(int m_idx, int v)
4169 monster_type *m_ptr = &m_list[m_idx];
4170 bool notice = FALSE;
4172 /* Hack -- Force good values */
4173 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4178 if (!MON_CONFUSED(m_ptr))
4180 mproc_add(m_idx, MTIMED_CONFUSED);
4188 if (MON_CONFUSED(m_ptr))
4190 mproc_remove(m_idx, MTIMED_CONFUSED);
4196 m_ptr->mtimed[MTIMED_CONFUSED] = v;
4203 * @brief ¥â¥ó¥¹¥¿¡¼¤Î¶²¹²¾õÂÖÃͤò¥»¥Ã¥È /
4204 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
4205 * @param m_idx ¥â¥ó¥¹¥¿¡¼»²¾ÈID
4206 * @param v ¥»¥Ã¥È¤¹¤ëÃÍ
4207 * @return ÊÌÅÓ¹¹¿·½èÍý¤¬É¬Íפʾì¹çTRUE¤òÊÖ¤¹
4209 bool set_monster_monfear(int m_idx, int v)
4211 monster_type *m_ptr = &m_list[m_idx];
4212 bool notice = FALSE;
4214 /* Hack -- Force good values */
4215 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4220 if (!MON_MONFEAR(m_ptr))
4222 mproc_add(m_idx, MTIMED_MONFEAR);
4230 if (MON_MONFEAR(m_ptr))
4232 mproc_remove(m_idx, MTIMED_MONFEAR);
4238 m_ptr->mtimed[MTIMED_MONFEAR] = v;
4240 if (!notice) return FALSE;
4244 /* Update health bar as needed */
4245 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
4246 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
4254 * @brief ¥â¥ó¥¹¥¿¡¼¤Î̵Ũ¾õÂÖÃͤò¥»¥Ã¥È /
4255 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
4256 * @param m_idx ¥â¥ó¥¹¥¿¡¼»²¾ÈID
4257 * @param v ¥»¥Ã¥È¤¹¤ëÃÍ
4258 * @param energy_need TRUE¤Ê¤é¤Ð̵Ũ²ò½ü»þ¤Ë¹ÔÆ°¥¿¡¼¥ó¾ÃÈñ¤ò¹Ô¤¦
4259 * @return ÊÌÅÓ¹¹¿·½èÍý¤¬É¬Íפʾì¹çTRUE¤òÊÖ¤¹
4261 bool set_monster_invulner(int m_idx, int v, bool energy_need)
4263 monster_type *m_ptr = &m_list[m_idx];
4264 bool notice = FALSE;
4266 /* Hack -- Force good values */
4267 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4272 if (!MON_INVULNER(m_ptr))
4274 mproc_add(m_idx, MTIMED_INVULNER);
4282 if (MON_INVULNER(m_ptr))
4284 mproc_remove(m_idx, MTIMED_INVULNER);
4285 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
4291 m_ptr->mtimed[MTIMED_INVULNER] = v;
4293 if (!notice) return FALSE;
4297 /* Update health bar as needed */
4298 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
4299 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
4306 static u32b csleep_noise;
4309 * @brief ¥â¥ó¥¹¥¿¡¼¤Î³Æ¼ï¾õÂÖÃͤò»þ´Ö·Ð²á¤Ë¤è¤ê¹¹¿·¤¹¤ë¥µ¥Ö¥ë¡¼¥Á¥ó
4310 * @param m_idx ¥â¥ó¥¹¥¿¡¼»²¾ÈID
4311 * @param mtimed_idx ¹¹¿·¤¹¤ë¥â¥ó¥¹¥¿¡¼¤Î»þ¸Â¥¹¥Æ¡¼¥¿¥¹ID
4314 static void process_monsters_mtimed_aux(int m_idx, int mtimed_idx)
4316 monster_type *m_ptr = &m_list[m_idx];
4322 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4324 /* Assume does not wake up */
4327 /* Hack -- Require proximity */
4328 if (m_ptr->cdis < AAF_LIMIT)
4330 /* Handle "sensing radius" */
4331 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
4333 /* We may wake up */
4337 /* Handle "sight" and "aggravation" */
4338 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
4340 /* We may wake up */
4347 u32b notice = randint0(1024);
4349 /* Nightmare monsters are more alert */
4350 if (ironman_nightmare) notice /= 2;
4352 /* Hack -- See if monster "notices" player */
4353 if ((notice * notice * notice) <= csleep_noise)
4355 /* Hack -- amount of "waking" */
4356 /* Wake up faster near the player */
4357 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
4359 /* Hack -- amount of "waking" is affected by speed of player */
4360 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
4363 /* Monster wakes up "a little bit" */
4366 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
4368 /* Notice the "not waking up" */
4369 if (is_original_ap_and_seen(m_ptr))
4371 /* Hack -- Count the ignores */
4372 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
4379 /* Notice the "waking up" */
4384 /* Acquire the monster name */
4385 monster_desc(m_name, m_ptr, 0);
4387 /* Dump a message */
4389 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
4391 msg_format("%^s wakes up.", m_name);
4395 if (is_original_ap_and_seen(m_ptr))
4397 /* Hack -- Count the wakings */
4398 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
4407 /* Reduce by one, note if expires */
4408 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
4414 /* Acquire the monster name */
4415 monster_desc(m_name, m_ptr, 0);
4417 /* Dump a message */
4419 msg_format("%^s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
4421 msg_format("%^s is no longer fast.", m_name);
4428 /* Reduce by one, note if expires */
4429 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
4435 /* Acquire the monster name */
4436 monster_desc(m_name, m_ptr, 0);
4438 /* Dump a message */
4440 msg_format("%^s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
4442 msg_format("%^s is no longer slow.", m_name);
4448 case MTIMED_STUNNED:
4450 int rlev = r_info[m_ptr->r_idx].level;
4452 /* Recover from stun */
4453 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
4455 /* Message if visible */
4460 /* Acquire the monster name */
4461 monster_desc(m_name, m_ptr, 0);
4463 /* Dump a message */
4465 msg_format("%^s¤ÏÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤Ã¤¿¡£", m_name);
4467 msg_format("%^s is no longer stunned.", m_name);
4474 case MTIMED_CONFUSED:
4475 /* Reduce the confusion */
4476 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
4478 /* Message if visible */
4483 /* Acquire the monster name */
4484 monster_desc(m_name, m_ptr, 0);
4486 /* Dump a message */
4488 msg_format("%^s¤Ïº®Í𤫤éΩ¤Áľ¤Ã¤¿¡£", m_name);
4490 msg_format("%^s is no longer confused.", m_name);
4496 case MTIMED_MONFEAR:
4497 /* Reduce the fear */
4498 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
4507 /* Acquire the monster possessive */
4508 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
4511 /* Acquire the monster name */
4512 monster_desc(m_name, m_ptr, 0);
4514 /* Dump a message */
4516 msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name);
4518 msg_format("%^s recovers %s courage.", m_name, m_poss);
4524 case MTIMED_INVULNER:
4525 /* Reduce by one, note if expires */
4526 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
4532 /* Acquire the monster name */
4533 monster_desc(m_name, m_ptr, 0);
4535 /* Dump a message */
4537 msg_format("%^s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ê¤¤¡£", m_name);
4539 msg_format("%^s is no longer invulnerable.", m_name);
4549 * @brief Á´¥â¥ó¥¹¥¿¡¼¤Î³Æ¼ï¾õÂÖÃͤò»þ´Ö·Ð²á¤Ë¤è¤ê¹¹¿·¤¹¤ë¥á¥¤¥ó¥ë¡¼¥Á¥ó
4550 * @param mtimed_idx ¹¹¿·¤¹¤ë¥â¥ó¥¹¥¿¡¼¤Î»þ¸Â¥¹¥Æ¡¼¥¿¥¹ID
4553 * Process the counters of monsters (once per 10 game turns)\n
4554 * These functions are to process monsters' counters same as player's.
4556 void process_monsters_mtimed(int mtimed_idx)
4559 s16b *cur_mproc_list = mproc_list[mtimed_idx];
4561 /* Hack -- calculate the "player noise" */
4562 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
4564 /* Process the monsters (backwards) */
4565 for (i = mproc_max[mtimed_idx] - 1; i >= 0; i--)
4567 /* Access the monster */
4568 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
4573 * @brief ¥â¥ó¥¹¥¿¡¼¤Ø¤ÎËâÎϾõî½èÍý
4574 * @param m_idx ËâÎϾõî¤ò¼õ¤±¤ë¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
4577 void dispel_monster_status(int m_idx)
4579 monster_type *m_ptr = &m_list[m_idx];
4582 monster_desc(m_name, m_ptr, 0);
4583 if (set_monster_invulner(m_idx, 0, TRUE))
4586 if (m_ptr->ml) msg_format("%s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ï¤Ê¤¤¡£", m_name);
4588 if (m_ptr->ml) msg_format("%^s is no longer invulnerable.", m_name);
4591 if (set_monster_fast(m_idx, 0))
4594 if (m_ptr->ml) msg_format("%s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
4596 if (m_ptr->ml) msg_format("%^s is no longer fast.", m_name);
4599 if (set_monster_slow(m_idx, 0))
4602 if (m_ptr->ml) msg_format("%s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
4604 if (m_ptr->ml) msg_format("%^s is no longer slow.", m_name);
4610 * @brief ¥â¥ó¥¹¥¿¡¼¤Î»þ´ÖÄä»ß½èÍý
4611 * @param num »þ´ÖÄä»ß¤ò¹Ô¤Ã¤¿Å¨¤¬¹ÔÆ°¤Ç¤¤ë²ó¿ô
4612 * @param who »þ´ÖÄä»ß½èÍý¤Î¼çÂÎID
4613 * @param vs_player TRUE¤Ê¤é¤Ð»þ´ÖÄä»ß³«»Ï½èÍý¤ò¹Ô¤¦
4614 * @return »þ´ÖÄä»ß¤¬¹Ô¤ï¤ì¤Æ¤¤¤ë¾õÂ֤ʤé¤ÐTRUE¤òÊÖ¤¹
4616 bool process_the_world(int num, int who, bool vs_player)
4618 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
4620 if(world_monster) return (FALSE);
4625 monster_desc(m_name, m_ptr, 0);
4629 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
4631 msg_format("%s yells 'The World! Time has stopped!'", m_name);
4635 msg_print("¡Ö»þ¤è¡ª¡×");
4637 msg_format("%s yells 'Time!'", m_name);
4639 else msg_print("hek!");
4644 /* This monster cast spells */
4645 world_monster = hack_m_idx;
4647 if (vs_player) do_cmd_redraw();
4651 if(!m_ptr->r_idx) break;
4652 process_monster(world_monster);
4654 reset_target(m_ptr);
4657 if (p_ptr->notice) notice_stuff();
4660 if (p_ptr->update) update_stuff();
4663 if (p_ptr->redraw) redraw_stuff();
4666 if (p_ptr->window) window_stuff();
4669 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
4673 p_ptr->redraw |= (PR_MAP);
4675 /* Update monsters */
4676 p_ptr->update |= (PU_MONSTERS);
4679 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4682 if (vs_player || (player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
4685 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
4687 msg_print("You feel time flowing around you once more.");
4698 * @brief ¥â¥ó¥¹¥¿¡¼¤Î·Ð¸³ÃͼèÆÀ½èÍý
4699 * @param m_idx ·Ð¸³ÃͤòÆÀ¤ë¥â¥ó¥¹¥¿¡¼¤Î»²¾ÈID
4700 * @param s_idx ·âÇˤµ¤ì¤¿¥â¥ó¥¹¥¿¡¼¼ï²¤Î»²¾ÈID
4703 void monster_gain_exp(int m_idx, int s_idx)
4705 monster_type *m_ptr;
4706 monster_race *r_ptr;
4707 monster_race *s_ptr;
4711 if (m_idx <= 0 || s_idx <= 0) return;
4713 m_ptr = &m_list[m_idx];
4715 /* Paranoia -- Skip dead monsters */
4716 if (!m_ptr->r_idx) return;
4718 r_ptr = &r_info[m_ptr->r_idx];
4719 s_ptr = &r_info[s_idx];
4721 if (p_ptr->inside_battle) return;
4723 if (!r_ptr->next_exp) return;
4725 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
4726 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
4727 if (!dun_level) new_exp /= 5;
4728 m_ptr->exp += new_exp;
4729 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
4731 if (m_ptr->exp >= r_ptr->next_exp)
4734 int old_hp = m_ptr->hp;
4735 int old_maxhp = m_ptr->max_maxhp;
4736 int old_r_idx = m_ptr->r_idx;
4737 byte old_sub_align = m_ptr->sub_align;
4739 /* Hack -- Reduce the racial counter of previous monster */
4740 real_r_ptr(m_ptr)->cur_num--;
4742 monster_desc(m_name, m_ptr, 0);
4743 m_ptr->r_idx = r_ptr->next_r_idx;
4745 /* Count the monsters on the level */
4746 real_r_ptr(m_ptr)->cur_num++;
4748 m_ptr->ap_r_idx = m_ptr->r_idx;
4749 r_ptr = &r_info[m_ptr->r_idx];
4751 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
4753 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
4757 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
4759 if (ironman_nightmare)
4761 u32b hp = m_ptr->max_maxhp * 2L;
4763 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
4765 m_ptr->maxhp = m_ptr->max_maxhp;
4766 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
4768 /* dealt damage is 0 at initial*/
4769 m_ptr->dealt_damage = 0;
4771 /* Extract the monster base speed */
4772 m_ptr->mspeed = get_mspeed(r_ptr);
4774 /* Sub-alignment of a monster */
4775 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
4776 m_ptr->sub_align = old_sub_align;
4779 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
4780 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
4781 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
4786 if (is_pet(m_ptr) || m_ptr->ml)
4788 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
4792 monster_race *hallu_race;
4796 hallu_race = &r_info[randint1(max_r_idx - 1)];
4798 while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
4801 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + hallu_race->name);
4803 msg_format("%^s evolved into %s.", m_name, r_name + hallu_race->name);
4809 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
4811 msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
4816 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
4818 /* Now you feel very close to this pet. */
4819 m_ptr->parent_m_idx = 0;
4821 update_mon(m_idx, FALSE);
4822 lite_spot(m_ptr->fy, m_ptr->fx);
4824 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;