OSDN Git Service

[Refactor] #40014 Separated monster-generator.c/h
[hengband/hengband.git] / src / monster / monster-processor.c
1 /*!
2  * @file monster-process.c
3  * @brief モンスターの特殊技能とターン経過処理 (移動等)/ Monster spells and movement for passaging a turn
4  * @date 2014/01/17
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7  * This software may be copied and distributed for educational, research,\n
8  * and not for profit purposes provided that this copyright and statement\n
9  * are included in all such copies.  Other copyrights may also apply.\n
10  * 2014 Deskull rearranged comment for Doxygen.\n
11  * @details
12  * This file has several additions to it by Keldon Jones (keldon@umr.edu)
13  * to improve the general quality of the AI (version 0.1.1).
14  */
15
16 #include "monster/monster-processor.h"
17 #include "cmd-io/cmd-dump.h"
18 #include "core/speed-table.h"
19 #include "grid/feature.h"
20 #include "grid/grid.h"
21 #include "io/write-diary.h"
22 #include "melee/melee-postprocess.h"
23 #include "monster-race/race-flags-ability2.h"
24 #include "monster-race/race-flags-resistance.h"
25 #include "monster-race/race-flags1.h"
26 #include "monster-race/race-flags2.h"
27 #include "monster-race/race-flags7.h"
28 #include "monster-race/race-indice-types.h"
29 #include "monster/monster-describer.h"
30 #include "monster/monster-description-types.h"
31 #include "monster/monster-direction.h"
32 #include "monster/monster-flag-types.h"
33 #include "monster/monster-generator.h"
34 #include "monster/monster-info.h"
35 #include "monster/monster-move.h"
36 #include "monster/monster-processor-util.h"
37 #include "monster/monster-runaway.h"
38 #include "monster/monster-status.h"
39 #include "monster/monster-update.h"
40 #include "monster/monster-util.h"
41 #include "monster/monster2.h"
42 #include "monster/place-monster-types.h"
43 #include "monster/quantum-effect.h"
44 #include "mspell/monster-spell.h"
45 #include "object-enchant/trc-types.h"
46 #include "pet/pet-fall-off.h"
47 #include "player/avatar.h"
48 #include "player/player-move.h"
49 #include "spell-realm/spells-hex.h"
50 #include "spell/spells-summon.h"
51 #include "util/util.h"
52
53 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon);
54 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx);
55 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
56 bool awake_monster(player_type *target_ptr, MONSTER_IDX m_idx);
57 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m);
58 bool explode_grenade(player_type *target_ptr, MONSTER_IDX m_idx);
59 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox);
60 void process_special(player_type *target_ptr, MONSTER_IDX m_idx);
61 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware);
62
63 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx);
64
65 void sweep_monster_process(player_type *target_ptr);
66 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr);
67
68 /*!
69  * @brief モンスター単体の1ターン行動処理メインルーチン /
70  * Process a monster
71  * @param target_ptr プレーヤーへの参照ポインタ
72  * @param m_idx 行動モンスターの参照ID
73  * @return なし
74  * @details
75  * The monster is known to be within 100 grids of the player\n
76  *\n
77  * In several cases, we directly update the monster lore\n
78  *\n
79  * Note that a monster is only allowed to "reproduce" if there\n
80  * are a limited number of "reproducing" monsters on the current\n
81  * level.  This should prevent the level from being "swamped" by\n
82  * reproducing monsters.  It also allows a large mass of mice to\n
83  * prevent a louse from multiplying, but this is a small price to\n
84  * pay for a simple multiplication method.\n
85  *\n
86  * XXX Monster fear is slightly odd, in particular, monsters will\n
87  * fixate on opening a door even if they cannot open it.  Actually,\n
88  * the same thing happens to normal monsters when they hit a door\n
89  *\n
90  * In addition, monsters which *cannot* open or bash\n
91  * down a door will still stand there trying to open it...\n
92  *\n
93  * XXX Technically, need to check for monster in the way\n
94  * combined with that monster being in a wall (or door?)\n
95  *\n
96  * A "direction" of "5" means "pick a random direction".\n
97  */
98 void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
99 {
100         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
101         monster_race *r_ptr = &r_info[m_ptr->r_idx];
102         turn_flags tmp_flags;
103         turn_flags *turn_flags_ptr = init_turn_flags(target_ptr->riding, m_idx, &tmp_flags);
104         turn_flags_ptr->see_m = is_seen(m_ptr);
105
106         decide_drop_from_monster(target_ptr, m_idx, turn_flags_ptr->is_riding_mon);
107         if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !monster_csleep_remaining(m_ptr))
108         {
109                 choose_new_monster(target_ptr, m_idx, FALSE, 0);
110                 r_ptr = &r_info[m_ptr->r_idx];
111         }
112
113         turn_flags_ptr->aware = process_stealth(target_ptr, m_idx);
114         if (vanish_summoned_children(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
115         if (process_quantum_effect(target_ptr, m_idx, turn_flags_ptr->see_m)) return;
116         if (explode_grenade(target_ptr, m_idx)) return;
117         if (runaway_monster(target_ptr, turn_flags_ptr, m_idx)) return;
118         if (!awake_monster(target_ptr, m_idx)) return;
119
120         if (monster_stunned_remaining(m_ptr))
121         {
122                 if (one_in_(2)) return;
123         }
124
125         if (turn_flags_ptr->is_riding_mon)
126         {
127                 target_ptr->update |= (PU_BONUS);
128         }
129
130         process_angar(target_ptr, m_idx, turn_flags_ptr->see_m);
131
132         POSITION oy = m_ptr->fy;
133         POSITION ox = m_ptr->fx;
134         if (decide_monster_multiplication(target_ptr, m_idx, oy, ox)) return;
135
136         process_special(target_ptr, m_idx);
137         process_speak_sound(target_ptr, m_idx, oy, ox, turn_flags_ptr->aware);
138         if (cast_spell(target_ptr, m_idx, turn_flags_ptr->aware)) return;
139
140         DIRECTION mm[8];
141         mm[0] = mm[1] = mm[2] = mm[3] = 0;
142         mm[4] = mm[5] = mm[6] = mm[7] = 0;
143
144         if (!decide_monster_movement_direction(target_ptr, mm, m_idx, turn_flags_ptr->aware)) return;
145
146         int count = 0;
147         if (!process_monster_movement(target_ptr, turn_flags_ptr, m_idx, mm, oy, ox, &count)) return;
148
149         /*
150          *  Forward movements failed, but now received LOS attack!
151          *  Try to flow by smell.
152          */
153         if (target_ptr->no_flowed && count > 2 && m_ptr->target_y)
154                 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
155
156         if (!turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && !monster_fear_remaining(m_ptr) && !turn_flags_ptr->is_riding_mon && turn_flags_ptr->aware)
157         {
158                 if (r_ptr->freq_spell && randint1(100) <= r_ptr->freq_spell)
159                 {
160                         if (make_attack_spell(m_idx, target_ptr)) return;
161                 }
162         }
163
164         update_player_type(target_ptr, turn_flags_ptr, r_ptr);
165         update_monster_race_flags(target_ptr, turn_flags_ptr, m_ptr);
166
167         if (!process_monster_fear(target_ptr, turn_flags_ptr, m_idx)) return;
168
169         if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
170 }
171
172
173 /*!
174  * @brief 超隠密処理
175  * @param target_ptr プレーヤーへの参照ポインタ
176  * @param m_idx モンスターID
177  * @return モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
178  */
179 bool process_stealth(player_type *target_ptr, MONSTER_IDX m_idx)
180 {
181         if ((target_ptr->special_defense & NINJA_S_STEALTH) == 0) return TRUE;
182
183         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
184         monster_race *r_ptr = &r_info[m_ptr->r_idx];
185         int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
186         if (target_ptr->monlite) tmp /= 3;
187         if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
188         if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
189         return (randint0(tmp) <= (r_ptr->level + 20));
190 }
191
192
193 /*!
194  * @brief 死亡したモンスターが乗馬中のモンスターだった場合に落馬処理を行う
195  * @param target_ptr プレーヤーへの参照ポインタ
196  * @param m_idx モンスターID
197  * @param is_riding_mon 騎乗中であればTRUE
198  * @return なし
199  */
200 void decide_drop_from_monster(player_type *target_ptr, MONSTER_IDX m_idx, bool is_riding_mon)
201 {
202         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
203         monster_race *r_ptr = &r_info[m_ptr->r_idx];
204         if (!is_riding_mon || ((r_ptr->flags7 & RF7_RIDING) != 0)) return;
205
206         if (process_fall_off_horse(target_ptr, 0, TRUE))
207         {
208 #ifdef JP
209                 msg_print("地面に落とされた。");
210 #else
211                 GAME_TEXT m_name[MAX_NLEN];
212                 monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
213                 msg_format("You have fallen from %s.", m_name);
214 #endif
215         }
216 }
217
218
219 /*!
220  * @brief 召喚の親元が消滅した時、子供も消滅させる
221  * @param target_ptr プレーヤーへの参照ポインタ
222  * @param m_idx モンスターID
223  * @param see_m モンスターが視界内にいたらTRUE
224  * @return 召喚モンスターが消滅したらTRUE
225  */
226 bool vanish_summoned_children(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
227 {
228         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
229         if ((m_ptr->parent_m_idx == 0) || (target_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx > 0))
230                 return FALSE;
231
232         if (see_m)
233         {
234                 GAME_TEXT m_name[MAX_NLEN];
235                 monster_desc(target_ptr, m_name, m_ptr, 0);
236                 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
237         }
238
239         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
240         {
241                 GAME_TEXT m_name[MAX_NLEN];
242                 monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
243                 exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
244         }
245
246         delete_monster_idx(target_ptr, m_idx);
247         return TRUE;
248 }
249
250
251 /*!
252  * @brief 寝ているモンスターの起床を判定する
253  * @param target_ptr プレーヤーへの参照ポインタ
254  * @param m_idx モンスターID
255  * @return 寝たままならFALSE、起きているor起きたらTRUE
256  */
257 bool awake_monster(player_type *target_ptr, MONSTER_IDX m_idx)
258 {
259         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
260         monster_race *r_ptr = &r_info[m_ptr->r_idx];
261         if (!monster_csleep_remaining(m_ptr)) return TRUE;
262         if (!(target_ptr->cursed & TRC_AGGRAVATE)) return FALSE;
263
264         (void)set_monster_csleep(target_ptr, m_idx, 0);
265         if (m_ptr->ml)
266         {
267                 GAME_TEXT m_name[MAX_NLEN];
268                 monster_desc(target_ptr, m_name, m_ptr, 0);
269                 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
270         }
271
272         if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
273         {
274                 r_ptr->r_wake++;
275         }
276
277         return TRUE;
278 }
279
280
281 /*!
282  * @brief モンスターの怒り状態を判定する (起こっていたら敵に回す)
283  * @param target_ptr プレーヤーへの参照ポインタ
284  * @param m_idx モンスターID
285  * @param see_m モンスターが視界内にいたらTRUE
286  * @return なし
287  */
288 void process_angar(player_type *target_ptr, MONSTER_IDX m_idx, bool see_m)
289 {
290         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
291         monster_race *r_ptr = &r_info[m_ptr->r_idx];
292         bool gets_angry = FALSE;
293         if (is_friendly(m_ptr) && (target_ptr->cursed & TRC_AGGRAVATE))
294                 gets_angry = TRUE;
295
296         if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
297                 monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
298         {
299                 gets_angry = TRUE;
300         }
301
302         if (target_ptr->phase_out || !gets_angry) return;
303
304         if (is_pet(m_ptr) || see_m)
305         {
306                 GAME_TEXT m_name[MAX_NLEN];
307                 monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
308                 msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
309         }
310
311         set_hostile(target_ptr, m_ptr);
312 }
313
314
315 /*!
316  * @brief 手榴弾の爆発処理
317  * @param target_ptr プレーヤーへの参照ポインタ
318  * @param m_idx モンスターID
319  * @return 爆死したらTRUE
320  */
321 bool explode_grenade(player_type *target_ptr, MONSTER_IDX m_idx)
322 {
323         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
324         if (m_ptr->r_idx != MON_GRENADE) return FALSE;
325
326         bool fear, dead;
327         mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
328         return dead;
329 }
330
331
332 /*!
333  * @brief モンスター依存の特別な行動を取らせる
334  * @param target_ptr プレーヤーへの参照ポインタ
335  * @param m_idx モンスターID
336  * @return なし
337  */
338 void process_special(player_type *target_ptr, MONSTER_IDX m_idx)
339 {
340         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
341         monster_race *r_ptr = &r_info[m_ptr->r_idx];
342         if ((r_ptr->a_ability_flags2 & RF6_SPECIAL) == 0) return;
343         if (m_ptr->r_idx != MON_OHMU) return;
344         if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out) return;
345         if ((r_ptr->freq_spell == 0) || !(randint1(100) <= r_ptr->freq_spell)) return;
346
347         int count = 0;
348         DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
349         BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
350
351         for (int k = 0; k < A_MAX; k++)
352         {
353                 if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
354                 {
355                         if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
356                 }
357         }
358
359         if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
360 }
361
362
363 /*!
364  * @brief モンスターを分裂させるかどうかを決定する (分裂もさせる)
365  * @param target_ptr プレーヤーへの参照ポインタ
366  * @param m_idx モンスターID
367  * @param oy 分裂元モンスターのY座標
368  * @param ox 分裂元モンスターのX座標
369  * @return 実際に分裂したらTRUEを返す
370  */
371 bool decide_monster_multiplication(player_type *target_ptr, MONSTER_IDX m_idx, POSITION oy, POSITION ox)
372 {
373         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
374         monster_race *r_ptr = &r_info[m_ptr->r_idx];
375         if (((r_ptr->flags2 & RF2_MULTIPLY) == 0) || (target_ptr->current_floor_ptr->num_repro >= MAX_REPRO))
376                 return FALSE;
377
378         int k = 0;
379         for (POSITION y = oy - 1; y <= oy + 1; y++)
380         {
381                 for (POSITION x = ox - 1; x <= ox + 1; x++)
382                 {
383                         if (!in_bounds2(target_ptr->current_floor_ptr, y, x)) continue;
384                         if (target_ptr->current_floor_ptr->grid_array[y][x].m_idx) k++;
385                 }
386         }
387
388         if (multiply_barrier(target_ptr, m_idx)) k = 8;
389
390         if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
391         {
392                 if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
393                 {
394                         if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
395                         {
396                                 r_ptr->r_flags2 |= (RF2_MULTIPLY);
397                         }
398
399                         return TRUE;
400                 }
401         }
402
403         return FALSE;
404 }
405
406
407 /*!
408  * @brief モンスターに魔法を試行させる
409  * @param target_ptr プレーヤーへの参照ポインタ
410  * @param m_idx モンスターID
411  * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
412  * @return 魔法を唱えられなければ強制的にFALSE、その後モンスターが実際に魔法を唱えればTRUE
413  */
414 bool cast_spell(player_type *target_ptr, MONSTER_IDX m_idx, bool aware)
415 {
416         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
417         monster_race *r_ptr = &r_info[m_ptr->r_idx];
418         if ((r_ptr->freq_spell == 0) || (randint1(100) > r_ptr->freq_spell))
419                 return FALSE;
420
421         bool counterattack = FALSE;
422         if (m_ptr->target_y)
423         {
424                 MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
425                 if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
426                         projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
427                 {
428                         counterattack = TRUE;
429                 }
430         }
431
432         if (counterattack)
433         {
434                 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
435                 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
436         }
437         else
438         {
439                 if (aware && make_attack_spell(m_idx, target_ptr)) return TRUE;
440                 if (monst_spell_monst(target_ptr, m_idx)) return TRUE;
441         }
442
443         return FALSE;
444 }
445
446
447 /*!
448  * @brief モンスターの恐怖状態を処理する
449  * @param target_ptr プレーヤーへの参照ポインタ
450  * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
451  * @param m_idx モンスターID
452  * @param aware モンスターがプレーヤーに気付いているならばTRUE、超隠密状態ならばFALSE
453  * @return モンスターが戦いを決意したらTRUE
454  */
455 bool process_monster_fear(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
456 {
457         monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
458         bool is_battle_determined = !turn_flags_ptr->do_turn && !turn_flags_ptr->do_move && monster_fear_remaining(m_ptr) && turn_flags_ptr->aware;
459         if (!is_battle_determined) return FALSE;
460
461         (void)set_monster_monfear(target_ptr, m_idx, 0);
462         if (!turn_flags_ptr->see_m) return TRUE;
463
464         GAME_TEXT m_name[MAX_NLEN];
465         monster_desc(target_ptr, m_name, m_ptr, 0);
466         msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
467         return TRUE;
468 }
469
470
471 /*!
472  * @brief 全モンスターのターン管理メインルーチン /
473  * Process all the "live" monsters, once per game turn.
474  * @return なし
475  * @details
476  * During each game current game turn, we scan through the list of all the "live" monsters,\n
477  * (backwards, so we can excise any "freshly dead" monsters), energizing each\n
478  * monster, and allowing fully energized monsters to move, attack, pass, etc.\n
479  *\n
480  * Note that monsters can never move in the monster array (except when the\n
481  * "compact_monsters()" function is called by "dungeon()" or "save_player()").\n
482  *\n
483  * This function is responsible for at least half of the processor time\n
484  * on a normal system with a "normal" amount of monsters and a player doing\n
485  * normal things.\n
486  *\n
487  * When the player is resting, virtually 90% of the processor time is spent\n
488  * in this function, and its children, "process_monster()" and "make_move()".\n
489  *\n
490  * Most of the rest of the time is spent in "update_view()" and "lite_spot()",\n
491  * especially when the player is running.\n
492  *\n
493  * Note the special "MFLAG_BORN" flag, which allows us to ignore "fresh"\n
494  * monsters while they are still being "born".  A monster is "fresh" only\n
495  * during the game turn in which it is created, and we use the "hack_m_idx" to\n
496  * determine if the monster is yet to be processed during the game turn.\n
497  *\n
498  * Note the special "MFLAG_NICE" flag, which allows the player to get one\n
499  * move before any "nasty" monsters get to use their spell attacks.\n
500  *\n
501  * Note that when the "knowledge" about the currently tracked monster\n
502  * changes (flags, attacks, spells), we induce a redraw of the monster\n
503  * recall window.\n
504  */
505 void process_monsters(player_type *target_ptr)
506 {
507         old_race_flags tmp_flags;
508         old_race_flags *old_race_flags_ptr = init_old_race_flags(&tmp_flags);
509
510         floor_type *floor_ptr = target_ptr->current_floor_ptr;
511         floor_ptr->monster_noise = FALSE;
512
513         MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
514         save_old_race_flags(target_ptr->monster_race_idx, old_race_flags_ptr);
515         sweep_monster_process(target_ptr);
516
517         hack_m_idx = 0;
518         if (!target_ptr->monster_race_idx || (target_ptr->monster_race_idx != old_monster_race_idx))
519                 return;
520
521         update_player_window(target_ptr, old_race_flags_ptr);
522 }
523
524
525 /*!
526  * @brief フロア内のモンスターについてターン終了時の処理を繰り返す
527  * @param target_ptr プレーヤーへの参照ポインタ
528  */
529 void sweep_monster_process(player_type *target_ptr)
530 {
531         floor_type *floor_ptr = target_ptr->current_floor_ptr;
532         for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
533         {
534                 monster_type *m_ptr;
535                 m_ptr = &floor_ptr->m_list[i];
536
537                 if (target_ptr->leaving) return;
538                 if (!monster_is_valid(m_ptr)) continue;
539                 if (target_ptr->wild_mode) continue;
540
541                 if (m_ptr->mflag & MFLAG_BORN)
542                 {
543                         m_ptr->mflag &= ~(MFLAG_BORN);
544                         continue;
545                 }
546
547                 if (m_ptr->cdis >= AAF_LIMIT) continue;
548                 if (!decide_process_continue(target_ptr, m_ptr)) continue;
549
550                 SPEED speed = (target_ptr->riding == i) ? target_ptr->pspeed : decide_monster_speed(m_ptr);
551                 m_ptr->energy_need -= SPEED_TO_ENERGY(speed);
552                 if (m_ptr->energy_need > 0) continue;
553
554                 m_ptr->energy_need += ENERGY_NEED();
555                 hack_m_idx = i;
556                 process_monster(target_ptr, i);
557                 reset_target(m_ptr);
558
559                 if (target_ptr->no_flowed && one_in_(3))
560                         m_ptr->mflag2 |= MFLAG2_NOFLOW;
561
562                 if (!target_ptr->playing || target_ptr->is_dead) return;
563                 if (target_ptr->leaving) return;
564         }
565 }
566
567
568 /*!
569  * @brief 後続のモンスター処理が必要かどうか判定する (要調査)
570  * @param target_ptr プレーヤーへの参照ポインタ
571  * @param m_ptr モンスターへの参照ポインタ
572  * @return 後続処理が必要ならTRUE
573  */
574 bool decide_process_continue(player_type *target_ptr, monster_type *m_ptr)
575 {
576         monster_race *r_ptr;
577         r_ptr = &r_info[m_ptr->r_idx];
578         if (!target_ptr->no_flowed)
579         {
580                 m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
581         }
582
583         if (m_ptr->cdis <= (is_pet(m_ptr) ? (r_ptr->aaf > MAX_SIGHT ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
584                 return TRUE;
585
586         if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
587                 (player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
588                 return TRUE;
589
590         if (m_ptr->target_y)
591                 return TRUE;
592
593         return FALSE;
594 }