OSDN Git Service

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