OSDN Git Service

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