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
50 #define FLG_MISSILES 33
51 #define FLG_DEVICES 34
54 #define FLG_SPELLBOOKS 37
56 #define FLG_SHIELDS 39
59 #define FLG_AMULETS 42
65 #define FLG_FAVORITE 48
67 #define FLG_NOUN_BEGIN FLG_ITEMS
68 #define FLG_NOUN_END FLG_FAVORITE
72 #define KEY_ALL "¤¹¤Ù¤Æ¤Î"
76 * MEGA HACK -- MPW¤Î¥Ð¥°½ü¤±¡£
77 * pre-processÃæ¤Ë¡Ö¼ý¡×¤Î»ú¤Î2¥Ð¥¤¥ÈÌܤ¬¾¡¼ê¤Ë¾Ã¤¨¤Æ¤·¤Þ¤¦¡£
79 #define KEY_COLLECTING "\x8e\xfb½¸Ãæ¤Î"
81 #define KEY_COLLECTING "¼ý½¸Ãæ¤Î"
84 #define KEY_UNAWARE "̤ȽÌÀ¤Î"
85 #define KEY_UNIDENTIFIED "̤´ÕÄê¤Î"
86 #define KEY_IDENTIFIED "´ÕÄêºÑ¤ß¤Î"
87 #define KEY_STAR_IDENTIFIED "*´ÕÄê*ºÑ¤ß¤Î"
88 #define KEY_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦"
89 #define KEY_MORE_THAN "¥À¥¤¥¹ÌÜ"
90 #define KEY_DICE "°Ê¾å¤Î"
91 #define KEY_MORE_BONUS "½¤ÀµÃÍ"
92 #define KEY_MORE_BONUS2 "°Ê¾å¤Î"
93 #define KEY_WORTHLESS "̵²ÁÃͤÎ"
94 #define KEY_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È"
95 #define KEY_EGO "¥¨¥´"
96 #define KEY_NAMELESS "̵ÌäÎ"
97 #define KEY_RARE "¥ì¥¢¤Ê"
98 #define KEY_COMMON "¤¢¤ê¤Õ¤ì¤¿"
99 #define KEY_WANTED "¾Þ¶â¼ó¤Î"
100 #define KEY_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î"
101 #define KEY_HUMAN "¿Í´Ö¤Î"
102 #define KEY_UNREADABLE "Æɤá¤Ê¤¤"
103 #define KEY_REALM1 "Âè°ìÎΰè¤Î"
104 #define KEY_REALM2 "ÂèÆóÎΰè¤Î"
105 #define KEY_FIRST "1ºýÌܤÎ"
106 #define KEY_SECOND "2ºýÌܤÎ"
107 #define KEY_THIRD "3ºýÌܤÎ"
108 #define KEY_FOURTH "4ºýÌܤÎ"
109 #define KEY_ITEMS "¥¢¥¤¥Æ¥à"
110 #define KEY_WEAPONS "Éð´ï"
111 #define KEY_ARMORS "Ëɶñ"
112 #define KEY_MISSILES "Ìð"
113 #define KEY_DEVICES "ËâË¡¥¢¥¤¥Æ¥à"
114 #define KEY_LIGHTS "¸÷¸»"
115 #define KEY_JUNKS "¤¬¤é¤¯¤¿"
116 #define KEY_SPELLBOOKS "ËâË¡½ñ"
117 #define KEY_HAFTED "Æß´ï"
118 #define KEY_SHIELDS "½â"
119 #define KEY_BOWS "µÝ"
120 #define KEY_RINGS "»ØÎØ"
121 #define KEY_AMULETS "¥¢¥ß¥å¥ì¥Ã¥È"
122 #define KEY_SUITS "³»"
123 #define KEY_CLOAKS "¥¯¥í¡¼¥¯"
124 #define KEY_HELMS "³õ"
125 #define KEY_GLOVES "äƼê"
126 #define KEY_BOOTS "·¤"
127 #define KEY_FAVORITE "ÆÀ°ÕÉð´ï"
131 #define KEY_ALL "all"
132 #define KEY_COLLECTING "collecting"
133 #define KEY_UNAWARE "unaware"
134 #define KEY_UNIDENTIFIED "unidentified"
135 #define KEY_IDENTIFIED "identified"
136 #define KEY_STAR_IDENTIFIED "*identified*"
137 #define KEY_BOOSTED "dice boosted"
138 #define KEY_MORE_THAN "more than"
139 #define KEY_DICE " dice"
140 #define KEY_MORE_BONUS "more bonus than"
141 #define KEY_MORE_BONUS2 ""
142 #define KEY_WORTHLESS "worthless"
143 #define KEY_ARTIFACT "artifact"
144 #define KEY_EGO "ego"
145 #define KEY_NAMELESS "nameless"
146 #define KEY_RARE "rare"
147 #define KEY_COMMON "common"
148 #define KEY_WANTED "wanted"
149 #define KEY_UNIQUE "unique monster's"
150 #define KEY_HUMAN "human"
151 #define KEY_UNREADABLE "unreadable"
152 #define KEY_REALM1 "first realm's"
153 #define KEY_REALM2 "second realm's"
154 #define KEY_FIRST "first"
155 #define KEY_SECOND "second"
156 #define KEY_THIRD "third"
157 #define KEY_FOURTH "fourth"
158 #define KEY_ITEMS "items"
159 #define KEY_WEAPONS "weapons"
160 #define KEY_ARMORS "armors"
161 #define KEY_MISSILES "missiles"
162 #define KEY_DEVICES "magical devices"
163 #define KEY_LIGHTS "lights"
164 #define KEY_JUNKS "junks"
165 #define KEY_SPELLBOOKS "spellbooks"
166 #define KEY_HAFTED "hafted weapons"
167 #define KEY_SHIELDS "shields"
168 #define KEY_BOWS "bows"
169 #define KEY_RINGS "rings"
170 #define KEY_AMULETS "amulets"
171 #define KEY_SUITS "suits"
172 #define KEY_CLOAKS "cloaks"
173 #define KEY_HELMS "helms"
174 #define KEY_GLOVES "gloves"
175 #define KEY_BOOTS "boots"
176 #define KEY_FAVORITE "favorite weapons"
180 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
181 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
182 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
183 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
186 #define ADD_KEY(KEY) strcat(ptr, KEY)
188 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
190 #define ADD_KEY2(KEY) strcat(ptr, KEY)
192 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
193 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
194 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
195 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
198 static char kanji_colon[] = "¡§";
203 * A function to create new entry
205 static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_default)
210 char buf[MAX_LINELEN];
211 cptr prev_ptr, ptr, old_ptr;
214 if (str[1] == ':') switch (str[0])
217 case 'A': case 'P': case 'C':
221 entry->flag[0] = entry->flag[1] = 0L;
224 act = DO_AUTOPICK | DO_DISPLAY;
227 if ((act & DO_AUTOPICK) && *str == '!')
230 act |= DO_AUTODESTROY;
233 else if ((act & DO_AUTOPICK) && *str == '~')
236 act |= DONT_AUTOPICK;
239 else if ((act & DO_AUTOPICK) && *str == ';')
242 act |= DO_QUERY_AUTOPICK;
245 else if ((act & DO_DISPLAY) && *str == '(')
254 /* don't mind upper or lower case */
256 for (i = 0; *str; i++)
267 /* Auto-inscription? */
275 if (isupper(c)) c = tolower(c);
281 /* Skip empty line unless allow_default */
282 if (!allow_default && *buf == 0) return FALSE;
284 /* Skip comment line */
285 if (*buf == 0 && insc) return FALSE;
287 ptr = prev_ptr = buf;
290 while (old_ptr != ptr)
292 /* Save current location */
295 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
296 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
297 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
298 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
299 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
300 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
301 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
303 /*** Weapons whose dd*ds is more than nn ***/
304 if (MATCH_KEY2(KEY_MORE_THAN))
309 /* Drop leading spaces */
310 while (' ' == *ptr) ptr++;
313 while ('0' <= *ptr && *ptr <= '9')
315 entry->dice = 10 * entry->dice + (*ptr - '0');
322 (void)MATCH_KEY(KEY_DICE);
323 ADD_FLG(FLG_MORE_DICE);
329 /*** Items whose magical bonus is more than n ***/
330 if (MATCH_KEY2(KEY_MORE_BONUS))
335 /* Drop leading spaces */
336 while (' ' == *ptr) ptr++;
339 while ('0' <= *ptr && *ptr <= '9')
341 entry->bonus = 10 * entry->bonus + (*ptr - '0');
348 (void)MATCH_KEY(KEY_MORE_BONUS2);
349 ADD_FLG(FLG_MORE_BONUS);
355 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
356 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
357 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
358 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
359 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
360 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
361 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
362 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
363 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
364 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
365 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
366 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
367 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
368 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
369 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
372 /* Not yet found any noun */
375 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
377 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
378 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
379 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
380 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
381 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
382 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
383 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
384 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
385 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
386 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
387 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
388 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
389 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
390 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
391 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
392 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
393 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
394 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
395 else if (MATCH_KEY2(KEY_FAVORITE)) ADD_FLG_NOUN(FLG_FAVORITE);
397 /* Last 'keyword' must be at the correct location */
401 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
404 else if (*ptr == '\0')
406 /* There was no noun */
409 /* Add extra word "items" */
410 ADD_FLG_NOUN(FLG_ITEMS);
417 /* A noun type keyword didn't end correctly */
418 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
423 /* Save this auto-picker entry line */
424 entry->name = string_make(ptr);
426 entry->insc = string_make(insc);
435 static bool is_favorite(object_type *o_ptr)
437 /* Only weapons match */
438 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
441 /* Favorite weapons are varied depend on the class */
442 switch (p_ptr->pclass)
446 u32b flgs[TR_FLAG_SIZE];
447 object_flags_known(o_ptr, flgs);
449 if (!have_flag(flgs, TR_BLESSED) &&
450 !(o_ptr->tval == TV_HAFTED))
456 case CLASS_FORCETRAINER:
458 if (!(s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval]))
462 case CLASS_BEASTMASTER:
465 u32b flgs[TR_FLAG_SIZE];
466 object_flags_known(o_ptr, flgs);
468 /* Is it known to be suitable to using while riding? */
469 if (!(have_flag(flgs, TR_RIDING)))
477 if (s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
482 /* All weapons are okay for non-special classes */
491 * Rare weapons/aromors
492 * including Blade of Chaos, Dragon armors, etc.
494 static bool is_rare(object_type *o_ptr)
499 if (o_ptr->sval == SV_MACE_OF_DISRUPTION ||
500 o_ptr->sval == SV_WIZSTAFF) return TRUE;
504 if (o_ptr->sval == SV_SCYTHE_OF_SLICING ||
505 o_ptr->sval == SV_DEATH_SCYTHE) return TRUE;
509 if (o_ptr->sval == SV_BLADE_OF_CHAOS ||
510 o_ptr->sval == SV_DIAMOND_EDGE ||
511 o_ptr->sval == SV_DOKUBARI ||
512 o_ptr->sval == SV_HAYABUSA) return TRUE;
516 if (o_ptr->sval == SV_DRAGON_SHIELD ||
517 o_ptr->sval == SV_MIRROR_SHIELD) return TRUE;
521 if (o_ptr->sval == SV_DRAGON_HELM) return TRUE;
525 if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) return TRUE;
529 if (o_ptr->sval == SV_ELVEN_CLOAK ||
530 o_ptr->sval == SV_ETHEREAL_CLOAK ||
531 o_ptr->sval == SV_SHADOW_CLOAK) return TRUE;
535 if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) return TRUE;
539 if (o_ptr->sval == SV_KUROSHOUZOKU ||
540 o_ptr->sval == SV_ABUNAI_MIZUGI) return TRUE;
550 /* Any others are not "rare" objects. */
556 * Convert string to lower case
558 static void str_tolower(char *str)
560 /* Force to be lower case string */
570 *str = tolower(*str);
576 * Get auto-picker entry from o_ptr.
578 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
580 /* Assume that object name is to be added */
584 /* ¥¨¥´Ì䬼ÙË⤫¤â¤·¤ì¤Ê¤¤¤Î¤Ç¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¡Ö^¡×¤ÏÉÕ¤±¤Ê¤¤ */
585 bool bol_mark = FALSE;
587 /* We can always use the ^ mark in English */
588 bool bol_mark = TRUE;
591 char name_str[MAX_NLEN];
593 /* Initialize name string */
596 entry->insc = string_make(quark_str(o_ptr->inscription));
597 entry->action = DO_AUTOPICK | DO_DISPLAY;
598 entry->flag[0] = entry->flag[1] = 0L;
602 if (!object_aware_p(o_ptr))
604 ADD_FLG(FLG_UNAWARE);
608 /* Not really identified */
609 else if (!object_known_p(o_ptr))
611 if (!(o_ptr->ident & IDENT_SENSE))
613 ADD_FLG(FLG_UNIDENTIFIED);
618 /* Pseudo-identified */
619 switch (o_ptr->feeling)
623 ADD_FLG(FLG_NAMELESS);
629 ADD_FLG(FLG_NAMELESS);
630 ADD_FLG(FLG_WORTHLESS);
636 ADD_FLG(FLG_WORTHLESS);
644 /* XXX No appropriate flag */
649 /* Never reach here */
662 if (TV_WEAPON_BEGIN <= o_ptr->tval &&
663 o_ptr->tval <= TV_ARMOR_END)
666 * Base name of ego weapons and armors
667 * are almost meaningless.
668 * Register the ego type only.
670 ego_item_type *e_ptr = &e_info[o_ptr->name2];
672 /* ¥¨¥´ÌäˤϡÖ^¡×¥Þ¡¼¥¯¤¬»È¤¨¤ë */
673 sprintf(name_str, "^%s", e_name + e_ptr->name);
675 /* We ommit the basename and cannot use the ^ mark */
676 strcpy(name_str, e_name + e_ptr->name);
679 /* Don't use the object description */
682 if (TV_WEAPON_BEGIN <= o_ptr->tval &&
683 o_ptr->tval <= TV_ARMOR_END)
685 /* Restrict to 'common' equipments */
686 if (!is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
694 else if (o_ptr->name1 || o_ptr->art_name)
695 ADD_FLG(FLG_ARTIFACT);
697 /* Non-ego, non-artifact */
700 /* Wearable nameless object */
701 if ((TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
702 ADD_FLG(FLG_NAMELESS);
713 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
714 k_ptr = &k_info[o_ptr->k_idx];
715 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
716 ADD_FLG(FLG_BOOSTED);
719 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
721 REM_FLG(FLG_WORTHLESS);
725 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
726 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
731 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
736 if (o_ptr->tval >= TV_LIFE_BOOK &&
737 !check_book_realm(o_ptr->tval, o_ptr->sval))
739 ADD_FLG(FLG_UNREADABLE);
740 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
743 if (REALM1_BOOK == o_ptr->tval &&
744 p_ptr->pclass != CLASS_SORCERER &&
745 p_ptr->pclass != CLASS_RED_MAGE)
751 if (REALM2_BOOK == o_ptr->tval &&
752 p_ptr->pclass != CLASS_SORCERER &&
753 p_ptr->pclass != CLASS_RED_MAGE)
759 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
761 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
763 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
765 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
768 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
769 || o_ptr->tval == TV_ARROW)
770 ADD_FLG(FLG_MISSILES);
771 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
772 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
773 ADD_FLG(FLG_DEVICES);
774 else if (o_ptr->tval == TV_LITE)
776 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
777 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
779 else if (o_ptr->tval >= TV_LIFE_BOOK)
780 ADD_FLG(FLG_SPELLBOOKS);
781 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
782 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
783 ADD_FLG(FLG_WEAPONS);
784 else if (o_ptr->tval == TV_SHIELD)
785 ADD_FLG(FLG_SHIELDS);
786 else if (o_ptr->tval == TV_BOW)
788 else if (o_ptr->tval == TV_RING)
790 else if (o_ptr->tval == TV_AMULET)
791 ADD_FLG(FLG_AMULETS);
792 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
793 o_ptr->tval == TV_SOFT_ARMOR)
795 else if (o_ptr->tval == TV_CLOAK)
797 else if (o_ptr->tval == TV_HELM)
799 else if (o_ptr->tval == TV_GLOVES)
801 else if (o_ptr->tval == TV_BOOTS)
804 /* Prepare the object description */
807 char o_name[MAX_NLEN];
809 object_desc(o_name, o_ptr, FALSE, 0);
812 * If necessary, add a '^' which indicates the
815 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
818 /* Register the name in lowercase */
819 str_tolower(name_str);
820 entry->name = string_make(name_str);
827 * A function to delete entry
829 static void autopick_free_entry(autopick_type *entry)
831 string_free(entry->name);
832 string_free(entry->insc);
837 * Initialize auto-picker preference
839 #define MAX_AUTOPICK_DEFAULT 200
841 void init_autopicker(void)
843 static const char easy_autopick_inscription[] = "(:=g";
849 max_max_autopick = MAX_AUTOPICK_DEFAULT;
850 C_MAKE(autopick_list, max_max_autopick, autopick_type);
854 /* Clear old entries */
855 for( i = 0; i < max_autopick; i++)
856 autopick_free_entry(&autopick_list[i]);
860 /* There is always one entry "=g" */
861 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
862 autopick_list[max_autopick++] = entry;
867 * Add one line to autopick_list[]
869 static void add_autopick_list(autopick_type *entry)
871 /* There is no enough space to add one line */
872 if (max_autopick >= max_max_autopick)
874 int old_max_max_autopick = max_max_autopick;
875 autopick_type *old_autopick_list = autopick_list;
877 /* Increase size of list */
878 max_max_autopick += MAX_AUTOPICK_DEFAULT;
881 C_MAKE(autopick_list, max_max_autopick, autopick_type);
883 /* Copy from old list to new list */
884 C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
887 C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
891 autopick_list[max_autopick] = *entry;
898 * Process line for auto picker/destroyer.
900 errr process_pickpref_file_line(char *buf)
902 autopick_type an_entry, *entry = &an_entry;
905 /* Nuke illegal char */
906 for(i = 0; buf[i]; i++)
915 if (isspace(buf[i]) && buf[i] != ' ')
920 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
922 /* Already has the same entry? */
923 for(i = 0; i < max_autopick; i++)
924 if(!strcmp(entry->name, autopick_list[i].name)
925 && entry->flag[0] == autopick_list[i].flag[0]
926 && entry->flag[1] == autopick_list[i].flag[1]
927 && entry->dice == autopick_list[i].dice
928 && entry->bonus == autopick_list[i].bonus) return 0;
930 add_autopick_list(entry);
936 * Reconstruct preference line from entry
938 cptr autopick_line_from_entry(autopick_type *entry)
940 char buf[MAX_LINELEN];
942 bool sepa_flag = TRUE;
945 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
946 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
947 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
948 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
952 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
953 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
954 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
955 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
956 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
957 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
958 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
960 if (IS_FLG(FLG_MORE_DICE))
962 ADD_KEY(KEY_MORE_THAN);
963 strcat(ptr, format("%d", entry->dice));
967 if (IS_FLG(FLG_MORE_BONUS))
969 ADD_KEY(KEY_MORE_BONUS);
970 strcat(ptr, format("%d", entry->bonus));
971 ADD_KEY(KEY_MORE_BONUS2);
974 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
975 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
976 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
977 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
978 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
979 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
980 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
981 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
982 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
983 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
984 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
985 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
986 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
987 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
988 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
990 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
992 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
993 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
994 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
995 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
996 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
997 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
998 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
999 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
1000 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
1001 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
1002 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
1003 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
1004 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
1005 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
1006 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
1007 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
1008 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
1009 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
1010 else if (IS_FLG(FLG_FAVORITE)) ADD_KEY2(KEY_FAVORITE);
1012 /* You don't need sepalator after adjective */
1013 /* 'artifact' is not true adjective */
1014 else if (!IS_FLG(FLG_ARTIFACT))
1017 if (entry->name && entry->name[0])
1021 if (sepa_flag) strcat(buf, ":");
1024 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
1027 if (iskanji(entry->name[j]))
1028 buf[i++] = entry->name[j++];
1030 buf[i++] = entry->name[j++];
1041 while (entry->insc[j] && i < MAX_LINELEN - 2)
1044 if (iskanji(entry->insc[j]))
1045 buf[i++] = entry->insc[j++];
1047 buf[i++] = entry->insc[j++];
1052 return string_make(buf);
1057 * Reconstruct preference line from entry and kill entry
1059 static cptr autopick_line_from_entry_kill(autopick_type *entry)
1061 cptr ptr = autopick_line_from_entry(entry);
1063 /* Free memory for original entry */
1064 autopick_free_entry(entry);
1071 * A function for Auto-picker/destroyer
1072 * Examine whether the object matches to the entry
1074 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
1077 cptr ptr = entry->name;
1079 /*** Unaware items ***/
1080 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
1083 /*** Unidentified ***/
1084 if (IS_FLG(FLG_UNIDENTIFIED)
1085 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1088 /*** Identified ***/
1089 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
1092 /*** *Identified* ***/
1093 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1094 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1097 /*** Dice boosted (weapon of slaying) ***/
1098 if (IS_FLG(FLG_BOOSTED))
1100 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1102 switch( o_ptr->tval )
1108 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1117 /*** Weapons which dd*ds is more than nn ***/
1118 if (IS_FLG(FLG_MORE_DICE))
1120 if (o_ptr->dd * o_ptr->ds < entry->dice)
1124 /*** Weapons whic dd*ds is more than nn ***/
1125 if (IS_FLG(FLG_MORE_BONUS))
1127 if (!object_known_p(o_ptr)) return FALSE;
1131 if (o_ptr->pval < entry->bonus) return FALSE;
1135 if (o_ptr->to_h < entry->bonus &&
1136 o_ptr->to_d < entry->bonus &&
1137 o_ptr->to_a < entry->bonus &&
1138 o_ptr->pval < entry->bonus)
1143 /*** Worthless items ***/
1144 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1147 /*** Artifact object ***/
1148 if (IS_FLG(FLG_ARTIFACT))
1150 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
1154 /*** Ego object ***/
1155 if (IS_FLG(FLG_EGO))
1157 /* Need to be an ego item */
1158 if (!o_ptr->name2) return FALSE;
1160 /* Need to be known to be an ego */
1161 if (!object_known_p(o_ptr) &&
1162 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1167 if (IS_FLG(FLG_NAMELESS))
1169 if (!(TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
1172 /* Inscription is a some sort of 'name' */
1173 if (o_ptr->inscription) return FALSE;
1176 if (object_known_p(o_ptr))
1178 /* Artifacts and Ego objects are not okay */
1179 if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2)
1183 /* Pseudo-identified */
1184 else if (o_ptr->ident & IDENT_SENSE)
1186 switch (o_ptr->feeling)
1196 /* It's not nameless */
1204 /* Not known to be nameless */
1209 /*** Rere equpiments ***/
1210 if (IS_FLG(FLG_RARE) && !is_rare(o_ptr))
1213 /*** Common equpiments ***/
1214 if (IS_FLG(FLG_COMMON) && is_rare(o_ptr))
1217 /*** Wanted monster's corpse/skeletons ***/
1218 if (IS_FLG(FLG_WANTED) &&
1219 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
1222 /*** Unique monster's corpse/skeletons/statues ***/
1223 if (IS_FLG(FLG_UNIQUE) &&
1224 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1225 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1228 /*** Human corpse/skeletons (for Daemon magic) ***/
1229 if (IS_FLG(FLG_HUMAN) &&
1230 (o_ptr->tval != TV_CORPSE ||
1231 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1234 /*** Unreadable spellbooks ***/
1235 if (IS_FLG(FLG_UNREADABLE) &&
1236 (o_ptr->tval < TV_LIFE_BOOK ||
1237 check_book_realm(o_ptr->tval, o_ptr->sval)))
1240 /*** First realm spellbooks ***/
1241 if (IS_FLG(FLG_REALM1) &&
1242 (REALM1_BOOK != o_ptr->tval ||
1243 p_ptr->pclass == CLASS_SORCERER ||
1244 p_ptr->pclass == CLASS_RED_MAGE))
1247 /*** Second realm spellbooks ***/
1248 if (IS_FLG(FLG_REALM2) &&
1249 (REALM2_BOOK != o_ptr->tval ||
1250 p_ptr->pclass == CLASS_SORCERER ||
1251 p_ptr->pclass == CLASS_RED_MAGE))
1254 /*** First rank spellbooks ***/
1255 if (IS_FLG(FLG_FIRST) &&
1256 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1259 /*** Second rank spellbooks ***/
1260 if (IS_FLG(FLG_SECOND) &&
1261 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1264 /*** Third rank spellbooks ***/
1265 if (IS_FLG(FLG_THIRD) &&
1266 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1269 /*** Fourth rank spellbooks ***/
1270 if (IS_FLG(FLG_FOURTH) &&
1271 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1275 if (IS_FLG(FLG_WEAPONS))
1277 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
1280 else if (IS_FLG(FLG_ARMORS))
1282 if (!(TV_ARMOR_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_ARMOR_END))
1285 else if (IS_FLG(FLG_MISSILES))
1289 case TV_SHOT: case TV_BOLT: case TV_ARROW:
1291 default: return FALSE;
1294 else if (IS_FLG(FLG_DEVICES))
1298 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1300 default: return FALSE;
1303 else if (IS_FLG(FLG_LIGHTS))
1305 if (!(o_ptr->tval == TV_LITE))
1308 else if (IS_FLG(FLG_JUNKS))
1312 case TV_SKELETON: case TV_BOTTLE:
1313 case TV_JUNK: case TV_STATUE:
1315 default: return FALSE;
1318 else if (IS_FLG(FLG_SPELLBOOKS))
1320 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1323 else if (IS_FLG(FLG_HAFTED))
1325 if (!(o_ptr->tval == TV_HAFTED))
1328 else if (IS_FLG(FLG_SHIELDS))
1330 if (!(o_ptr->tval == TV_SHIELD))
1333 else if (IS_FLG(FLG_BOWS))
1335 if (!(o_ptr->tval == TV_BOW))
1338 else if (IS_FLG(FLG_RINGS))
1340 if (!(o_ptr->tval == TV_RING))
1343 else if (IS_FLG(FLG_AMULETS))
1345 if (!(o_ptr->tval == TV_AMULET))
1348 else if (IS_FLG(FLG_SUITS))
1350 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1351 o_ptr->tval == TV_HARD_ARMOR ||
1352 o_ptr->tval == TV_SOFT_ARMOR))
1355 else if (IS_FLG(FLG_CLOAKS))
1357 if (!(o_ptr->tval == TV_CLOAK))
1360 else if (IS_FLG(FLG_HELMS))
1362 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1365 else if (IS_FLG(FLG_GLOVES))
1367 if (!(o_ptr->tval == TV_GLOVES))
1370 else if (IS_FLG(FLG_BOOTS))
1372 if (!(o_ptr->tval == TV_BOOTS))
1375 else if (IS_FLG(FLG_FAVORITE))
1377 if (!is_favorite(o_ptr))
1381 /* Keyword don't match */
1385 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1389 if (!my_strstr(o_name, ptr)) return FALSE;
1392 /* TRUE when it need not to be 'collecting' */
1393 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1395 /* Check if there is a same item */
1396 for (j = 0; j < INVEN_PACK; j++)
1399 * 'Collecting' means the item must be absorbed
1400 * into an inventory slot.
1401 * But an item can not be absorbed into itself!
1403 if ((&inventory[j] != o_ptr) &&
1404 object_similar(&inventory[j], o_ptr))
1408 /* Not collecting */
1414 * A function for Auto-picker/destroyer
1415 * Examine whether the object matches to the list of keywords or not.
1417 int is_autopick(object_type *o_ptr)
1420 char o_name[MAX_NLEN];
1422 if (o_ptr->tval == TV_GOLD) return -1;
1424 /* Prepare object name string first */
1425 object_desc(o_name, o_ptr, FALSE, 3);
1427 /* Convert the string to lower case */
1428 str_tolower(o_name);
1430 /* Look for a matching entry in the list */
1431 for (i=0; i < max_autopick; i++)
1433 autopick_type *entry = &autopick_list[i];
1435 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1438 /* No matching entry */
1446 static void auto_inscribe_item(object_type *o_ptr, int idx)
1448 /* Are there auto-inscription? */
1449 if (idx < 0 || !autopick_list[idx].insc) return;
1451 if (!o_ptr->inscription)
1452 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1454 /* Redraw inscription */
1455 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1457 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1458 p_ptr->update |= (PU_BONUS);
1463 * Automatically destroy items in this grid.
1465 static bool is_opt_confirm_destroy(object_type *o_ptr)
1467 if (!destroy_items) return FALSE;
1469 /* Known to be worthless? */
1471 if (object_value(o_ptr) > 0) return FALSE;
1474 if ((o_ptr->tval >= TV_MISSILE_BEGIN) && (o_ptr->tval <= TV_ARMOR_END)) return FALSE;
1477 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1481 if (o_ptr->tval == TV_CORPSE
1482 && object_is_shoukinkubi(o_ptr)) return FALSE;
1486 if (o_ptr->tval == TV_CORPSE) return FALSE;
1489 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1493 if (p_ptr->prace == RACE_DEMON)
1495 if (o_ptr->tval == TV_CORPSE &&
1496 o_ptr->sval == SV_CORPSE &&
1497 my_strchr("pht", r_info[o_ptr->pval].d_char))
1501 if (p_ptr->pclass == CLASS_ARCHER)
1503 if (o_ptr->tval == TV_SKELETON ||
1504 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1507 else if (p_ptr->pclass == CLASS_NINJA)
1509 if (o_ptr->tval == TV_LITE &&
1510 o_ptr->name2 == EGO_LITE_DARKNESS)
1513 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1514 p_ptr->pclass == CLASS_CAVALRY)
1516 if (o_ptr->tval == TV_WAND &&
1517 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1522 if (o_ptr->tval == TV_GOLD) return FALSE;
1529 * Automatically destroy an item if it is to be destroyed
1531 * When always_pickup is 'yes', we disable auto-destroyer function of
1532 * auto-picker/destroyer, and do only easy-auto-destroyer.
1534 static object_type autopick_last_destroyed_object;
1536 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1538 bool destroy = FALSE;
1540 /* Easy-Auto-Destroyer (3rd priority) */
1541 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1543 /* Protected by auto-picker (2nd priotity) */
1544 if (autopick_idx >= 0 &&
1545 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1548 /* Auto-destroyer works only when !always_pickup */
1551 /* Auto-picker/destroyer (1st priority) */
1552 if (autopick_idx >= 0 &&
1553 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1557 /* Not to be destroyed */
1558 if (!destroy) return;
1560 /* Now decided to destroy */
1565 if (!can_player_destroy_object(o_ptr))
1567 char o_name[MAX_NLEN];
1569 /* Describe the object (with {terrible/special}) */
1570 object_desc(o_name, o_ptr, TRUE, 3);
1574 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1576 msg_format("You cannot auto-destroy %s.", o_name);
1583 /* Record name of destroyed item */
1584 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1587 o_ptr->marked |= OM_AUTODESTROY;
1588 p_ptr->notice |= PN_AUTODESTROY;
1595 * Auto-destroy marked item
1597 static void delayed_auto_destroy_aux(int item)
1601 /* Get the item (in the pack) */
1602 if (item >= 0) o_ptr = &inventory[item];
1604 /* Get the item (on the floor) */
1605 else o_ptr = &o_list[0 - item];
1607 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1609 char o_name[MAX_NLEN];
1611 /* Describe the object (with {terrible/special}) */
1612 object_desc(o_name, o_ptr, TRUE, 3);
1614 /* Eliminate the item (from the pack) */
1617 inven_item_increase(item, -(o_ptr->number));
1618 inven_item_optimize(item);
1621 /* Eliminate the item (from the floor) */
1624 delete_object_idx(0 - item);
1627 /* Print a message */
1629 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1631 msg_format("Auto-destroying %s.", o_name);
1638 * Auto-destroy marked items in inventry and on floor
1640 void delayed_auto_destroy(void)
1645 * Scan inventry in reverse order to prevent
1646 * skipping after inven_item_optimize()
1648 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1649 delayed_auto_destroy_aux(item);
1651 /* Scan the pile of objects */
1652 item = cave[py][px].o_idx;
1655 int next = o_list[item].next_o_idx;
1656 delayed_auto_destroy_aux(-item);
1663 * Auto-inscription and/or destroy
1665 * Auto-destroyer works only on inventory or on floor stack only when
1668 void auto_do_item(int item, bool destroy)
1673 /* Get the item (in the pack) */
1674 if (item >= 0) o_ptr = &inventory[item];
1676 /* Get the item (on the floor) */
1677 else o_ptr = &o_list[0 - item];
1679 /* Get the index in the auto-pick/destroy list */
1680 idx = is_autopick(o_ptr);
1682 /* Do auto-inscription */
1683 auto_inscribe_item(o_ptr, idx);
1685 /* Do auto-destroy if needed */
1686 if (destroy && item <= INVEN_PACK)
1687 auto_destroy_item(o_ptr, idx);
1692 * Automatically pickup/destroy items in this grid.
1694 void auto_pickup_items(cave_type *c_ptr)
1696 s16b this_o_idx, next_o_idx = 0;
1698 /* Scan the pile of objects */
1699 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1703 /* Acquire object */
1704 object_type *o_ptr = &o_list[this_o_idx];
1706 /* Acquire next object */
1707 next_o_idx = o_ptr->next_o_idx;
1709 idx = is_autopick(o_ptr);
1711 /* Item index for floor -1,-2,-3,... */
1712 auto_inscribe_item(o_ptr, idx);
1715 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1719 if (!inven_carry_okay(o_ptr))
1721 char o_name[MAX_NLEN];
1723 /* Describe the object */
1724 object_desc(o_name, o_ptr, TRUE, 3);
1728 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1730 msg_format("You have no room for %s.", o_name);
1732 /* Hack - remember that the item has given a message here. */
1733 o_ptr->marked |= OM_NOMSG;
1737 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1739 char out_val[MAX_NLEN+20];
1740 char o_name[MAX_NLEN];
1742 if (o_ptr->marked & OM_NO_QUERY)
1744 /* Already answered as 'No' */
1748 /* Describe the object */
1749 object_desc(o_name, o_ptr, TRUE, 3);
1752 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1754 sprintf(out_val, "Pick up %s? ", o_name);
1757 if (!get_check(out_val))
1759 /* Hack - remember that the item has given a message here. */
1760 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1765 py_pickup_aux(this_o_idx);
1770 * When always_pickup is 'yes', we disable
1771 * auto-destroyer from autopick function, and do only
1772 * easy-auto-destroyer.
1776 auto_destroy_item(o_ptr, idx);
1782 #define PT_DEFAULT 0
1783 #define PT_WITH_PNAME 1
1786 * Get file name for autopick preference
1788 static cptr pickpref_filename(int filename_mode)
1791 static const char namebase[] = "picktype";
1793 static const char namebase[] = "pickpref";
1796 switch (filename_mode)
1799 return format("%s.prf", namebase);
1802 return format("%s-%s.prf", namebase, player_name);
1810 static const char autoregister_header[] = "?:$AUTOREGISTER";
1813 * Clear auto registered lines in the picktype.prf .
1815 static bool clear_auto_register(void)
1817 char tmp_file[1024];
1818 char pref_file[1024];
1823 bool autoregister = FALSE;
1826 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1827 pref_fff = my_fopen(pref_file, "r");
1831 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1832 pref_fff = my_fopen(pref_file, "r");
1841 /* Open a new (temporary) file */
1842 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1846 /* Close the preference file */
1850 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1852 msg_format("Failed to create temporary file %s.", tmp_file);
1859 /* Loop for every line */
1863 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1867 /* Delete auto-registered line */
1869 /* Count auto-destroy preference lines */
1870 if (buf[0] != '#' && buf[0] != '?') num++;
1873 /* We are looking for auto-registered line */
1876 if (streq(buf, autoregister_header))
1878 /* Delete all further lines */
1879 autoregister = TRUE;
1883 /* Copy orginally lines */
1884 fprintf(tmp_fff, "%s\n", buf);
1890 my_fclose(pref_fff);
1896 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1897 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1899 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1900 strcpy(buf, "These lines will be deleted. Are you sure? ");
1903 /* You can cancel it */
1904 if (!get_check(buf))
1907 autoregister = FALSE;
1910 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1912 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1918 /* If there are some changes, overwrite the original file with new one */
1921 /* Copy contents of temporary file */
1923 tmp_fff = my_fopen(tmp_file, "r");
1924 pref_fff = my_fopen(pref_file, "w");
1926 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1927 fprintf(pref_fff, "%s\n", buf);
1929 my_fclose(pref_fff);
1933 /* Kill the temporary file */
1941 * Automatically register an auto-destroy preference line
1943 bool add_auto_register(object_type *o_ptr)
1946 char pref_file[1024];
1948 autopick_type an_entry, *entry = &an_entry;
1950 int match_autopick = is_autopick(o_ptr);
1952 /* Already registered */
1953 if (match_autopick != -1)
1956 byte act = autopick_list[match_autopick].action;
1959 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1960 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1961 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1962 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1964 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1966 if (act & DO_AUTOPICK) what = "auto-pickup";
1967 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1968 else if (act & DONT_AUTOPICK) what = "leave on floor";
1969 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1971 msg_format("The object is already registered to %s.", what);
1977 /* Known to be an artifact? */
1978 if ((object_known_p(o_ptr) &&
1979 (artifact_p(o_ptr) || o_ptr->art_name)) ||
1980 ((o_ptr->ident & IDENT_SENSE) &&
1981 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1983 char o_name[MAX_NLEN];
1985 /* Describe the object (with {terrible/special}) */
1986 object_desc(o_name, o_ptr, TRUE, 3);
1990 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1992 msg_format("You cannot auto-destroy %s.", o_name);
2000 if (!p_ptr->autopick_autoregister)
2002 /* Clear old auto registered lines */
2003 if (!clear_auto_register()) return FALSE;
2006 /* Try a filename with player name */
2007 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
2008 pref_fff = my_fopen(pref_file, "r");
2012 /* Use default name */
2013 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
2014 pref_fff = my_fopen(pref_file, "r");
2017 /* Check the header */
2021 if (my_fgets(pref_fff, buf, sizeof(buf)))
2023 /* No header found */
2024 p_ptr->autopick_autoregister = FALSE;
2029 if (streq(buf, autoregister_header))
2031 /* Found the header */
2032 p_ptr->autopick_autoregister = TRUE;
2038 /* Close read only FILE* */
2041 /* Open for append */
2042 pref_fff = my_fopen(pref_file, "a");
2047 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
2049 msg_format("Failed to open %s.", pref_file);
2057 if (!p_ptr->autopick_autoregister)
2059 /* Add the header */
2060 fprintf(pref_fff, "%s\n", autoregister_header);
2063 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
2064 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
2066 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
2067 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
2070 /* Now auto register is in-use */
2071 p_ptr->autopick_autoregister = TRUE;
2074 /* Get a preference entry */
2075 autopick_entry_from_object(entry, o_ptr);
2077 /* Set to auto-destroy (with no-display) */
2078 entry->action = DO_AUTODESTROY;
2080 /* Load the new line as preference */
2081 add_autopick_list(entry);
2083 /* Add a line to the file */
2084 /* Don't kill "entry" */
2085 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2087 /* Close the file */
2094 /******** Auto-picker/destroyer editor **********/
2096 #define MAX_YANK MAX_LINELEN
2097 #define MAX_LINES 3000
2099 #define MARK_MARK 0x01
2100 #define MARK_BY_SHIFT 0x02
2102 #define LSTAT_BYPASS 0x01
2103 #define LSTAT_EXPRESSION 0x02
2104 #define LSTAT_AUTOREGISTER 0x04
2106 #define QUIT_WITHOUT_SAVE 1
2107 #define QUIT_AND_SAVE 2
2110 * Struct for yank buffer
2112 typedef struct chain_str {
2113 struct chain_str *next;
2119 * Data struct for text editor
2125 int old_wid, old_hgt;
2127 int old_upper, old_left;
2131 object_type *search_o_ptr;
2133 cptr last_destroyed;
2135 chain_str_type *yank;
2139 byte states[MAX_LINES];
2151 * Dirty flag for text editor
2153 #define DIRTY_ALL 0x0001
2154 #define DIRTY_MODE 0x0004
2155 #define DIRTY_SCREEN 0x0008
2156 #define DIRTY_NOT_FOUND 0x0010
2157 #define DIRTY_NO_SEARCH 0x0020
2158 #define DIRTY_EXPRESSION 0x0040
2159 #define DIRTY_SKIP_INACTIVE 0x0080
2160 #define DIRTY_INACTIVE 0x0100
2163 * Describe which kind of object is Auto-picked/destroyed
2165 static void describe_autopick(char *buff, autopick_type *entry)
2167 cptr str = entry->name;
2168 byte act = entry->action;
2169 cptr insc = entry->insc;
2175 cptr before_str[100], body_str;
2178 body_str = "¥¢¥¤¥Æ¥à";
2180 /*** Collecting items ***/
2181 /*** Which can be absorbed into a slot as a bundle ***/
2182 if (IS_FLG(FLG_COLLECTING))
2183 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2185 /*** Unaware items ***/
2186 if (IS_FLG(FLG_UNAWARE))
2187 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2189 /*** Unidentified ***/
2190 if (IS_FLG(FLG_UNIDENTIFIED))
2191 before_str[before_n++] = "̤´ÕÄê¤Î";
2193 /*** Identified ***/
2194 if (IS_FLG(FLG_IDENTIFIED))
2195 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2197 /*** *Identified* ***/
2198 if (IS_FLG(FLG_STAR_IDENTIFIED))
2199 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2201 /*** Dice boosted (weapon of slaying) ***/
2202 if (IS_FLG(FLG_BOOSTED))
2204 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2208 /*** Weapons whose dd*ds is more than nn ***/
2209 if (IS_FLG(FLG_MORE_DICE))
2211 static char more_than_desc_str[] = "___";
2212 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2215 sprintf(more_than_desc_str,"%d", entry->dice);
2216 before_str[before_n++] = more_than_desc_str;
2217 before_str[before_n++] = "°Ê¾å¤Î";
2220 /*** Items whose magical bonus is more than nn ***/
2221 if (IS_FLG(FLG_MORE_BONUS))
2223 static char more_bonus_desc_str[] = "___";
2224 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2226 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2227 before_str[before_n++] = more_bonus_desc_str;
2228 before_str[before_n++] = ")°Ê¾å¤Î";
2231 /*** Worthless items ***/
2232 if (IS_FLG(FLG_WORTHLESS))
2233 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2236 if (IS_FLG(FLG_ARTIFACT))
2238 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2243 if (IS_FLG(FLG_EGO))
2245 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2250 if (IS_FLG(FLG_NAMELESS))
2252 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2256 /*** Rare equpiments ***/
2257 if (IS_FLG(FLG_RARE))
2259 before_str[before_n++] = "¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ò´Þ¤àÄÁ¤·¤¤";
2263 /*** Common equpiments ***/
2264 if (IS_FLG(FLG_COMMON))
2266 before_str[before_n++] = "¤¢¤ê¤Õ¤ì¤¿(¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ÎÄÁ¤·¤¤Êª¤Ç¤Ï¤Ê¤¤)";
2270 /*** Wanted monster's corpse/skeletons ***/
2271 if (IS_FLG(FLG_WANTED))
2273 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2274 body_str = "»àÂΤä¹ü";
2277 /*** Human corpse/skeletons (for Daemon magic) ***/
2278 if (IS_FLG(FLG_HUMAN))
2280 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2281 body_str = "»àÂΤä¹ü";
2284 /*** Unique monster's corpse/skeletons/statues ***/
2285 if (IS_FLG(FLG_UNIQUE))
2287 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2288 body_str = "»àÂΤä¹ü";
2291 /*** Unreadable spellbooks ***/
2292 if (IS_FLG(FLG_UNREADABLE))
2294 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2295 body_str = "ËâË¡½ñ";
2298 /*** First realm spellbooks ***/
2299 if (IS_FLG(FLG_REALM1))
2301 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2302 body_str = "ËâË¡½ñ";
2305 /*** Second realm spellbooks ***/
2306 if (IS_FLG(FLG_REALM2))
2308 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2309 body_str = "ËâË¡½ñ";
2312 /*** First rank spellbooks ***/
2313 if (IS_FLG(FLG_FIRST))
2315 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2316 body_str = "ËâË¡½ñ";
2319 /*** Second rank spellbooks ***/
2320 if (IS_FLG(FLG_SECOND))
2322 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2323 body_str = "ËâË¡½ñ";
2326 /*** Third rank spellbooks ***/
2327 if (IS_FLG(FLG_THIRD))
2329 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2330 body_str = "ËâË¡½ñ";
2333 /*** Fourth rank spellbooks ***/
2334 if (IS_FLG(FLG_FOURTH))
2336 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2337 body_str = "ËâË¡½ñ";
2341 if (IS_FLG(FLG_ITEMS))
2342 ; /* Nothing to do */
2343 else if (IS_FLG(FLG_WEAPONS))
2345 else if (IS_FLG(FLG_ARMORS))
2347 else if (IS_FLG(FLG_MISSILES))
2348 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2349 else if (IS_FLG(FLG_DEVICES))
2350 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2351 else if (IS_FLG(FLG_LIGHTS))
2352 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2353 else if (IS_FLG(FLG_JUNKS))
2354 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2355 else if (IS_FLG(FLG_SPELLBOOKS))
2356 body_str = "ËâË¡½ñ";
2357 else if (IS_FLG(FLG_HAFTED))
2359 else if (IS_FLG(FLG_SHIELDS))
2361 else if (IS_FLG(FLG_BOWS))
2362 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2363 else if (IS_FLG(FLG_RINGS))
2365 else if (IS_FLG(FLG_AMULETS))
2366 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2367 else if (IS_FLG(FLG_SUITS))
2369 else if (IS_FLG(FLG_CLOAKS))
2370 body_str = "¥¯¥í¡¼¥¯";
2371 else if (IS_FLG(FLG_HELMS))
2372 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2373 else if (IS_FLG(FLG_GLOVES))
2375 else if (IS_FLG(FLG_BOOTS))
2376 body_str = "¥Ö¡¼¥Ä";
2377 else if (IS_FLG(FLG_FAVORITE))
2378 body_str = "ÆÀ°ÕÉð´ï";
2382 strcat(buff, "Á´¤Æ¤Î");
2383 else for (i = 0; i < before_n && before_str[i]; i++)
2384 strcat(buff, before_str[i]);
2386 strcat(buff, body_str);
2396 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2397 strncat(buff, str, 80);
2399 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2401 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2406 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2408 if (my_strstr(insc, "%%all"))
2409 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2410 else if (my_strstr(insc, "%all"))
2411 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2412 else if (my_strstr(insc, "%%"))
2413 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2414 else if (my_strstr(insc, "%"))
2415 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2417 strcat(buff, "¤È¹ï¤ó¤Ç");
2422 if (act & DONT_AUTOPICK)
2423 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2424 else if (act & DO_AUTODESTROY)
2425 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2426 else if (act & DO_QUERY_AUTOPICK)
2427 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2429 strcat(buff, "½¦¤¦¡£");
2431 if (act & DO_DISPLAY)
2433 if (act & DONT_AUTOPICK)
2434 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2435 else if (act & DO_AUTODESTROY)
2436 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2438 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2441 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2445 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2446 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2450 /*** Collecting items ***/
2451 /*** Which can be absorbed into a slot as a bundle ***/
2452 if (IS_FLG(FLG_COLLECTING))
2453 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2455 /*** Unaware items ***/
2456 if (IS_FLG(FLG_UNAWARE))
2458 before_str[before_n++] = "unidentified";
2459 whose_str[whose_n++] = "basic abilities are not known";
2462 /*** Unidentified ***/
2463 if (IS_FLG(FLG_UNIDENTIFIED))
2464 before_str[before_n++] = "unidentified";
2466 /*** Identified ***/
2467 if (IS_FLG(FLG_IDENTIFIED))
2468 before_str[before_n++] = "identified";
2470 /*** *Identified* ***/
2471 if (IS_FLG(FLG_STAR_IDENTIFIED))
2472 before_str[before_n++] = "fully identified";
2474 /*** Rare equpiments ***/
2475 if (IS_FLG(FLG_RARE))
2477 before_str[before_n++] = "very rare";
2478 body_str = "equipments";
2479 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2482 /*** Common equpiments ***/
2483 if (IS_FLG(FLG_COMMON))
2485 before_str[before_n++] = "relatively common";
2486 body_str = "equipments";
2487 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2490 /*** Worthless items ***/
2491 if (IS_FLG(FLG_WORTHLESS))
2493 before_str[before_n++] = "worthless";
2494 which_str[which_n++] = "can not be sold at stores";
2498 if (IS_FLG(FLG_ARTIFACT))
2500 before_str[before_n++] = "artifact";
2504 if (IS_FLG(FLG_EGO))
2506 before_str[before_n++] = "ego";
2510 if (IS_FLG(FLG_NAMELESS))
2512 body_str = "equipment";
2513 which_str[which_n++] = "is neither ego-item nor artifact";
2516 /*** Dice boosted (weapon of slaying) ***/
2517 if (IS_FLG(FLG_BOOSTED))
2519 body_str = "weapons";
2520 whose_str[whose_n++] = "damage dice is bigger than normal";
2523 /*** Weapons whose dd*ds is more than nn ***/
2524 if (IS_FLG(FLG_MORE_DICE))
2526 static char more_than_desc_str[] =
2527 "maximum damage from dice is bigger than __";
2528 body_str = "weapons";
2530 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2532 whose_str[whose_n++] = more_than_desc_str;
2535 /*** Items whose magical bonus is more than nn ***/
2536 if (IS_FLG(FLG_MORE_BONUS))
2538 static char more_bonus_desc_str[] =
2539 "magical bonus is bigger than (+__)";
2541 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2542 "%d)", entry->bonus);
2543 whose_str[whose_n++] = more_bonus_desc_str;
2546 /*** Wanted monster's corpse/skeletons ***/
2547 if (IS_FLG(FLG_WANTED))
2549 body_str = "corpse or skeletons";
2550 which_str[which_n++] = "is wanted at the Hunter's Office";
2553 /*** Human corpse/skeletons (for Daemon magic) ***/
2554 if (IS_FLG(FLG_HUMAN))
2556 before_str[before_n++] = "humanoid";
2557 body_str = "corpse or skeletons";
2558 which_str[which_n++] = "can be used for Daemon magic";
2561 /*** Unique monster's corpse/skeletons/statues ***/
2562 if (IS_FLG(FLG_UNIQUE))
2564 before_str[before_n++] = "unique monster's";
2565 body_str = "corpse or skeletons";
2568 /*** Unreadable spellbooks ***/
2569 if (IS_FLG(FLG_UNREADABLE))
2571 body_str = "spellbooks";
2572 after_str[after_n++] = "of different realms from yours";
2575 /*** First realm spellbooks ***/
2576 if (IS_FLG(FLG_REALM1))
2578 body_str = "spellbooks";
2579 after_str[after_n++] = "of your first realm";
2582 /*** Second realm spellbooks ***/
2583 if (IS_FLG(FLG_REALM2))
2585 body_str = "spellbooks";
2586 after_str[after_n++] = "of your second realm";
2589 /*** First rank spellbooks ***/
2590 if (IS_FLG(FLG_FIRST))
2592 before_str[before_n++] = "first one of four";
2593 body_str = "spellbooks";
2596 /*** Second rank spellbooks ***/
2597 if (IS_FLG(FLG_SECOND))
2599 before_str[before_n++] = "second one of four";
2600 body_str = "spellbooks";
2603 /*** Third rank spellbooks ***/
2604 if (IS_FLG(FLG_THIRD))
2606 before_str[before_n++] = "third one of four";
2607 body_str = "spellbooks";
2610 /*** Fourth rank spellbooks ***/
2611 if (IS_FLG(FLG_FOURTH))
2613 before_str[before_n++] = "fourth one of four";
2614 body_str = "spellbooks";
2618 if (IS_FLG(FLG_ITEMS))
2619 ; /* Nothing to do */
2620 else if (IS_FLG(FLG_WEAPONS))
2621 body_str = "weapons";
2622 else if (IS_FLG(FLG_ARMORS))
2623 body_str = "armors";
2624 else if (IS_FLG(FLG_MISSILES))
2625 body_str = "shots, arrows or crossbow bolts";
2626 else if (IS_FLG(FLG_DEVICES))
2627 body_str = "scrolls, wands, staves or rods";
2628 else if (IS_FLG(FLG_LIGHTS))
2629 body_str = "light sources";
2630 else if (IS_FLG(FLG_JUNKS))
2631 body_str = "junk such as broken sticks";
2632 else if (IS_FLG(FLG_SPELLBOOKS))
2633 body_str = "spellbooks";
2634 else if (IS_FLG(FLG_HAFTED))
2635 body_str = "hafted weapons";
2636 else if (IS_FLG(FLG_SHIELDS))
2637 body_str = "shields";
2638 else if (IS_FLG(FLG_BOWS))
2639 body_str = "slings, bows or crossbows";
2640 else if (IS_FLG(FLG_RINGS))
2642 else if (IS_FLG(FLG_AMULETS))
2643 body_str = "amulets";
2644 else if (IS_FLG(FLG_SUITS))
2645 body_str = "body armors";
2646 else if (IS_FLG(FLG_CLOAKS))
2647 body_str = "cloaks";
2648 else if (IS_FLG(FLG_HELMS))
2649 body_str = "helms or crowns";
2650 else if (IS_FLG(FLG_GLOVES))
2651 body_str = "gloves";
2652 else if (IS_FLG(FLG_BOOTS))
2654 else if (IS_FLG(FLG_FAVORITE))
2655 body_str = "favorite weapons";
2657 /* Prepare a string for item name */
2664 whose_str[whose_n++] = "name is beginning with \"";
2667 which_str[which_n++] = "have \"";
2671 /* Describe action flag */
2672 if (act & DONT_AUTOPICK)
2673 strcpy(buff, "Leave on floor ");
2674 else if (act & DO_AUTODESTROY)
2675 strcpy(buff, "Destroy ");
2676 else if (act & DO_QUERY_AUTOPICK)
2677 strcpy(buff, "Ask to pick up ");
2679 strcpy(buff, "Pickup ");
2681 /* Auto-insctiption */
2684 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2686 if (my_strstr(insc, "%all"))
2687 strcat(buff, ", replacing %all with code string representing all abilities,");
2688 else if (my_strstr(insc, "%"))
2689 strcat(buff, ", replacing % with code string representing extra random abilities,");
2691 strcat(buff, " on ");
2696 strcat(buff, "all ");
2697 else for (i = 0; i < before_n && before_str[i]; i++)
2699 strcat(buff, before_str[i]);
2704 strcat(buff, body_str);
2707 for (i = 0; i < after_n && after_str[i]; i++)
2710 strcat(buff, after_str[i]);
2714 for (i = 0; i < whose_n && whose_str[i]; i++)
2717 strcat(buff, " whose ");
2719 strcat(buff, ", and ");
2721 strcat(buff, whose_str[i]);
2724 /* Item name ; whose name is beginning with "str" */
2731 /* whose ..., and which .... */
2732 if (whose_n && which_n)
2733 strcat(buff, ", and ");
2736 for (i = 0; i < which_n && which_str[i]; i++)
2739 strcat(buff, " which ");
2741 strcat(buff, ", and ");
2743 strcat(buff, which_str[i]);
2746 /* Item name ; which have "str" as part of its name */
2749 strncat(buff, str, 80);
2750 strcat(buff, "\" as part of its name");
2754 /* Describe whether it will be displayed on the full map or not */
2755 if (act & DO_DISPLAY)
2757 if (act & DONT_AUTOPICK)
2758 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2759 else if (act & DO_AUTODESTROY)
2760 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2762 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2765 strcat(buff, " Not displayed in the full map.");
2772 * Read whole lines of a file to memory
2774 static cptr *read_text_lines(cptr filename, bool user)
2776 cptr *lines_list = NULL;
2784 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2788 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2792 fff = my_fopen(buf, "r");
2796 /* Allocate list of pointers */
2797 C_MAKE(lines_list, MAX_LINES, cptr);
2800 while (0 == my_fgets(fff, buf, sizeof(buf)))
2802 lines_list[lines++] = string_make(buf);
2803 if (lines >= MAX_LINES - 1) break;
2806 lines_list[0] = string_make("");
2811 if (!fff) return NULL;
2816 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2821 *filename_mode_p = PT_WITH_PNAME;
2822 strcpy(buf, pickpref_filename(*filename_mode_p));
2823 lines_list = read_text_lines(buf, TRUE);
2827 *filename_mode_p = PT_DEFAULT;
2828 strcpy(buf, pickpref_filename(*filename_mode_p));
2829 lines_list = read_text_lines(buf, TRUE);
2834 strcpy(buf, pickpref_filename(*filename_mode_p));
2835 lines_list = read_text_lines(buf, FALSE);
2840 /* Allocate list of pointers */
2841 C_MAKE(lines_list, MAX_LINES, cptr);
2842 lines_list[0] = string_make("");
2849 * Write whole lines of memory to a file.
2851 static bool write_text_lines(cptr filename, cptr *lines_list)
2858 /* Build the filename */
2859 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2862 fff = my_fopen(buf, "w");
2865 for (lines = 0; lines_list[lines]; lines++)
2866 my_fputs(fff, lines_list[lines], 1024);
2871 if (!fff) return FALSE;
2877 * Free memory of lines_list.
2879 static void free_text_lines(cptr *lines_list)
2883 for (lines = 0; lines_list[lines]; lines++)
2884 string_free(lines_list[lines]);
2886 /* free list of pointers */
2887 C_FREE((char **)lines_list, MAX_LINES, char *);
2892 * Delete or insert string
2894 static void toggle_keyword(text_body_type *tb, int flg)
2900 /* Some lines are selected */
2903 by1 = MIN(tb->my, tb->cy);
2904 by2 = MAX(tb->my, tb->cy);
2907 /* No mark -- Select current line */
2908 else /* if (!tb->mark) */
2914 /* Set/Reset flag of each line */
2915 for (y = by1; y <= by2; y++)
2917 autopick_type an_entry, *entry = &an_entry;
2919 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2921 string_free(tb->lines_list[y]);
2925 /* Add? or Remove? */
2926 if (!IS_FLG(flg)) add = TRUE;
2929 /* No more change */
2933 /* You can use only one noun flag */
2934 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2937 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2941 /* You can use only one identify state flag */
2942 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2945 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2949 /* You can use only one flag in artifact/ego/nameless */
2950 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
2953 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
2957 /* You can use only one flag in rare/common */
2958 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
2961 for (i = FLG_RARE; i <= FLG_COMMON; i++)
2965 if (add) ADD_FLG(flg);
2968 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2971 tb->dirty_flags |= DIRTY_ALL;
2973 /* Text is changed */
2980 * Change command letter
2982 static void toggle_command_letter(text_body_type *tb, byte flg)
2984 autopick_type an_entry, *entry = &an_entry;
2989 /* Some lines are selected */
2992 by1 = MIN(tb->my, tb->cy);
2993 by2 = MAX(tb->my, tb->cy);
2996 /* No mark -- Select current line */
2997 else /* if (!tb->mark) */
3003 /* Set/Reset flag of each line */
3004 for (y = by1; y <= by2; y++)
3008 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3010 string_free(tb->lines_list[y]);
3014 /* Add? or Remove? */
3015 if (!(entry->action & flg)) add = TRUE;
3018 /* No more change */
3022 /* Count number of letter (by negative number) */
3023 if (entry->action & DONT_AUTOPICK) wid--;
3024 else if (entry->action & DO_AUTODESTROY) wid--;
3025 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3026 if (!(entry->action & DO_DISPLAY)) wid--;
3028 /* Set/Reset the flag */
3029 if (flg != DO_DISPLAY)
3031 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3032 if (add) entry->action |= flg;
3033 else entry->action |= DO_AUTOPICK;
3037 entry->action &= ~(DO_DISPLAY);
3038 if (add) entry->action |= flg;
3041 /* Correct cursor location */
3044 if (entry->action & DONT_AUTOPICK) wid++;
3045 else if (entry->action & DO_AUTODESTROY) wid++;
3046 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3047 if (!(entry->action & DO_DISPLAY)) wid++;
3049 if (wid > 0) tb->cx++;
3050 if (wid < 0 && tb->cx > 0) tb->cx--;
3053 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3056 tb->dirty_flags |= DIRTY_ALL;
3058 /* Text is changed */
3064 * Delete or insert string
3066 static void add_keyword(text_body_type *tb, int flg)
3070 /* Some lines are selected */
3073 by1 = MIN(tb->my, tb->cy);
3074 by2 = MAX(tb->my, tb->cy);
3077 /* No mark -- Select current line */
3078 else /* if (!tb->mark) */
3084 /* Set/Reset flag of each line */
3085 for (y = by1; y <= by2; y++)
3087 autopick_type an_entry, *entry = &an_entry;
3089 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3091 /* There is the flag already */
3094 /* Free memory for the entry */
3095 autopick_free_entry(entry);
3100 string_free(tb->lines_list[y]);
3102 /* Remove all noun flag */
3103 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3106 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3112 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3115 tb->dirty_flags |= DIRTY_ALL;
3117 /* Text is changed */
3124 * Check if this line is expression or not.
3125 * And update it if it is.
3127 static void check_expression_line(text_body_type *tb, int y)
3129 cptr s = tb->lines_list[y];
3131 if ((s[0] == '?' && s[1] == ':') ||
3132 (tb->states[y] & LSTAT_BYPASS))
3134 /* Expressions need re-evaluation */
3135 tb->dirty_flags |= DIRTY_EXPRESSION;
3141 * Insert return code and split the line
3143 static bool insert_return_code(text_body_type *tb)
3145 char buf[MAX_LINELEN];
3148 for (k = 0; tb->lines_list[k]; k++)
3149 /* count number of lines */ ;
3151 if (k >= MAX_LINES - 2) return FALSE;
3154 /* Move down lines */
3155 for (; tb->cy < k; k--)
3157 tb->lines_list[k+1] = tb->lines_list[k];
3158 tb->states[k+1] = tb->states[k];
3161 /* Split current line */
3162 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3165 if (iskanji(tb->lines_list[tb->cy][i]))
3166 buf[j++] = tb->lines_list[tb->cy][i++];
3168 buf[j++] = tb->lines_list[tb->cy][i];
3171 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3172 string_free(tb->lines_list[tb->cy]);
3173 tb->lines_list[tb->cy] = string_make(buf);
3175 /* Expressions need re-evaluation */
3176 tb->dirty_flags |= DIRTY_EXPRESSION;
3178 /* Text is changed */
3186 * Choose an item and get auto-picker entry from it.
3188 static object_type *choose_object(cptr q, cptr s)
3192 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3194 /* Get the item (in the pack) */
3195 if (item >= 0) return &inventory[item];
3197 /* Get the item (on the floor) */
3198 else return &o_list[0 - item];
3203 * Choose an item and get auto-picker entry from it.
3205 static bool entry_from_choosed_object(autopick_type *entry)
3212 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3213 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3215 q = "Enter which item? ";
3216 s = "You have nothing to enter.";
3218 o_ptr = choose_object(q, s);
3219 if (!o_ptr) return FALSE;
3221 autopick_entry_from_object(entry, o_ptr);
3227 * Choose an item for search
3229 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3231 char buf[MAX_NLEN+20];
3237 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3238 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3240 q = "Enter which item? ";
3241 s = "You have nothing to enter.";
3243 o_ptr = choose_object(q, s);
3244 if (!o_ptr) return 0;
3248 string_free(*search_strp);
3249 object_desc(buf, *o_handle, FALSE, 3);
3250 *search_strp = string_make(format("<%s>", buf));
3256 * Prepare for search by destroyed object
3258 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3260 char buf[MAX_NLEN+20];
3262 if (!autopick_last_destroyed_object.k_idx) return 0;
3264 *o_handle = &autopick_last_destroyed_object;
3266 string_free(*search_strp);
3267 object_desc(buf, *o_handle, FALSE, 3);
3268 *search_strp = string_make(format("<%s>", buf));
3274 * Choose an item or string for search
3276 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3282 * TERM_YELLOW : Overwrite mode
3283 * TERM_WHITE : Insert mode
3285 byte color = TERM_YELLOW;
3286 char buf[MAX_NLEN+20];
3290 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3292 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3294 int col = sizeof(prompt) - 1;
3296 /* Prepare string buffer for edit */
3297 if (*search_strp) strcpy(buf, *search_strp);
3300 /* Object searching mode */
3303 color = TERM_L_GREEN;
3306 /* Display prompt */
3316 /* Display the string */
3317 Term_erase(col, 0, 255);
3318 Term_putstr(col, 0, -1, color, buf);
3321 Term_gotoxy(col + pos, 0);
3323 /* Get a special key code */
3324 skey = inkey_special();
3326 /* Analyze the key */
3334 /* Now on insert mode */
3337 /* No move at beginning of line */
3338 if (0 == pos) break;
3342 int next_pos = i + 1;
3345 if (iskanji(buf[i])) next_pos++;
3348 /* Is there the cursor at next position? */
3349 if (next_pos >= pos) break;
3355 /* Get previous position */
3363 /* Now on insert mode */
3366 /* No move at end of line */
3367 if ('\0' == buf[pos]) break;
3371 if (iskanji(buf[pos])) pos += 2;
3389 if (*o_handle) return (back ? -1 : 1);
3390 string_free(*search_strp);
3391 *search_strp = string_make(buf);
3393 return (back ? -1 : 1);
3397 return get_object_for_search(o_handle, search_strp);
3400 /* Prepare string for destroyed object if there is one. */
3401 if (get_destroyed_object_for_search(o_handle, search_strp))
3411 /* Now on insert mode */
3414 /* No move at beginning of line */
3415 if (0 == pos) break;
3419 int next_pos = i + 1;
3422 if (iskanji(buf[i])) next_pos++;
3425 /* Is there the cursor at next position? */
3426 if (next_pos >= pos) break;
3432 /* Get previous position */
3435 /* Fall through to 'Delete key' */
3444 /* Now on insert mode */
3447 /* No move at end of line */
3448 if ('\0' == buf[pos]) break;
3450 /* Position of next character */
3454 /* Next character is one more byte away */
3455 if (iskanji(buf[pos])) src++;
3460 /* Move characters at src to dst */
3461 while ('\0' != (buf[dst++] = buf[src++]))
3469 /* Insert a character */
3474 /* Ignore special keys */
3475 if (skey & SKEY_MASK) break;
3477 /* Get a character code */
3480 /* Was non insert mode? */
3481 if (color != TERM_WHITE)
3483 /* Was object searching mode */
3484 if (color == TERM_L_GREEN)
3486 /* Cancel the mode */
3489 /* Remove indicating string */
3490 string_free(*search_strp);
3491 *search_strp = NULL;
3494 /* Overwrite default string */
3497 /* Go to insert mode */
3501 /* Save right part of string */
3502 strcpy(tmp, buf + pos);
3508 /* Bypass macro processing */
3526 if (pos < len && (isprint(c) || iskana(c)))
3528 if (pos < len && isprint(c))
3542 /* Write back the left part of string */
3543 my_strcat(buf, tmp, len + 1);
3550 /* Object searching mode was cancelled? */
3551 if (*o_handle && color != TERM_L_GREEN)
3553 /* Cancel the mode */
3556 /* Remove indicating string */
3558 string_free(*search_strp);
3559 *search_strp = NULL;
3564 } /* while (TRUE) */
3569 * Search next line matches for o_ptr
3571 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3573 autopick_type an_entry, *entry = &an_entry;
3574 char o_name[MAX_NLEN];
3575 int bypassed_cy = -1;
3577 /* Start searching from current cursor position */
3580 /* Prepare object name string first */
3581 object_desc(o_name, o_ptr, FALSE, 3);
3583 /* Convert the string to lower case */
3584 str_tolower(o_name);
3591 if (!tb->lines_list[++i]) break;
3598 /* Is this line is a correct entry? */
3599 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3601 /* Does this line match to the object? */
3602 if (!is_autopick_aux(o_ptr, entry, o_name)) continue;
3605 /* Found a line but it's inactive */
3606 if (tb->states[i] & LSTAT_BYPASS)
3608 /* If it is first found, remember it */
3609 if (bypassed_cy == -1) bypassed_cy = i;
3612 /* Found an active line! */
3615 /* Move to this line */
3619 if (bypassed_cy != -1)
3621 /* Mark as some lines are skipped */
3622 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3630 if (bypassed_cy != -1)
3632 /* Move to the remembered line */
3634 tb->cy = bypassed_cy;
3636 /* Mark as this line is inactive */
3637 tb->dirty_flags |= DIRTY_INACTIVE;
3642 /* Mark as NOT FOUND */
3643 tb->dirty_flags |= DIRTY_NOT_FOUND;
3651 * Search next line matches to the string
3653 static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
3655 int bypassed_cy = -1;
3656 int bypassed_cx = 0;
3658 /* Start searching from current cursor position */
3668 if (!tb->lines_list[++i]) break;
3675 /* Look for the string pattern */
3676 pos = my_strstr(tb->lines_list[i], search_str);
3681 /* Found a line but it's inactive */
3682 if ((tb->states[i] & LSTAT_BYPASS) &&
3683 !(tb->states[i] & LSTAT_EXPRESSION))
3685 /* If it is first found, remember it */
3686 if (bypassed_cy == -1)
3689 bypassed_cx = (int)(pos - tb->lines_list[i]);
3693 /* Found an active line! */
3696 /* Move to this location */
3697 tb->cx = (int)(pos - tb->lines_list[i]);
3700 if (bypassed_cy != -1)
3702 /* Mark as some lines are skipped */
3703 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3711 if (bypassed_cy != -1)
3713 /* Move to the remembered line */
3714 tb->cx = bypassed_cx;
3715 tb->cy = bypassed_cy;
3717 /* Mark as this line is inactive */
3718 tb->dirty_flags |= DIRTY_INACTIVE;
3723 /* Mark as NOT FOUND */
3724 tb->dirty_flags |= DIRTY_NOT_FOUND;
3734 * Editor command id's
3737 #define EC_SAVEQUIT 2
3748 #define EC_PGDOWN 13
3750 #define EC_BOTTOM 15
3755 #define EC_KILL_LINE 20
3756 #define EC_DELETE_CHAR 21
3757 #define EC_BACKSPACE 22
3758 #define EC_SEARCH_STR 23
3759 #define EC_SEARCH_FORW 24
3760 #define EC_SEARCH_BACK 25
3761 #define EC_SEARCH_OBJ 26
3762 #define EC_SEARCH_DESTROYED 27
3763 #define EC_INSERT_OBJECT 28
3764 #define EC_INSERT_DESTROYED 29
3765 #define EC_INSERT_BLOCK 30
3766 #define EC_INSERT_MACRO 31
3767 #define EC_INSERT_KEYMAP 32
3768 #define EC_CL_AUTOPICK 33
3769 #define EC_CL_DESTROY 34
3770 #define EC_CL_LEAVE 35
3771 #define EC_CL_QUERY 36
3772 #define EC_CL_NO_DISP 37
3773 #define EC_OK_COLLECTING 38
3774 #define EC_IK_UNAWARE 39
3775 #define EC_IK_UNIDENTIFIED 40
3776 #define EC_IK_IDENTIFIED 41
3777 #define EC_IK_STAR_IDENTIFIED 42
3778 #define EC_OK_BOOSTED 43
3779 #define EC_OK_MORE_DICE 44
3780 #define EC_OK_MORE_BONUS 45
3781 #define EC_OK_WORTHLESS 46
3782 #define EC_OK_ARTIFACT 47
3783 #define EC_OK_EGO 48
3784 #define EC_OK_NAMELESS 49
3785 #define EC_OK_RARE 50
3786 #define EC_OK_COMMON 51
3787 #define EC_OK_WANTED 52
3788 #define EC_OK_UNIQUE 53
3789 #define EC_OK_HUMAN 54
3790 #define EC_OK_UNREADABLE 55
3791 #define EC_OK_REALM1 56
3792 #define EC_OK_REALM2 57
3793 #define EC_OK_FIRST 58
3794 #define EC_OK_SECOND 59
3795 #define EC_OK_THIRD 60
3796 #define EC_OK_FOURTH 61
3797 #define EC_KK_WEAPONS 62
3798 #define EC_KK_FAVORITE 63
3799 #define EC_KK_ARMORS 64
3800 #define EC_KK_MISSILES 65
3801 #define EC_KK_DEVICES 66
3802 #define EC_KK_LIGHTS 67
3803 #define EC_KK_JUNKS 68
3804 #define EC_KK_SPELLBOOKS 69
3805 #define EC_KK_SHIELDS 70
3806 #define EC_KK_BOWS 71
3807 #define EC_KK_RINGS 72
3808 #define EC_KK_AMULETS 73
3809 #define EC_KK_SUITS 74
3810 #define EC_KK_CLOAKS 75
3811 #define EC_KK_HELMS 76
3812 #define EC_KK_GLOVES 77
3813 #define EC_KK_BOOTS 78
3819 #define MN_QUIT "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»"
3820 #define MN_SAVEQUIT "¥»¡¼¥Ö¤·¤Æ½ªÎ»"
3821 #define MN_REVERT "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ"
3822 #define MN_HELP "¥Ø¥ë¥×"
3824 #define MN_MOVE "¥«¡¼¥½¥ë°ÜÆ°"
3825 #define MN_LEFT "º¸"
3826 #define MN_DOWN "²¼"
3828 #define MN_RIGHT "±¦"
3829 #define MN_BOL "¹Ô¤ÎÀèƬ"
3830 #define MN_EOL "¹Ô¤Î½ªÃ¼"
3831 #define MN_PGUP "¾å¤Î¥Ú¡¼¥¸"
3832 #define MN_PGDOWN "²¼¤Î¥Ú¡¼¥¸"
3833 #define MN_TOP "1¹ÔÌܤذÜÆ°"
3834 #define MN_BOTTOM "ºÇ²¼¹Ô¤Ø°ÜÆ°"
3836 #define MN_EDIT "ÊÔ½¸"
3837 #define MN_CUT "¥«¥Ã¥È"
3838 #define MN_COPY "¥³¥Ô¡¼"
3839 #define MN_PASTE "¥Ú¡¼¥¹¥È"
3840 #define MN_BLOCK "ÁªÂòÈϰϤλØÄê"
3841 #define MN_KILL_LINE "¹Ô¤Î»Ä¤ê¤òºï½ü"
3842 #define MN_DELETE_CHAR "1ʸ»úºï½ü"
3843 #define MN_BACKSPACE "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹"
3844 #define MN_RETURN "²þ¹Ô"
3845 #define MN_RETURN "²þ¹Ô"
3847 #define MN_SEARCH "¸¡º÷"
3848 #define MN_SEARCH_STR "ʸ»úÎó¤Ç¸¡º÷"
3849 #define MN_SEARCH_FORW "Á°Êý¤ØºÆ¸¡º÷"
3850 #define MN_SEARCH_BACK "¸åÊý¤ØºÆ¸¡º÷"
3851 #define MN_SEARCH_OBJ "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷"
3852 #define MN_SEARCH_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷"
3854 #define MN_INSERT "¿§¡¹ÁÞÆþ"
3855 #define MN_INSERT_OBJECT "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3856 #define MN_INSERT_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3857 #define MN_INSERT_BLOCK "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ"
3858 #define MN_INSERT_MACRO "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ"
3859 #define MN_INSERT_KEYMAP "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ"
3862 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/\x95\xfaÃÖ¤ÎÁªÂò"
3864 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò"
3866 #define MN_CL_AUTOPICK "¡Ö ¡× (¼«Æ°½¦¤¤)"
3867 #define MN_CL_DESTROY "¡Ö!¡× (¼«Æ°Ç˲õ)"
3869 #define MN_CL_LEAVE "¡Ö~¡× (\x95\xfaÃÖ)"
3871 #define MN_CL_LEAVE "¡Ö~¡× (ÊüÃÖ)"
3873 #define MN_CL_QUERY "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)"
3874 #define MN_CL_NO_DISP "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)"
3876 #define MN_ADJECTIVE_GEN "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò"
3878 #define MN_ADJECTIVE_SPECIAL "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò"
3879 #define MN_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)"
3880 #define MN_MORE_DICE "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)"
3881 #define MN_MORE_BONUS "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)"
3882 #define MN_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)"
3883 #define MN_EGO "¥¨¥´ (ÁõÈ÷)"
3884 #define MN_NAMELESS "̵ÌäΠ(ÁõÈ÷)"
3885 #define MN_RARE "¥ì¥¢¤Ê (ÁõÈ÷)"
3886 #define MN_COMMON "¤¢¤ê¤Õ¤ì¤¿ (ÁõÈ÷)"
3887 #define MN_WANTED "¾Þ¶â¼ó¤Î (»àÂÎ)"
3888 #define MN_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)"
3889 #define MN_HUMAN "¿Í´Ö¤Î (»àÂÎ)"
3890 #define MN_UNREADABLE "Æɤá¤Ê¤¤ (ËâË¡½ñ)"
3891 #define MN_REALM1 "Âè°ìÎΰè¤Î (ËâË¡½ñ)"
3892 #define MN_REALM2 "ÂèÆóÎΰè¤Î (ËâË¡½ñ)"
3893 #define MN_FIRST "1ºýÌܤΠ(ËâË¡½ñ)"
3894 #define MN_SECOND "2ºýÌܤΠ(ËâË¡½ñ)"
3895 #define MN_THIRD "3ºýÌܤΠ(ËâË¡½ñ)"
3896 #define MN_FOURTH "4ºýÌܤΠ(ËâË¡½ñ)"
3898 #define MN_NOUN "̾»ì¤ÎÁªÂò"
3902 #define MN_QUIT "Quit without save"
3903 #define MN_SAVEQUIT "Save & Quit"
3904 #define MN_REVERT "Revert all changes"
3905 #define MN_HELP "Help"
3907 #define MN_MOVE "Move cursor"
3908 #define MN_LEFT "Left"
3909 #define MN_DOWN "Down"
3911 #define MN_RIGHT "Right"
3912 #define MN_BOL "Beggining of line"
3913 #define MN_EOL "End of line"
3914 #define MN_PGUP "Page up"
3915 #define MN_PGDOWN "Page down"
3916 #define MN_TOP "Top"
3917 #define MN_BOTTOM "Bottom"
3919 #define MN_EDIT "Edit"
3920 #define MN_CUT "Cut"
3921 #define MN_COPY "Copy"
3922 #define MN_PASTE "Paste"
3923 #define MN_BLOCK "Select block"
3924 #define MN_KILL_LINE "Kill rest of line"
3925 #define MN_DELETE_CHAR "Delete character"
3926 #define MN_BACKSPACE "Backspace"
3927 #define MN_RETURN "Return"
3928 #define MN_RETURN "Return"
3930 #define MN_SEARCH "Search"
3931 #define MN_SEARCH_STR "Search by string"
3932 #define MN_SEARCH_FORW "Search forward"
3933 #define MN_SEARCH_BACK "Search backward"
3934 #define MN_SEARCH_OBJ "Search by inventory object"
3935 #define MN_SEARCH_DESTROYED "Search by destroyed object"
3937 #define MN_INSERT "Insert..."
3938 #define MN_INSERT_OBJECT "Insert name of choosen object"
3939 #define MN_INSERT_DESTROYED "Insert name of destroyed object"
3940 #define MN_INSERT_BLOCK "Insert conditional block"
3941 #define MN_INSERT_MACRO "Insert a macro definition"
3942 #define MN_INSERT_KEYMAP "Insert a keymap definition"
3944 #define MN_COMMAND_LETTER "Command letter"
3945 #define MN_CL_AUTOPICK "' ' (Auto pick)"
3946 #define MN_CL_DESTROY "'!' (Auto destroy)"
3947 #define MN_CL_LEAVE "'~' (Leave it on the floor)"
3948 #define MN_CL_QUERY "';' (Query to pick up)"
3949 #define MN_CL_NO_DISP "'(' (No display on the large map)"
3951 #define MN_ADJECTIVE_GEN "Adjective (general)"
3953 #define MN_ADJECTIVE_SPECIAL "Adjective (special)"
3954 #define MN_BOOSTED "dice boosted (weapons)"
3955 #define MN_MORE_DICE "more than # dice (weapons)"
3956 #define MN_MORE_BONUS "more bonus than # (rings etc.)"
3957 #define MN_ARTIFACT "artifact (equipments)"
3958 #define MN_EGO "ego (equipments)"
3959 #define MN_NAMELESS "nameless (equipments)"
3960 #define MN_RARE "rare (equipments)"
3961 #define MN_COMMON "common (equipments)"
3962 #define MN_WANTED "wanted (corpse)"
3963 #define MN_UNIQUE "unique (corpse)"
3964 #define MN_HUMAN "human (corpse)"
3965 #define MN_UNREADABLE "unreadable (spellbooks)"
3966 #define MN_REALM1 "realm1 (spellbooks)"
3967 #define MN_REALM2 "realm2 (spellbooks)"
3968 #define MN_FIRST "first (spellbooks)"
3969 #define MN_SECOND "second (spellbooks)"
3970 #define MN_THIRD "third (spellbooks)"
3971 #define MN_FOURTH "fourth (spellbooks)"
3973 #define MN_NOUN "Keywords (noun)"
3983 } command_menu_type;
3986 command_menu_type menu_data[] =
3988 {MN_HELP, 0, -1, EC_HELP},
3989 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
3990 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
3991 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
3993 {MN_EDIT, 0, -1, -1},
3994 {MN_CUT, 1, KTRL('x'), EC_CUT},
3995 {MN_COPY, 1, KTRL('c'), EC_COPY},
3996 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
3997 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
3998 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
3999 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4000 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4001 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4002 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4004 {MN_SEARCH, 0, -1, -1},
4005 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4006 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4007 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4008 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4009 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4011 {MN_MOVE, 0, -1, -1},
4012 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4013 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4014 {MN_UP, 1, KTRL('p'), EC_UP},
4015 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4016 {MN_BOL, 1, KTRL('a'), EC_BOL},
4017 {MN_EOL, 1, KTRL('e'), EC_EOL},
4018 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4019 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4020 {MN_TOP, 1, KTRL('t'), EC_TOP},
4021 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4023 {MN_INSERT, 0, -1, -1},
4024 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4025 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4026 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4027 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4028 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4030 {MN_ADJECTIVE_GEN, 0, -1, -1},
4031 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4032 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4033 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4034 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4035 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4036 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4038 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4039 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4040 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4041 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4042 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4043 {MN_EGO, 1, -1, EC_OK_EGO},
4044 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
4045 {MN_RARE, 1, -1, EC_OK_RARE},
4046 {MN_COMMON, 1, -1, EC_OK_COMMON},
4047 {MN_WANTED, 1, -1, EC_OK_WANTED},
4048 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4049 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4050 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4051 {MN_REALM1, 1, -1, EC_OK_REALM1},
4052 {MN_REALM2, 1, -1, EC_OK_REALM2},
4053 {MN_FIRST, 1, -1, EC_OK_FIRST},
4054 {MN_SECOND, 1, -1, EC_OK_SECOND},
4055 {MN_THIRD, 1, -1, EC_OK_THIRD},
4056 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4058 {MN_NOUN, 0, -1, -1},
4059 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4060 {KEY_FAVORITE, 1, -1, EC_KK_FAVORITE},
4061 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4062 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4063 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4064 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4065 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4066 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4067 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4068 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4069 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4070 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4071 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4072 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4073 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4074 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4075 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4077 {MN_COMMAND_LETTER, 0, -1, -1},
4078 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4079 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4080 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4081 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4082 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4084 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4091 * Find a command by 'key'.
4093 static int get_com_id(char key)
4097 for (i = 0; menu_data[i].name; i++)
4099 if (menu_data[i].key == key)
4101 return menu_data[i].com_id;
4110 * Display the menu, and get a command
4112 static int do_command_menu(int level, int start)
4117 int col0 = 5 + level*7;
4118 int row0 = 1 + level*3;
4120 int menu_id_list[26];
4122 char linestr[MAX_LINELEN];
4124 /* Get max length */
4126 for (i = start; menu_data[i].level >= level; i++)
4130 /* Ignore lower level sub menus */
4131 if (menu_data[i].level > level) continue;
4133 len = strlen(menu_data[i].name);
4134 if (len > max_len) max_len = len;
4136 menu_id_list[menu_key] = i;
4140 while (menu_key < 26)
4142 menu_id_list[menu_key] = -1;
4146 /* Extra space for displaying menu key and command key */
4147 max_menu_wid = max_len + 3 + 3;
4149 /* Prepare box line */
4151 strcat(linestr, "+");
4152 for (i = 0; i < max_menu_wid + 2; i++)
4154 strcat(linestr, "-");
4156 strcat(linestr, "+");
4166 int row1 = row0 + 1;
4169 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4171 /* Draw menu items */
4173 for (i = start; menu_data[i].level >= level; i++)
4175 char com_key_str[3];
4178 /* Ignore lower level sub menus */
4179 if (menu_data[i].level > level) continue;
4181 if (menu_data[i].com_id == -1)
4184 strcpy(com_key_str, "¢§");
4186 strcpy(com_key_str, ">");
4189 else if (menu_data[i].key != -1)
4191 com_key_str[0] = '^';
4192 com_key_str[1] = menu_data[i].key + '@';
4193 com_key_str[2] = '\0';
4197 com_key_str[0] = '\0';
4200 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4202 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4207 /* Draw bottom line */
4208 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4210 /* The menu was shown */
4214 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
4216 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
4220 if (key == ESCAPE) return 0;
4222 if ('a' <= key && key <= 'z')
4224 menu_id = menu_id_list[key - 'a'];
4228 com_id = menu_data[menu_id].com_id;
4232 com_id = do_command_menu(level + 1, menu_id + 1);
4234 if (com_id) return com_id;
4246 com_id = get_com_id(key);
4247 if (com_id) return com_id;
4254 static chain_str_type *new_chain_str(cptr str)
4256 chain_str_type *chain;
4258 size_t len = strlen(str);
4260 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4262 strcpy(chain->s, str);
4269 static void kill_yank_chain(text_body_type *tb)
4271 chain_str_type *chain = tb->yank;
4273 tb->yank_eol = TRUE;
4277 chain_str_type *next = chain->next;
4278 size_t len = strlen(chain->s);
4280 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4287 static void add_str_to_yank(text_body_type *tb, cptr str)
4289 chain_str_type *chain;
4291 tb->yank_eol = FALSE;
4293 if (NULL == tb->yank)
4295 tb->yank = new_chain_str(str);
4305 chain->next = new_chain_str(str);
4310 chain = chain->next;
4315 #define DESCRIPT_HGT 3
4320 static void draw_text_editor(text_body_type *tb)
4323 int by1 = 0, by2 = 0;
4326 Term_get_size(&tb->wid, &tb->hgt);
4329 * Top line (-1), description line (-3), separator (-1)
4332 tb->hgt -= 2 + DESCRIPT_HGT;
4335 /* Don't let cursor at second byte of kanji */
4336 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4337 if (iskanji(tb->lines_list[tb->cy][i]))
4348 /* Scroll if necessary */
4349 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4350 tb->upper = tb->cy - (tb->hgt)/2;
4353 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4354 tb->left = tb->cx - (tb->wid)*2/3;
4358 /* Redraw whole window after resize */
4359 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4360 tb->dirty_flags |= DIRTY_SCREEN;
4362 /* Redraw all text after scroll */
4363 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4364 tb->dirty_flags |= DIRTY_ALL;
4367 if (tb->dirty_flags & DIRTY_SCREEN)
4369 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4375 /* Redraw mode line */
4376 if (tb->dirty_flags & DIRTY_MODE)
4378 char buf[MAX_LINELEN];
4380 int sepa_length = tb->wid;
4383 for (i = 0; i < sepa_length; i++)
4387 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4390 if (tb->dirty_flags & DIRTY_EXPRESSION)
4395 for (y = 0; tb->lines_list[y]; y++)
4399 cptr s = tb->lines_list[y];
4401 /* Update this line's state */
4402 tb->states[y] = state;
4404 if (*s++ != '?') continue;
4405 if (*s++ != ':') continue;
4407 /* Lines below this line are auto-registered */
4408 if (streq(s, "$AUTOREGISTER"))
4409 state |= LSTAT_AUTOREGISTER;
4411 /* Parse the expr */
4412 v = process_pref_file_expr(&s, &f);
4415 if (streq(v, "0")) state |= LSTAT_BYPASS;
4416 else state &= ~LSTAT_BYPASS;
4418 /* Re-update this line's state */
4419 tb->states[y] = state | LSTAT_EXPRESSION;
4422 tb->dirty_flags |= DIRTY_ALL;
4427 int tmp_cx = tb->cx;
4428 int len = strlen(tb->lines_list[tb->cy]);
4430 /* Correct cursor location */
4431 if (tb->cx > len) tmp_cx = len;
4433 tb->dirty_flags |= DIRTY_ALL;
4435 by1 = MIN(tb->my, tb->cy);
4436 by2 = MAX(tb->my, tb->cy);
4439 /* Dump up to tb->hgt lines of messages */
4440 for (i = 0; i < tb->hgt; i++)
4446 int y = tb->upper+i;
4448 /* clean or dirty? */
4449 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4452 msg = tb->lines_list[y];
4455 /* Apply horizontal scroll */
4456 for (j = 0; *msg; msg++, j++)
4458 if (j == tb->left) break;
4474 Term_erase(0, i + 1, tb->wid);
4476 if (tb->states[y] & LSTAT_AUTOREGISTER)
4478 /* Warning color -- These lines will be deleted later */
4483 /* Bypassed line will be displayed by darker color */
4484 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4485 else color = TERM_WHITE;
4488 /* No mark or Out of mark */
4489 if (!tb->mark || (y < by1 || by2 < y))
4491 /* Dump the messages, bottom to top */
4492 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4495 /* Multiple lines selected */
4496 else if (by1 != by2)
4498 /* Dump the messages, bottom to top */
4499 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4502 /* Single line selected */
4505 int x0 = leftcol + tb->left;
4506 int len = strlen(tb->lines_list[tb->cy]);
4507 int bx1 = MIN(tb->mx, tb->cx);
4508 int bx2 = MAX(tb->mx, tb->cx);
4510 /* Correct cursor location */
4511 if (bx2 > len) bx2 = len;
4513 Term_gotoxy(leftcol, i + 1);
4514 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4515 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4516 Term_addstr(-1, color, msg + (bx2 - x0));
4520 for (; i < tb->hgt; i++)
4523 Term_erase(0, i + 1, tb->wid);
4526 /* Display information when updated */
4527 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4529 autopick_type an_entry, *entry = &an_entry;
4530 cptr str1 = NULL, str2 = NULL;
4533 /* Clear information line */
4534 for (i = 0; i < DESCRIPT_HGT; i++)
4537 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4540 /* Display information */
4541 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4544 str1 = format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str);
4546 str1 = format("Pattern not found: %s", tb->search_str);
4549 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4552 str1 = format("̵¸ú¾õÂ֤ιԤò¥¹¥¥Ã¥×¤·¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4554 str1 = format("Some inactive lines are skipped. (Searching %s)", tb->search_str);
4557 else if (tb->dirty_flags & DIRTY_INACTIVE)
4560 str1 = format("̵¸ú¾õÂ֤ιԤÀ¤±¤¬¸«ÉÕ¤«¤ê¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4562 str1 = format("Found only an inactive line. (Searching %s)", tb->search_str);
4565 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4568 str1 = "¸¡º÷¤¹¤ë¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó(^S ¤Ç¸¡º÷)¡£";
4570 str1 = "No pattern to search. (Press ^S to search.)";
4573 else if (tb->lines_list[tb->cy][0] == '#')
4576 str1 = "¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£";
4578 str1 = "This line is a comment.";
4581 else if (tb->lines_list[tb->cy][1] == ':')
4583 switch(tb->lines_list[tb->cy][0])
4587 str1 = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4589 str1 = "This line is a Conditional Expression.";
4595 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4597 str1 = "This line defines a Macro action.";
4602 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4604 str1 = "This line defines a Macro trigger key.";
4609 str1 = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4611 str1 = "This line defines a Keymap.";
4616 switch(tb->lines_list[tb->cy][0])
4619 if (tb->states[tb->cy] & LSTAT_BYPASS)
4622 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4624 str2 = "The expression is 'False'(=0) currently.";
4630 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4632 str2 = "The expression is 'True'(=1) currently.";
4638 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4641 str2 = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4643 str2 = "This line will be delete later.";
4647 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4650 str2 = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4652 str2 = "This line is bypassed currently.";
4659 /* Get description of an autopicker preference line */
4660 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4662 char buf[MAX_LINELEN];
4663 char temp[MAX_LINELEN];
4666 describe_autopick(buf, entry);
4668 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4671 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4673 strcat(buf, " This line will be delete later.");
4677 if (tb->states[tb->cy] & LSTAT_BYPASS)
4680 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4682 strcat(buf, " This line is bypassed currently.");
4686 roff_to_buf(buf, 81, temp, sizeof(temp));
4688 for (i = 0; i < 3; i++)
4694 prt(t, tb->hgt +1 + 1 + i, 0);
4698 autopick_free_entry(entry);
4701 /* Draw the first line */
4702 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4704 /* Draw the second line */
4705 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4711 * Kill segment of a line
4713 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4715 char buf[MAX_LINELEN];
4716 cptr s = tb->lines_list[y];
4720 /* Kill whole line? */
4721 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4725 string_free(tb->lines_list[y]);
4727 /* Shift lines up */
4728 for (i = y; tb->lines_list[i+1]; i++)
4729 tb->lines_list[i] = tb->lines_list[i+1];
4730 tb->lines_list[i] = NULL;
4732 /* Expressions need re-evaluation */
4733 tb->dirty_flags |= DIRTY_EXPRESSION;
4739 if (x0 == x1) return;
4741 /* Before the segment */
4742 for (x = 0; x < x0; x++)
4745 /* After the segment */
4746 for (x = x1; s[x]; x++)
4752 string_free(tb->lines_list[y]);
4753 tb->lines_list[y] = string_make(buf);
4755 /* Expressions may need re-evaluation */
4756 check_expression_line(tb, y);
4758 /* Text is changed */
4764 * Get a trigger key and insert ASCII string for the trigger
4766 static bool insert_macro_line(text_body_type *tb)
4775 /* Do not process macros */
4781 /* Read the pattern */
4787 /* Do not process macros */
4790 /* Do not wait for keys */
4793 /* Attempt to read a key */
4803 /* Convert the trigger */
4804 ascii_to_text(tmp, buf);
4807 if(!tmp[0]) return FALSE;
4811 /* Insert preference string */
4812 insert_return_code(tb);
4813 string_free(tb->lines_list[tb->cy]);
4814 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4816 /* Acquire action */
4817 i = macro_find_exact(buf);
4821 /* Nothing defined */
4826 /* Analyze the current action */
4827 ascii_to_text(tmp, macro__act[i]);
4830 /* Insert blank action preference line */
4831 insert_return_code(tb);
4832 string_free(tb->lines_list[tb->cy]);
4833 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4840 * Get a command key and insert ASCII string for the key
4842 static bool insert_keymap_line(text_body_type *tb)
4850 if (rogue_like_commands)
4852 mode = KEYMAP_MODE_ROGUE;
4858 mode = KEYMAP_MODE_ORIG;
4871 /* Convert the trigger */
4872 ascii_to_text(tmp, buf);
4875 if(!tmp[0]) return FALSE;
4879 /* Insert preference string */
4880 insert_return_code(tb);
4881 string_free(tb->lines_list[tb->cy]);
4882 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4884 /* Look up the keymap */
4885 act = keymap_act[mode][(byte)(buf[0])];
4887 /* Insert blank action preference line */
4888 insert_return_code(tb);
4889 string_free(tb->lines_list[tb->cy]);
4890 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4897 * Execute a single editor command
4899 static bool do_editor_command(text_body_type *tb, int com_id)
4907 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4909 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
4912 return QUIT_WITHOUT_SAVE;
4915 return QUIT_AND_SAVE;
4918 /* Revert to original */
4920 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4922 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
4925 free_text_lines(tb->lines_list);
4926 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4927 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4928 tb->cx = tb->cy = 0;
4931 /* Text is not changed */
4932 tb->changed = FALSE;
4936 /* Peruse the main help file */
4938 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
4940 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
4943 tb->dirty_flags |= DIRTY_SCREEN;
4948 /* Split a line or insert end of line */
4950 /* Ignore selection */
4956 tb->dirty_flags |= DIRTY_ALL;
4959 insert_return_code(tb);
4964 tb->dirty_flags |= DIRTY_ALL;
4974 len = strlen(tb->lines_list[tb->cy]);
4975 if (len < tb->cx) tb->cx = len;
4977 else if (tb->cy > 0)
4980 tb->cx = strlen(tb->lines_list[tb->cy]);
4986 if (tb->lines_list[tb->cy + 1]) tb->cy++;
4991 if (tb->cy > 0) tb->cy--;
5000 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5003 len = strlen(tb->lines_list[tb->cy]);
5006 if (tb->lines_list[tb->cy + 1])
5018 /* Beginning of line */
5024 tb->cx = strlen(tb->lines_list[tb->cy]);
5028 while (0 < tb->cy && tb->upper <= tb->cy)
5030 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5036 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
5046 while (tb->lines_list[tb->cy + 1])
5052 /* Copy the text first */
5053 do_editor_command(tb, EC_COPY);
5055 /* Single line case */
5056 if (tb->my == tb->cy)
5058 int bx1 = MIN(tb->mx, tb->cx);
5059 int bx2 = MAX(tb->mx, tb->cx);
5060 int len = strlen(tb->lines_list[tb->cy]);
5062 /* Correct fake cursor position */
5063 if (bx2 > len) bx2 = len;
5065 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5067 /* New cursor position */
5071 /* Multiple lines case */
5072 else /* if (tb->my != tb->cy) */
5076 int by1 = MIN(tb->my, tb->cy);
5077 int by2 = MAX(tb->my, tb->cy);
5079 /* Kill lines in reverse order */
5080 for (y = by2; y >= by1; y--)
5082 int len = strlen(tb->lines_list[y]);
5084 kill_line_segment(tb, y, 0, len, TRUE);
5087 /* New cursor position */
5093 /* Disable selection */
5097 tb->dirty_flags |= DIRTY_ALL;
5104 int len = strlen(tb->lines_list[tb->cy]);
5106 /* Correct cursor location */
5107 if (tb->cx > len) tb->cx = len;
5109 /* Use single line? */
5112 /* Select a single line */
5118 /* Kill old yank buffer */
5119 kill_yank_chain(tb);
5122 /* Single line case */
5123 if (tb->my == tb->cy)
5126 char buf[MAX_LINELEN];
5127 int bx1 = MIN(tb->mx, tb->cx);
5128 int bx2 = MAX(tb->mx, tb->cx);
5130 /* Correct fake cursor position */
5131 if (bx2 > len) bx2 = len;
5133 /* Whole part of this line is selected */
5134 if (bx1 == 0 && bx2 == len)
5136 /* Copy this line */
5137 add_str_to_yank(tb, tb->lines_list[tb->cy]);
5139 /* Add end of line to the buffer */
5140 add_str_to_yank(tb, "");
5143 /* Segment of this line is selected */
5146 for (i = 0; i < bx2 - bx1; i++)
5148 buf[i] = tb->lines_list[tb->cy][bx1 + i];
5152 /* Copy this segment of line */
5153 add_str_to_yank(tb, buf);
5157 /* Multiple lines case */
5158 else /* if (tb->my != tb->cy) */
5162 int by1 = MIN(tb->my, tb->cy);
5163 int by2 = MAX(tb->my, tb->cy);
5166 for (y = by1; y <= by2; y++)
5168 /* Copy this line */
5169 add_str_to_yank(tb, tb->lines_list[y]);
5172 /* Add final end of line to the buffer */
5173 add_str_to_yank(tb, "");
5176 /* Disable selection */
5180 tb->dirty_flags |= DIRTY_ALL;
5186 /* Paste killed text */
5188 chain_str_type *chain = tb->yank;
5189 int len = strlen(tb->lines_list[tb->cy]);
5191 /* Nothing to do? */
5194 /* Correct cursor location */
5195 if (tb->cx > len) tb->cx = len;
5197 /* Ignore selection */
5203 tb->dirty_flags |= DIRTY_ALL;
5209 cptr yank_str = chain->s;
5211 char buf[MAX_LINELEN];
5213 char rest[MAX_LINELEN], *rest_ptr = rest;
5215 /* Save preceding string */
5216 for(i = 0; i < tb->cx; i++)
5217 buf[i] = tb->lines_list[tb->cy][i];
5219 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5221 /* Paste yank buffer */
5222 while (*yank_str && i < MAX_LINELEN-1)
5224 buf[i++] = *yank_str++;
5230 chain = chain->next;
5232 if (chain || tb->yank_eol)
5234 /* There is an end of line between chain nodes */
5236 insert_return_code(tb);
5238 /* Replace this line with new one */
5239 string_free(tb->lines_list[tb->cy]);
5240 tb->lines_list[tb->cy] = string_make(buf);
5242 /* Move to next line */
5249 /* Final line doesn't have end of line */
5251 tb->cx = strlen(buf);
5253 /* Rest of original line */
5254 while (*rest_ptr && i < MAX_LINELEN-1)
5256 buf[i++] = *rest_ptr++;
5262 /* Replace this line with new one */
5263 string_free(tb->lines_list[tb->cy]);
5264 tb->lines_list[tb->cy] = string_make(buf);
5271 tb->dirty_flags |= DIRTY_ALL;
5273 /* Expressions need re-evaluation */
5274 tb->dirty_flags |= DIRTY_EXPRESSION;
5276 /* Text is changed */
5285 /* Disable the selection */
5289 tb->dirty_flags |= DIRTY_ALL;
5293 tb->mark = MARK_MARK;
5295 /* Repeating this command swaps cursor position */
5296 if (com_id == tb->old_com_id)
5308 tb->dirty_flags |= DIRTY_ALL;
5312 int len = strlen(tb->lines_list[tb->cy]);
5314 /* Mark the point 1 */
5318 /* Correct cursor location */
5319 if (tb->cx > len) tb->mx = len;
5326 /* Kill rest of line */
5328 int len = strlen(tb->lines_list[tb->cy]);
5330 /* Correct cursor location */
5331 if (tb->cx > len) tb->cx = len;
5333 /* Ignore selection */
5339 tb->dirty_flags |= DIRTY_ALL;
5342 /* Append only if this command is repeated. */
5343 if (tb->old_com_id != com_id)
5345 kill_yank_chain(tb);
5349 /* Really deleted some text */
5352 /* Add deleted string to yank buffer */
5353 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5355 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5358 tb->dirty_line = tb->cy;
5360 /* Leave end of line character */
5364 /* Cut the end of line character only */
5365 if (tb->yank_eol) add_str_to_yank(tb, "");
5367 /* Cut end of line */
5368 tb->yank_eol = TRUE;
5370 do_editor_command(tb, EC_DELETE_CHAR);
5374 case EC_DELETE_CHAR:
5375 /* DELETE == go forward + BACK SPACE */
5377 /* Ignore selection */
5383 tb->dirty_flags |= DIRTY_ALL;
5387 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5391 do_editor_command(tb, EC_BACKSPACE);
5399 char buf[MAX_LINELEN];
5401 /* Ignore selection */
5407 tb->dirty_flags |= DIRTY_ALL;
5410 len = strlen(tb->lines_list[tb->cy]);
5413 if (tb->lines_list[tb->cy + 1])
5427 /* delete a return code and union two lines */
5428 if (tb->cy == 0) break;
5429 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5430 strcpy(buf, tb->lines_list[tb->cy-1]);
5431 strcat(buf, tb->lines_list[tb->cy]);
5432 string_free(tb->lines_list[tb->cy-1]);
5433 string_free(tb->lines_list[tb->cy]);
5434 tb->lines_list[tb->cy-1] = string_make(buf);
5436 for (i = tb->cy; tb->lines_list[i+1]; i++)
5437 tb->lines_list[i] = tb->lines_list[i+1];
5439 tb->lines_list[i] = NULL;
5443 tb->dirty_flags |= DIRTY_ALL;
5445 /* Expressions need re-evaluation */
5446 tb->dirty_flags |= DIRTY_EXPRESSION;
5448 /* Text is changed */
5454 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5458 if (iskanji(tb->lines_list[tb->cy][i]))
5459 buf[j++] = tb->lines_list[tb->cy][i++];
5461 buf[j++] = tb->lines_list[tb->cy][i];
5468 for (; tb->lines_list[tb->cy][i]; i++)
5469 buf[j++] = tb->lines_list[tb->cy][i];
5471 string_free(tb->lines_list[tb->cy]);
5472 tb->lines_list[tb->cy] = string_make(buf);
5475 tb->dirty_line = tb->cy;
5477 /* Expressions may need re-evaluation */
5478 check_expression_line(tb, tb->cy);
5480 /* Text is changed */
5490 /* Become dirty because of item/equip menu */
5491 tb->dirty_flags |= DIRTY_SCREEN;
5493 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5495 if (!search_dir) break;
5497 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5498 else do_editor_command(tb, EC_SEARCH_BACK);
5502 case EC_SEARCH_FORW:
5503 if (tb->search_o_ptr)
5505 search_for_object(tb, tb->search_o_ptr, TRUE);
5507 else if (tb->search_str && tb->search_str[0])
5509 search_for_string(tb, tb->search_str, TRUE);
5513 tb->dirty_flags |= DIRTY_NO_SEARCH;
5517 case EC_SEARCH_BACK:
5518 if (tb->search_o_ptr)
5520 search_for_object(tb, tb->search_o_ptr, FALSE);
5522 else if (tb->search_str && tb->search_str[0])
5524 search_for_string(tb, tb->search_str, FALSE);
5528 tb->dirty_flags |= DIRTY_NO_SEARCH;
5533 /* Become dirty because of item/equip menu */
5534 tb->dirty_flags |= DIRTY_SCREEN;
5536 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5538 do_editor_command(tb, EC_SEARCH_FORW);
5541 case EC_SEARCH_DESTROYED:
5542 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5544 /* There is no object to search */
5545 tb->dirty_flags |= DIRTY_NO_SEARCH;
5550 do_editor_command(tb, EC_SEARCH_FORW);
5553 case EC_INSERT_OBJECT:
5555 /* Insert choosen item name */
5557 autopick_type an_entry, *entry = &an_entry;
5559 if (!entry_from_choosed_object(entry))
5561 /* Now dirty because of item/equip menu */
5562 tb->dirty_flags |= DIRTY_SCREEN;
5567 insert_return_code(tb);
5568 string_free(tb->lines_list[tb->cy]);
5569 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5571 /* Now dirty because of item/equip menu */
5572 tb->dirty_flags |= DIRTY_SCREEN;
5577 case EC_INSERT_DESTROYED:
5578 /* Insert a name of last destroyed item */
5579 if (tb->last_destroyed)
5582 insert_return_code(tb);
5583 string_free(tb->lines_list[tb->cy]);
5584 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5587 tb->dirty_flags |= DIRTY_ALL;
5589 /* Text is changed */
5594 case EC_INSERT_BLOCK:
5596 /* Insert a conditinal expression line */
5597 char expression[80];
5599 /* Conditional Expression for Class and Race */
5600 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5602 rp_ptr->E_title, cp_ptr->E_title,
5604 rp_ptr->title, cp_ptr->title,
5610 insert_return_code(tb);
5611 string_free(tb->lines_list[tb->cy]);
5612 tb->lines_list[tb->cy] = string_make(expression);
5614 insert_return_code(tb);
5615 string_free(tb->lines_list[tb->cy]);
5616 tb->lines_list[tb->cy] = string_make("?:1");
5619 tb->dirty_flags |= DIRTY_ALL;
5621 /* Text is changed */
5627 case EC_INSERT_MACRO:
5628 /* Draw_everythig (delete menu) */
5629 draw_text_editor(tb);
5632 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5636 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5638 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5640 if (insert_macro_line(tb))
5642 /* Prepare to input action */
5646 tb->dirty_flags |= DIRTY_ALL;
5648 /* Text is changed */
5654 case EC_INSERT_KEYMAP:
5655 /* Draw_everythig (delete menu) */
5656 draw_text_editor(tb);
5659 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5663 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)));
5665 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)));
5668 if (insert_keymap_line(tb))
5670 /* Prepare to input action */
5674 tb->dirty_flags |= DIRTY_ALL;
5676 /* Text is changed */
5681 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5682 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5683 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5684 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5685 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5687 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5688 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5689 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5690 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5691 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5692 case EC_KK_FAVORITE: toggle_keyword(tb, FLG_FAVORITE); break;
5693 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5694 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5695 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5696 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5697 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5698 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5699 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5700 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5701 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5702 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5703 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5704 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5705 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5706 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5707 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5708 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5709 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5710 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5711 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5712 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5713 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5714 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5715 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5716 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5717 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5718 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5719 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5720 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5721 case EC_OK_UNREADABLE:
5722 toggle_keyword(tb, FLG_UNREADABLE);
5723 add_keyword(tb, FLG_SPELLBOOKS);
5726 toggle_keyword(tb, FLG_REALM1);
5727 add_keyword(tb, FLG_SPELLBOOKS);
5730 toggle_keyword(tb, FLG_REALM2);
5731 add_keyword(tb, FLG_SPELLBOOKS);
5734 toggle_keyword(tb, FLG_FIRST);
5735 add_keyword(tb, FLG_SPELLBOOKS);
5738 toggle_keyword(tb, FLG_SECOND);
5739 add_keyword(tb, FLG_SPELLBOOKS);
5742 toggle_keyword(tb, FLG_THIRD);
5743 add_keyword(tb, FLG_SPELLBOOKS);
5746 toggle_keyword(tb, FLG_FOURTH);
5747 add_keyword(tb, FLG_SPELLBOOKS);
5751 /* Save old command */
5752 tb->old_com_id = com_id;
5759 * Insert single letter at cursor position.
5761 static void insert_single_letter(text_body_type *tb, int key)
5764 char buf[MAX_LINELEN];
5766 /* Save preceding string */
5767 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5768 buf[j++] = tb->lines_list[tb->cy][i];
5770 /* Add a character */
5778 if (j+2 < MAX_LINELEN)
5790 if (j+1 < MAX_LINELEN)
5796 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5797 buf[j++] = tb->lines_list[tb->cy][i];
5800 /* Replace current line with new line */
5801 string_free(tb->lines_list[tb->cy]);
5802 tb->lines_list[tb->cy] = string_make(buf);
5804 /* Move to correct collumn */
5805 len = strlen(tb->lines_list[tb->cy]);
5806 if (len < tb->cx) tb->cx = len;
5809 tb->dirty_line = tb->cy;
5811 /* Expressions may need re-evaluation */
5812 check_expression_line(tb, tb->cy);
5814 /* Text is changed */
5820 * Check special key code and get a movement command id
5822 static int analyze_move_key(text_body_type *tb, int skey)
5826 /* Not a special key */
5827 if (!(skey & SKEY_MASK)) return 0;
5829 /* Convert from a special key code to an editor command */
5830 switch(skey & ~SKEY_MOD_MASK)
5832 case SKEY_DOWN: com_id = EC_DOWN; break;
5833 case SKEY_LEFT: com_id = EC_LEFT; break;
5834 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5835 case SKEY_UP: com_id = EC_UP; break;
5836 case SKEY_PGUP: com_id = EC_PGUP; break;
5837 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5838 case SKEY_TOP: com_id = EC_TOP; break;
5839 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5842 /* Not a special movement key */
5846 /* Without shift modifier */
5847 if (!(skey & SKEY_MOD_SHIFT))
5850 * Un-shifted cursor keys cancells
5851 * selection created by shift+cursor.
5853 if (tb->mark & MARK_BY_SHIFT)
5858 tb->dirty_flags |= DIRTY_ALL;
5862 /* With shift modifier */
5865 /* Start selection by shift + cursor keys */
5868 int len = strlen(tb->lines_list[tb->cy]);
5870 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5874 /* Correct cursor location */
5875 if (tb->cx > len) tb->mx = len;
5877 /* Need to redraw text */
5878 if (com_id == EC_UP || com_id == EC_DOWN)
5880 /* Redraw all text */
5881 tb->dirty_flags |= DIRTY_ALL;
5885 tb->dirty_line = tb->cy;
5894 * In-game editor of Object Auto-picker/Destoryer
5896 void do_cmd_edit_autopick(void)
5898 static int cx_save = 0;
5899 static int cy_save = 0;
5901 text_body_type text_body, *tb = &text_body;
5903 autopick_type an_entry, *entry = &an_entry;
5904 char buf[MAX_LINELEN];
5909 static s32b old_autosave_turn = 0L;
5912 tb->changed = FALSE;
5915 tb->upper = tb->left = 0;
5917 tb->mx = tb->my = 0;
5918 tb->old_cy = tb->old_upper = tb->old_left = -1;
5919 tb->old_wid = tb->old_hgt = -1;
5923 tb->search_o_ptr = NULL;
5924 tb->search_str = NULL;
5925 tb->last_destroyed = NULL;
5926 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5927 tb->dirty_line = -1;
5928 tb->filename_mode = PT_DEFAULT;
5931 if (turn > old_autosave_turn + 100L)
5933 do_cmd_save_game(TRUE);
5934 old_autosave_turn = turn;
5937 /* HACK -- Reset start_time to stop counting playtime while edit */
5940 /* Free old entries */
5943 /* Command Description of the 'Last Destroyed Item' */
5944 if (autopick_last_destroyed_object.k_idx)
5946 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
5947 tb->last_destroyed = autopick_line_from_entry_kill(entry);
5950 /* Read or initialize whole text */
5951 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5953 /* Reset cursor position if needed */
5954 for (i = 0; i < tb->cy; i++)
5956 if (!tb->lines_list[i])
5958 tb->cy = tb->cx = 0;
5963 /* Save the screen */
5966 /* Process requests until done */
5971 /* Draw_everythig */
5972 draw_text_editor(tb);
5974 /* Display header line */
5976 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
5978 prt("(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)", 0, 0);
5982 /* Display current position */
5983 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
5987 /* Display current position and mark position */
5988 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
5992 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
5995 tb->dirty_flags = 0;
5996 tb->dirty_line = -1;
5998 /* Save old key and location */
5999 tb->old_cy = tb->cy;
6000 tb->old_upper = tb->upper;
6001 tb->old_left = tb->left;
6002 tb->old_wid = tb->wid;
6003 tb->old_hgt = tb->hgt;
6006 key = inkey_special();
6009 if (key & SKEY_MASK)
6011 /* Get a movement command */
6012 com_id = analyze_move_key(tb, key);
6016 else if (key == ESCAPE)
6018 com_id = do_command_menu(0, 0);
6020 /* Redraw all text later */
6021 tb->dirty_flags |= DIRTY_SCREEN;
6024 /* Insert a character */
6025 else if (!iscntrl((unsigned char)key))
6027 /* Ignore selection */
6033 tb->dirty_flags |= DIRTY_ALL;
6036 insert_single_letter(tb, key);
6042 /* Other commands */
6045 com_id = get_com_id(key);
6048 if (com_id) quit = do_editor_command(tb, com_id);
6049 } /* while (TRUE) */
6051 /* Restore the screen */
6054 /* Get the filename of preference */
6055 strcpy(buf, pickpref_filename(tb->filename_mode));
6057 if (quit == QUIT_AND_SAVE)
6058 write_text_lines(buf, tb->lines_list);
6060 free_text_lines(tb->lines_list);
6062 string_free(tb->last_destroyed);
6064 /* Destroy string chain */
6065 kill_yank_chain(tb);
6067 /* Reload autopick pref */
6068 process_pickpref_file(buf);
6070 /* HACK -- reset start_time so that playtime is not increase while edit */
6071 start_time = time(NULL);
6073 /* Save cursor location */