OSDN Git Service

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