OSDN Git Service

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