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 if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, FALSE);
267 /* Wipe the Monster */
268 (void)WIPE(m_ptr, monster_type);
276 /* Update some things */
277 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
278 p_ptr->update |= (PU_MON_LITE);
283 * Delete the monster, if any, at a given location
285 void delete_monster(int y, int x)
290 if (!in_bounds(y, x)) return;
295 /* Delete the monster (if any) */
296 if (c_ptr->m_idx) delete_monster_idx(c_ptr->m_idx);
301 * Move an object from index i1 to index i2 in the object list
303 static void compact_monsters_aux(int i1, int i2)
311 s16b this_o_idx, next_o_idx = 0;
315 if (i1 == i2) return;
328 /* Update the cave */
331 /* Repair objects being carried by monster */
332 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
337 o_ptr = &o_list[this_o_idx];
339 /* Acquire next object */
340 next_o_idx = o_ptr->next_o_idx;
342 /* Reset monster pointer */
343 o_ptr->held_m_idx = i2;
346 /* Hack -- Update the target */
347 if (target_who == i1) target_who = i2;
349 /* Hack -- Update the target */
350 if (pet_t_m_idx == i1) pet_t_m_idx = i2;
351 if (riding_t_m_idx == i1) riding_t_m_idx = i2;
353 /* Hack -- Update the riding */
354 if (p_ptr->riding == i1) p_ptr->riding = i2;
356 /* Hack -- Update the health bar */
357 if (p_ptr->health_who == i1) health_track(i2);
359 /* Hack -- Update parent index */
362 for (i = 1; i < m_max; i++)
364 monster_type *m2_ptr = &m_list[i];
366 if (m2_ptr->parent_m_idx == i1)
367 m2_ptr->parent_m_idx = i2;
372 COPY(&m_list[i2], &m_list[i1], monster_type);
375 (void)WIPE(&m_list[i1], monster_type);
377 for (i = 0; i < MAX_MTIMED; i++)
379 int mproc_idx = get_mproc_idx(i1, i);
380 if (mproc_idx >= 0) mproc_list[i][mproc_idx] = i2;
386 * Compact and Reorder the monster list
388 * This function can be very dangerous, use with caution!
390 * When actually "compacting" monsters, we base the saving throw
391 * on a combination of monster level, distance from player, and
392 * current "desperation".
394 * After "compacting" (if needed), we "reorder" the monsters into a more
395 * compact order, and we reset the allocation info, and the "live" array.
397 void compact_monsters(int size)
400 int cur_lev, cur_dis, chance;
402 /* Message (only if compacting) */
404 if (size) msg_print("¥â¥ó¥¹¥¿¡¼¾ðÊó¤ò°µ½Ì¤·¤Æ¤¤¤Þ¤¹...");
406 if (size) msg_print("Compacting monsters...");
410 /* Compact at least 'size' objects */
411 for (num = 0, cnt = 1; num < size; cnt++)
413 /* Get more vicious each iteration */
416 /* Get closer each iteration */
417 cur_dis = 5 * (20 - cnt);
419 /* Check all the monsters */
420 for (i = 1; i < m_max; i++)
422 monster_type *m_ptr = &m_list[i];
424 monster_race *r_ptr = &r_info[m_ptr->r_idx];
426 /* Paranoia -- skip "dead" monsters */
427 if (!m_ptr->r_idx) continue;
429 /* Hack -- High level monsters start out "immune" */
430 if (r_ptr->level > cur_lev) continue;
432 if (i == p_ptr->riding) continue;
434 /* Ignore nearby monsters */
435 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
437 /* Saving throw chance */
440 /* Only compact "Quest" Monsters in emergencies */
441 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
443 /* Try not to compact Unique Monsters */
444 if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
446 /* All monsters get a saving throw */
447 if (randint0(100) < chance) continue;
449 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
453 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
454 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
457 /* Delete the monster */
458 delete_monster_idx(i);
460 /* Count the monster */
466 /* Excise dead monsters (backwards!) */
467 for (i = m_max - 1; i >= 1; i--)
469 /* Get the i'th monster */
470 monster_type *m_ptr = &m_list[i];
472 /* Skip real monsters */
473 if (m_ptr->r_idx) continue;
475 /* Move last monster into open hole */
476 compact_monsters_aux(m_max - 1, i);
478 /* Compress "m_max" */
485 * Delete/Remove all the monsters when the player leaves the level
487 * This is an efficient method of simulating multiple calls to the
488 * "delete_monster()" function, with no visual effects.
490 void wipe_m_list(void)
494 /* Hack -- if Banor or Lupart dies, stay another dead */
495 if (!r_info[MON_BANORLUPART].max_num)
497 if (r_info[MON_BANOR].max_num)
499 r_info[MON_BANOR].max_num = 0;
500 r_info[MON_BANOR].r_pkills++;
501 r_info[MON_BANOR].r_akills++;
502 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
504 if (r_info[MON_LUPART].max_num)
506 r_info[MON_LUPART].max_num = 0;
507 r_info[MON_LUPART].r_pkills++;
508 r_info[MON_LUPART].r_akills++;
509 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
513 /* Delete all the monsters */
514 for (i = m_max - 1; i >= 1; i--)
516 monster_type *m_ptr = &m_list[i];
518 /* Skip dead monsters */
519 if (!m_ptr->r_idx) continue;
521 /* Monster is gone */
522 cave[m_ptr->fy][m_ptr->fx].m_idx = 0;
524 /* Wipe the Monster */
525 (void)WIPE(m_ptr, monster_type);
530 * Wiping racial counters of all monsters and incrementing of racial
531 * counters of monsters in party_mon[] are required to prevent multiple
532 * generation of unique monster who is the minion of player.
535 /* Hack -- Wipe the racial counter of all monster races */
536 for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
544 /* Reset "mproc_max[]" */
545 for (i = 0; i < MAX_MTIMED; i++) mproc_max[i] = 0;
547 /* Hack -- reset "reproducer" count */
550 /* Hack -- no more target */
555 /* Hack -- no more tracking */
561 * Acquires and returns the index of a "free" monster.
563 * This routine should almost never fail, but it *can* happen.
570 /* Normal allocation */
571 if (m_max < max_m_idx)
573 /* Access the next hole */
576 /* Expand the array */
582 /* Return the index */
587 /* Recycle dead monsters */
588 for (i = 1; i < m_max; i++)
592 /* Acquire monster */
595 /* Skip live monsters */
596 if (m_ptr->r_idx) continue;
601 /* Use this monster */
606 /* Warn the player (except during dungeon creation) */
608 if (character_dungeon) msg_print("¥â¥ó¥¹¥¿¡¼¤¬Â¿¤¹¤®¤ë¡ª");
610 if (character_dungeon) msg_print("Too many monsters!");
614 /* Try not to crash */
622 * Hack -- the "type" of the current "summon specific"
624 static int summon_specific_type = 0;
628 * Hack -- the index of the summoning monster
630 static int summon_specific_who = -1;
633 static bool summon_unique_okay = FALSE;
636 static bool summon_specific_aux(int r_idx)
638 monster_race *r_ptr = &r_info[r_idx];
641 /* Check our requirements */
642 switch (summon_specific_type)
646 okay = (r_ptr->d_char == 'a');
652 okay = (r_ptr->d_char == 'S');
658 okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
664 okay = (r_ptr->d_char == 'M');
670 okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
676 okay = (r_ptr->flags3 & RF3_DEMON);
682 okay = (r_ptr->flags3 & RF3_UNDEAD);
688 okay = (r_ptr->flags3 & RF3_DRAGON);
692 case SUMMON_HI_UNDEAD:
694 okay = ((r_ptr->d_char == 'L') ||
695 (r_ptr->d_char == 'V') ||
696 (r_ptr->d_char == 'W'));
700 case SUMMON_HI_DRAGON:
702 okay = (r_ptr->d_char == 'D');
706 case SUMMON_HI_DEMON:
708 okay = (((r_ptr->d_char == 'U') ||
709 (r_ptr->d_char == 'H') ||
710 (r_ptr->d_char == 'B')) &&
711 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
715 case SUMMON_AMBERITES:
717 okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
723 okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
727 case SUMMON_BIZARRE1:
729 okay = (r_ptr->d_char == 'm');
732 case SUMMON_BIZARRE2:
734 okay = (r_ptr->d_char == 'b');
737 case SUMMON_BIZARRE3:
739 okay = (r_ptr->d_char == 'Q');
743 case SUMMON_BIZARRE4:
745 okay = (r_ptr->d_char == 'v');
749 case SUMMON_BIZARRE5:
751 okay = (r_ptr->d_char == '$');
755 case SUMMON_BIZARRE6:
757 okay = ((r_ptr->d_char == '!') ||
758 (r_ptr->d_char == '?') ||
759 (r_ptr->d_char == '=') ||
760 (r_ptr->d_char == '$') ||
761 (r_ptr->d_char == '|'));
767 okay = (r_ptr->d_char == 'g');
773 okay = ((r_ptr->d_char == 'U') &&
774 (r_ptr->flags4 & RF4_ROCKET));
781 okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
787 okay = (r_idx == MON_DAWN);
793 okay = (r_ptr->flags3 & (RF3_ANIMAL));
797 case SUMMON_ANIMAL_RANGER:
799 okay = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
800 (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
801 !(r_ptr->flags3 & (RF3_DRAGON)) &&
802 !(r_ptr->flags3 & (RF3_EVIL)) &&
803 !(r_ptr->flags3 & (RF3_UNDEAD)) &&
804 !(r_ptr->flags3 & (RF3_DEMON)) &&
805 !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
806 !(r_ptr->flags4 || r_ptr->flags5 || r_ptr->flags6));
810 case SUMMON_HI_DRAGON_LIVING:
812 okay = ((r_ptr->d_char == 'D') && monster_living(r_ptr));
818 okay = monster_living(r_ptr);
824 okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
828 case SUMMON_BLUE_HORROR:
830 okay = (r_idx == MON_BLUE_HORROR);
834 case SUMMON_ELEMENTAL:
836 okay = (r_ptr->d_char == 'E');
842 okay = (r_ptr->d_char == 'v');
848 okay = (r_ptr->d_char == 'H');
854 okay = (r_ptr->d_char == 'B');
858 case SUMMON_KAMIKAZE:
861 for (i = 0; i < 4; i++)
862 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
866 case SUMMON_KAMIKAZE_LIVING:
870 for (i = 0; i < 4; i++)
871 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
872 okay = (okay && monster_living(r_ptr));
878 okay = (r_idx == MON_MANES);
884 okay = (r_idx == MON_LOUSE);
888 case SUMMON_GUARDIANS:
890 okay = (r_ptr->flags7 & RF7_GUARDIAN);
896 okay = ((r_idx == MON_NOV_PALADIN) ||
897 (r_idx == MON_NOV_PALADIN_G) ||
898 (r_idx == MON_PALADIN) ||
899 (r_idx == MON_W_KNIGHT) ||
900 (r_idx == MON_ULTRA_PALADIN) ||
901 (r_idx == MON_KNI_TEMPLAR));
907 okay = (r_ptr->d_char == 'B' &&
908 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
909 (r_ptr->flags8 & RF8_WILD_ONLY));
913 case SUMMON_PIRANHAS:
915 okay = (r_idx == MON_PIRANHA);
919 case SUMMON_ARMAGE_GOOD:
921 okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
925 case SUMMON_ARMAGE_EVIL:
927 okay = ((r_ptr->flags3 & RF3_DEMON) ||
928 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
934 /* Since okay is int, "return (okay);" is not correct. */
935 return (bool)(okay ? TRUE : FALSE);
939 static int chameleon_change_m_idx = 0;
943 * Some dungeon types restrict the possible monsters.
944 * Return TRUE is the monster is OK and FALSE otherwise
946 static bool restrict_monster_to_dungeon(int r_idx)
948 dungeon_info_type *d_ptr = &d_info[dungeon_type];
949 monster_race *r_ptr = &r_info[r_idx];
952 if (d_ptr->flags1 & DF1_CHAMELEON)
954 if (chameleon_change_m_idx) return TRUE;
956 if (d_ptr->flags1 & DF1_NO_MAGIC)
958 if (r_idx != MON_CHAMELEON &&
960 !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
961 !(r_ptr->flags5 & RF5_NOMAGIC_MASK) &&
962 !(r_ptr->flags6 & RF6_NOMAGIC_MASK))
965 if (d_ptr->flags1 & DF1_NO_MELEE)
967 if (r_idx == MON_CHAMELEON) return TRUE;
968 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
969 !(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)) &&
970 !(r_ptr->flags6 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
973 if (d_ptr->flags1 & DF1_BEGINNER)
975 if (r_ptr->level > dun_level)
979 if (d_ptr->special_div >= 64) return TRUE;
980 if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
984 case DUNGEON_MODE_AND:
987 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
992 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
997 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
1002 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
1007 if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
1012 if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
1017 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1022 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1027 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1032 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1035 for (a = 0; a < 5; a++)
1036 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
1040 case DUNGEON_MODE_NAND:
1043 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
1048 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
1053 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
1058 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
1063 if ((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
1068 if ((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
1073 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
1078 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
1083 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
1088 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
1091 for (a = 0; a < 5; a++)
1092 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
1096 case DUNGEON_MODE_OR:
1097 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
1098 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
1099 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
1100 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
1101 if (r_ptr->flags5 & d_ptr->mflags5) return TRUE;
1102 if (r_ptr->flags6 & d_ptr->mflags6) return TRUE;
1103 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
1104 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
1105 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
1106 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
1107 for (a = 0; a < 5; a++)
1108 if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
1112 case DUNGEON_MODE_NOR:
1113 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
1114 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
1115 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
1116 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
1117 if (r_ptr->flags5 & d_ptr->mflags5) return FALSE;
1118 if (r_ptr->flags6 & d_ptr->mflags6) return FALSE;
1119 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
1120 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
1121 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
1122 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
1123 for (a = 0; a < 5; a++)
1124 if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1133 * Apply a "monster restriction function" to the "monster allocation table"
1135 errr get_mon_num_prep(monster_hook_type monster_hook,
1136 monster_hook_type monster_hook2)
1140 /* Todo: Check the hooks for non-changes */
1142 /* Set the new hooks */
1143 get_mon_num_hook = monster_hook;
1144 get_mon_num2_hook = monster_hook2;
1146 /* Scan the allocation table */
1147 for (i = 0; i < alloc_race_size; i++)
1149 monster_race *r_ptr;
1152 alloc_entry *entry = &alloc_race_table[i];
1155 r_ptr = &r_info[entry->index];
1157 /* Skip monsters which don't pass the restriction */
1158 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1159 (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1162 if (!p_ptr->inside_battle && !chameleon_change_m_idx &&
1163 summon_specific_type != SUMMON_GUARDIANS)
1165 /* Hack -- don't create questors */
1166 if (r_ptr->flags1 & RF1_QUESTOR)
1169 if (r_ptr->flags7 & RF7_GUARDIAN)
1172 /* Depth Monsters never appear out of depth */
1173 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1174 (r_ptr->level > dun_level))
1178 /* Accept this monster */
1179 entry->prob2 = entry->prob1;
1181 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)
1183 int hoge = entry->prob2 * d_info[dungeon_type].special_div;
1184 entry->prob2 = hoge / 64;
1185 if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1194 static int mysqrt(int n)
1232 * Choose a monster race that seems "appropriate" to the given level
1234 * This function uses the "prob2" field of the "monster allocation table",
1235 * and various local information, to calculate the "prob3" field of the
1236 * same table, which is then used to choose an "appropriate" monster, in
1237 * a relatively efficient manner.
1239 * Note that "town" monsters will *only* be created in the town, and
1240 * "normal" monsters will *never* be created in the town, unless the
1241 * "level" is "modified", for example, by polymorph or summoning.
1243 * There is a small chance (1/50) of "boosting" the given depth by
1244 * a small amount (up to four levels), except in the town.
1246 * It is (slightly) more likely to acquire a monster of the given level
1247 * than one of a lower level. This is done by choosing several monsters
1248 * appropriate to the given level and keeping the "hardest" one.
1250 * Note that if no monsters are "appropriate", then this function will
1251 * fail, and return zero, but this should *almost* never happen.
1253 s16b get_mon_num(int level)
1261 monster_race *r_ptr;
1263 alloc_entry *table = alloc_race_table;
1265 int pls_kakuritu, pls_level;
1266 int hoge=mysqrt(level*10000L);
1268 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1270 if ((dungeon_turn > hoge*(TURNS_PER_TICK*500L)) && !level)
1272 pls_kakuritu = MAX(2, NASTY_MON-((dungeon_turn/(TURNS_PER_TICK*2500L)-hoge/10)));
1273 pls_level = MIN(8,3 + dungeon_turn/(TURNS_PER_TICK*20000L)-hoge/40);
1277 pls_kakuritu = NASTY_MON;
1281 if (d_info[dungeon_type].flags1 & DF1_MAZE)
1283 pls_kakuritu = MIN(pls_kakuritu/2, pls_kakuritu-10);
1284 if (pls_kakuritu < 2) pls_kakuritu = 2;
1289 /* Boost the level */
1290 if ((level > 0) && !p_ptr->inside_battle && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
1292 /* Nightmare mode allows more out-of depth monsters */
1293 if (ironman_nightmare && !randint0(pls_kakuritu))
1295 /* What a bizarre calculation */
1296 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1300 /* Occasional "nasty" monster */
1301 if (!randint0(pls_kakuritu))
1303 /* Pick a level bonus */
1304 int d = MIN(5, level/10) + pls_level;
1306 /* Boost the level */
1310 /* Occasional "nasty" monster */
1311 if (!randint0(pls_kakuritu))
1313 /* Pick a level bonus */
1314 int d = MIN(5, level/10) + pls_level;
1316 /* Boost the level */
1326 /* Process probabilities */
1327 for (i = 0; i < alloc_race_size; i++)
1329 /* Monsters are sorted by depth */
1330 if (table[i].level > level) break;
1335 /* Access the "r_idx" of the chosen monster */
1336 r_idx = table[i].index;
1338 /* Access the actual race */
1339 r_ptr = &r_info[r_idx];
1341 if (!p_ptr->inside_battle && !chameleon_change_m_idx)
1343 /* Hack -- "unique" monsters must be "unique" */
1344 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1345 (r_ptr->flags7 & (RF7_NAZGUL))) &&
1346 (r_ptr->cur_num >= r_ptr->max_num))
1351 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1352 (r_ptr->cur_num >= 1))
1357 if (r_idx == MON_BANORLUPART)
1359 if (r_info[MON_BANOR].cur_num > 0) continue;
1360 if (r_info[MON_LUPART].cur_num > 0) continue;
1365 table[i].prob3 = table[i].prob2;
1368 total += table[i].prob3;
1371 /* No legal monsters */
1372 if (total <= 0) return (0);
1375 /* Pick a monster */
1376 value = randint0(total);
1378 /* Find the monster */
1379 for (i = 0; i < alloc_race_size; i++)
1381 /* Found the entry */
1382 if (value < table[i].prob3) break;
1385 value = value - table[i].prob3;
1392 /* Try for a "harder" monster once (50%) or twice (10%) */
1398 /* Pick a monster */
1399 value = randint0(total);
1401 /* Find the monster */
1402 for (i = 0; i < alloc_race_size; i++)
1404 /* Found the entry */
1405 if (value < table[i].prob3) break;
1408 value = value - table[i].prob3;
1411 /* Keep the "best" one */
1412 if (table[i].level < table[j].level) i = j;
1415 /* Try for a "harder" monster twice (10%) */
1421 /* Pick a monster */
1422 value = randint0(total);
1424 /* Find the monster */
1425 for (i = 0; i < alloc_race_size; i++)
1427 /* Found the entry */
1428 if (value < table[i].prob3) break;
1431 value = value - table[i].prob3;
1434 /* Keep the "best" one */
1435 if (table[i].level < table[j].level) i = j;
1439 return (table[i].index);
1447 * Build a string describing a monster in some way.
1449 * We can correctly describe monsters based on their visibility.
1450 * We can force all monsters to be treated as visible or invisible.
1451 * We can build nominatives, objectives, possessives, or reflexives.
1452 * We can selectively pronominalize hidden, visible, or all monsters.
1453 * We can use definite or indefinite descriptions for hidden monsters.
1454 * We can use definite or indefinite descriptions for visible monsters.
1456 * Pronominalization involves the gender whenever possible and allowed,
1457 * so that by cleverly requesting pronominalization / visibility, you
1458 * can get messages like "You hit someone. She screams in agony!".
1460 * Reflexives are acquired by requesting Objective plus Possessive.
1462 * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1463 * unless the "Assume Visible" mode is requested.
1465 * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1466 * If neither m_ptr nor r_ptr is given, the monster is assumed to
1467 * be neuter, singular, and hidden (unless "Assume Visible" is set),
1468 * in which case you may be in trouble... :-)
1470 * I am assuming that no monster name is more than 70 characters long,
1471 * so that "char desc[80];" is sufficiently large for any result.
1474 * MD_OBJECTIVE --> Objective (or Reflexive)
1475 * MD_POSSESSIVE --> Possessive (or Reflexive)
1476 * MD_INDEF_HIDDEN --> Use indefinites for hidden monsters ("something")
1477 * MD_INDEF_VISIBLE --> Use indefinites for visible monsters ("a kobold")
1478 * MD_PRON_HIDDEN --> Pronominalize hidden monsters
1479 * MD_PRON_VISIBLE --> Pronominalize visible monsters
1480 * MD_ASSUME_HIDDEN --> Assume the monster is hidden
1481 * MD_ASSUME_VISIBLE --> Assume the monster is visible
1482 * MD_TRUE_NAME --> Chameleon's true name
1483 * MD_IGNORE_HALLU --> Ignore hallucination, and penetrate shape change
1486 * 0x00 --> Full nominative name ("the kobold") or "it"
1487 * MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1488 * MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1489 * MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1490 * MD_PRON_VISIBLE | MD_POSSESSIVE
1491 * --> Possessive, genderized if visable ("his") or "its"
1492 * MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1493 * --> Reflexive, genderized if visable ("himself") or "itself"
1495 void monster_desc(char *desc, monster_type *m_ptr, int mode)
1498 monster_race *r_ptr;
1502 char silly_name[1024];
1506 r_ptr = &r_info[m_ptr->ap_r_idx];
1508 /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1509 if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1510 else name = (r_name + r_ptr->name);
1512 /* Are we hallucinating? (Idea from Nethack...) */
1513 if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1518 if (!get_rnd_line("silly_j.txt", m_ptr->r_idx, silly_name))
1520 if (!get_rnd_line("silly.txt", m_ptr->r_idx, silly_name))
1528 monster_race *hallu_race;
1532 hallu_race = &r_info[randint1(max_r_idx - 1)];
1534 while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
1536 strcpy(silly_name, (r_name + hallu_race->name));
1539 /* Better not strcpy it, or we could corrupt r_info... */
1543 /* Can we "see" it (exists + forced, or visible + not unforced) */
1544 seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1546 /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1547 pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1550 /* First, try using pronouns, or describing hidden monsters */
1553 /* an encoding of the monster "sex" */
1556 /* Extract the gender (if applicable) */
1557 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1558 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1560 /* Ignore the gender (if desired) */
1561 if (!m_ptr || !pron) kind = 0x00;
1564 /* Assume simple result */
1572 /* Brute force: split on the possibilities */
1573 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1575 /* Neuter, or unknown */
1577 case 0x00: res = "²¿¤«"; break;
1578 case 0x00 + (MD_OBJECTIVE): res = "²¿¤«"; break;
1579 case 0x00 + (MD_POSSESSIVE): res = "²¿¤«¤Î"; break;
1580 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "²¿¤«¼«¿È"; break;
1581 case 0x00 + (MD_INDEF_HIDDEN): res = "²¿¤«"; break;
1582 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "²¿¤«"; break;
1583 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "²¿¤«"; break;
1584 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "¤½¤ì¼«¿È"; break;
1586 case 0x00: res = "it"; break;
1587 case 0x00 + (MD_OBJECTIVE): res = "it"; break;
1588 case 0x00 + (MD_POSSESSIVE): res = "its"; break;
1589 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1590 case 0x00 + (MD_INDEF_HIDDEN): res = "something"; break;
1591 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "something"; break;
1592 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "something's"; break;
1593 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1597 /* Male (assume human if vague) */
1599 case 0x10: res = "Èà"; break;
1600 case 0x10 + (MD_OBJECTIVE): res = "Èà"; break;
1601 case 0x10 + (MD_POSSESSIVE): res = "Èà¤Î"; break;
1602 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1603 case 0x10 + (MD_INDEF_HIDDEN): res = "狼"; break;
1604 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "狼"; break;
1605 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "狼¤Î"; break;
1606 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "È༫¿È"; break;
1608 case 0x10: res = "he"; break;
1609 case 0x10 + (MD_OBJECTIVE): res = "him"; break;
1610 case 0x10 + (MD_POSSESSIVE): res = "his"; break;
1611 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1612 case 0x10 + (MD_INDEF_HIDDEN): res = "someone"; break;
1613 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1614 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1615 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1619 /* Female (assume human if vague) */
1621 case 0x20: res = "Èà½÷"; break;
1622 case 0x20 + (MD_OBJECTIVE): res = "Èà½÷"; break;
1623 case 0x20 + (MD_POSSESSIVE): res = "Èà½÷¤Î"; break;
1624 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1625 case 0x20 + (MD_INDEF_HIDDEN): res = "狼"; break;
1626 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "狼"; break;
1627 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "狼¤Î"; break;
1628 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "Èà½÷¼«¿È"; break;
1630 case 0x20: res = "she"; break;
1631 case 0x20 + (MD_OBJECTIVE): res = "her"; break;
1632 case 0x20 + (MD_POSSESSIVE): res = "her"; break;
1633 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1634 case 0x20 + (MD_INDEF_HIDDEN): res = "someone"; break;
1635 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1636 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1637 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1641 /* Copy the result */
1642 (void)strcpy(desc, res);
1646 /* Handle visible monsters, "reflexive" request */
1647 else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1649 /* The monster is visible, so use its gender */
1651 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "Èà½÷¼«¿È");
1652 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "È༫¿È");
1653 else strcpy(desc, "¤½¤ì¼«¿È");
1655 if (r_ptr->flags1 & RF1_FEMALE) strcpy(desc, "herself");
1656 else if (r_ptr->flags1 & RF1_MALE) strcpy(desc, "himself");
1657 else strcpy(desc, "itself");
1662 /* Handle all other visible monster requests */
1666 if (is_pet(m_ptr) && !is_original_ap(m_ptr))
1672 while(strncmp(t, "¡Ù", 2) && *t) t++;
1676 (void)sprintf(desc, "%s¡©¡Ù", buf);
1679 (void)sprintf(desc, "%s¡©", name);
1681 (void)sprintf(desc, "%s?", name);
1686 /* It could be a Unique */
1687 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1689 /* Start with the name (thus nominative and objective) */
1690 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1696 while (strncmp(t, "¡Ù", 2) && *t) t++;
1700 (void)sprintf(desc, "%s¡©¡Ù", buf);
1703 (void)sprintf(desc, "%s¡©", name);
1705 (void)sprintf(desc, "%s?", name);
1709 /* Inside monster arena, and it is not your mount */
1710 else if (p_ptr->inside_battle &&
1711 !(p_ptr->riding && (&m_list[p_ptr->riding] == m_ptr)))
1713 /* It is a fake unique monster */
1715 (void)sprintf(desc, "%s¤â¤É¤", name);
1717 (void)sprintf(desc, "fake %s", name);
1723 (void)strcpy(desc, name);
1727 /* It could be an indefinite monster */
1728 else if (mode & MD_INDEF_VISIBLE)
1730 /* XXX Check plurality for "some" */
1732 /* Indefinite monsters need an indefinite article */
1734 (void)strcpy(desc, "");
1736 (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1739 (void)strcat(desc, name);
1742 /* It could be a normal, definite, monster */
1745 /* Definite monsters need a definite article */
1748 (void)strcpy(desc, "¤¢¤Ê¤¿¤Î");
1750 (void)strcpy(desc, "your ");
1755 (void)strcpy(desc, "");
1757 (void)strcpy(desc, "the ");
1760 (void)strcat(desc, name);
1763 if (m_ptr->nickname)
1766 sprintf(buf,"¡Ö%s¡×",quark_str(m_ptr->nickname));
1768 sprintf(buf," called %s",quark_str(m_ptr->nickname));
1773 if (p_ptr->riding && (&m_list[p_ptr->riding] == m_ptr))
1776 strcat(desc,"(¾èÇÏÃæ)");
1778 strcat(desc,"(riding)");
1782 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1784 if (r_ptr->flags1 & RF1_UNIQUE)
1787 strcat(desc,"(¥«¥á¥ì¥ª¥ó¤Î²¦)");
1789 strcat(desc,"(Chameleon Lord)");
1795 strcat(desc,"(¥«¥á¥ì¥ª¥ó)");
1797 strcat(desc,"(Chameleon)");
1802 if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr))
1804 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1807 /* Handle the Possessive as a special afterthought */
1808 if (mode & MD_POSSESSIVE)
1810 /* XXX Check for trailing "s" */
1812 /* Simply append "apostrophe" and "s" */
1814 (void)strcat(desc, "¤Î");
1816 (void)strcat(desc, "'s");
1826 * Learn about a monster (by "probing" it)
1828 * Return the number of new flags learnt. -Mogami-
1830 int lore_do_probe(int r_idx)
1832 monster_race *r_ptr = &r_info[r_idx];
1836 /* Maximal info about awareness */
1837 if (r_ptr->r_wake != MAX_UCHAR) n++;
1838 if (r_ptr->r_ignore != MAX_UCHAR) n++;
1839 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1841 /* Observe "maximal" attacks */
1842 for (i = 0; i < 4; i++)
1844 /* Examine "actual" blows */
1845 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1847 /* Maximal observations */
1848 if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1849 r_ptr->r_blows[i] = MAX_UCHAR;
1855 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1856 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1857 ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1858 ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1859 ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1860 ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1862 /* Only "valid" drops */
1863 if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1865 if (r_ptr->r_drop_item != tmp_byte) n++;
1866 r_ptr->r_drop_item = tmp_byte;
1868 if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1870 if (r_ptr->r_drop_gold != tmp_byte) n++;
1871 r_ptr->r_drop_gold = tmp_byte;
1874 /* Observe many spells */
1875 if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1876 r_ptr->r_cast_spell = MAX_UCHAR;
1878 /* Count unknown flags */
1879 for (i = 0; i < 32; i++)
1881 if (!(r_ptr->r_flags1 & (1L << i)) &&
1882 (r_ptr->flags1 & (1L << i))) n++;
1883 if (!(r_ptr->r_flags2 & (1L << i)) &&
1884 (r_ptr->flags2 & (1L << i))) n++;
1885 if (!(r_ptr->r_flags3 & (1L << i)) &&
1886 (r_ptr->flags3 & (1L << i))) n++;
1887 if (!(r_ptr->r_flags4 & (1L << i)) &&
1888 (r_ptr->flags4 & (1L << i))) n++;
1889 if (!(r_ptr->r_flags5 & (1L << i)) &&
1890 (r_ptr->flags5 & (1L << i))) n++;
1891 if (!(r_ptr->r_flags6 & (1L << i)) &&
1892 (r_ptr->flags6 & (1L << i))) n++;
1893 if (!(r_ptr->r_flagsr & (1L << i)) &&
1894 (r_ptr->flagsr & (1L << i))) n++;
1896 /* r_flags7 is actually unused */
1898 if (!(r_ptr->r_flags7 & (1L << i)) &&
1899 (r_ptr->flags7 & (1L << i))) n++;
1903 /* Know all the flags */
1904 r_ptr->r_flags1 = r_ptr->flags1;
1905 r_ptr->r_flags2 = r_ptr->flags2;
1906 r_ptr->r_flags3 = r_ptr->flags3;
1907 r_ptr->r_flags4 = r_ptr->flags4;
1908 r_ptr->r_flags5 = r_ptr->flags5;
1909 r_ptr->r_flags6 = r_ptr->flags6;
1910 r_ptr->r_flagsr = r_ptr->flagsr;
1912 /* r_flags7 is actually unused */
1913 /* r_ptr->r_flags7 = r_ptr->flags7; */
1915 /* Know about evolution */
1916 if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1917 r_ptr->r_xtra1 |= MR1_SINKA;
1919 /* Update monster recall window */
1920 if (p_ptr->monster_race_idx == r_idx)
1923 p_ptr->window |= (PW_MONSTER);
1926 /* Return the number of new flags learnt */
1932 * Take note that the given monster just dropped some treasure
1934 * Note that learning the "GOOD"/"GREAT" flags gives information
1935 * about the treasure (even when the monster is killed for the first
1936 * time, such as uniques, and the treasure has not been examined yet).
1938 * This "indirect" method is used to prevent the player from learning
1939 * exactly how much treasure a monster can drop from observing only
1940 * a single example of a drop. This method actually observes how much
1941 * gold and items are dropped, and remembers that information to be
1942 * described later by the monster recall code.
1944 void lore_treasure(int m_idx, int num_item, int num_gold)
1946 monster_type *m_ptr = &m_list[m_idx];
1948 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1950 /* If the monster doesn't have original appearance, don't note */
1951 if (!is_original_ap(m_ptr)) return;
1953 /* Note the number of things dropped */
1954 if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1955 if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1957 /* Hack -- memorize the good/great flags */
1958 if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1959 if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1961 /* Update monster recall window */
1962 if (p_ptr->monster_race_idx == m_ptr->r_idx)
1965 p_ptr->window |= (PW_MONSTER);
1971 void sanity_blast(monster_type *m_ptr, bool necro)
1973 bool happened = FALSE;
1976 if (p_ptr->inside_battle || !character_dungeon) return;
1981 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
1983 power = r_ptr->level / 2;
1985 monster_desc(m_name, m_ptr, 0);
1987 if (!(r_ptr->flags1 & RF1_UNIQUE))
1989 if (r_ptr->flags1 & RF1_FRIENDS)
1995 return; /* No effect yet, just loaded... */
1998 return; /* Cannot see it for some reason */
2000 if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
2006 return; /* Pet eldritch horrors are safe most of the time */
2008 if (randint1(100) > power) return;
2010 if (saving_throw(p_ptr->skill_sav - power))
2012 return; /* Save, no adverse effects */
2017 /* Something silly happens... */
2019 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2020 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2022 msg_format("You behold the %s visage of %s!",
2023 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
2029 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
2030 p_ptr->image = p_ptr->image + randint1(r_ptr->level);
2033 return; /* Never mind; we can't see it clearly enough */
2036 /* Something frightening happens... */
2038 msg_format("%s%s¤Î´é¤ò¸«¤Æ¤·¤Þ¤Ã¤¿¡ª",
2039 horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2041 msg_format("You behold the %s visage of %s!",
2042 horror_desc[randint0(MAX_SAN_HORROR)], m_name);
2045 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
2047 /* Demon characters are unaffected */
2048 if (prace_is_(RACE_IMP) || prace_is_(RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
2049 if (p_ptr->wizard) return;
2051 /* Undead characters are 50% likely to be unaffected */
2052 if (prace_is_(RACE_SKELETON) || prace_is_(RACE_ZOMBIE)
2053 || prace_is_(RACE_VAMPIRE) || prace_is_(RACE_SPECTRE) ||
2054 (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
2056 if (saving_throw(25 + p_ptr->lev)) return;
2062 msg_print("¥Í¥¯¥í¥Î¥ß¥³¥ó¤òÆɤó¤ÇÀµµ¤¤ò¼º¤Ã¤¿¡ª");
2064 msg_print("Your sanity is shaken by reading the Necronomicon!");
2069 if (!saving_throw(p_ptr->skill_sav - power)) /* Mind blast */
2071 if (!p_ptr->resist_conf)
2073 (void)set_confused(p_ptr->confused + randint0(4) + 4);
2075 if (!p_ptr->resist_chaos && one_in_(3))
2077 (void)set_image(p_ptr->image + randint0(250) + 150);
2082 if (!saving_throw(p_ptr->skill_sav - power)) /* Lose int & wis */
2089 if (!saving_throw(p_ptr->skill_sav - power)) /* Brain smash */
2091 if (!p_ptr->resist_conf)
2093 (void)set_confused(p_ptr->confused + randint0(4) + 4);
2095 if (!p_ptr->free_act)
2097 (void)set_paralyzed(p_ptr->paralyzed + randint0(4) + 4);
2099 while (randint0(100) > p_ptr->skill_sav)
2100 (void)do_dec_stat(A_INT);
2101 while (randint0(100) > p_ptr->skill_sav)
2102 (void)do_dec_stat(A_WIS);
2103 if (!p_ptr->resist_chaos)
2105 (void)set_image(p_ptr->image + randint0(250) + 150);
2110 if (!saving_throw(p_ptr->skill_sav - power)) /* Amnesia */
2113 if (lose_all_info())
2115 msg_print("¤¢¤Þ¤ê¤Î¶²ÉݤËÁ´¤Æ¤Î¤³¤È¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª");
2117 msg_print("You forget everything in your utmost terror!");
2123 if (saving_throw(p_ptr->skill_sav - power))
2128 /* Else gain permanent insanity */
2129 if ((p_ptr->muta3 & MUT3_MORONIC) && /*(p_ptr->muta2 & MUT2_BERS_RAGE) &&*/
2130 ((p_ptr->muta2 & MUT2_COWARDICE) || (p_ptr->resist_fear)) &&
2131 ((p_ptr->muta2 & MUT2_HALLU) || (p_ptr->resist_chaos)))
2133 /* The poor bastard already has all possible insanities! */
2139 switch (randint1(21))
2142 if (!(p_ptr->muta3 & MUT3_MORONIC) && one_in_(5))
2144 if ((p_ptr->stat_use[A_INT] < 4) && (p_ptr->stat_use[A_WIS] < 4))
2147 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¤è¤¦¤Êµ¤¤¬¤·¤¿¡£¤·¤«¤·¤½¤ì¤Ï¸µ¡¹¤À¤Ã¤¿¡£");
2149 msg_print("You turn into an utter moron!");
2155 msg_print("¤¢¤Ê¤¿¤Ï´°àú¤ÊÇϼ¯¤Ë¤Ê¤Ã¤¿¡ª");
2157 msg_print("You turn into an utter moron!");
2161 if (p_ptr->muta3 & MUT3_HYPER_INT)
2164 msg_print("¤¢¤Ê¤¿¤ÎǾ¤ÏÀ¸ÂÎ¥³¥ó¥Ô¥å¡¼¥¿¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2166 msg_print("Your brain is no longer a living computer.");
2169 p_ptr->muta3 &= ~(MUT3_HYPER_INT);
2171 p_ptr->muta3 |= MUT3_MORONIC;
2185 if (!(p_ptr->muta2 & MUT2_COWARDICE) && !p_ptr->resist_fear)
2188 msg_print("¤¢¤Ê¤¿¤Ï¥Ñ¥é¥Î¥¤¥¢¤Ë¤Ê¤Ã¤¿¡ª");
2190 msg_print("You become paranoid!");
2194 /* Duh, the following should never happen, but anyway... */
2195 if (p_ptr->muta3 & MUT3_FEARLESS)
2198 msg_print("¤¢¤Ê¤¿¤Ï¤â¤¦¶²¤ìÃΤ餺¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
2200 msg_print("You are no longer fearless.");
2203 p_ptr->muta3 &= ~(MUT3_FEARLESS);
2206 p_ptr->muta2 |= MUT2_COWARDICE;
2220 if (!(p_ptr->muta2 & MUT2_HALLU) && !p_ptr->resist_chaos)
2223 msg_print("¸¸³Ð¤ò¤Ò¤µ¯¤³¤¹Àº¿ÀºøÍð¤Ë´Ù¤Ã¤¿¡ª");
2225 msg_print("You are afflicted by a hallucinatory insanity!");
2228 p_ptr->muta2 |= MUT2_HALLU;
2233 if (!(p_ptr->muta2 & MUT2_BERS_RAGE))
2236 msg_print("·ãÎõ¤Ê´¶¾ð¤Îȯºî¤Ë¤ª¤½¤ï¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡ª");
2238 msg_print("You become subject to fits of berserk rage!");
2241 p_ptr->muta2 |= MUT2_BERS_RAGE;
2248 p_ptr->update |= PU_BONUS;
2254 * This function updates the monster record of the given monster
2256 * This involves extracting the distance to the player (if requested),
2257 * and then checking for visibility (natural, infravision, see-invis,
2258 * telepathy), updating the monster visibility flag, redrawing (or
2259 * erasing) the monster when its visibility changes, and taking note
2260 * of any interesting monster flags (cold-blooded, invisible, etc).
2262 * Note the new "mflag" field which encodes several monster state flags,
2263 * including "view" for when the monster is currently in line of sight,
2264 * and "mark" for when the monster is currently visible via detection.
2266 * The only monster fields that are changed here are "cdis" (the
2267 * distance from the player), "ml" (visible to the player), and
2268 * "mflag" (to maintain the "MFLAG_VIEW" flag).
2270 * Note the special "update_monsters()" function which can be used to
2271 * call this function once for every monster.
2273 * Note the "full" flag which requests that the "cdis" field be updated,
2274 * this is only needed when the monster (or the player) has moved.
2276 * Every time a monster moves, we must call this function for that
2277 * monster, and update the distance, and the visibility. Every time
2278 * the player moves, we must call this function for every monster, and
2279 * update the distance, and the visibility. Whenever the player "state"
2280 * changes in certain ways ("blindness", "infravision", "telepathy",
2281 * and "see invisible"), we must call this function for every monster,
2282 * and update the visibility.
2284 * Routines that change the "illumination" of a grid must also call this
2285 * function for any monster in that grid, since the "visibility" of some
2286 * monsters may be based on the illumination of their grid.
2288 * Note that this function is called once per monster every time the
2289 * player moves. When the player is running, this function is one
2290 * of the primary bottlenecks, along with "update_view()" and the
2291 * "process_monsters()" code, so efficiency is important.
2293 * Note the optimized "inline" version of the "distance()" function.
2295 * A monster is "visible" to the player if (1) it has been detected
2296 * by the player, (2) it is close to the player and the player has
2297 * telepathy, or (3) it is close to the player, and in line of sight
2298 * of the player, and it is "illuminated" by some combination of
2299 * infravision, torch light, or permanent light (invisible monsters
2300 * are only affected by "light" if the player can see invisible).
2302 * Monsters which are not on the current panel may be "visible" to
2303 * the player, and their descriptions will include an "offscreen"
2304 * reference. Currently, offscreen monsters cannot be targetted
2305 * or viewed directly, but old targets will remain set. XXX XXX
2307 * The player can choose to be disturbed by several things, including
2308 * "disturb_move" (monster which is viewable moves in some way), and
2309 * "disturb_near" (monster which is "easily" viewable moves in some
2310 * way). Note that "moves" includes "appears" and "disappears".
2312 void update_mon(int m_idx, bool full)
2314 monster_type *m_ptr = &m_list[m_idx];
2316 monster_race *r_ptr = &r_info[m_ptr->r_idx];
2318 bool do_disturb = disturb_move;
2322 /* Current location */
2329 /* Seen by vision */
2332 /* Non-Ninja player in the darkness */
2333 bool in_darkness = (d_info[dungeon_type].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
2338 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2340 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
2344 /* Compute distance */
2347 /* Distance components */
2348 int dy = (py > fy) ? (py - fy) : (fy - py);
2349 int dx = (px > fx) ? (px - fx) : (fx - px);
2351 /* Approximate distance */
2352 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
2354 /* Restrict distance */
2355 if (d > 255) d = 255;
2359 /* Save the distance */
2363 /* Extract distance */
2366 /* Extract the distance */
2372 if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
2376 if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
2378 if (!in_darkness || (d <= MAX_SIGHT / 4))
2380 if (p_ptr->special_defense & KATA_MUSOU)
2385 if (is_original_ap(m_ptr) && !p_ptr->image)
2387 /* Hack -- Memorize mental flags */
2388 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2389 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2393 /* Basic telepathy */
2394 /* Snipers get telepathy when they concentrate deeper */
2395 else if (p_ptr->telepathy)
2397 /* Empty mind, no telepathy */
2398 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
2400 /* Memorize flags */
2401 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
2404 /* Weird mind, occasional telepathy */
2405 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
2407 /* One in ten individuals are detectable */
2408 if ((m_idx % 10) == 5)
2413 if (is_original_ap(m_ptr) && !p_ptr->image)
2415 /* Memorize flags */
2416 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
2418 /* Hack -- Memorize mental flags */
2419 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2420 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2425 /* Normal mind, allow telepathy */
2431 if (is_original_ap(m_ptr) && !p_ptr->image)
2433 /* Hack -- Memorize mental flags */
2434 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
2435 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
2440 /* Magical sensing */
2441 if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
2444 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
2447 /* Magical sensing */
2448 if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
2451 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
2454 /* Magical sensing */
2455 if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
2458 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
2461 /* Magical sensing */
2462 if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
2465 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
2468 /* Magical sensing */
2469 if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
2472 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
2475 /* Magical sensing */
2476 if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
2479 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
2482 /* Magical sensing */
2483 if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
2486 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
2489 /* Magical sensing */
2490 if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
2493 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
2496 /* Magical sensing */
2497 if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2500 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
2503 /* Magical sensing */
2504 if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2507 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
2510 /* Magical sensing */
2511 if ((p_ptr->esp_nonliving) &&
2512 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2515 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
2518 /* Magical sensing */
2519 if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2522 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
2526 /* Normal line of sight, and not blind */
2527 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2529 bool do_invisible = FALSE;
2530 bool do_cold_blood = FALSE;
2532 /* Snipers can see targets in darkness when they concentrate deeper */
2533 if (p_ptr->concent >= CONCENT_RADAR_THRESHOLD)
2539 /* Use "infravision" */
2540 if (d <= p_ptr->see_infra)
2542 /* Handle "cold blooded" monsters */
2543 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2546 do_cold_blood = TRUE;
2549 /* Handle "warm blooded" monsters */
2557 /* Use "illumination" */
2558 if (player_can_see_bold(fy, fx))
2560 /* Handle "invisible" monsters */
2561 if (r_ptr->flags2 & (RF2_INVISIBLE))
2564 do_invisible = TRUE;
2574 /* Handle "normal" monsters */
2585 if (is_original_ap(m_ptr) && !p_ptr->image)
2587 /* Memorize flags */
2588 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2589 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2596 /* The monster is now visible */
2599 /* It was previously unseen */
2602 /* Mark as visible */
2605 /* Draw the monster */
2608 /* Update health bar as needed */
2609 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2610 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2612 /* Hack -- Count "fresh" sightings */
2615 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2616 r_info[MON_KAGE].r_sights++;
2617 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
2621 /* Eldritch Horror */
2622 if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
2624 sanity_blast(m_ptr, FALSE);
2627 /* Disturb on appearance */
2628 if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, py, px) && projectable(py, px, m_ptr->fy, m_ptr->fx)))
2630 if (disturb_pets || is_hostile(m_ptr))
2636 /* The monster is not visible */
2639 /* It was previously seen */
2642 /* Mark as not visible */
2645 /* Erase the monster */
2648 /* Update health bar as needed */
2649 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2650 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2652 /* Disturb on disappearance */
2655 if (disturb_pets || is_hostile(m_ptr))
2662 /* The monster is now easily visible */
2666 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2668 /* Mark as easily visible */
2669 m_ptr->mflag |= (MFLAG_VIEW);
2671 /* Disturb on appearance */
2674 if (disturb_pets || is_hostile(m_ptr))
2680 /* The monster is not easily visible */
2684 if (m_ptr->mflag & (MFLAG_VIEW))
2686 /* Mark as not easily visible */
2687 m_ptr->mflag &= ~(MFLAG_VIEW);
2689 /* Disturb on disappearance */
2692 if (disturb_pets || is_hostile(m_ptr))
2701 * This function simply updates all the (non-dead) monsters (see above).
2703 void update_monsters(bool full)
2707 /* Update each (live) monster */
2708 for (i = 1; i < m_max; i++)
2710 monster_type *m_ptr = &m_list[i];
2712 /* Skip dead monsters */
2713 if (!m_ptr->r_idx) continue;
2715 /* Update the monster */
2716 update_mon(i, full);
2722 * Hack -- the index of the summoning monster
2724 static bool monster_hook_chameleon_lord(int r_idx)
2726 monster_race *r_ptr = &r_info[r_idx];
2727 monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2728 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2730 if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2731 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2733 if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2735 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))
2738 if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2741 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2743 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2747 else if (summon_specific_who > 0)
2749 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2755 static bool monster_hook_chameleon(int r_idx)
2757 monster_race *r_ptr = &r_info[r_idx];
2758 monster_type *m_ptr = &m_list[chameleon_change_m_idx];
2759 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2761 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2762 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2763 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2765 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))
2768 if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2771 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2773 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2774 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2775 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2779 else if (summon_specific_who > 0)
2781 if (monster_has_hostile_align(&m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2784 return (*(get_monster_hook()))(r_idx);
2788 void choose_new_monster(int m_idx, bool born, int r_idx)
2791 monster_type *m_ptr = &m_list[m_idx];
2792 monster_race *r_ptr;
2793 char old_m_name[80];
2794 bool old_unique = FALSE;
2795 int old_r_idx = m_ptr->r_idx;
2797 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2799 if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2800 r_ptr = &r_info[r_idx];
2802 monster_desc(old_m_name, m_ptr, 0);
2808 chameleon_change_m_idx = m_idx;
2810 get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2812 get_mon_num_prep(monster_hook_chameleon, NULL);
2815 level = r_info[MON_CHAMELEON_K].level;
2816 else if (!dun_level)
2817 level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2821 if (d_info[dungeon_type].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2823 r_idx = get_mon_num(level);
2824 r_ptr = &r_info[r_idx];
2826 chameleon_change_m_idx = 0;
2832 if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, FALSE);
2834 m_ptr->r_idx = r_idx;
2835 m_ptr->ap_r_idx = r_idx;
2836 update_mon(m_idx, FALSE);
2837 lite_spot(m_ptr->fy, m_ptr->fx);
2839 if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2840 (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2841 p_ptr->update |= (PU_MON_LITE);
2843 if (is_pet(m_ptr)) check_pets_num_and_align(m_ptr, TRUE);
2847 /* Sub-alignment of a chameleon */
2848 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2850 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2851 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2852 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2857 if (m_idx == p_ptr->riding)
2860 monster_desc(m_name, m_ptr, 0);
2862 msg_format("ÆÍÁ³%s¤¬ÊѿȤ·¤¿¡£", old_m_name);
2864 msg_format("Suddenly, %s transforms!", old_m_name);
2866 if (!(r_ptr->flags7 & RF7_RIDING))
2868 if (rakuba(0, TRUE)) msg_print("ÃÏÌ̤ËÍî¤È¤µ¤ì¤¿¡£");
2870 if (rakuba(0, TRUE)) msg_format("You have fallen from %s.", m_name);
2874 /* Extract the monster base speed */
2875 m_ptr->mspeed = get_mspeed(r_ptr);
2877 oldmaxhp = m_ptr->max_maxhp;
2878 /* Assign maximal hitpoints */
2879 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2881 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2885 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2888 /* Monsters have double hitpoints in Nightmare mode */
2889 if (ironman_nightmare)
2891 u32b hp = m_ptr->max_maxhp * 2L;
2892 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
2895 m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2896 if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2897 m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2904 static bool monster_hook_tanuki(int r_idx)
2906 monster_race *r_ptr = &r_info[r_idx];
2908 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2909 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2910 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2911 if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2913 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))
2916 return (*(get_monster_hook()))(r_idx);
2921 * Set initial racial appearance of a monster
2923 static int initial_r_appearance(int r_idx)
2925 int attempts = 1000;
2928 int min = MIN(base_level-5, 50);
2930 if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2933 get_mon_num_prep(monster_hook_tanuki, NULL);
2937 ap_r_idx = get_mon_num(base_level + 10);
2938 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2946 * Get initial monster speed
2948 byte get_mspeed(monster_race *r_ptr)
2950 /* Extract the monster base speed */
2951 int mspeed = r_ptr->speed;
2953 /* Hack -- small racial variety */
2954 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2956 /* Allow some small variation per monster */
2957 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2958 if (i) mspeed += rand_spread(0, i);
2961 if (mspeed > 199) mspeed = 199;
2963 return (byte)mspeed;
2968 * Attempt to place a monster of the given race at the given location.
2970 * To give the player a sporting chance, any monster that appears in
2971 * line-of-sight and is extremely dangerous can be marked as
2972 * "FORCE_SLEEP", which will cause them to be placed with low energy,
2973 * which often (but not always) lets the player move before they do.
2975 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2977 * XXX XXX XXX Use special "here" and "dead" flags for unique monsters,
2978 * remove old "cur_num" and "max_num" fields.
2980 * XXX XXX XXX Actually, do something similar for artifacts, to simplify
2981 * the "preserve" mode, and to make the "what artifacts" flag more useful.
2983 * This is the only function which may place a monster in the dungeon,
2984 * except for the savefile loading code.
2986 static bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
2988 /* Access the location */
2989 cave_type *c_ptr = &cave[y][x];
2991 monster_type *m_ptr;
2993 monster_race *r_ptr = &r_info[r_idx];
2995 cptr name = (r_name + r_ptr->name);
2999 /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
3000 if (p_ptr->wild_mode) return FALSE;
3002 /* Verify location */
3003 if (!in_bounds(y, x)) return (FALSE);
3006 if (!r_idx) return (FALSE);
3009 if (!r_ptr->name) return (FALSE);
3011 if (!(mode & PM_IGNORE_TERRAIN))
3013 /* Not on the Pattern */
3014 if (pattern_tile(y, x)) return FALSE;
3016 /* Require empty space (if not ghostly) */
3017 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
3020 if (!p_ptr->inside_battle)
3022 /* Hack -- "unique" monsters must be "unique" */
3023 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
3024 (r_ptr->flags7 & (RF7_NAZGUL))) &&
3025 (r_ptr->cur_num >= r_ptr->max_num))
3031 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
3032 (r_ptr->cur_num >= 1))
3037 if (r_idx == MON_BANORLUPART)
3039 if (r_info[MON_BANOR].cur_num > 0) return FALSE;
3040 if (r_info[MON_LUPART].cur_num > 0) return FALSE;
3043 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
3044 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (dun_level < r_ptr->level) &&
3045 (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
3052 if (quest_number(dun_level))
3054 int hoge = quest_number(dun_level);
3055 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
3057 if(r_idx == quest[hoge].r_idx)
3059 int number_mon, i2, j2;
3062 /* Count all quest monsters */
3063 for (i2 = 0; i2 < cur_wid; ++i2)
3064 for (j2 = 0; j2 < cur_hgt; j2++)
3065 if (cave[j2][i2].m_idx > 0)
3066 if (m_list[cave[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
3068 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
3074 if (is_glyph_grid(c_ptr))
3076 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
3078 /* Describe observable breakage */
3079 if (c_ptr->info & CAVE_MARK)
3082 msg_print("¼é¤ê¤Î¥ë¡¼¥ó¤¬²õ¤ì¤¿¡ª");
3084 msg_print("The rune of protection is broken!");
3089 /* Forget the rune */
3090 c_ptr->info &= ~(CAVE_MARK);
3092 /* Break the rune */
3093 c_ptr->info &= ~(CAVE_OBJECT);
3102 /* Powerful monster */
3103 if (r_ptr->level > dun_level)
3105 /* Unique monsters */
3106 if (r_ptr->flags1 & (RF1_UNIQUE))
3108 /* Message for cheaters */
3110 if (cheat_hear) msg_format("¿¼ÁؤΥæ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3112 if (cheat_hear) msg_format("Deep Unique (%s).", name);
3116 /* Normal monsters */
3119 /* Message for cheaters */
3121 if (cheat_hear) msg_format("¿¼ÁؤΥâ¥ó¥¹¥¿¡¼ (%s)¡£", name);
3123 if (cheat_hear) msg_format("Deep Monster (%s).", name);
3128 /* Note the monster */
3129 else if (r_ptr->flags1 & (RF1_UNIQUE))
3131 /* Unique monsters induce message */
3133 if (cheat_hear) msg_format("¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼ (%s)¡£", name);
3135 if (cheat_hear) msg_format("Unique (%s).", name);
3140 if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
3142 /* Make a new monster */
3143 c_ptr->m_idx = m_pop();
3144 hack_m_idx_ii = c_ptr->m_idx;
3146 /* Mega-Hack -- catch "failure" */
3147 if (!c_ptr->m_idx) return (FALSE);
3150 /* Get a new monster record */
3151 m_ptr = &m_list[c_ptr->m_idx];
3154 m_ptr->r_idx = r_idx;
3155 m_ptr->ap_r_idx = initial_r_appearance(r_idx);
3161 /* Hack -- Appearance transfer */
3162 if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(&m_list[who]))
3164 m_ptr->ap_r_idx = m_list[who].ap_r_idx;
3166 /* Hack -- Shadower spawns Shadower */
3167 if (m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
3170 /* Sub-alignment of a monster */
3171 if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
3172 m_ptr->sub_align = m_list[who].sub_align;
3175 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3176 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
3177 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
3180 /* Place the monster at the location */
3185 /* No "timed status" yet */
3186 for (cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
3188 /* Unknown distance */
3191 reset_target(m_ptr);
3193 m_ptr->nickname = 0;
3198 /* Your pet summons its pet. */
3199 if (who > 0 && is_pet(&m_list[who]))
3201 mode |= PM_FORCE_PET;
3202 m_ptr->parent_m_idx = who;
3206 m_ptr->parent_m_idx = 0;
3209 if (r_ptr->flags7 & RF7_CHAMELEON)
3211 choose_new_monster(c_ptr->m_idx, TRUE, 0);
3212 r_ptr = &r_info[m_ptr->r_idx];
3213 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
3215 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
3216 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
3217 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
3219 else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
3221 m_ptr->ap_r_idx = MON_KAGE;
3222 m_ptr->mflag2 |= MFLAG2_KAGE;
3225 if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
3231 if (mode & PM_FORCE_PET)
3236 else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
3237 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
3239 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
3242 /* Assume no sleeping */
3243 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
3245 /* Enforce sleeping if needed */
3246 if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
3248 int val = r_ptr->sleep;
3249 (void)set_monster_csleep(c_ptr->m_idx, (val * 2) + randint1(val * 10));
3252 /* Assign maximal hitpoints */
3253 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
3255 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
3259 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
3262 /* Monsters have double hitpoints in Nightmare mode */
3263 if (ironman_nightmare)
3265 u32b hp = m_ptr->max_maxhp * 2L;
3267 m_ptr->max_maxhp = (s16b)MIN(30000, hp);
3270 m_ptr->maxhp = m_ptr->max_maxhp;
3272 /* And start out fully healthy */
3273 if (m_ptr->r_idx == MON_WOUNDED_BEAR)
3274 m_ptr->hp = m_ptr->maxhp / 2;
3275 else m_ptr->hp = m_ptr->maxhp;
3278 /* Extract the monster base speed */
3279 m_ptr->mspeed = get_mspeed(r_ptr);
3281 if (mode & PM_HASTE) (void)set_monster_fast(c_ptr->m_idx, 100);
3283 /* Give a random starting energy */
3284 if (!ironman_nightmare)
3286 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
3290 /* Nightmare monsters are more prepared */
3291 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
3294 /* Force monster to wait for player, unless in Nightmare mode */
3295 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
3297 /* Monster is still being nice */
3298 m_ptr->mflag |= (MFLAG_NICE);
3300 /* Must repair monsters */
3301 repair_monsters = TRUE;
3304 /* Hack -- see "process_monsters()" */
3305 if (c_ptr->m_idx < hack_m_idx)
3307 /* Monster is still being born */
3308 m_ptr->mflag |= (MFLAG_BORN);
3312 if (r_ptr->flags7 & RF7_SELF_LD_MASK)
3313 p_ptr->update |= (PU_MON_LITE);
3314 else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
3315 p_ptr->update |= (PU_MON_LITE);
3317 /* Update the monster */
3318 update_mon(c_ptr->m_idx, TRUE);
3321 /* Count the monsters on the level */
3322 real_r_ptr(m_ptr)->cur_num++;
3325 * Memorize location of the unique monster in saved floors.
3326 * A unique monster move from old saved floor.
3328 if (character_dungeon &&
3329 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
3330 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
3332 /* Hack -- Count the number of "reproducers" */
3333 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
3335 /* Hack -- Notice new multi-hued monsters */
3337 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
3338 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
3339 shimmer_monsters = TRUE;
3342 if (p_ptr->warning && character_dungeon)
3344 if (r_ptr->flags1 & RF1_UNIQUE)
3348 char o_name[MAX_NLEN];
3350 if (r_ptr->level > p_ptr->lev + 30)
3356 else if (r_ptr->level > p_ptr->lev + 15)
3362 else if (r_ptr->level > p_ptr->lev + 5)
3364 color = "¥ë¥Ó¡¼¿§¤Ë";
3368 else if (r_ptr->level > p_ptr->lev - 5)
3374 else if (r_ptr->level > p_ptr->lev - 15)
3376 color = "¥Ô¥ó¥¯¿§¤Ë";
3387 o_ptr = choose_warning_item();
3390 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
3392 msg_format("%s¤Ï%s¸÷¤Ã¤¿¡£", o_name, color);
3394 msg_format("%s glows %s.", o_name, color);
3400 msg_format("s%¸÷¤ëʪ¤¬Æ¬¤ËÉ⤫¤ó¤À¡£", color);
3402 msg_format("An %s image forms in your mind.");
3408 if (is_explosive_rune_grid(c_ptr))
3410 /* Break the ward */
3411 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
3413 /* Describe observable breakage */
3414 if (c_ptr->info & CAVE_MARK)
3417 msg_print("¥ë¡¼¥ó¤¬Çúȯ¤·¤¿¡ª");
3419 msg_print("The rune explodes!");
3422 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);
3428 msg_print("Çúȯ¤Î¥ë¡¼¥ó¤Ï²ò½ü¤µ¤ì¤¿¡£");
3430 msg_print("An explosive rune was disarmed.");
3434 /* Forget the rune */
3435 c_ptr->info &= ~(CAVE_MARK);
3437 /* Break the rune */
3438 c_ptr->info &= ~(CAVE_OBJECT);
3451 * improved version of scatter() for place monster
3454 #define MON_SCAT_MAXD 10
3456 static bool mon_scatter(int r_idx, int *yp, int *xp, int y, int x, int max_dist)
3458 int place_x[MON_SCAT_MAXD];
3459 int place_y[MON_SCAT_MAXD];
3460 int num[MON_SCAT_MAXD];
3464 if (max_dist >= MON_SCAT_MAXD)
3467 for (i = 0; i < MON_SCAT_MAXD; i++)
3470 for (nx = x - max_dist; nx <= x + max_dist; nx++)
3472 for (ny = y - max_dist; ny <= y + max_dist; ny++)
3474 /* Ignore annoying locations */
3475 if (!in_bounds(ny, nx)) continue;
3477 /* Require "line of projection" */
3478 if (!projectable(y, x, ny, nx)) continue;
3482 monster_race *r_ptr = &r_info[r_idx];
3484 /* Require empty space (if not ghostly) */
3485 if (!monster_can_enter(ny, nx, r_ptr, 0))
3490 /* Walls and Monsters block flow */
3491 if (!cave_empty_bold2(ny, nx)) continue;
3493 /* ... nor on the Pattern */
3494 if (pattern_tile(ny, nx)) continue;
3497 i = distance(y, x, ny, nx);
3505 if (one_in_(num[i]))
3514 while (i < MON_SCAT_MAXD && 0 == num[i])
3516 if (i >= MON_SCAT_MAXD)
3527 * Maximum size of a group of monsters
3529 #define GROUP_MAX 32
3533 * Attempt to place a "group" of monsters around the given location
3535 static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
3537 monster_race *r_ptr = &r_info[r_idx];
3540 int total = 0, extra = 0;
3544 byte hack_y[GROUP_MAX];
3545 byte hack_x[GROUP_MAX];
3548 /* Pick a group size */
3549 total = randint1(10);
3551 /* Hard monsters, small groups */
3552 if (r_ptr->level > dun_level)
3554 extra = r_ptr->level - dun_level;
3555 extra = 0 - randint1(extra);
3558 /* Easy monsters, large groups */
3559 else if (r_ptr->level < dun_level)
3561 extra = dun_level - r_ptr->level;
3562 extra = randint1(extra);
3565 /* Hack -- limit group reduction */
3566 if (extra > 9) extra = 9;
3568 /* Modify the group size */
3572 if (total < 1) total = 1;
3575 if (total > GROUP_MAX) total = GROUP_MAX;
3578 /* Start on the monster */
3583 /* Puddle monsters, breadth first, up to total */
3584 for (n = 0; (n < hack_n) && (hack_n < total); n++)
3586 /* Grab the location */
3590 /* Check each direction, up to total */
3591 for (i = 0; (i < 8) && (hack_n < total); i++)
3595 scatter(&my, &mx, hy, hx, 4, 0);
3597 /* Walls and Monsters block flow */
3598 if (!cave_empty_bold2(my, mx)) continue;
3600 /* Attempt to place another monster */
3601 if (place_monster_one(who, my, mx, r_idx, mode))
3603 /* Add it to the "hack" set */
3604 hack_y[hack_n] = my;
3605 hack_x[hack_n] = mx;
3618 * Hack -- help pick an escort type
3620 static int place_monster_idx = 0;
3621 static int place_monster_m_idx = 0;
3624 * Hack -- help pick an escort type
3626 static bool place_monster_okay(int r_idx)
3628 monster_race *r_ptr = &r_info[place_monster_idx];
3629 monster_type *m_ptr = &m_list[place_monster_m_idx];
3631 monster_race *z_ptr = &r_info[r_idx];
3633 /* Hack - Escorts have to have the same dungeon flag */
3634 if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return (FALSE);
3636 /* Require similar "race" */
3637 if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3639 /* Skip more advanced monsters */
3640 if (z_ptr->level > r_ptr->level) return (FALSE);
3642 /* Skip unique monsters */
3643 if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3645 /* Paranoia -- Skip identical monsters */
3646 if (place_monster_idx == r_idx) return (FALSE);
3648 /* Skip different alignment */
3649 if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3651 if (r_ptr->flags7 & RF7_FRIENDLY)
3653 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3656 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3665 * Attempt to place a monster of the given race at the given location
3667 * Note that certain monsters are now marked as requiring "friends".
3668 * These monsters, if successfully placed, and if the "grp" parameter
3669 * is TRUE, will be surrounded by a "group" of identical monsters.
3671 * Note that certain monsters are now marked as requiring an "escort",
3672 * which is a collection of monsters with similar "race" but lower level.
3674 * Some monsters induce a fake "group" flag on their escorts.
3676 * Note the "bizarre" use of non-recursion to prevent annoying output
3677 * when running a code profiler.
3679 * Note the use of the new "monster allocation table" code to restrict
3680 * the "get_mon_num()" function to "legal" escort types.
3682 bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
3685 monster_race *r_ptr = &r_info[r_idx];
3687 if (!(mode & PM_NO_KAGE) && one_in_(333))
3690 /* Place one monster, or fail */
3691 if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3694 /* Require the "group" flag */
3695 if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3697 place_monster_m_idx = hack_m_idx_ii;
3699 /* Friends for certain monsters */
3700 if (r_ptr->flags1 & (RF1_FRIENDS))
3702 /* Attempt to place a group */
3703 (void)place_monster_group(who, y, x, r_idx, mode);
3707 /* Escorts for certain monsters */
3708 if (r_ptr->flags1 & (RF1_ESCORT))
3710 /* Set the escort index */
3711 place_monster_idx = r_idx;
3713 /* Try to place several "escorts" */
3714 for (i = 0; i < 32; i++)
3716 int nx, ny, z, d = 3;
3718 /* Pick a location */
3719 scatter(&ny, &nx, y, x, d, 0);
3721 /* Require empty grids */
3722 if (!cave_empty_bold2(ny, nx)) continue;
3724 /* Prepare allocation table */
3725 get_mon_num_prep(place_monster_okay, get_monster_hook2(ny, nx));
3727 /* Pick a random race */
3728 z = get_mon_num(r_ptr->level);
3730 /* Handle failure */
3733 /* Place a single escort */
3734 (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3736 /* Place a "group" of escorts if needed */
3737 if ((r_info[z].flags1 & RF1_FRIENDS) ||
3738 (r_ptr->flags1 & RF1_ESCORTS))
3740 /* Place a group of monsters */
3741 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3752 * Hack -- attempt to place a monster at the given location
3754 * Attempt to find a monster appropriate to the "monster_level"
3756 bool place_monster(int y, int x, u32b mode)
3760 /* Prepare allocation table */
3761 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3763 /* Pick a monster */
3764 r_idx = get_mon_num(monster_level);
3766 /* Handle failure */
3767 if (!r_idx) return (FALSE);
3769 /* Attempt to place the monster */
3770 if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3777 #ifdef MONSTER_HORDES
3779 bool alloc_horde(int y, int x)
3781 monster_race *r_ptr = NULL;
3784 int attempts = 1000;
3788 /* Prepare allocation table */
3789 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3793 /* Pick a monster */
3794 r_idx = get_mon_num(monster_level);
3796 /* Handle failure */
3797 if (!r_idx) return (FALSE);
3799 r_ptr = &r_info[r_idx];
3801 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3803 if (r_idx == MON_HAGURE) continue;
3806 if (attempts < 1) return FALSE;
3812 /* Attempt to place the monster */
3813 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3816 if (attempts < 1) return FALSE;
3818 m_idx = cave[y][x].m_idx;
3820 if (m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[m_list[m_idx].r_idx];
3821 summon_kin_type = r_ptr->d_char;
3823 for (attempts = randint1(10) + 5; attempts; attempts--)
3825 scatter(&cy, &cx, y, x, 5, 0);
3827 (void)summon_specific(m_idx, cy, cx, dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3836 #endif /* MONSTER_HORDES */
3842 bool alloc_guardian(bool def_val)
3844 int guardian = d_info[dungeon_type].final_guardian;
3846 if (guardian && (d_info[dungeon_type].maxdepth == dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3852 /* Find a good position */
3855 /* Get a random spot */
3856 oy = randint1(cur_hgt - 4) + 2;
3857 ox = randint1(cur_wid - 4) + 2;
3859 /* Is it a good spot ? */
3860 if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian], 0))
3862 /* Place the guardian */
3863 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3878 * Attempt to allocate a random monster in the dungeon.
3880 * Place the monster at least "dis" distance from the player.
3882 * Use "slp" to choose the initial "sleep" status
3884 * Use "monster_level" for the monster level
3886 bool alloc_monster(int dis, u32b mode)
3889 int attempts_left = 10000;
3891 /* Put the Guardian */
3892 if (alloc_guardian(FALSE)) return TRUE;
3894 /* Find a legal, distant, unoccupied, space */
3895 while (attempts_left--)
3897 /* Pick a location */
3898 y = randint0(cur_hgt);
3899 x = randint0(cur_wid);
3901 /* Require empty floor grid (was "naked") */
3904 if (!cave_empty_bold2(y, x)) continue;
3908 if (!cave_empty_bold(y, x)) continue;
3911 /* Accept far away grids */
3912 if (distance(y, x, py, px) > dis) break;
3917 if (cheat_xtra || cheat_hear)
3920 msg_print("·Ù¹ð¡ª¿·¤¿¤Ê¥â¥ó¥¹¥¿¡¼¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡£¾®¤µ¤¤³¬¤Ç¤¹¤«¡©");
3922 msg_print("Warning! Could not allocate a new monster. Small level?");
3931 #ifdef MONSTER_HORDES
3932 if (randint1(5000) <= dun_level)
3934 if (alloc_horde(y, x))
3937 if (cheat_hear) msg_format("¥â¥ó¥¹¥¿¡¼¤ÎÂç·²(%c)", summon_kin_type);
3939 if (cheat_hear) msg_format("Monster horde (%c).", summon_kin_type);
3947 #endif /* MONSTER_HORDES */
3949 /* Attempt to place the monster, allow groups */
3950 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3952 #ifdef MONSTER_HORDES
3954 #endif /* MONSTER_HORDES */
3964 * Hack -- help decide if a monster race is "okay" to summon
3966 static bool summon_specific_okay(int r_idx)
3968 monster_race *r_ptr = &r_info[r_idx];
3970 /* Hack - Only summon dungeon monsters */
3971 if (!mon_hook_dungeon(r_idx)) return (FALSE);
3973 /* Hack -- identify the summoning monster */
3974 if (summon_specific_who > 0)
3976 monster_type *m_ptr = &m_list[summon_specific_who];
3978 /* Do not summon enemies */
3980 /* Friendly vs. opposite aligned normal or pet */
3981 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3983 /* Use the player's alignment */
3984 else if (summon_specific_who < 0)
3986 /* Do not summon enemies of the pets */
3987 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3989 if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3993 /* Hack -- no specific type specified */
3994 if (!summon_specific_type) return (TRUE);
3996 if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
3998 if ((summon_specific_who < 0) &&
3999 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
4000 monster_has_hostile_align(NULL, 10, -10, r_ptr))
4003 if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
4005 return (summon_specific_aux(r_idx));
4010 * Place a monster (of the specified "type") near the given
4011 * location. Return TRUE if a monster was actually summoned.
4013 * We will attempt to place the monster up to 10 times before giving up.
4015 * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
4016 * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
4017 * Note: None of the other summon codes will ever summon Unique's.
4019 * This function has been changed. We now take the "monster level"
4020 * of the summoning monster as a parameter, and use that, along with
4021 * the current dungeon level, to help determine the level of the
4022 * desired monster. Note that this is an upper bound, and also
4023 * tends to "prefer" monsters of that level. Currently, we use
4024 * the average of the dungeon and monster levels, and then add
4025 * five to allow slight increases in monster power.
4027 * Note that we use the new "monster allocation table" creation code
4028 * to restrict the "get_mon_num()" function to the set of "legal"
4029 * monsters, making this function much faster and more reliable.
4031 * Note that this function may not succeed, though this is very rare.
4033 bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
4037 if (p_ptr->inside_arena) return (FALSE);
4039 if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
4041 /* Save the summoner */
4042 summon_specific_who = who;
4044 /* Save the "summon" type */
4045 summon_specific_type = type;
4047 summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
4049 /* Prepare allocation table */
4050 get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
4052 /* Pick a monster, using the level calculation */
4053 r_idx = get_mon_num((dun_level + lev) / 2 + 5);
4055 /* Handle failure */
4058 summon_specific_type = 0;
4062 if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
4064 /* Attempt to place the monster (awake, allow groups) */
4065 if (!place_monster_aux(who, y, x, r_idx, mode))
4067 summon_specific_type = 0;
4071 summon_specific_type = 0;
4076 /* A "dangerous" function, creates a pet of the specified type */
4077 bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
4082 /* if (!r_idx) return; */
4084 /* Prevent illegal monsters */
4085 if (r_idx >= max_r_idx) return FALSE;
4087 if (p_ptr->inside_arena) return FALSE;
4089 if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
4091 /* Place it (allow groups) */
4092 return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
4097 * Let the given monster attempt to reproduce.
4099 * Note that "reproduction" REQUIRES empty space.
4101 bool multiply_monster(int m_idx, bool clone, u32b mode)
4103 monster_type *m_ptr = &m_list[m_idx];
4107 if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
4110 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
4112 /* Create a new monster (awake, no groups) */
4113 if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
4116 /* Hack -- Transfer "clone" flag */
4117 if (clone || (m_ptr->smart & SM_CLONED))
4119 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4120 m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
4131 * Dump a message describing a monster's reaction to damage
4133 * Technically should attempt to treat "Beholder"'s as jelly's
4135 void message_pain(int m_idx, int dam)
4137 long oldhp, newhp, tmp;
4140 monster_type *m_ptr = &m_list[m_idx];
4141 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4146 /* Get the monster name */
4147 monster_desc(m_name, m_ptr, 0);
4149 /* Notice non-damage */
4153 msg_format("%^s¤Ï¥À¥á¡¼¥¸¤ò¼õ¤±¤Æ¤¤¤Ê¤¤¡£", m_name);
4155 msg_format("%^s is unharmed.", m_name);
4161 /* Note -- subtle fix -CFT */
4162 newhp = (long)(m_ptr->hp);
4163 oldhp = newhp + (long)(dam);
4164 tmp = (newhp * 100L) / oldhp;
4165 percentage = (int)(tmp);
4168 /* Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs */
4169 if (my_strchr(",ejmvwQ", r_ptr->d_char))
4172 if (percentage > 95)
4173 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4174 else if (percentage > 75)
4175 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4176 else if (percentage > 50)
4177 msg_format("%^s¤Ï½Ì¤³¤Þ¤Ã¤¿¡£", m_name);
4178 else if (percentage > 35)
4179 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4180 else if (percentage > 20)
4181 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4182 else if (percentage > 10)
4183 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4185 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4187 if (percentage > 95)
4188 msg_format("%^s barely notices.", m_name);
4189 else if (percentage > 75)
4190 msg_format("%^s flinches.", m_name);
4191 else if (percentage > 50)
4192 msg_format("%^s squelches.", m_name);
4193 else if (percentage > 35)
4194 msg_format("%^s quivers in pain.", m_name);
4195 else if (percentage > 20)
4196 msg_format("%^s writhes about.", m_name);
4197 else if (percentage > 10)
4198 msg_format("%^s writhes in agony.", m_name);
4200 msg_format("%^s jerks limply.", m_name);
4207 else if (my_strchr("l", r_ptr->d_char))
4209 if (percentage > 95)
4211 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4213 msg_format("%^s barely notices.", m_name);
4215 else if (percentage > 75)
4217 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4219 msg_format("%^s flinches.", m_name);
4221 else if (percentage > 50)
4223 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4225 msg_format("%^s hesitates.", m_name);
4227 else if (percentage > 35)
4229 msg_format("%^s¤ÏÄˤߤ˿̤¨¤¿¡£", m_name);
4231 msg_format("%^s quivers in pain.", m_name);
4233 else if (percentage > 20)
4235 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4237 msg_format("%^s writhes about.", m_name);
4239 else if (percentage > 10)
4241 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4243 msg_format("%^s writhes in agony.", m_name);
4247 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4249 msg_format("%^s jerks limply.", m_name);
4254 /* Golems, Walls, Doors, Stairs */
4255 else if (my_strchr("g#+<>", r_ptr->d_char))
4257 if (percentage > 95)
4259 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4261 msg_format("%^s ignores the attack.", m_name);
4263 else if (percentage > 75)
4265 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4267 msg_format("%^s shrugs off the attack.", m_name);
4269 else if (percentage > 50)
4271 msg_format("%^s¤ÏÍëÌĤΤ褦¤ËËʤ¨¤¿¡£", m_name);
4273 msg_format("%^s roars thunderously.", m_name);
4275 else if (percentage > 35)
4277 msg_format("%^s¤Ï¶ì¤·¤²¤ËËʤ¨¤¿¡£", m_name);
4279 msg_format("%^s rumbles.", m_name);
4281 else if (percentage > 20)
4283 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4285 msg_format("%^s grunts.", m_name);
4287 else if (percentage > 10)
4289 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4291 msg_format("%^s hesitates.", m_name);
4295 msg_format("%^s¤Ï¤¯¤·¤ã¤¯¤·¤ã¤Ë¤Ê¤Ã¤¿¡£", m_name);
4297 msg_format("%^s crumples.", m_name);
4302 /* Snakes, Hydrae, Reptiles, Mimics */
4303 else if (my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char))
4305 if (percentage > 95)
4307 msg_format("%^s¤Ï¤Û¤È¤ó¤Éµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4309 msg_format("%^s barely notices.", m_name);
4311 else if (percentage > 75)
4313 msg_format("%^s¤Ï¥·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4315 msg_format("%^s hisses.", m_name);
4317 else if (percentage > 50)
4319 msg_format("%^s¤ÏÅܤäÆƬ¤ò¾å¤²¤¿¡£", m_name);
4321 msg_format("%^s rears up in anger.", m_name);
4323 else if (percentage > 35)
4325 msg_format("%^s¤ÏÌÔÁ³¤È°Ò³Å¤·¤¿¡£", m_name);
4327 msg_format("%^s hisses furiously.", m_name);
4329 else if (percentage > 20)
4331 msg_format("%^s¤Ï¿È¤â¤À¤¨¤·¤¿¡£", m_name);
4333 msg_format("%^s writhes about.", m_name);
4335 else if (percentage > 10)
4337 msg_format("%^s¤Ï¶ìÄˤǿȤâ¤À¤¨¤·¤¿¡£", m_name);
4339 msg_format("%^s writhes in agony.", m_name);
4343 msg_format("%^s¤Ï¤°¤Ë¤ã¤°¤Ë¤ã¤ÈáÛÚ»¤·¤¿¡£", m_name);
4345 msg_format("%^s jerks limply.", m_name);
4351 else if (my_strchr("f", r_ptr->d_char))
4353 if (percentage > 95)
4355 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4357 msg_format("%^s shrugs off the attack.", m_name);
4359 else if (percentage > 75)
4361 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4363 msg_format("%^s roars.", m_name);
4365 else if (percentage > 50)
4367 msg_format("%^s¤ÏÅܤäÆËʤ¨¤¿¡£", m_name);
4369 msg_format("%^s growls angrily.", m_name);
4371 else if (percentage > 35)
4373 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4375 msg_format("%^s hisses with pain.", m_name);
4377 else if (percentage > 20)
4379 msg_format("%^s¤ÏÄˤߤǼ塹¤·¤¯ÌĤ¤¤¿¡£", m_name);
4381 msg_format("%^s mewls in pain.", m_name);
4383 else if (percentage > 10)
4385 msg_format("%^s¤Ï¶ìÄˤˤ¦¤á¤¤¤¿¡£", m_name);
4387 msg_format("%^s hisses in agony.", m_name);
4391 msg_format("%s¤Ï°¥¤ì¤ÊÌĤÀ¼¤ò½Ð¤·¤¿¡£", m_name);
4393 msg_format("%^s mewls pitifully.", m_name);
4398 /* Ants, Centipedes, Flies, Insects, Beetles, Spiders */
4399 else if (my_strchr("acFIKS", r_ptr->d_char))
4401 if (percentage > 95)
4403 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4405 msg_format("%^s ignores the attack.", m_name);
4407 else if (percentage > 75)
4409 msg_format("%^s¤Ï¥¡¼¥¡¼ÌĤ¤¤¿¡£", m_name);
4411 msg_format("%^s chitters.", m_name);
4414 else if (percentage > 50)
4416 msg_format("%^s¤Ï¥è¥í¥è¥íƨ¤²²ó¤Ã¤¿¡£", m_name);
4418 msg_format("%^s scuttles about.", m_name);
4421 else if (percentage > 35)
4423 msg_format("%^s¤Ï¤¦¤ë¤µ¤¯ÌĤ¤¤¿¡£", m_name);
4425 msg_format("%^s twitters.", m_name);
4428 else if (percentage > 20)
4430 msg_format("%^s¤ÏÄˤߤËáÛÚ»¤·¤¿¡£", m_name);
4432 msg_format("%^s jerks in pain.", m_name);
4435 else if (percentage > 10)
4437 msg_format("%^s¤Ï¶ìÄˤÇáÛÚ»¤·¤¿¡£", m_name);
4439 msg_format("%^s jerks in agony.", m_name);
4444 msg_format("%^s¤Ï¥Ô¥¯¥Ô¥¯¤Ò¤¤Ä¤Ã¤¿¡£", m_name);
4446 msg_format("%^s twitches.", m_name);
4453 else if (my_strchr("B", r_ptr->d_char))
4455 if (percentage > 95)
4457 msg_format("%^s¤Ï¤µ¤¨¤º¤Ã¤¿¡£", m_name);
4459 msg_format("%^s chirps.", m_name);
4462 else if (percentage > 75)
4464 msg_format("%^s¤Ï¥Ô¡¼¥Ô¡¼ÌĤ¤¤¿¡£", m_name);
4466 msg_format("%^s twitters.", m_name);
4469 else if (percentage > 50)
4471 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤¤¿¡£", m_name);
4473 msg_format("%^s squawks.", m_name);
4476 else if (percentage > 35)
4478 msg_format("%^s¤Ï¥®¥ã¡¼¥®¥ã¡¼ÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4480 msg_format("%^s chatters.", m_name);
4483 else if (percentage > 20)
4485 msg_format("%^s¤Ï¶ì¤·¤ó¤À¡£", m_name);
4487 msg_format("%^s jeers.", m_name);
4490 else if (percentage > 10)
4492 msg_format("%^s¤Ï¤Î¤¿¤¦¤Á²ó¤Ã¤¿¡£", m_name);
4494 msg_format("%^s flutters about.", m_name);
4499 msg_format("%^s¤Ï¥¡¼¥¡¼¤ÈÌĤ¶«¤ó¤À¡£", m_name);
4501 msg_format("%^s squeaks.", m_name);
4507 /* Dragons, Demons, High Undead */
4508 else if (my_strchr("duDLUW", r_ptr->d_char))
4510 if (percentage > 95)
4512 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4514 msg_format("%^s ignores the attack.", m_name);
4517 else if (percentage > 75)
4519 msg_format("%^s¤Ï¤·¤ê¹þ¤ß¤·¤¿¡£", m_name);
4521 msg_format("%^s flinches.", m_name);
4524 else if (percentage > 50)
4526 msg_format("%^s¤ÏÄˤߤǥ·¡¼¥Ã¤ÈÌĤ¤¤¿¡£", m_name);
4528 msg_format("%^s hisses in pain.", m_name);
4531 else if (percentage > 35)
4533 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4535 msg_format("%^s snarls with pain.", m_name);
4538 else if (percentage > 20)
4540 msg_format("%^s¤ÏÄˤߤËËʤ¨¤¿¡£", m_name);
4542 msg_format("%^s roars with pain.", m_name);
4545 else if (percentage > 10)
4547 msg_format("%^s¤Ï¶ì¤·¤²¤Ë¶«¤ó¤À¡£", m_name);
4549 msg_format("%^s gasps.", m_name);
4554 msg_format("%^s¤Ï¼å¡¹¤·¤¯¤¦¤Ê¤Ã¤¿¡£", m_name);
4556 msg_format("%^s snarls feebly.", m_name);
4563 else if (my_strchr("s", r_ptr->d_char))
4565 if (percentage > 95)
4567 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4569 msg_format("%^s ignores the attack.", m_name);
4572 else if (percentage > 75)
4574 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4576 msg_format("%^s shrugs off the attack.", m_name);
4579 else if (percentage > 50)
4581 msg_format("%^s¤Ï¥«¥¿¥«¥¿¤È¾Ð¤Ã¤¿¡£", m_name);
4583 msg_format("%^s rattles.", m_name);
4586 else if (percentage > 35)
4588 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4590 msg_format("%^s stumbles.", m_name);
4593 else if (percentage > 20)
4595 msg_format("%^s¤Ï¥«¥¿¥«¥¿¸À¤Ã¤¿¡£", m_name);
4597 msg_format("%^s rattles.", m_name);
4600 else if (percentage > 10)
4602 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4604 msg_format("%^s staggers.", m_name);
4609 msg_format("%^s¤Ï¥¬¥¿¥¬¥¿¸À¤Ã¤¿¡£", m_name);
4611 msg_format("%^s clatters.", m_name);
4618 else if (my_strchr("z", r_ptr->d_char))
4620 if (percentage > 95)
4622 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4624 msg_format("%^s ignores the attack.", m_name);
4627 else if (percentage > 75)
4629 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4631 msg_format("%^s shrugs off the attack.", m_name);
4634 else if (percentage > 50)
4636 msg_format("%^s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4638 msg_format("%^s groans.", m_name);
4641 else if (percentage > 35)
4643 msg_format("%s¤Ï¶ì¤·¤²¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4645 msg_format("%^s moans.", m_name);
4648 else if (percentage > 20)
4650 msg_format("%^s¤Ïí´í°¤·¤¿¡£", m_name);
4652 msg_format("%^s hesitates.", m_name);
4655 else if (percentage > 10)
4657 msg_format("%^s¤Ï¤¦¤Ê¤Ã¤¿¡£", m_name);
4659 msg_format("%^s grunts.", m_name);
4664 msg_format("%^s¤Ï¤è¤í¤á¤¤¤¿¡£", m_name);
4666 msg_format("%^s staggers.", m_name);
4673 else if (my_strchr("G", r_ptr->d_char))
4676 if (percentage > 95)
4678 msg_format("%s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4680 msg_format("%^s ignores the attack.", m_name);
4683 else if (percentage > 75)
4685 msg_format("%s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4687 msg_format("%^s shrugs off the attack.", m_name);
4690 else if (percentage > 50)
4692 msg_format("%s¤Ï¤¦¤á¤¤¤¿¡£", m_name);
4694 msg_format("%^s moans.", m_name);
4697 else if (percentage > 35)
4699 msg_format("%^s¤Ïµã¤¤ï¤á¤¤¤¿¡£", m_name);
4701 msg_format("%^s wails.", m_name);
4704 else if (percentage > 20)
4706 msg_format("%^s¤ÏËʤ¨¤¿¡£", m_name);
4708 msg_format("%^s howls.", m_name);
4711 else if (percentage > 10)
4713 msg_format("%s¤Ï¼å¡¹¤·¤¯¤¦¤á¤¤¤¿¡£", m_name);
4715 msg_format("%^s moans softly.", m_name);
4720 msg_format("%^s¤Ï¤«¤¹¤«¤Ë¤¦¤á¤¤¤¿¡£", m_name);
4722 msg_format("%^s sighs.", m_name);
4728 /* Dogs and Hounds */
4729 else if (my_strchr("CZ", r_ptr->d_char))
4732 if (percentage > 95)
4733 msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4734 else if (percentage > 75)
4735 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4736 else if (percentage > 50)
4737 msg_format("%^s¤ÏÄˤߤǥ¥ã¥ó¥¥ã¥óËʤ¨¤¿¡£", m_name);
4738 else if (percentage > 35)
4739 msg_format("%^s¤ÏÄˤߤÇÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4740 else if (percentage > 20)
4741 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÌĤ¤ï¤á¤¤¤¿¡£", m_name);
4742 else if (percentage > 10)
4743 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4745 msg_format("%^s¤Ï¼å¡¹¤·¤¯Ëʤ¨¤¿¡£", m_name);
4747 if (percentage > 95)
4748 msg_format("%^s shrugs off the attack.", m_name);
4749 else if (percentage > 75)
4750 msg_format("%^s snarls with pain.", m_name);
4751 else if (percentage > 50)
4752 msg_format("%^s yelps in pain.", m_name);
4753 else if (percentage > 35)
4754 msg_format("%^s howls in pain.", m_name);
4755 else if (percentage > 20)
4756 msg_format("%^s howls in agony.", m_name);
4757 else if (percentage > 10)
4758 msg_format("%^s writhes in agony.", m_name);
4760 msg_format("%^s yelps feebly.", m_name);
4765 /* One type of monsters (ignore,squeal,shriek) */
4766 else if (my_strchr("Xbilqrt", r_ptr->d_char))
4769 if (percentage > 95)
4770 msg_format("%^s¤Ï¹¶·â¤òµ¤¤Ë¤È¤á¤Æ¤¤¤Ê¤¤¡£", m_name);
4771 else if (percentage > 75)
4772 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4773 else if (percentage > 50)
4774 msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4775 else if (percentage > 35)
4776 msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4777 else if (percentage > 20)
4778 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4779 else if (percentage > 10)
4780 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4782 msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4784 if (percentage > 95)
4785 msg_format("%^s ignores the attack.", m_name);
4786 else if (percentage > 75)
4787 msg_format("%^s grunts with pain.", m_name);
4788 else if (percentage > 50)
4789 msg_format("%^s squeals in pain.", m_name);
4790 else if (percentage > 35)
4791 msg_format("%^s shrieks in pain.", m_name);
4792 else if (percentage > 20)
4793 msg_format("%^s shrieks in agony.", m_name);
4794 else if (percentage > 10)
4795 msg_format("%^s writhes in agony.", m_name);
4797 msg_format("%^s cries out feebly.", m_name);
4802 /* Another type of monsters (shrug,cry,scream) */
4806 if (percentage > 95)
4807 msg_format("%^s¤Ï¹¶·â¤Ë¸ª¤ò¤¹¤¯¤á¤¿¡£", m_name);
4808 else if (percentage > 75)
4809 msg_format("%^s¤ÏÄˤߤǤ¦¤Ê¤Ã¤¿¡£", m_name);
4810 else if (percentage > 50)
4811 msg_format("%^s¤ÏÄˤߤǶ«¤ó¤À¡£", m_name);
4812 else if (percentage > 35)
4813 msg_format("%^s¤ÏÄˤߤÇÀ䶫¤·¤¿¡£", m_name);
4814 else if (percentage > 20)
4815 msg_format("%^s¤Ï¶ìÄˤΤ¢¤Þ¤êÀ䶫¤·¤¿¡£", m_name);
4816 else if (percentage > 10)
4817 msg_format("%^s¤Ï¶ìÄˤǤâ¤À¤¨¶ì¤·¤ó¤À¡£", m_name);
4819 msg_format("%^s¤Ï¼å¡¹¤·¤¯¶«¤ó¤À¡£", m_name);
4821 if (percentage > 95)
4822 msg_format("%^s shrugs off the attack.", m_name);
4823 else if (percentage > 75)
4824 msg_format("%^s grunts with pain.", m_name);
4825 else if (percentage > 50)
4826 msg_format("%^s cries out in pain.", m_name);
4827 else if (percentage > 35)
4828 msg_format("%^s screams in pain.", m_name);
4829 else if (percentage > 20)
4830 msg_format("%^s screams in agony.", m_name);
4831 else if (percentage > 10)
4832 msg_format("%^s writhes in agony.", m_name);
4834 msg_format("%^s cries out feebly.", m_name);
4842 * Learn about an "observed" resistance.
4844 void update_smart_learn(int m_idx, int what)
4846 monster_type *m_ptr = &m_list[m_idx];
4848 monster_race *r_ptr = &r_info[m_ptr->r_idx];
4851 /* Not allowed to learn */
4852 if (!smart_learn) return;
4854 /* Too stupid to learn anything */
4855 if (r_ptr->flags2 & (RF2_STUPID)) return;
4857 /* Not intelligent, only learn sometimes */
4858 if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
4863 /* Analyze the knowledge */
4867 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
4868 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
4869 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
4873 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
4874 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
4875 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
4879 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
4880 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
4881 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
4885 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
4886 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
4887 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
4891 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
4892 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
4897 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
4901 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
4905 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
4909 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
4913 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
4917 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4921 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4925 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4929 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4933 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4937 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4941 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4945 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4949 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4956 * Place the player in the dungeon XXX XXX
4958 bool player_place(int y, int x)
4960 /* Paranoia XXX XXX */
4961 if (cave[y][x].m_idx != 0) return FALSE;
4963 /* Save player location */
4973 * Drop all items carried by a monster
4975 void monster_drop_carried_objects(monster_type *m_ptr)
4977 s16b this_o_idx, next_o_idx = 0;
4983 /* Drop objects being carried */
4984 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4986 /* Acquire object */
4987 o_ptr = &o_list[this_o_idx];
4989 /* Acquire next object */
4990 next_o_idx = o_ptr->next_o_idx;
4992 /* Get local object */
4995 /* Copy the object */
4996 object_copy(q_ptr, o_ptr);
4998 /* Forget monster */
4999 q_ptr->held_m_idx = 0;
5001 /* Delete the object */
5002 delete_object_idx(this_o_idx);
5005 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
5008 /* Forget objects */
5009 m_ptr->hold_o_idx = 0;