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
22 #define FLG_COLLECTING 1
24 #define FLG_UNIDENTIFIED 3
25 #define FLG_IDENTIFIED 4
26 #define FLG_STAR_IDENTIFIED 5
28 #define FLG_MORE_DICE 7
29 #define FLG_MORE_BONUS 10
30 #define FLG_WORTHLESS 11
31 #define FLG_ARTIFACT 12
33 #define FLG_NAMELESS 14
39 #define FLG_UNREADABLE 20
48 #define FLG_WEAPONS 31
49 #define FLG_FAVORITE_WEAPONS 32
51 #define FLG_MISSILES 34
52 #define FLG_DEVICES 35
55 #define FLG_CORPSES 38
56 #define FLG_SPELLBOOKS 39
58 #define FLG_SHIELDS 41
61 #define FLG_AMULETS 44
68 #define FLG_NOUN_BEGIN FLG_ITEMS
69 #define FLG_NOUN_END FLG_BOOTS
73 static char KEY_ALL[] = "¤¹¤Ù¤Æ¤Î";
74 static char KEY_COLLECTING[] = "¼ý½¸Ãæ¤Î";
75 static char KEY_UNAWARE[] = "̤ȽÌÀ¤Î";
76 static char KEY_UNIDENTIFIED[] = "̤´ÕÄê¤Î";
77 static char KEY_IDENTIFIED[] = "´ÕÄêºÑ¤ß¤Î";
78 static char KEY_STAR_IDENTIFIED[] = "*´ÕÄê*ºÑ¤ß¤Î";
79 static char KEY_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦";
80 static char KEY_MORE_THAN[] = "¥À¥¤¥¹ÌÜ";
81 static char KEY_DICE[] = "°Ê¾å¤Î";
82 static char KEY_MORE_BONUS[] = "½¤ÀµÃÍ";
83 static char KEY_MORE_BONUS2[] = "°Ê¾å¤Î";
84 static char KEY_WORTHLESS[] = "̵²ÁÃͤÎ";
85 static char KEY_ARTIFACT[] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È";
86 static char KEY_EGO[] = "¥¨¥´";
87 static char KEY_NAMELESS[] = "̵ÌäÎ";
88 static char KEY_RARE[] = "¥ì¥¢¤Ê";
89 static char KEY_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿";
90 static char KEY_WANTED[] = "¾Þ¶â¼ó¤Î";
91 static char KEY_UNIQUE[] = "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î";
92 static char KEY_HUMAN[] = "¿Í´Ö¤Î";
93 static char KEY_UNREADABLE[] = "Æɤá¤Ê¤¤";
94 static char KEY_REALM1[] = "Âè°ìÎΰè¤Î";
95 static char KEY_REALM2[] = "ÂèÆóÎΰè¤Î";
96 static char KEY_FIRST[] = "1ºýÌܤÎ";
97 static char KEY_SECOND[] = "2ºýÌܤÎ";
98 static char KEY_THIRD[] = "3ºýÌܤÎ";
99 static char KEY_FOURTH[] = "4ºýÌܤÎ";
100 static char KEY_ITEMS[] = "¥¢¥¤¥Æ¥à";
101 static char KEY_WEAPONS[] = "Éð´ï";
102 static char KEY_FAVORITE_WEAPONS[] = "ÆÀ°ÕÉð´ï";
103 static char KEY_ARMORS[] = "Ëɶñ";
104 static char KEY_MISSILES[] = "Ìð";
105 static char KEY_DEVICES[] = "ËâË¡¥¢¥¤¥Æ¥à";
106 static char KEY_LIGHTS[] = "¸÷¸»";
107 static char KEY_JUNKS[] = "¤¬¤é¤¯¤¿";
108 static char KEY_CORPSES[] = "»àÂΤä¹ü";
109 static char KEY_SPELLBOOKS[] = "ËâË¡½ñ";
110 static char KEY_HAFTED[] = "Æß´ï";
111 static char KEY_SHIELDS[] = "½â";
112 static char KEY_BOWS[] = "µÝ";
113 static char KEY_RINGS[] = "»ØÎØ";
114 static char KEY_AMULETS[] = "¥¢¥ß¥å¥ì¥Ã¥È";
115 static char KEY_SUITS[] = "³»";
116 static char KEY_CLOAKS[] = "¥¯¥í¡¼¥¯";
117 static char KEY_HELMS[] = "³õ";
118 static char KEY_GLOVES[] = "äƼê";
119 static char KEY_BOOTS[] = "·¤";
123 static char KEY_ALL[] = "all";
124 static char KEY_COLLECTING[] = "collecting";
125 static char KEY_UNAWARE[] = "unaware";
126 static char KEY_UNIDENTIFIED[] = "unidentified";
127 static char KEY_IDENTIFIED[] = "identified";
128 static char KEY_STAR_IDENTIFIED[] = "*identified*";
129 static char KEY_BOOSTED[] = "dice boosted";
130 static char KEY_MORE_THAN[] = "more than";
131 static char KEY_DICE[] = " dice";
132 static char KEY_MORE_BONUS[] = "more bonus than";
133 static char KEY_MORE_BONUS2[] = "";
134 static char KEY_WORTHLESS[] = "worthless";
135 static char KEY_ARTIFACT[] = "artifact";
136 static char KEY_EGO[] = "ego";
137 static char KEY_NAMELESS[] = "nameless";
138 static char KEY_RARE[] = "rare";
139 static char KEY_COMMON[] = "common";
140 static char KEY_WANTED[] = "wanted";
141 static char KEY_UNIQUE[] = "unique monster's";
142 static char KEY_HUMAN[] = "human";
143 static char KEY_UNREADABLE[] = "unreadable";
144 static char KEY_REALM1[] = "first realm's";
145 static char KEY_REALM2[] = "second realm's";
146 static char KEY_FIRST[] = "first";
147 static char KEY_SECOND[] = "second";
148 static char KEY_THIRD[] = "third";
149 static char KEY_FOURTH[] = "fourth";
150 static char KEY_ITEMS[] = "items";
151 static char KEY_WEAPONS[] = "weapons";
152 static char KEY_FAVORITE_WEAPONS[] = "favorite weapons";
153 static char KEY_ARMORS[] = "armors";
154 static char KEY_MISSILES[] = "missiles";
155 static char KEY_DEVICES[] = "magical devices";
156 static char KEY_LIGHTS[] = "lights";
157 static char KEY_JUNKS[] = "junks";
158 static char KEY_CORPSES[] = "corpses or skeletons";
159 static char KEY_SPELLBOOKS[] = "spellbooks";
160 static char KEY_HAFTED[] = "hafted weapons";
161 static char KEY_SHIELDS[] = "shields";
162 static char KEY_BOWS[] = "bows";
163 static char KEY_RINGS[] = "rings";
164 static char KEY_AMULETS[] = "amulets";
165 static char KEY_SUITS[] = "suits";
166 static char KEY_CLOAKS[] = "cloaks";
167 static char KEY_HELMS[] = "helms";
168 static char KEY_GLOVES[] = "gloves";
169 static char KEY_BOOTS[] = "boots";
173 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
174 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
175 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
176 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
179 #define ADD_KEY(KEY) strcat(ptr, KEY)
181 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
183 #define ADD_KEY2(KEY) strcat(ptr, KEY)
185 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
186 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
187 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
188 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
191 static char kanji_colon[] = "¡§";
196 * A function to create new entry
198 static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_default)
203 char buf[MAX_LINELEN];
204 cptr prev_ptr, ptr, old_ptr;
207 if (str[1] == ':') switch (str[0])
210 case 'A': case 'P': case 'C':
214 entry->flag[0] = entry->flag[1] = 0L;
217 act = DO_AUTOPICK | DO_DISPLAY;
220 if ((act & DO_AUTOPICK) && *str == '!')
223 act |= DO_AUTODESTROY;
226 else if ((act & DO_AUTOPICK) && *str == '~')
229 act |= DONT_AUTOPICK;
232 else if ((act & DO_AUTOPICK) && *str == ';')
235 act |= DO_QUERY_AUTOPICK;
238 else if ((act & DO_DISPLAY) && *str == '(')
247 /* don't mind upper or lower case */
249 for (i = 0; *str; i++)
260 /* Auto-inscription? */
268 if (isupper(c)) c = tolower(c);
274 /* Skip empty line unless allow_default */
275 if (!allow_default && *buf == 0) return FALSE;
277 /* Skip comment line */
278 if (*buf == 0 && insc) return FALSE;
280 ptr = prev_ptr = buf;
283 while (old_ptr != ptr)
285 /* Save current location */
288 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
289 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
290 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
291 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
292 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
293 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
294 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
296 /*** Weapons whose dd*ds is more than nn ***/
297 if (MATCH_KEY2(KEY_MORE_THAN))
302 /* Drop leading spaces */
303 while (' ' == *ptr) ptr++;
306 while ('0' <= *ptr && *ptr <= '9')
308 entry->dice = 10 * entry->dice + (*ptr - '0');
315 (void)MATCH_KEY(KEY_DICE);
316 ADD_FLG(FLG_MORE_DICE);
322 /*** Items whose magical bonus is more than n ***/
323 if (MATCH_KEY2(KEY_MORE_BONUS))
328 /* Drop leading spaces */
329 while (' ' == *ptr) ptr++;
332 while ('0' <= *ptr && *ptr <= '9')
334 entry->bonus = 10 * entry->bonus + (*ptr - '0');
342 (void)MATCH_KEY(KEY_MORE_BONUS2);
344 if (' ' == *ptr) ptr++;
346 ADD_FLG(FLG_MORE_BONUS);
352 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
353 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
354 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
355 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
356 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
357 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
358 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
359 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
360 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
361 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
362 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
363 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
364 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
365 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
366 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
369 /* Not yet found any noun */
372 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
374 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
375 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
376 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
377 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
378 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
379 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
380 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
381 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
382 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
383 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
384 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
385 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
386 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
387 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
388 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
389 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
390 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
391 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
392 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
393 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
395 /* Last 'keyword' must be at the correct location */
399 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
402 else if (*ptr == '\0')
404 /* There was no noun */
407 /* Add extra word "items" */
408 ADD_FLG_NOUN(FLG_ITEMS);
415 /* A noun type keyword didn't end correctly */
416 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
421 /* Save this auto-picker entry line */
422 entry->name = string_make(ptr);
424 entry->insc = string_make(insc);
433 static bool is_favorite(object_type *o_ptr)
435 /* Only melee weapons match */
436 if (!(o_ptr->tval == TV_POLEARM ||
437 o_ptr->tval == TV_SWORD ||
438 o_ptr->tval == TV_DIGGING ||
439 o_ptr->tval == TV_HAFTED))
444 /* Favorite weapons are varied depend on the class */
445 switch (p_ptr->pclass)
449 u32b flgs[TR_FLAG_SIZE];
450 object_flags_known(o_ptr, flgs);
452 if (!have_flag(flgs, TR_BLESSED) &&
453 !(o_ptr->tval == TV_HAFTED))
459 case CLASS_FORCETRAINER:
461 if (!(s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval]))
465 case CLASS_BEASTMASTER:
468 u32b flgs[TR_FLAG_SIZE];
469 object_flags_known(o_ptr, flgs);
471 /* Is it known to be suitable to using while riding? */
472 if (!(have_flag(flgs, TR_RIDING)))
480 if (s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
485 /* All weapons are okay for non-special classes */
494 * Rare weapons/aromors
495 * including Blade of Chaos, Dragon armors, etc.
497 static bool is_rare(object_type *o_ptr)
502 if (o_ptr->sval == SV_MACE_OF_DISRUPTION ||
503 o_ptr->sval == SV_WIZSTAFF) return TRUE;
507 if (o_ptr->sval == SV_SCYTHE_OF_SLICING ||
508 o_ptr->sval == SV_DEATH_SCYTHE) return TRUE;
512 if (o_ptr->sval == SV_BLADE_OF_CHAOS ||
513 o_ptr->sval == SV_DIAMOND_EDGE ||
514 o_ptr->sval == SV_DOKUBARI ||
515 o_ptr->sval == SV_HAYABUSA) return TRUE;
519 if (o_ptr->sval == SV_DRAGON_SHIELD ||
520 o_ptr->sval == SV_MIRROR_SHIELD) return TRUE;
524 if (o_ptr->sval == SV_DRAGON_HELM) return TRUE;
528 if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) return TRUE;
532 if (o_ptr->sval == SV_ELVEN_CLOAK ||
533 o_ptr->sval == SV_ETHEREAL_CLOAK ||
534 o_ptr->sval == SV_SHADOW_CLOAK) return TRUE;
538 if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) return TRUE;
542 if (o_ptr->sval == SV_KUROSHOUZOKU ||
543 o_ptr->sval == SV_ABUNAI_MIZUGI) return TRUE;
553 /* Any others are not "rare" objects. */
559 * Get auto-picker entry from o_ptr.
561 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
563 /* Assume that object name is to be added */
567 /* ¥¨¥´Ì䬼ÙË⤫¤â¤·¤ì¤Ê¤¤¤Î¤Ç¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¡Ö^¡×¤ÏÉÕ¤±¤Ê¤¤ */
568 bool bol_mark = FALSE;
570 /* We can always use the ^ mark in English */
571 bool bol_mark = TRUE;
574 char name_str[MAX_NLEN];
576 /* Initialize name string */
579 entry->insc = string_make(quark_str(o_ptr->inscription));
580 entry->action = DO_AUTOPICK | DO_DISPLAY;
581 entry->flag[0] = entry->flag[1] = 0L;
585 if (!object_aware_p(o_ptr))
587 ADD_FLG(FLG_UNAWARE);
591 /* Not really identified */
592 else if (!object_known_p(o_ptr))
594 if (!(o_ptr->ident & IDENT_SENSE))
596 ADD_FLG(FLG_UNIDENTIFIED);
601 /* Pseudo-identified */
602 switch (o_ptr->feeling)
606 ADD_FLG(FLG_NAMELESS);
612 ADD_FLG(FLG_NAMELESS);
613 ADD_FLG(FLG_WORTHLESS);
619 ADD_FLG(FLG_WORTHLESS);
627 /* XXX No appropriate flag */
632 /* Never reach here */
645 if (TV_WEAPON_BEGIN <= o_ptr->tval &&
646 o_ptr->tval <= TV_ARMOR_END)
649 * Base name of ego weapons and armors
650 * are almost meaningless.
651 * Register the ego type only.
653 ego_item_type *e_ptr = &e_info[o_ptr->name2];
655 /* ¥¨¥´ÌäˤϡÖ^¡×¥Þ¡¼¥¯¤¬»È¤¨¤ë */
656 sprintf(name_str, "^%s", e_name + e_ptr->name);
658 /* We ommit the basename and cannot use the ^ mark */
659 strcpy(name_str, e_name + e_ptr->name);
662 /* Don't use the object description */
665 if (TV_WEAPON_BEGIN <= o_ptr->tval &&
666 o_ptr->tval <= TV_ARMOR_END)
668 /* Restrict to 'common' equipments */
669 if (!is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
677 else if (o_ptr->name1 || o_ptr->art_name)
678 ADD_FLG(FLG_ARTIFACT);
680 /* Non-ego, non-artifact */
683 /* Wearable nameless object */
684 if ((TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
685 ADD_FLG(FLG_NAMELESS);
696 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
697 k_ptr = &k_info[o_ptr->k_idx];
698 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
699 ADD_FLG(FLG_BOOSTED);
702 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
704 REM_FLG(FLG_WORTHLESS);
708 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
709 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
714 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
719 if (o_ptr->tval >= TV_LIFE_BOOK &&
720 !check_book_realm(o_ptr->tval, o_ptr->sval))
722 ADD_FLG(FLG_UNREADABLE);
723 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
726 if (REALM1_BOOK == o_ptr->tval &&
727 p_ptr->pclass != CLASS_SORCERER &&
728 p_ptr->pclass != CLASS_RED_MAGE)
734 if (REALM2_BOOK == o_ptr->tval &&
735 p_ptr->pclass != CLASS_SORCERER &&
736 p_ptr->pclass != CLASS_RED_MAGE)
742 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
744 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
746 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
748 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
751 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
752 || o_ptr->tval == TV_ARROW)
753 ADD_FLG(FLG_MISSILES);
754 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
755 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
756 ADD_FLG(FLG_DEVICES);
757 else if (o_ptr->tval == TV_LITE)
759 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
760 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
762 else if (o_ptr->tval == TV_CORPSE)
763 ADD_FLG(FLG_CORPSES);
764 else if (o_ptr->tval >= TV_LIFE_BOOK)
765 ADD_FLG(FLG_SPELLBOOKS);
766 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
767 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
768 ADD_FLG(FLG_WEAPONS);
769 else if (o_ptr->tval == TV_SHIELD)
770 ADD_FLG(FLG_SHIELDS);
771 else if (o_ptr->tval == TV_BOW)
773 else if (o_ptr->tval == TV_RING)
775 else if (o_ptr->tval == TV_AMULET)
776 ADD_FLG(FLG_AMULETS);
777 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
778 o_ptr->tval == TV_SOFT_ARMOR)
780 else if (o_ptr->tval == TV_CLOAK)
782 else if (o_ptr->tval == TV_HELM)
784 else if (o_ptr->tval == TV_GLOVES)
786 else if (o_ptr->tval == TV_BOOTS)
789 /* Prepare the object description */
792 char o_name[MAX_NLEN];
794 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
797 * If necessary, add a '^' which indicates the
800 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
803 /* Register the name in lowercase */
804 str_tolower(name_str);
805 entry->name = string_make(name_str);
812 * A function to delete entry
814 static void autopick_free_entry(autopick_type *entry)
816 string_free(entry->name);
817 string_free(entry->insc);
821 #define MAX_AUTOPICK_DEFAULT 200
824 * Initialize the autopick
826 static void init_autopick(void)
828 static const char easy_autopick_inscription[] = "(:=g";
834 max_max_autopick = MAX_AUTOPICK_DEFAULT;
835 C_MAKE(autopick_list, max_max_autopick, autopick_type);
839 /* Clear old entries */
840 for( i = 0; i < max_autopick; i++)
841 autopick_free_entry(&autopick_list[i]);
845 /* There is always one entry "=g" */
846 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
847 autopick_list[max_autopick++] = entry;
852 #define PT_WITH_PNAME 1
855 * Get file name for autopick preference
857 static cptr pickpref_filename(int filename_mode)
860 static const char namebase[] = "picktype";
862 static const char namebase[] = "pickpref";
865 switch (filename_mode)
868 return format("%s.prf", namebase);
871 return format("%s-%s.prf", namebase, player_name);
880 * Load an autopick preference file
882 void autopick_load_pref(bool disp_mes)
887 /* Free old entries */
890 /* Try a filename with player name */
891 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
894 err = process_autopick_file(buf);
896 if (err == 0 && disp_mes)
900 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
902 msg_format("Loaded '%s'.", buf);
909 /* Use default name */
910 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
913 err = process_autopick_file(buf);
915 if (err == 0 && disp_mes)
919 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
921 msg_format("Loaded '%s'.", buf);
930 msg_print("¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
932 msg_print("Failed to reload autopick preference.");
939 * Add one line to autopick_list[]
941 static void add_autopick_list(autopick_type *entry)
943 /* There is no enough space to add one line */
944 if (max_autopick >= max_max_autopick)
946 int old_max_max_autopick = max_max_autopick;
947 autopick_type *old_autopick_list = autopick_list;
949 /* Increase size of list */
950 max_max_autopick += MAX_AUTOPICK_DEFAULT;
953 C_MAKE(autopick_list, max_max_autopick, autopick_type);
955 /* Copy from old list to new list */
956 C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
959 C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
963 autopick_list[max_autopick] = *entry;
970 * Process line for auto picker/destroyer.
972 errr process_autopick_file_command(char *buf)
974 autopick_type an_entry, *entry = &an_entry;
977 /* Nuke illegal char */
978 for(i = 0; buf[i]; i++)
987 if (isspace(buf[i]) && buf[i] != ' ')
992 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
994 /* Already has the same entry? */
995 for(i = 0; i < max_autopick; i++)
996 if(!strcmp(entry->name, autopick_list[i].name)
997 && entry->flag[0] == autopick_list[i].flag[0]
998 && entry->flag[1] == autopick_list[i].flag[1]
999 && entry->dice == autopick_list[i].dice
1000 && entry->bonus == autopick_list[i].bonus) return 0;
1002 add_autopick_list(entry);
1008 * Reconstruct preference line from entry
1010 cptr autopick_line_from_entry(autopick_type *entry)
1012 char buf[MAX_LINELEN];
1014 bool sepa_flag = TRUE;
1017 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
1018 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
1019 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
1020 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
1024 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
1025 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
1026 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
1027 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
1028 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
1029 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
1030 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
1032 if (IS_FLG(FLG_MORE_DICE))
1034 ADD_KEY(KEY_MORE_THAN);
1035 strcat(ptr, format("%d", entry->dice));
1039 if (IS_FLG(FLG_MORE_BONUS))
1041 ADD_KEY(KEY_MORE_BONUS);
1042 strcat(ptr, format("%d", entry->bonus));
1043 ADD_KEY(KEY_MORE_BONUS2);
1046 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
1047 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
1048 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
1049 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
1050 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
1051 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
1052 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
1053 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
1054 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
1055 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
1056 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
1057 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
1058 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
1059 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
1060 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
1062 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
1064 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
1065 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
1066 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
1067 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
1068 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
1069 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
1070 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
1071 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
1072 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
1073 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
1074 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
1075 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
1076 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
1077 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
1078 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
1079 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
1080 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
1081 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
1082 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
1083 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
1085 /* You don't need sepalator after adjective */
1086 /* 'artifact' is not true adjective */
1087 else if (!IS_FLG(FLG_ARTIFACT))
1090 if (entry->name && entry->name[0])
1094 if (sepa_flag) strcat(buf, ":");
1097 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
1100 if (iskanji(entry->name[j]))
1101 buf[i++] = entry->name[j++];
1103 buf[i++] = entry->name[j++];
1114 while (entry->insc[j] && i < MAX_LINELEN - 2)
1117 if (iskanji(entry->insc[j]))
1118 buf[i++] = entry->insc[j++];
1120 buf[i++] = entry->insc[j++];
1125 return string_make(buf);
1130 * Reconstruct preference line from entry and kill entry
1132 static cptr autopick_line_from_entry_kill(autopick_type *entry)
1134 cptr ptr = autopick_line_from_entry(entry);
1136 /* Free memory for original entry */
1137 autopick_free_entry(entry);
1144 * A function for Auto-picker/destroyer
1145 * Examine whether the object matches to the entry
1147 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
1150 cptr ptr = entry->name;
1152 /*** Unaware items ***/
1153 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
1156 /*** Unidentified ***/
1157 if (IS_FLG(FLG_UNIDENTIFIED)
1158 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1161 /*** Identified ***/
1162 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
1165 /*** *Identified* ***/
1166 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1167 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1170 /*** Dice boosted (weapon of slaying) ***/
1171 if (IS_FLG(FLG_BOOSTED))
1173 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1175 switch( o_ptr->tval )
1181 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1190 /*** Weapons which dd*ds is more than nn ***/
1191 if (IS_FLG(FLG_MORE_DICE))
1193 if (o_ptr->dd * o_ptr->ds < entry->dice)
1197 /*** Weapons whic dd*ds is more than nn ***/
1198 if (IS_FLG(FLG_MORE_BONUS))
1200 if (!object_known_p(o_ptr)) return FALSE;
1204 if (o_ptr->pval < entry->bonus) return FALSE;
1208 if (o_ptr->to_h < entry->bonus &&
1209 o_ptr->to_d < entry->bonus &&
1210 o_ptr->to_a < entry->bonus &&
1211 o_ptr->pval < entry->bonus)
1216 /*** Worthless items ***/
1217 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1220 /*** Artifact object ***/
1221 if (IS_FLG(FLG_ARTIFACT))
1223 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
1227 /*** Ego object ***/
1228 if (IS_FLG(FLG_EGO))
1230 /* Need to be an ego item */
1231 if (!o_ptr->name2) return FALSE;
1233 /* Need to be known to be an ego */
1234 if (!object_known_p(o_ptr) &&
1235 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1240 if (IS_FLG(FLG_NAMELESS))
1242 if (!(TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
1246 if (object_known_p(o_ptr))
1248 /* Artifacts and Ego objects are not okay */
1249 if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2)
1253 /* Pseudo-identified */
1254 else if (o_ptr->ident & IDENT_SENSE)
1256 switch (o_ptr->feeling)
1266 /* It's not nameless */
1274 /* Not known to be nameless */
1279 /*** Rere equpiments ***/
1280 if (IS_FLG(FLG_RARE) && !is_rare(o_ptr))
1283 /*** Common equpiments ***/
1284 if (IS_FLG(FLG_COMMON) && is_rare(o_ptr))
1287 /*** Wanted monster's corpse/skeletons ***/
1288 if (IS_FLG(FLG_WANTED) &&
1289 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
1292 /*** Unique monster's corpse/skeletons/statues ***/
1293 if (IS_FLG(FLG_UNIQUE) &&
1294 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1295 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1298 /*** Human corpse/skeletons (for Daemon magic) ***/
1299 if (IS_FLG(FLG_HUMAN) &&
1300 (o_ptr->tval != TV_CORPSE ||
1301 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1304 /*** Unreadable spellbooks ***/
1305 if (IS_FLG(FLG_UNREADABLE) &&
1306 (o_ptr->tval < TV_LIFE_BOOK ||
1307 check_book_realm(o_ptr->tval, o_ptr->sval)))
1310 /*** First realm spellbooks ***/
1311 if (IS_FLG(FLG_REALM1) &&
1312 (REALM1_BOOK != o_ptr->tval ||
1313 p_ptr->pclass == CLASS_SORCERER ||
1314 p_ptr->pclass == CLASS_RED_MAGE))
1317 /*** Second realm spellbooks ***/
1318 if (IS_FLG(FLG_REALM2) &&
1319 (REALM2_BOOK != o_ptr->tval ||
1320 p_ptr->pclass == CLASS_SORCERER ||
1321 p_ptr->pclass == CLASS_RED_MAGE))
1324 /*** First rank spellbooks ***/
1325 if (IS_FLG(FLG_FIRST) &&
1326 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1329 /*** Second rank spellbooks ***/
1330 if (IS_FLG(FLG_SECOND) &&
1331 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1334 /*** Third rank spellbooks ***/
1335 if (IS_FLG(FLG_THIRD) &&
1336 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1339 /*** Fourth rank spellbooks ***/
1340 if (IS_FLG(FLG_FOURTH) &&
1341 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1345 if (IS_FLG(FLG_WEAPONS))
1347 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
1350 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1352 if (!is_favorite(o_ptr))
1355 else if (IS_FLG(FLG_ARMORS))
1357 if (!(TV_ARMOR_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_ARMOR_END))
1360 else if (IS_FLG(FLG_MISSILES))
1364 case TV_SHOT: case TV_BOLT: case TV_ARROW:
1366 default: return FALSE;
1369 else if (IS_FLG(FLG_DEVICES))
1373 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1375 default: return FALSE;
1378 else if (IS_FLG(FLG_LIGHTS))
1380 if (!(o_ptr->tval == TV_LITE))
1383 else if (IS_FLG(FLG_JUNKS))
1387 case TV_SKELETON: case TV_BOTTLE:
1388 case TV_JUNK: case TV_STATUE:
1390 default: return FALSE;
1393 else if (IS_FLG(FLG_CORPSES))
1395 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1398 else if (IS_FLG(FLG_SPELLBOOKS))
1400 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1403 else if (IS_FLG(FLG_HAFTED))
1405 if (!(o_ptr->tval == TV_HAFTED))
1408 else if (IS_FLG(FLG_SHIELDS))
1410 if (!(o_ptr->tval == TV_SHIELD))
1413 else if (IS_FLG(FLG_BOWS))
1415 if (!(o_ptr->tval == TV_BOW))
1418 else if (IS_FLG(FLG_RINGS))
1420 if (!(o_ptr->tval == TV_RING))
1423 else if (IS_FLG(FLG_AMULETS))
1425 if (!(o_ptr->tval == TV_AMULET))
1428 else if (IS_FLG(FLG_SUITS))
1430 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1431 o_ptr->tval == TV_HARD_ARMOR ||
1432 o_ptr->tval == TV_SOFT_ARMOR))
1435 else if (IS_FLG(FLG_CLOAKS))
1437 if (!(o_ptr->tval == TV_CLOAK))
1440 else if (IS_FLG(FLG_HELMS))
1442 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1445 else if (IS_FLG(FLG_GLOVES))
1447 if (!(o_ptr->tval == TV_GLOVES))
1450 else if (IS_FLG(FLG_BOOTS))
1452 if (!(o_ptr->tval == TV_BOOTS))
1456 /* Keyword don't match */
1460 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1464 if (!my_strstr(o_name, ptr)) return FALSE;
1467 /* TRUE when it need not to be 'collecting' */
1468 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1470 /* Check if there is a same item */
1471 for (j = 0; j < INVEN_PACK; j++)
1474 * 'Collecting' means the item must be absorbed
1475 * into an inventory slot.
1476 * But an item can not be absorbed into itself!
1478 if ((&inventory[j] != o_ptr) &&
1479 object_similar(&inventory[j], o_ptr))
1483 /* Not collecting */
1489 * A function for Auto-picker/destroyer
1490 * Examine whether the object matches to the list of keywords or not.
1492 int is_autopick(object_type *o_ptr)
1495 char o_name[MAX_NLEN];
1497 if (o_ptr->tval == TV_GOLD) return -1;
1499 /* Prepare object name string first */
1500 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1502 /* Convert the string to lower case */
1503 str_tolower(o_name);
1505 /* Look for a matching entry in the list */
1506 for (i=0; i < max_autopick; i++)
1508 autopick_type *entry = &autopick_list[i];
1510 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1513 /* No matching entry */
1521 static void auto_inscribe_item(object_type *o_ptr, int idx)
1523 /* Are there auto-inscription? */
1524 if (idx < 0 || !autopick_list[idx].insc) return;
1526 if (!o_ptr->inscription)
1527 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1529 /* Redraw inscription */
1530 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1532 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1533 p_ptr->update |= (PU_BONUS);
1538 * Automatically destroy items in this grid.
1540 static bool is_opt_confirm_destroy(object_type *o_ptr)
1542 if (!destroy_items) return FALSE;
1544 /* Known to be worthless? */
1546 if (object_value(o_ptr) > 0) return FALSE;
1549 if ((o_ptr->tval >= TV_MISSILE_BEGIN) && (o_ptr->tval <= TV_ARMOR_END)) return FALSE;
1552 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1556 if (o_ptr->tval == TV_CORPSE
1557 && object_is_shoukinkubi(o_ptr)) return FALSE;
1561 if (o_ptr->tval == TV_CORPSE) return FALSE;
1564 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1568 if (p_ptr->prace == RACE_DEMON)
1570 if (o_ptr->tval == TV_CORPSE &&
1571 o_ptr->sval == SV_CORPSE &&
1572 my_strchr("pht", r_info[o_ptr->pval].d_char))
1576 if (p_ptr->pclass == CLASS_ARCHER)
1578 if (o_ptr->tval == TV_SKELETON ||
1579 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1582 else if (p_ptr->pclass == CLASS_NINJA)
1584 if (o_ptr->tval == TV_LITE &&
1585 o_ptr->name2 == EGO_LITE_DARKNESS)
1588 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1589 p_ptr->pclass == CLASS_CAVALRY)
1591 if (o_ptr->tval == TV_WAND &&
1592 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1597 if (o_ptr->tval == TV_GOLD) return FALSE;
1604 * Automatically destroy an item if it is to be destroyed
1606 * When always_pickup is 'yes', we disable auto-destroyer function of
1607 * auto-picker/destroyer, and do only easy-auto-destroyer.
1609 static object_type autopick_last_destroyed_object;
1611 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1613 bool destroy = FALSE;
1615 /* Easy-Auto-Destroyer (3rd priority) */
1616 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1618 /* Protected by auto-picker (2nd priotity) */
1619 if (autopick_idx >= 0 &&
1620 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1623 /* Auto-destroyer works only when !always_pickup */
1626 /* Auto-picker/destroyer (1st priority) */
1627 if (autopick_idx >= 0 &&
1628 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1632 /* Not to be destroyed */
1633 if (!destroy) return;
1635 /* Now decided to destroy */
1640 if (!can_player_destroy_object(o_ptr))
1642 char o_name[MAX_NLEN];
1644 /* Describe the object (with {terrible/special}) */
1645 object_desc(o_name, o_ptr, 0);
1649 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1651 msg_format("You cannot auto-destroy %s.", o_name);
1658 /* Record name of destroyed item */
1659 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1662 o_ptr->marked |= OM_AUTODESTROY;
1663 p_ptr->notice |= PN_AUTODESTROY;
1670 * Auto-destroy marked item
1672 static void autopick_delayed_alter_aux(int item)
1676 /* Get the item (in the pack) */
1677 if (item >= 0) o_ptr = &inventory[item];
1679 /* Get the item (on the floor) */
1680 else o_ptr = &o_list[0 - item];
1682 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1684 char o_name[MAX_NLEN];
1686 /* Describe the object (with {terrible/special}) */
1687 object_desc(o_name, o_ptr, 0);
1689 /* Eliminate the item (from the pack) */
1692 inven_item_increase(item, -(o_ptr->number));
1693 inven_item_optimize(item);
1696 /* Eliminate the item (from the floor) */
1699 delete_object_idx(0 - item);
1702 /* Print a message */
1704 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1706 msg_format("Auto-destroying %s.", o_name);
1713 * Auto-destroy marked items in inventry and on floor
1715 void autopick_delayed_alter(void)
1720 * Scan inventry in reverse order to prevent
1721 * skipping after inven_item_optimize()
1723 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1724 autopick_delayed_alter_aux(item);
1726 /* Scan the pile of objects */
1727 item = cave[py][px].o_idx;
1730 int next = o_list[item].next_o_idx;
1731 autopick_delayed_alter_aux(-item);
1738 * Auto-inscription and/or destroy
1740 * Auto-destroyer works only on inventory or on floor stack only when
1743 void autopick_alter_item(int item, bool destroy)
1748 /* Get the item (in the pack) */
1749 if (item >= 0) o_ptr = &inventory[item];
1751 /* Get the item (on the floor) */
1752 else o_ptr = &o_list[0 - item];
1754 /* Get the index in the auto-pick/destroy list */
1755 idx = is_autopick(o_ptr);
1757 /* Do auto-inscription */
1758 auto_inscribe_item(o_ptr, idx);
1760 /* Do auto-destroy if needed */
1761 if (destroy && item <= INVEN_PACK)
1762 auto_destroy_item(o_ptr, idx);
1767 * Automatically pickup/destroy items in this grid.
1769 void autopick_pickup_items(cave_type *c_ptr)
1771 s16b this_o_idx, next_o_idx = 0;
1773 /* Scan the pile of objects */
1774 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1778 /* Acquire object */
1779 object_type *o_ptr = &o_list[this_o_idx];
1781 /* Acquire next object */
1782 next_o_idx = o_ptr->next_o_idx;
1784 idx = is_autopick(o_ptr);
1786 /* Item index for floor -1,-2,-3,... */
1787 auto_inscribe_item(o_ptr, idx);
1790 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1794 if (!inven_carry_okay(o_ptr))
1796 char o_name[MAX_NLEN];
1798 /* Describe the object */
1799 object_desc(o_name, o_ptr, 0);
1803 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1805 msg_format("You have no room for %s.", o_name);
1807 /* Hack - remember that the item has given a message here. */
1808 o_ptr->marked |= OM_NOMSG;
1812 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1814 char out_val[MAX_NLEN+20];
1815 char o_name[MAX_NLEN];
1817 if (o_ptr->marked & OM_NO_QUERY)
1819 /* Already answered as 'No' */
1823 /* Describe the object */
1824 object_desc(o_name, o_ptr, 0);
1827 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1829 sprintf(out_val, "Pick up %s? ", o_name);
1832 if (!get_check(out_val))
1834 /* Hack - remember that the item has given a message here. */
1835 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1840 py_pickup_aux(this_o_idx);
1845 * When always_pickup is 'yes', we disable
1846 * auto-destroyer from autopick function, and do only
1847 * easy-auto-destroyer.
1851 auto_destroy_item(o_ptr, idx);
1857 static const char autoregister_header[] = "?:$AUTOREGISTER";
1860 * Clear auto registered lines in the picktype.prf .
1862 static bool clear_auto_register(void)
1864 char tmp_file[1024];
1865 char pref_file[1024];
1870 bool autoregister = FALSE;
1873 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1874 pref_fff = my_fopen(pref_file, "r");
1878 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1879 pref_fff = my_fopen(pref_file, "r");
1888 /* Open a new (temporary) file */
1889 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1893 /* Close the preference file */
1897 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1899 msg_format("Failed to create temporary file %s.", tmp_file);
1906 /* Loop for every line */
1910 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1914 /* Delete auto-registered line */
1916 /* Count auto-destroy preference lines */
1917 if (buf[0] != '#' && buf[0] != '?') num++;
1920 /* We are looking for auto-registered line */
1923 if (streq(buf, autoregister_header))
1925 /* Delete all further lines */
1926 autoregister = TRUE;
1930 /* Copy orginally lines */
1931 fprintf(tmp_fff, "%s\n", buf);
1937 my_fclose(pref_fff);
1943 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1944 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1946 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1947 strcpy(buf, "These lines will be deleted. Are you sure? ");
1950 /* You can cancel it */
1951 if (!get_check(buf))
1954 autoregister = FALSE;
1957 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1959 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1965 /* If there are some changes, overwrite the original file with new one */
1968 /* Copy contents of temporary file */
1970 tmp_fff = my_fopen(tmp_file, "r");
1971 pref_fff = my_fopen(pref_file, "w");
1973 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1974 fprintf(pref_fff, "%s\n", buf);
1976 my_fclose(pref_fff);
1980 /* Kill the temporary file */
1988 * Automatically register an auto-destroy preference line
1990 bool autopick_autoregister(object_type *o_ptr)
1993 char pref_file[1024];
1995 autopick_type an_entry, *entry = &an_entry;
1997 int match_autopick = is_autopick(o_ptr);
1999 /* Already registered */
2000 if (match_autopick != -1)
2003 byte act = autopick_list[match_autopick].action;
2006 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
2007 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
2008 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
2009 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
2011 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
2013 if (act & DO_AUTOPICK) what = "auto-pickup";
2014 else if (act & DO_AUTODESTROY) what = "auto-destroy";
2015 else if (act & DONT_AUTOPICK) what = "leave on floor";
2016 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
2018 msg_format("The object is already registered to %s.", what);
2024 /* Known to be an artifact? */
2025 if ((object_known_p(o_ptr) &&
2026 (artifact_p(o_ptr) || o_ptr->art_name)) ||
2027 ((o_ptr->ident & IDENT_SENSE) &&
2028 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
2030 char o_name[MAX_NLEN];
2032 /* Describe the object (with {terrible/special}) */
2033 object_desc(o_name, o_ptr, 0);
2037 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
2039 msg_format("You cannot auto-destroy %s.", o_name);
2047 if (!p_ptr->autopick_autoregister)
2049 /* Clear old auto registered lines */
2050 if (!clear_auto_register()) return FALSE;
2053 /* Try a filename with player name */
2054 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
2055 pref_fff = my_fopen(pref_file, "r");
2059 /* Use default name */
2060 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
2061 pref_fff = my_fopen(pref_file, "r");
2064 /* Check the header */
2068 if (my_fgets(pref_fff, buf, sizeof(buf)))
2070 /* No header found */
2071 p_ptr->autopick_autoregister = FALSE;
2076 if (streq(buf, autoregister_header))
2078 /* Found the header */
2079 p_ptr->autopick_autoregister = TRUE;
2085 /* Close read only FILE* */
2088 /* Open for append */
2089 pref_fff = my_fopen(pref_file, "a");
2094 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
2096 msg_format("Failed to open %s.", pref_file);
2104 if (!p_ptr->autopick_autoregister)
2106 /* Add the header */
2107 fprintf(pref_fff, "%s\n", autoregister_header);
2110 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
2111 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
2113 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
2114 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
2117 /* Now auto register is in-use */
2118 p_ptr->autopick_autoregister = TRUE;
2121 /* Get a preference entry */
2122 autopick_entry_from_object(entry, o_ptr);
2124 /* Set to auto-destroy (with no-display) */
2125 entry->action = DO_AUTODESTROY;
2127 /* Load the new line as preference */
2128 add_autopick_list(entry);
2130 /* Add a line to the file */
2131 /* Don't kill "entry" */
2132 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2134 /* Close the file */
2141 /******** Auto-picker/destroyer editor **********/
2143 #define MAX_YANK MAX_LINELEN
2144 #define MAX_LINES 3000
2146 #define MARK_MARK 0x01
2147 #define MARK_BY_SHIFT 0x02
2149 #define LSTAT_BYPASS 0x01
2150 #define LSTAT_EXPRESSION 0x02
2151 #define LSTAT_AUTOREGISTER 0x04
2153 #define QUIT_WITHOUT_SAVE 1
2154 #define QUIT_AND_SAVE 2
2157 * Struct for yank buffer
2159 typedef struct chain_str {
2160 struct chain_str *next;
2166 * Data struct for text editor
2172 int old_wid, old_hgt;
2174 int old_upper, old_left;
2178 object_type *search_o_ptr;
2180 cptr last_destroyed;
2182 chain_str_type *yank;
2186 byte states[MAX_LINES];
2198 * Dirty flag for text editor
2200 #define DIRTY_ALL 0x0001
2201 #define DIRTY_MODE 0x0004
2202 #define DIRTY_SCREEN 0x0008
2203 #define DIRTY_NOT_FOUND 0x0010
2204 #define DIRTY_NO_SEARCH 0x0020
2205 #define DIRTY_EXPRESSION 0x0040
2206 #define DIRTY_SKIP_INACTIVE 0x0080
2207 #define DIRTY_INACTIVE 0x0100
2210 * Describe which kind of object is Auto-picked/destroyed
2212 static void describe_autopick(char *buff, autopick_type *entry)
2214 cptr str = entry->name;
2215 byte act = entry->action;
2216 cptr insc = entry->insc;
2222 cptr before_str[100], body_str;
2225 body_str = "¥¢¥¤¥Æ¥à";
2227 /*** Collecting items ***/
2228 /*** Which can be absorbed into a slot as a bundle ***/
2229 if (IS_FLG(FLG_COLLECTING))
2230 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2232 /*** Unaware items ***/
2233 if (IS_FLG(FLG_UNAWARE))
2234 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2236 /*** Unidentified ***/
2237 if (IS_FLG(FLG_UNIDENTIFIED))
2238 before_str[before_n++] = "̤´ÕÄê¤Î";
2240 /*** Identified ***/
2241 if (IS_FLG(FLG_IDENTIFIED))
2242 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2244 /*** *Identified* ***/
2245 if (IS_FLG(FLG_STAR_IDENTIFIED))
2246 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2248 /*** Dice boosted (weapon of slaying) ***/
2249 if (IS_FLG(FLG_BOOSTED))
2251 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2255 /*** Weapons whose dd*ds is more than nn ***/
2256 if (IS_FLG(FLG_MORE_DICE))
2258 static char more_than_desc_str[] = "___";
2259 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2262 sprintf(more_than_desc_str,"%d", entry->dice);
2263 before_str[before_n++] = more_than_desc_str;
2264 before_str[before_n++] = "°Ê¾å¤Î";
2267 /*** Items whose magical bonus is more than nn ***/
2268 if (IS_FLG(FLG_MORE_BONUS))
2270 static char more_bonus_desc_str[] = "___";
2271 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2273 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2274 before_str[before_n++] = more_bonus_desc_str;
2275 before_str[before_n++] = ")°Ê¾å¤Î";
2278 /*** Worthless items ***/
2279 if (IS_FLG(FLG_WORTHLESS))
2280 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2283 if (IS_FLG(FLG_ARTIFACT))
2285 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2290 if (IS_FLG(FLG_EGO))
2292 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2297 if (IS_FLG(FLG_NAMELESS))
2299 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2303 /*** Rare equpiments ***/
2304 if (IS_FLG(FLG_RARE))
2306 before_str[before_n++] = "¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ò´Þ¤àÄÁ¤·¤¤";
2310 /*** Common equpiments ***/
2311 if (IS_FLG(FLG_COMMON))
2313 before_str[before_n++] = "¤¢¤ê¤Õ¤ì¤¿(¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ÎÄÁ¤·¤¤Êª¤Ç¤Ï¤Ê¤¤)";
2317 /*** Wanted monster's corpse/skeletons ***/
2318 if (IS_FLG(FLG_WANTED))
2320 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2321 body_str = "»àÂΤä¹ü";
2324 /*** Human corpse/skeletons (for Daemon magic) ***/
2325 if (IS_FLG(FLG_HUMAN))
2327 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2328 body_str = "»àÂΤä¹ü";
2331 /*** Unique monster's corpse/skeletons/statues ***/
2332 if (IS_FLG(FLG_UNIQUE))
2334 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2335 body_str = "»àÂΤä¹ü";
2338 /*** Unreadable spellbooks ***/
2339 if (IS_FLG(FLG_UNREADABLE))
2341 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2342 body_str = "ËâË¡½ñ";
2345 /*** First realm spellbooks ***/
2346 if (IS_FLG(FLG_REALM1))
2348 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2349 body_str = "ËâË¡½ñ";
2352 /*** Second realm spellbooks ***/
2353 if (IS_FLG(FLG_REALM2))
2355 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2356 body_str = "ËâË¡½ñ";
2359 /*** First rank spellbooks ***/
2360 if (IS_FLG(FLG_FIRST))
2362 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2363 body_str = "ËâË¡½ñ";
2366 /*** Second rank spellbooks ***/
2367 if (IS_FLG(FLG_SECOND))
2369 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2370 body_str = "ËâË¡½ñ";
2373 /*** Third rank spellbooks ***/
2374 if (IS_FLG(FLG_THIRD))
2376 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2377 body_str = "ËâË¡½ñ";
2380 /*** Fourth rank spellbooks ***/
2381 if (IS_FLG(FLG_FOURTH))
2383 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2384 body_str = "ËâË¡½ñ";
2388 if (IS_FLG(FLG_ITEMS))
2389 ; /* Nothing to do */
2390 else if (IS_FLG(FLG_WEAPONS))
2392 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2393 body_str = "ÆÀ°ÕÉð´ï";
2394 else if (IS_FLG(FLG_ARMORS))
2396 else if (IS_FLG(FLG_MISSILES))
2397 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2398 else if (IS_FLG(FLG_DEVICES))
2399 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2400 else if (IS_FLG(FLG_LIGHTS))
2401 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2402 else if (IS_FLG(FLG_JUNKS))
2403 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2404 else if (IS_FLG(FLG_CORPSES))
2405 body_str = "»àÂΤä¹ü";
2406 else if (IS_FLG(FLG_SPELLBOOKS))
2407 body_str = "ËâË¡½ñ";
2408 else if (IS_FLG(FLG_HAFTED))
2410 else if (IS_FLG(FLG_SHIELDS))
2412 else if (IS_FLG(FLG_BOWS))
2413 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2414 else if (IS_FLG(FLG_RINGS))
2416 else if (IS_FLG(FLG_AMULETS))
2417 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2418 else if (IS_FLG(FLG_SUITS))
2420 else if (IS_FLG(FLG_CLOAKS))
2421 body_str = "¥¯¥í¡¼¥¯";
2422 else if (IS_FLG(FLG_HELMS))
2423 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2424 else if (IS_FLG(FLG_GLOVES))
2426 else if (IS_FLG(FLG_BOOTS))
2427 body_str = "¥Ö¡¼¥Ä";
2431 strcat(buff, "Á´¤Æ¤Î");
2432 else for (i = 0; i < before_n && before_str[i]; i++)
2433 strcat(buff, before_str[i]);
2435 strcat(buff, body_str);
2445 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2446 strncat(buff, str, 80);
2448 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2450 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2455 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2457 if (my_strstr(insc, "%%all"))
2458 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2459 else if (my_strstr(insc, "%all"))
2460 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2461 else if (my_strstr(insc, "%%"))
2462 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2463 else if (my_strstr(insc, "%"))
2464 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2466 strcat(buff, "¤È¹ï¤ó¤Ç");
2471 if (act & DONT_AUTOPICK)
2472 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2473 else if (act & DO_AUTODESTROY)
2474 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2475 else if (act & DO_QUERY_AUTOPICK)
2476 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2478 strcat(buff, "½¦¤¦¡£");
2480 if (act & DO_DISPLAY)
2482 if (act & DONT_AUTOPICK)
2483 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2484 else if (act & DO_AUTODESTROY)
2485 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2487 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2490 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2494 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2495 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2499 /*** Collecting items ***/
2500 /*** Which can be absorbed into a slot as a bundle ***/
2501 if (IS_FLG(FLG_COLLECTING))
2502 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2504 /*** Unaware items ***/
2505 if (IS_FLG(FLG_UNAWARE))
2507 before_str[before_n++] = "unidentified";
2508 whose_str[whose_n++] = "basic abilities are not known";
2511 /*** Unidentified ***/
2512 if (IS_FLG(FLG_UNIDENTIFIED))
2513 before_str[before_n++] = "unidentified";
2515 /*** Identified ***/
2516 if (IS_FLG(FLG_IDENTIFIED))
2517 before_str[before_n++] = "identified";
2519 /*** *Identified* ***/
2520 if (IS_FLG(FLG_STAR_IDENTIFIED))
2521 before_str[before_n++] = "fully identified";
2523 /*** Rare equpiments ***/
2524 if (IS_FLG(FLG_RARE))
2526 before_str[before_n++] = "very rare";
2527 body_str = "equipments";
2528 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2531 /*** Common equpiments ***/
2532 if (IS_FLG(FLG_COMMON))
2534 before_str[before_n++] = "relatively common";
2535 body_str = "equipments";
2536 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2539 /*** Worthless items ***/
2540 if (IS_FLG(FLG_WORTHLESS))
2542 before_str[before_n++] = "worthless";
2543 which_str[which_n++] = "can not be sold at stores";
2547 if (IS_FLG(FLG_ARTIFACT))
2549 before_str[before_n++] = "artifact";
2553 if (IS_FLG(FLG_EGO))
2555 before_str[before_n++] = "ego";
2559 if (IS_FLG(FLG_NAMELESS))
2561 body_str = "equipment";
2562 which_str[which_n++] = "is neither ego-item nor artifact";
2565 /*** Dice boosted (weapon of slaying) ***/
2566 if (IS_FLG(FLG_BOOSTED))
2568 body_str = "weapons";
2569 whose_str[whose_n++] = "damage dice is bigger than normal";
2572 /*** Weapons whose dd*ds is more than nn ***/
2573 if (IS_FLG(FLG_MORE_DICE))
2575 static char more_than_desc_str[] =
2576 "maximum damage from dice is bigger than __";
2577 body_str = "weapons";
2579 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2581 whose_str[whose_n++] = more_than_desc_str;
2584 /*** Items whose magical bonus is more than nn ***/
2585 if (IS_FLG(FLG_MORE_BONUS))
2587 static char more_bonus_desc_str[] =
2588 "magical bonus is bigger than (+__)";
2590 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2591 "%d)", entry->bonus);
2592 whose_str[whose_n++] = more_bonus_desc_str;
2595 /*** Wanted monster's corpse/skeletons ***/
2596 if (IS_FLG(FLG_WANTED))
2598 body_str = "corpse or skeletons";
2599 which_str[which_n++] = "is wanted at the Hunter's Office";
2602 /*** Human corpse/skeletons (for Daemon magic) ***/
2603 if (IS_FLG(FLG_HUMAN))
2605 before_str[before_n++] = "humanoid";
2606 body_str = "corpse or skeletons";
2607 which_str[which_n++] = "can be used for Daemon magic";
2610 /*** Unique monster's corpse/skeletons/statues ***/
2611 if (IS_FLG(FLG_UNIQUE))
2613 before_str[before_n++] = "unique monster's";
2614 body_str = "corpse or skeletons";
2617 /*** Unreadable spellbooks ***/
2618 if (IS_FLG(FLG_UNREADABLE))
2620 body_str = "spellbooks";
2621 after_str[after_n++] = "of different realms from yours";
2624 /*** First realm spellbooks ***/
2625 if (IS_FLG(FLG_REALM1))
2627 body_str = "spellbooks";
2628 after_str[after_n++] = "of your first realm";
2631 /*** Second realm spellbooks ***/
2632 if (IS_FLG(FLG_REALM2))
2634 body_str = "spellbooks";
2635 after_str[after_n++] = "of your second realm";
2638 /*** First rank spellbooks ***/
2639 if (IS_FLG(FLG_FIRST))
2641 before_str[before_n++] = "first one of four";
2642 body_str = "spellbooks";
2645 /*** Second rank spellbooks ***/
2646 if (IS_FLG(FLG_SECOND))
2648 before_str[before_n++] = "second one of four";
2649 body_str = "spellbooks";
2652 /*** Third rank spellbooks ***/
2653 if (IS_FLG(FLG_THIRD))
2655 before_str[before_n++] = "third one of four";
2656 body_str = "spellbooks";
2659 /*** Fourth rank spellbooks ***/
2660 if (IS_FLG(FLG_FOURTH))
2662 before_str[before_n++] = "fourth one of four";
2663 body_str = "spellbooks";
2667 if (IS_FLG(FLG_ITEMS))
2668 ; /* Nothing to do */
2669 else if (IS_FLG(FLG_WEAPONS))
2670 body_str = "weapons";
2671 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2672 body_str = "favorite weapons";
2673 else if (IS_FLG(FLG_ARMORS))
2674 body_str = "armors";
2675 else if (IS_FLG(FLG_MISSILES))
2676 body_str = "shots, arrows or crossbow bolts";
2677 else if (IS_FLG(FLG_DEVICES))
2678 body_str = "scrolls, wands, staves or rods";
2679 else if (IS_FLG(FLG_LIGHTS))
2680 body_str = "light sources";
2681 else if (IS_FLG(FLG_JUNKS))
2682 body_str = "junk such as broken sticks";
2683 else if (IS_FLG(FLG_CORPSES))
2684 body_str = "corpses or skeletons";
2685 else if (IS_FLG(FLG_SPELLBOOKS))
2686 body_str = "spellbooks";
2687 else if (IS_FLG(FLG_HAFTED))
2688 body_str = "hafted weapons";
2689 else if (IS_FLG(FLG_SHIELDS))
2690 body_str = "shields";
2691 else if (IS_FLG(FLG_BOWS))
2692 body_str = "slings, bows or crossbows";
2693 else if (IS_FLG(FLG_RINGS))
2695 else if (IS_FLG(FLG_AMULETS))
2696 body_str = "amulets";
2697 else if (IS_FLG(FLG_SUITS))
2698 body_str = "body armors";
2699 else if (IS_FLG(FLG_CLOAKS))
2700 body_str = "cloaks";
2701 else if (IS_FLG(FLG_HELMS))
2702 body_str = "helms or crowns";
2703 else if (IS_FLG(FLG_GLOVES))
2704 body_str = "gloves";
2705 else if (IS_FLG(FLG_BOOTS))
2708 /* Prepare a string for item name */
2715 whose_str[whose_n++] = "name is beginning with \"";
2718 which_str[which_n++] = "have \"";
2722 /* Describe action flag */
2723 if (act & DONT_AUTOPICK)
2724 strcpy(buff, "Leave on floor ");
2725 else if (act & DO_AUTODESTROY)
2726 strcpy(buff, "Destroy ");
2727 else if (act & DO_QUERY_AUTOPICK)
2728 strcpy(buff, "Ask to pick up ");
2730 strcpy(buff, "Pickup ");
2732 /* Auto-insctiption */
2735 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2737 if (my_strstr(insc, "%all"))
2738 strcat(buff, ", replacing %all with code string representing all abilities,");
2739 else if (my_strstr(insc, "%"))
2740 strcat(buff, ", replacing % with code string representing extra random abilities,");
2742 strcat(buff, " on ");
2747 strcat(buff, "all ");
2748 else for (i = 0; i < before_n && before_str[i]; i++)
2750 strcat(buff, before_str[i]);
2755 strcat(buff, body_str);
2758 for (i = 0; i < after_n && after_str[i]; i++)
2761 strcat(buff, after_str[i]);
2765 for (i = 0; i < whose_n && whose_str[i]; i++)
2768 strcat(buff, " whose ");
2770 strcat(buff, ", and ");
2772 strcat(buff, whose_str[i]);
2775 /* Item name ; whose name is beginning with "str" */
2782 /* whose ..., and which .... */
2783 if (whose_n && which_n)
2784 strcat(buff, ", and ");
2787 for (i = 0; i < which_n && which_str[i]; i++)
2790 strcat(buff, " which ");
2792 strcat(buff, ", and ");
2794 strcat(buff, which_str[i]);
2797 /* Item name ; which have "str" as part of its name */
2800 strncat(buff, str, 80);
2801 strcat(buff, "\" as part of its name");
2805 /* Describe whether it will be displayed on the full map or not */
2806 if (act & DO_DISPLAY)
2808 if (act & DONT_AUTOPICK)
2809 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2810 else if (act & DO_AUTODESTROY)
2811 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2813 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2816 strcat(buff, " Not displayed in the full map.");
2823 * Read whole lines of a file to memory
2825 static cptr *read_text_lines(cptr filename)
2827 cptr *lines_list = NULL;
2833 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2836 fff = my_fopen(buf, "r");
2840 /* Allocate list of pointers */
2841 C_MAKE(lines_list, MAX_LINES, cptr);
2844 while (0 == my_fgets(fff, buf, sizeof(buf)))
2846 lines_list[lines++] = string_make(buf);
2847 if (lines >= MAX_LINES - 1) break;
2850 lines_list[0] = string_make("");
2855 if (!fff) return NULL;
2861 * Copy the default autopick file to the user directory
2863 static void prepare_default_pickpref(void)
2865 static char *messages[] = {
2867 "¤¢¤Ê¤¿¤Ï¡Ö¼«Æ°½¦¤¤¥¨¥Ç¥£¥¿¡×¤ò½é¤á¤Æµ¯Æ°¤·¤Þ¤·¤¿¡£",
2868 "¼«Æ°½¦¤¤¤Î¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤¬¤Þ¤À½ñ¤«¤ì¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢",
2869 "´ðËÜŪ¤Ê¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤òlib/pref/picktype.prf¤«¤é¥³¥Ô¡¼¤·¤Þ¤¹¡£",
2872 "You have activated the Auto-Picker Editor for the first time.",
2873 "Since user pref file for autopick is not yet created,",
2874 "the default setting is loaded from lib/pref/pickpref.prf .",
2883 cptr filename = pickpref_filename(PT_DEFAULT);
2885 /* Display messages */
2886 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2891 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2892 user_fp = my_fopen(buf, "w");
2895 if (!user_fp) return;
2897 /* Write header messages for a notification */
2898 fprintf(user_fp, "#***\n");
2899 for (i = 0; messages[i]; i++)
2901 fprintf(user_fp, "#*** %s\n", messages[i]);
2903 fprintf(user_fp, "#***\n\n\n");
2906 /* Open the default file */
2907 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2908 pref_fp = my_fopen(buf, "r");
2917 /* Copy the contents of default file */
2918 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2919 fprintf(user_fp, "%s\n", buf);
2926 * Read an autopick prefence file to memory
2927 * Prepare default if no user file is found
2929 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2934 /* Try a filename with player name */
2935 *filename_mode_p = PT_WITH_PNAME;
2936 strcpy(buf, pickpref_filename(*filename_mode_p));
2937 lines_list = read_text_lines(buf);
2941 /* Use default name */
2942 *filename_mode_p = PT_DEFAULT;
2943 strcpy(buf, pickpref_filename(*filename_mode_p));
2944 lines_list = read_text_lines(buf);
2949 /* There is no preference file in the user directory */
2951 /* Copy the default autopick file to the user directory */
2952 prepare_default_pickpref();
2954 /* Use default name again */
2955 lines_list = read_text_lines(buf);
2960 /* Allocate list of pointers */
2961 C_MAKE(lines_list, MAX_LINES, cptr);
2962 lines_list[0] = string_make("");
2969 * Write whole lines of memory to a file.
2971 static bool write_text_lines(cptr filename, cptr *lines_list)
2978 /* Build the filename */
2979 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2982 fff = my_fopen(buf, "w");
2985 for (lines = 0; lines_list[lines]; lines++)
2986 my_fputs(fff, lines_list[lines], 1024);
2991 if (!fff) return FALSE;
2997 * Free memory of lines_list.
2999 static void free_text_lines(cptr *lines_list)
3003 for (lines = 0; lines_list[lines]; lines++)
3004 string_free(lines_list[lines]);
3006 /* free list of pointers */
3007 C_FREE((char **)lines_list, MAX_LINES, char *);
3012 * Delete or insert string
3014 static void toggle_keyword(text_body_type *tb, int flg)
3020 /* Some lines are selected */
3023 by1 = MIN(tb->my, tb->cy);
3024 by2 = MAX(tb->my, tb->cy);
3027 /* No mark -- Select current line */
3028 else /* if (!tb->mark) */
3034 /* Set/Reset flag of each line */
3035 for (y = by1; y <= by2; y++)
3037 autopick_type an_entry, *entry = &an_entry;
3039 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
3041 string_free(tb->lines_list[y]);
3045 /* Add? or Remove? */
3046 if (!IS_FLG(flg)) add = TRUE;
3049 /* No more change */
3053 /* You can use only one noun flag */
3054 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3057 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3061 /* You can use only one identify state flag */
3062 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
3065 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
3069 /* You can use only one flag in artifact/ego/nameless */
3070 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
3073 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
3077 /* You can use only one flag in rare/common */
3078 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
3081 for (i = FLG_RARE; i <= FLG_COMMON; i++)
3085 if (add) ADD_FLG(flg);
3088 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3091 tb->dirty_flags |= DIRTY_ALL;
3093 /* Text is changed */
3100 * Change command letter
3102 static void toggle_command_letter(text_body_type *tb, byte flg)
3104 autopick_type an_entry, *entry = &an_entry;
3109 /* Some lines are selected */
3112 by1 = MIN(tb->my, tb->cy);
3113 by2 = MAX(tb->my, tb->cy);
3116 /* No mark -- Select current line */
3117 else /* if (!tb->mark) */
3123 /* Set/Reset flag of each line */
3124 for (y = by1; y <= by2; y++)
3128 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3130 string_free(tb->lines_list[y]);
3134 /* Add? or Remove? */
3135 if (!(entry->action & flg)) add = TRUE;
3138 /* No more change */
3142 /* Count number of letter (by negative number) */
3143 if (entry->action & DONT_AUTOPICK) wid--;
3144 else if (entry->action & DO_AUTODESTROY) wid--;
3145 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3146 if (!(entry->action & DO_DISPLAY)) wid--;
3148 /* Set/Reset the flag */
3149 if (flg != DO_DISPLAY)
3151 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3152 if (add) entry->action |= flg;
3153 else entry->action |= DO_AUTOPICK;
3157 entry->action &= ~(DO_DISPLAY);
3158 if (add) entry->action |= flg;
3161 /* Correct cursor location */
3164 if (entry->action & DONT_AUTOPICK) wid++;
3165 else if (entry->action & DO_AUTODESTROY) wid++;
3166 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3167 if (!(entry->action & DO_DISPLAY)) wid++;
3169 if (wid > 0) tb->cx++;
3170 if (wid < 0 && tb->cx > 0) tb->cx--;
3173 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3176 tb->dirty_flags |= DIRTY_ALL;
3178 /* Text is changed */
3184 * Delete or insert string
3186 static void add_keyword(text_body_type *tb, int flg)
3190 /* Some lines are selected */
3193 by1 = MIN(tb->my, tb->cy);
3194 by2 = MAX(tb->my, tb->cy);
3197 /* No mark -- Select current line */
3198 else /* if (!tb->mark) */
3204 /* Set/Reset flag of each line */
3205 for (y = by1; y <= by2; y++)
3207 autopick_type an_entry, *entry = &an_entry;
3209 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3211 /* There is the flag already */
3214 /* Free memory for the entry */
3215 autopick_free_entry(entry);
3220 string_free(tb->lines_list[y]);
3222 /* Remove all noun flag */
3223 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3226 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3232 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3235 tb->dirty_flags |= DIRTY_ALL;
3237 /* Text is changed */
3244 * Check if this line is expression or not.
3245 * And update it if it is.
3247 static void check_expression_line(text_body_type *tb, int y)
3249 cptr s = tb->lines_list[y];
3251 if ((s[0] == '?' && s[1] == ':') ||
3252 (tb->states[y] & LSTAT_BYPASS))
3254 /* Expressions need re-evaluation */
3255 tb->dirty_flags |= DIRTY_EXPRESSION;
3261 * Insert return code and split the line
3263 static bool insert_return_code(text_body_type *tb)
3265 char buf[MAX_LINELEN];
3268 for (k = 0; tb->lines_list[k]; k++)
3269 /* count number of lines */ ;
3271 if (k >= MAX_LINES - 2) return FALSE;
3274 /* Move down lines */
3275 for (; tb->cy < k; k--)
3277 tb->lines_list[k+1] = tb->lines_list[k];
3278 tb->states[k+1] = tb->states[k];
3281 /* Split current line */
3282 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3285 if (iskanji(tb->lines_list[tb->cy][i]))
3286 buf[j++] = tb->lines_list[tb->cy][i++];
3288 buf[j++] = tb->lines_list[tb->cy][i];
3291 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3292 string_free(tb->lines_list[tb->cy]);
3293 tb->lines_list[tb->cy] = string_make(buf);
3295 /* Expressions need re-evaluation */
3296 tb->dirty_flags |= DIRTY_EXPRESSION;
3298 /* Text is changed */
3306 * Choose an item and get auto-picker entry from it.
3308 static object_type *choose_object(cptr q, cptr s)
3312 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3314 /* Get the item (in the pack) */
3315 if (item >= 0) return &inventory[item];
3317 /* Get the item (on the floor) */
3318 else return &o_list[0 - item];
3323 * Choose an item and get auto-picker entry from it.
3325 static bool entry_from_choosed_object(autopick_type *entry)
3332 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3333 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3335 q = "Enter which item? ";
3336 s = "You have nothing to enter.";
3338 o_ptr = choose_object(q, s);
3339 if (!o_ptr) return FALSE;
3341 autopick_entry_from_object(entry, o_ptr);
3347 * Choose an item for search
3349 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3351 char buf[MAX_NLEN+20];
3357 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3358 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3360 q = "Enter which item? ";
3361 s = "You have nothing to enter.";
3363 o_ptr = choose_object(q, s);
3364 if (!o_ptr) return 0;
3368 string_free(*search_strp);
3369 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3370 *search_strp = string_make(format("<%s>", buf));
3376 * Prepare for search by destroyed object
3378 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3380 char buf[MAX_NLEN+20];
3382 if (!autopick_last_destroyed_object.k_idx) return 0;
3384 *o_handle = &autopick_last_destroyed_object;
3386 string_free(*search_strp);
3387 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3388 *search_strp = string_make(format("<%s>", buf));
3394 * Choose an item or string for search
3396 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3402 * TERM_YELLOW : Overwrite mode
3403 * TERM_WHITE : Insert mode
3405 byte color = TERM_YELLOW;
3406 char buf[MAX_NLEN+20];
3410 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3412 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3414 int col = sizeof(prompt) - 1;
3416 /* Prepare string buffer for edit */
3417 if (*search_strp) strcpy(buf, *search_strp);
3420 /* Object searching mode */
3423 color = TERM_L_GREEN;
3426 /* Display prompt */
3436 /* Display the string */
3437 Term_erase(col, 0, 255);
3438 Term_putstr(col, 0, -1, color, buf);
3441 Term_gotoxy(col + pos, 0);
3443 /* Get a special key code */
3444 skey = inkey_special(TRUE);
3446 /* Analyze the key */
3454 /* Now on insert mode */
3457 /* No move at beginning of line */
3458 if (0 == pos) break;
3462 int next_pos = i + 1;
3465 if (iskanji(buf[i])) next_pos++;
3468 /* Is there the cursor at next position? */
3469 if (next_pos >= pos) break;
3475 /* Get previous position */
3483 /* Now on insert mode */
3486 /* No move at end of line */
3487 if ('\0' == buf[pos]) break;
3491 if (iskanji(buf[pos])) pos += 2;
3509 if (*o_handle) return (back ? -1 : 1);
3510 string_free(*search_strp);
3511 *search_strp = string_make(buf);
3513 return (back ? -1 : 1);
3517 return get_object_for_search(o_handle, search_strp);
3520 /* Prepare string for destroyed object if there is one. */
3521 if (get_destroyed_object_for_search(o_handle, search_strp))
3531 /* Now on insert mode */
3534 /* No move at beginning of line */
3535 if (0 == pos) break;
3539 int next_pos = i + 1;
3542 if (iskanji(buf[i])) next_pos++;
3545 /* Is there the cursor at next position? */
3546 if (next_pos >= pos) break;
3552 /* Get previous position */
3555 /* Fall through to 'Delete key' */
3564 /* Now on insert mode */
3567 /* No move at end of line */
3568 if ('\0' == buf[pos]) break;
3570 /* Position of next character */
3574 /* Next character is one more byte away */
3575 if (iskanji(buf[pos])) src++;
3580 /* Move characters at src to dst */
3581 while ('\0' != (buf[dst++] = buf[src++]))
3589 /* Insert a character */
3594 /* Ignore special keys */
3595 if (skey & SKEY_MASK) break;
3597 /* Get a character code */
3600 /* Was non insert mode? */
3601 if (color != TERM_WHITE)
3603 /* Was object searching mode */
3604 if (color == TERM_L_GREEN)
3606 /* Cancel the mode */
3609 /* Remove indicating string */
3610 string_free(*search_strp);
3611 *search_strp = NULL;
3614 /* Overwrite default string */
3617 /* Go to insert mode */
3621 /* Save right part of string */
3622 strcpy(tmp, buf + pos);
3628 /* Bypass macro processing */
3646 if (pos < len && (isprint(c) || iskana(c)))
3648 if (pos < len && isprint(c))
3662 /* Write back the left part of string */
3663 my_strcat(buf, tmp, len + 1);
3670 /* Object searching mode was cancelled? */
3671 if (*o_handle && color != TERM_L_GREEN)
3673 /* Cancel the mode */
3676 /* Remove indicating string */
3678 string_free(*search_strp);
3679 *search_strp = NULL;
3684 } /* while (TRUE) */
3689 * Search next line matches for o_ptr
3691 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3693 autopick_type an_entry, *entry = &an_entry;
3694 char o_name[MAX_NLEN];
3695 int bypassed_cy = -1;
3697 /* Start searching from current cursor position */
3700 /* Prepare object name string first */
3701 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3703 /* Convert the string to lower case */
3704 str_tolower(o_name);
3711 if (!tb->lines_list[++i]) break;
3718 /* Is this line is a correct entry? */
3719 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3721 /* Does this line match to the object? */
3722 if (!is_autopick_aux(o_ptr, entry, o_name)) continue;
3725 /* Found a line but it's inactive */
3726 if (tb->states[i] & LSTAT_BYPASS)
3728 /* If it is first found, remember it */
3729 if (bypassed_cy == -1) bypassed_cy = i;
3732 /* Found an active line! */
3735 /* Move to this line */
3739 if (bypassed_cy != -1)
3741 /* Mark as some lines are skipped */
3742 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3750 if (bypassed_cy != -1)
3752 /* Move to the remembered line */
3754 tb->cy = bypassed_cy;
3756 /* Mark as this line is inactive */
3757 tb->dirty_flags |= DIRTY_INACTIVE;
3762 /* Mark as NOT FOUND */
3763 tb->dirty_flags |= DIRTY_NOT_FOUND;
3771 * Search next line matches to the string
3773 static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
3775 int bypassed_cy = -1;
3776 int bypassed_cx = 0;
3778 /* Start searching from current cursor position */
3788 if (!tb->lines_list[++i]) break;
3795 /* Look for the string pattern */
3796 pos = my_strstr(tb->lines_list[i], search_str);
3801 /* Found a line but it's inactive */
3802 if ((tb->states[i] & LSTAT_BYPASS) &&
3803 !(tb->states[i] & LSTAT_EXPRESSION))
3805 /* If it is first found, remember it */
3806 if (bypassed_cy == -1)
3809 bypassed_cx = (int)(pos - tb->lines_list[i]);
3813 /* Found an active line! */
3816 /* Move to this location */
3817 tb->cx = (int)(pos - tb->lines_list[i]);
3820 if (bypassed_cy != -1)
3822 /* Mark as some lines are skipped */
3823 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3831 if (bypassed_cy != -1)
3833 /* Move to the remembered line */
3834 tb->cx = bypassed_cx;
3835 tb->cy = bypassed_cy;
3837 /* Mark as this line is inactive */
3838 tb->dirty_flags |= DIRTY_INACTIVE;
3843 /* Mark as NOT FOUND */
3844 tb->dirty_flags |= DIRTY_NOT_FOUND;
3854 * Editor command id's
3857 #define EC_SAVEQUIT 2
3868 #define EC_PGDOWN 13
3870 #define EC_BOTTOM 15
3875 #define EC_KILL_LINE 20
3876 #define EC_DELETE_CHAR 21
3877 #define EC_BACKSPACE 22
3878 #define EC_SEARCH_STR 23
3879 #define EC_SEARCH_FORW 24
3880 #define EC_SEARCH_BACK 25
3881 #define EC_SEARCH_OBJ 26
3882 #define EC_SEARCH_DESTROYED 27
3883 #define EC_INSERT_OBJECT 28
3884 #define EC_INSERT_DESTROYED 29
3885 #define EC_INSERT_BLOCK 30
3886 #define EC_INSERT_MACRO 31
3887 #define EC_INSERT_KEYMAP 32
3888 #define EC_CL_AUTOPICK 33
3889 #define EC_CL_DESTROY 34
3890 #define EC_CL_LEAVE 35
3891 #define EC_CL_QUERY 36
3892 #define EC_CL_NO_DISP 37
3893 #define EC_OK_COLLECTING 38
3894 #define EC_IK_UNAWARE 39
3895 #define EC_IK_UNIDENTIFIED 40
3896 #define EC_IK_IDENTIFIED 41
3897 #define EC_IK_STAR_IDENTIFIED 42
3898 #define EC_OK_BOOSTED 43
3899 #define EC_OK_MORE_DICE 44
3900 #define EC_OK_MORE_BONUS 45
3901 #define EC_OK_WORTHLESS 46
3902 #define EC_OK_ARTIFACT 47
3903 #define EC_OK_EGO 48
3904 #define EC_OK_NAMELESS 49
3905 #define EC_OK_RARE 50
3906 #define EC_OK_COMMON 51
3907 #define EC_OK_WANTED 52
3908 #define EC_OK_UNIQUE 53
3909 #define EC_OK_HUMAN 54
3910 #define EC_OK_UNREADABLE 55
3911 #define EC_OK_REALM1 56
3912 #define EC_OK_REALM2 57
3913 #define EC_OK_FIRST 58
3914 #define EC_OK_SECOND 59
3915 #define EC_OK_THIRD 60
3916 #define EC_OK_FOURTH 61
3917 #define EC_KK_WEAPONS 62
3918 #define EC_KK_FAVORITE_WEAPONS 63
3919 #define EC_KK_ARMORS 64
3920 #define EC_KK_MISSILES 65
3921 #define EC_KK_DEVICES 66
3922 #define EC_KK_LIGHTS 67
3923 #define EC_KK_JUNKS 68
3924 #define EC_KK_CORPSES 69
3925 #define EC_KK_SPELLBOOKS 70
3926 #define EC_KK_SHIELDS 71
3927 #define EC_KK_BOWS 72
3928 #define EC_KK_RINGS 73
3929 #define EC_KK_AMULETS 74
3930 #define EC_KK_SUITS 75
3931 #define EC_KK_CLOAKS 76
3932 #define EC_KK_HELMS 77
3933 #define EC_KK_GLOVES 78
3934 #define EC_KK_BOOTS 79
3940 static char MN_QUIT[] = "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»";
3941 static char MN_SAVEQUIT[] = "¥»¡¼¥Ö¤·¤Æ½ªÎ»";
3942 static char MN_REVERT[] = "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ";
3943 static char MN_HELP[] = "¥Ø¥ë¥×";
3945 static char MN_MOVE[] = "¥«¡¼¥½¥ë°ÜÆ°";
3946 static char MN_LEFT[] = "º¸ (¢«Ìð°õ¥¡¼)";
3947 static char MN_DOWN[] = "²¼ (¢Ìð°õ¥¡¼)";
3948 static char MN_UP[] = "¾å (¢¬Ìð°õ¥¡¼)";
3949 static char MN_RIGHT[] = "±¦ (¢ªÌð°õ¥¡¼)";
3950 static char MN_BOL[] = "¹Ô¤ÎÀèƬ";
3951 static char MN_EOL[] = "¹Ô¤Î½ªÃ¼";
3952 static char MN_PGUP[] = "¾å¤Î¥Ú¡¼¥¸ (PageUp¥¡¼)";
3953 static char MN_PGDOWN[] = "²¼¤Î¥Ú¡¼¥¸ (PageDown¥¡¼)";
3954 static char MN_TOP[] = "1¹ÔÌܤذÜÆ° (Home¥¡¼)";
3955 static char MN_BOTTOM[] = "ºÇ²¼¹Ô¤Ø°ÜÆ°(End¥¡¼)";
3957 static char MN_EDIT[] = "ÊÔ½¸";
3958 static char MN_CUT[] = "¥«¥Ã¥È";
3959 static char MN_COPY[] = "¥³¥Ô¡¼";
3960 static char MN_PASTE[] = "¥Ú¡¼¥¹¥È";
3961 static char MN_BLOCK[] = "ÁªÂòÈϰϤλØÄê";
3962 static char MN_KILL_LINE[] = "¹Ô¤Î»Ä¤ê¤òºï½ü";
3963 static char MN_DELETE_CHAR[] = "1ʸ»úºï½ü";
3964 static char MN_BACKSPACE[] = "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹";
3965 static char MN_RETURN[] = "²þ¹Ô";
3967 static char MN_SEARCH[] = "¸¡º÷";
3968 static char MN_SEARCH_STR[] = "ʸ»úÎó¤Ç¸¡º÷";
3969 static char MN_SEARCH_FORW[] = "Á°Êý¤ØºÆ¸¡º÷";
3970 static char MN_SEARCH_BACK[] = "¸åÊý¤ØºÆ¸¡º÷";
3971 static char MN_SEARCH_OBJ[] = "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷";
3972 static char MN_SEARCH_DESTROYED[] = "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷";
3974 static char MN_INSERT[] = "¿§¡¹ÁÞÆþ";
3975 static char MN_INSERT_OBJECT[] = "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ";
3976 static char MN_INSERT_DESTROYED[] = "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ";
3977 static char MN_INSERT_BLOCK[] = "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ";
3978 static char MN_INSERT_MACRO[] = "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ";
3979 static char MN_INSERT_KEYMAP[] = "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ";
3981 static char MN_COMMAND_LETTER[] = "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò";
3982 static char MN_CL_AUTOPICK[] = "¡Ö ¡× (¼«Æ°½¦¤¤)";
3983 static char MN_CL_DESTROY[] = "¡Ö!¡× (¼«Æ°Ç˲õ)";
3984 static char MN_CL_LEAVE[] = "¡Ö~¡× (ÊüÃÖ)";
3985 static char MN_CL_QUERY[] = "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)";
3986 static char MN_CL_NO_DISP[] = "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)";
3988 static char MN_ADJECTIVE_GEN[] = "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò";
3990 static char MN_ADJECTIVE_SPECIAL[] = "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò";
3991 static char MN_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)";
3992 static char MN_MORE_DICE[] = "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)";
3993 static char MN_MORE_BONUS[] = "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)";
3994 static char MN_ARTIFACT[] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)";
3995 static char MN_EGO[] = "¥¨¥´ (ÁõÈ÷)";
3996 static char MN_NAMELESS[] = "̵ÌäΠ(ÁõÈ÷)";
3997 static char MN_RARE[] = "¥ì¥¢¤Ê (ÁõÈ÷)";
3998 static char MN_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿ (ÁõÈ÷)";
3999 static char MN_WANTED[] = "¾Þ¶â¼ó¤Î (»àÂÎ)";
4000 static char MN_UNIQUE[] = "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)";
4001 static char MN_HUMAN[] = "¿Í´Ö¤Î (»àÂÎ)";
4002 static char MN_UNREADABLE[] = "Æɤá¤Ê¤¤ (ËâË¡½ñ)";
4003 static char MN_REALM1[] = "Âè°ìÎΰè¤Î (ËâË¡½ñ)";
4004 static char MN_REALM2[] = "ÂèÆóÎΰè¤Î (ËâË¡½ñ)";
4005 static char MN_FIRST[] = "1ºýÌܤΠ(ËâË¡½ñ)";
4006 static char MN_SECOND[] = "2ºýÌܤΠ(ËâË¡½ñ)";
4007 static char MN_THIRD[] = "3ºýÌܤΠ(ËâË¡½ñ)";
4008 static char MN_FOURTH[] = "4ºýÌܤΠ(ËâË¡½ñ)";
4010 static char MN_NOUN[] = "̾»ì¤ÎÁªÂò";
4014 static char MN_QUIT[] = "Quit without save";
4015 static char MN_SAVEQUIT[] = "Save & Quit";
4016 static char MN_REVERT[] = "Revert all changes";
4017 static char MN_HELP[] = "Help";
4019 static char MN_MOVE[] = "Move cursor";
4020 static char MN_LEFT[] = "Left (Left Arrow key)";
4021 static char MN_DOWN[] = "Down (Down Arrow key)";
4022 static char MN_UP[] = "Up (Up Arrow key)";
4023 static char MN_RIGHT[] = "Right (Right Arrow key)";
4024 static char MN_BOL[] = "Beggining of line";
4025 static char MN_EOL[] = "End of line";
4026 static char MN_PGUP[] = "Page up (PageUp key)";
4027 static char MN_PGDOWN[] = "Page down(PageDown key)";
4028 static char MN_TOP[] = "Top (Home key)";
4029 static char MN_BOTTOM[] = "Bottom (End key)";
4031 static char MN_EDIT[] = "Edit";
4032 static char MN_CUT[] = "Cut";
4033 static char MN_COPY[] = "Copy";
4034 static char MN_PASTE[] = "Paste";
4035 static char MN_BLOCK[] = "Select block";
4036 static char MN_KILL_LINE[] = "Kill rest of line";
4037 static char MN_DELETE_CHAR[] = "Delete character";
4038 static char MN_BACKSPACE[] = "Backspace";
4039 static char MN_RETURN[] = "Return";
4041 static char MN_SEARCH[] = "Search";
4042 static char MN_SEARCH_STR[] = "Search by string";
4043 static char MN_SEARCH_FORW[] = "Search forward";
4044 static char MN_SEARCH_BACK[] = "Search backward";
4045 static char MN_SEARCH_OBJ[] = "Search by inventory object";
4046 static char MN_SEARCH_DESTROYED[] = "Search by destroyed object";
4048 static char MN_INSERT[] = "Insert...";
4049 static char MN_INSERT_OBJECT[] = "Insert name of choosen object";
4050 static char MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
4051 static char MN_INSERT_BLOCK[] = "Insert conditional block";
4052 static char MN_INSERT_MACRO[] = "Insert a macro definition";
4053 static char MN_INSERT_KEYMAP[] = "Insert a keymap definition";
4055 static char MN_COMMAND_LETTER[] = "Command letter";
4056 static char MN_CL_AUTOPICK[] = "' ' (Auto pick)";
4057 static char MN_CL_DESTROY[] = "'!' (Auto destroy)";
4058 static char MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
4059 static char MN_CL_QUERY[] = "';' (Query to pick up)";
4060 static char MN_CL_NO_DISP[] = "'(' (No display on the large map)";
4062 static char MN_ADJECTIVE_GEN[] = "Adjective (general)";
4064 static char MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
4065 static char MN_BOOSTED[] = "dice boosted (weapons)";
4066 static char MN_MORE_DICE[] = "more than # dice (weapons)";
4067 static char MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
4068 static char MN_ARTIFACT[] = "artifact (equipments)";
4069 static char MN_EGO[] = "ego (equipments)";
4070 static char MN_NAMELESS[] = "nameless (equipments)";
4071 static char MN_RARE[] = "rare (equipments)";
4072 static char MN_COMMON[] = "common (equipments)";
4073 static char MN_WANTED[] = "wanted (corpse)";
4074 static char MN_UNIQUE[] = "unique (corpse)";
4075 static char MN_HUMAN[] = "human (corpse)";
4076 static char MN_UNREADABLE[] = "unreadable (spellbooks)";
4077 static char MN_REALM1[] = "realm1 (spellbooks)";
4078 static char MN_REALM2[] = "realm2 (spellbooks)";
4079 static char MN_FIRST[] = "first (spellbooks)";
4080 static char MN_SECOND[] = "second (spellbooks)";
4081 static char MN_THIRD[] = "third (spellbooks)";
4082 static char MN_FOURTH[] = "fourth (spellbooks)";
4084 static char MN_NOUN[] = "Keywords (noun)";
4094 } command_menu_type;
4097 command_menu_type menu_data[] =
4099 {MN_HELP, 0, -1, EC_HELP},
4100 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4101 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4102 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4104 {MN_EDIT, 0, -1, -1},
4105 {MN_CUT, 1, KTRL('x'), EC_CUT},
4106 {MN_COPY, 1, KTRL('c'), EC_COPY},
4107 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4108 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4109 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4110 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4111 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4112 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4113 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4115 {MN_SEARCH, 0, -1, -1},
4116 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4117 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4118 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4119 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4120 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4122 {MN_MOVE, 0, -1, -1},
4123 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4124 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4125 {MN_UP, 1, KTRL('p'), EC_UP},
4126 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4127 {MN_BOL, 1, KTRL('a'), EC_BOL},
4128 {MN_EOL, 1, KTRL('e'), EC_EOL},
4129 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4130 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4131 {MN_TOP, 1, KTRL('t'), EC_TOP},
4132 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4134 {MN_INSERT, 0, -1, -1},
4135 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4136 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4137 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4138 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4139 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4141 {MN_ADJECTIVE_GEN, 0, -1, -1},
4142 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4143 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4144 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4145 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4146 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4147 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4149 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4150 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4151 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4152 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4153 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4154 {MN_EGO, 1, -1, EC_OK_EGO},
4155 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
4156 {MN_RARE, 1, -1, EC_OK_RARE},
4157 {MN_COMMON, 1, -1, EC_OK_COMMON},
4158 {MN_WANTED, 1, -1, EC_OK_WANTED},
4159 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4160 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4161 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4162 {MN_REALM1, 1, -1, EC_OK_REALM1},
4163 {MN_REALM2, 1, -1, EC_OK_REALM2},
4164 {MN_FIRST, 1, -1, EC_OK_FIRST},
4165 {MN_SECOND, 1, -1, EC_OK_SECOND},
4166 {MN_THIRD, 1, -1, EC_OK_THIRD},
4167 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4169 {MN_NOUN, 0, -1, -1},
4170 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4171 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4172 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4173 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4174 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4175 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4176 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4177 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4178 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4179 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4180 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4181 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4182 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4183 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4184 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4185 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4186 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4187 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4189 {MN_COMMAND_LETTER, 0, -1, -1},
4190 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4191 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4192 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4193 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4194 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4196 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4203 * Find a command by 'key'.
4205 static int get_com_id(char key)
4209 for (i = 0; menu_data[i].name; i++)
4211 if (menu_data[i].key == key)
4213 return menu_data[i].com_id;
4222 * Display the menu, and get a command
4224 static int do_command_menu(int level, int start)
4229 int col0 = 5 + level*7;
4230 int row0 = 1 + level*3;
4232 int menu_id_list[26];
4234 char linestr[MAX_LINELEN];
4236 /* Get max length */
4238 for (i = start; menu_data[i].level >= level; i++)
4242 /* Ignore lower level sub menus */
4243 if (menu_data[i].level > level) continue;
4245 len = strlen(menu_data[i].name);
4246 if (len > max_len) max_len = len;
4248 menu_id_list[menu_key] = i;
4252 while (menu_key < 26)
4254 menu_id_list[menu_key] = -1;
4258 /* Extra space for displaying menu key and command key */
4259 max_menu_wid = max_len + 3 + 3;
4261 /* Prepare box line */
4263 strcat(linestr, "+");
4264 for (i = 0; i < max_menu_wid + 2; i++)
4266 strcat(linestr, "-");
4268 strcat(linestr, "+");
4278 int row1 = row0 + 1;
4281 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4283 /* Draw menu items */
4285 for (i = start; menu_data[i].level >= level; i++)
4287 char com_key_str[3];
4290 /* Ignore lower level sub menus */
4291 if (menu_data[i].level > level) continue;
4293 if (menu_data[i].com_id == -1)
4296 strcpy(com_key_str, "¢§");
4298 strcpy(com_key_str, ">");
4301 else if (menu_data[i].key != -1)
4303 com_key_str[0] = '^';
4304 com_key_str[1] = menu_data[i].key + '@';
4305 com_key_str[2] = '\0';
4309 com_key_str[0] = '\0';
4312 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4314 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4319 /* Draw bottom line */
4320 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4322 /* The menu was shown */
4326 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
4328 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
4332 if (key == ESCAPE) return 0;
4334 if ('a' <= key && key <= 'z')
4336 menu_id = menu_id_list[key - 'a'];
4340 com_id = menu_data[menu_id].com_id;
4344 com_id = do_command_menu(level + 1, menu_id + 1);
4346 if (com_id) return com_id;
4358 com_id = get_com_id(key);
4359 if (com_id) return com_id;
4366 static chain_str_type *new_chain_str(cptr str)
4368 chain_str_type *chain;
4370 size_t len = strlen(str);
4372 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4374 strcpy(chain->s, str);
4381 static void kill_yank_chain(text_body_type *tb)
4383 chain_str_type *chain = tb->yank;
4385 tb->yank_eol = TRUE;
4389 chain_str_type *next = chain->next;
4390 size_t len = strlen(chain->s);
4392 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4399 static void add_str_to_yank(text_body_type *tb, cptr str)
4401 chain_str_type *chain;
4403 tb->yank_eol = FALSE;
4405 if (NULL == tb->yank)
4407 tb->yank = new_chain_str(str);
4417 chain->next = new_chain_str(str);
4422 chain = chain->next;
4427 #define DESCRIPT_HGT 3
4432 static void draw_text_editor(text_body_type *tb)
4435 int by1 = 0, by2 = 0;
4438 Term_get_size(&tb->wid, &tb->hgt);
4441 * Top line (-1), description line (-3), separator (-1)
4444 tb->hgt -= 2 + DESCRIPT_HGT;
4447 /* Don't let cursor at second byte of kanji */
4448 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4449 if (iskanji(tb->lines_list[tb->cy][i]))
4460 /* Scroll if necessary */
4461 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4462 tb->upper = tb->cy - (tb->hgt)/2;
4465 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4466 tb->left = tb->cx - (tb->wid)*2/3;
4470 /* Redraw whole window after resize */
4471 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4472 tb->dirty_flags |= DIRTY_SCREEN;
4474 /* Redraw all text after scroll */
4475 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4476 tb->dirty_flags |= DIRTY_ALL;
4479 if (tb->dirty_flags & DIRTY_SCREEN)
4481 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4487 /* Redraw mode line */
4488 if (tb->dirty_flags & DIRTY_MODE)
4490 char buf[MAX_LINELEN];
4492 int sepa_length = tb->wid;
4495 for (i = 0; i < sepa_length; i++)
4499 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4502 if (tb->dirty_flags & DIRTY_EXPRESSION)
4507 for (y = 0; tb->lines_list[y]; y++)
4511 cptr s = tb->lines_list[y];
4513 /* Update this line's state */
4514 tb->states[y] = state;
4516 if (*s++ != '?') continue;
4517 if (*s++ != ':') continue;
4519 /* Lines below this line are auto-registered */
4520 if (streq(s, "$AUTOREGISTER"))
4521 state |= LSTAT_AUTOREGISTER;
4523 /* Parse the expr */
4524 v = process_pref_file_expr(&s, &f);
4527 if (streq(v, "0")) state |= LSTAT_BYPASS;
4528 else state &= ~LSTAT_BYPASS;
4530 /* Re-update this line's state */
4531 tb->states[y] = state | LSTAT_EXPRESSION;
4534 tb->dirty_flags |= DIRTY_ALL;
4539 int tmp_cx = tb->cx;
4540 int len = strlen(tb->lines_list[tb->cy]);
4542 /* Correct cursor location */
4543 if (tb->cx > len) tmp_cx = len;
4545 tb->dirty_flags |= DIRTY_ALL;
4547 by1 = MIN(tb->my, tb->cy);
4548 by2 = MAX(tb->my, tb->cy);
4551 /* Dump up to tb->hgt lines of messages */
4552 for (i = 0; i < tb->hgt; i++)
4558 int y = tb->upper+i;
4560 /* clean or dirty? */
4561 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4564 msg = tb->lines_list[y];
4567 /* Apply horizontal scroll */
4568 for (j = 0; *msg; msg++, j++)
4570 if (j == tb->left) break;
4586 Term_erase(0, i + 1, tb->wid);
4588 if (tb->states[y] & LSTAT_AUTOREGISTER)
4590 /* Warning color -- These lines will be deleted later */
4595 /* Bypassed line will be displayed by darker color */
4596 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4597 else color = TERM_WHITE;
4600 /* No mark or Out of mark */
4601 if (!tb->mark || (y < by1 || by2 < y))
4603 /* Dump the messages, bottom to top */
4604 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4607 /* Multiple lines selected */
4608 else if (by1 != by2)
4610 /* Dump the messages, bottom to top */
4611 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4614 /* Single line selected */
4617 int x0 = leftcol + tb->left;
4618 int len = strlen(tb->lines_list[tb->cy]);
4619 int bx1 = MIN(tb->mx, tb->cx);
4620 int bx2 = MAX(tb->mx, tb->cx);
4622 /* Correct cursor location */
4623 if (bx2 > len) bx2 = len;
4625 Term_gotoxy(leftcol, i + 1);
4626 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4627 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4628 Term_addstr(-1, color, msg + (bx2 - x0));
4632 for (; i < tb->hgt; i++)
4635 Term_erase(0, i + 1, tb->wid);
4638 /* Display information when updated */
4639 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4641 autopick_type an_entry, *entry = &an_entry;
4642 cptr str1 = NULL, str2 = NULL;
4645 /* Clear information line */
4646 for (i = 0; i < DESCRIPT_HGT; i++)
4649 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4652 /* Display information */
4653 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4656 str1 = format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str);
4658 str1 = format("Pattern not found: %s", tb->search_str);
4661 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4664 str1 = format("̵¸ú¾õÂ֤ιԤò¥¹¥¥Ã¥×¤·¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4666 str1 = format("Some inactive lines are skipped. (Searching %s)", tb->search_str);
4669 else if (tb->dirty_flags & DIRTY_INACTIVE)
4672 str1 = format("̵¸ú¾õÂ֤ιԤÀ¤±¤¬¸«ÉÕ¤«¤ê¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4674 str1 = format("Found only an inactive line. (Searching %s)", tb->search_str);
4677 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4680 str1 = "¸¡º÷¤¹¤ë¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó(^S ¤Ç¸¡º÷)¡£";
4682 str1 = "No pattern to search. (Press ^S to search.)";
4685 else if (tb->lines_list[tb->cy][0] == '#')
4688 str1 = "¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£";
4690 str1 = "This line is a comment.";
4693 else if (tb->lines_list[tb->cy][1] == ':')
4695 switch(tb->lines_list[tb->cy][0])
4699 str1 = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4701 str1 = "This line is a Conditional Expression.";
4707 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4709 str1 = "This line defines a Macro action.";
4714 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4716 str1 = "This line defines a Macro trigger key.";
4721 str1 = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4723 str1 = "This line defines a Keymap.";
4728 switch(tb->lines_list[tb->cy][0])
4731 if (tb->states[tb->cy] & LSTAT_BYPASS)
4734 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4736 str2 = "The expression is 'False'(=0) currently.";
4742 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4744 str2 = "The expression is 'True'(=1) currently.";
4750 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4753 str2 = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4755 str2 = "This line will be delete later.";
4759 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4762 str2 = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4764 str2 = "This line is bypassed currently.";
4771 /* Get description of an autopicker preference line */
4772 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4774 char buf[MAX_LINELEN];
4775 char temp[MAX_LINELEN];
4778 describe_autopick(buf, entry);
4780 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4783 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4785 strcat(buf, " This line will be delete later.");
4789 if (tb->states[tb->cy] & LSTAT_BYPASS)
4792 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4794 strcat(buf, " This line is bypassed currently.");
4798 roff_to_buf(buf, 81, temp, sizeof(temp));
4800 for (i = 0; i < 3; i++)
4806 prt(t, tb->hgt +1 + 1 + i, 0);
4810 autopick_free_entry(entry);
4813 /* Draw the first line */
4814 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4816 /* Draw the second line */
4817 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4823 * Kill segment of a line
4825 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4827 char buf[MAX_LINELEN];
4828 cptr s = tb->lines_list[y];
4832 /* Kill whole line? */
4833 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4837 string_free(tb->lines_list[y]);
4839 /* Shift lines up */
4840 for (i = y; tb->lines_list[i+1]; i++)
4841 tb->lines_list[i] = tb->lines_list[i+1];
4842 tb->lines_list[i] = NULL;
4844 /* Expressions need re-evaluation */
4845 tb->dirty_flags |= DIRTY_EXPRESSION;
4851 if (x0 == x1) return;
4853 /* Before the segment */
4854 for (x = 0; x < x0; x++)
4857 /* After the segment */
4858 for (x = x1; s[x]; x++)
4864 string_free(tb->lines_list[y]);
4865 tb->lines_list[y] = string_make(buf);
4867 /* Expressions may need re-evaluation */
4868 check_expression_line(tb, y);
4870 /* Text is changed */
4876 * Get a trigger key and insert ASCII string for the trigger
4878 static bool insert_macro_line(text_body_type *tb)
4887 /* Do not process macros */
4893 /* Read the pattern */
4899 /* Do not process macros */
4902 /* Do not wait for keys */
4905 /* Attempt to read a key */
4915 /* Convert the trigger */
4916 ascii_to_text(tmp, buf);
4919 if(!tmp[0]) return FALSE;
4923 /* Insert preference string */
4924 insert_return_code(tb);
4925 string_free(tb->lines_list[tb->cy]);
4926 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4928 /* Acquire action */
4929 i = macro_find_exact(buf);
4933 /* Nothing defined */
4938 /* Analyze the current action */
4939 ascii_to_text(tmp, macro__act[i]);
4942 /* Insert blank action preference line */
4943 insert_return_code(tb);
4944 string_free(tb->lines_list[tb->cy]);
4945 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4952 * Get a command key and insert ASCII string for the key
4954 static bool insert_keymap_line(text_body_type *tb)
4962 if (rogue_like_commands)
4964 mode = KEYMAP_MODE_ROGUE;
4970 mode = KEYMAP_MODE_ORIG;
4983 /* Convert the trigger */
4984 ascii_to_text(tmp, buf);
4987 if(!tmp[0]) return FALSE;
4991 /* Insert preference string */
4992 insert_return_code(tb);
4993 string_free(tb->lines_list[tb->cy]);
4994 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4996 /* Look up the keymap */
4997 act = keymap_act[mode][(byte)(buf[0])];
4999 /* Insert blank action preference line */
5000 insert_return_code(tb);
5001 string_free(tb->lines_list[tb->cy]);
5002 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
5009 * Execute a single editor command
5011 static bool do_editor_command(text_body_type *tb, int com_id)
5019 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
5021 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
5024 return QUIT_WITHOUT_SAVE;
5027 return QUIT_AND_SAVE;
5030 /* Revert to original */
5032 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
5034 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
5037 free_text_lines(tb->lines_list);
5038 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5039 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5040 tb->cx = tb->cy = 0;
5043 /* Text is not changed */
5044 tb->changed = FALSE;
5048 /* Peruse the main help file */
5050 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
5052 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
5055 tb->dirty_flags |= DIRTY_SCREEN;
5060 /* Split a line or insert end of line */
5062 /* Ignore selection */
5068 tb->dirty_flags |= DIRTY_ALL;
5071 insert_return_code(tb);
5076 tb->dirty_flags |= DIRTY_ALL;
5086 len = strlen(tb->lines_list[tb->cy]);
5087 if (len < tb->cx) tb->cx = len;
5089 else if (tb->cy > 0)
5092 tb->cx = strlen(tb->lines_list[tb->cy]);
5098 if (tb->lines_list[tb->cy + 1]) tb->cy++;
5103 if (tb->cy > 0) tb->cy--;
5112 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5115 len = strlen(tb->lines_list[tb->cy]);
5118 if (tb->lines_list[tb->cy + 1])
5130 /* Beginning of line */
5136 tb->cx = strlen(tb->lines_list[tb->cy]);
5140 while (0 < tb->cy && tb->upper <= tb->cy)
5142 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5148 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
5158 while (tb->lines_list[tb->cy + 1])
5164 /* Copy the text first */
5165 do_editor_command(tb, EC_COPY);
5167 /* Single line case */
5168 if (tb->my == tb->cy)
5170 int bx1 = MIN(tb->mx, tb->cx);
5171 int bx2 = MAX(tb->mx, tb->cx);
5172 int len = strlen(tb->lines_list[tb->cy]);
5174 /* Correct fake cursor position */
5175 if (bx2 > len) bx2 = len;
5177 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5179 /* New cursor position */
5183 /* Multiple lines case */
5184 else /* if (tb->my != tb->cy) */
5188 int by1 = MIN(tb->my, tb->cy);
5189 int by2 = MAX(tb->my, tb->cy);
5191 /* Kill lines in reverse order */
5192 for (y = by2; y >= by1; y--)
5194 int len = strlen(tb->lines_list[y]);
5196 kill_line_segment(tb, y, 0, len, TRUE);
5199 /* New cursor position */
5205 /* Disable selection */
5209 tb->dirty_flags |= DIRTY_ALL;
5216 int len = strlen(tb->lines_list[tb->cy]);
5218 /* Correct cursor location */
5219 if (tb->cx > len) tb->cx = len;
5221 /* Use single line? */
5224 /* Select a single line */
5230 /* Kill old yank buffer */
5231 kill_yank_chain(tb);
5234 /* Single line case */
5235 if (tb->my == tb->cy)
5238 char buf[MAX_LINELEN];
5239 int bx1 = MIN(tb->mx, tb->cx);
5240 int bx2 = MAX(tb->mx, tb->cx);
5242 /* Correct fake cursor position */
5243 if (bx2 > len) bx2 = len;
5245 /* Whole part of this line is selected */
5246 if (bx1 == 0 && bx2 == len)
5248 /* Copy this line */
5249 add_str_to_yank(tb, tb->lines_list[tb->cy]);
5251 /* Add end of line to the buffer */
5252 add_str_to_yank(tb, "");
5255 /* Segment of this line is selected */
5258 for (i = 0; i < bx2 - bx1; i++)
5260 buf[i] = tb->lines_list[tb->cy][bx1 + i];
5264 /* Copy this segment of line */
5265 add_str_to_yank(tb, buf);
5269 /* Multiple lines case */
5270 else /* if (tb->my != tb->cy) */
5274 int by1 = MIN(tb->my, tb->cy);
5275 int by2 = MAX(tb->my, tb->cy);
5278 for (y = by1; y <= by2; y++)
5280 /* Copy this line */
5281 add_str_to_yank(tb, tb->lines_list[y]);
5284 /* Add final end of line to the buffer */
5285 add_str_to_yank(tb, "");
5288 /* Disable selection */
5292 tb->dirty_flags |= DIRTY_ALL;
5298 /* Paste killed text */
5300 chain_str_type *chain = tb->yank;
5301 int len = strlen(tb->lines_list[tb->cy]);
5303 /* Nothing to do? */
5306 /* Correct cursor location */
5307 if (tb->cx > len) tb->cx = len;
5309 /* Ignore selection */
5315 tb->dirty_flags |= DIRTY_ALL;
5321 cptr yank_str = chain->s;
5323 char buf[MAX_LINELEN];
5325 char rest[MAX_LINELEN], *rest_ptr = rest;
5327 /* Save preceding string */
5328 for(i = 0; i < tb->cx; i++)
5329 buf[i] = tb->lines_list[tb->cy][i];
5331 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5333 /* Paste yank buffer */
5334 while (*yank_str && i < MAX_LINELEN-1)
5336 buf[i++] = *yank_str++;
5342 chain = chain->next;
5344 if (chain || tb->yank_eol)
5346 /* There is an end of line between chain nodes */
5348 insert_return_code(tb);
5350 /* Replace this line with new one */
5351 string_free(tb->lines_list[tb->cy]);
5352 tb->lines_list[tb->cy] = string_make(buf);
5354 /* Move to next line */
5361 /* Final line doesn't have end of line */
5363 tb->cx = strlen(buf);
5365 /* Rest of original line */
5366 while (*rest_ptr && i < MAX_LINELEN-1)
5368 buf[i++] = *rest_ptr++;
5374 /* Replace this line with new one */
5375 string_free(tb->lines_list[tb->cy]);
5376 tb->lines_list[tb->cy] = string_make(buf);
5383 tb->dirty_flags |= DIRTY_ALL;
5385 /* Expressions need re-evaluation */
5386 tb->dirty_flags |= DIRTY_EXPRESSION;
5388 /* Text is changed */
5397 /* Disable the selection */
5401 tb->dirty_flags |= DIRTY_ALL;
5405 tb->mark = MARK_MARK;
5407 /* Repeating this command swaps cursor position */
5408 if (com_id == tb->old_com_id)
5420 tb->dirty_flags |= DIRTY_ALL;
5424 int len = strlen(tb->lines_list[tb->cy]);
5426 /* Mark the point 1 */
5430 /* Correct cursor location */
5431 if (tb->cx > len) tb->mx = len;
5438 /* Kill rest of line */
5440 int len = strlen(tb->lines_list[tb->cy]);
5442 /* Correct cursor location */
5443 if (tb->cx > len) tb->cx = len;
5445 /* Ignore selection */
5451 tb->dirty_flags |= DIRTY_ALL;
5454 /* Append only if this command is repeated. */
5455 if (tb->old_com_id != com_id)
5457 kill_yank_chain(tb);
5461 /* Really deleted some text */
5464 /* Add deleted string to yank buffer */
5465 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5467 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5470 tb->dirty_line = tb->cy;
5472 /* Leave end of line character */
5476 /* Cut the end of line character only */
5477 if (tb->yank_eol) add_str_to_yank(tb, "");
5479 /* Cut end of line */
5480 tb->yank_eol = TRUE;
5482 do_editor_command(tb, EC_DELETE_CHAR);
5486 case EC_DELETE_CHAR:
5488 /* DELETE == go forward + BACK SPACE */
5492 /* Ignore selection */
5498 tb->dirty_flags |= DIRTY_ALL;
5502 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5506 /* Pass through the end of line to next line */
5507 len = strlen(tb->lines_list[tb->cy]);
5510 if (tb->lines_list[tb->cy + 1])
5522 do_editor_command(tb, EC_BACKSPACE);
5531 char buf[MAX_LINELEN];
5533 /* Ignore selection */
5539 tb->dirty_flags |= DIRTY_ALL;
5542 /* Move to correct collumn */
5543 len = strlen(tb->lines_list[tb->cy]);
5544 if (len < tb->cx) tb->cx = len;
5548 /* delete a return code and union two lines */
5549 if (tb->cy == 0) break;
5550 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5551 strcpy(buf, tb->lines_list[tb->cy-1]);
5552 strcat(buf, tb->lines_list[tb->cy]);
5553 string_free(tb->lines_list[tb->cy-1]);
5554 string_free(tb->lines_list[tb->cy]);
5555 tb->lines_list[tb->cy-1] = string_make(buf);
5557 for (i = tb->cy; tb->lines_list[i+1]; i++)
5558 tb->lines_list[i] = tb->lines_list[i+1];
5560 tb->lines_list[i] = NULL;
5564 tb->dirty_flags |= DIRTY_ALL;
5566 /* Expressions need re-evaluation */
5567 tb->dirty_flags |= DIRTY_EXPRESSION;
5569 /* Text is changed */
5575 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5579 if (iskanji(tb->lines_list[tb->cy][i]))
5580 buf[j++] = tb->lines_list[tb->cy][i++];
5582 buf[j++] = tb->lines_list[tb->cy][i];
5589 for (; tb->lines_list[tb->cy][i]; i++)
5590 buf[j++] = tb->lines_list[tb->cy][i];
5592 string_free(tb->lines_list[tb->cy]);
5593 tb->lines_list[tb->cy] = string_make(buf);
5596 tb->dirty_line = tb->cy;
5598 /* Expressions may need re-evaluation */
5599 check_expression_line(tb, tb->cy);
5601 /* Text is changed */
5611 /* Become dirty because of item/equip menu */
5612 tb->dirty_flags |= DIRTY_SCREEN;
5614 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5616 if (!search_dir) break;
5618 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5619 else do_editor_command(tb, EC_SEARCH_BACK);
5623 case EC_SEARCH_FORW:
5624 if (tb->search_o_ptr)
5626 search_for_object(tb, tb->search_o_ptr, TRUE);
5628 else if (tb->search_str && tb->search_str[0])
5630 search_for_string(tb, tb->search_str, TRUE);
5634 tb->dirty_flags |= DIRTY_NO_SEARCH;
5638 case EC_SEARCH_BACK:
5639 if (tb->search_o_ptr)
5641 search_for_object(tb, tb->search_o_ptr, FALSE);
5643 else if (tb->search_str && tb->search_str[0])
5645 search_for_string(tb, tb->search_str, FALSE);
5649 tb->dirty_flags |= DIRTY_NO_SEARCH;
5654 /* Become dirty because of item/equip menu */
5655 tb->dirty_flags |= DIRTY_SCREEN;
5657 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5659 do_editor_command(tb, EC_SEARCH_FORW);
5662 case EC_SEARCH_DESTROYED:
5663 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5665 /* There is no object to search */
5666 tb->dirty_flags |= DIRTY_NO_SEARCH;
5671 do_editor_command(tb, EC_SEARCH_FORW);
5674 case EC_INSERT_OBJECT:
5676 /* Insert choosen item name */
5678 autopick_type an_entry, *entry = &an_entry;
5680 if (!entry_from_choosed_object(entry))
5682 /* Now dirty because of item/equip menu */
5683 tb->dirty_flags |= DIRTY_SCREEN;
5688 insert_return_code(tb);
5689 string_free(tb->lines_list[tb->cy]);
5690 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5692 /* Now dirty because of item/equip menu */
5693 tb->dirty_flags |= DIRTY_SCREEN;
5698 case EC_INSERT_DESTROYED:
5699 /* Insert a name of last destroyed item */
5700 if (tb->last_destroyed)
5703 insert_return_code(tb);
5704 string_free(tb->lines_list[tb->cy]);
5705 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5708 tb->dirty_flags |= DIRTY_ALL;
5710 /* Text is changed */
5715 case EC_INSERT_BLOCK:
5717 /* Insert a conditinal expression line */
5718 char expression[80];
5720 /* Conditional Expression for Class and Race */
5721 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5723 rp_ptr->E_title, cp_ptr->E_title,
5725 rp_ptr->title, cp_ptr->title,
5731 insert_return_code(tb);
5732 string_free(tb->lines_list[tb->cy]);
5733 tb->lines_list[tb->cy] = string_make(expression);
5735 insert_return_code(tb);
5736 string_free(tb->lines_list[tb->cy]);
5737 tb->lines_list[tb->cy] = string_make("?:1");
5740 tb->dirty_flags |= DIRTY_ALL;
5742 /* Text is changed */
5748 case EC_INSERT_MACRO:
5749 /* Draw_everythig (delete menu) */
5750 draw_text_editor(tb);
5753 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5757 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5759 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5761 if (insert_macro_line(tb))
5763 /* Prepare to input action */
5767 tb->dirty_flags |= DIRTY_ALL;
5769 /* Text is changed */
5775 case EC_INSERT_KEYMAP:
5776 /* Draw_everythig (delete menu) */
5777 draw_text_editor(tb);
5780 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5784 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)));
5786 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)));
5789 if (insert_keymap_line(tb))
5791 /* Prepare to input action */
5795 tb->dirty_flags |= DIRTY_ALL;
5797 /* Text is changed */
5802 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5803 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5804 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5805 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5806 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5808 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5809 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5810 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5811 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5812 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5813 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5814 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5815 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5816 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5817 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5818 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5819 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5820 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5821 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5822 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5823 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5824 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5825 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5826 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5827 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5828 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5829 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5830 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5831 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5832 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5833 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5834 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5835 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5836 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5837 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5838 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5839 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5840 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5841 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5842 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5843 case EC_OK_UNREADABLE:
5844 toggle_keyword(tb, FLG_UNREADABLE);
5845 add_keyword(tb, FLG_SPELLBOOKS);
5848 toggle_keyword(tb, FLG_REALM1);
5849 add_keyword(tb, FLG_SPELLBOOKS);
5852 toggle_keyword(tb, FLG_REALM2);
5853 add_keyword(tb, FLG_SPELLBOOKS);
5856 toggle_keyword(tb, FLG_FIRST);
5857 add_keyword(tb, FLG_SPELLBOOKS);
5860 toggle_keyword(tb, FLG_SECOND);
5861 add_keyword(tb, FLG_SPELLBOOKS);
5864 toggle_keyword(tb, FLG_THIRD);
5865 add_keyword(tb, FLG_SPELLBOOKS);
5868 toggle_keyword(tb, FLG_FOURTH);
5869 add_keyword(tb, FLG_SPELLBOOKS);
5873 /* Save old command */
5874 tb->old_com_id = com_id;
5881 * Insert single letter at cursor position.
5883 static void insert_single_letter(text_body_type *tb, int key)
5886 char buf[MAX_LINELEN];
5888 /* Save preceding string */
5889 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5890 buf[j++] = tb->lines_list[tb->cy][i];
5892 /* Add a character */
5900 if (j+2 < MAX_LINELEN)
5912 if (j+1 < MAX_LINELEN)
5918 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5919 buf[j++] = tb->lines_list[tb->cy][i];
5922 /* Replace current line with new line */
5923 string_free(tb->lines_list[tb->cy]);
5924 tb->lines_list[tb->cy] = string_make(buf);
5926 /* Move to correct collumn */
5927 len = strlen(tb->lines_list[tb->cy]);
5928 if (len < tb->cx) tb->cx = len;
5931 tb->dirty_line = tb->cy;
5933 /* Expressions may need re-evaluation */
5934 check_expression_line(tb, tb->cy);
5936 /* Text is changed */
5942 * Check special key code and get a movement command id
5944 static int analyze_move_key(text_body_type *tb, int skey)
5948 /* Not a special key */
5949 if (!(skey & SKEY_MASK)) return 0;
5951 /* Convert from a special key code to an editor command */
5952 switch(skey & ~SKEY_MOD_MASK)
5954 case SKEY_DOWN: com_id = EC_DOWN; break;
5955 case SKEY_LEFT: com_id = EC_LEFT; break;
5956 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5957 case SKEY_UP: com_id = EC_UP; break;
5958 case SKEY_PGUP: com_id = EC_PGUP; break;
5959 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5960 case SKEY_TOP: com_id = EC_TOP; break;
5961 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5964 /* Not a special movement key */
5968 /* Without shift modifier */
5969 if (!(skey & SKEY_MOD_SHIFT))
5972 * Un-shifted cursor keys cancells
5973 * selection created by shift+cursor.
5975 if (tb->mark & MARK_BY_SHIFT)
5980 tb->dirty_flags |= DIRTY_ALL;
5984 /* With shift modifier */
5987 /* Start selection by shift + cursor keys */
5990 int len = strlen(tb->lines_list[tb->cy]);
5992 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5996 /* Correct cursor location */
5997 if (tb->cx > len) tb->mx = len;
5999 /* Need to redraw text */
6000 if (com_id == EC_UP || com_id == EC_DOWN)
6002 /* Redraw all text */
6003 tb->dirty_flags |= DIRTY_ALL;
6007 tb->dirty_line = tb->cy;
6016 * In-game editor of Object Auto-picker/Destoryer
6018 void do_cmd_edit_autopick(void)
6020 static int cx_save = 0;
6021 static int cy_save = 0;
6023 text_body_type text_body, *tb = &text_body;
6025 autopick_type an_entry, *entry = &an_entry;
6026 char buf[MAX_LINELEN];
6031 static s32b old_autosave_turn = 0L;
6034 tb->changed = FALSE;
6037 tb->upper = tb->left = 0;
6039 tb->mx = tb->my = 0;
6040 tb->old_cy = tb->old_upper = tb->old_left = -1;
6041 tb->old_wid = tb->old_hgt = -1;
6045 tb->search_o_ptr = NULL;
6046 tb->search_str = NULL;
6047 tb->last_destroyed = NULL;
6048 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6049 tb->dirty_line = -1;
6050 tb->filename_mode = PT_DEFAULT;
6053 if (turn > old_autosave_turn + 100L)
6055 do_cmd_save_game(TRUE);
6056 old_autosave_turn = turn;
6059 /* HACK -- Reset start_time to stop counting playtime while edit */
6062 /* Free old entries */
6065 /* Command Description of the 'Last Destroyed Item' */
6066 if (autopick_last_destroyed_object.k_idx)
6068 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6069 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6072 /* Read or initialize whole text */
6073 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6075 /* Reset cursor position if needed */
6076 for (i = 0; i < tb->cy; i++)
6078 if (!tb->lines_list[i])
6080 tb->cy = tb->cx = 0;
6085 /* Save the screen */
6088 /* Process requests until done */
6093 /* Draw_everythig */
6094 draw_text_editor(tb);
6096 /* Display header line */
6098 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
6100 prt("(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)", 0, 0);
6104 /* Display current position */
6105 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6109 /* Display current position and mark position */
6110 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6114 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6117 tb->dirty_flags = 0;
6118 tb->dirty_line = -1;
6120 /* Save old key and location */
6121 tb->old_cy = tb->cy;
6122 tb->old_upper = tb->upper;
6123 tb->old_left = tb->left;
6124 tb->old_wid = tb->wid;
6125 tb->old_hgt = tb->hgt;
6128 key = inkey_special(TRUE);
6131 if (key & SKEY_MASK)
6133 /* Get a movement command */
6134 com_id = analyze_move_key(tb, key);
6138 else if (key == ESCAPE)
6140 com_id = do_command_menu(0, 0);
6142 /* Redraw all text later */
6143 tb->dirty_flags |= DIRTY_SCREEN;
6146 /* Insert a character */
6147 else if (!iscntrl((unsigned char)key))
6149 /* Ignore selection */
6155 tb->dirty_flags |= DIRTY_ALL;
6158 insert_single_letter(tb, key);
6164 /* Other commands */
6167 com_id = get_com_id(key);
6170 if (com_id) quit = do_editor_command(tb, com_id);
6171 } /* while (TRUE) */
6173 /* Restore the screen */
6176 /* Get the filename of preference */
6177 strcpy(buf, pickpref_filename(tb->filename_mode));
6179 if (quit == QUIT_AND_SAVE)
6180 write_text_lines(buf, tb->lines_list);
6182 free_text_lines(tb->lines_list);
6184 string_free(tb->last_destroyed);
6186 /* Destroy string chain */
6187 kill_yank_chain(tb);
6189 /* Reload autopick pref */
6190 process_autopick_file(buf);
6192 /* HACK -- reset start_time so that playtime is not increase while edit */
6193 start_time = time(NULL);
6195 /* Save cursor location */