OSDN Git Service

Reword English message for giant eagle teleport self effect: original had subject...
[hengband/hengband.git] / src / pet / pet-fall-off.c
1 /*!
2  * @brief 落馬処理
3  * @date 2020/05/31
4  * @author Hourier
5  */
6
7 #include "pet/pet-fall-off.h"
8 #include "core/player-redraw-types.h"
9 #include "core/player-update-types.h"
10 #include "core/stuff-handler.h"
11 #include "core/window-redrawer.h"
12 #include "floor/cave.h"
13 #include "grid/feature.h"
14 #include "monster-race/monster-race.h"
15 #include "monster/monster-describer.h"
16 #include "pet/pet-util.h"
17 #include "player/player-damage.h"
18 #include "player/player-move.h"
19 #include "player/player-skill.h"
20 #include "system/floor-type-definition.h"
21 #include "target/target-checker.h"
22 #include "view/display-messages.h"
23
24 /*!
25  * @brief モンスターから直接攻撃を受けた時に落馬するかどうかを判定し、判定アウトならば落馬させる
26  * @param creature_ptr プレーヤーへの参照ポインタ
27  * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ
28  * @return なし
29  */
30 void check_fall_off_horse(player_type *creature_ptr, monap_type *monap_ptr)
31 {
32     if ((creature_ptr->riding == 0) || (monap_ptr->damage == 0))
33         return;
34
35     char m_steed_name[MAX_NLEN];
36     monster_desc(creature_ptr, m_steed_name, &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding], 0);
37     if (process_fall_off_horse(creature_ptr, (monap_ptr->damage > 200) ? 200 : monap_ptr->damage, FALSE))
38         msg_format(_("%^sから落ちてしまった!", "You have fallen from %s."), m_steed_name);
39 }
40
41 /*!
42  * @brief 落馬する可能性を計算する
43  * @param creature_ptr プレーヤーへの参照ポインタ
44  * @param dam 落馬判定を発した際に受けたダメージ量
45  * @param force TRUEならば強制的に落馬する
46  * @param 乗馬中のモンスターのレベル
47  * @return FALSEなら落馬しないことで確定、TRUEなら処理続行
48  * @details レベルの低い乗馬からは落馬しにくい
49  */
50 static bool calc_fall_off_possibility(player_type *creature_ptr, const HIT_POINT dam, const bool force, monster_race *r_ptr)
51 {
52     if (force)
53         return TRUE;
54
55     int cur = creature_ptr->skill_exp[GINOU_RIDING];
56     int max = s_info[creature_ptr->pclass].s_max[GINOU_RIDING];
57     int ridinglevel = r_ptr->level;
58
59     int fall_off_level = r_ptr->level;
60     if (creature_ptr->riding_ryoute)
61         fall_off_level += 20;
62
63     if ((cur < max) && (max > 1000) && (dam / 2 + ridinglevel) > (cur / 30 + 10)) {
64         int inc = 0;
65         if (ridinglevel > (cur / 100 + 15))
66             inc += 1 + (ridinglevel - cur / 100 - 15);
67         else
68             inc += 1;
69
70         creature_ptr->skill_exp[GINOU_RIDING] = MIN(max, cur + inc);
71     }
72
73     if (randint0(dam / 2 + fall_off_level * 2) >= cur / 30 + 10)
74         return TRUE;
75
76     if ((((creature_ptr->pclass == CLASS_BEASTMASTER) || (creature_ptr->pclass == CLASS_CAVALRY)) && !creature_ptr->riding_ryoute)
77         || !one_in_(creature_ptr->lev * (creature_ptr->riding_ryoute ? 2 : 3) + 30)) {
78         return FALSE;
79     }
80
81     return TRUE;
82 }
83
84 /*!
85  * @brief プレイヤーの落馬判定処理
86  * @param dam 落馬判定を発した際に受けたダメージ量
87  * @param force TRUEならば強制的に落馬する
88  * @return 実際に落馬したらTRUEを返す
89  */
90 bool process_fall_off_horse(player_type *creature_ptr, HIT_POINT dam, bool force)
91 {
92     POSITION sy = 0;
93     POSITION sx = 0;
94     int sn = 0;
95     GAME_TEXT m_name[MAX_NLEN];
96     monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
97     monster_race *r_ptr = &r_info[m_ptr->r_idx];
98
99     if (!creature_ptr->riding || creature_ptr->wild_mode)
100         return FALSE;
101
102     if (dam >= 0 || force) {
103         if (!calc_fall_off_possibility(creature_ptr, dam, force, r_ptr))
104             return FALSE;
105
106         /* Check around the player */
107         for (DIRECTION i = 0; i < 8; i++) {
108             POSITION y = creature_ptr->y + ddy_ddd[i];
109             POSITION x = creature_ptr->x + ddx_ddd[i];
110
111             grid_type *g_ptr;
112             g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
113
114             if (g_ptr->m_idx)
115                 continue;
116
117             /* Skip non-empty grids */
118             if (!cave_has_flag_grid(g_ptr, FF_MOVE) && !cave_has_flag_grid(g_ptr, FF_CAN_FLY)) {
119                 if (!can_player_ride_pet(creature_ptr, g_ptr, FALSE))
120                     continue;
121             }
122
123             if (cave_has_flag_grid(g_ptr, FF_PATTERN))
124                 continue;
125
126             /* Count "safe" grids */
127             sn++;
128
129             /* Randomize choice */
130             if (randint0(sn) > 0)
131                 continue;
132
133             /* Save the safe location */
134             sy = y;
135             sx = x;
136         }
137
138         if (!sn) {
139             monster_desc(creature_ptr, m_name, m_ptr, 0);
140             msg_format(_("%sから振り落とされそうになって、壁にぶつかった。", "You have nearly fallen from %s, but bumped into wall."), m_name);
141             take_hit(creature_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("壁への衝突", "bumping into wall"), -1);
142             return FALSE;
143         }
144
145         POSITION old_y = creature_ptr->y;
146         POSITION old_x = creature_ptr->x;
147         creature_ptr->y = sy;
148         creature_ptr->x = sx;
149         lite_spot(creature_ptr, old_y, old_x);
150         lite_spot(creature_ptr, creature_ptr->y, creature_ptr->x);
151         verify_panel(creature_ptr);
152     }
153
154     creature_ptr->riding = 0;
155     creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
156     creature_ptr->riding_ryoute = creature_ptr->old_riding_ryoute = FALSE;
157
158     creature_ptr->update |= (PU_BONUS | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
159     handle_stuff(creature_ptr);
160
161     creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
162     creature_ptr->redraw |= (PR_EXTRA);
163
164     /* Update health track of mount */
165     creature_ptr->redraw |= (PR_UHEALTH);
166
167     bool fall_dam = FALSE;
168     if (creature_ptr->levitation && !force) {
169         monster_desc(creature_ptr, m_name, m_ptr, 0);
170         msg_format(_("%sから落ちたが、空中でうまく体勢を立て直して着地した。", "You are thrown from %s, but make a good landing."), m_name);
171     } else {
172         take_hit(creature_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("落馬", "Falling from riding"), -1);
173         fall_dam = TRUE;
174     }
175
176     if (sy && !creature_ptr->is_dead)
177         (void)move_player_effect(creature_ptr, creature_ptr->y, creature_ptr->x, MPE_DONT_PICKUP | MPE_DONT_SWAP_MON);
178
179     return fall_dam;
180 }