OSDN Git Service

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