3 /* Purpose: Object Auto-picker/Destroyer */
6 * Copyright (c) 2002 Mogami
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.
16 #define MAX_LINELEN 1024
23 #define FLG_UNIDENTIFIED 2
24 #define FLG_IDENTIFIED 3
25 #define FLG_STAR_IDENTIFIED 4
26 #define FLG_COLLECTING 5
27 #define FLG_ARTIFACT 6
30 #define FLG_NAMELESS 11
31 #define FLG_AVERAGE 12
32 #define FLG_WORTHLESS 13
35 #define FLG_BOOSTED 16
36 #define FLG_MORE_DICE 17
37 #define FLG_MORE_BONUS 18
41 #define FLG_UNREADABLE 22
50 #define FLG_WEAPONS 31
51 #define FLG_FAVORITE_WEAPONS 32
53 #define FLG_MISSILES 34
54 #define FLG_DEVICES 35
57 #define FLG_CORPSES 38
58 #define FLG_SPELLBOOKS 39
60 #define FLG_SHIELDS 41
63 #define FLG_AMULETS 44
70 #define FLG_NOUN_BEGIN FLG_ITEMS
71 #define FLG_NOUN_END FLG_BOOTS
75 static char KEY_ALL[] = "¤¹¤Ù¤Æ¤Î";
76 static char KEY_UNAWARE[] = "̤ȽÌÀ¤Î";
77 static char KEY_UNIDENTIFIED[] = "̤´ÕÄê¤Î";
78 static char KEY_IDENTIFIED[] = "´ÕÄêºÑ¤ß¤Î";
79 static char KEY_STAR_IDENTIFIED[] = "*´ÕÄê*ºÑ¤ß¤Î";
80 static char KEY_COLLECTING[] = "¼ý½¸Ãæ¤Î";
81 static char KEY_ARTIFACT[] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È";
82 static char KEY_EGO[] = "¥¨¥´";
83 static char KEY_GOOD[] = "¾å¼Á¤Î";
84 static char KEY_NAMELESS[] = "̵ÌäÎ";
85 static char KEY_AVERAGE[] = "ʤÎ";
86 static char KEY_WORTHLESS[] = "̵²ÁÃͤÎ";
87 static char KEY_RARE[] = "¥ì¥¢¤Ê";
88 static char KEY_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿";
89 static char KEY_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦";
90 static char KEY_MORE_THAN[] = "¥À¥¤¥¹ÌÜ";
91 static char KEY_DICE[] = "°Ê¾å¤Î";
92 static char KEY_MORE_BONUS[] = "½¤ÀµÃÍ";
93 static char KEY_MORE_BONUS2[] = "°Ê¾å¤Î";
94 static char KEY_WANTED[] = "¾Þ¶â¼ó¤Î";
95 static char KEY_UNIQUE[] = "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î";
96 static char KEY_HUMAN[] = "¿Í´Ö¤Î";
97 static char KEY_UNREADABLE[] = "Æɤá¤Ê¤¤";
98 static char KEY_REALM1[] = "Âè°ìÎΰè¤Î";
99 static char KEY_REALM2[] = "ÂèÆóÎΰè¤Î";
100 static char KEY_FIRST[] = "1ºýÌܤÎ";
101 static char KEY_SECOND[] = "2ºýÌܤÎ";
102 static char KEY_THIRD[] = "3ºýÌܤÎ";
103 static char KEY_FOURTH[] = "4ºýÌܤÎ";
104 static char KEY_ITEMS[] = "¥¢¥¤¥Æ¥à";
105 static char KEY_WEAPONS[] = "Éð´ï";
106 static char KEY_FAVORITE_WEAPONS[] = "ÆÀ°ÕÉð´ï";
107 static char KEY_ARMORS[] = "Ëɶñ";
108 static char KEY_MISSILES[] = "Ìð";
109 static char KEY_DEVICES[] = "ËâË¡¥¢¥¤¥Æ¥à";
110 static char KEY_LIGHTS[] = "¸÷¸»";
111 static char KEY_JUNKS[] = "¤¬¤é¤¯¤¿";
112 static char KEY_CORPSES[] = "»àÂΤä¹ü";
113 static char KEY_SPELLBOOKS[] = "ËâË¡½ñ";
114 static char KEY_HAFTED[] = "Æß´ï";
115 static char KEY_SHIELDS[] = "½â";
116 static char KEY_BOWS[] = "µÝ";
117 static char KEY_RINGS[] = "»ØÎØ";
118 static char KEY_AMULETS[] = "¥¢¥ß¥å¥ì¥Ã¥È";
119 static char KEY_SUITS[] = "³»";
120 static char KEY_CLOAKS[] = "¥¯¥í¡¼¥¯";
121 static char KEY_HELMS[] = "³õ";
122 static char KEY_GLOVES[] = "äƼê";
123 static char KEY_BOOTS[] = "·¤";
127 static char KEY_ALL[] = "all";
128 static char KEY_UNAWARE[] = "unaware";
129 static char KEY_UNIDENTIFIED[] = "unidentified";
130 static char KEY_IDENTIFIED[] = "identified";
131 static char KEY_STAR_IDENTIFIED[] = "*identified*";
132 static char KEY_COLLECTING[] = "collecting";
133 static char KEY_ARTIFACT[] = "artifact";
134 static char KEY_EGO[] = "ego";
135 static char KEY_GOOD[] = "good";
136 static char KEY_NAMELESS[] = "nameless";
137 static char KEY_AVERAGE[] = "average";
138 static char KEY_WORTHLESS[] = "worthless";
139 static char KEY_RARE[] = "rare";
140 static char KEY_COMMON[] = "common";
141 static char KEY_BOOSTED[] = "dice boosted";
142 static char KEY_MORE_THAN[] = "more than";
143 static char KEY_DICE[] = " dice";
144 static char KEY_MORE_BONUS[] = "more bonus than";
145 static char KEY_MORE_BONUS2[] = "";
146 static char KEY_WANTED[] = "wanted";
147 static char KEY_UNIQUE[] = "unique monster's";
148 static char KEY_HUMAN[] = "human";
149 static char KEY_UNREADABLE[] = "unreadable";
150 static char KEY_REALM1[] = "first realm's";
151 static char KEY_REALM2[] = "second realm's";
152 static char KEY_FIRST[] = "first";
153 static char KEY_SECOND[] = "second";
154 static char KEY_THIRD[] = "third";
155 static char KEY_FOURTH[] = "fourth";
156 static char KEY_ITEMS[] = "items";
157 static char KEY_WEAPONS[] = "weapons";
158 static char KEY_FAVORITE_WEAPONS[] = "favorite weapons";
159 static char KEY_ARMORS[] = "armors";
160 static char KEY_MISSILES[] = "missiles";
161 static char KEY_DEVICES[] = "magical devices";
162 static char KEY_LIGHTS[] = "lights";
163 static char KEY_JUNKS[] = "junks";
164 static char KEY_CORPSES[] = "corpses or skeletons";
165 static char KEY_SPELLBOOKS[] = "spellbooks";
166 static char KEY_HAFTED[] = "hafted weapons";
167 static char KEY_SHIELDS[] = "shields";
168 static char KEY_BOWS[] = "bows";
169 static char KEY_RINGS[] = "rings";
170 static char KEY_AMULETS[] = "amulets";
171 static char KEY_SUITS[] = "suits";
172 static char KEY_CLOAKS[] = "cloaks";
173 static char KEY_HELMS[] = "helms";
174 static char KEY_GLOVES[] = "gloves";
175 static char KEY_BOOTS[] = "boots";
179 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
180 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
181 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
182 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
185 #define ADD_KEY(KEY) strcat(ptr, KEY)
187 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
189 #define ADD_KEY2(KEY) strcat(ptr, KEY)
191 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
192 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
193 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
194 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
197 static char kanji_colon[] = "¡§";
202 * A function to create new entry
204 static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_default)
209 char buf[MAX_LINELEN];
210 cptr prev_ptr, ptr, old_ptr;
213 if (str[1] == ':') switch (str[0])
216 case 'A': case 'P': case 'C':
220 entry->flag[0] = entry->flag[1] = 0L;
223 act = DO_AUTOPICK | DO_DISPLAY;
226 if ((act & DO_AUTOPICK) && *str == '!')
229 act |= DO_AUTODESTROY;
232 else if ((act & DO_AUTOPICK) && *str == '~')
235 act |= DONT_AUTOPICK;
238 else if ((act & DO_AUTOPICK) && *str == ';')
241 act |= DO_QUERY_AUTOPICK;
244 else if ((act & DO_DISPLAY) && *str == '(')
253 /* don't mind upper or lower case */
255 for (i = 0; *str; i++)
266 /* Auto-inscription? */
274 if (isupper(c)) c = tolower(c);
280 /* Skip empty line unless allow_default */
281 if (!allow_default && *buf == 0) return FALSE;
283 /* Skip comment line */
284 if (*buf == 0 && insc) return FALSE;
286 ptr = prev_ptr = buf;
289 while (old_ptr != ptr)
291 /* Save current location */
294 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
295 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
296 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
297 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
298 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
299 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
300 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
302 /*** Weapons whose dd*ds is more than nn ***/
303 if (MATCH_KEY2(KEY_MORE_THAN))
308 /* Drop leading spaces */
309 while (' ' == *ptr) ptr++;
312 while ('0' <= *ptr && *ptr <= '9')
314 entry->dice = 10 * entry->dice + (*ptr - '0');
321 (void)MATCH_KEY(KEY_DICE);
322 ADD_FLG(FLG_MORE_DICE);
328 /*** Items whose magical bonus is more than n ***/
329 if (MATCH_KEY2(KEY_MORE_BONUS))
334 /* Drop leading spaces */
335 while (' ' == *ptr) ptr++;
338 while ('0' <= *ptr && *ptr <= '9')
340 entry->bonus = 10 * entry->bonus + (*ptr - '0');
348 (void)MATCH_KEY(KEY_MORE_BONUS2);
350 if (' ' == *ptr) ptr++;
352 ADD_FLG(FLG_MORE_BONUS);
358 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
359 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
360 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
361 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
362 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
363 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
364 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
365 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
366 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
367 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
368 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
369 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
370 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
371 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
372 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
373 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
374 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
377 /* Not yet found any noun */
380 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
382 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
383 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
384 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
385 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
386 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
387 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
388 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
389 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
390 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
391 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
392 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
393 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
394 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
395 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
396 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
397 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
398 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
399 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
400 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
401 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
403 /* Last 'keyword' must be at the correct location */
407 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
410 else if (*ptr == '\0')
412 /* There was no noun */
415 /* Add extra word "items" */
416 ADD_FLG_NOUN(FLG_ITEMS);
423 /* A noun type keyword didn't end correctly */
424 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
429 /* Save this auto-picker entry line */
430 entry->name = string_make(ptr);
432 entry->insc = string_make(insc);
439 * Get auto-picker entry from o_ptr.
441 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
443 /* Assume that object name is to be added */
447 /* ¥¨¥´Ì䬼ÙË⤫¤â¤·¤ì¤Ê¤¤¤Î¤Ç¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¡Ö^¡×¤ÏÉÕ¤±¤Ê¤¤ */
448 bool bol_mark = FALSE;
450 /* We can always use the ^ mark in English */
451 bool bol_mark = TRUE;
454 char name_str[MAX_NLEN];
456 /* Initialize name string */
459 entry->insc = string_make(quark_str(o_ptr->inscription));
460 entry->action = DO_AUTOPICK | DO_DISPLAY;
461 entry->flag[0] = entry->flag[1] = 0L;
465 if (!object_is_aware(o_ptr))
467 ADD_FLG(FLG_UNAWARE);
471 /* Not really identified */
472 else if (!object_is_known(o_ptr))
474 if (!(o_ptr->ident & IDENT_SENSE))
476 ADD_FLG(FLG_UNIDENTIFIED);
481 /* Pseudo-identified */
482 switch (o_ptr->feeling)
486 ADD_FLG(FLG_NAMELESS);
492 ADD_FLG(FLG_NAMELESS);
493 ADD_FLG(FLG_WORTHLESS);
499 ADD_FLG(FLG_WORTHLESS);
507 /* XXX No appropriate flag */
512 /* Never reach here */
522 if (object_is_ego(o_ptr))
525 if (object_is_weapon_armour_ammo(o_ptr))
528 * Base name of ego weapons and armors
529 * are almost meaningless.
530 * Register the ego type only.
532 ego_item_type *e_ptr = &e_info[o_ptr->name2];
534 /* ¥¨¥´ÌäˤϡÖ^¡×¥Þ¡¼¥¯¤¬»È¤¨¤ë */
535 sprintf(name_str, "^%s", e_name + e_ptr->name);
537 /* We ommit the basename and cannot use the ^ mark */
538 strcpy(name_str, e_name + e_ptr->name);
541 /* Don't use the object description */
544 if (object_is_weapon_armour_ammo(o_ptr))
546 /* Restrict to 'common' equipments */
547 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
555 else if (object_is_artifact(o_ptr))
556 ADD_FLG(FLG_ARTIFACT);
558 /* Non-ego, non-artifact */
561 /* Wearable nameless object */
562 if (object_is_equipment(o_ptr))
563 ADD_FLG(FLG_NAMELESS);
570 /* Melee weapon with boosted dice */
571 if (object_is_melee_weapon(o_ptr))
573 object_kind *k_ptr = &k_info[o_ptr->k_idx];
575 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
576 ADD_FLG(FLG_BOOSTED);
579 /* Wanted monster's corpse */
580 if (object_is_shoukinkubi(o_ptr))
582 REM_FLG(FLG_WORTHLESS);
586 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
587 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
592 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
597 if (o_ptr->tval >= TV_LIFE_BOOK &&
598 !check_book_realm(o_ptr->tval, o_ptr->sval))
600 ADD_FLG(FLG_UNREADABLE);
601 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
604 if (REALM1_BOOK == o_ptr->tval &&
605 p_ptr->pclass != CLASS_SORCERER &&
606 p_ptr->pclass != CLASS_RED_MAGE)
612 if (REALM2_BOOK == o_ptr->tval &&
613 p_ptr->pclass != CLASS_SORCERER &&
614 p_ptr->pclass != CLASS_RED_MAGE)
620 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
622 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
624 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
626 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
629 if (object_is_ammo(o_ptr))
630 ADD_FLG(FLG_MISSILES);
631 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
632 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
633 ADD_FLG(FLG_DEVICES);
634 else if (o_ptr->tval == TV_LITE)
636 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
637 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
639 else if (o_ptr->tval == TV_CORPSE)
640 ADD_FLG(FLG_CORPSES);
641 else if (o_ptr->tval >= TV_LIFE_BOOK)
642 ADD_FLG(FLG_SPELLBOOKS);
643 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
644 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
645 ADD_FLG(FLG_WEAPONS);
646 else if (o_ptr->tval == TV_SHIELD)
647 ADD_FLG(FLG_SHIELDS);
648 else if (o_ptr->tval == TV_BOW)
650 else if (o_ptr->tval == TV_RING)
652 else if (o_ptr->tval == TV_AMULET)
653 ADD_FLG(FLG_AMULETS);
654 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
655 o_ptr->tval == TV_SOFT_ARMOR)
657 else if (o_ptr->tval == TV_CLOAK)
659 else if (o_ptr->tval == TV_HELM)
661 else if (o_ptr->tval == TV_GLOVES)
663 else if (o_ptr->tval == TV_BOOTS)
666 /* Prepare the object description */
669 char o_name[MAX_NLEN];
671 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
674 * If necessary, add a '^' which indicates the
677 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
680 /* Register the name in lowercase */
681 str_tolower(name_str);
682 entry->name = string_make(name_str);
689 * A function to delete entry
691 static void autopick_free_entry(autopick_type *entry)
693 string_free(entry->name);
694 string_free(entry->insc);
698 #define MAX_AUTOPICK_DEFAULT 200
701 * Initialize the autopick
703 static void init_autopick(void)
705 static const char easy_autopick_inscription[] = "(:=g";
711 max_max_autopick = MAX_AUTOPICK_DEFAULT;
712 C_MAKE(autopick_list, max_max_autopick, autopick_type);
716 /* Clear old entries */
717 for( i = 0; i < max_autopick; i++)
718 autopick_free_entry(&autopick_list[i]);
722 /* There is always one entry "=g" */
723 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
724 autopick_list[max_autopick++] = entry;
729 #define PT_WITH_PNAME 1
732 * Get file name for autopick preference
734 static cptr pickpref_filename(int filename_mode)
737 static const char namebase[] = "picktype";
739 static const char namebase[] = "pickpref";
742 switch (filename_mode)
745 return format("%s.prf", namebase);
748 return format("%s-%s.prf", namebase, player_name);
757 * Load an autopick preference file
759 void autopick_load_pref(bool disp_mes)
764 /* Free old entries */
767 /* Try a filename with player name */
768 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
771 err = process_autopick_file(buf);
773 if (err == 0 && disp_mes)
777 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
779 msg_format("Loaded '%s'.", buf);
786 /* Use default name */
787 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
790 err = process_autopick_file(buf);
792 if (err == 0 && disp_mes)
796 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
798 msg_format("Loaded '%s'.", buf);
807 msg_print("¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
809 msg_print("Failed to reload autopick preference.");
816 * Add one line to autopick_list[]
818 static void add_autopick_list(autopick_type *entry)
820 /* There is no enough space to add one line */
821 if (max_autopick >= max_max_autopick)
823 int old_max_max_autopick = max_max_autopick;
824 autopick_type *old_autopick_list = autopick_list;
826 /* Increase size of list */
827 max_max_autopick += MAX_AUTOPICK_DEFAULT;
830 C_MAKE(autopick_list, max_max_autopick, autopick_type);
832 /* Copy from old list to new list */
833 C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
836 C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
840 autopick_list[max_autopick] = *entry;
847 * Process line for auto picker/destroyer.
849 errr process_autopick_file_command(char *buf)
851 autopick_type an_entry, *entry = &an_entry;
854 /* Nuke illegal char */
855 for(i = 0; buf[i]; i++)
864 if (isspace(buf[i]) && buf[i] != ' ')
869 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
871 /* Already has the same entry? */
872 for(i = 0; i < max_autopick; i++)
873 if(!strcmp(entry->name, autopick_list[i].name)
874 && entry->flag[0] == autopick_list[i].flag[0]
875 && entry->flag[1] == autopick_list[i].flag[1]
876 && entry->dice == autopick_list[i].dice
877 && entry->bonus == autopick_list[i].bonus) return 0;
879 add_autopick_list(entry);
885 * Reconstruct preference line from entry
887 cptr autopick_line_from_entry(autopick_type *entry)
889 char buf[MAX_LINELEN];
891 bool sepa_flag = TRUE;
894 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
895 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
896 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
897 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
901 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
902 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
903 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
904 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
905 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
906 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
907 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
909 if (IS_FLG(FLG_MORE_DICE))
911 ADD_KEY(KEY_MORE_THAN);
912 strcat(ptr, format("%d", entry->dice));
916 if (IS_FLG(FLG_MORE_BONUS))
918 ADD_KEY(KEY_MORE_BONUS);
919 strcat(ptr, format("%d", entry->bonus));
920 ADD_KEY(KEY_MORE_BONUS2);
923 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
924 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
925 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
926 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
927 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
928 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
929 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
930 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
931 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
932 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
933 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
934 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
935 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
936 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
937 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
938 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
939 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
941 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
943 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
944 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
945 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
946 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
947 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
948 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
949 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
950 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
951 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
952 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
953 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
954 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
955 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
956 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
957 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
958 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
959 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
960 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
961 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
962 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
964 /* You don't need sepalator after adjective */
965 /* 'artifact' is not true adjective */
966 else if (!IS_FLG(FLG_ARTIFACT))
969 if (entry->name && entry->name[0])
973 if (sepa_flag) strcat(buf, ":");
976 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
979 if (iskanji(entry->name[j]))
980 buf[i++] = entry->name[j++];
982 buf[i++] = entry->name[j++];
993 while (entry->insc[j] && i < MAX_LINELEN - 2)
996 if (iskanji(entry->insc[j]))
997 buf[i++] = entry->insc[j++];
999 buf[i++] = entry->insc[j++];
1004 return string_make(buf);
1009 * Reconstruct preference line from entry and kill entry
1011 static cptr autopick_line_from_entry_kill(autopick_type *entry)
1013 cptr ptr = autopick_line_from_entry(entry);
1015 /* Free memory for original entry */
1016 autopick_free_entry(entry);
1023 * A function for Auto-picker/destroyer
1024 * Examine whether the object matches to the entry
1026 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
1029 cptr ptr = entry->name;
1031 /*** Unaware items ***/
1032 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1035 /*** Unidentified ***/
1036 if (IS_FLG(FLG_UNIDENTIFIED)
1037 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1040 /*** Identified ***/
1041 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1044 /*** *Identified* ***/
1045 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1046 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1049 /*** Dice boosted (weapon of slaying) ***/
1050 if (IS_FLG(FLG_BOOSTED))
1052 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1054 /* Require melee weapon */
1055 if (!object_is_melee_weapon(o_ptr))
1058 /* Require boosted dice */
1059 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1063 /*** Weapons which dd*ds is more than nn ***/
1064 if (IS_FLG(FLG_MORE_DICE))
1066 if (o_ptr->dd * o_ptr->ds < entry->dice)
1070 /*** Weapons whic dd*ds is more than nn ***/
1071 if (IS_FLG(FLG_MORE_BONUS))
1073 if (!object_is_known(o_ptr)) return FALSE;
1077 if (o_ptr->pval < entry->bonus) return FALSE;
1081 if (o_ptr->to_h < entry->bonus &&
1082 o_ptr->to_d < entry->bonus &&
1083 o_ptr->to_a < entry->bonus &&
1084 o_ptr->pval < entry->bonus)
1089 /*** Worthless items ***/
1090 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1093 /*** Artifact object ***/
1094 if (IS_FLG(FLG_ARTIFACT))
1096 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1100 /*** Ego object ***/
1101 if (IS_FLG(FLG_EGO))
1103 /* Need to be an ego item */
1104 if (!object_is_ego(o_ptr)) return FALSE;
1106 /* Need to be known to be an ego */
1107 if (!object_is_known(o_ptr) &&
1108 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1113 if (IS_FLG(FLG_GOOD))
1115 if (!object_is_equipment(o_ptr)) return FALSE;
1118 if (object_is_known(o_ptr))
1120 /* Artifacts and Ego objects are not okay */
1121 if (!object_is_nameless(o_ptr))
1124 /* Average are not okay */
1125 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1129 /* Pseudo-identified */
1130 else if (o_ptr->ident & IDENT_SENSE)
1132 switch (o_ptr->feeling)
1147 /* Not known to be good */
1153 if (IS_FLG(FLG_NAMELESS))
1155 if (!object_is_equipment(o_ptr)) return FALSE;
1158 if (object_is_known(o_ptr))
1160 /* Artifacts and Ego objects are not okay */
1161 if (!object_is_nameless(o_ptr))
1165 /* Pseudo-identified */
1166 else if (o_ptr->ident & IDENT_SENSE)
1168 switch (o_ptr->feeling)
1178 /* It's not nameless */
1186 /* Not known to be nameless */
1192 if (IS_FLG(FLG_AVERAGE))
1194 if (!object_is_equipment(o_ptr)) return FALSE;
1197 if (object_is_known(o_ptr))
1199 /* Artifacts and Ego objects are not okay */
1200 if (!object_is_nameless(o_ptr))
1203 /* Cursed or broken objects are not okay */
1204 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1207 /* Good are not okay */
1208 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1212 /* Pseudo-identified */
1213 else if (o_ptr->ident & IDENT_SENSE)
1215 switch (o_ptr->feeling)
1222 /* It's not average */
1230 /* Not known to be average */
1235 /*** Rere equpiments ***/
1236 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1239 /*** Common equpiments ***/
1240 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1243 /*** Wanted monster's corpse/skeletons ***/
1244 if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
1247 /*** Unique monster's corpse/skeletons/statues ***/
1248 if (IS_FLG(FLG_UNIQUE) &&
1249 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1250 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1253 /*** Human corpse/skeletons (for Daemon magic) ***/
1254 if (IS_FLG(FLG_HUMAN) &&
1255 (o_ptr->tval != TV_CORPSE ||
1256 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1259 /*** Unreadable spellbooks ***/
1260 if (IS_FLG(FLG_UNREADABLE) &&
1261 (o_ptr->tval < TV_LIFE_BOOK ||
1262 check_book_realm(o_ptr->tval, o_ptr->sval)))
1265 /*** First realm spellbooks ***/
1266 if (IS_FLG(FLG_REALM1) &&
1267 (REALM1_BOOK != o_ptr->tval ||
1268 p_ptr->pclass == CLASS_SORCERER ||
1269 p_ptr->pclass == CLASS_RED_MAGE))
1272 /*** Second realm spellbooks ***/
1273 if (IS_FLG(FLG_REALM2) &&
1274 (REALM2_BOOK != o_ptr->tval ||
1275 p_ptr->pclass == CLASS_SORCERER ||
1276 p_ptr->pclass == CLASS_RED_MAGE))
1279 /*** First rank spellbooks ***/
1280 if (IS_FLG(FLG_FIRST) &&
1281 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1284 /*** Second rank spellbooks ***/
1285 if (IS_FLG(FLG_SECOND) &&
1286 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1289 /*** Third rank spellbooks ***/
1290 if (IS_FLG(FLG_THIRD) &&
1291 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1294 /*** Fourth rank spellbooks ***/
1295 if (IS_FLG(FLG_FOURTH) &&
1296 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1300 if (IS_FLG(FLG_WEAPONS))
1302 if (!object_is_weapon(o_ptr))
1305 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1307 if (!object_is_favorite(o_ptr))
1310 else if (IS_FLG(FLG_ARMORS))
1312 if (!object_is_armour(o_ptr))
1315 else if (IS_FLG(FLG_MISSILES))
1317 if (!object_is_ammo(o_ptr)) return FALSE;
1319 else if (IS_FLG(FLG_DEVICES))
1323 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1325 default: return FALSE;
1328 else if (IS_FLG(FLG_LIGHTS))
1330 if (!(o_ptr->tval == TV_LITE))
1333 else if (IS_FLG(FLG_JUNKS))
1337 case TV_SKELETON: case TV_BOTTLE:
1338 case TV_JUNK: case TV_STATUE:
1340 default: return FALSE;
1343 else if (IS_FLG(FLG_CORPSES))
1345 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1348 else if (IS_FLG(FLG_SPELLBOOKS))
1350 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1353 else if (IS_FLG(FLG_HAFTED))
1355 if (!(o_ptr->tval == TV_HAFTED))
1358 else if (IS_FLG(FLG_SHIELDS))
1360 if (!(o_ptr->tval == TV_SHIELD))
1363 else if (IS_FLG(FLG_BOWS))
1365 if (!(o_ptr->tval == TV_BOW))
1368 else if (IS_FLG(FLG_RINGS))
1370 if (!(o_ptr->tval == TV_RING))
1373 else if (IS_FLG(FLG_AMULETS))
1375 if (!(o_ptr->tval == TV_AMULET))
1378 else if (IS_FLG(FLG_SUITS))
1380 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1381 o_ptr->tval == TV_HARD_ARMOR ||
1382 o_ptr->tval == TV_SOFT_ARMOR))
1385 else if (IS_FLG(FLG_CLOAKS))
1387 if (!(o_ptr->tval == TV_CLOAK))
1390 else if (IS_FLG(FLG_HELMS))
1392 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1395 else if (IS_FLG(FLG_GLOVES))
1397 if (!(o_ptr->tval == TV_GLOVES))
1400 else if (IS_FLG(FLG_BOOTS))
1402 if (!(o_ptr->tval == TV_BOOTS))
1406 /* Keyword don't match */
1410 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1414 if (!my_strstr(o_name, ptr)) return FALSE;
1417 /* TRUE when it need not to be 'collecting' */
1418 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1420 /* Check if there is a same item */
1421 for (j = 0; j < INVEN_PACK; j++)
1424 * 'Collecting' means the item must be absorbed
1425 * into an inventory slot.
1426 * But an item can not be absorbed into itself!
1428 if ((&inventory[j] != o_ptr) &&
1429 object_similar(&inventory[j], o_ptr))
1433 /* Not collecting */
1439 * A function for Auto-picker/destroyer
1440 * Examine whether the object matches to the list of keywords or not.
1442 int is_autopick(object_type *o_ptr)
1445 char o_name[MAX_NLEN];
1447 if (o_ptr->tval == TV_GOLD) return -1;
1449 /* Prepare object name string first */
1450 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1452 /* Convert the string to lower case */
1453 str_tolower(o_name);
1455 /* Look for a matching entry in the list */
1456 for (i=0; i < max_autopick; i++)
1458 autopick_type *entry = &autopick_list[i];
1460 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1463 /* No matching entry */
1471 static void auto_inscribe_item(object_type *o_ptr, int idx)
1473 /* Are there auto-inscription? */
1474 if (idx < 0 || !autopick_list[idx].insc) return;
1476 if (!o_ptr->inscription)
1477 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1479 /* Redraw inscription */
1480 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1482 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1483 p_ptr->update |= (PU_BONUS);
1488 * Automatically destroy items in this grid.
1490 static bool is_opt_confirm_destroy(object_type *o_ptr)
1492 if (!destroy_items) return FALSE;
1494 /* Known to be worthless? */
1496 if (object_value(o_ptr) > 0) return FALSE;
1499 if (!object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1502 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1506 if (object_is_shoukinkubi(o_ptr)) return FALSE;
1510 if (o_ptr->tval == TV_CORPSE) return FALSE;
1513 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1517 if (p_ptr->prace == RACE_DEMON)
1519 if (o_ptr->tval == TV_CORPSE &&
1520 o_ptr->sval == SV_CORPSE &&
1521 my_strchr("pht", r_info[o_ptr->pval].d_char))
1525 if (p_ptr->pclass == CLASS_ARCHER)
1527 if (o_ptr->tval == TV_SKELETON ||
1528 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1531 else if (p_ptr->pclass == CLASS_NINJA)
1533 if (o_ptr->tval == TV_LITE &&
1534 o_ptr->name2 == EGO_LITE_DARKNESS)
1537 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1538 p_ptr->pclass == CLASS_CAVALRY)
1540 if (o_ptr->tval == TV_WAND &&
1541 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1546 if (o_ptr->tval == TV_GOLD) return FALSE;
1553 * Automatically destroy an item if it is to be destroyed
1555 * When always_pickup is 'yes', we disable auto-destroyer function of
1556 * auto-picker/destroyer, and do only easy-auto-destroyer.
1558 static object_type autopick_last_destroyed_object;
1560 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1562 bool destroy = FALSE;
1564 /* Easy-Auto-Destroyer (3rd priority) */
1565 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1567 /* Protected by auto-picker (2nd priotity) */
1568 if (autopick_idx >= 0 &&
1569 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1572 /* Auto-destroyer works only when !always_pickup */
1575 /* Auto-picker/destroyer (1st priority) */
1576 if (autopick_idx >= 0 &&
1577 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1581 /* Not to be destroyed */
1582 if (!destroy) return;
1584 /* Now decided to destroy */
1589 if (!can_player_destroy_object(o_ptr))
1591 char o_name[MAX_NLEN];
1593 /* Describe the object (with {terrible/special}) */
1594 object_desc(o_name, o_ptr, 0);
1598 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1600 msg_format("You cannot auto-destroy %s.", o_name);
1607 /* Record name of destroyed item */
1608 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1611 o_ptr->marked |= OM_AUTODESTROY;
1612 p_ptr->notice |= PN_AUTODESTROY;
1619 * Auto-destroy marked item
1621 static void autopick_delayed_alter_aux(int item)
1625 /* Get the item (in the pack) */
1626 if (item >= 0) o_ptr = &inventory[item];
1628 /* Get the item (on the floor) */
1629 else o_ptr = &o_list[0 - item];
1631 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1633 char o_name[MAX_NLEN];
1635 /* Describe the object (with {terrible/special}) */
1636 object_desc(o_name, o_ptr, 0);
1638 /* Eliminate the item (from the pack) */
1641 inven_item_increase(item, -(o_ptr->number));
1642 inven_item_optimize(item);
1645 /* Eliminate the item (from the floor) */
1648 delete_object_idx(0 - item);
1651 /* Print a message */
1653 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1655 msg_format("Auto-destroying %s.", o_name);
1662 * Auto-destroy marked items in inventry and on floor
1664 void autopick_delayed_alter(void)
1669 * Scan inventry in reverse order to prevent
1670 * skipping after inven_item_optimize()
1672 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1673 autopick_delayed_alter_aux(item);
1675 /* Scan the pile of objects */
1676 item = cave[py][px].o_idx;
1679 int next = o_list[item].next_o_idx;
1680 autopick_delayed_alter_aux(-item);
1687 * Auto-inscription and/or destroy
1689 * Auto-destroyer works only on inventory or on floor stack only when
1692 void autopick_alter_item(int item, bool destroy)
1697 /* Get the item (in the pack) */
1698 if (item >= 0) o_ptr = &inventory[item];
1700 /* Get the item (on the floor) */
1701 else o_ptr = &o_list[0 - item];
1703 /* Get the index in the auto-pick/destroy list */
1704 idx = is_autopick(o_ptr);
1706 /* Do auto-inscription */
1707 auto_inscribe_item(o_ptr, idx);
1709 /* Do auto-destroy if needed */
1710 if (destroy && item <= INVEN_PACK)
1711 auto_destroy_item(o_ptr, idx);
1716 * Automatically pickup/destroy items in this grid.
1718 void autopick_pickup_items(cave_type *c_ptr)
1720 s16b this_o_idx, next_o_idx = 0;
1722 /* Scan the pile of objects */
1723 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1727 /* Acquire object */
1728 object_type *o_ptr = &o_list[this_o_idx];
1730 /* Acquire next object */
1731 next_o_idx = o_ptr->next_o_idx;
1733 idx = is_autopick(o_ptr);
1735 /* Item index for floor -1,-2,-3,... */
1736 auto_inscribe_item(o_ptr, idx);
1739 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1743 if (!inven_carry_okay(o_ptr))
1745 char o_name[MAX_NLEN];
1747 /* Describe the object */
1748 object_desc(o_name, o_ptr, 0);
1752 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1754 msg_format("You have no room for %s.", o_name);
1756 /* Hack - remember that the item has given a message here. */
1757 o_ptr->marked |= OM_NOMSG;
1761 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1763 char out_val[MAX_NLEN+20];
1764 char o_name[MAX_NLEN];
1766 if (o_ptr->marked & OM_NO_QUERY)
1768 /* Already answered as 'No' */
1772 /* Describe the object */
1773 object_desc(o_name, o_ptr, 0);
1776 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1778 sprintf(out_val, "Pick up %s? ", o_name);
1781 if (!get_check(out_val))
1783 /* Hack - remember that the item has given a message here. */
1784 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1789 py_pickup_aux(this_o_idx);
1794 * When always_pickup is 'yes', we disable
1795 * auto-destroyer from autopick function, and do only
1796 * easy-auto-destroyer.
1800 auto_destroy_item(o_ptr, idx);
1806 static const char autoregister_header[] = "?:$AUTOREGISTER";
1809 * Clear auto registered lines in the picktype.prf .
1811 static bool clear_auto_register(void)
1813 char tmp_file[1024];
1814 char pref_file[1024];
1819 bool autoregister = FALSE;
1822 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1823 pref_fff = my_fopen(pref_file, "r");
1827 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1828 pref_fff = my_fopen(pref_file, "r");
1837 /* Open a new (temporary) file */
1838 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1842 /* Close the preference file */
1846 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1848 msg_format("Failed to create temporary file %s.", tmp_file);
1855 /* Loop for every line */
1859 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1863 /* Delete auto-registered line */
1865 /* Count auto-destroy preference lines */
1866 if (buf[0] != '#' && buf[0] != '?') num++;
1869 /* We are looking for auto-registered line */
1872 if (streq(buf, autoregister_header))
1874 /* Delete all further lines */
1875 autoregister = TRUE;
1879 /* Copy orginally lines */
1880 fprintf(tmp_fff, "%s\n", buf);
1886 my_fclose(pref_fff);
1892 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1893 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1895 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1896 strcpy(buf, "These lines will be deleted. Are you sure? ");
1899 /* You can cancel it */
1900 if (!get_check(buf))
1903 autoregister = FALSE;
1906 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1908 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1914 /* If there are some changes, overwrite the original file with new one */
1917 /* Copy contents of temporary file */
1919 tmp_fff = my_fopen(tmp_file, "r");
1920 pref_fff = my_fopen(pref_file, "w");
1922 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1923 fprintf(pref_fff, "%s\n", buf);
1925 my_fclose(pref_fff);
1929 /* Kill the temporary file */
1937 * Automatically register an auto-destroy preference line
1939 bool autopick_autoregister(object_type *o_ptr)
1942 char pref_file[1024];
1944 autopick_type an_entry, *entry = &an_entry;
1946 int match_autopick = is_autopick(o_ptr);
1948 /* Already registered */
1949 if (match_autopick != -1)
1952 byte act = autopick_list[match_autopick].action;
1955 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1956 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1957 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1958 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1960 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1962 if (act & DO_AUTOPICK) what = "auto-pickup";
1963 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1964 else if (act & DONT_AUTOPICK) what = "leave on floor";
1965 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1967 msg_format("The object is already registered to %s.", what);
1973 /* Known to be an artifact? */
1974 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1975 ((o_ptr->ident & IDENT_SENSE) &&
1976 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1978 char o_name[MAX_NLEN];
1980 /* Describe the object (with {terrible/special}) */
1981 object_desc(o_name, o_ptr, 0);
1985 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1987 msg_format("You cannot auto-destroy %s.", o_name);
1995 if (!p_ptr->autopick_autoregister)
1997 /* Clear old auto registered lines */
1998 if (!clear_auto_register()) return FALSE;
2001 /* Try a filename with player name */
2002 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
2003 pref_fff = my_fopen(pref_file, "r");
2007 /* Use default name */
2008 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
2009 pref_fff = my_fopen(pref_file, "r");
2012 /* Check the header */
2016 if (my_fgets(pref_fff, buf, sizeof(buf)))
2018 /* No header found */
2019 p_ptr->autopick_autoregister = FALSE;
2024 if (streq(buf, autoregister_header))
2026 /* Found the header */
2027 p_ptr->autopick_autoregister = TRUE;
2033 /* Close read only FILE* */
2036 /* Open for append */
2037 pref_fff = my_fopen(pref_file, "a");
2042 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
2044 msg_format("Failed to open %s.", pref_file);
2052 if (!p_ptr->autopick_autoregister)
2054 /* Add the header */
2055 fprintf(pref_fff, "%s\n", autoregister_header);
2058 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
2059 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
2061 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
2062 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
2065 /* Now auto register is in-use */
2066 p_ptr->autopick_autoregister = TRUE;
2069 /* Get a preference entry */
2070 autopick_entry_from_object(entry, o_ptr);
2072 /* Set to auto-destroy (with no-display) */
2073 entry->action = DO_AUTODESTROY;
2075 /* Load the new line as preference */
2076 add_autopick_list(entry);
2078 /* Add a line to the file */
2079 /* Don't kill "entry" */
2080 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2082 /* Close the file */
2089 /******** Auto-picker/destroyer editor **********/
2091 #define MAX_YANK MAX_LINELEN
2092 #define MAX_LINES 3000
2094 #define MARK_MARK 0x01
2095 #define MARK_BY_SHIFT 0x02
2097 #define LSTAT_BYPASS 0x01
2098 #define LSTAT_EXPRESSION 0x02
2099 #define LSTAT_AUTOREGISTER 0x04
2101 #define QUIT_WITHOUT_SAVE 1
2102 #define QUIT_AND_SAVE 2
2105 * Struct for yank buffer
2107 typedef struct chain_str {
2108 struct chain_str *next;
2114 * Data struct for text editor
2120 int old_wid, old_hgt;
2122 int old_upper, old_left;
2126 object_type *search_o_ptr;
2128 cptr last_destroyed;
2130 chain_str_type *yank;
2134 byte states[MAX_LINES];
2146 * Dirty flag for text editor
2148 #define DIRTY_ALL 0x0001
2149 #define DIRTY_MODE 0x0004
2150 #define DIRTY_SCREEN 0x0008
2151 #define DIRTY_NOT_FOUND 0x0010
2152 #define DIRTY_NO_SEARCH 0x0020
2153 #define DIRTY_EXPRESSION 0x0040
2154 #define DIRTY_SKIP_INACTIVE 0x0080
2155 #define DIRTY_INACTIVE 0x0100
2158 * Describe which kind of object is Auto-picked/destroyed
2160 static void describe_autopick(char *buff, autopick_type *entry)
2162 cptr str = entry->name;
2163 byte act = entry->action;
2164 cptr insc = entry->insc;
2170 cptr before_str[100], body_str;
2173 body_str = "¥¢¥¤¥Æ¥à";
2175 /*** Collecting items ***/
2176 /*** Which can be absorbed into a slot as a bundle ***/
2177 if (IS_FLG(FLG_COLLECTING))
2178 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2180 /*** Unaware items ***/
2181 if (IS_FLG(FLG_UNAWARE))
2182 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2184 /*** Unidentified ***/
2185 if (IS_FLG(FLG_UNIDENTIFIED))
2186 before_str[before_n++] = "̤´ÕÄê¤Î";
2188 /*** Identified ***/
2189 if (IS_FLG(FLG_IDENTIFIED))
2190 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2192 /*** *Identified* ***/
2193 if (IS_FLG(FLG_STAR_IDENTIFIED))
2194 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2196 /*** Dice boosted (weapon of slaying) ***/
2197 if (IS_FLG(FLG_BOOSTED))
2199 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2203 /*** Weapons whose dd*ds is more than nn ***/
2204 if (IS_FLG(FLG_MORE_DICE))
2206 static char more_than_desc_str[] = "___";
2207 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2210 sprintf(more_than_desc_str,"%d", entry->dice);
2211 before_str[before_n++] = more_than_desc_str;
2212 before_str[before_n++] = "°Ê¾å¤Î";
2215 /*** Items whose magical bonus is more than nn ***/
2216 if (IS_FLG(FLG_MORE_BONUS))
2218 static char more_bonus_desc_str[] = "___";
2219 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2221 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2222 before_str[before_n++] = more_bonus_desc_str;
2223 before_str[before_n++] = ")°Ê¾å¤Î";
2226 /*** Worthless items ***/
2227 if (IS_FLG(FLG_WORTHLESS))
2228 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2231 if (IS_FLG(FLG_ARTIFACT))
2233 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2238 if (IS_FLG(FLG_EGO))
2240 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2245 if (IS_FLG(FLG_GOOD))
2247 before_str[before_n++] = "¾å¼Á¤Î";
2252 if (IS_FLG(FLG_NAMELESS))
2254 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2259 if (IS_FLG(FLG_AVERAGE))
2261 before_str[before_n++] = "ʤÎ";
2265 /*** Rare equpiments ***/
2266 if (IS_FLG(FLG_RARE))
2268 before_str[before_n++] = "¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ò´Þ¤àÄÁ¤·¤¤";
2272 /*** Common equpiments ***/
2273 if (IS_FLG(FLG_COMMON))
2275 before_str[before_n++] = "¤¢¤ê¤Õ¤ì¤¿(¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ÎÄÁ¤·¤¤Êª¤Ç¤Ï¤Ê¤¤)";
2279 /*** Wanted monster's corpse/skeletons ***/
2280 if (IS_FLG(FLG_WANTED))
2282 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2283 body_str = "»àÂΤä¹ü";
2286 /*** Human corpse/skeletons (for Daemon magic) ***/
2287 if (IS_FLG(FLG_HUMAN))
2289 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2290 body_str = "»àÂΤä¹ü";
2293 /*** Unique monster's corpse/skeletons/statues ***/
2294 if (IS_FLG(FLG_UNIQUE))
2296 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2297 body_str = "»àÂΤä¹ü";
2300 /*** Unreadable spellbooks ***/
2301 if (IS_FLG(FLG_UNREADABLE))
2303 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2304 body_str = "ËâË¡½ñ";
2307 /*** First realm spellbooks ***/
2308 if (IS_FLG(FLG_REALM1))
2310 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2311 body_str = "ËâË¡½ñ";
2314 /*** Second realm spellbooks ***/
2315 if (IS_FLG(FLG_REALM2))
2317 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2318 body_str = "ËâË¡½ñ";
2321 /*** First rank spellbooks ***/
2322 if (IS_FLG(FLG_FIRST))
2324 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2325 body_str = "ËâË¡½ñ";
2328 /*** Second rank spellbooks ***/
2329 if (IS_FLG(FLG_SECOND))
2331 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2332 body_str = "ËâË¡½ñ";
2335 /*** Third rank spellbooks ***/
2336 if (IS_FLG(FLG_THIRD))
2338 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2339 body_str = "ËâË¡½ñ";
2342 /*** Fourth rank spellbooks ***/
2343 if (IS_FLG(FLG_FOURTH))
2345 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2346 body_str = "ËâË¡½ñ";
2350 if (IS_FLG(FLG_ITEMS))
2351 ; /* Nothing to do */
2352 else if (IS_FLG(FLG_WEAPONS))
2354 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2355 body_str = "ÆÀ°ÕÉð´ï";
2356 else if (IS_FLG(FLG_ARMORS))
2358 else if (IS_FLG(FLG_MISSILES))
2359 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2360 else if (IS_FLG(FLG_DEVICES))
2361 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2362 else if (IS_FLG(FLG_LIGHTS))
2363 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2364 else if (IS_FLG(FLG_JUNKS))
2365 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2366 else if (IS_FLG(FLG_CORPSES))
2367 body_str = "»àÂΤä¹ü";
2368 else if (IS_FLG(FLG_SPELLBOOKS))
2369 body_str = "ËâË¡½ñ";
2370 else if (IS_FLG(FLG_HAFTED))
2372 else if (IS_FLG(FLG_SHIELDS))
2374 else if (IS_FLG(FLG_BOWS))
2375 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2376 else if (IS_FLG(FLG_RINGS))
2378 else if (IS_FLG(FLG_AMULETS))
2379 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2380 else if (IS_FLG(FLG_SUITS))
2382 else if (IS_FLG(FLG_CLOAKS))
2383 body_str = "¥¯¥í¡¼¥¯";
2384 else if (IS_FLG(FLG_HELMS))
2385 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2386 else if (IS_FLG(FLG_GLOVES))
2388 else if (IS_FLG(FLG_BOOTS))
2389 body_str = "¥Ö¡¼¥Ä";
2393 strcat(buff, "Á´¤Æ¤Î");
2394 else for (i = 0; i < before_n && before_str[i]; i++)
2395 strcat(buff, before_str[i]);
2397 strcat(buff, body_str);
2407 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2408 strncat(buff, str, 80);
2410 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2412 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2417 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2419 if (my_strstr(insc, "%%all"))
2420 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2421 else if (my_strstr(insc, "%all"))
2422 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2423 else if (my_strstr(insc, "%%"))
2424 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2425 else if (my_strstr(insc, "%"))
2426 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2428 strcat(buff, "¤È¹ï¤ó¤Ç");
2433 if (act & DONT_AUTOPICK)
2434 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2435 else if (act & DO_AUTODESTROY)
2436 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2437 else if (act & DO_QUERY_AUTOPICK)
2438 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2440 strcat(buff, "½¦¤¦¡£");
2442 if (act & DO_DISPLAY)
2444 if (act & DONT_AUTOPICK)
2445 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2446 else if (act & DO_AUTODESTROY)
2447 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2449 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2452 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2456 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2457 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2461 /*** Collecting items ***/
2462 /*** Which can be absorbed into a slot as a bundle ***/
2463 if (IS_FLG(FLG_COLLECTING))
2464 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2466 /*** Unaware items ***/
2467 if (IS_FLG(FLG_UNAWARE))
2469 before_str[before_n++] = "unidentified";
2470 whose_str[whose_n++] = "basic abilities are not known";
2473 /*** Unidentified ***/
2474 if (IS_FLG(FLG_UNIDENTIFIED))
2475 before_str[before_n++] = "unidentified";
2477 /*** Identified ***/
2478 if (IS_FLG(FLG_IDENTIFIED))
2479 before_str[before_n++] = "identified";
2481 /*** *Identified* ***/
2482 if (IS_FLG(FLG_STAR_IDENTIFIED))
2483 before_str[before_n++] = "fully identified";
2485 /*** Rare equpiments ***/
2486 if (IS_FLG(FLG_RARE))
2488 before_str[before_n++] = "very rare";
2489 body_str = "equipments";
2490 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2493 /*** Common equpiments ***/
2494 if (IS_FLG(FLG_COMMON))
2496 before_str[before_n++] = "relatively common";
2497 body_str = "equipments";
2498 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2501 /*** Worthless items ***/
2502 if (IS_FLG(FLG_WORTHLESS))
2504 before_str[before_n++] = "worthless";
2505 which_str[which_n++] = "can not be sold at stores";
2509 if (IS_FLG(FLG_ARTIFACT))
2511 before_str[before_n++] = "artifact";
2515 if (IS_FLG(FLG_EGO))
2517 before_str[before_n++] = "ego";
2521 if (IS_FLG(FLG_GOOD))
2523 body_str = "equipment";
2524 which_str[which_n++] = "have good quality";
2528 if (IS_FLG(FLG_NAMELESS))
2530 body_str = "equipment";
2531 which_str[which_n++] = "is neither ego-item nor artifact";
2535 if (IS_FLG(FLG_AVERAGE))
2537 body_str = "equipment";
2538 which_str[which_n++] = "have average quality";
2541 /*** Dice boosted (weapon of slaying) ***/
2542 if (IS_FLG(FLG_BOOSTED))
2544 body_str = "weapons";
2545 whose_str[whose_n++] = "damage dice is bigger than normal";
2548 /*** Weapons whose dd*ds is more than nn ***/
2549 if (IS_FLG(FLG_MORE_DICE))
2551 static char more_than_desc_str[] =
2552 "maximum damage from dice is bigger than __";
2553 body_str = "weapons";
2555 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2557 whose_str[whose_n++] = more_than_desc_str;
2560 /*** Items whose magical bonus is more than nn ***/
2561 if (IS_FLG(FLG_MORE_BONUS))
2563 static char more_bonus_desc_str[] =
2564 "magical bonus is bigger than (+__)";
2566 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2567 "%d)", entry->bonus);
2568 whose_str[whose_n++] = more_bonus_desc_str;
2571 /*** Wanted monster's corpse/skeletons ***/
2572 if (IS_FLG(FLG_WANTED))
2574 body_str = "corpse or skeletons";
2575 which_str[which_n++] = "is wanted at the Hunter's Office";
2578 /*** Human corpse/skeletons (for Daemon magic) ***/
2579 if (IS_FLG(FLG_HUMAN))
2581 before_str[before_n++] = "humanoid";
2582 body_str = "corpse or skeletons";
2583 which_str[which_n++] = "can be used for Daemon magic";
2586 /*** Unique monster's corpse/skeletons/statues ***/
2587 if (IS_FLG(FLG_UNIQUE))
2589 before_str[before_n++] = "unique monster's";
2590 body_str = "corpse or skeletons";
2593 /*** Unreadable spellbooks ***/
2594 if (IS_FLG(FLG_UNREADABLE))
2596 body_str = "spellbooks";
2597 after_str[after_n++] = "of different realms from yours";
2600 /*** First realm spellbooks ***/
2601 if (IS_FLG(FLG_REALM1))
2603 body_str = "spellbooks";
2604 after_str[after_n++] = "of your first realm";
2607 /*** Second realm spellbooks ***/
2608 if (IS_FLG(FLG_REALM2))
2610 body_str = "spellbooks";
2611 after_str[after_n++] = "of your second realm";
2614 /*** First rank spellbooks ***/
2615 if (IS_FLG(FLG_FIRST))
2617 before_str[before_n++] = "first one of four";
2618 body_str = "spellbooks";
2621 /*** Second rank spellbooks ***/
2622 if (IS_FLG(FLG_SECOND))
2624 before_str[before_n++] = "second one of four";
2625 body_str = "spellbooks";
2628 /*** Third rank spellbooks ***/
2629 if (IS_FLG(FLG_THIRD))
2631 before_str[before_n++] = "third one of four";
2632 body_str = "spellbooks";
2635 /*** Fourth rank spellbooks ***/
2636 if (IS_FLG(FLG_FOURTH))
2638 before_str[before_n++] = "fourth one of four";
2639 body_str = "spellbooks";
2643 if (IS_FLG(FLG_ITEMS))
2644 ; /* Nothing to do */
2645 else if (IS_FLG(FLG_WEAPONS))
2646 body_str = "weapons";
2647 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2648 body_str = "favorite weapons";
2649 else if (IS_FLG(FLG_ARMORS))
2650 body_str = "armors";
2651 else if (IS_FLG(FLG_MISSILES))
2652 body_str = "shots, arrows or crossbow bolts";
2653 else if (IS_FLG(FLG_DEVICES))
2654 body_str = "scrolls, wands, staves or rods";
2655 else if (IS_FLG(FLG_LIGHTS))
2656 body_str = "light sources";
2657 else if (IS_FLG(FLG_JUNKS))
2658 body_str = "junk such as broken sticks";
2659 else if (IS_FLG(FLG_CORPSES))
2660 body_str = "corpses or skeletons";
2661 else if (IS_FLG(FLG_SPELLBOOKS))
2662 body_str = "spellbooks";
2663 else if (IS_FLG(FLG_HAFTED))
2664 body_str = "hafted weapons";
2665 else if (IS_FLG(FLG_SHIELDS))
2666 body_str = "shields";
2667 else if (IS_FLG(FLG_BOWS))
2668 body_str = "slings, bows or crossbows";
2669 else if (IS_FLG(FLG_RINGS))
2671 else if (IS_FLG(FLG_AMULETS))
2672 body_str = "amulets";
2673 else if (IS_FLG(FLG_SUITS))
2674 body_str = "body armors";
2675 else if (IS_FLG(FLG_CLOAKS))
2676 body_str = "cloaks";
2677 else if (IS_FLG(FLG_HELMS))
2678 body_str = "helms or crowns";
2679 else if (IS_FLG(FLG_GLOVES))
2680 body_str = "gloves";
2681 else if (IS_FLG(FLG_BOOTS))
2684 /* Prepare a string for item name */
2691 whose_str[whose_n++] = "name is beginning with \"";
2694 which_str[which_n++] = "have \"";
2698 /* Describe action flag */
2699 if (act & DONT_AUTOPICK)
2700 strcpy(buff, "Leave on floor ");
2701 else if (act & DO_AUTODESTROY)
2702 strcpy(buff, "Destroy ");
2703 else if (act & DO_QUERY_AUTOPICK)
2704 strcpy(buff, "Ask to pick up ");
2706 strcpy(buff, "Pickup ");
2708 /* Auto-insctiption */
2711 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2713 if (my_strstr(insc, "%all"))
2714 strcat(buff, ", replacing %all with code string representing all abilities,");
2715 else if (my_strstr(insc, "%"))
2716 strcat(buff, ", replacing % with code string representing extra random abilities,");
2718 strcat(buff, " on ");
2723 strcat(buff, "all ");
2724 else for (i = 0; i < before_n && before_str[i]; i++)
2726 strcat(buff, before_str[i]);
2731 strcat(buff, body_str);
2734 for (i = 0; i < after_n && after_str[i]; i++)
2737 strcat(buff, after_str[i]);
2741 for (i = 0; i < whose_n && whose_str[i]; i++)
2744 strcat(buff, " whose ");
2746 strcat(buff, ", and ");
2748 strcat(buff, whose_str[i]);
2751 /* Item name ; whose name is beginning with "str" */
2758 /* whose ..., and which .... */
2759 if (whose_n && which_n)
2760 strcat(buff, ", and ");
2763 for (i = 0; i < which_n && which_str[i]; i++)
2766 strcat(buff, " which ");
2768 strcat(buff, ", and ");
2770 strcat(buff, which_str[i]);
2773 /* Item name ; which have "str" as part of its name */
2776 strncat(buff, str, 80);
2777 strcat(buff, "\" as part of its name");
2781 /* Describe whether it will be displayed on the full map or not */
2782 if (act & DO_DISPLAY)
2784 if (act & DONT_AUTOPICK)
2785 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2786 else if (act & DO_AUTODESTROY)
2787 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2789 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2792 strcat(buff, " Not displayed in the full map.");
2799 * Read whole lines of a file to memory
2801 static cptr *read_text_lines(cptr filename)
2803 cptr *lines_list = NULL;
2809 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2812 fff = my_fopen(buf, "r");
2816 /* Allocate list of pointers */
2817 C_MAKE(lines_list, MAX_LINES, cptr);
2820 while (0 == my_fgets(fff, buf, sizeof(buf)))
2822 lines_list[lines++] = string_make(buf);
2823 if (lines >= MAX_LINES - 1) break;
2826 lines_list[0] = string_make("");
2831 if (!fff) return NULL;
2837 * Copy the default autopick file to the user directory
2839 static void prepare_default_pickpref(void)
2841 static char *messages[] = {
2843 "¤¢¤Ê¤¿¤Ï¡Ö¼«Æ°½¦¤¤¥¨¥Ç¥£¥¿¡×¤ò½é¤á¤Æµ¯Æ°¤·¤Þ¤·¤¿¡£",
2844 "¼«Æ°½¦¤¤¤Î¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤¬¤Þ¤À½ñ¤«¤ì¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢",
2845 "´ðËÜŪ¤Ê¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤òlib/pref/picktype.prf¤«¤é¥³¥Ô¡¼¤·¤Þ¤¹¡£",
2848 "You have activated the Auto-Picker Editor for the first time.",
2849 "Since user pref file for autopick is not yet created,",
2850 "the default setting is loaded from lib/pref/pickpref.prf .",
2859 cptr filename = pickpref_filename(PT_DEFAULT);
2861 /* Display messages */
2862 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2867 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2868 user_fp = my_fopen(buf, "w");
2871 if (!user_fp) return;
2873 /* Write header messages for a notification */
2874 fprintf(user_fp, "#***\n");
2875 for (i = 0; messages[i]; i++)
2877 fprintf(user_fp, "#*** %s\n", messages[i]);
2879 fprintf(user_fp, "#***\n\n\n");
2882 /* Open the default file */
2883 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2884 pref_fp = my_fopen(buf, "r");
2893 /* Copy the contents of default file */
2894 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2895 fprintf(user_fp, "%s\n", buf);
2902 * Read an autopick prefence file to memory
2903 * Prepare default if no user file is found
2905 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2910 /* Try a filename with player name */
2911 *filename_mode_p = PT_WITH_PNAME;
2912 strcpy(buf, pickpref_filename(*filename_mode_p));
2913 lines_list = read_text_lines(buf);
2917 /* Use default name */
2918 *filename_mode_p = PT_DEFAULT;
2919 strcpy(buf, pickpref_filename(*filename_mode_p));
2920 lines_list = read_text_lines(buf);
2925 /* There is no preference file in the user directory */
2927 /* Copy the default autopick file to the user directory */
2928 prepare_default_pickpref();
2930 /* Use default name again */
2931 lines_list = read_text_lines(buf);
2936 /* Allocate list of pointers */
2937 C_MAKE(lines_list, MAX_LINES, cptr);
2938 lines_list[0] = string_make("");
2945 * Write whole lines of memory to a file.
2947 static bool write_text_lines(cptr filename, cptr *lines_list)
2954 /* Build the filename */
2955 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2958 fff = my_fopen(buf, "w");
2961 for (lines = 0; lines_list[lines]; lines++)
2962 my_fputs(fff, lines_list[lines], 1024);
2967 if (!fff) return FALSE;
2973 * Free memory of lines_list.
2975 static void free_text_lines(cptr *lines_list)
2979 for (lines = 0; lines_list[lines]; lines++)
2980 string_free(lines_list[lines]);
2982 /* free list of pointers */
2983 C_FREE((char **)lines_list, MAX_LINES, char *);
2988 * Delete or insert string
2990 static void toggle_keyword(text_body_type *tb, int flg)
2996 /* Some lines are selected */
2999 by1 = MIN(tb->my, tb->cy);
3000 by2 = MAX(tb->my, tb->cy);
3003 /* No mark -- Select current line */
3004 else /* if (!tb->mark) */
3010 /* Set/Reset flag of each line */
3011 for (y = by1; y <= by2; y++)
3013 autopick_type an_entry, *entry = &an_entry;
3015 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
3017 string_free(tb->lines_list[y]);
3021 /* Add? or Remove? */
3022 if (!IS_FLG(flg)) add = TRUE;
3025 /* No more change */
3029 /* You can use only one noun flag */
3030 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3033 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3037 /* You can use only one identify state flag */
3038 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
3041 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
3045 /* You can use only one flag in artifact/ego/nameless */
3046 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
3049 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
3053 /* You can use only one flag in rare/common */
3054 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
3057 for (i = FLG_RARE; i <= FLG_COMMON; i++)
3061 if (add) ADD_FLG(flg);
3064 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3067 tb->dirty_flags |= DIRTY_ALL;
3069 /* Text is changed */
3076 * Change command letter
3078 static void toggle_command_letter(text_body_type *tb, byte flg)
3080 autopick_type an_entry, *entry = &an_entry;
3085 /* Some lines are selected */
3088 by1 = MIN(tb->my, tb->cy);
3089 by2 = MAX(tb->my, tb->cy);
3092 /* No mark -- Select current line */
3093 else /* if (!tb->mark) */
3099 /* Set/Reset flag of each line */
3100 for (y = by1; y <= by2; y++)
3104 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3106 string_free(tb->lines_list[y]);
3110 /* Add? or Remove? */
3111 if (!(entry->action & flg)) add = TRUE;
3114 /* No more change */
3118 /* Count number of letter (by negative number) */
3119 if (entry->action & DONT_AUTOPICK) wid--;
3120 else if (entry->action & DO_AUTODESTROY) wid--;
3121 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3122 if (!(entry->action & DO_DISPLAY)) wid--;
3124 /* Set/Reset the flag */
3125 if (flg != DO_DISPLAY)
3127 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3128 if (add) entry->action |= flg;
3129 else entry->action |= DO_AUTOPICK;
3133 entry->action &= ~(DO_DISPLAY);
3134 if (add) entry->action |= flg;
3137 /* Correct cursor location */
3140 if (entry->action & DONT_AUTOPICK) wid++;
3141 else if (entry->action & DO_AUTODESTROY) wid++;
3142 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3143 if (!(entry->action & DO_DISPLAY)) wid++;
3145 if (wid > 0) tb->cx++;
3146 if (wid < 0 && tb->cx > 0) tb->cx--;
3149 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3152 tb->dirty_flags |= DIRTY_ALL;
3154 /* Text is changed */
3160 * Delete or insert string
3162 static void add_keyword(text_body_type *tb, int flg)
3166 /* Some lines are selected */
3169 by1 = MIN(tb->my, tb->cy);
3170 by2 = MAX(tb->my, tb->cy);
3173 /* No mark -- Select current line */
3174 else /* if (!tb->mark) */
3180 /* Set/Reset flag of each line */
3181 for (y = by1; y <= by2; y++)
3183 autopick_type an_entry, *entry = &an_entry;
3185 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3187 /* There is the flag already */
3190 /* Free memory for the entry */
3191 autopick_free_entry(entry);
3196 string_free(tb->lines_list[y]);
3198 /* Remove all noun flag */
3199 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3202 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3208 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3211 tb->dirty_flags |= DIRTY_ALL;
3213 /* Text is changed */
3220 * Check if this line is expression or not.
3221 * And update it if it is.
3223 static void check_expression_line(text_body_type *tb, int y)
3225 cptr s = tb->lines_list[y];
3227 if ((s[0] == '?' && s[1] == ':') ||
3228 (tb->states[y] & LSTAT_BYPASS))
3230 /* Expressions need re-evaluation */
3231 tb->dirty_flags |= DIRTY_EXPRESSION;
3237 * Insert return code and split the line
3239 static bool insert_return_code(text_body_type *tb)
3241 char buf[MAX_LINELEN];
3244 for (k = 0; tb->lines_list[k]; k++)
3245 /* count number of lines */ ;
3247 if (k >= MAX_LINES - 2) return FALSE;
3250 /* Move down lines */
3251 for (; tb->cy < k; k--)
3253 tb->lines_list[k+1] = tb->lines_list[k];
3254 tb->states[k+1] = tb->states[k];
3257 /* Split current line */
3258 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3261 if (iskanji(tb->lines_list[tb->cy][i]))
3262 buf[j++] = tb->lines_list[tb->cy][i++];
3264 buf[j++] = tb->lines_list[tb->cy][i];
3267 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3268 string_free(tb->lines_list[tb->cy]);
3269 tb->lines_list[tb->cy] = string_make(buf);
3271 /* Expressions need re-evaluation */
3272 tb->dirty_flags |= DIRTY_EXPRESSION;
3274 /* Text is changed */
3282 * Choose an item and get auto-picker entry from it.
3284 static object_type *choose_object(cptr q, cptr s)
3288 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3290 /* Get the item (in the pack) */
3291 if (item >= 0) return &inventory[item];
3293 /* Get the item (on the floor) */
3294 else return &o_list[0 - item];
3299 * Choose an item and get auto-picker entry from it.
3301 static bool entry_from_choosed_object(autopick_type *entry)
3308 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3309 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3311 q = "Enter which item? ";
3312 s = "You have nothing to enter.";
3314 o_ptr = choose_object(q, s);
3315 if (!o_ptr) return FALSE;
3317 autopick_entry_from_object(entry, o_ptr);
3323 * Choose an item for search
3325 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3327 char buf[MAX_NLEN+20];
3333 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3334 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3336 q = "Enter which item? ";
3337 s = "You have nothing to enter.";
3339 o_ptr = choose_object(q, s);
3340 if (!o_ptr) return 0;
3344 string_free(*search_strp);
3345 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3346 *search_strp = string_make(format("<%s>", buf));
3352 * Prepare for search by destroyed object
3354 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3356 char buf[MAX_NLEN+20];
3358 if (!autopick_last_destroyed_object.k_idx) return 0;
3360 *o_handle = &autopick_last_destroyed_object;
3362 string_free(*search_strp);
3363 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3364 *search_strp = string_make(format("<%s>", buf));
3370 * Choose an item or string for search
3372 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3378 * TERM_YELLOW : Overwrite mode
3379 * TERM_WHITE : Insert mode
3381 byte color = TERM_YELLOW;
3382 char buf[MAX_NLEN+20];
3386 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3388 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3390 int col = sizeof(prompt) - 1;
3392 /* Prepare string buffer for edit */
3393 if (*search_strp) strcpy(buf, *search_strp);
3396 /* Object searching mode */
3399 color = TERM_L_GREEN;
3402 /* Display prompt */
3412 /* Display the string */
3413 Term_erase(col, 0, 255);
3414 Term_putstr(col, 0, -1, color, buf);
3417 Term_gotoxy(col + pos, 0);
3419 /* Get a special key code */
3420 skey = inkey_special(TRUE);
3422 /* Analyze the key */
3430 /* Now on insert mode */
3433 /* No move at beginning of line */
3434 if (0 == pos) break;
3438 int next_pos = i + 1;
3441 if (iskanji(buf[i])) next_pos++;
3444 /* Is there the cursor at next position? */
3445 if (next_pos >= pos) break;
3451 /* Get previous position */
3459 /* Now on insert mode */
3462 /* No move at end of line */
3463 if ('\0' == buf[pos]) break;
3467 if (iskanji(buf[pos])) pos += 2;
3485 if (*o_handle) return (back ? -1 : 1);
3486 string_free(*search_strp);
3487 *search_strp = string_make(buf);
3489 return (back ? -1 : 1);
3493 return get_object_for_search(o_handle, search_strp);
3496 /* Prepare string for destroyed object if there is one. */
3497 if (get_destroyed_object_for_search(o_handle, search_strp))
3507 /* Now on insert mode */
3510 /* No move at beginning of line */
3511 if (0 == pos) break;
3515 int next_pos = i + 1;
3518 if (iskanji(buf[i])) next_pos++;
3521 /* Is there the cursor at next position? */
3522 if (next_pos >= pos) break;
3528 /* Get previous position */
3531 /* Fall through to 'Delete key' */
3540 /* Now on insert mode */
3543 /* No move at end of line */
3544 if ('\0' == buf[pos]) break;
3546 /* Position of next character */
3550 /* Next character is one more byte away */
3551 if (iskanji(buf[pos])) src++;
3556 /* Move characters at src to dst */
3557 while ('\0' != (buf[dst++] = buf[src++]))
3565 /* Insert a character */
3570 /* Ignore special keys */
3571 if (skey & SKEY_MASK) break;
3573 /* Get a character code */
3576 /* Was non insert mode? */
3577 if (color != TERM_WHITE)
3579 /* Was object searching mode */
3580 if (color == TERM_L_GREEN)
3582 /* Cancel the mode */
3585 /* Remove indicating string */
3586 string_free(*search_strp);
3587 *search_strp = NULL;
3590 /* Overwrite default string */
3593 /* Go to insert mode */
3597 /* Save right part of string */
3598 strcpy(tmp, buf + pos);
3604 /* Bypass macro processing */
3622 if (pos < len && (isprint(c) || iskana(c)))
3624 if (pos < len && isprint(c))
3638 /* Write back the left part of string */
3639 my_strcat(buf, tmp, len + 1);
3646 /* Object searching mode was cancelled? */
3647 if (*o_handle && color != TERM_L_GREEN)
3649 /* Cancel the mode */
3652 /* Remove indicating string */
3654 string_free(*search_strp);
3655 *search_strp = NULL;
3660 } /* while (TRUE) */
3665 * Search next line matches for o_ptr
3667 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3669 autopick_type an_entry, *entry = &an_entry;
3670 char o_name[MAX_NLEN];
3671 int bypassed_cy = -1;
3673 /* Start searching from current cursor position */
3676 /* Prepare object name string first */
3677 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3679 /* Convert the string to lower case */
3680 str_tolower(o_name);
3687 if (!tb->lines_list[++i]) break;
3694 /* Is this line is a correct entry? */
3695 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3697 /* Does this line match to the object? */
3698 if (!is_autopick_aux(o_ptr, entry, o_name)) continue;
3701 /* Found a line but it's inactive */
3702 if (tb->states[i] & LSTAT_BYPASS)
3704 /* If it is first found, remember it */
3705 if (bypassed_cy == -1) bypassed_cy = i;
3708 /* Found an active line! */
3711 /* Move to this line */
3715 if (bypassed_cy != -1)
3717 /* Mark as some lines are skipped */
3718 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3726 if (bypassed_cy != -1)
3728 /* Move to the remembered line */
3730 tb->cy = bypassed_cy;
3732 /* Mark as this line is inactive */
3733 tb->dirty_flags |= DIRTY_INACTIVE;
3738 /* Mark as NOT FOUND */
3739 tb->dirty_flags |= DIRTY_NOT_FOUND;
3747 * Search next line matches to the string
3749 static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
3751 int bypassed_cy = -1;
3752 int bypassed_cx = 0;
3754 /* Start searching from current cursor position */
3764 if (!tb->lines_list[++i]) break;
3771 /* Look for the string pattern */
3772 pos = my_strstr(tb->lines_list[i], search_str);
3777 /* Found a line but it's inactive */
3778 if ((tb->states[i] & LSTAT_BYPASS) &&
3779 !(tb->states[i] & LSTAT_EXPRESSION))
3781 /* If it is first found, remember it */
3782 if (bypassed_cy == -1)
3785 bypassed_cx = (int)(pos - tb->lines_list[i]);
3789 /* Found an active line! */
3792 /* Move to this location */
3793 tb->cx = (int)(pos - tb->lines_list[i]);
3796 if (bypassed_cy != -1)
3798 /* Mark as some lines are skipped */
3799 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3807 if (bypassed_cy != -1)
3809 /* Move to the remembered line */
3810 tb->cx = bypassed_cx;
3811 tb->cy = bypassed_cy;
3813 /* Mark as this line is inactive */
3814 tb->dirty_flags |= DIRTY_INACTIVE;
3819 /* Mark as NOT FOUND */
3820 tb->dirty_flags |= DIRTY_NOT_FOUND;
3830 * Editor command id's
3833 #define EC_SAVEQUIT 2
3844 #define EC_PGDOWN 13
3846 #define EC_BOTTOM 15
3851 #define EC_KILL_LINE 20
3852 #define EC_DELETE_CHAR 21
3853 #define EC_BACKSPACE 22
3854 #define EC_SEARCH_STR 23
3855 #define EC_SEARCH_FORW 24
3856 #define EC_SEARCH_BACK 25
3857 #define EC_SEARCH_OBJ 26
3858 #define EC_SEARCH_DESTROYED 27
3859 #define EC_INSERT_OBJECT 28
3860 #define EC_INSERT_DESTROYED 29
3861 #define EC_INSERT_BLOCK 30
3862 #define EC_INSERT_MACRO 31
3863 #define EC_INSERT_KEYMAP 32
3864 #define EC_CL_AUTOPICK 33
3865 #define EC_CL_DESTROY 34
3866 #define EC_CL_LEAVE 35
3867 #define EC_CL_QUERY 36
3868 #define EC_CL_NO_DISP 37
3869 #define EC_OK_COLLECTING 38
3870 #define EC_IK_UNAWARE 39
3871 #define EC_IK_UNIDENTIFIED 40
3872 #define EC_IK_IDENTIFIED 41
3873 #define EC_IK_STAR_IDENTIFIED 42
3874 #define EC_OK_BOOSTED 43
3875 #define EC_OK_MORE_DICE 44
3876 #define EC_OK_MORE_BONUS 45
3877 #define EC_OK_WORTHLESS 46
3878 #define EC_OK_ARTIFACT 47
3879 #define EC_OK_EGO 48
3880 #define EC_OK_GOOD 49
3881 #define EC_OK_NAMELESS 50
3882 #define EC_OK_AVERAGE 51
3883 #define EC_OK_RARE 52
3884 #define EC_OK_COMMON 53
3885 #define EC_OK_WANTED 54
3886 #define EC_OK_UNIQUE 55
3887 #define EC_OK_HUMAN 56
3888 #define EC_OK_UNREADABLE 57
3889 #define EC_OK_REALM1 58
3890 #define EC_OK_REALM2 59
3891 #define EC_OK_FIRST 60
3892 #define EC_OK_SECOND 61
3893 #define EC_OK_THIRD 62
3894 #define EC_OK_FOURTH 63
3895 #define EC_KK_WEAPONS 64
3896 #define EC_KK_FAVORITE_WEAPONS 65
3897 #define EC_KK_ARMORS 66
3898 #define EC_KK_MISSILES 67
3899 #define EC_KK_DEVICES 68
3900 #define EC_KK_LIGHTS 69
3901 #define EC_KK_JUNKS 70
3902 #define EC_KK_CORPSES 71
3903 #define EC_KK_SPELLBOOKS 72
3904 #define EC_KK_SHIELDS 73
3905 #define EC_KK_BOWS 74
3906 #define EC_KK_RINGS 75
3907 #define EC_KK_AMULETS 76
3908 #define EC_KK_SUITS 77
3909 #define EC_KK_CLOAKS 78
3910 #define EC_KK_HELMS 79
3911 #define EC_KK_GLOVES 80
3912 #define EC_KK_BOOTS 81
3918 static char MN_QUIT[] = "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»";
3919 static char MN_SAVEQUIT[] = "¥»¡¼¥Ö¤·¤Æ½ªÎ»";
3920 static char MN_REVERT[] = "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ";
3921 static char MN_HELP[] = "¥Ø¥ë¥×";
3923 static char MN_MOVE[] = "¥«¡¼¥½¥ë°ÜÆ°";
3924 static char MN_LEFT[] = "º¸ (¢«Ìð°õ¥¡¼)";
3925 static char MN_DOWN[] = "²¼ (¢Ìð°õ¥¡¼)";
3926 static char MN_UP[] = "¾å (¢¬Ìð°õ¥¡¼)";
3927 static char MN_RIGHT[] = "±¦ (¢ªÌð°õ¥¡¼)";
3928 static char MN_BOL[] = "¹Ô¤ÎÀèƬ";
3929 static char MN_EOL[] = "¹Ô¤Î½ªÃ¼";
3930 static char MN_PGUP[] = "¾å¤Î¥Ú¡¼¥¸ (PageUp¥¡¼)";
3931 static char MN_PGDOWN[] = "²¼¤Î¥Ú¡¼¥¸ (PageDown¥¡¼)";
3932 static char MN_TOP[] = "1¹ÔÌܤذÜÆ° (Home¥¡¼)";
3933 static char MN_BOTTOM[] = "ºÇ²¼¹Ô¤Ø°ÜÆ°(End¥¡¼)";
3935 static char MN_EDIT[] = "ÊÔ½¸";
3936 static char MN_CUT[] = "¥«¥Ã¥È";
3937 static char MN_COPY[] = "¥³¥Ô¡¼";
3938 static char MN_PASTE[] = "¥Ú¡¼¥¹¥È";
3939 static char MN_BLOCK[] = "ÁªÂòÈϰϤλØÄê";
3940 static char MN_KILL_LINE[] = "¹Ô¤Î»Ä¤ê¤òºï½ü";
3941 static char MN_DELETE_CHAR[] = "1ʸ»úºï½ü";
3942 static char MN_BACKSPACE[] = "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹";
3943 static char MN_RETURN[] = "²þ¹Ô";
3945 static char MN_SEARCH[] = "¸¡º÷";
3946 static char MN_SEARCH_STR[] = "ʸ»úÎó¤Ç¸¡º÷";
3947 static char MN_SEARCH_FORW[] = "Á°Êý¤ØºÆ¸¡º÷";
3948 static char MN_SEARCH_BACK[] = "¸åÊý¤ØºÆ¸¡º÷";
3949 static char MN_SEARCH_OBJ[] = "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷";
3950 static char MN_SEARCH_DESTROYED[] = "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷";
3952 static char MN_INSERT[] = "¿§¡¹ÁÞÆþ";
3953 static char MN_INSERT_OBJECT[] = "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ";
3954 static char MN_INSERT_DESTROYED[] = "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ";
3955 static char MN_INSERT_BLOCK[] = "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ";
3956 static char MN_INSERT_MACRO[] = "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ";
3957 static char MN_INSERT_KEYMAP[] = "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ";
3959 static char MN_COMMAND_LETTER[] = "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò";
3960 static char MN_CL_AUTOPICK[] = "¡Ö ¡× (¼«Æ°½¦¤¤)";
3961 static char MN_CL_DESTROY[] = "¡Ö!¡× (¼«Æ°Ç˲õ)";
3962 static char MN_CL_LEAVE[] = "¡Ö~¡× (ÊüÃÖ)";
3963 static char MN_CL_QUERY[] = "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)";
3964 static char MN_CL_NO_DISP[] = "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)";
3966 static char MN_ADJECTIVE_GEN[] = "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò";
3967 static char MN_RARE[] = "¥ì¥¢¤Ê (ÁõÈ÷)";
3968 static char MN_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿ (ÁõÈ÷)";
3970 static char MN_ADJECTIVE_SPECIAL[] = "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò";
3971 static char MN_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)";
3972 static char MN_MORE_DICE[] = "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)";
3973 static char MN_MORE_BONUS[] = "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)";
3974 static char MN_WANTED[] = "¾Þ¶â¼ó¤Î (»àÂÎ)";
3975 static char MN_UNIQUE[] = "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)";
3976 static char MN_HUMAN[] = "¿Í´Ö¤Î (»àÂÎ)";
3977 static char MN_UNREADABLE[] = "Æɤá¤Ê¤¤ (ËâË¡½ñ)";
3978 static char MN_REALM1[] = "Âè°ìÎΰè¤Î (ËâË¡½ñ)";
3979 static char MN_REALM2[] = "ÂèÆóÎΰè¤Î (ËâË¡½ñ)";
3980 static char MN_FIRST[] = "1ºýÌܤΠ(ËâË¡½ñ)";
3981 static char MN_SECOND[] = "2ºýÌܤΠ(ËâË¡½ñ)";
3982 static char MN_THIRD[] = "3ºýÌܤΠ(ËâË¡½ñ)";
3983 static char MN_FOURTH[] = "4ºýÌܤΠ(ËâË¡½ñ)";
3985 static char MN_NOUN[] = "̾»ì¤ÎÁªÂò";
3989 static char MN_QUIT[] = "Quit without save";
3990 static char MN_SAVEQUIT[] = "Save & Quit";
3991 static char MN_REVERT[] = "Revert all changes";
3992 static char MN_HELP[] = "Help";
3994 static char MN_MOVE[] = "Move cursor";
3995 static char MN_LEFT[] = "Left (Left Arrow key)";
3996 static char MN_DOWN[] = "Down (Down Arrow key)";
3997 static char MN_UP[] = "Up (Up Arrow key)";
3998 static char MN_RIGHT[] = "Right (Right Arrow key)";
3999 static char MN_BOL[] = "Beggining of line";
4000 static char MN_EOL[] = "End of line";
4001 static char MN_PGUP[] = "Page up (PageUp key)";
4002 static char MN_PGDOWN[] = "Page down(PageDown key)";
4003 static char MN_TOP[] = "Top (Home key)";
4004 static char MN_BOTTOM[] = "Bottom (End key)";
4006 static char MN_EDIT[] = "Edit";
4007 static char MN_CUT[] = "Cut";
4008 static char MN_COPY[] = "Copy";
4009 static char MN_PASTE[] = "Paste";
4010 static char MN_BLOCK[] = "Select block";
4011 static char MN_KILL_LINE[] = "Kill rest of line";
4012 static char MN_DELETE_CHAR[] = "Delete character";
4013 static char MN_BACKSPACE[] = "Backspace";
4014 static char MN_RETURN[] = "Return";
4016 static char MN_SEARCH[] = "Search";
4017 static char MN_SEARCH_STR[] = "Search by string";
4018 static char MN_SEARCH_FORW[] = "Search forward";
4019 static char MN_SEARCH_BACK[] = "Search backward";
4020 static char MN_SEARCH_OBJ[] = "Search by inventory object";
4021 static char MN_SEARCH_DESTROYED[] = "Search by destroyed object";
4023 static char MN_INSERT[] = "Insert...";
4024 static char MN_INSERT_OBJECT[] = "Insert name of choosen object";
4025 static char MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
4026 static char MN_INSERT_BLOCK[] = "Insert conditional block";
4027 static char MN_INSERT_MACRO[] = "Insert a macro definition";
4028 static char MN_INSERT_KEYMAP[] = "Insert a keymap definition";
4030 static char MN_COMMAND_LETTER[] = "Command letter";
4031 static char MN_CL_AUTOPICK[] = "' ' (Auto pick)";
4032 static char MN_CL_DESTROY[] = "'!' (Auto destroy)";
4033 static char MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
4034 static char MN_CL_QUERY[] = "';' (Query to pick up)";
4035 static char MN_CL_NO_DISP[] = "'(' (No display on the large map)";
4037 static char MN_ADJECTIVE_GEN[] = "Adjective (general)";
4038 static char MN_RARE[] = "rare (equipments)";
4039 static char MN_COMMON[] = "common (equipments)";
4041 static char MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
4042 static char MN_BOOSTED[] = "dice boosted (weapons)";
4043 static char MN_MORE_DICE[] = "more than # dice (weapons)";
4044 static char MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
4045 static char MN_WANTED[] = "wanted (corpse)";
4046 static char MN_UNIQUE[] = "unique (corpse)";
4047 static char MN_HUMAN[] = "human (corpse)";
4048 static char MN_UNREADABLE[] = "unreadable (spellbooks)";
4049 static char MN_REALM1[] = "realm1 (spellbooks)";
4050 static char MN_REALM2[] = "realm2 (spellbooks)";
4051 static char MN_FIRST[] = "first (spellbooks)";
4052 static char MN_SECOND[] = "second (spellbooks)";
4053 static char MN_THIRD[] = "third (spellbooks)";
4054 static char MN_FOURTH[] = "fourth (spellbooks)";
4056 static char MN_NOUN[] = "Keywords (noun)";
4066 } command_menu_type;
4069 command_menu_type menu_data[] =
4071 {MN_HELP, 0, -1, EC_HELP},
4072 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4073 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4074 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4076 {MN_EDIT, 0, -1, -1},
4077 {MN_CUT, 1, KTRL('x'), EC_CUT},
4078 {MN_COPY, 1, KTRL('c'), EC_COPY},
4079 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4080 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4081 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4082 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4083 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4084 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4085 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4087 {MN_SEARCH, 0, -1, -1},
4088 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4089 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4090 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4091 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4092 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4094 {MN_MOVE, 0, -1, -1},
4095 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4096 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4097 {MN_UP, 1, KTRL('p'), EC_UP},
4098 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4099 {MN_BOL, 1, KTRL('a'), EC_BOL},
4100 {MN_EOL, 1, KTRL('e'), EC_EOL},
4101 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4102 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4103 {MN_TOP, 1, KTRL('t'), EC_TOP},
4104 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4106 {MN_INSERT, 0, -1, -1},
4107 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4108 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4109 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4110 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4111 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4113 {MN_ADJECTIVE_GEN, 0, -1, -1},
4114 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4115 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4116 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4117 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4118 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4119 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4120 {KEY_EGO, 1, -1, EC_OK_EGO},
4121 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4122 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4123 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4124 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4125 {MN_RARE, 1, -1, EC_OK_RARE},
4126 {MN_COMMON, 1, -1, EC_OK_COMMON},
4128 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4129 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4130 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4131 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4132 {MN_WANTED, 1, -1, EC_OK_WANTED},
4133 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4134 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4135 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4136 {MN_REALM1, 1, -1, EC_OK_REALM1},
4137 {MN_REALM2, 1, -1, EC_OK_REALM2},
4138 {MN_FIRST, 1, -1, EC_OK_FIRST},
4139 {MN_SECOND, 1, -1, EC_OK_SECOND},
4140 {MN_THIRD, 1, -1, EC_OK_THIRD},
4141 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4143 {MN_NOUN, 0, -1, -1},
4144 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4145 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4146 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4147 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4148 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4149 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4150 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4151 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4152 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4153 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4154 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4155 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4156 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4157 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4158 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4159 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4160 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4161 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4163 {MN_COMMAND_LETTER, 0, -1, -1},
4164 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4165 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4166 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4167 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4168 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4170 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4177 * Find a command by 'key'.
4179 static int get_com_id(char key)
4183 for (i = 0; menu_data[i].name; i++)
4185 if (menu_data[i].key == key)
4187 return menu_data[i].com_id;
4196 * Display the menu, and get a command
4198 static int do_command_menu(int level, int start)
4203 int col0 = 5 + level*7;
4204 int row0 = 1 + level*3;
4206 int menu_id_list[26];
4208 char linestr[MAX_LINELEN];
4210 /* Get max length */
4212 for (i = start; menu_data[i].level >= level; i++)
4216 /* Ignore lower level sub menus */
4217 if (menu_data[i].level > level) continue;
4219 len = strlen(menu_data[i].name);
4220 if (len > max_len) max_len = len;
4222 menu_id_list[menu_key] = i;
4226 while (menu_key < 26)
4228 menu_id_list[menu_key] = -1;
4232 /* Extra space for displaying menu key and command key */
4233 max_menu_wid = max_len + 3 + 3;
4235 /* Prepare box line */
4237 strcat(linestr, "+");
4238 for (i = 0; i < max_menu_wid + 2; i++)
4240 strcat(linestr, "-");
4242 strcat(linestr, "+");
4252 int row1 = row0 + 1;
4255 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4257 /* Draw menu items */
4259 for (i = start; menu_data[i].level >= level; i++)
4261 char com_key_str[3];
4264 /* Ignore lower level sub menus */
4265 if (menu_data[i].level > level) continue;
4267 if (menu_data[i].com_id == -1)
4270 strcpy(com_key_str, "¢§");
4272 strcpy(com_key_str, ">");
4275 else if (menu_data[i].key != -1)
4277 com_key_str[0] = '^';
4278 com_key_str[1] = menu_data[i].key + '@';
4279 com_key_str[2] = '\0';
4283 com_key_str[0] = '\0';
4286 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4288 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4293 /* Draw bottom line */
4294 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4296 /* The menu was shown */
4300 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
4302 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
4306 if (key == ESCAPE) return 0;
4308 if ('a' <= key && key <= 'z')
4310 menu_id = menu_id_list[key - 'a'];
4314 com_id = menu_data[menu_id].com_id;
4318 com_id = do_command_menu(level + 1, menu_id + 1);
4320 if (com_id) return com_id;
4332 com_id = get_com_id(key);
4333 if (com_id) return com_id;
4340 static chain_str_type *new_chain_str(cptr str)
4342 chain_str_type *chain;
4344 size_t len = strlen(str);
4346 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4348 strcpy(chain->s, str);
4355 static void kill_yank_chain(text_body_type *tb)
4357 chain_str_type *chain = tb->yank;
4359 tb->yank_eol = TRUE;
4363 chain_str_type *next = chain->next;
4364 size_t len = strlen(chain->s);
4366 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4373 static void add_str_to_yank(text_body_type *tb, cptr str)
4375 chain_str_type *chain;
4377 tb->yank_eol = FALSE;
4379 if (NULL == tb->yank)
4381 tb->yank = new_chain_str(str);
4391 chain->next = new_chain_str(str);
4396 chain = chain->next;
4401 #define DESCRIPT_HGT 3
4406 static void draw_text_editor(text_body_type *tb)
4409 int by1 = 0, by2 = 0;
4412 Term_get_size(&tb->wid, &tb->hgt);
4415 * Top line (-1), description line (-3), separator (-1)
4418 tb->hgt -= 2 + DESCRIPT_HGT;
4421 /* Don't let cursor at second byte of kanji */
4422 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4423 if (iskanji(tb->lines_list[tb->cy][i]))
4434 /* Scroll if necessary */
4435 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4436 tb->upper = tb->cy - (tb->hgt)/2;
4439 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4440 tb->left = tb->cx - (tb->wid)*2/3;
4444 /* Redraw whole window after resize */
4445 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4446 tb->dirty_flags |= DIRTY_SCREEN;
4448 /* Redraw all text after scroll */
4449 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4450 tb->dirty_flags |= DIRTY_ALL;
4453 if (tb->dirty_flags & DIRTY_SCREEN)
4455 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4461 /* Redraw mode line */
4462 if (tb->dirty_flags & DIRTY_MODE)
4464 char buf[MAX_LINELEN];
4466 int sepa_length = tb->wid;
4469 for (i = 0; i < sepa_length; i++)
4473 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4476 if (tb->dirty_flags & DIRTY_EXPRESSION)
4481 for (y = 0; tb->lines_list[y]; y++)
4485 cptr s = tb->lines_list[y];
4487 /* Update this line's state */
4488 tb->states[y] = state;
4490 if (*s++ != '?') continue;
4491 if (*s++ != ':') continue;
4493 /* Lines below this line are auto-registered */
4494 if (streq(s, "$AUTOREGISTER"))
4495 state |= LSTAT_AUTOREGISTER;
4497 /* Parse the expr */
4498 v = process_pref_file_expr(&s, &f);
4501 if (streq(v, "0")) state |= LSTAT_BYPASS;
4502 else state &= ~LSTAT_BYPASS;
4504 /* Re-update this line's state */
4505 tb->states[y] = state | LSTAT_EXPRESSION;
4508 tb->dirty_flags |= DIRTY_ALL;
4513 int tmp_cx = tb->cx;
4514 int len = strlen(tb->lines_list[tb->cy]);
4516 /* Correct cursor location */
4517 if (tb->cx > len) tmp_cx = len;
4519 tb->dirty_flags |= DIRTY_ALL;
4521 by1 = MIN(tb->my, tb->cy);
4522 by2 = MAX(tb->my, tb->cy);
4525 /* Dump up to tb->hgt lines of messages */
4526 for (i = 0; i < tb->hgt; i++)
4532 int y = tb->upper+i;
4534 /* clean or dirty? */
4535 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4538 msg = tb->lines_list[y];
4541 /* Apply horizontal scroll */
4542 for (j = 0; *msg; msg++, j++)
4544 if (j == tb->left) break;
4560 Term_erase(0, i + 1, tb->wid);
4562 if (tb->states[y] & LSTAT_AUTOREGISTER)
4564 /* Warning color -- These lines will be deleted later */
4569 /* Bypassed line will be displayed by darker color */
4570 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4571 else color = TERM_WHITE;
4574 /* No mark or Out of mark */
4575 if (!tb->mark || (y < by1 || by2 < y))
4577 /* Dump the messages, bottom to top */
4578 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4581 /* Multiple lines selected */
4582 else if (by1 != by2)
4584 /* Dump the messages, bottom to top */
4585 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4588 /* Single line selected */
4591 int x0 = leftcol + tb->left;
4592 int len = strlen(tb->lines_list[tb->cy]);
4593 int bx1 = MIN(tb->mx, tb->cx);
4594 int bx2 = MAX(tb->mx, tb->cx);
4596 /* Correct cursor location */
4597 if (bx2 > len) bx2 = len;
4599 Term_gotoxy(leftcol, i + 1);
4600 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4601 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4602 Term_addstr(-1, color, msg + (bx2 - x0));
4606 for (; i < tb->hgt; i++)
4609 Term_erase(0, i + 1, tb->wid);
4612 /* Display information when updated */
4613 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4615 autopick_type an_entry, *entry = &an_entry;
4616 cptr str1 = NULL, str2 = NULL;
4619 /* Clear information line */
4620 for (i = 0; i < DESCRIPT_HGT; i++)
4623 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4626 /* Display information */
4627 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4630 str1 = format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str);
4632 str1 = format("Pattern not found: %s", tb->search_str);
4635 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4638 str1 = format("̵¸ú¾õÂ֤ιԤò¥¹¥¥Ã¥×¤·¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4640 str1 = format("Some inactive lines are skipped. (Searching %s)", tb->search_str);
4643 else if (tb->dirty_flags & DIRTY_INACTIVE)
4646 str1 = format("̵¸ú¾õÂ֤ιԤÀ¤±¤¬¸«ÉÕ¤«¤ê¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4648 str1 = format("Found only an inactive line. (Searching %s)", tb->search_str);
4651 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4654 str1 = "¸¡º÷¤¹¤ë¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó(^S ¤Ç¸¡º÷)¡£";
4656 str1 = "No pattern to search. (Press ^S to search.)";
4659 else if (tb->lines_list[tb->cy][0] == '#')
4662 str1 = "¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£";
4664 str1 = "This line is a comment.";
4667 else if (tb->lines_list[tb->cy][1] == ':')
4669 switch(tb->lines_list[tb->cy][0])
4673 str1 = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4675 str1 = "This line is a Conditional Expression.";
4681 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4683 str1 = "This line defines a Macro action.";
4688 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4690 str1 = "This line defines a Macro trigger key.";
4695 str1 = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4697 str1 = "This line defines a Keymap.";
4702 switch(tb->lines_list[tb->cy][0])
4705 if (tb->states[tb->cy] & LSTAT_BYPASS)
4708 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4710 str2 = "The expression is 'False'(=0) currently.";
4716 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4718 str2 = "The expression is 'True'(=1) currently.";
4724 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4727 str2 = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4729 str2 = "This line will be delete later.";
4733 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4736 str2 = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4738 str2 = "This line is bypassed currently.";
4745 /* Get description of an autopicker preference line */
4746 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4748 char buf[MAX_LINELEN];
4749 char temp[MAX_LINELEN];
4752 describe_autopick(buf, entry);
4754 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4757 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4759 strcat(buf, " This line will be delete later.");
4763 if (tb->states[tb->cy] & LSTAT_BYPASS)
4766 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4768 strcat(buf, " This line is bypassed currently.");
4772 roff_to_buf(buf, 81, temp, sizeof(temp));
4774 for (i = 0; i < 3; i++)
4780 prt(t, tb->hgt +1 + 1 + i, 0);
4784 autopick_free_entry(entry);
4787 /* Draw the first line */
4788 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4790 /* Draw the second line */
4791 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4797 * Kill segment of a line
4799 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4801 char buf[MAX_LINELEN];
4802 cptr s = tb->lines_list[y];
4806 /* Kill whole line? */
4807 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4811 string_free(tb->lines_list[y]);
4813 /* Shift lines up */
4814 for (i = y; tb->lines_list[i+1]; i++)
4815 tb->lines_list[i] = tb->lines_list[i+1];
4816 tb->lines_list[i] = NULL;
4818 /* Expressions need re-evaluation */
4819 tb->dirty_flags |= DIRTY_EXPRESSION;
4825 if (x0 == x1) return;
4827 /* Before the segment */
4828 for (x = 0; x < x0; x++)
4831 /* After the segment */
4832 for (x = x1; s[x]; x++)
4838 string_free(tb->lines_list[y]);
4839 tb->lines_list[y] = string_make(buf);
4841 /* Expressions may need re-evaluation */
4842 check_expression_line(tb, y);
4844 /* Text is changed */
4850 * Get a trigger key and insert ASCII string for the trigger
4852 static bool insert_macro_line(text_body_type *tb)
4861 /* Do not process macros */
4867 /* Read the pattern */
4873 /* Do not process macros */
4876 /* Do not wait for keys */
4879 /* Attempt to read a key */
4889 /* Convert the trigger */
4890 ascii_to_text(tmp, buf);
4893 if(!tmp[0]) return FALSE;
4897 /* Insert preference string */
4898 insert_return_code(tb);
4899 string_free(tb->lines_list[tb->cy]);
4900 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4902 /* Acquire action */
4903 i = macro_find_exact(buf);
4907 /* Nothing defined */
4912 /* Analyze the current action */
4913 ascii_to_text(tmp, macro__act[i]);
4916 /* Insert blank action preference line */
4917 insert_return_code(tb);
4918 string_free(tb->lines_list[tb->cy]);
4919 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4926 * Get a command key and insert ASCII string for the key
4928 static bool insert_keymap_line(text_body_type *tb)
4936 if (rogue_like_commands)
4938 mode = KEYMAP_MODE_ROGUE;
4944 mode = KEYMAP_MODE_ORIG;
4957 /* Convert the trigger */
4958 ascii_to_text(tmp, buf);
4961 if(!tmp[0]) return FALSE;
4965 /* Insert preference string */
4966 insert_return_code(tb);
4967 string_free(tb->lines_list[tb->cy]);
4968 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4970 /* Look up the keymap */
4971 act = keymap_act[mode][(byte)(buf[0])];
4973 /* Insert blank action preference line */
4974 insert_return_code(tb);
4975 string_free(tb->lines_list[tb->cy]);
4976 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4983 * Execute a single editor command
4985 static bool do_editor_command(text_body_type *tb, int com_id)
4993 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4995 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
4998 return QUIT_WITHOUT_SAVE;
5001 return QUIT_AND_SAVE;
5004 /* Revert to original */
5006 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
5008 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
5011 free_text_lines(tb->lines_list);
5012 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5013 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5014 tb->cx = tb->cy = 0;
5017 /* Text is not changed */
5018 tb->changed = FALSE;
5022 /* Peruse the main help file */
5024 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
5026 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
5029 tb->dirty_flags |= DIRTY_SCREEN;
5034 /* Split a line or insert end of line */
5036 /* Ignore selection */
5042 tb->dirty_flags |= DIRTY_ALL;
5045 insert_return_code(tb);
5050 tb->dirty_flags |= DIRTY_ALL;
5060 len = strlen(tb->lines_list[tb->cy]);
5061 if (len < tb->cx) tb->cx = len;
5063 else if (tb->cy > 0)
5066 tb->cx = strlen(tb->lines_list[tb->cy]);
5072 if (tb->lines_list[tb->cy + 1]) tb->cy++;
5077 if (tb->cy > 0) tb->cy--;
5086 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5089 len = strlen(tb->lines_list[tb->cy]);
5092 if (tb->lines_list[tb->cy + 1])
5104 /* Beginning of line */
5110 tb->cx = strlen(tb->lines_list[tb->cy]);
5114 while (0 < tb->cy && tb->upper <= tb->cy)
5116 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5122 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
5132 while (tb->lines_list[tb->cy + 1])
5138 /* Copy the text first */
5139 do_editor_command(tb, EC_COPY);
5141 /* Single line case */
5142 if (tb->my == tb->cy)
5144 int bx1 = MIN(tb->mx, tb->cx);
5145 int bx2 = MAX(tb->mx, tb->cx);
5146 int len = strlen(tb->lines_list[tb->cy]);
5148 /* Correct fake cursor position */
5149 if (bx2 > len) bx2 = len;
5151 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5153 /* New cursor position */
5157 /* Multiple lines case */
5158 else /* if (tb->my != tb->cy) */
5162 int by1 = MIN(tb->my, tb->cy);
5163 int by2 = MAX(tb->my, tb->cy);
5165 /* Kill lines in reverse order */
5166 for (y = by2; y >= by1; y--)
5168 int len = strlen(tb->lines_list[y]);
5170 kill_line_segment(tb, y, 0, len, TRUE);
5173 /* New cursor position */
5179 /* Disable selection */
5183 tb->dirty_flags |= DIRTY_ALL;
5185 /* Text is changed */
5193 int len = strlen(tb->lines_list[tb->cy]);
5195 /* Correct cursor location */
5196 if (tb->cx > len) tb->cx = len;
5198 /* Use single line? */
5201 /* Select a single line */
5207 /* Kill old yank buffer */
5208 kill_yank_chain(tb);
5211 /* Single line case */
5212 if (tb->my == tb->cy)
5215 char buf[MAX_LINELEN];
5216 int bx1 = MIN(tb->mx, tb->cx);
5217 int bx2 = MAX(tb->mx, tb->cx);
5219 /* Correct fake cursor position */
5220 if (bx2 > len) bx2 = len;
5222 /* Whole part of this line is selected */
5223 if (bx1 == 0 && bx2 == len)
5225 /* Copy this line */
5226 add_str_to_yank(tb, tb->lines_list[tb->cy]);
5228 /* Add end of line to the buffer */
5229 add_str_to_yank(tb, "");
5232 /* Segment of this line is selected */
5235 for (i = 0; i < bx2 - bx1; i++)
5237 buf[i] = tb->lines_list[tb->cy][bx1 + i];
5241 /* Copy this segment of line */
5242 add_str_to_yank(tb, buf);
5246 /* Multiple lines case */
5247 else /* if (tb->my != tb->cy) */
5251 int by1 = MIN(tb->my, tb->cy);
5252 int by2 = MAX(tb->my, tb->cy);
5255 for (y = by1; y <= by2; y++)
5257 /* Copy this line */
5258 add_str_to_yank(tb, tb->lines_list[y]);
5261 /* Add final end of line to the buffer */
5262 add_str_to_yank(tb, "");
5265 /* Disable selection */
5269 tb->dirty_flags |= DIRTY_ALL;
5275 /* Paste killed text */
5277 chain_str_type *chain = tb->yank;
5278 int len = strlen(tb->lines_list[tb->cy]);
5280 /* Nothing to do? */
5283 /* Correct cursor location */
5284 if (tb->cx > len) tb->cx = len;
5286 /* Ignore selection */
5292 tb->dirty_flags |= DIRTY_ALL;
5298 cptr yank_str = chain->s;
5300 char buf[MAX_LINELEN];
5302 char rest[MAX_LINELEN], *rest_ptr = rest;
5304 /* Save preceding string */
5305 for(i = 0; i < tb->cx; i++)
5306 buf[i] = tb->lines_list[tb->cy][i];
5308 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5310 /* Paste yank buffer */
5311 while (*yank_str && i < MAX_LINELEN-1)
5313 buf[i++] = *yank_str++;
5319 chain = chain->next;
5321 if (chain || tb->yank_eol)
5323 /* There is an end of line between chain nodes */
5325 insert_return_code(tb);
5327 /* Replace this line with new one */
5328 string_free(tb->lines_list[tb->cy]);
5329 tb->lines_list[tb->cy] = string_make(buf);
5331 /* Move to next line */
5338 /* Final line doesn't have end of line */
5340 tb->cx = strlen(buf);
5342 /* Rest of original line */
5343 while (*rest_ptr && i < MAX_LINELEN-1)
5345 buf[i++] = *rest_ptr++;
5351 /* Replace this line with new one */
5352 string_free(tb->lines_list[tb->cy]);
5353 tb->lines_list[tb->cy] = string_make(buf);
5360 tb->dirty_flags |= DIRTY_ALL;
5362 /* Expressions need re-evaluation */
5363 tb->dirty_flags |= DIRTY_EXPRESSION;
5365 /* Text is changed */
5374 /* Disable the selection */
5378 tb->dirty_flags |= DIRTY_ALL;
5382 tb->mark = MARK_MARK;
5384 /* Repeating this command swaps cursor position */
5385 if (com_id == tb->old_com_id)
5397 tb->dirty_flags |= DIRTY_ALL;
5401 int len = strlen(tb->lines_list[tb->cy]);
5403 /* Mark the point 1 */
5407 /* Correct cursor location */
5408 if (tb->cx > len) tb->mx = len;
5415 /* Kill rest of line */
5417 int len = strlen(tb->lines_list[tb->cy]);
5419 /* Correct cursor location */
5420 if (tb->cx > len) tb->cx = len;
5422 /* Ignore selection */
5428 tb->dirty_flags |= DIRTY_ALL;
5431 /* Append only if this command is repeated. */
5432 if (tb->old_com_id != com_id)
5434 kill_yank_chain(tb);
5438 /* Really deleted some text */
5441 /* Add deleted string to yank buffer */
5442 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5444 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5447 tb->dirty_line = tb->cy;
5449 /* Leave end of line character */
5453 /* Cut the end of line character only */
5454 if (tb->yank_eol) add_str_to_yank(tb, "");
5456 /* Cut end of line */
5457 tb->yank_eol = TRUE;
5459 do_editor_command(tb, EC_DELETE_CHAR);
5463 case EC_DELETE_CHAR:
5465 /* DELETE == go forward + BACK SPACE */
5469 /* Ignore selection */
5475 tb->dirty_flags |= DIRTY_ALL;
5479 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5483 /* Pass through the end of line to next line */
5484 len = strlen(tb->lines_list[tb->cy]);
5487 if (tb->lines_list[tb->cy + 1])
5499 do_editor_command(tb, EC_BACKSPACE);
5508 char buf[MAX_LINELEN];
5510 /* Ignore selection */
5516 tb->dirty_flags |= DIRTY_ALL;
5519 /* Move to correct collumn */
5520 len = strlen(tb->lines_list[tb->cy]);
5521 if (len < tb->cx) tb->cx = len;
5525 /* delete a return code and union two lines */
5526 if (tb->cy == 0) break;
5527 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5528 strcpy(buf, tb->lines_list[tb->cy-1]);
5529 strcat(buf, tb->lines_list[tb->cy]);
5530 string_free(tb->lines_list[tb->cy-1]);
5531 string_free(tb->lines_list[tb->cy]);
5532 tb->lines_list[tb->cy-1] = string_make(buf);
5534 for (i = tb->cy; tb->lines_list[i+1]; i++)
5535 tb->lines_list[i] = tb->lines_list[i+1];
5537 tb->lines_list[i] = NULL;
5541 tb->dirty_flags |= DIRTY_ALL;
5543 /* Expressions need re-evaluation */
5544 tb->dirty_flags |= DIRTY_EXPRESSION;
5546 /* Text is changed */
5552 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5556 if (iskanji(tb->lines_list[tb->cy][i]))
5557 buf[j++] = tb->lines_list[tb->cy][i++];
5559 buf[j++] = tb->lines_list[tb->cy][i];
5566 for (; tb->lines_list[tb->cy][i]; i++)
5567 buf[j++] = tb->lines_list[tb->cy][i];
5569 string_free(tb->lines_list[tb->cy]);
5570 tb->lines_list[tb->cy] = string_make(buf);
5573 tb->dirty_line = tb->cy;
5575 /* Expressions may need re-evaluation */
5576 check_expression_line(tb, tb->cy);
5578 /* Text is changed */
5588 /* Become dirty because of item/equip menu */
5589 tb->dirty_flags |= DIRTY_SCREEN;
5591 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5593 if (!search_dir) break;
5595 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5596 else do_editor_command(tb, EC_SEARCH_BACK);
5600 case EC_SEARCH_FORW:
5601 if (tb->search_o_ptr)
5603 search_for_object(tb, tb->search_o_ptr, TRUE);
5605 else if (tb->search_str && tb->search_str[0])
5607 search_for_string(tb, tb->search_str, TRUE);
5611 tb->dirty_flags |= DIRTY_NO_SEARCH;
5615 case EC_SEARCH_BACK:
5616 if (tb->search_o_ptr)
5618 search_for_object(tb, tb->search_o_ptr, FALSE);
5620 else if (tb->search_str && tb->search_str[0])
5622 search_for_string(tb, tb->search_str, FALSE);
5626 tb->dirty_flags |= DIRTY_NO_SEARCH;
5631 /* Become dirty because of item/equip menu */
5632 tb->dirty_flags |= DIRTY_SCREEN;
5634 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5636 do_editor_command(tb, EC_SEARCH_FORW);
5639 case EC_SEARCH_DESTROYED:
5640 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5642 /* There is no object to search */
5643 tb->dirty_flags |= DIRTY_NO_SEARCH;
5648 do_editor_command(tb, EC_SEARCH_FORW);
5651 case EC_INSERT_OBJECT:
5653 /* Insert choosen item name */
5655 autopick_type an_entry, *entry = &an_entry;
5657 if (!entry_from_choosed_object(entry))
5659 /* Now dirty because of item/equip menu */
5660 tb->dirty_flags |= DIRTY_SCREEN;
5665 insert_return_code(tb);
5666 string_free(tb->lines_list[tb->cy]);
5667 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5669 /* Now dirty because of item/equip menu */
5670 tb->dirty_flags |= DIRTY_SCREEN;
5675 case EC_INSERT_DESTROYED:
5676 /* Insert a name of last destroyed item */
5677 if (tb->last_destroyed)
5680 insert_return_code(tb);
5681 string_free(tb->lines_list[tb->cy]);
5682 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5685 tb->dirty_flags |= DIRTY_ALL;
5687 /* Text is changed */
5692 case EC_INSERT_BLOCK:
5694 /* Insert a conditinal expression line */
5695 char expression[80];
5697 /* Conditional Expression for Class and Race */
5698 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5700 rp_ptr->E_title, cp_ptr->E_title,
5702 rp_ptr->title, cp_ptr->title,
5708 insert_return_code(tb);
5709 string_free(tb->lines_list[tb->cy]);
5710 tb->lines_list[tb->cy] = string_make(expression);
5712 insert_return_code(tb);
5713 string_free(tb->lines_list[tb->cy]);
5714 tb->lines_list[tb->cy] = string_make("?:1");
5717 tb->dirty_flags |= DIRTY_ALL;
5719 /* Text is changed */
5725 case EC_INSERT_MACRO:
5726 /* Draw_everythig (delete menu) */
5727 draw_text_editor(tb);
5730 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5734 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5736 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5738 if (insert_macro_line(tb))
5740 /* Prepare to input action */
5744 tb->dirty_flags |= DIRTY_ALL;
5746 /* Text is changed */
5752 case EC_INSERT_KEYMAP:
5753 /* Draw_everythig (delete menu) */
5754 draw_text_editor(tb);
5757 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5761 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, format("C:%d:<¥³¥Þ¥ó¥É¥¡¼>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5763 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, format("C:%d:<Keypress>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5766 if (insert_keymap_line(tb))
5768 /* Prepare to input action */
5772 tb->dirty_flags |= DIRTY_ALL;
5774 /* Text is changed */
5779 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5780 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5781 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5782 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5783 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5785 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5786 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5787 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5788 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5789 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5790 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5791 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5792 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5793 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5794 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5795 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5796 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5797 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5798 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5799 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5800 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5801 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5802 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5803 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5804 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5805 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5806 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5807 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5808 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5809 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5810 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5811 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5812 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5813 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5814 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5815 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5816 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5817 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5818 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5819 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5820 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5821 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5822 case EC_OK_UNREADABLE:
5823 toggle_keyword(tb, FLG_UNREADABLE);
5824 add_keyword(tb, FLG_SPELLBOOKS);
5827 toggle_keyword(tb, FLG_REALM1);
5828 add_keyword(tb, FLG_SPELLBOOKS);
5831 toggle_keyword(tb, FLG_REALM2);
5832 add_keyword(tb, FLG_SPELLBOOKS);
5835 toggle_keyword(tb, FLG_FIRST);
5836 add_keyword(tb, FLG_SPELLBOOKS);
5839 toggle_keyword(tb, FLG_SECOND);
5840 add_keyword(tb, FLG_SPELLBOOKS);
5843 toggle_keyword(tb, FLG_THIRD);
5844 add_keyword(tb, FLG_SPELLBOOKS);
5847 toggle_keyword(tb, FLG_FOURTH);
5848 add_keyword(tb, FLG_SPELLBOOKS);
5852 /* Save old command */
5853 tb->old_com_id = com_id;
5860 * Insert single letter at cursor position.
5862 static void insert_single_letter(text_body_type *tb, int key)
5865 char buf[MAX_LINELEN];
5867 /* Save preceding string */
5868 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5869 buf[j++] = tb->lines_list[tb->cy][i];
5871 /* Add a character */
5879 if (j+2 < MAX_LINELEN)
5891 if (j+1 < MAX_LINELEN)
5897 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5898 buf[j++] = tb->lines_list[tb->cy][i];
5901 /* Replace current line with new line */
5902 string_free(tb->lines_list[tb->cy]);
5903 tb->lines_list[tb->cy] = string_make(buf);
5905 /* Move to correct collumn */
5906 len = strlen(tb->lines_list[tb->cy]);
5907 if (len < tb->cx) tb->cx = len;
5910 tb->dirty_line = tb->cy;
5912 /* Expressions may need re-evaluation */
5913 check_expression_line(tb, tb->cy);
5915 /* Text is changed */
5921 * Check special key code and get a movement command id
5923 static int analyze_move_key(text_body_type *tb, int skey)
5927 /* Not a special key */
5928 if (!(skey & SKEY_MASK)) return 0;
5930 /* Convert from a special key code to an editor command */
5931 switch(skey & ~SKEY_MOD_MASK)
5933 case SKEY_DOWN: com_id = EC_DOWN; break;
5934 case SKEY_LEFT: com_id = EC_LEFT; break;
5935 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5936 case SKEY_UP: com_id = EC_UP; break;
5937 case SKEY_PGUP: com_id = EC_PGUP; break;
5938 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5939 case SKEY_TOP: com_id = EC_TOP; break;
5940 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5943 /* Not a special movement key */
5947 /* Without shift modifier */
5948 if (!(skey & SKEY_MOD_SHIFT))
5951 * Un-shifted cursor keys cancells
5952 * selection created by shift+cursor.
5954 if (tb->mark & MARK_BY_SHIFT)
5959 tb->dirty_flags |= DIRTY_ALL;
5963 /* With shift modifier */
5966 /* Start selection by shift + cursor keys */
5969 int len = strlen(tb->lines_list[tb->cy]);
5971 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5975 /* Correct cursor location */
5976 if (tb->cx > len) tb->mx = len;
5978 /* Need to redraw text */
5979 if (com_id == EC_UP || com_id == EC_DOWN)
5981 /* Redraw all text */
5982 tb->dirty_flags |= DIRTY_ALL;
5986 tb->dirty_line = tb->cy;
5995 * In-game editor of Object Auto-picker/Destoryer
5997 void do_cmd_edit_autopick(void)
5999 static int cx_save = 0;
6000 static int cy_save = 0;
6002 text_body_type text_body, *tb = &text_body;
6004 autopick_type an_entry, *entry = &an_entry;
6005 char buf[MAX_LINELEN];
6010 static s32b old_autosave_turn = 0L;
6013 tb->changed = FALSE;
6016 tb->upper = tb->left = 0;
6018 tb->mx = tb->my = 0;
6019 tb->old_cy = tb->old_upper = tb->old_left = -1;
6020 tb->old_wid = tb->old_hgt = -1;
6024 tb->search_o_ptr = NULL;
6025 tb->search_str = NULL;
6026 tb->last_destroyed = NULL;
6027 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6028 tb->dirty_line = -1;
6029 tb->filename_mode = PT_DEFAULT;
6032 if (turn > old_autosave_turn + 100L)
6034 do_cmd_save_game(TRUE);
6035 old_autosave_turn = turn;
6038 /* HACK -- Reset start_time to stop counting playtime while edit */
6041 /* Free old entries */
6044 /* Command Description of the 'Last Destroyed Item' */
6045 if (autopick_last_destroyed_object.k_idx)
6047 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6048 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6051 /* Read or initialize whole text */
6052 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6054 /* Reset cursor position if needed */
6055 for (i = 0; i < tb->cy; i++)
6057 if (!tb->lines_list[i])
6059 tb->cy = tb->cx = 0;
6064 /* Save the screen */
6067 /* Process requests until done */
6072 /* Draw_everythig */
6073 draw_text_editor(tb);
6075 /* Display header line */
6077 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
6079 prt("(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)", 0, 0);
6083 /* Display current position */
6084 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6088 /* Display current position and mark position */
6089 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6093 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6096 tb->dirty_flags = 0;
6097 tb->dirty_line = -1;
6099 /* Save old key and location */
6100 tb->old_cy = tb->cy;
6101 tb->old_upper = tb->upper;
6102 tb->old_left = tb->left;
6103 tb->old_wid = tb->wid;
6104 tb->old_hgt = tb->hgt;
6107 key = inkey_special(TRUE);
6110 if (key & SKEY_MASK)
6112 /* Get a movement command */
6113 com_id = analyze_move_key(tb, key);
6117 else if (key == ESCAPE)
6119 com_id = do_command_menu(0, 0);
6121 /* Redraw all text later */
6122 tb->dirty_flags |= DIRTY_SCREEN;
6125 /* Insert a character */
6126 else if (!iscntrl((unsigned char)key))
6128 /* Ignore selection */
6134 tb->dirty_flags |= DIRTY_ALL;
6137 insert_single_letter(tb, key);
6143 /* Other commands */
6146 com_id = get_com_id(key);
6149 if (com_id) quit = do_editor_command(tb, com_id);
6150 } /* while (TRUE) */
6152 /* Restore the screen */
6155 /* Get the filename of preference */
6156 strcpy(buf, pickpref_filename(tb->filename_mode));
6158 if (quit == QUIT_AND_SAVE)
6159 write_text_lines(buf, tb->lines_list);
6161 free_text_lines(tb->lines_list);
6163 string_free(tb->last_destroyed);
6165 /* Destroy string chain */
6166 kill_yank_chain(tb);
6168 /* Reload autopick pref */
6169 process_autopick_file(buf);
6171 /* HACK -- reset start_time so that playtime is not increase while edit */
6172 start_time = time(NULL);
6174 /* Save cursor location */