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 (r_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
218 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
220 if (m_ptr->invulner && randint0(PENETRATE_INVULNERABILITY))
225 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
227 msg_format("%^s is unharmed.", m_name);
235 if (r_ptr->flagsr & RFR_RES_ALL)
240 if((dam == 0) && one_in_(3)) dam = 1;
247 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
249 msg_format("%^s is unharmed.", m_name);
260 /* It is dead now... or is it? */
263 if (((r_ptr->flags1 & RF1_UNIQUE) ||
264 (r_ptr->flags7 & RF7_UNIQUE_7) ||
265 (r_ptr->flags1 & RF1_QUESTOR)) &&
266 !p_ptr->inside_battle)
273 if (!monster_living(r_ptr))
284 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
285 /* Unseen death by normal attack */
290 /* Death by special attack */
294 msg_format("%^s%s", m_name, note);
296 msg_format("%^s%s", m_name, note);
300 /* Death by normal attack -- nonliving monster */
301 else if (!monster_living(r_ptr))
304 msg_format("%^s¤ÏÇ˲õ¤µ¤ì¤¿¡£", m_name);
306 msg_format("%^s is destroyed.", m_name);
310 /* Death by normal attack -- living monster */
314 msg_format("%^s¤Ï»¦¤µ¤ì¤¿¡£", m_name);
316 msg_format("%^s is killed.", m_name);
322 monster_gain_exp(who, m_ptr->r_idx);
324 /* Generate treasure */
325 monster_death(m_idx, FALSE);
327 /* Delete the monster */
328 delete_monster_idx(m_idx);
333 /* Monster is dead */
340 /* Mega-Hack -- Pain cancels fear */
341 if (m_ptr->monfear && (dam > 0))
343 int tmp = randint1(dam / 4);
345 /* Cure a little fear */
346 if (tmp < m_ptr->monfear)
349 m_ptr->monfear -= tmp;
352 /* Cure all the fear */
363 /* Sometimes a monster gets scared by damage */
364 if (!m_ptr->monfear && !(r_ptr->flags3 & RF3_NO_FEAR))
368 /* Percentage of fully healthy */
369 percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
372 * Run (sometimes) if at 10% or less of max hit points,
373 * or (usually) when hit for half its current hit points
375 if (((percentage <= 10) && (randint0(10) < percentage)) ||
376 ((dam >= m_ptr->hp) && (randint0(100) < 80)))
378 /* Hack -- note fear */
381 /* XXX XXX XXX Hack -- Add some timed fear */
382 m_ptr->monfear += (randint1(10) +
383 (((dam >= m_ptr->hp) && (percentage > 7)) ?
384 20 : ((11 - percentage) * 5)));
388 #endif /* ALLOW_FEAR */
390 if ((dam > 0) && !is_pet(m_ptr) && !is_friendly(m_ptr) && (who != m_idx))
392 if (is_pet(&m_list[who]) && !player_bold(m_ptr->target_y, m_ptr->target_x))
394 set_target(m_ptr, m_list[who].fy, m_list[who].fx);
398 if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
402 /* Extract monster name */
403 monster_desc(m_name, m_ptr, 0);
405 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
406 if (rakuba((dam > 200) ? 200 : dam, FALSE))
409 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
411 msg_format("You have thrown off from %s!", m_name);
422 * Returns whether a given monster will try to run from the player.
424 * Monsters will attempt to avoid very powerful players. See below.
426 * Because this function is called so often, little details are important
427 * for efficiency. Like not using "mod" or "div" when possible. And
428 * attempting to check the conditions in an optimal order. Note that
429 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.
431 * Note that this function is responsible for about one to five percent
432 * of the processor use in normal conditions...
434 static int mon_will_run(int m_idx)
436 monster_type *m_ptr = &m_list[m_idx];
440 monster_race *r_ptr = &r_info[m_ptr->r_idx];
449 /* Friends can be commanded to avoid the player */
452 /* Are we trying to avoid the player? */
453 return ((p_ptr->pet_follow_distance < 0) &&
454 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
457 /* Keep monsters from running too far away */
458 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
460 /* All "afraid" monsters will run away */
461 if (m_ptr->monfear) return (TRUE);
465 /* Nearby monsters will not become terrified */
466 if (m_ptr->cdis <= 5) return (FALSE);
468 /* Examine player power (level) */
471 /* Examine monster power (level plus morale) */
472 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
474 /* Optimize extreme cases below */
475 if (m_lev > p_lev + 4) return (FALSE);
476 if (m_lev + 4 <= p_lev) return (TRUE);
478 /* Examine player health */
482 /* Examine monster health */
484 m_mhp = m_ptr->maxhp;
486 /* Prepare to optimize the calculation */
487 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
488 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
490 /* Strong players scare strong monsters */
491 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
495 /* Assume no terror */
503 * Search spell castable grid
505 static bool get_moves_aux2(int m_idx, int *yp, int *xp)
507 int i, y, x, y1, x1, best = 999;
510 bool can_open_door = FALSE;
513 monster_type *m_ptr = &m_list[m_idx];
514 monster_race *r_ptr = &r_info[m_ptr->r_idx];
516 /* Monster location */
520 /* Monster can already cast spell to player */
521 if (projectable(y1, x1, py, px)) return (FALSE);
523 /* Set current grid cost */
524 now_cost = cave[y1][x1].cost;
525 if (now_cost == 0) now_cost = 999;
527 /* Can monster bash or open doors? */
528 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
530 can_open_door = TRUE;
533 /* Check nearby grids, diagonals first */
534 for (i = 7; i >= 0; i--)
538 /* Get the location */
542 /* Ignore locations off of edge */
543 if (!in_bounds2(y, x)) continue;
545 /* Simply move to player */
546 if (player_bold(y, x)) return (FALSE);
552 /* Monster cannot kill or pass walls */
553 if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) || (r_ptr->flags2 & RF2_KILL_WALL)))
555 if (cost == 0) continue;
556 if (!can_open_door && is_closed_door(c_ptr->feat)) continue;
559 /* Hack -- for kill or pass wall monster.. */
560 if (cost == 0) cost = 998;
562 if (now_cost < cost) continue;
564 if (!projectable(y, x, py, px)) continue;
566 /* Accept louder sounds */
567 if (best < cost) continue;
570 (*yp) = y1 + ddy_ddd[i];
571 (*xp) = x1 + ddx_ddd[i];
574 /* No legal move (?) */
575 if (best == 999) return (FALSE);
583 * Choose the "best" direction for "flowing"
585 * Note that ghosts and rock-eaters are never allowed to "flow",
586 * since they should move directly towards the player.
588 * Prefer "non-diagonal" directions, but twiddle them a little
589 * to angle slightly towards the player's actual location.
591 * Allow very perceptive monsters to track old "spoor" left by
592 * previous locations occupied by the player. This will tend
593 * to have monsters end up either near the player or on a grid
594 * recently occupied by the player (and left via "teleport").
596 * Note that if "smell" is turned on, all monsters get vicious.
598 * Also note that teleporting away from a location will cause
599 * the monsters who were chasing you to converge on that location
600 * as long as you are still near enough to "annoy" them without
601 * being close enough to chase directly. I have no idea what will
602 * happen if you combine "smell" with low "aaf" values.
604 static bool get_moves_aux(int m_idx, int *yp, int *xp, bool no_flow)
606 int i, y, x, y1, x1, best;
609 bool use_scent = FALSE;
611 monster_type *m_ptr = &m_list[m_idx];
612 monster_race *r_ptr = &r_info[m_ptr->r_idx];
614 /* Can monster cast attack spell? */
615 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
616 r_ptr->flags5 & (RF5_ATTACK_MASK) ||
617 r_ptr->flags6 & (RF6_ATTACK_MASK))
619 /* Can move spell castable grid? */
620 if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
623 /* Monster can't flow */
624 if (no_flow) return (FALSE);
626 /* Monster can go through rocks */
627 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) return (FALSE);
628 if (r_ptr->flags2 & RF2_KILL_WALL) return (FALSE);
629 if (!cave_floor_bold(py, px) && (cave[py][px].feat != FEAT_TREES)) return (FALSE);
631 /* Monster location */
635 /* Hack -- Player can see us, run towards him */
636 if (player_has_los_bold(y1, x1)) return (FALSE);
639 c_ptr = &cave[y1][x1];
641 /* If we can hear noises, advance towards them */
647 /* Otherwise, try to follow a scent trail */
648 else if (c_ptr->when)
651 if (cave[py][px].when - c_ptr->when > 127) return (FALSE);
657 /* Otherwise, advance blindly */
663 /* Check nearby grids, diagonals first */
664 for (i = 7; i >= 0; i--)
666 /* Get the location */
670 /* Ignore locations off of edge */
671 if (!in_bounds2(y, x)) continue;
675 /* We're following a scent trail */
678 int when = c_ptr->when;
680 /* Accept younger scent */
681 if (best > when) continue;
685 /* We're using sound */
690 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
692 else cost = c_ptr->cost;
694 /* Accept louder sounds */
695 if ((cost == 0) || (best < cost)) continue;
699 /* Hack -- Save the "twiddled" location */
700 (*yp) = py + 16 * ddy_ddd[i];
701 (*xp) = px + 16 * ddx_ddd[i];
704 /* No legal move (?) */
705 if (best == 999 || best == 0) return (FALSE);
713 * Provide a location to flee to, but give the player a wide berth.
715 * A monster may wish to flee to a location that is behind the player,
716 * but instead of heading directly for it, the monster should "swerve"
717 * around the player so that he has a smaller chance of getting hit.
719 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
721 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
725 monster_type *m_ptr = &m_list[m_idx];
727 /* Monster location */
731 /* Desired destination */
735 /* Check nearby grids, diagonals first */
736 for (i = 7; i >= 0; i--)
740 /* Get the location */
744 /* Ignore locations off of edge */
745 if (!in_bounds2(y, x)) continue;
747 /* Don't move toward player */
748 /* if (cave[y][x].dist < 3) continue; */ /* Hmm.. Need it? */
750 /* Calculate distance of this grid from our destination */
751 dis = distance(y, x, y1, x1);
753 /* Score this grid */
754 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
756 /* No negative scores */
759 /* Ignore lower scores */
760 if (s < score) continue;
762 /* Save the score and time */
765 /* Save the location */
770 /* No legal move (?) */
771 if (score == -1) return (FALSE);
782 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
785 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
786 * offsets of all the locations with a distance of n from a central point,
787 * with an offset of (0,0) indicating no more offsets at this distance.
789 * This is, of course, fairly unreadable, but it eliminates multiple loops
790 * from the previous version.
792 * It is probably better to replace these arrays with code to compute
793 * the relevant arrays, even if the storage is pre-allocated in hard
794 * coded sizes. At the very least, code should be included which is
795 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
797 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
799 * These arrays could be combined into two big arrays, using sub-arrays
800 * to hold the offsets and lengths of each portion of the sub-arrays, and
801 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
805 static sint d_off_y_0[] =
808 static sint d_off_x_0[] =
812 static sint d_off_y_1[] =
813 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
815 static sint d_off_x_1[] =
816 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
819 static sint d_off_y_2[] =
820 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
822 static sint d_off_x_2[] =
823 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
826 static sint d_off_y_3[] =
827 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
830 static sint d_off_x_3[] =
831 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
835 static sint d_off_y_4[] =
836 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
837 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
839 static sint d_off_x_4[] =
840 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
841 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
844 static sint d_off_y_5[] =
845 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
846 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
849 static sint d_off_x_5[] =
850 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
851 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
855 static sint d_off_y_6[] =
856 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
857 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
860 static sint d_off_x_6[] =
861 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
862 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
863 -3, 2, 3, -1, 0, 1, 0 };
866 static sint d_off_y_7[] =
867 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
868 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
869 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
871 static sint d_off_x_7[] =
872 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
873 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
874 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
878 static sint d_off_y_8[] =
879 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
880 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
881 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
884 static sint d_off_x_8[] =
885 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
886 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
887 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
891 static sint d_off_y_9[] =
892 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
893 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
894 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
895 7, 8, 8, 8, 8, 9, 9, 9, 0 };
897 static sint d_off_x_9[] =
898 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
899 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
900 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
901 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
904 static sint *dist_offsets_y[10] =
906 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
907 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
910 static sint *dist_offsets_x[10] =
912 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
913 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
917 * Choose a "safe" location near a monster for it to run toward.
919 * A location is "safe" if it can be reached quickly and the player
920 * is not able to fire into it (it isn't a "clean shot"). So, this will
921 * cause monsters to "duck" behind walls. Hopefully, monsters will also
922 * try to run towards corridor openings if they are in a room.
924 * This function may take lots of CPU time if lots of monsters are
927 * Return TRUE if a safe location is available.
929 static bool find_safety(int m_idx, int *yp, int *xp)
931 monster_type *m_ptr = &m_list[m_idx];
936 int y, x, dy, dx, d, dis, i;
937 int gy = 0, gx = 0, gdis = 0;
944 /* Start with adjacent locations, spread further */
945 for (d = 1; d < 10; d++)
947 /* Get the lists of points with a distance d from (fx, fy) */
948 y_offsets = dist_offsets_y[d];
949 x_offsets = dist_offsets_x[d];
951 /* Check the locations */
952 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
954 i++, dx = x_offsets[i], dy = y_offsets[i])
959 /* Skip illegal locations */
960 if (!in_bounds(y, x)) continue;
964 /* Skip locations in a wall */
965 if (!cave_floor_grid(c_ptr)) continue;
967 /* Check for "availability" (if monsters can flow) */
968 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
970 /* Ignore grids very far from the player */
971 if (c_ptr->dist == 0) continue;
973 /* Ignore too-distant grids */
974 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
977 /* Check for absence of shot (more or less) */
978 if (!player_has_los_grid(c_ptr))
981 /* Calculate distance from player */
982 dis = distance(y, x, py, px);
984 /* Remember if further than previous */
994 /* Check for success */
1001 /* Found safe place */
1012 * Choose a good hiding place near a monster for it to run toward.
1014 * Pack monsters will use this to "ambush" the player and lure him out
1015 * of corridors into open space so they can swarm him.
1017 * Return TRUE if a good location is available.
1019 static bool find_hiding(int m_idx, int *yp, int *xp)
1021 monster_type *m_ptr = &m_list[m_idx];
1026 int y, x, dy, dx, d, dis, i;
1027 int gy = 0, gx = 0, gdis = 999;
1029 sint *y_offsets, *x_offsets;
1033 /* Start with adjacent locations, spread further */
1034 for (d = 1; d < 10; d++)
1036 /* Get the lists of points with a distance d from (fx, fy) */
1037 y_offsets = dist_offsets_y[d];
1038 x_offsets = dist_offsets_x[d];
1040 /* Check the locations */
1041 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
1043 i++, dx = x_offsets[i], dy = y_offsets[i])
1048 /* Skip illegal locations */
1049 if (!in_bounds(y, x)) continue;
1051 c_ptr = &cave[y][x];
1053 /* Skip occupied locations */
1054 if (!cave_empty_grid(c_ptr)) continue;
1056 /* Check for hidden, available grid */
1057 if (!player_has_los_grid(c_ptr) && clean_shot(fy, fx, y, x, FALSE))
1059 /* Calculate distance from player */
1060 dis = distance(y, x, py, px);
1062 /* Remember if closer than previous */
1063 if (dis < gdis && dis >= 2)
1072 /* Check for success */
1079 /* Found good place */
1090 * Choose "logical" directions for monster movement
1092 static bool get_moves(int m_idx, int *mm)
1094 monster_type *m_ptr = &m_list[m_idx];
1095 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1101 bool will_run = mon_will_run(m_idx);
1103 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1104 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
1106 /* Counter attack to an enemy monster */
1107 if (!will_run && m_ptr->target_y)
1109 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
1111 /* The monster must be an enemy, and in LOS */
1113 are_enemies(m_ptr, &m_list[t_m_idx]) &&
1114 los(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1116 /* Extract the "pseudo-direction" */
1117 y = m_ptr->fy - m_ptr->target_y;
1118 x = m_ptr->fx - m_ptr->target_x;
1123 if (!done && !will_run && is_hostile(m_ptr) &&
1124 (r_ptr->flags1 & RF1_FRIENDS) &&
1125 (los(m_ptr->fy, m_ptr->fx, py, px) ||
1126 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1129 * Animal packs try to get the player out of corridors
1130 * (...unless they can move through walls -- TY)
1132 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1133 !(r_ptr->flags2 & RF2_KILL_WALL))
1137 /* Count room grids next to player */
1138 for (i = 0; i < 8; i++)
1140 int xx = px + ddx_ddd[i];
1141 int yy = py + ddy_ddd[i];
1143 if (!in_bounds2(yy, xx)) continue;
1145 c_ptr = &cave[yy][xx];
1148 if (((cave_floor_grid(c_ptr)) || ((c_ptr->feat & 0x60) == 0x60)) &&
1149 monster_can_cross_terrain(c_ptr->feat, r_ptr))
1151 /* One more room grid */
1155 if (cave[py][px].info & CAVE_ROOM) room -= 2;
1156 if (!r_ptr->flags4 && !r_ptr->flags5 && !r_ptr->flags6) room -= 2;
1158 /* Not in a room and strong player */
1159 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
1160 (p_ptr->mhp + p_ptr->msp))
1162 /* Find hiding place */
1163 if (find_hiding(m_idx, &y, &x)) done = TRUE;
1167 /* Monster groups try to surround the player */
1168 if (!done && (cave[m_ptr->fy][m_ptr->fx].dist < 3))
1172 /* Find an empty square near the player to fill */
1173 for (i = 0; i < 8; i++)
1175 /* Pick squares near player (semi-randomly) */
1176 y2 = py + ddy_ddd[(m_idx + i) & 7];
1177 x2 = px + ddx_ddd[(m_idx + i) & 7];
1179 /* Already there? */
1180 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
1182 /* Attack the player */
1189 if (!in_bounds2(y2, x2)) continue;
1191 /* Ignore filled grids */
1192 c_ptr = &cave[y2][x2];
1193 if (!cave_empty_grid(c_ptr)) continue;
1195 /* Try to fill this hole */
1199 /* Extract the new "pseudo-direction" */
1210 /* Flow towards the player */
1211 (void)get_moves_aux(m_idx, &y2, &x2, no_flow);
1213 /* Extract the "pseudo-direction" */
1220 /* Apply fear if possible and necessary */
1221 if (is_pet(m_ptr) && will_run)
1223 /* XXX XXX Not very "smart" */
1228 if (!done && will_run)
1233 /* Try to find safe place */
1234 if (find_safety(m_idx, &y, &x))
1236 /* Attempt to avoid the player */
1239 /* Adjust movement */
1240 if (get_fear_moves_aux(m_idx, &y, &x)) done = TRUE;
1246 /* This is not a very "smart" method XXX XXX */
1254 /* Check for no move */
1255 if (!x && !y) return (FALSE);
1258 /* Extract the "absolute distances" */
1262 /* Do something weird */
1263 if (y < 0) move_val += 8;
1264 if (x > 0) move_val += 4;
1266 /* Prevent the diamond maneuvre */
1267 if (ay > (ax << 1)) move_val += 2;
1268 else if (ax > (ay << 1)) move_val++;
1270 /* Extract some directions */
1415 /* Wants to move... */
1420 static int check_hit2(int power, int level, int ac, int stun)
1424 /* Percentile dice */
1427 if (stun && one_in_(2)) return FALSE;
1429 /* Hack -- Always miss or hit */
1430 if (k < 10) return (k < 5);
1432 /* Calculate the "attack quality" */
1433 i = (power + (level * 3));
1435 /* Power and Level compete against Armor */
1436 if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
1443 /* Monster attacks monster */
1444 static bool monst_attack_monst(int m_idx, int t_idx)
1446 monster_type *m_ptr = &m_list[m_idx];
1447 monster_type *t_ptr = &m_list[t_idx];
1449 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1450 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1454 char m_name[80], t_name[80];
1456 bool blinked, heal_effect;
1457 bool explode = FALSE, touched = FALSE, fear = FALSE;
1458 int y_saver = t_ptr->fy;
1459 int x_saver = t_ptr->fx;
1461 bool see_m = m_ptr->ml;
1462 bool see_t = t_ptr->ml;
1463 bool see_either = see_m || see_t;
1465 /* Can the player be aware of this attack? */
1466 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1467 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1469 /* Cannot attack self */
1470 if (m_idx == t_idx) return FALSE;
1472 /* Not allowed to attack */
1473 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1475 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1480 /* Extract the effective monster level */
1481 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1483 /* Get the monster name (or "it") */
1484 monster_desc(m_name, m_ptr, 0);
1486 /* Get the monster name (or "it") */
1487 monster_desc(t_name, t_ptr, 0);
1489 /* Assume no blink */
1492 if (!see_either && known)
1497 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
1499 /* Scan through all four blows */
1500 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1502 bool obvious = FALSE;
1509 /* Extract the attack infomation */
1510 int effect = r_ptr->blow[ap_cnt].effect;
1511 int method = r_ptr->blow[ap_cnt].method;
1512 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1513 int d_side = r_ptr->blow[ap_cnt].d_side;
1515 if (!m_ptr->r_idx) break;
1517 /* Stop attacking if the target dies! */
1518 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1521 /* Hack -- no more attacks */
1524 if (blinked) /* Stop! */
1529 if (method == RBM_SHOOT) continue;
1531 /* Extract the attack "power" */
1532 power = mbe_info[effect].power;
1535 if (!effect || check_hit2(power, rlev, ac, m_ptr->stunned))
1540 if (tr_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
1542 /* Describe the attack method */
1548 act = "%s¤ò²¥¤Ã¤¿¡£";
1560 act = "%s¤ò¿¨¤Ã¤¿¡£";
1562 act = "touches %s.";
1572 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1574 act = "punches %s.";
1584 act = "%s¤ò½³¤Ã¤¿¡£";
1596 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1608 act = "%s¤ò³ú¤ó¤À¡£";
1620 act = "%s¤ò»É¤·¤¿¡£";
1632 act = "%s¤ò»Â¤Ã¤¿¡£";
1634 act = "slashes %s.";
1643 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1655 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1657 act = "crushes %s.";
1667 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1669 act = "engulfs %s.";
1679 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1681 act = "charges %s.";
1691 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1693 act = "crawls on %s.";
1703 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1705 act = "drools on %s.";
1715 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1717 act = "spits on %s.";
1726 if (see_either) disturb(1, 0);
1741 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1743 act = "gazes at %s.";
1753 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1755 act = "wails at %s.";
1765 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1767 act = "releases spores at %s.";
1777 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1779 act = "projects XXX4's at %s.";
1789 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1791 act = "begs %s for money.";
1801 act = "%s¤òÉî¿«¤·¤¿¡£";
1803 act = "insults %s.";
1813 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1815 act = "moans at %s.";
1825 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1827 act = "sings to %s.";
1836 if (act && see_either)
1839 if (do_silly_attack) act = silly_attacks2[randint0(MAX_SILLY_ATTACK)];
1840 strfmt(temp, act, t_name);
1841 msg_format("%^s¤Ï%s", m_name, temp);
1843 if (do_silly_attack)
1845 act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
1846 strfmt(temp, "%s %s.", act, t_name);
1848 else strfmt(temp, act, t_name);
1849 msg_format("%^s %s", m_name, temp);
1853 /* Hack -- assume all attacks are obvious */
1856 /* Roll out the damage */
1857 damage = damroll(d_dice, d_side);
1859 /* Assume no healing effect */
1860 heal_effect = FALSE;
1864 /* Apply appropriate damage */
1876 if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13)) {
1877 int tmp_damage = damage-(damage*((ac < 150) ? ac : 150)/250);
1878 damage = MAX(damage, tmp_damage*2);
1884 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1914 if (one_in_(2)) blinked = TRUE;
1961 pt = GF_OLD_SLEEP; /* sort of close... */
1977 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1980 earthquake(m_ptr->fy, m_ptr->fx, 8);
2013 /* Do damage if not exploding */
2016 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
2017 (pt == GF_OLD_SLEEP ? r_ptr->level : damage), pt, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2022 if ((monster_living(tr_ptr)) && (damage > 2))
2024 bool did_heal = FALSE;
2026 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
2029 m_ptr->hp += damroll(4, damage / 6);
2030 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
2032 /* Redraw (later) if needed */
2033 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2034 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2036 /* Special message */
2037 if (see_m && did_heal)
2040 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
2042 msg_format("%^s appears healthier.", m_name);
2052 if ((tr_ptr->flags2 & RF2_AURA_FIRE) && m_ptr->r_idx)
2054 if (!(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
2060 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2062 msg_format("%^s is suddenly very hot!", m_name);
2065 if (see_t && is_original_ap(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2067 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2068 damroll (1 + ((tr_ptr->level) / 26),
2069 1 + ((tr_ptr->level) / 17)),
2070 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2074 if (see_m && is_original_ap(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
2079 if ((tr_ptr->flags3 & RF3_AURA_COLD) && m_ptr->r_idx)
2081 if (!(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK))
2087 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2089 msg_format("%^s is suddenly very cold!", m_name);
2092 if (see_t && is_original_ap(t_ptr)) tr_ptr->r_flags3 |= RF3_AURA_COLD;
2094 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2095 damroll (1 + ((tr_ptr->level) / 26),
2096 1 + ((tr_ptr->level) / 17)),
2097 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2101 if (see_m && is_original_ap(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
2106 if ((tr_ptr->flags2 & RF2_AURA_ELEC) && m_ptr->r_idx)
2108 if (!(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK))
2114 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2116 msg_format("%^s gets zapped!", m_name);
2119 if (see_t && is_original_ap(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_ELEC;
2121 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2122 damroll (1 + ((tr_ptr->level) / 26),
2123 1 + ((tr_ptr->level) / 17)),
2124 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER, -1);
2128 if (see_m && is_original_ap(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
2135 /* Monster missed player */
2138 /* Analyze failed attacks */
2157 if (tr_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
2159 /* Visible monsters */
2164 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2166 msg_format("%^s misses %s.", m_name, t_name);
2177 /* Analyze "visible" monsters only */
2178 if (see_m && !do_silly_attack)
2180 /* Count "obvious" attacks (and ones that cause damage) */
2181 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2183 /* Count attacks of this type */
2184 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2186 r_ptr->r_blows[ap_cnt]++;
2194 sound(SOUND_EXPLODE);
2196 /* Cancel Invulnerability */
2197 if (m_ptr->invulner) m_ptr->invulner = 0;
2200 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2202 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2216 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2218 msg_print("The thief flees laughing!");
2227 teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE);
2237 * The monster is known to be within 100 grids of the player
2239 * In several cases, we directly update the monster lore
2241 * Note that a monster is only allowed to "reproduce" if there
2242 * are a limited number of "reproducing" monsters on the current
2243 * level. This should prevent the level from being "swamped" by
2244 * reproducing monsters. It also allows a large mass of mice to
2245 * prevent a louse from multiplying, but this is a small price to
2246 * pay for a simple multiplication method.
2248 * XXX Monster fear is slightly odd, in particular, monsters will
2249 * fixate on opening a door even if they cannot open it. Actually,
2250 * the same thing happens to normal monsters when they hit a door
2252 * XXX XXX XXX In addition, monsters which *cannot* open or bash
2253 * down a door will still stand there trying to open it...
2255 * XXX Technically, need to check for monster in the way
2256 * combined with that monster being in a wall (or door?)
2258 * A "direction" of "5" means "pick a random direction".
2260 static void process_monster(int m_idx)
2262 monster_type *m_ptr = &m_list[m_idx];
2263 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2264 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2266 int i, d, oy, ox, ny, nx;
2272 monster_type *y_ptr;
2285 bool gets_angry = FALSE;
2291 if ((m_idx == p_ptr->riding) && !(r_ptr->flags7 & RF7_RIDING))
2293 if (rakuba(0, TRUE))
2296 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2299 monster_desc(m_name, &m_list[p_ptr->riding], 0);
2300 msg_format("You have fallen from %s.", m_name);
2305 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !m_ptr->csleep)
2307 choose_new_monster(m_idx, FALSE, 0);
2308 r_ptr = &r_info[m_ptr->r_idx];
2311 /* Players hidden in shadow are almost imperceptable. -LM- */
2312 if (p_ptr->special_defense & NINJA_S_STEALTH)
2314 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
2315 if (p_ptr->monlite) tmp /= 3;
2316 if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
2317 if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
2318 /* Low-level monsters will find it difficult to locate the player. */
2319 if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
2322 /* Quantum monsters are odd */
2323 if (r_ptr->flags2 & (RF2_QUANTUM))
2325 /* Sometimes skip move */
2326 if (!randint0(2)) return;
2329 if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2333 if (is_pet(m_ptr) && !(m_ptr->ml))
2340 /* Acquire the monster name */
2341 monster_desc(m_name, m_ptr, 0);
2345 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2347 msg_format("%^s disappears!", m_name);
2352 /* Generate treasure, etc */
2353 monster_death(m_idx, FALSE);
2355 /* Delete the monster */
2356 delete_monster_idx(m_idx);
2361 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2363 msg_print("You feel sad for a moment.");
2372 if (m_ptr->r_idx == MON_SHURYUUDAN)
2374 mon_take_hit_mon(m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2376 mon_take_hit_mon(m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2379 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) && !p_ptr->inside_battle)
2381 static int riding_pinch = 0;
2383 if (m_ptr->hp < m_ptr->maxhp/3)
2386 monster_desc(m_name, m_ptr, 0);
2388 if (m_idx == p_ptr->riding && riding_pinch < 2)
2391 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2393 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
2400 if (m_idx == p_ptr->riding)
2403 msg_format("%s¤Ï¤¢¤Ê¤¿¤Î«Çû¤«¤éæ½Ð¤·¤¿¡£", m_name);
2405 msg_format("%^s succeeded to escape from your restriction!", m_name);
2407 if (rakuba(-1, FALSE))
2410 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2412 msg_print("You have fallen from riding pet.");
2419 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))
2422 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2424 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2428 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2429 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2431 msg_format("%^s read a scroll of teleport level.", m_name);
2432 msg_format("%^s disappears.", m_name);
2436 if (m_idx == p_ptr->riding && rakuba(-1, FALSE))
2439 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2441 msg_print("You have fallen from riding pet.");
2445 /* Check for quest completion */
2446 check_quest_completion(m_ptr);
2448 delete_monster_idx(m_idx);
2455 /* Reset the counter */
2456 if (m_idx == p_ptr->riding) riding_pinch = 0;
2460 /* Handle "sleep" - Still sleeping */
2461 if (m_ptr->csleep) return;
2466 /* Sometimes skip move */
2467 if (one_in_(2)) return;
2470 if (p_ptr->riding == m_idx)
2472 p_ptr->update |= (PU_BONUS);
2475 /* No one wants to be your friend if you're aggravating */
2476 if (is_friendly(m_ptr) && (p_ptr->cursed & TRC_AGGRAVATE))
2479 /* Paranoia... no pet uniques outside wizard mode -- TY */
2480 if (is_pet(m_ptr) &&
2481 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
2482 monster_has_hostile_align(NULL, 10, -10, r_ptr))
2483 || (r_ptr->flagsr & RFR_RES_ALL)))
2488 if (p_ptr->inside_battle) gets_angry = FALSE;
2493 monster_desc(m_name, m_ptr, 0);
2495 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2497 msg_format("%^s suddenly becomes hostile!", m_name);
2503 /* Get the origin */
2508 /* Attempt to "multiply" if able and allowed */
2509 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2513 /* Count the adjacent monsters */
2514 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2516 for (x = ox - 1; x <= ox + 1; x++)
2518 /* Ignore locations off of edge */
2519 if (!in_bounds2(y, x)) continue;
2521 if (cave[y][x].m_idx) k++;
2525 /* Hack -- multiply slower in crowded areas */
2526 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2528 /* Try to multiply */
2529 if (multiply_monster(m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
2531 /* Take note if visible */
2532 if (m_ptr->ml && m_list[hack_m_idx_ii].ml && is_original_ap(m_ptr))
2534 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2537 /* Multiplying takes energy */
2544 if (r_ptr->flags6 & RF6_SPECIAL)
2546 /* Hack -- Ohmu scatters molds! */
2547 if (m_ptr->r_idx == MON_OHMU)
2549 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
2551 if (r_ptr->freq_spell && (randint1(100) <= r_ptr->freq_spell))
2554 int rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
2555 u32b p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
2557 for (k = 0; k < 6; k++)
2559 if (summon_specific(m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_BIZARRE1, (PM_ALLOW_GROUP | p_mode)))
2561 if (m_list[hack_m_idx_ii].ml) count++;
2565 if (count && m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
2572 if (!p_ptr->inside_battle)
2574 /* Hack! "Cyber" monster makes noise... */
2575 if (m_ptr->ap_r_idx == MON_CYBER &&
2576 one_in_(CYBERNOISE) &&
2577 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2579 if (disturb_minor) disturb(FALSE, FALSE);
2581 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2583 msg_print("You hear heavy steps.");
2588 /* Some monsters can speak */
2589 if ((ap_r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2590 one_in_(SPEAK_CHANCE) &&
2591 player_has_los_bold(oy, ox))
2594 char monmessage[1024];
2597 /* Acquire the monster name/poss */
2599 monster_desc(m_name, m_ptr, 0);
2602 strcpy(m_name, "¤½¤ì");
2604 strcpy(m_name, "It");
2608 /* Select the file for monster quotes */
2611 filename = "monfear_j.txt";
2613 filename = "monfear.txt";
2616 else if (is_pet(m_ptr))
2618 filename = "monpet_j.txt";
2620 filename = "monpet.txt";
2623 else if (is_friendly(m_ptr))
2625 filename = "monfrien_j.txt";
2627 filename = "monfrien.txt";
2632 filename = "monspeak_j.txt";
2634 filename = "monspeak.txt";
2638 /* Get the monster line */
2639 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
2643 msg_format("%^s%s", m_name, monmessage);
2645 msg_format("%^s %s", m_name, monmessage);
2652 /* Try to cast spell occasionally */
2653 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
2655 bool counterattack = FALSE;
2657 /* Give priority to counter attack? */
2658 if (m_ptr->target_y)
2660 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
2662 /* The monster must be an enemy, and projectable */
2664 are_enemies(m_ptr, &m_list[t_m_idx]) &&
2665 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
2667 counterattack = TRUE;
2673 /* Attempt to cast a spell */
2674 if (aware && make_attack_spell(m_idx)) return;
2677 * Attempt to cast a spell at an enemy other than the player
2678 * (may slow the game a smidgeon, but I haven't noticed.)
2680 if (monst_spell_monst(m_idx)) return;
2684 /* Attempt to do counter attack at first */
2685 if (monst_spell_monst(m_idx)) return;
2687 if (aware && make_attack_spell(m_idx)) return;
2691 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
2693 /* Hack -- Assume no movement */
2694 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2695 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2698 /* Confused -- 100% random */
2699 if (m_ptr->confused || !aware)
2701 /* Try four "random" directions */
2702 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2705 /* 75% random movement */
2706 else if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) &&
2707 (randint0(100) < 75))
2709 /* Memorize flags */
2710 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
2712 /* Try four "random" directions */
2713 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2716 /* 50% random movement */
2717 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2718 (randint0(100) < 50))
2720 /* Memorize flags */
2721 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
2723 /* Try four "random" directions */
2724 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2727 /* 25% random movement */
2728 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2729 (randint0(100) < 25))
2731 /* Memorize flags */
2732 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
2734 /* Try four "random" directions */
2735 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2738 /* Can't reach player - find something else to hit */
2739 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2741 /* Try four "random" directions */
2742 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2744 /* Look for an enemy */
2745 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2746 get_enemy_dir(m_idx, mm);
2750 /* Pets will follow the player */
2751 else if (is_pet(m_ptr))
2753 /* Are we trying to avoid the player? */
2754 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
2755 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2757 /* Do we want to find the player? */
2758 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2760 /* Should we find the player if we can't find a monster? */
2761 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2763 /* by default, move randomly */
2764 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2766 /* Look for an enemy */
2767 if (!get_enemy_dir(m_idx, mm))
2769 /* Find the player if necessary */
2770 if (avoid || lonely || distant)
2772 /* Remember the leash length */
2773 int dis = p_ptr->pet_follow_distance;
2775 /* Hack -- adjust follow distance temporarily */
2776 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2778 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2781 /* Find the player */
2782 get_moves(m_idx, mm);
2784 /* Restore the leash */
2785 p_ptr->pet_follow_distance = dis;
2790 /* Friendly monster movement */
2791 else if (!is_hostile(m_ptr))
2793 /* by default, move randomly */
2794 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2796 /* Look for an enemy */
2797 get_enemy_dir(m_idx, mm);
2799 /* Normal movement */
2802 /* Logical moves, may do nothing */
2803 if (!get_moves(m_idx, mm)) return;
2806 /* Assume nothing */
2811 /* Assume nothing */
2812 did_open_door = FALSE;
2813 did_bash_door = FALSE;
2814 did_take_item = FALSE;
2815 did_kill_item = FALSE;
2816 did_move_body = FALSE;
2817 did_pass_wall = FALSE;
2818 did_kill_wall = FALSE;
2821 /* Take a zero-terminated array of "directions" */
2822 for (i = 0; mm[i]; i++)
2824 /* Get the direction */
2827 /* Hack -- allow "randomized" motion */
2828 if (d == 5) d = ddd[randint0(8)];
2830 /* Get the destination */
2834 /* Ignore locations off of edge */
2835 if (!in_bounds2(ny, nx)) continue;
2837 /* Access that cave grid */
2838 c_ptr = &cave[ny][nx];
2840 /* Access that cave grid's contents */
2841 y_ptr = &m_list[c_ptr->m_idx];
2843 /* Floor is open? */
2844 if (cave_floor_grid(c_ptr))
2846 /* Go ahead and move */
2850 /* Hack -- player 'in' wall */
2851 else if (player_bold(ny, nx))
2856 else if (c_ptr->m_idx)
2858 /* Possibly a monster to attack */
2862 /* Permanent wall */
2863 else if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
2864 (c_ptr->feat <= FEAT_PERM_SOLID))
2869 /* Hack -- semi-transparent terrains are no obstacle */
2870 else if (c_ptr->feat == FEAT_TREES)
2875 /* Hack -- semi-transparent terrains are no obstacle */
2876 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)))))
2882 /* Monster moves through walls (and doors) */
2883 else if (can_pass_wall)
2885 /* Pass through walls/doors/rubble */
2888 /* Monster went through a wall */
2889 did_pass_wall = TRUE;
2892 /* Monster destroys walls (and doors) */
2893 else if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))
2895 /* Eat through walls/doors/rubble */
2898 /* Monster destroyed a wall */
2899 did_kill_wall = TRUE;
2901 if (one_in_(GRINDNOISE))
2904 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
2906 msg_print("There is a grinding sound.");
2911 /* Forget the wall */
2912 c_ptr->info &= ~(CAVE_MARK);
2915 cave_set_feat(ny, nx, floor_type[randint0(100)]);
2917 /* Note changes to viewable region */
2918 if (player_has_los_bold(ny, nx)) do_view = TRUE;
2921 /* Handle doors and secret doors */
2922 else if (is_closed_door(c_ptr->feat))
2924 bool may_bash = TRUE;
2926 /* Assume no move allowed */
2929 /* Creature can open doors. */
2930 if ((r_ptr->flags2 & RF2_OPEN_DOOR) &&
2931 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2934 if (c_ptr->feat == FEAT_DOOR_HEAD)
2936 /* The door is open */
2937 did_open_door = TRUE;
2939 /* Do not bash the door */
2942 /* Assume no move allowed */
2946 /* Locked doors (not jammed) */
2947 else if (c_ptr->feat < FEAT_DOOR_HEAD + 0x08)
2952 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
2954 /* Try to unlock it XXX XXX XXX */
2955 if (randint0(m_ptr->hp / 10) > k)
2957 /* Unlock the door */
2958 cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00);
2960 /* Do not bash the door */
2966 /* Stuck doors -- attempt to bash them down if allowed */
2967 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) &&
2968 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2973 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
2975 /* Attempt to Bash XXX XXX XXX */
2976 if (randint0(m_ptr->hp / 10) > k)
2980 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
2982 msg_print("You hear a door burst open!");
2986 /* Disturb (sometimes) */
2987 if (disturb_minor) disturb(0, 0);
2989 /* The door was bashed open */
2990 did_bash_door = TRUE;
2992 /* Hack -- fall into doorway */
2998 /* Deal with doors in the way */
2999 if (did_open_door || did_bash_door)
3001 /* Break down the door */
3002 if (did_bash_door && (randint0(100) < 50))
3004 cave_set_feat(ny, nx, FEAT_BROKEN);
3010 cave_set_feat(ny, nx, FEAT_OPEN);
3013 /* Handle viewable doors */
3014 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3018 /* Hack -- check for Glyph of Warding */
3019 if (do_move && is_glyph_grid(c_ptr) &&
3020 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3022 /* Assume no move allowed */
3025 /* Break the ward */
3026 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
3028 /* Describe observable breakage */
3029 if (c_ptr->info & CAVE_MARK)
3032 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3034 msg_print("The rune of protection is broken!");
3039 /* Forget the rune */
3040 c_ptr->info &= ~(CAVE_MARK);
3042 /* Break the rune */
3043 c_ptr->info &= ~(CAVE_OBJECT);
3046 /* Allow movement */
3053 else if (do_move && is_explosive_rune_grid(c_ptr) &&
3054 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3056 /* Assume no move allowed */
3059 /* Break the ward */
3062 /* Break the ward */
3063 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3065 /* Describe observable breakage */
3066 if (c_ptr->info & CAVE_MARK)
3069 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3071 msg_print("The rune explodes!");
3074 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);
3080 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3082 msg_print("An explosive rune was disarmed.");
3086 /* Forget the rune */
3087 c_ptr->info &= ~(CAVE_MARK);
3089 /* Break the rune */
3090 c_ptr->info &= ~(CAVE_OBJECT);
3096 if (!m_ptr->r_idx) return;
3097 /* Allow movement */
3102 /* The player is in the way */
3103 if (do_move && player_bold(ny, nx))
3105 /* Some monsters never attack */
3106 if (r_ptr->flags1 & RF1_NEVER_BLOW)
3108 /* Hack -- memorize lack of attacks */
3109 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3115 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
3116 if (do_move && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3118 if (!m_ptr->confused)
3120 if (!(r_ptr->flags2 & RF2_STUPID)) do_move = FALSE;
3123 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
3128 /* The player is in the way. Attack him. */
3131 if (!p_ptr->riding || one_in_(2))
3134 (void)make_attack_normal(m_idx);
3144 if ((c_ptr->feat >= FEAT_PATTERN_START) &&
3145 (c_ptr->feat <= FEAT_PATTERN_XTRA2) &&
3146 !do_turn && !(r_ptr->flags7 & RF7_CAN_FLY))
3152 /* A monster is in the way */
3153 if (do_move && c_ptr->m_idx)
3155 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3157 /* Assume no movement */
3160 /* Attack 'enemies' */
3161 if (((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW) &&
3162 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3163 cave_floor_grid(c_ptr) &&
3164 (c_ptr->m_idx != p_ptr->riding)) ||
3165 are_enemies(m_ptr, y_ptr) || m_ptr->confused)
3169 if (!(r_ptr->flags1 & RF1_NEVER_BLOW))
3171 if (r_ptr->flags2 & RF2_KILL_BODY)
3173 if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3177 if (y_ptr->r_idx && (y_ptr->hp >= 0))
3179 if (monst_attack_monst(m_idx, c_ptr->m_idx)) return;
3181 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
3182 else if (d_info[dungeon_type].flags1 & DF1_NO_MELEE)
3184 if (m_ptr->confused) return;
3185 else if (r_ptr->flags2 & RF2_STUPID)
3187 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
3195 /* Push past weaker monsters (unless leaving a wall) */
3196 else if ((r_ptr->flags2 & RF2_MOVE_BODY) &&
3197 (r_ptr->mexp > z_ptr->mexp) && cave_floor_grid(c_ptr) &&
3198 (cave_floor_grid(&cave[m_ptr->fy][m_ptr->fx])) &&
3199 (c_ptr->m_idx != p_ptr->riding))
3201 /* Allow movement */
3204 /* Monster pushed past another monster */
3205 did_move_body = TRUE;
3207 /* XXX XXX XXX Message */
3212 * Check if monster can cross terrain
3213 * This is checked after the normal attacks
3214 * to allow monsters to attack an enemy,
3215 * even if it can't enter the terrain.
3217 if (do_move && !monster_can_cross_terrain(c_ptr->feat, r_ptr))
3219 /* Assume no move allowed */
3223 /* Some monsters never move */
3224 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3226 /* Hack -- memorize lack of attacks */
3227 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3233 if (m_idx == p_ptr->riding)
3235 if (!p_ptr->riding_ryoute && !(m_list[p_ptr->riding].monfear)) do_move = FALSE;
3238 /* Creature has been allowed move */
3241 s16b this_o_idx, next_o_idx;
3246 /* Hack -- Update the old location */
3247 cave[oy][ox].m_idx = c_ptr->m_idx;
3249 if (c_ptr->feat == FEAT_TREES)
3251 if (r_ptr->flags2 & RF2_KILL_WALL)
3253 cave_set_feat(ny, nx, FEAT_GRASS);
3256 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3258 m_ptr->energy_need += ENERGY_NEED();
3262 /* Mega-Hack -- move the old monster, if any */
3265 /* Move the old monster */
3269 /* Update the old monster */
3270 update_mon(c_ptr->m_idx, TRUE);
3272 /* Wake up the moved monster */
3275 if (r_info[y_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
3278 /* Hack -- Update the new location */
3279 c_ptr->m_idx = m_idx;
3281 /* Move the monster */
3285 /* Update the monster */
3286 update_mon(m_idx, TRUE);
3288 if (p_ptr->riding == m_idx)
3294 /* Redraw the old grid */
3297 /* Redraw the new grid */
3300 if (p_ptr->riding == m_idx)
3305 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
3307 /* Update the monsters */
3308 p_ptr->update |= (PU_DISTANCE);
3310 /* Update sub-windows */
3311 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3314 /* Possible disturb */
3317 (disturb_near && (m_ptr->mflag & MFLAG_VIEW)) ||
3318 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)))
3321 if (is_hostile(m_ptr))
3325 /* Scan all objects in the grid */
3326 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3330 /* Acquire object */
3331 o_ptr = &o_list[this_o_idx];
3333 /* Acquire next object */
3334 next_o_idx = o_ptr->next_o_idx;
3337 if (o_ptr->tval == TV_GOLD) continue;
3340 * Skip "real" corpses and statues, to avoid extreme
3341 * silliness like a novice rogue pockets full of statues
3344 if ((o_ptr->tval == TV_CORPSE) ||
3345 (o_ptr->tval == TV_STATUE)) continue;
3347 /* Take or Kill objects on the floor */
3348 if ((r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3349 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)))
3351 u32b flgs[TR_FLAG_SIZE];
3357 char o_name[MAX_NLEN];
3359 /* Extract some flags */
3360 object_flags(o_ptr, flgs);
3362 /* Acquire the object name */
3363 object_desc(o_name, o_ptr, TRUE, 3);
3365 /* Acquire the monster name */
3366 monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
3368 /* React to objects that hurt the monster */
3369 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
3370 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
3371 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
3372 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
3373 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
3374 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
3375 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
3376 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
3377 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
3378 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
3379 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
3380 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
3381 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
3382 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
3383 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
3384 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
3385 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
3386 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
3388 /* The object cannot be picked up by the monster */
3389 if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
3392 /* Only give a message for "take_item" */
3393 if ((r_ptr->flags2 & (RF2_TAKE_ITEM)) && (r_ptr->flags2 & (RF2_STUPID)))
3396 did_take_item = TRUE;
3398 /* Describe observable situations */
3399 if (m_ptr->ml && player_can_see_bold(ny, nx))
3401 /* Dump a message */
3403 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£", m_name, o_name);
3405 msg_format("%^s tries to pick up %s, but fails.", m_name, o_name);
3411 /* Pick up the item */
3412 else if (r_ptr->flags2 & RF2_TAKE_ITEM)
3415 did_take_item = TRUE;
3417 /* Describe observable situations */
3418 if (player_can_see_bold(ny, nx))
3420 /* Dump a message */
3422 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3424 msg_format("%^s picks up %s.", m_name, o_name);
3429 /* Excise the object */
3430 excise_object_idx(this_o_idx);
3435 /* Forget location */
3436 o_ptr->iy = o_ptr->ix = 0;
3438 /* Memorize monster */
3439 o_ptr->held_m_idx = m_idx;
3442 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3445 m_ptr->hold_o_idx = this_o_idx;
3448 /* Destroy the item if not a pet */
3449 else if (!is_pet(m_ptr))
3452 did_kill_item = TRUE;
3454 /* Describe observable situations */
3455 if (player_has_los_bold(ny, nx))
3457 /* Dump a message */
3459 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3461 msg_format("%^s destroys %s.", m_name, o_name);
3466 /* Delete the object */
3467 delete_object_idx(this_o_idx);
3473 /* Stop when done */
3478 * Forward movements failed, but now received LOS attack!
3479 * Try to flow by smell.
3481 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3482 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3484 /* If we haven't done anything, try casting a spell again */
3485 if (!do_turn && !do_move && !m_ptr->monfear && !(p_ptr->riding == m_idx) && aware)
3487 /* Try to cast spell again */
3488 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
3490 if (make_attack_spell(m_idx)) return;
3495 /* Notice changes in view */
3498 /* Update some things */
3499 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
3502 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3505 /* Notice changes in view */
3506 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
3507 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !p_ptr->inside_battle)))
3509 /* Update some things */
3510 p_ptr->update |= (PU_MON_LITE);
3513 /* Learn things from observable monster */
3514 if (m_ptr->ml && is_original_ap(m_ptr))
3516 /* Monster opened a door */
3517 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3519 /* Monster bashed a door */
3520 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3522 /* Monster tried to pick something up */
3523 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3525 /* Monster tried to crush something */
3526 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3528 /* Monster pushed past another monster */
3529 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3531 /* Monster passed through a wall */
3532 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3534 /* Monster destroyed a wall */
3535 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3539 /* Hack -- get "bold" if out of options */
3540 if (!do_turn && !do_move && m_ptr->monfear && aware)
3542 /* No longer afraid */
3545 /* Message if seen */
3550 /* Acquire the monster name */
3551 monster_desc(m_name, m_ptr, 0);
3553 /* Dump a message */
3555 msg_format("%^s¤ÏÀ襤¤ò·è°Õ¤·¤¿¡ª", m_name);
3557 msg_format("%^s turns to fight!", m_name);
3560 /* Redraw (later) if needed */
3561 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
3563 chg_virtue(V_COMPASSION, -1);
3566 /* XXX XXX XXX Actually do something now (?) */
3571 * Process all the "live" monsters, once per game turn.
3573 * During each game turn, we scan through the list of all the "live" monsters,
3574 * (backwards, so we can excise any "freshly dead" monsters), energizing each
3575 * monster, and allowing fully energized monsters to move, attack, pass, etc.
3577 * Note that monsters can never move in the monster array (except when the
3578 * "compact_monsters()" function is called by "dungeon()" or "save_player()").
3580 * This function is responsible for at least half of the processor time
3581 * on a normal system with a "normal" amount of monsters and a player doing
3584 * When the player is resting, virtually 90% of the processor time is spent
3585 * in this function, and its children, "process_monster()" and "make_move()".
3587 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",
3588 * especially when the player is running.
3590 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"
3591 * monsters while they are still being "born". A monster is "fresh" only
3592 * during the turn in which it is created, and we use the "hack_m_idx" to
3593 * determine if the monster is yet to be processed during the current turn.
3595 * Note the special "MFLAG_NICE" flag, which allows the player to get one
3596 * move before any "nasty" monsters get to use their spell attacks.
3598 * Note that when the "knowledge" about the currently tracked monster
3599 * changes (flags, attacks, spells), we induce a redraw of the monster
3602 void process_monsters(void)
3609 monster_type *m_ptr;
3610 monster_race *r_ptr;
3612 int old_monster_race_idx;
3614 u32b old_r_flags1 = 0L;
3615 u32b old_r_flags2 = 0L;
3616 u32b old_r_flags3 = 0L;
3617 u32b old_r_flags4 = 0L;
3618 u32b old_r_flags5 = 0L;
3619 u32b old_r_flags6 = 0L;
3620 u32b old_r_flagsr = 0L;
3622 byte old_r_blows0 = 0;
3623 byte old_r_blows1 = 0;
3624 byte old_r_blows2 = 0;
3625 byte old_r_blows3 = 0;
3627 byte old_r_cast_spell = 0;
3631 /* Clear monster fighting indicator */
3634 /* Memorize old race */
3635 old_monster_race_idx = p_ptr->monster_race_idx;
3637 /* Acquire knowledge */
3638 if (p_ptr->monster_race_idx)
3640 /* Acquire current monster */
3641 r_ptr = &r_info[p_ptr->monster_race_idx];
3643 /* Memorize flags */
3644 old_r_flags1 = r_ptr->r_flags1;
3645 old_r_flags2 = r_ptr->r_flags2;
3646 old_r_flags3 = r_ptr->r_flags3;
3647 old_r_flags4 = r_ptr->r_flags4;
3648 old_r_flags5 = r_ptr->r_flags5;
3649 old_r_flags6 = r_ptr->r_flags6;
3650 old_r_flagsr = r_ptr->r_flagsr;
3652 /* Memorize blows */
3653 old_r_blows0 = r_ptr->r_blows[0];
3654 old_r_blows1 = r_ptr->r_blows[1];
3655 old_r_blows2 = r_ptr->r_blows[2];
3656 old_r_blows3 = r_ptr->r_blows[3];
3658 /* Memorize castings */
3659 old_r_cast_spell = r_ptr->r_cast_spell;
3663 /* Process the monsters (backwards) */
3664 for (i = m_max - 1; i >= 1; i--)
3666 /* Access the monster */
3668 r_ptr = &r_info[m_ptr->r_idx];
3670 /* Handle "leaving" */
3671 if (p_ptr->leaving) break;
3673 /* Ignore "dead" monsters */
3674 if (!m_ptr->r_idx) continue;
3676 if (p_ptr->wild_mode) continue;
3679 /* Handle "fresh" monsters */
3680 if (m_ptr->mflag & MFLAG_BORN)
3682 /* No longer "fresh" */
3683 m_ptr->mflag &= ~(MFLAG_BORN);
3689 /* Hack -- Require proximity */
3690 if (m_ptr->cdis >= AAF_LIMIT) continue;
3693 /* Access the location */
3697 /* Flow by smell is allowed */
3698 if (!p_ptr->no_flowed)
3700 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3703 /* Assume no move */
3706 /* Handle "sensing radius" */
3707 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
3709 /* We can "sense" the player */
3713 /* Handle "sight" and "aggravation" */
3714 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3715 (player_has_los_bold(fy, fx) || (p_ptr->cursed & TRC_AGGRAVATE)))
3717 /* We can "see" or "feel" the player */
3721 #if 0 /* (cave[py][px].when == cave[fy][fx].when) is always FALSE... */
3722 /* Hack -- Monsters can "smell" the player from far away */
3723 /* Note that most monsters have "aaf" of "20" or so */
3724 else if (!(m_ptr->mflag2 & MFLAG2_NOFLOW) &&
3725 (cave_floor_bold(py, px) || (cave[py][px].feat == FEAT_TREES)) &&
3726 (cave[py][px].when == cave[fy][fx].when) &&
3727 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3728 (cave[fy][fx].dist < r_ptr->aaf))
3730 /* We can "smell" the player */
3734 else if (m_ptr->target_y) test = TRUE;
3737 if (!test) continue;
3740 if (p_ptr->riding == i)
3741 speed = p_ptr->pspeed;
3744 speed = m_ptr->mspeed;
3746 /* Monsters move quickly in Nightmare mode */
3747 if (ironman_nightmare) speed += 5;
3749 if (m_ptr->fast) speed += 10;
3750 if (m_ptr->slow) speed -= 10;
3753 /* Give this monster some energy */
3754 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
3756 /* Not enough energy to move */
3757 if (m_ptr->energy_need > 0) continue;
3759 /* Use up "some" energy */
3760 m_ptr->energy_need += ENERGY_NEED();
3763 /* Save global index */
3766 /* Process the monster */
3769 reset_target(m_ptr);
3771 /* Give up flow_by_smell when it might useless */
3772 if (p_ptr->no_flowed && one_in_(3))
3773 m_ptr->mflag2 |= MFLAG2_NOFLOW;
3775 /* Hack -- notice death or departure */
3776 if (!p_ptr->playing || p_ptr->is_dead) break;
3778 /* Notice leaving */
3779 if (p_ptr->leaving) break;
3782 /* Reset global index */
3786 /* Tracking a monster race (the same one we were before) */
3787 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3789 /* Acquire monster race */
3790 r_ptr = &r_info[p_ptr->monster_race_idx];
3792 /* Check for knowledge change */
3793 if ((old_r_flags1 != r_ptr->r_flags1) ||
3794 (old_r_flags2 != r_ptr->r_flags2) ||
3795 (old_r_flags3 != r_ptr->r_flags3) ||
3796 (old_r_flags4 != r_ptr->r_flags4) ||
3797 (old_r_flags5 != r_ptr->r_flags5) ||
3798 (old_r_flags6 != r_ptr->r_flags6) ||
3799 (old_r_flagsr != r_ptr->r_flagsr) ||
3800 (old_r_blows0 != r_ptr->r_blows[0]) ||
3801 (old_r_blows1 != r_ptr->r_blows[1]) ||
3802 (old_r_blows2 != r_ptr->r_blows[2]) ||
3803 (old_r_blows3 != r_ptr->r_blows[3]) ||
3804 (old_r_cast_spell != r_ptr->r_cast_spell))
3807 p_ptr->window |= (PW_MONSTER);
3814 bool process_the_world(int num, int who, bool vs_player)
3816 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
3818 if(world_monster) return (FALSE);
3823 monster_desc(m_name, m_ptr, 0);
3827 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
3829 msg_format("%s yells 'The World! Time has stopped!'", m_name);
3833 msg_print("¡Ö»þ¤è¡ª¡×");
3835 msg_format("%s yells 'Time!'", m_name);
3837 else msg_print("hek!");
3842 world_monster = TRUE;
3844 if (vs_player) do_cmd_redraw();
3848 if(!m_ptr->r_idx) break;
3849 process_monster(hack_m_idx);
3851 reset_target(m_ptr);
3854 if (p_ptr->notice) notice_stuff();
3857 if (p_ptr->update) update_stuff();
3860 if (p_ptr->redraw) redraw_stuff();
3863 if (p_ptr->window) window_stuff();
3866 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
3870 p_ptr->redraw |= (PR_MAP);
3872 /* Update monsters */
3873 p_ptr->update |= (PU_MONSTERS);
3876 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3878 world_monster = FALSE;
3879 if (vs_player || los(py, px, m_ptr->fy, m_ptr->fx))
3882 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
3884 msg_print("You feel time flowing around you once more.");
3895 void monster_gain_exp(int m_idx, int s_idx)
3897 monster_type *m_ptr = &m_list[m_idx];
3898 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3899 monster_race *s_ptr = &r_info[s_idx];
3902 if (p_ptr->inside_battle) return;
3904 if (!r_ptr->next_exp) return;
3906 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
3907 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
3908 if (!dun_level) new_exp /= 5;
3909 m_ptr->exp += new_exp;
3910 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
3912 if (m_ptr->exp >= r_ptr->next_exp)
3915 int old_hp = m_ptr->hp;
3916 int old_maxhp = m_ptr->max_maxhp;
3917 int old_r_idx = m_ptr->r_idx;
3918 byte old_sub_align = m_ptr->sub_align;
3920 /* Hack -- Reduce the racial counter of previous monster */
3921 real_r_ptr(m_ptr)->cur_num--;
3923 monster_desc(m_name, m_ptr, 0);
3924 m_ptr->r_idx = r_ptr->next_r_idx;
3926 /* Count the monsters on the level */
3927 real_r_ptr(m_ptr)->cur_num++;
3929 m_ptr->ap_r_idx = m_ptr->r_idx;
3930 r_ptr = &r_info[m_ptr->r_idx];
3932 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3934 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3938 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3940 if (ironman_nightmare)
3942 u32b hp = m_ptr->max_maxhp * 2L;
3944 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3946 m_ptr->maxhp = m_ptr->max_maxhp;
3947 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
3949 /* Extract the monster base speed */
3950 m_ptr->mspeed = get_mspeed(r_ptr);
3952 /* Sub-alignment of a monster */
3953 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3954 m_ptr->sub_align = old_sub_align;
3957 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3958 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3959 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3964 if (is_pet(m_ptr) || m_ptr->ml)
3967 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
3969 msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
3971 r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
3973 update_mon(m_idx, FALSE);
3974 lite_spot(m_ptr->fy, m_ptr->fx);
3976 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;