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"
17 #include "player-move.h"
18 #include "object-hook.h"
20 #define MAX_LINELEN 1024
27 #define FLG_UNIDENTIFIED 2
28 #define FLG_IDENTIFIED 3
29 #define FLG_STAR_IDENTIFIED 4
30 #define FLG_COLLECTING 5
31 #define FLG_ARTIFACT 6
34 #define FLG_NAMELESS 11
35 #define FLG_AVERAGE 12
36 #define FLG_WORTHLESS 13
39 #define FLG_BOOSTED 16
40 #define FLG_MORE_DICE 17
41 #define FLG_MORE_BONUS 18
45 #define FLG_UNREADABLE 22
54 #define FLG_WEAPONS 31
55 #define FLG_FAVORITE_WEAPONS 32
57 #define FLG_MISSILES 34
58 #define FLG_DEVICES 35
61 #define FLG_CORPSES 38
62 #define FLG_SPELLBOOKS 39
64 #define FLG_SHIELDS 41
67 #define FLG_AMULETS 44
74 #define FLG_NOUN_BEGIN FLG_ITEMS
75 #define FLG_NOUN_END FLG_BOOTS
79 static GAME_TEXT KEY_ALL[] = "すべての";
80 static GAME_TEXT KEY_UNAWARE[] = "未判明の";
81 static GAME_TEXT KEY_UNIDENTIFIED[] = "未鑑定の";
82 static GAME_TEXT KEY_IDENTIFIED[] = "鑑定済みの";
83 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*鑑定*済みの";
84 static GAME_TEXT KEY_COLLECTING[] = "収集中の";
85 static GAME_TEXT KEY_ARTIFACT[] = "アーティファクト";
86 static GAME_TEXT KEY_EGO[] = "エゴ";
87 static GAME_TEXT KEY_GOOD[] = "上質の";
88 static GAME_TEXT KEY_NAMELESS[] = "無銘の";
89 static GAME_TEXT KEY_AVERAGE[] = "並の";
90 static GAME_TEXT KEY_WORTHLESS[] = "無価値の";
91 static GAME_TEXT KEY_RARE[] = "レアな";
92 static GAME_TEXT KEY_COMMON[] = "ありふれた";
93 static GAME_TEXT KEY_BOOSTED[] = "ダイス目の違う";
94 static GAME_TEXT KEY_MORE_THAN[] = "ダイス目";
95 static GAME_TEXT KEY_DICE[] = "以上の";
96 static GAME_TEXT KEY_MORE_BONUS[] = "修正値";
97 static GAME_TEXT KEY_MORE_BONUS2[] = "以上の";
98 static GAME_TEXT KEY_WANTED[] = "賞金首の";
99 static GAME_TEXT KEY_UNIQUE[] = "ユニーク・モンスターの";
100 static GAME_TEXT KEY_HUMAN[] = "人間の";
101 static GAME_TEXT KEY_UNREADABLE[] = "読めない";
102 static GAME_TEXT KEY_REALM1[] = "第一領域の";
103 static GAME_TEXT KEY_REALM2[] = "第二領域の";
104 static GAME_TEXT KEY_FIRST[] = "1冊目の";
105 static GAME_TEXT KEY_SECOND[] = "2冊目の";
106 static GAME_TEXT KEY_THIRD[] = "3冊目の";
107 static GAME_TEXT KEY_FOURTH[] = "4冊目の";
108 static GAME_TEXT KEY_ITEMS[] = "アイテム";
109 static GAME_TEXT KEY_WEAPONS[] = "武器";
110 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "得意武器";
111 static GAME_TEXT KEY_ARMORS[] = "防具";
112 static GAME_TEXT KEY_MISSILES[] = "矢";
113 static GAME_TEXT KEY_DEVICES[] = "魔法アイテム";
114 static GAME_TEXT KEY_LIGHTS[] = "光源";
115 static GAME_TEXT KEY_JUNKS[] = "がらくた";
116 static GAME_TEXT KEY_CORPSES[] = "死体や骨";
117 static GAME_TEXT KEY_SPELLBOOKS[] = "魔法書";
118 static GAME_TEXT KEY_HAFTED[] = "鈍器";
119 static GAME_TEXT KEY_SHIELDS[] = "盾";
120 static GAME_TEXT KEY_BOWS[] = "弓";
121 static GAME_TEXT KEY_RINGS[] = "指輪";
122 static GAME_TEXT KEY_AMULETS[] = "アミュレット";
123 static GAME_TEXT KEY_SUITS[] = "鎧";
124 static GAME_TEXT KEY_CLOAKS[] = "クローク";
125 static GAME_TEXT KEY_HELMS[] = "兜";
126 static GAME_TEXT KEY_GLOVES[] = "籠手";
127 static GAME_TEXT KEY_BOOTS[] = "靴";
131 static GAME_TEXT KEY_ALL[] = "all";
132 static GAME_TEXT KEY_UNAWARE[] = "unaware";
133 static GAME_TEXT KEY_UNIDENTIFIED[] = "unidentified";
134 static GAME_TEXT KEY_IDENTIFIED[] = "identified";
135 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*identified*";
136 static GAME_TEXT KEY_COLLECTING[] = "collecting";
137 static GAME_TEXT KEY_ARTIFACT[] = "artifact";
138 static GAME_TEXT KEY_EGO[] = "ego";
139 static GAME_TEXT KEY_GOOD[] = "good";
140 static GAME_TEXT KEY_NAMELESS[] = "nameless";
141 static GAME_TEXT KEY_AVERAGE[] = "average";
142 static GAME_TEXT KEY_WORTHLESS[] = "worthless";
143 static GAME_TEXT KEY_RARE[] = "rare";
144 static GAME_TEXT KEY_COMMON[] = "common";
145 static GAME_TEXT KEY_BOOSTED[] = "dice boosted";
146 static GAME_TEXT KEY_MORE_THAN[] = "more than";
147 static GAME_TEXT KEY_DICE[] = " dice";
148 static GAME_TEXT KEY_MORE_BONUS[] = "more bonus than";
149 static GAME_TEXT KEY_MORE_BONUS2[] = "";
150 static GAME_TEXT KEY_WANTED[] = "wanted";
151 static GAME_TEXT KEY_UNIQUE[] = "unique monster's";
152 static GAME_TEXT KEY_HUMAN[] = "human";
153 static GAME_TEXT KEY_UNREADABLE[] = "unreadable";
154 static GAME_TEXT KEY_REALM1[] = "first realm's";
155 static GAME_TEXT KEY_REALM2[] = "second realm's";
156 static GAME_TEXT KEY_FIRST[] = "first";
157 static GAME_TEXT KEY_SECOND[] = "second";
158 static GAME_TEXT KEY_THIRD[] = "third";
159 static GAME_TEXT KEY_FOURTH[] = "fourth";
160 static GAME_TEXT KEY_ITEMS[] = "items";
161 static GAME_TEXT KEY_WEAPONS[] = "weapons";
162 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "favorite weapons";
163 static GAME_TEXT KEY_ARMORS[] = "armors";
164 static GAME_TEXT KEY_MISSILES[] = "missiles";
165 static GAME_TEXT KEY_DEVICES[] = "magical devices";
166 static GAME_TEXT KEY_LIGHTS[] = "lights";
167 static GAME_TEXT KEY_JUNKS[] = "junks";
168 static GAME_TEXT KEY_CORPSES[] = "corpses or skeletons";
169 static GAME_TEXT KEY_SPELLBOOKS[] = "spellbooks";
170 static GAME_TEXT KEY_HAFTED[] = "hafted weapons";
171 static GAME_TEXT KEY_SHIELDS[] = "shields";
172 static GAME_TEXT KEY_BOWS[] = "bows";
173 static GAME_TEXT KEY_RINGS[] = "rings";
174 static GAME_TEXT KEY_AMULETS[] = "amulets";
175 static GAME_TEXT KEY_SUITS[] = "suits";
176 static GAME_TEXT KEY_CLOAKS[] = "cloaks";
177 static GAME_TEXT KEY_HELMS[] = "helms";
178 static GAME_TEXT KEY_GLOVES[] = "gloves";
179 static GAME_TEXT KEY_BOOTS[] = "boots";
183 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
184 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
185 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
186 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
189 #define ADD_KEY(KEY) strcat(ptr, KEY)
191 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
193 #define ADD_KEY2(KEY) strcat(ptr, KEY)
195 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
196 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
197 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
198 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
201 static char kanji_colon[] = ":";
206 * A function to create new entry
208 static bool autopick_new_entry(autopick_type *entry, concptr str, bool allow_default)
213 char buf[MAX_LINELEN];
214 concptr prev_ptr, ptr, old_ptr;
217 if (str[0] && str[1] == ':') switch (str[0])
220 case 'A': case 'P': case 'C':
224 entry->flag[0] = entry->flag[1] = 0L;
228 act = DO_AUTOPICK | DO_DISPLAY;
231 if ((act & DO_AUTOPICK) && *str == '!')
234 act |= DO_AUTODESTROY;
237 else if ((act & DO_AUTOPICK) && *str == '~')
240 act |= DONT_AUTOPICK;
243 else if ((act & DO_AUTOPICK) && *str == ';')
246 act |= DO_QUERY_AUTOPICK;
249 else if ((act & DO_DISPLAY) && *str == '(')
258 /* don't mind upper or lower case */
260 for (i = 0; *str; i++)
271 /* Auto-inscription? */
279 if (isupper(c)) c = (char)tolower(c);
285 /* Skip empty line unless allow_default */
286 if (!allow_default && *buf == 0) return FALSE;
288 /* Skip comment line */
289 if (*buf == 0 && insc) return FALSE;
291 ptr = prev_ptr = buf;
294 while (old_ptr != ptr)
296 /* Save current location */
299 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
300 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
301 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
302 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
303 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
304 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
305 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
307 /*** Weapons whose dd*ds is more than nn ***/
308 if (MATCH_KEY2(KEY_MORE_THAN))
313 /* Drop leading spaces */
314 while (' ' == *ptr) ptr++;
317 while ('0' <= *ptr && *ptr <= '9')
319 entry->dice = 10 * entry->dice + (*ptr - '0');
326 (void)MATCH_KEY(KEY_DICE);
327 ADD_FLG(FLG_MORE_DICE);
333 /*** Items whose magical bonus is more than n ***/
334 if (MATCH_KEY2(KEY_MORE_BONUS))
339 /* Drop leading spaces */
340 while (' ' == *ptr) ptr++;
343 while ('0' <= *ptr && *ptr <= '9')
345 entry->bonus = 10 * entry->bonus + (*ptr - '0');
353 (void)MATCH_KEY(KEY_MORE_BONUS2);
355 if (' ' == *ptr) ptr++;
357 ADD_FLG(FLG_MORE_BONUS);
363 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
364 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
365 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
366 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
367 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
368 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
369 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
370 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
371 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
372 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
373 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
374 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
375 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
376 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
377 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
378 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
379 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
382 /* Not yet found any noun */
385 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
387 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
388 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
389 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
390 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
391 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
392 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
393 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
394 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
395 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
396 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
397 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
398 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
399 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
400 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
401 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
402 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
403 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
404 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
405 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
406 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
408 /* Last 'keyword' must be at the correct location */
412 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
415 else if (*ptr == '\0')
417 /* There was no noun */
420 /* Add extra word "items" */
421 ADD_FLG_NOUN(FLG_ITEMS);
428 /* A noun type keyword didn't end correctly */
429 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
434 /* Save this auto-picker entry line */
435 entry->name = string_make(ptr);
437 entry->insc = string_make(insc);
444 * Get auto-picker entry from o_ptr.
446 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
448 /* Assume that object name is to be added */
452 /* エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない */
453 bool bol_mark = FALSE;
455 /* We can always use the ^ mark in English */
456 bool bol_mark = TRUE;
459 GAME_TEXT name_str[MAX_NLEN];
461 /* Initialize name string */
464 entry->insc = string_make(quark_str(o_ptr->inscription));
465 entry->action = DO_AUTOPICK | DO_DISPLAY;
466 entry->flag[0] = entry->flag[1] = 0L;
470 if (!object_is_aware(o_ptr))
472 ADD_FLG(FLG_UNAWARE);
476 /* Not really identified */
477 else if (!object_is_known(o_ptr))
479 if (!(o_ptr->ident & IDENT_SENSE))
481 ADD_FLG(FLG_UNIDENTIFIED);
486 /* Pseudo-identified */
487 switch (o_ptr->feeling)
491 ADD_FLG(FLG_NAMELESS);
497 ADD_FLG(FLG_NAMELESS);
498 ADD_FLG(FLG_WORTHLESS);
504 ADD_FLG(FLG_WORTHLESS);
512 /* XXX No appropriate flag */
517 /* Never reach here */
527 if (object_is_ego(o_ptr))
529 if (object_is_weapon_armour_ammo(o_ptr))
532 * Base name of ego weapons and armors
533 * are almost meaningless.
534 * Register the ego type only.
536 ego_item_type *e_ptr = &e_info[o_ptr->name2];
538 /* エゴ銘には「^」マークが使える */
539 sprintf(name_str, "^%s", e_name + e_ptr->name);
541 /* We ommit the basename and cannot use the ^ mark */
542 strcpy(name_str, e_name + e_ptr->name);
545 /* Don't use the object description */
548 /* Restrict to 'common' equipments */
549 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
556 else if (object_is_artifact(o_ptr))
557 ADD_FLG(FLG_ARTIFACT);
559 /* Non-ego, non-artifact */
562 /* Wearable nameless object */
563 if (object_is_equipment(o_ptr))
564 ADD_FLG(FLG_NAMELESS);
571 /* Melee weapon with boosted dice */
572 if (object_is_melee_weapon(o_ptr))
574 object_kind *k_ptr = &k_info[o_ptr->k_idx];
576 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
577 ADD_FLG(FLG_BOOSTED);
580 /* Wanted monster's corpse */
581 if (object_is_shoukinkubi(o_ptr))
583 REM_FLG(FLG_WORTHLESS);
587 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
588 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
593 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
598 if (o_ptr->tval >= TV_LIFE_BOOK &&
599 !check_book_realm(o_ptr->tval, o_ptr->sval))
601 ADD_FLG(FLG_UNREADABLE);
602 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
605 if (REALM1_BOOK == o_ptr->tval &&
606 p_ptr->pclass != CLASS_SORCERER &&
607 p_ptr->pclass != CLASS_RED_MAGE)
613 if (REALM2_BOOK == o_ptr->tval &&
614 p_ptr->pclass != CLASS_SORCERER &&
615 p_ptr->pclass != CLASS_RED_MAGE)
621 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
623 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
625 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
627 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
630 if (object_is_ammo(o_ptr))
631 ADD_FLG(FLG_MISSILES);
632 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
633 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
634 ADD_FLG(FLG_DEVICES);
635 else if (o_ptr->tval == TV_LITE)
637 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
638 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
640 else if (o_ptr->tval == TV_CORPSE)
641 ADD_FLG(FLG_CORPSES);
642 else if (o_ptr->tval >= TV_LIFE_BOOK)
643 ADD_FLG(FLG_SPELLBOOKS);
644 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
645 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
646 ADD_FLG(FLG_WEAPONS);
647 else if (o_ptr->tval == TV_SHIELD)
648 ADD_FLG(FLG_SHIELDS);
649 else if (o_ptr->tval == TV_BOW)
651 else if (o_ptr->tval == TV_RING)
653 else if (o_ptr->tval == TV_AMULET)
654 ADD_FLG(FLG_AMULETS);
655 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
656 o_ptr->tval == TV_SOFT_ARMOR)
658 else if (o_ptr->tval == TV_CLOAK)
660 else if (o_ptr->tval == TV_HELM)
662 else if (o_ptr->tval == TV_GLOVES)
664 else if (o_ptr->tval == TV_BOOTS)
667 /* Prepare the object description */
670 GAME_TEXT o_name[MAX_NLEN];
672 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
675 * If necessary, add a '^' which indicates the
678 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
681 /* Register the name in lowercase */
682 str_tolower(name_str);
683 entry->name = string_make(name_str);
690 * A function to delete entry
692 static void autopick_free_entry(autopick_type *entry)
694 string_free(entry->name);
695 string_free(entry->insc);
701 #define MAX_AUTOPICK_DEFAULT 200
704 * Initialize the autopick
706 static void init_autopick(void)
708 static const char easy_autopick_inscription[] = "(:=g";
714 max_max_autopick = MAX_AUTOPICK_DEFAULT;
715 C_MAKE(autopick_list, max_max_autopick, autopick_type);
719 /* Clear old entries */
720 for( i = 0; i < max_autopick; i++)
721 autopick_free_entry(&autopick_list[i]);
725 /* There is always one entry "=g" */
726 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
727 autopick_list[max_autopick++] = entry;
732 #define PT_WITH_PNAME 1
735 * Get file name for autopick preference
737 static concptr pickpref_filename(int filename_mode)
739 static const char namebase[] = _("picktype", "pickpref");
741 switch (filename_mode)
744 return format("%s.prf", namebase);
747 return format("%s-%s.prf", namebase, player_base);
756 * Load an autopick preference file
758 void autopick_load_pref(bool disp_mes)
763 /* Free old entries */
766 /* Try a filename with player name */
767 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
770 err = process_autopick_file(buf);
772 if (err == 0 && disp_mes)
775 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
781 /* Use default name */
782 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
785 err = process_autopick_file(buf);
787 if (err == 0 && disp_mes)
790 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
797 msg_print(_("自動拾い設定ファイルの読み込みに失敗しました。", "Failed to reload autopick preference."));
803 * Add one line to autopick_list[]
805 static void add_autopick_list(autopick_type *entry)
807 /* There is no enough space to add one line */
808 if (max_autopick >= max_max_autopick)
810 int old_max_max_autopick = max_max_autopick;
811 autopick_type *old_autopick_list = autopick_list;
813 /* Increase size of list */
814 max_max_autopick += MAX_AUTOPICK_DEFAULT;
817 C_MAKE(autopick_list, max_max_autopick, autopick_type);
819 /* Copy from old list to new list */
820 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
823 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
827 autopick_list[max_autopick] = *entry;
834 * Process line for auto picker/destroyer.
836 errr process_autopick_file_command(char *buf)
838 autopick_type an_entry, *entry = &an_entry;
841 /* Nuke illegal char */
842 for(i = 0; buf[i]; i++)
851 if (iswspace(buf[i]) && buf[i] != ' ')
856 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
858 /* Already has the same entry? */
859 for(i = 0; i < max_autopick; i++)
860 if(!strcmp(entry->name, autopick_list[i].name)
861 && entry->flag[0] == autopick_list[i].flag[0]
862 && entry->flag[1] == autopick_list[i].flag[1]
863 && entry->dice == autopick_list[i].dice
864 && entry->bonus == autopick_list[i].bonus)
866 autopick_free_entry(entry);
870 add_autopick_list(entry);
876 * Reconstruct preference line from entry
878 concptr autopick_line_from_entry(autopick_type *entry)
880 char buf[MAX_LINELEN];
882 bool sepa_flag = TRUE;
885 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
886 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
887 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
888 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
892 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
893 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
894 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
895 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
896 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
897 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
898 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
900 if (IS_FLG(FLG_MORE_DICE))
902 ADD_KEY(KEY_MORE_THAN);
903 strcat(ptr, format("%d", entry->dice));
907 if (IS_FLG(FLG_MORE_BONUS))
909 ADD_KEY(KEY_MORE_BONUS);
910 strcat(ptr, format("%d", entry->bonus));
911 ADD_KEY(KEY_MORE_BONUS2);
914 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
915 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
916 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
917 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
918 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
919 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
920 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
921 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
922 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
923 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
924 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
925 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
926 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
927 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
928 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
929 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
930 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
932 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
934 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
935 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
936 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
937 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
938 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
939 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
940 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
941 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
942 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
943 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
944 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
945 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
946 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
947 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
948 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
949 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
950 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
951 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
952 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
953 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
955 /* You don't need sepalator after adjective */
956 /* 'artifact' is not true adjective */
957 else if (!IS_FLG(FLG_ARTIFACT))
960 if (entry->name && entry->name[0])
964 if (sepa_flag) strcat(buf, ":");
967 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
970 if (iskanji(entry->name[j]))
971 buf[i++] = entry->name[j++];
973 buf[i++] = entry->name[j++];
984 while (entry->insc[j] && i < MAX_LINELEN - 2)
987 if (iskanji(entry->insc[j]))
988 buf[i++] = entry->insc[j++];
990 buf[i++] = entry->insc[j++];
995 return string_make(buf);
1000 * Reconstruct preference line from entry and kill entry
1002 static concptr autopick_line_from_entry_kill(autopick_type *entry)
1004 concptr ptr = autopick_line_from_entry(entry);
1006 /* Free memory for original entry */
1007 autopick_free_entry(entry);
1014 * A function for Auto-picker/destroyer
1015 * Examine whether the object matches to the entry
1017 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_name)
1020 concptr ptr = entry->name;
1022 /*** Unaware items ***/
1023 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1026 /*** Unidentified ***/
1027 if (IS_FLG(FLG_UNIDENTIFIED)
1028 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1031 /*** Identified ***/
1032 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1035 /*** *Identified* ***/
1036 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1037 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1040 /*** Dice boosted (weapon of slaying) ***/
1041 if (IS_FLG(FLG_BOOSTED))
1043 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1045 /* Require melee weapon */
1046 if (!object_is_melee_weapon(o_ptr))
1049 /* Require boosted dice */
1050 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1053 /* In Vault Quest, Dice must be hide.*/
1054 if(!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
1060 /*** Weapons which dd*ds is more than nn ***/
1061 if (IS_FLG(FLG_MORE_DICE))
1063 if (o_ptr->dd * o_ptr->ds < entry->dice)
1067 /*** Weapons whic dd*ds is more than nn ***/
1068 if (IS_FLG(FLG_MORE_BONUS))
1070 if (!object_is_known(o_ptr)) return FALSE;
1074 if (o_ptr->pval < entry->bonus) return FALSE;
1078 if (o_ptr->to_h < entry->bonus &&
1079 o_ptr->to_d < entry->bonus &&
1080 o_ptr->to_a < entry->bonus &&
1081 o_ptr->pval < entry->bonus)
1086 /*** Worthless items ***/
1087 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1090 /*** Artifact object ***/
1091 if (IS_FLG(FLG_ARTIFACT))
1093 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1097 /*** Ego object ***/
1098 if (IS_FLG(FLG_EGO))
1100 /* Need to be an ego item */
1101 if (!object_is_ego(o_ptr)) return FALSE;
1103 /* Need to be known to be an ego */
1104 if (!object_is_known(o_ptr) &&
1105 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1110 if (IS_FLG(FLG_GOOD))
1112 if (!object_is_equipment(o_ptr)) return FALSE;
1115 if (object_is_known(o_ptr))
1117 /* Artifacts and Ego objects are not okay */
1118 if (!object_is_nameless(o_ptr))
1121 /* Average are not okay */
1122 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1126 /* Pseudo-identified */
1127 else if (o_ptr->ident & IDENT_SENSE)
1129 switch (o_ptr->feeling)
1144 /* Not known to be good */
1150 if (IS_FLG(FLG_NAMELESS))
1152 if (!object_is_equipment(o_ptr)) return FALSE;
1155 if (object_is_known(o_ptr))
1157 /* Artifacts and Ego objects are not okay */
1158 if (!object_is_nameless(o_ptr))
1162 /* Pseudo-identified */
1163 else if (o_ptr->ident & IDENT_SENSE)
1165 switch (o_ptr->feeling)
1175 /* It's not nameless */
1183 /* Not known to be nameless */
1189 if (IS_FLG(FLG_AVERAGE))
1191 if (!object_is_equipment(o_ptr)) return FALSE;
1194 if (object_is_known(o_ptr))
1196 /* Artifacts and Ego objects are not okay */
1197 if (!object_is_nameless(o_ptr))
1200 /* Cursed or broken objects are not okay */
1201 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1204 /* Good are not okay */
1205 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1209 /* Pseudo-identified */
1210 else if (o_ptr->ident & IDENT_SENSE)
1212 switch (o_ptr->feeling)
1219 /* It's not average */
1227 /* Not known to be average */
1232 /*** Rere equipments ***/
1233 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1236 /*** Common equipments ***/
1237 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1240 /*** Wanted monster's corpse/skeletons ***/
1241 if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
1244 /*** Unique monster's corpse/skeletons/statues ***/
1245 if (IS_FLG(FLG_UNIQUE) &&
1246 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1247 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1250 /*** Human corpse/skeletons (for Daemon magic) ***/
1251 if (IS_FLG(FLG_HUMAN) &&
1252 (o_ptr->tval != TV_CORPSE ||
1253 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1256 /*** Unreadable spellbooks ***/
1257 if (IS_FLG(FLG_UNREADABLE) &&
1258 (o_ptr->tval < TV_LIFE_BOOK ||
1259 check_book_realm(o_ptr->tval, o_ptr->sval)))
1262 /*** First realm spellbooks ***/
1263 if (IS_FLG(FLG_REALM1) &&
1264 (REALM1_BOOK != o_ptr->tval ||
1265 p_ptr->pclass == CLASS_SORCERER ||
1266 p_ptr->pclass == CLASS_RED_MAGE))
1269 /*** Second realm spellbooks ***/
1270 if (IS_FLG(FLG_REALM2) &&
1271 (REALM2_BOOK != o_ptr->tval ||
1272 p_ptr->pclass == CLASS_SORCERER ||
1273 p_ptr->pclass == CLASS_RED_MAGE))
1276 /*** First rank spellbooks ***/
1277 if (IS_FLG(FLG_FIRST) &&
1278 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1281 /*** Second rank spellbooks ***/
1282 if (IS_FLG(FLG_SECOND) &&
1283 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1286 /*** Third rank spellbooks ***/
1287 if (IS_FLG(FLG_THIRD) &&
1288 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1291 /*** Fourth rank spellbooks ***/
1292 if (IS_FLG(FLG_FOURTH) &&
1293 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1297 if (IS_FLG(FLG_WEAPONS))
1299 if (!object_is_weapon(o_ptr))
1302 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1304 if (!object_is_favorite(o_ptr))
1307 else if (IS_FLG(FLG_ARMORS))
1309 if (!object_is_armour(o_ptr))
1312 else if (IS_FLG(FLG_MISSILES))
1314 if (!object_is_ammo(o_ptr)) return FALSE;
1316 else if (IS_FLG(FLG_DEVICES))
1320 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1322 default: return FALSE;
1325 else if (IS_FLG(FLG_LIGHTS))
1327 if (!(o_ptr->tval == TV_LITE))
1330 else if (IS_FLG(FLG_JUNKS))
1334 case TV_SKELETON: case TV_BOTTLE:
1335 case TV_JUNK: case TV_STATUE:
1337 default: return FALSE;
1340 else if (IS_FLG(FLG_CORPSES))
1342 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1345 else if (IS_FLG(FLG_SPELLBOOKS))
1347 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1350 else if (IS_FLG(FLG_HAFTED))
1352 if (!(o_ptr->tval == TV_HAFTED))
1355 else if (IS_FLG(FLG_SHIELDS))
1357 if (!(o_ptr->tval == TV_SHIELD))
1360 else if (IS_FLG(FLG_BOWS))
1362 if (!(o_ptr->tval == TV_BOW))
1365 else if (IS_FLG(FLG_RINGS))
1367 if (!(o_ptr->tval == TV_RING))
1370 else if (IS_FLG(FLG_AMULETS))
1372 if (!(o_ptr->tval == TV_AMULET))
1375 else if (IS_FLG(FLG_SUITS))
1377 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1378 o_ptr->tval == TV_HARD_ARMOR ||
1379 o_ptr->tval == TV_SOFT_ARMOR))
1382 else if (IS_FLG(FLG_CLOAKS))
1384 if (!(o_ptr->tval == TV_CLOAK))
1387 else if (IS_FLG(FLG_HELMS))
1389 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1392 else if (IS_FLG(FLG_GLOVES))
1394 if (!(o_ptr->tval == TV_GLOVES))
1397 else if (IS_FLG(FLG_BOOTS))
1399 if (!(o_ptr->tval == TV_BOOTS))
1403 /* Keyword don't match */
1407 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1411 if (!my_strstr(o_name, ptr)) return FALSE;
1414 /* TRUE when it need not to be 'collecting' */
1415 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1417 /* Check if there is a same item */
1418 for (j = 0; j < INVEN_PACK; j++)
1421 * 'Collecting' means the item must be absorbed
1422 * into an inventory slot.
1423 * But an item can not be absorbed into itself!
1425 if ((&inventory[j] != o_ptr) &&
1426 object_similar(&inventory[j], o_ptr))
1430 /* Not collecting */
1436 * A function for Auto-picker/destroyer
1437 * Examine whether the object matches to the list of keywords or not.
1439 int is_autopick(object_type *o_ptr)
1442 GAME_TEXT o_name[MAX_NLEN];
1444 if (o_ptr->tval == TV_GOLD) return -1;
1446 /* Prepare object name string first */
1447 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1449 /* Convert the string to lower case */
1450 str_tolower(o_name);
1452 /* Look for a matching entry in the list */
1453 for (i=0; i < max_autopick; i++)
1455 autopick_type *entry = &autopick_list[i];
1457 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1460 /* No matching entry */
1468 static void auto_inscribe_item(object_type *o_ptr, int idx)
1470 /* Are there auto-inscription? */
1471 if (idx < 0 || !autopick_list[idx].insc) return;
1473 if (!o_ptr->inscription)
1474 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1476 /* Redraw inscription */
1477 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1479 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1480 p_ptr->update |= (PU_BONUS);
1485 * Automatically destroy items in this grid.
1487 static bool is_opt_confirm_destroy(object_type *o_ptr)
1489 if (!destroy_items) return FALSE;
1491 /* Known to be worthless? */
1493 if (object_value(o_ptr) > 0) return FALSE;
1496 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1499 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1503 if (object_is_shoukinkubi(o_ptr)) return FALSE;
1507 if (o_ptr->tval == TV_CORPSE) return FALSE;
1510 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1514 if (p_ptr->prace == RACE_DEMON)
1516 if (o_ptr->tval == TV_CORPSE &&
1517 o_ptr->sval == SV_CORPSE &&
1518 my_strchr("pht", r_info[o_ptr->pval].d_char))
1522 if (p_ptr->pclass == CLASS_ARCHER)
1524 if (o_ptr->tval == TV_SKELETON ||
1525 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1528 else if (p_ptr->pclass == CLASS_NINJA)
1530 if (o_ptr->tval == TV_LITE &&
1531 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1534 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1535 p_ptr->pclass == CLASS_CAVALRY)
1537 if (o_ptr->tval == TV_WAND &&
1538 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1543 if (o_ptr->tval == TV_GOLD) return FALSE;
1550 * Automatically destroy an item if it is to be destroyed
1552 * When always_pickup is 'yes', we disable auto-destroyer function of
1553 * auto-picker/destroyer, and do only easy-auto-destroyer.
1555 static object_type autopick_last_destroyed_object;
1557 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1559 bool destroy = FALSE;
1561 /* Easy-Auto-Destroyer (3rd priority) */
1562 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1564 /* Protected by auto-picker (2nd priotity) */
1565 if (autopick_idx >= 0 &&
1566 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1569 /* Auto-destroyer works only when !always_pickup */
1572 /* Auto-picker/destroyer (1st priority) */
1573 if (autopick_idx >= 0 &&
1574 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1578 /* Not to be destroyed */
1579 if (!destroy) return;
1581 /* Now decided to destroy */
1583 disturb(FALSE, FALSE);
1586 if (!can_player_destroy_object(o_ptr))
1588 GAME_TEXT o_name[MAX_NLEN];
1590 /* Describe the object (with {terrible/special}) */
1591 object_desc(o_name, o_ptr, 0);
1593 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1598 /* Record name of destroyed item */
1599 (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1602 o_ptr->marked |= OM_AUTODESTROY;
1603 p_ptr->update |= PU_AUTODESTROY;
1610 * Auto-destroy marked item
1612 static void autopick_delayed_alter_aux(INVENTORY_IDX item)
1616 /* Get the item (in the pack) */
1617 if (item >= 0) o_ptr = &inventory[item];
1619 /* Get the item (on the floor) */
1620 else o_ptr = ¤t_floor_ptr->o_list[0 - item];
1622 if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
1624 GAME_TEXT o_name[MAX_NLEN];
1626 /* Describe the object (with {terrible/special}) */
1627 object_desc(o_name, o_ptr, 0);
1629 /* Eliminate the item (from the pack) */
1632 inven_item_increase(item, -(o_ptr->number));
1633 inven_item_optimize(item);
1636 /* Eliminate the item (from the floor) */
1639 delete_object_idx(0 - item);
1642 msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name);
1648 * Auto-destroy marked items in inventry and on floor
1650 void autopick_delayed_alter(void)
1655 * Scan inventry in reverse order to prevent
1656 * skipping after inven_item_optimize()
1658 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1659 autopick_delayed_alter_aux(item);
1661 /* Scan the pile of objects */
1662 item = current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx;
1665 OBJECT_IDX next = current_floor_ptr->o_list[item].next_o_idx;
1666 autopick_delayed_alter_aux(-item);
1673 * Auto-inscription and/or destroy
1675 * Auto-destroyer works only on inventory or on floor stack only when
1678 void autopick_alter_item(INVENTORY_IDX item, bool destroy)
1683 /* Get the item (in the pack) */
1684 if (item >= 0) o_ptr = &inventory[item];
1686 /* Get the item (on the floor) */
1687 else o_ptr = ¤t_floor_ptr->o_list[0 - item];
1689 /* Get the index in the auto-pick/destroy list */
1690 idx = is_autopick(o_ptr);
1692 /* Do auto-inscription */
1693 auto_inscribe_item(o_ptr, idx);
1695 /* Do auto-destroy if needed */
1696 if (destroy && item <= INVEN_PACK)
1697 auto_destroy_item(o_ptr, idx);
1702 * Automatically pickup/destroy items in this grid.
1704 void autopick_pickup_items(grid_type *g_ptr)
1706 OBJECT_IDX this_o_idx, next_o_idx = 0;
1708 /* Scan the pile of objects */
1709 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1712 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
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;
1906 int match_autopick = is_autopick(o_ptr);
1908 /* Already registered */
1909 if (match_autopick != -1)
1912 byte act = autopick_list[match_autopick].action;
1914 if (act & DO_AUTOPICK) what = _("自動で拾う", "auto-pickup");
1915 else if (act & DO_AUTODESTROY) what = _("自動破壊する", "auto-destroy");
1916 else if (act & DONT_AUTOPICK) what = _("放置する", "leave on floor");
1917 else /* if (act & DO_QUERY_AUTOPICK) */ what = _("確認して拾う", "query auto-pickup");
1919 msg_format(_("そのアイテムは既に%sように設定されています。", "The object is already registered to %s."), what);
1923 /* Known to be an artifact? */
1924 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1925 ((o_ptr->ident & IDENT_SENSE) &&
1926 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1928 GAME_TEXT o_name[MAX_NLEN];
1930 /* Describe the object (with {terrible/special}) */
1931 object_desc(o_name, o_ptr, 0);
1933 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1939 if (!p_ptr->autopick_autoregister)
1941 /* Clear old auto registered lines */
1942 if (!clear_auto_register()) return FALSE;
1945 /* Try a filename with player name */
1946 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1947 pref_fff = my_fopen(pref_file, "r");
1951 /* Use default name */
1952 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1953 pref_fff = my_fopen(pref_file, "r");
1956 /* Check the header */
1961 if (my_fgets(pref_fff, buf, sizeof(buf)))
1963 /* No header found */
1964 p_ptr->autopick_autoregister = FALSE;
1969 if (streq(buf, autoregister_header))
1971 /* Found the header */
1972 p_ptr->autopick_autoregister = TRUE;
1978 /* Close read only FILE* */
1984 * File could not be opened for reading. Assume header not
1987 p_ptr->autopick_autoregister = FALSE;
1990 /* Open for append */
1991 pref_fff = my_fopen(pref_file, "a");
1995 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), pref_file);
2002 if (!p_ptr->autopick_autoregister)
2004 /* Add the header */
2005 fprintf(pref_fff, "%s\n", autoregister_header);
2007 fprintf(pref_fff, "%s\n", _("# *警告!!* 以降の行は自動登録されたものです。",
2008 "# *Warning!* The lines below will be deleted later."));
2009 fprintf(pref_fff, "%s\n", _("# 後で自動的に削除されますので、必要な行は上の方へ移動しておいてください。",
2010 "# Keep it by cut & paste if you need these lines for future characters."));
2012 /* Now auto register is in-use */
2013 p_ptr->autopick_autoregister = TRUE;
2016 /* Get a preference entry */
2017 autopick_entry_from_object(entry, o_ptr);
2019 /* Set to auto-destroy (with no-display) */
2020 entry->action = DO_AUTODESTROY;
2022 /* Load the new line as preference */
2023 add_autopick_list(entry);
2025 /* Add a line to the file */
2026 /* Don't kill "entry" */
2027 tmp = autopick_line_from_entry(entry);
2028 fprintf(pref_fff, "%s\n", tmp);
2036 /******** Auto-picker/destroyer editor **********/
2038 #define MAX_YANK MAX_LINELEN
2039 #define MAX_LINES 3000
2041 #define MARK_MARK 0x01
2042 #define MARK_BY_SHIFT 0x02
2044 #define LSTAT_BYPASS 0x01
2045 #define LSTAT_EXPRESSION 0x02
2046 #define LSTAT_AUTOREGISTER 0x04
2048 #define QUIT_WITHOUT_SAVE 1
2049 #define QUIT_AND_SAVE 2
2052 * Struct for yank buffer
2054 typedef struct chain_str {
2055 struct chain_str *next;
2061 * Data struct for text editor
2067 int old_wid, old_hgt;
2069 int old_upper, old_left;
2073 object_type *search_o_ptr;
2075 concptr last_destroyed;
2077 chain_str_type *yank;
2080 concptr *lines_list;
2081 byte states[MAX_LINES];
2093 * Dirty flag for text editor
2095 #define DIRTY_ALL 0x0001
2096 #define DIRTY_MODE 0x0004
2097 #define DIRTY_SCREEN 0x0008
2098 #define DIRTY_NOT_FOUND 0x0010
2099 #define DIRTY_NO_SEARCH 0x0020
2100 #define DIRTY_EXPRESSION 0x0040
2101 #define DIRTY_SKIP_INACTIVE 0x0080
2102 #define DIRTY_INACTIVE 0x0100
2105 * Describe which kind of object is Auto-picked/destroyed
2107 static void describe_autopick(char *buff, autopick_type *entry)
2109 concptr str = entry->name;
2110 byte act = entry->action;
2111 concptr insc = entry->insc;
2117 concptr before_str[100], body_str;
2122 /*** Collecting items ***/
2123 /*** Which can be absorbed into a slot as a bundle ***/
2124 if (IS_FLG(FLG_COLLECTING))
2125 before_str[before_n++] = "収集中で既に持っているスロットにまとめられる";
2127 /*** Unaware items ***/
2128 if (IS_FLG(FLG_UNAWARE))
2129 before_str[before_n++] = "未鑑定でその効果も判明していない";
2131 /*** Unidentified ***/
2132 if (IS_FLG(FLG_UNIDENTIFIED))
2133 before_str[before_n++] = "未鑑定の";
2135 /*** Identified ***/
2136 if (IS_FLG(FLG_IDENTIFIED))
2137 before_str[before_n++] = "鑑定済みの";
2139 /*** *Identified* ***/
2140 if (IS_FLG(FLG_STAR_IDENTIFIED))
2141 before_str[before_n++] = "完全に鑑定済みの";
2143 /*** Dice boosted (weapon of slaying) ***/
2144 if (IS_FLG(FLG_BOOSTED))
2146 before_str[before_n++] = "ダメージダイスが通常より大きい";
2150 /*** Weapons whose dd*ds is more than nn ***/
2151 if (IS_FLG(FLG_MORE_DICE))
2153 static char more_than_desc_str[] = "___";
2154 before_str[before_n++] = "ダメージダイスの最大値が";
2157 sprintf(more_than_desc_str,"%d", entry->dice);
2158 before_str[before_n++] = more_than_desc_str;
2159 before_str[before_n++] = "以上の";
2162 /*** Items whose magical bonus is more than nn ***/
2163 if (IS_FLG(FLG_MORE_BONUS))
2165 static char more_bonus_desc_str[] = "___";
2166 before_str[before_n++] = "修正値が(+";
2168 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2169 before_str[before_n++] = more_bonus_desc_str;
2170 before_str[before_n++] = ")以上の";
2173 /*** Worthless items ***/
2174 if (IS_FLG(FLG_WORTHLESS))
2175 before_str[before_n++] = "店で無価値と判定される";
2178 if (IS_FLG(FLG_ARTIFACT))
2180 before_str[before_n++] = "アーティファクトの";
2185 if (IS_FLG(FLG_EGO))
2187 before_str[before_n++] = "エゴアイテムの";
2192 if (IS_FLG(FLG_GOOD))
2194 before_str[before_n++] = "上質の";
2199 if (IS_FLG(FLG_NAMELESS))
2201 before_str[before_n++] = "エゴでもアーティファクトでもない";
2206 if (IS_FLG(FLG_AVERAGE))
2208 before_str[before_n++] = "並の";
2212 /*** Rare equipments ***/
2213 if (IS_FLG(FLG_RARE))
2215 before_str[before_n++] = "ドラゴン装備やカオス・ブレード等を含む珍しい";
2219 /*** Common equipments ***/
2220 if (IS_FLG(FLG_COMMON))
2222 before_str[before_n++] = "ありふれた(ドラゴン装備やカオス・ブレード等の珍しい物ではない)";
2226 /*** Wanted monster's corpse/skeletons ***/
2227 if (IS_FLG(FLG_WANTED))
2229 before_str[before_n++] = "ハンター事務所で賞金首とされている";
2233 /*** Human corpse/skeletons (for Daemon magic) ***/
2234 if (IS_FLG(FLG_HUMAN))
2236 before_str[before_n++] = "悪魔魔法で使うための人間やヒューマノイドの";
2240 /*** Unique monster's corpse/skeletons/statues ***/
2241 if (IS_FLG(FLG_UNIQUE))
2243 before_str[before_n++] = "ユニークモンスターの";
2247 /*** Unreadable spellbooks ***/
2248 if (IS_FLG(FLG_UNREADABLE))
2250 before_str[before_n++] = "あなたが読めない領域の";
2254 /*** First realm spellbooks ***/
2255 if (IS_FLG(FLG_REALM1))
2257 before_str[before_n++] = "第一領域の";
2261 /*** Second realm spellbooks ***/
2262 if (IS_FLG(FLG_REALM2))
2264 before_str[before_n++] = "第二領域の";
2268 /*** First rank spellbooks ***/
2269 if (IS_FLG(FLG_FIRST))
2271 before_str[before_n++] = "全4冊の内の1冊目の";
2275 /*** Second rank spellbooks ***/
2276 if (IS_FLG(FLG_SECOND))
2278 before_str[before_n++] = "全4冊の内の2冊目の";
2282 /*** Third rank spellbooks ***/
2283 if (IS_FLG(FLG_THIRD))
2285 before_str[before_n++] = "全4冊の内の3冊目の";
2289 /*** Fourth rank spellbooks ***/
2290 if (IS_FLG(FLG_FOURTH))
2292 before_str[before_n++] = "全4冊の内の4冊目の";
2297 if (IS_FLG(FLG_ITEMS))
2298 ; /* Nothing to do */
2299 else if (IS_FLG(FLG_WEAPONS))
2301 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2303 else if (IS_FLG(FLG_ARMORS))
2305 else if (IS_FLG(FLG_MISSILES))
2306 body_str = "弾や矢やクロスボウの矢";
2307 else if (IS_FLG(FLG_DEVICES))
2308 body_str = "巻物や魔法棒や杖やロッド";
2309 else if (IS_FLG(FLG_LIGHTS))
2310 body_str = "光源用のアイテム";
2311 else if (IS_FLG(FLG_JUNKS))
2312 body_str = "折れた棒等のガラクタ";
2313 else if (IS_FLG(FLG_CORPSES))
2315 else if (IS_FLG(FLG_SPELLBOOKS))
2317 else if (IS_FLG(FLG_HAFTED))
2319 else if (IS_FLG(FLG_SHIELDS))
2321 else if (IS_FLG(FLG_BOWS))
2322 body_str = "スリングや弓やクロスボウ";
2323 else if (IS_FLG(FLG_RINGS))
2325 else if (IS_FLG(FLG_AMULETS))
2326 body_str = "アミュレット";
2327 else if (IS_FLG(FLG_SUITS))
2329 else if (IS_FLG(FLG_CLOAKS))
2331 else if (IS_FLG(FLG_HELMS))
2332 body_str = "ヘルメットや冠";
2333 else if (IS_FLG(FLG_GLOVES))
2335 else if (IS_FLG(FLG_BOOTS))
2340 strcat(buff, "全ての");
2341 else for (i = 0; i < before_n && before_str[i]; i++)
2342 strcat(buff, before_str[i]);
2344 strcat(buff, body_str);
2354 strcat(buff, "で、名前が「");
2355 strncat(buff, str, 80);
2357 strcat(buff, "」で始まるもの");
2359 strcat(buff, "」を含むもの");
2364 strncat(buff, format("に「%s」", insc), 80);
2366 if (my_strstr(insc, "%%all"))
2367 strcat(buff, "(%%allは全能力を表す英字の記号で置換)");
2368 else if (my_strstr(insc, "%all"))
2369 strcat(buff, "(%allは全能力を表す記号で置換)");
2370 else if (my_strstr(insc, "%%"))
2371 strcat(buff, "(%%は追加能力を表す英字の記号で置換)");
2372 else if (my_strstr(insc, "%"))
2373 strcat(buff, "(%は追加能力を表す記号で置換)");
2375 strcat(buff, "と刻んで");
2380 if (act & DONT_AUTOPICK)
2381 strcat(buff, "放置する。");
2382 else if (act & DO_AUTODESTROY)
2383 strcat(buff, "破壊する。");
2384 else if (act & DO_QUERY_AUTOPICK)
2385 strcat(buff, "確認の後に拾う。");
2387 strcat(buff, "拾う。");
2389 if (act & DO_DISPLAY)
2391 if (act & DONT_AUTOPICK)
2392 strcat(buff, "全体マップ('M')で'N'を押したときに表示する。");
2393 else if (act & DO_AUTODESTROY)
2394 strcat(buff, "全体マップ('M')で'K'を押したときに表示する。");
2396 strcat(buff, "全体マップ('M')で'M'を押したときに表示する。");
2399 strcat(buff, "全体マップには表示しない。");
2403 concptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2404 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2408 /*** Collecting items ***/
2409 /*** Which can be absorbed into a slot as a bundle ***/
2410 if (IS_FLG(FLG_COLLECTING))
2411 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2413 /*** Unaware items ***/
2414 if (IS_FLG(FLG_UNAWARE))
2416 before_str[before_n++] = "unidentified";
2417 whose_str[whose_n++] = "basic abilities are not known";
2420 /*** Unidentified ***/
2421 if (IS_FLG(FLG_UNIDENTIFIED))
2422 before_str[before_n++] = "unidentified";
2424 /*** Identified ***/
2425 if (IS_FLG(FLG_IDENTIFIED))
2426 before_str[before_n++] = "identified";
2428 /*** *Identified* ***/
2429 if (IS_FLG(FLG_STAR_IDENTIFIED))
2430 before_str[before_n++] = "fully identified";
2432 /*** Rare equipments ***/
2433 if (IS_FLG(FLG_RARE))
2435 before_str[before_n++] = "very rare";
2436 body_str = "equipments";
2437 after_str[after_n++] = "such as Dragon armor, Blades of Chaos, etc.";
2440 /*** Common equipments ***/
2441 if (IS_FLG(FLG_COMMON))
2443 before_str[before_n++] = "relatively common";
2444 body_str = "equipments";
2445 after_str[after_n++] = "compared to very rare Dragon armor, Blades of Chaos, etc.";
2448 /*** Worthless items ***/
2449 if (IS_FLG(FLG_WORTHLESS))
2451 before_str[before_n++] = "worthless";
2452 which_str[which_n++] = "can not be sold at stores";
2456 if (IS_FLG(FLG_ARTIFACT))
2458 before_str[before_n++] = "artifact";
2462 if (IS_FLG(FLG_EGO))
2464 before_str[before_n++] = "ego";
2468 if (IS_FLG(FLG_GOOD))
2470 body_str = "equipment";
2471 which_str[which_n++] = "have good quality";
2475 if (IS_FLG(FLG_NAMELESS))
2477 body_str = "equipment";
2478 which_str[which_n++] = "is neither ego-item nor artifact";
2482 if (IS_FLG(FLG_AVERAGE))
2484 body_str = "equipment";
2485 which_str[which_n++] = "have average quality";
2488 /*** Dice boosted (weapon of slaying) ***/
2489 if (IS_FLG(FLG_BOOSTED))
2491 body_str = "weapons";
2492 whose_str[whose_n++] = "damage dice is bigger than normal";
2495 /*** Weapons whose dd*ds is more than nn ***/
2496 if (IS_FLG(FLG_MORE_DICE))
2498 static char more_than_desc_str[] =
2499 "maximum damage from dice is bigger than __";
2500 body_str = "weapons";
2502 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2504 whose_str[whose_n++] = more_than_desc_str;
2507 /*** Items whose magical bonus is more than nn ***/
2508 if (IS_FLG(FLG_MORE_BONUS))
2510 static char more_bonus_desc_str[] =
2511 "magical bonus is bigger than (+__)";
2513 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2514 "%d)", entry->bonus);
2515 whose_str[whose_n++] = more_bonus_desc_str;
2518 /*** Wanted monster's corpse/skeletons ***/
2519 if (IS_FLG(FLG_WANTED))
2521 body_str = "corpse or skeletons";
2522 which_str[which_n++] = "is wanted at the Hunter's Office";
2525 /*** Human corpse/skeletons (for Daemon magic) ***/
2526 if (IS_FLG(FLG_HUMAN))
2528 before_str[before_n++] = "humanoid";
2529 body_str = "corpse or skeletons";
2530 which_str[which_n++] = "can be used for Daemon magic";
2533 /*** Unique monster's corpse/skeletons/statues ***/
2534 if (IS_FLG(FLG_UNIQUE))
2536 before_str[before_n++] = "unique monster's";
2537 body_str = "corpse or skeletons";
2540 /*** Unreadable spellbooks ***/
2541 if (IS_FLG(FLG_UNREADABLE))
2543 body_str = "spellbooks";
2544 after_str[after_n++] = "of different realms from yours";
2547 /*** First realm spellbooks ***/
2548 if (IS_FLG(FLG_REALM1))
2550 body_str = "spellbooks";
2551 after_str[after_n++] = "of your first realm";
2554 /*** Second realm spellbooks ***/
2555 if (IS_FLG(FLG_REALM2))
2557 body_str = "spellbooks";
2558 after_str[after_n++] = "of your second realm";
2561 /*** First rank spellbooks ***/
2562 if (IS_FLG(FLG_FIRST))
2564 before_str[before_n++] = "first one of four";
2565 body_str = "spellbooks";
2568 /*** Second rank spellbooks ***/
2569 if (IS_FLG(FLG_SECOND))
2571 before_str[before_n++] = "second one of four";
2572 body_str = "spellbooks";
2575 /*** Third rank spellbooks ***/
2576 if (IS_FLG(FLG_THIRD))
2578 before_str[before_n++] = "third one of four";
2579 body_str = "spellbooks";
2582 /*** Fourth rank spellbooks ***/
2583 if (IS_FLG(FLG_FOURTH))
2585 before_str[before_n++] = "fourth one of four";
2586 body_str = "spellbooks";
2590 if (IS_FLG(FLG_ITEMS))
2591 ; /* Nothing to do */
2592 else if (IS_FLG(FLG_WEAPONS))
2593 body_str = "weapons";
2594 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2595 body_str = "favorite weapons";
2596 else if (IS_FLG(FLG_ARMORS))
2597 body_str = "armors";
2598 else if (IS_FLG(FLG_MISSILES))
2599 body_str = "shots, arrows or crossbow bolts";
2600 else if (IS_FLG(FLG_DEVICES))
2601 body_str = "scrolls, wands, staffs or rods";
2602 else if (IS_FLG(FLG_LIGHTS))
2603 body_str = "light sources";
2604 else if (IS_FLG(FLG_JUNKS))
2605 body_str = "junk such as broken sticks";
2606 else if (IS_FLG(FLG_CORPSES))
2607 body_str = "corpses or skeletons";
2608 else if (IS_FLG(FLG_SPELLBOOKS))
2609 body_str = "spellbooks";
2610 else if (IS_FLG(FLG_HAFTED))
2611 body_str = "hafted weapons";
2612 else if (IS_FLG(FLG_SHIELDS))
2613 body_str = "shields";
2614 else if (IS_FLG(FLG_BOWS))
2615 body_str = "slings, bows or crossbows";
2616 else if (IS_FLG(FLG_RINGS))
2618 else if (IS_FLG(FLG_AMULETS))
2619 body_str = "amulets";
2620 else if (IS_FLG(FLG_SUITS))
2621 body_str = "body armors";
2622 else if (IS_FLG(FLG_CLOAKS))
2623 body_str = "cloaks";
2624 else if (IS_FLG(FLG_HELMS))
2625 body_str = "helms or crowns";
2626 else if (IS_FLG(FLG_GLOVES))
2627 body_str = "gloves";
2628 else if (IS_FLG(FLG_BOOTS))
2631 /* Prepare a string for item name */
2638 whose_str[whose_n++] = "name begins with \"";
2641 which_str[which_n++] = "have \"";
2645 /* Describe action flag */
2646 if (act & DONT_AUTOPICK)
2647 strcpy(buff, "Leave on floor ");
2648 else if (act & DO_AUTODESTROY)
2649 strcpy(buff, "Destroy ");
2650 else if (act & DO_QUERY_AUTOPICK)
2651 strcpy(buff, "Ask to pick up ");
2653 strcpy(buff, "Pickup ");
2655 /* Auto-insctiption */
2658 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2660 if (my_strstr(insc, "%all"))
2661 strcat(buff, ", replacing %all with code string representing all abilities,");
2662 else if (my_strstr(insc, "%"))
2663 strcat(buff, ", replacing % with code string representing extra random abilities,");
2665 strcat(buff, " on ");
2670 strcat(buff, "all ");
2671 else for (i = 0; i < before_n && before_str[i]; i++)
2673 strcat(buff, before_str[i]);
2678 strcat(buff, body_str);
2681 for (i = 0; i < after_n && after_str[i]; i++)
2684 strcat(buff, after_str[i]);
2688 for (i = 0; i < whose_n && whose_str[i]; i++)
2691 strcat(buff, " whose ");
2693 strcat(buff, ", and ");
2695 strcat(buff, whose_str[i]);
2698 /* Item name ; whose name is beginning with "str" */
2705 /* whose ..., and which .... */
2706 if (whose_n && which_n)
2707 strcat(buff, ", and ");
2710 for (i = 0; i < which_n && which_str[i]; i++)
2713 strcat(buff, " which ");
2715 strcat(buff, ", and ");
2717 strcat(buff, which_str[i]);
2720 /* Item name ; which have "str" as part of its name */
2723 strncat(buff, str, 80);
2724 strcat(buff, "\" as part of its name");
2728 /* Describe whether it will be displayed on the full map or not */
2729 if (act & DO_DISPLAY)
2731 if (act & DONT_AUTOPICK)
2732 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2733 else if (act & DO_AUTODESTROY)
2734 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2736 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2739 strcat(buff, " Not displayed in the full map.");
2746 * Read whole lines of a file to memory
2748 static concptr *read_text_lines(concptr filename)
2750 concptr *lines_list = NULL;
2756 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2759 fff = my_fopen(buf, "r");
2763 /* Allocate list of pointers */
2764 C_MAKE(lines_list, MAX_LINES, concptr);
2767 while (0 == my_fgets(fff, buf, sizeof(buf)))
2769 lines_list[lines++] = string_make(buf);
2770 if (lines >= MAX_LINES - 1) break;
2773 lines_list[0] = string_make("");
2778 if (!fff) return NULL;
2784 * Copy the default autopick file to the user directory
2786 static void prepare_default_pickpref(void)
2788 const concptr messages[] = {
2789 _("あなたは「自動拾いエディタ」を初めて起動しました。", "You have activated the Auto-Picker Editor for the first time."),
2790 _("自動拾いのユーザー設定ファイルがまだ書かれていないので、", "Since user pref file for autopick is not yet created,"),
2791 _("基本的な自動拾い設定ファイルをlib/pref/picktype.prfからコピーします。", "the default setting is loaded from lib/pref/pickpref.prf ."),
2799 concptr filename = pickpref_filename(PT_DEFAULT);
2801 /* Display messages */
2802 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2807 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2808 user_fp = my_fopen(buf, "w");
2811 if (!user_fp) return;
2813 /* Write header messages for a notification */
2814 fprintf(user_fp, "#***\n");
2815 for (i = 0; messages[i]; i++)
2817 fprintf(user_fp, "#*** %s\n", messages[i]);
2819 fprintf(user_fp, "#***\n\n\n");
2822 /* Open the default file */
2823 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2824 pref_fp = my_fopen(buf, "r");
2833 /* Copy the contents of default file */
2834 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2835 fprintf(user_fp, "%s\n", buf);
2842 * Read an autopick prefence file to memory
2843 * Prepare default if no user file is found
2845 static concptr *read_pickpref_text_lines(int *filename_mode_p)
2848 concptr *lines_list;
2850 /* Try a filename with player name */
2851 *filename_mode_p = PT_WITH_PNAME;
2852 strcpy(buf, pickpref_filename(*filename_mode_p));
2853 lines_list = read_text_lines(buf);
2857 /* Use default name */
2858 *filename_mode_p = PT_DEFAULT;
2859 strcpy(buf, pickpref_filename(*filename_mode_p));
2860 lines_list = read_text_lines(buf);
2865 /* There is no preference file in the user directory */
2867 /* Copy the default autopick file to the user directory */
2868 prepare_default_pickpref();
2870 /* Use default name again */
2871 lines_list = read_text_lines(buf);
2876 /* Allocate list of pointers */
2877 C_MAKE(lines_list, MAX_LINES, concptr);
2878 lines_list[0] = string_make("");
2885 * Write whole lines of memory to a file.
2887 static bool write_text_lines(concptr filename, concptr *lines_list)
2894 /* Build the filename */
2895 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2898 fff = my_fopen(buf, "w");
2901 for (lines = 0; lines_list[lines]; lines++)
2902 my_fputs(fff, lines_list[lines], 1024);
2907 if (!fff) return FALSE;
2913 * Free memory of lines_list.
2915 static void free_text_lines(concptr *lines_list)
2919 for (lines = 0; lines_list[lines]; lines++)
2920 string_free(lines_list[lines]);
2922 /* free list of pointers */
2923 C_KILL(lines_list, MAX_LINES, concptr);
2928 * Delete or insert string
2930 static void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
2936 /* Some lines are selected */
2939 by1 = MIN(tb->my, tb->cy);
2940 by2 = MAX(tb->my, tb->cy);
2943 /* No mark -- Select current line */
2944 else /* if (!tb->mark) */
2950 /* Set/Reset flag of each line */
2951 for (y = by1; y <= by2; y++)
2953 autopick_type an_entry, *entry = &an_entry;
2955 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2957 string_free(tb->lines_list[y]);
2961 /* Add? or Remove? */
2962 if (!IS_FLG(flg)) add = TRUE;
2965 /* No more change */
2969 /* You can use only one noun flag */
2970 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2973 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2977 /* You can use only one identify state flag */
2978 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2981 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2985 /* You can use only one flag in artifact/ego/nameless */
2986 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
2989 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
2993 /* You can use only one flag in rare/common */
2994 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
2997 for (i = FLG_RARE; i <= FLG_COMMON; i++)
3001 if (add) ADD_FLG(flg);
3004 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3007 tb->dirty_flags |= DIRTY_ALL;
3009 /* Text is changed */
3016 * Change command letter
3018 static void toggle_command_letter(text_body_type *tb, byte flg)
3020 autopick_type an_entry, *entry = &an_entry;
3025 /* Some lines are selected */
3028 by1 = MIN(tb->my, tb->cy);
3029 by2 = MAX(tb->my, tb->cy);
3032 /* No mark -- Select current line */
3033 else /* if (!tb->mark) */
3039 /* Set/Reset flag of each line */
3040 for (y = by1; y <= by2; y++)
3044 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3046 string_free(tb->lines_list[y]);
3050 /* Add? or Remove? */
3051 if (!(entry->action & flg)) add = TRUE;
3054 /* No more change */
3058 /* Count number of letter (by negative number) */
3059 if (entry->action & DONT_AUTOPICK) wid--;
3060 else if (entry->action & DO_AUTODESTROY) wid--;
3061 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3062 if (!(entry->action & DO_DISPLAY)) wid--;
3064 /* Set/Reset the flag */
3065 if (flg != DO_DISPLAY)
3067 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3068 if (add) entry->action |= flg;
3069 else entry->action |= DO_AUTOPICK;
3073 entry->action &= ~(DO_DISPLAY);
3074 if (add) entry->action |= flg;
3077 /* Correct cursor location */
3080 if (entry->action & DONT_AUTOPICK) wid++;
3081 else if (entry->action & DO_AUTODESTROY) wid++;
3082 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3083 if (!(entry->action & DO_DISPLAY)) wid++;
3085 if (wid > 0) tb->cx++;
3086 if (wid < 0 && tb->cx > 0) tb->cx--;
3089 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3092 tb->dirty_flags |= DIRTY_ALL;
3094 /* Text is changed */
3100 * Delete or insert string
3102 static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
3106 /* Some lines are selected */
3109 by1 = MIN(tb->my, tb->cy);
3110 by2 = MAX(tb->my, tb->cy);
3113 /* No mark -- Select current line */
3114 else /* if (!tb->mark) */
3120 /* Set/Reset flag of each line */
3121 for (y = by1; y <= by2; y++)
3123 autopick_type an_entry, *entry = &an_entry;
3125 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3127 /* There is the flag already */
3130 /* Free memory for the entry */
3131 autopick_free_entry(entry);
3136 string_free(tb->lines_list[y]);
3138 /* Remove all noun flag */
3139 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3142 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3148 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3151 tb->dirty_flags |= DIRTY_ALL;
3153 /* Text is changed */
3160 * Check if this line is expression or not.
3161 * And update it if it is.
3163 static void check_expression_line(text_body_type *tb, int y)
3165 concptr s = tb->lines_list[y];
3167 if ((s[0] == '?' && s[1] == ':') ||
3168 (tb->states[y] & LSTAT_BYPASS))
3170 /* Expressions need re-evaluation */
3171 tb->dirty_flags |= DIRTY_EXPRESSION;
3177 * Add an empty line at the last of the file
3179 static bool add_empty_line(text_body_type *tb)
3183 for (k = 0; tb->lines_list[k]; k++)
3184 /* count number of lines */ ;
3186 /* Too many lines! */
3187 if (k >= MAX_LINES - 2) return FALSE;
3189 /* The last line is already empty */
3190 if (!tb->lines_list[k-1][0]) return FALSE;
3192 /* Create new empty line */
3193 tb->lines_list[k] = string_make("");
3195 /* Expressions need re-evaluation */
3196 tb->dirty_flags |= DIRTY_EXPRESSION;
3198 /* Text is changed */
3201 /* A line is added */
3207 * Insert return code and split the line
3209 static bool insert_return_code(text_body_type *tb)
3211 char buf[MAX_LINELEN];
3214 for (k = 0; tb->lines_list[k]; k++)
3215 /* count number of lines */ ;
3217 if (k >= MAX_LINES - 2) return FALSE;
3220 /* Move down lines */
3221 for (; tb->cy < k; k--)
3223 tb->lines_list[k+1] = tb->lines_list[k];
3224 tb->states[k+1] = tb->states[k];
3227 /* Split current line */
3228 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3231 if (iskanji(tb->lines_list[tb->cy][i]))
3232 buf[j++] = tb->lines_list[tb->cy][i++];
3234 buf[j++] = tb->lines_list[tb->cy][i];
3237 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3238 string_free(tb->lines_list[tb->cy]);
3239 tb->lines_list[tb->cy] = string_make(buf);
3241 /* Expressions need re-evaluation */
3242 tb->dirty_flags |= DIRTY_EXPRESSION;
3244 /* Text is changed */
3252 * Choose an item and get auto-picker entry from it.
3254 static bool entry_from_choosed_object(autopick_type *entry)
3259 q = _("どのアイテムを登録しますか? ", "Enter which item? ");
3260 s = _("アイテムを持っていない。", "You have nothing to enter.");
3261 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3262 if (!o_ptr) return FALSE;
3264 autopick_entry_from_object(entry, o_ptr);
3270 * Choose an item for search
3272 static byte get_object_for_search(object_type **o_handle, concptr *search_strp)
3274 char buf[MAX_NLEN+20];
3278 q = _("どのアイテムを検索しますか? ", "Enter which item? ");
3279 s = _("アイテムを持っていない。", "You have nothing to enter.");
3280 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3281 if (!o_ptr) return 0;
3285 string_free(*search_strp);
3286 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3287 *search_strp = string_make(format("<%s>", buf));
3293 * Prepare for search by destroyed object
3295 static byte get_destroyed_object_for_search(object_type **o_handle, concptr *search_strp)
3297 char buf[MAX_NLEN+20];
3299 if (!autopick_last_destroyed_object.k_idx) return 0;
3301 *o_handle = &autopick_last_destroyed_object;
3303 string_free(*search_strp);
3304 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3305 *search_strp = string_make(format("<%s>", buf));
3311 * Choose an item or string for search
3313 static byte get_string_for_search(object_type **o_handle, concptr *search_strp)
3319 * TERM_YELLOW : Overwrite mode
3320 * TERM_WHITE : Insert mode
3322 byte color = TERM_YELLOW;
3323 char buf[MAX_NLEN+20];
3326 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
3327 int col = sizeof(prompt) - 1;
3329 /* Prepare string buffer for edit */
3330 if (*search_strp) strcpy(buf, *search_strp);
3333 /* Object searching mode */
3336 color = TERM_L_GREEN;
3339 /* Display prompt */
3349 /* Display the string */
3350 Term_erase(col, 0, 255);
3351 Term_putstr(col, 0, -1, color, buf);
3354 Term_gotoxy(col + pos, 0);
3356 /* Get a special key code */
3357 skey = inkey_special(TRUE);
3359 /* Analyze the key */
3367 /* Now on insert mode */
3370 /* No move at beginning of line */
3371 if (0 == pos) break;
3375 int next_pos = i + 1;
3378 if (iskanji(buf[i])) next_pos++;
3381 /* Is there the cursor at next position? */
3382 if (next_pos >= pos) break;
3388 /* Get previous position */
3396 /* Now on insert mode */
3399 /* No move at end of line */
3400 if ('\0' == buf[pos]) break;
3404 if (iskanji(buf[pos])) pos += 2;
3422 if (*o_handle) return (back ? -1 : 1);
3423 string_free(*search_strp);
3424 *search_strp = string_make(buf);
3426 return (back ? -1 : 1);
3429 return get_object_for_search(o_handle, search_strp);
3432 /* Prepare string for destroyed object if there is one. */
3433 if (get_destroyed_object_for_search(o_handle, search_strp))
3443 /* Now on insert mode */
3446 /* No move at beginning of line */
3447 if (0 == pos) break;
3451 int next_pos = i + 1;
3454 if (iskanji(buf[i])) next_pos++;
3457 /* Is there the cursor at next position? */
3458 if (next_pos >= pos) break;
3464 /* Get previous position */
3467 /* Fall through to 'Delete key' */
3476 /* Now on insert mode */
3479 /* No move at end of line */
3480 if ('\0' == buf[pos]) break;
3482 /* Position of next character */
3486 /* Next character is one more byte away */
3487 if (iskanji(buf[pos])) src++;
3492 /* Move characters at src to dst */
3493 while ('\0' != (buf[dst++] = buf[src++]))
3501 /* Insert a character */
3506 /* Ignore special keys */
3507 if (skey & SKEY_MASK) break;
3509 /* Get a character code */
3512 /* Was non insert mode? */
3513 if (color != TERM_WHITE)
3515 /* Was object searching mode */
3516 if (color == TERM_L_GREEN)
3518 /* Cancel the mode */
3521 /* Remove indicating string */
3522 string_free(*search_strp);
3523 *search_strp = NULL;
3526 /* Overwrite default string */
3529 /* Go to insert mode */
3533 /* Save right part of string */
3534 strcpy(tmp, buf + pos);
3540 /* Bypass macro processing */
3558 if (pos < len && (isprint(c) || iskana(c)))
3560 if (pos < len && isprint(c))
3574 /* Write back the left part of string */
3575 my_strcat(buf, tmp, len + 1);
3582 /* Object searching mode was cancelled? */
3583 if (*o_handle && color != TERM_L_GREEN)
3585 /* Cancel the mode */
3588 /* Remove indicating string */
3590 string_free(*search_strp);
3591 *search_strp = NULL;
3596 } /* while (TRUE) */
3601 * Search next line matches for o_ptr
3603 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3605 autopick_type an_entry, *entry = &an_entry;
3606 GAME_TEXT o_name[MAX_NLEN];
3607 int bypassed_cy = -1;
3609 /* Start searching from current cursor position */
3612 /* Prepare object name string first */
3613 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3615 /* Convert the string to lower case */
3616 str_tolower(o_name);
3625 if (!tb->lines_list[++i]) break;
3632 /* Is this line is a correct entry? */
3633 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3635 /* Does this line match to the object? */
3636 match = is_autopick_aux(o_ptr, entry, o_name);
3637 autopick_free_entry(entry);
3638 if (!match) continue;
3640 /* Found a line but it's inactive */
3641 if (tb->states[i] & LSTAT_BYPASS)
3643 /* If it is first found, remember it */
3644 if (bypassed_cy == -1) bypassed_cy = i;
3647 /* Found an active line! */
3650 /* Move to this line */
3654 if (bypassed_cy != -1)
3656 /* Mark as some lines are skipped */
3657 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3665 if (bypassed_cy != -1)
3667 /* Move to the remembered line */
3669 tb->cy = bypassed_cy;
3671 /* Mark as this line is inactive */
3672 tb->dirty_flags |= DIRTY_INACTIVE;
3677 /* Mark as NOT FOUND */
3678 tb->dirty_flags |= DIRTY_NOT_FOUND;
3686 * Search next line matches to the string
3688 static void search_for_string(text_body_type *tb, concptr search_str, bool forward)
3690 int bypassed_cy = -1;
3691 int bypassed_cx = 0;
3693 /* Start searching from current cursor position */
3703 if (!tb->lines_list[++i]) break;
3710 /* Look for the string pattern */
3711 pos = my_strstr(tb->lines_list[i], search_str);
3716 /* Found a line but it's inactive */
3717 if ((tb->states[i] & LSTAT_BYPASS) &&
3718 !(tb->states[i] & LSTAT_EXPRESSION))
3720 /* If it is first found, remember it */
3721 if (bypassed_cy == -1)
3724 bypassed_cx = (int)(pos - tb->lines_list[i]);
3728 /* Found an active line! */
3731 /* Move to this location */
3732 tb->cx = (int)(pos - tb->lines_list[i]);
3735 if (bypassed_cy != -1)
3737 /* Mark as some lines are skipped */
3738 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3746 if (bypassed_cy != -1)
3748 /* Move to the remembered line */
3749 tb->cx = bypassed_cx;
3750 tb->cy = bypassed_cy;
3752 /* Mark as this line is inactive */
3753 tb->dirty_flags |= DIRTY_INACTIVE;
3758 /* Mark as NOT FOUND */
3759 tb->dirty_flags |= DIRTY_NOT_FOUND;
3769 * Editor command id's
3772 #define EC_SAVEQUIT 2
3783 #define EC_PGDOWN 13
3785 #define EC_BOTTOM 15
3790 #define EC_KILL_LINE 20
3791 #define EC_DELETE_CHAR 21
3792 #define EC_BACKSPACE 22
3793 #define EC_SEARCH_STR 23
3794 #define EC_SEARCH_FORW 24
3795 #define EC_SEARCH_BACK 25
3796 #define EC_SEARCH_OBJ 26
3797 #define EC_SEARCH_DESTROYED 27
3798 #define EC_INSERT_OBJECT 28
3799 #define EC_INSERT_DESTROYED 29
3800 #define EC_INSERT_BLOCK 30
3801 #define EC_INSERT_MACRO 31
3802 #define EC_INSERT_KEYMAP 32
3803 #define EC_CL_AUTOPICK 33
3804 #define EC_CL_DESTROY 34
3805 #define EC_CL_LEAVE 35
3806 #define EC_CL_QUERY 36
3807 #define EC_CL_NO_DISP 37
3808 #define EC_OK_COLLECTING 38
3809 #define EC_IK_UNAWARE 39
3810 #define EC_IK_UNIDENTIFIED 40
3811 #define EC_IK_IDENTIFIED 41
3812 #define EC_IK_STAR_IDENTIFIED 42
3813 #define EC_OK_BOOSTED 43
3814 #define EC_OK_MORE_DICE 44
3815 #define EC_OK_MORE_BONUS 45
3816 #define EC_OK_WORTHLESS 46
3817 #define EC_OK_ARTIFACT 47
3818 #define EC_OK_EGO 48
3819 #define EC_OK_GOOD 49
3820 #define EC_OK_NAMELESS 50
3821 #define EC_OK_AVERAGE 51
3822 #define EC_OK_RARE 52
3823 #define EC_OK_COMMON 53
3824 #define EC_OK_WANTED 54
3825 #define EC_OK_UNIQUE 55
3826 #define EC_OK_HUMAN 56
3827 #define EC_OK_UNREADABLE 57
3828 #define EC_OK_REALM1 58
3829 #define EC_OK_REALM2 59
3830 #define EC_OK_FIRST 60
3831 #define EC_OK_SECOND 61
3832 #define EC_OK_THIRD 62
3833 #define EC_OK_FOURTH 63
3834 #define EC_KK_WEAPONS 64
3835 #define EC_KK_FAVORITE_WEAPONS 65
3836 #define EC_KK_ARMORS 66
3837 #define EC_KK_MISSILES 67
3838 #define EC_KK_DEVICES 68
3839 #define EC_KK_LIGHTS 69
3840 #define EC_KK_JUNKS 70
3841 #define EC_KK_CORPSES 71
3842 #define EC_KK_SPELLBOOKS 72
3843 #define EC_KK_SHIELDS 73
3844 #define EC_KK_BOWS 74
3845 #define EC_KK_RINGS 75
3846 #define EC_KK_AMULETS 76
3847 #define EC_KK_SUITS 77
3848 #define EC_KK_CLOAKS 78
3849 #define EC_KK_HELMS 79
3850 #define EC_KK_GLOVES 80
3851 #define EC_KK_BOOTS 81
3857 static GAME_TEXT MN_QUIT[] = "セーブ無しで終了";
3858 static GAME_TEXT MN_SAVEQUIT[] = "セーブして終了";
3859 static GAME_TEXT MN_REVERT[] = "全ての変更を破棄";
3860 static GAME_TEXT MN_HELP[] = "ヘルプ";
3862 static GAME_TEXT MN_MOVE[] = "カーソル移動";
3863 static GAME_TEXT MN_LEFT[] = "左 (←矢印キー)";
3864 static GAME_TEXT MN_DOWN[] = "下 (↓矢印キー)";
3865 static GAME_TEXT MN_UP[] = "上 (↑矢印キー)";
3866 static GAME_TEXT MN_RIGHT[] = "右 (→矢印キー)";
3867 static GAME_TEXT MN_BOL[] = "行の先頭";
3868 static GAME_TEXT MN_EOL[] = "行の終端";
3869 static GAME_TEXT MN_PGUP[] = "上のページ (PageUpキー)";
3870 static GAME_TEXT MN_PGDOWN[] = "下のページ (PageDownキー)";
3871 static GAME_TEXT MN_TOP[] = "1行目へ移動 (Homeキー)";
3872 static GAME_TEXT MN_BOTTOM[] = "最下行へ移動(Endキー)";
3874 static GAME_TEXT MN_EDIT[] = "編集";
3875 static GAME_TEXT MN_CUT[] = "カット";
3876 static GAME_TEXT MN_COPY[] = "コピー";
3877 static GAME_TEXT MN_PASTE[] = "ペースト";
3878 static GAME_TEXT MN_BLOCK[] = "選択範囲の指定";
3879 static GAME_TEXT MN_KILL_LINE[] = "行の残りを削除";
3880 static GAME_TEXT MN_DELETE_CHAR[] = "1文字削除";
3881 static GAME_TEXT MN_BACKSPACE[] = "バックスペース";
3882 static GAME_TEXT MN_RETURN[] = "改行";
3884 static GAME_TEXT MN_SEARCH[] = "検索";
3885 static GAME_TEXT MN_SEARCH_STR[] = "文字列で検索";
3886 static GAME_TEXT MN_SEARCH_FORW[] = "前方へ再検索";
3887 static GAME_TEXT MN_SEARCH_BACK[] = "後方へ再検索";
3888 static GAME_TEXT MN_SEARCH_OBJ[] = "アイテムを選択して検索";
3889 static GAME_TEXT MN_SEARCH_DESTROYED[] = "自動破壊されたアイテムで検索";
3891 static GAME_TEXT MN_INSERT[] = "色々挿入";
3892 static GAME_TEXT MN_INSERT_OBJECT[] = "選択したアイテムの名前を挿入";
3893 static GAME_TEXT MN_INSERT_DESTROYED[] = "自動破壊されたアイテムの名前を挿入";
3894 static GAME_TEXT MN_INSERT_BLOCK[] = "条件分岐ブロックの例を挿入";
3895 static GAME_TEXT MN_INSERT_MACRO[] = "マクロ定義を挿入";
3896 static GAME_TEXT MN_INSERT_KEYMAP[] = "キーマップ定義を挿入";
3898 static GAME_TEXT MN_COMMAND_LETTER[] = "拾い/破壊/放置の選択";
3899 static GAME_TEXT MN_CL_AUTOPICK[] = "「 」 (自動拾い)";
3900 static GAME_TEXT MN_CL_DESTROY[] = "「!」 (自動破壊)";
3901 static GAME_TEXT MN_CL_LEAVE[] = "「~」 (放置)";
3902 static GAME_TEXT MN_CL_QUERY[] = "「;」 (確認して拾う)";
3903 static GAME_TEXT MN_CL_NO_DISP[] = "「(」 (マップコマンドで表示しない)";
3905 static GAME_TEXT MN_ADJECTIVE_GEN[] = "形容詞(一般)の選択";
3906 static GAME_TEXT MN_RARE[] = "レアな (装備)";
3907 static GAME_TEXT MN_COMMON[] = "ありふれた (装備)";
3909 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "形容詞(特殊)の選択";
3910 static GAME_TEXT MN_BOOSTED[] = "ダイス目の違う (武器)";
3911 static GAME_TEXT MN_MORE_DICE[] = "ダイス目 # 以上の (武器)";
3912 static GAME_TEXT MN_MORE_BONUS[] = "修正値 # 以上の (指輪等)";
3913 static GAME_TEXT MN_WANTED[] = "賞金首の (死体)";
3914 static GAME_TEXT MN_UNIQUE[] = "ユニーク・モンスターの (死体)";
3915 static GAME_TEXT MN_HUMAN[] = "人間の (死体)";
3916 static GAME_TEXT MN_UNREADABLE[] = "読めない (魔法書)";
3917 static GAME_TEXT MN_REALM1[] = "第一領域の (魔法書)";
3918 static GAME_TEXT MN_REALM2[] = "第二領域の (魔法書)";
3919 static GAME_TEXT MN_FIRST[] = "1冊目の (魔法書)";
3920 static GAME_TEXT MN_SECOND[] = "2冊目の (魔法書)";
3921 static GAME_TEXT MN_THIRD[] = "3冊目の (魔法書)";
3922 static GAME_TEXT MN_FOURTH[] = "4冊目の (魔法書)";
3924 static GAME_TEXT MN_NOUN[] = "名詞の選択";
3928 static GAME_TEXT MN_QUIT[] = "Quit without save";
3929 static GAME_TEXT MN_SAVEQUIT[] = "Save & Quit";
3930 static GAME_TEXT MN_REVERT[] = "Revert all changes";
3931 static GAME_TEXT MN_HELP[] = "Help";
3933 static GAME_TEXT MN_MOVE[] = "Move cursor";
3934 static GAME_TEXT MN_LEFT[] = "Left (Left Arrow key)";
3935 static GAME_TEXT MN_DOWN[] = "Down (Down Arrow key)";
3936 static GAME_TEXT MN_UP[] = "Up (Up Arrow key)";
3937 static GAME_TEXT MN_RIGHT[] = "Right (Right Arrow key)";
3938 static GAME_TEXT MN_BOL[] = "Beggining of line";
3939 static GAME_TEXT MN_EOL[] = "End of line";
3940 static GAME_TEXT MN_PGUP[] = "Page up (PageUp key)";
3941 static GAME_TEXT MN_PGDOWN[] = "Page down(PageDown key)";
3942 static GAME_TEXT MN_TOP[] = "Top (Home key)";
3943 static GAME_TEXT MN_BOTTOM[] = "Bottom (End key)";
3945 static GAME_TEXT MN_EDIT[] = "Edit";
3946 static GAME_TEXT MN_CUT[] = "Cut";
3947 static GAME_TEXT MN_COPY[] = "Copy";
3948 static GAME_TEXT MN_PASTE[] = "Paste";
3949 static GAME_TEXT MN_BLOCK[] = "Select block";
3950 static GAME_TEXT MN_KILL_LINE[] = "Kill rest of line";
3951 static GAME_TEXT MN_DELETE_CHAR[] = "Delete character";
3952 static GAME_TEXT MN_BACKSPACE[] = "Backspace";
3953 static GAME_TEXT MN_RETURN[] = "Return";
3955 static GAME_TEXT MN_SEARCH[] = "Search";
3956 static GAME_TEXT MN_SEARCH_STR[] = "Search by string";
3957 static GAME_TEXT MN_SEARCH_FORW[] = "Search forward";
3958 static GAME_TEXT MN_SEARCH_BACK[] = "Search backward";
3959 static GAME_TEXT MN_SEARCH_OBJ[] = "Search by inventory object";
3960 static GAME_TEXT MN_SEARCH_DESTROYED[] = "Search by destroyed object";
3962 static GAME_TEXT MN_INSERT[] = "Insert...";
3963 static GAME_TEXT MN_INSERT_OBJECT[] = "Insert name of choosen object";
3964 static GAME_TEXT MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
3965 static GAME_TEXT MN_INSERT_BLOCK[] = "Insert conditional block";
3966 static GAME_TEXT MN_INSERT_MACRO[] = "Insert a macro definition";
3967 static GAME_TEXT MN_INSERT_KEYMAP[] = "Insert a keymap definition";
3969 static GAME_TEXT MN_COMMAND_LETTER[] = "Command letter";
3970 static GAME_TEXT MN_CL_AUTOPICK[] = "' ' (Auto pick)";
3971 static GAME_TEXT MN_CL_DESTROY[] = "'!' (Auto destroy)";
3972 static GAME_TEXT MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
3973 static GAME_TEXT MN_CL_QUERY[] = "';' (Query to pick up)";
3974 static GAME_TEXT MN_CL_NO_DISP[] = "'(' (No display on the large map)";
3976 static GAME_TEXT MN_ADJECTIVE_GEN[] = "Adjective (general)";
3977 static GAME_TEXT MN_RARE[] = "rare (equipment)";
3978 static GAME_TEXT MN_COMMON[] = "common (equipment)";
3980 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
3981 static GAME_TEXT MN_BOOSTED[] = "dice boosted (weapons)";
3982 static GAME_TEXT MN_MORE_DICE[] = "more than # dice (weapons)";
3983 static GAME_TEXT MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
3984 static GAME_TEXT MN_WANTED[] = "wanted (corpse)";
3985 static GAME_TEXT MN_UNIQUE[] = "unique (corpse)";
3986 static GAME_TEXT MN_HUMAN[] = "human (corpse)";
3987 static GAME_TEXT MN_UNREADABLE[] = "unreadable (spellbooks)";
3988 static GAME_TEXT MN_REALM1[] = "realm1 (spellbooks)";
3989 static GAME_TEXT MN_REALM2[] = "realm2 (spellbooks)";
3990 static GAME_TEXT MN_FIRST[] = "first (spellbooks)";
3991 static GAME_TEXT MN_SECOND[] = "second (spellbooks)";
3992 static GAME_TEXT MN_THIRD[] = "third (spellbooks)";
3993 static GAME_TEXT MN_FOURTH[] = "fourth (spellbooks)";
3995 static GAME_TEXT MN_NOUN[] = "Keywords (noun)";
4005 } command_menu_type;
4008 command_menu_type menu_data[] =
4010 {MN_HELP, 0, -1, EC_HELP},
4011 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4012 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4013 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4015 {MN_EDIT, 0, -1, -1},
4016 {MN_CUT, 1, KTRL('x'), EC_CUT},
4017 {MN_COPY, 1, KTRL('c'), EC_COPY},
4018 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4019 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4020 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4021 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4022 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4023 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4024 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4026 {MN_SEARCH, 0, -1, -1},
4027 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4028 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4029 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4030 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4031 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4033 {MN_MOVE, 0, -1, -1},
4034 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4035 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4036 {MN_UP, 1, KTRL('p'), EC_UP},
4037 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4038 {MN_BOL, 1, KTRL('a'), EC_BOL},
4039 {MN_EOL, 1, KTRL('e'), EC_EOL},
4040 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4041 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4042 {MN_TOP, 1, KTRL('t'), EC_TOP},
4043 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4045 {MN_INSERT, 0, -1, -1},
4046 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4047 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4048 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4049 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4050 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4052 {MN_ADJECTIVE_GEN, 0, -1, -1},
4053 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4054 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4055 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4056 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4057 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4058 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4059 {KEY_EGO, 1, -1, EC_OK_EGO},
4060 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4061 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4062 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4063 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4064 {MN_RARE, 1, -1, EC_OK_RARE},
4065 {MN_COMMON, 1, -1, EC_OK_COMMON},
4067 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4068 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4069 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4070 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4071 {MN_WANTED, 1, -1, EC_OK_WANTED},
4072 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4073 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4074 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4075 {MN_REALM1, 1, -1, EC_OK_REALM1},
4076 {MN_REALM2, 1, -1, EC_OK_REALM2},
4077 {MN_FIRST, 1, -1, EC_OK_FIRST},
4078 {MN_SECOND, 1, -1, EC_OK_SECOND},
4079 {MN_THIRD, 1, -1, EC_OK_THIRD},
4080 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4082 {MN_NOUN, 0, -1, -1},
4083 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4084 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4085 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4086 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4087 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4088 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4089 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4090 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4091 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4092 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4093 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4094 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4095 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4096 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4097 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4098 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4099 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4100 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4102 {MN_COMMAND_LETTER, 0, -1, -1},
4103 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4104 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4105 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4106 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4107 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4109 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4116 * Find a command by 'key'.
4118 static int get_com_id(char key)
4122 for (i = 0; menu_data[i].name; i++)
4124 if (menu_data[i].key == key)
4126 return menu_data[i].com_id;
4135 * Display the menu, and get a command
4137 static int do_command_menu(int level, int start)
4142 int col0 = 5 + level*7;
4143 int row0 = 1 + level*3;
4145 int menu_id_list[26];
4147 char linestr[MAX_LINELEN];
4149 /* Get max length */
4151 for (i = start; menu_data[i].level >= level; i++)
4155 /* Ignore lower level sub menus */
4156 if (menu_data[i].level > level) continue;
4158 len = strlen(menu_data[i].name);
4159 if (len > max_len) max_len = len;
4161 menu_id_list[menu_key] = i;
4165 while (menu_key < 26)
4167 menu_id_list[menu_key] = -1;
4171 /* Extra space for displaying menu key and command key */
4172 max_menu_wid = max_len + 3 + 3;
4174 /* Prepare box line */
4176 strcat(linestr, "+");
4177 for (i = 0; i < max_menu_wid + 2; i++)
4179 strcat(linestr, "-");
4181 strcat(linestr, "+");
4191 int row1 = row0 + 1;
4194 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4196 /* Draw menu items */
4198 for (i = start; menu_data[i].level >= level; i++)
4200 char com_key_str[3];
4203 /* Ignore lower level sub menus */
4204 if (menu_data[i].level > level) continue;
4206 if (menu_data[i].com_id == -1)
4208 strcpy(com_key_str, _("▼", ">"));
4210 else if (menu_data[i].key != -1)
4212 com_key_str[0] = '^';
4213 com_key_str[1] = menu_data[i].key + '@';
4214 com_key_str[2] = '\0';
4218 com_key_str[0] = '\0';
4221 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4223 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4228 /* Draw bottom line */
4229 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4231 /* The menu was shown */
4234 prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
4237 if (key == ESCAPE) return 0;
4239 if ('a' <= key && key <= 'z')
4241 menu_id = menu_id_list[key - 'a'];
4245 com_id = menu_data[menu_id].com_id;
4249 com_id = do_command_menu(level + 1, menu_id + 1);
4251 if (com_id) return com_id;
4263 com_id = get_com_id(key);
4264 if (com_id) return com_id;
4271 static chain_str_type *new_chain_str(concptr str)
4273 chain_str_type *chain;
4275 size_t len = strlen(str);
4277 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4279 strcpy(chain->s, str);
4286 static void kill_yank_chain(text_body_type *tb)
4288 chain_str_type *chain = tb->yank;
4290 tb->yank_eol = TRUE;
4294 chain_str_type *next = chain->next;
4295 size_t len = strlen(chain->s);
4297 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4304 static void add_str_to_yank(text_body_type *tb, concptr str)
4306 chain_str_type *chain;
4308 tb->yank_eol = FALSE;
4310 if (NULL == tb->yank)
4312 tb->yank = new_chain_str(str);
4322 chain->next = new_chain_str(str);
4327 chain = chain->next;
4333 * Do work for the copy editor-command
4335 static void copy_text_to_yank(text_body_type *tb)
4337 int len = strlen(tb->lines_list[tb->cy]);
4339 /* Correct cursor location */
4340 if (tb->cx > len) tb->cx = len;
4342 /* Use single line? */
4345 /* Select a single line */
4351 /* Kill old yank buffer */
4352 kill_yank_chain(tb);
4355 /* Single line case */
4356 if (tb->my == tb->cy)
4359 char buf[MAX_LINELEN];
4360 int bx1 = MIN(tb->mx, tb->cx);
4361 int bx2 = MAX(tb->mx, tb->cx);
4363 /* Correct fake cursor position */
4364 if (bx2 > len) bx2 = len;
4366 /* Whole part of this line is selected */
4367 if (bx1 == 0 && bx2 == len)
4369 /* Copy this line */
4370 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4372 /* Add end of line to the buffer */
4373 add_str_to_yank(tb, "");
4376 /* Segment of this line is selected */
4379 for (i = 0; i < bx2 - bx1; i++)
4381 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4385 /* Copy this segment of line */
4386 add_str_to_yank(tb, buf);
4390 /* Multiple lines case */
4391 else /* if (tb->my != tb->cy) */
4395 int by1 = MIN(tb->my, tb->cy);
4396 int by2 = MAX(tb->my, tb->cy);
4399 for (y = by1; y <= by2; y++)
4401 /* Copy this line */
4402 add_str_to_yank(tb, tb->lines_list[y]);
4405 /* Add final end of line to the buffer */
4406 add_str_to_yank(tb, "");
4409 /* Disable selection */
4413 tb->dirty_flags |= DIRTY_ALL;
4417 #define DESCRIPT_HGT 3
4422 static void draw_text_editor(text_body_type *tb)
4425 int by1 = 0, by2 = 0;
4427 Term_get_size(&tb->wid, &tb->hgt);
4430 * Top line (-1), description line (-3), separator (-1)
4433 tb->hgt -= 2 + DESCRIPT_HGT;
4436 /* Don't let cursor at second byte of kanji */
4437 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4438 if (iskanji(tb->lines_list[tb->cy][i]))
4444 * Move to a correct position in the
4447 if (i & 1) tb->cx--;
4454 /* Scroll if necessary */
4455 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4456 tb->upper = tb->cy - (tb->hgt)/2;
4459 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4460 tb->left = tb->cx - (tb->wid)*2/3;
4464 /* Redraw whole window after resize */
4465 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4466 tb->dirty_flags |= DIRTY_SCREEN;
4468 /* Redraw all text after scroll */
4469 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4470 tb->dirty_flags |= DIRTY_ALL;
4473 if (tb->dirty_flags & DIRTY_SCREEN)
4475 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4479 /* Redraw mode line */
4480 if (tb->dirty_flags & DIRTY_MODE)
4482 char buf[MAX_LINELEN];
4484 int sepa_length = tb->wid;
4487 for (i = 0; i < sepa_length; i++)
4491 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4494 if (tb->dirty_flags & DIRTY_EXPRESSION)
4499 for (y = 0; tb->lines_list[y]; y++)
4503 concptr s = tb->lines_list[y];
4507 /* Update this line's state */
4508 tb->states[y] = state;
4510 if (*s++ != '?') continue;
4511 if (*s++ != ':') continue;
4513 /* Lines below this line are auto-registered */
4514 if (streq(s, "$AUTOREGISTER"))
4515 state |= LSTAT_AUTOREGISTER;
4518 ss = (char *)string_make(s);
4521 /* Parse the expr */
4522 v = process_pref_file_expr(&ss, &f);
4525 if (streq(v, "0")) state |= LSTAT_BYPASS;
4526 else state &= ~LSTAT_BYPASS;
4528 /* Cannot use string_free() because the string was "destroyed" */
4529 C_KILL(s_keep, s_len + 1, char);
4531 /* Re-update this line's state */
4532 tb->states[y] = state | LSTAT_EXPRESSION;
4535 tb->dirty_flags |= DIRTY_ALL;
4540 tb->dirty_flags |= DIRTY_ALL;
4542 by1 = MIN(tb->my, tb->cy);
4543 by2 = MAX(tb->my, tb->cy);
4546 /* Dump up to tb->hgt lines of messages */
4547 for (i = 0; i < tb->hgt; i++)
4553 int y = tb->upper+i;
4555 /* clean or dirty? */
4556 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4559 msg = tb->lines_list[y];
4562 /* Apply horizontal scroll */
4563 for (j = 0; *msg; msg++, j++)
4565 if (j == tb->left) break;
4581 Term_erase(0, i + 1, tb->wid);
4583 if (tb->states[y] & LSTAT_AUTOREGISTER)
4585 /* Warning color -- These lines will be deleted later */
4590 /* Bypassed line will be displayed by darker color */
4591 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4592 else color = TERM_WHITE;
4595 /* No mark or Out of mark */
4596 if (!tb->mark || (y < by1 || by2 < y))
4598 /* Dump the messages, bottom to top */
4599 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4602 /* Multiple lines selected */
4603 else if (by1 != by2)
4605 /* Dump the messages, bottom to top */
4606 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4609 /* Single line selected */
4612 int x0 = leftcol + tb->left;
4613 int len = strlen(tb->lines_list[tb->cy]);
4614 int bx1 = MIN(tb->mx, tb->cx);
4615 int bx2 = MAX(tb->mx, tb->cx);
4617 /* Correct cursor location */
4618 if (bx2 > len) bx2 = len;
4620 Term_gotoxy(leftcol, i + 1);
4621 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4622 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4623 Term_addstr(-1, color, msg + (bx2 - x0));
4627 for (; i < tb->hgt; i++)
4630 Term_erase(0, i + 1, tb->wid);
4633 /* Display information when updated */
4634 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4636 autopick_type an_entry, *entry = &an_entry;
4637 concptr str1 = NULL, str2 = NULL;
4640 /* Clear information line */
4641 for (i = 0; i < DESCRIPT_HGT; i++)
4644 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4647 /* Display information */
4648 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4650 str1 = format(_("パターンが見つかりません: %s", "Pattern not found: %s"), tb->search_str);
4652 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4654 str1 = format(_("無効状態の行をスキップしました。(%sを検索中)",
4655 "Some inactive lines are skipped. (Searching %s)"), tb->search_str);
4657 else if (tb->dirty_flags & DIRTY_INACTIVE)
4659 str1 = format(_("無効状態の行だけが見付かりました。(%sを検索中)",
4660 "Found only an inactive line. (Searching %s)"), tb->search_str);
4662 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4664 str1 = _("検索するパターンがありません(^S で検索)。", "No pattern to search. (Press ^S to search.)");
4666 else if (tb->lines_list[tb->cy][0] == '#')
4668 str1 = _("この行はコメントです。", "This line is a comment.");
4670 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4672 switch(tb->lines_list[tb->cy][0])
4675 str1 = _("この行は条件分岐式です。", "This line is a Conditional Expression.");
4678 str1 = _("この行はマクロの実行内容を定義します。", "This line defines a Macro action.");
4681 str1 = _("この行はマクロのトリガー・キーを定義します。", "This line defines a Macro trigger key.");
4684 str1 = _("この行はキー配置を定義します。", "This line defines a Keymap.");
4688 switch(tb->lines_list[tb->cy][0])
4691 if (tb->states[tb->cy] & LSTAT_BYPASS)
4693 str2 = _("現在の式の値は「偽(=0)」です。", "The expression is 'False'(=0) currently.");
4697 str2 = _("現在の式の値は「真(=1)」です。", "The expression is 'True'(=1) currently.");
4702 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4704 str2 = _("この行は後で削除されます。", "This line will be delete later.");
4707 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4709 str2 = _("この行は現在は無効な状態です。", "This line is bypassed currently.");
4715 /* Get description of an autopicker preference line */
4716 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4718 char buf[MAX_LINELEN];
4719 char temp[MAX_LINELEN];
4722 describe_autopick(buf, entry);
4724 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4726 strcat(buf, _("この行は後で削除されます。", " This line will be delete later."));
4729 if (tb->states[tb->cy] & LSTAT_BYPASS)
4731 strcat(buf, _("この行は現在は無効な状態です。", " This line is bypassed currently."));
4734 roff_to_buf(buf, 81, temp, sizeof(temp));
4736 for (i = 0; i < 3; i++)
4742 prt(t, tb->hgt +1 + 1 + i, 0);
4746 autopick_free_entry(entry);
4749 /* Draw the first line */
4750 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4752 /* Draw the second line */
4753 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4759 * Kill segment of a line
4761 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4763 char buf[MAX_LINELEN];
4764 concptr s = tb->lines_list[y];
4768 /* Kill whole line? */
4769 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4773 string_free(tb->lines_list[y]);
4775 /* Shift lines up */
4776 for (i = y; tb->lines_list[i+1]; i++)
4777 tb->lines_list[i] = tb->lines_list[i+1];
4778 tb->lines_list[i] = NULL;
4780 /* Expressions need re-evaluation */
4781 tb->dirty_flags |= DIRTY_EXPRESSION;
4787 if (x0 == x1) return;
4789 /* Before the segment */
4790 for (x = 0; x < x0; x++)
4793 /* After the segment */
4794 for (x = x1; s[x]; x++)
4800 string_free(tb->lines_list[y]);
4801 tb->lines_list[y] = string_make(buf);
4803 /* Expressions may need re-evaluation */
4804 check_expression_line(tb, y);
4806 /* Text is changed */
4812 * Get a trigger key and insert ASCII string for the trigger
4814 static bool insert_macro_line(text_body_type *tb)
4823 /* Do not process macros */
4829 /* Read the pattern */
4835 /* Do not process macros */
4838 /* Do not wait for keys */
4841 /* Attempt to read a key */
4850 /* Convert the trigger */
4851 ascii_to_text(tmp, buf);
4854 if(!tmp[0]) return FALSE;
4858 /* Insert preference string */
4859 insert_return_code(tb);
4860 string_free(tb->lines_list[tb->cy]);
4861 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4863 /* Acquire action */
4864 i = macro_find_exact(buf);
4868 /* Nothing defined */
4873 /* Analyze the current action */
4874 ascii_to_text(tmp, macro__act[i]);
4877 /* Insert blank action preference line */
4878 insert_return_code(tb);
4879 string_free(tb->lines_list[tb->cy]);
4880 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4887 * Get a command key and insert ASCII string for the key
4889 static bool insert_keymap_line(text_body_type *tb)
4897 if (rogue_like_commands)
4899 mode = KEYMAP_MODE_ROGUE;
4905 mode = KEYMAP_MODE_ORIG;
4916 /* Convert the trigger */
4917 ascii_to_text(tmp, buf);
4920 if(!tmp[0]) return FALSE;
4924 /* Insert preference string */
4925 insert_return_code(tb);
4926 string_free(tb->lines_list[tb->cy]);
4927 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4929 /* Look up the keymap */
4930 act = keymap_act[mode][(byte)(buf[0])];
4934 /* Analyze the current action */
4935 ascii_to_text(tmp, act);
4939 /* No keymap defined -- Use trigger key itself as a default */
4941 /* Nothing to do (use tmp) */
4944 /* Insert blank action preference line */
4945 insert_return_code(tb);
4946 string_free(tb->lines_list[tb->cy]);
4947 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4954 * Execute a single editor command
4956 static bool do_editor_command(text_body_type *tb, int com_id)
4963 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
4964 "Discard all changes and quit. Are you sure? "))) break;
4966 return QUIT_WITHOUT_SAVE;
4969 return QUIT_AND_SAVE;
4972 /* Revert to original */
4973 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
4974 "Discard all changes and revert to original file. Are you sure? "))) break;
4976 free_text_lines(tb->lines_list);
4977 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4978 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4979 tb->cx = tb->cy = 0;
4982 /* Text is not changed */
4983 tb->changed = FALSE;
4987 /* Peruse the main help file */
4988 (void)show_file(TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
4990 tb->dirty_flags |= DIRTY_SCREEN;
4995 /* Split a line or insert end of line */
4997 /* Ignore selection */
5003 tb->dirty_flags |= DIRTY_ALL;
5006 insert_return_code(tb);
5011 tb->dirty_flags |= DIRTY_ALL;
5024 len = strlen(tb->lines_list[tb->cy]);
5025 if (len < tb->cx) tb->cx = len;
5028 /* Don't let cursor at second byte of kanji */
5029 for (i = 0; tb->lines_list[tb->cy][i]; i++)
5031 if (iskanji(tb->lines_list[tb->cy][i]))
5036 /* Move to the left */
5044 else if (tb->cy > 0)
5047 tb->cx = strlen(tb->lines_list[tb->cy]);
5054 /* Is this the last line? */
5055 if (!tb->lines_list[tb->cy + 1])
5057 /* Add one more empty line if possible */
5058 if (!add_empty_line(tb)) break;
5068 if (tb->cy > 0) tb->cy--;
5077 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5080 len = strlen(tb->lines_list[tb->cy]);
5083 /* Correct the cursor position */
5086 /* Is this the last line? */
5087 if (!tb->lines_list[tb->cy + 1])
5089 /* Add one more empty line if possible */
5090 if (!add_empty_line(tb)) break;
5093 /* Move to the beginning of next line */
5101 /* Beginning of line */
5107 tb->cx = strlen(tb->lines_list[tb->cy]);
5111 while (0 < tb->cy && tb->upper <= tb->cy)
5113 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5119 while (tb->cy < tb->upper + tb->hgt)
5121 /* Is this the last line? */
5122 if (!tb->lines_list[tb->cy + 1])
5124 /* Add one more empty line if possible */
5125 if (!add_empty_line(tb)) break;
5141 /* Is this the last line? */
5142 if (!tb->lines_list[tb->cy + 1])
5144 /* Add one more empty line if possible */
5145 if (!add_empty_line(tb)) break;
5151 /* Always at the biginning of the last line */
5158 /* Copy the text first */
5159 copy_text_to_yank(tb);
5161 /* Single line case */
5162 if (tb->my == tb->cy)
5164 int bx1 = MIN(tb->mx, tb->cx);
5165 int bx2 = MAX(tb->mx, tb->cx);
5166 int len = strlen(tb->lines_list[tb->cy]);
5168 /* Correct fake cursor position */
5169 if (bx2 > len) bx2 = len;
5171 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5173 /* New cursor position */
5177 /* Multiple lines case */
5178 else /* if (tb->my != tb->cy) */
5182 int by1 = MIN(tb->my, tb->cy);
5183 int by2 = MAX(tb->my, tb->cy);
5185 /* Kill lines in reverse order */
5186 for (y = by2; y >= by1; y--)
5188 int len = strlen(tb->lines_list[y]);
5190 kill_line_segment(tb, y, 0, len, TRUE);
5193 /* New cursor position */
5199 /* Disable selection */
5203 tb->dirty_flags |= DIRTY_ALL;
5205 /* Text is changed */
5212 copy_text_to_yank(tb);
5215 * Move cursor position to the end of the selection
5217 * Pressing ^C ^V correctly duplicates the selection.
5219 if (tb->my == tb->cy)
5221 tb->cx = MAX(tb->cx, tb->mx);
5224 * When whole line is selected, the end of
5225 * line code is also copyed.
5227 if (!tb->lines_list[tb->cy][tb->cx])
5229 /* Is this the last line? */
5230 if (!tb->lines_list[tb->cy + 1])
5232 /* Add one more empty line if possible */
5233 if (!add_empty_line(tb)) break;
5236 /* Go to the beginning of next line */
5243 tb->cy = MAX(tb->cy, tb->my);
5245 /* Is this the last line? */
5246 if (!tb->lines_list[tb->cy + 1])
5248 /* Add one more empty line if possible */
5249 if (!add_empty_line(tb)) break;
5260 /* Paste killed text */
5262 chain_str_type *chain = tb->yank;
5263 int len = strlen(tb->lines_list[tb->cy]);
5265 /* Nothing to do? */
5268 /* Correct cursor location */
5269 if (tb->cx > len) tb->cx = len;
5271 /* Ignore selection */
5277 tb->dirty_flags |= DIRTY_ALL;
5283 concptr yank_str = chain->s;
5285 char buf[MAX_LINELEN];
5287 char rest[MAX_LINELEN], *rest_ptr = rest;
5289 /* Save preceding string */
5290 for(i = 0; i < tb->cx; i++)
5291 buf[i] = tb->lines_list[tb->cy][i];
5293 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5295 /* Paste yank buffer */
5296 while (*yank_str && i < MAX_LINELEN-1)
5298 buf[i++] = *yank_str++;
5304 chain = chain->next;
5306 if (chain || tb->yank_eol)
5308 /* There is an end of line between chain nodes */
5310 insert_return_code(tb);
5312 /* Replace this line with new one */
5313 string_free(tb->lines_list[tb->cy]);
5314 tb->lines_list[tb->cy] = string_make(buf);
5316 /* Move to next line */
5323 /* Final line doesn't have end of line */
5325 tb->cx = strlen(buf);
5327 /* Rest of original line */
5328 while (*rest_ptr && i < MAX_LINELEN-1)
5330 buf[i++] = *rest_ptr++;
5336 /* Replace this line with new one */
5337 string_free(tb->lines_list[tb->cy]);
5338 tb->lines_list[tb->cy] = string_make(buf);
5345 tb->dirty_flags |= DIRTY_ALL;
5347 /* Expressions need re-evaluation */
5348 tb->dirty_flags |= DIRTY_EXPRESSION;
5350 /* Text is changed */
5359 /* Disable the selection */
5363 tb->dirty_flags |= DIRTY_ALL;
5367 tb->mark = MARK_MARK;
5369 /* Repeating this command swaps cursor position */
5370 if (com_id == tb->old_com_id)
5382 tb->dirty_flags |= DIRTY_ALL;
5386 int len = strlen(tb->lines_list[tb->cy]);
5388 /* Mark the point 1 */
5392 /* Correct cursor location */
5393 if (tb->cx > len) tb->mx = len;
5400 /* Kill rest of line */
5402 int len = strlen(tb->lines_list[tb->cy]);
5404 /* Correct cursor location */
5405 if (tb->cx > len) tb->cx = len;
5407 /* Ignore selection */
5413 tb->dirty_flags |= DIRTY_ALL;
5416 /* Append only if this command is repeated. */
5417 if (tb->old_com_id != com_id)
5419 kill_yank_chain(tb);
5423 /* Really deleted some text */
5426 /* Add deleted string to yank buffer */
5427 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5429 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5432 tb->dirty_line = tb->cy;
5434 /* Leave end of line character */
5438 /* Cut the end of line character only */
5439 if (tb->yank_eol) add_str_to_yank(tb, "");
5441 /* Cut end of line */
5442 tb->yank_eol = TRUE;
5444 do_editor_command(tb, EC_DELETE_CHAR);
5448 case EC_DELETE_CHAR:
5450 /* DELETE == go forward + BACK SPACE */
5454 /* Ignore selection */
5460 tb->dirty_flags |= DIRTY_ALL;
5464 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5468 /* Pass through the end of line to next line */
5469 len = strlen(tb->lines_list[tb->cy]);
5472 if (tb->lines_list[tb->cy + 1])
5484 do_editor_command(tb, EC_BACKSPACE);
5493 char buf[MAX_LINELEN];
5495 /* Ignore selection */
5501 tb->dirty_flags |= DIRTY_ALL;
5504 /* Move to correct collumn */
5505 len = strlen(tb->lines_list[tb->cy]);
5506 if (len < tb->cx) tb->cx = len;
5510 /* delete a return code and union two lines */
5511 if (tb->cy == 0) break;
5512 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5513 strcpy(buf, tb->lines_list[tb->cy-1]);
5514 strcat(buf, tb->lines_list[tb->cy]);
5515 string_free(tb->lines_list[tb->cy-1]);
5516 string_free(tb->lines_list[tb->cy]);
5517 tb->lines_list[tb->cy-1] = string_make(buf);
5519 for (i = tb->cy; tb->lines_list[i+1]; i++)
5520 tb->lines_list[i] = tb->lines_list[i+1];
5522 tb->lines_list[i] = NULL;
5526 tb->dirty_flags |= DIRTY_ALL;
5528 /* Expressions need re-evaluation */
5529 tb->dirty_flags |= DIRTY_EXPRESSION;
5531 /* Text is changed */
5537 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5541 if (iskanji(tb->lines_list[tb->cy][i]))
5542 buf[j++] = tb->lines_list[tb->cy][i++];
5544 buf[j++] = tb->lines_list[tb->cy][i];
5551 for (; tb->lines_list[tb->cy][i]; i++)
5552 buf[j++] = tb->lines_list[tb->cy][i];
5554 string_free(tb->lines_list[tb->cy]);
5555 tb->lines_list[tb->cy] = string_make(buf);
5558 tb->dirty_line = tb->cy;
5560 /* Expressions may need re-evaluation */
5561 check_expression_line(tb, tb->cy);
5563 /* Text is changed */
5573 /* Become dirty because of item/equip menu */
5574 tb->dirty_flags |= DIRTY_SCREEN;
5576 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5578 if (!search_dir) break;
5580 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5581 else do_editor_command(tb, EC_SEARCH_BACK);
5585 case EC_SEARCH_FORW:
5586 if (tb->search_o_ptr)
5588 search_for_object(tb, tb->search_o_ptr, TRUE);
5590 else if (tb->search_str && tb->search_str[0])
5592 search_for_string(tb, tb->search_str, TRUE);
5596 tb->dirty_flags |= DIRTY_NO_SEARCH;
5600 case EC_SEARCH_BACK:
5601 if (tb->search_o_ptr)
5603 search_for_object(tb, tb->search_o_ptr, FALSE);
5605 else if (tb->search_str && tb->search_str[0])
5607 search_for_string(tb, tb->search_str, FALSE);
5611 tb->dirty_flags |= DIRTY_NO_SEARCH;
5616 /* Become dirty because of item/equip menu */
5617 tb->dirty_flags |= DIRTY_SCREEN;
5619 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5621 do_editor_command(tb, EC_SEARCH_FORW);
5624 case EC_SEARCH_DESTROYED:
5625 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5627 /* There is no object to search */
5628 tb->dirty_flags |= DIRTY_NO_SEARCH;
5633 do_editor_command(tb, EC_SEARCH_FORW);
5636 case EC_INSERT_OBJECT:
5638 /* Insert choosen item name */
5640 autopick_type an_entry, *entry = &an_entry;
5642 if (!entry_from_choosed_object(entry))
5644 /* Now dirty because of item/equip menu */
5645 tb->dirty_flags |= DIRTY_SCREEN;
5650 insert_return_code(tb);
5651 string_free(tb->lines_list[tb->cy]);
5652 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5654 /* Now dirty because of item/equip menu */
5655 tb->dirty_flags |= DIRTY_SCREEN;
5660 case EC_INSERT_DESTROYED:
5661 /* Insert a name of last destroyed item */
5662 if (tb->last_destroyed)
5665 insert_return_code(tb);
5666 string_free(tb->lines_list[tb->cy]);
5667 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5670 tb->dirty_flags |= DIRTY_ALL;
5672 /* Text is changed */
5677 case EC_INSERT_BLOCK:
5679 /* Insert a conditinal expression line */
5680 char expression[80];
5682 /* Conditional Expression for Class and Race */
5683 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5685 rp_ptr->E_title, cp_ptr->E_title,
5687 rp_ptr->title, cp_ptr->title,
5693 insert_return_code(tb);
5694 string_free(tb->lines_list[tb->cy]);
5695 tb->lines_list[tb->cy] = string_make(expression);
5697 insert_return_code(tb);
5698 string_free(tb->lines_list[tb->cy]);
5699 tb->lines_list[tb->cy] = string_make("?:1");
5702 tb->dirty_flags |= DIRTY_ALL;
5704 /* Text is changed */
5710 case EC_INSERT_MACRO:
5711 /* Draw_everythig (delete menu) */
5712 draw_text_editor(tb);
5715 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5718 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
5719 if (insert_macro_line(tb))
5721 /* Prepare to input action */
5725 tb->dirty_flags |= DIRTY_ALL;
5727 /* Text is changed */
5733 case EC_INSERT_KEYMAP:
5734 /* Draw_everythig (delete menu) */
5735 draw_text_editor(tb);
5738 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5741 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
5742 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5744 if (insert_keymap_line(tb))
5746 /* Prepare to input action */
5750 tb->dirty_flags |= DIRTY_ALL;
5752 /* Text is changed */
5757 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5758 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5759 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5760 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5761 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5763 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5764 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5765 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5766 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5767 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5768 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5769 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5770 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5771 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5772 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5773 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5774 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5775 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5776 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5777 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5778 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5779 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5780 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5781 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5782 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5783 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5784 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5785 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5786 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5787 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5788 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5789 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5790 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5791 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5792 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5793 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5794 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5795 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5796 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5797 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5798 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5799 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5800 case EC_OK_UNREADABLE:
5801 toggle_keyword(tb, FLG_UNREADABLE);
5802 add_keyword(tb, FLG_SPELLBOOKS);
5805 toggle_keyword(tb, FLG_REALM1);
5806 add_keyword(tb, FLG_SPELLBOOKS);
5809 toggle_keyword(tb, FLG_REALM2);
5810 add_keyword(tb, FLG_SPELLBOOKS);
5813 toggle_keyword(tb, FLG_FIRST);
5814 add_keyword(tb, FLG_SPELLBOOKS);
5817 toggle_keyword(tb, FLG_SECOND);
5818 add_keyword(tb, FLG_SPELLBOOKS);
5821 toggle_keyword(tb, FLG_THIRD);
5822 add_keyword(tb, FLG_SPELLBOOKS);
5825 toggle_keyword(tb, FLG_FOURTH);
5826 add_keyword(tb, FLG_SPELLBOOKS);
5830 /* Save old command */
5831 tb->old_com_id = com_id;
5838 * Insert single letter at cursor position.
5840 static void insert_single_letter(text_body_type *tb, int key)
5843 char buf[MAX_LINELEN];
5845 /* Save preceding string */
5846 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5847 buf[j++] = tb->lines_list[tb->cy][i];
5849 /* Add a character */
5857 if (j+2 < MAX_LINELEN)
5859 buf[j++] = (char)key;
5860 buf[j++] = (char)next;
5869 if (j+1 < MAX_LINELEN)
5870 buf[j++] = (char)key;
5875 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5876 buf[j++] = tb->lines_list[tb->cy][i];
5879 /* Replace current line with new line */
5880 string_free(tb->lines_list[tb->cy]);
5881 tb->lines_list[tb->cy] = string_make(buf);
5883 /* Move to correct collumn */
5884 len = strlen(tb->lines_list[tb->cy]);
5885 if (len < tb->cx) tb->cx = len;
5888 tb->dirty_line = tb->cy;
5890 /* Expressions may need re-evaluation */
5891 check_expression_line(tb, tb->cy);
5893 /* Text is changed */
5899 * Check special key code and get a movement command id
5901 static int analyze_move_key(text_body_type *tb, int skey)
5905 /* Not a special key */
5906 if (!(skey & SKEY_MASK)) return 0;
5908 /* Convert from a special key code to an editor command */
5909 switch(skey & ~SKEY_MOD_MASK)
5911 case SKEY_DOWN: com_id = EC_DOWN; break;
5912 case SKEY_LEFT: com_id = EC_LEFT; break;
5913 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5914 case SKEY_UP: com_id = EC_UP; break;
5915 case SKEY_PGUP: com_id = EC_PGUP; break;
5916 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5917 case SKEY_TOP: com_id = EC_TOP; break;
5918 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5921 /* Not a special movement key */
5925 /* Without shift modifier */
5926 if (!(skey & SKEY_MOD_SHIFT))
5929 * Un-shifted cursor keys cancells
5930 * selection created by shift+cursor.
5932 if (tb->mark & MARK_BY_SHIFT)
5937 tb->dirty_flags |= DIRTY_ALL;
5941 /* With shift modifier */
5944 /* Start selection by shift + cursor keys */
5947 int len = strlen(tb->lines_list[tb->cy]);
5949 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5953 /* Correct cursor location */
5954 if (tb->cx > len) tb->mx = len;
5956 /* Need to redraw text */
5957 if (com_id == EC_UP || com_id == EC_DOWN)
5959 /* Redraw all text */
5960 tb->dirty_flags |= DIRTY_ALL;
5964 tb->dirty_line = tb->cy;
5973 * In-game editor of Object Auto-picker/Destoryer
5975 void do_cmd_edit_autopick(void)
5977 static int cx_save = 0;
5978 static int cy_save = 0;
5980 text_body_type text_body, *tb = &text_body;
5982 autopick_type an_entry, *entry = &an_entry;
5983 char buf[MAX_LINELEN];
5988 static s32b old_autosave_turn = 0L;
5991 tb->changed = FALSE;
5994 tb->upper = tb->left = 0;
5996 tb->mx = tb->my = 0;
5997 tb->old_cy = tb->old_upper = tb->old_left = -1;
5998 tb->old_wid = tb->old_hgt = -1;
6002 tb->search_o_ptr = NULL;
6003 tb->search_str = NULL;
6004 tb->last_destroyed = NULL;
6005 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6006 tb->dirty_line = -1;
6007 tb->filename_mode = PT_DEFAULT;
6009 if (current_world_ptr->game_turn < old_autosave_turn)
6011 while (old_autosave_turn > current_world_ptr->game_turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
6015 if (current_world_ptr->game_turn > old_autosave_turn + 100L)
6017 do_cmd_save_game(TRUE);
6018 old_autosave_turn = current_world_ptr->game_turn;
6021 /* HACK -- Reset start_time to stop counting current_world_ptr->play_time while edit */
6024 /* Free old entries */
6027 /* Command Description of the 'Last Destroyed Item' */
6028 if (autopick_last_destroyed_object.k_idx)
6030 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6031 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6034 /* Read or initialize whole text */
6035 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6037 /* Reset cursor position if needed */
6038 for (i = 0; i < tb->cy; i++)
6040 if (!tb->lines_list[i])
6042 tb->cy = tb->cx = 0;
6048 /* Process requests until done */
6053 /* Draw_everythig */
6054 draw_text_editor(tb);
6056 /* Display header line */
6057 prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)",
6058 "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0);
6061 /* Display current position */
6062 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6066 /* Display current position and mark position */
6067 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6071 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6074 tb->dirty_flags = 0;
6075 tb->dirty_line = -1;
6077 /* Save old key and location */
6078 tb->old_cy = tb->cy;
6079 tb->old_upper = tb->upper;
6080 tb->old_left = tb->left;
6081 tb->old_wid = tb->wid;
6082 tb->old_hgt = tb->hgt;
6084 key = inkey_special(TRUE);
6087 if (key & SKEY_MASK)
6089 /* Get a movement command */
6090 com_id = analyze_move_key(tb, key);
6094 else if (key == ESCAPE)
6096 com_id = do_command_menu(0, 0);
6098 /* Redraw all text later */
6099 tb->dirty_flags |= DIRTY_SCREEN;
6102 /* Insert a character */
6103 else if (!iscntrl((unsigned char)key))
6105 /* Ignore selection */
6111 tb->dirty_flags |= DIRTY_ALL;
6114 insert_single_letter(tb, key);
6120 /* Other commands */
6123 com_id = get_com_id((char)key);
6126 if (com_id) quit = do_editor_command(tb, com_id);
6127 } /* while (TRUE) */
6130 /* Get the filename of preference */
6131 strcpy(buf, pickpref_filename(tb->filename_mode));
6133 if (quit == QUIT_AND_SAVE)
6134 write_text_lines(buf, tb->lines_list);
6136 free_text_lines(tb->lines_list);
6138 string_free(tb->search_str);
6139 string_free(tb->last_destroyed);
6141 /* Destroy string chain */
6142 kill_yank_chain(tb);
6144 /* Reload autopick pref */
6145 process_autopick_file(buf);
6147 /* HACK -- reset start_time so that current_world_ptr->play_time is not increase while edit */
6148 start_time = (u32b)time(NULL);
6150 /* Save cursor location */