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
18 cptr horror_desc[MAX_SAN_HORROR] =
72 cptr funny_desc[MAX_SAN_FUNNY] =
87 "¥Õ¥¡¥ó¥¿¥¹¥Æ¥£¥Ã¥¯¤Ê",
132 cptr funny_comments[MAX_SAN_COMMENT] =
153 * Set the target of counter attack
155 void set_target(monster_type *m_ptr, int y, int x)
163 * Reset the target of counter attack
165 void reset_target(monster_type *m_ptr)
167 set_target(m_ptr, 0, 0);
172 * Extract monster race pointer of a monster's true form
174 monster_race *real_r_ptr(monster_type *m_ptr)
176 monster_race *r_ptr = &r_info[m_ptr->r_idx];
178 /* Extract real race */
179 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
181 if (r_ptr->flags1 & RF1_UNIQUE)
182 return &r_info[MON_CHAMELEON_K];
184 return &r_info[MON_CHAMELEON];
194 * Delete a monster by index.
196 * When a monster is deleted, all of its objects are deleted.
198 void delete_monster_idx(int i)
202 monster_type *m_ptr = &m_list[i];
204 monster_race *r_ptr = &r_info[m_ptr->r_idx];
206 s16b this_o_idx, next_o_idx = 0;
214 /* Hack -- Reduce the racial counter */
215 real_r_ptr(m_ptr)->cur_num--;
217 /* Hack -- count the number of "reproducers" */
218 if (r_ptr->flags2 & (RF2_MULTIPLY)) num_repro--;
220 if (MON_CSLEEP(m_ptr)) (void)set_monster_csleep(i, 0);
221 if (MON_FAST(m_ptr)) (void)set_monster_fast(i, 0);
222 if (MON_SLOW(m_ptr)) (void)set_monster_slow(i, 0);
223 if (MON_STUNNED(m_ptr)) (void)set_monster_stunned(i, 0);
224 if (MON_CONFUSED(m_ptr)) (void)set_monster_confused(i, 0);
225 if (MON_MONFEAR(m_ptr)) (void)set_monster_monfear(i, 0);
226 if (MON_INVULNER(m_ptr)) (void)set_monster_invulner(i, 0, FALSE);
229 /* Hack -- remove target monster */
230 if (i == target_who) target_who = 0;
232 /* Hack -- remove tracked monster */
233 if (i == p_ptr->health_who) health_track(0);
235 if (pet_t_m_idx == i ) pet_t_m_idx = 0;
236 if (riding_t_m_idx == i) riding_t_m_idx = 0;
237 if (p_ptr->riding == i) p_ptr->riding = 0;
239 /* Monster is gone */
240 cave[y][x].m_idx = 0;
244 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
249 o_ptr = &o_list[this_o_idx];
251 /* Acquire next object */
252 next_o_idx = o_ptr->next_o_idx;
255 * o_ptr->held_m_idx is needed in delete_object_idx()
256 * to prevent calling lite_spot()
259 /* Delete the object */
260 delete_object_idx(this_o_idx);
264 /* Wipe the Monster */
265 (void)WIPE(m_ptr, monster_type);
273 /* Update some things */
274 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
275 p_ptr->update |= (PU_MON_LITE);
280 * Delete the monster, if any, at a given location
282 void delete_monster(int y, int x)
287 if (!in_bounds(y, x)) return;
292 /* Delete the monster (if any) */
293 if (c_ptr->m_idx) delete_monster_idx(c_ptr->m_idx);
298 * Move an object from index i1 to index i2 in the object list
300 static void compact_monsters_aux(int i1, int i2)
308 s16b this_o_idx, next_o_idx = 0;
312 if (i1 == i2) return;
325 /* Update the cave */
328 /* Repair objects being carried by monster */
329 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
334 o_ptr = &o_list[this_o_idx];
336 /* Acquire next object */
337 next_o_idx = o_ptr->next_o_idx;
339 /* Reset monster pointer */
340 o_ptr->held_m_idx = i2;
343 /* Hack -- Update the target */
344 if (target_who == i1) target_who = i2;
346 /* Hack -- Update the target */
347 if (pet_t_m_idx == i1) pet_t_m_idx = i2;
348 if (riding_t_m_idx == i1) riding_t_m_idx = i2;
350 /* Hack -- Update the riding */
351 if (p_ptr->riding == i1) p_ptr->riding = i2;
353 /* Hack -- Update the health bar */
354 if (p_ptr->health_who == i1) health_track(i2);
356 /* Hack -- Update parent index */
359 for (i = 1; i < m_max; i++)
361 monster_type *m2_ptr = &m_list[i];
363 if (m2_ptr->parent_m_idx == i1)
364 m2_ptr->parent_m_idx = i2;
369 COPY(&m_list[i2], &m_list[i1], monster_type);
372 (void)WIPE(&m_list[i1], monster_type);
374 for (i = 0; i < MAX_MTIMED; i++)
376 int mproc_idx = get_mproc_idx(i1, i);
377 if (mproc_idx >= 0) mproc_list[i][mproc_idx] = i2;
383 * Compact and Reorder the monster list
385 * This function can be very dangerous, use with caution!
387 * When actually "compacting" monsters, we base the saving throw
388 * on a combination of monster level, distance from player, and
389 * current "desperation".
391 * After "compacting" (if needed), we "reorder" the monsters into a more
392 * compact order, and we reset the allocation info, and the "live" array.
394 void compact_monsters(int size)
397 int cur_lev, cur_dis, chance;
399 /* Message (only if compacting) */
401 if (size) msg_print("¥â¥ó¥¹¥¿¡¼¾ðÊó¤ò°µ½Ì¤·¤Æ¤¤¤Þ¤¹...");
403 if (size) msg_print("Compacting monsters...");
407 /* Compact at least 'size' objects */
408 for (num = 0, cnt = 1; num < size; cnt++)
410 /* Get more vicious each iteration */
413 /* Get closer each iteration */
414 cur_dis = 5 * (20 - cnt);
416 /* Check all the monsters */
417 for (i = 1; i < m_max; i++)
419 monster_type *m_ptr = &m_list[i];
421 monster_race *r_ptr = &r_info[m_ptr->r_idx];
423 /* Paranoia -- skip "dead" monsters */
424 if (!m_ptr->r_idx) continue;
426 /* Hack -- High level monsters start out "immune" */
427 if (r_ptr->level > cur_lev) continue;
429 if (i == p_ptr->riding) continue;
431 /* Ignore nearby monsters */
432 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
434 /* Saving throw chance */
437 /* Only compact "Quest" Monsters in emergencies */
438 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
440 /* Try not to compact Unique Monsters */
441 if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
443 /* All monsters get a saving throw */
444 if (randint0(100) < chance) continue;
446 /* Delete the monster */
447 delete_monster_idx(i);
449 /* Count the monster */
455 /* Excise dead monsters (backwards!) */
456 for (i = m_max - 1; i >= 1; i--)
458 /* Get the i'th monster */
459 monster_type *m_ptr = &m_list[i];
461 /* Skip real monsters */
462 if (m_ptr->r_idx) continue;
464 /* Move last monster into open hole */
465 compact_monsters_aux(m_max - 1, i);
467 /* Compress "m_max" */
474 * Delete/Remove all the monsters when the player leaves the level
476 * This is an efficient method of simulating multiple calls to the
477 * "delete_monster()" function, with no visual effects.
479 void wipe_m_list(void)
483 /* Hack -- if Banor or Lupart dies, stay another dead */
484 if (!r_info[MON_BANORLUPART].max_num)
486 if (r_info[MON_BANOR].max_num)
488 r_info[MON_BANOR].max_num = 0;
489 r_info[MON_BANOR].r_pkills++;
490 r_info[MON_BANOR].r_akills++;
491 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
493 if (r_info[MON_LUPART].max_num)
495 r_info[MON_LUPART].max_num = 0;
496 r_info[MON_LUPART].r_pkills++;
497 r_info[MON_LUPART].r_akills++;
498 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
502 /* Delete all the monsters */
503 for (i = m_max - 1; i >= 1; i--)
505 monster_type *m_ptr = &m_list[i];
507 /* Skip dead monsters */
508 if (!m_ptr->r_idx) continue;
510 /* Monster is gone */
511 cave[m_ptr->fy][m_ptr->fx].m_idx = 0;
513 /* Wipe the Monster */
514 (void)WIPE(m_ptr, monster_type);
519 * Wiping racial counters of all monsters and incrementing of racial
520 * counters of monsters in party_mon[] are required to prevent multiple
521 * generation of unique monster who is the minion of player.
524 /* Hack -- Wipe the racial counter of all monster races */
525 for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
533 /* Reset "mproc_max[]" */
534 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
536 /* Hack -- reset "reproducer" count */
539 /* Hack -- no more target */
544 /* Hack -- no more tracking */
550 * Acquires and returns the index of a "free" monster.
552 * This routine should almost never fail, but it *can* happen.
559 /* Normal allocation */
560 if (m_max < max_m_idx)
562 /* Access the next hole */
565 /* Expand the array */
571 /* Return the index */
576 /* Recycle dead monsters */
577 for (i = 1; i < m_max; i++)
581 /* Acquire monster */
584 /* Skip live monsters */
585 if (m_ptr->r_idx) continue;
590 /* Use this monster */
595 /* Warn the player (except during dungeon creation) */
597 if (character_dungeon) msg_print("¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë¡ª");
599 if (character_dungeon) msg_print("Too many monsters!");
603 /* Try not to crash */
611 * Hack -- the "type" of the current "summon specific"
613 static int summon_specific_type = 0;
617 * Hack -- the index of the summoning monster
619 static int summon_specific_who = -1;
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 (my_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_NAZGUL))) &&
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
1475 * 0x00 --> Full nominative name ("the kobold") or "it"
1476 * MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1477 * MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1478 * MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1479 * MD_PRON_VISIBLE | MD_POSSESSIVE
1480 * --> Possessive, genderized if visable ("his") or "its"
1481 * MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1482 * --> Reflexive, genderized if visable ("himself") or "itself"
1484 void monster_desc(char *desc, monster_type *m_ptr, int mode)
1487 monster_race *r_ptr;
1491 char silly_name[1024];
1495 r_ptr = &r_info[m_ptr->ap_r_idx];
1497 /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1498 if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1499 else name = (r_name + r_ptr->name);
1501 /* Are we hallucinating? (Idea from Nethack...) */
1502 if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1507 if (!get_rnd_line("silly_j.txt", m_ptr->r_idx, silly_name))
1509 if (!get_rnd_line("silly.txt", m_ptr->r_idx, silly_name))
1517 monster_race *hallu_race;
1521 hallu_race = &r_info[randint1(max_r_idx - 1)];
1523 while (hallu_race->flags1 & RF1_UNIQUE);
1525 strcpy(silly_name, (r_name + hallu_race->name));
1528 /* Better not strcpy it, or we could corrupt r_info... */
1532 /* Can we "see" it (exists + forced, or visible + not unforced) */
1533 seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1535 /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1536 pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1539 /* First, try using pronouns, or describing hidden monsters */
1542 /* an encoding of the monster "sex" */
1545 /* Extract the gender (if applicable) */
1546 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1547 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1549 /* Ignore the gender (if desired) */
1550 if (!m_ptr || !pron) kind = 0x00;
1553 /* Assume simple result */
1561 /* Brute force: split on the possibilities */
1562 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1564 /* Neuter, or unknown */
1566 case 0x00: res = "²¿¤«"; break;
1567 case 0x00 + (MD_OBJECTIVE): res = "²¿¤«"; break;
1568 case 0x00 + (MD_POSSESSIVE): res = "²¿¤«¤Î"; break;
1569 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "²¿¤«¼«¿È"; break;
1570 case 0x00 + (MD_INDEF_HIDDEN): res = "²¿¤«"; break;
1571 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "²¿¤«"; break;
1572 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "²¿¤«"; break;
1573 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "¤½¤ì¼«¿È"; break;
1575 case 0x00: res = "it"; break;
1576 case 0x00 + (MD_OBJECTIVE): res = "it"; break;
1577 case 0x00 + (MD_POSSESSIVE): res = "its"; break;
1578 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1579 case 0x00 + (MD_INDEF_HIDDEN): res = "something"; break;
1580 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "something"; break;
1581 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "something's"; break;
1582 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1586 /* Male (assume human if vague) */
1588 case 0x10: res = "Èà"; break;
1589 case 0x10 + (MD_OBJECTIVE): res = "Èà"; break;
1590 case 0x10 + (MD_POSSESSIVE): res = "Èà¤Î"; break;
1591 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1592 case 0x10 + (MD_INDEF_HIDDEN): res = "狼"; break;
1593 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "狼"; break;
1594 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "狼¤Î"; break;
1595 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1597 case 0x10: res = "he"; break;
1598 case 0x10 + (MD_OBJECTIVE): res = "him"; break;
1599 case 0x10 + (MD_POSSESSIVE): res = "his"; break;
1600 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1601 case 0x10 + (MD_INDEF_HIDDEN): res = "someone"; break;
1602 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1603 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1604 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1608 /* Female (assume human if vague) */
1610 case 0x20: res = "Èà½÷"; break;
1611 case 0x20 + (MD_OBJECTIVE): res = "Èà½÷"; break;
1612 case 0x20 + (MD_POSSESSIVE): res = "Èà½÷¤Î"; break;
1613 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1614 case 0x20 + (MD_INDEF_HIDDEN): res = "狼"; break;
1615 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "狼"; break;
1616 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "狼¤Î"; break;
1617 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1619 case 0x20: res = "she"; break;
1620 case 0x20 + (MD_OBJECTIVE): res = "her"; break;
1621 case 0x20 + (MD_POSSESSIVE): res = "her"; break;
1622 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1623 case 0x20 + (MD_INDEF_HIDDEN): res = "someone"; break;
1624 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1625 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1626 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1630 /* Copy the result */
1631 (void)strcpy(desc, res);
1635 /* Handle visible monsters, "reflexive" request */
1636 else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1638 /* The monster is visible, so use its gender */
1640 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "Èà½÷¼«¿È");
1641 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "È༫¿È");
1642 else strcpy(desc, "¤½¤ì¼«¿È");
1644 if (r_ptr->flags1 & RF1_FEMALE) strcpy(desc, "herself");
1645 else if (r_ptr->flags1 & RF1_MALE) strcpy(desc, "himself");
1646 else strcpy(desc, "itself");
1651 /* Handle all other visible monster requests */
1655 if (is_pet(m_ptr) && !is_original_ap(m_ptr))
1661 while(strncmp(t, "¡Ù", 2) && *t) t++;
1665 (void)sprintf(desc, "%s¡©¡Ù", buf);
1668 (void)sprintf(desc, "%s¡©", name);
1670 (void)sprintf(desc, "%s?", name);
1675 /* It could be a Unique */
1676 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1678 /* Start with the name (thus nominative and objective) */
1679 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1685 while (strncmp(t, "¡Ù", 2) && *t) t++;
1689 (void)sprintf(desc, "%s¡©¡Ù", buf);
1692 (void)sprintf(desc, "%s¡©", name);
1694 (void)sprintf(desc, "%s?", name);
1698 /* Inside monster arena, and it is not your mount */
1699 else if (p_ptr->inside_battle &&
1700 !(p_ptr->riding && (&m_list[p_ptr->riding] == m_ptr)))
1702 /* It is a fake unique monster */
1704 (void)sprintf(desc, "%s¤â¤É¤", name);
1706 (void)sprintf(desc, "fake %s", name);
1712 (void)strcpy(desc, name);
1716 /* It could be an indefinite monster */
1717 else if (mode & MD_INDEF_VISIBLE)
1719 /* XXX Check plurality for "some" */
1721 /* Indefinite monsters need an indefinite article */
1723 (void)strcpy(desc, "");
1725 (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1728 (void)strcat(desc, name);
1731 /* It could be a normal, definite, monster */
1734 /* Definite monsters need a definite article */
1737 (void)strcpy(desc, "¤¢¤Ê¤¿¤Î");
1739 (void)strcpy(desc, "your ");
1744 (void)strcpy(desc, "");
1746 (void)strcpy(desc, "the ");
1749 (void)strcat(desc, name);
1752 if (m_ptr->nickname)
1755 sprintf(buf,"¡Ö%s¡×",quark_str(m_ptr->nickname));
1757 sprintf(buf," called %s",quark_str(m_ptr->nickname));
1762 if (p_ptr->riding && (&m_list[p_ptr->riding] == m_ptr))
1765 strcat(desc,"(¾èÇÏÃæ)");
1767 strcat(desc,"(riding)");
1771 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1773 if (r_ptr->flags1 & RF1_UNIQUE)
1776 strcat(desc,"(¥«¥á¥ì¥ª¥ó¤Î²¦)");
1778 strcat(desc,"(Chameleon Lord)");
1784 strcat(desc,"(¥«¥á¥ì¥ª¥ó)");
1786 strcat(desc,"(Chameleon)");
1791 if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr))
1793 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1796 /* Handle the Possessive as a special afterthought */
1797 if (mode & MD_POSSESSIVE)
1799 /* XXX Check for trailing "s" */
1801 /* Simply append "apostrophe" and "s" */
1803 (void)strcat(desc, "¤Î");
1805 (void)strcat(desc, "'s");
1815 * Learn about a monster (by "probing" it)
1817 * Return the number of new flags learnt. -Mogami-
1819 int lore_do_probe(int r_idx)
1821 monster_race *r_ptr = &r_info[r_idx];
1825 /* Maximal info about awareness */
1826 if (r_ptr->r_wake != MAX_UCHAR) n++;
1827 if (r_ptr->r_ignore != MAX_UCHAR) n++;
1828 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1830 /* Observe "maximal" attacks */
1831 for (i = 0; i < 4; i++)
1833 /* Examine "actual" blows */
1834 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1836 /* Maximal observations */
1837 if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1838 r_ptr->r_blows[i] = MAX_UCHAR;
1844 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1845 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1846 ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1847 ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1848 ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1849 ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1851 /* Only "valid" drops */
1852 if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1854 if (r_ptr->r_drop_item != tmp_byte) n++;
1855 r_ptr->r_drop_item = tmp_byte;
1857 if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1859 if (r_ptr->r_drop_gold != tmp_byte) n++;
1860 r_ptr->r_drop_gold = tmp_byte;
1863 /* Observe many spells */
1864 if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1865 r_ptr->r_cast_spell = MAX_UCHAR;
1867 /* Count unknown flags */
1868 for (i = 0; i < 32; i++)
1870 if (!(r_ptr->r_flags1 & (1L << i)) &&
1871 (r_ptr->flags1 & (1L << i))) n++;
1872 if (!(r_ptr->r_flags2 & (1L << i)) &&
1873 (r_ptr->flags2 & (1L << i))) n++;
1874 if (!(r_ptr->r_flags3 & (1L << i)) &&
1875 (r_ptr->flags3 & (1L << i))) n++;
1876 if (!(r_ptr->r_flags4 & (1L << i)) &&
1877 (r_ptr->flags4 & (1L << i))) n++;
1878 if (!(r_ptr->r_flags5 & (1L << i)) &&
1879 (r_ptr->flags5 & (1L << i))) n++;
1880 if (!(r_ptr->r_flags6 & (1L << i)) &&
1881 (r_ptr->flags6 & (1L << i))) n++;
1882 if (!(r_ptr->r_flagsr & (1L << i)) &&
1883 (r_ptr->flagsr & (1L << i))) n++;
1885 /* r_flags7 is actually unused */
1887 if (!(r_ptr->r_flags7 & (1L << i)) &&
1888 (r_ptr->flags7 & (1L << i))) n++;
1892 /* Know all the flags */
1893 r_ptr->r_flags1 = r_ptr->flags1;
1894 r_ptr->r_flags2 = r_ptr->flags2;
1895 r_ptr->r_flags3 = r_ptr->flags3;
1896 r_ptr->r_flags4 = r_ptr->flags4;
1897 r_ptr->r_flags5 = r_ptr->flags5;
1898 r_ptr->r_flags6 = r_ptr->flags6;
1899 r_ptr->r_flagsr = r_ptr->flagsr;
1901 /* r_flags7 is actually unused */
1902 /* r_ptr->r_flags7 = r_ptr->flags7; */
1904 /* Know about evolution */
1905 if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1906 r_ptr->r_xtra1 |= MR1_SINKA;
1908 /* Update monster recall window */
1909 if (p_ptr->monster_race_idx == r_idx)
1912 p_ptr->window |= (PW_MONSTER);
1915 /* Return the number of new flags learnt */
1921 * Take note that the given monster just dropped some treasure
1923 * Note that learning the "GOOD"/"GREAT" flags gives information
1924 * about the treasure (even when the monster is killed for the first
1925 * time, such as uniques, and the treasure has not been examined yet).
1927 * This "indirect" method is used to prevent the player from learning
1928 * exactly how much treasure a monster can drop from observing only
1929 * a single example of a drop. This method actually observes how much
1930 * gold and items are dropped, and remembers that information to be
1931 * described later by the monster recall code.
1933 void lore_treasure(int m_idx, int num_item, int num_gold)
1935 monster_type *m_ptr = &m_list[m_idx];
1937 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1939 /* If the monster doesn't have original appearance, don't note */
1940 if (!is_original_ap(m_ptr)) return;
1942 /* Note the number of things dropped */
1943 if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1944 if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1946 /* Hack -- memorize the good/great flags */
1947 if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1948 if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1950 /* Update monster recall window */
1951 if (p_ptr->monster_race_idx == m_ptr->r_idx)
1954 p_ptr->window |= (PW_MONSTER);
1960 void sanity_blast(monster_type *m_ptr, bool necro)
1962 bool happened = FALSE;
1965 if (p_ptr->inside_battle || !character_dungeon) return;
1970 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1972 power = r_ptr->level / 2;
1974 monster_desc(m_name, m_ptr, 0);
1976 if (!(r_ptr->flags1 & RF1_UNIQUE))
1978 if (r_ptr->flags1 & RF1_FRIENDS)
1984 return; /* No effect yet, just loaded... */
1987 return; /* Cannot see it for some reason */
1989 if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
1995 return; /* Pet eldritch horrors are safe most of the time */
1997 if (randint1(100) > power) return;
1999 if (saving_throw(p_ptr->skill_sav - power))
2001 return; /* Save, no adverse effects */
2006 /* Something silly happens... */
2008 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2009 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2011 msg_format("You behold the %s visage of %s!",
2012 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2018 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2019 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2022 return; /* Never mind; we can't see it clearly enough */
2025 /* Something frightening happens... */
2027 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2028 horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2030 msg_format("You behold the %s visage of %s!",
2031 horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2034 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2036 /* Demon characters are unaffected */
2037 if (prace_is_(RACE_IMP) || prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
2038 if (p_ptr->wizard) return;
2040 /* Undead characters are 50% likely to be unaffected */
2041 if (prace_is_(RACE_SKELETON) || prace_is_(RACE_ZOMBIE)
2042 || prace_is_(RACE_VAMPIRE) || prace_is_(RACE_SPECTRE) ||
2043 (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
2045 if (saving_throw(25 + p_ptr->lev)) return;
2051 msg_print("¥Í¥¯¥í¥Î¥ß¥³¥ó¤òÆɤó¤ÇÀµµ¤¤ò¼º¤Ã¤¿¡ª");
2053 msg_print("Your sanity is shaken by reading the Necronomicon!");
2058 if (!saving_throw(p_ptr->skill_sav - power)) /* Mind blast */
2060 if (!p_ptr->resist_conf)
2062 (void)set_confused(p_ptr->confused + randint0(4) + 4);
2064 if (!p_ptr->resist_chaos && one_in_(3))
2066 (void)set_image(p_ptr->image + randint0(250) + 150);
2071 if (!saving_throw(p_ptr->skill_sav - power)) /* Lose int & wis */
2078 if (!saving_throw(p_ptr->skill_sav - power)) /* Brain smash */
2080 if (!p_ptr->resist_conf)
2082 (void)set_confused(p_ptr->confused + randint0(4) + 4);
2084 if (!p_ptr->free_act)
2086 (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2088 while (randint0(100) > p_ptr->skill_sav)
2089 (void)do_dec_stat(A_INT);
2090 while (randint0(100) > p_ptr->skill_sav)
2091 (void)do_dec_stat(A_WIS);
2092 if (!p_ptr->resist_chaos)
2094 (void)set_image(p_ptr->image + randint0(250) + 150);
2099 if (!saving_throw(p_ptr->skill_sav - power)) /* Amnesia */
2102 if (lose_all_info())
2104 msg_print("¤¢¤Þ¤ê¤Î¶²ÉݤËÁ´¤Æ¤Î¤³¤È¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
2106 msg_print("You forget everything in your utmost terror!");
2112 if (saving_throw(p_ptr->skill_sav - power))
2117 /* Else gain permanent insanity */
2118 if ((p_ptr->muta3 & MUT3_MORONIC) && /*(p_ptr->muta2 & MUT2_BERS_RAGE) &&*/
2119 ((p_ptr->muta2 & MUT2_COWARDICE) || (p_ptr->resist_fear)) &&
2120 ((p_ptr->muta2 & MUT2_HALLU) || (p_ptr->resist_chaos)))
2122 /* The poor bastard already has all possible insanities! */
2128 switch (randint1(21))
2131 if (!(p_ptr->muta3 & MUT3_MORONIC) && one_in_(5))
2133 if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2136 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¤è¤¦¤Êµ¤¤¬¤·¤¿¡£¤·¤«¤·¤½¤ì¤Ï¸µ¡¹¤À¤Ã¤¿¡£");
2138 msg_print("You turn into an utter moron!");
2144 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¡ª");
2146 msg_print("You turn into an utter moron!");
2150 if (p_ptr->muta3 & MUT3_HYPER_INT)
2153 msg_print("¤¢¤Ê¤¿¤ÎǾ¤ÏÀ¸ÂÎ¥³¥ó¥Ô¥å¡¼¥¿¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2155 msg_print("Your brain is no longer a living computer.");
2158 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2160 p_ptr->muta3 |= MUT3_MORONIC;
2174 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2177 msg_print("¤¢¤Ê¤¿¤Ï¥Ñ¥é¥Î¥¤¥¢¤Ë¤Ê¤Ã¤¿¡ª");
2179 msg_print("You become paranoid!");
2183 /* Duh, the following should never happen, but anyway... */
2184 if (p_ptr->muta3 & MUT3_FEARLESS)
2187 msg_print("¤¢¤Ê¤¿¤Ï¤â¤¦¶²¤ìÃΤ餺¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2189 msg_print("You are no longer fearless.");
2192 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2195 p_ptr->muta2 |= MUT2_COWARDICE;
2209 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2212 msg_print("¸¸³Ð¤ò¤Ò¤µ¯¤³¤¹Àº¿ÀºøÍð¤Ë´Ù¤Ã¤¿¡ª");
2214 msg_print("You are afflicted by a hallucinatory insanity!");
2217 p_ptr->muta2 |= MUT2_HALLU;
2222 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2225 msg_print("·ãÎõ¤Ê´¶¾ð¤Îȯºî¤Ë¤ª¤½¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡ª");
2227 msg_print("You become subject to fits of berserk rage!");
2230 p_ptr->muta2 |= MUT2_BERS_RAGE;
2237 p_ptr->update |= PU_BONUS;
2243 * This function updates the monster record of the given monster
2245 * This involves extracting the distance to the player (if requested),
2246 * and then checking for visibility (natural, infravision, see-invis,
2247 * telepathy), updating the monster visibility flag, redrawing (or
2248 * erasing) the monster when its visibility changes, and taking note
2249 * of any interesting monster flags (cold-blooded, invisible, etc).
2251 * Note the new "mflag" field which encodes several monster state flags,
2252 * including "view" for when the monster is currently in line of sight,
2253 * and "mark" for when the monster is currently visible via detection.
2255 * The only monster fields that are changed here are "cdis" (the
2256 * distance from the player), "ml" (visible to the player), and
2257 * "mflag" (to maintain the "MFLAG_VIEW" flag).
2259 * Note the special "update_monsters()" function which can be used to
2260 * call this function once for every monster.
2262 * Note the "full" flag which requests that the "cdis" field be updated,
2263 * this is only needed when the monster (or the player) has moved.
2265 * Every time a monster moves, we must call this function for that
2266 * monster, and update the distance, and the visibility. Every time
2267 * the player moves, we must call this function for every monster, and
2268 * update the distance, and the visibility. Whenever the player "state"
2269 * changes in certain ways ("blindness", "infravision", "telepathy",
2270 * and "see invisible"), we must call this function for every monster,
2271 * and update the visibility.
2273 * Routines that change the "illumination" of a grid must also call this
2274 * function for any monster in that grid, since the "visibility" of some
2275 * monsters may be based on the illumination of their grid.
2277 * Note that this function is called once per monster every time the
2278 * player moves. When the player is running, this function is one
2279 * of the primary bottlenecks, along with "update_view()" and the
2280 * "process_monsters()" code, so efficiency is important.
2282 * Note the optimized "inline" version of the "distance()" function.
2284 * A monster is "visible" to the player if (1) it has been detected
2285 * by the player, (2) it is close to the player and the player has
2286 * telepathy, or (3) it is close to the player, and in line of sight
2287 * of the player, and it is "illuminated" by some combination of
2288 * infravision, torch light, or permanent light (invisible monsters
2289 * are only affected by "light" if the player can see invisible).
2291 * Monsters which are not on the current panel may be "visible" to
2292 * the player, and their descriptions will include an "offscreen"
2293 * reference. Currently, offscreen monsters cannot be targetted
2294 * or viewed directly, but old targets will remain set. XXX XXX
2296 * The player can choose to be disturbed by several things, including
2297 * "disturb_move" (monster which is viewable moves in some way), and
2298 * "disturb_near" (monster which is "easily" viewable moves in some
2299 * way). Note that "moves" includes "appears" and "disappears".
2301 void update_mon(int m_idx, bool full)
2303 monster_type *m_ptr = &m_list[m_idx];
2305 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2307 bool do_disturb = disturb_move;
2311 /* Current location */
2318 /* Seen by vision */
2321 /* Non-Ninja player in the darkness */
2322 bool in_darkness = (d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
2327 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2329 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
2333 /* Compute distance */
2336 /* Distance components */
2337 int dy = (py > fy) ? (py - fy) : (fy - py);
2338 int dx = (px > fx) ? (px - fx) : (fx - px);
2340 /* Approximate distance */
2341 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2343 /* Restrict distance */
2344 if (d > 255) d = 255;
2348 /* Save the distance */
2352 /* Extract distance */
2355 /* Extract the distance */
2361 if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
2365 if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
2367 if (!in_darkness || (d <= MAX_SIGHT / 4))
2369 if (p_ptr->special_defense & KATA_MUSOU)
2374 if (is_original_ap(m_ptr) && !p_ptr->image)
2376 /* Hack -- Memorize mental flags */
2377 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2378 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2382 /* Basic telepathy */
2383 else if (p_ptr->telepathy)
2385 /* Empty mind, no telepathy */
2386 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
2388 /* Memorize flags */
2389 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
2392 /* Weird mind, occasional telepathy */
2393 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
2395 /* One in ten individuals are detectable */
2396 if ((m_idx % 10) == 5)
2401 if (is_original_ap(m_ptr) && !p_ptr->image)
2403 /* Memorize flags */
2404 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
2406 /* Hack -- Memorize mental flags */
2407 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2408 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2413 /* Normal mind, allow telepathy */
2419 if (is_original_ap(m_ptr) && !p_ptr->image)
2421 /* Hack -- Memorize mental flags */
2422 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2423 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2428 /* Magical sensing */
2429 if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
2432 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
2435 /* Magical sensing */
2436 if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
2439 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
2442 /* Magical sensing */
2443 if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
2446 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
2449 /* Magical sensing */
2450 if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
2453 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
2456 /* Magical sensing */
2457 if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
2460 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
2463 /* Magical sensing */
2464 if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
2467 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
2470 /* Magical sensing */
2471 if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
2474 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
2477 /* Magical sensing */
2478 if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
2481 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
2484 /* Magical sensing */
2485 if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2488 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
2491 /* Magical sensing */
2492 if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2495 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
2498 /* Magical sensing */
2499 if ((p_ptr->esp_nonliving) &&
2500 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2503 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
2506 /* Magical sensing */
2507 if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2510 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
2514 /* Normal line of sight, and not blind */
2515 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2517 bool do_invisible = FALSE;
2518 bool do_cold_blood = FALSE;
2520 /* Use "infravision" */
2521 if (d <= p_ptr->see_infra)
2523 /* Handle "cold blooded" monsters */
2524 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2527 do_cold_blood = TRUE;
2530 /* Handle "warm blooded" monsters */
2538 /* Use "illumination" */
2539 if (player_can_see_bold(fy, fx))
2541 /* Handle "invisible" monsters */
2542 if (r_ptr->flags2 & (RF2_INVISIBLE))
2545 do_invisible = TRUE;
2555 /* Handle "normal" monsters */
2566 if (is_original_ap(m_ptr) && !p_ptr->image)
2568 /* Memorize flags */
2569 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2570 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2577 /* The monster is now visible */
2580 /* It was previously unseen */
2583 /* Mark as visible */
2586 /* Draw the monster */
2589 /* Update health bar as needed */
2590 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2591 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2593 /* Hack -- Count "fresh" sightings */
2596 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2597 r_info[MON_KAGE].r_sights++;
2598 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
2602 /* Eldritch Horror */
2603 if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
2605 sanity_blast(m_ptr, FALSE);
2608 /* Disturb on appearance */
2609 if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, py, px) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
2611 if (disturb_pets || is_hostile(m_ptr))
2617 /* The monster is not visible */
2620 /* It was previously seen */
2623 /* Mark as not visible */
2626 /* Erase the monster */
2629 /* Update health bar as needed */
2630 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2631 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2633 /* Disturb on disappearance */
2636 if (disturb_pets || is_hostile(m_ptr))
2643 /* The monster is now easily visible */
2647 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2649 /* Mark as easily visible */
2650 m_ptr->mflag |= (MFLAG_VIEW);
2652 /* Disturb on appearance */
2655 if (disturb_pets || is_hostile(m_ptr))
2661 /* The monster is not easily visible */
2665 if (m_ptr->mflag & (MFLAG_VIEW))
2667 /* Mark as not easily visible */
2668 m_ptr->mflag &= ~(MFLAG_VIEW);
2670 /* Disturb on disappearance */
2673 if (disturb_pets || is_hostile(m_ptr))
2682 * This function simply updates all the (non-dead) monsters (see above).
2684 void update_monsters(bool full)
2688 /* Update each (live) monster */
2689 for (i = 1; i < m_max; i++)
2691 monster_type *m_ptr = &m_list[i];
2693 /* Skip dead monsters */
2694 if (!m_ptr->r_idx) continue;
2696 /* Update the monster */
2697 update_mon(i, full);
2703 * Hack -- the index of the summoning monster
2705 static bool monster_hook_chameleon_lord(int r_idx)
2707 monster_race *r_ptr = &r_info[r_idx];
2708 monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2709 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2711 if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2712 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2714 if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2716 if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2719 if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2722 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2724 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2728 else if (summon_specific_who > 0)
2730 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2736 static bool monster_hook_chameleon(int r_idx)
2738 monster_race *r_ptr = &r_info[r_idx];
2739 monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2740 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2742 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2743 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2744 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2746 if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
2749 if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2752 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2754 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2755 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2756 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2760 else if (summon_specific_who > 0)
2762 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2765 return (*(get_monster_hook()))(r_idx);
2769 void choose_new_monster(int m_idx, bool born, int r_idx)
2772 monster_type *m_ptr = &m_list[m_idx];
2773 monster_race *r_ptr;
2774 char old_m_name[80];
2775 bool old_unique = FALSE;
2776 int old_r_idx = m_ptr->r_idx;
2778 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2780 if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2781 r_ptr = &r_info[r_idx];
2783 monster_desc(old_m_name, m_ptr, 0);
2789 chameleon_change_m_idx = m_idx;
2791 get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2793 get_mon_num_prep(monster_hook_chameleon, NULL);
2796 level = r_info[MON_CHAMELEON_K].level;
2797 else if (!dun_level)
2798 level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2802 if (d_info[dungeon_type].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2804 r_idx = get_mon_num(level);
2805 r_ptr = &r_info[r_idx];
2807 chameleon_change_m_idx = 0;
2813 m_ptr->r_idx = r_idx;
2814 m_ptr->ap_r_idx = r_idx;
2815 update_mon(m_idx, FALSE);
2816 lite_spot(m_ptr->fy, m_ptr->fx);
2818 if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2819 (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2820 p_ptr->update |= (PU_MON_LITE);
2824 /* Sub-alignment of a chameleon */
2825 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2827 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2828 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2829 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2834 if (m_idx == p_ptr->riding)
2837 monster_desc(m_name, m_ptr, 0);
2839 msg_format("ÆÍÁ³%s¤¬ÊѿȤ·¤¿¡£", old_m_name);
2841 msg_format("Suddenly, %s transforms!", old_m_name);
2843 if (!(r_ptr->flags7 & RF7_RIDING))
2845 if (rakuba(0, TRUE)) msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2847 if (rakuba(0, TRUE)) msg_format("You have fallen from %s.", m_name);
2851 /* Extract the monster base speed */
2852 m_ptr->mspeed = get_mspeed(r_ptr);
2854 oldmaxhp = m_ptr->max_maxhp;
2855 /* Assign maximal hitpoints */
2856 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2858 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2862 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2865 /* Monsters have double hitpoints in Nightmare mode */
2866 if (ironman_nightmare)
2868 u32b hp = m_ptr->max_maxhp * 2L;
2869 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
2872 m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2873 if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2874 m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2881 static bool monster_hook_tanuki(int r_idx)
2883 monster_race *r_ptr = &r_info[r_idx];
2885 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2886 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2887 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2888 if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2890 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))
2893 return (*(get_monster_hook()))(r_idx);
2898 * Set initial racial appearance of a monster
2900 static int initial_r_appearance(int r_idx)
2902 int attempts = 1000;
2905 int min = MIN(base_level-5, 50);
2907 if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2910 get_mon_num_prep(monster_hook_tanuki, NULL);
2914 ap_r_idx = get_mon_num(base_level + 10);
2915 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2923 * Get initial monster speed
2925 byte get_mspeed(monster_race *r_ptr)
2927 /* Extract the monster base speed */
2928 int mspeed = r_ptr->speed;
2930 /* Hack -- small racial variety */
2931 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2933 /* Allow some small variation per monster */
2934 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2935 if (i) mspeed += rand_spread(0, i);
2938 if (mspeed > 199) mspeed = 199;
2940 return (byte)mspeed;
2945 * Attempt to place a monster of the given race at the given location.
2947 * To give the player a sporting chance, any monster that appears in
2948 * line-of-sight and is extremely dangerous can be marked as
2949 * "FORCE_SLEEP", which will cause them to be placed with low energy,
2950 * which often (but not always) lets the player move before they do.
2952 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2954 * XXX XXX XXX Use special "here" and "dead" flags for unique monsters,
2955 * remove old "cur_num" and "max_num" fields.
2957 * XXX XXX XXX Actually, do something similar for artifacts, to simplify
2958 * the "preserve" mode, and to make the "what artifacts" flag more useful.
2960 * This is the only function which may place a monster in the dungeon,
2961 * except for the savefile loading code.
2963 static bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
2965 /* Access the location */
2966 cave_type *c_ptr = &cave[y][x];
2968 monster_type *m_ptr;
2970 monster_race *r_ptr = &r_info[r_idx];
2972 cptr name = (r_name + r_ptr->name);
2976 /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2977 if (p_ptr->wild_mode) return FALSE;
2979 /* Verify location */
2980 if (!in_bounds(y, x)) return (FALSE);
2983 if (!r_idx) return (FALSE);
2986 if (!r_ptr->name) return (FALSE);
2988 if (!(mode & PM_IGNORE_TERRAIN))
2990 /* Not on the Pattern */
2991 if (pattern_tile(y, x)) return FALSE;
2993 /* Require empty space (if not ghostly) */
2994 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
2997 if (!p_ptr->inside_battle)
2999 /* Hack -- "unique" monsters must be "unique" */
3000 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
3001 (r_ptr->flags7 & (RF7_NAZGUL))) &&
3002 (r_ptr->cur_num >= r_ptr->max_num))
3008 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
3009 (r_ptr->cur_num >= 1))
3014 if (r_idx == MON_BANORLUPART)
3016 if (r_info[MON_BANOR].cur_num > 0) return FALSE;
3017 if (r_info[MON_LUPART].cur_num > 0) return FALSE;
3020 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
3021 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
3022 (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
3029 if (quest_number(dun_level))
3031 int hoge = quest_number(dun_level);
3032 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
3034 if(r_idx == quest[hoge].r_idx)
3036 int number_mon, i2, j2;
3039 /* Count all quest monsters */
3040 for (i2 = 0; i2 < cur_wid; ++i2)
3041 for (j2 = 0; j2 < cur_hgt; j2++)
3042 if (cave[j2][i2].m_idx > 0)
3043 if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
3045 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
3051 if (is_glyph_grid(c_ptr))
3053 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
3055 /* Describe observable breakage */
3056 if (c_ptr->info & CAVE_MARK)
3059 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3061 msg_print("The rune of protection is broken!");
3066 /* Forget the rune */
3067 c_ptr->info &= ~(CAVE_MARK);
3069 /* Break the rune */
3070 c_ptr->info &= ~(CAVE_OBJECT);
3079 /* Powerful monster */
3080 if (r_ptr->level > dun_level)
3082 /* Unique monsters */
3083 if (r_ptr->flags1 & (RF1_UNIQUE))
3085 /* Message for cheaters */
3087 if (cheat_hear) msg_format("¿¼ÁؤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3089 if (cheat_hear) msg_format("Deep Unique (%s).", name);
3093 /* Normal monsters */
3096 /* Message for cheaters */
3098 if (cheat_hear) msg_format("¿¼ÁؤΥâ¥ó¥¹¥¿¡¼ (%s)¡£", name);
3100 if (cheat_hear) msg_format("Deep Monster (%s).", name);
3105 /* Note the monster */
3106 else if (r_ptr->flags1 & (RF1_UNIQUE))
3108 /* Unique monsters induce message */
3110 if (cheat_hear) msg_format("¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3112 if (cheat_hear) msg_format("Unique (%s).", name);
3117 if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
3119 /* Make a new monster */
3120 c_ptr->m_idx = m_pop();
3121 hack_m_idx_ii = c_ptr->m_idx;
3123 /* Mega-Hack -- catch "failure" */
3124 if (!c_ptr->m_idx) return (FALSE);
3127 /* Get a new monster record */
3128 m_ptr = &m_list[c_ptr->m_idx];
3131 m_ptr->r_idx = r_idx;
3132 m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3138 /* Hack -- Appearance transfer */
3139 if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(&m_list[who]))
3141 m_ptr->ap_r_idx = m_list[who].ap_r_idx;
3143 /* Hack -- Shadower spawns Shadower */
3144 if (m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
3147 /* Sub-alignment of a monster */
3148 if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3149 m_ptr->sub_align = m_list[who].sub_align;
3152 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3153 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3154 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3157 /* Place the monster at the location */
3162 /* No "timed status" yet */
3163 for (cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
3165 /* Unknown distance */
3168 reset_target(m_ptr);
3170 m_ptr->nickname = 0;
3175 /* Your pet summons its pet. */
3176 if (who > 0 && is_pet(&m_list[who]))
3178 mode |= PM_FORCE_PET;
3179 m_ptr->parent_m_idx = who;
3183 m_ptr->parent_m_idx = 0;
3186 if (r_ptr->flags7 & RF7_CHAMELEON)
3188 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3189 r_ptr = &r_info[m_ptr->r_idx];
3190 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
3192 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3193 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3194 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3196 else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
3198 m_ptr->ap_r_idx = MON_KAGE;
3199 m_ptr->mflag2 |= MFLAG2_KAGE;
3202 if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
3208 if (mode & PM_FORCE_PET)
3213 else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3214 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3216 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
3219 /* Assume no sleeping */
3220 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
3222 /* Enforce sleeping if needed */
3223 if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3225 int val = r_ptr->sleep;
3226 (void)set_monster_csleep(c_ptr->m_idx, (val * 2) + randint1(val * 10));
3229 /* Assign maximal hitpoints */
3230 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3232 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3236 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3239 /* Monsters have double hitpoints in Nightmare mode */
3240 if (ironman_nightmare)
3242 u32b hp = m_ptr->max_maxhp * 2L;
3244 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3247 m_ptr->maxhp = m_ptr->max_maxhp;
3249 /* And start out fully healthy */
3250 if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3251 m_ptr->hp = m_ptr->maxhp / 2;
3252 else m_ptr->hp = m_ptr->maxhp;
3255 /* Extract the monster base speed */
3256 m_ptr->mspeed = get_mspeed(r_ptr);
3258 if (mode & PM_HASTE) (void)set_monster_fast(c_ptr->m_idx, 100);
3260 /* Give a random starting energy */
3261 if (!ironman_nightmare)
3263 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3267 /* Nightmare monsters are more prepared */
3268 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3271 /* Force monster to wait for player, unless in Nightmare mode */
3272 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3274 /* Monster is still being nice */
3275 m_ptr->mflag |= (MFLAG_NICE);
3277 /* Must repair monsters */
3278 repair_monsters = TRUE;
3281 /* Hack -- see "process_monsters()" */
3282 if (c_ptr->m_idx < hack_m_idx)
3284 /* Monster is still being born */
3285 m_ptr->mflag |= (MFLAG_BORN);
3289 if (r_ptr->flags7 & RF7_SELF_LD_MASK)
3290 p_ptr->update |= (PU_MON_LITE);
3291 else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
3292 p_ptr->update |= (PU_MON_LITE);
3294 /* Update the monster */
3295 update_mon(c_ptr->m_idx, TRUE);
3298 /* Count the monsters on the level */
3299 real_r_ptr(m_ptr)->cur_num++;
3302 * Memorize location of the unique monster in saved floors.
3303 * A unique monster move from old saved floor.
3305 if (character_dungeon &&
3306 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
3307 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
3309 /* Hack -- Count the number of "reproducers" */
3310 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3312 /* Hack -- Notice new multi-hued monsters */
3314 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3315 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
3316 shimmer_monsters = TRUE;
3319 if (p_ptr->warning && character_dungeon)
3321 if (r_ptr->flags1 & RF1_UNIQUE)
3325 char o_name[MAX_NLEN];
3327 if (r_ptr->level > p_ptr->lev + 30)
3333 else if (r_ptr->level > p_ptr->lev + 15)
3339 else if (r_ptr->level > p_ptr->lev + 5)
3341 color = "¥ë¥Ó¡¼¿§¤Ë";
3345 else if (r_ptr->level > p_ptr->lev - 5)
3351 else if (r_ptr->level > p_ptr->lev - 15)
3353 color = "¥Ô¥ó¥¯¿§¤Ë";
3364 o_ptr = choose_warning_item();
3367 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3369 msg_format("%s¤Ï%s¸÷¤Ã¤¿¡£", o_name, color);
3371 msg_format("%s glows %s.", o_name, color);
3377 msg_format("s%¸÷¤ëʪ¤¬Æ¬¤ËÉ⤫¤ó¤À¡£", color);
3379 msg_format("An %s image forms in your mind.");
3385 if (is_explosive_rune_grid(c_ptr))
3387 /* Break the ward */
3388 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3390 /* Describe observable breakage */
3391 if (c_ptr->info & CAVE_MARK)
3394 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3396 msg_print("The rune explodes!");
3399 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);
3405 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3407 msg_print("An explosive rune was disarmed.");
3411 /* Forget the rune */
3412 c_ptr->info &= ~(CAVE_MARK);
3414 /* Break the rune */
3415 c_ptr->info &= ~(CAVE_OBJECT);
3428 * improved version of scatter() for place monster
3431 #define MON_SCAT_MAXD 10
3433 static bool mon_scatter(int r_idx, int *yp, int *xp, int y, int x, int max_dist)
3435 int place_x[MON_SCAT_MAXD];
3436 int place_y[MON_SCAT_MAXD];
3437 int num[MON_SCAT_MAXD];
3441 if (max_dist >= MON_SCAT_MAXD)
3444 for (i = 0; i < MON_SCAT_MAXD; i++)
3447 for (nx = x - max_dist; nx <= x + max_dist; nx++)
3449 for (ny = y - max_dist; ny <= y + max_dist; ny++)
3451 /* Ignore annoying locations */
3452 if (!in_bounds(ny, nx)) continue;
3454 /* Require "line of projection" */
3455 if (!projectable(y, x, ny, nx)) continue;
3459 monster_race *r_ptr = &r_info[r_idx];
3461 /* Require empty space (if not ghostly) */
3462 if (!monster_can_enter(ny, nx, r_ptr, 0))
3467 /* Walls and Monsters block flow */
3468 if (!cave_empty_bold2(ny, nx)) continue;
3470 /* ... nor on the Pattern */
3471 if (pattern_tile(ny, nx)) continue;
3474 i = distance(y, x, ny, nx);
3482 if (one_in_(num[i]))
3491 while (i < MON_SCAT_MAXD && 0 == num[i])
3493 if (i >= MON_SCAT_MAXD)
3504 * Maximum size of a group of monsters
3506 #define GROUP_MAX 32
3510 * Attempt to place a "group" of monsters around the given location
3512 static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
3514 monster_race *r_ptr = &r_info[r_idx];
3517 int total = 0, extra = 0;
3521 byte hack_y[GROUP_MAX];
3522 byte hack_x[GROUP_MAX];
3525 /* Pick a group size */
3526 total = randint1(10);
3528 /* Hard monsters, small groups */
3529 if (r_ptr->level > dun_level)
3531 extra = r_ptr->level - dun_level;
3532 extra = 0 - randint1(extra);
3535 /* Easy monsters, large groups */
3536 else if (r_ptr->level < dun_level)
3538 extra = dun_level - r_ptr->level;
3539 extra = randint1(extra);
3542 /* Hack -- limit group reduction */
3543 if (extra > 9) extra = 9;
3545 /* Modify the group size */
3549 if (total < 1) total = 1;
3552 if (total > GROUP_MAX) total = GROUP_MAX;
3555 /* Start on the monster */
3560 /* Puddle monsters, breadth first, up to total */
3561 for (n = 0; (n < hack_n) && (hack_n < total); n++)
3563 /* Grab the location */
3567 /* Check each direction, up to total */
3568 for (i = 0; (i < 8) && (hack_n < total); i++)
3572 scatter(&my, &mx, hy, hx, 4, 0);
3574 /* Walls and Monsters block flow */
3575 if (!cave_empty_bold2(my, mx)) continue;
3577 /* Attempt to place another monster */
3578 if (place_monster_one(who, my, mx, r_idx, mode))
3580 /* Add it to the "hack" set */
3581 hack_y[hack_n] = my;
3582 hack_x[hack_n] = mx;
3595 * Hack -- help pick an escort type
3597 static int place_monster_idx = 0;
3598 static int place_monster_m_idx = 0;
3601 * Hack -- help pick an escort type
3603 static bool place_monster_okay(int r_idx)
3605 monster_race *r_ptr = &r_info[place_monster_idx];
3606 monster_type *m_ptr = &m_list[place_monster_m_idx];
3608 monster_race *z_ptr = &r_info[r_idx];
3610 /* Hack - Escorts have to have the same dungeon flag */
3611 if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return (FALSE);
3613 /* Require similar "race" */
3614 if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3616 /* Skip more advanced monsters */
3617 if (z_ptr->level > r_ptr->level) return (FALSE);
3619 /* Skip unique monsters */
3620 if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3622 /* Paranoia -- Skip identical monsters */
3623 if (place_monster_idx == r_idx) return (FALSE);
3625 /* Skip different alignment */
3626 if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3628 if (r_ptr->flags7 & RF7_FRIENDLY)
3630 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3633 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3642 * Attempt to place a monster of the given race at the given location
3644 * Note that certain monsters are now marked as requiring "friends".
3645 * These monsters, if successfully placed, and if the "grp" parameter
3646 * is TRUE, will be surrounded by a "group" of identical monsters.
3648 * Note that certain monsters are now marked as requiring an "escort",
3649 * which is a collection of monsters with similar "race" but lower level.
3651 * Some monsters induce a fake "group" flag on their escorts.
3653 * Note the "bizarre" use of non-recursion to prevent annoying output
3654 * when running a code profiler.
3656 * Note the use of the new "monster allocation table" code to restrict
3657 * the "get_mon_num()" function to "legal" escort types.
3659 bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
3662 monster_race *r_ptr = &r_info[r_idx];
3664 if (!(mode & PM_NO_KAGE) && one_in_(333))
3667 /* Place one monster, or fail */
3668 if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3671 /* Require the "group" flag */
3672 if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3674 place_monster_m_idx = hack_m_idx_ii;
3676 /* Friends for certain monsters */
3677 if (r_ptr->flags1 & (RF1_FRIENDS))
3679 /* Attempt to place a group */
3680 (void)place_monster_group(who, y, x, r_idx, mode);
3684 /* Escorts for certain monsters */
3685 if (r_ptr->flags1 & (RF1_ESCORT))
3687 /* Set the escort index */
3688 place_monster_idx = r_idx;
3690 /* Try to place several "escorts" */
3691 for (i = 0; i < 32; i++)
3693 int nx, ny, z, d = 3;
3695 /* Pick a location */
3696 scatter(&ny, &nx, y, x, d, 0);
3698 /* Require empty grids */
3699 if (!cave_empty_bold2(ny, nx)) continue;
3701 /* Prepare allocation table */
3702 get_mon_num_prep(place_monster_okay, get_monster_hook2(ny, nx));
3704 /* Pick a random race */
3705 z = get_mon_num(r_ptr->level);
3707 /* Handle failure */
3710 /* Place a single escort */
3711 (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3713 /* Place a "group" of escorts if needed */
3714 if ((r_info[z].flags1 & RF1_FRIENDS) ||
3715 (r_ptr->flags1 & RF1_ESCORTS))
3717 /* Place a group of monsters */
3718 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3729 * Hack -- attempt to place a monster at the given location
3731 * Attempt to find a monster appropriate to the "monster_level"
3733 bool place_monster(int y, int x, u32b mode)
3737 /* Prepare allocation table */
3738 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3740 /* Pick a monster */
3741 r_idx = get_mon_num(monster_level);
3743 /* Handle failure */
3744 if (!r_idx) return (FALSE);
3746 /* Attempt to place the monster */
3747 if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3754 #ifdef MONSTER_HORDES
3756 bool alloc_horde(int y, int x)
3758 monster_race *r_ptr = NULL;
3761 int attempts = 1000;
3765 /* Prepare allocation table */
3766 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3770 /* Pick a monster */
3771 r_idx = get_mon_num(monster_level);
3773 /* Handle failure */
3774 if (!r_idx) return (FALSE);
3776 r_ptr = &r_info[r_idx];
3778 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3780 if (r_idx == MON_HAGURE) continue;
3783 if (attempts < 1) return FALSE;
3789 /* Attempt to place the monster */
3790 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3793 if (attempts < 1) return FALSE;
3795 m_idx = cave[y][x].m_idx;
3797 if (m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[m_list[m_idx].r_idx];
3798 summon_kin_type = r_ptr->d_char;
3800 for (attempts = randint1(10) + 5; attempts; attempts--)
3802 scatter(&cy, &cx, y, x, 5, 0);
3804 (void)summon_specific(m_idx, cy, cx, dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3813 #endif /* MONSTER_HORDES */
3819 bool alloc_guardian(bool def_val)
3821 int guardian = d_info[dungeon_type].final_guardian;
3823 if (guardian && (d_info[dungeon_type].maxdepth == dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3829 /* Find a good position */
3832 /* Get a random spot */
3833 oy = randint1(cur_hgt - 4) + 2;
3834 ox = randint1(cur_wid - 4) + 2;
3836 /* Is it a good spot ? */
3837 if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian], 0))
3839 /* Place the guardian */
3840 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3855 * Attempt to allocate a random monster in the dungeon.
3857 * Place the monster at least "dis" distance from the player.
3859 * Use "slp" to choose the initial "sleep" status
3861 * Use "monster_level" for the monster level
3863 bool alloc_monster(int dis, u32b mode)
3866 int attempts_left = 10000;
3868 /* Put the Guardian */
3869 if (alloc_guardian(FALSE)) return TRUE;
3871 /* Find a legal, distant, unoccupied, space */
3872 while (attempts_left--)
3874 /* Pick a location */
3875 y = randint0(cur_hgt);
3876 x = randint0(cur_wid);
3878 /* Require empty floor grid (was "naked") */
3881 if (!cave_empty_bold2(y, x)) continue;
3885 if (!cave_empty_bold(y, x)) continue;
3888 /* Accept far away grids */
3889 if (distance(y, x, py, px) > dis) break;
3894 if (cheat_xtra || cheat_hear)
3897 msg_print("·Ù¹ð¡ª¿·¤¿¤Ê¥â¥ó¥¹¥¿¡¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡£¾®¤µ¤¤³¬¤Ç¤¹¤«¡©");
3899 msg_print("Warning! Could not allocate a new monster. Small level?");
3908 #ifdef MONSTER_HORDES
3909 if (randint1(5000) <= dun_level)
3911 if (alloc_horde(y, x))
3914 if (cheat_hear) msg_format("¥â¥ó¥¹¥¿¡¼¤ÎÂç·²(%c)", summon_kin_type);
3916 if (cheat_hear) msg_format("Monster horde (%c).", summon_kin_type);
3924 #endif /* MONSTER_HORDES */
3926 /* Attempt to place the monster, allow groups */
3927 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3929 #ifdef MONSTER_HORDES
3931 #endif /* MONSTER_HORDES */
3941 * Hack -- help decide if a monster race is "okay" to summon
3943 static bool summon_specific_okay(int r_idx)
3945 monster_race *r_ptr = &r_info[r_idx];
3947 /* Hack - Only summon dungeon monsters */
3948 if (!mon_hook_dungeon(r_idx)) return (FALSE);
3950 /* Hack -- identify the summoning monster */
3951 if (summon_specific_who > 0)
3953 monster_type *m_ptr = &m_list[summon_specific_who];
3955 /* Do not summon enemies */
3957 /* Friendly vs. opposite aligned normal or pet */
3958 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3960 /* Use the player's alignment */
3961 else if (summon_specific_who < 0)
3963 /* Do not summon enemies of the pets */
3964 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3966 if (!one_in_(ABS(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_NAZGUL))) return FALSE;
3975 if ((summon_specific_who < 0) &&
3976 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
3977 monster_has_hostile_align(NULL, 10, -10, r_ptr))
3980 if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
3982 return (summon_specific_aux(r_idx));
3987 * Place a monster (of the specified "type") near the given
3988 * location. Return TRUE if a monster was actually summoned.
3990 * We will attempt to place the monster up to 10 times before giving up.
3992 * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3993 * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3994 * Note: None of the other summon codes will ever summon Unique's.
3996 * This function has been changed. We now take the "monster level"
3997 * of the summoning monster as a parameter, and use that, along with
3998 * the current dungeon level, to help determine the level of the
3999 * desired monster. Note that this is an upper bound, and also
4000 * tends to "prefer" monsters of that level. Currently, we use
4001 * the average of the dungeon and monster levels, and then add
4002 * five to allow slight increases in monster power.
4004 * Note that we use the new "monster allocation table" creation code
4005 * to restrict the "get_mon_num()" function to the set of "legal"
4006 * monsters, making this function much faster and more reliable.
4008 * Note that this function may not succeed, though this is very rare.
4010 bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
4014 if (p_ptr->inside_arena) return (FALSE);
4016 if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
4018 /* Save the summoner */
4019 summon_specific_who = who;
4021 /* Save the "summon" type */
4022 summon_specific_type = type;
4024 summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
4026 /* Prepare allocation table */
4027 get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
4029 /* Pick a monster, using the level calculation */
4030 r_idx = get_mon_num((dun_level + lev) / 2 + 5);
4032 /* Handle failure */
4035 summon_specific_type = 0;
4039 if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
4041 /* Attempt to place the monster (awake, allow groups) */
4042 if (!place_monster_aux(who, y, x, r_idx, mode))
4044 summon_specific_type = 0;
4048 summon_specific_type = 0;
4053 /* A "dangerous" function, creates a pet of the specified type */
4054 bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
4059 /* if (!r_idx) return; */
4061 /* Prevent illegal monsters */
4062 if (r_idx >= max_r_idx) return FALSE;
4064 if (p_ptr->inside_arena) return FALSE;
4066 if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
4068 /* Place it (allow groups) */
4069 return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
4074 * Let the given monster attempt to reproduce.
4076 * Note that "reproduction" REQUIRES empty space.
4078 bool multiply_monster(int m_idx, bool clone, u32b mode)
4080 monster_type *m_ptr = &m_list[m_idx];
4084 if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
4087 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4089 /* Create a new monster (awake, no groups) */
4090 if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
4093 /* Hack -- Transfer "clone" flag */
4094 if (clone || (m_ptr->smart & SM_CLONED))
4096 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4097 m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
4108 * Dump a message describing a monster's reaction to damage
4110 * Technically should attempt to treat "Beholder"'s as jelly's
4112 void message_pain(int m_idx, int dam)
4114 long oldhp, newhp, tmp;
4117 monster_type *m_ptr = &m_list[m_idx];
4118 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4123 /* Get the monster name */
4124 monster_desc(m_name, m_ptr, 0);
4126 /* Notice non-damage */
4130 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Æ¤¤¤Ê¤¤¡£", m_name);
4132 msg_format("%^s is unharmed.", m_name);
4138 /* Note -- subtle fix -CFT */
4139 newhp = (long)(m_ptr->hp);
4140 oldhp = newhp + (long)(dam);
4141 tmp = (newhp * 100L) / oldhp;
4142 percentage = (int)(tmp);
4145 /* Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs */
4146 if (my_strchr(",ejmvwQ", r_ptr->d_char))
4149 if (percentage > 95)
4150 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4151 else if (percentage > 75)
4152 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4153 else if (percentage > 50)
4154 msg_format("%^s¤Ï½Ì¤³¤Þ¤Ã¤¿¡£", m_name);
4155 else if (percentage > 35)
4156 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4157 else if (percentage > 20)
4158 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4159 else if (percentage > 10)
4160 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4162 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4164 if (percentage > 95)
4165 msg_format("%^s barely notices.", m_name);
4166 else if (percentage > 75)
4167 msg_format("%^s flinches.", m_name);
4168 else if (percentage > 50)
4169 msg_format("%^s squelches.", m_name);
4170 else if (percentage > 35)
4171 msg_format("%^s quivers in pain.", m_name);
4172 else if (percentage > 20)
4173 msg_format("%^s writhes about.", m_name);
4174 else if (percentage > 10)
4175 msg_format("%^s writhes in agony.", m_name);
4177 msg_format("%^s jerks limply.", m_name);
4184 else if (my_strchr("l", r_ptr->d_char))
4186 if (percentage > 95)
4188 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4190 msg_format("%^s barely notices.", m_name);
4192 else if (percentage > 75)
4194 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4196 msg_format("%^s flinches.", m_name);
4198 else if (percentage > 50)
4200 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4202 msg_format("%^s hesitates.", m_name);
4204 else if (percentage > 35)
4206 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4208 msg_format("%^s quivers in pain.", m_name);
4210 else if (percentage > 20)
4212 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4214 msg_format("%^s writhes about.", m_name);
4216 else if (percentage > 10)
4218 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4220 msg_format("%^s writhes in agony.", m_name);
4224 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4226 msg_format("%^s jerks limply.", m_name);
4231 /* Golems, Walls, Doors, Stairs */
4232 else if (my_strchr("g#+<>", r_ptr->d_char))
4234 if (percentage > 95)
4236 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4238 msg_format("%^s ignores the attack.", m_name);
4240 else if (percentage > 75)
4242 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4244 msg_format("%^s shrugs off the attack.", m_name);
4246 else if (percentage > 50)
4248 msg_format("%^s¤ÏÍëÌĤΤ褦¤ËËʤ¨¤¿¡£", m_name);
4250 msg_format("%^s roars thunderously.", m_name);
4252 else if (percentage > 35)
4254 msg_format("%^s¤Ï¶ì¤·¤²¤ËËʤ¨¤¿¡£", m_name);
4256 msg_format("%^s rumbles.", m_name);
4258 else if (percentage > 20)
4260 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4262 msg_format("%^s grunts.", m_name);
4264 else if (percentage > 10)
4266 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4268 msg_format("%^s hesitates.", m_name);
4272 msg_format("%^s¤Ï¤¯¤·¤ã¤¯¤·¤ã¤Ë¤Ê¤Ã¤¿¡£", m_name);
4274 msg_format("%^s crumples.", m_name);
4279 /* Snakes, Hydrae, Reptiles, Mimics */
4280 else if (my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char))
4282 if (percentage > 95)
4284 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4286 msg_format("%^s barely notices.", m_name);
4288 else if (percentage > 75)
4290 msg_format("%^s¤Ï¥·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4292 msg_format("%^s hisses.", m_name);
4294 else if (percentage > 50)
4296 msg_format("%^s¤ÏÅܤäÆƬ¤ò¾å¤²¤¿¡£", m_name);
4298 msg_format("%^s rears up in anger.", m_name);
4300 else if (percentage > 35)
4302 msg_format("%^s¤ÏÌÔÁ³¤È°Ò³Å¤·¤¿¡£", m_name);
4304 msg_format("%^s hisses furiously.", m_name);
4306 else if (percentage > 20)
4308 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4310 msg_format("%^s writhes about.", m_name);
4312 else if (percentage > 10)
4314 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4316 msg_format("%^s writhes in agony.", m_name);
4320 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4322 msg_format("%^s jerks limply.", m_name);
4328 else if (my_strchr("f", r_ptr->d_char))
4330 if (percentage > 95)
4332 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4334 msg_format("%^s shrugs off the attack.", m_name);
4336 else if (percentage > 75)
4338 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4340 msg_format("%^s roars.", m_name);
4342 else if (percentage > 50)
4344 msg_format("%^s¤ÏÅܤäÆËʤ¨¤¿¡£", m_name);
4346 msg_format("%^s growls angrily.", m_name);
4348 else if (percentage > 35)
4350 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4352 msg_format("%^s hisses with pain.", m_name);
4354 else if (percentage > 20)
4356 msg_format("%^s¤ÏÄˤߤǼ塹¤·¤¯ÌĤ¤¤¿¡£", m_name);
4358 msg_format("%^s mewls in pain.", m_name);
4360 else if (percentage > 10)
4362 msg_format("%^s¤Ï¶ìÄˤˤ¦¤á¤¤¤¿¡£", m_name);
4364 msg_format("%^s hisses in agony.", m_name);
4368 msg_format("%s¤Ï°¥¤ì¤ÊÌĤÀ¼¤ò½Ð¤·¤¿¡£", m_name);
4370 msg_format("%^s mewls pitifully.", m_name);
4375 /* Ants, Centipedes, Flies, Insects, Beetles, Spiders */
4376 else if (my_strchr("acFIKS", r_ptr->d_char))
4378 if (percentage > 95)
4380 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4382 msg_format("%^s ignores the attack.", m_name);
4384 else if (percentage > 75)
4386 msg_format("%^s¤Ï¥¡¼¥¡¼ÌĤ¤¤¿¡£", m_name);
4388 msg_format("%^s chitters.", m_name);
4391 else if (percentage > 50)
4393 msg_format("%^s¤Ï¥è¥í¥è¥íƨ¤²²ó¤Ã¤¿¡£", m_name);
4395 msg_format("%^s scuttles about.", m_name);
4398 else if (percentage > 35)
4400 msg_format("%^s¤Ï¤¦¤ë¤µ¤¯ÌĤ¤¤¿¡£", m_name);
4402 msg_format("%^s twitters.", m_name);
4405 else if (percentage > 20)
4407 msg_format("%^s¤ÏÄˤߤËáÛÚ»¤·¤¿¡£", m_name);
4409 msg_format("%^s jerks in pain.", m_name);
4412 else if (percentage > 10)
4414 msg_format("%^s¤Ï¶ìÄˤÇáÛÚ»¤·¤¿¡£", m_name);
4416 msg_format("%^s jerks in agony.", m_name);
4421 msg_format("%^s¤Ï¥Ô¥¯¥Ô¥¯¤Ò¤¤Ä¤Ã¤¿¡£", m_name);
4423 msg_format("%^s twitches.", m_name);
4430 else if (my_strchr("B", r_ptr->d_char))
4432 if (percentage > 95)
4434 msg_format("%^s¤Ï¤µ¤¨¤º¤Ã¤¿¡£", m_name);
4436 msg_format("%^s chirps.", m_name);
4439 else if (percentage > 75)
4441 msg_format("%^s¤Ï¥Ô¡¼¥Ô¡¼ÌĤ¤¤¿¡£", m_name);
4443 msg_format("%^s twitters.", m_name);
4446 else if (percentage > 50)
4448 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤¤¿¡£", m_name);
4450 msg_format("%^s squawks.", m_name);
4453 else if (percentage > 35)
4455 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4457 msg_format("%^s chatters.", m_name);
4460 else if (percentage > 20)
4462 msg_format("%^s¤Ï¶ì¤·¤ó¤À¡£", m_name);
4464 msg_format("%^s jeers.", m_name);
4467 else if (percentage > 10)
4469 msg_format("%^s¤Ï¤Î¤¿¤¦¤Á²ó¤Ã¤¿¡£", m_name);
4471 msg_format("%^s flutters about.", m_name);
4476 msg_format("%^s¤Ï¥¡¼¥¡¼¤ÈÌĤ¶«¤ó¤À¡£", m_name);
4478 msg_format("%^s squeaks.", m_name);
4484 /* Dragons, Demons, High Undead */
4485 else if (my_strchr("duDLUW", r_ptr->d_char))
4487 if (percentage > 95)
4489 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4491 msg_format("%^s ignores the attack.", m_name);
4494 else if (percentage > 75)
4496 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4498 msg_format("%^s flinches.", m_name);
4501 else if (percentage > 50)
4503 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4505 msg_format("%^s hisses in pain.", m_name);
4508 else if (percentage > 35)
4510 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4512 msg_format("%^s snarls with pain.", m_name);
4515 else if (percentage > 20)
4517 msg_format("%^s¤ÏÄˤߤËËʤ¨¤¿¡£", m_name);
4519 msg_format("%^s roars with pain.", m_name);
4522 else if (percentage > 10)
4524 msg_format("%^s¤Ï¶ì¤·¤²¤Ë¶«¤ó¤À¡£", m_name);
4526 msg_format("%^s gasps.", m_name);
4531 msg_format("%^s¤Ï¼å¡¹¤·¤¯¤¦¤Ê¤Ã¤¿¡£", m_name);
4533 msg_format("%^s snarls feebly.", m_name);
4540 else if (my_strchr("s", r_ptr->d_char))
4542 if (percentage > 95)
4544 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4546 msg_format("%^s ignores the attack.", m_name);
4549 else if (percentage > 75)
4551 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4553 msg_format("%^s shrugs off the attack.", m_name);
4556 else if (percentage > 50)
4558 msg_format("%^s¤Ï¥«¥¿¥«¥¿¤È¾Ð¤Ã¤¿¡£", m_name);
4560 msg_format("%^s rattles.", m_name);
4563 else if (percentage > 35)
4565 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4567 msg_format("%^s stumbles.", m_name);
4570 else if (percentage > 20)
4572 msg_format("%^s¤Ï¥«¥¿¥«¥¿¸À¤Ã¤¿¡£", m_name);
4574 msg_format("%^s rattles.", m_name);
4577 else if (percentage > 10)
4579 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4581 msg_format("%^s staggers.", m_name);
4586 msg_format("%^s¤Ï¥¬¥¿¥¬¥¿¸À¤Ã¤¿¡£", m_name);
4588 msg_format("%^s clatters.", m_name);
4595 else if (my_strchr("z", r_ptr->d_char))
4597 if (percentage > 95)
4599 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4601 msg_format("%^s ignores the attack.", m_name);
4604 else if (percentage > 75)
4606 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4608 msg_format("%^s shrugs off the attack.", m_name);
4611 else if (percentage > 50)
4613 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4615 msg_format("%^s groans.", m_name);
4618 else if (percentage > 35)
4620 msg_format("%s¤Ï¶ì¤·¤²¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4622 msg_format("%^s moans.", m_name);
4625 else if (percentage > 20)
4627 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4629 msg_format("%^s hesitates.", m_name);
4632 else if (percentage > 10)
4634 msg_format("%^s¤Ï¤¦¤Ê¤Ã¤¿¡£", m_name);
4636 msg_format("%^s grunts.", m_name);
4641 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4643 msg_format("%^s staggers.", m_name);
4650 else if (my_strchr("G", r_ptr->d_char))
4653 if (percentage > 95)
4655 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4657 msg_format("%^s ignores the attack.", m_name);
4660 else if (percentage > 75)
4662 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4664 msg_format("%^s shrugs off the attack.", m_name);
4667 else if (percentage > 50)
4669 msg_format("%s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4671 msg_format("%^s moans.", m_name);
4674 else if (percentage > 35)
4676 msg_format("%^s¤Ïµã¤¤ï¤á¤¤¤¿¡£", m_name);
4678 msg_format("%^s wails.", m_name);
4681 else if (percentage > 20)
4683 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4685 msg_format("%^s howls.", m_name);
4688 else if (percentage > 10)
4690 msg_format("%s¤Ï¼å¡¹¤·¤¯¤¦¤á¤¤¤¿¡£", m_name);
4692 msg_format("%^s moans softly.", m_name);
4697 msg_format("%^s¤Ï¤«¤¹¤«¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4699 msg_format("%^s sighs.", m_name);
4705 /* Dogs and Hounds */
4706 else if (my_strchr("CZ", r_ptr->d_char))
4709 if (percentage > 95)
4710 msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4711 else if (percentage > 75)
4712 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4713 else if (percentage > 50)
4714 msg_format("%^s¤ÏÄˤߤǥ¥ã¥ó¥¥ã¥óËʤ¨¤¿¡£", m_name);
4715 else if (percentage > 35)
4716 msg_format("%^s¤ÏÄˤߤÇÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4717 else if (percentage > 20)
4718 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4719 else if (percentage > 10)
4720 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4722 msg_format("%^s¤Ï¼å¡¹¤·¤¯Ëʤ¨¤¿¡£", m_name);
4724 if (percentage > 95)
4725 msg_format("%^s shrugs off the attack.", m_name);
4726 else if (percentage > 75)
4727 msg_format("%^s snarls with pain.", m_name);
4728 else if (percentage > 50)
4729 msg_format("%^s yelps in pain.", m_name);
4730 else if (percentage > 35)
4731 msg_format("%^s howls in pain.", m_name);
4732 else if (percentage > 20)
4733 msg_format("%^s howls in agony.", m_name);
4734 else if (percentage > 10)
4735 msg_format("%^s writhes in agony.", m_name);
4737 msg_format("%^s yelps feebly.", m_name);
4742 /* One type of monsters (ignore,squeal,shriek) */
4743 else if (my_strchr("Xbilqrt", r_ptr->d_char))
4746 if (percentage > 95)
4747 msg_format("%^s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4748 else if (percentage > 75)
4749 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4750 else if (percentage > 50)
4751 msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4752 else if (percentage > 35)
4753 msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4754 else if (percentage > 20)
4755 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4756 else if (percentage > 10)
4757 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4759 msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4761 if (percentage > 95)
4762 msg_format("%^s ignores the attack.", m_name);
4763 else if (percentage > 75)
4764 msg_format("%^s grunts with pain.", m_name);
4765 else if (percentage > 50)
4766 msg_format("%^s squeals in pain.", m_name);
4767 else if (percentage > 35)
4768 msg_format("%^s shrieks in pain.", m_name);
4769 else if (percentage > 20)
4770 msg_format("%^s shrieks in agony.", m_name);
4771 else if (percentage > 10)
4772 msg_format("%^s writhes in agony.", m_name);
4774 msg_format("%^s cries out feebly.", m_name);
4779 /* Another type of monsters (shrug,cry,scream) */
4783 if (percentage > 95)
4784 msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4785 else if (percentage > 75)
4786 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4787 else if (percentage > 50)
4788 msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4789 else if (percentage > 35)
4790 msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4791 else if (percentage > 20)
4792 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4793 else if (percentage > 10)
4794 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4796 msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4798 if (percentage > 95)
4799 msg_format("%^s shrugs off the attack.", m_name);
4800 else if (percentage > 75)
4801 msg_format("%^s grunts with pain.", m_name);
4802 else if (percentage > 50)
4803 msg_format("%^s cries out in pain.", m_name);
4804 else if (percentage > 35)
4805 msg_format("%^s screams in pain.", m_name);
4806 else if (percentage > 20)
4807 msg_format("%^s screams in agony.", m_name);
4808 else if (percentage > 10)
4809 msg_format("%^s writhes in agony.", m_name);
4811 msg_format("%^s cries out feebly.", m_name);
4819 * Learn about an "observed" resistance.
4821 void update_smart_learn(int m_idx, int what)
4823 monster_type *m_ptr = &m_list[m_idx];
4825 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4828 /* Not allowed to learn */
4829 if (!smart_learn) return;
4831 /* Too stupid to learn anything */
4832 if (r_ptr->flags2 & (RF2_STUPID)) return;
4834 /* Not intelligent, only learn sometimes */
4835 if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4840 /* Analyze the knowledge */
4844 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4845 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
4846 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4850 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4851 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
4852 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4856 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4857 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
4858 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4862 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4863 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
4864 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4868 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4869 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
4874 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4878 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4882 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4886 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4890 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4894 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4898 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4902 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4906 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4910 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4914 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4918 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4922 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4926 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4933 * Place the player in the dungeon XXX XXX
4935 bool player_place(int y, int x)
4937 /* Paranoia XXX XXX */
4938 if (cave[y][x].m_idx != 0) return FALSE;
4940 /* Save player location */
4950 * Drop all items carried by a monster
4952 void monster_drop_carried_objects(monster_type *m_ptr)
4954 s16b this_o_idx, next_o_idx = 0;
4960 /* Drop objects being carried */
4961 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4963 /* Acquire object */
4964 o_ptr = &o_list[this_o_idx];
4966 /* Acquire next object */
4967 next_o_idx = o_ptr->next_o_idx;
4969 /* Get local object */
4972 /* Copy the object */
4973 object_copy(q_ptr, o_ptr);
4975 /* Forget monster */
4976 q_ptr->held_m_idx = 0;
4978 /* Delete the object */
4979 delete_object_idx(this_o_idx);
4982 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4985 /* Forget objects */
4986 m_ptr->hold_o_idx = 0;