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 m_ptr->target_y = m_list[who].fy;
395 m_ptr->target_x = m_list[who].fx;
399 if (p_ptr->riding && (p_ptr->riding == m_idx) && (dam > 0))
403 /* Extract monster name */
404 monster_desc(m_name, m_ptr, 0);
406 if (m_ptr->hp > m_ptr->maxhp/3) dam = (dam + 1) / 2;
407 if (rakuba((dam > 200) ? 200 : dam, FALSE))
410 msg_format("%^s¤Ë¿¶¤êÍî¤È¤µ¤ì¤¿¡ª", m_name);
412 msg_format("You have thrown off from %s!", m_name);
423 * Returns whether a given monster will try to run from the player.
425 * Monsters will attempt to avoid very powerful players. See below.
427 * Because this function is called so often, little details are important
428 * for efficiency. Like not using "mod" or "div" when possible. And
429 * attempting to check the conditions in an optimal order. Note that
430 * "(x << 2) == (x * 4)" if "x" has enough bits to hold the result.
432 * Note that this function is responsible for about one to five percent
433 * of the processor use in normal conditions...
435 static int mon_will_run(int m_idx)
437 monster_type *m_ptr = &m_list[m_idx];
441 monster_race *r_ptr = &r_info[m_ptr->r_idx];
450 /* Friends can be commanded to avoid the player */
453 /* Are we trying to avoid the player? */
454 return ((p_ptr->pet_follow_distance < 0) &&
455 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
458 /* Keep monsters from running too far away */
459 if (m_ptr->cdis > MAX_SIGHT + 5) return (FALSE);
461 /* All "afraid" monsters will run away */
462 if (m_ptr->monfear) return (TRUE);
466 /* Nearby monsters will not become terrified */
467 if (m_ptr->cdis <= 5) return (FALSE);
469 /* Examine player power (level) */
472 /* Examine monster power (level plus morale) */
473 m_lev = r_ptr->level + (m_idx & 0x08) + 25;
475 /* Optimize extreme cases below */
476 if (m_lev > p_lev + 4) return (FALSE);
477 if (m_lev + 4 <= p_lev) return (TRUE);
479 /* Examine player health */
483 /* Examine monster health */
485 m_mhp = m_ptr->maxhp;
487 /* Prepare to optimize the calculation */
488 p_val = (p_lev * p_mhp) + (p_chp << 2); /* div p_mhp */
489 m_val = (m_lev * m_mhp) + (m_chp << 2); /* div m_mhp */
491 /* Strong players scare strong monsters */
492 if (p_val * m_mhp > m_val * p_mhp) return (TRUE);
496 /* Assume no terror */
504 * Choose the "best" direction for "flowing"
506 * Note that ghosts and rock-eaters are never allowed to "flow",
507 * since they should move directly towards the player.
509 * Prefer "non-diagonal" directions, but twiddle them a little
510 * to angle slightly towards the player's actual location.
512 * Allow very perceptive monsters to track old "spoor" left by
513 * previous locations occupied by the player. This will tend
514 * to have monsters end up either near the player or on a grid
515 * recently occupied by the player (and left via "teleport").
517 * Note that if "smell" is turned on, all monsters get vicious.
519 * Also note that teleporting away from a location will cause
520 * the monsters who were chasing you to converge on that location
521 * as long as you are still near enough to "annoy" them without
522 * being close enough to chase directly. I have no idea what will
523 * happen if you combine "smell" with low "aaf" values.
525 static bool get_moves_aux(int m_idx, int *yp, int *xp)
527 int i, y, x, y1, x1, best;
530 bool use_sound = FALSE;
531 bool use_scent = FALSE;
533 monster_type *m_ptr = &m_list[m_idx];
534 monster_race *r_ptr = &r_info[m_ptr->r_idx];
536 /* Monster flowing disabled */
537 if (stupid_monsters) return (FALSE);
539 /* Monster can go through rocks */
540 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) return (FALSE);
541 if (r_ptr->flags2 & RF2_KILL_WALL) return (FALSE);
542 if (!cave_floor_bold(py, px) && (cave[py][px].feat != FEAT_TREES)) return (FALSE);
544 /* Monster location */
548 /* Hack -- Player can see us, run towards him */
549 if (player_has_los_bold(y1, x1)) return (FALSE);
552 c_ptr = &cave[y1][x1];
554 /* If we can hear noises, advance towards them */
561 /* Otherwise, try to follow a scent trail */
562 else if (c_ptr->when)
565 if (cave[py][px].when - c_ptr->when > 127) return (FALSE);
571 /* Otherwise, advance blindly */
577 /* Check nearby grids, diagonals first */
578 for (i = 7; i >= 0; i--)
580 /* Get the location */
584 /* Ignore locations off of edge */
585 if (!in_bounds2(y, x)) continue;
589 /* We're following a scent trail */
592 int when = c_ptr->when;
594 /* Accept younger scent */
595 if (best > when) continue;
599 /* We're using sound */
604 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
606 else cost = c_ptr->cost;
608 /* Accept louder sounds */
609 if ((cost == 0) || (best < cost)) continue;
613 /* Hack -- Save the "twiddled" location */
614 (*yp) = py + 16 * ddy_ddd[i];
615 (*xp) = px + 16 * ddx_ddd[i];
618 /* No legal move (?) */
619 if (best == 999 || best == 0) return (FALSE);
627 * Provide a location to flee to, but give the player a wide berth.
629 * A monster may wish to flee to a location that is behind the player,
630 * but instead of heading directly for it, the monster should "swerve"
631 * around the player so that he has a smaller chance of getting hit.
633 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
635 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
636 int dist = 0, score = -1;
639 monster_type *m_ptr = &m_list[m_idx];
641 /* Monster flowing disabled */
642 if (stupid_monsters) return (FALSE);
644 /* Monster location */
648 /* Desired destination */
652 /* Check nearby grids, diagonals first */
653 for (i = 7; i >= 0; i--)
657 /* Get the location */
661 /* Ignore locations off of edge */
662 if (!in_bounds2(y, x)) continue;
664 if (cave[y][x].dist < dist) continue;
666 /* Calculate distance of this grid from our destination */
667 dis = distance(y, x, y1, x1);
669 /* Score this grid */
670 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
672 /* No negative scores */
675 /* Ignore lower scores */
676 if (s < score) continue;
678 /* Save the score and time */
679 dist = cave[y][x].dist;
682 /* Save the location */
687 /* No legal move (?) */
688 if (score == -1) return (FALSE);
699 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
702 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
703 * offsets of all the locations with a distance of n from a central point,
704 * with an offset of (0,0) indicating no more offsets at this distance.
706 * This is, of course, fairly unreadable, but it eliminates multiple loops
707 * from the previous version.
709 * It is probably better to replace these arrays with code to compute
710 * the relevant arrays, even if the storage is pre-allocated in hard
711 * coded sizes. At the very least, code should be included which is
712 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
714 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
716 * These arrays could be combined into two big arrays, using sub-arrays
717 * to hold the offsets and lengths of each portion of the sub-arrays, and
718 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
722 static sint d_off_y_0[] =
725 static sint d_off_x_0[] =
729 static sint d_off_y_1[] =
730 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
732 static sint d_off_x_1[] =
733 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
736 static sint d_off_y_2[] =
737 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
739 static sint d_off_x_2[] =
740 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
743 static sint d_off_y_3[] =
744 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
747 static sint d_off_x_3[] =
748 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
752 static sint d_off_y_4[] =
753 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
754 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
756 static sint d_off_x_4[] =
757 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
758 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
761 static sint d_off_y_5[] =
762 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
763 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
766 static sint d_off_x_5[] =
767 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
768 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
772 static sint d_off_y_6[] =
773 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
774 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
777 static sint d_off_x_6[] =
778 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
779 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
780 -3, 2, 3, -1, 0, 1, 0 };
783 static sint d_off_y_7[] =
784 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
785 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
786 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
788 static sint d_off_x_7[] =
789 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
790 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
791 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
795 static sint d_off_y_8[] =
796 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
797 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
798 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
801 static sint d_off_x_8[] =
802 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
803 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
804 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
808 static sint d_off_y_9[] =
809 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
810 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
811 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
812 7, 8, 8, 8, 8, 9, 9, 9, 0 };
814 static sint d_off_x_9[] =
815 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
816 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
817 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
818 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
821 static sint *dist_offsets_y[10] =
823 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
824 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
827 static sint *dist_offsets_x[10] =
829 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
830 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
834 * Choose a "safe" location near a monster for it to run toward.
836 * A location is "safe" if it can be reached quickly and the player
837 * is not able to fire into it (it isn't a "clean shot"). So, this will
838 * cause monsters to "duck" behind walls. Hopefully, monsters will also
839 * try to run towards corridor openings if they are in a room.
841 * This function may take lots of CPU time if lots of monsters are
844 * Return TRUE if a safe location is available.
846 static bool find_safety(int m_idx, int *yp, int *xp)
848 monster_type *m_ptr = &m_list[m_idx];
853 int y, x, dy, dx, d, dis, i;
854 int gy = 0, gx = 0, gdis = 0;
861 /* Start with adjacent locations, spread further */
862 for (d = 1; d < 10; d++)
864 /* Get the lists of points with a distance d from (fx, fy) */
865 y_offsets = dist_offsets_y[d];
866 x_offsets = dist_offsets_x[d];
868 /* Check the locations */
869 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
871 i++, dx = x_offsets[i], dy = y_offsets[i])
876 /* Skip illegal locations */
877 if (!in_bounds(y, x)) continue;
881 /* Skip locations in a wall */
882 if (!cave_floor_grid(c_ptr)) continue;
884 /* Check for "availability" (if monsters can flow) */
885 if (!stupid_monsters && !(m_ptr->mflag2 & MFLAG_NOFLOW))
887 /* Ignore grids very far from the player */
888 if (c_ptr->when < cave[py][px].when) continue;
890 /* Ignore too-distant grids */
891 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
894 /* Check for absence of shot (more or less) */
895 if (clean_shot(fy, fx, y, x, FALSE))
898 /* Calculate distance from player */
899 dis = distance(y, x, py, px);
901 /* Remember if further than previous */
906 if (!player_has_los_grid(c_ptr))
918 /* Check for success */
919 if (gdis > d + m_ptr->cdis)
925 /* Found safe place */
932 /* Save farthest location from player in LOS of monster */
936 /* Hack - return TRUE anyway. */
942 * Choose a good hiding place near a monster for it to run toward.
944 * Pack monsters will use this to "ambush" the player and lure him out
945 * of corridors into open space so they can swarm him.
947 * Return TRUE if a good location is available.
949 static bool find_hiding(int m_idx, int *yp, int *xp)
951 monster_type *m_ptr = &m_list[m_idx];
956 int y, x, dy, dx, d, dis, i;
957 int gy = 0, gx = 0, gdis = 999;
959 sint *y_offsets, *x_offsets;
963 /* Start with adjacent locations, spread further */
964 for (d = 1; d < 10; d++)
966 /* Get the lists of points with a distance d from (fx, fy) */
967 y_offsets = dist_offsets_y[d];
968 x_offsets = dist_offsets_x[d];
970 /* Check the locations */
971 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
973 i++, dx = x_offsets[i], dy = y_offsets[i])
978 /* Skip illegal locations */
979 if (!in_bounds(y, x)) continue;
983 /* Skip occupied locations */
984 if (!cave_empty_grid(c_ptr)) continue;
986 /* Check for hidden, available grid */
987 if (!player_has_los_grid(c_ptr) && clean_shot(fy, fx, y, x, FALSE))
989 /* Calculate distance from player */
990 dis = distance(y, x, py, px);
992 /* Remember if closer than previous */
993 if (dis < gdis && dis >= 2)
1002 /* Check for success */
1009 /* Found good place */
1020 * Choose "logical" directions for monster movement
1022 static bool get_moves(int m_idx, int *mm)
1024 monster_type *m_ptr = &m_list[m_idx];
1025 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1031 bool will_run = mon_will_run(m_idx);
1033 bool no_flow = ((m_ptr->mflag2 & MFLAG_NOFLOW) && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1036 /* Flow towards the player */
1037 if (!stupid_monsters && !no_flow)
1039 /* Flow towards the player */
1040 (void)get_moves_aux(m_idx, &y2, &x2);
1043 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
1045 /* Extract the "pseudo-direction" */
1049 if (!stupid_monsters && !will_run && is_hostile(m_ptr) &&
1050 (r_ptr->flags1 & RF1_FRIENDS) &&
1051 (los(m_ptr->fy, m_ptr->fx, py, px) ||
1052 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1055 * Animal packs try to get the player out of corridors
1056 * (...unless they can move through walls -- TY)
1058 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1059 !(r_ptr->flags2 & RF2_KILL_WALL))
1063 /* Count room grids next to player */
1064 for (i = 0; i < 8; i++)
1066 int x = px + ddx_ddd[i];
1067 int y = py + ddy_ddd[i];
1071 if (!in_bounds2(y, x)) continue;
1073 c_ptr = &cave[y][x];
1076 if (((cave_floor_grid(c_ptr)) || ((c_ptr->feat & 0x60) == 0x60)) &&
1077 monster_can_cross_terrain(c_ptr->feat, r_ptr))
1079 /* One more room grid */
1083 if (cave[py][px].info & CAVE_ROOM) room -= 2;
1084 if (!r_ptr->flags4 && !r_ptr->flags5 && !r_ptr->flags6) room -= 2;
1086 /* Not in a room and strong player */
1087 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
1088 (p_ptr->mhp + p_ptr->msp))
1090 /* Find hiding place */
1091 if (find_hiding(m_idx, &y, &x)) done = TRUE;
1095 /* Monster groups try to surround the player */
1096 if (!done && (cave[m_ptr->fy][m_ptr->fx].dist < 3))
1100 /* Find an empty square near the player to fill */
1101 for (i = 0; i < 8; i++)
1103 /* Pick squares near player (semi-randomly) */
1104 y2 = py + ddy_ddd[(m_idx + i) & 7];
1105 x2 = px + ddx_ddd[(m_idx + i) & 7];
1107 /* Already there? */
1108 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
1110 /* Attack the player */
1117 if (!in_bounds2(y2, x2)) continue;
1119 /* Ignore filled grids */
1120 c_ptr = &cave[y2][x2];
1121 if (!cave_empty_grid(c_ptr)) continue;
1123 /* Try to fill this hole */
1127 /* Extract the new "pseudo-direction" */
1136 /* Apply fear if possible and necessary */
1137 if ((stupid_monsters || is_pet(m_ptr)) && will_run)
1139 /* XXX XXX Not very "smart" */
1144 if (!done && will_run)
1146 /* Try to find safe place */
1147 if (!find_safety(m_idx, &y, &x))
1149 /* This is not a very "smart" method XXX XXX */
1155 /* Attempt to avoid the player */
1156 if (!stupid_monsters && !no_flow)
1158 /* Adjust movement */
1159 (void)get_fear_moves_aux(m_idx, &y, &x);
1166 if (!stupid_monsters)
1168 /* Check for no move */
1169 if (!x && !y) return (FALSE);
1173 /* Extract the "absolute distances" */
1177 /* Do something weird */
1178 if (y < 0) move_val += 8;
1179 if (x > 0) move_val += 4;
1181 /* Prevent the diamond maneuvre */
1187 else if (ax > (ay << 1))
1192 /* Extract some directions */
1337 /* Wants to move... */
1342 static int check_hit2(int power, int level, int ac, int stun)
1346 /* Percentile dice */
1349 if (stun && one_in_(2)) return FALSE;
1351 /* Hack -- Always miss or hit */
1352 if (k < 10) return (k < 5);
1354 /* Calculate the "attack quality" */
1355 i = (power + (level * 3));
1357 /* Power and Level compete against Armor */
1358 if ((i > 0) && (randint(i) > ((ac * 3) / 4))) return (TRUE);
1365 /* Monster attacks monster */
1366 static bool monst_attack_monst(int m_idx, int t_idx)
1368 monster_type *m_ptr = &m_list[m_idx];
1369 monster_type *t_ptr = &m_list[t_idx];
1371 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1372 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1376 char m_name[80], t_name[80];
1377 char ddesc[80], temp[80];
1378 bool blinked, heal_effect;
1379 bool explode = FALSE, touched = FALSE, fear = FALSE;
1380 int y_saver = t_ptr->fy;
1381 int x_saver = t_ptr->fx;
1383 bool see_m = m_ptr->ml;
1384 bool see_t = t_ptr->ml;
1385 bool see_either = see_m || see_t;
1387 /* Can the player be aware of this attack? */
1388 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1389 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1391 /* Cannot attack self */
1392 if (m_idx == t_idx) return FALSE;
1394 /* Not allowed to attack */
1395 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1397 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1405 /* Extract the effective monster level */
1406 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1408 /* Get the monster name (or "it") */
1409 monster_desc(m_name, m_ptr, 0);
1411 /* Get the monster name (or "it") */
1412 monster_desc(t_name, t_ptr, 0);
1414 /* Get the "died from" information (i.e. "a kobold") */
1415 monster_desc(ddesc, m_ptr, 0x88);
1417 /* Assume no blink */
1420 if (!see_either && known)
1425 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
1427 /* Scan through all four blows */
1428 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1430 bool obvious = FALSE;
1437 /* Extract the attack infomation */
1438 int effect = r_ptr->blow[ap_cnt].effect;
1439 int method = r_ptr->blow[ap_cnt].method;
1440 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1441 int d_side = r_ptr->blow[ap_cnt].d_side;
1443 if (!m_ptr->r_idx) break;
1445 /* Stop attacking if the target dies! */
1446 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1449 /* Hack -- no more attacks */
1452 if (blinked) /* Stop! */
1457 /* Extract the attack "power" */
1460 case RBE_HURT: power = 60; break;
1461 case RBE_POISON: power = 5; break;
1462 case RBE_UN_BONUS: power = 20; break;
1463 case RBE_UN_POWER: power = 15; break;
1464 case RBE_EAT_GOLD: power = 5; break;
1465 case RBE_EAT_ITEM: power = 5; break;
1466 case RBE_EAT_FOOD: power = 5; break;
1467 case RBE_EAT_LITE: power = 5; break;
1468 case RBE_ACID: power = 0; break;
1469 case RBE_ELEC: power = 10; break;
1470 case RBE_FIRE: power = 10; break;
1471 case RBE_COLD: power = 10; break;
1472 case RBE_BLIND: power = 2; break;
1473 case RBE_CONFUSE: power = 10; break;
1474 case RBE_TERRIFY: power = 10; break;
1475 case RBE_PARALYZE: power = 2; break;
1476 case RBE_LOSE_STR: power = 0; break;
1477 case RBE_LOSE_DEX: power = 0; break;
1478 case RBE_LOSE_CON: power = 0; break;
1479 case RBE_LOSE_INT: power = 0; break;
1480 case RBE_LOSE_WIS: power = 0; break;
1481 case RBE_LOSE_CHR: power = 0; break;
1482 case RBE_LOSE_ALL: power = 2; break;
1483 case RBE_SHATTER: power = 60; break;
1484 case RBE_EXP_10: power = 5; break;
1485 case RBE_EXP_20: power = 5; break;
1486 case RBE_EXP_40: power = 5; break;
1487 case RBE_EXP_80: power = 5; break;
1488 case RBE_DISEASE: power = 5; break;
1489 case RBE_TIME: power = 5; break;
1490 case RBE_EXP_VAMP: power = 5; break;
1491 case RBE_DR_MANA: power = 5; break;
1492 case RBE_SUPERHURT: power = 60; break;
1497 if (!effect || check_hit2(power, rlev, ac, m_ptr->stunned))
1499 /* Describe the attack method */
1505 act = "%s¤ò²¥¤Ã¤¿¡£";
1517 act = "%s¤ò¿¨¤Ã¤¿¡£";
1519 act = "touches %s.";
1529 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1531 act = "punches %s.";
1541 act = "%s¤ò½³¤Ã¤¿¡£";
1553 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1565 act = "%s¤ò³ú¤ó¤À¡£";
1577 act = "%s¤ò»É¤·¤¿¡£";
1589 act = "%s¤ò»Â¤Ã¤¿¡£";
1591 act = "slashes %s.";
1600 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1612 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1614 act = "crushes %s.";
1624 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1626 act = "engulfs %s.";
1636 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1638 act = "charges %s.";
1648 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1650 act = "crawls on %s.";
1660 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1662 act = "drools on %s.";
1672 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1674 act = "spits on %s.";
1683 if (see_either) disturb(1, 0);
1698 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1700 act = "gazes at %s.";
1710 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1712 act = "wails at %s.";
1722 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1724 act = "releases spores at %s.";
1734 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1736 act = "projects XXX4's at %s.";
1746 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1748 act = "begs %s for money.";
1758 act = "%s¤òÉî¿«¤·¤¿¡£";
1760 act = "insults %s.";
1770 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1772 act = "moans at %s.";
1782 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1784 act = "sings to %s.";
1793 if (act && see_either)
1795 if (do_silly_attack)
1797 act = silly_attacks[rand_int(MAX_SILLY_ATTACK)];
1799 strfmt(temp, act, t_name);
1801 msg_format("%^s¤Ï%s", m_name, temp);
1803 msg_format("%^s %s", m_name, temp);
1808 /* Hack -- assume all attacks are obvious */
1811 /* Roll out the damage */
1812 damage = damroll(d_dice, d_side);
1814 /* Assume no healing effect */
1815 heal_effect = FALSE;
1819 /* Apply appropriate damage */
1831 if ((randint(rlev*2+250) > (ac+200)) || one_in_(13)) {
1832 int tmp_damage = damage-(damage*((ac < 150) ? ac : 150)/250);
1833 damage = MAX(damage, tmp_damage*2);
1839 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1869 if (randint(2) == 1) blinked = TRUE;
1916 pt = GF_OLD_SLEEP; /* sort of close... */
1934 earthquake(m_ptr->fy, m_ptr->fx, 8);
1967 /* Do damage if not exploding */
1970 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1971 (pt == GF_OLD_SLEEP ? r_ptr->level : damage), pt, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
1976 if ((monster_living(tr_ptr)) && (damage > 2))
1978 bool did_heal = FALSE;
1980 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
1983 m_ptr->hp += damroll(4, damage / 6);
1984 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
1986 /* Redraw (later) if needed */
1987 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1988 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1990 /* Special message */
1991 if (see_m && did_heal)
1994 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
1996 msg_format("%^s appears healthier.", m_name);
2006 if ((tr_ptr->flags2 & RF2_AURA_FIRE) &&
2007 !(r_ptr->flags3 & RF3_IM_FIRE) &&
2008 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2014 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2016 msg_format("%^s is suddenly very hot!", m_name);
2020 tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2022 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2023 damroll (1 + ((tr_ptr->level) / 26),
2024 1 + ((tr_ptr->level) / 17)),
2025 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2029 if ((tr_ptr->flags3 & RF3_AURA_COLD) &&
2030 !(r_ptr->flags3 & RF3_IM_COLD) &&
2031 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2037 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2039 msg_format("%^s is suddenly very cold!", m_name);
2043 tr_ptr->r_flags3 |= RF3_AURA_COLD;
2045 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2046 damroll (1 + ((tr_ptr->level) / 26),
2047 1 + ((tr_ptr->level) / 17)),
2048 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2052 if ((tr_ptr->flags2 & (RF2_AURA_ELEC)) &&
2053 !(r_ptr->flags3 & (RF3_IM_ELEC)) &&
2054 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2060 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2062 msg_format("%^s gets zapped!", m_name);
2066 tr_ptr->r_flags2 |= RF2_AURA_ELEC;
2068 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2069 damroll (1 + ((tr_ptr->level) / 26),
2070 1 + ((tr_ptr->level) / 17)),
2071 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2078 /* Monster missed player */
2081 /* Analyze failed attacks */
2097 /* Visible monsters */
2102 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2104 msg_format("%^s misses %s.", m_name, t_name);
2115 /* Analyze "visible" monsters only */
2116 if (see_m && !do_silly_attack)
2118 /* Count "obvious" attacks (and ones that cause damage) */
2119 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2121 /* Count attacks of this type */
2122 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2124 r_ptr->r_blows[ap_cnt]++;
2132 sound(SOUND_EXPLODE);
2134 /* Cancel Invulnerability */
2135 if (m_ptr->invulner) m_ptr->invulner = 0;
2138 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2140 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2154 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2156 msg_print("The thief flees laughing!");
2165 teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE);
2173 * Hack -- local "player stealth" value (see below)
2175 static u32b noise = 0L;
2181 * The monster is known to be within 100 grids of the player
2183 * In several cases, we directly update the monster lore
2185 * Note that a monster is only allowed to "reproduce" if there
2186 * are a limited number of "reproducing" monsters on the current
2187 * level. This should prevent the level from being "swamped" by
2188 * reproducing monsters. It also allows a large mass of mice to
2189 * prevent a louse from multiplying, but this is a small price to
2190 * pay for a simple multiplication method.
2192 * XXX Monster fear is slightly odd, in particular, monsters will
2193 * fixate on opening a door even if they cannot open it. Actually,
2194 * the same thing happens to normal monsters when they hit a door
2196 * XXX XXX XXX In addition, monsters which *cannot* open or bash
2197 * down a door will still stand there trying to open it...
2199 * XXX Technically, need to check for monster in the way
2200 * combined with that monster being in a wall (or door?)
2202 * A "direction" of "5" means "pick a random direction".
2204 static void process_monster(int m_idx)
2206 monster_type *m_ptr = &m_list[m_idx];
2207 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2209 int i, d, oy, ox, ny, nx;
2215 monster_type *y_ptr;
2228 bool gets_angry = FALSE;
2234 if ((m_idx == p_ptr->riding) && !(r_ptr->flags7 & RF7_RIDING))
2236 if (rakuba(0, TRUE))
2239 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2242 monster_desc(m_name, &m_list[p_ptr->riding], 0);
2243 msg_format("You have fallen from %s.", m_name);
2248 if ((m_ptr->mflag2 & MFLAG_CHAMELEON) && one_in_(13) && !m_ptr->csleep)
2250 choose_new_monster(m_idx, FALSE, 0);
2251 r_ptr = &r_info[m_ptr->r_idx];
2254 /* Players hidden in shadow are almost imperceptable. -LM- */
2255 if (p_ptr->special_defense & NINJA_S_STEALTH)
2257 int tmp = p_ptr->lev*6+(p_ptr->skill_stl+10)*4;
2258 if (p_ptr->monlite) tmp /= 3;
2259 if (p_ptr->aggravate) tmp /= 2;
2260 if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
2261 /* Low-level monsters will find it difficult to locate the player. */
2262 if (rand_int(tmp) > (r_ptr->level+20)) aware = FALSE;
2265 /* Quantum monsters are odd */
2266 if (r_ptr->flags2 & (RF2_QUANTUM))
2268 /* Sometimes skip move */
2269 if (!rand_int(2)) return;
2272 if (!rand_int((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2276 if (is_pet(m_ptr) && !(m_ptr->ml))
2283 /* Acquire the monster name */
2284 monster_desc(m_name, m_ptr, 0);
2288 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2290 msg_format("%^s disappears!", m_name);
2295 /* Generate treasure, etc */
2296 monster_death(m_idx, FALSE);
2298 /* Delete the monster */
2299 delete_monster_idx(m_idx);
2304 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2306 msg_print("You feel sad for a moment.");
2315 if (m_ptr->r_idx == MON_SHURYUUDAN)
2317 mon_take_hit_mon(FALSE, m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2319 mon_take_hit_mon(FALSE, m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2322 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) && !p_ptr->inside_battle)
2324 static int riding_pinch = 0;
2326 if (m_ptr->hp < m_ptr->maxhp/3)
2328 bool level_teleport = TRUE;
2330 monster_desc(m_name, m_ptr, 0);
2332 if (m_idx == p_ptr->riding && riding_pinch < 2)
2335 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2337 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
2340 level_teleport = FALSE;
2345 if (m_idx == p_ptr->riding)
2348 msg_format("%s¤Ï¤¢¤Ê¤¿¤Î«Çû¤«¤éæ½Ð¤·¤¿¡£", m_name);
2350 msg_format("%^s succeeded to escape from your restriction!", m_name);
2353 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))
2356 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2358 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2362 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2364 msg_format("%^s read a scroll of teleport level.", m_name);
2367 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2369 msg_format("%^s disappears.", m_name);
2375 delete_monster_idx(m_idx);
2377 if (m_idx == p_ptr->riding)
2379 if (rakuba(-1, FALSE))
2382 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2384 msg_print("You have fallen from riding pet.");
2392 if (m_idx == p_ptr->riding) riding_pinch = 0;
2396 /* Handle "sleep" */
2401 /* Hack -- handle non-aggravation */
2402 if (!p_ptr->aggravate) notice = rand_int(1024);
2404 /* Nightmare monsters are more alert */
2405 if (ironman_nightmare) notice /= 2;
2407 /* Hack -- See if monster "notices" player */
2408 if ((notice * notice * notice) <= noise)
2410 /* Hack -- amount of "waking" */
2413 /* Wake up faster near the player */
2414 if (m_ptr->cdis < 50) d = (100 / m_ptr->cdis);
2416 /* Hack -- handle aggravation */
2417 if (p_ptr->aggravate) d = m_ptr->csleep;
2420 if (m_ptr->csleep > d)
2422 /* Monster wakes up "a little bit" */
2425 /* Notice the "not waking up" */
2428 /* Hack -- Count the ignores */
2429 if (r_ptr->r_ignore < MAX_UCHAR)
2439 /* Reset sleep counter */
2442 /* Notice the "waking up" */
2447 /* Acquire the monster name */
2448 monster_desc(m_name, m_ptr, 0);
2450 /* Dump a message */
2452 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
2454 msg_format("%^s wakes up.", m_name);
2458 /* Redraw the health bar */
2459 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2460 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2462 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2))
2463 p_ptr->update |= (PU_MON_LITE);
2465 /* Hack -- Count the wakings */
2466 if (r_ptr->r_wake < MAX_UCHAR)
2474 /* Still sleeping */
2475 if (m_ptr->csleep) return;
2484 /* Make a "saving throw" against stun */
2485 if (rand_int(10000) <= r_ptr->level * r_ptr->level)
2491 /* Hack -- Recover from stun */
2492 if (m_ptr->stunned > d)
2494 /* Recover somewhat */
2495 m_ptr->stunned -= d;
2504 /* Message if visible */
2509 /* Acquire the monster name */
2510 monster_desc(m_name, m_ptr, 0);
2512 /* Dump a message */
2514 msg_format("%^s¤ÏÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2516 msg_format("%^s is no longer stunned.", m_name);
2519 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2520 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2525 if (m_ptr->stunned && one_in_(2)) return;
2529 /* Handle confusion */
2530 if (m_ptr->confused)
2532 /* Amount of "boldness" */
2533 int d = randint(r_ptr->level / 20 + 1);
2535 /* Still confused */
2536 if (m_ptr->confused > d)
2538 /* Reduce the confusion */
2539 m_ptr->confused -= d;
2545 /* No longer confused */
2546 m_ptr->confused = 0;
2548 /* Message if visible */
2553 /* Acquire the monster name */
2554 monster_desc(m_name, m_ptr, 0);
2556 /* Dump a message */
2558 msg_format("%^s¤Ïº®Í𤫤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2560 msg_format("%^s is no longer confused.", m_name);
2563 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2564 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2569 /* Handle Invulnerability */
2570 if (m_ptr->invulner)
2572 /* Reduce by one, note if expires */
2575 if (!(m_ptr->invulner) && m_ptr->ml)
2579 /* Acquire the monster name */
2580 monster_desc(m_name, m_ptr, 0);
2582 /* Dump a message */
2584 msg_format("%^s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ê¤¤¡£", m_name);
2586 msg_format("%^s is no longer invulnerable.", m_name);
2589 m_ptr->energy -= 100;
2590 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2591 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2598 /* Reduce by one, note if expires */
2601 if (!(m_ptr->fast) && m_ptr->ml)
2605 /* Acquire the monster name */
2606 monster_desc(m_name, m_ptr, 0);
2608 /* Dump a message */
2610 msg_format("%^s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2612 msg_format("%^s is no longer fast.", m_name);
2615 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2616 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2623 /* Reduce by one, note if expires */
2626 if (!(m_ptr->slow) && m_ptr->ml)
2630 /* Acquire the monster name */
2631 monster_desc(m_name, m_ptr, 0);
2633 /* Dump a message */
2635 msg_format("%^s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2637 msg_format("%^s is no longer slow.", m_name);
2640 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2641 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2645 if (p_ptr->riding == m_idx)
2647 p_ptr->update |= (PU_BONUS);
2650 /* No one wants to be your friend if you're aggravating */
2651 if (is_friendly(m_ptr) && p_ptr->aggravate)
2654 /* Paranoia... no pet uniques outside wizard mode -- TY */
2655 if (is_pet(m_ptr) &&
2656 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
2657 ((p_ptr->align > 9 && (r_ptr->flags3 & RF3_EVIL)) ||
2658 (p_ptr->align < -9 && (r_ptr->flags3 & RF3_GOOD))))
2659 || (r_ptr->flags3 & RF3_RES_ALL)))
2664 if (p_ptr->inside_battle) gets_angry = FALSE;
2669 monster_desc(m_name, m_ptr, 0);
2671 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2673 msg_format("%^s suddenly becomes hostile!", m_name);
2682 /* Amount of "boldness" */
2683 int d = randint(r_ptr->level / 20 + 1);
2686 if (m_ptr->monfear > d)
2688 /* Reduce the fear */
2689 m_ptr->monfear -= d;
2692 /* Recover from fear, take note if seen */
2695 /* No longer afraid */
2704 /* Acquire the monster name/poss */
2705 monster_desc(m_name, m_ptr, 0);
2706 monster_desc(m_poss, m_ptr, 0x22);
2708 /* Dump a message */
2710 msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name);
2712 msg_format("%^s recovers %s courage.", m_name, m_poss);
2715 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2720 /* Get the origin */
2725 /* Attempt to "multiply" if able and allowed */
2726 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2730 /* Count the adjacent monsters */
2731 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2733 for (x = ox - 1; x <= ox + 1; x++)
2735 /* Ignore locations off of edge */
2736 if (!in_bounds2(y, x)) continue;
2738 if (cave[y][x].m_idx) k++;
2742 /* Hack -- multiply slower in crowded areas */
2743 if ((k < 4) && (!k || !rand_int(k * MON_MULT_ADJ)))
2745 /* Try to multiply */
2746 if (multiply_monster(m_idx, FALSE, is_friendly(m_ptr), is_pet(m_ptr)))
2748 /* Take note if visible */
2751 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2754 /* Multiplying takes energy */
2761 if (!p_ptr->inside_battle)
2763 /* Hack! "Cyber" monster makes noise... */
2764 if (m_ptr->r_idx == MON_CYBER &&
2765 (randint(CYBERNOISE) == 1) &&
2766 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2768 if (disturb_minor) disturb(FALSE, FALSE);
2770 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2772 msg_print("You hear heavy steps.");
2777 /* Some monsters can speak */
2778 if ((r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2779 (randint(SPEAK_CHANCE) == 1) &&
2780 player_has_los_bold(oy, ox))
2783 char monmessage[1024];
2786 /* Acquire the monster name/poss */
2788 monster_desc(m_name, m_ptr, 0);
2791 strcpy(m_name, "¤½¤ì");
2793 strcpy(m_name, "It");
2797 /* Select the file for monster quotes */
2800 filename = "monfear_j.txt";
2802 filename = "monfear.txt";
2805 else if (is_pet(m_ptr))
2807 filename = "monpet_j.txt";
2809 filename = "monpet.txt";
2812 else if (is_friendly(m_ptr))
2814 filename = "monfrien_j.txt";
2816 filename = "monfrien.txt";
2821 filename = "monspeak_j.txt";
2823 filename = "monspeak.txt";
2827 /* Get the monster line */
2828 if (get_rnd_line(filename, m_ptr->r_idx, monmessage) == 0)
2832 msg_format("%^s%s", m_name, monmessage);
2834 msg_format("%^s %s", m_name, monmessage);
2841 /* Attempt to cast a spell */
2842 if (aware && make_attack_spell(m_idx)) return;
2845 * Attempt to cast a spell at an enemy other than the player
2846 * (may slow the game a smidgeon, but I haven't noticed.)
2848 if (monst_spell_monst(m_idx)) return;
2850 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
2852 /* Hack -- Assume no movement */
2853 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2854 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2857 /* Confused -- 100% random */
2858 if (m_ptr->confused || !aware)
2860 /* Try four "random" directions */
2861 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2864 /* 75% random movement */
2865 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2866 (r_ptr->flags1 & RF1_RAND_25) &&
2867 (rand_int(100) < 75))
2869 /* Memorize flags */
2870 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2871 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25);
2873 /* Try four "random" directions */
2874 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2877 /* 50% random movement */
2878 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2879 (rand_int(100) < 50))
2881 /* Memorize flags */
2882 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2884 /* Try four "random" directions */
2885 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2888 /* 25% random movement */
2889 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2890 (rand_int(100) < 25))
2892 /* Memorize flags */
2893 if (m_ptr->ml) r_ptr->r_flags1 |= RF1_RAND_25;
2895 /* Try four "random" directions */
2896 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2899 /* Can't reach player - find something else to hit */
2900 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2902 /* Try four "random" directions */
2903 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2905 /* Look for an enemy */
2906 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2907 get_enemy_dir(m_idx, mm);
2911 /* Pets will follow the player */
2912 else if (is_pet(m_ptr))
2914 /* Are we trying to avoid the player? */
2915 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
2916 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2918 /* Do we want to find the player? */
2919 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2921 /* Should we find the player if we can't find a monster? */
2922 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2924 /* by default, move randomly */
2925 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2927 /* Look for an enemy */
2928 if (!get_enemy_dir(m_idx, mm))
2930 /* Find the player if necessary */
2931 if (avoid || lonely || distant)
2933 /* Remember the leash length */
2934 int dis = p_ptr->pet_follow_distance;
2936 /* Hack -- adjust follow distance temporarily */
2937 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2939 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2942 /* Find the player */
2943 get_moves(m_idx, mm);
2945 /* Restore the leash */
2946 p_ptr->pet_follow_distance = dis;
2951 /* Friendly monster movement */
2952 else if (!is_hostile(m_ptr))
2954 /* by default, move randomly */
2955 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2957 /* Look for an enemy */
2958 get_enemy_dir(m_idx, mm);
2960 /* Normal movement */
2961 else if (stupid_monsters)
2964 get_moves(m_idx, mm);
2968 /* Logical moves, may do nothing */
2969 if (!get_moves(m_idx, mm)) return;
2972 /* Assume nothing */
2977 /* Assume nothing */
2978 did_open_door = FALSE;
2979 did_bash_door = FALSE;
2980 did_take_item = FALSE;
2981 did_kill_item = FALSE;
2982 did_move_body = FALSE;
2983 did_pass_wall = FALSE;
2984 did_kill_wall = FALSE;
2987 /* Take a zero-terminated array of "directions" */
2988 for (i = 0; mm[i]; i++)
2990 /* Get the direction */
2993 /* Hack -- allow "randomized" motion */
2994 if (d == 5) d = ddd[rand_int(8)];
2996 /* Get the destination */
3000 /* Ignore locations off of edge */
3001 if (!in_bounds2(ny, nx)) continue;
3003 /* Access that cave grid */
3004 c_ptr = &cave[ny][nx];
3006 /* Access that cave grid's contents */
3007 y_ptr = &m_list[c_ptr->m_idx];
3009 /* Floor is open? */
3010 if (cave_floor_grid(c_ptr))
3012 /* Go ahead and move */
3016 /* Hack -- player 'in' wall */
3017 else if ((ny == py) && (nx == px))
3022 else if (c_ptr->m_idx)
3024 /* Possibly a monster to attack */
3028 /* Permanent wall */
3029 else if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
3030 (c_ptr->feat <= FEAT_PERM_SOLID))
3035 /* Hack -- semi-transparent terrains are no obstacle */
3036 else if (c_ptr->feat == FEAT_TREES)
3041 /* Hack -- semi-transparent terrains are no obstacle */
3042 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)))))
3048 /* Monster moves through walls (and doors) */
3049 else if (can_pass_wall)
3051 /* Pass through walls/doors/rubble */
3054 /* Monster went through a wall */
3055 did_pass_wall = TRUE;
3058 /* Monster destroys walls (and doors) */
3059 else if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))
3061 /* Eat through walls/doors/rubble */
3064 /* Monster destroyed a wall */
3065 did_kill_wall = TRUE;
3067 if (randint(GRINDNOISE) == 1)
3070 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
3072 msg_print("There is a grinding sound.");
3077 /* Forget the wall */
3078 c_ptr->info &= ~(CAVE_MARK);
3081 c_ptr->feat = floor_type[rand_int(100)];
3082 c_ptr->info &= ~(CAVE_MASK);
3083 c_ptr->info |= CAVE_FLOOR;
3085 /* Note changes to viewable region */
3086 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3089 /* Handle doors and secret doors */
3090 else if (((c_ptr->feat >= FEAT_DOOR_HEAD) &&
3091 (c_ptr->feat <= FEAT_DOOR_TAIL)) ||
3092 (c_ptr->feat == FEAT_SECRET))
3094 bool may_bash = TRUE;
3096 /* Assume no move allowed */
3099 /* Creature can open doors. */
3100 if ((r_ptr->flags2 & RF2_OPEN_DOOR) &&
3101 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3103 /* Closed doors and secret doors */
3104 if ((c_ptr->feat == FEAT_DOOR_HEAD) ||
3105 (c_ptr->feat == FEAT_SECRET))
3107 /* The door is open */
3108 did_open_door = TRUE;
3110 /* Do not bash the door */
3113 /* Assume no move allowed */
3117 /* Locked doors (not jammed) */
3118 else if (c_ptr->feat < FEAT_DOOR_HEAD + 0x08)
3123 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3125 /* Try to unlock it XXX XXX XXX */
3126 if (rand_int(m_ptr->hp / 10) > k)
3128 /* Unlock the door */
3129 cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00);
3131 /* Do not bash the door */
3137 /* Stuck doors -- attempt to bash them down if allowed */
3138 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) &&
3139 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3144 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3146 /* Attempt to Bash XXX XXX XXX */
3147 if (rand_int(m_ptr->hp / 10) > k)
3151 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
3153 msg_print("You hear a door burst open!");
3157 /* Disturb (sometimes) */
3158 if (disturb_minor) disturb(0, 0);
3160 /* The door was bashed open */
3161 did_bash_door = TRUE;
3163 /* Hack -- fall into doorway */
3169 /* Deal with doors in the way */
3170 if (did_open_door || did_bash_door)
3172 /* Break down the door */
3173 if (did_bash_door && (rand_int(100) < 50))
3175 cave_set_feat(ny, nx, FEAT_BROKEN);
3181 cave_set_feat(ny, nx, FEAT_OPEN);
3184 /* Handle viewable doors */
3185 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3189 /* Hack -- check for Glyph of Warding */
3190 if (do_move && (c_ptr->feat == FEAT_GLYPH) &&
3191 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3193 /* Assume no move allowed */
3196 /* Break the ward */
3197 if (!is_pet(m_ptr) && (randint(BREAK_GLYPH) < r_ptr->level))
3199 /* Describe observable breakage */
3200 if (c_ptr->info & CAVE_MARK)
3203 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3205 msg_print("The rune of protection is broken!");
3210 /* Forget the rune */
3211 c_ptr->info &= ~(CAVE_MARK);
3213 /* Break the rune */
3214 c_ptr->feat = floor_type[rand_int(100)];
3215 c_ptr->info &= ~(CAVE_MASK);
3216 c_ptr->info |= CAVE_FLOOR;
3218 /* Allow movement */
3225 else if (do_move && (c_ptr->feat == FEAT_MINOR_GLYPH) &&
3226 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3228 /* Assume no move allowed */
3231 /* Break the ward */
3234 /* Break the ward */
3235 if (randint(BREAK_MINOR_GLYPH) > r_ptr->level)
3237 /* Describe observable breakage */
3238 if (c_ptr->info & CAVE_MARK)
3241 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3243 msg_print("The rune explodes!");
3246 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);
3252 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3254 msg_print("An explosive rune was disarmed.");
3258 /* Forget the rune */
3259 c_ptr->info &= ~(CAVE_MARK);
3261 /* Break the rune */
3262 c_ptr->feat = floor_type[rand_int(100)];
3263 c_ptr->info &= ~(CAVE_MASK);
3264 c_ptr->info |= CAVE_FLOOR;
3268 if (!m_ptr->r_idx) return;
3269 /* Allow movement */
3273 if (do_move && (ny == py) && (nx == px) && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3278 /* Some monsters never attack */
3279 if (do_move && (ny == py) && (nx == px) &&
3280 (r_ptr->flags1 & RF1_NEVER_BLOW))
3282 /* Hack -- memorize lack of attacks */
3283 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3289 /* The player is in the way. Attack him. */
3290 if (do_move && (ny == py) && (nx == px))
3292 if (!p_ptr->riding || one_in_(2))
3295 (void)make_attack_normal(m_idx);
3305 if ((c_ptr->feat >= FEAT_PATTERN_START) &&
3306 (c_ptr->feat <= FEAT_PATTERN_XTRA2) &&
3307 !do_turn && !(r_ptr->flags7 & RF7_CAN_FLY))
3313 /* A monster is in the way */
3314 if (do_move && c_ptr->m_idx)
3316 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3317 monster_type *m2_ptr = &m_list[c_ptr->m_idx];
3319 /* Assume no movement */
3322 /* Attack 'enemies' */
3323 if (((r_ptr->flags2 & (RF2_KILL_BODY)) &&
3324 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3325 (cave_floor_grid(c_ptr)) &&
3326 (c_ptr->m_idx != p_ptr->riding)) ||
3327 are_enemies(m_ptr, m2_ptr) || m_ptr->confused)
3331 if (r_ptr->flags2 & RF2_KILL_BODY) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3334 if ((m2_ptr->r_idx) && (m2_ptr->hp >= 0))
3336 if (monst_attack_monst(m_idx, cave[ny][nx].m_idx))
3341 /* Push past weaker monsters (unless leaving a wall) */
3342 else if ((r_ptr->flags2 & RF2_MOVE_BODY) &&
3343 (r_ptr->mexp > z_ptr->mexp) && cave_floor_grid(c_ptr) &&
3344 (cave_floor_grid(&cave[m_ptr->fy][m_ptr->fx])) &&
3345 (c_ptr->m_idx != p_ptr->riding))
3347 /* Allow movement */
3350 /* Monster pushed past another monster */
3351 did_move_body = TRUE;
3353 /* XXX XXX XXX Message */
3358 * Check if monster can cross terrain
3359 * This is checked after the normal attacks
3360 * to allow monsters to attack an enemy,
3361 * even if it can't enter the terrain.
3363 if (do_move && !monster_can_cross_terrain(c_ptr->feat, r_ptr))
3365 /* Assume no move allowed */
3369 /* Some monsters never move */
3370 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3372 /* Hack -- memorize lack of attacks */
3373 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3379 if (m_idx == p_ptr->riding)
3381 if (!p_ptr->riding_ryoute && !(m_list[p_ptr->riding].monfear)) do_move = FALSE;
3384 /* Creature has been allowed move */
3387 s16b this_o_idx, next_o_idx;
3392 /* Hack -- Update the old location */
3393 cave[oy][ox].m_idx = c_ptr->m_idx;
3395 if (cave[ny][nx].feat == FEAT_TREES)
3397 if (r_ptr->flags2 & RF2_KILL_WALL)
3399 c_ptr->feat = FEAT_GRASS;
3400 c_ptr->info &= ~(CAVE_MASK);
3401 c_ptr->info |= CAVE_FLOOR;
3403 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3405 m_ptr->energy -= 100;
3409 /* Mega-Hack -- move the old monster, if any */
3412 /* Move the old monster */
3416 /* Update the old monster */
3417 update_mon(c_ptr->m_idx, TRUE);
3419 /* Wake up the moved monster */
3420 m_list[c_ptr->m_idx].csleep = 0;
3423 /* Hack -- Update the new location */
3424 c_ptr->m_idx = m_idx;
3426 /* Move the monster */
3430 /* Update the monster */
3431 update_mon(m_idx, TRUE);
3433 if (p_ptr->riding == m_idx)
3439 /* Redraw the old grid */
3442 /* Redraw the new grid */
3445 if (p_ptr->riding == m_idx)
3450 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW);
3452 /* Update the monsters */
3453 p_ptr->update |= (PU_DISTANCE);
3456 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3459 /* Possible disturb */
3460 if (m_ptr->ml && (disturb_move ||
3461 ((m_ptr->mflag & MFLAG_VIEW) &&
3465 if (is_hostile(m_ptr))
3469 /* Scan all objects in the grid */
3470 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3474 /* Acquire object */
3475 o_ptr = &o_list[this_o_idx];
3477 /* Acquire next object */
3478 next_o_idx = o_ptr->next_o_idx;
3481 if (o_ptr->tval == TV_GOLD) continue;
3484 * Skip "real" corpses and statues, to avoid extreme
3485 * silliness like a novice rogue pockets full of statues
3488 if ((o_ptr->tval == TV_CORPSE) ||
3489 (o_ptr->tval == TV_STATUE)) continue;
3491 /* Take or Kill objects on the floor */
3492 if ((r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3493 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)))
3500 char o_name[MAX_NLEN];
3502 /* Extract some flags */
3503 object_flags(o_ptr, &f1, &f2, &f3);
3505 /* Acquire the object name */
3506 object_desc(o_name, o_ptr, TRUE, 3);
3508 /* Acquire the monster name */
3509 monster_desc(m_name, m_ptr, 0x04);
3511 /* React to objects that hurt the monster */
3512 if (f1 & TR1_KILL_DRAGON) flg3 |= (RF3_DRAGON);
3513 if (f1 & TR1_SLAY_DRAGON) flg3 |= (RF3_DRAGON);
3514 if (f1 & TR1_SLAY_TROLL) flg3 |= (RF3_TROLL);
3515 if (f1 & TR1_SLAY_GIANT) flg3 |= (RF3_GIANT);
3516 if (f1 & TR1_SLAY_ORC) flg3 |= (RF3_ORC);
3517 if (f1 & TR1_SLAY_DEMON) flg3 |= (RF3_DEMON);
3518 if (f1 & TR1_SLAY_UNDEAD) flg3 |= (RF3_UNDEAD);
3519 if (f1 & TR1_SLAY_ANIMAL) flg3 |= (RF3_ANIMAL);
3520 if (f1 & TR1_SLAY_EVIL) flg3 |= (RF3_EVIL);
3522 /* The object cannot be picked up by the monster */
3523 if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) ||
3526 /* Only give a message for "take_item" */
3527 if ((r_ptr->flags2 & (RF2_TAKE_ITEM)) && (r_ptr->flags2 & (RF2_STUPID)))
3530 did_take_item = TRUE;
3532 /* Describe observable situations */
3533 if (m_ptr->ml && player_can_see_bold(ny, nx))
3535 /* Dump a message */
3537 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£", m_name, o_name);
3539 msg_format("%^s tries to pick up %s, but fails.", m_name, o_name);
3545 /* Pick up the item */
3546 else if (r_ptr->flags2 & RF2_TAKE_ITEM)
3549 did_take_item = TRUE;
3551 /* Describe observable situations */
3552 if (player_can_see_bold(ny, nx))
3554 /* Dump a message */
3556 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3558 msg_format("%^s picks up %s.", m_name, o_name);
3563 /* Excise the object */
3564 excise_object_idx(this_o_idx);
3567 o_ptr->marked = FALSE;
3569 /* Forget location */
3570 o_ptr->iy = o_ptr->ix = 0;
3572 /* Memorize monster */
3573 o_ptr->held_m_idx = m_idx;
3576 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3579 m_ptr->hold_o_idx = this_o_idx;
3582 /* Destroy the item if not a pet */
3583 else if (!is_pet(m_ptr))
3586 did_kill_item = TRUE;
3588 /* Describe observable situations */
3589 if (player_has_los_bold(ny, nx))
3591 /* Dump a message */
3593 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3595 msg_format("%^s destroys %s.", m_name, o_name);
3600 /* Delete the object */
3601 delete_object_idx(this_o_idx);
3607 /* Stop when done */
3612 * Forward movements failed, but now recieved LOS attack!
3613 * Try to flow by smell.
3615 if (p_ptr->no_flowed && i > 2 && m_ptr->target_y)
3616 m_ptr->mflag2 &= ~MFLAG_NOFLOW;
3618 /* If we haven't done anything, try casting a spell again */
3619 if (!do_turn && !do_move && !m_ptr->monfear && !stupid_monsters && !(p_ptr->riding == m_idx) && aware)
3622 if (make_attack_spell(m_idx)) return;
3626 /* Notice changes in view */
3629 /* Update some things */
3630 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MONSTERS | PU_MON_LITE);
3633 /* Notice changes in view */
3634 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)))
3636 /* Update some things */
3637 p_ptr->update |= (PU_MON_LITE);
3640 /* Learn things from observable monster */
3643 /* Monster opened a door */
3644 if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
3646 /* Monster bashed a door */
3647 if (did_bash_door) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
3649 /* Monster tried to pick something up */
3650 if (did_take_item) r_ptr->r_flags2 |= (RF2_TAKE_ITEM);
3652 /* Monster tried to crush something */
3653 if (did_kill_item) r_ptr->r_flags2 |= (RF2_KILL_ITEM);
3655 /* Monster pushed past another monster */
3656 if (did_move_body) r_ptr->r_flags2 |= (RF2_MOVE_BODY);
3658 /* Monster passed through a wall */
3659 if (did_pass_wall) r_ptr->r_flags2 |= (RF2_PASS_WALL);
3661 /* Monster destroyed a wall */
3662 if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
3666 /* Hack -- get "bold" if out of options */
3667 if (!do_turn && !do_move && m_ptr->monfear && aware)
3669 /* No longer afraid */
3672 /* Message if seen */
3677 /* Acquire the monster name */
3678 monster_desc(m_name, m_ptr, 0);
3680 /* Dump a message */
3682 msg_format("%^s¤ÏÀ襤¤ò·è°Õ¤·¤¿¡ª", m_name);
3684 msg_format("%^s turns to fight!", m_name);
3687 chg_virtue(V_COMPASSION, -1);
3690 /* XXX XXX XXX Actually do something now (?) */
3695 * Process all the "live" monsters, once per game turn.
3697 * During each game turn, we scan through the list of all the "live" monsters,
3698 * (backwards, so we can excise any "freshly dead" monsters), energizing each
3699 * monster, and allowing fully energized monsters to move, attack, pass, etc.
3701 * Note that monsters can never move in the monster array (except when the
3702 * "compact_monsters()" function is called by "dungeon()" or "save_player()").
3704 * This function is responsible for at least half of the processor time
3705 * on a normal system with a "normal" amount of monsters and a player doing
3708 * When the player is resting, virtually 90% of the processor time is spent
3709 * in this function, and its children, "process_monster()" and "make_move()".
3711 * Most of the rest of the time is spent in "update_view()" and "lite_spot()",
3712 * especially when the player is running.
3714 * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"
3715 * monsters while they are still being "born". A monster is "fresh" only
3716 * during the turn in which it is created, and we use the "hack_m_idx" to
3717 * determine if the monster is yet to be processed during the current turn.
3719 * Note the special "MFLAG_NICE" flag, which allows the player to get one
3720 * move before any "nasty" monsters get to use their spell attacks.
3722 * Note that when the "knowledge" about the currently tracked monster
3723 * changes (flags, attacks, spells), we induce a redraw of the monster
3726 void process_monsters(void)
3733 monster_type *m_ptr;
3734 monster_race *r_ptr;
3736 int old_monster_race_idx;
3738 u32b old_r_flags1 = 0L;
3739 u32b old_r_flags2 = 0L;
3740 u32b old_r_flags3 = 0L;
3741 u32b old_r_flags4 = 0L;
3742 u32b old_r_flags5 = 0L;
3743 u32b old_r_flags6 = 0L;
3745 byte old_r_blows0 = 0;
3746 byte old_r_blows1 = 0;
3747 byte old_r_blows2 = 0;
3748 byte old_r_blows3 = 0;
3750 byte old_r_cast_inate = 0;
3751 byte old_r_cast_spell = 0;
3755 /* Clear monster fighting indicator */
3758 /* Memorize old race */
3759 old_monster_race_idx = p_ptr->monster_race_idx;
3761 /* Acquire knowledge */
3762 if (p_ptr->monster_race_idx)
3764 /* Acquire current monster */
3765 r_ptr = &r_info[p_ptr->monster_race_idx];
3767 /* Memorize flags */
3768 old_r_flags1 = r_ptr->r_flags1;
3769 old_r_flags2 = r_ptr->r_flags2;
3770 old_r_flags3 = r_ptr->r_flags3;
3771 old_r_flags4 = r_ptr->r_flags4;
3772 old_r_flags5 = r_ptr->r_flags5;
3773 old_r_flags6 = r_ptr->r_flags6;
3775 /* Memorize blows */
3776 old_r_blows0 = r_ptr->r_blows[0];
3777 old_r_blows1 = r_ptr->r_blows[1];
3778 old_r_blows2 = r_ptr->r_blows[2];
3779 old_r_blows3 = r_ptr->r_blows[3];
3781 /* Memorize castings */
3782 old_r_cast_inate = r_ptr->r_cast_inate;
3783 old_r_cast_spell = r_ptr->r_cast_spell;
3787 /* Hack -- calculate the "player noise" */
3788 noise = (1L << (30 - p_ptr->skill_stl));
3791 /* Process the monsters (backwards) */
3792 for (i = m_max - 1; i >= 1; i--)
3794 /* Access the monster */
3796 r_ptr = &r_info[m_ptr->r_idx];
3798 /* Handle "leaving" */
3799 if (p_ptr->leaving) break;
3801 /* Ignore "dead" monsters */
3802 if (!m_ptr->r_idx) continue;
3804 if (p_ptr->wild_mode) continue;
3807 /* Handle "fresh" monsters */
3808 if (m_ptr->mflag & MFLAG_BORN)
3810 /* No longer "fresh" */
3811 m_ptr->mflag &= ~(MFLAG_BORN);
3817 /* Hack -- Require proximity */
3818 if (m_ptr->cdis >= 100) continue;
3821 /* Access the location */
3825 /* Flow by smell is allowed */
3826 if (!stupid_monsters && !p_ptr->no_flowed)
3828 m_ptr->mflag2 &= ~MFLAG_NOFLOW;
3831 /* Assume no move */
3834 /* Handle "sensing radius" */
3835 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > 20 ? 20 : r_ptr->aaf) : r_ptr->aaf))
3837 /* We can "sense" the player */
3841 /* Handle "sight" and "aggravation" */
3842 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3843 (player_has_los_bold(fy, fx) || p_ptr->aggravate))
3845 /* We can "see" or "feel" the player */
3849 /* Hack -- Monsters can "smell" the player from far away */
3850 /* Note that most monsters have "aaf" of "20" or so */
3851 else if (!stupid_monsters && !(m_ptr->mflag2 & MFLAG_NOFLOW) &&
3852 (cave_floor_bold(py, px) || (cave[py][px].feat == FEAT_TREES)) &&
3853 (cave[py][px].when == cave[fy][fx].when) &&
3854 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3855 (cave[fy][fx].dist < r_ptr->aaf))
3857 /* We can "smell" the player */
3860 else if (m_ptr->target_y) test = TRUE;
3863 if (!test) continue;
3866 if (p_ptr->riding == i)
3867 speed = p_ptr->pspeed;
3870 speed = MIN(199, m_ptr->mspeed);
3872 /* Monsters move quickly in Nightmare mode */
3873 if (ironman_nightmare)
3875 speed = MIN(199, m_ptr->mspeed + 5);
3878 if (m_ptr->fast) speed = MIN(199, speed + 10);
3879 if (m_ptr->slow) speed = MAX(0, speed - 10);
3882 e = extract_energy[speed];
3884 /* Give this monster some energy */
3885 if(rand_int(60) < e)
3886 m_ptr->energy += gain_energy();
3889 /* Not enough energy to move */
3890 if (m_ptr->energy < 100) continue;
3892 /* Use up "some" energy */
3893 m_ptr->energy -= 100;
3896 /* Save global index */
3899 /* Process the monster */
3902 m_ptr->target_y = 0;
3903 m_ptr->target_x = 0;
3905 /* Give up flow_by_smell when it might useless */
3906 if (p_ptr->no_flowed && one_in_(3))
3907 m_ptr->mflag2 |= MFLAG_NOFLOW;
3909 /* Hack -- notice death or departure */
3910 if (!alive || death) break;
3912 /* Notice leaving */
3913 if (p_ptr->leaving) break;
3916 /* Reset global index */
3920 /* Tracking a monster race (the same one we were before) */
3921 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3923 /* Acquire monster race */
3924 r_ptr = &r_info[p_ptr->monster_race_idx];
3926 /* Check for knowledge change */
3927 if ((old_r_flags1 != r_ptr->r_flags1) ||
3928 (old_r_flags2 != r_ptr->r_flags2) ||
3929 (old_r_flags3 != r_ptr->r_flags3) ||
3930 (old_r_flags4 != r_ptr->r_flags4) ||
3931 (old_r_flags5 != r_ptr->r_flags5) ||
3932 (old_r_flags6 != r_ptr->r_flags6) ||
3933 (old_r_blows0 != r_ptr->r_blows[0]) ||
3934 (old_r_blows1 != r_ptr->r_blows[1]) ||
3935 (old_r_blows2 != r_ptr->r_blows[2]) ||
3936 (old_r_blows3 != r_ptr->r_blows[3]) ||
3937 (old_r_cast_inate != r_ptr->r_cast_inate) ||
3938 (old_r_cast_spell != r_ptr->r_cast_spell))
3941 p_ptr->window |= (PW_MONSTER);
3948 bool process_the_world(int num, int who, bool vs_player)
3950 if(world_monster) return (FALSE);
3955 monster_desc(m_name, &m_list[hack_m_idx], 0);
3959 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
3961 msg_format("%s yells 'The World! Time has stopped!'", m_name);
3965 msg_print("¡Ö»þ¤è¡ª¡×");
3967 msg_format("%s yells 'Time!'", m_name);
3969 else msg_print("hek!");
3974 world_monster = TRUE;
3976 if (vs_player) do_cmd_redraw();
3980 if(!m_list[hack_m_idx].r_idx) return (TRUE);
3981 process_monster(hack_m_idx);
3983 m_list[hack_m_idx].target_y = 0;
3984 m_list[hack_m_idx].target_x = 0;
3987 if (p_ptr->notice) notice_stuff();
3990 if (p_ptr->update) update_stuff();
3993 if (p_ptr->redraw) redraw_stuff();
3996 if (p_ptr->window) window_stuff();
3999 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
4003 p_ptr->redraw |= (PR_MAP);
4005 /* Update monsters */
4006 p_ptr->update |= (PU_MONSTERS);
4009 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4011 world_monster = FALSE;
4012 if (vs_player || los(py, px, m_list[hack_m_idx].fy, m_list[hack_m_idx].fx))
4015 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
4017 msg_print("You feel time flowing around you once more.");
4028 void monster_gain_exp(int m_idx, int s_idx)
4030 monster_type *m_ptr = &m_list[m_idx];
4031 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4032 monster_race *s_ptr = &r_info[s_idx];
4035 if (p_ptr->inside_battle) return;
4037 if (!r_ptr->next_exp) return;
4039 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
4040 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
4041 if (!dun_level) new_exp /= 5;
4042 m_ptr->exp += new_exp;
4043 if (m_ptr->mflag2 & MFLAG_CHAMELEON) return;
4045 if (m_ptr->exp >= r_ptr->next_exp)
4048 int old_hp = m_ptr->hp;
4049 int old_maxhp = m_ptr->max_maxhp;
4050 int old_r_idx = m_ptr->r_idx;
4053 monster_desc(m_name, m_ptr, 0);
4054 m_ptr->r_idx = r_ptr->next_r_idx;
4055 r_ptr = &r_info[m_ptr->r_idx];
4056 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
4058 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
4062 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
4064 if (ironman_nightmare)
4066 u32b hp = m_ptr->max_maxhp * 2L;
4068 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
4070 m_ptr->maxhp = m_ptr->max_maxhp;
4071 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
4073 /* Extract the monster base speed */
4074 m_ptr->mspeed = r_ptr->speed;
4076 /* Hack -- small racial variety */
4077 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
4079 /* Allow some small variation per monster */
4080 if(rand_int(4) == 1){
4081 i = extract_energy[r_ptr->speed] / 3;
4082 if (i) m_ptr->mspeed += rand_spread(0, i);
4085 i = extract_energy[r_ptr->speed] / 10;
4086 if (i) m_ptr->mspeed += rand_spread(0, i);
4090 if (m_ptr->mspeed > 199) m_ptr->mspeed = 199;
4094 if (is_pet(m_ptr) || m_ptr->ml)
4097 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
4099 msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
4101 r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
4103 update_mon(m_idx, FALSE);
4104 lite_spot(m_ptr->fy, m_ptr->fx);
4106 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;