OSDN Git Service

[Refactor] Changed player_race_type to Pascal case: PlayerRaceType
[hengbandforosx/hengbandosx.git] / src / cmd-item / cmd-eat.cpp
1 /*!
2  * @brief プレイヤーの食べるコマンド実装
3  * @date 2018/09/07
4  @ @author deskull
5  */
6
7 #include "cmd-item/cmd-eat.h"
8 #include "avatar/avatar.h"
9 #include "core/player-update-types.h"
10 #include "core/window-redrawer.h"
11 #include "flavor/flavor-describer.h"
12 #include "flavor/object-flavor-types.h"
13 #include "floor/floor-object.h"
14 #include "hpmp/hp-mp-processor.h"
15 #include "inventory/inventory-object.h"
16 #include "main/sound-definitions-table.h"
17 #include "main/sound-of-music.h"
18 #include "monster-race/monster-race.h"
19 #include "object-enchant/special-object-flags.h"
20 #include "object-hook/hook-expendable.h"
21 #include "object/item-tester-hooker.h"
22 #include "object/item-use-flags.h"
23 #include "object/object-info.h"
24 #include "object/object-kind-hook.h"
25 #include "object/object-kind.h"
26 #include "perception/object-perception.h"
27 #include "player-base/player-class.h"
28 #include "player-base/player-race.h"
29 #include "player-info/class-info.h"
30 #include "player-info/mimic-info-table.h"
31 #include "player-info/samurai-data-type.h"
32 #include "player-status/player-energy.h"
33 #include "player/attack-defense-types.h"
34 #include "player/digestion-processor.h"
35 #include "player/player-damage.h"
36 #include "player/player-status-flags.h"
37 #include "player/special-defense-types.h"
38 #include "spell-realm/spells-hex.h"
39 #include "spell-realm/spells-song.h"
40 #include "spell/spells-status.h"
41 #include "status/action-setter.h"
42 #include "status/bad-status-setter.h"
43 #include "status/base-status.h"
44 #include "status/element-resistance.h"
45 #include "status/experience.h"
46 #include "sv-definition/sv-food-types.h"
47 #include "sv-definition/sv-other-types.h"
48 #include "system/monster-race-definition.h"
49 #include "system/object-type-definition.h"
50 #include "system/player-type-definition.h"
51 #include "util/string-processor.h"
52 #include "view/display-messages.h"
53 #include "view/object-describer.h"
54
55 /*!
56  * @brief 食料タイプの食料を食べたときの効果を発動
57  * @param player_ptr プレイヤー情報への参照ポインタ
58  * @param o_ptr 食べるオブジェクト
59  * @return 鑑定されるならTRUE、されないならFALSE
60  */
61 bool exe_eat_food_type_object(player_type *player_ptr, object_type *o_ptr)
62 {
63     if (o_ptr->tval != TV_FOOD)
64         return false;
65
66     BadStatusSetter bss(player_ptr);
67     switch (o_ptr->sval) {
68     case SV_FOOD_POISON:
69         return (!(has_resist_pois(player_ptr) || is_oppose_pois(player_ptr))) && bss.mod_poison(randint0(10) + 10);
70     case SV_FOOD_BLINDNESS:
71         return !has_resist_blind(player_ptr) && bss.mod_blindness(randint0(200) + 200);
72     case SV_FOOD_PARANOIA:
73         return !has_resist_fear(player_ptr) && bss.mod_afraidness(randint0(10) + 10);
74     case SV_FOOD_CONFUSION:
75         return !has_resist_conf(player_ptr) && bss.mod_confusion(randint0(10) + 10);
76     case SV_FOOD_HALLUCINATION:
77         return !has_resist_chaos(player_ptr) && bss.mod_hallucination(randint0(250) + 250);
78     case SV_FOOD_PARALYSIS:
79         return !player_ptr->free_act && bss.mod_paralysis(randint0(10) + 10);
80     case SV_FOOD_WEAKNESS:
81         take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"));
82         (void)do_dec_stat(player_ptr, A_STR);
83         return true;
84     case SV_FOOD_SICKNESS:
85         take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"));
86         (void)do_dec_stat(player_ptr, A_CON);
87         return true;
88     case SV_FOOD_STUPIDITY:
89         take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"));
90         (void)do_dec_stat(player_ptr, A_INT);
91         return true;
92     case SV_FOOD_NAIVETY:
93         take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"));
94         (void)do_dec_stat(player_ptr, A_WIS);
95         return true;
96     case SV_FOOD_UNHEALTH:
97         take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"));
98         (void)do_dec_stat(player_ptr, A_CON);
99         return true;
100     case SV_FOOD_DISEASE:
101         take_hit(player_ptr, DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"));
102         (void)do_dec_stat(player_ptr, A_STR);
103         return true;
104     case SV_FOOD_CURE_POISON:
105         return bss.poison(0);
106     case SV_FOOD_CURE_BLINDNESS:
107         return bss.blindness(0);
108     case SV_FOOD_CURE_PARANOIA:
109         return bss.afraidness(0);
110     case SV_FOOD_CURE_CONFUSION:
111         return bss.confusion(0);
112     case SV_FOOD_CURE_SERIOUS:
113         return cure_serious_wounds(player_ptr, 4, 8);
114     case SV_FOOD_RESTORE_STR:
115         return do_res_stat(player_ptr, A_STR);
116     case SV_FOOD_RESTORE_CON:
117         return do_res_stat(player_ptr, A_CON);
118     case SV_FOOD_RESTORING:
119         return restore_all_status(player_ptr);
120     case SV_FOOD_BISCUIT:
121         msg_print(_("甘くてサクサクしてとてもおいしい。", "That is sweetly and shortly delicious."));
122         return true;
123     case SV_FOOD_JERKY:
124         msg_print(_("歯ごたえがあっておいしい。", "That is chewy and delicious."));
125         return true;
126     case SV_FOOD_SLIME_MOLD:
127         msg_print(_("これはなんとも形容しがたい味だ。", "That is an indescribable taste."));
128         return true;
129     case SV_FOOD_RATION:
130         msg_print(_("これはおいしい。", "That tastes good."));
131         return true;
132     case SV_FOOD_WAYBREAD:
133         msg_print(_("これはひじょうに美味だ。", "That tastes very good."));
134         (void)bss.poison(0);
135         (void)hp_player(player_ptr, damroll(4, 8));
136         return true;
137     case SV_FOOD_PINT_OF_ALE:
138     case SV_FOOD_PINT_OF_WINE:
139         msg_print(_("のどごし爽やかだ。", "That is refreshing through the throat."));
140         return true;
141     default:
142         return false;
143     }
144 }
145
146 /*!
147  * @brief 魔法道具のチャージをの食料として食べたときの効果を発動
148  * @param player_ptr プレイヤー情報への参照ポインタ
149  * @param o_ptr 食べるオブジェクト
150  * @param item オブジェクトのインベントリ番号
151  * @return 食べようとしたらTRUE、しなかったらFALSE
152  */
153 bool exe_eat_charge_of_magic_device(player_type *player_ptr, object_type *o_ptr, INVENTORY_IDX item)
154 {
155     if (o_ptr->tval != TV_STAFF && o_ptr->tval != TV_WAND)
156         return false;
157
158     if (PlayerRace(player_ptr).food() == PlayerRaceFood::MANA) {
159         concptr staff;
160
161         if (o_ptr->tval == TV_STAFF && (item < 0) && (o_ptr->number > 1)) {
162             msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));
163             return true;
164         }
165
166         staff = (o_ptr->tval == TV_STAFF) ? _("杖", "staff") : _("魔法棒", "wand");
167
168         /* "Eat" charges */
169         if (o_ptr->pval == 0) {
170             msg_format(_("この%sにはもう魔力が残っていない。", "The %s has no charges left."), staff);
171             o_ptr->ident |= (IDENT_EMPTY);
172             player_ptr->window_flags |= (PW_INVEN);
173             return true;
174         }
175
176         msg_format(_("あなたは%sの魔力をエネルギー源として吸収した。", "You absorb mana of the %s as your energy."), staff);
177
178         /* Use a single charge */
179         o_ptr->pval--;
180
181         /* Eat a charge */
182         set_food(player_ptr, player_ptr->food + 5000);
183
184         /* XXX Hack -- unstack if necessary */
185         if (o_ptr->tval == TV_STAFF && (item >= 0) && (o_ptr->number > 1)) {
186             object_type forge;
187             object_type *q_ptr;
188             q_ptr = &forge;
189             q_ptr->copy_from(o_ptr);
190
191             /* Modify quantity */
192             q_ptr->number = 1;
193
194             /* Restore the charges */
195             o_ptr->pval++;
196
197             /* Unstack the used item */
198             o_ptr->number--;
199             item = store_item_to_inventory(player_ptr, q_ptr);
200
201             msg_format(_("杖をまとめなおした。", "You unstack your staff."));
202         }
203
204         if (item >= 0) {
205             inven_item_charges(player_ptr, item);
206         } else {
207             floor_item_charges(player_ptr->current_floor_ptr, 0 - item);
208         }
209
210         player_ptr->window_flags |= (PW_INVEN | PW_EQUIP);
211         return true;
212     }
213
214     return false;
215 }
216
217 /*!
218  * @brief 食料を食べるコマンドのサブルーチン
219  * @param item 食べるオブジェクトの所持品ID
220  */
221 void exe_eat_food(player_type *player_ptr, INVENTORY_IDX item)
222 {
223     if (music_singing_any(player_ptr))
224         stop_singing(player_ptr);
225
226     SpellHex spell_hex(player_ptr);
227     if (spell_hex.is_spelling_any()) {
228         (void)spell_hex.stop_all_spells();
229     }
230
231     object_type *o_ptr = ref_item(player_ptr, item);
232
233     sound(SOUND_EAT);
234
235     PlayerEnergy(player_ptr).set_player_turn_energy(100);
236
237     /* Object level */
238     int lev = k_info[o_ptr->k_idx].level;
239
240     /* Identity not known yet */
241     int ident = exe_eat_food_type_object(player_ptr, o_ptr);
242
243     /*
244      * Store what may have to be updated for the inventory (including
245      * autodestroy if set by something else).  Then turn off those flags
246      * so that updates triggered by calling gain_exp() or set_food() below
247      * do not rearrange the inventory before the food item is destroyed in
248      * the pack.
249      */
250     BIT_FLAGS inventory_flags = (PU_COMBINE | PU_REORDER | (player_ptr->update & PU_AUTODESTROY));
251     player_ptr->update &= ~(PU_COMBINE | PU_REORDER | PU_AUTODESTROY);
252
253     if (!(o_ptr->is_aware())) {
254         chg_virtue(player_ptr, V_KNOWLEDGE, -1);
255         chg_virtue(player_ptr, V_PATIENCE, -1);
256         chg_virtue(player_ptr, V_CHANCE, 1);
257     }
258
259     /* We have tried it */
260     if (o_ptr->tval == TV_FOOD)
261         object_tried(o_ptr);
262
263     /* The player is now aware of the object */
264     if (ident && !o_ptr->is_aware()) {
265         object_aware(player_ptr, o_ptr);
266         gain_exp(player_ptr, (lev + (player_ptr->lev >> 1)) / player_ptr->lev);
267     }
268
269     player_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
270
271     /* Undeads drain recharge of magic device */
272     if (exe_eat_charge_of_magic_device(player_ptr, o_ptr, item)) {
273         player_ptr->update |= inventory_flags;
274         return;
275     }
276
277     auto food_type = PlayerRace(player_ptr).food();
278
279     /* Balrogs change humanoid corpses to energy */
280     if (food_type == PlayerRaceFood::CORPSE && (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_CORPSE && angband_strchr("pht", r_info[o_ptr->pval].d_char))) {
281         GAME_TEXT o_name[MAX_NLEN];
282         describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
283         msg_format(_("%sは燃え上り灰になった。精力を吸収した気がする。", "%^s is burnt to ashes.  You absorb its vitality!"), o_name);
284         (void)set_food(player_ptr, PY_FOOD_MAX - 1);
285
286         player_ptr->update |= inventory_flags;
287         vary_item(player_ptr, item, -1);
288         return;
289     }
290
291     if (PlayerRace(player_ptr).equals(PlayerRaceType::SKELETON)) {
292         if (!((o_ptr->sval == SV_FOOD_WAYBREAD) || (o_ptr->sval < SV_FOOD_BISCUIT))) {
293             object_type forge;
294             object_type *q_ptr = &forge;
295
296             msg_print(_("食べ物がアゴを素通りして落ちた!", "The food falls through your jaws!"));
297             q_ptr->prep(lookup_kind(o_ptr->tval, o_ptr->sval));
298
299             /* Drop the object from heaven */
300             (void)drop_near(player_ptr, q_ptr, -1, player_ptr->y, player_ptr->x);
301         } else {
302             msg_print(_("食べ物がアゴを素通りして落ち、消えた!", "The food falls through your jaws and vanishes!"));
303         }
304     } else if (food_type == PlayerRaceFood::BLOOD) {
305         /* Vampires are filled only by bloods, so reduced nutritional benefit */
306         (void)set_food(player_ptr, player_ptr->food + (o_ptr->pval / 10));
307         msg_print(_("あなたのような者にとって食糧など僅かな栄養にしかならない。", "Mere victuals hold scant sustenance for a being such as yourself."));
308
309         if (player_ptr->food < PY_FOOD_ALERT) /* Hungry */
310             msg_print(_("あなたの飢えは新鮮な血によってのみ満たされる!", "Your hunger can only be satisfied with fresh blood!"));
311     } else if (food_type == PlayerRaceFood::WATER) {
312         msg_print(_("動物の食物はあなたにとってほとんど栄養にならない。", "The food of animals is poor sustenance for you."));
313         set_food(player_ptr, player_ptr->food + ((o_ptr->pval) / 20));
314     } else if (food_type != PlayerRaceFood::RATION) {
315         msg_print(_("生者の食物はあなたにとってほとんど栄養にならない。", "The food of mortals is poor sustenance for you."));
316         set_food(player_ptr, player_ptr->food + ((o_ptr->pval) / 20));
317     } else {
318         if (o_ptr->tval == TV_FOOD && o_ptr->sval == SV_FOOD_WAYBREAD) {
319             /* Waybread is always fully satisfying. */
320             set_food(player_ptr, MAX(player_ptr->food, PY_FOOD_MAX - 1));
321         } else {
322             /* Food can feed the player */
323             (void)set_food(player_ptr, player_ptr->food + o_ptr->pval);
324         }
325     }
326
327     player_ptr->update |= inventory_flags;
328     vary_item(player_ptr, item, -1);
329 }
330
331 /*!
332  * @brief 食料を食べるコマンドのメインルーチン /
333  * Eat some food (from the pack or floor)
334  */
335 void do_cmd_eat_food(player_type *player_ptr)
336 {
337     OBJECT_IDX item;
338     concptr q, s;
339
340     PlayerClass(player_ptr).break_samurai_stance({ SamuraiStance::MUSOU, SamuraiStance::KOUKIJIN });
341
342     q = _("どれを食べますか? ", "Eat which item? ");
343     s = _("食べ物がない。", "You have nothing to eat.");
344
345     if (!choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), FuncItemTester(item_tester_hook_eatable, player_ptr)))
346         return;
347
348     exe_eat_food(player_ptr, item);
349 }