OSDN Git Service

「TOband dev-team からバグ報告」のバグいろいろ修正。全部ではない。
[hengband/hengband.git] / src / cmd3.c
1 /* File: cmd3.c */
2
3 /* Purpose: Inventory commands */
4
5 /*
6  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research, and
9  * not for profit purposes provided that this copyright and statement are
10  * included in all such copies.
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 #if 1 /* EASY_RING -- TNB */
257
258         if ((o_ptr->tval == TV_RING) && inventory[INVEN_LEFT].k_idx &&
259                 inventory[INVEN_RIGHT].k_idx)
260         {
261                 /* Restrict the choices */
262                 item_tester_tval = TV_RING;
263                 item_tester_no_ryoute = TRUE;
264
265                 /* Choose a ring from the equipment only */
266 #ifdef JP
267 q = "¤É¤Á¤é¤Î»ØÎؤȼè¤êÂؤ¨¤Þ¤¹¤«?";
268 #else
269                 q = "Replace which ring? ";
270 #endif
271
272 #ifdef JP
273 s = "¤ª¤Ã¤È¡£";
274 #else
275                 s = "Oops.";
276 #endif
277
278                 if (!get_item(&slot, q, s, (USE_EQUIP)))
279                         return;
280         }
281
282 #endif /* EASY_RING -- TNB */
283
284         if (((o_ptr->tval == TV_SHIELD) || (o_ptr->tval == TV_CARD) || (o_ptr->tval == TV_CAPTURE)) &&
285                 buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
286         {
287                 /* Restrict the choices */
288                 item_tester_hook = item_tester_hook_melee_weapon;
289                 item_tester_no_ryoute = TRUE;
290
291                 /* Choose a weapon from the equipment only */
292 #ifdef JP
293 q = "¤É¤Á¤é¤ÎÉð´ï¤È¼è¤êÂؤ¨¤Þ¤¹¤«?";
294 #else
295                 q = "Replace which weapon? ";
296 #endif
297
298 #ifdef JP
299 s = "¤ª¤Ã¤È¡£";
300 #else
301                 s = "Oops.";
302 #endif
303
304                 if (!get_item(&slot, q, s, (USE_EQUIP)))
305                         return;
306                 if (slot == INVEN_RARM)
307                 {
308                         object_type *or_ptr = &inventory[INVEN_RARM];
309                         object_type *ol_ptr = &inventory[INVEN_LARM];
310                         object_type *otmp_ptr;
311                         object_type object_tmp;
312                         char ol_name[MAX_NLEN];
313
314                         otmp_ptr = &object_tmp;
315
316                         object_desc(ol_name, ol_ptr, FALSE, 0);
317
318                         object_copy(otmp_ptr, ol_ptr);
319                         object_copy(ol_ptr, or_ptr);
320                         object_copy(or_ptr, otmp_ptr);
321 #ifdef JP
322                         msg_format("%s¤ò%s¤Ë¹½¤¨¤Ê¤ª¤·¤¿¡£", ol_name, left_hander ? "º¸¼ê" : "±¦¼ê");
323 #else
324                         msg_format("You wield %s at %s hand.", ol_name, left_hander ? "left" : "right");
325 #endif
326
327                         slot = INVEN_LARM;
328                 }
329         }
330
331         /* ÆóÅáή¤Ë¤¹¤ë¤«¤É¤¦¤« */
332         if ((o_ptr->tval >= TV_DIGGING) && (o_ptr->tval <= TV_SWORD) && (slot == INVEN_LARM))
333         {
334 #ifdef JP
335                 if (!get_check("ÆóÅáή¤ÇÀ襤¤Þ¤¹¤«¡©"))
336 #else
337                 if (!get_check("Dual wielding? "))
338 #endif
339                 {
340                         slot = INVEN_RARM;
341                 }
342         }
343
344         if ((o_ptr->tval >= TV_DIGGING) && (o_ptr->tval <= TV_SWORD) &&
345             inventory[INVEN_LARM].k_idx &&
346                 inventory[INVEN_RARM].k_idx)
347         {
348                 /* Restrict the choices */
349                 item_tester_hook = item_tester_hook_mochikae;
350
351                 /* Choose a ring from the equipment only */
352 #ifdef JP
353 q = "¤É¤Á¤é¤Î¼ê¤ËÁõÈ÷¤·¤Þ¤¹¤«?";
354 #else
355                 q = "Equip which hand? ";
356 #endif
357
358 #ifdef JP
359 s = "¤ª¤Ã¤È¡£";
360 #else
361                 s = "Oops.";
362 #endif
363
364                 if (!get_item(&slot, q, s, (USE_EQUIP)))
365                         return;
366         }
367
368         /* Prevent wielding into a cursed slot */
369         if (cursed_p(&inventory[slot]))
370         {
371                 /* Describe it */
372                 object_desc(o_name, &inventory[slot], FALSE, 0);
373
374                 /* Message */
375 #ifdef JP
376                 msg_format("%s%s¤Ï¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£",
377                            describe_use(slot) , o_name );
378 #else
379                 msg_format("The %s you are %s appears to be cursed.",
380                            o_name, describe_use(slot));
381 #endif
382
383
384                 /* Cancel the command */
385                 return;
386         }
387
388         if (cursed_p(o_ptr) && confirm_wear &&
389             (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
390         {
391                 char dummy[MAX_NLEN+80];
392
393                 /* Describe it */
394                 object_desc(o_name, o_ptr, FALSE, 0);
395
396 #ifdef JP
397 sprintf(dummy, "ËÜÅö¤Ë%s{¼ö¤ï¤ì¤Æ¤¤¤ë}¤ò»È¤¤¤Þ¤¹¤«¡©", o_name);
398 #else
399                 sprintf(dummy, "Really use the %s {cursed}? ", o_name);
400 #endif
401
402
403                 if (!get_check(dummy))
404                         return;
405         }
406
407         if ((o_ptr->name1 == ART_STONEMASK) && object_known_p(o_ptr) && (p_ptr->prace != RACE_VAMPIRE) && (p_ptr->prace != RACE_ANDROID))
408         {
409                 char dummy[MAX_NLEN+80];
410
411                 /* Describe it */
412                 object_desc(o_name, o_ptr, FALSE, 0);
413
414 #ifdef JP
415 sprintf(dummy, "%s¤òÁõÈ÷¤¹¤ë¤ÈµÛ·ìµ´¤Ë¤Ê¤ê¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©", o_name);
416 #else
417                 msg_format("%s will transforms you into a vampire permanently when equiped.", o_name);
418                 sprintf(dummy, "Do you become a vampire?");
419 #endif
420
421
422                 if (!get_check(dummy))
423                         return;
424         }
425
426         /* Check if completed a quest */
427         for (i = 0; i < max_quests; i++)
428         {
429                 if ((quest[i].type == QUEST_TYPE_FIND_ARTIFACT) &&
430                     (quest[i].status == QUEST_STATUS_TAKEN) &&
431                     (quest[i].k_idx == o_ptr->name1))
432                 {
433                         if (record_fix_quest) do_cmd_write_nikki(NIKKI_FIX_QUEST_C, i, NULL);
434                         quest[i].status = QUEST_STATUS_COMPLETED;
435                         quest[i].complev = (byte)p_ptr->lev;
436 #ifdef JP
437 msg_print("¥¯¥¨¥¹¥È¤òãÀ®¤·¤¿¡ª");
438 #else
439                         msg_print("You completed the quest!");
440 #endif
441
442                         msg_print(NULL);
443                 }
444         }
445
446         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN) identify_item(o_ptr);
447
448         /* Take a turn */
449         energy_use = 100;
450
451         /* Get local object */
452         q_ptr = &forge;
453
454         /* Obtain local object */
455         object_copy(q_ptr, o_ptr);
456
457         /* Modify quantity */
458         q_ptr->number = 1;
459
460         /* Decrease the item (from the pack) */
461         if (item >= 0)
462         {
463                 inven_item_increase(item, -1);
464                 inven_item_optimize(item);
465         }
466
467         /* Decrease the item (from the floor) */
468         else
469         {
470                 floor_item_increase(0 - item, -1);
471                 floor_item_optimize(0 - item);
472         }
473
474         /* Access the wield slot */
475         o_ptr = &inventory[slot];
476
477         /* Take off existing item */
478         if (o_ptr->k_idx)
479         {
480                 /* Take off existing item */
481                 (void)inven_takeoff(slot, 255);
482         }
483
484         /* Wear the new stuff */
485         object_copy(o_ptr, q_ptr);
486
487         /* Increase the weight */
488         p_ptr->total_weight += q_ptr->weight;
489
490         /* Increment the equip counter by hand */
491         equip_cnt++;
492
493         /* Where is the item now */
494         if (slot == INVEN_RARM)
495         {
496                 if((o_ptr->tval != TV_SHIELD) && (o_ptr->tval != TV_CAPTURE) && (o_ptr->tval != TV_CARD) && (empty_hands(FALSE) & 0x00000001) && ((o_ptr->weight > 99) || (o_ptr->tval == TV_POLEARM)) && (!p_ptr->riding || (p_ptr->pet_extra_flags & PF_RYOUTE)))
497 #ifdef JP
498                         act = "¤òξ¼ê¤Ç¹½¤¨¤¿";
499 #else
500                         act = "You are wielding";
501 #endif
502                 else
503 #ifdef JP
504                         act = (left_hander ? "¤òº¸¼ê¤ËÁõÈ÷¤·¤¿" : "¤ò±¦¼ê¤ËÁõÈ÷¤·¤¿");
505 #else
506                         act = "You are wielding";
507 #endif
508
509         }
510         else if (slot == INVEN_LARM)
511         {
512 #ifdef JP
513                 act = (left_hander ? "¤ò±¦¼ê¤ËÁõÈ÷¤·¤¿" : "¤òº¸¼ê¤ËÁõÈ÷¤·¤¿");
514 #else
515                 act = "You are wielding";
516 #endif
517
518         }
519         else if (slot == INVEN_BOW)
520         {
521 #ifdef JP
522                 act = "¤ò¼Í·âÍѤËÁõÈ÷¤·¤¿";
523 #else
524                 act = "You are shooting with";
525 #endif
526
527         }
528         else if (slot == INVEN_LITE)
529         {
530 #ifdef JP
531                 act = "¤ò¸÷¸»¤Ë¤·¤¿";
532 #else
533                 act = "Your light source is";
534 #endif
535
536         }
537         else
538         {
539 #ifdef JP
540                 act = "¤òÁõÈ÷¤·¤¿";
541 #else
542                 act = "You are wearing";
543 #endif
544
545         }
546
547         /* Describe the result */
548         object_desc(o_name, o_ptr, TRUE, 3);
549
550         /* Message */
551 #ifdef JP
552         msg_format("%s(%c)%s¡£", o_name, index_to_label(slot), act );
553 #else
554         msg_format("%s %s (%c).", act, o_name, index_to_label(slot));
555 #endif
556
557
558         /* Cursed! */
559         if (cursed_p(o_ptr))
560         {
561                 /* Warn the player */
562 #ifdef JP
563                 msg_print("¤¦¤ï¡ª ¤¹¤µ¤Þ¤¸¤¯Î䤿¤¤¡ª");
564 #else
565                 msg_print("Oops! It feels deathly cold!");
566 #endif
567
568
569                 chg_virtue(V_HARMONY, -1);
570
571                 /* Note the curse */
572                 o_ptr->ident |= (IDENT_SENSE);
573         }
574
575         if ((o_ptr->name1 == ART_STONEMASK) && (p_ptr->prace != RACE_VAMPIRE) && (p_ptr->prace != RACE_ANDROID))
576         {
577                 int h_percent;
578                 if (p_ptr->prace < 32)
579                 {
580                         p_ptr->old_race1 |= 1L << p_ptr->prace;
581                 }
582                 else
583                 {
584                         p_ptr->old_race2 = 1L << (p_ptr->prace-32);
585                 }
586                 p_ptr->prace = RACE_VAMPIRE;
587 #ifdef JP
588                 msg_format("¤¢¤Ê¤¿¤ÏµÛ·ìµ´¤ËÊѲ½¤·¤¿¡ª");
589 #else
590                 msg_format("You polymorphed into a vampire!");
591 #endif
592
593                 rp_ptr = &race_info[p_ptr->prace];
594
595                 /* Experience factor */
596                 p_ptr->expfact = rp_ptr->r_exp + cp_ptr->c_exp;
597
598                 /* Calculate the height/weight for males */
599                 if (p_ptr->psex == SEX_MALE)
600                 {
601                         p_ptr->ht = randnor(rp_ptr->m_b_ht, rp_ptr->m_m_ht);
602                         h_percent = (int)(p_ptr->ht) * 100 / (int)(rp_ptr->m_b_ht);
603                         p_ptr->wt = randnor((int)(rp_ptr->m_b_wt) * h_percent /100
604                                             , (int)(rp_ptr->m_m_wt) * h_percent / 300 );
605                 }
606
607                 /* Calculate the height/weight for females */
608                 else if (p_ptr->psex == SEX_FEMALE)
609                 {
610                         p_ptr->ht = randnor(rp_ptr->f_b_ht, rp_ptr->f_m_ht);
611                         h_percent = (int)(p_ptr->ht) * 100 / (int)(rp_ptr->f_b_ht);
612                         p_ptr->wt = randnor((int)(rp_ptr->f_b_wt) * h_percent /100
613                                             , (int)(rp_ptr->f_m_wt) * h_percent / 300 );
614                 }
615
616                 check_experience();
617
618                 /* Hitdice */
619                 if (p_ptr->pclass == CLASS_SORCERER)
620                         p_ptr->hitdie = rp_ptr->r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
621                 else
622                         p_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
623
624                 do_cmd_rerate(FALSE);
625
626                 p_ptr->redraw |= (PR_BASIC);
627
628                 p_ptr->update |= (PU_BONUS);
629
630                 handle_stuff();
631                 lite_spot(py, px);
632         }
633
634         /* Recalculate bonuses */
635         p_ptr->update |= (PU_BONUS);
636
637         /* Recalculate torch */
638         p_ptr->update |= (PU_TORCH);
639
640         /* Recalculate mana */
641         p_ptr->update |= (PU_MANA);
642
643         p_ptr->redraw |= (PR_EQUIPPY);
644
645         /* Window stuff */
646         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
647
648         calc_android_exp();
649 }
650
651
652 void kamaenaoshi(int item)
653 {
654         object_type *o_ptr, *o2_ptr;
655         char o_name[MAX_NLEN];
656
657         if ((item == INVEN_RARM) && buki_motteruka(INVEN_LARM))
658         {
659                 o_ptr = &inventory[INVEN_RARM];
660                 o2_ptr = &inventory[INVEN_LARM];
661                 object_copy(o_ptr, o2_ptr);
662                 p_ptr->total_weight += o2_ptr->weight;
663                 inven_item_increase(INVEN_LARM,-1);
664                 inven_item_optimize(INVEN_LARM);
665                 object_desc(o_name, o_ptr, TRUE, 3);
666                 if (((o_ptr->weight > 99) || (o_ptr->tval == TV_POLEARM)) && (!p_ptr->riding || (p_ptr->pet_extra_flags & PF_RYOUTE)))
667 #ifdef JP
668                         msg_format("%s¤òξ¼ê¤Ç¹½¤¨¤¿¡£", o_name );
669 #else
670                         msg_format("You are wielding %s with two-handed.", o_name );
671 #endif
672                  else
673 #ifdef JP
674                         msg_format("%s¤ò%s¤Ç¹½¤¨¤¿¡£", o_name, (left_hander ? "º¸¼ê" : "±¦¼ê"));
675 #else
676                         msg_format("You are wielding %s with %s hand.", o_name, (left_hander ? "left":"right") );
677 #endif
678         }
679         else if ((item == INVEN_LARM) && buki_motteruka(INVEN_RARM))
680         {
681                 o_ptr = &inventory[INVEN_RARM];
682                 object_desc(o_name, o_ptr, TRUE, 3);
683                 if (((o_ptr->weight > 99) || (o_ptr->tval == TV_POLEARM)) && (!p_ptr->riding || (p_ptr->pet_extra_flags & PF_RYOUTE)))
684 #ifdef JP
685                         msg_format("%s¤òξ¼ê¤Ç¹½¤¨¤¿¡£", o_name );
686 #else
687                         msg_format("You are wielding %s with two-handed.", o_name );
688 #endif
689         }
690         else if ((item == INVEN_LARM) && !(empty_hands(FALSE) & 0x0002))
691         {
692                 o_ptr = &inventory[INVEN_LARM];
693                 o2_ptr = &inventory[INVEN_RARM];
694                 object_copy(o_ptr, o2_ptr);
695                 p_ptr->total_weight += o2_ptr->weight;
696                 inven_item_increase(INVEN_RARM,-1);
697                 inven_item_optimize(INVEN_RARM);
698                 object_desc(o_name, o_ptr, TRUE, 3);
699 #ifdef JP
700                 msg_format("%s¤ò»ý¤ÁÂؤ¨¤¿¡£", o_name );
701 #else
702                 msg_format("You switched hand of %s.", o_name );
703 #endif
704         }
705 }
706
707
708 /*
709  * Take off an item
710  */
711 void do_cmd_takeoff(void)
712 {
713         int item;
714
715         object_type *o_ptr;
716
717         cptr q, s;
718
719         if (p_ptr->special_defense & KATA_MUSOU)
720         {
721                 set_action(ACTION_NONE);
722         }
723
724         item_tester_no_ryoute = TRUE;
725         /* Get an item */
726 #ifdef JP
727         q = "¤É¤ì¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤Þ¤¹¤«? ";
728         s = "¤Ï¤º¤»¤ëÁõÈ÷¤¬¤Ê¤¤¡£";
729 #else
730         q = "Take off which item? ";
731         s = "You are not wearing anything to take off.";
732 #endif
733
734         if (!get_item(&item, q, s, (USE_EQUIP))) return;
735
736         /* Get the item (in the pack) */
737         if (item >= 0)
738         {
739                 o_ptr = &inventory[item];
740         }
741
742         /* Get the item (on the floor) */
743         else
744         {
745                 o_ptr = &o_list[0 - item];
746         }
747
748
749         /* Item is cursed */
750         if (cursed_p(o_ptr))
751         {
752                 if ((o_ptr->curse_flags & TRC_PERMA_CURSE) || (p_ptr->pclass != CLASS_BERSERKER))
753                 {
754                         /* Oops */
755 #ifdef JP
756                         msg_print("¤Õ¡¼¤à¡¢¤É¤¦¤ä¤é¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£");
757 #else
758                         msg_print("Hmmm, it seems to be cursed.");
759 #endif
760
761                         /* Nope */
762                         return;
763                 }
764
765                 if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && one_in_(7)) || one_in_(4))
766                 {
767 #ifdef JP
768                         msg_print("¼ö¤ï¤ì¤¿ÁõÈ÷¤òÎϤŤ¯¤ÇÇí¤¬¤·¤¿¡ª");
769 #else
770                         msg_print("You teared a cursed equipment off by sheer strength!");
771 #endif
772
773                         /* Hack -- Assume felt */
774                         o_ptr->ident |= (IDENT_SENSE);
775
776                         o_ptr->curse_flags = 0L;
777
778                         /* Take note */
779                         o_ptr->feeling = FEEL_NONE;
780
781                         /* Recalculate the bonuses */
782                         p_ptr->update |= (PU_BONUS);
783
784                         /* Window stuff */
785                         p_ptr->window |= (PW_EQUIP);
786
787 #ifdef JP
788                         msg_print("¼ö¤¤¤òÂǤÁÇˤä¿¡£");
789 #else
790                         msg_print("You break the curse.");
791 #endif
792                 }
793                 else
794                 {
795 #ifdef JP
796                         msg_print("ÁõÈ÷¤ò³°¤»¤Ê¤«¤Ã¤¿¡£");
797 #else
798                         msg_print("You couldn't remove the equipment.");
799 #endif
800                         energy_use = 50;
801                         return;
802                 }
803         }
804
805         /* Take a partial turn */
806         energy_use = 50;
807
808         /* Take off the item */
809         (void)inven_takeoff(item, 255);
810
811         kamaenaoshi(item);
812
813         calc_android_exp();
814
815         p_ptr->redraw |= (PR_EQUIPPY);
816 }
817
818
819 /*
820  * Drop an item
821  */
822 void do_cmd_drop(void)
823 {
824         int item, amt = 1;
825
826         object_type *o_ptr;
827
828         cptr q, s;
829
830         if (p_ptr->special_defense & KATA_MUSOU)
831         {
832                 set_action(ACTION_NONE);
833         }
834
835         item_tester_no_ryoute = TRUE;
836         /* Get an item */
837 #ifdef JP
838         q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÍî¤È¤·¤Þ¤¹¤«? ";
839         s = "Íî¤È¤»¤ë¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
840 #else
841         q = "Drop which item? ";
842         s = "You have nothing to drop.";
843 #endif
844
845         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN))) return;
846
847         /* Get the item (in the pack) */
848         if (item >= 0)
849         {
850                 o_ptr = &inventory[item];
851         }
852
853         /* Get the item (on the floor) */
854         else
855         {
856                 o_ptr = &o_list[0 - item];
857         }
858
859
860         /* Hack -- Cannot remove cursed items */
861         if ((item >= INVEN_RARM) && cursed_p(o_ptr))
862         {
863                 /* Oops */
864 #ifdef JP
865                 msg_print("¤Õ¡¼¤à¡¢¤É¤¦¤ä¤é¼ö¤ï¤ì¤Æ¤¤¤ë¤è¤¦¤À¡£");
866 #else
867                 msg_print("Hmmm, it seems to be cursed.");
868 #endif
869
870
871                 /* Nope */
872                 return;
873         }
874
875
876         /* See how many items */
877         if (o_ptr->number > 1)
878         {
879                 /* Get a quantity */
880                 amt = get_quantity(NULL, o_ptr->number);
881
882                 /* Allow user abort */
883                 if (amt <= 0) return;
884         }
885
886
887         /* Take a partial turn */
888         energy_use = 50;
889
890         /* Drop (some of) the item */
891         inven_drop(item, amt);
892
893         if ((item == INVEN_RARM) || (item == INVEN_LARM)) kamaenaoshi(item);
894
895         if (item >= INVEN_RARM) calc_android_exp();
896
897         p_ptr->redraw |= (PR_EQUIPPY);
898 }
899
900
901 static bool high_level_book(object_type *o_ptr)
902 {
903         if ((o_ptr->tval == TV_LIFE_BOOK) ||
904             (o_ptr->tval == TV_SORCERY_BOOK) ||
905             (o_ptr->tval == TV_NATURE_BOOK) ||
906             (o_ptr->tval == TV_CHAOS_BOOK) ||
907             (o_ptr->tval == TV_DEATH_BOOK) ||
908             (o_ptr->tval == TV_TRUMP_BOOK) ||
909             (o_ptr->tval == TV_ENCHANT_BOOK) ||
910             (o_ptr->tval == TV_DAEMON_BOOK) ||
911             (o_ptr->tval == TV_CRUSADE_BOOK) ||
912             (o_ptr->tval == TV_MUSIC_BOOK))
913         {
914                 if (o_ptr->sval > 1)
915                         return TRUE;
916                 else
917                         return FALSE;
918         }
919
920         return FALSE;
921 }
922
923
924 /*
925  * Destroy an item
926  */
927 void do_cmd_destroy(void)
928 {
929         int                     item, amt = 1;
930         int                     old_number;
931
932         bool            force = FALSE;
933
934         object_type             *o_ptr;
935         object_type             forge;
936         object_type             *q_ptr = &forge;
937
938         char            o_name[MAX_NLEN];
939
940         char            out_val[MAX_NLEN+40];
941
942         cptr q, s;
943
944         if (p_ptr->special_defense & KATA_MUSOU)
945         {
946                 set_action(ACTION_NONE);
947         }
948
949         /* Hack -- force destruction */
950         if (command_arg > 0) force = TRUE;
951
952
953         /* Get an item */
954 #ifdef JP
955         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò²õ¤·¤Þ¤¹¤«? ";
956         s = "²õ¤»¤ë¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
957 #else
958         q = "Destroy which item? ";
959         s = "You have nothing to destroy.";
960 #endif
961
962         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
963
964         /* Get the item (in the pack) */
965         if (item >= 0)
966         {
967                 o_ptr = &inventory[item];
968         }
969
970         /* Get the item (on the floor) */
971         else
972         {
973                 o_ptr = &o_list[0 - item];
974         }
975
976
977         /* See how many items */
978         if (o_ptr->number > 1)
979         {
980                 /* Get a quantity */
981                 amt = get_quantity(NULL, o_ptr->number);
982
983                 /* Allow user abort */
984                 if (amt <= 0) return;
985         }
986
987
988         /* Describe the object */
989         old_number = o_ptr->number;
990         o_ptr->number = amt;
991         object_desc(o_name, o_ptr, TRUE, 3);
992         o_ptr->number = old_number;
993
994         /* Verify unless quantity given */
995         if (!force)
996         {
997                 if (confirm_destroy || (object_value(o_ptr) > 0))
998                 {
999                         /* Make a verification */
1000 #ifdef JP
1001                 sprintf(out_val, "ËÜÅö¤Ë%s¤ò²õ¤·¤Þ¤¹¤«? ", o_name);
1002 #else
1003                         sprintf(out_val, "Really destroy %s? ", o_name);
1004 #endif
1005
1006                         if (!get_check(out_val)) return;
1007                 }
1008         }
1009
1010         /* Take a turn */
1011         energy_use = 100;
1012
1013         /* Artifacts cannot be destroyed */
1014         if (!can_player_destroy_object(o_ptr))
1015         {
1016                 energy_use = 0;
1017
1018                 /* Message */
1019 #ifdef JP
1020                 msg_format("%s¤ÏÇ˲õÉÔ²Äǽ¤À¡£", o_name);
1021 #else
1022                 msg_format("You cannot destroy %s.", o_name);
1023 #endif
1024
1025                 /* Done */
1026                 return;
1027         }
1028
1029         object_copy(q_ptr, o_ptr);
1030
1031         /* Message */
1032 #ifdef JP
1033         msg_format("%s¤ò²õ¤·¤¿¡£", o_name);
1034 #else
1035         msg_format("You destroy %s.", o_name);
1036 #endif
1037
1038         sound(SOUND_DESTITEM);
1039
1040         /* Reduce the charges of rods/wands */
1041         reduce_charges(o_ptr, amt);
1042
1043         /* Eliminate the item (from the pack) */
1044         if (item >= 0)
1045         {
1046                 inven_item_increase(item, -amt);
1047                 inven_item_describe(item);
1048                 inven_item_optimize(item);
1049         }
1050
1051         /* Eliminate the item (from the floor) */
1052         else
1053         {
1054                 floor_item_increase(0 - item, -amt);
1055                 floor_item_describe(0 - item);
1056                 floor_item_optimize(0 - item);
1057         }
1058
1059         if (high_level_book(q_ptr))
1060         {
1061                 bool gain_expr = FALSE;
1062
1063                 if (p_ptr->prace == RACE_ANDROID)
1064                 {
1065                 }
1066                 else if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_BERSERKER))
1067                 {
1068                         gain_expr = TRUE;
1069                 }
1070                 else if (p_ptr->pclass == CLASS_PALADIN)
1071                 {
1072                         if (is_good_realm(p_ptr->realm1))
1073                         {
1074                                 if (!is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE;
1075                         }
1076                         else
1077                         {
1078                                 if (is_good_realm(tval2realm(q_ptr->tval))) gain_expr = TRUE;
1079                         }
1080                 }
1081
1082                 if (gain_expr && (p_ptr->exp < PY_MAX_EXP))
1083                 {
1084                         s32b tester_exp = p_ptr->max_exp / 20;
1085                         if (tester_exp > 10000) tester_exp = 10000;
1086                         if (q_ptr->sval < 3) tester_exp /= 4;
1087                         if (tester_exp<1) tester_exp = 1;
1088
1089 #ifdef JP
1090 msg_print("¹¹¤Ë·Ð¸³¤òÀѤó¤À¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
1091 #else
1092                         msg_print("You feel more experienced.");
1093 #endif
1094
1095                         gain_exp(tester_exp * amt);
1096                 }
1097                 if (high_level_book(q_ptr) && q_ptr->tval == TV_LIFE_BOOK)
1098                 {
1099                         chg_virtue(V_UNLIFE, 1);
1100                         chg_virtue(V_VITALITY, -1);
1101                 }
1102                 else if (high_level_book(q_ptr) && q_ptr->tval == TV_DEATH_BOOK)
1103                 {
1104                         chg_virtue(V_UNLIFE, -1);
1105                         chg_virtue(V_VITALITY, 1);
1106                 }
1107         
1108                 if (q_ptr->to_a || q_ptr->to_h || q_ptr->to_d)
1109                         chg_virtue(V_ENCHANT, -1);
1110         
1111                 if (object_value_real(q_ptr) > 30000)
1112                         chg_virtue(V_SACRIFICE, 2);
1113         
1114                 else if (object_value_real(q_ptr) > 10000)
1115                         chg_virtue(V_SACRIFICE, 1);
1116         }
1117
1118         if (q_ptr->to_a != 0 || q_ptr->to_d != 0 || q_ptr->to_h != 0)
1119                 chg_virtue(V_HARMONY, 1);
1120
1121         if (item >= INVEN_RARM) calc_android_exp();
1122 }
1123
1124
1125 /*
1126  * Observe an item which has been *identify*-ed
1127  */
1128 void do_cmd_observe(void)
1129 {
1130         int                     item;
1131
1132         object_type             *o_ptr;
1133
1134         char            o_name[MAX_NLEN];
1135
1136         cptr q, s;
1137
1138         item_tester_no_ryoute = TRUE;
1139         /* Get an item */
1140 #ifdef JP
1141         q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤Þ¤¹¤«? ";
1142         s = "Ä´¤Ù¤é¤ì¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
1143 #else
1144         q = "Examine which item? ";
1145         s = "You have nothing to examine.";
1146 #endif
1147
1148         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1149
1150         /* Get the item (in the pack) */
1151         if (item >= 0)
1152         {
1153                 o_ptr = &inventory[item];
1154         }
1155
1156         /* Get the item (on the floor) */
1157         else
1158         {
1159                 o_ptr = &o_list[0 - item];
1160         }
1161
1162
1163         /* Require full knowledge */
1164         if (!(o_ptr->ident & IDENT_MENTAL))
1165         {
1166 #ifdef JP
1167                 msg_print("¤³¤Î¥¢¥¤¥Æ¥à¤Ë¤Ä¤¤¤ÆÆäËÃΤäƤ¤¤ë¤³¤È¤Ï¤Ê¤¤¡£");
1168 #else
1169                 msg_print("You have no special knowledge about that item.");
1170 #endif
1171
1172                 return;
1173         }
1174
1175
1176         /* Description */
1177         object_desc(o_name, o_ptr, TRUE, 3);
1178
1179         /* Describe */
1180 #ifdef JP
1181         msg_format("%s¤òÄ´¤Ù¤Æ¤¤¤ë...", o_name);
1182 #else
1183         msg_format("Examining %s...", o_name);
1184 #endif
1185
1186         /* Describe it fully */
1187 #ifdef JP
1188         if (!identify_fully_aux(o_ptr)) msg_print("ÆäËÊѤï¤Ã¤¿¤È¤³¤í¤Ï¤Ê¤¤¤è¤¦¤À¡£");
1189 #else
1190         if (!identify_fully_aux(o_ptr)) msg_print("You see nothing special.");
1191 #endif
1192
1193 }
1194
1195
1196
1197 /*
1198  * Remove the inscription from an object
1199  * XXX Mention item (when done)?
1200  */
1201 void do_cmd_uninscribe(void)
1202 {
1203         int   item;
1204
1205         object_type *o_ptr;
1206
1207         cptr q, s;
1208
1209         item_tester_no_ryoute = TRUE;
1210         /* Get an item */
1211 #ifdef JP
1212         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ÎÌäò¾Ã¤·¤Þ¤¹¤«? ";
1213         s = "Ìäò¾Ã¤»¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
1214 #else
1215         q = "Un-inscribe which item? ";
1216         s = "You have nothing to un-inscribe.";
1217 #endif
1218
1219         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1220
1221         /* Get the item (in the pack) */
1222         if (item >= 0)
1223         {
1224                 o_ptr = &inventory[item];
1225         }
1226
1227         /* Get the item (on the floor) */
1228         else
1229         {
1230                 o_ptr = &o_list[0 - item];
1231         }
1232
1233         /* Nothing to remove */
1234         if (!o_ptr->inscription)
1235         {
1236 #ifdef JP
1237                 msg_print("¤³¤Î¥¢¥¤¥Æ¥à¤Ë¤Ï¾Ã¤¹¤Ù¤­Ì䬤ʤ¤¡£");
1238 #else
1239                 msg_print("That item had no inscription to remove.");
1240 #endif
1241
1242                 return;
1243         }
1244
1245         /* Message */
1246 #ifdef JP
1247         msg_print("Ìäò¾Ã¤·¤¿¡£");
1248 #else
1249         msg_print("Inscription removed.");
1250 #endif
1251
1252
1253         /* Remove the incription */
1254         o_ptr->inscription = 0;
1255
1256         /* Combine the pack */
1257         p_ptr->notice |= (PN_COMBINE);
1258
1259         /* Window stuff */
1260         p_ptr->window |= (PW_INVEN | PW_EQUIP);
1261
1262         /* .¤ä$¤Î´Ø·¸¤Ç, ºÆ·×»»¤¬É¬ÍפʤϤº -- henkma */
1263         p_ptr->update |= (PU_BONUS);
1264
1265 }
1266
1267 /*
1268  * Auto flag inscribe
1269  */
1270
1271 typedef struct flag_insc_table
1272 {
1273 #ifdef JP
1274         cptr japanese;
1275 #endif
1276         cptr english;
1277         int flag;
1278         u32b except_flag;
1279 } flag_insc_table;
1280
1281 #ifdef JP
1282 static flag_insc_table flag_insc_plus[] =
1283 {
1284         { "¹¶", "At", TR_BLOWS, -1 },
1285         { "®", "Sp", TR_SPEED, -1 },
1286         { "ÏÓ", "St", TR_STR, -1 },
1287         { "ÃÎ", "In", TR_INT, -1 },
1288         { "¸­", "Wi", TR_WIS, -1 },
1289         { "´ï", "Dx", TR_DEX, -1 },
1290         { "ÂÑ", "Cn", TR_CON, -1 },
1291         { "̥", "Ch", TR_CHR, -1 },
1292         { "±£", "Sl", TR_STEALTH, -1 },
1293         { "õ", "Sr", TR_SEARCH, -1 },
1294         { "ÀÖ", "If", TR_INFRA, -1 },
1295         { "·¡", "Dg", TR_TUNNEL, -1 },
1296         { NULL, NULL, 0, -1 }
1297 };
1298
1299 static flag_insc_table flag_insc_immune[] =
1300 {
1301         { "»À", "Ac", TR_IM_ACID, -1 },
1302         { "ÅÅ", "El", TR_IM_ELEC, -1 },
1303         { "²Ð", "Fi", TR_IM_FIRE, -1 },
1304         { "Îä", "Co", TR_IM_COLD, -1 },
1305         { NULL, NULL, 0, -1 }
1306 };
1307
1308 static flag_insc_table flag_insc_resistance[] =
1309 {
1310         { "»À", "Ac", TR_RES_ACID, TR_IM_ACID },
1311         { "ÅÅ", "El", TR_RES_ELEC, TR_IM_ELEC },
1312         { "²Ð", "Fi", TR_RES_FIRE, TR_IM_FIRE },
1313         { "Îä", "Co", TR_RES_COLD, TR_IM_COLD },
1314         { "ÆÇ", "Po", TR_RES_POIS, -1 },
1315         { "Á®", "Li", TR_RES_LITE, -1 },
1316         { "°Å", "Dk", TR_RES_DARK, -1 },
1317         { "ÇË", "Sh", TR_RES_SHARDS, -1 },
1318         { "ÌÕ", "Bl", TR_RES_BLIND, -1 },
1319         { "Íð", "Cf", TR_RES_CONF, -1 },
1320         { "¹ì", "So", TR_RES_SOUND, -1 },
1321         { "¹ö", "Nt", TR_RES_NETHER, -1 },
1322         { "°ø", "Nx", TR_RES_NEXUS, -1 },
1323         { "ÆÙ", "Ca", TR_RES_CHAOS, -1 },
1324         { "Îô", "Di", TR_RES_DISEN, -1 },
1325         { "¶²", "Fe", TR_RES_FEAR, -1 },
1326         { NULL, NULL, 0, -1 }
1327 };
1328
1329 static flag_insc_table flag_insc_misc[] =
1330 {
1331         { "ËâÎÏ", "Ma", TR_DEC_MANA, -1 },
1332         { "Åê", "Th", TR_THROW, -1 },
1333         { "ȿ", "Rf", TR_REFLECT, -1 },
1334         { "Ëã", "Fa", TR_FREE_ACT, -1 },
1335         { "»ë", "Si", TR_SEE_INVIS, -1 },
1336         { "·Ð", "Hl", TR_HOLD_LIFE, -1 },
1337         { "ÃÙ", "Sd", TR_SLOW_DIGEST, -1 },
1338         { "³è", "Rg", TR_REGEN, -1 },
1339         { "Éâ", "Lv", TR_FEATHER, -1 },
1340         { "ÌÀ", "Lu", TR_LITE, -1 },
1341         { "·Ù", "Wr", TR_WARNING, -1 },
1342         { "ÇÜ", "Xm", TR_XTRA_MIGHT, -1 },
1343         { "¼Í", "Xs", TR_XTRA_SHOTS, -1 },
1344         { "ÅÜ", "Ag", TR_AGGRAVATE, -1 },
1345         { "½Ë", "Bs", TR_BLESSED, -1 },
1346 #if 0
1347         { "±Ê¼ö", "Pc", TR_PERMA_CURSE, -1 },
1348         { "¼ö", "Cu", TR_HEAVY_CURSE, TR_PERMA_CURSE },
1349         { "´÷", "Ty", TR_TY_CURSE, -1 },
1350 #endif
1351         { NULL, NULL, 0, -1 }
1352 };
1353
1354 static flag_insc_table flag_insc_aura[] =
1355 {
1356         { "±ê", "F", TR_SH_FIRE, -1 },
1357         { "ÅÅ", "E", TR_SH_ELEC, -1 },
1358         { "Îä", "C", TR_SH_COLD, -1 },
1359         { "Ëâ", "M", TR_NO_MAGIC, -1 },
1360         { "½Ö", "T", TR_NO_TELE, -1 },
1361         { NULL, NULL, 0, -1 }
1362 };
1363
1364 static flag_insc_table flag_insc_brand[] =
1365 {
1366         { "»À", "A", TR_BRAND_ACID, -1 },
1367         { "ÅÅ", "E", TR_BRAND_ELEC, -1 },
1368         { "¾Æ", "F", TR_BRAND_FIRE, -1 },
1369         { "Åà", "Co", TR_BRAND_COLD, -1 },
1370         { "ÆÇ", "P", TR_BRAND_POIS, -1 },
1371         { "ÆÙ", "Ca", TR_CHAOTIC, -1 },
1372         { "µÛ", "V", TR_VAMPIRIC, -1 },
1373         { "¿Ì", "Q", TR_IMPACT, -1 },
1374         { "ÀÚ", "S", TR_VORPAL, -1 },
1375         { "Íý", "M", TR_FORCE_WEAPON, -1 },
1376         { NULL, NULL, 0, -1 }
1377 };
1378
1379 static flag_insc_table flag_insc_kill[] =
1380 {
1381         { "¼Ù", "*", TR_KILL_EVIL, -1 },
1382         { "¿Í", "p", TR_KILL_HUMAN, -1 },
1383         { "ζ", "D", TR_KILL_DRAGON, -1 },
1384         { "¥ª", "o", TR_KILL_ORC, -1 },
1385         { "¥È", "T", TR_KILL_TROLL, -1 },
1386         { "µð", "P", TR_KILL_GIANT, -1 },
1387         { "¥Ç", "U", TR_KILL_DEMON, -1 },
1388         { "»à", "L", TR_KILL_UNDEAD, -1 },
1389         { "ư", "Z", TR_KILL_ANIMAL, -1 },
1390         { NULL, NULL, 0, -1 }
1391 };
1392
1393 static flag_insc_table flag_insc_slay[] =
1394 {
1395         { "¼Ù", "*", TR_SLAY_EVIL, TR_KILL_EVIL },
1396         { "¿Í", "p", TR_SLAY_HUMAN, TR_KILL_HUMAN },
1397         { "ε", "D", TR_SLAY_DRAGON, TR_KILL_DRAGON },
1398         { "¥ª", "o", TR_SLAY_ORC, TR_KILL_ORC },
1399         { "¥È", "T", TR_SLAY_TROLL, TR_KILL_TROLL },
1400         { "µð", "P", TR_SLAY_GIANT, TR_KILL_GIANT },
1401         { "¥Ç", "U", TR_SLAY_DEMON, TR_KILL_DEMON },
1402         { "»à", "L", TR_SLAY_UNDEAD, TR_KILL_UNDEAD },
1403         { "ư", "Z", TR_SLAY_ANIMAL, TR_KILL_ANIMAL },
1404         { NULL, NULL, 0, -1 }
1405 };
1406
1407 static flag_insc_table flag_insc_esp1[] =
1408 {
1409         { "´¶", "Tele", TR_TELEPATHY, -1 },
1410         { "¼Ù", "Evil", TR_ESP_EVIL, -1 },
1411         { "Á±", "Good", TR_ESP_GOOD, -1 },
1412         { "̵", "Nolv", TR_ESP_NONLIVING, -1 },
1413         { "¸Ä", "Uniq", TR_ESP_UNIQUE, -1 },
1414         { NULL, NULL, 0, -1 }
1415 };
1416
1417 static flag_insc_table flag_insc_esp2[] =
1418 {
1419         { "¿Í", "p", TR_ESP_HUMAN, -1 },
1420         { "ε", "D", TR_ESP_DRAGON, -1 },
1421         { "¥ª", "o", TR_ESP_ORC, -1 },
1422         { "¥È", "T", TR_ESP_TROLL, -1 },
1423         { "µð", "P", TR_ESP_GIANT, -1 },
1424         { "¥Ç", "U", TR_ESP_DEMON, -1 },
1425         { "»à", "L", TR_ESP_UNDEAD, -1 },
1426         { "ư", "Z", TR_ESP_ANIMAL, -1 },
1427         { NULL, NULL, 0, -1 }
1428 };
1429
1430 static flag_insc_table flag_insc_sust[] =
1431 {
1432         { "ÏÓ", "St", TR_SUST_STR, -1 },
1433         { "ÃÎ", "In", TR_SUST_INT, -1 },
1434         { "¸­", "Wi", TR_SUST_WIS, -1 },
1435         { "´ï", "Dx", TR_SUST_DEX, -1 },
1436         { "ÂÑ", "Cn", TR_SUST_CON, -1 },
1437         { "̥", "Ch", TR_SUST_CHR, -1 },
1438         { NULL, NULL, 0, -1 }
1439 };
1440
1441 #else
1442 static flag_insc_table flag_insc_plus[] =
1443 {
1444         { "At", TR_BLOWS, -1 },
1445         { "Sp", TR_SPEED, -1 },
1446         { "St", TR_STR, -1 },
1447         { "In", TR_INT, -1 },
1448         { "Wi", TR_WIS, -1 },
1449         { "Dx", TR_DEX, -1 },
1450         { "Cn", TR_CON, -1 },
1451         { "Ch", TR_CHR, -1 },
1452         { "Sl", TR_STEALTH, -1 },
1453         { "Sr", TR_SEARCH, -1 },
1454         { "If", TR_INFRA, -1 },
1455         { "Dg", TR_TUNNEL, -1 },
1456         { NULL, 0, -1 }
1457 };
1458
1459 static flag_insc_table flag_insc_immune[] =
1460 {
1461         { "Ac", TR_IM_ACID, -1 },
1462         { "El", TR_IM_ELEC, -1 },
1463         { "Fi", TR_IM_FIRE, -1 },
1464         { "Co", TR_IM_COLD, -1 },
1465         { NULL, 0, -1 }
1466 };
1467
1468 static flag_insc_table flag_insc_resistance[] =
1469 {
1470         { "Ac", TR_RES_ACID, TR_IM_ACID },
1471         { "El", TR_RES_ELEC, TR_IM_ELEC },
1472         { "Fi", TR_RES_FIRE, TR_IM_FIRE },
1473         { "Co", TR_RES_COLD, TR_IM_COLD },
1474         { "Po", TR_RES_POIS, -1 },
1475         { "Li", TR_RES_LITE, -1 },
1476         { "Dk", TR_RES_DARK, -1 },
1477         { "Sh", TR_RES_SHARDS, -1 },
1478         { "Bl", TR_RES_BLIND, -1 },
1479         { "Cf", TR_RES_CONF, -1 },
1480         { "So", TR_RES_SOUND, -1 },
1481         { "Nt", TR_RES_NETHER, -1 },
1482         { "Nx", TR_RES_NEXUS, -1 },
1483         { "Ca", TR_RES_CHAOS, -1 },
1484         { "Di", TR_RES_DISEN, -1 },
1485         { "Fe", TR_RES_FEAR, -1 },
1486         { NULL, 0, -1 }
1487 };
1488
1489 static flag_insc_table flag_insc_misc[] =
1490 {
1491         { "Ma", TR_DEC_MANA, -1 },
1492         { "Th", TR_THROW, -1 },
1493         { "Rf", TR_REFLECT, -1 },
1494         { "Fa", TR_FREE_ACT, -1 },
1495         { "Si", TR_SEE_INVIS, -1 },
1496         { "Hl", TR_HOLD_LIFE, -1 },
1497         { "Sd", TR_SLOW_DIGEST, -1 },
1498         { "Rg", TR_REGEN, -1 },
1499         { "Lv", TR_FEATHER, -1 },
1500         { "Lu", TR_LITE, -1 },
1501         { "Wr", TR_WARNING, -1 },
1502         { "Xm", TR_XTRA_MIGHT, -1 },
1503         { "Xs", TR_XTRA_SHOTS, -1 },
1504         { "Ag", TR_AGGRAVATE, -1 },
1505         { "Bs", TR_BLESSED, -1 },
1506 #if 0
1507         { "Pc", TR_PERMA_CURSE, -1 },
1508         { "Cu", TR_HEAVY_CURSE, TR_PERMA_CURSE },
1509         { "Ty", TR_TY_CURSE, -1 },
1510 #endif
1511 #if 0
1512         { "De", TR_DRAIN_EXP, -1 },
1513 #endif
1514         { NULL, 0, -1 }
1515 };
1516
1517 static flag_insc_table flag_insc_aura[] =
1518 {
1519         { "F", TR_SH_FIRE, -1 },
1520         { "E", TR_SH_ELEC, -1 },
1521         { "C", TR_SH_COLD, -1 },
1522         { "M", TR_NO_MAGIC, -1 },
1523         { "T", TR_NO_TELE, -1 },
1524         { NULL, 0, -1 }
1525 };
1526
1527 static flag_insc_table flag_insc_brand[] =
1528 {
1529         { "A", TR_BRAND_ACID, -1 },
1530         { "E", TR_BRAND_ELEC, -1 },
1531         { "F", TR_BRAND_FIRE, -1 },
1532         { "Co", TR_BRAND_COLD, -1 },
1533         { "P", TR_BRAND_POIS, -1 },
1534         { "Ca", TR_CHAOTIC, -1 },
1535         { "V", TR_VAMPIRIC, -1 },
1536         { "Q", TR_IMPACT, -1 },
1537         { "S", TR_VORPAL, -1 },
1538         { "M", TR_FORCE_WEAPON, -1 },
1539         { NULL, 0, -1 }
1540 };
1541
1542 static flag_insc_table flag_insc_kill[] =
1543 {
1544         { "*", TR_KILL_EVIL, -1 },
1545         { "p", TR_KILL_HUMAN, -1 },
1546         { "D", TR_KILL_DRAGON, -1 },
1547         { "o", TR_KILL_ORC, -1 },
1548         { "T", TR_KILL_TROLL, -1 },
1549         { "P", TR_KILL_GIANT, -1 },
1550         { "U", TR_KILL_DEMON, -1 },
1551         { "L", TR_KILL_UNDEAD, -1 },
1552         { "Z", TR_KILL_ANIMAL, -1 },
1553         { NULL, 0, -1 }
1554 };
1555
1556 static flag_insc_table flag_insc_slay[] =
1557 {
1558         { "*", TR_SLAY_EVIL, TR_KILL_EVIL },
1559         { "p", TR_SLAY_HUMAN, TR_KILL_HUMAN },
1560         { "D", TR_SLAY_DRAGON, TR_KILL_DRAGON },
1561         { "o", TR_SLAY_ORC, TR_KILL_ORC },
1562         { "T", TR_SLAY_TROLL, TR_KILL_TROLL },
1563         { "P", TR_SLAY_GIANT, TR_KILL_GIANT },
1564         { "U", TR_SLAY_DEMON, TR_KILL_DEMON },
1565         { "L", TR_SLAY_UNDEAD, TR_KILL_UNDEAD },
1566         { "Z", TR_SLAY_ANIMAL, TR_KILL_ANIMAL },
1567         { NULL, 0, -1 }
1568 };
1569
1570 static flag_insc_table flag_insc_esp1[] =
1571 {
1572         { "Tele", TR_TELEPATHY, -1 },
1573         { "Evil", TR_ESP_EVIL, -1 },
1574         { "Good", TR_ESP_GOOD, -1 },
1575         { "Nolv", TR_ESP_NONLIVING, -1 },
1576         { "Uniq", TR_ESP_UNIQUE, -1 },
1577         { NULL, 0, -1 }
1578 };
1579
1580 static flag_insc_table flag_insc_esp2[] =
1581 {
1582         { "p", TR_ESP_HUMAN, -1 },
1583         { "D", TR_ESP_DRAGON, -1 },
1584         { "o", TR_ESP_ORC, -1 },
1585         { "T", TR_ESP_TROLL, -1 },
1586         { "P", TR_ESP_GIANT, -1 },
1587         { "U", TR_ESP_DEMON, -1 },
1588         { "L", TR_ESP_UNDEAD, -1 },
1589         { "Z", TR_ESP_ANIMAL, -1 },
1590         { NULL, 0, -1 }
1591 };
1592
1593 static flag_insc_table flag_insc_sust[] =
1594 {
1595         { "St", TR_SUST_STR, -1 },
1596         { "In", TR_SUST_INT, -1 },
1597         { "Wi", TR_SUST_WIS, -1 },
1598         { "Dx", TR_SUST_DEX, -1 },
1599         { "Cn", TR_SUST_CON, -1 },
1600         { "Ch", TR_SUST_CHR, -1 },
1601         { NULL, 0, -1 }
1602 };
1603 #endif
1604
1605 #define ADD_INSC(STR) (void)(strcat(ptr, (STR)), ptr += strlen(STR))
1606
1607 static char *inscribe_flags_aux(flag_insc_table *fi_ptr, u32b flgs[TR_FLAG_SIZE], bool kanji, char *ptr)
1608 {
1609         while (fi_ptr->english)
1610         {
1611                 if (have_flag(flgs, fi_ptr->flag) &&
1612                     (fi_ptr->except_flag == -1 || !have_flag(flgs, fi_ptr->except_flag)))
1613 #ifdef JP
1614                         ADD_INSC(kanji ? fi_ptr->japanese : fi_ptr->english);
1615 #else
1616                         ADD_INSC(fi_ptr->english);
1617 #endif
1618                 fi_ptr++;
1619         }
1620
1621         return ptr;
1622 }
1623
1624 static bool have_flag_of(flag_insc_table *fi_ptr, u32b flgs[TR_FLAG_SIZE])
1625 {
1626         while (fi_ptr->english)
1627         {
1628                 if (have_flag(flgs, fi_ptr->flag) &&
1629                    (fi_ptr->except_flag == -1 || !have_flag(flgs, fi_ptr->except_flag)))
1630                         return (TRUE);
1631                 fi_ptr++;
1632         }
1633
1634         return (FALSE);
1635 }
1636
1637 s16b inscribe_flags(object_type *o_ptr, cptr out_val)
1638 {
1639         char buff[1024];
1640         char *ptr = buff;
1641         char *prev_ptr = buff;
1642         int i;
1643
1644         bool kanji = FALSE;
1645         bool all = TRUE;
1646         u32b flgs[TR_FLAG_SIZE];
1647
1648         /* not fully identified */
1649         if (!(o_ptr->ident & IDENT_MENTAL))
1650                 return quark_add(out_val);
1651
1652         /* Extract the flags */
1653         object_flags(o_ptr, flgs);
1654
1655
1656         *buff = '\0';
1657         for (i = 0; out_val[i]; i++)
1658         {
1659                 if ('%' == out_val[i] )
1660                 {
1661                         cptr start_percent = ptr;
1662 #ifdef JP
1663                         if ('%' == out_val[i+1])
1664                         {
1665                                 i++;
1666                                 kanji = FALSE;
1667                         }
1668                         else
1669                         {
1670                                 kanji = TRUE;
1671                         }
1672 #endif
1673                         if ('a' == out_val[i+1] && 'l' == out_val[i+2] && 'l' == out_val[i+3])
1674                         {
1675                                 all = TRUE;
1676                                 i += 3;
1677                         }
1678                         else
1679                         {
1680                                 all = FALSE;
1681                         }
1682
1683                         /* check for too long inscription */
1684                         if (ptr >= buff + MAX_NLEN) continue;
1685
1686                         /* Remove obvious flags */
1687                         if (!all)
1688                         {
1689                                 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1690                                 int j;
1691                                 
1692                                 /* Base object */
1693                                 for (j = 0; j < TR_FLAG_SIZE; j++)
1694                                         flgs[j] &= ~k_ptr->flags[j];
1695
1696                                 if (o_ptr->name1)
1697                                 {
1698                                         artifact_type *a_ptr = &a_info[o_ptr->name1];
1699                                         
1700                                         for (j = 0; j < TR_FLAG_SIZE; j++)
1701                                                 flgs[j] &= ~a_ptr->flags[j];
1702                                 }
1703
1704                                 if (o_ptr->name2)
1705                                 {
1706                                         bool teleport = have_flag(flgs, TR_TELEPORT);
1707                                         ego_item_type *e_ptr = &e_info[o_ptr->name2];
1708                                         
1709                                         for (j = 0; j < TR_FLAG_SIZE; j++)
1710                                                 flgs[j] &= ~e_ptr->flags[j];
1711
1712                                         /* Always inscribe {.} for random teleport */
1713                                         if (teleport) add_flag(flgs, TR_TELEPORT);
1714                                 }
1715                         }
1716
1717
1718                         /* Plusses */
1719                         if (have_flag_of(flag_insc_plus, flgs))
1720                         {
1721                                 if (kanji)
1722                                         ADD_INSC("+");
1723                         }
1724                         ptr = inscribe_flags_aux(flag_insc_plus, flgs, kanji, ptr);
1725
1726                         /* Immunity */
1727                         if (have_flag_of(flag_insc_immune, flgs))
1728                         {
1729                                 if (!kanji && ptr != prev_ptr)
1730                                 {
1731                                         ADD_INSC(";");
1732                                         prev_ptr = ptr;
1733                                 }
1734                                 ADD_INSC("*");
1735                         }
1736                         ptr = inscribe_flags_aux(flag_insc_immune, flgs, kanji, ptr);
1737
1738                         /* Resistance */
1739                         if (have_flag_of(flag_insc_resistance, flgs))
1740                         {
1741                                 if (kanji)
1742                                         ADD_INSC("r");
1743                                 else if (ptr != prev_ptr)
1744                                 {
1745                                         ADD_INSC(";");
1746                                         prev_ptr = ptr;
1747                                 }
1748                         }
1749                         ptr = inscribe_flags_aux(flag_insc_resistance, flgs, kanji, ptr);
1750
1751                         /* Misc Ability */
1752                         if (have_flag_of(flag_insc_misc, flgs))
1753                         {
1754                                 if (ptr != prev_ptr)
1755                                 {
1756                                         ADD_INSC(";");
1757                                         prev_ptr = ptr;
1758                                 }
1759                         }
1760                         ptr = inscribe_flags_aux(flag_insc_misc, flgs, kanji, ptr);
1761
1762                         /* Aura */
1763                         if (have_flag_of(flag_insc_aura, flgs))
1764                         {
1765                                 ADD_INSC("[");
1766                         }
1767                         ptr = inscribe_flags_aux(flag_insc_aura, flgs, kanji, ptr);
1768
1769                         /* Brand Weapon */
1770                         if (have_flag_of(flag_insc_brand, flgs))
1771                                 ADD_INSC("|");
1772                         ptr = inscribe_flags_aux(flag_insc_brand, flgs, kanji, ptr);
1773
1774                         /* Kill Weapon */
1775                         if (have_flag_of(flag_insc_kill, flgs))
1776                                 ADD_INSC("/X");
1777                         ptr = inscribe_flags_aux(flag_insc_kill, flgs, kanji, ptr);
1778
1779                         /* Slay Weapon */
1780                         if (have_flag_of(flag_insc_slay, flgs))
1781                                 ADD_INSC("/");
1782                         ptr = inscribe_flags_aux(flag_insc_slay, flgs, kanji, ptr);
1783
1784                         /* Esp */
1785                         if (kanji)
1786                         {
1787                                 if (have_flag_of(flag_insc_esp1, flgs) ||
1788                                     have_flag_of(flag_insc_esp2, flgs))
1789                                         ADD_INSC("~");
1790                                 ptr = inscribe_flags_aux(flag_insc_esp1, flgs, kanji, ptr);
1791                                 ptr = inscribe_flags_aux(flag_insc_esp2, flgs, kanji, ptr);
1792                         }
1793                         else
1794                         {
1795                                 if (have_flag_of(flag_insc_esp1, flgs))
1796                                         ADD_INSC("~");
1797                                 ptr = inscribe_flags_aux(flag_insc_esp1, flgs, kanji, ptr);
1798                                 if (have_flag_of(flag_insc_esp2, flgs))
1799                                         ADD_INSC("~");
1800                                 ptr = inscribe_flags_aux(flag_insc_esp2, flgs, kanji, ptr);
1801                         }
1802
1803                         /* Random Teleport */
1804                         if (have_flag(flgs, TR_TELEPORT))
1805                         {
1806                                 ADD_INSC(".");
1807                         }
1808
1809                         /* sustain */
1810                         if (have_flag_of(flag_insc_sust, flgs))
1811                         {
1812                                 ADD_INSC("(");
1813                         }
1814                         ptr = inscribe_flags_aux(flag_insc_sust, flgs, kanji, ptr);
1815
1816                         if (ptr == start_percent)
1817                                 ADD_INSC(" ");
1818                 }
1819                 else
1820                 {
1821                         *ptr++ = out_val[i];
1822                         *ptr = '\0';
1823                 }
1824         }
1825
1826         /* cut too long inscription */
1827         if (strlen(buff) >= MAX_NLEN-1)
1828         {
1829 #ifdef JP
1830                 int n;
1831                 for (n = 0; n < MAX_NLEN; n++)
1832                         if(iskanji(buff[n])) n++;
1833                 if (n == MAX_NLEN) n = MAX_NLEN-2; /* ºÇ¸å¤¬´Á»úȾʬ */
1834                 buff[n] = '\0';
1835 #else
1836                 buff[MAX_NLEN-1] = '\0';
1837 #endif
1838         }
1839
1840         return quark_add(buff);
1841 }
1842
1843 /*
1844  * Inscribe an object with a comment
1845  */
1846 void do_cmd_inscribe(void)
1847 {
1848         int                     item;
1849
1850         object_type             *o_ptr;
1851
1852         char            o_name[MAX_NLEN];
1853
1854         char            out_val[80];
1855
1856         cptr q, s;
1857
1858         item_tester_no_ryoute = TRUE;
1859         /* Get an item */
1860 #ifdef JP
1861         q = "¤É¤Î¥¢¥¤¥Æ¥à¤ËÌäò¹ï¤ß¤Þ¤¹¤«? ";
1862         s = "Ìäò¹ï¤á¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
1863 #else
1864         q = "Inscribe which item? ";
1865         s = "You have nothing to inscribe.";
1866 #endif
1867
1868         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1869
1870         /* Get the item (in the pack) */
1871         if (item >= 0)
1872         {
1873                 o_ptr = &inventory[item];
1874         }
1875
1876         /* Get the item (on the floor) */
1877         else
1878         {
1879                 o_ptr = &o_list[0 - item];
1880         }
1881
1882         /* Describe the activity */
1883         object_desc(o_name, o_ptr, TRUE, 2);
1884
1885         /* Message */
1886 #ifdef JP
1887         msg_format("%s¤ËÌäò¹ï¤à¡£", o_name);
1888 #else
1889         msg_format("Inscribing %s.", o_name);
1890 #endif
1891
1892         msg_print(NULL);
1893
1894         /* Start with nothing */
1895         strcpy(out_val, "");
1896
1897         /* Use old inscription */
1898         if (o_ptr->inscription)
1899         {
1900                 /* Start with the old inscription */
1901                 strcpy(out_val, quark_str(o_ptr->inscription));
1902         }
1903
1904         /* Get a new inscription (possibly empty) */
1905 #ifdef JP
1906         if (get_string("ÌÃ: ", out_val, 80))
1907 #else
1908         if (get_string("Inscription: ", out_val, 80))
1909 #endif
1910         {
1911                 /* Save the inscription */
1912                 o_ptr->inscription = inscribe_flags(o_ptr, out_val);
1913
1914                 /* Combine the pack */
1915                 p_ptr->notice |= (PN_COMBINE);
1916
1917                 /* Window stuff */
1918                 p_ptr->window |= (PW_INVEN | PW_EQUIP);
1919
1920                 /* .¤ä$¤Î´Ø·¸¤Ç, ºÆ·×»»¤¬É¬ÍפʤϤº -- henkma */
1921                 p_ptr->update |= (PU_BONUS);
1922         }
1923 }
1924
1925
1926
1927 /*
1928  * An "item_tester_hook" for refilling lanterns
1929  */
1930 static bool item_tester_refill_lantern(object_type *o_ptr)
1931 {
1932         /* Flasks of oil are okay */
1933         if (o_ptr->tval == TV_FLASK) return (TRUE);
1934
1935         /* Laterns are okay */
1936         if ((o_ptr->tval == TV_LITE) &&
1937             (o_ptr->sval == SV_LITE_LANTERN)) return (TRUE);
1938
1939         /* Assume not okay */
1940         return (FALSE);
1941 }
1942
1943
1944 /*
1945  * Refill the players lamp (from the pack or floor)
1946  */
1947 static void do_cmd_refill_lamp(void)
1948 {
1949         int item;
1950
1951         object_type *o_ptr;
1952         object_type *j_ptr;
1953
1954         cptr q, s;
1955
1956
1957         /* Restrict the choices */
1958         item_tester_hook = item_tester_refill_lantern;
1959
1960         /* Get an item */
1961 #ifdef JP
1962         q = "¤É¤ÎÌý¤Ä¤Ü¤«¤éÃí¤®¤Þ¤¹¤«? ";
1963         s = "Ìý¤Ä¤Ü¤¬¤Ê¤¤¡£";
1964 #else
1965         q = "Refill with which flask? ";
1966         s = "You have no flasks of oil.";
1967 #endif
1968
1969         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
1970
1971         /* Get the item (in the pack) */
1972         if (item >= 0)
1973         {
1974                 o_ptr = &inventory[item];
1975         }
1976
1977         /* Get the item (on the floor) */
1978         else
1979         {
1980                 o_ptr = &o_list[0 - item];
1981         }
1982
1983
1984         /* Take a partial turn */
1985         energy_use = 50;
1986
1987         /* Access the lantern */
1988         j_ptr = &inventory[INVEN_LITE];
1989
1990         /* Refuel */
1991         j_ptr->xtra4 += o_ptr->xtra4;
1992
1993         /* Message */
1994 #ifdef JP
1995         msg_print("¥é¥ó¥×¤ËÌý¤òÃí¤¤¤À¡£");
1996 #else
1997         msg_print("You fuel your lamp.");
1998 #endif
1999
2000         /* Comment */
2001         if ((o_ptr->name2 == EGO_LITE_DARKNESS) && (j_ptr->xtra4 > 0))
2002         {
2003                 j_ptr->xtra4 = 0;
2004 #ifdef JP
2005                 msg_print("¥é¥ó¥×¤¬¾Ã¤¨¤Æ¤·¤Þ¤Ã¤¿¡ª");
2006 #else
2007                 msg_print("Your lamp has gone out!");
2008 #endif
2009         }
2010         else if ((o_ptr->name2 == EGO_LITE_DARKNESS) || (j_ptr->name2 == EGO_LITE_DARKNESS))
2011         {
2012                 j_ptr->xtra4 = 0;
2013 #ifdef JP
2014                 msg_print("¤·¤«¤·¥é¥ó¥×¤ÏÁ´¤¯¸÷¤é¤Ê¤¤¡£");
2015 #else
2016                 msg_print("Curiously, your lamp doesn't light.");
2017 #endif
2018         }
2019         else if (j_ptr->xtra4 >= FUEL_LAMP)
2020         {
2021                 j_ptr->xtra4 = FUEL_LAMP;
2022 #ifdef JP
2023                 msg_print("¥é¥ó¥×¤ÎÌý¤Ï°ìÇÕ¤À¡£");
2024 #else
2025                 msg_print("Your lamp is full.");
2026 #endif
2027
2028         }
2029
2030         /* Decrease the item (from the pack) */
2031         if (item >= 0)
2032         {
2033                 inven_item_increase(item, -1);
2034                 inven_item_describe(item);
2035                 inven_item_optimize(item);
2036         }
2037
2038         /* Decrease the item (from the floor) */
2039         else
2040         {
2041                 floor_item_increase(0 - item, -1);
2042                 floor_item_describe(0 - item);
2043                 floor_item_optimize(0 - item);
2044         }
2045
2046         /* Recalculate torch */
2047         p_ptr->update |= (PU_TORCH);
2048 }
2049
2050
2051 /*
2052  * An "item_tester_hook" for refilling torches
2053  */
2054 static bool item_tester_refill_torch(object_type *o_ptr)
2055 {
2056         /* Torches are okay */
2057         if ((o_ptr->tval == TV_LITE) &&
2058             (o_ptr->sval == SV_LITE_TORCH)) return (TRUE);
2059
2060         /* Assume not okay */
2061         return (FALSE);
2062 }
2063
2064
2065 /*
2066  * Refuel the players torch (from the pack or floor)
2067  */
2068 static void do_cmd_refill_torch(void)
2069 {
2070         int item;
2071
2072         object_type *o_ptr;
2073         object_type *j_ptr;
2074
2075         cptr q, s;
2076
2077
2078         /* Restrict the choices */
2079         item_tester_hook = item_tester_refill_torch;
2080
2081         /* Get an item */
2082 #ifdef JP
2083         q = "¤É¤Î¾¾ÌÀ¤ÇÌÀ¤«¤ê¤ò¶¯¤á¤Þ¤¹¤«? ";
2084         s = "¾¤Ë¾¾ÌÀ¤¬¤Ê¤¤¡£";
2085 #else
2086         q = "Refuel with which torch? ";
2087         s = "You have no extra torches.";
2088 #endif
2089
2090         if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
2091
2092         /* Get the item (in the pack) */
2093         if (item >= 0)
2094         {
2095                 o_ptr = &inventory[item];
2096         }
2097
2098         /* Get the item (on the floor) */
2099         else
2100         {
2101                 o_ptr = &o_list[0 - item];
2102         }
2103
2104
2105         /* Take a partial turn */
2106         energy_use = 50;
2107
2108         /* Access the primary torch */
2109         j_ptr = &inventory[INVEN_LITE];
2110
2111         /* Refuel */
2112         j_ptr->xtra4 += o_ptr->xtra4 + 5;
2113
2114         /* Message */
2115 #ifdef JP
2116         msg_print("¾¾ÌÀ¤ò·ë¹ç¤·¤¿¡£");
2117 #else
2118         msg_print("You combine the torches.");
2119 #endif
2120
2121
2122         /* Comment */
2123         if ((o_ptr->name2 == EGO_LITE_DARKNESS) && (j_ptr->xtra4 > 0))
2124         {
2125                 j_ptr->xtra4 = 0;
2126 #ifdef JP
2127                 msg_print("¾¾ÌÀ¤¬¾Ã¤¨¤Æ¤·¤Þ¤Ã¤¿¡ª");
2128 #else
2129                 msg_print("Your torch has gone out!");
2130 #endif
2131         }
2132         else if ((o_ptr->name2 == EGO_LITE_DARKNESS) || (j_ptr->name2 == EGO_LITE_DARKNESS))
2133         {
2134                 j_ptr->xtra4 = 0;
2135 #ifdef JP
2136                 msg_print("¤·¤«¤·¾¾ÌÀ¤ÏÁ´¤¯¸÷¤é¤Ê¤¤¡£");
2137 #else
2138                 msg_print("Curiously, your torche don't light.");
2139 #endif
2140         }
2141         /* Over-fuel message */
2142         else if (j_ptr->xtra4 >= FUEL_TORCH)
2143         {
2144                 j_ptr->xtra4 = FUEL_TORCH;
2145 #ifdef JP
2146                 msg_print("¾¾ÌÀ¤Î¼÷Ì¿¤Ï½½Ê¬¤À¡£");
2147 #else
2148                 msg_print("Your torch is fully fueled.");
2149 #endif
2150
2151         }
2152
2153         /* Refuel message */
2154         else
2155         {
2156 #ifdef JP
2157                 msg_print("¾¾ÌÀ¤Ï¤¤¤Ã¤½¤¦ÌÀ¤ë¤¯µ±¤¤¤¿¡£");
2158 #else
2159                 msg_print("Your torch glows more brightly.");
2160 #endif
2161
2162         }
2163
2164         /* Decrease the item (from the pack) */
2165         if (item >= 0)
2166         {
2167                 inven_item_increase(item, -1);
2168                 inven_item_describe(item);
2169                 inven_item_optimize(item);
2170         }
2171
2172         /* Decrease the item (from the floor) */
2173         else
2174         {
2175                 floor_item_increase(0 - item, -1);
2176                 floor_item_describe(0 - item);
2177                 floor_item_optimize(0 - item);
2178         }
2179
2180         /* Recalculate torch */
2181         p_ptr->update |= (PU_TORCH);
2182 }
2183
2184
2185 /*
2186  * Refill the players lamp, or restock his torches
2187  */
2188 void do_cmd_refill(void)
2189 {
2190         object_type *o_ptr;
2191
2192         /* Get the light */
2193         o_ptr = &inventory[INVEN_LITE];
2194
2195         if (p_ptr->special_defense & KATA_MUSOU)
2196         {
2197                 set_action(ACTION_NONE);
2198         }
2199
2200         /* It is nothing */
2201         if (o_ptr->tval != TV_LITE)
2202         {
2203 #ifdef JP
2204                 msg_print("¸÷¸»¤òÁõÈ÷¤·¤Æ¤¤¤Ê¤¤¡£");
2205 #else
2206                 msg_print("You are not wielding a light.");
2207 #endif
2208
2209         }
2210
2211         /* It's a lamp */
2212         else if (o_ptr->sval == SV_LITE_LANTERN)
2213         {
2214                 do_cmd_refill_lamp();
2215         }
2216
2217         /* It's a torch */
2218         else if (o_ptr->sval == SV_LITE_TORCH)
2219         {
2220                 do_cmd_refill_torch();
2221         }
2222
2223         /* No torch to refill */
2224         else
2225         {
2226 #ifdef JP
2227                 msg_print("¤³¤Î¸÷¸»¤Ï¼÷Ì¿¤ò±ä¤Ð¤»¤Ê¤¤¡£");
2228 #else
2229                 msg_print("Your light cannot be refilled.");
2230 #endif
2231
2232         }
2233 }
2234
2235
2236 /*
2237  * Target command
2238  */
2239 void do_cmd_target(void)
2240 {
2241         /* Target set */
2242         if (target_set(TARGET_KILL))
2243         {
2244 #ifdef JP
2245                 msg_print("¥¿¡¼¥²¥Ã¥È·èÄê¡£");
2246 #else
2247                 msg_print("Target Selected.");
2248 #endif
2249
2250         }
2251
2252         /* Target aborted */
2253         else
2254         {
2255 #ifdef JP
2256                 msg_print("¥¿¡¼¥²¥Ã¥È²ò½ü¡£");
2257 #else
2258                 msg_print("Target Aborted.");
2259 #endif
2260
2261         }
2262 }
2263
2264
2265
2266 /*
2267  * Look command
2268  */
2269 void do_cmd_look(void)
2270 {
2271         /* Look around */
2272         if (target_set(TARGET_LOOK))
2273         {
2274 #ifdef JP
2275                 msg_print("¥¿¡¼¥²¥Ã¥È·èÄê¡£");
2276 #else
2277                 msg_print("Target Selected.");
2278 #endif
2279
2280         }
2281 }
2282
2283
2284
2285 /*
2286  * Allow the player to examine other sectors on the map
2287  */
2288 void do_cmd_locate(void)
2289 {
2290         int             dir, y1, x1, y2, x2;
2291
2292         char    tmp_val[80];
2293
2294         char    out_val[160];
2295
2296         int wid, hgt;
2297
2298         /* Get size */
2299         get_screen_size(&wid, &hgt);
2300
2301
2302         /* Start at current panel */
2303         y2 = y1 = panel_row_min;
2304         x2 = x1 = panel_col_min;
2305
2306         /* Show panels until done */
2307         while (1)
2308         {
2309                 /* Describe the location */
2310                 if ((y2 == y1) && (x2 == x1))
2311                 {
2312 #ifdef JP
2313                         strcpy(tmp_val, "¿¿¾å");
2314 #else
2315                         tmp_val[0] = '\0';
2316 #endif
2317
2318                 }
2319                 else
2320                 {
2321 #ifdef JP
2322                         sprintf(tmp_val, "%s%s",
2323                                 ((y2 < y1) ? "ËÌ" : (y2 > y1) ? "Æî" : ""),
2324                                 ((x2 < x1) ? "À¾" : (x2 > x1) ? "Åì" : ""));
2325 #else
2326                         sprintf(tmp_val, "%s%s of",
2327                                 ((y2 < y1) ? " North" : (y2 > y1) ? " South" : ""),
2328                                 ((x2 < x1) ? " West" : (x2 > x1) ? " East" : ""));
2329 #endif
2330
2331                 }
2332
2333                 /* Prepare to ask which way to look */
2334                 sprintf(out_val,
2335 #ifdef JP
2336                         "¥Þ¥Ã¥×°ÌÃÖ [%d(%02d),%d(%02d)] (¥×¥ì¥¤¥ä¡¼¤Î%s)  Êý¸þ?",
2337 #else
2338                         "Map sector [%d(%02d),%d(%02d)], which is%s your sector.  Direction?",
2339 #endif
2340
2341                         y2 / (hgt / 2), y2 % (hgt / 2),
2342                         x2 / (wid / 2), x2 % (wid / 2), tmp_val);
2343
2344                 /* Assume no direction */
2345                 dir = 0;
2346
2347                 /* Get a direction */
2348                 while (!dir)
2349                 {
2350                         char command;
2351
2352                         /* Get a command (or Cancel) */
2353                         if (!get_com(out_val, &command, TRUE)) break;
2354
2355                         /* Extract the action (if any) */
2356                         dir = get_keymap_dir(command);
2357
2358                         /* Error */
2359                         if (!dir) bell();
2360                 }
2361
2362                 /* No direction */
2363                 if (!dir) break;
2364
2365                 /* Apply the motion */
2366                 if (change_panel(ddy[dir], ddx[dir]))
2367                 {
2368                         y2 = panel_row_min;
2369                         x2 = panel_col_min;
2370                 }
2371         }
2372
2373
2374         /* Recenter the map around the player */
2375         verify_panel();
2376
2377         /* Update stuff */
2378         p_ptr->update |= (PU_MONSTERS);
2379
2380         /* Redraw map */
2381         p_ptr->redraw |= (PR_MAP);
2382
2383         /* Window stuff */
2384         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
2385
2386         /* Handle stuff */
2387         handle_stuff();
2388 }
2389
2390
2391
2392 /*
2393  * The table of "symbol info" -- each entry is a string of the form
2394  * "X:desc" where "X" is the trigger, and "desc" is the "info".
2395  */
2396 static cptr ident_info[] =
2397 {
2398 #ifdef JP
2399         " :°Å°Ç",
2400         "!:Ìô, ¥ª¥¤¥ë",
2401         "\":¥¢¥ß¥å¥ì¥Ã¥È, ðô¾þ¤ê",
2402         "#:ÊÉ(±£¤·¥É¥¢)Ëô¤Ï¿¢Êª",
2403         "$:ºâÊõ(¶â¤«ÊõÀÐ)",
2404         "%:¹ÛÌ®(Íϴ䤫ÀбÑ)",
2405         "&:Ȣ",
2406         "':³«¤¤¤¿¥É¥¢",
2407         "(:Æð¤é¤«¤¤Ëɶñ",
2408         "):½â",
2409         "*:ºâÊõ¤ò´Þ¤ó¤À¹ÛÌ®¤Þ¤¿¤Ïµå·Á¤Î²øʪ",
2410         "+:ÊĤ¸¤¿¥É¥¢",
2411         ",:¿©¤Ùʪ, ¤ª¤Ð¤±¥­¥Î¥³",
2412         "-:ËâË¡ËÀ, ¥í¥Ã¥É",
2413         ".:¾²",
2414         "/:´È¾õÉð´ï(¥¢¥Ã¥¯¥¹/¥Ñ¥¤¥¯/Åù)",
2415         "0:Çîʪ´Û¤ÎÆþ¸ý",
2416         "1:»¨²ß²°¤ÎÆþ¸ý",
2417         "2:Ëɶñ²°¤ÎÆþ¸ý",
2418         "3:Éð´ïÀìÌ珤ÎÆþ¸ý",
2419         "4:»û±¡¤ÎÆþ¸ý",
2420         "5:Ï£¶â½Ñ¤ÎŹ¤ÎÆþ¸ý",
2421         "6:ËâË¡¤ÎŹ¤ÎÆþ¸ý",
2422         "7:¥Ö¥é¥Ã¥¯¥Þ¡¼¥±¥Ã¥È¤ÎÆþ¸ý",
2423         "8:²æ¤¬²È¤ÎÆþ¸ý",
2424         "9:½ñŹ¤ÎÆþ¸ý",
2425         "::´äÀÐ",
2426         ";:²óÈò¤Î³¨Ê¸»ú/Çúȯ¤Î¥ë¡¼¥ó",
2427         "<:¾å¤ê³¬ÃÊ",
2428         "=:»ØÎØ",
2429         ">:²¼¤ê³¬ÃÊ",
2430         "?:´¬Êª",
2431         "@:¥×¥ì¥¤¥ä¡¼",
2432         "A:Å·»È",
2433         "B:Ļ",
2434         "C:¸¤",
2435         "D:¸ÅÂå¥É¥é¥´¥ó/¥ï¥¤¥¢¡¼¥à",
2436         "E:¥¨¥ì¥á¥ó¥¿¥ë",
2437         "F:¥È¥ó¥Ü",
2438         "G:¥´¡¼¥¹¥È",
2439         "H:»¨¼ï",
2440         "I:º«Ãî",
2441         "J:¥Ø¥Ó",
2442         "K:¥­¥é¡¼¡¦¥Ó¡¼¥È¥ë",
2443         "L:¥ê¥Ã¥Á",
2444         "M:¿¼ó¤Îà¨ÃîÎà",
2445         "N:Ææ¤ÎÀ¸Êª",
2446         "O:¥ª¡¼¥¬",
2447         "P:µðÂç¿Í´Ö·¿À¸Êª",
2448         "Q:¥¯¥¤¥ë¥¹¥ë¥°(Ì®ÂǤÄÆù²ô)",
2449         "R:à¨ÃîÎà/ξÀ¸Îà",
2450         "S:ÃØéá/¥µ¥½¥ê/¥À¥Ë",
2451         "T:¥È¥í¥ë",
2452         "U:¾åµé¥Ç¡¼¥â¥ó",
2453         "V:¥Ð¥ó¥Ñ¥¤¥¢",
2454         "W:¥ï¥¤¥È/¥ì¥¤¥¹/Åù",
2455         "X:¥¾¡¼¥ó/¥¶¥ì¥ó/Åù",
2456         "Y:¥¤¥¨¥Æ¥£",
2457         "Z:¥Ï¥¦¥ó¥É",
2458         "[:·ø¤¤¥¢¡¼¥Þ¡¼",
2459         "\\:Æß´ï(¥á¥¤¥¹/¥à¥Á/Åù)",
2460         "]:¼ï¡¹¤ÎËɶñ",
2461         "^:¥È¥é¥Ã¥×",
2462         "_:¾ó",
2463         "`:¿Í·Á¡¤Ä¦Áü",
2464         "a:¥¢¥ê",
2465         "b:¥³¥¦¥â¥ê",
2466         "c:¥à¥«¥Ç",
2467         "d:¥É¥é¥´¥ó",
2468         "e:ÌܶÌ",
2469         "f:¥Í¥³",
2470         "g:¥´¡¼¥ì¥à",
2471         "h:¥Û¥Ó¥Ã¥È/¥¨¥ë¥Õ/¥É¥ï¡¼¥Õ",
2472         "i:¥Ù¥È¥Ù¥È",
2473         "j:¥¼¥ê¡¼",
2474         "k:¥³¥Ü¥ë¥É",
2475         "l:¿åÀ³À¸Êª",
2476         "m:¥â¥ë¥É",
2477         "n:¥Ê¡¼¥¬",
2478         "o:¥ª¡¼¥¯",
2479         "p:¿Í´Ö",
2480         "q:»Í­½Ã",
2481         "r:¥Í¥º¥ß",
2482         "s:¥¹¥±¥ë¥È¥ó",
2483         "t:Ä®¤Î¿Í",
2484         "u:²¼µé¥Ç¡¼¥â¥ó",
2485         "v:¥Ü¥ë¥Æ¥Ã¥¯¥¹",
2486         "w:¥¤¥â¥à¥·/Âç·²",
2487         /* "x:unused", */
2488         "y:¥¤¡¼¥¯",
2489         "z:¥¾¥ó¥Ó/¥ß¥¤¥é",
2490         "{:Èô¤ÓÆ»¶ñ¤ÎÃÆ(Ìð/ÃÆ)",
2491         "|:Åá·õÎà(¥½¡¼¥É/¥À¥¬¡¼/Åù)",
2492         "}:Èô¤ÓÆ»¶ñ(µÝ/¥¯¥í¥¹¥Ü¥¦/¥¹¥ê¥ó¥°)",
2493         "~:¿å/ÍÏ´äή(¼ï¡¹¤Î¥¢¥¤¥Æ¥à)",
2494 #else
2495         " :A dark grid",
2496         "!:A potion (or oil)",
2497         "\":An amulet (or necklace)",
2498         "#:A wall (or secret door)",
2499         "$:Treasure (gold or gems)",
2500         "%:A vein (magma or quartz)",
2501         "&:A chest",
2502         "':An open door",
2503         "(:Soft armor",
2504         "):A shield",
2505         "*:A vein with treasure or a ball monster",
2506         "+:A closed door",
2507         ",:Food (or mushroom patch)",
2508         "-:A wand (or rod)",
2509         ".:Floor",
2510         "/:A polearm (Axe/Pike/etc)",
2511         "0:Entrance to Museum",
2512         "1:Entrance to General Store",
2513         "2:Entrance to Armory",
2514         "3:Entrance to Weaponsmith",
2515         "4:Entrance to Temple",
2516         "5:Entrance to Alchemy shop",
2517         "6:Entrance to Magic store",
2518         "7:Entrance to Black Market",
2519         "8:Entrance to your home",
2520         "9:Entrance to the bookstore",
2521         "::Rubble",
2522         ";:A glyph of warding / explosive rune",
2523         "<:An up staircase",
2524         "=:A ring",
2525         ">:A down staircase",
2526         "?:A scroll",
2527         "@:You",
2528         "A:Angel",
2529         "B:Bird",
2530         "C:Canine",
2531         "D:Ancient Dragon/Wyrm",
2532         "E:Elemental",
2533         "F:Dragon Fly",
2534         "G:Ghost",
2535         "H:Hybrid",
2536         "I:Insect",
2537         "J:Snake",
2538         "K:Killer Beetle",
2539         "L:Lich",
2540         "M:Multi-Headed Reptile",
2541         "N:Mystery Living",
2542         "O:Ogre",
2543         "P:Giant Humanoid",
2544         "Q:Quylthulg (Pulsing Flesh Mound)",
2545         "R:Reptile/Amphibian",
2546         "S:Spider/Scorpion/Tick",
2547         "T:Troll",
2548         "U:Major Demon",
2549         "V:Vampire",
2550         "W:Wight/Wraith/etc",
2551         "X:Xorn/Xaren/etc",
2552         "Y:Yeti",
2553         "Z:Zephyr Hound",
2554         "[:Hard armor",
2555         "\\:A hafted weapon (mace/whip/etc)",
2556         "]:Misc. armor",
2557         "^:A trap",
2558         "_:A staff",
2559         "`:A figurine or statue",
2560         "a:Ant",
2561         "b:Bat",
2562         "c:Centipede",
2563         "d:Dragon",
2564         "e:Floating Eye",
2565         "f:Feline",
2566         "g:Golem",
2567         "h:Hobbit/Elf/Dwarf",
2568         "i:Icky Thing",
2569         "j:Jelly",
2570         "k:Kobold",
2571         "l:Aquatic monster",
2572         "m:Mold",
2573         "n:Naga",
2574         "o:Orc",
2575         "p:Person/Human",
2576         "q:Quadruped",
2577         "r:Rodent",
2578         "s:Skeleton",
2579         "t:Townsperson",
2580         "u:Minor Demon",
2581         "v:Vortex",
2582         "w:Worm/Worm-Mass",
2583         /* "x:unused", */
2584         "y:Yeek",
2585         "z:Zombie/Mummy",
2586         "{:A missile (arrow/bolt/shot)",
2587         "|:An edged weapon (sword/dagger/etc)",
2588         "}:A launcher (bow/crossbow/sling)",
2589         "~:Fluid terrain (or miscellaneous item)",
2590 #endif
2591
2592         NULL
2593 };
2594
2595
2596 /*
2597  * Sorting hook -- Comp function -- see below
2598  *
2599  * We use "u" to point to array of monster indexes,
2600  * and "v" to select the type of sorting to perform on "u".
2601  */
2602 bool ang_sort_comp_hook(vptr u, vptr v, int a, int b)
2603 {
2604         u16b *who = (u16b*)(u);
2605
2606         u16b *why = (u16b*)(v);
2607
2608         int w1 = who[a];
2609         int w2 = who[b];
2610
2611         int z1, z2;
2612
2613
2614         /* Sort by player kills */
2615         if (*why >= 4)
2616         {
2617                 /* Extract player kills */
2618                 z1 = r_info[w1].r_pkills;
2619                 z2 = r_info[w2].r_pkills;
2620
2621                 /* Compare player kills */
2622                 if (z1 < z2) return (TRUE);
2623                 if (z1 > z2) return (FALSE);
2624         }
2625
2626
2627         /* Sort by total kills */
2628         if (*why >= 3)
2629         {
2630                 /* Extract total kills */
2631                 z1 = r_info[w1].r_tkills;
2632                 z2 = r_info[w2].r_tkills;
2633
2634                 /* Compare total kills */
2635                 if (z1 < z2) return (TRUE);
2636                 if (z1 > z2) return (FALSE);
2637         }
2638
2639
2640         /* Sort by monster level */
2641         if (*why >= 2)
2642         {
2643                 /* Extract levels */
2644                 z1 = r_info[w1].level;
2645                 z2 = r_info[w2].level;
2646
2647                 /* Compare levels */
2648                 if (z1 < z2) return (TRUE);
2649                 if (z1 > z2) return (FALSE);
2650         }
2651
2652
2653         /* Sort by monster experience */
2654         if (*why >= 1)
2655         {
2656                 /* Extract experience */
2657                 z1 = r_info[w1].mexp;
2658                 z2 = r_info[w2].mexp;
2659
2660                 /* Compare experience */
2661                 if (z1 < z2) return (TRUE);
2662                 if (z1 > z2) return (FALSE);
2663         }
2664
2665
2666         /* Compare indexes */
2667         return (w1 <= w2);
2668 }
2669
2670
2671 /*
2672  * Sorting hook -- Swap function -- see below
2673  *
2674  * We use "u" to point to array of monster indexes,
2675  * and "v" to select the type of sorting to perform.
2676  */
2677 void ang_sort_swap_hook(vptr u, vptr v, int a, int b)
2678 {
2679         u16b *who = (u16b*)(u);
2680
2681         u16b holder;
2682
2683         /* Swap */
2684         holder = who[a];
2685         who[a] = who[b];
2686         who[b] = holder;
2687 }
2688
2689
2690
2691 /*
2692  * Identify a character, allow recall of monsters
2693  *
2694  * Several "special" responses recall "multiple" monsters:
2695  *   ^A (all monsters)
2696  *   ^U (all unique monsters)
2697  *   ^N (all non-unique monsters)
2698  *
2699  * The responses may be sorted in several ways, see below.
2700  *
2701  * Note that the player ghosts are ignored. XXX XXX XXX
2702  */
2703 void do_cmd_query_symbol(void)
2704 {
2705         int             i, n, r_idx;
2706         char    sym, query;
2707         char    buf[128];
2708
2709         bool    all = FALSE;
2710         bool    uniq = FALSE;
2711         bool    norm = FALSE;
2712         char    temp[80] = "";
2713
2714         bool    recall = FALSE;
2715
2716         u16b    why = 0;
2717         u16b    *who;
2718
2719         /* Get a character, or abort */
2720 #ifdef JP
2721         if (!get_com("ÃΤꤿ¤¤Ê¸»ú¤òÆþÎϤ·¤Æ²¼¤µ¤¤(µ­¹æ or ^AÁ´,^U¥æ,^NÈó¥æ,^M̾Á°): ", &sym, FALSE)) return;
2722 #else
2723         if (!get_com("Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): ", &sym, FALSE)) return;
2724 #endif
2725
2726
2727         /* Find that character info, and describe it */
2728         for (i = 0; ident_info[i]; ++i)
2729         {
2730                 if (sym == ident_info[i][0]) break;
2731         }
2732
2733         /* Describe */
2734         if (sym == KTRL('A'))
2735         {
2736                 all = TRUE;
2737 #ifdef JP
2738                 strcpy(buf, "Á´¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
2739 #else
2740                 strcpy(buf, "Full monster list.");
2741 #endif
2742
2743         }
2744         else if (sym == KTRL('U'))
2745         {
2746                 all = uniq = TRUE;
2747 #ifdef JP
2748                 strcpy(buf, "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
2749 #else
2750                 strcpy(buf, "Unique monster list.");
2751 #endif
2752
2753         }
2754         else if (sym == KTRL('N'))
2755         {
2756                 all = norm = TRUE;
2757 #ifdef JP
2758                 strcpy(buf, "¥æ¥Ë¡¼¥¯³°¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
2759 #else
2760                 strcpy(buf, "Non-unique monster list.");
2761 #endif
2762
2763         }
2764         /* XTRA HACK WHATSEARCH */
2765         else if (sym == KTRL('M'))
2766         {
2767                 all = TRUE;
2768 #ifdef JP
2769                 if (!get_string("̾Á°(±Ñ¸ì¤Î¾ì¹ç¾®Ê¸»ú¤Ç²Ä)",temp, 70))
2770 #else
2771                 if (!get_string("Enter name:",temp, 70))
2772 #endif
2773                 {
2774                         temp[0]=0;
2775                         return;
2776                 }
2777 #ifdef JP
2778                 sprintf(buf, "̾Á°:%s¤Ë¥Þ¥Ã¥Á",temp);
2779 #else
2780                 sprintf(buf, "Monsters with a name \"%s\"",temp);
2781 #endif
2782         }
2783         else if (ident_info[i])
2784         {
2785                 sprintf(buf, "%c - %s.", sym, ident_info[i] + 2);
2786         }
2787         else
2788         {
2789 #ifdef JP
2790                 sprintf(buf, "%c - %s", sym, "̵¸ú¤Êʸ»ú");
2791 #else
2792                 sprintf(buf, "%c - %s.", sym, "Unknown Symbol");
2793 #endif
2794
2795         }
2796
2797         /* Display the result */
2798         prt(buf, 0, 0);
2799
2800         /* Allocate the "who" array */
2801         C_MAKE(who, max_r_idx, u16b);
2802
2803         /* Collect matching monsters */
2804         for (n = 0, i = 1; i < max_r_idx; i++)
2805         {
2806                 monster_race *r_ptr = &r_info[i];
2807
2808                 /* Nothing to recall */
2809                 if (!cheat_know && !r_ptr->r_sights) continue;
2810
2811                 /* Require non-unique monsters if needed */
2812                 if (norm && (r_ptr->flags1 & (RF1_UNIQUE))) continue;
2813
2814                 /* Require unique monsters if needed */
2815                 if (uniq && !(r_ptr->flags1 & (RF1_UNIQUE))) continue;
2816
2817                 /* XTRA HACK WHATSEARCH */
2818                 if (temp[0]){
2819                   int xx;
2820                   char temp2[80];
2821   
2822                   for (xx=0; temp[xx] && xx<80; xx++){
2823 #ifdef JP
2824                     if (iskanji( temp[xx])) { xx++; continue; }
2825 #endif
2826                     if (isupper(temp[xx])) temp[xx]=tolower(temp[xx]);
2827                   }
2828   
2829 #ifdef JP
2830                   strcpy(temp2, r_name+r_ptr->E_name);
2831 #else
2832                   strcpy(temp2, r_name+r_ptr->name);
2833 #endif
2834                   for (xx=0; temp2[xx] && xx<80; xx++)
2835                     if (isupper(temp2[xx])) temp2[xx]=tolower(temp2[xx]);
2836   
2837 #ifdef JP
2838                   if (strstr(temp2, temp) || strstr_j(r_name + r_ptr->name, temp) )
2839 #else
2840                   if (strstr(temp2, temp))
2841 #endif
2842                           who[n++]=i;
2843                 }else
2844                 /* Collect "appropriate" monsters */
2845                 if (all || (r_ptr->d_char == sym)) who[n++] = i;
2846         }
2847
2848         /* Nothing to recall */
2849         if (!n)
2850         {
2851                 /* Free the "who" array */
2852                 C_KILL(who, max_r_idx, u16b);
2853
2854                 return;
2855         }
2856
2857
2858         /* Prompt XXX XXX XXX */
2859 #ifdef JP
2860         put_str("»×¤¤½Ð¤ò¸«¤Þ¤¹¤«? (k:»¦³²½ç/y/n): ", 0, 36);
2861 #else
2862         put_str("Recall details? (k/y/n): ", 0, 40);
2863 #endif
2864
2865
2866         /* Query */
2867         query = inkey();
2868
2869         /* Restore */
2870         prt(buf, 0, 0);
2871
2872         why = 2;
2873
2874         /* Select the sort method */
2875         ang_sort_comp = ang_sort_comp_hook;
2876         ang_sort_swap = ang_sort_swap_hook;
2877
2878         /* Sort the array */
2879         ang_sort(who, &why, n);
2880
2881         /* Sort by kills (and level) */
2882         if (query == 'k')
2883         {
2884                 why = 4;
2885                 query = 'y';
2886         }
2887
2888         /* Catch "escape" */
2889         if (query != 'y')
2890         {
2891                 /* Free the "who" array */
2892                 C_KILL(who, max_r_idx, u16b);
2893
2894                 return;
2895         }
2896
2897         /* Sort if needed */
2898         if (why == 4)
2899         {
2900                 /* Select the sort method */
2901                 ang_sort_comp = ang_sort_comp_hook;
2902                 ang_sort_swap = ang_sort_swap_hook;
2903
2904                 /* Sort the array */
2905                 ang_sort(who, &why, n);
2906         }
2907
2908
2909         /* Start at the end */
2910         i = n - 1;
2911
2912         /* Scan the monster memory */
2913         while (1)
2914         {
2915                 /* Extract a race */
2916                 r_idx = who[i];
2917
2918                 /* Hack -- Auto-recall */
2919                 monster_race_track(r_idx);
2920
2921                 /* Hack -- Handle stuff */
2922                 handle_stuff();
2923
2924                 /* Hack -- Begin the prompt */
2925                 roff_top(r_idx);
2926
2927                 /* Hack -- Complete the prompt */
2928 #ifdef JP
2929                 Term_addstr(-1, TERM_WHITE, " ['r'»×¤¤½Ð, ESC]");
2930 #else
2931                 Term_addstr(-1, TERM_WHITE, " [(r)ecall, ESC]");
2932 #endif
2933
2934
2935                 /* Interact */
2936                 while (1)
2937                 {
2938                         /* Recall */
2939                         if (recall)
2940                         {
2941                                 /* Save the screen */
2942                                 screen_save();
2943
2944                                 /* Recall on screen */
2945                                 screen_roff(who[i], 0);
2946
2947                                 /* Hack -- Complete the prompt (again) */
2948 #ifdef JP
2949                                 Term_addstr(-1, TERM_WHITE, " ['r'»×¤¤½Ð, ESC]");
2950 #else
2951                                 Term_addstr(-1, TERM_WHITE, " [(r)ecall, ESC]");
2952 #endif
2953
2954                         }
2955
2956                         /* Command */
2957                         query = inkey();
2958
2959                         /* Unrecall */
2960                         if (recall)
2961                         {
2962                                 /* Restore */
2963                                 screen_load();
2964                         }
2965
2966                         /* Normal commands */
2967                         if (query != 'r') break;
2968
2969                         /* Toggle recall */
2970                         recall = !recall;
2971                 }
2972
2973                 /* Stop scanning */
2974                 if (query == ESCAPE) break;
2975
2976                 /* Move to "prev" monster */
2977                 if (query == '-')
2978                 {
2979                         if (++i == n)
2980                         {
2981                                 i = 0;
2982                                 if (!expand_list) break;
2983                         }
2984                 }
2985
2986                 /* Move to "next" monster */
2987                 else
2988                 {
2989                         if (i-- == 0)
2990                         {
2991                                 i = n - 1;
2992                                 if (!expand_list) break;
2993                         }
2994                 }
2995         }
2996
2997         /* Free the "who" array */
2998         C_KILL(who, max_r_idx, u16b);
2999
3000         /* Re-display the identity */
3001         prt(buf, 0, 0);
3002 }
3003
3004
3005 /*
3006  *  research_mon
3007  *  -KMW-
3008  */
3009 bool research_mon(void)
3010 {
3011         int i, n, r_idx;
3012         char sym, query;
3013         char buf[128];
3014
3015         bool notpicked;
3016
3017         bool recall = FALSE;
3018
3019         u16b why = 0;
3020
3021         u16b    *who;
3022
3023         /* XTRA HACK WHATSEARCH */
3024         bool    all = FALSE;
3025         bool    uniq = FALSE;
3026         bool    norm = FALSE;
3027         char temp[80] = "";
3028
3029         /* XTRA HACK REMEMBER_IDX */
3030         static int old_sym = '\0';
3031         static int old_i = 0;
3032
3033
3034         /* Save the screen */
3035         screen_save();
3036
3037         /* Get a character, or abort */
3038 #ifdef JP
3039 if (!get_com("¥â¥ó¥¹¥¿¡¼¤Îʸ»ú¤òÆþÎϤ·¤Æ²¼¤µ¤¤(µ­¹æ or ^AÁ´,^U¥æ,^NÈó¥æ,^M̾Á°):", &sym, FALSE)) 
3040 #else
3041         if (!get_com("Enter character to be identified(^A:All,^U:Uniqs,^N:Non uniqs,^M:Name): ", &sym, FALSE))
3042 #endif
3043
3044         {
3045                 /* Restore */
3046                 screen_load();
3047
3048                 return (FALSE);
3049         }
3050
3051         /* Find that character info, and describe it */
3052         for (i = 0; ident_info[i]; ++i)
3053         {
3054                 if (sym == ident_info[i][0]) break;
3055         }
3056
3057                 /* XTRA HACK WHATSEARCH */
3058         if (sym == KTRL('A'))
3059         {
3060                 all = TRUE;
3061 #ifdef JP
3062                 strcpy(buf, "Á´¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
3063 #else
3064                 strcpy(buf, "Full monster list.");
3065 #endif
3066         }
3067         else if (sym == KTRL('U'))
3068         {
3069                 all = uniq = TRUE;
3070 #ifdef JP
3071                 strcpy(buf, "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
3072 #else
3073                 strcpy(buf, "Unique monster list.");
3074 #endif
3075         }
3076         else if (sym == KTRL('N'))
3077         {
3078                 all = norm = TRUE;
3079 #ifdef JP
3080                 strcpy(buf, "¥æ¥Ë¡¼¥¯³°¥â¥ó¥¹¥¿¡¼¤Î¥ê¥¹¥È");
3081 #else
3082                 strcpy(buf, "Non-unique monster list.");
3083 #endif
3084         }
3085         else if (sym == KTRL('M'))
3086         {
3087                 all = TRUE;
3088 #ifdef JP
3089                 if (!get_string("̾Á°(±Ñ¸ì¤Î¾ì¹ç¾®Ê¸»ú¤Ç²Ä)",temp, 70))
3090 #else
3091                 if (!get_string("Enter name:",temp, 70))
3092 #endif
3093                 {
3094                         temp[0]=0;
3095
3096                         /* Restore */
3097                         screen_load();
3098
3099                         return FALSE;
3100                 }
3101 #ifdef JP
3102                 sprintf(buf, "̾Á°:%s¤Ë¥Þ¥Ã¥Á",temp);
3103 #else
3104                 sprintf(buf, "Monsters with a name \"%s\"",temp);
3105 #endif
3106         }
3107         else if (ident_info[i])
3108         {
3109                 sprintf(buf, "%c - %s.", sym, ident_info[i] + 2);
3110         }
3111         else
3112         {
3113 #ifdef JP
3114 sprintf(buf, "%c - %s", sym, "̵¸ú¤Êʸ»ú");
3115 #else
3116                 sprintf(buf, "%c - %s.", sym, "Unknown Symbol");
3117 #endif
3118
3119         }
3120
3121         /* Display the result */
3122         prt(buf, 16, 10);
3123
3124
3125         /* Allocate the "who" array */
3126         C_MAKE(who, max_r_idx, u16b);
3127
3128         /* Collect matching monsters */
3129         for (n = 0, i = 1; i < max_r_idx; i++)
3130         {
3131                 monster_race *r_ptr = &r_info[i];
3132
3133                 /* XTRA HACK WHATSEARCH */
3134                 /* Require non-unique monsters if needed */
3135                 if (norm && (r_ptr->flags1 & (RF1_UNIQUE))) continue;
3136
3137                 /* Require unique monsters if needed */
3138                 if (uniq && !(r_ptr->flags1 & (RF1_UNIQUE))) continue;
3139
3140                 /* Ì¾Á°¸¡º÷ */
3141                 if (temp[0]){
3142                   int xx;
3143                   char temp2[80];
3144   
3145                   for (xx=0; temp[xx] && xx<80; xx++){
3146 #ifdef JP
3147                     if (iskanji( temp[xx])) { xx++; continue; }
3148 #endif
3149                     if (isupper(temp[xx])) temp[xx]=tolower(temp[xx]);
3150                   }
3151   
3152 #ifdef JP
3153                   strcpy(temp2, r_name+r_ptr->E_name);
3154 #else
3155                   strcpy(temp2, r_name+r_ptr->name);
3156 #endif
3157                   for (xx=0; temp2[xx] && xx<80; xx++)
3158                     if (isupper(temp2[xx])) temp2[xx]=tolower(temp2[xx]);
3159   
3160 #ifdef JP
3161                   if (strstr(temp2, temp) || strstr_j(r_name + r_ptr->name, temp) )
3162 #else
3163                   if (strstr(temp2, temp))
3164 #endif
3165                           who[n++]=i;
3166                 }
3167                 else if (all || (r_ptr->d_char == sym)) who[n++] = i;
3168         }
3169
3170         /* Nothing to recall */
3171         if (!n)
3172         {
3173                 /* Free the "who" array */
3174                 C_KILL(who, max_r_idx, u16b);
3175
3176                 /* Restore */
3177                 screen_load();
3178
3179                 return (FALSE);
3180         }
3181
3182         /* Sort by level */
3183         why = 2;
3184         query = 'y';
3185
3186         /* Sort if needed */
3187         if (why)
3188         {
3189                 /* Select the sort method */
3190                 ang_sort_comp = ang_sort_comp_hook;
3191                 ang_sort_swap = ang_sort_swap_hook;
3192
3193                 /* Sort the array */
3194                 ang_sort(who, &why, n);
3195         }
3196
3197
3198         /* Start at the end */
3199         /* XTRA HACK REMEMBER_IDX */
3200         if (old_sym == sym && old_i < n) i = old_i;
3201         else i = n - 1;
3202
3203         notpicked = TRUE;
3204
3205         /* Scan the monster memory */
3206         while (notpicked)
3207         {
3208                 /* Extract a race */
3209                 r_idx = who[i];
3210
3211                 /* Save this monster ID */
3212                 p_ptr->monster_race_idx = r_idx;
3213
3214                 /* Hack -- Handle stuff */
3215                 handle_stuff();
3216
3217                 /* Hack -- Begin the prompt */
3218                 roff_top(r_idx);
3219
3220                 /* Hack -- Complete the prompt */
3221 #ifdef JP
3222 Term_addstr(-1, TERM_WHITE, " ['r'»×¤¤½Ð, ' '¤Ç³¹Ô, ESC]");
3223 #else
3224                 Term_addstr(-1, TERM_WHITE, " [(r)ecall, ESC, space to continue]");
3225 #endif
3226
3227
3228                 /* Interact */
3229                 while (1)
3230                 {
3231                         /* Recall */
3232                         if (recall)
3233                         {
3234                                 /* Recall on screen */
3235                                 monster_race *r_ptr = &r_info[r_idx];
3236                                 int m;
3237
3238                                 /* Hack -- Maximal info */
3239                                 r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
3240                                 
3241                                 /* Observe "maximal" attacks */
3242                                 for (m = 0; m < 4; m++)
3243                                 {
3244                                         /* Examine "actual" blows */
3245                                         if (r_ptr->blow[m].effect || r_ptr->blow[m].method)
3246                                         {
3247                                                 /* Hack -- maximal observations */
3248                                                 r_ptr->r_blows[m] = MAX_UCHAR;
3249                                         }
3250                                 }
3251                                 
3252                                 /* Hack -- maximal drops */
3253                                 r_ptr->r_drop_gold = r_ptr->r_drop_item =
3254                                         (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) +
3255                                          ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) +
3256                                          ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) +
3257                                          ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) +
3258                                          ((r_ptr->flags1 & RF1_DROP_90)  ? 1 : 0) +
3259                                          ((r_ptr->flags1 & RF1_DROP_60)  ? 1 : 0));
3260                                 
3261                                 /* Hack -- but only "valid" drops */
3262                                 if (r_ptr->flags1 & RF1_ONLY_GOLD) r_ptr->r_drop_item = 0;
3263                                 if (r_ptr->flags1 & RF1_ONLY_ITEM) r_ptr->r_drop_gold = 0;
3264                                 
3265                                 /* Hack -- observe many spells */
3266                                 r_ptr->r_cast_inate = MAX_UCHAR;
3267                                 r_ptr->r_cast_spell = MAX_UCHAR;
3268                                 
3269                                 /* Hack -- know all the flags */
3270                                 r_ptr->r_flags1 = r_ptr->flags1;
3271                                 r_ptr->r_flags2 = r_ptr->flags2;
3272                                 r_ptr->r_flags3 = r_ptr->flags3;
3273                                 r_ptr->r_flags4 = r_ptr->flags4;
3274                                 r_ptr->r_flags5 = r_ptr->flags5;
3275                                 r_ptr->r_flags6 = r_ptr->flags6;
3276                                 
3277                                 r_ptr->r_xtra1 |= MR1_SINKA;
3278                         
3279                                 /* know every thing mode */
3280                                 screen_roff(r_idx, 0x01);
3281                                 notpicked = FALSE;
3282
3283                                 /* XTRA HACK REMEMBER_IDX */
3284                                 old_sym = sym;
3285                                 old_i = i;
3286                         }
3287
3288                         /* Command */
3289                         query = inkey();
3290
3291                         /* Normal commands */
3292                         if (query != 'r') break;
3293
3294                         /* Toggle recall */
3295                         recall = !recall;
3296                 }
3297
3298                 /* Stop scanning */
3299                 if (query == ESCAPE) break;
3300
3301                 /* Move to "prev" monster */
3302                 if (query == '-')
3303                 {
3304                         if (++i == n)
3305                         {
3306                                 i = 0;
3307                                 if (!expand_list) break;
3308                         }
3309                 }
3310
3311                 /* Move to "next" monster */
3312                 else
3313                 {
3314                         if (i-- == 0)
3315                         {
3316                                 i = n - 1;
3317                                 if (!expand_list) break;
3318                         }
3319                 }
3320         }
3321
3322
3323         /* Re-display the identity */
3324         /* prt(buf, 5, 5);*/
3325
3326         /* Free the "who" array */
3327         C_KILL(who, max_r_idx, u16b);
3328
3329         /* Restore */
3330         screen_load();
3331
3332         return (!notpicked);
3333 }
3334