OSDN Git Service

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