OSDN Git Service

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