OSDN Git Service

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