3 /* Purpose: Object Auto-picker/Destroyer */
6 * Copyright (c) 2002 Mogami
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
16 #define MAX_LINELEN 1024
23 #define FLG_UNIDENTIFIED 2
24 #define FLG_IDENTIFIED 3
25 #define FLG_STAR_IDENTIFIED 4
26 #define FLG_COLLECTING 5
27 #define FLG_ARTIFACT 6
30 #define FLG_NAMELESS 11
31 #define FLG_AVERAGE 12
32 #define FLG_WORTHLESS 13
35 #define FLG_BOOSTED 16
36 #define FLG_MORE_DICE 17
37 #define FLG_MORE_BONUS 18
41 #define FLG_UNREADABLE 22
50 #define FLG_WEAPONS 31
51 #define FLG_FAVORITE_WEAPONS 32
53 #define FLG_MISSILES 34
54 #define FLG_DEVICES 35
57 #define FLG_CORPSES 38
58 #define FLG_SPELLBOOKS 39
60 #define FLG_SHIELDS 41
63 #define FLG_AMULETS 44
70 #define FLG_NOUN_BEGIN FLG_ITEMS
71 #define FLG_NOUN_END FLG_BOOTS
75 static char KEY_ALL[] = "¤¹¤Ù¤Æ¤Î";
76 static char KEY_UNAWARE[] = "̤ȽÌÀ¤Î";
77 static char KEY_UNIDENTIFIED[] = "̤´ÕÄê¤Î";
78 static char KEY_IDENTIFIED[] = "´ÕÄêºÑ¤ß¤Î";
79 static char KEY_STAR_IDENTIFIED[] = "*´ÕÄê*ºÑ¤ß¤Î";
80 static char KEY_COLLECTING[] = "¼ý½¸Ãæ¤Î";
81 static char KEY_ARTIFACT[] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È";
82 static char KEY_EGO[] = "¥¨¥´";
83 static char KEY_GOOD[] = "¾å¼Á¤Î";
84 static char KEY_NAMELESS[] = "̵ÌäÎ";
85 static char KEY_AVERAGE[] = "ʤÎ";
86 static char KEY_WORTHLESS[] = "̵²ÁÃͤÎ";
87 static char KEY_RARE[] = "¥ì¥¢¤Ê";
88 static char KEY_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿";
89 static char KEY_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦";
90 static char KEY_MORE_THAN[] = "¥À¥¤¥¹ÌÜ";
91 static char KEY_DICE[] = "°Ê¾å¤Î";
92 static char KEY_MORE_BONUS[] = "½¤ÀµÃÍ";
93 static char KEY_MORE_BONUS2[] = "°Ê¾å¤Î";
94 static char KEY_WANTED[] = "¾Þ¶â¼ó¤Î";
95 static char KEY_UNIQUE[] = "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î";
96 static char KEY_HUMAN[] = "¿Í´Ö¤Î";
97 static char KEY_UNREADABLE[] = "Æɤá¤Ê¤¤";
98 static char KEY_REALM1[] = "Âè°ìÎΰè¤Î";
99 static char KEY_REALM2[] = "ÂèÆóÎΰè¤Î";
100 static char KEY_FIRST[] = "1ºýÌܤÎ";
101 static char KEY_SECOND[] = "2ºýÌܤÎ";
102 static char KEY_THIRD[] = "3ºýÌܤÎ";
103 static char KEY_FOURTH[] = "4ºýÌܤÎ";
104 static char KEY_ITEMS[] = "¥¢¥¤¥Æ¥à";
105 static char KEY_WEAPONS[] = "Éð´ï";
106 static char KEY_FAVORITE_WEAPONS[] = "ÆÀ°ÕÉð´ï";
107 static char KEY_ARMORS[] = "Ëɶñ";
108 static char KEY_MISSILES[] = "Ìð";
109 static char KEY_DEVICES[] = "ËâË¡¥¢¥¤¥Æ¥à";
110 static char KEY_LIGHTS[] = "¸÷¸»";
111 static char KEY_JUNKS[] = "¤¬¤é¤¯¤¿";
112 static char KEY_CORPSES[] = "»àÂΤä¹ü";
113 static char KEY_SPELLBOOKS[] = "ËâË¡½ñ";
114 static char KEY_HAFTED[] = "Æß´ï";
115 static char KEY_SHIELDS[] = "½â";
116 static char KEY_BOWS[] = "µÝ";
117 static char KEY_RINGS[] = "»ØÎØ";
118 static char KEY_AMULETS[] = "¥¢¥ß¥å¥ì¥Ã¥È";
119 static char KEY_SUITS[] = "³»";
120 static char KEY_CLOAKS[] = "¥¯¥í¡¼¥¯";
121 static char KEY_HELMS[] = "³õ";
122 static char KEY_GLOVES[] = "äƼê";
123 static char KEY_BOOTS[] = "·¤";
127 static char KEY_ALL[] = "all";
128 static char KEY_UNAWARE[] = "unaware";
129 static char KEY_UNIDENTIFIED[] = "unidentified";
130 static char KEY_IDENTIFIED[] = "identified";
131 static char KEY_STAR_IDENTIFIED[] = "*identified*";
132 static char KEY_COLLECTING[] = "collecting";
133 static char KEY_ARTIFACT[] = "artifact";
134 static char KEY_EGO[] = "ego";
135 static char KEY_GOOD[] = "good";
136 static char KEY_NAMELESS[] = "nameless";
137 static char KEY_AVERAGE[] = "average";
138 static char KEY_WORTHLESS[] = "worthless";
139 static char KEY_RARE[] = "rare";
140 static char KEY_COMMON[] = "common";
141 static char KEY_BOOSTED[] = "dice boosted";
142 static char KEY_MORE_THAN[] = "more than";
143 static char KEY_DICE[] = " dice";
144 static char KEY_MORE_BONUS[] = "more bonus than";
145 static char KEY_MORE_BONUS2[] = "";
146 static char KEY_WANTED[] = "wanted";
147 static char KEY_UNIQUE[] = "unique monster's";
148 static char KEY_HUMAN[] = "human";
149 static char KEY_UNREADABLE[] = "unreadable";
150 static char KEY_REALM1[] = "first realm's";
151 static char KEY_REALM2[] = "second realm's";
152 static char KEY_FIRST[] = "first";
153 static char KEY_SECOND[] = "second";
154 static char KEY_THIRD[] = "third";
155 static char KEY_FOURTH[] = "fourth";
156 static char KEY_ITEMS[] = "items";
157 static char KEY_WEAPONS[] = "weapons";
158 static char KEY_FAVORITE_WEAPONS[] = "favorite weapons";
159 static char KEY_ARMORS[] = "armors";
160 static char KEY_MISSILES[] = "missiles";
161 static char KEY_DEVICES[] = "magical devices";
162 static char KEY_LIGHTS[] = "lights";
163 static char KEY_JUNKS[] = "junks";
164 static char KEY_CORPSES[] = "corpses or skeletons";
165 static char KEY_SPELLBOOKS[] = "spellbooks";
166 static char KEY_HAFTED[] = "hafted weapons";
167 static char KEY_SHIELDS[] = "shields";
168 static char KEY_BOWS[] = "bows";
169 static char KEY_RINGS[] = "rings";
170 static char KEY_AMULETS[] = "amulets";
171 static char KEY_SUITS[] = "suits";
172 static char KEY_CLOAKS[] = "cloaks";
173 static char KEY_HELMS[] = "helms";
174 static char KEY_GLOVES[] = "gloves";
175 static char KEY_BOOTS[] = "boots";
179 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
180 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
181 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
182 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
185 #define ADD_KEY(KEY) strcat(ptr, KEY)
187 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
189 #define ADD_KEY2(KEY) strcat(ptr, KEY)
191 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
192 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
193 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
194 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
197 static char kanji_colon[] = "¡§";
202 * A function to create new entry
204 static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_default)
209 char buf[MAX_LINELEN];
210 cptr prev_ptr, ptr, old_ptr;
213 if (str[0] && str[1] == ':') switch (str[0])
216 case 'A': case 'P': case 'C':
220 entry->flag[0] = entry->flag[1] = 0L;
224 act = DO_AUTOPICK | DO_DISPLAY;
227 if ((act & DO_AUTOPICK) && *str == '!')
230 act |= DO_AUTODESTROY;
233 else if ((act & DO_AUTOPICK) && *str == '~')
236 act |= DONT_AUTOPICK;
239 else if ((act & DO_AUTOPICK) && *str == ';')
242 act |= DO_QUERY_AUTOPICK;
245 else if ((act & DO_DISPLAY) && *str == '(')
254 /* don't mind upper or lower case */
256 for (i = 0; *str; i++)
267 /* Auto-inscription? */
275 if (isupper(c)) c = tolower(c);
281 /* Skip empty line unless allow_default */
282 if (!allow_default && *buf == 0) return FALSE;
284 /* Skip comment line */
285 if (*buf == 0 && insc) return FALSE;
287 ptr = prev_ptr = buf;
290 while (old_ptr != ptr)
292 /* Save current location */
295 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
296 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
297 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
298 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
299 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
300 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
301 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
303 /*** Weapons whose dd*ds is more than nn ***/
304 if (MATCH_KEY2(KEY_MORE_THAN))
309 /* Drop leading spaces */
310 while (' ' == *ptr) ptr++;
313 while ('0' <= *ptr && *ptr <= '9')
315 entry->dice = 10 * entry->dice + (*ptr - '0');
322 (void)MATCH_KEY(KEY_DICE);
323 ADD_FLG(FLG_MORE_DICE);
329 /*** Items whose magical bonus is more than n ***/
330 if (MATCH_KEY2(KEY_MORE_BONUS))
335 /* Drop leading spaces */
336 while (' ' == *ptr) ptr++;
339 while ('0' <= *ptr && *ptr <= '9')
341 entry->bonus = 10 * entry->bonus + (*ptr - '0');
349 (void)MATCH_KEY(KEY_MORE_BONUS2);
351 if (' ' == *ptr) ptr++;
353 ADD_FLG(FLG_MORE_BONUS);
359 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
360 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
361 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
362 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
363 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
364 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
365 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
366 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
367 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
368 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
369 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
370 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
371 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
372 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
373 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
374 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
375 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
378 /* Not yet found any noun */
381 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
383 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
384 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
385 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
386 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
387 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
388 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
389 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
390 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
391 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
392 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
393 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
394 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
395 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
396 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
397 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
398 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
399 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
400 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
401 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
402 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
404 /* Last 'keyword' must be at the correct location */
408 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
411 else if (*ptr == '\0')
413 /* There was no noun */
416 /* Add extra word "items" */
417 ADD_FLG_NOUN(FLG_ITEMS);
424 /* A noun type keyword didn't end correctly */
425 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
430 /* Save this auto-picker entry line */
431 entry->name = string_make(ptr);
433 entry->insc = string_make(insc);
440 * Get auto-picker entry from o_ptr.
442 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
444 /* Assume that object name is to be added */
448 /* ¥¨¥´Ì䬼ÙË⤫¤â¤·¤ì¤Ê¤¤¤Î¤Ç¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¡Ö^¡×¤ÏÉÕ¤±¤Ê¤¤ */
449 bool bol_mark = FALSE;
451 /* We can always use the ^ mark in English */
452 bool bol_mark = TRUE;
455 char name_str[MAX_NLEN];
457 /* Initialize name string */
460 entry->insc = string_make(quark_str(o_ptr->inscription));
461 entry->action = DO_AUTOPICK | DO_DISPLAY;
462 entry->flag[0] = entry->flag[1] = 0L;
466 if (!object_is_aware(o_ptr))
468 ADD_FLG(FLG_UNAWARE);
472 /* Not really identified */
473 else if (!object_is_known(o_ptr))
475 if (!(o_ptr->ident & IDENT_SENSE))
477 ADD_FLG(FLG_UNIDENTIFIED);
482 /* Pseudo-identified */
483 switch (o_ptr->feeling)
487 ADD_FLG(FLG_NAMELESS);
493 ADD_FLG(FLG_NAMELESS);
494 ADD_FLG(FLG_WORTHLESS);
500 ADD_FLG(FLG_WORTHLESS);
508 /* XXX No appropriate flag */
513 /* Never reach here */
523 if (object_is_ego(o_ptr))
525 if (object_is_weapon_armour_ammo(o_ptr))
528 * Base name of ego weapons and armors
529 * are almost meaningless.
530 * Register the ego type only.
532 ego_item_type *e_ptr = &e_info[o_ptr->name2];
534 /* ¥¨¥´ÌäˤϡÖ^¡×¥Þ¡¼¥¯¤¬»È¤¨¤ë */
535 sprintf(name_str, "^%s", e_name + e_ptr->name);
537 /* We ommit the basename and cannot use the ^ mark */
538 strcpy(name_str, e_name + e_ptr->name);
541 /* Don't use the object description */
544 /* Restrict to 'common' equipments */
545 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
552 else if (object_is_artifact(o_ptr))
553 ADD_FLG(FLG_ARTIFACT);
555 /* Non-ego, non-artifact */
558 /* Wearable nameless object */
559 if (object_is_equipment(o_ptr))
560 ADD_FLG(FLG_NAMELESS);
567 /* Melee weapon with boosted dice */
568 if (object_is_melee_weapon(o_ptr))
570 object_kind *k_ptr = &k_info[o_ptr->k_idx];
572 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
573 ADD_FLG(FLG_BOOSTED);
576 /* Wanted monster's corpse */
577 if (object_is_shoukinkubi(o_ptr))
579 REM_FLG(FLG_WORTHLESS);
583 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
584 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
589 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
594 if (o_ptr->tval >= TV_LIFE_BOOK &&
595 !check_book_realm(o_ptr->tval, o_ptr->sval))
597 ADD_FLG(FLG_UNREADABLE);
598 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
601 if (REALM1_BOOK == o_ptr->tval &&
602 p_ptr->pclass != CLASS_SORCERER &&
603 p_ptr->pclass != CLASS_RED_MAGE)
609 if (REALM2_BOOK == o_ptr->tval &&
610 p_ptr->pclass != CLASS_SORCERER &&
611 p_ptr->pclass != CLASS_RED_MAGE)
617 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
619 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
621 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
623 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
626 if (object_is_ammo(o_ptr))
627 ADD_FLG(FLG_MISSILES);
628 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
629 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
630 ADD_FLG(FLG_DEVICES);
631 else if (o_ptr->tval == TV_LITE)
633 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
634 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
636 else if (o_ptr->tval == TV_CORPSE)
637 ADD_FLG(FLG_CORPSES);
638 else if (o_ptr->tval >= TV_LIFE_BOOK)
639 ADD_FLG(FLG_SPELLBOOKS);
640 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
641 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
642 ADD_FLG(FLG_WEAPONS);
643 else if (o_ptr->tval == TV_SHIELD)
644 ADD_FLG(FLG_SHIELDS);
645 else if (o_ptr->tval == TV_BOW)
647 else if (o_ptr->tval == TV_RING)
649 else if (o_ptr->tval == TV_AMULET)
650 ADD_FLG(FLG_AMULETS);
651 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
652 o_ptr->tval == TV_SOFT_ARMOR)
654 else if (o_ptr->tval == TV_CLOAK)
656 else if (o_ptr->tval == TV_HELM)
658 else if (o_ptr->tval == TV_GLOVES)
660 else if (o_ptr->tval == TV_BOOTS)
663 /* Prepare the object description */
666 char o_name[MAX_NLEN];
668 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
671 * If necessary, add a '^' which indicates the
674 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
677 /* Register the name in lowercase */
678 str_tolower(name_str);
679 entry->name = string_make(name_str);
686 * A function to delete entry
688 static void autopick_free_entry(autopick_type *entry)
690 string_free(entry->name);
691 string_free(entry->insc);
697 #define MAX_AUTOPICK_DEFAULT 200
700 * Initialize the autopick
702 static void init_autopick(void)
704 static const char easy_autopick_inscription[] = "(:=g";
710 max_max_autopick = MAX_AUTOPICK_DEFAULT;
711 C_MAKE(autopick_list, max_max_autopick, autopick_type);
715 /* Clear old entries */
716 for( i = 0; i < max_autopick; i++)
717 autopick_free_entry(&autopick_list[i]);
721 /* There is always one entry "=g" */
722 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
723 autopick_list[max_autopick++] = entry;
728 #define PT_WITH_PNAME 1
731 * Get file name for autopick preference
733 static cptr pickpref_filename(int filename_mode)
736 static const char namebase[] = "picktype";
738 static const char namebase[] = "pickpref";
741 switch (filename_mode)
744 return format("%s.prf", namebase);
747 return format("%s-%s.prf", namebase, player_base);
756 * Load an autopick preference file
758 void autopick_load_pref(bool disp_mes)
763 /* Free old entries */
766 /* Try a filename with player name */
767 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
770 err = process_autopick_file(buf);
772 if (err == 0 && disp_mes)
776 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
778 msg_format("Loaded '%s'.", buf);
785 /* Use default name */
786 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
789 err = process_autopick_file(buf);
791 if (err == 0 && disp_mes)
795 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
797 msg_format("Loaded '%s'.", buf);
806 msg_print("¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
808 msg_print("Failed to reload autopick preference.");
815 * Add one line to autopick_list[]
817 static void add_autopick_list(autopick_type *entry)
819 /* There is no enough space to add one line */
820 if (max_autopick >= max_max_autopick)
822 int old_max_max_autopick = max_max_autopick;
823 autopick_type *old_autopick_list = autopick_list;
825 /* Increase size of list */
826 max_max_autopick += MAX_AUTOPICK_DEFAULT;
829 C_MAKE(autopick_list, max_max_autopick, autopick_type);
831 /* Copy from old list to new list */
832 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
835 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
839 autopick_list[max_autopick] = *entry;
846 * Process line for auto picker/destroyer.
848 errr process_autopick_file_command(char *buf)
850 autopick_type an_entry, *entry = &an_entry;
853 /* Nuke illegal char */
854 for(i = 0; buf[i]; i++)
863 if (isspace(buf[i]) && buf[i] != ' ')
868 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
870 /* Already has the same entry? */
871 for(i = 0; i < max_autopick; i++)
872 if(!strcmp(entry->name, autopick_list[i].name)
873 && entry->flag[0] == autopick_list[i].flag[0]
874 && entry->flag[1] == autopick_list[i].flag[1]
875 && entry->dice == autopick_list[i].dice
876 && entry->bonus == autopick_list[i].bonus)
878 autopick_free_entry(entry);
882 add_autopick_list(entry);
888 * Reconstruct preference line from entry
890 cptr autopick_line_from_entry(autopick_type *entry)
892 char buf[MAX_LINELEN];
894 bool sepa_flag = TRUE;
897 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
898 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
899 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
900 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
904 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
905 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
906 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
907 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
908 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
909 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
910 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
912 if (IS_FLG(FLG_MORE_DICE))
914 ADD_KEY(KEY_MORE_THAN);
915 strcat(ptr, format("%d", entry->dice));
919 if (IS_FLG(FLG_MORE_BONUS))
921 ADD_KEY(KEY_MORE_BONUS);
922 strcat(ptr, format("%d", entry->bonus));
923 ADD_KEY(KEY_MORE_BONUS2);
926 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
927 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
928 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
929 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
930 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
931 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
932 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
933 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
934 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
935 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
936 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
937 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
938 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
939 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
940 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
941 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
942 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
944 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
946 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
947 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
948 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
949 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
950 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
951 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
952 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
953 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
954 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
955 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
956 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
957 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
958 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
959 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
960 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
961 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
962 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
963 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
964 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
965 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
967 /* You don't need sepalator after adjective */
968 /* 'artifact' is not true adjective */
969 else if (!IS_FLG(FLG_ARTIFACT))
972 if (entry->name && entry->name[0])
976 if (sepa_flag) strcat(buf, ":");
979 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
982 if (iskanji(entry->name[j]))
983 buf[i++] = entry->name[j++];
985 buf[i++] = entry->name[j++];
996 while (entry->insc[j] && i < MAX_LINELEN - 2)
999 if (iskanji(entry->insc[j]))
1000 buf[i++] = entry->insc[j++];
1002 buf[i++] = entry->insc[j++];
1007 return string_make(buf);
1012 * Reconstruct preference line from entry and kill entry
1014 static cptr autopick_line_from_entry_kill(autopick_type *entry)
1016 cptr ptr = autopick_line_from_entry(entry);
1018 /* Free memory for original entry */
1019 autopick_free_entry(entry);
1026 * A function for Auto-picker/destroyer
1027 * Examine whether the object matches to the entry
1029 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
1032 cptr ptr = entry->name;
1034 /*** Unaware items ***/
1035 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1038 /*** Unidentified ***/
1039 if (IS_FLG(FLG_UNIDENTIFIED)
1040 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1043 /*** Identified ***/
1044 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1047 /*** *Identified* ***/
1048 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1049 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1052 /*** Dice boosted (weapon of slaying) ***/
1053 if (IS_FLG(FLG_BOOSTED))
1055 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1057 /* Require melee weapon */
1058 if (!object_is_melee_weapon(o_ptr))
1061 /* Require boosted dice */
1062 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1065 /* In Vault Quest, Dice must be hide.*/
1066 if(!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
1072 /*** Weapons which dd*ds is more than nn ***/
1073 if (IS_FLG(FLG_MORE_DICE))
1075 if (o_ptr->dd * o_ptr->ds < entry->dice)
1079 /*** Weapons whic dd*ds is more than nn ***/
1080 if (IS_FLG(FLG_MORE_BONUS))
1082 if (!object_is_known(o_ptr)) return FALSE;
1086 if (o_ptr->pval < entry->bonus) return FALSE;
1090 if (o_ptr->to_h < entry->bonus &&
1091 o_ptr->to_d < entry->bonus &&
1092 o_ptr->to_a < entry->bonus &&
1093 o_ptr->pval < entry->bonus)
1098 /*** Worthless items ***/
1099 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1102 /*** Artifact object ***/
1103 if (IS_FLG(FLG_ARTIFACT))
1105 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1109 /*** Ego object ***/
1110 if (IS_FLG(FLG_EGO))
1112 /* Need to be an ego item */
1113 if (!object_is_ego(o_ptr)) return FALSE;
1115 /* Need to be known to be an ego */
1116 if (!object_is_known(o_ptr) &&
1117 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1122 if (IS_FLG(FLG_GOOD))
1124 if (!object_is_equipment(o_ptr)) return FALSE;
1127 if (object_is_known(o_ptr))
1129 /* Artifacts and Ego objects are not okay */
1130 if (!object_is_nameless(o_ptr))
1133 /* Average are not okay */
1134 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1138 /* Pseudo-identified */
1139 else if (o_ptr->ident & IDENT_SENSE)
1141 switch (o_ptr->feeling)
1156 /* Not known to be good */
1162 if (IS_FLG(FLG_NAMELESS))
1164 if (!object_is_equipment(o_ptr)) return FALSE;
1167 if (object_is_known(o_ptr))
1169 /* Artifacts and Ego objects are not okay */
1170 if (!object_is_nameless(o_ptr))
1174 /* Pseudo-identified */
1175 else if (o_ptr->ident & IDENT_SENSE)
1177 switch (o_ptr->feeling)
1187 /* It's not nameless */
1195 /* Not known to be nameless */
1201 if (IS_FLG(FLG_AVERAGE))
1203 if (!object_is_equipment(o_ptr)) return FALSE;
1206 if (object_is_known(o_ptr))
1208 /* Artifacts and Ego objects are not okay */
1209 if (!object_is_nameless(o_ptr))
1212 /* Cursed or broken objects are not okay */
1213 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1216 /* Good are not okay */
1217 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1221 /* Pseudo-identified */
1222 else if (o_ptr->ident & IDENT_SENSE)
1224 switch (o_ptr->feeling)
1231 /* It's not average */
1239 /* Not known to be average */
1244 /*** Rere equipments ***/
1245 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1248 /*** Common equipments ***/
1249 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1252 /*** Wanted monster's corpse/skeletons ***/
1253 if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
1256 /*** Unique monster's corpse/skeletons/statues ***/
1257 if (IS_FLG(FLG_UNIQUE) &&
1258 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1259 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1262 /*** Human corpse/skeletons (for Daemon magic) ***/
1263 if (IS_FLG(FLG_HUMAN) &&
1264 (o_ptr->tval != TV_CORPSE ||
1265 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1268 /*** Unreadable spellbooks ***/
1269 if (IS_FLG(FLG_UNREADABLE) &&
1270 (o_ptr->tval < TV_LIFE_BOOK ||
1271 check_book_realm(o_ptr->tval, o_ptr->sval)))
1274 /*** First realm spellbooks ***/
1275 if (IS_FLG(FLG_REALM1) &&
1276 (REALM1_BOOK != o_ptr->tval ||
1277 p_ptr->pclass == CLASS_SORCERER ||
1278 p_ptr->pclass == CLASS_RED_MAGE))
1281 /*** Second realm spellbooks ***/
1282 if (IS_FLG(FLG_REALM2) &&
1283 (REALM2_BOOK != o_ptr->tval ||
1284 p_ptr->pclass == CLASS_SORCERER ||
1285 p_ptr->pclass == CLASS_RED_MAGE))
1288 /*** First rank spellbooks ***/
1289 if (IS_FLG(FLG_FIRST) &&
1290 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1293 /*** Second rank spellbooks ***/
1294 if (IS_FLG(FLG_SECOND) &&
1295 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1298 /*** Third rank spellbooks ***/
1299 if (IS_FLG(FLG_THIRD) &&
1300 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1303 /*** Fourth rank spellbooks ***/
1304 if (IS_FLG(FLG_FOURTH) &&
1305 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1309 if (IS_FLG(FLG_WEAPONS))
1311 if (!object_is_weapon(o_ptr))
1314 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1316 if (!object_is_favorite(o_ptr))
1319 else if (IS_FLG(FLG_ARMORS))
1321 if (!object_is_armour(o_ptr))
1324 else if (IS_FLG(FLG_MISSILES))
1326 if (!object_is_ammo(o_ptr)) return FALSE;
1328 else if (IS_FLG(FLG_DEVICES))
1332 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1334 default: return FALSE;
1337 else if (IS_FLG(FLG_LIGHTS))
1339 if (!(o_ptr->tval == TV_LITE))
1342 else if (IS_FLG(FLG_JUNKS))
1346 case TV_SKELETON: case TV_BOTTLE:
1347 case TV_JUNK: case TV_STATUE:
1349 default: return FALSE;
1352 else if (IS_FLG(FLG_CORPSES))
1354 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1357 else if (IS_FLG(FLG_SPELLBOOKS))
1359 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1362 else if (IS_FLG(FLG_HAFTED))
1364 if (!(o_ptr->tval == TV_HAFTED))
1367 else if (IS_FLG(FLG_SHIELDS))
1369 if (!(o_ptr->tval == TV_SHIELD))
1372 else if (IS_FLG(FLG_BOWS))
1374 if (!(o_ptr->tval == TV_BOW))
1377 else if (IS_FLG(FLG_RINGS))
1379 if (!(o_ptr->tval == TV_RING))
1382 else if (IS_FLG(FLG_AMULETS))
1384 if (!(o_ptr->tval == TV_AMULET))
1387 else if (IS_FLG(FLG_SUITS))
1389 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1390 o_ptr->tval == TV_HARD_ARMOR ||
1391 o_ptr->tval == TV_SOFT_ARMOR))
1394 else if (IS_FLG(FLG_CLOAKS))
1396 if (!(o_ptr->tval == TV_CLOAK))
1399 else if (IS_FLG(FLG_HELMS))
1401 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1404 else if (IS_FLG(FLG_GLOVES))
1406 if (!(o_ptr->tval == TV_GLOVES))
1409 else if (IS_FLG(FLG_BOOTS))
1411 if (!(o_ptr->tval == TV_BOOTS))
1415 /* Keyword don't match */
1419 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1423 if (!my_strstr(o_name, ptr)) return FALSE;
1426 /* TRUE when it need not to be 'collecting' */
1427 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1429 /* Check if there is a same item */
1430 for (j = 0; j < INVEN_PACK; j++)
1433 * 'Collecting' means the item must be absorbed
1434 * into an inventory slot.
1435 * But an item can not be absorbed into itself!
1437 if ((&inventory[j] != o_ptr) &&
1438 object_similar(&inventory[j], o_ptr))
1442 /* Not collecting */
1448 * A function for Auto-picker/destroyer
1449 * Examine whether the object matches to the list of keywords or not.
1451 int is_autopick(object_type *o_ptr)
1454 char o_name[MAX_NLEN];
1456 if (o_ptr->tval == TV_GOLD) return -1;
1458 /* Prepare object name string first */
1459 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1461 /* Convert the string to lower case */
1462 str_tolower(o_name);
1464 /* Look for a matching entry in the list */
1465 for (i=0; i < max_autopick; i++)
1467 autopick_type *entry = &autopick_list[i];
1469 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1472 /* No matching entry */
1480 static void auto_inscribe_item(object_type *o_ptr, int idx)
1482 /* Are there auto-inscription? */
1483 if (idx < 0 || !autopick_list[idx].insc) return;
1485 if (!o_ptr->inscription)
1486 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1488 /* Redraw inscription */
1489 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1491 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1492 p_ptr->update |= (PU_BONUS);
1497 * Automatically destroy items in this grid.
1499 static bool is_opt_confirm_destroy(object_type *o_ptr)
1501 if (!destroy_items) return FALSE;
1503 /* Known to be worthless? */
1505 if (object_value(o_ptr) > 0) return FALSE;
1508 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1511 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1515 if (object_is_shoukinkubi(o_ptr)) return FALSE;
1519 if (o_ptr->tval == TV_CORPSE) return FALSE;
1522 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1526 if (p_ptr->prace == RACE_DEMON)
1528 if (o_ptr->tval == TV_CORPSE &&
1529 o_ptr->sval == SV_CORPSE &&
1530 my_strchr("pht", r_info[o_ptr->pval].d_char))
1534 if (p_ptr->pclass == CLASS_ARCHER)
1536 if (o_ptr->tval == TV_SKELETON ||
1537 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1540 else if (p_ptr->pclass == CLASS_NINJA)
1542 if (o_ptr->tval == TV_LITE &&
1543 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1546 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1547 p_ptr->pclass == CLASS_CAVALRY)
1549 if (o_ptr->tval == TV_WAND &&
1550 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1555 if (o_ptr->tval == TV_GOLD) return FALSE;
1562 * Automatically destroy an item if it is to be destroyed
1564 * When always_pickup is 'yes', we disable auto-destroyer function of
1565 * auto-picker/destroyer, and do only easy-auto-destroyer.
1567 static object_type autopick_last_destroyed_object;
1569 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1571 bool destroy = FALSE;
1573 /* Easy-Auto-Destroyer (3rd priority) */
1574 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1576 /* Protected by auto-picker (2nd priotity) */
1577 if (autopick_idx >= 0 &&
1578 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1581 /* Auto-destroyer works only when !always_pickup */
1584 /* Auto-picker/destroyer (1st priority) */
1585 if (autopick_idx >= 0 &&
1586 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1590 /* Not to be destroyed */
1591 if (!destroy) return;
1593 /* Now decided to destroy */
1598 if (!can_player_destroy_object(o_ptr))
1600 char o_name[MAX_NLEN];
1602 /* Describe the object (with {terrible/special}) */
1603 object_desc(o_name, o_ptr, 0);
1607 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1609 msg_format("You cannot auto-destroy %s.", o_name);
1616 /* Record name of destroyed item */
1617 (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1620 o_ptr->marked |= OM_AUTODESTROY;
1621 p_ptr->notice |= PN_AUTODESTROY;
1628 * Auto-destroy marked item
1630 static void autopick_delayed_alter_aux(int item)
1634 /* Get the item (in the pack) */
1635 if (item >= 0) o_ptr = &inventory[item];
1637 /* Get the item (on the floor) */
1638 else o_ptr = &o_list[0 - item];
1640 if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
1642 char o_name[MAX_NLEN];
1644 /* Describe the object (with {terrible/special}) */
1645 object_desc(o_name, o_ptr, 0);
1647 /* Eliminate the item (from the pack) */
1650 inven_item_increase(item, -(o_ptr->number));
1651 inven_item_optimize(item);
1654 /* Eliminate the item (from the floor) */
1657 delete_object_idx(0 - item);
1660 /* Print a message */
1662 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1664 msg_format("Auto-destroying %s.", o_name);
1671 * Auto-destroy marked items in inventry and on floor
1673 void autopick_delayed_alter(void)
1678 * Scan inventry in reverse order to prevent
1679 * skipping after inven_item_optimize()
1681 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1682 autopick_delayed_alter_aux(item);
1684 /* Scan the pile of objects */
1685 item = cave[py][px].o_idx;
1688 int next = o_list[item].next_o_idx;
1689 autopick_delayed_alter_aux(-item);
1696 * Auto-inscription and/or destroy
1698 * Auto-destroyer works only on inventory or on floor stack only when
1701 void autopick_alter_item(int item, bool destroy)
1706 /* Get the item (in the pack) */
1707 if (item >= 0) o_ptr = &inventory[item];
1709 /* Get the item (on the floor) */
1710 else o_ptr = &o_list[0 - item];
1712 /* Get the index in the auto-pick/destroy list */
1713 idx = is_autopick(o_ptr);
1715 /* Do auto-inscription */
1716 auto_inscribe_item(o_ptr, idx);
1718 /* Do auto-destroy if needed */
1719 if (destroy && item <= INVEN_PACK)
1720 auto_destroy_item(o_ptr, idx);
1725 * Automatically pickup/destroy items in this grid.
1727 void autopick_pickup_items(cave_type *c_ptr)
1729 s16b this_o_idx, next_o_idx = 0;
1731 /* Scan the pile of objects */
1732 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1736 /* Acquire object */
1737 object_type *o_ptr = &o_list[this_o_idx];
1739 /* Acquire next object */
1740 next_o_idx = o_ptr->next_o_idx;
1742 idx = is_autopick(o_ptr);
1744 /* Item index for floor -1,-2,-3,... */
1745 auto_inscribe_item(o_ptr, idx);
1748 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1752 if (!inven_carry_okay(o_ptr))
1754 char o_name[MAX_NLEN];
1756 /* Describe the object */
1757 object_desc(o_name, o_ptr, 0);
1761 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1763 msg_format("You have no room for %s.", o_name);
1765 /* Hack - remember that the item has given a message here. */
1766 o_ptr->marked |= OM_NOMSG;
1770 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1772 char out_val[MAX_NLEN+20];
1773 char o_name[MAX_NLEN];
1775 if (o_ptr->marked & OM_NO_QUERY)
1777 /* Already answered as 'No' */
1781 /* Describe the object */
1782 object_desc(o_name, o_ptr, 0);
1785 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1787 sprintf(out_val, "Pick up %s? ", o_name);
1790 if (!get_check(out_val))
1792 /* Hack - remember that the item has given a message here. */
1793 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1798 py_pickup_aux(this_o_idx);
1803 * When always_pickup is 'yes', we disable
1804 * auto-destroyer from autopick function, and do only
1805 * easy-auto-destroyer.
1809 auto_destroy_item(o_ptr, idx);
1815 static const char autoregister_header[] = "?:$AUTOREGISTER";
1818 * Clear auto registered lines in the picktype.prf .
1820 static bool clear_auto_register(void)
1822 char tmp_file[1024];
1823 char pref_file[1024];
1828 bool autoregister = FALSE;
1831 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1832 pref_fff = my_fopen(pref_file, "r");
1836 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1837 pref_fff = my_fopen(pref_file, "r");
1846 /* Open a new (temporary) file */
1847 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1851 /* Close the preference file */
1855 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1857 msg_format("Failed to create temporary file %s.", tmp_file);
1864 /* Loop for every line */
1868 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1872 /* Delete auto-registered line */
1874 /* Count auto-destroy preference lines */
1875 if (buf[0] != '#' && buf[0] != '?') num++;
1878 /* We are looking for auto-registered line */
1881 if (streq(buf, autoregister_header))
1883 /* Delete all further lines */
1884 autoregister = TRUE;
1888 /* Copy orginally lines */
1889 fprintf(tmp_fff, "%s\n", buf);
1895 my_fclose(pref_fff);
1901 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1902 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1904 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1905 strcpy(buf, "These lines will be deleted. Are you sure? ");
1908 /* You can cancel it */
1909 if (!get_check(buf))
1912 autoregister = FALSE;
1915 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1917 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1923 /* If there are some changes, overwrite the original file with new one */
1926 /* Copy contents of temporary file */
1928 tmp_fff = my_fopen(tmp_file, "r");
1929 pref_fff = my_fopen(pref_file, "w");
1931 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1932 fprintf(pref_fff, "%s\n", buf);
1934 my_fclose(pref_fff);
1938 /* Kill the temporary file */
1946 * Automatically register an auto-destroy preference line
1948 bool autopick_autoregister(object_type *o_ptr)
1951 char pref_file[1024];
1953 autopick_type an_entry, *entry = &an_entry;
1955 int match_autopick = is_autopick(o_ptr);
1957 /* Already registered */
1958 if (match_autopick != -1)
1961 byte act = autopick_list[match_autopick].action;
1964 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1965 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1966 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1967 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1969 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1971 if (act & DO_AUTOPICK) what = "auto-pickup";
1972 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1973 else if (act & DONT_AUTOPICK) what = "leave on floor";
1974 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1976 msg_format("The object is already registered to %s.", what);
1982 /* Known to be an artifact? */
1983 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1984 ((o_ptr->ident & IDENT_SENSE) &&
1985 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1987 char o_name[MAX_NLEN];
1989 /* Describe the object (with {terrible/special}) */
1990 object_desc(o_name, o_ptr, 0);
1994 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1996 msg_format("You cannot auto-destroy %s.", o_name);
2004 if (!p_ptr->autopick_autoregister)
2006 /* Clear old auto registered lines */
2007 if (!clear_auto_register()) return FALSE;
2010 /* Try a filename with player name */
2011 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
2012 pref_fff = my_fopen(pref_file, "r");
2016 /* Use default name */
2017 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
2018 pref_fff = my_fopen(pref_file, "r");
2021 /* Check the header */
2025 if (my_fgets(pref_fff, buf, sizeof(buf)))
2027 /* No header found */
2028 p_ptr->autopick_autoregister = FALSE;
2033 if (streq(buf, autoregister_header))
2035 /* Found the header */
2036 p_ptr->autopick_autoregister = TRUE;
2042 /* Close read only FILE* */
2045 /* Open for append */
2046 pref_fff = my_fopen(pref_file, "a");
2051 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
2053 msg_format("Failed to open %s.", pref_file);
2061 if (!p_ptr->autopick_autoregister)
2063 /* Add the header */
2064 fprintf(pref_fff, "%s\n", autoregister_header);
2067 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
2068 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
2070 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
2071 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
2074 /* Now auto register is in-use */
2075 p_ptr->autopick_autoregister = TRUE;
2078 /* Get a preference entry */
2079 autopick_entry_from_object(entry, o_ptr);
2081 /* Set to auto-destroy (with no-display) */
2082 entry->action = DO_AUTODESTROY;
2084 /* Load the new line as preference */
2085 add_autopick_list(entry);
2087 /* Add a line to the file */
2088 /* Don't kill "entry" */
2089 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2091 /* Close the file */
2098 /******** Auto-picker/destroyer editor **********/
2100 #define MAX_YANK MAX_LINELEN
2101 #define MAX_LINES 3000
2103 #define MARK_MARK 0x01
2104 #define MARK_BY_SHIFT 0x02
2106 #define LSTAT_BYPASS 0x01
2107 #define LSTAT_EXPRESSION 0x02
2108 #define LSTAT_AUTOREGISTER 0x04
2110 #define QUIT_WITHOUT_SAVE 1
2111 #define QUIT_AND_SAVE 2
2114 * Struct for yank buffer
2116 typedef struct chain_str {
2117 struct chain_str *next;
2123 * Data struct for text editor
2129 int old_wid, old_hgt;
2131 int old_upper, old_left;
2135 object_type *search_o_ptr;
2137 cptr last_destroyed;
2139 chain_str_type *yank;
2143 byte states[MAX_LINES];
2155 * Dirty flag for text editor
2157 #define DIRTY_ALL 0x0001
2158 #define DIRTY_MODE 0x0004
2159 #define DIRTY_SCREEN 0x0008
2160 #define DIRTY_NOT_FOUND 0x0010
2161 #define DIRTY_NO_SEARCH 0x0020
2162 #define DIRTY_EXPRESSION 0x0040
2163 #define DIRTY_SKIP_INACTIVE 0x0080
2164 #define DIRTY_INACTIVE 0x0100
2167 * Describe which kind of object is Auto-picked/destroyed
2169 static void describe_autopick(char *buff, autopick_type *entry)
2171 cptr str = entry->name;
2172 byte act = entry->action;
2173 cptr insc = entry->insc;
2179 cptr before_str[100], body_str;
2182 body_str = "¥¢¥¤¥Æ¥à";
2184 /*** Collecting items ***/
2185 /*** Which can be absorbed into a slot as a bundle ***/
2186 if (IS_FLG(FLG_COLLECTING))
2187 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2189 /*** Unaware items ***/
2190 if (IS_FLG(FLG_UNAWARE))
2191 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2193 /*** Unidentified ***/
2194 if (IS_FLG(FLG_UNIDENTIFIED))
2195 before_str[before_n++] = "̤´ÕÄê¤Î";
2197 /*** Identified ***/
2198 if (IS_FLG(FLG_IDENTIFIED))
2199 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2201 /*** *Identified* ***/
2202 if (IS_FLG(FLG_STAR_IDENTIFIED))
2203 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2205 /*** Dice boosted (weapon of slaying) ***/
2206 if (IS_FLG(FLG_BOOSTED))
2208 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2212 /*** Weapons whose dd*ds is more than nn ***/
2213 if (IS_FLG(FLG_MORE_DICE))
2215 static char more_than_desc_str[] = "___";
2216 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2219 sprintf(more_than_desc_str,"%d", entry->dice);
2220 before_str[before_n++] = more_than_desc_str;
2221 before_str[before_n++] = "°Ê¾å¤Î";
2224 /*** Items whose magical bonus is more than nn ***/
2225 if (IS_FLG(FLG_MORE_BONUS))
2227 static char more_bonus_desc_str[] = "___";
2228 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2230 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2231 before_str[before_n++] = more_bonus_desc_str;
2232 before_str[before_n++] = ")°Ê¾å¤Î";
2235 /*** Worthless items ***/
2236 if (IS_FLG(FLG_WORTHLESS))
2237 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2240 if (IS_FLG(FLG_ARTIFACT))
2242 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2247 if (IS_FLG(FLG_EGO))
2249 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2254 if (IS_FLG(FLG_GOOD))
2256 before_str[before_n++] = "¾å¼Á¤Î";
2261 if (IS_FLG(FLG_NAMELESS))
2263 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2268 if (IS_FLG(FLG_AVERAGE))
2270 before_str[before_n++] = "ʤÎ";
2274 /*** Rare equipments ***/
2275 if (IS_FLG(FLG_RARE))
2277 before_str[before_n++] = "¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ò´Þ¤àÄÁ¤·¤¤";
2281 /*** Common equipments ***/
2282 if (IS_FLG(FLG_COMMON))
2284 before_str[before_n++] = "¤¢¤ê¤Õ¤ì¤¿(¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ÎÄÁ¤·¤¤Êª¤Ç¤Ï¤Ê¤¤)";
2288 /*** Wanted monster's corpse/skeletons ***/
2289 if (IS_FLG(FLG_WANTED))
2291 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2292 body_str = "»àÂΤä¹ü";
2295 /*** Human corpse/skeletons (for Daemon magic) ***/
2296 if (IS_FLG(FLG_HUMAN))
2298 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2299 body_str = "»àÂΤä¹ü";
2302 /*** Unique monster's corpse/skeletons/statues ***/
2303 if (IS_FLG(FLG_UNIQUE))
2305 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2306 body_str = "»àÂΤä¹ü";
2309 /*** Unreadable spellbooks ***/
2310 if (IS_FLG(FLG_UNREADABLE))
2312 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2313 body_str = "ËâË¡½ñ";
2316 /*** First realm spellbooks ***/
2317 if (IS_FLG(FLG_REALM1))
2319 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2320 body_str = "ËâË¡½ñ";
2323 /*** Second realm spellbooks ***/
2324 if (IS_FLG(FLG_REALM2))
2326 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2327 body_str = "ËâË¡½ñ";
2330 /*** First rank spellbooks ***/
2331 if (IS_FLG(FLG_FIRST))
2333 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2334 body_str = "ËâË¡½ñ";
2337 /*** Second rank spellbooks ***/
2338 if (IS_FLG(FLG_SECOND))
2340 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2341 body_str = "ËâË¡½ñ";
2344 /*** Third rank spellbooks ***/
2345 if (IS_FLG(FLG_THIRD))
2347 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2348 body_str = "ËâË¡½ñ";
2351 /*** Fourth rank spellbooks ***/
2352 if (IS_FLG(FLG_FOURTH))
2354 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2355 body_str = "ËâË¡½ñ";
2359 if (IS_FLG(FLG_ITEMS))
2360 ; /* Nothing to do */
2361 else if (IS_FLG(FLG_WEAPONS))
2363 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2364 body_str = "ÆÀ°ÕÉð´ï";
2365 else if (IS_FLG(FLG_ARMORS))
2367 else if (IS_FLG(FLG_MISSILES))
2368 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2369 else if (IS_FLG(FLG_DEVICES))
2370 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2371 else if (IS_FLG(FLG_LIGHTS))
2372 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2373 else if (IS_FLG(FLG_JUNKS))
2374 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2375 else if (IS_FLG(FLG_CORPSES))
2376 body_str = "»àÂΤä¹ü";
2377 else if (IS_FLG(FLG_SPELLBOOKS))
2378 body_str = "ËâË¡½ñ";
2379 else if (IS_FLG(FLG_HAFTED))
2381 else if (IS_FLG(FLG_SHIELDS))
2383 else if (IS_FLG(FLG_BOWS))
2384 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2385 else if (IS_FLG(FLG_RINGS))
2387 else if (IS_FLG(FLG_AMULETS))
2388 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2389 else if (IS_FLG(FLG_SUITS))
2391 else if (IS_FLG(FLG_CLOAKS))
2392 body_str = "¥¯¥í¡¼¥¯";
2393 else if (IS_FLG(FLG_HELMS))
2394 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2395 else if (IS_FLG(FLG_GLOVES))
2397 else if (IS_FLG(FLG_BOOTS))
2398 body_str = "¥Ö¡¼¥Ä";
2402 strcat(buff, "Á´¤Æ¤Î");
2403 else for (i = 0; i < before_n && before_str[i]; i++)
2404 strcat(buff, before_str[i]);
2406 strcat(buff, body_str);
2416 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2417 strncat(buff, str, 80);
2419 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2421 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2426 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2428 if (my_strstr(insc, "%%all"))
2429 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2430 else if (my_strstr(insc, "%all"))
2431 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2432 else if (my_strstr(insc, "%%"))
2433 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2434 else if (my_strstr(insc, "%"))
2435 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2437 strcat(buff, "¤È¹ï¤ó¤Ç");
2442 if (act & DONT_AUTOPICK)
2443 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2444 else if (act & DO_AUTODESTROY)
2445 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2446 else if (act & DO_QUERY_AUTOPICK)
2447 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2449 strcat(buff, "½¦¤¦¡£");
2451 if (act & DO_DISPLAY)
2453 if (act & DONT_AUTOPICK)
2454 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2455 else if (act & DO_AUTODESTROY)
2456 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2458 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2461 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2465 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2466 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2470 /*** Collecting items ***/
2471 /*** Which can be absorbed into a slot as a bundle ***/
2472 if (IS_FLG(FLG_COLLECTING))
2473 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2475 /*** Unaware items ***/
2476 if (IS_FLG(FLG_UNAWARE))
2478 before_str[before_n++] = "unidentified";
2479 whose_str[whose_n++] = "basic abilities are not known";
2482 /*** Unidentified ***/
2483 if (IS_FLG(FLG_UNIDENTIFIED))
2484 before_str[before_n++] = "unidentified";
2486 /*** Identified ***/
2487 if (IS_FLG(FLG_IDENTIFIED))
2488 before_str[before_n++] = "identified";
2490 /*** *Identified* ***/
2491 if (IS_FLG(FLG_STAR_IDENTIFIED))
2492 before_str[before_n++] = "fully identified";
2494 /*** Rare equipments ***/
2495 if (IS_FLG(FLG_RARE))
2497 before_str[before_n++] = "very rare";
2498 body_str = "equipments";
2499 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2502 /*** Common equipments ***/
2503 if (IS_FLG(FLG_COMMON))
2505 before_str[before_n++] = "relatively common";
2506 body_str = "equipments";
2507 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2510 /*** Worthless items ***/
2511 if (IS_FLG(FLG_WORTHLESS))
2513 before_str[before_n++] = "worthless";
2514 which_str[which_n++] = "can not be sold at stores";
2518 if (IS_FLG(FLG_ARTIFACT))
2520 before_str[before_n++] = "artifact";
2524 if (IS_FLG(FLG_EGO))
2526 before_str[before_n++] = "ego";
2530 if (IS_FLG(FLG_GOOD))
2532 body_str = "equipment";
2533 which_str[which_n++] = "have good quality";
2537 if (IS_FLG(FLG_NAMELESS))
2539 body_str = "equipment";
2540 which_str[which_n++] = "is neither ego-item nor artifact";
2544 if (IS_FLG(FLG_AVERAGE))
2546 body_str = "equipment";
2547 which_str[which_n++] = "have average quality";
2550 /*** Dice boosted (weapon of slaying) ***/
2551 if (IS_FLG(FLG_BOOSTED))
2553 body_str = "weapons";
2554 whose_str[whose_n++] = "damage dice is bigger than normal";
2557 /*** Weapons whose dd*ds is more than nn ***/
2558 if (IS_FLG(FLG_MORE_DICE))
2560 static char more_than_desc_str[] =
2561 "maximum damage from dice is bigger than __";
2562 body_str = "weapons";
2564 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2566 whose_str[whose_n++] = more_than_desc_str;
2569 /*** Items whose magical bonus is more than nn ***/
2570 if (IS_FLG(FLG_MORE_BONUS))
2572 static char more_bonus_desc_str[] =
2573 "magical bonus is bigger than (+__)";
2575 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2576 "%d)", entry->bonus);
2577 whose_str[whose_n++] = more_bonus_desc_str;
2580 /*** Wanted monster's corpse/skeletons ***/
2581 if (IS_FLG(FLG_WANTED))
2583 body_str = "corpse or skeletons";
2584 which_str[which_n++] = "is wanted at the Hunter's Office";
2587 /*** Human corpse/skeletons (for Daemon magic) ***/
2588 if (IS_FLG(FLG_HUMAN))
2590 before_str[before_n++] = "humanoid";
2591 body_str = "corpse or skeletons";
2592 which_str[which_n++] = "can be used for Daemon magic";
2595 /*** Unique monster's corpse/skeletons/statues ***/
2596 if (IS_FLG(FLG_UNIQUE))
2598 before_str[before_n++] = "unique monster's";
2599 body_str = "corpse or skeletons";
2602 /*** Unreadable spellbooks ***/
2603 if (IS_FLG(FLG_UNREADABLE))
2605 body_str = "spellbooks";
2606 after_str[after_n++] = "of different realms from yours";
2609 /*** First realm spellbooks ***/
2610 if (IS_FLG(FLG_REALM1))
2612 body_str = "spellbooks";
2613 after_str[after_n++] = "of your first realm";
2616 /*** Second realm spellbooks ***/
2617 if (IS_FLG(FLG_REALM2))
2619 body_str = "spellbooks";
2620 after_str[after_n++] = "of your second realm";
2623 /*** First rank spellbooks ***/
2624 if (IS_FLG(FLG_FIRST))
2626 before_str[before_n++] = "first one of four";
2627 body_str = "spellbooks";
2630 /*** Second rank spellbooks ***/
2631 if (IS_FLG(FLG_SECOND))
2633 before_str[before_n++] = "second one of four";
2634 body_str = "spellbooks";
2637 /*** Third rank spellbooks ***/
2638 if (IS_FLG(FLG_THIRD))
2640 before_str[before_n++] = "third one of four";
2641 body_str = "spellbooks";
2644 /*** Fourth rank spellbooks ***/
2645 if (IS_FLG(FLG_FOURTH))
2647 before_str[before_n++] = "fourth one of four";
2648 body_str = "spellbooks";
2652 if (IS_FLG(FLG_ITEMS))
2653 ; /* Nothing to do */
2654 else if (IS_FLG(FLG_WEAPONS))
2655 body_str = "weapons";
2656 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2657 body_str = "favorite weapons";
2658 else if (IS_FLG(FLG_ARMORS))
2659 body_str = "armors";
2660 else if (IS_FLG(FLG_MISSILES))
2661 body_str = "shots, arrows or crossbow bolts";
2662 else if (IS_FLG(FLG_DEVICES))
2663 body_str = "scrolls, wands, staves or rods";
2664 else if (IS_FLG(FLG_LIGHTS))
2665 body_str = "light sources";
2666 else if (IS_FLG(FLG_JUNKS))
2667 body_str = "junk such as broken sticks";
2668 else if (IS_FLG(FLG_CORPSES))
2669 body_str = "corpses or skeletons";
2670 else if (IS_FLG(FLG_SPELLBOOKS))
2671 body_str = "spellbooks";
2672 else if (IS_FLG(FLG_HAFTED))
2673 body_str = "hafted weapons";
2674 else if (IS_FLG(FLG_SHIELDS))
2675 body_str = "shields";
2676 else if (IS_FLG(FLG_BOWS))
2677 body_str = "slings, bows or crossbows";
2678 else if (IS_FLG(FLG_RINGS))
2680 else if (IS_FLG(FLG_AMULETS))
2681 body_str = "amulets";
2682 else if (IS_FLG(FLG_SUITS))
2683 body_str = "body armors";
2684 else if (IS_FLG(FLG_CLOAKS))
2685 body_str = "cloaks";
2686 else if (IS_FLG(FLG_HELMS))
2687 body_str = "helms or crowns";
2688 else if (IS_FLG(FLG_GLOVES))
2689 body_str = "gloves";
2690 else if (IS_FLG(FLG_BOOTS))
2693 /* Prepare a string for item name */
2700 whose_str[whose_n++] = "name is beginning with \"";
2703 which_str[which_n++] = "have \"";
2707 /* Describe action flag */
2708 if (act & DONT_AUTOPICK)
2709 strcpy(buff, "Leave on floor ");
2710 else if (act & DO_AUTODESTROY)
2711 strcpy(buff, "Destroy ");
2712 else if (act & DO_QUERY_AUTOPICK)
2713 strcpy(buff, "Ask to pick up ");
2715 strcpy(buff, "Pickup ");
2717 /* Auto-insctiption */
2720 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2722 if (my_strstr(insc, "%all"))
2723 strcat(buff, ", replacing %all with code string representing all abilities,");
2724 else if (my_strstr(insc, "%"))
2725 strcat(buff, ", replacing % with code string representing extra random abilities,");
2727 strcat(buff, " on ");
2732 strcat(buff, "all ");
2733 else for (i = 0; i < before_n && before_str[i]; i++)
2735 strcat(buff, before_str[i]);
2740 strcat(buff, body_str);
2743 for (i = 0; i < after_n && after_str[i]; i++)
2746 strcat(buff, after_str[i]);
2750 for (i = 0; i < whose_n && whose_str[i]; i++)
2753 strcat(buff, " whose ");
2755 strcat(buff, ", and ");
2757 strcat(buff, whose_str[i]);
2760 /* Item name ; whose name is beginning with "str" */
2767 /* whose ..., and which .... */
2768 if (whose_n && which_n)
2769 strcat(buff, ", and ");
2772 for (i = 0; i < which_n && which_str[i]; i++)
2775 strcat(buff, " which ");
2777 strcat(buff, ", and ");
2779 strcat(buff, which_str[i]);
2782 /* Item name ; which have "str" as part of its name */
2785 strncat(buff, str, 80);
2786 strcat(buff, "\" as part of its name");
2790 /* Describe whether it will be displayed on the full map or not */
2791 if (act & DO_DISPLAY)
2793 if (act & DONT_AUTOPICK)
2794 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2795 else if (act & DO_AUTODESTROY)
2796 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2798 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2801 strcat(buff, " Not displayed in the full map.");
2808 * Read whole lines of a file to memory
2810 static cptr *read_text_lines(cptr filename)
2812 cptr *lines_list = NULL;
2818 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2821 fff = my_fopen(buf, "r");
2825 /* Allocate list of pointers */
2826 C_MAKE(lines_list, MAX_LINES, cptr);
2829 while (0 == my_fgets(fff, buf, sizeof(buf)))
2831 lines_list[lines++] = string_make(buf);
2832 if (lines >= MAX_LINES - 1) break;
2835 lines_list[0] = string_make("");
2840 if (!fff) return NULL;
2846 * Copy the default autopick file to the user directory
2848 static void prepare_default_pickpref(void)
2850 static char *messages[] = {
2852 "¤¢¤Ê¤¿¤Ï¡Ö¼«Æ°½¦¤¤¥¨¥Ç¥£¥¿¡×¤ò½é¤á¤Æµ¯Æ°¤·¤Þ¤·¤¿¡£",
2853 "¼«Æ°½¦¤¤¤Î¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤¬¤Þ¤À½ñ¤«¤ì¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢",
2854 "´ðËÜŪ¤Ê¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤òlib/pref/picktype.prf¤«¤é¥³¥Ô¡¼¤·¤Þ¤¹¡£",
2857 "You have activated the Auto-Picker Editor for the first time.",
2858 "Since user pref file for autopick is not yet created,",
2859 "the default setting is loaded from lib/pref/pickpref.prf .",
2868 cptr filename = pickpref_filename(PT_DEFAULT);
2870 /* Display messages */
2871 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2876 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2877 user_fp = my_fopen(buf, "w");
2880 if (!user_fp) return;
2882 /* Write header messages for a notification */
2883 fprintf(user_fp, "#***\n");
2884 for (i = 0; messages[i]; i++)
2886 fprintf(user_fp, "#*** %s\n", messages[i]);
2888 fprintf(user_fp, "#***\n\n\n");
2891 /* Open the default file */
2892 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2893 pref_fp = my_fopen(buf, "r");
2902 /* Copy the contents of default file */
2903 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2904 fprintf(user_fp, "%s\n", buf);
2911 * Read an autopick prefence file to memory
2912 * Prepare default if no user file is found
2914 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2919 /* Try a filename with player name */
2920 *filename_mode_p = PT_WITH_PNAME;
2921 strcpy(buf, pickpref_filename(*filename_mode_p));
2922 lines_list = read_text_lines(buf);
2926 /* Use default name */
2927 *filename_mode_p = PT_DEFAULT;
2928 strcpy(buf, pickpref_filename(*filename_mode_p));
2929 lines_list = read_text_lines(buf);
2934 /* There is no preference file in the user directory */
2936 /* Copy the default autopick file to the user directory */
2937 prepare_default_pickpref();
2939 /* Use default name again */
2940 lines_list = read_text_lines(buf);
2945 /* Allocate list of pointers */
2946 C_MAKE(lines_list, MAX_LINES, cptr);
2947 lines_list[0] = string_make("");
2954 * Write whole lines of memory to a file.
2956 static bool write_text_lines(cptr filename, cptr *lines_list)
2963 /* Build the filename */
2964 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2967 fff = my_fopen(buf, "w");
2970 for (lines = 0; lines_list[lines]; lines++)
2971 my_fputs(fff, lines_list[lines], 1024);
2976 if (!fff) return FALSE;
2982 * Free memory of lines_list.
2984 static void free_text_lines(cptr *lines_list)
2988 for (lines = 0; lines_list[lines]; lines++)
2989 string_free(lines_list[lines]);
2991 /* free list of pointers */
2992 C_KILL(lines_list, MAX_LINES, cptr);
2997 * Delete or insert string
2999 static void toggle_keyword(text_body_type *tb, int flg)
3005 /* Some lines are selected */
3008 by1 = MIN(tb->my, tb->cy);
3009 by2 = MAX(tb->my, tb->cy);
3012 /* No mark -- Select current line */
3013 else /* if (!tb->mark) */
3019 /* Set/Reset flag of each line */
3020 for (y = by1; y <= by2; y++)
3022 autopick_type an_entry, *entry = &an_entry;
3024 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
3026 string_free(tb->lines_list[y]);
3030 /* Add? or Remove? */
3031 if (!IS_FLG(flg)) add = TRUE;
3034 /* No more change */
3038 /* You can use only one noun flag */
3039 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3042 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3046 /* You can use only one identify state flag */
3047 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
3050 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
3054 /* You can use only one flag in artifact/ego/nameless */
3055 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
3058 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
3062 /* You can use only one flag in rare/common */
3063 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
3066 for (i = FLG_RARE; i <= FLG_COMMON; i++)
3070 if (add) ADD_FLG(flg);
3073 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3076 tb->dirty_flags |= DIRTY_ALL;
3078 /* Text is changed */
3085 * Change command letter
3087 static void toggle_command_letter(text_body_type *tb, byte flg)
3089 autopick_type an_entry, *entry = &an_entry;
3094 /* Some lines are selected */
3097 by1 = MIN(tb->my, tb->cy);
3098 by2 = MAX(tb->my, tb->cy);
3101 /* No mark -- Select current line */
3102 else /* if (!tb->mark) */
3108 /* Set/Reset flag of each line */
3109 for (y = by1; y <= by2; y++)
3113 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3115 string_free(tb->lines_list[y]);
3119 /* Add? or Remove? */
3120 if (!(entry->action & flg)) add = TRUE;
3123 /* No more change */
3127 /* Count number of letter (by negative number) */
3128 if (entry->action & DONT_AUTOPICK) wid--;
3129 else if (entry->action & DO_AUTODESTROY) wid--;
3130 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3131 if (!(entry->action & DO_DISPLAY)) wid--;
3133 /* Set/Reset the flag */
3134 if (flg != DO_DISPLAY)
3136 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3137 if (add) entry->action |= flg;
3138 else entry->action |= DO_AUTOPICK;
3142 entry->action &= ~(DO_DISPLAY);
3143 if (add) entry->action |= flg;
3146 /* Correct cursor location */
3149 if (entry->action & DONT_AUTOPICK) wid++;
3150 else if (entry->action & DO_AUTODESTROY) wid++;
3151 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3152 if (!(entry->action & DO_DISPLAY)) wid++;
3154 if (wid > 0) tb->cx++;
3155 if (wid < 0 && tb->cx > 0) tb->cx--;
3158 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3161 tb->dirty_flags |= DIRTY_ALL;
3163 /* Text is changed */
3169 * Delete or insert string
3171 static void add_keyword(text_body_type *tb, int flg)
3175 /* Some lines are selected */
3178 by1 = MIN(tb->my, tb->cy);
3179 by2 = MAX(tb->my, tb->cy);
3182 /* No mark -- Select current line */
3183 else /* if (!tb->mark) */
3189 /* Set/Reset flag of each line */
3190 for (y = by1; y <= by2; y++)
3192 autopick_type an_entry, *entry = &an_entry;
3194 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3196 /* There is the flag already */
3199 /* Free memory for the entry */
3200 autopick_free_entry(entry);
3205 string_free(tb->lines_list[y]);
3207 /* Remove all noun flag */
3208 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3211 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3217 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3220 tb->dirty_flags |= DIRTY_ALL;
3222 /* Text is changed */
3229 * Check if this line is expression or not.
3230 * And update it if it is.
3232 static void check_expression_line(text_body_type *tb, int y)
3234 cptr s = tb->lines_list[y];
3236 if ((s[0] == '?' && s[1] == ':') ||
3237 (tb->states[y] & LSTAT_BYPASS))
3239 /* Expressions need re-evaluation */
3240 tb->dirty_flags |= DIRTY_EXPRESSION;
3246 * Add an empty line at the last of the file
3248 static bool add_empty_line(text_body_type *tb)
3252 for (k = 0; tb->lines_list[k]; k++)
3253 /* count number of lines */ ;
3255 /* Too many lines! */
3256 if (k >= MAX_LINES - 2) return FALSE;
3258 /* The last line is already empty */
3259 if (!tb->lines_list[k-1][0]) return FALSE;
3261 /* Create new empty line */
3262 tb->lines_list[k] = string_make("");
3264 /* Expressions need re-evaluation */
3265 tb->dirty_flags |= DIRTY_EXPRESSION;
3267 /* Text is changed */
3270 /* A line is added */
3276 * Insert return code and split the line
3278 static bool insert_return_code(text_body_type *tb)
3280 char buf[MAX_LINELEN];
3283 for (k = 0; tb->lines_list[k]; k++)
3284 /* count number of lines */ ;
3286 if (k >= MAX_LINES - 2) return FALSE;
3289 /* Move down lines */
3290 for (; tb->cy < k; k--)
3292 tb->lines_list[k+1] = tb->lines_list[k];
3293 tb->states[k+1] = tb->states[k];
3296 /* Split current line */
3297 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3300 if (iskanji(tb->lines_list[tb->cy][i]))
3301 buf[j++] = tb->lines_list[tb->cy][i++];
3303 buf[j++] = tb->lines_list[tb->cy][i];
3306 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3307 string_free(tb->lines_list[tb->cy]);
3308 tb->lines_list[tb->cy] = string_make(buf);
3310 /* Expressions need re-evaluation */
3311 tb->dirty_flags |= DIRTY_EXPRESSION;
3313 /* Text is changed */
3321 * Choose an item and get auto-picker entry from it.
3323 static object_type *choose_object(cptr q, cptr s)
3327 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3329 /* Get the item (in the pack) */
3330 if (item >= 0) return &inventory[item];
3332 /* Get the item (on the floor) */
3333 else return &o_list[0 - item];
3338 * Choose an item and get auto-picker entry from it.
3340 static bool entry_from_choosed_object(autopick_type *entry)
3347 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3348 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3350 q = "Enter which item? ";
3351 s = "You have nothing to enter.";
3353 o_ptr = choose_object(q, s);
3354 if (!o_ptr) return FALSE;
3356 autopick_entry_from_object(entry, o_ptr);
3362 * Choose an item for search
3364 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3366 char buf[MAX_NLEN+20];
3372 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3373 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3375 q = "Enter which item? ";
3376 s = "You have nothing to enter.";
3378 o_ptr = choose_object(q, s);
3379 if (!o_ptr) return 0;
3383 string_free(*search_strp);
3384 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3385 *search_strp = string_make(format("<%s>", buf));
3391 * Prepare for search by destroyed object
3393 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3395 char buf[MAX_NLEN+20];
3397 if (!autopick_last_destroyed_object.k_idx) return 0;
3399 *o_handle = &autopick_last_destroyed_object;
3401 string_free(*search_strp);
3402 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3403 *search_strp = string_make(format("<%s>", buf));
3409 * Choose an item or string for search
3411 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3417 * TERM_YELLOW : Overwrite mode
3418 * TERM_WHITE : Insert mode
3420 byte color = TERM_YELLOW;
3421 char buf[MAX_NLEN+20];
3425 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3427 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3429 int col = sizeof(prompt) - 1;
3431 /* Prepare string buffer for edit */
3432 if (*search_strp) strcpy(buf, *search_strp);
3435 /* Object searching mode */
3438 color = TERM_L_GREEN;
3441 /* Display prompt */
3451 /* Display the string */
3452 Term_erase(col, 0, 255);
3453 Term_putstr(col, 0, -1, color, buf);
3456 Term_gotoxy(col + pos, 0);
3458 /* Get a special key code */
3459 skey = inkey_special(TRUE);
3461 /* Analyze the key */
3469 /* Now on insert mode */
3472 /* No move at beginning of line */
3473 if (0 == pos) break;
3477 int next_pos = i + 1;
3480 if (iskanji(buf[i])) next_pos++;
3483 /* Is there the cursor at next position? */
3484 if (next_pos >= pos) break;
3490 /* Get previous position */
3498 /* Now on insert mode */
3501 /* No move at end of line */
3502 if ('\0' == buf[pos]) break;
3506 if (iskanji(buf[pos])) pos += 2;
3524 if (*o_handle) return (back ? -1 : 1);
3525 string_free(*search_strp);
3526 *search_strp = string_make(buf);
3528 return (back ? -1 : 1);
3532 return get_object_for_search(o_handle, search_strp);
3535 /* Prepare string for destroyed object if there is one. */
3536 if (get_destroyed_object_for_search(o_handle, search_strp))
3546 /* Now on insert mode */
3549 /* No move at beginning of line */
3550 if (0 == pos) break;
3554 int next_pos = i + 1;
3557 if (iskanji(buf[i])) next_pos++;
3560 /* Is there the cursor at next position? */
3561 if (next_pos >= pos) break;
3567 /* Get previous position */
3570 /* Fall through to 'Delete key' */
3579 /* Now on insert mode */
3582 /* No move at end of line */
3583 if ('\0' == buf[pos]) break;
3585 /* Position of next character */
3589 /* Next character is one more byte away */
3590 if (iskanji(buf[pos])) src++;
3595 /* Move characters at src to dst */
3596 while ('\0' != (buf[dst++] = buf[src++]))
3604 /* Insert a character */
3609 /* Ignore special keys */
3610 if (skey & SKEY_MASK) break;
3612 /* Get a character code */
3615 /* Was non insert mode? */
3616 if (color != TERM_WHITE)
3618 /* Was object searching mode */
3619 if (color == TERM_L_GREEN)
3621 /* Cancel the mode */
3624 /* Remove indicating string */
3625 string_free(*search_strp);
3626 *search_strp = NULL;
3629 /* Overwrite default string */
3632 /* Go to insert mode */
3636 /* Save right part of string */
3637 strcpy(tmp, buf + pos);
3643 /* Bypass macro processing */
3661 if (pos < len && (isprint(c) || iskana(c)))
3663 if (pos < len && isprint(c))
3677 /* Write back the left part of string */
3678 my_strcat(buf, tmp, len + 1);
3685 /* Object searching mode was cancelled? */
3686 if (*o_handle && color != TERM_L_GREEN)
3688 /* Cancel the mode */
3691 /* Remove indicating string */
3693 string_free(*search_strp);
3694 *search_strp = NULL;
3699 } /* while (TRUE) */
3704 * Search next line matches for o_ptr
3706 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3708 autopick_type an_entry, *entry = &an_entry;
3709 char o_name[MAX_NLEN];
3710 int bypassed_cy = -1;
3712 /* Start searching from current cursor position */
3715 /* Prepare object name string first */
3716 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3718 /* Convert the string to lower case */
3719 str_tolower(o_name);
3728 if (!tb->lines_list[++i]) break;
3735 /* Is this line is a correct entry? */
3736 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3738 /* Does this line match to the object? */
3739 match = is_autopick_aux(o_ptr, entry, o_name);
3740 autopick_free_entry(entry);
3741 if (!match) continue;
3743 /* Found a line but it's inactive */
3744 if (tb->states[i] & LSTAT_BYPASS)
3746 /* If it is first found, remember it */
3747 if (bypassed_cy == -1) bypassed_cy = i;
3750 /* Found an active line! */
3753 /* Move to this line */
3757 if (bypassed_cy != -1)
3759 /* Mark as some lines are skipped */
3760 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3768 if (bypassed_cy != -1)
3770 /* Move to the remembered line */
3772 tb->cy = bypassed_cy;
3774 /* Mark as this line is inactive */
3775 tb->dirty_flags |= DIRTY_INACTIVE;
3780 /* Mark as NOT FOUND */
3781 tb->dirty_flags |= DIRTY_NOT_FOUND;
3789 * Search next line matches to the string
3791 static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
3793 int bypassed_cy = -1;
3794 int bypassed_cx = 0;
3796 /* Start searching from current cursor position */
3806 if (!tb->lines_list[++i]) break;
3813 /* Look for the string pattern */
3814 pos = my_strstr(tb->lines_list[i], search_str);
3819 /* Found a line but it's inactive */
3820 if ((tb->states[i] & LSTAT_BYPASS) &&
3821 !(tb->states[i] & LSTAT_EXPRESSION))
3823 /* If it is first found, remember it */
3824 if (bypassed_cy == -1)
3827 bypassed_cx = (int)(pos - tb->lines_list[i]);
3831 /* Found an active line! */
3834 /* Move to this location */
3835 tb->cx = (int)(pos - tb->lines_list[i]);
3838 if (bypassed_cy != -1)
3840 /* Mark as some lines are skipped */
3841 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3849 if (bypassed_cy != -1)
3851 /* Move to the remembered line */
3852 tb->cx = bypassed_cx;
3853 tb->cy = bypassed_cy;
3855 /* Mark as this line is inactive */
3856 tb->dirty_flags |= DIRTY_INACTIVE;
3861 /* Mark as NOT FOUND */
3862 tb->dirty_flags |= DIRTY_NOT_FOUND;
3872 * Editor command id's
3875 #define EC_SAVEQUIT 2
3886 #define EC_PGDOWN 13
3888 #define EC_BOTTOM 15
3893 #define EC_KILL_LINE 20
3894 #define EC_DELETE_CHAR 21
3895 #define EC_BACKSPACE 22
3896 #define EC_SEARCH_STR 23
3897 #define EC_SEARCH_FORW 24
3898 #define EC_SEARCH_BACK 25
3899 #define EC_SEARCH_OBJ 26
3900 #define EC_SEARCH_DESTROYED 27
3901 #define EC_INSERT_OBJECT 28
3902 #define EC_INSERT_DESTROYED 29
3903 #define EC_INSERT_BLOCK 30
3904 #define EC_INSERT_MACRO 31
3905 #define EC_INSERT_KEYMAP 32
3906 #define EC_CL_AUTOPICK 33
3907 #define EC_CL_DESTROY 34
3908 #define EC_CL_LEAVE 35
3909 #define EC_CL_QUERY 36
3910 #define EC_CL_NO_DISP 37
3911 #define EC_OK_COLLECTING 38
3912 #define EC_IK_UNAWARE 39
3913 #define EC_IK_UNIDENTIFIED 40
3914 #define EC_IK_IDENTIFIED 41
3915 #define EC_IK_STAR_IDENTIFIED 42
3916 #define EC_OK_BOOSTED 43
3917 #define EC_OK_MORE_DICE 44
3918 #define EC_OK_MORE_BONUS 45
3919 #define EC_OK_WORTHLESS 46
3920 #define EC_OK_ARTIFACT 47
3921 #define EC_OK_EGO 48
3922 #define EC_OK_GOOD 49
3923 #define EC_OK_NAMELESS 50
3924 #define EC_OK_AVERAGE 51
3925 #define EC_OK_RARE 52
3926 #define EC_OK_COMMON 53
3927 #define EC_OK_WANTED 54
3928 #define EC_OK_UNIQUE 55
3929 #define EC_OK_HUMAN 56
3930 #define EC_OK_UNREADABLE 57
3931 #define EC_OK_REALM1 58
3932 #define EC_OK_REALM2 59
3933 #define EC_OK_FIRST 60
3934 #define EC_OK_SECOND 61
3935 #define EC_OK_THIRD 62
3936 #define EC_OK_FOURTH 63
3937 #define EC_KK_WEAPONS 64
3938 #define EC_KK_FAVORITE_WEAPONS 65
3939 #define EC_KK_ARMORS 66
3940 #define EC_KK_MISSILES 67
3941 #define EC_KK_DEVICES 68
3942 #define EC_KK_LIGHTS 69
3943 #define EC_KK_JUNKS 70
3944 #define EC_KK_CORPSES 71
3945 #define EC_KK_SPELLBOOKS 72
3946 #define EC_KK_SHIELDS 73
3947 #define EC_KK_BOWS 74
3948 #define EC_KK_RINGS 75
3949 #define EC_KK_AMULETS 76
3950 #define EC_KK_SUITS 77
3951 #define EC_KK_CLOAKS 78
3952 #define EC_KK_HELMS 79
3953 #define EC_KK_GLOVES 80
3954 #define EC_KK_BOOTS 81
3960 static char MN_QUIT[] = "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»";
3961 static char MN_SAVEQUIT[] = "¥»¡¼¥Ö¤·¤Æ½ªÎ»";
3962 static char MN_REVERT[] = "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ";
3963 static char MN_HELP[] = "¥Ø¥ë¥×";
3965 static char MN_MOVE[] = "¥«¡¼¥½¥ë°ÜÆ°";
3966 static char MN_LEFT[] = "º¸ (¢«Ìð°õ¥¡¼)";
3967 static char MN_DOWN[] = "²¼ (¢Ìð°õ¥¡¼)";
3968 static char MN_UP[] = "¾å (¢¬Ìð°õ¥¡¼)";
3969 static char MN_RIGHT[] = "±¦ (¢ªÌð°õ¥¡¼)";
3970 static char MN_BOL[] = "¹Ô¤ÎÀèƬ";
3971 static char MN_EOL[] = "¹Ô¤Î½ªÃ¼";
3972 static char MN_PGUP[] = "¾å¤Î¥Ú¡¼¥¸ (PageUp¥¡¼)";
3973 static char MN_PGDOWN[] = "²¼¤Î¥Ú¡¼¥¸ (PageDown¥¡¼)";
3974 static char MN_TOP[] = "1¹ÔÌܤذÜÆ° (Home¥¡¼)";
3975 static char MN_BOTTOM[] = "ºÇ²¼¹Ô¤Ø°ÜÆ°(End¥¡¼)";
3977 static char MN_EDIT[] = "ÊÔ½¸";
3978 static char MN_CUT[] = "¥«¥Ã¥È";
3979 static char MN_COPY[] = "¥³¥Ô¡¼";
3980 static char MN_PASTE[] = "¥Ú¡¼¥¹¥È";
3981 static char MN_BLOCK[] = "ÁªÂòÈϰϤλØÄê";
3982 static char MN_KILL_LINE[] = "¹Ô¤Î»Ä¤ê¤òºï½ü";
3983 static char MN_DELETE_CHAR[] = "1ʸ»úºï½ü";
3984 static char MN_BACKSPACE[] = "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹";
3985 static char MN_RETURN[] = "²þ¹Ô";
3987 static char MN_SEARCH[] = "¸¡º÷";
3988 static char MN_SEARCH_STR[] = "ʸ»úÎó¤Ç¸¡º÷";
3989 static char MN_SEARCH_FORW[] = "Á°Êý¤ØºÆ¸¡º÷";
3990 static char MN_SEARCH_BACK[] = "¸åÊý¤ØºÆ¸¡º÷";
3991 static char MN_SEARCH_OBJ[] = "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷";
3992 static char MN_SEARCH_DESTROYED[] = "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷";
3994 static char MN_INSERT[] = "¿§¡¹ÁÞÆþ";
3995 static char MN_INSERT_OBJECT[] = "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ";
3996 static char MN_INSERT_DESTROYED[] = "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ";
3997 static char MN_INSERT_BLOCK[] = "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ";
3998 static char MN_INSERT_MACRO[] = "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ";
3999 static char MN_INSERT_KEYMAP[] = "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ";
4001 static char MN_COMMAND_LETTER[] = "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò";
4002 static char MN_CL_AUTOPICK[] = "¡Ö ¡× (¼«Æ°½¦¤¤)";
4003 static char MN_CL_DESTROY[] = "¡Ö!¡× (¼«Æ°Ç˲õ)";
4004 static char MN_CL_LEAVE[] = "¡Ö~¡× (ÊüÃÖ)";
4005 static char MN_CL_QUERY[] = "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)";
4006 static char MN_CL_NO_DISP[] = "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)";
4008 static char MN_ADJECTIVE_GEN[] = "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò";
4009 static char MN_RARE[] = "¥ì¥¢¤Ê (ÁõÈ÷)";
4010 static char MN_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿ (ÁõÈ÷)";
4012 static char MN_ADJECTIVE_SPECIAL[] = "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò";
4013 static char MN_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)";
4014 static char MN_MORE_DICE[] = "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)";
4015 static char MN_MORE_BONUS[] = "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)";
4016 static char MN_WANTED[] = "¾Þ¶â¼ó¤Î (»àÂÎ)";
4017 static char MN_UNIQUE[] = "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)";
4018 static char MN_HUMAN[] = "¿Í´Ö¤Î (»àÂÎ)";
4019 static char MN_UNREADABLE[] = "Æɤá¤Ê¤¤ (ËâË¡½ñ)";
4020 static char MN_REALM1[] = "Âè°ìÎΰè¤Î (ËâË¡½ñ)";
4021 static char MN_REALM2[] = "ÂèÆóÎΰè¤Î (ËâË¡½ñ)";
4022 static char MN_FIRST[] = "1ºýÌܤΠ(ËâË¡½ñ)";
4023 static char MN_SECOND[] = "2ºýÌܤΠ(ËâË¡½ñ)";
4024 static char MN_THIRD[] = "3ºýÌܤΠ(ËâË¡½ñ)";
4025 static char MN_FOURTH[] = "4ºýÌܤΠ(ËâË¡½ñ)";
4027 static char MN_NOUN[] = "̾»ì¤ÎÁªÂò";
4031 static char MN_QUIT[] = "Quit without save";
4032 static char MN_SAVEQUIT[] = "Save & Quit";
4033 static char MN_REVERT[] = "Revert all changes";
4034 static char MN_HELP[] = "Help";
4036 static char MN_MOVE[] = "Move cursor";
4037 static char MN_LEFT[] = "Left (Left Arrow key)";
4038 static char MN_DOWN[] = "Down (Down Arrow key)";
4039 static char MN_UP[] = "Up (Up Arrow key)";
4040 static char MN_RIGHT[] = "Right (Right Arrow key)";
4041 static char MN_BOL[] = "Beggining of line";
4042 static char MN_EOL[] = "End of line";
4043 static char MN_PGUP[] = "Page up (PageUp key)";
4044 static char MN_PGDOWN[] = "Page down(PageDown key)";
4045 static char MN_TOP[] = "Top (Home key)";
4046 static char MN_BOTTOM[] = "Bottom (End key)";
4048 static char MN_EDIT[] = "Edit";
4049 static char MN_CUT[] = "Cut";
4050 static char MN_COPY[] = "Copy";
4051 static char MN_PASTE[] = "Paste";
4052 static char MN_BLOCK[] = "Select block";
4053 static char MN_KILL_LINE[] = "Kill rest of line";
4054 static char MN_DELETE_CHAR[] = "Delete character";
4055 static char MN_BACKSPACE[] = "Backspace";
4056 static char MN_RETURN[] = "Return";
4058 static char MN_SEARCH[] = "Search";
4059 static char MN_SEARCH_STR[] = "Search by string";
4060 static char MN_SEARCH_FORW[] = "Search forward";
4061 static char MN_SEARCH_BACK[] = "Search backward";
4062 static char MN_SEARCH_OBJ[] = "Search by inventory object";
4063 static char MN_SEARCH_DESTROYED[] = "Search by destroyed object";
4065 static char MN_INSERT[] = "Insert...";
4066 static char MN_INSERT_OBJECT[] = "Insert name of choosen object";
4067 static char MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
4068 static char MN_INSERT_BLOCK[] = "Insert conditional block";
4069 static char MN_INSERT_MACRO[] = "Insert a macro definition";
4070 static char MN_INSERT_KEYMAP[] = "Insert a keymap definition";
4072 static char MN_COMMAND_LETTER[] = "Command letter";
4073 static char MN_CL_AUTOPICK[] = "' ' (Auto pick)";
4074 static char MN_CL_DESTROY[] = "'!' (Auto destroy)";
4075 static char MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
4076 static char MN_CL_QUERY[] = "';' (Query to pick up)";
4077 static char MN_CL_NO_DISP[] = "'(' (No display on the large map)";
4079 static char MN_ADJECTIVE_GEN[] = "Adjective (general)";
4080 static char MN_RARE[] = "rare (equipments)";
4081 static char MN_COMMON[] = "common (equipments)";
4083 static char MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
4084 static char MN_BOOSTED[] = "dice boosted (weapons)";
4085 static char MN_MORE_DICE[] = "more than # dice (weapons)";
4086 static char MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
4087 static char MN_WANTED[] = "wanted (corpse)";
4088 static char MN_UNIQUE[] = "unique (corpse)";
4089 static char MN_HUMAN[] = "human (corpse)";
4090 static char MN_UNREADABLE[] = "unreadable (spellbooks)";
4091 static char MN_REALM1[] = "realm1 (spellbooks)";
4092 static char MN_REALM2[] = "realm2 (spellbooks)";
4093 static char MN_FIRST[] = "first (spellbooks)";
4094 static char MN_SECOND[] = "second (spellbooks)";
4095 static char MN_THIRD[] = "third (spellbooks)";
4096 static char MN_FOURTH[] = "fourth (spellbooks)";
4098 static char MN_NOUN[] = "Keywords (noun)";
4108 } command_menu_type;
4111 command_menu_type menu_data[] =
4113 {MN_HELP, 0, -1, EC_HELP},
4114 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4115 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4116 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4118 {MN_EDIT, 0, -1, -1},
4119 {MN_CUT, 1, KTRL('x'), EC_CUT},
4120 {MN_COPY, 1, KTRL('c'), EC_COPY},
4121 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4122 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4123 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4124 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4125 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4126 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4127 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4129 {MN_SEARCH, 0, -1, -1},
4130 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4131 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4132 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4133 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4134 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4136 {MN_MOVE, 0, -1, -1},
4137 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4138 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4139 {MN_UP, 1, KTRL('p'), EC_UP},
4140 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4141 {MN_BOL, 1, KTRL('a'), EC_BOL},
4142 {MN_EOL, 1, KTRL('e'), EC_EOL},
4143 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4144 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4145 {MN_TOP, 1, KTRL('t'), EC_TOP},
4146 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4148 {MN_INSERT, 0, -1, -1},
4149 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4150 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4151 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4152 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4153 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4155 {MN_ADJECTIVE_GEN, 0, -1, -1},
4156 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4157 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4158 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4159 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4160 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4161 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4162 {KEY_EGO, 1, -1, EC_OK_EGO},
4163 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4164 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4165 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4166 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4167 {MN_RARE, 1, -1, EC_OK_RARE},
4168 {MN_COMMON, 1, -1, EC_OK_COMMON},
4170 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4171 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4172 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4173 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4174 {MN_WANTED, 1, -1, EC_OK_WANTED},
4175 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4176 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4177 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4178 {MN_REALM1, 1, -1, EC_OK_REALM1},
4179 {MN_REALM2, 1, -1, EC_OK_REALM2},
4180 {MN_FIRST, 1, -1, EC_OK_FIRST},
4181 {MN_SECOND, 1, -1, EC_OK_SECOND},
4182 {MN_THIRD, 1, -1, EC_OK_THIRD},
4183 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4185 {MN_NOUN, 0, -1, -1},
4186 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4187 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4188 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4189 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4190 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4191 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4192 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4193 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4194 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4195 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4196 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4197 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4198 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4199 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4200 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4201 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4202 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4203 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4205 {MN_COMMAND_LETTER, 0, -1, -1},
4206 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4207 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4208 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4209 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4210 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4212 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4219 * Find a command by 'key'.
4221 static int get_com_id(char key)
4225 for (i = 0; menu_data[i].name; i++)
4227 if (menu_data[i].key == key)
4229 return menu_data[i].com_id;
4238 * Display the menu, and get a command
4240 static int do_command_menu(int level, int start)
4245 int col0 = 5 + level*7;
4246 int row0 = 1 + level*3;
4248 int menu_id_list[26];
4250 char linestr[MAX_LINELEN];
4252 /* Get max length */
4254 for (i = start; menu_data[i].level >= level; i++)
4258 /* Ignore lower level sub menus */
4259 if (menu_data[i].level > level) continue;
4261 len = strlen(menu_data[i].name);
4262 if (len > max_len) max_len = len;
4264 menu_id_list[menu_key] = i;
4268 while (menu_key < 26)
4270 menu_id_list[menu_key] = -1;
4274 /* Extra space for displaying menu key and command key */
4275 max_menu_wid = max_len + 3 + 3;
4277 /* Prepare box line */
4279 strcat(linestr, "+");
4280 for (i = 0; i < max_menu_wid + 2; i++)
4282 strcat(linestr, "-");
4284 strcat(linestr, "+");
4294 int row1 = row0 + 1;
4297 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4299 /* Draw menu items */
4301 for (i = start; menu_data[i].level >= level; i++)
4303 char com_key_str[3];
4306 /* Ignore lower level sub menus */
4307 if (menu_data[i].level > level) continue;
4309 if (menu_data[i].com_id == -1)
4312 strcpy(com_key_str, "¢§");
4314 strcpy(com_key_str, ">");
4317 else if (menu_data[i].key != -1)
4319 com_key_str[0] = '^';
4320 com_key_str[1] = menu_data[i].key + '@';
4321 com_key_str[2] = '\0';
4325 com_key_str[0] = '\0';
4328 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4330 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4335 /* Draw bottom line */
4336 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4338 /* The menu was shown */
4342 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
4344 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
4348 if (key == ESCAPE) return 0;
4350 if ('a' <= key && key <= 'z')
4352 menu_id = menu_id_list[key - 'a'];
4356 com_id = menu_data[menu_id].com_id;
4360 com_id = do_command_menu(level + 1, menu_id + 1);
4362 if (com_id) return com_id;
4374 com_id = get_com_id(key);
4375 if (com_id) return com_id;
4382 static chain_str_type *new_chain_str(cptr str)
4384 chain_str_type *chain;
4386 size_t len = strlen(str);
4388 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4390 strcpy(chain->s, str);
4397 static void kill_yank_chain(text_body_type *tb)
4399 chain_str_type *chain = tb->yank;
4401 tb->yank_eol = TRUE;
4405 chain_str_type *next = chain->next;
4406 size_t len = strlen(chain->s);
4408 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4415 static void add_str_to_yank(text_body_type *tb, cptr str)
4417 chain_str_type *chain;
4419 tb->yank_eol = FALSE;
4421 if (NULL == tb->yank)
4423 tb->yank = new_chain_str(str);
4433 chain->next = new_chain_str(str);
4438 chain = chain->next;
4444 * Do work for the copy editor-command
4446 static void copy_text_to_yank(text_body_type *tb)
4448 int len = strlen(tb->lines_list[tb->cy]);
4450 /* Correct cursor location */
4451 if (tb->cx > len) tb->cx = len;
4453 /* Use single line? */
4456 /* Select a single line */
4462 /* Kill old yank buffer */
4463 kill_yank_chain(tb);
4466 /* Single line case */
4467 if (tb->my == tb->cy)
4470 char buf[MAX_LINELEN];
4471 int bx1 = MIN(tb->mx, tb->cx);
4472 int bx2 = MAX(tb->mx, tb->cx);
4474 /* Correct fake cursor position */
4475 if (bx2 > len) bx2 = len;
4477 /* Whole part of this line is selected */
4478 if (bx1 == 0 && bx2 == len)
4480 /* Copy this line */
4481 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4483 /* Add end of line to the buffer */
4484 add_str_to_yank(tb, "");
4487 /* Segment of this line is selected */
4490 for (i = 0; i < bx2 - bx1; i++)
4492 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4496 /* Copy this segment of line */
4497 add_str_to_yank(tb, buf);
4501 /* Multiple lines case */
4502 else /* if (tb->my != tb->cy) */
4506 int by1 = MIN(tb->my, tb->cy);
4507 int by2 = MAX(tb->my, tb->cy);
4510 for (y = by1; y <= by2; y++)
4512 /* Copy this line */
4513 add_str_to_yank(tb, tb->lines_list[y]);
4516 /* Add final end of line to the buffer */
4517 add_str_to_yank(tb, "");
4520 /* Disable selection */
4524 tb->dirty_flags |= DIRTY_ALL;
4528 #define DESCRIPT_HGT 3
4533 static void draw_text_editor(text_body_type *tb)
4536 int by1 = 0, by2 = 0;
4539 Term_get_size(&tb->wid, &tb->hgt);
4542 * Top line (-1), description line (-3), separator (-1)
4545 tb->hgt -= 2 + DESCRIPT_HGT;
4548 /* Don't let cursor at second byte of kanji */
4549 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4550 if (iskanji(tb->lines_list[tb->cy][i]))
4556 * Move to a correct position in the
4559 if (i & 1) tb->cx--;
4566 /* Scroll if necessary */
4567 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4568 tb->upper = tb->cy - (tb->hgt)/2;
4571 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4572 tb->left = tb->cx - (tb->wid)*2/3;
4576 /* Redraw whole window after resize */
4577 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4578 tb->dirty_flags |= DIRTY_SCREEN;
4580 /* Redraw all text after scroll */
4581 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4582 tb->dirty_flags |= DIRTY_ALL;
4585 if (tb->dirty_flags & DIRTY_SCREEN)
4587 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4593 /* Redraw mode line */
4594 if (tb->dirty_flags & DIRTY_MODE)
4596 char buf[MAX_LINELEN];
4598 int sepa_length = tb->wid;
4601 for (i = 0; i < sepa_length; i++)
4605 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4608 if (tb->dirty_flags & DIRTY_EXPRESSION)
4613 for (y = 0; tb->lines_list[y]; y++)
4617 cptr s = tb->lines_list[y];
4621 /* Update this line's state */
4622 tb->states[y] = state;
4624 if (*s++ != '?') continue;
4625 if (*s++ != ':') continue;
4627 /* Lines below this line are auto-registered */
4628 if (streq(s, "$AUTOREGISTER"))
4629 state |= LSTAT_AUTOREGISTER;
4632 ss = (char *)string_make(s);
4635 /* Parse the expr */
4636 v = process_pref_file_expr(&ss, &f);
4639 if (streq(v, "0")) state |= LSTAT_BYPASS;
4640 else state &= ~LSTAT_BYPASS;
4642 /* Cannot use string_free() because the string was "destroyed" */
4643 C_KILL(s_keep, s_len + 1, char);
4645 /* Re-update this line's state */
4646 tb->states[y] = state | LSTAT_EXPRESSION;
4649 tb->dirty_flags |= DIRTY_ALL;
4654 tb->dirty_flags |= DIRTY_ALL;
4656 by1 = MIN(tb->my, tb->cy);
4657 by2 = MAX(tb->my, tb->cy);
4660 /* Dump up to tb->hgt lines of messages */
4661 for (i = 0; i < tb->hgt; i++)
4667 int y = tb->upper+i;
4669 /* clean or dirty? */
4670 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4673 msg = tb->lines_list[y];
4676 /* Apply horizontal scroll */
4677 for (j = 0; *msg; msg++, j++)
4679 if (j == tb->left) break;
4695 Term_erase(0, i + 1, tb->wid);
4697 if (tb->states[y] & LSTAT_AUTOREGISTER)
4699 /* Warning color -- These lines will be deleted later */
4704 /* Bypassed line will be displayed by darker color */
4705 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4706 else color = TERM_WHITE;
4709 /* No mark or Out of mark */
4710 if (!tb->mark || (y < by1 || by2 < y))
4712 /* Dump the messages, bottom to top */
4713 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4716 /* Multiple lines selected */
4717 else if (by1 != by2)
4719 /* Dump the messages, bottom to top */
4720 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4723 /* Single line selected */
4726 int x0 = leftcol + tb->left;
4727 int len = strlen(tb->lines_list[tb->cy]);
4728 int bx1 = MIN(tb->mx, tb->cx);
4729 int bx2 = MAX(tb->mx, tb->cx);
4731 /* Correct cursor location */
4732 if (bx2 > len) bx2 = len;
4734 Term_gotoxy(leftcol, i + 1);
4735 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4736 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4737 Term_addstr(-1, color, msg + (bx2 - x0));
4741 for (; i < tb->hgt; i++)
4744 Term_erase(0, i + 1, tb->wid);
4747 /* Display information when updated */
4748 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4750 autopick_type an_entry, *entry = &an_entry;
4751 cptr str1 = NULL, str2 = NULL;
4754 /* Clear information line */
4755 for (i = 0; i < DESCRIPT_HGT; i++)
4758 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4761 /* Display information */
4762 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4765 str1 = format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str);
4767 str1 = format("Pattern not found: %s", tb->search_str);
4770 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4773 str1 = format("̵¸ú¾õÂ֤ιԤò¥¹¥¥Ã¥×¤·¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4775 str1 = format("Some inactive lines are skipped. (Searching %s)", tb->search_str);
4778 else if (tb->dirty_flags & DIRTY_INACTIVE)
4781 str1 = format("̵¸ú¾õÂ֤ιԤÀ¤±¤¬¸«ÉÕ¤«¤ê¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4783 str1 = format("Found only an inactive line. (Searching %s)", tb->search_str);
4786 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4789 str1 = "¸¡º÷¤¹¤ë¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó(^S ¤Ç¸¡º÷)¡£";
4791 str1 = "No pattern to search. (Press ^S to search.)";
4794 else if (tb->lines_list[tb->cy][0] == '#')
4797 str1 = "¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£";
4799 str1 = "This line is a comment.";
4802 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4804 switch(tb->lines_list[tb->cy][0])
4808 str1 = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4810 str1 = "This line is a Conditional Expression.";
4816 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4818 str1 = "This line defines a Macro action.";
4823 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4825 str1 = "This line defines a Macro trigger key.";
4830 str1 = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4832 str1 = "This line defines a Keymap.";
4837 switch(tb->lines_list[tb->cy][0])
4840 if (tb->states[tb->cy] & LSTAT_BYPASS)
4843 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4845 str2 = "The expression is 'False'(=0) currently.";
4851 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4853 str2 = "The expression is 'True'(=1) currently.";
4859 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4862 str2 = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4864 str2 = "This line will be delete later.";
4868 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4871 str2 = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4873 str2 = "This line is bypassed currently.";
4880 /* Get description of an autopicker preference line */
4881 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4883 char buf[MAX_LINELEN];
4884 char temp[MAX_LINELEN];
4887 describe_autopick(buf, entry);
4889 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4892 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4894 strcat(buf, " This line will be delete later.");
4898 if (tb->states[tb->cy] & LSTAT_BYPASS)
4901 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4903 strcat(buf, " This line is bypassed currently.");
4907 roff_to_buf(buf, 81, temp, sizeof(temp));
4909 for (i = 0; i < 3; i++)
4915 prt(t, tb->hgt +1 + 1 + i, 0);
4919 autopick_free_entry(entry);
4922 /* Draw the first line */
4923 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4925 /* Draw the second line */
4926 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4932 * Kill segment of a line
4934 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4936 char buf[MAX_LINELEN];
4937 cptr s = tb->lines_list[y];
4941 /* Kill whole line? */
4942 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4946 string_free(tb->lines_list[y]);
4948 /* Shift lines up */
4949 for (i = y; tb->lines_list[i+1]; i++)
4950 tb->lines_list[i] = tb->lines_list[i+1];
4951 tb->lines_list[i] = NULL;
4953 /* Expressions need re-evaluation */
4954 tb->dirty_flags |= DIRTY_EXPRESSION;
4960 if (x0 == x1) return;
4962 /* Before the segment */
4963 for (x = 0; x < x0; x++)
4966 /* After the segment */
4967 for (x = x1; s[x]; x++)
4973 string_free(tb->lines_list[y]);
4974 tb->lines_list[y] = string_make(buf);
4976 /* Expressions may need re-evaluation */
4977 check_expression_line(tb, y);
4979 /* Text is changed */
4985 * Get a trigger key and insert ASCII string for the trigger
4987 static bool insert_macro_line(text_body_type *tb)
4996 /* Do not process macros */
5002 /* Read the pattern */
5008 /* Do not process macros */
5011 /* Do not wait for keys */
5014 /* Attempt to read a key */
5024 /* Convert the trigger */
5025 ascii_to_text(tmp, buf);
5028 if(!tmp[0]) return FALSE;
5032 /* Insert preference string */
5033 insert_return_code(tb);
5034 string_free(tb->lines_list[tb->cy]);
5035 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
5037 /* Acquire action */
5038 i = macro_find_exact(buf);
5042 /* Nothing defined */
5047 /* Analyze the current action */
5048 ascii_to_text(tmp, macro__act[i]);
5051 /* Insert blank action preference line */
5052 insert_return_code(tb);
5053 string_free(tb->lines_list[tb->cy]);
5054 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
5061 * Get a command key and insert ASCII string for the key
5063 static bool insert_keymap_line(text_body_type *tb)
5071 if (rogue_like_commands)
5073 mode = KEYMAP_MODE_ROGUE;
5079 mode = KEYMAP_MODE_ORIG;
5092 /* Convert the trigger */
5093 ascii_to_text(tmp, buf);
5096 if(!tmp[0]) return FALSE;
5100 /* Insert preference string */
5101 insert_return_code(tb);
5102 string_free(tb->lines_list[tb->cy]);
5103 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
5105 /* Look up the keymap */
5106 act = keymap_act[mode][(byte)(buf[0])];
5110 /* Analyze the current action */
5111 ascii_to_text(tmp, act);
5115 /* No keymap defined -- Use trigger key itself as a default */
5117 /* Nothing to do (use tmp) */
5120 /* Insert blank action preference line */
5121 insert_return_code(tb);
5122 string_free(tb->lines_list[tb->cy]);
5123 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
5130 * Execute a single editor command
5132 static bool do_editor_command(text_body_type *tb, int com_id)
5140 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
5142 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
5145 return QUIT_WITHOUT_SAVE;
5148 return QUIT_AND_SAVE;
5151 /* Revert to original */
5153 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
5155 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
5158 free_text_lines(tb->lines_list);
5159 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5160 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5161 tb->cx = tb->cy = 0;
5164 /* Text is not changed */
5165 tb->changed = FALSE;
5169 /* Peruse the main help file */
5171 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
5173 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
5176 tb->dirty_flags |= DIRTY_SCREEN;
5181 /* Split a line or insert end of line */
5183 /* Ignore selection */
5189 tb->dirty_flags |= DIRTY_ALL;
5192 insert_return_code(tb);
5197 tb->dirty_flags |= DIRTY_ALL;
5210 len = strlen(tb->lines_list[tb->cy]);
5211 if (len < tb->cx) tb->cx = len;
5214 /* Don't let cursor at second byte of kanji */
5215 for (i = 0; tb->lines_list[tb->cy][i]; i++)
5217 if (iskanji(tb->lines_list[tb->cy][i]))
5222 /* Move to the left */
5230 else if (tb->cy > 0)
5233 tb->cx = strlen(tb->lines_list[tb->cy]);
5240 /* Is this the last line? */
5241 if (!tb->lines_list[tb->cy + 1])
5243 /* Add one more empty line if possible */
5244 if (!add_empty_line(tb)) break;
5254 if (tb->cy > 0) tb->cy--;
5263 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5266 len = strlen(tb->lines_list[tb->cy]);
5269 /* Correct the cursor position */
5272 /* Is this the last line? */
5273 if (!tb->lines_list[tb->cy + 1])
5275 /* Add one more empty line if possible */
5276 if (!add_empty_line(tb)) break;
5279 /* Move to the beginning of next line */
5287 /* Beginning of line */
5293 tb->cx = strlen(tb->lines_list[tb->cy]);
5297 while (0 < tb->cy && tb->upper <= tb->cy)
5299 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5305 while (tb->cy < tb->upper + tb->hgt)
5307 /* Is this the last line? */
5308 if (!tb->lines_list[tb->cy + 1])
5310 /* Add one more empty line if possible */
5311 if (!add_empty_line(tb)) break;
5327 /* Is this the last line? */
5328 if (!tb->lines_list[tb->cy + 1])
5330 /* Add one more empty line if possible */
5331 if (!add_empty_line(tb)) break;
5337 /* Always at the biginning of the last line */
5344 /* Copy the text first */
5345 copy_text_to_yank(tb);
5347 /* Single line case */
5348 if (tb->my == tb->cy)
5350 int bx1 = MIN(tb->mx, tb->cx);
5351 int bx2 = MAX(tb->mx, tb->cx);
5352 int len = strlen(tb->lines_list[tb->cy]);
5354 /* Correct fake cursor position */
5355 if (bx2 > len) bx2 = len;
5357 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5359 /* New cursor position */
5363 /* Multiple lines case */
5364 else /* if (tb->my != tb->cy) */
5368 int by1 = MIN(tb->my, tb->cy);
5369 int by2 = MAX(tb->my, tb->cy);
5371 /* Kill lines in reverse order */
5372 for (y = by2; y >= by1; y--)
5374 int len = strlen(tb->lines_list[y]);
5376 kill_line_segment(tb, y, 0, len, TRUE);
5379 /* New cursor position */
5385 /* Disable selection */
5389 tb->dirty_flags |= DIRTY_ALL;
5391 /* Text is changed */
5398 copy_text_to_yank(tb);
5401 * Move cursor position to the end of the selection
5403 * Pressing ^C ^V correctly duplicates the selection.
5405 if (tb->my == tb->cy)
5407 tb->cx = MAX(tb->cx, tb->mx);
5410 * When whole line is selected, the end of
5411 * line code is also copyed.
5413 if (!tb->lines_list[tb->cy][tb->cx])
5415 /* Is this the last line? */
5416 if (!tb->lines_list[tb->cy + 1])
5418 /* Add one more empty line if possible */
5419 if (!add_empty_line(tb)) break;
5422 /* Go to the beginning of next line */
5429 tb->cy = MAX(tb->cy, tb->my);
5431 /* Is this the last line? */
5432 if (!tb->lines_list[tb->cy + 1])
5434 /* Add one more empty line if possible */
5435 if (!add_empty_line(tb)) break;
5446 /* Paste killed text */
5448 chain_str_type *chain = tb->yank;
5449 int len = strlen(tb->lines_list[tb->cy]);
5451 /* Nothing to do? */
5454 /* Correct cursor location */
5455 if (tb->cx > len) tb->cx = len;
5457 /* Ignore selection */
5463 tb->dirty_flags |= DIRTY_ALL;
5469 cptr yank_str = chain->s;
5471 char buf[MAX_LINELEN];
5473 char rest[MAX_LINELEN], *rest_ptr = rest;
5475 /* Save preceding string */
5476 for(i = 0; i < tb->cx; i++)
5477 buf[i] = tb->lines_list[tb->cy][i];
5479 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5481 /* Paste yank buffer */
5482 while (*yank_str && i < MAX_LINELEN-1)
5484 buf[i++] = *yank_str++;
5490 chain = chain->next;
5492 if (chain || tb->yank_eol)
5494 /* There is an end of line between chain nodes */
5496 insert_return_code(tb);
5498 /* Replace this line with new one */
5499 string_free(tb->lines_list[tb->cy]);
5500 tb->lines_list[tb->cy] = string_make(buf);
5502 /* Move to next line */
5509 /* Final line doesn't have end of line */
5511 tb->cx = strlen(buf);
5513 /* Rest of original line */
5514 while (*rest_ptr && i < MAX_LINELEN-1)
5516 buf[i++] = *rest_ptr++;
5522 /* Replace this line with new one */
5523 string_free(tb->lines_list[tb->cy]);
5524 tb->lines_list[tb->cy] = string_make(buf);
5531 tb->dirty_flags |= DIRTY_ALL;
5533 /* Expressions need re-evaluation */
5534 tb->dirty_flags |= DIRTY_EXPRESSION;
5536 /* Text is changed */
5545 /* Disable the selection */
5549 tb->dirty_flags |= DIRTY_ALL;
5553 tb->mark = MARK_MARK;
5555 /* Repeating this command swaps cursor position */
5556 if (com_id == tb->old_com_id)
5568 tb->dirty_flags |= DIRTY_ALL;
5572 int len = strlen(tb->lines_list[tb->cy]);
5574 /* Mark the point 1 */
5578 /* Correct cursor location */
5579 if (tb->cx > len) tb->mx = len;
5586 /* Kill rest of line */
5588 int len = strlen(tb->lines_list[tb->cy]);
5590 /* Correct cursor location */
5591 if (tb->cx > len) tb->cx = len;
5593 /* Ignore selection */
5599 tb->dirty_flags |= DIRTY_ALL;
5602 /* Append only if this command is repeated. */
5603 if (tb->old_com_id != com_id)
5605 kill_yank_chain(tb);
5609 /* Really deleted some text */
5612 /* Add deleted string to yank buffer */
5613 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5615 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5618 tb->dirty_line = tb->cy;
5620 /* Leave end of line character */
5624 /* Cut the end of line character only */
5625 if (tb->yank_eol) add_str_to_yank(tb, "");
5627 /* Cut end of line */
5628 tb->yank_eol = TRUE;
5630 do_editor_command(tb, EC_DELETE_CHAR);
5634 case EC_DELETE_CHAR:
5636 /* DELETE == go forward + BACK SPACE */
5640 /* Ignore selection */
5646 tb->dirty_flags |= DIRTY_ALL;
5650 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5654 /* Pass through the end of line to next line */
5655 len = strlen(tb->lines_list[tb->cy]);
5658 if (tb->lines_list[tb->cy + 1])
5670 do_editor_command(tb, EC_BACKSPACE);
5679 char buf[MAX_LINELEN];
5681 /* Ignore selection */
5687 tb->dirty_flags |= DIRTY_ALL;
5690 /* Move to correct collumn */
5691 len = strlen(tb->lines_list[tb->cy]);
5692 if (len < tb->cx) tb->cx = len;
5696 /* delete a return code and union two lines */
5697 if (tb->cy == 0) break;
5698 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5699 strcpy(buf, tb->lines_list[tb->cy-1]);
5700 strcat(buf, tb->lines_list[tb->cy]);
5701 string_free(tb->lines_list[tb->cy-1]);
5702 string_free(tb->lines_list[tb->cy]);
5703 tb->lines_list[tb->cy-1] = string_make(buf);
5705 for (i = tb->cy; tb->lines_list[i+1]; i++)
5706 tb->lines_list[i] = tb->lines_list[i+1];
5708 tb->lines_list[i] = NULL;
5712 tb->dirty_flags |= DIRTY_ALL;
5714 /* Expressions need re-evaluation */
5715 tb->dirty_flags |= DIRTY_EXPRESSION;
5717 /* Text is changed */
5723 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5727 if (iskanji(tb->lines_list[tb->cy][i]))
5728 buf[j++] = tb->lines_list[tb->cy][i++];
5730 buf[j++] = tb->lines_list[tb->cy][i];
5737 for (; tb->lines_list[tb->cy][i]; i++)
5738 buf[j++] = tb->lines_list[tb->cy][i];
5740 string_free(tb->lines_list[tb->cy]);
5741 tb->lines_list[tb->cy] = string_make(buf);
5744 tb->dirty_line = tb->cy;
5746 /* Expressions may need re-evaluation */
5747 check_expression_line(tb, tb->cy);
5749 /* Text is changed */
5759 /* Become dirty because of item/equip menu */
5760 tb->dirty_flags |= DIRTY_SCREEN;
5762 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5764 if (!search_dir) break;
5766 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5767 else do_editor_command(tb, EC_SEARCH_BACK);
5771 case EC_SEARCH_FORW:
5772 if (tb->search_o_ptr)
5774 search_for_object(tb, tb->search_o_ptr, TRUE);
5776 else if (tb->search_str && tb->search_str[0])
5778 search_for_string(tb, tb->search_str, TRUE);
5782 tb->dirty_flags |= DIRTY_NO_SEARCH;
5786 case EC_SEARCH_BACK:
5787 if (tb->search_o_ptr)
5789 search_for_object(tb, tb->search_o_ptr, FALSE);
5791 else if (tb->search_str && tb->search_str[0])
5793 search_for_string(tb, tb->search_str, FALSE);
5797 tb->dirty_flags |= DIRTY_NO_SEARCH;
5802 /* Become dirty because of item/equip menu */
5803 tb->dirty_flags |= DIRTY_SCREEN;
5805 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5807 do_editor_command(tb, EC_SEARCH_FORW);
5810 case EC_SEARCH_DESTROYED:
5811 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5813 /* There is no object to search */
5814 tb->dirty_flags |= DIRTY_NO_SEARCH;
5819 do_editor_command(tb, EC_SEARCH_FORW);
5822 case EC_INSERT_OBJECT:
5824 /* Insert choosen item name */
5826 autopick_type an_entry, *entry = &an_entry;
5828 if (!entry_from_choosed_object(entry))
5830 /* Now dirty because of item/equip menu */
5831 tb->dirty_flags |= DIRTY_SCREEN;
5836 insert_return_code(tb);
5837 string_free(tb->lines_list[tb->cy]);
5838 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5840 /* Now dirty because of item/equip menu */
5841 tb->dirty_flags |= DIRTY_SCREEN;
5846 case EC_INSERT_DESTROYED:
5847 /* Insert a name of last destroyed item */
5848 if (tb->last_destroyed)
5851 insert_return_code(tb);
5852 string_free(tb->lines_list[tb->cy]);
5853 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5856 tb->dirty_flags |= DIRTY_ALL;
5858 /* Text is changed */
5863 case EC_INSERT_BLOCK:
5865 /* Insert a conditinal expression line */
5866 char expression[80];
5868 /* Conditional Expression for Class and Race */
5869 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5871 rp_ptr->E_title, cp_ptr->E_title,
5873 rp_ptr->title, cp_ptr->title,
5879 insert_return_code(tb);
5880 string_free(tb->lines_list[tb->cy]);
5881 tb->lines_list[tb->cy] = string_make(expression);
5883 insert_return_code(tb);
5884 string_free(tb->lines_list[tb->cy]);
5885 tb->lines_list[tb->cy] = string_make("?:1");
5888 tb->dirty_flags |= DIRTY_ALL;
5890 /* Text is changed */
5896 case EC_INSERT_MACRO:
5897 /* Draw_everythig (delete menu) */
5898 draw_text_editor(tb);
5901 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5905 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5907 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5909 if (insert_macro_line(tb))
5911 /* Prepare to input action */
5915 tb->dirty_flags |= DIRTY_ALL;
5917 /* Text is changed */
5923 case EC_INSERT_KEYMAP:
5924 /* Draw_everythig (delete menu) */
5925 draw_text_editor(tb);
5928 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5932 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)));
5934 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)));
5937 if (insert_keymap_line(tb))
5939 /* Prepare to input action */
5943 tb->dirty_flags |= DIRTY_ALL;
5945 /* Text is changed */
5950 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5951 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5952 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5953 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5954 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5956 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5957 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5958 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5959 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5960 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5961 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5962 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5963 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5964 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5965 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5966 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5967 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5968 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5969 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5970 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5971 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5972 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5973 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5974 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5975 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5976 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5977 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5978 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5979 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5980 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5981 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5982 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5983 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5984 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5985 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5986 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5987 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5988 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5989 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5990 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5991 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5992 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5993 case EC_OK_UNREADABLE:
5994 toggle_keyword(tb, FLG_UNREADABLE);
5995 add_keyword(tb, FLG_SPELLBOOKS);
5998 toggle_keyword(tb, FLG_REALM1);
5999 add_keyword(tb, FLG_SPELLBOOKS);
6002 toggle_keyword(tb, FLG_REALM2);
6003 add_keyword(tb, FLG_SPELLBOOKS);
6006 toggle_keyword(tb, FLG_FIRST);
6007 add_keyword(tb, FLG_SPELLBOOKS);
6010 toggle_keyword(tb, FLG_SECOND);
6011 add_keyword(tb, FLG_SPELLBOOKS);
6014 toggle_keyword(tb, FLG_THIRD);
6015 add_keyword(tb, FLG_SPELLBOOKS);
6018 toggle_keyword(tb, FLG_FOURTH);
6019 add_keyword(tb, FLG_SPELLBOOKS);
6023 /* Save old command */
6024 tb->old_com_id = com_id;
6031 * Insert single letter at cursor position.
6033 static void insert_single_letter(text_body_type *tb, int key)
6036 char buf[MAX_LINELEN];
6038 /* Save preceding string */
6039 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
6040 buf[j++] = tb->lines_list[tb->cy][i];
6042 /* Add a character */
6050 if (j+2 < MAX_LINELEN)
6062 if (j+1 < MAX_LINELEN)
6068 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
6069 buf[j++] = tb->lines_list[tb->cy][i];
6072 /* Replace current line with new line */
6073 string_free(tb->lines_list[tb->cy]);
6074 tb->lines_list[tb->cy] = string_make(buf);
6076 /* Move to correct collumn */
6077 len = strlen(tb->lines_list[tb->cy]);
6078 if (len < tb->cx) tb->cx = len;
6081 tb->dirty_line = tb->cy;
6083 /* Expressions may need re-evaluation */
6084 check_expression_line(tb, tb->cy);
6086 /* Text is changed */
6092 * Check special key code and get a movement command id
6094 static int analyze_move_key(text_body_type *tb, int skey)
6098 /* Not a special key */
6099 if (!(skey & SKEY_MASK)) return 0;
6101 /* Convert from a special key code to an editor command */
6102 switch(skey & ~SKEY_MOD_MASK)
6104 case SKEY_DOWN: com_id = EC_DOWN; break;
6105 case SKEY_LEFT: com_id = EC_LEFT; break;
6106 case SKEY_RIGHT: com_id = EC_RIGHT; break;
6107 case SKEY_UP: com_id = EC_UP; break;
6108 case SKEY_PGUP: com_id = EC_PGUP; break;
6109 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
6110 case SKEY_TOP: com_id = EC_TOP; break;
6111 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
6114 /* Not a special movement key */
6118 /* Without shift modifier */
6119 if (!(skey & SKEY_MOD_SHIFT))
6122 * Un-shifted cursor keys cancells
6123 * selection created by shift+cursor.
6125 if (tb->mark & MARK_BY_SHIFT)
6130 tb->dirty_flags |= DIRTY_ALL;
6134 /* With shift modifier */
6137 /* Start selection by shift + cursor keys */
6140 int len = strlen(tb->lines_list[tb->cy]);
6142 tb->mark = MARK_MARK | MARK_BY_SHIFT;
6146 /* Correct cursor location */
6147 if (tb->cx > len) tb->mx = len;
6149 /* Need to redraw text */
6150 if (com_id == EC_UP || com_id == EC_DOWN)
6152 /* Redraw all text */
6153 tb->dirty_flags |= DIRTY_ALL;
6157 tb->dirty_line = tb->cy;
6166 * In-game editor of Object Auto-picker/Destoryer
6168 void do_cmd_edit_autopick(void)
6170 static int cx_save = 0;
6171 static int cy_save = 0;
6173 text_body_type text_body, *tb = &text_body;
6175 autopick_type an_entry, *entry = &an_entry;
6176 char buf[MAX_LINELEN];
6181 static s32b old_autosave_turn = 0L;
6184 tb->changed = FALSE;
6187 tb->upper = tb->left = 0;
6189 tb->mx = tb->my = 0;
6190 tb->old_cy = tb->old_upper = tb->old_left = -1;
6191 tb->old_wid = tb->old_hgt = -1;
6195 tb->search_o_ptr = NULL;
6196 tb->search_str = NULL;
6197 tb->last_destroyed = NULL;
6198 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6199 tb->dirty_line = -1;
6200 tb->filename_mode = PT_DEFAULT;
6202 if (turn < old_autosave_turn)
6204 while (old_autosave_turn > turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
6208 if (turn > old_autosave_turn + 100L)
6210 do_cmd_save_game(TRUE);
6211 old_autosave_turn = turn;
6214 /* HACK -- Reset start_time to stop counting playtime while edit */
6217 /* Free old entries */
6220 /* Command Description of the 'Last Destroyed Item' */
6221 if (autopick_last_destroyed_object.k_idx)
6223 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6224 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6227 /* Read or initialize whole text */
6228 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6230 /* Reset cursor position if needed */
6231 for (i = 0; i < tb->cy; i++)
6233 if (!tb->lines_list[i])
6235 tb->cy = tb->cx = 0;
6240 /* Save the screen */
6243 /* Process requests until done */
6248 /* Draw_everythig */
6249 draw_text_editor(tb);
6251 /* Display header line */
6253 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
6255 prt("(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)", 0, 0);
6259 /* Display current position */
6260 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6264 /* Display current position and mark position */
6265 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6269 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6272 tb->dirty_flags = 0;
6273 tb->dirty_line = -1;
6275 /* Save old key and location */
6276 tb->old_cy = tb->cy;
6277 tb->old_upper = tb->upper;
6278 tb->old_left = tb->left;
6279 tb->old_wid = tb->wid;
6280 tb->old_hgt = tb->hgt;
6283 key = inkey_special(TRUE);
6286 if (key & SKEY_MASK)
6288 /* Get a movement command */
6289 com_id = analyze_move_key(tb, key);
6293 else if (key == ESCAPE)
6295 com_id = do_command_menu(0, 0);
6297 /* Redraw all text later */
6298 tb->dirty_flags |= DIRTY_SCREEN;
6301 /* Insert a character */
6302 else if (!iscntrl((unsigned char)key))
6304 /* Ignore selection */
6310 tb->dirty_flags |= DIRTY_ALL;
6313 insert_single_letter(tb, key);
6319 /* Other commands */
6322 com_id = get_com_id(key);
6325 if (com_id) quit = do_editor_command(tb, com_id);
6326 } /* while (TRUE) */
6328 /* Restore the screen */
6331 /* Get the filename of preference */
6332 strcpy(buf, pickpref_filename(tb->filename_mode));
6334 if (quit == QUIT_AND_SAVE)
6335 write_text_lines(buf, tb->lines_list);
6337 free_text_lines(tb->lines_list);
6339 string_free(tb->search_str);
6340 string_free(tb->last_destroyed);
6342 /* Destroy string chain */
6343 kill_yank_chain(tb);
6345 /* Reload autopick pref */
6346 process_autopick_file(buf);
6348 /* HACK -- reset start_time so that playtime is not increase while edit */
6349 start_time = time(NULL);
6351 /* Save cursor location */