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.
15 #include "monsterrace-hook.h"
16 #include "monster-status.h"
17 #include "projection.h"
19 #include "spells-summon.h"
22 #include "player-move.h"
25 #include "player-status.h"
26 #include "monster-spell.h"
28 #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */
29 #define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */
33 * @brief モンスターの目標地点をセットする / Set the target of counter attack
34 * @param m_ptr モンスターの参照ポインタ
39 void set_target(monster_type *m_ptr, POSITION y, POSITION x)
47 * @brief モンスターの目標地点をリセットする / Reset the target of counter attack
48 * @param m_ptr モンスターの参照ポインタ
51 void reset_target(monster_type *m_ptr)
53 set_target(m_ptr, 0, 0);
58 * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form
59 * @param m_ptr モンスターの参照ポインタ
60 * @return 本当のモンスター種族参照ポインタ
62 monster_race *real_r_ptr(monster_type *m_ptr)
64 return &r_info[real_r_idx(m_ptr)];
67 MONRACE_IDX real_r_idx(monster_type *m_ptr)
69 monster_race *r_ptr = &r_info[m_ptr->r_idx];
71 /* Extract real race */
72 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
74 if (r_ptr->flags1 & RF1_UNIQUE)
75 return MON_CHAMELEON_K;
87 * @brief モンスター配列からモンスターを消去する / Delete a monster by index.
88 * @param i 消去するモンスターのID
91 * モンスターを削除するとそのモンスターが拾っていたアイテムも同時に削除される。 /
92 * When a monster is deleted, all of its objects are deleted.
94 void delete_monster_idx(MONSTER_IDX i)
97 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
98 monster_race *r_ptr = &r_info[m_ptr->r_idx];
99 OBJECT_IDX this_o_idx, next_o_idx = 0;
104 /* Hack -- Reduce the racial counter */
105 real_r_ptr(m_ptr)->cur_num--;
107 /* Hack -- count the number of "reproducers" */
108 if (r_ptr->flags2 & (RF2_MULTIPLY)) current_floor_ptr->num_repro--;
110 if (MON_CSLEEP(m_ptr)) (void)set_monster_csleep(i, 0);
111 if (MON_FAST(m_ptr)) (void)set_monster_fast(i, 0);
112 if (MON_SLOW(m_ptr)) (void)set_monster_slow(i, 0);
113 if (MON_STUNNED(m_ptr)) (void)set_monster_stunned(i, 0);
114 if (MON_CONFUSED(m_ptr)) (void)set_monster_confused(i, 0);
115 if (MON_MONFEAR(m_ptr)) (void)set_monster_monfear(i, 0);
116 if (MON_INVULNER(m_ptr)) (void)set_monster_invulner(i, 0, FALSE);
118 /* Hack -- remove target monster */
119 if (i == target_who) target_who = 0;
121 /* Hack -- remove tracked monster */
122 if (i == p_ptr->health_who) health_track(0);
124 if (pet_t_m_idx == i ) pet_t_m_idx = 0;
125 if (riding_t_m_idx == i) riding_t_m_idx = 0;
126 if (p_ptr->riding == i) p_ptr->riding = 0;
128 /* Monster is gone */
129 current_floor_ptr->grid_array[y][x].m_idx = 0;
131 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
134 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
135 next_o_idx = o_ptr->next_o_idx;
138 * o_ptr->held_m_idx is needed in delete_object_idx()
139 * to prevent calling lite_spot()
142 delete_object_idx(this_o_idx);
145 (void)WIPE(m_ptr, monster_type);
151 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
153 p_ptr->update |= (PU_MON_LITE);
159 * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
164 void delete_monster(POSITION y, POSITION x)
167 if (!in_bounds(y, x)) return;
170 g_ptr = ¤t_floor_ptr->grid_array[y][x];
172 /* Delete the monster (if any) */
173 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
178 * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
183 static void compact_monsters_aux(MONSTER_IDX i1, MONSTER_IDX i2)
189 OBJECT_IDX this_o_idx, next_o_idx = 0;
192 if (i1 == i2) return;
195 m_ptr = ¤t_floor_ptr->m_list[i1];
201 g_ptr = ¤t_floor_ptr->grid_array[y][x];
203 /* Update the current_floor_ptr->grid_array */
206 /* Repair objects being carried by monster */
207 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
210 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
211 next_o_idx = o_ptr->next_o_idx;
213 /* Reset monster pointer */
214 o_ptr->held_m_idx = i2;
217 /* Hack -- Update the target */
218 if (target_who == i1) target_who = i2;
220 /* Hack -- Update the target */
221 if (pet_t_m_idx == i1) pet_t_m_idx = i2;
222 if (riding_t_m_idx == i1) riding_t_m_idx = i2;
224 /* Hack -- Update the riding */
225 if (p_ptr->riding == i1) p_ptr->riding = i2;
227 /* Hack -- Update the health bar */
228 if (p_ptr->health_who == i1) health_track(i2);
230 /* Hack -- Update parent index */
233 for (i = 1; i < m_max; i++)
235 monster_type *m2_ptr = ¤t_floor_ptr->m_list[i];
237 if (m2_ptr->parent_m_idx == i1)
238 m2_ptr->parent_m_idx = i2;
243 (void)COPY(¤t_floor_ptr->m_list[i2], ¤t_floor_ptr->m_list[i1], monster_type);
246 (void)WIPE(¤t_floor_ptr->m_list[i1], monster_type);
248 for (i = 0; i < MAX_MTIMED; i++)
250 int mproc_idx = get_mproc_idx(i1, i);
251 if (mproc_idx >= 0) current_floor_ptr->mproc_list[i][mproc_idx] = i2;
257 * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
258 * @param size 圧縮後のモンスター件数目標
261 * This function can be very dangerous, use with caution!
263 * When actually "compacting" monsters, we base the saving throw
264 * on a combination of monster level, distance from player, and
265 * current "desperation".
267 * After "compacting" (if needed), we "reorder" the monsters into a more
268 * compact order, and we reset the allocation info, and the "live" array.
270 void compact_monsters(int size)
274 int cur_lev, cur_dis, chance;
276 /* Message (only if compacting) */
277 if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
280 /* Compact at least 'size' objects */
281 for (num = 0, cnt = 1; num < size; cnt++)
283 /* Get more vicious each iteration */
286 /* Get closer each iteration */
287 cur_dis = 5 * (20 - cnt);
289 /* Check all the monsters */
290 for (i = 1; i < m_max; i++)
292 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
294 monster_race *r_ptr = &r_info[m_ptr->r_idx];
296 /* Paranoia -- skip "dead" monsters */
297 if (!monster_is_valid(m_ptr)) continue;
299 /* Hack -- High level monsters start out "immune" */
300 if (r_ptr->level > cur_lev) continue;
302 if (i == p_ptr->riding) continue;
304 /* Ignore nearby monsters */
305 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
307 /* Saving throw chance */
310 /* Only compact "Quest" Monsters in emergencies */
311 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
313 /* Try not to compact Unique Monsters */
314 if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
316 /* All monsters get a saving throw */
317 if (randint0(100) < chance) continue;
319 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
321 GAME_TEXT m_name[MAX_NLEN];
322 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
323 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
326 delete_monster_idx(i);
328 /* Count the monster */
334 /* Excise dead monsters (backwards!) */
335 for (i = m_max - 1; i >= 1; i--)
337 /* Get the i'th monster */
338 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
340 /* Skip real monsters */
341 if (m_ptr->r_idx) continue;
343 /* Move last monster into open hole */
344 compact_monsters_aux(m_max - 1, i);
346 /* Compress "m_max" */
353 * @brief プレイヤーのフロア離脱に伴う全モンスター配列の消去 / Delete/Remove all the monsters when the player leaves the level
356 * This is an efficient method of simulating multiple calls to the
357 * "delete_monster()" function, with no visual effects.
359 void wipe_m_list(void)
363 /* Hack -- if Banor or Lupart dies, stay another dead */
364 if (!r_info[MON_BANORLUPART].max_num)
366 if (r_info[MON_BANOR].max_num)
368 r_info[MON_BANOR].max_num = 0;
369 r_info[MON_BANOR].r_pkills++;
370 r_info[MON_BANOR].r_akills++;
371 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
373 if (r_info[MON_LUPART].max_num)
375 r_info[MON_LUPART].max_num = 0;
376 r_info[MON_LUPART].r_pkills++;
377 r_info[MON_LUPART].r_akills++;
378 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
382 /* Delete all the monsters */
383 for (i = m_max - 1; i >= 1; i--)
385 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
386 if (!monster_is_valid(m_ptr)) continue;
388 /* Monster is gone */
389 current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx = 0;
391 (void)WIPE(m_ptr, monster_type);
396 * Wiping racial counters of all monsters and incrementing of racial
397 * counters of monsters in party_mon[] are required to prevent multiple
398 * generation of unique monster who is the minion of player.
401 /* Hack -- Wipe the racial counter of all monster races */
402 for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
410 /* Reset "current_floor_ptr->mproc_max[]" */
411 for (i = 0; i < MAX_MTIMED; i++) current_floor_ptr->mproc_max[i] = 0;
413 /* Hack -- reset "reproducer" count */
414 current_floor_ptr->num_repro = 0;
416 /* Hack -- no more target */
421 /* Hack -- no more tracking */
427 * @brief モンスター配列の空きを探す / Acquires and returns the index of a "free" monster.
428 * @return 利用可能なモンスター配列の添字
430 * This routine should almost never fail, but it *can* happen.
432 MONSTER_IDX m_pop(void)
436 /* Normal allocation */
437 if (m_max < current_floor_ptr->max_m_idx)
439 /* Access the next hole */
442 /* Expand the array */
448 /* Return the index */
452 /* Recycle dead monsters */
453 for (i = 1; i < m_max; i++)
457 /* Acquire monster */
458 m_ptr = ¤t_floor_ptr->m_list[i];
460 /* Skip live monsters */
461 if (m_ptr->r_idx) continue;
466 /* Use this monster */
470 /* Warn the player (except during dungeon creation) */
471 if (character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
473 /* Try not to crash */
481 * @var summon_specific_type
482 * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
483 * @todo summon_specific_typeグローバル変数の除去と関数引数への代替を行う
485 static int summon_specific_type = 0;
489 * @var summon_specific_who
490 * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
491 * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
493 static int summon_specific_who = -1;
496 * @var summon_unique_okay
497 * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
498 * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
500 static bool summon_unique_okay = FALSE;
503 * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
504 * @return 召喚条件が一致するならtrue
507 static bool summon_specific_aux(MONRACE_IDX r_idx)
509 monster_race *r_ptr = &r_info[r_idx];
512 /* Check our requirements */
513 switch (summon_specific_type)
517 okay = (r_ptr->d_char == 'a');
523 okay = (r_ptr->d_char == 'S');
529 okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
535 okay = (r_ptr->d_char == 'M');
541 okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
547 okay = (r_ptr->flags3 & RF3_DEMON);
553 okay = (r_ptr->flags3 & RF3_UNDEAD);
559 okay = (r_ptr->flags3 & RF3_DRAGON);
563 case SUMMON_HI_UNDEAD:
565 okay = ((r_ptr->d_char == 'L') ||
566 (r_ptr->d_char == 'V') ||
567 (r_ptr->d_char == 'W'));
571 case SUMMON_HI_DRAGON:
573 okay = (r_ptr->d_char == 'D');
577 case SUMMON_HI_DEMON:
579 okay = (((r_ptr->d_char == 'U') ||
580 (r_ptr->d_char == 'H') ||
581 (r_ptr->d_char == 'B')) &&
582 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
586 case SUMMON_AMBERITES:
588 okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
594 okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
600 okay = (r_ptr->d_char == 'm');
605 okay = (r_ptr->d_char == 'b');
608 case SUMMON_QUYLTHULG:
610 okay = (r_ptr->d_char == 'Q');
614 case SUMMON_COIN_MIMIC:
616 okay = (r_ptr->d_char == '$');
622 okay = ((r_ptr->d_char == '!') ||
623 (r_ptr->d_char == '?') ||
624 (r_ptr->d_char == '=') ||
625 (r_ptr->d_char == '$') ||
626 (r_ptr->d_char == '|'));
632 okay = (r_ptr->d_char == 'g');
638 okay = ((r_ptr->d_char == 'U') &&
639 (r_ptr->flags4 & RF4_ROCKET));
645 okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
651 okay = (r_idx == MON_DAWN);
657 okay = (r_ptr->flags3 & (RF3_ANIMAL));
661 case SUMMON_ANIMAL_RANGER:
663 okay = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
664 (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
665 !(r_ptr->flags3 & (RF3_DRAGON)) &&
666 !(r_ptr->flags3 & (RF3_EVIL)) &&
667 !(r_ptr->flags3 & (RF3_UNDEAD)) &&
668 !(r_ptr->flags3 & (RF3_DEMON)) &&
669 !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
670 !(r_ptr->flags4 || r_ptr->a_ability_flags1 || r_ptr->a_ability_flags2));
674 case SUMMON_HI_DRAGON_LIVING:
676 okay = ((r_ptr->d_char == 'D') && monster_living(r_idx));
682 okay = monster_living(r_idx);
688 okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
692 case SUMMON_BLUE_HORROR:
694 okay = (r_idx == MON_BLUE_HORROR);
698 case SUMMON_ELEMENTAL:
700 okay = (r_ptr->d_char == 'E');
706 okay = (r_ptr->d_char == 'v');
712 okay = (r_ptr->d_char == 'H');
718 okay = (r_ptr->d_char == 'B');
722 case SUMMON_KAMIKAZE:
725 for (i = 0; i < 4; i++)
726 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
730 case SUMMON_KAMIKAZE_LIVING:
734 for (i = 0; i < 4; i++)
735 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
736 okay = (okay && monster_living(r_idx));
742 okay = (r_idx == MON_MANES);
748 okay = (r_idx == MON_LOUSE);
752 case SUMMON_GUARDIANS:
754 okay = (r_ptr->flags7 & RF7_GUARDIAN);
760 okay = ((r_idx == MON_NOV_PALADIN) ||
761 (r_idx == MON_NOV_PALADIN_G) ||
762 (r_idx == MON_PALADIN) ||
763 (r_idx == MON_W_KNIGHT) ||
764 (r_idx == MON_ULTRA_PALADIN) ||
765 (r_idx == MON_KNI_TEMPLAR));
771 okay = (r_ptr->d_char == 'B' &&
772 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
773 (r_ptr->flags8 & RF8_WILD_ONLY));
777 case SUMMON_PIRANHAS:
779 okay = (r_idx == MON_PIRANHA);
783 case SUMMON_ARMAGE_GOOD:
785 okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
789 case SUMMON_ARMAGE_EVIL:
791 okay = ((r_ptr->flags3 & RF3_DEMON) ||
792 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
796 /* Since okay is int, "return (okay);" is not correct. */
797 return (bool)(okay ? TRUE : FALSE);
801 * @var chameleon_change_m_idx
802 * @brief カメレオンの変身先モンスターIDを受け渡すためのグローバル変数
803 * @todo 変数渡しの問題などもあるができればchameleon_change_m_idxのグローバル変数を除去し、関数引き渡しに移行すること
805 static int chameleon_change_m_idx = 0;
809 * @brief 指定されたモンスター種族がダンジョンの制限にかかるかどうかをチェックする / Some dungeon types restrict the possible monsters.
810 * @param r_idx チェックするモンスター種族ID
811 * @return 召喚条件が一致するならtrue / Return TRUE is the monster is OK and FALSE otherwise
813 static bool restrict_monster_to_dungeon(MONRACE_IDX r_idx)
815 dungeon_type *d_ptr = &d_info[p_ptr->dungeon_idx];
816 monster_race *r_ptr = &r_info[r_idx];
819 if (d_ptr->flags1 & DF1_CHAMELEON)
821 if (chameleon_change_m_idx) return TRUE;
823 if (d_ptr->flags1 & DF1_NO_MAGIC)
825 if (r_idx != MON_CHAMELEON &&
827 !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
828 !(r_ptr->a_ability_flags1 & RF5_NOMAGIC_MASK) &&
829 !(r_ptr->a_ability_flags2 & RF6_NOMAGIC_MASK))
832 if (d_ptr->flags1 & DF1_NO_MELEE)
834 if (r_idx == MON_CHAMELEON) return TRUE;
835 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
836 !(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)) &&
837 !(r_ptr->a_ability_flags2 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
840 if (d_ptr->flags1 & DF1_BEGINNER)
842 if (r_ptr->level > current_floor_ptr->dun_level)
846 if (d_ptr->special_div >= 64) return TRUE;
847 if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
851 case DUNGEON_MODE_AND:
854 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
859 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
864 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
869 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
872 if (d_ptr->m_a_ability_flags1)
874 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
877 if (d_ptr->m_a_ability_flags2)
879 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
884 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
889 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
894 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
899 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
902 for (a = 0; a < 5; a++)
903 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
907 case DUNGEON_MODE_NAND:
910 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
915 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
920 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
925 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
928 if (d_ptr->m_a_ability_flags1)
930 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
933 if (d_ptr->m_a_ability_flags2)
935 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
940 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
945 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
950 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
955 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
958 for (a = 0; a < 5; a++)
959 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
963 case DUNGEON_MODE_OR:
964 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
965 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
966 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
967 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
968 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return TRUE;
969 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return TRUE;
970 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
971 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
972 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
973 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
974 for (a = 0; a < 5; a++)
975 if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
979 case DUNGEON_MODE_NOR:
980 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
981 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
982 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
983 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
984 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return FALSE;
985 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return FALSE;
986 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
987 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
988 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
989 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
990 for (a = 0; a < 5; a++)
991 if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1000 * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
1001 * @param monster_hook 制限関数1
1002 * @param monster_hook2 制限関数2
1005 errr get_mon_num_prep(monsterrace_hook_type monster_hook,
1006 monsterrace_hook_type monster_hook2)
1010 /* Todo: Check the hooks for non-changes */
1012 /* Set the new hooks */
1013 get_mon_num_hook = monster_hook;
1014 get_mon_num2_hook = monster_hook2;
1016 /* Scan the allocation table */
1017 for (i = 0; i < alloc_race_size; i++)
1019 monster_race *r_ptr;
1022 alloc_entry *entry = &alloc_race_table[i];
1025 r_ptr = &r_info[entry->index];
1027 /* Skip monsters which don't pass the restriction */
1028 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1029 (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1032 if (!p_ptr->inside_battle && !chameleon_change_m_idx &&
1033 summon_specific_type != SUMMON_GUARDIANS)
1035 /* Hack -- don't create questors */
1036 if (r_ptr->flags1 & RF1_QUESTOR)
1039 if (r_ptr->flags7 & RF7_GUARDIAN)
1042 /* Depth Monsters never appear out of depth */
1043 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1044 (r_ptr->level > current_floor_ptr->dun_level))
1048 /* Accept this monster */
1049 entry->prob2 = entry->prob1;
1051 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)
1053 int hoge = entry->prob2 * d_info[p_ptr->dungeon_idx].special_div;
1054 entry->prob2 = hoge / 64;
1055 if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1065 * @brief 生成モンスター種族を1種生成テーブルから選択する
1067 * @return 選択されたモンスター生成種族
1069 * Choose a monster race that seems "appropriate" to the given level
1071 * This function uses the "prob2" field of the "monster allocation table",
1072 * and various local information, to calculate the "prob3" field of the
1073 * same table, which is then used to choose an "appropriate" monster, in
1074 * a relatively efficient manner.
1076 * Note that "town" monsters will *only* be created in the town, and
1077 * "normal" monsters will *never* be created in the town, unless the
1078 * "level" is "modified", for example, by polymorph or summoning.
1080 * There is a small chance (1/50) of "boosting" the given depth by
1081 * a small amount (up to four levels), except in the town.
1083 * It is (slightly) more likely to acquire a monster of the given level
1084 * than one of a lower level. This is done by choosing several monsters
1085 * appropriate to the given level and keeping the "hardest" one.
1087 * Note that if no monsters are "appropriate", then this function will
1088 * fail, and return zero, but this should *almost* never happen.
1090 MONRACE_IDX get_mon_num(DEPTH level)
1095 monster_race *r_ptr;
1096 alloc_entry *table = alloc_race_table;
1098 int pls_kakuritu, pls_level;
1099 int delay = mysqrt(level * 10000L) + 400L;
1101 pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10)));
1102 pls_level = MIN(NASTY_MON_PLUS_MAX, 3 + current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10)) ;
1104 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_MAZE)
1106 pls_kakuritu = MIN(pls_kakuritu / 2, pls_kakuritu - 10);
1107 if (pls_kakuritu < 2) pls_kakuritu = 2;
1112 /* Boost the level */
1113 if (!p_ptr->inside_battle && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1115 /* Nightmare mode allows more out-of depth monsters */
1116 if (ironman_nightmare && !randint0(pls_kakuritu))
1118 /* What a bizarre calculation */
1119 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1123 /* Occasional "nasty" monster */
1124 if (!randint0(pls_kakuritu))
1126 /* Pick a level bonus */
1132 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1133 if (level < 0) level = 0;
1138 /* Process probabilities */
1139 for (i = 0; i < alloc_race_size; i++)
1141 /* Monsters are sorted by depth */
1142 if (table[i].level > level) break;
1147 /* Access the "r_idx" of the chosen monster */
1148 r_idx = table[i].index;
1150 /* Access the actual race */
1151 r_ptr = &r_info[r_idx];
1153 if (!p_ptr->inside_battle && !chameleon_change_m_idx)
1155 /* Hack -- "unique" monsters must be "unique" */
1156 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1157 (r_ptr->flags7 & (RF7_NAZGUL))) &&
1158 (r_ptr->cur_num >= r_ptr->max_num))
1163 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1164 (r_ptr->cur_num >= 1))
1169 if (r_idx == MON_BANORLUPART)
1171 if (r_info[MON_BANOR].cur_num > 0) continue;
1172 if (r_info[MON_LUPART].cur_num > 0) continue;
1177 table[i].prob3 = table[i].prob2;
1180 total += table[i].prob3;
1183 /* No legal monsters */
1184 if (total <= 0) return (0);
1186 /* Pick a monster */
1187 value = randint0(total);
1189 /* Find the monster */
1190 for (i = 0; i < alloc_race_size; i++)
1192 /* Found the entry */
1193 if (value < table[i].prob3) break;
1196 value = value - table[i].prob3;
1202 /* Try for a "harder" monster once (50%) or twice (10%) */
1208 /* Pick a monster */
1209 value = randint0(total);
1211 /* Find the monster */
1212 for (i = 0; i < alloc_race_size; i++)
1214 /* Found the entry */
1215 if (value < table[i].prob3) break;
1218 value = value - table[i].prob3;
1221 /* Keep the "best" one */
1222 if (table[i].level < table[j].level) i = j;
1225 /* Try for a "harder" monster twice (10%) */
1231 /* Pick a monster */
1232 value = randint0(total);
1234 /* Find the monster */
1235 for (i = 0; i < alloc_race_size; i++)
1237 /* Found the entry */
1238 if (value < table[i].prob3) break;
1241 value = value - table[i].prob3;
1244 /* Keep the "best" one */
1245 if (table[i].level < table[j].level) i = j;
1247 return (table[i].index);
1252 * @brief モンスターの呼称を作成する / Build a string describing a monster in some way.
1253 * @param desc 記述出力先の文字列参照ポインタ
1254 * @param m_ptr モンスターの参照ポインタ
1255 * @param mode 呼称オプション
1258 * We can correctly describe monsters based on their visibility.
1259 * We can force all monsters to be treated as visible or invisible.
1260 * We can build nominatives, objectives, possessives, or reflexives.
1261 * We can selectively pronominalize hidden, visible, or all monsters.
1262 * We can use definite or indefinite descriptions for hidden monsters.
1263 * We can use definite or indefinite descriptions for visible monsters.
1265 * Pronominalization involves the gender whenever possible and allowed,
1266 * so that by cleverly requesting pronominalization / visibility, you
1267 * can get messages like "You hit someone. She screams in agony!".
1269 * Reflexives are acquired by requesting Objective plus Possessive.
1271 * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1272 * unless the "Assume Visible" mode is requested.
1274 * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1275 * If neither m_ptr nor r_ptr is given, the monster is assumed to
1276 * be neuter, singular, and hidden (unless "Assume Visible" is set),
1277 * in which case you may be in trouble... :-)
1279 * I am assuming that no monster name is more than 70 characters long,
1280 * so that "char desc[80];" is sufficiently large for any result.
1283 * MD_OBJECTIVE --> Objective (or Reflexive)
1284 * MD_POSSESSIVE --> Possessive (or Reflexive)
1285 * MD_INDEF_HIDDEN --> Use indefinites for hidden monsters ("something")
1286 * MD_INDEF_VISIBLE --> Use indefinites for visible monsters ("a kobold")
1287 * MD_PRON_HIDDEN --> Pronominalize hidden monsters
1288 * MD_PRON_VISIBLE --> Pronominalize visible monsters
1289 * MD_ASSUME_HIDDEN --> Assume the monster is hidden
1290 * MD_ASSUME_VISIBLE --> Assume the monster is visible
1291 * MD_TRUE_NAME --> Chameleon's true name
1292 * MD_IGNORE_HALLU --> Ignore hallucination, and penetrate shape change
1295 * 0x00 --> Full nominative name ("the kobold") or "it"
1296 * MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1297 * MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1298 * MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1299 * MD_PRON_VISIBLE | MD_POSSESSIVE
1300 * --> Possessive, genderized if visable ("his") or "its"
1301 * MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1302 * --> Reflexive, genderized if visable ("himself") or "itself"
1304 void monster_desc(char *desc, monster_type *m_ptr, BIT_FLAGS mode)
1307 monster_race *r_ptr;
1311 GAME_TEXT silly_name[1024];
1315 r_ptr = &r_info[m_ptr->ap_r_idx];
1317 /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1318 if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1319 else name = (r_name + r_ptr->name);
1321 /* Are we hallucinating? (Idea from Nethack...) */
1322 if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1326 if (!get_rnd_line(_("silly_j.txt", "silly.txt"), m_ptr->r_idx, silly_name))
1332 monster_race *hallu_race;
1336 hallu_race = &r_info[randint1(max_r_idx - 1)];
1338 while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
1340 strcpy(silly_name, (r_name + hallu_race->name));
1343 /* Better not strcpy it, or we could corrupt r_info... */
1347 /* Can we "see" it (exists + forced, or visible + not unforced) */
1348 seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1350 /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1351 pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1354 /* First, try using pronouns, or describing hidden monsters */
1357 /* an encoding of the monster "sex" */
1360 /* Extract the gender (if applicable) */
1361 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1362 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1364 /* Ignore the gender (if desired) */
1365 if (!m_ptr || !pron) kind = 0x00;
1368 /* Assume simple result */
1369 res = _("何か", "it");
1371 /* Brute force: split on the possibilities */
1372 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1374 /* Neuter, or unknown */
1376 case 0x00: res = "何か"; break;
1377 case 0x00 + (MD_OBJECTIVE): res = "何か"; break;
1378 case 0x00 + (MD_POSSESSIVE): res = "何かの"; break;
1379 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "何か自身"; break;
1380 case 0x00 + (MD_INDEF_HIDDEN): res = "何か"; break;
1381 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "何か"; break;
1382 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "何か"; break;
1383 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "それ自身"; break;
1385 case 0x00: res = "it"; break;
1386 case 0x00 + (MD_OBJECTIVE): res = "it"; break;
1387 case 0x00 + (MD_POSSESSIVE): res = "its"; break;
1388 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1389 case 0x00 + (MD_INDEF_HIDDEN): res = "something"; break;
1390 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "something"; break;
1391 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "something's"; break;
1392 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "itself"; break;
1396 /* Male (assume human if vague) */
1398 case 0x10: res = "彼"; break;
1399 case 0x10 + (MD_OBJECTIVE): res = "彼"; break;
1400 case 0x10 + (MD_POSSESSIVE): res = "彼の"; break;
1401 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "彼自身"; break;
1402 case 0x10 + (MD_INDEF_HIDDEN): res = "誰か"; break;
1403 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "誰か"; break;
1404 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "誰かの"; break;
1405 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "彼自身"; break;
1407 case 0x10: res = "he"; break;
1408 case 0x10 + (MD_OBJECTIVE): res = "him"; break;
1409 case 0x10 + (MD_POSSESSIVE): res = "his"; break;
1410 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1411 case 0x10 + (MD_INDEF_HIDDEN): res = "someone"; break;
1412 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1413 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1414 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "himself"; break;
1418 /* Female (assume human if vague) */
1420 case 0x20: res = "彼女"; break;
1421 case 0x20 + (MD_OBJECTIVE): res = "彼女"; break;
1422 case 0x20 + (MD_POSSESSIVE): res = "彼女の"; break;
1423 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "彼女自身"; break;
1424 case 0x20 + (MD_INDEF_HIDDEN): res = "誰か"; break;
1425 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "誰か"; break;
1426 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "誰かの"; break;
1427 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "彼女自身"; break;
1429 case 0x20: res = "she"; break;
1430 case 0x20 + (MD_OBJECTIVE): res = "her"; break;
1431 case 0x20 + (MD_POSSESSIVE): res = "her"; break;
1432 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1433 case 0x20 + (MD_INDEF_HIDDEN): res = "someone"; break;
1434 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE): res = "someone"; break;
1435 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE): res = "someone's"; break;
1436 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE): res = "herself"; break;
1440 /* Copy the result */
1441 (void)strcpy(desc, res);
1445 /* Handle visible monsters, "reflexive" request */
1446 else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1448 /* The monster is visible, so use its gender */
1449 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, _("彼女自身", "herself"));
1450 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, _("彼自身", "himself"));
1451 else strcpy(desc, _("それ自身", "itself"));
1455 /* Handle all other visible monster requests */
1459 if (is_pet(m_ptr) && !is_original_ap(m_ptr))
1465 while(strncmp(t, "』", 2) && *t) t++;
1469 (void)sprintf(desc, "%s?』", buf);
1472 (void)sprintf(desc, "%s?", name);
1474 (void)sprintf(desc, "%s?", name);
1479 /* It could be a Unique */
1480 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1482 /* Start with the name (thus nominative and objective) */
1483 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1489 while (strncmp(t, "』", 2) && *t) t++;
1493 (void)sprintf(desc, "%s?』", buf);
1496 (void)sprintf(desc, "%s?", name);
1498 (void)sprintf(desc, "%s?", name);
1502 /* Inside monster arena, and it is not your mount */
1503 else if (p_ptr->inside_battle &&
1504 !(p_ptr->riding && (¤t_floor_ptr->m_list[p_ptr->riding] == m_ptr)))
1506 /* It is a fake unique monster */
1507 (void)sprintf(desc, _("%sもどき", "fake %s"), name);
1512 (void)strcpy(desc, name);
1516 /* It could be an indefinite monster */
1517 else if (mode & MD_INDEF_VISIBLE)
1519 /* XXX Check plurality for "some" */
1521 /* Indefinite monsters need an indefinite article */
1523 (void)strcpy(desc, "");
1525 (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1528 (void)strcat(desc, name);
1531 /* It could be a normal, definite, monster */
1534 /* Definite monsters need a definite article */
1536 (void)strcpy(desc, _("あなたの", "your "));
1538 (void)strcpy(desc, _("", "the "));
1540 (void)strcat(desc, name);
1543 if (m_ptr->nickname)
1545 sprintf(buf,_("「%s」", " called %s"),quark_str(m_ptr->nickname));
1549 if (p_ptr->riding && (¤t_floor_ptr->m_list[p_ptr->riding] == m_ptr))
1551 strcat(desc,_("(乗馬中)", "(riding)"));
1554 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1556 if (r_ptr->flags1 & RF1_UNIQUE)
1558 strcat(desc,_("(カメレオンの王)", "(Chameleon Lord)"));
1562 strcat(desc,_("(カメレオン)", "(Chameleon)"));
1566 if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr))
1568 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1571 /* Handle the Possessive as a special afterthought */
1572 if (mode & MD_POSSESSIVE)
1574 /* XXX Check for trailing "s" */
1576 /* Simply append "apostrophe" and "s" */
1577 (void)strcat(desc, _("の", "'s"));
1585 * @brief モンスターの調査による思い出補完処理 / Learn about a monster (by "probing" it)
1586 * @param r_idx 補完されるモンスター種族ID
1587 * @return 明らかになった情報の度数
1589 * Return the number of new flags learnt. -Mogami-
1591 int lore_do_probe(MONRACE_IDX r_idx)
1593 monster_race *r_ptr = &r_info[r_idx];
1597 /* Maximal info about awareness */
1598 if (r_ptr->r_wake != MAX_UCHAR) n++;
1599 if (r_ptr->r_ignore != MAX_UCHAR) n++;
1600 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1602 /* Observe "maximal" attacks */
1603 for (i = 0; i < 4; i++)
1605 /* Examine "actual" blows */
1606 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1608 /* Maximal observations */
1609 if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1610 r_ptr->r_blows[i] = MAX_UCHAR;
1616 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1617 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1618 ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1619 ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1620 ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1621 ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1623 /* Only "valid" drops */
1624 if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1626 if (r_ptr->r_drop_item != tmp_byte) n++;
1627 r_ptr->r_drop_item = tmp_byte;
1629 if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1631 if (r_ptr->r_drop_gold != tmp_byte) n++;
1632 r_ptr->r_drop_gold = tmp_byte;
1635 /* Observe many spells */
1636 if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1637 r_ptr->r_cast_spell = MAX_UCHAR;
1639 /* Count unknown flags */
1640 for (i = 0; i < 32; i++)
1642 if (!(r_ptr->r_flags1 & (1L << i)) &&
1643 (r_ptr->flags1 & (1L << i))) n++;
1644 if (!(r_ptr->r_flags2 & (1L << i)) &&
1645 (r_ptr->flags2 & (1L << i))) n++;
1646 if (!(r_ptr->r_flags3 & (1L << i)) &&
1647 (r_ptr->flags3 & (1L << i))) n++;
1648 if (!(r_ptr->r_flags4 & (1L << i)) &&
1649 (r_ptr->flags4 & (1L << i))) n++;
1650 if (!(r_ptr->r_flags5 & (1L << i)) &&
1651 (r_ptr->a_ability_flags1 & (1L << i))) n++;
1652 if (!(r_ptr->r_flags6 & (1L << i)) &&
1653 (r_ptr->a_ability_flags2 & (1L << i))) n++;
1654 if (!(r_ptr->r_flagsr & (1L << i)) &&
1655 (r_ptr->flagsr & (1L << i))) n++;
1657 /* r_flags7 is actually unused */
1659 if (!(r_ptr->r_flags7 & (1L << i)) &&
1660 (r_ptr->flags7 & (1L << i))) n++;
1664 /* Know all the flags */
1665 r_ptr->r_flags1 = r_ptr->flags1;
1666 r_ptr->r_flags2 = r_ptr->flags2;
1667 r_ptr->r_flags3 = r_ptr->flags3;
1668 r_ptr->r_flags4 = r_ptr->flags4;
1669 r_ptr->r_flags5 = r_ptr->a_ability_flags1;
1670 r_ptr->r_flags6 = r_ptr->a_ability_flags2;
1671 r_ptr->r_flagsr = r_ptr->flagsr;
1673 /* r_flags7 is actually unused */
1674 /* r_ptr->r_flags7 = r_ptr->flags7; */
1676 /* Know about evolution */
1677 if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1678 r_ptr->r_xtra1 |= MR1_SINKA;
1680 /* Update monster recall window */
1681 if (p_ptr->monster_race_idx == r_idx)
1683 p_ptr->window |= (PW_MONSTER);
1686 /* Return the number of new flags learnt */
1692 * @brief モンスターの撃破に伴うドロップ情報の保管処理 / Take note that the given monster just dropped some treasure
1693 * @param m_idx モンスター情報のID
1694 * @param num_item 手に入れたアイテム数
1695 * @param num_gold 手に入れた財宝の単位数
1698 * Note that learning the "GOOD"/"GREAT" flags gives information
1699 * about the treasure (even when the monster is killed for the first
1700 * time, such as uniques, and the treasure has not been examined yet).
1702 * This "indirect" method is used to prevent the player from learning
1703 * exactly how much treasure a monster can drop from observing only
1704 * a single example of a drop. This method actually observes how much
1705 * gold and items are dropped, and remembers that information to be
1706 * described later by the monster recall code.
1708 void lore_treasure(MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
1710 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1712 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1714 /* If the monster doesn't have original appearance, don't note */
1715 if (!is_original_ap(m_ptr)) return;
1717 /* Note the number of things dropped */
1718 if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1719 if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1721 /* Hack -- memorize the good/great flags */
1722 if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1723 if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1725 /* Update monster recall window */
1726 if (p_ptr->monster_race_idx == m_ptr->r_idx)
1728 p_ptr->window |= (PW_MONSTER);
1734 * @brief モンスターの各情報を更新する / This function updates the monster record of the given monster
1735 * @param m_idx 更新するモンスター情報のID
1736 * @param full プレイヤーとの距離更新を行うならばtrue
1739 * This involves extracting the distance to the player (if requested),
1740 * and then checking for visibility (natural, infravision, see-invis,
1741 * telepathy), updating the monster visibility flag, redrawing (or
1742 * erasing) the monster when its visibility changes, and taking note
1743 * of any interesting monster flags (cold-blooded, invisible, etc).
1745 * Note the new "mflag" field which encodes several monster state flags,
1746 * including "view" for when the monster is currently in line of sight,
1747 * and "mark" for when the monster is currently visible via detection.
1749 * The only monster fields that are changed here are "cdis" (the
1750 * distance from the player), "ml" (visible to the player), and
1751 * "mflag" (to maintain the "MFLAG_VIEW" flag).
1753 * Note the special "update_monsters()" function which can be used to
1754 * call this function once for every monster.
1756 * Note the "full" flag which requests that the "cdis" field be updated,
1757 * this is only needed when the monster (or the player) has moved.
1759 * Every time a monster moves, we must call this function for that
1760 * monster, and update the distance, and the visibility. Every time
1761 * the player moves, we must call this function for every monster, and
1762 * update the distance, and the visibility. Whenever the player "state"
1763 * changes in certain ways ("blindness", "infravision", "telepathy",
1764 * and "see invisible"), we must call this function for every monster,
1765 * and update the visibility.
1767 * Routines that change the "illumination" of a grid must also call this
1768 * function for any monster in that grid, since the "visibility" of some
1769 * monsters may be based on the illumination of their grid.
1771 * Note that this function is called once per monster every time the
1772 * player moves. When the player is running, this function is one
1773 * of the primary bottlenecks, along with "update_view()" and the
1774 * "process_monsters()" code, so efficiency is important.
1776 * Note the optimized "inline" version of the "distance()" function.
1778 * A monster is "visible" to the player if (1) it has been detected
1779 * by the player, (2) it is close to the player and the player has
1780 * telepathy, or (3) it is close to the player, and in line of sight
1781 * of the player, and it is "illuminated" by some combination of
1782 * infravision, torch light, or permanent light (invisible monsters
1783 * are only affected by "light" if the player can see invisible).
1785 * Monsters which are not on the current panel may be "visible" to
1786 * the player, and their descriptions will include an "offscreen"
1787 * reference. Currently, offscreen monsters cannot be targetted
1788 * or viewed directly, but old targets will remain set. XXX XXX
1790 * The player can choose to be disturbed by several things, including
1791 * "disturb_move" (monster which is viewable moves in some way), and
1792 * "disturb_near" (monster which is "easily" viewable moves in some
1793 * way). Note that "moves" includes "appears" and "disappears".
1795 void update_monster(MONSTER_IDX m_idx, bool full)
1797 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
1798 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1800 bool do_disturb = disturb_move;
1804 /* Current location */
1805 POSITION fy = m_ptr->fy;
1806 POSITION fx = m_ptr->fx;
1811 /* Seen by vision */
1814 /* Non-Ninja player in the darkness */
1815 bool in_darkness = (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !p_ptr->see_nocto;
1820 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1822 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
1826 /* Compute distance */
1829 /* Distance components */
1830 int dy = (p_ptr->y > fy) ? (p_ptr->y - fy) : (fy - p_ptr->y);
1831 int dx = (p_ptr->x > fx) ? (p_ptr->x - fx) : (fx - p_ptr->x);
1833 /* Approximate distance */
1834 d = (dy > dx) ? (dy + (dx>>1)) : (dx + (dy>>1));
1836 /* Restrict distance */
1837 if (d > 255) d = 255;
1841 /* Save the distance */
1845 /* Extract distance */
1848 /* Extract the distance */
1854 if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
1858 if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
1860 if (!in_darkness || (d <= MAX_SIGHT / 4))
1862 if (p_ptr->special_defense & KATA_MUSOU)
1867 if (is_original_ap(m_ptr) && !p_ptr->image)
1869 /* Hack -- Memorize mental flags */
1870 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1871 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1875 /* Basic telepathy */
1876 /* Snipers get telepathy when they concentrate deeper */
1877 else if (p_ptr->telepathy)
1879 /* Empty mind, no telepathy */
1880 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
1882 /* Memorize flags */
1883 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
1886 /* Weird mind, occasional telepathy */
1887 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
1889 /* One in ten individuals are detectable */
1890 if ((m_idx % 10) == 5)
1895 if (is_original_ap(m_ptr) && !p_ptr->image)
1897 /* Memorize flags */
1898 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
1900 /* Hack -- Memorize mental flags */
1901 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1902 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1907 /* Normal mind, allow telepathy */
1913 if (is_original_ap(m_ptr) && !p_ptr->image)
1915 /* Hack -- Memorize mental flags */
1916 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1917 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1922 if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
1925 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
1928 if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
1931 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
1934 if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
1937 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
1940 if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
1943 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
1946 if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
1949 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
1952 if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
1955 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
1958 if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
1961 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
1964 if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
1967 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
1970 if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
1973 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
1976 if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
1979 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
1982 if ((p_ptr->esp_nonliving) &&
1983 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
1986 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
1989 if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
1992 if (is_original_ap(m_ptr) && !p_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
1996 /* Normal line of sight, and not blind */
1997 if (player_has_los_bold(fy, fx) && !p_ptr->blind)
1999 bool do_invisible = FALSE;
2000 bool do_cold_blood = FALSE;
2002 /* Snipers can see targets in darkness when they concentrate deeper */
2003 if (p_ptr->concent >= CONCENT_RADAR_THRESHOLD)
2009 /* Use "infravision" */
2010 if (d <= p_ptr->see_infra)
2012 /* Handle "cold blooded" monsters */
2013 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2015 do_cold_blood = TRUE;
2018 /* Handle "warm blooded" monsters */
2026 /* Use "illumination" */
2027 if (player_can_see_bold(fy, fx))
2029 /* Handle "invisible" monsters */
2030 if (r_ptr->flags2 & (RF2_INVISIBLE))
2032 do_invisible = TRUE;
2042 /* Handle "normal" monsters */
2053 if (is_original_ap(m_ptr) && !p_ptr->image)
2055 /* Memorize flags */
2056 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2057 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2064 /* The monster is now visible */
2067 /* It was previously unseen */
2070 /* Mark as visible */
2073 /* Draw the monster */
2076 /* Update health bar as needed */
2077 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2078 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2080 /* Hack -- Count "fresh" sightings */
2083 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2084 r_info[MON_KAGE].r_sights++;
2085 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
2089 /* Eldritch Horror */
2090 if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
2092 sanity_blast(m_ptr, FALSE);
2095 /* Disturb on appearance */
2096 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)))
2098 if (disturb_pets || is_hostile(m_ptr))
2099 disturb(TRUE, TRUE);
2104 /* The monster is not visible */
2107 /* It was previously seen */
2110 /* Mark as not visible */
2113 /* Erase the monster */
2116 /* Update health bar as needed */
2117 if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
2118 if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
2120 /* Disturb on disappearance */
2123 if (disturb_pets || is_hostile(m_ptr))
2124 disturb(TRUE, TRUE);
2130 /* The monster is now easily visible */
2134 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2136 /* Mark as easily visible */
2137 m_ptr->mflag |= (MFLAG_VIEW);
2139 /* Disturb on appearance */
2142 if (disturb_pets || is_hostile(m_ptr))
2143 disturb(TRUE, TRUE);
2148 /* The monster is not easily visible */
2152 if (m_ptr->mflag & (MFLAG_VIEW))
2154 /* Mark as not easily visible */
2155 m_ptr->mflag &= ~(MFLAG_VIEW);
2157 /* Disturb on disappearance */
2160 if (disturb_pets || is_hostile(m_ptr))
2161 disturb(TRUE, TRUE);
2169 * @brief 単純に生存している全モンスターの更新処理を行う / This function simply updates all the (non-dead) monsters (see above).
2170 * @param full 距離更新を行うならtrue
2173 void update_monsters(bool full)
2177 /* Update each (live) monster */
2178 for (i = 1; i < m_max; i++)
2180 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
2181 if (!monster_is_valid(m_ptr)) continue;
2182 update_monster(i, full);
2188 * @brief カメレオンの王の変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2189 * @param r_idx モンスター種族ID
2190 * @return 対象にできるならtrueを返す
2192 static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
2194 monster_race *r_ptr = &r_info[r_idx];
2195 monster_type *m_ptr = ¤t_floor_ptr->m_list[chameleon_change_m_idx];
2196 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2198 if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2199 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2201 if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2203 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))
2206 if (!monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2209 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2211 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2215 else if (summon_specific_who > 0)
2217 if (monster_has_hostile_align(¤t_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2224 * @brief カメレオンの変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2225 * @param r_idx モンスター種族ID
2226 * @return 対象にできるならtrueを返す
2227 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2229 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
2231 monster_race *r_ptr = &r_info[r_idx];
2232 monster_type *m_ptr = ¤t_floor_ptr->m_list[chameleon_change_m_idx];
2233 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2235 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2236 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2237 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2239 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))
2242 if (!monster_can_cross_terrain(current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2245 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2247 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2248 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2249 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2253 else if (summon_specific_who > 0)
2255 if (monster_has_hostile_align(¤t_floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2258 return (*(get_monster_hook()))(r_idx);
2263 * @param m_idx 変身処理を受けるモンスター情報のID
2264 * @param born 生成時の初変身先指定ならばtrue
2265 * @param r_idx 旧モンスター種族のID
2268 void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
2271 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
2272 monster_race *r_ptr;
2273 char old_m_name[MAX_NLEN];
2274 bool old_unique = FALSE;
2275 int old_r_idx = m_ptr->r_idx;
2277 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2279 if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2280 r_ptr = &r_info[r_idx];
2282 monster_desc(old_m_name, m_ptr, 0);
2288 chameleon_change_m_idx = m_idx;
2290 get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2292 get_mon_num_prep(monster_hook_chameleon, NULL);
2295 level = r_info[MON_CHAMELEON_K].level;
2296 else if (!current_floor_ptr->dun_level)
2297 level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2299 level = current_floor_ptr->dun_level;
2301 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
2303 r_idx = get_mon_num(level);
2304 r_ptr = &r_info[r_idx];
2306 chameleon_change_m_idx = 0;
2310 m_ptr->r_idx = r_idx;
2311 m_ptr->ap_r_idx = r_idx;
2312 update_monster(m_idx, FALSE);
2313 lite_spot(m_ptr->fy, m_ptr->fx);
2315 if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2316 (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2317 p_ptr->update |= (PU_MON_LITE);
2321 /* Sub-alignment of a chameleon */
2322 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2324 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2325 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2326 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2331 if (m_idx == p_ptr->riding)
2333 GAME_TEXT m_name[MAX_NLEN];
2334 monster_desc(m_name, m_ptr, 0);
2335 msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
2336 if (!(r_ptr->flags7 & RF7_RIDING))
2337 if (rakuba(0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
2340 /* Extract the monster base speed */
2341 m_ptr->mspeed = get_mspeed(r_ptr);
2343 oldmaxhp = m_ptr->max_maxhp;
2344 /* Assign maximal hitpoints */
2345 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2347 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2351 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2354 /* Monsters have double hitpoints in Nightmare mode */
2355 if (ironman_nightmare)
2357 u32b hp = m_ptr->max_maxhp * 2L;
2358 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2361 m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2362 if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2363 m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2365 /* reset dealt_damage */
2366 m_ptr->dealt_damage = 0;
2371 * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
2372 * @param r_idx モンスター種族ID
2373 * @return 対象にできるならtrueを返す
2374 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2376 static bool monster_hook_tanuki(MONRACE_IDX r_idx)
2378 monster_race *r_ptr = &r_info[r_idx];
2380 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2381 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2382 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2383 if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2385 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))
2388 return (*(get_monster_hook()))(r_idx);
2393 * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
2394 * @param r_idx モンスター種族ID
2395 * @return モンスター種族の表層ID
2397 static MONRACE_IDX initial_r_appearance(MONRACE_IDX r_idx)
2399 int attempts = 1000;
2400 MONRACE_IDX ap_r_idx;
2401 DEPTH min = MIN(current_floor_ptr->base_level-5, 50);
2403 if (p_ptr->pseikaku == SEIKAKU_CHARGEMAN)
2405 if (current_floor_ptr->base_level == 0 || one_in_(5)) return MON_ALIEN_JURAL;
2408 if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2411 get_mon_num_prep(monster_hook_tanuki, NULL);
2415 ap_r_idx = get_mon_num(current_floor_ptr->base_level + 10);
2416 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2424 * @brief モンスターの個体加速を設定する / Get initial monster speed
2425 * @param r_ptr モンスター種族の参照ポインタ
2428 SPEED get_mspeed(monster_race *r_ptr)
2430 /* Extract the monster base speed */
2431 SPEED mspeed = r_ptr->speed;
2433 /* Hack -- small racial variety */
2434 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
2436 /* Allow some small variation per monster */
2437 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2438 if (i) mspeed += rand_spread(0, i);
2441 if (mspeed > 199) mspeed = 199;
2448 * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
2449 * @param who 召喚を行ったモンスターID
2452 * @param r_idx 生成モンスター種族
2453 * @param mode 生成オプション
2456 * To give the player a sporting chance, any monster that appears in
2457 * line-of-sight and is extremely dangerous can be marked as
2458 * "FORCE_SLEEP", which will cause them to be placed with low energy,
2459 * which often (but not always) lets the player move before they do.
2461 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2463 * Use special "here" and "dead" flags for unique monsters,
2464 * remove old "cur_num" and "max_num" fields.
2466 * Actually, do something similar for artifacts, to simplify
2467 * the "preserve" mode, and to make the "what artifacts" flag more useful.
2469 * This is the only function which may place a monster in the dungeon,
2470 * except for the savefile loading code.
2472 static bool place_monster_one(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2474 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
2475 monster_type *m_ptr;
2476 monster_race *r_ptr = &r_info[r_idx];
2477 concptr name = (r_name + r_ptr->name);
2481 /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2482 if (p_ptr->wild_mode) return FALSE;
2484 /* Verify location */
2485 if (!in_bounds(y, x)) return (FALSE);
2486 if (!r_idx) return (FALSE);
2487 if (!r_ptr->name) return (FALSE);
2489 if (!(mode & PM_IGNORE_TERRAIN))
2491 /* Not on the Pattern */
2492 if (pattern_tile(y, x)) return FALSE;
2494 /* Require empty space (if not ghostly) */
2495 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
2498 if (!p_ptr->inside_battle)
2500 /* Hack -- "unique" monsters must be "unique" */
2501 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2502 (r_ptr->flags7 & (RF7_NAZGUL))) &&
2503 (r_ptr->cur_num >= r_ptr->max_num))
2509 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
2510 (r_ptr->cur_num >= 1))
2515 if (r_idx == MON_BANORLUPART)
2517 if (r_info[MON_BANOR].cur_num > 0) return FALSE;
2518 if (r_info[MON_LUPART].cur_num > 0) return FALSE;
2521 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
2522 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (current_floor_ptr->dun_level < r_ptr->level) &&
2523 (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
2530 if (quest_number(current_floor_ptr->dun_level))
2532 int hoge = quest_number(current_floor_ptr->dun_level);
2533 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
2535 if(r_idx == quest[hoge].r_idx)
2537 int number_mon, i2, j2;
2540 /* Count all quest monsters */
2541 for (i2 = 0; i2 < current_floor_ptr->width; ++i2)
2542 for (j2 = 0; j2 < current_floor_ptr->height; j2++)
2543 if (current_floor_ptr->grid_array[j2][i2].m_idx > 0)
2544 if (current_floor_ptr->m_list[current_floor_ptr->grid_array[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
2546 if(number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
2552 if (is_glyph_grid(g_ptr))
2554 if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
2556 /* Describe observable breakage */
2557 if (g_ptr->info & CAVE_MARK)
2559 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2562 /* Forget the rune */
2563 g_ptr->info &= ~(CAVE_MARK);
2565 /* Break the rune */
2566 g_ptr->info &= ~(CAVE_OBJECT);
2574 msg_format_wizard(CHEAT_MONSTER, _("%s(Lv%d)を生成しました。", "%s(Lv%d) was generated."), name, r_ptr->level);
2576 if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
2578 /* Make a new monster */
2579 g_ptr->m_idx = m_pop();
2580 hack_m_idx_ii = g_ptr->m_idx;
2582 /* Mega-Hack -- catch "failure" */
2583 if (!g_ptr->m_idx) return (FALSE);
2586 /* Get a new monster record */
2587 m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
2590 m_ptr->r_idx = r_idx;
2591 m_ptr->ap_r_idx = initial_r_appearance(r_idx);
2597 /* Hack -- Appearance transfer */
2598 if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(¤t_floor_ptr->m_list[who]))
2600 m_ptr->ap_r_idx = current_floor_ptr->m_list[who].ap_r_idx;
2602 /* Hack -- Shadower spawns Shadower */
2603 if (current_floor_ptr->m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
2606 /* Sub-alignment of a monster */
2607 if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
2608 m_ptr->sub_align = current_floor_ptr->m_list[who].sub_align;
2611 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2612 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2613 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2616 /* Place the monster at the location */
2621 /* No "timed status" yet */
2622 for (cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
2624 /* Unknown distance */
2627 reset_target(m_ptr);
2629 m_ptr->nickname = 0;
2634 /* Your pet summons its pet. */
2635 if (who > 0 && is_pet(¤t_floor_ptr->m_list[who]))
2637 mode |= PM_FORCE_PET;
2638 m_ptr->parent_m_idx = who;
2642 m_ptr->parent_m_idx = 0;
2645 if (r_ptr->flags7 & RF7_CHAMELEON)
2647 choose_new_monster(g_ptr->m_idx, TRUE, 0);
2648 r_ptr = &r_info[m_ptr->r_idx];
2649 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
2651 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
2652 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
2653 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2655 else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
2657 m_ptr->ap_r_idx = MON_KAGE;
2658 m_ptr->mflag2 |= MFLAG2_KAGE;
2661 if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
2667 if (mode & PM_FORCE_PET)
2672 else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
2673 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(who))
2675 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
2678 /* Assume no sleeping */
2679 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
2681 /* Enforce sleeping if needed */
2682 if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
2684 int val = r_ptr->sleep;
2685 (void)set_monster_csleep(g_ptr->m_idx, (val * 2) + randint1(val * 10));
2688 /* Assign maximal hitpoints */
2689 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2691 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2695 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2698 /* Monsters have double hitpoints in Nightmare mode */
2699 if (ironman_nightmare)
2701 u32b hp = m_ptr->max_maxhp * 2L;
2703 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2706 m_ptr->maxhp = m_ptr->max_maxhp;
2708 /* And start out fully healthy */
2709 if (m_ptr->r_idx == MON_WOUNDED_BEAR)
2710 m_ptr->hp = m_ptr->maxhp / 2;
2711 else m_ptr->hp = m_ptr->maxhp;
2714 /* dealt damage is 0 at initial*/
2715 m_ptr->dealt_damage = 0;
2718 /* Extract the monster base speed */
2719 m_ptr->mspeed = get_mspeed(r_ptr);
2721 if (mode & PM_HASTE) (void)set_monster_fast(g_ptr->m_idx, 100);
2723 /* Give a random starting energy */
2724 if (!ironman_nightmare)
2726 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
2730 /* Nightmare monsters are more prepared */
2731 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
2734 /* Force monster to wait for player, unless in Nightmare mode */
2735 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
2737 /* Monster is still being nice */
2738 m_ptr->mflag |= (MFLAG_NICE);
2740 /* Must repair monsters */
2741 repair_monsters = TRUE;
2744 /* Hack -- see "process_monsters()" */
2745 if (g_ptr->m_idx < hack_m_idx)
2747 /* Monster is still being born */
2748 m_ptr->mflag |= (MFLAG_BORN);
2752 if (r_ptr->flags7 & RF7_SELF_LD_MASK)
2753 p_ptr->update |= (PU_MON_LITE);
2754 else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
2755 p_ptr->update |= (PU_MON_LITE);
2756 update_monster(g_ptr->m_idx, TRUE);
2759 /* Count the monsters on the level */
2760 real_r_ptr(m_ptr)->cur_num++;
2763 * Memorize location of the unique monster in saved floors.
2764 * A unique monster move from old saved floor.
2766 if (character_dungeon &&
2767 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
2768 real_r_ptr(m_ptr)->floor_id = p_ptr->floor_id;
2770 /* Hack -- Count the number of "reproducers" */
2771 if (r_ptr->flags2 & RF2_MULTIPLY) current_floor_ptr->num_repro++;
2773 /* Hack -- Notice new multi-hued monsters */
2775 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
2776 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
2777 shimmer_monsters = TRUE;
2780 if (p_ptr->warning && character_dungeon)
2782 if (r_ptr->flags1 & RF1_UNIQUE)
2786 GAME_TEXT o_name[MAX_NLEN];
2788 if (r_ptr->level > p_ptr->lev + 30)
2789 color = _("黒く", "black");
2790 else if (r_ptr->level > p_ptr->lev + 15)
2791 color = _("紫色に", "purple");
2792 else if (r_ptr->level > p_ptr->lev + 5)
2793 color = _("ルビー色に", "deep red");
2794 else if (r_ptr->level > p_ptr->lev - 5)
2795 color = _("赤く", "red");
2796 else if (r_ptr->level > p_ptr->lev - 15)
2797 color = _("ピンク色に", "pink");
2799 color = _("白く", "white");
2801 o_ptr = choose_warning_item();
2804 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2805 msg_format(_("%sは%s光った。", "%s glows %s."), o_name, color);
2809 msg_format(_("%s光る物が頭に浮かんだ。", "An %s image forms in your mind."), color);
2814 if (is_explosive_rune_grid(g_ptr))
2816 /* Break the ward */
2817 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2819 /* Describe observable breakage */
2820 if (g_ptr->info & CAVE_MARK)
2822 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2823 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);
2828 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2831 /* Forget the rune */
2832 g_ptr->info &= ~(CAVE_MARK);
2834 /* Break the rune */
2835 g_ptr->info &= ~(CAVE_OBJECT);
2848 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
2851 * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster
2852 * @param r_idx 生成モンスター種族
2853 * @param yp 結果生成位置y座標
2854 * @param xp 結果生成位置x座標
2855 * @param y 中心生成位置y座標
2856 * @param x 中心生成位置x座標
2857 * @param max_dist 生成位置の最大半径
2861 static bool mon_scatter(MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
2863 POSITION place_x[MON_SCAT_MAXD];
2864 POSITION place_y[MON_SCAT_MAXD];
2865 int num[MON_SCAT_MAXD];
2869 if (max_dist >= MON_SCAT_MAXD)
2872 for (i = 0; i < MON_SCAT_MAXD; i++)
2875 for (nx = x - max_dist; nx <= x + max_dist; nx++)
2877 for (ny = y - max_dist; ny <= y + max_dist; ny++)
2879 /* Ignore annoying locations */
2880 if (!in_bounds(ny, nx)) continue;
2882 /* Require "line of projection" */
2883 if (!projectable(y, x, ny, nx)) continue;
2887 monster_race *r_ptr = &r_info[r_idx];
2889 /* Require empty space (if not ghostly) */
2890 if (!monster_can_enter(ny, nx, r_ptr, 0))
2895 /* Walls and Monsters block flow */
2896 if (!cave_empty_bold2(ny, nx)) continue;
2898 /* ... nor on the Pattern */
2899 if (pattern_tile(ny, nx)) continue;
2902 i = distance(y, x, ny, nx);
2910 if (one_in_(num[i]))
2919 while (i < MON_SCAT_MAXD && 0 == num[i])
2921 if (i >= MON_SCAT_MAXD)
2931 * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
2932 * @param who 召喚主のモンスター情報ID
2933 * @param y 中心生成位置y座標
2934 * @param x 中心生成位置x座標
2935 * @param r_idx 生成モンスター種族
2936 * @param mode 生成オプション
2939 static bool place_monster_group(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2941 monster_race *r_ptr = &r_info[r_idx];
2944 int total = 0, extra = 0;
2948 POSITION hack_y[GROUP_MAX];
2949 POSITION hack_x[GROUP_MAX];
2952 /* Pick a group size */
2953 total = randint1(10);
2955 /* Hard monsters, small groups */
2956 if (r_ptr->level > current_floor_ptr->dun_level)
2958 extra = r_ptr->level - current_floor_ptr->dun_level;
2959 extra = 0 - randint1(extra);
2962 /* Easy monsters, large groups */
2963 else if (r_ptr->level < current_floor_ptr->dun_level)
2965 extra = current_floor_ptr->dun_level - r_ptr->level;
2966 extra = randint1(extra);
2969 /* Hack -- limit group reduction */
2970 if (extra > 9) extra = 9;
2972 /* Modify the group size */
2976 if (total < 1) total = 1;
2979 if (total > GROUP_MAX) total = GROUP_MAX;
2982 /* Start on the monster */
2987 /* Puddle monsters, breadth first, up to total */
2988 for (n = 0; (n < hack_n) && (hack_n < total); n++)
2990 /* Grab the location */
2991 POSITION hx = hack_x[n];
2992 POSITION hy = hack_y[n];
2994 /* Check each direction, up to total */
2995 for (i = 0; (i < 8) && (hack_n < total); i++)
2999 scatter(&my, &mx, hy, hx, 4, 0);
3001 /* Walls and Monsters block flow */
3002 if (!cave_empty_bold2(my, mx)) continue;
3004 /* Attempt to place another monster */
3005 if (place_monster_one(who, my, mx, r_idx, mode))
3007 /* Add it to the "hack" set */
3008 hack_y[hack_n] = my;
3009 hack_x[hack_n] = mx;
3021 * @var place_monster_idx
3022 * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
3023 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
3025 static MONSTER_IDX place_monster_idx = 0;
3028 * @var place_monster_m_idx
3029 * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
3030 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
3032 static MONSTER_IDX place_monster_m_idx = 0;
3035 * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
3036 * @param r_idx チェックするモンスター種族のID
3037 * @return 護衛にできるならばtrue
3039 static bool place_monster_can_escort(MONRACE_IDX r_idx)
3041 monster_race *r_ptr = &r_info[place_monster_idx];
3042 monster_type *m_ptr = ¤t_floor_ptr->m_list[place_monster_m_idx];
3044 monster_race *z_ptr = &r_info[r_idx];
3046 /* Hack - Escorts have to have the same dungeon flag */
3047 if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return (FALSE);
3049 /* Require similar "race" */
3050 if (z_ptr->d_char != r_ptr->d_char) return (FALSE);
3052 /* Skip more advanced monsters */
3053 if (z_ptr->level > r_ptr->level) return (FALSE);
3055 /* Skip unique monsters */
3056 if (z_ptr->flags1 & RF1_UNIQUE) return (FALSE);
3058 /* Paranoia -- Skip identical monsters */
3059 if (place_monster_idx == r_idx) return (FALSE);
3061 /* Skip different alignment */
3062 if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3064 if (r_ptr->flags7 & RF7_FRIENDLY)
3066 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3069 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3077 * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
3078 * @param who 召喚主のモンスター情報ID
3081 * @param r_idx 生成するモンスターの種族ID
3082 * @param mode 生成オプション
3083 * @return 生成に成功したらtrue
3085 * Note that certain monsters are now marked as requiring "friends".
3086 * These monsters, if successfully placed, and if the "grp" parameter
3087 * is TRUE, will be surrounded by a "group" of identical monsters.
3089 * Note that certain monsters are now marked as requiring an "escort",
3090 * which is a collection of monsters with similar "race" but lower level.
3092 * Some monsters induce a fake "group" flag on their escorts.
3094 * Note the "bizarre" use of non-recursion to prevent annoying output
3095 * when running a code profiler.
3097 * Note the use of the new "monster allocation table" code to restrict
3098 * the "get_mon_num()" function to "legal" escort types.
3100 bool place_monster_aux(MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
3103 monster_race *r_ptr = &r_info[r_idx];
3105 if (!(mode & PM_NO_KAGE) && one_in_(333))
3108 /* Place one monster, or fail */
3109 if (!place_monster_one(who, y, x, r_idx, mode)) return (FALSE);
3111 /* Require the "group" flag */
3112 if (!(mode & PM_ALLOW_GROUP)) return (TRUE);
3114 place_monster_m_idx = hack_m_idx_ii;
3117 for(i = 0; i < 6; i++)
3119 if(!r_ptr->reinforce_id[i]) break;
3120 n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
3121 for(j = 0; j < n; j++)
3123 POSITION nx, ny, d = 7;
3124 scatter(&ny, &nx, y, x, d, 0);
3125 (void)place_monster_one(place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
3129 /* Friends for certain monsters */
3130 if (r_ptr->flags1 & (RF1_FRIENDS))
3132 /* Attempt to place a group */
3133 (void)place_monster_group(who, y, x, r_idx, mode);
3136 /* Escorts for certain monsters */
3137 if (r_ptr->flags1 & (RF1_ESCORT))
3139 /* Set the escort index */
3140 place_monster_idx = r_idx;
3142 /* Try to place several "escorts" */
3143 for (i = 0; i < 32; i++)
3145 POSITION nx, ny, d = 3;
3148 /* Pick a location */
3149 scatter(&ny, &nx, y, x, d, 0);
3151 /* Require empty grids */
3152 if (!cave_empty_bold2(ny, nx)) continue;
3153 get_mon_num_prep(place_monster_can_escort, get_monster_hook2(ny, nx));
3155 /* Pick a random race */
3156 z = get_mon_num(r_ptr->level);
3158 /* Handle failure */
3161 /* Place a single escort */
3162 (void)place_monster_one(place_monster_m_idx, ny, nx, z, mode);
3164 /* Place a "group" of escorts if needed */
3165 if ((r_info[z].flags1 & RF1_FRIENDS) ||
3166 (r_ptr->flags1 & RF1_ESCORTS))
3168 /* Place a group of monsters */
3169 (void)place_monster_group(place_monster_m_idx, ny, nx, z, mode);
3179 * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
3182 * @param mode 生成オプション
3183 * @return 生成に成功したらtrue
3185 bool place_monster(POSITION y, POSITION x, BIT_FLAGS mode)
3188 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3190 /* Pick a monster */
3191 r_idx = get_mon_num(current_floor_ptr->monster_level);
3193 /* Handle failure */
3194 if (!r_idx) return (FALSE);
3196 /* Attempt to place the monster */
3197 if (place_monster_aux(0, y, x, r_idx, mode)) return (TRUE);
3203 * @brief 指定地点に1種類のモンスター種族による群れを生成する
3206 * @return 生成に成功したらtrue
3208 bool alloc_horde(POSITION y, POSITION x)
3210 monster_race *r_ptr = NULL;
3211 MONRACE_IDX r_idx = 0;
3213 int attempts = 1000;
3216 get_mon_num_prep(get_monster_hook(), get_monster_hook2(y, x));
3220 /* Pick a monster */
3221 r_idx = get_mon_num(current_floor_ptr->monster_level);
3223 /* Handle failure */
3224 if (!r_idx) return (FALSE);
3226 r_ptr = &r_info[r_idx];
3228 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3230 if (r_idx == MON_HAGURE) continue;
3233 if (attempts < 1) return FALSE;
3239 /* Attempt to place the monster */
3240 if (place_monster_aux(0, y, x, r_idx, 0L)) break;
3243 if (attempts < 1) return FALSE;
3245 m_idx = current_floor_ptr->grid_array[y][x].m_idx;
3247 if (current_floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[current_floor_ptr->m_list[m_idx].r_idx];
3249 for (attempts = randint1(10) + 5; attempts; attempts--)
3251 scatter(&cy, &cx, y, x, 5, 0);
3253 (void)summon_specific(m_idx, cy, cx, current_floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP, r_ptr->d_char);
3259 if (cheat_hear) msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), r_ptr->d_char);
3264 * @brief ダンジョンの主生成を試みる / Put the Guardian
3265 * @param def_val 現在の主の生成状態
3266 * @return 生成に成功したらtrue
3268 bool alloc_guardian(bool def_val)
3270 MONRACE_IDX guardian = d_info[p_ptr->dungeon_idx].final_guardian;
3272 if (guardian && (d_info[p_ptr->dungeon_idx].maxdepth == current_floor_ptr->dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3276 int try_count = 4000;
3278 /* Find a good position */
3281 /* Get a random spot */
3282 oy = randint1(current_floor_ptr->height - 4) + 2;
3283 ox = randint1(current_floor_ptr->width - 4) + 2;
3285 /* Is it a good spot ? */
3286 if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(current_floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0))
3288 /* Place the guardian */
3289 if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3292 /* One less try count */
3304 * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
3305 * @param dis プレイヤーから離れるべき最低距離
3306 * @param mode 生成オプション
3307 * @return 生成に成功したらtrue
3309 * Place the monster at least "dis" distance from the player.
3310 * Use "slp" to choose the initial "sleep" status
3311 * Use "current_floor_ptr->monster_level" for the monster level
3313 bool alloc_monster(POSITION dis, BIT_FLAGS mode)
3315 POSITION y = 0, x = 0;
3316 int attempts_left = 10000;
3318 /* Put the Guardian */
3319 if (alloc_guardian(FALSE)) return TRUE;
3321 /* Find a legal, distant, unoccupied, space */
3322 while (attempts_left--)
3324 /* Pick a location */
3325 y = randint0(current_floor_ptr->height);
3326 x = randint0(current_floor_ptr->width);
3328 /* Require empty floor grid (was "naked") */
3329 if (current_floor_ptr->dun_level)
3331 if (!cave_empty_bold2(y, x)) continue;
3335 if (!cave_empty_bold(y, x)) continue;
3338 /* Accept far away grids */
3339 if (distance(y, x, p_ptr->y, p_ptr->x) > dis) break;
3344 if (cheat_xtra || cheat_hear)
3346 msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
3353 if (randint1(5000) <= current_floor_ptr->dun_level)
3355 if (alloc_horde(y, x))
3362 /* Attempt to place the monster, allow groups */
3363 if (place_monster(y, x, (mode | PM_ALLOW_GROUP))) return (TRUE);
3371 * @brief モンスターが召喚の基本条件に合っているかをチェックする / Hack -- help decide if a monster race is "okay" to summon
3372 * @param r_idx チェックするモンスター種族ID
3373 * @return 召喚対象にできるならばTRUE
3375 static bool summon_specific_okay(MONRACE_IDX r_idx)
3377 monster_race *r_ptr = &r_info[r_idx];
3379 /* Hack - Only summon dungeon monsters */
3380 if (!mon_hook_dungeon(r_idx)) return (FALSE);
3382 /* Hack -- identify the summoning monster */
3383 if (summon_specific_who > 0)
3385 monster_type *m_ptr = ¤t_floor_ptr->m_list[summon_specific_who];
3387 /* Do not summon enemies */
3389 /* Friendly vs. opposite aligned normal or pet */
3390 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3392 /* Use the player's alignment */
3393 else if (summon_specific_who < 0)
3395 /* Do not summon enemies of the pets */
3396 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3398 if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3402 if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
3404 /* Hack -- no specific type specified */
3405 if (!summon_specific_type) return (TRUE);
3407 if ((summon_specific_who < 0) &&
3408 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
3409 monster_has_hostile_align(NULL, 10, -10, r_ptr))
3412 if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON)) return TRUE;
3414 return (summon_specific_aux(r_idx));
3419 * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
3420 * @param who 召喚主のモンスター情報ID
3425 * @param mode 生成オプション
3426 * @return 召喚できたらtrueを返す
3429 * We will attempt to place the monster up to 10 times before giving up.
3431 * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3432 * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3433 * Note: None of the other summon codes will ever summon Unique's.
3435 * This function has been changed. We now take the "monster level"
3436 * of the summoning monster as a parameter, and use that, along with
3437 * the current dungeon level, to help determine the level of the
3438 * desired monster. Note that this is an upper bound, and also
3439 * tends to "prefer" monsters of that level. Currently, we use
3440 * the average of the dungeon and monster levels, and then add
3441 * five to allow slight increases in monster power.
3443 * Note that we use the new "monster allocation table" creation code
3444 * to restrict the "get_mon_num()" function to the set of "legal"
3445 * monsters, making this function much faster and more reliable.
3447 * Note that this function may not succeed, though this is very rare.
3449 bool summon_specific(MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode, SYMBOL_CODE symbol)
3454 if (p_ptr->inside_arena) return (FALSE);
3456 if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
3458 /* Save the summoner */
3459 summon_specific_who = who;
3461 /* Save the "summon" type */
3462 summon_specific_type = type;
3464 summon_kin_type = symbol;
3466 summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
3467 get_mon_num_prep(summon_specific_okay, get_monster_hook2(y, x));
3469 /* Pick a monster, using the level calculation */
3470 r_idx = get_mon_num((current_floor_ptr->dun_level + lev) / 2 + 5);
3472 /* Handle failure */
3475 summon_specific_type = 0;
3479 if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
3481 /* Attempt to place the monster (awake, allow groups) */
3482 if (!place_monster_aux(who, y, x, r_idx, mode))
3484 summon_specific_type = 0;
3488 summon_specific_type = 0;
3490 sound(SOUND_SUMMON);
3496 * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
3497 * @param who 召喚主のモンスター情報ID
3500 * @param r_idx 生成するモンスター種族ID
3501 * @param mode 生成オプション
3502 * @return 召喚できたらtrueを返す
3504 bool summon_named_creature(MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
3507 /* if (!r_idx) return; */
3509 /* Prevent illegal monsters */
3510 if (r_idx >= max_r_idx) return FALSE;
3512 if (p_ptr->inside_arena) return FALSE;
3514 if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
3516 /* Place it (allow groups) */
3517 return place_monster_aux(who, y, x, r_idx, (mode | PM_NO_KAGE));
3522 * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
3523 * @param m_idx 増殖するモンスター情報ID
3524 * @param clone クローン・モンスター処理ならばtrue
3525 * @param mode 生成オプション
3526 * @return 生成できたらtrueを返す
3528 * Note that "reproduction" REQUIRES empty space.
3530 bool multiply_monster(MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
3532 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
3535 if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
3538 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
3540 /* Create a new monster (awake, no groups) */
3541 if (!place_monster_aux(m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
3544 /* Hack -- Transfer "clone" flag */
3545 if (clone || (m_ptr->smart & SM_CLONED))
3547 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3548 current_floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
3557 * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
3558 * @param m_idx モンスター情報ID
3559 * @param dam 与えたダメージ
3562 * Technically should attempt to treat "Beholder"'s as jelly's
3564 void message_pain(MONSTER_IDX m_idx, HIT_POINT dam)
3566 HIT_POINT oldhp, newhp;
3568 PERCENTAGE percentage;
3570 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
3571 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3573 GAME_TEXT m_name[MAX_NLEN];
3575 monster_desc(m_name, m_ptr, 0);
3577 if(dam == 0) // Notice non-damage
3579 msg_format(_("%^sはダメージを受けていない。", "%^s is unharmed."), m_name);
3583 /* Note -- subtle fix -CFT */
3585 oldhp = newhp + dam;
3586 tmp = (newhp * 100L) / oldhp;
3589 if(my_strchr(",ejmvwQ", r_ptr->d_char)) // Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs
3592 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3593 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
3594 else if(percentage > 50) msg_format("%^sは縮こまった。", m_name);
3595 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3596 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
3597 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3598 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3600 if(percentage > 95) msg_format("%^s barely notices.", m_name);
3601 else if(percentage > 75) msg_format("%^s flinches.", m_name);
3602 else if(percentage > 50) msg_format("%^s squelches.", m_name);
3603 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
3604 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
3605 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3606 else msg_format("%^s jerks limply.", m_name);
3610 else if(my_strchr("l", r_ptr->d_char)) // Fish
3613 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3614 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
3615 else if(percentage > 50) msg_format("%^sは躊躇した。", m_name);
3616 else if(percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3617 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
3618 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3619 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3621 if(percentage > 95) msg_format("%^s barely notices.", m_name);
3622 else if(percentage > 75) msg_format("%^s flinches.", m_name);
3623 else if(percentage > 50) msg_format("%^s hesitates.", m_name);
3624 else if(percentage > 35) msg_format("%^s quivers in pain.", m_name);
3625 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
3626 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3627 else msg_format("%^s jerks limply.", m_name);
3631 else if(my_strchr("g#+<>", r_ptr->d_char)) // Golems, Walls, Doors, Stairs
3634 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3635 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3636 else if(percentage > 50) msg_format("%^sは雷鳴のように吠えた。", m_name);
3637 else if(percentage > 35) msg_format("%^sは苦しげに吠えた。", m_name);
3638 else if(percentage > 20) msg_format("%^sはうめいた。", m_name);
3639 else if(percentage > 10) msg_format("%^sは躊躇した。", m_name);
3640 else msg_format("%^sはくしゃくしゃになった。", m_name);
3642 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3643 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3644 else if(percentage > 50) msg_format("%^s roars thunderously.", m_name);
3645 else if(percentage > 35) msg_format("%^s rumbles.", m_name);
3646 else if(percentage > 20) msg_format("%^s grunts.", m_name);
3647 else if(percentage > 10) msg_format("%^s hesitates.", m_name);
3648 else msg_format("%^s crumples.", m_name);
3652 else if(my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) // Snakes, Hydrae, Reptiles, Mimics
3655 if(percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3656 else if(percentage > 75) msg_format("%^sはシーッと鳴いた。", m_name);
3657 else if(percentage > 50) msg_format("%^sは怒って頭を上げた。", m_name);
3658 else if(percentage > 35) msg_format("%^sは猛然と威嚇した。", m_name);
3659 else if(percentage > 20) msg_format("%^sは身もだえした。", m_name);
3660 else if(percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3661 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3663 if(percentage > 95) msg_format("%^s barely notices.", m_name);
3664 else if(percentage > 75) msg_format("%^s hisses.", m_name);
3665 else if(percentage > 50) msg_format("%^s rears up in anger.", m_name);
3666 else if(percentage > 35) msg_format("%^s hisses furiously.", m_name);
3667 else if(percentage > 20) msg_format("%^s writhes about.", m_name);
3668 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3669 else msg_format("%^s jerks limply.", m_name);
3673 else if(my_strchr("f", r_ptr->d_char))
3676 if(percentage > 95) msg_format("%sは攻撃に肩をすくめた。", m_name);
3677 else if(percentage > 75) msg_format("%^sは吠えた。", m_name);
3678 else if(percentage > 50) msg_format("%^sは怒って吠えた。", m_name);
3679 else if(percentage > 35) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3680 else if(percentage > 20) msg_format("%^sは痛みで弱々しく鳴いた。", m_name);
3681 else if(percentage > 10) msg_format("%^sは苦痛にうめいた。", m_name);
3682 else msg_format("%sは哀れな鳴き声を出した。", m_name);
3684 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3685 else if(percentage > 75) msg_format("%^s roars.", m_name);
3686 else if(percentage > 50) msg_format("%^s growls angrily.", m_name);
3687 else if(percentage > 35) msg_format("%^s hisses with pain.", m_name);
3688 else if(percentage > 20) msg_format("%^s mewls in pain.", m_name);
3689 else if(percentage > 10) msg_format("%^s hisses in agony.", m_name);
3690 else msg_format("%^s mewls pitifully.", m_name);
3694 else if(my_strchr("acFIKS", r_ptr->d_char)) // Ants, Centipedes, Flies, Insects, Beetles, Spiders
3697 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3698 else if(percentage > 75) msg_format("%^sはキーキー鳴いた。", m_name);
3699 else if(percentage > 50) msg_format("%^sはヨロヨロ逃げ回った。", m_name);
3700 else if(percentage > 35) msg_format("%^sはうるさく鳴いた。", m_name);
3701 else if(percentage > 20) msg_format("%^sは痛みに痙攣した。", m_name);
3702 else if(percentage > 10) msg_format("%^sは苦痛で痙攣した。", m_name);
3703 else msg_format("%^sはピクピクひきつった。", m_name);
3705 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3706 else if(percentage > 75) msg_format("%^s chitters.", m_name);
3707 else if(percentage > 50) msg_format("%^s scuttles about.", m_name);
3708 else if(percentage > 35) msg_format("%^s twitters.", m_name);
3709 else if(percentage > 20) msg_format("%^s jerks in pain.", m_name);
3710 else if(percentage > 10) msg_format("%^s jerks in agony.", m_name);
3711 else msg_format("%^s twitches.", m_name);
3715 else if(my_strchr("B", r_ptr->d_char)) // Birds
3718 if(percentage > 95) msg_format("%^sはさえずった。", m_name);
3719 else if(percentage > 75) msg_format("%^sはピーピー鳴いた。", m_name);
3720 else if(percentage > 50) msg_format("%^sはギャーギャー鳴いた。", m_name);
3721 else if(percentage > 35) msg_format("%^sはギャーギャー鳴きわめいた。", m_name);
3722 else if(percentage > 20) msg_format("%^sは苦しんだ。", m_name);
3723 else if(percentage > 10) msg_format("%^sはのたうち回った。", m_name);
3724 else msg_format("%^sはキーキーと鳴き叫んだ。", m_name);
3726 if(percentage > 95) msg_format("%^s chirps.", m_name);
3727 else if(percentage > 75) msg_format("%^s twitters.", m_name);
3728 else if(percentage > 50) msg_format("%^s squawks.", m_name);
3729 else if(percentage > 35) msg_format("%^s chatters.", m_name);
3730 else if(percentage > 20) msg_format("%^s jeers.", m_name);
3731 else if(percentage > 10) msg_format("%^s flutters about.", m_name);
3732 else msg_format("%^s squeaks.", m_name);
3736 else if(my_strchr("duDLUW", r_ptr->d_char)) // Dragons, Demons, High Undead
3739 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3740 else if(percentage > 75) msg_format("%^sはしり込みした。", m_name);
3741 else if(percentage > 50) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3742 else if(percentage > 35) msg_format("%^sは痛みでうなった。", m_name);
3743 else if(percentage > 20) msg_format("%^sは痛みに吠えた。", m_name);
3744 else if(percentage > 10) msg_format("%^sは苦しげに叫んだ。", m_name);
3745 else msg_format("%^sは弱々しくうなった。", m_name);
3747 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3748 else if(percentage > 75) msg_format("%^s flinches.", m_name);
3749 else if(percentage > 50) msg_format("%^s hisses in pain.", m_name);
3750 else if(percentage > 35) msg_format("%^s snarls with pain.", m_name);
3751 else if(percentage > 20) msg_format("%^s roars with pain.", m_name);
3752 else if(percentage > 10) msg_format("%^s gasps.", m_name);
3753 else msg_format("%^s snarls feebly.", m_name);
3757 else if(my_strchr("s", r_ptr->d_char)) // Skeletons
3760 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3761 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3762 else if(percentage > 50) msg_format("%^sはカタカタと笑った。", m_name);
3763 else if(percentage > 35) msg_format("%^sはよろめいた。", m_name);
3764 else if(percentage > 20) msg_format("%^sはカタカタ言った。", m_name);
3765 else if(percentage > 10) msg_format("%^sはよろめいた。", m_name);
3766 else msg_format("%^sはガタガタ言った。", m_name);
3768 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3769 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3770 else if(percentage > 50) msg_format("%^s rattles.", m_name);
3771 else if(percentage > 35) msg_format("%^s stumbles.", m_name);
3772 else if(percentage > 20) msg_format("%^s rattles.", m_name);
3773 else if(percentage > 10) msg_format("%^s staggers.", m_name);
3774 else msg_format("%^s clatters.", m_name);
3778 else if(my_strchr("z", r_ptr->d_char)) // Zombies
3781 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3782 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3783 else if(percentage > 50) msg_format("%^sはうめいた。", m_name);
3784 else if(percentage > 35) msg_format("%sは苦しげにうめいた。", m_name);
3785 else if(percentage > 20) msg_format("%^sは躊躇した。", m_name);
3786 else if(percentage > 10) msg_format("%^sはうなった。", m_name);
3787 else msg_format("%^sはよろめいた。", m_name);
3789 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3790 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3791 else if(percentage > 50) msg_format("%^s groans.", m_name);
3792 else if(percentage > 35) msg_format("%^s moans.", m_name);
3793 else if(percentage > 20) msg_format("%^s hesitates.", m_name);
3794 else if(percentage > 10) msg_format("%^s grunts.", m_name);
3795 else msg_format("%^s staggers.", m_name);
3799 else if(my_strchr("G", r_ptr->d_char)) // Ghosts
3802 if(percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3803 else if(percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3804 else if(percentage > 50) msg_format("%sはうめいた。", m_name);
3805 else if(percentage > 35) msg_format("%^sは泣きわめいた。", m_name);
3806 else if(percentage > 20) msg_format("%^sは吠えた。", m_name);
3807 else if(percentage > 10) msg_format("%sは弱々しくうめいた。", m_name);
3808 else msg_format("%^sはかすかにうめいた。", m_name);
3810 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3811 else if(percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3812 else if(percentage > 50) msg_format("%^s moans.", m_name);
3813 else if(percentage > 35) msg_format("%^s wails.", m_name);
3814 else if(percentage > 20) msg_format("%^s howls.", m_name);
3815 else if(percentage > 10) msg_format("%^s moans softly.", m_name);
3816 else msg_format("%^s sighs.", m_name);
3820 else if(my_strchr("CZ", r_ptr->d_char)) // Dogs and Hounds
3823 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3824 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3825 else if(percentage > 50) msg_format("%^sは痛みでキャンキャン吠えた。", m_name);
3826 else if(percentage > 35) msg_format("%^sは痛みで鳴きわめいた。", m_name);
3827 else if(percentage > 20) msg_format("%^sは苦痛のあまり鳴きわめいた。", m_name);
3828 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3829 else msg_format("%^sは弱々しく吠えた。", m_name);
3831 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3832 else if(percentage > 75) msg_format("%^s snarls with pain.", m_name);
3833 else if(percentage > 50) msg_format("%^s yelps in pain.", m_name);
3834 else if(percentage > 35) msg_format("%^s howls in pain.", m_name);
3835 else if(percentage > 20) msg_format("%^s howls in agony.", m_name);
3836 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3837 else msg_format("%^s yelps feebly.", m_name);
3841 else if(my_strchr("Xbilqrt", r_ptr->d_char)) // One type of creatures (ignore,squeal,shriek)
3844 if(percentage > 95) msg_format("%^sは攻撃を気にとめていない。", m_name);
3845 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3846 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3847 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3848 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3849 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3850 else msg_format("%^sは弱々しく叫んだ。", m_name);
3852 if(percentage > 95) msg_format("%^s ignores the attack.", m_name);
3853 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
3854 else if(percentage > 50) msg_format("%^s squeals in pain.", m_name);
3855 else if(percentage > 35) msg_format("%^s shrieks in pain.", m_name);
3856 else if(percentage > 20) msg_format("%^s shrieks in agony.", m_name);
3857 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3858 else msg_format("%^s cries out feebly.", m_name);
3862 else // Another type of creatures (shrug,cry,scream)
3865 if(percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3866 else if(percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3867 else if(percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3868 else if(percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3869 else if(percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3870 else if(percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3871 else msg_format("%^sは弱々しく叫んだ。", m_name);
3873 if(percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3874 else if(percentage > 75) msg_format("%^s grunts with pain.", m_name);
3875 else if(percentage > 50) msg_format("%^s cries out in pain.", m_name);
3876 else if(percentage > 35) msg_format("%^s screams in pain.", m_name);
3877 else if(percentage > 20) msg_format("%^s screams in agony.", m_name);
3878 else if(percentage > 10) msg_format("%^s writhes in agony.", m_name);
3879 else msg_format("%^s cries out feebly.", m_name);
3887 * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance.
3888 * @param m_idx 更新を行う「モンスター情報ID
3889 * @param what 学習対象ID
3892 void update_smart_learn(MONSTER_IDX m_idx, int what)
3894 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
3895 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3897 /* Not allowed to learn */
3898 if (!smart_learn) return;
3900 /* Too stupid to learn anything */
3901 if (r_ptr->flags2 & (RF2_STUPID)) return;
3903 /* Not intelligent, only learn sometimes */
3904 if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
3906 /* Analyze the knowledge */
3910 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
3911 if (IS_OPPOSE_ACID()) m_ptr->smart |= (SM_OPP_ACID);
3912 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
3916 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
3917 if (IS_OPPOSE_ELEC()) m_ptr->smart |= (SM_OPP_ELEC);
3918 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
3922 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
3923 if (IS_OPPOSE_FIRE()) m_ptr->smart |= (SM_OPP_FIRE);
3924 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
3928 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
3929 if (IS_OPPOSE_COLD()) m_ptr->smart |= (SM_OPP_COLD);
3930 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
3934 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
3935 if (IS_OPPOSE_POIS()) m_ptr->smart |= (SM_OPP_POIS);
3940 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
3944 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
3948 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
3952 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
3956 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
3960 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
3964 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
3968 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
3972 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
3976 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
3980 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
3984 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
3988 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
3992 if (p_ptr->reflect) m_ptr-> smart |= (SM_IMM_REFLECT);
3999 * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster
4000 * @param m_ptr モンスター参照ポインタ
4003 void monster_drop_carried_objects(monster_type *m_ptr)
4005 OBJECT_IDX this_o_idx, next_o_idx = 0;
4011 /* Drop objects being carried */
4012 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4014 o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
4015 next_o_idx = o_ptr->next_o_idx;
4018 /* Copy the object */
4019 object_copy(q_ptr, o_ptr);
4021 /* Forget monster */
4022 q_ptr->held_m_idx = 0;
4024 delete_object_idx(this_o_idx);
4027 (void)drop_near(q_ptr, -1, m_ptr->fy, m_ptr->fx);
4030 /* Forget objects */
4031 m_ptr->hold_o_idx = 0;