OSDN Git Service

Merge branch 'develop' into feature/Monster-Sweep-Grid-Adjustment
[hengbandforosx/hengbandosx.git] / src / monster-floor / monster-runaway.cpp
1 /*!
2  * @brief モンスターの逃走に関する処理
3  * @date 2020/03/08
4  * @author Hourier
5  */
6
7 #include "monster-floor/monster-runaway.h"
8 #include "core/disturbance.h"
9 #include "dungeon/quest-completion-checker.h"
10 #include "floor/cave.h"
11 #include "grid/grid.h"
12 #include "monster-floor/monster-remover.h"
13 #include "monster-race/monster-race.h"
14 #include "monster-race/race-flags1.h"
15 #include "monster-race/race-flags2.h"
16 #include "monster-race/race-flags7.h"
17 #include "monster-race/race-indice-types.h"
18 #include "monster/monster-describer.h"
19 #include "monster/monster-info.h"
20 #include "monster/monster-processor-util.h"
21 #include "pet/pet-fall-off.h"
22 #include "system/floor-type-definition.h"
23 #include "system/monster-race-definition.h"
24 #include "system/monster-type-definition.h"
25 #include "system/player-type-definition.h"
26 #include "target/projection-path-calculator.h"
27 #include "view/display-messages.h"
28
29 /*!
30  * @brief HPが1/3未満になった有効的なユニークモンスターの逃走処理を行う
31  * @param target_ptr プレーヤーへの参照ポインタ
32  * @param is_riding_mon 騎乗状態ならばTRUE
33  * @param m_ptr モンスターへの参照ポインタ
34  * @param m_name モンスター名称
35  * @param see_m モンスターが視界内にいたらTRUE
36  */
37 static void escape_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, monster_type *m_ptr, GAME_TEXT *m_name)
38 {
39     monster_race *r_ptr = &r_info[m_ptr->r_idx];
40     if (turn_flags_ptr->is_riding_mon) {
41         msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
42         if (process_fall_off_horse(target_ptr, -1, false)) {
43             msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
44         }
45     }
46
47     if (turn_flags_ptr->see_m) {
48         if ((r_ptr->flags2 & RF2_CAN_SPEAK) && (m_ptr->r_idx != MON_GRIP) && (m_ptr->r_idx != MON_WOLF) && (m_ptr->r_idx != MON_FANG)
49             && player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x)) {
50             msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
51         }
52
53         msg_format(_("%^sがテレポート・レベルの巻物を読んだ。", "%^s reads a scroll of teleport level."), m_name);
54         msg_format(_("%^sが消え去った。", "%^s disappears."), m_name);
55     }
56
57     if (turn_flags_ptr->is_riding_mon && process_fall_off_horse(target_ptr, -1, false)) {
58         msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
59     }
60 }
61
62 /*!
63  * @brief ペットや友好的なモンスターがフロアから逃げる処理を行う
64  * @param target_ptr プレーヤーへの参照ポインタ
65  * @param m_idx モンスターID
66  * @param is_riding_mon 騎乗状態ならばTRUE
67  * @param see_m モンスターが視界内にいたらTRUE
68  * @return モンスターがフロアから消えたらTRUE
69  */
70 bool runaway_monster(player_type *target_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx)
71 {
72     monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
73     monster_race *r_ptr = &r_info[m_ptr->r_idx];
74     bool can_runaway = is_pet(m_ptr) || is_friendly(m_ptr);
75     can_runaway &= ((r_ptr->flags1 & RF1_UNIQUE) != 0) || ((r_ptr->flags7 & RF7_NAZGUL) != 0);
76     can_runaway &= !target_ptr->phase_out;
77     if (!can_runaway)
78         return false;
79
80     static int riding_pinch = 0;
81
82     if (m_ptr->hp >= m_ptr->maxhp / 3) {
83         /* Reset the counter */
84         if (turn_flags_ptr->is_riding_mon)
85             riding_pinch = 0;
86
87         return false;
88     }
89
90     GAME_TEXT m_name[MAX_NLEN];
91     monster_desc(target_ptr, m_name, m_ptr, 0);
92     if (turn_flags_ptr->is_riding_mon && riding_pinch < 2) {
93         msg_format(
94             _("%sは傷の痛さの余りあなたの束縛から逃れようとしている。", "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
95         riding_pinch++;
96         disturb(target_ptr, true, true);
97         return false;
98     }
99
100     escape_monster(target_ptr, turn_flags_ptr, m_ptr, m_name);
101     check_quest_completion(target_ptr, m_ptr);
102     delete_monster_idx(target_ptr, m_idx);
103     return true;
104 }