OSDN Git Service

Merge branch 'master' of https://github.com/hengband/hengband
[hengbandforosx/hengbandosx.git] / src / player / digestion-processor.cpp
1 #include "player/digestion-processor.h"
2 #include "avatar/avatar.h"
3 #include "core/disturbance.h"
4 #include "core/speed-table.h"
5 #include "core/stuff-handler.h"
6 #include "floor/wild.h"
7 #include "game-option/disturbance-options.h"
8 #include "main/sound-definitions-table.h"
9 #include "main/sound-of-music.h"
10 #include "object-enchant/trc-types.h"
11 #include "player-base/player-class.h"
12 #include "player-info/monk-data-type.h"
13 #include "player-info/samurai-data-type.h"
14 #include "player/player-damage.h"
15 #include "player/player-status.h"
16 #include "player/special-defense-types.h"
17 #include "status/bad-status-setter.h"
18 #include "system/player-type-definition.h"
19 #include "system/redrawing-flags-updater.h"
20 #include "timed-effect/player-paralysis.h"
21 #include "timed-effect/timed-effects.h"
22 #include "view/display-messages.h"
23 #include "world/world.h"
24
25 /*!
26  * @brief 10ゲームターンが進行するごとにプレイヤーの腹を減らす
27  * @param player_ptr プレイヤーへの参照ポインタ
28  */
29 void starve_player(PlayerType *player_ptr)
30 {
31     if (player_ptr->phase_out) {
32         return;
33     }
34
35     if (player_ptr->food >= PY_FOOD_MAX) {
36         (void)set_food(player_ptr, player_ptr->food - 100);
37     } else if (!(w_ptr->game_turn % (TURNS_PER_TICK * 5))) {
38         int digestion = speed_to_energy(player_ptr->pspeed);
39         if (player_ptr->regenerate) {
40             digestion += 20;
41         }
42         PlayerClass pc(player_ptr);
43         if (!pc.monk_stance_is(MonkStanceType::NONE) || !pc.samurai_stance_is(SamuraiStanceType::NONE)) {
44             digestion += 20;
45         }
46         if (player_ptr->cursed.has(CurseTraitType::FAST_DIGEST)) {
47             digestion += 30;
48         }
49
50         if (player_ptr->slow_digest) {
51             digestion -= 5;
52         }
53
54         if (digestion < 1) {
55             digestion = 1;
56         }
57         if (digestion > 100) {
58             digestion = 100;
59         }
60
61         (void)set_food(player_ptr, player_ptr->food - digestion);
62     }
63
64     if ((player_ptr->food >= PY_FOOD_FAINT)) {
65         return;
66     }
67
68     if (!player_ptr->effects()->paralysis()->is_paralyzed() && (randint0(100) < 10)) {
69         msg_print(_("あまりにも空腹で気絶してしまった。", "You faint from the lack of food."));
70         disturb(player_ptr, true, true);
71         (void)BadStatusSetter(player_ptr).mod_paralysis(1 + randint0(5));
72     }
73
74     if (player_ptr->food < PY_FOOD_STARVE) {
75         int dam = (PY_FOOD_STARVE - player_ptr->food) / 10;
76         if (!is_invuln(player_ptr)) {
77             take_hit(player_ptr, DAMAGE_LOSELIFE, dam, _("空腹", "starvation"));
78         }
79     }
80 }
81
82 /*!
83  * @brief 空腹状態をセットする / Set "food", notice observable changes
84  * @param v 継続時間
85  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す
86  * @details
87  * Set "", notice observable changes\n
88  *\n
89  * The "food" variable can get as large as 20000, allowing the
90  * addition of the most "filling" item, Elvish Waybread, which adds
91  * 7500 food units, without overflowing the 32767 maximum limit.\n
92  *\n
93  * Perhaps we should disturb the player with various messages,
94  * especially messages about hunger status changes.  \n
95  *\n
96  * Digestion of food is handled in "dungeon.c", in which, normally,
97  * the player digests about 20 food units per 100 game turns, more
98  * when "fast", more when "regenerating", less with "slow digestion",
99  * but when the player is "gorged", he digests 100 food units per 10
100  * game turns, or a full 1000 food units per 100 game turns.\n
101  *\n
102  * Note that the player's speed is reduced by 10 units while gorged,
103  * so if the player eats a single food ration (5000 food units) when
104  * full (15000 food units), he will be gorged for (5000/100)*10 = 500
105  * game turns, or 500/(100/5) = 25 player turns (if nothing else is
106  * affecting the player speed).\n
107  */
108 bool set_food(PlayerType *player_ptr, TIME_EFFECT v)
109 {
110     int old_aux, new_aux;
111
112     bool notice = false;
113     v = (v > 20000) ? 20000 : (v < 0) ? 0
114                                       : v;
115     if (player_ptr->food < PY_FOOD_FAINT) {
116         old_aux = 0;
117     } else if (player_ptr->food < PY_FOOD_WEAK) {
118         old_aux = 1;
119     } else if (player_ptr->food < PY_FOOD_ALERT) {
120         old_aux = 2;
121     } else if (player_ptr->food < PY_FOOD_FULL) {
122         old_aux = 3;
123     } else if (player_ptr->food < PY_FOOD_MAX) {
124         old_aux = 4;
125     } else {
126         old_aux = 5;
127     }
128
129     if (v < PY_FOOD_FAINT) {
130         new_aux = 0;
131     } else if (v < PY_FOOD_WEAK) {
132         new_aux = 1;
133     } else if (v < PY_FOOD_ALERT) {
134         new_aux = 2;
135     } else if (v < PY_FOOD_FULL) {
136         new_aux = 3;
137     } else if (v < PY_FOOD_MAX) {
138         new_aux = 4;
139     } else {
140         new_aux = 5;
141     }
142
143     if (old_aux < 1 && new_aux > 0) {
144         chg_virtue(player_ptr, Virtue::PATIENCE, 2);
145     } else if (old_aux < 3 && (old_aux != new_aux)) {
146         chg_virtue(player_ptr, Virtue::PATIENCE, 1);
147     }
148     if (old_aux == 2) {
149         chg_virtue(player_ptr, Virtue::TEMPERANCE, 1);
150     }
151     if (old_aux == 0) {
152         chg_virtue(player_ptr, Virtue::TEMPERANCE, -1);
153     }
154
155     if (new_aux > old_aux) {
156         switch (new_aux) {
157         case 1:
158             msg_print(_("まだ空腹で倒れそうだ。", "You are still weak."));
159             break;
160         case 2:
161             msg_print(_("まだ空腹だ。", "You are still hungry."));
162             break;
163         case 3:
164             msg_print(_("空腹感がおさまった。", "You are no longer hungry."));
165             break;
166         case 4:
167             msg_print(_("満腹だ!", "You are full!"));
168             break;
169
170         case 5:
171             msg_print(_("食べ過ぎだ!", "You have gorged yourself!"));
172             chg_virtue(player_ptr, Virtue::HARMONY, -1);
173             chg_virtue(player_ptr, Virtue::PATIENCE, -1);
174             chg_virtue(player_ptr, Virtue::TEMPERANCE, -2);
175             break;
176         }
177
178         notice = true;
179     } else if (new_aux < old_aux) {
180         switch (new_aux) {
181         case 0:
182             sound(SOUND_FAINT);
183             msg_print(_("あまりにも空腹で気を失ってしまった!", "You are getting faint from hunger!"));
184             break;
185         case 1:
186             sound(SOUND_WEAK);
187             msg_print(_("お腹が空いて倒れそうだ。", "You are getting weak from hunger!"));
188             break;
189         case 2:
190             sound(SOUND_HUNGRY);
191             msg_print(_("お腹が空いてきた。", "You are getting hungry."));
192             break;
193         case 3:
194             msg_print(_("満腹感がなくなった。", "You are no longer full."));
195             break;
196         case 4:
197             msg_print(_("やっとお腹がきつくなくなった。", "You are no longer gorged."));
198             break;
199         }
200
201         if (player_ptr->wild_mode && (new_aux < 2)) {
202             change_wild_mode(player_ptr, false);
203         }
204
205         notice = true;
206     }
207
208     player_ptr->food = v;
209     if (!notice) {
210         return false;
211     }
212
213     if (disturb_state) {
214         disturb(player_ptr, false, false);
215     }
216
217     auto &rfu = RedrawingFlagsUpdater::get_instance();
218     rfu.set_flag(StatusRecalculatingFlag::BONUS);
219     rfu.set_flag(MainWindowRedrawingFlag::HUNGER);
220     handle_stuff(player_ptr);
221
222     return true;
223 }