OSDN Git Service

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