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.
21 #include "object-flavor.h"
22 #include "monsterrace-hook.h"
23 #include "monster-status.h"
26 #include "spells-summon.h"
29 #include "player-move.h"
30 #include "player-status.h"
31 #include "player-race.h"
32 #include "player-class.h"
33 #include "player-personality.h"
36 #include "monster-spell.h"
38 #include "view-mainwindow.h"
40 #include "monsterrace.h"
42 #include "targeting.h"
43 #include "realm-song.h"
46 #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */
47 #define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */
49 MONSTER_IDX hack_m_idx = 0; /* Hack -- see "process_monsters()" */
50 MONSTER_IDX hack_m_idx_ii = 0;
52 bool is_friendly_idx(player_type *player_ptr, MONSTER_IDX m_idx);
55 * @brief モンスターの目標地点をセットする / Set the target of counter attack
56 * @param m_ptr モンスターの参照ポインタ
61 void set_target(monster_type *m_ptr, POSITION y, POSITION x)
69 * @brief モンスターの目標地点をリセットする / Reset the target of counter attack
70 * @param m_ptr モンスターの参照ポインタ
73 void reset_target(monster_type *m_ptr)
75 set_target(m_ptr, 0, 0);
80 * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form
81 * @param m_ptr モンスターの参照ポインタ
82 * @return 本当のモンスター種族参照ポインタ
84 monster_race *real_r_ptr(monster_type *m_ptr)
86 return &r_info[real_r_idx(m_ptr)];
89 MONRACE_IDX real_r_idx(monster_type *m_ptr)
91 monster_race *r_ptr = &r_info[m_ptr->r_idx];
93 /* Extract real race */
94 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
96 if (r_ptr->flags1 & RF1_UNIQUE)
97 return MON_CHAMELEON_K;
109 * @brief モンスター配列からモンスターを消去する / Delete a monster by index.
110 * @param i 消去するモンスターのID
113 * モンスターを削除するとそのモンスターが拾っていたアイテムも同時に削除される。 /
114 * When a monster is deleted, all of its objects are deleted.
116 void delete_monster_idx(MONSTER_IDX i)
119 floor_type *floor_ptr = p_ptr->current_floor_ptr;
120 monster_type *m_ptr = &floor_ptr->m_list[i];
121 monster_race *r_ptr = &r_info[m_ptr->r_idx];
122 OBJECT_IDX this_o_idx, next_o_idx = 0;
127 /* Hack -- Reduce the racial counter */
128 real_r_ptr(m_ptr)->cur_num--;
130 /* Hack -- count the number of "reproducers" */
131 if (r_ptr->flags2 & (RF2_MULTIPLY)) floor_ptr->num_repro--;
133 if (MON_CSLEEP(m_ptr)) (void)set_monster_csleep(p_ptr, i, 0);
134 if (MON_FAST(m_ptr)) (void)set_monster_fast(p_ptr, i, 0);
135 if (MON_SLOW(m_ptr)) (void)set_monster_slow(p_ptr, i, 0);
136 if (MON_STUNNED(m_ptr)) (void)set_monster_stunned(p_ptr, i, 0);
137 if (MON_CONFUSED(m_ptr)) (void)set_monster_confused(p_ptr, i, 0);
138 if (MON_MONFEAR(m_ptr)) (void)set_monster_monfear(p_ptr, i, 0);
139 if (MON_INVULNER(m_ptr)) (void)set_monster_invulner(p_ptr, i, 0, FALSE);
141 /* Hack -- remove target monster */
142 if (i == target_who) target_who = 0;
144 /* Hack -- remove tracked monster */
145 if (i == p_ptr->health_who) health_track(p_ptr, 0);
147 if (p_ptr->pet_t_m_idx == i) p_ptr->pet_t_m_idx = 0;
148 if (p_ptr->riding_t_m_idx == i) p_ptr->riding_t_m_idx = 0;
149 if (p_ptr->riding == i) p_ptr->riding = 0;
151 /* Monster is gone */
152 floor_ptr->grid_array[y][x].m_idx = 0;
154 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
157 o_ptr = &floor_ptr->o_list[this_o_idx];
158 next_o_idx = o_ptr->next_o_idx;
161 * o_ptr->held_m_idx is needed in delete_object_idx()
162 * to prevent calling lite_spot()
165 delete_object_idx(floor_ptr, this_o_idx);
168 (void)WIPE(m_ptr, monster_type);
174 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
176 p_ptr->update |= (PU_MON_LITE);
182 * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
183 * @param player_ptr プレーヤーへの参照ポインタ
188 static void compact_monsters_aux(player_type *player_ptr, MONSTER_IDX i1, MONSTER_IDX i2)
194 OBJECT_IDX this_o_idx, next_o_idx = 0;
197 if (i1 == i2) return;
200 floor_type *floor_ptr = player_ptr->current_floor_ptr;
201 m_ptr = &floor_ptr->m_list[i1];
207 g_ptr = &floor_ptr->grid_array[y][x];
211 /* Repair objects being carried by monster */
212 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
215 o_ptr = &floor_ptr->o_list[this_o_idx];
216 next_o_idx = o_ptr->next_o_idx;
218 /* Reset monster pointer */
219 o_ptr->held_m_idx = i2;
222 /* Hack -- Update the target */
223 if (target_who == i1) target_who = i2;
225 /* Hack -- Update the target */
226 if (player_ptr->pet_t_m_idx == i1) player_ptr->pet_t_m_idx = i2;
227 if (player_ptr->riding_t_m_idx == i1) player_ptr->riding_t_m_idx = i2;
229 /* Hack -- Update the riding */
230 if (player_ptr->riding == i1) player_ptr->riding = i2;
232 /* Hack -- Update the health bar */
233 if (player_ptr->health_who == i1) health_track(player_ptr, i2);
235 /* Hack -- Update parent index */
238 for (i = 1; i < floor_ptr->m_max; i++)
240 monster_type *m2_ptr = &floor_ptr->m_list[i];
242 if (m2_ptr->parent_m_idx == i1)
243 m2_ptr->parent_m_idx = i2;
248 (void)COPY(&floor_ptr->m_list[i2], &floor_ptr->m_list[i1], monster_type);
251 (void)WIPE(&floor_ptr->m_list[i1], monster_type);
253 for (i = 0; i < MAX_MTIMED; i++)
255 int mproc_idx = get_mproc_idx(floor_ptr, i1, i);
256 if (mproc_idx >= 0) floor_ptr->mproc_list[i][mproc_idx] = i2;
262 * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
263 * @param player_ptr プレーヤーへの参照ポインタ
264 * @param size 圧縮後のモンスター件数目標
267 * This function can be very dangerous, use with caution!
269 * When actually "compacting" monsters, we base the saving throw
270 * on a combination of monster level, distance from player, and
271 * current "desperation".
273 * After "compacting" (if needed), we "reorder" the monsters into a more
274 * compact order, and we reset the allocation info, and the "live" array.
276 void compact_monsters(player_type *player_ptr, int size)
280 int cur_lev, cur_dis, chance;
282 /* Message (only if compacting) */
283 if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
285 /* Compact at least 'size' objects */
286 floor_type *floor_ptr = player_ptr->current_floor_ptr;
287 for (num = 0, cnt = 1; num < size; cnt++)
289 /* Get more vicious each iteration */
292 /* Get closer each iteration */
293 cur_dis = 5 * (20 - cnt);
295 /* Check all the monsters */
296 for (i = 1; i < floor_ptr->m_max; i++)
298 monster_type *m_ptr = &floor_ptr->m_list[i];
300 monster_race *r_ptr = &r_info[m_ptr->r_idx];
302 /* Paranoia -- skip "dead" monsters */
303 if (!monster_is_valid(m_ptr)) continue;
305 /* Hack -- High level monsters start out "immune" */
306 if (r_ptr->level > cur_lev) continue;
308 if (i == player_ptr->riding) continue;
310 /* Ignore nearby monsters */
311 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
313 /* Saving throw chance */
316 /* Only compact "Quest" Monsters in emergencies */
317 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
319 /* Try not to compact Unique Monsters */
320 if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
322 /* All monsters get a saving throw */
323 if (randint0(100) < chance) continue;
325 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
327 GAME_TEXT m_name[MAX_NLEN];
328 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
329 exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
332 delete_monster_idx(i);
334 /* Count the monster */
340 /* Excise dead monsters (backwards!) */
341 for (i = floor_ptr->m_max - 1; i >= 1; i--)
343 /* Get the i'th monster */
344 monster_type *m_ptr = &floor_ptr->m_list[i];
346 /* Skip real monsters */
347 if (m_ptr->r_idx) continue;
349 /* Move last monster into open hole */
350 compact_monsters_aux(player_ptr, floor_ptr->m_max - 1, i);
352 /* Compress "floor_ptr->m_max" */
359 * @brief プレイヤーのフロア離脱に伴う全モンスター配列の消去 / Delete/Remove all the monsters when the player leaves the level
362 * This is an efficient method of simulating multiple calls to the
363 * "delete_monster()" function, with no visual effects.
365 void wipe_m_list(void)
369 /* Hack -- if Banor or Lupart dies, stay another dead */
370 if (!r_info[MON_BANORLUPART].max_num)
372 if (r_info[MON_BANOR].max_num)
374 r_info[MON_BANOR].max_num = 0;
375 r_info[MON_BANOR].r_pkills++;
376 r_info[MON_BANOR].r_akills++;
377 if (r_info[MON_BANOR].r_tkills < MAX_SHORT) r_info[MON_BANOR].r_tkills++;
379 if (r_info[MON_LUPART].max_num)
381 r_info[MON_LUPART].max_num = 0;
382 r_info[MON_LUPART].r_pkills++;
383 r_info[MON_LUPART].r_akills++;
384 if (r_info[MON_LUPART].r_tkills < MAX_SHORT) r_info[MON_LUPART].r_tkills++;
388 /* Delete all the monsters */
389 floor_type *floor_ptr = p_ptr->current_floor_ptr;
390 for (i = floor_ptr->m_max - 1; i >= 1; i--)
392 monster_type *m_ptr = &floor_ptr->m_list[i];
393 if (!monster_is_valid(m_ptr)) continue;
395 /* Monster is gone */
396 floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx = 0;
398 (void)WIPE(m_ptr, monster_type);
403 * Wiping racial counters of all monsters and incrementing of racial
404 * counters of monsters in party_mon[] are required to prevent multiple
405 * generation of unique monster who is the minion of player.
408 /* Hack -- Wipe the racial counter of all monster races */
409 for (i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
411 /* Reset "floor_ptr->m_max" */
412 floor_ptr->m_max = 1;
414 /* Reset "floor_ptr->m_cnt" */
415 floor_ptr->m_cnt = 0;
417 /* Reset "floor_ptr->mproc_max[]" */
418 for (i = 0; i < MAX_MTIMED; i++) floor_ptr->mproc_max[i] = 0;
420 /* Hack -- reset "reproducer" count */
421 floor_ptr->num_repro = 0;
423 /* Hack -- no more target */
425 p_ptr->pet_t_m_idx = 0;
426 p_ptr->riding_t_m_idx = 0;
428 health_track(p_ptr, 0);
433 * @brief モンスター配列の空きを探す / Acquires and returns the index of a "free" monster.
434 * @return 利用可能なモンスター配列の添字
436 * This routine should almost never fail, but it *can* happen.
438 MONSTER_IDX m_pop(void)
442 /* Normal allocation */
443 floor_type *floor_ptr = p_ptr->current_floor_ptr;
444 if (floor_ptr->m_max < current_world_ptr->max_m_idx)
446 /* Access the next hole */
447 i = floor_ptr->m_max;
449 /* Expand the array */
455 /* Return the index */
459 /* Recycle dead monsters */
460 for (i = 1; i < floor_ptr->m_max; i++)
463 m_ptr = &floor_ptr->m_list[i];
465 /* Skip live monsters */
466 if (m_ptr->r_idx) continue;
471 /* Use this monster */
475 /* Warn the player (except during dungeon creation) */
476 if (current_world_ptr->character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
478 /* Try not to crash */
486 * @var summon_specific_type
487 * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
488 * @todo summon_specific_typeグローバル変数の除去と関数引数への代替を行う
490 static int summon_specific_type = 0;
494 * @var summon_specific_who
495 * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
496 * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
498 static int summon_specific_who = -1;
501 * @var summon_unique_okay
502 * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
503 * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
505 static bool summon_unique_okay = FALSE;
508 * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
509 * @return 召喚条件が一致するならtrue
512 static bool summon_specific_aux(MONRACE_IDX summoner_idx, MONRACE_IDX r_idx)
514 monster_race *r_ptr = &r_info[r_idx];
517 /* Check our requirements */
518 switch (summon_specific_type)
522 okay = (r_ptr->d_char == 'a');
528 okay = (r_ptr->d_char == 'S');
534 okay = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
540 okay = (r_ptr->d_char == 'M');
546 okay = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
552 okay = (r_ptr->flags3 & RF3_DEMON);
558 okay = (r_ptr->flags3 & RF3_UNDEAD);
564 okay = (r_ptr->flags3 & RF3_DRAGON);
568 case SUMMON_HI_UNDEAD:
570 okay = ((r_ptr->d_char == 'L') ||
571 (r_ptr->d_char == 'V') ||
572 (r_ptr->d_char == 'W'));
576 case SUMMON_HI_DRAGON:
578 okay = (r_ptr->d_char == 'D');
582 case SUMMON_HI_DEMON:
584 okay = (((r_ptr->d_char == 'U') ||
585 (r_ptr->d_char == 'H') ||
586 (r_ptr->d_char == 'B')) &&
587 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
591 case SUMMON_AMBERITES:
593 okay = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
599 okay = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
605 okay = (r_ptr->d_char == 'm');
610 okay = (r_ptr->d_char == 'b');
613 case SUMMON_QUYLTHULG:
615 okay = (r_ptr->d_char == 'Q');
619 case SUMMON_COIN_MIMIC:
621 okay = (r_ptr->d_char == '$');
627 okay = ((r_ptr->d_char == '!') ||
628 (r_ptr->d_char == '?') ||
629 (r_ptr->d_char == '=') ||
630 (r_ptr->d_char == '$') ||
631 (r_ptr->d_char == '|'));
637 okay = (r_ptr->d_char == 'g');
643 okay = ((r_ptr->d_char == 'U') &&
644 (r_ptr->flags4 & RF4_ROCKET));
650 SYMBOL_CODE summon_kin_type;
653 summon_kin_type = r_info[summoner_idx].d_char;
657 summon_kin_type = get_summon_symbol_from_player(p_ptr);
660 okay = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
666 okay = (r_idx == MON_DAWN);
672 okay = (r_ptr->flags3 & (RF3_ANIMAL));
676 case SUMMON_ANIMAL_RANGER:
678 okay = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
679 (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
680 !(r_ptr->flags3 & (RF3_DRAGON)) &&
681 !(r_ptr->flags3 & (RF3_EVIL)) &&
682 !(r_ptr->flags3 & (RF3_UNDEAD)) &&
683 !(r_ptr->flags3 & (RF3_DEMON)) &&
684 !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
685 !(r_ptr->flags4 || r_ptr->a_ability_flags1 || r_ptr->a_ability_flags2));
689 case SUMMON_HI_DRAGON_LIVING:
691 okay = ((r_ptr->d_char == 'D') && monster_living(r_idx));
697 okay = monster_living(r_idx);
703 okay = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
707 case SUMMON_BLUE_HORROR:
709 okay = (r_idx == MON_BLUE_HORROR);
713 case SUMMON_ELEMENTAL:
715 okay = (r_ptr->d_char == 'E');
721 okay = (r_ptr->d_char == 'v');
727 okay = (r_ptr->d_char == 'H');
733 okay = (r_ptr->d_char == 'B');
737 case SUMMON_KAMIKAZE:
740 for (i = 0; i < 4; i++)
741 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
745 case SUMMON_KAMIKAZE_LIVING:
749 for (i = 0; i < 4; i++)
750 if (r_ptr->blow[i].method == RBM_EXPLODE) okay = TRUE;
751 okay = (okay && monster_living(r_idx));
757 okay = (r_idx == MON_MANES);
763 okay = (r_idx == MON_LOUSE);
767 case SUMMON_GUARDIANS:
769 okay = (r_ptr->flags7 & RF7_GUARDIAN);
775 okay = ((r_idx == MON_NOV_PALADIN) ||
776 (r_idx == MON_NOV_PALADIN_G) ||
777 (r_idx == MON_PALADIN) ||
778 (r_idx == MON_W_KNIGHT) ||
779 (r_idx == MON_ULTRA_PALADIN) ||
780 (r_idx == MON_KNI_TEMPLAR));
786 okay = (r_ptr->d_char == 'B' &&
787 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
788 (r_ptr->flags8 & RF8_WILD_ONLY));
792 case SUMMON_PIRANHAS:
794 okay = (r_idx == MON_PIRANHA);
798 case SUMMON_ARMAGE_GOOD:
800 okay = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
804 case SUMMON_ARMAGE_EVIL:
806 okay = ((r_ptr->flags3 & RF3_DEMON) ||
807 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
811 /* Since okay is int, "return (okay);" is not correct. */
812 return (bool)(okay ? TRUE : FALSE);
816 * @var chameleon_change_m_idx
817 * @brief カメレオンの変身先モンスターIDを受け渡すためのグローバル変数
818 * @todo 変数渡しの問題などもあるができればchameleon_change_m_idxのグローバル変数を除去し、関数引き渡しに移行すること
820 static int chameleon_change_m_idx = 0;
824 * @brief 指定されたモンスター種族がダンジョンの制限にかかるかどうかをチェックする / Some dungeon types restrict the possible monsters.
825 * @param r_idx チェックするモンスター種族ID
826 * @return 召喚条件が一致するならtrue / Return TRUE is the monster is OK and FALSE otherwise
828 static bool restrict_monster_to_dungeon(DUNGEON_IDX d_idx, MONRACE_IDX r_idx)
830 dungeon_type *d_ptr = &d_info[d_idx];
831 monster_race *r_ptr = &r_info[r_idx];
834 if (d_ptr->flags1 & DF1_CHAMELEON)
836 if (chameleon_change_m_idx) return TRUE;
839 if (d_ptr->flags1 & DF1_NO_MAGIC)
841 if (r_idx != MON_CHAMELEON &&
843 !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
844 !(r_ptr->a_ability_flags1 & RF5_NOMAGIC_MASK) &&
845 !(r_ptr->a_ability_flags2 & RF6_NOMAGIC_MASK))
849 if (d_ptr->flags1 & DF1_NO_MELEE)
851 if (r_idx == MON_CHAMELEON) return TRUE;
852 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
853 !(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)) &&
854 !(r_ptr->a_ability_flags2 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
858 floor_type *floor_ptr = p_ptr->current_floor_ptr;
859 if (d_ptr->flags1 & DF1_BEGINNER)
861 if (r_ptr->level > floor_ptr->dun_level)
865 if (d_ptr->special_div >= 64) return TRUE;
866 if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
870 case DUNGEON_MODE_AND:
873 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
878 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
883 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
888 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
891 if (d_ptr->m_a_ability_flags1)
893 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
896 if (d_ptr->m_a_ability_flags2)
898 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
903 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
908 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
913 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
918 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
921 for (a = 0; a < 5; a++)
922 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
926 case DUNGEON_MODE_NAND:
929 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
934 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
939 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
944 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
947 if (d_ptr->m_a_ability_flags1)
949 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
952 if (d_ptr->m_a_ability_flags2)
954 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
959 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
964 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
969 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
974 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
977 for (a = 0; a < 5; a++)
978 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
982 case DUNGEON_MODE_OR:
983 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
984 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
985 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
986 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
987 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return TRUE;
988 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return TRUE;
989 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
990 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
991 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
992 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
993 for (a = 0; a < 5; a++)
994 if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
998 case DUNGEON_MODE_NOR:
999 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
1000 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
1001 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
1002 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
1003 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return FALSE;
1004 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return FALSE;
1005 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
1006 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
1007 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
1008 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
1009 for (a = 0; a < 5; a++)
1010 if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1019 * Hack -- function hooks to restrict "get_mon_num_prep()" function
1021 monsterrace_hook_type get_mon_num_hook;
1022 monsterrace_hook_type get_mon_num2_hook;
1025 * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
1026 * @param monster_hook 制限関数1
1027 * @param monster_hook2 制限関数2
1030 errr get_mon_num_prep(monsterrace_hook_type monster_hook,
1031 monsterrace_hook_type monster_hook2)
1035 /* Todo: Check the hooks for non-changes */
1037 /* Set the new hooks */
1038 get_mon_num_hook = monster_hook;
1039 get_mon_num2_hook = monster_hook2;
1041 /* Scan the allocation table */
1042 floor_type *floor_ptr = p_ptr->current_floor_ptr;
1043 for (i = 0; i < alloc_race_size; i++)
1045 monster_race *r_ptr;
1048 alloc_entry *entry = &alloc_race_table[i];
1051 r_ptr = &r_info[entry->index];
1053 /* Skip monsters which don't pass the restriction */
1054 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1055 (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1058 if (!p_ptr->phase_out && !chameleon_change_m_idx &&
1059 summon_specific_type != SUMMON_GUARDIANS)
1061 /* Hack -- don't create questors */
1062 if (r_ptr->flags1 & RF1_QUESTOR)
1065 if (r_ptr->flags7 & RF7_GUARDIAN)
1068 /* Depth Monsters never appear out of depth */
1069 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1070 (r_ptr->level > floor_ptr->dun_level))
1074 /* Accept this monster */
1075 entry->prob2 = entry->prob1;
1077 if (floor_ptr->dun_level && (!floor_ptr->inside_quest || is_fixed_quest_idx(floor_ptr->inside_quest)) &&
1078 !restrict_monster_to_dungeon(p_ptr->dungeon_idx, entry->index) && !p_ptr->phase_out)
1080 int hoge = entry->prob2 * d_info[p_ptr->dungeon_idx].special_div;
1081 entry->prob2 = hoge / 64;
1082 if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1092 * @brief 生成モンスター種族を1種生成テーブルから選択する
1094 * @return 選択されたモンスター生成種族
1096 * Choose a monster race that seems "appropriate" to the given level
1098 * This function uses the "prob2" field of the "monster allocation table",
1099 * and various local information, to calculate the "prob3" field of the
1100 * same table, which is then used to choose an "appropriate" monster, in
1101 * a relatively efficient manner.
1103 * Note that "town" monsters will *only* be created in the town, and
1104 * "normal" monsters will *never* be created in the town, unless the
1105 * "level" is "modified", for example, by polymorph or summoning.
1107 * There is a small chance (1/50) of "boosting" the given depth by
1108 * a small amount (up to four levels), except in the town.
1110 * It is (slightly) more likely to acquire a monster of the given level
1111 * than one of a lower level. This is done by choosing several monsters
1112 * appropriate to the given level and keeping the "hardest" one.
1114 * Note that if no monsters are "appropriate", then this function will
1115 * fail, and return zero, but this should *almost* never happen.
1117 MONRACE_IDX get_mon_num(DEPTH level)
1122 monster_race *r_ptr;
1123 alloc_entry *table = alloc_race_table;
1125 int pls_kakuritu, pls_level;
1126 int delay = mysqrt(level * 10000L) + 400L;
1128 pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10)));
1129 pls_level = MIN(NASTY_MON_PLUS_MAX, 3 + current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10));
1131 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_MAZE)
1133 pls_kakuritu = MIN(pls_kakuritu / 2, pls_kakuritu - 10);
1134 if (pls_kakuritu < 2) pls_kakuritu = 2;
1139 /* Boost the level */
1140 if (!p_ptr->phase_out && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1142 /* Nightmare mode allows more out-of depth monsters */
1143 if (ironman_nightmare && !randint0(pls_kakuritu))
1145 /* What a bizarre calculation */
1146 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1150 /* Occasional "nasty" monster */
1151 if (!randint0(pls_kakuritu))
1153 /* Pick a level bonus */
1159 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1160 if (level < 0) level = 0;
1165 /* Process probabilities */
1166 for (i = 0; i < alloc_race_size; i++)
1168 /* Monsters are sorted by depth */
1169 if (table[i].level > level) break;
1174 /* Access the "r_idx" of the chosen monster */
1175 r_idx = table[i].index;
1177 /* Access the actual race */
1178 r_ptr = &r_info[r_idx];
1180 if (!p_ptr->phase_out && !chameleon_change_m_idx)
1182 /* Hack -- "unique" monsters must be "unique" */
1183 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1184 (r_ptr->flags7 & (RF7_NAZGUL))) &&
1185 (r_ptr->cur_num >= r_ptr->max_num))
1190 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1191 (r_ptr->cur_num >= 1))
1196 if (r_idx == MON_BANORLUPART)
1198 if (r_info[MON_BANOR].cur_num > 0) continue;
1199 if (r_info[MON_LUPART].cur_num > 0) continue;
1204 table[i].prob3 = table[i].prob2;
1207 total += table[i].prob3;
1210 /* No legal monsters */
1211 if (total <= 0) return 0;
1213 /* Pick a monster */
1214 value = randint0(total);
1216 /* Find the monster */
1217 for (i = 0; i < alloc_race_size; i++)
1219 /* Found the entry */
1220 if (value < table[i].prob3) break;
1223 value = value - table[i].prob3;
1229 /* Try for a "harder" monster once (50%) or twice (10%) */
1235 /* Pick a monster */
1236 value = randint0(total);
1238 /* Find the monster */
1239 for (i = 0; i < alloc_race_size; i++)
1241 /* Found the entry */
1242 if (value < table[i].prob3) break;
1245 value = value - table[i].prob3;
1248 /* Keep the "best" one */
1249 if (table[i].level < table[j].level) i = j;
1252 /* Try for a "harder" monster twice (10%) */
1258 /* Pick a monster */
1259 value = randint0(total);
1261 /* Find the monster */
1262 for (i = 0; i < alloc_race_size; i++)
1264 /* Found the entry */
1265 if (value < table[i].prob3) break;
1268 value = value - table[i].prob3;
1271 /* Keep the "best" one */
1272 if (table[i].level < table[j].level) i = j;
1274 return (table[i].index);
1279 * @brief モンスターの呼称を作成する / Build a string describing a monster in some way.
1280 * @param desc 記述出力先の文字列参照ポインタ
1281 * @param m_ptr モンスターの参照ポインタ
1282 * @param mode 呼称オプション
1285 * We can correctly describe monsters based on their visibility.
1286 * We can force all monsters to be treated as visible or invisible.
1287 * We can build nominatives, objectives, possessives, or reflexives.
1288 * We can selectively pronominalize hidden, visible, or all monsters.
1289 * We can use definite or indefinite descriptions for hidden monsters.
1290 * We can use definite or indefinite descriptions for visible monsters.
1292 * Pronominalization involves the gender whenever possible and allowed,
1293 * so that by cleverly requesting pronominalization / visibility, you
1294 * can get messages like "You hit someone. She screams in agony!".
1296 * Reflexives are acquired by requesting Objective plus Possessive.
1298 * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1299 * unless the "Assume Visible" mode is requested.
1301 * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1302 * If neither m_ptr nor r_ptr is given, the monster is assumed to
1303 * be neuter, singular, and hidden (unless "Assume Visible" is set),
1304 * in which case you may be in trouble... :-)
1306 * I am assuming that no monster name is more than 70 characters long,
1307 * so that "char desc[80];" is sufficiently large for any result.
1310 * MD_OBJECTIVE --> Objective (or Reflexive)
1311 * MD_POSSESSIVE --> Possessive (or Reflexive)
1312 * MD_INDEF_HIDDEN --> Use indefinites for hidden monsters ("something")
1313 * MD_INDEF_VISIBLE --> Use indefinites for visible monsters ("a kobold")
1314 * MD_PRON_HIDDEN --> Pronominalize hidden monsters
1315 * MD_PRON_VISIBLE --> Pronominalize visible monsters
1316 * MD_ASSUME_HIDDEN --> Assume the monster is hidden
1317 * MD_ASSUME_VISIBLE --> Assume the monster is visible
1318 * MD_TRUE_NAME --> Chameleon's true name
1319 * MD_IGNORE_HALLU --> Ignore hallucination, and penetrate shape change
1322 * 0x00 --> Full nominative name ("the kobold") or "it"
1323 * MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1324 * MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1325 * MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1326 * MD_PRON_VISIBLE | MD_POSSESSIVE
1327 * --> Possessive, genderized if visable ("his") or "its"
1328 * MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1329 * --> Reflexive, genderized if visable ("himself") or "itself"
1331 void monster_desc(char *desc, monster_type *m_ptr, BIT_FLAGS mode)
1334 monster_race *r_ptr;
1338 GAME_TEXT silly_name[1024];
1342 r_ptr = &r_info[m_ptr->ap_r_idx];
1344 /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1345 if (mode & MD_TRUE_NAME) name = (r_name + real_r_ptr(m_ptr)->name);
1346 else name = (r_name + r_ptr->name);
1348 /* Are we hallucinating? (Idea from Nethack...) */
1349 if (p_ptr->image && !(mode & MD_IGNORE_HALLU))
1353 if (!get_rnd_line(_("silly_j.txt", "silly.txt"), m_ptr->r_idx, silly_name))
1359 monster_race *hallu_race;
1363 hallu_race = &r_info[randint1(max_r_idx - 1)];
1364 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
1366 strcpy(silly_name, (r_name + hallu_race->name));
1369 /* Better not strcpy it, or we could corrupt r_info... */
1373 /* Can we "see" it (exists + forced, or visible + not unforced) */
1374 seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1376 /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1377 pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1380 /* First, try using pronouns, or describing hidden monsters */
1381 floor_type *floor_ptr = p_ptr->current_floor_ptr;
1384 /* an encoding of the monster "sex" */
1387 /* Extract the gender (if applicable) */
1388 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1389 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1391 /* Ignore the gender (if desired) */
1392 if (!m_ptr || !pron) kind = 0x00;
1395 /* Assume simple result */
1396 res = _("何か", "it");
1398 /* Brute force: split on the possibilities */
1399 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1401 /* Neuter, or unknown */
1403 case 0x00: res = "何か"; break;
1404 case 0x00 + (MD_OBJECTIVE) : res = "何か"; break;
1405 case 0x00 + (MD_POSSESSIVE) : res = "何かの"; break;
1406 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "何か自身"; break;
1407 case 0x00 + (MD_INDEF_HIDDEN) : res = "何か"; break;
1408 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "何か"; break;
1409 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "何か"; break;
1410 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "それ自身"; break;
1412 case 0x00: res = "it"; break;
1413 case 0x00 + (MD_OBJECTIVE) : res = "it"; break;
1414 case 0x00 + (MD_POSSESSIVE) : res = "its"; break;
1415 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "itself"; break;
1416 case 0x00 + (MD_INDEF_HIDDEN) : res = "something"; break;
1417 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "something"; break;
1418 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "something's"; break;
1419 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "itself"; break;
1423 /* Male (assume human if vague) */
1425 case 0x10: res = "彼"; break;
1426 case 0x10 + (MD_OBJECTIVE) : res = "彼"; break;
1427 case 0x10 + (MD_POSSESSIVE) : res = "彼の"; break;
1428 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼自身"; break;
1429 case 0x10 + (MD_INDEF_HIDDEN) : res = "誰か"; break;
1430 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "誰か"; break;
1431 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "誰かの"; break;
1432 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼自身"; break;
1434 case 0x10: res = "he"; break;
1435 case 0x10 + (MD_OBJECTIVE) : res = "him"; break;
1436 case 0x10 + (MD_POSSESSIVE) : res = "his"; break;
1437 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "himself"; break;
1438 case 0x10 + (MD_INDEF_HIDDEN) : res = "someone"; break;
1439 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "someone"; break;
1440 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "someone's"; break;
1441 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "himself"; break;
1445 /* Female (assume human if vague) */
1447 case 0x20: res = "彼女"; break;
1448 case 0x20 + (MD_OBJECTIVE) : res = "彼女"; break;
1449 case 0x20 + (MD_POSSESSIVE) : res = "彼女の"; break;
1450 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼女自身"; break;
1451 case 0x20 + (MD_INDEF_HIDDEN) : res = "誰か"; break;
1452 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "誰か"; break;
1453 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "誰かの"; break;
1454 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼女自身"; break;
1456 case 0x20: res = "she"; break;
1457 case 0x20 + (MD_OBJECTIVE) : res = "her"; break;
1458 case 0x20 + (MD_POSSESSIVE) : res = "her"; break;
1459 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "herself"; break;
1460 case 0x20 + (MD_INDEF_HIDDEN) : res = "someone"; break;
1461 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "someone"; break;
1462 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "someone's"; break;
1463 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "herself"; break;
1467 /* Copy the result */
1468 (void)strcpy(desc, res);
1472 /* Handle visible monsters, "reflexive" request */
1473 else if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1475 /* The monster is visible, so use its gender */
1476 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, _("彼女自身", "herself"));
1477 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, _("彼自身", "himself"));
1478 else strcpy(desc, _("それ自身", "itself"));
1482 /* Handle all other visible monster requests */
1486 if (is_pet(m_ptr) && !is_original_ap(m_ptr))
1492 while (strncmp(t, "』", 2) && *t) t++;
1496 (void)sprintf(desc, "%s?』", buf);
1499 (void)sprintf(desc, "%s?", name);
1501 (void)sprintf(desc, "%s?", name);
1506 /* It could be a Unique */
1507 if ((r_ptr->flags1 & RF1_UNIQUE) && !(p_ptr->image && !(mode & MD_IGNORE_HALLU)))
1509 /* Start with the name (thus nominative and objective) */
1510 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1516 while (strncmp(t, "』", 2) && *t) t++;
1520 (void)sprintf(desc, "%s?』", buf);
1523 (void)sprintf(desc, "%s?", name);
1525 (void)sprintf(desc, "%s?", name);
1529 /* Inside monster arena, and it is not your mount */
1530 else if (p_ptr->phase_out &&
1531 !(p_ptr->riding && (&floor_ptr->m_list[p_ptr->riding] == m_ptr)))
1533 /* It is a fake unique monster */
1534 (void)sprintf(desc, _("%sもどき", "fake %s"), name);
1539 (void)strcpy(desc, name);
1543 /* It could be an indefinite monster */
1544 else if (mode & MD_INDEF_VISIBLE)
1546 /* XXX Check plurality for "some" */
1548 /* Indefinite monsters need an indefinite article */
1550 (void)strcpy(desc, "");
1552 (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1555 (void)strcat(desc, name);
1558 /* It could be a normal, definite, monster */
1561 /* Definite monsters need a definite article */
1563 (void)strcpy(desc, _("あなたの", "your "));
1565 (void)strcpy(desc, _("", "the "));
1567 (void)strcat(desc, name);
1570 if (m_ptr->nickname)
1572 sprintf(buf, _("「%s」", " called %s"), quark_str(m_ptr->nickname));
1576 if (p_ptr->riding && (&floor_ptr->m_list[p_ptr->riding] == m_ptr))
1578 strcat(desc, _("(乗馬中)", "(riding)"));
1581 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1583 if (r_ptr->flags1 & RF1_UNIQUE)
1585 strcat(desc, _("(カメレオンの王)", "(Chameleon Lord)"));
1589 strcat(desc, _("(カメレオン)", "(Chameleon)"));
1593 if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr))
1595 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1598 /* Handle the Possessive as a special afterthought */
1599 if (mode & MD_POSSESSIVE)
1601 /* XXX Check for trailing "s" */
1603 /* Simply append "apostrophe" and "s" */
1604 (void)strcat(desc, _("の", "'s"));
1610 * @brief モンスターIDを取り、モンスター名をm_nameに代入する /
1611 * @param m_idx モンスターID
1612 * @param m_name モンスター名を入力する配列
1614 void monster_name(MONSTER_IDX m_idx, char* m_name)
1616 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
1617 monster_desc(m_name, m_ptr, 0x00);
1622 * @brief モンスターの調査による思い出補完処理 / Learn about a monster (by "probing" it)
1623 * @param r_idx 補完されるモンスター種族ID
1624 * @return 明らかになった情報の度数
1626 * Return the number of new flags learnt. -Mogami-
1628 int lore_do_probe(MONRACE_IDX r_idx)
1630 monster_race *r_ptr = &r_info[r_idx];
1634 /* Maximal info about awareness */
1635 if (r_ptr->r_wake != MAX_UCHAR) n++;
1636 if (r_ptr->r_ignore != MAX_UCHAR) n++;
1637 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1639 /* Observe "maximal" attacks */
1640 for (i = 0; i < 4; i++)
1642 /* Examine "actual" blows */
1643 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1645 /* Maximal observations */
1646 if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1647 r_ptr->r_blows[i] = MAX_UCHAR;
1653 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1654 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1655 ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1656 ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1657 ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1658 ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1660 /* Only "valid" drops */
1661 if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1663 if (r_ptr->r_drop_item != tmp_byte) n++;
1664 r_ptr->r_drop_item = tmp_byte;
1666 if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1668 if (r_ptr->r_drop_gold != tmp_byte) n++;
1669 r_ptr->r_drop_gold = tmp_byte;
1672 /* Observe many spells */
1673 if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1674 r_ptr->r_cast_spell = MAX_UCHAR;
1676 /* Count unknown flags */
1677 for (i = 0; i < 32; i++)
1679 if (!(r_ptr->r_flags1 & (1L << i)) &&
1680 (r_ptr->flags1 & (1L << i))) n++;
1681 if (!(r_ptr->r_flags2 & (1L << i)) &&
1682 (r_ptr->flags2 & (1L << i))) n++;
1683 if (!(r_ptr->r_flags3 & (1L << i)) &&
1684 (r_ptr->flags3 & (1L << i))) n++;
1685 if (!(r_ptr->r_flags4 & (1L << i)) &&
1686 (r_ptr->flags4 & (1L << i))) n++;
1687 if (!(r_ptr->r_flags5 & (1L << i)) &&
1688 (r_ptr->a_ability_flags1 & (1L << i))) n++;
1689 if (!(r_ptr->r_flags6 & (1L << i)) &&
1690 (r_ptr->a_ability_flags2 & (1L << i))) n++;
1691 if (!(r_ptr->r_flagsr & (1L << i)) &&
1692 (r_ptr->flagsr & (1L << i))) n++;
1694 /* r_flags7 is actually unused */
1697 /* Know all the flags */
1698 r_ptr->r_flags1 = r_ptr->flags1;
1699 r_ptr->r_flags2 = r_ptr->flags2;
1700 r_ptr->r_flags3 = r_ptr->flags3;
1701 r_ptr->r_flags4 = r_ptr->flags4;
1702 r_ptr->r_flags5 = r_ptr->a_ability_flags1;
1703 r_ptr->r_flags6 = r_ptr->a_ability_flags2;
1704 r_ptr->r_flagsr = r_ptr->flagsr;
1706 /* r_flags7 is actually unused */
1707 /* r_ptr->r_flags7 = r_ptr->flags7; */
1709 /* Know about evolution */
1710 if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1711 r_ptr->r_xtra1 |= MR1_SINKA;
1713 /* Update monster recall window */
1714 if (p_ptr->monster_race_idx == r_idx)
1716 p_ptr->window |= (PW_MONSTER);
1719 /* Return the number of new flags learnt */
1725 * @brief モンスターの撃破に伴うドロップ情報の保管処理 / Take note that the given monster just dropped some treasure
1726 * @param m_idx モンスター情報のID
1727 * @param num_item 手に入れたアイテム数
1728 * @param num_gold 手に入れた財宝の単位数
1731 * Note that learning the "GOOD"/"GREAT" flags gives information
1732 * about the treasure (even when the monster is killed for the first
1733 * time, such as uniques, and the treasure has not been examined yet).
1735 * This "indirect" method is used to prevent the player from learning
1736 * exactly how much treasure a monster can drop from observing only
1737 * a single example of a drop. This method actually observes how much
1738 * gold and items are dropped, and remembers that information to be
1739 * described later by the monster recall code.
1741 void lore_treasure(MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
1743 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
1745 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1747 /* If the monster doesn't have original appearance, don't note */
1748 if (!is_original_ap(m_ptr)) return;
1750 /* Note the number of things dropped */
1751 if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1752 if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1754 /* Hack -- memorize the good/great flags */
1755 if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1756 if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1758 /* Update monster recall window */
1759 if (p_ptr->monster_race_idx == m_ptr->r_idx)
1761 p_ptr->window |= (PW_MONSTER);
1767 * @brief モンスターの各情報を更新する / This function updates the monster record of the given monster
1768 * @param m_idx 更新するモンスター情報のID
1769 * @param full プレイヤーとの距離更新を行うならばtrue
1772 * This involves extracting the distance to the player (if requested),
1773 * and then checking for visibility (natural, infravision, see-invis,
1774 * telepathy), updating the monster visibility flag, redrawing (or
1775 * erasing) the monster when its visibility changes, and taking note
1776 * of any interesting monster flags (cold-blooded, invisible, etc).
1778 * Note the new "mflag" field which encodes several monster state flags,
1779 * including "view" for when the monster is currently in line of sight,
1780 * and "mark" for when the monster is currently visible via detection.
1782 * The only monster fields that are changed here are "cdis" (the
1783 * distance from the player), "ml" (visible to the player), and
1784 * "mflag" (to maintain the "MFLAG_VIEW" flag).
1786 * Note the special "update_monsters()" function which can be used to
1787 * call this function once for every monster.
1789 * Note the "full" flag which requests that the "cdis" field be updated,
1790 * this is only needed when the monster (or the player) has moved.
1792 * Every time a monster moves, we must call this function for that
1793 * monster, and update the distance, and the visibility. Every time
1794 * the player moves, we must call this function for every monster, and
1795 * update the distance, and the visibility. Whenever the player "state"
1796 * changes in certain ways ("blindness", "infravision", "telepathy",
1797 * and "see invisible"), we must call this function for every monster,
1798 * and update the visibility.
1800 * Routines that change the "illumination" of a grid must also call this
1801 * function for any monster in that grid, since the "visibility" of some
1802 * monsters may be based on the illumination of their grid.
1804 * Note that this function is called once per monster every time the
1805 * player moves. When the player is running, this function is one
1806 * of the primary bottlenecks, along with "update_view()" and the
1807 * "process_monsters()" code, so efficiency is important.
1809 * Note the optimized "inline" version of the "distance()" function.
1811 * A monster is "visible" to the player if (1) it has been detected
1812 * by the player, (2) it is close to the player and the player has
1813 * telepathy, or (3) it is close to the player, and in line of sight
1814 * of the player, and it is "illuminated" by some combination of
1815 * infravision, torch light, or permanent light (invisible monsters
1816 * are only affected by "light" if the player can see invisible).
1818 * Monsters which are not on the current panel may be "visible" to
1819 * the player, and their descriptions will include an "offscreen"
1820 * reference. Currently, offscreen monsters cannot be targetted
1821 * or viewed directly, but old targets will remain set. XXX XXX
1823 * The player can choose to be disturbed by several things, including
1824 * "disturb_move" (monster which is viewable moves in some way), and
1825 * "disturb_near" (monster which is "easily" viewable moves in some
1826 * way). Note that "moves" includes "appears" and "disappears".
1828 void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full)
1830 monster_type *m_ptr = &subject_ptr->current_floor_ptr->m_list[m_idx];
1831 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1833 bool do_disturb = disturb_move;
1836 POSITION fy = m_ptr->fy;
1837 POSITION fx = m_ptr->fx;
1842 /* Seen by vision */
1845 /* Non-Ninja player in the darkness */
1846 bool in_darkness = (d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !subject_ptr->see_nocto;
1851 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1853 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= subject_ptr->lev)
1857 /* Compute distance */
1860 /* Distance components */
1861 int dy = (subject_ptr->y > fy) ? (subject_ptr->y - fy) : (fy - subject_ptr->y);
1862 int dx = (subject_ptr->x > fx) ? (subject_ptr->x - fx) : (fx - subject_ptr->x);
1864 /* Approximate distance */
1865 d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
1867 /* Restrict distance */
1868 if (d > 255) d = 255;
1872 /* Save the distance */
1876 /* Extract distance */
1879 /* Extract the distance */
1884 if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
1887 if (d <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
1889 if (!in_darkness || (d <= MAX_SIGHT / 4))
1891 if (subject_ptr->special_defense & KATA_MUSOU)
1896 if (is_original_ap(m_ptr) && !subject_ptr->image)
1898 /* Hack -- Memorize mental flags */
1899 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1900 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1904 /* Basic telepathy */
1905 /* Snipers get telepathy when they concentrate deeper */
1906 else if (subject_ptr->telepathy)
1908 /* Empty mind, no telepathy */
1909 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
1911 /* Memorize flags */
1912 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
1915 /* Weird mind, occasional telepathy */
1916 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
1918 /* One in ten individuals are detectable */
1919 if ((m_idx % 10) == 5)
1924 if (is_original_ap(m_ptr) && !subject_ptr->image)
1926 /* Memorize flags */
1927 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
1929 /* Hack -- Memorize mental flags */
1930 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1931 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1936 /* Normal mind, allow telepathy */
1942 if (is_original_ap(m_ptr) && !subject_ptr->image)
1944 /* Hack -- Memorize mental flags */
1945 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1946 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1951 if ((subject_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
1954 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
1957 if ((subject_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
1960 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
1963 if ((subject_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
1966 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
1969 if ((subject_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
1972 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
1975 if ((subject_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
1978 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
1981 if ((subject_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
1984 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
1987 if ((subject_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
1990 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
1993 if ((subject_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
1996 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
1999 if ((subject_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
2002 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
2005 if ((subject_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
2008 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
2011 if ((subject_ptr->esp_nonliving) &&
2012 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
2015 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
2018 if ((subject_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
2021 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
2025 /* Normal line of sight, and not blind */
2026 if (player_has_los_bold(subject_ptr, fy, fx) && !subject_ptr->blind)
2028 bool do_invisible = FALSE;
2029 bool do_cold_blood = FALSE;
2031 /* Snipers can see targets in darkness when they concentrate deeper */
2032 if (subject_ptr->concent >= CONCENT_RADAR_THRESHOLD)
2038 /* Use "infravision" */
2039 if (d <= subject_ptr->see_infra)
2041 /* Handle "cold blooded" monsters */
2042 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2044 do_cold_blood = TRUE;
2047 /* Handle "warm blooded" monsters */
2055 /* Use "illumination" */
2056 if (player_can_see_bold(subject_ptr, fy, fx))
2058 /* Handle "invisible" monsters */
2059 if (r_ptr->flags2 & (RF2_INVISIBLE))
2061 do_invisible = TRUE;
2064 if (subject_ptr->see_inv)
2071 /* Handle "normal" monsters */
2082 if (is_original_ap(m_ptr) && !subject_ptr->image)
2084 /* Memorize flags */
2085 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2086 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2093 /* The monster is now visible */
2096 /* It was previously unseen */
2099 /* Mark as visible */
2102 /* Draw the monster */
2105 /* Update health bar as needed */
2106 if (subject_ptr->health_who == m_idx) subject_ptr->redraw |= (PR_HEALTH);
2107 if (subject_ptr->riding == m_idx) subject_ptr->redraw |= (PR_UHEALTH);
2109 /* Hack -- Count "fresh" sightings */
2110 if (!subject_ptr->image)
2112 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2113 r_info[MON_KAGE].r_sights++;
2114 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
2118 if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
2120 sanity_blast(subject_ptr, m_ptr, FALSE);
2123 /* Disturb on appearance */
2124 if (disturb_near && (projectable(subject_ptr, m_ptr->fy, m_ptr->fx, subject_ptr->y, subject_ptr->x) && projectable(subject_ptr, subject_ptr->y, subject_ptr->x, m_ptr->fy, m_ptr->fx)))
2126 if (disturb_pets || is_hostile(m_ptr))
2127 disturb(subject_ptr, TRUE, TRUE);
2132 /* The monster is not visible */
2135 /* It was previously seen */
2138 /* Mark as not visible */
2141 /* Erase the monster */
2144 /* Update health bar as needed */
2145 if (subject_ptr->health_who == m_idx) subject_ptr->redraw |= (PR_HEALTH);
2146 if (subject_ptr->riding == m_idx) subject_ptr->redraw |= (PR_UHEALTH);
2148 /* Disturb on disappearance */
2151 if (disturb_pets || is_hostile(m_ptr))
2152 disturb(subject_ptr, TRUE, TRUE);
2158 /* The monster is now easily visible */
2162 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2164 /* Mark as easily visible */
2165 m_ptr->mflag |= (MFLAG_VIEW);
2167 /* Disturb on appearance */
2170 if (disturb_pets || is_hostile(m_ptr))
2171 disturb(subject_ptr, TRUE, TRUE);
2176 /* The monster is not easily visible */
2180 if (m_ptr->mflag & (MFLAG_VIEW))
2182 /* Mark as not easily visible */
2183 m_ptr->mflag &= ~(MFLAG_VIEW);
2185 /* Disturb on disappearance */
2188 if (disturb_pets || is_hostile(m_ptr))
2189 disturb(subject_ptr, TRUE, TRUE);
2197 * @brief 単純に生存している全モンスターの更新処理を行う / This function simply updates all the (non-dead) monsters (see above).
2198 * @param full 距離更新を行うならtrue
2201 void update_monsters(bool full)
2205 /* Update each (live) monster */
2206 floor_type *floor_ptr = p_ptr->current_floor_ptr;
2207 for (i = 1; i < floor_ptr->m_max; i++)
2209 monster_type *m_ptr = &floor_ptr->m_list[i];
2210 if (!monster_is_valid(m_ptr)) continue;
2211 update_monster(p_ptr, i, full);
2217 * @brief カメレオンの王の変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2218 * @param r_idx モンスター種族ID
2219 * @return 対象にできるならtrueを返す
2221 static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
2223 floor_type *floor_ptr = p_ptr->current_floor_ptr;
2224 monster_race *r_ptr = &r_info[r_idx];
2225 monster_type *m_ptr = &floor_ptr->m_list[chameleon_change_m_idx];
2226 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2228 if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2229 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2231 if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2233 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))
2236 if (!monster_can_cross_terrain(floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2239 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2241 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2245 else if (summon_specific_who > 0)
2247 if (monster_has_hostile_align(&floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2254 * @brief カメレオンの変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2255 * @param r_idx モンスター種族ID
2256 * @return 対象にできるならtrueを返す
2257 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2259 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
2261 floor_type *floor_ptr = p_ptr->current_floor_ptr;
2262 monster_race *r_ptr = &r_info[r_idx];
2263 monster_type *m_ptr = &floor_ptr->m_list[chameleon_change_m_idx];
2264 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2266 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2267 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2268 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2270 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))
2273 if (!monster_can_cross_terrain(floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2276 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2278 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2279 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2280 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2284 else if (summon_specific_who > 0)
2286 if (monster_has_hostile_align(&floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2289 return (*(get_monster_hook(p_ptr)))(r_idx);
2294 * @param m_idx 変身処理を受けるモンスター情報のID
2295 * @param born 生成時の初変身先指定ならばtrue
2296 * @param r_idx 旧モンスター種族のID
2299 void choose_new_monster(MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
2302 floor_type *floor_ptr = p_ptr->current_floor_ptr;
2303 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
2304 monster_race *r_ptr;
2305 char old_m_name[MAX_NLEN];
2306 bool old_unique = FALSE;
2307 int old_r_idx = m_ptr->r_idx;
2309 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2311 if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2312 r_ptr = &r_info[r_idx];
2314 monster_desc(old_m_name, m_ptr, 0);
2320 chameleon_change_m_idx = m_idx;
2322 get_mon_num_prep(monster_hook_chameleon_lord, NULL);
2324 get_mon_num_prep(monster_hook_chameleon, NULL);
2327 level = r_info[MON_CHAMELEON_K].level;
2328 else if (!floor_ptr->dun_level)
2329 level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
2331 level = floor_ptr->dun_level;
2333 if (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level += 2 + randint1(3);
2335 r_idx = get_mon_num(level);
2336 r_ptr = &r_info[r_idx];
2338 chameleon_change_m_idx = 0;
2342 m_ptr->r_idx = r_idx;
2343 m_ptr->ap_r_idx = r_idx;
2344 update_monster(p_ptr, m_idx, FALSE);
2345 lite_spot(m_ptr->fy, m_ptr->fx);
2347 if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2348 (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2349 p_ptr->update |= (PU_MON_LITE);
2353 /* Sub-alignment of a chameleon */
2354 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2356 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2357 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2358 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2363 if (m_idx == p_ptr->riding)
2365 GAME_TEXT m_name[MAX_NLEN];
2366 monster_desc(m_name, m_ptr, 0);
2367 msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
2368 if (!(r_ptr->flags7 & RF7_RIDING))
2369 if (rakuba(p_ptr, 0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
2372 /* Extract the monster base speed */
2373 m_ptr->mspeed = get_mspeed(r_ptr);
2375 oldmaxhp = m_ptr->max_maxhp;
2376 /* Assign maximal hitpoints */
2377 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2379 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2383 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2386 /* Monsters have double hitpoints in Nightmare mode */
2387 if (ironman_nightmare)
2389 u32b hp = m_ptr->max_maxhp * 2L;
2390 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2393 m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2394 if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2395 m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2397 /* reset dealt_damage */
2398 m_ptr->dealt_damage = 0;
2403 * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
2404 * @param r_idx モンスター種族ID
2405 * @return 対象にできるならtrueを返す
2406 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2408 static bool monster_hook_tanuki(MONRACE_IDX r_idx)
2410 monster_race *r_ptr = &r_info[r_idx];
2412 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2413 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2414 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2415 if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2417 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))
2420 return (*(get_monster_hook(p_ptr)))(r_idx);
2425 * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
2426 * @param r_idx モンスター種族ID
2427 * @return モンスター種族の表層ID
2429 static MONRACE_IDX initial_r_appearance(MONRACE_IDX r_idx, BIT_FLAGS generate_mode)
2431 floor_type *floor_ptr = p_ptr->current_floor_ptr;
2432 int attempts = 1000;
2433 MONRACE_IDX ap_r_idx;
2434 DEPTH min = MIN(floor_ptr->base_level - 5, 50);
2436 if (p_ptr->pseikaku == SEIKAKU_CHARGEMAN && !(generate_mode & (PM_MULTIPLY | PM_KAGE)))
2438 if (floor_ptr->base_level == 0 ||
2439 (one_in_(5) && my_strchr("hkoptuyAHOPTUVY", r_info[r_idx].d_char))) return MON_ALIEN_JURAL;
2442 if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2445 get_mon_num_prep(monster_hook_tanuki, NULL);
2449 ap_r_idx = get_mon_num(floor_ptr->base_level + 10);
2450 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2458 * @brief モンスターの個体加速を設定する / Get initial monster speed
2459 * @param r_ptr モンスター種族の参照ポインタ
2462 SPEED get_mspeed(monster_race *r_ptr)
2464 /* Extract the monster base speed */
2465 SPEED mspeed = r_ptr->speed;
2467 /* Hack -- small racial variety */
2468 if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->current_floor_ptr->inside_arena)
2470 /* Allow some small variation per monster */
2471 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2472 if (i) mspeed += rand_spread(0, i);
2475 if (mspeed > 199) mspeed = 199;
2482 * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
2483 * @param player_ptr プレーヤーへの参照ポインタ
2484 * @param who 召喚を行ったモンスターID
2487 * @param r_idx 生成モンスター種族
2488 * @param mode 生成オプション
2491 * To give the player a sporting chance, any monster that appears in
2492 * line-of-sight and is extremely dangerous can be marked as
2493 * "FORCE_SLEEP", which will cause them to be placed with low energy,
2494 * which often (but not always) lets the player move before they do.
2496 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2498 * Use special "here" and "dead" flags for unique monsters,
2499 * remove old "cur_num" and "max_num" fields.
2501 * Actually, do something similar for artifacts, to simplify
2502 * the "preserve" mode, and to make the "what artifacts" flag more useful.
2504 * This is the only function which may place a monster in the dungeon,
2505 * except for the savefile loading code.
2507 static bool place_monster_one(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2509 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2510 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2511 monster_type *m_ptr;
2512 monster_race *r_ptr = &r_info[r_idx];
2513 concptr name = (r_name + r_ptr->name);
2517 /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2518 if (player_ptr->wild_mode) return FALSE;
2520 if (!in_bounds(floor_ptr, y, x)) return FALSE;
2521 if (!r_idx) return FALSE;
2522 if (!r_ptr->name) return FALSE;
2524 if (!(mode & PM_IGNORE_TERRAIN))
2526 /* Not on the Pattern */
2527 if (pattern_tile(y, x)) return FALSE;
2529 /* Require empty space (if not ghostly) */
2530 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
2533 if (!player_ptr->phase_out)
2535 /* Hack -- "unique" monsters must be "unique" */
2536 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2537 (r_ptr->flags7 & (RF7_NAZGUL))) &&
2538 (r_ptr->cur_num >= r_ptr->max_num))
2544 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
2545 (r_ptr->cur_num >= 1))
2550 if (r_idx == MON_BANORLUPART)
2552 if (r_info[MON_BANOR].cur_num > 0) return FALSE;
2553 if (r_info[MON_LUPART].cur_num > 0) return FALSE;
2556 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
2557 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (floor_ptr->dun_level < r_ptr->level) &&
2558 (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
2565 if (quest_number(player_ptr, floor_ptr->dun_level))
2567 int hoge = quest_number(player_ptr, floor_ptr->dun_level);
2568 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
2570 if (r_idx == quest[hoge].r_idx)
2572 int number_mon, i2, j2;
2575 /* Count all quest monsters */
2576 for (i2 = 0; i2 < floor_ptr->width; ++i2)
2577 for (j2 = 0; j2 < floor_ptr->height; j2++)
2578 if (floor_ptr->grid_array[j2][i2].m_idx > 0)
2579 if (floor_ptr->m_list[floor_ptr->grid_array[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
2581 if (number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
2587 if (is_glyph_grid(g_ptr))
2589 if (randint1(BREAK_GLYPH) < (r_ptr->level + 20))
2591 /* Describe observable breakage */
2592 if (g_ptr->info & CAVE_MARK)
2594 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2597 /* Forget the rune */
2598 g_ptr->info &= ~(CAVE_MARK);
2600 /* Break the rune */
2601 g_ptr->info &= ~(CAVE_OBJECT);
2609 msg_format_wizard(CHEAT_MONSTER, _("%s(Lv%d)を生成しました。", "%s(Lv%d) was generated."), name, r_ptr->level);
2611 if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
2613 /* Make a new monster */
2614 g_ptr->m_idx = m_pop();
2615 hack_m_idx_ii = g_ptr->m_idx;
2617 /* Mega-Hack -- catch "failure" */
2618 if (!g_ptr->m_idx) return FALSE;
2621 /* Get a new monster record */
2622 m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
2625 m_ptr->r_idx = r_idx;
2626 m_ptr->ap_r_idx = initial_r_appearance(r_idx, mode);
2632 /* Hack -- Appearance transfer */
2633 if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(&floor_ptr->m_list[who]))
2635 m_ptr->ap_r_idx = floor_ptr->m_list[who].ap_r_idx;
2637 /* Hack -- Shadower spawns Shadower */
2638 if (floor_ptr->m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
2641 /* Sub-alignment of a monster */
2642 if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
2643 m_ptr->sub_align = floor_ptr->m_list[who].sub_align;
2646 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2647 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2648 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2651 /* Place the monster at the location */
2654 m_ptr->current_floor_ptr = floor_ptr;
2656 /* No "timed status" yet */
2657 for (cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
2659 /* Unknown distance */
2662 reset_target(m_ptr);
2664 m_ptr->nickname = 0;
2669 /* Your pet summons its pet. */
2670 if (who > 0 && is_pet(&floor_ptr->m_list[who]))
2672 mode |= PM_FORCE_PET;
2673 m_ptr->parent_m_idx = who;
2677 m_ptr->parent_m_idx = 0;
2680 if (r_ptr->flags7 & RF7_CHAMELEON)
2682 choose_new_monster(g_ptr->m_idx, TRUE, 0);
2683 r_ptr = &r_info[m_ptr->r_idx];
2684 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
2686 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
2687 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
2688 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2690 else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
2692 m_ptr->ap_r_idx = MON_KAGE;
2693 m_ptr->mflag2 |= MFLAG2_KAGE;
2696 if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
2702 if (mode & PM_FORCE_PET)
2704 set_pet(player_ptr, m_ptr);
2707 else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
2708 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(player_ptr, who))
2710 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
2713 /* Assume no sleeping */
2714 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
2716 /* Enforce sleeping if needed */
2717 if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
2719 int val = r_ptr->sleep;
2720 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, (val * 2) + randint1(val * 10));
2723 /* Assign maximal hitpoints */
2724 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2726 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2730 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2733 /* Monsters have double hitpoints in Nightmare mode */
2734 if (ironman_nightmare)
2736 u32b hp = m_ptr->max_maxhp * 2L;
2738 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2741 m_ptr->maxhp = m_ptr->max_maxhp;
2743 /* And start out fully healthy */
2744 if (m_ptr->r_idx == MON_WOUNDED_BEAR)
2745 m_ptr->hp = m_ptr->maxhp / 2;
2746 else m_ptr->hp = m_ptr->maxhp;
2749 /* dealt damage is 0 at initial*/
2750 m_ptr->dealt_damage = 0;
2753 /* Extract the monster base speed */
2754 m_ptr->mspeed = get_mspeed(r_ptr);
2756 if (mode & PM_HASTE) (void)set_monster_fast(player_ptr, g_ptr->m_idx, 100);
2758 /* Give a random starting energy */
2759 if (!ironman_nightmare)
2761 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
2765 /* Nightmare monsters are more prepared */
2766 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
2769 /* Force monster to wait for player, unless in Nightmare mode */
2770 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
2772 /* Monster is still being nice */
2773 m_ptr->mflag |= (MFLAG_NICE);
2775 /* Must repair monsters */
2776 repair_monsters = TRUE;
2779 /* Hack -- see "process_monsters()" */
2780 if (g_ptr->m_idx < hack_m_idx)
2782 /* Monster is still being born */
2783 m_ptr->mflag |= (MFLAG_BORN);
2787 if (r_ptr->flags7 & RF7_SELF_LD_MASK)
2788 player_ptr->update |= (PU_MON_LITE);
2789 else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
2790 player_ptr->update |= (PU_MON_LITE);
2791 update_monster(player_ptr, g_ptr->m_idx, TRUE);
2794 /* Count the monsters on the level */
2795 real_r_ptr(m_ptr)->cur_num++;
2798 * Memorize location of the unique monster in saved floors.
2799 * A unique monster move from old saved floor.
2801 if (current_world_ptr->character_dungeon &&
2802 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
2803 real_r_ptr(m_ptr)->floor_id = player_ptr->floor_id;
2805 /* Hack -- Count the number of "reproducers" */
2806 if (r_ptr->flags2 & RF2_MULTIPLY) floor_ptr->num_repro++;
2808 if (player_ptr->warning && current_world_ptr->character_dungeon)
2810 if (r_ptr->flags1 & RF1_UNIQUE)
2814 GAME_TEXT o_name[MAX_NLEN];
2816 if (r_ptr->level > player_ptr->lev + 30)
2817 color = _("黒く", "black");
2818 else if (r_ptr->level > player_ptr->lev + 15)
2819 color = _("紫色に", "purple");
2820 else if (r_ptr->level > player_ptr->lev + 5)
2821 color = _("ルビー色に", "deep red");
2822 else if (r_ptr->level > player_ptr->lev - 5)
2823 color = _("赤く", "red");
2824 else if (r_ptr->level > player_ptr->lev - 15)
2825 color = _("ピンク色に", "pink");
2827 color = _("白く", "white");
2829 o_ptr = choose_warning_item(player_ptr);
2832 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2833 msg_format(_("%sは%s光った。", "%s glows %s."), o_name, color);
2837 msg_format(_("%s光る物が頭に浮かんだ。", "An %s image forms in your mind."), color);
2842 if (is_explosive_rune_grid(g_ptr))
2844 /* Break the ward */
2845 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2847 /* Describe observable breakage */
2848 if (g_ptr->info & CAVE_MARK)
2850 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2851 project(player_ptr, 0, 2, y, x, 2 * (player_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
2856 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2859 /* Forget the rune */
2860 g_ptr->info &= ~(CAVE_MARK);
2862 /* Break the rune */
2863 g_ptr->info &= ~(CAVE_OBJECT);
2876 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
2879 * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster
2880 * @param r_idx 生成モンスター種族
2881 * @param yp 結果生成位置y座標
2882 * @param xp 結果生成位置x座標
2883 * @param y 中心生成位置y座標
2884 * @param x 中心生成位置x座標
2885 * @param max_dist 生成位置の最大半径
2889 static bool mon_scatter(MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
2891 POSITION place_x[MON_SCAT_MAXD];
2892 POSITION place_y[MON_SCAT_MAXD];
2893 int num[MON_SCAT_MAXD];
2897 if (max_dist >= MON_SCAT_MAXD)
2900 for (i = 0; i < MON_SCAT_MAXD; i++)
2903 floor_type *floor_ptr = p_ptr->current_floor_ptr;
2904 for (nx = x - max_dist; nx <= x + max_dist; nx++)
2906 for (ny = y - max_dist; ny <= y + max_dist; ny++)
2908 /* Ignore annoying locations */
2909 if (!in_bounds(floor_ptr, ny, nx)) continue;
2911 /* Require "line of projection" */
2912 if (!projectable(p_ptr, y, x, ny, nx)) continue;
2916 monster_race *r_ptr = &r_info[r_idx];
2918 /* Require empty space (if not ghostly) */
2919 if (!monster_can_enter(ny, nx, r_ptr, 0))
2924 /* Walls and Monsters block flow */
2925 if (!cave_empty_bold2(floor_ptr, ny, nx)) continue;
2927 /* ... nor on the Pattern */
2928 if (pattern_tile(ny, nx)) continue;
2931 i = distance(y, x, ny, nx);
2939 if (one_in_(num[i]))
2948 while (i < MON_SCAT_MAXD && 0 == num[i])
2950 if (i >= MON_SCAT_MAXD)
2960 * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
2961 * @param who 召喚主のモンスター情報ID
2962 * @param y 中心生成位置y座標
2963 * @param x 中心生成位置x座標
2964 * @param r_idx 生成モンスター種族
2965 * @param mode 生成オプション
2968 static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2970 monster_race *r_ptr = &r_info[r_idx];
2973 int total = 0, extra = 0;
2977 POSITION hack_y[GROUP_MAX];
2978 POSITION hack_x[GROUP_MAX];
2981 /* Pick a group size */
2982 total = randint1(10);
2984 /* Hard monsters, small groups */
2985 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2986 if (r_ptr->level > floor_ptr->dun_level)
2988 extra = r_ptr->level - floor_ptr->dun_level;
2989 extra = 0 - randint1(extra);
2992 /* Easy monsters, large groups */
2993 else if (r_ptr->level < floor_ptr->dun_level)
2995 extra = floor_ptr->dun_level - r_ptr->level;
2996 extra = randint1(extra);
2999 /* Hack -- limit group reduction */
3000 if (extra > 9) extra = 9;
3002 /* Modify the group size */
3006 if (total < 1) total = 1;
3009 if (total > GROUP_MAX) total = GROUP_MAX;
3012 /* Start on the monster */
3017 /* Puddle monsters, breadth first, up to total */
3018 for (n = 0; (n < hack_n) && (hack_n < total); n++)
3020 /* Grab the location */
3021 POSITION hx = hack_x[n];
3022 POSITION hy = hack_y[n];
3024 /* Check each direction, up to total */
3025 for (i = 0; (i < 8) && (hack_n < total); i++)
3029 scatter(player_ptr, &my, &mx, hy, hx, 4, 0);
3031 /* Walls and Monsters block flow */
3032 if (!cave_empty_bold2(floor_ptr, my, mx)) continue;
3034 /* Attempt to place another monster */
3035 if (place_monster_one(player_ptr, who, my, mx, r_idx, mode))
3037 /* Add it to the "hack" set */
3038 hack_y[hack_n] = my;
3039 hack_x[hack_n] = mx;
3051 * @var place_monster_idx
3052 * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
3053 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
3055 static MONSTER_IDX place_monster_idx = 0;
3058 * @var place_monster_m_idx
3059 * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
3060 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
3062 static MONSTER_IDX place_monster_m_idx = 0;
3065 * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
3066 * @param r_idx チェックするモンスター種族のID
3067 * @return 護衛にできるならばtrue
3069 static bool place_monster_can_escort(MONRACE_IDX r_idx)
3071 monster_race *r_ptr = &r_info[place_monster_idx];
3072 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[place_monster_m_idx];
3074 monster_race *z_ptr = &r_info[r_idx];
3076 /* Hack - Escorts have to have the same dungeon flag */
3077 if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return FALSE;
3079 /* Require similar "race" */
3080 if (z_ptr->d_char != r_ptr->d_char) return FALSE;
3082 /* Skip more advanced monsters */
3083 if (z_ptr->level > r_ptr->level) return FALSE;
3085 /* Skip unique monsters */
3086 if (z_ptr->flags1 & RF1_UNIQUE) return FALSE;
3088 /* Paranoia -- Skip identical monsters */
3089 if (place_monster_idx == r_idx) return FALSE;
3091 /* Skip different alignment */
3092 if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3094 if (r_ptr->flags7 & RF7_FRIENDLY)
3096 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3099 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3107 * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
3108 * @param player_ptr プレーヤーへの参照ポインタ
3109 * @param who 召喚主のモンスター情報ID
3112 * @param r_idx 生成するモンスターの種族ID
3113 * @param mode 生成オプション
3114 * @return 生成に成功したらtrue
3116 * Note that certain monsters are now marked as requiring "friends".
3117 * These monsters, if successfully placed, and if the "grp" parameter
3118 * is TRUE, will be surrounded by a "group" of identical monsters.
3120 * Note that certain monsters are now marked as requiring an "escort",
3121 * which is a collection of monsters with similar "race" but lower level.
3123 * Some monsters induce a fake "group" flag on their escorts.
3125 * Note the "bizarre" use of non-recursion to prevent annoying output
3126 * when running a code profiler.
3128 * Note the use of the new "monster allocation table" code to restrict
3129 * the "get_mon_num()" function to "legal" escort types.
3131 bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
3134 monster_race *r_ptr = &r_info[r_idx];
3136 if (!(mode & PM_NO_KAGE) && one_in_(333))
3139 /* Place one monster, or fail */
3140 if (!place_monster_one(player_ptr, who, y, x, r_idx, mode)) return FALSE;
3142 /* Require the "group" flag */
3143 if (!(mode & PM_ALLOW_GROUP)) return TRUE;
3145 place_monster_m_idx = hack_m_idx_ii;
3148 for (i = 0; i < 6; i++)
3150 if (!r_ptr->reinforce_id[i]) break;
3151 n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
3152 for (j = 0; j < n; j++)
3154 POSITION nx, ny, d = 7;
3155 scatter(player_ptr, &ny, &nx, y, x, d, 0);
3156 (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
3160 /* Friends for certain monsters */
3161 if (r_ptr->flags1 & (RF1_FRIENDS))
3163 /* Attempt to place a group */
3164 (void)place_monster_group(player_ptr, who, y, x, r_idx, mode);
3167 /* Escorts for certain monsters */
3168 if (r_ptr->flags1 & (RF1_ESCORT))
3170 /* Set the escort index */
3171 place_monster_idx = r_idx;
3173 /* Try to place several "escorts" */
3174 for (i = 0; i < 32; i++)
3176 POSITION nx, ny, d = 3;
3179 /* Pick a location */
3180 scatter(player_ptr, &ny, &nx, y, x, d, 0);
3182 /* Require empty grids */
3183 if (!cave_empty_bold2(player_ptr->current_floor_ptr, ny, nx)) continue;
3184 get_mon_num_prep(place_monster_can_escort, get_monster_hook2(player_ptr, ny, nx));
3186 /* Pick a random race */
3187 z = get_mon_num(r_ptr->level);
3189 /* Handle failure */
3192 /* Place a single escort */
3193 (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, z, mode);
3195 /* Place a "group" of escorts if needed */
3196 if ((r_info[z].flags1 & RF1_FRIENDS) ||
3197 (r_ptr->flags1 & RF1_ESCORTS))
3199 /* Place a group of monsters */
3200 (void)place_monster_group(player_ptr, place_monster_m_idx, ny, nx, z, mode);
3210 * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
3211 * @param player_ptr プレーヤーへの参照ポインタ
3214 * @param mode 生成オプション
3215 * @return 生成に成功したらtrue
3217 bool place_monster(player_type *player_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
3220 get_mon_num_prep(get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
3222 /* Pick a monster */
3223 r_idx = get_mon_num(player_ptr->current_floor_ptr->monster_level);
3225 /* Handle failure */
3226 if (!r_idx) return FALSE;
3228 /* Attempt to place the monster */
3229 if (place_monster_aux(player_ptr, 0, y, x, r_idx, mode)) return TRUE;
3235 * @brief 指定地点に1種類のモンスター種族による群れを生成する
3236 * @param player_ptr プレーヤーへの参照ポインタ
3239 * @return 生成に成功したらtrue
3241 bool alloc_horde(player_type *player_ptr, POSITION y, POSITION x)
3243 monster_race *r_ptr = NULL;
3244 MONRACE_IDX r_idx = 0;
3246 int attempts = 1000;
3249 get_mon_num_prep(get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
3251 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3254 /* Pick a monster */
3255 r_idx = get_mon_num(floor_ptr->monster_level);
3257 /* Handle failure */
3258 if (!r_idx) return FALSE;
3260 r_ptr = &r_info[r_idx];
3262 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3264 if (r_idx == MON_HAGURE) continue;
3267 if (attempts < 1) return FALSE;
3273 /* Attempt to place the monster */
3274 if (place_monster_aux(player_ptr, 0, y, x, r_idx, 0L)) break;
3277 if (attempts < 1) return FALSE;
3279 m_idx = floor_ptr->grid_array[y][x].m_idx;
3281 if (floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[floor_ptr->m_list[m_idx].r_idx];
3283 for (attempts = randint1(10) + 5; attempts; attempts--)
3285 scatter(player_ptr, &cy, &cx, y, x, 5, 0);
3287 (void)summon_specific(player_ptr, m_idx, cy, cx, floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3293 if (cheat_hear) msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), r_ptr->d_char);
3298 * @brief ダンジョンの主生成を試みる / Put the Guardian
3299 * @param player_ptr プレーヤーへの参照ポインタ
3300 * @param def_val 現在の主の生成状態
3301 * @return 生成に成功したらtrue
3303 bool alloc_guardian(player_type *player_ptr, bool def_val)
3305 MONRACE_IDX guardian = d_info[player_ptr->dungeon_idx].final_guardian;
3307 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3308 if (guardian && (d_info[player_ptr->dungeon_idx].maxdepth == floor_ptr->dun_level) && (r_info[guardian].cur_num < r_info[guardian].max_num))
3312 int try_count = 4000;
3314 /* Find a good position */
3317 /* Get a random spot */
3318 oy = randint1(floor_ptr->height - 4) + 2;
3319 ox = randint1(floor_ptr->width - 4) + 2;
3321 /* Is it a good spot ? */
3322 if (cave_empty_bold2(floor_ptr, oy, ox) && monster_can_cross_terrain(floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0))
3324 /* Place the guardian */
3325 if (place_monster_aux(player_ptr, 0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) return TRUE;
3328 /* One less try count */
3340 * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
3341 * @param dis プレイヤーから離れるべき最低距離
3342 * @param mode 生成オプション
3343 * @return 生成に成功したらtrue
3345 * Place the monster at least "dis" distance from the player.
3346 * Use "slp" to choose the initial "sleep" status
3347 * Use "floor_ptr->monster_level" for the monster level
3349 bool alloc_monster(player_type *player_ptr, POSITION dis, BIT_FLAGS mode)
3351 POSITION y = 0, x = 0;
3352 int attempts_left = 10000;
3354 /* Put the Guardian */
3355 if (alloc_guardian(player_ptr, FALSE)) return TRUE;
3357 /* Find a legal, distant, unoccupied, space */
3358 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3359 while (attempts_left--)
3361 /* Pick a location */
3362 y = randint0(floor_ptr->height);
3363 x = randint0(floor_ptr->width);
3365 /* Require empty floor grid (was "naked") */
3366 if (floor_ptr->dun_level)
3368 if (!cave_empty_bold2(floor_ptr, y, x)) continue;
3372 if (!cave_empty_bold(floor_ptr, y, x)) continue;
3375 /* Accept far away grids */
3376 if (distance(y, x, player_ptr->y, player_ptr->x) > dis) break;
3381 if (cheat_xtra || cheat_hear)
3383 msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
3390 if (randint1(5000) <= floor_ptr->dun_level)
3392 if (alloc_horde(player_ptr, y, x))
3399 /* Attempt to place the monster, allow groups */
3400 if (place_monster(player_ptr, y, x, (mode | PM_ALLOW_GROUP))) return TRUE;
3408 * @brief モンスターが召喚の基本条件に合っているかをチェックする / Hack -- help decide if a monster race is "okay" to summon
3409 * @param r_idx チェックするモンスター種族ID
3410 * @return 召喚対象にできるならばTRUE
3412 static bool summon_specific_okay(MONRACE_IDX r_idx)
3414 monster_race *r_ptr = &r_info[r_idx];
3415 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[summon_specific_who];
3417 /* Hack - Only summon dungeon monsters */
3418 if (!mon_hook_dungeon(r_idx)) return FALSE;
3420 /* Hack -- identify the summoning monster */
3421 if (summon_specific_who > 0)
3424 /* Do not summon enemies */
3426 /* Friendly vs. opposite aligned normal or pet */
3427 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3429 /* Use the player's alignment */
3430 else if (summon_specific_who < 0)
3432 /* Do not summon enemies of the pets */
3433 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3435 if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3439 if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
3441 /* Hack -- no specific type specified */
3442 if (!summon_specific_type) return TRUE;
3444 if ((summon_specific_who < 0) &&
3445 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
3446 monster_has_hostile_align(NULL, 10, -10, r_ptr))
3449 if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON)) return TRUE;
3451 return (summon_specific_aux(m_ptr->r_idx, r_idx));
3456 * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
3457 * @param player_ptr プレーヤーへの参照ポインタ
3458 * @param who 召喚主のモンスター情報ID
3463 * @param mode 生成オプション
3464 * @return 召喚できたらtrueを返す
3467 * We will attempt to place the monster up to 10 times before giving up.
3469 * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3470 * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3471 * Note: None of the other summon codes will ever summon Unique's.
3473 * This function has been changed. We now take the "monster level"
3474 * of the summoning monster as a parameter, and use that, along with
3475 * the current dungeon level, to help determine the level of the
3476 * desired monster. Note that this is an upper bound, and also
3477 * tends to "prefer" monsters of that level. Currently, we use
3478 * the average of the dungeon and monster levels, and then add
3479 * five to allow slight increases in monster power.
3481 * Note that we use the new "monster allocation table" creation code
3482 * to restrict the "get_mon_num()" function to the set of "legal"
3483 * monsters, making this function much faster and more reliable.
3485 * Note that this function may not succeed, though this is very rare.
3487 bool summon_specific(player_type *player_ptr, MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode)
3492 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3493 if (floor_ptr->inside_arena) return FALSE;
3495 if (!mon_scatter(0, &y, &x, y1, x1, 2)) return FALSE;
3497 /* Save the summoner */
3498 summon_specific_who = who;
3500 /* Save the "summon" type */
3501 summon_specific_type = type;
3503 summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
3504 get_mon_num_prep(summon_specific_okay, get_monster_hook2(player_ptr, y, x));
3506 /* Pick a monster, using the level calculation */
3507 r_idx = get_mon_num((floor_ptr->dun_level + lev) / 2 + 5);
3509 /* Handle failure */
3512 summon_specific_type = 0;
3516 if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
3518 /* Attempt to place the monster (awake, allow groups) */
3519 if (!place_monster_aux(player_ptr, who, y, x, r_idx, mode))
3521 summon_specific_type = 0;
3525 summon_specific_type = 0;
3527 sound(SOUND_SUMMON);
3533 * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
3534 * @param player_ptr プレーヤーへの参照ポインタ
3535 * @param who 召喚主のモンスター情報ID
3538 * @param r_idx 生成するモンスター種族ID
3539 * @param mode 生成オプション
3540 * @return 召喚できたらtrueを返す
3542 bool summon_named_creature(player_type *player_ptr, MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
3545 /* if (!r_idx) return; */
3547 /* Prevent illegal monsters */
3548 if (r_idx >= max_r_idx) return FALSE;
3550 if (player_ptr->current_floor_ptr->inside_arena) return FALSE;
3552 if (!mon_scatter(r_idx, &y, &x, oy, ox, 2)) return FALSE;
3554 /* Place it (allow groups) */
3555 return place_monster_aux(player_ptr, who, y, x, r_idx, (mode | PM_NO_KAGE));
3560 * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
3561 * @param player_ptr プレーヤーへの参照ポインタ
3562 * @param m_idx 増殖するモンスター情報ID
3563 * @param clone クローン・モンスター処理ならばtrue
3564 * @param mode 生成オプション
3565 * @return 生成できたらtrueを返す
3567 * Note that "reproduction" REQUIRES empty space.
3569 bool multiply_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
3571 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3572 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
3575 if (!mon_scatter(m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
3578 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
3580 /* Create a new monster (awake, no groups) */
3581 if (!place_monster_aux(player_ptr, m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
3584 /* Hack -- Transfer "clone" flag */
3585 if (clone || (m_ptr->smart & SM_CLONED))
3587 floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3588 floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
3596 * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
3597 * @param m_idx モンスター情報ID
3598 * @param dam 与えたダメージ
3601 * Technically should attempt to treat "Beholder"'s as jelly's
3603 void message_pain(MONSTER_IDX m_idx, HIT_POINT dam)
3605 HIT_POINT oldhp, newhp;
3607 PERCENTAGE percentage;
3609 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
3610 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3612 GAME_TEXT m_name[MAX_NLEN];
3614 monster_desc(m_name, m_ptr, 0);
3616 if (dam == 0) // Notice non-damage
3618 msg_format(_("%^sはダメージを受けていない。", "%^s is unharmed."), m_name);
3622 /* Note -- subtle fix -CFT */
3624 oldhp = newhp + dam;
3625 tmp = (newhp * 100L) / oldhp;
3628 if (my_strchr(",ejmvwQ", r_ptr->d_char)) // Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs
3631 if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3632 else if (percentage > 75) msg_format("%^sはしり込みした。", m_name);
3633 else if (percentage > 50) msg_format("%^sは縮こまった。", m_name);
3634 else if (percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3635 else if (percentage > 20) msg_format("%^sは身もだえした。", m_name);
3636 else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3637 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3639 if (percentage > 95) msg_format("%^s barely notices.", m_name);
3640 else if (percentage > 75) msg_format("%^s flinches.", m_name);
3641 else if (percentage > 50) msg_format("%^s squelches.", m_name);
3642 else if (percentage > 35) msg_format("%^s quivers in pain.", m_name);
3643 else if (percentage > 20) msg_format("%^s writhes about.", m_name);
3644 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3645 else msg_format("%^s jerks limply.", m_name);
3649 else if (my_strchr("l", r_ptr->d_char)) // Fish
3652 if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3653 else if (percentage > 75) msg_format("%^sはしり込みした。", m_name);
3654 else if (percentage > 50) msg_format("%^sは躊躇した。", m_name);
3655 else if (percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3656 else if (percentage > 20) msg_format("%^sは身もだえした。", m_name);
3657 else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3658 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3660 if (percentage > 95) msg_format("%^s barely notices.", m_name);
3661 else if (percentage > 75) msg_format("%^s flinches.", m_name);
3662 else if (percentage > 50) msg_format("%^s hesitates.", m_name);
3663 else if (percentage > 35) msg_format("%^s quivers in pain.", m_name);
3664 else if (percentage > 20) msg_format("%^s writhes about.", m_name);
3665 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3666 else msg_format("%^s jerks limply.", m_name);
3670 else if (my_strchr("g#+<>", r_ptr->d_char)) // Golems, Walls, Doors, Stairs
3673 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3674 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3675 else if (percentage > 50) msg_format("%^sは雷鳴のように吠えた。", m_name);
3676 else if (percentage > 35) msg_format("%^sは苦しげに吠えた。", m_name);
3677 else if (percentage > 20) msg_format("%^sはうめいた。", m_name);
3678 else if (percentage > 10) msg_format("%^sは躊躇した。", m_name);
3679 else msg_format("%^sはくしゃくしゃになった。", m_name);
3681 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3682 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3683 else if (percentage > 50) msg_format("%^s roars thunderously.", m_name);
3684 else if (percentage > 35) msg_format("%^s rumbles.", m_name);
3685 else if (percentage > 20) msg_format("%^s grunts.", m_name);
3686 else if (percentage > 10) msg_format("%^s hesitates.", m_name);
3687 else msg_format("%^s crumples.", m_name);
3691 else if (my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) // Snakes, Hydrae, Reptiles, Mimics
3694 if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3695 else if (percentage > 75) msg_format("%^sはシーッと鳴いた。", m_name);
3696 else if (percentage > 50) msg_format("%^sは怒って頭を上げた。", m_name);
3697 else if (percentage > 35) msg_format("%^sは猛然と威嚇した。", m_name);
3698 else if (percentage > 20) msg_format("%^sは身もだえした。", m_name);
3699 else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3700 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3702 if (percentage > 95) msg_format("%^s barely notices.", m_name);
3703 else if (percentage > 75) msg_format("%^s hisses.", m_name);
3704 else if (percentage > 50) msg_format("%^s rears up in anger.", m_name);
3705 else if (percentage > 35) msg_format("%^s hisses furiously.", m_name);
3706 else if (percentage > 20) msg_format("%^s writhes about.", m_name);
3707 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3708 else msg_format("%^s jerks limply.", m_name);
3712 else if (my_strchr("f", r_ptr->d_char))
3715 if (percentage > 95) msg_format("%sは攻撃に肩をすくめた。", m_name);
3716 else if (percentage > 75) msg_format("%^sは吠えた。", m_name);
3717 else if (percentage > 50) msg_format("%^sは怒って吠えた。", m_name);
3718 else if (percentage > 35) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3719 else if (percentage > 20) msg_format("%^sは痛みで弱々しく鳴いた。", m_name);
3720 else if (percentage > 10) msg_format("%^sは苦痛にうめいた。", m_name);
3721 else msg_format("%sは哀れな鳴き声を出した。", m_name);
3723 if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3724 else if (percentage > 75) msg_format("%^s roars.", m_name);
3725 else if (percentage > 50) msg_format("%^s growls angrily.", m_name);
3726 else if (percentage > 35) msg_format("%^s hisses with pain.", m_name);
3727 else if (percentage > 20) msg_format("%^s mewls in pain.", m_name);
3728 else if (percentage > 10) msg_format("%^s hisses in agony.", m_name);
3729 else msg_format("%^s mewls pitifully.", m_name);
3733 else if (my_strchr("acFIKS", r_ptr->d_char)) // Ants, Centipedes, Flies, Insects, Beetles, Spiders
3736 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3737 else if (percentage > 75) msg_format("%^sはキーキー鳴いた。", m_name);
3738 else if (percentage > 50) msg_format("%^sはヨロヨロ逃げ回った。", m_name);
3739 else if (percentage > 35) msg_format("%^sはうるさく鳴いた。", m_name);
3740 else if (percentage > 20) msg_format("%^sは痛みに痙攣した。", m_name);
3741 else if (percentage > 10) msg_format("%^sは苦痛で痙攣した。", m_name);
3742 else msg_format("%^sはピクピクひきつった。", m_name);
3744 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3745 else if (percentage > 75) msg_format("%^s chitters.", m_name);
3746 else if (percentage > 50) msg_format("%^s scuttles about.", m_name);
3747 else if (percentage > 35) msg_format("%^s twitters.", m_name);
3748 else if (percentage > 20) msg_format("%^s jerks in pain.", m_name);
3749 else if (percentage > 10) msg_format("%^s jerks in agony.", m_name);
3750 else msg_format("%^s twitches.", m_name);
3754 else if (my_strchr("B", r_ptr->d_char)) // Birds
3757 if (percentage > 95) msg_format("%^sはさえずった。", m_name);
3758 else if (percentage > 75) msg_format("%^sはピーピー鳴いた。", m_name);
3759 else if (percentage > 50) msg_format("%^sはギャーギャー鳴いた。", m_name);
3760 else if (percentage > 35) msg_format("%^sはギャーギャー鳴きわめいた。", m_name);
3761 else if (percentage > 20) msg_format("%^sは苦しんだ。", m_name);
3762 else if (percentage > 10) msg_format("%^sはのたうち回った。", m_name);
3763 else msg_format("%^sはキーキーと鳴き叫んだ。", m_name);
3765 if (percentage > 95) msg_format("%^s chirps.", m_name);
3766 else if (percentage > 75) msg_format("%^s twitters.", m_name);
3767 else if (percentage > 50) msg_format("%^s squawks.", m_name);
3768 else if (percentage > 35) msg_format("%^s chatters.", m_name);
3769 else if (percentage > 20) msg_format("%^s jeers.", m_name);
3770 else if (percentage > 10) msg_format("%^s flutters about.", m_name);
3771 else msg_format("%^s squeaks.", m_name);
3775 else if (my_strchr("duDLUW", r_ptr->d_char)) // Dragons, Demons, High Undead
3778 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3779 else if (percentage > 75) msg_format("%^sはしり込みした。", m_name);
3780 else if (percentage > 50) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3781 else if (percentage > 35) msg_format("%^sは痛みでうなった。", m_name);
3782 else if (percentage > 20) msg_format("%^sは痛みに吠えた。", m_name);
3783 else if (percentage > 10) msg_format("%^sは苦しげに叫んだ。", m_name);
3784 else msg_format("%^sは弱々しくうなった。", m_name);
3786 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3787 else if (percentage > 75) msg_format("%^s flinches.", m_name);
3788 else if (percentage > 50) msg_format("%^s hisses in pain.", m_name);
3789 else if (percentage > 35) msg_format("%^s snarls with pain.", m_name);
3790 else if (percentage > 20) msg_format("%^s roars with pain.", m_name);
3791 else if (percentage > 10) msg_format("%^s gasps.", m_name);
3792 else msg_format("%^s snarls feebly.", m_name);
3796 else if (my_strchr("s", r_ptr->d_char)) // Skeletons
3799 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3800 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3801 else if (percentage > 50) msg_format("%^sはカタカタと笑った。", m_name);
3802 else if (percentage > 35) msg_format("%^sはよろめいた。", m_name);
3803 else if (percentage > 20) msg_format("%^sはカタカタ言った。", m_name);
3804 else if (percentage > 10) msg_format("%^sはよろめいた。", m_name);
3805 else msg_format("%^sはガタガタ言った。", m_name);
3807 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3808 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3809 else if (percentage > 50) msg_format("%^s rattles.", m_name);
3810 else if (percentage > 35) msg_format("%^s stumbles.", m_name);
3811 else if (percentage > 20) msg_format("%^s rattles.", m_name);
3812 else if (percentage > 10) msg_format("%^s staggers.", m_name);
3813 else msg_format("%^s clatters.", m_name);
3817 else if (my_strchr("z", r_ptr->d_char)) // Zombies
3820 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3821 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3822 else if (percentage > 50) msg_format("%^sはうめいた。", m_name);
3823 else if (percentage > 35) msg_format("%sは苦しげにうめいた。", m_name);
3824 else if (percentage > 20) msg_format("%^sは躊躇した。", m_name);
3825 else if (percentage > 10) msg_format("%^sはうなった。", m_name);
3826 else msg_format("%^sはよろめいた。", m_name);
3828 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3829 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3830 else if (percentage > 50) msg_format("%^s groans.", m_name);
3831 else if (percentage > 35) msg_format("%^s moans.", m_name);
3832 else if (percentage > 20) msg_format("%^s hesitates.", m_name);
3833 else if (percentage > 10) msg_format("%^s grunts.", m_name);
3834 else msg_format("%^s staggers.", m_name);
3838 else if (my_strchr("G", r_ptr->d_char)) // Ghosts
3841 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3842 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3843 else if (percentage > 50) msg_format("%sはうめいた。", m_name);
3844 else if (percentage > 35) msg_format("%^sは泣きわめいた。", m_name);
3845 else if (percentage > 20) msg_format("%^sは吠えた。", m_name);
3846 else if (percentage > 10) msg_format("%sは弱々しくうめいた。", m_name);
3847 else msg_format("%^sはかすかにうめいた。", m_name);
3849 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3850 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3851 else if (percentage > 50) msg_format("%^s moans.", m_name);
3852 else if (percentage > 35) msg_format("%^s wails.", m_name);
3853 else if (percentage > 20) msg_format("%^s howls.", m_name);
3854 else if (percentage > 10) msg_format("%^s moans softly.", m_name);
3855 else msg_format("%^s sighs.", m_name);
3859 else if (my_strchr("CZ", r_ptr->d_char)) // Dogs and Hounds
3862 if (percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3863 else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3864 else if (percentage > 50) msg_format("%^sは痛みでキャンキャン吠えた。", m_name);
3865 else if (percentage > 35) msg_format("%^sは痛みで鳴きわめいた。", m_name);
3866 else if (percentage > 20) msg_format("%^sは苦痛のあまり鳴きわめいた。", m_name);
3867 else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3868 else msg_format("%^sは弱々しく吠えた。", m_name);
3870 if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3871 else if (percentage > 75) msg_format("%^s snarls with pain.", m_name);
3872 else if (percentage > 50) msg_format("%^s yelps in pain.", m_name);
3873 else if (percentage > 35) msg_format("%^s howls in pain.", m_name);
3874 else if (percentage > 20) msg_format("%^s howls in agony.", m_name);
3875 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3876 else msg_format("%^s yelps feebly.", m_name);
3880 else if (my_strchr("Xbilqrt", r_ptr->d_char)) // One type of creatures (ignore,squeal,shriek)
3883 if (percentage > 95) msg_format("%^sは攻撃を気にとめていない。", m_name);
3884 else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3885 else if (percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3886 else if (percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3887 else if (percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3888 else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3889 else msg_format("%^sは弱々しく叫んだ。", m_name);
3891 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3892 else if (percentage > 75) msg_format("%^s grunts with pain.", m_name);
3893 else if (percentage > 50) msg_format("%^s squeals in pain.", m_name);
3894 else if (percentage > 35) msg_format("%^s shrieks in pain.", m_name);
3895 else if (percentage > 20) msg_format("%^s shrieks in agony.", m_name);
3896 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3897 else msg_format("%^s cries out feebly.", m_name);
3901 else // Another type of creatures (shrug,cry,scream)
3904 if (percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3905 else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3906 else if (percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3907 else if (percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3908 else if (percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3909 else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3910 else msg_format("%^sは弱々しく叫んだ。", m_name);
3912 if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3913 else if (percentage > 75) msg_format("%^s grunts with pain.", m_name);
3914 else if (percentage > 50) msg_format("%^s cries out in pain.", m_name);
3915 else if (percentage > 35) msg_format("%^s screams in pain.", m_name);
3916 else if (percentage > 20) msg_format("%^s screams in agony.", m_name);
3917 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3918 else msg_format("%^s cries out feebly.", m_name);
3926 * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance.
3927 * @param m_idx 更新を行う「モンスター情報ID
3928 * @param what 学習対象ID
3931 void update_smart_learn(MONSTER_IDX m_idx, int what)
3933 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
3934 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3936 /* Not allowed to learn */
3937 if (!smart_learn) return;
3939 /* Too stupid to learn anything */
3940 if (r_ptr->flags2 & (RF2_STUPID)) return;
3942 /* Not intelligent, only learn sometimes */
3943 if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
3945 /* Analyze the knowledge */
3949 if (p_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
3950 if (is_oppose_acid(p_ptr)) m_ptr->smart |= (SM_OPP_ACID);
3951 if (p_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
3955 if (p_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
3956 if (is_oppose_elec(p_ptr)) m_ptr->smart |= (SM_OPP_ELEC);
3957 if (p_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
3961 if (p_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
3962 if (is_oppose_fire(p_ptr)) m_ptr->smart |= (SM_OPP_FIRE);
3963 if (p_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
3967 if (p_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
3968 if (is_oppose_cold(p_ptr)) m_ptr->smart |= (SM_OPP_COLD);
3969 if (p_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
3973 if (p_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
3974 if (is_oppose_pois(p_ptr)) m_ptr->smart |= (SM_OPP_POIS);
3979 if (p_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
3983 if (p_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
3987 if (p_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
3991 if (p_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
3995 if (p_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
3999 if (p_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
4003 if (p_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
4007 if (p_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
4011 if (p_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
4015 if (p_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
4019 if (p_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
4023 if (p_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
4027 if (!p_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
4031 if (p_ptr->reflect) m_ptr->smart |= (SM_IMM_REFLECT);
4038 * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster
4039 * @param m_ptr モンスター参照ポインタ
4042 void monster_drop_carried_objects(monster_type *m_ptr)
4044 OBJECT_IDX this_o_idx, next_o_idx = 0;
4049 /* Drop objects being carried */
4050 floor_type *floor_ptr = p_ptr->current_floor_ptr;
4051 for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4053 o_ptr = &floor_ptr->o_list[this_o_idx];
4054 next_o_idx = o_ptr->next_o_idx;
4057 object_copy(q_ptr, o_ptr);
4059 /* Forget monster */
4060 q_ptr->held_m_idx = 0;
4062 delete_object_idx(floor_ptr, this_o_idx);
4065 (void)drop_near(p_ptr, q_ptr, -1, m_ptr->fy, m_ptr->fx);
4068 /* Forget objects */
4069 m_ptr->hold_o_idx = 0;
4073 * @brief 指定したモンスターに隣接しているモンスターの数を返す。
4074 * / Count number of adjacent monsters
4075 * @param m_idx 隣接数を調べたいモンスターのID
4076 * @return 隣接しているモンスターの数
4078 int get_monster_crowd_number(MONSTER_IDX m_idx)
4080 floor_type *floor_ptr = p_ptr->current_floor_ptr;
4081 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
4082 POSITION my = m_ptr->fy;
4083 POSITION mx = m_ptr->fx;
4087 for (i = 0; i < 7; i++)
4089 int ay = my + ddy_ddd[i];
4090 int ax = mx + ddx_ddd[i];
4092 if (!in_bounds(floor_ptr, ay, ax)) continue;
4094 /* Count number of monsters */
4095 if (floor_ptr->grid_array[ay][ax].m_idx > 0) count++;
4102 bool is_friendly_idx(player_type *player_ptr, MONSTER_IDX m_idx)
4104 return m_idx > 0 && is_friendly(&player_ptr->current_floor_ptr->m_list[(m_idx)]);