4 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: misc code for monsters */
15 #define HORDE_NOGOOD 0x01
16 #define HORDE_NOEVIL 0x02
20 cptr horror_desc[MAX_SAN_HORROR] =
74 cptr funny_desc[MAX_SAN_FUNNY] =
89 "¥Õ¥¡¥ó¥¿¥¹¥Æ¥£¥Ã¥¯¤Ê",
134 cptr funny_comments[MAX_SAN_COMMENT] =
155 * Set the target of counter attack
157 void set_target(monster_type *m_ptr, int y, int x)
165 * Reset the target of counter attack
167 void reset_target(monster_type *m_ptr)
169 set_target(m_ptr, 0, 0);
174 * Extract monster race pointer of a monster's true form
176 monster_race *real_r_ptr(monster_type *m_ptr)
178 monster_race *r_ptr = &r_info[m_ptr->r_idx];
180 /* Extract real race */
181 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
183 if (r_ptr->flags1 & RF1_UNIQUE)
184 return &r_info[MON_CHAMELEON_K];
186 return &r_info[MON_CHAMELEON];
196 * Delete a monster by index.
198 * When a monster is deleted, all of its objects are deleted.
200 void delete_monster_idx(int i)
204 monster_type *m_ptr = &m_list[i];
206 monster_race *r_ptr = &r_info[m_ptr->r_idx];
208 s16b this_o_idx, next_o_idx = 0;
216 /* Hack -- Reduce the racial counter */
217 real_r_ptr(m_ptr)->cur_num--;
219 /* Hack -- count the number of "reproducers" */
220 if (r_ptr->flags2 & (RF2_MULTIPLY)) num_repro--;
223 /* Hack -- remove target monster */
224 if (i == target_who) target_who = 0;
226 /* Hack -- remove tracked monster */
227 if (i == p_ptr->health_who) health_track(0);
229 if (pet_t_m_idx == i ) pet_t_m_idx = 0;
230 if (riding_t_m_idx == i) riding_t_m_idx = 0;
231 if (p_ptr->riding == i) p_ptr->riding = 0;
233 /* Monster is gone */
234 cave[y][x].m_idx = 0;
238 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
243 o_ptr = &o_list[this_o_idx];
245 /* Acquire next object */
246 next_o_idx = o_ptr->next_o_idx;
249 * o_ptr->held_m_idx is needed in delete_object_idx()
250 * to prevent calling lite_spot()
253 /* Delete the object */
254 delete_object_idx(this_o_idx);
258 /* Wipe the Monster */
259 (void)WIPE(m_ptr, monster_type);
267 /* Update some things */
268 p_ptr->update |= (PU_MON_LITE);
273 * Delete the monster, if any, at a given location
275 void delete_monster(int y, int x)
280 if (!in_bounds(y, x)) return;
285 /* Delete the monster (if any) */
286 if (c_ptr->m_idx) delete_monster_idx(c_ptr->m_idx);
291 * Move an object from index i1 to index i2 in the object list
293 static void compact_monsters_aux(int i1, int i2)
301 s16b this_o_idx, next_o_idx = 0;
305 if (i1 == i2) return;
318 /* Update the cave */
321 /* Repair objects being carried by monster */
322 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
327 o_ptr = &o_list[this_o_idx];
329 /* Acquire next object */
330 next_o_idx = o_ptr->next_o_idx;
332 /* Reset monster pointer */
333 o_ptr->held_m_idx = i2;
336 /* Hack -- Update the target */
337 if (target_who == i1) target_who = i2;
339 /* Hack -- Update the target */
340 if (pet_t_m_idx == i1) pet_t_m_idx = i2;
341 if (riding_t_m_idx == i1) riding_t_m_idx = i2;
343 /* Hack -- Update the riding */
344 if (p_ptr->riding == i1) p_ptr->riding = i2;
346 /* Hack -- Update the health bar */
347 if (p_ptr->health_who == i1) health_track(i2);
350 COPY(&m_list[i2], &m_list[i1], monster_type);
353 (void)WIPE(&m_list[i1], monster_type);
359 * Compact and Reorder the monster list
361 * This function can be very dangerous, use with caution!
363 * When actually "compacting" monsters, we base the saving throw
364 * on a combination of monster level, distance from player, and
365 * current "desperation".
367 * After "compacting" (if needed), we "reorder" the monsters into a more
368 * compact order, and we reset the allocation info, and the "live" array.
370 void compact_monsters(int size)
373 int cur_lev, cur_dis, chance;
375 /* Message (only if compacting) */
377 if (size) msg_print("¥â¥ó¥¹¥¿¡¼¾ðÊó¤ò°µ½Ì¤·¤Æ¤¤¤Þ¤¹...");
379 if (size) msg_print("Compacting monsters...");
383 /* Compact at least 'size' objects */
384 for (num = 0, cnt = 1; num < size; cnt++)
386 /* Get more vicious each iteration */
389 /* Get closer each iteration */
390 cur_dis = 5 * (20 - cnt);
392 /* Check all the monsters */
393 for (i = 1; i < m_max; i++)
395 monster_type *m_ptr = &m_list[i];
397 monster_race *r_ptr = &r_info[m_ptr->r_idx];
399 /* Paranoia -- skip "dead" monsters */
400 if (!m_ptr->r_idx) continue;
402 /* Hack -- High level monsters start out "immune" */
403 if (r_ptr->level > cur_lev) continue;
405 if (i == p_ptr->riding) continue;
407 /* Ignore nearby monsters */
408 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
410 /* Saving throw chance */
413 /* Only compact "Quest" Monsters in emergencies */
414 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
416 /* Try not to compact Unique Monsters */
417 if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
419 /* All monsters get a saving throw */
420 if (randint0(100) < chance) continue;
422 /* Delete the monster */
423 delete_monster_idx(i);
425 /* Count the monster */
431 /* Excise dead monsters (backwards!) */
432 for (i = m_max - 1; i >= 1; i--)
434 /* Get the i'th monster */
435 monster_type *m_ptr = &m_list[i];
437 /* Skip real monsters */
438 if (m_ptr->r_idx) continue;
440 /* Move last monster into open hole */
441 compact_monsters_aux(m_max - 1, i);
443 /* Compress "m_max" */
450 * Pre-calculate the racial counters of preserved pets
451 * To prevent multiple generation of unique monster who is the minion of player
453 void precalc_cur_num_of_pet(void)
457 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
459 for (i = 0; i < max_num; i++)
461 m_ptr = &party_mon[i];
463 /* Skip empty monsters */
464 if (!m_ptr->r_idx) continue;
466 /* Hack -- Increase the racial counter */
467 real_r_ptr(m_ptr)->cur_num++;
473 * Delete/Remove all the monsters when the player leaves the level
475 * This is an efficient method of simulating multiple calls to the
476 * "delete_monster()" function, with no visual effects.
478 void wipe_m_list(void)
482 /* Hack -- if Banor or Lupart dies, stay another dead */
483 if (!r_info[MON_BANORLUPART].max_num)
485 if (r_info[MON_BANOR].max_num)
487 r_info[MON_BANOR].max_num = 0;
488 r_info[MON_BANOR].r_pkills++;
489 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
491 if (r_info[MON_LUPART].max_num)
493 r_info[MON_LUPART].max_num = 0;
494 r_info[MON_LUPART].r_pkills++;
495 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
499 /* Delete all the monsters */
500 for (i = m_max - 1; i >= 1; i--)
502 monster_type *m_ptr = &m_list[i];
504 /* Skip dead monsters */
505 if (!m_ptr->r_idx) continue;
507 /* Monster is gone */
508 cave[m_ptr->fy][m_ptr->fx].m_idx = 0;
510 /* Wipe the Monster */
511 (void)WIPE(m_ptr, monster_type);
516 * Wiping racial counters of all monsters and incrementing of racial
517 * counters of monsters in party_mon[] is required to prevent multiple
518 * generation of unique monster who is the minion of player.
521 /* Hack -- Wipe the racial counter of all monster races */
522 for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
524 /* Hack -- Increase the racial counters of pets */
525 precalc_cur_num_of_pet();
533 /* Hack -- reset "reproducer" count */
536 /* Hack -- no more target */
541 /* Hack -- no more tracking */
547 * Acquires and returns the index of a "free" monster.
549 * This routine should almost never fail, but it *can* happen.
556 /* Normal allocation */
557 if (m_max < max_m_idx)
559 /* Access the next hole */
562 /* Expand the array */
568 /* Return the index */
573 /* Recycle dead monsters */
574 for (i = 1; i < m_max; i++)
578 /* Acquire monster */
581 /* Skip live monsters */
582 if (m_ptr->r_idx) continue;
587 /* Use this monster */
592 /* Warn the player (except during dungeon creation) */
594 if (character_dungeon) msg_print("¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë¡ª");
596 if (character_dungeon) msg_print("Too many monsters!");
600 /* Try not to crash */
608 * Hack -- the "type" of the current "summon specific"
610 static int summon_specific_type = 0;
614 * Hack -- the index of the summoning monster
616 static int summon_specific_who = -1;
620 * Hack -- the hostility of the summoned monster
622 static bool summon_specific_hostile = TRUE;
624 static bool summon_unique_okay = FALSE;
627 static bool summon_specific_aux(int r_idx)
629 monster_race *r_ptr = &r_info[r_idx];
632 /* Check our requirements */
633 switch (summon_specific_type)
637 okay = (r_ptr->d_char == 'a');
643 okay = (r_ptr->d_char == 'S');
649 okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
655 okay = (r_ptr->d_char == 'M');
661 okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
667 okay = (r_ptr->flags3 & RF3_DEMON);
673 okay = (r_ptr->flags3 & RF3_UNDEAD);
679 okay = (r_ptr->flags3 & RF3_DRAGON);
683 case SUMMON_HI_UNDEAD:
685 okay = ((r_ptr->d_char == 'L') ||
686 (r_ptr->d_char == 'V') ||
687 (r_ptr->d_char == 'W'));
691 case SUMMON_HI_DRAGON:
693 okay = (r_ptr->d_char == 'D');
697 case SUMMON_HI_DEMON:
699 okay = (((r_ptr->d_char == 'U') ||
700 (r_ptr->d_char == 'H') ||
701 (r_ptr->d_char == 'B')) &&
702 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
706 case SUMMON_AMBERITES:
708 okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
714 okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
718 case SUMMON_BIZARRE1:
720 okay = (r_ptr->d_char == 'm');
723 case SUMMON_BIZARRE2:
725 okay = (r_ptr->d_char == 'b');
728 case SUMMON_BIZARRE3:
730 okay = (r_ptr->d_char == 'Q');
734 case SUMMON_BIZARRE4:
736 okay = (r_ptr->d_char == 'v');
740 case SUMMON_BIZARRE5:
742 okay = (r_ptr->d_char == '$');
746 case SUMMON_BIZARRE6:
748 okay = ((r_ptr->d_char == '!') ||
749 (r_ptr->d_char == '?') ||
750 (r_ptr->d_char == '=') ||
751 (r_ptr->d_char == '$') ||
752 (r_ptr->d_char == '|'));
758 okay = (r_ptr->d_char == 'g');
764 okay = ((r_ptr->d_char == 'U') &&
765 (r_ptr->flags4 & RF4_ROCKET));
772 okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
778 okay = (r_idx == MON_DAWN);
784 okay = (r_ptr->flags3 & (RF3_ANIMAL));
788 case SUMMON_ANIMAL_RANGER:
790 okay = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
791 (strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
792 !(r_ptr->flags3 & (RF3_DRAGON)) &&
793 !(r_ptr->flags3 & (RF3_EVIL)) &&
794 !(r_ptr->flags3 & (RF3_UNDEAD)) &&
795 !(r_ptr->flags3 & (RF3_DEMON)) &&
796 !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
797 !(r_ptr->flags4 || r_ptr->flags5 || r_ptr->flags6));
801 case SUMMON_HI_DRAGON_LIVING:
803 okay = ((r_ptr->d_char == 'D') && monster_living(r_ptr));
809 okay = monster_living(r_ptr);
815 okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
819 case SUMMON_BLUE_HORROR:
821 okay = (r_idx == MON_BLUE_HORROR);
825 case SUMMON_ELEMENTAL:
827 okay = (r_ptr->d_char == 'E');
833 okay = (r_ptr->d_char == 'v');
839 okay = (r_ptr->d_char == 'H');
845 okay = (r_ptr->d_char == 'B');
849 case SUMMON_KAMIKAZE:
852 for (i = 0; i < 4; i++)
853 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
857 case SUMMON_KAMIKAZE_LIVING:
861 for (i = 0; i < 4; i++)
862 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
863 okay = (okay && monster_living(r_ptr));
869 okay = (r_idx == MON_MANES);
875 okay = (r_idx == MON_LOUSE);
879 case SUMMON_GUARDIANS:
881 okay = (r_ptr->flags7 & RF7_GUARDIAN);
887 okay = ((r_idx == MON_NOV_PALADIN) ||
888 (r_idx == MON_NOV_PALADIN_G) ||
889 (r_idx == MON_PALADIN) ||
890 (r_idx == MON_W_KNIGHT) ||
891 (r_idx == MON_ULTRA_PALADIN) ||
892 (r_idx == MON_KNI_TEMPLAR));
898 okay = (r_ptr->d_char == 'B' &&
899 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
900 (r_ptr->flags8 & RF8_WILD_ONLY));
904 case SUMMON_PIRANHAS:
906 okay = (r_idx == MON_PIRANHA);
910 case SUMMON_ARMAGE_GOOD:
912 okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
916 case SUMMON_ARMAGE_EVIL:
918 okay = ((r_ptr->flags3 & RF3_DEMON) ||
919 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
925 /* Since okay is int, "return (okay);" is not correct. */
926 return (bool)(okay ? TRUE : FALSE);
930 static int chameleon_change_m_idx = 0;
934 * Some dungeon types restrict the possible monsters.
935 * Return TRUE is the monster is OK and FALSE otherwise
937 static bool restrict_monster_to_dungeon(int r_idx)
939 dungeon_info_type *d_ptr = &d_info[dungeon_type];
940 monster_race *r_ptr = &r_info[r_idx];
943 if (d_ptr->flags1 & DF1_CHAMELEON)
945 if (chameleon_change_m_idx) return TRUE;
947 if (d_ptr->flags1 & DF1_NO_MAGIC)
949 if (r_idx != MON_CHAMELEON &&
951 !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
952 !(r_ptr->flags5 & RF5_NOMAGIC_MASK) &&
953 !(r_ptr->flags6 & RF6_NOMAGIC_MASK))
956 if (d_ptr->flags1 & DF1_NO_MELEE)
958 if (r_idx == MON_CHAMELEON) return TRUE;
959 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
960 !(r_ptr->flags5 & (RF5_BOLT_MASK | RF5_BEAM_MASK | RF5_BALL_MASK | RF5_CAUSE_1 | RF5_CAUSE_2 | RF5_CAUSE_3 | RF5_CAUSE_4 | RF5_MIND_BLAST | RF5_BRAIN_SMASH)) &&
961 !(r_ptr->flags6 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
964 if (d_ptr->flags1 & DF1_BEGINNER)
966 if (r_ptr->level > dun_level)
970 if (d_ptr->special_div >= 64) return TRUE;
971 if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
975 case DUNGEON_MODE_AND:
978 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
983 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
988 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
993 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
998 if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
1003 if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
1008 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1013 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1018 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1023 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1026 for (a = 0; a < 5; a++)
1027 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
1031 case DUNGEON_MODE_NAND:
1034 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
1039 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
1044 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
1049 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
1054 if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
1059 if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
1064 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1069 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1074 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1079 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1082 for (a = 0; a < 5; a++)
1083 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
1087 case DUNGEON_MODE_OR:
1088 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
1089 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
1090 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
1091 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
1092 if (r_ptr->flags5 & d_ptr->mflags5) return TRUE;
1093 if (r_ptr->flags6 & d_ptr->mflags6) return TRUE;
1094 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
1095 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
1096 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
1097 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
1098 for (a = 0; a < 5; a++)
1099 if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
1103 case DUNGEON_MODE_NOR:
1104 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
1105 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
1106 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
1107 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
1108 if (r_ptr->flags5 & d_ptr->mflags5) return FALSE;
1109 if (r_ptr->flags6 & d_ptr->mflags6) return FALSE;
1110 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
1111 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
1112 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
1113 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
1114 for (a = 0; a < 5; a++)
1115 if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1124 * Apply a "monster restriction function" to the "monster allocation table"
1126 errr get_mon_num_prep(monster_hook_type monster_hook,
1127 monster_hook_type monster_hook2)
1131 /* Todo: Check the hooks for non-changes */
1133 /* Set the new hooks */
1134 get_mon_num_hook = monster_hook;
1135 get_mon_num2_hook = monster_hook2;
1137 /* Scan the allocation table */
1138 for (i = 0; i < alloc_race_size; i++)
1140 monster_race *r_ptr;
1143 alloc_entry *entry = &alloc_race_table[i];
1146 r_ptr = &r_info[entry->index];
1148 /* Skip monsters which don't pass the restriction */
1149 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1150 (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1153 if (!p_ptr->inside_battle && !chameleon_change_m_idx &&
1154 summon_specific_type != SUMMON_GUARDIANS)
1156 /* Hack -- don't create questors */
1157 if (r_ptr->flags1 & RF1_QUESTOR)
1160 if (r_ptr->flags7 & RF7_GUARDIAN)
1163 /* Depth Monsters never appear out of depth */
1164 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1165 (r_ptr->level > dun_level))
1169 /* Accept this monster */
1170 entry->prob2 = entry->prob1;
1172 if (dun_level && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest)) && !restrict_monster_to_dungeon(entry->index) && !p_ptr->inside_battle)
1174 int hoge = entry->prob2 * d_info[dungeon_type].special_div;
1175 entry->prob2 = hoge / 64;
1176 if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1185 static int mysqrt(int n)
1223 * Choose a monster race that seems "appropriate" to the given level
1225 * This function uses the "prob2" field of the "monster allocation table",
1226 * and various local information, to calculate the "prob3" field of the
1227 * same table, which is then used to choose an "appropriate" monster, in
1228 * a relatively efficient manner.
1230 * Note that "town" monsters will *only* be created in the town, and
1231 * "normal" monsters will *never* be created in the town, unless the
1232 * "level" is "modified", for example, by polymorph or summoning.
1234 * There is a small chance (1/50) of "boosting" the given depth by
1235 * a small amount (up to four levels), except in the town.
1237 * It is (slightly) more likely to acquire a monster of the given level
1238 * than one of a lower level. This is done by choosing several monsters
1239 * appropriate to the given level and keeping the "hardest" one.
1241 * Note that if no monsters are "appropriate", then this function will
1242 * fail, and return zero, but this should *almost* never happen.
1244 s16b get_mon_num(int level)
1252 monster_race *r_ptr;
1254 alloc_entry *table = alloc_race_table;
1256 int pls_kakuritu, pls_level;
1257 int hoge=mysqrt(level*10000L);
1259 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1261 if ((dungeon_turn > hoge*(TURNS_PER_TICK*500L)) && !level)
1263 pls_kakuritu = MAX(2, NASTY_MON-((dungeon_turn/(TURNS_PER_TICK*2500L)-hoge/10)));
1264 pls_level = MIN(8,3 + dungeon_turn/(TURNS_PER_TICK*20000L)-hoge/40);
1268 pls_kakuritu = NASTY_MON;
1272 if (d_info[dungeon_type].flags1 & DF1_MAZE)
1274 pls_kakuritu = MIN(pls_kakuritu/2, pls_kakuritu-10);
1275 if (pls_kakuritu < 2) pls_kakuritu = 2;
1280 /* Boost the level */
1281 if ((level > 0) && !p_ptr->inside_battle && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1283 /* Nightmare mode allows more out-of depth monsters */
1284 if (ironman_nightmare && !randint0(pls_kakuritu))
1286 /* What a bizarre calculation */
1287 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1291 /* Occasional "nasty" monster */
1292 if (!randint0(pls_kakuritu))
1294 /* Pick a level bonus */
1295 int d = MIN(5, level/10) + pls_level;
1297 /* Boost the level */
1301 /* Occasional "nasty" monster */
1302 if (!randint0(pls_kakuritu))
1304 /* Pick a level bonus */
1305 int d = MIN(5, level/10) + pls_level;
1307 /* Boost the level */
1317 /* Process probabilities */
1318 for (i = 0; i < alloc_race_size; i++)
1320 /* Monsters are sorted by depth */
1321 if (table[i].level > level) break;
1326 /* Access the "r_idx" of the chosen monster */
1327 r_idx = table[i].index;
1329 /* Access the actual race */
1330 r_ptr = &r_info[r_idx];
1332 if (!p_ptr->inside_battle && !chameleon_change_m_idx)
1334 /* Hack -- "unique" monsters must be "unique" */
1335 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1336 (r_ptr->flags7 & (RF7_UNIQUE_7))) &&
1337 (r_ptr->cur_num >= r_ptr->max_num))
1342 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1343 (r_ptr->cur_num >= 1))
1348 if (r_idx == MON_BANORLUPART)
1350 if (r_info[MON_BANOR].cur_num > 0) continue;
1351 if (r_info[MON_LUPART].cur_num > 0) continue;
1356 table[i].prob3 = table[i].prob2;
1359 total += table[i].prob3;
1362 /* No legal monsters */
1363 if (total <= 0) return (0);
1366 /* Pick a monster */
1367 value = randint0(total);
1369 /* Find the monster */
1370 for (i = 0; i < alloc_race_size; i++)
1372 /* Found the entry */
1373 if (value < table[i].prob3) break;
1376 value = value - table[i].prob3;
1383 /* Try for a "harder" monster once (50%) or twice (10%) */
1389 /* Pick a monster */
1390 value = randint0(total);
1392 /* Find the monster */
1393 for (i = 0; i < alloc_race_size; i++)
1395 /* Found the entry */
1396 if (value < table[i].prob3) break;
1399 value = value - table[i].prob3;
1402 /* Keep the "best" one */
1403 if (table[i].level < table[j].level) i = j;
1406 /* Try for a "harder" monster twice (10%) */
1412 /* Pick a monster */
1413 value = randint0(total);
1415 /* Find the monster */
1416 for (i = 0; i < alloc_race_size; i++)
1418 /* Found the entry */
1419 if (value < table[i].prob3) break;
1422 value = value - table[i].prob3;
1425 /* Keep the "best" one */
1426 if (table[i].level < table[j].level) i = j;
1430 return (table[i].index);
1438 * Build a string describing a monster in some way.
1440 * We can correctly describe monsters based on their visibility.
1441 * We can force all monsters to be treated as visible or invisible.
1442 * We can build nominatives, objectives, possessives, or reflexives.
1443 * We can selectively pronominalize hidden, visible, or all monsters.
1444 * We can use definite or indefinite descriptions for hidden monsters.
1445 * We can use definite or indefinite descriptions for visible monsters.
1447 * Pronominalization involves the gender whenever possible and allowed,
1448 * so that by cleverly requesting pronominalization / visibility, you
1449 * can get messages like "You hit someone. She screams in agony!".
1451 * Reflexives are acquired by requesting Objective plus Possessive.
1453 * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1454 * unless the "Assume Visible" mode is requested.
1456 * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1457 * If neither m_ptr nor r_ptr is given, the monster is assumed to
1458 * be neuter, singular, and hidden (unless "Assume Visible" is set),
1459 * in which case you may be in trouble... :-)
1461 * I am assuming that no monster name is more than 70 characters long,
1462 * so that "char desc[80];" is sufficiently large for any result.
1465 * MD_OBJECTIVE --> Objective (or Reflexive)
1466 * MD_POSSESSIVE --> Possessive (or Reflexive)
1467 * MD_INDEF_HIDDEN --> Use indefinites for hidden monsters ("something")
1468 * MD_INDEF_VISIBLE --> Use indefinites for visible monsters ("a kobold")
1469 * MD_PRON_HIDDEN --> Pronominalize hidden monsters
1470 * MD_PRON_VISIBLE --> Pronominalize visible monsters
1471 * MD_ASSUME_HIDDEN --> Assume the monster is hidden
1472 * MD_ASSUME_VISIBLE --> Assume the monster is visible
1473 * MD_TRUE_NAME --> Chameleon's true name
1474 * MD_IGNORE_HALLU --> Ignore hallucination, and penetrate shape change
1475 * MD_ASSUME_OUTSIDE --> Assume this monster pet waiting outside the floor
1478 * 0x00 --> Full nominative name ("the kobold") or "it"
1479 * MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1480 * MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1481 * MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1482 * MD_PRON_VISIBLE | MD_POSSESSIVE
1483 * --> Possessive, genderized if visable ("his") or "its"
1484 * MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1485 * --> Reflexive, genderized if visable ("himself") or "itself"
1487 void monster_desc(char *desc, monster_type *m_ptr, int mode)
1490 monster_race *r_ptr;
1494 char silly_name[1024];
1498 r_ptr = &r_info[m_ptr->ap_r_idx];
1500 /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1501 if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1502 else name = (r_name + r_ptr->name);
1504 /* Are we hallucinating? (Idea from Nethack...) */
1505 if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1510 if (!get_rnd_line("silly_j.txt", m_ptr->r_idx, silly_name))
1512 if (!get_rnd_line("silly.txt", m_ptr->r_idx, silly_name))
1520 monster_race *hallu_race;
1524 hallu_race = &r_info[randint1(max_r_idx - 1)];
1526 while (hallu_race->flags1 & RF1_UNIQUE);
1528 strcpy(silly_name, (r_name + hallu_race->name));
1531 /* Better not strcpy it, or we could corrupt r_info... */
1535 /* Can we "see" it (exists + forced, or visible + not unforced) */
1536 seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1538 /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1539 pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1542 /* First, try using pronouns, or describing hidden monsters */
1545 /* an encoding of the monster "sex" */
1548 /* Extract the gender (if applicable) */
1549 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1550 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1552 /* Ignore the gender (if desired) */
1553 if (!m_ptr || !pron) kind = 0x00;
1556 /* Assume simple result */
1564 /* Brute force: split on the possibilities */
1565 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1567 /* Neuter, or unknown */
1569 case 0x00: res = "²¿¤«"; break;
1570 case 0x00 + (MD_OBJECTIVE): res = "²¿¤«"; break;
1571 case 0x00 + (MD_POSSESSIVE): res = "²¿¤«¤Î"; break;
1572 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "²¿¤«¼«¿È"; break;
1573 case 0x00 + (MD_INDEF_HIDDEN): res = "²¿¤«"; break;
1574 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "²¿¤«"; break;
1575 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "²¿¤«"; break;
1576 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "¤½¤ì¼«¿È"; break;
1578 case 0x00: res = "it"; break;
1579 case 0x00 + (MD_OBJECTIVE): res = "it"; break;
1580 case 0x00 + (MD_POSSESSIVE): res = "its"; break;
1581 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1582 case 0x00 + (MD_INDEF_HIDDEN): res = "something"; break;
1583 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "something"; break;
1584 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "something's"; break;
1585 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1589 /* Male (assume human if vague) */
1591 case 0x10: res = "Èà"; break;
1592 case 0x10 + (MD_OBJECTIVE): res = "Èà"; break;
1593 case 0x10 + (MD_POSSESSIVE): res = "Èà¤Î"; break;
1594 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1595 case 0x10 + (MD_INDEF_HIDDEN): res = "狼"; break;
1596 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "狼"; break;
1597 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "狼¤Î"; break;
1598 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1600 case 0x10: res = "he"; break;
1601 case 0x10 + (MD_OBJECTIVE): res = "him"; break;
1602 case 0x10 + (MD_POSSESSIVE): res = "his"; break;
1603 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1604 case 0x10 + (MD_INDEF_HIDDEN): res = "someone"; break;
1605 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1606 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1607 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1611 /* Female (assume human if vague) */
1613 case 0x20: res = "Èà½÷"; break;
1614 case 0x20 + (MD_OBJECTIVE): res = "Èà½÷"; break;
1615 case 0x20 + (MD_POSSESSIVE): res = "Èà½÷¤Î"; break;
1616 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1617 case 0x20 + (MD_INDEF_HIDDEN): res = "狼"; break;
1618 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "狼"; break;
1619 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "狼¤Î"; break;
1620 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1622 case 0x20: res = "she"; break;
1623 case 0x20 + (MD_OBJECTIVE): res = "her"; break;
1624 case 0x20 + (MD_POSSESSIVE): res = "her"; break;
1625 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1626 case 0x20 + (MD_INDEF_HIDDEN): res = "someone"; break;
1627 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1628 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1629 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1633 /* Copy the result */
1634 (void)strcpy(desc, res);
1638 /* Handle visible monsters, "reflexive" request */
1639 else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1641 /* The monster is visible, so use its gender */
1643 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "Èà½÷¼«¿È");
1644 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "È༫¿È");
1645 else strcpy(desc, "¤½¤ì¼«¿È");
1647 if (r_ptr->flags1 & RF1_FEMALE) strcpy(desc, "herself");
1648 else if (r_ptr->flags1 & RF1_MALE) strcpy(desc, "himself");
1649 else strcpy(desc, "itself");
1654 /* Handle all other visible monster requests */
1658 if (is_pet(m_ptr) && m_ptr->ap_r_idx != m_ptr->r_idx)
1664 while(strncmp(t, "¡Ù", 2) && *t) t++;
1668 (void)sprintf(desc, "%s¡©¡Ù", buf);
1671 (void)sprintf(desc, "%s¡©", name);
1673 (void)sprintf(desc, "%s?", name);
1678 /* It could be a Unique */
1679 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1681 /* Start with the name (thus nominative and objective) */
1682 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1688 while (strncmp(t, "¡Ù", 2) && *t) t++;
1692 (void)sprintf(desc, "%s¡©¡Ù", buf);
1695 (void)sprintf(desc, "%s¡©", name);
1697 (void)sprintf(desc, "%s?", name);
1700 else if ((cave[m_ptr->fy][m_ptr->fx].m_idx == p_ptr->riding) || !p_ptr->inside_battle)
1701 (void)strcpy(desc, name);
1704 (void)sprintf(desc, "%s¤â¤É¤", name);
1706 (void)sprintf(desc, "fake %s", name);
1710 /* It could be an indefinite monster */
1711 else if (mode & MD_INDEF_VISIBLE)
1713 /* XXX Check plurality for "some" */
1715 /* Indefinite monsters need an indefinite article */
1717 (void)strcpy(desc, "");
1719 (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1722 (void)strcat(desc, name);
1725 /* It could be a normal, definite, monster */
1728 /* Definite monsters need a definite article */
1731 (void)strcpy(desc, "¤¢¤Ê¤¿¤Î");
1733 (void)strcpy(desc, "your ");
1738 (void)strcpy(desc, "");
1740 (void)strcpy(desc, "the ");
1743 (void)strcat(desc, name);
1746 if (m_ptr->nickname)
1749 sprintf(buf,"¡Ö%s¡×",quark_str(m_ptr->nickname));
1751 sprintf(buf," called %s",quark_str(m_ptr->nickname));
1756 if (player_bold(m_ptr->fy, m_ptr->fx))
1759 strcat(desc,"(¾èÇÏÃæ)");
1761 strcat(desc,"(riding)");
1765 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1767 if (r_ptr->flags1 & RF1_UNIQUE)
1770 strcat(desc,"(¥«¥á¥ì¥ª¥ó¤Î²¦)");
1772 strcat(desc,"(Chameleon Lord)");
1778 strcat(desc,"(¥«¥á¥ì¥ª¥ó)");
1780 strcat(desc,"(Chameleon)");
1785 if ((mode & MD_IGNORE_HALLU) && m_ptr->ap_r_idx != m_ptr->r_idx)
1787 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1790 if (mode & MD_ASSUME_OUTSIDE)
1793 strcat(desc,"(ÂÔµ¡Ãæ)");
1795 strcat(desc,"(waiting)");
1799 /* Handle the Possessive as a special afterthought */
1800 if (mode & MD_POSSESSIVE)
1802 /* XXX Check for trailing "s" */
1804 /* Simply append "apostrophe" and "s" */
1806 (void)strcat(desc, "¤Î");
1808 (void)strcat(desc, "'s");
1818 * Learn about a monster (by "probing" it)
1820 * Return the number of new flags learnt. -Mogami-
1822 int lore_do_probe(int r_idx)
1824 monster_race *r_ptr = &r_info[r_idx];
1828 /* Maximal info about awareness */
1829 if (r_ptr->r_wake != MAX_UCHAR) n++;
1830 if (r_ptr->r_ignore != MAX_UCHAR) n++;
1831 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1833 /* Observe "maximal" attacks */
1834 for (i = 0; i < 4; i++)
1836 /* Examine "actual" blows */
1837 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1839 /* Maximal observations */
1840 if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1841 r_ptr->r_blows[i] = MAX_UCHAR;
1847 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1848 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1849 ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1850 ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1851 ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1852 ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1854 /* Only "valid" drops */
1855 if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1857 if (r_ptr->r_drop_item != tmp_byte) n++;
1858 r_ptr->r_drop_item = tmp_byte;
1860 if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1862 if (r_ptr->r_drop_gold != tmp_byte) n++;
1863 r_ptr->r_drop_gold = tmp_byte;
1866 /* Observe many spells */
1867 if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1868 r_ptr->r_cast_spell = MAX_UCHAR;
1870 /* Count unknown flags */
1871 for (i = 0; i < 32; i++)
1873 if (!(r_ptr->r_flags1 & (1L << i)) &&
1874 (r_ptr->flags1 & (1L << i))) n++;
1875 if (!(r_ptr->r_flags2 & (1L << i)) &&
1876 (r_ptr->flags2 & (1L << i))) n++;
1877 if (!(r_ptr->r_flags3 & (1L << i)) &&
1878 (r_ptr->flags3 & (1L << i))) n++;
1879 if (!(r_ptr->r_flags4 & (1L << i)) &&
1880 (r_ptr->flags4 & (1L << i))) n++;
1881 if (!(r_ptr->r_flags5 & (1L << i)) &&
1882 (r_ptr->flags5 & (1L << i))) n++;
1883 if (!(r_ptr->r_flags6 & (1L << i)) &&
1884 (r_ptr->flags6 & (1L << i))) n++;
1885 if (!(r_ptr->r_flagsr & (1L << i)) &&
1886 (r_ptr->flagsr & (1L << i))) n++;
1888 /* r_flags7 is actually unused */
1890 if (!(r_ptr->r_flags7 & (1L << i)) &&
1891 (r_ptr->flags7 & (1L << i))) n++;
1895 /* Know all the flags */
1896 r_ptr->r_flags1 = r_ptr->flags1;
1897 r_ptr->r_flags2 = r_ptr->flags2;
1898 r_ptr->r_flags3 = r_ptr->flags3;
1899 r_ptr->r_flags4 = r_ptr->flags4;
1900 r_ptr->r_flags5 = r_ptr->flags5;
1901 r_ptr->r_flags6 = r_ptr->flags6;
1902 r_ptr->r_flagsr = r_ptr->flagsr;
1904 /* r_flags7 is actually unused */
1905 /* r_ptr->r_flags7 = r_ptr->flags7; */
1907 /* Know about evolution */
1908 if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1909 r_ptr->r_xtra1 |= MR1_SINKA;
1911 /* Update monster recall window */
1912 if (p_ptr->monster_race_idx == r_idx)
1915 p_ptr->window |= (PW_MONSTER);
1918 /* Return the number of new flags learnt */
1924 * Take note that the given monster just dropped some treasure
1926 * Note that learning the "GOOD"/"GREAT" flags gives information
1927 * about the treasure (even when the monster is killed for the first
1928 * time, such as uniques, and the treasure has not been examined yet).
1930 * This "indirect" method is used to prevent the player from learning
1931 * exactly how much treasure a monster can drop from observing only
1932 * a single example of a drop. This method actually observes how much
1933 * gold and items are dropped, and remembers that information to be
1934 * described later by the monster recall code.
1936 void lore_treasure(int m_idx, int num_item, int num_gold)
1938 monster_type *m_ptr = &m_list[m_idx];
1940 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1942 /* If the monster doesn't have original appearance, don't note */
1943 if (!is_original_ap(m_ptr)) return;
1945 /* Note the number of things dropped */
1946 if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1947 if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1949 /* Hack -- memorize the good/great flags */
1950 if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1951 if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1953 /* Update monster recall window */
1954 if (p_ptr->monster_race_idx == m_ptr->r_idx)
1957 p_ptr->window |= (PW_MONSTER);
1963 void sanity_blast(monster_type *m_ptr, bool necro)
1965 bool happened = FALSE;
1968 if (p_ptr->inside_battle || !character_dungeon) return;
1973 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1975 power = r_ptr->level / 2;
1977 monster_desc(m_name, m_ptr, 0);
1979 if (!(r_ptr->flags1 & RF1_UNIQUE))
1981 if (r_ptr->flags1 & RF1_FRIENDS)
1987 return; /* No effect yet, just loaded... */
1990 return; /* Cannot see it for some reason */
1992 if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
1998 return; /* Pet eldritch horrors are safe most of the time */
2000 if (randint1(100) > power) return;
2002 if (saving_throw(p_ptr->skill_sav - power))
2004 return; /* Save, no adverse effects */
2009 /* Something silly happens... */
2011 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2012 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2014 msg_format("You behold the %s visage of %s!",
2015 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2021 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2022 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2025 return; /* Never mind; we can't see it clearly enough */
2028 /* Something frightening happens... */
2030 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2031 horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2033 msg_format("You behold the %s visage of %s!",
2034 horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2037 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2039 /* Demon characters are unaffected */
2040 if (prace_is_(RACE_IMP) || prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
2041 if (p_ptr->wizard) return;
2043 /* Undead characters are 50% likely to be unaffected */
2044 if (prace_is_(RACE_SKELETON) || prace_is_(RACE_ZOMBIE)
2045 || prace_is_(RACE_VAMPIRE) || prace_is_(RACE_SPECTRE) ||
2046 (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
2048 if (saving_throw(25 + p_ptr->lev)) return;
2054 msg_print("¥Í¥¯¥í¥Î¥ß¥³¥ó¤òÆɤó¤ÇÀµµ¤¤ò¼º¤Ã¤¿¡ª");
2056 msg_print("Your sanity is shaken by reading the Necronomicon!");
2061 if (!saving_throw(p_ptr->skill_sav - power)) /* Mind blast */
2063 if (!p_ptr->resist_conf)
2065 (void)set_confused(p_ptr->confused + randint0(4) + 4);
2067 if (!p_ptr->resist_chaos && one_in_(3))
2069 (void)set_image(p_ptr->image + randint0(250) + 150);
2074 if (!saving_throw(p_ptr->skill_sav - power)) /* Lose int & wis */
2081 if (!saving_throw(p_ptr->skill_sav - power)) /* Brain smash */
2083 if (!p_ptr->resist_conf)
2085 (void)set_confused(p_ptr->confused + randint0(4) + 4);
2087 if (!p_ptr->free_act)
2089 (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2091 while (randint0(100) > p_ptr->skill_sav)
2092 (void)do_dec_stat(A_INT);
2093 while (randint0(100) > p_ptr->skill_sav)
2094 (void)do_dec_stat(A_WIS);
2095 if (!p_ptr->resist_chaos)
2097 (void)set_image(p_ptr->image + randint0(250) + 150);
2102 if (!saving_throw(p_ptr->skill_sav - power)) /* Amnesia */
2105 if (lose_all_info())
2107 msg_print("¤¢¤Þ¤ê¤Î¶²ÉݤËÁ´¤Æ¤Î¤³¤È¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
2109 msg_print("You forget everything in your utmost terror!");
2115 if (saving_throw(p_ptr->skill_sav - power))
2120 /* Else gain permanent insanity */
2121 if ((p_ptr->muta3 & MUT3_MORONIC) && /*(p_ptr->muta2 & MUT2_BERS_RAGE) &&*/
2122 ((p_ptr->muta2 & MUT2_COWARDICE) || (p_ptr->resist_fear)) &&
2123 ((p_ptr->muta2 & MUT2_HALLU) || (p_ptr->resist_chaos)))
2125 /* The poor bastard already has all possible insanities! */
2131 switch (randint1(21))
2134 if (!(p_ptr->muta3 & MUT3_MORONIC) && one_in_(5))
2136 if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2139 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¤è¤¦¤Êµ¤¤¬¤·¤¿¡£¤·¤«¤·¤½¤ì¤Ï¸µ¡¹¤À¤Ã¤¿¡£");
2141 msg_print("You turn into an utter moron!");
2147 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¡ª");
2149 msg_print("You turn into an utter moron!");
2153 if (p_ptr->muta3 & MUT3_HYPER_INT)
2156 msg_print("¤¢¤Ê¤¿¤ÎǾ¤ÏÀ¸ÂÎ¥³¥ó¥Ô¥å¡¼¥¿¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2158 msg_print("Your brain is no longer a living computer.");
2161 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2163 p_ptr->muta3 |= MUT3_MORONIC;
2177 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2180 msg_print("¤¢¤Ê¤¿¤Ï¥Ñ¥é¥Î¥¤¥¢¤Ë¤Ê¤Ã¤¿¡ª");
2182 msg_print("You become paranoid!");
2186 /* Duh, the following should never happen, but anyway... */
2187 if (p_ptr->muta3 & MUT3_FEARLESS)
2190 msg_print("¤¢¤Ê¤¿¤Ï¤â¤¦¶²¤ìÃΤ餺¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2192 msg_print("You are no longer fearless.");
2195 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2198 p_ptr->muta2 |= MUT2_COWARDICE;
2212 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2215 msg_print("¸¸³Ð¤ò¤Ò¤µ¯¤³¤¹Àº¿ÀºøÍð¤Ë´Ù¤Ã¤¿¡ª");
2217 msg_print("You are afflicted by a hallucinatory insanity!");
2220 p_ptr->muta2 |= MUT2_HALLU;
2225 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2228 msg_print("·ãÎõ¤Ê´¶¾ð¤Îȯºî¤Ë¤ª¤½¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡ª");
2230 msg_print("You become subject to fits of berserk rage!");
2233 p_ptr->muta2 |= MUT2_BERS_RAGE;
2240 p_ptr->update |= PU_BONUS;
2246 * This function updates the monster record of the given monster
2248 * This involves extracting the distance to the player (if requested),
2249 * and then checking for visibility (natural, infravision, see-invis,
2250 * telepathy), updating the monster visibility flag, redrawing (or
2251 * erasing) the monster when its visibility changes, and taking note
2252 * of any interesting monster flags (cold-blooded, invisible, etc).
2254 * Note the new "mflag" field which encodes several monster state flags,
2255 * including "view" for when the monster is currently in line of sight,
2256 * and "mark" for when the monster is currently visible via detection.
2258 * The only monster fields that are changed here are "cdis" (the
2259 * distance from the player), "ml" (visible to the player), and
2260 * "mflag" (to maintain the "MFLAG_VIEW" flag).
2262 * Note the special "update_monsters()" function which can be used to
2263 * call this function once for every monster.
2265 * Note the "full" flag which requests that the "cdis" field be updated,
2266 * this is only needed when the monster (or the player) has moved.
2268 * Every time a monster moves, we must call this function for that
2269 * monster, and update the distance, and the visibility. Every time
2270 * the player moves, we must call this function for every monster, and
2271 * update the distance, and the visibility. Whenever the player "state"
2272 * changes in certain ways ("blindness", "infravision", "telepathy",
2273 * and "see invisible"), we must call this function for every monster,
2274 * and update the visibility.
2276 * Routines that change the "illumination" of a grid must also call this
2277 * function for any monster in that grid, since the "visibility" of some
2278 * monsters may be based on the illumination of their grid.
2280 * Note that this function is called once per monster every time the
2281 * player moves. When the player is running, this function is one
2282 * of the primary bottlenecks, along with "update_view()" and the
2283 * "process_monsters()" code, so efficiency is important.
2285 * Note the optimized "inline" version of the "distance()" function.
2287 * A monster is "visible" to the player if (1) it has been detected
2288 * by the player, (2) it is close to the player and the player has
2289 * telepathy, or (3) it is close to the player, and in line of sight
2290 * of the player, and it is "illuminated" by some combination of
2291 * infravision, torch light, or permanent light (invisible monsters
2292 * are only affected by "light" if the player can see invisible).
2294 * Monsters which are not on the current panel may be "visible" to
2295 * the player, and their descriptions will include an "offscreen"
2296 * reference. Currently, offscreen monsters cannot be targetted
2297 * or viewed directly, but old targets will remain set. XXX XXX
2299 * The player can choose to be disturbed by several things, including
2300 * "disturb_move" (monster which is viewable moves in some way), and
2301 * "disturb_near" (monster which is "easily" viewable moves in some
2302 * way). Note that "moves" includes "appears" and "disappears".
2304 void update_mon(int m_idx, bool full)
2306 monster_type *m_ptr = &m_list[m_idx];
2308 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2310 bool do_disturb = disturb_move;
2314 /* Current location */
2321 /* Seen by vision */
2324 /* Non-Ninja player in the darkness */
2325 bool in_darkness = (d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
2330 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2332 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
2336 /* Compute distance */
2339 /* Distance components */
2340 int dy = (py > fy) ? (py - fy) : (fy - py);
2341 int dx = (px > fx) ? (px - fx) : (fx - px);
2343 /* Approximate distance */
2344 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2346 /* Restrict distance */
2347 if (d > 255) d = 255;
2351 /* Save the distance */
2355 /* Extract distance */
2358 /* Extract the distance */
2364 if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
2368 if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
2370 if (!in_darkness || (d <= MAX_SIGHT / 4))
2372 if (p_ptr->special_defense & KATA_MUSOU)
2377 if (is_original_ap(m_ptr))
2379 /* Hack -- Memorize mental flags */
2380 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2381 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2385 /* Basic telepathy */
2386 else if (p_ptr->telepathy)
2388 /* Empty mind, no telepathy */
2389 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
2391 /* Memorize flags */
2392 if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
2395 /* Weird mind, occasional telepathy */
2396 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
2398 /* One in ten individuals are detectable */
2399 if ((m_idx % 10) == 5)
2404 if (is_original_ap(m_ptr))
2406 /* Memorize flags */
2407 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
2409 /* Hack -- Memorize mental flags */
2410 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2411 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2416 /* Normal mind, allow telepathy */
2422 if (is_original_ap(m_ptr))
2424 /* Hack -- Memorize mental flags */
2425 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2426 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2431 /* Magical sensing */
2432 if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
2435 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_ANIMAL);
2438 /* Magical sensing */
2439 if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
2442 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_UNDEAD);
2445 /* Magical sensing */
2446 if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
2449 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_DEMON);
2452 /* Magical sensing */
2453 if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
2456 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_ORC);
2459 /* Magical sensing */
2460 if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
2463 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_TROLL);
2466 /* Magical sensing */
2467 if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
2470 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_GIANT);
2473 /* Magical sensing */
2474 if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
2477 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_DRAGON);
2480 /* Magical sensing */
2481 if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
2484 if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_HUMAN);
2487 /* Magical sensing */
2488 if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2491 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_EVIL);
2494 /* Magical sensing */
2495 if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2498 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_GOOD);
2501 /* Magical sensing */
2502 if ((p_ptr->esp_nonliving) &&
2503 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2506 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_NONLIVING);
2509 /* Magical sensing */
2510 if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2513 if (is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_UNIQUE);
2517 /* Normal line of sight, and not blind */
2518 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2520 bool do_invisible = FALSE;
2521 bool do_cold_blood = FALSE;
2523 /* Use "infravision" */
2524 if (d <= p_ptr->see_infra)
2526 /* Handle "cold blooded" monsters */
2527 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2530 do_cold_blood = TRUE;
2533 /* Handle "warm blooded" monsters */
2541 /* Use "illumination" */
2542 if (player_can_see_bold(fy, fx))
2544 /* Handle "invisible" monsters */
2545 if (r_ptr->flags2 & (RF2_INVISIBLE))
2548 do_invisible = TRUE;
2558 /* Handle "normal" monsters */
2569 if (is_original_ap(m_ptr))
2571 /* Memorize flags */
2572 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2573 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2580 /* The monster is now visible */
2583 /* It was previously unseen */
2586 /* Mark as visible */
2589 /* Draw the monster */
2592 /* Update health bar as needed */
2593 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2594 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2596 /* Hack -- Count "fresh" sightings */
2597 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2598 r_info[MON_KAGE].r_sights++;
2599 else if (m_ptr->ap_r_idx == m_ptr->r_idx &&
2600 r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
2602 /* Eldritch Horror */
2603 if (r_ptr->flags2 & RF2_ELDRITCH_HORROR)
2605 sanity_blast(m_ptr, FALSE);
2608 /* Disturb on appearance */
2609 if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, py, px) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
2611 if (disturb_pets || is_hostile(m_ptr))
2617 /* The monster is not visible */
2620 /* It was previously seen */
2623 /* Mark as not visible */
2626 /* Erase the monster */
2629 /* Update health bar as needed */
2630 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2631 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2633 /* Disturb on disappearance */
2636 if (disturb_pets || is_hostile(m_ptr))
2643 /* The monster is now easily visible */
2647 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2649 /* Mark as easily visible */
2650 m_ptr->mflag |= (MFLAG_VIEW);
2652 /* Disturb on appearance */
2655 if (disturb_pets || is_hostile(m_ptr))
2661 /* The monster is not easily visible */
2665 if (m_ptr->mflag & (MFLAG_VIEW))
2667 /* Mark as not easily visible */
2668 m_ptr->mflag &= ~(MFLAG_VIEW);
2670 /* Disturb on disappearance */
2673 if (disturb_pets || is_hostile(m_ptr))
2682 * This function simply updates all the (non-dead) monsters (see above).
2684 void update_monsters(bool full)
2688 /* Update each (live) monster */
2689 for (i = 1; i < m_max; i++)
2691 monster_type *m_ptr = &m_list[i];
2693 /* Skip dead monsters */
2694 if (!m_ptr->r_idx) continue;
2696 /* Update the monster */
2697 update_mon(i, full);
2703 * Hack -- the index of the summoning monster
2705 static bool monster_hook_chameleon_lord(int r_idx)
2707 monster_race *r_ptr = &r_info[r_idx];
2708 monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2709 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2711 if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2712 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2714 if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2716 if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2719 if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
2722 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2724 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2728 else if (summon_specific_who > 0)
2730 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2736 static bool monster_hook_chameleon(int r_idx)
2738 monster_race *r_ptr = &r_info[r_idx];
2739 monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2740 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2742 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2743 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2744 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2746 if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2749 if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
2752 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2754 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2755 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2756 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2760 else if (summon_specific_who > 0)
2762 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2765 return (*(get_monster_hook()))(r_idx);
2769 void choose_new_monster(int m_idx, bool born, int r_idx)
2772 monster_type *m_ptr = &m_list[m_idx];
2773 monster_race *r_ptr;
2774 char old_m_name[80];
2775 bool old_unique = FALSE;
2777 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2779 if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2780 r_ptr = &r_info[r_idx];
2782 monster_desc(old_m_name, m_ptr, 0);
2788 chameleon_change_m_idx = m_idx;
2790 get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2792 get_mon_num_prep(monster_hook_chameleon, NULL);
2795 level = r_info[MON_CHAMELEON_K].level;
2796 else if (!dun_level)
2797 level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2801 if (d_info[dungeon_type].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2803 r_idx = get_mon_num(level);
2804 r_ptr = &r_info[r_idx];
2806 chameleon_change_m_idx = 0;
2812 m_ptr->r_idx = r_idx;
2813 m_ptr->ap_r_idx = r_idx;
2814 update_mon(m_idx, FALSE);
2815 lite_spot(m_ptr->fy, m_ptr->fx);
2818 /* Sub-alignment of a chameleon */
2819 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2821 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2822 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2823 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2828 if (m_idx == p_ptr->riding)
2831 monster_desc(m_name, m_ptr, 0);
2833 msg_format("ÆÍÁ³%s¤¬ÊѿȤ·¤¿¡£", old_m_name);
2835 msg_format("Suddenly, %s transforms!", old_m_name);
2837 if (!(r_ptr->flags7 & RF7_RIDING))
2839 if (rakuba(0, TRUE)) msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2841 if (rakuba(0, TRUE)) msg_format("You have fallen from %s.", m_name);
2845 /* Extract the monster base speed */
2846 m_ptr->mspeed = get_mspeed(r_ptr);
2848 oldmaxhp = m_ptr->max_maxhp;
2849 /* Assign maximal hitpoints */
2850 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2852 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2856 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2858 m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2859 m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2866 static bool monster_hook_tanuki(int r_idx)
2868 monster_race *r_ptr = &r_info[r_idx];
2870 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2871 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2872 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2873 if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2875 if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2878 return (*(get_monster_hook()))(r_idx);
2883 * Set initial racial appearance of a monster
2885 static int initial_r_appearance(int r_idx)
2887 int attempts = 1000;
2890 int min = MIN(base_level-5, 50);
2892 if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2895 get_mon_num_prep(monster_hook_tanuki, NULL);
2899 ap_r_idx = get_mon_num(base_level + 10);
2900 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2908 * Get initial monster speed
2910 byte get_mspeed(monster_race *r_ptr)
2912 /* Extract the monster base speed */
2913 int mspeed = r_ptr->speed;
2915 /* Hack -- small racial variety */
2916 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2918 /* Allow some small variation per monster */
2919 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2920 if (i) mspeed += rand_spread(0, i);
2923 if (mspeed > 199) mspeed = 199;
2925 return (byte)mspeed;
2930 * Attempt to place a monster of the given race at the given location.
2932 * To give the player a sporting chance, any monster that appears in
2933 * line-of-sight and is extremely dangerous can be marked as
2934 * "FORCE_SLEEP", which will cause them to be placed with low energy,
2935 * which often (but not always) lets the player move before they do.
2937 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2939 * XXX XXX XXX Use special "here" and "dead" flags for unique monsters,
2940 * remove old "cur_num" and "max_num" fields.
2942 * XXX XXX XXX Actually, do something similar for artifacts, to simplify
2943 * the "preserve" mode, and to make the "what artifacts" flag more useful.
2945 * This is the only function which may place a monster in the dungeon,
2946 * except for the savefile loading code.
2948 bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
2952 monster_type *m_ptr;
2954 monster_race *r_ptr = &r_info[r_idx];
2956 cptr name = (r_name + r_ptr->name);
2958 /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2959 if(p_ptr->wild_mode) return FALSE;
2961 /* Verify location */
2962 if (!in_bounds(y, x)) return (FALSE);
2964 /* Require empty space (if not ghostly) */
2965 if (!(!dun_level && (cave[y][x].feat == FEAT_MOUNTAIN) && ((r_ptr->flags8 & RF8_WILD_MOUNTAIN) || (r_ptr->flags7 & RF7_CAN_FLY))) &&
2966 !(cave_empty_bold2(y, x) || (mode & PM_IGNORE_TERRAIN)) &&
2967 !((r_ptr->flags2 & RF2_PASS_WALL) &&
2968 !(cave_perma_bold(y, x) || cave[y][x].m_idx ||
2969 player_bold(y, x)))) return (FALSE);
2972 if (!r_idx) return (FALSE);
2975 if (!r_ptr->name) return (FALSE);
2977 /* Nor on the Pattern */
2978 if ((cave[y][x].feat >= FEAT_PATTERN_START)
2979 && (cave[y][x].feat <= FEAT_PATTERN_XTRA2))
2982 if (!(mode & PM_IGNORE_TERRAIN) &&
2983 !monster_can_cross_terrain(cave[y][x].feat, r_ptr))
2988 if (!p_ptr->inside_battle)
2990 /* Hack -- "unique" monsters must be "unique" */
2991 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2992 (r_ptr->flags7 & (RF7_UNIQUE_7))) &&
2993 (r_ptr->cur_num >= r_ptr->max_num))
2999 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
3000 (r_ptr->cur_num >= 1))
3005 if (r_idx == MON_BANORLUPART)
3007 if (r_info[MON_BANOR].cur_num > 0) return FALSE;
3008 if (r_info[MON_LUPART].cur_num > 0) return FALSE;
3011 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
3012 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
3013 (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
3020 if (quest_number(dun_level))
3022 int hoge = quest_number(dun_level);
3023 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
3025 if(r_idx == quest[hoge].r_idx)
3027 int number_mon, i2, j2;
3030 /* Count all quest monsters */
3031 for (i2 = 0; i2 < cur_wid; ++i2)
3032 for (j2 = 0; j2 < cur_hgt; j2++)
3033 if (cave[j2][i2].m_idx > 0)
3034 if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
3036 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
3042 /* Access the location */
3043 c_ptr = &cave[y][x];
3045 if (is_glyph_grid(c_ptr))
3047 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
3049 /* Describe observable breakage */
3050 if (c_ptr->info & CAVE_MARK)
3053 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3055 msg_print("The rune of protection is broken!");
3060 /* Forget the rune */
3061 c_ptr->info &= ~(CAVE_MARK);
3063 /* Break the rune */
3064 c_ptr->info &= ~(CAVE_OBJECT);
3073 /* Powerful monster */
3074 if (r_ptr->level > dun_level)
3076 /* Unique monsters */
3077 if (r_ptr->flags1 & (RF1_UNIQUE))
3079 /* Message for cheaters */
3081 if (cheat_hear) msg_format("¿¼ÁؤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3083 if (cheat_hear) msg_format("Deep Unique (%s).", name);
3087 /* Boost rating by twice delta-depth */
3088 rating += (r_ptr->level - dun_level) * 2;
3091 /* Normal monsters */
3094 /* Message for cheaters */
3096 if (cheat_hear) msg_format("¿¼ÁؤΥâ¥ó¥¹¥¿¡¼ (%s)¡£", name);
3098 if (cheat_hear) msg_format("Deep Monster (%s).", name);
3102 /* Boost rating by delta-depth */
3103 rating += (r_ptr->level - dun_level);
3107 /* Note the monster */
3108 else if (r_ptr->flags1 & (RF1_UNIQUE))
3110 /* Unique monsters induce message */
3112 if (cheat_hear) msg_format("¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3114 if (cheat_hear) msg_format("Unique (%s).", name);
3119 if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7) || (r_ptr->level < 10)) is_kage = FALSE;
3121 /* Make a new monster */
3122 c_ptr->m_idx = m_pop();
3123 hack_m_idx_ii = c_ptr->m_idx;
3125 /* Mega-Hack -- catch "failure" */
3126 if (!c_ptr->m_idx) return (FALSE);
3129 /* Get a new monster record */
3130 m_ptr = &m_list[c_ptr->m_idx];
3133 m_ptr->r_idx = r_idx;
3134 m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3136 /* Sub-alignment of a monster */
3137 if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3138 m_ptr->sub_align = m_list[who].sub_align;
3141 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3142 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3143 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3146 /* Place the monster at the location */
3151 /* No "damage" yet */
3153 m_ptr->confused = 0;
3156 /* Unknown distance */
3159 reset_target(m_ptr);
3161 m_ptr->nickname = 0;
3169 if (r_ptr->flags7 & RF7_CHAMELEON)
3171 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3172 r_ptr = &r_info[m_ptr->r_idx];
3173 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
3176 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3177 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3178 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3182 m_ptr->ap_r_idx = MON_KAGE;
3183 m_ptr->mflag2 |= MFLAG2_KAGE;
3186 if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
3192 if (mode & PM_FORCE_PET)
3197 else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3198 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3200 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
3203 /* Assume no sleeping */
3206 /* Enforce sleeping if needed */
3207 if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3209 int val = r_ptr->sleep;
3210 m_ptr->csleep = ((val * 2) + randint1(val * 10));
3213 /* Assign maximal hitpoints */
3214 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3216 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3220 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3223 /* Monsters have double hitpoints in Nightmare mode */
3224 if (ironman_nightmare)
3226 u32b hp = m_ptr->max_maxhp * 2L;
3228 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3231 m_ptr->maxhp = m_ptr->max_maxhp;
3233 /* And start out fully healthy */
3234 if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3235 m_ptr->hp = m_ptr->maxhp / 2;
3236 else m_ptr->hp = m_ptr->maxhp;
3239 /* Extract the monster base speed */
3240 m_ptr->mspeed = get_mspeed(r_ptr);
3242 if (mode & PM_HASTE) m_ptr->fast = 100;
3244 /* Give a random starting energy */
3245 if (!ironman_nightmare)
3247 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3251 /* Nightmare monsters are more prepared */
3252 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3255 /* Force monster to wait for player, unless in Nightmare mode */
3256 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3258 /* Monster is still being nice */
3259 m_ptr->mflag |= (MFLAG_NICE);
3261 /* Must repair monsters */
3262 repair_monsters = TRUE;
3265 /* Hack -- see "process_monsters()" */
3266 if (c_ptr->m_idx < hack_m_idx)
3268 /* Monster is still being born */
3269 m_ptr->mflag |= (MFLAG_BORN);
3273 if (r_ptr->flags7 & RF7_SELF_LD_MASK)
3274 p_ptr->update |= (PU_MON_LITE);
3275 else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !m_ptr->csleep)
3276 p_ptr->update |= (PU_MON_LITE);
3278 /* Update the monster */
3279 update_mon(c_ptr->m_idx, TRUE);
3282 /* Count the monsters on the level */
3283 real_r_ptr(m_ptr)->cur_num++;
3286 * Memorize location of the unique monster in saved floors.
3287 * A unique monster move from old saved floor.
3289 if (character_dungeon &&
3290 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)))
3291 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
3293 /* Hack -- Count the number of "reproducers" */
3294 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3297 /* Hack -- Notice new multi-hued monsters */
3299 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3300 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
3301 shimmer_monsters = TRUE;
3304 if (p_ptr->warning && character_dungeon)
3306 if (r_ptr->flags1 & RF1_UNIQUE)
3310 char o_name[MAX_NLEN];
3312 if (r_ptr->level > p_ptr->lev + 30)
3318 else if (r_ptr->level > p_ptr->lev + 15)
3324 else if (r_ptr->level > p_ptr->lev + 5)
3326 color = "¥ë¥Ó¡¼¿§¤Ë";
3330 else if (r_ptr->level > p_ptr->lev - 5)
3336 else if (r_ptr->level > p_ptr->lev - 15)
3338 color = "¥Ô¥ó¥¯¿§¤Ë";
3349 o_ptr = choose_warning_item();
3352 object_desc(o_name, o_ptr, FALSE, 0);
3354 msg_format("%s¤Ï%s¸÷¤Ã¤¿¡£", o_name, color);
3356 msg_format("%s glows %s.", o_name, color);
3362 msg_format("s%¸÷¤ëʪ¤¬Æ¬¤ËÉ⤫¤ó¤À¡£", color);
3364 msg_format("An %s image forms in your mind.");
3370 if (is_explosive_rune_grid(c_ptr))
3372 /* Break the ward */
3373 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3375 /* Describe observable breakage */
3376 if (c_ptr->info & CAVE_MARK)
3379 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3381 msg_print("The rune explodes!");
3384 project(0, 2, y, x, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
3390 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3392 msg_print("An explosive rune was disarmed.");
3396 /* Forget the rune */
3397 c_ptr->info &= ~(CAVE_MARK);
3399 /* Break the rune */
3400 c_ptr->info &= ~(CAVE_OBJECT);
3413 * improved version of scatter() for place monster
3416 #define MON_SCAT_MAXD 10
3418 static bool mon_scatter(int *yp, int *xp, int y, int x, int max_dist)
3420 int place_x[MON_SCAT_MAXD];
3421 int place_y[MON_SCAT_MAXD];
3422 int num[MON_SCAT_MAXD];
3426 if (max_dist >= MON_SCAT_MAXD)
3429 for (i = 0; i < MON_SCAT_MAXD; i++)
3432 for (nx = x - max_dist; nx <= x + max_dist; nx++)
3433 for (ny = y - max_dist; ny <= y + max_dist; ny++)
3435 /* Ignore annoying locations */
3436 if (!in_bounds(ny, nx)) continue;
3438 /* Require "line of sight" */
3439 if (!los(y, x, ny, nx)) continue;
3441 /* Walls and Monsters block flow */
3442 if (!cave_empty_bold2(ny, nx)) continue;
3443 if (cave[ny][nx].m_idx) continue;
3444 if (player_bold(ny, nx)) continue;
3446 /* ... nor on the Pattern */
3447 if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
3448 (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2))
3451 i = distance(y, x, ny, nx);
3467 while (i < MON_SCAT_MAXD && 0 == num[i])
3469 if (i >= MON_SCAT_MAXD)
3480 * Maximum size of a group of monsters
3482 #define GROUP_MAX 32
3486 * Attempt to place a "group" of monsters around the given location
3488 static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
3490 monster_race *r_ptr = &r_info[r_idx];
3493 int total = 0, extra = 0;
3497 byte hack_y[GROUP_MAX];
3498 byte hack_x[GROUP_MAX];
3501 /* Pick a group size */
3502 total = randint1(10);
3504 /* Hard monsters, small groups */
3505 if (r_ptr->level > dun_level)
3507 extra = r_ptr->level - dun_level;
3508 extra = 0 - randint1(extra);
3511 /* Easy monsters, large groups */
3512 else if (r_ptr->level < dun_level)
3514 extra = dun_level - r_ptr->level;
3515 extra = randint1(extra);
3518 /* Hack -- limit group reduction */
3519 if (extra > 9) extra = 9;
3521 /* Modify the group size */
3525 if (total < 1) total = 1;
3528 if (total > GROUP_MAX) total = GROUP_MAX;
3531 /* Save the rating */
3534 /* Start on the monster */
3539 /* Puddle monsters, breadth first, up to total */
3540 for (n = 0; (n < hack_n) && (hack_n < total); n++)
3542 /* Grab the location */
3546 /* Check each direction, up to total */
3547 for (i = 0; (i < 8) && (hack_n < total); i++)
3551 scatter(&my, &mx, hy, hx, 4, 0);
3553 /* Walls and Monsters block flow */
3554 if (!cave_empty_bold2(my, mx)) continue;
3556 /* Attempt to place another monster */
3557 if (place_monster_one(who, my, mx, r_idx, mode))
3559 /* Add it to the "hack" set */
3560 hack_y[hack_n] = my;
3561 hack_x[hack_n] = mx;
3567 /* Hack -- restore the rating */
3577 * Hack -- help pick an escort type
3579 static int place_monster_idx = 0;
3580 static int place_monster_m_idx = 0;
3583 * Hack -- help pick an escort type
3585 static bool place_monster_okay(int r_idx)
3587 monster_race *r_ptr = &r_info[place_monster_idx];
3588 monster_type *m_ptr = &m_list[place_monster_m_idx];
3590 monster_race *z_ptr = &r_info[r_idx];
3592 /* Hack - Escorts have to have the same dungeon flag */
3593 if (monster_dungeon(place_monster_idx) != monster_dungeon(r_idx)) return (FALSE);
3595 /* Require similar "race" */
3596 if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3598 /* Skip more advanced monsters */
3599 if (z_ptr->level > r_ptr->level) return (FALSE);
3601 /* Skip unique monsters */
3602 if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3604 /* Paranoia -- Skip identical monsters */
3605 if (place_monster_idx == r_idx) return (FALSE);
3607 /* Skip different alignment */
3608 if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3610 if (r_ptr->flags7 & RF7_FRIENDLY)
3612 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3615 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3624 * Attempt to place a monster of the given race at the given location
3626 * Note that certain monsters are now marked as requiring "friends".
3627 * These monsters, if successfully placed, and if the "grp" parameter
3628 * is TRUE, will be surrounded by a "group" of identical monsters.
3630 * Note that certain monsters are now marked as requiring an "escort",
3631 * which is a collection of monsters with similar "race" but lower level.
3633 * Some monsters induce a fake "group" flag on their escorts.
3635 * Note the "bizarre" use of non-recursion to prevent annoying output
3636 * when running a code profiler.
3638 * Note the use of the new "monster allocation table" code to restrict
3639 * the "get_mon_num()" function to "legal" escort types.
3641 bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
3644 monster_race *r_ptr = &r_info[r_idx];
3646 if (one_in_(333) && !(mode & PM_NO_KAGE) && !(mode & PM_FORCE_PET))
3651 /* Place one monster, or fail */
3652 if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3655 /* Require the "group" flag */
3656 if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3658 place_monster_m_idx = hack_m_idx_ii;
3660 /* Friends for certain monsters */
3661 if (r_ptr->flags1 & (RF1_FRIENDS))
3663 /* Attempt to place a group */
3664 (void)place_monster_group(who, y, x, r_idx, mode);
3668 /* Escorts for certain monsters */
3669 if (r_ptr->flags1 & (RF1_ESCORT))
3671 /* Set the escort index */
3672 place_monster_idx = r_idx;
3674 /* Try to place several "escorts" */
3675 for (i = 0; i < 32; i++)
3677 int nx, ny, z, d = 3;
3679 /* Pick a location */
3680 scatter(&ny, &nx, y, x, d, 0);
3682 /* Require empty grids */
3683 if (!cave_empty_bold2(ny, nx)) continue;
3685 /* Prepare allocation table */
3686 get_mon_num_prep(place_monster_okay, get_monster_hook2(ny, nx));
3688 /* Pick a random race */
3689 z = get_mon_num(r_ptr->level);
3691 /* Handle failure */
3694 /* Place a single escort */
3695 (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3697 /* Place a "group" of escorts if needed */
3698 if ((r_info[z].flags1 & RF1_FRIENDS) ||
3699 (r_ptr->flags1 & RF1_ESCORTS))
3701 /* Place a group of monsters */
3702 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3713 * Hack -- attempt to place a monster at the given location
3715 * Attempt to find a monster appropriate to the "monster_level"
3717 bool place_monster(int y, int x, u32b mode)
3721 /* Prepare allocation table */
3722 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3724 /* Pick a monster */
3725 r_idx = get_mon_num(monster_level);
3727 /* Handle failure */
3728 if (!r_idx) return (FALSE);
3730 /* Attempt to place the monster */
3731 if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3738 #ifdef MONSTER_HORDES
3740 bool alloc_horde(int y, int x)
3742 monster_race *r_ptr = NULL;
3745 int attempts = 1000;
3749 /* Prepare allocation table */
3750 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3754 /* Pick a monster */
3755 r_idx = get_mon_num(monster_level);
3757 /* Handle failure */
3758 if (!r_idx) return (FALSE);
3760 r_ptr = &r_info[r_idx];
3762 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3764 if (r_idx == MON_HAGURE) continue;
3767 if (attempts < 1) return FALSE;
3773 /* Attempt to place the monster */
3774 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3777 if (attempts < 1) return FALSE;
3779 m_idx = cave[y][x].m_idx;
3781 if (m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[m_list[m_idx].r_idx];
3782 summon_kin_type = r_ptr->d_char;
3784 for (attempts = randint1(10) + 5; attempts; attempts--)
3786 scatter(&cy, &cx, y, x, 5, 0);
3788 (void)summon_specific(m_idx, cy, cx, dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3797 #endif /* MONSTER_HORDES */
3803 bool alloc_guardian(void)
3805 int guardian = d_info[dungeon_type].final_guardian;
3807 if (guardian && (d_info[dungeon_type].maxdepth == dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3813 /* Find a good position */
3816 /* Get a random spot */
3817 oy = randint1(cur_hgt - 4) + 2;
3818 ox = randint1(cur_wid - 4) + 2;
3820 /* Is it a good spot ? */
3821 if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian]))
3823 /* Place the guardian */
3824 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3837 * Attempt to allocate a random monster in the dungeon.
3839 * Place the monster at least "dis" distance from the player.
3841 * Use "slp" to choose the initial "sleep" status
3843 * Use "monster_level" for the monster level
3845 bool alloc_monster(int dis, u32b mode)
3848 int attempts_left = 10000;
3850 /* Put the Guardian */
3851 if (alloc_guardian()) return TRUE;
3853 /* Find a legal, distant, unoccupied, space */
3854 while (attempts_left--)
3856 /* Pick a location */
3857 y = randint0(cur_hgt);
3858 x = randint0(cur_wid);
3860 /* Require empty floor grid (was "naked") */
3861 if (dun_level || (wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].terrain != TERRAIN_MOUNTAIN))
3863 if (!cave_empty_bold2(y, x)) continue;
3867 if (!cave_empty_bold2(y, x) && (cave[y][x].feat != FEAT_MOUNTAIN)) continue;
3870 /* Accept far away grids */
3871 if (distance(y, x, py, px) > dis) break;
3876 if (cheat_xtra || cheat_hear)
3879 msg_print("·Ù¹ð¡ª¿·¤¿¤Ê¥â¥ó¥¹¥¿¡¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡£¾®¤µ¤¤³¬¤Ç¤¹¤«¡©");
3881 msg_print("Warning! Could not allocate a new monster. Small level?");
3890 #ifdef MONSTER_HORDES
3891 if (randint1(5000) <= dun_level)
3893 if (alloc_horde(y, x))
3896 if (cheat_hear) msg_format("¥â¥ó¥¹¥¿¡¼¤ÎÂç·²(%c)", summon_kin_type);
3898 if (cheat_hear) msg_format("Monster horde (%c).", summon_kin_type);
3906 #endif /* MONSTER_HORDES */
3908 /* Attempt to place the monster, allow groups */
3909 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3911 #ifdef MONSTER_HORDES
3913 #endif /* MONSTER_HORDES */
3923 * Hack -- help decide if a monster race is "okay" to summon
3925 static bool summon_specific_okay(int r_idx)
3927 monster_race *r_ptr = &r_info[r_idx];
3929 /* Hack - Only summon dungeon monsters */
3930 if (!monster_dungeon(r_idx)) return (FALSE);
3932 /* Hack -- identify the summoning monster */
3933 if (summon_specific_who > 0)
3935 monster_type *m_ptr = &m_list[summon_specific_who];
3937 /* Do not summon enemies */
3939 /* Friendly vs. opposite aligned normal or pet */
3940 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3942 /* Hostile vs. non-hostile */
3943 if (is_hostile(m_ptr) != summon_specific_hostile) return FALSE;
3945 /* Use the player's alignment */
3946 else if (summon_specific_who < 0)
3948 /* Do not summon enemies of the pets */
3949 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3951 if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3955 /* Hack -- no specific type specified */
3956 if (!summon_specific_type) return (TRUE);
3958 if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7))) return FALSE;
3960 if ((summon_specific_who < 0) &&
3961 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
3962 monster_has_hostile_align(NULL, 10, -10, r_ptr))
3965 if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
3967 return (summon_specific_aux(r_idx));
3972 * Place a monster (of the specified "type") near the given
3973 * location. Return TRUE if a monster was actually summoned.
3975 * We will attempt to place the monster up to 10 times before giving up.
3977 * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3978 * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3979 * Note: None of the other summon codes will ever summon Unique's.
3981 * This function has been changed. We now take the "monster level"
3982 * of the summoning monster as a parameter, and use that, along with
3983 * the current dungeon level, to help determine the level of the
3984 * desired monster. Note that this is an upper bound, and also
3985 * tends to "prefer" monsters of that level. Currently, we use
3986 * the average of the dungeon and monster levels, and then add
3987 * five to allow slight increases in monster power.
3989 * Note that we use the new "monster allocation table" creation code
3990 * to restrict the "get_mon_num()" function to the set of "legal"
3991 * monsters, making this function much faster and more reliable.
3993 * Note that this function may not succeed, though this is very rare.
3995 bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
3999 if (p_ptr->inside_arena) return (FALSE);
4001 if (!mon_scatter(&y, &x, y1, x1, 2)) return FALSE;
4003 /* Save the summoner */
4004 summon_specific_who = who;
4006 /* Save the "summon" type */
4007 summon_specific_type = type;
4009 summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
4011 /* Save the hostility */
4012 summon_specific_hostile = (!(mode & PM_FORCE_FRIENDLY) && !(is_friendly_idx(who)) && !(mode & PM_FORCE_PET));
4014 /* Prepare allocation table */
4015 get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
4017 /* Pick a monster, using the level calculation */
4018 r_idx = get_mon_num((dun_level + lev) / 2 + 5);
4020 /* Handle failure */
4023 summon_specific_type = 0;
4027 if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
4029 /* Attempt to place the monster (awake, allow groups) */
4030 if (!place_monster_aux(who, y, x, r_idx, mode))
4032 summon_specific_type = 0;
4036 summon_specific_type = 0;
4041 /* A "dangerous" function, creates a pet of the specified type */
4042 bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
4047 /* if (!r_idx) return; */
4049 /* Prevent illegal monsters */
4050 if (r_idx >= max_r_idx) return FALSE;
4052 if (p_ptr->inside_arena) return FALSE;
4054 if (!mon_scatter(&y, &x, oy, ox, 2)) return FALSE;
4056 /* Place it (allow groups) */
4057 return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
4062 * Let the given monster attempt to reproduce.
4064 * Note that "reproduction" REQUIRES empty space.
4066 bool multiply_monster(int m_idx, bool clone, u32b mode)
4068 monster_type *m_ptr = &m_list[m_idx];
4072 if (!mon_scatter(&y, &x, m_ptr->fy, m_ptr->fx, 1))
4075 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4077 /* Create a new monster (awake, no groups) */
4078 if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE)))
4083 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4084 m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
4087 /* Hack -- Shadower spawns Shadower */
4088 if (m_ptr->mflag2 & MFLAG2_KAGE) m_list[hack_m_idx_ii].mflag2 |= MFLAG2_KAGE;
4090 /* Hack -- Appearance transfer */
4091 if (!is_original_ap(m_ptr)) m_list[hack_m_idx_ii].ap_r_idx = m_ptr->ap_r_idx;
4101 * Dump a message describing a monster's reaction to damage
4103 * Technically should attempt to treat "Beholder"'s as jelly's
4105 void message_pain(int m_idx, int dam)
4107 long oldhp, newhp, tmp;
4110 monster_type *m_ptr = &m_list[m_idx];
4111 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4116 /* Get the monster name */
4117 monster_desc(m_name, m_ptr, 0);
4119 /* Notice non-damage */
4123 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Æ¤¤¤Ê¤¤¡£", m_name);
4125 msg_format("%^s is unharmed.", m_name);
4131 /* Note -- subtle fix -CFT */
4132 newhp = (long)(m_ptr->hp);
4133 oldhp = newhp + (long)(dam);
4134 tmp = (newhp * 100L) / oldhp;
4135 percentage = (int)(tmp);
4138 /* Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs */
4139 if (strchr(",ejmvwQ", r_ptr->d_char))
4142 if (percentage > 95)
4143 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4144 else if (percentage > 75)
4145 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4146 else if (percentage > 50)
4147 msg_format("%^s¤Ï½Ì¤³¤Þ¤Ã¤¿¡£", m_name);
4148 else if (percentage > 35)
4149 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4150 else if (percentage > 20)
4151 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4152 else if (percentage > 10)
4153 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4155 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4157 if (percentage > 95)
4158 msg_format("%^s barely notices.", m_name);
4159 else if (percentage > 75)
4160 msg_format("%^s flinches.", m_name);
4161 else if (percentage > 50)
4162 msg_format("%^s squelches.", m_name);
4163 else if (percentage > 35)
4164 msg_format("%^s quivers in pain.", m_name);
4165 else if (percentage > 20)
4166 msg_format("%^s writhes about.", m_name);
4167 else if (percentage > 10)
4168 msg_format("%^s writhes in agony.", m_name);
4170 msg_format("%^s jerks limply.", m_name);
4177 else if (strchr("l", r_ptr->d_char))
4179 if (percentage > 95)
4181 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4183 msg_format("%^s barely notices.", m_name);
4185 else if (percentage > 75)
4187 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4189 msg_format("%^s flinches.", m_name);
4191 else if (percentage > 50)
4193 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4195 msg_format("%^s hesitates.", m_name);
4197 else if (percentage > 35)
4199 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4201 msg_format("%^s quivers in pain.", m_name);
4203 else if (percentage > 20)
4205 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4207 msg_format("%^s writhes about.", m_name);
4209 else if (percentage > 10)
4211 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4213 msg_format("%^s writhes in agony.", m_name);
4217 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4219 msg_format("%^s jerks limply.", m_name);
4224 /* Golems, Walls, Doors, Stairs */
4225 else if (strchr("g#+<>", r_ptr->d_char))
4227 if (percentage > 95)
4229 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4231 msg_format("%^s ignores the attack.", m_name);
4233 else if (percentage > 75)
4235 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4237 msg_format("%^s shrugs off the attack.", m_name);
4239 else if (percentage > 50)
4241 msg_format("%^s¤ÏÍëÌĤΤ褦¤ËËʤ¨¤¿¡£", m_name);
4243 msg_format("%^s roars thunderously.", m_name);
4245 else if (percentage > 35)
4247 msg_format("%^s¤Ï¶ì¤·¤²¤ËËʤ¨¤¿¡£", m_name);
4249 msg_format("%^s rumbles.", m_name);
4251 else if (percentage > 20)
4253 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4255 msg_format("%^s grunts.", m_name);
4257 else if (percentage > 10)
4259 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4261 msg_format("%^s hesitates.", m_name);
4265 msg_format("%^s¤Ï¤¯¤·¤ã¤¯¤·¤ã¤Ë¤Ê¤Ã¤¿¡£", m_name);
4267 msg_format("%^s crumples.", m_name);
4272 /* Snakes, Hydrae, Reptiles, Mimics */
4273 else if (strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char))
4275 if (percentage > 95)
4277 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4279 msg_format("%^s barely notices.", m_name);
4281 else if (percentage > 75)
4283 msg_format("%^s¤Ï¥·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4285 msg_format("%^s hisses.", m_name);
4287 else if (percentage > 50)
4289 msg_format("%^s¤ÏÅܤäÆƬ¤ò¾å¤²¤¿¡£", m_name);
4291 msg_format("%^s rears up in anger.", m_name);
4293 else if (percentage > 35)
4295 msg_format("%^s¤ÏÌÔÁ³¤È°Ò³Å¤·¤¿¡£", m_name);
4297 msg_format("%^s hisses furiously.", m_name);
4299 else if (percentage > 20)
4301 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4303 msg_format("%^s writhes about.", m_name);
4305 else if (percentage > 10)
4307 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4309 msg_format("%^s writhes in agony.", m_name);
4313 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4315 msg_format("%^s jerks limply.", m_name);
4321 else if (strchr("f", r_ptr->d_char))
4323 if (percentage > 95)
4325 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4327 msg_format("%^s shrugs off the attack.", m_name);
4329 else if (percentage > 75)
4331 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4333 msg_format("%^s roars.", m_name);
4335 else if (percentage > 50)
4337 msg_format("%^s¤ÏÅܤäÆËʤ¨¤¿¡£", m_name);
4339 msg_format("%^s growls angrily.", m_name);
4341 else if (percentage > 35)
4343 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4345 msg_format("%^s hisses with pain.", m_name);
4347 else if (percentage > 20)
4349 msg_format("%^s¤ÏÄˤߤǼ塹¤·¤¯ÌĤ¤¤¿¡£", m_name);
4351 msg_format("%^s mewls in pain.", m_name);
4353 else if (percentage > 10)
4355 msg_format("%^s¤Ï¶ìÄˤˤ¦¤á¤¤¤¿¡£", m_name);
4357 msg_format("%^s hisses in agony.", m_name);
4361 msg_format("%s¤Ï°¥¤ì¤ÊÌĤÀ¼¤ò½Ð¤·¤¿¡£", m_name);
4363 msg_format("%^s mewls pitifully.", m_name);
4368 /* Ants, Centipedes, Flies, Insects, Beetles, Spiders */
4369 else if (strchr("acFIKS", r_ptr->d_char))
4371 if (percentage > 95)
4373 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4375 msg_format("%^s ignores the attack.", m_name);
4377 else if (percentage > 75)
4379 msg_format("%^s¤Ï¥¡¼¥¡¼ÌĤ¤¤¿¡£", m_name);
4381 msg_format("%^s chitters.", m_name);
4384 else if (percentage > 50)
4386 msg_format("%^s¤Ï¥è¥í¥è¥íƨ¤²²ó¤Ã¤¿¡£", m_name);
4388 msg_format("%^s scuttles about.", m_name);
4391 else if (percentage > 35)
4393 msg_format("%^s¤Ï¤¦¤ë¤µ¤¯ÌĤ¤¤¿¡£", m_name);
4395 msg_format("%^s twitters.", m_name);
4398 else if (percentage > 20)
4400 msg_format("%^s¤ÏÄˤߤËáÛÚ»¤·¤¿¡£", m_name);
4402 msg_format("%^s jerks in pain.", m_name);
4405 else if (percentage > 10)
4407 msg_format("%^s¤Ï¶ìÄˤÇáÛÚ»¤·¤¿¡£", m_name);
4409 msg_format("%^s jerks in agony.", m_name);
4414 msg_format("%^s¤Ï¥Ô¥¯¥Ô¥¯¤Ò¤¤Ä¤Ã¤¿¡£", m_name);
4416 msg_format("%^s twitches.", m_name);
4423 else if (strchr("B", r_ptr->d_char))
4425 if (percentage > 95)
4427 msg_format("%^s¤Ï¤µ¤¨¤º¤Ã¤¿¡£", m_name);
4429 msg_format("%^s chirps.", m_name);
4432 else if (percentage > 75)
4434 msg_format("%^s¤Ï¥Ô¡¼¥Ô¡¼ÌĤ¤¤¿¡£", m_name);
4436 msg_format("%^s twitters.", m_name);
4439 else if (percentage > 50)
4441 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤¤¿¡£", m_name);
4443 msg_format("%^s squawks.", m_name);
4446 else if (percentage > 35)
4448 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4450 msg_format("%^s chatters.", m_name);
4453 else if (percentage > 20)
4455 msg_format("%^s¤Ï¶ì¤·¤ó¤À¡£", m_name);
4457 msg_format("%^s jeers.", m_name);
4460 else if (percentage > 10)
4462 msg_format("%^s¤Ï¤Î¤¿¤¦¤Á²ó¤Ã¤¿¡£", m_name);
4464 msg_format("%^s flutters about.", m_name);
4469 msg_format("%^s¤Ï¥¡¼¥¡¼¤ÈÌĤ¶«¤ó¤À¡£", m_name);
4471 msg_format("%^s squeaks.", m_name);
4477 /* Dragons, Demons, High Undead */
4478 else if (strchr("duDLUW", r_ptr->d_char))
4480 if (percentage > 95)
4482 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4484 msg_format("%^s ignores the attack.", m_name);
4487 else if (percentage > 75)
4489 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4491 msg_format("%^s flinches.", m_name);
4494 else if (percentage > 50)
4496 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4498 msg_format("%^s hisses in pain.", m_name);
4501 else if (percentage > 35)
4503 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4505 msg_format("%^s snarls with pain.", m_name);
4508 else if (percentage > 20)
4510 msg_format("%^s¤ÏÄˤߤËËʤ¨¤¿¡£", m_name);
4512 msg_format("%^s roars with pain.", m_name);
4515 else if (percentage > 10)
4517 msg_format("%^s¤Ï¶ì¤·¤²¤Ë¶«¤ó¤À¡£", m_name);
4519 msg_format("%^s gasps.", m_name);
4524 msg_format("%^s¤Ï¼å¡¹¤·¤¯¤¦¤Ê¤Ã¤¿¡£", m_name);
4526 msg_format("%^s snarls feebly.", m_name);
4533 else if (strchr("s", r_ptr->d_char))
4535 if (percentage > 95)
4537 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4539 msg_format("%^s ignores the attack.", m_name);
4542 else if (percentage > 75)
4544 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4546 msg_format("%^s shrugs off the attack.", m_name);
4549 else if (percentage > 50)
4551 msg_format("%^s¤Ï¥«¥¿¥«¥¿¤È¾Ð¤Ã¤¿¡£", m_name);
4553 msg_format("%^s rattles.", m_name);
4556 else if (percentage > 35)
4558 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4560 msg_format("%^s stumbles.", m_name);
4563 else if (percentage > 20)
4565 msg_format("%^s¤Ï¥«¥¿¥«¥¿¸À¤Ã¤¿¡£", m_name);
4567 msg_format("%^s rattles.", m_name);
4570 else if (percentage > 10)
4572 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4574 msg_format("%^s staggers.", m_name);
4579 msg_format("%^s¤Ï¥¬¥¿¥¬¥¿¸À¤Ã¤¿¡£", m_name);
4581 msg_format("%^s clatters.", m_name);
4588 else if (strchr("z", r_ptr->d_char))
4590 if (percentage > 95)
4592 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4594 msg_format("%^s ignores the attack.", m_name);
4597 else if (percentage > 75)
4599 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4601 msg_format("%^s shrugs off the attack.", m_name);
4604 else if (percentage > 50)
4606 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4608 msg_format("%^s groans.", m_name);
4611 else if (percentage > 35)
4613 msg_format("%s¤Ï¶ì¤·¤²¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4615 msg_format("%^s moans.", m_name);
4618 else if (percentage > 20)
4620 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4622 msg_format("%^s hesitates.", m_name);
4625 else if (percentage > 10)
4627 msg_format("%^s¤Ï¤¦¤Ê¤Ã¤¿¡£", m_name);
4629 msg_format("%^s grunts.", m_name);
4634 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4636 msg_format("%^s staggers.", m_name);
4643 else if (strchr("G", r_ptr->d_char))
4646 if (percentage > 95)
4648 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4650 msg_format("%^s ignores the attack.", m_name);
4653 else if (percentage > 75)
4655 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4657 msg_format("%^s shrugs off the attack.", m_name);
4660 else if (percentage > 50)
4662 msg_format("%s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4664 msg_format("%^s moans.", m_name);
4667 else if (percentage > 35)
4669 msg_format("%^s¤Ïµã¤¤ï¤á¤¤¤¿¡£", m_name);
4671 msg_format("%^s wails.", m_name);
4674 else if (percentage > 20)
4676 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4678 msg_format("%^s howls.", m_name);
4681 else if (percentage > 10)
4683 msg_format("%s¤Ï¼å¡¹¤·¤¯¤¦¤á¤¤¤¿¡£", m_name);
4685 msg_format("%^s moans softly.", m_name);
4690 msg_format("%^s¤Ï¤«¤¹¤«¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4692 msg_format("%^s sighs.", m_name);
4698 /* Dogs and Hounds */
4699 else if (strchr("CZ", r_ptr->d_char))
4702 if (percentage > 95)
4703 msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4704 else if (percentage > 75)
4705 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4706 else if (percentage > 50)
4707 msg_format("%^s¤ÏÄˤߤǥ¥ã¥ó¥¥ã¥óËʤ¨¤¿¡£", m_name);
4708 else if (percentage > 35)
4709 msg_format("%^s¤ÏÄˤߤÇÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4710 else if (percentage > 20)
4711 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4712 else if (percentage > 10)
4713 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4715 msg_format("%^s¤Ï¼å¡¹¤·¤¯Ëʤ¨¤¿¡£", m_name);
4717 if (percentage > 95)
4718 msg_format("%^s shrugs off the attack.", m_name);
4719 else if (percentage > 75)
4720 msg_format("%^s snarls with pain.", m_name);
4721 else if (percentage > 50)
4722 msg_format("%^s yelps in pain.", m_name);
4723 else if (percentage > 35)
4724 msg_format("%^s howls in pain.", m_name);
4725 else if (percentage > 20)
4726 msg_format("%^s howls in agony.", m_name);
4727 else if (percentage > 10)
4728 msg_format("%^s writhes in agony.", m_name);
4730 msg_format("%^s yelps feebly.", m_name);
4735 /* One type of monsters (ignore,squeal,shriek) */
4736 else if (strchr("Xbilqrt", r_ptr->d_char))
4739 if (percentage > 95)
4740 msg_format("%^s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4741 else if (percentage > 75)
4742 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4743 else if (percentage > 50)
4744 msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4745 else if (percentage > 35)
4746 msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4747 else if (percentage > 20)
4748 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4749 else if (percentage > 10)
4750 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4752 msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4754 if (percentage > 95)
4755 msg_format("%^s ignores the attack.", m_name);
4756 else if (percentage > 75)
4757 msg_format("%^s grunts with pain.", m_name);
4758 else if (percentage > 50)
4759 msg_format("%^s squeals in pain.", m_name);
4760 else if (percentage > 35)
4761 msg_format("%^s shrieks in pain.", m_name);
4762 else if (percentage > 20)
4763 msg_format("%^s shrieks in agony.", m_name);
4764 else if (percentage > 10)
4765 msg_format("%^s writhes in agony.", m_name);
4767 msg_format("%^s cries out feebly.", m_name);
4772 /* Another type of monsters (shrug,cry,scream) */
4776 if (percentage > 95)
4777 msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4778 else if (percentage > 75)
4779 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4780 else if (percentage > 50)
4781 msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4782 else if (percentage > 35)
4783 msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4784 else if (percentage > 20)
4785 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4786 else if (percentage > 10)
4787 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4789 msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4791 if (percentage > 95)
4792 msg_format("%^s shrugs off the attack.", m_name);
4793 else if (percentage > 75)
4794 msg_format("%^s grunts with pain.", m_name);
4795 else if (percentage > 50)
4796 msg_format("%^s cries out in pain.", m_name);
4797 else if (percentage > 35)
4798 msg_format("%^s screams in pain.", m_name);
4799 else if (percentage > 20)
4800 msg_format("%^s screams in agony.", m_name);
4801 else if (percentage > 10)
4802 msg_format("%^s writhes in agony.", m_name);
4804 msg_format("%^s cries out feebly.", m_name);
4812 * Learn about an "observed" resistance.
4814 void update_smart_learn(int m_idx, int what)
4816 #ifdef DRS_SMART_OPTIONS
4818 monster_type *m_ptr = &m_list[m_idx];
4820 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4823 /* Not allowed to learn */
4824 if (!smart_learn) return;
4826 /* Too stupid to learn anything */
4827 if (r_ptr->flags2 & (RF2_STUPID)) return;
4829 /* Not intelligent, only learn sometimes */
4830 if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4835 /* Analyze the knowledge */
4839 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4840 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
4841 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4845 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4846 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
4847 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4851 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4852 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
4853 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4857 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4858 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
4859 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4863 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4864 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
4869 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4873 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4877 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4881 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4885 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4889 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4893 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4897 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4901 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4905 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4909 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4913 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4917 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4921 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4925 #endif /* DRS_SMART_OPTIONS */
4931 * Place the player in the dungeon XXX XXX
4933 bool player_place(int y, int x)
4935 /* Paranoia XXX XXX */
4936 if (cave[y][x].m_idx != 0) return FALSE;
4938 /* Save player location */
4948 * Drop all items carried by a monster
4950 void monster_drop_carried_objects(monster_type *m_ptr)
4952 s16b this_o_idx, next_o_idx = 0;
4958 /* Drop objects being carried */
4959 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4961 /* Acquire object */
4962 o_ptr = &o_list[this_o_idx];
4964 /* Acquire next object */
4965 next_o_idx = o_ptr->next_o_idx;
4967 /* Get local object */
4970 /* Copy the object */
4971 object_copy(q_ptr, o_ptr);
4973 /* Forget monster */
4974 q_ptr->held_m_idx = 0;
4976 /* Delete the object */
4977 delete_object_idx(this_o_idx);
4980 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4983 /* Forget objects */
4984 m_ptr->hold_o_idx = 0;