OSDN Git Service

[Refactor] #37287 #37353 型の置換。 / Type replacement.
[hengband/hengband.git] / src / cmd-eat.c
1 /*!\r
2  * @file cmd-eat.c\r
3  * @brief プレイヤーの食べるコマンド実装\r
4  * @date 2018/09/07\r
5  * @details\r
6  * cmd6.cより分離。\r
7  */\r
8 \r
9 \r
10 #include "angband.h"\r
11 #include "object-hook.h"\r
12 \r
13 /*!\r
14  * @brief 食料を食べるコマンドのサブルーチン\r
15  * @param item 食べるオブジェクトの所持品ID\r
16  * @return なし\r
17  */\r
18 void do_cmd_eat_food_aux(int item)\r
19 {\r
20         int ident, lev;\r
21         object_type *o_ptr;\r
22 \r
23         if (music_singing_any()) stop_singing();\r
24         if (hex_spelling_any()) stop_hex_spell_all();\r
25 \r
26         /* Get the item (in the pack) */\r
27         if (item >= 0)\r
28         {\r
29                 o_ptr = &inventory[item];\r
30         }\r
31 \r
32         /* Get the item (on the floor) */\r
33         else\r
34         {\r
35                 o_ptr = &o_list[0 - item];\r
36         }\r
37 \r
38         /* Sound */\r
39         sound(SOUND_EAT);\r
40 \r
41         /* Take a turn */\r
42         p_ptr->energy_use = 100;\r
43 \r
44         /* Identity not known yet */\r
45         ident = FALSE;\r
46 \r
47         /* Object level */\r
48         lev = k_info[o_ptr->k_idx].level;\r
49 \r
50         if (o_ptr->tval == TV_FOOD)\r
51         {\r
52                 /* Analyze the food */\r
53                 switch (o_ptr->sval)\r
54                 {\r
55                 case SV_FOOD_POISON:\r
56                 {\r
57                         if (!(p_ptr->resist_pois || IS_OPPOSE_POIS()))\r
58                         {\r
59                                 if (set_poisoned(p_ptr->poisoned + randint0(10) + 10))\r
60                                 {\r
61                                         ident = TRUE;\r
62                                 }\r
63                         }\r
64                         break;\r
65                 }\r
66 \r
67                 case SV_FOOD_BLINDNESS:\r
68                 {\r
69                         if (!p_ptr->resist_blind)\r
70                         {\r
71                                 if (set_blind(p_ptr->blind + randint0(200) + 200))\r
72                                 {\r
73                                         ident = TRUE;\r
74                                 }\r
75                         }\r
76                         break;\r
77                 }\r
78 \r
79                 case SV_FOOD_PARANOIA:\r
80                 {\r
81                         if (!p_ptr->resist_fear)\r
82                         {\r
83                                 if (set_afraid(p_ptr->afraid + randint0(10) + 10))\r
84                                 {\r
85                                         ident = TRUE;\r
86                                 }\r
87                         }\r
88                         break;\r
89                 }\r
90 \r
91                 case SV_FOOD_CONFUSION:\r
92                 {\r
93                         if (!p_ptr->resist_conf)\r
94                         {\r
95                                 if (set_confused(p_ptr->confused + randint0(10) + 10))\r
96                                 {\r
97                                         ident = TRUE;\r
98                                 }\r
99                         }\r
100                         break;\r
101                 }\r
102 \r
103                 case SV_FOOD_HALLUCINATION:\r
104                 {\r
105                         if (!p_ptr->resist_chaos)\r
106                         {\r
107                                 if (set_image(p_ptr->image + randint0(250) + 250))\r
108                                 {\r
109                                         ident = TRUE;\r
110                                 }\r
111                         }\r
112                         break;\r
113                 }\r
114 \r
115                 case SV_FOOD_PARALYSIS:\r
116                 {\r
117                         if (!p_ptr->free_act)\r
118                         {\r
119                                 if (set_paralyzed(p_ptr->paralyzed + randint0(10) + 10))\r
120                                 {\r
121                                         ident = TRUE;\r
122                                 }\r
123                         }\r
124                         break;\r
125                 }\r
126 \r
127                 case SV_FOOD_WEAKNESS:\r
128                 {\r
129                         take_hit(DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"), -1);\r
130                         (void)do_dec_stat(A_STR);\r
131                         ident = TRUE;\r
132                         break;\r
133                 }\r
134 \r
135                 case SV_FOOD_SICKNESS:\r
136                 {\r
137                         take_hit(DAMAGE_NOESCAPE, damroll(6, 6), _("毒入り食料", "poisonous food"), -1);\r
138                         (void)do_dec_stat(A_CON);\r
139                         ident = TRUE;\r
140                         break;\r
141                 }\r
142 \r
143                 case SV_FOOD_STUPIDITY:\r
144                 {\r
145                         take_hit(DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"), -1);\r
146                         (void)do_dec_stat(A_INT);\r
147                         ident = TRUE;\r
148                         break;\r
149                 }\r
150 \r
151                 case SV_FOOD_NAIVETY:\r
152                 {\r
153                         take_hit(DAMAGE_NOESCAPE, damroll(8, 8), _("毒入り食料", "poisonous food"), -1);\r
154                         (void)do_dec_stat(A_WIS);\r
155                         ident = TRUE;\r
156                         break;\r
157                 }\r
158 \r
159                 case SV_FOOD_UNHEALTH:\r
160                 {\r
161                         take_hit(DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"), -1);\r
162                         (void)do_dec_stat(A_CON);\r
163                         ident = TRUE;\r
164                         break;\r
165                 }\r
166 \r
167                 case SV_FOOD_DISEASE:\r
168                 {\r
169                         take_hit(DAMAGE_NOESCAPE, damroll(10, 10), _("毒入り食料", "poisonous food"), -1);\r
170                         (void)do_dec_stat(A_STR);\r
171                         ident = TRUE;\r
172                         break;\r
173                 }\r
174 \r
175                 case SV_FOOD_CURE_POISON:\r
176                 {\r
177                         if (set_poisoned(0)) ident = TRUE;\r
178                         break;\r
179                 }\r
180 \r
181                 case SV_FOOD_CURE_BLINDNESS:\r
182                 {\r
183                         if (set_blind(0)) ident = TRUE;\r
184                         break;\r
185                 }\r
186 \r
187                 case SV_FOOD_CURE_PARANOIA:\r
188                 {\r
189                         if (set_afraid(0)) ident = TRUE;\r
190                         break;\r
191                 }\r
192 \r
193                 case SV_FOOD_CURE_CONFUSION:\r
194                 {\r
195                         if (set_confused(0)) ident = TRUE;\r
196                         break;\r
197                 }\r
198 \r
199                 case SV_FOOD_CURE_SERIOUS:\r
200                 {\r
201                         ident = cure_serious_wounds(4, 8);\r
202                         break;\r
203                 }\r
204 \r
205                 case SV_FOOD_RESTORE_STR:\r
206                 {\r
207                         if (do_res_stat(A_STR)) ident = TRUE;\r
208                         break;\r
209                 }\r
210 \r
211                 case SV_FOOD_RESTORE_CON:\r
212                 {\r
213                         if (do_res_stat(A_CON)) ident = TRUE;\r
214                         break;\r
215                 }\r
216 \r
217                 case SV_FOOD_RESTORING:\r
218                 {\r
219                         ident = restore_all_status();\r
220                         break;\r
221                 }\r
222 \r
223 \r
224 #ifdef JP\r
225                 /* それぞれの食べ物の感想をオリジナルより細かく表現 */\r
226                 case SV_FOOD_BISCUIT:\r
227                 {\r
228                         msg_print("甘くてサクサクしてとてもおいしい。");\r
229                         ident = TRUE;\r
230                         break;\r
231                 }\r
232 \r
233                 case SV_FOOD_JERKY:\r
234                 {\r
235                         msg_print("歯ごたえがあっておいしい。");\r
236                         ident = TRUE;\r
237                         break;\r
238                 }\r
239 \r
240                 case SV_FOOD_SLIME_MOLD:\r
241                 {\r
242                         msg_print("これはなんとも形容しがたい味だ。");\r
243                         ident = TRUE;\r
244                         break;\r
245                 }\r
246 \r
247                 case SV_FOOD_RATION:\r
248                 {\r
249                         msg_print("これはおいしい。");\r
250                         ident = TRUE;\r
251                         break;\r
252                 }\r
253 #else\r
254                 case SV_FOOD_RATION:\r
255                 case SV_FOOD_BISCUIT:\r
256                 case SV_FOOD_JERKY:\r
257                 case SV_FOOD_SLIME_MOLD:\r
258                 {\r
259                         msg_print("That tastes good.");\r
260                         ident = TRUE;\r
261                         break;\r
262                 }\r
263 #endif\r
264 \r
265 \r
266                 case SV_FOOD_WAYBREAD:\r
267                 {\r
268                         msg_print(_("これはひじょうに美味だ。", "That tastes good."));\r
269                         (void)set_poisoned(0);\r
270                         (void)hp_player(damroll(4, 8));\r
271                         ident = TRUE;\r
272                         break;\r
273                 }\r
274 \r
275 #ifdef JP\r
276                 case SV_FOOD_PINT_OF_ALE:\r
277                 {\r
278                         msg_print("のどごし爽やかだ。");\r
279                         ident = TRUE;\r
280                         break;\r
281                 }\r
282 \r
283                 case SV_FOOD_PINT_OF_WINE:\r
284                 {\r
285                         msg_print("That tastes good.");\r
286                         ident = TRUE;\r
287                         break;\r
288                 }\r
289 #else\r
290                 case SV_FOOD_PINT_OF_ALE:\r
291                 case SV_FOOD_PINT_OF_WINE:\r
292                 {\r
293                         msg_print("That tastes good.");\r
294                         ident = TRUE;\r
295                         break;\r
296                 }\r
297 #endif\r
298 \r
299                 }\r
300         }\r
301 \r
302         /* Combine / Reorder the pack (later) */\r
303         p_ptr->notice |= (PN_COMBINE | PN_REORDER);\r
304 \r
305         if (!(object_is_aware(o_ptr)))\r
306         {\r
307                 chg_virtue(V_KNOWLEDGE, -1);\r
308                 chg_virtue(V_PATIENCE, -1);\r
309                 chg_virtue(V_CHANCE, 1);\r
310         }\r
311 \r
312         /* We have tried it */\r
313         if (o_ptr->tval == TV_FOOD) object_tried(o_ptr);\r
314 \r
315         /* The player is now aware of the object */\r
316         if (ident && !object_is_aware(o_ptr))\r
317         {\r
318                 object_aware(o_ptr);\r
319                 gain_exp((lev + (p_ptr->lev >> 1)) / p_ptr->lev);\r
320         }\r
321 \r
322         /* Window stuff */\r
323         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);\r
324 \r
325 \r
326         /* Food can feed the player */\r
327         if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE))\r
328         {\r
329                 /* Reduced nutritional benefit */\r
330                 (void)set_food(p_ptr->food + (o_ptr->pval / 10));\r
331                 msg_print(_("あなたのような者にとって食糧など僅かな栄養にしかならない。",\r
332                         "Mere victuals hold scant sustenance for a being such as yourself."));\r
333 \r
334                 if (p_ptr->food < PY_FOOD_ALERT)   /* Hungry */\r
335                         msg_print(_("あなたの飢えは新鮮な血によってのみ満たされる!",\r
336                                 "Your hunger can only be satisfied with fresh blood!"));\r
337         }\r
338         else if ((prace_is_(RACE_SKELETON) ||\r
339                 prace_is_(RACE_GOLEM) ||\r
340                 prace_is_(RACE_ZOMBIE) ||\r
341                 prace_is_(RACE_SPECTRE)) &&\r
342                 (o_ptr->tval == TV_STAFF || o_ptr->tval == TV_WAND))\r
343         {\r
344                 cptr staff;\r
345 \r
346                 if (o_ptr->tval == TV_STAFF &&\r
347                         (item < 0) && (o_ptr->number > 1))\r
348                 {\r
349                         msg_print(_("まずは杖を拾わなければ。", "You must first pick up the staffs."));\r
350                         return;\r
351                 }\r
352                 staff = (o_ptr->tval == TV_STAFF) ? _("杖", "staff") : _("魔法棒", "wand");\r
353 \r
354                 /* "Eat" charges */\r
355                 if (o_ptr->pval == 0)\r
356                 {\r
357                         msg_format(_("この%sにはもう魔力が残っていない。", "The %s has no charges left."), staff);\r
358                         o_ptr->ident |= (IDENT_EMPTY);\r
359 \r
360                         /* Combine / Reorder the pack (later) */\r
361                         p_ptr->notice |= (PN_COMBINE | PN_REORDER);\r
362                         p_ptr->window |= (PW_INVEN);\r
363 \r
364                         return;\r
365                 }\r
366                 msg_format(_("あなたは%sの魔力をエネルギー源として吸収した。", "You absorb mana of the %s as your energy."), staff);\r
367 \r
368                 /* Use a single charge */\r
369                 o_ptr->pval--;\r
370 \r
371                 /* Eat a charge */\r
372                 set_food(p_ptr->food + 5000);\r
373 \r
374                 /* XXX Hack -- unstack if necessary */\r
375                 if (o_ptr->tval == TV_STAFF &&\r
376                         (item >= 0) && (o_ptr->number > 1))\r
377                 {\r
378                         object_type forge;\r
379                         object_type *q_ptr;\r
380 \r
381                         /* Get local object */\r
382                         q_ptr = &forge;\r
383 \r
384                         /* Obtain a local object */\r
385                         object_copy(q_ptr, o_ptr);\r
386 \r
387                         /* Modify quantity */\r
388                         q_ptr->number = 1;\r
389 \r
390                         /* Restore the charges */\r
391                         o_ptr->pval++;\r
392 \r
393                         /* Unstack the used item */\r
394                         o_ptr->number--;\r
395                         p_ptr->total_weight -= q_ptr->weight;\r
396                         item = inven_carry(q_ptr);\r
397 \r
398                         /* Message */\r
399                         msg_format(_("杖をまとめなおした。", "You unstack your staff."));\r
400                 }\r
401 \r
402                 /* Describe charges in the pack */\r
403                 if (item >= 0)\r
404                 {\r
405                         inven_item_charges(item);\r
406                 }\r
407 \r
408                 /* Describe charges on the floor */\r
409                 else\r
410                 {\r
411                         floor_item_charges(0 - item);\r
412                 }\r
413 \r
414                 /* Window stuff */\r
415                 p_ptr->window |= (PW_INVEN | PW_EQUIP);\r
416 \r
417                 /* Don't eat a staff/wand itself */\r
418                 return;\r
419         }\r
420         else if ((prace_is_(RACE_DEMON) ||\r
421                 (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) &&\r
422                 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_CORPSE &&\r
423                         my_strchr("pht", r_info[o_ptr->pval].d_char)))\r
424         {\r
425                 /* Drain vitality of humanoids */\r
426                 char o_name[MAX_NLEN];\r
427                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));\r
428                 msg_format(_("%sは燃え上り灰になった。精力を吸収した気がする。", "%^s is burnt to ashes.  You absorb its vitality!"), o_name);\r
429                 (void)set_food(PY_FOOD_MAX - 1);\r
430         }\r
431         else if (prace_is_(RACE_SKELETON))\r
432         {\r
433 #if 0\r
434                 if (o_ptr->tval == TV_SKELETON ||\r
435                         (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))\r
436                 {\r
437                         msg_print(_("あなたは骨で自分の体を補った。", "Your body absorbs the bone."));\r
438                         set_food(p_ptr->food + 5000);\r
439                 }\r
440                 else\r
441 #endif\r
442 \r
443                         if (!((o_ptr->sval == SV_FOOD_WAYBREAD) ||\r
444                                 (o_ptr->sval < SV_FOOD_BISCUIT)))\r
445                         {\r
446                                 object_type forge;\r
447                                 object_type *q_ptr = &forge;\r
448 \r
449                                 msg_print(_("食べ物がアゴを素通りして落ちた!", "The food falls through your jaws!"));\r
450 \r
451                                 /* Create the item */\r
452                                 object_prep(q_ptr, lookup_kind(o_ptr->tval, o_ptr->sval));\r
453 \r
454                                 /* Drop the object from heaven */\r
455                                 (void)drop_near(q_ptr, -1, p_ptr->y, p_ptr->x);\r
456                         }\r
457                         else\r
458                         {\r
459                                 msg_print(_("食べ物がアゴを素通りして落ち、消えた!", "The food falls through your jaws and vanishes!"));\r
460                         }\r
461         }\r
462         else if (prace_is_(RACE_GOLEM) ||\r
463                 prace_is_(RACE_ZOMBIE) ||\r
464                 prace_is_(RACE_ENT) ||\r
465                 prace_is_(RACE_DEMON) ||\r
466                 prace_is_(RACE_ANDROID) ||\r
467                 prace_is_(RACE_SPECTRE) ||\r
468                 (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING))\r
469         {\r
470                 msg_print(_("生者の食物はあなたにとってほとんど栄養にならない。", "The food of mortals is poor sustenance for you."));\r
471                 set_food(p_ptr->food + ((o_ptr->pval) / 20));\r
472         }\r
473         else if (o_ptr->tval == TV_FOOD && o_ptr->sval == SV_FOOD_WAYBREAD)\r
474         {\r
475                 /* Waybread is always fully satisfying. */\r
476                 set_food(MAX(p_ptr->food, PY_FOOD_MAX - 1));\r
477         }\r
478         else\r
479         {\r
480                 /* Food can feed the player */\r
481                 (void)set_food(p_ptr->food + o_ptr->pval);\r
482         }\r
483 \r
484         /* Destroy a food in the pack */\r
485         if (item >= 0)\r
486         {\r
487                 inven_item_increase(item, -1);\r
488                 inven_item_describe(item);\r
489                 inven_item_optimize(item);\r
490         }\r
491 \r
492         /* Destroy a food on the floor */\r
493         else\r
494         {\r
495                 floor_item_increase(0 - item, -1);\r
496                 floor_item_describe(0 - item);\r
497                 floor_item_optimize(0 - item);\r
498         }\r
499 }\r
500 \r
501 \r
502 /*!\r
503  * @brief 食料を食べるコマンドのメインルーチン /\r
504  * Eat some food (from the pack or floor)\r
505  * @return なし\r
506  */\r
507 void do_cmd_eat_food(void)\r
508 {\r
509         OBJECT_IDX item;\r
510         cptr        q, s;\r
511 \r
512 \r
513         if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))\r
514         {\r
515                 set_action(ACTION_NONE);\r
516         }\r
517 \r
518         /* Restrict choices to food */\r
519         item_tester_hook = item_tester_hook_eatable;\r
520 \r
521         /* Get an item */\r
522         q = _("どれを食べますか? ", "Eat which item? ");\r
523         s = _("食べ物がない。", "You have nothing to eat.");\r
524 \r
525         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;\r
526 \r
527         /* Eat the object */\r
528         do_cmd_eat_food_aux(item);\r
529 }\r
530 \r