4 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: Monster spells and movement */
14 * This file has several additions to it by Keldon Jones (keldon@umr.edu)
15 * to improve the general quality of the AI (version 0.1.1).
20 #define SPEAK_CHANCE 8
25 * Calculate the direction to the next enemy
27 static bool get_enemy_dir(int m_idx, int *mm)
35 monster_type *m_ptr = &m_list[m_idx];
36 monster_race *r_ptr = &r_info[m_ptr->r_idx];
40 if (riding_t_m_idx && player_bold(m_ptr->fy, m_ptr->fx))
42 y = m_list[riding_t_m_idx].fy;
43 x = m_list[riding_t_m_idx].fx;
45 else if (is_pet(m_ptr) && pet_t_m_idx)
47 y = m_list[pet_t_m_idx].fy;
48 x = m_list[pet_t_m_idx].fx;
52 if (p_ptr->inside_battle)
54 start = randint1(m_max-1)+m_max;
55 if(randint0(2)) plus = -1;
57 else start = m_max + 1;
59 /* Scan thru all monsters */
60 for (i = start; ((i < start + m_max) && (i > start - m_max)); i+=plus)
62 int dummy = (i % m_max);
67 t_ptr = &m_list[t_idx];
69 /* The monster itself isn't a target */
70 if (t_ptr == m_ptr) continue;
72 /* Paranoia -- Skip dead monsters */
73 if (!t_ptr->r_idx) continue;
77 /* Hack -- only fight away from player */
78 if (p_ptr->pet_follow_distance < 0)
80 /* No fighting near player */
81 if (t_ptr->cdis <= (0 - p_ptr->pet_follow_distance))
86 /* Hack -- no fighting away from player */
87 else if ((m_ptr->cdis < t_ptr->cdis) &&
88 (t_ptr->cdis > p_ptr->pet_follow_distance))
93 if (r_ptr->aaf < t_ptr->cdis) continue;
96 /* Monster must be 'an enemy' */
97 if (!are_enemies(m_ptr, t_ptr)) continue;
99 /* Monster must be projectable if we can't pass through walls */
100 if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) ||
101 ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding)))
103 if (!in_disintegration_range(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
107 if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
110 /* OK -- we've got a target */
116 if (!x && !y) return FALSE;
119 /* Extract the direction */
124 if ((y < 0) && (x == 0))
131 else if ((y > 0) && (x == 0))
138 else if ((x > 0) && (y == 0))
145 else if ((x < 0) && (y == 0))
152 else if ((y < 0) && (x < 0))
159 else if ((y < 0) && (x > 0))
166 else if ((y > 0) && (x < 0))
173 else if ((y > 0) && (x > 0))
180 /* Found a monster */
186 * Hack, based on mon_take_hit... perhaps all monster attacks on
187 * other monsters should use this?
189 void mon_take_hit_mon(int m_idx, int dam, bool *fear, cptr note, int who)
191 monster_type *m_ptr = &m_list[m_idx];
193 monster_race *r_ptr = &r_info[m_ptr->r_idx];
197 bool seen = is_seen(m_ptr);
199 /* Can the player be aware of this attack? */
200 bool known = (m_ptr->cdis <= MAX_SIGHT);
202 /* Extract monster name */
203 monster_desc(m_name, m_ptr, 0);
205 /* Redraw (later) if needed */
208 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
209 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
213 (void)set_monster_csleep(m_idx, 0);
215 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 1);
217 if (MON_INVULNER(m_ptr) && randint0(PENETRATE_INVULNERABILITY))
222 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
224 msg_format("%^s is unharmed.", m_name);
232 if (r_ptr->flagsr & RFR_RES_ALL)
237 if((dam == 0) && one_in_(3)) dam = 1;
244 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
246 msg_format("%^s is unharmed.", m_name);
257 /* It is dead now... or is it? */
260 if (((r_ptr->flags1 & (RF1_UNIQUE | RF1_QUESTOR)) ||
261 (r_ptr->flags7 & RF7_NAZGUL)) &&
262 !p_ptr->inside_battle)
269 if (!monster_living(r_ptr))
280 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
281 /* Unseen death by normal attack */
286 /* Death by special attack */
290 msg_format("%^s%s", m_name, note);
292 msg_format("%^s%s", m_name, note);
296 /* Death by normal attack -- nonliving monster */
297 else if (!monster_living(r_ptr))
300 msg_format("%^s¤ÏÇ˲õ¤µ¤ì¤¿¡£", m_name);
302 msg_format("%^s is destroyed.", m_name);
306 /* Death by normal attack -- living monster */
310 msg_format("%^s¤Ï»¦¤µ¤ì¤¿¡£", m_name);
312 msg_format("%^s is killed.", m_name);
318 monster_gain_exp(who, m_ptr->r_idx);
320 /* Generate treasure */
321 monster_death(m_idx, FALSE);
323 /* Delete the monster */
324 delete_monster_idx(m_idx);
329 /* Monster is dead */
336 /* Mega-Hack -- Pain cancels fear */
337 if (MON_MONFEAR(m_ptr) && (dam > 0))
340 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(dam / 4)))
347 /* Sometimes a monster gets scared by damage */
348 if (!MON_MONFEAR(m_ptr) && !(r_ptr->flags3 & RF3_NO_FEAR))
350 /* Percentage of fully healthy */
351 int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
354 * Run (sometimes) if at 10% or less of max hit points,
355 * or (usually) when hit for half its current hit points
357 if (((percentage <= 10) && (randint0(10) < percentage)) ||
358 ((dam >= m_ptr->hp) && (randint0(100) < 80)))
360 /* Hack -- note fear */
363 /* XXX XXX XXX Hack -- Add some timed fear */
364 (void)set_monster_monfear(m_idx, (randint1(10) +
365 (((dam >= m_ptr->hp) && (percentage > 7)) ?
366 20 : ((11 - percentage) * 5))));
370 #endif /* ALLOW_FEAR */
372 if ((dam > 0) && !is_pet(m_ptr) && !is_friendly(m_ptr) && (who != m_idx))
374 if (is_pet(&m_list[who]) && !player_bold(m_ptr->target_y, m_ptr->target_x))
376 set_target(m_ptr, m_list[who].fy, m_list[who].fx);
380 if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
384 /* Extract monster name */
385 monster_desc(m_name, m_ptr, 0);
387 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
388 if (rakuba((dam > 200) ? 200 : dam, FALSE))
391 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
393 msg_format("You have thrown off from %s!", m_name);
404 * Returns whether a given monster will try to run from the player.
406 * Monsters will attempt to avoid very powerful players. See below.
408 * Because this function is called so often, little details are important
409 * for efficiency. Like not using "mod" or "div" when possible. And
410 * attempting to check the conditions in an optimal order. Note that
411 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.
413 * Note that this function is responsible for about one to five percent
414 * of the processor use in normal conditions...
416 static int mon_will_run(int m_idx)
418 monster_type *m_ptr = &m_list[m_idx];
422 monster_race *r_ptr = &r_info[m_ptr->r_idx];
431 /* Friends can be commanded to avoid the player */
434 /* Are we trying to avoid the player? */
435 return ((p_ptr->pet_follow_distance < 0) &&
436 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
439 /* Keep monsters from running too far away */
440 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
442 /* All "afraid" monsters will run away */
443 if (MON_MONFEAR(m_ptr)) return (TRUE);
447 /* Nearby monsters will not become terrified */
448 if (m_ptr->cdis <= 5) return (FALSE);
450 /* Examine player power (level) */
453 /* Examine monster power (level plus morale) */
454 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
456 /* Optimize extreme cases below */
457 if (m_lev > p_lev + 4) return (FALSE);
458 if (m_lev + 4 <= p_lev) return (TRUE);
460 /* Examine player health */
464 /* Examine monster health */
466 m_mhp = m_ptr->maxhp;
468 /* Prepare to optimize the calculation */
469 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
470 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
472 /* Strong players scare strong monsters */
473 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
477 /* Assume no terror */
485 * Search spell castable grid
487 static bool get_moves_aux2(int m_idx, int *yp, int *xp)
489 int i, y, x, y1, x1, best = 999;
492 bool can_open_door = FALSE;
495 monster_type *m_ptr = &m_list[m_idx];
496 monster_race *r_ptr = &r_info[m_ptr->r_idx];
498 /* Monster location */
502 /* Monster can already cast spell to player */
503 if (projectable(y1, x1, py, px)) return (FALSE);
505 /* Set current grid cost */
506 now_cost = cave[y1][x1].cost;
507 if (now_cost == 0) now_cost = 999;
509 /* Can monster bash or open doors? */
510 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
512 can_open_door = TRUE;
515 /* Check nearby grids, diagonals first */
516 for (i = 7; i >= 0; i--)
520 /* Get the location */
524 /* Ignore locations off of edge */
525 if (!in_bounds2(y, x)) continue;
527 /* Simply move to player */
528 if (player_bold(y, x)) return (FALSE);
534 /* Monster cannot kill or pass walls */
535 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))))
537 if (cost == 0) continue;
538 if (!can_open_door && is_closed_door(c_ptr->feat)) continue;
541 /* Hack -- for kill or pass wall monster.. */
542 if (cost == 0) cost = 998;
544 if (now_cost < cost) continue;
546 if (!projectable(y, x, py, px)) continue;
548 /* Accept louder sounds */
549 if (best < cost) continue;
552 (*yp) = y1 + ddy_ddd[i];
553 (*xp) = x1 + ddx_ddd[i];
556 /* No legal move (?) */
557 if (best == 999) return (FALSE);
565 * Choose the "best" direction for "flowing"
567 * Note that ghosts and rock-eaters are never allowed to "flow",
568 * since they should move directly towards the player.
570 * Prefer "non-diagonal" directions, but twiddle them a little
571 * to angle slightly towards the player's actual location.
573 * Allow very perceptive monsters to track old "spoor" left by
574 * previous locations occupied by the player. This will tend
575 * to have monsters end up either near the player or on a grid
576 * recently occupied by the player (and left via "teleport").
578 * Note that if "smell" is turned on, all monsters get vicious.
580 * Also note that teleporting away from a location will cause
581 * the monsters who were chasing you to converge on that location
582 * as long as you are still near enough to "annoy" them without
583 * being close enough to chase directly. I have no idea what will
584 * happen if you combine "smell" with low "aaf" values.
586 static bool get_moves_aux(int m_idx, int *yp, int *xp, bool no_flow)
588 int i, y, x, y1, x1, best;
591 bool use_scent = FALSE;
593 monster_type *m_ptr = &m_list[m_idx];
594 monster_race *r_ptr = &r_info[m_ptr->r_idx];
596 /* Can monster cast attack spell? */
597 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
598 r_ptr->flags5 & (RF5_ATTACK_MASK) ||
599 r_ptr->flags6 & (RF6_ATTACK_MASK))
601 /* Can move spell castable grid? */
602 if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
605 /* Monster can't flow */
606 if (no_flow) return (FALSE);
608 /* Monster can go through rocks */
609 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) return (FALSE);
610 if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding)) return (FALSE);
612 /* Monster location */
616 /* Hack -- Player can see us, run towards him */
617 if (player_has_los_bold(y1, x1) && projectable(py, px, y1, x1)) return (FALSE);
620 c_ptr = &cave[y1][x1];
622 /* If we can hear noises, advance towards them */
628 /* Otherwise, try to follow a scent trail */
629 else if (c_ptr->when)
632 if (cave[py][px].when - c_ptr->when > 127) return (FALSE);
638 /* Otherwise, advance blindly */
644 /* Check nearby grids, diagonals first */
645 for (i = 7; i >= 0; i--)
647 /* Get the location */
651 /* Ignore locations off of edge */
652 if (!in_bounds2(y, x)) continue;
656 /* We're following a scent trail */
659 int when = c_ptr->when;
661 /* Accept younger scent */
662 if (best > when) continue;
666 /* We're using sound */
671 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
673 else cost = c_ptr->cost;
675 /* Accept louder sounds */
676 if ((cost == 0) || (best < cost)) continue;
680 /* Hack -- Save the "twiddled" location */
681 (*yp) = py + 16 * ddy_ddd[i];
682 (*xp) = px + 16 * ddx_ddd[i];
685 /* No legal move (?) */
686 if (best == 999 || best == 0) return (FALSE);
694 * Provide a location to flee to, but give the player a wide berth.
696 * A monster may wish to flee to a location that is behind the player,
697 * but instead of heading directly for it, the monster should "swerve"
698 * around the player so that he has a smaller chance of getting hit.
700 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
702 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
706 monster_type *m_ptr = &m_list[m_idx];
708 /* Monster location */
712 /* Desired destination */
716 /* Check nearby grids, diagonals first */
717 for (i = 7; i >= 0; i--)
721 /* Get the location */
725 /* Ignore locations off of edge */
726 if (!in_bounds2(y, x)) continue;
728 /* Don't move toward player */
729 /* if (cave[y][x].dist < 3) continue; */ /* Hmm.. Need it? */
731 /* Calculate distance of this grid from our destination */
732 dis = distance(y, x, y1, x1);
734 /* Score this grid */
735 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
737 /* No negative scores */
740 /* Ignore lower scores */
741 if (s < score) continue;
743 /* Save the score and time */
746 /* Save the location */
751 /* No legal move (?) */
752 if (score == -1) return (FALSE);
763 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
766 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
767 * offsets of all the locations with a distance of n from a central point,
768 * with an offset of (0,0) indicating no more offsets at this distance.
770 * This is, of course, fairly unreadable, but it eliminates multiple loops
771 * from the previous version.
773 * It is probably better to replace these arrays with code to compute
774 * the relevant arrays, even if the storage is pre-allocated in hard
775 * coded sizes. At the very least, code should be included which is
776 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
778 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
780 * These arrays could be combined into two big arrays, using sub-arrays
781 * to hold the offsets and lengths of each portion of the sub-arrays, and
782 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
786 static sint d_off_y_0[] =
789 static sint d_off_x_0[] =
793 static sint d_off_y_1[] =
794 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
796 static sint d_off_x_1[] =
797 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
800 static sint d_off_y_2[] =
801 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
803 static sint d_off_x_2[] =
804 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
807 static sint d_off_y_3[] =
808 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
811 static sint d_off_x_3[] =
812 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
816 static sint d_off_y_4[] =
817 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
818 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
820 static sint d_off_x_4[] =
821 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
822 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
825 static sint d_off_y_5[] =
826 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
827 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
830 static sint d_off_x_5[] =
831 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
832 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
836 static sint d_off_y_6[] =
837 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
838 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
841 static sint d_off_x_6[] =
842 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
843 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
844 -3, 2, 3, -1, 0, 1, 0 };
847 static sint d_off_y_7[] =
848 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
849 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
850 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
852 static sint d_off_x_7[] =
853 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
854 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
855 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
859 static sint d_off_y_8[] =
860 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
861 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
862 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
865 static sint d_off_x_8[] =
866 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
867 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
868 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
872 static sint d_off_y_9[] =
873 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
874 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
875 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
876 7, 8, 8, 8, 8, 9, 9, 9, 0 };
878 static sint d_off_x_9[] =
879 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
880 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
881 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
882 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
885 static sint *dist_offsets_y[10] =
887 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
888 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
891 static sint *dist_offsets_x[10] =
893 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
894 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
898 * Choose a "safe" location near a monster for it to run toward.
900 * A location is "safe" if it can be reached quickly and the player
901 * is not able to fire into it (it isn't a "clean shot"). So, this will
902 * cause monsters to "duck" behind walls. Hopefully, monsters will also
903 * try to run towards corridor openings if they are in a room.
905 * This function may take lots of CPU time if lots of monsters are
908 * Return TRUE if a safe location is available.
910 static bool find_safety(int m_idx, int *yp, int *xp)
912 monster_type *m_ptr = &m_list[m_idx];
917 int y, x, dy, dx, d, dis, i;
918 int gy = 0, gx = 0, gdis = 0;
925 /* Start with adjacent locations, spread further */
926 for (d = 1; d < 10; d++)
928 /* Get the lists of points with a distance d from (fx, fy) */
929 y_offsets = dist_offsets_y[d];
930 x_offsets = dist_offsets_x[d];
932 /* Check the locations */
933 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
935 i++, dx = x_offsets[i], dy = y_offsets[i])
940 /* Skip illegal locations */
941 if (!in_bounds(y, x)) continue;
945 /* Skip locations in a wall */
946 if (!monster_can_cross_terrain(c_ptr->feat, &r_info[m_ptr->r_idx], (m_idx == p_ptr->riding) ? CEM_RIDING : 0)) continue;
948 /* Check for "availability" (if monsters can flow) */
949 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
951 /* Ignore grids very far from the player */
952 if (c_ptr->dist == 0) continue;
954 /* Ignore too-distant grids */
955 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
958 /* Check for absence of shot (more or less) */
959 if (!projectable(py, px, y, x))
961 /* Calculate distance from player */
962 dis = distance(y, x, py, px);
964 /* Remember if further than previous */
974 /* Check for success */
981 /* Found safe place */
992 * Choose a good hiding place near a monster for it to run toward.
994 * Pack monsters will use this to "ambush" the player and lure him out
995 * of corridors into open space so they can swarm him.
997 * Return TRUE if a good location is available.
999 static bool find_hiding(int m_idx, int *yp, int *xp)
1001 monster_type *m_ptr = &m_list[m_idx];
1002 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1007 int y, x, dy, dx, d, dis, i;
1008 int gy = 0, gx = 0, gdis = 999;
1010 sint *y_offsets, *x_offsets;
1012 /* Start with adjacent locations, spread further */
1013 for (d = 1; d < 10; d++)
1015 /* Get the lists of points with a distance d from (fx, fy) */
1016 y_offsets = dist_offsets_y[d];
1017 x_offsets = dist_offsets_x[d];
1019 /* Check the locations */
1020 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
1022 i++, dx = x_offsets[i], dy = y_offsets[i])
1027 /* Skip illegal locations */
1028 if (!in_bounds(y, x)) continue;
1030 /* Skip occupied locations */
1031 if (!monster_can_enter(y, x, r_ptr, 0)) continue;
1033 /* Check for hidden, available grid */
1034 if (!projectable(py, px, y, x) && clean_shot(fy, fx, y, x, FALSE))
1036 /* Calculate distance from player */
1037 dis = distance(y, x, py, px);
1039 /* Remember if closer than previous */
1040 if (dis < gdis && dis >= 2)
1049 /* Check for success */
1056 /* Found good place */
1067 * Choose "logical" directions for monster movement
1069 static bool get_moves(int m_idx, int *mm)
1071 monster_type *m_ptr = &m_list[m_idx];
1072 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1078 bool will_run = mon_will_run(m_idx);
1080 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1081 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall));
1083 /* Counter attack to an enemy monster */
1084 if (!will_run && m_ptr->target_y)
1086 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
1088 /* The monster must be an enemy, and in LOS */
1090 are_enemies(m_ptr, &m_list[t_m_idx]) &&
1091 los(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
1092 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1094 /* Extract the "pseudo-direction" */
1095 y = m_ptr->fy - m_ptr->target_y;
1096 x = m_ptr->fx - m_ptr->target_x;
1101 if (!done && !will_run && is_hostile(m_ptr) &&
1102 (r_ptr->flags1 & RF1_FRIENDS) &&
1103 ((los(m_ptr->fy, m_ptr->fx, py, px) && projectable(m_ptr->fy, m_ptr->fx, py, px)) ||
1104 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1107 * Animal packs try to get the player out of corridors
1108 * (...unless they can move through walls -- TY)
1110 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1111 !(r_ptr->flags2 & RF2_KILL_WALL))
1115 /* Count room grids next to player */
1116 for (i = 0; i < 8; i++)
1118 int xx = px + ddx_ddd[i];
1119 int yy = py + ddy_ddd[i];
1121 if (!in_bounds2(yy, xx)) continue;
1123 c_ptr = &cave[yy][xx];
1126 if (monster_can_cross_terrain(c_ptr->feat, r_ptr, 0))
1128 /* One more room grid */
1132 if (cave[py][px].info & CAVE_ROOM) room -= 2;
1133 if (!r_ptr->flags4 && !r_ptr->flags5 && !r_ptr->flags6) room -= 2;
1135 /* Not in a room and strong player */
1136 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
1137 (p_ptr->mhp + p_ptr->msp))
1139 /* Find hiding place */
1140 if (find_hiding(m_idx, &y, &x)) done = TRUE;
1144 /* Monster groups try to surround the player */
1145 if (!done && (cave[m_ptr->fy][m_ptr->fx].dist < 3))
1149 /* Find an empty square near the player to fill */
1150 for (i = 0; i < 8; i++)
1152 /* Pick squares near player (semi-randomly) */
1153 y2 = py + ddy_ddd[(m_idx + i) & 7];
1154 x2 = px + ddx_ddd[(m_idx + i) & 7];
1156 /* Already there? */
1157 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
1159 /* Attack the player */
1166 if (!in_bounds2(y2, x2)) continue;
1168 /* Ignore filled grids */
1169 if (!monster_can_enter(y2, x2, r_ptr, 0)) continue;
1171 /* Try to fill this hole */
1175 /* Extract the new "pseudo-direction" */
1186 /* Flow towards the player */
1187 (void)get_moves_aux(m_idx, &y2, &x2, no_flow);
1189 /* Extract the "pseudo-direction" */
1196 /* Apply fear if possible and necessary */
1197 if (is_pet(m_ptr) && will_run)
1199 /* XXX XXX Not very "smart" */
1204 if (!done && will_run)
1209 /* Try to find safe place */
1210 if (find_safety(m_idx, &y, &x))
1212 /* Attempt to avoid the player */
1215 /* Adjust movement */
1216 if (get_fear_moves_aux(m_idx, &y, &x)) done = TRUE;
1222 /* This is not a very "smart" method XXX XXX */
1230 /* Check for no move */
1231 if (!x && !y) return (FALSE);
1234 /* Extract the "absolute distances" */
1238 /* Do something weird */
1239 if (y < 0) move_val += 8;
1240 if (x > 0) move_val += 4;
1242 /* Prevent the diamond maneuvre */
1243 if (ay > (ax << 1)) move_val += 2;
1244 else if (ax > (ay << 1)) move_val++;
1246 /* Extract some directions */
1391 /* Wants to move... */
1396 static int check_hit2(int power, int level, int ac, int stun)
1400 /* Percentile dice */
1403 if (stun && one_in_(2)) return FALSE;
1405 /* Hack -- Always miss or hit */
1406 if (k < 10) return (k < 5);
1408 /* Calculate the "attack quality" */
1409 i = (power + (level * 3));
1411 /* Power and Level compete against Armor */
1412 if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
1419 #define BLOW_EFFECT_TYPE_NONE 0
1420 #define BLOW_EFFECT_TYPE_FEAR 1
1421 #define BLOW_EFFECT_TYPE_SLEEP 2
1422 #define BLOW_EFFECT_TYPE_HEAL 3
1425 /* Monster attacks monster */
1426 static bool monst_attack_monst(int m_idx, int t_idx)
1428 monster_type *m_ptr = &m_list[m_idx];
1429 monster_type *t_ptr = &m_list[t_idx];
1431 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1432 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1436 char m_name[80], t_name[80];
1437 char temp[MAX_NLEN];
1439 bool explode = FALSE, touched = FALSE, fear = FALSE;
1440 int y_saver = t_ptr->fy;
1441 int x_saver = t_ptr->fx;
1444 bool see_m = is_seen(m_ptr);
1445 bool see_t = is_seen(t_ptr);
1446 bool see_either = see_m || see_t;
1448 /* Can the player be aware of this attack? */
1449 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1450 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1452 /* Cannot attack self */
1453 if (m_idx == t_idx) return FALSE;
1455 /* Not allowed to attack */
1456 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1458 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1463 /* Extract the effective monster level */
1464 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1466 /* Get the monster name (or "it") */
1467 monster_desc(m_name, m_ptr, 0);
1469 /* Get the monster name (or "it") */
1470 monster_desc(t_name, t_ptr, 0);
1472 /* Assume no blink */
1475 if (!see_either && known)
1480 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 1);
1482 /* Scan through all four blows */
1483 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1485 bool obvious = FALSE;
1492 /* Extract the attack infomation */
1493 int effect = r_ptr->blow[ap_cnt].effect;
1494 int method = r_ptr->blow[ap_cnt].method;
1495 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1496 int d_side = r_ptr->blow[ap_cnt].d_side;
1498 if (!m_ptr->r_idx) break;
1500 /* Stop attacking if the target dies! */
1501 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1504 /* Hack -- no more attacks */
1507 if (method == RBM_SHOOT) continue;
1509 /* Extract the attack "power" */
1510 power = mbe_info[effect].power;
1513 if (!effect || check_hit2(power, rlev, ac, MON_STUNNED(m_ptr)))
1516 (void)set_monster_csleep(t_idx, 0);
1520 /* Redraw the health bar */
1521 if (p_ptr->health_who == t_idx) p_ptr->redraw |= (PR_HEALTH);
1522 if (p_ptr->riding == t_idx) p_ptr->redraw |= (PR_UHEALTH);
1525 /* Describe the attack method */
1531 act = "%s¤ò²¥¤Ã¤¿¡£";
1543 act = "%s¤ò¿¨¤Ã¤¿¡£";
1545 act = "touches %s.";
1555 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1557 act = "punches %s.";
1567 act = "%s¤ò½³¤Ã¤¿¡£";
1579 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1591 act = "%s¤ò³ú¤ó¤À¡£";
1603 act = "%s¤ò»É¤·¤¿¡£";
1615 act = "%s¤ò»Â¤Ã¤¿¡£";
1617 act = "slashes %s.";
1626 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1638 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1640 act = "crushes %s.";
1650 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1652 act = "engulfs %s.";
1662 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1664 act = "charges %s.";
1674 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1676 act = "crawls on %s.";
1686 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1688 act = "drools on %s.";
1698 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1700 act = "spits on %s.";
1709 if (see_either) disturb(1, 1);
1724 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1726 act = "gazes at %s.";
1736 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1738 act = "wails at %s.";
1748 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1750 act = "releases spores at %s.";
1760 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1762 act = "projects XXX4's at %s.";
1772 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1774 act = "begs %s for money.";
1784 act = "%s¤òÉî¿«¤·¤¿¡£";
1786 act = "insults %s.";
1796 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1798 act = "moans at %s.";
1808 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1810 act = "sings to %s.";
1819 if (act && see_either)
1822 if (do_silly_attack) act = silly_attacks2[randint0(MAX_SILLY_ATTACK)];
1823 strfmt(temp, act, t_name);
1824 msg_format("%^s¤Ï%s", m_name, temp);
1826 if (do_silly_attack)
1828 act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
1829 strfmt(temp, "%s %s.", act, t_name);
1831 else strfmt(temp, act, t_name);
1832 msg_format("%^s %s", m_name, temp);
1836 /* Hack -- assume all attacks are obvious */
1839 /* Roll out the damage */
1840 damage = damroll(d_dice, d_side);
1842 /* Assume no effect */
1843 effect_type = BLOW_EFFECT_TYPE_NONE;
1847 /* Apply appropriate damage */
1856 if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13))
1858 int tmp_damage = damage - (damage * ((ac < 150) ? ac : 150) / 250);
1859 damage = MAX(damage, tmp_damage * 2);
1866 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1881 if ((p_ptr->riding != m_idx) && one_in_(2)) blinked = TRUE;
1917 effect_type = BLOW_EFFECT_TYPE_FEAR;
1921 effect_type = BLOW_EFFECT_TYPE_SLEEP;
1925 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1926 if (damage > 23) earthquake_aux(m_ptr->fy, m_ptr->fx, 8, m_idx);
1942 effect_type = BLOW_EFFECT_TYPE_HEAL;
1960 /* Do damage if not exploding */
1963 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1964 damage, pt, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1967 switch (effect_type)
1969 case BLOW_EFFECT_TYPE_FEAR:
1970 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1971 damage, GF_TURN_ALL, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1974 case BLOW_EFFECT_TYPE_SLEEP:
1975 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1976 r_ptr->level, GF_OLD_SLEEP, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
1979 case BLOW_EFFECT_TYPE_HEAL:
1980 if ((monster_living(tr_ptr)) && (damage > 2))
1982 bool did_heal = FALSE;
1984 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
1987 m_ptr->hp += damroll(4, damage / 6);
1988 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
1990 /* Redraw (later) if needed */
1991 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1992 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1994 /* Special message */
1995 if (see_m && did_heal)
1998 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
2000 msg_format("%^s appears healthier.", m_name);
2010 if ((tr_ptr->flags2 & RF2_AURA_FIRE) && m_ptr->r_idx)
2012 if (!(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
2017 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2019 msg_format("%^s is suddenly very hot!", m_name);
2022 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2023 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2024 damroll (1 + ((tr_ptr->level) / 26),
2025 1 + ((tr_ptr->level) / 17)),
2026 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2030 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
2035 if ((tr_ptr->flags3 & RF3_AURA_COLD) && m_ptr->r_idx)
2037 if (!(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK))
2042 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2044 msg_format("%^s is suddenly very cold!", m_name);
2047 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags3 |= RF3_AURA_COLD;
2048 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2049 damroll (1 + ((tr_ptr->level) / 26),
2050 1 + ((tr_ptr->level) / 17)),
2051 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2055 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
2060 if ((tr_ptr->flags2 & RF2_AURA_ELEC) && m_ptr->r_idx)
2062 if (!(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK))
2067 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2069 msg_format("%^s gets zapped!", m_name);
2072 if (m_ptr->ml && is_original_ap_and_seen(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_ELEC;
2073 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2074 damroll (1 + ((tr_ptr->level) / 26),
2075 1 + ((tr_ptr->level) / 17)),
2076 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2080 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
2087 /* Monster missed player */
2090 /* Analyze failed attacks */
2107 (void)set_monster_csleep(t_idx, 0);
2109 /* Visible monsters */
2114 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2116 msg_format("%^s misses %s.", m_name, t_name);
2126 /* Analyze "visible" monsters only */
2127 if (is_original_ap_and_seen(m_ptr) && !do_silly_attack)
2129 /* Count "obvious" attacks (and ones that cause damage) */
2130 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2132 /* Count attacks of this type */
2133 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2135 r_ptr->r_blows[ap_cnt]++;
2143 sound(SOUND_EXPLODE);
2145 /* Cancel Invulnerability */
2146 (void)set_monster_invulner(m_idx, 0, FALSE);
2149 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2151 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2158 if (blinked && m_ptr->r_idx)
2160 if (teleport_barrier(m_idx))
2165 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²...¤è¤¦¤È¤·¤¿¤¬¥Ð¥ê¥¢¤ËËɤ¬¤ì¤¿¡£");
2167 msg_print("The thief flees laughing...? But magic barrier obstructs it.");
2180 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2182 msg_print("The thief flees laughing!");
2190 teleport_away(m_idx, MAX_SIGHT * 2 + 5, 0L);
2198 static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
2200 return !have_flag(f_ptr->flags, FF_GLASS) ||
2201 (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
2202 (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
2209 * The monster is known to be within 100 grids of the player
2211 * In several cases, we directly update the monster lore
2213 * Note that a monster is only allowed to "reproduce" if there
2214 * are a limited number of "reproducing" monsters on the current
2215 * level. This should prevent the level from being "swamped" by
2216 * reproducing monsters. It also allows a large mass of mice to
2217 * prevent a louse from multiplying, but this is a small price to
2218 * pay for a simple multiplication method.
2220 * XXX Monster fear is slightly odd, in particular, monsters will
2221 * fixate on opening a door even if they cannot open it. Actually,
2222 * the same thing happens to normal monsters when they hit a door
2224 * XXX XXX XXX In addition, monsters which *cannot* open or bash
2225 * down a door will still stand there trying to open it...
2227 * XXX Technically, need to check for monster in the way
2228 * combined with that monster being in a wall (or door?)
2230 * A "direction" of "5" means "pick a random direction".
2232 static void process_monster(int m_idx)
2234 monster_type *m_ptr = &m_list[m_idx];
2235 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2236 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2238 int i, d, oy, ox, ny, nx;
2243 feature_type *f_ptr;
2245 monster_type *y_ptr;
2250 bool must_alter_to_move;
2259 bool gets_angry = FALSE;
2265 bool is_riding_mon = (m_idx == p_ptr->riding);
2267 bool see_m = is_seen(m_ptr);
2269 if (is_riding_mon && !(r_ptr->flags7 & RF7_RIDING))
2271 if (rakuba(0, TRUE))
2274 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2277 monster_desc(m_name, &m_list[p_ptr->riding], 0);
2278 msg_format("You have fallen from %s.", m_name);
2283 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
2285 choose_new_monster(m_idx, FALSE, 0);
2286 r_ptr = &r_info[m_ptr->r_idx];
2289 /* Players hidden in shadow are almost imperceptable. -LM- */
2290 if (p_ptr->special_defense & NINJA_S_STEALTH)
2292 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
2293 if (p_ptr->monlite) tmp /= 3;
2294 if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
2295 if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
2296 /* Low-level monsters will find it difficult to locate the player. */
2297 if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
2300 /* Are there its parent? */
2301 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
2303 /* Its parent have gone, it also goes away. */
2309 /* Acquire the monster name */
2310 monster_desc(m_name, m_ptr, 0);
2313 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2315 msg_format("%^s disappears!", m_name);
2319 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
2323 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
2324 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
2327 /* Delete the monster */
2328 delete_monster_idx(m_idx);
2333 /* Quantum monsters are odd */
2334 if (r_ptr->flags2 & (RF2_QUANTUM))
2336 /* Sometimes skip move */
2337 if (!randint0(2)) return;
2340 if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2344 if (is_pet(m_ptr) && !(m_ptr->ml))
2351 /* Acquire the monster name */
2352 monster_desc(m_name, m_ptr, 0);
2356 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2358 msg_format("%^s disappears!", m_name);
2362 /* Generate treasure, etc */
2363 monster_death(m_idx, FALSE);
2365 /* Delete the monster */
2366 delete_monster_idx(m_idx);
2371 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2373 msg_print("You feel sad for a moment.");
2381 if (m_ptr->r_idx == MON_SHURYUUDAN)
2383 mon_take_hit_mon(m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2385 mon_take_hit_mon(m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2388 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) && !p_ptr->inside_battle)
2390 static int riding_pinch = 0;
2392 if (m_ptr->hp < m_ptr->maxhp/3)
2395 monster_desc(m_name, m_ptr, 0);
2397 if (is_riding_mon && riding_pinch < 2)
2400 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2402 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
2412 msg_format("%s¤Ï¤¢¤Ê¤¿¤Î«Çû¤«¤éæ½Ð¤·¤¿¡£", m_name);
2414 msg_format("%^s succeeded to escape from your restriction!", m_name);
2416 if (rakuba(-1, FALSE))
2419 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2421 msg_print("You have fallen from riding pet.");
2428 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) &&
2429 player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(m_ptr->fy, m_ptr->fx, py, px))
2432 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2434 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2438 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2439 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2441 msg_format("%^s read a scroll of teleport level.", m_name);
2442 msg_format("%^s disappears.", m_name);
2446 if (is_riding_mon && rakuba(-1, FALSE))
2449 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2451 msg_print("You have fallen from riding pet.");
2455 /* Check for quest completion */
2456 check_quest_completion(m_ptr);
2458 delete_monster_idx(m_idx);
2465 /* Reset the counter */
2466 if (is_riding_mon) riding_pinch = 0;
2470 /* Handle "sleep" */
2471 if (MON_CSLEEP(m_ptr))
2473 /* Handle non-aggravation - Still sleeping */
2474 if (!(p_ptr->cursed & TRC_AGGRAVATE)) return;
2476 /* Handle aggravation */
2478 /* Reset sleep counter */
2479 (void)set_monster_csleep(m_idx, 0);
2481 /* Notice the "waking up" */
2486 /* Acquire the monster name */
2487 monster_desc(m_name, m_ptr, 0);
2489 /* Dump a message */
2491 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
2493 msg_format("%^s wakes up.", m_name);
2497 /* Hack -- Count the wakings */
2498 if (is_original_ap_and_seen(m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
2505 if (MON_STUNNED(m_ptr))
2507 /* Sometimes skip move */
2508 if (one_in_(2)) return;
2513 p_ptr->update |= (PU_BONUS);
2516 /* No one wants to be your friend if you're aggravating */
2517 if (is_friendly(m_ptr) && (p_ptr->cursed & TRC_AGGRAVATE))
2520 /* Paranoia... no pet uniques outside wizard mode -- TY */
2521 if (is_pet(m_ptr) &&
2522 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
2523 monster_has_hostile_align(NULL, 10, -10, r_ptr))
2524 || (r_ptr->flagsr & RFR_RES_ALL)))
2529 if (p_ptr->inside_battle) gets_angry = FALSE;
2533 if (is_pet(m_ptr) || see_m)
2536 monster_desc(m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
2538 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2540 msg_format("%^s suddenly becomes hostile!", m_name);
2547 /* Get the origin */
2552 /* Attempt to "multiply" if able and allowed */
2553 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2557 /* Count the adjacent monsters */
2558 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2560 for (x = ox - 1; x <= ox + 1; x++)
2562 /* Ignore locations off of edge */
2563 if (!in_bounds2(y, x)) continue;
2565 if (cave[y][x].m_idx) k++;
2570 if (multiply_barrier(m_idx)) k = 8;
2572 /* Hack -- multiply slower in crowded areas */
2573 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2575 /* Try to multiply */
2576 if (multiply_monster(m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
2578 /* Take note if visible */
2579 if (m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(m_ptr))
2581 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2584 /* Multiplying takes energy */
2591 if (r_ptr->flags6 & RF6_SPECIAL)
2593 /* Hack -- Ohmu scatters molds! */
2594 if (m_ptr->r_idx == MON_OHMU)
2596 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
2598 if (r_ptr->freq_spell && (randint1(100) <= r_ptr->freq_spell))
2601 int rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
2602 u32b p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
2604 for (k = 0; k < 6; k++)
2606 if (summon_specific(m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_BIZARRE1, (PM_ALLOW_GROUP | p_mode)))
2608 if (m_list[hack_m_idx_ii].ml) count++;
2612 if (count && is_original_ap_and_seen(m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
2619 if (!p_ptr->inside_battle)
2621 /* Hack! "Cyber" monster makes noise... */
2622 if (m_ptr->ap_r_idx == MON_CYBER &&
2623 one_in_(CYBERNOISE) &&
2624 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2626 if (disturb_minor) disturb(FALSE, FALSE);
2628 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2630 msg_print("You hear heavy steps.");
2634 /* Some monsters can speak */
2635 if ((ap_r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2636 one_in_(SPEAK_CHANCE) &&
2637 player_has_los_bold(oy, ox) &&
2638 projectable(oy, ox, py, px))
2641 char monmessage[1024];
2644 /* Acquire the monster name/poss */
2646 monster_desc(m_name, m_ptr, 0);
2649 strcpy(m_name, "¤½¤ì");
2651 strcpy(m_name, "It");
2654 /* Select the file for monster quotes */
2655 if (MON_MONFEAR(m_ptr))
2657 filename = "monfear_j.txt";
2659 filename = "monfear.txt";
2661 else if (is_pet(m_ptr))
2663 filename = "monpet_j.txt";
2665 filename = "monpet.txt";
2667 else if (is_friendly(m_ptr))
2669 filename = "monfrien_j.txt";
2671 filename = "monfrien.txt";
2675 filename = "monspeak_j.txt";
2677 filename = "monspeak.txt";
2679 /* Get the monster line */
2680 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
2684 msg_format("%^s%s", m_name, monmessage);
2686 msg_format("%^s %s", m_name, monmessage);
2693 /* Try to cast spell occasionally */
2694 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
2696 bool counterattack = FALSE;
2698 /* Give priority to counter attack? */
2699 if (m_ptr->target_y)
2701 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
2703 /* The monster must be an enemy, and projectable */
2705 are_enemies(m_ptr, &m_list[t_m_idx]) &&
2706 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
2708 counterattack = TRUE;
2714 /* Attempt to cast a spell */
2715 if (aware && make_attack_spell(m_idx)) return;
2718 * Attempt to cast a spell at an enemy other than the player
2719 * (may slow the game a smidgeon, but I haven't noticed.)
2721 if (monst_spell_monst(m_idx)) return;
2725 /* Attempt to do counter attack at first */
2726 if (monst_spell_monst(m_idx)) return;
2728 if (aware && make_attack_spell(m_idx)) return;
2732 /* Hack -- Assume no movement */
2733 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2734 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2737 /* Confused -- 100% random */
2738 if (MON_CONFUSED(m_ptr) || !aware)
2740 /* Try four "random" directions */
2741 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2744 /* 75% random movement */
2745 else if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) &&
2746 (randint0(100) < 75))
2748 /* Memorize flags */
2749 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
2751 /* Try four "random" directions */
2752 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2755 /* 50% random movement */
2756 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2757 (randint0(100) < 50))
2759 /* Memorize flags */
2760 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
2762 /* Try four "random" directions */
2763 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2766 /* 25% random movement */
2767 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2768 (randint0(100) < 25))
2770 /* Memorize flags */
2771 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
2773 /* Try four "random" directions */
2774 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2777 /* Can't reach player - find something else to hit */
2778 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2780 /* Try four "random" directions */
2781 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2783 /* Look for an enemy */
2784 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2785 get_enemy_dir(m_idx, mm);
2789 /* Pets will follow the player */
2790 else if (is_pet(m_ptr))
2792 /* Are we trying to avoid the player? */
2793 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
2794 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2796 /* Do we want to find the player? */
2797 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2799 /* Should we find the player if we can't find a monster? */
2800 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2802 /* by default, move randomly */
2803 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2805 /* Look for an enemy */
2806 if (!get_enemy_dir(m_idx, mm))
2808 /* Find the player if necessary */
2809 if (avoid || lonely || distant)
2811 /* Remember the leash length */
2812 int dis = p_ptr->pet_follow_distance;
2814 /* Hack -- adjust follow distance temporarily */
2815 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2817 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2820 /* Find the player */
2821 (void)get_moves(m_idx, mm);
2823 /* Restore the leash */
2824 p_ptr->pet_follow_distance = dis;
2829 /* Friendly monster movement */
2830 else if (!is_hostile(m_ptr))
2832 /* by default, move randomly */
2833 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2835 /* Look for an enemy */
2836 get_enemy_dir(m_idx, mm);
2838 /* Normal movement */
2841 /* Logical moves, may do nothing */
2842 if (!get_moves(m_idx, mm)) return;
2845 /* Assume nothing */
2849 must_alter_to_move = FALSE;
2851 /* Assume nothing */
2852 did_open_door = FALSE;
2853 did_bash_door = FALSE;
2854 did_take_item = FALSE;
2855 did_kill_item = FALSE;
2856 did_move_body = FALSE;
2857 did_pass_wall = FALSE;
2858 did_kill_wall = FALSE;
2861 /* Take a zero-terminated array of "directions" */
2862 for (i = 0; mm[i]; i++)
2864 /* Get the direction */
2867 /* Hack -- allow "randomized" motion */
2868 if (d == 5) d = ddd[randint0(8)];
2870 /* Get the destination */
2874 /* Ignore locations off of edge */
2875 if (!in_bounds2(ny, nx)) continue;
2877 /* Access that cave grid */
2878 c_ptr = &cave[ny][nx];
2879 f_ptr = &f_info[c_ptr->feat];
2880 can_cross = monster_can_cross_terrain(c_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0);
2882 /* Access that cave grid's contents */
2883 y_ptr = &m_list[c_ptr->m_idx];
2885 /* Hack -- player 'in' wall */
2886 if (player_bold(ny, nx))
2891 /* Possibly a monster to attack */
2892 else if (c_ptr->m_idx)
2897 /* Monster destroys walls (and doors) */
2898 else if ((r_ptr->flags2 & RF2_KILL_WALL) &&
2899 (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !is_riding_mon) &&
2900 have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
2901 check_hp_for_feat_destruction(f_ptr, m_ptr))
2903 /* Eat through walls/doors/rubble */
2905 if (!can_cross) must_alter_to_move = TRUE;
2907 /* Monster destroyed a wall (later) */
2908 did_kill_wall = TRUE;
2911 /* Floor is open? */
2914 /* Go ahead and move */
2917 /* Monster moves through walls (and doors) */
2918 if ((r_ptr->flags2 & RF2_PASS_WALL) && (!is_riding_mon || p_ptr->pass_wall) &&
2919 have_flag(f_ptr->flags, FF_CAN_PASS))
2921 /* Monster went through a wall */
2922 did_pass_wall = TRUE;
2926 /* Handle doors and secret doors */
2927 else if (is_closed_door(c_ptr->feat))
2929 bool may_bash = TRUE;
2931 /* Assume no move allowed */
2934 /* Creature can open doors. */
2935 if ((r_ptr->flags2 & RF2_OPEN_DOOR) && have_flag(f_ptr->flags, FF_OPEN) &&
2936 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2941 /* The door is open */
2942 did_open_door = TRUE;
2944 /* Do not bash the door */
2951 /* Locked doors (not jammed) */
2954 /* Try to unlock it XXX XXX XXX */
2955 if (randint0(m_ptr->hp / 10) > f_ptr->power)
2957 /* Unlock the door */
2958 cave_alter_feat(ny, nx, FF_DISARM);
2960 /* Do not bash the door */
2969 /* Stuck doors -- attempt to bash them down if allowed */
2970 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) && have_flag(f_ptr->flags, FF_BASH) &&
2971 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2973 /* Attempt to Bash XXX XXX XXX */
2974 if (check_hp_for_feat_destruction(f_ptr, m_ptr) && (randint0(m_ptr->hp / 10) > f_ptr->power))
2977 if (have_flag(f_ptr->flags, FF_GLASS))
2979 msg_print("¥¬¥é¥¹¤¬ºÕ¤±¤ë²»¤¬¤·¤¿¡ª");
2981 msg_print("You hear a glass was crashed!");
2985 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
2987 msg_print("You hear a door burst open!");
2990 /* Disturb (sometimes) */
2991 if (disturb_minor) disturb(0, 0);
2993 /* The door was bashed open */
2994 did_bash_door = TRUE;
2996 /* Hack -- fall into doorway */
2998 must_alter_to_move = TRUE;
3003 /* Deal with doors in the way */
3004 if (did_open_door || did_bash_door)
3006 /* Break down the door */
3007 if (did_bash_door && ((randint0(100) < 50) || (feat_state(c_ptr->feat, FF_OPEN) == c_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
3009 cave_alter_feat(ny, nx, FF_BASH);
3011 if (!m_ptr->r_idx) /* Killed by shards of glass, etc. */
3013 /* Update some things */
3014 p_ptr->update |= (PU_FLOW);
3015 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3016 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3025 cave_alter_feat(ny, nx, FF_OPEN);
3028 f_ptr = &f_info[c_ptr->feat];
3030 /* Handle viewable doors */
3035 /* Hack -- check for Glyph of Warding */
3036 if (do_move && is_glyph_grid(c_ptr) &&
3037 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3039 /* Assume no move allowed */
3042 /* Break the ward */
3043 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
3045 /* Describe observable breakage */
3046 if (c_ptr->info & CAVE_MARK)
3049 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3051 msg_print("The rune of protection is broken!");
3055 /* Forget the rune */
3056 c_ptr->info &= ~(CAVE_MARK);
3058 /* Break the rune */
3059 c_ptr->info &= ~(CAVE_OBJECT);
3062 /* Allow movement */
3069 else if (do_move && is_explosive_rune_grid(c_ptr) &&
3070 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3072 /* Assume no move allowed */
3075 /* Break the ward */
3078 /* Break the ward */
3079 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3081 /* Describe observable breakage */
3082 if (c_ptr->info & CAVE_MARK)
3085 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3087 msg_print("The rune explodes!");
3090 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);
3096 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3098 msg_print("An explosive rune was disarmed.");
3102 /* Forget the rune */
3103 c_ptr->info &= ~(CAVE_MARK);
3105 /* Break the rune */
3106 c_ptr->info &= ~(CAVE_OBJECT);
3112 if (!m_ptr->r_idx) return;
3113 /* Allow movement */
3118 /* The player is in the way */
3119 if (do_move && player_bold(ny, nx))
3121 /* Some monsters never attack */
3122 if (r_ptr->flags1 & RF1_NEVER_BLOW)
3124 /* Hack -- memorize lack of attacks */
3125 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3131 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
3132 if (do_move && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3134 if (!MON_CONFUSED(m_ptr))
3136 if (!(r_ptr->flags2 & RF2_STUPID)) do_move = FALSE;
3139 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
3144 /* The player is in the way. Attack him. */
3147 if (!p_ptr->riding || one_in_(2))
3150 (void)make_attack_normal(m_idx);
3161 /* A monster is in the way */
3162 if (do_move && c_ptr->m_idx)
3164 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3166 /* Assume no movement */
3169 /* Attack 'enemies' */
3170 if (((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW) &&
3171 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3172 can_cross && (c_ptr->m_idx != p_ptr->riding)) ||
3173 are_enemies(m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
3175 if (!(r_ptr->flags1 & RF1_NEVER_BLOW))
3177 if (r_ptr->flags2 & RF2_KILL_BODY)
3179 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3183 if (y_ptr->r_idx && (y_ptr->hp >= 0))
3185 if (monst_attack_monst(m_idx, c_ptr->m_idx)) return;
3187 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
3188 else if (d_info[dungeon_type].flags1 & DF1_NO_MELEE)
3190 if (MON_CONFUSED(m_ptr)) return;
3191 else if (r_ptr->flags2 & RF2_STUPID)
3193 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
3201 /* Push past weaker monsters (unless leaving a wall) */
3202 else if ((r_ptr->flags2 & RF2_MOVE_BODY) && !(r_ptr->flags1 & RF1_NEVER_MOVE) &&
3203 (r_ptr->mexp > z_ptr->mexp) &&
3204 can_cross && (c_ptr->m_idx != p_ptr->riding) &&
3205 monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
3207 /* Allow movement */
3210 /* Monster pushed past another monster */
3211 did_move_body = TRUE;
3213 /* Wake up the moved monster */
3214 (void)set_monster_csleep(c_ptr->m_idx, 0);
3216 /* XXX XXX XXX Message */
3222 if (!p_ptr->riding_ryoute && !MON_MONFEAR(&m_list[p_ptr->riding])) do_move = FALSE;
3225 if (did_kill_wall && do_move)
3227 if (one_in_(GRINDNOISE))
3229 if (have_flag(f_ptr->flags, FF_GLASS))
3231 msg_print("²¿¤«¤ÎºÕ¤±¤ë²»¤¬Ê¹¤³¤¨¤ë¡£");
3233 msg_print("There is a crashing sound.");
3237 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
3239 msg_print("There is a grinding sound.");
3243 cave_alter_feat(ny, nx, FF_HURT_DISI);
3245 if (!m_ptr->r_idx) /* Killed by shards of glass, etc. */
3247 /* Update some things */
3248 p_ptr->update |= (PU_FLOW);
3249 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3250 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3255 f_ptr = &f_info[c_ptr->feat];
3257 /* Note changes to viewable region */
3264 if (must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
3266 if (!monster_can_cross_terrain(c_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0))
3268 /* Assume no move allowed */
3274 * Check if monster can cross terrain
3275 * This is checked after the normal attacks
3276 * to allow monsters to attack an enemy,
3277 * even if it can't enter the terrain.
3279 if (do_move && !can_cross && !did_kill_wall && !did_bash_door)
3281 /* Assume no move allowed */
3285 /* Some monsters never move */
3286 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3288 /* Hack -- memorize lack of moves */
3289 if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3295 /* Creature has been allowed move */
3301 if (have_flag(f_ptr->flags, FF_TREE))
3303 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3305 m_ptr->energy_need += ENERGY_NEED();
3311 /* Hack -- Update the old location */
3312 cave[oy][ox].m_idx = c_ptr->m_idx;
3314 /* Mega-Hack -- move the old monster, if any */
3317 /* Move the old monster */
3321 /* Update the old monster */
3322 update_mon(c_ptr->m_idx, TRUE);
3325 /* Hack -- Update the new location */
3326 c_ptr->m_idx = m_idx;
3328 /* Move the monster */
3332 /* Update the monster */
3333 update_mon(m_idx, TRUE);
3335 /* Redraw the old grid */
3338 /* Redraw the new grid */
3344 /* sound(SOUND_WALK); */
3346 /* Move the player */
3347 if (!move_player_effect(ny, nx, MPE_DONT_PICKUP)) break;
3350 /* Possible disturb */
3353 (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(py, px, m_ptr->fy, m_ptr->fx)) ||
3354 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)))
3357 if (is_hostile(m_ptr))
3361 /* Take or Kill objects on the floor */
3362 if (c_ptr->o_idx && (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3363 (!is_pet(m_ptr) || ((p_ptr->pet_extra_flags & PF_PICKUP_ITEMS) && (r_ptr->flags2 & RF2_TAKE_ITEM))))
3365 s16b this_o_idx, next_o_idx;
3366 bool do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) ? TRUE : FALSE;
3368 /* Scan all objects in the grid */
3369 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3371 u32b flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
3372 char m_name[80], o_name[MAX_NLEN];
3374 /* Acquire object */
3375 object_type *o_ptr = &o_list[this_o_idx];
3377 /* Acquire next object */
3378 next_o_idx = o_ptr->next_o_idx;
3383 if (o_ptr->tval == TV_GOLD) continue;
3386 * Skip "real" corpses and statues, to avoid extreme
3387 * silliness like a novice rogue pockets full of statues
3390 if ((o_ptr->tval == TV_CORPSE) ||
3391 (o_ptr->tval == TV_STATUE)) continue;
3394 /* Extract some flags */
3395 object_flags(o_ptr, flgs);
3397 /* Acquire the object name */
3398 object_desc(o_name, o_ptr, 0);
3400 /* Acquire the monster name */
3401 monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
3403 /* React to objects that hurt the monster */
3404 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
3405 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
3406 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
3407 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
3408 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
3409 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
3410 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
3411 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
3412 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
3413 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
3414 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
3415 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
3416 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
3417 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
3418 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
3419 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
3420 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
3421 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
3422 if (have_flag(flgs, TR_BRAND_ACID)) flgr |= (RFR_IM_ACID);
3423 if (have_flag(flgs, TR_BRAND_ELEC)) flgr |= (RFR_IM_ELEC);
3424 if (have_flag(flgs, TR_BRAND_FIRE)) flgr |= (RFR_IM_FIRE);
3425 if (have_flag(flgs, TR_BRAND_COLD)) flgr |= (RFR_IM_COLD);
3426 if (have_flag(flgs, TR_BRAND_POIS)) flgr |= (RFR_IM_POIS);
3428 /* The object cannot be picked up by the monster */
3429 if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
3430 ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
3432 /* Only give a message for "take_item" */
3433 if (do_take && (r_ptr->flags2 & RF2_STUPID))
3436 did_take_item = TRUE;
3438 /* Describe observable situations */
3439 if (m_ptr->ml && player_can_see_bold(ny, nx))
3441 /* Dump a message */
3443 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£", m_name, o_name);
3445 msg_format("%^s tries to pick up %s, but fails.", m_name, o_name);
3451 /* Pick up the item */
3455 did_take_item = TRUE;
3457 /* Describe observable situations */
3458 if (player_can_see_bold(ny, nx))
3460 /* Dump a message */
3462 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3464 msg_format("%^s picks up %s.", m_name, o_name);
3468 /* Excise the object */
3469 excise_object_idx(this_o_idx);
3472 o_ptr->marked &= OM_TOUCHED;
3474 /* Forget location */
3475 o_ptr->iy = o_ptr->ix = 0;
3477 /* Memorize monster */
3478 o_ptr->held_m_idx = m_idx;
3481 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3484 m_ptr->hold_o_idx = this_o_idx;
3487 /* Destroy the item if not a pet */
3488 else if (!is_pet(m_ptr))
3491 did_kill_item = TRUE;
3493 /* Describe observable situations */
3494 if (player_has_los_bold(ny, nx))
3496 /* Dump a message */
3498 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3500 msg_format("%^s destroys %s.", m_name, o_name);
3504 /* Delete the object */
3505 delete_object_idx(this_o_idx);
3511 /* Stop when done */
3516 * Forward movements failed, but now received LOS attack!
3517 * Try to flow by smell.
3519 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3520 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3522 /* If we haven't done anything, try casting a spell again */
3523 if (!do_turn && !do_move && !MON_MONFEAR(m_ptr) && !is_riding_mon && aware)
3525 /* Try to cast spell again */
3526 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
3528 if (make_attack_spell(m_idx)) return;
3533 /* Notice changes in view */
3536 /* Update some things */
3537 p_ptr->update |= (PU_FLOW);
3540 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3543 /* Notice changes in view */
3544 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
3545 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !p_ptr->inside_battle)))
3547 /* Update some things */
3548 p_ptr->update |= (PU_MON_LITE);
3551 /* Learn things from observable monster */
3552 if (is_original_ap_and_seen(m_ptr))
3554 /* Monster opened a door */
3555 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3557 /* Monster bashed a door */
3558 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3560 /* Monster tried to pick something up */
3561 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3563 /* Monster tried to crush something */
3564 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3566 /* Monster pushed past another monster */
3567 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3569 /* Monster passed through a wall */
3570 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3572 /* Monster destroyed a wall */
3573 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3577 /* Hack -- get "bold" if out of options */
3578 if (!do_turn && !do_move && MON_MONFEAR(m_ptr) && aware)
3580 /* No longer afraid */
3581 (void)set_monster_monfear(m_idx, 0);
3583 /* Message if seen */
3588 /* Acquire the monster name */
3589 monster_desc(m_name, m_ptr, 0);
3591 /* Dump a message */
3593 msg_format("%^s¤ÏÀ襤¤ò·è°Õ¤·¤¿¡ª", m_name);
3595 msg_format("%^s turns to fight!", m_name);
3599 if (m_ptr->ml) chg_virtue(V_COMPASSION, -1);
3601 /* XXX XXX XXX Actually do something now (?) */
3606 * Process all the "live" monsters, once per game turn.
3608 * During each game turn, we scan through the list of all the "live" monsters,
3609 * (backwards, so we can excise any "freshly dead" monsters), energizing each
3610 * monster, and allowing fully energized monsters to move, attack, pass, etc.
3612 * Note that monsters can never move in the monster array (except when the
3613 * "compact_monsters()" function is called by "dungeon()" or "save_player()").
3615 * This function is responsible for at least half of the processor time
3616 * on a normal system with a "normal" amount of monsters and a player doing
3619 * When the player is resting, virtually 90% of the processor time is spent
3620 * in this function, and its children, "process_monster()" and "make_move()".
3622 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",
3623 * especially when the player is running.
3625 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"
3626 * monsters while they are still being "born". A monster is "fresh" only
3627 * during the turn in which it is created, and we use the "hack_m_idx" to
3628 * determine if the monster is yet to be processed during the current turn.
3630 * Note the special "MFLAG_NICE" flag, which allows the player to get one
3631 * move before any "nasty" monsters get to use their spell attacks.
3633 * Note that when the "knowledge" about the currently tracked monster
3634 * changes (flags, attacks, spells), we induce a redraw of the monster
3637 void process_monsters(void)
3644 monster_type *m_ptr;
3645 monster_race *r_ptr;
3647 int old_monster_race_idx;
3649 u32b old_r_flags1 = 0L;
3650 u32b old_r_flags2 = 0L;
3651 u32b old_r_flags3 = 0L;
3652 u32b old_r_flags4 = 0L;
3653 u32b old_r_flags5 = 0L;
3654 u32b old_r_flags6 = 0L;
3655 u32b old_r_flagsr = 0L;
3657 byte old_r_blows0 = 0;
3658 byte old_r_blows1 = 0;
3659 byte old_r_blows2 = 0;
3660 byte old_r_blows3 = 0;
3662 byte old_r_cast_spell = 0;
3666 /* Clear monster fighting indicator */
3669 /* Memorize old race */
3670 old_monster_race_idx = p_ptr->monster_race_idx;
3672 /* Acquire knowledge */
3673 if (p_ptr->monster_race_idx)
3675 /* Acquire current monster */
3676 r_ptr = &r_info[p_ptr->monster_race_idx];
3678 /* Memorize flags */
3679 old_r_flags1 = r_ptr->r_flags1;
3680 old_r_flags2 = r_ptr->r_flags2;
3681 old_r_flags3 = r_ptr->r_flags3;
3682 old_r_flags4 = r_ptr->r_flags4;
3683 old_r_flags5 = r_ptr->r_flags5;
3684 old_r_flags6 = r_ptr->r_flags6;
3685 old_r_flagsr = r_ptr->r_flagsr;
3687 /* Memorize blows */
3688 old_r_blows0 = r_ptr->r_blows[0];
3689 old_r_blows1 = r_ptr->r_blows[1];
3690 old_r_blows2 = r_ptr->r_blows[2];
3691 old_r_blows3 = r_ptr->r_blows[3];
3693 /* Memorize castings */
3694 old_r_cast_spell = r_ptr->r_cast_spell;
3698 /* Process the monsters (backwards) */
3699 for (i = m_max - 1; i >= 1; i--)
3701 /* Access the monster */
3703 r_ptr = &r_info[m_ptr->r_idx];
3705 /* Handle "leaving" */
3706 if (p_ptr->leaving) break;
3708 /* Ignore "dead" monsters */
3709 if (!m_ptr->r_idx) continue;
3711 if (p_ptr->wild_mode) continue;
3714 /* Handle "fresh" monsters */
3715 if (m_ptr->mflag & MFLAG_BORN)
3717 /* No longer "fresh" */
3718 m_ptr->mflag &= ~(MFLAG_BORN);
3724 /* Hack -- Require proximity */
3725 if (m_ptr->cdis >= AAF_LIMIT) continue;
3728 /* Access the location */
3732 /* Flow by smell is allowed */
3733 if (!p_ptr->no_flowed)
3735 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3738 /* Assume no move */
3741 /* Handle "sensing radius" */
3742 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
3744 /* We can "sense" the player */
3748 /* Handle "sight" and "aggravation" */
3749 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3750 (player_has_los_bold(fy, fx) || (p_ptr->cursed & TRC_AGGRAVATE)))
3752 /* We can "see" or "feel" the player */
3756 #if 0 /* (cave[py][px].when == cave[fy][fx].when) is always FALSE... */
3757 /* Hack -- Monsters can "smell" the player from far away */
3758 /* Note that most monsters have "aaf" of "20" or so */
3759 else if (!(m_ptr->mflag2 & MFLAG2_NOFLOW) &&
3760 cave_have_flag_bold(py, px, FF_MOVE) &&
3761 (cave[py][px].when == cave[fy][fx].when) &&
3762 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3763 (cave[fy][fx].dist < r_ptr->aaf))
3765 /* We can "smell" the player */
3769 else if (m_ptr->target_y) test = TRUE;
3772 if (!test) continue;
3775 if (p_ptr->riding == i)
3776 speed = p_ptr->pspeed;
3779 speed = m_ptr->mspeed;
3781 /* Monsters move quickly in Nightmare mode */
3782 if (ironman_nightmare) speed += 5;
3784 if (MON_FAST(m_ptr)) speed += 10;
3785 if (MON_SLOW(m_ptr)) speed -= 10;
3788 /* Give this monster some energy */
3789 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
3791 /* Not enough energy to move */
3792 if (m_ptr->energy_need > 0) continue;
3794 /* Use up "some" energy */
3795 m_ptr->energy_need += ENERGY_NEED();
3798 /* Save global index */
3801 /* Process the monster */
3804 reset_target(m_ptr);
3806 /* Give up flow_by_smell when it might useless */
3807 if (p_ptr->no_flowed && one_in_(3))
3808 m_ptr->mflag2 |= MFLAG2_NOFLOW;
3810 /* Hack -- notice death or departure */
3811 if (!p_ptr->playing || p_ptr->is_dead) break;
3813 /* Notice leaving */
3814 if (p_ptr->leaving) break;
3817 /* Reset global index */
3821 /* Tracking a monster race (the same one we were before) */
3822 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3824 /* Acquire monster race */
3825 r_ptr = &r_info[p_ptr->monster_race_idx];
3827 /* Check for knowledge change */
3828 if ((old_r_flags1 != r_ptr->r_flags1) ||
3829 (old_r_flags2 != r_ptr->r_flags2) ||
3830 (old_r_flags3 != r_ptr->r_flags3) ||
3831 (old_r_flags4 != r_ptr->r_flags4) ||
3832 (old_r_flags5 != r_ptr->r_flags5) ||
3833 (old_r_flags6 != r_ptr->r_flags6) ||
3834 (old_r_flagsr != r_ptr->r_flagsr) ||
3835 (old_r_blows0 != r_ptr->r_blows[0]) ||
3836 (old_r_blows1 != r_ptr->r_blows[1]) ||
3837 (old_r_blows2 != r_ptr->r_blows[2]) ||
3838 (old_r_blows3 != r_ptr->r_blows[3]) ||
3839 (old_r_cast_spell != r_ptr->r_cast_spell))
3842 p_ptr->window |= (PW_MONSTER);
3848 int get_mproc_idx(int m_idx, int mproc_type)
3850 s16b *cur_mproc_list = mproc_list[mproc_type];
3853 for (i = mproc_max[mproc_type] - 1; i >= 0; i--)
3855 if (cur_mproc_list[i] == m_idx) return i;
3862 static void mproc_add(int m_idx, int mproc_type)
3864 if (mproc_max[mproc_type] < max_m_idx) mproc_list[mproc_type][mproc_max[mproc_type]++] = m_idx;
3868 static void mproc_remove(int m_idx, int mproc_type)
3870 int mproc_idx = get_mproc_idx(m_idx, mproc_type);
3871 if (mproc_idx >= 0) mproc_list[mproc_type][mproc_idx] = mproc_list[mproc_type][--mproc_max[mproc_type]];
3876 * Initialize monster process
3878 void mproc_init(void)
3880 monster_type *m_ptr;
3883 /* Reset "mproc_max[]" */
3884 for (cmi = 0; cmi < MAX_MTIMED; cmi++) mproc_max[cmi] = 0;
3886 /* Process the monsters (backwards) */
3887 for (i = m_max - 1; i >= 1; i--)
3889 /* Access the monster */
3892 /* Ignore "dead" monsters */
3893 if (!m_ptr->r_idx) continue;
3895 for (cmi = 0; cmi < MAX_MTIMED; cmi++)
3897 if (m_ptr->mtimed[cmi]) mproc_add(i, cmi);
3904 * Set "m_ptr->mtimed[MTIMED_CSLEEP]", notice observable changes
3906 bool set_monster_csleep(int m_idx, int v)
3908 monster_type *m_ptr = &m_list[m_idx];
3909 bool notice = FALSE;
3911 /* Hack -- Force good values */
3912 v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
3917 if (!MON_CSLEEP(m_ptr))
3919 mproc_add(m_idx, MTIMED_CSLEEP);
3927 if (MON_CSLEEP(m_ptr))
3929 mproc_remove(m_idx, MTIMED_CSLEEP);
3935 m_ptr->mtimed[MTIMED_CSLEEP] = v;
3937 if (!notice) return FALSE;
3941 /* Update health bar as needed */
3942 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
3943 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
3946 if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
3953 * Set "m_ptr->mtimed[MTIMED_FAST]", notice observable changes
3955 bool set_monster_fast(int m_idx, int v)
3957 monster_type *m_ptr = &m_list[m_idx];
3958 bool notice = FALSE;
3960 /* Hack -- Force good values */
3961 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
3966 if (!MON_FAST(m_ptr))
3968 mproc_add(m_idx, MTIMED_FAST);
3976 if (MON_FAST(m_ptr))
3978 mproc_remove(m_idx, MTIMED_FAST);
3984 m_ptr->mtimed[MTIMED_FAST] = v;
3986 if (!notice) return FALSE;
3988 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
3995 * Set "m_ptr->mtimed[MTIMED_SLOW]", notice observable changes
3997 bool set_monster_slow(int m_idx, int v)
3999 monster_type *m_ptr = &m_list[m_idx];
4000 bool notice = FALSE;
4002 /* Hack -- Force good values */
4003 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4008 if (!MON_SLOW(m_ptr))
4010 mproc_add(m_idx, MTIMED_SLOW);
4018 if (MON_SLOW(m_ptr))
4020 mproc_remove(m_idx, MTIMED_SLOW);
4026 m_ptr->mtimed[MTIMED_SLOW] = v;
4028 if (!notice) return FALSE;
4030 if ((p_ptr->riding == m_idx) && !p_ptr->leaving) p_ptr->update |= (PU_BONUS);
4037 * Set "m_ptr->mtimed[MTIMED_STUNNED]", notice observable changes
4039 bool set_monster_stunned(int m_idx, int v)
4041 monster_type *m_ptr = &m_list[m_idx];
4042 bool notice = FALSE;
4044 /* Hack -- Force good values */
4045 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4050 if (!MON_STUNNED(m_ptr))
4052 mproc_add(m_idx, MTIMED_STUNNED);
4060 if (MON_STUNNED(m_ptr))
4062 mproc_remove(m_idx, MTIMED_STUNNED);
4068 m_ptr->mtimed[MTIMED_STUNNED] = v;
4075 * Set "m_ptr->mtimed[MTIMED_CONFUSED]", notice observable changes
4077 bool set_monster_confused(int m_idx, int v)
4079 monster_type *m_ptr = &m_list[m_idx];
4080 bool notice = FALSE;
4082 /* Hack -- Force good values */
4083 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4088 if (!MON_CONFUSED(m_ptr))
4090 mproc_add(m_idx, MTIMED_CONFUSED);
4098 if (MON_CONFUSED(m_ptr))
4100 mproc_remove(m_idx, MTIMED_CONFUSED);
4106 m_ptr->mtimed[MTIMED_CONFUSED] = v;
4113 * Set "m_ptr->mtimed[MTIMED_MONFEAR]", notice observable changes
4115 bool set_monster_monfear(int m_idx, int v)
4117 monster_type *m_ptr = &m_list[m_idx];
4118 bool notice = FALSE;
4120 /* Hack -- Force good values */
4121 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4126 if (!MON_MONFEAR(m_ptr))
4128 mproc_add(m_idx, MTIMED_MONFEAR);
4136 if (MON_MONFEAR(m_ptr))
4138 mproc_remove(m_idx, MTIMED_MONFEAR);
4144 m_ptr->mtimed[MTIMED_MONFEAR] = v;
4146 if (!notice) return FALSE;
4150 /* Update health bar as needed */
4151 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
4152 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
4160 * Set "m_ptr->mtimed[MTIMED_INVULNER]", notice observable changes
4162 bool set_monster_invulner(int m_idx, int v, bool energy_need)
4164 monster_type *m_ptr = &m_list[m_idx];
4165 bool notice = FALSE;
4167 /* Hack -- Force good values */
4168 v = (v > 200) ? 200 : (v < 0) ? 0 : v;
4173 if (!MON_INVULNER(m_ptr))
4175 mproc_add(m_idx, MTIMED_INVULNER);
4183 if (MON_INVULNER(m_ptr))
4185 mproc_remove(m_idx, MTIMED_INVULNER);
4186 if (energy_need && !p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
4192 m_ptr->mtimed[MTIMED_INVULNER] = v;
4194 if (!notice) return FALSE;
4198 /* Update health bar as needed */
4199 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
4200 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
4207 static u32b csleep_noise;
4209 static void process_monsters_mtimed_aux(int m_idx, int mtimed_idx)
4211 monster_type *m_ptr = &m_list[m_idx];
4217 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4219 /* Assume does not wake up */
4222 /* Hack -- Require proximity */
4223 if (m_ptr->cdis < AAF_LIMIT)
4225 /* Handle "sensing radius" */
4226 if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
4228 /* We may wake up */
4232 /* Handle "sight" and "aggravation" */
4233 else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
4235 /* We may wake up */
4242 u32b notice = randint0(1024);
4244 /* Nightmare monsters are more alert */
4245 if (ironman_nightmare) notice /= 2;
4247 /* Hack -- See if monster "notices" player */
4248 if ((notice * notice * notice) <= csleep_noise)
4250 /* Hack -- amount of "waking" */
4251 /* Wake up faster near the player */
4252 int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
4254 /* Hack -- amount of "waking" is affected by speed of player */
4255 d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
4258 /* Monster wakes up "a little bit" */
4261 if (!set_monster_csleep(m_idx, MON_CSLEEP(m_ptr) - d))
4263 /* Notice the "not waking up" */
4264 if (is_original_ap_and_seen(m_ptr))
4266 /* Hack -- Count the ignores */
4267 if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++;
4274 /* Notice the "waking up" */
4279 /* Acquire the monster name */
4280 monster_desc(m_name, m_ptr, 0);
4282 /* Dump a message */
4284 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
4286 msg_format("%^s wakes up.", m_name);
4290 if (is_original_ap_and_seen(m_ptr))
4292 /* Hack -- Count the wakings */
4293 if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++;
4302 /* Reduce by one, note if expires */
4303 if (set_monster_fast(m_idx, MON_FAST(m_ptr) - 1))
4309 /* Acquire the monster name */
4310 monster_desc(m_name, m_ptr, 0);
4312 /* Dump a message */
4314 msg_format("%^s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
4316 msg_format("%^s is no longer fast.", m_name);
4323 /* Reduce by one, note if expires */
4324 if (set_monster_slow(m_idx, MON_SLOW(m_ptr) - 1))
4330 /* Acquire the monster name */
4331 monster_desc(m_name, m_ptr, 0);
4333 /* Dump a message */
4335 msg_format("%^s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
4337 msg_format("%^s is no longer slow.", m_name);
4343 case MTIMED_STUNNED:
4345 int rlev = r_info[m_ptr->r_idx].level;
4347 /* Recover from stun */
4348 if (set_monster_stunned(m_idx, (randint0(10000) <= rlev * rlev) ? 0 : (MON_STUNNED(m_ptr) - 1)))
4350 /* Message if visible */
4355 /* Acquire the monster name */
4356 monster_desc(m_name, m_ptr, 0);
4358 /* Dump a message */
4360 msg_format("%^s¤ÏÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤Ã¤¿¡£", m_name);
4362 msg_format("%^s is no longer stunned.", m_name);
4369 case MTIMED_CONFUSED:
4370 /* Reduce the confusion */
4371 if (set_monster_confused(m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
4373 /* Message if visible */
4378 /* Acquire the monster name */
4379 monster_desc(m_name, m_ptr, 0);
4381 /* Dump a message */
4383 msg_format("%^s¤Ïº®Í𤫤éΩ¤Áľ¤Ã¤¿¡£", m_name);
4385 msg_format("%^s is no longer confused.", m_name);
4391 case MTIMED_MONFEAR:
4392 /* Reduce the fear */
4393 if (set_monster_monfear(m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1)))
4402 /* Acquire the monster possessive */
4403 monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
4406 /* Acquire the monster name */
4407 monster_desc(m_name, m_ptr, 0);
4409 /* Dump a message */
4411 msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name);
4413 msg_format("%^s recovers %s courage.", m_name, m_poss);
4419 case MTIMED_INVULNER:
4420 /* Reduce by one, note if expires */
4421 if (set_monster_invulner(m_idx, MON_INVULNER(m_ptr) - 1, TRUE))
4427 /* Acquire the monster name */
4428 monster_desc(m_name, m_ptr, 0);
4430 /* Dump a message */
4432 msg_format("%^s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ê¤¤¡£", m_name);
4434 msg_format("%^s is no longer invulnerable.", m_name);
4444 * Process the counters of monsters (once per 10 game turns)
4446 * These functions are to process monsters' counters same as player's.
4448 void process_monsters_mtimed(int mtimed_idx)
4451 s16b *cur_mproc_list = mproc_list[mtimed_idx];
4453 /* Hack -- calculate the "player noise" */
4454 if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - p_ptr->skill_stl));
4456 /* Process the monsters (backwards) */
4457 for (i = mproc_max[mtimed_idx] - 1; i >= 0; i--)
4459 /* Access the monster */
4460 process_monsters_mtimed_aux(cur_mproc_list[i], mtimed_idx);
4465 void dispel_monster_status(int m_idx)
4467 monster_type *m_ptr = &m_list[m_idx];
4470 monster_desc(m_name, m_ptr, 0);
4471 if (set_monster_invulner(m_idx, 0, TRUE))
4474 if (m_ptr->ml) msg_format("%s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ï¤Ê¤¤¡£", m_name);
4476 if (m_ptr->ml) msg_format("%^s is no longer invulnerable.", m_name);
4479 if (set_monster_fast(m_idx, 0))
4482 if (m_ptr->ml) msg_format("%s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
4484 if (m_ptr->ml) msg_format("%^s is no longer fast.", m_name);
4487 if (set_monster_slow(m_idx, 0))
4490 if (m_ptr->ml) msg_format("%s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
4492 if (m_ptr->ml) msg_format("%^s is no longer slow.", m_name);
4498 bool process_the_world(int num, int who, bool vs_player)
4500 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
4502 if(world_monster) return (FALSE);
4507 monster_desc(m_name, m_ptr, 0);
4511 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
4513 msg_format("%s yells 'The World! Time has stopped!'", m_name);
4517 msg_print("¡Ö»þ¤è¡ª¡×");
4519 msg_format("%s yells 'Time!'", m_name);
4521 else msg_print("hek!");
4526 /* This monster cast spells */
4527 world_monster = hack_m_idx;
4529 if (vs_player) do_cmd_redraw();
4533 if(!m_ptr->r_idx) break;
4534 process_monster(world_monster);
4536 reset_target(m_ptr);
4539 if (p_ptr->notice) notice_stuff();
4542 if (p_ptr->update) update_stuff();
4545 if (p_ptr->redraw) redraw_stuff();
4548 if (p_ptr->window) window_stuff();
4551 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
4555 p_ptr->redraw |= (PR_MAP);
4557 /* Update monsters */
4558 p_ptr->update |= (PU_MONSTERS);
4561 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4564 if (vs_player || (player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
4567 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
4569 msg_print("You feel time flowing around you once more.");
4580 void monster_gain_exp(int m_idx, int s_idx)
4582 monster_type *m_ptr;
4583 monster_race *r_ptr;
4584 monster_race *s_ptr;
4588 if (m_idx <= 0 || s_idx <= 0) return;
4590 m_ptr = &m_list[m_idx];
4592 /* Paranoia -- Skip dead monsters */
4593 if (!m_ptr->r_idx) return;
4595 r_ptr = &r_info[m_ptr->r_idx];
4596 s_ptr = &r_info[s_idx];
4598 if (p_ptr->inside_battle) return;
4600 if (!r_ptr->next_exp) return;
4602 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
4603 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
4604 if (!dun_level) new_exp /= 5;
4605 m_ptr->exp += new_exp;
4606 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
4608 if (m_ptr->exp >= r_ptr->next_exp)
4611 int old_hp = m_ptr->hp;
4612 int old_maxhp = m_ptr->max_maxhp;
4613 int old_r_idx = m_ptr->r_idx;
4614 byte old_sub_align = m_ptr->sub_align;
4616 /* Hack -- Reduce the racial counter of previous monster */
4617 real_r_ptr(m_ptr)->cur_num--;
4619 monster_desc(m_name, m_ptr, 0);
4620 m_ptr->r_idx = r_ptr->next_r_idx;
4622 /* Count the monsters on the level */
4623 real_r_ptr(m_ptr)->cur_num++;
4625 m_ptr->ap_r_idx = m_ptr->r_idx;
4626 r_ptr = &r_info[m_ptr->r_idx];
4628 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
4630 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
4634 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
4636 if (ironman_nightmare)
4638 u32b hp = m_ptr->max_maxhp * 2L;
4640 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
4642 m_ptr->maxhp = m_ptr->max_maxhp;
4643 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
4645 /* dealt damage is 0 at initial*/
4646 m_ptr->dealt_damage = 0;
4648 /* Extract the monster base speed */
4649 m_ptr->mspeed = get_mspeed(r_ptr);
4651 /* Sub-alignment of a monster */
4652 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
4653 m_ptr->sub_align = old_sub_align;
4656 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
4657 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
4658 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
4663 if (is_pet(m_ptr) || m_ptr->ml)
4665 if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
4669 monster_race *hallu_race;
4673 hallu_race = &r_info[randint1(max_r_idx - 1)];
4675 while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
4678 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + hallu_race->name);
4680 msg_format("%^s evolved into %s.", m_name, r_name + hallu_race->name);
4686 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
4688 msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
4693 if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
4695 /* Now you feel very close to this pet. */
4696 m_ptr->parent_m_idx = 0;
4698 update_mon(m_idx, FALSE);
4699 lite_spot(m_ptr->fy, m_ptr->fx);
4701 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;