OSDN Git Service

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