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
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 && (m_ptr->fx == px) && (m_ptr->fy == py))
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(bool is_psy_spear, 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, 0x100);
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]) && (m_ptr->target_y != py) && (m_ptr->target_x != px))
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 ((y == py) && (x == px)) 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_sound = FALSE;
608 bool use_scent = FALSE;
610 monster_type *m_ptr = &m_list[m_idx];
611 monster_race *r_ptr = &r_info[m_ptr->r_idx];
613 /* Monster flowing disabled */
614 if (stupid_monsters) return (FALSE);
616 /* Can monster cast attack spell? */
617 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
618 r_ptr->flags5 & (RF5_ATTACK_MASK) ||
619 r_ptr->flags6 & (RF6_ATTACK_MASK))
621 /* Can move spell castable grid? */
622 if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
625 /* Monster can't flow */
626 if (no_flow) return (FALSE);
628 /* Monster can go through rocks */
629 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) return (FALSE);
630 if (r_ptr->flags2 & RF2_KILL_WALL) return (FALSE);
631 if (!cave_floor_bold(py, px) && (cave[py][px].feat != FEAT_TREES)) return (FALSE);
633 /* Monster location */
637 /* Hack -- Player can see us, run towards him */
638 if (player_has_los_bold(y1, x1)) return (FALSE);
641 c_ptr = &cave[y1][x1];
643 /* If we can hear noises, advance towards them */
650 /* Otherwise, try to follow a scent trail */
651 else if (c_ptr->when)
654 if (cave[py][px].when - c_ptr->when > 127) return (FALSE);
660 /* Otherwise, advance blindly */
666 /* Check nearby grids, diagonals first */
667 for (i = 7; i >= 0; i--)
669 /* Get the location */
673 /* Ignore locations off of edge */
674 if (!in_bounds2(y, x)) continue;
678 /* We're following a scent trail */
681 int when = c_ptr->when;
683 /* Accept younger scent */
684 if (best > when) continue;
688 /* We're using sound */
693 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
695 else cost = c_ptr->cost;
697 /* Accept louder sounds */
698 if ((cost == 0) || (best < cost)) continue;
702 /* Hack -- Save the "twiddled" location */
703 (*yp) = py + 16 * ddy_ddd[i];
704 (*xp) = px + 16 * ddx_ddd[i];
707 /* No legal move (?) */
708 if (best == 999 || best == 0) return (FALSE);
716 * Provide a location to flee to, but give the player a wide berth.
718 * A monster may wish to flee to a location that is behind the player,
719 * but instead of heading directly for it, the monster should "swerve"
720 * around the player so that he has a smaller chance of getting hit.
722 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
724 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
728 monster_type *m_ptr = &m_list[m_idx];
730 /* Monster flowing disabled */
731 if (stupid_monsters) return (FALSE);
733 /* Monster location */
737 /* Desired destination */
741 /* Check nearby grids, diagonals first */
742 for (i = 7; i >= 0; i--)
746 /* Get the location */
750 /* Ignore locations off of edge */
751 if (!in_bounds2(y, x)) continue;
753 /* Don't move toward player */
754 /* if (cave[y][x].dist < 3) continue; */ /* Hmm.. Need it? */
756 /* Calculate distance of this grid from our destination */
757 dis = distance(y, x, y1, x1);
759 /* Score this grid */
760 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
762 /* No negative scores */
765 /* Ignore lower scores */
766 if (s < score) continue;
768 /* Save the score and time */
771 /* Save the location */
776 /* No legal move (?) */
777 if (score == -1) return (FALSE);
788 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
791 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
792 * offsets of all the locations with a distance of n from a central point,
793 * with an offset of (0,0) indicating no more offsets at this distance.
795 * This is, of course, fairly unreadable, but it eliminates multiple loops
796 * from the previous version.
798 * It is probably better to replace these arrays with code to compute
799 * the relevant arrays, even if the storage is pre-allocated in hard
800 * coded sizes. At the very least, code should be included which is
801 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
803 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
805 * These arrays could be combined into two big arrays, using sub-arrays
806 * to hold the offsets and lengths of each portion of the sub-arrays, and
807 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
811 static sint d_off_y_0[] =
814 static sint d_off_x_0[] =
818 static sint d_off_y_1[] =
819 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
821 static sint d_off_x_1[] =
822 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
825 static sint d_off_y_2[] =
826 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
828 static sint d_off_x_2[] =
829 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
832 static sint d_off_y_3[] =
833 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
836 static sint d_off_x_3[] =
837 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
841 static sint d_off_y_4[] =
842 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
843 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
845 static sint d_off_x_4[] =
846 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
847 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
850 static sint d_off_y_5[] =
851 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
852 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
855 static sint d_off_x_5[] =
856 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
857 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
861 static sint d_off_y_6[] =
862 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
863 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
866 static sint d_off_x_6[] =
867 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
868 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
869 -3, 2, 3, -1, 0, 1, 0 };
872 static sint d_off_y_7[] =
873 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
874 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
875 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
877 static sint d_off_x_7[] =
878 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
879 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
880 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
884 static sint d_off_y_8[] =
885 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
886 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
887 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
890 static sint d_off_x_8[] =
891 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
892 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
893 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
897 static sint d_off_y_9[] =
898 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
899 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
900 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
901 7, 8, 8, 8, 8, 9, 9, 9, 0 };
903 static sint d_off_x_9[] =
904 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
905 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
906 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
907 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
910 static sint *dist_offsets_y[10] =
912 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
913 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
916 static sint *dist_offsets_x[10] =
918 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
919 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
923 * Choose a "safe" location near a monster for it to run toward.
925 * A location is "safe" if it can be reached quickly and the player
926 * is not able to fire into it (it isn't a "clean shot"). So, this will
927 * cause monsters to "duck" behind walls. Hopefully, monsters will also
928 * try to run towards corridor openings if they are in a room.
930 * This function may take lots of CPU time if lots of monsters are
933 * Return TRUE if a safe location is available.
935 static bool find_safety(int m_idx, int *yp, int *xp)
937 monster_type *m_ptr = &m_list[m_idx];
942 int y, x, dy, dx, d, dis, i;
943 int gy = 0, gx = 0, gdis = 0;
950 /* Start with adjacent locations, spread further */
951 for (d = 1; d < 10; d++)
953 /* Get the lists of points with a distance d from (fx, fy) */
954 y_offsets = dist_offsets_y[d];
955 x_offsets = dist_offsets_x[d];
957 /* Check the locations */
958 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
960 i++, dx = x_offsets[i], dy = y_offsets[i])
965 /* Skip illegal locations */
966 if (!in_bounds(y, x)) continue;
970 /* Skip locations in a wall */
971 if (!cave_floor_grid(c_ptr)) continue;
973 /* Check for "availability" (if monsters can flow) */
974 if (!stupid_monsters && !(m_ptr->mflag2 & MFLAG_NOFLOW))
976 /* Ignore grids very far from the player */
977 if (c_ptr->dist == 0) continue;
979 /* Ignore too-distant grids */
980 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
983 /* Check for absence of shot (more or less) */
984 if (!player_has_los_grid(c_ptr))
987 /* Calculate distance from player */
988 dis = distance(y, x, py, px);
990 /* Remember if further than previous */
1000 /* Check for success */
1007 /* Found safe place */
1018 * Choose a good hiding place near a monster for it to run toward.
1020 * Pack monsters will use this to "ambush" the player and lure him out
1021 * of corridors into open space so they can swarm him.
1023 * Return TRUE if a good location is available.
1025 static bool find_hiding(int m_idx, int *yp, int *xp)
1027 monster_type *m_ptr = &m_list[m_idx];
1032 int y, x, dy, dx, d, dis, i;
1033 int gy = 0, gx = 0, gdis = 999;
1035 sint *y_offsets, *x_offsets;
1039 /* Start with adjacent locations, spread further */
1040 for (d = 1; d < 10; d++)
1042 /* Get the lists of points with a distance d from (fx, fy) */
1043 y_offsets = dist_offsets_y[d];
1044 x_offsets = dist_offsets_x[d];
1046 /* Check the locations */
1047 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
1049 i++, dx = x_offsets[i], dy = y_offsets[i])
1054 /* Skip illegal locations */
1055 if (!in_bounds(y, x)) continue;
1057 c_ptr = &cave[y][x];
1059 /* Skip occupied locations */
1060 if (!cave_empty_grid(c_ptr)) continue;
1062 /* Check for hidden, available grid */
1063 if (!player_has_los_grid(c_ptr) && clean_shot(fy, fx, y, x, FALSE))
1065 /* Calculate distance from player */
1066 dis = distance(y, x, py, px);
1068 /* Remember if closer than previous */
1069 if (dis < gdis && dis >= 2)
1078 /* Check for success */
1085 /* Found good place */
1096 * Choose "logical" directions for monster movement
1098 static bool get_moves(int m_idx, int *mm)
1100 monster_type *m_ptr = &m_list[m_idx];
1101 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1107 bool will_run = mon_will_run(m_idx);
1109 bool no_flow = ((m_ptr->mflag2 & MFLAG_NOFLOW) && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1112 /* Flow towards the player */
1113 if (!stupid_monsters)
1115 /* Flow towards the player */
1116 (void)get_moves_aux(m_idx, &y2, &x2, no_flow);
1119 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
1121 /* Extract the "pseudo-direction" */
1125 if (!stupid_monsters && !will_run && is_hostile(m_ptr) &&
1126 (r_ptr->flags1 & RF1_FRIENDS) &&
1127 (los(m_ptr->fy, m_ptr->fx, py, px) ||
1128 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1131 * Animal packs try to get the player out of corridors
1132 * (...unless they can move through walls -- TY)
1134 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1135 !(r_ptr->flags2 & RF2_KILL_WALL))
1139 /* Count room grids next to player */
1140 for (i = 0; i < 8; i++)
1142 int x = px + ddx_ddd[i];
1143 int y = py + ddy_ddd[i];
1147 if (!in_bounds2(y, x)) continue;
1149 c_ptr = &cave[y][x];
1152 if (((cave_floor_grid(c_ptr)) || ((c_ptr->feat & 0x60) == 0x60)) &&
1153 monster_can_cross_terrain(c_ptr->feat, r_ptr))
1155 /* One more room grid */
1159 if (cave[py][px].info & CAVE_ROOM) room -= 2;
1160 if (!r_ptr->flags4 && !r_ptr->flags5 && !r_ptr->flags6) room -= 2;
1162 /* Not in a room and strong player */
1163 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
1164 (p_ptr->mhp + p_ptr->msp))
1166 /* Find hiding place */
1167 if (find_hiding(m_idx, &y, &x)) done = TRUE;
1171 /* Monster groups try to surround the player */
1172 if (!done && (cave[m_ptr->fy][m_ptr->fx].dist < 3))
1176 /* Find an empty square near the player to fill */
1177 for (i = 0; i < 8; i++)
1179 /* Pick squares near player (semi-randomly) */
1180 y2 = py + ddy_ddd[(m_idx + i) & 7];
1181 x2 = px + ddx_ddd[(m_idx + i) & 7];
1183 /* Already there? */
1184 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
1186 /* Attack the player */
1193 if (!in_bounds2(y2, x2)) continue;
1195 /* Ignore filled grids */
1196 c_ptr = &cave[y2][x2];
1197 if (!cave_empty_grid(c_ptr)) continue;
1199 /* Try to fill this hole */
1203 /* Extract the new "pseudo-direction" */
1212 /* Apply fear if possible and necessary */
1213 if ((stupid_monsters || is_pet(m_ptr)) && will_run)
1215 /* XXX XXX Not very "smart" */
1220 if (!done && will_run)
1225 /* Try to find safe place */
1226 if (find_safety(m_idx, &y, &x))
1228 /* Attempt to avoid the player */
1229 if (!stupid_monsters && !no_flow)
1231 /* Adjust movement */
1232 if (get_fear_moves_aux(m_idx, &y, &x)) done = TRUE;
1238 /* This is not a very "smart" method XXX XXX */
1246 if (!stupid_monsters)
1248 /* Check for no move */
1249 if (!x && !y) return (FALSE);
1253 /* Extract the "absolute distances" */
1257 /* Do something weird */
1258 if (y < 0) move_val += 8;
1259 if (x > 0) move_val += 4;
1261 /* Prevent the diamond maneuvre */
1267 else if (ax > (ay << 1))
1272 /* Extract some directions */
1417 /* Wants to move... */
1422 static int check_hit2(int power, int level, int ac, int stun)
1426 /* Percentile dice */
1429 if (stun && one_in_(2)) return FALSE;
1431 /* Hack -- Always miss or hit */
1432 if (k < 10) return (k < 5);
1434 /* Calculate the "attack quality" */
1435 i = (power + (level * 3));
1437 /* Power and Level compete against Armor */
1438 if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
1445 /* Monster attacks monster */
1446 static bool monst_attack_monst(int m_idx, int t_idx)
1448 monster_type *m_ptr = &m_list[m_idx];
1449 monster_type *t_ptr = &m_list[t_idx];
1451 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1452 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1456 char m_name[80], t_name[80];
1458 bool blinked, heal_effect;
1459 bool explode = FALSE, touched = FALSE, fear = FALSE;
1460 int y_saver = t_ptr->fy;
1461 int x_saver = t_ptr->fx;
1463 bool see_m = m_ptr->ml;
1464 bool see_t = t_ptr->ml;
1465 bool see_either = see_m || see_t;
1467 /* Can the player be aware of this attack? */
1468 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1469 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1471 /* Cannot attack self */
1472 if (m_idx == t_idx) return FALSE;
1474 /* Not allowed to attack */
1475 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1477 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1485 /* Extract the effective monster level */
1486 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1488 /* Get the monster name (or "it") */
1489 monster_desc(m_name, m_ptr, 0);
1491 /* Get the monster name (or "it") */
1492 monster_desc(t_name, t_ptr, 0);
1494 /* Assume no blink */
1497 if (!see_either && known)
1502 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
1504 /* Scan through all four blows */
1505 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1507 bool obvious = FALSE;
1514 /* Extract the attack infomation */
1515 int effect = r_ptr->blow[ap_cnt].effect;
1516 int method = r_ptr->blow[ap_cnt].method;
1517 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1518 int d_side = r_ptr->blow[ap_cnt].d_side;
1520 if (!m_ptr->r_idx) break;
1522 /* Stop attacking if the target dies! */
1523 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1526 /* Hack -- no more attacks */
1529 if (blinked) /* Stop! */
1534 if (method == RBM_SHOOT) continue;
1536 /* Extract the attack "power" */
1539 case RBE_HURT: power = 60; break;
1540 case RBE_POISON: power = 5; break;
1541 case RBE_UN_BONUS: power = 20; break;
1542 case RBE_UN_POWER: power = 15; break;
1543 case RBE_EAT_GOLD: power = 5; break;
1544 case RBE_EAT_ITEM: power = 5; break;
1545 case RBE_EAT_FOOD: power = 5; break;
1546 case RBE_EAT_LITE: power = 5; break;
1547 case RBE_ACID: power = 0; break;
1548 case RBE_ELEC: power = 10; break;
1549 case RBE_FIRE: power = 10; break;
1550 case RBE_COLD: power = 10; break;
1551 case RBE_BLIND: power = 2; break;
1552 case RBE_CONFUSE: power = 10; break;
1553 case RBE_TERRIFY: power = 10; break;
1554 case RBE_PARALYZE: power = 2; break;
1555 case RBE_LOSE_STR: power = 0; break;
1556 case RBE_LOSE_DEX: power = 0; break;
1557 case RBE_LOSE_CON: power = 0; break;
1558 case RBE_LOSE_INT: power = 0; break;
1559 case RBE_LOSE_WIS: power = 0; break;
1560 case RBE_LOSE_CHR: power = 0; break;
1561 case RBE_LOSE_ALL: power = 2; break;
1562 case RBE_SHATTER: power = 60; break;
1563 case RBE_EXP_10: power = 5; break;
1564 case RBE_EXP_20: power = 5; break;
1565 case RBE_EXP_40: power = 5; break;
1566 case RBE_EXP_80: power = 5; break;
1567 case RBE_DISEASE: power = 5; break;
1568 case RBE_TIME: power = 5; break;
1569 case RBE_EXP_VAMP: power = 5; break;
1570 case RBE_DR_MANA: power = 5; break;
1571 case RBE_SUPERHURT: power = 60; break;
1576 if (!effect || check_hit2(power, rlev, ac, m_ptr->stunned))
1578 /* Describe the attack method */
1584 act = "%s¤ò²¥¤Ã¤¿¡£";
1596 act = "%s¤ò¿¨¤Ã¤¿¡£";
1598 act = "touches %s.";
1608 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1610 act = "punches %s.";
1620 act = "%s¤ò½³¤Ã¤¿¡£";
1632 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1644 act = "%s¤ò³ú¤ó¤À¡£";
1656 act = "%s¤ò»É¤·¤¿¡£";
1668 act = "%s¤ò»Â¤Ã¤¿¡£";
1670 act = "slashes %s.";
1679 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1691 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1693 act = "crushes %s.";
1703 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1705 act = "engulfs %s.";
1715 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1717 act = "charges %s.";
1727 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1729 act = "crawls on %s.";
1739 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1741 act = "drools on %s.";
1751 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1753 act = "spits on %s.";
1762 if (see_either) disturb(1, 0);
1777 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1779 act = "gazes at %s.";
1789 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1791 act = "wails at %s.";
1801 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1803 act = "releases spores at %s.";
1813 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1815 act = "projects XXX4's at %s.";
1825 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1827 act = "begs %s for money.";
1837 act = "%s¤òÉî¿«¤·¤¿¡£";
1839 act = "insults %s.";
1849 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1851 act = "moans at %s.";
1861 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1863 act = "sings to %s.";
1872 if (act && see_either)
1874 if (do_silly_attack)
1876 act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
1878 strfmt(temp, act, t_name);
1880 msg_format("%^s¤Ï%s", m_name, temp);
1882 msg_format("%^s %s", m_name, temp);
1887 /* Hack -- assume all attacks are obvious */
1890 /* Roll out the damage */
1891 damage = damroll(d_dice, d_side);
1893 /* Assume no healing effect */
1894 heal_effect = FALSE;
1898 /* Apply appropriate damage */
1910 if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13)) {
1911 int tmp_damage = damage-(damage*((ac < 150) ? ac : 150)/250);
1912 damage = MAX(damage, tmp_damage*2);
1918 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1948 if (one_in_(2)) blinked = TRUE;
1995 pt = GF_OLD_SLEEP; /* sort of close... */
2013 earthquake(m_ptr->fy, m_ptr->fx, 8);
2046 /* Do damage if not exploding */
2049 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
2050 (pt == GF_OLD_SLEEP ? r_ptr->level : damage), pt, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2055 if ((monster_living(tr_ptr)) && (damage > 2))
2057 bool did_heal = FALSE;
2059 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
2062 m_ptr->hp += damroll(4, damage / 6);
2063 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
2065 /* Redraw (later) if needed */
2066 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2067 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2069 /* Special message */
2070 if (see_m && did_heal)
2073 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
2075 msg_format("%^s appears healthier.", m_name);
2085 if ((tr_ptr->flags2 & RF2_AURA_FIRE) &&
2086 !(r_ptr->flags3 & RF3_IM_FIRE) &&
2087 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2093 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2095 msg_format("%^s is suddenly very hot!", m_name);
2099 tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2101 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2102 damroll (1 + ((tr_ptr->level) / 26),
2103 1 + ((tr_ptr->level) / 17)),
2104 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2108 if ((tr_ptr->flags3 & RF3_AURA_COLD) &&
2109 !(r_ptr->flags3 & RF3_IM_COLD) &&
2110 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2116 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2118 msg_format("%^s is suddenly very cold!", m_name);
2122 tr_ptr->r_flags3 |= RF3_AURA_COLD;
2124 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2125 damroll (1 + ((tr_ptr->level) / 26),
2126 1 + ((tr_ptr->level) / 17)),
2127 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2131 if ((tr_ptr->flags2 & (RF2_AURA_ELEC)) &&
2132 !(r_ptr->flags3 & (RF3_IM_ELEC)) &&
2133 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2139 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2141 msg_format("%^s gets zapped!", m_name);
2145 tr_ptr->r_flags2 |= RF2_AURA_ELEC;
2147 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2148 damroll (1 + ((tr_ptr->level) / 26),
2149 1 + ((tr_ptr->level) / 17)),
2150 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2157 /* Monster missed player */
2160 /* Analyze failed attacks */
2176 /* Visible monsters */
2181 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2183 msg_format("%^s misses %s.", m_name, t_name);
2194 /* Analyze "visible" monsters only */
2195 if (see_m && !do_silly_attack)
2197 /* Count "obvious" attacks (and ones that cause damage) */
2198 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2200 /* Count attacks of this type */
2201 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2203 r_ptr->r_blows[ap_cnt]++;
2211 sound(SOUND_EXPLODE);
2213 /* Cancel Invulnerability */
2214 if (m_ptr->invulner) m_ptr->invulner = 0;
2217 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2219 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2233 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2235 msg_print("The thief flees laughing!");
2244 teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE);
2252 * Hack -- local "player stealth" value (see below)
2254 static u32b noise = 0L;
2260 * The monster is known to be within 100 grids of the player
2262 * In several cases, we directly update the monster lore
2264 * Note that a monster is only allowed to "reproduce" if there
2265 * are a limited number of "reproducing" monsters on the current
2266 * level. This should prevent the level from being "swamped" by
2267 * reproducing monsters. It also allows a large mass of mice to
2268 * prevent a louse from multiplying, but this is a small price to
2269 * pay for a simple multiplication method.
2271 * XXX Monster fear is slightly odd, in particular, monsters will
2272 * fixate on opening a door even if they cannot open it. Actually,
2273 * the same thing happens to normal monsters when they hit a door
2275 * XXX XXX XXX In addition, monsters which *cannot* open or bash
2276 * down a door will still stand there trying to open it...
2278 * XXX Technically, need to check for monster in the way
2279 * combined with that monster being in a wall (or door?)
2281 * A "direction" of "5" means "pick a random direction".
2283 static void process_monster(int m_idx)
2285 monster_type *m_ptr = &m_list[m_idx];
2286 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2288 int i, d, oy, ox, ny, nx;
2294 monster_type *y_ptr;
2307 bool gets_angry = FALSE;
2313 if ((m_idx == p_ptr->riding) && !(r_ptr->flags7 & RF7_RIDING))
2315 if (rakuba(0, TRUE))
2318 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2321 monster_desc(m_name, &m_list[p_ptr->riding], 0);
2322 msg_format("You have fallen from %s.", m_name);
2327 if ((m_ptr->mflag2 & MFLAG_CHAMELEON) && one_in_(13) && !m_ptr->csleep)
2329 choose_new_monster(m_idx, FALSE, 0);
2330 r_ptr = &r_info[m_ptr->r_idx];
2333 /* Players hidden in shadow are almost imperceptable. -LM- */
2334 if (p_ptr->special_defense & NINJA_S_STEALTH)
2336 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
2337 if (p_ptr->monlite) tmp /= 3;
2338 if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
2339 if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
2340 /* Low-level monsters will find it difficult to locate the player. */
2341 if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
2344 /* Quantum monsters are odd */
2345 if (r_ptr->flags2 & (RF2_QUANTUM))
2347 /* Sometimes skip move */
2348 if (!randint0(2)) return;
2351 if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2355 if (is_pet(m_ptr) && !(m_ptr->ml))
2362 /* Acquire the monster name */
2363 monster_desc(m_name, m_ptr, 0);
2367 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2369 msg_format("%^s disappears!", m_name);
2374 /* Generate treasure, etc */
2375 monster_death(m_idx, FALSE);
2377 /* Delete the monster */
2378 delete_monster_idx(m_idx);
2383 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2385 msg_print("You feel sad for a moment.");
2394 if (m_ptr->r_idx == MON_SHURYUUDAN)
2396 mon_take_hit_mon(FALSE, m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2398 mon_take_hit_mon(FALSE, m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2401 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) && !p_ptr->inside_battle)
2403 static int riding_pinch = 0;
2405 if (m_ptr->hp < m_ptr->maxhp/3)
2407 bool level_teleport = TRUE;
2409 monster_desc(m_name, m_ptr, 0);
2411 if (m_idx == p_ptr->riding && riding_pinch < 2)
2414 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2416 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
2419 level_teleport = FALSE;
2424 if (m_idx == p_ptr->riding)
2427 msg_format("%s¤Ï¤¢¤Ê¤¿¤Î«Çû¤«¤éæ½Ð¤·¤¿¡£", m_name);
2429 msg_format("%^s succeeded to escape from your restriction!", m_name);
2432 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))
2435 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2437 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2441 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2443 msg_format("%^s read a scroll of teleport level.", m_name);
2446 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2448 msg_format("%^s disappears.", m_name);
2454 delete_monster_idx(m_idx);
2456 if (m_idx == p_ptr->riding)
2458 if (rakuba(-1, FALSE))
2461 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2463 msg_print("You have fallen from riding pet.");
2471 if (m_idx == p_ptr->riding) riding_pinch = 0;
2475 /* Handle Invulnerability */
2476 if (m_ptr->invulner)
2478 /* Reduce by one, note if expires */
2481 if (!(m_ptr->invulner) && m_ptr->ml)
2485 /* Acquire the monster name */
2486 monster_desc(m_name, m_ptr, 0);
2488 /* Dump a message */
2490 msg_format("%^s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ê¤¤¡£", m_name);
2492 msg_format("%^s is no longer invulnerable.", m_name);
2495 m_ptr->energy_need += ENERGY_NEED();
2496 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2497 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2504 /* Reduce by one, note if expires */
2507 if (!(m_ptr->fast) && m_ptr->ml)
2511 /* Acquire the monster name */
2512 monster_desc(m_name, m_ptr, 0);
2514 /* Dump a message */
2516 msg_format("%^s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2518 msg_format("%^s is no longer fast.", m_name);
2521 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2522 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2529 /* Reduce by one, note if expires */
2532 if (!(m_ptr->slow) && m_ptr->ml)
2536 /* Acquire the monster name */
2537 monster_desc(m_name, m_ptr, 0);
2539 /* Dump a message */
2541 msg_format("%^s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2543 msg_format("%^s is no longer slow.", m_name);
2546 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2547 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2551 /* Handle "sleep" */
2556 /* Hack -- handle non-aggravation */
2557 if (!(p_ptr->cursed & TRC_AGGRAVATE)) notice = randint0(1024);
2559 /* Nightmare monsters are more alert */
2560 if (ironman_nightmare) notice /= 2;
2562 /* Hack -- See if monster "notices" player */
2563 if ((notice * notice * notice) <= noise)
2565 /* Hack -- amount of "waking" */
2568 /* Wake up faster near the player */
2569 if (m_ptr->cdis < 50) d = (100 / m_ptr->cdis);
2571 /* Hack -- handle aggravation */
2572 if (p_ptr->cursed & TRC_AGGRAVATE) d = m_ptr->csleep;
2575 if (m_ptr->csleep > d)
2577 /* Monster wakes up "a little bit" */
2580 /* Notice the "not waking up" */
2583 /* Hack -- Count the ignores */
2584 if (r_ptr->r_ignore < MAX_UCHAR)
2594 /* Reset sleep counter */
2597 /* Notice the "waking up" */
2602 /* Acquire the monster name */
2603 monster_desc(m_name, m_ptr, 0);
2605 /* Dump a message */
2607 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
2609 msg_format("%^s wakes up.", m_name);
2613 /* Redraw the health bar */
2614 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2615 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2617 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2))
2618 p_ptr->update |= (PU_MON_LITE);
2620 /* Hack -- Count the wakings */
2621 if (r_ptr->r_wake < MAX_UCHAR)
2629 /* Still sleeping */
2630 if (m_ptr->csleep) return;
2639 /* Make a "saving throw" against stun */
2640 if (randint0(10000) <= r_ptr->level * r_ptr->level)
2646 /* Hack -- Recover from stun */
2647 if (m_ptr->stunned > d)
2649 /* Recover somewhat */
2650 m_ptr->stunned -= d;
2659 /* Message if visible */
2664 /* Acquire the monster name */
2665 monster_desc(m_name, m_ptr, 0);
2667 /* Dump a message */
2669 msg_format("%^s¤ÏÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2671 msg_format("%^s is no longer stunned.", m_name);
2674 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2675 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2680 if (m_ptr->stunned && one_in_(2)) return;
2684 /* Handle confusion */
2685 if (m_ptr->confused)
2687 /* Amount of "boldness" */
2688 int d = randint1(r_ptr->level / 20 + 1);
2690 /* Still confused */
2691 if (m_ptr->confused > d)
2693 /* Reduce the confusion */
2694 m_ptr->confused -= d;
2700 /* No longer confused */
2701 m_ptr->confused = 0;
2703 /* Message if visible */
2708 /* Acquire the monster name */
2709 monster_desc(m_name, m_ptr, 0);
2711 /* Dump a message */
2713 msg_format("%^s¤Ïº®Í𤫤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2715 msg_format("%^s is no longer confused.", m_name);
2718 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2719 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2724 if (p_ptr->riding == m_idx)
2726 p_ptr->update |= (PU_BONUS);
2729 /* No one wants to be your friend if you're aggravating */
2730 if (is_friendly(m_ptr) && (p_ptr->cursed & TRC_AGGRAVATE))
2733 /* Paranoia... no pet uniques outside wizard mode -- TY */
2734 if (is_pet(m_ptr) &&
2735 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
2736 ((p_ptr->align > 9 && (r_ptr->flags3 & RF3_EVIL)) ||
2737 (p_ptr->align < -9 && (r_ptr->flags3 & RF3_GOOD))))
2738 || (r_ptr->flags3 & RF3_RES_ALL)))
2743 if (p_ptr->inside_battle) gets_angry = FALSE;
2748 monster_desc(m_name, m_ptr, 0);
2750 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2752 msg_format("%^s suddenly becomes hostile!", m_name);
2761 /* Amount of "boldness" */
2762 int d = randint1(r_ptr->level / 20 + 1);
2765 if (m_ptr->monfear > d)
2767 /* Reduce the fear */
2768 m_ptr->monfear -= d;
2771 /* Recover from fear, take note if seen */
2774 /* No longer afraid */
2783 /* Acquire the monster name/poss */
2784 monster_desc(m_name, m_ptr, 0);
2785 monster_desc(m_poss, m_ptr, 0x22);
2787 /* Dump a message */
2789 msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name);
2791 msg_format("%^s recovers %s courage.", m_name, m_poss);
2794 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2799 /* Get the origin */
2804 /* Attempt to "multiply" if able and allowed */
2805 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2809 /* Count the adjacent monsters */
2810 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2812 for (x = ox - 1; x <= ox + 1; x++)
2814 /* Ignore locations off of edge */
2815 if (!in_bounds2(y, x)) continue;
2817 if (cave[y][x].m_idx) k++;
2821 /* Hack -- multiply slower in crowded areas */
2822 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2824 /* Try to multiply */
2825 if (multiply_monster(m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
2827 /* Take note if visible */
2830 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2833 /* Multiplying takes energy */
2840 if (!p_ptr->inside_battle)
2842 /* Hack! "Cyber" monster makes noise... */
2843 if (m_ptr->ap_r_idx == MON_CYBER &&
2844 one_in_(CYBERNOISE) &&
2845 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2847 if (disturb_minor) disturb(FALSE, FALSE);
2849 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2851 msg_print("You hear heavy steps.");
2856 /* Some monsters can speak */
2857 if ((r_info[m_ptr->ap_r_idx].flags2 & RF2_CAN_SPEAK) && aware &&
2858 one_in_(SPEAK_CHANCE) &&
2859 player_has_los_bold(oy, ox))
2862 char monmessage[1024];
2865 /* Acquire the monster name/poss */
2867 monster_desc(m_name, m_ptr, 0);
2870 strcpy(m_name, "¤½¤ì");
2872 strcpy(m_name, "It");
2876 /* Select the file for monster quotes */
2879 filename = "monfear_j.txt";
2881 filename = "monfear.txt";
2884 else if (is_pet(m_ptr))
2886 filename = "monpet_j.txt";
2888 filename = "monpet.txt";
2891 else if (is_friendly(m_ptr))
2893 filename = "monfrien_j.txt";
2895 filename = "monfrien.txt";
2900 filename = "monspeak_j.txt";
2902 filename = "monspeak.txt";
2906 /* Get the monster line */
2907 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
2911 msg_format("%^s%s", m_name, monmessage);
2913 msg_format("%^s %s", m_name, monmessage);
2920 /* Attempt to cast a spell */
2921 if (aware && make_attack_spell(m_idx)) return;
2924 * Attempt to cast a spell at an enemy other than the player
2925 * (may slow the game a smidgeon, but I haven't noticed.)
2927 if (monst_spell_monst(m_idx)) return;
2929 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
2931 /* Hack -- Assume no movement */
2932 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2933 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2936 /* Confused -- 100% random */
2937 if (m_ptr->confused || !aware)
2939 /* Try four "random" directions */
2940 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2943 /* 75% random movement */
2944 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2945 (r_ptr->flags1 & RF1_RAND_25) &&
2946 (randint0(100) < 75))
2948 /* Memorize flags */
2949 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2950 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25);
2952 /* Try four "random" directions */
2953 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2956 /* 50% random movement */
2957 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2958 (randint0(100) < 50))
2960 /* Memorize flags */
2961 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2963 /* Try four "random" directions */
2964 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2967 /* 25% random movement */
2968 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2969 (randint0(100) < 25))
2971 /* Memorize flags */
2972 if (m_ptr->ml) r_ptr->r_flags1 |= RF1_RAND_25;
2974 /* Try four "random" directions */
2975 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2978 /* Can't reach player - find something else to hit */
2979 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2981 /* Try four "random" directions */
2982 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2984 /* Look for an enemy */
2985 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2986 get_enemy_dir(m_idx, mm);
2990 /* Pets will follow the player */
2991 else if (is_pet(m_ptr))
2993 /* Are we trying to avoid the player? */
2994 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
2995 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2997 /* Do we want to find the player? */
2998 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
3000 /* Should we find the player if we can't find a monster? */
3001 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
3003 /* by default, move randomly */
3004 mm[0] = mm[1] = mm[2] = mm[3] = 5;
3006 /* Look for an enemy */
3007 if (!get_enemy_dir(m_idx, mm))
3009 /* Find the player if necessary */
3010 if (avoid || lonely || distant)
3012 /* Remember the leash length */
3013 int dis = p_ptr->pet_follow_distance;
3015 /* Hack -- adjust follow distance temporarily */
3016 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
3018 p_ptr->pet_follow_distance = PET_SEEK_DIST;
3021 /* Find the player */
3022 get_moves(m_idx, mm);
3024 /* Restore the leash */
3025 p_ptr->pet_follow_distance = dis;
3030 /* Friendly monster movement */
3031 else if (!is_hostile(m_ptr))
3033 /* by default, move randomly */
3034 mm[0] = mm[1] = mm[2] = mm[3] = 5;
3036 /* Look for an enemy */
3037 get_enemy_dir(m_idx, mm);
3039 /* Normal movement */
3040 else if (stupid_monsters)
3043 get_moves(m_idx, mm);
3047 /* Logical moves, may do nothing */
3048 if (!get_moves(m_idx, mm)) return;
3051 /* Assume nothing */
3056 /* Assume nothing */
3057 did_open_door = FALSE;
3058 did_bash_door = FALSE;
3059 did_take_item = FALSE;
3060 did_kill_item = FALSE;
3061 did_move_body = FALSE;
3062 did_pass_wall = FALSE;
3063 did_kill_wall = FALSE;
3066 /* Take a zero-terminated array of "directions" */
3067 for (i = 0; mm[i]; i++)
3069 /* Get the direction */
3072 /* Hack -- allow "randomized" motion */
3073 if (d == 5) d = ddd[randint0(8)];
3075 /* Get the destination */
3079 /* Ignore locations off of edge */
3080 if (!in_bounds2(ny, nx)) continue;
3082 /* Access that cave grid */
3083 c_ptr = &cave[ny][nx];
3085 /* Access that cave grid's contents */
3086 y_ptr = &m_list[c_ptr->m_idx];
3088 /* Floor is open? */
3089 if (cave_floor_grid(c_ptr))
3091 /* Go ahead and move */
3095 /* Hack -- player 'in' wall */
3096 else if ((ny == py) && (nx == px))
3101 else if (c_ptr->m_idx)
3103 /* Possibly a monster to attack */
3107 /* Permanent wall */
3108 else if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
3109 (c_ptr->feat <= FEAT_PERM_SOLID))
3114 /* Hack -- semi-transparent terrains are no obstacle */
3115 else if (c_ptr->feat == FEAT_TREES)
3120 /* Hack -- semi-transparent terrains are no obstacle */
3121 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)))))
3127 /* Monster moves through walls (and doors) */
3128 else if (can_pass_wall)
3130 /* Pass through walls/doors/rubble */
3133 /* Monster went through a wall */
3134 did_pass_wall = TRUE;
3137 /* Monster destroys walls (and doors) */
3138 else if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))
3140 /* Eat through walls/doors/rubble */
3143 /* Monster destroyed a wall */
3144 did_kill_wall = TRUE;
3146 if (one_in_(GRINDNOISE))
3149 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
3151 msg_print("There is a grinding sound.");
3156 /* Forget the wall */
3157 c_ptr->info &= ~(CAVE_MARK);
3159 /* Clear garbage of hidden trap or door */
3163 c_ptr->feat = floor_type[randint0(100)];
3165 /* Note changes to viewable region */
3166 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3169 /* Handle doors and secret doors */
3170 else if (is_closed_door(c_ptr->feat))
3172 bool may_bash = TRUE;
3174 /* Assume no move allowed */
3177 /* Creature can open doors. */
3178 if ((r_ptr->flags2 & RF2_OPEN_DOOR) &&
3179 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3182 if (c_ptr->feat == FEAT_DOOR_HEAD)
3184 /* The door is open */
3185 did_open_door = TRUE;
3187 /* Do not bash the door */
3190 /* Assume no move allowed */
3194 /* Locked doors (not jammed) */
3195 else if (c_ptr->feat < FEAT_DOOR_HEAD + 0x08)
3200 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3202 /* Try to unlock it XXX XXX XXX */
3203 if (randint0(m_ptr->hp / 10) > k)
3205 /* Unlock the door */
3206 cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00);
3208 /* Do not bash the door */
3214 /* Stuck doors -- attempt to bash them down if allowed */
3215 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) &&
3216 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3221 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3223 /* Attempt to Bash XXX XXX XXX */
3224 if (randint0(m_ptr->hp / 10) > k)
3228 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
3230 msg_print("You hear a door burst open!");
3234 /* Disturb (sometimes) */
3235 if (disturb_minor) disturb(0, 0);
3237 /* The door was bashed open */
3238 did_bash_door = TRUE;
3240 /* Hack -- fall into doorway */
3246 /* Deal with doors in the way */
3247 if (did_open_door || did_bash_door)
3249 /* Break down the door */
3250 if (did_bash_door && (randint0(100) < 50))
3252 cave_set_feat(ny, nx, FEAT_BROKEN);
3258 cave_set_feat(ny, nx, FEAT_OPEN);
3261 /* Handle viewable doors */
3262 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3266 /* Hack -- check for Glyph of Warding */
3267 if (do_move && is_glyph_grid(c_ptr) &&
3268 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3270 /* Assume no move allowed */
3273 /* Break the ward */
3274 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
3276 /* Describe observable breakage */
3277 if (c_ptr->info & CAVE_MARK)
3280 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3282 msg_print("The rune of protection is broken!");
3287 /* Forget the rune */
3288 c_ptr->info &= ~(CAVE_MARK);
3290 /* Break the rune */
3291 c_ptr->info &= ~(CAVE_OBJECT);
3294 /* Allow movement */
3301 else if (do_move && is_explosive_rune_grid(c_ptr) &&
3302 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3304 /* Assume no move allowed */
3307 /* Break the ward */
3310 /* Break the ward */
3311 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3313 /* Describe observable breakage */
3314 if (c_ptr->info & CAVE_MARK)
3317 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3319 msg_print("The rune explodes!");
3322 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);
3328 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3330 msg_print("An explosive rune was disarmed.");
3334 /* Forget the rune */
3335 c_ptr->info &= ~(CAVE_MARK);
3337 /* Break the rune */
3338 c_ptr->info &= ~(CAVE_OBJECT);
3344 if (!m_ptr->r_idx) return;
3345 /* Allow movement */
3349 if (do_move && (ny == py) && (nx == px) && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3354 /* Some monsters never attack */
3355 if (do_move && (ny == py) && (nx == px) &&
3356 (r_ptr->flags1 & RF1_NEVER_BLOW))
3358 /* Hack -- memorize lack of attacks */
3359 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3365 /* The player is in the way. Attack him. */
3366 if (do_move && (ny == py) && (nx == px))
3368 if (!p_ptr->riding || one_in_(2))
3371 (void)make_attack_normal(m_idx);
3381 if ((c_ptr->feat >= FEAT_PATTERN_START) &&
3382 (c_ptr->feat <= FEAT_PATTERN_XTRA2) &&
3383 !do_turn && !(r_ptr->flags7 & RF7_CAN_FLY))
3389 /* A monster is in the way */
3390 if (do_move && c_ptr->m_idx)
3392 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3393 monster_type *m2_ptr = &m_list[c_ptr->m_idx];
3395 /* Assume no movement */
3398 /* Attack 'enemies' */
3399 if (((r_ptr->flags2 & (RF2_KILL_BODY)) &&
3400 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3401 (cave_floor_grid(c_ptr)) &&
3402 (c_ptr->m_idx != p_ptr->riding)) ||
3403 are_enemies(m_ptr, m2_ptr) || m_ptr->confused)
3407 if (r_ptr->flags2 & RF2_KILL_BODY) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3410 if ((m2_ptr->r_idx) && (m2_ptr->hp >= 0))
3412 if (monst_attack_monst(m_idx, cave[ny][nx].m_idx))
3417 /* Push past weaker monsters (unless leaving a wall) */
3418 else if ((r_ptr->flags2 & RF2_MOVE_BODY) &&
3419 (r_ptr->mexp > z_ptr->mexp) && cave_floor_grid(c_ptr) &&
3420 (cave_floor_grid(&cave[m_ptr->fy][m_ptr->fx])) &&
3421 (c_ptr->m_idx != p_ptr->riding))
3423 /* Allow movement */
3426 /* Monster pushed past another monster */
3427 did_move_body = TRUE;
3429 /* XXX XXX XXX Message */
3434 * Check if monster can cross terrain
3435 * This is checked after the normal attacks
3436 * to allow monsters to attack an enemy,
3437 * even if it can't enter the terrain.
3439 if (do_move && !monster_can_cross_terrain(c_ptr->feat, r_ptr))
3441 /* Assume no move allowed */
3445 /* Some monsters never move */
3446 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3448 /* Hack -- memorize lack of attacks */
3449 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3455 if (m_idx == p_ptr->riding)
3457 if (!p_ptr->riding_ryoute && !(m_list[p_ptr->riding].monfear)) do_move = FALSE;
3460 /* Creature has been allowed move */
3463 s16b this_o_idx, next_o_idx;
3468 /* Hack -- Update the old location */
3469 cave[oy][ox].m_idx = c_ptr->m_idx;
3471 if (cave[ny][nx].feat == FEAT_TREES)
3473 if (r_ptr->flags2 & RF2_KILL_WALL)
3475 c_ptr->feat = FEAT_GRASS;
3477 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3479 m_ptr->energy_need += ENERGY_NEED();
3483 /* Mega-Hack -- move the old monster, if any */
3486 /* Move the old monster */
3490 /* Update the old monster */
3491 update_mon(c_ptr->m_idx, TRUE);
3493 /* Wake up the moved monster */
3494 m_list[c_ptr->m_idx].csleep = 0;
3497 /* Hack -- Update the new location */
3498 c_ptr->m_idx = m_idx;
3500 /* Move the monster */
3504 /* Update the monster */
3505 update_mon(m_idx, TRUE);
3507 if (p_ptr->riding == m_idx)
3513 /* Redraw the old grid */
3516 /* Redraw the new grid */
3519 if (p_ptr->riding == m_idx)
3524 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW);
3526 /* Update the monsters */
3527 p_ptr->update |= (PU_DISTANCE);
3530 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3533 /* Possible disturb */
3534 if (m_ptr->ml && (disturb_move ||
3535 ((m_ptr->mflag & MFLAG_VIEW) &&
3539 if (is_hostile(m_ptr))
3543 /* Scan all objects in the grid */
3544 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3548 /* Acquire object */
3549 o_ptr = &o_list[this_o_idx];
3551 /* Acquire next object */
3552 next_o_idx = o_ptr->next_o_idx;
3555 if (o_ptr->tval == TV_GOLD) continue;
3558 * Skip "real" corpses and statues, to avoid extreme
3559 * silliness like a novice rogue pockets full of statues
3562 if ((o_ptr->tval == TV_CORPSE) ||
3563 (o_ptr->tval == TV_STATUE)) continue;
3565 /* Take or Kill objects on the floor */
3566 if ((r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3567 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)))
3569 u32b flgs[TR_FLAG_SIZE];
3575 char o_name[MAX_NLEN];
3577 /* Extract some flags */
3578 object_flags(o_ptr, flgs);
3580 /* Acquire the object name */
3581 object_desc(o_name, o_ptr, TRUE, 3);
3583 /* Acquire the monster name */
3584 monster_desc(m_name, m_ptr, 0x04);
3586 /* React to objects that hurt the monster */
3587 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
3588 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
3589 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
3590 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
3591 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
3592 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
3593 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
3594 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
3595 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
3596 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
3597 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
3598 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
3599 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
3600 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
3601 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
3602 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
3603 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
3604 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
3606 /* The object cannot be picked up by the monster */
3607 if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
3610 /* Only give a message for "take_item" */
3611 if ((r_ptr->flags2 & (RF2_TAKE_ITEM)) && (r_ptr->flags2 & (RF2_STUPID)))
3614 did_take_item = TRUE;
3616 /* Describe observable situations */
3617 if (m_ptr->ml && player_can_see_bold(ny, nx))
3619 /* Dump a message */
3621 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£", m_name, o_name);
3623 msg_format("%^s tries to pick up %s, but fails.", m_name, o_name);
3629 /* Pick up the item */
3630 else if (r_ptr->flags2 & RF2_TAKE_ITEM)
3633 did_take_item = TRUE;
3635 /* Describe observable situations */
3636 if (player_can_see_bold(ny, nx))
3638 /* Dump a message */
3640 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3642 msg_format("%^s picks up %s.", m_name, o_name);
3647 /* Excise the object */
3648 excise_object_idx(this_o_idx);
3653 /* Forget location */
3654 o_ptr->iy = o_ptr->ix = 0;
3656 /* Memorize monster */
3657 o_ptr->held_m_idx = m_idx;
3660 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3663 m_ptr->hold_o_idx = this_o_idx;
3666 /* Destroy the item if not a pet */
3667 else if (!is_pet(m_ptr))
3670 did_kill_item = TRUE;
3672 /* Describe observable situations */
3673 if (player_has_los_bold(ny, nx))
3675 /* Dump a message */
3677 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3679 msg_format("%^s destroys %s.", m_name, o_name);
3684 /* Delete the object */
3685 delete_object_idx(this_o_idx);
3691 /* Stop when done */
3696 * Forward movements failed, but now received LOS attack!
3697 * Try to flow by smell.
3699 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3700 m_ptr->mflag2 &= ~MFLAG_NOFLOW;
3702 /* If we haven't done anything, try casting a spell again */
3703 if (!do_turn && !do_move && !m_ptr->monfear && !stupid_monsters && !(p_ptr->riding == m_idx) && aware)
3706 if (make_attack_spell(m_idx)) return;
3710 /* Notice changes in view */
3713 /* Update some things */
3714 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
3717 /* Notice changes in view */
3718 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)))
3720 /* Update some things */
3721 p_ptr->update |= (PU_MON_LITE);
3724 /* Learn things from observable monster */
3727 /* Monster opened a door */
3728 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3730 /* Monster bashed a door */
3731 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3733 /* Monster tried to pick something up */
3734 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3736 /* Monster tried to crush something */
3737 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3739 /* Monster pushed past another monster */
3740 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3742 /* Monster passed through a wall */
3743 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3745 /* Monster destroyed a wall */
3746 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3750 /* Hack -- get "bold" if out of options */
3751 if (!do_turn && !do_move && m_ptr->monfear && aware)
3753 /* No longer afraid */
3756 /* Message if seen */
3761 /* Acquire the monster name */
3762 monster_desc(m_name, m_ptr, 0);
3764 /* Dump a message */
3766 msg_format("%^s¤ÏÀ襤¤ò·è°Õ¤·¤¿¡ª", m_name);
3768 msg_format("%^s turns to fight!", m_name);
3771 /* Redraw (later) if needed */
3772 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
3774 chg_virtue(V_COMPASSION, -1);
3777 /* XXX XXX XXX Actually do something now (?) */
3782 * Process all the "live" monsters, once per game turn.
3784 * During each game turn, we scan through the list of all the "live" monsters,
3785 * (backwards, so we can excise any "freshly dead" monsters), energizing each
3786 * monster, and allowing fully energized monsters to move, attack, pass, etc.
3788 * Note that monsters can never move in the monster array (except when the
3789 * "compact_monsters()" function is called by "dungeon()" or "save_player()").
3791 * This function is responsible for at least half of the processor time
3792 * on a normal system with a "normal" amount of monsters and a player doing
3795 * When the player is resting, virtually 90% of the processor time is spent
3796 * in this function, and its children, "process_monster()" and "make_move()".
3798 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",
3799 * especially when the player is running.
3801 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"
3802 * monsters while they are still being "born". A monster is "fresh" only
3803 * during the turn in which it is created, and we use the "hack_m_idx" to
3804 * determine if the monster is yet to be processed during the current turn.
3806 * Note the special "MFLAG_NICE" flag, which allows the player to get one
3807 * move before any "nasty" monsters get to use their spell attacks.
3809 * Note that when the "knowledge" about the currently tracked monster
3810 * changes (flags, attacks, spells), we induce a redraw of the monster
3813 void process_monsters(void)
3820 monster_type *m_ptr;
3821 monster_race *r_ptr;
3823 int old_monster_race_idx;
3825 u32b old_r_flags1 = 0L;
3826 u32b old_r_flags2 = 0L;
3827 u32b old_r_flags3 = 0L;
3828 u32b old_r_flags4 = 0L;
3829 u32b old_r_flags5 = 0L;
3830 u32b old_r_flags6 = 0L;
3832 byte old_r_blows0 = 0;
3833 byte old_r_blows1 = 0;
3834 byte old_r_blows2 = 0;
3835 byte old_r_blows3 = 0;
3837 byte old_r_cast_inate = 0;
3838 byte old_r_cast_spell = 0;
3842 /* Clear monster fighting indicator */
3845 /* Memorize old race */
3846 old_monster_race_idx = p_ptr->monster_race_idx;
3848 /* Acquire knowledge */
3849 if (p_ptr->monster_race_idx)
3851 /* Acquire current monster */
3852 r_ptr = &r_info[p_ptr->monster_race_idx];
3854 /* Memorize flags */
3855 old_r_flags1 = r_ptr->r_flags1;
3856 old_r_flags2 = r_ptr->r_flags2;
3857 old_r_flags3 = r_ptr->r_flags3;
3858 old_r_flags4 = r_ptr->r_flags4;
3859 old_r_flags5 = r_ptr->r_flags5;
3860 old_r_flags6 = r_ptr->r_flags6;
3862 /* Memorize blows */
3863 old_r_blows0 = r_ptr->r_blows[0];
3864 old_r_blows1 = r_ptr->r_blows[1];
3865 old_r_blows2 = r_ptr->r_blows[2];
3866 old_r_blows3 = r_ptr->r_blows[3];
3868 /* Memorize castings */
3869 old_r_cast_inate = r_ptr->r_cast_inate;
3870 old_r_cast_spell = r_ptr->r_cast_spell;
3874 /* Hack -- calculate the "player noise" */
3875 noise = (1L << (30 - p_ptr->skill_stl));
3878 /* Process the monsters (backwards) */
3879 for (i = m_max - 1; i >= 1; i--)
3881 /* Access the monster */
3883 r_ptr = &r_info[m_ptr->r_idx];
3885 /* Handle "leaving" */
3886 if (p_ptr->leaving) break;
3888 /* Ignore "dead" monsters */
3889 if (!m_ptr->r_idx) continue;
3891 if (p_ptr->wild_mode) continue;
3894 /* Handle "fresh" monsters */
3895 if (m_ptr->mflag & MFLAG_BORN)
3897 /* No longer "fresh" */
3898 m_ptr->mflag &= ~(MFLAG_BORN);
3904 /* Hack -- Require proximity */
3905 if (m_ptr->cdis >= 100) continue;
3908 /* Access the location */
3912 /* Flow by smell is allowed */
3913 if (!stupid_monsters && !p_ptr->no_flowed)
3915 m_ptr->mflag2 &= ~MFLAG_NOFLOW;
3918 /* Assume no move */
3921 /* Handle "sensing radius" */
3922 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > 20 ? 20 : r_ptr->aaf) : r_ptr->aaf))
3924 /* We can "sense" the player */
3928 /* Handle "sight" and "aggravation" */
3929 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3930 (player_has_los_bold(fy, fx) || (p_ptr->cursed & TRC_AGGRAVATE)))
3932 /* We can "see" or "feel" the player */
3936 #if 0 /* (cave[py][px].when == cave[fy][fx].when) is always FALSE... */
3937 /* Hack -- Monsters can "smell" the player from far away */
3938 /* Note that most monsters have "aaf" of "20" or so */
3939 else if (!stupid_monsters && !(m_ptr->mflag2 & MFLAG_NOFLOW) &&
3940 (cave_floor_bold(py, px) || (cave[py][px].feat == FEAT_TREES)) &&
3941 (cave[py][px].when == cave[fy][fx].when) &&
3942 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3943 (cave[fy][fx].dist < r_ptr->aaf))
3945 /* We can "smell" the player */
3949 else if (m_ptr->target_y) test = TRUE;
3952 if (!test) continue;
3955 if (p_ptr->riding == i)
3956 speed = p_ptr->pspeed;
3959 speed = MIN(199, m_ptr->mspeed);
3961 /* Monsters move quickly in Nightmare mode */
3962 if (ironman_nightmare)
3964 speed = MIN(199, m_ptr->mspeed + 5);
3967 if (m_ptr->fast) speed = MIN(199, speed + 10);
3968 if (m_ptr->slow) speed = MAX(0, speed - 10);
3971 /* Give this monster some energy */
3972 m_ptr->energy_need -= extract_energy[speed];
3974 /* Not enough energy to move */
3975 if (m_ptr->energy_need > 0) continue;
3977 /* Use up "some" energy */
3978 m_ptr->energy_need += ENERGY_NEED();
3981 /* Save global index */
3984 /* Process the monster */
3987 reset_target(m_ptr);
3989 /* Give up flow_by_smell when it might useless */
3990 if (p_ptr->no_flowed && one_in_(3))
3991 m_ptr->mflag2 |= MFLAG_NOFLOW;
3993 /* Hack -- notice death or departure */
3994 if (!p_ptr->playing || p_ptr->is_dead) break;
3996 /* Notice leaving */
3997 if (p_ptr->leaving) break;
4000 /* Reset global index */
4004 /* Tracking a monster race (the same one we were before) */
4005 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
4007 /* Acquire monster race */
4008 r_ptr = &r_info[p_ptr->monster_race_idx];
4010 /* Check for knowledge change */
4011 if ((old_r_flags1 != r_ptr->r_flags1) ||
4012 (old_r_flags2 != r_ptr->r_flags2) ||
4013 (old_r_flags3 != r_ptr->r_flags3) ||
4014 (old_r_flags4 != r_ptr->r_flags4) ||
4015 (old_r_flags5 != r_ptr->r_flags5) ||
4016 (old_r_flags6 != r_ptr->r_flags6) ||
4017 (old_r_blows0 != r_ptr->r_blows[0]) ||
4018 (old_r_blows1 != r_ptr->r_blows[1]) ||
4019 (old_r_blows2 != r_ptr->r_blows[2]) ||
4020 (old_r_blows3 != r_ptr->r_blows[3]) ||
4021 (old_r_cast_inate != r_ptr->r_cast_inate) ||
4022 (old_r_cast_spell != r_ptr->r_cast_spell))
4025 p_ptr->window |= (PW_MONSTER);
4032 bool process_the_world(int num, int who, bool vs_player)
4034 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
4036 if(world_monster) return (FALSE);
4041 monster_desc(m_name, m_ptr, 0);
4045 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
4047 msg_format("%s yells 'The World! Time has stopped!'", m_name);
4051 msg_print("¡Ö»þ¤è¡ª¡×");
4053 msg_format("%s yells 'Time!'", m_name);
4055 else msg_print("hek!");
4060 world_monster = TRUE;
4062 if (vs_player) do_cmd_redraw();
4066 if(!m_ptr->r_idx) break;
4067 process_monster(hack_m_idx);
4069 reset_target(m_ptr);
4072 if (p_ptr->notice) notice_stuff();
4075 if (p_ptr->update) update_stuff();
4078 if (p_ptr->redraw) redraw_stuff();
4081 if (p_ptr->window) window_stuff();
4084 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
4088 p_ptr->redraw |= (PR_MAP);
4090 /* Update monsters */
4091 p_ptr->update |= (PU_MONSTERS);
4094 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4096 world_monster = FALSE;
4097 if (vs_player || los(py, px, m_ptr->fy, m_ptr->fx))
4100 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
4102 msg_print("You feel time flowing around you once more.");
4113 void monster_gain_exp(int m_idx, int s_idx)
4115 monster_type *m_ptr = &m_list[m_idx];
4116 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4117 monster_race *s_ptr = &r_info[s_idx];
4120 if (p_ptr->inside_battle) return;
4122 if (!r_ptr->next_exp) return;
4124 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
4125 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
4126 if (!dun_level) new_exp /= 5;
4127 m_ptr->exp += new_exp;
4128 if (m_ptr->mflag2 & MFLAG_CHAMELEON) return;
4130 if (m_ptr->exp >= r_ptr->next_exp)
4133 int old_hp = m_ptr->hp;
4134 int old_maxhp = m_ptr->max_maxhp;
4135 int old_r_idx = m_ptr->r_idx;
4138 monster_desc(m_name, m_ptr, 0);
4139 m_ptr->r_idx = r_ptr->next_r_idx;
4140 m_ptr->ap_r_idx = m_ptr->r_idx;
4141 r_ptr = &r_info[m_ptr->r_idx];
4142 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
4144 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
4148 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
4150 if (ironman_nightmare)
4152 u32b hp = m_ptr->max_maxhp * 2L;
4154 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
4156 m_ptr->maxhp = m_ptr->max_maxhp;
4157 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
4159 /* Extract the monster base speed */
4160 m_ptr->mspeed = r_ptr->speed;
4162 /* Hack -- small racial variety */
4163 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
4165 /* Allow some small variation per monster */
4167 i = extract_energy[r_ptr->speed] / 3;
4168 if (i) m_ptr->mspeed += rand_spread(0, i);
4171 i = extract_energy[r_ptr->speed] / 10;
4172 if (i) m_ptr->mspeed += rand_spread(0, i);
4176 if (m_ptr->mspeed > 199) m_ptr->mspeed = 199;
4180 if (is_pet(m_ptr) || m_ptr->ml)
4183 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
4185 msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
4187 r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
4189 update_mon(m_idx, FALSE);
4190 lite_spot(m_ptr->fy, m_ptr->fx);
4192 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;