OSDN Git Service

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