3 * @brief 自動拾い機能の実装 / Object Auto-picker/Destroyer
6 * Copyright (c) 2002 Mogami\n
8 * This software may be copied and distributed for educational, research, and\n
9 * not for profit purposes provided that this copyright and statement are\n
10 * included in all such copies.\n
11 * 2014 Deskull rearranged comment for Doxygen.\n
20 #include "player-status.h"
21 #include "player-move.h"
22 #include "object-flavor.h"
23 #include "object-hook.h"
28 #define MAX_LINELEN 1024
35 #define FLG_UNIDENTIFIED 2
36 #define FLG_IDENTIFIED 3
37 #define FLG_STAR_IDENTIFIED 4
38 #define FLG_COLLECTING 5
39 #define FLG_ARTIFACT 6
42 #define FLG_NAMELESS 11
43 #define FLG_AVERAGE 12
44 #define FLG_WORTHLESS 13
47 #define FLG_BOOSTED 16
48 #define FLG_MORE_DICE 17
49 #define FLG_MORE_BONUS 18
53 #define FLG_UNREADABLE 22
62 #define FLG_WEAPONS 31
63 #define FLG_FAVORITE_WEAPONS 32
65 #define FLG_MISSILES 34
66 #define FLG_DEVICES 35
69 #define FLG_CORPSES 38
70 #define FLG_SPELLBOOKS 39
72 #define FLG_SHIELDS 41
75 #define FLG_AMULETS 44
82 #define FLG_NOUN_BEGIN FLG_ITEMS
83 #define FLG_NOUN_END FLG_BOOTS
87 static GAME_TEXT KEY_ALL[] = "すべての";
88 static GAME_TEXT KEY_UNAWARE[] = "未判明の";
89 static GAME_TEXT KEY_UNIDENTIFIED[] = "未鑑定の";
90 static GAME_TEXT KEY_IDENTIFIED[] = "鑑定済みの";
91 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*鑑定*済みの";
92 static GAME_TEXT KEY_COLLECTING[] = "収集中の";
93 static GAME_TEXT KEY_ARTIFACT[] = "アーティファクト";
94 static GAME_TEXT KEY_EGO[] = "エゴ";
95 static GAME_TEXT KEY_GOOD[] = "上質の";
96 static GAME_TEXT KEY_NAMELESS[] = "無銘の";
97 static GAME_TEXT KEY_AVERAGE[] = "並の";
98 static GAME_TEXT KEY_WORTHLESS[] = "無価値の";
99 static GAME_TEXT KEY_RARE[] = "レアな";
100 static GAME_TEXT KEY_COMMON[] = "ありふれた";
101 static GAME_TEXT KEY_BOOSTED[] = "ダイス目の違う";
102 static GAME_TEXT KEY_MORE_THAN[] = "ダイス目";
103 static GAME_TEXT KEY_DICE[] = "以上の";
104 static GAME_TEXT KEY_MORE_BONUS[] = "修正値";
105 static GAME_TEXT KEY_MORE_BONUS2[] = "以上の";
106 static GAME_TEXT KEY_WANTED[] = "賞金首の";
107 static GAME_TEXT KEY_UNIQUE[] = "ユニーク・モンスターの";
108 static GAME_TEXT KEY_HUMAN[] = "人間の";
109 static GAME_TEXT KEY_UNREADABLE[] = "読めない";
110 static GAME_TEXT KEY_REALM1[] = "第一領域の";
111 static GAME_TEXT KEY_REALM2[] = "第二領域の";
112 static GAME_TEXT KEY_FIRST[] = "1冊目の";
113 static GAME_TEXT KEY_SECOND[] = "2冊目の";
114 static GAME_TEXT KEY_THIRD[] = "3冊目の";
115 static GAME_TEXT KEY_FOURTH[] = "4冊目の";
116 static GAME_TEXT KEY_ITEMS[] = "アイテム";
117 static GAME_TEXT KEY_WEAPONS[] = "武器";
118 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "得意武器";
119 static GAME_TEXT KEY_ARMORS[] = "防具";
120 static GAME_TEXT KEY_MISSILES[] = "矢";
121 static GAME_TEXT KEY_DEVICES[] = "魔法アイテム";
122 static GAME_TEXT KEY_LIGHTS[] = "光源";
123 static GAME_TEXT KEY_JUNKS[] = "がらくた";
124 static GAME_TEXT KEY_CORPSES[] = "死体や骨";
125 static GAME_TEXT KEY_SPELLBOOKS[] = "魔法書";
126 static GAME_TEXT KEY_HAFTED[] = "鈍器";
127 static GAME_TEXT KEY_SHIELDS[] = "盾";
128 static GAME_TEXT KEY_BOWS[] = "弓";
129 static GAME_TEXT KEY_RINGS[] = "指輪";
130 static GAME_TEXT KEY_AMULETS[] = "アミュレット";
131 static GAME_TEXT KEY_SUITS[] = "鎧";
132 static GAME_TEXT KEY_CLOAKS[] = "クローク";
133 static GAME_TEXT KEY_HELMS[] = "兜";
134 static GAME_TEXT KEY_GLOVES[] = "籠手";
135 static GAME_TEXT KEY_BOOTS[] = "靴";
139 static GAME_TEXT KEY_ALL[] = "all";
140 static GAME_TEXT KEY_UNAWARE[] = "unaware";
141 static GAME_TEXT KEY_UNIDENTIFIED[] = "unidentified";
142 static GAME_TEXT KEY_IDENTIFIED[] = "identified";
143 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*identified*";
144 static GAME_TEXT KEY_COLLECTING[] = "collecting";
145 static GAME_TEXT KEY_ARTIFACT[] = "artifact";
146 static GAME_TEXT KEY_EGO[] = "ego";
147 static GAME_TEXT KEY_GOOD[] = "good";
148 static GAME_TEXT KEY_nameLESS[] = "nameless";
149 static GAME_TEXT KEY_AVERAGE[] = "average";
150 static GAME_TEXT KEY_WORTHLESS[] = "worthless";
151 static GAME_TEXT KEY_RARE[] = "rare";
152 static GAME_TEXT KEY_COMMON[] = "common";
153 static GAME_TEXT KEY_BOOSTED[] = "dice boosted";
154 static GAME_TEXT KEY_MORE_THAN[] = "more than";
155 static GAME_TEXT KEY_DICE[] = " dice";
156 static GAME_TEXT KEY_MORE_BONUS[] = "more bonus than";
157 static GAME_TEXT KEY_MORE_BONUS2[] = "";
158 static GAME_TEXT KEY_WANTED[] = "wanted";
159 static GAME_TEXT KEY_UNIQUE[] = "unique monster's";
160 static GAME_TEXT KEY_HUMAN[] = "human";
161 static GAME_TEXT KEY_UNREADABLE[] = "unreadable";
162 static GAME_TEXT KEY_REALM1[] = "first realm's";
163 static GAME_TEXT KEY_REALM2[] = "second realm's";
164 static GAME_TEXT KEY_FIRST[] = "first";
165 static GAME_TEXT KEY_SECOND[] = "second";
166 static GAME_TEXT KEY_THIRD[] = "third";
167 static GAME_TEXT KEY_FOURTH[] = "fourth";
168 static GAME_TEXT KEY_ITEMS[] = "items";
169 static GAME_TEXT KEY_WEAPONS[] = "weapons";
170 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "favorite weapons";
171 static GAME_TEXT KEY_ARMORS[] = "armors";
172 static GAME_TEXT KEY_MISSILES[] = "missiles";
173 static GAME_TEXT KEY_DEVICES[] = "magical devices";
174 static GAME_TEXT KEY_LIGHTS[] = "lights";
175 static GAME_TEXT KEY_JUNKS[] = "junks";
176 static GAME_TEXT KEY_CORPSES[] = "corpses or skeletons";
177 static GAME_TEXT KEY_SPELLBOOKS[] = "spellbooks";
178 static GAME_TEXT KEY_HAFTED[] = "hafted weapons";
179 static GAME_TEXT KEY_SHIELDS[] = "shields";
180 static GAME_TEXT KEY_BOWS[] = "bows";
181 static GAME_TEXT KEY_RINGS[] = "rings";
182 static GAME_TEXT KEY_AMULETS[] = "amulets";
183 static GAME_TEXT KEY_SUITS[] = "suits";
184 static GAME_TEXT KEY_CLOAKS[] = "cloaks";
185 static GAME_TEXT KEY_HELMS[] = "helms";
186 static GAME_TEXT KEY_GLOVES[] = "gloves";
187 static GAME_TEXT KEY_BOOTS[] = "boots";
191 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
192 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
193 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
194 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
197 #define ADD_KEY(KEY) strcat(ptr, KEY)
199 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
201 #define ADD_KEY2(KEY) strcat(ptr, KEY)
203 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
204 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
205 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
206 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
209 static char kanji_colon[] = ":";
214 * A function to create new entry
216 static bool autopick_new_entry(autopick_type *entry, concptr str, bool allow_default)
221 char buf[MAX_LINELEN];
222 concptr prev_ptr, ptr, old_ptr;
225 if (str[0] && str[1] == ':') switch (str[0])
228 case 'A': case 'P': case 'C':
232 entry->flag[0] = entry->flag[1] = 0L;
236 act = DO_AUTOPICK | DO_DISPLAY;
239 if ((act & DO_AUTOPICK) && *str == '!')
242 act |= DO_AUTODESTROY;
245 else if ((act & DO_AUTOPICK) && *str == '~')
248 act |= DONT_AUTOPICK;
251 else if ((act & DO_AUTOPICK) && *str == ';')
254 act |= DO_QUERY_AUTOPICK;
257 else if ((act & DO_DISPLAY) && *str == '(')
266 /* don't mind upper or lower case */
268 for (i = 0; *str; i++)
279 /* Auto-inscription? */
287 if (isupper(c)) c = (char)tolower(c);
293 /* Skip empty line unless allow_default */
294 if (!allow_default && *buf == 0) return FALSE;
296 /* Skip comment line */
297 if (*buf == 0 && insc) return FALSE;
299 ptr = prev_ptr = buf;
302 while (old_ptr != ptr)
304 /* Save current location */
307 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
308 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
309 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
310 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
311 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
312 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
313 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
315 /*** Weapons whose dd*ds is more than nn ***/
316 if (MATCH_KEY2(KEY_MORE_THAN))
321 /* Drop leading spaces */
322 while (' ' == *ptr) ptr++;
325 while ('0' <= *ptr && *ptr <= '9')
327 entry->dice = 10 * entry->dice + (*ptr - '0');
334 (void)MATCH_KEY(KEY_DICE);
335 ADD_FLG(FLG_MORE_DICE);
341 /*** Items whose magical bonus is more than n ***/
342 if (MATCH_KEY2(KEY_MORE_BONUS))
347 /* Drop leading spaces */
348 while (' ' == *ptr) ptr++;
351 while ('0' <= *ptr && *ptr <= '9')
353 entry->bonus = 10 * entry->bonus + (*ptr - '0');
361 (void)MATCH_KEY(KEY_MORE_BONUS2);
363 if (' ' == *ptr) ptr++;
365 ADD_FLG(FLG_MORE_BONUS);
371 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
372 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
373 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
374 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
375 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
376 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
377 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
378 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
379 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
380 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
381 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
382 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
383 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
384 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
385 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
386 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
387 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
390 /* Not yet found any noun */
393 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
395 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
396 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
397 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
398 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
399 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
400 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
401 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
402 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
403 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
404 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
405 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
406 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
407 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
408 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
409 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
410 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
411 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
412 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
413 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
414 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
416 /* Last 'keyword' must be at the correct location */
420 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
423 else if (*ptr == '\0')
425 /* There was no noun */
428 /* Add extra word "items" */
429 ADD_FLG_NOUN(FLG_ITEMS);
436 /* A noun type keyword didn't end correctly */
437 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
442 /* Save this auto-picker entry line */
443 entry->name = string_make(ptr);
445 entry->insc = string_make(insc);
452 * Get auto-picker entry from o_ptr.
454 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
456 /* Assume that object name is to be added */
460 /* エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない */
461 bool bol_mark = FALSE;
463 /* We can always use the ^ mark in English */
464 bool bol_mark = TRUE;
467 GAME_TEXT name_str[MAX_NLEN];
469 /* Initialize name string */
472 entry->insc = string_make(quark_str(o_ptr->inscription));
473 entry->action = DO_AUTOPICK | DO_DISPLAY;
474 entry->flag[0] = entry->flag[1] = 0L;
478 if (!object_is_aware(o_ptr))
480 ADD_FLG(FLG_UNAWARE);
484 /* Not really identified */
485 else if (!object_is_known(o_ptr))
487 if (!(o_ptr->ident & IDENT_SENSE))
489 ADD_FLG(FLG_UNIDENTIFIED);
494 /* Pseudo-identified */
495 switch (o_ptr->feeling)
499 ADD_FLG(FLG_NAMELESS);
505 ADD_FLG(FLG_NAMELESS);
506 ADD_FLG(FLG_WORTHLESS);
512 ADD_FLG(FLG_WORTHLESS);
520 /* XXX No appropriate flag */
525 /* Never reach here */
535 if (object_is_ego(o_ptr))
537 if (object_is_weapon_armour_ammo(o_ptr))
540 * Base name of ego weapons and armors
541 * are almost meaningless.
542 * Register the ego type only.
544 ego_item_type *e_ptr = &e_info[o_ptr->name2];
546 /* エゴ銘には「^」マークが使える */
547 sprintf(name_str, "^%s", e_name + e_ptr->name);
549 /* We ommit the basename and cannot use the ^ mark */
550 strcpy(name_str, e_name + e_ptr->name);
553 /* Don't use the object description */
556 /* Restrict to 'common' equipments */
557 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
564 else if (object_is_artifact(o_ptr))
565 ADD_FLG(FLG_ARTIFACT);
567 /* Non-ego, non-artifact */
570 /* Wearable nameless object */
571 if (object_is_equipment(o_ptr))
572 ADD_FLG(FLG_NAMELESS);
579 /* Melee weapon with boosted dice */
580 if (object_is_melee_weapon(o_ptr))
582 object_kind *k_ptr = &k_info[o_ptr->k_idx];
584 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
585 ADD_FLG(FLG_BOOSTED);
588 /* Wanted monster's corpse */
589 if (object_is_shoukinkubi(o_ptr))
591 REM_FLG(FLG_WORTHLESS);
595 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
596 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
601 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
606 if (o_ptr->tval >= TV_LIFE_BOOK &&
607 !check_book_realm(o_ptr->tval, o_ptr->sval))
609 ADD_FLG(FLG_UNREADABLE);
610 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
613 if (REALM1_BOOK == o_ptr->tval &&
614 p_ptr->pclass != CLASS_SORCERER &&
615 p_ptr->pclass != CLASS_RED_MAGE)
621 if (REALM2_BOOK == o_ptr->tval &&
622 p_ptr->pclass != CLASS_SORCERER &&
623 p_ptr->pclass != CLASS_RED_MAGE)
629 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
631 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
633 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
635 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
638 if (object_is_ammo(o_ptr))
639 ADD_FLG(FLG_MISSILES);
640 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
641 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
642 ADD_FLG(FLG_DEVICES);
643 else if (o_ptr->tval == TV_LITE)
645 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
646 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
648 else if (o_ptr->tval == TV_CORPSE)
649 ADD_FLG(FLG_CORPSES);
650 else if (o_ptr->tval >= TV_LIFE_BOOK)
651 ADD_FLG(FLG_SPELLBOOKS);
652 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
653 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
654 ADD_FLG(FLG_WEAPONS);
655 else if (o_ptr->tval == TV_SHIELD)
656 ADD_FLG(FLG_SHIELDS);
657 else if (o_ptr->tval == TV_BOW)
659 else if (o_ptr->tval == TV_RING)
661 else if (o_ptr->tval == TV_AMULET)
662 ADD_FLG(FLG_AMULETS);
663 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
664 o_ptr->tval == TV_SOFT_ARMOR)
666 else if (o_ptr->tval == TV_CLOAK)
668 else if (o_ptr->tval == TV_HELM)
670 else if (o_ptr->tval == TV_GLOVES)
672 else if (o_ptr->tval == TV_BOOTS)
675 /* Prepare the object description */
678 GAME_TEXT o_name[MAX_NLEN];
680 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
683 * If necessary, add a '^' which indicates the
686 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
689 /* Register the name in lowercase */
690 str_tolower(name_str);
691 entry->name = string_make(name_str);
698 * A function to delete entry
700 static void autopick_free_entry(autopick_type *entry)
702 string_free(entry->name);
703 string_free(entry->insc);
709 #define MAX_AUTOPICK_DEFAULT 200
712 * Initialize the autopick
714 static void init_autopick(void)
716 static const char easy_autopick_inscription[] = "(:=g";
722 max_max_autopick = MAX_AUTOPICK_DEFAULT;
723 C_MAKE(autopick_list, max_max_autopick, autopick_type);
727 /* Clear old entries */
728 for( i = 0; i < max_autopick; i++)
729 autopick_free_entry(&autopick_list[i]);
733 /* There is always one entry "=g" */
734 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
735 autopick_list[max_autopick++] = entry;
740 #define PT_WITH_PNAME 1
743 * Get file name for autopick preference
745 static concptr pickpref_filename(int filename_mode)
747 static const char namebase[] = _("picktype", "pickpref");
749 switch (filename_mode)
752 return format("%s.prf", namebase);
755 return format("%s-%s.prf", namebase, player_base);
764 * Load an autopick preference file
766 void autopick_load_pref(bool disp_mes)
771 /* Free old entries */
774 /* Try a filename with player name */
775 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
778 err = process_autopick_file(buf);
780 if (err == 0 && disp_mes)
783 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
789 /* Use default name */
790 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
793 err = process_autopick_file(buf);
795 if (err == 0 && disp_mes)
798 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
805 msg_print(_("自動拾い設定ファイルの読み込みに失敗しました。", "Failed to reload autopick preference."));
811 * Add one line to autopick_list[]
813 static void add_autopick_list(autopick_type *entry)
815 /* There is no enough space to add one line */
816 if (max_autopick >= max_max_autopick)
818 int old_max_max_autopick = max_max_autopick;
819 autopick_type *old_autopick_list = autopick_list;
821 /* Increase size of list */
822 max_max_autopick += MAX_AUTOPICK_DEFAULT;
825 C_MAKE(autopick_list, max_max_autopick, autopick_type);
827 /* Copy from old list to new list */
828 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
831 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
835 autopick_list[max_autopick] = *entry;
842 * Process line for auto picker/destroyer.
844 errr process_autopick_file_command(char *buf)
846 autopick_type an_entry, *entry = &an_entry;
849 /* Nuke illegal char */
850 for(i = 0; buf[i]; i++)
859 if (iswspace(buf[i]) && buf[i] != ' ')
864 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
866 /* Already has the same entry? */
867 for(i = 0; i < max_autopick; i++)
868 if(!strcmp(entry->name, autopick_list[i].name)
869 && entry->flag[0] == autopick_list[i].flag[0]
870 && entry->flag[1] == autopick_list[i].flag[1]
871 && entry->dice == autopick_list[i].dice
872 && entry->bonus == autopick_list[i].bonus)
874 autopick_free_entry(entry);
878 add_autopick_list(entry);
884 * Reconstruct preference line from entry
886 concptr autopick_line_from_entry(autopick_type *entry)
888 char buf[MAX_LINELEN];
890 bool sepa_flag = TRUE;
893 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
894 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
895 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
896 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
900 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
901 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
902 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
903 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
904 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
905 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
906 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
908 if (IS_FLG(FLG_MORE_DICE))
910 ADD_KEY(KEY_MORE_THAN);
911 strcat(ptr, format("%d", entry->dice));
915 if (IS_FLG(FLG_MORE_BONUS))
917 ADD_KEY(KEY_MORE_BONUS);
918 strcat(ptr, format("%d", entry->bonus));
919 ADD_KEY(KEY_MORE_BONUS2);
922 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
923 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
924 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
925 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
926 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
927 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
928 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
929 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
930 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
931 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
932 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
933 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
934 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
935 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
936 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
937 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
938 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
940 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
942 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
943 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
944 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
945 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
946 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
947 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
948 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
949 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
950 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
951 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
952 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
953 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
954 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
955 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
956 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
957 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
958 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
959 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
960 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
961 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
963 /* You don't need sepalator after adjective */
964 /* 'artifact' is not true adjective */
965 else if (!IS_FLG(FLG_ARTIFACT))
968 if (entry->name && entry->name[0])
972 if (sepa_flag) strcat(buf, ":");
975 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
978 if (iskanji(entry->name[j]))
979 buf[i++] = entry->name[j++];
981 buf[i++] = entry->name[j++];
992 while (entry->insc[j] && i < MAX_LINELEN - 2)
995 if (iskanji(entry->insc[j]))
996 buf[i++] = entry->insc[j++];
998 buf[i++] = entry->insc[j++];
1003 return string_make(buf);
1008 * Reconstruct preference line from entry and kill entry
1010 static concptr autopick_line_from_entry_kill(autopick_type *entry)
1012 concptr ptr = autopick_line_from_entry(entry);
1014 /* Free memory for original entry */
1015 autopick_free_entry(entry);
1022 * A function for Auto-picker/destroyer
1023 * Examine whether the object matches to the entry
1025 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_name)
1028 concptr ptr = entry->name;
1030 /*** Unaware items ***/
1031 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1034 /*** Unidentified ***/
1035 if (IS_FLG(FLG_UNIDENTIFIED)
1036 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1039 /*** Identified ***/
1040 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1043 /*** *Identified* ***/
1044 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1045 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1048 /*** Dice boosted (weapon of slaying) ***/
1049 if (IS_FLG(FLG_BOOSTED))
1051 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1053 /* Require melee weapon */
1054 if (!object_is_melee_weapon(o_ptr))
1057 /* Require boosted dice */
1058 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1061 /* In Vault Quest, Dice must be hide.*/
1062 if(!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
1068 /*** Weapons which dd*ds is more than nn ***/
1069 if (IS_FLG(FLG_MORE_DICE))
1071 if (o_ptr->dd * o_ptr->ds < entry->dice)
1075 /*** Weapons whic dd*ds is more than nn ***/
1076 if (IS_FLG(FLG_MORE_BONUS))
1078 if (!object_is_known(o_ptr)) return FALSE;
1082 if (o_ptr->pval < entry->bonus) return FALSE;
1086 if (o_ptr->to_h < entry->bonus &&
1087 o_ptr->to_d < entry->bonus &&
1088 o_ptr->to_a < entry->bonus &&
1089 o_ptr->pval < entry->bonus)
1094 /*** Worthless items ***/
1095 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1098 /*** Artifact object ***/
1099 if (IS_FLG(FLG_ARTIFACT))
1101 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1105 /*** Ego object ***/
1106 if (IS_FLG(FLG_EGO))
1108 /* Need to be an ego item */
1109 if (!object_is_ego(o_ptr)) return FALSE;
1111 /* Need to be known to be an ego */
1112 if (!object_is_known(o_ptr) &&
1113 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1118 if (IS_FLG(FLG_GOOD))
1120 if (!object_is_equipment(o_ptr)) return FALSE;
1123 if (object_is_known(o_ptr))
1125 /* Artifacts and Ego objects are not okay */
1126 if (!object_is_nameless(o_ptr))
1129 /* Average are not okay */
1130 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1134 /* Pseudo-identified */
1135 else if (o_ptr->ident & IDENT_SENSE)
1137 switch (o_ptr->feeling)
1152 /* Not known to be good */
1158 if (IS_FLG(FLG_NAMELESS))
1160 if (!object_is_equipment(o_ptr)) return FALSE;
1163 if (object_is_known(o_ptr))
1165 /* Artifacts and Ego objects are not okay */
1166 if (!object_is_nameless(o_ptr))
1170 /* Pseudo-identified */
1171 else if (o_ptr->ident & IDENT_SENSE)
1173 switch (o_ptr->feeling)
1183 /* It's not nameless */
1191 /* Not known to be nameless */
1197 if (IS_FLG(FLG_AVERAGE))
1199 if (!object_is_equipment(o_ptr)) return FALSE;
1202 if (object_is_known(o_ptr))
1204 /* Artifacts and Ego objects are not okay */
1205 if (!object_is_nameless(o_ptr))
1208 /* Cursed or broken objects are not okay */
1209 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1212 /* Good are not okay */
1213 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1217 /* Pseudo-identified */
1218 else if (o_ptr->ident & IDENT_SENSE)
1220 switch (o_ptr->feeling)
1227 /* It's not average */
1235 /* Not known to be average */
1240 /*** Rere equipments ***/
1241 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1244 /*** Common equipments ***/
1245 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1248 /*** Wanted monster's corpse/skeletons ***/
1249 if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
1252 /*** Unique monster's corpse/skeletons/statues ***/
1253 if (IS_FLG(FLG_UNIQUE) &&
1254 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1255 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1258 /*** Human corpse/skeletons (for Daemon magic) ***/
1259 if (IS_FLG(FLG_HUMAN) &&
1260 (o_ptr->tval != TV_CORPSE ||
1261 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1264 /*** Unreadable spellbooks ***/
1265 if (IS_FLG(FLG_UNREADABLE) &&
1266 (o_ptr->tval < TV_LIFE_BOOK ||
1267 check_book_realm(o_ptr->tval, o_ptr->sval)))
1270 /*** First realm spellbooks ***/
1271 if (IS_FLG(FLG_REALM1) &&
1272 (REALM1_BOOK != o_ptr->tval ||
1273 p_ptr->pclass == CLASS_SORCERER ||
1274 p_ptr->pclass == CLASS_RED_MAGE))
1277 /*** Second realm spellbooks ***/
1278 if (IS_FLG(FLG_REALM2) &&
1279 (REALM2_BOOK != o_ptr->tval ||
1280 p_ptr->pclass == CLASS_SORCERER ||
1281 p_ptr->pclass == CLASS_RED_MAGE))
1284 /*** First rank spellbooks ***/
1285 if (IS_FLG(FLG_FIRST) &&
1286 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1289 /*** Second rank spellbooks ***/
1290 if (IS_FLG(FLG_SECOND) &&
1291 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1294 /*** Third rank spellbooks ***/
1295 if (IS_FLG(FLG_THIRD) &&
1296 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1299 /*** Fourth rank spellbooks ***/
1300 if (IS_FLG(FLG_FOURTH) &&
1301 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1305 if (IS_FLG(FLG_WEAPONS))
1307 if (!object_is_weapon(o_ptr))
1310 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1312 if (!object_is_favorite(o_ptr))
1315 else if (IS_FLG(FLG_ARMORS))
1317 if (!object_is_armour(o_ptr))
1320 else if (IS_FLG(FLG_MISSILES))
1322 if (!object_is_ammo(o_ptr)) return FALSE;
1324 else if (IS_FLG(FLG_DEVICES))
1328 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1330 default: return FALSE;
1333 else if (IS_FLG(FLG_LIGHTS))
1335 if (!(o_ptr->tval == TV_LITE))
1338 else if (IS_FLG(FLG_JUNKS))
1342 case TV_SKELETON: case TV_BOTTLE:
1343 case TV_JUNK: case TV_STATUE:
1345 default: return FALSE;
1348 else if (IS_FLG(FLG_CORPSES))
1350 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1353 else if (IS_FLG(FLG_SPELLBOOKS))
1355 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1358 else if (IS_FLG(FLG_HAFTED))
1360 if (!(o_ptr->tval == TV_HAFTED))
1363 else if (IS_FLG(FLG_SHIELDS))
1365 if (!(o_ptr->tval == TV_SHIELD))
1368 else if (IS_FLG(FLG_BOWS))
1370 if (!(o_ptr->tval == TV_BOW))
1373 else if (IS_FLG(FLG_RINGS))
1375 if (!(o_ptr->tval == TV_RING))
1378 else if (IS_FLG(FLG_AMULETS))
1380 if (!(o_ptr->tval == TV_AMULET))
1383 else if (IS_FLG(FLG_SUITS))
1385 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1386 o_ptr->tval == TV_HARD_ARMOR ||
1387 o_ptr->tval == TV_SOFT_ARMOR))
1390 else if (IS_FLG(FLG_CLOAKS))
1392 if (!(o_ptr->tval == TV_CLOAK))
1395 else if (IS_FLG(FLG_HELMS))
1397 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1400 else if (IS_FLG(FLG_GLOVES))
1402 if (!(o_ptr->tval == TV_GLOVES))
1405 else if (IS_FLG(FLG_BOOTS))
1407 if (!(o_ptr->tval == TV_BOOTS))
1411 /* Keyword don't match */
1415 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1419 if (!my_strstr(o_name, ptr)) return FALSE;
1422 /* TRUE when it need not to be 'collecting' */
1423 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1425 /* Check if there is a same item */
1426 for (j = 0; j < INVEN_PACK; j++)
1429 * 'Collecting' means the item must be absorbed
1430 * into an inventory slot.
1431 * But an item can not be absorbed into itself!
1433 if ((&inventory[j] != o_ptr) &&
1434 object_similar(&inventory[j], o_ptr))
1438 /* Not collecting */
1444 * A function for Auto-picker/destroyer
1445 * Examine whether the object matches to the list of keywords or not.
1447 int is_autopick(object_type *o_ptr)
1450 GAME_TEXT o_name[MAX_NLEN];
1452 if (o_ptr->tval == TV_GOLD) return -1;
1454 /* Prepare object name string first */
1455 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1457 /* Convert the string to lower case */
1458 str_tolower(o_name);
1460 /* Look for a matching entry in the list */
1461 for (i=0; i < max_autopick; i++)
1463 autopick_type *entry = &autopick_list[i];
1465 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1468 /* No matching entry */
1476 static void auto_inscribe_item(object_type *o_ptr, int idx)
1478 /* Are there auto-inscription? */
1479 if (idx < 0 || !autopick_list[idx].insc) return;
1481 if (!o_ptr->inscription)
1482 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1484 /* Redraw inscription */
1485 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1487 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1488 p_ptr->update |= (PU_BONUS);
1493 * Automatically destroy items in this grid.
1495 static bool is_opt_confirm_destroy(object_type *o_ptr)
1497 if (!destroy_items) return FALSE;
1499 /* Known to be worthless? */
1501 if (object_value(o_ptr) > 0) return FALSE;
1504 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1507 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1511 if (object_is_shoukinkubi(o_ptr)) return FALSE;
1515 if (o_ptr->tval == TV_CORPSE) return FALSE;
1518 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1522 if (p_ptr->prace == RACE_DEMON)
1524 if (o_ptr->tval == TV_CORPSE &&
1525 o_ptr->sval == SV_CORPSE &&
1526 my_strchr("pht", r_info[o_ptr->pval].d_char))
1530 if (p_ptr->pclass == CLASS_ARCHER)
1532 if (o_ptr->tval == TV_SKELETON ||
1533 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1536 else if (p_ptr->pclass == CLASS_NINJA)
1538 if (o_ptr->tval == TV_LITE &&
1539 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1542 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1543 p_ptr->pclass == CLASS_CAVALRY)
1545 if (o_ptr->tval == TV_WAND &&
1546 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1551 if (o_ptr->tval == TV_GOLD) return FALSE;
1558 * Automatically destroy an item if it is to be destroyed
1560 * When always_pickup is 'yes', we disable auto-destroyer function of
1561 * auto-picker/destroyer, and do only easy-auto-destroyer.
1563 static object_type autopick_last_destroyed_object;
1565 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1567 bool destroy = FALSE;
1569 /* Easy-Auto-Destroyer (3rd priority) */
1570 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1572 /* Protected by auto-picker (2nd priotity) */
1573 if (autopick_idx >= 0 &&
1574 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1577 /* Auto-destroyer works only when !always_pickup */
1580 /* Auto-picker/destroyer (1st priority) */
1581 if (autopick_idx >= 0 &&
1582 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1586 /* Not to be destroyed */
1587 if (!destroy) return;
1589 /* Now decided to destroy */
1591 disturb(FALSE, FALSE);
1594 if (!can_player_destroy_object(o_ptr))
1596 GAME_TEXT o_name[MAX_NLEN];
1598 /* Describe the object (with {terrible/special}) */
1599 object_desc(o_name, o_ptr, 0);
1601 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1606 /* Record name of destroyed item */
1607 (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1610 o_ptr->marked |= OM_AUTODESTROY;
1611 p_ptr->update |= PU_AUTODESTROY;
1618 * Auto-destroy marked item
1620 static void autopick_delayed_alter_aux(INVENTORY_IDX item)
1624 /* Get the item (in the pack) */
1625 if (item >= 0) o_ptr = &inventory[item];
1627 /* Get the item (on the floor) */
1628 else o_ptr = ¤t_floor_ptr->o_list[0 - item];
1630 if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
1632 GAME_TEXT o_name[MAX_NLEN];
1634 /* Describe the object (with {terrible/special}) */
1635 object_desc(o_name, o_ptr, 0);
1637 /* Eliminate the item (from the pack) */
1640 inven_item_increase(item, -(o_ptr->number));
1641 inven_item_optimize(item);
1644 /* Eliminate the item (from the floor) */
1647 delete_object_idx(0 - item);
1650 msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name);
1656 * Auto-destroy marked items in inventry and on floor
1658 void autopick_delayed_alter(void)
1663 * Scan inventry in reverse order to prevent
1664 * skipping after inven_item_optimize()
1666 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1667 autopick_delayed_alter_aux(item);
1669 /* Scan the pile of objects */
1670 item = current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx;
1673 OBJECT_IDX next = current_floor_ptr->o_list[item].next_o_idx;
1674 autopick_delayed_alter_aux(-item);
1681 * Auto-inscription and/or destroy
1683 * Auto-destroyer works only on inventory or on floor stack only when
1686 void autopick_alter_item(INVENTORY_IDX item, bool destroy)
1691 /* Get the item (in the pack) */
1692 if (item >= 0) o_ptr = &inventory[item];
1694 /* Get the item (on the floor) */
1695 else o_ptr = ¤t_floor_ptr->o_list[0 - item];
1697 /* Get the index in the auto-pick/destroy list */
1698 idx = is_autopick(o_ptr);
1700 /* Do auto-inscription */
1701 auto_inscribe_item(o_ptr, idx);
1703 /* Do auto-destroy if needed */
1704 if (destroy && item <= INVEN_PACK)
1705 auto_destroy_item(o_ptr, idx);
1710 * Automatically pickup/destroy items in this grid.
1712 void autopick_pickup_items(grid_type *g_ptr)
1714 OBJECT_IDX this_o_idx, next_o_idx = 0;
1716 /* Scan the pile of objects */
1717 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1720 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1721 next_o_idx = o_ptr->next_o_idx;
1723 idx = is_autopick(o_ptr);
1725 /* Item index for floor -1,-2,-3,... */
1726 auto_inscribe_item(o_ptr, idx);
1729 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1731 disturb(FALSE, FALSE);
1733 if (!inven_carry_okay(o_ptr))
1735 GAME_TEXT o_name[MAX_NLEN];
1737 object_desc(o_name, o_ptr, 0);
1739 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
1740 /* Hack - remember that the item has given a message here. */
1741 o_ptr->marked |= OM_NOMSG;
1745 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1747 char out_val[MAX_NLEN+20];
1748 GAME_TEXT o_name[MAX_NLEN];
1750 if (o_ptr->marked & OM_NO_QUERY)
1752 /* Already answered as 'No' */
1756 object_desc(o_name, o_ptr, 0);
1758 sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
1760 if (!get_check(out_val))
1762 /* Hack - remember that the item has given a message here. */
1763 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1768 py_pickup_aux(this_o_idx);
1773 * When always_pickup is 'yes', we disable
1774 * auto-destroyer from autopick function, and do only
1775 * easy-auto-destroyer.
1779 auto_destroy_item(o_ptr, idx);
1785 static const char autoregister_header[] = "?:$AUTOREGISTER";
1788 * Clear auto registered lines in the picktype.prf .
1790 static bool clear_auto_register(void)
1792 char tmp_file[1024];
1793 char pref_file[1024];
1798 bool autoregister = FALSE;
1801 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1802 pref_fff = my_fopen(pref_file, "r");
1806 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1807 pref_fff = my_fopen(pref_file, "r");
1816 /* Open a new (temporary) file */
1817 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1821 /* Close the preference file */
1823 msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
1829 /* Loop for every line */
1833 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1837 /* Delete auto-registered line */
1839 /* Count auto-destroy preference lines */
1840 if (buf[0] != '#' && buf[0] != '?') num++;
1843 /* We are looking for auto-registered line */
1846 if (streq(buf, autoregister_header))
1848 /* Delete all further lines */
1849 autoregister = TRUE;
1853 /* Copy orginally lines */
1854 fprintf(tmp_fff, "%s\n", buf);
1860 my_fclose(pref_fff);
1865 msg_format(_("以前のキャラクター用の自動設定(%d行)が残っています。",
1866 "Auto registered lines (%d lines) for previous character are remaining."), num);
1867 strcpy(buf, _("古い設定行は削除します。よろしいですか?", "These lines will be deleted. Are you sure? "));
1869 /* You can cancel it */
1870 if (!get_check(buf))
1873 autoregister = FALSE;
1875 msg_print(_("エディタのカット&ペースト等を使って必要な行を避難してください。",
1876 "Use cut & paste of auto picker editor (_) to keep old prefs."));
1881 /* If there are some changes, overwrite the original file with new one */
1884 /* Copy contents of temporary file */
1886 tmp_fff = my_fopen(tmp_file, "r");
1887 pref_fff = my_fopen(pref_file, "w");
1889 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1890 fprintf(pref_fff, "%s\n", buf);
1892 my_fclose(pref_fff);
1896 /* Kill the temporary file */
1904 * Automatically register an auto-destroy preference line
1906 bool autopick_autoregister(object_type *o_ptr)
1909 char pref_file[1024];
1911 autopick_type an_entry, *entry = &an_entry;
1913 int match_autopick = is_autopick(o_ptr);
1915 /* Already registered */
1916 if (match_autopick != -1)
1919 byte act = autopick_list[match_autopick].action;
1921 if (act & DO_AUTOPICK) what = _("自動で拾う", "auto-pickup");
1922 else if (act & DO_AUTODESTROY) what = _("自動破壊する", "auto-destroy");
1923 else if (act & DONT_AUTOPICK) what = _("放置する", "leave on floor");
1924 else /* if (act & DO_QUERY_AUTOPICK) */ what = _("確認して拾う", "query auto-pickup");
1926 msg_format(_("そのアイテムは既に%sように設定されています。", "The object is already registered to %s."), what);
1930 /* Known to be an artifact? */
1931 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1932 ((o_ptr->ident & IDENT_SENSE) &&
1933 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1935 GAME_TEXT o_name[MAX_NLEN];
1937 /* Describe the object (with {terrible/special}) */
1938 object_desc(o_name, o_ptr, 0);
1940 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1946 if (!p_ptr->autopick_autoregister)
1948 /* Clear old auto registered lines */
1949 if (!clear_auto_register()) return FALSE;
1952 /* Try a filename with player name */
1953 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1954 pref_fff = my_fopen(pref_file, "r");
1958 /* Use default name */
1959 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1960 pref_fff = my_fopen(pref_file, "r");
1963 /* Check the header */
1967 if (my_fgets(pref_fff, buf, sizeof(buf)))
1969 /* No header found */
1970 p_ptr->autopick_autoregister = FALSE;
1975 if (streq(buf, autoregister_header))
1977 /* Found the header */
1978 p_ptr->autopick_autoregister = TRUE;
1984 /* Close read only FILE* */
1987 /* Open for append */
1988 pref_fff = my_fopen(pref_file, "a");
1992 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), pref_file);
1999 if (!p_ptr->autopick_autoregister)
2001 /* Add the header */
2002 fprintf(pref_fff, "%s\n", autoregister_header);
2004 fprintf(pref_fff, "%s\n", _("# *警告!!* 以降の行は自動登録されたものです。",
2005 "# *Waring!* The lines below will be deleated later."));
2006 fprintf(pref_fff, "%s\n", _("# 後で自動的に削除されますので、必要な行は上の方へ移動しておいてください。",
2007 "# Keep it by cut & paste if you need these lines for future characters."));
2009 /* Now auto register is in-use */
2010 p_ptr->autopick_autoregister = TRUE;
2013 /* Get a preference entry */
2014 autopick_entry_from_object(entry, o_ptr);
2016 /* Set to auto-destroy (with no-display) */
2017 entry->action = DO_AUTODESTROY;
2019 /* Load the new line as preference */
2020 add_autopick_list(entry);
2022 /* Add a line to the file */
2023 /* Don't kill "entry" */
2024 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2031 /******** Auto-picker/destroyer editor **********/
2033 #define MAX_YANK MAX_LINELEN
2034 #define MAX_LINES 3000
2036 #define MARK_MARK 0x01
2037 #define MARK_BY_SHIFT 0x02
2039 #define LSTAT_BYPASS 0x01
2040 #define LSTAT_EXPRESSION 0x02
2041 #define LSTAT_AUTOREGISTER 0x04
2043 #define QUIT_WITHOUT_SAVE 1
2044 #define QUIT_AND_SAVE 2
2047 * Struct for yank buffer
2049 typedef struct chain_str {
2050 struct chain_str *next;
2056 * Data struct for text editor
2062 int old_wid, old_hgt;
2064 int old_upper, old_left;
2068 object_type *search_o_ptr;
2070 concptr last_destroyed;
2072 chain_str_type *yank;
2075 concptr *lines_list;
2076 byte states[MAX_LINES];
2088 * Dirty flag for text editor
2090 #define DIRTY_ALL 0x0001
2091 #define DIRTY_MODE 0x0004
2092 #define DIRTY_SCREEN 0x0008
2093 #define DIRTY_NOT_FOUND 0x0010
2094 #define DIRTY_NO_SEARCH 0x0020
2095 #define DIRTY_EXPRESSION 0x0040
2096 #define DIRTY_SKIP_INACTIVE 0x0080
2097 #define DIRTY_INACTIVE 0x0100
2100 * Describe which kind of object is Auto-picked/destroyed
2102 static void describe_autopick(char *buff, autopick_type *entry)
2104 concptr str = entry->name;
2105 byte act = entry->action;
2106 concptr insc = entry->insc;
2112 concptr before_str[100], body_str;
2117 /*** Collecting items ***/
2118 /*** Which can be absorbed into a slot as a bundle ***/
2119 if (IS_FLG(FLG_COLLECTING))
2120 before_str[before_n++] = "収集中で既に持っているスロットにまとめられる";
2122 /*** Unaware items ***/
2123 if (IS_FLG(FLG_UNAWARE))
2124 before_str[before_n++] = "未鑑定でその効果も判明していない";
2126 /*** Unidentified ***/
2127 if (IS_FLG(FLG_UNIDENTIFIED))
2128 before_str[before_n++] = "未鑑定の";
2130 /*** Identified ***/
2131 if (IS_FLG(FLG_IDENTIFIED))
2132 before_str[before_n++] = "鑑定済みの";
2134 /*** *Identified* ***/
2135 if (IS_FLG(FLG_STAR_IDENTIFIED))
2136 before_str[before_n++] = "完全に鑑定済みの";
2138 /*** Dice boosted (weapon of slaying) ***/
2139 if (IS_FLG(FLG_BOOSTED))
2141 before_str[before_n++] = "ダメージダイスが通常より大きい";
2145 /*** Weapons whose dd*ds is more than nn ***/
2146 if (IS_FLG(FLG_MORE_DICE))
2148 static char more_than_desc_str[] = "___";
2149 before_str[before_n++] = "ダメージダイスの最大値が";
2152 sprintf(more_than_desc_str,"%d", entry->dice);
2153 before_str[before_n++] = more_than_desc_str;
2154 before_str[before_n++] = "以上の";
2157 /*** Items whose magical bonus is more than nn ***/
2158 if (IS_FLG(FLG_MORE_BONUS))
2160 static char more_bonus_desc_str[] = "___";
2161 before_str[before_n++] = "修正値が(+";
2163 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2164 before_str[before_n++] = more_bonus_desc_str;
2165 before_str[before_n++] = ")以上の";
2168 /*** Worthless items ***/
2169 if (IS_FLG(FLG_WORTHLESS))
2170 before_str[before_n++] = "店で無価値と判定される";
2173 if (IS_FLG(FLG_ARTIFACT))
2175 before_str[before_n++] = "アーティファクトの";
2180 if (IS_FLG(FLG_EGO))
2182 before_str[before_n++] = "エゴアイテムの";
2187 if (IS_FLG(FLG_GOOD))
2189 before_str[before_n++] = "上質の";
2194 if (IS_FLG(FLG_NAMELESS))
2196 before_str[before_n++] = "エゴでもアーティファクトでもない";
2201 if (IS_FLG(FLG_AVERAGE))
2203 before_str[before_n++] = "並の";
2207 /*** Rare equipments ***/
2208 if (IS_FLG(FLG_RARE))
2210 before_str[before_n++] = "ドラゴン装備やカオス・ブレード等を含む珍しい";
2214 /*** Common equipments ***/
2215 if (IS_FLG(FLG_COMMON))
2217 before_str[before_n++] = "ありふれた(ドラゴン装備やカオス・ブレード等の珍しい物ではない)";
2221 /*** Wanted monster's corpse/skeletons ***/
2222 if (IS_FLG(FLG_WANTED))
2224 before_str[before_n++] = "ハンター事務所で賞金首とされている";
2228 /*** Human corpse/skeletons (for Daemon magic) ***/
2229 if (IS_FLG(FLG_HUMAN))
2231 before_str[before_n++] = "悪魔魔法で使うための人間やヒューマノイドの";
2235 /*** Unique monster's corpse/skeletons/statues ***/
2236 if (IS_FLG(FLG_UNIQUE))
2238 before_str[before_n++] = "ユニークモンスターの";
2242 /*** Unreadable spellbooks ***/
2243 if (IS_FLG(FLG_UNREADABLE))
2245 before_str[before_n++] = "あなたが読めない領域の";
2249 /*** First realm spellbooks ***/
2250 if (IS_FLG(FLG_REALM1))
2252 before_str[before_n++] = "第一領域の";
2256 /*** Second realm spellbooks ***/
2257 if (IS_FLG(FLG_REALM2))
2259 before_str[before_n++] = "第二領域の";
2263 /*** First rank spellbooks ***/
2264 if (IS_FLG(FLG_FIRST))
2266 before_str[before_n++] = "全4冊の内の1冊目の";
2270 /*** Second rank spellbooks ***/
2271 if (IS_FLG(FLG_SECOND))
2273 before_str[before_n++] = "全4冊の内の2冊目の";
2277 /*** Third rank spellbooks ***/
2278 if (IS_FLG(FLG_THIRD))
2280 before_str[before_n++] = "全4冊の内の3冊目の";
2284 /*** Fourth rank spellbooks ***/
2285 if (IS_FLG(FLG_FOURTH))
2287 before_str[before_n++] = "全4冊の内の4冊目の";
2292 if (IS_FLG(FLG_ITEMS))
2293 ; /* Nothing to do */
2294 else if (IS_FLG(FLG_WEAPONS))
2296 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2298 else if (IS_FLG(FLG_ARMORS))
2300 else if (IS_FLG(FLG_MISSILES))
2301 body_str = "弾や矢やクロスボウの矢";
2302 else if (IS_FLG(FLG_DEVICES))
2303 body_str = "巻物や魔法棒や杖やロッド";
2304 else if (IS_FLG(FLG_LIGHTS))
2305 body_str = "光源用のアイテム";
2306 else if (IS_FLG(FLG_JUNKS))
2307 body_str = "折れた棒等のガラクタ";
2308 else if (IS_FLG(FLG_CORPSES))
2310 else if (IS_FLG(FLG_SPELLBOOKS))
2312 else if (IS_FLG(FLG_HAFTED))
2314 else if (IS_FLG(FLG_SHIELDS))
2316 else if (IS_FLG(FLG_BOWS))
2317 body_str = "スリングや弓やクロスボウ";
2318 else if (IS_FLG(FLG_RINGS))
2320 else if (IS_FLG(FLG_AMULETS))
2321 body_str = "アミュレット";
2322 else if (IS_FLG(FLG_SUITS))
2324 else if (IS_FLG(FLG_CLOAKS))
2326 else if (IS_FLG(FLG_HELMS))
2327 body_str = "ヘルメットや冠";
2328 else if (IS_FLG(FLG_GLOVES))
2330 else if (IS_FLG(FLG_BOOTS))
2335 strcat(buff, "全ての");
2336 else for (i = 0; i < before_n && before_str[i]; i++)
2337 strcat(buff, before_str[i]);
2339 strcat(buff, body_str);
2349 strcat(buff, "で、名前が「");
2350 strncat(buff, str, 80);
2352 strcat(buff, "」で始まるもの");
2354 strcat(buff, "」を含むもの");
2359 strncat(buff, format("に「%s」", insc), 80);
2361 if (my_strstr(insc, "%%all"))
2362 strcat(buff, "(%%allは全能力を表す英字の記号で置換)");
2363 else if (my_strstr(insc, "%all"))
2364 strcat(buff, "(%allは全能力を表す記号で置換)");
2365 else if (my_strstr(insc, "%%"))
2366 strcat(buff, "(%%は追加能力を表す英字の記号で置換)");
2367 else if (my_strstr(insc, "%"))
2368 strcat(buff, "(%は追加能力を表す記号で置換)");
2370 strcat(buff, "と刻んで");
2375 if (act & DONT_AUTOPICK)
2376 strcat(buff, "放置する。");
2377 else if (act & DO_AUTODESTROY)
2378 strcat(buff, "破壊する。");
2379 else if (act & DO_QUERY_AUTOPICK)
2380 strcat(buff, "確認の後に拾う。");
2382 strcat(buff, "拾う。");
2384 if (act & DO_DISPLAY)
2386 if (act & DONT_AUTOPICK)
2387 strcat(buff, "全体マップ('M')で'N'を押したときに表示する。");
2388 else if (act & DO_AUTODESTROY)
2389 strcat(buff, "全体マップ('M')で'K'を押したときに表示する。");
2391 strcat(buff, "全体マップ('M')で'M'を押したときに表示する。");
2394 strcat(buff, "全体マップには表示しない。");
2398 concptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2399 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2403 /*** Collecting items ***/
2404 /*** Which can be absorbed into a slot as a bundle ***/
2405 if (IS_FLG(FLG_COLLECTING))
2406 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2408 /*** Unaware items ***/
2409 if (IS_FLG(FLG_UNAWARE))
2411 before_str[before_n++] = "unidentified";
2412 whose_str[whose_n++] = "basic abilities are not known";
2415 /*** Unidentified ***/
2416 if (IS_FLG(FLG_UNIDENTIFIED))
2417 before_str[before_n++] = "unidentified";
2419 /*** Identified ***/
2420 if (IS_FLG(FLG_IDENTIFIED))
2421 before_str[before_n++] = "identified";
2423 /*** *Identified* ***/
2424 if (IS_FLG(FLG_STAR_IDENTIFIED))
2425 before_str[before_n++] = "fully identified";
2427 /*** Rare equipments ***/
2428 if (IS_FLG(FLG_RARE))
2430 before_str[before_n++] = "very rare";
2431 body_str = "equipments";
2432 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2435 /*** Common equipments ***/
2436 if (IS_FLG(FLG_COMMON))
2438 before_str[before_n++] = "relatively common";
2439 body_str = "equipments";
2440 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2443 /*** Worthless items ***/
2444 if (IS_FLG(FLG_WORTHLESS))
2446 before_str[before_n++] = "worthless";
2447 which_str[which_n++] = "can not be sold at stores";
2451 if (IS_FLG(FLG_ARTIFACT))
2453 before_str[before_n++] = "artifact";
2457 if (IS_FLG(FLG_EGO))
2459 before_str[before_n++] = "ego";
2463 if (IS_FLG(FLG_GOOD))
2465 body_str = "equipment";
2466 which_str[which_n++] = "have good quality";
2470 if (IS_FLG(FLG_NAMELESS))
2472 body_str = "equipment";
2473 which_str[which_n++] = "is neither ego-item nor artifact";
2477 if (IS_FLG(FLG_AVERAGE))
2479 body_str = "equipment";
2480 which_str[which_n++] = "have average quality";
2483 /*** Dice boosted (weapon of slaying) ***/
2484 if (IS_FLG(FLG_BOOSTED))
2486 body_str = "weapons";
2487 whose_str[whose_n++] = "damage dice is bigger than normal";
2490 /*** Weapons whose dd*ds is more than nn ***/
2491 if (IS_FLG(FLG_MORE_DICE))
2493 static char more_than_desc_str[] =
2494 "maximum damage from dice is bigger than __";
2495 body_str = "weapons";
2497 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2499 whose_str[whose_n++] = more_than_desc_str;
2502 /*** Items whose magical bonus is more than nn ***/
2503 if (IS_FLG(FLG_MORE_BONUS))
2505 static char more_bonus_desc_str[] =
2506 "magical bonus is bigger than (+__)";
2508 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2509 "%d)", entry->bonus);
2510 whose_str[whose_n++] = more_bonus_desc_str;
2513 /*** Wanted monster's corpse/skeletons ***/
2514 if (IS_FLG(FLG_WANTED))
2516 body_str = "corpse or skeletons";
2517 which_str[which_n++] = "is wanted at the Hunter's Office";
2520 /*** Human corpse/skeletons (for Daemon magic) ***/
2521 if (IS_FLG(FLG_HUMAN))
2523 before_str[before_n++] = "humanoid";
2524 body_str = "corpse or skeletons";
2525 which_str[which_n++] = "can be used for Daemon magic";
2528 /*** Unique monster's corpse/skeletons/statues ***/
2529 if (IS_FLG(FLG_UNIQUE))
2531 before_str[before_n++] = "unique monster's";
2532 body_str = "corpse or skeletons";
2535 /*** Unreadable spellbooks ***/
2536 if (IS_FLG(FLG_UNREADABLE))
2538 body_str = "spellbooks";
2539 after_str[after_n++] = "of different realms from yours";
2542 /*** First realm spellbooks ***/
2543 if (IS_FLG(FLG_REALM1))
2545 body_str = "spellbooks";
2546 after_str[after_n++] = "of your first realm";
2549 /*** Second realm spellbooks ***/
2550 if (IS_FLG(FLG_REALM2))
2552 body_str = "spellbooks";
2553 after_str[after_n++] = "of your second realm";
2556 /*** First rank spellbooks ***/
2557 if (IS_FLG(FLG_FIRST))
2559 before_str[before_n++] = "first one of four";
2560 body_str = "spellbooks";
2563 /*** Second rank spellbooks ***/
2564 if (IS_FLG(FLG_SECOND))
2566 before_str[before_n++] = "second one of four";
2567 body_str = "spellbooks";
2570 /*** Third rank spellbooks ***/
2571 if (IS_FLG(FLG_THIRD))
2573 before_str[before_n++] = "third one of four";
2574 body_str = "spellbooks";
2577 /*** Fourth rank spellbooks ***/
2578 if (IS_FLG(FLG_FOURTH))
2580 before_str[before_n++] = "fourth one of four";
2581 body_str = "spellbooks";
2585 if (IS_FLG(FLG_ITEMS))
2586 ; /* Nothing to do */
2587 else if (IS_FLG(FLG_WEAPONS))
2588 body_str = "weapons";
2589 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2590 body_str = "favorite weapons";
2591 else if (IS_FLG(FLG_ARMORS))
2592 body_str = "armors";
2593 else if (IS_FLG(FLG_MISSILES))
2594 body_str = "shots, arrows or crossbow bolts";
2595 else if (IS_FLG(FLG_DEVICES))
2596 body_str = "scrolls, wands, staves or rods";
2597 else if (IS_FLG(FLG_LIGHTS))
2598 body_str = "light sources";
2599 else if (IS_FLG(FLG_JUNKS))
2600 body_str = "junk such as broken sticks";
2601 else if (IS_FLG(FLG_CORPSES))
2602 body_str = "corpses or skeletons";
2603 else if (IS_FLG(FLG_SPELLBOOKS))
2604 body_str = "spellbooks";
2605 else if (IS_FLG(FLG_HAFTED))
2606 body_str = "hafted weapons";
2607 else if (IS_FLG(FLG_SHIELDS))
2608 body_str = "shields";
2609 else if (IS_FLG(FLG_BOWS))
2610 body_str = "slings, bows or crossbows";
2611 else if (IS_FLG(FLG_RINGS))
2613 else if (IS_FLG(FLG_AMULETS))
2614 body_str = "amulets";
2615 else if (IS_FLG(FLG_SUITS))
2616 body_str = "body armors";
2617 else if (IS_FLG(FLG_CLOAKS))
2618 body_str = "cloaks";
2619 else if (IS_FLG(FLG_HELMS))
2620 body_str = "helms or crowns";
2621 else if (IS_FLG(FLG_GLOVES))
2622 body_str = "gloves";
2623 else if (IS_FLG(FLG_BOOTS))
2626 /* Prepare a string for item name */
2633 whose_str[whose_n++] = "name is beginning with \"";
2636 which_str[which_n++] = "have \"";
2640 /* Describe action flag */
2641 if (act & DONT_AUTOPICK)
2642 strcpy(buff, "Leave on floor ");
2643 else if (act & DO_AUTODESTROY)
2644 strcpy(buff, "Destroy ");
2645 else if (act & DO_QUERY_AUTOPICK)
2646 strcpy(buff, "Ask to pick up ");
2648 strcpy(buff, "Pickup ");
2650 /* Auto-insctiption */
2653 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2655 if (my_strstr(insc, "%all"))
2656 strcat(buff, ", replacing %all with code string representing all abilities,");
2657 else if (my_strstr(insc, "%"))
2658 strcat(buff, ", replacing % with code string representing extra random abilities,");
2660 strcat(buff, " on ");
2665 strcat(buff, "all ");
2666 else for (i = 0; i < before_n && before_str[i]; i++)
2668 strcat(buff, before_str[i]);
2673 strcat(buff, body_str);
2676 for (i = 0; i < after_n && after_str[i]; i++)
2679 strcat(buff, after_str[i]);
2683 for (i = 0; i < whose_n && whose_str[i]; i++)
2686 strcat(buff, " whose ");
2688 strcat(buff, ", and ");
2690 strcat(buff, whose_str[i]);
2693 /* Item name ; whose name is beginning with "str" */
2700 /* whose ..., and which .... */
2701 if (whose_n && which_n)
2702 strcat(buff, ", and ");
2705 for (i = 0; i < which_n && which_str[i]; i++)
2708 strcat(buff, " which ");
2710 strcat(buff, ", and ");
2712 strcat(buff, which_str[i]);
2715 /* Item name ; which have "str" as part of its name */
2718 strncat(buff, str, 80);
2719 strcat(buff, "\" as part of its name");
2723 /* Describe whether it will be displayed on the full map or not */
2724 if (act & DO_DISPLAY)
2726 if (act & DONT_AUTOPICK)
2727 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2728 else if (act & DO_AUTODESTROY)
2729 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2731 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2734 strcat(buff, " Not displayed in the full map.");
2741 * Read whole lines of a file to memory
2743 static concptr *read_text_lines(concptr filename)
2745 concptr *lines_list = NULL;
2751 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2754 fff = my_fopen(buf, "r");
2758 /* Allocate list of pointers */
2759 C_MAKE(lines_list, MAX_LINES, concptr);
2762 while (0 == my_fgets(fff, buf, sizeof(buf)))
2764 lines_list[lines++] = string_make(buf);
2765 if (lines >= MAX_LINES - 1) break;
2768 lines_list[0] = string_make("");
2773 if (!fff) return NULL;
2779 * Copy the default autopick file to the user directory
2781 static void prepare_default_pickpref(void)
2783 const concptr messages[] = {
2784 _("あなたは「自動拾いエディタ」を初めて起動しました。", "You have activated the Auto-Picker Editor for the first time."),
2785 _("自動拾いのユーザー設定ファイルがまだ書かれていないので、", "Since user pref file for autopick is not yet created,"),
2786 _("基本的な自動拾い設定ファイルをlib/pref/picktype.prfからコピーします。", "the default setting is loaded from lib/pref/pickpref.prf ."),
2794 concptr filename = pickpref_filename(PT_DEFAULT);
2796 /* Display messages */
2797 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2802 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2803 user_fp = my_fopen(buf, "w");
2806 if (!user_fp) return;
2808 /* Write header messages for a notification */
2809 fprintf(user_fp, "#***\n");
2810 for (i = 0; messages[i]; i++)
2812 fprintf(user_fp, "#*** %s\n", messages[i]);
2814 fprintf(user_fp, "#***\n\n\n");
2817 /* Open the default file */
2818 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2819 pref_fp = my_fopen(buf, "r");
2828 /* Copy the contents of default file */
2829 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2830 fprintf(user_fp, "%s\n", buf);
2837 * Read an autopick prefence file to memory
2838 * Prepare default if no user file is found
2840 static concptr *read_pickpref_text_lines(int *filename_mode_p)
2843 concptr *lines_list;
2845 /* Try a filename with player name */
2846 *filename_mode_p = PT_WITH_PNAME;
2847 strcpy(buf, pickpref_filename(*filename_mode_p));
2848 lines_list = read_text_lines(buf);
2852 /* Use default name */
2853 *filename_mode_p = PT_DEFAULT;
2854 strcpy(buf, pickpref_filename(*filename_mode_p));
2855 lines_list = read_text_lines(buf);
2860 /* There is no preference file in the user directory */
2862 /* Copy the default autopick file to the user directory */
2863 prepare_default_pickpref();
2865 /* Use default name again */
2866 lines_list = read_text_lines(buf);
2871 /* Allocate list of pointers */
2872 C_MAKE(lines_list, MAX_LINES, concptr);
2873 lines_list[0] = string_make("");
2880 * Write whole lines of memory to a file.
2882 static bool write_text_lines(concptr filename, concptr *lines_list)
2889 /* Build the filename */
2890 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2893 fff = my_fopen(buf, "w");
2896 for (lines = 0; lines_list[lines]; lines++)
2897 my_fputs(fff, lines_list[lines], 1024);
2902 if (!fff) return FALSE;
2908 * Free memory of lines_list.
2910 static void free_text_lines(concptr *lines_list)
2914 for (lines = 0; lines_list[lines]; lines++)
2915 string_free(lines_list[lines]);
2917 /* free list of pointers */
2918 C_KILL(lines_list, MAX_LINES, concptr);
2923 * Delete or insert string
2925 static void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
2931 /* Some lines are selected */
2934 by1 = MIN(tb->my, tb->cy);
2935 by2 = MAX(tb->my, tb->cy);
2938 /* No mark -- Select current line */
2939 else /* if (!tb->mark) */
2945 /* Set/Reset flag of each line */
2946 for (y = by1; y <= by2; y++)
2948 autopick_type an_entry, *entry = &an_entry;
2950 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2952 string_free(tb->lines_list[y]);
2956 /* Add? or Remove? */
2957 if (!IS_FLG(flg)) add = TRUE;
2960 /* No more change */
2964 /* You can use only one noun flag */
2965 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2968 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2972 /* You can use only one identify state flag */
2973 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2976 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2980 /* You can use only one flag in artifact/ego/nameless */
2981 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
2984 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
2988 /* You can use only one flag in rare/common */
2989 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
2992 for (i = FLG_RARE; i <= FLG_COMMON; i++)
2996 if (add) ADD_FLG(flg);
2999 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3002 tb->dirty_flags |= DIRTY_ALL;
3004 /* Text is changed */
3011 * Change command letter
3013 static void toggle_command_letter(text_body_type *tb, byte flg)
3015 autopick_type an_entry, *entry = &an_entry;
3020 /* Some lines are selected */
3023 by1 = MIN(tb->my, tb->cy);
3024 by2 = MAX(tb->my, tb->cy);
3027 /* No mark -- Select current line */
3028 else /* if (!tb->mark) */
3034 /* Set/Reset flag of each line */
3035 for (y = by1; y <= by2; y++)
3039 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3041 string_free(tb->lines_list[y]);
3045 /* Add? or Remove? */
3046 if (!(entry->action & flg)) add = TRUE;
3049 /* No more change */
3053 /* Count number of letter (by negative number) */
3054 if (entry->action & DONT_AUTOPICK) wid--;
3055 else if (entry->action & DO_AUTODESTROY) wid--;
3056 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3057 if (!(entry->action & DO_DISPLAY)) wid--;
3059 /* Set/Reset the flag */
3060 if (flg != DO_DISPLAY)
3062 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3063 if (add) entry->action |= flg;
3064 else entry->action |= DO_AUTOPICK;
3068 entry->action &= ~(DO_DISPLAY);
3069 if (add) entry->action |= flg;
3072 /* Correct cursor location */
3075 if (entry->action & DONT_AUTOPICK) wid++;
3076 else if (entry->action & DO_AUTODESTROY) wid++;
3077 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3078 if (!(entry->action & DO_DISPLAY)) wid++;
3080 if (wid > 0) tb->cx++;
3081 if (wid < 0 && tb->cx > 0) tb->cx--;
3084 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3087 tb->dirty_flags |= DIRTY_ALL;
3089 /* Text is changed */
3095 * Delete or insert string
3097 static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
3101 /* Some lines are selected */
3104 by1 = MIN(tb->my, tb->cy);
3105 by2 = MAX(tb->my, tb->cy);
3108 /* No mark -- Select current line */
3109 else /* if (!tb->mark) */
3115 /* Set/Reset flag of each line */
3116 for (y = by1; y <= by2; y++)
3118 autopick_type an_entry, *entry = &an_entry;
3120 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3122 /* There is the flag already */
3125 /* Free memory for the entry */
3126 autopick_free_entry(entry);
3131 string_free(tb->lines_list[y]);
3133 /* Remove all noun flag */
3134 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3137 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3143 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3146 tb->dirty_flags |= DIRTY_ALL;
3148 /* Text is changed */
3155 * Check if this line is expression or not.
3156 * And update it if it is.
3158 static void check_expression_line(text_body_type *tb, int y)
3160 concptr s = tb->lines_list[y];
3162 if ((s[0] == '?' && s[1] == ':') ||
3163 (tb->states[y] & LSTAT_BYPASS))
3165 /* Expressions need re-evaluation */
3166 tb->dirty_flags |= DIRTY_EXPRESSION;
3172 * Add an empty line at the last of the file
3174 static bool add_empty_line(text_body_type *tb)
3178 for (k = 0; tb->lines_list[k]; k++)
3179 /* count number of lines */ ;
3181 /* Too many lines! */
3182 if (k >= MAX_LINES - 2) return FALSE;
3184 /* The last line is already empty */
3185 if (!tb->lines_list[k-1][0]) return FALSE;
3187 /* Create new empty line */
3188 tb->lines_list[k] = string_make("");
3190 /* Expressions need re-evaluation */
3191 tb->dirty_flags |= DIRTY_EXPRESSION;
3193 /* Text is changed */
3196 /* A line is added */
3202 * Insert return code and split the line
3204 static bool insert_return_code(text_body_type *tb)
3206 char buf[MAX_LINELEN];
3209 for (k = 0; tb->lines_list[k]; k++)
3210 /* count number of lines */ ;
3212 if (k >= MAX_LINES - 2) return FALSE;
3215 /* Move down lines */
3216 for (; tb->cy < k; k--)
3218 tb->lines_list[k+1] = tb->lines_list[k];
3219 tb->states[k+1] = tb->states[k];
3222 /* Split current line */
3223 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3226 if (iskanji(tb->lines_list[tb->cy][i]))
3227 buf[j++] = tb->lines_list[tb->cy][i++];
3229 buf[j++] = tb->lines_list[tb->cy][i];
3232 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3233 string_free(tb->lines_list[tb->cy]);
3234 tb->lines_list[tb->cy] = string_make(buf);
3236 /* Expressions need re-evaluation */
3237 tb->dirty_flags |= DIRTY_EXPRESSION;
3239 /* Text is changed */
3247 * Choose an item and get auto-picker entry from it.
3249 static bool entry_from_choosed_object(autopick_type *entry)
3254 q = _("どのアイテムを登録しますか? ", "Enter which item? ");
3255 s = _("アイテムを持っていない。", "You have nothing to enter.");
3256 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3257 if (!o_ptr) return FALSE;
3259 autopick_entry_from_object(entry, o_ptr);
3265 * Choose an item for search
3267 static byte get_object_for_search(object_type **o_handle, concptr *search_strp)
3269 char buf[MAX_NLEN+20];
3273 q = _("どのアイテムを検索しますか? ", "Enter which item? ");
3274 s = _("アイテムを持っていない。", "You have nothing to enter.");
3275 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3276 if (!o_ptr) return 0;
3280 string_free(*search_strp);
3281 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3282 *search_strp = string_make(format("<%s>", buf));
3288 * Prepare for search by destroyed object
3290 static byte get_destroyed_object_for_search(object_type **o_handle, concptr *search_strp)
3292 char buf[MAX_NLEN+20];
3294 if (!autopick_last_destroyed_object.k_idx) return 0;
3296 *o_handle = &autopick_last_destroyed_object;
3298 string_free(*search_strp);
3299 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3300 *search_strp = string_make(format("<%s>", buf));
3306 * Choose an item or string for search
3308 static byte get_string_for_search(object_type **o_handle, concptr *search_strp)
3314 * TERM_YELLOW : Overwrite mode
3315 * TERM_WHITE : Insert mode
3317 byte color = TERM_YELLOW;
3318 char buf[MAX_NLEN+20];
3321 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
3322 int col = sizeof(prompt) - 1;
3324 /* Prepare string buffer for edit */
3325 if (*search_strp) strcpy(buf, *search_strp);
3328 /* Object searching mode */
3331 color = TERM_L_GREEN;
3334 /* Display prompt */
3344 /* Display the string */
3345 Term_erase(col, 0, 255);
3346 Term_putstr(col, 0, -1, color, buf);
3349 Term_gotoxy(col + pos, 0);
3351 /* Get a special key code */
3352 skey = inkey_special(TRUE);
3354 /* Analyze the key */
3362 /* Now on insert mode */
3365 /* No move at beginning of line */
3366 if (0 == pos) break;
3370 int next_pos = i + 1;
3373 if (iskanji(buf[i])) next_pos++;
3376 /* Is there the cursor at next position? */
3377 if (next_pos >= pos) break;
3383 /* Get previous position */
3391 /* Now on insert mode */
3394 /* No move at end of line */
3395 if ('\0' == buf[pos]) break;
3399 if (iskanji(buf[pos])) pos += 2;
3417 if (*o_handle) return (back ? -1 : 1);
3418 string_free(*search_strp);
3419 *search_strp = string_make(buf);
3421 return (back ? -1 : 1);
3424 return get_object_for_search(o_handle, search_strp);
3427 /* Prepare string for destroyed object if there is one. */
3428 if (get_destroyed_object_for_search(o_handle, search_strp))
3438 /* Now on insert mode */
3441 /* No move at beginning of line */
3442 if (0 == pos) break;
3446 int next_pos = i + 1;
3449 if (iskanji(buf[i])) next_pos++;
3452 /* Is there the cursor at next position? */
3453 if (next_pos >= pos) break;
3459 /* Get previous position */
3462 /* Fall through to 'Delete key' */
3471 /* Now on insert mode */
3474 /* No move at end of line */
3475 if ('\0' == buf[pos]) break;
3477 /* Position of next character */
3481 /* Next character is one more byte away */
3482 if (iskanji(buf[pos])) src++;
3487 /* Move characters at src to dst */
3488 while ('\0' != (buf[dst++] = buf[src++]))
3496 /* Insert a character */
3501 /* Ignore special keys */
3502 if (skey & SKEY_MASK) break;
3504 /* Get a character code */
3507 /* Was non insert mode? */
3508 if (color != TERM_WHITE)
3510 /* Was object searching mode */
3511 if (color == TERM_L_GREEN)
3513 /* Cancel the mode */
3516 /* Remove indicating string */
3517 string_free(*search_strp);
3518 *search_strp = NULL;
3521 /* Overwrite default string */
3524 /* Go to insert mode */
3528 /* Save right part of string */
3529 strcpy(tmp, buf + pos);
3535 /* Bypass macro processing */
3553 if (pos < len && (isprint(c) || iskana(c)))
3555 if (pos < len && isprint(c))
3569 /* Write back the left part of string */
3570 my_strcat(buf, tmp, len + 1);
3577 /* Object searching mode was cancelled? */
3578 if (*o_handle && color != TERM_L_GREEN)
3580 /* Cancel the mode */
3583 /* Remove indicating string */
3585 string_free(*search_strp);
3586 *search_strp = NULL;
3591 } /* while (TRUE) */
3596 * Search next line matches for o_ptr
3598 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3600 autopick_type an_entry, *entry = &an_entry;
3601 GAME_TEXT o_name[MAX_NLEN];
3602 int bypassed_cy = -1;
3604 /* Start searching from current cursor position */
3607 /* Prepare object name string first */
3608 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3610 /* Convert the string to lower case */
3611 str_tolower(o_name);
3620 if (!tb->lines_list[++i]) break;
3627 /* Is this line is a correct entry? */
3628 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3630 /* Does this line match to the object? */
3631 match = is_autopick_aux(o_ptr, entry, o_name);
3632 autopick_free_entry(entry);
3633 if (!match) continue;
3635 /* Found a line but it's inactive */
3636 if (tb->states[i] & LSTAT_BYPASS)
3638 /* If it is first found, remember it */
3639 if (bypassed_cy == -1) bypassed_cy = i;
3642 /* Found an active line! */
3645 /* Move to this line */
3649 if (bypassed_cy != -1)
3651 /* Mark as some lines are skipped */
3652 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3660 if (bypassed_cy != -1)
3662 /* Move to the remembered line */
3664 tb->cy = bypassed_cy;
3666 /* Mark as this line is inactive */
3667 tb->dirty_flags |= DIRTY_INACTIVE;
3672 /* Mark as NOT FOUND */
3673 tb->dirty_flags |= DIRTY_NOT_FOUND;
3681 * Search next line matches to the string
3683 static void search_for_string(text_body_type *tb, concptr search_str, bool forward)
3685 int bypassed_cy = -1;
3686 int bypassed_cx = 0;
3688 /* Start searching from current cursor position */
3698 if (!tb->lines_list[++i]) break;
3705 /* Look for the string pattern */
3706 pos = my_strstr(tb->lines_list[i], search_str);
3711 /* Found a line but it's inactive */
3712 if ((tb->states[i] & LSTAT_BYPASS) &&
3713 !(tb->states[i] & LSTAT_EXPRESSION))
3715 /* If it is first found, remember it */
3716 if (bypassed_cy == -1)
3719 bypassed_cx = (int)(pos - tb->lines_list[i]);
3723 /* Found an active line! */
3726 /* Move to this location */
3727 tb->cx = (int)(pos - tb->lines_list[i]);
3730 if (bypassed_cy != -1)
3732 /* Mark as some lines are skipped */
3733 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3741 if (bypassed_cy != -1)
3743 /* Move to the remembered line */
3744 tb->cx = bypassed_cx;
3745 tb->cy = bypassed_cy;
3747 /* Mark as this line is inactive */
3748 tb->dirty_flags |= DIRTY_INACTIVE;
3753 /* Mark as NOT FOUND */
3754 tb->dirty_flags |= DIRTY_NOT_FOUND;
3764 * Editor command id's
3767 #define EC_SAVEQUIT 2
3778 #define EC_PGDOWN 13
3780 #define EC_BOTTOM 15
3785 #define EC_KILL_LINE 20
3786 #define EC_DELETE_CHAR 21
3787 #define EC_BACKSPACE 22
3788 #define EC_SEARCH_STR 23
3789 #define EC_SEARCH_FORW 24
3790 #define EC_SEARCH_BACK 25
3791 #define EC_SEARCH_OBJ 26
3792 #define EC_SEARCH_DESTROYED 27
3793 #define EC_INSERT_OBJECT 28
3794 #define EC_INSERT_DESTROYED 29
3795 #define EC_INSERT_BLOCK 30
3796 #define EC_INSERT_MACRO 31
3797 #define EC_INSERT_KEYMAP 32
3798 #define EC_CL_AUTOPICK 33
3799 #define EC_CL_DESTROY 34
3800 #define EC_CL_LEAVE 35
3801 #define EC_CL_QUERY 36
3802 #define EC_CL_NO_DISP 37
3803 #define EC_OK_COLLECTING 38
3804 #define EC_IK_UNAWARE 39
3805 #define EC_IK_UNIDENTIFIED 40
3806 #define EC_IK_IDENTIFIED 41
3807 #define EC_IK_STAR_IDENTIFIED 42
3808 #define EC_OK_BOOSTED 43
3809 #define EC_OK_MORE_DICE 44
3810 #define EC_OK_MORE_BONUS 45
3811 #define EC_OK_WORTHLESS 46
3812 #define EC_OK_ARTIFACT 47
3813 #define EC_OK_EGO 48
3814 #define EC_OK_GOOD 49
3815 #define EC_OK_NAMELESS 50
3816 #define EC_OK_AVERAGE 51
3817 #define EC_OK_RARE 52
3818 #define EC_OK_COMMON 53
3819 #define EC_OK_WANTED 54
3820 #define EC_OK_UNIQUE 55
3821 #define EC_OK_HUMAN 56
3822 #define EC_OK_UNREADABLE 57
3823 #define EC_OK_REALM1 58
3824 #define EC_OK_REALM2 59
3825 #define EC_OK_FIRST 60
3826 #define EC_OK_SECOND 61
3827 #define EC_OK_THIRD 62
3828 #define EC_OK_FOURTH 63
3829 #define EC_KK_WEAPONS 64
3830 #define EC_KK_FAVORITE_WEAPONS 65
3831 #define EC_KK_ARMORS 66
3832 #define EC_KK_MISSILES 67
3833 #define EC_KK_DEVICES 68
3834 #define EC_KK_LIGHTS 69
3835 #define EC_KK_JUNKS 70
3836 #define EC_KK_CORPSES 71
3837 #define EC_KK_SPELLBOOKS 72
3838 #define EC_KK_SHIELDS 73
3839 #define EC_KK_BOWS 74
3840 #define EC_KK_RINGS 75
3841 #define EC_KK_AMULETS 76
3842 #define EC_KK_SUITS 77
3843 #define EC_KK_CLOAKS 78
3844 #define EC_KK_HELMS 79
3845 #define EC_KK_GLOVES 80
3846 #define EC_KK_BOOTS 81
3852 static GAME_TEXT MN_QUIT[] = "セーブ無しで終了";
3853 static GAME_TEXT MN_SAVEQUIT[] = "セーブして終了";
3854 static GAME_TEXT MN_REVERT[] = "全ての変更を破棄";
3855 static GAME_TEXT MN_HELP[] = "ヘルプ";
3857 static GAME_TEXT MN_MOVE[] = "カーソル移動";
3858 static GAME_TEXT MN_LEFT[] = "左 (←矢印キー)";
3859 static GAME_TEXT MN_DOWN[] = "下 (↓矢印キー)";
3860 static GAME_TEXT MN_UP[] = "上 (↑矢印キー)";
3861 static GAME_TEXT MN_RIGHT[] = "右 (→矢印キー)";
3862 static GAME_TEXT MN_BOL[] = "行の先頭";
3863 static GAME_TEXT MN_EOL[] = "行の終端";
3864 static GAME_TEXT MN_PGUP[] = "上のページ (PageUpキー)";
3865 static GAME_TEXT MN_PGDOWN[] = "下のページ (PageDownキー)";
3866 static GAME_TEXT MN_TOP[] = "1行目へ移動 (Homeキー)";
3867 static GAME_TEXT MN_BOTTOM[] = "最下行へ移動(Endキー)";
3869 static GAME_TEXT MN_EDIT[] = "編集";
3870 static GAME_TEXT MN_CUT[] = "カット";
3871 static GAME_TEXT MN_COPY[] = "コピー";
3872 static GAME_TEXT MN_PASTE[] = "ペースト";
3873 static GAME_TEXT MN_BLOCK[] = "選択範囲の指定";
3874 static GAME_TEXT MN_KILL_LINE[] = "行の残りを削除";
3875 static GAME_TEXT MN_DELETE_CHAR[] = "1文字削除";
3876 static GAME_TEXT MN_BACKSPACE[] = "バックスペース";
3877 static GAME_TEXT MN_RETURN[] = "改行";
3879 static GAME_TEXT MN_SEARCH[] = "検索";
3880 static GAME_TEXT MN_SEARCH_STR[] = "文字列で検索";
3881 static GAME_TEXT MN_SEARCH_FORW[] = "前方へ再検索";
3882 static GAME_TEXT MN_SEARCH_BACK[] = "後方へ再検索";
3883 static GAME_TEXT MN_SEARCH_OBJ[] = "アイテムを選択して検索";
3884 static GAME_TEXT MN_SEARCH_DESTROYED[] = "自動破壊されたアイテムで検索";
3886 static GAME_TEXT MN_INSERT[] = "色々挿入";
3887 static GAME_TEXT MN_INSERT_OBJECT[] = "選択したアイテムの名前を挿入";
3888 static GAME_TEXT MN_INSERT_DESTROYED[] = "自動破壊されたアイテムの名前を挿入";
3889 static GAME_TEXT MN_INSERT_BLOCK[] = "条件分岐ブロックの例を挿入";
3890 static GAME_TEXT MN_INSERT_MACRO[] = "マクロ定義を挿入";
3891 static GAME_TEXT MN_INSERT_KEYMAP[] = "キーマップ定義を挿入";
3893 static GAME_TEXT MN_COMMAND_LETTER[] = "拾い/破壊/放置の選択";
3894 static GAME_TEXT MN_CL_AUTOPICK[] = "「 」 (自動拾い)";
3895 static GAME_TEXT MN_CL_DESTROY[] = "「!」 (自動破壊)";
3896 static GAME_TEXT MN_CL_LEAVE[] = "「~」 (放置)";
3897 static GAME_TEXT MN_CL_QUERY[] = "「;」 (確認して拾う)";
3898 static GAME_TEXT MN_CL_NO_DISP[] = "「(」 (マップコマンドで表示しない)";
3900 static GAME_TEXT MN_ADJECTIVE_GEN[] = "形容詞(一般)の選択";
3901 static GAME_TEXT MN_RARE[] = "レアな (装備)";
3902 static GAME_TEXT MN_COMMON[] = "ありふれた (装備)";
3904 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "形容詞(特殊)の選択";
3905 static GAME_TEXT MN_BOOSTED[] = "ダイス目の違う (武器)";
3906 static GAME_TEXT MN_MORE_DICE[] = "ダイス目 # 以上の (武器)";
3907 static GAME_TEXT MN_MORE_BONUS[] = "修正値 # 以上の (指輪等)";
3908 static GAME_TEXT MN_WANTED[] = "賞金首の (死体)";
3909 static GAME_TEXT MN_UNIQUE[] = "ユニーク・モンスターの (死体)";
3910 static GAME_TEXT MN_HUMAN[] = "人間の (死体)";
3911 static GAME_TEXT MN_UNREADABLE[] = "読めない (魔法書)";
3912 static GAME_TEXT MN_REALM1[] = "第一領域の (魔法書)";
3913 static GAME_TEXT MN_REALM2[] = "第二領域の (魔法書)";
3914 static GAME_TEXT MN_FIRST[] = "1冊目の (魔法書)";
3915 static GAME_TEXT MN_SECOND[] = "2冊目の (魔法書)";
3916 static GAME_TEXT MN_THIRD[] = "3冊目の (魔法書)";
3917 static GAME_TEXT MN_FOURTH[] = "4冊目の (魔法書)";
3919 static GAME_TEXT MN_NOUN[] = "名詞の選択";
3923 static GAME_TEXT MN_QUIT[] = "Quit without save";
3924 static GAME_TEXT MN_SAVEQUIT[] = "Save & Quit";
3925 static GAME_TEXT MN_REVERT[] = "Revert all changes";
3926 static GAME_TEXT MN_HELP[] = "Help";
3928 static GAME_TEXT MN_MOVE[] = "Move cursor";
3929 static GAME_TEXT MN_LEFT[] = "Left (Left Arrow key)";
3930 static GAME_TEXT MN_DOWN[] = "Down (Down Arrow key)";
3931 static GAME_TEXT MN_UP[] = "Up (Up Arrow key)";
3932 static GAME_TEXT MN_RIGHT[] = "Right (Right Arrow key)";
3933 static GAME_TEXT MN_BOL[] = "Beggining of line";
3934 static GAME_TEXT MN_EOL[] = "End of line";
3935 static GAME_TEXT MN_PGUP[] = "Page up (PageUp key)";
3936 static GAME_TEXT MN_PGDOWN[] = "Page down(PageDown key)";
3937 static GAME_TEXT MN_TOP[] = "Top (Home key)";
3938 static GAME_TEXT MN_BOTTOM[] = "Bottom (End key)";
3940 static GAME_TEXT MN_EDIT[] = "Edit";
3941 static GAME_TEXT MN_CUT[] = "Cut";
3942 static GAME_TEXT MN_COPY[] = "Copy";
3943 static GAME_TEXT MN_PASTE[] = "Paste";
3944 static GAME_TEXT MN_BLOCK[] = "Select block";
3945 static GAME_TEXT MN_KILL_LINE[] = "Kill rest of line";
3946 static GAME_TEXT MN_DELETE_CHAR[] = "Delete character";
3947 static GAME_TEXT MN_BACKSPACE[] = "Backspace";
3948 static GAME_TEXT MN_RETURN[] = "Return";
3950 static GAME_TEXT MN_SEARCH[] = "Search";
3951 static GAME_TEXT MN_SEARCH_STR[] = "Search by string";
3952 static GAME_TEXT MN_SEARCH_FORW[] = "Search forward";
3953 static GAME_TEXT MN_SEARCH_BACK[] = "Search backward";
3954 static GAME_TEXT MN_SEARCH_OBJ[] = "Search by inventory object";
3955 static GAME_TEXT MN_SEARCH_DESTROYED[] = "Search by destroyed object";
3957 static GAME_TEXT MN_INSERT[] = "Insert...";
3958 static GAME_TEXT MN_INSERT_OBJECT[] = "Insert name of choosen object";
3959 static GAME_TEXT MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
3960 static GAME_TEXT MN_INSERT_BLOCK[] = "Insert conditional block";
3961 static GAME_TEXT MN_INSERT_MACRO[] = "Insert a macro definition";
3962 static GAME_TEXT MN_INSERT_KEYMAP[] = "Insert a keymap definition";
3964 static GAME_TEXT MN_COMMAND_LETTER[] = "Command letter";
3965 static GAME_TEXT MN_CL_AUTOPICK[] = "' ' (Auto pick)";
3966 static GAME_TEXT MN_CL_DESTROY[] = "'!' (Auto destroy)";
3967 static GAME_TEXT MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
3968 static GAME_TEXT MN_CL_QUERY[] = "';' (Query to pick up)";
3969 static GAME_TEXT MN_CL_NO_DISP[] = "'(' (No display on the large map)";
3971 static GAME_TEXT MN_ADJECTIVE_GEN[] = "Adjective (general)";
3972 static GAME_TEXT MN_RARE[] = "rare (equipments)";
3973 static GAME_TEXT MN_COMMON[] = "common (equipments)";
3975 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
3976 static GAME_TEXT MN_BOOSTED[] = "dice boosted (weapons)";
3977 static GAME_TEXT MN_MORE_DICE[] = "more than # dice (weapons)";
3978 static GAME_TEXT MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
3979 static GAME_TEXT MN_WANTED[] = "wanted (corpse)";
3980 static GAME_TEXT MN_UNIQUE[] = "unique (corpse)";
3981 static GAME_TEXT MN_HUMAN[] = "human (corpse)";
3982 static GAME_TEXT MN_UNREADABLE[] = "unreadable (spellbooks)";
3983 static GAME_TEXT MN_REALM1[] = "realm1 (spellbooks)";
3984 static GAME_TEXT MN_REALM2[] = "realm2 (spellbooks)";
3985 static GAME_TEXT MN_FIRST[] = "first (spellbooks)";
3986 static GAME_TEXT MN_SECOND[] = "second (spellbooks)";
3987 static GAME_TEXT MN_THIRD[] = "third (spellbooks)";
3988 static GAME_TEXT MN_FOURTH[] = "fourth (spellbooks)";
3990 static GAME_TEXT MN_NOUN[] = "Keywords (noun)";
4000 } command_menu_type;
4003 command_menu_type menu_data[] =
4005 {MN_HELP, 0, -1, EC_HELP},
4006 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4007 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4008 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4010 {MN_EDIT, 0, -1, -1},
4011 {MN_CUT, 1, KTRL('x'), EC_CUT},
4012 {MN_COPY, 1, KTRL('c'), EC_COPY},
4013 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4014 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4015 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4016 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4017 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4018 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4019 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4021 {MN_SEARCH, 0, -1, -1},
4022 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4023 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4024 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4025 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4026 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4028 {MN_MOVE, 0, -1, -1},
4029 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4030 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4031 {MN_UP, 1, KTRL('p'), EC_UP},
4032 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4033 {MN_BOL, 1, KTRL('a'), EC_BOL},
4034 {MN_EOL, 1, KTRL('e'), EC_EOL},
4035 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4036 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4037 {MN_TOP, 1, KTRL('t'), EC_TOP},
4038 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4040 {MN_INSERT, 0, -1, -1},
4041 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4042 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4043 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4044 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4045 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4047 {MN_ADJECTIVE_GEN, 0, -1, -1},
4048 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4049 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4050 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4051 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4052 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4053 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4054 {KEY_EGO, 1, -1, EC_OK_EGO},
4055 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4056 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4057 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4058 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4059 {MN_RARE, 1, -1, EC_OK_RARE},
4060 {MN_COMMON, 1, -1, EC_OK_COMMON},
4062 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4063 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4064 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4065 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4066 {MN_WANTED, 1, -1, EC_OK_WANTED},
4067 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4068 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4069 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4070 {MN_REALM1, 1, -1, EC_OK_REALM1},
4071 {MN_REALM2, 1, -1, EC_OK_REALM2},
4072 {MN_FIRST, 1, -1, EC_OK_FIRST},
4073 {MN_SECOND, 1, -1, EC_OK_SECOND},
4074 {MN_THIRD, 1, -1, EC_OK_THIRD},
4075 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4077 {MN_NOUN, 0, -1, -1},
4078 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4079 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4080 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4081 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4082 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4083 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4084 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4085 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4086 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4087 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4088 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4089 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4090 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4091 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4092 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4093 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4094 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4095 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4097 {MN_COMMAND_LETTER, 0, -1, -1},
4098 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4099 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4100 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4101 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4102 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4104 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4111 * Find a command by 'key'.
4113 static int get_com_id(char key)
4117 for (i = 0; menu_data[i].name; i++)
4119 if (menu_data[i].key == key)
4121 return menu_data[i].com_id;
4130 * Display the menu, and get a command
4132 static int do_command_menu(int level, int start)
4137 int col0 = 5 + level*7;
4138 int row0 = 1 + level*3;
4140 int menu_id_list[26];
4142 char linestr[MAX_LINELEN];
4144 /* Get max length */
4146 for (i = start; menu_data[i].level >= level; i++)
4150 /* Ignore lower level sub menus */
4151 if (menu_data[i].level > level) continue;
4153 len = strlen(menu_data[i].name);
4154 if (len > max_len) max_len = len;
4156 menu_id_list[menu_key] = i;
4160 while (menu_key < 26)
4162 menu_id_list[menu_key] = -1;
4166 /* Extra space for displaying menu key and command key */
4167 max_menu_wid = max_len + 3 + 3;
4169 /* Prepare box line */
4171 strcat(linestr, "+");
4172 for (i = 0; i < max_menu_wid + 2; i++)
4174 strcat(linestr, "-");
4176 strcat(linestr, "+");
4186 int row1 = row0 + 1;
4189 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4191 /* Draw menu items */
4193 for (i = start; menu_data[i].level >= level; i++)
4195 char com_key_str[3];
4198 /* Ignore lower level sub menus */
4199 if (menu_data[i].level > level) continue;
4201 if (menu_data[i].com_id == -1)
4203 strcpy(com_key_str, _("▼", ">"));
4205 else if (menu_data[i].key != -1)
4207 com_key_str[0] = '^';
4208 com_key_str[1] = menu_data[i].key + '@';
4209 com_key_str[2] = '\0';
4213 com_key_str[0] = '\0';
4216 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4218 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4223 /* Draw bottom line */
4224 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4226 /* The menu was shown */
4229 prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
4232 if (key == ESCAPE) return 0;
4234 if ('a' <= key && key <= 'z')
4236 menu_id = menu_id_list[key - 'a'];
4240 com_id = menu_data[menu_id].com_id;
4244 com_id = do_command_menu(level + 1, menu_id + 1);
4246 if (com_id) return com_id;
4258 com_id = get_com_id(key);
4259 if (com_id) return com_id;
4266 static chain_str_type *new_chain_str(concptr str)
4268 chain_str_type *chain;
4270 size_t len = strlen(str);
4272 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4274 strcpy(chain->s, str);
4281 static void kill_yank_chain(text_body_type *tb)
4283 chain_str_type *chain = tb->yank;
4285 tb->yank_eol = TRUE;
4289 chain_str_type *next = chain->next;
4290 size_t len = strlen(chain->s);
4292 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4299 static void add_str_to_yank(text_body_type *tb, concptr str)
4301 chain_str_type *chain;
4303 tb->yank_eol = FALSE;
4305 if (NULL == tb->yank)
4307 tb->yank = new_chain_str(str);
4317 chain->next = new_chain_str(str);
4322 chain = chain->next;
4328 * Do work for the copy editor-command
4330 static void copy_text_to_yank(text_body_type *tb)
4332 int len = strlen(tb->lines_list[tb->cy]);
4334 /* Correct cursor location */
4335 if (tb->cx > len) tb->cx = len;
4337 /* Use single line? */
4340 /* Select a single line */
4346 /* Kill old yank buffer */
4347 kill_yank_chain(tb);
4350 /* Single line case */
4351 if (tb->my == tb->cy)
4354 char buf[MAX_LINELEN];
4355 int bx1 = MIN(tb->mx, tb->cx);
4356 int bx2 = MAX(tb->mx, tb->cx);
4358 /* Correct fake cursor position */
4359 if (bx2 > len) bx2 = len;
4361 /* Whole part of this line is selected */
4362 if (bx1 == 0 && bx2 == len)
4364 /* Copy this line */
4365 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4367 /* Add end of line to the buffer */
4368 add_str_to_yank(tb, "");
4371 /* Segment of this line is selected */
4374 for (i = 0; i < bx2 - bx1; i++)
4376 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4380 /* Copy this segment of line */
4381 add_str_to_yank(tb, buf);
4385 /* Multiple lines case */
4386 else /* if (tb->my != tb->cy) */
4390 int by1 = MIN(tb->my, tb->cy);
4391 int by2 = MAX(tb->my, tb->cy);
4394 for (y = by1; y <= by2; y++)
4396 /* Copy this line */
4397 add_str_to_yank(tb, tb->lines_list[y]);
4400 /* Add final end of line to the buffer */
4401 add_str_to_yank(tb, "");
4404 /* Disable selection */
4408 tb->dirty_flags |= DIRTY_ALL;
4412 #define DESCRIPT_HGT 3
4417 static void draw_text_editor(text_body_type *tb)
4420 int by1 = 0, by2 = 0;
4422 Term_get_size(&tb->wid, &tb->hgt);
4425 * Top line (-1), description line (-3), separator (-1)
4428 tb->hgt -= 2 + DESCRIPT_HGT;
4431 /* Don't let cursor at second byte of kanji */
4432 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4433 if (iskanji(tb->lines_list[tb->cy][i]))
4439 * Move to a correct position in the
4442 if (i & 1) tb->cx--;
4449 /* Scroll if necessary */
4450 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4451 tb->upper = tb->cy - (tb->hgt)/2;
4454 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4455 tb->left = tb->cx - (tb->wid)*2/3;
4459 /* Redraw whole window after resize */
4460 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4461 tb->dirty_flags |= DIRTY_SCREEN;
4463 /* Redraw all text after scroll */
4464 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4465 tb->dirty_flags |= DIRTY_ALL;
4468 if (tb->dirty_flags & DIRTY_SCREEN)
4470 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4474 /* Redraw mode line */
4475 if (tb->dirty_flags & DIRTY_MODE)
4477 char buf[MAX_LINELEN];
4479 int sepa_length = tb->wid;
4482 for (i = 0; i < sepa_length; i++)
4486 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4489 if (tb->dirty_flags & DIRTY_EXPRESSION)
4494 for (y = 0; tb->lines_list[y]; y++)
4498 concptr s = tb->lines_list[y];
4502 /* Update this line's state */
4503 tb->states[y] = state;
4505 if (*s++ != '?') continue;
4506 if (*s++ != ':') continue;
4508 /* Lines below this line are auto-registered */
4509 if (streq(s, "$AUTOREGISTER"))
4510 state |= LSTAT_AUTOREGISTER;
4513 ss = (char *)string_make(s);
4516 /* Parse the expr */
4517 v = process_pref_file_expr(&ss, &f);
4520 if (streq(v, "0")) state |= LSTAT_BYPASS;
4521 else state &= ~LSTAT_BYPASS;
4523 /* Cannot use string_free() because the string was "destroyed" */
4524 C_KILL(s_keep, s_len + 1, char);
4526 /* Re-update this line's state */
4527 tb->states[y] = state | LSTAT_EXPRESSION;
4530 tb->dirty_flags |= DIRTY_ALL;
4535 tb->dirty_flags |= DIRTY_ALL;
4537 by1 = MIN(tb->my, tb->cy);
4538 by2 = MAX(tb->my, tb->cy);
4541 /* Dump up to tb->hgt lines of messages */
4542 for (i = 0; i < tb->hgt; i++)
4548 int y = tb->upper+i;
4550 /* clean or dirty? */
4551 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4554 msg = tb->lines_list[y];
4557 /* Apply horizontal scroll */
4558 for (j = 0; *msg; msg++, j++)
4560 if (j == tb->left) break;
4576 Term_erase(0, i + 1, tb->wid);
4578 if (tb->states[y] & LSTAT_AUTOREGISTER)
4580 /* Warning color -- These lines will be deleted later */
4585 /* Bypassed line will be displayed by darker color */
4586 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4587 else color = TERM_WHITE;
4590 /* No mark or Out of mark */
4591 if (!tb->mark || (y < by1 || by2 < y))
4593 /* Dump the messages, bottom to top */
4594 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4597 /* Multiple lines selected */
4598 else if (by1 != by2)
4600 /* Dump the messages, bottom to top */
4601 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4604 /* Single line selected */
4607 int x0 = leftcol + tb->left;
4608 int len = strlen(tb->lines_list[tb->cy]);
4609 int bx1 = MIN(tb->mx, tb->cx);
4610 int bx2 = MAX(tb->mx, tb->cx);
4612 /* Correct cursor location */
4613 if (bx2 > len) bx2 = len;
4615 Term_gotoxy(leftcol, i + 1);
4616 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4617 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4618 Term_addstr(-1, color, msg + (bx2 - x0));
4622 for (; i < tb->hgt; i++)
4625 Term_erase(0, i + 1, tb->wid);
4628 /* Display information when updated */
4629 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4631 autopick_type an_entry, *entry = &an_entry;
4632 concptr str1 = NULL, str2 = NULL;
4635 /* Clear information line */
4636 for (i = 0; i < DESCRIPT_HGT; i++)
4639 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4642 /* Display information */
4643 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4645 str1 = format(_("パターンが見つかりません: %s", "Pattern not found: %s"), tb->search_str);
4647 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4649 str1 = format(_("無効状態の行をスキップしました。(%sを検索中)",
4650 "Some inactive lines are skipped. (Searching %s)"), tb->search_str);
4652 else if (tb->dirty_flags & DIRTY_INACTIVE)
4654 str1 = format(_("無効状態の行だけが見付かりました。(%sを検索中)",
4655 "Found only an inactive line. (Searching %s)"), tb->search_str);
4657 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4659 str1 = _("検索するパターンがありません(^S で検索)。", "No pattern to search. (Press ^S to search.)");
4661 else if (tb->lines_list[tb->cy][0] == '#')
4663 str1 = _("この行はコメントです。", "This line is a comment.");
4665 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4667 switch(tb->lines_list[tb->cy][0])
4670 str1 = _("この行は条件分岐式です。", "This line is a Conditional Expression.");
4673 str1 = _("この行はマクロの実行内容を定義します。", "This line defines a Macro action.");
4676 str1 = _("この行はマクロのトリガー・キーを定義します。", "This line defines a Macro trigger key.");
4679 str1 = _("この行はキー配置を定義します。", "This line defines a Keymap.");
4683 switch(tb->lines_list[tb->cy][0])
4686 if (tb->states[tb->cy] & LSTAT_BYPASS)
4688 str2 = _("現在の式の値は「偽(=0)」です。", "The expression is 'False'(=0) currently.");
4692 str2 = _("現在の式の値は「真(=1)」です。", "The expression is 'True'(=1) currently.");
4697 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4699 str2 = _("この行は後で削除されます。", "This line will be delete later.");
4702 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4704 str2 = _("この行は現在は無効な状態です。", "This line is bypassed currently.");
4710 /* Get description of an autopicker preference line */
4711 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4713 char buf[MAX_LINELEN];
4714 char temp[MAX_LINELEN];
4717 describe_autopick(buf, entry);
4719 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4721 strcat(buf, _("この行は後で削除されます。", " This line will be delete later."));
4724 if (tb->states[tb->cy] & LSTAT_BYPASS)
4726 strcat(buf, _("この行は現在は無効な状態です。", " This line is bypassed currently."));
4729 roff_to_buf(buf, 81, temp, sizeof(temp));
4731 for (i = 0; i < 3; i++)
4737 prt(t, tb->hgt +1 + 1 + i, 0);
4741 autopick_free_entry(entry);
4744 /* Draw the first line */
4745 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4747 /* Draw the second line */
4748 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4754 * Kill segment of a line
4756 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4758 char buf[MAX_LINELEN];
4759 concptr s = tb->lines_list[y];
4763 /* Kill whole line? */
4764 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4768 string_free(tb->lines_list[y]);
4770 /* Shift lines up */
4771 for (i = y; tb->lines_list[i+1]; i++)
4772 tb->lines_list[i] = tb->lines_list[i+1];
4773 tb->lines_list[i] = NULL;
4775 /* Expressions need re-evaluation */
4776 tb->dirty_flags |= DIRTY_EXPRESSION;
4782 if (x0 == x1) return;
4784 /* Before the segment */
4785 for (x = 0; x < x0; x++)
4788 /* After the segment */
4789 for (x = x1; s[x]; x++)
4795 string_free(tb->lines_list[y]);
4796 tb->lines_list[y] = string_make(buf);
4798 /* Expressions may need re-evaluation */
4799 check_expression_line(tb, y);
4801 /* Text is changed */
4807 * Get a trigger key and insert ASCII string for the trigger
4809 static bool insert_macro_line(text_body_type *tb)
4818 /* Do not process macros */
4824 /* Read the pattern */
4830 /* Do not process macros */
4833 /* Do not wait for keys */
4836 /* Attempt to read a key */
4845 /* Convert the trigger */
4846 ascii_to_text(tmp, buf);
4849 if(!tmp[0]) return FALSE;
4853 /* Insert preference string */
4854 insert_return_code(tb);
4855 string_free(tb->lines_list[tb->cy]);
4856 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4858 /* Acquire action */
4859 i = macro_find_exact(buf);
4863 /* Nothing defined */
4868 /* Analyze the current action */
4869 ascii_to_text(tmp, macro__act[i]);
4872 /* Insert blank action preference line */
4873 insert_return_code(tb);
4874 string_free(tb->lines_list[tb->cy]);
4875 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4882 * Get a command key and insert ASCII string for the key
4884 static bool insert_keymap_line(text_body_type *tb)
4892 if (rogue_like_commands)
4894 mode = KEYMAP_MODE_ROGUE;
4900 mode = KEYMAP_MODE_ORIG;
4911 /* Convert the trigger */
4912 ascii_to_text(tmp, buf);
4915 if(!tmp[0]) return FALSE;
4919 /* Insert preference string */
4920 insert_return_code(tb);
4921 string_free(tb->lines_list[tb->cy]);
4922 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4924 /* Look up the keymap */
4925 act = keymap_act[mode][(byte)(buf[0])];
4929 /* Analyze the current action */
4930 ascii_to_text(tmp, act);
4934 /* No keymap defined -- Use trigger key itself as a default */
4936 /* Nothing to do (use tmp) */
4939 /* Insert blank action preference line */
4940 insert_return_code(tb);
4941 string_free(tb->lines_list[tb->cy]);
4942 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4949 * Execute a single editor command
4951 static bool do_editor_command(text_body_type *tb, int com_id)
4958 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
4959 "Discard all changes and quit. Are you sure? "))) break;
4961 return QUIT_WITHOUT_SAVE;
4964 return QUIT_AND_SAVE;
4967 /* Revert to original */
4968 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
4969 "Discard all changes and revert to original file. Are you sure? "))) break;
4971 free_text_lines(tb->lines_list);
4972 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4973 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4974 tb->cx = tb->cy = 0;
4977 /* Text is not changed */
4978 tb->changed = FALSE;
4982 /* Peruse the main help file */
4983 (void)show_file(TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
4985 tb->dirty_flags |= DIRTY_SCREEN;
4990 /* Split a line or insert end of line */
4992 /* Ignore selection */
4998 tb->dirty_flags |= DIRTY_ALL;
5001 insert_return_code(tb);
5006 tb->dirty_flags |= DIRTY_ALL;
5019 len = strlen(tb->lines_list[tb->cy]);
5020 if (len < tb->cx) tb->cx = len;
5023 /* Don't let cursor at second byte of kanji */
5024 for (i = 0; tb->lines_list[tb->cy][i]; i++)
5026 if (iskanji(tb->lines_list[tb->cy][i]))
5031 /* Move to the left */
5039 else if (tb->cy > 0)
5042 tb->cx = strlen(tb->lines_list[tb->cy]);
5049 /* Is this the last line? */
5050 if (!tb->lines_list[tb->cy + 1])
5052 /* Add one more empty line if possible */
5053 if (!add_empty_line(tb)) break;
5063 if (tb->cy > 0) tb->cy--;
5072 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5075 len = strlen(tb->lines_list[tb->cy]);
5078 /* Correct the cursor position */
5081 /* Is this the last line? */
5082 if (!tb->lines_list[tb->cy + 1])
5084 /* Add one more empty line if possible */
5085 if (!add_empty_line(tb)) break;
5088 /* Move to the beginning of next line */
5096 /* Beginning of line */
5102 tb->cx = strlen(tb->lines_list[tb->cy]);
5106 while (0 < tb->cy && tb->upper <= tb->cy)
5108 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5114 while (tb->cy < tb->upper + tb->hgt)
5116 /* Is this the last line? */
5117 if (!tb->lines_list[tb->cy + 1])
5119 /* Add one more empty line if possible */
5120 if (!add_empty_line(tb)) break;
5136 /* Is this the last line? */
5137 if (!tb->lines_list[tb->cy + 1])
5139 /* Add one more empty line if possible */
5140 if (!add_empty_line(tb)) break;
5146 /* Always at the biginning of the last line */
5153 /* Copy the text first */
5154 copy_text_to_yank(tb);
5156 /* Single line case */
5157 if (tb->my == tb->cy)
5159 int bx1 = MIN(tb->mx, tb->cx);
5160 int bx2 = MAX(tb->mx, tb->cx);
5161 int len = strlen(tb->lines_list[tb->cy]);
5163 /* Correct fake cursor position */
5164 if (bx2 > len) bx2 = len;
5166 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5168 /* New cursor position */
5172 /* Multiple lines case */
5173 else /* if (tb->my != tb->cy) */
5177 int by1 = MIN(tb->my, tb->cy);
5178 int by2 = MAX(tb->my, tb->cy);
5180 /* Kill lines in reverse order */
5181 for (y = by2; y >= by1; y--)
5183 int len = strlen(tb->lines_list[y]);
5185 kill_line_segment(tb, y, 0, len, TRUE);
5188 /* New cursor position */
5194 /* Disable selection */
5198 tb->dirty_flags |= DIRTY_ALL;
5200 /* Text is changed */
5207 copy_text_to_yank(tb);
5210 * Move cursor position to the end of the selection
5212 * Pressing ^C ^V correctly duplicates the selection.
5214 if (tb->my == tb->cy)
5216 tb->cx = MAX(tb->cx, tb->mx);
5219 * When whole line is selected, the end of
5220 * line code is also copyed.
5222 if (!tb->lines_list[tb->cy][tb->cx])
5224 /* Is this the last line? */
5225 if (!tb->lines_list[tb->cy + 1])
5227 /* Add one more empty line if possible */
5228 if (!add_empty_line(tb)) break;
5231 /* Go to the beginning of next line */
5238 tb->cy = MAX(tb->cy, tb->my);
5240 /* Is this the last line? */
5241 if (!tb->lines_list[tb->cy + 1])
5243 /* Add one more empty line if possible */
5244 if (!add_empty_line(tb)) break;
5255 /* Paste killed text */
5257 chain_str_type *chain = tb->yank;
5258 int len = strlen(tb->lines_list[tb->cy]);
5260 /* Nothing to do? */
5263 /* Correct cursor location */
5264 if (tb->cx > len) tb->cx = len;
5266 /* Ignore selection */
5272 tb->dirty_flags |= DIRTY_ALL;
5278 concptr yank_str = chain->s;
5280 char buf[MAX_LINELEN];
5282 char rest[MAX_LINELEN], *rest_ptr = rest;
5284 /* Save preceding string */
5285 for(i = 0; i < tb->cx; i++)
5286 buf[i] = tb->lines_list[tb->cy][i];
5288 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5290 /* Paste yank buffer */
5291 while (*yank_str && i < MAX_LINELEN-1)
5293 buf[i++] = *yank_str++;
5299 chain = chain->next;
5301 if (chain || tb->yank_eol)
5303 /* There is an end of line between chain nodes */
5305 insert_return_code(tb);
5307 /* Replace this line with new one */
5308 string_free(tb->lines_list[tb->cy]);
5309 tb->lines_list[tb->cy] = string_make(buf);
5311 /* Move to next line */
5318 /* Final line doesn't have end of line */
5320 tb->cx = strlen(buf);
5322 /* Rest of original line */
5323 while (*rest_ptr && i < MAX_LINELEN-1)
5325 buf[i++] = *rest_ptr++;
5331 /* Replace this line with new one */
5332 string_free(tb->lines_list[tb->cy]);
5333 tb->lines_list[tb->cy] = string_make(buf);
5340 tb->dirty_flags |= DIRTY_ALL;
5342 /* Expressions need re-evaluation */
5343 tb->dirty_flags |= DIRTY_EXPRESSION;
5345 /* Text is changed */
5354 /* Disable the selection */
5358 tb->dirty_flags |= DIRTY_ALL;
5362 tb->mark = MARK_MARK;
5364 /* Repeating this command swaps cursor position */
5365 if (com_id == tb->old_com_id)
5377 tb->dirty_flags |= DIRTY_ALL;
5381 int len = strlen(tb->lines_list[tb->cy]);
5383 /* Mark the point 1 */
5387 /* Correct cursor location */
5388 if (tb->cx > len) tb->mx = len;
5395 /* Kill rest of line */
5397 int len = strlen(tb->lines_list[tb->cy]);
5399 /* Correct cursor location */
5400 if (tb->cx > len) tb->cx = len;
5402 /* Ignore selection */
5408 tb->dirty_flags |= DIRTY_ALL;
5411 /* Append only if this command is repeated. */
5412 if (tb->old_com_id != com_id)
5414 kill_yank_chain(tb);
5418 /* Really deleted some text */
5421 /* Add deleted string to yank buffer */
5422 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5424 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5427 tb->dirty_line = tb->cy;
5429 /* Leave end of line character */
5433 /* Cut the end of line character only */
5434 if (tb->yank_eol) add_str_to_yank(tb, "");
5436 /* Cut end of line */
5437 tb->yank_eol = TRUE;
5439 do_editor_command(tb, EC_DELETE_CHAR);
5443 case EC_DELETE_CHAR:
5445 /* DELETE == go forward + BACK SPACE */
5449 /* Ignore selection */
5455 tb->dirty_flags |= DIRTY_ALL;
5459 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5463 /* Pass through the end of line to next line */
5464 len = strlen(tb->lines_list[tb->cy]);
5467 if (tb->lines_list[tb->cy + 1])
5479 do_editor_command(tb, EC_BACKSPACE);
5488 char buf[MAX_LINELEN];
5490 /* Ignore selection */
5496 tb->dirty_flags |= DIRTY_ALL;
5499 /* Move to correct collumn */
5500 len = strlen(tb->lines_list[tb->cy]);
5501 if (len < tb->cx) tb->cx = len;
5505 /* delete a return code and union two lines */
5506 if (tb->cy == 0) break;
5507 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5508 strcpy(buf, tb->lines_list[tb->cy-1]);
5509 strcat(buf, tb->lines_list[tb->cy]);
5510 string_free(tb->lines_list[tb->cy-1]);
5511 string_free(tb->lines_list[tb->cy]);
5512 tb->lines_list[tb->cy-1] = string_make(buf);
5514 for (i = tb->cy; tb->lines_list[i+1]; i++)
5515 tb->lines_list[i] = tb->lines_list[i+1];
5517 tb->lines_list[i] = NULL;
5521 tb->dirty_flags |= DIRTY_ALL;
5523 /* Expressions need re-evaluation */
5524 tb->dirty_flags |= DIRTY_EXPRESSION;
5526 /* Text is changed */
5532 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5536 if (iskanji(tb->lines_list[tb->cy][i]))
5537 buf[j++] = tb->lines_list[tb->cy][i++];
5539 buf[j++] = tb->lines_list[tb->cy][i];
5546 for (; tb->lines_list[tb->cy][i]; i++)
5547 buf[j++] = tb->lines_list[tb->cy][i];
5549 string_free(tb->lines_list[tb->cy]);
5550 tb->lines_list[tb->cy] = string_make(buf);
5553 tb->dirty_line = tb->cy;
5555 /* Expressions may need re-evaluation */
5556 check_expression_line(tb, tb->cy);
5558 /* Text is changed */
5568 /* Become dirty because of item/equip menu */
5569 tb->dirty_flags |= DIRTY_SCREEN;
5571 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5573 if (!search_dir) break;
5575 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5576 else do_editor_command(tb, EC_SEARCH_BACK);
5580 case EC_SEARCH_FORW:
5581 if (tb->search_o_ptr)
5583 search_for_object(tb, tb->search_o_ptr, TRUE);
5585 else if (tb->search_str && tb->search_str[0])
5587 search_for_string(tb, tb->search_str, TRUE);
5591 tb->dirty_flags |= DIRTY_NO_SEARCH;
5595 case EC_SEARCH_BACK:
5596 if (tb->search_o_ptr)
5598 search_for_object(tb, tb->search_o_ptr, FALSE);
5600 else if (tb->search_str && tb->search_str[0])
5602 search_for_string(tb, tb->search_str, FALSE);
5606 tb->dirty_flags |= DIRTY_NO_SEARCH;
5611 /* Become dirty because of item/equip menu */
5612 tb->dirty_flags |= DIRTY_SCREEN;
5614 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5616 do_editor_command(tb, EC_SEARCH_FORW);
5619 case EC_SEARCH_DESTROYED:
5620 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5622 /* There is no object to search */
5623 tb->dirty_flags |= DIRTY_NO_SEARCH;
5628 do_editor_command(tb, EC_SEARCH_FORW);
5631 case EC_INSERT_OBJECT:
5633 /* Insert choosen item name */
5635 autopick_type an_entry, *entry = &an_entry;
5637 if (!entry_from_choosed_object(entry))
5639 /* Now dirty because of item/equip menu */
5640 tb->dirty_flags |= DIRTY_SCREEN;
5645 insert_return_code(tb);
5646 string_free(tb->lines_list[tb->cy]);
5647 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5649 /* Now dirty because of item/equip menu */
5650 tb->dirty_flags |= DIRTY_SCREEN;
5655 case EC_INSERT_DESTROYED:
5656 /* Insert a name of last destroyed item */
5657 if (tb->last_destroyed)
5660 insert_return_code(tb);
5661 string_free(tb->lines_list[tb->cy]);
5662 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5665 tb->dirty_flags |= DIRTY_ALL;
5667 /* Text is changed */
5672 case EC_INSERT_BLOCK:
5674 /* Insert a conditinal expression line */
5675 char expression[80];
5677 /* Conditional Expression for Class and Race */
5678 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5680 rp_ptr->E_title, cp_ptr->E_title,
5682 rp_ptr->title, cp_ptr->title,
5688 insert_return_code(tb);
5689 string_free(tb->lines_list[tb->cy]);
5690 tb->lines_list[tb->cy] = string_make(expression);
5692 insert_return_code(tb);
5693 string_free(tb->lines_list[tb->cy]);
5694 tb->lines_list[tb->cy] = string_make("?:1");
5697 tb->dirty_flags |= DIRTY_ALL;
5699 /* Text is changed */
5705 case EC_INSERT_MACRO:
5706 /* Draw_everythig (delete menu) */
5707 draw_text_editor(tb);
5710 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5713 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
5714 if (insert_macro_line(tb))
5716 /* Prepare to input action */
5720 tb->dirty_flags |= DIRTY_ALL;
5722 /* Text is changed */
5728 case EC_INSERT_KEYMAP:
5729 /* Draw_everythig (delete menu) */
5730 draw_text_editor(tb);
5733 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5736 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
5737 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5739 if (insert_keymap_line(tb))
5741 /* Prepare to input action */
5745 tb->dirty_flags |= DIRTY_ALL;
5747 /* Text is changed */
5752 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5753 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5754 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5755 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5756 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5758 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5759 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5760 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5761 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5762 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5763 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5764 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5765 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5766 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5767 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5768 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5769 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5770 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5771 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5772 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5773 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5774 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5775 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5776 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5777 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5778 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5779 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5780 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5781 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5782 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5783 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5784 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5785 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5786 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5787 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5788 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5789 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5790 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5791 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5792 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5793 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5794 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5795 case EC_OK_UNREADABLE:
5796 toggle_keyword(tb, FLG_UNREADABLE);
5797 add_keyword(tb, FLG_SPELLBOOKS);
5800 toggle_keyword(tb, FLG_REALM1);
5801 add_keyword(tb, FLG_SPELLBOOKS);
5804 toggle_keyword(tb, FLG_REALM2);
5805 add_keyword(tb, FLG_SPELLBOOKS);
5808 toggle_keyword(tb, FLG_FIRST);
5809 add_keyword(tb, FLG_SPELLBOOKS);
5812 toggle_keyword(tb, FLG_SECOND);
5813 add_keyword(tb, FLG_SPELLBOOKS);
5816 toggle_keyword(tb, FLG_THIRD);
5817 add_keyword(tb, FLG_SPELLBOOKS);
5820 toggle_keyword(tb, FLG_FOURTH);
5821 add_keyword(tb, FLG_SPELLBOOKS);
5825 /* Save old command */
5826 tb->old_com_id = com_id;
5833 * Insert single letter at cursor position.
5835 static void insert_single_letter(text_body_type *tb, int key)
5838 char buf[MAX_LINELEN];
5840 /* Save preceding string */
5841 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5842 buf[j++] = tb->lines_list[tb->cy][i];
5844 /* Add a character */
5852 if (j+2 < MAX_LINELEN)
5854 buf[j++] = (char)key;
5855 buf[j++] = (char)next;
5864 if (j+1 < MAX_LINELEN)
5865 buf[j++] = (char)key;
5870 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5871 buf[j++] = tb->lines_list[tb->cy][i];
5874 /* Replace current line with new line */
5875 string_free(tb->lines_list[tb->cy]);
5876 tb->lines_list[tb->cy] = string_make(buf);
5878 /* Move to correct collumn */
5879 len = strlen(tb->lines_list[tb->cy]);
5880 if (len < tb->cx) tb->cx = len;
5883 tb->dirty_line = tb->cy;
5885 /* Expressions may need re-evaluation */
5886 check_expression_line(tb, tb->cy);
5888 /* Text is changed */
5894 * Check special key code and get a movement command id
5896 static int analyze_move_key(text_body_type *tb, int skey)
5900 /* Not a special key */
5901 if (!(skey & SKEY_MASK)) return 0;
5903 /* Convert from a special key code to an editor command */
5904 switch(skey & ~SKEY_MOD_MASK)
5906 case SKEY_DOWN: com_id = EC_DOWN; break;
5907 case SKEY_LEFT: com_id = EC_LEFT; break;
5908 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5909 case SKEY_UP: com_id = EC_UP; break;
5910 case SKEY_PGUP: com_id = EC_PGUP; break;
5911 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5912 case SKEY_TOP: com_id = EC_TOP; break;
5913 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5916 /* Not a special movement key */
5920 /* Without shift modifier */
5921 if (!(skey & SKEY_MOD_SHIFT))
5924 * Un-shifted cursor keys cancells
5925 * selection created by shift+cursor.
5927 if (tb->mark & MARK_BY_SHIFT)
5932 tb->dirty_flags |= DIRTY_ALL;
5936 /* With shift modifier */
5939 /* Start selection by shift + cursor keys */
5942 int len = strlen(tb->lines_list[tb->cy]);
5944 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5948 /* Correct cursor location */
5949 if (tb->cx > len) tb->mx = len;
5951 /* Need to redraw text */
5952 if (com_id == EC_UP || com_id == EC_DOWN)
5954 /* Redraw all text */
5955 tb->dirty_flags |= DIRTY_ALL;
5959 tb->dirty_line = tb->cy;
5968 * In-game editor of Object Auto-picker/Destoryer
5970 void do_cmd_edit_autopick(void)
5972 static int cx_save = 0;
5973 static int cy_save = 0;
5975 text_body_type text_body, *tb = &text_body;
5977 autopick_type an_entry, *entry = &an_entry;
5978 char buf[MAX_LINELEN];
5983 static s32b old_autosave_turn = 0L;
5986 tb->changed = FALSE;
5989 tb->upper = tb->left = 0;
5991 tb->mx = tb->my = 0;
5992 tb->old_cy = tb->old_upper = tb->old_left = -1;
5993 tb->old_wid = tb->old_hgt = -1;
5997 tb->search_o_ptr = NULL;
5998 tb->search_str = NULL;
5999 tb->last_destroyed = NULL;
6000 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6001 tb->dirty_line = -1;
6002 tb->filename_mode = PT_DEFAULT;
6004 if (current_world_ptr->game_turn < old_autosave_turn)
6006 while (old_autosave_turn > current_world_ptr->game_turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
6010 if (current_world_ptr->game_turn > old_autosave_turn + 100L)
6012 do_cmd_save_game(TRUE);
6013 old_autosave_turn = current_world_ptr->game_turn;
6016 /* HACK -- Reset start_time to stop counting current_world_ptr->play_time while edit */
6019 /* Free old entries */
6022 /* Command Description of the 'Last Destroyed Item' */
6023 if (autopick_last_destroyed_object.k_idx)
6025 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6026 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6029 /* Read or initialize whole text */
6030 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6032 /* Reset cursor position if needed */
6033 for (i = 0; i < tb->cy; i++)
6035 if (!tb->lines_list[i])
6037 tb->cy = tb->cx = 0;
6043 /* Process requests until done */
6048 /* Draw_everythig */
6049 draw_text_editor(tb);
6051 /* Display header line */
6052 prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)",
6053 "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0);
6056 /* Display current position */
6057 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6061 /* Display current position and mark position */
6062 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6066 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6069 tb->dirty_flags = 0;
6070 tb->dirty_line = -1;
6072 /* Save old key and location */
6073 tb->old_cy = tb->cy;
6074 tb->old_upper = tb->upper;
6075 tb->old_left = tb->left;
6076 tb->old_wid = tb->wid;
6077 tb->old_hgt = tb->hgt;
6079 key = inkey_special(TRUE);
6082 if (key & SKEY_MASK)
6084 /* Get a movement command */
6085 com_id = analyze_move_key(tb, key);
6089 else if (key == ESCAPE)
6091 com_id = do_command_menu(0, 0);
6093 /* Redraw all text later */
6094 tb->dirty_flags |= DIRTY_SCREEN;
6097 /* Insert a character */
6098 else if (!iscntrl((unsigned char)key))
6100 /* Ignore selection */
6106 tb->dirty_flags |= DIRTY_ALL;
6109 insert_single_letter(tb, key);
6115 /* Other commands */
6118 com_id = get_com_id((char)key);
6121 if (com_id) quit = do_editor_command(tb, com_id);
6122 } /* while (TRUE) */
6125 /* Get the filename of preference */
6126 strcpy(buf, pickpref_filename(tb->filename_mode));
6128 if (quit == QUIT_AND_SAVE)
6129 write_text_lines(buf, tb->lines_list);
6131 free_text_lines(tb->lines_list);
6133 string_free(tb->search_str);
6134 string_free(tb->last_destroyed);
6136 /* Destroy string chain */
6137 kill_yank_chain(tb);
6139 /* Reload autopick pref */
6140 process_autopick_file(buf);
6142 /* HACK -- reset start_time so that current_world_ptr->play_time is not increase while edit */
6143 start_time = (u32b)time(NULL);
6145 /* Save cursor location */