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;
223 act = DO_AUTOPICK | DO_DISPLAY;
226 if ((act & DO_AUTOPICK) && *str == '!')
229 act |= DO_AUTODESTROY;
232 else if ((act & DO_AUTOPICK) && *str == '~')
235 act |= DONT_AUTOPICK;
238 else if ((act & DO_AUTOPICK) && *str == ';')
241 act |= DO_QUERY_AUTOPICK;
244 else if ((act & DO_DISPLAY) && *str == '(')
253 /* don't mind upper or lower case */
255 for (i = 0; *str; i++)
266 /* Auto-inscription? */
274 if (isupper(c)) c = tolower(c);
280 /* Skip empty line unless allow_default */
281 if (!allow_default && *buf == 0) return FALSE;
283 /* Skip comment line */
284 if (*buf == 0 && insc) return FALSE;
286 ptr = prev_ptr = buf;
289 while (old_ptr != ptr)
291 /* Save current location */
294 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
295 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
296 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
297 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
298 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
299 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
300 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
302 /*** Weapons whose dd*ds is more than nn ***/
303 if (MATCH_KEY2(KEY_MORE_THAN))
308 /* Drop leading spaces */
309 while (' ' == *ptr) ptr++;
312 while ('0' <= *ptr && *ptr <= '9')
314 entry->dice = 10 * entry->dice + (*ptr - '0');
321 (void)MATCH_KEY(KEY_DICE);
322 ADD_FLG(FLG_MORE_DICE);
328 /*** Items whose magical bonus is more than n ***/
329 if (MATCH_KEY2(KEY_MORE_BONUS))
334 /* Drop leading spaces */
335 while (' ' == *ptr) ptr++;
338 while ('0' <= *ptr && *ptr <= '9')
340 entry->bonus = 10 * entry->bonus + (*ptr - '0');
348 (void)MATCH_KEY(KEY_MORE_BONUS2);
350 if (' ' == *ptr) ptr++;
352 ADD_FLG(FLG_MORE_BONUS);
358 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
359 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
360 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
361 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
362 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
363 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
364 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
365 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
366 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
367 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
368 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
369 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
370 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
371 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
372 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
373 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
374 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
377 /* Not yet found any noun */
380 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
382 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
383 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
384 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
385 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
386 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
387 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
388 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
389 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
390 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
391 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
392 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
393 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
394 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
395 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
396 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
397 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
398 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
399 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
400 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
401 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
403 /* Last 'keyword' must be at the correct location */
407 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
410 else if (*ptr == '\0')
412 /* There was no noun */
415 /* Add extra word "items" */
416 ADD_FLG_NOUN(FLG_ITEMS);
423 /* A noun type keyword didn't end correctly */
424 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
429 /* Save this auto-picker entry line */
430 entry->name = string_make(ptr);
432 entry->insc = string_make(insc);
439 * Get auto-picker entry from o_ptr.
441 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
443 /* Assume that object name is to be added */
447 /* ¥¨¥´Ì䬼ÙË⤫¤â¤·¤ì¤Ê¤¤¤Î¤Ç¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¡Ö^¡×¤ÏÉÕ¤±¤Ê¤¤ */
448 bool bol_mark = FALSE;
450 /* We can always use the ^ mark in English */
451 bool bol_mark = TRUE;
454 char name_str[MAX_NLEN];
456 /* Initialize name string */
459 entry->insc = string_make(quark_str(o_ptr->inscription));
460 entry->action = DO_AUTOPICK | DO_DISPLAY;
461 entry->flag[0] = entry->flag[1] = 0L;
465 if (!object_is_aware(o_ptr))
467 ADD_FLG(FLG_UNAWARE);
471 /* Not really identified */
472 else if (!object_is_known(o_ptr))
474 if (!(o_ptr->ident & IDENT_SENSE))
476 ADD_FLG(FLG_UNIDENTIFIED);
481 /* Pseudo-identified */
482 switch (o_ptr->feeling)
486 ADD_FLG(FLG_NAMELESS);
492 ADD_FLG(FLG_NAMELESS);
493 ADD_FLG(FLG_WORTHLESS);
499 ADD_FLG(FLG_WORTHLESS);
507 /* XXX No appropriate flag */
512 /* Never reach here */
522 if (object_is_ego(o_ptr))
524 if (object_is_weapon_armour_ammo(o_ptr))
527 * Base name of ego weapons and armors
528 * are almost meaningless.
529 * Register the ego type only.
531 ego_item_type *e_ptr = &e_info[o_ptr->name2];
533 /* ¥¨¥´ÌäˤϡÖ^¡×¥Þ¡¼¥¯¤¬»È¤¨¤ë */
534 sprintf(name_str, "^%s", e_name + e_ptr->name);
536 /* We ommit the basename and cannot use the ^ mark */
537 strcpy(name_str, e_name + e_ptr->name);
540 /* Don't use the object description */
543 /* Restrict to 'common' equipments */
544 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
551 else if (object_is_artifact(o_ptr))
552 ADD_FLG(FLG_ARTIFACT);
554 /* Non-ego, non-artifact */
557 /* Wearable nameless object */
558 if (object_is_equipment(o_ptr))
559 ADD_FLG(FLG_NAMELESS);
566 /* Melee weapon with boosted dice */
567 if (object_is_melee_weapon(o_ptr))
569 object_kind *k_ptr = &k_info[o_ptr->k_idx];
571 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
572 ADD_FLG(FLG_BOOSTED);
575 /* Wanted monster's corpse */
576 if (object_is_shoukinkubi(o_ptr))
578 REM_FLG(FLG_WORTHLESS);
582 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
583 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
588 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
593 if (o_ptr->tval >= TV_LIFE_BOOK &&
594 !check_book_realm(o_ptr->tval, o_ptr->sval))
596 ADD_FLG(FLG_UNREADABLE);
597 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
600 if (REALM1_BOOK == o_ptr->tval &&
601 p_ptr->pclass != CLASS_SORCERER &&
602 p_ptr->pclass != CLASS_RED_MAGE)
608 if (REALM2_BOOK == o_ptr->tval &&
609 p_ptr->pclass != CLASS_SORCERER &&
610 p_ptr->pclass != CLASS_RED_MAGE)
616 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
618 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
620 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
622 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
625 if (object_is_ammo(o_ptr))
626 ADD_FLG(FLG_MISSILES);
627 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
628 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
629 ADD_FLG(FLG_DEVICES);
630 else if (o_ptr->tval == TV_LITE)
632 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
633 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
635 else if (o_ptr->tval == TV_CORPSE)
636 ADD_FLG(FLG_CORPSES);
637 else if (o_ptr->tval >= TV_LIFE_BOOK)
638 ADD_FLG(FLG_SPELLBOOKS);
639 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
640 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
641 ADD_FLG(FLG_WEAPONS);
642 else if (o_ptr->tval == TV_SHIELD)
643 ADD_FLG(FLG_SHIELDS);
644 else if (o_ptr->tval == TV_BOW)
646 else if (o_ptr->tval == TV_RING)
648 else if (o_ptr->tval == TV_AMULET)
649 ADD_FLG(FLG_AMULETS);
650 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
651 o_ptr->tval == TV_SOFT_ARMOR)
653 else if (o_ptr->tval == TV_CLOAK)
655 else if (o_ptr->tval == TV_HELM)
657 else if (o_ptr->tval == TV_GLOVES)
659 else if (o_ptr->tval == TV_BOOTS)
662 /* Prepare the object description */
665 char o_name[MAX_NLEN];
667 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
670 * If necessary, add a '^' which indicates the
673 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
676 /* Register the name in lowercase */
677 str_tolower(name_str);
678 entry->name = string_make(name_str);
685 * A function to delete entry
687 static void autopick_free_entry(autopick_type *entry)
689 string_free(entry->name);
690 string_free(entry->insc);
696 #define MAX_AUTOPICK_DEFAULT 200
699 * Initialize the autopick
701 static void init_autopick(void)
703 static const char easy_autopick_inscription[] = "(:=g";
709 max_max_autopick = MAX_AUTOPICK_DEFAULT;
710 C_MAKE(autopick_list, max_max_autopick, autopick_type);
714 /* Clear old entries */
715 for( i = 0; i < max_autopick; i++)
716 autopick_free_entry(&autopick_list[i]);
720 /* There is always one entry "=g" */
721 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
722 autopick_list[max_autopick++] = entry;
727 #define PT_WITH_PNAME 1
730 * Get file name for autopick preference
732 static cptr pickpref_filename(int filename_mode)
735 static const char namebase[] = "picktype";
737 static const char namebase[] = "pickpref";
740 switch (filename_mode)
743 return format("%s.prf", namebase);
746 return format("%s-%s.prf", namebase, player_base);
755 * Load an autopick preference file
757 void autopick_load_pref(bool disp_mes)
762 /* Free old entries */
765 /* Try a filename with player name */
766 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
769 err = process_autopick_file(buf);
771 if (err == 0 && disp_mes)
775 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
777 msg_format("Loaded '%s'.", buf);
784 /* Use default name */
785 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
788 err = process_autopick_file(buf);
790 if (err == 0 && disp_mes)
794 msg_format("%s¤òÆɤ߹þ¤ß¤Þ¤·¤¿¡£", buf);
796 msg_format("Loaded '%s'.", buf);
805 msg_print("¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
807 msg_print("Failed to reload autopick preference.");
814 * Add one line to autopick_list[]
816 static void add_autopick_list(autopick_type *entry)
818 /* There is no enough space to add one line */
819 if (max_autopick >= max_max_autopick)
821 int old_max_max_autopick = max_max_autopick;
822 autopick_type *old_autopick_list = autopick_list;
824 /* Increase size of list */
825 max_max_autopick += MAX_AUTOPICK_DEFAULT;
828 C_MAKE(autopick_list, max_max_autopick, autopick_type);
830 /* Copy from old list to new list */
831 C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
834 C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
838 autopick_list[max_autopick] = *entry;
845 * Process line for auto picker/destroyer.
847 errr process_autopick_file_command(char *buf)
849 autopick_type an_entry, *entry = &an_entry;
852 /* Nuke illegal char */
853 for(i = 0; buf[i]; i++)
862 if (isspace(buf[i]) && buf[i] != ' ')
867 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
869 /* Already has the same entry? */
870 for(i = 0; i < max_autopick; i++)
871 if(!strcmp(entry->name, autopick_list[i].name)
872 && entry->flag[0] == autopick_list[i].flag[0]
873 && entry->flag[1] == autopick_list[i].flag[1]
874 && entry->dice == autopick_list[i].dice
875 && entry->bonus == autopick_list[i].bonus)
877 autopick_free_entry(entry);
881 add_autopick_list(entry);
887 * Reconstruct preference line from entry
889 cptr autopick_line_from_entry(autopick_type *entry)
891 char buf[MAX_LINELEN];
893 bool sepa_flag = TRUE;
896 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
897 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
898 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
899 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
903 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
904 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
905 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
906 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
907 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
908 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
909 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
911 if (IS_FLG(FLG_MORE_DICE))
913 ADD_KEY(KEY_MORE_THAN);
914 strcat(ptr, format("%d", entry->dice));
918 if (IS_FLG(FLG_MORE_BONUS))
920 ADD_KEY(KEY_MORE_BONUS);
921 strcat(ptr, format("%d", entry->bonus));
922 ADD_KEY(KEY_MORE_BONUS2);
925 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
926 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
927 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
928 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
929 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
930 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
931 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
932 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
933 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
934 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
935 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
936 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
937 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
938 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
939 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
940 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
941 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
943 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
945 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
946 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
947 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
948 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
949 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
950 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
951 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
952 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
953 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
954 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
955 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
956 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
957 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
958 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
959 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
960 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
961 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
962 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
963 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
964 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
966 /* You don't need sepalator after adjective */
967 /* 'artifact' is not true adjective */
968 else if (!IS_FLG(FLG_ARTIFACT))
971 if (entry->name && entry->name[0])
975 if (sepa_flag) strcat(buf, ":");
978 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
981 if (iskanji(entry->name[j]))
982 buf[i++] = entry->name[j++];
984 buf[i++] = entry->name[j++];
995 while (entry->insc[j] && i < MAX_LINELEN - 2)
998 if (iskanji(entry->insc[j]))
999 buf[i++] = entry->insc[j++];
1001 buf[i++] = entry->insc[j++];
1006 return string_make(buf);
1011 * Reconstruct preference line from entry and kill entry
1013 static cptr autopick_line_from_entry_kill(autopick_type *entry)
1015 cptr ptr = autopick_line_from_entry(entry);
1017 /* Free memory for original entry */
1018 autopick_free_entry(entry);
1025 * A function for Auto-picker/destroyer
1026 * Examine whether the object matches to the entry
1028 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
1031 cptr ptr = entry->name;
1033 /*** Unaware items ***/
1034 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1037 /*** Unidentified ***/
1038 if (IS_FLG(FLG_UNIDENTIFIED)
1039 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1042 /*** Identified ***/
1043 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1046 /*** *Identified* ***/
1047 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1048 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1051 /*** Dice boosted (weapon of slaying) ***/
1052 if (IS_FLG(FLG_BOOSTED))
1054 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1056 /* Require melee weapon */
1057 if (!object_is_melee_weapon(o_ptr))
1060 /* Require boosted dice */
1061 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1065 /*** Weapons which dd*ds is more than nn ***/
1066 if (IS_FLG(FLG_MORE_DICE))
1068 if (o_ptr->dd * o_ptr->ds < entry->dice)
1072 /*** Weapons whic dd*ds is more than nn ***/
1073 if (IS_FLG(FLG_MORE_BONUS))
1075 if (!object_is_known(o_ptr)) return FALSE;
1079 if (o_ptr->pval < entry->bonus) return FALSE;
1083 if (o_ptr->to_h < entry->bonus &&
1084 o_ptr->to_d < entry->bonus &&
1085 o_ptr->to_a < entry->bonus &&
1086 o_ptr->pval < entry->bonus)
1091 /*** Worthless items ***/
1092 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1095 /*** Artifact object ***/
1096 if (IS_FLG(FLG_ARTIFACT))
1098 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1102 /*** Ego object ***/
1103 if (IS_FLG(FLG_EGO))
1105 /* Need to be an ego item */
1106 if (!object_is_ego(o_ptr)) return FALSE;
1108 /* Need to be known to be an ego */
1109 if (!object_is_known(o_ptr) &&
1110 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1115 if (IS_FLG(FLG_GOOD))
1117 if (!object_is_equipment(o_ptr)) return FALSE;
1120 if (object_is_known(o_ptr))
1122 /* Artifacts and Ego objects are not okay */
1123 if (!object_is_nameless(o_ptr))
1126 /* Average are not okay */
1127 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1131 /* Pseudo-identified */
1132 else if (o_ptr->ident & IDENT_SENSE)
1134 switch (o_ptr->feeling)
1149 /* Not known to be good */
1155 if (IS_FLG(FLG_NAMELESS))
1157 if (!object_is_equipment(o_ptr)) return FALSE;
1160 if (object_is_known(o_ptr))
1162 /* Artifacts and Ego objects are not okay */
1163 if (!object_is_nameless(o_ptr))
1167 /* Pseudo-identified */
1168 else if (o_ptr->ident & IDENT_SENSE)
1170 switch (o_ptr->feeling)
1180 /* It's not nameless */
1188 /* Not known to be nameless */
1194 if (IS_FLG(FLG_AVERAGE))
1196 if (!object_is_equipment(o_ptr)) return FALSE;
1199 if (object_is_known(o_ptr))
1201 /* Artifacts and Ego objects are not okay */
1202 if (!object_is_nameless(o_ptr))
1205 /* Cursed or broken objects are not okay */
1206 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1209 /* Good are not okay */
1210 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1214 /* Pseudo-identified */
1215 else if (o_ptr->ident & IDENT_SENSE)
1217 switch (o_ptr->feeling)
1224 /* It's not average */
1232 /* Not known to be average */
1237 /*** Rere equipments ***/
1238 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1241 /*** Common equipments ***/
1242 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1245 /*** Wanted monster's corpse/skeletons ***/
1246 if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
1249 /*** Unique monster's corpse/skeletons/statues ***/
1250 if (IS_FLG(FLG_UNIQUE) &&
1251 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1252 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1255 /*** Human corpse/skeletons (for Daemon magic) ***/
1256 if (IS_FLG(FLG_HUMAN) &&
1257 (o_ptr->tval != TV_CORPSE ||
1258 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1261 /*** Unreadable spellbooks ***/
1262 if (IS_FLG(FLG_UNREADABLE) &&
1263 (o_ptr->tval < TV_LIFE_BOOK ||
1264 check_book_realm(o_ptr->tval, o_ptr->sval)))
1267 /*** First realm spellbooks ***/
1268 if (IS_FLG(FLG_REALM1) &&
1269 (REALM1_BOOK != o_ptr->tval ||
1270 p_ptr->pclass == CLASS_SORCERER ||
1271 p_ptr->pclass == CLASS_RED_MAGE))
1274 /*** Second realm spellbooks ***/
1275 if (IS_FLG(FLG_REALM2) &&
1276 (REALM2_BOOK != o_ptr->tval ||
1277 p_ptr->pclass == CLASS_SORCERER ||
1278 p_ptr->pclass == CLASS_RED_MAGE))
1281 /*** First rank spellbooks ***/
1282 if (IS_FLG(FLG_FIRST) &&
1283 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1286 /*** Second rank spellbooks ***/
1287 if (IS_FLG(FLG_SECOND) &&
1288 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1291 /*** Third rank spellbooks ***/
1292 if (IS_FLG(FLG_THIRD) &&
1293 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1296 /*** Fourth rank spellbooks ***/
1297 if (IS_FLG(FLG_FOURTH) &&
1298 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1302 if (IS_FLG(FLG_WEAPONS))
1304 if (!object_is_weapon(o_ptr))
1307 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1309 if (!object_is_favorite(o_ptr))
1312 else if (IS_FLG(FLG_ARMORS))
1314 if (!object_is_armour(o_ptr))
1317 else if (IS_FLG(FLG_MISSILES))
1319 if (!object_is_ammo(o_ptr)) return FALSE;
1321 else if (IS_FLG(FLG_DEVICES))
1325 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1327 default: return FALSE;
1330 else if (IS_FLG(FLG_LIGHTS))
1332 if (!(o_ptr->tval == TV_LITE))
1335 else if (IS_FLG(FLG_JUNKS))
1339 case TV_SKELETON: case TV_BOTTLE:
1340 case TV_JUNK: case TV_STATUE:
1342 default: return FALSE;
1345 else if (IS_FLG(FLG_CORPSES))
1347 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1350 else if (IS_FLG(FLG_SPELLBOOKS))
1352 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1355 else if (IS_FLG(FLG_HAFTED))
1357 if (!(o_ptr->tval == TV_HAFTED))
1360 else if (IS_FLG(FLG_SHIELDS))
1362 if (!(o_ptr->tval == TV_SHIELD))
1365 else if (IS_FLG(FLG_BOWS))
1367 if (!(o_ptr->tval == TV_BOW))
1370 else if (IS_FLG(FLG_RINGS))
1372 if (!(o_ptr->tval == TV_RING))
1375 else if (IS_FLG(FLG_AMULETS))
1377 if (!(o_ptr->tval == TV_AMULET))
1380 else if (IS_FLG(FLG_SUITS))
1382 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1383 o_ptr->tval == TV_HARD_ARMOR ||
1384 o_ptr->tval == TV_SOFT_ARMOR))
1387 else if (IS_FLG(FLG_CLOAKS))
1389 if (!(o_ptr->tval == TV_CLOAK))
1392 else if (IS_FLG(FLG_HELMS))
1394 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1397 else if (IS_FLG(FLG_GLOVES))
1399 if (!(o_ptr->tval == TV_GLOVES))
1402 else if (IS_FLG(FLG_BOOTS))
1404 if (!(o_ptr->tval == TV_BOOTS))
1408 /* Keyword don't match */
1412 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1416 if (!my_strstr(o_name, ptr)) return FALSE;
1419 /* TRUE when it need not to be 'collecting' */
1420 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1422 /* Check if there is a same item */
1423 for (j = 0; j < INVEN_PACK; j++)
1426 * 'Collecting' means the item must be absorbed
1427 * into an inventory slot.
1428 * But an item can not be absorbed into itself!
1430 if ((&inventory[j] != o_ptr) &&
1431 object_similar(&inventory[j], o_ptr))
1435 /* Not collecting */
1441 * A function for Auto-picker/destroyer
1442 * Examine whether the object matches to the list of keywords or not.
1444 int is_autopick(object_type *o_ptr)
1447 char o_name[MAX_NLEN];
1449 if (o_ptr->tval == TV_GOLD) return -1;
1451 /* Prepare object name string first */
1452 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1454 /* Convert the string to lower case */
1455 str_tolower(o_name);
1457 /* Look for a matching entry in the list */
1458 for (i=0; i < max_autopick; i++)
1460 autopick_type *entry = &autopick_list[i];
1462 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1465 /* No matching entry */
1473 static void auto_inscribe_item(object_type *o_ptr, int idx)
1475 /* Are there auto-inscription? */
1476 if (idx < 0 || !autopick_list[idx].insc) return;
1478 if (!o_ptr->inscription)
1479 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1481 /* Redraw inscription */
1482 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1484 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1485 p_ptr->update |= (PU_BONUS);
1490 * Automatically destroy items in this grid.
1492 static bool is_opt_confirm_destroy(object_type *o_ptr)
1494 if (!destroy_items) return FALSE;
1496 /* Known to be worthless? */
1498 if (object_value(o_ptr) > 0) return FALSE;
1501 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1504 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1508 if (object_is_shoukinkubi(o_ptr)) return FALSE;
1512 if (o_ptr->tval == TV_CORPSE) return FALSE;
1515 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1519 if (p_ptr->prace == RACE_DEMON)
1521 if (o_ptr->tval == TV_CORPSE &&
1522 o_ptr->sval == SV_CORPSE &&
1523 my_strchr("pht", r_info[o_ptr->pval].d_char))
1527 if (p_ptr->pclass == CLASS_ARCHER)
1529 if (o_ptr->tval == TV_SKELETON ||
1530 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1533 else if (p_ptr->pclass == CLASS_NINJA)
1535 if (o_ptr->tval == TV_LITE &&
1536 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1539 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1540 p_ptr->pclass == CLASS_CAVALRY)
1542 if (o_ptr->tval == TV_WAND &&
1543 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1548 if (o_ptr->tval == TV_GOLD) return FALSE;
1555 * Automatically destroy an item if it is to be destroyed
1557 * When always_pickup is 'yes', we disable auto-destroyer function of
1558 * auto-picker/destroyer, and do only easy-auto-destroyer.
1560 static object_type autopick_last_destroyed_object;
1562 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1564 bool destroy = FALSE;
1566 /* Easy-Auto-Destroyer (3rd priority) */
1567 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1569 /* Protected by auto-picker (2nd priotity) */
1570 if (autopick_idx >= 0 &&
1571 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1574 /* Auto-destroyer works only when !always_pickup */
1577 /* Auto-picker/destroyer (1st priority) */
1578 if (autopick_idx >= 0 &&
1579 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1583 /* Not to be destroyed */
1584 if (!destroy) return;
1586 /* Now decided to destroy */
1591 if (!can_player_destroy_object(o_ptr))
1593 char o_name[MAX_NLEN];
1595 /* Describe the object (with {terrible/special}) */
1596 object_desc(o_name, o_ptr, 0);
1600 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1602 msg_format("You cannot auto-destroy %s.", o_name);
1609 /* Record name of destroyed item */
1610 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1613 o_ptr->marked |= OM_AUTODESTROY;
1614 p_ptr->notice |= PN_AUTODESTROY;
1621 * Auto-destroy marked item
1623 static void autopick_delayed_alter_aux(int item)
1627 /* Get the item (in the pack) */
1628 if (item >= 0) o_ptr = &inventory[item];
1630 /* Get the item (on the floor) */
1631 else o_ptr = &o_list[0 - item];
1633 if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
1635 char o_name[MAX_NLEN];
1637 /* Describe the object (with {terrible/special}) */
1638 object_desc(o_name, o_ptr, 0);
1640 /* Eliminate the item (from the pack) */
1643 inven_item_increase(item, -(o_ptr->number));
1644 inven_item_optimize(item);
1647 /* Eliminate the item (from the floor) */
1650 delete_object_idx(0 - item);
1653 /* Print a message */
1655 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1657 msg_format("Auto-destroying %s.", o_name);
1664 * Auto-destroy marked items in inventry and on floor
1666 void autopick_delayed_alter(void)
1671 * Scan inventry in reverse order to prevent
1672 * skipping after inven_item_optimize()
1674 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1675 autopick_delayed_alter_aux(item);
1677 /* Scan the pile of objects */
1678 item = cave[py][px].o_idx;
1681 int next = o_list[item].next_o_idx;
1682 autopick_delayed_alter_aux(-item);
1689 * Auto-inscription and/or destroy
1691 * Auto-destroyer works only on inventory or on floor stack only when
1694 void autopick_alter_item(int item, bool destroy)
1699 /* Get the item (in the pack) */
1700 if (item >= 0) o_ptr = &inventory[item];
1702 /* Get the item (on the floor) */
1703 else o_ptr = &o_list[0 - item];
1705 /* Get the index in the auto-pick/destroy list */
1706 idx = is_autopick(o_ptr);
1708 /* Do auto-inscription */
1709 auto_inscribe_item(o_ptr, idx);
1711 /* Do auto-destroy if needed */
1712 if (destroy && item <= INVEN_PACK)
1713 auto_destroy_item(o_ptr, idx);
1718 * Automatically pickup/destroy items in this grid.
1720 void autopick_pickup_items(cave_type *c_ptr)
1722 s16b this_o_idx, next_o_idx = 0;
1724 /* Scan the pile of objects */
1725 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1729 /* Acquire object */
1730 object_type *o_ptr = &o_list[this_o_idx];
1732 /* Acquire next object */
1733 next_o_idx = o_ptr->next_o_idx;
1735 idx = is_autopick(o_ptr);
1737 /* Item index for floor -1,-2,-3,... */
1738 auto_inscribe_item(o_ptr, idx);
1741 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1745 if (!inven_carry_okay(o_ptr))
1747 char o_name[MAX_NLEN];
1749 /* Describe the object */
1750 object_desc(o_name, o_ptr, 0);
1754 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1756 msg_format("You have no room for %s.", o_name);
1758 /* Hack - remember that the item has given a message here. */
1759 o_ptr->marked |= OM_NOMSG;
1763 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1765 char out_val[MAX_NLEN+20];
1766 char o_name[MAX_NLEN];
1768 if (o_ptr->marked & OM_NO_QUERY)
1770 /* Already answered as 'No' */
1774 /* Describe the object */
1775 object_desc(o_name, o_ptr, 0);
1778 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1780 sprintf(out_val, "Pick up %s? ", o_name);
1783 if (!get_check(out_val))
1785 /* Hack - remember that the item has given a message here. */
1786 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1791 py_pickup_aux(this_o_idx);
1796 * When always_pickup is 'yes', we disable
1797 * auto-destroyer from autopick function, and do only
1798 * easy-auto-destroyer.
1802 auto_destroy_item(o_ptr, idx);
1808 static const char autoregister_header[] = "?:$AUTOREGISTER";
1811 * Clear auto registered lines in the picktype.prf .
1813 static bool clear_auto_register(void)
1815 char tmp_file[1024];
1816 char pref_file[1024];
1821 bool autoregister = FALSE;
1824 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1825 pref_fff = my_fopen(pref_file, "r");
1829 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1830 pref_fff = my_fopen(pref_file, "r");
1839 /* Open a new (temporary) file */
1840 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1844 /* Close the preference file */
1848 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1850 msg_format("Failed to create temporary file %s.", tmp_file);
1857 /* Loop for every line */
1861 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1865 /* Delete auto-registered line */
1867 /* Count auto-destroy preference lines */
1868 if (buf[0] != '#' && buf[0] != '?') num++;
1871 /* We are looking for auto-registered line */
1874 if (streq(buf, autoregister_header))
1876 /* Delete all further lines */
1877 autoregister = TRUE;
1881 /* Copy orginally lines */
1882 fprintf(tmp_fff, "%s\n", buf);
1888 my_fclose(pref_fff);
1894 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1895 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1897 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1898 strcpy(buf, "These lines will be deleted. Are you sure? ");
1901 /* You can cancel it */
1902 if (!get_check(buf))
1905 autoregister = FALSE;
1908 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1910 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1916 /* If there are some changes, overwrite the original file with new one */
1919 /* Copy contents of temporary file */
1921 tmp_fff = my_fopen(tmp_file, "r");
1922 pref_fff = my_fopen(pref_file, "w");
1924 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1925 fprintf(pref_fff, "%s\n", buf);
1927 my_fclose(pref_fff);
1931 /* Kill the temporary file */
1939 * Automatically register an auto-destroy preference line
1941 bool autopick_autoregister(object_type *o_ptr)
1944 char pref_file[1024];
1946 autopick_type an_entry, *entry = &an_entry;
1948 int match_autopick = is_autopick(o_ptr);
1950 /* Already registered */
1951 if (match_autopick != -1)
1954 byte act = autopick_list[match_autopick].action;
1957 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1958 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1959 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1960 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1962 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1964 if (act & DO_AUTOPICK) what = "auto-pickup";
1965 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1966 else if (act & DONT_AUTOPICK) what = "leave on floor";
1967 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1969 msg_format("The object is already registered to %s.", what);
1975 /* Known to be an artifact? */
1976 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1977 ((o_ptr->ident & IDENT_SENSE) &&
1978 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1980 char o_name[MAX_NLEN];
1982 /* Describe the object (with {terrible/special}) */
1983 object_desc(o_name, o_ptr, 0);
1987 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1989 msg_format("You cannot auto-destroy %s.", o_name);
1997 if (!p_ptr->autopick_autoregister)
1999 /* Clear old auto registered lines */
2000 if (!clear_auto_register()) return FALSE;
2003 /* Try a filename with player name */
2004 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
2005 pref_fff = my_fopen(pref_file, "r");
2009 /* Use default name */
2010 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
2011 pref_fff = my_fopen(pref_file, "r");
2014 /* Check the header */
2018 if (my_fgets(pref_fff, buf, sizeof(buf)))
2020 /* No header found */
2021 p_ptr->autopick_autoregister = FALSE;
2026 if (streq(buf, autoregister_header))
2028 /* Found the header */
2029 p_ptr->autopick_autoregister = TRUE;
2035 /* Close read only FILE* */
2038 /* Open for append */
2039 pref_fff = my_fopen(pref_file, "a");
2044 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
2046 msg_format("Failed to open %s.", pref_file);
2054 if (!p_ptr->autopick_autoregister)
2056 /* Add the header */
2057 fprintf(pref_fff, "%s\n", autoregister_header);
2060 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
2061 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
2063 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
2064 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
2067 /* Now auto register is in-use */
2068 p_ptr->autopick_autoregister = TRUE;
2071 /* Get a preference entry */
2072 autopick_entry_from_object(entry, o_ptr);
2074 /* Set to auto-destroy (with no-display) */
2075 entry->action = DO_AUTODESTROY;
2077 /* Load the new line as preference */
2078 add_autopick_list(entry);
2080 /* Add a line to the file */
2081 /* Don't kill "entry" */
2082 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2084 /* Close the file */
2091 /******** Auto-picker/destroyer editor **********/
2093 #define MAX_YANK MAX_LINELEN
2094 #define MAX_LINES 3000
2096 #define MARK_MARK 0x01
2097 #define MARK_BY_SHIFT 0x02
2099 #define LSTAT_BYPASS 0x01
2100 #define LSTAT_EXPRESSION 0x02
2101 #define LSTAT_AUTOREGISTER 0x04
2103 #define QUIT_WITHOUT_SAVE 1
2104 #define QUIT_AND_SAVE 2
2107 * Struct for yank buffer
2109 typedef struct chain_str {
2110 struct chain_str *next;
2116 * Data struct for text editor
2122 int old_wid, old_hgt;
2124 int old_upper, old_left;
2128 object_type *search_o_ptr;
2130 cptr last_destroyed;
2132 chain_str_type *yank;
2136 byte states[MAX_LINES];
2148 * Dirty flag for text editor
2150 #define DIRTY_ALL 0x0001
2151 #define DIRTY_MODE 0x0004
2152 #define DIRTY_SCREEN 0x0008
2153 #define DIRTY_NOT_FOUND 0x0010
2154 #define DIRTY_NO_SEARCH 0x0020
2155 #define DIRTY_EXPRESSION 0x0040
2156 #define DIRTY_SKIP_INACTIVE 0x0080
2157 #define DIRTY_INACTIVE 0x0100
2160 * Describe which kind of object is Auto-picked/destroyed
2162 static void describe_autopick(char *buff, autopick_type *entry)
2164 cptr str = entry->name;
2165 byte act = entry->action;
2166 cptr insc = entry->insc;
2172 cptr before_str[100], body_str;
2175 body_str = "¥¢¥¤¥Æ¥à";
2177 /*** Collecting items ***/
2178 /*** Which can be absorbed into a slot as a bundle ***/
2179 if (IS_FLG(FLG_COLLECTING))
2180 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2182 /*** Unaware items ***/
2183 if (IS_FLG(FLG_UNAWARE))
2184 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2186 /*** Unidentified ***/
2187 if (IS_FLG(FLG_UNIDENTIFIED))
2188 before_str[before_n++] = "̤´ÕÄê¤Î";
2190 /*** Identified ***/
2191 if (IS_FLG(FLG_IDENTIFIED))
2192 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2194 /*** *Identified* ***/
2195 if (IS_FLG(FLG_STAR_IDENTIFIED))
2196 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2198 /*** Dice boosted (weapon of slaying) ***/
2199 if (IS_FLG(FLG_BOOSTED))
2201 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2205 /*** Weapons whose dd*ds is more than nn ***/
2206 if (IS_FLG(FLG_MORE_DICE))
2208 static char more_than_desc_str[] = "___";
2209 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2212 sprintf(more_than_desc_str,"%d", entry->dice);
2213 before_str[before_n++] = more_than_desc_str;
2214 before_str[before_n++] = "°Ê¾å¤Î";
2217 /*** Items whose magical bonus is more than nn ***/
2218 if (IS_FLG(FLG_MORE_BONUS))
2220 static char more_bonus_desc_str[] = "___";
2221 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2223 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2224 before_str[before_n++] = more_bonus_desc_str;
2225 before_str[before_n++] = ")°Ê¾å¤Î";
2228 /*** Worthless items ***/
2229 if (IS_FLG(FLG_WORTHLESS))
2230 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2233 if (IS_FLG(FLG_ARTIFACT))
2235 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2240 if (IS_FLG(FLG_EGO))
2242 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2247 if (IS_FLG(FLG_GOOD))
2249 before_str[before_n++] = "¾å¼Á¤Î";
2254 if (IS_FLG(FLG_NAMELESS))
2256 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2261 if (IS_FLG(FLG_AVERAGE))
2263 before_str[before_n++] = "ʤÎ";
2267 /*** Rare equipments ***/
2268 if (IS_FLG(FLG_RARE))
2270 before_str[before_n++] = "¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ò´Þ¤àÄÁ¤·¤¤";
2274 /*** Common equipments ***/
2275 if (IS_FLG(FLG_COMMON))
2277 before_str[before_n++] = "¤¢¤ê¤Õ¤ì¤¿(¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ÎÄÁ¤·¤¤Êª¤Ç¤Ï¤Ê¤¤)";
2281 /*** Wanted monster's corpse/skeletons ***/
2282 if (IS_FLG(FLG_WANTED))
2284 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2285 body_str = "»àÂΤä¹ü";
2288 /*** Human corpse/skeletons (for Daemon magic) ***/
2289 if (IS_FLG(FLG_HUMAN))
2291 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2292 body_str = "»àÂΤä¹ü";
2295 /*** Unique monster's corpse/skeletons/statues ***/
2296 if (IS_FLG(FLG_UNIQUE))
2298 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2299 body_str = "»àÂΤä¹ü";
2302 /*** Unreadable spellbooks ***/
2303 if (IS_FLG(FLG_UNREADABLE))
2305 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2306 body_str = "ËâË¡½ñ";
2309 /*** First realm spellbooks ***/
2310 if (IS_FLG(FLG_REALM1))
2312 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2313 body_str = "ËâË¡½ñ";
2316 /*** Second realm spellbooks ***/
2317 if (IS_FLG(FLG_REALM2))
2319 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2320 body_str = "ËâË¡½ñ";
2323 /*** First rank spellbooks ***/
2324 if (IS_FLG(FLG_FIRST))
2326 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2327 body_str = "ËâË¡½ñ";
2330 /*** Second rank spellbooks ***/
2331 if (IS_FLG(FLG_SECOND))
2333 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2334 body_str = "ËâË¡½ñ";
2337 /*** Third rank spellbooks ***/
2338 if (IS_FLG(FLG_THIRD))
2340 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2341 body_str = "ËâË¡½ñ";
2344 /*** Fourth rank spellbooks ***/
2345 if (IS_FLG(FLG_FOURTH))
2347 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2348 body_str = "ËâË¡½ñ";
2352 if (IS_FLG(FLG_ITEMS))
2353 ; /* Nothing to do */
2354 else if (IS_FLG(FLG_WEAPONS))
2356 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2357 body_str = "ÆÀ°ÕÉð´ï";
2358 else if (IS_FLG(FLG_ARMORS))
2360 else if (IS_FLG(FLG_MISSILES))
2361 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2362 else if (IS_FLG(FLG_DEVICES))
2363 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2364 else if (IS_FLG(FLG_LIGHTS))
2365 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2366 else if (IS_FLG(FLG_JUNKS))
2367 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2368 else if (IS_FLG(FLG_CORPSES))
2369 body_str = "»àÂΤä¹ü";
2370 else if (IS_FLG(FLG_SPELLBOOKS))
2371 body_str = "ËâË¡½ñ";
2372 else if (IS_FLG(FLG_HAFTED))
2374 else if (IS_FLG(FLG_SHIELDS))
2376 else if (IS_FLG(FLG_BOWS))
2377 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2378 else if (IS_FLG(FLG_RINGS))
2380 else if (IS_FLG(FLG_AMULETS))
2381 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2382 else if (IS_FLG(FLG_SUITS))
2384 else if (IS_FLG(FLG_CLOAKS))
2385 body_str = "¥¯¥í¡¼¥¯";
2386 else if (IS_FLG(FLG_HELMS))
2387 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2388 else if (IS_FLG(FLG_GLOVES))
2390 else if (IS_FLG(FLG_BOOTS))
2391 body_str = "¥Ö¡¼¥Ä";
2395 strcat(buff, "Á´¤Æ¤Î");
2396 else for (i = 0; i < before_n && before_str[i]; i++)
2397 strcat(buff, before_str[i]);
2399 strcat(buff, body_str);
2409 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2410 strncat(buff, str, 80);
2412 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2414 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2419 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2421 if (my_strstr(insc, "%%all"))
2422 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2423 else if (my_strstr(insc, "%all"))
2424 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2425 else if (my_strstr(insc, "%%"))
2426 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2427 else if (my_strstr(insc, "%"))
2428 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2430 strcat(buff, "¤È¹ï¤ó¤Ç");
2435 if (act & DONT_AUTOPICK)
2436 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2437 else if (act & DO_AUTODESTROY)
2438 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2439 else if (act & DO_QUERY_AUTOPICK)
2440 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2442 strcat(buff, "½¦¤¦¡£");
2444 if (act & DO_DISPLAY)
2446 if (act & DONT_AUTOPICK)
2447 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2448 else if (act & DO_AUTODESTROY)
2449 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2451 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2454 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2458 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2459 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2463 /*** Collecting items ***/
2464 /*** Which can be absorbed into a slot as a bundle ***/
2465 if (IS_FLG(FLG_COLLECTING))
2466 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2468 /*** Unaware items ***/
2469 if (IS_FLG(FLG_UNAWARE))
2471 before_str[before_n++] = "unidentified";
2472 whose_str[whose_n++] = "basic abilities are not known";
2475 /*** Unidentified ***/
2476 if (IS_FLG(FLG_UNIDENTIFIED))
2477 before_str[before_n++] = "unidentified";
2479 /*** Identified ***/
2480 if (IS_FLG(FLG_IDENTIFIED))
2481 before_str[before_n++] = "identified";
2483 /*** *Identified* ***/
2484 if (IS_FLG(FLG_STAR_IDENTIFIED))
2485 before_str[before_n++] = "fully identified";
2487 /*** Rare equipments ***/
2488 if (IS_FLG(FLG_RARE))
2490 before_str[before_n++] = "very rare";
2491 body_str = "equipments";
2492 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2495 /*** Common equipments ***/
2496 if (IS_FLG(FLG_COMMON))
2498 before_str[before_n++] = "relatively common";
2499 body_str = "equipments";
2500 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2503 /*** Worthless items ***/
2504 if (IS_FLG(FLG_WORTHLESS))
2506 before_str[before_n++] = "worthless";
2507 which_str[which_n++] = "can not be sold at stores";
2511 if (IS_FLG(FLG_ARTIFACT))
2513 before_str[before_n++] = "artifact";
2517 if (IS_FLG(FLG_EGO))
2519 before_str[before_n++] = "ego";
2523 if (IS_FLG(FLG_GOOD))
2525 body_str = "equipment";
2526 which_str[which_n++] = "have good quality";
2530 if (IS_FLG(FLG_NAMELESS))
2532 body_str = "equipment";
2533 which_str[which_n++] = "is neither ego-item nor artifact";
2537 if (IS_FLG(FLG_AVERAGE))
2539 body_str = "equipment";
2540 which_str[which_n++] = "have average quality";
2543 /*** Dice boosted (weapon of slaying) ***/
2544 if (IS_FLG(FLG_BOOSTED))
2546 body_str = "weapons";
2547 whose_str[whose_n++] = "damage dice is bigger than normal";
2550 /*** Weapons whose dd*ds is more than nn ***/
2551 if (IS_FLG(FLG_MORE_DICE))
2553 static char more_than_desc_str[] =
2554 "maximum damage from dice is bigger than __";
2555 body_str = "weapons";
2557 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2559 whose_str[whose_n++] = more_than_desc_str;
2562 /*** Items whose magical bonus is more than nn ***/
2563 if (IS_FLG(FLG_MORE_BONUS))
2565 static char more_bonus_desc_str[] =
2566 "magical bonus is bigger than (+__)";
2568 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2569 "%d)", entry->bonus);
2570 whose_str[whose_n++] = more_bonus_desc_str;
2573 /*** Wanted monster's corpse/skeletons ***/
2574 if (IS_FLG(FLG_WANTED))
2576 body_str = "corpse or skeletons";
2577 which_str[which_n++] = "is wanted at the Hunter's Office";
2580 /*** Human corpse/skeletons (for Daemon magic) ***/
2581 if (IS_FLG(FLG_HUMAN))
2583 before_str[before_n++] = "humanoid";
2584 body_str = "corpse or skeletons";
2585 which_str[which_n++] = "can be used for Daemon magic";
2588 /*** Unique monster's corpse/skeletons/statues ***/
2589 if (IS_FLG(FLG_UNIQUE))
2591 before_str[before_n++] = "unique monster's";
2592 body_str = "corpse or skeletons";
2595 /*** Unreadable spellbooks ***/
2596 if (IS_FLG(FLG_UNREADABLE))
2598 body_str = "spellbooks";
2599 after_str[after_n++] = "of different realms from yours";
2602 /*** First realm spellbooks ***/
2603 if (IS_FLG(FLG_REALM1))
2605 body_str = "spellbooks";
2606 after_str[after_n++] = "of your first realm";
2609 /*** Second realm spellbooks ***/
2610 if (IS_FLG(FLG_REALM2))
2612 body_str = "spellbooks";
2613 after_str[after_n++] = "of your second realm";
2616 /*** First rank spellbooks ***/
2617 if (IS_FLG(FLG_FIRST))
2619 before_str[before_n++] = "first one of four";
2620 body_str = "spellbooks";
2623 /*** Second rank spellbooks ***/
2624 if (IS_FLG(FLG_SECOND))
2626 before_str[before_n++] = "second one of four";
2627 body_str = "spellbooks";
2630 /*** Third rank spellbooks ***/
2631 if (IS_FLG(FLG_THIRD))
2633 before_str[before_n++] = "third one of four";
2634 body_str = "spellbooks";
2637 /*** Fourth rank spellbooks ***/
2638 if (IS_FLG(FLG_FOURTH))
2640 before_str[before_n++] = "fourth one of four";
2641 body_str = "spellbooks";
2645 if (IS_FLG(FLG_ITEMS))
2646 ; /* Nothing to do */
2647 else if (IS_FLG(FLG_WEAPONS))
2648 body_str = "weapons";
2649 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2650 body_str = "favorite weapons";
2651 else if (IS_FLG(FLG_ARMORS))
2652 body_str = "armors";
2653 else if (IS_FLG(FLG_MISSILES))
2654 body_str = "shots, arrows or crossbow bolts";
2655 else if (IS_FLG(FLG_DEVICES))
2656 body_str = "scrolls, wands, staves or rods";
2657 else if (IS_FLG(FLG_LIGHTS))
2658 body_str = "light sources";
2659 else if (IS_FLG(FLG_JUNKS))
2660 body_str = "junk such as broken sticks";
2661 else if (IS_FLG(FLG_CORPSES))
2662 body_str = "corpses or skeletons";
2663 else if (IS_FLG(FLG_SPELLBOOKS))
2664 body_str = "spellbooks";
2665 else if (IS_FLG(FLG_HAFTED))
2666 body_str = "hafted weapons";
2667 else if (IS_FLG(FLG_SHIELDS))
2668 body_str = "shields";
2669 else if (IS_FLG(FLG_BOWS))
2670 body_str = "slings, bows or crossbows";
2671 else if (IS_FLG(FLG_RINGS))
2673 else if (IS_FLG(FLG_AMULETS))
2674 body_str = "amulets";
2675 else if (IS_FLG(FLG_SUITS))
2676 body_str = "body armors";
2677 else if (IS_FLG(FLG_CLOAKS))
2678 body_str = "cloaks";
2679 else if (IS_FLG(FLG_HELMS))
2680 body_str = "helms or crowns";
2681 else if (IS_FLG(FLG_GLOVES))
2682 body_str = "gloves";
2683 else if (IS_FLG(FLG_BOOTS))
2686 /* Prepare a string for item name */
2693 whose_str[whose_n++] = "name is beginning with \"";
2696 which_str[which_n++] = "have \"";
2700 /* Describe action flag */
2701 if (act & DONT_AUTOPICK)
2702 strcpy(buff, "Leave on floor ");
2703 else if (act & DO_AUTODESTROY)
2704 strcpy(buff, "Destroy ");
2705 else if (act & DO_QUERY_AUTOPICK)
2706 strcpy(buff, "Ask to pick up ");
2708 strcpy(buff, "Pickup ");
2710 /* Auto-insctiption */
2713 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2715 if (my_strstr(insc, "%all"))
2716 strcat(buff, ", replacing %all with code string representing all abilities,");
2717 else if (my_strstr(insc, "%"))
2718 strcat(buff, ", replacing % with code string representing extra random abilities,");
2720 strcat(buff, " on ");
2725 strcat(buff, "all ");
2726 else for (i = 0; i < before_n && before_str[i]; i++)
2728 strcat(buff, before_str[i]);
2733 strcat(buff, body_str);
2736 for (i = 0; i < after_n && after_str[i]; i++)
2739 strcat(buff, after_str[i]);
2743 for (i = 0; i < whose_n && whose_str[i]; i++)
2746 strcat(buff, " whose ");
2748 strcat(buff, ", and ");
2750 strcat(buff, whose_str[i]);
2753 /* Item name ; whose name is beginning with "str" */
2760 /* whose ..., and which .... */
2761 if (whose_n && which_n)
2762 strcat(buff, ", and ");
2765 for (i = 0; i < which_n && which_str[i]; i++)
2768 strcat(buff, " which ");
2770 strcat(buff, ", and ");
2772 strcat(buff, which_str[i]);
2775 /* Item name ; which have "str" as part of its name */
2778 strncat(buff, str, 80);
2779 strcat(buff, "\" as part of its name");
2783 /* Describe whether it will be displayed on the full map or not */
2784 if (act & DO_DISPLAY)
2786 if (act & DONT_AUTOPICK)
2787 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2788 else if (act & DO_AUTODESTROY)
2789 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2791 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2794 strcat(buff, " Not displayed in the full map.");
2801 * Read whole lines of a file to memory
2803 static cptr *read_text_lines(cptr filename)
2805 cptr *lines_list = NULL;
2811 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2814 fff = my_fopen(buf, "r");
2818 /* Allocate list of pointers */
2819 C_MAKE(lines_list, MAX_LINES, cptr);
2822 while (0 == my_fgets(fff, buf, sizeof(buf)))
2824 lines_list[lines++] = string_make(buf);
2825 if (lines >= MAX_LINES - 1) break;
2828 lines_list[0] = string_make("");
2833 if (!fff) return NULL;
2839 * Copy the default autopick file to the user directory
2841 static void prepare_default_pickpref(void)
2843 static char *messages[] = {
2845 "¤¢¤Ê¤¿¤Ï¡Ö¼«Æ°½¦¤¤¥¨¥Ç¥£¥¿¡×¤ò½é¤á¤Æµ¯Æ°¤·¤Þ¤·¤¿¡£",
2846 "¼«Æ°½¦¤¤¤Î¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤¬¤Þ¤À½ñ¤«¤ì¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢",
2847 "´ðËÜŪ¤Ê¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤òlib/pref/picktype.prf¤«¤é¥³¥Ô¡¼¤·¤Þ¤¹¡£",
2850 "You have activated the Auto-Picker Editor for the first time.",
2851 "Since user pref file for autopick is not yet created,",
2852 "the default setting is loaded from lib/pref/pickpref.prf .",
2861 cptr filename = pickpref_filename(PT_DEFAULT);
2863 /* Display messages */
2864 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2869 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2870 user_fp = my_fopen(buf, "w");
2873 if (!user_fp) return;
2875 /* Write header messages for a notification */
2876 fprintf(user_fp, "#***\n");
2877 for (i = 0; messages[i]; i++)
2879 fprintf(user_fp, "#*** %s\n", messages[i]);
2881 fprintf(user_fp, "#***\n\n\n");
2884 /* Open the default file */
2885 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2886 pref_fp = my_fopen(buf, "r");
2895 /* Copy the contents of default file */
2896 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2897 fprintf(user_fp, "%s\n", buf);
2904 * Read an autopick prefence file to memory
2905 * Prepare default if no user file is found
2907 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2912 /* Try a filename with player name */
2913 *filename_mode_p = PT_WITH_PNAME;
2914 strcpy(buf, pickpref_filename(*filename_mode_p));
2915 lines_list = read_text_lines(buf);
2919 /* Use default name */
2920 *filename_mode_p = PT_DEFAULT;
2921 strcpy(buf, pickpref_filename(*filename_mode_p));
2922 lines_list = read_text_lines(buf);
2927 /* There is no preference file in the user directory */
2929 /* Copy the default autopick file to the user directory */
2930 prepare_default_pickpref();
2932 /* Use default name again */
2933 lines_list = read_text_lines(buf);
2938 /* Allocate list of pointers */
2939 C_MAKE(lines_list, MAX_LINES, cptr);
2940 lines_list[0] = string_make("");
2947 * Write whole lines of memory to a file.
2949 static bool write_text_lines(cptr filename, cptr *lines_list)
2956 /* Build the filename */
2957 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2960 fff = my_fopen(buf, "w");
2963 for (lines = 0; lines_list[lines]; lines++)
2964 my_fputs(fff, lines_list[lines], 1024);
2969 if (!fff) return FALSE;
2975 * Free memory of lines_list.
2977 static void free_text_lines(cptr *lines_list)
2981 for (lines = 0; lines_list[lines]; lines++)
2982 string_free(lines_list[lines]);
2984 /* free list of pointers */
2985 C_FREE((char **)lines_list, MAX_LINES, char *);
2990 * Delete or insert string
2992 static void toggle_keyword(text_body_type *tb, int flg)
2998 /* Some lines are selected */
3001 by1 = MIN(tb->my, tb->cy);
3002 by2 = MAX(tb->my, tb->cy);
3005 /* No mark -- Select current line */
3006 else /* if (!tb->mark) */
3012 /* Set/Reset flag of each line */
3013 for (y = by1; y <= by2; y++)
3015 autopick_type an_entry, *entry = &an_entry;
3017 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
3019 string_free(tb->lines_list[y]);
3023 /* Add? or Remove? */
3024 if (!IS_FLG(flg)) add = TRUE;
3027 /* No more change */
3031 /* You can use only one noun flag */
3032 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3035 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3039 /* You can use only one identify state flag */
3040 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
3043 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
3047 /* You can use only one flag in artifact/ego/nameless */
3048 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
3051 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
3055 /* You can use only one flag in rare/common */
3056 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
3059 for (i = FLG_RARE; i <= FLG_COMMON; i++)
3063 if (add) ADD_FLG(flg);
3066 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3069 tb->dirty_flags |= DIRTY_ALL;
3071 /* Text is changed */
3078 * Change command letter
3080 static void toggle_command_letter(text_body_type *tb, byte flg)
3082 autopick_type an_entry, *entry = &an_entry;
3087 /* Some lines are selected */
3090 by1 = MIN(tb->my, tb->cy);
3091 by2 = MAX(tb->my, tb->cy);
3094 /* No mark -- Select current line */
3095 else /* if (!tb->mark) */
3101 /* Set/Reset flag of each line */
3102 for (y = by1; y <= by2; y++)
3106 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3108 string_free(tb->lines_list[y]);
3112 /* Add? or Remove? */
3113 if (!(entry->action & flg)) add = TRUE;
3116 /* No more change */
3120 /* Count number of letter (by negative number) */
3121 if (entry->action & DONT_AUTOPICK) wid--;
3122 else if (entry->action & DO_AUTODESTROY) wid--;
3123 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3124 if (!(entry->action & DO_DISPLAY)) wid--;
3126 /* Set/Reset the flag */
3127 if (flg != DO_DISPLAY)
3129 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3130 if (add) entry->action |= flg;
3131 else entry->action |= DO_AUTOPICK;
3135 entry->action &= ~(DO_DISPLAY);
3136 if (add) entry->action |= flg;
3139 /* Correct cursor location */
3142 if (entry->action & DONT_AUTOPICK) wid++;
3143 else if (entry->action & DO_AUTODESTROY) wid++;
3144 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3145 if (!(entry->action & DO_DISPLAY)) wid++;
3147 if (wid > 0) tb->cx++;
3148 if (wid < 0 && tb->cx > 0) tb->cx--;
3151 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3154 tb->dirty_flags |= DIRTY_ALL;
3156 /* Text is changed */
3162 * Delete or insert string
3164 static void add_keyword(text_body_type *tb, int flg)
3168 /* Some lines are selected */
3171 by1 = MIN(tb->my, tb->cy);
3172 by2 = MAX(tb->my, tb->cy);
3175 /* No mark -- Select current line */
3176 else /* if (!tb->mark) */
3182 /* Set/Reset flag of each line */
3183 for (y = by1; y <= by2; y++)
3185 autopick_type an_entry, *entry = &an_entry;
3187 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3189 /* There is the flag already */
3192 /* Free memory for the entry */
3193 autopick_free_entry(entry);
3198 string_free(tb->lines_list[y]);
3200 /* Remove all noun flag */
3201 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3204 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3210 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3213 tb->dirty_flags |= DIRTY_ALL;
3215 /* Text is changed */
3222 * Check if this line is expression or not.
3223 * And update it if it is.
3225 static void check_expression_line(text_body_type *tb, int y)
3227 cptr s = tb->lines_list[y];
3229 if ((s[0] == '?' && s[1] == ':') ||
3230 (tb->states[y] & LSTAT_BYPASS))
3232 /* Expressions need re-evaluation */
3233 tb->dirty_flags |= DIRTY_EXPRESSION;
3239 * Add an empty line at the last of the file
3241 static bool add_empty_line(text_body_type *tb)
3245 for (k = 0; tb->lines_list[k]; k++)
3246 /* count number of lines */ ;
3248 /* Too many lines! */
3249 if (k >= MAX_LINES - 2) return FALSE;
3251 /* The last line is already empty */
3252 if (!tb->lines_list[k-1][0]) return FALSE;
3254 /* Create new empty line */
3255 tb->lines_list[k] = string_make("");
3257 /* Expressions need re-evaluation */
3258 tb->dirty_flags |= DIRTY_EXPRESSION;
3260 /* Text is changed */
3263 /* A line is added */
3269 * Insert return code and split the line
3271 static bool insert_return_code(text_body_type *tb)
3273 char buf[MAX_LINELEN];
3276 for (k = 0; tb->lines_list[k]; k++)
3277 /* count number of lines */ ;
3279 if (k >= MAX_LINES - 2) return FALSE;
3282 /* Move down lines */
3283 for (; tb->cy < k; k--)
3285 tb->lines_list[k+1] = tb->lines_list[k];
3286 tb->states[k+1] = tb->states[k];
3289 /* Split current line */
3290 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3293 if (iskanji(tb->lines_list[tb->cy][i]))
3294 buf[j++] = tb->lines_list[tb->cy][i++];
3296 buf[j++] = tb->lines_list[tb->cy][i];
3299 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3300 string_free(tb->lines_list[tb->cy]);
3301 tb->lines_list[tb->cy] = string_make(buf);
3303 /* Expressions need re-evaluation */
3304 tb->dirty_flags |= DIRTY_EXPRESSION;
3306 /* Text is changed */
3314 * Choose an item and get auto-picker entry from it.
3316 static object_type *choose_object(cptr q, cptr s)
3320 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3322 /* Get the item (in the pack) */
3323 if (item >= 0) return &inventory[item];
3325 /* Get the item (on the floor) */
3326 else return &o_list[0 - item];
3331 * Choose an item and get auto-picker entry from it.
3333 static bool entry_from_choosed_object(autopick_type *entry)
3340 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3341 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3343 q = "Enter which item? ";
3344 s = "You have nothing to enter.";
3346 o_ptr = choose_object(q, s);
3347 if (!o_ptr) return FALSE;
3349 autopick_entry_from_object(entry, o_ptr);
3355 * Choose an item for search
3357 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3359 char buf[MAX_NLEN+20];
3365 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3366 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3368 q = "Enter which item? ";
3369 s = "You have nothing to enter.";
3371 o_ptr = choose_object(q, s);
3372 if (!o_ptr) return 0;
3376 string_free(*search_strp);
3377 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3378 *search_strp = string_make(format("<%s>", buf));
3384 * Prepare for search by destroyed object
3386 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3388 char buf[MAX_NLEN+20];
3390 if (!autopick_last_destroyed_object.k_idx) return 0;
3392 *o_handle = &autopick_last_destroyed_object;
3394 string_free(*search_strp);
3395 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3396 *search_strp = string_make(format("<%s>", buf));
3402 * Choose an item or string for search
3404 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3410 * TERM_YELLOW : Overwrite mode
3411 * TERM_WHITE : Insert mode
3413 byte color = TERM_YELLOW;
3414 char buf[MAX_NLEN+20];
3418 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3420 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3422 int col = sizeof(prompt) - 1;
3424 /* Prepare string buffer for edit */
3425 if (*search_strp) strcpy(buf, *search_strp);
3428 /* Object searching mode */
3431 color = TERM_L_GREEN;
3434 /* Display prompt */
3444 /* Display the string */
3445 Term_erase(col, 0, 255);
3446 Term_putstr(col, 0, -1, color, buf);
3449 Term_gotoxy(col + pos, 0);
3451 /* Get a special key code */
3452 skey = inkey_special(TRUE);
3454 /* Analyze the key */
3462 /* Now on insert mode */
3465 /* No move at beginning of line */
3466 if (0 == pos) break;
3470 int next_pos = i + 1;
3473 if (iskanji(buf[i])) next_pos++;
3476 /* Is there the cursor at next position? */
3477 if (next_pos >= pos) break;
3483 /* Get previous position */
3491 /* Now on insert mode */
3494 /* No move at end of line */
3495 if ('\0' == buf[pos]) break;
3499 if (iskanji(buf[pos])) pos += 2;
3517 if (*o_handle) return (back ? -1 : 1);
3518 string_free(*search_strp);
3519 *search_strp = string_make(buf);
3521 return (back ? -1 : 1);
3525 return get_object_for_search(o_handle, search_strp);
3528 /* Prepare string for destroyed object if there is one. */
3529 if (get_destroyed_object_for_search(o_handle, search_strp))
3539 /* Now on insert mode */
3542 /* No move at beginning of line */
3543 if (0 == pos) break;
3547 int next_pos = i + 1;
3550 if (iskanji(buf[i])) next_pos++;
3553 /* Is there the cursor at next position? */
3554 if (next_pos >= pos) break;
3560 /* Get previous position */
3563 /* Fall through to 'Delete key' */
3572 /* Now on insert mode */
3575 /* No move at end of line */
3576 if ('\0' == buf[pos]) break;
3578 /* Position of next character */
3582 /* Next character is one more byte away */
3583 if (iskanji(buf[pos])) src++;
3588 /* Move characters at src to dst */
3589 while ('\0' != (buf[dst++] = buf[src++]))
3597 /* Insert a character */
3602 /* Ignore special keys */
3603 if (skey & SKEY_MASK) break;
3605 /* Get a character code */
3608 /* Was non insert mode? */
3609 if (color != TERM_WHITE)
3611 /* Was object searching mode */
3612 if (color == TERM_L_GREEN)
3614 /* Cancel the mode */
3617 /* Remove indicating string */
3618 string_free(*search_strp);
3619 *search_strp = NULL;
3622 /* Overwrite default string */
3625 /* Go to insert mode */
3629 /* Save right part of string */
3630 strcpy(tmp, buf + pos);
3636 /* Bypass macro processing */
3654 if (pos < len && (isprint(c) || iskana(c)))
3656 if (pos < len && isprint(c))
3670 /* Write back the left part of string */
3671 my_strcat(buf, tmp, len + 1);
3678 /* Object searching mode was cancelled? */
3679 if (*o_handle && color != TERM_L_GREEN)
3681 /* Cancel the mode */
3684 /* Remove indicating string */
3686 string_free(*search_strp);
3687 *search_strp = NULL;
3692 } /* while (TRUE) */
3697 * Search next line matches for o_ptr
3699 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3701 autopick_type an_entry, *entry = &an_entry;
3702 char o_name[MAX_NLEN];
3703 int bypassed_cy = -1;
3705 /* Start searching from current cursor position */
3708 /* Prepare object name string first */
3709 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3711 /* Convert the string to lower case */
3712 str_tolower(o_name);
3721 if (!tb->lines_list[++i]) break;
3728 /* Is this line is a correct entry? */
3729 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3731 /* Does this line match to the object? */
3732 match = is_autopick_aux(o_ptr, entry, o_name);
3733 autopick_free_entry(entry);
3734 if (!match) continue;
3736 /* Found a line but it's inactive */
3737 if (tb->states[i] & LSTAT_BYPASS)
3739 /* If it is first found, remember it */
3740 if (bypassed_cy == -1) bypassed_cy = i;
3743 /* Found an active line! */
3746 /* Move to this line */
3750 if (bypassed_cy != -1)
3752 /* Mark as some lines are skipped */
3753 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3761 if (bypassed_cy != -1)
3763 /* Move to the remembered line */
3765 tb->cy = bypassed_cy;
3767 /* Mark as this line is inactive */
3768 tb->dirty_flags |= DIRTY_INACTIVE;
3773 /* Mark as NOT FOUND */
3774 tb->dirty_flags |= DIRTY_NOT_FOUND;
3782 * Search next line matches to the string
3784 static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
3786 int bypassed_cy = -1;
3787 int bypassed_cx = 0;
3789 /* Start searching from current cursor position */
3799 if (!tb->lines_list[++i]) break;
3806 /* Look for the string pattern */
3807 pos = my_strstr(tb->lines_list[i], search_str);
3812 /* Found a line but it's inactive */
3813 if ((tb->states[i] & LSTAT_BYPASS) &&
3814 !(tb->states[i] & LSTAT_EXPRESSION))
3816 /* If it is first found, remember it */
3817 if (bypassed_cy == -1)
3820 bypassed_cx = (int)(pos - tb->lines_list[i]);
3824 /* Found an active line! */
3827 /* Move to this location */
3828 tb->cx = (int)(pos - tb->lines_list[i]);
3831 if (bypassed_cy != -1)
3833 /* Mark as some lines are skipped */
3834 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3842 if (bypassed_cy != -1)
3844 /* Move to the remembered line */
3845 tb->cx = bypassed_cx;
3846 tb->cy = bypassed_cy;
3848 /* Mark as this line is inactive */
3849 tb->dirty_flags |= DIRTY_INACTIVE;
3854 /* Mark as NOT FOUND */
3855 tb->dirty_flags |= DIRTY_NOT_FOUND;
3865 * Editor command id's
3868 #define EC_SAVEQUIT 2
3879 #define EC_PGDOWN 13
3881 #define EC_BOTTOM 15
3886 #define EC_KILL_LINE 20
3887 #define EC_DELETE_CHAR 21
3888 #define EC_BACKSPACE 22
3889 #define EC_SEARCH_STR 23
3890 #define EC_SEARCH_FORW 24
3891 #define EC_SEARCH_BACK 25
3892 #define EC_SEARCH_OBJ 26
3893 #define EC_SEARCH_DESTROYED 27
3894 #define EC_INSERT_OBJECT 28
3895 #define EC_INSERT_DESTROYED 29
3896 #define EC_INSERT_BLOCK 30
3897 #define EC_INSERT_MACRO 31
3898 #define EC_INSERT_KEYMAP 32
3899 #define EC_CL_AUTOPICK 33
3900 #define EC_CL_DESTROY 34
3901 #define EC_CL_LEAVE 35
3902 #define EC_CL_QUERY 36
3903 #define EC_CL_NO_DISP 37
3904 #define EC_OK_COLLECTING 38
3905 #define EC_IK_UNAWARE 39
3906 #define EC_IK_UNIDENTIFIED 40
3907 #define EC_IK_IDENTIFIED 41
3908 #define EC_IK_STAR_IDENTIFIED 42
3909 #define EC_OK_BOOSTED 43
3910 #define EC_OK_MORE_DICE 44
3911 #define EC_OK_MORE_BONUS 45
3912 #define EC_OK_WORTHLESS 46
3913 #define EC_OK_ARTIFACT 47
3914 #define EC_OK_EGO 48
3915 #define EC_OK_GOOD 49
3916 #define EC_OK_NAMELESS 50
3917 #define EC_OK_AVERAGE 51
3918 #define EC_OK_RARE 52
3919 #define EC_OK_COMMON 53
3920 #define EC_OK_WANTED 54
3921 #define EC_OK_UNIQUE 55
3922 #define EC_OK_HUMAN 56
3923 #define EC_OK_UNREADABLE 57
3924 #define EC_OK_REALM1 58
3925 #define EC_OK_REALM2 59
3926 #define EC_OK_FIRST 60
3927 #define EC_OK_SECOND 61
3928 #define EC_OK_THIRD 62
3929 #define EC_OK_FOURTH 63
3930 #define EC_KK_WEAPONS 64
3931 #define EC_KK_FAVORITE_WEAPONS 65
3932 #define EC_KK_ARMORS 66
3933 #define EC_KK_MISSILES 67
3934 #define EC_KK_DEVICES 68
3935 #define EC_KK_LIGHTS 69
3936 #define EC_KK_JUNKS 70
3937 #define EC_KK_CORPSES 71
3938 #define EC_KK_SPELLBOOKS 72
3939 #define EC_KK_SHIELDS 73
3940 #define EC_KK_BOWS 74
3941 #define EC_KK_RINGS 75
3942 #define EC_KK_AMULETS 76
3943 #define EC_KK_SUITS 77
3944 #define EC_KK_CLOAKS 78
3945 #define EC_KK_HELMS 79
3946 #define EC_KK_GLOVES 80
3947 #define EC_KK_BOOTS 81
3953 static char MN_QUIT[] = "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»";
3954 static char MN_SAVEQUIT[] = "¥»¡¼¥Ö¤·¤Æ½ªÎ»";
3955 static char MN_REVERT[] = "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ";
3956 static char MN_HELP[] = "¥Ø¥ë¥×";
3958 static char MN_MOVE[] = "¥«¡¼¥½¥ë°ÜÆ°";
3959 static char MN_LEFT[] = "º¸ (¢«Ìð°õ¥¡¼)";
3960 static char MN_DOWN[] = "²¼ (¢Ìð°õ¥¡¼)";
3961 static char MN_UP[] = "¾å (¢¬Ìð°õ¥¡¼)";
3962 static char MN_RIGHT[] = "±¦ (¢ªÌð°õ¥¡¼)";
3963 static char MN_BOL[] = "¹Ô¤ÎÀèƬ";
3964 static char MN_EOL[] = "¹Ô¤Î½ªÃ¼";
3965 static char MN_PGUP[] = "¾å¤Î¥Ú¡¼¥¸ (PageUp¥¡¼)";
3966 static char MN_PGDOWN[] = "²¼¤Î¥Ú¡¼¥¸ (PageDown¥¡¼)";
3967 static char MN_TOP[] = "1¹ÔÌܤذÜÆ° (Home¥¡¼)";
3968 static char MN_BOTTOM[] = "ºÇ²¼¹Ô¤Ø°ÜÆ°(End¥¡¼)";
3970 static char MN_EDIT[] = "ÊÔ½¸";
3971 static char MN_CUT[] = "¥«¥Ã¥È";
3972 static char MN_COPY[] = "¥³¥Ô¡¼";
3973 static char MN_PASTE[] = "¥Ú¡¼¥¹¥È";
3974 static char MN_BLOCK[] = "ÁªÂòÈϰϤλØÄê";
3975 static char MN_KILL_LINE[] = "¹Ô¤Î»Ä¤ê¤òºï½ü";
3976 static char MN_DELETE_CHAR[] = "1ʸ»úºï½ü";
3977 static char MN_BACKSPACE[] = "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹";
3978 static char MN_RETURN[] = "²þ¹Ô";
3980 static char MN_SEARCH[] = "¸¡º÷";
3981 static char MN_SEARCH_STR[] = "ʸ»úÎó¤Ç¸¡º÷";
3982 static char MN_SEARCH_FORW[] = "Á°Êý¤ØºÆ¸¡º÷";
3983 static char MN_SEARCH_BACK[] = "¸åÊý¤ØºÆ¸¡º÷";
3984 static char MN_SEARCH_OBJ[] = "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷";
3985 static char MN_SEARCH_DESTROYED[] = "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷";
3987 static char MN_INSERT[] = "¿§¡¹ÁÞÆþ";
3988 static char MN_INSERT_OBJECT[] = "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ";
3989 static char MN_INSERT_DESTROYED[] = "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ";
3990 static char MN_INSERT_BLOCK[] = "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ";
3991 static char MN_INSERT_MACRO[] = "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ";
3992 static char MN_INSERT_KEYMAP[] = "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ";
3994 static char MN_COMMAND_LETTER[] = "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò";
3995 static char MN_CL_AUTOPICK[] = "¡Ö ¡× (¼«Æ°½¦¤¤)";
3996 static char MN_CL_DESTROY[] = "¡Ö!¡× (¼«Æ°Ç˲õ)";
3997 static char MN_CL_LEAVE[] = "¡Ö~¡× (ÊüÃÖ)";
3998 static char MN_CL_QUERY[] = "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)";
3999 static char MN_CL_NO_DISP[] = "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)";
4001 static char MN_ADJECTIVE_GEN[] = "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò";
4002 static char MN_RARE[] = "¥ì¥¢¤Ê (ÁõÈ÷)";
4003 static char MN_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿ (ÁõÈ÷)";
4005 static char MN_ADJECTIVE_SPECIAL[] = "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò";
4006 static char MN_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)";
4007 static char MN_MORE_DICE[] = "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)";
4008 static char MN_MORE_BONUS[] = "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)";
4009 static char MN_WANTED[] = "¾Þ¶â¼ó¤Î (»àÂÎ)";
4010 static char MN_UNIQUE[] = "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)";
4011 static char MN_HUMAN[] = "¿Í´Ö¤Î (»àÂÎ)";
4012 static char MN_UNREADABLE[] = "Æɤá¤Ê¤¤ (ËâË¡½ñ)";
4013 static char MN_REALM1[] = "Âè°ìÎΰè¤Î (ËâË¡½ñ)";
4014 static char MN_REALM2[] = "ÂèÆóÎΰè¤Î (ËâË¡½ñ)";
4015 static char MN_FIRST[] = "1ºýÌܤΠ(ËâË¡½ñ)";
4016 static char MN_SECOND[] = "2ºýÌܤΠ(ËâË¡½ñ)";
4017 static char MN_THIRD[] = "3ºýÌܤΠ(ËâË¡½ñ)";
4018 static char MN_FOURTH[] = "4ºýÌܤΠ(ËâË¡½ñ)";
4020 static char MN_NOUN[] = "̾»ì¤ÎÁªÂò";
4024 static char MN_QUIT[] = "Quit without save";
4025 static char MN_SAVEQUIT[] = "Save & Quit";
4026 static char MN_REVERT[] = "Revert all changes";
4027 static char MN_HELP[] = "Help";
4029 static char MN_MOVE[] = "Move cursor";
4030 static char MN_LEFT[] = "Left (Left Arrow key)";
4031 static char MN_DOWN[] = "Down (Down Arrow key)";
4032 static char MN_UP[] = "Up (Up Arrow key)";
4033 static char MN_RIGHT[] = "Right (Right Arrow key)";
4034 static char MN_BOL[] = "Beggining of line";
4035 static char MN_EOL[] = "End of line";
4036 static char MN_PGUP[] = "Page up (PageUp key)";
4037 static char MN_PGDOWN[] = "Page down(PageDown key)";
4038 static char MN_TOP[] = "Top (Home key)";
4039 static char MN_BOTTOM[] = "Bottom (End key)";
4041 static char MN_EDIT[] = "Edit";
4042 static char MN_CUT[] = "Cut";
4043 static char MN_COPY[] = "Copy";
4044 static char MN_PASTE[] = "Paste";
4045 static char MN_BLOCK[] = "Select block";
4046 static char MN_KILL_LINE[] = "Kill rest of line";
4047 static char MN_DELETE_CHAR[] = "Delete character";
4048 static char MN_BACKSPACE[] = "Backspace";
4049 static char MN_RETURN[] = "Return";
4051 static char MN_SEARCH[] = "Search";
4052 static char MN_SEARCH_STR[] = "Search by string";
4053 static char MN_SEARCH_FORW[] = "Search forward";
4054 static char MN_SEARCH_BACK[] = "Search backward";
4055 static char MN_SEARCH_OBJ[] = "Search by inventory object";
4056 static char MN_SEARCH_DESTROYED[] = "Search by destroyed object";
4058 static char MN_INSERT[] = "Insert...";
4059 static char MN_INSERT_OBJECT[] = "Insert name of choosen object";
4060 static char MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
4061 static char MN_INSERT_BLOCK[] = "Insert conditional block";
4062 static char MN_INSERT_MACRO[] = "Insert a macro definition";
4063 static char MN_INSERT_KEYMAP[] = "Insert a keymap definition";
4065 static char MN_COMMAND_LETTER[] = "Command letter";
4066 static char MN_CL_AUTOPICK[] = "' ' (Auto pick)";
4067 static char MN_CL_DESTROY[] = "'!' (Auto destroy)";
4068 static char MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
4069 static char MN_CL_QUERY[] = "';' (Query to pick up)";
4070 static char MN_CL_NO_DISP[] = "'(' (No display on the large map)";
4072 static char MN_ADJECTIVE_GEN[] = "Adjective (general)";
4073 static char MN_RARE[] = "rare (equipments)";
4074 static char MN_COMMON[] = "common (equipments)";
4076 static char MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
4077 static char MN_BOOSTED[] = "dice boosted (weapons)";
4078 static char MN_MORE_DICE[] = "more than # dice (weapons)";
4079 static char MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
4080 static char MN_WANTED[] = "wanted (corpse)";
4081 static char MN_UNIQUE[] = "unique (corpse)";
4082 static char MN_HUMAN[] = "human (corpse)";
4083 static char MN_UNREADABLE[] = "unreadable (spellbooks)";
4084 static char MN_REALM1[] = "realm1 (spellbooks)";
4085 static char MN_REALM2[] = "realm2 (spellbooks)";
4086 static char MN_FIRST[] = "first (spellbooks)";
4087 static char MN_SECOND[] = "second (spellbooks)";
4088 static char MN_THIRD[] = "third (spellbooks)";
4089 static char MN_FOURTH[] = "fourth (spellbooks)";
4091 static char MN_NOUN[] = "Keywords (noun)";
4101 } command_menu_type;
4104 command_menu_type menu_data[] =
4106 {MN_HELP, 0, -1, EC_HELP},
4107 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4108 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4109 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4111 {MN_EDIT, 0, -1, -1},
4112 {MN_CUT, 1, KTRL('x'), EC_CUT},
4113 {MN_COPY, 1, KTRL('c'), EC_COPY},
4114 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4115 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4116 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4117 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4118 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4119 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4120 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4122 {MN_SEARCH, 0, -1, -1},
4123 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4124 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4125 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4126 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4127 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4129 {MN_MOVE, 0, -1, -1},
4130 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4131 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4132 {MN_UP, 1, KTRL('p'), EC_UP},
4133 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4134 {MN_BOL, 1, KTRL('a'), EC_BOL},
4135 {MN_EOL, 1, KTRL('e'), EC_EOL},
4136 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4137 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4138 {MN_TOP, 1, KTRL('t'), EC_TOP},
4139 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4141 {MN_INSERT, 0, -1, -1},
4142 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4143 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4144 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4145 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4146 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4148 {MN_ADJECTIVE_GEN, 0, -1, -1},
4149 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4150 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4151 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4152 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4153 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4154 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4155 {KEY_EGO, 1, -1, EC_OK_EGO},
4156 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4157 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4158 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4159 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4160 {MN_RARE, 1, -1, EC_OK_RARE},
4161 {MN_COMMON, 1, -1, EC_OK_COMMON},
4163 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4164 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4165 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4166 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4167 {MN_WANTED, 1, -1, EC_OK_WANTED},
4168 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4169 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4170 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4171 {MN_REALM1, 1, -1, EC_OK_REALM1},
4172 {MN_REALM2, 1, -1, EC_OK_REALM2},
4173 {MN_FIRST, 1, -1, EC_OK_FIRST},
4174 {MN_SECOND, 1, -1, EC_OK_SECOND},
4175 {MN_THIRD, 1, -1, EC_OK_THIRD},
4176 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4178 {MN_NOUN, 0, -1, -1},
4179 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4180 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4181 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4182 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4183 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4184 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4185 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4186 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4187 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4188 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4189 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4190 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4191 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4192 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4193 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4194 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4195 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4196 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4198 {MN_COMMAND_LETTER, 0, -1, -1},
4199 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4200 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4201 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4202 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4203 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4205 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4212 * Find a command by 'key'.
4214 static int get_com_id(char key)
4218 for (i = 0; menu_data[i].name; i++)
4220 if (menu_data[i].key == key)
4222 return menu_data[i].com_id;
4231 * Display the menu, and get a command
4233 static int do_command_menu(int level, int start)
4238 int col0 = 5 + level*7;
4239 int row0 = 1 + level*3;
4241 int menu_id_list[26];
4243 char linestr[MAX_LINELEN];
4245 /* Get max length */
4247 for (i = start; menu_data[i].level >= level; i++)
4251 /* Ignore lower level sub menus */
4252 if (menu_data[i].level > level) continue;
4254 len = strlen(menu_data[i].name);
4255 if (len > max_len) max_len = len;
4257 menu_id_list[menu_key] = i;
4261 while (menu_key < 26)
4263 menu_id_list[menu_key] = -1;
4267 /* Extra space for displaying menu key and command key */
4268 max_menu_wid = max_len + 3 + 3;
4270 /* Prepare box line */
4272 strcat(linestr, "+");
4273 for (i = 0; i < max_menu_wid + 2; i++)
4275 strcat(linestr, "-");
4277 strcat(linestr, "+");
4287 int row1 = row0 + 1;
4290 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4292 /* Draw menu items */
4294 for (i = start; menu_data[i].level >= level; i++)
4296 char com_key_str[3];
4299 /* Ignore lower level sub menus */
4300 if (menu_data[i].level > level) continue;
4302 if (menu_data[i].com_id == -1)
4305 strcpy(com_key_str, "¢§");
4307 strcpy(com_key_str, ">");
4310 else if (menu_data[i].key != -1)
4312 com_key_str[0] = '^';
4313 com_key_str[1] = menu_data[i].key + '@';
4314 com_key_str[2] = '\0';
4318 com_key_str[0] = '\0';
4321 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4323 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4328 /* Draw bottom line */
4329 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4331 /* The menu was shown */
4335 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
4337 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
4341 if (key == ESCAPE) return 0;
4343 if ('a' <= key && key <= 'z')
4345 menu_id = menu_id_list[key - 'a'];
4349 com_id = menu_data[menu_id].com_id;
4353 com_id = do_command_menu(level + 1, menu_id + 1);
4355 if (com_id) return com_id;
4367 com_id = get_com_id(key);
4368 if (com_id) return com_id;
4375 static chain_str_type *new_chain_str(cptr str)
4377 chain_str_type *chain;
4379 size_t len = strlen(str);
4381 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4383 strcpy(chain->s, str);
4390 static void kill_yank_chain(text_body_type *tb)
4392 chain_str_type *chain = tb->yank;
4394 tb->yank_eol = TRUE;
4398 chain_str_type *next = chain->next;
4399 size_t len = strlen(chain->s);
4401 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4408 static void add_str_to_yank(text_body_type *tb, cptr str)
4410 chain_str_type *chain;
4412 tb->yank_eol = FALSE;
4414 if (NULL == tb->yank)
4416 tb->yank = new_chain_str(str);
4426 chain->next = new_chain_str(str);
4431 chain = chain->next;
4437 * Do work for the copy editor-command
4439 static void copy_text_to_yank(text_body_type *tb)
4441 int len = strlen(tb->lines_list[tb->cy]);
4443 /* Correct cursor location */
4444 if (tb->cx > len) tb->cx = len;
4446 /* Use single line? */
4449 /* Select a single line */
4455 /* Kill old yank buffer */
4456 kill_yank_chain(tb);
4459 /* Single line case */
4460 if (tb->my == tb->cy)
4463 char buf[MAX_LINELEN];
4464 int bx1 = MIN(tb->mx, tb->cx);
4465 int bx2 = MAX(tb->mx, tb->cx);
4467 /* Correct fake cursor position */
4468 if (bx2 > len) bx2 = len;
4470 /* Whole part of this line is selected */
4471 if (bx1 == 0 && bx2 == len)
4473 /* Copy this line */
4474 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4476 /* Add end of line to the buffer */
4477 add_str_to_yank(tb, "");
4480 /* Segment of this line is selected */
4483 for (i = 0; i < bx2 - bx1; i++)
4485 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4489 /* Copy this segment of line */
4490 add_str_to_yank(tb, buf);
4494 /* Multiple lines case */
4495 else /* if (tb->my != tb->cy) */
4499 int by1 = MIN(tb->my, tb->cy);
4500 int by2 = MAX(tb->my, tb->cy);
4503 for (y = by1; y <= by2; y++)
4505 /* Copy this line */
4506 add_str_to_yank(tb, tb->lines_list[y]);
4509 /* Add final end of line to the buffer */
4510 add_str_to_yank(tb, "");
4513 /* Disable selection */
4517 tb->dirty_flags |= DIRTY_ALL;
4521 #define DESCRIPT_HGT 3
4526 static void draw_text_editor(text_body_type *tb)
4529 int by1 = 0, by2 = 0;
4532 Term_get_size(&tb->wid, &tb->hgt);
4535 * Top line (-1), description line (-3), separator (-1)
4538 tb->hgt -= 2 + DESCRIPT_HGT;
4541 /* Don't let cursor at second byte of kanji */
4542 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4543 if (iskanji(tb->lines_list[tb->cy][i]))
4549 * Move to a correct position in the
4552 if (i & 1) tb->cx--;
4559 /* Scroll if necessary */
4560 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4561 tb->upper = tb->cy - (tb->hgt)/2;
4564 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4565 tb->left = tb->cx - (tb->wid)*2/3;
4569 /* Redraw whole window after resize */
4570 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4571 tb->dirty_flags |= DIRTY_SCREEN;
4573 /* Redraw all text after scroll */
4574 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4575 tb->dirty_flags |= DIRTY_ALL;
4578 if (tb->dirty_flags & DIRTY_SCREEN)
4580 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4586 /* Redraw mode line */
4587 if (tb->dirty_flags & DIRTY_MODE)
4589 char buf[MAX_LINELEN];
4591 int sepa_length = tb->wid;
4594 for (i = 0; i < sepa_length; i++)
4598 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4601 if (tb->dirty_flags & DIRTY_EXPRESSION)
4606 for (y = 0; tb->lines_list[y]; y++)
4610 cptr s = tb->lines_list[y];
4614 /* Update this line's state */
4615 tb->states[y] = state;
4617 if (*s++ != '?') continue;
4618 if (*s++ != ':') continue;
4620 /* Lines below this line are auto-registered */
4621 if (streq(s, "$AUTOREGISTER"))
4622 state |= LSTAT_AUTOREGISTER;
4625 ss = (char *)string_make(s);
4628 /* Parse the expr */
4629 v = process_pref_file_expr(&ss, &f);
4632 if (streq(v, "0")) state |= LSTAT_BYPASS;
4633 else state &= ~LSTAT_BYPASS;
4635 /* Cannot use string_free() because the string was "destroyed" */
4636 C_FREE(s_keep, s_len + 1, char);
4638 /* Re-update this line's state */
4639 tb->states[y] = state | LSTAT_EXPRESSION;
4642 tb->dirty_flags |= DIRTY_ALL;
4647 tb->dirty_flags |= DIRTY_ALL;
4649 by1 = MIN(tb->my, tb->cy);
4650 by2 = MAX(tb->my, tb->cy);
4653 /* Dump up to tb->hgt lines of messages */
4654 for (i = 0; i < tb->hgt; i++)
4660 int y = tb->upper+i;
4662 /* clean or dirty? */
4663 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4666 msg = tb->lines_list[y];
4669 /* Apply horizontal scroll */
4670 for (j = 0; *msg; msg++, j++)
4672 if (j == tb->left) break;
4688 Term_erase(0, i + 1, tb->wid);
4690 if (tb->states[y] & LSTAT_AUTOREGISTER)
4692 /* Warning color -- These lines will be deleted later */
4697 /* Bypassed line will be displayed by darker color */
4698 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4699 else color = TERM_WHITE;
4702 /* No mark or Out of mark */
4703 if (!tb->mark || (y < by1 || by2 < y))
4705 /* Dump the messages, bottom to top */
4706 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4709 /* Multiple lines selected */
4710 else if (by1 != by2)
4712 /* Dump the messages, bottom to top */
4713 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4716 /* Single line selected */
4719 int x0 = leftcol + tb->left;
4720 int len = strlen(tb->lines_list[tb->cy]);
4721 int bx1 = MIN(tb->mx, tb->cx);
4722 int bx2 = MAX(tb->mx, tb->cx);
4724 /* Correct cursor location */
4725 if (bx2 > len) bx2 = len;
4727 Term_gotoxy(leftcol, i + 1);
4728 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4729 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4730 Term_addstr(-1, color, msg + (bx2 - x0));
4734 for (; i < tb->hgt; i++)
4737 Term_erase(0, i + 1, tb->wid);
4740 /* Display information when updated */
4741 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4743 autopick_type an_entry, *entry = &an_entry;
4744 cptr str1 = NULL, str2 = NULL;
4747 /* Clear information line */
4748 for (i = 0; i < DESCRIPT_HGT; i++)
4751 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4754 /* Display information */
4755 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4758 str1 = format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str);
4760 str1 = format("Pattern not found: %s", tb->search_str);
4763 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4766 str1 = format("̵¸ú¾õÂ֤ιԤò¥¹¥¥Ã¥×¤·¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4768 str1 = format("Some inactive lines are skipped. (Searching %s)", tb->search_str);
4771 else if (tb->dirty_flags & DIRTY_INACTIVE)
4774 str1 = format("̵¸ú¾õÂ֤ιԤÀ¤±¤¬¸«ÉÕ¤«¤ê¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4776 str1 = format("Found only an inactive line. (Searching %s)", tb->search_str);
4779 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4782 str1 = "¸¡º÷¤¹¤ë¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó(^S ¤Ç¸¡º÷)¡£";
4784 str1 = "No pattern to search. (Press ^S to search.)";
4787 else if (tb->lines_list[tb->cy][0] == '#')
4790 str1 = "¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£";
4792 str1 = "This line is a comment.";
4795 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4797 switch(tb->lines_list[tb->cy][0])
4801 str1 = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4803 str1 = "This line is a Conditional Expression.";
4809 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4811 str1 = "This line defines a Macro action.";
4816 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4818 str1 = "This line defines a Macro trigger key.";
4823 str1 = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4825 str1 = "This line defines a Keymap.";
4830 switch(tb->lines_list[tb->cy][0])
4833 if (tb->states[tb->cy] & LSTAT_BYPASS)
4836 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4838 str2 = "The expression is 'False'(=0) currently.";
4844 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4846 str2 = "The expression is 'True'(=1) currently.";
4852 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4855 str2 = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4857 str2 = "This line will be delete later.";
4861 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4864 str2 = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4866 str2 = "This line is bypassed currently.";
4873 /* Get description of an autopicker preference line */
4874 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4876 char buf[MAX_LINELEN];
4877 char temp[MAX_LINELEN];
4880 describe_autopick(buf, entry);
4882 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4885 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4887 strcat(buf, " This line will be delete later.");
4891 if (tb->states[tb->cy] & LSTAT_BYPASS)
4894 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4896 strcat(buf, " This line is bypassed currently.");
4900 roff_to_buf(buf, 81, temp, sizeof(temp));
4902 for (i = 0; i < 3; i++)
4908 prt(t, tb->hgt +1 + 1 + i, 0);
4912 autopick_free_entry(entry);
4915 /* Draw the first line */
4916 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4918 /* Draw the second line */
4919 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4925 * Kill segment of a line
4927 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4929 char buf[MAX_LINELEN];
4930 cptr s = tb->lines_list[y];
4934 /* Kill whole line? */
4935 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4939 string_free(tb->lines_list[y]);
4941 /* Shift lines up */
4942 for (i = y; tb->lines_list[i+1]; i++)
4943 tb->lines_list[i] = tb->lines_list[i+1];
4944 tb->lines_list[i] = NULL;
4946 /* Expressions need re-evaluation */
4947 tb->dirty_flags |= DIRTY_EXPRESSION;
4953 if (x0 == x1) return;
4955 /* Before the segment */
4956 for (x = 0; x < x0; x++)
4959 /* After the segment */
4960 for (x = x1; s[x]; x++)
4966 string_free(tb->lines_list[y]);
4967 tb->lines_list[y] = string_make(buf);
4969 /* Expressions may need re-evaluation */
4970 check_expression_line(tb, y);
4972 /* Text is changed */
4978 * Get a trigger key and insert ASCII string for the trigger
4980 static bool insert_macro_line(text_body_type *tb)
4989 /* Do not process macros */
4995 /* Read the pattern */
5001 /* Do not process macros */
5004 /* Do not wait for keys */
5007 /* Attempt to read a key */
5017 /* Convert the trigger */
5018 ascii_to_text(tmp, buf);
5021 if(!tmp[0]) return FALSE;
5025 /* Insert preference string */
5026 insert_return_code(tb);
5027 string_free(tb->lines_list[tb->cy]);
5028 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
5030 /* Acquire action */
5031 i = macro_find_exact(buf);
5035 /* Nothing defined */
5040 /* Analyze the current action */
5041 ascii_to_text(tmp, macro__act[i]);
5044 /* Insert blank action preference line */
5045 insert_return_code(tb);
5046 string_free(tb->lines_list[tb->cy]);
5047 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
5054 * Get a command key and insert ASCII string for the key
5056 static bool insert_keymap_line(text_body_type *tb)
5064 if (rogue_like_commands)
5066 mode = KEYMAP_MODE_ROGUE;
5072 mode = KEYMAP_MODE_ORIG;
5085 /* Convert the trigger */
5086 ascii_to_text(tmp, buf);
5089 if(!tmp[0]) return FALSE;
5093 /* Insert preference string */
5094 insert_return_code(tb);
5095 string_free(tb->lines_list[tb->cy]);
5096 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
5098 /* Look up the keymap */
5099 act = keymap_act[mode][(byte)(buf[0])];
5103 /* Analyze the current action */
5104 ascii_to_text(tmp, act);
5108 /* No keymap defined -- Use trigger key itself as a default */
5110 /* Nothing to do (use tmp) */
5113 /* Insert blank action preference line */
5114 insert_return_code(tb);
5115 string_free(tb->lines_list[tb->cy]);
5116 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
5123 * Execute a single editor command
5125 static bool do_editor_command(text_body_type *tb, int com_id)
5133 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
5135 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
5138 return QUIT_WITHOUT_SAVE;
5141 return QUIT_AND_SAVE;
5144 /* Revert to original */
5146 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
5148 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
5151 free_text_lines(tb->lines_list);
5152 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5153 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5154 tb->cx = tb->cy = 0;
5157 /* Text is not changed */
5158 tb->changed = FALSE;
5162 /* Peruse the main help file */
5164 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
5166 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
5169 tb->dirty_flags |= DIRTY_SCREEN;
5174 /* Split a line or insert end of line */
5176 /* Ignore selection */
5182 tb->dirty_flags |= DIRTY_ALL;
5185 insert_return_code(tb);
5190 tb->dirty_flags |= DIRTY_ALL;
5203 len = strlen(tb->lines_list[tb->cy]);
5204 if (len < tb->cx) tb->cx = len;
5207 /* Don't let cursor at second byte of kanji */
5208 for (i = 0; tb->lines_list[tb->cy][i]; i++)
5210 if (iskanji(tb->lines_list[tb->cy][i]))
5215 /* Move to the left */
5223 else if (tb->cy > 0)
5226 tb->cx = strlen(tb->lines_list[tb->cy]);
5233 /* Is this the last line? */
5234 if (!tb->lines_list[tb->cy + 1])
5236 /* Add one more empty line if possible */
5237 if (!add_empty_line(tb)) break;
5247 if (tb->cy > 0) tb->cy--;
5256 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5259 len = strlen(tb->lines_list[tb->cy]);
5262 /* Correct the cursor position */
5265 /* Is this the last line? */
5266 if (!tb->lines_list[tb->cy + 1])
5268 /* Add one more empty line if possible */
5269 if (!add_empty_line(tb)) break;
5272 /* Move to the beginning of next line */
5280 /* Beginning of line */
5286 tb->cx = strlen(tb->lines_list[tb->cy]);
5290 while (0 < tb->cy && tb->upper <= tb->cy)
5292 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5298 while (tb->cy < tb->upper + tb->hgt)
5300 /* Is this the last line? */
5301 if (!tb->lines_list[tb->cy + 1])
5303 /* Add one more empty line if possible */
5304 if (!add_empty_line(tb)) break;
5320 /* Is this the last line? */
5321 if (!tb->lines_list[tb->cy + 1])
5323 /* Add one more empty line if possible */
5324 if (!add_empty_line(tb)) break;
5330 /* Always at the biginning of the last line */
5337 /* Copy the text first */
5338 copy_text_to_yank(tb);
5340 /* Single line case */
5341 if (tb->my == tb->cy)
5343 int bx1 = MIN(tb->mx, tb->cx);
5344 int bx2 = MAX(tb->mx, tb->cx);
5345 int len = strlen(tb->lines_list[tb->cy]);
5347 /* Correct fake cursor position */
5348 if (bx2 > len) bx2 = len;
5350 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5352 /* New cursor position */
5356 /* Multiple lines case */
5357 else /* if (tb->my != tb->cy) */
5361 int by1 = MIN(tb->my, tb->cy);
5362 int by2 = MAX(tb->my, tb->cy);
5364 /* Kill lines in reverse order */
5365 for (y = by2; y >= by1; y--)
5367 int len = strlen(tb->lines_list[y]);
5369 kill_line_segment(tb, y, 0, len, TRUE);
5372 /* New cursor position */
5378 /* Disable selection */
5382 tb->dirty_flags |= DIRTY_ALL;
5384 /* Text is changed */
5391 copy_text_to_yank(tb);
5394 * Move cursor position to the end of the selection
5396 * Pressing ^C ^V correctly duplicates the selection.
5398 if (tb->my == tb->cy)
5400 tb->cx = MAX(tb->cx, tb->mx);
5403 * When whole line is selected, the end of
5404 * line code is also copyed.
5406 if (!tb->lines_list[tb->cy][tb->cx])
5408 /* Is this the last line? */
5409 if (!tb->lines_list[tb->cy + 1])
5411 /* Add one more empty line if possible */
5412 if (!add_empty_line(tb)) break;
5415 /* Go to the beginning of next line */
5422 tb->cy = MAX(tb->cy, tb->my);
5424 /* Is this the last line? */
5425 if (!tb->lines_list[tb->cy + 1])
5427 /* Add one more empty line if possible */
5428 if (!add_empty_line(tb)) break;
5439 /* Paste killed text */
5441 chain_str_type *chain = tb->yank;
5442 int len = strlen(tb->lines_list[tb->cy]);
5444 /* Nothing to do? */
5447 /* Correct cursor location */
5448 if (tb->cx > len) tb->cx = len;
5450 /* Ignore selection */
5456 tb->dirty_flags |= DIRTY_ALL;
5462 cptr yank_str = chain->s;
5464 char buf[MAX_LINELEN];
5466 char rest[MAX_LINELEN], *rest_ptr = rest;
5468 /* Save preceding string */
5469 for(i = 0; i < tb->cx; i++)
5470 buf[i] = tb->lines_list[tb->cy][i];
5472 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5474 /* Paste yank buffer */
5475 while (*yank_str && i < MAX_LINELEN-1)
5477 buf[i++] = *yank_str++;
5483 chain = chain->next;
5485 if (chain || tb->yank_eol)
5487 /* There is an end of line between chain nodes */
5489 insert_return_code(tb);
5491 /* Replace this line with new one */
5492 string_free(tb->lines_list[tb->cy]);
5493 tb->lines_list[tb->cy] = string_make(buf);
5495 /* Move to next line */
5502 /* Final line doesn't have end of line */
5504 tb->cx = strlen(buf);
5506 /* Rest of original line */
5507 while (*rest_ptr && i < MAX_LINELEN-1)
5509 buf[i++] = *rest_ptr++;
5515 /* Replace this line with new one */
5516 string_free(tb->lines_list[tb->cy]);
5517 tb->lines_list[tb->cy] = string_make(buf);
5524 tb->dirty_flags |= DIRTY_ALL;
5526 /* Expressions need re-evaluation */
5527 tb->dirty_flags |= DIRTY_EXPRESSION;
5529 /* Text is changed */
5538 /* Disable the selection */
5542 tb->dirty_flags |= DIRTY_ALL;
5546 tb->mark = MARK_MARK;
5548 /* Repeating this command swaps cursor position */
5549 if (com_id == tb->old_com_id)
5561 tb->dirty_flags |= DIRTY_ALL;
5565 int len = strlen(tb->lines_list[tb->cy]);
5567 /* Mark the point 1 */
5571 /* Correct cursor location */
5572 if (tb->cx > len) tb->mx = len;
5579 /* Kill rest of line */
5581 int len = strlen(tb->lines_list[tb->cy]);
5583 /* Correct cursor location */
5584 if (tb->cx > len) tb->cx = len;
5586 /* Ignore selection */
5592 tb->dirty_flags |= DIRTY_ALL;
5595 /* Append only if this command is repeated. */
5596 if (tb->old_com_id != com_id)
5598 kill_yank_chain(tb);
5602 /* Really deleted some text */
5605 /* Add deleted string to yank buffer */
5606 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5608 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5611 tb->dirty_line = tb->cy;
5613 /* Leave end of line character */
5617 /* Cut the end of line character only */
5618 if (tb->yank_eol) add_str_to_yank(tb, "");
5620 /* Cut end of line */
5621 tb->yank_eol = TRUE;
5623 do_editor_command(tb, EC_DELETE_CHAR);
5627 case EC_DELETE_CHAR:
5629 /* DELETE == go forward + BACK SPACE */
5633 /* Ignore selection */
5639 tb->dirty_flags |= DIRTY_ALL;
5643 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5647 /* Pass through the end of line to next line */
5648 len = strlen(tb->lines_list[tb->cy]);
5651 if (tb->lines_list[tb->cy + 1])
5663 do_editor_command(tb, EC_BACKSPACE);
5672 char buf[MAX_LINELEN];
5674 /* Ignore selection */
5680 tb->dirty_flags |= DIRTY_ALL;
5683 /* Move to correct collumn */
5684 len = strlen(tb->lines_list[tb->cy]);
5685 if (len < tb->cx) tb->cx = len;
5689 /* delete a return code and union two lines */
5690 if (tb->cy == 0) break;
5691 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5692 strcpy(buf, tb->lines_list[tb->cy-1]);
5693 strcat(buf, tb->lines_list[tb->cy]);
5694 string_free(tb->lines_list[tb->cy-1]);
5695 string_free(tb->lines_list[tb->cy]);
5696 tb->lines_list[tb->cy-1] = string_make(buf);
5698 for (i = tb->cy; tb->lines_list[i+1]; i++)
5699 tb->lines_list[i] = tb->lines_list[i+1];
5701 tb->lines_list[i] = NULL;
5705 tb->dirty_flags |= DIRTY_ALL;
5707 /* Expressions need re-evaluation */
5708 tb->dirty_flags |= DIRTY_EXPRESSION;
5710 /* Text is changed */
5716 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5720 if (iskanji(tb->lines_list[tb->cy][i]))
5721 buf[j++] = tb->lines_list[tb->cy][i++];
5723 buf[j++] = tb->lines_list[tb->cy][i];
5730 for (; tb->lines_list[tb->cy][i]; i++)
5731 buf[j++] = tb->lines_list[tb->cy][i];
5733 string_free(tb->lines_list[tb->cy]);
5734 tb->lines_list[tb->cy] = string_make(buf);
5737 tb->dirty_line = tb->cy;
5739 /* Expressions may need re-evaluation */
5740 check_expression_line(tb, tb->cy);
5742 /* Text is changed */
5752 /* Become dirty because of item/equip menu */
5753 tb->dirty_flags |= DIRTY_SCREEN;
5755 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5757 if (!search_dir) break;
5759 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5760 else do_editor_command(tb, EC_SEARCH_BACK);
5764 case EC_SEARCH_FORW:
5765 if (tb->search_o_ptr)
5767 search_for_object(tb, tb->search_o_ptr, TRUE);
5769 else if (tb->search_str && tb->search_str[0])
5771 search_for_string(tb, tb->search_str, TRUE);
5775 tb->dirty_flags |= DIRTY_NO_SEARCH;
5779 case EC_SEARCH_BACK:
5780 if (tb->search_o_ptr)
5782 search_for_object(tb, tb->search_o_ptr, FALSE);
5784 else if (tb->search_str && tb->search_str[0])
5786 search_for_string(tb, tb->search_str, FALSE);
5790 tb->dirty_flags |= DIRTY_NO_SEARCH;
5795 /* Become dirty because of item/equip menu */
5796 tb->dirty_flags |= DIRTY_SCREEN;
5798 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5800 do_editor_command(tb, EC_SEARCH_FORW);
5803 case EC_SEARCH_DESTROYED:
5804 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5806 /* There is no object to search */
5807 tb->dirty_flags |= DIRTY_NO_SEARCH;
5812 do_editor_command(tb, EC_SEARCH_FORW);
5815 case EC_INSERT_OBJECT:
5817 /* Insert choosen item name */
5819 autopick_type an_entry, *entry = &an_entry;
5821 if (!entry_from_choosed_object(entry))
5823 /* Now dirty because of item/equip menu */
5824 tb->dirty_flags |= DIRTY_SCREEN;
5829 insert_return_code(tb);
5830 string_free(tb->lines_list[tb->cy]);
5831 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5833 /* Now dirty because of item/equip menu */
5834 tb->dirty_flags |= DIRTY_SCREEN;
5839 case EC_INSERT_DESTROYED:
5840 /* Insert a name of last destroyed item */
5841 if (tb->last_destroyed)
5844 insert_return_code(tb);
5845 string_free(tb->lines_list[tb->cy]);
5846 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5849 tb->dirty_flags |= DIRTY_ALL;
5851 /* Text is changed */
5856 case EC_INSERT_BLOCK:
5858 /* Insert a conditinal expression line */
5859 char expression[80];
5861 /* Conditional Expression for Class and Race */
5862 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5864 rp_ptr->E_title, cp_ptr->E_title,
5866 rp_ptr->title, cp_ptr->title,
5872 insert_return_code(tb);
5873 string_free(tb->lines_list[tb->cy]);
5874 tb->lines_list[tb->cy] = string_make(expression);
5876 insert_return_code(tb);
5877 string_free(tb->lines_list[tb->cy]);
5878 tb->lines_list[tb->cy] = string_make("?:1");
5881 tb->dirty_flags |= DIRTY_ALL;
5883 /* Text is changed */
5889 case EC_INSERT_MACRO:
5890 /* Draw_everythig (delete menu) */
5891 draw_text_editor(tb);
5894 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5898 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5900 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5902 if (insert_macro_line(tb))
5904 /* Prepare to input action */
5908 tb->dirty_flags |= DIRTY_ALL;
5910 /* Text is changed */
5916 case EC_INSERT_KEYMAP:
5917 /* Draw_everythig (delete menu) */
5918 draw_text_editor(tb);
5921 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5925 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)));
5927 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)));
5930 if (insert_keymap_line(tb))
5932 /* Prepare to input action */
5936 tb->dirty_flags |= DIRTY_ALL;
5938 /* Text is changed */
5943 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5944 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5945 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5946 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5947 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5949 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5950 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5951 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5952 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5953 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5954 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5955 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5956 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5957 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5958 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5959 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5960 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5961 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5962 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5963 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5964 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5965 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5966 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5967 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5968 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5969 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5970 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5971 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5972 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5973 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5974 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5975 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5976 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5977 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5978 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5979 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5980 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5981 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5982 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5983 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5984 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5985 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5986 case EC_OK_UNREADABLE:
5987 toggle_keyword(tb, FLG_UNREADABLE);
5988 add_keyword(tb, FLG_SPELLBOOKS);
5991 toggle_keyword(tb, FLG_REALM1);
5992 add_keyword(tb, FLG_SPELLBOOKS);
5995 toggle_keyword(tb, FLG_REALM2);
5996 add_keyword(tb, FLG_SPELLBOOKS);
5999 toggle_keyword(tb, FLG_FIRST);
6000 add_keyword(tb, FLG_SPELLBOOKS);
6003 toggle_keyword(tb, FLG_SECOND);
6004 add_keyword(tb, FLG_SPELLBOOKS);
6007 toggle_keyword(tb, FLG_THIRD);
6008 add_keyword(tb, FLG_SPELLBOOKS);
6011 toggle_keyword(tb, FLG_FOURTH);
6012 add_keyword(tb, FLG_SPELLBOOKS);
6016 /* Save old command */
6017 tb->old_com_id = com_id;
6024 * Insert single letter at cursor position.
6026 static void insert_single_letter(text_body_type *tb, int key)
6029 char buf[MAX_LINELEN];
6031 /* Save preceding string */
6032 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
6033 buf[j++] = tb->lines_list[tb->cy][i];
6035 /* Add a character */
6043 if (j+2 < MAX_LINELEN)
6055 if (j+1 < MAX_LINELEN)
6061 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
6062 buf[j++] = tb->lines_list[tb->cy][i];
6065 /* Replace current line with new line */
6066 string_free(tb->lines_list[tb->cy]);
6067 tb->lines_list[tb->cy] = string_make(buf);
6069 /* Move to correct collumn */
6070 len = strlen(tb->lines_list[tb->cy]);
6071 if (len < tb->cx) tb->cx = len;
6074 tb->dirty_line = tb->cy;
6076 /* Expressions may need re-evaluation */
6077 check_expression_line(tb, tb->cy);
6079 /* Text is changed */
6085 * Check special key code and get a movement command id
6087 static int analyze_move_key(text_body_type *tb, int skey)
6091 /* Not a special key */
6092 if (!(skey & SKEY_MASK)) return 0;
6094 /* Convert from a special key code to an editor command */
6095 switch(skey & ~SKEY_MOD_MASK)
6097 case SKEY_DOWN: com_id = EC_DOWN; break;
6098 case SKEY_LEFT: com_id = EC_LEFT; break;
6099 case SKEY_RIGHT: com_id = EC_RIGHT; break;
6100 case SKEY_UP: com_id = EC_UP; break;
6101 case SKEY_PGUP: com_id = EC_PGUP; break;
6102 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
6103 case SKEY_TOP: com_id = EC_TOP; break;
6104 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
6107 /* Not a special movement key */
6111 /* Without shift modifier */
6112 if (!(skey & SKEY_MOD_SHIFT))
6115 * Un-shifted cursor keys cancells
6116 * selection created by shift+cursor.
6118 if (tb->mark & MARK_BY_SHIFT)
6123 tb->dirty_flags |= DIRTY_ALL;
6127 /* With shift modifier */
6130 /* Start selection by shift + cursor keys */
6133 int len = strlen(tb->lines_list[tb->cy]);
6135 tb->mark = MARK_MARK | MARK_BY_SHIFT;
6139 /* Correct cursor location */
6140 if (tb->cx > len) tb->mx = len;
6142 /* Need to redraw text */
6143 if (com_id == EC_UP || com_id == EC_DOWN)
6145 /* Redraw all text */
6146 tb->dirty_flags |= DIRTY_ALL;
6150 tb->dirty_line = tb->cy;
6159 * In-game editor of Object Auto-picker/Destoryer
6161 void do_cmd_edit_autopick(void)
6163 static int cx_save = 0;
6164 static int cy_save = 0;
6166 text_body_type text_body, *tb = &text_body;
6168 autopick_type an_entry, *entry = &an_entry;
6169 char buf[MAX_LINELEN];
6174 static s32b old_autosave_turn = 0L;
6177 tb->changed = FALSE;
6180 tb->upper = tb->left = 0;
6182 tb->mx = tb->my = 0;
6183 tb->old_cy = tb->old_upper = tb->old_left = -1;
6184 tb->old_wid = tb->old_hgt = -1;
6188 tb->search_o_ptr = NULL;
6189 tb->search_str = NULL;
6190 tb->last_destroyed = NULL;
6191 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6192 tb->dirty_line = -1;
6193 tb->filename_mode = PT_DEFAULT;
6195 if (turn < old_autosave_turn)
6197 while (old_autosave_turn > turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
6201 if (turn > old_autosave_turn + 100L)
6203 do_cmd_save_game(TRUE);
6204 old_autosave_turn = turn;
6207 /* HACK -- Reset start_time to stop counting playtime while edit */
6210 /* Free old entries */
6213 /* Command Description of the 'Last Destroyed Item' */
6214 if (autopick_last_destroyed_object.k_idx)
6216 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6217 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6220 /* Read or initialize whole text */
6221 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6223 /* Reset cursor position if needed */
6224 for (i = 0; i < tb->cy; i++)
6226 if (!tb->lines_list[i])
6228 tb->cy = tb->cx = 0;
6233 /* Save the screen */
6236 /* Process requests until done */
6241 /* Draw_everythig */
6242 draw_text_editor(tb);
6244 /* Display header line */
6246 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
6248 prt("(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)", 0, 0);
6252 /* Display current position */
6253 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6257 /* Display current position and mark position */
6258 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6262 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6265 tb->dirty_flags = 0;
6266 tb->dirty_line = -1;
6268 /* Save old key and location */
6269 tb->old_cy = tb->cy;
6270 tb->old_upper = tb->upper;
6271 tb->old_left = tb->left;
6272 tb->old_wid = tb->wid;
6273 tb->old_hgt = tb->hgt;
6276 key = inkey_special(TRUE);
6279 if (key & SKEY_MASK)
6281 /* Get a movement command */
6282 com_id = analyze_move_key(tb, key);
6286 else if (key == ESCAPE)
6288 com_id = do_command_menu(0, 0);
6290 /* Redraw all text later */
6291 tb->dirty_flags |= DIRTY_SCREEN;
6294 /* Insert a character */
6295 else if (!iscntrl((unsigned char)key))
6297 /* Ignore selection */
6303 tb->dirty_flags |= DIRTY_ALL;
6306 insert_single_letter(tb, key);
6312 /* Other commands */
6315 com_id = get_com_id(key);
6318 if (com_id) quit = do_editor_command(tb, com_id);
6319 } /* while (TRUE) */
6321 /* Restore the screen */
6324 /* Get the filename of preference */
6325 strcpy(buf, pickpref_filename(tb->filename_mode));
6327 if (quit == QUIT_AND_SAVE)
6328 write_text_lines(buf, tb->lines_list);
6330 free_text_lines(tb->lines_list);
6332 string_free(tb->search_str);
6333 string_free(tb->last_destroyed);
6335 /* Destroy string chain */
6336 kill_yank_chain(tb);
6338 /* Reload autopick pref */
6339 process_autopick_file(buf);
6341 /* HACK -- reset start_time so that playtime is not increase while edit */
6342 start_time = time(NULL);
6344 /* Save cursor location */