3 /* Purpose: Monster spells and movement */
6 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
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
24 extern cptr silly_attacks[MAX_SILLY_ATTACK];
27 * Calculate the direction to the next enemy
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 && (m_ptr->fx == px) && (m_ptr->fy == py))
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);
70 t_ptr = &m_list[t_idx];
72 /* The monster itself isn't a target */
73 if (t_ptr == m_ptr) continue;
75 /* Paranoia -- Skip dead monsters */
76 if (!t_ptr->r_idx) continue;
80 /* Hack -- only fight away from player */
81 if (p_ptr->pet_follow_distance < 0)
83 /* No fighting near player */
84 if (t_ptr->cdis <= (0 - p_ptr->pet_follow_distance))
89 /* Hack -- no fighting away from player */
90 else if ((m_ptr->cdis < t_ptr->cdis) &&
91 (t_ptr->cdis > p_ptr->pet_follow_distance))
96 if (r_ptr->aaf < t_ptr->cdis) continue;
99 /* Monster must be 'an enemy' */
100 if (!are_enemies(m_ptr, t_ptr)) continue;
102 can_pass_wall = (((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)));
104 /* Monster must be projectable if we can't pass through walls */
105 if (!can_pass_wall &&
106 !projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
111 !in_disintegration_range(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
116 /* OK -- we've got a target */
122 if (!x && !y) return FALSE;
125 /* Extract the direction */
130 if ((y < 0) && (x == 0))
137 else if ((y > 0) && (x == 0))
144 else if ((x > 0) && (y == 0))
151 else if ((x < 0) && (y == 0))
158 else if ((y < 0) && (x < 0))
165 else if ((y < 0) && (x > 0))
172 else if ((y > 0) && (x < 0))
179 else if ((y > 0) && (x > 0))
186 /* Found a monster */
192 * Hack, based on mon_take_hit... perhaps all monster attacks on
193 * other monsters should use this?
195 void mon_take_hit_mon(bool is_psy_spear, int m_idx, int dam, bool *fear, cptr note, int who)
197 monster_type *m_ptr = &m_list[m_idx];
199 monster_race *r_ptr = &r_info[m_ptr->r_idx];
203 bool seen = m_ptr->ml;
205 /* Can the player be aware of this attack? */
206 bool known = (m_ptr->cdis <= MAX_SIGHT);
208 /* Extract monster name */
209 monster_desc(m_name, m_ptr, 0);
211 /* Redraw (later) if needed */
212 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
213 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
218 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
220 if (m_ptr->invulner && randint0(PENETRATE_INVULNERABILITY))
225 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
227 msg_format("%^s is unharmed.", m_name);
235 if (r_ptr->flags3 & RF3_RES_ALL)
240 if((dam == 0) && one_in_(3)) dam = 1;
247 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
249 msg_format("%^s is unharmed.", m_name);
260 /* It is dead now... or is it? */
263 if (((r_ptr->flags1 & RF1_UNIQUE) ||
264 (r_ptr->flags7 & RF7_UNIQUE_7) ||
265 (r_ptr->flags1 & RF1_QUESTOR)) &&
266 !p_ptr->inside_battle)
273 if (!monster_living(r_ptr))
284 monster_desc(m_name, m_ptr, 0x100);
285 /* Unseen death by normal attack */
290 /* Death by special attack */
294 msg_format("%^s%s", m_name, note);
296 msg_format("%^s%s", m_name, note);
300 /* Death by normal attack -- nonliving monster */
301 else if (!monster_living(r_ptr))
304 msg_format("%^s¤ÏÇ˲õ¤µ¤ì¤¿¡£", m_name);
306 msg_format("%^s is destroyed.", m_name);
310 /* Death by normal attack -- living monster */
314 msg_format("%^s¤Ï»¦¤µ¤ì¤¿¡£", m_name);
316 msg_format("%^s is killed.", m_name);
322 monster_gain_exp(who, m_ptr->r_idx);
324 /* Generate treasure */
325 monster_death(m_idx, FALSE);
327 /* Delete the monster */
328 delete_monster_idx(m_idx);
333 /* Monster is dead */
340 /* Mega-Hack -- Pain cancels fear */
341 if (m_ptr->monfear && (dam > 0))
343 int tmp = randint1(dam / 4);
345 /* Cure a little fear */
346 if (tmp < m_ptr->monfear)
349 m_ptr->monfear -= tmp;
352 /* Cure all the fear */
363 /* Sometimes a monster gets scared by damage */
364 if (!m_ptr->monfear && !(r_ptr->flags3 & RF3_NO_FEAR))
368 /* Percentage of fully healthy */
369 percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
372 * Run (sometimes) if at 10% or less of max hit points,
373 * or (usually) when hit for half its current hit points
375 if (((percentage <= 10) && (randint0(10) < percentage)) ||
376 ((dam >= m_ptr->hp) && (randint0(100) < 80)))
378 /* Hack -- note fear */
381 /* XXX XXX XXX Hack -- Add some timed fear */
382 m_ptr->monfear += (randint1(10) +
383 (((dam >= m_ptr->hp) && (percentage > 7)) ?
384 20 : ((11 - percentage) * 5)));
388 #endif /* ALLOW_FEAR */
390 if ((dam > 0) && !is_pet(m_ptr) && !is_friendly(m_ptr) && (who != m_idx))
392 if (is_pet(&m_list[who]) && (m_ptr->target_y != py) && (m_ptr->target_x != px))
394 set_target(m_ptr, m_list[who].fy, m_list[who].fx);
398 if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
402 /* Extract monster name */
403 monster_desc(m_name, m_ptr, 0);
405 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
406 if (rakuba((dam > 200) ? 200 : dam, FALSE))
409 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
411 msg_format("You have thrown off from %s!", m_name);
422 * Returns whether a given monster will try to run from the player.
424 * Monsters will attempt to avoid very powerful players. See below.
426 * Because this function is called so often, little details are important
427 * for efficiency. Like not using "mod" or "div" when possible. And
428 * attempting to check the conditions in an optimal order. Note that
429 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.
431 * Note that this function is responsible for about one to five percent
432 * of the processor use in normal conditions...
434 static int mon_will_run(int m_idx)
436 monster_type *m_ptr = &m_list[m_idx];
440 monster_race *r_ptr = &r_info[m_ptr->r_idx];
449 /* Friends can be commanded to avoid the player */
452 /* Are we trying to avoid the player? */
453 return ((p_ptr->pet_follow_distance < 0) &&
454 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
457 /* Keep monsters from running too far away */
458 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
460 /* All "afraid" monsters will run away */
461 if (m_ptr->monfear) return (TRUE);
465 /* Nearby monsters will not become terrified */
466 if (m_ptr->cdis <= 5) return (FALSE);
468 /* Examine player power (level) */
471 /* Examine monster power (level plus morale) */
472 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
474 /* Optimize extreme cases below */
475 if (m_lev > p_lev + 4) return (FALSE);
476 if (m_lev + 4 <= p_lev) return (TRUE);
478 /* Examine player health */
482 /* Examine monster health */
484 m_mhp = m_ptr->maxhp;
486 /* Prepare to optimize the calculation */
487 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
488 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
490 /* Strong players scare strong monsters */
491 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
495 /* Assume no terror */
503 * Search spell castable grid
505 static bool get_moves_aux2(int m_idx, int *yp, int *xp)
507 int i, y, x, y1, x1, best = 999;
510 bool can_open_door = FALSE;
513 monster_type *m_ptr = &m_list[m_idx];
514 monster_race *r_ptr = &r_info[m_ptr->r_idx];
516 /* Monster location */
520 /* Monster can already cast spell to player */
521 if (projectable(y1, x1, py, px)) return (FALSE);
523 /* Set current grid cost */
524 now_cost = cave[y1][x1].cost;
525 if (now_cost == 0) now_cost = 999;
527 /* Can monster bash or open doors? */
528 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
530 can_open_door = TRUE;
533 /* Check nearby grids, diagonals first */
534 for (i = 7; i >= 0; i--)
538 /* Get the location */
542 /* Ignore locations off of edge */
543 if (!in_bounds2(y, x)) continue;
545 /* Simply move to player */
546 if ((y == py) && (x == px)) return (FALSE);
552 /* Monster cannot kill or pass walls */
553 if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) || (r_ptr->flags2 & RF2_KILL_WALL)))
555 if (cost == 0) continue;
556 if (!can_open_door && (c_ptr->feat >= FEAT_DOOR_HEAD && c_ptr->feat <= FEAT_SECRET)) continue;
559 /* Hack -- for kill or pass wall monster.. */
560 if (cost == 0) cost = 998;
562 if (now_cost < cost) continue;
564 if (!projectable(y, x, py, px)) continue;
566 /* Accept louder sounds */
567 if (best < cost) continue;
570 (*yp) = y1 + ddy_ddd[i];
571 (*xp) = x1 + ddx_ddd[i];
574 /* No legal move (?) */
575 if (best == 999) return (FALSE);
583 * Choose the "best" direction for "flowing"
585 * Note that ghosts and rock-eaters are never allowed to "flow",
586 * since they should move directly towards the player.
588 * Prefer "non-diagonal" directions, but twiddle them a little
589 * to angle slightly towards the player's actual location.
591 * Allow very perceptive monsters to track old "spoor" left by
592 * previous locations occupied by the player. This will tend
593 * to have monsters end up either near the player or on a grid
594 * recently occupied by the player (and left via "teleport").
596 * Note that if "smell" is turned on, all monsters get vicious.
598 * Also note that teleporting away from a location will cause
599 * the monsters who were chasing you to converge on that location
600 * as long as you are still near enough to "annoy" them without
601 * being close enough to chase directly. I have no idea what will
602 * happen if you combine "smell" with low "aaf" values.
604 static bool get_moves_aux(int m_idx, int *yp, int *xp)
606 int i, y, x, y1, x1, best;
609 bool use_sound = FALSE;
610 bool use_scent = FALSE;
612 monster_type *m_ptr = &m_list[m_idx];
613 monster_race *r_ptr = &r_info[m_ptr->r_idx];
615 /* Monster flowing disabled */
616 if (stupid_monsters) return (FALSE);
618 /* Can monster cast attack spell? */
619 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
620 r_ptr->flags5 & (RF5_ATTACK_MASK) ||
621 r_ptr->flags6 & (RF6_ATTACK_MASK))
623 /* Can move spell castable grid? */
624 if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
627 /* Monster can go through rocks */
628 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) return (FALSE);
629 if (r_ptr->flags2 & RF2_KILL_WALL) return (FALSE);
630 if (!cave_floor_bold(py, px) && (cave[py][px].feat != FEAT_TREES)) return (FALSE);
632 /* Monster location */
636 /* Hack -- Player can see us, run towards him */
637 if (player_has_los_bold(y1, x1)) return (FALSE);
640 c_ptr = &cave[y1][x1];
642 /* If we can hear noises, advance towards them */
649 /* Otherwise, try to follow a scent trail */
650 else if (c_ptr->when)
653 if (cave[py][px].when - c_ptr->when > 127) return (FALSE);
659 /* Otherwise, advance blindly */
665 /* Check nearby grids, diagonals first */
666 for (i = 7; i >= 0; i--)
668 /* Get the location */
672 /* Ignore locations off of edge */
673 if (!in_bounds2(y, x)) continue;
677 /* We're following a scent trail */
680 int when = c_ptr->when;
682 /* Accept younger scent */
683 if (best > when) continue;
687 /* We're using sound */
692 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
694 else cost = c_ptr->cost;
696 /* Accept louder sounds */
697 if ((cost == 0) || (best < cost)) continue;
701 /* Hack -- Save the "twiddled" location */
702 (*yp) = py + 16 * ddy_ddd[i];
703 (*xp) = px + 16 * ddx_ddd[i];
706 /* No legal move (?) */
707 if (best == 999 || best == 0) return (FALSE);
715 * Provide a location to flee to, but give the player a wide berth.
717 * A monster may wish to flee to a location that is behind the player,
718 * but instead of heading directly for it, the monster should "swerve"
719 * around the player so that he has a smaller chance of getting hit.
721 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
723 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
724 int dist = 0, score = -1;
727 monster_type *m_ptr = &m_list[m_idx];
729 /* Monster flowing disabled */
730 if (stupid_monsters) return (FALSE);
732 /* Monster location */
736 /* Desired destination */
740 /* Check nearby grids, diagonals first */
741 for (i = 7; i >= 0; i--)
745 /* Get the location */
749 /* Ignore locations off of edge */
750 if (!in_bounds2(y, x)) continue;
752 if (cave[y][x].dist < dist) continue;
754 /* Calculate distance of this grid from our destination */
755 dis = distance(y, x, y1, x1);
757 /* Score this grid */
758 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
760 /* No negative scores */
763 /* Ignore lower scores */
764 if (s < score) continue;
766 /* Save the score and time */
767 dist = cave[y][x].dist;
770 /* Save the location */
775 /* No legal move (?) */
776 if (score == -1) return (FALSE);
787 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
790 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
791 * offsets of all the locations with a distance of n from a central point,
792 * with an offset of (0,0) indicating no more offsets at this distance.
794 * This is, of course, fairly unreadable, but it eliminates multiple loops
795 * from the previous version.
797 * It is probably better to replace these arrays with code to compute
798 * the relevant arrays, even if the storage is pre-allocated in hard
799 * coded sizes. At the very least, code should be included which is
800 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
802 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
804 * These arrays could be combined into two big arrays, using sub-arrays
805 * to hold the offsets and lengths of each portion of the sub-arrays, and
806 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
810 static sint d_off_y_0[] =
813 static sint d_off_x_0[] =
817 static sint d_off_y_1[] =
818 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
820 static sint d_off_x_1[] =
821 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
824 static sint d_off_y_2[] =
825 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
827 static sint d_off_x_2[] =
828 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
831 static sint d_off_y_3[] =
832 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
835 static sint d_off_x_3[] =
836 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
840 static sint d_off_y_4[] =
841 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
842 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
844 static sint d_off_x_4[] =
845 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
846 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
849 static sint d_off_y_5[] =
850 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
851 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
854 static sint d_off_x_5[] =
855 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
856 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
860 static sint d_off_y_6[] =
861 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
862 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
865 static sint d_off_x_6[] =
866 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
867 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
868 -3, 2, 3, -1, 0, 1, 0 };
871 static sint d_off_y_7[] =
872 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
873 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
874 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
876 static sint d_off_x_7[] =
877 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
878 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
879 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
883 static sint d_off_y_8[] =
884 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
885 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
886 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
889 static sint d_off_x_8[] =
890 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
891 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
892 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
896 static sint d_off_y_9[] =
897 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
898 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
899 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
900 7, 8, 8, 8, 8, 9, 9, 9, 0 };
902 static sint d_off_x_9[] =
903 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
904 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
905 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
906 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
909 static sint *dist_offsets_y[10] =
911 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
912 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
915 static sint *dist_offsets_x[10] =
917 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
918 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
922 * Choose a "safe" location near a monster for it to run toward.
924 * A location is "safe" if it can be reached quickly and the player
925 * is not able to fire into it (it isn't a "clean shot"). So, this will
926 * cause monsters to "duck" behind walls. Hopefully, monsters will also
927 * try to run towards corridor openings if they are in a room.
929 * This function may take lots of CPU time if lots of monsters are
932 * Return TRUE if a safe location is available.
934 static bool find_safety(int m_idx, int *yp, int *xp)
936 monster_type *m_ptr = &m_list[m_idx];
941 int y, x, dy, dx, d, dis, i;
942 int gy = 0, gx = 0, gdis = 0;
949 /* Start with adjacent locations, spread further */
950 for (d = 1; d < 10; d++)
952 /* Get the lists of points with a distance d from (fx, fy) */
953 y_offsets = dist_offsets_y[d];
954 x_offsets = dist_offsets_x[d];
956 /* Check the locations */
957 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
959 i++, dx = x_offsets[i], dy = y_offsets[i])
964 /* Skip illegal locations */
965 if (!in_bounds(y, x)) continue;
969 /* Skip locations in a wall */
970 if (!cave_floor_grid(c_ptr)) continue;
972 /* Check for "availability" (if monsters can flow) */
973 if (!stupid_monsters && !(m_ptr->mflag2 & MFLAG_NOFLOW))
975 /* Ignore grids very far from the player */
976 if (c_ptr->when < cave[py][px].when) continue;
978 /* Ignore too-distant grids */
979 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
982 /* Check for absence of shot (more or less) */
983 if (clean_shot(fy, fx, y, x, FALSE))
986 /* Calculate distance from player */
987 dis = distance(y, x, py, px);
989 /* Remember if further than previous */
994 if (!player_has_los_grid(c_ptr))
1006 /* Check for success */
1007 if (gdis > d + m_ptr->cdis)
1013 /* Found safe place */
1020 /* Save farthest location from player in LOS of monster */
1024 /* Hack - return TRUE anyway. */
1030 * Choose a good hiding place near a monster for it to run toward.
1032 * Pack monsters will use this to "ambush" the player and lure him out
1033 * of corridors into open space so they can swarm him.
1035 * Return TRUE if a good location is available.
1037 static bool find_hiding(int m_idx, int *yp, int *xp)
1039 monster_type *m_ptr = &m_list[m_idx];
1044 int y, x, dy, dx, d, dis, i;
1045 int gy = 0, gx = 0, gdis = 999;
1047 sint *y_offsets, *x_offsets;
1051 /* Start with adjacent locations, spread further */
1052 for (d = 1; d < 10; d++)
1054 /* Get the lists of points with a distance d from (fx, fy) */
1055 y_offsets = dist_offsets_y[d];
1056 x_offsets = dist_offsets_x[d];
1058 /* Check the locations */
1059 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
1061 i++, dx = x_offsets[i], dy = y_offsets[i])
1066 /* Skip illegal locations */
1067 if (!in_bounds(y, x)) continue;
1069 c_ptr = &cave[y][x];
1071 /* Skip occupied locations */
1072 if (!cave_empty_grid(c_ptr)) continue;
1074 /* Check for hidden, available grid */
1075 if (!player_has_los_grid(c_ptr) && clean_shot(fy, fx, y, x, FALSE))
1077 /* Calculate distance from player */
1078 dis = distance(y, x, py, px);
1080 /* Remember if closer than previous */
1081 if (dis < gdis && dis >= 2)
1090 /* Check for success */
1097 /* Found good place */
1108 * Choose "logical" directions for monster movement
1110 static bool get_moves(int m_idx, int *mm)
1112 monster_type *m_ptr = &m_list[m_idx];
1113 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1119 bool will_run = mon_will_run(m_idx);
1121 bool no_flow = ((m_ptr->mflag2 & MFLAG_NOFLOW) && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1124 /* Flow towards the player */
1125 if (!stupid_monsters && !no_flow)
1127 /* Flow towards the player */
1128 (void)get_moves_aux(m_idx, &y2, &x2);
1131 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
1133 /* Extract the "pseudo-direction" */
1137 if (!stupid_monsters && !will_run && is_hostile(m_ptr) &&
1138 (r_ptr->flags1 & RF1_FRIENDS) &&
1139 (los(m_ptr->fy, m_ptr->fx, py, px) ||
1140 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1143 * Animal packs try to get the player out of corridors
1144 * (...unless they can move through walls -- TY)
1146 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1147 !(r_ptr->flags2 & RF2_KILL_WALL))
1151 /* Count room grids next to player */
1152 for (i = 0; i < 8; i++)
1154 int x = px + ddx_ddd[i];
1155 int y = py + ddy_ddd[i];
1159 if (!in_bounds2(y, x)) continue;
1161 c_ptr = &cave[y][x];
1164 if (((cave_floor_grid(c_ptr)) || ((c_ptr->feat & 0x60) == 0x60)) &&
1165 monster_can_cross_terrain(c_ptr->feat, r_ptr))
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 c_ptr = &cave[y2][x2];
1209 if (!cave_empty_grid(c_ptr)) continue;
1211 /* Try to fill this hole */
1215 /* Extract the new "pseudo-direction" */
1224 /* Apply fear if possible and necessary */
1225 if ((stupid_monsters || is_pet(m_ptr)) && will_run)
1227 /* XXX XXX Not very "smart" */
1232 if (!done && will_run)
1234 /* Try to find safe place */
1235 if (!find_safety(m_idx, &y, &x))
1237 /* This is not a very "smart" method XXX XXX */
1243 /* Attempt to avoid the player */
1244 if (!stupid_monsters && !no_flow)
1246 /* Adjust movement */
1247 (void)get_fear_moves_aux(m_idx, &y, &x);
1254 if (!stupid_monsters)
1256 /* Check for no move */
1257 if (!x && !y) return (FALSE);
1261 /* Extract the "absolute distances" */
1265 /* Do something weird */
1266 if (y < 0) move_val += 8;
1267 if (x > 0) move_val += 4;
1269 /* Prevent the diamond maneuvre */
1275 else if (ax > (ay << 1))
1280 /* Extract some directions */
1425 /* Wants to move... */
1430 static int check_hit2(int power, int level, int ac, int stun)
1434 /* Percentile dice */
1437 if (stun && one_in_(2)) return FALSE;
1439 /* Hack -- Always miss or hit */
1440 if (k < 10) return (k < 5);
1442 /* Calculate the "attack quality" */
1443 i = (power + (level * 3));
1445 /* Power and Level compete against Armor */
1446 if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
1453 /* Monster attacks monster */
1454 static bool monst_attack_monst(int m_idx, int t_idx)
1456 monster_type *m_ptr = &m_list[m_idx];
1457 monster_type *t_ptr = &m_list[t_idx];
1459 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1460 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1464 char m_name[80], t_name[80];
1465 char ddesc[80], temp[80];
1466 bool blinked, heal_effect;
1467 bool explode = FALSE, touched = FALSE, fear = FALSE;
1468 int y_saver = t_ptr->fy;
1469 int x_saver = t_ptr->fx;
1471 bool see_m = m_ptr->ml;
1472 bool see_t = t_ptr->ml;
1473 bool see_either = see_m || see_t;
1475 /* Can the player be aware of this attack? */
1476 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1477 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1479 /* Cannot attack self */
1480 if (m_idx == t_idx) return FALSE;
1482 /* Not allowed to attack */
1483 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1485 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1493 /* Extract the effective monster level */
1494 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1496 /* Get the monster name (or "it") */
1497 monster_desc(m_name, m_ptr, 0);
1499 /* Get the monster name (or "it") */
1500 monster_desc(t_name, t_ptr, 0);
1502 /* Get the "died from" information (i.e. "a kobold") */
1503 monster_desc(ddesc, m_ptr, 0x88);
1505 /* Assume no blink */
1508 if (!see_either && known)
1513 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
1515 /* Scan through all four blows */
1516 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1518 bool obvious = FALSE;
1525 /* Extract the attack infomation */
1526 int effect = r_ptr->blow[ap_cnt].effect;
1527 int method = r_ptr->blow[ap_cnt].method;
1528 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1529 int d_side = r_ptr->blow[ap_cnt].d_side;
1531 if (!m_ptr->r_idx) break;
1533 /* Stop attacking if the target dies! */
1534 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1537 /* Hack -- no more attacks */
1540 if (blinked) /* Stop! */
1545 if (method == RBM_SHOOT) continue;
1547 /* Extract the attack "power" */
1550 case RBE_HURT: power = 60; break;
1551 case RBE_POISON: power = 5; break;
1552 case RBE_UN_BONUS: power = 20; break;
1553 case RBE_UN_POWER: power = 15; break;
1554 case RBE_EAT_GOLD: power = 5; break;
1555 case RBE_EAT_ITEM: power = 5; break;
1556 case RBE_EAT_FOOD: power = 5; break;
1557 case RBE_EAT_LITE: power = 5; break;
1558 case RBE_ACID: power = 0; break;
1559 case RBE_ELEC: power = 10; break;
1560 case RBE_FIRE: power = 10; break;
1561 case RBE_COLD: power = 10; break;
1562 case RBE_BLIND: power = 2; break;
1563 case RBE_CONFUSE: power = 10; break;
1564 case RBE_TERRIFY: power = 10; break;
1565 case RBE_PARALYZE: power = 2; break;
1566 case RBE_LOSE_STR: power = 0; break;
1567 case RBE_LOSE_DEX: power = 0; break;
1568 case RBE_LOSE_CON: power = 0; break;
1569 case RBE_LOSE_INT: power = 0; break;
1570 case RBE_LOSE_WIS: power = 0; break;
1571 case RBE_LOSE_CHR: power = 0; break;
1572 case RBE_LOSE_ALL: power = 2; break;
1573 case RBE_SHATTER: power = 60; break;
1574 case RBE_EXP_10: power = 5; break;
1575 case RBE_EXP_20: power = 5; break;
1576 case RBE_EXP_40: power = 5; break;
1577 case RBE_EXP_80: power = 5; break;
1578 case RBE_DISEASE: power = 5; break;
1579 case RBE_TIME: power = 5; break;
1580 case RBE_EXP_VAMP: power = 5; break;
1581 case RBE_DR_MANA: power = 5; break;
1582 case RBE_SUPERHURT: power = 60; break;
1587 if (!effect || check_hit2(power, rlev, ac, m_ptr->stunned))
1589 /* Describe the attack method */
1595 act = "%s¤ò²¥¤Ã¤¿¡£";
1607 act = "%s¤ò¿¨¤Ã¤¿¡£";
1609 act = "touches %s.";
1619 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1621 act = "punches %s.";
1631 act = "%s¤ò½³¤Ã¤¿¡£";
1643 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1655 act = "%s¤ò³ú¤ó¤À¡£";
1667 act = "%s¤ò»É¤·¤¿¡£";
1679 act = "%s¤ò»Â¤Ã¤¿¡£";
1681 act = "slashes %s.";
1690 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1702 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1704 act = "crushes %s.";
1714 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1716 act = "engulfs %s.";
1726 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1728 act = "charges %s.";
1738 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1740 act = "crawls on %s.";
1750 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1752 act = "drools on %s.";
1762 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1764 act = "spits on %s.";
1773 if (see_either) disturb(1, 0);
1788 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1790 act = "gazes at %s.";
1800 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1802 act = "wails at %s.";
1812 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1814 act = "releases spores at %s.";
1824 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1826 act = "projects XXX4's at %s.";
1836 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1838 act = "begs %s for money.";
1848 act = "%s¤òÉî¿«¤·¤¿¡£";
1850 act = "insults %s.";
1860 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1862 act = "moans at %s.";
1872 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1874 act = "sings to %s.";
1883 if (act && see_either)
1885 if (do_silly_attack)
1887 act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
1889 strfmt(temp, act, t_name);
1891 msg_format("%^s¤Ï%s", m_name, temp);
1893 msg_format("%^s %s", m_name, temp);
1898 /* Hack -- assume all attacks are obvious */
1901 /* Roll out the damage */
1902 damage = damroll(d_dice, d_side);
1904 /* Assume no healing effect */
1905 heal_effect = FALSE;
1909 /* Apply appropriate damage */
1921 if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13)) {
1922 int tmp_damage = damage-(damage*((ac < 150) ? ac : 150)/250);
1923 damage = MAX(damage, tmp_damage*2);
1929 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1959 if (one_in_(2)) blinked = TRUE;
2006 pt = GF_OLD_SLEEP; /* sort of close... */
2024 earthquake(m_ptr->fy, m_ptr->fx, 8);
2057 /* Do damage if not exploding */
2060 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
2061 (pt == GF_OLD_SLEEP ? r_ptr->level : damage), pt, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2066 if ((monster_living(tr_ptr)) && (damage > 2))
2068 bool did_heal = FALSE;
2070 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
2073 m_ptr->hp += damroll(4, damage / 6);
2074 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
2076 /* Redraw (later) if needed */
2077 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2078 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2080 /* Special message */
2081 if (see_m && did_heal)
2084 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
2086 msg_format("%^s appears healthier.", m_name);
2096 if ((tr_ptr->flags2 & RF2_AURA_FIRE) &&
2097 !(r_ptr->flags3 & RF3_IM_FIRE) &&
2098 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2104 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2106 msg_format("%^s is suddenly very hot!", m_name);
2110 tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2112 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2113 damroll (1 + ((tr_ptr->level) / 26),
2114 1 + ((tr_ptr->level) / 17)),
2115 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2119 if ((tr_ptr->flags3 & RF3_AURA_COLD) &&
2120 !(r_ptr->flags3 & RF3_IM_COLD) &&
2121 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2127 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2129 msg_format("%^s is suddenly very cold!", m_name);
2133 tr_ptr->r_flags3 |= RF3_AURA_COLD;
2135 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2136 damroll (1 + ((tr_ptr->level) / 26),
2137 1 + ((tr_ptr->level) / 17)),
2138 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2142 if ((tr_ptr->flags2 & (RF2_AURA_ELEC)) &&
2143 !(r_ptr->flags3 & (RF3_IM_ELEC)) &&
2144 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2150 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2152 msg_format("%^s gets zapped!", m_name);
2156 tr_ptr->r_flags2 |= RF2_AURA_ELEC;
2158 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2159 damroll (1 + ((tr_ptr->level) / 26),
2160 1 + ((tr_ptr->level) / 17)),
2161 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2168 /* Monster missed player */
2171 /* Analyze failed attacks */
2187 /* Visible monsters */
2192 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2194 msg_format("%^s misses %s.", m_name, t_name);
2205 /* Analyze "visible" monsters only */
2206 if (see_m && !do_silly_attack)
2208 /* Count "obvious" attacks (and ones that cause damage) */
2209 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2211 /* Count attacks of this type */
2212 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2214 r_ptr->r_blows[ap_cnt]++;
2222 sound(SOUND_EXPLODE);
2224 /* Cancel Invulnerability */
2225 if (m_ptr->invulner) m_ptr->invulner = 0;
2228 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2230 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2244 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2246 msg_print("The thief flees laughing!");
2255 teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE);
2263 * Hack -- local "player stealth" value (see below)
2265 static u32b noise = 0L;
2271 * The monster is known to be within 100 grids of the player
2273 * In several cases, we directly update the monster lore
2275 * Note that a monster is only allowed to "reproduce" if there
2276 * are a limited number of "reproducing" monsters on the current
2277 * level. This should prevent the level from being "swamped" by
2278 * reproducing monsters. It also allows a large mass of mice to
2279 * prevent a louse from multiplying, but this is a small price to
2280 * pay for a simple multiplication method.
2282 * XXX Monster fear is slightly odd, in particular, monsters will
2283 * fixate on opening a door even if they cannot open it. Actually,
2284 * the same thing happens to normal monsters when they hit a door
2286 * XXX XXX XXX In addition, monsters which *cannot* open or bash
2287 * down a door will still stand there trying to open it...
2289 * XXX Technically, need to check for monster in the way
2290 * combined with that monster being in a wall (or door?)
2292 * A "direction" of "5" means "pick a random direction".
2294 static void process_monster(int m_idx)
2296 monster_type *m_ptr = &m_list[m_idx];
2297 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2299 int i, d, oy, ox, ny, nx;
2305 monster_type *y_ptr;
2318 bool gets_angry = FALSE;
2324 if ((m_idx == p_ptr->riding) && !(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 & MFLAG_CHAMELEON) && one_in_(13) && !m_ptr->csleep)
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->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 /* Quantum monsters are odd */
2356 if (r_ptr->flags2 & (RF2_QUANTUM))
2358 /* Sometimes skip move */
2359 if (!randint0(2)) return;
2362 if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2366 if (is_pet(m_ptr) && !(m_ptr->ml))
2373 /* Acquire the monster name */
2374 monster_desc(m_name, m_ptr, 0);
2378 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2380 msg_format("%^s disappears!", m_name);
2385 /* Generate treasure, etc */
2386 monster_death(m_idx, FALSE);
2388 /* Delete the monster */
2389 delete_monster_idx(m_idx);
2394 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2396 msg_print("You feel sad for a moment.");
2405 if (m_ptr->r_idx == MON_SHURYUUDAN)
2407 mon_take_hit_mon(FALSE, m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2409 mon_take_hit_mon(FALSE, m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2412 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) && !p_ptr->inside_battle)
2414 static int riding_pinch = 0;
2416 if (m_ptr->hp < m_ptr->maxhp/3)
2418 bool level_teleport = TRUE;
2420 monster_desc(m_name, m_ptr, 0);
2422 if (m_idx == p_ptr->riding && riding_pinch < 2)
2425 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2427 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
2430 level_teleport = FALSE;
2435 if (m_idx == p_ptr->riding)
2438 msg_format("%s¤Ï¤¢¤Ê¤¿¤Î«Çû¤«¤éæ½Ð¤·¤¿¡£", m_name);
2440 msg_format("%^s succeeded to escape from your restriction!", m_name);
2443 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))
2446 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2448 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2452 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2454 msg_format("%^s read a scroll of teleport level.", m_name);
2457 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2459 msg_format("%^s disappears.", m_name);
2465 delete_monster_idx(m_idx);
2467 if (m_idx == p_ptr->riding)
2469 if (rakuba(-1, FALSE))
2472 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2474 msg_print("You have fallen from riding pet.");
2482 if (m_idx == p_ptr->riding) riding_pinch = 0;
2486 /* Handle "sleep" */
2491 /* Hack -- handle non-aggravation */
2492 if (!p_ptr->aggravate) notice = randint0(1024);
2494 /* Nightmare monsters are more alert */
2495 if (ironman_nightmare) notice /= 2;
2497 /* Hack -- See if monster "notices" player */
2498 if ((notice * notice * notice) <= noise)
2500 /* Hack -- amount of "waking" */
2503 /* Wake up faster near the player */
2504 if (m_ptr->cdis < 50) d = (100 / m_ptr->cdis);
2506 /* Hack -- handle aggravation */
2507 if (p_ptr->aggravate) d = m_ptr->csleep;
2510 if (m_ptr->csleep > d)
2512 /* Monster wakes up "a little bit" */
2515 /* Notice the "not waking up" */
2518 /* Hack -- Count the ignores */
2519 if (r_ptr->r_ignore < MAX_UCHAR)
2529 /* Reset sleep counter */
2532 /* Notice the "waking up" */
2537 /* Acquire the monster name */
2538 monster_desc(m_name, m_ptr, 0);
2540 /* Dump a message */
2542 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
2544 msg_format("%^s wakes up.", m_name);
2548 /* Redraw the health bar */
2549 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2550 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2552 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2))
2553 p_ptr->update |= (PU_MON_LITE);
2555 /* Hack -- Count the wakings */
2556 if (r_ptr->r_wake < MAX_UCHAR)
2564 /* Still sleeping */
2565 if (m_ptr->csleep) return;
2574 /* Make a "saving throw" against stun */
2575 if (randint0(10000) <= r_ptr->level * r_ptr->level)
2581 /* Hack -- Recover from stun */
2582 if (m_ptr->stunned > d)
2584 /* Recover somewhat */
2585 m_ptr->stunned -= d;
2594 /* Message if visible */
2599 /* Acquire the monster name */
2600 monster_desc(m_name, m_ptr, 0);
2602 /* Dump a message */
2604 msg_format("%^s¤ÏÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2606 msg_format("%^s is no longer stunned.", m_name);
2609 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2610 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2615 if (m_ptr->stunned && one_in_(2)) return;
2619 /* Handle confusion */
2620 if (m_ptr->confused)
2622 /* Amount of "boldness" */
2623 int d = randint1(r_ptr->level / 20 + 1);
2625 /* Still confused */
2626 if (m_ptr->confused > d)
2628 /* Reduce the confusion */
2629 m_ptr->confused -= d;
2635 /* No longer confused */
2636 m_ptr->confused = 0;
2638 /* Message if visible */
2643 /* Acquire the monster name */
2644 monster_desc(m_name, m_ptr, 0);
2646 /* Dump a message */
2648 msg_format("%^s¤Ïº®Í𤫤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2650 msg_format("%^s is no longer confused.", m_name);
2653 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2654 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2659 /* Handle Invulnerability */
2660 if (m_ptr->invulner)
2662 /* Reduce by one, note if expires */
2665 if (!(m_ptr->invulner) && m_ptr->ml)
2669 /* Acquire the monster name */
2670 monster_desc(m_name, m_ptr, 0);
2672 /* Dump a message */
2674 msg_format("%^s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ê¤¤¡£", m_name);
2676 msg_format("%^s is no longer invulnerable.", m_name);
2679 m_ptr->energy -= 100;
2680 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2681 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2688 /* Reduce by one, note if expires */
2691 if (!(m_ptr->fast) && m_ptr->ml)
2695 /* Acquire the monster name */
2696 monster_desc(m_name, m_ptr, 0);
2698 /* Dump a message */
2700 msg_format("%^s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2702 msg_format("%^s is no longer fast.", m_name);
2705 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2706 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2713 /* Reduce by one, note if expires */
2716 if (!(m_ptr->slow) && m_ptr->ml)
2720 /* Acquire the monster name */
2721 monster_desc(m_name, m_ptr, 0);
2723 /* Dump a message */
2725 msg_format("%^s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2727 msg_format("%^s is no longer slow.", m_name);
2730 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2731 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2735 if (p_ptr->riding == m_idx)
2737 p_ptr->update |= (PU_BONUS);
2740 /* No one wants to be your friend if you're aggravating */
2741 if (is_friendly(m_ptr) && p_ptr->aggravate)
2744 /* Paranoia... no pet uniques outside wizard mode -- TY */
2745 if (is_pet(m_ptr) &&
2746 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
2747 ((p_ptr->align > 9 && (r_ptr->flags3 & RF3_EVIL)) ||
2748 (p_ptr->align < -9 && (r_ptr->flags3 & RF3_GOOD))))
2749 || (r_ptr->flags3 & RF3_RES_ALL)))
2754 if (p_ptr->inside_battle) gets_angry = FALSE;
2759 monster_desc(m_name, m_ptr, 0);
2761 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2763 msg_format("%^s suddenly becomes hostile!", m_name);
2772 /* Amount of "boldness" */
2773 int d = randint1(r_ptr->level / 20 + 1);
2776 if (m_ptr->monfear > d)
2778 /* Reduce the fear */
2779 m_ptr->monfear -= d;
2782 /* Recover from fear, take note if seen */
2785 /* No longer afraid */
2794 /* Acquire the monster name/poss */
2795 monster_desc(m_name, m_ptr, 0);
2796 monster_desc(m_poss, m_ptr, 0x22);
2798 /* Dump a message */
2800 msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name);
2802 msg_format("%^s recovers %s courage.", m_name, m_poss);
2805 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2810 /* Get the origin */
2815 /* Attempt to "multiply" if able and allowed */
2816 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2820 /* Count the adjacent monsters */
2821 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2823 for (x = ox - 1; x <= ox + 1; x++)
2825 /* Ignore locations off of edge */
2826 if (!in_bounds2(y, x)) continue;
2828 if (cave[y][x].m_idx) k++;
2832 /* Hack -- multiply slower in crowded areas */
2833 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2835 /* Try to multiply */
2836 if (multiply_monster(m_idx, FALSE, is_friendly(m_ptr), is_pet(m_ptr)))
2838 /* Take note if visible */
2841 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2844 /* Multiplying takes energy */
2851 if (!p_ptr->inside_battle)
2853 /* Hack! "Cyber" monster makes noise... */
2854 if (m_ptr->r_idx == MON_CYBER &&
2855 one_in_(CYBERNOISE) &&
2856 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2858 if (disturb_minor) disturb(FALSE, FALSE);
2860 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2862 msg_print("You hear heavy steps.");
2867 /* Some monsters can speak */
2868 if ((r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2869 one_in_(SPEAK_CHANCE) &&
2870 player_has_los_bold(oy, ox))
2873 char monmessage[1024];
2876 /* Acquire the monster name/poss */
2878 monster_desc(m_name, m_ptr, 0);
2881 strcpy(m_name, "¤½¤ì");
2883 strcpy(m_name, "It");
2887 /* Select the file for monster quotes */
2890 filename = "monfear_j.txt";
2892 filename = "monfear.txt";
2895 else if (is_pet(m_ptr))
2897 filename = "monpet_j.txt";
2899 filename = "monpet.txt";
2902 else if (is_friendly(m_ptr))
2904 filename = "monfrien_j.txt";
2906 filename = "monfrien.txt";
2911 filename = "monspeak_j.txt";
2913 filename = "monspeak.txt";
2917 /* Get the monster line */
2918 if (get_rnd_line(filename, m_ptr->r_idx, monmessage) == 0)
2922 msg_format("%^s%s", m_name, monmessage);
2924 msg_format("%^s %s", m_name, monmessage);
2931 /* Attempt to cast a spell */
2932 if (aware && make_attack_spell(m_idx)) return;
2935 * Attempt to cast a spell at an enemy other than the player
2936 * (may slow the game a smidgeon, but I haven't noticed.)
2938 if (monst_spell_monst(m_idx)) return;
2940 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
2942 /* Hack -- Assume no movement */
2943 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2944 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2947 /* Confused -- 100% random */
2948 if (m_ptr->confused || !aware)
2950 /* Try four "random" directions */
2951 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2954 /* 75% random movement */
2955 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2956 (r_ptr->flags1 & RF1_RAND_25) &&
2957 (randint0(100) < 75))
2959 /* Memorize flags */
2960 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2961 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25);
2963 /* Try four "random" directions */
2964 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2967 /* 50% random movement */
2968 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2969 (randint0(100) < 50))
2971 /* Memorize flags */
2972 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2974 /* Try four "random" directions */
2975 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2978 /* 25% random movement */
2979 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2980 (randint0(100) < 25))
2982 /* Memorize flags */
2983 if (m_ptr->ml) r_ptr->r_flags1 |= RF1_RAND_25;
2985 /* Try four "random" directions */
2986 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2989 /* Can't reach player - find something else to hit */
2990 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2992 /* Try four "random" directions */
2993 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2995 /* Look for an enemy */
2996 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2997 get_enemy_dir(m_idx, mm);
3001 /* Pets will follow the player */
3002 else if (is_pet(m_ptr))
3004 /* Are we trying to avoid the player? */
3005 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
3006 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
3008 /* Do we want to find the player? */
3009 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
3011 /* Should we find the player if we can't find a monster? */
3012 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
3014 /* by default, move randomly */
3015 mm[0] = mm[1] = mm[2] = mm[3] = 5;
3017 /* Look for an enemy */
3018 if (!get_enemy_dir(m_idx, mm))
3020 /* Find the player if necessary */
3021 if (avoid || lonely || distant)
3023 /* Remember the leash length */
3024 int dis = p_ptr->pet_follow_distance;
3026 /* Hack -- adjust follow distance temporarily */
3027 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
3029 p_ptr->pet_follow_distance = PET_SEEK_DIST;
3032 /* Find the player */
3033 get_moves(m_idx, mm);
3035 /* Restore the leash */
3036 p_ptr->pet_follow_distance = dis;
3041 /* Friendly monster movement */
3042 else if (!is_hostile(m_ptr))
3044 /* by default, move randomly */
3045 mm[0] = mm[1] = mm[2] = mm[3] = 5;
3047 /* Look for an enemy */
3048 get_enemy_dir(m_idx, mm);
3050 /* Normal movement */
3051 else if (stupid_monsters)
3054 get_moves(m_idx, mm);
3058 /* Logical moves, may do nothing */
3059 if (!get_moves(m_idx, mm)) return;
3062 /* Assume nothing */
3067 /* Assume nothing */
3068 did_open_door = FALSE;
3069 did_bash_door = FALSE;
3070 did_take_item = FALSE;
3071 did_kill_item = FALSE;
3072 did_move_body = FALSE;
3073 did_pass_wall = FALSE;
3074 did_kill_wall = FALSE;
3077 /* Take a zero-terminated array of "directions" */
3078 for (i = 0; mm[i]; i++)
3080 /* Get the direction */
3083 /* Hack -- allow "randomized" motion */
3084 if (d == 5) d = ddd[randint0(8)];
3086 /* Get the destination */
3090 /* Ignore locations off of edge */
3091 if (!in_bounds2(ny, nx)) continue;
3093 /* Access that cave grid */
3094 c_ptr = &cave[ny][nx];
3096 /* Access that cave grid's contents */
3097 y_ptr = &m_list[c_ptr->m_idx];
3099 /* Floor is open? */
3100 if (cave_floor_grid(c_ptr))
3102 /* Go ahead and move */
3106 /* Hack -- player 'in' wall */
3107 else if ((ny == py) && (nx == px))
3112 else if (c_ptr->m_idx)
3114 /* Possibly a monster to attack */
3118 /* Permanent wall */
3119 else if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
3120 (c_ptr->feat <= FEAT_PERM_SOLID))
3125 /* Hack -- semi-transparent terrains are no obstacle */
3126 else if (c_ptr->feat == FEAT_TREES)
3131 /* Hack -- semi-transparent terrains are no obstacle */
3132 else if ((c_ptr->feat == FEAT_MOUNTAIN) && ((r_ptr->flags2 & RF2_KILL_WALL) || (!dun_level && ((r_ptr->flags7 & RF7_CAN_FLY) || (r_ptr->flags8 & RF8_WILD_MOUNTAIN)))))
3138 /* Monster moves through walls (and doors) */
3139 else if (can_pass_wall)
3141 /* Pass through walls/doors/rubble */
3144 /* Monster went through a wall */
3145 did_pass_wall = TRUE;
3148 /* Monster destroys walls (and doors) */
3149 else if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))
3151 /* Eat through walls/doors/rubble */
3154 /* Monster destroyed a wall */
3155 did_kill_wall = TRUE;
3157 if (one_in_(GRINDNOISE))
3160 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
3162 msg_print("There is a grinding sound.");
3167 /* Forget the wall */
3168 c_ptr->info &= ~(CAVE_MARK);
3171 c_ptr->feat = floor_type[randint0(100)];
3172 c_ptr->info &= ~(CAVE_MASK);
3173 c_ptr->info |= CAVE_FLOOR;
3175 /* Note changes to viewable region */
3176 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3179 /* Handle doors and secret doors */
3180 else if (((c_ptr->feat >= FEAT_DOOR_HEAD) &&
3181 (c_ptr->feat <= FEAT_DOOR_TAIL)) ||
3182 (c_ptr->feat == FEAT_SECRET))
3184 bool may_bash = TRUE;
3186 /* Assume no move allowed */
3189 /* Creature can open doors. */
3190 if ((r_ptr->flags2 & RF2_OPEN_DOOR) &&
3191 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3193 /* Closed doors and secret doors */
3194 if ((c_ptr->feat == FEAT_DOOR_HEAD) ||
3195 (c_ptr->feat == FEAT_SECRET))
3197 /* The door is open */
3198 did_open_door = TRUE;
3200 /* Do not bash the door */
3203 /* Assume no move allowed */
3207 /* Locked doors (not jammed) */
3208 else if (c_ptr->feat < FEAT_DOOR_HEAD + 0x08)
3213 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3215 /* Try to unlock it XXX XXX XXX */
3216 if (randint0(m_ptr->hp / 10) > k)
3218 /* Unlock the door */
3219 cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00);
3221 /* Do not bash the door */
3227 /* Stuck doors -- attempt to bash them down if allowed */
3228 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) &&
3229 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3234 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3236 /* Attempt to Bash XXX XXX XXX */
3237 if (randint0(m_ptr->hp / 10) > k)
3241 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
3243 msg_print("You hear a door burst open!");
3247 /* Disturb (sometimes) */
3248 if (disturb_minor) disturb(0, 0);
3250 /* The door was bashed open */
3251 did_bash_door = TRUE;
3253 /* Hack -- fall into doorway */
3259 /* Deal with doors in the way */
3260 if (did_open_door || did_bash_door)
3262 /* Break down the door */
3263 if (did_bash_door && (randint0(100) < 50))
3265 cave_set_feat(ny, nx, FEAT_BROKEN);
3271 cave_set_feat(ny, nx, FEAT_OPEN);
3274 /* Handle viewable doors */
3275 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3279 /* Hack -- check for Glyph of Warding */
3280 if (do_move && (c_ptr->feat == FEAT_GLYPH) &&
3281 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3283 /* Assume no move allowed */
3286 /* Break the ward */
3287 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
3289 /* Describe observable breakage */
3290 if (c_ptr->info & CAVE_MARK)
3293 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3295 msg_print("The rune of protection is broken!");
3300 /* Forget the rune */
3301 c_ptr->info &= ~(CAVE_MARK);
3303 /* Break the rune */
3304 c_ptr->feat = floor_type[randint0(100)];
3305 c_ptr->info &= ~(CAVE_MASK);
3306 c_ptr->info |= CAVE_FLOOR;
3308 /* Allow movement */
3315 else if (do_move && (c_ptr->feat == FEAT_MINOR_GLYPH) &&
3316 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3318 /* Assume no move allowed */
3321 /* Break the ward */
3324 /* Break the ward */
3325 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3327 /* Describe observable breakage */
3328 if (c_ptr->info & CAVE_MARK)
3331 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3333 msg_print("The rune explodes!");
3336 project(0, 2, ny, nx, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_REF | PROJECT_NO_HANGEKI), -1);
3342 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3344 msg_print("An explosive rune was disarmed.");
3348 /* Forget the rune */
3349 c_ptr->info &= ~(CAVE_MARK);
3351 /* Break the rune */
3352 c_ptr->feat = floor_type[randint0(100)];
3353 c_ptr->info &= ~(CAVE_MASK);
3354 c_ptr->info |= CAVE_FLOOR;
3358 if (!m_ptr->r_idx) return;
3359 /* Allow movement */
3363 if (do_move && (ny == py) && (nx == px) && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3368 /* Some monsters never attack */
3369 if (do_move && (ny == py) && (nx == px) &&
3370 (r_ptr->flags1 & RF1_NEVER_BLOW))
3372 /* Hack -- memorize lack of attacks */
3373 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3379 /* The player is in the way. Attack him. */
3380 if (do_move && (ny == py) && (nx == px))
3382 if (!p_ptr->riding || one_in_(2))
3385 (void)make_attack_normal(m_idx);
3395 if ((c_ptr->feat >= FEAT_PATTERN_START) &&
3396 (c_ptr->feat <= FEAT_PATTERN_XTRA2) &&
3397 !do_turn && !(r_ptr->flags7 & RF7_CAN_FLY))
3403 /* A monster is in the way */
3404 if (do_move && c_ptr->m_idx)
3406 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3407 monster_type *m2_ptr = &m_list[c_ptr->m_idx];
3409 /* Assume no movement */
3412 /* Attack 'enemies' */
3413 if (((r_ptr->flags2 & (RF2_KILL_BODY)) &&
3414 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3415 (cave_floor_grid(c_ptr)) &&
3416 (c_ptr->m_idx != p_ptr->riding)) ||
3417 are_enemies(m_ptr, m2_ptr) || m_ptr->confused)
3421 if (r_ptr->flags2 & RF2_KILL_BODY) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3424 if ((m2_ptr->r_idx) && (m2_ptr->hp >= 0))
3426 if (monst_attack_monst(m_idx, cave[ny][nx].m_idx))
3431 /* Push past weaker monsters (unless leaving a wall) */
3432 else if ((r_ptr->flags2 & RF2_MOVE_BODY) &&
3433 (r_ptr->mexp > z_ptr->mexp) && cave_floor_grid(c_ptr) &&
3434 (cave_floor_grid(&cave[m_ptr->fy][m_ptr->fx])) &&
3435 (c_ptr->m_idx != p_ptr->riding))
3437 /* Allow movement */
3440 /* Monster pushed past another monster */
3441 did_move_body = TRUE;
3443 /* XXX XXX XXX Message */
3448 * Check if monster can cross terrain
3449 * This is checked after the normal attacks
3450 * to allow monsters to attack an enemy,
3451 * even if it can't enter the terrain.
3453 if (do_move && !monster_can_cross_terrain(c_ptr->feat, r_ptr))
3455 /* Assume no move allowed */
3459 /* Some monsters never move */
3460 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3462 /* Hack -- memorize lack of attacks */
3463 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3469 if (m_idx == p_ptr->riding)
3471 if (!p_ptr->riding_ryoute && !(m_list[p_ptr->riding].monfear)) do_move = FALSE;
3474 /* Creature has been allowed move */
3477 s16b this_o_idx, next_o_idx;
3482 /* Hack -- Update the old location */
3483 cave[oy][ox].m_idx = c_ptr->m_idx;
3485 if (cave[ny][nx].feat == FEAT_TREES)
3487 if (r_ptr->flags2 & RF2_KILL_WALL)
3489 c_ptr->feat = FEAT_GRASS;
3490 c_ptr->info &= ~(CAVE_MASK);
3491 c_ptr->info |= CAVE_FLOOR;
3493 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3495 m_ptr->energy -= 100;
3499 /* Mega-Hack -- move the old monster, if any */
3502 /* Move the old monster */
3506 /* Update the old monster */
3507 update_mon(c_ptr->m_idx, TRUE);
3509 /* Wake up the moved monster */
3510 m_list[c_ptr->m_idx].csleep = 0;
3513 /* Hack -- Update the new location */
3514 c_ptr->m_idx = m_idx;
3516 /* Move the monster */
3520 /* Update the monster */
3521 update_mon(m_idx, TRUE);
3523 if (p_ptr->riding == m_idx)
3529 /* Redraw the old grid */
3532 /* Redraw the new grid */
3535 if (p_ptr->riding == m_idx)
3540 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW);
3542 /* Update the monsters */
3543 p_ptr->update |= (PU_DISTANCE);
3546 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3549 /* Possible disturb */
3550 if (m_ptr->ml && (disturb_move ||
3551 ((m_ptr->mflag & MFLAG_VIEW) &&
3555 if (is_hostile(m_ptr))
3559 /* Scan all objects in the grid */
3560 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3564 /* Acquire object */
3565 o_ptr = &o_list[this_o_idx];
3567 /* Acquire next object */
3568 next_o_idx = o_ptr->next_o_idx;
3571 if (o_ptr->tval == TV_GOLD) continue;
3574 * Skip "real" corpses and statues, to avoid extreme
3575 * silliness like a novice rogue pockets full of statues
3578 if ((o_ptr->tval == TV_CORPSE) ||
3579 (o_ptr->tval == TV_STATUE)) continue;
3581 /* Take or Kill objects on the floor */
3582 if ((r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3583 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)))
3590 char o_name[MAX_NLEN];
3592 /* Extract some flags */
3593 object_flags(o_ptr, &f1, &f2, &f3);
3595 /* Acquire the object name */
3596 object_desc(o_name, o_ptr, TRUE, 3);
3598 /* Acquire the monster name */
3599 monster_desc(m_name, m_ptr, 0x04);
3601 /* React to objects that hurt the monster */
3602 if (f1 & TR1_KILL_DRAGON) flg3 |= (RF3_DRAGON);
3603 if (f1 & TR1_SLAY_DRAGON) flg3 |= (RF3_DRAGON);
3604 if (f1 & TR1_SLAY_TROLL) flg3 |= (RF3_TROLL);
3605 if (f1 & TR1_SLAY_GIANT) flg3 |= (RF3_GIANT);
3606 if (f1 & TR1_SLAY_ORC) flg3 |= (RF3_ORC);
3607 if (f1 & TR1_SLAY_DEMON) flg3 |= (RF3_DEMON);
3608 if (f1 & TR1_SLAY_UNDEAD) flg3 |= (RF3_UNDEAD);
3609 if (f1 & TR1_SLAY_ANIMAL) flg3 |= (RF3_ANIMAL);
3610 if (f1 & TR1_SLAY_EVIL) flg3 |= (RF3_EVIL);
3612 /* The object cannot be picked up by the monster */
3613 if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) ||
3616 /* Only give a message for "take_item" */
3617 if ((r_ptr->flags2 & (RF2_TAKE_ITEM)) && (r_ptr->flags2 & (RF2_STUPID)))
3620 did_take_item = TRUE;
3622 /* Describe observable situations */
3623 if (m_ptr->ml && player_can_see_bold(ny, nx))
3625 /* Dump a message */
3627 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£", m_name, o_name);
3629 msg_format("%^s tries to pick up %s, but fails.", m_name, o_name);
3635 /* Pick up the item */
3636 else if (r_ptr->flags2 & RF2_TAKE_ITEM)
3639 did_take_item = TRUE;
3641 /* Describe observable situations */
3642 if (player_can_see_bold(ny, nx))
3644 /* Dump a message */
3646 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3648 msg_format("%^s picks up %s.", m_name, o_name);
3653 /* Excise the object */
3654 excise_object_idx(this_o_idx);
3657 o_ptr->marked = FALSE;
3659 /* Forget location */
3660 o_ptr->iy = o_ptr->ix = 0;
3662 /* Memorize monster */
3663 o_ptr->held_m_idx = m_idx;
3666 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3669 m_ptr->hold_o_idx = this_o_idx;
3672 /* Destroy the item if not a pet */
3673 else if (!is_pet(m_ptr))
3676 did_kill_item = TRUE;
3678 /* Describe observable situations */
3679 if (player_has_los_bold(ny, nx))
3681 /* Dump a message */
3683 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3685 msg_format("%^s destroys %s.", m_name, o_name);
3690 /* Delete the object */
3691 delete_object_idx(this_o_idx);
3697 /* Stop when done */
3702 * Forward movements failed, but now recieved LOS attack!
3703 * Try to flow by smell.
3705 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3706 m_ptr->mflag2 &= ~MFLAG_NOFLOW;
3708 /* If we haven't done anything, try casting a spell again */
3709 if (!do_turn && !do_move && !m_ptr->monfear && !stupid_monsters && !(p_ptr->riding == m_idx) && aware)
3712 if (make_attack_spell(m_idx)) return;
3716 /* Notice changes in view */
3719 /* Update some things */
3720 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
3723 /* Notice changes in view */
3724 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !p_ptr->inside_battle)))
3726 /* Update some things */
3727 p_ptr->update |= (PU_MON_LITE);
3730 /* Learn things from observable monster */
3733 /* Monster opened a door */
3734 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3736 /* Monster bashed a door */
3737 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3739 /* Monster tried to pick something up */
3740 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3742 /* Monster tried to crush something */
3743 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3745 /* Monster pushed past another monster */
3746 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3748 /* Monster passed through a wall */
3749 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3751 /* Monster destroyed a wall */
3752 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3756 /* Hack -- get "bold" if out of options */
3757 if (!do_turn && !do_move && m_ptr->monfear && aware)
3759 /* No longer afraid */
3762 /* Message if seen */
3767 /* Acquire the monster name */
3768 monster_desc(m_name, m_ptr, 0);
3770 /* Dump a message */
3772 msg_format("%^s¤ÏÀ襤¤ò·è°Õ¤·¤¿¡ª", m_name);
3774 msg_format("%^s turns to fight!", m_name);
3777 chg_virtue(V_COMPASSION, -1);
3780 /* XXX XXX XXX Actually do something now (?) */
3785 * Process all the "live" monsters, once per game turn.
3787 * During each game turn, we scan through the list of all the "live" monsters,
3788 * (backwards, so we can excise any "freshly dead" monsters), energizing each
3789 * monster, and allowing fully energized monsters to move, attack, pass, etc.
3791 * Note that monsters can never move in the monster array (except when the
3792 * "compact_monsters()" function is called by "dungeon()" or "save_player()").
3794 * This function is responsible for at least half of the processor time
3795 * on a normal system with a "normal" amount of monsters and a player doing
3798 * When the player is resting, virtually 90% of the processor time is spent
3799 * in this function, and its children, "process_monster()" and "make_move()".
3801 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",
3802 * especially when the player is running.
3804 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"
3805 * monsters while they are still being "born". A monster is "fresh" only
3806 * during the turn in which it is created, and we use the "hack_m_idx" to
3807 * determine if the monster is yet to be processed during the current turn.
3809 * Note the special "MFLAG_NICE" flag, which allows the player to get one
3810 * move before any "nasty" monsters get to use their spell attacks.
3812 * Note that when the "knowledge" about the currently tracked monster
3813 * changes (flags, attacks, spells), we induce a redraw of the monster
3816 void process_monsters(void)
3823 monster_type *m_ptr;
3824 monster_race *r_ptr;
3826 int old_monster_race_idx;
3828 u32b old_r_flags1 = 0L;
3829 u32b old_r_flags2 = 0L;
3830 u32b old_r_flags3 = 0L;
3831 u32b old_r_flags4 = 0L;
3832 u32b old_r_flags5 = 0L;
3833 u32b old_r_flags6 = 0L;
3835 byte old_r_blows0 = 0;
3836 byte old_r_blows1 = 0;
3837 byte old_r_blows2 = 0;
3838 byte old_r_blows3 = 0;
3840 byte old_r_cast_inate = 0;
3841 byte old_r_cast_spell = 0;
3845 /* Clear monster fighting indicator */
3848 /* Memorize old race */
3849 old_monster_race_idx = p_ptr->monster_race_idx;
3851 /* Acquire knowledge */
3852 if (p_ptr->monster_race_idx)
3854 /* Acquire current monster */
3855 r_ptr = &r_info[p_ptr->monster_race_idx];
3857 /* Memorize flags */
3858 old_r_flags1 = r_ptr->r_flags1;
3859 old_r_flags2 = r_ptr->r_flags2;
3860 old_r_flags3 = r_ptr->r_flags3;
3861 old_r_flags4 = r_ptr->r_flags4;
3862 old_r_flags5 = r_ptr->r_flags5;
3863 old_r_flags6 = r_ptr->r_flags6;
3865 /* Memorize blows */
3866 old_r_blows0 = r_ptr->r_blows[0];
3867 old_r_blows1 = r_ptr->r_blows[1];
3868 old_r_blows2 = r_ptr->r_blows[2];
3869 old_r_blows3 = r_ptr->r_blows[3];
3871 /* Memorize castings */
3872 old_r_cast_inate = r_ptr->r_cast_inate;
3873 old_r_cast_spell = r_ptr->r_cast_spell;
3877 /* Hack -- calculate the "player noise" */
3878 noise = (1L << (30 - p_ptr->skill_stl));
3881 /* Process the monsters (backwards) */
3882 for (i = m_max - 1; i >= 1; i--)
3884 /* Access the monster */
3886 r_ptr = &r_info[m_ptr->r_idx];
3888 /* Handle "leaving" */
3889 if (p_ptr->leaving) break;
3891 /* Ignore "dead" monsters */
3892 if (!m_ptr->r_idx) continue;
3894 if (p_ptr->wild_mode) continue;
3897 /* Handle "fresh" monsters */
3898 if (m_ptr->mflag & MFLAG_BORN)
3900 /* No longer "fresh" */
3901 m_ptr->mflag &= ~(MFLAG_BORN);
3907 /* Hack -- Require proximity */
3908 if (m_ptr->cdis >= 100) continue;
3911 /* Access the location */
3915 /* Flow by smell is allowed */
3916 if (!stupid_monsters && !p_ptr->no_flowed)
3918 m_ptr->mflag2 &= ~MFLAG_NOFLOW;
3921 /* Assume no move */
3924 /* Handle "sensing radius" */
3925 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > 20 ? 20 : r_ptr->aaf) : r_ptr->aaf))
3927 /* We can "sense" the player */
3931 /* Handle "sight" and "aggravation" */
3932 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3933 (player_has_los_bold(fy, fx) || p_ptr->aggravate))
3935 /* We can "see" or "feel" the player */
3939 /* Hack -- Monsters can "smell" the player from far away */
3940 /* Note that most monsters have "aaf" of "20" or so */
3941 else if (!stupid_monsters && !(m_ptr->mflag2 & MFLAG_NOFLOW) &&
3942 (cave_floor_bold(py, px) || (cave[py][px].feat == FEAT_TREES)) &&
3943 (cave[py][px].when == cave[fy][fx].when) &&
3944 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3945 (cave[fy][fx].dist < r_ptr->aaf))
3947 /* We can "smell" the player */
3950 else if (m_ptr->target_y) test = TRUE;
3953 if (!test) continue;
3956 if (p_ptr->riding == i)
3957 speed = p_ptr->pspeed;
3960 speed = MIN(199, m_ptr->mspeed);
3962 /* Monsters move quickly in Nightmare mode */
3963 if (ironman_nightmare)
3965 speed = MIN(199, m_ptr->mspeed + 5);
3968 if (m_ptr->fast) speed = MIN(199, speed + 10);
3969 if (m_ptr->slow) speed = MAX(0, speed - 10);
3972 e = extract_energy[speed];
3974 /* Give this monster some energy */
3975 if(randint0(60) < e)
3976 m_ptr->energy += gain_energy();
3979 /* Not enough energy to move */
3980 if (m_ptr->energy < 100) continue;
3982 /* Use up "some" energy */
3983 m_ptr->energy -= 100;
3986 /* Save global index */
3989 /* Process the monster */
3992 reset_target(m_ptr);
3994 /* Give up flow_by_smell when it might useless */
3995 if (p_ptr->no_flowed && one_in_(3))
3996 m_ptr->mflag2 |= MFLAG_NOFLOW;
3998 /* Hack -- notice death or departure */
3999 if (!alive || death) break;
4001 /* Notice leaving */
4002 if (p_ptr->leaving) break;
4005 /* Reset global index */
4009 /* Tracking a monster race (the same one we were before) */
4010 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
4012 /* Acquire monster race */
4013 r_ptr = &r_info[p_ptr->monster_race_idx];
4015 /* Check for knowledge change */
4016 if ((old_r_flags1 != r_ptr->r_flags1) ||
4017 (old_r_flags2 != r_ptr->r_flags2) ||
4018 (old_r_flags3 != r_ptr->r_flags3) ||
4019 (old_r_flags4 != r_ptr->r_flags4) ||
4020 (old_r_flags5 != r_ptr->r_flags5) ||
4021 (old_r_flags6 != r_ptr->r_flags6) ||
4022 (old_r_blows0 != r_ptr->r_blows[0]) ||
4023 (old_r_blows1 != r_ptr->r_blows[1]) ||
4024 (old_r_blows2 != r_ptr->r_blows[2]) ||
4025 (old_r_blows3 != r_ptr->r_blows[3]) ||
4026 (old_r_cast_inate != r_ptr->r_cast_inate) ||
4027 (old_r_cast_spell != r_ptr->r_cast_spell))
4030 p_ptr->window |= (PW_MONSTER);
4037 bool process_the_world(int num, int who, bool vs_player)
4039 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
4041 if(world_monster) return (FALSE);
4046 monster_desc(m_name, m_ptr, 0);
4050 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
4052 msg_format("%s yells 'The World! Time has stopped!'", m_name);
4056 msg_print("¡Ö»þ¤è¡ª¡×");
4058 msg_format("%s yells 'Time!'", m_name);
4060 else msg_print("hek!");
4065 world_monster = TRUE;
4067 if (vs_player) do_cmd_redraw();
4071 if(!m_ptr->r_idx) break;
4072 process_monster(hack_m_idx);
4074 reset_target(m_ptr);
4077 if (p_ptr->notice) notice_stuff();
4080 if (p_ptr->update) update_stuff();
4083 if (p_ptr->redraw) redraw_stuff();
4086 if (p_ptr->window) window_stuff();
4089 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
4093 p_ptr->redraw |= (PR_MAP);
4095 /* Update monsters */
4096 p_ptr->update |= (PU_MONSTERS);
4099 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4101 world_monster = FALSE;
4102 if (vs_player || los(py, px, m_ptr->fy, m_ptr->fx))
4105 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
4107 msg_print("You feel time flowing around you once more.");
4118 void monster_gain_exp(int m_idx, int s_idx)
4120 monster_type *m_ptr = &m_list[m_idx];
4121 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4122 monster_race *s_ptr = &r_info[s_idx];
4125 if (p_ptr->inside_battle) return;
4127 if (!r_ptr->next_exp) return;
4129 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
4130 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
4131 if (!dun_level) new_exp /= 5;
4132 m_ptr->exp += new_exp;
4133 if (m_ptr->mflag2 & MFLAG_CHAMELEON) return;
4135 if (m_ptr->exp >= r_ptr->next_exp)
4138 int old_hp = m_ptr->hp;
4139 int old_maxhp = m_ptr->max_maxhp;
4140 int old_r_idx = m_ptr->r_idx;
4143 monster_desc(m_name, m_ptr, 0);
4144 m_ptr->r_idx = r_ptr->next_r_idx;
4145 r_ptr = &r_info[m_ptr->r_idx];
4146 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
4148 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
4152 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
4154 if (ironman_nightmare)
4156 u32b hp = m_ptr->max_maxhp * 2L;
4158 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
4160 m_ptr->maxhp = m_ptr->max_maxhp;
4161 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
4163 /* Extract the monster base speed */
4164 m_ptr->mspeed = r_ptr->speed;
4166 /* Hack -- small racial variety */
4167 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
4169 /* Allow some small variation per monster */
4171 i = extract_energy[r_ptr->speed] / 3;
4172 if (i) m_ptr->mspeed += rand_spread(0, i);
4175 i = extract_energy[r_ptr->speed] / 10;
4176 if (i) m_ptr->mspeed += rand_spread(0, i);
4180 if (m_ptr->mspeed > 199) m_ptr->mspeed = 199;
4184 if (is_pet(m_ptr) || m_ptr->ml)
4187 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
4189 msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
4191 r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
4193 update_mon(m_idx, FALSE);
4194 lite_spot(m_ptr->fy, m_ptr->fx);
4196 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;