OSDN Git Service

[Refactor] #39963 Separated effect-characteristics.h from floor.h
[hengband/hengband.git] / src / monster2.c
1 /*!
2  * @file monster2.c
3  * @brief モンスター処理 / misc code for monsters
4  * @date 2014/07/08
5  * @author
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.
11  */
12
13 #include "angband.h"
14 #include "util.h"
15 #include "main/sound-definitions-table.h"
16 #include "core.h"
17
18 #include "io/write-diary.h"
19 #include "cmd/cmd-dump.h"
20 #include "cmd-pet.h"
21 #include "dungeon.h"
22 #include "effect/effect-characteristics.h"
23 #include "object-flavor.h"
24 #include "monsterrace-hook.h"
25 #include "monster-status.h"
26 #include "monster.h"
27 #include "spell/spells-type.h"
28 #include "spells-summon.h"
29 #include "quest.h"
30 #include "grid.h"
31 #include "player-move.h"
32 #include "player-status.h"
33 #include "player-race.h"
34 #include "player-class.h"
35 #include "player-personality.h"
36 #include "wild.h"
37 #include "warning.h"
38 #include "monster-spell.h"
39 #include "files.h"
40 #include "view/display-main-window.h"
41 #include "world.h"
42 #include "monsterrace.h"
43 #include "creature.h"
44 #include "targeting.h"
45 #include "melee.h"
46 #include "spell/process-effect.h"
47
48 #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */
49 #define HORDE_NOEVIL 0x02 /*!< (未実装フラグ)HORDE生成でEVILなモンスターの生成を禁止する? */
50 #define MON_SCAT_MAXD 10 /*!< mon_scatter()関数によるモンスター配置で許される中心からの最大距離 */
51
52 MONSTER_IDX hack_m_idx = 0;     /* Hack -- see "process_monsters()" */
53 MONSTER_IDX hack_m_idx_ii = 0;
54
55 bool is_friendly_idx(player_type *player_ptr, MONSTER_IDX m_idx);
56
57 /*!
58  * @brief モンスターの目標地点をセットする / Set the target of counter attack
59  * @param m_ptr モンスターの参照ポインタ
60  * @param y 目標y座標
61  * @param x 目標x座標
62  * @return なし
63  */
64 void set_target(monster_type *m_ptr, POSITION y, POSITION x)
65 {
66         m_ptr->target_y = y;
67         m_ptr->target_x = x;
68 }
69
70
71 /*!
72  * @brief モンスターの目標地点をリセットする / Reset the target of counter attack
73  * @param m_ptr モンスターの参照ポインタ
74  * @return なし
75  */
76 void reset_target(monster_type *m_ptr)
77 {
78         set_target(m_ptr, 0, 0);
79 }
80
81
82 /*!
83  * @brief モンスターの真の種族を返す / Extract monster race pointer of a monster's true form
84  * @param m_ptr モンスターの参照ポインタ
85  * @return 本当のモンスター種族参照ポインタ
86  */
87 monster_race *real_r_ptr(monster_type *m_ptr)
88 {
89         return &r_info[real_r_idx(m_ptr)];
90 }
91
92
93 MONRACE_IDX real_r_idx(monster_type *m_ptr)
94 {
95         monster_race *r_ptr = &r_info[m_ptr->r_idx];
96         if (m_ptr->mflag2 & MFLAG2_CHAMELEON)
97         {
98                 if (r_ptr->flags1 & RF1_UNIQUE)
99                         return MON_CHAMELEON_K;
100                 else
101                         return MON_CHAMELEON;
102         }
103
104         return m_ptr->r_idx;
105 }
106
107
108 /*!
109  * @brief モンスター配列からモンスターを消去する / Delete a monster by index.
110  * @param i 消去するモンスターのID
111  * @return なし
112  * @details
113  * モンスターを削除するとそのモンスターが拾っていたアイテムも同時に削除される。 /
114  * When a monster is deleted, all of its objects are deleted.
115  */
116 void delete_monster_idx(player_type *player_ptr, MONSTER_IDX i)
117 {
118         floor_type *floor_ptr = player_ptr->current_floor_ptr;
119         monster_type *m_ptr = &floor_ptr->m_list[i];
120         monster_race *r_ptr = &r_info[m_ptr->r_idx];
121
122         POSITION y = m_ptr->fy;
123         POSITION x = m_ptr->fx;
124
125         real_r_ptr(m_ptr)->cur_num--;
126         if (r_ptr->flags2 & (RF2_MULTIPLY)) floor_ptr->num_repro--;
127
128         if (MON_CSLEEP(m_ptr)) (void)set_monster_csleep(player_ptr, i, 0);
129         if (MON_FAST(m_ptr)) (void)set_monster_fast(player_ptr, i, 0);
130         if (MON_SLOW(m_ptr)) (void)set_monster_slow(player_ptr, i, 0);
131         if (MON_STUNNED(m_ptr)) (void)set_monster_stunned(player_ptr, i, 0);
132         if (MON_CONFUSED(m_ptr)) (void)set_monster_confused(player_ptr, i, 0);
133         if (MON_MONFEAR(m_ptr)) (void)set_monster_monfear(player_ptr, i, 0);
134         if (MON_INVULNER(m_ptr)) (void)set_monster_invulner(player_ptr, i, 0, FALSE);
135
136         if (i == target_who) target_who = 0;
137
138         if (i == player_ptr->health_who) health_track(player_ptr, 0);
139
140         if (player_ptr->pet_t_m_idx == i) player_ptr->pet_t_m_idx = 0;
141         if (player_ptr->riding_t_m_idx == i) player_ptr->riding_t_m_idx = 0;
142         if (player_ptr->riding == i) player_ptr->riding = 0;
143
144         floor_ptr->grid_array[y][x].m_idx = 0;
145         OBJECT_IDX next_o_idx = 0;
146         for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
147         {
148                 object_type *o_ptr;
149                 o_ptr = &floor_ptr->o_list[this_o_idx];
150                 next_o_idx = o_ptr->next_o_idx;
151                 delete_object_idx(player_ptr, this_o_idx);
152         }
153
154         (void)WIPE(m_ptr, monster_type);
155         floor_ptr->m_cnt--;
156         lite_spot(player_ptr, y, x);
157         if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
158         {
159                 player_ptr->update |= (PU_MON_LITE);
160         }
161 }
162
163
164 /*!
165  * @brief モンスター情報を配列内移動する / Move an object from index i1 to index i2 in the object list
166  * @param player_ptr プレーヤーへの参照ポインタ
167  * @param i1 配列移動元添字
168  * @param i2 配列移動先添字
169  * @return なし
170  */
171 static void compact_monsters_aux(player_type *player_ptr, MONSTER_IDX i1, MONSTER_IDX i2)
172 {
173         if (i1 == i2) return;
174
175         floor_type *floor_ptr = player_ptr->current_floor_ptr;
176         monster_type *m_ptr;
177         m_ptr = &floor_ptr->m_list[i1];
178
179         POSITION y = m_ptr->fy;
180         POSITION x = m_ptr->fx;
181         grid_type *g_ptr;
182         g_ptr = &floor_ptr->grid_array[y][x];
183         g_ptr->m_idx = i2;
184
185         OBJECT_IDX next_o_idx = 0;
186         for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
187         {
188                 object_type *o_ptr;
189                 o_ptr = &floor_ptr->o_list[this_o_idx];
190                 next_o_idx = o_ptr->next_o_idx;
191                 o_ptr->held_m_idx = i2;
192         }
193
194         if (target_who == i1) target_who = i2;
195
196         if (player_ptr->pet_t_m_idx == i1) player_ptr->pet_t_m_idx = i2;
197         if (player_ptr->riding_t_m_idx == i1) player_ptr->riding_t_m_idx = i2;
198
199         if (player_ptr->riding == i1) player_ptr->riding = i2;
200
201         if (player_ptr->health_who == i1) health_track(player_ptr, i2);
202
203         if (is_pet(m_ptr))
204         {
205                 for (int i = 1; i < floor_ptr->m_max; i++)
206                 {
207                         monster_type *m2_ptr = &floor_ptr->m_list[i];
208
209                         if (m2_ptr->parent_m_idx == i1)
210                                 m2_ptr->parent_m_idx = i2;
211                 }
212         }
213
214         (void)COPY(&floor_ptr->m_list[i2], &floor_ptr->m_list[i1], monster_type);
215         (void)WIPE(&floor_ptr->m_list[i1], monster_type);
216
217         for (int i = 0; i < MAX_MTIMED; i++)
218         {
219                 int mproc_idx = get_mproc_idx(floor_ptr, i1, i);
220                 if (mproc_idx >= 0) floor_ptr->mproc_list[i][mproc_idx] = i2;
221         }
222 }
223
224
225 /*!
226  * @brief モンスター情報配列を圧縮する / Compact and Reorder the monster list
227  * @param player_ptr プレーヤーへの参照ポインタ
228  * @param size 圧縮後のモンスター件数目標
229  * @return なし
230  * @details
231  * This function can be very dangerous, use with caution!
232  *
233  * When actually "compacting" monsters, we base the saving throw
234  * on a combination of monster level, distance from player, and
235  * current "desperation".
236  *
237  * After "compacting" (if needed), we "reorder" the monsters into a more
238  * compact order, and we reset the allocation info, and the "live" array.
239  */
240 void compact_monsters(player_type *player_ptr, int size)
241 {
242         if (size) msg_print(_("モンスター情報を圧縮しています...", "Compacting monsters..."));
243
244         /* Compact at least 'size' objects */
245         floor_type *floor_ptr = player_ptr->current_floor_ptr;
246         for (int num = 0, cnt = 1; num < size; cnt++)
247         {
248                 int cur_lev = 5 * cnt;
249                 int cur_dis = 5 * (20 - cnt);
250                 for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++)
251                 {
252                         monster_type *m_ptr = &floor_ptr->m_list[i];
253                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
254                         if (!monster_is_valid(m_ptr)) continue;
255                         if (r_ptr->level > cur_lev) continue;
256                         if (i == player_ptr->riding) continue;
257                         if ((cur_dis > 0) && (m_ptr->cdis < cur_dis)) continue;
258
259                         int chance = 90;
260                         if ((r_ptr->flags1 & (RF1_QUESTOR)) && (cnt < 1000)) chance = 100;
261
262                         if (r_ptr->flags1 & (RF1_UNIQUE)) chance = 100;
263
264                         if (randint0(100) < chance) continue;
265
266                         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
267                         {
268                                 GAME_TEXT m_name[MAX_NLEN];
269                                 monster_desc(player_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
270                                 exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_COMPACT, m_name);
271                         }
272
273                         delete_monster_idx(player_ptr, i);
274                         num++;
275                 }
276         }
277
278         /* Excise dead monsters (backwards!) */
279         for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
280         {
281                 monster_type *m_ptr = &floor_ptr->m_list[i];
282                 if (m_ptr->r_idx) continue;
283                 compact_monsters_aux(player_ptr, floor_ptr->m_max - 1, i);
284                 floor_ptr->m_max--;
285         }
286 }
287
288
289 /*!
290  * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
291  * @brief プレイヤーのフロア離脱に伴う全モンスター配列の消去 / Delete/Remove all the monsters when the player leaves the level
292  * @param player_ptr プレーヤーへの参照ポインタ
293  * @return なし
294  * @details
295  * This is an efficient method of simulating multiple calls to the
296  * "delete_monster()" function, with no visual effects.
297  */
298 void wipe_monsters_list(player_type *player_ptr)
299 {
300         if (!r_info[MON_BANORLUPART].max_num)
301         {
302                 if (r_info[MON_BANOR].max_num)
303                 {
304                         r_info[MON_BANOR].max_num = 0;
305                         r_info[MON_BANOR].r_pkills++;
306                         r_info[MON_BANOR].r_akills++;
307                         if (r_info[MON_BANOR].r_tkills < MAX_SHORT)
308                                 r_info[MON_BANOR].r_tkills++;
309                 }
310
311                 if (r_info[MON_LUPART].max_num)
312                 {
313                         r_info[MON_LUPART].max_num = 0;
314                         r_info[MON_LUPART].r_pkills++;
315                         r_info[MON_LUPART].r_akills++;
316                         if (r_info[MON_LUPART].r_tkills < MAX_SHORT)
317                                 r_info[MON_LUPART].r_tkills++;
318                 }
319         }
320
321         floor_type *floor_ptr = player_ptr->current_floor_ptr;
322         for (int i = floor_ptr->m_max - 1; i >= 1; i--)
323         {
324                 monster_type *m_ptr = &floor_ptr->m_list[i];
325                 if (!monster_is_valid(m_ptr)) continue;
326
327                 floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx = 0;
328                 (void)WIPE(m_ptr, monster_type);
329         }
330
331         /*
332          * Wiping racial counters of all monsters and incrementing of racial
333          * counters of monsters in party_mon[] are required to prevent multiple
334          * generation of unique monster who is the minion of player.
335          */
336         for (int i = 1; i < max_r_idx; i++) r_info[i].cur_num = 0;
337
338         floor_ptr->m_max = 1;
339         floor_ptr->m_cnt = 0;
340         for (int i = 0; i < MAX_MTIMED; i++) floor_ptr->mproc_max[i] = 0;
341
342         floor_ptr->num_repro = 0;
343         target_who = 0;
344         player_ptr->pet_t_m_idx = 0;
345         player_ptr->riding_t_m_idx = 0;
346         health_track(player_ptr, 0);
347 }
348
349
350 /*!
351  * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
352  * @brief モンスター配列の空きを探す / Acquires and returns the index of a "free" monster.
353  * @return 利用可能なモンスター配列の添字
354  * @details
355  * This routine should almost never fail, but it *can* happen.
356  */
357 MONSTER_IDX m_pop(player_type *player_ptr)
358 {
359         /* Normal allocation */
360         floor_type *floor_ptr = player_ptr->current_floor_ptr;
361         if (floor_ptr->m_max < current_world_ptr->max_m_idx)
362         {
363                 MONSTER_IDX i = floor_ptr->m_max;
364                 floor_ptr->m_max++;
365                 floor_ptr->m_cnt++;
366                 return i;
367         }
368
369         /* Recycle dead monsters */
370         for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++)
371         {
372                 monster_type *m_ptr;
373                 m_ptr = &floor_ptr->m_list[i];
374                 if (m_ptr->r_idx) continue;
375                 floor_ptr->m_cnt++;
376                 return i;
377         }
378
379         if (current_world_ptr->character_dungeon) msg_print(_("モンスターが多すぎる!", "Too many monsters!"));
380         return 0;
381 }
382
383
384 /*!
385  * @var summon_specific_type
386  * @brief 召喚条件を指定するグローバル変数 / Hack -- the "type" of the current "summon specific"
387  * @todo summon_specific_typeグローバル変数の除去と関数引数への代替を行う
388  */
389 static int summon_specific_type = 0;
390
391
392 /*!
393  * @var summon_specific_who
394  * @brief 召喚を行ったプレイヤーあるいはモンスターのIDを示すグローバル変数 / Hack -- the index of the summoning monster
395  * @todo summon_specific_who グローバル変数の除去と関数引数への代替を行う
396  */
397 static int summon_specific_who = -1;
398
399
400 /*!
401  * @var summon_unique_okay
402  * @brief 召喚対象にユニークを含めるかを示すグローバル変数 / summoning unique enable
403  * @todo summon_unique_okay グローバル変数の除去と関数引数への代替を行う
404  */
405 static bool summon_unique_okay = FALSE;
406
407
408 /*!
409  * @brief 指定されたモンスター種族がsummon_specific_typeで指定された召喚条件に合うかどうかを返す
410  * @param player_ptr プレーヤーへの参照ポインタ
411  * @return 召喚条件が一致するならtrue
412  * @details
413  */
414 static bool summon_specific_aux(player_type *player_ptr, MONRACE_IDX summoner_idx, MONRACE_IDX r_idx)
415 {
416         monster_race *r_ptr = &r_info[r_idx];
417         bool is_match = FALSE;
418
419         switch (summon_specific_type)
420         {
421         case SUMMON_ANT:
422         {
423                 is_match = (r_ptr->d_char == 'a');
424                 break;
425         }
426         case SUMMON_SPIDER:
427         {
428                 is_match = (r_ptr->d_char == 'S');
429                 break;
430         }
431         case SUMMON_HOUND:
432         {
433                 is_match = ((r_ptr->d_char == 'C') || (r_ptr->d_char == 'Z'));
434                 break;
435         }
436         case SUMMON_HYDRA:
437         {
438                 is_match = (r_ptr->d_char == 'M');
439                 break;
440         }
441         case SUMMON_ANGEL:
442         {
443                 is_match = (r_ptr->d_char == 'A' && ((r_ptr->flags3 & RF3_EVIL) || (r_ptr->flags3 & RF3_GOOD)));
444                 break;
445         }
446         case SUMMON_DEMON:
447         {
448                 is_match = (r_ptr->flags3 & RF3_DEMON);
449                 break;
450         }
451         case SUMMON_UNDEAD:
452         {
453                 is_match = (r_ptr->flags3 & RF3_UNDEAD);
454                 break;
455         }
456         case SUMMON_DRAGON:
457         {
458                 is_match = (r_ptr->flags3 & RF3_DRAGON);
459                 break;
460         }
461         case SUMMON_HI_UNDEAD:
462         {
463                 is_match = ((r_ptr->d_char == 'L') ||
464                         (r_ptr->d_char == 'V') ||
465                         (r_ptr->d_char == 'W'));
466                 break;
467         }
468         case SUMMON_HI_DRAGON:
469         {
470                 is_match = (r_ptr->d_char == 'D');
471                 break;
472         }
473         case SUMMON_HI_DEMON:
474         {
475                 is_match = (((r_ptr->d_char == 'U') ||
476                         (r_ptr->d_char == 'H') ||
477                         (r_ptr->d_char == 'B')) &&
478                         (r_ptr->flags3 & RF3_DEMON)) ? TRUE : FALSE;
479                 break;
480         }
481         case SUMMON_AMBERITES:
482         {
483                 is_match = (r_ptr->flags3 & (RF3_AMBERITE)) ? TRUE : FALSE;
484                 break;
485         }
486         case SUMMON_UNIQUE:
487         {
488                 is_match = (r_ptr->flags1 & (RF1_UNIQUE)) ? TRUE : FALSE;
489                 break;
490         }
491         case SUMMON_MOLD:
492         {
493                 is_match = (r_ptr->d_char == 'm');
494                 break;
495         }
496         case SUMMON_BAT:
497         {
498                 is_match = (r_ptr->d_char == 'b');
499                 break;
500         }
501         case SUMMON_QUYLTHULG:
502         {
503                 is_match = (r_ptr->d_char == 'Q');
504                 break;
505         }
506         case SUMMON_COIN_MIMIC:
507         {
508                 is_match = (r_ptr->d_char == '$');
509                 break;
510         }
511         case SUMMON_MIMIC:
512         {
513                 is_match = ((r_ptr->d_char == '!') ||
514                         (r_ptr->d_char == '?') ||
515                         (r_ptr->d_char == '=') ||
516                         (r_ptr->d_char == '$') ||
517                         (r_ptr->d_char == '|'));
518                 break;
519         }
520         case SUMMON_GOLEM:
521         {
522                 is_match = (r_ptr->d_char == 'g');
523                 break;
524         }
525         case SUMMON_CYBER:
526         {
527                 is_match = ((r_ptr->d_char == 'U') &&
528                         (r_ptr->flags4 & RF4_ROCKET));
529                 break;
530         }
531         case SUMMON_KIN:
532         {
533                 SYMBOL_CODE summon_kin_type;
534                 if (summoner_idx)
535                 {
536                         summon_kin_type = r_info[summoner_idx].d_char;
537                 }
538                 else
539                 {
540                         summon_kin_type = get_summon_symbol_from_player(player_ptr);
541                 }
542
543                 is_match = ((r_ptr->d_char == summon_kin_type) && (r_idx != MON_HAGURE));
544                 break;
545         }
546         case SUMMON_DAWN:
547         {
548                 is_match = (r_idx == MON_DAWN);
549                 break;
550         }
551         case SUMMON_ANIMAL:
552         {
553                 is_match = (r_ptr->flags3 & (RF3_ANIMAL));
554                 break;
555         }
556         case SUMMON_ANIMAL_RANGER:
557         {
558                 is_match = ((r_ptr->flags3 & (RF3_ANIMAL)) &&
559                         (my_strchr("abcflqrwBCHIJKMRS", r_ptr->d_char)) &&
560                         !(r_ptr->flags3 & (RF3_DRAGON)) &&
561                         !(r_ptr->flags3 & (RF3_EVIL)) &&
562                         !(r_ptr->flags3 & (RF3_UNDEAD)) &&
563                         !(r_ptr->flags3 & (RF3_DEMON)) &&
564                         !(r_ptr->flags2 & (RF2_MULTIPLY)) &&
565                         !(r_ptr->flags4 || r_ptr->a_ability_flags1 || r_ptr->a_ability_flags2));
566                 break;
567         }
568         case SUMMON_HI_DRAGON_LIVING:
569         {
570                 is_match = ((r_ptr->d_char == 'D') && monster_living(r_idx));
571                 break;
572         }
573         case SUMMON_LIVING:
574         {
575                 is_match = monster_living(r_idx);
576                 break;
577         }
578         case SUMMON_PHANTOM:
579         {
580                 is_match = (r_idx == MON_PHANTOM_B || r_idx == MON_PHANTOM_W);
581                 break;
582         }
583         case SUMMON_BLUE_HORROR:
584         {
585                 is_match = (r_idx == MON_BLUE_HORROR);
586                 break;
587         }
588         case SUMMON_ELEMENTAL:
589         {
590                 is_match = (r_ptr->d_char == 'E');
591                 break;
592         }
593         case SUMMON_VORTEX:
594         {
595                 is_match = (r_ptr->d_char == 'v');
596                 break;
597         }
598         case SUMMON_HYBRID:
599         {
600                 is_match = (r_ptr->d_char == 'H');
601                 break;
602         }
603         case SUMMON_BIRD:
604         {
605                 is_match = (r_ptr->d_char == 'B');
606                 break;
607         }
608         case SUMMON_KAMIKAZE:
609         {
610                 int i;
611                 for (i = 0; i < 4; i++)
612                         if (r_ptr->blow[i].method == RBM_EXPLODE) is_match = TRUE;
613                 break;
614         }
615         case SUMMON_KAMIKAZE_LIVING:
616         {
617                 int i;
618
619                 for (i = 0; i < 4; i++)
620                         if (r_ptr->blow[i].method == RBM_EXPLODE) is_match = TRUE;
621                 is_match = (is_match && monster_living(r_idx));
622                 break;
623         }
624         case SUMMON_MANES:
625         {
626                 is_match = (r_idx == MON_MANES);
627                 break;
628         }
629         case SUMMON_LOUSE:
630         {
631                 is_match = (r_idx == MON_LOUSE);
632                 break;
633         }
634         case SUMMON_GUARDIANS:
635         {
636                 is_match = (r_ptr->flags7 & RF7_GUARDIAN);
637                 break;
638         }
639         case SUMMON_KNIGHTS:
640         {
641                 is_match = ((r_idx == MON_NOV_PALADIN) ||
642                         (r_idx == MON_NOV_PALADIN_G) ||
643                         (r_idx == MON_PALADIN) ||
644                         (r_idx == MON_W_KNIGHT) ||
645                         (r_idx == MON_ULTRA_PALADIN) ||
646                         (r_idx == MON_KNI_TEMPLAR));
647                 break;
648         }
649         case SUMMON_EAGLES:
650         {
651                 is_match = (r_ptr->d_char == 'B' &&
652                         (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
653                         (r_ptr->flags8 & RF8_WILD_ONLY));
654                 break;
655         }
656         case SUMMON_PIRANHAS:
657         {
658                 is_match = (r_idx == MON_PIRANHA);
659                 break;
660         }
661         case SUMMON_ARMAGE_GOOD:
662         {
663                 is_match = (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_GOOD));
664                 break;
665         }
666         case SUMMON_ARMAGE_EVIL:
667         {
668                 is_match = ((r_ptr->flags3 & RF3_DEMON) ||
669                         (r_ptr->d_char == 'A' && (r_ptr->flags3 & RF3_EVIL)));
670                 break;
671         }
672         }
673
674         return is_match;
675 }
676
677
678 /*!
679  * @var chameleon_change_m_idx
680  * @brief カメレオンの変身先モンスターIDを受け渡すためのグローバル変数
681  * @todo 変数渡しの問題などもあるができればchameleon_change_m_idxのグローバル変数を除去し、関数引き渡しに移行すること
682  */
683 static int chameleon_change_m_idx = 0;
684
685 /*!
686  * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
687  * @brief 指定されたモンスター種族がダンジョンの制限にかかるかどうかをチェックする / Some dungeon types restrict the possible monsters.
688  * @param player_ptr プレーヤーへの参照ポインタ
689  * @param r_idx チェックするモンスター種族ID
690  * @return 召喚条件が一致するならtrue / Return TRUE is the monster is OK and FALSE otherwise
691  */
692 static bool restrict_monster_to_dungeon(player_type *player_ptr, MONRACE_IDX r_idx)
693 {
694         DUNGEON_IDX d_idx = player_ptr->dungeon_idx;
695         dungeon_type *d_ptr = &d_info[d_idx];
696         monster_race *r_ptr = &r_info[r_idx];
697
698         if (d_ptr->flags1 & DF1_CHAMELEON)
699         {
700                 if (chameleon_change_m_idx) return TRUE;
701         }
702
703         if (d_ptr->flags1 & DF1_NO_MAGIC)
704         {
705                 if (r_idx != MON_CHAMELEON &&
706                         r_ptr->freq_spell &&
707                         !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
708                         !(r_ptr->a_ability_flags1 & RF5_NOMAGIC_MASK) &&
709                         !(r_ptr->a_ability_flags2 & RF6_NOMAGIC_MASK))
710                         return FALSE;
711         }
712
713         if (d_ptr->flags1 & DF1_NO_MELEE)
714         {
715                 if (r_idx == MON_CHAMELEON) return TRUE;
716                 if (!(r_ptr->flags4 & (RF4_BOLT_MASK | RF4_BEAM_MASK | RF4_BALL_MASK)) &&
717                         !(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)) &&
718                         !(r_ptr->a_ability_flags2 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
719                         return FALSE;
720         }
721
722         floor_type *floor_ptr = player_ptr->current_floor_ptr;
723         if (d_ptr->flags1 & DF1_BEGINNER)
724         {
725                 if (r_ptr->level > floor_ptr->dun_level)
726                         return FALSE;
727         }
728
729         if (d_ptr->special_div >= 64) return TRUE;
730         if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
731
732         byte a;
733         switch (d_ptr->mode)
734         {
735         case DUNGEON_MODE_AND:
736         {
737                 if (d_ptr->mflags1)
738                 {
739                         if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
740                                 return FALSE;
741                 }
742
743                 if (d_ptr->mflags2)
744                 {
745                         if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
746                                 return FALSE;
747                 }
748
749                 if (d_ptr->mflags3)
750                 {
751                         if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
752                                 return FALSE;
753                 }
754
755                 if (d_ptr->mflags4)
756                 {
757                         if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
758                                 return FALSE;
759                 }
760
761                 if (d_ptr->m_a_ability_flags1)
762                 {
763                         if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
764                                 return FALSE;
765                 }
766
767                 if (d_ptr->m_a_ability_flags2)
768                 {
769                         if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
770                                 return FALSE;
771                 }
772
773                 if (d_ptr->mflags7)
774                 {
775                         if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
776                                 return FALSE;
777                 }
778
779                 if (d_ptr->mflags8)
780                 {
781                         if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
782                                 return FALSE;
783                 }
784
785                 if (d_ptr->mflags9)
786                 {
787                         if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
788                                 return FALSE;
789                 }
790
791                 if (d_ptr->mflagsr)
792                 {
793                         if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
794                                 return FALSE;
795                 }
796
797                 for (a = 0; a < 5; a++)
798                         if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
799
800                 return TRUE;
801         }
802         case DUNGEON_MODE_NAND:
803         {
804                 if (d_ptr->mflags1)
805                 {
806                         if ((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
807                                 return TRUE;
808                 }
809
810                 if (d_ptr->mflags2)
811                 {
812                         if ((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
813                                 return TRUE;
814                 }
815
816                 if (d_ptr->mflags3)
817                 {
818                         if ((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
819                                 return TRUE;
820                 }
821
822                 if (d_ptr->mflags4)
823                 {
824                         if ((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
825                                 return TRUE;
826                 }
827
828                 if (d_ptr->m_a_ability_flags1)
829                 {
830                         if ((d_ptr->m_a_ability_flags1 & r_ptr->a_ability_flags1) != d_ptr->m_a_ability_flags1)
831                                 return TRUE;
832                 }
833
834                 if (d_ptr->m_a_ability_flags2)
835                 {
836                         if ((d_ptr->m_a_ability_flags2 & r_ptr->a_ability_flags2) != d_ptr->m_a_ability_flags2)
837                                 return TRUE;
838                 }
839
840                 if (d_ptr->mflags7)
841                 {
842                         if ((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
843                                 return TRUE;
844                 }
845
846                 if (d_ptr->mflags8)
847                 {
848                         if ((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
849                                 return TRUE;
850                 }
851
852                 if (d_ptr->mflags9)
853                 {
854                         if ((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
855                                 return TRUE;
856                 }
857
858                 if (d_ptr->mflagsr)
859                 {
860                         if ((d_ptr->mflagsr & r_ptr->flagsr) != d_ptr->mflagsr)
861                                 return TRUE;
862                 }
863
864                 for (a = 0; a < 5; a++)
865                         if (d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return TRUE;
866
867                 return FALSE;
868         }
869         case DUNGEON_MODE_OR:
870         {
871                 if (r_ptr->flags1 & d_ptr->mflags1) return TRUE;
872                 if (r_ptr->flags2 & d_ptr->mflags2) return TRUE;
873                 if (r_ptr->flags3 & d_ptr->mflags3) return TRUE;
874                 if (r_ptr->flags4 & d_ptr->mflags4) return TRUE;
875                 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return TRUE;
876                 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return TRUE;
877                 if (r_ptr->flags7 & d_ptr->mflags7) return TRUE;
878                 if (r_ptr->flags8 & d_ptr->mflags8) return TRUE;
879                 if (r_ptr->flags9 & d_ptr->mflags9) return TRUE;
880                 if (r_ptr->flagsr & d_ptr->mflagsr) return TRUE;
881                 for (a = 0; a < 5; a++)
882                         if (d_ptr->r_char[a] == r_ptr->d_char) return TRUE;
883
884                 return FALSE;
885         }
886         case DUNGEON_MODE_NOR:
887         {
888                 if (r_ptr->flags1 & d_ptr->mflags1) return FALSE;
889                 if (r_ptr->flags2 & d_ptr->mflags2) return FALSE;
890                 if (r_ptr->flags3 & d_ptr->mflags3) return FALSE;
891                 if (r_ptr->flags4 & d_ptr->mflags4) return FALSE;
892                 if (r_ptr->a_ability_flags1 & d_ptr->m_a_ability_flags1) return FALSE;
893                 if (r_ptr->a_ability_flags2 & d_ptr->m_a_ability_flags2) return FALSE;
894                 if (r_ptr->flags7 & d_ptr->mflags7) return FALSE;
895                 if (r_ptr->flags8 & d_ptr->mflags8) return FALSE;
896                 if (r_ptr->flags9 & d_ptr->mflags9) return FALSE;
897                 if (r_ptr->flagsr & d_ptr->mflagsr) return FALSE;
898                 for (a = 0; a < 5; a++)
899                         if (d_ptr->r_char[a] == r_ptr->d_char) return FALSE;
900
901                 return TRUE;
902         }
903         }
904
905         return TRUE;
906 }
907
908 /*
909  * Hack -- function hooks to restrict "get_mon_num_prep()" function
910  */
911 monsterrace_hook_type get_mon_num_hook;
912 monsterrace_hook_type get_mon_num2_hook;
913
914 /*!
915  * @brief モンスター生成制限関数最大2つから / Apply a "monster restriction function" to the "monster allocation table"
916  * @param player_ptr プレーヤーへの参照ポインタ
917  * @param monster_hook 制限関数1
918  * @param monster_hook2 制限関数2
919  * @return エラーコード
920  */
921 errr get_mon_num_prep(player_type *player_ptr, monsterrace_hook_type monster_hook, monsterrace_hook_type monster_hook2)
922 {
923         /* Todo: Check the hooks for non-changes */
924         get_mon_num_hook = monster_hook;
925         get_mon_num2_hook = monster_hook2;
926
927         floor_type *floor_ptr = player_ptr->current_floor_ptr;
928         for (int i = 0; i < alloc_race_size; i++)
929         {
930                 monster_race *r_ptr;
931                 alloc_entry *entry = &alloc_race_table[i];
932                 entry->prob2 = 0;
933                 r_ptr = &r_info[entry->index];
934
935                 if ((get_mon_num_hook && !((*get_mon_num_hook)(entry->index))) ||
936                         (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
937                         continue;
938
939                 if (!player_ptr->phase_out && !chameleon_change_m_idx &&
940                         summon_specific_type != SUMMON_GUARDIANS)
941                 {
942                         if (r_ptr->flags1 & RF1_QUESTOR)
943                                 continue;
944
945                         if (r_ptr->flags7 & RF7_GUARDIAN)
946                                 continue;
947
948                         if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) &&
949                                 (r_ptr->level > floor_ptr->dun_level))
950                                 continue;
951                 }
952
953                 entry->prob2 = entry->prob1;
954                 if (floor_ptr->dun_level && (!floor_ptr->inside_quest || is_fixed_quest_idx(floor_ptr->inside_quest)) &&
955                         !restrict_monster_to_dungeon(player_ptr, entry->index) && !player_ptr->phase_out)
956                 {
957                         int hoge = entry->prob2 * d_info[player_ptr->dungeon_idx].special_div;
958                         entry->prob2 = hoge / 64;
959                         if (randint0(64) < (hoge & 0x3f)) entry->prob2++;
960                 }
961         }
962
963         return 0;
964 }
965
966
967 /*!
968  * @brief 生成モンスター種族を1種生成テーブルから選択する
969  * @param player_ptr プレーヤーへの参照ポインタ
970  * @param level 生成階
971  * @return 選択されたモンスター生成種族
972  * @details
973  * Choose a monster race that seems "appropriate" to the given level
974  *
975  * This function uses the "prob2" field of the "monster allocation table",
976  * and various local information, to calculate the "prob3" field of the
977  * same table, which is then used to choose an "appropriate" monster, in
978  * a relatively efficient manner.
979  *
980  * Note that "town" monsters will *only* be created in the town, and
981  * "normal" monsters will *never* be created in the town, unless the
982  * "level" is "modified", for example, by polymorph or summoning.
983  *
984  * There is a small chance (1/50) of "boosting" the given depth by
985  * a small amount (up to four levels), except in the town.
986  *
987  * It is (slightly) more likely to acquire a monster of the given level
988  * than one of a lower level.  This is done by choosing several monsters
989  * appropriate to the given level and keeping the "hardest" one.
990  *
991  * Note that if no monsters are "appropriate", then this function will
992  * fail, and return zero, but this should *almost* never happen.
993  */
994 MONRACE_IDX get_mon_num(player_type *player_ptr, DEPTH level, BIT_FLAGS option)
995 {
996         int                     i, j, p;
997         int                     r_idx;
998         long            value, total;
999         monster_race    *r_ptr;
1000         alloc_entry             *table = alloc_race_table;
1001
1002         int pls_kakuritu, pls_level, over_days;
1003         int delay = mysqrt(level * 10000L) + (level * 5);
1004
1005         /* town level : same delay as 10F, no nasty mons till day18 */
1006         if (!level) delay = 360;
1007
1008         if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
1009
1010         /* +1 per day after the base date */
1011         /* base dates : day5(1F), day18(10F,0F), day34(30F), day53(60F), day69(90F) */
1012         over_days = MAX(0, current_world_ptr->dungeon_turn / (TURNS_PER_TICK * 10000L) - delay / 20);
1013
1014         /* starts from 1/25, reaches 1/3 after 44days from a level dependent base date */
1015         pls_kakuritu = MAX(NASTY_MON_MAX, NASTY_MON_BASE - over_days / 2);
1016         /* starts from 0, reaches +25lv after 75days from a level dependent base date */
1017         pls_level = MIN(NASTY_MON_PLUS_MAX, over_days / 3);
1018
1019         if (d_info[player_ptr->dungeon_idx].flags1 & DF1_MAZE)
1020         {
1021                 pls_kakuritu = MIN(pls_kakuritu / 2, pls_kakuritu - 10);
1022                 if (pls_kakuritu < 2) pls_kakuritu = 2;
1023                 pls_level += 2;
1024                 level += 3;
1025         }
1026
1027         /* Boost the level */
1028         if (!player_ptr->phase_out && !(d_info[player_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
1029         {
1030                 /* Nightmare mode allows more out-of depth monsters */
1031                 if (ironman_nightmare && !randint0(pls_kakuritu))
1032                 {
1033                         /* What a bizarre calculation */
1034                         level = 1 + (level * MAX_DEPTH / randint1(MAX_DEPTH));
1035                 }
1036                 else
1037                 {
1038                         /* Occasional "nasty" monster */
1039                         if (!randint0(pls_kakuritu))
1040                         {
1041                                 /* Pick a level bonus */
1042                                 level += pls_level;
1043                         }
1044                 }
1045         }
1046
1047         total = 0L;
1048
1049         /* Process probabilities */
1050         for (i = 0; i < alloc_race_size; i++)
1051         {
1052                 if (table[i].level > level) break;
1053                 table[i].prob3 = 0;
1054                 r_idx = table[i].index;
1055                 r_ptr = &r_info[r_idx];
1056                 if (!(option & GMN_ARENA) && !chameleon_change_m_idx)
1057                 {
1058                         if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
1059                                 (r_ptr->flags7 & (RF7_NAZGUL))) &&
1060                                 (r_ptr->cur_num >= r_ptr->max_num))
1061                         {
1062                                 continue;
1063                         }
1064
1065                         if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
1066                                 (r_ptr->cur_num >= 1))
1067                         {
1068                                 continue;
1069                         }
1070
1071                         if (r_idx == MON_BANORLUPART)
1072                         {
1073                                 if (r_info[MON_BANOR].cur_num > 0) continue;
1074                                 if (r_info[MON_LUPART].cur_num > 0) continue;
1075                         }
1076                 }
1077
1078                 table[i].prob3 = table[i].prob2;
1079                 total += table[i].prob3;
1080         }
1081
1082         if (total <= 0) return 0;
1083
1084         value = randint0(total);
1085         int found_count = 0;
1086         for (i = 0; i < alloc_race_size; i++)
1087         {
1088                 if (value < table[i].prob3) break;
1089                 value = value - table[i].prob3;
1090                 found_count++;
1091         }
1092
1093         p = randint0(100);
1094
1095         /* Try for a "harder" monster once (50%) or twice (10%) */
1096         if (p < 60)
1097         {
1098                 j = found_count;
1099                 value = randint0(total);
1100                 for (found_count = 0; found_count < alloc_race_size; found_count++)
1101                 {
1102                         if (value < table[found_count].prob3) break;
1103
1104                         value = value - table[found_count].prob3;
1105                 }
1106
1107                 if (table[found_count].level < table[j].level)
1108                         found_count = j;
1109         }
1110
1111         /* Try for a "harder" monster twice (10%) */
1112         if (p < 10)
1113         {
1114                 j = found_count;
1115                 value = randint0(total);
1116                 for (found_count = 0; found_count < alloc_race_size; found_count++)
1117                 {
1118                         if (value < table[found_count].prob3) break;
1119
1120                         value = value - table[found_count].prob3;
1121                 }
1122
1123                 if (table[found_count].level < table[j].level)
1124                         found_count = j;
1125         }
1126
1127         return (table[found_count].index);
1128 }
1129
1130
1131 /*!
1132  * @brief モンスターの呼称を作成する / Build a string describing a monster in some way.
1133  * @param desc 記述出力先の文字列参照ポインタ
1134  * @param m_ptr モンスターの参照ポインタ
1135  * @param mode 呼称オプション
1136  * @return なし
1137  * @details
1138  * We can correctly describe monsters based on their visibility.
1139  * We can force all monsters to be treated as visible or invisible.
1140  * We can build nominatives, objectives, possessives, or reflexives.
1141  * We can selectively pronominalize hidden, visible, or all monsters.
1142  * We can use definite or indefinite descriptions for hidden monsters.
1143  * We can use definite or indefinite descriptions for visible monsters.
1144  *
1145  * Pronominalization involves the gender whenever possible and allowed,
1146  * so that by cleverly requesting pronominalization / visibility, you
1147  * can get messages like "You hit someone.  She screams in agony!".
1148  *
1149  * Reflexives are acquired by requesting Objective plus Possessive.
1150  *
1151  * If no m_ptr arg is given (?), the monster is assumed to be hidden,
1152  * unless the "Assume Visible" mode is requested.
1153  *
1154  * If no r_ptr arg is given, it is extracted from m_ptr and r_info
1155  * If neither m_ptr nor r_ptr is given, the monster is assumed to
1156  * be neuter, singular, and hidden (unless "Assume Visible" is set),
1157  * in which case you may be in trouble... :-)
1158  *
1159  * I am assuming that no monster name is more than 70 characters long,
1160  * so that "char desc[80];" is sufficiently large for any result.
1161  *
1162  * Mode Flags:
1163  *  MD_OBJECTIVE      --> Objective (or Reflexive)
1164  *  MD_POSSESSIVE     --> Possessive (or Reflexive)
1165  *  MD_INDEF_HIDDEN   --> Use indefinites for hidden monsters ("something")
1166  *  MD_INDEF_VISIBLE  --> Use indefinites for visible monsters ("a kobold")
1167  *  MD_PRON_HIDDEN    --> Pronominalize hidden monsters
1168  *  MD_PRON_VISIBLE   --> Pronominalize visible monsters
1169  *  MD_ASSUME_HIDDEN  --> Assume the monster is hidden
1170  *  MD_ASSUME_VISIBLE --> Assume the monster is visible
1171  *  MD_TRUE_NAME      --> Chameleon's true name
1172  *  MD_IGNORE_HALLU   --> Ignore hallucination, and penetrate shape change
1173  *
1174  * Useful Modes:
1175  *  0x00 --> Full nominative name ("the kobold") or "it"
1176  *  MD_INDEF_HIDDEN --> Full nominative name ("the kobold") or "something"
1177  *  MD_ASSUME_VISIBLE --> Genocide resistance name ("the kobold")
1178  *  MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE --> Killing name ("a kobold")
1179  *  MD_PRON_VISIBLE | MD_POSSESSIVE
1180  *    --> Possessive, genderized if visable ("his") or "its"
1181  *  MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE
1182  *    --> Reflexive, genderized if visable ("himself") or "itself"
1183  */
1184 void monster_desc(player_type *player_ptr, char *desc, monster_type *m_ptr, BIT_FLAGS mode)
1185 {
1186         monster_race *r_ptr;
1187         r_ptr = &r_info[m_ptr->ap_r_idx];
1188         concptr name = (mode & MD_TRUE_NAME) ? (r_name + real_r_ptr(m_ptr)->name) : (r_name + r_ptr->name);
1189         GAME_TEXT silly_name[1024];
1190         bool named = FALSE;
1191         if (player_ptr->image && !(mode & MD_IGNORE_HALLU))
1192         {
1193                 if (one_in_(2))
1194                 {
1195                         if (!get_rnd_line(_("silly_j.txt", "silly.txt"), m_ptr->r_idx, silly_name))
1196                                 named = TRUE;
1197                 }
1198
1199                 if (!named)
1200                 {
1201                         monster_race *hallu_race;
1202
1203                         do
1204                         {
1205                                 hallu_race = &r_info[randint1(max_r_idx - 1)];
1206                         } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
1207
1208                         strcpy(silly_name, (r_name + hallu_race->name));
1209                 }
1210
1211                 name = silly_name;
1212         }
1213
1214         bool seen = (m_ptr && ((mode & MD_ASSUME_VISIBLE) || (!(mode & MD_ASSUME_HIDDEN) && m_ptr->ml)));
1215         bool pron = (m_ptr && ((seen && (mode & MD_PRON_VISIBLE)) || (!seen && (mode & MD_PRON_HIDDEN))));
1216
1217         /* First, try using pronouns, or describing hidden monsters */
1218         floor_type *floor_ptr = player_ptr->current_floor_ptr;
1219         if (!seen || pron)
1220         {
1221                 int kind = 0x00;
1222                 if (r_ptr->flags1 & (RF1_FEMALE)) kind = 0x20;
1223                 else if (r_ptr->flags1 & (RF1_MALE)) kind = 0x10;
1224
1225                 if (!m_ptr || !pron) kind = 0x00;
1226
1227                 concptr res = _("何か", "it");
1228                 switch (kind + (mode & (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE)))
1229                 {
1230 #ifdef JP
1231                 case 0x00:                                                    res = "何か"; break;
1232                         case 0x00 + (MD_OBJECTIVE) : res = "何か"; break;
1233                                 case 0x00 + (MD_POSSESSIVE) : res = "何かの"; break;
1234                                         case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "何か自身"; break;
1235                                                 case 0x00 + (MD_INDEF_HIDDEN) : res = "何か"; break;
1236                                                         case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "何か"; break;
1237                                                                 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "何か"; break;
1238                                                                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "それ自身"; break;
1239 #else
1240                 case 0x00:                                                    res = "it"; break;
1241                         case 0x00 + (MD_OBJECTIVE) : res = "it"; break;
1242                                 case 0x00 + (MD_POSSESSIVE) : res = "its"; break;
1243                                         case 0x00 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "itself"; break;
1244                                                 case 0x00 + (MD_INDEF_HIDDEN) : res = "something"; break;
1245                                                         case 0x00 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "something"; break;
1246                                                                 case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "something's"; break;
1247                                                                         case 0x00 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "itself"; break;
1248 #endif
1249
1250 #ifdef JP
1251                                                                         case 0x10:                                                    res = "彼"; break;
1252                                                                                 case 0x10 + (MD_OBJECTIVE) : res = "彼"; break;
1253                                                                                         case 0x10 + (MD_POSSESSIVE) : res = "彼の"; break;
1254                                                                                                 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼自身"; break;
1255                                                                                                         case 0x10 + (MD_INDEF_HIDDEN) : res = "誰か"; break;
1256                                                                                                                 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "誰か"; break;
1257                                                                                                                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "誰かの"; break;
1258                                                                                                                                 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼自身"; break;
1259 #else
1260                                                                         case 0x10:                                                    res = "he"; break;
1261                                                                                 case 0x10 + (MD_OBJECTIVE) : res = "him"; break;
1262                                                                                         case 0x10 + (MD_POSSESSIVE) : res = "his"; break;
1263                                                                                                 case 0x10 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "himself"; break;
1264                                                                                                         case 0x10 + (MD_INDEF_HIDDEN) : res = "someone"; break;
1265                                                                                                                 case 0x10 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "someone"; break;
1266                                                                                                                         case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "someone's"; break;
1267                                                                                                                                 case 0x10 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "himself"; break;
1268 #endif
1269
1270 #ifdef JP
1271                                                                                                                                 case 0x20:                                                    res = "彼女"; break;
1272                                                                                                                                         case 0x20 + (MD_OBJECTIVE) : res = "彼女"; break;
1273                                                                                                                                                 case 0x20 + (MD_POSSESSIVE) : res = "彼女の"; break;
1274                                                                                                                                                         case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼女自身"; break;
1275                                                                                                                                                                 case 0x20 + (MD_INDEF_HIDDEN) : res = "誰か"; break;
1276                                                                                                                                                                         case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "誰か"; break;
1277                                                                                                                                                                                 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "誰かの"; break;
1278                                                                                                                                                                                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "彼女自身"; break;
1279 #else
1280                                                                                                                                 case 0x20:                                                    res = "she"; break;
1281                                                                                                                                         case 0x20 + (MD_OBJECTIVE) : res = "her"; break;
1282                                                                                                                                                 case 0x20 + (MD_POSSESSIVE) : res = "her"; break;
1283                                                                                                                                                         case 0x20 + (MD_POSSESSIVE | MD_OBJECTIVE) : res = "herself"; break;
1284                                                                                                                                                                 case 0x20 + (MD_INDEF_HIDDEN) : res = "someone"; break;
1285                                                                                                                                                                         case 0x20 + (MD_INDEF_HIDDEN | MD_OBJECTIVE) : res = "someone"; break;
1286                                                                                                                                                                                 case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE) : res = "someone's"; break;
1287                                                                                                                                                                                         case 0x20 + (MD_INDEF_HIDDEN | MD_POSSESSIVE | MD_OBJECTIVE) : res = "herself"; break;
1288 #endif
1289                 }
1290
1291                 (void)strcpy(desc, res);
1292                 return;
1293         }
1294
1295         /* Handle visible monsters, "reflexive" request */
1296         if ((mode & (MD_POSSESSIVE | MD_OBJECTIVE)) == (MD_POSSESSIVE | MD_OBJECTIVE))
1297         {
1298                 /* The monster is visible, so use its gender */
1299                 if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, _("彼女自身", "herself"));
1300                 else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, _("彼自身", "himself"));
1301                 else strcpy(desc, _("それ自身", "itself"));
1302                 return;
1303         }
1304
1305         /* Handle all other visible monster requests */
1306         /* Tanuki? */
1307         if (is_pet(m_ptr) && !is_original_ap(m_ptr))
1308         {
1309 #ifdef JP
1310                 char *t;
1311                 char buf[128];
1312                 strcpy(buf, name);
1313                 t = buf;
1314                 while (strncmp(t, "』", 2) && *t) t++;
1315                 if (*t)
1316                 {
1317                         *t = '\0';
1318                         (void)sprintf(desc, "%s?』", buf);
1319                 }
1320                 else
1321                         (void)sprintf(desc, "%s?", name);
1322 #else
1323                 (void)sprintf(desc, "%s?", name);
1324 #endif
1325         }
1326         else
1327         {
1328                 if ((r_ptr->flags1 & RF1_UNIQUE) && !(player_ptr->image && !(mode & MD_IGNORE_HALLU)))
1329                 {
1330                         if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && !(mode & MD_TRUE_NAME))
1331                         {
1332 #ifdef JP
1333                                 char *t;
1334                                 char buf[128];
1335                                 strcpy(buf, name);
1336                                 t = buf;
1337                                 while (strncmp(t, "』", 2) && *t) t++;
1338                                 if (*t)
1339                                 {
1340                                         *t = '\0';
1341                                         (void)sprintf(desc, "%s?』", buf);
1342                                 }
1343                                 else
1344                                         (void)sprintf(desc, "%s?", name);
1345 #else
1346                                 (void)sprintf(desc, "%s?", name);
1347 #endif
1348                         }
1349                         else if (player_ptr->phase_out &&
1350                                 !(player_ptr->riding && (&floor_ptr->m_list[player_ptr->riding] == m_ptr)))
1351                         {
1352                                 (void)sprintf(desc, _("%sもどき", "fake %s"), name);
1353                         }
1354                         else
1355                         {
1356                                 (void)strcpy(desc, name);
1357                         }
1358                 }
1359                 else if (mode & MD_INDEF_VISIBLE)
1360                 {
1361 #ifdef JP
1362                         (void)strcpy(desc, "");
1363 #else
1364                         (void)strcpy(desc, is_a_vowel(name[0]) ? "an " : "a ");
1365 #endif
1366                         (void)strcat(desc, name);
1367                 }
1368                 else
1369                 {
1370                         if (is_pet(m_ptr))
1371                                 (void)strcpy(desc, _("あなたの", "your "));
1372                         else
1373                                 (void)strcpy(desc, _("", "the "));
1374
1375                         (void)strcat(desc, name);
1376                 }
1377         }
1378
1379         if (m_ptr->nickname)
1380         {
1381                 char buf[128];
1382                 sprintf(buf, _("「%s」", " called %s"), quark_str(m_ptr->nickname));
1383                 strcat(desc, buf);
1384         }
1385
1386         if (player_ptr->riding && (&floor_ptr->m_list[player_ptr->riding] == m_ptr))
1387         {
1388                 strcat(desc, _("(乗馬中)", "(riding)"));
1389         }
1390
1391         if ((mode & MD_IGNORE_HALLU) && (m_ptr->mflag2 & MFLAG2_CHAMELEON))
1392         {
1393                 if (r_ptr->flags1 & RF1_UNIQUE)
1394                 {
1395                         strcat(desc, _("(カメレオンの王)", "(Chameleon Lord)"));
1396                 }
1397                 else
1398                 {
1399                         strcat(desc, _("(カメレオン)", "(Chameleon)"));
1400                 }
1401         }
1402
1403         if ((mode & MD_IGNORE_HALLU) && !is_original_ap(m_ptr))
1404         {
1405                 strcat(desc, format("(%s)", r_name + r_info[m_ptr->r_idx].name));
1406         }
1407
1408         /* Handle the Possessive as a special afterthought */
1409         if (mode & MD_POSSESSIVE)
1410         {
1411                 (void)strcat(desc, _("の", "'s"));
1412         }
1413 }
1414
1415
1416 /*!
1417 * @brief モンスターIDを取り、モンスター名をm_nameに代入する /
1418 * @param player_ptr プレーヤーへの参照ポインタ
1419 * @param m_idx モンスターID
1420 * @param m_name モンスター名を入力する配列
1421 */
1422 void monster_name(player_type *player_ptr, MONSTER_IDX m_idx, char* m_name)
1423 {
1424         monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
1425         monster_desc(player_ptr, m_name, m_ptr, 0x00);
1426 }
1427
1428
1429 /*!
1430  * @brief モンスターの調査による思い出補完処理 / Learn about a monster (by "probing" it)
1431  * @param player_ptr プレーヤーへの参照ポインタ
1432  * @param r_idx 補完されるモンスター種族ID
1433  * @return 明らかになった情報の度数
1434  * @details
1435  * Return the number of new flags learnt.  -Mogami-
1436  */
1437 int lore_do_probe(player_type *player_ptr, MONRACE_IDX r_idx)
1438 {
1439         int n = 0;
1440         monster_race *r_ptr = &r_info[r_idx];
1441         if (r_ptr->r_wake != MAX_UCHAR) n++;
1442         if (r_ptr->r_ignore != MAX_UCHAR) n++;
1443         r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
1444
1445         for (int i = 0; i < 4; i++)
1446         {
1447                 if (r_ptr->blow[i].effect || r_ptr->blow[i].method)
1448                 {
1449                         if (r_ptr->r_blows[i] != MAX_UCHAR) n++;
1450                         r_ptr->r_blows[i] = MAX_UCHAR;
1451                 }
1452         }
1453
1454         byte tmp_byte =
1455                 (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
1456                 ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
1457                         ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
1458                         ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
1459                         ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) +
1460                         ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
1461
1462         if (!(r_ptr->flags1 & RF1_ONLY_GOLD))
1463         {
1464                 if (r_ptr->r_drop_item != tmp_byte) n++;
1465                 r_ptr->r_drop_item = tmp_byte;
1466         }
1467         if (!(r_ptr->flags1 & RF1_ONLY_ITEM))
1468         {
1469                 if (r_ptr->r_drop_gold != tmp_byte) n++;
1470                 r_ptr->r_drop_gold = tmp_byte;
1471         }
1472
1473         if (r_ptr->r_cast_spell != MAX_UCHAR) n++;
1474         r_ptr->r_cast_spell = MAX_UCHAR;
1475
1476         for (int i = 0; i < 32; i++)
1477         {
1478                 if (!(r_ptr->r_flags1 & (1L << i)) &&
1479                         (r_ptr->flags1 & (1L << i))) n++;
1480                 if (!(r_ptr->r_flags2 & (1L << i)) &&
1481                         (r_ptr->flags2 & (1L << i))) n++;
1482                 if (!(r_ptr->r_flags3 & (1L << i)) &&
1483                         (r_ptr->flags3 & (1L << i))) n++;
1484                 if (!(r_ptr->r_flags4 & (1L << i)) &&
1485                         (r_ptr->flags4 & (1L << i))) n++;
1486                 if (!(r_ptr->r_flags5 & (1L << i)) &&
1487                         (r_ptr->a_ability_flags1 & (1L << i))) n++;
1488                 if (!(r_ptr->r_flags6 & (1L << i)) &&
1489                         (r_ptr->a_ability_flags2 & (1L << i))) n++;
1490                 if (!(r_ptr->r_flagsr & (1L << i)) &&
1491                         (r_ptr->flagsr & (1L << i))) n++;
1492         }
1493
1494         r_ptr->r_flags1 = r_ptr->flags1;
1495         r_ptr->r_flags2 = r_ptr->flags2;
1496         r_ptr->r_flags3 = r_ptr->flags3;
1497         r_ptr->r_flags4 = r_ptr->flags4;
1498         r_ptr->r_flags5 = r_ptr->a_ability_flags1;
1499         r_ptr->r_flags6 = r_ptr->a_ability_flags2;
1500         r_ptr->r_flagsr = r_ptr->flagsr;
1501
1502         if (!(r_ptr->r_xtra1 & MR1_SINKA)) n++;
1503         r_ptr->r_xtra1 |= MR1_SINKA;
1504
1505         if (player_ptr->monster_race_idx == r_idx)
1506         {
1507                 player_ptr->window |= (PW_MONSTER);
1508         }
1509
1510         return n;
1511 }
1512
1513
1514 /*!
1515  * @brief モンスターの撃破に伴うドロップ情報の保管処理 / Take note that the given monster just dropped some treasure
1516  * @param player_ptr プレーヤーへの参照ポインタ
1517  * @param m_idx モンスター情報のID
1518  * @param num_item 手に入れたアイテム数
1519  * @param num_gold 手に入れた財宝の単位数
1520  * @return なし
1521  * @details
1522  * Note that learning the "GOOD"/"GREAT" flags gives information
1523  * about the treasure (even when the monster is killed for the first
1524  * time, such as uniques, and the treasure has not been examined yet).
1525  *
1526  * This "indirect" method is used to prevent the player from learning
1527  * exactly how much treasure a monster can drop from observing only
1528  * a single example of a drop.  This method actually observes how much
1529  * gold and items are dropped, and remembers that information to be
1530  * described later by the monster recall code.
1531  */
1532 void lore_treasure(player_type *player_ptr, MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
1533 {
1534         monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
1535         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1536
1537         if (!is_original_ap(m_ptr)) return;
1538
1539         if (num_item > r_ptr->r_drop_item) r_ptr->r_drop_item = num_item;
1540         if (num_gold > r_ptr->r_drop_gold) r_ptr->r_drop_gold = num_gold;
1541
1542         if (r_ptr->flags1 & (RF1_DROP_GOOD)) r_ptr->r_flags1 |= (RF1_DROP_GOOD);
1543         if (r_ptr->flags1 & (RF1_DROP_GREAT)) r_ptr->r_flags1 |= (RF1_DROP_GREAT);
1544         if (player_ptr->monster_race_idx == m_ptr->r_idx) player_ptr->window |= (PW_MONSTER);
1545 }
1546
1547
1548 /*!
1549  * @brief モンスターの各情報を更新する / This function updates the monster record of the given monster
1550  * @param m_idx 更新するモンスター情報のID
1551  * @param full プレイヤーとの距離更新を行うならばtrue
1552  * @return なし
1553  * @details
1554  * This involves extracting the distance to the player (if requested),
1555  * and then checking for visibility (natural, infravision, see-invis,
1556  * telepathy), updating the monster visibility flag, redrawing (or
1557  * erasing) the monster when its visibility changes, and taking note
1558  * of any interesting monster flags (cold-blooded, invisible, etc).
1559  *
1560  * Note the new "mflag" field which encodes several monster state flags,
1561  * including "view" for when the monster is currently in line of sight,
1562  * and "mark" for when the monster is currently visible via detection.
1563  *
1564  * The only monster fields that are changed here are "cdis" (the
1565  * distance from the player), "ml" (visible to the player), and
1566  * "mflag" (to maintain the "MFLAG_VIEW" flag).
1567  *
1568  * Note the special "update_monsters()" function which can be used to
1569  * call this function once for every monster.
1570  *
1571  * Note the "full" flag which requests that the "cdis" field be updated,
1572  * this is only needed when the monster (or the player) has moved.
1573  *
1574  * Every time a monster moves, we must call this function for that
1575  * monster, and update the distance, and the visibility.  Every time
1576  * the player moves, we must call this function for every monster, and
1577  * update the distance, and the visibility.  Whenever the player "state"
1578  * changes in certain ways ("blindness", "infravision", "telepathy",
1579  * and "see invisible"), we must call this function for every monster,
1580  * and update the visibility.
1581  *
1582  * Routines that change the "illumination" of a grid must also call this
1583  * function for any monster in that grid, since the "visibility" of some
1584  * monsters may be based on the illumination of their grid.
1585  *
1586  * Note that this function is called once per monster every time the
1587  * player moves.  When the player is running, this function is one
1588  * of the primary bottlenecks, along with "update_view()" and the
1589  * "process_monsters()" code, so efficiency is important.
1590  *
1591  * Note the optimized "inline" version of the "distance()" function.
1592  *
1593  * A monster is "visible" to the player if (1) it has been detected
1594  * by the player, (2) it is close to the player and the player has
1595  * telepathy, or (3) it is close to the player, and in line of sight
1596  * of the player, and it is "illuminated" by some combination of
1597  * infravision, torch light, or permanent light (invisible monsters
1598  * are only affected by "light" if the player can see invisible).
1599  *
1600  * Monsters which are not on the current panel may be "visible" to
1601  * the player, and their descriptions will include an "offscreen"
1602  * reference.  Currently, offscreen monsters cannot be targetted
1603  * or viewed directly, but old targets will remain set.  XXX XXX
1604  *
1605  * The player can choose to be disturbed by several things, including
1606  * "disturb_move" (monster which is viewable moves in some way), and
1607  * "disturb_near" (monster which is "easily" viewable moves in some
1608  * way).  Note that "moves" includes "appears" and "disappears".
1609  */
1610 void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full)
1611 {
1612         monster_type *m_ptr = &subject_ptr->current_floor_ptr->m_list[m_idx];
1613         monster_race *r_ptr = &r_info[m_ptr->r_idx];
1614
1615         bool do_disturb = disturb_move;
1616
1617         POSITION fy = m_ptr->fy;
1618         POSITION fx = m_ptr->fx;
1619
1620         bool flag = FALSE;
1621         bool easy = FALSE;
1622         bool in_darkness = (d_info[subject_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !subject_ptr->see_nocto;
1623         if (disturb_high)
1624         {
1625                 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
1626                 if (ap_r_ptr->r_tkills && ap_r_ptr->level >= subject_ptr->lev)
1627                         do_disturb = TRUE;
1628         }
1629
1630         POSITION distance;
1631         if (full)
1632         {
1633                 int dy = (subject_ptr->y > fy) ? (subject_ptr->y - fy) : (fy - subject_ptr->y);
1634                 int dx = (subject_ptr->x > fx) ? (subject_ptr->x - fx) : (fx - subject_ptr->x);
1635
1636                 distance = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
1637                 if (distance > 255) distance = 255;
1638                 if (!distance) distance = 1;
1639
1640                 m_ptr->cdis = distance;
1641         }
1642         else
1643         {
1644                 distance = m_ptr->cdis;
1645         }
1646
1647         if (m_ptr->mflag2 & (MFLAG2_MARK)) flag = TRUE;
1648
1649         if (distance <= (in_darkness ? MAX_SIGHT / 2 : MAX_SIGHT))
1650         {
1651                 if (!in_darkness || (distance <= MAX_SIGHT / 4))
1652                 {
1653                         if (subject_ptr->special_defense & KATA_MUSOU)
1654                         {
1655                                 flag = TRUE;
1656                                 if (is_original_ap(m_ptr) && !subject_ptr->image)
1657                                 {
1658                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1659                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1660                                 }
1661                         }
1662                         else if (subject_ptr->telepathy)
1663                         {
1664                                 if (r_ptr->flags2 & (RF2_EMPTY_MIND))
1665                                 {
1666                                         if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags2 |= (RF2_EMPTY_MIND);
1667                                 }
1668                                 else if (r_ptr->flags2 & (RF2_WEIRD_MIND))
1669                                 {
1670                                         if ((m_idx % 10) == 5)
1671                                         {
1672                                                 flag = TRUE;
1673                                                 if (is_original_ap(m_ptr) && !subject_ptr->image)
1674                                                 {
1675                                                         r_ptr->r_flags2 |= (RF2_WEIRD_MIND);
1676                                                         if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1677                                                         if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1678                                                 }
1679                                         }
1680                                 }
1681                                 else
1682                                 {
1683                                         flag = TRUE;
1684                                         if (is_original_ap(m_ptr) && !subject_ptr->image)
1685                                         {
1686                                                 if (r_ptr->flags2 & (RF2_SMART)) r_ptr->r_flags2 |= (RF2_SMART);
1687                                                 if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
1688                                         }
1689                                 }
1690                         }
1691
1692                         if ((subject_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
1693                         {
1694                                 flag = TRUE;
1695                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_ANIMAL);
1696                         }
1697
1698                         if ((subject_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
1699                         {
1700                                 flag = TRUE;
1701                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_UNDEAD);
1702                         }
1703
1704                         if ((subject_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
1705                         {
1706                                 flag = TRUE;
1707                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_DEMON);
1708                         }
1709
1710                         if ((subject_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
1711                         {
1712                                 flag = TRUE;
1713                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_ORC);
1714                         }
1715
1716                         if ((subject_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
1717                         {
1718                                 flag = TRUE;
1719                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_TROLL);
1720                         }
1721
1722                         if ((subject_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
1723                         {
1724                                 flag = TRUE;
1725                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_GIANT);
1726                         }
1727
1728                         if ((subject_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
1729                         {
1730                                 flag = TRUE;
1731                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_DRAGON);
1732                         }
1733
1734                         if ((subject_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
1735                         {
1736                                 flag = TRUE;
1737                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags2 |= (RF2_HUMAN);
1738                         }
1739
1740                         if ((subject_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
1741                         {
1742                                 flag = TRUE;
1743                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_EVIL);
1744                         }
1745
1746                         if ((subject_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
1747                         {
1748                                 flag = TRUE;
1749                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_GOOD);
1750                         }
1751
1752                         if ((subject_ptr->esp_nonliving) &&
1753                                 ((r_ptr->flags3 & (RF3_DEMON | RF3_UNDEAD | RF3_NONLIVING)) == RF3_NONLIVING))
1754                         {
1755                                 flag = TRUE;
1756                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags3 |= (RF3_NONLIVING);
1757                         }
1758
1759                         if ((subject_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
1760                         {
1761                                 flag = TRUE;
1762                                 if (is_original_ap(m_ptr) && !subject_ptr->image) r_ptr->r_flags1 |= (RF1_UNIQUE);
1763                         }
1764                 }
1765
1766                 if (player_has_los_bold(subject_ptr, fy, fx) && !subject_ptr->blind)
1767                 {
1768                         bool do_invisible = FALSE;
1769                         bool do_cold_blood = FALSE;
1770
1771                         if (subject_ptr->concent >= CONCENT_RADAR_THRESHOLD)
1772                         {
1773                                 easy = flag = TRUE;
1774                         }
1775
1776                         if (distance <= subject_ptr->see_infra)
1777                         {
1778                                 if ((r_ptr->flags2 & (RF2_COLD_BLOOD | RF2_AURA_FIRE)) == RF2_COLD_BLOOD)
1779                                 {
1780                                         do_cold_blood = TRUE;
1781                                 }
1782                                 else
1783                                 {
1784                                         easy = flag = TRUE;
1785                                 }
1786                         }
1787
1788                         if (player_can_see_bold(subject_ptr, fy, fx))
1789                         {
1790                                 if (r_ptr->flags2 & (RF2_INVISIBLE))
1791                                 {
1792                                         do_invisible = TRUE;
1793                                         if (subject_ptr->see_inv)
1794                                         {
1795                                                 easy = flag = TRUE;
1796                                         }
1797                                 }
1798                                 else
1799                                 {
1800                                         easy = flag = TRUE;
1801                                 }
1802                         }
1803
1804                         if (flag)
1805                         {
1806                                 if (is_original_ap(m_ptr) && !subject_ptr->image)
1807                                 {
1808                                         if (do_invisible) r_ptr->r_flags2 |= (RF2_INVISIBLE);
1809                                         if (do_cold_blood) r_ptr->r_flags2 |= (RF2_COLD_BLOOD);
1810                                 }
1811                         }
1812                 }
1813         }
1814
1815         /* The monster is now visible */
1816         if (flag)
1817         {
1818                 if (!m_ptr->ml)
1819                 {
1820                         m_ptr->ml = TRUE;
1821                         lite_spot(subject_ptr, fy, fx);
1822
1823                         if (subject_ptr->health_who == m_idx) subject_ptr->redraw |= (PR_HEALTH);
1824                         if (subject_ptr->riding == m_idx) subject_ptr->redraw |= (PR_UHEALTH);
1825
1826                         if (!subject_ptr->image)
1827                         {
1828                                 if ((m_ptr->ap_r_idx == MON_KAGE) && (r_info[MON_KAGE].r_sights < MAX_SHORT))
1829                                         r_info[MON_KAGE].r_sights++;
1830                                 else if (is_original_ap(m_ptr) && (r_ptr->r_sights < MAX_SHORT))
1831                                         r_ptr->r_sights++;
1832                         }
1833
1834                         if (r_info[m_ptr->ap_r_idx].flags2 & RF2_ELDRITCH_HORROR)
1835                         {
1836                                 sanity_blast(subject_ptr, m_ptr, FALSE);
1837                         }
1838
1839                         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)))
1840                         {
1841                                 if (disturb_pets || is_hostile(m_ptr))
1842                                         disturb(subject_ptr, TRUE, TRUE);
1843                         }
1844                 }
1845         }
1846
1847         /* The monster is not visible */
1848         else
1849         {
1850                 if (m_ptr->ml)
1851                 {
1852                         m_ptr->ml = FALSE;
1853                         lite_spot(subject_ptr, fy, fx);
1854
1855                         if (subject_ptr->health_who == m_idx) subject_ptr->redraw |= (PR_HEALTH);
1856                         if (subject_ptr->riding == m_idx) subject_ptr->redraw |= (PR_UHEALTH);
1857                         if (do_disturb)
1858                         {
1859                                 if (disturb_pets || is_hostile(m_ptr))
1860                                         disturb(subject_ptr, TRUE, TRUE);
1861                         }
1862                 }
1863         }
1864
1865         /* The monster is now easily visible */
1866         if (easy)
1867         {
1868                 if (!(m_ptr->mflag & (MFLAG_VIEW)))
1869                 {
1870                         m_ptr->mflag |= (MFLAG_VIEW);
1871                         if (do_disturb)
1872                         {
1873                                 if (disturb_pets || is_hostile(m_ptr))
1874                                         disturb(subject_ptr, TRUE, TRUE);
1875                         }
1876                 }
1877
1878                 return;
1879         }
1880
1881         /* The monster is not easily visible */
1882         /* Change */
1883         if (!(m_ptr->mflag & (MFLAG_VIEW))) return;
1884
1885         /* Mark as not easily visible */
1886         m_ptr->mflag &= ~(MFLAG_VIEW);
1887
1888         if (do_disturb)
1889         {
1890                 if (disturb_pets || is_hostile(m_ptr))
1891                         disturb(subject_ptr, TRUE, TRUE);
1892         }
1893 }
1894
1895
1896 /*!
1897  * @param player_ptr プレーヤーへの参照ポインタ
1898  * @brief 単純に生存している全モンスターの更新処理を行う / This function simply updates all the (non-dead) monsters (see above).
1899  * @param full 距離更新を行うならtrue
1900  * @return なし
1901  */
1902 void update_monsters(player_type *player_ptr, bool full)
1903 {
1904         floor_type *floor_ptr = player_ptr->current_floor_ptr;
1905         for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++)
1906         {
1907                 monster_type *m_ptr = &floor_ptr->m_list[i];
1908                 if (!monster_is_valid(m_ptr)) continue;
1909                 update_monster(player_ptr, i, full);
1910         }
1911 }
1912
1913
1914 /*!
1915  * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
1916  * @param player_ptr プレーヤーへの参照ポインタ
1917  * @brief カメレオンの王の変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
1918  * @param r_idx モンスター種族ID
1919  * @return 対象にできるならtrueを返す
1920  */
1921 static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx)
1922 {
1923         floor_type *floor_ptr = p_ptr->current_floor_ptr;
1924         monster_race *r_ptr = &r_info[r_idx];
1925         monster_type *m_ptr = &floor_ptr->m_list[chameleon_change_m_idx];
1926         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
1927
1928         if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
1929         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
1930
1931         if (ABS(r_ptr->level - r_info[MON_CHAMELEON_K].level) > 5) return FALSE;
1932
1933         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))
1934                 return FALSE;
1935
1936         if (!monster_can_cross_terrain(p_ptr, floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
1937
1938         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
1939         {
1940                 if (monster_has_hostile_align(p_ptr, m_ptr, 0, 0, r_ptr)) return FALSE;
1941         }
1942         else if (summon_specific_who > 0)
1943         {
1944                 if (monster_has_hostile_align(p_ptr, &floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
1945         }
1946
1947         return TRUE;
1948 }
1949
1950
1951 /*!
1952  * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
1953  * @brief カメレオンの変身対象となるモンスターかどうか判定する / Hack -- the index of the summoning monster
1954  * @param r_idx モンスター種族ID
1955  * @return 対象にできるならtrueを返す
1956  * @todo グローバル変数対策の上 monster_hook.cへ移す。
1957  */
1958 static bool monster_hook_chameleon(MONRACE_IDX r_idx)
1959 {
1960         floor_type *floor_ptr = p_ptr->current_floor_ptr;
1961         monster_race *r_ptr = &r_info[r_idx];
1962         monster_type *m_ptr = &floor_ptr->m_list[chameleon_change_m_idx];
1963         monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
1964
1965         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
1966         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
1967         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
1968
1969         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))
1970                 return FALSE;
1971
1972         if (!monster_can_cross_terrain(p_ptr, floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, r_ptr, 0)) return FALSE;
1973
1974         if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
1975         {
1976                 if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
1977                 if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
1978                 if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
1979         }
1980         else if (summon_specific_who > 0)
1981         {
1982                 if (monster_has_hostile_align(p_ptr, &floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE;
1983         }
1984
1985         return (*(get_monster_hook(p_ptr)))(r_idx);
1986 }
1987
1988
1989 /*!
1990  * @brief モンスターの変身処理
1991  * @param player_ptr プレーヤーへの参照ポインタ
1992  * @param m_idx 変身処理を受けるモンスター情報のID
1993  * @param born 生成時の初変身先指定ならばtrue
1994  * @param r_idx 旧モンスター種族のID
1995  * @return なし
1996  */
1997 void choose_new_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx)
1998 {
1999         floor_type *floor_ptr = player_ptr->current_floor_ptr;
2000         monster_type *m_ptr = &floor_ptr->m_list[m_idx];
2001         monster_race *r_ptr;
2002
2003         bool old_unique = FALSE;
2004         if (r_info[m_ptr->r_idx].flags1 & RF1_UNIQUE)
2005                 old_unique = TRUE;
2006         if (old_unique && (r_idx == MON_CHAMELEON)) r_idx = MON_CHAMELEON_K;
2007         r_ptr = &r_info[r_idx];
2008
2009         char old_m_name[MAX_NLEN];
2010         monster_desc(player_ptr, old_m_name, m_ptr, 0);
2011
2012         if (!r_idx)
2013         {
2014                 DEPTH level;
2015
2016                 chameleon_change_m_idx = m_idx;
2017                 if (old_unique)
2018                         get_mon_num_prep(player_ptr, monster_hook_chameleon_lord, NULL);
2019                 else
2020                         get_mon_num_prep(player_ptr, monster_hook_chameleon, NULL);
2021
2022                 if (old_unique)
2023                         level = r_info[MON_CHAMELEON_K].level;
2024                 else if (!floor_ptr->dun_level)
2025                         level = wilderness[player_ptr->wilderness_y][player_ptr->wilderness_x].level;
2026                 else
2027                         level = floor_ptr->dun_level;
2028
2029                 if (d_info[player_ptr->dungeon_idx].flags1 & DF1_CHAMELEON) level += 2 + randint1(3);
2030
2031                 r_idx = get_mon_num(player_ptr, level, 0);
2032                 r_ptr = &r_info[r_idx];
2033
2034                 chameleon_change_m_idx = 0;
2035                 if (!r_idx) return;
2036         }
2037
2038         m_ptr->r_idx = r_idx;
2039         m_ptr->ap_r_idx = r_idx;
2040         update_monster(player_ptr, m_idx, FALSE);
2041         lite_spot(player_ptr, m_ptr->fy, m_ptr->fx);
2042
2043         int old_r_idx = m_ptr->r_idx;
2044         if ((r_info[old_r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) ||
2045                 (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)))
2046                 player_ptr->update |= (PU_MON_LITE);
2047
2048         if (born)
2049         {
2050                 if (r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))
2051                 {
2052                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2053                         if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2054                         if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2055                 }
2056
2057                 return;
2058         }
2059
2060         if (m_idx == player_ptr->riding)
2061         {
2062                 GAME_TEXT m_name[MAX_NLEN];
2063                 monster_desc(player_ptr, m_name, m_ptr, 0);
2064                 msg_format(_("突然%sが変身した。", "Suddenly, %s transforms!"), old_m_name);
2065                 if (!(r_ptr->flags7 & RF7_RIDING))
2066                         if (rakuba(player_ptr, 0, TRUE)) msg_format(_("地面に落とされた。", "You have fallen from %s."), m_name);
2067         }
2068
2069         m_ptr->mspeed = get_mspeed(player_ptr, r_ptr);
2070
2071         int oldmaxhp = m_ptr->max_maxhp;
2072         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2073         {
2074                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2075         }
2076         else
2077         {
2078                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2079         }
2080
2081         if (ironman_nightmare)
2082         {
2083                 u32b hp = m_ptr->max_maxhp * 2L;
2084                 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2085         }
2086
2087         m_ptr->maxhp = (long)(m_ptr->maxhp * m_ptr->max_maxhp) / oldmaxhp;
2088         if (m_ptr->maxhp < 1) m_ptr->maxhp = 1;
2089         m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
2090         m_ptr->dealt_damage = 0;
2091 }
2092
2093
2094 /*!
2095  * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
2096  * @brief たぬきの変身対象となるモンスターかどうか判定する / Hook for Tanuki
2097  * @param r_idx モンスター種族ID
2098  * @return 対象にできるならtrueを返す
2099  * @todo グローバル変数対策の上 monster_hook.cへ移す。
2100  */
2101 static bool monster_hook_tanuki(MONRACE_IDX r_idx)
2102 {
2103         monster_race *r_ptr = &r_info[r_idx];
2104
2105         if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
2106         if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
2107         if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
2108         if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
2109
2110         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))
2111                 return FALSE;
2112
2113         return (*(get_monster_hook(p_ptr)))(r_idx);
2114 }
2115
2116
2117 /*!
2118  * @param player_ptr プレーヤーへの参照ポインタ
2119  * @brief モンスターの表層IDを設定する / Set initial racial appearance of a monster
2120  * @param r_idx モンスター種族ID
2121  * @return モンスター種族の表層ID
2122  */
2123 static MONRACE_IDX initial_r_appearance(player_type *player_ptr, MONRACE_IDX r_idx, BIT_FLAGS generate_mode)
2124 {
2125         floor_type *floor_ptr = player_ptr->current_floor_ptr;
2126         if (player_ptr->pseikaku == SEIKAKU_CHARGEMAN && (generate_mode & PM_JURAL) && !(generate_mode & (PM_MULTIPLY | PM_KAGE)))
2127         {
2128                 return MON_ALIEN_JURAL;
2129         }
2130
2131         if (!(r_info[r_idx].flags7 & RF7_TANUKI))
2132                 return r_idx;
2133
2134         get_mon_num_prep(player_ptr, monster_hook_tanuki, NULL);
2135
2136         int attempts = 1000;
2137         DEPTH min = MIN(floor_ptr->base_level - 5, 50);
2138         while (--attempts)
2139         {
2140                 MONRACE_IDX ap_r_idx = get_mon_num(player_ptr, floor_ptr->base_level + 10, 0);
2141                 if (r_info[ap_r_idx].level >= min) return ap_r_idx;
2142         }
2143
2144         return r_idx;
2145 }
2146
2147
2148 /*!
2149  * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
2150  * @brief モンスターの個体加速を設定する / Get initial monster speed
2151  * @param r_ptr モンスター種族の参照ポインタ
2152  * @return 加速値
2153  */
2154 SPEED get_mspeed(player_type *player_ptr, monster_race *r_ptr)
2155 {
2156         SPEED mspeed = r_ptr->speed;
2157         if (!(r_ptr->flags1 & RF1_UNIQUE) && !player_ptr->current_floor_ptr->inside_arena)
2158         {
2159                 /* Allow some small variation per monster */
2160                 int i = SPEED_TO_ENERGY(r_ptr->speed) / (one_in_(4) ? 3 : 10);
2161                 if (i) mspeed += rand_spread(0, i);
2162         }
2163
2164         if (mspeed > 199) mspeed = 199;
2165
2166         return mspeed;
2167 }
2168
2169
2170 /*!
2171  * @brief モンスターを一体生成する / Attempt to place a monster of the given race at the given location.
2172  * @param player_ptr プレーヤーへの参照ポインタ
2173  * @param who 召喚を行ったモンスターID
2174  * @param y 生成位置y座標
2175  * @param x 生成位置x座標
2176  * @param r_idx 生成モンスター種族
2177  * @param mode 生成オプション
2178  * @return 成功したらtrue
2179  * @details
2180  * To give the player a sporting chance, any monster that appears in
2181  * line-of-sight and is extremely dangerous can be marked as
2182  * "FORCE_SLEEP", which will cause them to be placed with low energy,
2183  * which often (but not always) lets the player move before they do.
2184  *
2185  * This routine refuses to place out-of-depth "FORCE_DEPTH" monsters.
2186  *
2187  * Use special "here" and "dead" flags for unique monsters,
2188  * remove old "cur_num" and "max_num" fields.
2189  *
2190  * Actually, do something similar for artifacts, to simplify
2191  * the "preserve" mode, and to make the "what artifacts" flag more useful.
2192  *
2193  * This is the only function which may place a monster in the dungeon,
2194  * except for the savefile loading code.
2195  */
2196 static bool place_monster_one(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2197 {
2198         floor_type *floor_ptr = player_ptr->current_floor_ptr;
2199         grid_type *g_ptr = &floor_ptr->grid_array[y][x];
2200         monster_type *m_ptr;
2201         monster_race *r_ptr = &r_info[r_idx];
2202         concptr name = (r_name + r_ptr->name);
2203
2204         if (player_ptr->wild_mode) return FALSE;
2205         if (!in_bounds(floor_ptr, y, x)) return FALSE;
2206         if (!r_idx) return FALSE;
2207         if (!r_ptr->name) return FALSE;
2208
2209         if (!(mode & PM_IGNORE_TERRAIN))
2210         {
2211                 if (pattern_tile(floor_ptr, y, x)) return FALSE;
2212                 if (!monster_can_enter(player_ptr, y, x, r_ptr, 0)) return FALSE;
2213         }
2214
2215         if (!player_ptr->phase_out)
2216         {
2217                 if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
2218                         (r_ptr->flags7 & (RF7_NAZGUL))) &&
2219                         (r_ptr->cur_num >= r_ptr->max_num))
2220                 {
2221                         return FALSE;
2222                 }
2223
2224                 if ((r_ptr->flags7 & (RF7_UNIQUE2)) &&
2225                         (r_ptr->cur_num >= 1))
2226                 {
2227                         return FALSE;
2228                 }
2229
2230                 if (r_idx == MON_BANORLUPART)
2231                 {
2232                         if (r_info[MON_BANOR].cur_num > 0) return FALSE;
2233                         if (r_info[MON_LUPART].cur_num > 0) return FALSE;
2234                 }
2235
2236                 if ((r_ptr->flags1 & (RF1_FORCE_DEPTH)) && (floor_ptr->dun_level < r_ptr->level) &&
2237                         (!ironman_nightmare || (r_ptr->flags1 & (RF1_QUESTOR))))
2238                 {
2239                         return FALSE;
2240                 }
2241         }
2242
2243         if (quest_number(player_ptr, floor_ptr->dun_level))
2244         {
2245                 int hoge = quest_number(player_ptr, floor_ptr->dun_level);
2246                 if ((quest[hoge].type == QUEST_TYPE_KILL_LEVEL) || (quest[hoge].type == QUEST_TYPE_RANDOM))
2247                 {
2248                         if (r_idx == quest[hoge].r_idx)
2249                         {
2250                                 int number_mon, i2, j2;
2251                                 number_mon = 0;
2252
2253                                 for (i2 = 0; i2 < floor_ptr->width; ++i2)
2254                                         for (j2 = 0; j2 < floor_ptr->height; j2++)
2255                                                 if (floor_ptr->grid_array[j2][i2].m_idx > 0)
2256                                                         if (floor_ptr->m_list[floor_ptr->grid_array[j2][i2].m_idx].r_idx == quest[hoge].r_idx)
2257                                                                 number_mon++;
2258                                 if (number_mon + quest[hoge].cur_num >= quest[hoge].max_num)
2259                                         return FALSE;
2260                         }
2261                 }
2262         }
2263
2264         if (is_glyph_grid(g_ptr))
2265         {
2266                 if (randint1(BREAK_GLYPH) < (r_ptr->level + 20))
2267                 {
2268                         if (g_ptr->info & CAVE_MARK)
2269                         {
2270                                 msg_print(_("守りのルーンが壊れた!", "The rune of protection is broken!"));
2271                         }
2272
2273                         g_ptr->info &= ~(CAVE_MARK);
2274                         g_ptr->info &= ~(CAVE_OBJECT);
2275                         g_ptr->mimic = 0;
2276
2277                         note_spot(player_ptr, y, x);
2278                 }
2279                 else return FALSE;
2280         }
2281
2282         msg_format_wizard(CHEAT_MONSTER, _("%s(Lv%d)を生成しました。", "%s(Lv%d) was generated."), name, r_ptr->level);
2283         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL) || (r_ptr->level < 10)) mode &= ~PM_KAGE;
2284
2285         g_ptr->m_idx = m_pop(player_ptr);
2286         hack_m_idx_ii = g_ptr->m_idx;
2287         if (!g_ptr->m_idx) return FALSE;
2288
2289         m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
2290         m_ptr->r_idx = r_idx;
2291         m_ptr->ap_r_idx = initial_r_appearance(player_ptr, r_idx, mode);
2292
2293         m_ptr->mflag = 0;
2294         m_ptr->mflag2 = 0;
2295         if ((mode & PM_MULTIPLY) && (who > 0) && !is_original_ap(&floor_ptr->m_list[who]))
2296         {
2297                 m_ptr->ap_r_idx = floor_ptr->m_list[who].ap_r_idx;
2298                 if (floor_ptr->m_list[who].mflag2 & MFLAG2_KAGE) m_ptr->mflag2 |= MFLAG2_KAGE;
2299         }
2300
2301         if ((who > 0) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD)))
2302                 m_ptr->sub_align = floor_ptr->m_list[who].sub_align;
2303         else
2304         {
2305                 m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2306                 if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL;
2307                 if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD;
2308         }
2309
2310         m_ptr->fy = y;
2311         m_ptr->fx = x;
2312         m_ptr->current_floor_ptr = floor_ptr;
2313
2314         for (int cmi = 0; cmi < MAX_MTIMED; cmi++) m_ptr->mtimed[cmi] = 0;
2315
2316         m_ptr->cdis = 0;
2317         reset_target(m_ptr);
2318         m_ptr->nickname = 0;
2319         m_ptr->exp = 0;
2320
2321         if (who > 0 && is_pet(&floor_ptr->m_list[who]))
2322         {
2323                 mode |= PM_FORCE_PET;
2324                 m_ptr->parent_m_idx = who;
2325         }
2326         else
2327         {
2328                 m_ptr->parent_m_idx = 0;
2329         }
2330
2331         if (r_ptr->flags7 & RF7_CHAMELEON)
2332         {
2333                 choose_new_monster(player_ptr, g_ptr->m_idx, TRUE, 0);
2334                 r_ptr = &r_info[m_ptr->r_idx];
2335                 m_ptr->mflag2 |= MFLAG2_CHAMELEON;
2336                 if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
2337                         m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
2338         }
2339         else if ((mode & PM_KAGE) && !(mode & PM_FORCE_PET))
2340         {
2341                 m_ptr->ap_r_idx = MON_KAGE;
2342                 m_ptr->mflag2 |= MFLAG2_KAGE;
2343         }
2344
2345         if (mode & PM_NO_PET) m_ptr->mflag2 |= MFLAG2_NOPET;
2346
2347         m_ptr->ml = FALSE;
2348         if (mode & PM_FORCE_PET)
2349         {
2350                 set_pet(player_ptr, m_ptr);
2351         }
2352         else if ((r_ptr->flags7 & RF7_FRIENDLY) ||
2353                 (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(player_ptr, who))
2354         {
2355                 if (!monster_has_hostile_align(player_ptr, NULL, 0, -1, r_ptr)) set_friendly(m_ptr);
2356         }
2357
2358         m_ptr->mtimed[MTIMED_CSLEEP] = 0;
2359         if ((mode & PM_ALLOW_SLEEP) && r_ptr->sleep && !ironman_nightmare)
2360         {
2361                 int val = r_ptr->sleep;
2362                 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, (val * 2) + randint1(val * 10));
2363         }
2364
2365         if (r_ptr->flags1 & RF1_FORCE_MAXHP)
2366         {
2367                 m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside);
2368         }
2369         else
2370         {
2371                 m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside);
2372         }
2373
2374         if (ironman_nightmare)
2375         {
2376                 u32b hp = m_ptr->max_maxhp * 2L;
2377
2378                 m_ptr->max_maxhp = (HIT_POINT)MIN(30000, hp);
2379         }
2380
2381         m_ptr->maxhp = m_ptr->max_maxhp;
2382         if (m_ptr->r_idx == MON_WOUNDED_BEAR)
2383                 m_ptr->hp = m_ptr->maxhp / 2;
2384         else m_ptr->hp = m_ptr->maxhp;
2385
2386         m_ptr->dealt_damage = 0;
2387
2388         m_ptr->mspeed = get_mspeed(player_ptr, r_ptr);
2389
2390         if (mode & PM_HASTE) (void)set_monster_fast(player_ptr, g_ptr->m_idx, 100);
2391
2392         if (!ironman_nightmare)
2393         {
2394                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100);
2395         }
2396         else
2397         {
2398                 m_ptr->energy_need = ENERGY_NEED() - (s16b)randint0(100) * 2;
2399         }
2400
2401         if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
2402         {
2403                 m_ptr->mflag |= (MFLAG_NICE);
2404                 repair_monsters = TRUE;
2405         }
2406
2407         if (g_ptr->m_idx < hack_m_idx)
2408         {
2409                 m_ptr->mflag |= (MFLAG_BORN);
2410         }
2411
2412         if (r_ptr->flags7 & RF7_SELF_LD_MASK)
2413                 player_ptr->update |= (PU_MON_LITE);
2414         else if ((r_ptr->flags7 & RF7_HAS_LD_MASK) && !MON_CSLEEP(m_ptr))
2415                 player_ptr->update |= (PU_MON_LITE);
2416         update_monster(player_ptr, g_ptr->m_idx, TRUE);
2417
2418         real_r_ptr(m_ptr)->cur_num++;
2419
2420         /*
2421          * Memorize location of the unique monster in saved floors.
2422          * A unique monster move from old saved floor.
2423          */
2424         if (current_world_ptr->character_dungeon &&
2425                 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)))
2426                 real_r_ptr(m_ptr)->floor_id = player_ptr->floor_id;
2427
2428         if (r_ptr->flags2 & RF2_MULTIPLY) floor_ptr->num_repro++;
2429
2430         if (player_ptr->warning && current_world_ptr->character_dungeon)
2431         {
2432                 if (r_ptr->flags1 & RF1_UNIQUE)
2433                 {
2434                         concptr color;
2435                         object_type *o_ptr;
2436                         GAME_TEXT o_name[MAX_NLEN];
2437
2438                         if (r_ptr->level > player_ptr->lev + 30)
2439                                 color = _("黒く", "black");
2440                         else if (r_ptr->level > player_ptr->lev + 15)
2441                                 color = _("紫色に", "purple");
2442                         else if (r_ptr->level > player_ptr->lev + 5)
2443                                 color = _("ルビー色に", "deep red");
2444                         else if (r_ptr->level > player_ptr->lev - 5)
2445                                 color = _("赤く", "red");
2446                         else if (r_ptr->level > player_ptr->lev - 15)
2447                                 color = _("ピンク色に", "pink");
2448                         else
2449                                 color = _("白く", "white");
2450
2451                         o_ptr = choose_warning_item(player_ptr);
2452                         if (o_ptr)
2453                         {
2454                                 object_desc(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
2455                                 msg_format(_("%sは%s光った。", "%s glows %s."), o_name, color);
2456                         }
2457                         else
2458                         {
2459                                 msg_format(_("%s光る物が頭に浮かんだ。", "An %s image forms in your mind."), color);
2460                         }
2461                 }
2462         }
2463
2464         if (!is_explosive_rune_grid(g_ptr)) return TRUE;
2465
2466         if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
2467         {
2468                 if (g_ptr->info & CAVE_MARK)
2469                 {
2470                         msg_print(_("ルーンが爆発した!", "The rune explodes!"));
2471                         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);
2472                 }
2473         }
2474         else
2475         {
2476                 msg_print(_("爆発のルーンは解除された。", "An explosive rune was disarmed."));
2477         }
2478
2479         g_ptr->info &= ~(CAVE_MARK);
2480         g_ptr->info &= ~(CAVE_OBJECT);
2481         g_ptr->mimic = 0;
2482
2483         note_spot(player_ptr, y, x);
2484         lite_spot(player_ptr, y, x);
2485
2486         return TRUE;
2487 }
2488
2489
2490 /*!
2491  * @brief モンスター1体を目標地点に可能な限り近い位置に生成する / improved version of scatter() for place monster
2492  * @param player_ptr プレーヤーへの参照ポインタ
2493  * @param r_idx 生成モンスター種族
2494  * @param yp 結果生成位置y座標
2495  * @param xp 結果生成位置x座標
2496  * @param y 中心生成位置y座標
2497  * @param x 中心生成位置x座標
2498  * @param max_dist 生成位置の最大半径
2499  * @return 成功したらtrue
2500  *
2501  */
2502 static bool mon_scatter(player_type *player_ptr, MONRACE_IDX r_idx, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION max_dist)
2503 {
2504         POSITION place_x[MON_SCAT_MAXD];
2505         POSITION place_y[MON_SCAT_MAXD];
2506         int num[MON_SCAT_MAXD];
2507
2508         if (max_dist >= MON_SCAT_MAXD)
2509                 return FALSE;
2510
2511         int i;
2512         for (i = 0; i < MON_SCAT_MAXD; i++)
2513                 num[i] = 0;
2514
2515         floor_type *floor_ptr = player_ptr->current_floor_ptr;
2516         for (POSITION nx = x - max_dist; nx <= x + max_dist; nx++)
2517         {
2518                 for (POSITION ny = y - max_dist; ny <= y + max_dist; ny++)
2519                 {
2520                         if (!in_bounds(floor_ptr, ny, nx)) continue;
2521                         if (!projectable(player_ptr, y, x, ny, nx)) continue;
2522                         if (r_idx > 0)
2523                         {
2524                                 monster_race *r_ptr = &r_info[r_idx];
2525                                 if (!monster_can_enter(player_ptr, ny, nx, r_ptr, 0))
2526                                         continue;
2527                         }
2528                         else
2529                         {
2530                                 if (!is_cave_empty_bold2(player_ptr, ny, nx)) continue;
2531                                 if (pattern_tile(floor_ptr, ny, nx)) continue;
2532                         }
2533
2534                         i = distance(y, x, ny, nx);
2535                         if (i > max_dist)
2536                                 continue;
2537
2538                         num[i]++;
2539                         if (one_in_(num[i]))
2540                         {
2541                                 place_x[i] = nx;
2542                                 place_y[i] = ny;
2543                         }
2544                 }
2545         }
2546
2547         i = 0;
2548         while (i < MON_SCAT_MAXD && 0 == num[i])
2549                 i++;
2550         if (i >= MON_SCAT_MAXD)
2551                 return FALSE;
2552
2553         *xp = place_x[i];
2554         *yp = place_y[i];
2555
2556         return TRUE;
2557 }
2558
2559
2560 /*!
2561  * @brief モンスターを目標地点に集団生成する / Attempt to place a "group" of monsters around the given location
2562  * @param who 召喚主のモンスター情報ID
2563  * @param y 中心生成位置y座標
2564  * @param x 中心生成位置x座標
2565  * @param r_idx 生成モンスター種族
2566  * @param mode 生成オプション
2567  * @return 成功したらtrue
2568  */
2569 static bool place_monster_group(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2570 {
2571         monster_race *r_ptr = &r_info[r_idx];
2572         int total = randint1(10);
2573
2574         floor_type *floor_ptr = player_ptr->current_floor_ptr;
2575         int extra = 0;
2576         if (r_ptr->level > floor_ptr->dun_level)
2577         {
2578                 extra = r_ptr->level - floor_ptr->dun_level;
2579                 extra = 0 - randint1(extra);
2580         }
2581         else if (r_ptr->level < floor_ptr->dun_level)
2582         {
2583                 extra = floor_ptr->dun_level - r_ptr->level;
2584                 extra = randint1(extra);
2585         }
2586
2587         if (extra > 9) extra = 9;
2588
2589         total += extra;
2590
2591         if (total < 1) total = 1;
2592         if (total > GROUP_MAX) total = GROUP_MAX;
2593
2594         int hack_n = 1;
2595         POSITION hack_x[GROUP_MAX];
2596         hack_x[0] = x;
2597         POSITION hack_y[GROUP_MAX];
2598         hack_y[0] = y;
2599
2600         for (int n = 0; (n < hack_n) && (hack_n < total); n++)
2601         {
2602                 POSITION hx = hack_x[n];
2603                 POSITION hy = hack_y[n];
2604                 for (int i = 0; (i < 8) && (hack_n < total); i++)
2605                 {
2606                         POSITION mx, my;
2607                         scatter(player_ptr, &my, &mx, hy, hx, 4, 0);
2608                         if (!is_cave_empty_bold2(player_ptr, my, mx)) continue;
2609
2610                         if (place_monster_one(player_ptr, who, my, mx, r_idx, mode))
2611                         {
2612                                 hack_y[hack_n] = my;
2613                                 hack_x[hack_n] = mx;
2614                                 hack_n++;
2615                         }
2616                 }
2617         }
2618
2619         return TRUE;
2620 }
2621
2622
2623 /*!
2624  * @var place_monster_idx
2625  * @brief 護衛対象となるモンスター種族IDを渡すグローバル変数 / Hack -- help pick an escort type
2626  * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_idxを除去し、関数引数化する
2627  */
2628 static MONSTER_IDX place_monster_idx = 0;
2629
2630 /*!
2631  * @var place_monster_m_idx
2632  * @brief 護衛対象となるモンスターIDを渡すグローバル変数 / Hack -- help pick an escort type
2633  * @todo 関数ポインタの都合を配慮しながら、グローバル変数place_monster_m_idxを除去し、関数引数化する
2634  */
2635 static MONSTER_IDX place_monster_m_idx = 0;
2636
2637 /*!
2638  * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
2639  * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
2640  * @brief モンスター種族が召喚主の護衛となれるかどうかをチェックする / Hack -- help pick an escort type
2641  * @param r_idx チェックするモンスター種族のID
2642  * @return 護衛にできるならばtrue
2643  */
2644 static bool place_monster_can_escort(MONRACE_IDX r_idx)
2645 {
2646         monster_race *r_ptr = &r_info[place_monster_idx];
2647         monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[place_monster_m_idx];
2648         monster_race *z_ptr = &r_info[r_idx];
2649
2650         if (mon_hook_dungeon(place_monster_idx) != mon_hook_dungeon(r_idx)) return FALSE;
2651         if (z_ptr->d_char != r_ptr->d_char) return FALSE;
2652         if (z_ptr->level > r_ptr->level) return FALSE;
2653         if (z_ptr->flags1 & RF1_UNIQUE) return FALSE;
2654         if (place_monster_idx == r_idx) return FALSE;
2655         if (monster_has_hostile_align(p_ptr, m_ptr, 0, 0, z_ptr)) return FALSE;
2656
2657         if (r_ptr->flags7 & RF7_FRIENDLY)
2658         {
2659                 if (monster_has_hostile_align(p_ptr, NULL, 1, -1, z_ptr)) return FALSE;
2660         }
2661
2662         if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON))
2663                 return FALSE;
2664
2665         return TRUE;
2666 }
2667
2668
2669 /*!
2670  * @brief 一般的なモンスター生成処理のサブルーチン / Attempt to place a monster of the given race at the given location
2671  * @param player_ptr プレーヤーへの参照ポインタ
2672  * @param who 召喚主のモンスター情報ID
2673  * @param y 生成地点y座標
2674  * @param x 生成地点x座標
2675  * @param r_idx 生成するモンスターの種族ID
2676  * @param mode 生成オプション
2677  * @return 生成に成功したらtrue
2678  * @details
2679  * Note that certain monsters are now marked as requiring "friends".
2680  * These monsters, if successfully placed, and if the "grp" parameter
2681  * is TRUE, will be surrounded by a "group" of identical monsters.
2682  *
2683  * Note that certain monsters are now marked as requiring an "escort",
2684  * which is a collection of monsters with similar "race" but lower level.
2685  *
2686  * Some monsters induce a fake "group" flag on their escorts.
2687  *
2688  * Note the "bizarre" use of non-recursion to prevent annoying output
2689  * when running a code profiler.
2690  *
2691  * Note the use of the new "monster allocation table" code to restrict
2692  * the "get_mon_num()" function to "legal" escort types.
2693  */
2694 bool place_monster_aux(player_type *player_ptr, MONSTER_IDX who, POSITION y, POSITION x, MONRACE_IDX r_idx, BIT_FLAGS mode)
2695 {
2696         monster_race *r_ptr = &r_info[r_idx];
2697
2698         if (!(mode & PM_NO_KAGE) && one_in_(333))
2699                 mode |= PM_KAGE;
2700
2701         if (!place_monster_one(player_ptr, who, y, x, r_idx, mode)) return FALSE;
2702         if (!(mode & PM_ALLOW_GROUP)) return TRUE;
2703
2704         place_monster_m_idx = hack_m_idx_ii;
2705
2706         /* Reinforcement */
2707         for (int i = 0; i < 6; i++)
2708         {
2709                 if (!r_ptr->reinforce_id[i]) break;
2710                 int n = damroll(r_ptr->reinforce_dd[i], r_ptr->reinforce_ds[i]);
2711                 for (int j = 0; j < n; j++)
2712                 {
2713                         POSITION nx, ny, d = 7;
2714                         scatter(player_ptr, &ny, &nx, y, x, d, 0);
2715                         (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, r_ptr->reinforce_id[i], mode);
2716                 }
2717         }
2718
2719         if (r_ptr->flags1 & (RF1_FRIENDS))
2720         {
2721                 (void)place_monster_group(player_ptr, who, y, x, r_idx, mode);
2722         }
2723
2724         if (!(r_ptr->flags1 & (RF1_ESCORT))) return TRUE;
2725
2726         place_monster_idx = r_idx;
2727         for (int i = 0; i < 32; i++)
2728         {
2729                 POSITION nx, ny, d = 3;
2730                 MONRACE_IDX z;
2731                 scatter(player_ptr, &ny, &nx, y, x, d, 0);
2732                 if (!is_cave_empty_bold2(player_ptr, ny, nx)) continue;
2733
2734                 get_mon_num_prep(player_ptr, place_monster_can_escort, get_monster_hook2(player_ptr, ny, nx));
2735                 z = get_mon_num(player_ptr, r_ptr->level, 0);
2736                 if (!z) break;
2737
2738                 (void)place_monster_one(player_ptr, place_monster_m_idx, ny, nx, z, mode);
2739                 if ((r_info[z].flags1 & RF1_FRIENDS) ||
2740                         (r_ptr->flags1 & RF1_ESCORTS))
2741                 {
2742                         (void)place_monster_group(player_ptr, place_monster_m_idx, ny, nx, z, mode);
2743                 }
2744         }
2745
2746         return TRUE;
2747 }
2748
2749
2750 /*!
2751  * @brief 一般的なモンスター生成処理のメインルーチン / Attempt to place a monster of the given race at the given location
2752  * @param player_ptr プレーヤーへの参照ポインタ
2753  * @param y 生成地点y座標
2754  * @param x 生成地点x座標
2755  * @param mode 生成オプション
2756  * @return 生成に成功したらtrue
2757  */
2758 bool place_monster(player_type *player_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
2759 {
2760         MONRACE_IDX r_idx;
2761         get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
2762         r_idx = get_mon_num(player_ptr, player_ptr->current_floor_ptr->monster_level, 0);
2763         if (!r_idx) return FALSE;
2764
2765         if ((one_in_(5) || (player_ptr->current_floor_ptr->base_level == 0)) &&
2766                 !(r_info[r_idx].flags1 & RF1_UNIQUE) && my_strchr("hkoptuyAHLOPTUVY", r_info[r_idx].d_char))
2767         {
2768                 mode |= PM_JURAL;
2769         }
2770
2771         if (place_monster_aux(player_ptr, 0, y, x, r_idx, mode)) return TRUE;
2772
2773         return FALSE;
2774 }
2775
2776
2777 /*!
2778  * @brief 指定地点に1種類のモンスター種族による群れを生成する
2779  * @param player_ptr プレーヤーへの参照ポインタ
2780  * @param y 生成地点y座標
2781  * @param x 生成地点x座標
2782  * @return 生成に成功したらtrue
2783  */
2784 bool alloc_horde(player_type *player_ptr, POSITION y, POSITION x)
2785 {
2786         get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), get_monster_hook2(player_ptr, y, x));
2787
2788         floor_type *floor_ptr = player_ptr->current_floor_ptr;
2789         MONRACE_IDX r_idx = 0;
2790         int attempts = 1000;
2791         monster_race *r_ptr = NULL;
2792         while (--attempts)
2793         {
2794                 r_idx = get_mon_num(player_ptr, floor_ptr->monster_level, 0);
2795                 if (!r_idx) return FALSE;
2796
2797                 r_ptr = &r_info[r_idx];
2798                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
2799
2800                 if (r_idx == MON_HAGURE) continue;
2801                 break;
2802         }
2803
2804         if (attempts < 1) return FALSE;
2805
2806         attempts = 1000;
2807
2808         while (--attempts)
2809         {
2810                 if (place_monster_aux(player_ptr, 0, y, x, r_idx, 0L)) break;
2811         }
2812
2813         if (attempts < 1) return FALSE;
2814
2815         MONSTER_IDX m_idx = floor_ptr->grid_array[y][x].m_idx;
2816         if (floor_ptr->m_list[m_idx].mflag2 & MFLAG2_CHAMELEON) r_ptr = &r_info[floor_ptr->m_list[m_idx].r_idx];
2817
2818         POSITION cy = y;
2819         POSITION cx = x;
2820         for (attempts = randint1(10) + 5; attempts; attempts--)
2821         {
2822                 scatter(player_ptr, &cy, &cx, y, x, 5, 0);
2823                 (void)summon_specific(player_ptr, m_idx, cy, cx, floor_ptr->dun_level + 5, SUMMON_KIN, PM_ALLOW_GROUP);
2824                 y = cy;
2825                 x = cx;
2826         }
2827
2828         if (cheat_hear) msg_format(_("モンスターの大群(%c)", "Monster horde (%c)."), r_ptr->d_char);
2829         return TRUE;
2830 }
2831
2832
2833 /*!
2834  * @brief ダンジョンの主生成を試みる / Put the Guardian
2835  * @param player_ptr プレーヤーへの参照ポインタ
2836  * @param def_val 現在の主の生成状態
2837  * @return 生成に成功したらtrue
2838  */
2839 bool alloc_guardian(player_type *player_ptr, bool def_val)
2840 {
2841         MONRACE_IDX guardian = d_info[player_ptr->dungeon_idx].final_guardian;
2842         floor_type *floor_ptr = player_ptr->current_floor_ptr;
2843         bool is_guardian_applicable = guardian > 0;
2844         is_guardian_applicable &= d_info[player_ptr->dungeon_idx].maxdepth == floor_ptr->dun_level;
2845         is_guardian_applicable &= r_info[guardian].cur_num < r_info[guardian].max_num;
2846         if (!is_guardian_applicable) return def_val;
2847
2848         int try_count = 4000;
2849         while (try_count)
2850         {
2851                 POSITION oy = randint1(floor_ptr->height - 4) + 2;
2852                 POSITION ox = randint1(floor_ptr->width - 4) + 2;
2853                 if (!is_cave_empty_bold2(player_ptr, oy, ox))
2854                 {
2855                         try_count++;
2856                         continue;
2857                 }
2858
2859                 if (!monster_can_cross_terrain(player_ptr, floor_ptr->grid_array[oy][ox].feat, &r_info[guardian], 0))
2860                 {
2861                         try_count++;
2862                         continue;
2863                 }
2864
2865                 if (place_monster_aux(player_ptr, 0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET)))
2866                         return TRUE;
2867
2868                 try_count--;
2869         }
2870
2871         return FALSE;
2872 }
2873
2874
2875 /*!
2876  * @brief ダンジョンの初期配置モンスターを生成1回生成する / Attempt to allocate a random monster in the dungeon.
2877  * @param dis プレイヤーから離れるべき最低距離
2878  * @param mode 生成オプション
2879  * @return 生成に成功したらtrue
2880  * @details
2881  * Place the monster at least "dis" distance from the player.
2882  * Use "slp" to choose the initial "sleep" status
2883  * Use "floor_ptr->monster_level" for the monster level
2884  */
2885 bool alloc_monster(player_type *player_ptr, POSITION dis, BIT_FLAGS mode)
2886 {
2887         if (alloc_guardian(player_ptr, FALSE)) return TRUE;
2888
2889         floor_type *floor_ptr = player_ptr->current_floor_ptr;
2890         POSITION y = 0, x = 0;
2891         int attempts_left = 10000;
2892         while (attempts_left--)
2893         {
2894                 y = randint0(floor_ptr->height);
2895                 x = randint0(floor_ptr->width);
2896
2897                 if (floor_ptr->dun_level)
2898                 {
2899                         if (!is_cave_empty_bold2(player_ptr, y, x)) continue;
2900                 }
2901                 else
2902                 {
2903                         if (!is_cave_empty_bold(player_ptr, y, x)) continue;
2904                 }
2905
2906                 if (distance(y, x, player_ptr->y, player_ptr->x) > dis) break;
2907         }
2908
2909         if (!attempts_left)
2910         {
2911                 if (cheat_xtra || cheat_hear)
2912                 {
2913                         msg_print(_("警告!新たなモンスターを配置できません。小さい階ですか?", "Warning! Could not allocate a new monster. Small level?"));
2914                 }
2915
2916                 return FALSE;
2917         }
2918
2919
2920         if (randint1(5000) <= floor_ptr->dun_level)
2921         {
2922                 if (alloc_horde(player_ptr, y, x))
2923                 {
2924                         return TRUE;
2925                 }
2926         }
2927         else
2928         {
2929                 if (place_monster(player_ptr, y, x, (mode | PM_ALLOW_GROUP))) return TRUE;
2930         }
2931
2932         return FALSE;
2933 }
2934
2935
2936 /*!
2937  * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
2938  * @brief モンスターが召喚の基本条件に合っているかをチェックする / Hack -- help decide if a monster race is "okay" to summon
2939  * @param r_idx チェックするモンスター種族ID
2940  * @return 召喚対象にできるならばTRUE
2941  */
2942 static bool summon_specific_okay(MONRACE_IDX r_idx)
2943 {
2944         monster_race *r_ptr = &r_info[r_idx];
2945         monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[summon_specific_who];
2946         if (!mon_hook_dungeon(r_idx)) return FALSE;
2947
2948         if (summon_specific_who > 0)
2949         {
2950                 if (monster_has_hostile_align(p_ptr, m_ptr, 0, 0, r_ptr)) return FALSE;
2951         }
2952         else if (summon_specific_who < 0)
2953         {
2954                 if (monster_has_hostile_align(p_ptr, NULL, 10, -10, r_ptr))
2955                 {
2956                         if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE;
2957                 }
2958         }
2959
2960         if (!summon_unique_okay && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))) return FALSE;
2961
2962         if (!summon_specific_type) return TRUE;
2963
2964         if ((summon_specific_who < 0) &&
2965                 ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
2966                 monster_has_hostile_align(p_ptr, NULL, 10, -10, r_ptr))
2967                 return FALSE;
2968
2969         if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON)) return TRUE;
2970
2971         return (summon_specific_aux(p_ptr, m_ptr->r_idx, r_idx));
2972 }
2973
2974
2975 /*!
2976  * @brief モンスターを召喚により配置する / Place a monster (of the specified "type") near the given location. Return TRUE if a monster was actually summoned.
2977  * @param player_ptr プレーヤーへの参照ポインタ
2978  * @param who 召喚主のモンスター情報ID
2979  * @param y1 目標地点y座標
2980  * @param x1 目標地点x座標
2981  * @param lev 相当生成階
2982  * @param type 召喚種別
2983  * @param mode 生成オプション
2984  * @return 召喚できたらtrueを返す
2985  * @details
2986  *
2987  * We will attempt to place the monster up to 10 times before giving up.
2988  *
2989  * Note: SUMMON_UNIQUE and SUMMON_AMBERITES will summon Unique's
2990  * Note: SUMMON_HI_UNDEAD and SUMMON_HI_DRAGON may summon Unique's
2991  * Note: None of the other summon codes will ever summon Unique's.
2992  *
2993  * This function has been changed.  We now take the "monster level"
2994  * of the summoning monster as a parameter, and use that, along with
2995  * the current dungeon level, to help determine the level of the
2996  * desired monster.  Note that this is an upper bound, and also
2997  * tends to "prefer" monsters of that level.  Currently, we use
2998  * the average of the dungeon and monster levels, and then add
2999  * five to allow slight increases in monster power.
3000  *
3001  * Note that we use the new "monster allocation table" creation code
3002  * to restrict the "get_mon_num()" function to the set of "legal"
3003  * monsters, making this function much faster and more reliable.
3004  *
3005  * Note that this function may not succeed, though this is very rare.
3006  */
3007 bool summon_specific(player_type *player_ptr, MONSTER_IDX who, POSITION y1, POSITION x1, DEPTH lev, int type, BIT_FLAGS mode)
3008 {
3009         floor_type *floor_ptr = player_ptr->current_floor_ptr;
3010         if (floor_ptr->inside_arena) return FALSE;
3011
3012         POSITION x, y;
3013         if (!mon_scatter(player_ptr, 0, &y, &x, y1, x1, 2)) return FALSE;
3014
3015         summon_specific_who = who;
3016         summon_specific_type = type;
3017         summon_unique_okay = (mode & PM_ALLOW_UNIQUE) ? TRUE : FALSE;
3018         get_mon_num_prep(player_ptr, summon_specific_okay, get_monster_hook2(player_ptr, y, x));
3019
3020         MONRACE_IDX r_idx = get_mon_num(player_ptr, (floor_ptr->dun_level + lev) / 2 + 5, 0);
3021         if (!r_idx)
3022         {
3023                 summon_specific_type = 0;
3024                 return FALSE;
3025         }
3026
3027         if ((type == SUMMON_BLUE_HORROR) || (type == SUMMON_DAWN)) mode |= PM_NO_KAGE;
3028
3029         if (!place_monster_aux(player_ptr, who, y, x, r_idx, mode))
3030         {
3031                 summon_specific_type = 0;
3032                 return FALSE;
3033         }
3034
3035         summon_specific_type = 0;
3036         sound(SOUND_SUMMON);
3037         return TRUE;
3038 }
3039
3040
3041 /*!
3042  * @brief 特定モンスター種族を召喚により生成する / A "dangerous" function, creates a pet of the specified type
3043  * @param player_ptr プレーヤーへの参照ポインタ
3044  * @param who 召喚主のモンスター情報ID
3045  * @param oy 目標地点y座標
3046  * @param ox 目標地点x座標
3047  * @param r_idx 生成するモンスター種族ID
3048  * @param mode 生成オプション
3049  * @return 召喚できたらtrueを返す
3050  */
3051 bool summon_named_creature(player_type *player_ptr, MONSTER_IDX who, POSITION oy, POSITION ox, MONRACE_IDX r_idx, BIT_FLAGS mode)
3052 {
3053         if (r_idx >= max_r_idx) return FALSE;
3054
3055         POSITION x, y;
3056         if (player_ptr->current_floor_ptr->inside_arena) return FALSE;
3057
3058         if (!mon_scatter(player_ptr, r_idx, &y, &x, oy, ox, 2)) return FALSE;
3059
3060         return place_monster_aux(player_ptr, who, y, x, r_idx, (mode | PM_NO_KAGE));
3061 }
3062
3063
3064 /*!
3065  * @brief モンスターを増殖生成する / Let the given monster attempt to reproduce.
3066  * @param player_ptr プレーヤーへの参照ポインタ
3067  * @param m_idx 増殖するモンスター情報ID
3068  * @param clone クローン・モンスター処理ならばtrue
3069  * @param mode 生成オプション
3070  * @return 生成できたらtrueを返す
3071  * @details
3072  * Note that "reproduction" REQUIRES empty space.
3073  */
3074 bool multiply_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool clone, BIT_FLAGS mode)
3075 {
3076         floor_type *floor_ptr = player_ptr->current_floor_ptr;
3077         monster_type *m_ptr = &floor_ptr->m_list[m_idx];
3078         POSITION y, x;
3079         if (!mon_scatter(player_ptr, m_ptr->r_idx, &y, &x, m_ptr->fy, m_ptr->fx, 1))
3080                 return FALSE;
3081
3082         if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
3083
3084         if (!place_monster_aux(player_ptr, m_idx, y, x, m_ptr->r_idx, (mode | PM_NO_KAGE | PM_MULTIPLY)))
3085                 return FALSE;
3086
3087         if (clone || (m_ptr->smart & SM_CLONED))
3088         {
3089                 floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3090                 floor_ptr->m_list[hack_m_idx_ii].mflag2 |= MFLAG2_NOPET;
3091         }
3092
3093         return TRUE;
3094 }
3095
3096
3097 /*!
3098  * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
3099  * @param player_ptr プレーヤーへの参照ポインタ
3100  * @param m_idx モンスター情報ID
3101  * @param dam 与えたダメージ
3102  * @return なし
3103  * @details
3104  * Technically should attempt to treat "Beholder"'s as jelly's
3105  */
3106 void message_pain(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam)
3107 {
3108         monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
3109         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3110
3111         GAME_TEXT m_name[MAX_NLEN];
3112
3113         monster_desc(player_ptr, m_name, m_ptr, 0);
3114
3115         if (dam == 0)
3116         {
3117                 msg_format(_("%^sはダメージを受けていない。", "%^s is unharmed."), m_name);
3118                 return;
3119         }
3120
3121         HIT_POINT newhp = m_ptr->hp;
3122         HIT_POINT oldhp = newhp + dam;
3123         HIT_POINT tmp = (newhp * 100L) / oldhp;
3124         PERCENTAGE percentage = tmp;
3125
3126         if (my_strchr(",ejmvwQ", r_ptr->d_char))
3127         {
3128 #ifdef JP
3129                 if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3130                 else if (percentage > 75) msg_format("%^sはしり込みした。", m_name);
3131                 else if (percentage > 50) msg_format("%^sは縮こまった。", m_name);
3132                 else if (percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3133                 else if (percentage > 20) msg_format("%^sは身もだえした。", m_name);
3134                 else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3135                 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3136                 return;
3137 #else
3138                 if (percentage > 95) msg_format("%^s barely notices.", m_name);
3139                 else if (percentage > 75) msg_format("%^s flinches.", m_name);
3140                 else if (percentage > 50) msg_format("%^s squelches.", m_name);
3141                 else if (percentage > 35) msg_format("%^s quivers in pain.", m_name);
3142                 else if (percentage > 20) msg_format("%^s writhes about.", m_name);
3143                 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3144                 else msg_format("%^s jerks limply.", m_name);
3145                 return;
3146 #endif
3147         }
3148
3149         if (my_strchr("l", r_ptr->d_char))
3150         {
3151 #ifdef JP
3152                 if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3153                 else if (percentage > 75) msg_format("%^sはしり込みした。", m_name);
3154                 else if (percentage > 50) msg_format("%^sは躊躇した。", m_name);
3155                 else if (percentage > 35) msg_format("%^sは痛みに震えた。", m_name);
3156                 else if (percentage > 20) msg_format("%^sは身もだえした。", m_name);
3157                 else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3158                 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3159                 return;
3160 #else
3161                 if (percentage > 95) msg_format("%^s barely notices.", m_name);
3162                 else if (percentage > 75) msg_format("%^s flinches.", m_name);
3163                 else if (percentage > 50) msg_format("%^s hesitates.", m_name);
3164                 else if (percentage > 35) msg_format("%^s quivers in pain.", m_name);
3165                 else if (percentage > 20) msg_format("%^s writhes about.", m_name);
3166                 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3167                 else msg_format("%^s jerks limply.", m_name);
3168                 return;
3169 #endif          
3170         }
3171
3172         if (my_strchr("g#+<>", r_ptr->d_char))
3173         {
3174 #ifdef JP
3175                 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3176                 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3177                 else if (percentage > 50) msg_format("%^sは雷鳴のように吠えた。", m_name);
3178                 else if (percentage > 35) msg_format("%^sは苦しげに吠えた。", m_name);
3179                 else if (percentage > 20) msg_format("%^sはうめいた。", m_name);
3180                 else if (percentage > 10) msg_format("%^sは躊躇した。", m_name);
3181                 else msg_format("%^sはくしゃくしゃになった。", m_name);
3182                 return;
3183 #else
3184                 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3185                 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3186                 else if (percentage > 50) msg_format("%^s roars thunderously.", m_name);
3187                 else if (percentage > 35) msg_format("%^s rumbles.", m_name);
3188                 else if (percentage > 20) msg_format("%^s grunts.", m_name);
3189                 else if (percentage > 10) msg_format("%^s hesitates.", m_name);
3190                 else msg_format("%^s crumples.", m_name);
3191                 return;
3192 #endif
3193         }
3194
3195         if (my_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char))
3196         {
3197 #ifdef JP
3198                 if (percentage > 95) msg_format("%^sはほとんど気にとめていない。", m_name);
3199                 else if (percentage > 75) msg_format("%^sはシーッと鳴いた。", m_name);
3200                 else if (percentage > 50) msg_format("%^sは怒って頭を上げた。", m_name);
3201                 else if (percentage > 35) msg_format("%^sは猛然と威嚇した。", m_name);
3202                 else if (percentage > 20) msg_format("%^sは身もだえした。", m_name);
3203                 else if (percentage > 10) msg_format("%^sは苦痛で身もだえした。", m_name);
3204                 else msg_format("%^sはぐにゃぐにゃと痙攣した。", m_name);
3205                 return;
3206 #else
3207                 if (percentage > 95) msg_format("%^s barely notices.", m_name);
3208                 else if (percentage > 75) msg_format("%^s hisses.", m_name);
3209                 else if (percentage > 50) msg_format("%^s rears up in anger.", m_name);
3210                 else if (percentage > 35) msg_format("%^s hisses furiously.", m_name);
3211                 else if (percentage > 20) msg_format("%^s writhes about.", m_name);
3212                 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3213                 else msg_format("%^s jerks limply.", m_name);
3214                 return;
3215 #endif
3216         }
3217
3218         if (my_strchr("f", r_ptr->d_char))
3219         {
3220 #ifdef JP
3221                 if (percentage > 95) msg_format("%sは攻撃に肩をすくめた。", m_name);
3222                 else if (percentage > 75) msg_format("%^sは吠えた。", m_name);
3223                 else if (percentage > 50) msg_format("%^sは怒って吠えた。", m_name);
3224                 else if (percentage > 35) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3225                 else if (percentage > 20) msg_format("%^sは痛みで弱々しく鳴いた。", m_name);
3226                 else if (percentage > 10) msg_format("%^sは苦痛にうめいた。", m_name);
3227                 else msg_format("%sは哀れな鳴き声を出した。", m_name);
3228                 return;
3229 #else
3230                 if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3231                 else if (percentage > 75) msg_format("%^s roars.", m_name);
3232                 else if (percentage > 50) msg_format("%^s growls angrily.", m_name);
3233                 else if (percentage > 35) msg_format("%^s hisses with pain.", m_name);
3234                 else if (percentage > 20) msg_format("%^s mewls in pain.", m_name);
3235                 else if (percentage > 10) msg_format("%^s hisses in agony.", m_name);
3236                 else msg_format("%^s mewls pitifully.", m_name);
3237                 return;
3238 #endif
3239         }
3240
3241         if (my_strchr("acFIKS", r_ptr->d_char))
3242         {
3243 #ifdef JP
3244                 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3245                 else if (percentage > 75) msg_format("%^sはキーキー鳴いた。", m_name);
3246                 else if (percentage > 50) msg_format("%^sはヨロヨロ逃げ回った。", m_name);
3247                 else if (percentage > 35) msg_format("%^sはうるさく鳴いた。", m_name);
3248                 else if (percentage > 20) msg_format("%^sは痛みに痙攣した。", m_name);
3249                 else if (percentage > 10) msg_format("%^sは苦痛で痙攣した。", m_name);
3250                 else msg_format("%^sはピクピクひきつった。", m_name);
3251                 return;
3252 #else
3253                 if (percentage > 95)    msg_format("%^s ignores the attack.", m_name);
3254                 else if (percentage > 75) msg_format("%^s chitters.", m_name);
3255                 else if (percentage > 50) msg_format("%^s scuttles about.", m_name);
3256                 else if (percentage > 35) msg_format("%^s twitters.", m_name);
3257                 else if (percentage > 20) msg_format("%^s jerks in pain.", m_name);
3258                 else if (percentage > 10) msg_format("%^s jerks in agony.", m_name);
3259                 else msg_format("%^s twitches.", m_name);
3260                 return;
3261 #endif
3262         }
3263
3264         if (my_strchr("B", r_ptr->d_char))
3265         {
3266 #ifdef JP
3267                 if (percentage > 95) msg_format("%^sはさえずった。", m_name);
3268                 else if (percentage > 75) msg_format("%^sはピーピー鳴いた。", m_name);
3269                 else if (percentage > 50) msg_format("%^sはギャーギャー鳴いた。", m_name);
3270                 else if (percentage > 35) msg_format("%^sはギャーギャー鳴きわめいた。", m_name);
3271                 else if (percentage > 20) msg_format("%^sは苦しんだ。", m_name);
3272                 else if (percentage > 10) msg_format("%^sはのたうち回った。", m_name);
3273                 else msg_format("%^sはキーキーと鳴き叫んだ。", m_name);
3274                 return;
3275 #else
3276                 if (percentage > 95)    msg_format("%^s chirps.", m_name);
3277                 else if (percentage > 75) msg_format("%^s twitters.", m_name);
3278                 else if (percentage > 50) msg_format("%^s squawks.", m_name);
3279                 else if (percentage > 35) msg_format("%^s chatters.", m_name);
3280                 else if (percentage > 20) msg_format("%^s jeers.", m_name);
3281                 else if (percentage > 10) msg_format("%^s flutters about.", m_name);
3282                 else msg_format("%^s squeaks.", m_name);
3283                 return;
3284 #endif
3285         }
3286
3287         if (my_strchr("duDLUW", r_ptr->d_char))
3288         {
3289 #ifdef JP
3290                 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3291                 else if (percentage > 75) msg_format("%^sはしり込みした。", m_name);
3292                 else if (percentage > 50) msg_format("%^sは痛みでシーッと鳴いた。", m_name);
3293                 else if (percentage > 35) msg_format("%^sは痛みでうなった。", m_name);
3294                 else if (percentage > 20) msg_format("%^sは痛みに吠えた。", m_name);
3295                 else if (percentage > 10) msg_format("%^sは苦しげに叫んだ。", m_name);
3296                 else msg_format("%^sは弱々しくうなった。", m_name);
3297                 return;
3298 #else
3299                 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3300                 else if (percentage > 75) msg_format("%^s flinches.", m_name);
3301                 else if (percentage > 50) msg_format("%^s hisses in pain.", m_name);
3302                 else if (percentage > 35) msg_format("%^s snarls with pain.", m_name);
3303                 else if (percentage > 20) msg_format("%^s roars with pain.", m_name);
3304                 else if (percentage > 10) msg_format("%^s gasps.", m_name);
3305                 else msg_format("%^s snarls feebly.", m_name);
3306                 return;
3307 #endif
3308         }
3309
3310         if (my_strchr("s", r_ptr->d_char))
3311         {
3312 #ifdef JP
3313                 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3314                 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3315                 else if (percentage > 50) msg_format("%^sはカタカタと笑った。", m_name);
3316                 else if (percentage > 35) msg_format("%^sはよろめいた。", m_name);
3317                 else if (percentage > 20) msg_format("%^sはカタカタ言った。", m_name);
3318                 else if (percentage > 10) msg_format("%^sはよろめいた。", m_name);
3319                 else msg_format("%^sはガタガタ言った。", m_name);
3320                 return;
3321 #else
3322                 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3323                 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3324                 else if (percentage > 50) msg_format("%^s rattles.", m_name);
3325                 else if (percentage > 35) msg_format("%^s stumbles.", m_name);
3326                 else if (percentage > 20) msg_format("%^s rattles.", m_name);
3327                 else if (percentage > 10) msg_format("%^s staggers.", m_name);
3328                 else msg_format("%^s clatters.", m_name);
3329                 return;
3330 #endif
3331         }
3332
3333         if (my_strchr("z", r_ptr->d_char))
3334         {
3335 #ifdef JP
3336                 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3337                 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3338                 else if (percentage > 50) msg_format("%^sはうめいた。", m_name);
3339                 else if (percentage > 35) msg_format("%sは苦しげにうめいた。", m_name);
3340                 else if (percentage > 20) msg_format("%^sは躊躇した。", m_name);
3341                 else if (percentage > 10) msg_format("%^sはうなった。", m_name);
3342                 else msg_format("%^sはよろめいた。", m_name);
3343                 return;
3344 #else
3345                 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3346                 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3347                 else if (percentage > 50) msg_format("%^s groans.", m_name);
3348                 else if (percentage > 35) msg_format("%^s moans.", m_name);
3349                 else if (percentage > 20) msg_format("%^s hesitates.", m_name);
3350                 else if (percentage > 10) msg_format("%^s grunts.", m_name);
3351                 else msg_format("%^s staggers.", m_name);
3352                 return;
3353 #endif
3354         }
3355
3356         if (my_strchr("G", r_ptr->d_char))
3357         {
3358 #ifdef JP
3359                 if (percentage > 95) msg_format("%sは攻撃を気にとめていない。", m_name);
3360                 else if (percentage > 75) msg_format("%sは攻撃に肩をすくめた。", m_name);
3361                 else if (percentage > 50) msg_format("%sはうめいた。", m_name);
3362                 else if (percentage > 35) msg_format("%^sは泣きわめいた。", m_name);
3363                 else if (percentage > 20) msg_format("%^sは吠えた。", m_name);
3364                 else if (percentage > 10) msg_format("%sは弱々しくうめいた。", m_name);
3365                 else msg_format("%^sはかすかにうめいた。", m_name);
3366                 return;
3367 #else
3368                 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3369                 else if (percentage > 75) msg_format("%^s shrugs off the attack.", m_name);
3370                 else if (percentage > 50)  msg_format("%^s moans.", m_name);
3371                 else if (percentage > 35) msg_format("%^s wails.", m_name);
3372                 else if (percentage > 20) msg_format("%^s howls.", m_name);
3373                 else if (percentage > 10) msg_format("%^s moans softly.", m_name);
3374                 else msg_format("%^s sighs.", m_name);
3375                 return;
3376 #endif
3377         }
3378
3379         if (my_strchr("CZ", r_ptr->d_char))
3380         {
3381 #ifdef JP
3382                 if (percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3383                 else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3384                 else if (percentage > 50) msg_format("%^sは痛みでキャンキャン吠えた。", m_name);
3385                 else if (percentage > 35) msg_format("%^sは痛みで鳴きわめいた。", m_name);
3386                 else if (percentage > 20) msg_format("%^sは苦痛のあまり鳴きわめいた。", m_name);
3387                 else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3388                 else msg_format("%^sは弱々しく吠えた。", m_name);
3389                 return;
3390 #else
3391                 if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3392                 else if (percentage > 75) msg_format("%^s snarls with pain.", m_name);
3393                 else if (percentage > 50) msg_format("%^s yelps in pain.", m_name);
3394                 else if (percentage > 35) msg_format("%^s howls in pain.", m_name);
3395                 else if (percentage > 20) msg_format("%^s howls in agony.", m_name);
3396                 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3397                 else msg_format("%^s yelps feebly.", m_name);
3398                 return;
3399 #endif
3400         }
3401
3402         if (my_strchr("Xbilqrt", r_ptr->d_char))
3403         {
3404 #ifdef JP
3405                 if (percentage > 95) msg_format("%^sは攻撃を気にとめていない。", m_name);
3406                 else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3407                 else if (percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3408                 else if (percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3409                 else if (percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3410                 else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3411                 else msg_format("%^sは弱々しく叫んだ。", m_name);
3412                 return;
3413 #else
3414                 if (percentage > 95) msg_format("%^s ignores the attack.", m_name);
3415                 else if (percentage > 75) msg_format("%^s grunts with pain.", m_name);
3416                 else if (percentage > 50) msg_format("%^s squeals in pain.", m_name);
3417                 else if (percentage > 35) msg_format("%^s shrieks in pain.", m_name);
3418                 else if (percentage > 20) msg_format("%^s shrieks in agony.", m_name);
3419                 else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3420                 else msg_format("%^s cries out feebly.", m_name);
3421                 return;
3422 #endif
3423         }
3424
3425 #ifdef JP
3426         if (percentage > 95) msg_format("%^sは攻撃に肩をすくめた。", m_name);
3427         else if (percentage > 75) msg_format("%^sは痛みでうなった。", m_name);
3428         else if (percentage > 50) msg_format("%^sは痛みで叫んだ。", m_name);
3429         else if (percentage > 35) msg_format("%^sは痛みで絶叫した。", m_name);
3430         else if (percentage > 20) msg_format("%^sは苦痛のあまり絶叫した。", m_name);
3431         else if (percentage > 10) msg_format("%^sは苦痛でもだえ苦しんだ。", m_name);
3432         else msg_format("%^sは弱々しく叫んだ。", m_name);
3433 #else
3434         if (percentage > 95) msg_format("%^s shrugs off the attack.", m_name);
3435         else if (percentage > 75) msg_format("%^s grunts with pain.", m_name);
3436         else if (percentage > 50) msg_format("%^s cries out in pain.", m_name);
3437         else if (percentage > 35) msg_format("%^s screams in pain.", m_name);
3438         else if (percentage > 20) msg_format("%^s screams in agony.", m_name);
3439         else if (percentage > 10) msg_format("%^s writhes in agony.", m_name);
3440         else msg_format("%^s cries out feebly.", m_name);
3441 #endif
3442 }
3443
3444
3445 /*!
3446  * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance.
3447  * @param m_idx 更新を行う「モンスター情報ID
3448  * @param what 学習対象ID
3449  * @return なし
3450  */
3451 void update_smart_learn(player_type *player_ptr, MONSTER_IDX m_idx, int what)
3452 {
3453         monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
3454         monster_race *r_ptr = &r_info[m_ptr->r_idx];
3455
3456         if (!smart_learn) return;
3457         if (r_ptr->flags2 & (RF2_STUPID)) return;
3458         if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) return;
3459
3460         switch (what)
3461         {
3462         case DRS_ACID:
3463                 if (player_ptr->resist_acid) m_ptr->smart |= (SM_RES_ACID);
3464                 if (is_oppose_acid(player_ptr)) m_ptr->smart |= (SM_OPP_ACID);
3465                 if (player_ptr->immune_acid) m_ptr->smart |= (SM_IMM_ACID);
3466                 break;
3467
3468         case DRS_ELEC:
3469                 if (player_ptr->resist_elec) m_ptr->smart |= (SM_RES_ELEC);
3470                 if (is_oppose_elec(player_ptr)) m_ptr->smart |= (SM_OPP_ELEC);
3471                 if (player_ptr->immune_elec) m_ptr->smart |= (SM_IMM_ELEC);
3472                 break;
3473
3474         case DRS_FIRE:
3475                 if (player_ptr->resist_fire) m_ptr->smart |= (SM_RES_FIRE);
3476                 if (is_oppose_fire(player_ptr)) m_ptr->smart |= (SM_OPP_FIRE);
3477                 if (player_ptr->immune_fire) m_ptr->smart |= (SM_IMM_FIRE);
3478                 break;
3479
3480         case DRS_COLD:
3481                 if (player_ptr->resist_cold) m_ptr->smart |= (SM_RES_COLD);
3482                 if (is_oppose_cold(player_ptr)) m_ptr->smart |= (SM_OPP_COLD);
3483                 if (player_ptr->immune_cold) m_ptr->smart |= (SM_IMM_COLD);
3484                 break;
3485
3486         case DRS_POIS:
3487                 if (player_ptr->resist_pois) m_ptr->smart |= (SM_RES_POIS);
3488                 if (is_oppose_pois(player_ptr)) m_ptr->smart |= (SM_OPP_POIS);
3489                 break;
3490
3491
3492         case DRS_NETH:
3493                 if (player_ptr->resist_neth) m_ptr->smart |= (SM_RES_NETH);
3494                 break;
3495
3496         case DRS_LITE:
3497                 if (player_ptr->resist_lite) m_ptr->smart |= (SM_RES_LITE);
3498                 break;
3499
3500         case DRS_DARK:
3501                 if (player_ptr->resist_dark) m_ptr->smart |= (SM_RES_DARK);
3502                 break;
3503
3504         case DRS_FEAR:
3505                 if (player_ptr->resist_fear) m_ptr->smart |= (SM_RES_FEAR);
3506                 break;
3507
3508         case DRS_CONF:
3509                 if (player_ptr->resist_conf) m_ptr->smart |= (SM_RES_CONF);
3510                 break;
3511
3512         case DRS_CHAOS:
3513                 if (player_ptr->resist_chaos) m_ptr->smart |= (SM_RES_CHAOS);
3514                 break;
3515
3516         case DRS_DISEN:
3517                 if (player_ptr->resist_disen) m_ptr->smart |= (SM_RES_DISEN);
3518                 break;
3519
3520         case DRS_BLIND:
3521                 if (player_ptr->resist_blind) m_ptr->smart |= (SM_RES_BLIND);
3522                 break;
3523
3524         case DRS_NEXUS:
3525                 if (player_ptr->resist_nexus) m_ptr->smart |= (SM_RES_NEXUS);
3526                 break;
3527
3528         case DRS_SOUND:
3529                 if (player_ptr->resist_sound) m_ptr->smart |= (SM_RES_SOUND);
3530                 break;
3531
3532         case DRS_SHARD:
3533                 if (player_ptr->resist_shard) m_ptr->smart |= (SM_RES_SHARD);
3534                 break;
3535
3536         case DRS_FREE:
3537                 if (player_ptr->free_act) m_ptr->smart |= (SM_IMM_FREE);
3538                 break;
3539
3540         case DRS_MANA:
3541                 if (!player_ptr->msp) m_ptr->smart |= (SM_IMM_MANA);
3542                 break;
3543
3544         case DRS_REFLECT:
3545                 if (player_ptr->reflect) m_ptr->smart |= (SM_IMM_REFLECT);
3546                 break;
3547         }
3548 }
3549
3550
3551 /*!
3552  * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster
3553  * @param player_ptr プレーヤーへの参照ポインタ
3554  * @param m_ptr モンスター参照ポインタ
3555  * @return なし
3556  */
3557 void monster_drop_carried_objects(player_type *player_ptr, monster_type *m_ptr)
3558 {
3559         floor_type *floor_ptr = player_ptr->current_floor_ptr;
3560         OBJECT_IDX next_o_idx = 0;
3561         for (OBJECT_IDX this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
3562         {
3563                 object_type forge;
3564                 object_type *o_ptr;
3565                 object_type *q_ptr;
3566                 o_ptr = &floor_ptr->o_list[this_o_idx];
3567                 next_o_idx = o_ptr->next_o_idx;
3568                 q_ptr = &forge;
3569
3570                 object_copy(q_ptr, o_ptr);
3571                 q_ptr->held_m_idx = 0;
3572                 delete_object_idx(player_ptr, this_o_idx);
3573                 (void)drop_near(player_ptr, q_ptr, -1, m_ptr->fy, m_ptr->fx);
3574         }
3575
3576         m_ptr->hold_o_idx = 0;
3577 }
3578
3579
3580 /*!
3581  * todo ここには本来floor_type*を追加したいが、monster.hにfloor.hの参照を追加するとコンパイルエラーが出るので保留
3582  * @brief 指定したモンスターに隣接しているモンスターの数を返す。
3583  * / Count number of adjacent monsters
3584  * @param player_ptr プレーヤーへの参照ポインタ
3585  * @param m_idx 隣接数を調べたいモンスターのID
3586  * @return 隣接しているモンスターの数
3587  */
3588 int get_monster_crowd_number(player_type *player_ptr, MONSTER_IDX m_idx)
3589 {
3590         floor_type *floor_ptr = player_ptr->current_floor_ptr;
3591         monster_type *m_ptr = &floor_ptr->m_list[m_idx];
3592         POSITION my = m_ptr->fy;
3593         POSITION mx = m_ptr->fx;
3594         int count = 0;
3595         for (int i = 0; i < 7; i++)
3596         {
3597                 int ay = my + ddy_ddd[i];
3598                 int ax = mx + ddx_ddd[i];
3599
3600                 if (!in_bounds(floor_ptr, ay, ax)) continue;
3601                 if (floor_ptr->grid_array[ay][ax].m_idx > 0) count++;
3602         }
3603
3604         return count;
3605 }
3606
3607
3608 bool is_friendly_idx(player_type *player_ptr, MONSTER_IDX m_idx)
3609 {
3610         return m_idx > 0 && is_friendly(&player_ptr->current_floor_ptr->m_list[(m_idx)]);
3611 }