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 | RF1_QUESTOR)) ||
264 (r_ptr->flags7 & RF7_NAZGUL)) &&
265 !p_ptr->inside_battle)
272 if (!monster_living(r_ptr))
283 monster_desc(m_name, m_ptr, MD_TRUE_NAME);
284 /* Unseen death by normal attack */
289 /* Death by special attack */
293 msg_format("%^s%s", m_name, note);
295 msg_format("%^s%s", m_name, note);
299 /* Death by normal attack -- nonliving monster */
300 else if (!monster_living(r_ptr))
303 msg_format("%^s¤ÏÇ˲õ¤µ¤ì¤¿¡£", m_name);
305 msg_format("%^s is destroyed.", m_name);
309 /* Death by normal attack -- living monster */
313 msg_format("%^s¤Ï»¦¤µ¤ì¤¿¡£", m_name);
315 msg_format("%^s is killed.", m_name);
321 monster_gain_exp(who, m_ptr->r_idx);
323 /* Generate treasure */
324 monster_death(m_idx, FALSE);
326 /* Delete the monster */
327 delete_monster_idx(m_idx);
332 /* Monster is dead */
339 /* Mega-Hack -- Pain cancels fear */
340 if (m_ptr->monfear && (dam > 0))
342 int tmp = randint1(dam / 4);
344 /* Cure a little fear */
345 if (tmp < m_ptr->monfear)
348 m_ptr->monfear -= tmp;
351 /* Cure all the fear */
362 /* Sometimes a monster gets scared by damage */
363 if (!m_ptr->monfear && !(r_ptr->flags3 & RF3_NO_FEAR))
367 /* Percentage of fully healthy */
368 percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
371 * Run (sometimes) if at 10% or less of max hit points,
372 * or (usually) when hit for half its current hit points
374 if (((percentage <= 10) && (randint0(10) < percentage)) ||
375 ((dam >= m_ptr->hp) && (randint0(100) < 80)))
377 /* Hack -- note fear */
380 /* XXX XXX XXX Hack -- Add some timed fear */
381 m_ptr->monfear += (randint1(10) +
382 (((dam >= m_ptr->hp) && (percentage > 7)) ?
383 20 : ((11 - percentage) * 5)));
387 #endif /* ALLOW_FEAR */
389 if ((dam > 0) && !is_pet(m_ptr) && !is_friendly(m_ptr) && (who != m_idx))
391 if (is_pet(&m_list[who]) && !player_bold(m_ptr->target_y, m_ptr->target_x))
393 set_target(m_ptr, m_list[who].fy, m_list[who].fx);
397 if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
401 /* Extract monster name */
402 monster_desc(m_name, m_ptr, 0);
404 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
405 if (rakuba((dam > 200) ? 200 : dam, FALSE))
408 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
410 msg_format("You have thrown off from %s!", m_name);
421 * Returns whether a given monster will try to run from the player.
423 * Monsters will attempt to avoid very powerful players. See below.
425 * Because this function is called so often, little details are important
426 * for efficiency. Like not using "mod" or "div" when possible. And
427 * attempting to check the conditions in an optimal order. Note that
428 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.
430 * Note that this function is responsible for about one to five percent
431 * of the processor use in normal conditions...
433 static int mon_will_run(int m_idx)
435 monster_type *m_ptr = &m_list[m_idx];
439 monster_race *r_ptr = &r_info[m_ptr->r_idx];
448 /* Friends can be commanded to avoid the player */
451 /* Are we trying to avoid the player? */
452 return ((p_ptr->pet_follow_distance < 0) &&
453 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
456 /* Keep monsters from running too far away */
457 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
459 /* All "afraid" monsters will run away */
460 if (m_ptr->monfear) return (TRUE);
464 /* Nearby monsters will not become terrified */
465 if (m_ptr->cdis <= 5) return (FALSE);
467 /* Examine player power (level) */
470 /* Examine monster power (level plus morale) */
471 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
473 /* Optimize extreme cases below */
474 if (m_lev > p_lev + 4) return (FALSE);
475 if (m_lev + 4 <= p_lev) return (TRUE);
477 /* Examine player health */
481 /* Examine monster health */
483 m_mhp = m_ptr->maxhp;
485 /* Prepare to optimize the calculation */
486 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
487 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
489 /* Strong players scare strong monsters */
490 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
494 /* Assume no terror */
502 * Search spell castable grid
504 static bool get_moves_aux2(int m_idx, int *yp, int *xp)
506 int i, y, x, y1, x1, best = 999;
509 bool can_open_door = FALSE;
512 monster_type *m_ptr = &m_list[m_idx];
513 monster_race *r_ptr = &r_info[m_ptr->r_idx];
515 /* Monster location */
519 /* Monster can already cast spell to player */
520 if (projectable(y1, x1, py, px)) return (FALSE);
522 /* Set current grid cost */
523 now_cost = cave[y1][x1].cost;
524 if (now_cost == 0) now_cost = 999;
526 /* Can monster bash or open doors? */
527 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
529 can_open_door = TRUE;
532 /* Check nearby grids, diagonals first */
533 for (i = 7; i >= 0; i--)
537 /* Get the location */
541 /* Ignore locations off of edge */
542 if (!in_bounds2(y, x)) continue;
544 /* Simply move to player */
545 if (player_bold(y, x)) return (FALSE);
551 /* Monster cannot kill or pass walls */
552 if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) || (r_ptr->flags2 & RF2_KILL_WALL)))
554 if (cost == 0) continue;
555 if (!can_open_door && is_closed_door(c_ptr->feat)) continue;
558 /* Hack -- for kill or pass wall monster.. */
559 if (cost == 0) cost = 998;
561 if (now_cost < cost) continue;
563 if (!projectable(y, x, py, px)) continue;
565 /* Accept louder sounds */
566 if (best < cost) continue;
569 (*yp) = y1 + ddy_ddd[i];
570 (*xp) = x1 + ddx_ddd[i];
573 /* No legal move (?) */
574 if (best == 999) return (FALSE);
582 * Choose the "best" direction for "flowing"
584 * Note that ghosts and rock-eaters are never allowed to "flow",
585 * since they should move directly towards the player.
587 * Prefer "non-diagonal" directions, but twiddle them a little
588 * to angle slightly towards the player's actual location.
590 * Allow very perceptive monsters to track old "spoor" left by
591 * previous locations occupied by the player. This will tend
592 * to have monsters end up either near the player or on a grid
593 * recently occupied by the player (and left via "teleport").
595 * Note that if "smell" is turned on, all monsters get vicious.
597 * Also note that teleporting away from a location will cause
598 * the monsters who were chasing you to converge on that location
599 * as long as you are still near enough to "annoy" them without
600 * being close enough to chase directly. I have no idea what will
601 * happen if you combine "smell" with low "aaf" values.
603 static bool get_moves_aux(int m_idx, int *yp, int *xp, bool no_flow)
605 int i, y, x, y1, x1, best;
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 /* Can monster cast attack spell? */
614 if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
615 r_ptr->flags5 & (RF5_ATTACK_MASK) ||
616 r_ptr->flags6 & (RF6_ATTACK_MASK))
618 /* Can move spell castable grid? */
619 if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
622 /* Monster can't flow */
623 if (no_flow) return (FALSE);
625 /* Monster can go through rocks */
626 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) return (FALSE);
627 if (r_ptr->flags2 & RF2_KILL_WALL) return (FALSE);
628 if (!cave_floor_bold(py, px) && (cave[py][px].feat != FEAT_TREES)) return (FALSE);
630 /* Monster location */
634 /* Hack -- Player can see us, run towards him */
635 if (player_has_los_bold(y1, x1)) return (FALSE);
638 c_ptr = &cave[y1][x1];
640 /* If we can hear noises, advance towards them */
646 /* Otherwise, try to follow a scent trail */
647 else if (c_ptr->when)
650 if (cave[py][px].when - c_ptr->when > 127) return (FALSE);
656 /* Otherwise, advance blindly */
662 /* Check nearby grids, diagonals first */
663 for (i = 7; i >= 0; i--)
665 /* Get the location */
669 /* Ignore locations off of edge */
670 if (!in_bounds2(y, x)) continue;
674 /* We're following a scent trail */
677 int when = c_ptr->when;
679 /* Accept younger scent */
680 if (best > when) continue;
684 /* We're using sound */
689 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
691 else cost = c_ptr->cost;
693 /* Accept louder sounds */
694 if ((cost == 0) || (best < cost)) continue;
698 /* Hack -- Save the "twiddled" location */
699 (*yp) = py + 16 * ddy_ddd[i];
700 (*xp) = px + 16 * ddx_ddd[i];
703 /* No legal move (?) */
704 if (best == 999 || best == 0) return (FALSE);
712 * Provide a location to flee to, but give the player a wide berth.
714 * A monster may wish to flee to a location that is behind the player,
715 * but instead of heading directly for it, the monster should "swerve"
716 * around the player so that he has a smaller chance of getting hit.
718 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
720 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
724 monster_type *m_ptr = &m_list[m_idx];
726 /* Monster location */
730 /* Desired destination */
734 /* Check nearby grids, diagonals first */
735 for (i = 7; i >= 0; i--)
739 /* Get the location */
743 /* Ignore locations off of edge */
744 if (!in_bounds2(y, x)) continue;
746 /* Don't move toward player */
747 /* if (cave[y][x].dist < 3) continue; */ /* Hmm.. Need it? */
749 /* Calculate distance of this grid from our destination */
750 dis = distance(y, x, y1, x1);
752 /* Score this grid */
753 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
755 /* No negative scores */
758 /* Ignore lower scores */
759 if (s < score) continue;
761 /* Save the score and time */
764 /* Save the location */
769 /* No legal move (?) */
770 if (score == -1) return (FALSE);
781 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
784 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
785 * offsets of all the locations with a distance of n from a central point,
786 * with an offset of (0,0) indicating no more offsets at this distance.
788 * This is, of course, fairly unreadable, but it eliminates multiple loops
789 * from the previous version.
791 * It is probably better to replace these arrays with code to compute
792 * the relevant arrays, even if the storage is pre-allocated in hard
793 * coded sizes. At the very least, code should be included which is
794 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
796 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
798 * These arrays could be combined into two big arrays, using sub-arrays
799 * to hold the offsets and lengths of each portion of the sub-arrays, and
800 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
804 static sint d_off_y_0[] =
807 static sint d_off_x_0[] =
811 static sint d_off_y_1[] =
812 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
814 static sint d_off_x_1[] =
815 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
818 static sint d_off_y_2[] =
819 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
821 static sint d_off_x_2[] =
822 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
825 static sint d_off_y_3[] =
826 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
829 static sint d_off_x_3[] =
830 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
834 static sint d_off_y_4[] =
835 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
836 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
838 static sint d_off_x_4[] =
839 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
840 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
843 static sint d_off_y_5[] =
844 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
845 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
848 static sint d_off_x_5[] =
849 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
850 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
854 static sint d_off_y_6[] =
855 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
856 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
859 static sint d_off_x_6[] =
860 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
861 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
862 -3, 2, 3, -1, 0, 1, 0 };
865 static sint d_off_y_7[] =
866 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
867 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
868 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
870 static sint d_off_x_7[] =
871 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
872 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
873 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
877 static sint d_off_y_8[] =
878 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
879 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
880 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
883 static sint d_off_x_8[] =
884 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
885 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
886 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
890 static sint d_off_y_9[] =
891 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
892 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
893 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
894 7, 8, 8, 8, 8, 9, 9, 9, 0 };
896 static sint d_off_x_9[] =
897 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
898 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
899 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
900 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
903 static sint *dist_offsets_y[10] =
905 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
906 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
909 static sint *dist_offsets_x[10] =
911 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
912 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
916 * Choose a "safe" location near a monster for it to run toward.
918 * A location is "safe" if it can be reached quickly and the player
919 * is not able to fire into it (it isn't a "clean shot"). So, this will
920 * cause monsters to "duck" behind walls. Hopefully, monsters will also
921 * try to run towards corridor openings if they are in a room.
923 * This function may take lots of CPU time if lots of monsters are
926 * Return TRUE if a safe location is available.
928 static bool find_safety(int m_idx, int *yp, int *xp)
930 monster_type *m_ptr = &m_list[m_idx];
935 int y, x, dy, dx, d, dis, i;
936 int gy = 0, gx = 0, gdis = 0;
943 /* Start with adjacent locations, spread further */
944 for (d = 1; d < 10; d++)
946 /* Get the lists of points with a distance d from (fx, fy) */
947 y_offsets = dist_offsets_y[d];
948 x_offsets = dist_offsets_x[d];
950 /* Check the locations */
951 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
953 i++, dx = x_offsets[i], dy = y_offsets[i])
958 /* Skip illegal locations */
959 if (!in_bounds(y, x)) continue;
963 /* Skip locations in a wall */
964 if (!cave_floor_grid(c_ptr)) continue;
966 /* Check for "availability" (if monsters can flow) */
967 if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
969 /* Ignore grids very far from the player */
970 if (c_ptr->dist == 0) continue;
972 /* Ignore too-distant grids */
973 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
976 /* Check for absence of shot (more or less) */
977 if (!player_has_los_grid(c_ptr))
980 /* Calculate distance from player */
981 dis = distance(y, x, py, px);
983 /* Remember if further than previous */
993 /* Check for success */
1000 /* Found safe place */
1011 * Choose a good hiding place near a monster for it to run toward.
1013 * Pack monsters will use this to "ambush" the player and lure him out
1014 * of corridors into open space so they can swarm him.
1016 * Return TRUE if a good location is available.
1018 static bool find_hiding(int m_idx, int *yp, int *xp)
1020 monster_type *m_ptr = &m_list[m_idx];
1025 int y, x, dy, dx, d, dis, i;
1026 int gy = 0, gx = 0, gdis = 999;
1028 sint *y_offsets, *x_offsets;
1032 /* Start with adjacent locations, spread further */
1033 for (d = 1; d < 10; d++)
1035 /* Get the lists of points with a distance d from (fx, fy) */
1036 y_offsets = dist_offsets_y[d];
1037 x_offsets = dist_offsets_x[d];
1039 /* Check the locations */
1040 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
1042 i++, dx = x_offsets[i], dy = y_offsets[i])
1047 /* Skip illegal locations */
1048 if (!in_bounds(y, x)) continue;
1050 c_ptr = &cave[y][x];
1052 /* Skip occupied locations */
1053 if (!cave_empty_grid(c_ptr)) continue;
1055 /* Check for hidden, available grid */
1056 if (!player_has_los_grid(c_ptr) && clean_shot(fy, fx, y, x, FALSE))
1058 /* Calculate distance from player */
1059 dis = distance(y, x, py, px);
1061 /* Remember if closer than previous */
1062 if (dis < gdis && dis >= 2)
1071 /* Check for success */
1078 /* Found good place */
1089 * Choose "logical" directions for monster movement
1091 static bool get_moves(int m_idx, int *mm)
1093 monster_type *m_ptr = &m_list[m_idx];
1094 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1100 bool will_run = mon_will_run(m_idx);
1102 bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1103 bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
1105 /* Counter attack to an enemy monster */
1106 if (!will_run && m_ptr->target_y)
1108 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
1110 /* The monster must be an enemy, and in LOS */
1112 are_enemies(m_ptr, &m_list[t_m_idx]) &&
1113 los(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
1115 /* Extract the "pseudo-direction" */
1116 y = m_ptr->fy - m_ptr->target_y;
1117 x = m_ptr->fx - m_ptr->target_x;
1122 if (!done && !will_run && is_hostile(m_ptr) &&
1123 (r_ptr->flags1 & RF1_FRIENDS) &&
1124 (los(m_ptr->fy, m_ptr->fx, py, px) ||
1125 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1128 * Animal packs try to get the player out of corridors
1129 * (...unless they can move through walls -- TY)
1131 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1132 !(r_ptr->flags2 & RF2_KILL_WALL))
1136 /* Count room grids next to player */
1137 for (i = 0; i < 8; i++)
1139 int xx = px + ddx_ddd[i];
1140 int yy = py + ddy_ddd[i];
1142 if (!in_bounds2(yy, xx)) continue;
1144 c_ptr = &cave[yy][xx];
1147 if (((cave_floor_grid(c_ptr)) || ((c_ptr->feat & 0x60) == 0x60)) &&
1148 monster_can_cross_terrain(c_ptr->feat, r_ptr))
1150 /* One more room grid */
1154 if (cave[py][px].info & CAVE_ROOM) room -= 2;
1155 if (!r_ptr->flags4 && !r_ptr->flags5 && !r_ptr->flags6) room -= 2;
1157 /* Not in a room and strong player */
1158 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
1159 (p_ptr->mhp + p_ptr->msp))
1161 /* Find hiding place */
1162 if (find_hiding(m_idx, &y, &x)) done = TRUE;
1166 /* Monster groups try to surround the player */
1167 if (!done && (cave[m_ptr->fy][m_ptr->fx].dist < 3))
1171 /* Find an empty square near the player to fill */
1172 for (i = 0; i < 8; i++)
1174 /* Pick squares near player (semi-randomly) */
1175 y2 = py + ddy_ddd[(m_idx + i) & 7];
1176 x2 = px + ddx_ddd[(m_idx + i) & 7];
1178 /* Already there? */
1179 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
1181 /* Attack the player */
1188 if (!in_bounds2(y2, x2)) continue;
1190 /* Ignore filled grids */
1191 c_ptr = &cave[y2][x2];
1192 if (!cave_empty_grid(c_ptr)) continue;
1194 /* Try to fill this hole */
1198 /* Extract the new "pseudo-direction" */
1209 /* Flow towards the player */
1210 (void)get_moves_aux(m_idx, &y2, &x2, no_flow);
1212 /* Extract the "pseudo-direction" */
1219 /* Apply fear if possible and necessary */
1220 if (is_pet(m_ptr) && will_run)
1222 /* XXX XXX Not very "smart" */
1227 if (!done && will_run)
1232 /* Try to find safe place */
1233 if (find_safety(m_idx, &y, &x))
1235 /* Attempt to avoid the player */
1238 /* Adjust movement */
1239 if (get_fear_moves_aux(m_idx, &y, &x)) done = TRUE;
1245 /* This is not a very "smart" method XXX XXX */
1253 /* Check for no move */
1254 if (!x && !y) return (FALSE);
1257 /* Extract the "absolute distances" */
1261 /* Do something weird */
1262 if (y < 0) move_val += 8;
1263 if (x > 0) move_val += 4;
1265 /* Prevent the diamond maneuvre */
1266 if (ay > (ax << 1)) move_val += 2;
1267 else if (ax > (ay << 1)) move_val++;
1269 /* Extract some directions */
1414 /* Wants to move... */
1419 static int check_hit2(int power, int level, int ac, int stun)
1423 /* Percentile dice */
1426 if (stun && one_in_(2)) return FALSE;
1428 /* Hack -- Always miss or hit */
1429 if (k < 10) return (k < 5);
1431 /* Calculate the "attack quality" */
1432 i = (power + (level * 3));
1434 /* Power and Level compete against Armor */
1435 if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
1442 /* Monster attacks monster */
1443 static bool monst_attack_monst(int m_idx, int t_idx)
1445 monster_type *m_ptr = &m_list[m_idx];
1446 monster_type *t_ptr = &m_list[t_idx];
1448 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1449 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1453 char m_name[80], t_name[80];
1455 bool blinked, heal_effect;
1456 bool explode = FALSE, touched = FALSE, fear = FALSE;
1457 int y_saver = t_ptr->fy;
1458 int x_saver = t_ptr->fx;
1460 bool see_m = m_ptr->ml;
1461 bool see_t = t_ptr->ml;
1462 bool see_either = see_m || see_t;
1464 /* Can the player be aware of this attack? */
1465 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1466 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1468 /* Cannot attack self */
1469 if (m_idx == t_idx) return FALSE;
1471 /* Not allowed to attack */
1472 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1474 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1479 /* Extract the effective monster level */
1480 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1482 /* Get the monster name (or "it") */
1483 monster_desc(m_name, m_ptr, 0);
1485 /* Get the monster name (or "it") */
1486 monster_desc(t_name, t_ptr, 0);
1488 /* Assume no blink */
1491 if (!see_either && known)
1496 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
1498 /* Scan through all four blows */
1499 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1501 bool obvious = FALSE;
1508 /* Extract the attack infomation */
1509 int effect = r_ptr->blow[ap_cnt].effect;
1510 int method = r_ptr->blow[ap_cnt].method;
1511 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1512 int d_side = r_ptr->blow[ap_cnt].d_side;
1514 if (!m_ptr->r_idx) break;
1516 /* Stop attacking if the target dies! */
1517 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1520 /* Hack -- no more attacks */
1523 if (blinked) /* Stop! */
1528 if (method == RBM_SHOOT) continue;
1530 /* Extract the attack "power" */
1531 power = mbe_info[effect].power;
1534 if (!effect || check_hit2(power, rlev, ac, m_ptr->stunned))
1539 if (tr_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
1541 /* Describe the attack method */
1547 act = "%s¤ò²¥¤Ã¤¿¡£";
1559 act = "%s¤ò¿¨¤Ã¤¿¡£";
1561 act = "touches %s.";
1571 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1573 act = "punches %s.";
1583 act = "%s¤ò½³¤Ã¤¿¡£";
1595 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1607 act = "%s¤ò³ú¤ó¤À¡£";
1619 act = "%s¤ò»É¤·¤¿¡£";
1631 act = "%s¤ò»Â¤Ã¤¿¡£";
1633 act = "slashes %s.";
1642 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1654 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1656 act = "crushes %s.";
1666 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1668 act = "engulfs %s.";
1678 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1680 act = "charges %s.";
1690 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1692 act = "crawls on %s.";
1702 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1704 act = "drools on %s.";
1714 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1716 act = "spits on %s.";
1725 if (see_either) disturb(1, 0);
1740 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1742 act = "gazes at %s.";
1752 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1754 act = "wails at %s.";
1764 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1766 act = "releases spores at %s.";
1776 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1778 act = "projects XXX4's at %s.";
1788 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1790 act = "begs %s for money.";
1800 act = "%s¤òÉî¿«¤·¤¿¡£";
1802 act = "insults %s.";
1812 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1814 act = "moans at %s.";
1824 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1826 act = "sings to %s.";
1835 if (act && see_either)
1838 if (do_silly_attack) act = silly_attacks2[randint0(MAX_SILLY_ATTACK)];
1839 strfmt(temp, act, t_name);
1840 msg_format("%^s¤Ï%s", m_name, temp);
1842 if (do_silly_attack)
1844 act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
1845 strfmt(temp, "%s %s.", act, t_name);
1847 else strfmt(temp, act, t_name);
1848 msg_format("%^s %s", m_name, temp);
1852 /* Hack -- assume all attacks are obvious */
1855 /* Roll out the damage */
1856 damage = damroll(d_dice, d_side);
1858 /* Assume no healing effect */
1859 heal_effect = FALSE;
1863 /* Apply appropriate damage */
1875 if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13)) {
1876 int tmp_damage = damage-(damage*((ac < 150) ? ac : 150)/250);
1877 damage = MAX(damage, tmp_damage*2);
1883 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1913 if (one_in_(2)) blinked = TRUE;
1960 pt = GF_OLD_SLEEP; /* sort of close... */
1976 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1979 earthquake(m_ptr->fy, m_ptr->fx, 8);
2012 /* Do damage if not exploding */
2015 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
2016 (pt == GF_OLD_SLEEP ? r_ptr->level : damage), pt, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2021 if ((monster_living(tr_ptr)) && (damage > 2))
2023 bool did_heal = FALSE;
2025 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
2028 m_ptr->hp += damroll(4, damage / 6);
2029 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
2031 /* Redraw (later) if needed */
2032 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2033 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2035 /* Special message */
2036 if (see_m && did_heal)
2039 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
2041 msg_format("%^s appears healthier.", m_name);
2051 if ((tr_ptr->flags2 & RF2_AURA_FIRE) && m_ptr->r_idx)
2053 if (!(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK))
2059 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2061 msg_format("%^s is suddenly very hot!", m_name);
2064 if (see_t && is_original_ap(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2066 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2067 damroll (1 + ((tr_ptr->level) / 26),
2068 1 + ((tr_ptr->level) / 17)),
2069 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2073 if (see_m && is_original_ap(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK);
2078 if ((tr_ptr->flags3 & RF3_AURA_COLD) && m_ptr->r_idx)
2080 if (!(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK))
2086 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2088 msg_format("%^s is suddenly very cold!", m_name);
2091 if (see_t && is_original_ap(t_ptr)) tr_ptr->r_flags3 |= RF3_AURA_COLD;
2093 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2094 damroll (1 + ((tr_ptr->level) / 26),
2095 1 + ((tr_ptr->level) / 17)),
2096 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2100 if (see_m && is_original_ap(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_COLD_MASK);
2105 if ((tr_ptr->flags2 & RF2_AURA_ELEC) && m_ptr->r_idx)
2107 if (!(r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK))
2113 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2115 msg_format("%^s gets zapped!", m_name);
2118 if (see_t && is_original_ap(t_ptr)) tr_ptr->r_flags2 |= RF2_AURA_ELEC;
2120 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2121 damroll (1 + ((tr_ptr->level) / 26),
2122 1 + ((tr_ptr->level) / 17)),
2123 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_AIMED, -1);
2127 if (see_m && is_original_ap(m_ptr)) r_ptr->r_flagsr |= (r_ptr->flagsr & RFR_EFF_IM_ELEC_MASK);
2134 /* Monster missed player */
2137 /* Analyze failed attacks */
2156 if (tr_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
2158 /* Visible monsters */
2163 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2165 msg_format("%^s misses %s.", m_name, t_name);
2176 /* Analyze "visible" monsters only */
2177 if (see_m && !do_silly_attack)
2179 /* Count "obvious" attacks (and ones that cause damage) */
2180 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2182 /* Count attacks of this type */
2183 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2185 r_ptr->r_blows[ap_cnt]++;
2193 sound(SOUND_EXPLODE);
2195 /* Cancel Invulnerability */
2196 if (m_ptr->invulner) m_ptr->invulner = 0;
2199 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2201 mon_take_hit_mon(m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2215 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2217 msg_print("The thief flees laughing!");
2226 teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE);
2236 * The monster is known to be within 100 grids of the player
2238 * In several cases, we directly update the monster lore
2240 * Note that a monster is only allowed to "reproduce" if there
2241 * are a limited number of "reproducing" monsters on the current
2242 * level. This should prevent the level from being "swamped" by
2243 * reproducing monsters. It also allows a large mass of mice to
2244 * prevent a louse from multiplying, but this is a small price to
2245 * pay for a simple multiplication method.
2247 * XXX Monster fear is slightly odd, in particular, monsters will
2248 * fixate on opening a door even if they cannot open it. Actually,
2249 * the same thing happens to normal monsters when they hit a door
2251 * XXX XXX XXX In addition, monsters which *cannot* open or bash
2252 * down a door will still stand there trying to open it...
2254 * XXX Technically, need to check for monster in the way
2255 * combined with that monster being in a wall (or door?)
2257 * A "direction" of "5" means "pick a random direction".
2259 static void process_monster(int m_idx)
2261 monster_type *m_ptr = &m_list[m_idx];
2262 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2263 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2265 int i, d, oy, ox, ny, nx;
2271 monster_type *y_ptr;
2284 bool gets_angry = FALSE;
2290 if ((m_idx == p_ptr->riding) && !(r_ptr->flags7 & RF7_RIDING))
2292 if (rakuba(0, TRUE))
2295 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2298 monster_desc(m_name, &m_list[p_ptr->riding], 0);
2299 msg_format("You have fallen from %s.", m_name);
2304 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !m_ptr->csleep)
2306 choose_new_monster(m_idx, FALSE, 0);
2307 r_ptr = &r_info[m_ptr->r_idx];
2310 /* Players hidden in shadow are almost imperceptable. -LM- */
2311 if (p_ptr->special_defense & NINJA_S_STEALTH)
2313 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
2314 if (p_ptr->monlite) tmp /= 3;
2315 if (p_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
2316 if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
2317 /* Low-level monsters will find it difficult to locate the player. */
2318 if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
2321 /* Are there its parent? */
2322 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
2324 /* Its parent have gone, it also goes away. */
2330 /* Acquire the monster name */
2331 monster_desc(m_name, m_ptr, 0);
2334 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2336 msg_format("%^s disappears!", m_name);
2340 /* Delete the monster */
2341 delete_monster_idx(m_idx);
2346 /* Quantum monsters are odd */
2347 if (r_ptr->flags2 & (RF2_QUANTUM))
2349 /* Sometimes skip move */
2350 if (!randint0(2)) return;
2353 if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2357 if (is_pet(m_ptr) && !(m_ptr->ml))
2364 /* Acquire the monster name */
2365 monster_desc(m_name, m_ptr, 0);
2369 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2371 msg_format("%^s disappears!", m_name);
2376 /* Generate treasure, etc */
2377 monster_death(m_idx, FALSE);
2379 /* Delete the monster */
2380 delete_monster_idx(m_idx);
2385 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2387 msg_print("You feel sad for a moment.");
2396 if (m_ptr->r_idx == MON_SHURYUUDAN)
2398 mon_take_hit_mon(m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2400 mon_take_hit_mon(m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2403 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) && !p_ptr->inside_battle)
2405 static int riding_pinch = 0;
2407 if (m_ptr->hp < m_ptr->maxhp/3)
2410 monster_desc(m_name, m_ptr, 0);
2412 if (m_idx == p_ptr->riding && riding_pinch < 2)
2415 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2417 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
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);
2431 if (rakuba(-1, FALSE))
2434 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2436 msg_print("You have fallen from riding pet.");
2443 if ((r_ptr->flags2 & RF2_CAN_SPEAK) && (m_ptr->r_idx != MON_GRIP) && (m_ptr->r_idx != MON_WOLF) && (m_ptr->r_idx != MON_FANG))
2446 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2448 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2452 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2453 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2455 msg_format("%^s read a scroll of teleport level.", m_name);
2456 msg_format("%^s disappears.", m_name);
2460 if (m_idx == p_ptr->riding && rakuba(-1, FALSE))
2463 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2465 msg_print("You have fallen from riding pet.");
2469 /* Check for quest completion */
2470 check_quest_completion(m_ptr);
2472 delete_monster_idx(m_idx);
2479 /* Reset the counter */
2480 if (m_idx == p_ptr->riding) riding_pinch = 0;
2484 /* Handle "sleep" */
2487 /* Handle non-aggravation - Still sleeping */
2488 if (!(p_ptr->cursed & TRC_AGGRAVATE)) return;
2490 /* Handle aggravation */
2492 /* Reset sleep counter */
2495 if (r_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
2497 /* Notice the "waking up" */
2502 /* Acquire the monster name */
2503 monster_desc(m_name, m_ptr, 0);
2505 /* Dump a message */
2507 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
2509 msg_format("%^s wakes up.", m_name);
2512 /* Redraw the health bar */
2513 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2514 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2516 /* Hack -- Count the wakings */
2517 if (r_ptr->r_wake < MAX_UCHAR)
2527 /* Sometimes skip move */
2528 if (one_in_(2)) return;
2531 if (p_ptr->riding == m_idx)
2533 p_ptr->update |= (PU_BONUS);
2536 /* No one wants to be your friend if you're aggravating */
2537 if (is_friendly(m_ptr) && (p_ptr->cursed & TRC_AGGRAVATE))
2540 /* Paranoia... no pet uniques outside wizard mode -- TY */
2541 if (is_pet(m_ptr) &&
2542 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
2543 monster_has_hostile_align(NULL, 10, -10, r_ptr))
2544 || (r_ptr->flagsr & RFR_RES_ALL)))
2549 if (p_ptr->inside_battle) gets_angry = FALSE;
2554 monster_desc(m_name, m_ptr, 0);
2556 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2558 msg_format("%^s suddenly becomes hostile!", m_name);
2564 /* Get the origin */
2569 /* Attempt to "multiply" if able and allowed */
2570 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2574 /* Count the adjacent monsters */
2575 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2577 for (x = ox - 1; x <= ox + 1; x++)
2579 /* Ignore locations off of edge */
2580 if (!in_bounds2(y, x)) continue;
2582 if (cave[y][x].m_idx) k++;
2586 /* Hack -- multiply slower in crowded areas */
2587 if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
2589 /* Try to multiply */
2590 if (multiply_monster(m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
2592 /* Take note if visible */
2593 if (m_ptr->ml && m_list[hack_m_idx_ii].ml && is_original_ap(m_ptr))
2595 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2598 /* Multiplying takes energy */
2605 if (r_ptr->flags6 & RF6_SPECIAL)
2607 /* Hack -- Ohmu scatters molds! */
2608 if (m_ptr->r_idx == MON_OHMU)
2610 if (!p_ptr->inside_arena && !p_ptr->inside_battle)
2612 if (r_ptr->freq_spell && (randint1(100) <= r_ptr->freq_spell))
2615 int rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
2616 u32b p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
2618 for (k = 0; k < 6; k++)
2620 if (summon_specific(m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_BIZARRE1, (PM_ALLOW_GROUP | p_mode)))
2622 if (m_list[hack_m_idx_ii].ml) count++;
2626 if (count && m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
2633 if (!p_ptr->inside_battle)
2635 /* Hack! "Cyber" monster makes noise... */
2636 if (m_ptr->ap_r_idx == MON_CYBER &&
2637 one_in_(CYBERNOISE) &&
2638 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2640 if (disturb_minor) disturb(FALSE, FALSE);
2642 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2644 msg_print("You hear heavy steps.");
2649 /* Some monsters can speak */
2650 if ((ap_r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2651 one_in_(SPEAK_CHANCE) &&
2652 player_has_los_bold(oy, ox))
2655 char monmessage[1024];
2658 /* Acquire the monster name/poss */
2660 monster_desc(m_name, m_ptr, 0);
2663 strcpy(m_name, "¤½¤ì");
2665 strcpy(m_name, "It");
2669 /* Select the file for monster quotes */
2672 filename = "monfear_j.txt";
2674 filename = "monfear.txt";
2677 else if (is_pet(m_ptr))
2679 filename = "monpet_j.txt";
2681 filename = "monpet.txt";
2684 else if (is_friendly(m_ptr))
2686 filename = "monfrien_j.txt";
2688 filename = "monfrien.txt";
2693 filename = "monspeak_j.txt";
2695 filename = "monspeak.txt";
2699 /* Get the monster line */
2700 if (get_rnd_line(filename, m_ptr->ap_r_idx, monmessage) == 0)
2704 msg_format("%^s%s", m_name, monmessage);
2706 msg_format("%^s %s", m_name, monmessage);
2713 /* Try to cast spell occasionally */
2714 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
2716 bool counterattack = FALSE;
2718 /* Give priority to counter attack? */
2719 if (m_ptr->target_y)
2721 int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
2723 /* The monster must be an enemy, and projectable */
2725 are_enemies(m_ptr, &m_list[t_m_idx]) &&
2726 projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
2728 counterattack = TRUE;
2734 /* Attempt to cast a spell */
2735 if (aware && make_attack_spell(m_idx)) return;
2738 * Attempt to cast a spell at an enemy other than the player
2739 * (may slow the game a smidgeon, but I haven't noticed.)
2741 if (monst_spell_monst(m_idx)) return;
2745 /* Attempt to do counter attack at first */
2746 if (monst_spell_monst(m_idx)) return;
2748 if (aware && make_attack_spell(m_idx)) return;
2752 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
2754 /* Hack -- Assume no movement */
2755 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2756 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2759 /* Confused -- 100% random */
2760 if (m_ptr->confused || !aware)
2762 /* Try four "random" directions */
2763 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2766 /* 75% random movement */
2767 else if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) &&
2768 (randint0(100) < 75))
2770 /* Memorize flags */
2771 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
2773 /* Try four "random" directions */
2774 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2777 /* 50% random movement */
2778 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2779 (randint0(100) < 50))
2781 /* Memorize flags */
2782 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
2784 /* Try four "random" directions */
2785 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2788 /* 25% random movement */
2789 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2790 (randint0(100) < 25))
2792 /* Memorize flags */
2793 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
2795 /* Try four "random" directions */
2796 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2799 /* Can't reach player - find something else to hit */
2800 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2802 /* Try four "random" directions */
2803 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2805 /* Look for an enemy */
2806 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2807 get_enemy_dir(m_idx, mm);
2811 /* Pets will follow the player */
2812 else if (is_pet(m_ptr))
2814 /* Are we trying to avoid the player? */
2815 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
2816 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2818 /* Do we want to find the player? */
2819 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2821 /* Should we find the player if we can't find a monster? */
2822 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2824 /* by default, move randomly */
2825 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2827 /* Look for an enemy */
2828 if (!get_enemy_dir(m_idx, mm))
2830 /* Find the player if necessary */
2831 if (avoid || lonely || distant)
2833 /* Remember the leash length */
2834 int dis = p_ptr->pet_follow_distance;
2836 /* Hack -- adjust follow distance temporarily */
2837 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2839 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2842 /* Find the player */
2843 get_moves(m_idx, mm);
2845 /* Restore the leash */
2846 p_ptr->pet_follow_distance = dis;
2851 /* Friendly monster movement */
2852 else if (!is_hostile(m_ptr))
2854 /* by default, move randomly */
2855 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2857 /* Look for an enemy */
2858 get_enemy_dir(m_idx, mm);
2860 /* Normal movement */
2863 /* Logical moves, may do nothing */
2864 if (!get_moves(m_idx, mm)) return;
2867 /* Assume nothing */
2872 /* Assume nothing */
2873 did_open_door = FALSE;
2874 did_bash_door = FALSE;
2875 did_take_item = FALSE;
2876 did_kill_item = FALSE;
2877 did_move_body = FALSE;
2878 did_pass_wall = FALSE;
2879 did_kill_wall = FALSE;
2882 /* Take a zero-terminated array of "directions" */
2883 for (i = 0; mm[i]; i++)
2885 /* Get the direction */
2888 /* Hack -- allow "randomized" motion */
2889 if (d == 5) d = ddd[randint0(8)];
2891 /* Get the destination */
2895 /* Ignore locations off of edge */
2896 if (!in_bounds2(ny, nx)) continue;
2898 /* Access that cave grid */
2899 c_ptr = &cave[ny][nx];
2901 /* Access that cave grid's contents */
2902 y_ptr = &m_list[c_ptr->m_idx];
2904 /* Floor is open? */
2905 if (cave_floor_grid(c_ptr))
2907 /* Go ahead and move */
2911 /* Hack -- player 'in' wall */
2912 else if (player_bold(ny, nx))
2917 else if (c_ptr->m_idx)
2919 /* Possibly a monster to attack */
2923 /* Permanent wall */
2924 else if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
2925 (c_ptr->feat <= FEAT_PERM_SOLID))
2930 /* Hack -- semi-transparent terrains are no obstacle */
2931 else if (c_ptr->feat == FEAT_TREES)
2936 /* Hack -- semi-transparent terrains are no obstacle */
2937 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)))))
2943 /* Monster moves through walls (and doors) */
2944 else if (can_pass_wall)
2946 /* Pass through walls/doors/rubble */
2949 /* Monster went through a wall */
2950 did_pass_wall = TRUE;
2953 /* Monster destroys walls (and doors) */
2954 else if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))
2956 /* Eat through walls/doors/rubble */
2959 /* Monster destroyed a wall */
2960 did_kill_wall = TRUE;
2962 if (one_in_(GRINDNOISE))
2965 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
2967 msg_print("There is a grinding sound.");
2972 /* Forget the wall */
2973 c_ptr->info &= ~(CAVE_MARK);
2976 cave_set_feat(ny, nx, floor_type[randint0(100)]);
2978 /* Note changes to viewable region */
2979 if (player_has_los_bold(ny, nx)) do_view = TRUE;
2982 /* Handle doors and secret doors */
2983 else if (is_closed_door(c_ptr->feat))
2985 bool may_bash = TRUE;
2987 /* Assume no move allowed */
2990 /* Creature can open doors. */
2991 if ((r_ptr->flags2 & RF2_OPEN_DOOR) &&
2992 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
2995 if (c_ptr->feat == FEAT_DOOR_HEAD)
2997 /* The door is open */
2998 did_open_door = TRUE;
3000 /* Do not bash the door */
3003 /* Assume no move allowed */
3007 /* Locked doors (not jammed) */
3008 else if (c_ptr->feat < FEAT_DOOR_HEAD + 0x08)
3013 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3015 /* Try to unlock it XXX XXX XXX */
3016 if (randint0(m_ptr->hp / 10) > k)
3018 /* Unlock the door */
3019 cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00);
3021 /* Do not bash the door */
3027 /* Stuck doors -- attempt to bash them down if allowed */
3028 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) &&
3029 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3034 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3036 /* Attempt to Bash XXX XXX XXX */
3037 if (randint0(m_ptr->hp / 10) > k)
3041 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
3043 msg_print("You hear a door burst open!");
3047 /* Disturb (sometimes) */
3048 if (disturb_minor) disturb(0, 0);
3050 /* The door was bashed open */
3051 did_bash_door = TRUE;
3053 /* Hack -- fall into doorway */
3059 /* Deal with doors in the way */
3060 if (did_open_door || did_bash_door)
3062 /* Break down the door */
3063 if (did_bash_door && (randint0(100) < 50))
3065 cave_set_feat(ny, nx, FEAT_BROKEN);
3071 cave_set_feat(ny, nx, FEAT_OPEN);
3074 /* Handle viewable doors */
3075 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3079 /* Hack -- check for Glyph of Warding */
3080 if (do_move && is_glyph_grid(c_ptr) &&
3081 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3083 /* Assume no move allowed */
3086 /* Break the ward */
3087 if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
3089 /* Describe observable breakage */
3090 if (c_ptr->info & CAVE_MARK)
3093 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3095 msg_print("The rune of protection is broken!");
3100 /* Forget the rune */
3101 c_ptr->info &= ~(CAVE_MARK);
3103 /* Break the rune */
3104 c_ptr->info &= ~(CAVE_OBJECT);
3107 /* Allow movement */
3114 else if (do_move && is_explosive_rune_grid(c_ptr) &&
3115 !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(ny, nx)))
3117 /* Assume no move allowed */
3120 /* Break the ward */
3123 /* Break the ward */
3124 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3126 /* Describe observable breakage */
3127 if (c_ptr->info & CAVE_MARK)
3130 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3132 msg_print("The rune explodes!");
3135 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);
3141 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3143 msg_print("An explosive rune was disarmed.");
3147 /* Forget the rune */
3148 c_ptr->info &= ~(CAVE_MARK);
3150 /* Break the rune */
3151 c_ptr->info &= ~(CAVE_OBJECT);
3157 if (!m_ptr->r_idx) return;
3158 /* Allow movement */
3163 /* The player is in the way */
3164 if (do_move && player_bold(ny, nx))
3166 /* Some monsters never attack */
3167 if (r_ptr->flags1 & RF1_NEVER_BLOW)
3169 /* Hack -- memorize lack of attacks */
3170 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3176 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
3177 if (do_move && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3179 if (!m_ptr->confused)
3181 if (!(r_ptr->flags2 & RF2_STUPID)) do_move = FALSE;
3184 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
3189 /* The player is in the way. Attack him. */
3192 if (!p_ptr->riding || one_in_(2))
3195 (void)make_attack_normal(m_idx);
3205 if ((c_ptr->feat >= FEAT_PATTERN_START) &&
3206 (c_ptr->feat <= FEAT_PATTERN_XTRA2) &&
3207 !do_turn && !(r_ptr->flags7 & RF7_CAN_FLY))
3213 /* A monster is in the way */
3214 if (do_move && c_ptr->m_idx)
3216 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3218 /* Assume no movement */
3221 /* Attack 'enemies' */
3222 if (((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW) &&
3223 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3224 cave_floor_grid(c_ptr) &&
3225 (c_ptr->m_idx != p_ptr->riding)) ||
3226 are_enemies(m_ptr, y_ptr) || m_ptr->confused)
3230 if (!(r_ptr->flags1 & RF1_NEVER_BLOW))
3232 if (r_ptr->flags2 & RF2_KILL_BODY)
3234 if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3238 if (y_ptr->r_idx && (y_ptr->hp >= 0))
3240 if (monst_attack_monst(m_idx, c_ptr->m_idx)) return;
3242 /* In anti-melee dungeon, stupid or confused monster takes useless turn */
3243 else if (d_info[dungeon_type].flags1 & DF1_NO_MELEE)
3245 if (m_ptr->confused) return;
3246 else if (r_ptr->flags2 & RF2_STUPID)
3248 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
3256 /* Push past weaker monsters (unless leaving a wall) */
3257 else if ((r_ptr->flags2 & RF2_MOVE_BODY) &&
3258 (r_ptr->mexp > z_ptr->mexp) && cave_floor_grid(c_ptr) &&
3259 (cave_floor_grid(&cave[m_ptr->fy][m_ptr->fx])) &&
3260 (c_ptr->m_idx != p_ptr->riding))
3262 /* Allow movement */
3265 /* Monster pushed past another monster */
3266 did_move_body = TRUE;
3268 /* XXX XXX XXX Message */
3273 * Check if monster can cross terrain
3274 * This is checked after the normal attacks
3275 * to allow monsters to attack an enemy,
3276 * even if it can't enter the terrain.
3278 if (do_move && !monster_can_cross_terrain(c_ptr->feat, r_ptr))
3280 /* Assume no move allowed */
3284 /* Some monsters never move */
3285 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3287 /* Hack -- memorize lack of attacks */
3288 if (m_ptr->ml && is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3294 if (m_idx == p_ptr->riding)
3296 if (!p_ptr->riding_ryoute && !(m_list[p_ptr->riding].monfear)) do_move = FALSE;
3299 /* Creature has been allowed move */
3302 s16b this_o_idx, next_o_idx;
3307 /* Hack -- Update the old location */
3308 cave[oy][ox].m_idx = c_ptr->m_idx;
3310 if (c_ptr->feat == FEAT_TREES)
3312 if (r_ptr->flags2 & RF2_KILL_WALL)
3314 cave_set_feat(ny, nx, FEAT_GRASS);
3317 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3319 m_ptr->energy_need += ENERGY_NEED();
3323 /* Mega-Hack -- move the old monster, if any */
3326 /* Move the old monster */
3330 /* Update the old monster */
3331 update_mon(c_ptr->m_idx, TRUE);
3333 /* Wake up the moved monster */
3336 if (r_info[y_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
3337 p_ptr->update |= (PU_MON_LITE);
3340 /* Hack -- Update the new location */
3341 c_ptr->m_idx = m_idx;
3343 /* Move the monster */
3347 /* Update the monster */
3348 update_mon(m_idx, TRUE);
3350 if (p_ptr->riding == m_idx)
3356 /* Redraw the old grid */
3359 /* Redraw the new grid */
3362 if (p_ptr->riding == m_idx)
3367 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
3369 /* Update the monsters */
3370 p_ptr->update |= (PU_DISTANCE);
3372 /* Update sub-windows */
3373 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3376 /* Possible disturb */
3379 (disturb_near && (m_ptr->mflag & MFLAG_VIEW)) ||
3380 (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)))
3383 if (is_hostile(m_ptr))
3387 /* Scan all objects in the grid */
3388 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3392 /* Acquire object */
3393 o_ptr = &o_list[this_o_idx];
3395 /* Acquire next object */
3396 next_o_idx = o_ptr->next_o_idx;
3399 if (o_ptr->tval == TV_GOLD) continue;
3402 * Skip "real" corpses and statues, to avoid extreme
3403 * silliness like a novice rogue pockets full of statues
3406 if ((o_ptr->tval == TV_CORPSE) ||
3407 (o_ptr->tval == TV_STATUE)) continue;
3409 /* Take or Kill objects on the floor */
3410 if ((r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3411 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)))
3413 u32b flgs[TR_FLAG_SIZE];
3419 char o_name[MAX_NLEN];
3421 /* Extract some flags */
3422 object_flags(o_ptr, flgs);
3424 /* Acquire the object name */
3425 object_desc(o_name, o_ptr, TRUE, 3);
3427 /* Acquire the monster name */
3428 monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
3430 /* React to objects that hurt the monster */
3431 if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
3432 if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
3433 if (have_flag(flgs, TR_SLAY_TROLL)) flg3 |= (RF3_TROLL);
3434 if (have_flag(flgs, TR_KILL_TROLL)) flg3 |= (RF3_TROLL);
3435 if (have_flag(flgs, TR_KILL_GIANT)) flg3 |= (RF3_GIANT);
3436 if (have_flag(flgs, TR_SLAY_GIANT)) flg3 |= (RF3_GIANT);
3437 if (have_flag(flgs, TR_SLAY_ORC)) flg3 |= (RF3_ORC);
3438 if (have_flag(flgs, TR_KILL_ORC)) flg3 |= (RF3_ORC);
3439 if (have_flag(flgs, TR_SLAY_DEMON)) flg3 |= (RF3_DEMON);
3440 if (have_flag(flgs, TR_KILL_DEMON)) flg3 |= (RF3_DEMON);
3441 if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
3442 if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
3443 if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
3444 if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
3445 if (have_flag(flgs, TR_SLAY_EVIL)) flg3 |= (RF3_EVIL);
3446 if (have_flag(flgs, TR_KILL_EVIL)) flg3 |= (RF3_EVIL);
3447 if (have_flag(flgs, TR_SLAY_HUMAN)) flg2 |= (RF2_HUMAN);
3448 if (have_flag(flgs, TR_KILL_HUMAN)) flg2 |= (RF2_HUMAN);
3450 /* The object cannot be picked up by the monster */
3451 if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
3454 /* Only give a message for "take_item" */
3455 if ((r_ptr->flags2 & (RF2_TAKE_ITEM)) && (r_ptr->flags2 & (RF2_STUPID)))
3458 did_take_item = TRUE;
3460 /* Describe observable situations */
3461 if (m_ptr->ml && player_can_see_bold(ny, nx))
3463 /* Dump a message */
3465 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£", m_name, o_name);
3467 msg_format("%^s tries to pick up %s, but fails.", m_name, o_name);
3473 /* Pick up the item */
3474 else if (r_ptr->flags2 & RF2_TAKE_ITEM)
3477 did_take_item = TRUE;
3479 /* Describe observable situations */
3480 if (player_can_see_bold(ny, nx))
3482 /* Dump a message */
3484 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3486 msg_format("%^s picks up %s.", m_name, o_name);
3491 /* Excise the object */
3492 excise_object_idx(this_o_idx);
3497 /* Forget location */
3498 o_ptr->iy = o_ptr->ix = 0;
3500 /* Memorize monster */
3501 o_ptr->held_m_idx = m_idx;
3504 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3507 m_ptr->hold_o_idx = this_o_idx;
3510 /* Destroy the item if not a pet */
3511 else if (!is_pet(m_ptr))
3514 did_kill_item = TRUE;
3516 /* Describe observable situations */
3517 if (player_has_los_bold(ny, nx))
3519 /* Dump a message */
3521 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3523 msg_format("%^s destroys %s.", m_name, o_name);
3528 /* Delete the object */
3529 delete_object_idx(this_o_idx);
3535 /* Stop when done */
3540 * Forward movements failed, but now received LOS attack!
3541 * Try to flow by smell.
3543 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3544 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3546 /* If we haven't done anything, try casting a spell again */
3547 if (!do_turn && !do_move && !m_ptr->monfear && !(p_ptr->riding == m_idx) && aware)
3549 /* Try to cast spell again */
3550 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
3552 if (make_attack_spell(m_idx)) return;
3557 /* Notice changes in view */
3560 /* Update some things */
3561 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
3564 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3567 /* Notice changes in view */
3568 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LD_MASK | RF7_HAS_DARK_1 | RF7_HAS_DARK_2))
3569 || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !p_ptr->inside_battle)))
3571 /* Update some things */
3572 p_ptr->update |= (PU_MON_LITE);
3575 /* Learn things from observable monster */
3576 if (m_ptr->ml && is_original_ap(m_ptr))
3578 /* Monster opened a door */
3579 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3581 /* Monster bashed a door */
3582 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3584 /* Monster tried to pick something up */
3585 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3587 /* Monster tried to crush something */
3588 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3590 /* Monster pushed past another monster */
3591 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3593 /* Monster passed through a wall */
3594 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3596 /* Monster destroyed a wall */
3597 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3601 /* Hack -- get "bold" if out of options */
3602 if (!do_turn && !do_move && m_ptr->monfear && aware)
3604 /* No longer afraid */
3607 /* Message if seen */
3612 /* Acquire the monster name */
3613 monster_desc(m_name, m_ptr, 0);
3615 /* Dump a message */
3617 msg_format("%^s¤ÏÀ襤¤ò·è°Õ¤·¤¿¡ª", m_name);
3619 msg_format("%^s turns to fight!", m_name);
3622 /* Redraw (later) if needed */
3623 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
3625 chg_virtue(V_COMPASSION, -1);
3628 /* XXX XXX XXX Actually do something now (?) */
3633 * Process all the "live" monsters, once per game turn.
3635 * During each game turn, we scan through the list of all the "live" monsters,
3636 * (backwards, so we can excise any "freshly dead" monsters), energizing each
3637 * monster, and allowing fully energized monsters to move, attack, pass, etc.
3639 * Note that monsters can never move in the monster array (except when the
3640 * "compact_monsters()" function is called by "dungeon()" or "save_player()").
3642 * This function is responsible for at least half of the processor time
3643 * on a normal system with a "normal" amount of monsters and a player doing
3646 * When the player is resting, virtually 90% of the processor time is spent
3647 * in this function, and its children, "process_monster()" and "make_move()".
3649 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",
3650 * especially when the player is running.
3652 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"
3653 * monsters while they are still being "born". A monster is "fresh" only
3654 * during the turn in which it is created, and we use the "hack_m_idx" to
3655 * determine if the monster is yet to be processed during the current turn.
3657 * Note the special "MFLAG_NICE" flag, which allows the player to get one
3658 * move before any "nasty" monsters get to use their spell attacks.
3660 * Note that when the "knowledge" about the currently tracked monster
3661 * changes (flags, attacks, spells), we induce a redraw of the monster
3664 void process_monsters(void)
3671 monster_type *m_ptr;
3672 monster_race *r_ptr;
3674 int old_monster_race_idx;
3676 u32b old_r_flags1 = 0L;
3677 u32b old_r_flags2 = 0L;
3678 u32b old_r_flags3 = 0L;
3679 u32b old_r_flags4 = 0L;
3680 u32b old_r_flags5 = 0L;
3681 u32b old_r_flags6 = 0L;
3682 u32b old_r_flagsr = 0L;
3684 byte old_r_blows0 = 0;
3685 byte old_r_blows1 = 0;
3686 byte old_r_blows2 = 0;
3687 byte old_r_blows3 = 0;
3689 byte old_r_cast_spell = 0;
3693 /* Clear monster fighting indicator */
3696 /* Memorize old race */
3697 old_monster_race_idx = p_ptr->monster_race_idx;
3699 /* Acquire knowledge */
3700 if (p_ptr->monster_race_idx)
3702 /* Acquire current monster */
3703 r_ptr = &r_info[p_ptr->monster_race_idx];
3705 /* Memorize flags */
3706 old_r_flags1 = r_ptr->r_flags1;
3707 old_r_flags2 = r_ptr->r_flags2;
3708 old_r_flags3 = r_ptr->r_flags3;
3709 old_r_flags4 = r_ptr->r_flags4;
3710 old_r_flags5 = r_ptr->r_flags5;
3711 old_r_flags6 = r_ptr->r_flags6;
3712 old_r_flagsr = r_ptr->r_flagsr;
3714 /* Memorize blows */
3715 old_r_blows0 = r_ptr->r_blows[0];
3716 old_r_blows1 = r_ptr->r_blows[1];
3717 old_r_blows2 = r_ptr->r_blows[2];
3718 old_r_blows3 = r_ptr->r_blows[3];
3720 /* Memorize castings */
3721 old_r_cast_spell = r_ptr->r_cast_spell;
3725 /* Process the monsters (backwards) */
3726 for (i = m_max - 1; i >= 1; i--)
3728 /* Access the monster */
3730 r_ptr = &r_info[m_ptr->r_idx];
3732 /* Handle "leaving" */
3733 if (p_ptr->leaving) break;
3735 /* Ignore "dead" monsters */
3736 if (!m_ptr->r_idx) continue;
3738 if (p_ptr->wild_mode) continue;
3741 /* Handle "fresh" monsters */
3742 if (m_ptr->mflag & MFLAG_BORN)
3744 /* No longer "fresh" */
3745 m_ptr->mflag &= ~(MFLAG_BORN);
3751 /* Hack -- Require proximity */
3752 if (m_ptr->cdis >= AAF_LIMIT) continue;
3755 /* Access the location */
3759 /* Flow by smell is allowed */
3760 if (!p_ptr->no_flowed)
3762 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
3765 /* Assume no move */
3768 /* Handle "sensing radius" */
3769 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
3771 /* We can "sense" the player */
3775 /* Handle "sight" and "aggravation" */
3776 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3777 (player_has_los_bold(fy, fx) || (p_ptr->cursed & TRC_AGGRAVATE)))
3779 /* We can "see" or "feel" the player */
3783 #if 0 /* (cave[py][px].when == cave[fy][fx].when) is always FALSE... */
3784 /* Hack -- Monsters can "smell" the player from far away */
3785 /* Note that most monsters have "aaf" of "20" or so */
3786 else if (!(m_ptr->mflag2 & MFLAG2_NOFLOW) &&
3787 (cave_floor_bold(py, px) || (cave[py][px].feat == FEAT_TREES)) &&
3788 (cave[py][px].when == cave[fy][fx].when) &&
3789 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3790 (cave[fy][fx].dist < r_ptr->aaf))
3792 /* We can "smell" the player */
3796 else if (m_ptr->target_y) test = TRUE;
3799 if (!test) continue;
3802 if (p_ptr->riding == i)
3803 speed = p_ptr->pspeed;
3806 speed = m_ptr->mspeed;
3808 /* Monsters move quickly in Nightmare mode */
3809 if (ironman_nightmare) speed += 5;
3811 if (m_ptr->fast) speed += 10;
3812 if (m_ptr->slow) speed -= 10;
3815 /* Give this monster some energy */
3816 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
3818 /* Not enough energy to move */
3819 if (m_ptr->energy_need > 0) continue;
3821 /* Use up "some" energy */
3822 m_ptr->energy_need += ENERGY_NEED();
3825 /* Save global index */
3828 /* Process the monster */
3831 reset_target(m_ptr);
3833 /* Give up flow_by_smell when it might useless */
3834 if (p_ptr->no_flowed && one_in_(3))
3835 m_ptr->mflag2 |= MFLAG2_NOFLOW;
3837 /* Hack -- notice death or departure */
3838 if (!p_ptr->playing || p_ptr->is_dead) break;
3840 /* Notice leaving */
3841 if (p_ptr->leaving) break;
3844 /* Reset global index */
3848 /* Tracking a monster race (the same one we were before) */
3849 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3851 /* Acquire monster race */
3852 r_ptr = &r_info[p_ptr->monster_race_idx];
3854 /* Check for knowledge change */
3855 if ((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) ||
3861 (old_r_flagsr != r_ptr->r_flagsr) ||
3862 (old_r_blows0 != r_ptr->r_blows[0]) ||
3863 (old_r_blows1 != r_ptr->r_blows[1]) ||
3864 (old_r_blows2 != r_ptr->r_blows[2]) ||
3865 (old_r_blows3 != r_ptr->r_blows[3]) ||
3866 (old_r_cast_spell != r_ptr->r_cast_spell))
3869 p_ptr->window |= (PW_MONSTER);
3876 bool process_the_world(int num, int who, bool vs_player)
3878 monster_type *m_ptr = &m_list[hack_m_idx]; /* the world monster */
3880 if(world_monster) return (FALSE);
3885 monster_desc(m_name, m_ptr, 0);
3889 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
3891 msg_format("%s yells 'The World! Time has stopped!'", m_name);
3895 msg_print("¡Ö»þ¤è¡ª¡×");
3897 msg_format("%s yells 'Time!'", m_name);
3899 else msg_print("hek!");
3904 /* This monster cast spells */
3905 world_monster = hack_m_idx;
3907 if (vs_player) do_cmd_redraw();
3911 if(!m_ptr->r_idx) break;
3912 process_monster(world_monster);
3914 reset_target(m_ptr);
3917 if (p_ptr->notice) notice_stuff();
3920 if (p_ptr->update) update_stuff();
3923 if (p_ptr->redraw) redraw_stuff();
3926 if (p_ptr->window) window_stuff();
3929 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
3933 p_ptr->redraw |= (PR_MAP);
3935 /* Update monsters */
3936 p_ptr->update |= (PU_MONSTERS);
3939 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3942 if (vs_player || los(py, px, m_ptr->fy, m_ptr->fx))
3945 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
3947 msg_print("You feel time flowing around you once more.");
3958 void monster_gain_exp(int m_idx, int s_idx)
3960 monster_type *m_ptr = &m_list[m_idx];
3961 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3962 monster_race *s_ptr = &r_info[s_idx];
3965 if (p_ptr->inside_battle) return;
3967 if (!r_ptr->next_exp) return;
3969 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
3970 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
3971 if (!dun_level) new_exp /= 5;
3972 m_ptr->exp += new_exp;
3973 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return;
3975 if (m_ptr->exp >= r_ptr->next_exp)
3978 int old_hp = m_ptr->hp;
3979 int old_maxhp = m_ptr->max_maxhp;
3980 int old_r_idx = m_ptr->r_idx;
3981 byte old_sub_align = m_ptr->sub_align;
3983 /* Hack -- Reduce the racial counter of previous monster */
3984 real_r_ptr(m_ptr)->cur_num--;
3986 monster_desc(m_name, m_ptr, 0);
3987 m_ptr->r_idx = r_ptr->next_r_idx;
3989 /* Count the monsters on the level */
3990 real_r_ptr(m_ptr)->cur_num++;
3992 m_ptr->ap_r_idx = m_ptr->r_idx;
3993 r_ptr = &r_info[m_ptr->r_idx];
3995 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3997 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
4001 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
4003 if (ironman_nightmare)
4005 u32b hp = m_ptr->max_maxhp * 2L;
4007 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
4009 m_ptr->maxhp = m_ptr->max_maxhp;
4010 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
4012 /* Extract the monster base speed */
4013 m_ptr->mspeed = get_mspeed(r_ptr);
4015 /* Sub-alignment of a monster */
4016 if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
4017 m_ptr->sub_align = old_sub_align;
4020 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
4021 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
4022 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
4027 if (is_pet(m_ptr) || m_ptr->ml)
4030 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
4032 msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
4034 r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
4036 /* Now you feel very close to this pet. */
4037 m_ptr->parent_m_idx = 0;
4039 update_mon(m_idx, FALSE);
4040 lite_spot(m_ptr->fy, m_ptr->fx);
4042 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;