OSDN Git Service

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