3 /* Purpose: Object Auto-picker/Destroyer */
6 * Copyright (c) 2002 Mogami
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
16 #define MAX_LINELEN 1024
22 #define FLG_COLLECTING 1
24 #define FLG_UNIDENTIFIED 3
25 #define FLG_IDENTIFIED 4
26 #define FLG_STAR_IDENTIFIED 5
28 #define FLG_MORE_DICE 7
29 #define FLG_MORE_BONUS 10
30 #define FLG_WORTHLESS 11
31 #define FLG_ARTIFACT 12
33 #define FLG_NAMELESS 14
39 #define FLG_UNREADABLE 20
48 #define FLG_WEAPONS 31
49 #define FLG_FAVORITE_WEAPONS 32
51 #define FLG_MISSILES 34
52 #define FLG_DEVICES 35
55 #define FLG_CORPSES 38
56 #define FLG_SPELLBOOKS 39
58 #define FLG_SHIELDS 41
61 #define FLG_AMULETS 44
68 #define FLG_NOUN_BEGIN FLG_ITEMS
69 #define FLG_NOUN_END FLG_BOOTS
73 #define KEY_ALL "¤¹¤Ù¤Æ¤Î"
77 * MEGA HACK -- MPW¤Î¥Ð¥°½ü¤±¡£
78 * pre-processÃæ¤Ë¡Ö¼ý¡×¤Î»ú¤Î2¥Ð¥¤¥ÈÌܤ¬¾¡¼ê¤Ë¾Ã¤¨¤Æ¤·¤Þ¤¦¡£
80 #define KEY_COLLECTING "\x8e\xfb½¸Ãæ¤Î"
82 #define KEY_COLLECTING "¼ý½¸Ãæ¤Î"
85 #define KEY_UNAWARE "̤ȽÌÀ¤Î"
86 #define KEY_UNIDENTIFIED "̤´ÕÄê¤Î"
87 #define KEY_IDENTIFIED "´ÕÄêºÑ¤ß¤Î"
88 #define KEY_STAR_IDENTIFIED "*´ÕÄê*ºÑ¤ß¤Î"
89 #define KEY_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦"
90 #define KEY_MORE_THAN "¥À¥¤¥¹ÌÜ"
91 #define KEY_DICE "°Ê¾å¤Î"
92 #define KEY_MORE_BONUS "½¤ÀµÃÍ"
93 #define KEY_MORE_BONUS2 "°Ê¾å¤Î"
94 #define KEY_WORTHLESS "̵²ÁÃͤÎ"
95 #define KEY_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È"
96 #define KEY_EGO "¥¨¥´"
97 #define KEY_NAMELESS "̵ÌäÎ"
98 #define KEY_RARE "¥ì¥¢¤Ê"
99 #define KEY_COMMON "¤¢¤ê¤Õ¤ì¤¿"
100 #define KEY_WANTED "¾Þ¶â¼ó¤Î"
101 #define KEY_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î"
102 #define KEY_HUMAN "¿Í´Ö¤Î"
103 #define KEY_UNREADABLE "Æɤá¤Ê¤¤"
104 #define KEY_REALM1 "Âè°ìÎΰè¤Î"
105 #define KEY_REALM2 "ÂèÆóÎΰè¤Î"
106 #define KEY_FIRST "1ºýÌܤÎ"
107 #define KEY_SECOND "2ºýÌܤÎ"
108 #define KEY_THIRD "3ºýÌܤÎ"
109 #define KEY_FOURTH "4ºýÌܤÎ"
110 #define KEY_ITEMS "¥¢¥¤¥Æ¥à"
111 #define KEY_WEAPONS "Éð´ï"
112 #define KEY_FAVORITE_WEAPONS "ÆÀ°ÕÉð´ï"
113 #define KEY_ARMORS "Ëɶñ"
114 #define KEY_MISSILES "Ìð"
115 #define KEY_DEVICES "ËâË¡¥¢¥¤¥Æ¥à"
116 #define KEY_LIGHTS "¸÷¸»"
117 #define KEY_JUNKS "¤¬¤é¤¯¤¿"
118 #define KEY_CORPSES "»àÂΤä¹ü"
119 #define KEY_SPELLBOOKS "ËâË¡½ñ"
120 #define KEY_HAFTED "Æß´ï"
121 #define KEY_SHIELDS "½â"
122 #define KEY_BOWS "µÝ"
123 #define KEY_RINGS "»ØÎØ"
124 #define KEY_AMULETS "¥¢¥ß¥å¥ì¥Ã¥È"
125 #define KEY_SUITS "³»"
126 #define KEY_CLOAKS "¥¯¥í¡¼¥¯"
127 #define KEY_HELMS "³õ"
128 #define KEY_GLOVES "äƼê"
129 #define KEY_BOOTS "·¤"
133 #define KEY_ALL "all"
134 #define KEY_COLLECTING "collecting"
135 #define KEY_UNAWARE "unaware"
136 #define KEY_UNIDENTIFIED "unidentified"
137 #define KEY_IDENTIFIED "identified"
138 #define KEY_STAR_IDENTIFIED "*identified*"
139 #define KEY_BOOSTED "dice boosted"
140 #define KEY_MORE_THAN "more than"
141 #define KEY_DICE " dice"
142 #define KEY_MORE_BONUS "more bonus than"
143 #define KEY_MORE_BONUS2 ""
144 #define KEY_WORTHLESS "worthless"
145 #define KEY_ARTIFACT "artifact"
146 #define KEY_EGO "ego"
147 #define KEY_NAMELESS "nameless"
148 #define KEY_RARE "rare"
149 #define KEY_COMMON "common"
150 #define KEY_WANTED "wanted"
151 #define KEY_UNIQUE "unique monster's"
152 #define KEY_HUMAN "human"
153 #define KEY_UNREADABLE "unreadable"
154 #define KEY_REALM1 "first realm's"
155 #define KEY_REALM2 "second realm's"
156 #define KEY_FIRST "first"
157 #define KEY_SECOND "second"
158 #define KEY_THIRD "third"
159 #define KEY_FOURTH "fourth"
160 #define KEY_ITEMS "items"
161 #define KEY_WEAPONS "weapons"
162 #define KEY_FAVORITE_WEAPONS "favorite weapons"
163 #define KEY_ARMORS "armors"
164 #define KEY_MISSILES "missiles"
165 #define KEY_DEVICES "magical devices"
166 #define KEY_LIGHTS "lights"
167 #define KEY_JUNKS "junks"
168 #define KEY_CORPSES "corpses or skeletons"
169 #define KEY_SPELLBOOKS "spellbooks"
170 #define KEY_HAFTED "hafted weapons"
171 #define KEY_SHIELDS "shields"
172 #define KEY_BOWS "bows"
173 #define KEY_RINGS "rings"
174 #define KEY_AMULETS "amulets"
175 #define KEY_SUITS "suits"
176 #define KEY_CLOAKS "cloaks"
177 #define KEY_HELMS "helms"
178 #define KEY_GLOVES "gloves"
179 #define KEY_BOOTS "boots"
183 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
184 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
185 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
186 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
189 #define ADD_KEY(KEY) strcat(ptr, KEY)
191 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
193 #define ADD_KEY2(KEY) strcat(ptr, KEY)
195 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
196 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
197 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
198 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
201 static char kanji_colon[] = "¡§";
206 * A function to create new entry
208 static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_default)
213 char buf[MAX_LINELEN];
214 cptr prev_ptr, ptr, old_ptr;
217 if (str[1] == ':') switch (str[0])
220 case 'A': case 'P': case 'C':
224 entry->flag[0] = entry->flag[1] = 0L;
227 act = DO_AUTOPICK | DO_DISPLAY;
230 if ((act & DO_AUTOPICK) && *str == '!')
233 act |= DO_AUTODESTROY;
236 else if ((act & DO_AUTOPICK) && *str == '~')
239 act |= DONT_AUTOPICK;
242 else if ((act & DO_AUTOPICK) && *str == ';')
245 act |= DO_QUERY_AUTOPICK;
248 else if ((act & DO_DISPLAY) && *str == '(')
257 /* don't mind upper or lower case */
259 for (i = 0; *str; i++)
270 /* Auto-inscription? */
278 if (isupper(c)) c = tolower(c);
284 /* Skip empty line unless allow_default */
285 if (!allow_default && *buf == 0) return FALSE;
287 /* Skip comment line */
288 if (*buf == 0 && insc) return FALSE;
290 ptr = prev_ptr = buf;
293 while (old_ptr != ptr)
295 /* Save current location */
298 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
299 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
300 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
301 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
302 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
303 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
304 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
306 /*** Weapons whose dd*ds is more than nn ***/
307 if (MATCH_KEY2(KEY_MORE_THAN))
312 /* Drop leading spaces */
313 while (' ' == *ptr) ptr++;
316 while ('0' <= *ptr && *ptr <= '9')
318 entry->dice = 10 * entry->dice + (*ptr - '0');
325 (void)MATCH_KEY(KEY_DICE);
326 ADD_FLG(FLG_MORE_DICE);
332 /*** Items whose magical bonus is more than n ***/
333 if (MATCH_KEY2(KEY_MORE_BONUS))
338 /* Drop leading spaces */
339 while (' ' == *ptr) ptr++;
342 while ('0' <= *ptr && *ptr <= '9')
344 entry->bonus = 10 * entry->bonus + (*ptr - '0');
351 (void)MATCH_KEY(KEY_MORE_BONUS2);
352 ADD_FLG(FLG_MORE_BONUS);
358 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
359 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
360 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
361 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
362 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
363 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
364 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
365 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
366 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
367 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
368 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
369 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
370 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
371 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
372 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
375 /* Not yet found any noun */
378 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
380 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
381 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
382 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
383 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
384 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
385 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
386 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
387 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
388 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
389 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
390 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
391 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
392 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
393 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
394 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
395 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
396 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
397 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
398 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
399 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
401 /* Last 'keyword' must be at the correct location */
405 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
408 else if (*ptr == '\0')
410 /* There was no noun */
413 /* Add extra word "items" */
414 ADD_FLG_NOUN(FLG_ITEMS);
421 /* A noun type keyword didn't end correctly */
422 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
427 /* Save this auto-picker entry line */
428 entry->name = string_make(ptr);
430 entry->insc = string_make(insc);
439 static bool is_favorite(object_type *o_ptr)
441 /* Only weapons match */
442 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
445 /* Favorite weapons are varied depend on the class */
446 switch (p_ptr->pclass)
450 u32b flgs[TR_FLAG_SIZE];
451 object_flags_known(o_ptr, flgs);
453 if (!have_flag(flgs, TR_BLESSED) &&
454 !(o_ptr->tval == TV_HAFTED))
460 case CLASS_FORCETRAINER:
462 if (!(s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval]))
466 case CLASS_BEASTMASTER:
469 u32b flgs[TR_FLAG_SIZE];
470 object_flags_known(o_ptr, flgs);
472 /* Is it known to be suitable to using while riding? */
473 if (!(have_flag(flgs, TR_RIDING)))
481 if (s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
486 /* All weapons are okay for non-special classes */
495 * Rare weapons/aromors
496 * including Blade of Chaos, Dragon armors, etc.
498 static bool is_rare(object_type *o_ptr)
503 if (o_ptr->sval == SV_MACE_OF_DISRUPTION ||
504 o_ptr->sval == SV_WIZSTAFF) return TRUE;
508 if (o_ptr->sval == SV_SCYTHE_OF_SLICING ||
509 o_ptr->sval == SV_DEATH_SCYTHE) return TRUE;
513 if (o_ptr->sval == SV_BLADE_OF_CHAOS ||
514 o_ptr->sval == SV_DIAMOND_EDGE ||
515 o_ptr->sval == SV_DOKUBARI ||
516 o_ptr->sval == SV_HAYABUSA) return TRUE;
520 if (o_ptr->sval == SV_DRAGON_SHIELD ||
521 o_ptr->sval == SV_MIRROR_SHIELD) return TRUE;
525 if (o_ptr->sval == SV_DRAGON_HELM) return TRUE;
529 if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) return TRUE;
533 if (o_ptr->sval == SV_ELVEN_CLOAK ||
534 o_ptr->sval == SV_ETHEREAL_CLOAK ||
535 o_ptr->sval == SV_SHADOW_CLOAK) return TRUE;
539 if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) return TRUE;
543 if (o_ptr->sval == SV_KUROSHOUZOKU ||
544 o_ptr->sval == SV_ABUNAI_MIZUGI) return TRUE;
554 /* Any others are not "rare" objects. */
560 * Convert string to lower case
562 static void str_tolower(char *str)
564 /* Force to be lower case string */
574 *str = tolower(*str);
580 * Get auto-picker entry from o_ptr.
582 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
584 /* Assume that object name is to be added */
588 /* ¥¨¥´Ì䬼ÙË⤫¤â¤·¤ì¤Ê¤¤¤Î¤Ç¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¡Ö^¡×¤ÏÉÕ¤±¤Ê¤¤ */
589 bool bol_mark = FALSE;
591 /* We can always use the ^ mark in English */
592 bool bol_mark = TRUE;
595 char name_str[MAX_NLEN];
597 /* Initialize name string */
600 entry->insc = string_make(quark_str(o_ptr->inscription));
601 entry->action = DO_AUTOPICK | DO_DISPLAY;
602 entry->flag[0] = entry->flag[1] = 0L;
606 if (!object_aware_p(o_ptr))
608 ADD_FLG(FLG_UNAWARE);
612 /* Not really identified */
613 else if (!object_known_p(o_ptr))
615 if (!(o_ptr->ident & IDENT_SENSE))
617 ADD_FLG(FLG_UNIDENTIFIED);
622 /* Pseudo-identified */
623 switch (o_ptr->feeling)
627 ADD_FLG(FLG_NAMELESS);
633 ADD_FLG(FLG_NAMELESS);
634 ADD_FLG(FLG_WORTHLESS);
640 ADD_FLG(FLG_WORTHLESS);
648 /* XXX No appropriate flag */
653 /* Never reach here */
666 if (TV_WEAPON_BEGIN <= o_ptr->tval &&
667 o_ptr->tval <= TV_ARMOR_END)
670 * Base name of ego weapons and armors
671 * are almost meaningless.
672 * Register the ego type only.
674 ego_item_type *e_ptr = &e_info[o_ptr->name2];
676 /* ¥¨¥´ÌäˤϡÖ^¡×¥Þ¡¼¥¯¤¬»È¤¨¤ë */
677 sprintf(name_str, "^%s", e_name + e_ptr->name);
679 /* We ommit the basename and cannot use the ^ mark */
680 strcpy(name_str, e_name + e_ptr->name);
683 /* Don't use the object description */
686 if (TV_WEAPON_BEGIN <= o_ptr->tval &&
687 o_ptr->tval <= TV_ARMOR_END)
689 /* Restrict to 'common' equipments */
690 if (!is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
698 else if (o_ptr->name1 || o_ptr->art_name)
699 ADD_FLG(FLG_ARTIFACT);
701 /* Non-ego, non-artifact */
704 /* Wearable nameless object */
705 if ((TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
706 ADD_FLG(FLG_NAMELESS);
717 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
718 k_ptr = &k_info[o_ptr->k_idx];
719 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
720 ADD_FLG(FLG_BOOSTED);
723 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
725 REM_FLG(FLG_WORTHLESS);
729 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
730 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
735 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
740 if (o_ptr->tval >= TV_LIFE_BOOK &&
741 !check_book_realm(o_ptr->tval, o_ptr->sval))
743 ADD_FLG(FLG_UNREADABLE);
744 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
747 if (REALM1_BOOK == o_ptr->tval &&
748 p_ptr->pclass != CLASS_SORCERER &&
749 p_ptr->pclass != CLASS_RED_MAGE)
755 if (REALM2_BOOK == o_ptr->tval &&
756 p_ptr->pclass != CLASS_SORCERER &&
757 p_ptr->pclass != CLASS_RED_MAGE)
763 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
765 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
767 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
769 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
772 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
773 || o_ptr->tval == TV_ARROW)
774 ADD_FLG(FLG_MISSILES);
775 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
776 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
777 ADD_FLG(FLG_DEVICES);
778 else if (o_ptr->tval == TV_LITE)
780 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
781 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
783 else if (o_ptr->tval == TV_CORPSE)
784 ADD_FLG(FLG_CORPSES);
785 else if (o_ptr->tval >= TV_LIFE_BOOK)
786 ADD_FLG(FLG_SPELLBOOKS);
787 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
788 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
789 ADD_FLG(FLG_WEAPONS);
790 else if (o_ptr->tval == TV_SHIELD)
791 ADD_FLG(FLG_SHIELDS);
792 else if (o_ptr->tval == TV_BOW)
794 else if (o_ptr->tval == TV_RING)
796 else if (o_ptr->tval == TV_AMULET)
797 ADD_FLG(FLG_AMULETS);
798 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
799 o_ptr->tval == TV_SOFT_ARMOR)
801 else if (o_ptr->tval == TV_CLOAK)
803 else if (o_ptr->tval == TV_HELM)
805 else if (o_ptr->tval == TV_GLOVES)
807 else if (o_ptr->tval == TV_BOOTS)
810 /* Prepare the object description */
813 char o_name[MAX_NLEN];
815 object_desc(o_name, o_ptr, FALSE, 0);
818 * If necessary, add a '^' which indicates the
821 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
824 /* Register the name in lowercase */
825 str_tolower(name_str);
826 entry->name = string_make(name_str);
833 * A function to delete entry
835 static void autopick_free_entry(autopick_type *entry)
837 string_free(entry->name);
838 string_free(entry->insc);
843 * Initialize auto-picker preference
845 #define MAX_AUTOPICK_DEFAULT 200
847 void init_autopicker(void)
849 static const char easy_autopick_inscription[] = "(:=g";
855 max_max_autopick = MAX_AUTOPICK_DEFAULT;
856 C_MAKE(autopick_list, max_max_autopick, autopick_type);
860 /* Clear old entries */
861 for( i = 0; i < max_autopick; i++)
862 autopick_free_entry(&autopick_list[i]);
866 /* There is always one entry "=g" */
867 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
868 autopick_list[max_autopick++] = entry;
873 * Add one line to autopick_list[]
875 static void add_autopick_list(autopick_type *entry)
877 /* There is no enough space to add one line */
878 if (max_autopick >= max_max_autopick)
880 int old_max_max_autopick = max_max_autopick;
881 autopick_type *old_autopick_list = autopick_list;
883 /* Increase size of list */
884 max_max_autopick += MAX_AUTOPICK_DEFAULT;
887 C_MAKE(autopick_list, max_max_autopick, autopick_type);
889 /* Copy from old list to new list */
890 C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
893 C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
897 autopick_list[max_autopick] = *entry;
904 * Process line for auto picker/destroyer.
906 errr process_pickpref_file_line(char *buf)
908 autopick_type an_entry, *entry = &an_entry;
911 /* Nuke illegal char */
912 for(i = 0; buf[i]; i++)
921 if (isspace(buf[i]) && buf[i] != ' ')
926 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
928 /* Already has the same entry? */
929 for(i = 0; i < max_autopick; i++)
930 if(!strcmp(entry->name, autopick_list[i].name)
931 && entry->flag[0] == autopick_list[i].flag[0]
932 && entry->flag[1] == autopick_list[i].flag[1]
933 && entry->dice == autopick_list[i].dice
934 && entry->bonus == autopick_list[i].bonus) return 0;
936 add_autopick_list(entry);
942 * Reconstruct preference line from entry
944 cptr autopick_line_from_entry(autopick_type *entry)
946 char buf[MAX_LINELEN];
948 bool sepa_flag = TRUE;
951 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
952 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
953 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
954 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
958 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
959 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
960 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
961 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
962 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
963 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
964 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
966 if (IS_FLG(FLG_MORE_DICE))
968 ADD_KEY(KEY_MORE_THAN);
969 strcat(ptr, format("%d", entry->dice));
973 if (IS_FLG(FLG_MORE_BONUS))
975 ADD_KEY(KEY_MORE_BONUS);
976 strcat(ptr, format("%d", entry->bonus));
977 ADD_KEY(KEY_MORE_BONUS2);
980 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
981 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
982 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
983 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
984 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
985 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
986 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
987 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
988 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
989 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
990 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
991 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
992 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
993 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
994 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
996 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
998 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
999 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
1000 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
1001 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
1002 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
1003 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
1004 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
1005 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
1006 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
1007 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
1008 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
1009 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
1010 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
1011 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
1012 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
1013 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
1014 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
1015 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
1016 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
1017 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
1019 /* You don't need sepalator after adjective */
1020 /* 'artifact' is not true adjective */
1021 else if (!IS_FLG(FLG_ARTIFACT))
1024 if (entry->name && entry->name[0])
1028 if (sepa_flag) strcat(buf, ":");
1031 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
1034 if (iskanji(entry->name[j]))
1035 buf[i++] = entry->name[j++];
1037 buf[i++] = entry->name[j++];
1048 while (entry->insc[j] && i < MAX_LINELEN - 2)
1051 if (iskanji(entry->insc[j]))
1052 buf[i++] = entry->insc[j++];
1054 buf[i++] = entry->insc[j++];
1059 return string_make(buf);
1064 * Reconstruct preference line from entry and kill entry
1066 static cptr autopick_line_from_entry_kill(autopick_type *entry)
1068 cptr ptr = autopick_line_from_entry(entry);
1070 /* Free memory for original entry */
1071 autopick_free_entry(entry);
1078 * A function for Auto-picker/destroyer
1079 * Examine whether the object matches to the entry
1081 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
1084 cptr ptr = entry->name;
1086 /*** Unaware items ***/
1087 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
1090 /*** Unidentified ***/
1091 if (IS_FLG(FLG_UNIDENTIFIED)
1092 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1095 /*** Identified ***/
1096 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
1099 /*** *Identified* ***/
1100 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1101 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1104 /*** Dice boosted (weapon of slaying) ***/
1105 if (IS_FLG(FLG_BOOSTED))
1107 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1109 switch( o_ptr->tval )
1115 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1124 /*** Weapons which dd*ds is more than nn ***/
1125 if (IS_FLG(FLG_MORE_DICE))
1127 if (o_ptr->dd * o_ptr->ds < entry->dice)
1131 /*** Weapons whic dd*ds is more than nn ***/
1132 if (IS_FLG(FLG_MORE_BONUS))
1134 if (!object_known_p(o_ptr)) return FALSE;
1138 if (o_ptr->pval < entry->bonus) return FALSE;
1142 if (o_ptr->to_h < entry->bonus &&
1143 o_ptr->to_d < entry->bonus &&
1144 o_ptr->to_a < entry->bonus &&
1145 o_ptr->pval < entry->bonus)
1150 /*** Worthless items ***/
1151 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1154 /*** Artifact object ***/
1155 if (IS_FLG(FLG_ARTIFACT))
1157 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
1161 /*** Ego object ***/
1162 if (IS_FLG(FLG_EGO))
1164 /* Need to be an ego item */
1165 if (!o_ptr->name2) return FALSE;
1167 /* Need to be known to be an ego */
1168 if (!object_known_p(o_ptr) &&
1169 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1174 if (IS_FLG(FLG_NAMELESS))
1176 if (!(TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
1180 if (object_known_p(o_ptr))
1182 /* Artifacts and Ego objects are not okay */
1183 if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2)
1187 /* Pseudo-identified */
1188 else if (o_ptr->ident & IDENT_SENSE)
1190 switch (o_ptr->feeling)
1200 /* It's not nameless */
1208 /* Not known to be nameless */
1213 /*** Rere equpiments ***/
1214 if (IS_FLG(FLG_RARE) && !is_rare(o_ptr))
1217 /*** Common equpiments ***/
1218 if (IS_FLG(FLG_COMMON) && is_rare(o_ptr))
1221 /*** Wanted monster's corpse/skeletons ***/
1222 if (IS_FLG(FLG_WANTED) &&
1223 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
1226 /*** Unique monster's corpse/skeletons/statues ***/
1227 if (IS_FLG(FLG_UNIQUE) &&
1228 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1229 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1232 /*** Human corpse/skeletons (for Daemon magic) ***/
1233 if (IS_FLG(FLG_HUMAN) &&
1234 (o_ptr->tval != TV_CORPSE ||
1235 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1238 /*** Unreadable spellbooks ***/
1239 if (IS_FLG(FLG_UNREADABLE) &&
1240 (o_ptr->tval < TV_LIFE_BOOK ||
1241 check_book_realm(o_ptr->tval, o_ptr->sval)))
1244 /*** First realm spellbooks ***/
1245 if (IS_FLG(FLG_REALM1) &&
1246 (REALM1_BOOK != o_ptr->tval ||
1247 p_ptr->pclass == CLASS_SORCERER ||
1248 p_ptr->pclass == CLASS_RED_MAGE))
1251 /*** Second realm spellbooks ***/
1252 if (IS_FLG(FLG_REALM2) &&
1253 (REALM2_BOOK != o_ptr->tval ||
1254 p_ptr->pclass == CLASS_SORCERER ||
1255 p_ptr->pclass == CLASS_RED_MAGE))
1258 /*** First rank spellbooks ***/
1259 if (IS_FLG(FLG_FIRST) &&
1260 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1263 /*** Second rank spellbooks ***/
1264 if (IS_FLG(FLG_SECOND) &&
1265 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1268 /*** Third rank spellbooks ***/
1269 if (IS_FLG(FLG_THIRD) &&
1270 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1273 /*** Fourth rank spellbooks ***/
1274 if (IS_FLG(FLG_FOURTH) &&
1275 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1279 if (IS_FLG(FLG_WEAPONS))
1281 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
1284 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1286 if (!is_favorite(o_ptr))
1289 else if (IS_FLG(FLG_ARMORS))
1291 if (!(TV_ARMOR_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_ARMOR_END))
1294 else if (IS_FLG(FLG_MISSILES))
1298 case TV_SHOT: case TV_BOLT: case TV_ARROW:
1300 default: return FALSE;
1303 else if (IS_FLG(FLG_DEVICES))
1307 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1309 default: return FALSE;
1312 else if (IS_FLG(FLG_LIGHTS))
1314 if (!(o_ptr->tval == TV_LITE))
1317 else if (IS_FLG(FLG_JUNKS))
1321 case TV_SKELETON: case TV_BOTTLE:
1322 case TV_JUNK: case TV_STATUE:
1324 default: return FALSE;
1327 else if (IS_FLG(FLG_CORPSES))
1329 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1332 else if (IS_FLG(FLG_SPELLBOOKS))
1334 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1337 else if (IS_FLG(FLG_HAFTED))
1339 if (!(o_ptr->tval == TV_HAFTED))
1342 else if (IS_FLG(FLG_SHIELDS))
1344 if (!(o_ptr->tval == TV_SHIELD))
1347 else if (IS_FLG(FLG_BOWS))
1349 if (!(o_ptr->tval == TV_BOW))
1352 else if (IS_FLG(FLG_RINGS))
1354 if (!(o_ptr->tval == TV_RING))
1357 else if (IS_FLG(FLG_AMULETS))
1359 if (!(o_ptr->tval == TV_AMULET))
1362 else if (IS_FLG(FLG_SUITS))
1364 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1365 o_ptr->tval == TV_HARD_ARMOR ||
1366 o_ptr->tval == TV_SOFT_ARMOR))
1369 else if (IS_FLG(FLG_CLOAKS))
1371 if (!(o_ptr->tval == TV_CLOAK))
1374 else if (IS_FLG(FLG_HELMS))
1376 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1379 else if (IS_FLG(FLG_GLOVES))
1381 if (!(o_ptr->tval == TV_GLOVES))
1384 else if (IS_FLG(FLG_BOOTS))
1386 if (!(o_ptr->tval == TV_BOOTS))
1390 /* Keyword don't match */
1394 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1398 if (!my_strstr(o_name, ptr)) return FALSE;
1401 /* TRUE when it need not to be 'collecting' */
1402 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1404 /* Check if there is a same item */
1405 for (j = 0; j < INVEN_PACK; j++)
1408 * 'Collecting' means the item must be absorbed
1409 * into an inventory slot.
1410 * But an item can not be absorbed into itself!
1412 if ((&inventory[j] != o_ptr) &&
1413 object_similar(&inventory[j], o_ptr))
1417 /* Not collecting */
1423 * A function for Auto-picker/destroyer
1424 * Examine whether the object matches to the list of keywords or not.
1426 int is_autopick(object_type *o_ptr)
1429 char o_name[MAX_NLEN];
1431 if (o_ptr->tval == TV_GOLD) return -1;
1433 /* Prepare object name string first */
1434 object_desc(o_name, o_ptr, FALSE, 3);
1436 /* Convert the string to lower case */
1437 str_tolower(o_name);
1439 /* Look for a matching entry in the list */
1440 for (i=0; i < max_autopick; i++)
1442 autopick_type *entry = &autopick_list[i];
1444 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1447 /* No matching entry */
1455 static void auto_inscribe_item(object_type *o_ptr, int idx)
1457 /* Are there auto-inscription? */
1458 if (idx < 0 || !autopick_list[idx].insc) return;
1460 if (!o_ptr->inscription)
1461 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1463 /* Redraw inscription */
1464 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1466 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1467 p_ptr->update |= (PU_BONUS);
1472 * Automatically destroy items in this grid.
1474 static bool is_opt_confirm_destroy(object_type *o_ptr)
1476 if (!destroy_items) return FALSE;
1478 /* Known to be worthless? */
1480 if (object_value(o_ptr) > 0) return FALSE;
1483 if ((o_ptr->tval >= TV_MISSILE_BEGIN) && (o_ptr->tval <= TV_ARMOR_END)) return FALSE;
1486 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1490 if (o_ptr->tval == TV_CORPSE
1491 && object_is_shoukinkubi(o_ptr)) return FALSE;
1495 if (o_ptr->tval == TV_CORPSE) return FALSE;
1498 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1502 if (p_ptr->prace == RACE_DEMON)
1504 if (o_ptr->tval == TV_CORPSE &&
1505 o_ptr->sval == SV_CORPSE &&
1506 my_strchr("pht", r_info[o_ptr->pval].d_char))
1510 if (p_ptr->pclass == CLASS_ARCHER)
1512 if (o_ptr->tval == TV_SKELETON ||
1513 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1516 else if (p_ptr->pclass == CLASS_NINJA)
1518 if (o_ptr->tval == TV_LITE &&
1519 o_ptr->name2 == EGO_LITE_DARKNESS)
1522 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1523 p_ptr->pclass == CLASS_CAVALRY)
1525 if (o_ptr->tval == TV_WAND &&
1526 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1531 if (o_ptr->tval == TV_GOLD) return FALSE;
1538 * Automatically destroy an item if it is to be destroyed
1540 * When always_pickup is 'yes', we disable auto-destroyer function of
1541 * auto-picker/destroyer, and do only easy-auto-destroyer.
1543 static object_type autopick_last_destroyed_object;
1545 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1547 bool destroy = FALSE;
1549 /* Easy-Auto-Destroyer (3rd priority) */
1550 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1552 /* Protected by auto-picker (2nd priotity) */
1553 if (autopick_idx >= 0 &&
1554 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1557 /* Auto-destroyer works only when !always_pickup */
1560 /* Auto-picker/destroyer (1st priority) */
1561 if (autopick_idx >= 0 &&
1562 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1566 /* Not to be destroyed */
1567 if (!destroy) return;
1569 /* Now decided to destroy */
1574 if (!can_player_destroy_object(o_ptr))
1576 char o_name[MAX_NLEN];
1578 /* Describe the object (with {terrible/special}) */
1579 object_desc(o_name, o_ptr, TRUE, 3);
1583 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1585 msg_format("You cannot auto-destroy %s.", o_name);
1592 /* Record name of destroyed item */
1593 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1596 o_ptr->marked |= OM_AUTODESTROY;
1597 p_ptr->notice |= PN_AUTODESTROY;
1604 * Auto-destroy marked item
1606 static void delayed_auto_destroy_aux(int item)
1610 /* Get the item (in the pack) */
1611 if (item >= 0) o_ptr = &inventory[item];
1613 /* Get the item (on the floor) */
1614 else o_ptr = &o_list[0 - item];
1616 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1618 char o_name[MAX_NLEN];
1620 /* Describe the object (with {terrible/special}) */
1621 object_desc(o_name, o_ptr, TRUE, 3);
1623 /* Eliminate the item (from the pack) */
1626 inven_item_increase(item, -(o_ptr->number));
1627 inven_item_optimize(item);
1630 /* Eliminate the item (from the floor) */
1633 delete_object_idx(0 - item);
1636 /* Print a message */
1638 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1640 msg_format("Auto-destroying %s.", o_name);
1647 * Auto-destroy marked items in inventry and on floor
1649 void delayed_auto_destroy(void)
1654 * Scan inventry in reverse order to prevent
1655 * skipping after inven_item_optimize()
1657 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1658 delayed_auto_destroy_aux(item);
1660 /* Scan the pile of objects */
1661 item = cave[py][px].o_idx;
1664 int next = o_list[item].next_o_idx;
1665 delayed_auto_destroy_aux(-item);
1672 * Auto-inscription and/or destroy
1674 * Auto-destroyer works only on inventory or on floor stack only when
1677 void auto_do_item(int item, bool destroy)
1682 /* Get the item (in the pack) */
1683 if (item >= 0) o_ptr = &inventory[item];
1685 /* Get the item (on the floor) */
1686 else o_ptr = &o_list[0 - item];
1688 /* Get the index in the auto-pick/destroy list */
1689 idx = is_autopick(o_ptr);
1691 /* Do auto-inscription */
1692 auto_inscribe_item(o_ptr, idx);
1694 /* Do auto-destroy if needed */
1695 if (destroy && item <= INVEN_PACK)
1696 auto_destroy_item(o_ptr, idx);
1701 * Automatically pickup/destroy items in this grid.
1703 void auto_pickup_items(cave_type *c_ptr)
1705 s16b this_o_idx, next_o_idx = 0;
1707 /* Scan the pile of objects */
1708 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1712 /* Acquire object */
1713 object_type *o_ptr = &o_list[this_o_idx];
1715 /* Acquire next object */
1716 next_o_idx = o_ptr->next_o_idx;
1718 idx = is_autopick(o_ptr);
1720 /* Item index for floor -1,-2,-3,... */
1721 auto_inscribe_item(o_ptr, idx);
1724 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1728 if (!inven_carry_okay(o_ptr))
1730 char o_name[MAX_NLEN];
1732 /* Describe the object */
1733 object_desc(o_name, o_ptr, TRUE, 3);
1737 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1739 msg_format("You have no room for %s.", o_name);
1741 /* Hack - remember that the item has given a message here. */
1742 o_ptr->marked |= OM_NOMSG;
1746 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1748 char out_val[MAX_NLEN+20];
1749 char o_name[MAX_NLEN];
1751 if (o_ptr->marked & OM_NO_QUERY)
1753 /* Already answered as 'No' */
1757 /* Describe the object */
1758 object_desc(o_name, o_ptr, TRUE, 3);
1761 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1763 sprintf(out_val, "Pick up %s? ", o_name);
1766 if (!get_check(out_val))
1768 /* Hack - remember that the item has given a message here. */
1769 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1774 py_pickup_aux(this_o_idx);
1779 * When always_pickup is 'yes', we disable
1780 * auto-destroyer from autopick function, and do only
1781 * easy-auto-destroyer.
1785 auto_destroy_item(o_ptr, idx);
1791 #define PT_DEFAULT 0
1792 #define PT_WITH_PNAME 1
1795 * Get file name for autopick preference
1797 static cptr pickpref_filename(int filename_mode)
1800 static const char namebase[] = "picktype";
1802 static const char namebase[] = "pickpref";
1805 switch (filename_mode)
1808 return format("%s.prf", namebase);
1811 return format("%s-%s.prf", namebase, player_name);
1819 static const char autoregister_header[] = "?:$AUTOREGISTER";
1822 * Clear auto registered lines in the picktype.prf .
1824 static bool clear_auto_register(void)
1826 char tmp_file[1024];
1827 char pref_file[1024];
1832 bool autoregister = FALSE;
1835 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1836 pref_fff = my_fopen(pref_file, "r");
1840 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1841 pref_fff = my_fopen(pref_file, "r");
1850 /* Open a new (temporary) file */
1851 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1855 /* Close the preference file */
1859 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1861 msg_format("Failed to create temporary file %s.", tmp_file);
1868 /* Loop for every line */
1872 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1876 /* Delete auto-registered line */
1878 /* Count auto-destroy preference lines */
1879 if (buf[0] != '#' && buf[0] != '?') num++;
1882 /* We are looking for auto-registered line */
1885 if (streq(buf, autoregister_header))
1887 /* Delete all further lines */
1888 autoregister = TRUE;
1892 /* Copy orginally lines */
1893 fprintf(tmp_fff, "%s\n", buf);
1899 my_fclose(pref_fff);
1905 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1906 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1908 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1909 strcpy(buf, "These lines will be deleted. Are you sure? ");
1912 /* You can cancel it */
1913 if (!get_check(buf))
1916 autoregister = FALSE;
1919 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1921 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1927 /* If there are some changes, overwrite the original file with new one */
1930 /* Copy contents of temporary file */
1932 tmp_fff = my_fopen(tmp_file, "r");
1933 pref_fff = my_fopen(pref_file, "w");
1935 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1936 fprintf(pref_fff, "%s\n", buf);
1938 my_fclose(pref_fff);
1942 /* Kill the temporary file */
1950 * Automatically register an auto-destroy preference line
1952 bool add_auto_register(object_type *o_ptr)
1955 char pref_file[1024];
1957 autopick_type an_entry, *entry = &an_entry;
1959 int match_autopick = is_autopick(o_ptr);
1961 /* Already registered */
1962 if (match_autopick != -1)
1965 byte act = autopick_list[match_autopick].action;
1968 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1969 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1970 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1971 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1973 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1975 if (act & DO_AUTOPICK) what = "auto-pickup";
1976 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1977 else if (act & DONT_AUTOPICK) what = "leave on floor";
1978 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1980 msg_format("The object is already registered to %s.", what);
1986 /* Known to be an artifact? */
1987 if ((object_known_p(o_ptr) &&
1988 (artifact_p(o_ptr) || o_ptr->art_name)) ||
1989 ((o_ptr->ident & IDENT_SENSE) &&
1990 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1992 char o_name[MAX_NLEN];
1994 /* Describe the object (with {terrible/special}) */
1995 object_desc(o_name, o_ptr, TRUE, 3);
1999 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
2001 msg_format("You cannot auto-destroy %s.", o_name);
2009 if (!p_ptr->autopick_autoregister)
2011 /* Clear old auto registered lines */
2012 if (!clear_auto_register()) return FALSE;
2015 /* Try a filename with player name */
2016 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
2017 pref_fff = my_fopen(pref_file, "r");
2021 /* Use default name */
2022 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
2023 pref_fff = my_fopen(pref_file, "r");
2026 /* Check the header */
2030 if (my_fgets(pref_fff, buf, sizeof(buf)))
2032 /* No header found */
2033 p_ptr->autopick_autoregister = FALSE;
2038 if (streq(buf, autoregister_header))
2040 /* Found the header */
2041 p_ptr->autopick_autoregister = TRUE;
2047 /* Close read only FILE* */
2050 /* Open for append */
2051 pref_fff = my_fopen(pref_file, "a");
2056 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
2058 msg_format("Failed to open %s.", pref_file);
2066 if (!p_ptr->autopick_autoregister)
2068 /* Add the header */
2069 fprintf(pref_fff, "%s\n", autoregister_header);
2072 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
2073 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
2075 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
2076 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
2079 /* Now auto register is in-use */
2080 p_ptr->autopick_autoregister = TRUE;
2083 /* Get a preference entry */
2084 autopick_entry_from_object(entry, o_ptr);
2086 /* Set to auto-destroy (with no-display) */
2087 entry->action = DO_AUTODESTROY;
2089 /* Load the new line as preference */
2090 add_autopick_list(entry);
2092 /* Add a line to the file */
2093 /* Don't kill "entry" */
2094 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2096 /* Close the file */
2103 /******** Auto-picker/destroyer editor **********/
2105 #define MAX_YANK MAX_LINELEN
2106 #define MAX_LINES 3000
2108 #define MARK_MARK 0x01
2109 #define MARK_BY_SHIFT 0x02
2111 #define LSTAT_BYPASS 0x01
2112 #define LSTAT_EXPRESSION 0x02
2113 #define LSTAT_AUTOREGISTER 0x04
2115 #define QUIT_WITHOUT_SAVE 1
2116 #define QUIT_AND_SAVE 2
2119 * Struct for yank buffer
2121 typedef struct chain_str {
2122 struct chain_str *next;
2128 * Data struct for text editor
2134 int old_wid, old_hgt;
2136 int old_upper, old_left;
2140 object_type *search_o_ptr;
2142 cptr last_destroyed;
2144 chain_str_type *yank;
2148 byte states[MAX_LINES];
2160 * Dirty flag for text editor
2162 #define DIRTY_ALL 0x0001
2163 #define DIRTY_MODE 0x0004
2164 #define DIRTY_SCREEN 0x0008
2165 #define DIRTY_NOT_FOUND 0x0010
2166 #define DIRTY_NO_SEARCH 0x0020
2167 #define DIRTY_EXPRESSION 0x0040
2168 #define DIRTY_SKIP_INACTIVE 0x0080
2169 #define DIRTY_INACTIVE 0x0100
2172 * Describe which kind of object is Auto-picked/destroyed
2174 static void describe_autopick(char *buff, autopick_type *entry)
2176 cptr str = entry->name;
2177 byte act = entry->action;
2178 cptr insc = entry->insc;
2184 cptr before_str[100], body_str;
2187 body_str = "¥¢¥¤¥Æ¥à";
2189 /*** Collecting items ***/
2190 /*** Which can be absorbed into a slot as a bundle ***/
2191 if (IS_FLG(FLG_COLLECTING))
2192 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2194 /*** Unaware items ***/
2195 if (IS_FLG(FLG_UNAWARE))
2196 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2198 /*** Unidentified ***/
2199 if (IS_FLG(FLG_UNIDENTIFIED))
2200 before_str[before_n++] = "̤´ÕÄê¤Î";
2202 /*** Identified ***/
2203 if (IS_FLG(FLG_IDENTIFIED))
2204 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2206 /*** *Identified* ***/
2207 if (IS_FLG(FLG_STAR_IDENTIFIED))
2208 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2210 /*** Dice boosted (weapon of slaying) ***/
2211 if (IS_FLG(FLG_BOOSTED))
2213 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2217 /*** Weapons whose dd*ds is more than nn ***/
2218 if (IS_FLG(FLG_MORE_DICE))
2220 static char more_than_desc_str[] = "___";
2221 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2224 sprintf(more_than_desc_str,"%d", entry->dice);
2225 before_str[before_n++] = more_than_desc_str;
2226 before_str[before_n++] = "°Ê¾å¤Î";
2229 /*** Items whose magical bonus is more than nn ***/
2230 if (IS_FLG(FLG_MORE_BONUS))
2232 static char more_bonus_desc_str[] = "___";
2233 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2235 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2236 before_str[before_n++] = more_bonus_desc_str;
2237 before_str[before_n++] = ")°Ê¾å¤Î";
2240 /*** Worthless items ***/
2241 if (IS_FLG(FLG_WORTHLESS))
2242 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2245 if (IS_FLG(FLG_ARTIFACT))
2247 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2252 if (IS_FLG(FLG_EGO))
2254 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2259 if (IS_FLG(FLG_NAMELESS))
2261 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2265 /*** Rare equpiments ***/
2266 if (IS_FLG(FLG_RARE))
2268 before_str[before_n++] = "¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ò´Þ¤àÄÁ¤·¤¤";
2272 /*** Common equpiments ***/
2273 if (IS_FLG(FLG_COMMON))
2275 before_str[before_n++] = "¤¢¤ê¤Õ¤ì¤¿(¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ÎÄÁ¤·¤¤Êª¤Ç¤Ï¤Ê¤¤)";
2279 /*** Wanted monster's corpse/skeletons ***/
2280 if (IS_FLG(FLG_WANTED))
2282 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2283 body_str = "»àÂΤä¹ü";
2286 /*** Human corpse/skeletons (for Daemon magic) ***/
2287 if (IS_FLG(FLG_HUMAN))
2289 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2290 body_str = "»àÂΤä¹ü";
2293 /*** Unique monster's corpse/skeletons/statues ***/
2294 if (IS_FLG(FLG_UNIQUE))
2296 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2297 body_str = "»àÂΤä¹ü";
2300 /*** Unreadable spellbooks ***/
2301 if (IS_FLG(FLG_UNREADABLE))
2303 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2304 body_str = "ËâË¡½ñ";
2307 /*** First realm spellbooks ***/
2308 if (IS_FLG(FLG_REALM1))
2310 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2311 body_str = "ËâË¡½ñ";
2314 /*** Second realm spellbooks ***/
2315 if (IS_FLG(FLG_REALM2))
2317 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2318 body_str = "ËâË¡½ñ";
2321 /*** First rank spellbooks ***/
2322 if (IS_FLG(FLG_FIRST))
2324 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2325 body_str = "ËâË¡½ñ";
2328 /*** Second rank spellbooks ***/
2329 if (IS_FLG(FLG_SECOND))
2331 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2332 body_str = "ËâË¡½ñ";
2335 /*** Third rank spellbooks ***/
2336 if (IS_FLG(FLG_THIRD))
2338 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2339 body_str = "ËâË¡½ñ";
2342 /*** Fourth rank spellbooks ***/
2343 if (IS_FLG(FLG_FOURTH))
2345 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2346 body_str = "ËâË¡½ñ";
2350 if (IS_FLG(FLG_ITEMS))
2351 ; /* Nothing to do */
2352 else if (IS_FLG(FLG_WEAPONS))
2354 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2355 body_str = "ÆÀ°ÕÉð´ï";
2356 else if (IS_FLG(FLG_ARMORS))
2358 else if (IS_FLG(FLG_MISSILES))
2359 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2360 else if (IS_FLG(FLG_DEVICES))
2361 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2362 else if (IS_FLG(FLG_LIGHTS))
2363 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2364 else if (IS_FLG(FLG_JUNKS))
2365 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2366 else if (IS_FLG(FLG_CORPSES))
2367 body_str = "»àÂΤä¹ü";
2368 else if (IS_FLG(FLG_SPELLBOOKS))
2369 body_str = "ËâË¡½ñ";
2370 else if (IS_FLG(FLG_HAFTED))
2372 else if (IS_FLG(FLG_SHIELDS))
2374 else if (IS_FLG(FLG_BOWS))
2375 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2376 else if (IS_FLG(FLG_RINGS))
2378 else if (IS_FLG(FLG_AMULETS))
2379 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2380 else if (IS_FLG(FLG_SUITS))
2382 else if (IS_FLG(FLG_CLOAKS))
2383 body_str = "¥¯¥í¡¼¥¯";
2384 else if (IS_FLG(FLG_HELMS))
2385 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2386 else if (IS_FLG(FLG_GLOVES))
2388 else if (IS_FLG(FLG_BOOTS))
2389 body_str = "¥Ö¡¼¥Ä";
2393 strcat(buff, "Á´¤Æ¤Î");
2394 else for (i = 0; i < before_n && before_str[i]; i++)
2395 strcat(buff, before_str[i]);
2397 strcat(buff, body_str);
2407 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2408 strncat(buff, str, 80);
2410 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2412 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2417 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2419 if (my_strstr(insc, "%%all"))
2420 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2421 else if (my_strstr(insc, "%all"))
2422 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2423 else if (my_strstr(insc, "%%"))
2424 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2425 else if (my_strstr(insc, "%"))
2426 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2428 strcat(buff, "¤È¹ï¤ó¤Ç");
2433 if (act & DONT_AUTOPICK)
2434 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2435 else if (act & DO_AUTODESTROY)
2436 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2437 else if (act & DO_QUERY_AUTOPICK)
2438 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2440 strcat(buff, "½¦¤¦¡£");
2442 if (act & DO_DISPLAY)
2444 if (act & DONT_AUTOPICK)
2445 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2446 else if (act & DO_AUTODESTROY)
2447 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2449 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2452 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2456 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2457 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2461 /*** Collecting items ***/
2462 /*** Which can be absorbed into a slot as a bundle ***/
2463 if (IS_FLG(FLG_COLLECTING))
2464 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2466 /*** Unaware items ***/
2467 if (IS_FLG(FLG_UNAWARE))
2469 before_str[before_n++] = "unidentified";
2470 whose_str[whose_n++] = "basic abilities are not known";
2473 /*** Unidentified ***/
2474 if (IS_FLG(FLG_UNIDENTIFIED))
2475 before_str[before_n++] = "unidentified";
2477 /*** Identified ***/
2478 if (IS_FLG(FLG_IDENTIFIED))
2479 before_str[before_n++] = "identified";
2481 /*** *Identified* ***/
2482 if (IS_FLG(FLG_STAR_IDENTIFIED))
2483 before_str[before_n++] = "fully identified";
2485 /*** Rare equpiments ***/
2486 if (IS_FLG(FLG_RARE))
2488 before_str[before_n++] = "very rare";
2489 body_str = "equipments";
2490 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2493 /*** Common equpiments ***/
2494 if (IS_FLG(FLG_COMMON))
2496 before_str[before_n++] = "relatively common";
2497 body_str = "equipments";
2498 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2501 /*** Worthless items ***/
2502 if (IS_FLG(FLG_WORTHLESS))
2504 before_str[before_n++] = "worthless";
2505 which_str[which_n++] = "can not be sold at stores";
2509 if (IS_FLG(FLG_ARTIFACT))
2511 before_str[before_n++] = "artifact";
2515 if (IS_FLG(FLG_EGO))
2517 before_str[before_n++] = "ego";
2521 if (IS_FLG(FLG_NAMELESS))
2523 body_str = "equipment";
2524 which_str[which_n++] = "is neither ego-item nor artifact";
2527 /*** Dice boosted (weapon of slaying) ***/
2528 if (IS_FLG(FLG_BOOSTED))
2530 body_str = "weapons";
2531 whose_str[whose_n++] = "damage dice is bigger than normal";
2534 /*** Weapons whose dd*ds is more than nn ***/
2535 if (IS_FLG(FLG_MORE_DICE))
2537 static char more_than_desc_str[] =
2538 "maximum damage from dice is bigger than __";
2539 body_str = "weapons";
2541 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2543 whose_str[whose_n++] = more_than_desc_str;
2546 /*** Items whose magical bonus is more than nn ***/
2547 if (IS_FLG(FLG_MORE_BONUS))
2549 static char more_bonus_desc_str[] =
2550 "magical bonus is bigger than (+__)";
2552 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2553 "%d)", entry->bonus);
2554 whose_str[whose_n++] = more_bonus_desc_str;
2557 /*** Wanted monster's corpse/skeletons ***/
2558 if (IS_FLG(FLG_WANTED))
2560 body_str = "corpse or skeletons";
2561 which_str[which_n++] = "is wanted at the Hunter's Office";
2564 /*** Human corpse/skeletons (for Daemon magic) ***/
2565 if (IS_FLG(FLG_HUMAN))
2567 before_str[before_n++] = "humanoid";
2568 body_str = "corpse or skeletons";
2569 which_str[which_n++] = "can be used for Daemon magic";
2572 /*** Unique monster's corpse/skeletons/statues ***/
2573 if (IS_FLG(FLG_UNIQUE))
2575 before_str[before_n++] = "unique monster's";
2576 body_str = "corpse or skeletons";
2579 /*** Unreadable spellbooks ***/
2580 if (IS_FLG(FLG_UNREADABLE))
2582 body_str = "spellbooks";
2583 after_str[after_n++] = "of different realms from yours";
2586 /*** First realm spellbooks ***/
2587 if (IS_FLG(FLG_REALM1))
2589 body_str = "spellbooks";
2590 after_str[after_n++] = "of your first realm";
2593 /*** Second realm spellbooks ***/
2594 if (IS_FLG(FLG_REALM2))
2596 body_str = "spellbooks";
2597 after_str[after_n++] = "of your second realm";
2600 /*** First rank spellbooks ***/
2601 if (IS_FLG(FLG_FIRST))
2603 before_str[before_n++] = "first one of four";
2604 body_str = "spellbooks";
2607 /*** Second rank spellbooks ***/
2608 if (IS_FLG(FLG_SECOND))
2610 before_str[before_n++] = "second one of four";
2611 body_str = "spellbooks";
2614 /*** Third rank spellbooks ***/
2615 if (IS_FLG(FLG_THIRD))
2617 before_str[before_n++] = "third one of four";
2618 body_str = "spellbooks";
2621 /*** Fourth rank spellbooks ***/
2622 if (IS_FLG(FLG_FOURTH))
2624 before_str[before_n++] = "fourth one of four";
2625 body_str = "spellbooks";
2629 if (IS_FLG(FLG_ITEMS))
2630 ; /* Nothing to do */
2631 else if (IS_FLG(FLG_WEAPONS))
2632 body_str = "weapons";
2633 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2634 body_str = "favorite weapons";
2635 else if (IS_FLG(FLG_ARMORS))
2636 body_str = "armors";
2637 else if (IS_FLG(FLG_MISSILES))
2638 body_str = "shots, arrows or crossbow bolts";
2639 else if (IS_FLG(FLG_DEVICES))
2640 body_str = "scrolls, wands, staves or rods";
2641 else if (IS_FLG(FLG_LIGHTS))
2642 body_str = "light sources";
2643 else if (IS_FLG(FLG_JUNKS))
2644 body_str = "junk such as broken sticks";
2645 else if (IS_FLG(FLG_CORPSES))
2646 body_str = "corpses or skeletons";
2647 else if (IS_FLG(FLG_SPELLBOOKS))
2648 body_str = "spellbooks";
2649 else if (IS_FLG(FLG_HAFTED))
2650 body_str = "hafted weapons";
2651 else if (IS_FLG(FLG_SHIELDS))
2652 body_str = "shields";
2653 else if (IS_FLG(FLG_BOWS))
2654 body_str = "slings, bows or crossbows";
2655 else if (IS_FLG(FLG_RINGS))
2657 else if (IS_FLG(FLG_AMULETS))
2658 body_str = "amulets";
2659 else if (IS_FLG(FLG_SUITS))
2660 body_str = "body armors";
2661 else if (IS_FLG(FLG_CLOAKS))
2662 body_str = "cloaks";
2663 else if (IS_FLG(FLG_HELMS))
2664 body_str = "helms or crowns";
2665 else if (IS_FLG(FLG_GLOVES))
2666 body_str = "gloves";
2667 else if (IS_FLG(FLG_BOOTS))
2670 /* Prepare a string for item name */
2677 whose_str[whose_n++] = "name is beginning with \"";
2680 which_str[which_n++] = "have \"";
2684 /* Describe action flag */
2685 if (act & DONT_AUTOPICK)
2686 strcpy(buff, "Leave on floor ");
2687 else if (act & DO_AUTODESTROY)
2688 strcpy(buff, "Destroy ");
2689 else if (act & DO_QUERY_AUTOPICK)
2690 strcpy(buff, "Ask to pick up ");
2692 strcpy(buff, "Pickup ");
2694 /* Auto-insctiption */
2697 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2699 if (my_strstr(insc, "%all"))
2700 strcat(buff, ", replacing %all with code string representing all abilities,");
2701 else if (my_strstr(insc, "%"))
2702 strcat(buff, ", replacing % with code string representing extra random abilities,");
2704 strcat(buff, " on ");
2709 strcat(buff, "all ");
2710 else for (i = 0; i < before_n && before_str[i]; i++)
2712 strcat(buff, before_str[i]);
2717 strcat(buff, body_str);
2720 for (i = 0; i < after_n && after_str[i]; i++)
2723 strcat(buff, after_str[i]);
2727 for (i = 0; i < whose_n && whose_str[i]; i++)
2730 strcat(buff, " whose ");
2732 strcat(buff, ", and ");
2734 strcat(buff, whose_str[i]);
2737 /* Item name ; whose name is beginning with "str" */
2744 /* whose ..., and which .... */
2745 if (whose_n && which_n)
2746 strcat(buff, ", and ");
2749 for (i = 0; i < which_n && which_str[i]; i++)
2752 strcat(buff, " which ");
2754 strcat(buff, ", and ");
2756 strcat(buff, which_str[i]);
2759 /* Item name ; which have "str" as part of its name */
2762 strncat(buff, str, 80);
2763 strcat(buff, "\" as part of its name");
2767 /* Describe whether it will be displayed on the full map or not */
2768 if (act & DO_DISPLAY)
2770 if (act & DONT_AUTOPICK)
2771 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2772 else if (act & DO_AUTODESTROY)
2773 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2775 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2778 strcat(buff, " Not displayed in the full map.");
2785 * Read whole lines of a file to memory
2787 static cptr *read_text_lines(cptr filename, bool user)
2789 cptr *lines_list = NULL;
2797 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2801 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2805 fff = my_fopen(buf, "r");
2809 /* Allocate list of pointers */
2810 C_MAKE(lines_list, MAX_LINES, cptr);
2813 while (0 == my_fgets(fff, buf, sizeof(buf)))
2815 lines_list[lines++] = string_make(buf);
2816 if (lines >= MAX_LINES - 1) break;
2819 lines_list[0] = string_make("");
2824 if (!fff) return NULL;
2829 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2834 *filename_mode_p = PT_WITH_PNAME;
2835 strcpy(buf, pickpref_filename(*filename_mode_p));
2836 lines_list = read_text_lines(buf, TRUE);
2840 *filename_mode_p = PT_DEFAULT;
2841 strcpy(buf, pickpref_filename(*filename_mode_p));
2842 lines_list = read_text_lines(buf, TRUE);
2847 strcpy(buf, pickpref_filename(*filename_mode_p));
2848 lines_list = read_text_lines(buf, FALSE);
2853 /* Allocate list of pointers */
2854 C_MAKE(lines_list, MAX_LINES, cptr);
2855 lines_list[0] = string_make("");
2862 * Write whole lines of memory to a file.
2864 static bool write_text_lines(cptr filename, cptr *lines_list)
2871 /* Build the filename */
2872 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2875 fff = my_fopen(buf, "w");
2878 for (lines = 0; lines_list[lines]; lines++)
2879 my_fputs(fff, lines_list[lines], 1024);
2884 if (!fff) return FALSE;
2890 * Free memory of lines_list.
2892 static void free_text_lines(cptr *lines_list)
2896 for (lines = 0; lines_list[lines]; lines++)
2897 string_free(lines_list[lines]);
2899 /* free list of pointers */
2900 C_FREE((char **)lines_list, MAX_LINES, char *);
2905 * Delete or insert string
2907 static void toggle_keyword(text_body_type *tb, int flg)
2913 /* Some lines are selected */
2916 by1 = MIN(tb->my, tb->cy);
2917 by2 = MAX(tb->my, tb->cy);
2920 /* No mark -- Select current line */
2921 else /* if (!tb->mark) */
2927 /* Set/Reset flag of each line */
2928 for (y = by1; y <= by2; y++)
2930 autopick_type an_entry, *entry = &an_entry;
2932 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2934 string_free(tb->lines_list[y]);
2938 /* Add? or Remove? */
2939 if (!IS_FLG(flg)) add = TRUE;
2942 /* No more change */
2946 /* You can use only one noun flag */
2947 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2950 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2954 /* You can use only one identify state flag */
2955 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2958 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2962 /* You can use only one flag in artifact/ego/nameless */
2963 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
2966 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
2970 /* You can use only one flag in rare/common */
2971 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
2974 for (i = FLG_RARE; i <= FLG_COMMON; i++)
2978 if (add) ADD_FLG(flg);
2981 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2984 tb->dirty_flags |= DIRTY_ALL;
2986 /* Text is changed */
2993 * Change command letter
2995 static void toggle_command_letter(text_body_type *tb, byte flg)
2997 autopick_type an_entry, *entry = &an_entry;
3002 /* Some lines are selected */
3005 by1 = MIN(tb->my, tb->cy);
3006 by2 = MAX(tb->my, tb->cy);
3009 /* No mark -- Select current line */
3010 else /* if (!tb->mark) */
3016 /* Set/Reset flag of each line */
3017 for (y = by1; y <= by2; y++)
3021 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3023 string_free(tb->lines_list[y]);
3027 /* Add? or Remove? */
3028 if (!(entry->action & flg)) add = TRUE;
3031 /* No more change */
3035 /* Count number of letter (by negative number) */
3036 if (entry->action & DONT_AUTOPICK) wid--;
3037 else if (entry->action & DO_AUTODESTROY) wid--;
3038 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3039 if (!(entry->action & DO_DISPLAY)) wid--;
3041 /* Set/Reset the flag */
3042 if (flg != DO_DISPLAY)
3044 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3045 if (add) entry->action |= flg;
3046 else entry->action |= DO_AUTOPICK;
3050 entry->action &= ~(DO_DISPLAY);
3051 if (add) entry->action |= flg;
3054 /* Correct cursor location */
3057 if (entry->action & DONT_AUTOPICK) wid++;
3058 else if (entry->action & DO_AUTODESTROY) wid++;
3059 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3060 if (!(entry->action & DO_DISPLAY)) wid++;
3062 if (wid > 0) tb->cx++;
3063 if (wid < 0 && tb->cx > 0) tb->cx--;
3066 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3069 tb->dirty_flags |= DIRTY_ALL;
3071 /* Text is changed */
3077 * Delete or insert string
3079 static void add_keyword(text_body_type *tb, int flg)
3083 /* Some lines are selected */
3086 by1 = MIN(tb->my, tb->cy);
3087 by2 = MAX(tb->my, tb->cy);
3090 /* No mark -- Select current line */
3091 else /* if (!tb->mark) */
3097 /* Set/Reset flag of each line */
3098 for (y = by1; y <= by2; y++)
3100 autopick_type an_entry, *entry = &an_entry;
3102 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3104 /* There is the flag already */
3107 /* Free memory for the entry */
3108 autopick_free_entry(entry);
3113 string_free(tb->lines_list[y]);
3115 /* Remove all noun flag */
3116 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3119 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3125 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3128 tb->dirty_flags |= DIRTY_ALL;
3130 /* Text is changed */
3137 * Check if this line is expression or not.
3138 * And update it if it is.
3140 static void check_expression_line(text_body_type *tb, int y)
3142 cptr s = tb->lines_list[y];
3144 if ((s[0] == '?' && s[1] == ':') ||
3145 (tb->states[y] & LSTAT_BYPASS))
3147 /* Expressions need re-evaluation */
3148 tb->dirty_flags |= DIRTY_EXPRESSION;
3154 * Insert return code and split the line
3156 static bool insert_return_code(text_body_type *tb)
3158 char buf[MAX_LINELEN];
3161 for (k = 0; tb->lines_list[k]; k++)
3162 /* count number of lines */ ;
3164 if (k >= MAX_LINES - 2) return FALSE;
3167 /* Move down lines */
3168 for (; tb->cy < k; k--)
3170 tb->lines_list[k+1] = tb->lines_list[k];
3171 tb->states[k+1] = tb->states[k];
3174 /* Split current line */
3175 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3178 if (iskanji(tb->lines_list[tb->cy][i]))
3179 buf[j++] = tb->lines_list[tb->cy][i++];
3181 buf[j++] = tb->lines_list[tb->cy][i];
3184 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3185 string_free(tb->lines_list[tb->cy]);
3186 tb->lines_list[tb->cy] = string_make(buf);
3188 /* Expressions need re-evaluation */
3189 tb->dirty_flags |= DIRTY_EXPRESSION;
3191 /* Text is changed */
3199 * Choose an item and get auto-picker entry from it.
3201 static object_type *choose_object(cptr q, cptr s)
3205 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3207 /* Get the item (in the pack) */
3208 if (item >= 0) return &inventory[item];
3210 /* Get the item (on the floor) */
3211 else return &o_list[0 - item];
3216 * Choose an item and get auto-picker entry from it.
3218 static bool entry_from_choosed_object(autopick_type *entry)
3225 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3226 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3228 q = "Enter which item? ";
3229 s = "You have nothing to enter.";
3231 o_ptr = choose_object(q, s);
3232 if (!o_ptr) return FALSE;
3234 autopick_entry_from_object(entry, o_ptr);
3240 * Choose an item for search
3242 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3244 char buf[MAX_NLEN+20];
3250 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3251 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3253 q = "Enter which item? ";
3254 s = "You have nothing to enter.";
3256 o_ptr = choose_object(q, s);
3257 if (!o_ptr) return 0;
3261 string_free(*search_strp);
3262 object_desc(buf, *o_handle, FALSE, 3);
3263 *search_strp = string_make(format("<%s>", buf));
3269 * Prepare for search by destroyed object
3271 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3273 char buf[MAX_NLEN+20];
3275 if (!autopick_last_destroyed_object.k_idx) return 0;
3277 *o_handle = &autopick_last_destroyed_object;
3279 string_free(*search_strp);
3280 object_desc(buf, *o_handle, FALSE, 3);
3281 *search_strp = string_make(format("<%s>", buf));
3287 * Choose an item or string for search
3289 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3295 * TERM_YELLOW : Overwrite mode
3296 * TERM_WHITE : Insert mode
3298 byte color = TERM_YELLOW;
3299 char buf[MAX_NLEN+20];
3303 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3305 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3307 int col = sizeof(prompt) - 1;
3309 /* Prepare string buffer for edit */
3310 if (*search_strp) strcpy(buf, *search_strp);
3313 /* Object searching mode */
3316 color = TERM_L_GREEN;
3319 /* Display prompt */
3329 /* Display the string */
3330 Term_erase(col, 0, 255);
3331 Term_putstr(col, 0, -1, color, buf);
3334 Term_gotoxy(col + pos, 0);
3336 /* Get a special key code */
3337 skey = inkey_special();
3339 /* Analyze the key */
3347 /* Now on insert mode */
3350 /* No move at beginning of line */
3351 if (0 == pos) break;
3355 int next_pos = i + 1;
3358 if (iskanji(buf[i])) next_pos++;
3361 /* Is there the cursor at next position? */
3362 if (next_pos >= pos) break;
3368 /* Get previous position */
3376 /* Now on insert mode */
3379 /* No move at end of line */
3380 if ('\0' == buf[pos]) break;
3384 if (iskanji(buf[pos])) pos += 2;
3402 if (*o_handle) return (back ? -1 : 1);
3403 string_free(*search_strp);
3404 *search_strp = string_make(buf);
3406 return (back ? -1 : 1);
3410 return get_object_for_search(o_handle, search_strp);
3413 /* Prepare string for destroyed object if there is one. */
3414 if (get_destroyed_object_for_search(o_handle, search_strp))
3424 /* Now on insert mode */
3427 /* No move at beginning of line */
3428 if (0 == pos) break;
3432 int next_pos = i + 1;
3435 if (iskanji(buf[i])) next_pos++;
3438 /* Is there the cursor at next position? */
3439 if (next_pos >= pos) break;
3445 /* Get previous position */
3448 /* Fall through to 'Delete key' */
3457 /* Now on insert mode */
3460 /* No move at end of line */
3461 if ('\0' == buf[pos]) break;
3463 /* Position of next character */
3467 /* Next character is one more byte away */
3468 if (iskanji(buf[pos])) src++;
3473 /* Move characters at src to dst */
3474 while ('\0' != (buf[dst++] = buf[src++]))
3482 /* Insert a character */
3487 /* Ignore special keys */
3488 if (skey & SKEY_MASK) break;
3490 /* Get a character code */
3493 /* Was non insert mode? */
3494 if (color != TERM_WHITE)
3496 /* Was object searching mode */
3497 if (color == TERM_L_GREEN)
3499 /* Cancel the mode */
3502 /* Remove indicating string */
3503 string_free(*search_strp);
3504 *search_strp = NULL;
3507 /* Overwrite default string */
3510 /* Go to insert mode */
3514 /* Save right part of string */
3515 strcpy(tmp, buf + pos);
3521 /* Bypass macro processing */
3539 if (pos < len && (isprint(c) || iskana(c)))
3541 if (pos < len && isprint(c))
3555 /* Write back the left part of string */
3556 my_strcat(buf, tmp, len + 1);
3563 /* Object searching mode was cancelled? */
3564 if (*o_handle && color != TERM_L_GREEN)
3566 /* Cancel the mode */
3569 /* Remove indicating string */
3571 string_free(*search_strp);
3572 *search_strp = NULL;
3577 } /* while (TRUE) */
3582 * Search next line matches for o_ptr
3584 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3586 autopick_type an_entry, *entry = &an_entry;
3587 char o_name[MAX_NLEN];
3588 int bypassed_cy = -1;
3590 /* Start searching from current cursor position */
3593 /* Prepare object name string first */
3594 object_desc(o_name, o_ptr, FALSE, 3);
3596 /* Convert the string to lower case */
3597 str_tolower(o_name);
3604 if (!tb->lines_list[++i]) break;
3611 /* Is this line is a correct entry? */
3612 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3614 /* Does this line match to the object? */
3615 if (!is_autopick_aux(o_ptr, entry, o_name)) continue;
3618 /* Found a line but it's inactive */
3619 if (tb->states[i] & LSTAT_BYPASS)
3621 /* If it is first found, remember it */
3622 if (bypassed_cy == -1) bypassed_cy = i;
3625 /* Found an active line! */
3628 /* Move to this line */
3632 if (bypassed_cy != -1)
3634 /* Mark as some lines are skipped */
3635 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3643 if (bypassed_cy != -1)
3645 /* Move to the remembered line */
3647 tb->cy = bypassed_cy;
3649 /* Mark as this line is inactive */
3650 tb->dirty_flags |= DIRTY_INACTIVE;
3655 /* Mark as NOT FOUND */
3656 tb->dirty_flags |= DIRTY_NOT_FOUND;
3664 * Search next line matches to the string
3666 static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
3668 int bypassed_cy = -1;
3669 int bypassed_cx = 0;
3671 /* Start searching from current cursor position */
3681 if (!tb->lines_list[++i]) break;
3688 /* Look for the string pattern */
3689 pos = my_strstr(tb->lines_list[i], search_str);
3694 /* Found a line but it's inactive */
3695 if ((tb->states[i] & LSTAT_BYPASS) &&
3696 !(tb->states[i] & LSTAT_EXPRESSION))
3698 /* If it is first found, remember it */
3699 if (bypassed_cy == -1)
3702 bypassed_cx = (int)(pos - tb->lines_list[i]);
3706 /* Found an active line! */
3709 /* Move to this location */
3710 tb->cx = (int)(pos - tb->lines_list[i]);
3713 if (bypassed_cy != -1)
3715 /* Mark as some lines are skipped */
3716 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3724 if (bypassed_cy != -1)
3726 /* Move to the remembered line */
3727 tb->cx = bypassed_cx;
3728 tb->cy = bypassed_cy;
3730 /* Mark as this line is inactive */
3731 tb->dirty_flags |= DIRTY_INACTIVE;
3736 /* Mark as NOT FOUND */
3737 tb->dirty_flags |= DIRTY_NOT_FOUND;
3747 * Editor command id's
3750 #define EC_SAVEQUIT 2
3761 #define EC_PGDOWN 13
3763 #define EC_BOTTOM 15
3768 #define EC_KILL_LINE 20
3769 #define EC_DELETE_CHAR 21
3770 #define EC_BACKSPACE 22
3771 #define EC_SEARCH_STR 23
3772 #define EC_SEARCH_FORW 24
3773 #define EC_SEARCH_BACK 25
3774 #define EC_SEARCH_OBJ 26
3775 #define EC_SEARCH_DESTROYED 27
3776 #define EC_INSERT_OBJECT 28
3777 #define EC_INSERT_DESTROYED 29
3778 #define EC_INSERT_BLOCK 30
3779 #define EC_INSERT_MACRO 31
3780 #define EC_INSERT_KEYMAP 32
3781 #define EC_CL_AUTOPICK 33
3782 #define EC_CL_DESTROY 34
3783 #define EC_CL_LEAVE 35
3784 #define EC_CL_QUERY 36
3785 #define EC_CL_NO_DISP 37
3786 #define EC_OK_COLLECTING 38
3787 #define EC_IK_UNAWARE 39
3788 #define EC_IK_UNIDENTIFIED 40
3789 #define EC_IK_IDENTIFIED 41
3790 #define EC_IK_STAR_IDENTIFIED 42
3791 #define EC_OK_BOOSTED 43
3792 #define EC_OK_MORE_DICE 44
3793 #define EC_OK_MORE_BONUS 45
3794 #define EC_OK_WORTHLESS 46
3795 #define EC_OK_ARTIFACT 47
3796 #define EC_OK_EGO 48
3797 #define EC_OK_NAMELESS 49
3798 #define EC_OK_RARE 50
3799 #define EC_OK_COMMON 51
3800 #define EC_OK_WANTED 52
3801 #define EC_OK_UNIQUE 53
3802 #define EC_OK_HUMAN 54
3803 #define EC_OK_UNREADABLE 55
3804 #define EC_OK_REALM1 56
3805 #define EC_OK_REALM2 57
3806 #define EC_OK_FIRST 58
3807 #define EC_OK_SECOND 59
3808 #define EC_OK_THIRD 60
3809 #define EC_OK_FOURTH 61
3810 #define EC_KK_WEAPONS 62
3811 #define EC_KK_FAVORITE_WEAPONS 63
3812 #define EC_KK_ARMORS 64
3813 #define EC_KK_MISSILES 65
3814 #define EC_KK_DEVICES 66
3815 #define EC_KK_LIGHTS 67
3816 #define EC_KK_JUNKS 68
3817 #define EC_KK_CORPSES 69
3818 #define EC_KK_SPELLBOOKS 70
3819 #define EC_KK_SHIELDS 71
3820 #define EC_KK_BOWS 72
3821 #define EC_KK_RINGS 73
3822 #define EC_KK_AMULETS 74
3823 #define EC_KK_SUITS 75
3824 #define EC_KK_CLOAKS 76
3825 #define EC_KK_HELMS 77
3826 #define EC_KK_GLOVES 78
3827 #define EC_KK_BOOTS 79
3833 #define MN_QUIT "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»"
3834 #define MN_SAVEQUIT "¥»¡¼¥Ö¤·¤Æ½ªÎ»"
3835 #define MN_REVERT "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ"
3836 #define MN_HELP "¥Ø¥ë¥×"
3838 #define MN_MOVE "¥«¡¼¥½¥ë°ÜÆ°"
3839 #define MN_LEFT "º¸ (¢«Ìð°õ¥¡¼)"
3840 #define MN_DOWN "²¼ (¢Ìð°õ¥¡¼)"
3841 #define MN_UP "¾å (¢¬Ìð°õ¥¡¼)"
3842 #define MN_RIGHT "±¦ (¢ªÌð°õ¥¡¼)"
3843 #define MN_BOL "¹Ô¤ÎÀèƬ"
3844 #define MN_EOL "¹Ô¤Î½ªÃ¼"
3845 #define MN_PGUP "¾å¤Î¥Ú¡¼¥¸ (PageUp¥¡¼)"
3846 #define MN_PGDOWN "²¼¤Î¥Ú¡¼¥¸ (PageDown¥¡¼)"
3847 #define MN_TOP "1¹ÔÌܤذÜÆ° (Home¥¡¼)"
3848 #define MN_BOTTOM "ºÇ²¼¹Ô¤Ø°ÜÆ°(End¥¡¼)"
3850 #define MN_EDIT "ÊÔ½¸"
3851 #define MN_CUT "¥«¥Ã¥È"
3852 #define MN_COPY "¥³¥Ô¡¼"
3853 #define MN_PASTE "¥Ú¡¼¥¹¥È"
3854 #define MN_BLOCK "ÁªÂòÈϰϤλØÄê"
3855 #define MN_KILL_LINE "¹Ô¤Î»Ä¤ê¤òºï½ü"
3856 #define MN_DELETE_CHAR "1ʸ»úºï½ü"
3857 #define MN_BACKSPACE "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹"
3858 #define MN_RETURN "²þ¹Ô"
3859 #define MN_RETURN "²þ¹Ô"
3861 #define MN_SEARCH "¸¡º÷"
3862 #define MN_SEARCH_STR "ʸ»úÎó¤Ç¸¡º÷"
3863 #define MN_SEARCH_FORW "Á°Êý¤ØºÆ¸¡º÷"
3864 #define MN_SEARCH_BACK "¸åÊý¤ØºÆ¸¡º÷"
3865 #define MN_SEARCH_OBJ "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷"
3866 #define MN_SEARCH_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷"
3868 #define MN_INSERT "¿§¡¹ÁÞÆþ"
3869 #define MN_INSERT_OBJECT "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3870 #define MN_INSERT_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3871 #define MN_INSERT_BLOCK "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ"
3872 #define MN_INSERT_MACRO "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ"
3873 #define MN_INSERT_KEYMAP "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ"
3876 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/\x95\xfaÃÖ¤ÎÁªÂò"
3878 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò"
3880 #define MN_CL_AUTOPICK "¡Ö ¡× (¼«Æ°½¦¤¤)"
3881 #define MN_CL_DESTROY "¡Ö!¡× (¼«Æ°Ç˲õ)"
3883 #define MN_CL_LEAVE "¡Ö~¡× (\x95\xfaÃÖ)"
3885 #define MN_CL_LEAVE "¡Ö~¡× (ÊüÃÖ)"
3887 #define MN_CL_QUERY "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)"
3888 #define MN_CL_NO_DISP "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)"
3890 #define MN_ADJECTIVE_GEN "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò"
3892 #define MN_ADJECTIVE_SPECIAL "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò"
3893 #define MN_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)"
3894 #define MN_MORE_DICE "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)"
3895 #define MN_MORE_BONUS "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)"
3896 #define MN_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)"
3897 #define MN_EGO "¥¨¥´ (ÁõÈ÷)"
3898 #define MN_NAMELESS "̵ÌäΠ(ÁõÈ÷)"
3899 #define MN_RARE "¥ì¥¢¤Ê (ÁõÈ÷)"
3900 #define MN_COMMON "¤¢¤ê¤Õ¤ì¤¿ (ÁõÈ÷)"
3901 #define MN_WANTED "¾Þ¶â¼ó¤Î (»àÂÎ)"
3902 #define MN_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)"
3903 #define MN_HUMAN "¿Í´Ö¤Î (»àÂÎ)"
3904 #define MN_UNREADABLE "Æɤá¤Ê¤¤ (ËâË¡½ñ)"
3905 #define MN_REALM1 "Âè°ìÎΰè¤Î (ËâË¡½ñ)"
3906 #define MN_REALM2 "ÂèÆóÎΰè¤Î (ËâË¡½ñ)"
3907 #define MN_FIRST "1ºýÌܤΠ(ËâË¡½ñ)"
3908 #define MN_SECOND "2ºýÌܤΠ(ËâË¡½ñ)"
3909 #define MN_THIRD "3ºýÌܤΠ(ËâË¡½ñ)"
3910 #define MN_FOURTH "4ºýÌܤΠ(ËâË¡½ñ)"
3912 #define MN_NOUN "̾»ì¤ÎÁªÂò"
3916 #define MN_QUIT "Quit without save"
3917 #define MN_SAVEQUIT "Save & Quit"
3918 #define MN_REVERT "Revert all changes"
3919 #define MN_HELP "Help"
3921 #define MN_MOVE "Move cursor"
3922 #define MN_LEFT "Left (Left Arrow key)"
3923 #define MN_DOWN "Down (Down Arrow key)"
3924 #define MN_UP "Up (Up Arrow key)"
3925 #define MN_RIGHT "Right (Right Arrow key)"
3926 #define MN_BOL "Beggining of line"
3927 #define MN_EOL "End of line"
3928 #define MN_PGUP "Page up (PageUp key)"
3929 #define MN_PGDOWN "Page down(PageDown key)"
3930 #define MN_TOP "Top (Home key)"
3931 #define MN_BOTTOM "Bottom (End key)"
3933 #define MN_EDIT "Edit"
3934 #define MN_CUT "Cut"
3935 #define MN_COPY "Copy"
3936 #define MN_PASTE "Paste"
3937 #define MN_BLOCK "Select block"
3938 #define MN_KILL_LINE "Kill rest of line"
3939 #define MN_DELETE_CHAR "Delete character"
3940 #define MN_BACKSPACE "Backspace"
3941 #define MN_RETURN "Return"
3942 #define MN_RETURN "Return"
3944 #define MN_SEARCH "Search"
3945 #define MN_SEARCH_STR "Search by string"
3946 #define MN_SEARCH_FORW "Search forward"
3947 #define MN_SEARCH_BACK "Search backward"
3948 #define MN_SEARCH_OBJ "Search by inventory object"
3949 #define MN_SEARCH_DESTROYED "Search by destroyed object"
3951 #define MN_INSERT "Insert..."
3952 #define MN_INSERT_OBJECT "Insert name of choosen object"
3953 #define MN_INSERT_DESTROYED "Insert name of destroyed object"
3954 #define MN_INSERT_BLOCK "Insert conditional block"
3955 #define MN_INSERT_MACRO "Insert a macro definition"
3956 #define MN_INSERT_KEYMAP "Insert a keymap definition"
3958 #define MN_COMMAND_LETTER "Command letter"
3959 #define MN_CL_AUTOPICK "' ' (Auto pick)"
3960 #define MN_CL_DESTROY "'!' (Auto destroy)"
3961 #define MN_CL_LEAVE "'~' (Leave it on the floor)"
3962 #define MN_CL_QUERY "';' (Query to pick up)"
3963 #define MN_CL_NO_DISP "'(' (No display on the large map)"
3965 #define MN_ADJECTIVE_GEN "Adjective (general)"
3967 #define MN_ADJECTIVE_SPECIAL "Adjective (special)"
3968 #define MN_BOOSTED "dice boosted (weapons)"
3969 #define MN_MORE_DICE "more than # dice (weapons)"
3970 #define MN_MORE_BONUS "more bonus than # (rings etc.)"
3971 #define MN_ARTIFACT "artifact (equipments)"
3972 #define MN_EGO "ego (equipments)"
3973 #define MN_NAMELESS "nameless (equipments)"
3974 #define MN_RARE "rare (equipments)"
3975 #define MN_COMMON "common (equipments)"
3976 #define MN_WANTED "wanted (corpse)"
3977 #define MN_UNIQUE "unique (corpse)"
3978 #define MN_HUMAN "human (corpse)"
3979 #define MN_UNREADABLE "unreadable (spellbooks)"
3980 #define MN_REALM1 "realm1 (spellbooks)"
3981 #define MN_REALM2 "realm2 (spellbooks)"
3982 #define MN_FIRST "first (spellbooks)"
3983 #define MN_SECOND "second (spellbooks)"
3984 #define MN_THIRD "third (spellbooks)"
3985 #define MN_FOURTH "fourth (spellbooks)"
3987 #define MN_NOUN "Keywords (noun)"
3997 } command_menu_type;
4000 command_menu_type menu_data[] =
4002 {MN_HELP, 0, -1, EC_HELP},
4003 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4004 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4005 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4007 {MN_EDIT, 0, -1, -1},
4008 {MN_CUT, 1, KTRL('x'), EC_CUT},
4009 {MN_COPY, 1, KTRL('c'), EC_COPY},
4010 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4011 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4012 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4013 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4014 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4015 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4016 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4018 {MN_SEARCH, 0, -1, -1},
4019 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4020 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4021 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4022 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4023 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4025 {MN_MOVE, 0, -1, -1},
4026 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4027 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4028 {MN_UP, 1, KTRL('p'), EC_UP},
4029 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4030 {MN_BOL, 1, KTRL('a'), EC_BOL},
4031 {MN_EOL, 1, KTRL('e'), EC_EOL},
4032 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4033 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4034 {MN_TOP, 1, KTRL('t'), EC_TOP},
4035 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4037 {MN_INSERT, 0, -1, -1},
4038 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4039 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4040 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4041 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4042 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4044 {MN_ADJECTIVE_GEN, 0, -1, -1},
4045 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4046 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4047 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4048 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4049 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4050 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4052 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4053 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4054 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4055 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4056 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4057 {MN_EGO, 1, -1, EC_OK_EGO},
4058 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
4059 {MN_RARE, 1, -1, EC_OK_RARE},
4060 {MN_COMMON, 1, -1, EC_OK_COMMON},
4061 {MN_WANTED, 1, -1, EC_OK_WANTED},
4062 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4063 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4064 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4065 {MN_REALM1, 1, -1, EC_OK_REALM1},
4066 {MN_REALM2, 1, -1, EC_OK_REALM2},
4067 {MN_FIRST, 1, -1, EC_OK_FIRST},
4068 {MN_SECOND, 1, -1, EC_OK_SECOND},
4069 {MN_THIRD, 1, -1, EC_OK_THIRD},
4070 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4072 {MN_NOUN, 0, -1, -1},
4073 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4074 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4075 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4076 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4077 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4078 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4079 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4080 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4081 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4082 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4083 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4084 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4085 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4086 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4087 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4088 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4089 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4090 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4092 {MN_COMMAND_LETTER, 0, -1, -1},
4093 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4094 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4095 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4096 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4097 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4099 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4106 * Find a command by 'key'.
4108 static int get_com_id(char key)
4112 for (i = 0; menu_data[i].name; i++)
4114 if (menu_data[i].key == key)
4116 return menu_data[i].com_id;
4125 * Display the menu, and get a command
4127 static int do_command_menu(int level, int start)
4132 int col0 = 5 + level*7;
4133 int row0 = 1 + level*3;
4135 int menu_id_list[26];
4137 char linestr[MAX_LINELEN];
4139 /* Get max length */
4141 for (i = start; menu_data[i].level >= level; i++)
4145 /* Ignore lower level sub menus */
4146 if (menu_data[i].level > level) continue;
4148 len = strlen(menu_data[i].name);
4149 if (len > max_len) max_len = len;
4151 menu_id_list[menu_key] = i;
4155 while (menu_key < 26)
4157 menu_id_list[menu_key] = -1;
4161 /* Extra space for displaying menu key and command key */
4162 max_menu_wid = max_len + 3 + 3;
4164 /* Prepare box line */
4166 strcat(linestr, "+");
4167 for (i = 0; i < max_menu_wid + 2; i++)
4169 strcat(linestr, "-");
4171 strcat(linestr, "+");
4181 int row1 = row0 + 1;
4184 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4186 /* Draw menu items */
4188 for (i = start; menu_data[i].level >= level; i++)
4190 char com_key_str[3];
4193 /* Ignore lower level sub menus */
4194 if (menu_data[i].level > level) continue;
4196 if (menu_data[i].com_id == -1)
4199 strcpy(com_key_str, "¢§");
4201 strcpy(com_key_str, ">");
4204 else if (menu_data[i].key != -1)
4206 com_key_str[0] = '^';
4207 com_key_str[1] = menu_data[i].key + '@';
4208 com_key_str[2] = '\0';
4212 com_key_str[0] = '\0';
4215 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4217 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4222 /* Draw bottom line */
4223 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4225 /* The menu was shown */
4229 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
4231 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
4235 if (key == ESCAPE) return 0;
4237 if ('a' <= key && key <= 'z')
4239 menu_id = menu_id_list[key - 'a'];
4243 com_id = menu_data[menu_id].com_id;
4247 com_id = do_command_menu(level + 1, menu_id + 1);
4249 if (com_id) return com_id;
4261 com_id = get_com_id(key);
4262 if (com_id) return com_id;
4269 static chain_str_type *new_chain_str(cptr str)
4271 chain_str_type *chain;
4273 size_t len = strlen(str);
4275 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4277 strcpy(chain->s, str);
4284 static void kill_yank_chain(text_body_type *tb)
4286 chain_str_type *chain = tb->yank;
4288 tb->yank_eol = TRUE;
4292 chain_str_type *next = chain->next;
4293 size_t len = strlen(chain->s);
4295 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4302 static void add_str_to_yank(text_body_type *tb, cptr str)
4304 chain_str_type *chain;
4306 tb->yank_eol = FALSE;
4308 if (NULL == tb->yank)
4310 tb->yank = new_chain_str(str);
4320 chain->next = new_chain_str(str);
4325 chain = chain->next;
4330 #define DESCRIPT_HGT 3
4335 static void draw_text_editor(text_body_type *tb)
4338 int by1 = 0, by2 = 0;
4341 Term_get_size(&tb->wid, &tb->hgt);
4344 * Top line (-1), description line (-3), separator (-1)
4347 tb->hgt -= 2 + DESCRIPT_HGT;
4350 /* Don't let cursor at second byte of kanji */
4351 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4352 if (iskanji(tb->lines_list[tb->cy][i]))
4363 /* Scroll if necessary */
4364 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4365 tb->upper = tb->cy - (tb->hgt)/2;
4368 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4369 tb->left = tb->cx - (tb->wid)*2/3;
4373 /* Redraw whole window after resize */
4374 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4375 tb->dirty_flags |= DIRTY_SCREEN;
4377 /* Redraw all text after scroll */
4378 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4379 tb->dirty_flags |= DIRTY_ALL;
4382 if (tb->dirty_flags & DIRTY_SCREEN)
4384 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4390 /* Redraw mode line */
4391 if (tb->dirty_flags & DIRTY_MODE)
4393 char buf[MAX_LINELEN];
4395 int sepa_length = tb->wid;
4398 for (i = 0; i < sepa_length; i++)
4402 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4405 if (tb->dirty_flags & DIRTY_EXPRESSION)
4410 for (y = 0; tb->lines_list[y]; y++)
4414 cptr s = tb->lines_list[y];
4416 /* Update this line's state */
4417 tb->states[y] = state;
4419 if (*s++ != '?') continue;
4420 if (*s++ != ':') continue;
4422 /* Lines below this line are auto-registered */
4423 if (streq(s, "$AUTOREGISTER"))
4424 state |= LSTAT_AUTOREGISTER;
4426 /* Parse the expr */
4427 v = process_pref_file_expr(&s, &f);
4430 if (streq(v, "0")) state |= LSTAT_BYPASS;
4431 else state &= ~LSTAT_BYPASS;
4433 /* Re-update this line's state */
4434 tb->states[y] = state | LSTAT_EXPRESSION;
4437 tb->dirty_flags |= DIRTY_ALL;
4442 int tmp_cx = tb->cx;
4443 int len = strlen(tb->lines_list[tb->cy]);
4445 /* Correct cursor location */
4446 if (tb->cx > len) tmp_cx = len;
4448 tb->dirty_flags |= DIRTY_ALL;
4450 by1 = MIN(tb->my, tb->cy);
4451 by2 = MAX(tb->my, tb->cy);
4454 /* Dump up to tb->hgt lines of messages */
4455 for (i = 0; i < tb->hgt; i++)
4461 int y = tb->upper+i;
4463 /* clean or dirty? */
4464 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4467 msg = tb->lines_list[y];
4470 /* Apply horizontal scroll */
4471 for (j = 0; *msg; msg++, j++)
4473 if (j == tb->left) break;
4489 Term_erase(0, i + 1, tb->wid);
4491 if (tb->states[y] & LSTAT_AUTOREGISTER)
4493 /* Warning color -- These lines will be deleted later */
4498 /* Bypassed line will be displayed by darker color */
4499 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4500 else color = TERM_WHITE;
4503 /* No mark or Out of mark */
4504 if (!tb->mark || (y < by1 || by2 < y))
4506 /* Dump the messages, bottom to top */
4507 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4510 /* Multiple lines selected */
4511 else if (by1 != by2)
4513 /* Dump the messages, bottom to top */
4514 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4517 /* Single line selected */
4520 int x0 = leftcol + tb->left;
4521 int len = strlen(tb->lines_list[tb->cy]);
4522 int bx1 = MIN(tb->mx, tb->cx);
4523 int bx2 = MAX(tb->mx, tb->cx);
4525 /* Correct cursor location */
4526 if (bx2 > len) bx2 = len;
4528 Term_gotoxy(leftcol, i + 1);
4529 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4530 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4531 Term_addstr(-1, color, msg + (bx2 - x0));
4535 for (; i < tb->hgt; i++)
4538 Term_erase(0, i + 1, tb->wid);
4541 /* Display information when updated */
4542 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4544 autopick_type an_entry, *entry = &an_entry;
4545 cptr str1 = NULL, str2 = NULL;
4548 /* Clear information line */
4549 for (i = 0; i < DESCRIPT_HGT; i++)
4552 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4555 /* Display information */
4556 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4559 str1 = format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str);
4561 str1 = format("Pattern not found: %s", tb->search_str);
4564 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4567 str1 = format("̵¸ú¾õÂ֤ιԤò¥¹¥¥Ã¥×¤·¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4569 str1 = format("Some inactive lines are skipped. (Searching %s)", tb->search_str);
4572 else if (tb->dirty_flags & DIRTY_INACTIVE)
4575 str1 = format("̵¸ú¾õÂ֤ιԤÀ¤±¤¬¸«ÉÕ¤«¤ê¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4577 str1 = format("Found only an inactive line. (Searching %s)", tb->search_str);
4580 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4583 str1 = "¸¡º÷¤¹¤ë¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó(^S ¤Ç¸¡º÷)¡£";
4585 str1 = "No pattern to search. (Press ^S to search.)";
4588 else if (tb->lines_list[tb->cy][0] == '#')
4591 str1 = "¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£";
4593 str1 = "This line is a comment.";
4596 else if (tb->lines_list[tb->cy][1] == ':')
4598 switch(tb->lines_list[tb->cy][0])
4602 str1 = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4604 str1 = "This line is a Conditional Expression.";
4610 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4612 str1 = "This line defines a Macro action.";
4617 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4619 str1 = "This line defines a Macro trigger key.";
4624 str1 = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4626 str1 = "This line defines a Keymap.";
4631 switch(tb->lines_list[tb->cy][0])
4634 if (tb->states[tb->cy] & LSTAT_BYPASS)
4637 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4639 str2 = "The expression is 'False'(=0) currently.";
4645 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4647 str2 = "The expression is 'True'(=1) currently.";
4653 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4656 str2 = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4658 str2 = "This line will be delete later.";
4662 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4665 str2 = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4667 str2 = "This line is bypassed currently.";
4674 /* Get description of an autopicker preference line */
4675 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4677 char buf[MAX_LINELEN];
4678 char temp[MAX_LINELEN];
4681 describe_autopick(buf, entry);
4683 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4686 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4688 strcat(buf, " This line will be delete later.");
4692 if (tb->states[tb->cy] & LSTAT_BYPASS)
4695 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4697 strcat(buf, " This line is bypassed currently.");
4701 roff_to_buf(buf, 81, temp, sizeof(temp));
4703 for (i = 0; i < 3; i++)
4709 prt(t, tb->hgt +1 + 1 + i, 0);
4713 autopick_free_entry(entry);
4716 /* Draw the first line */
4717 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4719 /* Draw the second line */
4720 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4726 * Kill segment of a line
4728 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4730 char buf[MAX_LINELEN];
4731 cptr s = tb->lines_list[y];
4735 /* Kill whole line? */
4736 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4740 string_free(tb->lines_list[y]);
4742 /* Shift lines up */
4743 for (i = y; tb->lines_list[i+1]; i++)
4744 tb->lines_list[i] = tb->lines_list[i+1];
4745 tb->lines_list[i] = NULL;
4747 /* Expressions need re-evaluation */
4748 tb->dirty_flags |= DIRTY_EXPRESSION;
4754 if (x0 == x1) return;
4756 /* Before the segment */
4757 for (x = 0; x < x0; x++)
4760 /* After the segment */
4761 for (x = x1; s[x]; x++)
4767 string_free(tb->lines_list[y]);
4768 tb->lines_list[y] = string_make(buf);
4770 /* Expressions may need re-evaluation */
4771 check_expression_line(tb, y);
4773 /* Text is changed */
4779 * Get a trigger key and insert ASCII string for the trigger
4781 static bool insert_macro_line(text_body_type *tb)
4790 /* Do not process macros */
4796 /* Read the pattern */
4802 /* Do not process macros */
4805 /* Do not wait for keys */
4808 /* Attempt to read a key */
4818 /* Convert the trigger */
4819 ascii_to_text(tmp, buf);
4822 if(!tmp[0]) return FALSE;
4826 /* Insert preference string */
4827 insert_return_code(tb);
4828 string_free(tb->lines_list[tb->cy]);
4829 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4831 /* Acquire action */
4832 i = macro_find_exact(buf);
4836 /* Nothing defined */
4841 /* Analyze the current action */
4842 ascii_to_text(tmp, macro__act[i]);
4845 /* Insert blank action preference line */
4846 insert_return_code(tb);
4847 string_free(tb->lines_list[tb->cy]);
4848 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4855 * Get a command key and insert ASCII string for the key
4857 static bool insert_keymap_line(text_body_type *tb)
4865 if (rogue_like_commands)
4867 mode = KEYMAP_MODE_ROGUE;
4873 mode = KEYMAP_MODE_ORIG;
4886 /* Convert the trigger */
4887 ascii_to_text(tmp, buf);
4890 if(!tmp[0]) return FALSE;
4894 /* Insert preference string */
4895 insert_return_code(tb);
4896 string_free(tb->lines_list[tb->cy]);
4897 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4899 /* Look up the keymap */
4900 act = keymap_act[mode][(byte)(buf[0])];
4902 /* Insert blank action preference line */
4903 insert_return_code(tb);
4904 string_free(tb->lines_list[tb->cy]);
4905 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4912 * Execute a single editor command
4914 static bool do_editor_command(text_body_type *tb, int com_id)
4922 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4924 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
4927 return QUIT_WITHOUT_SAVE;
4930 return QUIT_AND_SAVE;
4933 /* Revert to original */
4935 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4937 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
4940 free_text_lines(tb->lines_list);
4941 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4942 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4943 tb->cx = tb->cy = 0;
4946 /* Text is not changed */
4947 tb->changed = FALSE;
4951 /* Peruse the main help file */
4953 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
4955 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
4958 tb->dirty_flags |= DIRTY_SCREEN;
4963 /* Split a line or insert end of line */
4965 /* Ignore selection */
4971 tb->dirty_flags |= DIRTY_ALL;
4974 insert_return_code(tb);
4979 tb->dirty_flags |= DIRTY_ALL;
4989 len = strlen(tb->lines_list[tb->cy]);
4990 if (len < tb->cx) tb->cx = len;
4992 else if (tb->cy > 0)
4995 tb->cx = strlen(tb->lines_list[tb->cy]);
5001 if (tb->lines_list[tb->cy + 1]) tb->cy++;
5006 if (tb->cy > 0) tb->cy--;
5015 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5018 len = strlen(tb->lines_list[tb->cy]);
5021 if (tb->lines_list[tb->cy + 1])
5033 /* Beginning of line */
5039 tb->cx = strlen(tb->lines_list[tb->cy]);
5043 while (0 < tb->cy && tb->upper <= tb->cy)
5045 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5051 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
5061 while (tb->lines_list[tb->cy + 1])
5067 /* Copy the text first */
5068 do_editor_command(tb, EC_COPY);
5070 /* Single line case */
5071 if (tb->my == tb->cy)
5073 int bx1 = MIN(tb->mx, tb->cx);
5074 int bx2 = MAX(tb->mx, tb->cx);
5075 int len = strlen(tb->lines_list[tb->cy]);
5077 /* Correct fake cursor position */
5078 if (bx2 > len) bx2 = len;
5080 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5082 /* New cursor position */
5086 /* Multiple lines case */
5087 else /* if (tb->my != tb->cy) */
5091 int by1 = MIN(tb->my, tb->cy);
5092 int by2 = MAX(tb->my, tb->cy);
5094 /* Kill lines in reverse order */
5095 for (y = by2; y >= by1; y--)
5097 int len = strlen(tb->lines_list[y]);
5099 kill_line_segment(tb, y, 0, len, TRUE);
5102 /* New cursor position */
5108 /* Disable selection */
5112 tb->dirty_flags |= DIRTY_ALL;
5119 int len = strlen(tb->lines_list[tb->cy]);
5121 /* Correct cursor location */
5122 if (tb->cx > len) tb->cx = len;
5124 /* Use single line? */
5127 /* Select a single line */
5133 /* Kill old yank buffer */
5134 kill_yank_chain(tb);
5137 /* Single line case */
5138 if (tb->my == tb->cy)
5141 char buf[MAX_LINELEN];
5142 int bx1 = MIN(tb->mx, tb->cx);
5143 int bx2 = MAX(tb->mx, tb->cx);
5145 /* Correct fake cursor position */
5146 if (bx2 > len) bx2 = len;
5148 /* Whole part of this line is selected */
5149 if (bx1 == 0 && bx2 == len)
5151 /* Copy this line */
5152 add_str_to_yank(tb, tb->lines_list[tb->cy]);
5154 /* Add end of line to the buffer */
5155 add_str_to_yank(tb, "");
5158 /* Segment of this line is selected */
5161 for (i = 0; i < bx2 - bx1; i++)
5163 buf[i] = tb->lines_list[tb->cy][bx1 + i];
5167 /* Copy this segment of line */
5168 add_str_to_yank(tb, buf);
5172 /* Multiple lines case */
5173 else /* if (tb->my != tb->cy) */
5177 int by1 = MIN(tb->my, tb->cy);
5178 int by2 = MAX(tb->my, tb->cy);
5181 for (y = by1; y <= by2; y++)
5183 /* Copy this line */
5184 add_str_to_yank(tb, tb->lines_list[y]);
5187 /* Add final end of line to the buffer */
5188 add_str_to_yank(tb, "");
5191 /* Disable selection */
5195 tb->dirty_flags |= DIRTY_ALL;
5201 /* Paste killed text */
5203 chain_str_type *chain = tb->yank;
5204 int len = strlen(tb->lines_list[tb->cy]);
5206 /* Nothing to do? */
5209 /* Correct cursor location */
5210 if (tb->cx > len) tb->cx = len;
5212 /* Ignore selection */
5218 tb->dirty_flags |= DIRTY_ALL;
5224 cptr yank_str = chain->s;
5226 char buf[MAX_LINELEN];
5228 char rest[MAX_LINELEN], *rest_ptr = rest;
5230 /* Save preceding string */
5231 for(i = 0; i < tb->cx; i++)
5232 buf[i] = tb->lines_list[tb->cy][i];
5234 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5236 /* Paste yank buffer */
5237 while (*yank_str && i < MAX_LINELEN-1)
5239 buf[i++] = *yank_str++;
5245 chain = chain->next;
5247 if (chain || tb->yank_eol)
5249 /* There is an end of line between chain nodes */
5251 insert_return_code(tb);
5253 /* Replace this line with new one */
5254 string_free(tb->lines_list[tb->cy]);
5255 tb->lines_list[tb->cy] = string_make(buf);
5257 /* Move to next line */
5264 /* Final line doesn't have end of line */
5266 tb->cx = strlen(buf);
5268 /* Rest of original line */
5269 while (*rest_ptr && i < MAX_LINELEN-1)
5271 buf[i++] = *rest_ptr++;
5277 /* Replace this line with new one */
5278 string_free(tb->lines_list[tb->cy]);
5279 tb->lines_list[tb->cy] = string_make(buf);
5286 tb->dirty_flags |= DIRTY_ALL;
5288 /* Expressions need re-evaluation */
5289 tb->dirty_flags |= DIRTY_EXPRESSION;
5291 /* Text is changed */
5300 /* Disable the selection */
5304 tb->dirty_flags |= DIRTY_ALL;
5308 tb->mark = MARK_MARK;
5310 /* Repeating this command swaps cursor position */
5311 if (com_id == tb->old_com_id)
5323 tb->dirty_flags |= DIRTY_ALL;
5327 int len = strlen(tb->lines_list[tb->cy]);
5329 /* Mark the point 1 */
5333 /* Correct cursor location */
5334 if (tb->cx > len) tb->mx = len;
5341 /* Kill rest of line */
5343 int len = strlen(tb->lines_list[tb->cy]);
5345 /* Correct cursor location */
5346 if (tb->cx > len) tb->cx = len;
5348 /* Ignore selection */
5354 tb->dirty_flags |= DIRTY_ALL;
5357 /* Append only if this command is repeated. */
5358 if (tb->old_com_id != com_id)
5360 kill_yank_chain(tb);
5364 /* Really deleted some text */
5367 /* Add deleted string to yank buffer */
5368 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5370 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5373 tb->dirty_line = tb->cy;
5375 /* Leave end of line character */
5379 /* Cut the end of line character only */
5380 if (tb->yank_eol) add_str_to_yank(tb, "");
5382 /* Cut end of line */
5383 tb->yank_eol = TRUE;
5385 do_editor_command(tb, EC_DELETE_CHAR);
5389 case EC_DELETE_CHAR:
5390 /* DELETE == go forward + BACK SPACE */
5392 /* Ignore selection */
5398 tb->dirty_flags |= DIRTY_ALL;
5402 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5406 do_editor_command(tb, EC_BACKSPACE);
5414 char buf[MAX_LINELEN];
5416 /* Ignore selection */
5422 tb->dirty_flags |= DIRTY_ALL;
5425 len = strlen(tb->lines_list[tb->cy]);
5428 if (tb->lines_list[tb->cy + 1])
5442 /* delete a return code and union two lines */
5443 if (tb->cy == 0) break;
5444 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5445 strcpy(buf, tb->lines_list[tb->cy-1]);
5446 strcat(buf, tb->lines_list[tb->cy]);
5447 string_free(tb->lines_list[tb->cy-1]);
5448 string_free(tb->lines_list[tb->cy]);
5449 tb->lines_list[tb->cy-1] = string_make(buf);
5451 for (i = tb->cy; tb->lines_list[i+1]; i++)
5452 tb->lines_list[i] = tb->lines_list[i+1];
5454 tb->lines_list[i] = NULL;
5458 tb->dirty_flags |= DIRTY_ALL;
5460 /* Expressions need re-evaluation */
5461 tb->dirty_flags |= DIRTY_EXPRESSION;
5463 /* Text is changed */
5469 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5473 if (iskanji(tb->lines_list[tb->cy][i]))
5474 buf[j++] = tb->lines_list[tb->cy][i++];
5476 buf[j++] = tb->lines_list[tb->cy][i];
5483 for (; tb->lines_list[tb->cy][i]; i++)
5484 buf[j++] = tb->lines_list[tb->cy][i];
5486 string_free(tb->lines_list[tb->cy]);
5487 tb->lines_list[tb->cy] = string_make(buf);
5490 tb->dirty_line = tb->cy;
5492 /* Expressions may need re-evaluation */
5493 check_expression_line(tb, tb->cy);
5495 /* Text is changed */
5505 /* Become dirty because of item/equip menu */
5506 tb->dirty_flags |= DIRTY_SCREEN;
5508 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5510 if (!search_dir) break;
5512 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5513 else do_editor_command(tb, EC_SEARCH_BACK);
5517 case EC_SEARCH_FORW:
5518 if (tb->search_o_ptr)
5520 search_for_object(tb, tb->search_o_ptr, TRUE);
5522 else if (tb->search_str && tb->search_str[0])
5524 search_for_string(tb, tb->search_str, TRUE);
5528 tb->dirty_flags |= DIRTY_NO_SEARCH;
5532 case EC_SEARCH_BACK:
5533 if (tb->search_o_ptr)
5535 search_for_object(tb, tb->search_o_ptr, FALSE);
5537 else if (tb->search_str && tb->search_str[0])
5539 search_for_string(tb, tb->search_str, FALSE);
5543 tb->dirty_flags |= DIRTY_NO_SEARCH;
5548 /* Become dirty because of item/equip menu */
5549 tb->dirty_flags |= DIRTY_SCREEN;
5551 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5553 do_editor_command(tb, EC_SEARCH_FORW);
5556 case EC_SEARCH_DESTROYED:
5557 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5559 /* There is no object to search */
5560 tb->dirty_flags |= DIRTY_NO_SEARCH;
5565 do_editor_command(tb, EC_SEARCH_FORW);
5568 case EC_INSERT_OBJECT:
5570 /* Insert choosen item name */
5572 autopick_type an_entry, *entry = &an_entry;
5574 if (!entry_from_choosed_object(entry))
5576 /* Now dirty because of item/equip menu */
5577 tb->dirty_flags |= DIRTY_SCREEN;
5582 insert_return_code(tb);
5583 string_free(tb->lines_list[tb->cy]);
5584 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5586 /* Now dirty because of item/equip menu */
5587 tb->dirty_flags |= DIRTY_SCREEN;
5592 case EC_INSERT_DESTROYED:
5593 /* Insert a name of last destroyed item */
5594 if (tb->last_destroyed)
5597 insert_return_code(tb);
5598 string_free(tb->lines_list[tb->cy]);
5599 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5602 tb->dirty_flags |= DIRTY_ALL;
5604 /* Text is changed */
5609 case EC_INSERT_BLOCK:
5611 /* Insert a conditinal expression line */
5612 char expression[80];
5614 /* Conditional Expression for Class and Race */
5615 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5617 rp_ptr->E_title, cp_ptr->E_title,
5619 rp_ptr->title, cp_ptr->title,
5625 insert_return_code(tb);
5626 string_free(tb->lines_list[tb->cy]);
5627 tb->lines_list[tb->cy] = string_make(expression);
5629 insert_return_code(tb);
5630 string_free(tb->lines_list[tb->cy]);
5631 tb->lines_list[tb->cy] = string_make("?:1");
5634 tb->dirty_flags |= DIRTY_ALL;
5636 /* Text is changed */
5642 case EC_INSERT_MACRO:
5643 /* Draw_everythig (delete menu) */
5644 draw_text_editor(tb);
5647 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5651 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5653 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5655 if (insert_macro_line(tb))
5657 /* Prepare to input action */
5661 tb->dirty_flags |= DIRTY_ALL;
5663 /* Text is changed */
5669 case EC_INSERT_KEYMAP:
5670 /* Draw_everythig (delete menu) */
5671 draw_text_editor(tb);
5674 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5678 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)));
5680 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)));
5683 if (insert_keymap_line(tb))
5685 /* Prepare to input action */
5689 tb->dirty_flags |= DIRTY_ALL;
5691 /* Text is changed */
5696 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5697 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5698 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5699 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5700 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5702 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5703 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5704 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5705 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5706 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5707 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5708 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5709 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5710 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5711 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5712 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5713 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5714 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5715 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5716 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5717 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5718 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5719 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5720 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5721 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5722 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5723 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5724 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5725 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5726 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5727 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5728 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5729 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5730 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5731 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5732 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5733 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5734 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5735 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5736 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5737 case EC_OK_UNREADABLE:
5738 toggle_keyword(tb, FLG_UNREADABLE);
5739 add_keyword(tb, FLG_SPELLBOOKS);
5742 toggle_keyword(tb, FLG_REALM1);
5743 add_keyword(tb, FLG_SPELLBOOKS);
5746 toggle_keyword(tb, FLG_REALM2);
5747 add_keyword(tb, FLG_SPELLBOOKS);
5750 toggle_keyword(tb, FLG_FIRST);
5751 add_keyword(tb, FLG_SPELLBOOKS);
5754 toggle_keyword(tb, FLG_SECOND);
5755 add_keyword(tb, FLG_SPELLBOOKS);
5758 toggle_keyword(tb, FLG_THIRD);
5759 add_keyword(tb, FLG_SPELLBOOKS);
5762 toggle_keyword(tb, FLG_FOURTH);
5763 add_keyword(tb, FLG_SPELLBOOKS);
5767 /* Save old command */
5768 tb->old_com_id = com_id;
5775 * Insert single letter at cursor position.
5777 static void insert_single_letter(text_body_type *tb, int key)
5780 char buf[MAX_LINELEN];
5782 /* Save preceding string */
5783 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5784 buf[j++] = tb->lines_list[tb->cy][i];
5786 /* Add a character */
5794 if (j+2 < MAX_LINELEN)
5806 if (j+1 < MAX_LINELEN)
5812 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5813 buf[j++] = tb->lines_list[tb->cy][i];
5816 /* Replace current line with new line */
5817 string_free(tb->lines_list[tb->cy]);
5818 tb->lines_list[tb->cy] = string_make(buf);
5820 /* Move to correct collumn */
5821 len = strlen(tb->lines_list[tb->cy]);
5822 if (len < tb->cx) tb->cx = len;
5825 tb->dirty_line = tb->cy;
5827 /* Expressions may need re-evaluation */
5828 check_expression_line(tb, tb->cy);
5830 /* Text is changed */
5836 * Check special key code and get a movement command id
5838 static int analyze_move_key(text_body_type *tb, int skey)
5842 /* Not a special key */
5843 if (!(skey & SKEY_MASK)) return 0;
5845 /* Convert from a special key code to an editor command */
5846 switch(skey & ~SKEY_MOD_MASK)
5848 case SKEY_DOWN: com_id = EC_DOWN; break;
5849 case SKEY_LEFT: com_id = EC_LEFT; break;
5850 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5851 case SKEY_UP: com_id = EC_UP; break;
5852 case SKEY_PGUP: com_id = EC_PGUP; break;
5853 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5854 case SKEY_TOP: com_id = EC_TOP; break;
5855 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5858 /* Not a special movement key */
5862 /* Without shift modifier */
5863 if (!(skey & SKEY_MOD_SHIFT))
5866 * Un-shifted cursor keys cancells
5867 * selection created by shift+cursor.
5869 if (tb->mark & MARK_BY_SHIFT)
5874 tb->dirty_flags |= DIRTY_ALL;
5878 /* With shift modifier */
5881 /* Start selection by shift + cursor keys */
5884 int len = strlen(tb->lines_list[tb->cy]);
5886 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5890 /* Correct cursor location */
5891 if (tb->cx > len) tb->mx = len;
5893 /* Need to redraw text */
5894 if (com_id == EC_UP || com_id == EC_DOWN)
5896 /* Redraw all text */
5897 tb->dirty_flags |= DIRTY_ALL;
5901 tb->dirty_line = tb->cy;
5910 * In-game editor of Object Auto-picker/Destoryer
5912 void do_cmd_edit_autopick(void)
5914 static int cx_save = 0;
5915 static int cy_save = 0;
5917 text_body_type text_body, *tb = &text_body;
5919 autopick_type an_entry, *entry = &an_entry;
5920 char buf[MAX_LINELEN];
5925 static s32b old_autosave_turn = 0L;
5928 tb->changed = FALSE;
5931 tb->upper = tb->left = 0;
5933 tb->mx = tb->my = 0;
5934 tb->old_cy = tb->old_upper = tb->old_left = -1;
5935 tb->old_wid = tb->old_hgt = -1;
5939 tb->search_o_ptr = NULL;
5940 tb->search_str = NULL;
5941 tb->last_destroyed = NULL;
5942 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5943 tb->dirty_line = -1;
5944 tb->filename_mode = PT_DEFAULT;
5947 if (turn > old_autosave_turn + 100L)
5949 do_cmd_save_game(TRUE);
5950 old_autosave_turn = turn;
5953 /* HACK -- Reset start_time to stop counting playtime while edit */
5956 /* Free old entries */
5959 /* Command Description of the 'Last Destroyed Item' */
5960 if (autopick_last_destroyed_object.k_idx)
5962 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
5963 tb->last_destroyed = autopick_line_from_entry_kill(entry);
5966 /* Read or initialize whole text */
5967 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5969 /* Reset cursor position if needed */
5970 for (i = 0; i < tb->cy; i++)
5972 if (!tb->lines_list[i])
5974 tb->cy = tb->cx = 0;
5979 /* Save the screen */
5982 /* Process requests until done */
5987 /* Draw_everythig */
5988 draw_text_editor(tb);
5990 /* Display header line */
5992 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
5994 prt("(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)", 0, 0);
5998 /* Display current position */
5999 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6003 /* Display current position and mark position */
6004 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6008 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6011 tb->dirty_flags = 0;
6012 tb->dirty_line = -1;
6014 /* Save old key and location */
6015 tb->old_cy = tb->cy;
6016 tb->old_upper = tb->upper;
6017 tb->old_left = tb->left;
6018 tb->old_wid = tb->wid;
6019 tb->old_hgt = tb->hgt;
6022 key = inkey_special();
6025 if (key & SKEY_MASK)
6027 /* Get a movement command */
6028 com_id = analyze_move_key(tb, key);
6032 else if (key == ESCAPE)
6034 com_id = do_command_menu(0, 0);
6036 /* Redraw all text later */
6037 tb->dirty_flags |= DIRTY_SCREEN;
6040 /* Insert a character */
6041 else if (!iscntrl((unsigned char)key))
6043 /* Ignore selection */
6049 tb->dirty_flags |= DIRTY_ALL;
6052 insert_single_letter(tb, key);
6058 /* Other commands */
6061 com_id = get_com_id(key);
6064 if (com_id) quit = do_editor_command(tb, com_id);
6065 } /* while (TRUE) */
6067 /* Restore the screen */
6070 /* Get the filename of preference */
6071 strcpy(buf, pickpref_filename(tb->filename_mode));
6073 if (quit == QUIT_AND_SAVE)
6074 write_text_lines(buf, tb->lines_list);
6076 free_text_lines(tb->lines_list);
6078 string_free(tb->last_destroyed);
6080 /* Destroy string chain */
6081 kill_yank_chain(tb);
6083 /* Reload autopick pref */
6084 process_pickpref_file(buf);
6086 /* HACK -- reset start_time so that playtime is not increase while edit */
6087 start_time = time(NULL);
6089 /* Save cursor location */