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
17 #define MAX_LINELEN 1024
24 #define FLG_UNIDENTIFIED 2
25 #define FLG_IDENTIFIED 3
26 #define FLG_STAR_IDENTIFIED 4
27 #define FLG_COLLECTING 5
28 #define FLG_ARTIFACT 6
31 #define FLG_NAMELESS 11
32 #define FLG_AVERAGE 12
33 #define FLG_WORTHLESS 13
36 #define FLG_BOOSTED 16
37 #define FLG_MORE_DICE 17
38 #define FLG_MORE_BONUS 18
42 #define FLG_UNREADABLE 22
51 #define FLG_WEAPONS 31
52 #define FLG_FAVORITE_WEAPONS 32
54 #define FLG_MISSILES 34
55 #define FLG_DEVICES 35
58 #define FLG_CORPSES 38
59 #define FLG_SPELLBOOKS 39
61 #define FLG_SHIELDS 41
64 #define FLG_AMULETS 44
71 #define FLG_NOUN_BEGIN FLG_ITEMS
72 #define FLG_NOUN_END FLG_BOOTS
76 static char KEY_ALL[] = "すべての";
77 static char KEY_UNAWARE[] = "未判明の";
78 static char KEY_UNIDENTIFIED[] = "未鑑定の";
79 static char KEY_IDENTIFIED[] = "鑑定済みの";
80 static char KEY_STAR_IDENTIFIED[] = "*鑑定*済みの";
81 static char KEY_COLLECTING[] = "収集中の";
82 static char KEY_ARTIFACT[] = "アーティファクト";
83 static char KEY_EGO[] = "エゴ";
84 static char KEY_GOOD[] = "上質の";
85 static char KEY_NAMELESS[] = "無銘の";
86 static char KEY_AVERAGE[] = "並の";
87 static char KEY_WORTHLESS[] = "無価値の";
88 static char KEY_RARE[] = "レアな";
89 static char KEY_COMMON[] = "ありふれた";
90 static char KEY_BOOSTED[] = "ダイス目の違う";
91 static char KEY_MORE_THAN[] = "ダイス目";
92 static char KEY_DICE[] = "以上の";
93 static char KEY_MORE_BONUS[] = "修正値";
94 static char KEY_MORE_BONUS2[] = "以上の";
95 static char KEY_WANTED[] = "賞金首の";
96 static char KEY_UNIQUE[] = "ユニーク・モンスターの";
97 static char KEY_HUMAN[] = "人間の";
98 static char KEY_UNREADABLE[] = "読めない";
99 static char KEY_REALM1[] = "第一領域の";
100 static char KEY_REALM2[] = "第二領域の";
101 static char KEY_FIRST[] = "1冊目の";
102 static char KEY_SECOND[] = "2冊目の";
103 static char KEY_THIRD[] = "3冊目の";
104 static char KEY_FOURTH[] = "4冊目の";
105 static char KEY_ITEMS[] = "アイテム";
106 static char KEY_WEAPONS[] = "武器";
107 static char KEY_FAVORITE_WEAPONS[] = "得意武器";
108 static char KEY_ARMORS[] = "防具";
109 static char KEY_MISSILES[] = "矢";
110 static char KEY_DEVICES[] = "魔法アイテム";
111 static char KEY_LIGHTS[] = "光源";
112 static char KEY_JUNKS[] = "がらくた";
113 static char KEY_CORPSES[] = "死体や骨";
114 static char KEY_SPELLBOOKS[] = "魔法書";
115 static char KEY_HAFTED[] = "鈍器";
116 static char KEY_SHIELDS[] = "盾";
117 static char KEY_BOWS[] = "弓";
118 static char KEY_RINGS[] = "指輪";
119 static char KEY_AMULETS[] = "アミュレット";
120 static char KEY_SUITS[] = "鎧";
121 static char KEY_CLOAKS[] = "クローク";
122 static char KEY_HELMS[] = "兜";
123 static char KEY_GLOVES[] = "籠手";
124 static char KEY_BOOTS[] = "靴";
128 static char KEY_ALL[] = "all";
129 static char KEY_UNAWARE[] = "unaware";
130 static char KEY_UNIDENTIFIED[] = "unidentified";
131 static char KEY_IDENTIFIED[] = "identified";
132 static char KEY_STAR_IDENTIFIED[] = "*identified*";
133 static char KEY_COLLECTING[] = "collecting";
134 static char KEY_ARTIFACT[] = "artifact";
135 static char KEY_EGO[] = "ego";
136 static char KEY_GOOD[] = "good";
137 static char KEY_NAMELESS[] = "nameless";
138 static char KEY_AVERAGE[] = "average";
139 static char KEY_WORTHLESS[] = "worthless";
140 static char KEY_RARE[] = "rare";
141 static char KEY_COMMON[] = "common";
142 static char KEY_BOOSTED[] = "dice boosted";
143 static char KEY_MORE_THAN[] = "more than";
144 static char KEY_DICE[] = " dice";
145 static char KEY_MORE_BONUS[] = "more bonus than";
146 static char KEY_MORE_BONUS2[] = "";
147 static char KEY_WANTED[] = "wanted";
148 static char KEY_UNIQUE[] = "unique monster's";
149 static char KEY_HUMAN[] = "human";
150 static char KEY_UNREADABLE[] = "unreadable";
151 static char KEY_REALM1[] = "first realm's";
152 static char KEY_REALM2[] = "second realm's";
153 static char KEY_FIRST[] = "first";
154 static char KEY_SECOND[] = "second";
155 static char KEY_THIRD[] = "third";
156 static char KEY_FOURTH[] = "fourth";
157 static char KEY_ITEMS[] = "items";
158 static char KEY_WEAPONS[] = "weapons";
159 static char KEY_FAVORITE_WEAPONS[] = "favorite weapons";
160 static char KEY_ARMORS[] = "armors";
161 static char KEY_MISSILES[] = "missiles";
162 static char KEY_DEVICES[] = "magical devices";
163 static char KEY_LIGHTS[] = "lights";
164 static char KEY_JUNKS[] = "junks";
165 static char KEY_CORPSES[] = "corpses or skeletons";
166 static char KEY_SPELLBOOKS[] = "spellbooks";
167 static char KEY_HAFTED[] = "hafted weapons";
168 static char KEY_SHIELDS[] = "shields";
169 static char KEY_BOWS[] = "bows";
170 static char KEY_RINGS[] = "rings";
171 static char KEY_AMULETS[] = "amulets";
172 static char KEY_SUITS[] = "suits";
173 static char KEY_CLOAKS[] = "cloaks";
174 static char KEY_HELMS[] = "helms";
175 static char KEY_GLOVES[] = "gloves";
176 static char KEY_BOOTS[] = "boots";
180 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
181 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
182 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
183 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
186 #define ADD_KEY(KEY) strcat(ptr, KEY)
188 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
190 #define ADD_KEY2(KEY) strcat(ptr, KEY)
192 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
193 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
194 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
195 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
198 static char kanji_colon[] = ":";
203 * A function to create new entry
205 static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_default)
210 char buf[MAX_LINELEN];
211 cptr prev_ptr, ptr, old_ptr;
214 if (str[0] && str[1] == ':') switch (str[0])
217 case 'A': case 'P': case 'C':
221 entry->flag[0] = entry->flag[1] = 0L;
225 act = DO_AUTOPICK | DO_DISPLAY;
228 if ((act & DO_AUTOPICK) && *str == '!')
231 act |= DO_AUTODESTROY;
234 else if ((act & DO_AUTOPICK) && *str == '~')
237 act |= DONT_AUTOPICK;
240 else if ((act & DO_AUTOPICK) && *str == ';')
243 act |= DO_QUERY_AUTOPICK;
246 else if ((act & DO_DISPLAY) && *str == '(')
255 /* don't mind upper or lower case */
257 for (i = 0; *str; i++)
268 /* Auto-inscription? */
276 if (isupper(c)) c = (char)tolower(c);
282 /* Skip empty line unless allow_default */
283 if (!allow_default && *buf == 0) return FALSE;
285 /* Skip comment line */
286 if (*buf == 0 && insc) return FALSE;
288 ptr = prev_ptr = buf;
291 while (old_ptr != ptr)
293 /* Save current location */
296 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
297 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
298 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
299 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
300 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
301 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
302 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
304 /*** Weapons whose dd*ds is more than nn ***/
305 if (MATCH_KEY2(KEY_MORE_THAN))
310 /* Drop leading spaces */
311 while (' ' == *ptr) ptr++;
314 while ('0' <= *ptr && *ptr <= '9')
316 entry->dice = 10 * entry->dice + (*ptr - '0');
323 (void)MATCH_KEY(KEY_DICE);
324 ADD_FLG(FLG_MORE_DICE);
330 /*** Items whose magical bonus is more than n ***/
331 if (MATCH_KEY2(KEY_MORE_BONUS))
336 /* Drop leading spaces */
337 while (' ' == *ptr) ptr++;
340 while ('0' <= *ptr && *ptr <= '9')
342 entry->bonus = 10 * entry->bonus + (*ptr - '0');
350 (void)MATCH_KEY(KEY_MORE_BONUS2);
352 if (' ' == *ptr) ptr++;
354 ADD_FLG(FLG_MORE_BONUS);
360 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
361 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
362 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
363 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
364 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
365 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
366 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
367 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
368 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
369 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
370 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
371 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
372 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
373 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
374 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
375 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
376 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
379 /* Not yet found any noun */
382 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
384 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
385 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
386 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
387 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
388 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
389 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
390 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
391 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
392 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
393 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
394 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
395 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
396 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
397 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
398 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
399 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
400 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
401 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
402 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
403 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
405 /* Last 'keyword' must be at the correct location */
409 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
412 else if (*ptr == '\0')
414 /* There was no noun */
417 /* Add extra word "items" */
418 ADD_FLG_NOUN(FLG_ITEMS);
425 /* A noun type keyword didn't end correctly */
426 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
431 /* Save this auto-picker entry line */
432 entry->name = string_make(ptr);
434 entry->insc = string_make(insc);
441 * Get auto-picker entry from o_ptr.
443 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
445 /* Assume that object name is to be added */
449 /* エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない */
450 bool bol_mark = FALSE;
452 /* We can always use the ^ mark in English */
453 bool bol_mark = TRUE;
456 char name_str[MAX_NLEN];
458 /* Initialize name string */
461 entry->insc = string_make(quark_str(o_ptr->inscription));
462 entry->action = DO_AUTOPICK | DO_DISPLAY;
463 entry->flag[0] = entry->flag[1] = 0L;
467 if (!object_is_aware(o_ptr))
469 ADD_FLG(FLG_UNAWARE);
473 /* Not really identified */
474 else if (!object_is_known(o_ptr))
476 if (!(o_ptr->ident & IDENT_SENSE))
478 ADD_FLG(FLG_UNIDENTIFIED);
483 /* Pseudo-identified */
484 switch (o_ptr->feeling)
488 ADD_FLG(FLG_NAMELESS);
494 ADD_FLG(FLG_NAMELESS);
495 ADD_FLG(FLG_WORTHLESS);
501 ADD_FLG(FLG_WORTHLESS);
509 /* XXX No appropriate flag */
514 /* Never reach here */
524 if (object_is_ego(o_ptr))
526 if (object_is_weapon_armour_ammo(o_ptr))
529 * Base name of ego weapons and armors
530 * are almost meaningless.
531 * Register the ego type only.
533 ego_item_type *e_ptr = &e_info[o_ptr->name2];
535 /* エゴ銘には「^」マークが使える */
536 sprintf(name_str, "^%s", e_name + e_ptr->name);
538 /* We ommit the basename and cannot use the ^ mark */
539 strcpy(name_str, e_name + e_ptr->name);
542 /* Don't use the object description */
545 /* Restrict to 'common' equipments */
546 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
553 else if (object_is_artifact(o_ptr))
554 ADD_FLG(FLG_ARTIFACT);
556 /* Non-ego, non-artifact */
559 /* Wearable nameless object */
560 if (object_is_equipment(o_ptr))
561 ADD_FLG(FLG_NAMELESS);
568 /* Melee weapon with boosted dice */
569 if (object_is_melee_weapon(o_ptr))
571 object_kind *k_ptr = &k_info[o_ptr->k_idx];
573 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
574 ADD_FLG(FLG_BOOSTED);
577 /* Wanted monster's corpse */
578 if (object_is_shoukinkubi(o_ptr))
580 REM_FLG(FLG_WORTHLESS);
584 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
585 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
590 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
595 if (o_ptr->tval >= TV_LIFE_BOOK &&
596 !check_book_realm(o_ptr->tval, o_ptr->sval))
598 ADD_FLG(FLG_UNREADABLE);
599 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
602 if (REALM1_BOOK == o_ptr->tval &&
603 p_ptr->pclass != CLASS_SORCERER &&
604 p_ptr->pclass != CLASS_RED_MAGE)
610 if (REALM2_BOOK == o_ptr->tval &&
611 p_ptr->pclass != CLASS_SORCERER &&
612 p_ptr->pclass != CLASS_RED_MAGE)
618 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
620 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
622 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
624 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
627 if (object_is_ammo(o_ptr))
628 ADD_FLG(FLG_MISSILES);
629 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
630 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
631 ADD_FLG(FLG_DEVICES);
632 else if (o_ptr->tval == TV_LITE)
634 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
635 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
637 else if (o_ptr->tval == TV_CORPSE)
638 ADD_FLG(FLG_CORPSES);
639 else if (o_ptr->tval >= TV_LIFE_BOOK)
640 ADD_FLG(FLG_SPELLBOOKS);
641 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
642 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
643 ADD_FLG(FLG_WEAPONS);
644 else if (o_ptr->tval == TV_SHIELD)
645 ADD_FLG(FLG_SHIELDS);
646 else if (o_ptr->tval == TV_BOW)
648 else if (o_ptr->tval == TV_RING)
650 else if (o_ptr->tval == TV_AMULET)
651 ADD_FLG(FLG_AMULETS);
652 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
653 o_ptr->tval == TV_SOFT_ARMOR)
655 else if (o_ptr->tval == TV_CLOAK)
657 else if (o_ptr->tval == TV_HELM)
659 else if (o_ptr->tval == TV_GLOVES)
661 else if (o_ptr->tval == TV_BOOTS)
664 /* Prepare the object description */
667 char o_name[MAX_NLEN];
669 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
672 * If necessary, add a '^' which indicates the
675 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
678 /* Register the name in lowercase */
679 str_tolower(name_str);
680 entry->name = string_make(name_str);
687 * A function to delete entry
689 static void autopick_free_entry(autopick_type *entry)
691 string_free(entry->name);
692 string_free(entry->insc);
698 #define MAX_AUTOPICK_DEFAULT 200
701 * Initialize the autopick
703 static void init_autopick(void)
705 static const char easy_autopick_inscription[] = "(:=g";
711 max_max_autopick = MAX_AUTOPICK_DEFAULT;
712 C_MAKE(autopick_list, max_max_autopick, autopick_type);
716 /* Clear old entries */
717 for( i = 0; i < max_autopick; i++)
718 autopick_free_entry(&autopick_list[i]);
722 /* There is always one entry "=g" */
723 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
724 autopick_list[max_autopick++] = entry;
729 #define PT_WITH_PNAME 1
732 * Get file name for autopick preference
734 static cptr pickpref_filename(int filename_mode)
736 static const char namebase[] = _("picktype", "pickpref");
738 switch (filename_mode)
741 return format("%s.prf", namebase);
744 return format("%s-%s.prf", namebase, player_base);
753 * Load an autopick preference file
755 void autopick_load_pref(bool disp_mes)
760 /* Free old entries */
763 /* Try a filename with player name */
764 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
767 err = process_autopick_file(buf);
769 if (err == 0 && disp_mes)
772 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
778 /* Use default name */
779 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
782 err = process_autopick_file(buf);
784 if (err == 0 && disp_mes)
787 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
794 msg_print(_("自動拾い設定ファイルの読み込みに失敗しました。", "Failed to reload autopick preference."));
800 * Add one line to autopick_list[]
802 static void add_autopick_list(autopick_type *entry)
804 /* There is no enough space to add one line */
805 if (max_autopick >= max_max_autopick)
807 int old_max_max_autopick = max_max_autopick;
808 autopick_type *old_autopick_list = autopick_list;
810 /* Increase size of list */
811 max_max_autopick += MAX_AUTOPICK_DEFAULT;
814 C_MAKE(autopick_list, max_max_autopick, autopick_type);
816 /* Copy from old list to new list */
817 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
820 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
824 autopick_list[max_autopick] = *entry;
831 * Process line for auto picker/destroyer.
833 errr process_autopick_file_command(char *buf)
835 autopick_type an_entry, *entry = &an_entry;
838 /* Nuke illegal char */
839 for(i = 0; buf[i]; i++)
848 if (iswspace(buf[i]) && buf[i] != ' ')
853 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
855 /* Already has the same entry? */
856 for(i = 0; i < max_autopick; i++)
857 if(!strcmp(entry->name, autopick_list[i].name)
858 && entry->flag[0] == autopick_list[i].flag[0]
859 && entry->flag[1] == autopick_list[i].flag[1]
860 && entry->dice == autopick_list[i].dice
861 && entry->bonus == autopick_list[i].bonus)
863 autopick_free_entry(entry);
867 add_autopick_list(entry);
873 * Reconstruct preference line from entry
875 cptr autopick_line_from_entry(autopick_type *entry)
877 char buf[MAX_LINELEN];
879 bool sepa_flag = TRUE;
882 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
883 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
884 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
885 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
889 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
890 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
891 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
892 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
893 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
894 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
895 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
897 if (IS_FLG(FLG_MORE_DICE))
899 ADD_KEY(KEY_MORE_THAN);
900 strcat(ptr, format("%d", entry->dice));
904 if (IS_FLG(FLG_MORE_BONUS))
906 ADD_KEY(KEY_MORE_BONUS);
907 strcat(ptr, format("%d", entry->bonus));
908 ADD_KEY(KEY_MORE_BONUS2);
911 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
912 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
913 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
914 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
915 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
916 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
917 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
918 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
919 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
920 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
921 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
922 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
923 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
924 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
925 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
926 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
927 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
929 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
931 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
932 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
933 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
934 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
935 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
936 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
937 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
938 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
939 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
940 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
941 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
942 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
943 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
944 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
945 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
946 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
947 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
948 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
949 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
950 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
952 /* You don't need sepalator after adjective */
953 /* 'artifact' is not true adjective */
954 else if (!IS_FLG(FLG_ARTIFACT))
957 if (entry->name && entry->name[0])
961 if (sepa_flag) strcat(buf, ":");
964 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
967 if (iskanji(entry->name[j]))
968 buf[i++] = entry->name[j++];
970 buf[i++] = entry->name[j++];
981 while (entry->insc[j] && i < MAX_LINELEN - 2)
984 if (iskanji(entry->insc[j]))
985 buf[i++] = entry->insc[j++];
987 buf[i++] = entry->insc[j++];
992 return string_make(buf);
997 * Reconstruct preference line from entry and kill entry
999 static cptr autopick_line_from_entry_kill(autopick_type *entry)
1001 cptr ptr = autopick_line_from_entry(entry);
1003 /* Free memory for original entry */
1004 autopick_free_entry(entry);
1011 * A function for Auto-picker/destroyer
1012 * Examine whether the object matches to the entry
1014 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
1017 cptr ptr = entry->name;
1019 /*** Unaware items ***/
1020 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1023 /*** Unidentified ***/
1024 if (IS_FLG(FLG_UNIDENTIFIED)
1025 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1028 /*** Identified ***/
1029 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1032 /*** *Identified* ***/
1033 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1034 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1037 /*** Dice boosted (weapon of slaying) ***/
1038 if (IS_FLG(FLG_BOOSTED))
1040 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1042 /* Require melee weapon */
1043 if (!object_is_melee_weapon(o_ptr))
1046 /* Require boosted dice */
1047 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1050 /* In Vault Quest, Dice must be hide.*/
1051 if(!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
1057 /*** Weapons which dd*ds is more than nn ***/
1058 if (IS_FLG(FLG_MORE_DICE))
1060 if (o_ptr->dd * o_ptr->ds < entry->dice)
1064 /*** Weapons whic dd*ds is more than nn ***/
1065 if (IS_FLG(FLG_MORE_BONUS))
1067 if (!object_is_known(o_ptr)) return FALSE;
1071 if (o_ptr->pval < entry->bonus) return FALSE;
1075 if (o_ptr->to_h < entry->bonus &&
1076 o_ptr->to_d < entry->bonus &&
1077 o_ptr->to_a < entry->bonus &&
1078 o_ptr->pval < entry->bonus)
1083 /*** Worthless items ***/
1084 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1087 /*** Artifact object ***/
1088 if (IS_FLG(FLG_ARTIFACT))
1090 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1094 /*** Ego object ***/
1095 if (IS_FLG(FLG_EGO))
1097 /* Need to be an ego item */
1098 if (!object_is_ego(o_ptr)) return FALSE;
1100 /* Need to be known to be an ego */
1101 if (!object_is_known(o_ptr) &&
1102 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1107 if (IS_FLG(FLG_GOOD))
1109 if (!object_is_equipment(o_ptr)) return FALSE;
1112 if (object_is_known(o_ptr))
1114 /* Artifacts and Ego objects are not okay */
1115 if (!object_is_nameless(o_ptr))
1118 /* Average are not okay */
1119 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1123 /* Pseudo-identified */
1124 else if (o_ptr->ident & IDENT_SENSE)
1126 switch (o_ptr->feeling)
1141 /* Not known to be good */
1147 if (IS_FLG(FLG_NAMELESS))
1149 if (!object_is_equipment(o_ptr)) return FALSE;
1152 if (object_is_known(o_ptr))
1154 /* Artifacts and Ego objects are not okay */
1155 if (!object_is_nameless(o_ptr))
1159 /* Pseudo-identified */
1160 else if (o_ptr->ident & IDENT_SENSE)
1162 switch (o_ptr->feeling)
1172 /* It's not nameless */
1180 /* Not known to be nameless */
1186 if (IS_FLG(FLG_AVERAGE))
1188 if (!object_is_equipment(o_ptr)) return FALSE;
1191 if (object_is_known(o_ptr))
1193 /* Artifacts and Ego objects are not okay */
1194 if (!object_is_nameless(o_ptr))
1197 /* Cursed or broken objects are not okay */
1198 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1201 /* Good are not okay */
1202 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1206 /* Pseudo-identified */
1207 else if (o_ptr->ident & IDENT_SENSE)
1209 switch (o_ptr->feeling)
1216 /* It's not average */
1224 /* Not known to be average */
1229 /*** Rere equipments ***/
1230 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1233 /*** Common equipments ***/
1234 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1237 /*** Wanted monster's corpse/skeletons ***/
1238 if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
1241 /*** Unique monster's corpse/skeletons/statues ***/
1242 if (IS_FLG(FLG_UNIQUE) &&
1243 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1244 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1247 /*** Human corpse/skeletons (for Daemon magic) ***/
1248 if (IS_FLG(FLG_HUMAN) &&
1249 (o_ptr->tval != TV_CORPSE ||
1250 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1253 /*** Unreadable spellbooks ***/
1254 if (IS_FLG(FLG_UNREADABLE) &&
1255 (o_ptr->tval < TV_LIFE_BOOK ||
1256 check_book_realm(o_ptr->tval, o_ptr->sval)))
1259 /*** First realm spellbooks ***/
1260 if (IS_FLG(FLG_REALM1) &&
1261 (REALM1_BOOK != o_ptr->tval ||
1262 p_ptr->pclass == CLASS_SORCERER ||
1263 p_ptr->pclass == CLASS_RED_MAGE))
1266 /*** Second realm spellbooks ***/
1267 if (IS_FLG(FLG_REALM2) &&
1268 (REALM2_BOOK != o_ptr->tval ||
1269 p_ptr->pclass == CLASS_SORCERER ||
1270 p_ptr->pclass == CLASS_RED_MAGE))
1273 /*** First rank spellbooks ***/
1274 if (IS_FLG(FLG_FIRST) &&
1275 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1278 /*** Second rank spellbooks ***/
1279 if (IS_FLG(FLG_SECOND) &&
1280 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1283 /*** Third rank spellbooks ***/
1284 if (IS_FLG(FLG_THIRD) &&
1285 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1288 /*** Fourth rank spellbooks ***/
1289 if (IS_FLG(FLG_FOURTH) &&
1290 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1294 if (IS_FLG(FLG_WEAPONS))
1296 if (!object_is_weapon(o_ptr))
1299 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1301 if (!object_is_favorite(o_ptr))
1304 else if (IS_FLG(FLG_ARMORS))
1306 if (!object_is_armour(o_ptr))
1309 else if (IS_FLG(FLG_MISSILES))
1311 if (!object_is_ammo(o_ptr)) return FALSE;
1313 else if (IS_FLG(FLG_DEVICES))
1317 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1319 default: return FALSE;
1322 else if (IS_FLG(FLG_LIGHTS))
1324 if (!(o_ptr->tval == TV_LITE))
1327 else if (IS_FLG(FLG_JUNKS))
1331 case TV_SKELETON: case TV_BOTTLE:
1332 case TV_JUNK: case TV_STATUE:
1334 default: return FALSE;
1337 else if (IS_FLG(FLG_CORPSES))
1339 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1342 else if (IS_FLG(FLG_SPELLBOOKS))
1344 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1347 else if (IS_FLG(FLG_HAFTED))
1349 if (!(o_ptr->tval == TV_HAFTED))
1352 else if (IS_FLG(FLG_SHIELDS))
1354 if (!(o_ptr->tval == TV_SHIELD))
1357 else if (IS_FLG(FLG_BOWS))
1359 if (!(o_ptr->tval == TV_BOW))
1362 else if (IS_FLG(FLG_RINGS))
1364 if (!(o_ptr->tval == TV_RING))
1367 else if (IS_FLG(FLG_AMULETS))
1369 if (!(o_ptr->tval == TV_AMULET))
1372 else if (IS_FLG(FLG_SUITS))
1374 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1375 o_ptr->tval == TV_HARD_ARMOR ||
1376 o_ptr->tval == TV_SOFT_ARMOR))
1379 else if (IS_FLG(FLG_CLOAKS))
1381 if (!(o_ptr->tval == TV_CLOAK))
1384 else if (IS_FLG(FLG_HELMS))
1386 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1389 else if (IS_FLG(FLG_GLOVES))
1391 if (!(o_ptr->tval == TV_GLOVES))
1394 else if (IS_FLG(FLG_BOOTS))
1396 if (!(o_ptr->tval == TV_BOOTS))
1400 /* Keyword don't match */
1404 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1408 if (!my_strstr(o_name, ptr)) return FALSE;
1411 /* TRUE when it need not to be 'collecting' */
1412 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1414 /* Check if there is a same item */
1415 for (j = 0; j < INVEN_PACK; j++)
1418 * 'Collecting' means the item must be absorbed
1419 * into an inventory slot.
1420 * But an item can not be absorbed into itself!
1422 if ((&inventory[j] != o_ptr) &&
1423 object_similar(&inventory[j], o_ptr))
1427 /* Not collecting */
1433 * A function for Auto-picker/destroyer
1434 * Examine whether the object matches to the list of keywords or not.
1436 int is_autopick(object_type *o_ptr)
1439 char o_name[MAX_NLEN];
1441 if (o_ptr->tval == TV_GOLD) return -1;
1443 /* Prepare object name string first */
1444 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1446 /* Convert the string to lower case */
1447 str_tolower(o_name);
1449 /* Look for a matching entry in the list */
1450 for (i=0; i < max_autopick; i++)
1452 autopick_type *entry = &autopick_list[i];
1454 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1457 /* No matching entry */
1465 static void auto_inscribe_item(object_type *o_ptr, int idx)
1467 /* Are there auto-inscription? */
1468 if (idx < 0 || !autopick_list[idx].insc) return;
1470 if (!o_ptr->inscription)
1471 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1473 /* Redraw inscription */
1474 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1476 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1477 p_ptr->update |= (PU_BONUS);
1482 * Automatically destroy items in this grid.
1484 static bool is_opt_confirm_destroy(object_type *o_ptr)
1486 if (!destroy_items) return FALSE;
1488 /* Known to be worthless? */
1490 if (object_value(o_ptr) > 0) return FALSE;
1493 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1496 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1500 if (object_is_shoukinkubi(o_ptr)) return FALSE;
1504 if (o_ptr->tval == TV_CORPSE) return FALSE;
1507 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1511 if (p_ptr->prace == RACE_DEMON)
1513 if (o_ptr->tval == TV_CORPSE &&
1514 o_ptr->sval == SV_CORPSE &&
1515 my_strchr("pht", r_info[o_ptr->pval].d_char))
1519 if (p_ptr->pclass == CLASS_ARCHER)
1521 if (o_ptr->tval == TV_SKELETON ||
1522 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1525 else if (p_ptr->pclass == CLASS_NINJA)
1527 if (o_ptr->tval == TV_LITE &&
1528 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1531 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1532 p_ptr->pclass == CLASS_CAVALRY)
1534 if (o_ptr->tval == TV_WAND &&
1535 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1540 if (o_ptr->tval == TV_GOLD) return FALSE;
1547 * Automatically destroy an item if it is to be destroyed
1549 * When always_pickup is 'yes', we disable auto-destroyer function of
1550 * auto-picker/destroyer, and do only easy-auto-destroyer.
1552 static object_type autopick_last_destroyed_object;
1554 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1556 bool destroy = FALSE;
1558 /* Easy-Auto-Destroyer (3rd priority) */
1559 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1561 /* Protected by auto-picker (2nd priotity) */
1562 if (autopick_idx >= 0 &&
1563 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1566 /* Auto-destroyer works only when !always_pickup */
1569 /* Auto-picker/destroyer (1st priority) */
1570 if (autopick_idx >= 0 &&
1571 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1575 /* Not to be destroyed */
1576 if (!destroy) return;
1578 /* Now decided to destroy */
1583 if (!can_player_destroy_object(o_ptr))
1585 char o_name[MAX_NLEN];
1587 /* Describe the object (with {terrible/special}) */
1588 object_desc(o_name, o_ptr, 0);
1590 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1595 /* Record name of destroyed item */
1596 (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1599 o_ptr->marked |= OM_AUTODESTROY;
1600 p_ptr->notice |= PN_AUTODESTROY;
1607 * Auto-destroy marked item
1609 static void autopick_delayed_alter_aux(INVENTORY_IDX item)
1613 /* Get the item (in the pack) */
1614 if (item >= 0) o_ptr = &inventory[item];
1616 /* Get the item (on the floor) */
1617 else o_ptr = &o_list[0 - item];
1619 if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
1621 char o_name[MAX_NLEN];
1623 /* Describe the object (with {terrible/special}) */
1624 object_desc(o_name, o_ptr, 0);
1626 /* Eliminate the item (from the pack) */
1629 inven_item_increase(item, -(o_ptr->number));
1630 inven_item_optimize(item);
1633 /* Eliminate the item (from the floor) */
1636 delete_object_idx(0 - item);
1639 /* Print a message */
1640 msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name);
1646 * Auto-destroy marked items in inventry and on floor
1648 void autopick_delayed_alter(void)
1653 * Scan inventry in reverse order to prevent
1654 * skipping after inven_item_optimize()
1656 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1657 autopick_delayed_alter_aux(item);
1659 /* Scan the pile of objects */
1660 item = cave[p_ptr->y][p_ptr->x].o_idx;
1663 OBJECT_IDX next = o_list[item].next_o_idx;
1664 autopick_delayed_alter_aux(-item);
1671 * Auto-inscription and/or destroy
1673 * Auto-destroyer works only on inventory or on floor stack only when
1676 void autopick_alter_item(INVENTORY_IDX item, bool destroy)
1681 /* Get the item (in the pack) */
1682 if (item >= 0) o_ptr = &inventory[item];
1684 /* Get the item (on the floor) */
1685 else o_ptr = &o_list[0 - item];
1687 /* Get the index in the auto-pick/destroy list */
1688 idx = is_autopick(o_ptr);
1690 /* Do auto-inscription */
1691 auto_inscribe_item(o_ptr, idx);
1693 /* Do auto-destroy if needed */
1694 if (destroy && item <= INVEN_PACK)
1695 auto_destroy_item(o_ptr, idx);
1700 * Automatically pickup/destroy items in this grid.
1702 void autopick_pickup_items(cave_type *c_ptr)
1704 OBJECT_IDX this_o_idx, next_o_idx = 0;
1706 /* Scan the pile of objects */
1707 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1711 /* Acquire object */
1712 object_type *o_ptr = &o_list[this_o_idx];
1714 /* Acquire next object */
1715 next_o_idx = o_ptr->next_o_idx;
1717 idx = is_autopick(o_ptr);
1719 /* Item index for floor -1,-2,-3,... */
1720 auto_inscribe_item(o_ptr, idx);
1723 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1727 if (!inven_carry_okay(o_ptr))
1729 char o_name[MAX_NLEN];
1731 /* Describe the object */
1732 object_desc(o_name, o_ptr, 0);
1734 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
1735 /* Hack - remember that the item has given a message here. */
1736 o_ptr->marked |= OM_NOMSG;
1740 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1742 char out_val[MAX_NLEN+20];
1743 char o_name[MAX_NLEN];
1745 if (o_ptr->marked & OM_NO_QUERY)
1747 /* Already answered as 'No' */
1751 /* Describe the object */
1752 object_desc(o_name, o_ptr, 0);
1754 sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
1756 if (!get_check(out_val))
1758 /* Hack - remember that the item has given a message here. */
1759 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1764 py_pickup_aux(this_o_idx);
1769 * When always_pickup is 'yes', we disable
1770 * auto-destroyer from autopick function, and do only
1771 * easy-auto-destroyer.
1775 auto_destroy_item(o_ptr, idx);
1781 static const char autoregister_header[] = "?:$AUTOREGISTER";
1784 * Clear auto registered lines in the picktype.prf .
1786 static bool clear_auto_register(void)
1788 char tmp_file[1024];
1789 char pref_file[1024];
1794 bool autoregister = FALSE;
1797 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1798 pref_fff = my_fopen(pref_file, "r");
1802 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1803 pref_fff = my_fopen(pref_file, "r");
1812 /* Open a new (temporary) file */
1813 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1817 /* Close the preference file */
1819 msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
1825 /* Loop for every line */
1829 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1833 /* Delete auto-registered line */
1835 /* Count auto-destroy preference lines */
1836 if (buf[0] != '#' && buf[0] != '?') num++;
1839 /* We are looking for auto-registered line */
1842 if (streq(buf, autoregister_header))
1844 /* Delete all further lines */
1845 autoregister = TRUE;
1849 /* Copy orginally lines */
1850 fprintf(tmp_fff, "%s\n", buf);
1856 my_fclose(pref_fff);
1861 msg_format(_("以前のキャラクター用の自動設定(%d行)が残っています。",
1862 "Auto registered lines (%d lines) for previous character are remaining."), num);
1863 strcpy(buf, _("古い設定行は削除します。よろしいですか?", "These lines will be deleted. Are you sure? "));
1865 /* You can cancel it */
1866 if (!get_check(buf))
1869 autoregister = FALSE;
1871 msg_print(_("エディタのカット&ペースト等を使って必要な行を避難してください。",
1872 "Use cut & paste of auto picker editor (_) to keep old prefs."));
1877 /* If there are some changes, overwrite the original file with new one */
1880 /* Copy contents of temporary file */
1882 tmp_fff = my_fopen(tmp_file, "r");
1883 pref_fff = my_fopen(pref_file, "w");
1885 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1886 fprintf(pref_fff, "%s\n", buf);
1888 my_fclose(pref_fff);
1892 /* Kill the temporary file */
1900 * Automatically register an auto-destroy preference line
1902 bool autopick_autoregister(object_type *o_ptr)
1905 char pref_file[1024];
1907 autopick_type an_entry, *entry = &an_entry;
1909 int match_autopick = is_autopick(o_ptr);
1911 /* Already registered */
1912 if (match_autopick != -1)
1915 byte act = autopick_list[match_autopick].action;
1917 if (act & DO_AUTOPICK) what = _("自動で拾う", "auto-pickup");
1918 else if (act & DO_AUTODESTROY) what = _("自動破壊する", "auto-destroy");
1919 else if (act & DONT_AUTOPICK) what = _("放置する", "leave on floor");
1920 else /* if (act & DO_QUERY_AUTOPICK) */ what = _("確認して拾う", "query auto-pickup");
1922 msg_format(_("そのアイテムは既に%sように設定されています。", "The object is already registered to %s."), what);
1926 /* Known to be an artifact? */
1927 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1928 ((o_ptr->ident & IDENT_SENSE) &&
1929 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1931 char o_name[MAX_NLEN];
1933 /* Describe the object (with {terrible/special}) */
1934 object_desc(o_name, o_ptr, 0);
1936 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1942 if (!p_ptr->autopick_autoregister)
1944 /* Clear old auto registered lines */
1945 if (!clear_auto_register()) return FALSE;
1948 /* Try a filename with player name */
1949 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1950 pref_fff = my_fopen(pref_file, "r");
1954 /* Use default name */
1955 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1956 pref_fff = my_fopen(pref_file, "r");
1959 /* Check the header */
1963 if (my_fgets(pref_fff, buf, sizeof(buf)))
1965 /* No header found */
1966 p_ptr->autopick_autoregister = FALSE;
1971 if (streq(buf, autoregister_header))
1973 /* Found the header */
1974 p_ptr->autopick_autoregister = TRUE;
1980 /* Close read only FILE* */
1983 /* Open for append */
1984 pref_fff = my_fopen(pref_file, "a");
1988 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), pref_file);
1995 if (!p_ptr->autopick_autoregister)
1997 /* Add the header */
1998 fprintf(pref_fff, "%s\n", autoregister_header);
2000 fprintf(pref_fff, "%s\n", _("# *警告!!* 以降の行は自動登録されたものです。",
2001 "# *Waring!* The lines below will be deleated later."));
2002 fprintf(pref_fff, "%s\n", _("# 後で自動的に削除されますので、必要な行は上の方へ移動しておいてください。",
2003 "# Keep it by cut & paste if you need these lines for future characters."));
2005 /* Now auto register is in-use */
2006 p_ptr->autopick_autoregister = TRUE;
2009 /* Get a preference entry */
2010 autopick_entry_from_object(entry, o_ptr);
2012 /* Set to auto-destroy (with no-display) */
2013 entry->action = DO_AUTODESTROY;
2015 /* Load the new line as preference */
2016 add_autopick_list(entry);
2018 /* Add a line to the file */
2019 /* Don't kill "entry" */
2020 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2022 /* Close the file */
2029 /******** Auto-picker/destroyer editor **********/
2031 #define MAX_YANK MAX_LINELEN
2032 #define MAX_LINES 3000
2034 #define MARK_MARK 0x01
2035 #define MARK_BY_SHIFT 0x02
2037 #define LSTAT_BYPASS 0x01
2038 #define LSTAT_EXPRESSION 0x02
2039 #define LSTAT_AUTOREGISTER 0x04
2041 #define QUIT_WITHOUT_SAVE 1
2042 #define QUIT_AND_SAVE 2
2045 * Struct for yank buffer
2047 typedef struct chain_str {
2048 struct chain_str *next;
2054 * Data struct for text editor
2060 int old_wid, old_hgt;
2062 int old_upper, old_left;
2066 object_type *search_o_ptr;
2068 cptr last_destroyed;
2070 chain_str_type *yank;
2074 byte states[MAX_LINES];
2086 * Dirty flag for text editor
2088 #define DIRTY_ALL 0x0001
2089 #define DIRTY_MODE 0x0004
2090 #define DIRTY_SCREEN 0x0008
2091 #define DIRTY_NOT_FOUND 0x0010
2092 #define DIRTY_NO_SEARCH 0x0020
2093 #define DIRTY_EXPRESSION 0x0040
2094 #define DIRTY_SKIP_INACTIVE 0x0080
2095 #define DIRTY_INACTIVE 0x0100
2098 * Describe which kind of object is Auto-picked/destroyed
2100 static void describe_autopick(char *buff, autopick_type *entry)
2102 cptr str = entry->name;
2103 byte act = entry->action;
2104 cptr insc = entry->insc;
2110 cptr before_str[100], body_str;
2115 /*** Collecting items ***/
2116 /*** Which can be absorbed into a slot as a bundle ***/
2117 if (IS_FLG(FLG_COLLECTING))
2118 before_str[before_n++] = "収集中で既に持っているスロットにまとめられる";
2120 /*** Unaware items ***/
2121 if (IS_FLG(FLG_UNAWARE))
2122 before_str[before_n++] = "未鑑定でその効果も判明していない";
2124 /*** Unidentified ***/
2125 if (IS_FLG(FLG_UNIDENTIFIED))
2126 before_str[before_n++] = "未鑑定の";
2128 /*** Identified ***/
2129 if (IS_FLG(FLG_IDENTIFIED))
2130 before_str[before_n++] = "鑑定済みの";
2132 /*** *Identified* ***/
2133 if (IS_FLG(FLG_STAR_IDENTIFIED))
2134 before_str[before_n++] = "完全に鑑定済みの";
2136 /*** Dice boosted (weapon of slaying) ***/
2137 if (IS_FLG(FLG_BOOSTED))
2139 before_str[before_n++] = "ダメージダイスが通常より大きい";
2143 /*** Weapons whose dd*ds is more than nn ***/
2144 if (IS_FLG(FLG_MORE_DICE))
2146 static char more_than_desc_str[] = "___";
2147 before_str[before_n++] = "ダメージダイスの最大値が";
2150 sprintf(more_than_desc_str,"%d", entry->dice);
2151 before_str[before_n++] = more_than_desc_str;
2152 before_str[before_n++] = "以上の";
2155 /*** Items whose magical bonus is more than nn ***/
2156 if (IS_FLG(FLG_MORE_BONUS))
2158 static char more_bonus_desc_str[] = "___";
2159 before_str[before_n++] = "修正値が(+";
2161 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2162 before_str[before_n++] = more_bonus_desc_str;
2163 before_str[before_n++] = ")以上の";
2166 /*** Worthless items ***/
2167 if (IS_FLG(FLG_WORTHLESS))
2168 before_str[before_n++] = "店で無価値と判定される";
2171 if (IS_FLG(FLG_ARTIFACT))
2173 before_str[before_n++] = "アーティファクトの";
2178 if (IS_FLG(FLG_EGO))
2180 before_str[before_n++] = "エゴアイテムの";
2185 if (IS_FLG(FLG_GOOD))
2187 before_str[before_n++] = "上質の";
2192 if (IS_FLG(FLG_NAMELESS))
2194 before_str[before_n++] = "エゴでもアーティファクトでもない";
2199 if (IS_FLG(FLG_AVERAGE))
2201 before_str[before_n++] = "並の";
2205 /*** Rare equipments ***/
2206 if (IS_FLG(FLG_RARE))
2208 before_str[before_n++] = "ドラゴン装備やカオス・ブレード等を含む珍しい";
2212 /*** Common equipments ***/
2213 if (IS_FLG(FLG_COMMON))
2215 before_str[before_n++] = "ありふれた(ドラゴン装備やカオス・ブレード等の珍しい物ではない)";
2219 /*** Wanted monster's corpse/skeletons ***/
2220 if (IS_FLG(FLG_WANTED))
2222 before_str[before_n++] = "ハンター事務所で賞金首とされている";
2226 /*** Human corpse/skeletons (for Daemon magic) ***/
2227 if (IS_FLG(FLG_HUMAN))
2229 before_str[before_n++] = "悪魔魔法で使うための人間やヒューマノイドの";
2233 /*** Unique monster's corpse/skeletons/statues ***/
2234 if (IS_FLG(FLG_UNIQUE))
2236 before_str[before_n++] = "ユニークモンスターの";
2240 /*** Unreadable spellbooks ***/
2241 if (IS_FLG(FLG_UNREADABLE))
2243 before_str[before_n++] = "あなたが読めない領域の";
2247 /*** First realm spellbooks ***/
2248 if (IS_FLG(FLG_REALM1))
2250 before_str[before_n++] = "第一領域の";
2254 /*** Second realm spellbooks ***/
2255 if (IS_FLG(FLG_REALM2))
2257 before_str[before_n++] = "第二領域の";
2261 /*** First rank spellbooks ***/
2262 if (IS_FLG(FLG_FIRST))
2264 before_str[before_n++] = "全4冊の内の1冊目の";
2268 /*** Second rank spellbooks ***/
2269 if (IS_FLG(FLG_SECOND))
2271 before_str[before_n++] = "全4冊の内の2冊目の";
2275 /*** Third rank spellbooks ***/
2276 if (IS_FLG(FLG_THIRD))
2278 before_str[before_n++] = "全4冊の内の3冊目の";
2282 /*** Fourth rank spellbooks ***/
2283 if (IS_FLG(FLG_FOURTH))
2285 before_str[before_n++] = "全4冊の内の4冊目の";
2290 if (IS_FLG(FLG_ITEMS))
2291 ; /* Nothing to do */
2292 else if (IS_FLG(FLG_WEAPONS))
2294 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2296 else if (IS_FLG(FLG_ARMORS))
2298 else if (IS_FLG(FLG_MISSILES))
2299 body_str = "弾や矢やクロスボウの矢";
2300 else if (IS_FLG(FLG_DEVICES))
2301 body_str = "巻物や魔法棒や杖やロッド";
2302 else if (IS_FLG(FLG_LIGHTS))
2303 body_str = "光源用のアイテム";
2304 else if (IS_FLG(FLG_JUNKS))
2305 body_str = "折れた棒等のガラクタ";
2306 else if (IS_FLG(FLG_CORPSES))
2308 else if (IS_FLG(FLG_SPELLBOOKS))
2310 else if (IS_FLG(FLG_HAFTED))
2312 else if (IS_FLG(FLG_SHIELDS))
2314 else if (IS_FLG(FLG_BOWS))
2315 body_str = "スリングや弓やクロスボウ";
2316 else if (IS_FLG(FLG_RINGS))
2318 else if (IS_FLG(FLG_AMULETS))
2319 body_str = "アミュレット";
2320 else if (IS_FLG(FLG_SUITS))
2322 else if (IS_FLG(FLG_CLOAKS))
2324 else if (IS_FLG(FLG_HELMS))
2325 body_str = "ヘルメットや冠";
2326 else if (IS_FLG(FLG_GLOVES))
2328 else if (IS_FLG(FLG_BOOTS))
2333 strcat(buff, "全ての");
2334 else for (i = 0; i < before_n && before_str[i]; i++)
2335 strcat(buff, before_str[i]);
2337 strcat(buff, body_str);
2347 strcat(buff, "で、名前が「");
2348 strncat(buff, str, 80);
2350 strcat(buff, "」で始まるもの");
2352 strcat(buff, "」を含むもの");
2357 strncat(buff, format("に「%s」", insc), 80);
2359 if (my_strstr(insc, "%%all"))
2360 strcat(buff, "(%%allは全能力を表す英字の記号で置換)");
2361 else if (my_strstr(insc, "%all"))
2362 strcat(buff, "(%allは全能力を表す記号で置換)");
2363 else if (my_strstr(insc, "%%"))
2364 strcat(buff, "(%%は追加能力を表す英字の記号で置換)");
2365 else if (my_strstr(insc, "%"))
2366 strcat(buff, "(%は追加能力を表す記号で置換)");
2368 strcat(buff, "と刻んで");
2373 if (act & DONT_AUTOPICK)
2374 strcat(buff, "放置する。");
2375 else if (act & DO_AUTODESTROY)
2376 strcat(buff, "破壊する。");
2377 else if (act & DO_QUERY_AUTOPICK)
2378 strcat(buff, "確認の後に拾う。");
2380 strcat(buff, "拾う。");
2382 if (act & DO_DISPLAY)
2384 if (act & DONT_AUTOPICK)
2385 strcat(buff, "全体マップ('M')で'N'を押したときに表示する。");
2386 else if (act & DO_AUTODESTROY)
2387 strcat(buff, "全体マップ('M')で'K'を押したときに表示する。");
2389 strcat(buff, "全体マップ('M')で'M'を押したときに表示する。");
2392 strcat(buff, "全体マップには表示しない。");
2396 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2397 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2401 /*** Collecting items ***/
2402 /*** Which can be absorbed into a slot as a bundle ***/
2403 if (IS_FLG(FLG_COLLECTING))
2404 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2406 /*** Unaware items ***/
2407 if (IS_FLG(FLG_UNAWARE))
2409 before_str[before_n++] = "unidentified";
2410 whose_str[whose_n++] = "basic abilities are not known";
2413 /*** Unidentified ***/
2414 if (IS_FLG(FLG_UNIDENTIFIED))
2415 before_str[before_n++] = "unidentified";
2417 /*** Identified ***/
2418 if (IS_FLG(FLG_IDENTIFIED))
2419 before_str[before_n++] = "identified";
2421 /*** *Identified* ***/
2422 if (IS_FLG(FLG_STAR_IDENTIFIED))
2423 before_str[before_n++] = "fully identified";
2425 /*** Rare equipments ***/
2426 if (IS_FLG(FLG_RARE))
2428 before_str[before_n++] = "very rare";
2429 body_str = "equipments";
2430 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2433 /*** Common equipments ***/
2434 if (IS_FLG(FLG_COMMON))
2436 before_str[before_n++] = "relatively common";
2437 body_str = "equipments";
2438 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2441 /*** Worthless items ***/
2442 if (IS_FLG(FLG_WORTHLESS))
2444 before_str[before_n++] = "worthless";
2445 which_str[which_n++] = "can not be sold at stores";
2449 if (IS_FLG(FLG_ARTIFACT))
2451 before_str[before_n++] = "artifact";
2455 if (IS_FLG(FLG_EGO))
2457 before_str[before_n++] = "ego";
2461 if (IS_FLG(FLG_GOOD))
2463 body_str = "equipment";
2464 which_str[which_n++] = "have good quality";
2468 if (IS_FLG(FLG_NAMELESS))
2470 body_str = "equipment";
2471 which_str[which_n++] = "is neither ego-item nor artifact";
2475 if (IS_FLG(FLG_AVERAGE))
2477 body_str = "equipment";
2478 which_str[which_n++] = "have average quality";
2481 /*** Dice boosted (weapon of slaying) ***/
2482 if (IS_FLG(FLG_BOOSTED))
2484 body_str = "weapons";
2485 whose_str[whose_n++] = "damage dice is bigger than normal";
2488 /*** Weapons whose dd*ds is more than nn ***/
2489 if (IS_FLG(FLG_MORE_DICE))
2491 static char more_than_desc_str[] =
2492 "maximum damage from dice is bigger than __";
2493 body_str = "weapons";
2495 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2497 whose_str[whose_n++] = more_than_desc_str;
2500 /*** Items whose magical bonus is more than nn ***/
2501 if (IS_FLG(FLG_MORE_BONUS))
2503 static char more_bonus_desc_str[] =
2504 "magical bonus is bigger than (+__)";
2506 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2507 "%d)", entry->bonus);
2508 whose_str[whose_n++] = more_bonus_desc_str;
2511 /*** Wanted monster's corpse/skeletons ***/
2512 if (IS_FLG(FLG_WANTED))
2514 body_str = "corpse or skeletons";
2515 which_str[which_n++] = "is wanted at the Hunter's Office";
2518 /*** Human corpse/skeletons (for Daemon magic) ***/
2519 if (IS_FLG(FLG_HUMAN))
2521 before_str[before_n++] = "humanoid";
2522 body_str = "corpse or skeletons";
2523 which_str[which_n++] = "can be used for Daemon magic";
2526 /*** Unique monster's corpse/skeletons/statues ***/
2527 if (IS_FLG(FLG_UNIQUE))
2529 before_str[before_n++] = "unique monster's";
2530 body_str = "corpse or skeletons";
2533 /*** Unreadable spellbooks ***/
2534 if (IS_FLG(FLG_UNREADABLE))
2536 body_str = "spellbooks";
2537 after_str[after_n++] = "of different realms from yours";
2540 /*** First realm spellbooks ***/
2541 if (IS_FLG(FLG_REALM1))
2543 body_str = "spellbooks";
2544 after_str[after_n++] = "of your first realm";
2547 /*** Second realm spellbooks ***/
2548 if (IS_FLG(FLG_REALM2))
2550 body_str = "spellbooks";
2551 after_str[after_n++] = "of your second realm";
2554 /*** First rank spellbooks ***/
2555 if (IS_FLG(FLG_FIRST))
2557 before_str[before_n++] = "first one of four";
2558 body_str = "spellbooks";
2561 /*** Second rank spellbooks ***/
2562 if (IS_FLG(FLG_SECOND))
2564 before_str[before_n++] = "second one of four";
2565 body_str = "spellbooks";
2568 /*** Third rank spellbooks ***/
2569 if (IS_FLG(FLG_THIRD))
2571 before_str[before_n++] = "third one of four";
2572 body_str = "spellbooks";
2575 /*** Fourth rank spellbooks ***/
2576 if (IS_FLG(FLG_FOURTH))
2578 before_str[before_n++] = "fourth one of four";
2579 body_str = "spellbooks";
2583 if (IS_FLG(FLG_ITEMS))
2584 ; /* Nothing to do */
2585 else if (IS_FLG(FLG_WEAPONS))
2586 body_str = "weapons";
2587 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2588 body_str = "favorite weapons";
2589 else if (IS_FLG(FLG_ARMORS))
2590 body_str = "armors";
2591 else if (IS_FLG(FLG_MISSILES))
2592 body_str = "shots, arrows or crossbow bolts";
2593 else if (IS_FLG(FLG_DEVICES))
2594 body_str = "scrolls, wands, staves or rods";
2595 else if (IS_FLG(FLG_LIGHTS))
2596 body_str = "light sources";
2597 else if (IS_FLG(FLG_JUNKS))
2598 body_str = "junk such as broken sticks";
2599 else if (IS_FLG(FLG_CORPSES))
2600 body_str = "corpses or skeletons";
2601 else if (IS_FLG(FLG_SPELLBOOKS))
2602 body_str = "spellbooks";
2603 else if (IS_FLG(FLG_HAFTED))
2604 body_str = "hafted weapons";
2605 else if (IS_FLG(FLG_SHIELDS))
2606 body_str = "shields";
2607 else if (IS_FLG(FLG_BOWS))
2608 body_str = "slings, bows or crossbows";
2609 else if (IS_FLG(FLG_RINGS))
2611 else if (IS_FLG(FLG_AMULETS))
2612 body_str = "amulets";
2613 else if (IS_FLG(FLG_SUITS))
2614 body_str = "body armors";
2615 else if (IS_FLG(FLG_CLOAKS))
2616 body_str = "cloaks";
2617 else if (IS_FLG(FLG_HELMS))
2618 body_str = "helms or crowns";
2619 else if (IS_FLG(FLG_GLOVES))
2620 body_str = "gloves";
2621 else if (IS_FLG(FLG_BOOTS))
2624 /* Prepare a string for item name */
2631 whose_str[whose_n++] = "name is beginning with \"";
2634 which_str[which_n++] = "have \"";
2638 /* Describe action flag */
2639 if (act & DONT_AUTOPICK)
2640 strcpy(buff, "Leave on floor ");
2641 else if (act & DO_AUTODESTROY)
2642 strcpy(buff, "Destroy ");
2643 else if (act & DO_QUERY_AUTOPICK)
2644 strcpy(buff, "Ask to pick up ");
2646 strcpy(buff, "Pickup ");
2648 /* Auto-insctiption */
2651 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2653 if (my_strstr(insc, "%all"))
2654 strcat(buff, ", replacing %all with code string representing all abilities,");
2655 else if (my_strstr(insc, "%"))
2656 strcat(buff, ", replacing % with code string representing extra random abilities,");
2658 strcat(buff, " on ");
2663 strcat(buff, "all ");
2664 else for (i = 0; i < before_n && before_str[i]; i++)
2666 strcat(buff, before_str[i]);
2671 strcat(buff, body_str);
2674 for (i = 0; i < after_n && after_str[i]; i++)
2677 strcat(buff, after_str[i]);
2681 for (i = 0; i < whose_n && whose_str[i]; i++)
2684 strcat(buff, " whose ");
2686 strcat(buff, ", and ");
2688 strcat(buff, whose_str[i]);
2691 /* Item name ; whose name is beginning with "str" */
2698 /* whose ..., and which .... */
2699 if (whose_n && which_n)
2700 strcat(buff, ", and ");
2703 for (i = 0; i < which_n && which_str[i]; i++)
2706 strcat(buff, " which ");
2708 strcat(buff, ", and ");
2710 strcat(buff, which_str[i]);
2713 /* Item name ; which have "str" as part of its name */
2716 strncat(buff, str, 80);
2717 strcat(buff, "\" as part of its name");
2721 /* Describe whether it will be displayed on the full map or not */
2722 if (act & DO_DISPLAY)
2724 if (act & DONT_AUTOPICK)
2725 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2726 else if (act & DO_AUTODESTROY)
2727 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2729 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2732 strcat(buff, " Not displayed in the full map.");
2739 * Read whole lines of a file to memory
2741 static cptr *read_text_lines(cptr filename)
2743 cptr *lines_list = NULL;
2749 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2752 fff = my_fopen(buf, "r");
2756 /* Allocate list of pointers */
2757 C_MAKE(lines_list, MAX_LINES, cptr);
2760 while (0 == my_fgets(fff, buf, sizeof(buf)))
2762 lines_list[lines++] = string_make(buf);
2763 if (lines >= MAX_LINES - 1) break;
2766 lines_list[0] = string_make("");
2771 if (!fff) return NULL;
2777 * Copy the default autopick file to the user directory
2779 static void prepare_default_pickpref(void)
2781 const cptr messages[] = {
2782 _("あなたは「自動拾いエディタ」を初めて起動しました。", "You have activated the Auto-Picker Editor for the first time."),
2783 _("自動拾いのユーザー設定ファイルがまだ書かれていないので、", "Since user pref file for autopick is not yet created,"),
2784 _("基本的な自動拾い設定ファイルをlib/pref/picktype.prfからコピーします。", "the default setting is loaded from lib/pref/pickpref.prf ."),
2792 cptr filename = pickpref_filename(PT_DEFAULT);
2794 /* Display messages */
2795 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2800 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2801 user_fp = my_fopen(buf, "w");
2804 if (!user_fp) return;
2806 /* Write header messages for a notification */
2807 fprintf(user_fp, "#***\n");
2808 for (i = 0; messages[i]; i++)
2810 fprintf(user_fp, "#*** %s\n", messages[i]);
2812 fprintf(user_fp, "#***\n\n\n");
2815 /* Open the default file */
2816 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2817 pref_fp = my_fopen(buf, "r");
2826 /* Copy the contents of default file */
2827 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2828 fprintf(user_fp, "%s\n", buf);
2835 * Read an autopick prefence file to memory
2836 * Prepare default if no user file is found
2838 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2843 /* Try a filename with player name */
2844 *filename_mode_p = PT_WITH_PNAME;
2845 strcpy(buf, pickpref_filename(*filename_mode_p));
2846 lines_list = read_text_lines(buf);
2850 /* Use default name */
2851 *filename_mode_p = PT_DEFAULT;
2852 strcpy(buf, pickpref_filename(*filename_mode_p));
2853 lines_list = read_text_lines(buf);
2858 /* There is no preference file in the user directory */
2860 /* Copy the default autopick file to the user directory */
2861 prepare_default_pickpref();
2863 /* Use default name again */
2864 lines_list = read_text_lines(buf);
2869 /* Allocate list of pointers */
2870 C_MAKE(lines_list, MAX_LINES, cptr);
2871 lines_list[0] = string_make("");
2878 * Write whole lines of memory to a file.
2880 static bool write_text_lines(cptr filename, cptr *lines_list)
2887 /* Build the filename */
2888 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2891 fff = my_fopen(buf, "w");
2894 for (lines = 0; lines_list[lines]; lines++)
2895 my_fputs(fff, lines_list[lines], 1024);
2900 if (!fff) return FALSE;
2906 * Free memory of lines_list.
2908 static void free_text_lines(cptr *lines_list)
2912 for (lines = 0; lines_list[lines]; lines++)
2913 string_free(lines_list[lines]);
2915 /* free list of pointers */
2916 C_KILL(lines_list, MAX_LINES, cptr);
2921 * Delete or insert string
2923 static void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
2929 /* Some lines are selected */
2932 by1 = MIN(tb->my, tb->cy);
2933 by2 = MAX(tb->my, tb->cy);
2936 /* No mark -- Select current line */
2937 else /* if (!tb->mark) */
2943 /* Set/Reset flag of each line */
2944 for (y = by1; y <= by2; y++)
2946 autopick_type an_entry, *entry = &an_entry;
2948 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2950 string_free(tb->lines_list[y]);
2954 /* Add? or Remove? */
2955 if (!IS_FLG(flg)) add = TRUE;
2958 /* No more change */
2962 /* You can use only one noun flag */
2963 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2966 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2970 /* You can use only one identify state flag */
2971 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2974 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2978 /* You can use only one flag in artifact/ego/nameless */
2979 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
2982 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
2986 /* You can use only one flag in rare/common */
2987 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
2990 for (i = FLG_RARE; i <= FLG_COMMON; i++)
2994 if (add) ADD_FLG(flg);
2997 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3000 tb->dirty_flags |= DIRTY_ALL;
3002 /* Text is changed */
3009 * Change command letter
3011 static void toggle_command_letter(text_body_type *tb, byte flg)
3013 autopick_type an_entry, *entry = &an_entry;
3018 /* Some lines are selected */
3021 by1 = MIN(tb->my, tb->cy);
3022 by2 = MAX(tb->my, tb->cy);
3025 /* No mark -- Select current line */
3026 else /* if (!tb->mark) */
3032 /* Set/Reset flag of each line */
3033 for (y = by1; y <= by2; y++)
3037 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3039 string_free(tb->lines_list[y]);
3043 /* Add? or Remove? */
3044 if (!(entry->action & flg)) add = TRUE;
3047 /* No more change */
3051 /* Count number of letter (by negative number) */
3052 if (entry->action & DONT_AUTOPICK) wid--;
3053 else if (entry->action & DO_AUTODESTROY) wid--;
3054 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3055 if (!(entry->action & DO_DISPLAY)) wid--;
3057 /* Set/Reset the flag */
3058 if (flg != DO_DISPLAY)
3060 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3061 if (add) entry->action |= flg;
3062 else entry->action |= DO_AUTOPICK;
3066 entry->action &= ~(DO_DISPLAY);
3067 if (add) entry->action |= flg;
3070 /* Correct cursor location */
3073 if (entry->action & DONT_AUTOPICK) wid++;
3074 else if (entry->action & DO_AUTODESTROY) wid++;
3075 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3076 if (!(entry->action & DO_DISPLAY)) wid++;
3078 if (wid > 0) tb->cx++;
3079 if (wid < 0 && tb->cx > 0) tb->cx--;
3082 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3085 tb->dirty_flags |= DIRTY_ALL;
3087 /* Text is changed */
3093 * Delete or insert string
3095 static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
3099 /* Some lines are selected */
3102 by1 = MIN(tb->my, tb->cy);
3103 by2 = MAX(tb->my, tb->cy);
3106 /* No mark -- Select current line */
3107 else /* if (!tb->mark) */
3113 /* Set/Reset flag of each line */
3114 for (y = by1; y <= by2; y++)
3116 autopick_type an_entry, *entry = &an_entry;
3118 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3120 /* There is the flag already */
3123 /* Free memory for the entry */
3124 autopick_free_entry(entry);
3129 string_free(tb->lines_list[y]);
3131 /* Remove all noun flag */
3132 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3135 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3141 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3144 tb->dirty_flags |= DIRTY_ALL;
3146 /* Text is changed */
3153 * Check if this line is expression or not.
3154 * And update it if it is.
3156 static void check_expression_line(text_body_type *tb, int y)
3158 cptr s = tb->lines_list[y];
3160 if ((s[0] == '?' && s[1] == ':') ||
3161 (tb->states[y] & LSTAT_BYPASS))
3163 /* Expressions need re-evaluation */
3164 tb->dirty_flags |= DIRTY_EXPRESSION;
3170 * Add an empty line at the last of the file
3172 static bool add_empty_line(text_body_type *tb)
3176 for (k = 0; tb->lines_list[k]; k++)
3177 /* count number of lines */ ;
3179 /* Too many lines! */
3180 if (k >= MAX_LINES - 2) return FALSE;
3182 /* The last line is already empty */
3183 if (!tb->lines_list[k-1][0]) return FALSE;
3185 /* Create new empty line */
3186 tb->lines_list[k] = string_make("");
3188 /* Expressions need re-evaluation */
3189 tb->dirty_flags |= DIRTY_EXPRESSION;
3191 /* Text is changed */
3194 /* A line is added */
3200 * Insert return code and split the line
3202 static bool insert_return_code(text_body_type *tb)
3204 char buf[MAX_LINELEN];
3207 for (k = 0; tb->lines_list[k]; k++)
3208 /* count number of lines */ ;
3210 if (k >= MAX_LINES - 2) return FALSE;
3213 /* Move down lines */
3214 for (; tb->cy < k; k--)
3216 tb->lines_list[k+1] = tb->lines_list[k];
3217 tb->states[k+1] = tb->states[k];
3220 /* Split current line */
3221 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3224 if (iskanji(tb->lines_list[tb->cy][i]))
3225 buf[j++] = tb->lines_list[tb->cy][i++];
3227 buf[j++] = tb->lines_list[tb->cy][i];
3230 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3231 string_free(tb->lines_list[tb->cy]);
3232 tb->lines_list[tb->cy] = string_make(buf);
3234 /* Expressions need re-evaluation */
3235 tb->dirty_flags |= DIRTY_EXPRESSION;
3237 /* Text is changed */
3245 * Choose an item and get auto-picker entry from it.
3247 static object_type *choose_object(cptr q, cptr s)
3251 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3253 /* Get the item (in the pack) */
3254 if (item >= 0) return &inventory[item];
3256 /* Get the item (on the floor) */
3257 else return &o_list[0 - item];
3262 * Choose an item and get auto-picker entry from it.
3264 static bool entry_from_choosed_object(autopick_type *entry)
3271 q = "どのアイテムを登録しますか? ";
3274 q = "Enter which item? ";
3275 s = "You have nothing to enter.";
3277 o_ptr = choose_object(q, s);
3278 if (!o_ptr) return FALSE;
3280 autopick_entry_from_object(entry, o_ptr);
3286 * Choose an item for search
3288 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3290 char buf[MAX_NLEN+20];
3296 q = "どのアイテムを検索しますか? ";
3299 q = "Enter which item? ";
3300 s = "You have nothing to enter.";
3302 o_ptr = choose_object(q, s);
3303 if (!o_ptr) return 0;
3307 string_free(*search_strp);
3308 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3309 *search_strp = string_make(format("<%s>", buf));
3315 * Prepare for search by destroyed object
3317 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3319 char buf[MAX_NLEN+20];
3321 if (!autopick_last_destroyed_object.k_idx) return 0;
3323 *o_handle = &autopick_last_destroyed_object;
3325 string_free(*search_strp);
3326 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3327 *search_strp = string_make(format("<%s>", buf));
3333 * Choose an item or string for search
3335 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3341 * TERM_YELLOW : Overwrite mode
3342 * TERM_WHITE : Insert mode
3344 byte color = TERM_YELLOW;
3345 char buf[MAX_NLEN+20];
3348 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
3349 int col = sizeof(prompt) - 1;
3351 /* Prepare string buffer for edit */
3352 if (*search_strp) strcpy(buf, *search_strp);
3355 /* Object searching mode */
3358 color = TERM_L_GREEN;
3361 /* Display prompt */
3371 /* Display the string */
3372 Term_erase(col, 0, 255);
3373 Term_putstr(col, 0, -1, color, buf);
3376 Term_gotoxy(col + pos, 0);
3378 /* Get a special key code */
3379 skey = inkey_special(TRUE);
3381 /* Analyze the key */
3389 /* Now on insert mode */
3392 /* No move at beginning of line */
3393 if (0 == pos) break;
3397 int next_pos = i + 1;
3400 if (iskanji(buf[i])) next_pos++;
3403 /* Is there the cursor at next position? */
3404 if (next_pos >= pos) break;
3410 /* Get previous position */
3418 /* Now on insert mode */
3421 /* No move at end of line */
3422 if ('\0' == buf[pos]) break;
3426 if (iskanji(buf[pos])) pos += 2;
3444 if (*o_handle) return (back ? -1 : 1);
3445 string_free(*search_strp);
3446 *search_strp = string_make(buf);
3448 return (back ? -1 : 1);
3452 return get_object_for_search(o_handle, search_strp);
3455 /* Prepare string for destroyed object if there is one. */
3456 if (get_destroyed_object_for_search(o_handle, search_strp))
3466 /* Now on insert mode */
3469 /* No move at beginning of line */
3470 if (0 == pos) break;
3474 int next_pos = i + 1;
3477 if (iskanji(buf[i])) next_pos++;
3480 /* Is there the cursor at next position? */
3481 if (next_pos >= pos) break;
3487 /* Get previous position */
3490 /* Fall through to 'Delete key' */
3499 /* Now on insert mode */
3502 /* No move at end of line */
3503 if ('\0' == buf[pos]) break;
3505 /* Position of next character */
3509 /* Next character is one more byte away */
3510 if (iskanji(buf[pos])) src++;
3515 /* Move characters at src to dst */
3516 while ('\0' != (buf[dst++] = buf[src++]))
3524 /* Insert a character */
3529 /* Ignore special keys */
3530 if (skey & SKEY_MASK) break;
3532 /* Get a character code */
3535 /* Was non insert mode? */
3536 if (color != TERM_WHITE)
3538 /* Was object searching mode */
3539 if (color == TERM_L_GREEN)
3541 /* Cancel the mode */
3544 /* Remove indicating string */
3545 string_free(*search_strp);
3546 *search_strp = NULL;
3549 /* Overwrite default string */
3552 /* Go to insert mode */
3556 /* Save right part of string */
3557 strcpy(tmp, buf + pos);
3563 /* Bypass macro processing */
3581 if (pos < len && (isprint(c) || iskana(c)))
3583 if (pos < len && isprint(c))
3597 /* Write back the left part of string */
3598 my_strcat(buf, tmp, len + 1);
3605 /* Object searching mode was cancelled? */
3606 if (*o_handle && color != TERM_L_GREEN)
3608 /* Cancel the mode */
3611 /* Remove indicating string */
3613 string_free(*search_strp);
3614 *search_strp = NULL;
3619 } /* while (TRUE) */
3624 * Search next line matches for o_ptr
3626 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3628 autopick_type an_entry, *entry = &an_entry;
3629 char o_name[MAX_NLEN];
3630 int bypassed_cy = -1;
3632 /* Start searching from current cursor position */
3635 /* Prepare object name string first */
3636 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3638 /* Convert the string to lower case */
3639 str_tolower(o_name);
3648 if (!tb->lines_list[++i]) break;
3655 /* Is this line is a correct entry? */
3656 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3658 /* Does this line match to the object? */
3659 match = is_autopick_aux(o_ptr, entry, o_name);
3660 autopick_free_entry(entry);
3661 if (!match) continue;
3663 /* Found a line but it's inactive */
3664 if (tb->states[i] & LSTAT_BYPASS)
3666 /* If it is first found, remember it */
3667 if (bypassed_cy == -1) bypassed_cy = i;
3670 /* Found an active line! */
3673 /* Move to this line */
3677 if (bypassed_cy != -1)
3679 /* Mark as some lines are skipped */
3680 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3688 if (bypassed_cy != -1)
3690 /* Move to the remembered line */
3692 tb->cy = bypassed_cy;
3694 /* Mark as this line is inactive */
3695 tb->dirty_flags |= DIRTY_INACTIVE;
3700 /* Mark as NOT FOUND */
3701 tb->dirty_flags |= DIRTY_NOT_FOUND;
3709 * Search next line matches to the string
3711 static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
3713 int bypassed_cy = -1;
3714 int bypassed_cx = 0;
3716 /* Start searching from current cursor position */
3726 if (!tb->lines_list[++i]) break;
3733 /* Look for the string pattern */
3734 pos = my_strstr(tb->lines_list[i], search_str);
3739 /* Found a line but it's inactive */
3740 if ((tb->states[i] & LSTAT_BYPASS) &&
3741 !(tb->states[i] & LSTAT_EXPRESSION))
3743 /* If it is first found, remember it */
3744 if (bypassed_cy == -1)
3747 bypassed_cx = (int)(pos - tb->lines_list[i]);
3751 /* Found an active line! */
3754 /* Move to this location */
3755 tb->cx = (int)(pos - tb->lines_list[i]);
3758 if (bypassed_cy != -1)
3760 /* Mark as some lines are skipped */
3761 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3769 if (bypassed_cy != -1)
3771 /* Move to the remembered line */
3772 tb->cx = bypassed_cx;
3773 tb->cy = bypassed_cy;
3775 /* Mark as this line is inactive */
3776 tb->dirty_flags |= DIRTY_INACTIVE;
3781 /* Mark as NOT FOUND */
3782 tb->dirty_flags |= DIRTY_NOT_FOUND;
3792 * Editor command id's
3795 #define EC_SAVEQUIT 2
3806 #define EC_PGDOWN 13
3808 #define EC_BOTTOM 15
3813 #define EC_KILL_LINE 20
3814 #define EC_DELETE_CHAR 21
3815 #define EC_BACKSPACE 22
3816 #define EC_SEARCH_STR 23
3817 #define EC_SEARCH_FORW 24
3818 #define EC_SEARCH_BACK 25
3819 #define EC_SEARCH_OBJ 26
3820 #define EC_SEARCH_DESTROYED 27
3821 #define EC_INSERT_OBJECT 28
3822 #define EC_INSERT_DESTROYED 29
3823 #define EC_INSERT_BLOCK 30
3824 #define EC_INSERT_MACRO 31
3825 #define EC_INSERT_KEYMAP 32
3826 #define EC_CL_AUTOPICK 33
3827 #define EC_CL_DESTROY 34
3828 #define EC_CL_LEAVE 35
3829 #define EC_CL_QUERY 36
3830 #define EC_CL_NO_DISP 37
3831 #define EC_OK_COLLECTING 38
3832 #define EC_IK_UNAWARE 39
3833 #define EC_IK_UNIDENTIFIED 40
3834 #define EC_IK_IDENTIFIED 41
3835 #define EC_IK_STAR_IDENTIFIED 42
3836 #define EC_OK_BOOSTED 43
3837 #define EC_OK_MORE_DICE 44
3838 #define EC_OK_MORE_BONUS 45
3839 #define EC_OK_WORTHLESS 46
3840 #define EC_OK_ARTIFACT 47
3841 #define EC_OK_EGO 48
3842 #define EC_OK_GOOD 49
3843 #define EC_OK_NAMELESS 50
3844 #define EC_OK_AVERAGE 51
3845 #define EC_OK_RARE 52
3846 #define EC_OK_COMMON 53
3847 #define EC_OK_WANTED 54
3848 #define EC_OK_UNIQUE 55
3849 #define EC_OK_HUMAN 56
3850 #define EC_OK_UNREADABLE 57
3851 #define EC_OK_REALM1 58
3852 #define EC_OK_REALM2 59
3853 #define EC_OK_FIRST 60
3854 #define EC_OK_SECOND 61
3855 #define EC_OK_THIRD 62
3856 #define EC_OK_FOURTH 63
3857 #define EC_KK_WEAPONS 64
3858 #define EC_KK_FAVORITE_WEAPONS 65
3859 #define EC_KK_ARMORS 66
3860 #define EC_KK_MISSILES 67
3861 #define EC_KK_DEVICES 68
3862 #define EC_KK_LIGHTS 69
3863 #define EC_KK_JUNKS 70
3864 #define EC_KK_CORPSES 71
3865 #define EC_KK_SPELLBOOKS 72
3866 #define EC_KK_SHIELDS 73
3867 #define EC_KK_BOWS 74
3868 #define EC_KK_RINGS 75
3869 #define EC_KK_AMULETS 76
3870 #define EC_KK_SUITS 77
3871 #define EC_KK_CLOAKS 78
3872 #define EC_KK_HELMS 79
3873 #define EC_KK_GLOVES 80
3874 #define EC_KK_BOOTS 81
3880 static char MN_QUIT[] = "セーブ無しで終了";
3881 static char MN_SAVEQUIT[] = "セーブして終了";
3882 static char MN_REVERT[] = "全ての変更を破棄";
3883 static char MN_HELP[] = "ヘルプ";
3885 static char MN_MOVE[] = "カーソル移動";
3886 static char MN_LEFT[] = "左 (←矢印キー)";
3887 static char MN_DOWN[] = "下 (↓矢印キー)";
3888 static char MN_UP[] = "上 (↑矢印キー)";
3889 static char MN_RIGHT[] = "右 (→矢印キー)";
3890 static char MN_BOL[] = "行の先頭";
3891 static char MN_EOL[] = "行の終端";
3892 static char MN_PGUP[] = "上のページ (PageUpキー)";
3893 static char MN_PGDOWN[] = "下のページ (PageDownキー)";
3894 static char MN_TOP[] = "1行目へ移動 (Homeキー)";
3895 static char MN_BOTTOM[] = "最下行へ移動(Endキー)";
3897 static char MN_EDIT[] = "編集";
3898 static char MN_CUT[] = "カット";
3899 static char MN_COPY[] = "コピー";
3900 static char MN_PASTE[] = "ペースト";
3901 static char MN_BLOCK[] = "選択範囲の指定";
3902 static char MN_KILL_LINE[] = "行の残りを削除";
3903 static char MN_DELETE_CHAR[] = "1文字削除";
3904 static char MN_BACKSPACE[] = "バックスペース";
3905 static char MN_RETURN[] = "改行";
3907 static char MN_SEARCH[] = "検索";
3908 static char MN_SEARCH_STR[] = "文字列で検索";
3909 static char MN_SEARCH_FORW[] = "前方へ再検索";
3910 static char MN_SEARCH_BACK[] = "後方へ再検索";
3911 static char MN_SEARCH_OBJ[] = "アイテムを選択して検索";
3912 static char MN_SEARCH_DESTROYED[] = "自動破壊されたアイテムで検索";
3914 static char MN_INSERT[] = "色々挿入";
3915 static char MN_INSERT_OBJECT[] = "選択したアイテムの名前を挿入";
3916 static char MN_INSERT_DESTROYED[] = "自動破壊されたアイテムの名前を挿入";
3917 static char MN_INSERT_BLOCK[] = "条件分岐ブロックの例を挿入";
3918 static char MN_INSERT_MACRO[] = "マクロ定義を挿入";
3919 static char MN_INSERT_KEYMAP[] = "キーマップ定義を挿入";
3921 static char MN_COMMAND_LETTER[] = "拾い/破壊/放置の選択";
3922 static char MN_CL_AUTOPICK[] = "「 」 (自動拾い)";
3923 static char MN_CL_DESTROY[] = "「!」 (自動破壊)";
3924 static char MN_CL_LEAVE[] = "「~」 (放置)";
3925 static char MN_CL_QUERY[] = "「;」 (確認して拾う)";
3926 static char MN_CL_NO_DISP[] = "「(」 (マップコマンドで表示しない)";
3928 static char MN_ADJECTIVE_GEN[] = "形容詞(一般)の選択";
3929 static char MN_RARE[] = "レアな (装備)";
3930 static char MN_COMMON[] = "ありふれた (装備)";
3932 static char MN_ADJECTIVE_SPECIAL[] = "形容詞(特殊)の選択";
3933 static char MN_BOOSTED[] = "ダイス目の違う (武器)";
3934 static char MN_MORE_DICE[] = "ダイス目 # 以上の (武器)";
3935 static char MN_MORE_BONUS[] = "修正値 # 以上の (指輪等)";
3936 static char MN_WANTED[] = "賞金首の (死体)";
3937 static char MN_UNIQUE[] = "ユニーク・モンスターの (死体)";
3938 static char MN_HUMAN[] = "人間の (死体)";
3939 static char MN_UNREADABLE[] = "読めない (魔法書)";
3940 static char MN_REALM1[] = "第一領域の (魔法書)";
3941 static char MN_REALM2[] = "第二領域の (魔法書)";
3942 static char MN_FIRST[] = "1冊目の (魔法書)";
3943 static char MN_SECOND[] = "2冊目の (魔法書)";
3944 static char MN_THIRD[] = "3冊目の (魔法書)";
3945 static char MN_FOURTH[] = "4冊目の (魔法書)";
3947 static char MN_NOUN[] = "名詞の選択";
3951 static char MN_QUIT[] = "Quit without save";
3952 static char MN_SAVEQUIT[] = "Save & Quit";
3953 static char MN_REVERT[] = "Revert all changes";
3954 static char MN_HELP[] = "Help";
3956 static char MN_MOVE[] = "Move cursor";
3957 static char MN_LEFT[] = "Left (Left Arrow key)";
3958 static char MN_DOWN[] = "Down (Down Arrow key)";
3959 static char MN_UP[] = "Up (Up Arrow key)";
3960 static char MN_RIGHT[] = "Right (Right Arrow key)";
3961 static char MN_BOL[] = "Beggining of line";
3962 static char MN_EOL[] = "End of line";
3963 static char MN_PGUP[] = "Page up (PageUp key)";
3964 static char MN_PGDOWN[] = "Page down(PageDown key)";
3965 static char MN_TOP[] = "Top (Home key)";
3966 static char MN_BOTTOM[] = "Bottom (End key)";
3968 static char MN_EDIT[] = "Edit";
3969 static char MN_CUT[] = "Cut";
3970 static char MN_COPY[] = "Copy";
3971 static char MN_PASTE[] = "Paste";
3972 static char MN_BLOCK[] = "Select block";
3973 static char MN_KILL_LINE[] = "Kill rest of line";
3974 static char MN_DELETE_CHAR[] = "Delete character";
3975 static char MN_BACKSPACE[] = "Backspace";
3976 static char MN_RETURN[] = "Return";
3978 static char MN_SEARCH[] = "Search";
3979 static char MN_SEARCH_STR[] = "Search by string";
3980 static char MN_SEARCH_FORW[] = "Search forward";
3981 static char MN_SEARCH_BACK[] = "Search backward";
3982 static char MN_SEARCH_OBJ[] = "Search by inventory object";
3983 static char MN_SEARCH_DESTROYED[] = "Search by destroyed object";
3985 static char MN_INSERT[] = "Insert...";
3986 static char MN_INSERT_OBJECT[] = "Insert name of choosen object";
3987 static char MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
3988 static char MN_INSERT_BLOCK[] = "Insert conditional block";
3989 static char MN_INSERT_MACRO[] = "Insert a macro definition";
3990 static char MN_INSERT_KEYMAP[] = "Insert a keymap definition";
3992 static char MN_COMMAND_LETTER[] = "Command letter";
3993 static char MN_CL_AUTOPICK[] = "' ' (Auto pick)";
3994 static char MN_CL_DESTROY[] = "'!' (Auto destroy)";
3995 static char MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
3996 static char MN_CL_QUERY[] = "';' (Query to pick up)";
3997 static char MN_CL_NO_DISP[] = "'(' (No display on the large map)";
3999 static char MN_ADJECTIVE_GEN[] = "Adjective (general)";
4000 static char MN_RARE[] = "rare (equipments)";
4001 static char MN_COMMON[] = "common (equipments)";
4003 static char MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
4004 static char MN_BOOSTED[] = "dice boosted (weapons)";
4005 static char MN_MORE_DICE[] = "more than # dice (weapons)";
4006 static char MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
4007 static char MN_WANTED[] = "wanted (corpse)";
4008 static char MN_UNIQUE[] = "unique (corpse)";
4009 static char MN_HUMAN[] = "human (corpse)";
4010 static char MN_UNREADABLE[] = "unreadable (spellbooks)";
4011 static char MN_REALM1[] = "realm1 (spellbooks)";
4012 static char MN_REALM2[] = "realm2 (spellbooks)";
4013 static char MN_FIRST[] = "first (spellbooks)";
4014 static char MN_SECOND[] = "second (spellbooks)";
4015 static char MN_THIRD[] = "third (spellbooks)";
4016 static char MN_FOURTH[] = "fourth (spellbooks)";
4018 static char MN_NOUN[] = "Keywords (noun)";
4028 } command_menu_type;
4031 command_menu_type menu_data[] =
4033 {MN_HELP, 0, -1, EC_HELP},
4034 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4035 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4036 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4038 {MN_EDIT, 0, -1, -1},
4039 {MN_CUT, 1, KTRL('x'), EC_CUT},
4040 {MN_COPY, 1, KTRL('c'), EC_COPY},
4041 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4042 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4043 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4044 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4045 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4046 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4047 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4049 {MN_SEARCH, 0, -1, -1},
4050 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4051 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4052 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4053 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4054 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4056 {MN_MOVE, 0, -1, -1},
4057 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4058 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4059 {MN_UP, 1, KTRL('p'), EC_UP},
4060 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4061 {MN_BOL, 1, KTRL('a'), EC_BOL},
4062 {MN_EOL, 1, KTRL('e'), EC_EOL},
4063 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4064 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4065 {MN_TOP, 1, KTRL('t'), EC_TOP},
4066 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4068 {MN_INSERT, 0, -1, -1},
4069 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4070 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4071 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4072 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4073 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4075 {MN_ADJECTIVE_GEN, 0, -1, -1},
4076 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4077 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4078 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4079 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4080 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4081 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4082 {KEY_EGO, 1, -1, EC_OK_EGO},
4083 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4084 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4085 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4086 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4087 {MN_RARE, 1, -1, EC_OK_RARE},
4088 {MN_COMMON, 1, -1, EC_OK_COMMON},
4090 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4091 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4092 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4093 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4094 {MN_WANTED, 1, -1, EC_OK_WANTED},
4095 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4096 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4097 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4098 {MN_REALM1, 1, -1, EC_OK_REALM1},
4099 {MN_REALM2, 1, -1, EC_OK_REALM2},
4100 {MN_FIRST, 1, -1, EC_OK_FIRST},
4101 {MN_SECOND, 1, -1, EC_OK_SECOND},
4102 {MN_THIRD, 1, -1, EC_OK_THIRD},
4103 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4105 {MN_NOUN, 0, -1, -1},
4106 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4107 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4108 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4109 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4110 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4111 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4112 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4113 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4114 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4115 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4116 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4117 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4118 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4119 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4120 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4121 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4122 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4123 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4125 {MN_COMMAND_LETTER, 0, -1, -1},
4126 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4127 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4128 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4129 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4130 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4132 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4139 * Find a command by 'key'.
4141 static int get_com_id(char key)
4145 for (i = 0; menu_data[i].name; i++)
4147 if (menu_data[i].key == key)
4149 return menu_data[i].com_id;
4158 * Display the menu, and get a command
4160 static int do_command_menu(int level, int start)
4165 int col0 = 5 + level*7;
4166 int row0 = 1 + level*3;
4168 int menu_id_list[26];
4170 char linestr[MAX_LINELEN];
4172 /* Get max length */
4174 for (i = start; menu_data[i].level >= level; i++)
4178 /* Ignore lower level sub menus */
4179 if (menu_data[i].level > level) continue;
4181 len = strlen(menu_data[i].name);
4182 if (len > max_len) max_len = len;
4184 menu_id_list[menu_key] = i;
4188 while (menu_key < 26)
4190 menu_id_list[menu_key] = -1;
4194 /* Extra space for displaying menu key and command key */
4195 max_menu_wid = max_len + 3 + 3;
4197 /* Prepare box line */
4199 strcat(linestr, "+");
4200 for (i = 0; i < max_menu_wid + 2; i++)
4202 strcat(linestr, "-");
4204 strcat(linestr, "+");
4214 int row1 = row0 + 1;
4217 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4219 /* Draw menu items */
4221 for (i = start; menu_data[i].level >= level; i++)
4223 char com_key_str[3];
4226 /* Ignore lower level sub menus */
4227 if (menu_data[i].level > level) continue;
4229 if (menu_data[i].com_id == -1)
4231 strcpy(com_key_str, _("▼", ">"));
4233 else if (menu_data[i].key != -1)
4235 com_key_str[0] = '^';
4236 com_key_str[1] = menu_data[i].key + '@';
4237 com_key_str[2] = '\0';
4241 com_key_str[0] = '\0';
4244 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4246 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4251 /* Draw bottom line */
4252 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4254 /* The menu was shown */
4257 prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
4260 if (key == ESCAPE) return 0;
4262 if ('a' <= key && key <= 'z')
4264 menu_id = menu_id_list[key - 'a'];
4268 com_id = menu_data[menu_id].com_id;
4272 com_id = do_command_menu(level + 1, menu_id + 1);
4274 if (com_id) return com_id;
4286 com_id = get_com_id(key);
4287 if (com_id) return com_id;
4294 static chain_str_type *new_chain_str(cptr str)
4296 chain_str_type *chain;
4298 size_t len = strlen(str);
4300 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4302 strcpy(chain->s, str);
4309 static void kill_yank_chain(text_body_type *tb)
4311 chain_str_type *chain = tb->yank;
4313 tb->yank_eol = TRUE;
4317 chain_str_type *next = chain->next;
4318 size_t len = strlen(chain->s);
4320 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4327 static void add_str_to_yank(text_body_type *tb, cptr str)
4329 chain_str_type *chain;
4331 tb->yank_eol = FALSE;
4333 if (NULL == tb->yank)
4335 tb->yank = new_chain_str(str);
4345 chain->next = new_chain_str(str);
4350 chain = chain->next;
4356 * Do work for the copy editor-command
4358 static void copy_text_to_yank(text_body_type *tb)
4360 int len = strlen(tb->lines_list[tb->cy]);
4362 /* Correct cursor location */
4363 if (tb->cx > len) tb->cx = len;
4365 /* Use single line? */
4368 /* Select a single line */
4374 /* Kill old yank buffer */
4375 kill_yank_chain(tb);
4378 /* Single line case */
4379 if (tb->my == tb->cy)
4382 char buf[MAX_LINELEN];
4383 int bx1 = MIN(tb->mx, tb->cx);
4384 int bx2 = MAX(tb->mx, tb->cx);
4386 /* Correct fake cursor position */
4387 if (bx2 > len) bx2 = len;
4389 /* Whole part of this line is selected */
4390 if (bx1 == 0 && bx2 == len)
4392 /* Copy this line */
4393 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4395 /* Add end of line to the buffer */
4396 add_str_to_yank(tb, "");
4399 /* Segment of this line is selected */
4402 for (i = 0; i < bx2 - bx1; i++)
4404 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4408 /* Copy this segment of line */
4409 add_str_to_yank(tb, buf);
4413 /* Multiple lines case */
4414 else /* if (tb->my != tb->cy) */
4418 int by1 = MIN(tb->my, tb->cy);
4419 int by2 = MAX(tb->my, tb->cy);
4422 for (y = by1; y <= by2; y++)
4424 /* Copy this line */
4425 add_str_to_yank(tb, tb->lines_list[y]);
4428 /* Add final end of line to the buffer */
4429 add_str_to_yank(tb, "");
4432 /* Disable selection */
4436 tb->dirty_flags |= DIRTY_ALL;
4440 #define DESCRIPT_HGT 3
4445 static void draw_text_editor(text_body_type *tb)
4448 int by1 = 0, by2 = 0;
4451 Term_get_size(&tb->wid, &tb->hgt);
4454 * Top line (-1), description line (-3), separator (-1)
4457 tb->hgt -= 2 + DESCRIPT_HGT;
4460 /* Don't let cursor at second byte of kanji */
4461 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4462 if (iskanji(tb->lines_list[tb->cy][i]))
4468 * Move to a correct position in the
4471 if (i & 1) tb->cx--;
4478 /* Scroll if necessary */
4479 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4480 tb->upper = tb->cy - (tb->hgt)/2;
4483 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4484 tb->left = tb->cx - (tb->wid)*2/3;
4488 /* Redraw whole window after resize */
4489 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4490 tb->dirty_flags |= DIRTY_SCREEN;
4492 /* Redraw all text after scroll */
4493 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4494 tb->dirty_flags |= DIRTY_ALL;
4497 if (tb->dirty_flags & DIRTY_SCREEN)
4499 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4505 /* Redraw mode line */
4506 if (tb->dirty_flags & DIRTY_MODE)
4508 char buf[MAX_LINELEN];
4510 int sepa_length = tb->wid;
4513 for (i = 0; i < sepa_length; i++)
4517 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4520 if (tb->dirty_flags & DIRTY_EXPRESSION)
4525 for (y = 0; tb->lines_list[y]; y++)
4529 cptr s = tb->lines_list[y];
4533 /* Update this line's state */
4534 tb->states[y] = state;
4536 if (*s++ != '?') continue;
4537 if (*s++ != ':') continue;
4539 /* Lines below this line are auto-registered */
4540 if (streq(s, "$AUTOREGISTER"))
4541 state |= LSTAT_AUTOREGISTER;
4544 ss = (char *)string_make(s);
4547 /* Parse the expr */
4548 v = process_pref_file_expr(&ss, &f);
4551 if (streq(v, "0")) state |= LSTAT_BYPASS;
4552 else state &= ~LSTAT_BYPASS;
4554 /* Cannot use string_free() because the string was "destroyed" */
4555 C_KILL(s_keep, s_len + 1, char);
4557 /* Re-update this line's state */
4558 tb->states[y] = state | LSTAT_EXPRESSION;
4561 tb->dirty_flags |= DIRTY_ALL;
4566 tb->dirty_flags |= DIRTY_ALL;
4568 by1 = MIN(tb->my, tb->cy);
4569 by2 = MAX(tb->my, tb->cy);
4572 /* Dump up to tb->hgt lines of messages */
4573 for (i = 0; i < tb->hgt; i++)
4579 int y = tb->upper+i;
4581 /* clean or dirty? */
4582 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4585 msg = tb->lines_list[y];
4588 /* Apply horizontal scroll */
4589 for (j = 0; *msg; msg++, j++)
4591 if (j == tb->left) break;
4607 Term_erase(0, i + 1, tb->wid);
4609 if (tb->states[y] & LSTAT_AUTOREGISTER)
4611 /* Warning color -- These lines will be deleted later */
4616 /* Bypassed line will be displayed by darker color */
4617 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4618 else color = TERM_WHITE;
4621 /* No mark or Out of mark */
4622 if (!tb->mark || (y < by1 || by2 < y))
4624 /* Dump the messages, bottom to top */
4625 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4628 /* Multiple lines selected */
4629 else if (by1 != by2)
4631 /* Dump the messages, bottom to top */
4632 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4635 /* Single line selected */
4638 int x0 = leftcol + tb->left;
4639 int len = strlen(tb->lines_list[tb->cy]);
4640 int bx1 = MIN(tb->mx, tb->cx);
4641 int bx2 = MAX(tb->mx, tb->cx);
4643 /* Correct cursor location */
4644 if (bx2 > len) bx2 = len;
4646 Term_gotoxy(leftcol, i + 1);
4647 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4648 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4649 Term_addstr(-1, color, msg + (bx2 - x0));
4653 for (; i < tb->hgt; i++)
4656 Term_erase(0, i + 1, tb->wid);
4659 /* Display information when updated */
4660 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4662 autopick_type an_entry, *entry = &an_entry;
4663 cptr str1 = NULL, str2 = NULL;
4666 /* Clear information line */
4667 for (i = 0; i < DESCRIPT_HGT; i++)
4670 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4673 /* Display information */
4674 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4676 str1 = format(_("パターンが見つかりません: %s", "Pattern not found: %s"), tb->search_str);
4678 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4680 str1 = format(_("無効状態の行をスキップしました。(%sを検索中)",
4681 "Some inactive lines are skipped. (Searching %s)"), tb->search_str);
4683 else if (tb->dirty_flags & DIRTY_INACTIVE)
4685 str1 = format(_("無効状態の行だけが見付かりました。(%sを検索中)",
4686 "Found only an inactive line. (Searching %s)"), tb->search_str);
4688 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4690 str1 = _("検索するパターンがありません(^S で検索)。", "No pattern to search. (Press ^S to search.)");
4692 else if (tb->lines_list[tb->cy][0] == '#')
4694 str1 = _("この行はコメントです。", "This line is a comment.");
4696 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4698 switch(tb->lines_list[tb->cy][0])
4701 str1 = _("この行は条件分岐式です。", "This line is a Conditional Expression.");
4704 str1 = _("この行はマクロの実行内容を定義します。", "This line defines a Macro action.");
4707 str1 = _("この行はマクロのトリガー・キーを定義します。", "This line defines a Macro trigger key.");
4710 str1 = _("この行はキー配置を定義します。", "This line defines a Keymap.");
4714 switch(tb->lines_list[tb->cy][0])
4717 if (tb->states[tb->cy] & LSTAT_BYPASS)
4719 str2 = _("現在の式の値は「偽(=0)」です。", "The expression is 'False'(=0) currently.");
4723 str2 = _("現在の式の値は「真(=1)」です。", "The expression is 'True'(=1) currently.");
4728 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4730 str2 = _("この行は後で削除されます。", "This line will be delete later.");
4733 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4735 str2 = _("この行は現在は無効な状態です。", "This line is bypassed currently.");
4741 /* Get description of an autopicker preference line */
4742 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4744 char buf[MAX_LINELEN];
4745 char temp[MAX_LINELEN];
4748 describe_autopick(buf, entry);
4750 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4752 strcat(buf, _("この行は後で削除されます。", " This line will be delete later."));
4755 if (tb->states[tb->cy] & LSTAT_BYPASS)
4757 strcat(buf, _("この行は現在は無効な状態です。", " This line is bypassed currently."));
4760 roff_to_buf(buf, 81, temp, sizeof(temp));
4762 for (i = 0; i < 3; i++)
4768 prt(t, tb->hgt +1 + 1 + i, 0);
4772 autopick_free_entry(entry);
4775 /* Draw the first line */
4776 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4778 /* Draw the second line */
4779 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4785 * Kill segment of a line
4787 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4789 char buf[MAX_LINELEN];
4790 cptr s = tb->lines_list[y];
4794 /* Kill whole line? */
4795 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4799 string_free(tb->lines_list[y]);
4801 /* Shift lines up */
4802 for (i = y; tb->lines_list[i+1]; i++)
4803 tb->lines_list[i] = tb->lines_list[i+1];
4804 tb->lines_list[i] = NULL;
4806 /* Expressions need re-evaluation */
4807 tb->dirty_flags |= DIRTY_EXPRESSION;
4813 if (x0 == x1) return;
4815 /* Before the segment */
4816 for (x = 0; x < x0; x++)
4819 /* After the segment */
4820 for (x = x1; s[x]; x++)
4826 string_free(tb->lines_list[y]);
4827 tb->lines_list[y] = string_make(buf);
4829 /* Expressions may need re-evaluation */
4830 check_expression_line(tb, y);
4832 /* Text is changed */
4838 * Get a trigger key and insert ASCII string for the trigger
4840 static bool insert_macro_line(text_body_type *tb)
4849 /* Do not process macros */
4855 /* Read the pattern */
4861 /* Do not process macros */
4864 /* Do not wait for keys */
4867 /* Attempt to read a key */
4877 /* Convert the trigger */
4878 ascii_to_text(tmp, buf);
4881 if(!tmp[0]) return FALSE;
4885 /* Insert preference string */
4886 insert_return_code(tb);
4887 string_free(tb->lines_list[tb->cy]);
4888 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4890 /* Acquire action */
4891 i = macro_find_exact(buf);
4895 /* Nothing defined */
4900 /* Analyze the current action */
4901 ascii_to_text(tmp, macro__act[i]);
4904 /* Insert blank action preference line */
4905 insert_return_code(tb);
4906 string_free(tb->lines_list[tb->cy]);
4907 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4914 * Get a command key and insert ASCII string for the key
4916 static bool insert_keymap_line(text_body_type *tb)
4924 if (rogue_like_commands)
4926 mode = KEYMAP_MODE_ROGUE;
4932 mode = KEYMAP_MODE_ORIG;
4945 /* Convert the trigger */
4946 ascii_to_text(tmp, buf);
4949 if(!tmp[0]) return FALSE;
4953 /* Insert preference string */
4954 insert_return_code(tb);
4955 string_free(tb->lines_list[tb->cy]);
4956 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4958 /* Look up the keymap */
4959 act = keymap_act[mode][(byte)(buf[0])];
4963 /* Analyze the current action */
4964 ascii_to_text(tmp, act);
4968 /* No keymap defined -- Use trigger key itself as a default */
4970 /* Nothing to do (use tmp) */
4973 /* Insert blank action preference line */
4974 insert_return_code(tb);
4975 string_free(tb->lines_list[tb->cy]);
4976 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4983 * Execute a single editor command
4985 static bool do_editor_command(text_body_type *tb, int com_id)
4992 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
4993 "Discard all changes and quit. Are you sure? "))) break;
4995 return QUIT_WITHOUT_SAVE;
4998 return QUIT_AND_SAVE;
5001 /* Revert to original */
5002 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
5003 "Discard all changes and revert to original file. Are you sure? "))) break;
5005 free_text_lines(tb->lines_list);
5006 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5007 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5008 tb->cx = tb->cy = 0;
5011 /* Text is not changed */
5012 tb->changed = FALSE;
5016 /* Peruse the main help file */
5017 (void)show_file(TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
5019 tb->dirty_flags |= DIRTY_SCREEN;
5024 /* Split a line or insert end of line */
5026 /* Ignore selection */
5032 tb->dirty_flags |= DIRTY_ALL;
5035 insert_return_code(tb);
5040 tb->dirty_flags |= DIRTY_ALL;
5053 len = strlen(tb->lines_list[tb->cy]);
5054 if (len < tb->cx) tb->cx = len;
5057 /* Don't let cursor at second byte of kanji */
5058 for (i = 0; tb->lines_list[tb->cy][i]; i++)
5060 if (iskanji(tb->lines_list[tb->cy][i]))
5065 /* Move to the left */
5073 else if (tb->cy > 0)
5076 tb->cx = strlen(tb->lines_list[tb->cy]);
5083 /* Is this the last line? */
5084 if (!tb->lines_list[tb->cy + 1])
5086 /* Add one more empty line if possible */
5087 if (!add_empty_line(tb)) break;
5097 if (tb->cy > 0) tb->cy--;
5106 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5109 len = strlen(tb->lines_list[tb->cy]);
5112 /* Correct the cursor position */
5115 /* Is this the last line? */
5116 if (!tb->lines_list[tb->cy + 1])
5118 /* Add one more empty line if possible */
5119 if (!add_empty_line(tb)) break;
5122 /* Move to the beginning of next line */
5130 /* Beginning of line */
5136 tb->cx = strlen(tb->lines_list[tb->cy]);
5140 while (0 < tb->cy && tb->upper <= tb->cy)
5142 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5148 while (tb->cy < tb->upper + tb->hgt)
5150 /* Is this the last line? */
5151 if (!tb->lines_list[tb->cy + 1])
5153 /* Add one more empty line if possible */
5154 if (!add_empty_line(tb)) break;
5170 /* Is this the last line? */
5171 if (!tb->lines_list[tb->cy + 1])
5173 /* Add one more empty line if possible */
5174 if (!add_empty_line(tb)) break;
5180 /* Always at the biginning of the last line */
5187 /* Copy the text first */
5188 copy_text_to_yank(tb);
5190 /* Single line case */
5191 if (tb->my == tb->cy)
5193 int bx1 = MIN(tb->mx, tb->cx);
5194 int bx2 = MAX(tb->mx, tb->cx);
5195 int len = strlen(tb->lines_list[tb->cy]);
5197 /* Correct fake cursor position */
5198 if (bx2 > len) bx2 = len;
5200 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5202 /* New cursor position */
5206 /* Multiple lines case */
5207 else /* if (tb->my != tb->cy) */
5211 int by1 = MIN(tb->my, tb->cy);
5212 int by2 = MAX(tb->my, tb->cy);
5214 /* Kill lines in reverse order */
5215 for (y = by2; y >= by1; y--)
5217 int len = strlen(tb->lines_list[y]);
5219 kill_line_segment(tb, y, 0, len, TRUE);
5222 /* New cursor position */
5228 /* Disable selection */
5232 tb->dirty_flags |= DIRTY_ALL;
5234 /* Text is changed */
5241 copy_text_to_yank(tb);
5244 * Move cursor position to the end of the selection
5246 * Pressing ^C ^V correctly duplicates the selection.
5248 if (tb->my == tb->cy)
5250 tb->cx = MAX(tb->cx, tb->mx);
5253 * When whole line is selected, the end of
5254 * line code is also copyed.
5256 if (!tb->lines_list[tb->cy][tb->cx])
5258 /* Is this the last line? */
5259 if (!tb->lines_list[tb->cy + 1])
5261 /* Add one more empty line if possible */
5262 if (!add_empty_line(tb)) break;
5265 /* Go to the beginning of next line */
5272 tb->cy = MAX(tb->cy, tb->my);
5274 /* Is this the last line? */
5275 if (!tb->lines_list[tb->cy + 1])
5277 /* Add one more empty line if possible */
5278 if (!add_empty_line(tb)) break;
5289 /* Paste killed text */
5291 chain_str_type *chain = tb->yank;
5292 int len = strlen(tb->lines_list[tb->cy]);
5294 /* Nothing to do? */
5297 /* Correct cursor location */
5298 if (tb->cx > len) tb->cx = len;
5300 /* Ignore selection */
5306 tb->dirty_flags |= DIRTY_ALL;
5312 cptr yank_str = chain->s;
5314 char buf[MAX_LINELEN];
5316 char rest[MAX_LINELEN], *rest_ptr = rest;
5318 /* Save preceding string */
5319 for(i = 0; i < tb->cx; i++)
5320 buf[i] = tb->lines_list[tb->cy][i];
5322 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5324 /* Paste yank buffer */
5325 while (*yank_str && i < MAX_LINELEN-1)
5327 buf[i++] = *yank_str++;
5333 chain = chain->next;
5335 if (chain || tb->yank_eol)
5337 /* There is an end of line between chain nodes */
5339 insert_return_code(tb);
5341 /* Replace this line with new one */
5342 string_free(tb->lines_list[tb->cy]);
5343 tb->lines_list[tb->cy] = string_make(buf);
5345 /* Move to next line */
5352 /* Final line doesn't have end of line */
5354 tb->cx = strlen(buf);
5356 /* Rest of original line */
5357 while (*rest_ptr && i < MAX_LINELEN-1)
5359 buf[i++] = *rest_ptr++;
5365 /* Replace this line with new one */
5366 string_free(tb->lines_list[tb->cy]);
5367 tb->lines_list[tb->cy] = string_make(buf);
5374 tb->dirty_flags |= DIRTY_ALL;
5376 /* Expressions need re-evaluation */
5377 tb->dirty_flags |= DIRTY_EXPRESSION;
5379 /* Text is changed */
5388 /* Disable the selection */
5392 tb->dirty_flags |= DIRTY_ALL;
5396 tb->mark = MARK_MARK;
5398 /* Repeating this command swaps cursor position */
5399 if (com_id == tb->old_com_id)
5411 tb->dirty_flags |= DIRTY_ALL;
5415 int len = strlen(tb->lines_list[tb->cy]);
5417 /* Mark the point 1 */
5421 /* Correct cursor location */
5422 if (tb->cx > len) tb->mx = len;
5429 /* Kill rest of line */
5431 int len = strlen(tb->lines_list[tb->cy]);
5433 /* Correct cursor location */
5434 if (tb->cx > len) tb->cx = len;
5436 /* Ignore selection */
5442 tb->dirty_flags |= DIRTY_ALL;
5445 /* Append only if this command is repeated. */
5446 if (tb->old_com_id != com_id)
5448 kill_yank_chain(tb);
5452 /* Really deleted some text */
5455 /* Add deleted string to yank buffer */
5456 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5458 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5461 tb->dirty_line = tb->cy;
5463 /* Leave end of line character */
5467 /* Cut the end of line character only */
5468 if (tb->yank_eol) add_str_to_yank(tb, "");
5470 /* Cut end of line */
5471 tb->yank_eol = TRUE;
5473 do_editor_command(tb, EC_DELETE_CHAR);
5477 case EC_DELETE_CHAR:
5479 /* DELETE == go forward + BACK SPACE */
5483 /* Ignore selection */
5489 tb->dirty_flags |= DIRTY_ALL;
5493 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5497 /* Pass through the end of line to next line */
5498 len = strlen(tb->lines_list[tb->cy]);
5501 if (tb->lines_list[tb->cy + 1])
5513 do_editor_command(tb, EC_BACKSPACE);
5522 char buf[MAX_LINELEN];
5524 /* Ignore selection */
5530 tb->dirty_flags |= DIRTY_ALL;
5533 /* Move to correct collumn */
5534 len = strlen(tb->lines_list[tb->cy]);
5535 if (len < tb->cx) tb->cx = len;
5539 /* delete a return code and union two lines */
5540 if (tb->cy == 0) break;
5541 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5542 strcpy(buf, tb->lines_list[tb->cy-1]);
5543 strcat(buf, tb->lines_list[tb->cy]);
5544 string_free(tb->lines_list[tb->cy-1]);
5545 string_free(tb->lines_list[tb->cy]);
5546 tb->lines_list[tb->cy-1] = string_make(buf);
5548 for (i = tb->cy; tb->lines_list[i+1]; i++)
5549 tb->lines_list[i] = tb->lines_list[i+1];
5551 tb->lines_list[i] = NULL;
5555 tb->dirty_flags |= DIRTY_ALL;
5557 /* Expressions need re-evaluation */
5558 tb->dirty_flags |= DIRTY_EXPRESSION;
5560 /* Text is changed */
5566 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5570 if (iskanji(tb->lines_list[tb->cy][i]))
5571 buf[j++] = tb->lines_list[tb->cy][i++];
5573 buf[j++] = tb->lines_list[tb->cy][i];
5580 for (; tb->lines_list[tb->cy][i]; i++)
5581 buf[j++] = tb->lines_list[tb->cy][i];
5583 string_free(tb->lines_list[tb->cy]);
5584 tb->lines_list[tb->cy] = string_make(buf);
5587 tb->dirty_line = tb->cy;
5589 /* Expressions may need re-evaluation */
5590 check_expression_line(tb, tb->cy);
5592 /* Text is changed */
5602 /* Become dirty because of item/equip menu */
5603 tb->dirty_flags |= DIRTY_SCREEN;
5605 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5607 if (!search_dir) break;
5609 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5610 else do_editor_command(tb, EC_SEARCH_BACK);
5614 case EC_SEARCH_FORW:
5615 if (tb->search_o_ptr)
5617 search_for_object(tb, tb->search_o_ptr, TRUE);
5619 else if (tb->search_str && tb->search_str[0])
5621 search_for_string(tb, tb->search_str, TRUE);
5625 tb->dirty_flags |= DIRTY_NO_SEARCH;
5629 case EC_SEARCH_BACK:
5630 if (tb->search_o_ptr)
5632 search_for_object(tb, tb->search_o_ptr, FALSE);
5634 else if (tb->search_str && tb->search_str[0])
5636 search_for_string(tb, tb->search_str, FALSE);
5640 tb->dirty_flags |= DIRTY_NO_SEARCH;
5645 /* Become dirty because of item/equip menu */
5646 tb->dirty_flags |= DIRTY_SCREEN;
5648 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5650 do_editor_command(tb, EC_SEARCH_FORW);
5653 case EC_SEARCH_DESTROYED:
5654 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5656 /* There is no object to search */
5657 tb->dirty_flags |= DIRTY_NO_SEARCH;
5662 do_editor_command(tb, EC_SEARCH_FORW);
5665 case EC_INSERT_OBJECT:
5667 /* Insert choosen item name */
5669 autopick_type an_entry, *entry = &an_entry;
5671 if (!entry_from_choosed_object(entry))
5673 /* Now dirty because of item/equip menu */
5674 tb->dirty_flags |= DIRTY_SCREEN;
5679 insert_return_code(tb);
5680 string_free(tb->lines_list[tb->cy]);
5681 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5683 /* Now dirty because of item/equip menu */
5684 tb->dirty_flags |= DIRTY_SCREEN;
5689 case EC_INSERT_DESTROYED:
5690 /* Insert a name of last destroyed item */
5691 if (tb->last_destroyed)
5694 insert_return_code(tb);
5695 string_free(tb->lines_list[tb->cy]);
5696 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5699 tb->dirty_flags |= DIRTY_ALL;
5701 /* Text is changed */
5706 case EC_INSERT_BLOCK:
5708 /* Insert a conditinal expression line */
5709 char expression[80];
5711 /* Conditional Expression for Class and Race */
5712 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5714 rp_ptr->E_title, cp_ptr->E_title,
5716 rp_ptr->title, cp_ptr->title,
5722 insert_return_code(tb);
5723 string_free(tb->lines_list[tb->cy]);
5724 tb->lines_list[tb->cy] = string_make(expression);
5726 insert_return_code(tb);
5727 string_free(tb->lines_list[tb->cy]);
5728 tb->lines_list[tb->cy] = string_make("?:1");
5731 tb->dirty_flags |= DIRTY_ALL;
5733 /* Text is changed */
5739 case EC_INSERT_MACRO:
5740 /* Draw_everythig (delete menu) */
5741 draw_text_editor(tb);
5744 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5747 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
5748 if (insert_macro_line(tb))
5750 /* Prepare to input action */
5754 tb->dirty_flags |= DIRTY_ALL;
5756 /* Text is changed */
5762 case EC_INSERT_KEYMAP:
5763 /* Draw_everythig (delete menu) */
5764 draw_text_editor(tb);
5767 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5770 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
5771 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5773 if (insert_keymap_line(tb))
5775 /* Prepare to input action */
5779 tb->dirty_flags |= DIRTY_ALL;
5781 /* Text is changed */
5786 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5787 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5788 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5789 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5790 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5792 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5793 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5794 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5795 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5796 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5797 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5798 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5799 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5800 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5801 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5802 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5803 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5804 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5805 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5806 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5807 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5808 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5809 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5810 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5811 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5812 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5813 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5814 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5815 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5816 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5817 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5818 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5819 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5820 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5821 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5822 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5823 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5824 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5825 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5826 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5827 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5828 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5829 case EC_OK_UNREADABLE:
5830 toggle_keyword(tb, FLG_UNREADABLE);
5831 add_keyword(tb, FLG_SPELLBOOKS);
5834 toggle_keyword(tb, FLG_REALM1);
5835 add_keyword(tb, FLG_SPELLBOOKS);
5838 toggle_keyword(tb, FLG_REALM2);
5839 add_keyword(tb, FLG_SPELLBOOKS);
5842 toggle_keyword(tb, FLG_FIRST);
5843 add_keyword(tb, FLG_SPELLBOOKS);
5846 toggle_keyword(tb, FLG_SECOND);
5847 add_keyword(tb, FLG_SPELLBOOKS);
5850 toggle_keyword(tb, FLG_THIRD);
5851 add_keyword(tb, FLG_SPELLBOOKS);
5854 toggle_keyword(tb, FLG_FOURTH);
5855 add_keyword(tb, FLG_SPELLBOOKS);
5859 /* Save old command */
5860 tb->old_com_id = com_id;
5867 * Insert single letter at cursor position.
5869 static void insert_single_letter(text_body_type *tb, int key)
5872 char buf[MAX_LINELEN];
5874 /* Save preceding string */
5875 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5876 buf[j++] = tb->lines_list[tb->cy][i];
5878 /* Add a character */
5886 if (j+2 < MAX_LINELEN)
5888 buf[j++] = (char)key;
5889 buf[j++] = (char)next;
5898 if (j+1 < MAX_LINELEN)
5899 buf[j++] = (char)key;
5904 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5905 buf[j++] = tb->lines_list[tb->cy][i];
5908 /* Replace current line with new line */
5909 string_free(tb->lines_list[tb->cy]);
5910 tb->lines_list[tb->cy] = string_make(buf);
5912 /* Move to correct collumn */
5913 len = strlen(tb->lines_list[tb->cy]);
5914 if (len < tb->cx) tb->cx = len;
5917 tb->dirty_line = tb->cy;
5919 /* Expressions may need re-evaluation */
5920 check_expression_line(tb, tb->cy);
5922 /* Text is changed */
5928 * Check special key code and get a movement command id
5930 static int analyze_move_key(text_body_type *tb, int skey)
5934 /* Not a special key */
5935 if (!(skey & SKEY_MASK)) return 0;
5937 /* Convert from a special key code to an editor command */
5938 switch(skey & ~SKEY_MOD_MASK)
5940 case SKEY_DOWN: com_id = EC_DOWN; break;
5941 case SKEY_LEFT: com_id = EC_LEFT; break;
5942 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5943 case SKEY_UP: com_id = EC_UP; break;
5944 case SKEY_PGUP: com_id = EC_PGUP; break;
5945 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5946 case SKEY_TOP: com_id = EC_TOP; break;
5947 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5950 /* Not a special movement key */
5954 /* Without shift modifier */
5955 if (!(skey & SKEY_MOD_SHIFT))
5958 * Un-shifted cursor keys cancells
5959 * selection created by shift+cursor.
5961 if (tb->mark & MARK_BY_SHIFT)
5966 tb->dirty_flags |= DIRTY_ALL;
5970 /* With shift modifier */
5973 /* Start selection by shift + cursor keys */
5976 int len = strlen(tb->lines_list[tb->cy]);
5978 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5982 /* Correct cursor location */
5983 if (tb->cx > len) tb->mx = len;
5985 /* Need to redraw text */
5986 if (com_id == EC_UP || com_id == EC_DOWN)
5988 /* Redraw all text */
5989 tb->dirty_flags |= DIRTY_ALL;
5993 tb->dirty_line = tb->cy;
6002 * In-game editor of Object Auto-picker/Destoryer
6004 void do_cmd_edit_autopick(void)
6006 static int cx_save = 0;
6007 static int cy_save = 0;
6009 text_body_type text_body, *tb = &text_body;
6011 autopick_type an_entry, *entry = &an_entry;
6012 char buf[MAX_LINELEN];
6017 static s32b old_autosave_turn = 0L;
6020 tb->changed = FALSE;
6023 tb->upper = tb->left = 0;
6025 tb->mx = tb->my = 0;
6026 tb->old_cy = tb->old_upper = tb->old_left = -1;
6027 tb->old_wid = tb->old_hgt = -1;
6031 tb->search_o_ptr = NULL;
6032 tb->search_str = NULL;
6033 tb->last_destroyed = NULL;
6034 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6035 tb->dirty_line = -1;
6036 tb->filename_mode = PT_DEFAULT;
6038 if (turn < old_autosave_turn)
6040 while (old_autosave_turn > turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
6044 if (turn > old_autosave_turn + 100L)
6046 do_cmd_save_game(TRUE);
6047 old_autosave_turn = turn;
6050 /* HACK -- Reset start_time to stop counting playtime while edit */
6053 /* Free old entries */
6056 /* Command Description of the 'Last Destroyed Item' */
6057 if (autopick_last_destroyed_object.k_idx)
6059 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6060 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6063 /* Read or initialize whole text */
6064 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6066 /* Reset cursor position if needed */
6067 for (i = 0; i < tb->cy; i++)
6069 if (!tb->lines_list[i])
6071 tb->cy = tb->cx = 0;
6076 /* Save the screen */
6079 /* Process requests until done */
6084 /* Draw_everythig */
6085 draw_text_editor(tb);
6087 /* Display header line */
6088 prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)",
6089 "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0);
6092 /* Display current position */
6093 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6097 /* Display current position and mark position */
6098 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6102 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6105 tb->dirty_flags = 0;
6106 tb->dirty_line = -1;
6108 /* Save old key and location */
6109 tb->old_cy = tb->cy;
6110 tb->old_upper = tb->upper;
6111 tb->old_left = tb->left;
6112 tb->old_wid = tb->wid;
6113 tb->old_hgt = tb->hgt;
6116 key = inkey_special(TRUE);
6119 if (key & SKEY_MASK)
6121 /* Get a movement command */
6122 com_id = analyze_move_key(tb, key);
6126 else if (key == ESCAPE)
6128 com_id = do_command_menu(0, 0);
6130 /* Redraw all text later */
6131 tb->dirty_flags |= DIRTY_SCREEN;
6134 /* Insert a character */
6135 else if (!iscntrl((unsigned char)key))
6137 /* Ignore selection */
6143 tb->dirty_flags |= DIRTY_ALL;
6146 insert_single_letter(tb, key);
6152 /* Other commands */
6155 com_id = get_com_id((char)key);
6158 if (com_id) quit = do_editor_command(tb, com_id);
6159 } /* while (TRUE) */
6161 /* Restore the screen */
6164 /* Get the filename of preference */
6165 strcpy(buf, pickpref_filename(tb->filename_mode));
6167 if (quit == QUIT_AND_SAVE)
6168 write_text_lines(buf, tb->lines_list);
6170 free_text_lines(tb->lines_list);
6172 string_free(tb->search_str);
6173 string_free(tb->last_destroyed);
6175 /* Destroy string chain */
6176 kill_yank_chain(tb);
6178 /* Reload autopick pref */
6179 process_autopick_file(buf);
6181 /* HACK -- reset start_time so that playtime is not increase while edit */
6182 start_time = (u32b)time(NULL);
6184 /* Save cursor location */