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
16 #include "player-status.h"
18 #define MAX_LINELEN 1024
25 #define FLG_UNIDENTIFIED 2
26 #define FLG_IDENTIFIED 3
27 #define FLG_STAR_IDENTIFIED 4
28 #define FLG_COLLECTING 5
29 #define FLG_ARTIFACT 6
32 #define FLG_NAMELESS 11
33 #define FLG_AVERAGE 12
34 #define FLG_WORTHLESS 13
37 #define FLG_BOOSTED 16
38 #define FLG_MORE_DICE 17
39 #define FLG_MORE_BONUS 18
43 #define FLG_UNREADABLE 22
52 #define FLG_WEAPONS 31
53 #define FLG_FAVORITE_WEAPONS 32
55 #define FLG_MISSILES 34
56 #define FLG_DEVICES 35
59 #define FLG_CORPSES 38
60 #define FLG_SPELLBOOKS 39
62 #define FLG_SHIELDS 41
65 #define FLG_AMULETS 44
72 #define FLG_NOUN_BEGIN FLG_ITEMS
73 #define FLG_NOUN_END FLG_BOOTS
77 static GAME_TEXT KEY_ALL[] = "すべての";
78 static GAME_TEXT KEY_UNAWARE[] = "未判明の";
79 static GAME_TEXT KEY_UNIDENTIFIED[] = "未鑑定の";
80 static GAME_TEXT KEY_IDENTIFIED[] = "鑑定済みの";
81 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*鑑定*済みの";
82 static GAME_TEXT KEY_COLLECTING[] = "収集中の";
83 static GAME_TEXT KEY_ARTIFACT[] = "アーティファクト";
84 static GAME_TEXT KEY_EGO[] = "エゴ";
85 static GAME_TEXT KEY_GOOD[] = "上質の";
86 static GAME_TEXT KEY_NAMELESS[] = "無銘の";
87 static GAME_TEXT KEY_AVERAGE[] = "並の";
88 static GAME_TEXT KEY_WORTHLESS[] = "無価値の";
89 static GAME_TEXT KEY_RARE[] = "レアな";
90 static GAME_TEXT KEY_COMMON[] = "ありふれた";
91 static GAME_TEXT KEY_BOOSTED[] = "ダイス目の違う";
92 static GAME_TEXT KEY_MORE_THAN[] = "ダイス目";
93 static GAME_TEXT KEY_DICE[] = "以上の";
94 static GAME_TEXT KEY_MORE_BONUS[] = "修正値";
95 static GAME_TEXT KEY_MORE_BONUS2[] = "以上の";
96 static GAME_TEXT KEY_WANTED[] = "賞金首の";
97 static GAME_TEXT KEY_UNIQUE[] = "ユニーク・モンスターの";
98 static GAME_TEXT KEY_HUMAN[] = "人間の";
99 static GAME_TEXT KEY_UNREADABLE[] = "読めない";
100 static GAME_TEXT KEY_REALM1[] = "第一領域の";
101 static GAME_TEXT KEY_REALM2[] = "第二領域の";
102 static GAME_TEXT KEY_FIRST[] = "1冊目の";
103 static GAME_TEXT KEY_SECOND[] = "2冊目の";
104 static GAME_TEXT KEY_THIRD[] = "3冊目の";
105 static GAME_TEXT KEY_FOURTH[] = "4冊目の";
106 static GAME_TEXT KEY_ITEMS[] = "アイテム";
107 static GAME_TEXT KEY_WEAPONS[] = "武器";
108 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "得意武器";
109 static GAME_TEXT KEY_ARMORS[] = "防具";
110 static GAME_TEXT KEY_MISSILES[] = "矢";
111 static GAME_TEXT KEY_DEVICES[] = "魔法アイテム";
112 static GAME_TEXT KEY_LIGHTS[] = "光源";
113 static GAME_TEXT KEY_JUNKS[] = "がらくた";
114 static GAME_TEXT KEY_CORPSES[] = "死体や骨";
115 static GAME_TEXT KEY_SPELLBOOKS[] = "魔法書";
116 static GAME_TEXT KEY_HAFTED[] = "鈍器";
117 static GAME_TEXT KEY_SHIELDS[] = "盾";
118 static GAME_TEXT KEY_BOWS[] = "弓";
119 static GAME_TEXT KEY_RINGS[] = "指輪";
120 static GAME_TEXT KEY_AMULETS[] = "アミュレット";
121 static GAME_TEXT KEY_SUITS[] = "鎧";
122 static GAME_TEXT KEY_CLOAKS[] = "クローク";
123 static GAME_TEXT KEY_HELMS[] = "兜";
124 static GAME_TEXT KEY_GLOVES[] = "籠手";
125 static GAME_TEXT KEY_BOOTS[] = "靴";
129 static GAME_TEXT KEY_ALL[] = "all";
130 static GAME_TEXT KEY_UNAWARE[] = "unaware";
131 static GAME_TEXT KEY_UNIDENTIFIED[] = "unidentified";
132 static GAME_TEXT KEY_IDENTIFIED[] = "identified";
133 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*identified*";
134 static GAME_TEXT KEY_COLLECTING[] = "collecting";
135 static GAME_TEXT KEY_ARTIFACT[] = "artifact";
136 static GAME_TEXT KEY_EGO[] = "ego";
137 static GAME_TEXT KEY_GOOD[] = "good";
138 static GAME_TEXT KEY_nameLESS[] = "nameless";
139 static GAME_TEXT KEY_AVERAGE[] = "average";
140 static GAME_TEXT KEY_WORTHLESS[] = "worthless";
141 static GAME_TEXT KEY_RARE[] = "rare";
142 static GAME_TEXT KEY_COMMON[] = "common";
143 static GAME_TEXT KEY_BOOSTED[] = "dice boosted";
144 static GAME_TEXT KEY_MORE_THAN[] = "more than";
145 static GAME_TEXT KEY_DICE[] = " dice";
146 static GAME_TEXT KEY_MORE_BONUS[] = "more bonus than";
147 static GAME_TEXT KEY_MORE_BONUS2[] = "";
148 static GAME_TEXT KEY_WANTED[] = "wanted";
149 static GAME_TEXT KEY_UNIQUE[] = "unique monster's";
150 static GAME_TEXT KEY_HUMAN[] = "human";
151 static GAME_TEXT KEY_UNREADABLE[] = "unreadable";
152 static GAME_TEXT KEY_REALM1[] = "first realm's";
153 static GAME_TEXT KEY_REALM2[] = "second realm's";
154 static GAME_TEXT KEY_FIRST[] = "first";
155 static GAME_TEXT KEY_SECOND[] = "second";
156 static GAME_TEXT KEY_THIRD[] = "third";
157 static GAME_TEXT KEY_FOURTH[] = "fourth";
158 static GAME_TEXT KEY_ITEMS[] = "items";
159 static GAME_TEXT KEY_WEAPONS[] = "weapons";
160 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "favorite weapons";
161 static GAME_TEXT KEY_ARMORS[] = "armors";
162 static GAME_TEXT KEY_MISSILES[] = "missiles";
163 static GAME_TEXT KEY_DEVICES[] = "magical devices";
164 static GAME_TEXT KEY_LIGHTS[] = "lights";
165 static GAME_TEXT KEY_JUNKS[] = "junks";
166 static GAME_TEXT KEY_CORPSES[] = "corpses or skeletons";
167 static GAME_TEXT KEY_SPELLBOOKS[] = "spellbooks";
168 static GAME_TEXT KEY_HAFTED[] = "hafted weapons";
169 static GAME_TEXT KEY_SHIELDS[] = "shields";
170 static GAME_TEXT KEY_BOWS[] = "bows";
171 static GAME_TEXT KEY_RINGS[] = "rings";
172 static GAME_TEXT KEY_AMULETS[] = "amulets";
173 static GAME_TEXT KEY_SUITS[] = "suits";
174 static GAME_TEXT KEY_CLOAKS[] = "cloaks";
175 static GAME_TEXT KEY_HELMS[] = "helms";
176 static GAME_TEXT KEY_GLOVES[] = "gloves";
177 static GAME_TEXT KEY_BOOTS[] = "boots";
181 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
182 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
183 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
184 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
187 #define ADD_KEY(KEY) strcat(ptr, KEY)
189 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
191 #define ADD_KEY2(KEY) strcat(ptr, KEY)
193 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
194 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
195 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
196 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
199 static char kanji_colon[] = ":";
204 * A function to create new entry
206 static bool autopick_new_entry(autopick_type *entry, concptr str, bool allow_default)
211 char buf[MAX_LINELEN];
212 concptr prev_ptr, ptr, old_ptr;
215 if (str[0] && str[1] == ':') switch (str[0])
218 case 'A': case 'P': case 'C':
222 entry->flag[0] = entry->flag[1] = 0L;
226 act = DO_AUTOPICK | DO_DISPLAY;
229 if ((act & DO_AUTOPICK) && *str == '!')
232 act |= DO_AUTODESTROY;
235 else if ((act & DO_AUTOPICK) && *str == '~')
238 act |= DONT_AUTOPICK;
241 else if ((act & DO_AUTOPICK) && *str == ';')
244 act |= DO_QUERY_AUTOPICK;
247 else if ((act & DO_DISPLAY) && *str == '(')
256 /* don't mind upper or lower case */
258 for (i = 0; *str; i++)
269 /* Auto-inscription? */
277 if (isupper(c)) c = (char)tolower(c);
283 /* Skip empty line unless allow_default */
284 if (!allow_default && *buf == 0) return FALSE;
286 /* Skip comment line */
287 if (*buf == 0 && insc) return FALSE;
289 ptr = prev_ptr = buf;
292 while (old_ptr != ptr)
294 /* Save current location */
297 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
298 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
299 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
300 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
301 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
302 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
303 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
305 /*** Weapons whose dd*ds is more than nn ***/
306 if (MATCH_KEY2(KEY_MORE_THAN))
311 /* Drop leading spaces */
312 while (' ' == *ptr) ptr++;
315 while ('0' <= *ptr && *ptr <= '9')
317 entry->dice = 10 * entry->dice + (*ptr - '0');
324 (void)MATCH_KEY(KEY_DICE);
325 ADD_FLG(FLG_MORE_DICE);
331 /*** Items whose magical bonus is more than n ***/
332 if (MATCH_KEY2(KEY_MORE_BONUS))
337 /* Drop leading spaces */
338 while (' ' == *ptr) ptr++;
341 while ('0' <= *ptr && *ptr <= '9')
343 entry->bonus = 10 * entry->bonus + (*ptr - '0');
351 (void)MATCH_KEY(KEY_MORE_BONUS2);
353 if (' ' == *ptr) ptr++;
355 ADD_FLG(FLG_MORE_BONUS);
361 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
362 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
363 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
364 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
365 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
366 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
367 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
368 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
369 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
370 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
371 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
372 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
373 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
374 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
375 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
376 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
377 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
380 /* Not yet found any noun */
383 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
385 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
386 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
387 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
388 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
389 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
390 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
391 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
392 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
393 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
394 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
395 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
396 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
397 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
398 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
399 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
400 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
401 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
402 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
403 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
404 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
406 /* Last 'keyword' must be at the correct location */
410 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
413 else if (*ptr == '\0')
415 /* There was no noun */
418 /* Add extra word "items" */
419 ADD_FLG_NOUN(FLG_ITEMS);
426 /* A noun type keyword didn't end correctly */
427 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
432 /* Save this auto-picker entry line */
433 entry->name = string_make(ptr);
435 entry->insc = string_make(insc);
442 * Get auto-picker entry from o_ptr.
444 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
446 /* Assume that object name is to be added */
450 /* エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない */
451 bool bol_mark = FALSE;
453 /* We can always use the ^ mark in English */
454 bool bol_mark = TRUE;
457 GAME_TEXT name_str[MAX_NLEN];
459 /* Initialize name string */
462 entry->insc = string_make(quark_str(o_ptr->inscription));
463 entry->action = DO_AUTOPICK | DO_DISPLAY;
464 entry->flag[0] = entry->flag[1] = 0L;
468 if (!object_is_aware(o_ptr))
470 ADD_FLG(FLG_UNAWARE);
474 /* Not really identified */
475 else if (!object_is_known(o_ptr))
477 if (!(o_ptr->ident & IDENT_SENSE))
479 ADD_FLG(FLG_UNIDENTIFIED);
484 /* Pseudo-identified */
485 switch (o_ptr->feeling)
489 ADD_FLG(FLG_NAMELESS);
495 ADD_FLG(FLG_NAMELESS);
496 ADD_FLG(FLG_WORTHLESS);
502 ADD_FLG(FLG_WORTHLESS);
510 /* XXX No appropriate flag */
515 /* Never reach here */
525 if (object_is_ego(o_ptr))
527 if (object_is_weapon_armour_ammo(o_ptr))
530 * Base name of ego weapons and armors
531 * are almost meaningless.
532 * Register the ego type only.
534 ego_item_type *e_ptr = &e_info[o_ptr->name2];
536 /* エゴ銘には「^」マークが使える */
537 sprintf(name_str, "^%s", e_name + e_ptr->name);
539 /* We ommit the basename and cannot use the ^ mark */
540 strcpy(name_str, e_name + e_ptr->name);
543 /* Don't use the object description */
546 /* Restrict to 'common' equipments */
547 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
554 else if (object_is_artifact(o_ptr))
555 ADD_FLG(FLG_ARTIFACT);
557 /* Non-ego, non-artifact */
560 /* Wearable nameless object */
561 if (object_is_equipment(o_ptr))
562 ADD_FLG(FLG_NAMELESS);
569 /* Melee weapon with boosted dice */
570 if (object_is_melee_weapon(o_ptr))
572 object_kind *k_ptr = &k_info[o_ptr->k_idx];
574 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
575 ADD_FLG(FLG_BOOSTED);
578 /* Wanted monster's corpse */
579 if (object_is_shoukinkubi(o_ptr))
581 REM_FLG(FLG_WORTHLESS);
585 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
586 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
591 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
596 if (o_ptr->tval >= TV_LIFE_BOOK &&
597 !check_book_realm(o_ptr->tval, o_ptr->sval))
599 ADD_FLG(FLG_UNREADABLE);
600 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
603 if (REALM1_BOOK == o_ptr->tval &&
604 p_ptr->pclass != CLASS_SORCERER &&
605 p_ptr->pclass != CLASS_RED_MAGE)
611 if (REALM2_BOOK == o_ptr->tval &&
612 p_ptr->pclass != CLASS_SORCERER &&
613 p_ptr->pclass != CLASS_RED_MAGE)
619 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
621 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
623 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
625 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
628 if (object_is_ammo(o_ptr))
629 ADD_FLG(FLG_MISSILES);
630 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
631 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
632 ADD_FLG(FLG_DEVICES);
633 else if (o_ptr->tval == TV_LITE)
635 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
636 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
638 else if (o_ptr->tval == TV_CORPSE)
639 ADD_FLG(FLG_CORPSES);
640 else if (o_ptr->tval >= TV_LIFE_BOOK)
641 ADD_FLG(FLG_SPELLBOOKS);
642 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
643 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
644 ADD_FLG(FLG_WEAPONS);
645 else if (o_ptr->tval == TV_SHIELD)
646 ADD_FLG(FLG_SHIELDS);
647 else if (o_ptr->tval == TV_BOW)
649 else if (o_ptr->tval == TV_RING)
651 else if (o_ptr->tval == TV_AMULET)
652 ADD_FLG(FLG_AMULETS);
653 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
654 o_ptr->tval == TV_SOFT_ARMOR)
656 else if (o_ptr->tval == TV_CLOAK)
658 else if (o_ptr->tval == TV_HELM)
660 else if (o_ptr->tval == TV_GLOVES)
662 else if (o_ptr->tval == TV_BOOTS)
665 /* Prepare the object description */
668 GAME_TEXT o_name[MAX_NLEN];
670 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
673 * If necessary, add a '^' which indicates the
676 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
679 /* Register the name in lowercase */
680 str_tolower(name_str);
681 entry->name = string_make(name_str);
688 * A function to delete entry
690 static void autopick_free_entry(autopick_type *entry)
692 string_free(entry->name);
693 string_free(entry->insc);
699 #define MAX_AUTOPICK_DEFAULT 200
702 * Initialize the autopick
704 static void init_autopick(void)
706 static const char easy_autopick_inscription[] = "(:=g";
712 max_max_autopick = MAX_AUTOPICK_DEFAULT;
713 C_MAKE(autopick_list, max_max_autopick, autopick_type);
717 /* Clear old entries */
718 for( i = 0; i < max_autopick; i++)
719 autopick_free_entry(&autopick_list[i]);
723 /* There is always one entry "=g" */
724 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
725 autopick_list[max_autopick++] = entry;
730 #define PT_WITH_PNAME 1
733 * Get file name for autopick preference
735 static concptr pickpref_filename(int filename_mode)
737 static const char namebase[] = _("picktype", "pickpref");
739 switch (filename_mode)
742 return format("%s.prf", namebase);
745 return format("%s-%s.prf", namebase, player_base);
754 * Load an autopick preference file
756 void autopick_load_pref(bool disp_mes)
761 /* Free old entries */
764 /* Try a filename with player name */
765 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
768 err = process_autopick_file(buf);
770 if (err == 0 && disp_mes)
773 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
779 /* Use default name */
780 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
783 err = process_autopick_file(buf);
785 if (err == 0 && disp_mes)
788 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
795 msg_print(_("自動拾い設定ファイルの読み込みに失敗しました。", "Failed to reload autopick preference."));
801 * Add one line to autopick_list[]
803 static void add_autopick_list(autopick_type *entry)
805 /* There is no enough space to add one line */
806 if (max_autopick >= max_max_autopick)
808 int old_max_max_autopick = max_max_autopick;
809 autopick_type *old_autopick_list = autopick_list;
811 /* Increase size of list */
812 max_max_autopick += MAX_AUTOPICK_DEFAULT;
815 C_MAKE(autopick_list, max_max_autopick, autopick_type);
817 /* Copy from old list to new list */
818 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
821 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
825 autopick_list[max_autopick] = *entry;
832 * Process line for auto picker/destroyer.
834 errr process_autopick_file_command(char *buf)
836 autopick_type an_entry, *entry = &an_entry;
839 /* Nuke illegal char */
840 for(i = 0; buf[i]; i++)
849 if (iswspace(buf[i]) && buf[i] != ' ')
854 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
856 /* Already has the same entry? */
857 for(i = 0; i < max_autopick; i++)
858 if(!strcmp(entry->name, autopick_list[i].name)
859 && entry->flag[0] == autopick_list[i].flag[0]
860 && entry->flag[1] == autopick_list[i].flag[1]
861 && entry->dice == autopick_list[i].dice
862 && entry->bonus == autopick_list[i].bonus)
864 autopick_free_entry(entry);
868 add_autopick_list(entry);
874 * Reconstruct preference line from entry
876 concptr autopick_line_from_entry(autopick_type *entry)
878 char buf[MAX_LINELEN];
880 bool sepa_flag = TRUE;
883 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
884 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
885 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
886 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
890 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
891 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
892 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
893 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
894 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
895 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
896 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
898 if (IS_FLG(FLG_MORE_DICE))
900 ADD_KEY(KEY_MORE_THAN);
901 strcat(ptr, format("%d", entry->dice));
905 if (IS_FLG(FLG_MORE_BONUS))
907 ADD_KEY(KEY_MORE_BONUS);
908 strcat(ptr, format("%d", entry->bonus));
909 ADD_KEY(KEY_MORE_BONUS2);
912 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
913 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
914 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
915 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
916 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
917 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
918 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
919 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
920 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
921 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
922 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
923 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
924 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
925 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
926 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
927 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
928 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
930 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
932 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
933 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
934 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
935 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
936 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
937 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
938 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
939 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
940 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
941 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
942 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
943 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
944 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
945 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
946 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
947 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
948 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
949 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
950 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
951 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
953 /* You don't need sepalator after adjective */
954 /* 'artifact' is not true adjective */
955 else if (!IS_FLG(FLG_ARTIFACT))
958 if (entry->name && entry->name[0])
962 if (sepa_flag) strcat(buf, ":");
965 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
968 if (iskanji(entry->name[j]))
969 buf[i++] = entry->name[j++];
971 buf[i++] = entry->name[j++];
982 while (entry->insc[j] && i < MAX_LINELEN - 2)
985 if (iskanji(entry->insc[j]))
986 buf[i++] = entry->insc[j++];
988 buf[i++] = entry->insc[j++];
993 return string_make(buf);
998 * Reconstruct preference line from entry and kill entry
1000 static concptr autopick_line_from_entry_kill(autopick_type *entry)
1002 concptr ptr = autopick_line_from_entry(entry);
1004 /* Free memory for original entry */
1005 autopick_free_entry(entry);
1012 * A function for Auto-picker/destroyer
1013 * Examine whether the object matches to the entry
1015 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_name)
1018 concptr ptr = entry->name;
1020 /*** Unaware items ***/
1021 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1024 /*** Unidentified ***/
1025 if (IS_FLG(FLG_UNIDENTIFIED)
1026 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1029 /*** Identified ***/
1030 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1033 /*** *Identified* ***/
1034 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1035 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1038 /*** Dice boosted (weapon of slaying) ***/
1039 if (IS_FLG(FLG_BOOSTED))
1041 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1043 /* Require melee weapon */
1044 if (!object_is_melee_weapon(o_ptr))
1047 /* Require boosted dice */
1048 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1051 /* In Vault Quest, Dice must be hide.*/
1052 if(!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
1058 /*** Weapons which dd*ds is more than nn ***/
1059 if (IS_FLG(FLG_MORE_DICE))
1061 if (o_ptr->dd * o_ptr->ds < entry->dice)
1065 /*** Weapons whic dd*ds is more than nn ***/
1066 if (IS_FLG(FLG_MORE_BONUS))
1068 if (!object_is_known(o_ptr)) return FALSE;
1072 if (o_ptr->pval < entry->bonus) return FALSE;
1076 if (o_ptr->to_h < entry->bonus &&
1077 o_ptr->to_d < entry->bonus &&
1078 o_ptr->to_a < entry->bonus &&
1079 o_ptr->pval < entry->bonus)
1084 /*** Worthless items ***/
1085 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1088 /*** Artifact object ***/
1089 if (IS_FLG(FLG_ARTIFACT))
1091 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1095 /*** Ego object ***/
1096 if (IS_FLG(FLG_EGO))
1098 /* Need to be an ego item */
1099 if (!object_is_ego(o_ptr)) return FALSE;
1101 /* Need to be known to be an ego */
1102 if (!object_is_known(o_ptr) &&
1103 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1108 if (IS_FLG(FLG_GOOD))
1110 if (!object_is_equipment(o_ptr)) return FALSE;
1113 if (object_is_known(o_ptr))
1115 /* Artifacts and Ego objects are not okay */
1116 if (!object_is_nameless(o_ptr))
1119 /* Average are not okay */
1120 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1124 /* Pseudo-identified */
1125 else if (o_ptr->ident & IDENT_SENSE)
1127 switch (o_ptr->feeling)
1142 /* Not known to be good */
1148 if (IS_FLG(FLG_NAMELESS))
1150 if (!object_is_equipment(o_ptr)) return FALSE;
1153 if (object_is_known(o_ptr))
1155 /* Artifacts and Ego objects are not okay */
1156 if (!object_is_nameless(o_ptr))
1160 /* Pseudo-identified */
1161 else if (o_ptr->ident & IDENT_SENSE)
1163 switch (o_ptr->feeling)
1173 /* It's not nameless */
1181 /* Not known to be nameless */
1187 if (IS_FLG(FLG_AVERAGE))
1189 if (!object_is_equipment(o_ptr)) return FALSE;
1192 if (object_is_known(o_ptr))
1194 /* Artifacts and Ego objects are not okay */
1195 if (!object_is_nameless(o_ptr))
1198 /* Cursed or broken objects are not okay */
1199 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1202 /* Good are not okay */
1203 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1207 /* Pseudo-identified */
1208 else if (o_ptr->ident & IDENT_SENSE)
1210 switch (o_ptr->feeling)
1217 /* It's not average */
1225 /* Not known to be average */
1230 /*** Rere equipments ***/
1231 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1234 /*** Common equipments ***/
1235 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1238 /*** Wanted monster's corpse/skeletons ***/
1239 if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
1242 /*** Unique monster's corpse/skeletons/statues ***/
1243 if (IS_FLG(FLG_UNIQUE) &&
1244 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1245 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1248 /*** Human corpse/skeletons (for Daemon magic) ***/
1249 if (IS_FLG(FLG_HUMAN) &&
1250 (o_ptr->tval != TV_CORPSE ||
1251 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1254 /*** Unreadable spellbooks ***/
1255 if (IS_FLG(FLG_UNREADABLE) &&
1256 (o_ptr->tval < TV_LIFE_BOOK ||
1257 check_book_realm(o_ptr->tval, o_ptr->sval)))
1260 /*** First realm spellbooks ***/
1261 if (IS_FLG(FLG_REALM1) &&
1262 (REALM1_BOOK != o_ptr->tval ||
1263 p_ptr->pclass == CLASS_SORCERER ||
1264 p_ptr->pclass == CLASS_RED_MAGE))
1267 /*** Second realm spellbooks ***/
1268 if (IS_FLG(FLG_REALM2) &&
1269 (REALM2_BOOK != o_ptr->tval ||
1270 p_ptr->pclass == CLASS_SORCERER ||
1271 p_ptr->pclass == CLASS_RED_MAGE))
1274 /*** First rank spellbooks ***/
1275 if (IS_FLG(FLG_FIRST) &&
1276 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1279 /*** Second rank spellbooks ***/
1280 if (IS_FLG(FLG_SECOND) &&
1281 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1284 /*** Third rank spellbooks ***/
1285 if (IS_FLG(FLG_THIRD) &&
1286 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1289 /*** Fourth rank spellbooks ***/
1290 if (IS_FLG(FLG_FOURTH) &&
1291 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1295 if (IS_FLG(FLG_WEAPONS))
1297 if (!object_is_weapon(o_ptr))
1300 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1302 if (!object_is_favorite(o_ptr))
1305 else if (IS_FLG(FLG_ARMORS))
1307 if (!object_is_armour(o_ptr))
1310 else if (IS_FLG(FLG_MISSILES))
1312 if (!object_is_ammo(o_ptr)) return FALSE;
1314 else if (IS_FLG(FLG_DEVICES))
1318 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1320 default: return FALSE;
1323 else if (IS_FLG(FLG_LIGHTS))
1325 if (!(o_ptr->tval == TV_LITE))
1328 else if (IS_FLG(FLG_JUNKS))
1332 case TV_SKELETON: case TV_BOTTLE:
1333 case TV_JUNK: case TV_STATUE:
1335 default: return FALSE;
1338 else if (IS_FLG(FLG_CORPSES))
1340 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1343 else if (IS_FLG(FLG_SPELLBOOKS))
1345 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1348 else if (IS_FLG(FLG_HAFTED))
1350 if (!(o_ptr->tval == TV_HAFTED))
1353 else if (IS_FLG(FLG_SHIELDS))
1355 if (!(o_ptr->tval == TV_SHIELD))
1358 else if (IS_FLG(FLG_BOWS))
1360 if (!(o_ptr->tval == TV_BOW))
1363 else if (IS_FLG(FLG_RINGS))
1365 if (!(o_ptr->tval == TV_RING))
1368 else if (IS_FLG(FLG_AMULETS))
1370 if (!(o_ptr->tval == TV_AMULET))
1373 else if (IS_FLG(FLG_SUITS))
1375 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1376 o_ptr->tval == TV_HARD_ARMOR ||
1377 o_ptr->tval == TV_SOFT_ARMOR))
1380 else if (IS_FLG(FLG_CLOAKS))
1382 if (!(o_ptr->tval == TV_CLOAK))
1385 else if (IS_FLG(FLG_HELMS))
1387 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1390 else if (IS_FLG(FLG_GLOVES))
1392 if (!(o_ptr->tval == TV_GLOVES))
1395 else if (IS_FLG(FLG_BOOTS))
1397 if (!(o_ptr->tval == TV_BOOTS))
1401 /* Keyword don't match */
1405 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1409 if (!my_strstr(o_name, ptr)) return FALSE;
1412 /* TRUE when it need not to be 'collecting' */
1413 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1415 /* Check if there is a same item */
1416 for (j = 0; j < INVEN_PACK; j++)
1419 * 'Collecting' means the item must be absorbed
1420 * into an inventory slot.
1421 * But an item can not be absorbed into itself!
1423 if ((&inventory[j] != o_ptr) &&
1424 object_similar(&inventory[j], o_ptr))
1428 /* Not collecting */
1434 * A function for Auto-picker/destroyer
1435 * Examine whether the object matches to the list of keywords or not.
1437 int is_autopick(object_type *o_ptr)
1440 GAME_TEXT o_name[MAX_NLEN];
1442 if (o_ptr->tval == TV_GOLD) return -1;
1444 /* Prepare object name string first */
1445 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1447 /* Convert the string to lower case */
1448 str_tolower(o_name);
1450 /* Look for a matching entry in the list */
1451 for (i=0; i < max_autopick; i++)
1453 autopick_type *entry = &autopick_list[i];
1455 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1458 /* No matching entry */
1466 static void auto_inscribe_item(object_type *o_ptr, int idx)
1468 /* Are there auto-inscription? */
1469 if (idx < 0 || !autopick_list[idx].insc) return;
1471 if (!o_ptr->inscription)
1472 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1474 /* Redraw inscription */
1475 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1477 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1478 p_ptr->update |= (PU_BONUS);
1483 * Automatically destroy items in this grid.
1485 static bool is_opt_confirm_destroy(object_type *o_ptr)
1487 if (!destroy_items) return FALSE;
1489 /* Known to be worthless? */
1491 if (object_value(o_ptr) > 0) return FALSE;
1494 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1497 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1501 if (object_is_shoukinkubi(o_ptr)) return FALSE;
1505 if (o_ptr->tval == TV_CORPSE) return FALSE;
1508 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1512 if (p_ptr->prace == RACE_DEMON)
1514 if (o_ptr->tval == TV_CORPSE &&
1515 o_ptr->sval == SV_CORPSE &&
1516 my_strchr("pht", r_info[o_ptr->pval].d_char))
1520 if (p_ptr->pclass == CLASS_ARCHER)
1522 if (o_ptr->tval == TV_SKELETON ||
1523 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1526 else if (p_ptr->pclass == CLASS_NINJA)
1528 if (o_ptr->tval == TV_LITE &&
1529 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1532 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1533 p_ptr->pclass == CLASS_CAVALRY)
1535 if (o_ptr->tval == TV_WAND &&
1536 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1541 if (o_ptr->tval == TV_GOLD) return FALSE;
1548 * Automatically destroy an item if it is to be destroyed
1550 * When always_pickup is 'yes', we disable auto-destroyer function of
1551 * auto-picker/destroyer, and do only easy-auto-destroyer.
1553 static object_type autopick_last_destroyed_object;
1555 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1557 bool destroy = FALSE;
1559 /* Easy-Auto-Destroyer (3rd priority) */
1560 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1562 /* Protected by auto-picker (2nd priotity) */
1563 if (autopick_idx >= 0 &&
1564 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1567 /* Auto-destroyer works only when !always_pickup */
1570 /* Auto-picker/destroyer (1st priority) */
1571 if (autopick_idx >= 0 &&
1572 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1576 /* Not to be destroyed */
1577 if (!destroy) return;
1579 /* Now decided to destroy */
1581 disturb(FALSE, FALSE);
1584 if (!can_player_destroy_object(o_ptr))
1586 GAME_TEXT o_name[MAX_NLEN];
1588 /* Describe the object (with {terrible/special}) */
1589 object_desc(o_name, o_ptr, 0);
1591 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1596 /* Record name of destroyed item */
1597 (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1600 o_ptr->marked |= OM_AUTODESTROY;
1601 p_ptr->update |= PU_AUTODESTROY;
1608 * Auto-destroy marked item
1610 static void autopick_delayed_alter_aux(INVENTORY_IDX item)
1614 /* Get the item (in the pack) */
1615 if (item >= 0) o_ptr = &inventory[item];
1617 /* Get the item (on the floor) */
1618 else o_ptr = &o_list[0 - item];
1620 if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
1622 GAME_TEXT o_name[MAX_NLEN];
1624 /* Describe the object (with {terrible/special}) */
1625 object_desc(o_name, o_ptr, 0);
1627 /* Eliminate the item (from the pack) */
1630 inven_item_increase(item, -(o_ptr->number));
1631 inven_item_optimize(item);
1634 /* Eliminate the item (from the floor) */
1637 delete_object_idx(0 - item);
1640 msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name);
1646 * Auto-destroy marked items in inventry and on floor
1648 void autopick_delayed_alter(void)
1653 * Scan inventry in reverse order to prevent
1654 * skipping after inven_item_optimize()
1656 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1657 autopick_delayed_alter_aux(item);
1659 /* Scan the pile of objects */
1660 item = cave[p_ptr->y][p_ptr->x].o_idx;
1663 OBJECT_IDX next = o_list[item].next_o_idx;
1664 autopick_delayed_alter_aux(-item);
1671 * Auto-inscription and/or destroy
1673 * Auto-destroyer works only on inventory or on floor stack only when
1676 void autopick_alter_item(INVENTORY_IDX item, bool destroy)
1681 /* Get the item (in the pack) */
1682 if (item >= 0) o_ptr = &inventory[item];
1684 /* Get the item (on the floor) */
1685 else o_ptr = &o_list[0 - item];
1687 /* Get the index in the auto-pick/destroy list */
1688 idx = is_autopick(o_ptr);
1690 /* Do auto-inscription */
1691 auto_inscribe_item(o_ptr, idx);
1693 /* Do auto-destroy if needed */
1694 if (destroy && item <= INVEN_PACK)
1695 auto_destroy_item(o_ptr, idx);
1700 * Automatically pickup/destroy items in this grid.
1702 void autopick_pickup_items(cave_type *c_ptr)
1704 OBJECT_IDX this_o_idx, next_o_idx = 0;
1706 /* Scan the pile of objects */
1707 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1710 object_type *o_ptr = &o_list[this_o_idx];
1712 /* Acquire next object */
1713 next_o_idx = o_ptr->next_o_idx;
1715 idx = is_autopick(o_ptr);
1717 /* Item index for floor -1,-2,-3,... */
1718 auto_inscribe_item(o_ptr, idx);
1721 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1723 disturb(FALSE, FALSE);
1725 if (!inven_carry_okay(o_ptr))
1727 GAME_TEXT o_name[MAX_NLEN];
1729 object_desc(o_name, o_ptr, 0);
1731 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
1732 /* Hack - remember that the item has given a message here. */
1733 o_ptr->marked |= OM_NOMSG;
1737 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1739 char out_val[MAX_NLEN+20];
1740 GAME_TEXT o_name[MAX_NLEN];
1742 if (o_ptr->marked & OM_NO_QUERY)
1744 /* Already answered as 'No' */
1748 object_desc(o_name, o_ptr, 0);
1750 sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
1752 if (!get_check(out_val))
1754 /* Hack - remember that the item has given a message here. */
1755 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1760 py_pickup_aux(this_o_idx);
1765 * When always_pickup is 'yes', we disable
1766 * auto-destroyer from autopick function, and do only
1767 * easy-auto-destroyer.
1771 auto_destroy_item(o_ptr, idx);
1777 static const char autoregister_header[] = "?:$AUTOREGISTER";
1780 * Clear auto registered lines in the picktype.prf .
1782 static bool clear_auto_register(void)
1784 char tmp_file[1024];
1785 char pref_file[1024];
1790 bool autoregister = FALSE;
1793 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1794 pref_fff = my_fopen(pref_file, "r");
1798 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1799 pref_fff = my_fopen(pref_file, "r");
1808 /* Open a new (temporary) file */
1809 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1813 /* Close the preference file */
1815 msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
1821 /* Loop for every line */
1825 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1829 /* Delete auto-registered line */
1831 /* Count auto-destroy preference lines */
1832 if (buf[0] != '#' && buf[0] != '?') num++;
1835 /* We are looking for auto-registered line */
1838 if (streq(buf, autoregister_header))
1840 /* Delete all further lines */
1841 autoregister = TRUE;
1845 /* Copy orginally lines */
1846 fprintf(tmp_fff, "%s\n", buf);
1852 my_fclose(pref_fff);
1857 msg_format(_("以前のキャラクター用の自動設定(%d行)が残っています。",
1858 "Auto registered lines (%d lines) for previous character are remaining."), num);
1859 strcpy(buf, _("古い設定行は削除します。よろしいですか?", "These lines will be deleted. Are you sure? "));
1861 /* You can cancel it */
1862 if (!get_check(buf))
1865 autoregister = FALSE;
1867 msg_print(_("エディタのカット&ペースト等を使って必要な行を避難してください。",
1868 "Use cut & paste of auto picker editor (_) to keep old prefs."));
1873 /* If there are some changes, overwrite the original file with new one */
1876 /* Copy contents of temporary file */
1878 tmp_fff = my_fopen(tmp_file, "r");
1879 pref_fff = my_fopen(pref_file, "w");
1881 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1882 fprintf(pref_fff, "%s\n", buf);
1884 my_fclose(pref_fff);
1888 /* Kill the temporary file */
1896 * Automatically register an auto-destroy preference line
1898 bool autopick_autoregister(object_type *o_ptr)
1901 char pref_file[1024];
1903 autopick_type an_entry, *entry = &an_entry;
1905 int match_autopick = is_autopick(o_ptr);
1907 /* Already registered */
1908 if (match_autopick != -1)
1911 byte act = autopick_list[match_autopick].action;
1913 if (act & DO_AUTOPICK) what = _("自動で拾う", "auto-pickup");
1914 else if (act & DO_AUTODESTROY) what = _("自動破壊する", "auto-destroy");
1915 else if (act & DONT_AUTOPICK) what = _("放置する", "leave on floor");
1916 else /* if (act & DO_QUERY_AUTOPICK) */ what = _("確認して拾う", "query auto-pickup");
1918 msg_format(_("そのアイテムは既に%sように設定されています。", "The object is already registered to %s."), what);
1922 /* Known to be an artifact? */
1923 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1924 ((o_ptr->ident & IDENT_SENSE) &&
1925 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1927 GAME_TEXT o_name[MAX_NLEN];
1929 /* Describe the object (with {terrible/special}) */
1930 object_desc(o_name, o_ptr, 0);
1932 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1938 if (!p_ptr->autopick_autoregister)
1940 /* Clear old auto registered lines */
1941 if (!clear_auto_register()) return FALSE;
1944 /* Try a filename with player name */
1945 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1946 pref_fff = my_fopen(pref_file, "r");
1950 /* Use default name */
1951 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1952 pref_fff = my_fopen(pref_file, "r");
1955 /* Check the header */
1959 if (my_fgets(pref_fff, buf, sizeof(buf)))
1961 /* No header found */
1962 p_ptr->autopick_autoregister = FALSE;
1967 if (streq(buf, autoregister_header))
1969 /* Found the header */
1970 p_ptr->autopick_autoregister = TRUE;
1976 /* Close read only FILE* */
1979 /* Open for append */
1980 pref_fff = my_fopen(pref_file, "a");
1984 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), pref_file);
1991 if (!p_ptr->autopick_autoregister)
1993 /* Add the header */
1994 fprintf(pref_fff, "%s\n", autoregister_header);
1996 fprintf(pref_fff, "%s\n", _("# *警告!!* 以降の行は自動登録されたものです。",
1997 "# *Waring!* The lines below will be deleated later."));
1998 fprintf(pref_fff, "%s\n", _("# 後で自動的に削除されますので、必要な行は上の方へ移動しておいてください。",
1999 "# Keep it by cut & paste if you need these lines for future characters."));
2001 /* Now auto register is in-use */
2002 p_ptr->autopick_autoregister = TRUE;
2005 /* Get a preference entry */
2006 autopick_entry_from_object(entry, o_ptr);
2008 /* Set to auto-destroy (with no-display) */
2009 entry->action = DO_AUTODESTROY;
2011 /* Load the new line as preference */
2012 add_autopick_list(entry);
2014 /* Add a line to the file */
2015 /* Don't kill "entry" */
2016 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2023 /******** Auto-picker/destroyer editor **********/
2025 #define MAX_YANK MAX_LINELEN
2026 #define MAX_LINES 3000
2028 #define MARK_MARK 0x01
2029 #define MARK_BY_SHIFT 0x02
2031 #define LSTAT_BYPASS 0x01
2032 #define LSTAT_EXPRESSION 0x02
2033 #define LSTAT_AUTOREGISTER 0x04
2035 #define QUIT_WITHOUT_SAVE 1
2036 #define QUIT_AND_SAVE 2
2039 * Struct for yank buffer
2041 typedef struct chain_str {
2042 struct chain_str *next;
2048 * Data struct for text editor
2054 int old_wid, old_hgt;
2056 int old_upper, old_left;
2060 object_type *search_o_ptr;
2062 concptr last_destroyed;
2064 chain_str_type *yank;
2067 concptr *lines_list;
2068 byte states[MAX_LINES];
2080 * Dirty flag for text editor
2082 #define DIRTY_ALL 0x0001
2083 #define DIRTY_MODE 0x0004
2084 #define DIRTY_SCREEN 0x0008
2085 #define DIRTY_NOT_FOUND 0x0010
2086 #define DIRTY_NO_SEARCH 0x0020
2087 #define DIRTY_EXPRESSION 0x0040
2088 #define DIRTY_SKIP_INACTIVE 0x0080
2089 #define DIRTY_INACTIVE 0x0100
2092 * Describe which kind of object is Auto-picked/destroyed
2094 static void describe_autopick(char *buff, autopick_type *entry)
2096 concptr str = entry->name;
2097 byte act = entry->action;
2098 concptr insc = entry->insc;
2104 concptr before_str[100], body_str;
2109 /*** Collecting items ***/
2110 /*** Which can be absorbed into a slot as a bundle ***/
2111 if (IS_FLG(FLG_COLLECTING))
2112 before_str[before_n++] = "収集中で既に持っているスロットにまとめられる";
2114 /*** Unaware items ***/
2115 if (IS_FLG(FLG_UNAWARE))
2116 before_str[before_n++] = "未鑑定でその効果も判明していない";
2118 /*** Unidentified ***/
2119 if (IS_FLG(FLG_UNIDENTIFIED))
2120 before_str[before_n++] = "未鑑定の";
2122 /*** Identified ***/
2123 if (IS_FLG(FLG_IDENTIFIED))
2124 before_str[before_n++] = "鑑定済みの";
2126 /*** *Identified* ***/
2127 if (IS_FLG(FLG_STAR_IDENTIFIED))
2128 before_str[before_n++] = "完全に鑑定済みの";
2130 /*** Dice boosted (weapon of slaying) ***/
2131 if (IS_FLG(FLG_BOOSTED))
2133 before_str[before_n++] = "ダメージダイスが通常より大きい";
2137 /*** Weapons whose dd*ds is more than nn ***/
2138 if (IS_FLG(FLG_MORE_DICE))
2140 static char more_than_desc_str[] = "___";
2141 before_str[before_n++] = "ダメージダイスの最大値が";
2144 sprintf(more_than_desc_str,"%d", entry->dice);
2145 before_str[before_n++] = more_than_desc_str;
2146 before_str[before_n++] = "以上の";
2149 /*** Items whose magical bonus is more than nn ***/
2150 if (IS_FLG(FLG_MORE_BONUS))
2152 static char more_bonus_desc_str[] = "___";
2153 before_str[before_n++] = "修正値が(+";
2155 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2156 before_str[before_n++] = more_bonus_desc_str;
2157 before_str[before_n++] = ")以上の";
2160 /*** Worthless items ***/
2161 if (IS_FLG(FLG_WORTHLESS))
2162 before_str[before_n++] = "店で無価値と判定される";
2165 if (IS_FLG(FLG_ARTIFACT))
2167 before_str[before_n++] = "アーティファクトの";
2172 if (IS_FLG(FLG_EGO))
2174 before_str[before_n++] = "エゴアイテムの";
2179 if (IS_FLG(FLG_GOOD))
2181 before_str[before_n++] = "上質の";
2186 if (IS_FLG(FLG_NAMELESS))
2188 before_str[before_n++] = "エゴでもアーティファクトでもない";
2193 if (IS_FLG(FLG_AVERAGE))
2195 before_str[before_n++] = "並の";
2199 /*** Rare equipments ***/
2200 if (IS_FLG(FLG_RARE))
2202 before_str[before_n++] = "ドラゴン装備やカオス・ブレード等を含む珍しい";
2206 /*** Common equipments ***/
2207 if (IS_FLG(FLG_COMMON))
2209 before_str[before_n++] = "ありふれた(ドラゴン装備やカオス・ブレード等の珍しい物ではない)";
2213 /*** Wanted monster's corpse/skeletons ***/
2214 if (IS_FLG(FLG_WANTED))
2216 before_str[before_n++] = "ハンター事務所で賞金首とされている";
2220 /*** Human corpse/skeletons (for Daemon magic) ***/
2221 if (IS_FLG(FLG_HUMAN))
2223 before_str[before_n++] = "悪魔魔法で使うための人間やヒューマノイドの";
2227 /*** Unique monster's corpse/skeletons/statues ***/
2228 if (IS_FLG(FLG_UNIQUE))
2230 before_str[before_n++] = "ユニークモンスターの";
2234 /*** Unreadable spellbooks ***/
2235 if (IS_FLG(FLG_UNREADABLE))
2237 before_str[before_n++] = "あなたが読めない領域の";
2241 /*** First realm spellbooks ***/
2242 if (IS_FLG(FLG_REALM1))
2244 before_str[before_n++] = "第一領域の";
2248 /*** Second realm spellbooks ***/
2249 if (IS_FLG(FLG_REALM2))
2251 before_str[before_n++] = "第二領域の";
2255 /*** First rank spellbooks ***/
2256 if (IS_FLG(FLG_FIRST))
2258 before_str[before_n++] = "全4冊の内の1冊目の";
2262 /*** Second rank spellbooks ***/
2263 if (IS_FLG(FLG_SECOND))
2265 before_str[before_n++] = "全4冊の内の2冊目の";
2269 /*** Third rank spellbooks ***/
2270 if (IS_FLG(FLG_THIRD))
2272 before_str[before_n++] = "全4冊の内の3冊目の";
2276 /*** Fourth rank spellbooks ***/
2277 if (IS_FLG(FLG_FOURTH))
2279 before_str[before_n++] = "全4冊の内の4冊目の";
2284 if (IS_FLG(FLG_ITEMS))
2285 ; /* Nothing to do */
2286 else if (IS_FLG(FLG_WEAPONS))
2288 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2290 else if (IS_FLG(FLG_ARMORS))
2292 else if (IS_FLG(FLG_MISSILES))
2293 body_str = "弾や矢やクロスボウの矢";
2294 else if (IS_FLG(FLG_DEVICES))
2295 body_str = "巻物や魔法棒や杖やロッド";
2296 else if (IS_FLG(FLG_LIGHTS))
2297 body_str = "光源用のアイテム";
2298 else if (IS_FLG(FLG_JUNKS))
2299 body_str = "折れた棒等のガラクタ";
2300 else if (IS_FLG(FLG_CORPSES))
2302 else if (IS_FLG(FLG_SPELLBOOKS))
2304 else if (IS_FLG(FLG_HAFTED))
2306 else if (IS_FLG(FLG_SHIELDS))
2308 else if (IS_FLG(FLG_BOWS))
2309 body_str = "スリングや弓やクロスボウ";
2310 else if (IS_FLG(FLG_RINGS))
2312 else if (IS_FLG(FLG_AMULETS))
2313 body_str = "アミュレット";
2314 else if (IS_FLG(FLG_SUITS))
2316 else if (IS_FLG(FLG_CLOAKS))
2318 else if (IS_FLG(FLG_HELMS))
2319 body_str = "ヘルメットや冠";
2320 else if (IS_FLG(FLG_GLOVES))
2322 else if (IS_FLG(FLG_BOOTS))
2327 strcat(buff, "全ての");
2328 else for (i = 0; i < before_n && before_str[i]; i++)
2329 strcat(buff, before_str[i]);
2331 strcat(buff, body_str);
2341 strcat(buff, "で、名前が「");
2342 strncat(buff, str, 80);
2344 strcat(buff, "」で始まるもの");
2346 strcat(buff, "」を含むもの");
2351 strncat(buff, format("に「%s」", insc), 80);
2353 if (my_strstr(insc, "%%all"))
2354 strcat(buff, "(%%allは全能力を表す英字の記号で置換)");
2355 else if (my_strstr(insc, "%all"))
2356 strcat(buff, "(%allは全能力を表す記号で置換)");
2357 else if (my_strstr(insc, "%%"))
2358 strcat(buff, "(%%は追加能力を表す英字の記号で置換)");
2359 else if (my_strstr(insc, "%"))
2360 strcat(buff, "(%は追加能力を表す記号で置換)");
2362 strcat(buff, "と刻んで");
2367 if (act & DONT_AUTOPICK)
2368 strcat(buff, "放置する。");
2369 else if (act & DO_AUTODESTROY)
2370 strcat(buff, "破壊する。");
2371 else if (act & DO_QUERY_AUTOPICK)
2372 strcat(buff, "確認の後に拾う。");
2374 strcat(buff, "拾う。");
2376 if (act & DO_DISPLAY)
2378 if (act & DONT_AUTOPICK)
2379 strcat(buff, "全体マップ('M')で'N'を押したときに表示する。");
2380 else if (act & DO_AUTODESTROY)
2381 strcat(buff, "全体マップ('M')で'K'を押したときに表示する。");
2383 strcat(buff, "全体マップ('M')で'M'を押したときに表示する。");
2386 strcat(buff, "全体マップには表示しない。");
2390 concptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2391 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2395 /*** Collecting items ***/
2396 /*** Which can be absorbed into a slot as a bundle ***/
2397 if (IS_FLG(FLG_COLLECTING))
2398 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2400 /*** Unaware items ***/
2401 if (IS_FLG(FLG_UNAWARE))
2403 before_str[before_n++] = "unidentified";
2404 whose_str[whose_n++] = "basic abilities are not known";
2407 /*** Unidentified ***/
2408 if (IS_FLG(FLG_UNIDENTIFIED))
2409 before_str[before_n++] = "unidentified";
2411 /*** Identified ***/
2412 if (IS_FLG(FLG_IDENTIFIED))
2413 before_str[before_n++] = "identified";
2415 /*** *Identified* ***/
2416 if (IS_FLG(FLG_STAR_IDENTIFIED))
2417 before_str[before_n++] = "fully identified";
2419 /*** Rare equipments ***/
2420 if (IS_FLG(FLG_RARE))
2422 before_str[before_n++] = "very rare";
2423 body_str = "equipments";
2424 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2427 /*** Common equipments ***/
2428 if (IS_FLG(FLG_COMMON))
2430 before_str[before_n++] = "relatively common";
2431 body_str = "equipments";
2432 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2435 /*** Worthless items ***/
2436 if (IS_FLG(FLG_WORTHLESS))
2438 before_str[before_n++] = "worthless";
2439 which_str[which_n++] = "can not be sold at stores";
2443 if (IS_FLG(FLG_ARTIFACT))
2445 before_str[before_n++] = "artifact";
2449 if (IS_FLG(FLG_EGO))
2451 before_str[before_n++] = "ego";
2455 if (IS_FLG(FLG_GOOD))
2457 body_str = "equipment";
2458 which_str[which_n++] = "have good quality";
2462 if (IS_FLG(FLG_NAMELESS))
2464 body_str = "equipment";
2465 which_str[which_n++] = "is neither ego-item nor artifact";
2469 if (IS_FLG(FLG_AVERAGE))
2471 body_str = "equipment";
2472 which_str[which_n++] = "have average quality";
2475 /*** Dice boosted (weapon of slaying) ***/
2476 if (IS_FLG(FLG_BOOSTED))
2478 body_str = "weapons";
2479 whose_str[whose_n++] = "damage dice is bigger than normal";
2482 /*** Weapons whose dd*ds is more than nn ***/
2483 if (IS_FLG(FLG_MORE_DICE))
2485 static char more_than_desc_str[] =
2486 "maximum damage from dice is bigger than __";
2487 body_str = "weapons";
2489 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2491 whose_str[whose_n++] = more_than_desc_str;
2494 /*** Items whose magical bonus is more than nn ***/
2495 if (IS_FLG(FLG_MORE_BONUS))
2497 static char more_bonus_desc_str[] =
2498 "magical bonus is bigger than (+__)";
2500 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2501 "%d)", entry->bonus);
2502 whose_str[whose_n++] = more_bonus_desc_str;
2505 /*** Wanted monster's corpse/skeletons ***/
2506 if (IS_FLG(FLG_WANTED))
2508 body_str = "corpse or skeletons";
2509 which_str[which_n++] = "is wanted at the Hunter's Office";
2512 /*** Human corpse/skeletons (for Daemon magic) ***/
2513 if (IS_FLG(FLG_HUMAN))
2515 before_str[before_n++] = "humanoid";
2516 body_str = "corpse or skeletons";
2517 which_str[which_n++] = "can be used for Daemon magic";
2520 /*** Unique monster's corpse/skeletons/statues ***/
2521 if (IS_FLG(FLG_UNIQUE))
2523 before_str[before_n++] = "unique monster's";
2524 body_str = "corpse or skeletons";
2527 /*** Unreadable spellbooks ***/
2528 if (IS_FLG(FLG_UNREADABLE))
2530 body_str = "spellbooks";
2531 after_str[after_n++] = "of different realms from yours";
2534 /*** First realm spellbooks ***/
2535 if (IS_FLG(FLG_REALM1))
2537 body_str = "spellbooks";
2538 after_str[after_n++] = "of your first realm";
2541 /*** Second realm spellbooks ***/
2542 if (IS_FLG(FLG_REALM2))
2544 body_str = "spellbooks";
2545 after_str[after_n++] = "of your second realm";
2548 /*** First rank spellbooks ***/
2549 if (IS_FLG(FLG_FIRST))
2551 before_str[before_n++] = "first one of four";
2552 body_str = "spellbooks";
2555 /*** Second rank spellbooks ***/
2556 if (IS_FLG(FLG_SECOND))
2558 before_str[before_n++] = "second one of four";
2559 body_str = "spellbooks";
2562 /*** Third rank spellbooks ***/
2563 if (IS_FLG(FLG_THIRD))
2565 before_str[before_n++] = "third one of four";
2566 body_str = "spellbooks";
2569 /*** Fourth rank spellbooks ***/
2570 if (IS_FLG(FLG_FOURTH))
2572 before_str[before_n++] = "fourth one of four";
2573 body_str = "spellbooks";
2577 if (IS_FLG(FLG_ITEMS))
2578 ; /* Nothing to do */
2579 else if (IS_FLG(FLG_WEAPONS))
2580 body_str = "weapons";
2581 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2582 body_str = "favorite weapons";
2583 else if (IS_FLG(FLG_ARMORS))
2584 body_str = "armors";
2585 else if (IS_FLG(FLG_MISSILES))
2586 body_str = "shots, arrows or crossbow bolts";
2587 else if (IS_FLG(FLG_DEVICES))
2588 body_str = "scrolls, wands, staves or rods";
2589 else if (IS_FLG(FLG_LIGHTS))
2590 body_str = "light sources";
2591 else if (IS_FLG(FLG_JUNKS))
2592 body_str = "junk such as broken sticks";
2593 else if (IS_FLG(FLG_CORPSES))
2594 body_str = "corpses or skeletons";
2595 else if (IS_FLG(FLG_SPELLBOOKS))
2596 body_str = "spellbooks";
2597 else if (IS_FLG(FLG_HAFTED))
2598 body_str = "hafted weapons";
2599 else if (IS_FLG(FLG_SHIELDS))
2600 body_str = "shields";
2601 else if (IS_FLG(FLG_BOWS))
2602 body_str = "slings, bows or crossbows";
2603 else if (IS_FLG(FLG_RINGS))
2605 else if (IS_FLG(FLG_AMULETS))
2606 body_str = "amulets";
2607 else if (IS_FLG(FLG_SUITS))
2608 body_str = "body armors";
2609 else if (IS_FLG(FLG_CLOAKS))
2610 body_str = "cloaks";
2611 else if (IS_FLG(FLG_HELMS))
2612 body_str = "helms or crowns";
2613 else if (IS_FLG(FLG_GLOVES))
2614 body_str = "gloves";
2615 else if (IS_FLG(FLG_BOOTS))
2618 /* Prepare a string for item name */
2625 whose_str[whose_n++] = "name is beginning with \"";
2628 which_str[which_n++] = "have \"";
2632 /* Describe action flag */
2633 if (act & DONT_AUTOPICK)
2634 strcpy(buff, "Leave on floor ");
2635 else if (act & DO_AUTODESTROY)
2636 strcpy(buff, "Destroy ");
2637 else if (act & DO_QUERY_AUTOPICK)
2638 strcpy(buff, "Ask to pick up ");
2640 strcpy(buff, "Pickup ");
2642 /* Auto-insctiption */
2645 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2647 if (my_strstr(insc, "%all"))
2648 strcat(buff, ", replacing %all with code string representing all abilities,");
2649 else if (my_strstr(insc, "%"))
2650 strcat(buff, ", replacing % with code string representing extra random abilities,");
2652 strcat(buff, " on ");
2657 strcat(buff, "all ");
2658 else for (i = 0; i < before_n && before_str[i]; i++)
2660 strcat(buff, before_str[i]);
2665 strcat(buff, body_str);
2668 for (i = 0; i < after_n && after_str[i]; i++)
2671 strcat(buff, after_str[i]);
2675 for (i = 0; i < whose_n && whose_str[i]; i++)
2678 strcat(buff, " whose ");
2680 strcat(buff, ", and ");
2682 strcat(buff, whose_str[i]);
2685 /* Item name ; whose name is beginning with "str" */
2692 /* whose ..., and which .... */
2693 if (whose_n && which_n)
2694 strcat(buff, ", and ");
2697 for (i = 0; i < which_n && which_str[i]; i++)
2700 strcat(buff, " which ");
2702 strcat(buff, ", and ");
2704 strcat(buff, which_str[i]);
2707 /* Item name ; which have "str" as part of its name */
2710 strncat(buff, str, 80);
2711 strcat(buff, "\" as part of its name");
2715 /* Describe whether it will be displayed on the full map or not */
2716 if (act & DO_DISPLAY)
2718 if (act & DONT_AUTOPICK)
2719 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2720 else if (act & DO_AUTODESTROY)
2721 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2723 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2726 strcat(buff, " Not displayed in the full map.");
2733 * Read whole lines of a file to memory
2735 static concptr *read_text_lines(concptr filename)
2737 concptr *lines_list = NULL;
2743 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2746 fff = my_fopen(buf, "r");
2750 /* Allocate list of pointers */
2751 C_MAKE(lines_list, MAX_LINES, concptr);
2754 while (0 == my_fgets(fff, buf, sizeof(buf)))
2756 lines_list[lines++] = string_make(buf);
2757 if (lines >= MAX_LINES - 1) break;
2760 lines_list[0] = string_make("");
2765 if (!fff) return NULL;
2771 * Copy the default autopick file to the user directory
2773 static void prepare_default_pickpref(void)
2775 const concptr messages[] = {
2776 _("あなたは「自動拾いエディタ」を初めて起動しました。", "You have activated the Auto-Picker Editor for the first time."),
2777 _("自動拾いのユーザー設定ファイルがまだ書かれていないので、", "Since user pref file for autopick is not yet created,"),
2778 _("基本的な自動拾い設定ファイルをlib/pref/picktype.prfからコピーします。", "the default setting is loaded from lib/pref/pickpref.prf ."),
2786 concptr filename = pickpref_filename(PT_DEFAULT);
2788 /* Display messages */
2789 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2794 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2795 user_fp = my_fopen(buf, "w");
2798 if (!user_fp) return;
2800 /* Write header messages for a notification */
2801 fprintf(user_fp, "#***\n");
2802 for (i = 0; messages[i]; i++)
2804 fprintf(user_fp, "#*** %s\n", messages[i]);
2806 fprintf(user_fp, "#***\n\n\n");
2809 /* Open the default file */
2810 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2811 pref_fp = my_fopen(buf, "r");
2820 /* Copy the contents of default file */
2821 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2822 fprintf(user_fp, "%s\n", buf);
2829 * Read an autopick prefence file to memory
2830 * Prepare default if no user file is found
2832 static concptr *read_pickpref_text_lines(int *filename_mode_p)
2835 concptr *lines_list;
2837 /* Try a filename with player name */
2838 *filename_mode_p = PT_WITH_PNAME;
2839 strcpy(buf, pickpref_filename(*filename_mode_p));
2840 lines_list = read_text_lines(buf);
2844 /* Use default name */
2845 *filename_mode_p = PT_DEFAULT;
2846 strcpy(buf, pickpref_filename(*filename_mode_p));
2847 lines_list = read_text_lines(buf);
2852 /* There is no preference file in the user directory */
2854 /* Copy the default autopick file to the user directory */
2855 prepare_default_pickpref();
2857 /* Use default name again */
2858 lines_list = read_text_lines(buf);
2863 /* Allocate list of pointers */
2864 C_MAKE(lines_list, MAX_LINES, concptr);
2865 lines_list[0] = string_make("");
2872 * Write whole lines of memory to a file.
2874 static bool write_text_lines(concptr filename, concptr *lines_list)
2881 /* Build the filename */
2882 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2885 fff = my_fopen(buf, "w");
2888 for (lines = 0; lines_list[lines]; lines++)
2889 my_fputs(fff, lines_list[lines], 1024);
2894 if (!fff) return FALSE;
2900 * Free memory of lines_list.
2902 static void free_text_lines(concptr *lines_list)
2906 for (lines = 0; lines_list[lines]; lines++)
2907 string_free(lines_list[lines]);
2909 /* free list of pointers */
2910 C_KILL(lines_list, MAX_LINES, concptr);
2915 * Delete or insert string
2917 static void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
2923 /* Some lines are selected */
2926 by1 = MIN(tb->my, tb->cy);
2927 by2 = MAX(tb->my, tb->cy);
2930 /* No mark -- Select current line */
2931 else /* if (!tb->mark) */
2937 /* Set/Reset flag of each line */
2938 for (y = by1; y <= by2; y++)
2940 autopick_type an_entry, *entry = &an_entry;
2942 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2944 string_free(tb->lines_list[y]);
2948 /* Add? or Remove? */
2949 if (!IS_FLG(flg)) add = TRUE;
2952 /* No more change */
2956 /* You can use only one noun flag */
2957 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2960 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2964 /* You can use only one identify state flag */
2965 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2968 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2972 /* You can use only one flag in artifact/ego/nameless */
2973 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
2976 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
2980 /* You can use only one flag in rare/common */
2981 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
2984 for (i = FLG_RARE; i <= FLG_COMMON; i++)
2988 if (add) ADD_FLG(flg);
2991 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2994 tb->dirty_flags |= DIRTY_ALL;
2996 /* Text is changed */
3003 * Change command letter
3005 static void toggle_command_letter(text_body_type *tb, byte flg)
3007 autopick_type an_entry, *entry = &an_entry;
3012 /* Some lines are selected */
3015 by1 = MIN(tb->my, tb->cy);
3016 by2 = MAX(tb->my, tb->cy);
3019 /* No mark -- Select current line */
3020 else /* if (!tb->mark) */
3026 /* Set/Reset flag of each line */
3027 for (y = by1; y <= by2; y++)
3031 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3033 string_free(tb->lines_list[y]);
3037 /* Add? or Remove? */
3038 if (!(entry->action & flg)) add = TRUE;
3041 /* No more change */
3045 /* Count number of letter (by negative number) */
3046 if (entry->action & DONT_AUTOPICK) wid--;
3047 else if (entry->action & DO_AUTODESTROY) wid--;
3048 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3049 if (!(entry->action & DO_DISPLAY)) wid--;
3051 /* Set/Reset the flag */
3052 if (flg != DO_DISPLAY)
3054 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3055 if (add) entry->action |= flg;
3056 else entry->action |= DO_AUTOPICK;
3060 entry->action &= ~(DO_DISPLAY);
3061 if (add) entry->action |= flg;
3064 /* Correct cursor location */
3067 if (entry->action & DONT_AUTOPICK) wid++;
3068 else if (entry->action & DO_AUTODESTROY) wid++;
3069 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3070 if (!(entry->action & DO_DISPLAY)) wid++;
3072 if (wid > 0) tb->cx++;
3073 if (wid < 0 && tb->cx > 0) tb->cx--;
3076 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3079 tb->dirty_flags |= DIRTY_ALL;
3081 /* Text is changed */
3087 * Delete or insert string
3089 static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
3093 /* Some lines are selected */
3096 by1 = MIN(tb->my, tb->cy);
3097 by2 = MAX(tb->my, tb->cy);
3100 /* No mark -- Select current line */
3101 else /* if (!tb->mark) */
3107 /* Set/Reset flag of each line */
3108 for (y = by1; y <= by2; y++)
3110 autopick_type an_entry, *entry = &an_entry;
3112 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3114 /* There is the flag already */
3117 /* Free memory for the entry */
3118 autopick_free_entry(entry);
3123 string_free(tb->lines_list[y]);
3125 /* Remove all noun flag */
3126 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3129 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3135 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3138 tb->dirty_flags |= DIRTY_ALL;
3140 /* Text is changed */
3147 * Check if this line is expression or not.
3148 * And update it if it is.
3150 static void check_expression_line(text_body_type *tb, int y)
3152 concptr s = tb->lines_list[y];
3154 if ((s[0] == '?' && s[1] == ':') ||
3155 (tb->states[y] & LSTAT_BYPASS))
3157 /* Expressions need re-evaluation */
3158 tb->dirty_flags |= DIRTY_EXPRESSION;
3164 * Add an empty line at the last of the file
3166 static bool add_empty_line(text_body_type *tb)
3170 for (k = 0; tb->lines_list[k]; k++)
3171 /* count number of lines */ ;
3173 /* Too many lines! */
3174 if (k >= MAX_LINES - 2) return FALSE;
3176 /* The last line is already empty */
3177 if (!tb->lines_list[k-1][0]) return FALSE;
3179 /* Create new empty line */
3180 tb->lines_list[k] = string_make("");
3182 /* Expressions need re-evaluation */
3183 tb->dirty_flags |= DIRTY_EXPRESSION;
3185 /* Text is changed */
3188 /* A line is added */
3194 * Insert return code and split the line
3196 static bool insert_return_code(text_body_type *tb)
3198 char buf[MAX_LINELEN];
3201 for (k = 0; tb->lines_list[k]; k++)
3202 /* count number of lines */ ;
3204 if (k >= MAX_LINES - 2) return FALSE;
3207 /* Move down lines */
3208 for (; tb->cy < k; k--)
3210 tb->lines_list[k+1] = tb->lines_list[k];
3211 tb->states[k+1] = tb->states[k];
3214 /* Split current line */
3215 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3218 if (iskanji(tb->lines_list[tb->cy][i]))
3219 buf[j++] = tb->lines_list[tb->cy][i++];
3221 buf[j++] = tb->lines_list[tb->cy][i];
3224 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3225 string_free(tb->lines_list[tb->cy]);
3226 tb->lines_list[tb->cy] = string_make(buf);
3228 /* Expressions need re-evaluation */
3229 tb->dirty_flags |= DIRTY_EXPRESSION;
3231 /* Text is changed */
3239 * Choose an item and get auto-picker entry from it.
3241 static bool entry_from_choosed_object(autopick_type *entry)
3246 q = _("どのアイテムを登録しますか? ", "Enter which item? ");
3247 s = _("アイテムを持っていない。", "You have nothing to enter.");
3248 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3249 if (!o_ptr) return FALSE;
3251 autopick_entry_from_object(entry, o_ptr);
3257 * Choose an item for search
3259 static byte get_object_for_search(object_type **o_handle, concptr *search_strp)
3261 char buf[MAX_NLEN+20];
3265 q = _("どのアイテムを検索しますか? ", "Enter which item? ");
3266 s = _("アイテムを持っていない。", "You have nothing to enter.");
3267 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3268 if (!o_ptr) return 0;
3272 string_free(*search_strp);
3273 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3274 *search_strp = string_make(format("<%s>", buf));
3280 * Prepare for search by destroyed object
3282 static byte get_destroyed_object_for_search(object_type **o_handle, concptr *search_strp)
3284 char buf[MAX_NLEN+20];
3286 if (!autopick_last_destroyed_object.k_idx) return 0;
3288 *o_handle = &autopick_last_destroyed_object;
3290 string_free(*search_strp);
3291 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3292 *search_strp = string_make(format("<%s>", buf));
3298 * Choose an item or string for search
3300 static byte get_string_for_search(object_type **o_handle, concptr *search_strp)
3306 * TERM_YELLOW : Overwrite mode
3307 * TERM_WHITE : Insert mode
3309 byte color = TERM_YELLOW;
3310 char buf[MAX_NLEN+20];
3313 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
3314 int col = sizeof(prompt) - 1;
3316 /* Prepare string buffer for edit */
3317 if (*search_strp) strcpy(buf, *search_strp);
3320 /* Object searching mode */
3323 color = TERM_L_GREEN;
3326 /* Display prompt */
3336 /* Display the string */
3337 Term_erase(col, 0, 255);
3338 Term_putstr(col, 0, -1, color, buf);
3341 Term_gotoxy(col + pos, 0);
3343 /* Get a special key code */
3344 skey = inkey_special(TRUE);
3346 /* Analyze the key */
3354 /* Now on insert mode */
3357 /* No move at beginning of line */
3358 if (0 == pos) break;
3362 int next_pos = i + 1;
3365 if (iskanji(buf[i])) next_pos++;
3368 /* Is there the cursor at next position? */
3369 if (next_pos >= pos) break;
3375 /* Get previous position */
3383 /* Now on insert mode */
3386 /* No move at end of line */
3387 if ('\0' == buf[pos]) break;
3391 if (iskanji(buf[pos])) pos += 2;
3409 if (*o_handle) return (back ? -1 : 1);
3410 string_free(*search_strp);
3411 *search_strp = string_make(buf);
3413 return (back ? -1 : 1);
3416 return get_object_for_search(o_handle, search_strp);
3419 /* Prepare string for destroyed object if there is one. */
3420 if (get_destroyed_object_for_search(o_handle, search_strp))
3430 /* Now on insert mode */
3433 /* No move at beginning of line */
3434 if (0 == pos) break;
3438 int next_pos = i + 1;
3441 if (iskanji(buf[i])) next_pos++;
3444 /* Is there the cursor at next position? */
3445 if (next_pos >= pos) break;
3451 /* Get previous position */
3454 /* Fall through to 'Delete key' */
3463 /* Now on insert mode */
3466 /* No move at end of line */
3467 if ('\0' == buf[pos]) break;
3469 /* Position of next character */
3473 /* Next character is one more byte away */
3474 if (iskanji(buf[pos])) src++;
3479 /* Move characters at src to dst */
3480 while ('\0' != (buf[dst++] = buf[src++]))
3488 /* Insert a character */
3493 /* Ignore special keys */
3494 if (skey & SKEY_MASK) break;
3496 /* Get a character code */
3499 /* Was non insert mode? */
3500 if (color != TERM_WHITE)
3502 /* Was object searching mode */
3503 if (color == TERM_L_GREEN)
3505 /* Cancel the mode */
3508 /* Remove indicating string */
3509 string_free(*search_strp);
3510 *search_strp = NULL;
3513 /* Overwrite default string */
3516 /* Go to insert mode */
3520 /* Save right part of string */
3521 strcpy(tmp, buf + pos);
3527 /* Bypass macro processing */
3545 if (pos < len && (isprint(c) || iskana(c)))
3547 if (pos < len && isprint(c))
3561 /* Write back the left part of string */
3562 my_strcat(buf, tmp, len + 1);
3569 /* Object searching mode was cancelled? */
3570 if (*o_handle && color != TERM_L_GREEN)
3572 /* Cancel the mode */
3575 /* Remove indicating string */
3577 string_free(*search_strp);
3578 *search_strp = NULL;
3583 } /* while (TRUE) */
3588 * Search next line matches for o_ptr
3590 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3592 autopick_type an_entry, *entry = &an_entry;
3593 GAME_TEXT o_name[MAX_NLEN];
3594 int bypassed_cy = -1;
3596 /* Start searching from current cursor position */
3599 /* Prepare object name string first */
3600 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3602 /* Convert the string to lower case */
3603 str_tolower(o_name);
3612 if (!tb->lines_list[++i]) break;
3619 /* Is this line is a correct entry? */
3620 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3622 /* Does this line match to the object? */
3623 match = is_autopick_aux(o_ptr, entry, o_name);
3624 autopick_free_entry(entry);
3625 if (!match) continue;
3627 /* Found a line but it's inactive */
3628 if (tb->states[i] & LSTAT_BYPASS)
3630 /* If it is first found, remember it */
3631 if (bypassed_cy == -1) bypassed_cy = i;
3634 /* Found an active line! */
3637 /* Move to this line */
3641 if (bypassed_cy != -1)
3643 /* Mark as some lines are skipped */
3644 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3652 if (bypassed_cy != -1)
3654 /* Move to the remembered line */
3656 tb->cy = bypassed_cy;
3658 /* Mark as this line is inactive */
3659 tb->dirty_flags |= DIRTY_INACTIVE;
3664 /* Mark as NOT FOUND */
3665 tb->dirty_flags |= DIRTY_NOT_FOUND;
3673 * Search next line matches to the string
3675 static void search_for_string(text_body_type *tb, concptr search_str, bool forward)
3677 int bypassed_cy = -1;
3678 int bypassed_cx = 0;
3680 /* Start searching from current cursor position */
3690 if (!tb->lines_list[++i]) break;
3697 /* Look for the string pattern */
3698 pos = my_strstr(tb->lines_list[i], search_str);
3703 /* Found a line but it's inactive */
3704 if ((tb->states[i] & LSTAT_BYPASS) &&
3705 !(tb->states[i] & LSTAT_EXPRESSION))
3707 /* If it is first found, remember it */
3708 if (bypassed_cy == -1)
3711 bypassed_cx = (int)(pos - tb->lines_list[i]);
3715 /* Found an active line! */
3718 /* Move to this location */
3719 tb->cx = (int)(pos - tb->lines_list[i]);
3722 if (bypassed_cy != -1)
3724 /* Mark as some lines are skipped */
3725 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3733 if (bypassed_cy != -1)
3735 /* Move to the remembered line */
3736 tb->cx = bypassed_cx;
3737 tb->cy = bypassed_cy;
3739 /* Mark as this line is inactive */
3740 tb->dirty_flags |= DIRTY_INACTIVE;
3745 /* Mark as NOT FOUND */
3746 tb->dirty_flags |= DIRTY_NOT_FOUND;
3756 * Editor command id's
3759 #define EC_SAVEQUIT 2
3770 #define EC_PGDOWN 13
3772 #define EC_BOTTOM 15
3777 #define EC_KILL_LINE 20
3778 #define EC_DELETE_CHAR 21
3779 #define EC_BACKSPACE 22
3780 #define EC_SEARCH_STR 23
3781 #define EC_SEARCH_FORW 24
3782 #define EC_SEARCH_BACK 25
3783 #define EC_SEARCH_OBJ 26
3784 #define EC_SEARCH_DESTROYED 27
3785 #define EC_INSERT_OBJECT 28
3786 #define EC_INSERT_DESTROYED 29
3787 #define EC_INSERT_BLOCK 30
3788 #define EC_INSERT_MACRO 31
3789 #define EC_INSERT_KEYMAP 32
3790 #define EC_CL_AUTOPICK 33
3791 #define EC_CL_DESTROY 34
3792 #define EC_CL_LEAVE 35
3793 #define EC_CL_QUERY 36
3794 #define EC_CL_NO_DISP 37
3795 #define EC_OK_COLLECTING 38
3796 #define EC_IK_UNAWARE 39
3797 #define EC_IK_UNIDENTIFIED 40
3798 #define EC_IK_IDENTIFIED 41
3799 #define EC_IK_STAR_IDENTIFIED 42
3800 #define EC_OK_BOOSTED 43
3801 #define EC_OK_MORE_DICE 44
3802 #define EC_OK_MORE_BONUS 45
3803 #define EC_OK_WORTHLESS 46
3804 #define EC_OK_ARTIFACT 47
3805 #define EC_OK_EGO 48
3806 #define EC_OK_GOOD 49
3807 #define EC_OK_NAMELESS 50
3808 #define EC_OK_AVERAGE 51
3809 #define EC_OK_RARE 52
3810 #define EC_OK_COMMON 53
3811 #define EC_OK_WANTED 54
3812 #define EC_OK_UNIQUE 55
3813 #define EC_OK_HUMAN 56
3814 #define EC_OK_UNREADABLE 57
3815 #define EC_OK_REALM1 58
3816 #define EC_OK_REALM2 59
3817 #define EC_OK_FIRST 60
3818 #define EC_OK_SECOND 61
3819 #define EC_OK_THIRD 62
3820 #define EC_OK_FOURTH 63
3821 #define EC_KK_WEAPONS 64
3822 #define EC_KK_FAVORITE_WEAPONS 65
3823 #define EC_KK_ARMORS 66
3824 #define EC_KK_MISSILES 67
3825 #define EC_KK_DEVICES 68
3826 #define EC_KK_LIGHTS 69
3827 #define EC_KK_JUNKS 70
3828 #define EC_KK_CORPSES 71
3829 #define EC_KK_SPELLBOOKS 72
3830 #define EC_KK_SHIELDS 73
3831 #define EC_KK_BOWS 74
3832 #define EC_KK_RINGS 75
3833 #define EC_KK_AMULETS 76
3834 #define EC_KK_SUITS 77
3835 #define EC_KK_CLOAKS 78
3836 #define EC_KK_HELMS 79
3837 #define EC_KK_GLOVES 80
3838 #define EC_KK_BOOTS 81
3844 static GAME_TEXT MN_QUIT[] = "セーブ無しで終了";
3845 static GAME_TEXT MN_SAVEQUIT[] = "セーブして終了";
3846 static GAME_TEXT MN_REVERT[] = "全ての変更を破棄";
3847 static GAME_TEXT MN_HELP[] = "ヘルプ";
3849 static GAME_TEXT MN_MOVE[] = "カーソル移動";
3850 static GAME_TEXT MN_LEFT[] = "左 (←矢印キー)";
3851 static GAME_TEXT MN_DOWN[] = "下 (↓矢印キー)";
3852 static GAME_TEXT MN_UP[] = "上 (↑矢印キー)";
3853 static GAME_TEXT MN_RIGHT[] = "右 (→矢印キー)";
3854 static GAME_TEXT MN_BOL[] = "行の先頭";
3855 static GAME_TEXT MN_EOL[] = "行の終端";
3856 static GAME_TEXT MN_PGUP[] = "上のページ (PageUpキー)";
3857 static GAME_TEXT MN_PGDOWN[] = "下のページ (PageDownキー)";
3858 static GAME_TEXT MN_TOP[] = "1行目へ移動 (Homeキー)";
3859 static GAME_TEXT MN_BOTTOM[] = "最下行へ移動(Endキー)";
3861 static GAME_TEXT MN_EDIT[] = "編集";
3862 static GAME_TEXT MN_CUT[] = "カット";
3863 static GAME_TEXT MN_COPY[] = "コピー";
3864 static GAME_TEXT MN_PASTE[] = "ペースト";
3865 static GAME_TEXT MN_BLOCK[] = "選択範囲の指定";
3866 static GAME_TEXT MN_KILL_LINE[] = "行の残りを削除";
3867 static GAME_TEXT MN_DELETE_CHAR[] = "1文字削除";
3868 static GAME_TEXT MN_BACKSPACE[] = "バックスペース";
3869 static GAME_TEXT MN_RETURN[] = "改行";
3871 static GAME_TEXT MN_SEARCH[] = "検索";
3872 static GAME_TEXT MN_SEARCH_STR[] = "文字列で検索";
3873 static GAME_TEXT MN_SEARCH_FORW[] = "前方へ再検索";
3874 static GAME_TEXT MN_SEARCH_BACK[] = "後方へ再検索";
3875 static GAME_TEXT MN_SEARCH_OBJ[] = "アイテムを選択して検索";
3876 static GAME_TEXT MN_SEARCH_DESTROYED[] = "自動破壊されたアイテムで検索";
3878 static GAME_TEXT MN_INSERT[] = "色々挿入";
3879 static GAME_TEXT MN_INSERT_OBJECT[] = "選択したアイテムの名前を挿入";
3880 static GAME_TEXT MN_INSERT_DESTROYED[] = "自動破壊されたアイテムの名前を挿入";
3881 static GAME_TEXT MN_INSERT_BLOCK[] = "条件分岐ブロックの例を挿入";
3882 static GAME_TEXT MN_INSERT_MACRO[] = "マクロ定義を挿入";
3883 static GAME_TEXT MN_INSERT_KEYMAP[] = "キーマップ定義を挿入";
3885 static GAME_TEXT MN_COMMAND_LETTER[] = "拾い/破壊/放置の選択";
3886 static GAME_TEXT MN_CL_AUTOPICK[] = "「 」 (自動拾い)";
3887 static GAME_TEXT MN_CL_DESTROY[] = "「!」 (自動破壊)";
3888 static GAME_TEXT MN_CL_LEAVE[] = "「~」 (放置)";
3889 static GAME_TEXT MN_CL_QUERY[] = "「;」 (確認して拾う)";
3890 static GAME_TEXT MN_CL_NO_DISP[] = "「(」 (マップコマンドで表示しない)";
3892 static GAME_TEXT MN_ADJECTIVE_GEN[] = "形容詞(一般)の選択";
3893 static GAME_TEXT MN_RARE[] = "レアな (装備)";
3894 static GAME_TEXT MN_COMMON[] = "ありふれた (装備)";
3896 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "形容詞(特殊)の選択";
3897 static GAME_TEXT MN_BOOSTED[] = "ダイス目の違う (武器)";
3898 static GAME_TEXT MN_MORE_DICE[] = "ダイス目 # 以上の (武器)";
3899 static GAME_TEXT MN_MORE_BONUS[] = "修正値 # 以上の (指輪等)";
3900 static GAME_TEXT MN_WANTED[] = "賞金首の (死体)";
3901 static GAME_TEXT MN_UNIQUE[] = "ユニーク・モンスターの (死体)";
3902 static GAME_TEXT MN_HUMAN[] = "人間の (死体)";
3903 static GAME_TEXT MN_UNREADABLE[] = "読めない (魔法書)";
3904 static GAME_TEXT MN_REALM1[] = "第一領域の (魔法書)";
3905 static GAME_TEXT MN_REALM2[] = "第二領域の (魔法書)";
3906 static GAME_TEXT MN_FIRST[] = "1冊目の (魔法書)";
3907 static GAME_TEXT MN_SECOND[] = "2冊目の (魔法書)";
3908 static GAME_TEXT MN_THIRD[] = "3冊目の (魔法書)";
3909 static GAME_TEXT MN_FOURTH[] = "4冊目の (魔法書)";
3911 static GAME_TEXT MN_NOUN[] = "名詞の選択";
3915 static GAME_TEXT MN_QUIT[] = "Quit without save";
3916 static GAME_TEXT MN_SAVEQUIT[] = "Save & Quit";
3917 static GAME_TEXT MN_REVERT[] = "Revert all changes";
3918 static GAME_TEXT MN_HELP[] = "Help";
3920 static GAME_TEXT MN_MOVE[] = "Move cursor";
3921 static GAME_TEXT MN_LEFT[] = "Left (Left Arrow key)";
3922 static GAME_TEXT MN_DOWN[] = "Down (Down Arrow key)";
3923 static GAME_TEXT MN_UP[] = "Up (Up Arrow key)";
3924 static GAME_TEXT MN_RIGHT[] = "Right (Right Arrow key)";
3925 static GAME_TEXT MN_BOL[] = "Beggining of line";
3926 static GAME_TEXT MN_EOL[] = "End of line";
3927 static GAME_TEXT MN_PGUP[] = "Page up (PageUp key)";
3928 static GAME_TEXT MN_PGDOWN[] = "Page down(PageDown key)";
3929 static GAME_TEXT MN_TOP[] = "Top (Home key)";
3930 static GAME_TEXT MN_BOTTOM[] = "Bottom (End key)";
3932 static GAME_TEXT MN_EDIT[] = "Edit";
3933 static GAME_TEXT MN_CUT[] = "Cut";
3934 static GAME_TEXT MN_COPY[] = "Copy";
3935 static GAME_TEXT MN_PASTE[] = "Paste";
3936 static GAME_TEXT MN_BLOCK[] = "Select block";
3937 static GAME_TEXT MN_KILL_LINE[] = "Kill rest of line";
3938 static GAME_TEXT MN_DELETE_CHAR[] = "Delete character";
3939 static GAME_TEXT MN_BACKSPACE[] = "Backspace";
3940 static GAME_TEXT MN_RETURN[] = "Return";
3942 static GAME_TEXT MN_SEARCH[] = "Search";
3943 static GAME_TEXT MN_SEARCH_STR[] = "Search by string";
3944 static GAME_TEXT MN_SEARCH_FORW[] = "Search forward";
3945 static GAME_TEXT MN_SEARCH_BACK[] = "Search backward";
3946 static GAME_TEXT MN_SEARCH_OBJ[] = "Search by inventory object";
3947 static GAME_TEXT MN_SEARCH_DESTROYED[] = "Search by destroyed object";
3949 static GAME_TEXT MN_INSERT[] = "Insert...";
3950 static GAME_TEXT MN_INSERT_OBJECT[] = "Insert name of choosen object";
3951 static GAME_TEXT MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
3952 static GAME_TEXT MN_INSERT_BLOCK[] = "Insert conditional block";
3953 static GAME_TEXT MN_INSERT_MACRO[] = "Insert a macro definition";
3954 static GAME_TEXT MN_INSERT_KEYMAP[] = "Insert a keymap definition";
3956 static GAME_TEXT MN_COMMAND_LETTER[] = "Command letter";
3957 static GAME_TEXT MN_CL_AUTOPICK[] = "' ' (Auto pick)";
3958 static GAME_TEXT MN_CL_DESTROY[] = "'!' (Auto destroy)";
3959 static GAME_TEXT MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
3960 static GAME_TEXT MN_CL_QUERY[] = "';' (Query to pick up)";
3961 static GAME_TEXT MN_CL_NO_DISP[] = "'(' (No display on the large map)";
3963 static GAME_TEXT MN_ADJECTIVE_GEN[] = "Adjective (general)";
3964 static GAME_TEXT MN_RARE[] = "rare (equipments)";
3965 static GAME_TEXT MN_COMMON[] = "common (equipments)";
3967 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
3968 static GAME_TEXT MN_BOOSTED[] = "dice boosted (weapons)";
3969 static GAME_TEXT MN_MORE_DICE[] = "more than # dice (weapons)";
3970 static GAME_TEXT MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
3971 static GAME_TEXT MN_WANTED[] = "wanted (corpse)";
3972 static GAME_TEXT MN_UNIQUE[] = "unique (corpse)";
3973 static GAME_TEXT MN_HUMAN[] = "human (corpse)";
3974 static GAME_TEXT MN_UNREADABLE[] = "unreadable (spellbooks)";
3975 static GAME_TEXT MN_REALM1[] = "realm1 (spellbooks)";
3976 static GAME_TEXT MN_REALM2[] = "realm2 (spellbooks)";
3977 static GAME_TEXT MN_FIRST[] = "first (spellbooks)";
3978 static GAME_TEXT MN_SECOND[] = "second (spellbooks)";
3979 static GAME_TEXT MN_THIRD[] = "third (spellbooks)";
3980 static GAME_TEXT MN_FOURTH[] = "fourth (spellbooks)";
3982 static GAME_TEXT MN_NOUN[] = "Keywords (noun)";
3992 } command_menu_type;
3995 command_menu_type menu_data[] =
3997 {MN_HELP, 0, -1, EC_HELP},
3998 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
3999 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4000 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4002 {MN_EDIT, 0, -1, -1},
4003 {MN_CUT, 1, KTRL('x'), EC_CUT},
4004 {MN_COPY, 1, KTRL('c'), EC_COPY},
4005 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4006 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4007 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4008 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4009 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4010 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4011 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4013 {MN_SEARCH, 0, -1, -1},
4014 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4015 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4016 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4017 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4018 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4020 {MN_MOVE, 0, -1, -1},
4021 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4022 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4023 {MN_UP, 1, KTRL('p'), EC_UP},
4024 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4025 {MN_BOL, 1, KTRL('a'), EC_BOL},
4026 {MN_EOL, 1, KTRL('e'), EC_EOL},
4027 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4028 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4029 {MN_TOP, 1, KTRL('t'), EC_TOP},
4030 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4032 {MN_INSERT, 0, -1, -1},
4033 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4034 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4035 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4036 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4037 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4039 {MN_ADJECTIVE_GEN, 0, -1, -1},
4040 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4041 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4042 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4043 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4044 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4045 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4046 {KEY_EGO, 1, -1, EC_OK_EGO},
4047 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4048 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4049 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4050 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4051 {MN_RARE, 1, -1, EC_OK_RARE},
4052 {MN_COMMON, 1, -1, EC_OK_COMMON},
4054 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4055 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4056 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4057 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4058 {MN_WANTED, 1, -1, EC_OK_WANTED},
4059 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4060 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4061 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4062 {MN_REALM1, 1, -1, EC_OK_REALM1},
4063 {MN_REALM2, 1, -1, EC_OK_REALM2},
4064 {MN_FIRST, 1, -1, EC_OK_FIRST},
4065 {MN_SECOND, 1, -1, EC_OK_SECOND},
4066 {MN_THIRD, 1, -1, EC_OK_THIRD},
4067 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4069 {MN_NOUN, 0, -1, -1},
4070 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4071 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4072 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4073 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4074 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4075 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4076 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4077 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4078 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4079 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4080 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4081 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4082 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4083 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4084 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4085 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4086 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4087 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4089 {MN_COMMAND_LETTER, 0, -1, -1},
4090 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4091 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4092 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4093 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4094 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4096 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4103 * Find a command by 'key'.
4105 static int get_com_id(char key)
4109 for (i = 0; menu_data[i].name; i++)
4111 if (menu_data[i].key == key)
4113 return menu_data[i].com_id;
4122 * Display the menu, and get a command
4124 static int do_command_menu(int level, int start)
4129 int col0 = 5 + level*7;
4130 int row0 = 1 + level*3;
4132 int menu_id_list[26];
4134 char linestr[MAX_LINELEN];
4136 /* Get max length */
4138 for (i = start; menu_data[i].level >= level; i++)
4142 /* Ignore lower level sub menus */
4143 if (menu_data[i].level > level) continue;
4145 len = strlen(menu_data[i].name);
4146 if (len > max_len) max_len = len;
4148 menu_id_list[menu_key] = i;
4152 while (menu_key < 26)
4154 menu_id_list[menu_key] = -1;
4158 /* Extra space for displaying menu key and command key */
4159 max_menu_wid = max_len + 3 + 3;
4161 /* Prepare box line */
4163 strcat(linestr, "+");
4164 for (i = 0; i < max_menu_wid + 2; i++)
4166 strcat(linestr, "-");
4168 strcat(linestr, "+");
4178 int row1 = row0 + 1;
4181 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4183 /* Draw menu items */
4185 for (i = start; menu_data[i].level >= level; i++)
4187 char com_key_str[3];
4190 /* Ignore lower level sub menus */
4191 if (menu_data[i].level > level) continue;
4193 if (menu_data[i].com_id == -1)
4195 strcpy(com_key_str, _("▼", ">"));
4197 else if (menu_data[i].key != -1)
4199 com_key_str[0] = '^';
4200 com_key_str[1] = menu_data[i].key + '@';
4201 com_key_str[2] = '\0';
4205 com_key_str[0] = '\0';
4208 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4210 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4215 /* Draw bottom line */
4216 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4218 /* The menu was shown */
4221 prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
4224 if (key == ESCAPE) return 0;
4226 if ('a' <= key && key <= 'z')
4228 menu_id = menu_id_list[key - 'a'];
4232 com_id = menu_data[menu_id].com_id;
4236 com_id = do_command_menu(level + 1, menu_id + 1);
4238 if (com_id) return com_id;
4250 com_id = get_com_id(key);
4251 if (com_id) return com_id;
4258 static chain_str_type *new_chain_str(concptr str)
4260 chain_str_type *chain;
4262 size_t len = strlen(str);
4264 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4266 strcpy(chain->s, str);
4273 static void kill_yank_chain(text_body_type *tb)
4275 chain_str_type *chain = tb->yank;
4277 tb->yank_eol = TRUE;
4281 chain_str_type *next = chain->next;
4282 size_t len = strlen(chain->s);
4284 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4291 static void add_str_to_yank(text_body_type *tb, concptr str)
4293 chain_str_type *chain;
4295 tb->yank_eol = FALSE;
4297 if (NULL == tb->yank)
4299 tb->yank = new_chain_str(str);
4309 chain->next = new_chain_str(str);
4314 chain = chain->next;
4320 * Do work for the copy editor-command
4322 static void copy_text_to_yank(text_body_type *tb)
4324 int len = strlen(tb->lines_list[tb->cy]);
4326 /* Correct cursor location */
4327 if (tb->cx > len) tb->cx = len;
4329 /* Use single line? */
4332 /* Select a single line */
4338 /* Kill old yank buffer */
4339 kill_yank_chain(tb);
4342 /* Single line case */
4343 if (tb->my == tb->cy)
4346 char buf[MAX_LINELEN];
4347 int bx1 = MIN(tb->mx, tb->cx);
4348 int bx2 = MAX(tb->mx, tb->cx);
4350 /* Correct fake cursor position */
4351 if (bx2 > len) bx2 = len;
4353 /* Whole part of this line is selected */
4354 if (bx1 == 0 && bx2 == len)
4356 /* Copy this line */
4357 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4359 /* Add end of line to the buffer */
4360 add_str_to_yank(tb, "");
4363 /* Segment of this line is selected */
4366 for (i = 0; i < bx2 - bx1; i++)
4368 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4372 /* Copy this segment of line */
4373 add_str_to_yank(tb, buf);
4377 /* Multiple lines case */
4378 else /* if (tb->my != tb->cy) */
4382 int by1 = MIN(tb->my, tb->cy);
4383 int by2 = MAX(tb->my, tb->cy);
4386 for (y = by1; y <= by2; y++)
4388 /* Copy this line */
4389 add_str_to_yank(tb, tb->lines_list[y]);
4392 /* Add final end of line to the buffer */
4393 add_str_to_yank(tb, "");
4396 /* Disable selection */
4400 tb->dirty_flags |= DIRTY_ALL;
4404 #define DESCRIPT_HGT 3
4409 static void draw_text_editor(text_body_type *tb)
4412 int by1 = 0, by2 = 0;
4414 Term_get_size(&tb->wid, &tb->hgt);
4417 * Top line (-1), description line (-3), separator (-1)
4420 tb->hgt -= 2 + DESCRIPT_HGT;
4423 /* Don't let cursor at second byte of kanji */
4424 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4425 if (iskanji(tb->lines_list[tb->cy][i]))
4431 * Move to a correct position in the
4434 if (i & 1) tb->cx--;
4441 /* Scroll if necessary */
4442 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4443 tb->upper = tb->cy - (tb->hgt)/2;
4446 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4447 tb->left = tb->cx - (tb->wid)*2/3;
4451 /* Redraw whole window after resize */
4452 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4453 tb->dirty_flags |= DIRTY_SCREEN;
4455 /* Redraw all text after scroll */
4456 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4457 tb->dirty_flags |= DIRTY_ALL;
4460 if (tb->dirty_flags & DIRTY_SCREEN)
4462 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4466 /* Redraw mode line */
4467 if (tb->dirty_flags & DIRTY_MODE)
4469 char buf[MAX_LINELEN];
4471 int sepa_length = tb->wid;
4474 for (i = 0; i < sepa_length; i++)
4478 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4481 if (tb->dirty_flags & DIRTY_EXPRESSION)
4486 for (y = 0; tb->lines_list[y]; y++)
4490 concptr s = tb->lines_list[y];
4494 /* Update this line's state */
4495 tb->states[y] = state;
4497 if (*s++ != '?') continue;
4498 if (*s++ != ':') continue;
4500 /* Lines below this line are auto-registered */
4501 if (streq(s, "$AUTOREGISTER"))
4502 state |= LSTAT_AUTOREGISTER;
4505 ss = (char *)string_make(s);
4508 /* Parse the expr */
4509 v = process_pref_file_expr(&ss, &f);
4512 if (streq(v, "0")) state |= LSTAT_BYPASS;
4513 else state &= ~LSTAT_BYPASS;
4515 /* Cannot use string_free() because the string was "destroyed" */
4516 C_KILL(s_keep, s_len + 1, char);
4518 /* Re-update this line's state */
4519 tb->states[y] = state | LSTAT_EXPRESSION;
4522 tb->dirty_flags |= DIRTY_ALL;
4527 tb->dirty_flags |= DIRTY_ALL;
4529 by1 = MIN(tb->my, tb->cy);
4530 by2 = MAX(tb->my, tb->cy);
4533 /* Dump up to tb->hgt lines of messages */
4534 for (i = 0; i < tb->hgt; i++)
4540 int y = tb->upper+i;
4542 /* clean or dirty? */
4543 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4546 msg = tb->lines_list[y];
4549 /* Apply horizontal scroll */
4550 for (j = 0; *msg; msg++, j++)
4552 if (j == tb->left) break;
4568 Term_erase(0, i + 1, tb->wid);
4570 if (tb->states[y] & LSTAT_AUTOREGISTER)
4572 /* Warning color -- These lines will be deleted later */
4577 /* Bypassed line will be displayed by darker color */
4578 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4579 else color = TERM_WHITE;
4582 /* No mark or Out of mark */
4583 if (!tb->mark || (y < by1 || by2 < y))
4585 /* Dump the messages, bottom to top */
4586 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4589 /* Multiple lines selected */
4590 else if (by1 != by2)
4592 /* Dump the messages, bottom to top */
4593 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4596 /* Single line selected */
4599 int x0 = leftcol + tb->left;
4600 int len = strlen(tb->lines_list[tb->cy]);
4601 int bx1 = MIN(tb->mx, tb->cx);
4602 int bx2 = MAX(tb->mx, tb->cx);
4604 /* Correct cursor location */
4605 if (bx2 > len) bx2 = len;
4607 Term_gotoxy(leftcol, i + 1);
4608 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4609 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4610 Term_addstr(-1, color, msg + (bx2 - x0));
4614 for (; i < tb->hgt; i++)
4617 Term_erase(0, i + 1, tb->wid);
4620 /* Display information when updated */
4621 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4623 autopick_type an_entry, *entry = &an_entry;
4624 concptr str1 = NULL, str2 = NULL;
4627 /* Clear information line */
4628 for (i = 0; i < DESCRIPT_HGT; i++)
4631 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4634 /* Display information */
4635 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4637 str1 = format(_("パターンが見つかりません: %s", "Pattern not found: %s"), tb->search_str);
4639 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4641 str1 = format(_("無効状態の行をスキップしました。(%sを検索中)",
4642 "Some inactive lines are skipped. (Searching %s)"), tb->search_str);
4644 else if (tb->dirty_flags & DIRTY_INACTIVE)
4646 str1 = format(_("無効状態の行だけが見付かりました。(%sを検索中)",
4647 "Found only an inactive line. (Searching %s)"), tb->search_str);
4649 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4651 str1 = _("検索するパターンがありません(^S で検索)。", "No pattern to search. (Press ^S to search.)");
4653 else if (tb->lines_list[tb->cy][0] == '#')
4655 str1 = _("この行はコメントです。", "This line is a comment.");
4657 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4659 switch(tb->lines_list[tb->cy][0])
4662 str1 = _("この行は条件分岐式です。", "This line is a Conditional Expression.");
4665 str1 = _("この行はマクロの実行内容を定義します。", "This line defines a Macro action.");
4668 str1 = _("この行はマクロのトリガー・キーを定義します。", "This line defines a Macro trigger key.");
4671 str1 = _("この行はキー配置を定義します。", "This line defines a Keymap.");
4675 switch(tb->lines_list[tb->cy][0])
4678 if (tb->states[tb->cy] & LSTAT_BYPASS)
4680 str2 = _("現在の式の値は「偽(=0)」です。", "The expression is 'False'(=0) currently.");
4684 str2 = _("現在の式の値は「真(=1)」です。", "The expression is 'True'(=1) currently.");
4689 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4691 str2 = _("この行は後で削除されます。", "This line will be delete later.");
4694 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4696 str2 = _("この行は現在は無効な状態です。", "This line is bypassed currently.");
4702 /* Get description of an autopicker preference line */
4703 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4705 char buf[MAX_LINELEN];
4706 char temp[MAX_LINELEN];
4709 describe_autopick(buf, entry);
4711 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4713 strcat(buf, _("この行は後で削除されます。", " This line will be delete later."));
4716 if (tb->states[tb->cy] & LSTAT_BYPASS)
4718 strcat(buf, _("この行は現在は無効な状態です。", " This line is bypassed currently."));
4721 roff_to_buf(buf, 81, temp, sizeof(temp));
4723 for (i = 0; i < 3; i++)
4729 prt(t, tb->hgt +1 + 1 + i, 0);
4733 autopick_free_entry(entry);
4736 /* Draw the first line */
4737 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4739 /* Draw the second line */
4740 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4746 * Kill segment of a line
4748 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4750 char buf[MAX_LINELEN];
4751 concptr s = tb->lines_list[y];
4755 /* Kill whole line? */
4756 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4760 string_free(tb->lines_list[y]);
4762 /* Shift lines up */
4763 for (i = y; tb->lines_list[i+1]; i++)
4764 tb->lines_list[i] = tb->lines_list[i+1];
4765 tb->lines_list[i] = NULL;
4767 /* Expressions need re-evaluation */
4768 tb->dirty_flags |= DIRTY_EXPRESSION;
4774 if (x0 == x1) return;
4776 /* Before the segment */
4777 for (x = 0; x < x0; x++)
4780 /* After the segment */
4781 for (x = x1; s[x]; x++)
4787 string_free(tb->lines_list[y]);
4788 tb->lines_list[y] = string_make(buf);
4790 /* Expressions may need re-evaluation */
4791 check_expression_line(tb, y);
4793 /* Text is changed */
4799 * Get a trigger key and insert ASCII string for the trigger
4801 static bool insert_macro_line(text_body_type *tb)
4810 /* Do not process macros */
4816 /* Read the pattern */
4822 /* Do not process macros */
4825 /* Do not wait for keys */
4828 /* Attempt to read a key */
4837 /* Convert the trigger */
4838 ascii_to_text(tmp, buf);
4841 if(!tmp[0]) return FALSE;
4845 /* Insert preference string */
4846 insert_return_code(tb);
4847 string_free(tb->lines_list[tb->cy]);
4848 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4850 /* Acquire action */
4851 i = macro_find_exact(buf);
4855 /* Nothing defined */
4860 /* Analyze the current action */
4861 ascii_to_text(tmp, macro__act[i]);
4864 /* Insert blank action preference line */
4865 insert_return_code(tb);
4866 string_free(tb->lines_list[tb->cy]);
4867 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4874 * Get a command key and insert ASCII string for the key
4876 static bool insert_keymap_line(text_body_type *tb)
4884 if (rogue_like_commands)
4886 mode = KEYMAP_MODE_ROGUE;
4892 mode = KEYMAP_MODE_ORIG;
4903 /* Convert the trigger */
4904 ascii_to_text(tmp, buf);
4907 if(!tmp[0]) return FALSE;
4911 /* Insert preference string */
4912 insert_return_code(tb);
4913 string_free(tb->lines_list[tb->cy]);
4914 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4916 /* Look up the keymap */
4917 act = keymap_act[mode][(byte)(buf[0])];
4921 /* Analyze the current action */
4922 ascii_to_text(tmp, act);
4926 /* No keymap defined -- Use trigger key itself as a default */
4928 /* Nothing to do (use tmp) */
4931 /* Insert blank action preference line */
4932 insert_return_code(tb);
4933 string_free(tb->lines_list[tb->cy]);
4934 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4941 * Execute a single editor command
4943 static bool do_editor_command(text_body_type *tb, int com_id)
4950 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
4951 "Discard all changes and quit. Are you sure? "))) break;
4953 return QUIT_WITHOUT_SAVE;
4956 return QUIT_AND_SAVE;
4959 /* Revert to original */
4960 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
4961 "Discard all changes and revert to original file. Are you sure? "))) break;
4963 free_text_lines(tb->lines_list);
4964 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4965 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4966 tb->cx = tb->cy = 0;
4969 /* Text is not changed */
4970 tb->changed = FALSE;
4974 /* Peruse the main help file */
4975 (void)show_file(TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
4977 tb->dirty_flags |= DIRTY_SCREEN;
4982 /* Split a line or insert end of line */
4984 /* Ignore selection */
4990 tb->dirty_flags |= DIRTY_ALL;
4993 insert_return_code(tb);
4998 tb->dirty_flags |= DIRTY_ALL;
5011 len = strlen(tb->lines_list[tb->cy]);
5012 if (len < tb->cx) tb->cx = len;
5015 /* Don't let cursor at second byte of kanji */
5016 for (i = 0; tb->lines_list[tb->cy][i]; i++)
5018 if (iskanji(tb->lines_list[tb->cy][i]))
5023 /* Move to the left */
5031 else if (tb->cy > 0)
5034 tb->cx = strlen(tb->lines_list[tb->cy]);
5041 /* Is this the last line? */
5042 if (!tb->lines_list[tb->cy + 1])
5044 /* Add one more empty line if possible */
5045 if (!add_empty_line(tb)) break;
5055 if (tb->cy > 0) tb->cy--;
5064 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5067 len = strlen(tb->lines_list[tb->cy]);
5070 /* Correct the cursor position */
5073 /* Is this the last line? */
5074 if (!tb->lines_list[tb->cy + 1])
5076 /* Add one more empty line if possible */
5077 if (!add_empty_line(tb)) break;
5080 /* Move to the beginning of next line */
5088 /* Beginning of line */
5094 tb->cx = strlen(tb->lines_list[tb->cy]);
5098 while (0 < tb->cy && tb->upper <= tb->cy)
5100 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5106 while (tb->cy < tb->upper + tb->hgt)
5108 /* Is this the last line? */
5109 if (!tb->lines_list[tb->cy + 1])
5111 /* Add one more empty line if possible */
5112 if (!add_empty_line(tb)) break;
5128 /* Is this the last line? */
5129 if (!tb->lines_list[tb->cy + 1])
5131 /* Add one more empty line if possible */
5132 if (!add_empty_line(tb)) break;
5138 /* Always at the biginning of the last line */
5145 /* Copy the text first */
5146 copy_text_to_yank(tb);
5148 /* Single line case */
5149 if (tb->my == tb->cy)
5151 int bx1 = MIN(tb->mx, tb->cx);
5152 int bx2 = MAX(tb->mx, tb->cx);
5153 int len = strlen(tb->lines_list[tb->cy]);
5155 /* Correct fake cursor position */
5156 if (bx2 > len) bx2 = len;
5158 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5160 /* New cursor position */
5164 /* Multiple lines case */
5165 else /* if (tb->my != tb->cy) */
5169 int by1 = MIN(tb->my, tb->cy);
5170 int by2 = MAX(tb->my, tb->cy);
5172 /* Kill lines in reverse order */
5173 for (y = by2; y >= by1; y--)
5175 int len = strlen(tb->lines_list[y]);
5177 kill_line_segment(tb, y, 0, len, TRUE);
5180 /* New cursor position */
5186 /* Disable selection */
5190 tb->dirty_flags |= DIRTY_ALL;
5192 /* Text is changed */
5199 copy_text_to_yank(tb);
5202 * Move cursor position to the end of the selection
5204 * Pressing ^C ^V correctly duplicates the selection.
5206 if (tb->my == tb->cy)
5208 tb->cx = MAX(tb->cx, tb->mx);
5211 * When whole line is selected, the end of
5212 * line code is also copyed.
5214 if (!tb->lines_list[tb->cy][tb->cx])
5216 /* Is this the last line? */
5217 if (!tb->lines_list[tb->cy + 1])
5219 /* Add one more empty line if possible */
5220 if (!add_empty_line(tb)) break;
5223 /* Go to the beginning of next line */
5230 tb->cy = MAX(tb->cy, tb->my);
5232 /* Is this the last line? */
5233 if (!tb->lines_list[tb->cy + 1])
5235 /* Add one more empty line if possible */
5236 if (!add_empty_line(tb)) break;
5247 /* Paste killed text */
5249 chain_str_type *chain = tb->yank;
5250 int len = strlen(tb->lines_list[tb->cy]);
5252 /* Nothing to do? */
5255 /* Correct cursor location */
5256 if (tb->cx > len) tb->cx = len;
5258 /* Ignore selection */
5264 tb->dirty_flags |= DIRTY_ALL;
5270 concptr yank_str = chain->s;
5272 char buf[MAX_LINELEN];
5274 char rest[MAX_LINELEN], *rest_ptr = rest;
5276 /* Save preceding string */
5277 for(i = 0; i < tb->cx; i++)
5278 buf[i] = tb->lines_list[tb->cy][i];
5280 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5282 /* Paste yank buffer */
5283 while (*yank_str && i < MAX_LINELEN-1)
5285 buf[i++] = *yank_str++;
5291 chain = chain->next;
5293 if (chain || tb->yank_eol)
5295 /* There is an end of line between chain nodes */
5297 insert_return_code(tb);
5299 /* Replace this line with new one */
5300 string_free(tb->lines_list[tb->cy]);
5301 tb->lines_list[tb->cy] = string_make(buf);
5303 /* Move to next line */
5310 /* Final line doesn't have end of line */
5312 tb->cx = strlen(buf);
5314 /* Rest of original line */
5315 while (*rest_ptr && i < MAX_LINELEN-1)
5317 buf[i++] = *rest_ptr++;
5323 /* Replace this line with new one */
5324 string_free(tb->lines_list[tb->cy]);
5325 tb->lines_list[tb->cy] = string_make(buf);
5332 tb->dirty_flags |= DIRTY_ALL;
5334 /* Expressions need re-evaluation */
5335 tb->dirty_flags |= DIRTY_EXPRESSION;
5337 /* Text is changed */
5346 /* Disable the selection */
5350 tb->dirty_flags |= DIRTY_ALL;
5354 tb->mark = MARK_MARK;
5356 /* Repeating this command swaps cursor position */
5357 if (com_id == tb->old_com_id)
5369 tb->dirty_flags |= DIRTY_ALL;
5373 int len = strlen(tb->lines_list[tb->cy]);
5375 /* Mark the point 1 */
5379 /* Correct cursor location */
5380 if (tb->cx > len) tb->mx = len;
5387 /* Kill rest of line */
5389 int len = strlen(tb->lines_list[tb->cy]);
5391 /* Correct cursor location */
5392 if (tb->cx > len) tb->cx = len;
5394 /* Ignore selection */
5400 tb->dirty_flags |= DIRTY_ALL;
5403 /* Append only if this command is repeated. */
5404 if (tb->old_com_id != com_id)
5406 kill_yank_chain(tb);
5410 /* Really deleted some text */
5413 /* Add deleted string to yank buffer */
5414 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5416 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5419 tb->dirty_line = tb->cy;
5421 /* Leave end of line character */
5425 /* Cut the end of line character only */
5426 if (tb->yank_eol) add_str_to_yank(tb, "");
5428 /* Cut end of line */
5429 tb->yank_eol = TRUE;
5431 do_editor_command(tb, EC_DELETE_CHAR);
5435 case EC_DELETE_CHAR:
5437 /* DELETE == go forward + BACK SPACE */
5441 /* Ignore selection */
5447 tb->dirty_flags |= DIRTY_ALL;
5451 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5455 /* Pass through the end of line to next line */
5456 len = strlen(tb->lines_list[tb->cy]);
5459 if (tb->lines_list[tb->cy + 1])
5471 do_editor_command(tb, EC_BACKSPACE);
5480 char buf[MAX_LINELEN];
5482 /* Ignore selection */
5488 tb->dirty_flags |= DIRTY_ALL;
5491 /* Move to correct collumn */
5492 len = strlen(tb->lines_list[tb->cy]);
5493 if (len < tb->cx) tb->cx = len;
5497 /* delete a return code and union two lines */
5498 if (tb->cy == 0) break;
5499 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5500 strcpy(buf, tb->lines_list[tb->cy-1]);
5501 strcat(buf, tb->lines_list[tb->cy]);
5502 string_free(tb->lines_list[tb->cy-1]);
5503 string_free(tb->lines_list[tb->cy]);
5504 tb->lines_list[tb->cy-1] = string_make(buf);
5506 for (i = tb->cy; tb->lines_list[i+1]; i++)
5507 tb->lines_list[i] = tb->lines_list[i+1];
5509 tb->lines_list[i] = NULL;
5513 tb->dirty_flags |= DIRTY_ALL;
5515 /* Expressions need re-evaluation */
5516 tb->dirty_flags |= DIRTY_EXPRESSION;
5518 /* Text is changed */
5524 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5528 if (iskanji(tb->lines_list[tb->cy][i]))
5529 buf[j++] = tb->lines_list[tb->cy][i++];
5531 buf[j++] = tb->lines_list[tb->cy][i];
5538 for (; tb->lines_list[tb->cy][i]; i++)
5539 buf[j++] = tb->lines_list[tb->cy][i];
5541 string_free(tb->lines_list[tb->cy]);
5542 tb->lines_list[tb->cy] = string_make(buf);
5545 tb->dirty_line = tb->cy;
5547 /* Expressions may need re-evaluation */
5548 check_expression_line(tb, tb->cy);
5550 /* Text is changed */
5560 /* Become dirty because of item/equip menu */
5561 tb->dirty_flags |= DIRTY_SCREEN;
5563 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5565 if (!search_dir) break;
5567 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5568 else do_editor_command(tb, EC_SEARCH_BACK);
5572 case EC_SEARCH_FORW:
5573 if (tb->search_o_ptr)
5575 search_for_object(tb, tb->search_o_ptr, TRUE);
5577 else if (tb->search_str && tb->search_str[0])
5579 search_for_string(tb, tb->search_str, TRUE);
5583 tb->dirty_flags |= DIRTY_NO_SEARCH;
5587 case EC_SEARCH_BACK:
5588 if (tb->search_o_ptr)
5590 search_for_object(tb, tb->search_o_ptr, FALSE);
5592 else if (tb->search_str && tb->search_str[0])
5594 search_for_string(tb, tb->search_str, FALSE);
5598 tb->dirty_flags |= DIRTY_NO_SEARCH;
5603 /* Become dirty because of item/equip menu */
5604 tb->dirty_flags |= DIRTY_SCREEN;
5606 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5608 do_editor_command(tb, EC_SEARCH_FORW);
5611 case EC_SEARCH_DESTROYED:
5612 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5614 /* There is no object to search */
5615 tb->dirty_flags |= DIRTY_NO_SEARCH;
5620 do_editor_command(tb, EC_SEARCH_FORW);
5623 case EC_INSERT_OBJECT:
5625 /* Insert choosen item name */
5627 autopick_type an_entry, *entry = &an_entry;
5629 if (!entry_from_choosed_object(entry))
5631 /* Now dirty because of item/equip menu */
5632 tb->dirty_flags |= DIRTY_SCREEN;
5637 insert_return_code(tb);
5638 string_free(tb->lines_list[tb->cy]);
5639 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5641 /* Now dirty because of item/equip menu */
5642 tb->dirty_flags |= DIRTY_SCREEN;
5647 case EC_INSERT_DESTROYED:
5648 /* Insert a name of last destroyed item */
5649 if (tb->last_destroyed)
5652 insert_return_code(tb);
5653 string_free(tb->lines_list[tb->cy]);
5654 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5657 tb->dirty_flags |= DIRTY_ALL;
5659 /* Text is changed */
5664 case EC_INSERT_BLOCK:
5666 /* Insert a conditinal expression line */
5667 char expression[80];
5669 /* Conditional Expression for Class and Race */
5670 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5672 rp_ptr->E_title, cp_ptr->E_title,
5674 rp_ptr->title, cp_ptr->title,
5680 insert_return_code(tb);
5681 string_free(tb->lines_list[tb->cy]);
5682 tb->lines_list[tb->cy] = string_make(expression);
5684 insert_return_code(tb);
5685 string_free(tb->lines_list[tb->cy]);
5686 tb->lines_list[tb->cy] = string_make("?:1");
5689 tb->dirty_flags |= DIRTY_ALL;
5691 /* Text is changed */
5697 case EC_INSERT_MACRO:
5698 /* Draw_everythig (delete menu) */
5699 draw_text_editor(tb);
5702 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5705 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
5706 if (insert_macro_line(tb))
5708 /* Prepare to input action */
5712 tb->dirty_flags |= DIRTY_ALL;
5714 /* Text is changed */
5720 case EC_INSERT_KEYMAP:
5721 /* Draw_everythig (delete menu) */
5722 draw_text_editor(tb);
5725 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5728 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
5729 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5731 if (insert_keymap_line(tb))
5733 /* Prepare to input action */
5737 tb->dirty_flags |= DIRTY_ALL;
5739 /* Text is changed */
5744 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5745 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5746 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5747 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5748 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5750 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5751 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5752 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5753 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5754 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5755 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5756 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5757 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5758 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5759 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5760 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5761 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5762 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5763 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5764 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5765 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5766 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5767 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5768 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5769 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5770 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5771 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5772 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5773 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5774 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5775 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5776 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5777 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5778 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5779 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5780 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5781 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5782 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5783 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5784 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5785 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5786 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5787 case EC_OK_UNREADABLE:
5788 toggle_keyword(tb, FLG_UNREADABLE);
5789 add_keyword(tb, FLG_SPELLBOOKS);
5792 toggle_keyword(tb, FLG_REALM1);
5793 add_keyword(tb, FLG_SPELLBOOKS);
5796 toggle_keyword(tb, FLG_REALM2);
5797 add_keyword(tb, FLG_SPELLBOOKS);
5800 toggle_keyword(tb, FLG_FIRST);
5801 add_keyword(tb, FLG_SPELLBOOKS);
5804 toggle_keyword(tb, FLG_SECOND);
5805 add_keyword(tb, FLG_SPELLBOOKS);
5808 toggle_keyword(tb, FLG_THIRD);
5809 add_keyword(tb, FLG_SPELLBOOKS);
5812 toggle_keyword(tb, FLG_FOURTH);
5813 add_keyword(tb, FLG_SPELLBOOKS);
5817 /* Save old command */
5818 tb->old_com_id = com_id;
5825 * Insert single letter at cursor position.
5827 static void insert_single_letter(text_body_type *tb, int key)
5830 char buf[MAX_LINELEN];
5832 /* Save preceding string */
5833 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5834 buf[j++] = tb->lines_list[tb->cy][i];
5836 /* Add a character */
5844 if (j+2 < MAX_LINELEN)
5846 buf[j++] = (char)key;
5847 buf[j++] = (char)next;
5856 if (j+1 < MAX_LINELEN)
5857 buf[j++] = (char)key;
5862 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5863 buf[j++] = tb->lines_list[tb->cy][i];
5866 /* Replace current line with new line */
5867 string_free(tb->lines_list[tb->cy]);
5868 tb->lines_list[tb->cy] = string_make(buf);
5870 /* Move to correct collumn */
5871 len = strlen(tb->lines_list[tb->cy]);
5872 if (len < tb->cx) tb->cx = len;
5875 tb->dirty_line = tb->cy;
5877 /* Expressions may need re-evaluation */
5878 check_expression_line(tb, tb->cy);
5880 /* Text is changed */
5886 * Check special key code and get a movement command id
5888 static int analyze_move_key(text_body_type *tb, int skey)
5892 /* Not a special key */
5893 if (!(skey & SKEY_MASK)) return 0;
5895 /* Convert from a special key code to an editor command */
5896 switch(skey & ~SKEY_MOD_MASK)
5898 case SKEY_DOWN: com_id = EC_DOWN; break;
5899 case SKEY_LEFT: com_id = EC_LEFT; break;
5900 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5901 case SKEY_UP: com_id = EC_UP; break;
5902 case SKEY_PGUP: com_id = EC_PGUP; break;
5903 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5904 case SKEY_TOP: com_id = EC_TOP; break;
5905 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5908 /* Not a special movement key */
5912 /* Without shift modifier */
5913 if (!(skey & SKEY_MOD_SHIFT))
5916 * Un-shifted cursor keys cancells
5917 * selection created by shift+cursor.
5919 if (tb->mark & MARK_BY_SHIFT)
5924 tb->dirty_flags |= DIRTY_ALL;
5928 /* With shift modifier */
5931 /* Start selection by shift + cursor keys */
5934 int len = strlen(tb->lines_list[tb->cy]);
5936 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5940 /* Correct cursor location */
5941 if (tb->cx > len) tb->mx = len;
5943 /* Need to redraw text */
5944 if (com_id == EC_UP || com_id == EC_DOWN)
5946 /* Redraw all text */
5947 tb->dirty_flags |= DIRTY_ALL;
5951 tb->dirty_line = tb->cy;
5960 * In-game editor of Object Auto-picker/Destoryer
5962 void do_cmd_edit_autopick(void)
5964 static int cx_save = 0;
5965 static int cy_save = 0;
5967 text_body_type text_body, *tb = &text_body;
5969 autopick_type an_entry, *entry = &an_entry;
5970 char buf[MAX_LINELEN];
5975 static s32b old_autosave_turn = 0L;
5978 tb->changed = FALSE;
5981 tb->upper = tb->left = 0;
5983 tb->mx = tb->my = 0;
5984 tb->old_cy = tb->old_upper = tb->old_left = -1;
5985 tb->old_wid = tb->old_hgt = -1;
5989 tb->search_o_ptr = NULL;
5990 tb->search_str = NULL;
5991 tb->last_destroyed = NULL;
5992 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5993 tb->dirty_line = -1;
5994 tb->filename_mode = PT_DEFAULT;
5996 if (turn < old_autosave_turn)
5998 while (old_autosave_turn > turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
6002 if (turn > old_autosave_turn + 100L)
6004 do_cmd_save_game(TRUE);
6005 old_autosave_turn = turn;
6008 /* HACK -- Reset start_time to stop counting playtime while edit */
6011 /* Free old entries */
6014 /* Command Description of the 'Last Destroyed Item' */
6015 if (autopick_last_destroyed_object.k_idx)
6017 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6018 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6021 /* Read or initialize whole text */
6022 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6024 /* Reset cursor position if needed */
6025 for (i = 0; i < tb->cy; i++)
6027 if (!tb->lines_list[i])
6029 tb->cy = tb->cx = 0;
6035 /* Process requests until done */
6040 /* Draw_everythig */
6041 draw_text_editor(tb);
6043 /* Display header line */
6044 prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)",
6045 "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0);
6048 /* Display current position */
6049 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6053 /* Display current position and mark position */
6054 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6058 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6061 tb->dirty_flags = 0;
6062 tb->dirty_line = -1;
6064 /* Save old key and location */
6065 tb->old_cy = tb->cy;
6066 tb->old_upper = tb->upper;
6067 tb->old_left = tb->left;
6068 tb->old_wid = tb->wid;
6069 tb->old_hgt = tb->hgt;
6071 key = inkey_special(TRUE);
6074 if (key & SKEY_MASK)
6076 /* Get a movement command */
6077 com_id = analyze_move_key(tb, key);
6081 else if (key == ESCAPE)
6083 com_id = do_command_menu(0, 0);
6085 /* Redraw all text later */
6086 tb->dirty_flags |= DIRTY_SCREEN;
6089 /* Insert a character */
6090 else if (!iscntrl((unsigned char)key))
6092 /* Ignore selection */
6098 tb->dirty_flags |= DIRTY_ALL;
6101 insert_single_letter(tb, key);
6107 /* Other commands */
6110 com_id = get_com_id((char)key);
6113 if (com_id) quit = do_editor_command(tb, com_id);
6114 } /* while (TRUE) */
6117 /* Get the filename of preference */
6118 strcpy(buf, pickpref_filename(tb->filename_mode));
6120 if (quit == QUIT_AND_SAVE)
6121 write_text_lines(buf, tb->lines_list);
6123 free_text_lines(tb->lines_list);
6125 string_free(tb->search_str);
6126 string_free(tb->last_destroyed);
6128 /* Destroy string chain */
6129 kill_yank_chain(tb);
6131 /* Reload autopick pref */
6132 process_autopick_file(buf);
6134 /* HACK -- reset start_time so that playtime is not increase while edit */
6135 start_time = (u32b)time(NULL);
6137 /* Save cursor location */