OSDN Git Service

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