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, when = 0, cost = 999;
531 monster_type *m_ptr = &m_list[m_idx];
532 monster_race *r_ptr = &r_info[m_ptr->r_idx];
534 /* Monster flowing disabled */
535 if (stupid_monsters) return (FALSE);
537 /* Monster can go through rocks */
538 if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) return (FALSE);
539 if (r_ptr->flags2 & RF2_KILL_WALL) return (FALSE);
540 if (!cave_floor_bold(py, px) && (cave[py][px].feat != FEAT_TREES)) return (FALSE);
542 /* Monster location */
547 c_ptr = &cave[y1][x1];
549 /* The player is not currently near the monster grid */
550 if (c_ptr->when < cave[py][px].when)
552 /* The player has never been near the monster grid */
553 if (!c_ptr->when) return (FALSE);
556 if (c_ptr->dist > MONSTER_FLOW_DEPTH) return (FALSE);
557 if ((c_ptr->dist > r_ptr->aaf) && !m_ptr->target_y) return (FALSE);
559 /* Hack -- Player can see us, run towards him */
560 if (player_has_los_bold(y1, x1)) return (FALSE);
562 /* Check nearby grids, diagonals first */
563 for (i = 7; i >= 0; i--)
567 /* Get the location */
571 /* Ignore locations off of edge */
572 if (!in_bounds2(y, x)) continue;
576 /* Ignore illegal locations */
577 if (!c_ptr->when) continue;
579 /* Ignore ancient locations */
580 if (c_ptr->when < when) continue;
582 if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
584 else value = c_ptr->cost;
586 /* Ignore distant locations */
587 if (value > cost) continue;
589 /* Save the cost and time */
593 /* Hack -- Save the "twiddled" location */
594 (*yp) = py + 16 * ddy_ddd[i];
595 (*xp) = px + 16 * ddx_ddd[i];
598 /* No legal move (?) */
599 if (!when) return (FALSE);
607 * Provide a location to flee to, but give the player a wide berth.
609 * A monster may wish to flee to a location that is behind the player,
610 * but instead of heading directly for it, the monster should "swerve"
611 * around the player so that he has a smaller chance of getting hit.
613 static bool get_fear_moves_aux(int m_idx, int *yp, int *xp)
615 int y, x, y1, x1, fy, fx, gy = 0, gx = 0;
616 int when = 0, score = -1;
619 monster_type *m_ptr = &m_list[m_idx];
620 monster_race *r_ptr = &r_info[m_ptr->r_idx];
622 /* Monster flowing disabled */
623 if (stupid_monsters) return (FALSE);
625 /* Monster location */
629 /* Desired destination */
633 /* The player is not currently near the monster grid */
634 if (cave[fy][fx].when < cave[py][px].when)
636 /* No reason to attempt flowing */
640 /* Monster is too far away to use flow information */
641 if (cave[fy][fx].dist > MONSTER_FLOW_DEPTH) return (FALSE);
642 if ((cave[fy][fx].dist > r_ptr->aaf) && !m_ptr->target_y) return (FALSE);
644 /* Check nearby grids, diagonals first */
645 for (i = 7; i >= 0; i--)
649 /* Get the location */
653 /* Ignore locations off of edge */
654 if (!in_bounds2(y, x)) continue;
656 /* Ignore illegal locations */
657 if (cave[y][x].when == 0) continue;
659 /* Ignore ancient locations */
660 if (cave[y][x].when < when) continue;
662 /* Calculate distance of this grid from our destination */
663 dis = distance(y, x, y1, x1);
665 /* Score this grid */
666 s = 5000 / (dis + 3) - 500 / (cave[y][x].dist + 1);
668 /* No negative scores */
671 /* Ignore lower scores */
672 if (s < score) continue;
674 /* Save the score and time */
675 when = cave[y][x].when;
678 /* Save the location */
683 /* No legal move (?) */
684 if (!when) return (FALSE);
695 * Hack -- Precompute a bunch of calls to distance() in find_safety() and
698 * The pair of arrays dist_offsets_y[n] and dist_offsets_x[n] contain the
699 * offsets of all the locations with a distance of n from a central point,
700 * with an offset of (0,0) indicating no more offsets at this distance.
702 * This is, of course, fairly unreadable, but it eliminates multiple loops
703 * from the previous version.
705 * It is probably better to replace these arrays with code to compute
706 * the relevant arrays, even if the storage is pre-allocated in hard
707 * coded sizes. At the very least, code should be included which is
708 * able to generate and dump these arrays (ala "los()"). XXX XXX XXX
710 * Also, the storage needs could be halved by using bytes. XXX XXX XXX
712 * These arrays could be combined into two big arrays, using sub-arrays
713 * to hold the offsets and lengths of each portion of the sub-arrays, and
714 * this could perhaps also be used somehow in the "look" code. XXX XXX XXX
718 static sint d_off_y_0[] =
721 static sint d_off_x_0[] =
725 static sint d_off_y_1[] =
726 { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
728 static sint d_off_x_1[] =
729 { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
732 static sint d_off_y_2[] =
733 { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
735 static sint d_off_x_2[] =
736 { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
739 static sint d_off_y_3[] =
740 { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
743 static sint d_off_x_3[] =
744 { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
748 static sint d_off_y_4[] =
749 { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
750 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
752 static sint d_off_x_4[] =
753 { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
754 -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
757 static sint d_off_y_5[] =
758 { -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
759 -5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
762 static sint d_off_x_5[] =
763 { -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
764 -5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
768 static sint d_off_y_6[] =
769 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
770 -6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
773 static sint d_off_x_6[] =
774 { -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
775 0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
776 -3, 2, 3, -1, 0, 1, 0 };
779 static sint d_off_y_7[] =
780 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
781 -6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
782 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 };
784 static sint d_off_x_7[] =
785 { -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
786 -3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
787 6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
791 static sint d_off_y_8[] =
792 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
793 -6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
794 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
797 static sint d_off_x_8[] =
798 { -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
799 5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
800 7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
804 static sint d_off_y_9[] =
805 { -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
806 -7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
807 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
808 7, 8, 8, 8, 8, 9, 9, 9, 0 };
810 static sint d_off_x_9[] =
811 { -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
812 -5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
813 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
814 4, 5, -2, -3, 2, 3, -1, 0, 1, 0 };
817 static sint *dist_offsets_y[10] =
819 d_off_y_0, d_off_y_1, d_off_y_2, d_off_y_3, d_off_y_4,
820 d_off_y_5, d_off_y_6, d_off_y_7, d_off_y_8, d_off_y_9
823 static sint *dist_offsets_x[10] =
825 d_off_x_0, d_off_x_1, d_off_x_2, d_off_x_3, d_off_x_4,
826 d_off_x_5, d_off_x_6, d_off_x_7, d_off_x_8, d_off_x_9
830 * Choose a "safe" location near a monster for it to run toward.
832 * A location is "safe" if it can be reached quickly and the player
833 * is not able to fire into it (it isn't a "clean shot"). So, this will
834 * cause monsters to "duck" behind walls. Hopefully, monsters will also
835 * try to run towards corridor openings if they are in a room.
837 * This function may take lots of CPU time if lots of monsters are
840 * Return TRUE if a safe location is available.
842 static bool find_safety(int m_idx, int *yp, int *xp)
844 monster_type *m_ptr = &m_list[m_idx];
849 int y, x, dy, dx, d, dis, i;
850 int gy = 0, gx = 0, gdis = 0;
857 /* Start with adjacent locations, spread further */
858 for (d = 1; d < 10; d++)
860 /* Get the lists of points with a distance d from (fx, fy) */
861 y_offsets = dist_offsets_y[d];
862 x_offsets = dist_offsets_x[d];
864 /* Check the locations */
865 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
867 i++, dx = x_offsets[i], dy = y_offsets[i])
872 /* Skip illegal locations */
873 if (!in_bounds(y, x)) continue;
877 /* Skip locations in a wall */
878 if (!cave_floor_grid(c_ptr)) continue;
880 /* Check for "availability" (if monsters can flow) */
881 if (!stupid_monsters && !p_ptr->no_flowed)
883 /* Ignore grids very far from the player */
884 if (c_ptr->when < cave[py][px].when) continue;
886 /* Ignore too-distant grids */
887 if (c_ptr->dist > cave[fy][fx].dist + 2 * d) continue;
890 /* Check for absence of shot (more or less) */
891 if (clean_shot(fy, fx, y, x, FALSE))
894 /* Calculate distance from player */
895 dis = distance(y, x, py, px);
897 /* Remember if further than previous */
902 if (!player_has_los_grid(c_ptr))
914 /* Check for success */
915 if (gdis > d + m_ptr->cdis)
921 /* Found safe place */
928 /* Save farthest location from player in LOS of monster */
932 /* Hack - return TRUE anyway. */
938 * Choose a good hiding place near a monster for it to run toward.
940 * Pack monsters will use this to "ambush" the player and lure him out
941 * of corridors into open space so they can swarm him.
943 * Return TRUE if a good location is available.
945 static bool find_hiding(int m_idx, int *yp, int *xp)
947 monster_type *m_ptr = &m_list[m_idx];
952 int y, x, dy, dx, d, dis, i;
953 int gy = 0, gx = 0, gdis = 999;
955 sint *y_offsets, *x_offsets;
959 /* Start with adjacent locations, spread further */
960 for (d = 1; d < 10; d++)
962 /* Get the lists of points with a distance d from (fx, fy) */
963 y_offsets = dist_offsets_y[d];
964 x_offsets = dist_offsets_x[d];
966 /* Check the locations */
967 for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
969 i++, dx = x_offsets[i], dy = y_offsets[i])
974 /* Skip illegal locations */
975 if (!in_bounds(y, x)) continue;
979 /* Skip occupied locations */
980 if (!cave_empty_grid(c_ptr)) continue;
982 /* Check for hidden, available grid */
983 if (!player_has_los_grid(c_ptr) && clean_shot(fy, fx, y, x, FALSE))
985 /* Calculate distance from player */
986 dis = distance(y, x, py, px);
988 /* Remember if closer than previous */
989 if (dis < gdis && dis >= 2)
998 /* Check for success */
1005 /* Found good place */
1016 * Choose "logical" directions for monster movement
1018 static bool get_moves(int m_idx, int *mm)
1020 monster_type *m_ptr = &m_list[m_idx];
1021 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1027 bool will_run = mon_will_run(m_idx);
1029 bool no_flow = (p_ptr->no_flowed && (cave[m_ptr->fy][m_ptr->fx].cost > 2));
1032 /* Flow towards the player */
1033 if (!stupid_monsters && !no_flow)
1035 /* Flow towards the player */
1036 (void)get_moves_aux(m_idx, &y2, &x2);
1039 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
1041 /* Extract the "pseudo-direction" */
1045 if (!stupid_monsters && !will_run && is_hostile(m_ptr) &&
1046 (r_ptr->flags1 & RF1_FRIENDS) &&
1047 (los(m_ptr->fy, m_ptr->fx, py, px) ||
1048 (cave[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
1051 * Animal packs try to get the player out of corridors
1052 * (...unless they can move through walls -- TY)
1054 if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
1055 !(r_ptr->flags2 & RF2_KILL_WALL))
1059 /* Count room grids next to player */
1060 for (i = 0; i < 8; i++)
1062 int x = px + ddx_ddd[i];
1063 int y = py + ddy_ddd[i];
1067 if (!in_bounds2(y, x)) continue;
1069 c_ptr = &cave[y][x];
1072 if (((cave_floor_grid(c_ptr)) || ((c_ptr->feat & 0x60) == 0x60)) &&
1073 monster_can_cross_terrain(c_ptr->feat, r_ptr))
1075 /* One more room grid */
1079 if (cave[py][px].info & CAVE_ROOM) room -= 2;
1080 if (!r_ptr->flags4 && !r_ptr->flags5 && !r_ptr->flags6) room -= 2;
1082 /* Not in a room and strong player */
1083 if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
1084 (p_ptr->mhp + p_ptr->msp))
1086 /* Find hiding place */
1087 if (find_hiding(m_idx, &y, &x)) done = TRUE;
1091 /* Monster groups try to surround the player */
1092 if (!done && (cave[m_ptr->fy][m_ptr->fx].dist < 3))
1096 /* Find an empty square near the player to fill */
1097 for (i = 0; i < 8; i++)
1099 /* Pick squares near player (semi-randomly) */
1100 y2 = py + ddy_ddd[(m_idx + i) & 7];
1101 x2 = px + ddx_ddd[(m_idx + i) & 7];
1103 /* Already there? */
1104 if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
1106 /* Attack the player */
1113 if (!in_bounds2(y2, x2)) continue;
1115 /* Ignore filled grids */
1116 c_ptr = &cave[y2][x2];
1117 if (!cave_empty_grid(c_ptr)) continue;
1119 /* Try to fill this hole */
1123 /* Extract the new "pseudo-direction" */
1132 /* Apply fear if possible and necessary */
1133 if ((stupid_monsters || is_pet(m_ptr)) && will_run)
1135 /* XXX XXX Not very "smart" */
1140 if (!done && will_run)
1142 /* Try to find safe place */
1143 if (!find_safety(m_idx, &y, &x))
1145 /* This is not a very "smart" method XXX XXX */
1151 /* Attempt to avoid the player */
1152 if (!stupid_monsters && !no_flow)
1154 /* Adjust movement */
1155 (void)get_fear_moves_aux(m_idx, &y, &x);
1162 if (!stupid_monsters)
1164 /* Check for no move */
1165 if (!x && !y) return (FALSE);
1169 /* Extract the "absolute distances" */
1173 /* Do something weird */
1174 if (y < 0) move_val += 8;
1175 if (x > 0) move_val += 4;
1177 /* Prevent the diamond maneuvre */
1183 else if (ax > (ay << 1))
1188 /* Extract some directions */
1333 /* Wants to move... */
1338 static int check_hit2(int power, int level, int ac, int stun)
1342 /* Percentile dice */
1345 if (stun && one_in_(2)) return FALSE;
1347 /* Hack -- Always miss or hit */
1348 if (k < 10) return (k < 5);
1350 /* Calculate the "attack quality" */
1351 i = (power + (level * 3));
1353 /* Power and Level compete against Armor */
1354 if ((i > 0) && (randint(i) > ((ac * 3) / 4))) return (TRUE);
1361 /* Monster attacks monster */
1362 static bool monst_attack_monst(int m_idx, int t_idx)
1364 monster_type *m_ptr = &m_list[m_idx];
1365 monster_type *t_ptr = &m_list[t_idx];
1367 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1368 monster_race *tr_ptr = &r_info[t_ptr->r_idx];
1372 char m_name[80], t_name[80];
1373 char ddesc[80], temp[80];
1374 bool blinked, heal_effect;
1375 bool explode = FALSE, touched = FALSE, fear = FALSE;
1376 int y_saver = t_ptr->fy;
1377 int x_saver = t_ptr->fx;
1379 bool see_m = m_ptr->ml;
1380 bool see_t = t_ptr->ml;
1381 bool see_either = see_m || see_t;
1383 /* Can the player be aware of this attack? */
1384 bool known = (m_ptr->cdis <= MAX_SIGHT) || (t_ptr->cdis <= MAX_SIGHT);
1385 bool do_silly_attack = (one_in_(2) && p_ptr->image);
1387 /* Cannot attack self */
1388 if (m_idx == t_idx) return FALSE;
1390 /* Not allowed to attack */
1391 if (r_ptr->flags1 & RF1_NEVER_BLOW) return FALSE;
1393 if (d_info[dungeon_type].flags1 & DF1_NO_MELEE) return (FALSE);
1401 /* Extract the effective monster level */
1402 rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
1404 /* Get the monster name (or "it") */
1405 monster_desc(m_name, m_ptr, 0);
1407 /* Get the monster name (or "it") */
1408 monster_desc(t_name, t_ptr, 0);
1410 /* Get the "died from" information (i.e. "a kobold") */
1411 monster_desc(ddesc, m_ptr, 0x88);
1413 /* Assume no blink */
1416 if (!see_either && known)
1421 if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
1423 /* Scan through all four blows */
1424 for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
1426 bool obvious = FALSE;
1433 /* Extract the attack infomation */
1434 int effect = r_ptr->blow[ap_cnt].effect;
1435 int method = r_ptr->blow[ap_cnt].method;
1436 int d_dice = r_ptr->blow[ap_cnt].d_dice;
1437 int d_side = r_ptr->blow[ap_cnt].d_side;
1439 if (!m_ptr->r_idx) break;
1441 /* Stop attacking if the target dies! */
1442 if (t_ptr->fx != x_saver || t_ptr->fy != y_saver)
1445 /* Hack -- no more attacks */
1448 if (blinked) /* Stop! */
1453 /* Extract the attack "power" */
1456 case RBE_HURT: power = 60; break;
1457 case RBE_POISON: power = 5; break;
1458 case RBE_UN_BONUS: power = 20; break;
1459 case RBE_UN_POWER: power = 15; break;
1460 case RBE_EAT_GOLD: power = 5; break;
1461 case RBE_EAT_ITEM: power = 5; break;
1462 case RBE_EAT_FOOD: power = 5; break;
1463 case RBE_EAT_LITE: power = 5; break;
1464 case RBE_ACID: power = 0; break;
1465 case RBE_ELEC: power = 10; break;
1466 case RBE_FIRE: power = 10; break;
1467 case RBE_COLD: power = 10; break;
1468 case RBE_BLIND: power = 2; break;
1469 case RBE_CONFUSE: power = 10; break;
1470 case RBE_TERRIFY: power = 10; break;
1471 case RBE_PARALYZE: power = 2; break;
1472 case RBE_LOSE_STR: power = 0; break;
1473 case RBE_LOSE_DEX: power = 0; break;
1474 case RBE_LOSE_CON: power = 0; break;
1475 case RBE_LOSE_INT: power = 0; break;
1476 case RBE_LOSE_WIS: power = 0; break;
1477 case RBE_LOSE_CHR: power = 0; break;
1478 case RBE_LOSE_ALL: power = 2; break;
1479 case RBE_SHATTER: power = 60; break;
1480 case RBE_EXP_10: power = 5; break;
1481 case RBE_EXP_20: power = 5; break;
1482 case RBE_EXP_40: power = 5; break;
1483 case RBE_EXP_80: power = 5; break;
1484 case RBE_DISEASE: power = 5; break;
1485 case RBE_TIME: power = 5; break;
1486 case RBE_EXP_VAMP: power = 5; break;
1487 case RBE_DR_MANA: power = 5; break;
1488 case RBE_SUPERHURT: power = 60; break;
1493 if (!effect || check_hit2(power, rlev, ac, m_ptr->stunned))
1495 /* Describe the attack method */
1501 act = "%s¤ò²¥¤Ã¤¿¡£";
1513 act = "%s¤ò¿¨¤Ã¤¿¡£";
1515 act = "touches %s.";
1525 act = "%s¤ò¥Ñ¥ó¥Á¤·¤¿¡£";
1527 act = "punches %s.";
1537 act = "%s¤ò½³¤Ã¤¿¡£";
1549 act = "%s¤ò¤Ò¤Ã¤«¤¤¤¿¡£";
1561 act = "%s¤ò³ú¤ó¤À¡£";
1573 act = "%s¤ò»É¤·¤¿¡£";
1585 act = "%s¤ò»Â¤Ã¤¿¡£";
1587 act = "slashes %s.";
1596 act = "%s¤ò³Ñ¤ÇÆͤ¤¤¿¡£";
1608 act = "%s¤ËÂÎÅö¤ê¤·¤¿¡£";
1610 act = "crushes %s.";
1620 act = "%s¤ò°û¤ß¹þ¤ó¤À¡£";
1622 act = "engulfs %s.";
1632 act = "%s¤ËÀÁµá½ñ¤ò¤è¤³¤·¤¿¡£";
1634 act = "charges %s.";
1644 act = "%s¤ÎÂΤξå¤òÇ礤²ó¤Ã¤¿¡£";
1646 act = "crawls on %s.";
1656 act = "%s¤Ë¤è¤À¤ì¤ò¤¿¤é¤·¤¿¡£";
1658 act = "drools on %s.";
1668 act = "%s¤ËÂäòÅǤ¤¤¿¡£";
1670 act = "spits on %s.";
1679 if (see_either) disturb(1, 0);
1694 act = "%s¤ò¤Ë¤é¤ó¤À¡£";
1696 act = "gazes at %s.";
1706 act = "%s¤Ëµã¤¤Ä¤¤¤¿¡£";
1708 act = "wails at %s.";
1718 act = "%s¤Ë˦»Ò¤òÈô¤Ð¤·¤¿¡£";
1720 act = "releases spores at %s.";
1730 act = "%s¤ËXXX4¤òÈô¤Ð¤·¤¿¡£";
1732 act = "projects XXX4's at %s.";
1742 act = "%s¤Ë¶â¤ò¤»¤¬¤ó¤À¡£";
1744 act = "begs %s for money.";
1754 act = "%s¤òÉî¿«¤·¤¿¡£";
1756 act = "insults %s.";
1766 act = "%s¤Ë¤à¤«¤Ã¤Æ¤¦¤á¤¤¤¿¡£";
1768 act = "moans at %s.";
1778 act = "%s¤Ë¤à¤«¤Ã¤Æ²Î¤Ã¤¿¡£";
1780 act = "sings to %s.";
1789 if (act && see_either)
1791 if (do_silly_attack)
1793 act = silly_attacks[rand_int(MAX_SILLY_ATTACK)];
1795 strfmt(temp, act, t_name);
1797 msg_format("%^s¤Ï%s", m_name, temp);
1799 msg_format("%^s %s", m_name, temp);
1804 /* Hack -- assume all attacks are obvious */
1807 /* Roll out the damage */
1808 damage = damroll(d_dice, d_side);
1810 /* Assume no healing effect */
1811 heal_effect = FALSE;
1815 /* Apply appropriate damage */
1827 if ((randint(rlev*2+250) > (ac+200)) || one_in_(13)) {
1828 int tmp_damage = damage-(damage*((ac < 150) ? ac : 150)/250);
1829 damage = MAX(damage, tmp_damage*2);
1835 damage -= (damage * ((ac < 150) ? ac : 150) / 250);
1865 if (randint(2) == 1) blinked = TRUE;
1912 pt = GF_OLD_SLEEP; /* sort of close... */
1930 earthquake(m_ptr->fy, m_ptr->fx, 8);
1963 /* Do damage if not exploding */
1966 project(m_idx, 0, t_ptr->fy, t_ptr->fx,
1967 (pt == GF_OLD_SLEEP ? r_ptr->level : damage), pt, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
1972 if ((monster_living(tr_ptr)) && (damage > 2))
1974 bool did_heal = FALSE;
1976 if (m_ptr->hp < m_ptr->maxhp) did_heal = TRUE;
1979 m_ptr->hp += damroll(4, damage / 6);
1980 if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
1982 /* Redraw (later) if needed */
1983 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
1984 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
1986 /* Special message */
1987 if (see_m && did_heal)
1990 msg_format("%s¤ÏÂÎÎϤò²óÉü¤·¤¿¤è¤¦¤À¡£", m_name);
1992 msg_format("%^s appears healthier.", m_name);
2002 if ((tr_ptr->flags2 & RF2_AURA_FIRE) &&
2003 !(r_ptr->flags3 & RF3_IM_FIRE) &&
2004 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2010 msg_format("%^s¤ÏÆÍÁ³Ç®¤¯¤Ê¤Ã¤¿¡ª", m_name);
2012 msg_format("%^s is suddenly very hot!", m_name);
2016 tr_ptr->r_flags2 |= RF2_AURA_FIRE;
2018 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2019 damroll (1 + ((tr_ptr->level) / 26),
2020 1 + ((tr_ptr->level) / 17)),
2021 GF_FIRE, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2025 if ((tr_ptr->flags3 & RF3_AURA_COLD) &&
2026 !(r_ptr->flags3 & RF3_IM_COLD) &&
2027 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2033 msg_format("%^s¤ÏÆÍÁ³´¨¤¯¤Ê¤Ã¤¿¡ª", m_name);
2035 msg_format("%^s is suddenly very cold!", m_name);
2039 tr_ptr->r_flags3 |= RF3_AURA_COLD;
2041 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2042 damroll (1 + ((tr_ptr->level) / 26),
2043 1 + ((tr_ptr->level) / 17)),
2044 GF_COLD, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2048 if ((tr_ptr->flags2 & (RF2_AURA_ELEC)) &&
2049 !(r_ptr->flags3 & (RF3_IM_ELEC)) &&
2050 !(r_ptr->flags3 & RF3_RES_ALL) && m_ptr->r_idx)
2056 msg_format("%^s¤ÏÅÅ·â¤ò¿©¤é¤Ã¤¿¡ª", m_name);
2058 msg_format("%^s gets zapped!", m_name);
2062 tr_ptr->r_flags2 |= RF2_AURA_ELEC;
2064 project(t_idx, 0, m_ptr->fy, m_ptr->fx,
2065 damroll (1 + ((tr_ptr->level) / 26),
2066 1 + ((tr_ptr->level) / 17)),
2067 GF_ELEC, PROJECT_KILL | PROJECT_STOP | PROJECT_MONSTER | PROJECT_NO_REF, -1);
2074 /* Monster missed player */
2077 /* Analyze failed attacks */
2093 /* Visible monsters */
2098 msg_format("%s¤Ï%^s¤Î¹¶·â¤ò¤«¤ï¤·¤¿¡£", t_name,m_name);
2100 msg_format("%^s misses %s.", m_name, t_name);
2111 /* Analyze "visible" monsters only */
2112 if (see_m && !do_silly_attack)
2114 /* Count "obvious" attacks (and ones that cause damage) */
2115 if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10))
2117 /* Count attacks of this type */
2118 if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR)
2120 r_ptr->r_blows[ap_cnt]++;
2128 sound(SOUND_EXPLODE);
2130 /* Cancel Invulnerability */
2131 if (m_ptr->invulner) m_ptr->invulner = 0;
2134 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2136 mon_take_hit_mon(FALSE, m_idx, m_ptr->hp + 1, &fear, " explodes into tiny shreds.", m_idx);
2150 msg_print("Å¥ËÀ¤Ï¾Ð¤Ã¤Æƨ¤²¤¿¡ª");
2152 msg_print("The thief flees laughing!");
2161 teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE);
2169 * Hack -- local "player stealth" value (see below)
2171 static u32b noise = 0L;
2177 * The monster is known to be within 100 grids of the player
2179 * In several cases, we directly update the monster lore
2181 * Note that a monster is only allowed to "reproduce" if there
2182 * are a limited number of "reproducing" monsters on the current
2183 * level. This should prevent the level from being "swamped" by
2184 * reproducing monsters. It also allows a large mass of mice to
2185 * prevent a louse from multiplying, but this is a small price to
2186 * pay for a simple multiplication method.
2188 * XXX Monster fear is slightly odd, in particular, monsters will
2189 * fixate on opening a door even if they cannot open it. Actually,
2190 * the same thing happens to normal monsters when they hit a door
2192 * XXX XXX XXX In addition, monsters which *cannot* open or bash
2193 * down a door will still stand there trying to open it...
2195 * XXX Technically, need to check for monster in the way
2196 * combined with that monster being in a wall (or door?)
2198 * A "direction" of "5" means "pick a random direction".
2200 static void process_monster(int m_idx)
2202 monster_type *m_ptr = &m_list[m_idx];
2203 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2205 int i, d, oy, ox, ny, nx;
2211 monster_type *y_ptr;
2224 bool gets_angry = FALSE;
2230 if ((m_idx == p_ptr->riding) && !(r_ptr->flags7 & RF7_RIDING))
2232 if (rakuba(0, TRUE))
2235 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2238 monster_desc(m_name, &m_list[p_ptr->riding], 0);
2239 msg_format("You have fallen from %s.", m_name);
2244 if ((m_ptr->mflag2 & MFLAG_CHAMELEON) && one_in_(13) && !m_ptr->csleep)
2246 choose_new_monster(m_idx, FALSE, 0);
2247 r_ptr = &r_info[m_ptr->r_idx];
2250 /* Players hidden in shadow are almost imperceptable. -LM- */
2251 if (p_ptr->special_defense & NINJA_S_STEALTH)
2253 int tmp = p_ptr->lev*8+50;
2254 if (p_ptr->monlite) tmp /= 3;
2255 if (p_ptr->aggravate) tmp /= 2;
2256 if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
2257 /* Low-level monsters will find it difficult to locate the player. */
2258 if (rand_int(tmp) > (r_ptr->level+20)) aware = FALSE;
2261 /* Quantum monsters are odd */
2262 if (r_ptr->flags2 & (RF2_QUANTUM))
2264 /* Sometimes skip move */
2265 if (!rand_int(2)) return;
2268 if (!rand_int((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
2272 if (is_pet(m_ptr) && !(m_ptr->ml))
2279 /* Acquire the monster name */
2280 monster_desc(m_name, m_ptr, 0);
2284 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
2286 msg_format("%^s disappears!", m_name);
2291 /* Generate treasure, etc */
2292 monster_death(m_idx, FALSE);
2294 /* Delete the monster */
2295 delete_monster_idx(m_idx);
2300 msg_print("¾¯¤·¤Î´ÖÈᤷ¤¤µ¤Ê¬¤Ë¤Ê¤Ã¤¿¡£");
2302 msg_print("You feel sad for a moment.");
2311 if (m_ptr->r_idx == MON_SHURYUUDAN)
2313 mon_take_hit_mon(FALSE, m_idx, 1, &fear, "¤ÏÇúȯ¤·¤ÆÊ´¡¹¤Ë¤Ê¤Ã¤¿¡£", m_idx);
2315 mon_take_hit_mon(FALSE, m_idx, 1, &fear, " explodes into tiny shreds.", m_idx);
2318 if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) && !p_ptr->inside_battle)
2320 static int riding_pinch = 0;
2322 if (m_ptr->hp < m_ptr->maxhp/3)
2324 bool level_teleport = TRUE;
2326 monster_desc(m_name, m_ptr, 0);
2328 if (m_idx == p_ptr->riding && riding_pinch < 2)
2331 msg_format("%s¤Ï½ý¤ÎÄˤµ¤Î;¤ê¤¢¤Ê¤¿¤Î«Çû¤«¤éƨ¤ì¤è¤¦¤È¤·¤Æ¤¤¤ë¡£", m_name);
2333 msg_format("%^s seems to be in so much pain, and trying to escape from your restriction.", m_name);
2336 level_teleport = FALSE;
2341 if (m_idx == p_ptr->riding)
2344 msg_format("%s¤Ï¤¢¤Ê¤¿¤Î«Çû¤«¤éæ½Ð¤·¤¿¡£", m_name);
2346 msg_format("%^s succeeded to escape from your restriction!", m_name);
2349 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))
2352 msg_format("%^s¡Ö¥Ô¥ó¥Á¤À¡ªÂàµÑ¤µ¤»¤Æ¤â¤é¤¦¡ª¡×", m_name);
2354 msg_format("%^s says 'It is the pinch! I will retreat'.", m_name);
2358 msg_format("%^s¤¬¥Æ¥ì¥Ý¡¼¥È¡¦¥ì¥Ù¥ë¤Î´¬Êª¤òÆɤó¤À¡£", m_name);
2360 msg_format("%^s read a scroll of teleport level.", m_name);
2363 msg_format("%^s¤¬¾Ã¤¨µî¤Ã¤¿¡£", m_name);
2365 msg_format("%^s disappears.", m_name);
2371 delete_monster_idx(m_idx);
2373 if (m_idx == p_ptr->riding)
2375 if (rakuba(-1, FALSE))
2378 msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2380 msg_print("You have fallen from riding pet.");
2388 if (m_idx == p_ptr->riding) riding_pinch = 0;
2392 /* Handle "sleep" */
2397 /* Hack -- handle non-aggravation */
2398 if (!p_ptr->aggravate) notice = rand_int(1024);
2400 /* Nightmare monsters are more alert */
2401 if (ironman_nightmare) notice /= 2;
2403 /* Hack -- See if monster "notices" player */
2404 if ((notice * notice * notice) <= noise)
2406 /* Hack -- amount of "waking" */
2409 /* Wake up faster near the player */
2410 if (m_ptr->cdis < 50) d = (100 / m_ptr->cdis);
2412 /* Hack -- handle aggravation */
2413 if (p_ptr->aggravate) d = m_ptr->csleep;
2416 if (m_ptr->csleep > d)
2418 /* Monster wakes up "a little bit" */
2421 /* Notice the "not waking up" */
2424 /* Hack -- Count the ignores */
2425 if (r_ptr->r_ignore < MAX_UCHAR)
2435 /* Reset sleep counter */
2438 /* Notice the "waking up" */
2443 /* Acquire the monster name */
2444 monster_desc(m_name, m_ptr, 0);
2446 /* Dump a message */
2448 msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
2450 msg_format("%^s wakes up.", m_name);
2454 /* Redraw the health bar */
2455 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2456 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2458 if (r_ptr->flags7 & (RF7_HAS_LITE_1 | RF7_HAS_LITE_2))
2459 p_ptr->update |= (PU_MON_LITE);
2461 /* Hack -- Count the wakings */
2462 if (r_ptr->r_wake < MAX_UCHAR)
2470 /* Still sleeping */
2471 if (m_ptr->csleep) return;
2480 /* Make a "saving throw" against stun */
2481 if (rand_int(10000) <= r_ptr->level * r_ptr->level)
2487 /* Hack -- Recover from stun */
2488 if (m_ptr->stunned > d)
2490 /* Recover somewhat */
2491 m_ptr->stunned -= d;
2500 /* Message if visible */
2505 /* Acquire the monster name */
2506 monster_desc(m_name, m_ptr, 0);
2508 /* Dump a message */
2510 msg_format("%^s¤ÏÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2512 msg_format("%^s is no longer stunned.", m_name);
2515 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2516 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2521 if (m_ptr->stunned && one_in_(2)) return;
2525 /* Handle confusion */
2526 if (m_ptr->confused)
2528 /* Amount of "boldness" */
2529 int d = randint(r_ptr->level / 20 + 1);
2531 /* Still confused */
2532 if (m_ptr->confused > d)
2534 /* Reduce the confusion */
2535 m_ptr->confused -= d;
2541 /* No longer confused */
2542 m_ptr->confused = 0;
2544 /* Message if visible */
2549 /* Acquire the monster name */
2550 monster_desc(m_name, m_ptr, 0);
2552 /* Dump a message */
2554 msg_format("%^s¤Ïº®Í𤫤éΩ¤Áľ¤Ã¤¿¡£", m_name);
2556 msg_format("%^s is no longer confused.", m_name);
2559 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2560 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2565 /* Handle Invulnerability */
2566 if (m_ptr->invulner)
2568 /* Reduce by one, note if expires */
2571 if (!(m_ptr->invulner) && m_ptr->ml)
2575 /* Acquire the monster name */
2576 monster_desc(m_name, m_ptr, 0);
2578 /* Dump a message */
2580 msg_format("%^s¤Ï¤â¤¦ÌµÅ¨¤Ç¤Ê¤¤¡£", m_name);
2582 msg_format("%^s is no longer invulnerable.", m_name);
2585 m_ptr->energy -= 100;
2586 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2587 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2594 /* Reduce by one, note if expires */
2597 if (!(m_ptr->fast) && m_ptr->ml)
2601 /* Acquire the monster name */
2602 monster_desc(m_name, m_ptr, 0);
2604 /* Dump a message */
2606 msg_format("%^s¤Ï¤â¤¦²Ã®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2608 msg_format("%^s is no longer fast.", m_name);
2611 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2612 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2619 /* Reduce by one, note if expires */
2622 if (!(m_ptr->slow) && m_ptr->ml)
2626 /* Acquire the monster name */
2627 monster_desc(m_name, m_ptr, 0);
2629 /* Dump a message */
2631 msg_format("%^s¤Ï¤â¤¦¸ºÂ®¤µ¤ì¤Æ¤¤¤Ê¤¤¡£", m_name);
2633 msg_format("%^s is no longer slow.", m_name);
2636 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2637 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2641 if (p_ptr->riding == m_idx)
2643 p_ptr->update |= (PU_BONUS);
2646 /* No one wants to be your friend if you're aggravating */
2647 if (is_friendly(m_ptr) && p_ptr->aggravate)
2650 /* Paranoia... no pet uniques outside wizard mode -- TY */
2651 if (is_pet(m_ptr) &&
2652 ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
2653 ((p_ptr->align > 9 && (r_ptr->flags3 & RF3_EVIL)) ||
2654 (p_ptr->align < -9 && (r_ptr->flags3 & RF3_GOOD))))
2655 || (r_ptr->flags3 & RF3_RES_ALL)))
2660 if (p_ptr->inside_battle) gets_angry = FALSE;
2665 monster_desc(m_name, m_ptr, 0);
2667 msg_format("%^s¤ÏÆÍÁ³Å¨¤Ë¤Þ¤ï¤Ã¤¿¡ª", m_name);
2669 msg_format("%^s suddenly becomes hostile!", m_name);
2678 /* Amount of "boldness" */
2679 int d = randint(r_ptr->level / 20 + 1);
2682 if (m_ptr->monfear > d)
2684 /* Reduce the fear */
2685 m_ptr->monfear -= d;
2688 /* Recover from fear, take note if seen */
2691 /* No longer afraid */
2700 /* Acquire the monster name/poss */
2701 monster_desc(m_name, m_ptr, 0);
2702 monster_desc(m_poss, m_ptr, 0x22);
2704 /* Dump a message */
2706 msg_format("%^s¤Ïͦµ¤¤ò¼è¤êÌᤷ¤¿¡£", m_name);
2708 msg_format("%^s recovers %s courage.", m_name, m_poss);
2711 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2716 /* Get the origin */
2721 /* Attempt to "multiply" if able and allowed */
2722 if ((r_ptr->flags2 & RF2_MULTIPLY) && (num_repro < MAX_REPRO))
2726 /* Count the adjacent monsters */
2727 for (k = 0, y = oy - 1; y <= oy + 1; y++)
2729 for (x = ox - 1; x <= ox + 1; x++)
2731 /* Ignore locations off of edge */
2732 if (!in_bounds2(y, x)) continue;
2734 if (cave[y][x].m_idx) k++;
2738 /* Hack -- multiply slower in crowded areas */
2739 if ((k < 4) && (!k || !rand_int(k * MON_MULT_ADJ)))
2741 /* Try to multiply */
2742 if (multiply_monster(m_idx, FALSE, is_friendly(m_ptr), is_pet(m_ptr)))
2744 /* Take note if visible */
2747 r_ptr->r_flags2 |= (RF2_MULTIPLY);
2750 /* Multiplying takes energy */
2757 if (!p_ptr->inside_battle)
2759 /* Hack! "Cyber" monster makes noise... */
2760 if (m_ptr->r_idx == MON_CYBER &&
2761 (randint(CYBERNOISE) == 1) &&
2762 !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
2764 if (disturb_minor) disturb(FALSE, FALSE);
2766 msg_print("½Å¸ü¤Ê²»¤¬Ê¹¤³¤¨¤¿¡£");
2768 msg_print("You hear heavy steps.");
2773 /* Some monsters can speak */
2774 if ((r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
2775 (randint(SPEAK_CHANCE) == 1) &&
2776 player_has_los_bold(oy, ox))
2779 char monmessage[1024];
2782 /* Acquire the monster name/poss */
2784 monster_desc(m_name, m_ptr, 0);
2787 strcpy(m_name, "¤½¤ì");
2789 strcpy(m_name, "It");
2793 /* Select the file for monster quotes */
2796 filename = "monfear_j.txt";
2798 filename = "monfear.txt";
2801 else if (is_pet(m_ptr))
2803 filename = "monpet_j.txt";
2805 filename = "monpet.txt";
2808 else if (is_friendly(m_ptr))
2810 filename = "monfrien_j.txt";
2812 filename = "monfrien.txt";
2817 filename = "monspeak_j.txt";
2819 filename = "monspeak.txt";
2823 /* Get the monster line */
2824 if (get_rnd_line(filename, m_ptr->r_idx, monmessage) == 0)
2828 msg_format("%^s%s", m_name, monmessage);
2830 msg_format("%^s %s", m_name, monmessage);
2837 /* Attempt to cast a spell */
2838 if (aware && make_attack_spell(m_idx)) return;
2841 * Attempt to cast a spell at an enemy other than the player
2842 * (may slow the game a smidgeon, but I haven't noticed.)
2844 if (monst_spell_monst(m_idx)) return;
2846 can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall)));
2848 /* Hack -- Assume no movement */
2849 mm[0] = mm[1] = mm[2] = mm[3] = 0;
2850 mm[4] = mm[5] = mm[6] = mm[7] = 0;
2853 if (monster_move_callback(mm, m_idx))
2857 #endif /* USE_SCRIPT */
2860 /* Confused -- 100% random */
2861 if (m_ptr->confused || !aware)
2863 /* Try four "random" directions */
2864 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2867 /* 75% random movement */
2868 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2869 (r_ptr->flags1 & RF1_RAND_25) &&
2870 (rand_int(100) < 75))
2872 /* Memorize flags */
2873 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2874 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_25);
2876 /* Try four "random" directions */
2877 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2880 /* 50% random movement */
2881 else if ((r_ptr->flags1 & RF1_RAND_50) &&
2882 (rand_int(100) < 50))
2884 /* Memorize flags */
2885 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
2887 /* Try four "random" directions */
2888 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2891 /* 25% random movement */
2892 else if ((r_ptr->flags1 & RF1_RAND_25) &&
2893 (rand_int(100) < 25))
2895 /* Memorize flags */
2896 if (m_ptr->ml) r_ptr->r_flags1 |= RF1_RAND_25;
2898 /* Try four "random" directions */
2899 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2902 /* Can't reach player - find something else to hit */
2903 else if ((r_ptr->flags1 & RF1_NEVER_MOVE) && (m_ptr->cdis > 1))
2905 /* Try four "random" directions */
2906 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2908 /* Look for an enemy */
2909 #if 0 /* Hack - Too slow. Mimic pits are horrible with this on. */
2910 get_enemy_dir(m_idx, mm);
2914 /* Pets will follow the player */
2915 else if (is_pet(m_ptr))
2917 /* Are we trying to avoid the player? */
2918 bool avoid = ((p_ptr->pet_follow_distance < 0) &&
2919 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
2921 /* Do we want to find the player? */
2922 bool lonely = (!avoid && (m_ptr->cdis > p_ptr->pet_follow_distance));
2924 /* Should we find the player if we can't find a monster? */
2925 bool distant = (m_ptr->cdis > PET_SEEK_DIST);
2927 /* by default, move randomly */
2928 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2930 /* Look for an enemy */
2931 if (!get_enemy_dir(m_idx, mm))
2933 /* Find the player if necessary */
2934 if (avoid || lonely || distant)
2936 /* Remember the leash length */
2937 int dis = p_ptr->pet_follow_distance;
2939 /* Hack -- adjust follow distance temporarily */
2940 if (p_ptr->pet_follow_distance > PET_SEEK_DIST)
2942 p_ptr->pet_follow_distance = PET_SEEK_DIST;
2945 /* Find the player */
2946 get_moves(m_idx, mm);
2948 /* Restore the leash */
2949 p_ptr->pet_follow_distance = dis;
2954 /* Friendly monster movement */
2955 else if (!is_hostile(m_ptr))
2957 /* by default, move randomly */
2958 mm[0] = mm[1] = mm[2] = mm[3] = 5;
2960 /* Look for an enemy */
2961 get_enemy_dir(m_idx, mm);
2963 /* Normal movement */
2964 else if (stupid_monsters)
2967 get_moves(m_idx, mm);
2971 /* Logical moves, may do nothing */
2972 if (!get_moves(m_idx, mm)) return;
2975 /* Assume nothing */
2980 /* Assume nothing */
2981 did_open_door = FALSE;
2982 did_bash_door = FALSE;
2983 did_take_item = FALSE;
2984 did_kill_item = FALSE;
2985 did_move_body = FALSE;
2986 did_pass_wall = FALSE;
2987 did_kill_wall = FALSE;
2990 /* Take a zero-terminated array of "directions" */
2991 for (i = 0; mm[i]; i++)
2993 /* Get the direction */
2996 /* Hack -- allow "randomized" motion */
2997 if (d == 5) d = ddd[rand_int(8)];
2999 /* Get the destination */
3003 /* Ignore locations off of edge */
3004 if (!in_bounds2(ny, nx)) continue;
3006 /* Access that cave grid */
3007 c_ptr = &cave[ny][nx];
3009 /* Access that cave grid's contents */
3010 y_ptr = &m_list[c_ptr->m_idx];
3012 /* Floor is open? */
3013 if (cave_floor_grid(c_ptr))
3015 /* Go ahead and move */
3019 /* Hack -- player 'in' wall */
3020 else if ((ny == py) && (nx == px))
3025 else if (c_ptr->m_idx)
3027 /* Possibly a monster to attack */
3031 /* Permanent wall */
3032 else if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
3033 (c_ptr->feat <= FEAT_PERM_SOLID))
3038 /* Hack -- semi-transparent terrains are no obstacle */
3039 else if (c_ptr->feat == FEAT_TREES)
3044 /* Hack -- semi-transparent terrains are no obstacle */
3045 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)))))
3051 /* Monster moves through walls (and doors) */
3052 else if (can_pass_wall)
3054 /* Pass through walls/doors/rubble */
3057 /* Monster went through a wall */
3058 did_pass_wall = TRUE;
3061 /* Monster destroys walls (and doors) */
3062 else if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != p_ptr->riding))
3064 /* Eat through walls/doors/rubble */
3067 /* Monster destroyed a wall */
3068 did_kill_wall = TRUE;
3070 if (randint(GRINDNOISE) == 1)
3073 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
3075 msg_print("There is a grinding sound.");
3080 /* Forget the wall */
3081 c_ptr->info &= ~(CAVE_MARK);
3084 c_ptr->feat = floor_type[rand_int(100)];
3085 c_ptr->info &= ~(CAVE_MASK);
3086 c_ptr->info |= CAVE_FLOOR;
3088 /* Note changes to viewable region */
3089 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3092 /* Handle doors and secret doors */
3093 else if (((c_ptr->feat >= FEAT_DOOR_HEAD) &&
3094 (c_ptr->feat <= FEAT_DOOR_TAIL)) ||
3095 (c_ptr->feat == FEAT_SECRET))
3097 bool may_bash = TRUE;
3099 /* Assume no move allowed */
3102 /* Creature can open doors. */
3103 if ((r_ptr->flags2 & RF2_OPEN_DOOR) &&
3104 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3106 /* Closed doors and secret doors */
3107 if ((c_ptr->feat == FEAT_DOOR_HEAD) ||
3108 (c_ptr->feat == FEAT_SECRET))
3110 /* The door is open */
3111 did_open_door = TRUE;
3113 /* Do not bash the door */
3116 /* Assume no move allowed */
3120 /* Locked doors (not jammed) */
3121 else if (c_ptr->feat < FEAT_DOOR_HEAD + 0x08)
3126 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3128 /* Try to unlock it XXX XXX XXX */
3129 if (rand_int(m_ptr->hp / 10) > k)
3131 /* Unlock the door */
3132 cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00);
3134 /* Do not bash the door */
3140 /* Stuck doors -- attempt to bash them down if allowed */
3141 if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) &&
3142 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
3147 k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
3149 /* Attempt to Bash XXX XXX XXX */
3150 if (rand_int(m_ptr->hp / 10) > k)
3154 msg_print("¥É¥¢¤òᤳ«¤±¤ë²»¤¬¤·¤¿¡ª");
3156 msg_print("You hear a door burst open!");
3160 /* Disturb (sometimes) */
3161 if (disturb_minor) disturb(0, 0);
3163 /* The door was bashed open */
3164 did_bash_door = TRUE;
3166 /* Hack -- fall into doorway */
3172 /* Deal with doors in the way */
3173 if (did_open_door || did_bash_door)
3175 /* Break down the door */
3176 if (did_bash_door && (rand_int(100) < 50))
3178 cave_set_feat(ny, nx, FEAT_BROKEN);
3184 cave_set_feat(ny, nx, FEAT_OPEN);
3187 /* Handle viewable doors */
3188 if (player_has_los_bold(ny, nx)) do_view = TRUE;
3192 /* Hack -- check for Glyph of Warding */
3193 if (do_move && (c_ptr->feat == FEAT_GLYPH) &&
3194 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3196 /* Assume no move allowed */
3199 /* Break the ward */
3200 if (!is_pet(m_ptr) && (randint(BREAK_GLYPH) < r_ptr->level))
3202 /* Describe observable breakage */
3203 if (c_ptr->info & CAVE_MARK)
3206 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3208 msg_print("The rune of protection is broken!");
3213 /* Forget the rune */
3214 c_ptr->info &= ~(CAVE_MARK);
3216 /* Break the rune */
3217 c_ptr->feat = floor_type[rand_int(100)];
3218 c_ptr->info &= ~(CAVE_MASK);
3219 c_ptr->info |= CAVE_FLOOR;
3221 /* Allow movement */
3228 else if (do_move && (c_ptr->feat == FEAT_MINOR_GLYPH) &&
3229 !((r_ptr->flags1 & RF1_NEVER_BLOW) && (py == ny) && (px == nx)))
3231 /* Assume no move allowed */
3234 /* Break the ward */
3237 /* Break the ward */
3238 if (randint(BREAK_MINOR_GLYPH) > r_ptr->level)
3240 /* Describe observable breakage */
3241 if (c_ptr->info & CAVE_MARK)
3244 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3246 msg_print("The rune explodes!");
3249 project(0, 2, ny, nx, 2 * ((p_ptr->lev / 2) + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_REF | PROJECT_NO_HANGEKI), -1);
3255 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3257 msg_print("An explosive rune was disarmed.");
3261 /* Forget the rune */
3262 c_ptr->info &= ~(CAVE_MARK);
3264 /* Break the rune */
3265 c_ptr->feat = floor_type[rand_int(100)];
3266 c_ptr->info &= ~(CAVE_MASK);
3267 c_ptr->info |= CAVE_FLOOR;
3271 if (!m_ptr->r_idx) return;
3272 /* Allow movement */
3276 if (do_move && (ny == py) && (nx == px) && (d_info[dungeon_type].flags1 & DF1_NO_MELEE))
3281 /* Some monsters never attack */
3282 if (do_move && (ny == py) && (nx == px) &&
3283 (r_ptr->flags1 & RF1_NEVER_BLOW))
3285 /* Hack -- memorize lack of attacks */
3286 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
3292 /* The player is in the way. Attack him. */
3293 if (do_move && (ny == py) && (nx == px))
3295 if (!p_ptr->riding || one_in_(2))
3298 (void)make_attack_normal(m_idx);
3308 if ((c_ptr->feat >= FEAT_PATTERN_START) &&
3309 (c_ptr->feat <= FEAT_PATTERN_XTRA2) &&
3310 !do_turn && !(r_ptr->flags7 & RF7_CAN_FLY))
3316 /* A monster is in the way */
3317 if (do_move && c_ptr->m_idx)
3319 monster_race *z_ptr = &r_info[y_ptr->r_idx];
3320 monster_type *m2_ptr = &m_list[c_ptr->m_idx];
3322 /* Assume no movement */
3325 /* Attack 'enemies' */
3326 if (((r_ptr->flags2 & (RF2_KILL_BODY)) &&
3327 (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
3328 (cave_floor_grid(c_ptr)) &&
3329 (c_ptr->m_idx != p_ptr->riding)) ||
3330 are_enemies(m_ptr, m2_ptr) || m_ptr->confused)
3334 if (r_ptr->flags2 & RF2_KILL_BODY) r_ptr->r_flags2 |= (RF2_KILL_BODY);
3337 if ((m2_ptr->r_idx) && (m2_ptr->hp >= 0))
3339 if (monst_attack_monst(m_idx, cave[ny][nx].m_idx))
3344 /* Push past weaker monsters (unless leaving a wall) */
3345 else if ((r_ptr->flags2 & RF2_MOVE_BODY) &&
3346 (r_ptr->mexp > z_ptr->mexp) && cave_floor_grid(c_ptr) &&
3347 (cave_floor_grid(&cave[m_ptr->fy][m_ptr->fx])) &&
3348 (c_ptr->m_idx != p_ptr->riding))
3350 /* Allow movement */
3353 /* Monster pushed past another monster */
3354 did_move_body = TRUE;
3356 /* XXX XXX XXX Message */
3361 * Check if monster can cross terrain
3362 * This is checked after the normal attacks
3363 * to allow monsters to attack an enemy,
3364 * even if it can't enter the terrain.
3366 if (do_move && !monster_can_cross_terrain(c_ptr->feat, r_ptr))
3368 /* Assume no move allowed */
3372 /* Some monsters never move */
3373 if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
3375 /* Hack -- memorize lack of attacks */
3376 if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
3382 if (m_idx == p_ptr->riding)
3384 if (!p_ptr->riding_ryoute && !(m_list[p_ptr->riding].monfear)) do_move = FALSE;
3387 /* Creature has been allowed move */
3390 s16b this_o_idx, next_o_idx;
3395 /* Hack -- Update the old location */
3396 cave[oy][ox].m_idx = c_ptr->m_idx;
3398 if (cave[ny][nx].feat == FEAT_TREES)
3400 if (r_ptr->flags2 & RF2_KILL_WALL)
3402 c_ptr->feat = FEAT_GRASS;
3403 c_ptr->info &= ~(CAVE_MASK);
3404 c_ptr->info |= CAVE_FLOOR;
3406 if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
3408 m_ptr->energy -= 100;
3412 /* Mega-Hack -- move the old monster, if any */
3415 /* Move the old monster */
3419 /* Update the old monster */
3420 update_mon(c_ptr->m_idx, TRUE);
3422 /* Wake up the moved monster */
3423 m_list[c_ptr->m_idx].csleep = 0;
3426 /* Hack -- Update the new location */
3427 c_ptr->m_idx = m_idx;
3429 /* Move the monster */
3433 /* Update the monster */
3434 update_mon(m_idx, TRUE);
3436 if (p_ptr->riding == m_idx)
3442 /* Redraw the old grid */
3445 /* Redraw the new grid */
3448 if (p_ptr->riding == m_idx)
3453 p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW);
3455 /* Update the monsters */
3456 p_ptr->update |= (PU_DISTANCE);
3459 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
3462 /* Possible disturb */
3463 if (m_ptr->ml && (disturb_move ||
3464 ((m_ptr->mflag & MFLAG_VIEW) &&
3468 if (is_hostile(m_ptr))
3472 /* Scan all objects in the grid */
3473 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3477 /* Acquire object */
3478 o_ptr = &o_list[this_o_idx];
3480 /* Acquire next object */
3481 next_o_idx = o_ptr->next_o_idx;
3484 if (o_ptr->tval == TV_GOLD) continue;
3487 * Skip "real" corpses and statues, to avoid extreme
3488 * silliness like a novice rogue pockets full of statues
3491 if ((o_ptr->tval == TV_CORPSE) ||
3492 (o_ptr->tval == TV_STATUE)) continue;
3494 /* Take or Kill objects on the floor */
3495 if ((r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
3496 (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)))
3503 char o_name[MAX_NLEN];
3505 /* Extract some flags */
3506 object_flags(o_ptr, &f1, &f2, &f3);
3508 /* Acquire the object name */
3509 object_desc(o_name, o_ptr, TRUE, 3);
3511 /* Acquire the monster name */
3512 monster_desc(m_name, m_ptr, 0x04);
3514 /* React to objects that hurt the monster */
3515 if (f1 & TR1_KILL_DRAGON) flg3 |= (RF3_DRAGON);
3516 if (f1 & TR1_SLAY_DRAGON) flg3 |= (RF3_DRAGON);
3517 if (f1 & TR1_SLAY_TROLL) flg3 |= (RF3_TROLL);
3518 if (f1 & TR1_SLAY_GIANT) flg3 |= (RF3_GIANT);
3519 if (f1 & TR1_SLAY_ORC) flg3 |= (RF3_ORC);
3520 if (f1 & TR1_SLAY_DEMON) flg3 |= (RF3_DEMON);
3521 if (f1 & TR1_SLAY_UNDEAD) flg3 |= (RF3_UNDEAD);
3522 if (f1 & TR1_SLAY_ANIMAL) flg3 |= (RF3_ANIMAL);
3523 if (f1 & TR1_SLAY_EVIL) flg3 |= (RF3_EVIL);
3525 /* The object cannot be picked up by the monster */
3526 if (artifact_p(o_ptr) || (r_ptr->flags3 & flg3) ||
3529 /* Only give a message for "take_item" */
3530 if ((r_ptr->flags2 & (RF2_TAKE_ITEM)) && (r_ptr->flags2 & (RF2_STUPID)))
3533 did_take_item = TRUE;
3535 /* Describe observable situations */
3536 if (m_ptr->ml && player_can_see_bold(ny, nx))
3538 /* Dump a message */
3540 msg_format("%^s¤Ï%s¤ò½¦¤ª¤¦¤È¤·¤¿¤¬¡¢¤À¤á¤À¤Ã¤¿¡£",
3542 msg_format("%^s tries to pick up %s, but fails.",
3550 /* Pick up the item */
3551 else if (r_ptr->flags2 & RF2_TAKE_ITEM)
3554 did_take_item = TRUE;
3556 /* Describe observable situations */
3557 if (player_can_see_bold(ny, nx))
3559 /* Dump a message */
3561 msg_format("%^s¤¬%s¤ò½¦¤Ã¤¿¡£", m_name, o_name);
3563 msg_format("%^s picks up %s.", m_name, o_name);
3568 /* Excise the object */
3569 excise_object_idx(this_o_idx);
3572 o_ptr->marked = FALSE;
3574 /* Forget location */
3575 o_ptr->iy = o_ptr->ix = 0;
3577 /* Memorize monster */
3578 o_ptr->held_m_idx = m_idx;
3581 o_ptr->next_o_idx = m_ptr->hold_o_idx;
3584 m_ptr->hold_o_idx = this_o_idx;
3587 /* Destroy the item if not a pet */
3588 else if (!is_pet(m_ptr))
3591 did_kill_item = TRUE;
3593 /* Describe observable situations */
3594 if (player_has_los_bold(ny, nx))
3596 /* Dump a message */
3598 msg_format("%^s¤¬%s¤òÇ˲õ¤·¤¿¡£", m_name, o_name);
3600 msg_format("%^s destroys %s.", m_name, o_name);
3605 /* Delete the object */
3606 delete_object_idx(this_o_idx);
3612 /* Stop when done */
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 */
3825 /* Assume no move */
3828 /* Handle "sensing radius" */
3829 if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > 20 ? 20 : r_ptr->aaf) : r_ptr->aaf))
3831 /* We can "sense" the player */
3835 /* Handle "sight" and "aggravation" */
3836 else if ((m_ptr->cdis <= MAX_SIGHT) &&
3837 (player_has_los_bold(fy, fx) || p_ptr->aggravate))
3839 /* We can "see" or "feel" the player */
3843 /* Hack -- Monsters can "smell" the player from far away */
3844 /* Note that most monsters have "aaf" of "20" or so */
3845 else if (!stupid_monsters && !p_ptr->no_flowed &&
3846 (cave_floor_bold(py, px) || (cave[py][px].feat == FEAT_TREES)) &&
3847 (cave[py][px].when == cave[fy][fx].when) &&
3848 (cave[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
3849 (cave[fy][fx].dist < r_ptr->aaf))
3851 /* We can "smell" the player */
3854 else if (m_ptr->target_y) test = TRUE;
3857 if (!test) continue;
3860 if (p_ptr->riding == i)
3861 speed = p_ptr->pspeed;
3864 speed = MIN(199, m_ptr->mspeed);
3866 /* Monsters move quickly in Nightmare mode */
3867 if (ironman_nightmare)
3869 speed = MIN(199, m_ptr->mspeed + 5);
3872 if (m_ptr->fast) speed = MIN(199, speed + 10);
3873 if (m_ptr->slow) speed = MAX(0, speed - 10);
3876 e = extract_energy[speed];
3878 /* Give this monster some energy */
3879 if(rand_int(60) < e)
3880 m_ptr->energy += gain_energy();
3883 /* Not enough energy to move */
3884 if (m_ptr->energy < 100) continue;
3886 /* Use up "some" energy */
3887 m_ptr->energy -= 100;
3890 /* Save global index */
3893 /* Process the monster */
3896 m_ptr->target_y = 0;
3897 m_ptr->target_x = 0;
3899 /* Hack -- notice death or departure */
3900 if (!alive || death) break;
3902 /* Notice leaving */
3903 if (p_ptr->leaving) break;
3906 /* Reset global index */
3910 /* Tracking a monster race (the same one we were before) */
3911 if (p_ptr->monster_race_idx && (p_ptr->monster_race_idx == old_monster_race_idx))
3913 /* Acquire monster race */
3914 r_ptr = &r_info[p_ptr->monster_race_idx];
3916 /* Check for knowledge change */
3917 if ((old_r_flags1 != r_ptr->r_flags1) ||
3918 (old_r_flags2 != r_ptr->r_flags2) ||
3919 (old_r_flags3 != r_ptr->r_flags3) ||
3920 (old_r_flags4 != r_ptr->r_flags4) ||
3921 (old_r_flags5 != r_ptr->r_flags5) ||
3922 (old_r_flags6 != r_ptr->r_flags6) ||
3923 (old_r_blows0 != r_ptr->r_blows[0]) ||
3924 (old_r_blows1 != r_ptr->r_blows[1]) ||
3925 (old_r_blows2 != r_ptr->r_blows[2]) ||
3926 (old_r_blows3 != r_ptr->r_blows[3]) ||
3927 (old_r_cast_inate != r_ptr->r_cast_inate) ||
3928 (old_r_cast_spell != r_ptr->r_cast_spell))
3931 p_ptr->window |= (PW_MONSTER);
3938 bool process_the_world(int num, int who, bool vs_player)
3940 if(world_monster) return (FALSE);
3945 monster_desc(m_name, &m_list[hack_m_idx], 0);
3949 msg_print("¡Ö¡Ø¥¶¡¦¥ï¡¼¥ë¥É¡Ù¡ª»þ¤Ï»ß¤Þ¤Ã¤¿¡ª¡×");
3951 msg_format("%s yells 'The World! Time has stopped!'", m_name);
3955 msg_print("¡Ö»þ¤è¡ª¡×");
3957 msg_format("%s yells 'Time!'", m_name);
3959 else msg_print("hek!");
3964 world_monster = TRUE;
3966 if (vs_player) do_cmd_redraw();
3970 if(!m_list[hack_m_idx].r_idx) return (TRUE);
3971 process_monster(hack_m_idx);
3973 m_list[hack_m_idx].target_y = 0;
3974 m_list[hack_m_idx].target_x = 0;
3977 if (p_ptr->notice) notice_stuff();
3980 if (p_ptr->update) update_stuff();
3983 if (p_ptr->redraw) redraw_stuff();
3986 if (p_ptr->window) window_stuff();
3989 if (vs_player) Term_xtra(TERM_XTRA_DELAY, 500);
3993 p_ptr->redraw |= (PR_MAP);
3995 /* Update monsters */
3996 p_ptr->update |= (PU_MONSTERS);
3999 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
4001 world_monster = FALSE;
4002 if (vs_player || los(py, px, m_list[hack_m_idx].fy, m_list[hack_m_idx].fx))
4005 msg_print("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
4007 msg_print("You feel time flowing around you once more.");
4018 void monster_gain_exp(int m_idx, int s_idx)
4020 monster_type *m_ptr = &m_list[m_idx];
4021 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4022 monster_race *s_ptr = &r_info[s_idx];
4025 if (p_ptr->inside_battle) return;
4027 if (!r_ptr->next_exp) return;
4029 new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2);
4030 if (m_idx == p_ptr->riding) new_exp = (new_exp + 1) / 2;
4031 if (!dun_level) new_exp /= 5;
4032 m_ptr->exp += new_exp;
4033 if (m_ptr->mflag2 & MFLAG_CHAMELEON) return;
4035 if (m_ptr->exp >= r_ptr->next_exp)
4038 int old_hp = m_ptr->hp;
4039 int old_maxhp = m_ptr->max_maxhp;
4040 int old_r_idx = m_ptr->r_idx;
4043 monster_desc(m_name, m_ptr, 0);
4044 m_ptr->r_idx = r_ptr->next_r_idx;
4045 r_ptr = &r_info[m_ptr->r_idx];
4046 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
4048 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
4052 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
4054 if (ironman_nightmare)
4056 u32b hp = m_ptr->max_maxhp * 2L;
4058 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
4060 m_ptr->maxhp = m_ptr->max_maxhp;
4061 m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp;
4063 /* Extract the monster base speed */
4064 m_ptr->mspeed = r_ptr->speed;
4066 /* Hack -- small racial variety */
4067 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
4069 /* Allow some small variation per monster */
4070 if(rand_int(4) == 1){
4071 i = extract_energy[r_ptr->speed] / 3;
4072 if (i) m_ptr->mspeed += rand_spread(0, i);
4075 i = extract_energy[r_ptr->speed] / 10;
4076 if (i) m_ptr->mspeed += rand_spread(0, i);
4080 if (m_ptr->mspeed > 199) m_ptr->mspeed = 199;
4084 if (is_pet(m_ptr) || m_ptr->ml)
4086 msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
4087 r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
4089 update_mon(m_idx, FALSE);
4090 lite_spot(m_ptr->fy, m_ptr->fx);
4092 if (m_idx == p_ptr->riding) p_ptr->update |= PU_BONUS;
4097 * ¥¨¥Í¥ë¥®¡¼¤ÎÁý²ÃÎÌ10d5¤ò®¤¯·×»»¤¹¤ë¤¿¤á¤Î´Ø¿ô
4100 #define Go_no_JuuJou 5*5*5*5*5*5*5*5*5*5
4102 s32b gain_energy(void)
4105 s32b energy_result = 10;
4108 tmp = rand_int(Go_no_JuuJou);
4110 for (i = 0; i < 9; i ++){
4111 energy_result += tmp % 5;
4115 return energy_result + tmp;