3 * @brief モンスター処理 / misc code for monsters
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7 * This software may be copied and distributed for educational, research,
8 * and not for profit purposes provided that this copyright and statement
9 * are included in all such copies. Other copyrights may also apply.
10 * 2014 Deskull rearranged comment for Doxygen.
19 #include "object-flavor.h"
20 #include "monsterrace-hook.h"
21 #include "monster-status.h"
24 #include "spells-summon.h"
27 #include "player-move.h"
30 #include "player-status.h"
31 #include "monster-spell.h"
33 #include "view-mainwindow.h"
36 #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */
37 #define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */
41 * @brief モンスターの目標地点をセットする / Set the target of counter attack
42 * @param m_ptr モンスターの参照ポインタ
47 void set_target(monster_type *m_ptr, POSITION y, POSITION x)
55 * @brief モンスターの目標地点をリセットする / Reset the target of counter attack
56 * @param m_ptr モンスターの参照ポインタ
59 void reset_target(monster_type *m_ptr)
61 set_target(m_ptr, 0, 0);
66 * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form
67 * @param m_ptr モンスターの参照ポインタ
68 * @return 本当のモンスター種族参照ポインタ
70 monster_race *real_r_ptr(monster_type *m_ptr)
72 return &r_info[real_r_idx(m_ptr)];
75 MONRACE_IDX real_r_idx(monster_type *m_ptr)
77 monster_race *r_ptr = &r_info[m_ptr->r_idx];
79 /* Extract real race */
80 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
82 if (r_ptr->flags1 & RF1_UNIQUE)
83 return MON_CHAMELEON_K;
95 * @brief モンスター配列からモンスターを消去する / Delete a monster by index.
96 * @param i 消去するモンスターのID
99 * モンスターを削除するとそのモンスターが拾っていたアイテムも同時に削除される。 /
100 * When a monster is deleted, all of its objects are deleted.
102 void delete_monster_idx(MONSTER_IDX i)
105 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
106 monster_race *r_ptr = &r_info[m_ptr->r_idx];
107 OBJECT_IDX this_o_idx, next_o_idx = 0;
112 /* Hack -- Reduce the racial counter */
113 real_r_ptr(m_ptr)->cur_num--;
115 /* Hack -- count the number of "reproducers" */
116 if (r_ptr->flags2 & (RF2_MULTIPLY)) current_floor_ptr->num_repro--;
118 if (MON_CSLEEP(m_ptr)) (void)set_monster_csleep(i, 0);
119 if (MON_FAST(m_ptr)) (void)set_monster_fast(i, 0);
120 if (MON_SLOW(m_ptr)) (void)set_monster_slow(i, 0);
121 if (MON_STUNNED(m_ptr)) (void)set_monster_stunned(i, 0);
122 if (MON_CONFUSED(m_ptr)) (void)set_monster_confused(i, 0);
123 if (MON_MONFEAR(m_ptr)) (void)set_monster_monfear(i, 0);
124 if (MON_INVULNER(m_ptr)) (void)set_monster_invulner(i, 0, FALSE);
126 /* Hack -- remove target monster */
127 if (i == target_who) target_who = 0;
129 /* Hack -- remove tracked monster */
130 if (i == p_ptr->health_who) health_track(0);
132 if (pet_t_m_idx == i ) pet_t_m_idx = 0;
133 if (riding_t_m_idx == i) riding_t_m_idx = 0;
134 if (p_ptr->riding == i) p_ptr->riding = 0;
136 /* Monster is gone */
137 current_floor_ptr->grid_array[y][x].m_idx = 0;
139 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
142 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
143 next_o_idx = o_ptr->next_o_idx;
146 * o_ptr->held_m_idx is needed in delete_object_idx()
147 * to prevent calling lite_spot()
150 delete_object_idx(this_o_idx);
153 (void)WIPE(m_ptr, monster_type);
159 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
161 p_ptr->update |= (PU_MON_LITE);
167 * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
172 void delete_monster(POSITION y, POSITION x)
175 if (!in_bounds(y, x)) return;
178 g_ptr = ¤t_floor_ptr->grid_array[y][x];
180 /* Delete the monster (if any) */
181 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
186 * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
191 static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
197 OBJECT_IDX this_o_idx, next_o_idx = 0;
200 if (i1 == i2) return;
203 m_ptr = ¤t_floor_ptr->m_list[i1];
209 g_ptr = ¤t_floor_ptr->grid_array[y][x];
211 /* Update the current_floor_ptr->grid_array */
214 /* Repair objects being carried by monster */
215 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
218 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
219 next_o_idx = o_ptr->next_o_idx;
221 /* Reset monster pointer */
222 o_ptr->held_m_idx = i2;
225 /* Hack -- Update the target */
226 if (target_who == i1) target_who = i2;
228 /* Hack -- Update the target */
229 if (pet_t_m_idx == i1) pet_t_m_idx = i2;
230 if (riding_t_m_idx == i1) riding_t_m_idx = i2;
232 /* Hack -- Update the riding */
233 if (p_ptr->riding == i1) p_ptr->riding = i2;
235 /* Hack -- Update the health bar */
236 if (p_ptr->health_who == i1) health_track(i2);
238 /* Hack -- Update parent index */
241 for (i = 1; i < m_max; i++)
243 monster_type *m2_ptr = ¤t_floor_ptr->m_list[i];
245 if (m2_ptr->parent_m_idx == i1)
246 m2_ptr->parent_m_idx = i2;
251 (void)COPY(¤t_floor_ptr->m_list[i2], ¤t_floor_ptr->m_list[i1], monster_type);
254 (void)WIPE(¤t_floor_ptr->m_list[i1], monster_type);
256 for (i = 0; i < MAX_MTIMED; i++)
258 int mproc_idx = get_mproc_idx(i1, i);
259 if (mproc_idx >= 0) current_floor_ptr->mproc_list[i][mproc_idx] = i2;
265 * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
266 * @param size 圧縮後のモンスター件数目標
269 * This function can be very dangerous, use with caution!
271 * When actually "compacting" monsters, we base the saving throw
272 * on a combination of monster level, distance from player, and
273 * current "desperation".
275 * After "compacting" (if needed), we "reorder" the monsters into a more
276 * compact order, and we reset the allocation info, and the "live" array.
278 void compact_monsters(int size)
282 int cur_lev, cur_dis, chance;
284 /* Message (only if compacting) */
285 if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
288 /* Compact at least 'size' objects */
289 for (num = 0, cnt = 1; num < size; cnt++)
291 /* Get more vicious each iteration */
294 /* Get closer each iteration */
295 cur_dis = 5 * (20 - cnt);
297 /* Check all the monsters */
298 for (i = 1; i < m_max; i++)
300 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
302 monster_race *r_ptr = &r_info[m_ptr->r_idx];
304 /* Paranoia -- skip "dead" monsters */
305 if (!monster_is_valid(m_ptr)) continue;
307 /* Hack -- High level monsters start out "immune" */
308 if (r_ptr->level > cur_lev) continue;
310 if (i == p_ptr->riding) continue;
312 /* Ignore nearby monsters */
313 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
315 /* Saving throw chance */
318 /* Only compact "Quest" Monsters in emergencies */
319 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
321 /* Try not to compact Unique Monsters */
322 if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
324 /* All monsters get a saving throw */
325 if (randint0(100) < chance) continue;
327 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
329 GAME_TEXT m_name[MAX_NLEN];
330 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
331 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
334 delete_monster_idx(i);
336 /* Count the monster */
342 /* Excise dead monsters (backwards!) */
343 for (i = m_max - 1; i >= 1; i--)
345 /* Get the i'th monster */
346 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
348 /* Skip real monsters */
349 if (m_ptr->r_idx) continue;
351 /* Move last monster into open hole */
352 compact_monsters_aux(m_max - 1, i);
354 /* Compress "m_max" */
361 * @brief プレイヤーのフロア離脱に伴う全モンスター配列の消去 / Delete/Remove all the monsters when the player leaves the level
364 * This is an efficient method of simulating multiple calls to the
365 * "delete_monster()" function, with no visual effects.
367 void wipe_m_list(void)
371 /* Hack -- if Banor or Lupart dies, stay another dead */
372 if (!r_info[MON_BANORLUPART].max_num)
374 if (r_info[MON_BANOR].max_num)
376 r_info[MON_BANOR].max_num = 0;
377 r_info[MON_BANOR].r_pkills++;
378 r_info[MON_BANOR].r_akills++;
379 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
381 if (r_info[MON_LUPART].max_num)
383 r_info[MON_LUPART].max_num = 0;
384 r_info[MON_LUPART].r_pkills++;
385 r_info[MON_LUPART].r_akills++;
386 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
390 /* Delete all the monsters */
391 for (i = m_max - 1; i >= 1; i--)
393 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
394 if (!monster_is_valid(m_ptr)) continue;
396 /* Monster is gone */
397 current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx = 0;
399 (void)WIPE(m_ptr, monster_type);
404 * Wiping racial counters of all monsters and incrementing of racial
405 * counters of monsters in party_mon[] are required to prevent multiple
406 * generation of unique monster who is the minion of player.
409 /* Hack -- Wipe the racial counter of all monster races */
410 for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
418 /* Reset "current_floor_ptr->mproc_max[]" */
419 for (i = 0; i < MAX_MTIMED; i++) current_floor_ptr->mproc_max[i] = 0;
421 /* Hack -- reset "reproducer" count */
422 current_floor_ptr->num_repro = 0;
424 /* Hack -- no more target */
429 /* Hack -- no more tracking */
435 * @brief モンスター配列の空きを探す / Acquires and returns the index of a "free" monster.
436 * @return 利用可能なモンスター配列の添字
438 * This routine should almost never fail, but it *can* happen.
440 MONSTER_IDX m_pop(void)
444 /* Normal allocation */
445 if (m_max < current_floor_ptr->max_m_idx)
447 /* Access the next hole */
450 /* Expand the array */
456 /* Return the index */
460 /* Recycle dead monsters */
461 for (i = 1; i < m_max; i++)
465 /* Acquire monster */
466 m_ptr = ¤t_floor_ptr->m_list[i];
468 /* Skip live monsters */
469 if (m_ptr->r_idx) continue;
474 /* Use this monster */
478 /* Warn the player (except during dungeon creation) */
479 if (character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
481 /* Try not to crash */
489 * @var summon_specific_type
490 * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
491 * @todo summon_specific_typeグローバル変数の除去と関数引数への代替を行う
493 static int summon_specific_type = 0;
497 * @var summon_specific_who
498 * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
499 * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
501 static int summon_specific_who = -1;
504 * @var summon_unique_okay
505 * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
506 * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
508 static bool summon_unique_okay = FALSE;
511 * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
512 * @return 召喚条件が一致するならtrue
515 static bool summon_specific_aux(MONRACE_IDX r_idx)
517 monster_race *r_ptr = &r_info[r_idx];
520 /* Check our requirements */
521 switch (summon_specific_type)
525 okay = (r_ptr->d_char == 'a');
531 okay = (r_ptr->d_char == 'S');
537 okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
543 okay = (r_ptr->d_char == 'M');
549 okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
555 okay = (r_ptr->flags3 & RF3_DEMON);
561 okay = (r_ptr->flags3 & RF3_UNDEAD);
567 okay = (r_ptr->flags3 & RF3_DRAGON);
571 case SUMMON_HI_UNDEAD:
573 okay = ((r_ptr->d_char == 'L') ||
574 (r_ptr->d_char == 'V') ||
575 (r_ptr->d_char == 'W'));
579 case SUMMON_HI_DRAGON:
581 okay = (r_ptr->d_char == 'D');
585 case SUMMON_HI_DEMON:
587 okay = (((r_ptr->d_char == 'U') ||
588 (r_ptr->d_char == 'H') ||
589 (r_ptr->d_char == 'B')) &&
590 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
594 case SUMMON_AMBERITES:
596 okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
602 okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
608 okay = (r_ptr->d_char == 'm');
613 okay = (r_ptr->d_char == 'b');
616 case SUMMON_QUYLTHULG:
618 okay = (r_ptr->d_char == 'Q');
622 case SUMMON_COIN_MIMIC:
624 okay = (r_ptr->d_char == '$');
630 okay = ((r_ptr->d_char == '!') ||
631 (r_ptr->d_char == '?') ||
632 (r_ptr->d_char == '=') ||
633 (r_ptr->d_char == '$') ||
634 (r_ptr->d_char == '|'));
640 okay = (r_ptr->d_char == 'g');
646 okay = ((r_ptr->d_char == 'U') &&
647 (r_ptr->flags4 & RF4_ROCKET));
653 okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
659 okay = (r_idx == MON_DAWN);
665 okay = (r_ptr->flags3 & (RF3_ANIMAL));
669 case SUMMON_ANIMAL_RANGER:
671 okay = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
672 (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
673 !(r_ptr->flags3 & (RF3_DRAGON)) &&
674 !(r_ptr->flags3 & (RF3_EVIL)) &&
675 !(r_ptr->flags3 & (RF3_UNDEAD)) &&
676 !(r_ptr->flags3 & (RF3_DEMON)) &&
677 !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
678 !(r_ptr->flags4 || r_ptr->a_ability_flags1 || r_ptr->a_ability_flags2));
682 case SUMMON_HI_DRAGON_LIVING:
684 okay = ((r_ptr->d_char == 'D') && monster_living(r_idx));
690 okay = monster_living(r_idx);
696 okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
700 case SUMMON_BLUE_HORROR:
702 okay = (r_idx == MON_BLUE_HORROR);
706 case SUMMON_ELEMENTAL:
708 okay = (r_ptr->d_char == 'E');
714 okay = (r_ptr->d_char == 'v');
720 okay = (r_ptr->d_char == 'H');
726 okay = (r_ptr->d_char == 'B');
730 case SUMMON_KAMIKAZE:
733 for (i = 0; i < 4; i++)
734 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
738 case SUMMON_KAMIKAZE_LIVING:
742 for (i = 0; i < 4; i++)
743 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
744 okay = (okay && monster_living(r_idx));
750 okay = (r_idx == MON_MANES);
756 okay = (r_idx == MON_LOUSE);
760 case SUMMON_GUARDIANS:
762 okay = (r_ptr->flags7 & RF7_GUARDIAN);
768 okay = ((r_idx == MON_NOV_PALADIN) ||
769 (r_idx == MON_NOV_PALADIN_G) ||
770 (r_idx == MON_PALADIN) ||
771 (r_idx == MON_W_KNIGHT) ||
772 (r_idx == MON_ULTRA_PALADIN) ||
773 (r_idx == MON_KNI_TEMPLAR));
779 okay = (r_ptr->d_char == 'B' &&
780 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
781 (r_ptr->flags8 & RF8_WILD_ONLY));
785 case SUMMON_PIRANHAS:
787 okay = (r_idx == MON_PIRANHA);
791 case SUMMON_ARMAGE_GOOD:
793 okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
797 case SUMMON_ARMAGE_EVIL:
799 okay = ((r_ptr->flags3 & RF3_DEMON) ||
800 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
804 /* Since okay is int, "return (okay);" is not correct. */
805 return (bool)(okay ? TRUE : FALSE);
809 * @var chameleon_change_m_idx
810 * @brief カメレオンの変身先モンスターIDを受け渡すためのグローバル変数
811 * @todo 変数渡しの問題などもあるができればchameleon_change_m_idxのグローバル変数を除去し、関数引き渡しに移行すること
813 static int chameleon_change_m_idx = 0;
817 * @brief 指定されたモンスター種族がダンジョンの制限にかかるかどうかをチェックする / Some dungeon types restrict the possible monsters.
818 * @param r_idx チェックするモンスター種族ID
819 * @return 召喚条件が一致するならtrue / Return TRUE is the monster is OK and FALSE otherwise
821 static bool restrict_monster_to_dungeon(MONRACE_IDX r_idx)
823 dungeon_type *d_ptr = &d_info[p_ptr->dungeon_idx];
824 monster_race *r_ptr = &r_info[r_idx];
827 if (d_ptr->flags1 & DF1_CHAMELEON)
829 if (chameleon_change_m_idx) return TRUE;
831 if (d_ptr->flags1 & DF1_NO_MAGIC)
833 if (r_idx != MON_CHAMELEON &&
835 !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
836 !(r_ptr->a_ability_flags1 & RF5_NOMAGIC_MASK) &&
837 !(r_ptr->a_ability_flags2 & RF6_NOMAGIC_MASK))
840 if (d_ptr->flags1 & DF1_NO_MELEE)
842 if (r_idx == MON_CHAMELEON) return TRUE;
843 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
844 !(r_ptr->a_ability_flags1 & (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)) &&
845 !(r_ptr->a_ability_flags2 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
848 if (d_ptr->flags1 & DF1_BEGINNER)
850 if (r_ptr->level > current_floor_ptr->dun_level)
854 if (d_ptr->special_div >= 64) return TRUE;
855 if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
859 case DUNGEON_MODE_AND:
862 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
867 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
872 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
877 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
880 if (d_ptr->m_a_ability_flags1)
882 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
885 if (d_ptr->m_a_ability_flags2)
887 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
892 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
897 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
902 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
907 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
910 for (a = 0; a < 5; a++)
911 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
915 case DUNGEON_MODE_NAND:
918 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
923 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
928 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
933 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
936 if (d_ptr->m_a_ability_flags1)
938 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
941 if (d_ptr->m_a_ability_flags2)
943 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
948 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
953 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
958 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
963 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
966 for (a = 0; a < 5; a++)
967 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
971 case DUNGEON_MODE_OR:
972 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
973 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
974 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
975 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
976 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return TRUE;
977 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return TRUE;
978 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
979 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
980 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
981 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
982 for (a = 0; a < 5; a++)
983 if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
987 case DUNGEON_MODE_NOR:
988 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
989 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
990 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
991 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
992 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return FALSE;
993 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return FALSE;
994 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
995 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
996 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
997 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
998 for (a = 0; a < 5; a++)
999 if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1008 * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
1009 * @param monster_hook 制限関数1
1010 * @param monster_hook2 制限関数2
1013 errr get_mon_num_prep(monsterrace_hook_type monster_hook,
1014 monsterrace_hook_type monster_hook2)
1018 /* Todo: Check the hooks for non-changes */
1020 /* Set the new hooks */
1021 get_mon_num_hook = monster_hook;
1022 get_mon_num2_hook = monster_hook2;
1024 /* Scan the allocation table */
1025 for (i = 0; i < alloc_race_size; i++)
1027 monster_race *r_ptr;
1030 alloc_entry *entry = &alloc_race_table[i];
1033 r_ptr = &r_info[entry->index];
1035 /* Skip monsters which don't pass the restriction */
1036 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1037 (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1040 if (!p_ptr->inside_battle && !chameleon_change_m_idx &&
1041 summon_specific_type != SUMMON_GUARDIANS)
1043 /* Hack -- don't create questors */
1044 if (r_ptr->flags1 & RF1_QUESTOR)
1047 if (r_ptr->flags7 & RF7_GUARDIAN)
1050 /* Depth Monsters never appear out of depth */
1051 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1052 (r_ptr->level > current_floor_ptr->dun_level))
1056 /* Accept this monster */
1057 entry->prob2 = entry->prob1;
1059 if (current_floor_ptr->dun_level && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest)) && !restrict_monster_to_dungeon(entry->index) && !p_ptr->inside_battle)
1061 int hoge = entry->prob2 * d_info[p_ptr->dungeon_idx].special_div;
1062 entry->prob2 = hoge / 64;
1063 if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1073 * @brief 生成モンスター種族を1種生成テーブルから選択する
1075 * @return 選択されたモンスター生成種族
1077 * Choose a monster race that seems "appropriate" to the given level
1079 * This function uses the "prob2" field of the "monster allocation table",
1080 * and various local information, to calculate the "prob3" field of the
1081 * same table, which is then used to choose an "appropriate" monster, in
1082 * a relatively efficient manner.
1084 * Note that "town" monsters will *only* be created in the town, and
1085 * "normal" monsters will *never* be created in the town, unless the
1086 * "level" is "modified", for example, by polymorph or summoning.
1088 * There is a small chance (1/50) of "boosting" the given depth by
1089 * a small amount (up to four levels), except in the town.
1091 * It is (slightly) more likely to acquire a monster of the given level
1092 * than one of a lower level. This is done by choosing several monsters
1093 * appropriate to the given level and keeping the "hardest" one.
1095 * Note that if no monsters are "appropriate", then this function will
1096 * fail, and return zero, but this should *almost* never happen.
1098 MONRACE_IDX get_mon_num(DEPTH level)
1103 monster_race *r_ptr;
1104 alloc_entry *table = alloc_race_table;
1106 int pls_kakuritu, pls_level;
1107 int delay = mysqrt(level * 10000L) + 400L;
1109 pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10)));
1110 pls_level = MIN(NASTY_MON_PLUS_MAX, 3 + current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10)) ;
1112 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_MAZE)
1114 pls_kakuritu = MIN(pls_kakuritu / 2, pls_kakuritu - 10);
1115 if (pls_kakuritu < 2) pls_kakuritu = 2;
1120 /* Boost the level */
1121 if (!p_ptr->inside_battle && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1123 /* Nightmare mode allows more out-of depth monsters */
1124 if (ironman_nightmare && !randint0(pls_kakuritu))
1126 /* What a bizarre calculation */
1127 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1131 /* Occasional "nasty" monster */
1132 if (!randint0(pls_kakuritu))
1134 /* Pick a level bonus */
1140 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1141 if (level < 0) level = 0;
1146 /* Process probabilities */
1147 for (i = 0; i < alloc_race_size; i++)
1149 /* Monsters are sorted by depth */
1150 if (table[i].level > level) break;
1155 /* Access the "r_idx" of the chosen monster */
1156 r_idx = table[i].index;
1158 /* Access the actual race */
1159 r_ptr = &r_info[r_idx];
1161 if (!p_ptr->inside_battle && !chameleon_change_m_idx)
1163 /* Hack -- "unique" monsters must be "unique" */
1164 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1165 (r_ptr->flags7 & (RF7_NAZGUL))) &&
1166 (r_ptr->cur_num >= r_ptr->max_num))
1171 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1172 (r_ptr->cur_num >= 1))
1177 if (r_idx == MON_BANORLUPART)
1179 if (r_info[MON_BANOR].cur_num > 0) continue;
1180 if (r_info[MON_LUPART].cur_num > 0) continue;
1185 table[i].prob3 = table[i].prob2;
1188 total += table[i].prob3;
1191 /* No legal monsters */
1192 if (total <= 0) return (0);
1194 /* Pick a monster */
1195 value = randint0(total);
1197 /* Find the monster */
1198 for (i = 0; i < alloc_race_size; i++)
1200 /* Found the entry */
1201 if (value < table[i].prob3) break;
1204 value = value - table[i].prob3;
1210 /* Try for a "harder" monster once (50%) or twice (10%) */
1216 /* Pick a monster */
1217 value = randint0(total);
1219 /* Find the monster */
1220 for (i = 0; i < alloc_race_size; i++)
1222 /* Found the entry */
1223 if (value < table[i].prob3) break;
1226 value = value - table[i].prob3;
1229 /* Keep the "best" one */
1230 if (table[i].level < table[j].level) i = j;
1233 /* Try for a "harder" monster twice (10%) */
1239 /* Pick a monster */
1240 value = randint0(total);
1242 /* Find the monster */
1243 for (i = 0; i < alloc_race_size; i++)
1245 /* Found the entry */
1246 if (value < table[i].prob3) break;
1249 value = value - table[i].prob3;
1252 /* Keep the "best" one */
1253 if (table[i].level < table[j].level) i = j;
1255 return (table[i].index);
1260 * @brief モンスターの呼称を作成する / Build a string describing a monster in some way.
1261 * @param desc 記述出力先の文字列参照ポインタ
1262 * @param m_ptr モンスターの参照ポインタ
1263 * @param mode 呼称オプション
1266 * We can correctly describe monsters based on their visibility.
1267 * We can force all monsters to be treated as visible or invisible.
1268 * We can build nominatives, objectives, possessives, or reflexives.
1269 * We can selectively pronominalize hidden, visible, or all monsters.
1270 * We can use definite or indefinite descriptions for hidden monsters.
1271 * We can use definite or indefinite descriptions for visible monsters.
1273 * Pronominalization involves the gender whenever possible and allowed,
1274 * so that by cleverly requesting pronominalization / visibility, you
1275 * can get messages like "You hit someone. She screams in agony!".
1277 * Reflexives are acquired by requesting Objective plus Possessive.
1279 * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1280 * unless the "Assume Visible" mode is requested.
1282 * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1283 * If neither m_ptr nor r_ptr is given, the monster is assumed to
1284 * be neuter, singular, and hidden (unless "Assume Visible" is set),
1285 * in which case you may be in trouble... :-)
1287 * I am assuming that no monster name is more than 70 characters long,
1288 * so that "char desc[80];" is sufficiently large for any result.
1291 * MD_OBJECTIVE --> Objective (or Reflexive)
1292 * MD_POSSESSIVE --> Possessive (or Reflexive)
1293 * MD_INDEF_HIDDEN --> Use indefinites for hidden monsters ("something")
1294 * MD_INDEF_VISIBLE --> Use indefinites for visible monsters ("a kobold")
1295 * MD_PRON_HIDDEN --> Pronominalize hidden monsters
1296 * MD_PRON_VISIBLE --> Pronominalize visible monsters
1297 * MD_ASSUME_HIDDEN --> Assume the monster is hidden
1298 * MD_ASSUME_VISIBLE --> Assume the monster is visible
1299 * MD_TRUE_NAME --> Chameleon's true name
1300 * MD_IGNORE_HALLU --> Ignore hallucination, and penetrate shape change
1303 * 0x00 --> Full nominative name ("the kobold") or "it"
1304 * MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1305 * MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1306 * MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1307 * MD_PRON_VISIBLE | MD_POSSESSIVE
1308 * --> Possessive, genderized if visable ("his") or "its"
1309 * MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1310 * --> Reflexive, genderized if visable ("himself") or "itself"
1312 void monster_desc(char *desc, monster_type *m_ptr, BIT_FLAGS mode)
1315 monster_race *r_ptr;
1319 GAME_TEXT silly_name[1024];
1323 r_ptr = &r_info[m_ptr->ap_r_idx];
1325 /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1326 if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1327 else name = (r_name + r_ptr->name);
1329 /* Are we hallucinating? (Idea from Nethack...) */
1330 if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1334 if (!get_rnd_line(_("silly_j.txt", "silly.txt"), m_ptr->r_idx, silly_name))
1340 monster_race *hallu_race;
1344 hallu_race = &r_info[randint1(max_r_idx - 1)];
1346 while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
1348 strcpy(silly_name, (r_name + hallu_race->name));
1351 /* Better not strcpy it, or we could corrupt r_info... */
1355 /* Can we "see" it (exists + forced, or visible + not unforced) */
1356 seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1358 /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1359 pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1362 /* First, try using pronouns, or describing hidden monsters */
1365 /* an encoding of the monster "sex" */
1368 /* Extract the gender (if applicable) */
1369 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1370 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1372 /* Ignore the gender (if desired) */
1373 if (!m_ptr || !pron) kind = 0x00;
1376 /* Assume simple result */
1377 res = _("何か", "it");
1379 /* Brute force: split on the possibilities */
1380 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1382 /* Neuter, or unknown */
1384 case 0x00: res = "何か"; break;
1385 case 0x00 + (MD_OBJECTIVE): res = "何か"; break;
1386 case 0x00 + (MD_POSSESSIVE): res = "何かの"; break;
1387 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "何か自身"; break;
1388 case 0x00 + (MD_INDEF_HIDDEN): res = "何か"; break;
1389 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "何か"; break;
1390 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "何か"; break;
1391 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "それ自身"; break;
1393 case 0x00: res = "it"; break;
1394 case 0x00 + (MD_OBJECTIVE): res = "it"; break;
1395 case 0x00 + (MD_POSSESSIVE): res = "its"; break;
1396 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1397 case 0x00 + (MD_INDEF_HIDDEN): res = "something"; break;
1398 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "something"; break;
1399 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "something's"; break;
1400 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1404 /* Male (assume human if vague) */
1406 case 0x10: res = "彼"; break;
1407 case 0x10 + (MD_OBJECTIVE): res = "彼"; break;
1408 case 0x10 + (MD_POSSESSIVE): res = "彼の"; break;
1409 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "彼自身"; break;
1410 case 0x10 + (MD_INDEF_HIDDEN): res = "誰か"; break;
1411 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "誰か"; break;
1412 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "誰かの"; break;
1413 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "彼自身"; break;
1415 case 0x10: res = "he"; break;
1416 case 0x10 + (MD_OBJECTIVE): res = "him"; break;
1417 case 0x10 + (MD_POSSESSIVE): res = "his"; break;
1418 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1419 case 0x10 + (MD_INDEF_HIDDEN): res = "someone"; break;
1420 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1421 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1422 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1426 /* Female (assume human if vague) */
1428 case 0x20: res = "彼女"; break;
1429 case 0x20 + (MD_OBJECTIVE): res = "彼女"; break;
1430 case 0x20 + (MD_POSSESSIVE): res = "彼女の"; break;
1431 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "彼女自身"; break;
1432 case 0x20 + (MD_INDEF_HIDDEN): res = "誰か"; break;
1433 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "誰か"; break;
1434 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "誰かの"; break;
1435 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "彼女自身"; break;
1437 case 0x20: res = "she"; break;
1438 case 0x20 + (MD_OBJECTIVE): res = "her"; break;
1439 case 0x20 + (MD_POSSESSIVE): res = "her"; break;
1440 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1441 case 0x20 + (MD_INDEF_HIDDEN): res = "someone"; break;
1442 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1443 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1444 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1448 /* Copy the result */
1449 (void)strcpy(desc, res);
1453 /* Handle visible monsters, "reflexive" request */
1454 else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1456 /* The monster is visible, so use its gender */
1457 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, _("彼女自身", "herself"));
1458 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, _("彼自身", "himself"));
1459 else strcpy(desc, _("それ自身", "itself"));
1463 /* Handle all other visible monster requests */
1467 if (is_pet(m_ptr) && !is_original_ap(m_ptr))
1473 while(strncmp(t, "』", 2) && *t) t++;
1477 (void)sprintf(desc, "%s?』", buf);
1480 (void)sprintf(desc, "%s?", name);
1482 (void)sprintf(desc, "%s?", name);
1487 /* It could be a Unique */
1488 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1490 /* Start with the name (thus nominative and objective) */
1491 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1497 while (strncmp(t, "』", 2) && *t) t++;
1501 (void)sprintf(desc, "%s?』", buf);
1504 (void)sprintf(desc, "%s?", name);
1506 (void)sprintf(desc, "%s?", name);
1510 /* Inside monster arena, and it is not your mount */
1511 else if (p_ptr->inside_battle &&
1512 !(p_ptr->riding && (¤t_floor_ptr->m_list[p_ptr->riding] == m_ptr)))
1514 /* It is a fake unique monster */
1515 (void)sprintf(desc, _("%sもどき", "fake %s"), name);
1520 (void)strcpy(desc, name);
1524 /* It could be an indefinite monster */
1525 else if (mode & MD_INDEF_VISIBLE)
1527 /* XXX Check plurality for "some" */
1529 /* Indefinite monsters need an indefinite article */
1531 (void)strcpy(desc, "");
1533 (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1536 (void)strcat(desc, name);
1539 /* It could be a normal, definite, monster */
1542 /* Definite monsters need a definite article */
1544 (void)strcpy(desc, _("あなたの", "your "));
1546 (void)strcpy(desc, _("", "the "));
1548 (void)strcat(desc, name);
1551 if (m_ptr->nickname)
1553 sprintf(buf,_("「%s」", " called %s"),quark_str(m_ptr->nickname));
1557 if (p_ptr->riding && (¤t_floor_ptr->m_list[p_ptr->riding] == m_ptr))
1559 strcat(desc,_("(乗馬中)", "(riding)"));
1562 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1564 if (r_ptr->flags1 & RF1_UNIQUE)
1566 strcat(desc,_("(カメレオンの王)", "(Chameleon Lord)"));
1570 strcat(desc,_("(カメレオン)", "(Chameleon)"));
1574 if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr))
1576 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1579 /* Handle the Possessive as a special afterthought */
1580 if (mode & MD_POSSESSIVE)
1582 /* XXX Check for trailing "s" */
1584 /* Simply append "apostrophe" and "s" */
1585 (void)strcat(desc, _("の", "'s"));
1591 * @brief モンスターIDを取り、モンスター名をm_nameに代入する /
1592 * @param m_idx モンスターID
1593 * @param m_name モンスター名を入力する配列
1595 void monster_name(MONSTER_IDX m_idx, char* m_name)
1597 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1598 monster_desc(m_name, m_ptr, 0x00);
1603 * @brief モンスターの調査による思い出補完処理 / Learn about a monster (by "probing" it)
1604 * @param r_idx 補完されるモンスター種族ID
1605 * @return 明らかになった情報の度数
1607 * Return the number of new flags learnt. -Mogami-
1609 int lore_do_probe(MONRACE_IDX r_idx)
1611 monster_race *r_ptr = &r_info[r_idx];
1615 /* Maximal info about awareness */
1616 if (r_ptr->r_wake != MAX_UCHAR) n++;
1617 if (r_ptr->r_ignore != MAX_UCHAR) n++;
1618 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1620 /* Observe "maximal" attacks */
1621 for (i = 0; i < 4; i++)
1623 /* Examine "actual" blows */
1624 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1626 /* Maximal observations */
1627 if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1628 r_ptr->r_blows[i] = MAX_UCHAR;
1634 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1635 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1636 ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1637 ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1638 ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1639 ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1641 /* Only "valid" drops */
1642 if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1644 if (r_ptr->r_drop_item != tmp_byte) n++;
1645 r_ptr->r_drop_item = tmp_byte;
1647 if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1649 if (r_ptr->r_drop_gold != tmp_byte) n++;
1650 r_ptr->r_drop_gold = tmp_byte;
1653 /* Observe many spells */
1654 if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1655 r_ptr->r_cast_spell = MAX_UCHAR;
1657 /* Count unknown flags */
1658 for (i = 0; i < 32; i++)
1660 if (!(r_ptr->r_flags1 & (1L << i)) &&
1661 (r_ptr->flags1 & (1L << i))) n++;
1662 if (!(r_ptr->r_flags2 & (1L << i)) &&
1663 (r_ptr->flags2 & (1L << i))) n++;
1664 if (!(r_ptr->r_flags3 & (1L << i)) &&
1665 (r_ptr->flags3 & (1L << i))) n++;
1666 if (!(r_ptr->r_flags4 & (1L << i)) &&
1667 (r_ptr->flags4 & (1L << i))) n++;
1668 if (!(r_ptr->r_flags5 & (1L << i)) &&
1669 (r_ptr->a_ability_flags1 & (1L << i))) n++;
1670 if (!(r_ptr->r_flags6 & (1L << i)) &&
1671 (r_ptr->a_ability_flags2 & (1L << i))) n++;
1672 if (!(r_ptr->r_flagsr & (1L << i)) &&
1673 (r_ptr->flagsr & (1L << i))) n++;
1675 /* r_flags7 is actually unused */
1677 if (!(r_ptr->r_flags7 & (1L << i)) &&
1678 (r_ptr->flags7 & (1L << i))) n++;
1682 /* Know all the flags */
1683 r_ptr->r_flags1 = r_ptr->flags1;
1684 r_ptr->r_flags2 = r_ptr->flags2;
1685 r_ptr->r_flags3 = r_ptr->flags3;
1686 r_ptr->r_flags4 = r_ptr->flags4;
1687 r_ptr->r_flags5 = r_ptr->a_ability_flags1;
1688 r_ptr->r_flags6 = r_ptr->a_ability_flags2;
1689 r_ptr->r_flagsr = r_ptr->flagsr;
1691 /* r_flags7 is actually unused */
1692 /* r_ptr->r_flags7 = r_ptr->flags7; */
1694 /* Know about evolution */
1695 if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1696 r_ptr->r_xtra1 |= MR1_SINKA;
1698 /* Update monster recall window */
1699 if (p_ptr->monster_race_idx == r_idx)
1701 p_ptr->window |= (PW_MONSTER);
1704 /* Return the number of new flags learnt */
1710 * @brief モンスターの撃破に伴うドロップ情報の保管処理 / Take note that the given monster just dropped some treasure
1711 * @param m_idx モンスター情報のID
1712 * @param num_item 手に入れたアイテム数
1713 * @param num_gold 手に入れた財宝の単位数
1716 * Note that learning the "GOOD"/"GREAT" flags gives information
1717 * about the treasure (even when the monster is killed for the first
1718 * time, such as uniques, and the treasure has not been examined yet).
1720 * This "indirect" method is used to prevent the player from learning
1721 * exactly how much treasure a monster can drop from observing only
1722 * a single example of a drop. This method actually observes how much
1723 * gold and items are dropped, and remembers that information to be
1724 * described later by the monster recall code.
1726 void lore_treasure(MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
1728 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1730 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1732 /* If the monster doesn't have original appearance, don't note */
1733 if (!is_original_ap(m_ptr)) return;
1735 /* Note the number of things dropped */
1736 if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1737 if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1739 /* Hack -- memorize the good/great flags */
1740 if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1741 if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1743 /* Update monster recall window */
1744 if (p_ptr->monster_race_idx == m_ptr->r_idx)
1746 p_ptr->window |= (PW_MONSTER);
1752 * @brief モンスターの各情報を更新する / This function updates the monster record of the given monster
1753 * @param m_idx 更新するモンスター情報のID
1754 * @param full プレイヤーとの距離更新を行うならばtrue
1757 * This involves extracting the distance to the player (if requested),
1758 * and then checking for visibility (natural, infravision, see-invis,
1759 * telepathy), updating the monster visibility flag, redrawing (or
1760 * erasing) the monster when its visibility changes, and taking note
1761 * of any interesting monster flags (cold-blooded, invisible, etc).
1763 * Note the new "mflag" field which encodes several monster state flags,
1764 * including "view" for when the monster is currently in line of sight,
1765 * and "mark" for when the monster is currently visible via detection.
1767 * The only monster fields that are changed here are "cdis" (the
1768 * distance from the player), "ml" (visible to the player), and
1769 * "mflag" (to maintain the "MFLAG_VIEW" flag).
1771 * Note the special "update_monsters()" function which can be used to
1772 * call this function once for every monster.
1774 * Note the "full" flag which requests that the "cdis" field be updated,
1775 * this is only needed when the monster (or the player) has moved.
1777 * Every time a monster moves, we must call this function for that
1778 * monster, and update the distance, and the visibility. Every time
1779 * the player moves, we must call this function for every monster, and
1780 * update the distance, and the visibility. Whenever the player "state"
1781 * changes in certain ways ("blindness", "infravision", "telepathy",
1782 * and "see invisible"), we must call this function for every monster,
1783 * and update the visibility.
1785 * Routines that change the "illumination" of a grid must also call this
1786 * function for any monster in that grid, since the "visibility" of some
1787 * monsters may be based on the illumination of their grid.
1789 * Note that this function is called once per monster every time the
1790 * player moves. When the player is running, this function is one
1791 * of the primary bottlenecks, along with "update_view()" and the
1792 * "process_monsters()" code, so efficiency is important.
1794 * Note the optimized "inline" version of the "distance()" function.
1796 * A monster is "visible" to the player if (1) it has been detected
1797 * by the player, (2) it is close to the player and the player has
1798 * telepathy, or (3) it is close to the player, and in line of sight
1799 * of the player, and it is "illuminated" by some combination of
1800 * infravision, torch light, or permanent light (invisible monsters
1801 * are only affected by "light" if the player can see invisible).
1803 * Monsters which are not on the current panel may be "visible" to
1804 * the player, and their descriptions will include an "offscreen"
1805 * reference. Currently, offscreen monsters cannot be targetted
1806 * or viewed directly, but old targets will remain set. XXX XXX
1808 * The player can choose to be disturbed by several things, including
1809 * "disturb_move" (monster which is viewable moves in some way), and
1810 * "disturb_near" (monster which is "easily" viewable moves in some
1811 * way). Note that "moves" includes "appears" and "disappears".
1813 void update_monster(MONSTER_IDX m_idx, bool full)
1815 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1816 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1818 bool do_disturb = disturb_move;
1821 POSITION fy = m_ptr->fy;
1822 POSITION fx = m_ptr->fx;
1827 /* Seen by vision */
1830 /* Non-Ninja player in the darkness */
1831 bool in_darkness = (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
1836 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1838 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
1842 /* Compute distance */
1845 /* Distance components */
1846 int dy = (p_ptr->y > fy) ? (p_ptr->y - fy) : (fy - p_ptr->y);
1847 int dx = (p_ptr->x > fx) ? (p_ptr->x - fx) : (fx - p_ptr->x);
1849 /* Approximate distance */
1850 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
1852 /* Restrict distance */
1853 if (d > 255) d = 255;
1857 /* Save the distance */
1861 /* Extract distance */
1864 /* Extract the distance */
1869 if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
1872 if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
1874 if (!in_darkness || (d <= MAX_SIGHT / 4))
1876 if (p_ptr->special_defense & KATA_MUSOU)
1881 if (is_original_ap(m_ptr) && !p_ptr->image)
1883 /* Hack -- Memorize mental flags */
1884 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1885 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1889 /* Basic telepathy */
1890 /* Snipers get telepathy when they concentrate deeper */
1891 else if (p_ptr->telepathy)
1893 /* Empty mind, no telepathy */
1894 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
1896 /* Memorize flags */
1897 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
1900 /* Weird mind, occasional telepathy */
1901 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
1903 /* One in ten individuals are detectable */
1904 if ((m_idx % 10) == 5)
1909 if (is_original_ap(m_ptr) && !p_ptr->image)
1911 /* Memorize flags */
1912 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
1914 /* Hack -- Memorize mental flags */
1915 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1916 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1921 /* Normal mind, allow telepathy */
1927 if (is_original_ap(m_ptr) && !p_ptr->image)
1929 /* Hack -- Memorize mental flags */
1930 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1931 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1936 if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
1939 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
1942 if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
1945 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
1948 if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
1951 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
1954 if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
1957 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
1960 if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
1963 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
1966 if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
1969 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
1972 if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
1975 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
1978 if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
1981 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
1984 if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
1987 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
1990 if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
1993 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
1996 if ((p_ptr->esp_nonliving) &&
1997 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2000 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
2003 if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2006 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
2010 /* Normal line of sight, and not blind */
2011 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
2013 bool do_invisible = FALSE;
2014 bool do_cold_blood = FALSE;
2016 /* Snipers can see targets in darkness when they concentrate deeper */
2017 if (p_ptr->concent >= CONCENT_RADAR_THRESHOLD)
2023 /* Use "infravision" */
2024 if (d <= p_ptr->see_infra)
2026 /* Handle "cold blooded" monsters */
2027 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2029 do_cold_blood = TRUE;
2032 /* Handle "warm blooded" monsters */
2040 /* Use "illumination" */
2041 if (player_can_see_bold(fy, fx))
2043 /* Handle "invisible" monsters */
2044 if (r_ptr->flags2 & (RF2_INVISIBLE))
2046 do_invisible = TRUE;
2056 /* Handle "normal" monsters */
2067 if (is_original_ap(m_ptr) && !p_ptr->image)
2069 /* Memorize flags */
2070 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2071 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2078 /* The monster is now visible */
2081 /* It was previously unseen */
2084 /* Mark as visible */
2087 /* Draw the monster */
2090 /* Update health bar as needed */
2091 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2092 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2094 /* Hack -- Count "fresh" sightings */
2097 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2098 r_info[MON_KAGE].r_sights++;
2099 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
2103 if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
2105 sanity_blast(m_ptr, FALSE);
2108 /* Disturb on appearance */
2109 if (disturb_near && (projectable(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)))
2111 if (disturb_pets || is_hostile(m_ptr))
2112 disturb(TRUE, TRUE);
2117 /* The monster is not visible */
2120 /* It was previously seen */
2123 /* Mark as not visible */
2126 /* Erase the monster */
2129 /* Update health bar as needed */
2130 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2131 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2133 /* Disturb on disappearance */
2136 if (disturb_pets || is_hostile(m_ptr))
2137 disturb(TRUE, TRUE);
2143 /* The monster is now easily visible */
2147 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2149 /* Mark as easily visible */
2150 m_ptr->mflag |= (MFLAG_VIEW);
2152 /* Disturb on appearance */
2155 if (disturb_pets || is_hostile(m_ptr))
2156 disturb(TRUE, TRUE);
2161 /* The monster is not easily visible */
2165 if (m_ptr->mflag & (MFLAG_VIEW))
2167 /* Mark as not easily visible */
2168 m_ptr->mflag &= ~(MFLAG_VIEW);
2170 /* Disturb on disappearance */
2173 if (disturb_pets || is_hostile(m_ptr))
2174 disturb(TRUE, TRUE);
2182 * @brief 単純に生存している全モンスターの更新処理を行う / This function simply updates all the (non-dead) monsters (see above).
2183 * @param full 距離更新を行うならtrue
2186 void update_monsters(bool full)
2190 /* Update each (live) monster */
2191 for (i = 1; i < m_max; i++)
2193 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
2194 if (!monster_is_valid(m_ptr)) continue;
2195 update_monster(i, full);
2201 * @brief カメレオンの王の変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2202 * @param r_idx モンスター種族ID
2203 * @return 対象にできるならtrueを返す
2205 static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
2207 monster_race *r_ptr = &r_info[r_idx];
2208 monster_type *m_ptr = ¤t_floor_ptr->m_list[chameleon_change_m_idx];
2209 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2211 if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2212 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2214 if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2216 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))
2219 if (!monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2222 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2224 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2228 else if (summon_specific_who > 0)
2230 if (monster_has_hostile_align(¤t_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2237 * @brief カメレオンの変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2238 * @param r_idx モンスター種族ID
2239 * @return 対象にできるならtrueを返す
2240 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2242 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
2244 monster_race *r_ptr = &r_info[r_idx];
2245 monster_type *m_ptr = ¤t_floor_ptr->m_list[chameleon_change_m_idx];
2246 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2248 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2249 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2250 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2252 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))
2255 if (!monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2258 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2260 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2261 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2262 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2266 else if (summon_specific_who > 0)
2268 if (monster_has_hostile_align(¤t_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2271 return (*(get_monster_hook()))(r_idx);
2276 * @param m_idx 変身処理を受けるモンスター情報のID
2277 * @param born 生成時の初変身先指定ならばtrue
2278 * @param r_idx 旧モンスター種族のID
2281 void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
2284 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
2285 monster_race *r_ptr;
2286 char old_m_name[MAX_NLEN];
2287 bool old_unique = FALSE;
2288 int old_r_idx = m_ptr->r_idx;
2290 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2292 if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2293 r_ptr = &r_info[r_idx];
2295 monster_desc(old_m_name, m_ptr, 0);
2301 chameleon_change_m_idx = m_idx;
2303 get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2305 get_mon_num_prep(monster_hook_chameleon, NULL);
2308 level = r_info[MON_CHAMELEON_K].level;
2309 else if (!current_floor_ptr->dun_level)
2310 level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2312 level = current_floor_ptr->dun_level;
2314 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2316 r_idx = get_mon_num(level);
2317 r_ptr = &r_info[r_idx];
2319 chameleon_change_m_idx = 0;
2323 m_ptr->r_idx = r_idx;
2324 m_ptr->ap_r_idx = r_idx;
2325 update_monster(m_idx, FALSE);
2326 lite_spot(m_ptr->fy, m_ptr->fx);
2328 if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2329 (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2330 p_ptr->update |= (PU_MON_LITE);
2334 /* Sub-alignment of a chameleon */
2335 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2337 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2338 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2339 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2344 if (m_idx == p_ptr->riding)
2346 GAME_TEXT m_name[MAX_NLEN];
2347 monster_desc(m_name, m_ptr, 0);
2348 msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
2349 if (!(r_ptr->flags7 & RF7_RIDING))
2350 if (rakuba(0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
2353 /* Extract the monster base speed */
2354 m_ptr->mspeed = get_mspeed(r_ptr);
2356 oldmaxhp = m_ptr->max_maxhp;
2357 /* Assign maximal hitpoints */
2358 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2360 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2364 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2367 /* Monsters have double hitpoints in Nightmare mode */
2368 if (ironman_nightmare)
2370 u32b hp = m_ptr->max_maxhp * 2L;
2371 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2374 m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2375 if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2376 m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2378 /* reset dealt_damage */
2379 m_ptr->dealt_damage = 0;
2384 * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
2385 * @param r_idx モンスター種族ID
2386 * @return 対象にできるならtrueを返す
2387 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2389 static bool monster_hook_tanuki(MONRACE_IDX r_idx)
2391 monster_race *r_ptr = &r_info[r_idx];
2393 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2394 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2395 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2396 if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2398 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))
2401 return (*(get_monster_hook()))(r_idx);
2406 * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
2407 * @param r_idx モンスター種族ID
2408 * @return モンスター種族の表層ID
2410 static MONRACE_IDX initial_r_appearance(MONRACE_IDX r_idx, BIT_FLAGS generate_mode)
2412 int attempts = 1000;
2413 MONRACE_IDX ap_r_idx;
2414 DEPTH min = MIN(current_floor_ptr->base_level - 5, 50);
2416 if (p_ptr->pseikaku == SEIKAKU_CHARGEMAN && !(generate_mode & (PM_MULTIPLY | PM_KAGE)))
2418 if (current_floor_ptr->base_level == 0 || one_in_(5)) return MON_ALIEN_JURAL;
2421 if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2424 get_mon_num_prep(monster_hook_tanuki, NULL);
2428 ap_r_idx = get_mon_num(current_floor_ptr->base_level + 10);
2429 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2437 * @brief モンスターの個体加速を設定する / Get initial monster speed
2438 * @param r_ptr モンスター種族の参照ポインタ
2441 SPEED get_mspeed(monster_race *r_ptr)
2443 /* Extract the monster base speed */
2444 SPEED mspeed = r_ptr->speed;
2446 /* Hack -- small racial variety */
2447 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2449 /* Allow some small variation per monster */
2450 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2451 if (i) mspeed += rand_spread(0, i);
2454 if (mspeed > 199) mspeed = 199;
2461 * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
2462 * @param who 召喚を行ったモンスターID
2465 * @param r_idx 生成モンスター種族
2466 * @param mode 生成オプション
2469 * To give the player a sporting chance, any monster that appears in
2470 * line-of-sight and is extremely dangerous can be marked as
2471 * "FORCE_SLEEP", which will cause them to be placed with low energy,
2472 * which often (but not always) lets the player move before they do.
2474 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2476 * Use special "here" and "dead" flags for unique monsters,
2477 * remove old "cur_num" and "max_num" fields.
2479 * Actually, do something similar for artifacts, to simplify
2480 * the "preserve" mode, and to make the "what artifacts" flag more useful.
2482 * This is the only function which may place a monster in the dungeon,
2483 * except for the savefile loading code.
2485 static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2487 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2488 monster_type *m_ptr;
2489 monster_race *r_ptr = &r_info[r_idx];
2490 concptr name = (r_name + r_ptr->name);
2494 /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2495 if (p_ptr->wild_mode) return FALSE;
2497 if (!in_bounds(y, x)) return (FALSE);
2498 if (!r_idx) return (FALSE);
2499 if (!r_ptr->name) return (FALSE);
2501 if (!(mode & PM_IGNORE_TERRAIN))
2503 /* Not on the Pattern */
2504 if (pattern_tile(y, x)) return FALSE;
2506 /* Require empty space (if not ghostly) */
2507 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
2510 if (!p_ptr->inside_battle)
2512 /* Hack -- "unique" monsters must be "unique" */
2513 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2514 (r_ptr->flags7 & (RF7_NAZGUL))) &&
2515 (r_ptr->cur_num >= r_ptr->max_num))
2521 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
2522 (r_ptr->cur_num >= 1))
2527 if (r_idx == MON_BANORLUPART)
2529 if (r_info[MON_BANOR].cur_num > 0) return FALSE;
2530 if (r_info[MON_LUPART].cur_num > 0) return FALSE;
2533 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
2534 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (current_floor_ptr->dun_level < r_ptr->level) &&
2535 (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
2542 if (quest_number(current_floor_ptr->dun_level))
2544 int hoge = quest_number(current_floor_ptr->dun_level);
2545 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
2547 if(r_idx == quest[hoge].r_idx)
2549 int number_mon, i2, j2;
2552 /* Count all quest monsters */
2553 for (i2 = 0; i2 < current_floor_ptr->width; ++i2)
2554 for (j2 = 0; j2 < current_floor_ptr->height; j2++)
2555 if (current_floor_ptr->grid_array[j2][i2].m_idx > 0)
2556 if (current_floor_ptr->m_list[current_floor_ptr->grid_array[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
2558 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
2564 if (is_glyph_grid(g_ptr))
2566 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
2568 /* Describe observable breakage */
2569 if (g_ptr->info & CAVE_MARK)
2571 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2574 /* Forget the rune */
2575 g_ptr->info &= ~(CAVE_MARK);
2577 /* Break the rune */
2578 g_ptr->info &= ~(CAVE_OBJECT);
2586 msg_format_wizard(CHEAT_MONSTER, _("%s(Lv%d)を生成しました。", "%s(Lv%d) was generated."), name, r_ptr->level);
2588 if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
2590 /* Make a new monster */
2591 g_ptr->m_idx = m_pop();
2592 hack_m_idx_ii = g_ptr->m_idx;
2594 /* Mega-Hack -- catch "failure" */
2595 if (!g_ptr->m_idx) return (FALSE);
2598 /* Get a new monster record */
2599 m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
2602 m_ptr->r_idx = r_idx;
2603 m_ptr->ap_r_idx = initial_r_appearance(r_idx, mode);
2609 /* Hack -- Appearance transfer */
2610 if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(¤t_floor_ptr->m_list[who]))
2612 m_ptr->ap_r_idx = current_floor_ptr->m_list[who].ap_r_idx;
2614 /* Hack -- Shadower spawns Shadower */
2615 if (current_floor_ptr->m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
2618 /* Sub-alignment of a monster */
2619 if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
2620 m_ptr->sub_align = current_floor_ptr->m_list[who].sub_align;
2623 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2624 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2625 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2628 /* Place the monster at the location */
2633 /* No "timed status" yet */
2634 for (cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
2636 /* Unknown distance */
2639 reset_target(m_ptr);
2641 m_ptr->nickname = 0;
2646 /* Your pet summons its pet. */
2647 if (who > 0 && is_pet(¤t_floor_ptr->m_list[who]))
2649 mode |= PM_FORCE_PET;
2650 m_ptr->parent_m_idx = who;
2654 m_ptr->parent_m_idx = 0;
2657 if (r_ptr->flags7 & RF7_CHAMELEON)
2659 choose_new_monster(g_ptr->m_idx, TRUE, 0);
2660 r_ptr = &r_info[m_ptr->r_idx];
2661 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
2663 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
2664 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
2665 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2667 else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
2669 m_ptr->ap_r_idx = MON_KAGE;
2670 m_ptr->mflag2 |= MFLAG2_KAGE;
2673 if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
2679 if (mode & PM_FORCE_PET)
2684 else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
2685 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
2687 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
2690 /* Assume no sleeping */
2691 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
2693 /* Enforce sleeping if needed */
2694 if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
2696 int val = r_ptr->sleep;
2697 (void)set_monster_csleep(g_ptr->m_idx, (val * 2) + randint1(val * 10));
2700 /* Assign maximal hitpoints */
2701 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2703 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2707 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2710 /* Monsters have double hitpoints in Nightmare mode */
2711 if (ironman_nightmare)
2713 u32b hp = m_ptr->max_maxhp * 2L;
2715 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2718 m_ptr->maxhp = m_ptr->max_maxhp;
2720 /* And start out fully healthy */
2721 if (m_ptr->r_idx == MON_WOUNDED_BEAR)
2722 m_ptr->hp = m_ptr->maxhp / 2;
2723 else m_ptr->hp = m_ptr->maxhp;
2726 /* dealt damage is 0 at initial*/
2727 m_ptr->dealt_damage = 0;
2730 /* Extract the monster base speed */
2731 m_ptr->mspeed = get_mspeed(r_ptr);
2733 if (mode & PM_HASTE) (void)set_monster_fast(g_ptr->m_idx, 100);
2735 /* Give a random starting energy */
2736 if (!ironman_nightmare)
2738 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
2742 /* Nightmare monsters are more prepared */
2743 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
2746 /* Force monster to wait for player, unless in Nightmare mode */
2747 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
2749 /* Monster is still being nice */
2750 m_ptr->mflag |= (MFLAG_NICE);
2752 /* Must repair monsters */
2753 repair_monsters = TRUE;
2756 /* Hack -- see "process_monsters()" */
2757 if (g_ptr->m_idx < hack_m_idx)
2759 /* Monster is still being born */
2760 m_ptr->mflag |= (MFLAG_BORN);
2764 if (r_ptr->flags7 & RF7_SELF_LD_MASK)
2765 p_ptr->update |= (PU_MON_LITE);
2766 else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
2767 p_ptr->update |= (PU_MON_LITE);
2768 update_monster(g_ptr->m_idx, TRUE);
2771 /* Count the monsters on the level */
2772 real_r_ptr(m_ptr)->cur_num++;
2775 * Memorize location of the unique monster in saved floors.
2776 * A unique monster move from old saved floor.
2778 if (character_dungeon &&
2779 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
2780 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
2782 /* Hack -- Count the number of "reproducers" */
2783 if (r_ptr->flags2 & RF2_MULTIPLY) current_floor_ptr->num_repro++;
2785 /* Hack -- Notice new multi-hued monsters */
2787 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2788 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
2789 shimmer_monsters = TRUE;
2792 if (p_ptr->warning && character_dungeon)
2794 if (r_ptr->flags1 & RF1_UNIQUE)
2798 GAME_TEXT o_name[MAX_NLEN];
2800 if (r_ptr->level > p_ptr->lev + 30)
2801 color = _("黒く", "black");
2802 else if (r_ptr->level > p_ptr->lev + 15)
2803 color = _("紫色に", "purple");
2804 else if (r_ptr->level > p_ptr->lev + 5)
2805 color = _("ルビー色に", "deep red");
2806 else if (r_ptr->level > p_ptr->lev - 5)
2807 color = _("赤く", "red");
2808 else if (r_ptr->level > p_ptr->lev - 15)
2809 color = _("ピンク色に", "pink");
2811 color = _("白く", "white");
2813 o_ptr = choose_warning_item();
2816 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2817 msg_format(_("%sは%s光った。", "%s glows %s."), o_name, color);
2821 msg_format(_("%s光る物が頭に浮かんだ。", "An %s image forms in your mind."), color);
2826 if (is_explosive_rune_grid(g_ptr))
2828 /* Break the ward */
2829 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2831 /* Describe observable breakage */
2832 if (g_ptr->info & CAVE_MARK)
2834 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2835 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);
2840 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2843 /* Forget the rune */
2844 g_ptr->info &= ~(CAVE_MARK);
2846 /* Break the rune */
2847 g_ptr->info &= ~(CAVE_OBJECT);
2860 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
2863 * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster
2864 * @param r_idx 生成モンスター種族
2865 * @param yp 結果生成位置y座標
2866 * @param xp 結果生成位置x座標
2867 * @param y 中心生成位置y座標
2868 * @param x 中心生成位置x座標
2869 * @param max_dist 生成位置の最大半径
2873 static bool mon_scatter(MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
2875 POSITION place_x[MON_SCAT_MAXD];
2876 POSITION place_y[MON_SCAT_MAXD];
2877 int num[MON_SCAT_MAXD];
2881 if (max_dist >= MON_SCAT_MAXD)
2884 for (i = 0; i < MON_SCAT_MAXD; i++)
2887 for (nx = x - max_dist; nx <= x + max_dist; nx++)
2889 for (ny = y - max_dist; ny <= y + max_dist; ny++)
2891 /* Ignore annoying locations */
2892 if (!in_bounds(ny, nx)) continue;
2894 /* Require "line of projection" */
2895 if (!projectable(y, x, ny, nx)) continue;
2899 monster_race *r_ptr = &r_info[r_idx];
2901 /* Require empty space (if not ghostly) */
2902 if (!monster_can_enter(ny, nx, r_ptr, 0))
2907 /* Walls and Monsters block flow */
2908 if (!cave_empty_bold2(ny, nx)) continue;
2910 /* ... nor on the Pattern */
2911 if (pattern_tile(ny, nx)) continue;
2914 i = distance(y, x, ny, nx);
2922 if (one_in_(num[i]))
2931 while (i < MON_SCAT_MAXD && 0 == num[i])
2933 if (i >= MON_SCAT_MAXD)
2943 * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
2944 * @param who 召喚主のモンスター情報ID
2945 * @param y 中心生成位置y座標
2946 * @param x 中心生成位置x座標
2947 * @param r_idx 生成モンスター種族
2948 * @param mode 生成オプション
2951 static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2953 monster_race *r_ptr = &r_info[r_idx];
2956 int total = 0, extra = 0;
2960 POSITION hack_y[GROUP_MAX];
2961 POSITION hack_x[GROUP_MAX];
2964 /* Pick a group size */
2965 total = randint1(10);
2967 /* Hard monsters, small groups */
2968 if (r_ptr->level > current_floor_ptr->dun_level)
2970 extra = r_ptr->level - current_floor_ptr->dun_level;
2971 extra = 0 - randint1(extra);
2974 /* Easy monsters, large groups */
2975 else if (r_ptr->level < current_floor_ptr->dun_level)
2977 extra = current_floor_ptr->dun_level - r_ptr->level;
2978 extra = randint1(extra);
2981 /* Hack -- limit group reduction */
2982 if (extra > 9) extra = 9;
2984 /* Modify the group size */
2988 if (total < 1) total = 1;
2991 if (total > GROUP_MAX) total = GROUP_MAX;
2994 /* Start on the monster */
2999 /* Puddle monsters, breadth first, up to total */
3000 for (n = 0; (n < hack_n) && (hack_n < total); n++)
3002 /* Grab the location */
3003 POSITION hx = hack_x[n];
3004 POSITION hy = hack_y[n];
3006 /* Check each direction, up to total */
3007 for (i = 0; (i < 8) && (hack_n < total); i++)
3011 scatter(&my, &mx, hy, hx, 4, 0);
3013 /* Walls and Monsters block flow */
3014 if (!cave_empty_bold2(my, mx)) continue;
3016 /* Attempt to place another monster */
3017 if (place_monster_one(who, my, mx, r_idx, mode))
3019 /* Add it to the "hack" set */
3020 hack_y[hack_n] = my;
3021 hack_x[hack_n] = mx;
3033 * @var place_monster_idx
3034 * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
3035 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
3037 static MONSTER_IDX place_monster_idx = 0;
3040 * @var place_monster_m_idx
3041 * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
3042 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
3044 static MONSTER_IDX place_monster_m_idx = 0;
3047 * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
3048 * @param r_idx チェックするモンスター種族のID
3049 * @return 護衛にできるならばtrue
3051 static bool place_monster_can_escort(MONRACE_IDX r_idx)
3053 monster_race *r_ptr = &r_info[place_monster_idx];
3054 monster_type *m_ptr = ¤t_floor_ptr->m_list[place_monster_m_idx];
3056 monster_race *z_ptr = &r_info[r_idx];
3058 /* Hack - Escorts have to have the same dungeon flag */
3059 if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return (FALSE);
3061 /* Require similar "race" */
3062 if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3064 /* Skip more advanced monsters */
3065 if (z_ptr->level > r_ptr->level) return (FALSE);
3067 /* Skip unique monsters */
3068 if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3070 /* Paranoia -- Skip identical monsters */
3071 if (place_monster_idx == r_idx) return (FALSE);
3073 /* Skip different alignment */
3074 if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3076 if (r_ptr->flags7 & RF7_FRIENDLY)
3078 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3081 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3089 * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
3090 * @param who 召喚主のモンスター情報ID
3093 * @param r_idx 生成するモンスターの種族ID
3094 * @param mode 生成オプション
3095 * @return 生成に成功したらtrue
3097 * Note that certain monsters are now marked as requiring "friends".
3098 * These monsters, if successfully placed, and if the "grp" parameter
3099 * is TRUE, will be surrounded by a "group" of identical monsters.
3101 * Note that certain monsters are now marked as requiring an "escort",
3102 * which is a collection of monsters with similar "race" but lower level.
3104 * Some monsters induce a fake "group" flag on their escorts.
3106 * Note the "bizarre" use of non-recursion to prevent annoying output
3107 * when running a code profiler.
3109 * Note the use of the new "monster allocation table" code to restrict
3110 * the "get_mon_num()" function to "legal" escort types.
3112 bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
3115 monster_race *r_ptr = &r_info[r_idx];
3117 if (!(mode & PM_NO_KAGE) && one_in_(333))
3120 /* Place one monster, or fail */
3121 if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3123 /* Require the "group" flag */
3124 if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3126 place_monster_m_idx = hack_m_idx_ii;
3129 for(i = 0; i < 6; i++)
3131 if(!r_ptr->reinforce_id[i]) break;
3132 n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
3133 for(j = 0; j < n; j++)
3135 POSITION nx, ny, d = 7;
3136 scatter(&ny, &nx, y, x, d, 0);
3137 (void)place_monster_one(place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
3141 /* Friends for certain monsters */
3142 if (r_ptr->flags1 & (RF1_FRIENDS))
3144 /* Attempt to place a group */
3145 (void)place_monster_group(who, y, x, r_idx, mode);
3148 /* Escorts for certain monsters */
3149 if (r_ptr->flags1 & (RF1_ESCORT))
3151 /* Set the escort index */
3152 place_monster_idx = r_idx;
3154 /* Try to place several "escorts" */
3155 for (i = 0; i < 32; i++)
3157 POSITION nx, ny, d = 3;
3160 /* Pick a location */
3161 scatter(&ny, &nx, y, x, d, 0);
3163 /* Require empty grids */
3164 if (!cave_empty_bold2(ny, nx)) continue;
3165 get_mon_num_prep(place_monster_can_escort, get_monster_hook2(ny, nx));
3167 /* Pick a random race */
3168 z = get_mon_num(r_ptr->level);
3170 /* Handle failure */
3173 /* Place a single escort */
3174 (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3176 /* Place a "group" of escorts if needed */
3177 if ((r_info[z].flags1 & RF1_FRIENDS) ||
3178 (r_ptr->flags1 & RF1_ESCORTS))
3180 /* Place a group of monsters */
3181 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3191 * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
3194 * @param mode 生成オプション
3195 * @return 生成に成功したらtrue
3197 bool place_monster(POSITION y, POSITION x, BIT_FLAGS mode)
3200 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3202 /* Pick a monster */
3203 r_idx = get_mon_num(current_floor_ptr->monster_level);
3205 /* Handle failure */
3206 if (!r_idx) return (FALSE);
3208 /* Attempt to place the monster */
3209 if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3215 * @brief 指定地点に1種類のモンスター種族による群れを生成する
3218 * @return 生成に成功したらtrue
3220 bool alloc_horde(POSITION y, POSITION x)
3222 monster_race *r_ptr = NULL;
3223 MONRACE_IDX r_idx = 0;
3225 int attempts = 1000;
3228 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3232 /* Pick a monster */
3233 r_idx = get_mon_num(current_floor_ptr->monster_level);
3235 /* Handle failure */
3236 if (!r_idx) return (FALSE);
3238 r_ptr = &r_info[r_idx];
3240 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3242 if (r_idx == MON_HAGURE) continue;
3245 if (attempts < 1) return FALSE;
3251 /* Attempt to place the monster */
3252 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3255 if (attempts < 1) return FALSE;
3257 m_idx = current_floor_ptr->grid_array[y][x].m_idx;
3259 if (current_floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[current_floor_ptr->m_list[m_idx].r_idx];
3261 for (attempts = randint1(10) + 5; attempts; attempts--)
3263 scatter(&cy, &cx, y, x, 5, 0);
3265 (void)summon_specific(m_idx, cy, cx, current_floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP, r_ptr->d_char);
3271 if (cheat_hear) msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), r_ptr->d_char);
3276 * @brief ダンジョンの主生成を試みる / Put the Guardian
3277 * @param def_val 現在の主の生成状態
3278 * @return 生成に成功したらtrue
3280 bool alloc_guardian(bool def_val)
3282 MONRACE_IDX guardian = d_info[p_ptr->dungeon_idx].final_guardian;
3284 if (guardian && (d_info[p_ptr->dungeon_idx].maxdepth == current_floor_ptr->dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3288 int try_count = 4000;
3290 /* Find a good position */
3293 /* Get a random spot */
3294 oy = randint1(current_floor_ptr->height - 4) + 2;
3295 ox = randint1(current_floor_ptr->width - 4) + 2;
3297 /* Is it a good spot ? */
3298 if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(current_floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0))
3300 /* Place the guardian */
3301 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3304 /* One less try count */
3316 * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
3317 * @param dis プレイヤーから離れるべき最低距離
3318 * @param mode 生成オプション
3319 * @return 生成に成功したらtrue
3321 * Place the monster at least "dis" distance from the player.
3322 * Use "slp" to choose the initial "sleep" status
3323 * Use "current_floor_ptr->monster_level" for the monster level
3325 bool alloc_monster(POSITION dis, BIT_FLAGS mode)
3327 POSITION y = 0, x = 0;
3328 int attempts_left = 10000;
3330 /* Put the Guardian */
3331 if (alloc_guardian(FALSE)) return TRUE;
3333 /* Find a legal, distant, unoccupied, space */
3334 while (attempts_left--)
3336 /* Pick a location */
3337 y = randint0(current_floor_ptr->height);
3338 x = randint0(current_floor_ptr->width);
3340 /* Require empty floor grid (was "naked") */
3341 if (current_floor_ptr->dun_level)
3343 if (!cave_empty_bold2(y, x)) continue;
3347 if (!cave_empty_bold(y, x)) continue;
3350 /* Accept far away grids */
3351 if (distance(y, x, p_ptr->y, p_ptr->x) > dis) break;
3356 if (cheat_xtra || cheat_hear)
3358 msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
3365 if (randint1(5000) <= current_floor_ptr->dun_level)
3367 if (alloc_horde(y, x))
3374 /* Attempt to place the monster, allow groups */
3375 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3383 * @brief モンスターが召喚の基本条件に合っているかをチェックする / Hack -- help decide if a monster race is "okay" to summon
3384 * @param r_idx チェックするモンスター種族ID
3385 * @return 召喚対象にできるならばTRUE
3387 static bool summon_specific_okay(MONRACE_IDX r_idx)
3389 monster_race *r_ptr = &r_info[r_idx];
3391 /* Hack - Only summon dungeon monsters */
3392 if (!mon_hook_dungeon(r_idx)) return (FALSE);
3394 /* Hack -- identify the summoning monster */
3395 if (summon_specific_who > 0)
3397 monster_type *m_ptr = ¤t_floor_ptr->m_list[summon_specific_who];
3399 /* Do not summon enemies */
3401 /* Friendly vs. opposite aligned normal or pet */
3402 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3404 /* Use the player's alignment */
3405 else if (summon_specific_who < 0)
3407 /* Do not summon enemies of the pets */
3408 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3410 if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3414 if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
3416 /* Hack -- no specific type specified */
3417 if (!summon_specific_type) return (TRUE);
3419 if ((summon_specific_who < 0) &&
3420 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
3421 monster_has_hostile_align(NULL, 10, -10, r_ptr))
3424 if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON)) return TRUE;
3426 return (summon_specific_aux(r_idx));
3431 * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
3432 * @param who 召喚主のモンスター情報ID
3437 * @param mode 生成オプション
3438 * @return 召喚できたらtrueを返す
3441 * We will attempt to place the monster up to 10 times before giving up.
3443 * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3444 * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3445 * Note: None of the other summon codes will ever summon Unique's.
3447 * This function has been changed. We now take the "monster level"
3448 * of the summoning monster as a parameter, and use that, along with
3449 * the current dungeon level, to help determine the level of the
3450 * desired monster. Note that this is an upper bound, and also
3451 * tends to "prefer" monsters of that level. Currently, we use
3452 * the average of the dungeon and monster levels, and then add
3453 * five to allow slight increases in monster power.
3455 * Note that we use the new "monster allocation table" creation code
3456 * to restrict the "get_mon_num()" function to the set of "legal"
3457 * monsters, making this function much faster and more reliable.
3459 * Note that this function may not succeed, though this is very rare.
3461 bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode, SYMBOL_CODE symbol)
3466 if (p_ptr->inside_arena) return (FALSE);
3468 if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
3470 /* Save the summoner */
3471 summon_specific_who = who;
3473 /* Save the "summon" type */
3474 summon_specific_type = type;
3476 summon_kin_type = symbol;
3478 summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
3479 get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
3481 /* Pick a monster, using the level calculation */
3482 r_idx = get_mon_num((current_floor_ptr->dun_level + lev) / 2 + 5);
3484 /* Handle failure */
3487 summon_specific_type = 0;
3491 if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
3493 /* Attempt to place the monster (awake, allow groups) */
3494 if (!place_monster_aux(who, y, x, r_idx, mode))
3496 summon_specific_type = 0;
3500 summon_specific_type = 0;
3502 sound(SOUND_SUMMON);
3508 * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
3509 * @param who 召喚主のモンスター情報ID
3512 * @param r_idx 生成するモンスター種族ID
3513 * @param mode 生成オプション
3514 * @return 召喚できたらtrueを返す
3516 bool summon_named_creature(MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
3519 /* if (!r_idx) return; */
3521 /* Prevent illegal monsters */
3522 if (r_idx >= max_r_idx) return FALSE;
3524 if (p_ptr->inside_arena) return FALSE;
3526 if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
3528 /* Place it (allow groups) */
3529 return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
3534 * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
3535 * @param m_idx 増殖するモンスター情報ID
3536 * @param clone クローン・モンスター処理ならばtrue
3537 * @param mode 生成オプション
3538 * @return 生成できたらtrueを返す
3540 * Note that "reproduction" REQUIRES empty space.
3542 bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
3544 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
3547 if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
3550 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
3552 /* Create a new monster (awake, no groups) */
3553 if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
3556 /* Hack -- Transfer "clone" flag */
3557 if (clone || (m_ptr->smart & SM_CLONED))
3559 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3560 current_floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
3569 * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
3570 * @param m_idx モンスター情報ID
3571 * @param dam 与えたダメージ
3574 * Technically should attempt to treat "Beholder"'s as jelly's
3576 void message_pain(MONSTER_IDX m_idx, HIT_POINT dam)
3578 HIT_POINT oldhp, newhp;
3580 PERCENTAGE percentage;
3582 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
3583 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3585 GAME_TEXT m_name[MAX_NLEN];
3587 monster_desc(m_name, m_ptr, 0);
3589 if(dam == 0) // Notice non-damage
3591 msg_format(_("%^sはダメージを受けていない。", "%^s is unharmed."), m_name);
3595 /* Note -- subtle fix -CFT */
3597 oldhp = newhp + dam;
3598 tmp = (newhp * 100L) / oldhp;
3601 if(my_strchr(",ejmvwQ", r_ptr->d_char)) // Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs
3604 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3605 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
3606 else if(percentage > 50) msg_format("%^sは縮こまった。", m_name);
3607 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3608 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
3609 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3610 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3612 if(percentage > 95) msg_format("%^s barely notices.", m_name);
3613 else if(percentage > 75) msg_format("%^s flinches.", m_name);
3614 else if(percentage > 50) msg_format("%^s squelches.", m_name);
3615 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
3616 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
3617 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3618 else msg_format("%^s jerks limply.", m_name);
3622 else if(my_strchr("l", r_ptr->d_char)) // Fish
3625 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3626 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
3627 else if(percentage > 50) msg_format("%^sは躊躇した。", m_name);
3628 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3629 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
3630 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3631 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3633 if(percentage > 95) msg_format("%^s barely notices.", m_name);
3634 else if(percentage > 75) msg_format("%^s flinches.", m_name);
3635 else if(percentage > 50) msg_format("%^s hesitates.", m_name);
3636 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
3637 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
3638 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3639 else msg_format("%^s jerks limply.", m_name);
3643 else if(my_strchr("g#+<>", r_ptr->d_char)) // Golems, Walls, Doors, Stairs
3646 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3647 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3648 else if(percentage > 50) msg_format("%^sは雷鳴のように吠えた。", m_name);
3649 else if(percentage > 35) msg_format("%^sは苦しげに吠えた。", m_name);
3650 else if(percentage > 20) msg_format("%^sはうめいた。", m_name);
3651 else if(percentage > 10) msg_format("%^sは躊躇した。", m_name);
3652 else msg_format("%^sはくしゃくしゃになった。", m_name);
3654 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3655 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3656 else if(percentage > 50) msg_format("%^s roars thunderously.", m_name);
3657 else if(percentage > 35) msg_format("%^s rumbles.", m_name);
3658 else if(percentage > 20) msg_format("%^s grunts.", m_name);
3659 else if(percentage > 10) msg_format("%^s hesitates.", m_name);
3660 else msg_format("%^s crumples.", m_name);
3664 else if(my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) // Snakes, Hydrae, Reptiles, Mimics
3667 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3668 else if(percentage > 75) msg_format("%^sはシーッと鳴いた。", m_name);
3669 else if(percentage > 50) msg_format("%^sは怒って頭を上げた。", m_name);
3670 else if(percentage > 35) msg_format("%^sは猛然と威嚇した。", m_name);
3671 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
3672 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3673 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3675 if(percentage > 95) msg_format("%^s barely notices.", m_name);
3676 else if(percentage > 75) msg_format("%^s hisses.", m_name);
3677 else if(percentage > 50) msg_format("%^s rears up in anger.", m_name);
3678 else if(percentage > 35) msg_format("%^s hisses furiously.", m_name);
3679 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
3680 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3681 else msg_format("%^s jerks limply.", m_name);
3685 else if(my_strchr("f", r_ptr->d_char))
3688 if(percentage > 95) msg_format("%sは攻撃に肩をすくめた。", m_name);
3689 else if(percentage > 75) msg_format("%^sは吠えた。", m_name);
3690 else if(percentage > 50) msg_format("%^sは怒って吠えた。", m_name);
3691 else if(percentage > 35) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3692 else if(percentage > 20) msg_format("%^sは痛みで弱々しく鳴いた。", m_name);
3693 else if(percentage > 10) msg_format("%^sは苦痛にうめいた。", m_name);
3694 else msg_format("%sは哀れな鳴き声を出した。", m_name);
3696 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3697 else if(percentage > 75) msg_format("%^s roars.", m_name);
3698 else if(percentage > 50) msg_format("%^s growls angrily.", m_name);
3699 else if(percentage > 35) msg_format("%^s hisses with pain.", m_name);
3700 else if(percentage > 20) msg_format("%^s mewls in pain.", m_name);
3701 else if(percentage > 10) msg_format("%^s hisses in agony.", m_name);
3702 else msg_format("%^s mewls pitifully.", m_name);
3706 else if(my_strchr("acFIKS", r_ptr->d_char)) // Ants, Centipedes, Flies, Insects, Beetles, Spiders
3709 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3710 else if(percentage > 75) msg_format("%^sはキーキー鳴いた。", m_name);
3711 else if(percentage > 50) msg_format("%^sはヨロヨロ逃げ回った。", m_name);
3712 else if(percentage > 35) msg_format("%^sはうるさく鳴いた。", m_name);
3713 else if(percentage > 20) msg_format("%^sは痛みに痙攣した。", m_name);
3714 else if(percentage > 10) msg_format("%^sは苦痛で痙攣した。", m_name);
3715 else msg_format("%^sはピクピクひきつった。", m_name);
3717 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3718 else if(percentage > 75) msg_format("%^s chitters.", m_name);
3719 else if(percentage > 50) msg_format("%^s scuttles about.", m_name);
3720 else if(percentage > 35) msg_format("%^s twitters.", m_name);
3721 else if(percentage > 20) msg_format("%^s jerks in pain.", m_name);
3722 else if(percentage > 10) msg_format("%^s jerks in agony.", m_name);
3723 else msg_format("%^s twitches.", m_name);
3727 else if(my_strchr("B", r_ptr->d_char)) // Birds
3730 if(percentage > 95) msg_format("%^sはさえずった。", m_name);
3731 else if(percentage > 75) msg_format("%^sはピーピー鳴いた。", m_name);
3732 else if(percentage > 50) msg_format("%^sはギャーギャー鳴いた。", m_name);
3733 else if(percentage > 35) msg_format("%^sはギャーギャー鳴きわめいた。", m_name);
3734 else if(percentage > 20) msg_format("%^sは苦しんだ。", m_name);
3735 else if(percentage > 10) msg_format("%^sはのたうち回った。", m_name);
3736 else msg_format("%^sはキーキーと鳴き叫んだ。", m_name);
3738 if(percentage > 95) msg_format("%^s chirps.", m_name);
3739 else if(percentage > 75) msg_format("%^s twitters.", m_name);
3740 else if(percentage > 50) msg_format("%^s squawks.", m_name);
3741 else if(percentage > 35) msg_format("%^s chatters.", m_name);
3742 else if(percentage > 20) msg_format("%^s jeers.", m_name);
3743 else if(percentage > 10) msg_format("%^s flutters about.", m_name);
3744 else msg_format("%^s squeaks.", m_name);
3748 else if(my_strchr("duDLUW", r_ptr->d_char)) // Dragons, Demons, High Undead
3751 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3752 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
3753 else if(percentage > 50) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3754 else if(percentage > 35) msg_format("%^sは痛みでうなった。", m_name);
3755 else if(percentage > 20) msg_format("%^sは痛みに吠えた。", m_name);
3756 else if(percentage > 10) msg_format("%^sは苦しげに叫んだ。", m_name);
3757 else msg_format("%^sは弱々しくうなった。", m_name);
3759 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3760 else if(percentage > 75) msg_format("%^s flinches.", m_name);
3761 else if(percentage > 50) msg_format("%^s hisses in pain.", m_name);
3762 else if(percentage > 35) msg_format("%^s snarls with pain.", m_name);
3763 else if(percentage > 20) msg_format("%^s roars with pain.", m_name);
3764 else if(percentage > 10) msg_format("%^s gasps.", m_name);
3765 else msg_format("%^s snarls feebly.", m_name);
3769 else if(my_strchr("s", r_ptr->d_char)) // Skeletons
3772 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3773 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3774 else if(percentage > 50) msg_format("%^sはカタカタと笑った。", m_name);
3775 else if(percentage > 35) msg_format("%^sはよろめいた。", m_name);
3776 else if(percentage > 20) msg_format("%^sはカタカタ言った。", m_name);
3777 else if(percentage > 10) msg_format("%^sはよろめいた。", m_name);
3778 else msg_format("%^sはガタガタ言った。", m_name);
3780 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3781 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3782 else if(percentage > 50) msg_format("%^s rattles.", m_name);
3783 else if(percentage > 35) msg_format("%^s stumbles.", m_name);
3784 else if(percentage > 20) msg_format("%^s rattles.", m_name);
3785 else if(percentage > 10) msg_format("%^s staggers.", m_name);
3786 else msg_format("%^s clatters.", m_name);
3790 else if(my_strchr("z", r_ptr->d_char)) // Zombies
3793 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3794 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3795 else if(percentage > 50) msg_format("%^sはうめいた。", m_name);
3796 else if(percentage > 35) msg_format("%sは苦しげにうめいた。", m_name);
3797 else if(percentage > 20) msg_format("%^sは躊躇した。", m_name);
3798 else if(percentage > 10) msg_format("%^sはうなった。", m_name);
3799 else msg_format("%^sはよろめいた。", m_name);
3801 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3802 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3803 else if(percentage > 50) msg_format("%^s groans.", m_name);
3804 else if(percentage > 35) msg_format("%^s moans.", m_name);
3805 else if(percentage > 20) msg_format("%^s hesitates.", m_name);
3806 else if(percentage > 10) msg_format("%^s grunts.", m_name);
3807 else msg_format("%^s staggers.", m_name);
3811 else if(my_strchr("G", r_ptr->d_char)) // Ghosts
3814 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3815 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3816 else if(percentage > 50) msg_format("%sはうめいた。", m_name);
3817 else if(percentage > 35) msg_format("%^sは泣きわめいた。", m_name);
3818 else if(percentage > 20) msg_format("%^sは吠えた。", m_name);
3819 else if(percentage > 10) msg_format("%sは弱々しくうめいた。", m_name);
3820 else msg_format("%^sはかすかにうめいた。", m_name);
3822 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3823 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3824 else if(percentage > 50) msg_format("%^s moans.", m_name);
3825 else if(percentage > 35) msg_format("%^s wails.", m_name);
3826 else if(percentage > 20) msg_format("%^s howls.", m_name);
3827 else if(percentage > 10) msg_format("%^s moans softly.", m_name);
3828 else msg_format("%^s sighs.", m_name);
3832 else if(my_strchr("CZ", r_ptr->d_char)) // Dogs and Hounds
3835 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3836 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3837 else if(percentage > 50) msg_format("%^sは痛みでキャンキャン吠えた。", m_name);
3838 else if(percentage > 35) msg_format("%^sは痛みで鳴きわめいた。", m_name);
3839 else if(percentage > 20) msg_format("%^sは苦痛のあまり鳴きわめいた。", m_name);
3840 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3841 else msg_format("%^sは弱々しく吠えた。", m_name);
3843 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3844 else if(percentage > 75) msg_format("%^s snarls with pain.", m_name);
3845 else if(percentage > 50) msg_format("%^s yelps in pain.", m_name);
3846 else if(percentage > 35) msg_format("%^s howls in pain.", m_name);
3847 else if(percentage > 20) msg_format("%^s howls in agony.", m_name);
3848 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3849 else msg_format("%^s yelps feebly.", m_name);
3853 else if(my_strchr("Xbilqrt", r_ptr->d_char)) // One type of creatures (ignore,squeal,shriek)
3856 if(percentage > 95) msg_format("%^sは攻撃を気にとめていない。", m_name);
3857 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3858 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3859 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3860 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3861 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3862 else msg_format("%^sは弱々しく叫んだ。", m_name);
3864 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3865 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
3866 else if(percentage > 50) msg_format("%^s squeals in pain.", m_name);
3867 else if(percentage > 35) msg_format("%^s shrieks in pain.", m_name);
3868 else if(percentage > 20) msg_format("%^s shrieks in agony.", m_name);
3869 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3870 else msg_format("%^s cries out feebly.", m_name);
3874 else // Another type of creatures (shrug,cry,scream)
3877 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3878 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3879 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3880 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3881 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3882 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3883 else msg_format("%^sは弱々しく叫んだ。", m_name);
3885 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3886 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
3887 else if(percentage > 50) msg_format("%^s cries out in pain.", m_name);
3888 else if(percentage > 35) msg_format("%^s screams in pain.", m_name);
3889 else if(percentage > 20) msg_format("%^s screams in agony.", m_name);
3890 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3891 else msg_format("%^s cries out feebly.", m_name);
3899 * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance.
3900 * @param m_idx 更新を行う「モンスター情報ID
3901 * @param what 学習対象ID
3904 void update_smart_learn(MONSTER_IDX m_idx, int what)
3906 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
3907 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3909 /* Not allowed to learn */
3910 if (!smart_learn) return;
3912 /* Too stupid to learn anything */
3913 if (r_ptr->flags2 & (RF2_STUPID)) return;
3915 /* Not intelligent, only learn sometimes */
3916 if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
3918 /* Analyze the knowledge */
3922 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
3923 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
3924 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
3928 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
3929 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
3930 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
3934 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
3935 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
3936 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
3940 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
3941 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
3942 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
3946 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
3947 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
3952 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
3956 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
3960 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
3964 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
3968 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
3972 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
3976 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
3980 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
3984 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
3988 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
3992 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
3996 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4000 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4004 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
4011 * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster
4012 * @param m_ptr モンスター参照ポインタ
4015 void monster_drop_carried_objects(monster_type *m_ptr)
4017 OBJECT_IDX this_o_idx, next_o_idx = 0;
4023 /* Drop objects being carried */
4024 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4026 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
4027 next_o_idx = o_ptr->next_o_idx;
4030 object_copy(q_ptr, o_ptr);
4032 /* Forget monster */
4033 q_ptr->held_m_idx = 0;
4035 delete_object_idx(this_o_idx);
4038 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4041 /* Forget objects */
4042 m_ptr->hold_o_idx = 0;
4046 * @brief 指定したモンスターに隣接しているモンスターの数を返す。
4047 * / Count number of adjacent monsters
4048 * @param m_idx 隣接数を調べたいモンスターのID
4049 * @return 隣接しているモンスターの数
4051 int get_monster_crowd_number(MONSTER_IDX m_idx)
4053 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
4054 POSITION my = m_ptr->fy;
4055 POSITION mx = m_ptr->fx;
4059 for (i = 0; i < 7; i++)
4061 int ay = my + ddy_ddd[i];
4062 int ax = mx + ddx_ddd[i];
4064 if (!in_bounds(ay, ax)) continue;
4066 /* Count number of monsters */
4067 if (current_floor_ptr->grid_array[ay][ax].m_idx > 0) count++;