OSDN Git Service

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