3 /* Purpose: Monster spells and movement */
6 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
14 * This file has several additions to it by Keldon Jones (keldon@umr.edu)
15 * to improve the general quality of the AI (version 0.1.1).
20 #define SPEAK_CHANCE 8
24 extern cptr silly_attacks[MAX_SILLY_ATTACK];
27 * Calculate the direction to the next enemy
29 static bool get_enemy_dir(int m_idx, int *mm)
37 monster_type *m_ptr = &m_list[m_idx];
38 monster_race *r_ptr = &r_info[m_ptr->r_idx];
42 if (riding_t_m_idx && (m_ptr->fx == px) && (m_ptr->fy == py))
44 y = m_list[riding_t_m_idx].fy;
45 x = m_list[riding_t_m_idx].fx;
47 else if (is_pet(m_ptr) && pet_t_m_idx)
49 y = m_list[pet_t_m_idx].fy;
50 x = m_list[pet_t_m_idx].fx;
54 if (p_ptr->inside_battle)
56 start = randint(m_max-1)+m_max;
57 if(rand_int(2)) plus = -1;
59 else start = m_max + 1;
61 /* Scan thru all monsters */
62 for (i = start; ((i < start + m_max) && (i > start - m_max)); i+=plus)
64 int dummy = (i % m_max);
70 t_ptr = &m_list[t_idx];
72 /* The monster itself isn't a target */
73 if (t_ptr == m_ptr) continue;
75 /* Paranoia -- Skip dead monsters */
76 if (!t_ptr->r_idx) continue;
80 /* Hack -- only fight away from player */
81 if (p_ptr->pet_follow_distance < 0)
83 /* No fighting near player */
84 if (t_ptr->cdis <= (0 - p_ptr->pet_follow_distance))
89 /* Hack -- no fighting away from player */
90 else if ((m_ptr->cdis < t_ptr->cdis) &&
91 (t_ptr->cdis > p_ptr->pet_follow_distance))
96 if (r_ptr->aaf < t_ptr->cdis) continue;
99 /* Monster must be 'an enemy' */
100 if (!are_enemies(m_ptr, t_ptr)) continue;
102 can_pass_wall = (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) || ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding)));
104 /* Monster must be projectable if we can't pass through walls */
105 if (!can_pass_wall &&
106 !projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
111 !in_disintegration_range(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
116 /* OK -- we've got a target */
122 if (!x && !y) return FALSE;
125 /* Extract the direction */
130 if ((y < 0) && (x == 0))
137 else if ((y > 0) && (x == 0))
144 else if ((x > 0) && (y == 0))
151 else if ((x < 0) && (y == 0))
158 else if ((y < 0) && (x < 0))
165 else if ((y < 0) && (x > 0))
172 else if ((y > 0) && (x < 0))
179 else if ((y > 0) && (x > 0))
186 /* Found a monster */
192 * Hack, based on mon_take_hit... perhaps all monster attacks on
193 * other monsters should use this?
195 void mon_take_hit_mon(bool is_psy_spear, int m_idx, int dam, bool *fear, cptr note, int who)
197 monster_type *m_ptr = &m_list[m_idx];
199 monster_race *r_ptr = &r_info[m_ptr->r_idx];
203 bool seen = m_ptr->ml;
205 /* Can the player be aware of this attack? */
206 bool known = (m_ptr->cdis <= MAX_SIGHT);
208 /* Extract monster name */
209 monster_desc(m_name, m_ptr, 0);
211 /* Redraw (later) if needed */
212 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
213 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
218 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
220 if (m_ptr->invulner && rand_int(PENETRATE_INVULNERABILITY))
225 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
227 msg_format("%^s is unharmed.", m_name);
235 if (r_ptr->flags3 & RF3_RES_ALL)
240 if((dam == 0) && (randint(3) == 1)) dam = 1;
247 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Ê¤¤¡£", m_name);
249 msg_format("%^s is unharmed.", m_name);
260 /* It is dead now... or is it? */
263 if (((r_ptr->flags1 & RF1_UNIQUE) ||
264 (r_ptr->flags7 & RF7_UNIQUE_7) ||
265 (r_ptr->flags1 & RF1_QUESTOR)) &&
266 !p_ptr->inside_battle)
273 if (!monster_living(r_ptr))
284 monster_desc(m_name, m_ptr, 0x100);
285 /* Unseen death by normal attack */
290 /* Death by special attack */
294 msg_format("%^s%s", m_name, note);
296 msg_format("%^s%s", m_name, note);
300 /* Death by normal attack -- nonliving monster */
301 else if (!monster_living(r_ptr))
304 msg_format("%^s¤ÏÇ˲õ¤µ¤ì¤¿¡£", m_name);
306 msg_format("%^s is destroyed.", m_name);
310 /* Death by normal attack -- living monster */
314 msg_format("%^s¤Ï»¦¤µ¤ì¤¿¡£", m_name);
316 msg_format("%^s is killed.", m_name);
322 monster_gain_exp(who, m_ptr->r_idx);
324 /* Generate treasure */
325 monster_death(m_idx, FALSE);
327 /* Delete the monster */
328 delete_monster_idx(m_idx);
333 /* Monster is dead */
340 /* Mega-Hack -- Pain cancels fear */
341 if (m_ptr->monfear && (dam > 0))
343 int tmp = randint(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) && (rand_int(10) < percentage)) ||
376 ((dam >= m_ptr->hp) && (rand_int(100) < 80)))
378 /* Hack -- note fear */
381 /* XXX XXX XXX Hack -- Add some timed fear */
382 m_ptr->monfear += (randint(10) +
383 (((dam >= m_ptr->hp) && (percentage > 7)) ?
384 20 : ((11 - percentage) * 5)));
388 #endif /* ALLOW_FEAR */
390 if ((dam > 0) && !is_pet(m_ptr) && !is_friendly(m_ptr) && (who != m_idx))
392 if (is_pet(&m_list[who]) && (m_ptr->target_y != py) && (m_ptr->target_x != px))
394 set_target(m_ptr, m_list[who].fy, m_list[who].fx);
398 if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
402 /* Extract monster name */
403 monster_desc(m_name, m_ptr, 0);
405 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
406 if (rakuba((dam > 200) ? 200 : dam, FALSE))
409 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
411 msg_format("You have thrown off from %s!", m_name);
422 * Returns whether a given monster will try to run from the player.
424 * Monsters will attempt to avoid very powerful players. See below.
426 * Because this function is called so often, little details are important
427 * for efficiency. Like not using "mod" or "div" when possible. And
428 * attempting to check the conditions in an optimal order. Note that
429 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.
431 * Note that this function is responsible for about one to five percent
432 * of the processor use in normal conditions...
434 static int mon_will_run(int m_idx)
436 monster_type *m_ptr = &m_list[m_idx];
440 monster_race *r_ptr = &r_info[m_ptr->r_idx];
449 /* Friends can be commanded to avoid the player */
452 /* Are we trying to avoid the player? */
453 return ((p_ptr->pet_follow_distance < 0) &&
454 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
457 /* Keep monsters from running too far away */
458 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
460 /* All "afraid" monsters will run away */
461 if (m_ptr->monfear) return (TRUE);
465 /* Nearby monsters will not become terrified */
466 if (m_ptr->cdis <= 5) return (FALSE);
468 /* Examine player power (level) */
471 /* Examine monster power (level plus morale) */
472 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
474 /* Optimize extreme cases below */
475 if (m_lev > p_lev + 4) return (FALSE);
476 if (m_lev + 4 <= p_lev) return (TRUE);
478 /* Examine player health */
482 /* Examine monster health */
484 m_mhp = m_ptr->maxhp;
486 /* Prepare to optimize the calculation */
487 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
488 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
490 /* Strong players scare strong monsters */
491 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
495 /* Assume no terror */
503 * Choose the "best" direction for "flowing"
505 * Note that ghosts and rock-eaters are never allowed to "flow",
506 * since they should move directly towards the player.
508 * Prefer "non-diagonal" directions, but twiddle them a little
509 * to angle slightly towards the player's actual location.
511 * Allow very perceptive monsters to track old "spoor" left by
512 * previous locations occupied by the player. This will tend
513 * to have monsters end up either near the player or on a grid
514 * recently occupied by the player (and left via "teleport").
516 * Note that if "smell" is turned on, all monsters get vicious.
518 * Also note that teleporting away from a location will cause
519 * the monsters who were chasing you to converge on that location
520 * as long as you are still near enough to "annoy" them without
521 * being close enough to chase directly. I have no idea what will
522 * happen if you combine "smell" with low "aaf" values.
524 static bool get_moves_aux(int m_idx, int *yp, int *xp)
526 int i, y, x, y1, x1, best;
529 bool use_sound = FALSE;
530 bool use_scent = FALSE;
532 monster_type *m_ptr = &m_list[m_idx];
533 monster_race *r_ptr = &r_info[m_ptr->r_idx];
535 /* Monster flowing disabled */
536 if (stupid_monsters) return (FALSE);
538 /* Monster can go through rocks */
539 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) return (FALSE);
540 if (r_ptr->flags2 & RF2_KILL_WALL) return (FALSE);
541 if (!cave_floor_bold(py, px) && (cave[py][px].feat != FEAT_TREES)) return (FALSE);
543 /* Monster location */
547 /* Hack -- Player can see us, run towards him */
548 if (player_has_los_bold(y1, x1)) return (FALSE);
551 c_ptr = &cave[y1][x1];
553 /* If we can hear noises, advance towards them */
560 /* Otherwise, try to follow a scent trail */
561 else if (c_ptr->when)
564 if (cave[py][px].when - c_ptr->when > 127) return (FALSE);
570 /* Otherwise, advance blindly */
576 /* Check nearby grids, diagonals first */
577 for (i = 7; i >= 0; i--)
579 /* Get the location */
583 /* Ignore locations off of edge */
584 if (!in_bounds2(y, x)) continue;
588 /* We're following a scent trail */
591 int when = c_ptr->when;
593 /* Accept younger scent */
594 if (best > when) continue;
598 /* We're using sound */
603 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
605 else cost = c_ptr->cost;
607 /* Accept louder sounds */
608 if ((cost == 0) || (best < cost)) continue;
612 /* Hack -- Save the "twiddled" location */
613 (*yp) = py + 16 * ddy_ddd[i];
614 (*xp) = px + 16 * ddx_ddd[i];
617 /* No legal move (?) */
618 if (best == 999 || best == 0) return (FALSE);
626 * Provide a location to flee to, but give the player a wide berth.
628 * A monster may wish to flee to a location that is behind the player,
629 * but instead of heading directly for it, the monster should "swerve"
630 * around the player so that he has a smaller chance of getting hit.
632 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
634 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
635 int dist = 0, score = -1;
638 monster_type *m_ptr = &m_list[m_idx];
640 /* Monster flowing disabled */
641 if (stupid_monsters) return (FALSE);
643 /* Monster location */
647 /* Desired destination */
651 /* Check nearby grids, diagonals first */
652 for (i = 7; i >= 0; i--)
656 /* Get the location */
660 /* Ignore locations off of edge */
661 if (!in_bounds2(y, x)) continue;
663 if (cave[y][x].dist < dist) continue;
665 /* Calculate distance of this grid from our destination */
666 dis = distance(y, x, y1, x1);
668 /* Score this grid */
669 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
671 /* No negative scores */
674 /* Ignore lower scores */
675 if (s < score) continue;
677 /* Save the score and time */
678 dist = cave[y][x].dist;
681 /* Save the location */
686 /* No legal move (?) */
687 if (score == -1) return (FALSE);
698 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
701 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
702 * offsets of all the locations with a distance of n from a central point,
703 * with an offset of (0,0) indicating no more offsets at this distance.
705 * This is, of course, fairly unreadable, but it eliminates multiple loops
706 * from the previous version.
708 * It is probably better to replace these arrays with code to compute
709 * the relevant arrays, even if the storage is pre-allocated in hard
710 * coded sizes. At the very least, code should be included which is
711 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
713 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
715 * These arrays could be combined into two big arrays, using sub-arrays
716 * to hold the offsets and lengths of each portion of the sub-arrays, and
717 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
721 static sint d_off_y_0[] =
724 static sint d_off_x_0[] =
728 static sint d_off_y_1[] =
729 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
731 static sint d_off_x_1[] =
732 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
735 static sint d_off_y_2[] =
736 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
738 static sint d_off_x_2[] =
739 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
742 static sint d_off_y_3[] =
743 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
746 static sint d_off_x_3[] =
747 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
751 static sint d_off_y_4[] =
752 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
753 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
755 static sint d_off_x_4[] =
756 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
757 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
760 static sint d_off_y_5[] =
761 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
762 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
765 static sint d_off_x_5[] =
766 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
767 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
771 static sint d_off_y_6[] =
772 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
773 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
776 static sint d_off_x_6[] =
777 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
778 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
779 -3, 2, 3, -1, 0, 1, 0 };
782 static sint d_off_y_7[] =
783 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
784 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
785 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
787 static sint d_off_x_7[] =
788 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
789 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
790 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
794 static sint d_off_y_8[] =
795 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
796 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
797 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
800 static sint d_off_x_8[] =
801 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
802 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
803 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
807 static sint d_off_y_9[] =
808 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
809 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
810 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
811 7, 8, 8, 8, 8, 9, 9, 9, 0 };
813 static sint d_off_x_9[] =
814 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
815 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
816 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
817 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
820 static sint *dist_offsets_y[10] =
822 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
823 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
826 static sint *dist_offsets_x[10] =
828 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
829 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
833 * Choose a "safe" location near a monster for it to run toward.
835 * A location is "safe" if it can be reached quickly and the player
836 * is not able to fire into it (it isn't a "clean shot"). So, this will
837 * cause monsters to "duck" behind walls. Hopefully, monsters will also
838 * try to run towards corridor openings if they are in a room.
840 * This function may take lots of CPU time if lots of monsters are
843 * Return TRUE if a safe location is available.
845 static bool find_safety(int m_idx, int *yp, int *xp)
847 monster_type *m_ptr = &m_list[m_idx];
852 int y, x, dy, dx, d, dis, i;
853 int gy = 0, gx = 0, gdis = 0;
860 /* Start with adjacent locations, spread further */
861 for (d = 1; d < 10; d++)
863 /* Get the lists of points with a distance d from (fx, fy) */
864 y_offsets = dist_offsets_y[d];
865 x_offsets = dist_offsets_x[d];
867 /* Check the locations */
868 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
870 i++, dx = x_offsets[i], dy = y_offsets[i])
875 /* Skip illegal locations */
876 if (!in_bounds(y, x)) continue;
880 /* Skip locations in a wall */
881 if (!cave_floor_grid(c_ptr)) continue;
883 /* Check for "availability" (if monsters can flow) */
884 if (!stupid_monsters && !(m_ptr->mflag2 & MFLAG_NOFLOW))
886 /* Ignore grids very far from the player */
887 if (c_ptr->when < cave[py][px].when) continue;
889 /* Ignore too-distant grids */
890 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
893 /* Check for absence of shot (more or less) */
894 if (clean_shot(fy, fx, y, x, FALSE))
897 /* Calculate distance from player */
898 dis = distance(y, x, py, px);
900 /* Remember if further than previous */
905 if (!player_has_los_grid(c_ptr))
917 /* Check for success */
918 if (gdis > d + m_ptr->cdis)
924 /* Found safe place */
931 /* Save farthest location from player in LOS of monster */
935 /* Hack - return TRUE anyway. */
941 * Choose a good hiding place near a monster for it to run toward.
943 * Pack monsters will use this to "ambush" the player and lure him out
944 * of corridors into open space so they can swarm him.
946 * Return TRUE if a good location is available.
948 static bool find_hiding(int m_idx, int *yp, int *xp)
950 monster_type *m_ptr = &m_list[m_idx];
955 int y, x, dy, dx, d, dis, i;
956 int gy = 0, gx = 0, gdis = 999;
958 sint *y_offsets, *x_offsets;
962 /* Start with adjacent locations, spread further */
963 for (d = 1; d < 10; d++)
965 /* Get the lists of points with a distance d from (fx, fy) */
966 y_offsets = dist_offsets_y[d];
967 x_offsets = dist_offsets_x[d];
969 /* Check the locations */
970 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
972 i++, dx = x_offsets[i], dy = y_offsets[i])
977 /* Skip illegal locations */
978 if (!in_bounds(y, x)) continue;
982 /* Skip occupied locations */
983 if (!cave_empty_grid(c_ptr)) continue;
985 /* Check for hidden, available grid */
986 if (!player_has_los_grid(c_ptr) && clean_shot(fy, fx, y, x, FALSE))
988 /* Calculate distance from player */
989 dis = distance(y, x, py, px);
991 /* Remember if closer than previous */
992 if (dis < gdis && dis >= 2)
1001 /* Check for success */
1008 /* Found good place */
1019 * Choose "logical" directions for monster movement
1021 static bool get_moves(int m_idx, int *mm)
1023 monster_type *m_ptr = &m_list[m_idx];
1024 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1030 bool will_run = mon_will_run(m_idx);
1032 bool no_flow = ((m_ptr->mflag2 & MFLAG_NOFLOW) && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1035 /* Flow towards the player */
1036 if (!stupid_monsters && !no_flow)
1038 /* Flow towards the player */
1039 (void)get_moves_aux(m_idx, &y2, &x2);
1042 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
1044 /* Extract the "pseudo-direction" */
1048 if (!stupid_monsters && !will_run && is_hostile(m_ptr) &&
1049 (r_ptr->flags1 & RF1_FRIENDS) &&
1050 (los(m_ptr->fy, m_ptr->fx, py, px) ||
1051 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1054 * Animal packs try to get the player out of corridors
1055 * (...unless they can move through walls -- TY)
1057 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1058 !(r_ptr->flags2 & RF2_KILL_WALL))
1062 /* Count room grids next to player */
1063 for (i = 0; i < 8; i++)
1065 int x = px + ddx_ddd[i];
1066 int y = py + ddy_ddd[i];
1070 if (!in_bounds2(y, x)) continue;
1072 c_ptr = &cave[y][x];
1075 if (((cave_floor_grid(c_ptr)) || ((c_ptr->feat & 0x60) == 0x60)) &&
1076 monster_can_cross_terrain(c_ptr->feat, r_ptr))
1078 /* One more room grid */
1082 if (cave[py][px].info & CAVE_ROOM) room -= 2;
1083 if (!r_ptr->flags4 && !r_ptr->flags5 && !r_ptr->flags6) room -= 2;
1085 /* Not in a room and strong player */
1086 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
1087 (p_ptr->mhp + p_ptr->msp))
1089 /* Find hiding place */
1090 if (find_hiding(m_idx, &y, &x)) done = TRUE;
1094 /* Monster groups try to surround the player */
1095 if (!done && (cave[m_ptr->fy][m_ptr->fx].dist < 3))
1099 /* Find an empty square near the player to fill */
1100 for (i = 0; i < 8; i++)
1102 /* Pick squares near player (semi-randomly) */
1103 y2 = py + ddy_ddd[(m_idx + i) & 7];
1104 x2 = px + ddx_ddd[(m_idx + i) & 7];
1106 /* Already there? */
1107 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
1109 /* Attack the player */
1116 if (!in_bounds2(y2, x2)) continue;
1118 /* Ignore filled grids */
1119 c_ptr = &cave[y2][x2];
1120 if (!cave_empty_grid(c_ptr)) continue;
1122 /* Try to fill this hole */
1126 /* Extract the new "pseudo-direction" */
1135 /* Apply fear if possible and necessary */
1136 if ((stupid_monsters || is_pet(m_ptr)) && will_run)
1138 /* XXX XXX Not very "smart" */
1143 if (!done && will_run)
1145 /* Try to find safe place */
1146 if (!find_safety(m_idx, &y, &x))
1148 /* This is not a very "smart" method XXX XXX */
1154 /* Attempt to avoid the player */
1155 if (!stupid_monsters && !no_flow)
1157 /* Adjust movement */
1158 (void)get_fear_moves_aux(m_idx, &y, &x);
1165 if (!stupid_monsters)
1167 /* Check for no move */
1168 if (!x && !y) return (FALSE);
1172 /* Extract the "absolute distances" */
1176 /* Do something weird */
1177 if (y < 0) move_val += 8;
1178 if (x > 0) move_val += 4;
1180 /* Prevent the diamond maneuvre */
1186 else if (ax > (ay << 1))
1191 /* Extract some directions */
1336 /* Wants to move... */
1341 static int check_hit2(int power, int level, int ac, int stun)
1345 /* Percentile dice */
1348 if (stun && one_in_(2)) return FALSE;
1350 /* Hack -- Always miss or hit */
1351 if (k < 10) return (k < 5);
1353 /* Calculate the "attack quality" */
1354 i = (power + (level * 3));
1356 /* Power and Level compete against Armor */
1357 if ((i > 0) && (randint(i) > ((ac * 3) / 4))) return (TRUE);
1364 /* Monster attacks monster */
1365 static bool monst_attack_monst(int m_idx, int t_idx)
1367 monster_type *m_ptr = &m_list[m_idx];
1368 monster_type *t_ptr = &m_list[t_idx];
1370 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1371 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1375 char m_name[80], t_name[80];
1376 char ddesc[80], temp[80];
1377 bool blinked, heal_effect;
1378 bool explode = FALSE, touched = FALSE, fear = FALSE;
1379 int y_saver = t_ptr->fy;
1380 int x_saver = t_ptr->fx;
1382 bool see_m = m_ptr->ml;
1383 bool see_t = t_ptr->ml;
1384 bool see_either = see_m || see_t;
1386 /* Can the player be aware of this attack? */
1387 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1388 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1390 /* Cannot attack self */
1391 if (m_idx == t_idx) return FALSE;
1393 /* Not allowed to attack */
1394 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1396 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1404 /* Extract the effective monster level */
1405 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1407 /* Get the monster name (or "it") */
1408 monster_desc(m_name, m_ptr, 0);
1410 /* Get the monster name (or "it") */
1411 monster_desc(t_name, t_ptr, 0);
1413 /* Get the "died from" information (i.e. "a kobold") */
1414 monster_desc(ddesc, m_ptr, 0x88);
1416 /* Assume no blink */
1419 if (!see_either && known)
1424 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
1426 /* Scan through all four blows */
1427 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1429 bool obvious = FALSE;
1436 /* Extract the attack infomation */
1437 int effect = r_ptr->blow[ap_cnt].effect;
1438 int method = r_ptr->blow[ap_cnt].method;
1439 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1440 int d_side = r_ptr->blow[ap_cnt].d_side;
1442 if (!m_ptr->r_idx) break;
1444 /* Stop attacking if the target dies! */
1445 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1448 /* Hack -- no more attacks */
1451 if (blinked) /* Stop! */
1456 /* Extract the attack "power" */
1459 case RBE_HURT: power = 60; break;
1460 case RBE_POISON: power = 5; break;
1461 case RBE_UN_BONUS: power = 20; break;
1462 case RBE_UN_POWER: power = 15; break;
1463 case RBE_EAT_GOLD: power = 5; break;
1464 case RBE_EAT_ITEM: power = 5; break;
1465 case RBE_EAT_FOOD: power = 5; break;
1466 case RBE_EAT_LITE: power = 5; break;
1467 case RBE_ACID: power = 0; break;
1468 case RBE_ELEC: power = 10; break;
1469 case RBE_FIRE: power = 10; break;
1470 case RBE_COLD: power = 10; break;
1471 case RBE_BLIND: power = 2; break;
1472 case RBE_CONFUSE: power = 10; break;
1473 case RBE_TERRIFY: power = 10; break;
1474 case RBE_PARALYZE: power = 2; break;
1475 case RBE_LOSE_STR: power = 0; break;
1476 case RBE_LOSE_DEX: power = 0; break;
1477 case RBE_LOSE_CON: power = 0; break;
1478 case RBE_LOSE_INT: power = 0; break;
1479 case RBE_LOSE_WIS: power = 0; break;
1480 case RBE_LOSE_CHR: power = 0; break;
1481 case RBE_LOSE_ALL: power = 2; break;
1482 case RBE_SHATTER: power = 60; break;
1483 case RBE_EXP_10: power = 5; break;
1484 case RBE_EXP_20: power = 5; break;
1485 case RBE_EXP_40: power = 5; break;
1486 case RBE_EXP_80: power = 5; break;
1487 case RBE_DISEASE: power = 5; break;
1488 case RBE_TIME: power = 5; break;
1489 case RBE_EXP_VAMP: power = 5; break;
1490 case RBE_DR_MANA: power = 5; break;
1491 case RBE_SUPERHURT: power = 60; break;
1496 if (!effect || check_hit2(power, rlev, ac, m_ptr->stunned))
1498 /* Describe the attack method */
1504 act = "%s¤ò²¥¤Ã¤¿¡£";
1516 act = "%s¤ò¿¨¤Ã¤¿¡£";
1518 act = "touches %s.";
1528 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1530 act = "punches %s.";
1540 act = "%s¤ò½³¤Ã¤¿¡£";
1552 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1564 act = "%s¤ò³ú¤ó¤À¡£";
1576 act = "%s¤ò»É¤·¤¿¡£";
1588 act = "%s¤ò»Â¤Ã¤¿¡£";
1590 act = "slashes %s.";
1599 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1611 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1613 act = "crushes %s.";
1623 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1625 act = "engulfs %s.";
1635 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1637 act = "charges %s.";
1647 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1649 act = "crawls on %s.";
1659 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1661 act = "drools on %s.";
1671 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1673 act = "spits on %s.";
1682 if (see_either) disturb(1, 0);
1697 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1699 act = "gazes at %s.";
1709 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1711 act = "wails at %s.";
1721 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1723 act = "releases spores at %s.";
1733 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1735 act = "projects XXX4's at %s.";
1745 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1747 act = "begs %s for money.";
1757 act = "%s¤òÉî¿«¤·¤¿¡£";
1759 act = "insults %s.";
1769 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1771 act = "moans at %s.";
1781 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1783 act = "sings to %s.";
1792 if (act && see_either)
1794 if (do_silly_attack)
1796 act = silly_attacks[rand_int(MAX_SILLY_ATTACK)];
1798 strfmt(temp, act, t_name);
1800 msg_format("%^s¤Ï%s", m_name, temp);
1802 msg_format("%^s %s", m_name, temp);
1807 /* Hack -- assume all attacks are obvious */
1810 /* Roll out the damage */
1811 damage = damroll(d_dice, d_side);
1813 /* Assume no healing effect */
1814 heal_effect = FALSE;
1818 /* Apply appropriate damage */
1830 if ((randint(rlev*2+250) > (ac+200)) || one_in_(13)) {
1831 int tmp_damage = damage-(damage*((ac < 150) ? ac : 150)/250);
1832 damage = MAX(damage, tmp_damage*2);
1838 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1868 if (randint(2) == 1) blinked = TRUE;
1915 pt = GF_OLD_SLEEP; /* sort of close... */
1933 earthquake(m_ptr->fy, m_ptr->fx, 8);
1966 /* Do damage if not exploding */
1969 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1970 (pt == GF_OLD_SLEEP ? r_ptr->level : damage), pt, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
1975 if ((monster_living(tr_ptr)) && (damage > 2))
1977 bool did_heal = FALSE;
1979 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
1982 m_ptr->hp += damroll(4, damage / 6);
1983 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
1985 /* Redraw (later) if needed */
1986 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1987 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1989 /* Special message */
1990 if (see_m && did_heal)
1993 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
1995 msg_format("%^s appears healthier.", m_name);
2005 if ((tr_ptr->flags2 & RF2_AURA_FIRE) &&
2006 !(r_ptr->flags3 & RF3_IM_FIRE) &&
2007 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2013 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2015 msg_format("%^s is suddenly very hot!", m_name);
2019 tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2021 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2022 damroll (1 + ((tr_ptr->level) / 26),
2023 1 + ((tr_ptr->level) / 17)),
2024 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2028 if ((tr_ptr->flags3 & RF3_AURA_COLD) &&
2029 !(r_ptr->flags3 & RF3_IM_COLD) &&
2030 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2036 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2038 msg_format("%^s is suddenly very cold!", m_name);
2042 tr_ptr->r_flags3 |= RF3_AURA_COLD;
2044 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2045 damroll (1 + ((tr_ptr->level) / 26),
2046 1 + ((tr_ptr->level) / 17)),
2047 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2051 if ((tr_ptr->flags2 & (RF2_AURA_ELEC)) &&
2052 !(r_ptr->flags3 & (RF3_IM_ELEC)) &&
2053 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2059 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2061 msg_format("%^s gets zapped!", m_name);
2065 tr_ptr->r_flags2 |= RF2_AURA_ELEC;
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_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2077 /* Monster missed player */
2080 /* Analyze failed attacks */
2096 /* Visible monsters */
2101 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2103 msg_format("%^s misses %s.", m_name, t_name);
2114 /* Analyze "visible" monsters only */
2115 if (see_m && !do_silly_attack)
2117 /* Count "obvious" attacks (and ones that cause damage) */
2118 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2120 /* Count attacks of this type */
2121 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2123 r_ptr->r_blows[ap_cnt]++;
2131 sound(SOUND_EXPLODE);
2133 /* Cancel Invulnerability */
2134 if (m_ptr->invulner) m_ptr->invulner = 0;
2137 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2139 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2153 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2155 msg_print("The thief flees laughing!");
2164 teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE);
2172 * Hack -- local "player stealth" value (see below)
2174 static u32b noise = 0L;
2180 * The monster is known to be within 100 grids of the player
2182 * In several cases, we directly update the monster lore
2184 * Note that a monster is only allowed to "reproduce" if there
2185 * are a limited number of "reproducing" monsters on the current
2186 * level. This should prevent the level from being "swamped" by
2187 * reproducing monsters. It also allows a large mass of mice to
2188 * prevent a louse from multiplying, but this is a small price to
2189 * pay for a simple multiplication method.
2191 * XXX Monster fear is slightly odd, in particular, monsters will
2192 * fixate on opening a door even if they cannot open it. Actually,
2193 * the same thing happens to normal monsters when they hit a door
2195 * XXX XXX XXX In addition, monsters which *cannot* open or bash
2196 * down a door will still stand there trying to open it...
2198 * XXX Technically, need to check for monster in the way
2199 * combined with that monster being in a wall (or door?)
2201 * A "direction" of "5" means "pick a random direction".
2203 static void process_monster(int m_idx)
2205 monster_type *m_ptr = &m_list[m_idx];
2206 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2208 int i, d, oy, ox, ny, nx;
2214 monster_type *y_ptr;
2227 bool gets_angry = FALSE;
2233 if ((m_idx == p_ptr->riding) && !(r_ptr->flags7 & RF7_RIDING))
2235 if (rakuba(0, TRUE))
2238 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2241 monster_desc(m_name, &m_list[p_ptr->riding], 0);
2242 msg_format("You have fallen from %s.", m_name);
2247 if ((m_ptr->mflag2 & MFLAG_CHAMELEON) && one_in_(13) && !m_ptr->csleep)
2249 choose_new_monster(m_idx, FALSE, 0);
2250 r_ptr = &r_info[m_ptr->r_idx];
2253 /* Players hidden in shadow are almost imperceptable. -LM- */
2254 if (p_ptr->special_defense & NINJA_S_STEALTH)
2256 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
2257 if (p_ptr->monlite) tmp /= 3;
2258 if (p_ptr->aggravate) tmp /= 2;
2259 if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
2260 /* Low-level monsters will find it difficult to locate the player. */
2261 if (rand_int(tmp) > (r_ptr->level+20)) aware = FALSE;
2264 /* Quantum monsters are odd */
2265 if (r_ptr->flags2 & (RF2_QUANTUM))
2267 /* Sometimes skip move */
2268 if (!rand_int(2)) return;
2271 if (!rand_int((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2275 if (is_pet(m_ptr) && !(m_ptr->ml))
2282 /* Acquire the monster name */
2283 monster_desc(m_name, m_ptr, 0);
2287 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2289 msg_format("%^s disappears!", m_name);
2294 /* Generate treasure, etc */
2295 monster_death(m_idx, FALSE);
2297 /* Delete the monster */
2298 delete_monster_idx(m_idx);
2303 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2305 msg_print("You feel sad for a moment.");
2314 if (m_ptr->r_idx == MON_SHURYUUDAN)
2316 mon_take_hit_mon(FALSE, m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2318 mon_take_hit_mon(FALSE, m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2321 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) && !p_ptr->inside_battle)
2323 static int riding_pinch = 0;
2325 if (m_ptr->hp < m_ptr->maxhp/3)
2327 bool level_teleport = TRUE;
2329 monster_desc(m_name, m_ptr, 0);
2331 if (m_idx == p_ptr->riding && riding_pinch < 2)
2334 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2336 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
2339 level_teleport = FALSE;
2344 if (m_idx == p_ptr->riding)
2347 msg_format("%s¤Ï¤¢¤Ê¤¿¤Î«Çû¤«¤éæ½Ð¤·¤¿¡£", m_name);
2349 msg_format("%^s succeeded to escape from your restriction!", m_name);
2352 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))
2355 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2357 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2361 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2363 msg_format("%^s read a scroll of teleport level.", m_name);
2366 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2368 msg_format("%^s disappears.", m_name);
2374 delete_monster_idx(m_idx);
2376 if (m_idx == p_ptr->riding)
2378 if (rakuba(-1, FALSE))
2381 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2383 msg_print("You have fallen from riding pet.");
2391 if (m_idx == p_ptr->riding) riding_pinch = 0;
2395 /* Handle "sleep" */
2400 /* Hack -- handle non-aggravation */
2401 if (!p_ptr->aggravate) notice = rand_int(1024);
2403 /* Nightmare monsters are more alert */
2404 if (ironman_nightmare) notice /= 2;
2406 /* Hack -- See if monster "notices" player */
2407 if ((notice * notice * notice) <= noise)
2409 /* Hack -- amount of "waking" */
2412 /* Wake up faster near the player */
2413 if (m_ptr->cdis < 50) d = (100 / m_ptr->cdis);
2415 /* Hack -- handle aggravation */
2416 if (p_ptr->aggravate) d = m_ptr->csleep;
2419 if (m_ptr->csleep > d)
2421 /* Monster wakes up "a little bit" */
2424 /* Notice the "not waking up" */
2427 /* Hack -- Count the ignores */
2428 if (r_ptr->r_ignore < MAX_UCHAR)
2438 /* Reset sleep counter */
2441 /* Notice the "waking up" */
2446 /* Acquire the monster name */
2447 monster_desc(m_name, m_ptr, 0);
2449 /* Dump a message */
2451 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
2453 msg_format("%^s wakes up.", m_name);
2457 /* Redraw the health bar */
2458 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2459 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2461 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2))
2462 p_ptr->update |= (PU_MON_LITE);
2464 /* Hack -- Count the wakings */
2465 if (r_ptr->r_wake < MAX_UCHAR)
2473 /* Still sleeping */
2474 if (m_ptr->csleep) return;
2483 /* Make a "saving throw" against stun */
2484 if (rand_int(10000) <= r_ptr->level * r_ptr->level)
2490 /* Hack -- Recover from stun */
2491 if (m_ptr->stunned > d)
2493 /* Recover somewhat */
2494 m_ptr->stunned -= d;
2503 /* Message if visible */
2508 /* Acquire the monster name */
2509 monster_desc(m_name, m_ptr, 0);
2511 /* Dump a message */
2513 msg_format("%^s¤ÏÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2515 msg_format("%^s is no longer stunned.", m_name);
2518 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2519 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2524 if (m_ptr->stunned && one_in_(2)) return;
2528 /* Handle confusion */
2529 if (m_ptr->confused)
2531 /* Amount of "boldness" */
2532 int d = randint(r_ptr->level / 20 + 1);
2534 /* Still confused */
2535 if (m_ptr->confused > d)
2537 /* Reduce the confusion */
2538 m_ptr->confused -= d;
2544 /* No longer confused */
2545 m_ptr->confused = 0;
2547 /* Message if visible */
2552 /* Acquire the monster name */
2553 monster_desc(m_name, m_ptr, 0);
2555 /* Dump a message */
2557 msg_format("%^s¤Ïº®Í𤫤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2559 msg_format("%^s is no longer confused.", m_name);
2562 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2563 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2568 /* Handle Invulnerability */
2569 if (m_ptr->invulner)
2571 /* Reduce by one, note if expires */
2574 if (!(m_ptr->invulner) && m_ptr->ml)
2578 /* Acquire the monster name */
2579 monster_desc(m_name, m_ptr, 0);
2581 /* Dump a message */
2583 msg_format("%^s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ê¤¤¡£", m_name);
2585 msg_format("%^s is no longer invulnerable.", m_name);
2588 m_ptr->energy -= 100;
2589 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2590 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2597 /* Reduce by one, note if expires */
2600 if (!(m_ptr->fast) && m_ptr->ml)
2604 /* Acquire the monster name */
2605 monster_desc(m_name, m_ptr, 0);
2607 /* Dump a message */
2609 msg_format("%^s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2611 msg_format("%^s is no longer fast.", m_name);
2614 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2615 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2622 /* Reduce by one, note if expires */
2625 if (!(m_ptr->slow) && m_ptr->ml)
2629 /* Acquire the monster name */
2630 monster_desc(m_name, m_ptr, 0);
2632 /* Dump a message */
2634 msg_format("%^s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2636 msg_format("%^s is no longer slow.", m_name);
2639 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2640 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2644 if (p_ptr->riding == m_idx)
2646 p_ptr->update |= (PU_BONUS);
2649 /* No one wants to be your friend if you're aggravating */
2650 if (is_friendly(m_ptr) && p_ptr->aggravate)
2653 /* Paranoia... no pet uniques outside wizard mode -- TY */
2654 if (is_pet(m_ptr) &&
2655 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
2656 ((p_ptr->align > 9 && (r_ptr->flags3 & RF3_EVIL)) ||
2657 (p_ptr->align < -9 && (r_ptr->flags3 & RF3_GOOD))))
2658 || (r_ptr->flags3 & RF3_RES_ALL)))
2663 if (p_ptr->inside_battle) gets_angry = FALSE;
2668 monster_desc(m_name, m_ptr, 0);
2670 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2672 msg_format("%^s suddenly becomes hostile!", m_name);
2681 /* Amount of "boldness" */
2682 int d = randint(r_ptr->level / 20 + 1);
2685 if (m_ptr->monfear > d)
2687 /* Reduce the fear */
2688 m_ptr->monfear -= d;
2691 /* Recover from fear, take note if seen */
2694 /* No longer afraid */
2703 /* Acquire the monster name/poss */
2704 monster_desc(m_name, m_ptr, 0);
2705 monster_desc(m_poss, m_ptr, 0x22);
2707 /* Dump a message */
2709 msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name);
2711 msg_format("%^s recovers %s courage.", m_name, m_poss);
2714 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2719 /* Get the origin */
2724 /* Attempt to "multiply" if able and allowed */
2725 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2729 /* Count the adjacent monsters */
2730 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2732 for (x = ox - 1; x <= ox + 1; x++)
2734 /* Ignore locations off of edge */
2735 if (!in_bounds2(y, x)) continue;
2737 if (cave[y][x].m_idx) k++;
2741 /* Hack -- multiply slower in crowded areas */
2742 if ((k < 4) && (!k || !rand_int(k * MON_MULT_ADJ)))
2744 /* Try to multiply */
2745 if (multiply_monster(m_idx, FALSE, is_friendly(m_ptr), is_pet(m_ptr)))
2747 /* Take note if visible */
2750 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2753 /* Multiplying takes energy */
2760 if (!p_ptr->inside_battle)
2762 /* Hack! "Cyber" monster makes noise... */
2763 if (m_ptr->r_idx == MON_CYBER &&
2764 (randint(CYBERNOISE) == 1) &&
2765 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2767 if (disturb_minor) disturb(FALSE, FALSE);
2769 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2771 msg_print("You hear heavy steps.");
2776 /* Some monsters can speak */
2777 if ((r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2778 (randint(SPEAK_CHANCE) == 1) &&
2779 player_has_los_bold(oy, ox))
2782 char monmessage[1024];
2785 /* Acquire the monster name/poss */
2787 monster_desc(m_name, m_ptr, 0);
2790 strcpy(m_name, "¤½¤ì");
2792 strcpy(m_name, "It");
2796 /* Select the file for monster quotes */
2799 filename = "monfear_j.txt";
2801 filename = "monfear.txt";
2804 else if (is_pet(m_ptr))
2806 filename = "monpet_j.txt";
2808 filename = "monpet.txt";
2811 else if (is_friendly(m_ptr))
2813 filename = "monfrien_j.txt";
2815 filename = "monfrien.txt";
2820 filename = "monspeak_j.txt";
2822 filename = "monspeak.txt";
2826 /* Get the monster line */
2827 if (get_rnd_line(filename, m_ptr->r_idx, monmessage) == 0)
2831 msg_format("%^s%s", m_name, monmessage);
2833 msg_format("%^s %s", m_name, monmessage);
2840 /* Attempt to cast a spell */
2841 if (aware && make_attack_spell(m_idx)) return;
2844 * Attempt to cast a spell at an enemy other than the player
2845 * (may slow the game a smidgeon, but I haven't noticed.)
2847 if (monst_spell_monst(m_idx)) return;
2849 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
2851 /* Hack -- Assume no movement */
2852 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2853 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2856 /* Confused -- 100% random */
2857 if (m_ptr->confused || !aware)
2859 /* Try four "random" directions */
2860 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2863 /* 75% random movement */
2864 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2865 (r_ptr->flags1 & RF1_RAND_25) &&
2866 (rand_int(100) < 75))
2868 /* Memorize flags */
2869 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2870 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25);
2872 /* Try four "random" directions */
2873 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2876 /* 50% random movement */
2877 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2878 (rand_int(100) < 50))
2880 /* Memorize flags */
2881 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2883 /* Try four "random" directions */
2884 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2887 /* 25% random movement */
2888 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2889 (rand_int(100) < 25))
2891 /* Memorize flags */
2892 if (m_ptr->ml) r_ptr->r_flags1 |= RF1_RAND_25;
2894 /* Try four "random" directions */
2895 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2898 /* Can't reach player - find something else to hit */
2899 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2901 /* Try four "random" directions */
2902 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2904 /* Look for an enemy */
2905 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2906 get_enemy_dir(m_idx, mm);
2910 /* Pets will follow the player */
2911 else if (is_pet(m_ptr))
2913 /* Are we trying to avoid the player? */
2914 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
2915 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2917 /* Do we want to find the player? */
2918 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2920 /* Should we find the player if we can't find a monster? */
2921 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2923 /* by default, move randomly */
2924 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2926 /* Look for an enemy */
2927 if (!get_enemy_dir(m_idx, mm))
2929 /* Find the player if necessary */
2930 if (avoid || lonely || distant)
2932 /* Remember the leash length */
2933 int dis = p_ptr->pet_follow_distance;
2935 /* Hack -- adjust follow distance temporarily */
2936 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2938 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2941 /* Find the player */
2942 get_moves(m_idx, mm);
2944 /* Restore the leash */
2945 p_ptr->pet_follow_distance = dis;
2950 /* Friendly monster movement */
2951 else if (!is_hostile(m_ptr))
2953 /* by default, move randomly */
2954 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2956 /* Look for an enemy */
2957 get_enemy_dir(m_idx, mm);
2959 /* Normal movement */
2960 else if (stupid_monsters)
2963 get_moves(m_idx, mm);
2967 /* Logical moves, may do nothing */
2968 if (!get_moves(m_idx, mm)) return;
2971 /* Assume nothing */
2976 /* Assume nothing */
2977 did_open_door = FALSE;
2978 did_bash_door = FALSE;
2979 did_take_item = FALSE;
2980 did_kill_item = FALSE;
2981 did_move_body = FALSE;
2982 did_pass_wall = FALSE;
2983 did_kill_wall = FALSE;
2986 /* Take a zero-terminated array of "directions" */
2987 for (i = 0; mm[i]; i++)
2989 /* Get the direction */
2992 /* Hack -- allow "randomized" motion */
2993 if (d == 5) d = ddd[rand_int(8)];
2995 /* Get the destination */
2999 /* Ignore locations off of edge */
3000 if (!in_bounds2(ny, nx)) continue;
3002 /* Access that cave grid */
3003 c_ptr = &cave[ny][nx];
3005 /* Access that cave grid's contents */
3006 y_ptr = &m_list[c_ptr->m_idx];
3008 /* Floor is open? */
3009 if (cave_floor_grid(c_ptr))
3011 /* Go ahead and move */
3015 /* Hack -- player 'in' wall */
3016 else if ((ny == py) && (nx == px))
3021 else if (c_ptr->m_idx)
3023 /* Possibly a monster to attack */
3027 /* Permanent wall */
3028 else if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
3029 (c_ptr->feat <= FEAT_PERM_SOLID))
3034 /* Hack -- semi-transparent terrains are no obstacle */
3035 else if (c_ptr->feat == FEAT_TREES)
3040 /* Hack -- semi-transparent terrains are no obstacle */
3041 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)))))
3047 /* Monster moves through walls (and doors) */
3048 else if (can_pass_wall)
3050 /* Pass through walls/doors/rubble */
3053 /* Monster went through a wall */
3054 did_pass_wall = TRUE;
3057 /* Monster destroys walls (and doors) */
3058 else if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))
3060 /* Eat through walls/doors/rubble */
3063 /* Monster destroyed a wall */
3064 did_kill_wall = TRUE;
3066 if (randint(GRINDNOISE) == 1)
3069 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
3071 msg_print("There is a grinding sound.");
3076 /* Forget the wall */
3077 c_ptr->info &= ~(CAVE_MARK);
3080 c_ptr->feat = floor_type[rand_int(100)];
3081 c_ptr->info &= ~(CAVE_MASK);
3082 c_ptr->info |= CAVE_FLOOR;
3084 /* Note changes to viewable region */
3085 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3088 /* Handle doors and secret doors */
3089 else if (((c_ptr->feat >= FEAT_DOOR_HEAD) &&
3090 (c_ptr->feat <= FEAT_DOOR_TAIL)) ||
3091 (c_ptr->feat == FEAT_SECRET))
3093 bool may_bash = TRUE;
3095 /* Assume no move allowed */
3098 /* Creature can open doors. */
3099 if ((r_ptr->flags2 & RF2_OPEN_DOOR) &&
3100 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3102 /* Closed doors and secret doors */
3103 if ((c_ptr->feat == FEAT_DOOR_HEAD) ||
3104 (c_ptr->feat == FEAT_SECRET))
3106 /* The door is open */
3107 did_open_door = TRUE;
3109 /* Do not bash the door */
3112 /* Assume no move allowed */
3116 /* Locked doors (not jammed) */
3117 else if (c_ptr->feat < FEAT_DOOR_HEAD + 0x08)
3122 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3124 /* Try to unlock it XXX XXX XXX */
3125 if (rand_int(m_ptr->hp / 10) > k)
3127 /* Unlock the door */
3128 cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00);
3130 /* Do not bash the door */
3136 /* Stuck doors -- attempt to bash them down if allowed */
3137 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) &&
3138 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3143 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3145 /* Attempt to Bash XXX XXX XXX */
3146 if (rand_int(m_ptr->hp / 10) > k)
3150 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
3152 msg_print("You hear a door burst open!");
3156 /* Disturb (sometimes) */
3157 if (disturb_minor) disturb(0, 0);
3159 /* The door was bashed open */
3160 did_bash_door = TRUE;
3162 /* Hack -- fall into doorway */
3168 /* Deal with doors in the way */
3169 if (did_open_door || did_bash_door)
3171 /* Break down the door */
3172 if (did_bash_door && (rand_int(100) < 50))
3174 cave_set_feat(ny, nx, FEAT_BROKEN);
3180 cave_set_feat(ny, nx, FEAT_OPEN);
3183 /* Handle viewable doors */
3184 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3188 /* Hack -- check for Glyph of Warding */
3189 if (do_move && (c_ptr->feat == FEAT_GLYPH) &&
3190 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3192 /* Assume no move allowed */
3195 /* Break the ward */
3196 if (!is_pet(m_ptr) && (randint(BREAK_GLYPH) < r_ptr->level))
3198 /* Describe observable breakage */
3199 if (c_ptr->info & CAVE_MARK)
3202 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3204 msg_print("The rune of protection is broken!");
3209 /* Forget the rune */
3210 c_ptr->info &= ~(CAVE_MARK);
3212 /* Break the rune */
3213 c_ptr->feat = floor_type[rand_int(100)];
3214 c_ptr->info &= ~(CAVE_MASK);
3215 c_ptr->info |= CAVE_FLOOR;
3217 /* Allow movement */
3224 else if (do_move && (c_ptr->feat == FEAT_MINOR_GLYPH) &&
3225 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3227 /* Assume no move allowed */
3230 /* Break the ward */
3233 /* Break the ward */
3234 if (randint(BREAK_MINOR_GLYPH) > r_ptr->level)
3236 /* Describe observable breakage */
3237 if (c_ptr->info & CAVE_MARK)
3240 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3242 msg_print("The rune explodes!");
3245 project(0, 2, ny, nx, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_REF | PROJECT_NO_HANGEKI), -1);
3251 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3253 msg_print("An explosive rune was disarmed.");
3257 /* Forget the rune */
3258 c_ptr->info &= ~(CAVE_MARK);
3260 /* Break the rune */
3261 c_ptr->feat = floor_type[rand_int(100)];
3262 c_ptr->info &= ~(CAVE_MASK);
3263 c_ptr->info |= CAVE_FLOOR;
3267 if (!m_ptr->r_idx) return;
3268 /* Allow movement */
3272 if (do_move && (ny == py) && (nx == px) && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3277 /* Some monsters never attack */
3278 if (do_move && (ny == py) && (nx == px) &&
3279 (r_ptr->flags1 & RF1_NEVER_BLOW))
3281 /* Hack -- memorize lack of attacks */
3282 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3288 /* The player is in the way. Attack him. */
3289 if (do_move && (ny == py) && (nx == px))
3291 if (!p_ptr->riding || one_in_(2))
3294 (void)make_attack_normal(m_idx);
3304 if ((c_ptr->feat >= FEAT_PATTERN_START) &&
3305 (c_ptr->feat <= FEAT_PATTERN_XTRA2) &&
3306 !do_turn && !(r_ptr->flags7 & RF7_CAN_FLY))
3312 /* A monster is in the way */
3313 if (do_move && c_ptr->m_idx)
3315 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3316 monster_type *m2_ptr = &m_list[c_ptr->m_idx];
3318 /* Assume no movement */
3321 /* Attack 'enemies' */
3322 if (((r_ptr->flags2 & (RF2_KILL_BODY)) &&
3323 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3324 (cave_floor_grid(c_ptr)) &&
3325 (c_ptr->m_idx != p_ptr->riding)) ||
3326 are_enemies(m_ptr, m2_ptr) || m_ptr->confused)
3330 if (r_ptr->flags2 & RF2_KILL_BODY) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3333 if ((m2_ptr->r_idx) && (m2_ptr->hp >= 0))
3335 if (monst_attack_monst(m_idx, cave[ny][nx].m_idx))
3340 /* Push past weaker monsters (unless leaving a wall) */
3341 else if ((r_ptr->flags2 & RF2_MOVE_BODY) &&
3342 (r_ptr->mexp > z_ptr->mexp) && cave_floor_grid(c_ptr) &&
3343 (cave_floor_grid(&cave[m_ptr->fy][m_ptr->fx])) &&
3344 (c_ptr->m_idx != p_ptr->riding))
3346 /* Allow movement */
3349 /* Monster pushed past another monster */
3350 did_move_body = TRUE;
3352 /* XXX XXX XXX Message */
3357 * Check if monster can cross terrain
3358 * This is checked after the normal attacks
3359 * to allow monsters to attack an enemy,
3360 * even if it can't enter the terrain.
3362 if (do_move && !monster_can_cross_terrain(c_ptr->feat, r_ptr))
3364 /* Assume no move allowed */
3368 /* Some monsters never move */
3369 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3371 /* Hack -- memorize lack of attacks */
3372 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3378 if (m_idx == p_ptr->riding)
3380 if (!p_ptr->riding_ryoute && !(m_list[p_ptr->riding].monfear)) do_move = FALSE;
3383 /* Creature has been allowed move */
3386 s16b this_o_idx, next_o_idx;
3391 /* Hack -- Update the old location */
3392 cave[oy][ox].m_idx = c_ptr->m_idx;
3394 if (cave[ny][nx].feat == FEAT_TREES)
3396 if (r_ptr->flags2 & RF2_KILL_WALL)
3398 c_ptr->feat = FEAT_GRASS;
3399 c_ptr->info &= ~(CAVE_MASK);
3400 c_ptr->info |= CAVE_FLOOR;
3402 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3404 m_ptr->energy -= 100;
3408 /* Mega-Hack -- move the old monster, if any */
3411 /* Move the old monster */
3415 /* Update the old monster */
3416 update_mon(c_ptr->m_idx, TRUE);
3418 /* Wake up the moved monster */
3419 m_list[c_ptr->m_idx].csleep = 0;
3422 /* Hack -- Update the new location */
3423 c_ptr->m_idx = m_idx;
3425 /* Move the monster */
3429 /* Update the monster */
3430 update_mon(m_idx, TRUE);
3432 if (p_ptr->riding == m_idx)
3438 /* Redraw the old grid */
3441 /* Redraw the new grid */
3444 if (p_ptr->riding == m_idx)
3449 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW);
3451 /* Update the monsters */
3452 p_ptr->update |= (PU_DISTANCE);
3455 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3458 /* Possible disturb */
3459 if (m_ptr->ml && (disturb_move ||
3460 ((m_ptr->mflag & MFLAG_VIEW) &&
3464 if (is_hostile(m_ptr))
3468 /* Scan all objects in the grid */
3469 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3473 /* Acquire object */
3474 o_ptr = &o_list[this_o_idx];
3476 /* Acquire next object */
3477 next_o_idx = o_ptr->next_o_idx;
3480 if (o_ptr->tval == TV_GOLD) continue;
3483 * Skip "real" corpses and statues, to avoid extreme
3484 * silliness like a novice rogue pockets full of statues
3487 if ((o_ptr->tval == TV_CORPSE) ||
3488 (o_ptr->tval == TV_STATUE)) continue;
3490 /* Take or Kill objects on the floor */
3491 if ((r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3492 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)))
3499 char o_name[MAX_NLEN];
3501 /* Extract some flags */
3502 object_flags(o_ptr, &f1, &f2, &f3);
3504 /* Acquire the object name */
3505 object_desc(o_name, o_ptr, TRUE, 3);
3507 /* Acquire the monster name */
3508 monster_desc(m_name, m_ptr, 0x04);
3510 /* React to objects that hurt the monster */
3511 if (f1 & TR1_KILL_DRAGON) flg3 |= (RF3_DRAGON);
3512 if (f1 & TR1_SLAY_DRAGON) flg3 |= (RF3_DRAGON);
3513 if (f1 & TR1_SLAY_TROLL) flg3 |= (RF3_TROLL);
3514 if (f1 & TR1_SLAY_GIANT) flg3 |= (RF3_GIANT);
3515 if (f1 & TR1_SLAY_ORC) flg3 |= (RF3_ORC);
3516 if (f1 & TR1_SLAY_DEMON) flg3 |= (RF3_DEMON);
3517 if (f1 & TR1_SLAY_UNDEAD) flg3 |= (RF3_UNDEAD);
3518 if (f1 & TR1_SLAY_ANIMAL) flg3 |= (RF3_ANIMAL);
3519 if (f1 & TR1_SLAY_EVIL) flg3 |= (RF3_EVIL);
3521 /* The object cannot be picked up by the monster */
3522 if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) ||
3525 /* Only give a message for "take_item" */
3526 if ((r_ptr->flags2 & (RF2_TAKE_ITEM)) && (r_ptr->flags2 & (RF2_STUPID)))
3529 did_take_item = TRUE;
3531 /* Describe observable situations */
3532 if (m_ptr->ml && player_can_see_bold(ny, nx))
3534 /* Dump a message */
3536 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£", m_name, o_name);
3538 msg_format("%^s tries to pick up %s, but fails.", m_name, o_name);
3544 /* Pick up the item */
3545 else if (r_ptr->flags2 & RF2_TAKE_ITEM)
3548 did_take_item = TRUE;
3550 /* Describe observable situations */
3551 if (player_can_see_bold(ny, nx))
3553 /* Dump a message */
3555 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3557 msg_format("%^s picks up %s.", m_name, o_name);
3562 /* Excise the object */
3563 excise_object_idx(this_o_idx);
3566 o_ptr->marked = FALSE;
3568 /* Forget location */
3569 o_ptr->iy = o_ptr->ix = 0;
3571 /* Memorize monster */
3572 o_ptr->held_m_idx = m_idx;
3575 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3578 m_ptr->hold_o_idx = this_o_idx;
3581 /* Destroy the item if not a pet */
3582 else if (!is_pet(m_ptr))
3585 did_kill_item = TRUE;
3587 /* Describe observable situations */
3588 if (player_has_los_bold(ny, nx))
3590 /* Dump a message */
3592 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3594 msg_format("%^s destroys %s.", m_name, o_name);
3599 /* Delete the object */
3600 delete_object_idx(this_o_idx);
3606 /* Stop when done */
3611 * Forward movements failed, but now recieved LOS attack!
3612 * Try to flow by smell.
3614 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3615 m_ptr->mflag2 &= ~MFLAG_NOFLOW;
3617 /* If we haven't done anything, try casting a spell again */
3618 if (!do_turn && !do_move && !m_ptr->monfear && !stupid_monsters && !(p_ptr->riding == m_idx) && aware)
3621 if (make_attack_spell(m_idx)) return;
3625 /* Notice changes in view */
3628 /* Update some things */
3629 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
3632 /* Notice changes in view */
3633 if (do_move && ((r_ptr->flags7 & (RF7_SELF_LITE_1 | RF7_SELF_LITE_2)) || ((r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2)) && !p_ptr->inside_battle)))
3635 /* Update some things */
3636 p_ptr->update |= (PU_MON_LITE);
3639 /* Learn things from observable monster */
3642 /* Monster opened a door */
3643 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3645 /* Monster bashed a door */
3646 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3648 /* Monster tried to pick something up */
3649 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3651 /* Monster tried to crush something */
3652 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3654 /* Monster pushed past another monster */
3655 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3657 /* Monster passed through a wall */
3658 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3660 /* Monster destroyed a wall */
3661 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3665 /* Hack -- get "bold" if out of options */
3666 if (!do_turn && !do_move && m_ptr->monfear && aware)
3668 /* No longer afraid */
3671 /* Message if seen */
3676 /* Acquire the monster name */
3677 monster_desc(m_name, m_ptr, 0);
3679 /* Dump a message */
3681 msg_format("%^s¤ÏÀ襤¤ò·è°Õ¤·¤¿¡ª", m_name);
3683 msg_format("%^s turns to fight!", m_name);
3686 chg_virtue(V_COMPASSION, -1);
3689 /* XXX XXX XXX Actually do something now (?) */
3694 * Process all the "live" monsters, once per game turn.
3696 * During each game turn, we scan through the list of all the "live" monsters,
3697 * (backwards, so we can excise any "freshly dead" monsters), energizing each
3698 * monster, and allowing fully energized monsters to move, attack, pass, etc.
3700 * Note that monsters can never move in the monster array (except when the
3701 * "compact_monsters()" function is called by "dungeon()" or "save_player()").
3703 * This function is responsible for at least half of the processor time
3704 * on a normal system with a "normal" amount of monsters and a player doing
3707 * When the player is resting, virtually 90% of the processor time is spent
3708 * in this function, and its children, "process_monster()" and "make_move()".
3710 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",
3711 * especially when the player is running.
3713 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"
3714 * monsters while they are still being "born". A monster is "fresh" only
3715 * during the turn in which it is created, and we use the "hack_m_idx" to
3716 * determine if the monster is yet to be processed during the current turn.
3718 * Note the special "MFLAG_NICE" flag, which allows the player to get one
3719 * move before any "nasty" monsters get to use their spell attacks.
3721 * Note that when the "knowledge" about the currently tracked monster
3722 * changes (flags, attacks, spells), we induce a redraw of the monster
3725 void process_monsters(void)
3732 monster_type *m_ptr;
3733 monster_race *r_ptr;
3735 int old_monster_race_idx;
3737 u32b old_r_flags1 = 0L;
3738 u32b old_r_flags2 = 0L;
3739 u32b old_r_flags3 = 0L;
3740 u32b old_r_flags4 = 0L;
3741 u32b old_r_flags5 = 0L;
3742 u32b old_r_flags6 = 0L;
3744 byte old_r_blows0 = 0;
3745 byte old_r_blows1 = 0;
3746 byte old_r_blows2 = 0;
3747 byte old_r_blows3 = 0;
3749 byte old_r_cast_inate = 0;
3750 byte old_r_cast_spell = 0;
3754 /* Clear monster fighting indicator */
3757 /* Memorize old race */
3758 old_monster_race_idx = p_ptr->monster_race_idx;
3760 /* Acquire knowledge */
3761 if (p_ptr->monster_race_idx)
3763 /* Acquire current monster */
3764 r_ptr = &r_info[p_ptr->monster_race_idx];
3766 /* Memorize flags */
3767 old_r_flags1 = r_ptr->r_flags1;
3768 old_r_flags2 = r_ptr->r_flags2;
3769 old_r_flags3 = r_ptr->r_flags3;
3770 old_r_flags4 = r_ptr->r_flags4;
3771 old_r_flags5 = r_ptr->r_flags5;
3772 old_r_flags6 = r_ptr->r_flags6;
3774 /* Memorize blows */
3775 old_r_blows0 = r_ptr->r_blows[0];
3776 old_r_blows1 = r_ptr->r_blows[1];
3777 old_r_blows2 = r_ptr->r_blows[2];
3778 old_r_blows3 = r_ptr->r_blows[3];
3780 /* Memorize castings */
3781 old_r_cast_inate = r_ptr->r_cast_inate;
3782 old_r_cast_spell = r_ptr->r_cast_spell;
3786 /* Hack -- calculate the "player noise" */
3787 noise = (1L << (30 - p_ptr->skill_stl));
3790 /* Process the monsters (backwards) */
3791 for (i = m_max - 1; i >= 1; i--)
3793 /* Access the monster */
3795 r_ptr = &r_info[m_ptr->r_idx];
3797 /* Handle "leaving" */
3798 if (p_ptr->leaving) break;
3800 /* Ignore "dead" monsters */
3801 if (!m_ptr->r_idx) continue;
3803 if (p_ptr->wild_mode) continue;
3806 /* Handle "fresh" monsters */
3807 if (m_ptr->mflag & MFLAG_BORN)
3809 /* No longer "fresh" */
3810 m_ptr->mflag &= ~(MFLAG_BORN);
3816 /* Hack -- Require proximity */
3817 if (m_ptr->cdis >= 100) continue;
3820 /* Access the location */
3824 /* Flow by smell is allowed */
3825 if (!stupid_monsters && !p_ptr->no_flowed)
3827 m_ptr->mflag2 &= ~MFLAG_NOFLOW;
3830 /* Assume no move */
3833 /* Handle "sensing radius" */
3834 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > 20 ? 20 : r_ptr->aaf) : r_ptr->aaf))
3836 /* We can "sense" the player */
3840 /* Handle "sight" and "aggravation" */
3841 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3842 (player_has_los_bold(fy, fx) || p_ptr->aggravate))
3844 /* We can "see" or "feel" the player */
3848 /* Hack -- Monsters can "smell" the player from far away */
3849 /* Note that most monsters have "aaf" of "20" or so */
3850 else if (!stupid_monsters && !(m_ptr->mflag2 & MFLAG_NOFLOW) &&
3851 (cave_floor_bold(py, px) || (cave[py][px].feat == FEAT_TREES)) &&
3852 (cave[py][px].when == cave[fy][fx].when) &&
3853 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3854 (cave[fy][fx].dist < r_ptr->aaf))
3856 /* We can "smell" the player */
3859 else if (m_ptr->target_y) test = TRUE;
3862 if (!test) continue;
3865 if (p_ptr->riding == i)
3866 speed = p_ptr->pspeed;
3869 speed = MIN(199, m_ptr->mspeed);
3871 /* Monsters move quickly in Nightmare mode */
3872 if (ironman_nightmare)
3874 speed = MIN(199, m_ptr->mspeed + 5);
3877 if (m_ptr->fast) speed = MIN(199, speed + 10);
3878 if (m_ptr->slow) speed = MAX(0, speed - 10);
3881 e = extract_energy[speed];
3883 /* Give this monster some energy */
3884 if(rand_int(60) < e)
3885 m_ptr->energy += gain_energy();
3888 /* Not enough energy to move */
3889 if (m_ptr->energy < 100) continue;
3891 /* Use up "some" energy */
3892 m_ptr->energy -= 100;
3895 /* Save global index */
3898 /* Process the monster */
3901 reset_target(m_ptr);
3903 /* Give up flow_by_smell when it might useless */
3904 if (p_ptr->no_flowed && one_in_(3))
3905 m_ptr->mflag2 |= MFLAG_NOFLOW;
3907 /* Hack -- notice death or departure */
3908 if (!alive || death) break;
3910 /* Notice leaving */
3911 if (p_ptr->leaving) break;
3914 /* Reset global index */
3918 /* Tracking a monster race (the same one we were before) */
3919 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3921 /* Acquire monster race */
3922 r_ptr = &r_info[p_ptr->monster_race_idx];
3924 /* Check for knowledge change */
3925 if ((old_r_flags1 != r_ptr->r_flags1) ||
3926 (old_r_flags2 != r_ptr->r_flags2) ||
3927 (old_r_flags3 != r_ptr->r_flags3) ||
3928 (old_r_flags4 != r_ptr->r_flags4) ||
3929 (old_r_flags5 != r_ptr->r_flags5) ||
3930 (old_r_flags6 != r_ptr->r_flags6) ||
3931 (old_r_blows0 != r_ptr->r_blows[0]) ||
3932 (old_r_blows1 != r_ptr->r_blows[1]) ||
3933 (old_r_blows2 != r_ptr->r_blows[2]) ||
3934 (old_r_blows3 != r_ptr->r_blows[3]) ||
3935 (old_r_cast_inate != r_ptr->r_cast_inate) ||
3936 (old_r_cast_spell != r_ptr->r_cast_spell))
3939 p_ptr->window |= (PW_MONSTER);
3946 bool process_the_world(int num, int who, bool vs_player)
3948 if(world_monster) return (FALSE);
3953 monster_desc(m_name, &m_list[hack_m_idx], 0);
3957 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
3959 msg_format("%s yells 'The World! Time has stopped!'", m_name);
3963 msg_print("¡Ö»þ¤è¡ª¡×");
3965 msg_format("%s yells 'Time!'", m_name);
3967 else msg_print("hek!");
3972 world_monster = TRUE;
3974 if (vs_player) do_cmd_redraw();
3978 if(!m_list[hack_m_idx].r_idx) return (TRUE);
3979 process_monster(hack_m_idx);
3981 reset_target(&m_list[hack_m_idx]);
3984 if (p_ptr->notice) notice_stuff();
3987 if (p_ptr->update) update_stuff();
3990 if (p_ptr->redraw) redraw_stuff();
3993 if (p_ptr->window) window_stuff();
3996 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
4000 p_ptr->redraw |= (PR_MAP);
4002 /* Update monsters */
4003 p_ptr->update |= (PU_MONSTERS);
4006 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4008 world_monster = FALSE;
4009 if (vs_player || los(py, px, m_list[hack_m_idx].fy, m_list[hack_m_idx].fx))
4012 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
4014 msg_print("You feel time flowing around you once more.");
4025 void monster_gain_exp(int m_idx, int s_idx)
4027 monster_type *m_ptr = &m_list[m_idx];
4028 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4029 monster_race *s_ptr = &r_info[s_idx];
4032 if (p_ptr->inside_battle) return;
4034 if (!r_ptr->next_exp) return;
4036 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
4037 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
4038 if (!dun_level) new_exp /= 5;
4039 m_ptr->exp += new_exp;
4040 if (m_ptr->mflag2 & MFLAG_CHAMELEON) return;
4042 if (m_ptr->exp >= r_ptr->next_exp)
4045 int old_hp = m_ptr->hp;
4046 int old_maxhp = m_ptr->max_maxhp;
4047 int old_r_idx = m_ptr->r_idx;
4050 monster_desc(m_name, m_ptr, 0);
4051 m_ptr->r_idx = r_ptr->next_r_idx;
4052 r_ptr = &r_info[m_ptr->r_idx];
4053 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
4055 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
4059 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
4061 if (ironman_nightmare)
4063 u32b hp = m_ptr->max_maxhp * 2L;
4065 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
4067 m_ptr->maxhp = m_ptr->max_maxhp;
4068 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
4070 /* Extract the monster base speed */
4071 m_ptr->mspeed = r_ptr->speed;
4073 /* Hack -- small racial variety */
4074 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
4076 /* Allow some small variation per monster */
4077 if(rand_int(4) == 1){
4078 i = extract_energy[r_ptr->speed] / 3;
4079 if (i) m_ptr->mspeed += rand_spread(0, i);
4082 i = extract_energy[r_ptr->speed] / 10;
4083 if (i) m_ptr->mspeed += rand_spread(0, i);
4087 if (m_ptr->mspeed > 199) m_ptr->mspeed = 199;
4091 if (is_pet(m_ptr) || m_ptr->ml)
4094 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
4096 msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
4098 r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
4100 update_mon(m_idx, FALSE);
4101 lite_spot(m_ptr->fy, m_ptr->fx);
4103 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;