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;
248 /* Hack -- efficiency */
249 o_ptr->held_m_idx = 0;
251 /* Delete the object */
252 delete_object_idx(this_o_idx);
256 /* Wipe the Monster */
257 (void)WIPE(m_ptr, monster_type);
265 /* Update some things */
266 p_ptr->update |= (PU_MON_LITE);
271 * Delete the monster, if any, at a given location
273 void delete_monster(int y, int x)
278 if (!in_bounds(y, x)) return;
283 /* Delete the monster (if any) */
284 if (c_ptr->m_idx) delete_monster_idx(c_ptr->m_idx);
289 * Move an object from index i1 to index i2 in the object list
291 static void compact_monsters_aux(int i1, int i2)
299 s16b this_o_idx, next_o_idx = 0;
303 if (i1 == i2) return;
316 /* Update the cave */
319 /* Repair objects being carried by monster */
320 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
325 o_ptr = &o_list[this_o_idx];
327 /* Acquire next object */
328 next_o_idx = o_ptr->next_o_idx;
330 /* Reset monster pointer */
331 o_ptr->held_m_idx = i2;
334 /* Hack -- Update the target */
335 if (target_who == i1) target_who = i2;
337 /* Hack -- Update the target */
338 if (pet_t_m_idx == i1) pet_t_m_idx = i2;
339 if (riding_t_m_idx == i1) riding_t_m_idx = i2;
341 /* Hack -- Update the riding */
342 if (p_ptr->riding == i1) p_ptr->riding = i2;
344 /* Hack -- Update the health bar */
345 if (p_ptr->health_who == i1) health_track(i2);
348 COPY(&m_list[i2], &m_list[i1], monster_type);
351 (void)WIPE(&m_list[i1], monster_type);
357 * Compact and Reorder the monster list
359 * This function can be very dangerous, use with caution!
361 * When actually "compacting" monsters, we base the saving throw
362 * on a combination of monster level, distance from player, and
363 * current "desperation".
365 * After "compacting" (if needed), we "reorder" the monsters into a more
366 * compact order, and we reset the allocation info, and the "live" array.
368 void compact_monsters(int size)
371 int cur_lev, cur_dis, chance;
373 /* Message (only if compacting) */
375 if (size) msg_print("¥â¥ó¥¹¥¿¡¼¾ðÊó¤ò°µ½Ì¤·¤Æ¤¤¤Þ¤¹...");
377 if (size) msg_print("Compacting monsters...");
381 /* Compact at least 'size' objects */
382 for (num = 0, cnt = 1; num < size; cnt++)
384 /* Get more vicious each iteration */
387 /* Get closer each iteration */
388 cur_dis = 5 * (20 - cnt);
390 /* Check all the monsters */
391 for (i = 1; i < m_max; i++)
393 monster_type *m_ptr = &m_list[i];
395 monster_race *r_ptr = &r_info[m_ptr->r_idx];
397 /* Paranoia -- skip "dead" monsters */
398 if (!m_ptr->r_idx) continue;
400 /* Hack -- High level monsters start out "immune" */
401 if (r_ptr->level > cur_lev) continue;
403 if (i == p_ptr->riding) continue;
405 /* Ignore nearby monsters */
406 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
408 /* Saving throw chance */
411 /* Only compact "Quest" Monsters in emergencies */
412 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
414 /* Try not to compact Unique Monsters */
415 if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
417 /* All monsters get a saving throw */
418 if (randint0(100) < chance) continue;
420 /* Delete the monster */
421 delete_monster_idx(i);
423 /* Count the monster */
429 /* Excise dead monsters (backwards!) */
430 for (i = m_max - 1; i >= 1; i--)
432 /* Get the i'th monster */
433 monster_type *m_ptr = &m_list[i];
435 /* Skip real monsters */
436 if (m_ptr->r_idx) continue;
438 /* Move last monster into open hole */
439 compact_monsters_aux(m_max - 1, i);
441 /* Compress "m_max" */
448 * Pre-calculate the racial counters of preserved pets
449 * To prevent multiple generation of unique monster who is the minion of player
451 void precalc_cur_num_of_pet(void)
455 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
457 for (i = 0; i < max_num; i++)
459 m_ptr = &party_mon[i];
461 /* Skip empty monsters */
462 if (!m_ptr->r_idx) continue;
464 /* Hack -- Increase the racial counter */
465 real_r_ptr(m_ptr)->cur_num++;
471 * Delete/Remove all the monsters when the player leaves the level
473 * This is an efficient method of simulating multiple calls to the
474 * "delete_monster()" function, with no visual effects.
476 void wipe_m_list(void)
480 /* Hack -- if Banor or Lupart dies, stay another dead */
481 if (!r_info[MON_BANORLUPART].max_num)
483 if (r_info[MON_BANOR].max_num)
485 r_info[MON_BANOR].max_num = 0;
486 r_info[MON_BANOR].r_pkills++;
487 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
489 if (r_info[MON_LUPART].max_num)
491 r_info[MON_LUPART].max_num = 0;
492 r_info[MON_LUPART].r_pkills++;
493 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
497 /* Delete all the monsters */
498 for (i = m_max - 1; i >= 1; i--)
500 monster_type *m_ptr = &m_list[i];
502 /* Skip dead monsters */
503 if (!m_ptr->r_idx) continue;
505 /* Monster is gone */
506 cave[m_ptr->fy][m_ptr->fx].m_idx = 0;
508 /* Wipe the Monster */
509 (void)WIPE(m_ptr, monster_type);
514 * Wiping racial counters of all monsters and incrementing of racial
515 * counters of monsters in party_mon[] is required to prevent multiple
516 * generation of unique monster who is the minion of player.
519 /* Hack -- Wipe the racial counter of all monster races */
520 for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
522 /* Hack -- Increase the racial counters of pets */
523 precalc_cur_num_of_pet();
531 /* Hack -- reset "reproducer" count */
534 /* Hack -- no more target */
539 /* Hack -- no more tracking */
545 * Acquires and returns the index of a "free" monster.
547 * This routine should almost never fail, but it *can* happen.
554 /* Normal allocation */
555 if (m_max < max_m_idx)
557 /* Access the next hole */
560 /* Expand the array */
566 /* Return the index */
571 /* Recycle dead monsters */
572 for (i = 1; i < m_max; i++)
576 /* Acquire monster */
579 /* Skip live monsters */
580 if (m_ptr->r_idx) continue;
585 /* Use this monster */
590 /* Warn the player (except during dungeon creation) */
592 if (character_dungeon) msg_print("¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë¡ª");
594 if (character_dungeon) msg_print("Too many monsters!");
598 /* Try not to crash */
606 * Hack -- the "type" of the current "summon specific"
608 static int summon_specific_type = 0;
612 * Hack -- the index of the summoning monster
614 static int summon_specific_who = -1;
618 * Hack -- the hostility of the summoned monster
620 static bool summon_specific_hostile = TRUE;
622 static bool summon_unique_okay = FALSE;
625 static bool summon_specific_aux(int r_idx)
627 monster_race *r_ptr = &r_info[r_idx];
630 /* Check our requirements */
631 switch (summon_specific_type)
635 okay = (r_ptr->d_char == 'a');
641 okay = (r_ptr->d_char == 'S');
647 okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
653 okay = (r_ptr->d_char == 'M');
659 okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
665 okay = (r_ptr->flags3 & RF3_DEMON);
671 okay = (r_ptr->flags3 & RF3_UNDEAD);
677 okay = (r_ptr->flags3 & RF3_DRAGON);
681 case SUMMON_HI_UNDEAD:
683 okay = ((r_ptr->d_char == 'L') ||
684 (r_ptr->d_char == 'V') ||
685 (r_ptr->d_char == 'W'));
689 case SUMMON_HI_DRAGON:
691 okay = (r_ptr->d_char == 'D');
695 case SUMMON_HI_DEMON:
697 okay = (((r_ptr->d_char == 'U') ||
698 (r_ptr->d_char == 'H') ||
699 (r_ptr->d_char == 'B')) &&
700 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
704 case SUMMON_AMBERITES:
706 okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
712 okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
716 case SUMMON_BIZARRE1:
718 okay = (r_ptr->d_char == 'm');
721 case SUMMON_BIZARRE2:
723 okay = (r_ptr->d_char == 'b');
726 case SUMMON_BIZARRE3:
728 okay = (r_ptr->d_char == 'Q');
732 case SUMMON_BIZARRE4:
734 okay = (r_ptr->d_char == 'v');
738 case SUMMON_BIZARRE5:
740 okay = (r_ptr->d_char == '$');
744 case SUMMON_BIZARRE6:
746 okay = ((r_ptr->d_char == '!') ||
747 (r_ptr->d_char == '?') ||
748 (r_ptr->d_char == '=') ||
749 (r_ptr->d_char == '$') ||
750 (r_ptr->d_char == '|'));
756 okay = (r_ptr->d_char == 'g');
762 okay = ((r_ptr->d_char == 'U') &&
763 (r_ptr->flags4 & RF4_ROCKET));
770 okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
776 okay = (r_idx == MON_DAWN);
782 okay = (r_ptr->flags3 & (RF3_ANIMAL));
786 case SUMMON_ANIMAL_RANGER:
788 okay = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
789 (strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
790 !(r_ptr->flags3 & (RF3_DRAGON)) &&
791 !(r_ptr->flags3 & (RF3_EVIL)) &&
792 !(r_ptr->flags3 & (RF3_UNDEAD)) &&
793 !(r_ptr->flags3 & (RF3_DEMON)) &&
794 !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
795 !(r_ptr->flags4 || r_ptr->flags5 || r_ptr->flags6));
799 case SUMMON_HI_DRAGON_LIVING:
801 okay = ((r_ptr->d_char == 'D') && monster_living(r_ptr));
807 okay = monster_living(r_ptr);
813 okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
817 case SUMMON_BLUE_HORROR:
819 okay = (r_idx == MON_BLUE_HORROR);
823 case SUMMON_ELEMENTAL:
825 okay = (r_ptr->d_char == 'E');
831 okay = (r_ptr->d_char == 'v');
837 okay = (r_ptr->d_char == 'H');
843 okay = (r_ptr->d_char == 'B');
847 case SUMMON_KAMIKAZE:
850 for (i = 0; i < 4; i++)
851 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
855 case SUMMON_KAMIKAZE_LIVING:
859 for (i = 0; i < 4; i++)
860 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
861 okay = (okay && monster_living(r_ptr));
867 okay = (r_idx == MON_MANES);
873 okay = (r_idx == MON_LOUSE);
877 case SUMMON_GUARDIANS:
879 okay = (r_ptr->flags7 & RF7_GUARDIAN);
885 okay = ((r_idx == MON_NOV_PALADIN) ||
886 (r_idx == MON_NOV_PALADIN_G) ||
887 (r_idx == MON_PALADIN) ||
888 (r_idx == MON_W_KNIGHT) ||
889 (r_idx == MON_ULTRA_PALADIN) ||
890 (r_idx == MON_KNI_TEMPLAR));
896 okay = (r_ptr->d_char == 'B' &&
897 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
898 (r_ptr->flags8 & RF8_WILD_ONLY));
902 case SUMMON_PIRANHAS:
904 okay = (r_idx == MON_PIRANHA);
908 case SUMMON_ARMAGE_GOOD:
910 okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
914 case SUMMON_ARMAGE_EVIL:
916 okay = ((r_ptr->flags3 & RF3_DEMON) ||
917 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
923 /* Since okay is int, "return (okay);" is not correct. */
924 return (bool)(okay ? TRUE : FALSE);
928 static int chameleon_change_m_idx = 0;
932 * Some dungeon types restrict the possible monsters.
933 * Return TRUE is the monster is OK and FALSE otherwise
935 static bool restrict_monster_to_dungeon(int r_idx)
937 dungeon_info_type *d_ptr = &d_info[dungeon_type];
938 monster_race *r_ptr = &r_info[r_idx];
941 if (d_ptr->flags1 & DF1_CHAMELEON)
943 if (chameleon_change_m_idx) return TRUE;
945 if (d_ptr->flags1 & DF1_NO_MAGIC)
947 if (r_idx != MON_CHAMELEON &&
949 !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
950 !(r_ptr->flags5 & RF5_NOMAGIC_MASK) &&
951 !(r_ptr->flags6 & RF6_NOMAGIC_MASK))
954 if (d_ptr->flags1 & DF1_NO_MELEE)
956 if (r_idx == MON_CHAMELEON) return TRUE;
957 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
958 !(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)) &&
959 !(r_ptr->flags6 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
962 if (d_ptr->flags1 & DF1_BEGINNER)
964 if (r_ptr->level > dun_level)
968 if (d_ptr->special_div >= 64) return TRUE;
969 if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
973 case DUNGEON_MODE_AND:
976 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
981 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
986 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
991 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
996 if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
1001 if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
1006 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1011 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1016 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1021 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1024 for (a = 0; a < 5; a++)
1025 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
1029 case DUNGEON_MODE_NAND:
1032 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
1037 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
1042 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
1047 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
1052 if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
1057 if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
1062 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1067 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1072 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1077 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1080 for (a = 0; a < 5; a++)
1081 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
1085 case DUNGEON_MODE_OR:
1086 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
1087 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
1088 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
1089 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
1090 if (r_ptr->flags5 & d_ptr->mflags5) return TRUE;
1091 if (r_ptr->flags6 & d_ptr->mflags6) return TRUE;
1092 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
1093 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
1094 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
1095 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
1096 for (a = 0; a < 5; a++)
1097 if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
1101 case DUNGEON_MODE_NOR:
1102 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
1103 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
1104 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
1105 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
1106 if (r_ptr->flags5 & d_ptr->mflags5) return FALSE;
1107 if (r_ptr->flags6 & d_ptr->mflags6) return FALSE;
1108 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
1109 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
1110 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
1111 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
1112 for (a = 0; a < 5; a++)
1113 if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1122 * Apply a "monster restriction function" to the "monster allocation table"
1124 errr get_mon_num_prep(monster_hook_type monster_hook,
1125 monster_hook_type monster_hook2)
1129 /* Todo: Check the hooks for non-changes */
1131 /* Set the new hooks */
1132 get_mon_num_hook = monster_hook;
1133 get_mon_num2_hook = monster_hook2;
1135 /* Scan the allocation table */
1136 for (i = 0; i < alloc_race_size; i++)
1138 monster_race *r_ptr;
1141 alloc_entry *entry = &alloc_race_table[i];
1144 r_ptr = &r_info[entry->index];
1146 /* Skip monsters which don't pass the restriction */
1147 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1148 (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1151 if (!p_ptr->inside_battle && !chameleon_change_m_idx &&
1152 summon_specific_type != SUMMON_GUARDIANS)
1154 /* Hack -- don't create questors */
1155 if (r_ptr->flags1 & RF1_QUESTOR)
1158 if (r_ptr->flags7 & RF7_GUARDIAN)
1161 /* Depth Monsters never appear out of depth */
1162 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1163 (r_ptr->level > dun_level))
1167 /* Accept this monster */
1168 entry->prob2 = entry->prob1;
1170 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)
1172 int hoge = entry->prob2 * d_info[dungeon_type].special_div;
1173 entry->prob2 = hoge / 64;
1174 if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1183 static int mysqrt(int n)
1221 * Choose a monster race that seems "appropriate" to the given level
1223 * This function uses the "prob2" field of the "monster allocation table",
1224 * and various local information, to calculate the "prob3" field of the
1225 * same table, which is then used to choose an "appropriate" monster, in
1226 * a relatively efficient manner.
1228 * Note that "town" monsters will *only* be created in the town, and
1229 * "normal" monsters will *never* be created in the town, unless the
1230 * "level" is "modified", for example, by polymorph or summoning.
1232 * There is a small chance (1/50) of "boosting" the given depth by
1233 * a small amount (up to four levels), except in the town.
1235 * It is (slightly) more likely to acquire a monster of the given level
1236 * than one of a lower level. This is done by choosing several monsters
1237 * appropriate to the given level and keeping the "hardest" one.
1239 * Note that if no monsters are "appropriate", then this function will
1240 * fail, and return zero, but this should *almost* never happen.
1242 s16b get_mon_num(int level)
1250 monster_race *r_ptr;
1252 alloc_entry *table = alloc_race_table;
1254 int pls_kakuritu, pls_level;
1255 int hoge=mysqrt(level*10000L);
1257 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1259 if ((dungeon_turn > hoge*(TURNS_PER_TICK*500L)) && !level)
1261 pls_kakuritu = MAX(2, NASTY_MON-((dungeon_turn/(TURNS_PER_TICK*2500L)-hoge/10)));
1262 pls_level = MIN(8,3 + dungeon_turn/(TURNS_PER_TICK*20000L)-hoge/40);
1266 pls_kakuritu = NASTY_MON;
1270 if (d_info[dungeon_type].flags1 & DF1_MAZE)
1272 pls_kakuritu = MIN(pls_kakuritu/2, pls_kakuritu-10);
1273 if (pls_kakuritu < 2) pls_kakuritu = 2;
1278 /* Boost the level */
1279 if ((level > 0) && !p_ptr->inside_battle && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1281 /* Nightmare mode allows more out-of depth monsters */
1282 if (ironman_nightmare && !randint0(pls_kakuritu))
1284 /* What a bizarre calculation */
1285 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1289 /* Occasional "nasty" monster */
1290 if (!randint0(pls_kakuritu))
1292 /* Pick a level bonus */
1293 int d = MIN(5, level/10) + pls_level;
1295 /* Boost the level */
1299 /* Occasional "nasty" monster */
1300 if (!randint0(pls_kakuritu))
1302 /* Pick a level bonus */
1303 int d = MIN(5, level/10) + pls_level;
1305 /* Boost the level */
1315 /* Process probabilities */
1316 for (i = 0; i < alloc_race_size; i++)
1318 /* Monsters are sorted by depth */
1319 if (table[i].level > level) break;
1324 /* Access the "r_idx" of the chosen monster */
1325 r_idx = table[i].index;
1327 /* Access the actual race */
1328 r_ptr = &r_info[r_idx];
1330 if (!p_ptr->inside_battle && !chameleon_change_m_idx)
1332 /* Hack -- "unique" monsters must be "unique" */
1333 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1334 (r_ptr->flags7 & (RF7_UNIQUE_7))) &&
1335 (r_ptr->cur_num >= r_ptr->max_num))
1340 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1341 (r_ptr->cur_num >= 1))
1346 if (r_idx == MON_BANORLUPART)
1348 if (r_info[MON_BANOR].cur_num > 0) continue;
1349 if (r_info[MON_LUPART].cur_num > 0) continue;
1354 table[i].prob3 = table[i].prob2;
1357 total += table[i].prob3;
1360 /* No legal monsters */
1361 if (total <= 0) return (0);
1364 /* Pick a monster */
1365 value = randint0(total);
1367 /* Find the monster */
1368 for (i = 0; i < alloc_race_size; i++)
1370 /* Found the entry */
1371 if (value < table[i].prob3) break;
1374 value = value - table[i].prob3;
1381 /* Try for a "harder" monster once (50%) or twice (10%) */
1387 /* Pick a monster */
1388 value = randint0(total);
1390 /* Find the monster */
1391 for (i = 0; i < alloc_race_size; i++)
1393 /* Found the entry */
1394 if (value < table[i].prob3) break;
1397 value = value - table[i].prob3;
1400 /* Keep the "best" one */
1401 if (table[i].level < table[j].level) i = j;
1404 /* Try for a "harder" monster twice (10%) */
1410 /* Pick a monster */
1411 value = randint0(total);
1413 /* Find the monster */
1414 for (i = 0; i < alloc_race_size; i++)
1416 /* Found the entry */
1417 if (value < table[i].prob3) break;
1420 value = value - table[i].prob3;
1423 /* Keep the "best" one */
1424 if (table[i].level < table[j].level) i = j;
1428 return (table[i].index);
1436 * Build a string describing a monster in some way.
1438 * We can correctly describe monsters based on their visibility.
1439 * We can force all monsters to be treated as visible or invisible.
1440 * We can build nominatives, objectives, possessives, or reflexives.
1441 * We can selectively pronominalize hidden, visible, or all monsters.
1442 * We can use definite or indefinite descriptions for hidden monsters.
1443 * We can use definite or indefinite descriptions for visible monsters.
1445 * Pronominalization involves the gender whenever possible and allowed,
1446 * so that by cleverly requesting pronominalization / visibility, you
1447 * can get messages like "You hit someone. She screams in agony!".
1449 * Reflexives are acquired by requesting Objective plus Possessive.
1451 * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1452 * unless the "Assume Visible" mode is requested.
1454 * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1455 * If neither m_ptr nor r_ptr is given, the monster is assumed to
1456 * be neuter, singular, and hidden (unless "Assume Visible" is set),
1457 * in which case you may be in trouble... :-)
1459 * I am assuming that no monster name is more than 70 characters long,
1460 * so that "char desc[80];" is sufficiently large for any result.
1463 * MD_OBJECTIVE --> Objective (or Reflexive)
1464 * MD_POSSESSIVE --> Possessive (or Reflexive)
1465 * MD_INDEF_HIDDEN --> Use indefinites for hidden monsters ("something")
1466 * MD_INDEF_VISIBLE --> Use indefinites for visible monsters ("a kobold")
1467 * MD_PRON_HIDDEN --> Pronominalize hidden monsters
1468 * MD_PRON_VISIBLE --> Pronominalize visible monsters
1469 * MD_ASSUME_HIDDEN --> Assume the monster is hidden
1470 * MD_ASSUME_VISIBLE --> Assume the monster is visible
1471 * MD_TRUE_NAME --> Chameleon's true name
1472 * MD_IGNORE_HALLU --> Ignore hallucination, and penetrate shape change
1473 * MD_ASSUME_OUTSIDE --> Assume this monster pet waiting outside the floor
1476 * 0x00 --> Full nominative name ("the kobold") or "it"
1477 * MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1478 * MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1479 * MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1480 * MD_PRON_VISIBLE | MD_POSSESSIVE
1481 * --> Possessive, genderized if visable ("his") or "its"
1482 * MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1483 * --> Reflexive, genderized if visable ("himself") or "itself"
1485 void monster_desc(char *desc, monster_type *m_ptr, int mode)
1488 monster_race *r_ptr;
1492 char silly_name[1024];
1496 r_ptr = &r_info[m_ptr->ap_r_idx];
1498 /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1499 if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1500 else name = (r_name + r_ptr->name);
1502 /* Are we hallucinating? (Idea from Nethack...) */
1503 if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1508 if (!get_rnd_line("silly_j.txt", m_ptr->r_idx, silly_name))
1510 if (!get_rnd_line("silly.txt", m_ptr->r_idx, silly_name))
1518 monster_race *hallu_race;
1522 hallu_race = &r_info[randint1(max_r_idx - 1)];
1524 while (hallu_race->flags1 & RF1_UNIQUE);
1526 strcpy(silly_name, (r_name + hallu_race->name));
1529 /* Better not strcpy it, or we could corrupt r_info... */
1533 /* Can we "see" it (exists + forced, or visible + not unforced) */
1534 seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1536 /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1537 pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1540 /* First, try using pronouns, or describing hidden monsters */
1543 /* an encoding of the monster "sex" */
1546 /* Extract the gender (if applicable) */
1547 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1548 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1550 /* Ignore the gender (if desired) */
1551 if (!m_ptr || !pron) kind = 0x00;
1554 /* Assume simple result */
1562 /* Brute force: split on the possibilities */
1563 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1565 /* Neuter, or unknown */
1567 case 0x00: res = "²¿¤«"; break;
1568 case 0x00 + (MD_OBJECTIVE): res = "²¿¤«"; break;
1569 case 0x00 + (MD_POSSESSIVE): res = "²¿¤«¤Î"; break;
1570 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "²¿¤«¼«¿È"; break;
1571 case 0x00 + (MD_INDEF_HIDDEN): res = "²¿¤«"; break;
1572 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "²¿¤«"; break;
1573 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "²¿¤«"; break;
1574 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "¤½¤ì¼«¿È"; break;
1576 case 0x00: res = "it"; break;
1577 case 0x00 + (MD_OBJECTIVE): res = "it"; break;
1578 case 0x00 + (MD_POSSESSIVE): res = "its"; break;
1579 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1580 case 0x00 + (MD_INDEF_HIDDEN): res = "something"; break;
1581 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "something"; break;
1582 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "something's"; break;
1583 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1587 /* Male (assume human if vague) */
1589 case 0x10: res = "Èà"; break;
1590 case 0x10 + (MD_OBJECTIVE): res = "Èà"; break;
1591 case 0x10 + (MD_POSSESSIVE): res = "Èà¤Î"; break;
1592 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1593 case 0x10 + (MD_INDEF_HIDDEN): res = "狼"; break;
1594 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "狼"; break;
1595 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "狼¤Î"; break;
1596 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1598 case 0x10: res = "he"; break;
1599 case 0x10 + (MD_OBJECTIVE): res = "him"; break;
1600 case 0x10 + (MD_POSSESSIVE): res = "his"; break;
1601 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1602 case 0x10 + (MD_INDEF_HIDDEN): res = "someone"; break;
1603 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1604 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1605 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1609 /* Female (assume human if vague) */
1611 case 0x20: res = "Èà½÷"; break;
1612 case 0x20 + (MD_OBJECTIVE): res = "Èà½÷"; break;
1613 case 0x20 + (MD_POSSESSIVE): res = "Èà½÷¤Î"; break;
1614 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1615 case 0x20 + (MD_INDEF_HIDDEN): res = "狼"; break;
1616 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "狼"; break;
1617 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "狼¤Î"; break;
1618 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1620 case 0x20: res = "she"; break;
1621 case 0x20 + (MD_OBJECTIVE): res = "her"; break;
1622 case 0x20 + (MD_POSSESSIVE): res = "her"; break;
1623 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1624 case 0x20 + (MD_INDEF_HIDDEN): res = "someone"; break;
1625 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1626 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1627 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1631 /* Copy the result */
1632 (void)strcpy(desc, res);
1636 /* Handle visible monsters, "reflexive" request */
1637 else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1639 /* The monster is visible, so use its gender */
1641 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "Èà½÷¼«¿È");
1642 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "È༫¿È");
1643 else strcpy(desc, "¤½¤ì¼«¿È");
1645 if (r_ptr->flags1 & RF1_FEMALE) strcpy(desc, "herself");
1646 else if (r_ptr->flags1 & RF1_MALE) strcpy(desc, "himself");
1647 else strcpy(desc, "itself");
1652 /* Handle all other visible monster requests */
1656 if (is_pet(m_ptr) && m_ptr->ap_r_idx != m_ptr->r_idx)
1662 while(strncmp(t, "¡Ù", 2) && *t) t++;
1666 (void)sprintf(desc, "%s¡©¡Ù", buf);
1669 (void)sprintf(desc, "%s¡©", name);
1671 (void)sprintf(desc, "%s?", name);
1676 /* It could be a Unique */
1677 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1679 /* Start with the name (thus nominative and objective) */
1680 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1686 while (strncmp(t, "¡Ù", 2) && *t) t++;
1690 (void)sprintf(desc, "%s¡©¡Ù", buf);
1693 (void)sprintf(desc, "%s¡©", name);
1695 (void)sprintf(desc, "%s?", name);
1698 else if ((cave[m_ptr->fy][m_ptr->fx].m_idx == p_ptr->riding) || !p_ptr->inside_battle)
1699 (void)strcpy(desc, name);
1702 (void)sprintf(desc, "%s¤â¤É¤", name);
1704 (void)sprintf(desc, "fake %s", name);
1708 /* It could be an indefinite monster */
1709 else if (mode & MD_INDEF_VISIBLE)
1711 /* XXX Check plurality for "some" */
1713 /* Indefinite monsters need an indefinite article */
1715 (void)strcpy(desc, "");
1717 (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1720 (void)strcat(desc, name);
1723 /* It could be a normal, definite, monster */
1726 /* Definite monsters need a definite article */
1729 (void)strcpy(desc, "¤¢¤Ê¤¿¤Î");
1731 (void)strcpy(desc, "your ");
1736 (void)strcpy(desc, "");
1738 (void)strcpy(desc, "the ");
1741 (void)strcat(desc, name);
1744 if (m_ptr->nickname)
1747 sprintf(buf,"¡Ö%s¡×",quark_str(m_ptr->nickname));
1749 sprintf(buf," called %s",quark_str(m_ptr->nickname));
1754 if (player_bold(m_ptr->fy, m_ptr->fx))
1757 strcat(desc,"(¾èÇÏÃæ)");
1759 strcat(desc,"(riding)");
1763 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1765 if (r_ptr->flags1 & RF1_UNIQUE)
1768 strcat(desc,"(¥«¥á¥ì¥ª¥ó¤Î²¦)");
1770 strcat(desc,"(Chameleon Lord)");
1776 strcat(desc,"(¥«¥á¥ì¥ª¥ó)");
1778 strcat(desc,"(Chameleon)");
1783 if ((mode & MD_IGNORE_HALLU) && m_ptr->ap_r_idx != m_ptr->r_idx)
1785 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1788 if (mode & MD_ASSUME_OUTSIDE)
1791 strcat(desc,"(ÂÔµ¡Ãæ)");
1793 strcat(desc,"(waiting)");
1797 /* Handle the Possessive as a special afterthought */
1798 if (mode & MD_POSSESSIVE)
1800 /* XXX Check for trailing "s" */
1802 /* Simply append "apostrophe" and "s" */
1804 (void)strcat(desc, "¤Î");
1806 (void)strcat(desc, "'s");
1816 * Learn about a monster (by "probing" it)
1818 * Return the number of new flags learnt. -Mogami-
1820 int lore_do_probe(int r_idx)
1822 monster_race *r_ptr = &r_info[r_idx];
1826 /* Maximal info about awareness */
1827 if (r_ptr->r_wake != MAX_UCHAR) n++;
1828 if (r_ptr->r_ignore != MAX_UCHAR) n++;
1829 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1831 /* Observe "maximal" attacks */
1832 for (i = 0; i < 4; i++)
1834 /* Examine "actual" blows */
1835 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1837 /* Maximal observations */
1838 if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1839 r_ptr->r_blows[i] = MAX_UCHAR;
1845 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1846 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1847 ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1848 ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1849 ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1850 ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1852 /* Only "valid" drops */
1853 if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1855 if (r_ptr->r_drop_item != tmp_byte) n++;
1856 r_ptr->r_drop_item = tmp_byte;
1858 if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1860 if (r_ptr->r_drop_gold != tmp_byte) n++;
1861 r_ptr->r_drop_gold = tmp_byte;
1864 /* Observe many spells */
1865 if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1866 r_ptr->r_cast_spell = MAX_UCHAR;
1868 /* Count unknown flags */
1869 for (i = 0; i < 32; i++)
1871 if (!(r_ptr->r_flags1 & (1L << i)) &&
1872 (r_ptr->flags1 & (1L << i))) n++;
1873 if (!(r_ptr->r_flags2 & (1L << i)) &&
1874 (r_ptr->flags2 & (1L << i))) n++;
1875 if (!(r_ptr->r_flags3 & (1L << i)) &&
1876 (r_ptr->flags3 & (1L << i))) n++;
1877 if (!(r_ptr->r_flags4 & (1L << i)) &&
1878 (r_ptr->flags4 & (1L << i))) n++;
1879 if (!(r_ptr->r_flags5 & (1L << i)) &&
1880 (r_ptr->flags5 & (1L << i))) n++;
1881 if (!(r_ptr->r_flags6 & (1L << i)) &&
1882 (r_ptr->flags6 & (1L << i))) n++;
1883 if (!(r_ptr->r_flagsr & (1L << i)) &&
1884 (r_ptr->flagsr & (1L << i))) n++;
1886 /* r_flags7 is actually unused */
1888 if (!(r_ptr->r_flags7 & (1L << i)) &&
1889 (r_ptr->flags7 & (1L << i))) n++;
1893 /* Know all the flags */
1894 r_ptr->r_flags1 = r_ptr->flags1;
1895 r_ptr->r_flags2 = r_ptr->flags2;
1896 r_ptr->r_flags3 = r_ptr->flags3;
1897 r_ptr->r_flags4 = r_ptr->flags4;
1898 r_ptr->r_flags5 = r_ptr->flags5;
1899 r_ptr->r_flags6 = r_ptr->flags6;
1900 r_ptr->r_flagsr = r_ptr->flagsr;
1902 /* r_flags7 is actually unused */
1903 /* r_ptr->r_flags7 = r_ptr->flags7; */
1905 /* Know about evolution */
1906 if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1907 r_ptr->r_xtra1 |= MR1_SINKA;
1909 /* Update monster recall window */
1910 if (p_ptr->monster_race_idx == r_idx)
1913 p_ptr->window |= (PW_MONSTER);
1916 /* Return the number of new flags learnt */
1922 * Take note that the given monster just dropped some treasure
1924 * Note that learning the "GOOD"/"GREAT" flags gives information
1925 * about the treasure (even when the monster is killed for the first
1926 * time, such as uniques, and the treasure has not been examined yet).
1928 * This "indirect" method is used to prevent the player from learning
1929 * exactly how much treasure a monster can drop from observing only
1930 * a single example of a drop. This method actually observes how much
1931 * gold and items are dropped, and remembers that information to be
1932 * described later by the monster recall code.
1934 void lore_treasure(int m_idx, int num_item, int num_gold)
1936 monster_type *m_ptr = &m_list[m_idx];
1938 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1940 /* If the monster doesn't have original appearance, don't note */
1941 if (!is_original_ap(m_ptr)) return;
1943 /* Note the number of things dropped */
1944 if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1945 if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1947 /* Hack -- memorize the good/great flags */
1948 if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1949 if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1951 /* Update monster recall window */
1952 if (p_ptr->monster_race_idx == m_ptr->r_idx)
1955 p_ptr->window |= (PW_MONSTER);
1961 void sanity_blast(monster_type *m_ptr, bool necro)
1963 bool happened = FALSE;
1966 if (p_ptr->inside_battle || !character_dungeon) return;
1971 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1973 power = r_ptr->level / 2;
1975 monster_desc(m_name, m_ptr, 0);
1977 if (!(r_ptr->flags1 & RF1_UNIQUE))
1979 if (r_ptr->flags1 & RF1_FRIENDS)
1985 return; /* No effect yet, just loaded... */
1988 return; /* Cannot see it for some reason */
1990 if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
1996 return; /* Pet eldritch horrors are safe most of the time */
1998 if (randint1(100) > power) return;
2000 if (saving_throw(p_ptr->skill_sav - power))
2002 return; /* Save, no adverse effects */
2007 /* Something silly happens... */
2009 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2010 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2012 msg_format("You behold the %s visage of %s!",
2013 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2019 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2020 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2023 return; /* Never mind; we can't see it clearly enough */
2026 /* Something frightening happens... */
2028 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2029 horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2031 msg_format("You behold the %s visage of %s!",
2032 horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2035 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2037 /* Demon characters are unaffected */
2038 if (prace_is_(RACE_IMP) || prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
2039 if (p_ptr->wizard) return;
2041 /* Undead characters are 50% likely to be unaffected */
2042 if (prace_is_(RACE_SKELETON) || prace_is_(RACE_ZOMBIE)
2043 || prace_is_(RACE_VAMPIRE) || prace_is_(RACE_SPECTRE) ||
2044 (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
2046 if (saving_throw(25 + p_ptr->lev)) return;
2052 msg_print("¥Í¥¯¥í¥Î¥ß¥³¥ó¤òÆɤó¤ÇÀµµ¤¤ò¼º¤Ã¤¿¡ª");
2054 msg_print("Your sanity is shaken by reading the Necronomicon!");
2059 if (!saving_throw(p_ptr->skill_sav - power)) /* Mind blast */
2061 if (!p_ptr->resist_conf)
2063 (void)set_confused(p_ptr->confused + randint0(4) + 4);
2065 if (!p_ptr->resist_chaos && one_in_(3))
2067 (void)set_image(p_ptr->image + randint0(250) + 150);
2072 if (!saving_throw(p_ptr->skill_sav - power)) /* Lose int & wis */
2079 if (!saving_throw(p_ptr->skill_sav - power)) /* Brain smash */
2081 if (!p_ptr->resist_conf)
2083 (void)set_confused(p_ptr->confused + randint0(4) + 4);
2085 if (!p_ptr->free_act)
2087 (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2089 while (randint0(100) > p_ptr->skill_sav)
2090 (void)do_dec_stat(A_INT);
2091 while (randint0(100) > p_ptr->skill_sav)
2092 (void)do_dec_stat(A_WIS);
2093 if (!p_ptr->resist_chaos)
2095 (void)set_image(p_ptr->image + randint0(250) + 150);
2100 if (!saving_throw(p_ptr->skill_sav - power)) /* Amnesia */
2103 if (lose_all_info())
2105 msg_print("¤¢¤Þ¤ê¤Î¶²ÉݤËÁ´¤Æ¤Î¤³¤È¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
2107 msg_print("You forget everything in your utmost terror!");
2113 if (saving_throw(p_ptr->skill_sav - power))
2118 /* Else gain permanent insanity */
2119 if ((p_ptr->muta3 & MUT3_MORONIC) && /*(p_ptr->muta2 & MUT2_BERS_RAGE) &&*/
2120 ((p_ptr->muta2 & MUT2_COWARDICE) || (p_ptr->resist_fear)) &&
2121 ((p_ptr->muta2 & MUT2_HALLU) || (p_ptr->resist_chaos)))
2123 /* The poor bastard already has all possible insanities! */
2129 switch (randint1(21))
2132 if (!(p_ptr->muta3 & MUT3_MORONIC) && one_in_(5))
2134 if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2137 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¤è¤¦¤Êµ¤¤¬¤·¤¿¡£¤·¤«¤·¤½¤ì¤Ï¸µ¡¹¤À¤Ã¤¿¡£");
2139 msg_print("You turn into an utter moron!");
2145 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¡ª");
2147 msg_print("You turn into an utter moron!");
2151 if (p_ptr->muta3 & MUT3_HYPER_INT)
2154 msg_print("¤¢¤Ê¤¿¤ÎǾ¤ÏÀ¸ÂÎ¥³¥ó¥Ô¥å¡¼¥¿¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2156 msg_print("Your brain is no longer a living computer.");
2159 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2161 p_ptr->muta3 |= MUT3_MORONIC;
2175 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2178 msg_print("¤¢¤Ê¤¿¤Ï¥Ñ¥é¥Î¥¤¥¢¤Ë¤Ê¤Ã¤¿¡ª");
2180 msg_print("You become paranoid!");
2184 /* Duh, the following should never happen, but anyway... */
2185 if (p_ptr->muta3 & MUT3_FEARLESS)
2188 msg_print("¤¢¤Ê¤¿¤Ï¤â¤¦¶²¤ìÃΤ餺¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2190 msg_print("You are no longer fearless.");
2193 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2196 p_ptr->muta2 |= MUT2_COWARDICE;
2210 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2213 msg_print("¸¸³Ð¤ò¤Ò¤µ¯¤³¤¹Àº¿ÀºøÍð¤Ë´Ù¤Ã¤¿¡ª");
2215 msg_print("You are afflicted by a hallucinatory insanity!");
2218 p_ptr->muta2 |= MUT2_HALLU;
2223 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2226 msg_print("·ãÎõ¤Ê´¶¾ð¤Îȯºî¤Ë¤ª¤½¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡ª");
2228 msg_print("You become subject to fits of berserk rage!");
2231 p_ptr->muta2 |= MUT2_BERS_RAGE;
2238 p_ptr->update |= PU_BONUS;
2244 * This function updates the monster record of the given monster
2246 * This involves extracting the distance to the player (if requested),
2247 * and then checking for visibility (natural, infravision, see-invis,
2248 * telepathy), updating the monster visibility flag, redrawing (or
2249 * erasing) the monster when its visibility changes, and taking note
2250 * of any interesting monster flags (cold-blooded, invisible, etc).
2252 * Note the new "mflag" field which encodes several monster state flags,
2253 * including "view" for when the monster is currently in line of sight,
2254 * and "mark" for when the monster is currently visible via detection.
2256 * The only monster fields that are changed here are "cdis" (the
2257 * distance from the player), "ml" (visible to the player), and
2258 * "mflag" (to maintain the "MFLAG_VIEW" flag).
2260 * Note the special "update_monsters()" function which can be used to
2261 * call this function once for every monster.
2263 * Note the "full" flag which requests that the "cdis" field be updated,
2264 * this is only needed when the monster (or the player) has moved.
2266 * Every time a monster moves, we must call this function for that
2267 * monster, and update the distance, and the visibility. Every time
2268 * the player moves, we must call this function for every monster, and
2269 * update the distance, and the visibility. Whenever the player "state"
2270 * changes in certain ways ("blindness", "infravision", "telepathy",
2271 * and "see invisible"), we must call this function for every monster,
2272 * and update the visibility.
2274 * Routines that change the "illumination" of a grid must also call this
2275 * function for any monster in that grid, since the "visibility" of some
2276 * monsters may be based on the illumination of their grid.
2278 * Note that this function is called once per monster every time the
2279 * player moves. When the player is running, this function is one
2280 * of the primary bottlenecks, along with "update_view()" and the
2281 * "process_monsters()" code, so efficiency is important.
2283 * Note the optimized "inline" version of the "distance()" function.
2285 * A monster is "visible" to the player if (1) it has been detected
2286 * by the player, (2) it is close to the player and the player has
2287 * telepathy, or (3) it is close to the player, and in line of sight
2288 * of the player, and it is "illuminated" by some combination of
2289 * infravision, torch light, or permanent light (invisible monsters
2290 * are only affected by "light" if the player can see invisible).
2292 * Monsters which are not on the current panel may be "visible" to
2293 * the player, and their descriptions will include an "offscreen"
2294 * reference. Currently, offscreen monsters cannot be targetted
2295 * or viewed directly, but old targets will remain set. XXX XXX
2297 * The player can choose to be disturbed by several things, including
2298 * "disturb_move" (monster which is viewable moves in some way), and
2299 * "disturb_near" (monster which is "easily" viewable moves in some
2300 * way). Note that "moves" includes "appears" and "disappears".
2302 void update_mon(int m_idx, bool full)
2304 monster_type *m_ptr = &m_list[m_idx];
2306 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2308 bool do_disturb = disturb_move;
2312 /* Current location */
2319 /* Seen by vision */
2322 /* Non-Ninja player in the darkness */
2323 bool in_darkness = (d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
2328 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2330 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
2334 /* Compute distance */
2337 /* Distance components */
2338 int dy = (py > fy) ? (py - fy) : (fy - py);
2339 int dx = (px > fx) ? (px - fx) : (fx - px);
2341 /* Approximate distance */
2342 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2344 /* Restrict distance */
2345 if (d > 255) d = 255;
2349 /* Save the distance */
2353 /* Extract distance */
2356 /* Extract the distance */
2362 if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
2366 if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
2368 if (!in_darkness || (d <= MAX_SIGHT / 4))
2370 if (p_ptr->special_defense & KATA_MUSOU)
2375 if (is_original_ap(m_ptr))
2377 /* Hack -- Memorize mental flags */
2378 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2379 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2383 /* Basic telepathy */
2384 else if (p_ptr->telepathy)
2386 /* Empty mind, no telepathy */
2387 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
2389 /* Memorize flags */
2390 if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
2393 /* Weird mind, occasional telepathy */
2394 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
2396 /* One in ten individuals are detectable */
2397 if ((m_idx % 10) == 5)
2402 if (is_original_ap(m_ptr))
2404 /* Memorize flags */
2405 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
2407 /* Hack -- Memorize mental flags */
2408 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2409 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2414 /* Normal mind, allow telepathy */
2420 if (is_original_ap(m_ptr))
2422 /* Hack -- Memorize mental flags */
2423 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2424 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2429 /* Magical sensing */
2430 if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
2433 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_ANIMAL);
2436 /* Magical sensing */
2437 if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
2440 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_UNDEAD);
2443 /* Magical sensing */
2444 if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
2447 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_DEMON);
2450 /* Magical sensing */
2451 if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
2454 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_ORC);
2457 /* Magical sensing */
2458 if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
2461 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_TROLL);
2464 /* Magical sensing */
2465 if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
2468 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_GIANT);
2471 /* Magical sensing */
2472 if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
2475 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_DRAGON);
2478 /* Magical sensing */
2479 if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
2482 if (is_original_ap(m_ptr)) r_ptr->r_flags2 |= (RF2_HUMAN);
2485 /* Magical sensing */
2486 if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2489 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_EVIL);
2492 /* Magical sensing */
2493 if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2496 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_GOOD);
2499 /* Magical sensing */
2500 if ((p_ptr->esp_nonliving) &&
2501 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2504 if (is_original_ap(m_ptr)) r_ptr->r_flags3 |= (RF3_NONLIVING);
2507 /* Magical sensing */
2508 if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2511 if (is_original_ap(m_ptr)) r_ptr->r_flags1 |= (RF1_UNIQUE);
2515 /* Normal line of sight, and not blind */
2516 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2518 bool do_invisible = FALSE;
2519 bool do_cold_blood = FALSE;
2521 /* Use "infravision" */
2522 if (d <= p_ptr->see_infra)
2524 /* Handle "cold blooded" monsters */
2525 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2528 do_cold_blood = TRUE;
2531 /* Handle "warm blooded" monsters */
2539 /* Use "illumination" */
2540 if (player_can_see_bold(fy, fx))
2542 /* Handle "invisible" monsters */
2543 if (r_ptr->flags2 & (RF2_INVISIBLE))
2546 do_invisible = TRUE;
2556 /* Handle "normal" monsters */
2567 if (is_original_ap(m_ptr))
2569 /* Memorize flags */
2570 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2571 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2578 /* The monster is now visible */
2581 /* It was previously unseen */
2584 /* Mark as visible */
2587 /* Draw the monster */
2590 /* Update health bar as needed */
2591 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2592 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2594 /* Hack -- Count "fresh" sightings */
2595 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2596 r_info[MON_KAGE].r_sights++;
2597 else if (m_ptr->ap_r_idx == m_ptr->r_idx &&
2598 r_ptr->r_sights < MAX_SHORT) r_ptr->r_sights++;
2600 /* Eldritch Horror */
2601 if (r_ptr->flags2 & RF2_ELDRITCH_HORROR)
2603 sanity_blast(m_ptr, FALSE);
2606 /* Disturb on appearance */
2607 if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, py, px) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
2609 if (disturb_pets || is_hostile(m_ptr))
2615 /* The monster is not visible */
2618 /* It was previously seen */
2621 /* Mark as not visible */
2624 /* Erase the monster */
2627 /* Update health bar as needed */
2628 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2629 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2631 /* Disturb on disappearance */
2634 if (disturb_pets || is_hostile(m_ptr))
2641 /* The monster is now easily visible */
2645 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2647 /* Mark as easily visible */
2648 m_ptr->mflag |= (MFLAG_VIEW);
2650 /* Disturb on appearance */
2653 if (disturb_pets || is_hostile(m_ptr))
2659 /* The monster is not easily visible */
2663 if (m_ptr->mflag & (MFLAG_VIEW))
2665 /* Mark as not easily visible */
2666 m_ptr->mflag &= ~(MFLAG_VIEW);
2668 /* Disturb on disappearance */
2671 if (disturb_pets || is_hostile(m_ptr))
2680 * This function simply updates all the (non-dead) monsters (see above).
2682 void update_monsters(bool full)
2686 /* Update each (live) monster */
2687 for (i = 1; i < m_max; i++)
2689 monster_type *m_ptr = &m_list[i];
2691 /* Skip dead monsters */
2692 if (!m_ptr->r_idx) continue;
2694 /* Update the monster */
2695 update_mon(i, full);
2701 * Hack -- the index of the summoning monster
2703 static bool monster_hook_chameleon_lord(int r_idx)
2705 monster_race *r_ptr = &r_info[r_idx];
2706 monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2707 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2709 if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2710 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2712 if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2714 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))
2717 if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
2720 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2722 if ((m_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
2723 if ((m_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
2727 else if (summon_specific_who > 0)
2729 monster_type *sm_ptr = &m_list[summon_specific_who];
2731 if ((sm_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
2732 if ((sm_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
2738 static bool monster_hook_chameleon(int r_idx)
2740 monster_race *r_ptr = &r_info[r_idx];
2741 monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2742 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2744 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2745 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2746 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2748 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))
2751 if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
2754 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2756 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2757 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2758 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2762 else if (summon_specific_who > 0)
2764 monster_type *sm_ptr = &m_list[summon_specific_who];
2766 if ((sm_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
2767 if ((sm_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
2770 return (*(get_monster_hook()))(r_idx);
2774 void choose_new_monster(int m_idx, bool born, int r_idx)
2777 monster_type *m_ptr = &m_list[m_idx];
2778 monster_race *r_ptr;
2779 char old_m_name[80];
2780 bool old_unique = FALSE;
2782 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2784 if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2785 r_ptr = &r_info[r_idx];
2787 monster_desc(old_m_name, m_ptr, 0);
2793 chameleon_change_m_idx = m_idx;
2795 get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2797 get_mon_num_prep(monster_hook_chameleon, NULL);
2800 level = r_info[MON_CHAMELEON_K].level;
2801 else if (!dun_level)
2802 level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2806 if (d_info[dungeon_type].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2808 r_idx = get_mon_num(level);
2809 r_ptr = &r_info[r_idx];
2811 chameleon_change_m_idx = 0;
2817 m_ptr->r_idx = r_idx;
2818 m_ptr->ap_r_idx = r_idx;
2819 update_mon(m_idx, FALSE);
2820 lite_spot(m_ptr->fy, m_ptr->fx);
2823 /* Sub-alignment of a chameleon */
2824 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2826 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2827 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2828 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2833 if (m_idx == p_ptr->riding)
2836 monster_desc(m_name, m_ptr, 0);
2838 msg_format("ÆÍÁ³%s¤¬ÊѿȤ·¤¿¡£", old_m_name);
2840 msg_format("Suddenly, %s transforms!", old_m_name);
2842 if (!(r_ptr->flags7 & RF7_RIDING))
2844 if (rakuba(0, TRUE)) msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2846 if (rakuba(0, TRUE)) msg_format("You have fallen from %s.", m_name);
2850 /* Extract the monster base speed */
2851 m_ptr->mspeed = get_mspeed(r_ptr);
2853 oldmaxhp = m_ptr->max_maxhp;
2854 /* Assign maximal hitpoints */
2855 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2857 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2861 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2863 m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2864 m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2871 static bool monster_hook_tanuki(int r_idx)
2873 monster_race *r_ptr = &r_info[r_idx];
2875 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2876 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2877 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2878 if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2880 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))
2883 return (*(get_monster_hook()))(r_idx);
2888 * Set initial racial appearance of a monster
2890 static int initial_r_appearance(int r_idx)
2892 int attempts = 1000;
2895 int min = MIN(base_level-5, 50);
2897 if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2900 get_mon_num_prep(monster_hook_tanuki, NULL);
2904 ap_r_idx = get_mon_num(base_level + 10);
2905 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2913 * Get initial monster speed
2915 byte get_mspeed(monster_race *r_ptr)
2917 /* Extract the monster base speed */
2918 int mspeed = r_ptr->speed;
2920 /* Hack -- small racial variety */
2921 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2923 /* Allow some small variation per monster */
2924 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2925 if (i) mspeed += rand_spread(0, i);
2928 if (mspeed > 199) mspeed = 199;
2930 return (byte)mspeed;
2935 * Attempt to place a monster of the given race at the given location.
2937 * To give the player a sporting chance, any monster that appears in
2938 * line-of-sight and is extremely dangerous can be marked as
2939 * "FORCE_SLEEP", which will cause them to be placed with low energy,
2940 * which often (but not always) lets the player move before they do.
2942 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2944 * XXX XXX XXX Use special "here" and "dead" flags for unique monsters,
2945 * remove old "cur_num" and "max_num" fields.
2947 * XXX XXX XXX Actually, do something similar for artifacts, to simplify
2948 * the "preserve" mode, and to make the "what artifacts" flag more useful.
2950 * This is the only function which may place a monster in the dungeon,
2951 * except for the savefile loading code.
2953 bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
2957 monster_type *m_ptr;
2959 monster_race *r_ptr = &r_info[r_idx];
2961 cptr name = (r_name + r_ptr->name);
2963 /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2964 if(p_ptr->wild_mode) return FALSE;
2966 /* Verify location */
2967 if (!in_bounds(y, x)) return (FALSE);
2969 /* Require empty space (if not ghostly) */
2970 if (!(!dun_level && (cave[y][x].feat == FEAT_MOUNTAIN) && ((r_ptr->flags8 & RF8_WILD_MOUNTAIN) || (r_ptr->flags7 & RF7_CAN_FLY))) &&
2971 !(cave_empty_bold2(y, x) || (mode & PM_IGNORE_TERRAIN)) &&
2972 !((r_ptr->flags2 & RF2_PASS_WALL) &&
2973 !(cave_perma_bold(y, x) || cave[y][x].m_idx ||
2974 player_bold(y, x)))) return (FALSE);
2977 if (!r_idx) return (FALSE);
2980 if (!r_ptr->name) return (FALSE);
2982 /* Nor on the Pattern */
2983 if ((cave[y][x].feat >= FEAT_PATTERN_START)
2984 && (cave[y][x].feat <= FEAT_PATTERN_XTRA2))
2987 if (!(mode & PM_IGNORE_TERRAIN) &&
2988 !monster_can_cross_terrain(cave[y][x].feat, r_ptr))
2993 if (!p_ptr->inside_battle)
2995 /* Hack -- "unique" monsters must be "unique" */
2996 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2997 (r_ptr->flags7 & (RF7_UNIQUE_7))) &&
2998 (r_ptr->cur_num >= r_ptr->max_num))
3004 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
3005 (r_ptr->cur_num >= 1))
3010 if (r_idx == MON_BANORLUPART)
3012 if (r_info[MON_BANOR].cur_num > 0) return FALSE;
3013 if (r_info[MON_LUPART].cur_num > 0) return FALSE;
3016 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
3017 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
3018 (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
3025 if (quest_number(dun_level))
3027 int hoge = quest_number(dun_level);
3028 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
3030 if(r_idx == quest[hoge].r_idx)
3032 int number_mon, i2, j2;
3035 /* Count all quest monsters */
3036 for (i2 = 0; i2 < cur_wid; ++i2)
3037 for (j2 = 0; j2 < cur_hgt; j2++)
3038 if (cave[j2][i2].m_idx > 0)
3039 if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
3041 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
3047 /* Access the location */
3048 c_ptr = &cave[y][x];
3050 if (is_glyph_grid(c_ptr))
3052 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
3054 /* Describe observable breakage */
3055 if (c_ptr->info & CAVE_MARK)
3058 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3060 msg_print("The rune of protection is broken!");
3065 /* Forget the rune */
3066 c_ptr->info &= ~(CAVE_MARK);
3068 /* Break the rune */
3069 c_ptr->info &= ~(CAVE_OBJECT);
3078 /* Powerful monster */
3079 if (r_ptr->level > dun_level)
3081 /* Unique monsters */
3082 if (r_ptr->flags1 & (RF1_UNIQUE))
3084 /* Message for cheaters */
3086 if (cheat_hear) msg_format("¿¼ÁؤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3088 if (cheat_hear) msg_format("Deep Unique (%s).", name);
3092 /* Boost rating by twice delta-depth */
3093 rating += (r_ptr->level - dun_level) * 2;
3096 /* Normal monsters */
3099 /* Message for cheaters */
3101 if (cheat_hear) msg_format("¿¼ÁؤΥâ¥ó¥¹¥¿¡¼ (%s)¡£", name);
3103 if (cheat_hear) msg_format("Deep Monster (%s).", name);
3107 /* Boost rating by delta-depth */
3108 rating += (r_ptr->level - dun_level);
3112 /* Note the monster */
3113 else if (r_ptr->flags1 & (RF1_UNIQUE))
3115 /* Unique monsters induce message */
3117 if (cheat_hear) msg_format("¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3119 if (cheat_hear) msg_format("Unique (%s).", name);
3124 if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7) || (r_ptr->level < 10)) is_kage = FALSE;
3126 /* Make a new monster */
3127 c_ptr->m_idx = m_pop();
3128 hack_m_idx_ii = c_ptr->m_idx;
3130 /* Mega-Hack -- catch "failure" */
3131 if (!c_ptr->m_idx) return (FALSE);
3134 /* Get a new monster record */
3135 m_ptr = &m_list[c_ptr->m_idx];
3138 m_ptr->r_idx = r_idx;
3139 m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3141 /* Sub-alignment of a monster */
3142 if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3143 m_ptr->sub_align = m_list[who].sub_align;
3146 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3147 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3148 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3151 /* Place the monster at the location */
3156 /* No "damage" yet */
3158 m_ptr->confused = 0;
3161 /* Unknown distance */
3164 reset_target(m_ptr);
3166 m_ptr->nickname = 0;
3174 if (r_ptr->flags7 & RF7_CHAMELEON)
3176 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3177 r_ptr = &r_info[m_ptr->r_idx];
3178 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
3181 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3182 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3183 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3187 m_ptr->ap_r_idx = MON_KAGE;
3188 m_ptr->mflag2 |= MFLAG2_KAGE;
3191 if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
3197 if (mode & PM_FORCE_PET)
3202 else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3203 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3205 if (!(p_ptr->align >= 0 && (r_ptr->flags3 & RF3_EVIL)) &&
3206 !(p_ptr->align < 0 && (r_ptr->flags3 & RF3_GOOD)))
3208 set_friendly(m_ptr);
3212 /* Assume no sleeping */
3215 /* Enforce sleeping if needed */
3216 if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3218 int val = r_ptr->sleep;
3219 m_ptr->csleep = ((val * 2) + randint1(val * 10));
3222 /* Assign maximal hitpoints */
3223 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3225 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3229 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3232 /* Monsters have double hitpoints in Nightmare mode */
3233 if (ironman_nightmare)
3235 u32b hp = m_ptr->max_maxhp * 2L;
3237 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3240 m_ptr->maxhp = m_ptr->max_maxhp;
3242 /* And start out fully healthy */
3243 if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3244 m_ptr->hp = m_ptr->maxhp / 2;
3245 else m_ptr->hp = m_ptr->maxhp;
3248 /* Extract the monster base speed */
3249 m_ptr->mspeed = get_mspeed(r_ptr);
3251 if (mode & PM_HASTE) m_ptr->fast = 100;
3253 /* Give a random starting energy */
3254 if (!ironman_nightmare)
3256 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3260 /* Nightmare monsters are more prepared */
3261 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3264 /* Force monster to wait for player, unless in Nightmare mode */
3265 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3267 /* Monster is still being nice */
3268 m_ptr->mflag |= (MFLAG_NICE);
3270 /* Must repair monsters */
3271 repair_monsters = TRUE;
3274 /* Hack -- see "process_monsters()" */
3275 if (c_ptr->m_idx < hack_m_idx)
3277 /* Monster is still being born */
3278 m_ptr->mflag |= (MFLAG_BORN);
3282 if (r_ptr->flags7 & RF7_SELF_LD_MASK)
3283 p_ptr->update |= (PU_MON_LITE);
3284 else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !m_ptr->csleep)
3285 p_ptr->update |= (PU_MON_LITE);
3287 /* Update the monster */
3288 update_mon(c_ptr->m_idx, TRUE);
3291 /* Count the monsters on the level */
3292 real_r_ptr(m_ptr)->cur_num++;
3295 * Memorize location of the unique monster in saved floors.
3296 * A unique monster move from old saved floor.
3298 if (character_dungeon &&
3299 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)))
3300 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
3302 /* Hack -- Count the number of "reproducers" */
3303 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3306 /* Hack -- Notice new multi-hued monsters */
3308 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3309 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
3310 shimmer_monsters = TRUE;
3313 if (p_ptr->warning && character_dungeon)
3315 if (r_ptr->flags1 & RF1_UNIQUE)
3319 char o_name[MAX_NLEN];
3321 if (r_ptr->level > p_ptr->lev + 30)
3327 else if (r_ptr->level > p_ptr->lev + 15)
3333 else if (r_ptr->level > p_ptr->lev + 5)
3335 color = "¥ë¥Ó¡¼¿§¤Ë";
3339 else if (r_ptr->level > p_ptr->lev - 5)
3345 else if (r_ptr->level > p_ptr->lev - 15)
3347 color = "¥Ô¥ó¥¯¿§¤Ë";
3358 o_ptr = choose_warning_item();
3359 object_desc(o_name, o_ptr, FALSE, 0);
3361 msg_format("%s¤Ï%s¸÷¤Ã¤¿¡£",o_name, color);
3363 msg_format("%s glows %s.",o_name, color);
3368 if (is_explosive_rune_grid(c_ptr))
3370 /* Break the ward */
3371 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3373 /* Describe observable breakage */
3374 if (c_ptr->info & CAVE_MARK)
3377 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3379 msg_print("The rune explodes!");
3382 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);
3388 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3390 msg_print("An explosive rune was disarmed.");
3394 /* Forget the rune */
3395 c_ptr->info &= ~(CAVE_MARK);
3397 /* Break the rune */
3398 c_ptr->info &= ~(CAVE_OBJECT);
3411 * improved version of scatter() for place monster
3414 #define MON_SCAT_MAXD 10
3416 static bool mon_scatter(int *yp, int *xp, int y, int x, int max_dist)
3418 int place_x[MON_SCAT_MAXD];
3419 int place_y[MON_SCAT_MAXD];
3420 int num[MON_SCAT_MAXD];
3424 if (max_dist >= MON_SCAT_MAXD)
3427 for (i = 0; i < MON_SCAT_MAXD; i++)
3430 for (nx = x - max_dist; nx <= x + max_dist; nx++)
3431 for (ny = y - max_dist; ny <= y + max_dist; ny++)
3433 /* Ignore annoying locations */
3434 if (!in_bounds(ny, nx)) continue;
3436 /* Require "line of sight" */
3437 if (!los(y, x, ny, nx)) continue;
3439 /* Walls and Monsters block flow */
3440 if (!cave_empty_bold2(ny, nx)) continue;
3441 if (cave[ny][nx].m_idx) continue;
3442 if (player_bold(ny, nx)) continue;
3444 /* ... nor on the Pattern */
3445 if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
3446 (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2))
3449 i = distance(y, x, ny, nx);
3465 while (i < MON_SCAT_MAXD && 0 == num[i])
3467 if (i >= MON_SCAT_MAXD)
3478 * Maximum size of a group of monsters
3480 #define GROUP_MAX 32
3484 * Attempt to place a "group" of monsters around the given location
3486 static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
3488 monster_race *r_ptr = &r_info[r_idx];
3491 int total = 0, extra = 0;
3495 byte hack_y[GROUP_MAX];
3496 byte hack_x[GROUP_MAX];
3499 /* Pick a group size */
3500 total = randint1(10);
3502 /* Hard monsters, small groups */
3503 if (r_ptr->level > dun_level)
3505 extra = r_ptr->level - dun_level;
3506 extra = 0 - randint1(extra);
3509 /* Easy monsters, large groups */
3510 else if (r_ptr->level < dun_level)
3512 extra = dun_level - r_ptr->level;
3513 extra = randint1(extra);
3516 /* Hack -- limit group reduction */
3517 if (extra > 9) extra = 9;
3519 /* Modify the group size */
3523 if (total < 1) total = 1;
3526 if (total > GROUP_MAX) total = GROUP_MAX;
3529 /* Save the rating */
3532 /* Start on the monster */
3537 /* Puddle monsters, breadth first, up to total */
3538 for (n = 0; (n < hack_n) && (hack_n < total); n++)
3540 /* Grab the location */
3544 /* Check each direction, up to total */
3545 for (i = 0; (i < 8) && (hack_n < total); i++)
3549 scatter(&my, &mx, hy, hx, 4, 0);
3551 /* Walls and Monsters block flow */
3552 if (!cave_empty_bold2(my, mx)) continue;
3554 /* Attempt to place another monster */
3555 if (place_monster_one(who, my, mx, r_idx, mode))
3557 /* Add it to the "hack" set */
3558 hack_y[hack_n] = my;
3559 hack_x[hack_n] = mx;
3565 /* Hack -- restore the rating */
3575 * Hack -- help pick an escort type
3577 static int place_monster_idx = 0;
3578 static int place_monster_m_idx = 0;
3581 * Hack -- help pick an escort type
3583 static bool place_monster_okay(int r_idx)
3585 monster_race *r_ptr = &r_info[place_monster_idx];
3586 monster_type *m_ptr = &m_list[place_monster_m_idx];
3588 monster_race *z_ptr = &r_info[r_idx];
3590 /* Hack - Escorts have to have the same dungeon flag */
3591 if (monster_dungeon(place_monster_idx) != monster_dungeon(r_idx)) return (FALSE);
3593 /* Require similar "race" */
3594 if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3596 /* Skip more advanced monsters */
3597 if (z_ptr->level > r_ptr->level) return (FALSE);
3599 /* Skip unique monsters */
3600 if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3602 /* Paranoia -- Skip identical monsters */
3603 if (place_monster_idx == r_idx) return (FALSE);
3605 /* Skip different alignment */
3606 if (((m_ptr->sub_align & SUB_ALIGN_EVIL) && (z_ptr->flags3 & RF3_GOOD)) ||
3607 ((m_ptr->sub_align & SUB_ALIGN_GOOD) && (z_ptr->flags3 & RF3_EVIL)))
3610 if (r_ptr->flags7 & RF7_FRIENDLY)
3612 if (((p_ptr->align < 0) && (z_ptr->flags3 & RF3_GOOD)) ||
3613 ((p_ptr->align > 0) && (z_ptr->flags3 & RF3_EVIL)))
3617 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3626 * Attempt to place a monster of the given race at the given location
3628 * Note that certain monsters are now marked as requiring "friends".
3629 * These monsters, if successfully placed, and if the "grp" parameter
3630 * is TRUE, will be surrounded by a "group" of identical monsters.
3632 * Note that certain monsters are now marked as requiring an "escort",
3633 * which is a collection of monsters with similar "race" but lower level.
3635 * Some monsters induce a fake "group" flag on their escorts.
3637 * Note the "bizarre" use of non-recursion to prevent annoying output
3638 * when running a code profiler.
3640 * Note the use of the new "monster allocation table" code to restrict
3641 * the "get_mon_num()" function to "legal" escort types.
3643 bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
3646 monster_race *r_ptr = &r_info[r_idx];
3648 if (one_in_(333) && !(mode & PM_NO_KAGE) && !(mode & PM_FORCE_PET))
3653 /* Place one monster, or fail */
3654 if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3657 /* Require the "group" flag */
3658 if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3660 place_monster_m_idx = hack_m_idx_ii;
3662 /* Friends for certain monsters */
3663 if (r_ptr->flags1 & (RF1_FRIENDS))
3665 /* Attempt to place a group */
3666 (void)place_monster_group(who, y, x, r_idx, mode);
3670 /* Escorts for certain monsters */
3671 if (r_ptr->flags1 & (RF1_ESCORT))
3673 /* Set the escort index */
3674 place_monster_idx = r_idx;
3676 /* Try to place several "escorts" */
3677 for (i = 0; i < 32; i++)
3679 int nx, ny, z, d = 3;
3681 /* Pick a location */
3682 scatter(&ny, &nx, y, x, d, 0);
3684 /* Require empty grids */
3685 if (!cave_empty_bold2(ny, nx)) continue;
3687 /* Prepare allocation table */
3688 get_mon_num_prep(place_monster_okay, get_monster_hook2(ny, nx));
3690 /* Pick a random race */
3691 z = get_mon_num(r_ptr->level);
3693 /* Handle failure */
3696 /* Place a single escort */
3697 (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3699 /* Place a "group" of escorts if needed */
3700 if ((r_info[z].flags1 & RF1_FRIENDS) ||
3701 (r_ptr->flags1 & RF1_ESCORTS))
3703 /* Place a group of monsters */
3704 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3715 * Hack -- attempt to place a monster at the given location
3717 * Attempt to find a monster appropriate to the "monster_level"
3719 bool place_monster(int y, int x, u32b mode)
3723 /* Prepare allocation table */
3724 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3726 /* Pick a monster */
3727 r_idx = get_mon_num(monster_level);
3729 /* Handle failure */
3730 if (!r_idx) return (FALSE);
3732 /* Attempt to place the monster */
3733 if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3740 #ifdef MONSTER_HORDES
3742 bool alloc_horde(int y, int x)
3744 monster_race *r_ptr = NULL;
3747 int attempts = 1000;
3751 /* Prepare allocation table */
3752 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3756 /* Pick a monster */
3757 r_idx = get_mon_num(monster_level);
3759 /* Handle failure */
3760 if (!r_idx) return (FALSE);
3762 r_ptr = &r_info[r_idx];
3764 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3766 if (r_idx == MON_HAGURE) continue;
3769 if (attempts < 1) return FALSE;
3775 /* Attempt to place the monster */
3776 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3779 if (attempts < 1) return FALSE;
3781 m_idx = cave[y][x].m_idx;
3783 if (m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[m_list[m_idx].r_idx];
3784 summon_kin_type = r_ptr->d_char;
3786 for (attempts = randint1(10) + 5; attempts; attempts--)
3788 scatter(&cy, &cx, y, x, 5, 0);
3790 (void)summon_specific(m_idx, cy, cx, dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3799 #endif /* MONSTER_HORDES */
3805 bool alloc_guardian(void)
3807 int guardian = d_info[dungeon_type].final_guardian;
3809 if (guardian && (d_info[dungeon_type].maxdepth == dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3815 /* Find a good position */
3818 /* Get a random spot */
3819 oy = randint1(cur_hgt - 4) + 2;
3820 ox = randint1(cur_wid - 4) + 2;
3822 /* Is it a good spot ? */
3823 if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian]))
3825 /* Place the guardian */
3826 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3839 * Attempt to allocate a random monster in the dungeon.
3841 * Place the monster at least "dis" distance from the player.
3843 * Use "slp" to choose the initial "sleep" status
3845 * Use "monster_level" for the monster level
3847 bool alloc_monster(int dis, u32b mode)
3850 int attempts_left = 10000;
3852 /* Put the Guardian */
3853 if (alloc_guardian()) return TRUE;
3855 /* Find a legal, distant, unoccupied, space */
3856 while (attempts_left--)
3858 /* Pick a location */
3859 y = randint0(cur_hgt);
3860 x = randint0(cur_wid);
3862 /* Require empty floor grid (was "naked") */
3863 if (dun_level || (wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].terrain != TERRAIN_MOUNTAIN))
3865 if (!cave_empty_bold2(y, x)) continue;
3869 if (!cave_empty_bold2(y, x) && (cave[y][x].feat != FEAT_MOUNTAIN)) continue;
3872 /* Accept far away grids */
3873 if (distance(y, x, py, px) > dis) break;
3878 if (cheat_xtra || cheat_hear)
3881 msg_print("·Ù¹ð¡ª¿·¤¿¤Ê¥â¥ó¥¹¥¿¡¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡£¾®¤µ¤¤³¬¤Ç¤¹¤«¡©");
3883 msg_print("Warning! Could not allocate a new monster. Small level?");
3892 #ifdef MONSTER_HORDES
3893 if (randint1(5000) <= dun_level)
3895 if (alloc_horde(y, x))
3898 if (cheat_hear) msg_format("¥â¥ó¥¹¥¿¡¼¤ÎÂç·²(%c)", summon_kin_type);
3900 if (cheat_hear) msg_format("Monster horde (%c).", summon_kin_type);
3908 #endif /* MONSTER_HORDES */
3910 /* Attempt to place the monster, allow groups */
3911 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3913 #ifdef MONSTER_HORDES
3915 #endif /* MONSTER_HORDES */
3925 * Hack -- help decide if a monster race is "okay" to summon
3927 static bool summon_specific_okay(int r_idx)
3929 monster_race *r_ptr = &r_info[r_idx];
3931 /* Hack - Only summon dungeon monsters */
3932 if (!monster_dungeon(r_idx)) return (FALSE);
3934 /* Hack -- identify the summoning monster */
3935 if (summon_specific_who > 0)
3937 monster_type *m_ptr = &m_list[summon_specific_who];
3939 /* Do not summon enemies */
3941 /* Friendly vs. opposite aligned normal or pet */
3942 if (((r_ptr->flags3 & RF3_EVIL) &&
3943 (m_ptr->sub_align & SUB_ALIGN_GOOD)) ||
3944 ((r_ptr->flags3 & RF3_GOOD) &&
3945 (m_ptr->sub_align & SUB_ALIGN_EVIL)))
3950 /* Hostile vs. non-hostile */
3951 if (is_hostile(m_ptr) != summon_specific_hostile)
3956 /* Use the player's alignment */
3957 else if (summon_specific_who < 0)
3959 /* Do not summon enemies of the pets */
3960 if ((p_ptr->align < -9) && (r_ptr->flags3 & RF3_GOOD))
3962 if (!one_in_((0-p_ptr->align)/2+1)) return FALSE;
3964 else if ((p_ptr->align > 9) && (r_ptr->flags3 & RF3_EVIL))
3966 if (!one_in_(p_ptr->align/2+1)) return FALSE;
3970 /* Hack -- no specific type specified */
3971 if (!summon_specific_type) return (TRUE);
3973 if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7))) return FALSE;
3975 if ((summon_specific_who < 0) &&
3976 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_UNIQUE_7)) &&
3977 (((p_ptr->align > 9) && (r_ptr->flags3 & RF3_EVIL)) ||
3978 ((p_ptr->align < -9) && (r_ptr->flags3 & RF3_GOOD))))
3981 if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
3983 return (summon_specific_aux(r_idx));
3988 * Place a monster (of the specified "type") near the given
3989 * location. Return TRUE if a monster was actually summoned.
3991 * We will attempt to place the monster up to 10 times before giving up.
3993 * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3994 * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3995 * Note: None of the other summon codes will ever summon Unique's.
3997 * This function has been changed. We now take the "monster level"
3998 * of the summoning monster as a parameter, and use that, along with
3999 * the current dungeon level, to help determine the level of the
4000 * desired monster. Note that this is an upper bound, and also
4001 * tends to "prefer" monsters of that level. Currently, we use
4002 * the average of the dungeon and monster levels, and then add
4003 * five to allow slight increases in monster power.
4005 * Note that we use the new "monster allocation table" creation code
4006 * to restrict the "get_mon_num()" function to the set of "legal"
4007 * monsters, making this function much faster and more reliable.
4009 * Note that this function may not succeed, though this is very rare.
4011 bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
4015 if (p_ptr->inside_arena) return (FALSE);
4017 if (!mon_scatter(&y, &x, y1, x1, 2)) return FALSE;
4019 /* Save the summoner */
4020 summon_specific_who = who;
4022 /* Save the "summon" type */
4023 summon_specific_type = type;
4025 summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
4027 /* Save the hostility */
4028 summon_specific_hostile = (!(mode & PM_FORCE_FRIENDLY) && !(is_friendly_idx(who)) && !(mode & PM_FORCE_PET));
4030 /* Prepare allocation table */
4031 get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
4033 /* Pick a monster, using the level calculation */
4034 r_idx = get_mon_num((dun_level + lev) / 2 + 5);
4036 /* Handle failure */
4039 summon_specific_type = 0;
4043 if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
4045 /* Attempt to place the monster (awake, allow groups) */
4046 if (!place_monster_aux(who, y, x, r_idx, mode))
4048 summon_specific_type = 0;
4052 summon_specific_type = 0;
4057 /* A "dangerous" function, creates a pet of the specified type */
4058 bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
4063 /* if (!r_idx) return; */
4065 /* Prevent illegal monsters */
4066 if (r_idx >= max_r_idx) return FALSE;
4068 if (p_ptr->inside_arena) return FALSE;
4070 if (!mon_scatter(&y, &x, oy, ox, 2)) return FALSE;
4072 /* Place it (allow groups) */
4073 return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
4078 * Let the given monster attempt to reproduce.
4080 * Note that "reproduction" REQUIRES empty space.
4082 bool multiply_monster(int m_idx, bool clone, u32b mode)
4084 monster_type *m_ptr = &m_list[m_idx];
4088 if (!mon_scatter(&y, &x, m_ptr->fy, m_ptr->fx, 1))
4091 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4093 /* Create a new monster (awake, no groups) */
4094 if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE)))
4099 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4100 m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
4103 /* Hack -- Shadower spawns Shadower */
4104 if (m_ptr->mflag2 & MFLAG2_KAGE) m_list[hack_m_idx_ii].mflag2 |= MFLAG2_KAGE;
4106 /* Hack -- Appearance transfer */
4107 if (!is_original_ap(m_ptr)) m_list[hack_m_idx_ii].ap_r_idx = m_ptr->ap_r_idx;
4117 * Dump a message describing a monster's reaction to damage
4119 * Technically should attempt to treat "Beholder"'s as jelly's
4121 void message_pain(int m_idx, int dam)
4123 long oldhp, newhp, tmp;
4126 monster_type *m_ptr = &m_list[m_idx];
4127 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4132 /* Get the monster name */
4133 monster_desc(m_name, m_ptr, 0);
4135 /* Notice non-damage */
4139 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Æ¤¤¤Ê¤¤¡£", m_name);
4141 msg_format("%^s is unharmed.", m_name);
4147 /* Note -- subtle fix -CFT */
4148 newhp = (long)(m_ptr->hp);
4149 oldhp = newhp + (long)(dam);
4150 tmp = (newhp * 100L) / oldhp;
4151 percentage = (int)(tmp);
4154 /* Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs */
4155 if (strchr(",ejmvwQ", r_ptr->d_char))
4158 if (percentage > 95)
4159 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4160 else if (percentage > 75)
4161 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4162 else if (percentage > 50)
4163 msg_format("%^s¤Ï½Ì¤³¤Þ¤Ã¤¿¡£", m_name);
4164 else if (percentage > 35)
4165 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4166 else if (percentage > 20)
4167 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4168 else if (percentage > 10)
4169 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4171 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4173 if (percentage > 95)
4174 msg_format("%^s barely notices.", m_name);
4175 else if (percentage > 75)
4176 msg_format("%^s flinches.", m_name);
4177 else if (percentage > 50)
4178 msg_format("%^s squelches.", m_name);
4179 else if (percentage > 35)
4180 msg_format("%^s quivers in pain.", m_name);
4181 else if (percentage > 20)
4182 msg_format("%^s writhes about.", m_name);
4183 else if (percentage > 10)
4184 msg_format("%^s writhes in agony.", m_name);
4186 msg_format("%^s jerks limply.", m_name);
4193 else if (strchr("l", r_ptr->d_char))
4195 if (percentage > 95)
4197 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4199 msg_format("%^s barely notices.", m_name);
4201 else if (percentage > 75)
4203 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4205 msg_format("%^s flinches.", m_name);
4207 else if (percentage > 50)
4209 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4211 msg_format("%^s hesitates.", m_name);
4213 else if (percentage > 35)
4215 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4217 msg_format("%^s quivers in pain.", m_name);
4219 else if (percentage > 20)
4221 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4223 msg_format("%^s writhes about.", m_name);
4225 else if (percentage > 10)
4227 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4229 msg_format("%^s writhes in agony.", m_name);
4233 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4235 msg_format("%^s jerks limply.", m_name);
4240 /* Golems, Walls, Doors, Stairs */
4241 else if (strchr("g#+<>", r_ptr->d_char))
4243 if (percentage > 95)
4245 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4247 msg_format("%^s ignores the attack.", m_name);
4249 else if (percentage > 75)
4251 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4253 msg_format("%^s shrugs off the attack.", m_name);
4255 else if (percentage > 50)
4257 msg_format("%^s¤ÏÍëÌĤΤ褦¤ËËʤ¨¤¿¡£", m_name);
4259 msg_format("%^s roars thunderously.", m_name);
4261 else if (percentage > 35)
4263 msg_format("%^s¤Ï¶ì¤·¤²¤ËËʤ¨¤¿¡£", m_name);
4265 msg_format("%^s rumbles.", m_name);
4267 else if (percentage > 20)
4269 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4271 msg_format("%^s grunts.", m_name);
4273 else if (percentage > 10)
4275 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4277 msg_format("%^s hesitates.", m_name);
4281 msg_format("%^s¤Ï¤¯¤·¤ã¤¯¤·¤ã¤Ë¤Ê¤Ã¤¿¡£", m_name);
4283 msg_format("%^s crumples.", m_name);
4288 /* Snakes, Hydrae, Reptiles, Mimics */
4289 else if (strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char))
4291 if (percentage > 95)
4293 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4295 msg_format("%^s barely notices.", m_name);
4297 else if (percentage > 75)
4299 msg_format("%^s¤Ï¥·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4301 msg_format("%^s hisses.", m_name);
4303 else if (percentage > 50)
4305 msg_format("%^s¤ÏÅܤäÆƬ¤ò¾å¤²¤¿¡£", m_name);
4307 msg_format("%^s rears up in anger.", m_name);
4309 else if (percentage > 35)
4311 msg_format("%^s¤ÏÌÔÁ³¤È°Ò³Å¤·¤¿¡£", m_name);
4313 msg_format("%^s hisses furiously.", m_name);
4315 else if (percentage > 20)
4317 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4319 msg_format("%^s writhes about.", m_name);
4321 else if (percentage > 10)
4323 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4325 msg_format("%^s writhes in agony.", m_name);
4329 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4331 msg_format("%^s jerks limply.", m_name);
4337 else if (strchr("f", r_ptr->d_char))
4339 if (percentage > 95)
4341 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4343 msg_format("%^s shrugs off the attack.", m_name);
4345 else if (percentage > 75)
4347 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4349 msg_format("%^s roars.", m_name);
4351 else if (percentage > 50)
4353 msg_format("%^s¤ÏÅܤäÆËʤ¨¤¿¡£", m_name);
4355 msg_format("%^s growls angrily.", m_name);
4357 else if (percentage > 35)
4359 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4361 msg_format("%^s hisses with pain.", m_name);
4363 else if (percentage > 20)
4365 msg_format("%^s¤ÏÄˤߤǼ塹¤·¤¯ÌĤ¤¤¿¡£", m_name);
4367 msg_format("%^s mewls in pain.", m_name);
4369 else if (percentage > 10)
4371 msg_format("%^s¤Ï¶ìÄˤˤ¦¤á¤¤¤¿¡£", m_name);
4373 msg_format("%^s hisses in agony.", m_name);
4377 msg_format("%s¤Ï°¥¤ì¤ÊÌĤÀ¼¤ò½Ð¤·¤¿¡£", m_name);
4379 msg_format("%^s mewls pitifully.", m_name);
4384 /* Ants, Centipedes, Flies, Insects, Beetles, Spiders */
4385 else if (strchr("acFIKS", r_ptr->d_char))
4387 if (percentage > 95)
4389 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4391 msg_format("%^s ignores the attack.", m_name);
4393 else if (percentage > 75)
4395 msg_format("%^s¤Ï¥¡¼¥¡¼ÌĤ¤¤¿¡£", m_name);
4397 msg_format("%^s chitters.", m_name);
4400 else if (percentage > 50)
4402 msg_format("%^s¤Ï¥è¥í¥è¥íƨ¤²²ó¤Ã¤¿¡£", m_name);
4404 msg_format("%^s scuttles about.", m_name);
4407 else if (percentage > 35)
4409 msg_format("%^s¤Ï¤¦¤ë¤µ¤¯ÌĤ¤¤¿¡£", m_name);
4411 msg_format("%^s twitters.", m_name);
4414 else if (percentage > 20)
4416 msg_format("%^s¤ÏÄˤߤËáÛÚ»¤·¤¿¡£", m_name);
4418 msg_format("%^s jerks in pain.", m_name);
4421 else if (percentage > 10)
4423 msg_format("%^s¤Ï¶ìÄˤÇáÛÚ»¤·¤¿¡£", m_name);
4425 msg_format("%^s jerks in agony.", m_name);
4430 msg_format("%^s¤Ï¥Ô¥¯¥Ô¥¯¤Ò¤¤Ä¤Ã¤¿¡£", m_name);
4432 msg_format("%^s twitches.", m_name);
4439 else if (strchr("B", r_ptr->d_char))
4441 if (percentage > 95)
4443 msg_format("%^s¤Ï¤µ¤¨¤º¤Ã¤¿¡£", m_name);
4445 msg_format("%^s chirps.", m_name);
4448 else if (percentage > 75)
4450 msg_format("%^s¤Ï¥Ô¡¼¥Ô¡¼ÌĤ¤¤¿¡£", m_name);
4452 msg_format("%^s twitters.", m_name);
4455 else if (percentage > 50)
4457 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤¤¿¡£", m_name);
4459 msg_format("%^s squawks.", m_name);
4462 else if (percentage > 35)
4464 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4466 msg_format("%^s chatters.", m_name);
4469 else if (percentage > 20)
4471 msg_format("%^s¤Ï¶ì¤·¤ó¤À¡£", m_name);
4473 msg_format("%^s jeers.", m_name);
4476 else if (percentage > 10)
4478 msg_format("%^s¤Ï¤Î¤¿¤¦¤Á²ó¤Ã¤¿¡£", m_name);
4480 msg_format("%^s flutters about.", m_name);
4485 msg_format("%^s¤Ï¥¡¼¥¡¼¤ÈÌĤ¶«¤ó¤À¡£", m_name);
4487 msg_format("%^s squeaks.", m_name);
4493 /* Dragons, Demons, High Undead */
4494 else if (strchr("duDLUW", r_ptr->d_char))
4496 if (percentage > 95)
4498 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4500 msg_format("%^s ignores the attack.", m_name);
4503 else if (percentage > 75)
4505 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4507 msg_format("%^s flinches.", m_name);
4510 else if (percentage > 50)
4512 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4514 msg_format("%^s hisses in pain.", m_name);
4517 else if (percentage > 35)
4519 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4521 msg_format("%^s snarls with pain.", m_name);
4524 else if (percentage > 20)
4526 msg_format("%^s¤ÏÄˤߤËËʤ¨¤¿¡£", m_name);
4528 msg_format("%^s roars with pain.", m_name);
4531 else if (percentage > 10)
4533 msg_format("%^s¤Ï¶ì¤·¤²¤Ë¶«¤ó¤À¡£", m_name);
4535 msg_format("%^s gasps.", m_name);
4540 msg_format("%^s¤Ï¼å¡¹¤·¤¯¤¦¤Ê¤Ã¤¿¡£", m_name);
4542 msg_format("%^s snarls feebly.", m_name);
4549 else if (strchr("s", r_ptr->d_char))
4551 if (percentage > 95)
4553 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4555 msg_format("%^s ignores the attack.", m_name);
4558 else if (percentage > 75)
4560 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4562 msg_format("%^s shrugs off the attack.", m_name);
4565 else if (percentage > 50)
4567 msg_format("%^s¤Ï¥«¥¿¥«¥¿¤È¾Ð¤Ã¤¿¡£", m_name);
4569 msg_format("%^s rattles.", m_name);
4572 else if (percentage > 35)
4574 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4576 msg_format("%^s stumbles.", m_name);
4579 else if (percentage > 20)
4581 msg_format("%^s¤Ï¥«¥¿¥«¥¿¸À¤Ã¤¿¡£", m_name);
4583 msg_format("%^s rattles.", m_name);
4586 else if (percentage > 10)
4588 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4590 msg_format("%^s staggers.", m_name);
4595 msg_format("%^s¤Ï¥¬¥¿¥¬¥¿¸À¤Ã¤¿¡£", m_name);
4597 msg_format("%^s clatters.", m_name);
4604 else if (strchr("z", r_ptr->d_char))
4606 if (percentage > 95)
4608 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4610 msg_format("%^s ignores the attack.", m_name);
4613 else if (percentage > 75)
4615 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4617 msg_format("%^s shrugs off the attack.", m_name);
4620 else if (percentage > 50)
4622 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4624 msg_format("%^s groans.", m_name);
4627 else if (percentage > 35)
4629 msg_format("%s¤Ï¶ì¤·¤²¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4631 msg_format("%^s moans.", m_name);
4634 else if (percentage > 20)
4636 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4638 msg_format("%^s hesitates.", m_name);
4641 else if (percentage > 10)
4643 msg_format("%^s¤Ï¤¦¤Ê¤Ã¤¿¡£", m_name);
4645 msg_format("%^s grunts.", m_name);
4650 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4652 msg_format("%^s staggers.", m_name);
4659 else if (strchr("G", r_ptr->d_char))
4662 if (percentage > 95)
4664 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4666 msg_format("%^s ignores the attack.", m_name);
4669 else if (percentage > 75)
4671 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4673 msg_format("%^s shrugs off the attack.", m_name);
4676 else if (percentage > 50)
4678 msg_format("%s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4680 msg_format("%^s moans.", m_name);
4683 else if (percentage > 35)
4685 msg_format("%^s¤Ïµã¤¤ï¤á¤¤¤¿¡£", m_name);
4687 msg_format("%^s wails.", m_name);
4690 else if (percentage > 20)
4692 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4694 msg_format("%^s howls.", m_name);
4697 else if (percentage > 10)
4699 msg_format("%s¤Ï¼å¡¹¤·¤¯¤¦¤á¤¤¤¿¡£", m_name);
4701 msg_format("%^s moans softly.", m_name);
4706 msg_format("%^s¤Ï¤«¤¹¤«¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4708 msg_format("%^s sighs.", m_name);
4714 /* Dogs and Hounds */
4715 else if (strchr("CZ", r_ptr->d_char))
4718 if (percentage > 95)
4719 msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4720 else if (percentage > 75)
4721 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4722 else if (percentage > 50)
4723 msg_format("%^s¤ÏÄˤߤǥ¥ã¥ó¥¥ã¥óËʤ¨¤¿¡£", m_name);
4724 else if (percentage > 35)
4725 msg_format("%^s¤ÏÄˤߤÇÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4726 else if (percentage > 20)
4727 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4728 else if (percentage > 10)
4729 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4731 msg_format("%^s¤Ï¼å¡¹¤·¤¯Ëʤ¨¤¿¡£", m_name);
4733 if (percentage > 95)
4734 msg_format("%^s shrugs off the attack.", m_name);
4735 else if (percentage > 75)
4736 msg_format("%^s snarls with pain.", m_name);
4737 else if (percentage > 50)
4738 msg_format("%^s yelps in pain.", m_name);
4739 else if (percentage > 35)
4740 msg_format("%^s howls in pain.", m_name);
4741 else if (percentage > 20)
4742 msg_format("%^s howls in agony.", m_name);
4743 else if (percentage > 10)
4744 msg_format("%^s writhes in agony.", m_name);
4746 msg_format("%^s yelps feebly.", m_name);
4751 /* One type of monsters (ignore,squeal,shriek) */
4752 else if (strchr("Xbilqrt", r_ptr->d_char))
4755 if (percentage > 95)
4756 msg_format("%^s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4757 else if (percentage > 75)
4758 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4759 else if (percentage > 50)
4760 msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4761 else if (percentage > 35)
4762 msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4763 else if (percentage > 20)
4764 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4765 else if (percentage > 10)
4766 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4768 msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4770 if (percentage > 95)
4771 msg_format("%^s ignores the attack.", m_name);
4772 else if (percentage > 75)
4773 msg_format("%^s grunts with pain.", m_name);
4774 else if (percentage > 50)
4775 msg_format("%^s squeals in pain.", m_name);
4776 else if (percentage > 35)
4777 msg_format("%^s shrieks in pain.", m_name);
4778 else if (percentage > 20)
4779 msg_format("%^s shrieks in agony.", m_name);
4780 else if (percentage > 10)
4781 msg_format("%^s writhes in agony.", m_name);
4783 msg_format("%^s cries out feebly.", m_name);
4788 /* Another type of monsters (shrug,cry,scream) */
4792 if (percentage > 95)
4793 msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4794 else if (percentage > 75)
4795 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4796 else if (percentage > 50)
4797 msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4798 else if (percentage > 35)
4799 msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4800 else if (percentage > 20)
4801 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4802 else if (percentage > 10)
4803 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4805 msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4807 if (percentage > 95)
4808 msg_format("%^s shrugs off the attack.", m_name);
4809 else if (percentage > 75)
4810 msg_format("%^s grunts with pain.", m_name);
4811 else if (percentage > 50)
4812 msg_format("%^s cries out in pain.", m_name);
4813 else if (percentage > 35)
4814 msg_format("%^s screams in pain.", m_name);
4815 else if (percentage > 20)
4816 msg_format("%^s screams in agony.", m_name);
4817 else if (percentage > 10)
4818 msg_format("%^s writhes in agony.", m_name);
4820 msg_format("%^s cries out feebly.", m_name);
4828 * Learn about an "observed" resistance.
4830 void update_smart_learn(int m_idx, int what)
4832 #ifdef DRS_SMART_OPTIONS
4834 monster_type *m_ptr = &m_list[m_idx];
4836 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4839 /* Not allowed to learn */
4840 if (!smart_learn) return;
4842 /* Too stupid to learn anything */
4843 if (r_ptr->flags2 & (RF2_STUPID)) return;
4845 /* Not intelligent, only learn sometimes */
4846 if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4851 /* Analyze the knowledge */
4855 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4856 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
4857 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4861 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4862 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
4863 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4867 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4868 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
4869 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4873 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4874 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
4875 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4879 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4880 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
4885 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4889 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4893 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4897 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4901 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4905 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4909 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4913 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4917 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4921 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4925 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4929 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4933 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4937 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4941 #endif /* DRS_SMART_OPTIONS */
4947 * Place the player in the dungeon XXX XXX
4949 bool player_place(int y, int x)
4951 /* Paranoia XXX XXX */
4952 if (cave[y][x].m_idx != 0) return FALSE;
4954 /* Save player location */
4964 * Drop all items carried by a monster
4966 void monster_drop_carried_objects(monster_type *m_ptr)
4968 s16b this_o_idx, next_o_idx = 0;
4974 /* Drop objects being carried */
4975 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4977 /* Acquire object */
4978 o_ptr = &o_list[this_o_idx];
4980 /* Acquire next object */
4981 next_o_idx = o_ptr->next_o_idx;
4984 o_ptr->held_m_idx = 0;
4986 /* Get local object */
4989 /* Copy the object */
4990 object_copy(q_ptr, o_ptr);
4992 /* Delete the object */
4993 delete_object_idx(this_o_idx);
4996 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4999 /* Forget objects */
5000 m_ptr->hold_o_idx = 0;