OSDN Git Service

[Fix] mutation-flag-types.h のインクルード関係
[hengbandforosx/hengbandosx.git] / src / inventory / inventory-damage.cpp
1 #include "inventory/inventory-damage.h"
2 #include "flavor/flavor-describer.h"
3 #include "flavor/object-flavor-types.h"
4 #include "inventory/inventory-object.h"
5 #include "inventory/inventory-slot-types.h"
6 #include "mind/mind-mirror-master.h"
7 #include "object-hook/hook-enchant.h"
8 #include "object-hook/hook-expendable.h"
9 #include "object/object-broken.h"
10 #include "object/object-info.h"
11 #include "object/object-stack.h"
12 #include "player/player-status.h"
13 #include "system/floor-type-definition.h"
14 #include "system/object-type-definition.h"
15 #include "system/player-type-definition.h"
16 #include "view/display-messages.h"
17
18 /*!
19  * @brief アイテムを指定確率で破損させる /
20  * Destroys a type of item on a given percent chance
21  * @param player_ptr プレーヤーへの参照ポインタ
22  * @param typ 破損判定関数ポインタ
23  * @param perc 基本確率
24  * @details
25  * Note that missiles are no longer necessarily all destroyed
26  * Destruction taken from "melee.c" code for "stealing".
27  * New-style wands and rods handled correctly. -LM-
28  */
29 void inventory_damage(player_type *player_ptr, inven_func typ, int perc)
30 {
31     INVENTORY_IDX i;
32     int j, amt;
33     object_type *o_ptr;
34     GAME_TEXT o_name[MAX_NLEN];
35
36     if (check_multishadow(player_ptr) || player_ptr->current_floor_ptr->inside_arena)
37         return;
38
39     /* Scan through the slots backwards */
40     for (i = 0; i < INVEN_PACK; i++) {
41         o_ptr = &player_ptr->inventory_list[i];
42         if (!o_ptr->k_idx)
43             continue;
44
45         /* Hack -- for now, skip artifacts */
46         if (object_is_artifact(o_ptr))
47             continue;
48
49         /* Give this item slot a shot at death */
50         if (!(*typ)(player_ptr, o_ptr))
51             continue;
52
53         /* Count the casualties */
54         for (amt = j = 0; j < o_ptr->number; ++j) {
55             if (randint0(100) < perc)
56                 amt++;
57         }
58
59         /* Some casualities */
60         if (!amt)
61             continue;
62
63         describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
64
65         msg_format(_("%s(%c)が%s壊れてしまった!", "%sour %s (%c) %s destroyed!"),
66 #ifdef JP
67             o_name, index_to_label(i), ((o_ptr->number > 1) ? ((amt == o_ptr->number) ? "全部" : (amt > 1 ? "何個か" : "一個")) : ""));
68 #else
69             ((o_ptr->number > 1) ? ((amt == o_ptr->number) ? "All of y" : (amt > 1 ? "Some of y" : "One of y")) : "Y"), o_name, index_to_label(i),
70             ((amt > 1) ? "were" : "was"));
71 #endif
72
73 #ifdef JP
74         if (is_echizen(player_ptr))
75             msg_print("やりやがったな!");
76         else if (player_ptr->pseikaku == PERSONALITY_CHARGEMAN) {
77             if (randint0(2) == 0)
78                 msg_print(_("ジュラル星人め!", ""));
79             else
80                 msg_print(_("弱い者いじめは止めるんだ!", ""));
81         }
82 #endif
83
84         /* Potions smash open */
85         if (object_is_potion(o_ptr)) {
86             (void)potion_smash_effect(player_ptr, 0, player_ptr->y, player_ptr->x, o_ptr->k_idx);
87         }
88
89         /* Reduce the charges of rods/wands */
90         reduce_charges(o_ptr, amt);
91
92         /* Destroy "amt" items */
93         inven_item_increase(player_ptr, i, -amt);
94         inven_item_optimize(player_ptr, i);
95     }
96 }