OSDN Git Service

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