OSDN Git Service

[Refactor] player_type から total_weight を削除し calc_inventory_weight() を反映. / Remove...
[hengband/hengband.git] / src / cmd-item / cmd-equipment.c
1 #include "cmd-item/cmd-equipment.h"
2 #include "action/weapon-shield.h"
3 #include "art-definition/art-protector-types.h"
4 #include "autopick/autopick.h"
5 #include "core/asking-player.h"
6 #include "core/player-redraw-types.h"
7 #include "core/player-update-types.h"
8 #include "core/window-redrawer.h"
9 #include "dungeon/quest.h" // todo \88á\98a\8a´\81A\89½\8cÌ\83A\83C\83e\83\80\82ð\91\95\94õ\82·\82é\82Æ\83N\83G\83X\83g\82Ì\90¬\8c÷\94»\92è\82ª\91\96\82é\82Ì\82©\81H.
10 #include "flavor/flavor-describer.h"
11 #include "flavor/object-flavor-types.h"
12 #include "floor/floor-object.h"
13 #include "game-option/birth-options.h"
14 #include "game-option/input-options.h"
15 #include "inventory/inventory-describer.h"
16 #include "inventory/inventory-object.h"
17 #include "inventory/inventory-slot-types.h"
18 #include "io/input-key-acceptor.h"
19 #include "io/input-key-requester.h"
20 #include "object-enchant/item-feeling.h"
21 #include "object-enchant/special-object-flags.h"
22 #include "object-enchant/trc-types.h"
23 #include "object-hook/hook-armor.h"
24 #include "object-hook/hook-checker.h"
25 #include "object-hook/hook-weapon.h"
26 #include "object/item-tester-hooker.h"
27 #include "object/item-use-flags.h"
28 #include "object/object-generator.h"
29 #include "object/object-info.h"
30 #include "object/object-mark-types.h"
31 #include "perception/object-perception.h"
32 #include "player/attack-defense-types.h"
33 #include "player-info/avatar.h"
34 #include "player/special-defense-types.h"
35 #include "racial/racial-android.h"
36 #include "spell-kind/spells-perception.h"
37 #include "status/action-setter.h"
38 #include "status/shape-changer.h"
39 #include "system/object-type-definition.h"
40 #include "term/screen-processor.h"
41 #include "util/int-char-converter.h"
42 #include "view/display-inventory.h"
43 #include "view/display-messages.h"
44
45 /*!
46  * @brief \91\95\94õ\88ê\97\97\82ð\95\\8e¦\82·\82é\83R\83}\83\93\83h\82Ì\83\81\83C\83\93\83\8b\81[\83`\83\93 / Display equipment
47  * @return \82È\82µ
48  */
49 void do_cmd_equip(player_type *creature_ptr)
50 {
51     char out_val[160];
52     command_wrk = TRUE;
53     if (easy_floor)
54         command_wrk = USE_EQUIP;
55
56     screen_save();
57     (void)show_equipment(creature_ptr, 0, USE_FULL, 0);
58     WEIGHT weight = calc_inventory_weight(creature_ptr);
59     WEIGHT weight_lim = weight_limit(creature_ptr);
60 #ifdef JP
61     sprintf(out_val, "\91\95\94õ\81\8d\87\8cv %3d.%1d kg (\8cÀ\8aE\82Ì%ld%%) \83R\83}\83\93\83h: ", (int)lbtokg1(weight), (int)lbtokg2(weight), (long int)((weight * 100) / weight_lim));
62 #else
63     sprintf(out_val, "Equipment: carrying %d.%d pounds (%ld%% of capacity). Command: ", (int)(weight / 10), (int)(weight % 10),
64         (long int)((weight * 100) / weight_lim);
65 #endif
66
67     prt(out_val, 0, 0);
68     command_new = inkey();
69     screen_load();
70
71     if (command_new != ESCAPE) {
72         command_see = TRUE;
73         return;
74     }
75
76     TERM_LEN wid, hgt;
77     term_get_size(&wid, &hgt);
78     command_new = 0;
79     command_gap = wid - 30;
80 }
81
82 bool select_ring_slot = FALSE;
83
84 /*!
85  * @brief \91\95\94õ\82·\82é\83R\83}\83\93\83h\82Ì\83\81\83C\83\93\83\8b\81[\83`\83\93 / Wield or wear a single item from the pack or floor
86  * @param creature_ptr \83v\83\8c\81[\83\84\81[\82Ö\82Ì\8eQ\8fÆ\83|\83C\83\93\83^
87  * @return \82È\82µ
88  */
89 void do_cmd_wield(player_type *creature_ptr)
90 {
91     OBJECT_IDX item, slot;
92     object_type forge;
93     object_type *q_ptr;
94     object_type *o_ptr;
95     concptr act;
96     GAME_TEXT o_name[MAX_NLEN];
97     OBJECT_IDX need_switch_wielding = 0;
98     if (creature_ptr->special_defense & KATA_MUSOU)
99         set_action(creature_ptr, ACTION_NONE);
100
101     item_tester_hook = item_tester_hook_wear;
102     concptr q = _("\82Ç\82ê\82ð\91\95\94õ\82µ\82Ü\82·\82©? ", "Wear/Wield which item? ");
103     concptr s = _("\91\95\94õ\89Â\94\\82È\83A\83C\83e\83\80\82ª\82È\82¢\81B", "You have nothing you can wear or wield.");
104     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
105     if (!o_ptr)
106         return;
107
108     slot = wield_slot(creature_ptr, o_ptr);
109
110     switch (o_ptr->tval) {
111     case TV_CAPTURE:
112     case TV_SHIELD:
113     case TV_CARD:
114         if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM)) {
115             item_tester_hook = item_tester_hook_melee_weapon;
116             q = _("\82Ç\82¿\82ç\82Ì\95\90\8aí\82Æ\8eæ\82è\91Ö\82¦\82Ü\82·\82©?", "Replace which weapon? ");
117             s = _("\82¨\82Á\82Æ\81B", "Oops.");
118             if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), 0))
119                 return;
120
121             if (slot == INVEN_RARM)
122                 need_switch_wielding = INVEN_LARM;
123         } else if (has_melee_weapon(creature_ptr, INVEN_LARM))
124             slot = INVEN_RARM;
125         else if (creature_ptr->inventory_list[INVEN_RARM].k_idx && !object_is_melee_weapon(&creature_ptr->inventory_list[INVEN_RARM])
126             && creature_ptr->inventory_list[INVEN_LARM].k_idx && !object_is_melee_weapon(&creature_ptr->inventory_list[INVEN_LARM])) {
127             item_tester_hook = item_tester_hook_mochikae;
128             q = _("\82Ç\82¿\82ç\82Ì\8eè\82É\91\95\94õ\82µ\82Ü\82·\82©?", "Equip which hand? ");
129             s = _("\82¨\82Á\82Æ\81B", "Oops.");
130             if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP), 0))
131                 return;
132         }
133
134         break;
135     case TV_DIGGING:
136     case TV_HAFTED:
137     case TV_POLEARM:
138     case TV_SWORD:
139         if (slot == INVEN_LARM) {
140             if (!get_check(_("\93ñ\93\81\97¬\82Å\90í\82¢\82Ü\82·\82©\81H", "Dual wielding? ")))
141                 slot = INVEN_RARM;
142         } else if (!creature_ptr->inventory_list[INVEN_RARM].k_idx && has_melee_weapon(creature_ptr, INVEN_LARM)) {
143             if (!get_check(_("\93ñ\93\81\97¬\82Å\90í\82¢\82Ü\82·\82©\81H", "Dual wielding? ")))
144                 slot = INVEN_LARM;
145         } else if (creature_ptr->inventory_list[INVEN_LARM].k_idx && creature_ptr->inventory_list[INVEN_RARM].k_idx) {
146             item_tester_hook = item_tester_hook_mochikae;
147             q = _("\82Ç\82¿\82ç\82Ì\8eè\82É\91\95\94õ\82µ\82Ü\82·\82©?", "Equip which hand? ");
148             s = _("\82¨\82Á\82Æ\81B", "Oops.");
149             if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP), 0))
150                 return;
151
152             if ((slot == INVEN_LARM) && !has_melee_weapon(creature_ptr, INVEN_RARM))
153                 need_switch_wielding = INVEN_RARM;
154         }
155
156         break;
157     case TV_RING:
158         if (creature_ptr->inventory_list[INVEN_LEFT].k_idx && creature_ptr->inventory_list[INVEN_RIGHT].k_idx)
159             q = _("\82Ç\82¿\82ç\82Ì\8ew\97Ö\82Æ\8eæ\82è\91Ö\82¦\82Ü\82·\82©?", "Replace which ring? ");
160         else
161             q = _("\82Ç\82¿\82ç\82Ì\8eè\82É\91\95\94õ\82µ\82Ü\82·\82©?", "Equip which hand? ");
162
163         s = _("\82¨\82Á\82Æ\81B", "Oops.");
164         select_ring_slot = TRUE;
165         if (!choose_object(creature_ptr, &slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), 0)) {
166             select_ring_slot = FALSE;
167             return;
168         }
169
170         select_ring_slot = FALSE;
171         break;
172     }
173
174     if (object_is_cursed(&creature_ptr->inventory_list[slot])) {
175         describe_flavor(creature_ptr, o_name, &creature_ptr->inventory_list[slot], OD_OMIT_PREFIX | OD_NAME_ONLY);
176 #ifdef JP
177         msg_format("%s%s\82Í\8eô\82í\82ê\82Ä\82¢\82é\82æ\82¤\82¾\81B", describe_use(creature_ptr, slot), o_name);
178 #else
179         msg_format("The %s you are %s appears to be cursed.", o_name, describe_use(creature_ptr, slot));
180 #endif
181         return;
182     }
183
184     if (confirm_wear
185         && ((object_is_cursed(o_ptr) && object_is_known(o_ptr))
186             || ((o_ptr->ident & IDENT_SENSE) && (FEEL_BROKEN <= o_ptr->feeling) && (o_ptr->feeling <= FEEL_CURSED)))) {
187         char dummy[MAX_NLEN + 80];
188         describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
189         sprintf(dummy, _("\96{\93\96\82É%s{\8eô\82í\82ê\82Ä\82¢\82é}\82ð\8eg\82¢\82Ü\82·\82©\81H", "Really use the %s {cursed}? "), o_name);
190
191         if (!get_check(dummy))
192             return;
193     }
194
195     if ((o_ptr->name1 == ART_STONEMASK) && object_is_known(o_ptr) && (creature_ptr->prace != RACE_VAMPIRE) && (creature_ptr->prace != RACE_ANDROID)) {
196         char dummy[MAX_NLEN + 100];
197         describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
198         sprintf(dummy,
199             _("%s\82ð\91\95\94õ\82·\82é\82Æ\8bz\8c\8c\8bS\82É\82È\82è\82Ü\82·\81B\82æ\82ë\82µ\82¢\82Å\82·\82©\81H", "%s will transforms you into a vampire permanently when equiped. Do you become a vampire?"),
200             o_name);
201
202         if (!get_check(dummy))
203             return;
204     }
205
206     if (need_switch_wielding && !object_is_cursed(&creature_ptr->inventory_list[need_switch_wielding])) {
207         object_type *slot_o_ptr = &creature_ptr->inventory_list[slot];
208         object_type *switch_o_ptr = &creature_ptr->inventory_list[need_switch_wielding];
209         object_type object_tmp;
210         object_type *otmp_ptr = &object_tmp;
211         GAME_TEXT switch_name[MAX_NLEN];
212         describe_flavor(creature_ptr, switch_name, switch_o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
213         object_copy(otmp_ptr, switch_o_ptr);
214         object_copy(switch_o_ptr, slot_o_ptr);
215         object_copy(slot_o_ptr, otmp_ptr);
216         msg_format(_("%s\82ð%s\82É\8d\\82¦\82È\82¨\82µ\82½\81B", "You wield %s at %s hand."), switch_name,
217             (slot == INVEN_RARM) ? (left_hander ? _("\8d\8eè", "left") : _("\89E\8eè", "right")) : (left_hander ? _("\89E\8eè", "right") : _("\8d\8eè", "left")));
218         slot = need_switch_wielding;
219     }
220
221     check_find_art_quest_completion(creature_ptr, o_ptr);
222     if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
223         identify_item(creature_ptr, o_ptr);
224         autopick_alter_item(creature_ptr, item, FALSE);
225     }
226
227     take_turn(creature_ptr, 100);
228     q_ptr = &forge;
229     object_copy(q_ptr, o_ptr);
230     q_ptr->number = 1;
231     if (item >= 0) {
232         inven_item_increase(creature_ptr, item, -1);
233         inven_item_optimize(creature_ptr, item);
234     } else {
235         floor_item_increase(creature_ptr->current_floor_ptr, 0 - item, -1);
236         floor_item_optimize(creature_ptr, 0 - item);
237     }
238
239     o_ptr = &creature_ptr->inventory_list[slot];
240     if (o_ptr->k_idx)
241         (void)inven_takeoff(creature_ptr, slot, 255);
242
243     object_copy(o_ptr, q_ptr);
244     o_ptr->marked |= OM_TOUCHED;
245     creature_ptr->equip_cnt++;
246
247 #define STR_WIELD_RARM _("%s(%c)\82ð\89E\8eè\82É\91\95\94õ\82µ\82½\81B", "You are wielding %s (%c) in your right hand.")
248 #define STR_WIELD_LARM _("%s(%c)\82ð\8d\8eè\82É\91\95\94õ\82µ\82½\81B", "You are wielding %s (%c) in your left hand.")
249 #define STR_WIELD_ARMS _("%s(%c)\82ð\97¼\8eè\82Å\8d\\82¦\82½\81B", "You are wielding %s (%c) with both hands.")
250
251     switch (slot) {
252     case INVEN_RARM:
253         if (object_allow_two_hands_wielding(o_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_LARM) && can_two_hands_wielding(creature_ptr))
254             act = STR_WIELD_ARMS;
255         else
256             act = (left_hander ? STR_WIELD_LARM : STR_WIELD_RARM);
257
258         break;
259     case INVEN_LARM:
260         if (object_allow_two_hands_wielding(o_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_RARM) && can_two_hands_wielding(creature_ptr))
261             act = STR_WIELD_ARMS;
262         else
263             act = (left_hander ? STR_WIELD_RARM : STR_WIELD_LARM);
264
265         break;
266     case INVEN_BOW:
267         act = _("%s(%c)\82ð\8eË\8c\82\97p\82É\91\95\94õ\82µ\82½\81B", "You are shooting with %s (%c).");
268         break;
269     case INVEN_LITE:
270         act = _("%s(%c)\82ð\8cõ\8c¹\82É\82µ\82½\81B", "Your light source is %s (%c).");
271         break;
272     default:
273         act = _("%s(%c)\82ð\91\95\94õ\82µ\82½\81B", "You are wearing %s (%c).");
274         break;
275     }
276
277     describe_flavor(creature_ptr, o_name, o_ptr, 0);
278     msg_format(act, o_name, index_to_label(slot));
279     if (object_is_cursed(o_ptr)) {
280         msg_print(_("\82¤\82í\81\82·\82³\82Ü\82\82­\97â\82½\82¢\81I", "Oops! It feels deathly cold!"));
281         chg_virtue(creature_ptr, V_HARMONY, -1);
282         o_ptr->ident |= (IDENT_SENSE);
283     }
284
285     if ((o_ptr->name1 == ART_STONEMASK) && (creature_ptr->prace != RACE_VAMPIRE) && (creature_ptr->prace != RACE_ANDROID))
286         change_race(creature_ptr, RACE_VAMPIRE, "");
287
288     creature_ptr->update |= PU_BONUS | PU_TORCH | PU_MANA;
289     creature_ptr->redraw |= PR_EQUIPPY;
290     creature_ptr->window |= PW_INVEN | PW_EQUIP | PW_PLAYER;
291     calc_android_exp(creature_ptr);
292 }
293
294 /*!
295  * @brief \91\95\94õ\82ð\8aO\82·\83R\83}\83\93\83h\82Ì\83\81\83C\83\93\83\8b\81[\83`\83\93 / Take off an item
296  * @return \82È\82µ
297  */
298 void do_cmd_takeoff(player_type *creature_ptr)
299 {
300     OBJECT_IDX item;
301     object_type *o_ptr;
302     if (creature_ptr->special_defense & KATA_MUSOU)
303         set_action(creature_ptr, ACTION_NONE);
304
305     concptr q = _("\82Ç\82ê\82ð\91\95\94õ\82©\82ç\82Í\82¸\82µ\82Ü\82·\82©? ", "Take off which item? ");
306     concptr s = _("\82Í\82¸\82¹\82é\91\95\94õ\82ª\82È\82¢\81B", "You are not wearing anything to take off.");
307     o_ptr = choose_object(creature_ptr, &item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), 0);
308     if (!o_ptr)
309         return;
310
311     if (object_is_cursed(o_ptr)) {
312         if ((o_ptr->curse_flags & TRC_PERMA_CURSE) || (creature_ptr->pclass != CLASS_BERSERKER)) {
313             msg_print(_("\82Ó\81[\82Þ\81A\82Ç\82¤\82â\82ç\8eô\82í\82ê\82Ä\82¢\82é\82æ\82¤\82¾\81B", "Hmmm, it seems to be cursed."));
314             return;
315         }
316
317         if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && one_in_(7)) || one_in_(4)) {
318             msg_print(_("\8eô\82í\82ê\82½\91\95\94õ\82ð\97Í\82Ã\82­\82Å\94\8d\82ª\82µ\82½\81I", "You tore off a piece of cursed equipment by sheer strength!"));
319             o_ptr->ident |= (IDENT_SENSE);
320             o_ptr->curse_flags = 0L;
321             o_ptr->feeling = FEEL_NONE;
322             creature_ptr->update |= PU_BONUS;
323             creature_ptr->window |= PW_EQUIP;
324             msg_print(_("\8eô\82¢\82ð\91Å\82¿\94j\82Á\82½\81B", "You break the curse."));
325         } else {
326             msg_print(_("\91\95\94õ\82ð\8aO\82¹\82È\82©\82Á\82½\81B", "You couldn't remove the equipment."));
327             take_turn(creature_ptr, 50);
328             return;
329         }
330     }
331
332     take_turn(creature_ptr, 50);
333     (void)inven_takeoff(creature_ptr, item, 255);
334     verify_equip_slot(creature_ptr, item);
335     calc_android_exp(creature_ptr);
336     creature_ptr->redraw |= PR_EQUIPPY;
337 }