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
21 #include "player-status.h"
22 #include "player-move.h"
23 #include "player-class.h"
24 #include "objectkind.h"
25 #include "object-flavor.h"
26 #include "object-hook.h"
32 #include "monsterrace.h"
34 #define MAX_LINELEN 1024
41 #define FLG_UNIDENTIFIED 2
42 #define FLG_IDENTIFIED 3
43 #define FLG_STAR_IDENTIFIED 4
44 #define FLG_COLLECTING 5
45 #define FLG_ARTIFACT 6
48 #define FLG_NAMELESS 11
49 #define FLG_AVERAGE 12
50 #define FLG_WORTHLESS 13
53 #define FLG_BOOSTED 16
54 #define FLG_MORE_DICE 17
55 #define FLG_MORE_BONUS 18
59 #define FLG_UNREADABLE 22
68 #define FLG_WEAPONS 31
69 #define FLG_FAVORITE_WEAPONS 32
71 #define FLG_MISSILES 34
72 #define FLG_DEVICES 35
75 #define FLG_CORPSES 38
76 #define FLG_SPELLBOOKS 39
78 #define FLG_SHIELDS 41
81 #define FLG_AMULETS 44
88 #define FLG_NOUN_BEGIN FLG_ITEMS
89 #define FLG_NOUN_END FLG_BOOTS
93 static GAME_TEXT KEY_ALL[] = "すべての";
94 static GAME_TEXT KEY_UNAWARE[] = "未判明の";
95 static GAME_TEXT KEY_UNIDENTIFIED[] = "未鑑定の";
96 static GAME_TEXT KEY_IDENTIFIED[] = "鑑定済みの";
97 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*鑑定*済みの";
98 static GAME_TEXT KEY_COLLECTING[] = "収集中の";
99 static GAME_TEXT KEY_ARTIFACT[] = "アーティファクト";
100 static GAME_TEXT KEY_EGO[] = "エゴ";
101 static GAME_TEXT KEY_GOOD[] = "上質の";
102 static GAME_TEXT KEY_NAMELESS[] = "無銘の";
103 static GAME_TEXT KEY_AVERAGE[] = "並の";
104 static GAME_TEXT KEY_WORTHLESS[] = "無価値の";
105 static GAME_TEXT KEY_RARE[] = "レアな";
106 static GAME_TEXT KEY_COMMON[] = "ありふれた";
107 static GAME_TEXT KEY_BOOSTED[] = "ダイス目の違う";
108 static GAME_TEXT KEY_MORE_THAN[] = "ダイス目";
109 static GAME_TEXT KEY_DICE[] = "以上の";
110 static GAME_TEXT KEY_MORE_BONUS[] = "修正値";
111 static GAME_TEXT KEY_MORE_BONUS2[] = "以上の";
112 static GAME_TEXT KEY_WANTED[] = "賞金首の";
113 static GAME_TEXT KEY_UNIQUE[] = "ユニーク・モンスターの";
114 static GAME_TEXT KEY_HUMAN[] = "人間の";
115 static GAME_TEXT KEY_UNREADABLE[] = "読めない";
116 static GAME_TEXT KEY_REALM1[] = "第一領域の";
117 static GAME_TEXT KEY_REALM2[] = "第二領域の";
118 static GAME_TEXT KEY_FIRST[] = "1冊目の";
119 static GAME_TEXT KEY_SECOND[] = "2冊目の";
120 static GAME_TEXT KEY_THIRD[] = "3冊目の";
121 static GAME_TEXT KEY_FOURTH[] = "4冊目の";
122 static GAME_TEXT KEY_ITEMS[] = "アイテム";
123 static GAME_TEXT KEY_WEAPONS[] = "武器";
124 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "得意武器";
125 static GAME_TEXT KEY_ARMORS[] = "防具";
126 static GAME_TEXT KEY_MISSILES[] = "矢";
127 static GAME_TEXT KEY_DEVICES[] = "魔法アイテム";
128 static GAME_TEXT KEY_LIGHTS[] = "光源";
129 static GAME_TEXT KEY_JUNKS[] = "がらくた";
130 static GAME_TEXT KEY_CORPSES[] = "死体や骨";
131 static GAME_TEXT KEY_SPELLBOOKS[] = "魔法書";
132 static GAME_TEXT KEY_HAFTED[] = "鈍器";
133 static GAME_TEXT KEY_SHIELDS[] = "盾";
134 static GAME_TEXT KEY_BOWS[] = "弓";
135 static GAME_TEXT KEY_RINGS[] = "指輪";
136 static GAME_TEXT KEY_AMULETS[] = "アミュレット";
137 static GAME_TEXT KEY_SUITS[] = "鎧";
138 static GAME_TEXT KEY_CLOAKS[] = "クローク";
139 static GAME_TEXT KEY_HELMS[] = "兜";
140 static GAME_TEXT KEY_GLOVES[] = "籠手";
141 static GAME_TEXT KEY_BOOTS[] = "靴";
145 static GAME_TEXT KEY_ALL[] = "all";
146 static GAME_TEXT KEY_UNAWARE[] = "unaware";
147 static GAME_TEXT KEY_UNIDENTIFIED[] = "unidentified";
148 static GAME_TEXT KEY_IDENTIFIED[] = "identified";
149 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*identified*";
150 static GAME_TEXT KEY_COLLECTING[] = "collecting";
151 static GAME_TEXT KEY_ARTIFACT[] = "artifact";
152 static GAME_TEXT KEY_EGO[] = "ego";
153 static GAME_TEXT KEY_GOOD[] = "good";
154 static GAME_TEXT KEY_nameLESS[] = "nameless";
155 static GAME_TEXT KEY_AVERAGE[] = "average";
156 static GAME_TEXT KEY_WORTHLESS[] = "worthless";
157 static GAME_TEXT KEY_RARE[] = "rare";
158 static GAME_TEXT KEY_COMMON[] = "common";
159 static GAME_TEXT KEY_BOOSTED[] = "dice boosted";
160 static GAME_TEXT KEY_MORE_THAN[] = "more than";
161 static GAME_TEXT KEY_DICE[] = " dice";
162 static GAME_TEXT KEY_MORE_BONUS[] = "more bonus than";
163 static GAME_TEXT KEY_MORE_BONUS2[] = "";
164 static GAME_TEXT KEY_WANTED[] = "wanted";
165 static GAME_TEXT KEY_UNIQUE[] = "unique monster's";
166 static GAME_TEXT KEY_HUMAN[] = "human";
167 static GAME_TEXT KEY_UNREADABLE[] = "unreadable";
168 static GAME_TEXT KEY_REALM1[] = "first realm's";
169 static GAME_TEXT KEY_REALM2[] = "second realm's";
170 static GAME_TEXT KEY_FIRST[] = "first";
171 static GAME_TEXT KEY_SECOND[] = "second";
172 static GAME_TEXT KEY_THIRD[] = "third";
173 static GAME_TEXT KEY_FOURTH[] = "fourth";
174 static GAME_TEXT KEY_ITEMS[] = "items";
175 static GAME_TEXT KEY_WEAPONS[] = "weapons";
176 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "favorite weapons";
177 static GAME_TEXT KEY_ARMORS[] = "armors";
178 static GAME_TEXT KEY_MISSILES[] = "missiles";
179 static GAME_TEXT KEY_DEVICES[] = "magical devices";
180 static GAME_TEXT KEY_LIGHTS[] = "lights";
181 static GAME_TEXT KEY_JUNKS[] = "junks";
182 static GAME_TEXT KEY_CORPSES[] = "corpses or skeletons";
183 static GAME_TEXT KEY_SPELLBOOKS[] = "spellbooks";
184 static GAME_TEXT KEY_HAFTED[] = "hafted weapons";
185 static GAME_TEXT KEY_SHIELDS[] = "shields";
186 static GAME_TEXT KEY_BOWS[] = "bows";
187 static GAME_TEXT KEY_RINGS[] = "rings";
188 static GAME_TEXT KEY_AMULETS[] = "amulets";
189 static GAME_TEXT KEY_SUITS[] = "suits";
190 static GAME_TEXT KEY_CLOAKS[] = "cloaks";
191 static GAME_TEXT KEY_HELMS[] = "helms";
192 static GAME_TEXT KEY_GLOVES[] = "gloves";
193 static GAME_TEXT KEY_BOOTS[] = "boots";
197 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
198 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
199 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
200 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
203 #define ADD_KEY(KEY) strcat(ptr, KEY)
205 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
207 #define ADD_KEY2(KEY) strcat(ptr, KEY)
209 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
210 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
211 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
212 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
215 static char kanji_colon[] = ":";
220 * 自動拾い/破壊設定のリストに関する変数 / List for auto-picker/destroyer entries
222 int max_autopick = 0; /*!< 現在登録している自動拾い/破壊設定の数 */
223 int max_max_autopick = 0; /*!< 自動拾い/破壊設定の限界数 */
224 autopick_type *autopick_list = NULL; /*!< 自動拾い/破壊設定構造体のポインタ配列 */
227 * A function to create new entry
229 static bool autopick_new_entry(autopick_type *entry, concptr str, bool allow_default)
234 char buf[MAX_LINELEN];
235 concptr prev_ptr, ptr, old_ptr;
238 if (str[0] && str[1] == ':') switch (str[0])
241 case 'A': case 'P': case 'C':
245 entry->flag[0] = entry->flag[1] = 0L;
249 act = DO_AUTOPICK | DO_DISPLAY;
252 if ((act & DO_AUTOPICK) && *str == '!')
255 act |= DO_AUTODESTROY;
258 else if ((act & DO_AUTOPICK) && *str == '~')
261 act |= DONT_AUTOPICK;
264 else if ((act & DO_AUTOPICK) && *str == ';')
267 act |= DO_QUERY_AUTOPICK;
270 else if ((act & DO_DISPLAY) && *str == '(')
279 /* don't mind upper or lower case */
281 for (i = 0; *str; i++)
292 /* Auto-inscription? */
300 if (isupper(c)) c = (char)tolower(c);
306 /* Skip empty line unless allow_default */
307 if (!allow_default && *buf == 0) return FALSE;
309 /* Skip comment line */
310 if (*buf == 0 && insc) return FALSE;
312 ptr = prev_ptr = buf;
315 while (old_ptr != ptr)
317 /* Save current location */
320 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
321 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
322 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
323 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
324 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
325 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
326 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
328 /*** Weapons whose dd*ds is more than nn ***/
329 if (MATCH_KEY2(KEY_MORE_THAN))
334 /* Drop leading spaces */
335 while (' ' == *ptr) ptr++;
338 while ('0' <= *ptr && *ptr <= '9')
340 entry->dice = 10 * entry->dice + (*ptr - '0');
347 (void)MATCH_KEY(KEY_DICE);
348 ADD_FLG(FLG_MORE_DICE);
354 /*** Items whose magical bonus is more than n ***/
355 if (MATCH_KEY2(KEY_MORE_BONUS))
360 /* Drop leading spaces */
361 while (' ' == *ptr) ptr++;
364 while ('0' <= *ptr && *ptr <= '9')
366 entry->bonus = 10 * entry->bonus + (*ptr - '0');
374 (void)MATCH_KEY(KEY_MORE_BONUS2);
376 if (' ' == *ptr) ptr++;
378 ADD_FLG(FLG_MORE_BONUS);
384 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
385 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
386 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
387 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
388 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
389 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
390 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
391 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
392 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
393 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
394 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
395 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
396 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
397 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
398 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
399 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
400 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
403 /* Not yet found any noun */
406 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
408 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
409 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
410 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
411 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
412 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
413 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
414 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
415 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
416 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
417 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
418 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
419 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
420 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
421 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
422 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
423 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
424 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
425 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
426 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
427 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
429 /* Last 'keyword' must be at the correct location */
433 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
436 else if (*ptr == '\0')
438 /* There was no noun */
441 /* Add extra word "items" */
442 ADD_FLG_NOUN(FLG_ITEMS);
449 /* A noun type keyword didn't end correctly */
450 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
455 /* Save this auto-picker entry line */
456 entry->name = string_make(ptr);
458 entry->insc = string_make(insc);
465 * Get auto-picker entry from o_ptr.
467 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
469 /* Assume that object name is to be added */
473 /* エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない */
474 bool bol_mark = FALSE;
476 /* We can always use the ^ mark in English */
477 bool bol_mark = TRUE;
480 GAME_TEXT name_str[MAX_NLEN];
482 /* Initialize name string */
485 entry->insc = string_make(quark_str(o_ptr->inscription));
486 entry->action = DO_AUTOPICK | DO_DISPLAY;
487 entry->flag[0] = entry->flag[1] = 0L;
491 if (!object_is_aware(o_ptr))
493 ADD_FLG(FLG_UNAWARE);
497 /* Not really identified */
498 else if (!object_is_known(o_ptr))
500 if (!(o_ptr->ident & IDENT_SENSE))
502 ADD_FLG(FLG_UNIDENTIFIED);
507 /* Pseudo-identified */
508 switch (o_ptr->feeling)
512 ADD_FLG(FLG_NAMELESS);
518 ADD_FLG(FLG_NAMELESS);
519 ADD_FLG(FLG_WORTHLESS);
525 ADD_FLG(FLG_WORTHLESS);
533 /* XXX No appropriate flag */
538 /* Never reach here */
548 if (object_is_ego(o_ptr))
550 if (object_is_weapon_armour_ammo(o_ptr))
553 * Base name of ego weapons and armors
554 * are almost meaningless.
555 * Register the ego type only.
557 ego_item_type *e_ptr = &e_info[o_ptr->name2];
559 /* エゴ銘には「^」マークが使える */
560 sprintf(name_str, "^%s", e_name + e_ptr->name);
562 /* We ommit the basename and cannot use the ^ mark */
563 strcpy(name_str, e_name + e_ptr->name);
566 /* Don't use the object description */
569 /* Restrict to 'common' equipments */
570 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
577 else if (object_is_artifact(o_ptr))
578 ADD_FLG(FLG_ARTIFACT);
580 /* Non-ego, non-artifact */
583 /* Wearable nameless object */
584 if (object_is_equipment(o_ptr))
585 ADD_FLG(FLG_NAMELESS);
592 /* Melee weapon with boosted dice */
593 if (object_is_melee_weapon(o_ptr))
595 object_kind *k_ptr = &k_info[o_ptr->k_idx];
597 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
598 ADD_FLG(FLG_BOOSTED);
601 /* Wanted monster's corpse */
602 if (object_is_shoukinkubi(o_ptr))
604 REM_FLG(FLG_WORTHLESS);
608 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
609 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
614 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
619 if (o_ptr->tval >= TV_LIFE_BOOK &&
620 !check_book_realm(o_ptr->tval, o_ptr->sval))
622 ADD_FLG(FLG_UNREADABLE);
623 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
626 if (REALM1_BOOK == o_ptr->tval &&
627 p_ptr->pclass != CLASS_SORCERER &&
628 p_ptr->pclass != CLASS_RED_MAGE)
634 if (REALM2_BOOK == o_ptr->tval &&
635 p_ptr->pclass != CLASS_SORCERER &&
636 p_ptr->pclass != CLASS_RED_MAGE)
642 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
644 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
646 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
648 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
651 if (object_is_ammo(o_ptr))
652 ADD_FLG(FLG_MISSILES);
653 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
654 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
655 ADD_FLG(FLG_DEVICES);
656 else if (o_ptr->tval == TV_LITE)
658 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
659 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
661 else if (o_ptr->tval == TV_CORPSE)
662 ADD_FLG(FLG_CORPSES);
663 else if (o_ptr->tval >= TV_LIFE_BOOK)
664 ADD_FLG(FLG_SPELLBOOKS);
665 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
666 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
667 ADD_FLG(FLG_WEAPONS);
668 else if (o_ptr->tval == TV_SHIELD)
669 ADD_FLG(FLG_SHIELDS);
670 else if (o_ptr->tval == TV_BOW)
672 else if (o_ptr->tval == TV_RING)
674 else if (o_ptr->tval == TV_AMULET)
675 ADD_FLG(FLG_AMULETS);
676 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
677 o_ptr->tval == TV_SOFT_ARMOR)
679 else if (o_ptr->tval == TV_CLOAK)
681 else if (o_ptr->tval == TV_HELM)
683 else if (o_ptr->tval == TV_GLOVES)
685 else if (o_ptr->tval == TV_BOOTS)
688 /* Prepare the object description */
691 GAME_TEXT o_name[MAX_NLEN];
693 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
696 * If necessary, add a '^' which indicates the
699 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
702 /* Register the name in lowercase */
703 str_tolower(name_str);
704 entry->name = string_make(name_str);
711 * A function to delete entry
713 static void autopick_free_entry(autopick_type *entry)
715 string_free(entry->name);
716 string_free(entry->insc);
722 #define MAX_AUTOPICK_DEFAULT 200
725 * Initialize the autopick
727 static void init_autopick(void)
729 static const char easy_autopick_inscription[] = "(:=g";
735 max_max_autopick = MAX_AUTOPICK_DEFAULT;
736 C_MAKE(autopick_list, max_max_autopick, autopick_type);
740 /* Clear old entries */
741 for( i = 0; i < max_autopick; i++)
742 autopick_free_entry(&autopick_list[i]);
746 /* There is always one entry "=g" */
747 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
748 autopick_list[max_autopick++] = entry;
753 #define PT_WITH_PNAME 1
756 * Get file name for autopick preference
758 static concptr pickpref_filename(int filename_mode)
760 static const char namebase[] = _("picktype", "pickpref");
762 switch (filename_mode)
765 return format("%s.prf", namebase);
768 return format("%s-%s.prf", namebase, player_base);
777 * Load an autopick preference file
779 void autopick_load_pref(bool disp_mes)
784 /* Free old entries */
787 /* Try a filename with player name */
788 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
791 err = process_autopick_file(buf);
793 if (err == 0 && disp_mes)
796 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
802 /* Use default name */
803 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
806 err = process_autopick_file(buf);
808 if (err == 0 && disp_mes)
811 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
818 msg_print(_("自動拾い設定ファイルの読み込みに失敗しました。", "Failed to reload autopick preference."));
824 * Add one line to autopick_list[]
826 static void add_autopick_list(autopick_type *entry)
828 /* There is no enough space to add one line */
829 if (max_autopick >= max_max_autopick)
831 int old_max_max_autopick = max_max_autopick;
832 autopick_type *old_autopick_list = autopick_list;
834 /* Increase size of list */
835 max_max_autopick += MAX_AUTOPICK_DEFAULT;
838 C_MAKE(autopick_list, max_max_autopick, autopick_type);
840 /* Copy from old list to new list */
841 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
844 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
848 autopick_list[max_autopick] = *entry;
855 * Process line for auto picker/destroyer.
857 errr process_autopick_file_command(char *buf)
859 autopick_type an_entry, *entry = &an_entry;
862 /* Nuke illegal char */
863 for(i = 0; buf[i]; i++)
872 if (iswspace(buf[i]) && buf[i] != ' ')
877 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
879 /* Already has the same entry? */
880 for(i = 0; i < max_autopick; i++)
881 if(!strcmp(entry->name, autopick_list[i].name)
882 && entry->flag[0] == autopick_list[i].flag[0]
883 && entry->flag[1] == autopick_list[i].flag[1]
884 && entry->dice == autopick_list[i].dice
885 && entry->bonus == autopick_list[i].bonus)
887 autopick_free_entry(entry);
891 add_autopick_list(entry);
897 * Reconstruct preference line from entry
899 concptr autopick_line_from_entry(autopick_type *entry)
901 char buf[MAX_LINELEN];
903 bool sepa_flag = TRUE;
906 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
907 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
908 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
909 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
913 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
914 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
915 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
916 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
917 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
918 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
919 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
921 if (IS_FLG(FLG_MORE_DICE))
923 ADD_KEY(KEY_MORE_THAN);
924 strcat(ptr, format("%d", entry->dice));
928 if (IS_FLG(FLG_MORE_BONUS))
930 ADD_KEY(KEY_MORE_BONUS);
931 strcat(ptr, format("%d", entry->bonus));
932 ADD_KEY(KEY_MORE_BONUS2);
935 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
936 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
937 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
938 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
939 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
940 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
941 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
942 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
943 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
944 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
945 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
946 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
947 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
948 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
949 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
950 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
951 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
953 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
955 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
956 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
957 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
958 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
959 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
960 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
961 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
962 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
963 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
964 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
965 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
966 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
967 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
968 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
969 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
970 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
971 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
972 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
973 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
974 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
976 /* You don't need sepalator after adjective */
977 /* 'artifact' is not true adjective */
978 else if (!IS_FLG(FLG_ARTIFACT))
981 if (entry->name && entry->name[0])
985 if (sepa_flag) strcat(buf, ":");
988 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
991 if (iskanji(entry->name[j]))
992 buf[i++] = entry->name[j++];
994 buf[i++] = entry->name[j++];
1005 while (entry->insc[j] && i < MAX_LINELEN - 2)
1008 if (iskanji(entry->insc[j]))
1009 buf[i++] = entry->insc[j++];
1011 buf[i++] = entry->insc[j++];
1016 return string_make(buf);
1021 * Reconstruct preference line from entry and kill entry
1023 static concptr autopick_line_from_entry_kill(autopick_type *entry)
1025 concptr ptr = autopick_line_from_entry(entry);
1027 /* Free memory for original entry */
1028 autopick_free_entry(entry);
1035 * A function for Auto-picker/destroyer
1036 * Examine whether the object matches to the entry
1038 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_name)
1041 concptr ptr = entry->name;
1043 /*** Unaware items ***/
1044 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1047 /*** Unidentified ***/
1048 if (IS_FLG(FLG_UNIDENTIFIED)
1049 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1052 /*** Identified ***/
1053 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1056 /*** *Identified* ***/
1057 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1058 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1061 /*** Dice boosted (weapon of slaying) ***/
1062 if (IS_FLG(FLG_BOOSTED))
1064 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1066 /* Require melee weapon */
1067 if (!object_is_melee_weapon(o_ptr))
1070 /* Require boosted dice */
1071 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1074 /* In Vault Quest, Dice must be hide.*/
1075 if(!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
1081 /*** Weapons which dd*ds is more than nn ***/
1082 if (IS_FLG(FLG_MORE_DICE))
1084 if (o_ptr->dd * o_ptr->ds < entry->dice)
1088 /*** Weapons whic dd*ds is more than nn ***/
1089 if (IS_FLG(FLG_MORE_BONUS))
1091 if (!object_is_known(o_ptr)) return FALSE;
1095 if (o_ptr->pval < entry->bonus) return FALSE;
1099 if (o_ptr->to_h < entry->bonus &&
1100 o_ptr->to_d < entry->bonus &&
1101 o_ptr->to_a < entry->bonus &&
1102 o_ptr->pval < entry->bonus)
1107 /*** Worthless items ***/
1108 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1111 /*** Artifact object ***/
1112 if (IS_FLG(FLG_ARTIFACT))
1114 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1118 /*** Ego object ***/
1119 if (IS_FLG(FLG_EGO))
1121 /* Need to be an ego item */
1122 if (!object_is_ego(o_ptr)) return FALSE;
1124 /* Need to be known to be an ego */
1125 if (!object_is_known(o_ptr) &&
1126 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1131 if (IS_FLG(FLG_GOOD))
1133 if (!object_is_equipment(o_ptr)) return FALSE;
1136 if (object_is_known(o_ptr))
1138 /* Artifacts and Ego objects are not okay */
1139 if (!object_is_nameless(o_ptr))
1142 /* Average are not okay */
1143 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1147 /* Pseudo-identified */
1148 else if (o_ptr->ident & IDENT_SENSE)
1150 switch (o_ptr->feeling)
1165 /* Not known to be good */
1171 if (IS_FLG(FLG_NAMELESS))
1173 if (!object_is_equipment(o_ptr)) return FALSE;
1176 if (object_is_known(o_ptr))
1178 /* Artifacts and Ego objects are not okay */
1179 if (!object_is_nameless(o_ptr))
1183 /* Pseudo-identified */
1184 else if (o_ptr->ident & IDENT_SENSE)
1186 switch (o_ptr->feeling)
1196 /* It's not nameless */
1204 /* Not known to be nameless */
1210 if (IS_FLG(FLG_AVERAGE))
1212 if (!object_is_equipment(o_ptr)) return FALSE;
1215 if (object_is_known(o_ptr))
1217 /* Artifacts and Ego objects are not okay */
1218 if (!object_is_nameless(o_ptr))
1221 /* Cursed or broken objects are not okay */
1222 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1225 /* Good are not okay */
1226 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1230 /* Pseudo-identified */
1231 else if (o_ptr->ident & IDENT_SENSE)
1233 switch (o_ptr->feeling)
1240 /* It's not average */
1248 /* Not known to be average */
1253 /*** Rere equipments ***/
1254 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1257 /*** Common equipments ***/
1258 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1261 /*** Wanted monster's corpse/skeletons ***/
1262 if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
1265 /*** Unique monster's corpse/skeletons/statues ***/
1266 if (IS_FLG(FLG_UNIQUE) &&
1267 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1268 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1271 /*** Human corpse/skeletons (for Daemon magic) ***/
1272 if (IS_FLG(FLG_HUMAN) &&
1273 (o_ptr->tval != TV_CORPSE ||
1274 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1277 /*** Unreadable spellbooks ***/
1278 if (IS_FLG(FLG_UNREADABLE) &&
1279 (o_ptr->tval < TV_LIFE_BOOK ||
1280 check_book_realm(o_ptr->tval, o_ptr->sval)))
1283 /*** First realm spellbooks ***/
1284 if (IS_FLG(FLG_REALM1) &&
1285 (REALM1_BOOK != o_ptr->tval ||
1286 p_ptr->pclass == CLASS_SORCERER ||
1287 p_ptr->pclass == CLASS_RED_MAGE))
1290 /*** Second realm spellbooks ***/
1291 if (IS_FLG(FLG_REALM2) &&
1292 (REALM2_BOOK != o_ptr->tval ||
1293 p_ptr->pclass == CLASS_SORCERER ||
1294 p_ptr->pclass == CLASS_RED_MAGE))
1297 /*** First rank spellbooks ***/
1298 if (IS_FLG(FLG_FIRST) &&
1299 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1302 /*** Second rank spellbooks ***/
1303 if (IS_FLG(FLG_SECOND) &&
1304 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1307 /*** Third rank spellbooks ***/
1308 if (IS_FLG(FLG_THIRD) &&
1309 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1312 /*** Fourth rank spellbooks ***/
1313 if (IS_FLG(FLG_FOURTH) &&
1314 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1318 if (IS_FLG(FLG_WEAPONS))
1320 if (!object_is_weapon(o_ptr))
1323 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1325 if (!object_is_favorite(o_ptr))
1328 else if (IS_FLG(FLG_ARMORS))
1330 if (!object_is_armour(o_ptr))
1333 else if (IS_FLG(FLG_MISSILES))
1335 if (!object_is_ammo(o_ptr)) return FALSE;
1337 else if (IS_FLG(FLG_DEVICES))
1341 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1343 default: return FALSE;
1346 else if (IS_FLG(FLG_LIGHTS))
1348 if (!(o_ptr->tval == TV_LITE))
1351 else if (IS_FLG(FLG_JUNKS))
1355 case TV_SKELETON: case TV_BOTTLE:
1356 case TV_JUNK: case TV_STATUE:
1358 default: return FALSE;
1361 else if (IS_FLG(FLG_CORPSES))
1363 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1366 else if (IS_FLG(FLG_SPELLBOOKS))
1368 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1371 else if (IS_FLG(FLG_HAFTED))
1373 if (!(o_ptr->tval == TV_HAFTED))
1376 else if (IS_FLG(FLG_SHIELDS))
1378 if (!(o_ptr->tval == TV_SHIELD))
1381 else if (IS_FLG(FLG_BOWS))
1383 if (!(o_ptr->tval == TV_BOW))
1386 else if (IS_FLG(FLG_RINGS))
1388 if (!(o_ptr->tval == TV_RING))
1391 else if (IS_FLG(FLG_AMULETS))
1393 if (!(o_ptr->tval == TV_AMULET))
1396 else if (IS_FLG(FLG_SUITS))
1398 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1399 o_ptr->tval == TV_HARD_ARMOR ||
1400 o_ptr->tval == TV_SOFT_ARMOR))
1403 else if (IS_FLG(FLG_CLOAKS))
1405 if (!(o_ptr->tval == TV_CLOAK))
1408 else if (IS_FLG(FLG_HELMS))
1410 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1413 else if (IS_FLG(FLG_GLOVES))
1415 if (!(o_ptr->tval == TV_GLOVES))
1418 else if (IS_FLG(FLG_BOOTS))
1420 if (!(o_ptr->tval == TV_BOOTS))
1424 /* Keyword don't match */
1428 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1432 if (!my_strstr(o_name, ptr)) return FALSE;
1435 /* TRUE when it need not to be 'collecting' */
1436 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1438 /* Check if there is a same item */
1439 for (j = 0; j < INVEN_PACK; j++)
1442 * 'Collecting' means the item must be absorbed
1443 * into an p_ptr->inventory_list slot.
1444 * But an item can not be absorbed into itself!
1446 if ((&p_ptr->inventory_list[j] != o_ptr) &&
1447 object_similar(&p_ptr->inventory_list[j], o_ptr))
1451 /* Not collecting */
1457 * A function for Auto-picker/destroyer
1458 * Examine whether the object matches to the list of keywords or not.
1460 int is_autopick(object_type *o_ptr)
1463 GAME_TEXT o_name[MAX_NLEN];
1465 if (o_ptr->tval == TV_GOLD) return -1;
1467 /* Prepare object name string first */
1468 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1470 /* Convert the string to lower case */
1471 str_tolower(o_name);
1473 /* Look for a matching entry in the list */
1474 for (i=0; i < max_autopick; i++)
1476 autopick_type *entry = &autopick_list[i];
1478 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1481 /* No matching entry */
1489 static void auto_inscribe_item(object_type *o_ptr, int idx)
1491 /* Are there auto-inscription? */
1492 if (idx < 0 || !autopick_list[idx].insc) return;
1494 if (!o_ptr->inscription)
1495 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1497 /* Redraw inscription */
1498 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1500 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1501 p_ptr->update |= (PU_BONUS);
1506 * Automatically destroy items in this grid.
1508 static bool is_opt_confirm_destroy(object_type *o_ptr)
1510 if (!destroy_items) return FALSE;
1512 /* Known to be worthless? */
1514 if (object_value(o_ptr) > 0) return FALSE;
1517 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1520 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1524 if (object_is_shoukinkubi(o_ptr)) return FALSE;
1528 if (o_ptr->tval == TV_CORPSE) return FALSE;
1531 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1535 if (p_ptr->prace == RACE_DEMON)
1537 if (o_ptr->tval == TV_CORPSE &&
1538 o_ptr->sval == SV_CORPSE &&
1539 my_strchr("pht", r_info[o_ptr->pval].d_char))
1543 if (p_ptr->pclass == CLASS_ARCHER)
1545 if (o_ptr->tval == TV_SKELETON ||
1546 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1549 else if (p_ptr->pclass == CLASS_NINJA)
1551 if (o_ptr->tval == TV_LITE &&
1552 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1555 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1556 p_ptr->pclass == CLASS_CAVALRY)
1558 if (o_ptr->tval == TV_WAND &&
1559 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1564 if (o_ptr->tval == TV_GOLD) return FALSE;
1571 * Automatically destroy an item if it is to be destroyed
1573 * When always_pickup is 'yes', we disable auto-destroyer function of
1574 * auto-picker/destroyer, and do only easy-auto-destroyer.
1576 static object_type autopick_last_destroyed_object;
1578 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1580 bool destroy = FALSE;
1582 /* Easy-Auto-Destroyer (3rd priority) */
1583 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1585 /* Protected by auto-picker (2nd priotity) */
1586 if (autopick_idx >= 0 &&
1587 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1590 /* Auto-destroyer works only when !always_pickup */
1593 /* Auto-picker/destroyer (1st priority) */
1594 if (autopick_idx >= 0 &&
1595 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1599 /* Not to be destroyed */
1600 if (!destroy) return;
1602 /* Now decided to destroy */
1604 disturb(FALSE, FALSE);
1607 if (!can_player_destroy_object(o_ptr))
1609 GAME_TEXT o_name[MAX_NLEN];
1611 /* Describe the object (with {terrible/special}) */
1612 object_desc(o_name, o_ptr, 0);
1614 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1619 /* Record name of destroyed item */
1620 (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1623 o_ptr->marked |= OM_AUTODESTROY;
1624 p_ptr->update |= PU_AUTODESTROY;
1631 * Auto-destroy marked item
1633 static void autopick_delayed_alter_aux(INVENTORY_IDX item)
1637 /* Get the item (in the pack) */
1638 if (item >= 0) o_ptr = &p_ptr->inventory_list[item];
1640 /* Get the item (on the floor) */
1641 else o_ptr = ¤t_floor_ptr->o_list[0 - item];
1643 if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
1645 GAME_TEXT o_name[MAX_NLEN];
1647 /* Describe the object (with {terrible/special}) */
1648 object_desc(o_name, o_ptr, 0);
1650 /* Eliminate the item (from the pack) */
1653 inven_item_increase(item, -(o_ptr->number));
1654 inven_item_optimize(item);
1657 /* Eliminate the item (from the floor) */
1660 delete_object_idx(0 - item);
1663 msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name);
1669 * Auto-destroy marked items in inventry and on floor
1671 void autopick_delayed_alter(void)
1676 * Scan inventry in reverse order to prevent
1677 * skipping after inven_item_optimize()
1679 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1680 autopick_delayed_alter_aux(item);
1682 /* Scan the pile of objects */
1683 item = current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx;
1686 OBJECT_IDX next = current_floor_ptr->o_list[item].next_o_idx;
1687 autopick_delayed_alter_aux(-item);
1694 * Auto-inscription and/or destroy
1696 * Auto-destroyer works only on p_ptr->inventory_list or on floor stack only when
1699 void autopick_alter_item(INVENTORY_IDX item, bool destroy)
1704 /* Get the item (in the pack) */
1705 if (item >= 0) o_ptr = &p_ptr->inventory_list[item];
1707 /* Get the item (on the floor) */
1708 else o_ptr = ¤t_floor_ptr->o_list[0 - item];
1710 /* Get the index in the auto-pick/destroy list */
1711 idx = is_autopick(o_ptr);
1713 /* Do auto-inscription */
1714 auto_inscribe_item(o_ptr, idx);
1716 /* Do auto-destroy if needed */
1717 if (destroy && item <= INVEN_PACK)
1718 auto_destroy_item(o_ptr, idx);
1723 * Automatically pickup/destroy items in this grid.
1725 void autopick_pickup_items(grid_type *g_ptr)
1727 OBJECT_IDX this_o_idx, next_o_idx = 0;
1729 /* Scan the pile of objects */
1730 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1733 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1734 next_o_idx = o_ptr->next_o_idx;
1736 idx = is_autopick(o_ptr);
1738 /* Item index for floor -1,-2,-3,... */
1739 auto_inscribe_item(o_ptr, idx);
1742 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1744 disturb(FALSE, FALSE);
1746 if (!inven_carry_okay(o_ptr))
1748 GAME_TEXT o_name[MAX_NLEN];
1750 object_desc(o_name, o_ptr, 0);
1752 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
1753 /* Hack - remember that the item has given a message here. */
1754 o_ptr->marked |= OM_NOMSG;
1758 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1760 char out_val[MAX_NLEN+20];
1761 GAME_TEXT o_name[MAX_NLEN];
1763 if (o_ptr->marked & OM_NO_QUERY)
1765 /* Already answered as 'No' */
1769 object_desc(o_name, o_ptr, 0);
1771 sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
1773 if (!get_check(out_val))
1775 /* Hack - remember that the item has given a message here. */
1776 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1781 py_pickup_aux(this_o_idx);
1786 * When always_pickup is 'yes', we disable
1787 * auto-destroyer from autopick function, and do only
1788 * easy-auto-destroyer.
1792 auto_destroy_item(o_ptr, idx);
1798 static const char autoregister_header[] = "?:$AUTOREGISTER";
1801 * Clear auto registered lines in the picktype.prf .
1803 static bool clear_auto_register(void)
1805 char tmp_file[1024];
1806 char pref_file[1024];
1811 bool autoregister = FALSE;
1814 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1815 pref_fff = my_fopen(pref_file, "r");
1819 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1820 pref_fff = my_fopen(pref_file, "r");
1829 /* Open a new (temporary) file */
1830 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1834 /* Close the preference file */
1836 msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
1842 /* Loop for every line */
1846 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1850 /* Delete auto-registered line */
1852 /* Count auto-destroy preference lines */
1853 if (buf[0] != '#' && buf[0] != '?') num++;
1856 /* We are looking for auto-registered line */
1859 if (streq(buf, autoregister_header))
1861 /* Delete all further lines */
1862 autoregister = TRUE;
1866 /* Copy orginally lines */
1867 fprintf(tmp_fff, "%s\n", buf);
1873 my_fclose(pref_fff);
1878 msg_format(_("以前のキャラクター用の自動設定(%d行)が残っています。",
1879 "Auto registered lines (%d lines) for previous character are remaining."), num);
1880 strcpy(buf, _("古い設定行は削除します。よろしいですか?", "These lines will be deleted. Are you sure? "));
1882 /* You can cancel it */
1883 if (!get_check(buf))
1886 autoregister = FALSE;
1888 msg_print(_("エディタのカット&ペースト等を使って必要な行を避難してください。",
1889 "Use cut & paste of auto picker editor (_) to keep old prefs."));
1894 /* If there are some changes, overwrite the original file with new one */
1897 /* Copy contents of temporary file */
1899 tmp_fff = my_fopen(tmp_file, "r");
1900 pref_fff = my_fopen(pref_file, "w");
1902 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1903 fprintf(pref_fff, "%s\n", buf);
1905 my_fclose(pref_fff);
1909 /* Kill the temporary file */
1917 * Automatically register an auto-destroy preference line
1919 bool autopick_autoregister(object_type *o_ptr)
1922 char pref_file[1024];
1924 autopick_type an_entry, *entry = &an_entry;
1926 int match_autopick = is_autopick(o_ptr);
1928 /* Already registered */
1929 if (match_autopick != -1)
1932 byte act = autopick_list[match_autopick].action;
1934 if (act & DO_AUTOPICK) what = _("自動で拾う", "auto-pickup");
1935 else if (act & DO_AUTODESTROY) what = _("自動破壊する", "auto-destroy");
1936 else if (act & DONT_AUTOPICK) what = _("放置する", "leave on floor");
1937 else /* if (act & DO_QUERY_AUTOPICK) */ what = _("確認して拾う", "query auto-pickup");
1939 msg_format(_("そのアイテムは既に%sように設定されています。", "The object is already registered to %s."), what);
1943 /* Known to be an artifact? */
1944 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1945 ((o_ptr->ident & IDENT_SENSE) &&
1946 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1948 GAME_TEXT o_name[MAX_NLEN];
1950 /* Describe the object (with {terrible/special}) */
1951 object_desc(o_name, o_ptr, 0);
1953 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1959 if (!p_ptr->autopick_autoregister)
1961 /* Clear old auto registered lines */
1962 if (!clear_auto_register()) return FALSE;
1965 /* Try a filename with player name */
1966 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1967 pref_fff = my_fopen(pref_file, "r");
1971 /* Use default name */
1972 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1973 pref_fff = my_fopen(pref_file, "r");
1976 /* Check the header */
1980 if (my_fgets(pref_fff, buf, sizeof(buf)))
1982 /* No header found */
1983 p_ptr->autopick_autoregister = FALSE;
1988 if (streq(buf, autoregister_header))
1990 /* Found the header */
1991 p_ptr->autopick_autoregister = TRUE;
1997 /* Close read only FILE* */
2000 /* Open for append */
2001 pref_fff = my_fopen(pref_file, "a");
2005 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), pref_file);
2012 if (!p_ptr->autopick_autoregister)
2014 /* Add the header */
2015 fprintf(pref_fff, "%s\n", autoregister_header);
2017 fprintf(pref_fff, "%s\n", _("# *警告!!* 以降の行は自動登録されたものです。",
2018 "# *Waring!* The lines below will be deleated later."));
2019 fprintf(pref_fff, "%s\n", _("# 後で自動的に削除されますので、必要な行は上の方へ移動しておいてください。",
2020 "# Keep it by cut & paste if you need these lines for future characters."));
2022 /* Now auto register is in-use */
2023 p_ptr->autopick_autoregister = TRUE;
2026 /* Get a preference entry */
2027 autopick_entry_from_object(entry, o_ptr);
2029 /* Set to auto-destroy (with no-display) */
2030 entry->action = DO_AUTODESTROY;
2032 /* Load the new line as preference */
2033 add_autopick_list(entry);
2035 /* Add a line to the file */
2036 /* Don't kill "entry" */
2037 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2044 /******** Auto-picker/destroyer editor **********/
2046 #define MAX_YANK MAX_LINELEN
2047 #define MAX_LINES 3000
2049 #define MARK_MARK 0x01
2050 #define MARK_BY_SHIFT 0x02
2052 #define LSTAT_BYPASS 0x01
2053 #define LSTAT_EXPRESSION 0x02
2054 #define LSTAT_AUTOREGISTER 0x04
2056 #define QUIT_WITHOUT_SAVE 1
2057 #define QUIT_AND_SAVE 2
2060 * Struct for yank buffer
2062 typedef struct chain_str {
2063 struct chain_str *next;
2069 * Data struct for text editor
2075 int old_wid, old_hgt;
2077 int old_upper, old_left;
2081 object_type *search_o_ptr;
2083 concptr last_destroyed;
2085 chain_str_type *yank;
2088 concptr *lines_list;
2089 byte states[MAX_LINES];
2101 * Dirty flag for text editor
2103 #define DIRTY_ALL 0x0001
2104 #define DIRTY_MODE 0x0004
2105 #define DIRTY_SCREEN 0x0008
2106 #define DIRTY_NOT_FOUND 0x0010
2107 #define DIRTY_NO_SEARCH 0x0020
2108 #define DIRTY_EXPRESSION 0x0040
2109 #define DIRTY_SKIP_INACTIVE 0x0080
2110 #define DIRTY_INACTIVE 0x0100
2113 * Describe which kind of object is Auto-picked/destroyed
2115 static void describe_autopick(char *buff, autopick_type *entry)
2117 concptr str = entry->name;
2118 byte act = entry->action;
2119 concptr insc = entry->insc;
2125 concptr before_str[100], body_str;
2130 /*** Collecting items ***/
2131 /*** Which can be absorbed into a slot as a bundle ***/
2132 if (IS_FLG(FLG_COLLECTING))
2133 before_str[before_n++] = "収集中で既に持っているスロットにまとめられる";
2135 /*** Unaware items ***/
2136 if (IS_FLG(FLG_UNAWARE))
2137 before_str[before_n++] = "未鑑定でその効果も判明していない";
2139 /*** Unidentified ***/
2140 if (IS_FLG(FLG_UNIDENTIFIED))
2141 before_str[before_n++] = "未鑑定の";
2143 /*** Identified ***/
2144 if (IS_FLG(FLG_IDENTIFIED))
2145 before_str[before_n++] = "鑑定済みの";
2147 /*** *Identified* ***/
2148 if (IS_FLG(FLG_STAR_IDENTIFIED))
2149 before_str[before_n++] = "完全に鑑定済みの";
2151 /*** Dice boosted (weapon of slaying) ***/
2152 if (IS_FLG(FLG_BOOSTED))
2154 before_str[before_n++] = "ダメージダイスが通常より大きい";
2158 /*** Weapons whose dd*ds is more than nn ***/
2159 if (IS_FLG(FLG_MORE_DICE))
2161 static char more_than_desc_str[] = "___";
2162 before_str[before_n++] = "ダメージダイスの最大値が";
2165 sprintf(more_than_desc_str,"%d", entry->dice);
2166 before_str[before_n++] = more_than_desc_str;
2167 before_str[before_n++] = "以上の";
2170 /*** Items whose magical bonus is more than nn ***/
2171 if (IS_FLG(FLG_MORE_BONUS))
2173 static char more_bonus_desc_str[] = "___";
2174 before_str[before_n++] = "修正値が(+";
2176 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2177 before_str[before_n++] = more_bonus_desc_str;
2178 before_str[before_n++] = ")以上の";
2181 /*** Worthless items ***/
2182 if (IS_FLG(FLG_WORTHLESS))
2183 before_str[before_n++] = "店で無価値と判定される";
2186 if (IS_FLG(FLG_ARTIFACT))
2188 before_str[before_n++] = "アーティファクトの";
2193 if (IS_FLG(FLG_EGO))
2195 before_str[before_n++] = "エゴアイテムの";
2200 if (IS_FLG(FLG_GOOD))
2202 before_str[before_n++] = "上質の";
2207 if (IS_FLG(FLG_NAMELESS))
2209 before_str[before_n++] = "エゴでもアーティファクトでもない";
2214 if (IS_FLG(FLG_AVERAGE))
2216 before_str[before_n++] = "並の";
2220 /*** Rare equipments ***/
2221 if (IS_FLG(FLG_RARE))
2223 before_str[before_n++] = "ドラゴン装備やカオス・ブレード等を含む珍しい";
2227 /*** Common equipments ***/
2228 if (IS_FLG(FLG_COMMON))
2230 before_str[before_n++] = "ありふれた(ドラゴン装備やカオス・ブレード等の珍しい物ではない)";
2234 /*** Wanted monster's corpse/skeletons ***/
2235 if (IS_FLG(FLG_WANTED))
2237 before_str[before_n++] = "ハンター事務所で賞金首とされている";
2241 /*** Human corpse/skeletons (for Daemon magic) ***/
2242 if (IS_FLG(FLG_HUMAN))
2244 before_str[before_n++] = "悪魔魔法で使うための人間やヒューマノイドの";
2248 /*** Unique monster's corpse/skeletons/statues ***/
2249 if (IS_FLG(FLG_UNIQUE))
2251 before_str[before_n++] = "ユニークモンスターの";
2255 /*** Unreadable spellbooks ***/
2256 if (IS_FLG(FLG_UNREADABLE))
2258 before_str[before_n++] = "あなたが読めない領域の";
2262 /*** First realm spellbooks ***/
2263 if (IS_FLG(FLG_REALM1))
2265 before_str[before_n++] = "第一領域の";
2269 /*** Second realm spellbooks ***/
2270 if (IS_FLG(FLG_REALM2))
2272 before_str[before_n++] = "第二領域の";
2276 /*** First rank spellbooks ***/
2277 if (IS_FLG(FLG_FIRST))
2279 before_str[before_n++] = "全4冊の内の1冊目の";
2283 /*** Second rank spellbooks ***/
2284 if (IS_FLG(FLG_SECOND))
2286 before_str[before_n++] = "全4冊の内の2冊目の";
2290 /*** Third rank spellbooks ***/
2291 if (IS_FLG(FLG_THIRD))
2293 before_str[before_n++] = "全4冊の内の3冊目の";
2297 /*** Fourth rank spellbooks ***/
2298 if (IS_FLG(FLG_FOURTH))
2300 before_str[before_n++] = "全4冊の内の4冊目の";
2305 if (IS_FLG(FLG_ITEMS))
2306 ; /* Nothing to do */
2307 else if (IS_FLG(FLG_WEAPONS))
2309 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2311 else if (IS_FLG(FLG_ARMORS))
2313 else if (IS_FLG(FLG_MISSILES))
2314 body_str = "弾や矢やクロスボウの矢";
2315 else if (IS_FLG(FLG_DEVICES))
2316 body_str = "巻物や魔法棒や杖やロッド";
2317 else if (IS_FLG(FLG_LIGHTS))
2318 body_str = "光源用のアイテム";
2319 else if (IS_FLG(FLG_JUNKS))
2320 body_str = "折れた棒等のガラクタ";
2321 else if (IS_FLG(FLG_CORPSES))
2323 else if (IS_FLG(FLG_SPELLBOOKS))
2325 else if (IS_FLG(FLG_HAFTED))
2327 else if (IS_FLG(FLG_SHIELDS))
2329 else if (IS_FLG(FLG_BOWS))
2330 body_str = "スリングや弓やクロスボウ";
2331 else if (IS_FLG(FLG_RINGS))
2333 else if (IS_FLG(FLG_AMULETS))
2334 body_str = "アミュレット";
2335 else if (IS_FLG(FLG_SUITS))
2337 else if (IS_FLG(FLG_CLOAKS))
2339 else if (IS_FLG(FLG_HELMS))
2340 body_str = "ヘルメットや冠";
2341 else if (IS_FLG(FLG_GLOVES))
2343 else if (IS_FLG(FLG_BOOTS))
2348 strcat(buff, "全ての");
2349 else for (i = 0; i < before_n && before_str[i]; i++)
2350 strcat(buff, before_str[i]);
2352 strcat(buff, body_str);
2362 strcat(buff, "で、名前が「");
2363 strncat(buff, str, 80);
2365 strcat(buff, "」で始まるもの");
2367 strcat(buff, "」を含むもの");
2372 strncat(buff, format("に「%s」", insc), 80);
2374 if (my_strstr(insc, "%%all"))
2375 strcat(buff, "(%%allは全能力を表す英字の記号で置換)");
2376 else if (my_strstr(insc, "%all"))
2377 strcat(buff, "(%allは全能力を表す記号で置換)");
2378 else if (my_strstr(insc, "%%"))
2379 strcat(buff, "(%%は追加能力を表す英字の記号で置換)");
2380 else if (my_strstr(insc, "%"))
2381 strcat(buff, "(%は追加能力を表す記号で置換)");
2383 strcat(buff, "と刻んで");
2388 if (act & DONT_AUTOPICK)
2389 strcat(buff, "放置する。");
2390 else if (act & DO_AUTODESTROY)
2391 strcat(buff, "破壊する。");
2392 else if (act & DO_QUERY_AUTOPICK)
2393 strcat(buff, "確認の後に拾う。");
2395 strcat(buff, "拾う。");
2397 if (act & DO_DISPLAY)
2399 if (act & DONT_AUTOPICK)
2400 strcat(buff, "全体マップ('M')で'N'を押したときに表示する。");
2401 else if (act & DO_AUTODESTROY)
2402 strcat(buff, "全体マップ('M')で'K'を押したときに表示する。");
2404 strcat(buff, "全体マップ('M')で'M'を押したときに表示する。");
2407 strcat(buff, "全体マップには表示しない。");
2411 concptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2412 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2416 /*** Collecting items ***/
2417 /*** Which can be absorbed into a slot as a bundle ***/
2418 if (IS_FLG(FLG_COLLECTING))
2419 which_str[which_n++] = "can be absorbed into an existing p_ptr->inventory_list slot";
2421 /*** Unaware items ***/
2422 if (IS_FLG(FLG_UNAWARE))
2424 before_str[before_n++] = "unidentified";
2425 whose_str[whose_n++] = "basic abilities are not known";
2428 /*** Unidentified ***/
2429 if (IS_FLG(FLG_UNIDENTIFIED))
2430 before_str[before_n++] = "unidentified";
2432 /*** Identified ***/
2433 if (IS_FLG(FLG_IDENTIFIED))
2434 before_str[before_n++] = "identified";
2436 /*** *Identified* ***/
2437 if (IS_FLG(FLG_STAR_IDENTIFIED))
2438 before_str[before_n++] = "fully identified";
2440 /*** Rare equipments ***/
2441 if (IS_FLG(FLG_RARE))
2443 before_str[before_n++] = "very rare";
2444 body_str = "equipments";
2445 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2448 /*** Common equipments ***/
2449 if (IS_FLG(FLG_COMMON))
2451 before_str[before_n++] = "relatively common";
2452 body_str = "equipments";
2453 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2456 /*** Worthless items ***/
2457 if (IS_FLG(FLG_WORTHLESS))
2459 before_str[before_n++] = "worthless";
2460 which_str[which_n++] = "can not be sold at stores";
2464 if (IS_FLG(FLG_ARTIFACT))
2466 before_str[before_n++] = "artifact";
2470 if (IS_FLG(FLG_EGO))
2472 before_str[before_n++] = "ego";
2476 if (IS_FLG(FLG_GOOD))
2478 body_str = "equipment";
2479 which_str[which_n++] = "have good quality";
2483 if (IS_FLG(FLG_NAMELESS))
2485 body_str = "equipment";
2486 which_str[which_n++] = "is neither ego-item nor artifact";
2490 if (IS_FLG(FLG_AVERAGE))
2492 body_str = "equipment";
2493 which_str[which_n++] = "have average quality";
2496 /*** Dice boosted (weapon of slaying) ***/
2497 if (IS_FLG(FLG_BOOSTED))
2499 body_str = "weapons";
2500 whose_str[whose_n++] = "damage dice is bigger than normal";
2503 /*** Weapons whose dd*ds is more than nn ***/
2504 if (IS_FLG(FLG_MORE_DICE))
2506 static char more_than_desc_str[] =
2507 "maximum damage from dice is bigger than __";
2508 body_str = "weapons";
2510 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2512 whose_str[whose_n++] = more_than_desc_str;
2515 /*** Items whose magical bonus is more than nn ***/
2516 if (IS_FLG(FLG_MORE_BONUS))
2518 static char more_bonus_desc_str[] =
2519 "magical bonus is bigger than (+__)";
2521 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2522 "%d)", entry->bonus);
2523 whose_str[whose_n++] = more_bonus_desc_str;
2526 /*** Wanted monster's corpse/skeletons ***/
2527 if (IS_FLG(FLG_WANTED))
2529 body_str = "corpse or skeletons";
2530 which_str[which_n++] = "is wanted at the Hunter's Office";
2533 /*** Human corpse/skeletons (for Daemon magic) ***/
2534 if (IS_FLG(FLG_HUMAN))
2536 before_str[before_n++] = "humanoid";
2537 body_str = "corpse or skeletons";
2538 which_str[which_n++] = "can be used for Daemon magic";
2541 /*** Unique monster's corpse/skeletons/statues ***/
2542 if (IS_FLG(FLG_UNIQUE))
2544 before_str[before_n++] = "unique monster's";
2545 body_str = "corpse or skeletons";
2548 /*** Unreadable spellbooks ***/
2549 if (IS_FLG(FLG_UNREADABLE))
2551 body_str = "spellbooks";
2552 after_str[after_n++] = "of different realms from yours";
2555 /*** First realm spellbooks ***/
2556 if (IS_FLG(FLG_REALM1))
2558 body_str = "spellbooks";
2559 after_str[after_n++] = "of your first realm";
2562 /*** Second realm spellbooks ***/
2563 if (IS_FLG(FLG_REALM2))
2565 body_str = "spellbooks";
2566 after_str[after_n++] = "of your second realm";
2569 /*** First rank spellbooks ***/
2570 if (IS_FLG(FLG_FIRST))
2572 before_str[before_n++] = "first one of four";
2573 body_str = "spellbooks";
2576 /*** Second rank spellbooks ***/
2577 if (IS_FLG(FLG_SECOND))
2579 before_str[before_n++] = "second one of four";
2580 body_str = "spellbooks";
2583 /*** Third rank spellbooks ***/
2584 if (IS_FLG(FLG_THIRD))
2586 before_str[before_n++] = "third one of four";
2587 body_str = "spellbooks";
2590 /*** Fourth rank spellbooks ***/
2591 if (IS_FLG(FLG_FOURTH))
2593 before_str[before_n++] = "fourth one of four";
2594 body_str = "spellbooks";
2598 if (IS_FLG(FLG_ITEMS))
2599 ; /* Nothing to do */
2600 else if (IS_FLG(FLG_WEAPONS))
2601 body_str = "weapons";
2602 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2603 body_str = "favorite weapons";
2604 else if (IS_FLG(FLG_ARMORS))
2605 body_str = "armors";
2606 else if (IS_FLG(FLG_MISSILES))
2607 body_str = "shots, arrows or crossbow bolts";
2608 else if (IS_FLG(FLG_DEVICES))
2609 body_str = "scrolls, wands, staves or rods";
2610 else if (IS_FLG(FLG_LIGHTS))
2611 body_str = "light sources";
2612 else if (IS_FLG(FLG_JUNKS))
2613 body_str = "junk such as broken sticks";
2614 else if (IS_FLG(FLG_CORPSES))
2615 body_str = "corpses or skeletons";
2616 else if (IS_FLG(FLG_SPELLBOOKS))
2617 body_str = "spellbooks";
2618 else if (IS_FLG(FLG_HAFTED))
2619 body_str = "hafted weapons";
2620 else if (IS_FLG(FLG_SHIELDS))
2621 body_str = "shields";
2622 else if (IS_FLG(FLG_BOWS))
2623 body_str = "slings, bows or crossbows";
2624 else if (IS_FLG(FLG_RINGS))
2626 else if (IS_FLG(FLG_AMULETS))
2627 body_str = "amulets";
2628 else if (IS_FLG(FLG_SUITS))
2629 body_str = "body armors";
2630 else if (IS_FLG(FLG_CLOAKS))
2631 body_str = "cloaks";
2632 else if (IS_FLG(FLG_HELMS))
2633 body_str = "helms or crowns";
2634 else if (IS_FLG(FLG_GLOVES))
2635 body_str = "gloves";
2636 else if (IS_FLG(FLG_BOOTS))
2639 /* Prepare a string for item name */
2646 whose_str[whose_n++] = "name is beginning with \"";
2649 which_str[which_n++] = "have \"";
2653 /* Describe action flag */
2654 if (act & DONT_AUTOPICK)
2655 strcpy(buff, "Leave on floor ");
2656 else if (act & DO_AUTODESTROY)
2657 strcpy(buff, "Destroy ");
2658 else if (act & DO_QUERY_AUTOPICK)
2659 strcpy(buff, "Ask to pick up ");
2661 strcpy(buff, "Pickup ");
2663 /* Auto-insctiption */
2666 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2668 if (my_strstr(insc, "%all"))
2669 strcat(buff, ", replacing %all with code string representing all abilities,");
2670 else if (my_strstr(insc, "%"))
2671 strcat(buff, ", replacing % with code string representing extra random abilities,");
2673 strcat(buff, " on ");
2678 strcat(buff, "all ");
2679 else for (i = 0; i < before_n && before_str[i]; i++)
2681 strcat(buff, before_str[i]);
2686 strcat(buff, body_str);
2689 for (i = 0; i < after_n && after_str[i]; i++)
2692 strcat(buff, after_str[i]);
2696 for (i = 0; i < whose_n && whose_str[i]; i++)
2699 strcat(buff, " whose ");
2701 strcat(buff, ", and ");
2703 strcat(buff, whose_str[i]);
2706 /* Item name ; whose name is beginning with "str" */
2713 /* whose ..., and which .... */
2714 if (whose_n && which_n)
2715 strcat(buff, ", and ");
2718 for (i = 0; i < which_n && which_str[i]; i++)
2721 strcat(buff, " which ");
2723 strcat(buff, ", and ");
2725 strcat(buff, which_str[i]);
2728 /* Item name ; which have "str" as part of its name */
2731 strncat(buff, str, 80);
2732 strcat(buff, "\" as part of its name");
2736 /* Describe whether it will be displayed on the full map or not */
2737 if (act & DO_DISPLAY)
2739 if (act & DONT_AUTOPICK)
2740 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2741 else if (act & DO_AUTODESTROY)
2742 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2744 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2747 strcat(buff, " Not displayed in the full map.");
2754 * Read whole lines of a file to memory
2756 static concptr *read_text_lines(concptr filename)
2758 concptr *lines_list = NULL;
2764 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2767 fff = my_fopen(buf, "r");
2771 /* Allocate list of pointers */
2772 C_MAKE(lines_list, MAX_LINES, concptr);
2775 while (0 == my_fgets(fff, buf, sizeof(buf)))
2777 lines_list[lines++] = string_make(buf);
2778 if (lines >= MAX_LINES - 1) break;
2781 lines_list[0] = string_make("");
2786 if (!fff) return NULL;
2792 * Copy the default autopick file to the user directory
2794 static void prepare_default_pickpref(void)
2796 const concptr messages[] = {
2797 _("あなたは「自動拾いエディタ」を初めて起動しました。", "You have activated the Auto-Picker Editor for the first time."),
2798 _("自動拾いのユーザー設定ファイルがまだ書かれていないので、", "Since user pref file for autopick is not yet created,"),
2799 _("基本的な自動拾い設定ファイルをlib/pref/picktype.prfからコピーします。", "the default setting is loaded from lib/pref/pickpref.prf ."),
2807 concptr filename = pickpref_filename(PT_DEFAULT);
2809 /* Display messages */
2810 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2815 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2816 user_fp = my_fopen(buf, "w");
2819 if (!user_fp) return;
2821 /* Write header messages for a notification */
2822 fprintf(user_fp, "#***\n");
2823 for (i = 0; messages[i]; i++)
2825 fprintf(user_fp, "#*** %s\n", messages[i]);
2827 fprintf(user_fp, "#***\n\n\n");
2830 /* Open the default file */
2831 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2832 pref_fp = my_fopen(buf, "r");
2841 /* Copy the contents of default file */
2842 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2843 fprintf(user_fp, "%s\n", buf);
2850 * Read an autopick prefence file to memory
2851 * Prepare default if no user file is found
2853 static concptr *read_pickpref_text_lines(int *filename_mode_p)
2856 concptr *lines_list;
2858 /* Try a filename with player name */
2859 *filename_mode_p = PT_WITH_PNAME;
2860 strcpy(buf, pickpref_filename(*filename_mode_p));
2861 lines_list = read_text_lines(buf);
2865 /* Use default name */
2866 *filename_mode_p = PT_DEFAULT;
2867 strcpy(buf, pickpref_filename(*filename_mode_p));
2868 lines_list = read_text_lines(buf);
2873 /* There is no preference file in the user directory */
2875 /* Copy the default autopick file to the user directory */
2876 prepare_default_pickpref();
2878 /* Use default name again */
2879 lines_list = read_text_lines(buf);
2884 /* Allocate list of pointers */
2885 C_MAKE(lines_list, MAX_LINES, concptr);
2886 lines_list[0] = string_make("");
2893 * Write whole lines of memory to a file.
2895 static bool write_text_lines(concptr filename, concptr *lines_list)
2902 /* Build the filename */
2903 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2906 fff = my_fopen(buf, "w");
2909 for (lines = 0; lines_list[lines]; lines++)
2910 my_fputs(fff, lines_list[lines], 1024);
2915 if (!fff) return FALSE;
2921 * Free memory of lines_list.
2923 static void free_text_lines(concptr *lines_list)
2927 for (lines = 0; lines_list[lines]; lines++)
2928 string_free(lines_list[lines]);
2930 /* free list of pointers */
2931 C_KILL(lines_list, MAX_LINES, concptr);
2936 * Delete or insert string
2938 static void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
2944 /* Some lines are selected */
2947 by1 = MIN(tb->my, tb->cy);
2948 by2 = MAX(tb->my, tb->cy);
2951 /* No mark -- Select current line */
2952 else /* if (!tb->mark) */
2958 /* Set/Reset flag of each line */
2959 for (y = by1; y <= by2; y++)
2961 autopick_type an_entry, *entry = &an_entry;
2963 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2965 string_free(tb->lines_list[y]);
2969 /* Add? or Remove? */
2970 if (!IS_FLG(flg)) add = TRUE;
2973 /* No more change */
2977 /* You can use only one noun flag */
2978 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2981 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2985 /* You can use only one identify state flag */
2986 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2989 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2993 /* You can use only one flag in artifact/ego/nameless */
2994 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
2997 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
3001 /* You can use only one flag in rare/common */
3002 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
3005 for (i = FLG_RARE; i <= FLG_COMMON; i++)
3009 if (add) ADD_FLG(flg);
3012 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3015 tb->dirty_flags |= DIRTY_ALL;
3017 /* Text is changed */
3024 * Change command letter
3026 static void toggle_command_letter(text_body_type *tb, byte flg)
3028 autopick_type an_entry, *entry = &an_entry;
3033 /* Some lines are selected */
3036 by1 = MIN(tb->my, tb->cy);
3037 by2 = MAX(tb->my, tb->cy);
3040 /* No mark -- Select current line */
3041 else /* if (!tb->mark) */
3047 /* Set/Reset flag of each line */
3048 for (y = by1; y <= by2; y++)
3052 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3054 string_free(tb->lines_list[y]);
3058 /* Add? or Remove? */
3059 if (!(entry->action & flg)) add = TRUE;
3062 /* No more change */
3066 /* Count number of letter (by negative number) */
3067 if (entry->action & DONT_AUTOPICK) wid--;
3068 else if (entry->action & DO_AUTODESTROY) wid--;
3069 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3070 if (!(entry->action & DO_DISPLAY)) wid--;
3072 /* Set/Reset the flag */
3073 if (flg != DO_DISPLAY)
3075 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3076 if (add) entry->action |= flg;
3077 else entry->action |= DO_AUTOPICK;
3081 entry->action &= ~(DO_DISPLAY);
3082 if (add) entry->action |= flg;
3085 /* Correct cursor location */
3088 if (entry->action & DONT_AUTOPICK) wid++;
3089 else if (entry->action & DO_AUTODESTROY) wid++;
3090 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3091 if (!(entry->action & DO_DISPLAY)) wid++;
3093 if (wid > 0) tb->cx++;
3094 if (wid < 0 && tb->cx > 0) tb->cx--;
3097 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3100 tb->dirty_flags |= DIRTY_ALL;
3102 /* Text is changed */
3108 * Delete or insert string
3110 static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
3114 /* Some lines are selected */
3117 by1 = MIN(tb->my, tb->cy);
3118 by2 = MAX(tb->my, tb->cy);
3121 /* No mark -- Select current line */
3122 else /* if (!tb->mark) */
3128 /* Set/Reset flag of each line */
3129 for (y = by1; y <= by2; y++)
3131 autopick_type an_entry, *entry = &an_entry;
3133 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3135 /* There is the flag already */
3138 /* Free memory for the entry */
3139 autopick_free_entry(entry);
3144 string_free(tb->lines_list[y]);
3146 /* Remove all noun flag */
3147 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3150 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3156 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3159 tb->dirty_flags |= DIRTY_ALL;
3161 /* Text is changed */
3168 * Check if this line is expression or not.
3169 * And update it if it is.
3171 static void check_expression_line(text_body_type *tb, int y)
3173 concptr s = tb->lines_list[y];
3175 if ((s[0] == '?' && s[1] == ':') ||
3176 (tb->states[y] & LSTAT_BYPASS))
3178 /* Expressions need re-evaluation */
3179 tb->dirty_flags |= DIRTY_EXPRESSION;
3185 * Add an empty line at the last of the file
3187 static bool add_empty_line(text_body_type *tb)
3191 for (k = 0; tb->lines_list[k]; k++)
3192 /* count number of lines */ ;
3194 /* Too many lines! */
3195 if (k >= MAX_LINES - 2) return FALSE;
3197 /* The last line is already empty */
3198 if (!tb->lines_list[k-1][0]) return FALSE;
3200 /* Create new empty line */
3201 tb->lines_list[k] = string_make("");
3203 /* Expressions need re-evaluation */
3204 tb->dirty_flags |= DIRTY_EXPRESSION;
3206 /* Text is changed */
3209 /* A line is added */
3215 * Insert return code and split the line
3217 static bool insert_return_code(text_body_type *tb)
3219 char buf[MAX_LINELEN];
3222 for (k = 0; tb->lines_list[k]; k++)
3223 /* count number of lines */ ;
3225 if (k >= MAX_LINES - 2) return FALSE;
3228 /* Move down lines */
3229 for (; tb->cy < k; k--)
3231 tb->lines_list[k+1] = tb->lines_list[k];
3232 tb->states[k+1] = tb->states[k];
3235 /* Split current line */
3236 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3239 if (iskanji(tb->lines_list[tb->cy][i]))
3240 buf[j++] = tb->lines_list[tb->cy][i++];
3242 buf[j++] = tb->lines_list[tb->cy][i];
3245 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3246 string_free(tb->lines_list[tb->cy]);
3247 tb->lines_list[tb->cy] = string_make(buf);
3249 /* Expressions need re-evaluation */
3250 tb->dirty_flags |= DIRTY_EXPRESSION;
3252 /* Text is changed */
3260 * Choose an item and get auto-picker entry from it.
3262 static bool entry_from_choosed_object(autopick_type *entry)
3267 q = _("どのアイテムを登録しますか? ", "Enter which item? ");
3268 s = _("アイテムを持っていない。", "You have nothing to enter.");
3269 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3270 if (!o_ptr) return FALSE;
3272 autopick_entry_from_object(entry, o_ptr);
3278 * Choose an item for search
3280 static byte get_object_for_search(object_type **o_handle, concptr *search_strp)
3282 char buf[MAX_NLEN+20];
3286 q = _("どのアイテムを検索しますか? ", "Enter which item? ");
3287 s = _("アイテムを持っていない。", "You have nothing to enter.");
3288 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3289 if (!o_ptr) return 0;
3293 string_free(*search_strp);
3294 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3295 *search_strp = string_make(format("<%s>", buf));
3301 * Prepare for search by destroyed object
3303 static byte get_destroyed_object_for_search(object_type **o_handle, concptr *search_strp)
3305 char buf[MAX_NLEN+20];
3307 if (!autopick_last_destroyed_object.k_idx) return 0;
3309 *o_handle = &autopick_last_destroyed_object;
3311 string_free(*search_strp);
3312 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3313 *search_strp = string_make(format("<%s>", buf));
3319 * Choose an item or string for search
3321 static byte get_string_for_search(object_type **o_handle, concptr *search_strp)
3327 * TERM_YELLOW : Overwrite mode
3328 * TERM_WHITE : Insert mode
3330 byte color = TERM_YELLOW;
3331 char buf[MAX_NLEN+20];
3334 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
3335 int col = sizeof(prompt) - 1;
3337 /* Prepare string buffer for edit */
3338 if (*search_strp) strcpy(buf, *search_strp);
3341 /* Object searching mode */
3344 color = TERM_L_GREEN;
3347 /* Display prompt */
3357 /* Display the string */
3358 Term_erase(col, 0, 255);
3359 Term_putstr(col, 0, -1, color, buf);
3362 Term_gotoxy(col + pos, 0);
3364 /* Get a special key code */
3365 skey = inkey_special(TRUE);
3367 /* Analyze the key */
3375 /* Now on insert mode */
3378 /* No move at beginning of line */
3379 if (0 == pos) break;
3383 int next_pos = i + 1;
3386 if (iskanji(buf[i])) next_pos++;
3389 /* Is there the cursor at next position? */
3390 if (next_pos >= pos) break;
3396 /* Get previous position */
3404 /* Now on insert mode */
3407 /* No move at end of line */
3408 if ('\0' == buf[pos]) break;
3412 if (iskanji(buf[pos])) pos += 2;
3430 if (*o_handle) return (back ? -1 : 1);
3431 string_free(*search_strp);
3432 *search_strp = string_make(buf);
3434 return (back ? -1 : 1);
3437 return get_object_for_search(o_handle, search_strp);
3440 /* Prepare string for destroyed object if there is one. */
3441 if (get_destroyed_object_for_search(o_handle, search_strp))
3451 /* Now on insert mode */
3454 /* No move at beginning of line */
3455 if (0 == pos) break;
3459 int next_pos = i + 1;
3462 if (iskanji(buf[i])) next_pos++;
3465 /* Is there the cursor at next position? */
3466 if (next_pos >= pos) break;
3472 /* Get previous position */
3475 /* Fall through to 'Delete key' */
3484 /* Now on insert mode */
3487 /* No move at end of line */
3488 if ('\0' == buf[pos]) break;
3490 /* Position of next character */
3494 /* Next character is one more byte away */
3495 if (iskanji(buf[pos])) src++;
3500 /* Move characters at src to dst */
3501 while ('\0' != (buf[dst++] = buf[src++]))
3509 /* Insert a character */
3514 /* Ignore special keys */
3515 if (skey & SKEY_MASK) break;
3517 /* Get a character code */
3520 /* Was non insert mode? */
3521 if (color != TERM_WHITE)
3523 /* Was object searching mode */
3524 if (color == TERM_L_GREEN)
3526 /* Cancel the mode */
3529 /* Remove indicating string */
3530 string_free(*search_strp);
3531 *search_strp = NULL;
3534 /* Overwrite default string */
3537 /* Go to insert mode */
3541 /* Save right part of string */
3542 strcpy(tmp, buf + pos);
3548 /* Bypass macro processing */
3566 if (pos < len && (isprint(c) || iskana(c)))
3568 if (pos < len && isprint(c))
3582 /* Write back the left part of string */
3583 my_strcat(buf, tmp, len + 1);
3590 /* Object searching mode was cancelled? */
3591 if (*o_handle && color != TERM_L_GREEN)
3593 /* Cancel the mode */
3596 /* Remove indicating string */
3598 string_free(*search_strp);
3599 *search_strp = NULL;
3604 } /* while (TRUE) */
3609 * Search next line matches for o_ptr
3611 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3613 autopick_type an_entry, *entry = &an_entry;
3614 GAME_TEXT o_name[MAX_NLEN];
3615 int bypassed_cy = -1;
3617 /* Start searching from current cursor position */
3620 /* Prepare object name string first */
3621 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3623 /* Convert the string to lower case */
3624 str_tolower(o_name);
3633 if (!tb->lines_list[++i]) break;
3640 /* Is this line is a correct entry? */
3641 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3643 /* Does this line match to the object? */
3644 match = is_autopick_aux(o_ptr, entry, o_name);
3645 autopick_free_entry(entry);
3646 if (!match) continue;
3648 /* Found a line but it's inactive */
3649 if (tb->states[i] & LSTAT_BYPASS)
3651 /* If it is first found, remember it */
3652 if (bypassed_cy == -1) bypassed_cy = i;
3655 /* Found an active line! */
3658 /* Move to this line */
3662 if (bypassed_cy != -1)
3664 /* Mark as some lines are skipped */
3665 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3673 if (bypassed_cy != -1)
3675 /* Move to the remembered line */
3677 tb->cy = bypassed_cy;
3679 /* Mark as this line is inactive */
3680 tb->dirty_flags |= DIRTY_INACTIVE;
3685 /* Mark as NOT FOUND */
3686 tb->dirty_flags |= DIRTY_NOT_FOUND;
3694 * Search next line matches to the string
3696 static void search_for_string(text_body_type *tb, concptr search_str, bool forward)
3698 int bypassed_cy = -1;
3699 int bypassed_cx = 0;
3701 /* Start searching from current cursor position */
3711 if (!tb->lines_list[++i]) break;
3718 /* Look for the string pattern */
3719 pos = my_strstr(tb->lines_list[i], search_str);
3724 /* Found a line but it's inactive */
3725 if ((tb->states[i] & LSTAT_BYPASS) &&
3726 !(tb->states[i] & LSTAT_EXPRESSION))
3728 /* If it is first found, remember it */
3729 if (bypassed_cy == -1)
3732 bypassed_cx = (int)(pos - tb->lines_list[i]);
3736 /* Found an active line! */
3739 /* Move to this location */
3740 tb->cx = (int)(pos - tb->lines_list[i]);
3743 if (bypassed_cy != -1)
3745 /* Mark as some lines are skipped */
3746 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3754 if (bypassed_cy != -1)
3756 /* Move to the remembered line */
3757 tb->cx = bypassed_cx;
3758 tb->cy = bypassed_cy;
3760 /* Mark as this line is inactive */
3761 tb->dirty_flags |= DIRTY_INACTIVE;
3766 /* Mark as NOT FOUND */
3767 tb->dirty_flags |= DIRTY_NOT_FOUND;
3777 * Editor command id's
3780 #define EC_SAVEQUIT 2
3791 #define EC_PGDOWN 13
3793 #define EC_BOTTOM 15
3798 #define EC_KILL_LINE 20
3799 #define EC_DELETE_CHAR 21
3800 #define EC_BACKSPACE 22
3801 #define EC_SEARCH_STR 23
3802 #define EC_SEARCH_FORW 24
3803 #define EC_SEARCH_BACK 25
3804 #define EC_SEARCH_OBJ 26
3805 #define EC_SEARCH_DESTROYED 27
3806 #define EC_INSERT_OBJECT 28
3807 #define EC_INSERT_DESTROYED 29
3808 #define EC_INSERT_BLOCK 30
3809 #define EC_INSERT_MACRO 31
3810 #define EC_INSERT_KEYMAP 32
3811 #define EC_CL_AUTOPICK 33
3812 #define EC_CL_DESTROY 34
3813 #define EC_CL_LEAVE 35
3814 #define EC_CL_QUERY 36
3815 #define EC_CL_NO_DISP 37
3816 #define EC_OK_COLLECTING 38
3817 #define EC_IK_UNAWARE 39
3818 #define EC_IK_UNIDENTIFIED 40
3819 #define EC_IK_IDENTIFIED 41
3820 #define EC_IK_STAR_IDENTIFIED 42
3821 #define EC_OK_BOOSTED 43
3822 #define EC_OK_MORE_DICE 44
3823 #define EC_OK_MORE_BONUS 45
3824 #define EC_OK_WORTHLESS 46
3825 #define EC_OK_ARTIFACT 47
3826 #define EC_OK_EGO 48
3827 #define EC_OK_GOOD 49
3828 #define EC_OK_NAMELESS 50
3829 #define EC_OK_AVERAGE 51
3830 #define EC_OK_RARE 52
3831 #define EC_OK_COMMON 53
3832 #define EC_OK_WANTED 54
3833 #define EC_OK_UNIQUE 55
3834 #define EC_OK_HUMAN 56
3835 #define EC_OK_UNREADABLE 57
3836 #define EC_OK_REALM1 58
3837 #define EC_OK_REALM2 59
3838 #define EC_OK_FIRST 60
3839 #define EC_OK_SECOND 61
3840 #define EC_OK_THIRD 62
3841 #define EC_OK_FOURTH 63
3842 #define EC_KK_WEAPONS 64
3843 #define EC_KK_FAVORITE_WEAPONS 65
3844 #define EC_KK_ARMORS 66
3845 #define EC_KK_MISSILES 67
3846 #define EC_KK_DEVICES 68
3847 #define EC_KK_LIGHTS 69
3848 #define EC_KK_JUNKS 70
3849 #define EC_KK_CORPSES 71
3850 #define EC_KK_SPELLBOOKS 72
3851 #define EC_KK_SHIELDS 73
3852 #define EC_KK_BOWS 74
3853 #define EC_KK_RINGS 75
3854 #define EC_KK_AMULETS 76
3855 #define EC_KK_SUITS 77
3856 #define EC_KK_CLOAKS 78
3857 #define EC_KK_HELMS 79
3858 #define EC_KK_GLOVES 80
3859 #define EC_KK_BOOTS 81
3865 static GAME_TEXT MN_QUIT[] = "セーブ無しで終了";
3866 static GAME_TEXT MN_SAVEQUIT[] = "セーブして終了";
3867 static GAME_TEXT MN_REVERT[] = "全ての変更を破棄";
3868 static GAME_TEXT MN_HELP[] = "ヘルプ";
3870 static GAME_TEXT MN_MOVE[] = "カーソル移動";
3871 static GAME_TEXT MN_LEFT[] = "左 (←矢印キー)";
3872 static GAME_TEXT MN_DOWN[] = "下 (↓矢印キー)";
3873 static GAME_TEXT MN_UP[] = "上 (↑矢印キー)";
3874 static GAME_TEXT MN_RIGHT[] = "右 (→矢印キー)";
3875 static GAME_TEXT MN_BOL[] = "行の先頭";
3876 static GAME_TEXT MN_EOL[] = "行の終端";
3877 static GAME_TEXT MN_PGUP[] = "上のページ (PageUpキー)";
3878 static GAME_TEXT MN_PGDOWN[] = "下のページ (PageDownキー)";
3879 static GAME_TEXT MN_TOP[] = "1行目へ移動 (Homeキー)";
3880 static GAME_TEXT MN_BOTTOM[] = "最下行へ移動(Endキー)";
3882 static GAME_TEXT MN_EDIT[] = "編集";
3883 static GAME_TEXT MN_CUT[] = "カット";
3884 static GAME_TEXT MN_COPY[] = "コピー";
3885 static GAME_TEXT MN_PASTE[] = "ペースト";
3886 static GAME_TEXT MN_BLOCK[] = "選択範囲の指定";
3887 static GAME_TEXT MN_KILL_LINE[] = "行の残りを削除";
3888 static GAME_TEXT MN_DELETE_CHAR[] = "1文字削除";
3889 static GAME_TEXT MN_BACKSPACE[] = "バックスペース";
3890 static GAME_TEXT MN_RETURN[] = "改行";
3892 static GAME_TEXT MN_SEARCH[] = "検索";
3893 static GAME_TEXT MN_SEARCH_STR[] = "文字列で検索";
3894 static GAME_TEXT MN_SEARCH_FORW[] = "前方へ再検索";
3895 static GAME_TEXT MN_SEARCH_BACK[] = "後方へ再検索";
3896 static GAME_TEXT MN_SEARCH_OBJ[] = "アイテムを選択して検索";
3897 static GAME_TEXT MN_SEARCH_DESTROYED[] = "自動破壊されたアイテムで検索";
3899 static GAME_TEXT MN_INSERT[] = "色々挿入";
3900 static GAME_TEXT MN_INSERT_OBJECT[] = "選択したアイテムの名前を挿入";
3901 static GAME_TEXT MN_INSERT_DESTROYED[] = "自動破壊されたアイテムの名前を挿入";
3902 static GAME_TEXT MN_INSERT_BLOCK[] = "条件分岐ブロックの例を挿入";
3903 static GAME_TEXT MN_INSERT_MACRO[] = "マクロ定義を挿入";
3904 static GAME_TEXT MN_INSERT_KEYMAP[] = "キーマップ定義を挿入";
3906 static GAME_TEXT MN_COMMAND_LETTER[] = "拾い/破壊/放置の選択";
3907 static GAME_TEXT MN_CL_AUTOPICK[] = "「 」 (自動拾い)";
3908 static GAME_TEXT MN_CL_DESTROY[] = "「!」 (自動破壊)";
3909 static GAME_TEXT MN_CL_LEAVE[] = "「~」 (放置)";
3910 static GAME_TEXT MN_CL_QUERY[] = "「;」 (確認して拾う)";
3911 static GAME_TEXT MN_CL_NO_DISP[] = "「(」 (マップコマンドで表示しない)";
3913 static GAME_TEXT MN_ADJECTIVE_GEN[] = "形容詞(一般)の選択";
3914 static GAME_TEXT MN_RARE[] = "レアな (装備)";
3915 static GAME_TEXT MN_COMMON[] = "ありふれた (装備)";
3917 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "形容詞(特殊)の選択";
3918 static GAME_TEXT MN_BOOSTED[] = "ダイス目の違う (武器)";
3919 static GAME_TEXT MN_MORE_DICE[] = "ダイス目 # 以上の (武器)";
3920 static GAME_TEXT MN_MORE_BONUS[] = "修正値 # 以上の (指輪等)";
3921 static GAME_TEXT MN_WANTED[] = "賞金首の (死体)";
3922 static GAME_TEXT MN_UNIQUE[] = "ユニーク・モンスターの (死体)";
3923 static GAME_TEXT MN_HUMAN[] = "人間の (死体)";
3924 static GAME_TEXT MN_UNREADABLE[] = "読めない (魔法書)";
3925 static GAME_TEXT MN_REALM1[] = "第一領域の (魔法書)";
3926 static GAME_TEXT MN_REALM2[] = "第二領域の (魔法書)";
3927 static GAME_TEXT MN_FIRST[] = "1冊目の (魔法書)";
3928 static GAME_TEXT MN_SECOND[] = "2冊目の (魔法書)";
3929 static GAME_TEXT MN_THIRD[] = "3冊目の (魔法書)";
3930 static GAME_TEXT MN_FOURTH[] = "4冊目の (魔法書)";
3932 static GAME_TEXT MN_NOUN[] = "名詞の選択";
3936 static GAME_TEXT MN_QUIT[] = "Quit without save";
3937 static GAME_TEXT MN_SAVEQUIT[] = "Save & Quit";
3938 static GAME_TEXT MN_REVERT[] = "Revert all changes";
3939 static GAME_TEXT MN_HELP[] = "Help";
3941 static GAME_TEXT MN_MOVE[] = "Move cursor";
3942 static GAME_TEXT MN_LEFT[] = "Left (Left Arrow key)";
3943 static GAME_TEXT MN_DOWN[] = "Down (Down Arrow key)";
3944 static GAME_TEXT MN_UP[] = "Up (Up Arrow key)";
3945 static GAME_TEXT MN_RIGHT[] = "Right (Right Arrow key)";
3946 static GAME_TEXT MN_BOL[] = "Beggining of line";
3947 static GAME_TEXT MN_EOL[] = "End of line";
3948 static GAME_TEXT MN_PGUP[] = "Page up (PageUp key)";
3949 static GAME_TEXT MN_PGDOWN[] = "Page down(PageDown key)";
3950 static GAME_TEXT MN_TOP[] = "Top (Home key)";
3951 static GAME_TEXT MN_BOTTOM[] = "Bottom (End key)";
3953 static GAME_TEXT MN_EDIT[] = "Edit";
3954 static GAME_TEXT MN_CUT[] = "Cut";
3955 static GAME_TEXT MN_COPY[] = "Copy";
3956 static GAME_TEXT MN_PASTE[] = "Paste";
3957 static GAME_TEXT MN_BLOCK[] = "Select block";
3958 static GAME_TEXT MN_KILL_LINE[] = "Kill rest of line";
3959 static GAME_TEXT MN_DELETE_CHAR[] = "Delete character";
3960 static GAME_TEXT MN_BACKSPACE[] = "Backspace";
3961 static GAME_TEXT MN_RETURN[] = "Return";
3963 static GAME_TEXT MN_SEARCH[] = "Search";
3964 static GAME_TEXT MN_SEARCH_STR[] = "Search by string";
3965 static GAME_TEXT MN_SEARCH_FORW[] = "Search forward";
3966 static GAME_TEXT MN_SEARCH_BACK[] = "Search backward";
3967 static GAME_TEXT MN_SEARCH_OBJ[] = "Search by p_ptr->inventory_list object";
3968 static GAME_TEXT MN_SEARCH_DESTROYED[] = "Search by destroyed object";
3970 static GAME_TEXT MN_INSERT[] = "Insert...";
3971 static GAME_TEXT MN_INSERT_OBJECT[] = "Insert name of choosen object";
3972 static GAME_TEXT MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
3973 static GAME_TEXT MN_INSERT_BLOCK[] = "Insert conditional block";
3974 static GAME_TEXT MN_INSERT_MACRO[] = "Insert a macro definition";
3975 static GAME_TEXT MN_INSERT_KEYMAP[] = "Insert a keymap definition";
3977 static GAME_TEXT MN_COMMAND_LETTER[] = "Command letter";
3978 static GAME_TEXT MN_CL_AUTOPICK[] = "' ' (Auto pick)";
3979 static GAME_TEXT MN_CL_DESTROY[] = "'!' (Auto destroy)";
3980 static GAME_TEXT MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
3981 static GAME_TEXT MN_CL_QUERY[] = "';' (Query to pick up)";
3982 static GAME_TEXT MN_CL_NO_DISP[] = "'(' (No display on the large map)";
3984 static GAME_TEXT MN_ADJECTIVE_GEN[] = "Adjective (general)";
3985 static GAME_TEXT MN_RARE[] = "rare (equipments)";
3986 static GAME_TEXT MN_COMMON[] = "common (equipments)";
3988 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
3989 static GAME_TEXT MN_BOOSTED[] = "dice boosted (weapons)";
3990 static GAME_TEXT MN_MORE_DICE[] = "more than # dice (weapons)";
3991 static GAME_TEXT MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
3992 static GAME_TEXT MN_WANTED[] = "wanted (corpse)";
3993 static GAME_TEXT MN_UNIQUE[] = "unique (corpse)";
3994 static GAME_TEXT MN_HUMAN[] = "human (corpse)";
3995 static GAME_TEXT MN_UNREADABLE[] = "unreadable (spellbooks)";
3996 static GAME_TEXT MN_REALM1[] = "realm1 (spellbooks)";
3997 static GAME_TEXT MN_REALM2[] = "realm2 (spellbooks)";
3998 static GAME_TEXT MN_FIRST[] = "first (spellbooks)";
3999 static GAME_TEXT MN_SECOND[] = "second (spellbooks)";
4000 static GAME_TEXT MN_THIRD[] = "third (spellbooks)";
4001 static GAME_TEXT MN_FOURTH[] = "fourth (spellbooks)";
4003 static GAME_TEXT MN_NOUN[] = "Keywords (noun)";
4013 } command_menu_type;
4016 command_menu_type menu_data[] =
4018 {MN_HELP, 0, -1, EC_HELP},
4019 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4020 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4021 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4023 {MN_EDIT, 0, -1, -1},
4024 {MN_CUT, 1, KTRL('x'), EC_CUT},
4025 {MN_COPY, 1, KTRL('c'), EC_COPY},
4026 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4027 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4028 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4029 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4030 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4031 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4032 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4034 {MN_SEARCH, 0, -1, -1},
4035 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4036 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4037 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4038 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4039 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4041 {MN_MOVE, 0, -1, -1},
4042 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4043 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4044 {MN_UP, 1, KTRL('p'), EC_UP},
4045 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4046 {MN_BOL, 1, KTRL('a'), EC_BOL},
4047 {MN_EOL, 1, KTRL('e'), EC_EOL},
4048 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4049 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4050 {MN_TOP, 1, KTRL('t'), EC_TOP},
4051 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4053 {MN_INSERT, 0, -1, -1},
4054 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4055 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4056 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4057 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4058 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4060 {MN_ADJECTIVE_GEN, 0, -1, -1},
4061 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4062 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4063 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4064 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4065 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4066 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4067 {KEY_EGO, 1, -1, EC_OK_EGO},
4068 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4069 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4070 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4071 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4072 {MN_RARE, 1, -1, EC_OK_RARE},
4073 {MN_COMMON, 1, -1, EC_OK_COMMON},
4075 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4076 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4077 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4078 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4079 {MN_WANTED, 1, -1, EC_OK_WANTED},
4080 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4081 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4082 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4083 {MN_REALM1, 1, -1, EC_OK_REALM1},
4084 {MN_REALM2, 1, -1, EC_OK_REALM2},
4085 {MN_FIRST, 1, -1, EC_OK_FIRST},
4086 {MN_SECOND, 1, -1, EC_OK_SECOND},
4087 {MN_THIRD, 1, -1, EC_OK_THIRD},
4088 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4090 {MN_NOUN, 0, -1, -1},
4091 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4092 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4093 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4094 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4095 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4096 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4097 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4098 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4099 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4100 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4101 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4102 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4103 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4104 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4105 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4106 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4107 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4108 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4110 {MN_COMMAND_LETTER, 0, -1, -1},
4111 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4112 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4113 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4114 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4115 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4117 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4124 * Find a command by 'key'.
4126 static int get_com_id(char key)
4130 for (i = 0; menu_data[i].name; i++)
4132 if (menu_data[i].key == key)
4134 return menu_data[i].com_id;
4143 * Display the menu, and get a command
4145 static int do_command_menu(int level, int start)
4150 int col0 = 5 + level*7;
4151 int row0 = 1 + level*3;
4153 int menu_id_list[26];
4155 char linestr[MAX_LINELEN];
4157 /* Get max length */
4159 for (i = start; menu_data[i].level >= level; i++)
4163 /* Ignore lower level sub menus */
4164 if (menu_data[i].level > level) continue;
4166 len = strlen(menu_data[i].name);
4167 if (len > max_len) max_len = len;
4169 menu_id_list[menu_key] = i;
4173 while (menu_key < 26)
4175 menu_id_list[menu_key] = -1;
4179 /* Extra space for displaying menu key and command key */
4180 max_menu_wid = max_len + 3 + 3;
4182 /* Prepare box line */
4184 strcat(linestr, "+");
4185 for (i = 0; i < max_menu_wid + 2; i++)
4187 strcat(linestr, "-");
4189 strcat(linestr, "+");
4199 int row1 = row0 + 1;
4202 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4204 /* Draw menu items */
4206 for (i = start; menu_data[i].level >= level; i++)
4208 char com_key_str[3];
4211 /* Ignore lower level sub menus */
4212 if (menu_data[i].level > level) continue;
4214 if (menu_data[i].com_id == -1)
4216 strcpy(com_key_str, _("▼", ">"));
4218 else if (menu_data[i].key != -1)
4220 com_key_str[0] = '^';
4221 com_key_str[1] = menu_data[i].key + '@';
4222 com_key_str[2] = '\0';
4226 com_key_str[0] = '\0';
4229 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4231 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4236 /* Draw bottom line */
4237 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4239 /* The menu was shown */
4242 prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
4245 if (key == ESCAPE) return 0;
4247 if ('a' <= key && key <= 'z')
4249 menu_id = menu_id_list[key - 'a'];
4253 com_id = menu_data[menu_id].com_id;
4257 com_id = do_command_menu(level + 1, menu_id + 1);
4259 if (com_id) return com_id;
4271 com_id = get_com_id(key);
4272 if (com_id) return com_id;
4279 static chain_str_type *new_chain_str(concptr str)
4281 chain_str_type *chain;
4283 size_t len = strlen(str);
4285 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4287 strcpy(chain->s, str);
4294 static void kill_yank_chain(text_body_type *tb)
4296 chain_str_type *chain = tb->yank;
4298 tb->yank_eol = TRUE;
4302 chain_str_type *next = chain->next;
4303 size_t len = strlen(chain->s);
4305 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4312 static void add_str_to_yank(text_body_type *tb, concptr str)
4314 chain_str_type *chain;
4316 tb->yank_eol = FALSE;
4318 if (NULL == tb->yank)
4320 tb->yank = new_chain_str(str);
4330 chain->next = new_chain_str(str);
4335 chain = chain->next;
4341 * Do work for the copy editor-command
4343 static void copy_text_to_yank(text_body_type *tb)
4345 int len = strlen(tb->lines_list[tb->cy]);
4347 /* Correct cursor location */
4348 if (tb->cx > len) tb->cx = len;
4350 /* Use single line? */
4353 /* Select a single line */
4359 /* Kill old yank buffer */
4360 kill_yank_chain(tb);
4363 /* Single line case */
4364 if (tb->my == tb->cy)
4367 char buf[MAX_LINELEN];
4368 int bx1 = MIN(tb->mx, tb->cx);
4369 int bx2 = MAX(tb->mx, tb->cx);
4371 /* Correct fake cursor position */
4372 if (bx2 > len) bx2 = len;
4374 /* Whole part of this line is selected */
4375 if (bx1 == 0 && bx2 == len)
4377 /* Copy this line */
4378 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4380 /* Add end of line to the buffer */
4381 add_str_to_yank(tb, "");
4384 /* Segment of this line is selected */
4387 for (i = 0; i < bx2 - bx1; i++)
4389 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4393 /* Copy this segment of line */
4394 add_str_to_yank(tb, buf);
4398 /* Multiple lines case */
4399 else /* if (tb->my != tb->cy) */
4403 int by1 = MIN(tb->my, tb->cy);
4404 int by2 = MAX(tb->my, tb->cy);
4407 for (y = by1; y <= by2; y++)
4409 /* Copy this line */
4410 add_str_to_yank(tb, tb->lines_list[y]);
4413 /* Add final end of line to the buffer */
4414 add_str_to_yank(tb, "");
4417 /* Disable selection */
4421 tb->dirty_flags |= DIRTY_ALL;
4425 #define DESCRIPT_HGT 3
4430 static void draw_text_editor(text_body_type *tb)
4433 int by1 = 0, by2 = 0;
4435 Term_get_size(&tb->wid, &tb->hgt);
4438 * Top line (-1), description line (-3), separator (-1)
4441 tb->hgt -= 2 + DESCRIPT_HGT;
4444 /* Don't let cursor at second byte of kanji */
4445 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4446 if (iskanji(tb->lines_list[tb->cy][i]))
4452 * Move to a correct position in the
4455 if (i & 1) tb->cx--;
4462 /* Scroll if necessary */
4463 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4464 tb->upper = tb->cy - (tb->hgt)/2;
4467 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4468 tb->left = tb->cx - (tb->wid)*2/3;
4472 /* Redraw whole window after resize */
4473 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4474 tb->dirty_flags |= DIRTY_SCREEN;
4476 /* Redraw all text after scroll */
4477 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4478 tb->dirty_flags |= DIRTY_ALL;
4481 if (tb->dirty_flags & DIRTY_SCREEN)
4483 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4487 /* Redraw mode line */
4488 if (tb->dirty_flags & DIRTY_MODE)
4490 char buf[MAX_LINELEN];
4492 int sepa_length = tb->wid;
4495 for (i = 0; i < sepa_length; i++)
4499 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4502 if (tb->dirty_flags & DIRTY_EXPRESSION)
4507 for (y = 0; tb->lines_list[y]; y++)
4511 concptr s = tb->lines_list[y];
4515 /* Update this line's state */
4516 tb->states[y] = state;
4518 if (*s++ != '?') continue;
4519 if (*s++ != ':') continue;
4521 /* Lines below this line are auto-registered */
4522 if (streq(s, "$AUTOREGISTER"))
4523 state |= LSTAT_AUTOREGISTER;
4526 ss = (char *)string_make(s);
4529 /* Parse the expr */
4530 v = process_pref_file_expr(&ss, &f);
4533 if (streq(v, "0")) state |= LSTAT_BYPASS;
4534 else state &= ~LSTAT_BYPASS;
4536 /* Cannot use string_free() because the string was "destroyed" */
4537 C_KILL(s_keep, s_len + 1, char);
4539 /* Re-update this line's state */
4540 tb->states[y] = state | LSTAT_EXPRESSION;
4543 tb->dirty_flags |= DIRTY_ALL;
4548 tb->dirty_flags |= DIRTY_ALL;
4550 by1 = MIN(tb->my, tb->cy);
4551 by2 = MAX(tb->my, tb->cy);
4554 /* Dump up to tb->hgt lines of messages */
4555 for (i = 0; i < tb->hgt; i++)
4561 int y = tb->upper+i;
4563 /* clean or dirty? */
4564 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4567 msg = tb->lines_list[y];
4570 /* Apply horizontal scroll */
4571 for (j = 0; *msg; msg++, j++)
4573 if (j == tb->left) break;
4589 Term_erase(0, i + 1, tb->wid);
4591 if (tb->states[y] & LSTAT_AUTOREGISTER)
4593 /* Warning color -- These lines will be deleted later */
4598 /* Bypassed line will be displayed by darker color */
4599 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4600 else color = TERM_WHITE;
4603 /* No mark or Out of mark */
4604 if (!tb->mark || (y < by1 || by2 < y))
4606 /* Dump the messages, bottom to top */
4607 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4610 /* Multiple lines selected */
4611 else if (by1 != by2)
4613 /* Dump the messages, bottom to top */
4614 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4617 /* Single line selected */
4620 int x0 = leftcol + tb->left;
4621 int len = strlen(tb->lines_list[tb->cy]);
4622 int bx1 = MIN(tb->mx, tb->cx);
4623 int bx2 = MAX(tb->mx, tb->cx);
4625 /* Correct cursor location */
4626 if (bx2 > len) bx2 = len;
4628 Term_gotoxy(leftcol, i + 1);
4629 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4630 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4631 Term_addstr(-1, color, msg + (bx2 - x0));
4635 for (; i < tb->hgt; i++)
4638 Term_erase(0, i + 1, tb->wid);
4641 /* Display information when updated */
4642 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4644 autopick_type an_entry, *entry = &an_entry;
4645 concptr str1 = NULL, str2 = NULL;
4648 /* Clear information line */
4649 for (i = 0; i < DESCRIPT_HGT; i++)
4652 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4655 /* Display information */
4656 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4658 str1 = format(_("パターンが見つかりません: %s", "Pattern not found: %s"), tb->search_str);
4660 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4662 str1 = format(_("無効状態の行をスキップしました。(%sを検索中)",
4663 "Some inactive lines are skipped. (Searching %s)"), tb->search_str);
4665 else if (tb->dirty_flags & DIRTY_INACTIVE)
4667 str1 = format(_("無効状態の行だけが見付かりました。(%sを検索中)",
4668 "Found only an inactive line. (Searching %s)"), tb->search_str);
4670 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4672 str1 = _("検索するパターンがありません(^S で検索)。", "No pattern to search. (Press ^S to search.)");
4674 else if (tb->lines_list[tb->cy][0] == '#')
4676 str1 = _("この行はコメントです。", "This line is a comment.");
4678 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4680 switch(tb->lines_list[tb->cy][0])
4683 str1 = _("この行は条件分岐式です。", "This line is a Conditional Expression.");
4686 str1 = _("この行はマクロの実行内容を定義します。", "This line defines a Macro action.");
4689 str1 = _("この行はマクロのトリガー・キーを定義します。", "This line defines a Macro trigger key.");
4692 str1 = _("この行はキー配置を定義します。", "This line defines a Keymap.");
4696 switch(tb->lines_list[tb->cy][0])
4699 if (tb->states[tb->cy] & LSTAT_BYPASS)
4701 str2 = _("現在の式の値は「偽(=0)」です。", "The expression is 'False'(=0) currently.");
4705 str2 = _("現在の式の値は「真(=1)」です。", "The expression is 'True'(=1) currently.");
4710 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4712 str2 = _("この行は後で削除されます。", "This line will be delete later.");
4715 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4717 str2 = _("この行は現在は無効な状態です。", "This line is bypassed currently.");
4723 /* Get description of an autopicker preference line */
4724 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4726 char buf[MAX_LINELEN];
4727 char temp[MAX_LINELEN];
4730 describe_autopick(buf, entry);
4732 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4734 strcat(buf, _("この行は後で削除されます。", " This line will be delete later."));
4737 if (tb->states[tb->cy] & LSTAT_BYPASS)
4739 strcat(buf, _("この行は現在は無効な状態です。", " This line is bypassed currently."));
4742 roff_to_buf(buf, 81, temp, sizeof(temp));
4744 for (i = 0; i < 3; i++)
4750 prt(t, tb->hgt +1 + 1 + i, 0);
4754 autopick_free_entry(entry);
4757 /* Draw the first line */
4758 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4760 /* Draw the second line */
4761 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4767 * Kill segment of a line
4769 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4771 char buf[MAX_LINELEN];
4772 concptr s = tb->lines_list[y];
4776 /* Kill whole line? */
4777 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4781 string_free(tb->lines_list[y]);
4783 /* Shift lines up */
4784 for (i = y; tb->lines_list[i+1]; i++)
4785 tb->lines_list[i] = tb->lines_list[i+1];
4786 tb->lines_list[i] = NULL;
4788 /* Expressions need re-evaluation */
4789 tb->dirty_flags |= DIRTY_EXPRESSION;
4795 if (x0 == x1) return;
4797 /* Before the segment */
4798 for (x = 0; x < x0; x++)
4801 /* After the segment */
4802 for (x = x1; s[x]; x++)
4808 string_free(tb->lines_list[y]);
4809 tb->lines_list[y] = string_make(buf);
4811 /* Expressions may need re-evaluation */
4812 check_expression_line(tb, y);
4814 /* Text is changed */
4820 * Get a trigger key and insert ASCII string for the trigger
4822 static bool insert_macro_line(text_body_type *tb)
4831 /* Do not process macros */
4837 /* Read the pattern */
4843 /* Do not process macros */
4846 /* Do not wait for keys */
4849 /* Attempt to read a key */
4858 /* Convert the trigger */
4859 ascii_to_text(tmp, buf);
4862 if(!tmp[0]) return FALSE;
4866 /* Insert preference string */
4867 insert_return_code(tb);
4868 string_free(tb->lines_list[tb->cy]);
4869 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4871 /* Acquire action */
4872 i = macro_find_exact(buf);
4876 /* Nothing defined */
4881 /* Analyze the current action */
4882 ascii_to_text(tmp, macro__act[i]);
4885 /* Insert blank action preference line */
4886 insert_return_code(tb);
4887 string_free(tb->lines_list[tb->cy]);
4888 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4895 * Get a command key and insert ASCII string for the key
4897 static bool insert_keymap_line(text_body_type *tb)
4905 if (rogue_like_commands)
4907 mode = KEYMAP_MODE_ROGUE;
4913 mode = KEYMAP_MODE_ORIG;
4924 /* Convert the trigger */
4925 ascii_to_text(tmp, buf);
4928 if(!tmp[0]) return FALSE;
4932 /* Insert preference string */
4933 insert_return_code(tb);
4934 string_free(tb->lines_list[tb->cy]);
4935 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4937 /* Look up the keymap */
4938 act = keymap_act[mode][(byte)(buf[0])];
4942 /* Analyze the current action */
4943 ascii_to_text(tmp, act);
4947 /* No keymap defined -- Use trigger key itself as a default */
4949 /* Nothing to do (use tmp) */
4952 /* Insert blank action preference line */
4953 insert_return_code(tb);
4954 string_free(tb->lines_list[tb->cy]);
4955 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4962 * Execute a single editor command
4964 static bool do_editor_command(text_body_type *tb, int com_id)
4971 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
4972 "Discard all changes and quit. Are you sure? "))) break;
4974 return QUIT_WITHOUT_SAVE;
4977 return QUIT_AND_SAVE;
4980 /* Revert to original */
4981 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
4982 "Discard all changes and revert to original file. Are you sure? "))) break;
4984 free_text_lines(tb->lines_list);
4985 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4986 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4987 tb->cx = tb->cy = 0;
4990 /* Text is not changed */
4991 tb->changed = FALSE;
4995 /* Peruse the main help file */
4996 (void)show_file(TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
4998 tb->dirty_flags |= DIRTY_SCREEN;
5003 /* Split a line or insert end of line */
5005 /* Ignore selection */
5011 tb->dirty_flags |= DIRTY_ALL;
5014 insert_return_code(tb);
5019 tb->dirty_flags |= DIRTY_ALL;
5032 len = strlen(tb->lines_list[tb->cy]);
5033 if (len < tb->cx) tb->cx = len;
5036 /* Don't let cursor at second byte of kanji */
5037 for (i = 0; tb->lines_list[tb->cy][i]; i++)
5039 if (iskanji(tb->lines_list[tb->cy][i]))
5044 /* Move to the left */
5052 else if (tb->cy > 0)
5055 tb->cx = strlen(tb->lines_list[tb->cy]);
5062 /* Is this the last line? */
5063 if (!tb->lines_list[tb->cy + 1])
5065 /* Add one more empty line if possible */
5066 if (!add_empty_line(tb)) break;
5076 if (tb->cy > 0) tb->cy--;
5085 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5088 len = strlen(tb->lines_list[tb->cy]);
5091 /* Correct the cursor position */
5094 /* Is this the last line? */
5095 if (!tb->lines_list[tb->cy + 1])
5097 /* Add one more empty line if possible */
5098 if (!add_empty_line(tb)) break;
5101 /* Move to the beginning of next line */
5109 /* Beginning of line */
5115 tb->cx = strlen(tb->lines_list[tb->cy]);
5119 while (0 < tb->cy && tb->upper <= tb->cy)
5121 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5127 while (tb->cy < tb->upper + tb->hgt)
5129 /* Is this the last line? */
5130 if (!tb->lines_list[tb->cy + 1])
5132 /* Add one more empty line if possible */
5133 if (!add_empty_line(tb)) break;
5149 /* Is this the last line? */
5150 if (!tb->lines_list[tb->cy + 1])
5152 /* Add one more empty line if possible */
5153 if (!add_empty_line(tb)) break;
5159 /* Always at the biginning of the last line */
5166 /* Copy the text first */
5167 copy_text_to_yank(tb);
5169 /* Single line case */
5170 if (tb->my == tb->cy)
5172 int bx1 = MIN(tb->mx, tb->cx);
5173 int bx2 = MAX(tb->mx, tb->cx);
5174 int len = strlen(tb->lines_list[tb->cy]);
5176 /* Correct fake cursor position */
5177 if (bx2 > len) bx2 = len;
5179 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5181 /* New cursor position */
5185 /* Multiple lines case */
5186 else /* if (tb->my != tb->cy) */
5190 int by1 = MIN(tb->my, tb->cy);
5191 int by2 = MAX(tb->my, tb->cy);
5193 /* Kill lines in reverse order */
5194 for (y = by2; y >= by1; y--)
5196 int len = strlen(tb->lines_list[y]);
5198 kill_line_segment(tb, y, 0, len, TRUE);
5201 /* New cursor position */
5207 /* Disable selection */
5211 tb->dirty_flags |= DIRTY_ALL;
5213 /* Text is changed */
5220 copy_text_to_yank(tb);
5223 * Move cursor position to the end of the selection
5225 * Pressing ^C ^V correctly duplicates the selection.
5227 if (tb->my == tb->cy)
5229 tb->cx = MAX(tb->cx, tb->mx);
5232 * When whole line is selected, the end of
5233 * line code is also copyed.
5235 if (!tb->lines_list[tb->cy][tb->cx])
5237 /* Is this the last line? */
5238 if (!tb->lines_list[tb->cy + 1])
5240 /* Add one more empty line if possible */
5241 if (!add_empty_line(tb)) break;
5244 /* Go to the beginning of next line */
5251 tb->cy = MAX(tb->cy, tb->my);
5253 /* Is this the last line? */
5254 if (!tb->lines_list[tb->cy + 1])
5256 /* Add one more empty line if possible */
5257 if (!add_empty_line(tb)) break;
5268 /* Paste killed text */
5270 chain_str_type *chain = tb->yank;
5271 int len = strlen(tb->lines_list[tb->cy]);
5273 /* Nothing to do? */
5276 /* Correct cursor location */
5277 if (tb->cx > len) tb->cx = len;
5279 /* Ignore selection */
5285 tb->dirty_flags |= DIRTY_ALL;
5291 concptr yank_str = chain->s;
5293 char buf[MAX_LINELEN];
5295 char rest[MAX_LINELEN], *rest_ptr = rest;
5297 /* Save preceding string */
5298 for(i = 0; i < tb->cx; i++)
5299 buf[i] = tb->lines_list[tb->cy][i];
5301 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5303 /* Paste yank buffer */
5304 while (*yank_str && i < MAX_LINELEN-1)
5306 buf[i++] = *yank_str++;
5312 chain = chain->next;
5314 if (chain || tb->yank_eol)
5316 /* There is an end of line between chain nodes */
5318 insert_return_code(tb);
5320 /* Replace this line with new one */
5321 string_free(tb->lines_list[tb->cy]);
5322 tb->lines_list[tb->cy] = string_make(buf);
5324 /* Move to next line */
5331 /* Final line doesn't have end of line */
5333 tb->cx = strlen(buf);
5335 /* Rest of original line */
5336 while (*rest_ptr && i < MAX_LINELEN-1)
5338 buf[i++] = *rest_ptr++;
5344 /* Replace this line with new one */
5345 string_free(tb->lines_list[tb->cy]);
5346 tb->lines_list[tb->cy] = string_make(buf);
5353 tb->dirty_flags |= DIRTY_ALL;
5355 /* Expressions need re-evaluation */
5356 tb->dirty_flags |= DIRTY_EXPRESSION;
5358 /* Text is changed */
5367 /* Disable the selection */
5371 tb->dirty_flags |= DIRTY_ALL;
5375 tb->mark = MARK_MARK;
5377 /* Repeating this command swaps cursor position */
5378 if (com_id == tb->old_com_id)
5390 tb->dirty_flags |= DIRTY_ALL;
5394 int len = strlen(tb->lines_list[tb->cy]);
5396 /* Mark the point 1 */
5400 /* Correct cursor location */
5401 if (tb->cx > len) tb->mx = len;
5408 /* Kill rest of line */
5410 int len = strlen(tb->lines_list[tb->cy]);
5412 /* Correct cursor location */
5413 if (tb->cx > len) tb->cx = len;
5415 /* Ignore selection */
5421 tb->dirty_flags |= DIRTY_ALL;
5424 /* Append only if this command is repeated. */
5425 if (tb->old_com_id != com_id)
5427 kill_yank_chain(tb);
5431 /* Really deleted some text */
5434 /* Add deleted string to yank buffer */
5435 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5437 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5440 tb->dirty_line = tb->cy;
5442 /* Leave end of line character */
5446 /* Cut the end of line character only */
5447 if (tb->yank_eol) add_str_to_yank(tb, "");
5449 /* Cut end of line */
5450 tb->yank_eol = TRUE;
5452 do_editor_command(tb, EC_DELETE_CHAR);
5456 case EC_DELETE_CHAR:
5458 /* DELETE == go forward + BACK SPACE */
5462 /* Ignore selection */
5468 tb->dirty_flags |= DIRTY_ALL;
5472 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5476 /* Pass through the end of line to next line */
5477 len = strlen(tb->lines_list[tb->cy]);
5480 if (tb->lines_list[tb->cy + 1])
5492 do_editor_command(tb, EC_BACKSPACE);
5501 char buf[MAX_LINELEN];
5503 /* Ignore selection */
5509 tb->dirty_flags |= DIRTY_ALL;
5512 /* Move to correct collumn */
5513 len = strlen(tb->lines_list[tb->cy]);
5514 if (len < tb->cx) tb->cx = len;
5518 /* delete a return code and union two lines */
5519 if (tb->cy == 0) break;
5520 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5521 strcpy(buf, tb->lines_list[tb->cy-1]);
5522 strcat(buf, tb->lines_list[tb->cy]);
5523 string_free(tb->lines_list[tb->cy-1]);
5524 string_free(tb->lines_list[tb->cy]);
5525 tb->lines_list[tb->cy-1] = string_make(buf);
5527 for (i = tb->cy; tb->lines_list[i+1]; i++)
5528 tb->lines_list[i] = tb->lines_list[i+1];
5530 tb->lines_list[i] = NULL;
5534 tb->dirty_flags |= DIRTY_ALL;
5536 /* Expressions need re-evaluation */
5537 tb->dirty_flags |= DIRTY_EXPRESSION;
5539 /* Text is changed */
5545 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5549 if (iskanji(tb->lines_list[tb->cy][i]))
5550 buf[j++] = tb->lines_list[tb->cy][i++];
5552 buf[j++] = tb->lines_list[tb->cy][i];
5559 for (; tb->lines_list[tb->cy][i]; i++)
5560 buf[j++] = tb->lines_list[tb->cy][i];
5562 string_free(tb->lines_list[tb->cy]);
5563 tb->lines_list[tb->cy] = string_make(buf);
5566 tb->dirty_line = tb->cy;
5568 /* Expressions may need re-evaluation */
5569 check_expression_line(tb, tb->cy);
5571 /* Text is changed */
5581 /* Become dirty because of item/equip menu */
5582 tb->dirty_flags |= DIRTY_SCREEN;
5584 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5586 if (!search_dir) break;
5588 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5589 else do_editor_command(tb, EC_SEARCH_BACK);
5593 case EC_SEARCH_FORW:
5594 if (tb->search_o_ptr)
5596 search_for_object(tb, tb->search_o_ptr, TRUE);
5598 else if (tb->search_str && tb->search_str[0])
5600 search_for_string(tb, tb->search_str, TRUE);
5604 tb->dirty_flags |= DIRTY_NO_SEARCH;
5608 case EC_SEARCH_BACK:
5609 if (tb->search_o_ptr)
5611 search_for_object(tb, tb->search_o_ptr, FALSE);
5613 else if (tb->search_str && tb->search_str[0])
5615 search_for_string(tb, tb->search_str, FALSE);
5619 tb->dirty_flags |= DIRTY_NO_SEARCH;
5624 /* Become dirty because of item/equip menu */
5625 tb->dirty_flags |= DIRTY_SCREEN;
5627 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5629 do_editor_command(tb, EC_SEARCH_FORW);
5632 case EC_SEARCH_DESTROYED:
5633 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5635 /* There is no object to search */
5636 tb->dirty_flags |= DIRTY_NO_SEARCH;
5641 do_editor_command(tb, EC_SEARCH_FORW);
5644 case EC_INSERT_OBJECT:
5646 /* Insert choosen item name */
5648 autopick_type an_entry, *entry = &an_entry;
5650 if (!entry_from_choosed_object(entry))
5652 /* Now dirty because of item/equip menu */
5653 tb->dirty_flags |= DIRTY_SCREEN;
5658 insert_return_code(tb);
5659 string_free(tb->lines_list[tb->cy]);
5660 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5662 /* Now dirty because of item/equip menu */
5663 tb->dirty_flags |= DIRTY_SCREEN;
5668 case EC_INSERT_DESTROYED:
5669 /* Insert a name of last destroyed item */
5670 if (tb->last_destroyed)
5673 insert_return_code(tb);
5674 string_free(tb->lines_list[tb->cy]);
5675 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5678 tb->dirty_flags |= DIRTY_ALL;
5680 /* Text is changed */
5685 case EC_INSERT_BLOCK:
5687 /* Insert a conditinal expression line */
5688 char expression[80];
5690 /* Conditional Expression for Class and Race */
5691 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5693 rp_ptr->E_title, cp_ptr->E_title,
5695 rp_ptr->title, cp_ptr->title,
5701 insert_return_code(tb);
5702 string_free(tb->lines_list[tb->cy]);
5703 tb->lines_list[tb->cy] = string_make(expression);
5705 insert_return_code(tb);
5706 string_free(tb->lines_list[tb->cy]);
5707 tb->lines_list[tb->cy] = string_make("?:1");
5710 tb->dirty_flags |= DIRTY_ALL;
5712 /* Text is changed */
5718 case EC_INSERT_MACRO:
5719 /* Draw_everythig (delete menu) */
5720 draw_text_editor(tb);
5723 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5726 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
5727 if (insert_macro_line(tb))
5729 /* Prepare to input action */
5733 tb->dirty_flags |= DIRTY_ALL;
5735 /* Text is changed */
5741 case EC_INSERT_KEYMAP:
5742 /* Draw_everythig (delete menu) */
5743 draw_text_editor(tb);
5746 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5749 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
5750 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5752 if (insert_keymap_line(tb))
5754 /* Prepare to input action */
5758 tb->dirty_flags |= DIRTY_ALL;
5760 /* Text is changed */
5765 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5766 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5767 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5768 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5769 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5771 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5772 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5773 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5774 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5775 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5776 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5777 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5778 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5779 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5780 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5781 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5782 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5783 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5784 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5785 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5786 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5787 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5788 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5789 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5790 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5791 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5792 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5793 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5794 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5795 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5796 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5797 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5798 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5799 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5800 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5801 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5802 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5803 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5804 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5805 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5806 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5807 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5808 case EC_OK_UNREADABLE:
5809 toggle_keyword(tb, FLG_UNREADABLE);
5810 add_keyword(tb, FLG_SPELLBOOKS);
5813 toggle_keyword(tb, FLG_REALM1);
5814 add_keyword(tb, FLG_SPELLBOOKS);
5817 toggle_keyword(tb, FLG_REALM2);
5818 add_keyword(tb, FLG_SPELLBOOKS);
5821 toggle_keyword(tb, FLG_FIRST);
5822 add_keyword(tb, FLG_SPELLBOOKS);
5825 toggle_keyword(tb, FLG_SECOND);
5826 add_keyword(tb, FLG_SPELLBOOKS);
5829 toggle_keyword(tb, FLG_THIRD);
5830 add_keyword(tb, FLG_SPELLBOOKS);
5833 toggle_keyword(tb, FLG_FOURTH);
5834 add_keyword(tb, FLG_SPELLBOOKS);
5838 /* Save old command */
5839 tb->old_com_id = com_id;
5846 * Insert single letter at cursor position.
5848 static void insert_single_letter(text_body_type *tb, int key)
5851 char buf[MAX_LINELEN];
5853 /* Save preceding string */
5854 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5855 buf[j++] = tb->lines_list[tb->cy][i];
5857 /* Add a character */
5865 if (j+2 < MAX_LINELEN)
5867 buf[j++] = (char)key;
5868 buf[j++] = (char)next;
5877 if (j+1 < MAX_LINELEN)
5878 buf[j++] = (char)key;
5883 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5884 buf[j++] = tb->lines_list[tb->cy][i];
5887 /* Replace current line with new line */
5888 string_free(tb->lines_list[tb->cy]);
5889 tb->lines_list[tb->cy] = string_make(buf);
5891 /* Move to correct collumn */
5892 len = strlen(tb->lines_list[tb->cy]);
5893 if (len < tb->cx) tb->cx = len;
5896 tb->dirty_line = tb->cy;
5898 /* Expressions may need re-evaluation */
5899 check_expression_line(tb, tb->cy);
5901 /* Text is changed */
5907 * Check special key code and get a movement command id
5909 static int analyze_move_key(text_body_type *tb, int skey)
5913 /* Not a special key */
5914 if (!(skey & SKEY_MASK)) return 0;
5916 /* Convert from a special key code to an editor command */
5917 switch(skey & ~SKEY_MOD_MASK)
5919 case SKEY_DOWN: com_id = EC_DOWN; break;
5920 case SKEY_LEFT: com_id = EC_LEFT; break;
5921 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5922 case SKEY_UP: com_id = EC_UP; break;
5923 case SKEY_PGUP: com_id = EC_PGUP; break;
5924 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5925 case SKEY_TOP: com_id = EC_TOP; break;
5926 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5929 /* Not a special movement key */
5933 /* Without shift modifier */
5934 if (!(skey & SKEY_MOD_SHIFT))
5937 * Un-shifted cursor keys cancells
5938 * selection created by shift+cursor.
5940 if (tb->mark & MARK_BY_SHIFT)
5945 tb->dirty_flags |= DIRTY_ALL;
5949 /* With shift modifier */
5952 /* Start selection by shift + cursor keys */
5955 int len = strlen(tb->lines_list[tb->cy]);
5957 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5961 /* Correct cursor location */
5962 if (tb->cx > len) tb->mx = len;
5964 /* Need to redraw text */
5965 if (com_id == EC_UP || com_id == EC_DOWN)
5967 /* Redraw all text */
5968 tb->dirty_flags |= DIRTY_ALL;
5972 tb->dirty_line = tb->cy;
5981 * In-game editor of Object Auto-picker/Destoryer
5983 void do_cmd_edit_autopick(void)
5985 static int cx_save = 0;
5986 static int cy_save = 0;
5988 text_body_type text_body, *tb = &text_body;
5990 autopick_type an_entry, *entry = &an_entry;
5991 char buf[MAX_LINELEN];
5996 static s32b old_autosave_turn = 0L;
5999 tb->changed = FALSE;
6002 tb->upper = tb->left = 0;
6004 tb->mx = tb->my = 0;
6005 tb->old_cy = tb->old_upper = tb->old_left = -1;
6006 tb->old_wid = tb->old_hgt = -1;
6010 tb->search_o_ptr = NULL;
6011 tb->search_str = NULL;
6012 tb->last_destroyed = NULL;
6013 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6014 tb->dirty_line = -1;
6015 tb->filename_mode = PT_DEFAULT;
6017 if (current_world_ptr->game_turn < old_autosave_turn)
6019 while (old_autosave_turn > current_world_ptr->game_turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
6023 if (current_world_ptr->game_turn > old_autosave_turn + 100L)
6025 do_cmd_save_game(TRUE);
6026 old_autosave_turn = current_world_ptr->game_turn;
6029 /* HACK -- Reset start_time to stop counting current_world_ptr->play_time while edit */
6032 /* Free old entries */
6035 /* Command Description of the 'Last Destroyed Item' */
6036 if (autopick_last_destroyed_object.k_idx)
6038 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6039 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6042 /* Read or initialize whole text */
6043 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6045 /* Reset cursor position if needed */
6046 for (i = 0; i < tb->cy; i++)
6048 if (!tb->lines_list[i])
6050 tb->cy = tb->cx = 0;
6056 /* Process requests until done */
6061 /* Draw_everythig */
6062 draw_text_editor(tb);
6064 /* Display header line */
6065 prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)",
6066 "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0);
6069 /* Display current position */
6070 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6074 /* Display current position and mark position */
6075 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6079 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6082 tb->dirty_flags = 0;
6083 tb->dirty_line = -1;
6085 /* Save old key and location */
6086 tb->old_cy = tb->cy;
6087 tb->old_upper = tb->upper;
6088 tb->old_left = tb->left;
6089 tb->old_wid = tb->wid;
6090 tb->old_hgt = tb->hgt;
6092 key = inkey_special(TRUE);
6095 if (key & SKEY_MASK)
6097 /* Get a movement command */
6098 com_id = analyze_move_key(tb, key);
6102 else if (key == ESCAPE)
6104 com_id = do_command_menu(0, 0);
6106 /* Redraw all text later */
6107 tb->dirty_flags |= DIRTY_SCREEN;
6110 /* Insert a character */
6111 else if (!iscntrl((unsigned char)key))
6113 /* Ignore selection */
6119 tb->dirty_flags |= DIRTY_ALL;
6122 insert_single_letter(tb, key);
6128 /* Other commands */
6131 com_id = get_com_id((char)key);
6134 if (com_id) quit = do_editor_command(tb, com_id);
6135 } /* while (TRUE) */
6138 /* Get the filename of preference */
6139 strcpy(buf, pickpref_filename(tb->filename_mode));
6141 if (quit == QUIT_AND_SAVE)
6142 write_text_lines(buf, tb->lines_list);
6144 free_text_lines(tb->lines_list);
6146 string_free(tb->search_str);
6147 string_free(tb->last_destroyed);
6149 /* Destroy string chain */
6150 kill_yank_chain(tb);
6152 /* Reload autopick pref */
6153 process_autopick_file(buf);
6155 /* HACK -- reset start_time so that current_world_ptr->play_time is not increase while edit */
6156 start_time = (u32b)time(NULL);
6158 /* Save cursor location */