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);
68 t_ptr = &m_list[t_idx];
70 /* The monster itself isn't a target */
71 if (t_ptr == m_ptr) continue;
73 /* Paranoia -- Skip dead monsters */
74 if (!t_ptr->r_idx) continue;
78 /* Hack -- only fight away from player */
79 if (p_ptr->pet_follow_distance < 0)
81 /* No fighting near player */
82 if (t_ptr->cdis <= (0 - p_ptr->pet_follow_distance))
87 /* Hack -- no fighting away from player */
88 else if ((m_ptr->cdis < t_ptr->cdis) &&
89 (t_ptr->cdis > p_ptr->pet_follow_distance))
94 if (r_ptr->aaf < t_ptr->cdis) continue;
97 /* Monster must be 'an enemy' */
98 if (!are_enemies(m_ptr, t_ptr)) continue;
100 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)));
102 /* Monster must be projectable if we can't pass through walls */
103 if (!can_pass_wall &&
104 !projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
109 !in_disintegration_range(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
114 /* OK -- we've got a target */
120 if (!x && !y) return FALSE;
123 /* Extract the direction */
128 if ((y < 0) && (x == 0))
135 else if ((y > 0) && (x == 0))
142 else if ((x > 0) && (y == 0))
149 else if ((x < 0) && (y == 0))
156 else if ((y < 0) && (x < 0))
163 else if ((y < 0) && (x > 0))
170 else if ((y > 0) && (x < 0))
177 else if ((y > 0) && (x > 0))
184 /* Found a monster */
190 * Hack, based on mon_take_hit... perhaps all monster attacks on
191 * other monsters should use this?
193 void mon_take_hit_mon(int m_idx, int dam, bool *fear, cptr note, int who)
195 monster_type *m_ptr = &m_list[m_idx];
197 monster_race *r_ptr = &r_info[m_ptr->r_idx];
201 bool seen = m_ptr->ml;
203 /* Can the player be aware of this attack? */
204 bool known = (m_ptr->cdis <= MAX_SIGHT);
206 /* Extract monster name */
207 monster_desc(m_name, m_ptr, 0);
209 /* Redraw (later) if needed */
210 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
211 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
216 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
218 if (m_ptr->invulner && randint0(PENETRATE_INVULNERABILITY))
223 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
225 msg_format("%^s is unharmed.", m_name);
233 if (r_ptr->flags3 & RF3_RES_ALL)
238 if((dam == 0) && one_in_(3)) dam = 1;
245 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
247 msg_format("%^s is unharmed.", m_name);
258 /* It is dead now... or is it? */
261 if (((r_ptr->flags1 & RF1_UNIQUE) ||
262 (r_ptr->flags7 & RF7_UNIQUE_7) ||
263 (r_ptr->flags1 & RF1_QUESTOR)) &&
264 !p_ptr->inside_battle)
271 if (!monster_living(r_ptr))
282 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
283 /* Unseen death by normal attack */
288 /* Death by special attack */
292 msg_format("%^s%s", m_name, note);
294 msg_format("%^s%s", m_name, note);
298 /* Death by normal attack -- nonliving monster */
299 else if (!monster_living(r_ptr))
302 msg_format("%^s¤ÏÇ˲õ¤µ¤ì¤¿¡£", m_name);
304 msg_format("%^s is destroyed.", m_name);
308 /* Death by normal attack -- living monster */
312 msg_format("%^s¤Ï»¦¤µ¤ì¤¿¡£", m_name);
314 msg_format("%^s is killed.", m_name);
320 monster_gain_exp(who, m_ptr->r_idx);
322 /* Generate treasure */
323 monster_death(m_idx, FALSE);
325 /* Delete the monster */
326 delete_monster_idx(m_idx);
331 /* Monster is dead */
338 /* Mega-Hack -- Pain cancels fear */
339 if (m_ptr->monfear && (dam > 0))
341 int tmp = randint1(dam / 4);
343 /* Cure a little fear */
344 if (tmp < m_ptr->monfear)
347 m_ptr->monfear -= tmp;
350 /* Cure all the fear */
361 /* Sometimes a monster gets scared by damage */
362 if (!m_ptr->monfear && !(r_ptr->flags3 & RF3_NO_FEAR))
366 /* Percentage of fully healthy */
367 percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
370 * Run (sometimes) if at 10% or less of max hit points,
371 * or (usually) when hit for half its current hit points
373 if (((percentage <= 10) && (randint0(10) < percentage)) ||
374 ((dam >= m_ptr->hp) && (randint0(100) < 80)))
376 /* Hack -- note fear */
379 /* XXX XXX XXX Hack -- Add some timed fear */
380 m_ptr->monfear += (randint1(10) +
381 (((dam >= m_ptr->hp) && (percentage > 7)) ?
382 20 : ((11 - percentage) * 5)));
386 #endif /* ALLOW_FEAR */
388 if ((dam > 0) && !is_pet(m_ptr) && !is_friendly(m_ptr) && (who != m_idx))
390 if (is_pet(&m_list[who]) && !player_bold(m_ptr->target_y, m_ptr->target_x))
392 set_target(m_ptr, m_list[who].fy, m_list[who].fx);
396 if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
400 /* Extract monster name */
401 monster_desc(m_name, m_ptr, 0);
403 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
404 if (rakuba((dam > 200) ? 200 : dam, FALSE))
407 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
409 msg_format("You have thrown off from %s!", m_name);
420 * Returns whether a given monster will try to run from the player.
422 * Monsters will attempt to avoid very powerful players. See below.
424 * Because this function is called so often, little details are important
425 * for efficiency. Like not using "mod" or "div" when possible. And
426 * attempting to check the conditions in an optimal order. Note that
427 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.
429 * Note that this function is responsible for about one to five percent
430 * of the processor use in normal conditions...
432 static int mon_will_run(int m_idx)
434 monster_type *m_ptr = &m_list[m_idx];
438 monster_race *r_ptr = &r_info[m_ptr->r_idx];
447 /* Friends can be commanded to avoid the player */
450 /* Are we trying to avoid the player? */
451 return ((p_ptr->pet_follow_distance < 0) &&
452 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
455 /* Keep monsters from running too far away */
456 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
458 /* All "afraid" monsters will run away */
459 if (m_ptr->monfear) return (TRUE);
463 /* Nearby monsters will not become terrified */
464 if (m_ptr->cdis <= 5) return (FALSE);
466 /* Examine player power (level) */
469 /* Examine monster power (level plus morale) */
470 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
472 /* Optimize extreme cases below */
473 if (m_lev > p_lev + 4) return (FALSE);
474 if (m_lev + 4 <= p_lev) return (TRUE);
476 /* Examine player health */
480 /* Examine monster health */
482 m_mhp = m_ptr->maxhp;
484 /* Prepare to optimize the calculation */
485 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
486 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
488 /* Strong players scare strong monsters */
489 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
493 /* Assume no terror */
501 * Search spell castable grid
503 static bool get_moves_aux2(int m_idx, int *yp, int *xp)
505 int i, y, x, y1, x1, best = 999;
508 bool can_open_door = FALSE;
511 monster_type *m_ptr = &m_list[m_idx];
512 monster_race *r_ptr = &r_info[m_ptr->r_idx];
514 /* Monster location */
518 /* Monster can already cast spell to player */
519 if (projectable(y1, x1, py, px)) return (FALSE);
521 /* Set current grid cost */
522 now_cost = cave[y1][x1].cost;
523 if (now_cost == 0) now_cost = 999;
525 /* Can monster bash or open doors? */
526 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
528 can_open_door = TRUE;
531 /* Check nearby grids, diagonals first */
532 for (i = 7; i >= 0; i--)
536 /* Get the location */
540 /* Ignore locations off of edge */
541 if (!in_bounds2(y, x)) continue;
543 /* Simply move to player */
544 if (player_bold(y, x)) return (FALSE);
550 /* Monster cannot kill or pass walls */
551 if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) || (r_ptr->flags2 & RF2_KILL_WALL)))
553 if (cost == 0) continue;
554 if (!can_open_door && is_closed_door(c_ptr->feat)) continue;
557 /* Hack -- for kill or pass wall monster.. */
558 if (cost == 0) cost = 998;
560 if (now_cost < cost) continue;
562 if (!projectable(y, x, py, px)) continue;
564 /* Accept louder sounds */
565 if (best < cost) continue;
568 (*yp) = y1 + ddy_ddd[i];
569 (*xp) = x1 + ddx_ddd[i];
572 /* No legal move (?) */
573 if (best == 999) return (FALSE);
581 * Choose the "best" direction for "flowing"
583 * Note that ghosts and rock-eaters are never allowed to "flow",
584 * since they should move directly towards the player.
586 * Prefer "non-diagonal" directions, but twiddle them a little
587 * to angle slightly towards the player's actual location.
589 * Allow very perceptive monsters to track old "spoor" left by
590 * previous locations occupied by the player. This will tend
591 * to have monsters end up either near the player or on a grid
592 * recently occupied by the player (and left via "teleport").
594 * Note that if "smell" is turned on, all monsters get vicious.
596 * Also note that teleporting away from a location will cause
597 * the monsters who were chasing you to converge on that location
598 * as long as you are still near enough to "annoy" them without
599 * being close enough to chase directly. I have no idea what will
600 * happen if you combine "smell" with low "aaf" values.
602 static bool get_moves_aux(int m_idx, int *yp, int *xp, bool no_flow)
604 int i, y, x, y1, x1, best;
607 bool use_scent = FALSE;
609 monster_type *m_ptr = &m_list[m_idx];
610 monster_race *r_ptr = &r_info[m_ptr->r_idx];
612 /* Can monster cast attack spell? */
613 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
614 r_ptr->flags5 & (RF5_ATTACK_MASK) ||
615 r_ptr->flags6 & (RF6_ATTACK_MASK))
617 /* Can move spell castable grid? */
618 if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
621 /* Monster can't flow */
622 if (no_flow) return (FALSE);
624 /* Monster can go through rocks */
625 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) return (FALSE);
626 if (r_ptr->flags2 & RF2_KILL_WALL) return (FALSE);
627 if (!cave_floor_bold(py, px) && (cave[py][px].feat != FEAT_TREES)) return (FALSE);
629 /* Monster location */
633 /* Hack -- Player can see us, run towards him */
634 if (player_has_los_bold(y1, x1)) return (FALSE);
637 c_ptr = &cave[y1][x1];
639 /* If we can hear noises, advance towards them */
645 /* Otherwise, try to follow a scent trail */
646 else if (c_ptr->when)
649 if (cave[py][px].when - c_ptr->when > 127) return (FALSE);
655 /* Otherwise, advance blindly */
661 /* Check nearby grids, diagonals first */
662 for (i = 7; i >= 0; i--)
664 /* Get the location */
668 /* Ignore locations off of edge */
669 if (!in_bounds2(y, x)) continue;
673 /* We're following a scent trail */
676 int when = c_ptr->when;
678 /* Accept younger scent */
679 if (best > when) continue;
683 /* We're using sound */
688 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
690 else cost = c_ptr->cost;
692 /* Accept louder sounds */
693 if ((cost == 0) || (best < cost)) continue;
697 /* Hack -- Save the "twiddled" location */
698 (*yp) = py + 16 * ddy_ddd[i];
699 (*xp) = px + 16 * ddx_ddd[i];
702 /* No legal move (?) */
703 if (best == 999 || best == 0) return (FALSE);
711 * Provide a location to flee to, but give the player a wide berth.
713 * A monster may wish to flee to a location that is behind the player,
714 * but instead of heading directly for it, the monster should "swerve"
715 * around the player so that he has a smaller chance of getting hit.
717 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
719 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
723 monster_type *m_ptr = &m_list[m_idx];
725 /* Monster location */
729 /* Desired destination */
733 /* Check nearby grids, diagonals first */
734 for (i = 7; i >= 0; i--)
738 /* Get the location */
742 /* Ignore locations off of edge */
743 if (!in_bounds2(y, x)) continue;
745 /* Don't move toward player */
746 /* if (cave[y][x].dist < 3) continue; */ /* Hmm.. Need it? */
748 /* Calculate distance of this grid from our destination */
749 dis = distance(y, x, y1, x1);
751 /* Score this grid */
752 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
754 /* No negative scores */
757 /* Ignore lower scores */
758 if (s < score) continue;
760 /* Save the score and time */
763 /* Save the location */
768 /* No legal move (?) */
769 if (score == -1) return (FALSE);
780 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
783 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
784 * offsets of all the locations with a distance of n from a central point,
785 * with an offset of (0,0) indicating no more offsets at this distance.
787 * This is, of course, fairly unreadable, but it eliminates multiple loops
788 * from the previous version.
790 * It is probably better to replace these arrays with code to compute
791 * the relevant arrays, even if the storage is pre-allocated in hard
792 * coded sizes. At the very least, code should be included which is
793 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
795 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
797 * These arrays could be combined into two big arrays, using sub-arrays
798 * to hold the offsets and lengths of each portion of the sub-arrays, and
799 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
803 static sint d_off_y_0[] =
806 static sint d_off_x_0[] =
810 static sint d_off_y_1[] =
811 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
813 static sint d_off_x_1[] =
814 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
817 static sint d_off_y_2[] =
818 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
820 static sint d_off_x_2[] =
821 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
824 static sint d_off_y_3[] =
825 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
828 static sint d_off_x_3[] =
829 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
833 static sint d_off_y_4[] =
834 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
835 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
837 static sint d_off_x_4[] =
838 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
839 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
842 static sint d_off_y_5[] =
843 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
844 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
847 static sint d_off_x_5[] =
848 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
849 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
853 static sint d_off_y_6[] =
854 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
855 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
858 static sint d_off_x_6[] =
859 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
860 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
861 -3, 2, 3, -1, 0, 1, 0 };
864 static sint d_off_y_7[] =
865 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
866 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
867 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
869 static sint d_off_x_7[] =
870 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
871 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
872 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
876 static sint d_off_y_8[] =
877 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
878 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
879 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
882 static sint d_off_x_8[] =
883 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
884 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
885 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
889 static sint d_off_y_9[] =
890 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
891 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
892 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
893 7, 8, 8, 8, 8, 9, 9, 9, 0 };
895 static sint d_off_x_9[] =
896 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
897 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
898 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
899 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
902 static sint *dist_offsets_y[10] =
904 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
905 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
908 static sint *dist_offsets_x[10] =
910 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
911 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
915 * Choose a "safe" location near a monster for it to run toward.
917 * A location is "safe" if it can be reached quickly and the player
918 * is not able to fire into it (it isn't a "clean shot"). So, this will
919 * cause monsters to "duck" behind walls. Hopefully, monsters will also
920 * try to run towards corridor openings if they are in a room.
922 * This function may take lots of CPU time if lots of monsters are
925 * Return TRUE if a safe location is available.
927 static bool find_safety(int m_idx, int *yp, int *xp)
929 monster_type *m_ptr = &m_list[m_idx];
934 int y, x, dy, dx, d, dis, i;
935 int gy = 0, gx = 0, gdis = 0;
942 /* Start with adjacent locations, spread further */
943 for (d = 1; d < 10; d++)
945 /* Get the lists of points with a distance d from (fx, fy) */
946 y_offsets = dist_offsets_y[d];
947 x_offsets = dist_offsets_x[d];
949 /* Check the locations */
950 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
952 i++, dx = x_offsets[i], dy = y_offsets[i])
957 /* Skip illegal locations */
958 if (!in_bounds(y, x)) continue;
962 /* Skip locations in a wall */
963 if (!cave_floor_grid(c_ptr)) continue;
965 /* Check for "availability" (if monsters can flow) */
966 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
968 /* Ignore grids very far from the player */
969 if (c_ptr->dist == 0) continue;
971 /* Ignore too-distant grids */
972 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
975 /* Check for absence of shot (more or less) */
976 if (!player_has_los_grid(c_ptr))
979 /* Calculate distance from player */
980 dis = distance(y, x, py, px);
982 /* Remember if further than previous */
992 /* Check for success */
999 /* Found safe place */
1010 * Choose a good hiding place near a monster for it to run toward.
1012 * Pack monsters will use this to "ambush" the player and lure him out
1013 * of corridors into open space so they can swarm him.
1015 * Return TRUE if a good location is available.
1017 static bool find_hiding(int m_idx, int *yp, int *xp)
1019 monster_type *m_ptr = &m_list[m_idx];
1024 int y, x, dy, dx, d, dis, i;
1025 int gy = 0, gx = 0, gdis = 999;
1027 sint *y_offsets, *x_offsets;
1031 /* Start with adjacent locations, spread further */
1032 for (d = 1; d < 10; d++)
1034 /* Get the lists of points with a distance d from (fx, fy) */
1035 y_offsets = dist_offsets_y[d];
1036 x_offsets = dist_offsets_x[d];
1038 /* Check the locations */
1039 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
1041 i++, dx = x_offsets[i], dy = y_offsets[i])
1046 /* Skip illegal locations */
1047 if (!in_bounds(y, x)) continue;
1049 c_ptr = &cave[y][x];
1051 /* Skip occupied locations */
1052 if (!cave_empty_grid(c_ptr)) continue;
1054 /* Check for hidden, available grid */
1055 if (!player_has_los_grid(c_ptr) && clean_shot(fy, fx, y, x, FALSE))
1057 /* Calculate distance from player */
1058 dis = distance(y, x, py, px);
1060 /* Remember if closer than previous */
1061 if (dis < gdis && dis >= 2)
1070 /* Check for success */
1077 /* Found good place */
1088 * Choose "logical" directions for monster movement
1090 static bool get_moves(int m_idx, int *mm)
1092 monster_type *m_ptr = &m_list[m_idx];
1093 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1099 bool will_run = mon_will_run(m_idx);
1101 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1102 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
1104 /* Counter attack to an enemy monster */
1105 if (!will_run && m_ptr->target_y)
1107 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
1109 /* The monster must be an enemy, and in LOS */
1111 are_enemies(m_ptr, &m_list[t_m_idx]) &&
1112 los(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1114 /* Extract the "pseudo-direction" */
1115 y = m_ptr->fy - m_ptr->target_y;
1116 x = m_ptr->fx - m_ptr->target_x;
1121 if (!done && !will_run && is_hostile(m_ptr) &&
1122 (r_ptr->flags1 & RF1_FRIENDS) &&
1123 (los(m_ptr->fy, m_ptr->fx, py, px) ||
1124 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1127 * Animal packs try to get the player out of corridors
1128 * (...unless they can move through walls -- TY)
1130 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1131 !(r_ptr->flags2 & RF2_KILL_WALL))
1135 /* Count room grids next to player */
1136 for (i = 0; i < 8; i++)
1138 int xx = px + ddx_ddd[i];
1139 int yy = py + ddy_ddd[i];
1141 if (!in_bounds2(yy, xx)) continue;
1143 c_ptr = &cave[yy][xx];
1146 if (((cave_floor_grid(c_ptr)) || ((c_ptr->feat & 0x60) == 0x60)) &&
1147 monster_can_cross_terrain(c_ptr->feat, r_ptr))
1149 /* One more room grid */
1153 if (cave[py][px].info & CAVE_ROOM) room -= 2;
1154 if (!r_ptr->flags4 && !r_ptr->flags5 && !r_ptr->flags6) room -= 2;
1156 /* Not in a room and strong player */
1157 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
1158 (p_ptr->mhp + p_ptr->msp))
1160 /* Find hiding place */
1161 if (find_hiding(m_idx, &y, &x)) done = TRUE;
1165 /* Monster groups try to surround the player */
1166 if (!done && (cave[m_ptr->fy][m_ptr->fx].dist < 3))
1170 /* Find an empty square near the player to fill */
1171 for (i = 0; i < 8; i++)
1173 /* Pick squares near player (semi-randomly) */
1174 y2 = py + ddy_ddd[(m_idx + i) & 7];
1175 x2 = px + ddx_ddd[(m_idx + i) & 7];
1177 /* Already there? */
1178 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
1180 /* Attack the player */
1187 if (!in_bounds2(y2, x2)) continue;
1189 /* Ignore filled grids */
1190 c_ptr = &cave[y2][x2];
1191 if (!cave_empty_grid(c_ptr)) continue;
1193 /* Try to fill this hole */
1197 /* Extract the new "pseudo-direction" */
1208 /* Flow towards the player */
1209 (void)get_moves_aux(m_idx, &y2, &x2, no_flow);
1211 /* Extract the "pseudo-direction" */
1218 /* Apply fear if possible and necessary */
1219 if (is_pet(m_ptr) && will_run)
1221 /* XXX XXX Not very "smart" */
1226 if (!done && will_run)
1231 /* Try to find safe place */
1232 if (find_safety(m_idx, &y, &x))
1234 /* Attempt to avoid the player */
1237 /* Adjust movement */
1238 if (get_fear_moves_aux(m_idx, &y, &x)) done = TRUE;
1244 /* This is not a very "smart" method XXX XXX */
1252 /* Check for no move */
1253 if (!x && !y) return (FALSE);
1256 /* Extract the "absolute distances" */
1260 /* Do something weird */
1261 if (y < 0) move_val += 8;
1262 if (x > 0) move_val += 4;
1264 /* Prevent the diamond maneuvre */
1265 if (ay > (ax << 1)) move_val += 2;
1266 else if (ax > (ay << 1)) move_val++;
1268 /* Extract some directions */
1413 /* Wants to move... */
1418 static int check_hit2(int power, int level, int ac, int stun)
1422 /* Percentile dice */
1425 if (stun && one_in_(2)) return FALSE;
1427 /* Hack -- Always miss or hit */
1428 if (k < 10) return (k < 5);
1430 /* Calculate the "attack quality" */
1431 i = (power + (level * 3));
1433 /* Power and Level compete against Armor */
1434 if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
1441 /* Monster attacks monster */
1442 static bool monst_attack_monst(int m_idx, int t_idx)
1444 monster_type *m_ptr = &m_list[m_idx];
1445 monster_type *t_ptr = &m_list[t_idx];
1447 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1448 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1452 char m_name[80], t_name[80];
1454 bool blinked, heal_effect;
1455 bool explode = FALSE, touched = FALSE, fear = FALSE;
1456 int y_saver = t_ptr->fy;
1457 int x_saver = t_ptr->fx;
1459 bool see_m = m_ptr->ml;
1460 bool see_t = t_ptr->ml;
1461 bool see_either = see_m || see_t;
1463 /* Can the player be aware of this attack? */
1464 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1465 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1467 /* Cannot attack self */
1468 if (m_idx == t_idx) return FALSE;
1470 /* Not allowed to attack */
1471 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1473 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1481 /* Extract the effective monster level */
1482 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1484 /* Get the monster name (or "it") */
1485 monster_desc(m_name, m_ptr, 0);
1487 /* Get the monster name (or "it") */
1488 monster_desc(t_name, t_ptr, 0);
1490 /* Assume no blink */
1493 if (!see_either && known)
1498 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
1500 /* Scan through all four blows */
1501 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1503 bool obvious = FALSE;
1510 /* Extract the attack infomation */
1511 int effect = r_ptr->blow[ap_cnt].effect;
1512 int method = r_ptr->blow[ap_cnt].method;
1513 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1514 int d_side = r_ptr->blow[ap_cnt].d_side;
1516 if (!m_ptr->r_idx) break;
1518 /* Stop attacking if the target dies! */
1519 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1522 /* Hack -- no more attacks */
1525 if (blinked) /* Stop! */
1530 if (method == RBM_SHOOT) continue;
1532 /* Extract the attack "power" */
1533 power = mbe_info[effect].power;
1536 if (!effect || check_hit2(power, rlev, ac, m_ptr->stunned))
1538 /* Describe the attack method */
1544 act = "%s¤ò²¥¤Ã¤¿¡£";
1556 act = "%s¤ò¿¨¤Ã¤¿¡£";
1558 act = "touches %s.";
1568 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1570 act = "punches %s.";
1580 act = "%s¤ò½³¤Ã¤¿¡£";
1592 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1604 act = "%s¤ò³ú¤ó¤À¡£";
1616 act = "%s¤ò»É¤·¤¿¡£";
1628 act = "%s¤ò»Â¤Ã¤¿¡£";
1630 act = "slashes %s.";
1639 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1651 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1653 act = "crushes %s.";
1663 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1665 act = "engulfs %s.";
1675 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1677 act = "charges %s.";
1687 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1689 act = "crawls on %s.";
1699 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1701 act = "drools on %s.";
1711 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1713 act = "spits on %s.";
1722 if (see_either) disturb(1, 0);
1737 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1739 act = "gazes at %s.";
1749 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1751 act = "wails at %s.";
1761 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1763 act = "releases spores at %s.";
1773 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1775 act = "projects XXX4's at %s.";
1785 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1787 act = "begs %s for money.";
1797 act = "%s¤òÉî¿«¤·¤¿¡£";
1799 act = "insults %s.";
1809 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1811 act = "moans at %s.";
1821 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1823 act = "sings to %s.";
1832 if (act && see_either)
1835 if (do_silly_attack) act = silly_attacks2[randint0(MAX_SILLY_ATTACK)];
1836 strfmt(temp, act, t_name);
1837 msg_format("%^s¤Ï%s", m_name, temp);
1839 if (do_silly_attack)
1841 act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
1842 strfmt(temp, "%s %s.", act, t_name);
1844 else strfmt(temp, act, t_name);
1845 msg_format("%^s %s", m_name, temp);
1849 /* Hack -- assume all attacks are obvious */
1852 /* Roll out the damage */
1853 damage = damroll(d_dice, d_side);
1855 /* Assume no healing effect */
1856 heal_effect = FALSE;
1860 /* Apply appropriate damage */
1872 if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13)) {
1873 int tmp_damage = damage-(damage*((ac < 150) ? ac : 150)/250);
1874 damage = MAX(damage, tmp_damage*2);
1880 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1910 if (one_in_(2)) blinked = TRUE;
1957 pt = GF_OLD_SLEEP; /* sort of close... */
1973 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1976 earthquake(m_ptr->fy, m_ptr->fx, 8);
2009 /* Do damage if not exploding */
2012 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
2013 (pt == GF_OLD_SLEEP ? r_ptr->level : damage), pt, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2018 if ((monster_living(tr_ptr)) && (damage > 2))
2020 bool did_heal = FALSE;
2022 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
2025 m_ptr->hp += damroll(4, damage / 6);
2026 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
2028 /* Redraw (later) if needed */
2029 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2030 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2032 /* Special message */
2033 if (see_m && did_heal)
2036 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
2038 msg_format("%^s appears healthier.", m_name);
2048 if ((tr_ptr->flags2 & RF2_AURA_FIRE) && m_ptr->r_idx)
2050 if (!(r_ptr->flags3 & RF3_EFF_IM_FIRE_MASK))
2056 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2058 msg_format("%^s is suddenly very hot!", m_name);
2061 if (see_t) tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2063 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2064 damroll (1 + ((tr_ptr->level) / 26),
2065 1 + ((tr_ptr->level) / 17)),
2066 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2070 if (see_m) r_ptr->r_flags3 |= (r_ptr->flags3 & RF3_EFF_IM_FIRE_MASK);
2075 if ((tr_ptr->flags3 & RF3_AURA_COLD) && m_ptr->r_idx)
2077 if (!(r_ptr->flags3 & RF3_EFF_IM_COLD_MASK))
2083 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2085 msg_format("%^s is suddenly very cold!", m_name);
2088 if (see_t) tr_ptr->r_flags3 |= RF3_AURA_COLD;
2090 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2091 damroll (1 + ((tr_ptr->level) / 26),
2092 1 + ((tr_ptr->level) / 17)),
2093 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2097 if (see_m) r_ptr->r_flags3 |= (r_ptr->flags3 & RF3_EFF_IM_COLD_MASK);
2102 if ((tr_ptr->flags2 & RF2_AURA_ELEC) && m_ptr->r_idx)
2104 if (!(r_ptr->flags3 & RF3_EFF_IM_ELEC_MASK))
2110 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2112 msg_format("%^s gets zapped!", m_name);
2115 if (see_t) tr_ptr->r_flags2 |= RF2_AURA_ELEC;
2117 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2118 damroll (1 + ((tr_ptr->level) / 26),
2119 1 + ((tr_ptr->level) / 17)),
2120 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2124 if (see_m) r_ptr->r_flags3 |= (r_ptr->flags3 & RF3_EFF_IM_ELEC_MASK);
2131 /* Monster missed player */
2134 /* Analyze failed attacks */
2150 /* Visible monsters */
2155 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2157 msg_format("%^s misses %s.", m_name, t_name);
2168 /* Analyze "visible" monsters only */
2169 if (see_m && !do_silly_attack)
2171 /* Count "obvious" attacks (and ones that cause damage) */
2172 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2174 /* Count attacks of this type */
2175 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2177 r_ptr->r_blows[ap_cnt]++;
2185 sound(SOUND_EXPLODE);
2187 /* Cancel Invulnerability */
2188 if (m_ptr->invulner) m_ptr->invulner = 0;
2191 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2193 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2207 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2209 msg_print("The thief flees laughing!");
2218 teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE);
2228 * The monster is known to be within 100 grids of the player
2230 * In several cases, we directly update the monster lore
2232 * Note that a monster is only allowed to "reproduce" if there
2233 * are a limited number of "reproducing" monsters on the current
2234 * level. This should prevent the level from being "swamped" by
2235 * reproducing monsters. It also allows a large mass of mice to
2236 * prevent a louse from multiplying, but this is a small price to
2237 * pay for a simple multiplication method.
2239 * XXX Monster fear is slightly odd, in particular, monsters will
2240 * fixate on opening a door even if they cannot open it. Actually,
2241 * the same thing happens to normal monsters when they hit a door
2243 * XXX XXX XXX In addition, monsters which *cannot* open or bash
2244 * down a door will still stand there trying to open it...
2246 * XXX Technically, need to check for monster in the way
2247 * combined with that monster being in a wall (or door?)
2249 * A "direction" of "5" means "pick a random direction".
2251 static void process_monster(int m_idx)
2253 monster_type *m_ptr = &m_list[m_idx];
2254 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2255 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2257 int i, d, oy, ox, ny, nx;
2263 monster_type *y_ptr;
2276 bool gets_angry = FALSE;
2282 if ((m_idx == p_ptr->riding) && !(r_ptr->flags7 & RF7_RIDING))
2284 if (rakuba(0, TRUE))
2287 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2290 monster_desc(m_name, &m_list[p_ptr->riding], 0);
2291 msg_format("You have fallen from %s.", m_name);
2296 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !m_ptr->csleep)
2298 choose_new_monster(m_idx, FALSE, 0);
2299 r_ptr = &r_info[m_ptr->r_idx];
2302 /* Players hidden in shadow are almost imperceptable. -LM- */
2303 if (p_ptr->special_defense & NINJA_S_STEALTH)
2305 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
2306 if (p_ptr->monlite) tmp /= 3;
2307 if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
2308 if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
2309 /* Low-level monsters will find it difficult to locate the player. */
2310 if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
2313 /* Quantum monsters are odd */
2314 if (r_ptr->flags2 & (RF2_QUANTUM))
2316 /* Sometimes skip move */
2317 if (!randint0(2)) return;
2320 if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2324 if (is_pet(m_ptr) && !(m_ptr->ml))
2331 /* Acquire the monster name */
2332 monster_desc(m_name, m_ptr, 0);
2336 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2338 msg_format("%^s disappears!", m_name);
2343 /* Generate treasure, etc */
2344 monster_death(m_idx, FALSE);
2346 /* Delete the monster */
2347 delete_monster_idx(m_idx);
2352 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2354 msg_print("You feel sad for a moment.");
2363 if (m_ptr->r_idx == MON_SHURYUUDAN)
2365 mon_take_hit_mon(m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2367 mon_take_hit_mon(m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2370 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) && !p_ptr->inside_battle)
2372 static int riding_pinch = 0;
2374 if (m_ptr->hp < m_ptr->maxhp/3)
2377 monster_desc(m_name, m_ptr, 0);
2379 if (m_idx == p_ptr->riding && riding_pinch < 2)
2382 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2384 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
2391 if (m_idx == p_ptr->riding)
2394 msg_format("%s¤Ï¤¢¤Ê¤¿¤Î«Çû¤«¤éæ½Ð¤·¤¿¡£", m_name);
2396 msg_format("%^s succeeded to escape from your restriction!", m_name);
2398 if (rakuba(-1, FALSE))
2401 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2403 msg_print("You have fallen from riding pet.");
2410 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))
2413 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2415 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2419 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2420 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2422 msg_format("%^s read a scroll of teleport level.", m_name);
2423 msg_format("%^s disappears.", m_name);
2427 if (m_idx == p_ptr->riding && rakuba(-1, FALSE))
2430 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2432 msg_print("You have fallen from riding pet.");
2436 /* Check for quest completion */
2437 check_quest_completion(m_ptr);
2439 delete_monster_idx(m_idx);
2446 /* Reset the counter */
2447 if (m_idx == p_ptr->riding) riding_pinch = 0;
2451 /* Handle "sleep" - Still sleeping */
2452 if (m_ptr->csleep) return;
2457 /* Sometimes skip move */
2458 if (one_in_(2)) return;
2461 if (p_ptr->riding == m_idx)
2463 p_ptr->update |= (PU_BONUS);
2466 /* No one wants to be your friend if you're aggravating */
2467 if (is_friendly(m_ptr) && (p_ptr->cursed & TRC_AGGRAVATE))
2470 /* Paranoia... no pet uniques outside wizard mode -- TY */
2471 if (is_pet(m_ptr) &&
2472 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
2473 ((p_ptr->align > 9 && (r_ptr->flags3 & RF3_EVIL)) ||
2474 (p_ptr->align < -9 && (r_ptr->flags3 & RF3_GOOD))))
2475 || (r_ptr->flags3 & RF3_RES_ALL)))
2480 if (p_ptr->inside_battle) gets_angry = FALSE;
2485 monster_desc(m_name, m_ptr, 0);
2487 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2489 msg_format("%^s suddenly becomes hostile!", m_name);
2495 /* Get the origin */
2500 /* Attempt to "multiply" if able and allowed */
2501 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2505 /* Count the adjacent monsters */
2506 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2508 for (x = ox - 1; x <= ox + 1; x++)
2510 /* Ignore locations off of edge */
2511 if (!in_bounds2(y, x)) continue;
2513 if (cave[y][x].m_idx) k++;
2517 /* Hack -- multiply slower in crowded areas */
2518 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2520 /* Try to multiply */
2521 if (multiply_monster(m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
2523 /* Take note if visible */
2526 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2529 /* Multiplying takes energy */
2536 if (r_ptr->flags6 & RF6_SPECIAL)
2538 /* Hack -- Ohmu scatters molds! */
2539 if (m_ptr->r_idx == MON_OHMU)
2541 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
2543 if (r_ptr->freq_spell && (randint1(100) <= r_ptr->freq_spell))
2546 int rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
2547 u32b p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
2549 for (k = 0; k < 6; k++)
2551 if (summon_specific(m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_BIZARRE1, (PM_ALLOW_GROUP | p_mode)))
2553 if (m_list[hack_m_idx_ii].ml) count++;
2557 if (count && m_ptr->ml) r_ptr->r_flags6 |= (RF6_SPECIAL);
2564 if (!p_ptr->inside_battle)
2566 /* Hack! "Cyber" monster makes noise... */
2567 if (m_ptr->ap_r_idx == MON_CYBER &&
2568 one_in_(CYBERNOISE) &&
2569 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2571 if (disturb_minor) disturb(FALSE, FALSE);
2573 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2575 msg_print("You hear heavy steps.");
2580 /* Some monsters can speak */
2581 if ((ap_r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2582 one_in_(SPEAK_CHANCE) &&
2583 player_has_los_bold(oy, ox))
2586 char monmessage[1024];
2589 /* Acquire the monster name/poss */
2591 monster_desc(m_name, m_ptr, 0);
2594 strcpy(m_name, "¤½¤ì");
2596 strcpy(m_name, "It");
2600 /* Select the file for monster quotes */
2603 filename = "monfear_j.txt";
2605 filename = "monfear.txt";
2608 else if (is_pet(m_ptr))
2610 filename = "monpet_j.txt";
2612 filename = "monpet.txt";
2615 else if (is_friendly(m_ptr))
2617 filename = "monfrien_j.txt";
2619 filename = "monfrien.txt";
2624 filename = "monspeak_j.txt";
2626 filename = "monspeak.txt";
2630 /* Get the monster line */
2631 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
2635 msg_format("%^s%s", m_name, monmessage);
2637 msg_format("%^s %s", m_name, monmessage);
2644 /* Try to cast spell occasionally */
2645 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
2647 bool counterattack = FALSE;
2649 /* Give priority to counter attack? */
2650 if (m_ptr->target_y)
2652 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
2654 /* The monster must be an enemy, and projectable */
2656 are_enemies(m_ptr, &m_list[t_m_idx]) &&
2657 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
2659 counterattack = TRUE;
2665 /* Attempt to cast a spell */
2666 if (aware && make_attack_spell(m_idx)) return;
2669 * Attempt to cast a spell at an enemy other than the player
2670 * (may slow the game a smidgeon, but I haven't noticed.)
2672 if (monst_spell_monst(m_idx)) return;
2676 /* Attempt to do counter attack at first */
2677 if (monst_spell_monst(m_idx)) return;
2679 if (aware && make_attack_spell(m_idx)) return;
2683 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
2685 /* Hack -- Assume no movement */
2686 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2687 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2690 /* Confused -- 100% random */
2691 if (m_ptr->confused || !aware)
2693 /* Try four "random" directions */
2694 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2697 /* 75% random movement */
2698 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2699 (r_ptr->flags1 & RF1_RAND_25) &&
2700 (randint0(100) < 75))
2702 /* Memorize flags */
2703 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2704 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25);
2706 /* Try four "random" directions */
2707 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2710 /* 50% random movement */
2711 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2712 (randint0(100) < 50))
2714 /* Memorize flags */
2715 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2717 /* Try four "random" directions */
2718 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2721 /* 25% random movement */
2722 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2723 (randint0(100) < 25))
2725 /* Memorize flags */
2726 if (m_ptr->ml) r_ptr->r_flags1 |= RF1_RAND_25;
2728 /* Try four "random" directions */
2729 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2732 /* Can't reach player - find something else to hit */
2733 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2735 /* Try four "random" directions */
2736 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2738 /* Look for an enemy */
2739 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2740 get_enemy_dir(m_idx, mm);
2744 /* Pets will follow the player */
2745 else if (is_pet(m_ptr))
2747 /* Are we trying to avoid the player? */
2748 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
2749 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2751 /* Do we want to find the player? */
2752 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2754 /* Should we find the player if we can't find a monster? */
2755 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2757 /* by default, move randomly */
2758 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2760 /* Look for an enemy */
2761 if (!get_enemy_dir(m_idx, mm))
2763 /* Find the player if necessary */
2764 if (avoid || lonely || distant)
2766 /* Remember the leash length */
2767 int dis = p_ptr->pet_follow_distance;
2769 /* Hack -- adjust follow distance temporarily */
2770 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2772 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2775 /* Find the player */
2776 get_moves(m_idx, mm);
2778 /* Restore the leash */
2779 p_ptr->pet_follow_distance = dis;
2784 /* Friendly monster movement */
2785 else if (!is_hostile(m_ptr))
2787 /* by default, move randomly */
2788 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2790 /* Look for an enemy */
2791 get_enemy_dir(m_idx, mm);
2793 /* Normal movement */
2796 /* Logical moves, may do nothing */
2797 if (!get_moves(m_idx, mm)) return;
2800 /* Assume nothing */
2805 /* Assume nothing */
2806 did_open_door = FALSE;
2807 did_bash_door = FALSE;
2808 did_take_item = FALSE;
2809 did_kill_item = FALSE;
2810 did_move_body = FALSE;
2811 did_pass_wall = FALSE;
2812 did_kill_wall = FALSE;
2815 /* Take a zero-terminated array of "directions" */
2816 for (i = 0; mm[i]; i++)
2818 /* Get the direction */
2821 /* Hack -- allow "randomized" motion */
2822 if (d == 5) d = ddd[randint0(8)];
2824 /* Get the destination */
2828 /* Ignore locations off of edge */
2829 if (!in_bounds2(ny, nx)) continue;
2831 /* Access that cave grid */
2832 c_ptr = &cave[ny][nx];
2834 /* Access that cave grid's contents */
2835 y_ptr = &m_list[c_ptr->m_idx];
2837 /* Floor is open? */
2838 if (cave_floor_grid(c_ptr))
2840 /* Go ahead and move */
2844 /* Hack -- player 'in' wall */
2845 else if (player_bold(ny, nx))
2850 else if (c_ptr->m_idx)
2852 /* Possibly a monster to attack */
2856 /* Permanent wall */
2857 else if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
2858 (c_ptr->feat <= FEAT_PERM_SOLID))
2863 /* Hack -- semi-transparent terrains are no obstacle */
2864 else if (c_ptr->feat == FEAT_TREES)
2869 /* Hack -- semi-transparent terrains are no obstacle */
2870 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)))))
2876 /* Monster moves through walls (and doors) */
2877 else if (can_pass_wall)
2879 /* Pass through walls/doors/rubble */
2882 /* Monster went through a wall */
2883 did_pass_wall = TRUE;
2886 /* Monster destroys walls (and doors) */
2887 else if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))
2889 /* Eat through walls/doors/rubble */
2892 /* Monster destroyed a wall */
2893 did_kill_wall = TRUE;
2895 if (one_in_(GRINDNOISE))
2898 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
2900 msg_print("There is a grinding sound.");
2905 /* Forget the wall */
2906 c_ptr->info &= ~(CAVE_MARK);
2909 cave_set_feat(ny, nx, floor_type[randint0(100)]);
2911 /* Note changes to viewable region */
2912 if (player_has_los_bold(ny, nx)) do_view = TRUE;
2915 /* Handle doors and secret doors */
2916 else if (is_closed_door(c_ptr->feat))
2918 bool may_bash = TRUE;
2920 /* Assume no move allowed */
2923 /* Creature can open doors. */
2924 if ((r_ptr->flags2 & RF2_OPEN_DOOR) &&
2925 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2928 if (c_ptr->feat == FEAT_DOOR_HEAD)
2930 /* The door is open */
2931 did_open_door = TRUE;
2933 /* Do not bash the door */
2936 /* Assume no move allowed */
2940 /* Locked doors (not jammed) */
2941 else if (c_ptr->feat < FEAT_DOOR_HEAD + 0x08)
2946 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
2948 /* Try to unlock it XXX XXX XXX */
2949 if (randint0(m_ptr->hp / 10) > k)
2951 /* Unlock the door */
2952 cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00);
2954 /* Do not bash the door */
2960 /* Stuck doors -- attempt to bash them down if allowed */
2961 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) &&
2962 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2967 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
2969 /* Attempt to Bash XXX XXX XXX */
2970 if (randint0(m_ptr->hp / 10) > k)
2974 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
2976 msg_print("You hear a door burst open!");
2980 /* Disturb (sometimes) */
2981 if (disturb_minor) disturb(0, 0);
2983 /* The door was bashed open */
2984 did_bash_door = TRUE;
2986 /* Hack -- fall into doorway */
2992 /* Deal with doors in the way */
2993 if (did_open_door || did_bash_door)
2995 /* Break down the door */
2996 if (did_bash_door && (randint0(100) < 50))
2998 cave_set_feat(ny, nx, FEAT_BROKEN);
3004 cave_set_feat(ny, nx, FEAT_OPEN);
3007 /* Handle viewable doors */
3008 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3012 /* Hack -- check for Glyph of Warding */
3013 if (do_move && is_glyph_grid(c_ptr) &&
3014 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3016 /* Assume no move allowed */
3019 /* Break the ward */
3020 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
3022 /* Describe observable breakage */
3023 if (c_ptr->info & CAVE_MARK)
3026 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3028 msg_print("The rune of protection is broken!");
3033 /* Forget the rune */
3034 c_ptr->info &= ~(CAVE_MARK);
3036 /* Break the rune */
3037 c_ptr->info &= ~(CAVE_OBJECT);
3040 /* Allow movement */
3047 else if (do_move && is_explosive_rune_grid(c_ptr) &&
3048 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3050 /* Assume no move allowed */
3053 /* Break the ward */
3056 /* Break the ward */
3057 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3059 /* Describe observable breakage */
3060 if (c_ptr->info & CAVE_MARK)
3063 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3065 msg_print("The rune explodes!");
3068 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);
3074 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3076 msg_print("An explosive rune was disarmed.");
3080 /* Forget the rune */
3081 c_ptr->info &= ~(CAVE_MARK);
3083 /* Break the rune */
3084 c_ptr->info &= ~(CAVE_OBJECT);
3090 if (!m_ptr->r_idx) return;
3091 /* Allow movement */
3095 if (do_move && player_bold(ny, nx) && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3100 /* Some monsters never attack */
3101 if (do_move && player_bold(ny, nx) && (r_ptr->flags1 & RF1_NEVER_BLOW))
3103 /* Hack -- memorize lack of attacks */
3104 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3110 /* The player is in the way. Attack him. */
3111 if (do_move && player_bold(ny, nx))
3113 if (!p_ptr->riding || one_in_(2))
3116 (void)make_attack_normal(m_idx);
3126 if ((c_ptr->feat >= FEAT_PATTERN_START) &&
3127 (c_ptr->feat <= FEAT_PATTERN_XTRA2) &&
3128 !do_turn && !(r_ptr->flags7 & RF7_CAN_FLY))
3134 /* A monster is in the way */
3135 if (do_move && c_ptr->m_idx)
3137 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3138 monster_type *m2_ptr = &m_list[c_ptr->m_idx];
3140 /* Assume no movement */
3143 /* Attack 'enemies' */
3144 if (((r_ptr->flags2 & (RF2_KILL_BODY)) &&
3145 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3146 (cave_floor_grid(c_ptr)) &&
3147 (c_ptr->m_idx != p_ptr->riding)) ||
3148 are_enemies(m_ptr, m2_ptr) || m_ptr->confused)
3152 if (r_ptr->flags2 & RF2_KILL_BODY) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3155 if ((m2_ptr->r_idx) && (m2_ptr->hp >= 0))
3157 if (monst_attack_monst(m_idx, cave[ny][nx].m_idx))
3162 /* Push past weaker monsters (unless leaving a wall) */
3163 else if ((r_ptr->flags2 & RF2_MOVE_BODY) &&
3164 (r_ptr->mexp > z_ptr->mexp) && cave_floor_grid(c_ptr) &&
3165 (cave_floor_grid(&cave[m_ptr->fy][m_ptr->fx])) &&
3166 (c_ptr->m_idx != p_ptr->riding))
3168 /* Allow movement */
3171 /* Monster pushed past another monster */
3172 did_move_body = TRUE;
3174 /* XXX XXX XXX Message */
3179 * Check if monster can cross terrain
3180 * This is checked after the normal attacks
3181 * to allow monsters to attack an enemy,
3182 * even if it can't enter the terrain.
3184 if (do_move && !monster_can_cross_terrain(c_ptr->feat, r_ptr))
3186 /* Assume no move allowed */
3190 /* Some monsters never move */
3191 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3193 /* Hack -- memorize lack of attacks */
3194 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3200 if (m_idx == p_ptr->riding)
3202 if (!p_ptr->riding_ryoute && !(m_list[p_ptr->riding].monfear)) do_move = FALSE;
3205 /* Creature has been allowed move */
3208 s16b this_o_idx, next_o_idx;
3213 /* Hack -- Update the old location */
3214 cave[oy][ox].m_idx = c_ptr->m_idx;
3216 if (cave[ny][nx].feat == FEAT_TREES)
3218 if (r_ptr->flags2 & RF2_KILL_WALL)
3220 cave_set_feat(ny, nx, FEAT_GRASS);
3223 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3225 m_ptr->energy_need += ENERGY_NEED();
3229 /* Mega-Hack -- move the old monster, if any */
3232 /* Move the old monster */
3236 /* Update the old monster */
3237 update_mon(c_ptr->m_idx, TRUE);
3239 /* Wake up the moved monster */
3240 m_list[c_ptr->m_idx].csleep = 0;
3243 /* Hack -- Update the new location */
3244 c_ptr->m_idx = m_idx;
3246 /* Move the monster */
3250 /* Update the monster */
3251 update_mon(m_idx, TRUE);
3253 if (p_ptr->riding == m_idx)
3259 /* Redraw the old grid */
3262 /* Redraw the new grid */
3265 if (p_ptr->riding == m_idx)
3270 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
3272 /* Update the monsters */
3273 p_ptr->update |= (PU_DISTANCE);
3275 /* Update sub-windows */
3276 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3279 /* Possible disturb */
3282 (disturb_near && (m_ptr->mflag & MFLAG_VIEW)) ||
3283 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)))
3286 if (is_hostile(m_ptr))
3290 /* Scan all objects in the grid */
3291 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3295 /* Acquire object */
3296 o_ptr = &o_list[this_o_idx];
3298 /* Acquire next object */
3299 next_o_idx = o_ptr->next_o_idx;
3302 if (o_ptr->tval == TV_GOLD) continue;
3305 * Skip "real" corpses and statues, to avoid extreme
3306 * silliness like a novice rogue pockets full of statues
3309 if ((o_ptr->tval == TV_CORPSE) ||
3310 (o_ptr->tval == TV_STATUE)) continue;
3312 /* Take or Kill objects on the floor */
3313 if ((r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3314 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)))
3316 u32b flgs[TR_FLAG_SIZE];
3322 char o_name[MAX_NLEN];
3324 /* Extract some flags */
3325 object_flags(o_ptr, flgs);
3327 /* Acquire the object name */
3328 object_desc(o_name, o_ptr, TRUE, 3);
3330 /* Acquire the monster name */
3331 monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
3333 /* React to objects that hurt the monster */
3334 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
3335 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
3336 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
3337 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
3338 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
3339 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
3340 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
3341 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
3342 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
3343 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
3344 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
3345 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
3346 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
3347 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
3348 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
3349 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
3350 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
3351 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
3353 /* The object cannot be picked up by the monster */
3354 if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
3357 /* Only give a message for "take_item" */
3358 if ((r_ptr->flags2 & (RF2_TAKE_ITEM)) && (r_ptr->flags2 & (RF2_STUPID)))
3361 did_take_item = TRUE;
3363 /* Describe observable situations */
3364 if (m_ptr->ml && player_can_see_bold(ny, nx))
3366 /* Dump a message */
3368 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£", m_name, o_name);
3370 msg_format("%^s tries to pick up %s, but fails.", m_name, o_name);
3376 /* Pick up the item */
3377 else if (r_ptr->flags2 & RF2_TAKE_ITEM)
3380 did_take_item = TRUE;
3382 /* Describe observable situations */
3383 if (player_can_see_bold(ny, nx))
3385 /* Dump a message */
3387 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3389 msg_format("%^s picks up %s.", m_name, o_name);
3394 /* Excise the object */
3395 excise_object_idx(this_o_idx);
3400 /* Forget location */
3401 o_ptr->iy = o_ptr->ix = 0;
3403 /* Memorize monster */
3404 o_ptr->held_m_idx = m_idx;
3407 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3410 m_ptr->hold_o_idx = this_o_idx;
3413 /* Destroy the item if not a pet */
3414 else if (!is_pet(m_ptr))
3417 did_kill_item = TRUE;
3419 /* Describe observable situations */
3420 if (player_has_los_bold(ny, nx))
3422 /* Dump a message */
3424 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3426 msg_format("%^s destroys %s.", m_name, o_name);
3431 /* Delete the object */
3432 delete_object_idx(this_o_idx);
3438 /* Stop when done */
3443 * Forward movements failed, but now received LOS attack!
3444 * Try to flow by smell.
3446 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3447 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3449 /* If we haven't done anything, try casting a spell again */
3450 if (!do_turn && !do_move && !m_ptr->monfear && !(p_ptr->riding == m_idx) && aware)
3452 /* Try to cast spell again */
3453 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
3455 if (make_attack_spell(m_idx)) return;
3460 /* Notice changes in view */
3463 /* Update some things */
3464 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
3467 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3470 /* Notice changes in view */
3471 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
3472 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !p_ptr->inside_battle)))
3474 /* Update some things */
3475 p_ptr->update |= (PU_MON_LITE);
3478 /* Learn things from observable monster */
3481 /* Monster opened a door */
3482 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3484 /* Monster bashed a door */
3485 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3487 /* Monster tried to pick something up */
3488 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3490 /* Monster tried to crush something */
3491 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3493 /* Monster pushed past another monster */
3494 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3496 /* Monster passed through a wall */
3497 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3499 /* Monster destroyed a wall */
3500 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3504 /* Hack -- get "bold" if out of options */
3505 if (!do_turn && !do_move && m_ptr->monfear && aware)
3507 /* No longer afraid */
3510 /* Message if seen */
3515 /* Acquire the monster name */
3516 monster_desc(m_name, m_ptr, 0);
3518 /* Dump a message */
3520 msg_format("%^s¤ÏÀ襤¤ò·è°Õ¤·¤¿¡ª", m_name);
3522 msg_format("%^s turns to fight!", m_name);
3525 /* Redraw (later) if needed */
3526 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
3528 chg_virtue(V_COMPASSION, -1);
3531 /* XXX XXX XXX Actually do something now (?) */
3536 * Process all the "live" monsters, once per game turn.
3538 * During each game turn, we scan through the list of all the "live" monsters,
3539 * (backwards, so we can excise any "freshly dead" monsters), energizing each
3540 * monster, and allowing fully energized monsters to move, attack, pass, etc.
3542 * Note that monsters can never move in the monster array (except when the
3543 * "compact_monsters()" function is called by "dungeon()" or "save_player()").
3545 * This function is responsible for at least half of the processor time
3546 * on a normal system with a "normal" amount of monsters and a player doing
3549 * When the player is resting, virtually 90% of the processor time is spent
3550 * in this function, and its children, "process_monster()" and "make_move()".
3552 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",
3553 * especially when the player is running.
3555 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"
3556 * monsters while they are still being "born". A monster is "fresh" only
3557 * during the turn in which it is created, and we use the "hack_m_idx" to
3558 * determine if the monster is yet to be processed during the current turn.
3560 * Note the special "MFLAG_NICE" flag, which allows the player to get one
3561 * move before any "nasty" monsters get to use their spell attacks.
3563 * Note that when the "knowledge" about the currently tracked monster
3564 * changes (flags, attacks, spells), we induce a redraw of the monster
3567 void process_monsters(void)
3574 monster_type *m_ptr;
3575 monster_race *r_ptr;
3577 int old_monster_race_idx;
3579 u32b old_r_flags1 = 0L;
3580 u32b old_r_flags2 = 0L;
3581 u32b old_r_flags3 = 0L;
3582 u32b old_r_flags4 = 0L;
3583 u32b old_r_flags5 = 0L;
3584 u32b old_r_flags6 = 0L;
3586 byte old_r_blows0 = 0;
3587 byte old_r_blows1 = 0;
3588 byte old_r_blows2 = 0;
3589 byte old_r_blows3 = 0;
3591 byte old_r_cast_spell = 0;
3595 /* Clear monster fighting indicator */
3598 /* Memorize old race */
3599 old_monster_race_idx = p_ptr->monster_race_idx;
3601 /* Acquire knowledge */
3602 if (p_ptr->monster_race_idx)
3604 /* Acquire current monster */
3605 r_ptr = &r_info[p_ptr->monster_race_idx];
3607 /* Memorize flags */
3608 old_r_flags1 = r_ptr->r_flags1;
3609 old_r_flags2 = r_ptr->r_flags2;
3610 old_r_flags3 = r_ptr->r_flags3;
3611 old_r_flags4 = r_ptr->r_flags4;
3612 old_r_flags5 = r_ptr->r_flags5;
3613 old_r_flags6 = r_ptr->r_flags6;
3615 /* Memorize blows */
3616 old_r_blows0 = r_ptr->r_blows[0];
3617 old_r_blows1 = r_ptr->r_blows[1];
3618 old_r_blows2 = r_ptr->r_blows[2];
3619 old_r_blows3 = r_ptr->r_blows[3];
3621 /* Memorize castings */
3622 old_r_cast_spell = r_ptr->r_cast_spell;
3626 /* Process the monsters (backwards) */
3627 for (i = m_max - 1; i >= 1; i--)
3629 /* Access the monster */
3631 r_ptr = &r_info[m_ptr->r_idx];
3633 /* Handle "leaving" */
3634 if (p_ptr->leaving) break;
3636 /* Ignore "dead" monsters */
3637 if (!m_ptr->r_idx) continue;
3639 if (p_ptr->wild_mode) continue;
3642 /* Handle "fresh" monsters */
3643 if (m_ptr->mflag & MFLAG_BORN)
3645 /* No longer "fresh" */
3646 m_ptr->mflag &= ~(MFLAG_BORN);
3652 /* Hack -- Require proximity */
3653 if (m_ptr->cdis >= AAF_LIMIT) continue;
3656 /* Access the location */
3660 /* Flow by smell is allowed */
3661 if (!p_ptr->no_flowed)
3663 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3666 /* Assume no move */
3669 /* Handle "sensing radius" */
3670 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
3672 /* We can "sense" the player */
3676 /* Handle "sight" and "aggravation" */
3677 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3678 (player_has_los_bold(fy, fx) || (p_ptr->cursed & TRC_AGGRAVATE)))
3680 /* We can "see" or "feel" the player */
3684 #if 0 /* (cave[py][px].when == cave[fy][fx].when) is always FALSE... */
3685 /* Hack -- Monsters can "smell" the player from far away */
3686 /* Note that most monsters have "aaf" of "20" or so */
3687 else if (!(m_ptr->mflag2 & MFLAG2_NOFLOW) &&
3688 (cave_floor_bold(py, px) || (cave[py][px].feat == FEAT_TREES)) &&
3689 (cave[py][px].when == cave[fy][fx].when) &&
3690 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3691 (cave[fy][fx].dist < r_ptr->aaf))
3693 /* We can "smell" the player */
3697 else if (m_ptr->target_y) test = TRUE;
3700 if (!test) continue;
3703 if (p_ptr->riding == i)
3704 speed = p_ptr->pspeed;
3707 speed = m_ptr->mspeed;
3709 /* Monsters move quickly in Nightmare mode */
3710 if (ironman_nightmare) speed += 5;
3712 if (m_ptr->fast) speed += 10;
3713 if (m_ptr->slow) speed -= 10;
3716 /* Give this monster some energy */
3717 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
3719 /* Not enough energy to move */
3720 if (m_ptr->energy_need > 0) continue;
3722 /* Use up "some" energy */
3723 m_ptr->energy_need += ENERGY_NEED();
3726 /* Save global index */
3729 /* Process the monster */
3732 reset_target(m_ptr);
3734 /* Give up flow_by_smell when it might useless */
3735 if (p_ptr->no_flowed && one_in_(3))
3736 m_ptr->mflag2 |= MFLAG2_NOFLOW;
3738 /* Hack -- notice death or departure */
3739 if (!p_ptr->playing || p_ptr->is_dead) break;
3741 /* Notice leaving */
3742 if (p_ptr->leaving) break;
3745 /* Reset global index */
3749 /* Tracking a monster race (the same one we were before) */
3750 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3752 /* Acquire monster race */
3753 r_ptr = &r_info[p_ptr->monster_race_idx];
3755 /* Check for knowledge change */
3756 if ((old_r_flags1 != r_ptr->r_flags1) ||
3757 (old_r_flags2 != r_ptr->r_flags2) ||
3758 (old_r_flags3 != r_ptr->r_flags3) ||
3759 (old_r_flags4 != r_ptr->r_flags4) ||
3760 (old_r_flags5 != r_ptr->r_flags5) ||
3761 (old_r_flags6 != r_ptr->r_flags6) ||
3762 (old_r_blows0 != r_ptr->r_blows[0]) ||
3763 (old_r_blows1 != r_ptr->r_blows[1]) ||
3764 (old_r_blows2 != r_ptr->r_blows[2]) ||
3765 (old_r_blows3 != r_ptr->r_blows[3]) ||
3766 (old_r_cast_spell != r_ptr->r_cast_spell))
3769 p_ptr->window |= (PW_MONSTER);
3776 bool process_the_world(int num, int who, bool vs_player)
3778 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
3780 if(world_monster) return (FALSE);
3785 monster_desc(m_name, m_ptr, 0);
3789 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
3791 msg_format("%s yells 'The World! Time has stopped!'", m_name);
3795 msg_print("¡Ö»þ¤è¡ª¡×");
3797 msg_format("%s yells 'Time!'", m_name);
3799 else msg_print("hek!");
3804 world_monster = TRUE;
3806 if (vs_player) do_cmd_redraw();
3810 if(!m_ptr->r_idx) break;
3811 process_monster(hack_m_idx);
3813 reset_target(m_ptr);
3816 if (p_ptr->notice) notice_stuff();
3819 if (p_ptr->update) update_stuff();
3822 if (p_ptr->redraw) redraw_stuff();
3825 if (p_ptr->window) window_stuff();
3828 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
3832 p_ptr->redraw |= (PR_MAP);
3834 /* Update monsters */
3835 p_ptr->update |= (PU_MONSTERS);
3838 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3840 world_monster = FALSE;
3841 if (vs_player || los(py, px, m_ptr->fy, m_ptr->fx))
3844 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
3846 msg_print("You feel time flowing around you once more.");
3857 void monster_gain_exp(int m_idx, int s_idx)
3859 monster_type *m_ptr = &m_list[m_idx];
3860 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3861 monster_race *s_ptr = &r_info[s_idx];
3864 if (p_ptr->inside_battle) return;
3866 if (!r_ptr->next_exp) return;
3868 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
3869 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
3870 if (!dun_level) new_exp /= 5;
3871 m_ptr->exp += new_exp;
3872 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
3874 if (m_ptr->exp >= r_ptr->next_exp)
3877 int old_hp = m_ptr->hp;
3878 int old_maxhp = m_ptr->max_maxhp;
3879 int old_r_idx = m_ptr->r_idx;
3880 byte old_sub_align = m_ptr->sub_align;
3882 monster_desc(m_name, m_ptr, 0);
3883 m_ptr->r_idx = r_ptr->next_r_idx;
3884 m_ptr->ap_r_idx = m_ptr->r_idx;
3885 r_ptr = &r_info[m_ptr->r_idx];
3886 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3888 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3892 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3894 if (ironman_nightmare)
3896 u32b hp = m_ptr->max_maxhp * 2L;
3898 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3900 m_ptr->maxhp = m_ptr->max_maxhp;
3901 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
3903 /* Extract the monster base speed */
3904 m_ptr->mspeed = get_mspeed(r_ptr);
3906 /* Sub-alignment of a monster */
3907 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3908 m_ptr->sub_align = old_sub_align;
3911 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3912 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3913 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3918 if (is_pet(m_ptr) || m_ptr->ml)
3921 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
3923 msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
3925 r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
3927 update_mon(m_idx, FALSE);
3928 lite_spot(m_ptr->fy, m_ptr->fx);
3930 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;