OSDN Git Service

[Refactor] #2124 Changed struct object_type to class ObjectType
[hengbandforosx/hengbandosx.git] / src / market / building-recharger.cpp
1 #include "market/building-recharger.h"
2 #include "autopick/autopick.h"
3 #include "core/asking-player.h"
4 #include "core/player-update-types.h"
5 #include "core/window-redrawer.h"
6 #include "flavor/flavor-describer.h"
7 #include "flavor/object-flavor-types.h"
8 #include "floor/floor-object.h"
9 #include "inventory/inventory-slot-types.h"
10 #include "market/building-util.h"
11 #include "object-enchant/special-object-flags.h"
12 #include "object-hook/hook-magic.h"
13 #include "object/item-tester-hooker.h"
14 #include "object/item-use-flags.h"
15 #include "object/object-kind.h"
16 #include "perception/object-perception.h"
17 #include "spell-kind/spells-perception.h"
18 #include "system/object-type-definition.h"
19 #include "system/player-type-definition.h"
20 #include "term/screen-processor.h"
21 #include "view/display-messages.h"
22
23 /*!
24  * @brief 魔道具の使用回数を回復させる施設のメインルーチン / Recharge rods, wands and staffs
25  * @details
26  * The player can select the number of charges to add\n
27  * (up to a limit), and the recharge never fails.\n
28  *\n
29  * The cost for rods depends on the level of the rod. The prices\n
30  * for recharging wands and staffs are dependent on the cost of\n
31  * the base-item.\n
32  * @param player_ptr プレイヤーへの参照ポインタ
33  */
34 void building_recharge(PlayerType *player_ptr)
35 {
36     msg_flag = false;
37     clear_bldg(4, 18);
38     prt(_("  再充填の費用はアイテムの種類によります。", "  The prices of recharge depend on the type."), 6, 0);
39
40     concptr q = _("どのアイテムに魔力を充填しますか? ", "Recharge which item? ");
41     concptr s = _("魔力を充填すべきアイテムがない。", "You have nothing to recharge.");
42
43     OBJECT_IDX item;
44     ObjectType *o_ptr;
45     o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), FuncItemTester(&ObjectType::is_rechargeable));
46     if (!o_ptr)
47         return;
48
49     object_kind *k_ptr;
50     k_ptr = &k_info[o_ptr->k_idx];
51
52     /*
53      * We don't want to give the player free info about
54      * the level of the item or the number of charges.
55      */
56     /* The item must be "known" */
57     char tmp_str[MAX_NLEN];
58     if (!o_ptr->is_known()) {
59         msg_format(_("充填する前に鑑定されている必要があります!", "The item must be identified first!"));
60         msg_print(nullptr);
61
62         if ((player_ptr->au >= 50) && get_check(_("$50で鑑定しますか? ", "Identify for 50 gold? ")))
63
64         {
65             player_ptr->au -= 50;
66             identify_item(player_ptr, o_ptr);
67             describe_flavor(player_ptr, tmp_str, o_ptr, 0);
68             msg_format(_("%s です。", "You have: %s."), tmp_str);
69
70             autopick_alter_item(player_ptr, item, false);
71             building_prt_gold(player_ptr);
72         }
73
74         return;
75     }
76
77     DEPTH lev = k_info[o_ptr->k_idx].level;
78     PRICE price;
79     if (o_ptr->tval == ItemKindType::ROD) {
80         if (o_ptr->timeout > 0) {
81             price = (lev * 50 * o_ptr->timeout) / k_ptr->pval;
82         } else {
83             price = 0;
84             msg_format(_("それは再充填する必要はありません。", "That doesn't need to be recharged."));
85             return;
86         }
87     } else if (o_ptr->tval == ItemKindType::STAFF) {
88         price = (k_info[o_ptr->k_idx].cost / 10) * o_ptr->number;
89         price = std::max(10, price);
90     } else {
91         price = (k_info[o_ptr->k_idx].cost / 10);
92         price = std::max(10, price);
93     }
94
95     if (o_ptr->tval == ItemKindType::WAND && (o_ptr->pval / o_ptr->number >= k_ptr->pval)) {
96         if (o_ptr->number > 1) {
97             msg_print(_("この魔法棒はもう充分に充填されています。", "These wands are already fully charged."));
98         } else {
99             msg_print(_("この魔法棒はもう充分に充填されています。", "This wand is already fully charged."));
100         }
101
102         return;
103     } else if (o_ptr->tval == ItemKindType::STAFF && o_ptr->pval >= k_ptr->pval) {
104         if (o_ptr->number > 1) {
105             msg_print(_("この杖はもう充分に充填されています。", "These staffs are already fully charged."));
106         } else {
107             msg_print(_("この杖はもう充分に充填されています。", "This staff is already fully charged."));
108         }
109
110         return;
111     }
112
113     if (player_ptr->au < price) {
114         describe_flavor(player_ptr, tmp_str, o_ptr, OD_NAME_ONLY);
115 #ifdef JP
116         msg_format("%sを再充填するには$%d 必要です!", tmp_str, price);
117 #else
118         msg_format("You need %d gold to recharge %s!", price, tmp_str);
119 #endif
120         return;
121     }
122
123     PARAMETER_VALUE charges;
124     if (o_ptr->tval == ItemKindType::ROD) {
125 #ifdef JP
126         if (get_check(format("そのロッドを$%d で再充填しますか?", price)))
127 #else
128         if (get_check(format("Recharge the %s for %d gold? ", ((o_ptr->number > 1) ? "rods" : "rod"), price)))
129 #endif
130
131         {
132             o_ptr->timeout = 0;
133         } else {
134             return;
135         }
136     } else {
137         int max_charges;
138         if (o_ptr->tval == ItemKindType::STAFF)
139             max_charges = k_ptr->pval - o_ptr->pval;
140         else
141             max_charges = o_ptr->number * k_ptr->pval - o_ptr->pval;
142
143         charges = (PARAMETER_VALUE)get_quantity(
144             format(_("一回分$%d で何回分充填しますか?", "Add how many charges for %d gold apiece? "), price), std::min(player_ptr->au / price, max_charges));
145
146         if (charges < 1)
147             return;
148
149         price *= charges;
150         o_ptr->pval += charges;
151         o_ptr->ident &= ~(IDENT_EMPTY);
152     }
153
154     describe_flavor(player_ptr, tmp_str, o_ptr, 0);
155 #ifdef JP
156     msg_format("%sを$%d で再充填しました。", tmp_str, price);
157 #else
158     msg_format("%^s %s recharged for %d gold.", tmp_str, ((o_ptr->number > 1) ? "were" : "was"), price);
159 #endif
160     player_ptr->update |= (PU_COMBINE | PU_REORDER);
161     player_ptr->window_flags |= (PW_INVEN);
162     player_ptr->au -= price;
163 }
164
165 /*!
166  * @brief 魔道具の使用回数を回復させる施設の一括処理向けサブルーチン / Recharge rods, wands and staffs
167  * @details
168  * The player can select the number of charges to add\n
169  * (up to a limit), and the recharge never fails.\n
170  *\n
171  * The cost for rods depends on the level of the rod. The prices\n
172  * for recharging wands and staffs are dependent on the cost of\n
173  * the base-item.\n
174  * @param player_ptr プレイヤーへの参照ポインタ
175  */
176 void building_recharge_all(PlayerType *player_ptr)
177 {
178     msg_flag = false;
179     clear_bldg(4, 18);
180     prt(_("  再充填の費用はアイテムの種類によります。", "  The prices of recharge depend on the type."), 6, 0);
181
182     PRICE price = 0;
183     PRICE total_cost = 0;
184     for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
185         ObjectType *o_ptr;
186         o_ptr = &player_ptr->inventory_list[i];
187
188         if ((o_ptr->tval < ItemKindType::STAFF) || (o_ptr->tval > ItemKindType::ROD))
189             continue;
190         if (!o_ptr->is_known())
191             total_cost += 50;
192
193         DEPTH lev = k_info[o_ptr->k_idx].level;
194         object_kind *k_ptr;
195         k_ptr = &k_info[o_ptr->k_idx];
196
197         switch (o_ptr->tval) {
198         case ItemKindType::ROD:
199             price = (lev * 50 * o_ptr->timeout) / k_ptr->pval;
200             break;
201
202         case ItemKindType::STAFF:
203             price = (k_info[o_ptr->k_idx].cost / 10) * o_ptr->number;
204             price = std::max(10, price);
205             price = (k_ptr->pval - o_ptr->pval) * price;
206             break;
207
208         case ItemKindType::WAND:
209             price = (k_info[o_ptr->k_idx].cost / 10);
210             price = std::max(10, price);
211             price = (o_ptr->number * k_ptr->pval - o_ptr->pval) * price;
212             break;
213
214         default:
215             break;
216         }
217
218         if (price > 0)
219             total_cost += price;
220     }
221
222     if (!total_cost) {
223         msg_print(_("充填する必要はありません。", "No need to recharge."));
224         msg_print(nullptr);
225         return;
226     }
227
228     if (player_ptr->au < total_cost) {
229         msg_format(_("すべてのアイテムを再充填するには$%d 必要です!", "You need %d gold to recharge all items!"), total_cost);
230         msg_print(nullptr);
231         return;
232     }
233
234     if (!get_check(format(_("すべてのアイテムを $%d で再充填しますか?", "Recharge all items for %d gold? "), total_cost)))
235         return;
236
237     for (INVENTORY_IDX i = 0; i < INVEN_PACK; i++) {
238         ObjectType *o_ptr;
239         o_ptr = &player_ptr->inventory_list[i];
240         object_kind *k_ptr;
241         k_ptr = &k_info[o_ptr->k_idx];
242
243         if ((o_ptr->tval < ItemKindType::STAFF) || (o_ptr->tval > ItemKindType::ROD))
244             continue;
245
246         if (!o_ptr->is_known()) {
247             identify_item(player_ptr, o_ptr);
248             autopick_alter_item(player_ptr, i, false);
249         }
250
251         switch (o_ptr->tval) {
252         case ItemKindType::ROD:
253             o_ptr->timeout = 0;
254             break;
255         case ItemKindType::STAFF:
256             if (o_ptr->pval < k_ptr->pval)
257                 o_ptr->pval = k_ptr->pval;
258
259             o_ptr->ident &= ~(IDENT_EMPTY);
260             break;
261         case ItemKindType::WAND:
262             if (o_ptr->pval < o_ptr->number * k_ptr->pval)
263                 o_ptr->pval = o_ptr->number * k_ptr->pval;
264
265             o_ptr->ident &= ~(IDENT_EMPTY);
266             break;
267
268         default:
269             break;
270         }
271     }
272
273     msg_format(_("$%d で再充填しました。", "You pay %d gold."), total_cost);
274     msg_print(nullptr);
275     player_ptr->update |= (PU_COMBINE | PU_REORDER);
276     player_ptr->window_flags |= (PW_INVEN);
277     player_ptr->au -= total_cost;
278 }