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なモンスターの生成を禁止する? */
48 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
50 MONSTER_IDX hack_m_idx = 0; /* Hack -- see "process_monsters()" */
51 MONSTER_IDX hack_m_idx_ii = 0;
53 bool is_friendly_idx(player_type *player_ptr, MONSTER_IDX m_idx);
56 * @brief モンスターの目標地点をセットする / Set the target of counter attack
57 * @param m_ptr モンスターの参照ポインタ
62 void set_target(monster_type *m_ptr, POSITION y, POSITION x)
70 * @brief モンスターの目標地点をリセットする / Reset the target of counter attack
71 * @param m_ptr モンスターの参照ポインタ
74 void reset_target(monster_type *m_ptr)
76 set_target(m_ptr, 0, 0);
81 * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form
82 * @param m_ptr モンスターの参照ポインタ
83 * @return 本当のモンスター種族参照ポインタ
85 monster_race *real_r_ptr(monster_type *m_ptr)
87 return &r_info[real_r_idx(m_ptr)];
91 MONRACE_IDX real_r_idx(monster_type *m_ptr)
93 monster_race *r_ptr = &r_info[m_ptr->r_idx];
94 if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
96 if (r_ptr->flags1 & RF1_UNIQUE)
97 return MON_CHAMELEON_K;
107 * @brief モンスター配列からモンスターを消去する / Delete a monster by index.
108 * @param i 消去するモンスターのID
111 * モンスターを削除するとそのモンスターが拾っていたアイテムも同時に削除される。 /
112 * When a monster is deleted, all of its objects are deleted.
114 void delete_monster_idx(player_type *player_ptr, MONSTER_IDX i)
116 floor_type *floor_ptr = player_ptr->current_floor_ptr;
117 monster_type *m_ptr = &floor_ptr->m_list[i];
118 monster_race *r_ptr = &r_info[m_ptr->r_idx];
120 POSITION y = m_ptr->fy;
121 POSITION x = m_ptr->fx;
123 /* Hack -- Reduce the racial counter */
124 real_r_ptr(m_ptr)->cur_num--;
126 /* Hack -- count the number of "reproducers" */
127 if (r_ptr->flags2 & (RF2_MULTIPLY)) floor_ptr->num_repro--;
129 if (MON_CSLEEP(m_ptr)) (void)set_monster_csleep(player_ptr, i, 0);
130 if (MON_FAST(m_ptr)) (void)set_monster_fast(player_ptr, i, 0);
131 if (MON_SLOW(m_ptr)) (void)set_monster_slow(player_ptr, i, 0);
132 if (MON_STUNNED(m_ptr)) (void)set_monster_stunned(player_ptr, i, 0);
133 if (MON_CONFUSED(m_ptr)) (void)set_monster_confused(player_ptr, i, 0);
134 if (MON_MONFEAR(m_ptr)) (void)set_monster_monfear(player_ptr, i, 0);
135 if (MON_INVULNER(m_ptr)) (void)set_monster_invulner(player_ptr, i, 0, FALSE);
137 /* Hack -- remove target monster */
138 if (i == target_who) target_who = 0;
140 /* Hack -- remove tracked monster */
141 if (i == player_ptr->health_who) health_track(player_ptr, 0);
143 if (player_ptr->pet_t_m_idx == i) player_ptr->pet_t_m_idx = 0;
144 if (player_ptr->riding_t_m_idx == i) player_ptr->riding_t_m_idx = 0;
145 if (player_ptr->riding == i) player_ptr->riding = 0;
147 /* Monster is gone */
148 floor_ptr->grid_array[y][x].m_idx = 0;
150 OBJECT_IDX next_o_idx = 0;
151 for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
154 o_ptr = &floor_ptr->o_list[this_o_idx];
155 next_o_idx = o_ptr->next_o_idx;
156 delete_object_idx(floor_ptr, this_o_idx);
159 (void)WIPE(m_ptr, monster_type);
162 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
164 player_ptr->update |= (PU_MON_LITE);
170 * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
171 * @param player_ptr プレーヤーへの参照ポインタ
176 static void compact_monsters_aux(player_type *player_ptr, MONSTER_IDX i1, MONSTER_IDX i2)
178 if (i1 == i2) return;
181 floor_type *floor_ptr = player_ptr->current_floor_ptr;
183 m_ptr = &floor_ptr->m_list[i1];
185 POSITION y = m_ptr->fy;
186 POSITION x = m_ptr->fx;
190 g_ptr = &floor_ptr->grid_array[y][x];
194 /* Repair objects being carried by monster */
195 OBJECT_IDX next_o_idx = 0;
196 for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
199 o_ptr = &floor_ptr->o_list[this_o_idx];
200 next_o_idx = o_ptr->next_o_idx;
202 /* Reset monster pointer */
203 o_ptr->held_m_idx = i2;
206 /* Hack -- Update the target */
207 if (target_who == i1) target_who = i2;
209 /* Hack -- Update the target */
210 if (player_ptr->pet_t_m_idx == i1) player_ptr->pet_t_m_idx = i2;
211 if (player_ptr->riding_t_m_idx == i1) player_ptr->riding_t_m_idx = i2;
213 /* Hack -- Update the riding */
214 if (player_ptr->riding == i1) player_ptr->riding = i2;
216 /* Hack -- Update the health bar */
217 if (player_ptr->health_who == i1) health_track(player_ptr, i2);
219 /* Hack -- Update parent index */
222 for (int i = 1; i < floor_ptr->m_max; i++)
224 monster_type *m2_ptr = &floor_ptr->m_list[i];
226 if (m2_ptr->parent_m_idx == i1)
227 m2_ptr->parent_m_idx = i2;
232 (void)COPY(&floor_ptr->m_list[i2], &floor_ptr->m_list[i1], monster_type);
235 (void)WIPE(&floor_ptr->m_list[i1], monster_type);
237 for (int i = 0; i < MAX_MTIMED; i++)
239 int mproc_idx = get_mproc_idx(floor_ptr, i1, i);
240 if (mproc_idx >= 0) floor_ptr->mproc_list[i][mproc_idx] = i2;
246 * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
247 * @param player_ptr プレーヤーへの参照ポインタ
248 * @param size 圧縮後のモンスター件数目標
251 * This function can be very dangerous, use with caution!
253 * When actually "compacting" monsters, we base the saving throw
254 * on a combination of monster level, distance from player, and
255 * current "desperation".
257 * After "compacting" (if needed), we "reorder" the monsters into a more
258 * compact order, and we reset the allocation info, and the "live" array.
260 void compact_monsters(player_type *player_ptr, int size)
262 if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
264 /* Compact at least 'size' objects */
265 floor_type *floor_ptr = player_ptr->current_floor_ptr;
266 for (int num = 0, cnt = 1; num < size; cnt++)
268 /* Get more vicious each iteration */
269 int cur_lev = 5 * cnt;
271 /* Get closer each iteration */
272 int cur_dis = 5 * (20 - cnt);
274 /* Check all the monsters */
275 for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++)
277 monster_type *m_ptr = &floor_ptr->m_list[i];
279 monster_race *r_ptr = &r_info[m_ptr->r_idx];
281 /* Paranoia -- skip "dead" monsters */
282 if (!monster_is_valid(m_ptr)) continue;
284 /* Hack -- High level monsters start out "immune" */
285 if (r_ptr->level > cur_lev) continue;
287 if (i == player_ptr->riding) continue;
289 /* Ignore nearby monsters */
290 if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
292 /* Saving throw chance */
295 /* Only compact "Quest" Monsters in emergencies */
296 if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
298 /* Try not to compact Unique Monsters */
299 if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
301 /* All monsters get a saving throw */
302 if (randint0(100) < chance) continue;
304 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
306 GAME_TEXT m_name[MAX_NLEN];
307 monster_desc(player_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
308 exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
311 delete_monster_idx(player_ptr, i);
316 /* Excise dead monsters (backwards!) */
317 for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
319 monster_type *m_ptr = &floor_ptr->m_list[i];
320 if (m_ptr->r_idx) continue;
321 compact_monsters_aux(player_ptr, floor_ptr->m_max - 1, i);
328 * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
329 * @brief プレイヤーのフロア離脱に伴う全モンスター配列の消去 / Delete/Remove all the monsters when the player leaves the level
330 * @param player_ptr プレーヤーへの参照ポインタ
333 * This is an efficient method of simulating multiple calls to the
334 * "delete_monster()" function, with no visual effects.
336 void wipe_monsters_list(player_type *player_ptr)
338 /* Hack -- if Banor or Lupart dies, stay another dead */
339 if (!r_info[MON_BANORLUPART].max_num)
341 if (r_info[MON_BANOR].max_num)
343 r_info[MON_BANOR].max_num = 0;
344 r_info[MON_BANOR].r_pkills++;
345 r_info[MON_BANOR].r_akills++;
346 if (r_info[MON_BANOR].r_tkills < MAX_SHORT)
347 r_info[MON_BANOR].r_tkills++;
350 if (r_info[MON_LUPART].max_num)
352 r_info[MON_LUPART].max_num = 0;
353 r_info[MON_LUPART].r_pkills++;
354 r_info[MON_LUPART].r_akills++;
355 if (r_info[MON_LUPART].r_tkills < MAX_SHORT)
356 r_info[MON_LUPART].r_tkills++;
360 /* Delete all the monsters */
361 floor_type *floor_ptr = player_ptr->current_floor_ptr;
362 for (int i = floor_ptr->m_max - 1; i >= 1; i--)
364 monster_type *m_ptr = &floor_ptr->m_list[i];
365 if (!monster_is_valid(m_ptr)) continue;
367 /* Monster is gone */
368 floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx = 0;
370 (void)WIPE(m_ptr, monster_type);
375 * Wiping racial counters of all monsters and incrementing of racial
376 * counters of monsters in party_mon[] are required to prevent multiple
377 * generation of unique monster who is the minion of player.
380 /* Hack -- Wipe the racial counter of all monster races */
381 for (int i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
383 /* Reset "floor_ptr->m_max" */
384 floor_ptr->m_max = 1;
386 /* Reset "floor_ptr->m_cnt" */
387 floor_ptr->m_cnt = 0;
389 /* Reset "floor_ptr->mproc_max[]" */
390 for (int i = 0; i < MAX_MTIMED; i++) floor_ptr->mproc_max[i] = 0;
392 floor_ptr->num_repro = 0;
394 player_ptr->pet_t_m_idx = 0;
395 player_ptr->riding_t_m_idx = 0;
396 health_track(player_ptr, 0);
401 * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
402 * @brief モンスター配列の空きを探す / Acquires and returns the index of a "free" monster.
403 * @return 利用可能なモンスター配列の添字
405 * This routine should almost never fail, but it *can* happen.
407 MONSTER_IDX m_pop(player_type *player_ptr)
409 /* Normal allocation */
410 floor_type *floor_ptr = player_ptr->current_floor_ptr;
411 if (floor_ptr->m_max < current_world_ptr->max_m_idx)
413 MONSTER_IDX i = floor_ptr->m_max;
419 /* Recycle dead monsters */
420 for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++)
423 m_ptr = &floor_ptr->m_list[i];
424 if (m_ptr->r_idx) continue;
429 /* Warn the player (except during dungeon creation) */
430 if (current_world_ptr->character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
436 * @var summon_specific_type
437 * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
438 * @todo summon_specific_typeグローバル変数の除去と関数引数への代替を行う
440 static int summon_specific_type = 0;
444 * @var summon_specific_who
445 * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
446 * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
448 static int summon_specific_who = -1;
452 * @var summon_unique_okay
453 * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
454 * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
456 static bool summon_unique_okay = FALSE;
460 * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
461 * @param player_ptr プレーヤーへの参照ポインタ
462 * @return 召喚条件が一致するならtrue
465 static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_idx, MONRACE_IDX r_idx)
467 monster_race *r_ptr = &r_info[r_idx];
468 bool is_match = FALSE;
470 /* Check our requirements */
471 switch (summon_specific_type)
475 is_match = (r_ptr->d_char == 'a');
481 is_match = (r_ptr->d_char == 'S');
487 is_match = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
493 is_match = (r_ptr->d_char == 'M');
499 is_match = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
505 is_match = (r_ptr->flags3 & RF3_DEMON);
511 is_match = (r_ptr->flags3 & RF3_UNDEAD);
517 is_match = (r_ptr->flags3 & RF3_DRAGON);
521 case SUMMON_HI_UNDEAD:
523 is_match = ((r_ptr->d_char == 'L') ||
524 (r_ptr->d_char == 'V') ||
525 (r_ptr->d_char == 'W'));
529 case SUMMON_HI_DRAGON:
531 is_match = (r_ptr->d_char == 'D');
535 case SUMMON_HI_DEMON:
537 is_match = (((r_ptr->d_char == 'U') ||
538 (r_ptr->d_char == 'H') ||
539 (r_ptr->d_char == 'B')) &&
540 (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
544 case SUMMON_AMBERITES:
546 is_match = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
552 is_match = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
558 is_match = (r_ptr->d_char == 'm');
563 is_match = (r_ptr->d_char == 'b');
566 case SUMMON_QUYLTHULG:
568 is_match = (r_ptr->d_char == 'Q');
572 case SUMMON_COIN_MIMIC:
574 is_match = (r_ptr->d_char == '$');
580 is_match = ((r_ptr->d_char == '!') ||
581 (r_ptr->d_char == '?') ||
582 (r_ptr->d_char == '=') ||
583 (r_ptr->d_char == '$') ||
584 (r_ptr->d_char == '|'));
590 is_match = (r_ptr->d_char == 'g');
596 is_match = ((r_ptr->d_char == 'U') &&
597 (r_ptr->flags4 & RF4_ROCKET));
603 SYMBOL_CODE summon_kin_type;
606 summon_kin_type = r_info[summoner_idx].d_char;
610 summon_kin_type = get_summon_symbol_from_player(player_ptr);
613 is_match = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
619 is_match = (r_idx == MON_DAWN);
625 is_match = (r_ptr->flags3 & (RF3_ANIMAL));
629 case SUMMON_ANIMAL_RANGER:
631 is_match = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
632 (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
633 !(r_ptr->flags3 & (RF3_DRAGON)) &&
634 !(r_ptr->flags3 & (RF3_EVIL)) &&
635 !(r_ptr->flags3 & (RF3_UNDEAD)) &&
636 !(r_ptr->flags3 & (RF3_DEMON)) &&
637 !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
638 !(r_ptr->flags4 || r_ptr->a_ability_flags1 || r_ptr->a_ability_flags2));
642 case SUMMON_HI_DRAGON_LIVING:
644 is_match = ((r_ptr->d_char == 'D') && monster_living(r_idx));
650 is_match = monster_living(r_idx);
656 is_match = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
660 case SUMMON_BLUE_HORROR:
662 is_match = (r_idx == MON_BLUE_HORROR);
666 case SUMMON_ELEMENTAL:
668 is_match = (r_ptr->d_char == 'E');
674 is_match = (r_ptr->d_char == 'v');
680 is_match = (r_ptr->d_char == 'H');
686 is_match = (r_ptr->d_char == 'B');
690 case SUMMON_KAMIKAZE:
693 for (i = 0; i < 4; i++)
694 if (r_ptr->blow[i].method == RBM_EXPLODE) is_match = TRUE;
698 case SUMMON_KAMIKAZE_LIVING:
702 for (i = 0; i < 4; i++)
703 if (r_ptr->blow[i].method == RBM_EXPLODE) is_match = TRUE;
704 is_match = (is_match && monster_living(r_idx));
710 is_match = (r_idx == MON_MANES);
716 is_match = (r_idx == MON_LOUSE);
720 case SUMMON_GUARDIANS:
722 is_match = (r_ptr->flags7 & RF7_GUARDIAN);
728 is_match = ((r_idx == MON_NOV_PALADIN) ||
729 (r_idx == MON_NOV_PALADIN_G) ||
730 (r_idx == MON_PALADIN) ||
731 (r_idx == MON_W_KNIGHT) ||
732 (r_idx == MON_ULTRA_PALADIN) ||
733 (r_idx == MON_KNI_TEMPLAR));
739 is_match = (r_ptr->d_char == 'B' &&
740 (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
741 (r_ptr->flags8 & RF8_WILD_ONLY));
745 case SUMMON_PIRANHAS:
747 is_match = (r_idx == MON_PIRANHA);
751 case SUMMON_ARMAGE_GOOD:
753 is_match = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
757 case SUMMON_ARMAGE_EVIL:
759 is_match = ((r_ptr->flags3 & RF3_DEMON) ||
760 (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
769 * @var chameleon_change_m_idx
770 * @brief カメレオンの変身先モンスターIDを受け渡すためのグローバル変数
771 * @todo 変数渡しの問題などもあるができればchameleon_change_m_idxのグローバル変数を除去し、関数引き渡しに移行すること
773 static int chameleon_change_m_idx = 0;
776 * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
777 * @brief 指定されたモンスター種族がダンジョンの制限にかかるかどうかをチェックする / Some dungeon types restrict the possible monsters.
778 * @param player_ptr プレーヤーへの参照ポインタ
779 * @param r_idx チェックするモンスター種族ID
780 * @return 召喚条件が一致するならtrue / Return TRUE is the monster is OK and FALSE otherwise
782 static bool restrict_monster_to_dungeon(player_type *player_ptr, MONRACE_IDX r_idx)
784 DUNGEON_IDX d_idx = player_ptr->dungeon_idx;
785 dungeon_type *d_ptr = &d_info[d_idx];
786 monster_race *r_ptr = &r_info[r_idx];
788 if (d_ptr->flags1 & DF1_CHAMELEON)
790 if (chameleon_change_m_idx) return TRUE;
793 if (d_ptr->flags1 & DF1_NO_MAGIC)
795 if (r_idx != MON_CHAMELEON &&
797 !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
798 !(r_ptr->a_ability_flags1 & RF5_NOMAGIC_MASK) &&
799 !(r_ptr->a_ability_flags2 & RF6_NOMAGIC_MASK))
803 if (d_ptr->flags1 & DF1_NO_MELEE)
805 if (r_idx == MON_CHAMELEON) return TRUE;
806 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
807 !(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)) &&
808 !(r_ptr->a_ability_flags2 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
812 floor_type *floor_ptr = player_ptr->current_floor_ptr;
813 if (d_ptr->flags1 & DF1_BEGINNER)
815 if (r_ptr->level > floor_ptr->dun_level)
819 if (d_ptr->special_div >= 64) return TRUE;
820 if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
825 case DUNGEON_MODE_AND:
829 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
835 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
841 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
847 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
851 if (d_ptr->m_a_ability_flags1)
853 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
857 if (d_ptr->m_a_ability_flags2)
859 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
865 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
871 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
877 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
883 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
887 for (a = 0; a < 5; a++)
888 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
893 case DUNGEON_MODE_NAND:
897 if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
903 if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
909 if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
915 if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
919 if (d_ptr->m_a_ability_flags1)
921 if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
925 if (d_ptr->m_a_ability_flags2)
927 if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
933 if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
939 if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
945 if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
951 if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
955 for (a = 0; a < 5; a++)
956 if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
961 case DUNGEON_MODE_OR:
963 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
964 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
965 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
966 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
967 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return TRUE;
968 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return TRUE;
969 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
970 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
971 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
972 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
973 for (a = 0; a < 5; a++)
974 if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
979 case DUNGEON_MODE_NOR:
981 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
982 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
983 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
984 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
985 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return FALSE;
986 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return FALSE;
987 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
988 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
989 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
990 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
991 for (a = 0; a < 5; a++)
992 if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
1002 * Hack -- function hooks to restrict "get_mon_num_prep()" function
1004 monsterrace_hook_type get_mon_num_hook;
1005 monsterrace_hook_type get_mon_num2_hook;
1008 * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
1009 * @param player_ptr プレーヤーへの参照ポインタ
1010 * @param monster_hook 制限関数1
1011 * @param monster_hook2 制限関数2
1014 errr get_mon_num_prep(player_type *player_ptr, monsterrace_hook_type monster_hook, monsterrace_hook_type monster_hook2)
1016 /* Todo: Check the hooks for non-changes */
1018 /* Set the new hooks */
1019 get_mon_num_hook = monster_hook;
1020 get_mon_num2_hook = monster_hook2;
1022 /* Scan the allocation table */
1023 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1024 for (int i = 0; i < alloc_race_size; i++)
1026 monster_race *r_ptr;
1029 alloc_entry *entry = &alloc_race_table[i];
1032 r_ptr = &r_info[entry->index];
1034 /* Skip monsters which don't pass the restriction */
1035 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
1036 (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
1039 if (!player_ptr->phase_out && !chameleon_change_m_idx &&
1040 summon_specific_type != SUMMON_GUARDIANS)
1042 /* Hack -- don't create questors */
1043 if (r_ptr->flags1 & RF1_QUESTOR)
1046 if (r_ptr->flags7 & RF7_GUARDIAN)
1049 /* Depth Monsters never appear out of depth */
1050 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
1051 (r_ptr->level > floor_ptr->dun_level))
1055 /* Accept this monster */
1056 entry->prob2 = entry->prob1;
1058 if (floor_ptr->dun_level && (!floor_ptr->inside_quest || is_fixed_quest_idx(floor_ptr->inside_quest)) &&
1059 !restrict_monster_to_dungeon(player_ptr, entry->index) && !player_ptr->phase_out)
1061 int hoge = entry->prob2 * d_info[player_ptr->dungeon_idx].special_div;
1062 entry->prob2 = hoge / 64;
1063 if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
1072 * @brief 生成モンスター種族を1種生成テーブルから選択する
1073 * @param player_ptr プレーヤーへの参照ポインタ
1075 * @return 選択されたモンスター生成種族
1077 * Choose a monster race that seems "appropriate" to the given level
1079 * This function uses the "prob2" field of the "monster allocation table",
1080 * and various local information, to calculate the "prob3" field of the
1081 * same table, which is then used to choose an "appropriate" monster, in
1082 * a relatively efficient manner.
1084 * Note that "town" monsters will *only* be created in the town, and
1085 * "normal" monsters will *never* be created in the town, unless the
1086 * "level" is "modified", for example, by polymorph or summoning.
1088 * There is a small chance (1/50) of "boosting" the given depth by
1089 * a small amount (up to four levels), except in the town.
1091 * It is (slightly) more likely to acquire a monster of the given level
1092 * than one of a lower level. This is done by choosing several monsters
1093 * appropriate to the given level and keeping the "hardest" one.
1095 * Note that if no monsters are "appropriate", then this function will
1096 * fail, and return zero, but this should *almost* never happen.
1098 MONRACE_IDX get_mon_num(player_type *player_ptr, DEPTH level)
1100 int delay = mysqrt(level * 10000L) + 400L;
1102 int reinforcement_possibility = MAX(NASTY_MON_MAX, NASTY_MON_BASE - ((current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 5000L) - delay / 10)));
1103 int reinforcement_level = MIN(NASTY_MON_PLUS_MAX, 3 + current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 40000L) - delay / 40 + MIN(5, level / 10));
1105 if (d_info[player_ptr->dungeon_idx].flags1 & DF1_MAZE)
1107 reinforcement_possibility = MIN(reinforcement_possibility / 2, reinforcement_possibility - 10);
1108 if (reinforcement_possibility < 2) reinforcement_possibility = 2;
1109 reinforcement_level += 2;
1113 /* Boost the level */
1114 if (!player_ptr->phase_out && !(d_info[player_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1116 if (ironman_nightmare && !randint0(reinforcement_possibility))
1118 level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1122 if (!randint0(reinforcement_possibility))
1124 level += reinforcement_level;
1129 if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1130 if (level < 0) level = 0;
1134 /* Process probabilities */
1135 alloc_entry *table = alloc_race_table;
1136 for (int i = 0; i < alloc_race_size; i++)
1138 /* Monsters are sorted by depth */
1139 if (table[i].level > level) break;
1144 /* Access the "r_idx" of the chosen monster */
1145 MONRACE_IDX r_idx = table[i].index;
1147 /* Access the actual race */
1148 monster_race *r_ptr;
1149 r_ptr = &r_info[r_idx];
1151 if (!player_ptr->phase_out && !chameleon_change_m_idx)
1153 /* Hack -- "unique" monsters must be "unique" */
1154 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1155 (r_ptr->flags7 & (RF7_NAZGUL))) &&
1156 (r_ptr->cur_num >= r_ptr->max_num))
1161 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1162 (r_ptr->cur_num >= 1))
1167 if (r_idx == MON_BANORLUPART)
1169 if (r_info[MON_BANOR].cur_num > 0) continue;
1170 if (r_info[MON_LUPART].cur_num > 0) continue;
1175 table[i].prob3 = table[i].prob2;
1178 total += table[i].prob3;
1181 /* No legal monsters */
1182 if (total <= 0) return 0;
1184 /* Pick a monster */
1185 long value = randint0(total);
1187 int found_count = 0;
1188 for (int i = 0; i < alloc_race_size; i++)
1190 if (value < table[i].prob3) break;
1191 value = value - table[i].prob3;
1196 int p = randint0(100);
1198 /* Try for a "harder" monster once (50%) or twice (10%) */
1202 int j = found_count;
1204 /* Pick a monster */
1205 value = randint0(total);
1207 /* Find the monster */
1208 for (found_count = 0; found_count < alloc_race_size; found_count++)
1210 /* Found the entry */
1211 if (value < table[found_count].prob3) break;
1214 value = value - table[found_count].prob3;
1217 /* Keep the "best" one */
1218 if (table[found_count].level < table[j].level)
1222 /* Try for a "harder" monster twice (10%) */
1226 int j = found_count;
1228 /* Pick a monster */
1229 value = randint0(total);
1231 /* Find the monster */
1232 for (found_count = 0; found_count < alloc_race_size; found_count++)
1234 /* Found the entry */
1235 if (value < table[found_count].prob3) break;
1238 value = value - table[found_count].prob3;
1241 /* Keep the "best" one */
1242 if (table[found_count].level < table[j].level)
1246 return (table[found_count].index);
1251 * @brief モンスターの呼称を作成する / Build a string describing a monster in some way.
1252 * @param desc 記述出力先の文字列参照ポインタ
1253 * @param m_ptr モンスターの参照ポインタ
1254 * @param mode 呼称オプション
1257 * We can correctly describe monsters based on their visibility.
1258 * We can force all monsters to be treated as visible or invisible.
1259 * We can build nominatives, objectives, possessives, or reflexives.
1260 * We can selectively pronominalize hidden, visible, or all monsters.
1261 * We can use definite or indefinite descriptions for hidden monsters.
1262 * We can use definite or indefinite descriptions for visible monsters.
1264 * Pronominalization involves the gender whenever possible and allowed,
1265 * so that by cleverly requesting pronominalization / visibility, you
1266 * can get messages like "You hit someone. She screams in agony!".
1268 * Reflexives are acquired by requesting Objective plus Possessive.
1270 * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1271 * unless the "Assume Visible" mode is requested.
1273 * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1274 * If neither m_ptr nor r_ptr is given, the monster is assumed to
1275 * be neuter, singular, and hidden (unless "Assume Visible" is set),
1276 * in which case you may be in trouble... :-)
1278 * I am assuming that no monster name is more than 70 characters long,
1279 * so that "char desc[80];" is sufficiently large for any result.
1282 * MD_OBJECTIVE --> Objective (or Reflexive)
1283 * MD_POSSESSIVE --> Possessive (or Reflexive)
1284 * MD_INDEF_HIDDEN --> Use indefinites for hidden monsters ("something")
1285 * MD_INDEF_VISIBLE --> Use indefinites for visible monsters ("a kobold")
1286 * MD_PRON_HIDDEN --> Pronominalize hidden monsters
1287 * MD_PRON_VISIBLE --> Pronominalize visible monsters
1288 * MD_ASSUME_HIDDEN --> Assume the monster is hidden
1289 * MD_ASSUME_VISIBLE --> Assume the monster is visible
1290 * MD_TRUE_NAME --> Chameleon's true name
1291 * MD_IGNORE_HALLU --> Ignore hallucination, and penetrate shape change
1294 * 0x00 --> Full nominative name ("the kobold") or "it"
1295 * MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1296 * MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1297 * MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1298 * MD_PRON_VISIBLE | MD_POSSESSIVE
1299 * --> Possessive, genderized if visable ("his") or "its"
1300 * MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1301 * --> Reflexive, genderized if visable ("himself") or "itself"
1303 void monster_desc(player_type *player_ptr, char *desc, monster_type *m_ptr, BIT_FLAGS mode)
1305 monster_race *r_ptr;
1306 r_ptr = &r_info[m_ptr->ap_r_idx];
1308 /* Mode of MD_TRUE_NAME will reveal Chameleon's true name */
1309 concptr name = (mode & MD_TRUE_NAME) ? (r_name + real_r_ptr(m_ptr)->name) : (r_name + r_ptr->name);
1311 /* Are we hallucinating? (Idea from Nethack...) */
1312 GAME_TEXT silly_name[1024];
1314 if (player_ptr->image && !(mode & MD_IGNORE_HALLU))
1318 if (!get_rnd_line(_("silly_j.txt", "silly.txt"), m_ptr->r_idx, silly_name))
1324 monster_race *hallu_race;
1328 hallu_race = &r_info[randint1(max_r_idx - 1)];
1329 } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
1331 strcpy(silly_name, (r_name + hallu_race->name));
1334 /* Better not strcpy it, or we could corrupt r_info... */
1338 /* Can we "see" it (exists + forced, or visible + not unforced) */
1339 bool seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1341 /* Sexed Pronouns (seen and allowed, or unseen and allowed) */
1342 bool pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1344 /* First, try using pronouns, or describing hidden monsters */
1345 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1348 /* an encoding of the monster "sex" */
1351 /* Extract the gender (if applicable) */
1352 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1353 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1355 /* Ignore the gender (if desired) */
1356 if (!m_ptr || !pron) kind = 0x00;
1359 /* Assume simple result */
1360 concptr res = _("何か", "it");
1362 /* Brute force: split on the possibilities */
1363 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1366 case 0x00: res = "何か"; break;
1367 case 0x00 + (MD_OBJECTIVE) : res = "何か"; break;
1368 case 0x00 + (MD_POSSESSIVE) : res = "何かの"; break;
1369 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "何か自身"; break;
1370 case 0x00 + (MD_INDEF_HIDDEN) : res = "何か"; break;
1371 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "何か"; break;
1372 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "何か"; break;
1373 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "それ自身"; break;
1375 case 0x00: res = "it"; break;
1376 case 0x00 + (MD_OBJECTIVE) : res = "it"; break;
1377 case 0x00 + (MD_POSSESSIVE) : res = "its"; break;
1378 case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "itself"; break;
1379 case 0x00 + (MD_INDEF_HIDDEN) : res = "something"; break;
1380 case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "something"; break;
1381 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "something's"; break;
1382 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "itself"; break;
1387 case 0x10: res = "彼"; break;
1388 case 0x10 + (MD_OBJECTIVE) : res = "彼"; break;
1389 case 0x10 + (MD_POSSESSIVE) : res = "彼の"; break;
1390 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼自身"; break;
1391 case 0x10 + (MD_INDEF_HIDDEN) : res = "誰か"; break;
1392 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "誰か"; break;
1393 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "誰かの"; break;
1394 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼自身"; break;
1396 case 0x10: res = "he"; break;
1397 case 0x10 + (MD_OBJECTIVE) : res = "him"; break;
1398 case 0x10 + (MD_POSSESSIVE) : res = "his"; break;
1399 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "himself"; break;
1400 case 0x10 + (MD_INDEF_HIDDEN) : res = "someone"; break;
1401 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "someone"; break;
1402 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "someone's"; break;
1403 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "himself"; break;
1408 case 0x20: res = "彼女"; break;
1409 case 0x20 + (MD_OBJECTIVE) : res = "彼女"; break;
1410 case 0x20 + (MD_POSSESSIVE) : res = "彼女の"; break;
1411 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼女自身"; break;
1412 case 0x20 + (MD_INDEF_HIDDEN) : res = "誰か"; break;
1413 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "誰か"; break;
1414 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "誰かの"; break;
1415 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼女自身"; break;
1417 case 0x20: res = "she"; break;
1418 case 0x20 + (MD_OBJECTIVE) : res = "her"; break;
1419 case 0x20 + (MD_POSSESSIVE) : res = "her"; break;
1420 case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "herself"; break;
1421 case 0x20 + (MD_INDEF_HIDDEN) : res = "someone"; break;
1422 case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "someone"; break;
1423 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "someone's"; break;
1424 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "herself"; break;
1428 /* Copy the result */
1429 (void)strcpy(desc, res);
1433 /* Handle visible monsters, "reflexive" request */
1434 if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1436 /* The monster is visible, so use its gender */
1437 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, _("彼女自身", "herself"));
1438 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, _("彼自身", "himself"));
1439 else strcpy(desc, _("それ自身", "itself"));
1443 /* Handle all other visible monster requests */
1445 if (is_pet(m_ptr) && !is_original_ap(m_ptr))
1452 while (strncmp(t, "』", 2) && *t) t++;
1456 (void)sprintf(desc, "%s?』", buf);
1459 (void)sprintf(desc, "%s?", name);
1461 (void)sprintf(desc, "%s?", name);
1466 /* It could be a Unique */
1467 if ((r_ptr->flags1 & RF1_UNIQUE) && !(player_ptr->image && !(mode & MD_IGNORE_HALLU)))
1469 /* Start with the name (thus nominative and objective) */
1470 if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1477 while (strncmp(t, "』", 2) && *t) t++;
1481 (void)sprintf(desc, "%s?』", buf);
1484 (void)sprintf(desc, "%s?", name);
1486 (void)sprintf(desc, "%s?", name);
1490 /* Inside monster arena, and it is not your mount */
1491 else if (player_ptr->phase_out &&
1492 !(player_ptr->riding && (&floor_ptr->m_list[player_ptr->riding] == m_ptr)))
1494 /* It is a fake unique monster */
1495 (void)sprintf(desc, _("%sもどき", "fake %s"), name);
1500 (void)strcpy(desc, name);
1504 /* It could be an indefinite monster */
1505 else if (mode & MD_INDEF_VISIBLE)
1507 /* XXX Check plurality for "some" */
1509 /* Indefinite monsters need an indefinite article */
1511 (void)strcpy(desc, "");
1513 (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1516 (void)strcat(desc, name);
1519 /* It could be a normal, definite, monster */
1522 /* Definite monsters need a definite article */
1524 (void)strcpy(desc, _("あなたの", "your "));
1526 (void)strcpy(desc, _("", "the "));
1528 (void)strcat(desc, name);
1532 if (m_ptr->nickname)
1535 sprintf(buf, _("「%s」", " called %s"), quark_str(m_ptr->nickname));
1539 if (player_ptr->riding && (&floor_ptr->m_list[player_ptr->riding] == m_ptr))
1541 strcat(desc, _("(乗馬中)", "(riding)"));
1544 if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1546 if (r_ptr->flags1 & RF1_UNIQUE)
1548 strcat(desc, _("(カメレオンの王)", "(Chameleon Lord)"));
1552 strcat(desc, _("(カメレオン)", "(Chameleon)"));
1556 if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr))
1558 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1561 /* Handle the Possessive as a special afterthought */
1562 if (mode & MD_POSSESSIVE)
1564 /* XXX Check for trailing "s" */
1566 /* Simply append "apostrophe" and "s" */
1567 (void)strcat(desc, _("の", "'s"));
1573 * @brief モンスターIDを取り、モンスター名をm_nameに代入する /
1574 * @param player_ptr プレーヤーへの参照ポインタ
1575 * @param m_idx モンスターID
1576 * @param m_name モンスター名を入力する配列
1578 void monster_name(player_type *player_ptr, MONSTER_IDX m_idx, char* m_name)
1580 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
1581 monster_desc(player_ptr, m_name, m_ptr, 0x00);
1586 * @brief モンスターの調査による思い出補完処理 / Learn about a monster (by "probing" it)
1587 * @param player_ptr プレーヤーへの参照ポインタ
1588 * @param r_idx 補完されるモンスター種族ID
1589 * @return 明らかになった情報の度数
1591 * Return the number of new flags learnt. -Mogami-
1593 int lore_do_probe(player_type *player_ptr, MONRACE_IDX r_idx)
1595 /* Maximal info about awareness */
1597 monster_race *r_ptr = &r_info[r_idx];
1598 if (r_ptr->r_wake != MAX_UCHAR) n++;
1599 if (r_ptr->r_ignore != MAX_UCHAR) n++;
1600 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1602 /* Observe "maximal" attacks */
1603 for (int i = 0; i < 4; i++)
1605 /* Examine "actual" blows */
1606 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1608 /* Maximal observations */
1609 if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1610 r_ptr->r_blows[i] = MAX_UCHAR;
1616 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1617 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1618 ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1619 ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1620 ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1621 ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1623 /* Only "valid" drops */
1624 if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1626 if (r_ptr->r_drop_item != tmp_byte) n++;
1627 r_ptr->r_drop_item = tmp_byte;
1629 if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1631 if (r_ptr->r_drop_gold != tmp_byte) n++;
1632 r_ptr->r_drop_gold = tmp_byte;
1635 /* Observe many spells */
1636 if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1637 r_ptr->r_cast_spell = MAX_UCHAR;
1639 /* Count unknown flags */
1640 for (int i = 0; i < 32; i++)
1642 if (!(r_ptr->r_flags1 & (1L << i)) &&
1643 (r_ptr->flags1 & (1L << i))) n++;
1644 if (!(r_ptr->r_flags2 & (1L << i)) &&
1645 (r_ptr->flags2 & (1L << i))) n++;
1646 if (!(r_ptr->r_flags3 & (1L << i)) &&
1647 (r_ptr->flags3 & (1L << i))) n++;
1648 if (!(r_ptr->r_flags4 & (1L << i)) &&
1649 (r_ptr->flags4 & (1L << i))) n++;
1650 if (!(r_ptr->r_flags5 & (1L << i)) &&
1651 (r_ptr->a_ability_flags1 & (1L << i))) n++;
1652 if (!(r_ptr->r_flags6 & (1L << i)) &&
1653 (r_ptr->a_ability_flags2 & (1L << i))) n++;
1654 if (!(r_ptr->r_flagsr & (1L << i)) &&
1655 (r_ptr->flagsr & (1L << i))) n++;
1658 /* Know all the flags */
1659 r_ptr->r_flags1 = r_ptr->flags1;
1660 r_ptr->r_flags2 = r_ptr->flags2;
1661 r_ptr->r_flags3 = r_ptr->flags3;
1662 r_ptr->r_flags4 = r_ptr->flags4;
1663 r_ptr->r_flags5 = r_ptr->a_ability_flags1;
1664 r_ptr->r_flags6 = r_ptr->a_ability_flags2;
1665 r_ptr->r_flagsr = r_ptr->flagsr;
1667 /* Know about evolution */
1668 if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1669 r_ptr->r_xtra1 |= MR1_SINKA;
1671 /* Update monster recall window */
1672 if (player_ptr->monster_race_idx == r_idx)
1674 player_ptr->window |= (PW_MONSTER);
1682 * @brief モンスターの撃破に伴うドロップ情報の保管処理 / Take note that the given monster just dropped some treasure
1683 * @param player_ptr プレーヤーへの参照ポインタ
1684 * @param m_idx モンスター情報のID
1685 * @param num_item 手に入れたアイテム数
1686 * @param num_gold 手に入れた財宝の単位数
1689 * Note that learning the "GOOD"/"GREAT" flags gives information
1690 * about the treasure (even when the monster is killed for the first
1691 * time, such as uniques, and the treasure has not been examined yet).
1693 * This "indirect" method is used to prevent the player from learning
1694 * exactly how much treasure a monster can drop from observing only
1695 * a single example of a drop. This method actually observes how much
1696 * gold and items are dropped, and remembers that information to be
1697 * described later by the monster recall code.
1699 void lore_treasure(player_type *player_ptr, MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
1701 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
1702 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1704 /* If the monster doesn't have original appearance, don't note */
1705 if (!is_original_ap(m_ptr)) return;
1707 /* Note the number of things dropped */
1708 if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1709 if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1711 /* Hack -- memorize the good/great flags */
1712 if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1713 if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1715 /* Update monster recall window */
1716 if (player_ptr->monster_race_idx == m_ptr->r_idx)
1718 player_ptr->window |= (PW_MONSTER);
1724 * @brief モンスターの各情報を更新する / This function updates the monster record of the given monster
1725 * @param m_idx 更新するモンスター情報のID
1726 * @param full プレイヤーとの距離更新を行うならばtrue
1729 * This involves extracting the distance to the player (if requested),
1730 * and then checking for visibility (natural, infravision, see-invis,
1731 * telepathy), updating the monster visibility flag, redrawing (or
1732 * erasing) the monster when its visibility changes, and taking note
1733 * of any interesting monster flags (cold-blooded, invisible, etc).
1735 * Note the new "mflag" field which encodes several monster state flags,
1736 * including "view" for when the monster is currently in line of sight,
1737 * and "mark" for when the monster is currently visible via detection.
1739 * The only monster fields that are changed here are "cdis" (the
1740 * distance from the player), "ml" (visible to the player), and
1741 * "mflag" (to maintain the "MFLAG_VIEW" flag).
1743 * Note the special "update_monsters()" function which can be used to
1744 * call this function once for every monster.
1746 * Note the "full" flag which requests that the "cdis" field be updated,
1747 * this is only needed when the monster (or the player) has moved.
1749 * Every time a monster moves, we must call this function for that
1750 * monster, and update the distance, and the visibility. Every time
1751 * the player moves, we must call this function for every monster, and
1752 * update the distance, and the visibility. Whenever the player "state"
1753 * changes in certain ways ("blindness", "infravision", "telepathy",
1754 * and "see invisible"), we must call this function for every monster,
1755 * and update the visibility.
1757 * Routines that change the "illumination" of a grid must also call this
1758 * function for any monster in that grid, since the "visibility" of some
1759 * monsters may be based on the illumination of their grid.
1761 * Note that this function is called once per monster every time the
1762 * player moves. When the player is running, this function is one
1763 * of the primary bottlenecks, along with "update_view()" and the
1764 * "process_monsters()" code, so efficiency is important.
1766 * Note the optimized "inline" version of the "distance()" function.
1768 * A monster is "visible" to the player if (1) it has been detected
1769 * by the player, (2) it is close to the player and the player has
1770 * telepathy, or (3) it is close to the player, and in line of sight
1771 * of the player, and it is "illuminated" by some combination of
1772 * infravision, torch light, or permanent light (invisible monsters
1773 * are only affected by "light" if the player can see invisible).
1775 * Monsters which are not on the current panel may be "visible" to
1776 * the player, and their descriptions will include an "offscreen"
1777 * reference. Currently, offscreen monsters cannot be targetted
1778 * or viewed directly, but old targets will remain set. XXX XXX
1780 * The player can choose to be disturbed by several things, including
1781 * "disturb_move" (monster which is viewable moves in some way), and
1782 * "disturb_near" (monster which is "easily" viewable moves in some
1783 * way). Note that "moves" includes "appears" and "disappears".
1785 void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full)
1787 monster_type *m_ptr = &subject_ptr->current_floor_ptr->m_list[m_idx];
1788 monster_race *r_ptr = &r_info[m_ptr->r_idx];
1790 bool do_disturb = disturb_move;
1792 POSITION fy = m_ptr->fy;
1793 POSITION fx = m_ptr->fx;
1798 /* Seen by vision */
1801 /* Non-Ninja player in the darkness */
1802 bool in_darkness = (d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !subject_ptr->see_nocto;
1807 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1809 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= subject_ptr->lev)
1816 /* Distance components */
1817 int dy = (subject_ptr->y > fy) ? (subject_ptr->y - fy) : (fy - subject_ptr->y);
1818 int dx = (subject_ptr->x > fx) ? (subject_ptr->x - fx) : (fx - subject_ptr->x);
1820 /* Approximate distance */
1821 distance = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
1823 /* Restrict distance */
1824 if (distance > 255) distance = 255;
1826 if (!distance) distance = 1;
1828 /* Save the distance */
1829 m_ptr->cdis = distance;
1832 /* Extract distance */
1835 /* Extract the distance */
1836 distance = m_ptr->cdis;
1840 if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
1843 if (distance <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
1845 if (!in_darkness || (distance <= MAX_SIGHT / 4))
1847 if (subject_ptr->special_defense & KATA_MUSOU)
1852 if (is_original_ap(m_ptr) && !subject_ptr->image)
1854 /* Hack -- Memorize mental flags */
1855 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1856 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1860 /* Basic telepathy */
1861 /* Snipers get telepathy when they concentrate deeper */
1862 else if (subject_ptr->telepathy)
1864 /* Empty mind, no telepathy */
1865 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
1867 /* Memorize flags */
1868 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
1871 /* Weird mind, occasional telepathy */
1872 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
1874 /* One in ten individuals are detectable */
1875 if ((m_idx % 10) == 5)
1880 if (is_original_ap(m_ptr) && !subject_ptr->image)
1882 /* Memorize flags */
1883 r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
1885 /* Hack -- Memorize mental flags */
1886 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1887 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1892 /* Normal mind, allow telepathy */
1898 if (is_original_ap(m_ptr) && !subject_ptr->image)
1900 /* Hack -- Memorize mental flags */
1901 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1902 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1907 if ((subject_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
1910 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
1913 if ((subject_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
1916 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
1919 if ((subject_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
1922 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
1925 if ((subject_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
1928 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
1931 if ((subject_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
1934 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
1937 if ((subject_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
1940 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
1943 if ((subject_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
1946 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
1949 if ((subject_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
1952 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
1955 if ((subject_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
1958 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
1961 if ((subject_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
1964 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
1967 if ((subject_ptr->esp_nonliving) &&
1968 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
1971 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
1974 if ((subject_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
1977 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
1981 /* Normal line of sight, and not blind */
1982 if (player_has_los_bold(subject_ptr, fy, fx) && !subject_ptr->blind)
1984 bool do_invisible = FALSE;
1985 bool do_cold_blood = FALSE;
1987 /* Snipers can see targets in darkness when they concentrate deeper */
1988 if (subject_ptr->concent >= CONCENT_RADAR_THRESHOLD)
1994 /* Use "infravision" */
1995 if (distance <= subject_ptr->see_infra)
1997 /* Handle "cold blooded" monsters */
1998 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
2000 do_cold_blood = TRUE;
2003 /* Handle "warm blooded" monsters */
2011 /* Use "illumination" */
2012 if (player_can_see_bold(subject_ptr, fy, fx))
2014 /* Handle "invisible" monsters */
2015 if (r_ptr->flags2 & (RF2_INVISIBLE))
2017 do_invisible = TRUE;
2020 if (subject_ptr->see_inv)
2027 /* Handle "normal" monsters */
2038 if (is_original_ap(m_ptr) && !subject_ptr->image)
2040 /* Memorize flags */
2041 if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
2042 if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
2048 /* The monster is now visible */
2051 /* It was previously unseen */
2054 /* Mark as visible */
2057 /* Draw the monster */
2060 /* Update health bar as needed */
2061 if (subject_ptr->health_who == m_idx) subject_ptr->redraw |= (PR_HEALTH);
2062 if (subject_ptr->riding == m_idx) subject_ptr->redraw |= (PR_UHEALTH);
2064 /* Hack -- Count "fresh" sightings */
2065 if (!subject_ptr->image)
2067 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
2068 r_info[MON_KAGE].r_sights++;
2069 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
2073 if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
2075 sanity_blast(subject_ptr, m_ptr, FALSE);
2078 /* Disturb on appearance */
2079 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)))
2081 if (disturb_pets || is_hostile(m_ptr))
2082 disturb(subject_ptr, TRUE, TRUE);
2087 /* The monster is not visible */
2090 /* It was previously seen */
2093 /* Mark as not visible */
2096 /* Erase the monster */
2099 /* Update health bar as needed */
2100 if (subject_ptr->health_who == m_idx) subject_ptr->redraw |= (PR_HEALTH);
2101 if (subject_ptr->riding == m_idx) subject_ptr->redraw |= (PR_UHEALTH);
2103 /* Disturb on disappearance */
2106 if (disturb_pets || is_hostile(m_ptr))
2107 disturb(subject_ptr, TRUE, TRUE);
2113 /* The monster is now easily visible */
2117 if (!(m_ptr->mflag & (MFLAG_VIEW)))
2119 /* Mark as easily visible */
2120 m_ptr->mflag |= (MFLAG_VIEW);
2122 /* Disturb on appearance */
2125 if (disturb_pets || is_hostile(m_ptr))
2126 disturb(subject_ptr, TRUE, TRUE);
2133 /* The monster is not easily visible */
2135 if (!(m_ptr->mflag & (MFLAG_VIEW))) return;
2137 /* Mark as not easily visible */
2138 m_ptr->mflag &= ~(MFLAG_VIEW);
2140 /* Disturb on disappearance */
2143 if (disturb_pets || is_hostile(m_ptr))
2144 disturb(subject_ptr, TRUE, TRUE);
2150 * @param player_ptr プレーヤーへの参照ポインタ
2151 * @brief 単純に生存している全モンスターの更新処理を行う / This function simply updates all the (non-dead) monsters (see above).
2152 * @param full 距離更新を行うならtrue
2155 void update_monsters(player_type *player_ptr, bool full)
2157 /* Update each (live) monster */
2158 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2159 for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++)
2161 monster_type *m_ptr = &floor_ptr->m_list[i];
2162 if (!monster_is_valid(m_ptr)) continue;
2163 update_monster(player_ptr, i, full);
2169 * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
2170 * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
2171 * @param player_ptr プレーヤーへの参照ポインタ
2172 * @brief カメレオンの王の変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2173 * @param r_idx モンスター種族ID
2174 * @return 対象にできるならtrueを返す
2176 static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
2178 floor_type *floor_ptr = p_ptr->current_floor_ptr;
2179 monster_race *r_ptr = &r_info[r_idx];
2180 monster_type *m_ptr = &floor_ptr->m_list[chameleon_change_m_idx];
2181 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2183 if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
2184 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2186 if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
2188 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))
2191 if (!monster_can_cross_terrain(floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2194 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2196 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
2200 else if (summon_specific_who > 0)
2202 if (monster_has_hostile_align(&floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2210 * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
2211 * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
2212 * @brief カメレオンの変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
2213 * @param r_idx モンスター種族ID
2214 * @return 対象にできるならtrueを返す
2215 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2217 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
2219 floor_type *floor_ptr = p_ptr->current_floor_ptr;
2220 monster_race *r_ptr = &r_info[r_idx];
2221 monster_type *m_ptr = &floor_ptr->m_list[chameleon_change_m_idx];
2222 monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
2224 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2225 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2226 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2228 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))
2231 if (!monster_can_cross_terrain(floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
2234 if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
2236 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
2237 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
2238 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
2242 else if (summon_specific_who > 0)
2244 if (monster_has_hostile_align(&floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
2247 return (*(get_monster_hook(p_ptr)))(r_idx);
2253 * @param player_ptr プレーヤーへの参照ポインタ
2254 * @param m_idx 変身処理を受けるモンスター情報のID
2255 * @param born 生成時の初変身先指定ならばtrue
2256 * @param r_idx 旧モンスター種族のID
2259 void choose_new_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
2261 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2262 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
2263 monster_race *r_ptr;
2265 bool old_unique = FALSE;
2266 if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2268 if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2269 r_ptr = &r_info[r_idx];
2271 char old_m_name[MAX_NLEN];
2272 monster_desc(player_ptr, old_m_name, m_ptr, 0);
2278 chameleon_change_m_idx = m_idx;
2280 get_mon_num_prep(player_ptr, monster_hook_chameleon_lord, NULL);
2282 get_mon_num_prep(player_ptr, monster_hook_chameleon, NULL);
2285 level = r_info[MON_CHAMELEON_K].level;
2286 else if (!floor_ptr->dun_level)
2287 level = wilderness[player_ptr->wilderness_y][player_ptr->wilderness_x].level;
2289 level = floor_ptr->dun_level;
2291 if (d_info[player_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level += 2 + randint1(3);
2293 r_idx = get_mon_num(player_ptr, level);
2294 r_ptr = &r_info[r_idx];
2296 chameleon_change_m_idx = 0;
2300 m_ptr->r_idx = r_idx;
2301 m_ptr->ap_r_idx = r_idx;
2302 update_monster(player_ptr, m_idx, FALSE);
2303 lite_spot(m_ptr->fy, m_ptr->fx);
2305 int old_r_idx = m_ptr->r_idx;
2306 if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2307 (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2308 player_ptr->update |= (PU_MON_LITE);
2312 /* Sub-alignment of a chameleon */
2313 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2315 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2316 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2317 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2322 if (m_idx == player_ptr->riding)
2324 GAME_TEXT m_name[MAX_NLEN];
2325 monster_desc(player_ptr, m_name, m_ptr, 0);
2326 msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
2327 if (!(r_ptr->flags7 & RF7_RIDING))
2328 if (rakuba(player_ptr, 0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
2331 /* Extract the monster base speed */
2332 m_ptr->mspeed = get_mspeed(player_ptr, r_ptr);
2334 int oldmaxhp = m_ptr->max_maxhp;
2335 /* Assign maximal hitpoints */
2336 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2338 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2342 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2345 /* Monsters have double hitpoints in Nightmare mode */
2346 if (ironman_nightmare)
2348 u32b hp = m_ptr->max_maxhp * 2L;
2349 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2352 m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2353 if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2354 m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2355 m_ptr->dealt_damage = 0;
2360 * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
2361 * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
2362 * @param r_idx モンスター種族ID
2363 * @return 対象にできるならtrueを返す
2364 * @todo グローバル変数対策の上 monster_hook.cへ移す。
2366 static bool monster_hook_tanuki(MONRACE_IDX r_idx)
2368 monster_race *r_ptr = &r_info[r_idx];
2370 if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2371 if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2372 if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2373 if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2375 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))
2378 return (*(get_monster_hook(p_ptr)))(r_idx);
2383 * @param player_ptr プレーヤーへの参照ポインタ
2384 * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
2385 * @param r_idx モンスター種族ID
2386 * @return モンスター種族の表層ID
2388 static MONRACE_IDX initial_r_appearance(player_type *player_ptr, MONRACE_IDX r_idx, BIT_FLAGS generate_mode)
2390 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2391 if (player_ptr->pseikaku == SEIKAKU_CHARGEMAN && !(generate_mode & (PM_MULTIPLY | PM_KAGE)))
2393 if (floor_ptr->base_level == 0 ||
2394 (one_in_(5) && my_strchr("hkoptuyAHOPTUVY", r_info[r_idx].d_char))) return MON_ALIEN_JURAL;
2397 if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2400 get_mon_num_prep(player_ptr, monster_hook_tanuki, NULL);
2402 int attempts = 1000;
2403 DEPTH min = MIN(floor_ptr->base_level - 5, 50);
2406 MONRACE_IDX ap_r_idx = get_mon_num(player_ptr, floor_ptr->base_level + 10);
2407 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2415 * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
2416 * @brief モンスターの個体加速を設定する / Get initial monster speed
2417 * @param r_ptr モンスター種族の参照ポインタ
2420 SPEED get_mspeed(player_type *player_ptr, monster_race *r_ptr)
2422 /* Extract the monster base speed */
2423 SPEED mspeed = r_ptr->speed;
2425 /* Hack -- small racial variety */
2426 if (!(r_ptr->flags1 & RF1_UNIQUE) && !player_ptr->current_floor_ptr->inside_arena)
2428 /* Allow some small variation per monster */
2429 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2430 if (i) mspeed += rand_spread(0, i);
2433 if (mspeed > 199) mspeed = 199;
2440 * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
2441 * @param player_ptr プレーヤーへの参照ポインタ
2442 * @param who 召喚を行ったモンスターID
2445 * @param r_idx 生成モンスター種族
2446 * @param mode 生成オプション
2449 * To give the player a sporting chance, any monster that appears in
2450 * line-of-sight and is extremely dangerous can be marked as
2451 * "FORCE_SLEEP", which will cause them to be placed with low energy,
2452 * which often (but not always) lets the player move before they do.
2454 * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2456 * Use special "here" and "dead" flags for unique monsters,
2457 * remove old "cur_num" and "max_num" fields.
2459 * Actually, do something similar for artifacts, to simplify
2460 * the "preserve" mode, and to make the "what artifacts" flag more useful.
2462 * This is the only function which may place a monster in the dungeon,
2463 * except for the savefile loading code.
2465 static bool place_monster_one(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2467 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2468 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2469 monster_type *m_ptr;
2470 monster_race *r_ptr = &r_info[r_idx];
2471 concptr name = (r_name + r_ptr->name);
2473 /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
2474 if (player_ptr->wild_mode) return FALSE;
2476 if (!in_bounds(floor_ptr, y, x)) return FALSE;
2477 if (!r_idx) return FALSE;
2478 if (!r_ptr->name) return FALSE;
2480 if (!(mode & PM_IGNORE_TERRAIN))
2482 /* Not on the Pattern */
2483 if (pattern_tile(y, x)) return FALSE;
2485 /* Require empty space (if not ghostly) */
2486 if (!monster_can_enter(y, x, r_ptr, 0)) return FALSE;
2489 if (!player_ptr->phase_out)
2491 /* Hack -- "unique" monsters must be "unique" */
2492 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2493 (r_ptr->flags7 & (RF7_NAZGUL))) &&
2494 (r_ptr->cur_num >= r_ptr->max_num))
2500 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
2501 (r_ptr->cur_num >= 1))
2506 if (r_idx == MON_BANORLUPART)
2508 if (r_info[MON_BANOR].cur_num > 0) return FALSE;
2509 if (r_info[MON_LUPART].cur_num > 0) return FALSE;
2512 /* Depth monsters may NOT be created out of depth, unless in Nightmare mode */
2513 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (floor_ptr->dun_level < r_ptr->level) &&
2514 (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
2521 if (quest_number(player_ptr, floor_ptr->dun_level))
2523 int hoge = quest_number(player_ptr, floor_ptr->dun_level);
2524 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
2526 if (r_idx == quest[hoge].r_idx)
2528 int number_mon, i2, j2;
2531 /* Count all quest monsters */
2532 for (i2 = 0; i2 < floor_ptr->width; ++i2)
2533 for (j2 = 0; j2 < floor_ptr->height; j2++)
2534 if (floor_ptr->grid_array[j2][i2].m_idx > 0)
2535 if (floor_ptr->m_list[floor_ptr->grid_array[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
2537 if (number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
2543 if (is_glyph_grid(g_ptr))
2545 if (randint1(BREAK_GLYPH) < (r_ptr->level + 20))
2547 /* Describe observable breakage */
2548 if (g_ptr->info & CAVE_MARK)
2550 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2553 /* Forget the rune */
2554 g_ptr->info &= ~(CAVE_MARK);
2556 /* Break the rune */
2557 g_ptr->info &= ~(CAVE_OBJECT);
2565 msg_format_wizard(CHEAT_MONSTER, _("%s(Lv%d)を生成しました。", "%s(Lv%d) was generated."), name, r_ptr->level);
2567 if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
2569 /* Make a new monster */
2570 g_ptr->m_idx = m_pop(player_ptr);
2571 hack_m_idx_ii = g_ptr->m_idx;
2573 /* Mega-Hack -- catch "failure" */
2574 if (!g_ptr->m_idx) return FALSE;
2577 /* Get a new monster record */
2578 m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
2581 m_ptr->r_idx = r_idx;
2582 m_ptr->ap_r_idx = initial_r_appearance(player_ptr, r_idx, mode);
2588 /* Hack -- Appearance transfer */
2589 if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(&floor_ptr->m_list[who]))
2591 m_ptr->ap_r_idx = floor_ptr->m_list[who].ap_r_idx;
2593 /* Hack -- Shadower spawns Shadower */
2594 if (floor_ptr->m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
2597 /* Sub-alignment of a monster */
2598 if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
2599 m_ptr->sub_align = floor_ptr->m_list[who].sub_align;
2602 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2603 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2604 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2607 /* Place the monster at the location */
2610 m_ptr->current_floor_ptr = floor_ptr;
2612 /* No "timed status" yet */
2613 for (int cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
2615 /* Unknown distance */
2618 reset_target(m_ptr);
2620 m_ptr->nickname = 0;
2625 /* Your pet summons its pet. */
2626 if (who > 0 && is_pet(&floor_ptr->m_list[who]))
2628 mode |= PM_FORCE_PET;
2629 m_ptr->parent_m_idx = who;
2633 m_ptr->parent_m_idx = 0;
2636 if (r_ptr->flags7 & RF7_CHAMELEON)
2638 choose_new_monster(player_ptr, g_ptr->m_idx, TRUE, 0);
2639 r_ptr = &r_info[m_ptr->r_idx];
2640 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
2642 /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
2643 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
2644 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2646 else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
2648 m_ptr->ap_r_idx = MON_KAGE;
2649 m_ptr->mflag2 |= MFLAG2_KAGE;
2652 if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
2658 if (mode & PM_FORCE_PET)
2660 set_pet(player_ptr, m_ptr);
2663 else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
2664 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(player_ptr, who))
2666 if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
2669 /* Assume no sleeping */
2670 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
2672 /* Enforce sleeping if needed */
2673 if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
2675 int val = r_ptr->sleep;
2676 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, (val * 2) + randint1(val * 10));
2679 /* Assign maximal hitpoints */
2680 if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2682 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2686 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2689 /* Monsters have double hitpoints in Nightmare mode */
2690 if (ironman_nightmare)
2692 u32b hp = m_ptr->max_maxhp * 2L;
2694 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2697 m_ptr->maxhp = m_ptr->max_maxhp;
2699 /* And start out fully healthy */
2700 if (m_ptr->r_idx == MON_WOUNDED_BEAR)
2701 m_ptr->hp = m_ptr->maxhp / 2;
2702 else m_ptr->hp = m_ptr->maxhp;
2705 /* dealt damage is 0 at initial*/
2706 m_ptr->dealt_damage = 0;
2709 /* Extract the monster base speed */
2710 m_ptr->mspeed = get_mspeed(player_ptr, r_ptr);
2712 if (mode & PM_HASTE) (void)set_monster_fast(player_ptr, g_ptr->m_idx, 100);
2714 /* Give a random starting energy */
2715 if (!ironman_nightmare)
2717 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
2721 /* Nightmare monsters are more prepared */
2722 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
2725 /* Force monster to wait for player, unless in Nightmare mode */
2726 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
2728 /* Monster is still being nice */
2729 m_ptr->mflag |= (MFLAG_NICE);
2731 /* Must repair monsters */
2732 repair_monsters = TRUE;
2735 /* Hack -- see "process_monsters()" */
2736 if (g_ptr->m_idx < hack_m_idx)
2738 /* Monster is still being born */
2739 m_ptr->mflag |= (MFLAG_BORN);
2743 if (r_ptr->flags7 & RF7_SELF_LD_MASK)
2744 player_ptr->update |= (PU_MON_LITE);
2745 else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
2746 player_ptr->update |= (PU_MON_LITE);
2747 update_monster(player_ptr, g_ptr->m_idx, TRUE);
2750 /* Count the monsters on the level */
2751 real_r_ptr(m_ptr)->cur_num++;
2754 * Memorize location of the unique monster in saved floors.
2755 * A unique monster move from old saved floor.
2757 if (current_world_ptr->character_dungeon &&
2758 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
2759 real_r_ptr(m_ptr)->floor_id = player_ptr->floor_id;
2761 /* Hack -- Count the number of "reproducers" */
2762 if (r_ptr->flags2 & RF2_MULTIPLY) floor_ptr->num_repro++;
2764 if (player_ptr->warning && current_world_ptr->character_dungeon)
2766 if (r_ptr->flags1 & RF1_UNIQUE)
2770 GAME_TEXT o_name[MAX_NLEN];
2772 if (r_ptr->level > player_ptr->lev + 30)
2773 color = _("黒く", "black");
2774 else if (r_ptr->level > player_ptr->lev + 15)
2775 color = _("紫色に", "purple");
2776 else if (r_ptr->level > player_ptr->lev + 5)
2777 color = _("ルビー色に", "deep red");
2778 else if (r_ptr->level > player_ptr->lev - 5)
2779 color = _("赤く", "red");
2780 else if (r_ptr->level > player_ptr->lev - 15)
2781 color = _("ピンク色に", "pink");
2783 color = _("白く", "white");
2785 o_ptr = choose_warning_item(player_ptr);
2788 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2789 msg_format(_("%sは%s光った。", "%s glows %s."), o_name, color);
2793 msg_format(_("%s光る物が頭に浮かんだ。", "An %s image forms in your mind."), color);
2798 if (!is_explosive_rune_grid(g_ptr)) return TRUE;
2800 /* Break the ward */
2801 if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2803 /* Describe observable breakage */
2804 if (g_ptr->info & CAVE_MARK)
2806 msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2807 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);
2812 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2815 /* Forget the rune */
2816 g_ptr->info &= ~(CAVE_MARK);
2818 /* Break the rune */
2819 g_ptr->info &= ~(CAVE_OBJECT);
2830 * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster
2831 * @param player_ptr プレーヤーへの参照ポインタ
2832 * @param r_idx 生成モンスター種族
2833 * @param yp 結果生成位置y座標
2834 * @param xp 結果生成位置x座標
2835 * @param y 中心生成位置y座標
2836 * @param x 中心生成位置x座標
2837 * @param max_dist 生成位置の最大半径
2841 static bool mon_scatter(player_type *player_ptr, MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
2843 POSITION place_x[MON_SCAT_MAXD];
2844 POSITION place_y[MON_SCAT_MAXD];
2845 int num[MON_SCAT_MAXD];
2847 if (max_dist >= MON_SCAT_MAXD)
2851 for (i = 0; i < MON_SCAT_MAXD; i++)
2854 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2855 for (POSITION nx = x - max_dist; nx <= x + max_dist; nx++)
2857 for (POSITION ny = y - max_dist; ny <= y + max_dist; ny++)
2859 /* Ignore annoying locations */
2860 if (!in_bounds(floor_ptr, ny, nx)) continue;
2862 /* Require "line of projection" */
2863 if (!projectable(player_ptr, y, x, ny, nx)) continue;
2867 monster_race *r_ptr = &r_info[r_idx];
2869 /* Require empty space (if not ghostly) */
2870 if (!monster_can_enter(ny, nx, r_ptr, 0))
2875 /* Walls and Monsters block flow */
2876 if (!cave_empty_bold2(floor_ptr, ny, nx)) continue;
2878 /* ... nor on the Pattern */
2879 if (pattern_tile(ny, nx)) continue;
2882 i = distance(y, x, ny, nx);
2890 if (one_in_(num[i]))
2899 while (i < MON_SCAT_MAXD && 0 == num[i])
2901 if (i >= MON_SCAT_MAXD)
2911 * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
2912 * @param who 召喚主のモンスター情報ID
2913 * @param y 中心生成位置y座標
2914 * @param x 中心生成位置x座標
2915 * @param r_idx 生成モンスター種族
2916 * @param mode 生成オプション
2919 static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2921 monster_race *r_ptr = &r_info[r_idx];
2922 int total = randint1(10);
2924 /* Hard monsters, small groups */
2925 floor_type *floor_ptr = player_ptr->current_floor_ptr;
2927 if (r_ptr->level > floor_ptr->dun_level)
2929 extra = r_ptr->level - floor_ptr->dun_level;
2930 extra = 0 - randint1(extra);
2933 /* Easy monsters, large groups */
2934 else if (r_ptr->level < floor_ptr->dun_level)
2936 extra = floor_ptr->dun_level - r_ptr->level;
2937 extra = randint1(extra);
2940 /* Hack -- limit group reduction */
2941 if (extra > 9) extra = 9;
2943 /* Modify the group size */
2947 if (total < 1) total = 1;
2950 if (total > GROUP_MAX) total = GROUP_MAX;
2953 /* Start on the monster */
2955 POSITION hack_x[GROUP_MAX];
2957 POSITION hack_y[GROUP_MAX];
2960 /* Puddle monsters, breadth first, up to total */
2961 for (int n = 0; (n < hack_n) && (hack_n < total); n++)
2963 /* Grab the location */
2964 POSITION hx = hack_x[n];
2965 POSITION hy = hack_y[n];
2967 /* Check each direction, up to total */
2968 for (int i = 0; (i < 8) && (hack_n < total); i++)
2972 scatter(player_ptr, &my, &mx, hy, hx, 4, 0);
2974 /* Walls and Monsters block flow */
2975 if (!cave_empty_bold2(floor_ptr, my, mx)) continue;
2977 /* Attempt to place another monster */
2978 if (place_monster_one(player_ptr, who, my, mx, r_idx, mode))
2980 /* Add it to the "hack" set */
2981 hack_y[hack_n] = my;
2982 hack_x[hack_n] = mx;
2993 * @var place_monster_idx
2994 * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
2995 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
2997 static MONSTER_IDX place_monster_idx = 0;
3000 * @var place_monster_m_idx
3001 * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
3002 * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
3004 static MONSTER_IDX place_monster_m_idx = 0;
3007 * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
3008 * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
3009 * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
3010 * @param r_idx チェックするモンスター種族のID
3011 * @return 護衛にできるならばtrue
3013 static bool place_monster_can_escort(MONRACE_IDX r_idx)
3015 monster_race *r_ptr = &r_info[place_monster_idx];
3016 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[place_monster_m_idx];
3017 monster_race *z_ptr = &r_info[r_idx];
3019 /* Hack - Escorts have to have the same dungeon flag */
3020 if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return FALSE;
3022 /* Require similar "race" */
3023 if (z_ptr->d_char != r_ptr->d_char) return FALSE;
3025 /* Skip more advanced monsters */
3026 if (z_ptr->level > r_ptr->level) return FALSE;
3028 /* Skip unique monsters */
3029 if (z_ptr->flags1 & RF1_UNIQUE) return FALSE;
3031 /* Paranoia -- Skip identical monsters */
3032 if (place_monster_idx == r_idx) return FALSE;
3034 /* Skip different alignment */
3035 if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE;
3037 if (r_ptr->flags7 & RF7_FRIENDLY)
3039 if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE;
3042 if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
3050 * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
3051 * @param player_ptr プレーヤーへの参照ポインタ
3052 * @param who 召喚主のモンスター情報ID
3055 * @param r_idx 生成するモンスターの種族ID
3056 * @param mode 生成オプション
3057 * @return 生成に成功したらtrue
3059 * Note that certain monsters are now marked as requiring "friends".
3060 * These monsters, if successfully placed, and if the "grp" parameter
3061 * is TRUE, will be surrounded by a "group" of identical monsters.
3063 * Note that certain monsters are now marked as requiring an "escort",
3064 * which is a collection of monsters with similar "race" but lower level.
3066 * Some monsters induce a fake "group" flag on their escorts.
3068 * Note the "bizarre" use of non-recursion to prevent annoying output
3069 * when running a code profiler.
3071 * Note the use of the new "monster allocation table" code to restrict
3072 * the "get_mon_num()" function to "legal" escort types.
3074 bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
3076 monster_race *r_ptr = &r_info[r_idx];
3078 if (!(mode & PM_NO_KAGE) && one_in_(333))
3081 /* Place one monster, or fail */
3082 if (!place_monster_one(player_ptr, who, y, x, r_idx, mode)) return FALSE;
3084 /* Require the "group" flag */
3085 if (!(mode & PM_ALLOW_GROUP)) return TRUE;
3087 place_monster_m_idx = hack_m_idx_ii;
3090 for (int i = 0; i < 6; i++)
3092 if (!r_ptr->reinforce_id[i]) break;
3093 int n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
3094 for (int j = 0; j < n; j++)
3096 POSITION nx, ny, d = 7;
3097 scatter(player_ptr, &ny, &nx, y, x, d, 0);
3098 (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
3102 /* Friends for certain monsters */
3103 if (r_ptr->flags1 & (RF1_FRIENDS))
3105 /* Attempt to place a group */
3106 (void)place_monster_group(player_ptr, who, y, x, r_idx, mode);
3109 /* Escorts for certain monsters */
3110 if (!(r_ptr->flags1 & (RF1_ESCORT))) return TRUE;
3112 /* Set the escort index */
3113 place_monster_idx = r_idx;
3115 /* Try to place several "escorts" */
3116 for (int i = 0; i < 32; i++)
3118 POSITION nx, ny, d = 3;
3121 /* Pick a location */
3122 scatter(player_ptr, &ny, &nx, y, x, d, 0);
3124 /* Require empty grids */
3125 if (!cave_empty_bold2(player_ptr->current_floor_ptr, ny, nx)) continue;
3126 get_mon_num_prep(player_ptr, place_monster_can_escort, get_monster_hook2(player_ptr, ny, nx));
3128 /* Pick a random race */
3129 z = get_mon_num(player_ptr, r_ptr->level);
3131 /* Handle failure */
3134 /* Place a single escort */
3135 (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, z, mode);
3137 /* Place a "group" of escorts if needed */
3138 if ((r_info[z].flags1 & RF1_FRIENDS) ||
3139 (r_ptr->flags1 & RF1_ESCORTS))
3141 /* Place a group of monsters */
3142 (void)place_monster_group(player_ptr, place_monster_m_idx, ny, nx, z, mode);
3151 * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
3152 * @param player_ptr プレーヤーへの参照ポインタ
3155 * @param mode 生成オプション
3156 * @return 生成に成功したらtrue
3158 bool place_monster(player_type *player_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
3161 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
3163 /* Pick a monster */
3164 r_idx = get_mon_num(player_ptr, player_ptr->current_floor_ptr->monster_level);
3166 /* Handle failure */
3167 if (!r_idx) return FALSE;
3169 /* Attempt to place the monster */
3170 if (place_monster_aux(player_ptr, 0, y, x, r_idx, mode)) return TRUE;
3177 * @brief 指定地点に1種類のモンスター種族による群れを生成する
3178 * @param player_ptr プレーヤーへの参照ポインタ
3181 * @return 生成に成功したらtrue
3183 bool alloc_horde(player_type *player_ptr, POSITION y, POSITION x)
3185 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
3187 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3188 MONRACE_IDX r_idx = 0;
3189 int attempts = 1000;
3190 monster_race *r_ptr = NULL;
3193 /* Pick a monster */
3194 r_idx = get_mon_num(player_ptr, floor_ptr->monster_level);
3196 /* Handle failure */
3197 if (!r_idx) return FALSE;
3199 r_ptr = &r_info[r_idx];
3201 if (r_ptr->flags1 & RF1_UNIQUE) continue;
3203 if (r_idx == MON_HAGURE) continue;
3207 if (attempts < 1) return FALSE;
3213 /* Attempt to place the monster */
3214 if (place_monster_aux(player_ptr, 0, y, x, r_idx, 0L)) break;
3217 if (attempts < 1) return FALSE;
3219 MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
3221 if (floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[floor_ptr->m_list[m_idx].r_idx];
3225 for (attempts = randint1(10) + 5; attempts; attempts--)
3227 scatter(player_ptr, &cy, &cx, y, x, 5, 0);
3229 (void)summon_specific(player_ptr, m_idx, cy, cx, floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
3235 if (cheat_hear) msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), r_ptr->d_char);
3240 * @brief ダンジョンの主生成を試みる / Put the Guardian
3241 * @param player_ptr プレーヤーへの参照ポインタ
3242 * @param def_val 現在の主の生成状態
3243 * @return 生成に成功したらtrue
3245 bool alloc_guardian(player_type *player_ptr, bool def_val)
3247 MONRACE_IDX guardian = d_info[player_ptr->dungeon_idx].final_guardian;
3249 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3250 bool is_guardian_applicable = guardian > 0;
3251 is_guardian_applicable &= d_info[player_ptr->dungeon_idx].maxdepth == floor_ptr->dun_level;
3252 is_guardian_applicable &= r_info[guardian].cur_num < r_info[guardian].max_num;
3253 if (!is_guardian_applicable) return def_val;
3255 int try_count = 4000;
3258 /* Get a random spot */
3259 POSITION oy = randint1(floor_ptr->height - 4) + 2;
3260 POSITION ox = randint1(floor_ptr->width - 4) + 2;
3262 /* Is it a good spot ? */
3263 if (!cave_empty_bold2(floor_ptr, oy, ox))
3269 if (!monster_can_cross_terrain(floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0))
3275 if (place_monster_aux(player_ptr, 0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET)))
3286 * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
3287 * @param dis プレイヤーから離れるべき最低距離
3288 * @param mode 生成オプション
3289 * @return 生成に成功したらtrue
3291 * Place the monster at least "dis" distance from the player.
3292 * Use "slp" to choose the initial "sleep" status
3293 * Use "floor_ptr->monster_level" for the monster level
3295 bool alloc_monster(player_type *player_ptr, POSITION dis, BIT_FLAGS mode)
3297 /* Put the Guardian */
3298 if (alloc_guardian(player_ptr, FALSE)) return TRUE;
3300 /* Find a legal, distant, unoccupied, space */
3301 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3302 POSITION y = 0, x = 0;
3303 int attempts_left = 10000;
3304 while (attempts_left--)
3306 /* Pick a location */
3307 y = randint0(floor_ptr->height);
3308 x = randint0(floor_ptr->width);
3310 /* Require empty floor grid (was "naked") */
3311 if (floor_ptr->dun_level)
3313 if (!cave_empty_bold2(floor_ptr, y, x)) continue;
3317 if (!cave_empty_bold(floor_ptr, y, x)) continue;
3320 /* Accept far away grids */
3321 if (distance(y, x, player_ptr->y, player_ptr->x) > dis) break;
3326 if (cheat_xtra || cheat_hear)
3328 msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
3335 if (randint1(5000) <= floor_ptr->dun_level)
3337 if (alloc_horde(player_ptr, y, x))
3344 /* Attempt to place the monster, allow groups */
3345 if (place_monster(player_ptr, y, x, (mode | PM_ALLOW_GROUP))) return TRUE;
3353 * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
3354 * @brief モンスターが召喚の基本条件に合っているかをチェックする / Hack -- help decide if a monster race is "okay" to summon
3355 * @param r_idx チェックするモンスター種族ID
3356 * @return 召喚対象にできるならばTRUE
3358 static bool summon_specific_okay(MONRACE_IDX r_idx)
3360 monster_race *r_ptr = &r_info[r_idx];
3361 monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[summon_specific_who];
3363 /* Hack - Only summon dungeon monsters */
3364 if (!mon_hook_dungeon(r_idx)) return FALSE;
3366 /* Hack -- identify the summoning monster */
3367 if (summon_specific_who > 0)
3370 /* Do not summon enemies */
3372 /* Friendly vs. opposite aligned normal or pet */
3373 if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE;
3375 /* Use the player's alignment */
3376 else if (summon_specific_who < 0)
3378 /* Do not summon enemies of the pets */
3379 if (monster_has_hostile_align(NULL, 10, -10, r_ptr))
3381 if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
3385 if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
3387 /* Hack -- no specific type specified */
3388 if (!summon_specific_type) return TRUE;
3390 if ((summon_specific_who < 0) &&
3391 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
3392 monster_has_hostile_align(NULL, 10, -10, r_ptr))
3395 if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON)) return TRUE;
3397 return (summon_specific_aux(p_ptr, m_ptr->r_idx, r_idx));
3402 * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
3403 * @param player_ptr プレーヤーへの参照ポインタ
3404 * @param who 召喚主のモンスター情報ID
3409 * @param mode 生成オプション
3410 * @return 召喚できたらtrueを返す
3413 * We will attempt to place the monster up to 10 times before giving up.
3415 * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
3416 * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
3417 * Note: None of the other summon codes will ever summon Unique's.
3419 * This function has been changed. We now take the "monster level"
3420 * of the summoning monster as a parameter, and use that, along with
3421 * the current dungeon level, to help determine the level of the
3422 * desired monster. Note that this is an upper bound, and also
3423 * tends to "prefer" monsters of that level. Currently, we use
3424 * the average of the dungeon and monster levels, and then add
3425 * five to allow slight increases in monster power.
3427 * Note that we use the new "monster allocation table" creation code
3428 * to restrict the "get_mon_num()" function to the set of "legal"
3429 * monsters, making this function much faster and more reliable.
3431 * Note that this function may not succeed, though this is very rare.
3433 bool summon_specific(player_type *player_ptr, MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode)
3435 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3436 if (floor_ptr->inside_arena) return FALSE;
3439 if (!mon_scatter(player_ptr, 0, &y, &x, y1, x1, 2)) return FALSE;
3441 /* Save the summoner */
3442 summon_specific_who = who;
3444 /* Save the "summon" type */
3445 summon_specific_type = type;
3447 summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
3448 get_mon_num_prep(player_ptr, summon_specific_okay, get_monster_hook2(player_ptr, y, x));
3450 /* Pick a monster, using the level calculation */
3451 MONRACE_IDX r_idx = get_mon_num(player_ptr, (floor_ptr->dun_level + lev) / 2 + 5);
3453 /* Handle failure */
3456 summon_specific_type = 0;
3460 if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
3462 /* Attempt to place the monster (awake, allow groups) */
3463 if (!place_monster_aux(player_ptr, who, y, x, r_idx, mode))
3465 summon_specific_type = 0;
3469 summon_specific_type = 0;
3471 sound(SOUND_SUMMON);
3477 * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
3478 * @param player_ptr プレーヤーへの参照ポインタ
3479 * @param who 召喚主のモンスター情報ID
3482 * @param r_idx 生成するモンスター種族ID
3483 * @param mode 生成オプション
3484 * @return 召喚できたらtrueを返す
3486 bool summon_named_creature(player_type *player_ptr, MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
3488 /* Prevent illegal monsters */
3489 if (r_idx >= max_r_idx) return FALSE;
3492 if (player_ptr->current_floor_ptr->inside_arena) return FALSE;
3494 if (!mon_scatter(player_ptr, r_idx, &y, &x, oy, ox, 2)) return FALSE;
3496 /* Place it (allow groups) */
3497 return place_monster_aux(player_ptr, who, y, x, r_idx, (mode | PM_NO_KAGE));
3502 * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
3503 * @param player_ptr プレーヤーへの参照ポインタ
3504 * @param m_idx 増殖するモンスター情報ID
3505 * @param clone クローン・モンスター処理ならばtrue
3506 * @param mode 生成オプション
3507 * @return 生成できたらtrueを返す
3509 * Note that "reproduction" REQUIRES empty space.
3511 bool multiply_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
3513 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3514 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
3516 if (!mon_scatter(player_ptr, m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
3519 if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
3521 /* Create a new monster (awake, no groups) */
3522 if (!place_monster_aux(player_ptr, m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
3525 /* Hack -- Transfer "clone" flag */
3526 if (clone || (m_ptr->smart & SM_CLONED))
3528 floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3529 floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
3537 * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
3538 * @param player_ptr プレーヤーへの参照ポインタ
3539 * @param m_idx モンスター情報ID
3540 * @param dam 与えたダメージ
3543 * Technically should attempt to treat "Beholder"'s as jelly's
3545 void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam)
3547 HIT_POINT oldhp, newhp;
3549 PERCENTAGE percentage;
3551 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
3552 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3554 GAME_TEXT m_name[MAX_NLEN];
3556 monster_desc(player_ptr, m_name, m_ptr, 0);
3558 if (dam == 0) // Notice non-damage
3560 msg_format(_("%^sはダメージを受けていない。", "%^s is unharmed."), m_name);
3565 oldhp = newhp + dam;
3566 tmp = (newhp * 100L) / oldhp;
3569 if (my_strchr(",ejmvwQ", r_ptr->d_char)) // Mushrooms, Eyes, Jellies, Molds, Vortices, Worms, Quylthulgs
3572 if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3573 else if (percentage > 75) msg_format("%^sはしり込みした。", m_name);
3574 else if (percentage > 50) msg_format("%^sは縮こまった。", m_name);
3575 else if (percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3576 else if (percentage > 20) msg_format("%^sは身もだえした。", m_name);
3577 else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3578 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3581 if (percentage > 95) msg_format("%^s barely notices.", m_name);
3582 else if (percentage > 75) msg_format("%^s flinches.", m_name);
3583 else if (percentage > 50) msg_format("%^s squelches.", m_name);
3584 else if (percentage > 35) msg_format("%^s quivers in pain.", m_name);
3585 else if (percentage > 20) msg_format("%^s writhes about.", m_name);
3586 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3587 else msg_format("%^s jerks limply.", m_name);
3592 if (my_strchr("l", r_ptr->d_char)) // Fish
3595 if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3596 else if (percentage > 75) msg_format("%^sはしり込みした。", m_name);
3597 else if (percentage > 50) msg_format("%^sは躊躇した。", m_name);
3598 else if (percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3599 else if (percentage > 20) msg_format("%^sは身もだえした。", m_name);
3600 else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3601 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3604 if (percentage > 95) msg_format("%^s barely notices.", m_name);
3605 else if (percentage > 75) msg_format("%^s flinches.", m_name);
3606 else if (percentage > 50) msg_format("%^s hesitates.", m_name);
3607 else if (percentage > 35) msg_format("%^s quivers in pain.", m_name);
3608 else if (percentage > 20) msg_format("%^s writhes about.", m_name);
3609 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3610 else msg_format("%^s jerks limply.", m_name);
3615 if (my_strchr("g#+<>", r_ptr->d_char)) // Golems, Walls, Doors, Stairs
3618 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3619 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3620 else if (percentage > 50) msg_format("%^sは雷鳴のように吠えた。", m_name);
3621 else if (percentage > 35) msg_format("%^sは苦しげに吠えた。", m_name);
3622 else if (percentage > 20) msg_format("%^sはうめいた。", m_name);
3623 else if (percentage > 10) msg_format("%^sは躊躇した。", m_name);
3624 else msg_format("%^sはくしゃくしゃになった。", m_name);
3627 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3628 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3629 else if (percentage > 50) msg_format("%^s roars thunderously.", m_name);
3630 else if (percentage > 35) msg_format("%^s rumbles.", m_name);
3631 else if (percentage > 20) msg_format("%^s grunts.", m_name);
3632 else if (percentage > 10) msg_format("%^s hesitates.", m_name);
3633 else msg_format("%^s crumples.", m_name);
3638 if (my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) // Snakes, Hydrae, Reptiles, Mimics
3641 if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3642 else if (percentage > 75) msg_format("%^sはシーッと鳴いた。", m_name);
3643 else if (percentage > 50) msg_format("%^sは怒って頭を上げた。", m_name);
3644 else if (percentage > 35) msg_format("%^sは猛然と威嚇した。", m_name);
3645 else if (percentage > 20) msg_format("%^sは身もだえした。", m_name);
3646 else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3647 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3650 if (percentage > 95) msg_format("%^s barely notices.", m_name);
3651 else if (percentage > 75) msg_format("%^s hisses.", m_name);
3652 else if (percentage > 50) msg_format("%^s rears up in anger.", m_name);
3653 else if (percentage > 35) msg_format("%^s hisses furiously.", m_name);
3654 else if (percentage > 20) msg_format("%^s writhes about.", m_name);
3655 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3656 else msg_format("%^s jerks limply.", m_name);
3661 if (my_strchr("f", r_ptr->d_char))
3664 if (percentage > 95) msg_format("%sは攻撃に肩をすくめた。", m_name);
3665 else if (percentage > 75) msg_format("%^sは吠えた。", m_name);
3666 else if (percentage > 50) msg_format("%^sは怒って吠えた。", m_name);
3667 else if (percentage > 35) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3668 else if (percentage > 20) msg_format("%^sは痛みで弱々しく鳴いた。", m_name);
3669 else if (percentage > 10) msg_format("%^sは苦痛にうめいた。", m_name);
3670 else msg_format("%sは哀れな鳴き声を出した。", m_name);
3673 if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3674 else if (percentage > 75) msg_format("%^s roars.", m_name);
3675 else if (percentage > 50) msg_format("%^s growls angrily.", m_name);
3676 else if (percentage > 35) msg_format("%^s hisses with pain.", m_name);
3677 else if (percentage > 20) msg_format("%^s mewls in pain.", m_name);
3678 else if (percentage > 10) msg_format("%^s hisses in agony.", m_name);
3679 else msg_format("%^s mewls pitifully.", m_name);
3684 if (my_strchr("acFIKS", r_ptr->d_char)) // Ants, Centipedes, Flies, Insects, Beetles, Spiders
3687 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3688 else if (percentage > 75) msg_format("%^sはキーキー鳴いた。", m_name);
3689 else if (percentage > 50) msg_format("%^sはヨロヨロ逃げ回った。", m_name);
3690 else if (percentage > 35) msg_format("%^sはうるさく鳴いた。", m_name);
3691 else if (percentage > 20) msg_format("%^sは痛みに痙攣した。", m_name);
3692 else if (percentage > 10) msg_format("%^sは苦痛で痙攣した。", m_name);
3693 else msg_format("%^sはピクピクひきつった。", m_name);
3696 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3697 else if (percentage > 75) msg_format("%^s chitters.", m_name);
3698 else if (percentage > 50) msg_format("%^s scuttles about.", m_name);
3699 else if (percentage > 35) msg_format("%^s twitters.", m_name);
3700 else if (percentage > 20) msg_format("%^s jerks in pain.", m_name);
3701 else if (percentage > 10) msg_format("%^s jerks in agony.", m_name);
3702 else msg_format("%^s twitches.", m_name);
3707 if (my_strchr("B", r_ptr->d_char)) // Birds
3710 if (percentage > 95) msg_format("%^sはさえずった。", m_name);
3711 else if (percentage > 75) msg_format("%^sはピーピー鳴いた。", m_name);
3712 else if (percentage > 50) msg_format("%^sはギャーギャー鳴いた。", m_name);
3713 else if (percentage > 35) msg_format("%^sはギャーギャー鳴きわめいた。", m_name);
3714 else if (percentage > 20) msg_format("%^sは苦しんだ。", m_name);
3715 else if (percentage > 10) msg_format("%^sはのたうち回った。", m_name);
3716 else msg_format("%^sはキーキーと鳴き叫んだ。", m_name);
3719 if (percentage > 95) msg_format("%^s chirps.", m_name);
3720 else if (percentage > 75) msg_format("%^s twitters.", m_name);
3721 else if (percentage > 50) msg_format("%^s squawks.", m_name);
3722 else if (percentage > 35) msg_format("%^s chatters.", m_name);
3723 else if (percentage > 20) msg_format("%^s jeers.", m_name);
3724 else if (percentage > 10) msg_format("%^s flutters about.", m_name);
3725 else msg_format("%^s squeaks.", m_name);
3730 if (my_strchr("duDLUW", r_ptr->d_char)) // Dragons, Demons, High Undead
3733 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3734 else if (percentage > 75) msg_format("%^sはしり込みした。", m_name);
3735 else if (percentage > 50) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3736 else if (percentage > 35) msg_format("%^sは痛みでうなった。", m_name);
3737 else if (percentage > 20) msg_format("%^sは痛みに吠えた。", m_name);
3738 else if (percentage > 10) msg_format("%^sは苦しげに叫んだ。", m_name);
3739 else msg_format("%^sは弱々しくうなった。", m_name);
3742 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3743 else if (percentage > 75) msg_format("%^s flinches.", m_name);
3744 else if (percentage > 50) msg_format("%^s hisses in pain.", m_name);
3745 else if (percentage > 35) msg_format("%^s snarls with pain.", m_name);
3746 else if (percentage > 20) msg_format("%^s roars with pain.", m_name);
3747 else if (percentage > 10) msg_format("%^s gasps.", m_name);
3748 else msg_format("%^s snarls feebly.", m_name);
3753 if (my_strchr("s", r_ptr->d_char)) // Skeletons
3756 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3757 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3758 else if (percentage > 50) msg_format("%^sはカタカタと笑った。", m_name);
3759 else if (percentage > 35) msg_format("%^sはよろめいた。", m_name);
3760 else if (percentage > 20) msg_format("%^sはカタカタ言った。", m_name);
3761 else if (percentage > 10) msg_format("%^sはよろめいた。", m_name);
3762 else msg_format("%^sはガタガタ言った。", m_name);
3765 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3766 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3767 else if (percentage > 50) msg_format("%^s rattles.", m_name);
3768 else if (percentage > 35) msg_format("%^s stumbles.", m_name);
3769 else if (percentage > 20) msg_format("%^s rattles.", m_name);
3770 else if (percentage > 10) msg_format("%^s staggers.", m_name);
3771 else msg_format("%^s clatters.", m_name);
3776 if (my_strchr("z", r_ptr->d_char)) // Zombies
3779 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3780 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3781 else if (percentage > 50) msg_format("%^sはうめいた。", m_name);
3782 else if (percentage > 35) msg_format("%sは苦しげにうめいた。", m_name);
3783 else if (percentage > 20) msg_format("%^sは躊躇した。", m_name);
3784 else if (percentage > 10) msg_format("%^sはうなった。", m_name);
3785 else msg_format("%^sはよろめいた。", m_name);
3788 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3789 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3790 else if (percentage > 50) msg_format("%^s groans.", m_name);
3791 else if (percentage > 35) msg_format("%^s moans.", m_name);
3792 else if (percentage > 20) msg_format("%^s hesitates.", m_name);
3793 else if (percentage > 10) msg_format("%^s grunts.", m_name);
3794 else msg_format("%^s staggers.", m_name);
3799 if (my_strchr("G", r_ptr->d_char)) // Ghosts
3802 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3803 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3804 else if (percentage > 50) msg_format("%sはうめいた。", m_name);
3805 else if (percentage > 35) msg_format("%^sは泣きわめいた。", m_name);
3806 else if (percentage > 20) msg_format("%^sは吠えた。", m_name);
3807 else if (percentage > 10) msg_format("%sは弱々しくうめいた。", m_name);
3808 else msg_format("%^sはかすかにうめいた。", m_name);
3811 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3812 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3813 else if (percentage > 50) msg_format("%^s moans.", m_name);
3814 else if (percentage > 35) msg_format("%^s wails.", m_name);
3815 else if (percentage > 20) msg_format("%^s howls.", m_name);
3816 else if (percentage > 10) msg_format("%^s moans softly.", m_name);
3817 else msg_format("%^s sighs.", m_name);
3822 if (my_strchr("CZ", r_ptr->d_char)) // Dogs and Hounds
3825 if (percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3826 else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3827 else if (percentage > 50) msg_format("%^sは痛みでキャンキャン吠えた。", m_name);
3828 else if (percentage > 35) msg_format("%^sは痛みで鳴きわめいた。", m_name);
3829 else if (percentage > 20) msg_format("%^sは苦痛のあまり鳴きわめいた。", m_name);
3830 else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3831 else msg_format("%^sは弱々しく吠えた。", m_name);
3834 if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3835 else if (percentage > 75) msg_format("%^s snarls with pain.", m_name);
3836 else if (percentage > 50) msg_format("%^s yelps in pain.", m_name);
3837 else if (percentage > 35) msg_format("%^s howls in pain.", m_name);
3838 else if (percentage > 20) msg_format("%^s howls in agony.", m_name);
3839 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3840 else msg_format("%^s yelps feebly.", m_name);
3845 if (my_strchr("Xbilqrt", r_ptr->d_char)) // One type of creatures (ignore,squeal,shriek)
3848 if (percentage > 95) msg_format("%^sは攻撃を気にとめていない。", m_name);
3849 else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3850 else if (percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3851 else if (percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3852 else if (percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3853 else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3854 else msg_format("%^sは弱々しく叫んだ。", m_name);
3857 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3858 else if (percentage > 75) msg_format("%^s grunts with pain.", m_name);
3859 else if (percentage > 50) msg_format("%^s squeals in pain.", m_name);
3860 else if (percentage > 35) msg_format("%^s shrieks in pain.", m_name);
3861 else if (percentage > 20) msg_format("%^s shrieks in agony.", m_name);
3862 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3863 else msg_format("%^s cries out feebly.", m_name);
3869 if (percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3870 else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3871 else if (percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3872 else if (percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3873 else if (percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3874 else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3875 else msg_format("%^sは弱々しく叫んだ。", m_name);
3877 if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3878 else if (percentage > 75) msg_format("%^s grunts with pain.", m_name);
3879 else if (percentage > 50) msg_format("%^s cries out in pain.", m_name);
3880 else if (percentage > 35) msg_format("%^s screams in pain.", m_name);
3881 else if (percentage > 20) msg_format("%^s screams in agony.", m_name);
3882 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3883 else msg_format("%^s cries out feebly.", m_name);
3889 * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance.
3890 * @param m_idx 更新を行う「モンスター情報ID
3891 * @param what 学習対象ID
3894 void update_smart_learn(player_type *player_ptr, MONSTER_IDX m_idx, int what)
3896 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
3897 monster_race *r_ptr = &r_info[m_ptr->r_idx];
3899 /* Not allowed to learn */
3900 if (!smart_learn) return;
3902 /* Too stupid to learn anything */
3903 if (r_ptr->flags2 & (RF2_STUPID)) return;
3905 /* Not intelligent, only learn sometimes */
3906 if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
3908 /* Analyze the knowledge */
3912 if (player_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
3913 if (is_oppose_acid(player_ptr)) m_ptr->smart |= (SM_OPP_ACID);
3914 if (player_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
3918 if (player_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
3919 if (is_oppose_elec(player_ptr)) m_ptr->smart |= (SM_OPP_ELEC);
3920 if (player_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
3924 if (player_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
3925 if (is_oppose_fire(player_ptr)) m_ptr->smart |= (SM_OPP_FIRE);
3926 if (player_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
3930 if (player_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
3931 if (is_oppose_cold(player_ptr)) m_ptr->smart |= (SM_OPP_COLD);
3932 if (player_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
3936 if (player_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
3937 if (is_oppose_pois(player_ptr)) m_ptr->smart |= (SM_OPP_POIS);
3942 if (player_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
3946 if (player_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
3950 if (player_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
3954 if (player_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
3958 if (player_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
3962 if (player_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
3966 if (player_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
3970 if (player_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
3974 if (player_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
3978 if (player_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
3982 if (player_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
3986 if (player_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
3990 if (!player_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
3994 if (player_ptr->reflect) m_ptr->smart |= (SM_IMM_REFLECT);
4001 * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster
4002 * @param player_ptr プレーヤーへの参照ポインタ
4003 * @param m_ptr モンスター参照ポインタ
4006 void monster_drop_carried_objects(player_type *player_ptr, monster_type *m_ptr)
4008 /* Drop objects being carried */
4009 floor_type *floor_ptr = player_ptr->current_floor_ptr;
4010 OBJECT_IDX next_o_idx = 0;
4011 for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
4016 o_ptr = &floor_ptr->o_list[this_o_idx];
4017 next_o_idx = o_ptr->next_o_idx;
4020 object_copy(q_ptr, o_ptr);
4021 q_ptr->held_m_idx = 0;
4022 delete_object_idx(floor_ptr, this_o_idx);
4023 (void)drop_near(player_ptr, q_ptr, -1, m_ptr->fy, m_ptr->fx);
4026 m_ptr->hold_o_idx = 0;
4031 * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
4032 * @brief 指定したモンスターに隣接しているモンスターの数を返す。
4033 * / Count number of adjacent monsters
4034 * @param player_ptr プレーヤーへの参照ポインタ
4035 * @param m_idx 隣接数を調べたいモンスターのID
4036 * @return 隣接しているモンスターの数
4038 int get_monster_crowd_number(player_type *player_ptr, MONSTER_IDX m_idx)
4040 floor_type *floor_ptr = player_ptr->current_floor_ptr;
4041 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
4042 POSITION my = m_ptr->fy;
4043 POSITION mx = m_ptr->fx;
4045 for (int i = 0; i < 7; i++)
4047 int ay = my + ddy_ddd[i];
4048 int ax = mx + ddx_ddd[i];
4050 if (!in_bounds(floor_ptr, ay, ax)) continue;
4051 if (floor_ptr->grid_array[ay][ax].m_idx > 0) count++;
4058 bool is_friendly_idx(player_type *player_ptr, MONSTER_IDX m_idx)
4060 return m_idx > 0 && is_friendly(&player_ptr->current_floor_ptr->m_list[(m_idx)]);