OSDN Git Service

autopick.cの関数を外部から呼ぶ部分を簡略化。なるべくカプセル化する。
[hengband/hengband.git] / src / cmd3.c
1 /* File: cmd3.c */
2
3 /* Purpose: Inventory commands */
4
5 /*
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  */
12
13 #include "angband.h"
14
15
16
17 /*
18  * Display inventory
19  */
20 void do_cmd_inven(void)
21 {
22         char out_val[160];
23
24
25         /* Note that we are in "inventory" mode */
26         command_wrk = FALSE;
27
28 #ifdef ALLOW_EASY_FLOOR
29
30         /* Note that we are in "inventory" mode */
31         if (easy_floor) command_wrk = (USE_INVEN);
32
33 #endif /* ALLOW_EASY_FLOOR */
34
35         /* Save screen */
36         screen_save();
37
38         /* Hack -- show empty slots */
39         item_tester_full = TRUE;
40
41         /* Display the inventory */
42         (void)show_inven(0);
43
44         /* Hack -- hide empty slots */
45         item_tester_full = FALSE;
46
47 #ifdef JP
48         sprintf(out_val, "»ý¤Áʪ¡§ ¹ç·× %3d.%1d kg (¸Â³¦¤Î%ld%%) ¥³¥Þ¥ó¥É: ",
49             lbtokg1(p_ptr->total_weight) , lbtokg2(p_ptr->total_weight) ,
50             (p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) 
51 / 2));
52 #else
53         sprintf(out_val, "Inventory: carrying %d.%d pounds (%ld%% of capacity). Command: ",
54             (int)(p_ptr->total_weight / 10), (int)(p_ptr->total_weight % 10),
55             (p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2));
56 #endif
57
58
59         /* Get a command */
60         prt(out_val, 0, 0);
61
62         /* Get a new command */
63         command_new = inkey();
64
65         /* Load screen */
66         screen_load();
67
68
69         /* Process "Escape" */
70         if (command_new == ESCAPE)
71         {
72                 int wid, hgt;
73
74                 /* Get size */
75                 Term_get_size(&wid, &hgt);
76
77                 /* Reset stuff */
78                 command_new = 0;
79                 command_gap = wid - 30;
80         }
81
82         /* Process normal keys */
83         else
84         {
85                 /* Hack -- Use "display" mode */
86                 command_see = TRUE;
87         }
88 }
89
90
91 /*
92  * Display equipment
93  */
94 void do_cmd_equip(void)
95 {
96         char out_val[160];
97
98
99         /* Note that we are in "equipment" mode */
100         command_wrk = TRUE;
101
102 #ifdef ALLOW_EASY_FLOOR
103
104         /* Note that we are in "equipment" mode */
105         if (easy_floor) command_wrk = (USE_EQUIP);
106
107 #endif /* ALLOW_EASY_FLOOR  */
108
109         /* Save the screen */
110         screen_save();
111
112         /* Hack -- show empty slots */
113         item_tester_full = TRUE;
114
115         /* Display the equipment */
116         (void)show_equip(0);
117
118         /* Hack -- undo the hack above */
119         item_tester_full = FALSE;
120
121         /* Build a prompt */
122 #ifdef JP
123         sprintf(out_val, "ÁõÈ÷¡§ ¹ç·× %3d.%1d kg (¸Â³¦¤Î%ld%%) ¥³¥Þ¥ó¥É: ",
124             lbtokg1(p_ptr->total_weight) , lbtokg2(p_ptr->total_weight) ,
125             (p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) 
126 / 2));
127 #else
128         sprintf(out_val, "Equipment: carrying %d.%d pounds (%ld%% of capacity). Command: ",
129             (int)(p_ptr->total_weight / 10), (int)(p_ptr->total_weight % 10),
130             (p_ptr->total_weight * 100) / ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2));
131 #endif
132
133
134         /* Get a command */
135         prt(out_val, 0, 0);
136
137         /* Get a new command */
138         command_new = inkey();
139
140         /* Restore the screen */
141         screen_load();
142
143
144         /* Process "Escape" */
145         if (command_new == ESCAPE)
146         {
147                 int wid, hgt;
148
149                 /* Get size */
150                 Term_get_size(&wid, &hgt);
151
152                 /* Reset stuff */
153                 command_new = 0;
154                 command_gap = wid - 30;
155         }
156
157         /* Process normal keys */
158         else
159         {
160                 /* Enter "display" mode */
161                 command_see = TRUE;
162         }
163 }
164
165
166 /*
167  * The "wearable" tester
168  */
169 static bool item_tester_hook_wear(object_type *o_ptr)
170 {
171         if ((o_ptr->tval == TV_SOFT_ARMOR) && (o_ptr->sval == SV_ABUNAI_MIZUGI))
172                 if (p_ptr->psex == SEX_MALE) return FALSE;
173
174         /* Check for a usable slot */
175         if (wield_slot(o_ptr) >= INVEN_RARM) return (TRUE);
176
177         /* Assume not wearable */
178         return (FALSE);
179 }
180
181
182 static bool item_tester_hook_mochikae(object_type *o_ptr)
183 {
184         /* Check for a usable slot */
185         if (((o_ptr->tval >= TV_DIGGING) && (o_ptr->tval <= TV_SWORD)) ||
186             (o_ptr->tval == TV_SHIELD) || (o_ptr->tval == TV_CAPTURE) ||
187             (o_ptr->tval == TV_CARD)) return (TRUE);
188
189         /* Assume not wearable */
190         return (FALSE);
191 }
192
193
194 static bool item_tester_hook_melee_weapon(object_type *o_ptr)
195 {
196         /* Check for a usable slot */
197         if ((o_ptr->tval >= TV_DIGGING) && (o_ptr->tval <= TV_SWORD))return (TRUE);
198
199         /* Assume not wearable */
200         return (FALSE);
201 }
202
203
204 /*
205  * Wield or wear a single item from the pack or floor
206  */
207 void do_cmd_wield(void)
208 {
209         int i, item, slot;
210
211         object_type forge;
212         object_type *q_ptr;
213
214         object_type *o_ptr;
215
216         cptr act;
217
218         char o_name[MAX_NLEN];
219
220         cptr q, s;
221
222         if (p_ptr->special_defense & KATA_MUSOU)
223         {
224                 set_action(ACTION_NONE);
225         }
226
227         /* Restrict the choices */
228         item_tester_hook = item_tester_hook_wear;
229
230         /* Get an item */
231 #ifdef JP
232         q = "¤É¤ì¤òÁõÈ÷¤·¤Þ¤¹¤«? ";
233         s = "ÁõÈ÷²Äǽ¤Ê¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
234 #else
235         q = "Wear/Wield which item? ";
236         s = "You have nothing you can wear or wield.";
237 #endif
238
239         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
240
241         /* Get the item (in the pack) */
242         if (item >= 0)
243         {
244                 o_ptr = &inventory[item];
245         }
246
247         /* Get the item (on the floor) */
248         else
249         {
250                 o_ptr = &o_list[0 - item];
251         }
252
253
254         /* Check the slot */
255         slot = wield_slot(o_ptr);
256
257         switch (o_ptr->tval)
258         {
259         /* Shields and some misc. items */
260         case TV_CAPTURE:
261         case TV_SHIELD:
262         case TV_CARD:
263                 if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
264                 {
265                         /* Restrict the choices */
266                         item_tester_hook = item_tester_hook_melee_weapon;
267                         item_tester_no_ryoute = TRUE;
268
269                         /* Choose a weapon from the equipment only */
270 #ifdef JP
271                         q = "¤É¤Á¤é¤ÎÉð´ï¤È¼è¤êÂؤ¨¤Þ¤¹¤«?";
272                         s = "¤ª¤Ã¤È¡£";
273 #else
274                         q = "Replace which weapon? ";
275                         s = "Oops.";
276 #endif
277
278                         if (!get_item(&slot, q, s, (USE_EQUIP))) return;
279                         if ((slot == INVEN_RARM) && !cursed_p(&inventory[INVEN_RARM]))
280                         {
281                                 object_type *or_ptr = &inventory[INVEN_RARM];
282                                 object_type *ol_ptr = &inventory[INVEN_LARM];
283                                 object_type object_tmp;
284                                 object_type *otmp_ptr = &object_tmp;
285                                 char ol_name[MAX_NLEN];
286
287                                 object_desc(ol_name, ol_ptr, FALSE, 0);
288
289                                 object_copy(otmp_ptr, ol_ptr);
290                                 object_copy(ol_ptr, or_ptr);
291                                 object_copy(or_ptr, otmp_ptr);
292 #ifdef JP
293                                 msg_format("%s¤ò%s¤Ë¹½¤¨¤Ê¤ª¤·¤¿¡£", ol_name, left_hander ? "º¸¼ê" : "±¦¼ê");
294 #else
295                                 msg_format("You wield %s at %s hand.", ol_name, left_hander ? "left" : "right");
296 #endif
297
298                                 slot = INVEN_LARM;
299                         }
300                 }
301                 break;
302
303         /* Melee weapons */
304         case TV_DIGGING:
305         case TV_HAFTED:
306         case TV_POLEARM:
307         case TV_SWORD:
308                 /* Asking for dual wielding */
309                 if (slot == INVEN_LARM)
310                 {
311 #ifdef JP
312                         if (!get_check("ÆóÅáή¤ÇÀ襤¤Þ¤¹¤«¡©")) slot = INVEN_RARM;
313 #else
314                         if (!get_check("Dual wielding? ")) slot = INVEN_RARM;
315 #endif
316                 }
317
318                 /* Both arms are already used */
319                 else if (inventory[INVEN_LARM].k_idx && inventory[INVEN_RARM].k_idx)
320                 {
321                         /* Restrict the choices */
322                         item_tester_hook = item_tester_hook_mochikae;
323
324                         /* Choose a hand */
325 #ifdef JP
326                         q = "¤É¤Á¤é¤Î¼ê¤ËÁõÈ÷¤·¤Þ¤¹¤«?";
327                         s = "¤ª¤Ã¤È¡£";
328 #else
329                         q = "Equip which hand? ";
330                         s = "Oops.";
331 #endif
332
333                         if (!get_item(&slot, q, s, (USE_EQUIP))) return;
334                 }
335                 break;
336
337         /* Rings */
338         case TV_RING:
339                 if (inventory[INVEN_LEFT].k_idx && inventory[INVEN_RIGHT].k_idx)
340                 {
341                         /* Restrict the choices */
342                         item_tester_tval = TV_RING;
343                         item_tester_no_ryoute = TRUE;
344
345                         /* Choose a ring from the equipment only */
346 #ifdef JP
347                         q = "¤É¤Á¤é¤Î»ØÎؤȼè¤êÂؤ¨¤Þ¤¹¤«?";
348                         s = "¤ª¤Ã¤È¡£";
349 #else
350                         q = "Replace which ring? ";
351                         s = "Oops.";
352 #endif
353
354                         if (!get_item(&slot, q, s, (USE_EQUIP))) return;
355                 }
356                 break;
357         }
358
359         /* Prevent wielding into a cursed slot */
360         if (cursed_p(&inventory[slot]))
361         {
362                 /* Describe it */
363                 object_desc(o_name, &inventory[slot], FALSE, 0);
364
365                 /* Message */
366 #ifdef JP
367                 msg_format("%s%s¤Ï¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£",
368                            describe_use(slot) , o_name );
369 #else
370                 msg_format("The %s you are %s appears to be cursed.",
371                            o_name, describe_use(slot));
372 #endif
373
374                 /* Cancel the command */
375                 return;
376         }
377
378         if (cursed_p(o_ptr) && confirm_wear &&
379             (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
380         {
381                 char dummy[MAX_NLEN+80];
382
383                 /* Describe it */
384                 object_desc(o_name, o_ptr, FALSE, 0);
385
386 #ifdef JP
387 sprintf(dummy, "ËÜÅö¤Ë%s{¼ö¤ï¤ì¤Æ¤¤¤ë}¤ò»È¤¤¤Þ¤¹¤«¡©", o_name);
388 #else
389                 sprintf(dummy, "Really use the %s {cursed}? ", o_name);
390 #endif
391
392                 if (!get_check(dummy)) return;
393         }
394
395         if ((o_ptr->name1 == ART_STONEMASK) && object_known_p(o_ptr) && (p_ptr->prace != RACE_VAMPIRE) && (p_ptr->prace != RACE_ANDROID))
396         {
397                 char dummy[MAX_NLEN+80];
398
399                 /* Describe it */
400                 object_desc(o_name, o_ptr, FALSE, 0);
401
402 #ifdef JP
403 sprintf(dummy, "%s¤òÁõÈ÷¤¹¤ë¤ÈµÛ·ìµ´¤Ë¤Ê¤ê¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©", o_name);
404 #else
405                 msg_format("%s will transforms you into a vampire permanently when equiped.", o_name);
406                 sprintf(dummy, "Do you become a vampire?");
407 #endif
408
409                 if (!get_check(dummy)) return;
410         }
411
412         /* Check if completed a quest */
413         for (i = 0; i < max_quests; i++)
414         {
415                 if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
416                     (quest[i].status == QUEST_STATUS_TAKEN) &&
417                     (quest[i].k_idx == o_ptr->name1))
418                 {
419                         if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
420                         quest[i].status = QUEST_STATUS_COMPLETED;
421                         quest[i].complev = (byte)p_ptr->lev;
422 #ifdef JP
423 msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
424 #else
425                         msg_print("You completed the quest!");
426 #endif
427
428                         msg_print(NULL);
429                 }
430         }
431
432         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
433         {
434                 identify_item(o_ptr);
435
436                 /* Auto-inscription */
437                 auto_do_item(item, FALSE);
438         }
439
440         /* Take a turn */
441         energy_use = 100;
442
443         /* Get local object */
444         q_ptr = &forge;
445
446         /* Obtain local object */
447         object_copy(q_ptr, o_ptr);
448
449         /* Modify quantity */
450         q_ptr->number = 1;
451
452         /* Decrease the item (from the pack) */
453         if (item >= 0)
454         {
455                 inven_item_increase(item, -1);
456                 inven_item_optimize(item);
457         }
458
459         /* Decrease the item (from the floor) */
460         else
461         {
462                 floor_item_increase(0 - item, -1);
463                 floor_item_optimize(0 - item);
464         }
465
466         /* Access the wield slot */
467         o_ptr = &inventory[slot];
468
469         /* Take off existing item */
470         if (o_ptr->k_idx)
471         {
472                 /* Take off existing item */
473                 (void)inven_takeoff(slot, 255);
474         }
475
476         /* Wear the new stuff */
477         object_copy(o_ptr, q_ptr);
478
479         /* Increase the weight */
480         p_ptr->total_weight += q_ptr->weight;
481
482         /* Increment the equip counter by hand */
483         equip_cnt++;
484
485         /* Where is the item now */
486         switch (slot)
487         {
488         case INVEN_RARM:
489                 if ((o_ptr->tval != TV_SHIELD) && (o_ptr->tval != TV_CAPTURE) && (o_ptr->tval != TV_CARD) && (empty_hands(FALSE) & EMPTY_HAND_LARM) && ((o_ptr->weight > 99) || (o_ptr->tval == TV_POLEARM)) && (!p_ptr->riding || (p_ptr->pet_extra_flags & PF_RYOUTE)))
490 #ifdef JP
491                         act = "%s(%c)¤òξ¼ê¤Ç¹½¤¨¤¿¡£";
492 #else
493                         act = "You are wielding %s (%c) with both hands.";
494 #endif
495                 else
496 #ifdef JP
497                         act = (left_hander ? "%s(%c)¤òº¸¼ê¤ËÁõÈ÷¤·¤¿¡£" : "%s(%c)¤ò±¦¼ê¤ËÁõÈ÷¤·¤¿¡£");
498 #else
499                         act = (left_hander ? "You are wielding %s (%c) on left hand." : "You are wielding %s (%c) on right hand.");
500 #endif
501                 break;
502
503         case INVEN_LARM:
504 #ifdef JP
505                 act = (left_hander ? "%s(%c)¤ò±¦¼ê¤ËÁõÈ÷¤·¤¿¡£" : "%s(%c)¤òº¸¼ê¤ËÁõÈ÷¤·¤¿¡£");
506 #else
507                 act = (left_hander ? "You are wielding %s (%c) on right hand." : "You are wielding %s (%c) on left hand.");
508 #endif
509                 break;
510
511         case INVEN_BOW:
512 #ifdef JP
513                 act = "%s(%c)¤ò¼Í·âÍѤËÁõÈ÷¤·¤¿¡£";
514 #else
515                 act = "You are shooting with %s (%c).";
516 #endif
517                 break;
518
519         case INVEN_LITE:
520 #ifdef JP
521                 act = "%s(%c)¤ò¸÷¸»¤Ë¤·¤¿¡£";
522 #else
523                 act = "Your light source is %s (%c).";
524 #endif
525                 break;
526
527         default:
528 #ifdef JP
529                 act = "%s(%c)¤òÁõÈ÷¤·¤¿¡£";
530 #else
531                 act = "You are wearing %s (%c).";
532 #endif
533                 break;
534         }
535
536         /* Describe the result */
537         object_desc(o_name, o_ptr, TRUE, 3);
538
539         /* Message */
540         msg_format(act, o_name, index_to_label(slot));
541
542
543         /* Cursed! */
544         if (cursed_p(o_ptr))
545         {
546                 /* Warn the player */
547 #ifdef JP
548                 msg_print("¤¦¤ï¡ª ¤¹¤µ¤Þ¤¸¤¯Î䤿¤¤¡ª");
549 #else
550                 msg_print("Oops! It feels deathly cold!");
551 #endif
552
553
554                 chg_virtue(V_HARMONY, -1);
555
556                 /* Note the curse */
557                 o_ptr->ident |= (IDENT_SENSE);
558         }
559
560         /* The Stone Mask make the player turn into a vampire! */
561         if ((o_ptr->name1 == ART_STONEMASK) && (p_ptr->prace != RACE_VAMPIRE) && (p_ptr->prace != RACE_ANDROID))
562         {
563                 /* Turn into a vampire */
564                 change_race(RACE_VAMPIRE, "");
565         }
566
567         /* Recalculate bonuses */
568         p_ptr->update |= (PU_BONUS);
569
570         /* Recalculate torch */
571         p_ptr->update |= (PU_TORCH);
572
573         /* Recalculate mana */
574         p_ptr->update |= (PU_MANA);
575
576         p_ptr->redraw |= (PR_EQUIPPY);
577
578         /* Window stuff */
579         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
580
581         calc_android_exp();
582 }
583
584
585 void kamaenaoshi(int item)
586 {
587         object_type *o_ptr, *o2_ptr;
588         char o_name[MAX_NLEN];
589
590         if ((item == INVEN_RARM) && buki_motteruka(INVEN_LARM))
591         {
592                 o_ptr = &inventory[INVEN_RARM];
593                 o2_ptr = &inventory[INVEN_LARM];
594                 object_copy(o_ptr, o2_ptr);
595                 p_ptr->total_weight += o2_ptr->weight;
596                 inven_item_increase(INVEN_LARM,-1);
597                 inven_item_optimize(INVEN_LARM);
598                 object_desc(o_name, o_ptr, TRUE, 3);
599                 if (((o_ptr->weight > 99) || (o_ptr->tval == TV_POLEARM)) && (!p_ptr->riding || (p_ptr->pet_extra_flags & PF_RYOUTE)))
600 #ifdef JP
601                         msg_format("%s¤òξ¼ê¤Ç¹½¤¨¤¿¡£", o_name );
602 #else
603                         msg_format("You are wielding %s with both hands.", o_name );
604 #endif
605                  else
606 #ifdef JP
607                         msg_format("%s¤ò%s¤Ç¹½¤¨¤¿¡£", o_name, (left_hander ? "º¸¼ê" : "±¦¼ê"));
608 #else
609                         msg_format("You are wielding %s on %s hand.", o_name, (left_hander ? "left":"right") );
610 #endif
611         }
612         else if (item == INVEN_LARM)
613         {
614                 if (buki_motteruka(INVEN_RARM))
615                 {
616                         o_ptr = &inventory[INVEN_RARM];
617                         object_desc(o_name, o_ptr, TRUE, 3);
618                         if (((o_ptr->weight > 99) || (o_ptr->tval == TV_POLEARM)) && (!p_ptr->riding || (p_ptr->pet_extra_flags & PF_RYOUTE)))
619 #ifdef JP
620                                 msg_format("%s¤òξ¼ê¤Ç¹½¤¨¤¿¡£", o_name );
621 #else
622                                 msg_format("You are wielding %s with both hands.", o_name );
623 #endif
624                 }
625                 else if (!(empty_hands(FALSE) & EMPTY_HAND_RARM))
626                 {
627                         o_ptr = &inventory[INVEN_LARM];
628                         o2_ptr = &inventory[INVEN_RARM];
629                         object_copy(o_ptr, o2_ptr);
630                         p_ptr->total_weight += o2_ptr->weight;
631                         inven_item_increase(INVEN_RARM,-1);
632                         inven_item_optimize(INVEN_RARM);
633                         object_desc(o_name, o_ptr, TRUE, 3);
634 #ifdef JP
635                         msg_format("%s¤ò»ý¤ÁÂؤ¨¤¿¡£", o_name);
636 #else
637                         msg_format("You switched hand of %s.", o_name);
638 #endif
639                 }
640         }
641 }
642
643
644 /*
645  * Take off an item
646  */
647 void do_cmd_takeoff(void)
648 {
649         int item;
650
651         object_type *o_ptr;
652
653         cptr q, s;
654
655         if (p_ptr->special_defense & KATA_MUSOU)
656         {
657                 set_action(ACTION_NONE);
658         }
659
660         item_tester_no_ryoute = TRUE;
661         /* Get an item */
662 #ifdef JP
663         q = "¤É¤ì¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤Þ¤¹¤«? ";
664         s = "¤Ï¤º¤»¤ëÁõÈ÷¤¬¤Ê¤¤¡£";
665 #else
666         q = "Take off which item? ";
667         s = "You are not wearing anything to take off.";
668 #endif
669
670         if (!get_item(&item, q, s, (USE_EQUIP))) return;
671
672         /* Get the item (in the pack) */
673         if (item >= 0)
674         {
675                 o_ptr = &inventory[item];
676         }
677
678         /* Get the item (on the floor) */
679         else
680         {
681                 o_ptr = &o_list[0 - item];
682         }
683
684
685         /* Item is cursed */
686         if (cursed_p(o_ptr))
687         {
688                 if ((o_ptr->curse_flags & TRC_PERMA_CURSE) || (p_ptr->pclass != CLASS_BERSERKER))
689                 {
690                         /* Oops */
691 #ifdef JP
692                         msg_print("¤Õ¡¼¤à¡¢¤É¤¦¤ä¤é¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£");
693 #else
694                         msg_print("Hmmm, it seems to be cursed.");
695 #endif
696
697                         /* Nope */
698                         return;
699                 }
700
701                 if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && one_in_(7)) || one_in_(4))
702                 {
703 #ifdef JP
704                         msg_print("¼ö¤ï¤ì¤¿ÁõÈ÷¤òÎϤŤ¯¤ÇÇí¤¬¤·¤¿¡ª");
705 #else
706                         msg_print("You teared a cursed equipment off by sheer strength!");
707 #endif
708
709                         /* Hack -- Assume felt */
710                         o_ptr->ident |= (IDENT_SENSE);
711
712                         o_ptr->curse_flags = 0L;
713
714                         /* Take note */
715                         o_ptr->feeling = FEEL_NONE;
716
717                         /* Recalculate the bonuses */
718                         p_ptr->update |= (PU_BONUS);
719
720                         /* Window stuff */
721                         p_ptr->window |= (PW_EQUIP);
722
723 #ifdef JP
724                         msg_print("¼ö¤¤¤òÂǤÁÇˤä¿¡£");
725 #else
726                         msg_print("You break the curse.");
727 #endif
728                 }
729                 else
730                 {
731 #ifdef JP
732                         msg_print("ÁõÈ÷¤ò³°¤»¤Ê¤«¤Ã¤¿¡£");
733 #else
734                         msg_print("You couldn't remove the equipment.");
735 #endif
736                         energy_use = 50;
737                         return;
738                 }
739         }
740
741         /* Take a partial turn */
742         energy_use = 50;
743
744         /* Take off the item */
745         (void)inven_takeoff(item, 255);
746
747         kamaenaoshi(item);
748
749         calc_android_exp();
750
751         p_ptr->redraw |= (PR_EQUIPPY);
752 }
753
754
755 /*
756  * Drop an item
757  */
758 void do_cmd_drop(void)
759 {
760         int item, amt = 1;
761
762         object_type *o_ptr;
763
764         cptr q, s;
765
766         if (p_ptr->special_defense & KATA_MUSOU)
767         {
768                 set_action(ACTION_NONE);
769         }
770
771         item_tester_no_ryoute = TRUE;
772         /* Get an item */
773 #ifdef JP
774         q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÍî¤È¤·¤Þ¤¹¤«? ";
775         s = "Íî¤È¤»¤ë¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
776 #else
777         q = "Drop which item? ";
778         s = "You have nothing to drop.";
779 #endif
780
781         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN))) return;
782
783         /* Get the item (in the pack) */
784         if (item >= 0)
785         {
786                 o_ptr = &inventory[item];
787         }
788
789         /* Get the item (on the floor) */
790         else
791         {
792                 o_ptr = &o_list[0 - item];
793         }
794
795
796         /* Hack -- Cannot remove cursed items */
797         if ((item >= INVEN_RARM) && cursed_p(o_ptr))
798         {
799                 /* Oops */
800 #ifdef JP
801                 msg_print("¤Õ¡¼¤à¡¢¤É¤¦¤ä¤é¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£");
802 #else
803                 msg_print("Hmmm, it seems to be cursed.");
804 #endif
805
806
807                 /* Nope */
808                 return;
809         }
810
811
812         /* See how many items */
813         if (o_ptr->number > 1)
814         {
815                 /* Get a quantity */
816                 amt = get_quantity(NULL, o_ptr->number);
817
818                 /* Allow user abort */
819                 if (amt <= 0) return;
820         }
821
822
823         /* Take a partial turn */
824         energy_use = 50;
825
826         /* Drop (some of) the item */
827         inven_drop(item, amt);
828
829         if ((item == INVEN_RARM) || (item == INVEN_LARM)) kamaenaoshi(item);
830
831         if (item >= INVEN_RARM) calc_android_exp();
832
833         p_ptr->redraw |= (PR_EQUIPPY);
834 }
835
836
837 static bool high_level_book(object_type *o_ptr)
838 {
839         if ((o_ptr->tval == TV_LIFE_BOOK) ||
840             (o_ptr->tval == TV_SORCERY_BOOK) ||
841             (o_ptr->tval == TV_NATURE_BOOK) ||
842             (o_ptr->tval == TV_CHAOS_BOOK) ||
843             (o_ptr->tval == TV_DEATH_BOOK) ||
844             (o_ptr->tval == TV_TRUMP_BOOK) ||
845             (o_ptr->tval == TV_ENCHANT_BOOK) ||
846             (o_ptr->tval == TV_DAEMON_BOOK) ||
847             (o_ptr->tval == TV_CRUSADE_BOOK) ||
848             (o_ptr->tval == TV_MUSIC_BOOK))
849         {
850                 if (o_ptr->sval > 1)
851                         return TRUE;
852                 else
853                         return FALSE;
854         }
855
856         return FALSE;
857 }
858
859
860 /*
861  * Destroy an item
862  */
863 void do_cmd_destroy(void)
864 {
865         int                     item, amt = 1;
866         int                     old_number;
867
868         bool            force = FALSE;
869
870         object_type             *o_ptr;
871         object_type             forge;
872         object_type             *q_ptr = &forge;
873
874         char            o_name[MAX_NLEN];
875
876         char            out_val[MAX_NLEN+40];
877
878         cptr q, s;
879
880         if (p_ptr->special_defense & KATA_MUSOU)
881         {
882                 set_action(ACTION_NONE);
883         }
884
885         /* Hack -- force destruction */
886         if (command_arg > 0) force = TRUE;
887
888
889         /* Get an item */
890 #ifdef JP
891         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò²õ¤·¤Þ¤¹¤«? ";
892         s = "²õ¤»¤ë¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
893 #else
894         q = "Destroy which item? ";
895         s = "You have nothing to destroy.";
896 #endif
897
898         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
899
900         /* Get the item (in the pack) */
901         if (item >= 0)
902         {
903                 o_ptr = &inventory[item];
904         }
905
906         /* Get the item (on the floor) */
907         else
908         {
909                 o_ptr = &o_list[0 - item];
910         }
911
912
913         /* See how many items */
914         if (o_ptr->number > 1)
915         {
916                 /* Get a quantity */
917                 amt = get_quantity(NULL, o_ptr->number);
918
919                 /* Allow user abort */
920                 if (amt <= 0) return;
921         }
922
923
924         /* Describe the object */
925         old_number = o_ptr->number;
926         o_ptr->number = amt;
927         object_desc(o_name, o_ptr, TRUE, 3);
928         o_ptr->number = old_number;
929
930         /* Verify unless quantity given */
931         if (!force && (confirm_destroy || (object_value(o_ptr) > 0)))
932         {
933                 /* Make a verification */
934                 sprintf(out_val, 
935 #ifdef JP
936                         "ËÜÅö¤Ë%s¤ò²õ¤·¤Þ¤¹¤«? [y/n/Auto]",
937 #else
938                         "Really destroy %s? [y/n/Auto]",
939 #endif
940                         o_name);
941
942                 msg_print(NULL);
943
944                 /* HACK : Add the line to message buffer */
945                 message_add(out_val);
946                 p_ptr->window |= (PW_MESSAGE);
947                 window_stuff();
948
949                 /* Get an acceptable answer */
950                 while (TRUE)
951                 {
952                         char i;
953
954                         /* Prompt */
955                         prt(out_val, 0, 0);
956
957                         i = inkey();
958
959                         /* Erase the prompt */
960                         prt("", 0, 0);
961
962
963                         if (i == 'y' || i == 'Y')
964                         {
965                                 break;
966                         }
967                         if (i == ESCAPE || i == 'n' || i == 'N')
968                         {
969                                 /* Cancel */
970                                 return;
971                         }
972                         if (i == 'a' || i == 'A')
973                         {
974                                 /* Add an auto-destroy preference line */
975                                 if (add_auto_register(o_ptr))
976                                 {
977                                         /* Auto-destroy it */
978                                         auto_do_item(item, TRUE);
979                                 }
980
981                                 /* The object is already destroyed. */
982                                 return;
983                         }
984                 }
985         }
986
987         /* Take a turn */
988         energy_use = 100;
989
990         /* Artifacts cannot be destroyed */
991         if (!can_player_destroy_object(o_ptr))
992         {
993                 energy_use = 0;
994
995                 /* Message */
996 #ifdef JP
997                 msg_format("%s¤ÏÇ˲õÉÔ²Äǽ¤À¡£", o_name);
998 #else
999                 msg_format("You cannot destroy %s.", o_name);
1000 #endif
1001
1002                 /* Done */
1003                 return;
1004         }
1005
1006         object_copy(q_ptr, o_ptr);
1007
1008         /* Message */
1009 #ifdef JP
1010         msg_format("%s¤ò²õ¤·¤¿¡£", o_name);
1011 #else
1012         msg_format("You destroy %s.", o_name);
1013 #endif
1014
1015         sound(SOUND_DESTITEM);
1016
1017         /* Reduce the charges of rods/wands */
1018         reduce_charges(o_ptr, amt);
1019
1020         /* Eliminate the item (from the pack) */
1021         if (item >= 0)
1022         {
1023                 inven_item_increase(item, -amt);
1024                 inven_item_describe(item);
1025                 inven_item_optimize(item);
1026         }
1027
1028         /* Eliminate the item (from the floor) */
1029         else
1030         {
1031                 floor_item_increase(0 - item, -amt);
1032                 floor_item_describe(0 - item);
1033                 floor_item_optimize(0 - item);
1034         }
1035
1036         if (high_level_book(q_ptr))
1037         {
1038                 bool gain_expr = FALSE;
1039
1040                 if (p_ptr->prace == RACE_ANDROID)
1041                 {
1042                 }
1043                 else if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_BERSERKER))
1044                 {
1045                         gain_expr = TRUE;
1046                 }
1047                 else if (p_ptr->pclass == CLASS_PALADIN)
1048                 {
1049                         if (is_good_realm(p_ptr->realm1))
1050                         {
1051                                 if (!is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE;
1052                         }
1053                         else
1054                         {
1055                                 if (is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE;
1056                         }
1057                 }
1058
1059                 if (gain_expr && (p_ptr->exp < PY_MAX_EXP))
1060                 {
1061                         s32b tester_exp = p_ptr->max_exp / 20;
1062                         if (tester_exp > 10000) tester_exp = 10000;
1063                         if (q_ptr->sval < 3) tester_exp /= 4;
1064                         if (tester_exp<1) tester_exp = 1;
1065
1066 #ifdef JP
1067 msg_print("¹¹¤Ë·Ð¸³¤òÀѤó¤À¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
1068 #else
1069                         msg_print("You feel more experienced.");
1070 #endif
1071
1072                         gain_exp(tester_exp * amt);
1073                 }
1074                 if (high_level_book(q_ptr) && q_ptr->tval == TV_LIFE_BOOK)
1075                 {
1076                         chg_virtue(V_UNLIFE, 1);
1077                         chg_virtue(V_VITALITY, -1);
1078                 }
1079                 else if (high_level_book(q_ptr) && q_ptr->tval == TV_DEATH_BOOK)
1080                 {
1081                         chg_virtue(V_UNLIFE, -1);
1082                         chg_virtue(V_VITALITY, 1);
1083                 }
1084         
1085                 if (q_ptr->to_a || q_ptr->to_h || q_ptr->to_d)
1086                         chg_virtue(V_ENCHANT, -1);
1087         
1088                 if (object_value_real(q_ptr) > 30000)
1089                         chg_virtue(V_SACRIFICE, 2);
1090         
1091                 else if (object_value_real(q_ptr) > 10000)
1092                         chg_virtue(V_SACRIFICE, 1);
1093         }
1094
1095         if (q_ptr->to_a != 0 || q_ptr->to_d != 0 || q_ptr->to_h != 0)
1096                 chg_virtue(V_HARMONY, 1);
1097
1098         if (item >= INVEN_RARM) calc_android_exp();
1099 }
1100
1101
1102 /*
1103  * Observe an item which has been *identify*-ed
1104  */
1105 void do_cmd_observe(void)
1106 {
1107         int                     item;
1108
1109         object_type             *o_ptr;
1110
1111         char            o_name[MAX_NLEN];
1112
1113         cptr q, s;
1114
1115         item_tester_no_ryoute = TRUE;
1116         /* Get an item */
1117 #ifdef JP
1118         q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤Þ¤¹¤«? ";
1119         s = "Ä´¤Ù¤é¤ì¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
1120 #else
1121         q = "Examine which item? ";
1122         s = "You have nothing to examine.";
1123 #endif
1124
1125         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1126
1127         /* Get the item (in the pack) */
1128         if (item >= 0)
1129         {
1130                 o_ptr = &inventory[item];
1131         }
1132
1133         /* Get the item (on the floor) */
1134         else
1135         {
1136                 o_ptr = &o_list[0 - item];
1137         }
1138
1139
1140         /* Require full knowledge */
1141         if (!(o_ptr->ident & IDENT_MENTAL))
1142         {
1143 #ifdef JP
1144                 msg_print("¤³¤Î¥¢¥¤¥Æ¥à¤Ë¤Ä¤¤¤ÆÆäËÃΤäƤ¤¤ë¤³¤È¤Ï¤Ê¤¤¡£");
1145 #else
1146                 msg_print("You have no special knowledge about that item.");
1147 #endif
1148
1149                 return;
1150         }
1151
1152
1153         /* Description */
1154         object_desc(o_name, o_ptr, TRUE, 3);
1155
1156         /* Describe */
1157 #ifdef JP
1158         msg_format("%s¤òÄ´¤Ù¤Æ¤¤¤ë...", o_name);
1159 #else
1160         msg_format("Examining %s...", o_name);
1161 #endif
1162
1163         /* Describe it fully */
1164 #ifdef JP
1165         if (!screen_object(o_ptr, TRUE)) msg_print("ÆäËÊѤï¤Ã¤¿¤È¤³¤í¤Ï¤Ê¤¤¤è¤¦¤À¡£");
1166 #else
1167         if (!screen_object(o_ptr, TRUE)) msg_print("You see nothing special.");
1168 #endif
1169
1170 }
1171
1172
1173
1174 /*
1175  * Remove the inscription from an object
1176  * XXX Mention item (when done)?
1177  */
1178 void do_cmd_uninscribe(void)
1179 {
1180         int   item;
1181
1182         object_type *o_ptr;
1183
1184         cptr q, s;
1185
1186         item_tester_no_ryoute = TRUE;
1187         /* Get an item */
1188 #ifdef JP
1189         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ÎÌäò¾Ã¤·¤Þ¤¹¤«? ";
1190         s = "Ìäò¾Ã¤»¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
1191 #else
1192         q = "Un-inscribe which item? ";
1193         s = "You have nothing to un-inscribe.";
1194 #endif
1195
1196         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1197
1198         /* Get the item (in the pack) */
1199         if (item >= 0)
1200         {
1201                 o_ptr = &inventory[item];
1202         }
1203
1204         /* Get the item (on the floor) */
1205         else
1206         {
1207                 o_ptr = &o_list[0 - item];
1208         }
1209
1210         /* Nothing to remove */
1211         if (!o_ptr->inscription)
1212         {
1213 #ifdef JP
1214                 msg_print("¤³¤Î¥¢¥¤¥Æ¥à¤Ë¤Ï¾Ã¤¹¤Ù¤­Ì䬤ʤ¤¡£");
1215 #else
1216                 msg_print("That item had no inscription to remove.");
1217 #endif
1218
1219                 return;
1220         }
1221
1222         /* Message */
1223 #ifdef JP
1224         msg_print("Ìäò¾Ã¤·¤¿¡£");
1225 #else
1226         msg_print("Inscription removed.");
1227 #endif
1228
1229
1230         /* Remove the incription */
1231         o_ptr->inscription = 0;
1232
1233         /* Combine the pack */
1234         p_ptr->notice |= (PN_COMBINE);
1235
1236         /* Window stuff */
1237         p_ptr->window |= (PW_INVEN | PW_EQUIP);
1238
1239         /* .¤ä$¤Î´Ø·¸¤Ç, ºÆ·×»»¤¬É¬ÍפʤϤº -- henkma */
1240         p_ptr->update |= (PU_BONUS);
1241
1242 }
1243
1244
1245 /*
1246  * Inscribe an object with a comment
1247  */
1248 void do_cmd_inscribe(void)
1249 {
1250         int                     item;
1251
1252         object_type             *o_ptr;
1253
1254         char            o_name[MAX_NLEN];
1255
1256         char            out_val[80];
1257
1258         cptr q, s;
1259
1260         item_tester_no_ryoute = TRUE;
1261         /* Get an item */
1262 #ifdef JP
1263         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ËÌäò¹ï¤ß¤Þ¤¹¤«? ";
1264         s = "Ìäò¹ï¤á¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
1265 #else
1266         q = "Inscribe which item? ";
1267         s = "You have nothing to inscribe.";
1268 #endif
1269
1270         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1271
1272         /* Get the item (in the pack) */
1273         if (item >= 0)
1274         {
1275                 o_ptr = &inventory[item];
1276         }
1277
1278         /* Get the item (on the floor) */
1279         else
1280         {
1281                 o_ptr = &o_list[0 - item];
1282         }
1283
1284         /* Describe the activity */
1285         object_desc(o_name, o_ptr, TRUE, 2);
1286
1287         /* Message */
1288 #ifdef JP
1289         msg_format("%s¤ËÌäò¹ï¤à¡£", o_name);
1290 #else
1291         msg_format("Inscribing %s.", o_name);
1292 #endif
1293
1294         msg_print(NULL);
1295
1296         /* Start with nothing */
1297         strcpy(out_val, "");
1298
1299         /* Use old inscription */
1300         if (o_ptr->inscription)
1301         {
1302                 /* Start with the old inscription */
1303                 strcpy(out_val, quark_str(o_ptr->inscription));
1304         }
1305
1306         /* Get a new inscription (possibly empty) */
1307 #ifdef JP
1308         if (get_string("ÌÃ: ", out_val, 80))
1309 #else
1310         if (get_string("Inscription: ", out_val, 80))
1311 #endif
1312         {
1313                 /* Save the inscription */
1314                 o_ptr->inscription = quark_add(out_val);
1315
1316                 /* Combine the pack */
1317                 p_ptr->notice |= (PN_COMBINE);
1318
1319                 /* Window stuff */
1320                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
1321
1322                 /* .¤ä$¤Î´Ø·¸¤Ç, ºÆ·×»»¤¬É¬ÍפʤϤº -- henkma */
1323                 p_ptr->update |= (PU_BONUS);
1324         }
1325 }
1326
1327
1328
1329 /*
1330  * An "item_tester_hook" for refilling lanterns
1331  */
1332 static bool item_tester_refill_lantern(object_type *o_ptr)
1333 {
1334         /* Flasks of oil are okay */
1335         if (o_ptr->tval == TV_FLASK) return (TRUE);
1336
1337         /* Laterns are okay */
1338         if ((o_ptr->tval == TV_LITE) &&
1339             (o_ptr->sval == SV_LITE_LANTERN)) return (TRUE);
1340
1341         /* Assume not okay */
1342         return (FALSE);
1343 }
1344
1345
1346 /*
1347  * Refill the players lamp (from the pack or floor)
1348  */
1349 static void do_cmd_refill_lamp(void)
1350 {
1351         int item;
1352
1353         object_type *o_ptr;
1354         object_type *j_ptr;
1355
1356         cptr q, s;
1357
1358
1359         /* Restrict the choices */
1360         item_tester_hook = item_tester_refill_lantern;
1361
1362         /* Get an item */
1363 #ifdef JP
1364         q = "¤É¤ÎÌý¤Ä¤Ü¤«¤éÃí¤®¤Þ¤¹¤«? ";
1365         s = "Ìý¤Ä¤Ü¤¬¤Ê¤¤¡£";
1366 #else
1367         q = "Refill with which flask? ";
1368         s = "You have no flasks of oil.";
1369 #endif
1370
1371         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
1372
1373         /* Get the item (in the pack) */
1374         if (item >= 0)
1375         {
1376                 o_ptr = &inventory[item];
1377         }
1378
1379         /* Get the item (on the floor) */
1380         else
1381         {
1382                 o_ptr = &o_list[0 - item];
1383         }
1384
1385
1386         /* Take a partial turn */
1387         energy_use = 50;
1388
1389         /* Access the lantern */
1390         j_ptr = &inventory[INVEN_LITE];
1391
1392         /* Refuel */
1393         j_ptr->xtra4 += o_ptr->xtra4;
1394
1395         /* Message */
1396 #ifdef JP
1397         msg_print("¥é¥ó¥×¤ËÌý¤òÃí¤¤¤À¡£");
1398 #else
1399         msg_print("You fuel your lamp.");
1400 #endif
1401
1402         /* Comment */
1403         if ((o_ptr->name2 == EGO_LITE_DARKNESS) && (j_ptr->xtra4 > 0))
1404         {
1405                 j_ptr->xtra4 = 0;
1406 #ifdef JP
1407                 msg_print("¥é¥ó¥×¤¬¾Ã¤¨¤Æ¤·¤Þ¤Ã¤¿¡ª");
1408 #else
1409                 msg_print("Your lamp has gone out!");
1410 #endif
1411         }
1412         else if ((o_ptr->name2 == EGO_LITE_DARKNESS) || (j_ptr->name2 == EGO_LITE_DARKNESS))
1413         {
1414                 j_ptr->xtra4 = 0;
1415 #ifdef JP
1416                 msg_print("¤·¤«¤·¥é¥ó¥×¤ÏÁ´¤¯¸÷¤é¤Ê¤¤¡£");
1417 #else
1418                 msg_print("Curiously, your lamp doesn't light.");
1419 #endif
1420         }
1421         else if (j_ptr->xtra4 >= FUEL_LAMP)
1422         {
1423                 j_ptr->xtra4 = FUEL_LAMP;
1424 #ifdef JP
1425                 msg_print("¥é¥ó¥×¤ÎÌý¤Ï°ìÇÕ¤À¡£");
1426 #else
1427                 msg_print("Your lamp is full.");
1428 #endif
1429
1430         }
1431
1432         /* Decrease the item (from the pack) */
1433         if (item >= 0)
1434         {
1435                 inven_item_increase(item, -1);
1436                 inven_item_describe(item);
1437                 inven_item_optimize(item);
1438         }
1439
1440         /* Decrease the item (from the floor) */
1441         else
1442         {
1443                 floor_item_increase(0 - item, -1);
1444                 floor_item_describe(0 - item);
1445                 floor_item_optimize(0 - item);
1446         }
1447
1448         /* Recalculate torch */
1449         p_ptr->update |= (PU_TORCH);
1450 }
1451
1452
1453 /*
1454  * An "item_tester_hook" for refilling torches
1455  */
1456 static bool item_tester_refill_torch(object_type *o_ptr)
1457 {
1458         /* Torches are okay */
1459         if ((o_ptr->tval == TV_LITE) &&
1460             (o_ptr->sval == SV_LITE_TORCH)) return (TRUE);
1461
1462         /* Assume not okay */
1463         return (FALSE);
1464 }
1465
1466
1467 /*
1468  * Refuel the players torch (from the pack or floor)
1469  */
1470 static void do_cmd_refill_torch(void)
1471 {
1472         int item;
1473
1474         object_type *o_ptr;
1475         object_type *j_ptr;
1476
1477         cptr q, s;
1478
1479
1480         /* Restrict the choices */
1481         item_tester_hook = item_tester_refill_torch;
1482
1483         /* Get an item */
1484 #ifdef JP
1485         q = "¤É¤Î¾¾ÌÀ¤ÇÌÀ¤«¤ê¤ò¶¯¤á¤Þ¤¹¤«? ";
1486         s = "¾¤Ë¾¾ÌÀ¤¬¤Ê¤¤¡£";
1487 #else
1488         q = "Refuel with which torch? ";
1489         s = "You have no extra torches.";
1490 #endif
1491
1492         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
1493
1494         /* Get the item (in the pack) */
1495         if (item >= 0)
1496         {
1497                 o_ptr = &inventory[item];
1498         }
1499
1500         /* Get the item (on the floor) */
1501         else
1502         {
1503                 o_ptr = &o_list[0 - item];
1504         }
1505
1506
1507         /* Take a partial turn */
1508         energy_use = 50;
1509
1510         /* Access the primary torch */
1511         j_ptr = &inventory[INVEN_LITE];
1512
1513         /* Refuel */
1514         j_ptr->xtra4 += o_ptr->xtra4 + 5;
1515
1516         /* Message */
1517 #ifdef JP
1518         msg_print("¾¾ÌÀ¤ò·ë¹ç¤·¤¿¡£");
1519 #else
1520         msg_print("You combine the torches.");
1521 #endif
1522
1523
1524         /* Comment */
1525         if ((o_ptr->name2 == EGO_LITE_DARKNESS) && (j_ptr->xtra4 > 0))
1526         {
1527                 j_ptr->xtra4 = 0;
1528 #ifdef JP
1529                 msg_print("¾¾ÌÀ¤¬¾Ã¤¨¤Æ¤·¤Þ¤Ã¤¿¡ª");
1530 #else
1531                 msg_print("Your torch has gone out!");
1532 #endif
1533         }
1534         else if ((o_ptr->name2 == EGO_LITE_DARKNESS) || (j_ptr->name2 == EGO_LITE_DARKNESS))
1535         {
1536                 j_ptr->xtra4 = 0;
1537 #ifdef JP
1538                 msg_print("¤·¤«¤·¾¾ÌÀ¤ÏÁ´¤¯¸÷¤é¤Ê¤¤¡£");
1539 #else
1540                 msg_print("Curiously, your torche don't light.");
1541 #endif
1542         }
1543         /* Over-fuel message */
1544         else if (j_ptr->xtra4 >= FUEL_TORCH)
1545         {
1546                 j_ptr->xtra4 = FUEL_TORCH;
1547 #ifdef JP
1548                 msg_print("¾¾ÌÀ¤Î¼÷Ì¿¤Ï½½Ê¬¤À¡£");
1549 #else
1550                 msg_print("Your torch is fully fueled.");
1551 #endif
1552
1553         }
1554
1555         /* Refuel message */
1556         else
1557         {
1558 #ifdef JP
1559                 msg_print("¾¾ÌÀ¤Ï¤¤¤Ã¤½¤¦ÌÀ¤ë¤¯µ±¤¤¤¿¡£");
1560 #else
1561                 msg_print("Your torch glows more brightly.");
1562 #endif
1563
1564         }
1565
1566         /* Decrease the item (from the pack) */
1567         if (item >= 0)
1568         {
1569                 inven_item_increase(item, -1);
1570                 inven_item_describe(item);
1571                 inven_item_optimize(item);
1572         }
1573
1574         /* Decrease the item (from the floor) */
1575         else
1576         {
1577                 floor_item_increase(0 - item, -1);
1578                 floor_item_describe(0 - item);
1579                 floor_item_optimize(0 - item);
1580         }
1581
1582         /* Recalculate torch */
1583         p_ptr->update |= (PU_TORCH);
1584 }
1585
1586
1587 /*
1588  * Refill the players lamp, or restock his torches
1589  */
1590 void do_cmd_refill(void)
1591 {
1592         object_type *o_ptr;
1593
1594         /* Get the light */
1595         o_ptr = &inventory[INVEN_LITE];
1596
1597         if (p_ptr->special_defense & KATA_MUSOU)
1598         {
1599                 set_action(ACTION_NONE);
1600         }
1601
1602         /* It is nothing */
1603         if (o_ptr->tval != TV_LITE)
1604         {
1605 #ifdef JP
1606                 msg_print("¸÷¸»¤òÁõÈ÷¤·¤Æ¤¤¤Ê¤¤¡£");
1607 #else
1608                 msg_print("You are not wielding a light.");
1609 #endif
1610
1611         }
1612
1613         /* It's a lamp */
1614         else if (o_ptr->sval == SV_LITE_LANTERN)
1615         {
1616                 do_cmd_refill_lamp();
1617         }
1618
1619         /* It's a torch */
1620         else if (o_ptr->sval == SV_LITE_TORCH)
1621         {
1622                 do_cmd_refill_torch();
1623         }
1624
1625         /* No torch to refill */
1626         else
1627         {
1628 #ifdef JP
1629                 msg_print("¤³¤Î¸÷¸»¤Ï¼÷Ì¿¤ò±ä¤Ð¤»¤Ê¤¤¡£");
1630 #else
1631                 msg_print("Your light cannot be refilled.");
1632 #endif
1633
1634         }
1635 }
1636
1637
1638 /*
1639  * Target command
1640  */
1641 void do_cmd_target(void)
1642 {
1643         /* Target set */
1644         if (target_set(TARGET_KILL))
1645         {
1646 #ifdef JP
1647                 msg_print("¥¿¡¼¥²¥Ã¥È·èÄê¡£");
1648 #else
1649                 msg_print("Target Selected.");
1650 #endif
1651
1652         }
1653
1654         /* Target aborted */
1655         else
1656         {
1657 #ifdef JP
1658                 msg_print("¥¿¡¼¥²¥Ã¥È²ò½ü¡£");
1659 #else
1660                 msg_print("Target Aborted.");
1661 #endif
1662
1663         }
1664 }
1665
1666
1667
1668 /*
1669  * Look command
1670  */
1671 void do_cmd_look(void)
1672 {
1673         /* Look around */
1674         if (target_set(TARGET_LOOK))
1675         {
1676 #ifdef JP
1677                 msg_print("¥¿¡¼¥²¥Ã¥È·èÄê¡£");
1678 #else
1679                 msg_print("Target Selected.");
1680 #endif
1681
1682         }
1683 }
1684
1685
1686
1687 /*
1688  * Allow the player to examine other sectors on the map
1689  */
1690 void do_cmd_locate(void)
1691 {
1692         int             dir, y1, x1, y2, x2;
1693
1694         char    tmp_val[80];
1695
1696         char    out_val[160];
1697
1698         int wid, hgt;
1699
1700         /* Get size */
1701         get_screen_size(&wid, &hgt);
1702
1703
1704         /* Start at current panel */
1705         y2 = y1 = panel_row_min;
1706         x2 = x1 = panel_col_min;
1707
1708         /* Show panels until done */
1709         while (1)
1710         {
1711                 /* Describe the location */
1712                 if ((y2 == y1) && (x2 == x1))
1713                 {
1714 #ifdef JP
1715                         strcpy(tmp_val, "¿¿¾å");
1716 #else
1717                         tmp_val[0] = '\0';
1718 #endif
1719
1720                 }
1721                 else
1722                 {
1723 #ifdef JP
1724                         sprintf(tmp_val, "%s%s",
1725                                 ((y2 < y1) ? "ËÌ" : (y2 > y1) ? "Æî" : ""),
1726                                 ((x2 < x1) ? "À¾" : (x2 > x1) ? "Åì" : ""));
1727 #else
1728                         sprintf(tmp_val, "%s%s of",
1729                                 ((y2 < y1) ? " North" : (y2 > y1) ? " South" : ""),
1730                                 ((x2 < x1) ? " West" : (x2 > x1) ? " East" : ""));
1731 #endif
1732
1733                 }
1734
1735                 /* Prepare to ask which way to look */
1736                 sprintf(out_val,
1737 #ifdef JP
1738                         "¥Þ¥Ã¥×°ÌÃÖ [%d(%02d),%d(%02d)] (¥×¥ì¥¤¥ä¡¼¤Î%s)  Êý¸þ?",
1739 #else
1740                         "Map sector [%d(%02d),%d(%02d)], which is%s your sector.  Direction?",
1741 #endif
1742
1743                         y2 / (hgt / 2), y2 % (hgt / 2),
1744                         x2 / (wid / 2), x2 % (wid / 2), tmp_val);
1745
1746                 /* Assume no direction */
1747                 dir = 0;
1748
1749                 /* Get a direction */
1750                 while (!dir)
1751                 {
1752                         char command;
1753
1754                         /* Get a command (or Cancel) */
1755                         if (!get_com(out_val, &command, TRUE)) break;
1756
1757                         /* Extract the action (if any) */
1758                         dir = get_keymap_dir(command);
1759
1760                         /* Error */
1761                         if (!dir) bell();
1762                 }
1763
1764                 /* No direction */
1765                 if (!dir) break;
1766
1767                 /* Apply the motion */
1768                 if (change_panel(ddy[dir], ddx[dir]))
1769                 {
1770                         y2 = panel_row_min;
1771                         x2 = panel_col_min;
1772                 }
1773         }
1774
1775
1776         /* Recenter the map around the player */
1777         verify_panel();
1778
1779         /* Update stuff */
1780         p_ptr->update |= (PU_MONSTERS);
1781
1782         /* Redraw map */
1783         p_ptr->redraw |= (PR_MAP);
1784
1785         /* Window stuff */
1786         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1787
1788         /* Handle stuff */
1789         handle_stuff();
1790 }
1791
1792
1793
1794 /*
1795  * Sorting hook -- Comp function -- see below
1796  *
1797  * We use "u" to point to array of monster indexes,
1798  * and "v" to select the type of sorting to perform on "u".
1799  */
1800 bool ang_sort_comp_hook(vptr u, vptr v, int a, int b)
1801 {
1802         u16b *who = (u16b*)(u);
1803
1804         u16b *why = (u16b*)(v);
1805
1806         int w1 = who[a];
1807         int w2 = who[b];
1808
1809         int z1, z2;
1810
1811         /* Sort by player kills */
1812         if (*why >= 4)
1813         {
1814                 /* Extract player kills */
1815                 z1 = r_info[w1].r_pkills;
1816                 z2 = r_info[w2].r_pkills;
1817
1818                 /* Compare player kills */
1819                 if (z1 < z2) return (TRUE);
1820                 if (z1 > z2) return (FALSE);
1821         }
1822
1823
1824         /* Sort by total kills */
1825         if (*why >= 3)
1826         {
1827                 /* Extract total kills */
1828                 z1 = r_info[w1].r_tkills;
1829                 z2 = r_info[w2].r_tkills;
1830
1831                 /* Compare total kills */
1832                 if (z1 < z2) return (TRUE);
1833                 if (z1 > z2) return (FALSE);
1834         }
1835
1836
1837         /* Sort by monster level */
1838         if (*why >= 2)
1839         {
1840                 /* Extract levels */
1841                 z1 = r_info[w1].level;
1842                 z2 = r_info[w2].level;
1843
1844                 /* Compare levels */
1845                 if (z1 < z2) return (TRUE);
1846                 if (z1 > z2) return (FALSE);
1847         }
1848
1849
1850         /* Sort by monster experience */
1851         if (*why >= 1)
1852         {
1853                 /* Extract experience */
1854                 z1 = r_info[w1].mexp;
1855                 z2 = r_info[w2].mexp;
1856
1857                 /* Compare experience */
1858                 if (z1 < z2) return (TRUE);
1859                 if (z1 > z2) return (FALSE);
1860         }
1861
1862
1863         /* Compare indexes */
1864         return (w1 <= w2);
1865 }
1866
1867
1868 /*
1869  * Sorting hook -- Swap function -- see below
1870  *
1871  * We use "u" to point to array of monster indexes,
1872  * and "v" to select the type of sorting to perform.
1873  */
1874 void ang_sort_swap_hook(vptr u, vptr v, int a, int b)
1875 {
1876         u16b *who = (u16b*)(u);
1877
1878         u16b holder;
1879
1880         /* Unused */
1881         (void)v;
1882
1883         /* Swap */
1884         holder = who[a];
1885         who[a] = who[b];
1886         who[b] = holder;
1887 }
1888
1889
1890
1891 /*
1892  * Identify a character, allow recall of monsters
1893  *
1894  * Several "special" responses recall "multiple" monsters:
1895  *   ^A (all monsters)
1896  *   ^U (all unique monsters)
1897  *   ^N (all non-unique monsters)
1898  *
1899  * The responses may be sorted in several ways, see below.
1900  *
1901  * Note that the player ghosts are ignored. XXX XXX XXX
1902  */
1903 void do_cmd_query_symbol(void)
1904 {
1905         int             i, n, r_idx;
1906         char    sym, query;
1907         char    buf[128];
1908
1909         bool    all = FALSE;
1910         bool    uniq = FALSE;
1911         bool    norm = FALSE;
1912         bool    ride = FALSE;
1913         char    temp[80] = "";
1914
1915         bool    recall = FALSE;
1916
1917         u16b    why = 0;
1918         u16b    *who;
1919
1920         /* Get a character, or abort */
1921 #ifdef JP
1922         if (!get_com("ÃΤꤿ¤¤Ê¸»ú¤òÆþÎϤ·¤Æ²¼¤µ¤¤(µ­¹æ or ^AÁ´,^U¥æ,^NÈó¥æ,^R¾èÇÏ,^M̾Á°): ", &sym, FALSE)) return;
1923 #else
1924         if (!get_com("Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): ", &sym, FALSE)) return;
1925 #endif
1926
1927         /* Find that character info, and describe it */
1928         for (i = 0; ident_info[i]; ++i)
1929         {
1930                 if (sym == ident_info[i][0]) break;
1931         }
1932
1933         /* Describe */
1934         if (sym == KTRL('A'))
1935         {
1936                 all = TRUE;
1937 #ifdef JP
1938                 strcpy(buf, "Á´¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
1939 #else
1940                 strcpy(buf, "Full monster list.");
1941 #endif
1942         }
1943         else if (sym == KTRL('U'))
1944         {
1945                 all = uniq = TRUE;
1946 #ifdef JP
1947                 strcpy(buf, "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
1948 #else
1949                 strcpy(buf, "Unique monster list.");
1950 #endif
1951         }
1952         else if (sym == KTRL('N'))
1953         {
1954                 all = norm = TRUE;
1955 #ifdef JP
1956                 strcpy(buf, "¥æ¥Ë¡¼¥¯³°¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
1957 #else
1958                 strcpy(buf, "Non-unique monster list.");
1959 #endif
1960         }
1961         else if (sym == KTRL('R'))
1962         {
1963                 all = ride = TRUE;
1964 #ifdef JP
1965                 strcpy(buf, "¾èÇϲÄǽ¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
1966 #else
1967                 strcpy(buf, "Ridable monster list.");
1968 #endif
1969         }
1970         /* XTRA HACK WHATSEARCH */
1971         else if (sym == KTRL('M'))
1972         {
1973                 all = TRUE;
1974 #ifdef JP
1975                 if (!get_string("̾Á°(±Ñ¸ì¤Î¾ì¹ç¾®Ê¸»ú¤Ç²Ä)",temp, 70))
1976 #else
1977                 if (!get_string("Enter name:",temp, 70))
1978 #endif
1979                 {
1980                         temp[0]=0;
1981                         return;
1982                 }
1983 #ifdef JP
1984                 sprintf(buf, "̾Á°:%s¤Ë¥Þ¥Ã¥Á",temp);
1985 #else
1986                 sprintf(buf, "Monsters with a name \"%s\"",temp);
1987 #endif
1988         }
1989         else if (ident_info[i])
1990         {
1991                 sprintf(buf, "%c - %s.", sym, ident_info[i] + 2);
1992         }
1993         else
1994         {
1995 #ifdef JP
1996                 sprintf(buf, "%c - %s", sym, "̵¸ú¤Êʸ»ú");
1997 #else
1998                 sprintf(buf, "%c - %s.", sym, "Unknown Symbol");
1999 #endif
2000         }
2001
2002         /* Display the result */
2003         prt(buf, 0, 0);
2004
2005         /* Allocate the "who" array */
2006         C_MAKE(who, max_r_idx, u16b);
2007
2008         /* Collect matching monsters */
2009         for (n = 0, i = 1; i < max_r_idx; i++)
2010         {
2011                 monster_race *r_ptr = &r_info[i];
2012
2013                 /* Nothing to recall */
2014                 if (!cheat_know && !r_ptr->r_sights) continue;
2015
2016                 /* Require non-unique monsters if needed */
2017                 if (norm && (r_ptr->flags1 & (RF1_UNIQUE))) continue;
2018
2019                 /* Require unique monsters if needed */
2020                 if (uniq && !(r_ptr->flags1 & (RF1_UNIQUE))) continue;
2021
2022                 /* Require ridable monsters if needed */
2023                 if (ride && !(r_ptr->flags7 & (RF7_RIDING))) continue;
2024
2025                 /* XTRA HACK WHATSEARCH */
2026                 if (temp[0])
2027                 {
2028                   int xx;
2029                   char temp2[80];
2030   
2031                   for (xx=0; temp[xx] && xx<80; xx++)
2032                   {
2033 #ifdef JP
2034                     if (iskanji( temp[xx])) { xx++; continue; }
2035 #endif
2036                     if (isupper(temp[xx])) temp[xx]=tolower(temp[xx]);
2037                   }
2038   
2039 #ifdef JP
2040                   strcpy(temp2, r_name+r_ptr->E_name);
2041 #else
2042                   strcpy(temp2, r_name+r_ptr->name);
2043 #endif
2044                   for (xx=0; temp2[xx] && xx<80; xx++)
2045                     if (isupper(temp2[xx])) temp2[xx]=tolower(temp2[xx]);
2046   
2047 #ifdef JP
2048                   if (strstr(temp2, temp) || strstr_j(r_name + r_ptr->name, temp) )
2049 #else
2050                   if (strstr(temp2, temp))
2051 #endif
2052                           who[n++]=i;
2053                 }
2054
2055                 /* Collect "appropriate" monsters */
2056                 else if (all || (r_ptr->d_char == sym)) who[n++] = i;
2057         }
2058
2059         /* Nothing to recall */
2060         if (!n)
2061         {
2062                 /* Free the "who" array */
2063                 C_KILL(who, max_r_idx, u16b);
2064
2065                 return;
2066         }
2067
2068
2069         /* Prompt XXX XXX XXX */
2070 #ifdef JP
2071         put_str("»×¤¤½Ð¤ò¸«¤Þ¤¹¤«? (k:»¦³²½ç/y/n): ", 0, 36);
2072 #else
2073         put_str("Recall details? (k/y/n): ", 0, 40);
2074 #endif
2075
2076
2077         /* Query */
2078         query = inkey();
2079
2080         /* Restore */
2081         prt(buf, 0, 0);
2082
2083         why = 2;
2084
2085         /* Select the sort method */
2086         ang_sort_comp = ang_sort_comp_hook;
2087         ang_sort_swap = ang_sort_swap_hook;
2088
2089         /* Sort the array */
2090         ang_sort(who, &why, n);
2091
2092         /* Sort by kills (and level) */
2093         if (query == 'k')
2094         {
2095                 why = 4;
2096                 query = 'y';
2097         }
2098
2099         /* Catch "escape" */
2100         if (query != 'y')
2101         {
2102                 /* Free the "who" array */
2103                 C_KILL(who, max_r_idx, u16b);
2104
2105                 return;
2106         }
2107
2108         /* Sort if needed */
2109         if (why == 4)
2110         {
2111                 /* Select the sort method */
2112                 ang_sort_comp = ang_sort_comp_hook;
2113                 ang_sort_swap = ang_sort_swap_hook;
2114
2115                 /* Sort the array */
2116                 ang_sort(who, &why, n);
2117         }
2118
2119
2120         /* Start at the end */
2121         i = n - 1;
2122
2123         /* Scan the monster memory */
2124         while (1)
2125         {
2126                 /* Extract a race */
2127                 r_idx = who[i];
2128
2129                 /* Hack -- Auto-recall */
2130                 monster_race_track(r_idx);
2131
2132                 /* Hack -- Handle stuff */
2133                 handle_stuff();
2134
2135                 /* Interact */
2136                 while (1)
2137                 {
2138                         /* Recall */
2139                         if (recall)
2140                         {
2141                                 /* Save the screen */
2142                                 screen_save();
2143
2144                                 /* Recall on screen */
2145                                 screen_roff(who[i], 0);
2146                         }
2147
2148                         /* Hack -- Begin the prompt */
2149                         roff_top(r_idx);
2150
2151                         /* Hack -- Complete the prompt */
2152 #ifdef JP
2153                         Term_addstr(-1, TERM_WHITE, " ['r'»×¤¤½Ð, ESC]");
2154 #else
2155                         Term_addstr(-1, TERM_WHITE, " [(r)ecall, ESC]");
2156 #endif
2157
2158                         /* Command */
2159                         query = inkey();
2160
2161                         /* Unrecall */
2162                         if (recall)
2163                         {
2164                                 /* Restore */
2165                                 screen_load();
2166                         }
2167
2168                         /* Normal commands */
2169                         if (query != 'r') break;
2170
2171                         /* Toggle recall */
2172                         recall = !recall;
2173                 }
2174
2175                 /* Stop scanning */
2176                 if (query == ESCAPE) break;
2177
2178                 /* Move to "prev" monster */
2179                 if (query == '-')
2180                 {
2181                         if (++i == n)
2182                         {
2183                                 i = 0;
2184                                 if (!expand_list) break;
2185                         }
2186                 }
2187
2188                 /* Move to "next" monster */
2189                 else
2190                 {
2191                         if (i-- == 0)
2192                         {
2193                                 i = n - 1;
2194                                 if (!expand_list) break;
2195                         }
2196                 }
2197         }
2198
2199         /* Free the "who" array */
2200         C_KILL(who, max_r_idx, u16b);
2201
2202         /* Re-display the identity */
2203         prt(buf, 0, 0);
2204 }
2205
2206