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
23 #include "player-status.h"
24 #include "player-move.h"
25 #include "player-class.h"
26 #include "player-race.h"
27 #include "player-inventory.h"
28 #include "objectkind.h"
29 #include "object-ego.h"
30 #include "object-flavor.h"
31 #include "object-hook.h"
37 #include "monsterrace.h"
38 #include "view-mainwindow.h"
40 #define MAX_LINELEN 1024
47 #define FLG_UNIDENTIFIED 2
48 #define FLG_IDENTIFIED 3
49 #define FLG_STAR_IDENTIFIED 4
50 #define FLG_COLLECTING 5
51 #define FLG_ARTIFACT 6
54 #define FLG_NAMELESS 11
55 #define FLG_AVERAGE 12
56 #define FLG_WORTHLESS 13
59 #define FLG_BOOSTED 16
60 #define FLG_MORE_DICE 17
61 #define FLG_MORE_BONUS 18
65 #define FLG_UNREADABLE 22
74 #define FLG_WEAPONS 31
75 #define FLG_FAVORITE_WEAPONS 32
77 #define FLG_MISSILES 34
78 #define FLG_DEVICES 35
81 #define FLG_CORPSES 38
82 #define FLG_SPELLBOOKS 39
84 #define FLG_SHIELDS 41
87 #define FLG_AMULETS 44
94 #define FLG_NOUN_BEGIN FLG_ITEMS
95 #define FLG_NOUN_END FLG_BOOTS
99 static GAME_TEXT KEY_ALL[] = "すべての";
100 static GAME_TEXT KEY_UNAWARE[] = "未判明の";
101 static GAME_TEXT KEY_UNIDENTIFIED[] = "未鑑定の";
102 static GAME_TEXT KEY_IDENTIFIED[] = "鑑定済みの";
103 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*鑑定*済みの";
104 static GAME_TEXT KEY_COLLECTING[] = "収集中の";
105 static GAME_TEXT KEY_ARTIFACT[] = "アーティファクト";
106 static GAME_TEXT KEY_EGO[] = "エゴ";
107 static GAME_TEXT KEY_GOOD[] = "上質の";
108 static GAME_TEXT KEY_NAMELESS[] = "無銘の";
109 static GAME_TEXT KEY_AVERAGE[] = "並の";
110 static GAME_TEXT KEY_WORTHLESS[] = "無価値の";
111 static GAME_TEXT KEY_RARE[] = "レアな";
112 static GAME_TEXT KEY_COMMON[] = "ありふれた";
113 static GAME_TEXT KEY_BOOSTED[] = "ダイス目の違う";
114 static GAME_TEXT KEY_MORE_THAN[] = "ダイス目";
115 static GAME_TEXT KEY_DICE[] = "以上の";
116 static GAME_TEXT KEY_MORE_BONUS[] = "修正値";
117 static GAME_TEXT KEY_MORE_BONUS2[] = "以上の";
118 static GAME_TEXT KEY_WANTED[] = "賞金首の";
119 static GAME_TEXT KEY_UNIQUE[] = "ユニーク・モンスターの";
120 static GAME_TEXT KEY_HUMAN[] = "人間の";
121 static GAME_TEXT KEY_UNREADABLE[] = "読めない";
122 static GAME_TEXT KEY_REALM1[] = "第一領域の";
123 static GAME_TEXT KEY_REALM2[] = "第二領域の";
124 static GAME_TEXT KEY_FIRST[] = "1冊目の";
125 static GAME_TEXT KEY_SECOND[] = "2冊目の";
126 static GAME_TEXT KEY_THIRD[] = "3冊目の";
127 static GAME_TEXT KEY_FOURTH[] = "4冊目の";
128 static GAME_TEXT KEY_ITEMS[] = "アイテム";
129 static GAME_TEXT KEY_WEAPONS[] = "武器";
130 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "得意武器";
131 static GAME_TEXT KEY_ARMORS[] = "防具";
132 static GAME_TEXT KEY_MISSILES[] = "矢";
133 static GAME_TEXT KEY_DEVICES[] = "魔法アイテム";
134 static GAME_TEXT KEY_LIGHTS[] = "光源";
135 static GAME_TEXT KEY_JUNKS[] = "がらくた";
136 static GAME_TEXT KEY_CORPSES[] = "死体や骨";
137 static GAME_TEXT KEY_SPELLBOOKS[] = "魔法書";
138 static GAME_TEXT KEY_HAFTED[] = "鈍器";
139 static GAME_TEXT KEY_SHIELDS[] = "盾";
140 static GAME_TEXT KEY_BOWS[] = "弓";
141 static GAME_TEXT KEY_RINGS[] = "指輪";
142 static GAME_TEXT KEY_AMULETS[] = "アミュレット";
143 static GAME_TEXT KEY_SUITS[] = "鎧";
144 static GAME_TEXT KEY_CLOAKS[] = "クローク";
145 static GAME_TEXT KEY_HELMS[] = "兜";
146 static GAME_TEXT KEY_GLOVES[] = "籠手";
147 static GAME_TEXT KEY_BOOTS[] = "靴";
151 static GAME_TEXT KEY_ALL[] = "all";
152 static GAME_TEXT KEY_UNAWARE[] = "unaware";
153 static GAME_TEXT KEY_UNIDENTIFIED[] = "unidentified";
154 static GAME_TEXT KEY_IDENTIFIED[] = "identified";
155 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*identified*";
156 static GAME_TEXT KEY_COLLECTING[] = "collecting";
157 static GAME_TEXT KEY_ARTIFACT[] = "artifact";
158 static GAME_TEXT KEY_EGO[] = "ego";
159 static GAME_TEXT KEY_GOOD[] = "good";
160 static GAME_TEXT KEY_NAMELESS[] = "nameless";
161 static GAME_TEXT KEY_AVERAGE[] = "average";
162 static GAME_TEXT KEY_WORTHLESS[] = "worthless";
163 static GAME_TEXT KEY_RARE[] = "rare";
164 static GAME_TEXT KEY_COMMON[] = "common";
165 static GAME_TEXT KEY_BOOSTED[] = "dice boosted";
166 static GAME_TEXT KEY_MORE_THAN[] = "more than";
167 static GAME_TEXT KEY_DICE[] = " dice";
168 static GAME_TEXT KEY_MORE_BONUS[] = "more bonus than";
169 static GAME_TEXT KEY_MORE_BONUS2[] = "";
170 static GAME_TEXT KEY_WANTED[] = "wanted";
171 static GAME_TEXT KEY_UNIQUE[] = "unique monster's";
172 static GAME_TEXT KEY_HUMAN[] = "human";
173 static GAME_TEXT KEY_UNREADABLE[] = "unreadable";
174 static GAME_TEXT KEY_REALM1[] = "first realm's";
175 static GAME_TEXT KEY_REALM2[] = "second realm's";
176 static GAME_TEXT KEY_FIRST[] = "first";
177 static GAME_TEXT KEY_SECOND[] = "second";
178 static GAME_TEXT KEY_THIRD[] = "third";
179 static GAME_TEXT KEY_FOURTH[] = "fourth";
180 static GAME_TEXT KEY_ITEMS[] = "items";
181 static GAME_TEXT KEY_WEAPONS[] = "weapons";
182 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "favorite weapons";
183 static GAME_TEXT KEY_ARMORS[] = "armors";
184 static GAME_TEXT KEY_MISSILES[] = "missiles";
185 static GAME_TEXT KEY_DEVICES[] = "magical devices";
186 static GAME_TEXT KEY_LIGHTS[] = "lights";
187 static GAME_TEXT KEY_JUNKS[] = "junks";
188 static GAME_TEXT KEY_CORPSES[] = "corpses or skeletons";
189 static GAME_TEXT KEY_SPELLBOOKS[] = "spellbooks";
190 static GAME_TEXT KEY_HAFTED[] = "hafted weapons";
191 static GAME_TEXT KEY_SHIELDS[] = "shields";
192 static GAME_TEXT KEY_BOWS[] = "bows";
193 static GAME_TEXT KEY_RINGS[] = "rings";
194 static GAME_TEXT KEY_AMULETS[] = "amulets";
195 static GAME_TEXT KEY_SUITS[] = "suits";
196 static GAME_TEXT KEY_CLOAKS[] = "cloaks";
197 static GAME_TEXT KEY_HELMS[] = "helms";
198 static GAME_TEXT KEY_GLOVES[] = "gloves";
199 static GAME_TEXT KEY_BOOTS[] = "boots";
203 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
204 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
205 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
206 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
209 #define ADD_KEY(KEY) strcat(ptr, KEY)
211 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
213 #define ADD_KEY2(KEY) strcat(ptr, KEY)
215 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
216 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
217 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
218 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
221 static char kanji_colon[] = ":";
226 * 自動拾い/破壊設定のリストに関する変数 / List for auto-picker/destroyer entries
228 int max_autopick = 0; /*!< 現在登録している自動拾い/破壊設定の数 */
229 int max_max_autopick = 0; /*!< 自動拾い/破壊設定の限界数 */
230 autopick_type *autopick_list = NULL; /*!< 自動拾い/破壊設定構造体のポインタ配列 */
233 * A function to create new entry
235 static bool autopick_new_entry(autopick_type *entry, concptr str, bool allow_default)
240 char buf[MAX_LINELEN];
241 concptr prev_ptr, ptr, old_ptr;
244 if (str[0] && str[1] == ':') switch (str[0])
247 case 'A': case 'P': case 'C':
251 entry->flag[0] = entry->flag[1] = 0L;
255 act = DO_AUTOPICK | DO_DISPLAY;
258 if ((act & DO_AUTOPICK) && *str == '!')
261 act |= DO_AUTODESTROY;
264 else if ((act & DO_AUTOPICK) && *str == '~')
267 act |= DONT_AUTOPICK;
270 else if ((act & DO_AUTOPICK) && *str == ';')
273 act |= DO_QUERY_AUTOPICK;
276 else if ((act & DO_DISPLAY) && *str == '(')
285 /* don't mind upper or lower case */
287 for (i = 0; *str; i++)
298 /* Auto-inscription? */
306 if (isupper(c)) c = (char)tolower(c);
312 /* Skip empty line unless allow_default */
313 if (!allow_default && *buf == 0) return FALSE;
315 /* Skip comment line */
316 if (*buf == 0 && insc) return FALSE;
318 ptr = prev_ptr = buf;
321 while (old_ptr != ptr)
323 /* Save current location */
326 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
327 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
328 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
329 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
330 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
331 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
332 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
334 /*** Weapons whose dd*ds is more than nn ***/
335 if (MATCH_KEY2(KEY_MORE_THAN))
340 /* Drop leading spaces */
341 while (' ' == *ptr) ptr++;
344 while ('0' <= *ptr && *ptr <= '9')
346 entry->dice = 10 * entry->dice + (*ptr - '0');
353 (void)MATCH_KEY(KEY_DICE);
354 ADD_FLG(FLG_MORE_DICE);
360 /*** Items whose magical bonus is more than n ***/
361 if (MATCH_KEY2(KEY_MORE_BONUS))
366 /* Drop leading spaces */
367 while (' ' == *ptr) ptr++;
370 while ('0' <= *ptr && *ptr <= '9')
372 entry->bonus = 10 * entry->bonus + (*ptr - '0');
380 (void)MATCH_KEY(KEY_MORE_BONUS2);
382 if (' ' == *ptr) ptr++;
384 ADD_FLG(FLG_MORE_BONUS);
390 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
391 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
392 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
393 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
394 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
395 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
396 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
397 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
398 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
399 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
400 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
401 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
402 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
403 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
404 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
405 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
406 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
409 /* Not yet found any noun */
412 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
414 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
415 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
416 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
417 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
418 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
419 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
420 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
421 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
422 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
423 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
424 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
425 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
426 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
427 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
428 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
429 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
430 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
431 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
432 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
433 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
435 /* Last 'keyword' must be at the correct location */
439 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
442 else if (*ptr == '\0')
444 /* There was no noun */
447 /* Add extra word "items" */
448 ADD_FLG_NOUN(FLG_ITEMS);
455 /* A noun type keyword didn't end correctly */
456 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
461 /* Save this auto-picker entry line */
462 entry->name = string_make(ptr);
464 entry->insc = string_make(insc);
471 * Get auto-picker entry from o_ptr.
473 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
475 /* Assume that object name is to be added */
479 /* エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない */
480 bool bol_mark = FALSE;
482 /* We can always use the ^ mark in English */
483 bool bol_mark = TRUE;
486 GAME_TEXT name_str[MAX_NLEN];
488 /* Initialize name string */
491 entry->insc = string_make(quark_str(o_ptr->inscription));
492 entry->action = DO_AUTOPICK | DO_DISPLAY;
493 entry->flag[0] = entry->flag[1] = 0L;
497 if (!object_is_aware(o_ptr))
499 ADD_FLG(FLG_UNAWARE);
503 /* Not really identified */
504 else if (!object_is_known(o_ptr))
506 if (!(o_ptr->ident & IDENT_SENSE))
508 ADD_FLG(FLG_UNIDENTIFIED);
513 /* Pseudo-identified */
514 switch (o_ptr->feeling)
518 ADD_FLG(FLG_NAMELESS);
524 ADD_FLG(FLG_NAMELESS);
525 ADD_FLG(FLG_WORTHLESS);
531 ADD_FLG(FLG_WORTHLESS);
539 /* XXX No appropriate flag */
544 /* Never reach here */
554 if (object_is_ego(o_ptr))
556 if (object_is_weapon_armour_ammo(o_ptr))
559 * Base name of ego weapons and armors
560 * are almost meaningless.
561 * Register the ego type only.
563 ego_item_type *e_ptr = &e_info[o_ptr->name2];
565 /* エゴ銘には「^」マークが使える */
566 sprintf(name_str, "^%s", e_name + e_ptr->name);
568 /* We ommit the basename and cannot use the ^ mark */
569 strcpy(name_str, e_name + e_ptr->name);
572 /* Don't use the object description */
575 /* Restrict to 'common' equipments */
576 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
583 else if (object_is_artifact(o_ptr))
584 ADD_FLG(FLG_ARTIFACT);
586 /* Non-ego, non-artifact */
589 /* Wearable nameless object */
590 if (object_is_equipment(o_ptr))
591 ADD_FLG(FLG_NAMELESS);
598 /* Melee weapon with boosted dice */
599 if (object_is_melee_weapon(o_ptr))
601 object_kind *k_ptr = &k_info[o_ptr->k_idx];
603 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
604 ADD_FLG(FLG_BOOSTED);
607 /* Wanted monster's corpse */
608 if (object_is_bounty(o_ptr))
610 REM_FLG(FLG_WORTHLESS);
614 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
615 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
620 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
625 if (o_ptr->tval >= TV_LIFE_BOOK &&
626 !check_book_realm(o_ptr->tval, o_ptr->sval))
628 ADD_FLG(FLG_UNREADABLE);
629 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
632 if (REALM1_BOOK == o_ptr->tval &&
633 p_ptr->pclass != CLASS_SORCERER &&
634 p_ptr->pclass != CLASS_RED_MAGE)
640 if (REALM2_BOOK == o_ptr->tval &&
641 p_ptr->pclass != CLASS_SORCERER &&
642 p_ptr->pclass != CLASS_RED_MAGE)
648 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
650 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
652 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
654 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
657 if (object_is_ammo(o_ptr))
658 ADD_FLG(FLG_MISSILES);
659 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
660 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
661 ADD_FLG(FLG_DEVICES);
662 else if (o_ptr->tval == TV_LITE)
664 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
665 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
667 else if (o_ptr->tval == TV_CORPSE)
668 ADD_FLG(FLG_CORPSES);
669 else if (o_ptr->tval >= TV_LIFE_BOOK)
670 ADD_FLG(FLG_SPELLBOOKS);
671 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
672 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
673 ADD_FLG(FLG_WEAPONS);
674 else if (o_ptr->tval == TV_SHIELD)
675 ADD_FLG(FLG_SHIELDS);
676 else if (o_ptr->tval == TV_BOW)
678 else if (o_ptr->tval == TV_RING)
680 else if (o_ptr->tval == TV_AMULET)
681 ADD_FLG(FLG_AMULETS);
682 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
683 o_ptr->tval == TV_SOFT_ARMOR)
685 else if (o_ptr->tval == TV_CLOAK)
687 else if (o_ptr->tval == TV_HELM)
689 else if (o_ptr->tval == TV_GLOVES)
691 else if (o_ptr->tval == TV_BOOTS)
694 /* Prepare the object description */
697 GAME_TEXT o_name[MAX_NLEN];
699 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
702 * If necessary, add a '^' which indicates the
705 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
708 /* Register the name in lowercase */
709 str_tolower(name_str);
710 entry->name = string_make(name_str);
717 * A function to delete entry
719 static void autopick_free_entry(autopick_type *entry)
721 string_free(entry->name);
722 string_free(entry->insc);
728 #define MAX_AUTOPICK_DEFAULT 200
731 * Initialize the autopick
733 static void init_autopick(void)
735 static const char easy_autopick_inscription[] = "(:=g";
741 max_max_autopick = MAX_AUTOPICK_DEFAULT;
742 C_MAKE(autopick_list, max_max_autopick, autopick_type);
746 /* Clear old entries */
747 for( i = 0; i < max_autopick; i++)
748 autopick_free_entry(&autopick_list[i]);
752 /* There is always one entry "=g" */
753 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
754 autopick_list[max_autopick++] = entry;
759 #define PT_WITH_PNAME 1
762 * Get file name for autopick preference
764 static concptr pickpref_filename(int filename_mode)
766 static const char namebase[] = _("picktype", "pickpref");
768 switch (filename_mode)
771 return format("%s.prf", namebase);
774 return format("%s-%s.prf", namebase, p_ptr->base_name);
783 * Load an autopick preference file
785 void autopick_load_pref(bool disp_mes)
790 /* Free old entries */
793 /* Try a filename with player name */
794 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
797 err = process_autopick_file(buf);
799 if (err == 0 && disp_mes)
802 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
808 /* Use default name */
809 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
812 err = process_autopick_file(buf);
814 if (err == 0 && disp_mes)
817 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
824 msg_print(_("自動拾い設定ファイルの読み込みに失敗しました。", "Failed to reload autopick preference."));
830 * Add one line to autopick_list[]
832 static void add_autopick_list(autopick_type *entry)
834 /* There is no enough space to add one line */
835 if (max_autopick >= max_max_autopick)
837 int old_max_max_autopick = max_max_autopick;
838 autopick_type *old_autopick_list = autopick_list;
840 /* Increase size of list */
841 max_max_autopick += MAX_AUTOPICK_DEFAULT;
844 C_MAKE(autopick_list, max_max_autopick, autopick_type);
846 /* Copy from old list to new list */
847 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
850 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
854 autopick_list[max_autopick] = *entry;
861 * Process line for auto picker/destroyer.
863 errr process_autopick_file_command(char *buf)
865 autopick_type an_entry, *entry = &an_entry;
868 /* Nuke illegal char */
869 for(i = 0; buf[i]; i++)
878 if (iswspace(buf[i]) && buf[i] != ' ')
883 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
885 /* Already has the same entry? */
886 for(i = 0; i < max_autopick; i++)
887 if(!strcmp(entry->name, autopick_list[i].name)
888 && entry->flag[0] == autopick_list[i].flag[0]
889 && entry->flag[1] == autopick_list[i].flag[1]
890 && entry->dice == autopick_list[i].dice
891 && entry->bonus == autopick_list[i].bonus)
893 autopick_free_entry(entry);
897 add_autopick_list(entry);
903 * Reconstruct preference line from entry
905 concptr autopick_line_from_entry(autopick_type *entry)
907 char buf[MAX_LINELEN];
909 bool sepa_flag = TRUE;
912 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
913 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
914 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
915 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
919 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
920 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
921 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
922 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
923 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
924 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
925 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
927 if (IS_FLG(FLG_MORE_DICE))
929 ADD_KEY(KEY_MORE_THAN);
930 strcat(ptr, format("%d", entry->dice));
934 if (IS_FLG(FLG_MORE_BONUS))
936 ADD_KEY(KEY_MORE_BONUS);
937 strcat(ptr, format("%d", entry->bonus));
938 ADD_KEY(KEY_MORE_BONUS2);
941 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
942 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
943 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
944 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
945 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
946 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
947 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
948 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
949 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
950 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
951 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
952 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
953 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
954 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
955 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
956 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
957 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
959 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
961 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
962 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
963 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
964 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
965 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
966 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
967 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
968 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
969 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
970 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
971 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
972 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
973 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
974 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
975 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
976 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
977 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
978 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
979 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
980 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
982 /* You don't need sepalator after adjective */
983 /* 'artifact' is not true adjective */
984 else if (!IS_FLG(FLG_ARTIFACT))
987 if (entry->name && entry->name[0])
991 if (sepa_flag) strcat(buf, ":");
994 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
997 if (iskanji(entry->name[j]))
998 buf[i++] = entry->name[j++];
1000 buf[i++] = entry->name[j++];
1011 while (entry->insc[j] && i < MAX_LINELEN - 2)
1014 if (iskanji(entry->insc[j]))
1015 buf[i++] = entry->insc[j++];
1017 buf[i++] = entry->insc[j++];
1022 return string_make(buf);
1027 * Reconstruct preference line from entry and kill entry
1029 static concptr autopick_line_from_entry_kill(autopick_type *entry)
1031 concptr ptr = autopick_line_from_entry(entry);
1033 /* Free memory for original entry */
1034 autopick_free_entry(entry);
1041 * A function for Auto-picker/destroyer
1042 * Examine whether the object matches to the entry
1044 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_name)
1047 concptr ptr = entry->name;
1049 /*** Unaware items ***/
1050 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1053 /*** Unidentified ***/
1054 if (IS_FLG(FLG_UNIDENTIFIED)
1055 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1058 /*** Identified ***/
1059 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1062 /*** *Identified* ***/
1063 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1064 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1067 /*** Dice boosted (weapon of slaying) ***/
1068 if (IS_FLG(FLG_BOOSTED))
1070 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1072 /* Require melee weapon */
1073 if (!object_is_melee_weapon(o_ptr))
1076 /* Require boosted dice */
1077 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1080 /* In Vault Quest, Dice must be hide.*/
1081 if(!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
1087 /*** Weapons which dd*ds is more than nn ***/
1088 if (IS_FLG(FLG_MORE_DICE))
1090 if (o_ptr->dd * o_ptr->ds < entry->dice)
1094 /*** Weapons whic dd*ds is more than nn ***/
1095 if (IS_FLG(FLG_MORE_BONUS))
1097 if (!object_is_known(o_ptr)) return FALSE;
1101 if (o_ptr->pval < entry->bonus) return FALSE;
1105 if (o_ptr->to_h < entry->bonus &&
1106 o_ptr->to_d < entry->bonus &&
1107 o_ptr->to_a < entry->bonus &&
1108 o_ptr->pval < entry->bonus)
1113 /*** Worthless items ***/
1114 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1117 /*** Artifact object ***/
1118 if (IS_FLG(FLG_ARTIFACT))
1120 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1124 /*** Ego object ***/
1125 if (IS_FLG(FLG_EGO))
1127 /* Need to be an ego item */
1128 if (!object_is_ego(o_ptr)) return FALSE;
1130 /* Need to be known to be an ego */
1131 if (!object_is_known(o_ptr) &&
1132 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1137 if (IS_FLG(FLG_GOOD))
1139 if (!object_is_equipment(o_ptr)) return FALSE;
1142 if (object_is_known(o_ptr))
1144 /* Artifacts and Ego objects are not okay */
1145 if (!object_is_nameless(o_ptr))
1148 /* Average are not okay */
1149 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1153 /* Pseudo-identified */
1154 else if (o_ptr->ident & IDENT_SENSE)
1156 switch (o_ptr->feeling)
1171 /* Not known to be good */
1177 if (IS_FLG(FLG_NAMELESS))
1179 if (!object_is_equipment(o_ptr)) return FALSE;
1182 if (object_is_known(o_ptr))
1184 /* Artifacts and Ego objects are not okay */
1185 if (!object_is_nameless(o_ptr))
1189 /* Pseudo-identified */
1190 else if (o_ptr->ident & IDENT_SENSE)
1192 switch (o_ptr->feeling)
1202 /* It's not nameless */
1210 /* Not known to be nameless */
1216 if (IS_FLG(FLG_AVERAGE))
1218 if (!object_is_equipment(o_ptr)) return FALSE;
1221 if (object_is_known(o_ptr))
1223 /* Artifacts and Ego objects are not okay */
1224 if (!object_is_nameless(o_ptr))
1227 /* Cursed or broken objects are not okay */
1228 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1231 /* Good are not okay */
1232 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1236 /* Pseudo-identified */
1237 else if (o_ptr->ident & IDENT_SENSE)
1239 switch (o_ptr->feeling)
1246 /* It's not average */
1254 /* Not known to be average */
1259 /*** Rere equipments ***/
1260 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1263 /*** Common equipments ***/
1264 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1267 /*** Wanted monster's corpse/skeletons ***/
1268 if (IS_FLG(FLG_WANTED) && !object_is_bounty(o_ptr))
1271 /*** Unique monster's corpse/skeletons/statues ***/
1272 if (IS_FLG(FLG_UNIQUE) &&
1273 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1274 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1277 /*** Human corpse/skeletons (for Daemon magic) ***/
1278 if (IS_FLG(FLG_HUMAN) &&
1279 (o_ptr->tval != TV_CORPSE ||
1280 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1283 /*** Unreadable spellbooks ***/
1284 if (IS_FLG(FLG_UNREADABLE) &&
1285 (o_ptr->tval < TV_LIFE_BOOK ||
1286 check_book_realm(o_ptr->tval, o_ptr->sval)))
1289 /*** First realm spellbooks ***/
1290 if (IS_FLG(FLG_REALM1) &&
1291 (REALM1_BOOK != o_ptr->tval ||
1292 p_ptr->pclass == CLASS_SORCERER ||
1293 p_ptr->pclass == CLASS_RED_MAGE))
1296 /*** Second realm spellbooks ***/
1297 if (IS_FLG(FLG_REALM2) &&
1298 (REALM2_BOOK != o_ptr->tval ||
1299 p_ptr->pclass == CLASS_SORCERER ||
1300 p_ptr->pclass == CLASS_RED_MAGE))
1303 /*** First rank spellbooks ***/
1304 if (IS_FLG(FLG_FIRST) &&
1305 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1308 /*** Second rank spellbooks ***/
1309 if (IS_FLG(FLG_SECOND) &&
1310 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1313 /*** Third rank spellbooks ***/
1314 if (IS_FLG(FLG_THIRD) &&
1315 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1318 /*** Fourth rank spellbooks ***/
1319 if (IS_FLG(FLG_FOURTH) &&
1320 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1324 if (IS_FLG(FLG_WEAPONS))
1326 if (!object_is_weapon(o_ptr))
1329 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1331 if (!object_is_favorite(o_ptr))
1334 else if (IS_FLG(FLG_ARMORS))
1336 if (!object_is_armour(o_ptr))
1339 else if (IS_FLG(FLG_MISSILES))
1341 if (!object_is_ammo(o_ptr)) return FALSE;
1343 else if (IS_FLG(FLG_DEVICES))
1347 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1349 default: return FALSE;
1352 else if (IS_FLG(FLG_LIGHTS))
1354 if (!(o_ptr->tval == TV_LITE))
1357 else if (IS_FLG(FLG_JUNKS))
1361 case TV_SKELETON: case TV_BOTTLE:
1362 case TV_JUNK: case TV_STATUE:
1364 default: return FALSE;
1367 else if (IS_FLG(FLG_CORPSES))
1369 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1372 else if (IS_FLG(FLG_SPELLBOOKS))
1374 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1377 else if (IS_FLG(FLG_HAFTED))
1379 if (!(o_ptr->tval == TV_HAFTED))
1382 else if (IS_FLG(FLG_SHIELDS))
1384 if (!(o_ptr->tval == TV_SHIELD))
1387 else if (IS_FLG(FLG_BOWS))
1389 if (!(o_ptr->tval == TV_BOW))
1392 else if (IS_FLG(FLG_RINGS))
1394 if (!(o_ptr->tval == TV_RING))
1397 else if (IS_FLG(FLG_AMULETS))
1399 if (!(o_ptr->tval == TV_AMULET))
1402 else if (IS_FLG(FLG_SUITS))
1404 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1405 o_ptr->tval == TV_HARD_ARMOR ||
1406 o_ptr->tval == TV_SOFT_ARMOR))
1409 else if (IS_FLG(FLG_CLOAKS))
1411 if (!(o_ptr->tval == TV_CLOAK))
1414 else if (IS_FLG(FLG_HELMS))
1416 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1419 else if (IS_FLG(FLG_GLOVES))
1421 if (!(o_ptr->tval == TV_GLOVES))
1424 else if (IS_FLG(FLG_BOOTS))
1426 if (!(o_ptr->tval == TV_BOOTS))
1430 /* Keyword don't match */
1434 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1438 if (!my_strstr(o_name, ptr)) return FALSE;
1441 /* TRUE when it need not to be 'collecting' */
1442 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1444 /* Check if there is a same item */
1445 for (j = 0; j < INVEN_PACK; j++)
1448 * 'Collecting' means the item must be absorbed
1449 * into an inventory slot.
1450 * But an item can not be absorbed into itself!
1452 if ((&p_ptr->inventory_list[j] != o_ptr) &&
1453 object_similar(&p_ptr->inventory_list[j], o_ptr))
1457 /* Not collecting */
1463 * A function for Auto-picker/destroyer
1464 * Examine whether the object matches to the list of keywords or not.
1466 int is_autopick(object_type *o_ptr)
1469 GAME_TEXT o_name[MAX_NLEN];
1471 if (o_ptr->tval == TV_GOLD) return -1;
1473 /* Prepare object name string first */
1474 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1476 /* Convert the string to lower case */
1477 str_tolower(o_name);
1479 /* Look for a matching entry in the list */
1480 for (i=0; i < max_autopick; i++)
1482 autopick_type *entry = &autopick_list[i];
1484 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1487 /* No matching entry */
1495 static void auto_inscribe_item(object_type *o_ptr, int idx)
1497 /* Are there auto-inscription? */
1498 if (idx < 0 || !autopick_list[idx].insc) return;
1500 if (!o_ptr->inscription)
1501 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1503 /* Redraw inscription */
1504 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1506 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1507 p_ptr->update |= (PU_BONUS);
1512 * Automatically destroy items in this grid.
1514 static bool is_opt_confirm_destroy(object_type *o_ptr)
1516 if (!destroy_items) return FALSE;
1518 /* Known to be worthless? */
1520 if (object_value(o_ptr) > 0) return FALSE;
1523 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1526 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1530 if (object_is_bounty(o_ptr)) return FALSE;
1534 if (o_ptr->tval == TV_CORPSE) return FALSE;
1537 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1541 if (p_ptr->prace == RACE_DEMON)
1543 if (o_ptr->tval == TV_CORPSE &&
1544 o_ptr->sval == SV_CORPSE &&
1545 my_strchr("pht", r_info[o_ptr->pval].d_char))
1549 if (p_ptr->pclass == CLASS_ARCHER)
1551 if (o_ptr->tval == TV_SKELETON ||
1552 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1555 else if (p_ptr->pclass == CLASS_NINJA)
1557 if (o_ptr->tval == TV_LITE &&
1558 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1561 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1562 p_ptr->pclass == CLASS_CAVALRY)
1564 if (o_ptr->tval == TV_WAND &&
1565 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1570 if (o_ptr->tval == TV_GOLD) return FALSE;
1577 * Automatically destroy an item if it is to be destroyed
1579 * When always_pickup is 'yes', we disable auto-destroyer function of
1580 * auto-picker/destroyer, and do only easy-auto-destroyer.
1582 static object_type autopick_last_destroyed_object;
1584 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1586 bool destroy = FALSE;
1588 /* Easy-Auto-Destroyer (3rd priority) */
1589 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1591 /* Protected by auto-picker (2nd priotity) */
1592 if (autopick_idx >= 0 &&
1593 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1596 /* Auto-destroyer works only when !always_pickup */
1599 /* Auto-picker/destroyer (1st priority) */
1600 if (autopick_idx >= 0 &&
1601 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1605 /* Not to be destroyed */
1606 if (!destroy) return;
1608 /* Now decided to destroy */
1610 disturb(p_ptr, FALSE, FALSE);
1613 if (!can_player_destroy_object(o_ptr))
1615 GAME_TEXT o_name[MAX_NLEN];
1617 /* Describe the object (with {terrible/special}) */
1618 object_desc(o_name, o_ptr, 0);
1620 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1625 /* Record name of destroyed item */
1626 (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1629 o_ptr->marked |= OM_AUTODESTROY;
1630 p_ptr->update |= PU_AUTODESTROY;
1635 * Auto-destroy marked item
1637 static void autopick_delayed_alter_aux(player_type *player_ptr, INVENTORY_IDX item)
1640 o_ptr = REF_ITEM(p_ptr, p_ptr->current_floor_ptr, item);
1642 if (o_ptr->k_idx == 0 || !(o_ptr->marked & OM_AUTODESTROY)) return;
1644 GAME_TEXT o_name[MAX_NLEN];
1646 /* Describe the object (with {terrible/special}) */
1647 object_desc(o_name, o_ptr, 0);
1649 /* Eliminate the item (from the pack) */
1652 inven_item_increase(player_ptr, item, -(o_ptr->number));
1653 inven_item_optimize(item);
1656 /* Eliminate the item (from the floor) */
1659 delete_object_idx(player_ptr->current_floor_ptr, 0 - item);
1662 msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name);
1667 * Auto-destroy marked items in inventry and on floor
1669 void autopick_delayed_alter(player_type *owner_ptr)
1674 * Scan inventry in reverse order to prevent
1675 * skipping after inven_item_optimize()
1677 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1678 autopick_delayed_alter_aux(owner_ptr, item);
1680 /* Scan the pile of objects */
1681 item = p_ptr->current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx;
1684 OBJECT_IDX next = p_ptr->current_floor_ptr->o_list[item].next_o_idx;
1685 autopick_delayed_alter_aux(owner_ptr, -item);
1692 * Auto-inscription and/or destroy
1694 * Auto-destroyer works only on inventory or on floor stack only when
1697 void autopick_alter_item(INVENTORY_IDX item, bool destroy)
1702 o_ptr = REF_ITEM(p_ptr, p_ptr->current_floor_ptr, item);
1704 /* Get the index in the auto-pick/destroy list */
1705 idx = is_autopick(o_ptr);
1707 /* Do auto-inscription */
1708 auto_inscribe_item(o_ptr, idx);
1710 /* Do auto-destroy if needed */
1711 if (destroy && item <= INVEN_PACK)
1712 auto_destroy_item(o_ptr, idx);
1717 * Automatically pickup/destroy items in this grid.
1719 void autopick_pickup_items(grid_type *g_ptr)
1721 OBJECT_IDX this_o_idx, next_o_idx = 0;
1723 /* Scan the pile of objects */
1724 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1727 object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
1728 next_o_idx = o_ptr->next_o_idx;
1730 idx = is_autopick(o_ptr);
1732 /* Item index for floor -1,-2,-3,... */
1733 auto_inscribe_item(o_ptr, idx);
1736 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1738 disturb(p_ptr, FALSE, FALSE);
1740 if (!inven_carry_okay(o_ptr))
1742 GAME_TEXT o_name[MAX_NLEN];
1744 object_desc(o_name, o_ptr, 0);
1746 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
1747 /* Hack - remember that the item has given a message here. */
1748 o_ptr->marked |= OM_NOMSG;
1752 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1754 char out_val[MAX_NLEN+20];
1755 GAME_TEXT o_name[MAX_NLEN];
1757 if (o_ptr->marked & OM_NO_QUERY)
1759 /* Already answered as 'No' */
1763 object_desc(o_name, o_ptr, 0);
1765 sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
1767 if (!get_check(out_val))
1769 /* Hack - remember that the item has given a message here. */
1770 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1775 py_pickup_aux(p_ptr, this_o_idx);
1780 * When always_pickup is 'yes', we disable
1781 * auto-destroyer from autopick function, and do only
1782 * easy-auto-destroyer.
1786 auto_destroy_item(o_ptr, idx);
1792 static const char autoregister_header[] = "?:$AUTOREGISTER";
1795 * Clear auto registered lines in the picktype.prf .
1797 static bool clear_auto_register(void)
1799 char tmp_file[1024];
1800 char pref_file[1024];
1805 bool autoregister = FALSE;
1808 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1809 pref_fff = my_fopen(pref_file, "r");
1813 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1814 pref_fff = my_fopen(pref_file, "r");
1823 /* Open a new (temporary) file */
1824 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1828 /* Close the preference file */
1830 msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
1836 /* Loop for every line */
1840 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1844 /* Delete auto-registered line */
1846 /* Count auto-destroy preference lines */
1847 if (buf[0] != '#' && buf[0] != '?') num++;
1850 /* We are looking for auto-registered line */
1853 if (streq(buf, autoregister_header))
1855 /* Delete all further lines */
1856 autoregister = TRUE;
1860 /* Copy orginally lines */
1861 fprintf(tmp_fff, "%s\n", buf);
1867 my_fclose(pref_fff);
1872 msg_format(_("以前のキャラクター用の自動設定(%d行)が残っています。",
1873 "Auto registered lines (%d lines) for previous character are remaining."), num);
1874 strcpy(buf, _("古い設定行は削除します。よろしいですか?", "These lines will be deleted. Are you sure? "));
1876 /* You can cancel it */
1877 if (!get_check(buf))
1880 autoregister = FALSE;
1882 msg_print(_("エディタのカット&ペースト等を使って必要な行を避難してください。",
1883 "Use cut & paste of auto picker editor (_) to keep old prefs."));
1888 /* If there are some changes, overwrite the original file with new one */
1891 /* Copy contents of temporary file */
1893 tmp_fff = my_fopen(tmp_file, "r");
1894 pref_fff = my_fopen(pref_file, "w");
1896 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1897 fprintf(pref_fff, "%s\n", buf);
1899 my_fclose(pref_fff);
1903 /* Kill the temporary file */
1911 * Automatically register an auto-destroy preference line
1913 bool autopick_autoregister(object_type *o_ptr)
1916 char pref_file[1024];
1918 autopick_type an_entry, *entry = &an_entry;
1920 int match_autopick = is_autopick(o_ptr);
1922 /* Already registered */
1923 if (match_autopick != -1)
1926 byte act = autopick_list[match_autopick].action;
1928 if (act & DO_AUTOPICK) what = _("自動で拾う", "auto-pickup");
1929 else if (act & DO_AUTODESTROY) what = _("自動破壊する", "auto-destroy");
1930 else if (act & DONT_AUTOPICK) what = _("放置する", "leave on floor");
1931 else /* if (act & DO_QUERY_AUTOPICK) */ what = _("確認して拾う", "query auto-pickup");
1933 msg_format(_("そのアイテムは既に%sように設定されています。", "The object is already registered to %s."), what);
1937 /* Known to be an artifact? */
1938 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1939 ((o_ptr->ident & IDENT_SENSE) &&
1940 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1942 GAME_TEXT o_name[MAX_NLEN];
1944 /* Describe the object (with {terrible/special}) */
1945 object_desc(o_name, o_ptr, 0);
1947 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1953 if (!p_ptr->autopick_autoregister)
1955 /* Clear old auto registered lines */
1956 if (!clear_auto_register()) return FALSE;
1959 /* Try a filename with player name */
1960 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1961 pref_fff = my_fopen(pref_file, "r");
1965 /* Use default name */
1966 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1967 pref_fff = my_fopen(pref_file, "r");
1970 /* Check the header */
1974 if (my_fgets(pref_fff, buf, sizeof(buf)))
1976 /* No header found */
1977 p_ptr->autopick_autoregister = FALSE;
1982 if (streq(buf, autoregister_header))
1984 /* Found the header */
1985 p_ptr->autopick_autoregister = TRUE;
1991 /* Close read only FILE* */
1994 /* Open for append */
1995 pref_fff = my_fopen(pref_file, "a");
1999 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), pref_file);
2006 if (!p_ptr->autopick_autoregister)
2008 /* Add the header */
2009 fprintf(pref_fff, "%s\n", autoregister_header);
2011 fprintf(pref_fff, "%s\n", _("# *警告!!* 以降の行は自動登録されたものです。",
2012 "# *Waring!* The lines below will be deleated later."));
2013 fprintf(pref_fff, "%s\n", _("# 後で自動的に削除されますので、必要な行は上の方へ移動しておいてください。",
2014 "# Keep it by cut & paste if you need these lines for future characters."));
2016 /* Now auto register is in-use */
2017 p_ptr->autopick_autoregister = TRUE;
2020 /* Get a preference entry */
2021 autopick_entry_from_object(entry, o_ptr);
2023 /* Set to auto-destroy (with no-display) */
2024 entry->action = DO_AUTODESTROY;
2026 /* Load the new line as preference */
2027 add_autopick_list(entry);
2029 /* Add a line to the file */
2030 /* Don't kill "entry" */
2031 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2038 /******** Auto-picker/destroyer editor **********/
2040 #define MAX_YANK MAX_LINELEN
2041 #define MAX_LINES 3000
2043 #define MARK_MARK 0x01
2044 #define MARK_BY_SHIFT 0x02
2046 #define LSTAT_BYPASS 0x01
2047 #define LSTAT_EXPRESSION 0x02
2048 #define LSTAT_AUTOREGISTER 0x04
2050 #define QUIT_WITHOUT_SAVE 1
2051 #define QUIT_AND_SAVE 2
2054 * Struct for yank buffer
2056 typedef struct chain_str {
2057 struct chain_str *next;
2063 * Data struct for text editor
2069 int old_wid, old_hgt;
2071 int old_upper, old_left;
2075 object_type *search_o_ptr;
2077 concptr last_destroyed;
2079 chain_str_type *yank;
2082 concptr *lines_list;
2083 byte states[MAX_LINES];
2095 * Dirty flag for text editor
2097 #define DIRTY_ALL 0x0001
2098 #define DIRTY_MODE 0x0004
2099 #define DIRTY_SCREEN 0x0008
2100 #define DIRTY_NOT_FOUND 0x0010
2101 #define DIRTY_NO_SEARCH 0x0020
2102 #define DIRTY_EXPRESSION 0x0040
2103 #define DIRTY_SKIP_INACTIVE 0x0080
2104 #define DIRTY_INACTIVE 0x0100
2107 * Describe which kind of object is Auto-picked/destroyed
2109 static void describe_autopick(char *buff, autopick_type *entry)
2111 concptr str = entry->name;
2112 byte act = entry->action;
2113 concptr insc = entry->insc;
2119 concptr before_str[100], body_str;
2124 /*** Collecting items ***/
2125 /*** Which can be absorbed into a slot as a bundle ***/
2126 if (IS_FLG(FLG_COLLECTING))
2127 before_str[before_n++] = "収集中で既に持っているスロットにまとめられる";
2129 /*** Unaware items ***/
2130 if (IS_FLG(FLG_UNAWARE))
2131 before_str[before_n++] = "未鑑定でその効果も判明していない";
2133 /*** Unidentified ***/
2134 if (IS_FLG(FLG_UNIDENTIFIED))
2135 before_str[before_n++] = "未鑑定の";
2137 /*** Identified ***/
2138 if (IS_FLG(FLG_IDENTIFIED))
2139 before_str[before_n++] = "鑑定済みの";
2141 /*** *Identified* ***/
2142 if (IS_FLG(FLG_STAR_IDENTIFIED))
2143 before_str[before_n++] = "完全に鑑定済みの";
2145 /*** Dice boosted (weapon of slaying) ***/
2146 if (IS_FLG(FLG_BOOSTED))
2148 before_str[before_n++] = "ダメージダイスが通常より大きい";
2152 /*** Weapons whose dd*ds is more than nn ***/
2153 if (IS_FLG(FLG_MORE_DICE))
2155 static char more_than_desc_str[] = "___";
2156 before_str[before_n++] = "ダメージダイスの最大値が";
2159 sprintf(more_than_desc_str,"%d", entry->dice);
2160 before_str[before_n++] = more_than_desc_str;
2161 before_str[before_n++] = "以上の";
2164 /*** Items whose magical bonus is more than nn ***/
2165 if (IS_FLG(FLG_MORE_BONUS))
2167 static char more_bonus_desc_str[] = "___";
2168 before_str[before_n++] = "修正値が(+";
2170 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2171 before_str[before_n++] = more_bonus_desc_str;
2172 before_str[before_n++] = ")以上の";
2175 /*** Worthless items ***/
2176 if (IS_FLG(FLG_WORTHLESS))
2177 before_str[before_n++] = "店で無価値と判定される";
2180 if (IS_FLG(FLG_ARTIFACT))
2182 before_str[before_n++] = "アーティファクトの";
2187 if (IS_FLG(FLG_EGO))
2189 before_str[before_n++] = "エゴアイテムの";
2194 if (IS_FLG(FLG_GOOD))
2196 before_str[before_n++] = "上質の";
2201 if (IS_FLG(FLG_NAMELESS))
2203 before_str[before_n++] = "エゴでもアーティファクトでもない";
2208 if (IS_FLG(FLG_AVERAGE))
2210 before_str[before_n++] = "並の";
2214 /*** Rare equipments ***/
2215 if (IS_FLG(FLG_RARE))
2217 before_str[before_n++] = "ドラゴン装備やカオス・ブレード等を含む珍しい";
2221 /*** Common equipments ***/
2222 if (IS_FLG(FLG_COMMON))
2224 before_str[before_n++] = "ありふれた(ドラゴン装備やカオス・ブレード等の珍しい物ではない)";
2228 /*** Wanted monster's corpse/skeletons ***/
2229 if (IS_FLG(FLG_WANTED))
2231 before_str[before_n++] = "ハンター事務所で賞金首とされている";
2235 /*** Human corpse/skeletons (for Daemon magic) ***/
2236 if (IS_FLG(FLG_HUMAN))
2238 before_str[before_n++] = "悪魔魔法で使うための人間やヒューマノイドの";
2242 /*** Unique monster's corpse/skeletons/statues ***/
2243 if (IS_FLG(FLG_UNIQUE))
2245 before_str[before_n++] = "ユニークモンスターの";
2249 /*** Unreadable spellbooks ***/
2250 if (IS_FLG(FLG_UNREADABLE))
2252 before_str[before_n++] = "あなたが読めない領域の";
2256 /*** First realm spellbooks ***/
2257 if (IS_FLG(FLG_REALM1))
2259 before_str[before_n++] = "第一領域の";
2263 /*** Second realm spellbooks ***/
2264 if (IS_FLG(FLG_REALM2))
2266 before_str[before_n++] = "第二領域の";
2270 /*** First rank spellbooks ***/
2271 if (IS_FLG(FLG_FIRST))
2273 before_str[before_n++] = "全4冊の内の1冊目の";
2277 /*** Second rank spellbooks ***/
2278 if (IS_FLG(FLG_SECOND))
2280 before_str[before_n++] = "全4冊の内の2冊目の";
2284 /*** Third rank spellbooks ***/
2285 if (IS_FLG(FLG_THIRD))
2287 before_str[before_n++] = "全4冊の内の3冊目の";
2291 /*** Fourth rank spellbooks ***/
2292 if (IS_FLG(FLG_FOURTH))
2294 before_str[before_n++] = "全4冊の内の4冊目の";
2299 if (IS_FLG(FLG_ITEMS))
2300 ; /* Nothing to do */
2301 else if (IS_FLG(FLG_WEAPONS))
2303 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2305 else if (IS_FLG(FLG_ARMORS))
2307 else if (IS_FLG(FLG_MISSILES))
2308 body_str = "弾や矢やクロスボウの矢";
2309 else if (IS_FLG(FLG_DEVICES))
2310 body_str = "巻物や魔法棒や杖やロッド";
2311 else if (IS_FLG(FLG_LIGHTS))
2312 body_str = "光源用のアイテム";
2313 else if (IS_FLG(FLG_JUNKS))
2314 body_str = "折れた棒等のガラクタ";
2315 else if (IS_FLG(FLG_CORPSES))
2317 else if (IS_FLG(FLG_SPELLBOOKS))
2319 else if (IS_FLG(FLG_HAFTED))
2321 else if (IS_FLG(FLG_SHIELDS))
2323 else if (IS_FLG(FLG_BOWS))
2324 body_str = "スリングや弓やクロスボウ";
2325 else if (IS_FLG(FLG_RINGS))
2327 else if (IS_FLG(FLG_AMULETS))
2328 body_str = "アミュレット";
2329 else if (IS_FLG(FLG_SUITS))
2331 else if (IS_FLG(FLG_CLOAKS))
2333 else if (IS_FLG(FLG_HELMS))
2334 body_str = "ヘルメットや冠";
2335 else if (IS_FLG(FLG_GLOVES))
2337 else if (IS_FLG(FLG_BOOTS))
2342 strcat(buff, "全ての");
2343 else for (i = 0; i < before_n && before_str[i]; i++)
2344 strcat(buff, before_str[i]);
2346 strcat(buff, body_str);
2356 strcat(buff, "で、名前が「");
2357 strncat(buff, str, 80);
2359 strcat(buff, "」で始まるもの");
2361 strcat(buff, "」を含むもの");
2366 strncat(buff, format("に「%s」", insc), 80);
2368 if (my_strstr(insc, "%%all"))
2369 strcat(buff, "(%%allは全能力を表す英字の記号で置換)");
2370 else if (my_strstr(insc, "%all"))
2371 strcat(buff, "(%allは全能力を表す記号で置換)");
2372 else if (my_strstr(insc, "%%"))
2373 strcat(buff, "(%%は追加能力を表す英字の記号で置換)");
2374 else if (my_strstr(insc, "%"))
2375 strcat(buff, "(%は追加能力を表す記号で置換)");
2377 strcat(buff, "と刻んで");
2382 if (act & DONT_AUTOPICK)
2383 strcat(buff, "放置する。");
2384 else if (act & DO_AUTODESTROY)
2385 strcat(buff, "破壊する。");
2386 else if (act & DO_QUERY_AUTOPICK)
2387 strcat(buff, "確認の後に拾う。");
2389 strcat(buff, "拾う。");
2391 if (act & DO_DISPLAY)
2393 if (act & DONT_AUTOPICK)
2394 strcat(buff, "全体マップ('M')で'N'を押したときに表示する。");
2395 else if (act & DO_AUTODESTROY)
2396 strcat(buff, "全体マップ('M')で'K'を押したときに表示する。");
2398 strcat(buff, "全体マップ('M')で'M'を押したときに表示する。");
2401 strcat(buff, "全体マップには表示しない。");
2405 concptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2406 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2410 /*** Collecting items ***/
2411 /*** Which can be absorbed into a slot as a bundle ***/
2412 if (IS_FLG(FLG_COLLECTING))
2413 which_str[which_n++] = "can be absorbed into an existing p_ptr->inventory_list slot";
2415 /*** Unaware items ***/
2416 if (IS_FLG(FLG_UNAWARE))
2418 before_str[before_n++] = "unidentified";
2419 whose_str[whose_n++] = "basic abilities are not known";
2422 /*** Unidentified ***/
2423 if (IS_FLG(FLG_UNIDENTIFIED))
2424 before_str[before_n++] = "unidentified";
2426 /*** Identified ***/
2427 if (IS_FLG(FLG_IDENTIFIED))
2428 before_str[before_n++] = "identified";
2430 /*** *Identified* ***/
2431 if (IS_FLG(FLG_STAR_IDENTIFIED))
2432 before_str[before_n++] = "fully identified";
2434 /*** Rare equipments ***/
2435 if (IS_FLG(FLG_RARE))
2437 before_str[before_n++] = "very rare";
2438 body_str = "equipments";
2439 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2442 /*** Common equipments ***/
2443 if (IS_FLG(FLG_COMMON))
2445 before_str[before_n++] = "relatively common";
2446 body_str = "equipments";
2447 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2450 /*** Worthless items ***/
2451 if (IS_FLG(FLG_WORTHLESS))
2453 before_str[before_n++] = "worthless";
2454 which_str[which_n++] = "can not be sold at stores";
2458 if (IS_FLG(FLG_ARTIFACT))
2460 before_str[before_n++] = "artifact";
2464 if (IS_FLG(FLG_EGO))
2466 before_str[before_n++] = "ego";
2470 if (IS_FLG(FLG_GOOD))
2472 body_str = "equipment";
2473 which_str[which_n++] = "have good quality";
2477 if (IS_FLG(FLG_NAMELESS))
2479 body_str = "equipment";
2480 which_str[which_n++] = "is neither ego-item nor artifact";
2484 if (IS_FLG(FLG_AVERAGE))
2486 body_str = "equipment";
2487 which_str[which_n++] = "have average quality";
2490 /*** Dice boosted (weapon of slaying) ***/
2491 if (IS_FLG(FLG_BOOSTED))
2493 body_str = "weapons";
2494 whose_str[whose_n++] = "damage dice is bigger than normal";
2497 /*** Weapons whose dd*ds is more than nn ***/
2498 if (IS_FLG(FLG_MORE_DICE))
2500 static char more_than_desc_str[] =
2501 "maximum damage from dice is bigger than __";
2502 body_str = "weapons";
2504 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2506 whose_str[whose_n++] = more_than_desc_str;
2509 /*** Items whose magical bonus is more than nn ***/
2510 if (IS_FLG(FLG_MORE_BONUS))
2512 static char more_bonus_desc_str[] =
2513 "magical bonus is bigger than (+__)";
2515 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2516 "%d)", entry->bonus);
2517 whose_str[whose_n++] = more_bonus_desc_str;
2520 /*** Wanted monster's corpse/skeletons ***/
2521 if (IS_FLG(FLG_WANTED))
2523 body_str = "corpse or skeletons";
2524 which_str[which_n++] = "is wanted at the Hunter's Office";
2527 /*** Human corpse/skeletons (for Daemon magic) ***/
2528 if (IS_FLG(FLG_HUMAN))
2530 before_str[before_n++] = "humanoid";
2531 body_str = "corpse or skeletons";
2532 which_str[which_n++] = "can be used for Daemon magic";
2535 /*** Unique monster's corpse/skeletons/statues ***/
2536 if (IS_FLG(FLG_UNIQUE))
2538 before_str[before_n++] = "unique monster's";
2539 body_str = "corpse or skeletons";
2542 /*** Unreadable spellbooks ***/
2543 if (IS_FLG(FLG_UNREADABLE))
2545 body_str = "spellbooks";
2546 after_str[after_n++] = "of different realms from yours";
2549 /*** First realm spellbooks ***/
2550 if (IS_FLG(FLG_REALM1))
2552 body_str = "spellbooks";
2553 after_str[after_n++] = "of your first realm";
2556 /*** Second realm spellbooks ***/
2557 if (IS_FLG(FLG_REALM2))
2559 body_str = "spellbooks";
2560 after_str[after_n++] = "of your second realm";
2563 /*** First rank spellbooks ***/
2564 if (IS_FLG(FLG_FIRST))
2566 before_str[before_n++] = "first one of four";
2567 body_str = "spellbooks";
2570 /*** Second rank spellbooks ***/
2571 if (IS_FLG(FLG_SECOND))
2573 before_str[before_n++] = "second one of four";
2574 body_str = "spellbooks";
2577 /*** Third rank spellbooks ***/
2578 if (IS_FLG(FLG_THIRD))
2580 before_str[before_n++] = "third one of four";
2581 body_str = "spellbooks";
2584 /*** Fourth rank spellbooks ***/
2585 if (IS_FLG(FLG_FOURTH))
2587 before_str[before_n++] = "fourth one of four";
2588 body_str = "spellbooks";
2592 if (IS_FLG(FLG_ITEMS))
2593 ; /* Nothing to do */
2594 else if (IS_FLG(FLG_WEAPONS))
2595 body_str = "weapons";
2596 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2597 body_str = "favorite weapons";
2598 else if (IS_FLG(FLG_ARMORS))
2599 body_str = "armors";
2600 else if (IS_FLG(FLG_MISSILES))
2601 body_str = "shots, arrows or crossbow bolts";
2602 else if (IS_FLG(FLG_DEVICES))
2603 body_str = "scrolls, wands, staves or rods";
2604 else if (IS_FLG(FLG_LIGHTS))
2605 body_str = "light sources";
2606 else if (IS_FLG(FLG_JUNKS))
2607 body_str = "junk such as broken sticks";
2608 else if (IS_FLG(FLG_CORPSES))
2609 body_str = "corpses or skeletons";
2610 else if (IS_FLG(FLG_SPELLBOOKS))
2611 body_str = "spellbooks";
2612 else if (IS_FLG(FLG_HAFTED))
2613 body_str = "hafted weapons";
2614 else if (IS_FLG(FLG_SHIELDS))
2615 body_str = "shields";
2616 else if (IS_FLG(FLG_BOWS))
2617 body_str = "slings, bows or crossbows";
2618 else if (IS_FLG(FLG_RINGS))
2620 else if (IS_FLG(FLG_AMULETS))
2621 body_str = "amulets";
2622 else if (IS_FLG(FLG_SUITS))
2623 body_str = "body armors";
2624 else if (IS_FLG(FLG_CLOAKS))
2625 body_str = "cloaks";
2626 else if (IS_FLG(FLG_HELMS))
2627 body_str = "helms or crowns";
2628 else if (IS_FLG(FLG_GLOVES))
2629 body_str = "gloves";
2630 else if (IS_FLG(FLG_BOOTS))
2633 /* Prepare a string for item name */
2640 whose_str[whose_n++] = "name is beginning with \"";
2643 which_str[which_n++] = "have \"";
2647 /* Describe action flag */
2648 if (act & DONT_AUTOPICK)
2649 strcpy(buff, "Leave on floor ");
2650 else if (act & DO_AUTODESTROY)
2651 strcpy(buff, "Destroy ");
2652 else if (act & DO_QUERY_AUTOPICK)
2653 strcpy(buff, "Ask to pick up ");
2655 strcpy(buff, "Pickup ");
2657 /* Auto-insctiption */
2660 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2662 if (my_strstr(insc, "%all"))
2663 strcat(buff, ", replacing %all with code string representing all abilities,");
2664 else if (my_strstr(insc, "%"))
2665 strcat(buff, ", replacing % with code string representing extra random abilities,");
2667 strcat(buff, " on ");
2672 strcat(buff, "all ");
2673 else for (i = 0; i < before_n && before_str[i]; i++)
2675 strcat(buff, before_str[i]);
2680 strcat(buff, body_str);
2683 for (i = 0; i < after_n && after_str[i]; i++)
2686 strcat(buff, after_str[i]);
2690 for (i = 0; i < whose_n && whose_str[i]; i++)
2693 strcat(buff, " whose ");
2695 strcat(buff, ", and ");
2697 strcat(buff, whose_str[i]);
2700 /* Item name ; whose name is beginning with "str" */
2707 /* whose ..., and which .... */
2708 if (whose_n && which_n)
2709 strcat(buff, ", and ");
2712 for (i = 0; i < which_n && which_str[i]; i++)
2715 strcat(buff, " which ");
2717 strcat(buff, ", and ");
2719 strcat(buff, which_str[i]);
2722 /* Item name ; which have "str" as part of its name */
2725 strncat(buff, str, 80);
2726 strcat(buff, "\" as part of its name");
2730 /* Describe whether it will be displayed on the full map or not */
2731 if (act & DO_DISPLAY)
2733 if (act & DONT_AUTOPICK)
2734 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2735 else if (act & DO_AUTODESTROY)
2736 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2738 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2741 strcat(buff, " Not displayed in the full map.");
2748 * Read whole lines of a file to memory
2750 static concptr *read_text_lines(concptr filename)
2752 concptr *lines_list = NULL;
2758 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2759 fff = my_fopen(buf, "r");
2763 /* Allocate list of pointers */
2764 C_MAKE(lines_list, MAX_LINES, concptr);
2767 while (0 == my_fgets(fff, buf, sizeof(buf)))
2769 lines_list[lines++] = string_make(buf);
2770 if (lines >= MAX_LINES - 1) break;
2773 lines_list[0] = string_make("");
2778 if (!fff) return NULL;
2784 * Copy the default autopick file to the user directory
2786 static void prepare_default_pickpref(void)
2788 const concptr messages[] = {
2789 _("あなたは「自動拾いエディタ」を初めて起動しました。", "You have activated the Auto-Picker Editor for the first time."),
2790 _("自動拾いのユーザー設定ファイルがまだ書かれていないので、", "Since user pref file for autopick is not yet created,"),
2791 _("基本的な自動拾い設定ファイルをlib/pref/picktype.prfからコピーします。", "the default setting is loaded from lib/pref/pickpref.prf ."),
2799 concptr filename = pickpref_filename(PT_DEFAULT);
2801 /* Display messages */
2802 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2807 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2808 user_fp = my_fopen(buf, "w");
2811 if (!user_fp) return;
2813 /* Write header messages for a notification */
2814 fprintf(user_fp, "#***\n");
2815 for (i = 0; messages[i]; i++)
2817 fprintf(user_fp, "#*** %s\n", messages[i]);
2819 fprintf(user_fp, "#***\n\n\n");
2822 /* Open the default file */
2823 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2824 pref_fp = my_fopen(buf, "r");
2833 /* Copy the contents of default file */
2834 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2835 fprintf(user_fp, "%s\n", buf);
2842 * Read an autopick prefence file to memory
2843 * Prepare default if no user file is found
2845 static concptr *read_pickpref_text_lines(int *filename_mode_p)
2848 concptr *lines_list;
2850 /* Try a filename with player name */
2851 *filename_mode_p = PT_WITH_PNAME;
2852 strcpy(buf, pickpref_filename(*filename_mode_p));
2853 lines_list = read_text_lines(buf);
2857 /* Use default name */
2858 *filename_mode_p = PT_DEFAULT;
2859 strcpy(buf, pickpref_filename(*filename_mode_p));
2860 lines_list = read_text_lines(buf);
2865 /* There is no preference file in the user directory */
2867 /* Copy the default autopick file to the user directory */
2868 prepare_default_pickpref();
2870 /* Use default name again */
2871 lines_list = read_text_lines(buf);
2876 /* Allocate list of pointers */
2877 C_MAKE(lines_list, MAX_LINES, concptr);
2878 lines_list[0] = string_make("");
2885 * Write whole lines of memory to a file.
2887 static bool write_text_lines(concptr filename, concptr *lines_list)
2893 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2894 fff = my_fopen(buf, "w");
2897 for (lines = 0; lines_list[lines]; lines++)
2898 my_fputs(fff, lines_list[lines], 1024);
2903 if (!fff) return FALSE;
2909 * Free memory of lines_list.
2911 static void free_text_lines(concptr *lines_list)
2915 for (lines = 0; lines_list[lines]; lines++)
2916 string_free(lines_list[lines]);
2918 /* free list of pointers */
2919 C_KILL(lines_list, MAX_LINES, concptr);
2924 * Delete or insert string
2926 static void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
2932 /* Some lines are selected */
2935 by1 = MIN(tb->my, tb->cy);
2936 by2 = MAX(tb->my, tb->cy);
2939 /* No mark -- Select current line */
2940 else /* if (!tb->mark) */
2946 /* Set/Reset flag of each line */
2947 for (y = by1; y <= by2; y++)
2949 autopick_type an_entry, *entry = &an_entry;
2951 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2953 string_free(tb->lines_list[y]);
2957 /* Add? or Remove? */
2958 if (!IS_FLG(flg)) add = TRUE;
2961 /* No more change */
2965 /* You can use only one noun flag */
2966 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2969 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2973 /* You can use only one identify state flag */
2974 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2977 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2981 /* You can use only one flag in artifact/ego/nameless */
2982 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
2985 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
2989 /* You can use only one flag in rare/common */
2990 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
2993 for (i = FLG_RARE; i <= FLG_COMMON; i++)
2997 if (add) ADD_FLG(flg);
3000 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3003 tb->dirty_flags |= DIRTY_ALL;
3005 /* Text is changed */
3012 * Change command letter
3014 static void toggle_command_letter(text_body_type *tb, byte flg)
3016 autopick_type an_entry, *entry = &an_entry;
3021 /* Some lines are selected */
3024 by1 = MIN(tb->my, tb->cy);
3025 by2 = MAX(tb->my, tb->cy);
3028 /* No mark -- Select current line */
3029 else /* if (!tb->mark) */
3035 /* Set/Reset flag of each line */
3036 for (y = by1; y <= by2; y++)
3040 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3042 string_free(tb->lines_list[y]);
3046 /* Add? or Remove? */
3047 if (!(entry->action & flg)) add = TRUE;
3050 /* No more change */
3054 /* Count number of letter (by negative number) */
3055 if (entry->action & DONT_AUTOPICK) wid--;
3056 else if (entry->action & DO_AUTODESTROY) wid--;
3057 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3058 if (!(entry->action & DO_DISPLAY)) wid--;
3060 /* Set/Reset the flag */
3061 if (flg != DO_DISPLAY)
3063 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3064 if (add) entry->action |= flg;
3065 else entry->action |= DO_AUTOPICK;
3069 entry->action &= ~(DO_DISPLAY);
3070 if (add) entry->action |= flg;
3073 /* Correct cursor location */
3076 if (entry->action & DONT_AUTOPICK) wid++;
3077 else if (entry->action & DO_AUTODESTROY) wid++;
3078 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3079 if (!(entry->action & DO_DISPLAY)) wid++;
3081 if (wid > 0) tb->cx++;
3082 if (wid < 0 && tb->cx > 0) tb->cx--;
3085 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3088 tb->dirty_flags |= DIRTY_ALL;
3090 /* Text is changed */
3096 * Delete or insert string
3098 static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
3102 /* Some lines are selected */
3105 by1 = MIN(tb->my, tb->cy);
3106 by2 = MAX(tb->my, tb->cy);
3109 /* No mark -- Select current line */
3110 else /* if (!tb->mark) */
3116 /* Set/Reset flag of each line */
3117 for (y = by1; y <= by2; y++)
3119 autopick_type an_entry, *entry = &an_entry;
3121 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3123 /* There is the flag already */
3126 /* Free memory for the entry */
3127 autopick_free_entry(entry);
3132 string_free(tb->lines_list[y]);
3134 /* Remove all noun flag */
3135 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3138 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3144 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3147 tb->dirty_flags |= DIRTY_ALL;
3149 /* Text is changed */
3156 * Check if this line is expression or not.
3157 * And update it if it is.
3159 static void check_expression_line(text_body_type *tb, int y)
3161 concptr s = tb->lines_list[y];
3163 if ((s[0] == '?' && s[1] == ':') ||
3164 (tb->states[y] & LSTAT_BYPASS))
3166 /* Expressions need re-evaluation */
3167 tb->dirty_flags |= DIRTY_EXPRESSION;
3173 * Add an empty line at the last of the file
3175 static bool add_empty_line(text_body_type *tb)
3179 for (k = 0; tb->lines_list[k]; k++)
3180 /* count number of lines */ ;
3182 /* Too many lines! */
3183 if (k >= MAX_LINES - 2) return FALSE;
3185 /* The last line is already empty */
3186 if (!tb->lines_list[k-1][0]) return FALSE;
3188 /* Create new empty line */
3189 tb->lines_list[k] = string_make("");
3191 /* Expressions need re-evaluation */
3192 tb->dirty_flags |= DIRTY_EXPRESSION;
3194 /* Text is changed */
3197 /* A line is added */
3203 * Insert return code and split the line
3205 static bool insert_return_code(text_body_type *tb)
3207 char buf[MAX_LINELEN];
3210 for (k = 0; tb->lines_list[k]; k++)
3211 /* count number of lines */ ;
3213 if (k >= MAX_LINES - 2) return FALSE;
3216 /* Move down lines */
3217 for (; tb->cy < k; k--)
3219 tb->lines_list[k+1] = tb->lines_list[k];
3220 tb->states[k+1] = tb->states[k];
3223 /* Split current line */
3224 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3227 if (iskanji(tb->lines_list[tb->cy][i]))
3228 buf[j++] = tb->lines_list[tb->cy][i++];
3230 buf[j++] = tb->lines_list[tb->cy][i];
3233 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3234 string_free(tb->lines_list[tb->cy]);
3235 tb->lines_list[tb->cy] = string_make(buf);
3237 /* Expressions need re-evaluation */
3238 tb->dirty_flags |= DIRTY_EXPRESSION;
3240 /* Text is changed */
3248 * Choose an item and get auto-picker entry from it.
3250 static bool entry_from_choosed_object(autopick_type *entry)
3255 q = _("どのアイテムを登録しますか? ", "Enter which item? ");
3256 s = _("アイテムを持っていない。", "You have nothing to enter.");
3257 o_ptr = choose_object(p_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
3258 if (!o_ptr) return FALSE;
3260 autopick_entry_from_object(entry, o_ptr);
3266 * Choose an item for search
3268 static byte get_object_for_search(object_type **o_handle, concptr *search_strp)
3270 char buf[MAX_NLEN+20];
3274 q = _("どのアイテムを検索しますか? ", "Enter which item? ");
3275 s = _("アイテムを持っていない。", "You have nothing to enter.");
3276 o_ptr = choose_object(p_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
3277 if (!o_ptr) return 0;
3281 string_free(*search_strp);
3282 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3283 *search_strp = string_make(format("<%s>", buf));
3289 * Prepare for search by destroyed object
3291 static byte get_destroyed_object_for_search(object_type **o_handle, concptr *search_strp)
3293 char buf[MAX_NLEN+20];
3295 if (!autopick_last_destroyed_object.k_idx) return 0;
3297 *o_handle = &autopick_last_destroyed_object;
3299 string_free(*search_strp);
3300 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3301 *search_strp = string_make(format("<%s>", buf));
3307 * Choose an item or string for search
3309 static byte get_string_for_search(object_type **o_handle, concptr *search_strp)
3315 * TERM_YELLOW : Overwrite mode
3316 * TERM_WHITE : Insert mode
3318 byte color = TERM_YELLOW;
3319 char buf[MAX_NLEN+20];
3322 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
3323 int col = sizeof(prompt) - 1;
3325 /* Prepare string buffer for edit */
3326 if (*search_strp) strcpy(buf, *search_strp);
3329 /* Object searching mode */
3332 color = TERM_L_GREEN;
3335 /* Display prompt */
3345 /* Display the string */
3346 Term_erase(col, 0, 255);
3347 Term_putstr(col, 0, -1, color, buf);
3350 Term_gotoxy(col + pos, 0);
3352 /* Get a special key code */
3353 skey = inkey_special(TRUE);
3355 /* Analyze the key */
3363 /* Now on insert mode */
3366 /* No move at beginning of line */
3367 if (0 == pos) break;
3371 int next_pos = i + 1;
3374 if (iskanji(buf[i])) next_pos++;
3377 /* Is there the cursor at next position? */
3378 if (next_pos >= pos) break;
3384 /* Get previous position */
3392 /* Now on insert mode */
3395 /* No move at end of line */
3396 if ('\0' == buf[pos]) break;
3400 if (iskanji(buf[pos])) pos += 2;
3418 if (*o_handle) return (back ? -1 : 1);
3419 string_free(*search_strp);
3420 *search_strp = string_make(buf);
3422 return (back ? -1 : 1);
3425 return get_object_for_search(o_handle, search_strp);
3428 /* Prepare string for destroyed object if there is one. */
3429 if (get_destroyed_object_for_search(o_handle, search_strp))
3439 /* Now on insert mode */
3442 /* No move at beginning of line */
3443 if (0 == pos) break;
3447 int next_pos = i + 1;
3450 if (iskanji(buf[i])) next_pos++;
3453 /* Is there the cursor at next position? */
3454 if (next_pos >= pos) break;
3460 /* Get previous position */
3463 /* Fall through to 'Delete key' */
3472 /* Now on insert mode */
3475 /* No move at end of line */
3476 if ('\0' == buf[pos]) break;
3478 /* Position of next character */
3482 /* Next character is one more byte away */
3483 if (iskanji(buf[pos])) src++;
3488 /* Move characters at src to dst */
3489 while ('\0' != (buf[dst++] = buf[src++]))
3497 /* Insert a character */
3502 /* Ignore special keys */
3503 if (skey & SKEY_MASK) break;
3505 /* Get a character code */
3508 /* Was non insert mode? */
3509 if (color != TERM_WHITE)
3511 /* Was object searching mode */
3512 if (color == TERM_L_GREEN)
3514 /* Cancel the mode */
3517 /* Remove indicating string */
3518 string_free(*search_strp);
3519 *search_strp = NULL;
3522 /* Overwrite default string */
3525 /* Go to insert mode */
3529 /* Save right part of string */
3530 strcpy(tmp, buf + pos);
3536 /* Bypass macro processing */
3554 if (pos < len && (isprint(c) || iskana(c)))
3556 if (pos < len && isprint(c))
3570 /* Write back the left part of string */
3571 my_strcat(buf, tmp, len + 1);
3578 /* Object searching mode was cancelled? */
3579 if (*o_handle && color != TERM_L_GREEN)
3581 /* Cancel the mode */
3584 /* Remove indicating string */
3586 string_free(*search_strp);
3587 *search_strp = NULL;
3592 } /* while (TRUE) */
3597 * Search next line matches for o_ptr
3599 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3601 autopick_type an_entry, *entry = &an_entry;
3602 GAME_TEXT o_name[MAX_NLEN];
3603 int bypassed_cy = -1;
3605 /* Start searching from current cursor position */
3608 /* Prepare object name string first */
3609 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3611 /* Convert the string to lower case */
3612 str_tolower(o_name);
3621 if (!tb->lines_list[++i]) break;
3628 /* Is this line is a correct entry? */
3629 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3631 /* Does this line match to the object? */
3632 match = is_autopick_aux(o_ptr, entry, o_name);
3633 autopick_free_entry(entry);
3634 if (!match) continue;
3636 /* Found a line but it's inactive */
3637 if (tb->states[i] & LSTAT_BYPASS)
3639 /* If it is first found, remember it */
3640 if (bypassed_cy == -1) bypassed_cy = i;
3643 /* Found an active line! */
3646 /* Move to this line */
3650 if (bypassed_cy != -1)
3652 /* Mark as some lines are skipped */
3653 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3661 if (bypassed_cy != -1)
3663 /* Move to the remembered line */
3665 tb->cy = bypassed_cy;
3667 /* Mark as this line is inactive */
3668 tb->dirty_flags |= DIRTY_INACTIVE;
3673 /* Mark as NOT FOUND */
3674 tb->dirty_flags |= DIRTY_NOT_FOUND;
3682 * Search next line matches to the string
3684 static void search_for_string(text_body_type *tb, concptr search_str, bool forward)
3686 int bypassed_cy = -1;
3687 int bypassed_cx = 0;
3689 /* Start searching from current cursor position */
3699 if (!tb->lines_list[++i]) break;
3706 /* Look for the string pattern */
3707 pos = my_strstr(tb->lines_list[i], search_str);
3712 /* Found a line but it's inactive */
3713 if ((tb->states[i] & LSTAT_BYPASS) &&
3714 !(tb->states[i] & LSTAT_EXPRESSION))
3716 /* If it is first found, remember it */
3717 if (bypassed_cy == -1)
3720 bypassed_cx = (int)(pos - tb->lines_list[i]);
3724 /* Found an active line! */
3727 /* Move to this location */
3728 tb->cx = (int)(pos - tb->lines_list[i]);
3731 if (bypassed_cy != -1)
3733 /* Mark as some lines are skipped */
3734 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3742 if (bypassed_cy != -1)
3744 /* Move to the remembered line */
3745 tb->cx = bypassed_cx;
3746 tb->cy = bypassed_cy;
3748 /* Mark as this line is inactive */
3749 tb->dirty_flags |= DIRTY_INACTIVE;
3754 /* Mark as NOT FOUND */
3755 tb->dirty_flags |= DIRTY_NOT_FOUND;
3765 * Editor command id's
3768 #define EC_SAVEQUIT 2
3779 #define EC_PGDOWN 13
3781 #define EC_BOTTOM 15
3786 #define EC_KILL_LINE 20
3787 #define EC_DELETE_CHAR 21
3788 #define EC_BACKSPACE 22
3789 #define EC_SEARCH_STR 23
3790 #define EC_SEARCH_FORW 24
3791 #define EC_SEARCH_BACK 25
3792 #define EC_SEARCH_OBJ 26
3793 #define EC_SEARCH_DESTROYED 27
3794 #define EC_INSERT_OBJECT 28
3795 #define EC_INSERT_DESTROYED 29
3796 #define EC_INSERT_BLOCK 30
3797 #define EC_INSERT_MACRO 31
3798 #define EC_INSERT_KEYMAP 32
3799 #define EC_CL_AUTOPICK 33
3800 #define EC_CL_DESTROY 34
3801 #define EC_CL_LEAVE 35
3802 #define EC_CL_QUERY 36
3803 #define EC_CL_NO_DISP 37
3804 #define EC_OK_COLLECTING 38
3805 #define EC_IK_UNAWARE 39
3806 #define EC_IK_UNIDENTIFIED 40
3807 #define EC_IK_IDENTIFIED 41
3808 #define EC_IK_STAR_IDENTIFIED 42
3809 #define EC_OK_BOOSTED 43
3810 #define EC_OK_MORE_DICE 44
3811 #define EC_OK_MORE_BONUS 45
3812 #define EC_OK_WORTHLESS 46
3813 #define EC_OK_ARTIFACT 47
3814 #define EC_OK_EGO 48
3815 #define EC_OK_GOOD 49
3816 #define EC_OK_NAMELESS 50
3817 #define EC_OK_AVERAGE 51
3818 #define EC_OK_RARE 52
3819 #define EC_OK_COMMON 53
3820 #define EC_OK_WANTED 54
3821 #define EC_OK_UNIQUE 55
3822 #define EC_OK_HUMAN 56
3823 #define EC_OK_UNREADABLE 57
3824 #define EC_OK_REALM1 58
3825 #define EC_OK_REALM2 59
3826 #define EC_OK_FIRST 60
3827 #define EC_OK_SECOND 61
3828 #define EC_OK_THIRD 62
3829 #define EC_OK_FOURTH 63
3830 #define EC_KK_WEAPONS 64
3831 #define EC_KK_FAVORITE_WEAPONS 65
3832 #define EC_KK_ARMORS 66
3833 #define EC_KK_MISSILES 67
3834 #define EC_KK_DEVICES 68
3835 #define EC_KK_LIGHTS 69
3836 #define EC_KK_JUNKS 70
3837 #define EC_KK_CORPSES 71
3838 #define EC_KK_SPELLBOOKS 72
3839 #define EC_KK_SHIELDS 73
3840 #define EC_KK_BOWS 74
3841 #define EC_KK_RINGS 75
3842 #define EC_KK_AMULETS 76
3843 #define EC_KK_SUITS 77
3844 #define EC_KK_CLOAKS 78
3845 #define EC_KK_HELMS 79
3846 #define EC_KK_GLOVES 80
3847 #define EC_KK_BOOTS 81
3853 static GAME_TEXT MN_QUIT[] = "セーブ無しで終了";
3854 static GAME_TEXT MN_SAVEQUIT[] = "セーブして終了";
3855 static GAME_TEXT MN_REVERT[] = "全ての変更を破棄";
3856 static GAME_TEXT MN_HELP[] = "ヘルプ";
3858 static GAME_TEXT MN_MOVE[] = "カーソル移動";
3859 static GAME_TEXT MN_LEFT[] = "左 (←矢印キー)";
3860 static GAME_TEXT MN_DOWN[] = "下 (↓矢印キー)";
3861 static GAME_TEXT MN_UP[] = "上 (↑矢印キー)";
3862 static GAME_TEXT MN_RIGHT[] = "右 (→矢印キー)";
3863 static GAME_TEXT MN_BOL[] = "行の先頭";
3864 static GAME_TEXT MN_EOL[] = "行の終端";
3865 static GAME_TEXT MN_PGUP[] = "上のページ (PageUpキー)";
3866 static GAME_TEXT MN_PGDOWN[] = "下のページ (PageDownキー)";
3867 static GAME_TEXT MN_TOP[] = "1行目へ移動 (Homeキー)";
3868 static GAME_TEXT MN_BOTTOM[] = "最下行へ移動(Endキー)";
3870 static GAME_TEXT MN_EDIT[] = "編集";
3871 static GAME_TEXT MN_CUT[] = "カット";
3872 static GAME_TEXT MN_COPY[] = "コピー";
3873 static GAME_TEXT MN_PASTE[] = "ペースト";
3874 static GAME_TEXT MN_BLOCK[] = "選択範囲の指定";
3875 static GAME_TEXT MN_KILL_LINE[] = "行の残りを削除";
3876 static GAME_TEXT MN_DELETE_CHAR[] = "1文字削除";
3877 static GAME_TEXT MN_BACKSPACE[] = "バックスペース";
3878 static GAME_TEXT MN_RETURN[] = "改行";
3880 static GAME_TEXT MN_SEARCH[] = "検索";
3881 static GAME_TEXT MN_SEARCH_STR[] = "文字列で検索";
3882 static GAME_TEXT MN_SEARCH_FORW[] = "前方へ再検索";
3883 static GAME_TEXT MN_SEARCH_BACK[] = "後方へ再検索";
3884 static GAME_TEXT MN_SEARCH_OBJ[] = "アイテムを選択して検索";
3885 static GAME_TEXT MN_SEARCH_DESTROYED[] = "自動破壊されたアイテムで検索";
3887 static GAME_TEXT MN_INSERT[] = "色々挿入";
3888 static GAME_TEXT MN_INSERT_OBJECT[] = "選択したアイテムの名前を挿入";
3889 static GAME_TEXT MN_INSERT_DESTROYED[] = "自動破壊されたアイテムの名前を挿入";
3890 static GAME_TEXT MN_INSERT_BLOCK[] = "条件分岐ブロックの例を挿入";
3891 static GAME_TEXT MN_INSERT_MACRO[] = "マクロ定義を挿入";
3892 static GAME_TEXT MN_INSERT_KEYMAP[] = "キーマップ定義を挿入";
3894 static GAME_TEXT MN_COMMAND_LETTER[] = "拾い/破壊/放置の選択";
3895 static GAME_TEXT MN_CL_AUTOPICK[] = "「 」 (自動拾い)";
3896 static GAME_TEXT MN_CL_DESTROY[] = "「!」 (自動破壊)";
3897 static GAME_TEXT MN_CL_LEAVE[] = "「~」 (放置)";
3898 static GAME_TEXT MN_CL_QUERY[] = "「;」 (確認して拾う)";
3899 static GAME_TEXT MN_CL_NO_DISP[] = "「(」 (マップコマンドで表示しない)";
3901 static GAME_TEXT MN_ADJECTIVE_GEN[] = "形容詞(一般)の選択";
3902 static GAME_TEXT MN_RARE[] = "レアな (装備)";
3903 static GAME_TEXT MN_COMMON[] = "ありふれた (装備)";
3905 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "形容詞(特殊)の選択";
3906 static GAME_TEXT MN_BOOSTED[] = "ダイス目の違う (武器)";
3907 static GAME_TEXT MN_MORE_DICE[] = "ダイス目 # 以上の (武器)";
3908 static GAME_TEXT MN_MORE_BONUS[] = "修正値 # 以上の (指輪等)";
3909 static GAME_TEXT MN_WANTED[] = "賞金首の (死体)";
3910 static GAME_TEXT MN_UNIQUE[] = "ユニーク・モンスターの (死体)";
3911 static GAME_TEXT MN_HUMAN[] = "人間の (死体)";
3912 static GAME_TEXT MN_UNREADABLE[] = "読めない (魔法書)";
3913 static GAME_TEXT MN_REALM1[] = "第一領域の (魔法書)";
3914 static GAME_TEXT MN_REALM2[] = "第二領域の (魔法書)";
3915 static GAME_TEXT MN_FIRST[] = "1冊目の (魔法書)";
3916 static GAME_TEXT MN_SECOND[] = "2冊目の (魔法書)";
3917 static GAME_TEXT MN_THIRD[] = "3冊目の (魔法書)";
3918 static GAME_TEXT MN_FOURTH[] = "4冊目の (魔法書)";
3920 static GAME_TEXT MN_NOUN[] = "名詞の選択";
3924 static GAME_TEXT MN_QUIT[] = "Quit without save";
3925 static GAME_TEXT MN_SAVEQUIT[] = "Save & Quit";
3926 static GAME_TEXT MN_REVERT[] = "Revert all changes";
3927 static GAME_TEXT MN_HELP[] = "Help";
3929 static GAME_TEXT MN_MOVE[] = "Move cursor";
3930 static GAME_TEXT MN_LEFT[] = "Left (Left Arrow key)";
3931 static GAME_TEXT MN_DOWN[] = "Down (Down Arrow key)";
3932 static GAME_TEXT MN_UP[] = "Up (Up Arrow key)";
3933 static GAME_TEXT MN_RIGHT[] = "Right (Right Arrow key)";
3934 static GAME_TEXT MN_BOL[] = "Beggining of line";
3935 static GAME_TEXT MN_EOL[] = "End of line";
3936 static GAME_TEXT MN_PGUP[] = "Page up (PageUp key)";
3937 static GAME_TEXT MN_PGDOWN[] = "Page down(PageDown key)";
3938 static GAME_TEXT MN_TOP[] = "Top (Home key)";
3939 static GAME_TEXT MN_BOTTOM[] = "Bottom (End key)";
3941 static GAME_TEXT MN_EDIT[] = "Edit";
3942 static GAME_TEXT MN_CUT[] = "Cut";
3943 static GAME_TEXT MN_COPY[] = "Copy";
3944 static GAME_TEXT MN_PASTE[] = "Paste";
3945 static GAME_TEXT MN_BLOCK[] = "Select block";
3946 static GAME_TEXT MN_KILL_LINE[] = "Kill rest of line";
3947 static GAME_TEXT MN_DELETE_CHAR[] = "Delete character";
3948 static GAME_TEXT MN_BACKSPACE[] = "Backspace";
3949 static GAME_TEXT MN_RETURN[] = "Return";
3951 static GAME_TEXT MN_SEARCH[] = "Search";
3952 static GAME_TEXT MN_SEARCH_STR[] = "Search by string";
3953 static GAME_TEXT MN_SEARCH_FORW[] = "Search forward";
3954 static GAME_TEXT MN_SEARCH_BACK[] = "Search backward";
3955 static GAME_TEXT MN_SEARCH_OBJ[] = "Search by p_ptr->inventory_list object";
3956 static GAME_TEXT MN_SEARCH_DESTROYED[] = "Search by destroyed object";
3958 static GAME_TEXT MN_INSERT[] = "Insert...";
3959 static GAME_TEXT MN_INSERT_OBJECT[] = "Insert name of choosen object";
3960 static GAME_TEXT MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
3961 static GAME_TEXT MN_INSERT_BLOCK[] = "Insert conditional block";
3962 static GAME_TEXT MN_INSERT_MACRO[] = "Insert a macro definition";
3963 static GAME_TEXT MN_INSERT_KEYMAP[] = "Insert a keymap definition";
3965 static GAME_TEXT MN_COMMAND_LETTER[] = "Command letter";
3966 static GAME_TEXT MN_CL_AUTOPICK[] = "' ' (Auto pick)";
3967 static GAME_TEXT MN_CL_DESTROY[] = "'!' (Auto destroy)";
3968 static GAME_TEXT MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
3969 static GAME_TEXT MN_CL_QUERY[] = "';' (Query to pick up)";
3970 static GAME_TEXT MN_CL_NO_DISP[] = "'(' (No display on the large map)";
3972 static GAME_TEXT MN_ADJECTIVE_GEN[] = "Adjective (general)";
3973 static GAME_TEXT MN_RARE[] = "rare (equipments)";
3974 static GAME_TEXT MN_COMMON[] = "common (equipments)";
3976 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
3977 static GAME_TEXT MN_BOOSTED[] = "dice boosted (weapons)";
3978 static GAME_TEXT MN_MORE_DICE[] = "more than # dice (weapons)";
3979 static GAME_TEXT MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
3980 static GAME_TEXT MN_WANTED[] = "wanted (corpse)";
3981 static GAME_TEXT MN_UNIQUE[] = "unique (corpse)";
3982 static GAME_TEXT MN_HUMAN[] = "human (corpse)";
3983 static GAME_TEXT MN_UNREADABLE[] = "unreadable (spellbooks)";
3984 static GAME_TEXT MN_REALM1[] = "realm1 (spellbooks)";
3985 static GAME_TEXT MN_REALM2[] = "realm2 (spellbooks)";
3986 static GAME_TEXT MN_FIRST[] = "first (spellbooks)";
3987 static GAME_TEXT MN_SECOND[] = "second (spellbooks)";
3988 static GAME_TEXT MN_THIRD[] = "third (spellbooks)";
3989 static GAME_TEXT MN_FOURTH[] = "fourth (spellbooks)";
3991 static GAME_TEXT MN_NOUN[] = "Keywords (noun)";
4001 } command_menu_type;
4004 command_menu_type menu_data[] =
4006 {MN_HELP, 0, -1, EC_HELP},
4007 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4008 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4009 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4011 {MN_EDIT, 0, -1, -1},
4012 {MN_CUT, 1, KTRL('x'), EC_CUT},
4013 {MN_COPY, 1, KTRL('c'), EC_COPY},
4014 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4015 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4016 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4017 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4018 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4019 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4020 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4022 {MN_SEARCH, 0, -1, -1},
4023 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4024 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4025 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4026 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4027 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4029 {MN_MOVE, 0, -1, -1},
4030 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4031 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4032 {MN_UP, 1, KTRL('p'), EC_UP},
4033 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4034 {MN_BOL, 1, KTRL('a'), EC_BOL},
4035 {MN_EOL, 1, KTRL('e'), EC_EOL},
4036 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4037 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4038 {MN_TOP, 1, KTRL('t'), EC_TOP},
4039 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4041 {MN_INSERT, 0, -1, -1},
4042 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4043 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4044 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4045 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4046 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4048 {MN_ADJECTIVE_GEN, 0, -1, -1},
4049 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4050 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4051 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4052 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4053 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4054 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4055 {KEY_EGO, 1, -1, EC_OK_EGO},
4056 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4057 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4058 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4059 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4060 {MN_RARE, 1, -1, EC_OK_RARE},
4061 {MN_COMMON, 1, -1, EC_OK_COMMON},
4063 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4064 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4065 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4066 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4067 {MN_WANTED, 1, -1, EC_OK_WANTED},
4068 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4069 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4070 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4071 {MN_REALM1, 1, -1, EC_OK_REALM1},
4072 {MN_REALM2, 1, -1, EC_OK_REALM2},
4073 {MN_FIRST, 1, -1, EC_OK_FIRST},
4074 {MN_SECOND, 1, -1, EC_OK_SECOND},
4075 {MN_THIRD, 1, -1, EC_OK_THIRD},
4076 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4078 {MN_NOUN, 0, -1, -1},
4079 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4080 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4081 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4082 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4083 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4084 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4085 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4086 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4087 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4088 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4089 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4090 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4091 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4092 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4093 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4094 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4095 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4096 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4098 {MN_COMMAND_LETTER, 0, -1, -1},
4099 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4100 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4101 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4102 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4103 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4105 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4112 * Find a command by 'key'.
4114 static int get_com_id(char key)
4118 for (i = 0; menu_data[i].name; i++)
4120 if (menu_data[i].key == key)
4122 return menu_data[i].com_id;
4131 * Display the menu, and get a command
4133 static int do_command_menu(int level, int start)
4138 int col0 = 5 + level*7;
4139 int row0 = 1 + level*3;
4141 int menu_id_list[26];
4143 char linestr[MAX_LINELEN];
4145 /* Get max length */
4147 for (i = start; menu_data[i].level >= level; i++)
4151 /* Ignore lower level sub menus */
4152 if (menu_data[i].level > level) continue;
4154 len = strlen(menu_data[i].name);
4155 if (len > max_len) max_len = len;
4157 menu_id_list[menu_key] = i;
4161 while (menu_key < 26)
4163 menu_id_list[menu_key] = -1;
4167 /* Extra space for displaying menu key and command key */
4168 max_menu_wid = max_len + 3 + 3;
4170 /* Prepare box line */
4172 strcat(linestr, "+");
4173 for (i = 0; i < max_menu_wid + 2; i++)
4175 strcat(linestr, "-");
4177 strcat(linestr, "+");
4187 int row1 = row0 + 1;
4190 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4192 /* Draw menu items */
4194 for (i = start; menu_data[i].level >= level; i++)
4196 char com_key_str[3];
4199 /* Ignore lower level sub menus */
4200 if (menu_data[i].level > level) continue;
4202 if (menu_data[i].com_id == -1)
4204 strcpy(com_key_str, _("▼", ">"));
4206 else if (menu_data[i].key != -1)
4208 com_key_str[0] = '^';
4209 com_key_str[1] = menu_data[i].key + '@';
4210 com_key_str[2] = '\0';
4214 com_key_str[0] = '\0';
4217 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4219 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4224 /* Draw bottom line */
4225 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4227 /* The menu was shown */
4230 prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
4233 if (key == ESCAPE) return 0;
4235 if ('a' <= key && key <= 'z')
4237 menu_id = menu_id_list[key - 'a'];
4241 com_id = menu_data[menu_id].com_id;
4245 com_id = do_command_menu(level + 1, menu_id + 1);
4247 if (com_id) return com_id;
4259 com_id = get_com_id(key);
4260 if (com_id) return com_id;
4267 static chain_str_type *new_chain_str(concptr str)
4269 chain_str_type *chain;
4271 size_t len = strlen(str);
4273 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4275 strcpy(chain->s, str);
4282 static void kill_yank_chain(text_body_type *tb)
4284 chain_str_type *chain = tb->yank;
4286 tb->yank_eol = TRUE;
4290 chain_str_type *next = chain->next;
4291 size_t len = strlen(chain->s);
4293 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4300 static void add_str_to_yank(text_body_type *tb, concptr str)
4302 chain_str_type *chain;
4304 tb->yank_eol = FALSE;
4306 if (NULL == tb->yank)
4308 tb->yank = new_chain_str(str);
4318 chain->next = new_chain_str(str);
4323 chain = chain->next;
4329 * Do work for the copy editor-command
4331 static void copy_text_to_yank(text_body_type *tb)
4333 int len = strlen(tb->lines_list[tb->cy]);
4335 /* Correct cursor location */
4336 if (tb->cx > len) tb->cx = len;
4338 /* Use single line? */
4341 /* Select a single line */
4347 /* Kill old yank buffer */
4348 kill_yank_chain(tb);
4351 /* Single line case */
4352 if (tb->my == tb->cy)
4355 char buf[MAX_LINELEN];
4356 int bx1 = MIN(tb->mx, tb->cx);
4357 int bx2 = MAX(tb->mx, tb->cx);
4359 /* Correct fake cursor position */
4360 if (bx2 > len) bx2 = len;
4362 /* Whole part of this line is selected */
4363 if (bx1 == 0 && bx2 == len)
4365 /* Copy this line */
4366 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4368 /* Add end of line to the buffer */
4369 add_str_to_yank(tb, "");
4372 /* Segment of this line is selected */
4375 for (i = 0; i < bx2 - bx1; i++)
4377 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4381 /* Copy this segment of line */
4382 add_str_to_yank(tb, buf);
4386 /* Multiple lines case */
4387 else /* if (tb->my != tb->cy) */
4391 int by1 = MIN(tb->my, tb->cy);
4392 int by2 = MAX(tb->my, tb->cy);
4395 for (y = by1; y <= by2; y++)
4397 /* Copy this line */
4398 add_str_to_yank(tb, tb->lines_list[y]);
4401 /* Add final end of line to the buffer */
4402 add_str_to_yank(tb, "");
4405 /* Disable selection */
4409 tb->dirty_flags |= DIRTY_ALL;
4413 #define DESCRIPT_HGT 3
4418 static void draw_text_editor(text_body_type *tb)
4421 int by1 = 0, by2 = 0;
4423 Term_get_size(&tb->wid, &tb->hgt);
4426 * Top line (-1), description line (-3), separator (-1)
4429 tb->hgt -= 2 + DESCRIPT_HGT;
4432 /* Don't let cursor at second byte of kanji */
4433 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4434 if (iskanji(tb->lines_list[tb->cy][i]))
4440 * Move to a correct position in the
4443 if (i & 1) tb->cx--;
4450 /* Scroll if necessary */
4451 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4452 tb->upper = tb->cy - (tb->hgt)/2;
4455 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4456 tb->left = tb->cx - (tb->wid)*2/3;
4460 /* Redraw whole window after resize */
4461 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4462 tb->dirty_flags |= DIRTY_SCREEN;
4464 /* Redraw all text after scroll */
4465 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4466 tb->dirty_flags |= DIRTY_ALL;
4469 if (tb->dirty_flags & DIRTY_SCREEN)
4471 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4475 /* Redraw mode line */
4476 if (tb->dirty_flags & DIRTY_MODE)
4478 char buf[MAX_LINELEN];
4480 int sepa_length = tb->wid;
4483 for (i = 0; i < sepa_length; i++)
4487 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4490 if (tb->dirty_flags & DIRTY_EXPRESSION)
4495 for (y = 0; tb->lines_list[y]; y++)
4499 concptr s = tb->lines_list[y];
4503 /* Update this line's state */
4504 tb->states[y] = state;
4506 if (*s++ != '?') continue;
4507 if (*s++ != ':') continue;
4509 /* Lines below this line are auto-registered */
4510 if (streq(s, "$AUTOREGISTER"))
4511 state |= LSTAT_AUTOREGISTER;
4514 ss = (char *)string_make(s);
4517 /* Parse the expr */
4518 v = process_pref_file_expr(&ss, &f);
4521 if (streq(v, "0")) state |= LSTAT_BYPASS;
4522 else state &= ~LSTAT_BYPASS;
4524 /* Cannot use string_free() because the string was "destroyed" */
4525 C_KILL(s_keep, s_len + 1, char);
4527 /* Re-update this line's state */
4528 tb->states[y] = state | LSTAT_EXPRESSION;
4531 tb->dirty_flags |= DIRTY_ALL;
4536 tb->dirty_flags |= DIRTY_ALL;
4538 by1 = MIN(tb->my, tb->cy);
4539 by2 = MAX(tb->my, tb->cy);
4542 /* Dump up to tb->hgt lines of messages */
4543 for (i = 0; i < tb->hgt; i++)
4549 int y = tb->upper+i;
4551 /* clean or dirty? */
4552 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4555 msg = tb->lines_list[y];
4558 /* Apply horizontal scroll */
4559 for (j = 0; *msg; msg++, j++)
4561 if (j == tb->left) break;
4577 Term_erase(0, i + 1, tb->wid);
4579 if (tb->states[y] & LSTAT_AUTOREGISTER)
4581 /* Warning color -- These lines will be deleted later */
4586 /* Bypassed line will be displayed by darker color */
4587 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4588 else color = TERM_WHITE;
4591 /* No mark or Out of mark */
4592 if (!tb->mark || (y < by1 || by2 < y))
4594 /* Dump the messages, bottom to top */
4595 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4598 /* Multiple lines selected */
4599 else if (by1 != by2)
4601 /* Dump the messages, bottom to top */
4602 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4605 /* Single line selected */
4608 int x0 = leftcol + tb->left;
4609 int len = strlen(tb->lines_list[tb->cy]);
4610 int bx1 = MIN(tb->mx, tb->cx);
4611 int bx2 = MAX(tb->mx, tb->cx);
4613 /* Correct cursor location */
4614 if (bx2 > len) bx2 = len;
4616 Term_gotoxy(leftcol, i + 1);
4617 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4618 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4619 Term_addstr(-1, color, msg + (bx2 - x0));
4623 for (; i < tb->hgt; i++)
4626 Term_erase(0, i + 1, tb->wid);
4629 /* Display information when updated */
4630 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4632 autopick_type an_entry, *entry = &an_entry;
4633 concptr str1 = NULL, str2 = NULL;
4636 /* Clear information line */
4637 for (i = 0; i < DESCRIPT_HGT; i++)
4640 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4643 /* Display information */
4644 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4646 str1 = format(_("パターンが見つかりません: %s", "Pattern not found: %s"), tb->search_str);
4648 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4650 str1 = format(_("無効状態の行をスキップしました。(%sを検索中)",
4651 "Some inactive lines are skipped. (Searching %s)"), tb->search_str);
4653 else if (tb->dirty_flags & DIRTY_INACTIVE)
4655 str1 = format(_("無効状態の行だけが見付かりました。(%sを検索中)",
4656 "Found only an inactive line. (Searching %s)"), tb->search_str);
4658 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4660 str1 = _("検索するパターンがありません(^S で検索)。", "No pattern to search. (Press ^S to search.)");
4662 else if (tb->lines_list[tb->cy][0] == '#')
4664 str1 = _("この行はコメントです。", "This line is a comment.");
4666 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4668 switch(tb->lines_list[tb->cy][0])
4671 str1 = _("この行は条件分岐式です。", "This line is a Conditional Expression.");
4674 str1 = _("この行はマクロの実行内容を定義します。", "This line defines a Macro action.");
4677 str1 = _("この行はマクロのトリガー・キーを定義します。", "This line defines a Macro trigger key.");
4680 str1 = _("この行はキー配置を定義します。", "This line defines a Keymap.");
4684 switch(tb->lines_list[tb->cy][0])
4687 if (tb->states[tb->cy] & LSTAT_BYPASS)
4689 str2 = _("現在の式の値は「偽(=0)」です。", "The expression is 'False'(=0) currently.");
4693 str2 = _("現在の式の値は「真(=1)」です。", "The expression is 'True'(=1) currently.");
4698 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4700 str2 = _("この行は後で削除されます。", "This line will be delete later.");
4703 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4705 str2 = _("この行は現在は無効な状態です。", "This line is bypassed currently.");
4711 /* Get description of an autopicker preference line */
4712 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4714 char buf[MAX_LINELEN];
4715 char temp[MAX_LINELEN];
4718 describe_autopick(buf, entry);
4720 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4722 strcat(buf, _("この行は後で削除されます。", " This line will be delete later."));
4725 if (tb->states[tb->cy] & LSTAT_BYPASS)
4727 strcat(buf, _("この行は現在は無効な状態です。", " This line is bypassed currently."));
4730 roff_to_buf(buf, 81, temp, sizeof(temp));
4732 for (i = 0; i < 3; i++)
4738 prt(t, tb->hgt +1 + 1 + i, 0);
4742 autopick_free_entry(entry);
4745 /* Draw the first line */
4746 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4748 /* Draw the second line */
4749 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4755 * Kill segment of a line
4757 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4759 char buf[MAX_LINELEN];
4760 concptr s = tb->lines_list[y];
4764 /* Kill whole line? */
4765 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4769 string_free(tb->lines_list[y]);
4771 /* Shift lines up */
4772 for (i = y; tb->lines_list[i+1]; i++)
4773 tb->lines_list[i] = tb->lines_list[i+1];
4774 tb->lines_list[i] = NULL;
4776 /* Expressions need re-evaluation */
4777 tb->dirty_flags |= DIRTY_EXPRESSION;
4783 if (x0 == x1) return;
4785 /* Before the segment */
4786 for (x = 0; x < x0; x++)
4789 /* After the segment */
4790 for (x = x1; s[x]; x++)
4796 string_free(tb->lines_list[y]);
4797 tb->lines_list[y] = string_make(buf);
4799 /* Expressions may need re-evaluation */
4800 check_expression_line(tb, y);
4802 /* Text is changed */
4808 * Get a trigger key and insert ASCII string for the trigger
4810 static bool insert_macro_line(text_body_type *tb)
4819 /* Do not process macros */
4825 /* Read the pattern */
4831 /* Do not process macros */
4834 /* Do not wait for keys */
4837 /* Attempt to read a key */
4846 /* Convert the trigger */
4847 ascii_to_text(tmp, buf);
4850 if(!tmp[0]) return FALSE;
4854 /* Insert preference string */
4855 insert_return_code(tb);
4856 string_free(tb->lines_list[tb->cy]);
4857 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4859 /* Acquire action */
4860 i = macro_find_exact(buf);
4864 /* Nothing defined */
4869 /* Analyze the current action */
4870 ascii_to_text(tmp, macro__act[i]);
4873 /* Insert blank action preference line */
4874 insert_return_code(tb);
4875 string_free(tb->lines_list[tb->cy]);
4876 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4883 * Get a command key and insert ASCII string for the key
4885 static bool insert_keymap_line(text_body_type *tb)
4893 if (rogue_like_commands)
4895 mode = KEYMAP_MODE_ROGUE;
4901 mode = KEYMAP_MODE_ORIG;
4912 /* Convert the trigger */
4913 ascii_to_text(tmp, buf);
4916 if(!tmp[0]) return FALSE;
4920 /* Insert preference string */
4921 insert_return_code(tb);
4922 string_free(tb->lines_list[tb->cy]);
4923 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4925 /* Look up the keymap */
4926 act = keymap_act[mode][(byte)(buf[0])];
4930 /* Analyze the current action */
4931 ascii_to_text(tmp, act);
4935 /* No keymap defined -- Use trigger key itself as a default */
4937 /* Nothing to do (use tmp) */
4940 /* Insert blank action preference line */
4941 insert_return_code(tb);
4942 string_free(tb->lines_list[tb->cy]);
4943 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4950 * Execute a single editor command
4952 static bool do_editor_command(text_body_type *tb, int com_id)
4959 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
4960 "Discard all changes and quit. Are you sure? "))) break;
4962 return QUIT_WITHOUT_SAVE;
4965 return QUIT_AND_SAVE;
4968 /* Revert to original */
4969 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
4970 "Discard all changes and revert to original file. Are you sure? "))) break;
4972 free_text_lines(tb->lines_list);
4973 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4974 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4975 tb->cx = tb->cy = 0;
4978 /* Text is not changed */
4979 tb->changed = FALSE;
4983 /* Peruse the main help file */
4984 (void)show_file(TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
4986 tb->dirty_flags |= DIRTY_SCREEN;
4991 /* Split a line or insert end of line */
4993 /* Ignore selection */
4999 tb->dirty_flags |= DIRTY_ALL;
5002 insert_return_code(tb);
5007 tb->dirty_flags |= DIRTY_ALL;
5020 len = strlen(tb->lines_list[tb->cy]);
5021 if (len < tb->cx) tb->cx = len;
5024 /* Don't let cursor at second byte of kanji */
5025 for (i = 0; tb->lines_list[tb->cy][i]; i++)
5027 if (iskanji(tb->lines_list[tb->cy][i]))
5032 /* Move to the left */
5040 else if (tb->cy > 0)
5043 tb->cx = strlen(tb->lines_list[tb->cy]);
5050 /* Is this the last line? */
5051 if (!tb->lines_list[tb->cy + 1])
5053 /* Add one more empty line if possible */
5054 if (!add_empty_line(tb)) break;
5064 if (tb->cy > 0) tb->cy--;
5073 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5076 len = strlen(tb->lines_list[tb->cy]);
5079 /* Correct the cursor position */
5082 /* Is this the last line? */
5083 if (!tb->lines_list[tb->cy + 1])
5085 /* Add one more empty line if possible */
5086 if (!add_empty_line(tb)) break;
5089 /* Move to the beginning of next line */
5097 /* Beginning of line */
5103 tb->cx = strlen(tb->lines_list[tb->cy]);
5107 while (0 < tb->cy && tb->upper <= tb->cy)
5109 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5115 while (tb->cy < tb->upper + tb->hgt)
5117 /* Is this the last line? */
5118 if (!tb->lines_list[tb->cy + 1])
5120 /* Add one more empty line if possible */
5121 if (!add_empty_line(tb)) break;
5137 /* Is this the last line? */
5138 if (!tb->lines_list[tb->cy + 1])
5140 /* Add one more empty line if possible */
5141 if (!add_empty_line(tb)) break;
5147 /* Always at the biginning of the last line */
5154 /* Copy the text first */
5155 copy_text_to_yank(tb);
5157 /* Single line case */
5158 if (tb->my == tb->cy)
5160 int bx1 = MIN(tb->mx, tb->cx);
5161 int bx2 = MAX(tb->mx, tb->cx);
5162 int len = strlen(tb->lines_list[tb->cy]);
5164 /* Correct fake cursor position */
5165 if (bx2 > len) bx2 = len;
5167 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5169 /* New cursor position */
5173 /* Multiple lines case */
5174 else /* if (tb->my != tb->cy) */
5178 int by1 = MIN(tb->my, tb->cy);
5179 int by2 = MAX(tb->my, tb->cy);
5181 /* Kill lines in reverse order */
5182 for (y = by2; y >= by1; y--)
5184 int len = strlen(tb->lines_list[y]);
5186 kill_line_segment(tb, y, 0, len, TRUE);
5189 /* New cursor position */
5195 /* Disable selection */
5199 tb->dirty_flags |= DIRTY_ALL;
5201 /* Text is changed */
5208 copy_text_to_yank(tb);
5211 * Move cursor position to the end of the selection
5213 * Pressing ^C ^V correctly duplicates the selection.
5215 if (tb->my == tb->cy)
5217 tb->cx = MAX(tb->cx, tb->mx);
5220 * When whole line is selected, the end of
5221 * line code is also copyed.
5223 if (!tb->lines_list[tb->cy][tb->cx])
5225 /* Is this the last line? */
5226 if (!tb->lines_list[tb->cy + 1])
5228 /* Add one more empty line if possible */
5229 if (!add_empty_line(tb)) break;
5232 /* Go to the beginning of next line */
5239 tb->cy = MAX(tb->cy, tb->my);
5241 /* Is this the last line? */
5242 if (!tb->lines_list[tb->cy + 1])
5244 /* Add one more empty line if possible */
5245 if (!add_empty_line(tb)) break;
5256 /* Paste killed text */
5258 chain_str_type *chain = tb->yank;
5259 int len = strlen(tb->lines_list[tb->cy]);
5261 /* Nothing to do? */
5264 /* Correct cursor location */
5265 if (tb->cx > len) tb->cx = len;
5267 /* Ignore selection */
5273 tb->dirty_flags |= DIRTY_ALL;
5279 concptr yank_str = chain->s;
5281 char buf[MAX_LINELEN];
5283 char rest[MAX_LINELEN], *rest_ptr = rest;
5285 /* Save preceding string */
5286 for(i = 0; i < tb->cx; i++)
5287 buf[i] = tb->lines_list[tb->cy][i];
5289 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5291 /* Paste yank buffer */
5292 while (*yank_str && i < MAX_LINELEN-1)
5294 buf[i++] = *yank_str++;
5300 chain = chain->next;
5302 if (chain || tb->yank_eol)
5304 /* There is an end of line between chain nodes */
5306 insert_return_code(tb);
5308 /* Replace this line with new one */
5309 string_free(tb->lines_list[tb->cy]);
5310 tb->lines_list[tb->cy] = string_make(buf);
5312 /* Move to next line */
5319 /* Final line doesn't have end of line */
5321 tb->cx = strlen(buf);
5323 /* Rest of original line */
5324 while (*rest_ptr && i < MAX_LINELEN-1)
5326 buf[i++] = *rest_ptr++;
5332 /* Replace this line with new one */
5333 string_free(tb->lines_list[tb->cy]);
5334 tb->lines_list[tb->cy] = string_make(buf);
5341 tb->dirty_flags |= DIRTY_ALL;
5343 /* Expressions need re-evaluation */
5344 tb->dirty_flags |= DIRTY_EXPRESSION;
5346 /* Text is changed */
5355 /* Disable the selection */
5359 tb->dirty_flags |= DIRTY_ALL;
5363 tb->mark = MARK_MARK;
5365 /* Repeating this command swaps cursor position */
5366 if (com_id == tb->old_com_id)
5378 tb->dirty_flags |= DIRTY_ALL;
5382 int len = strlen(tb->lines_list[tb->cy]);
5384 /* Mark the point 1 */
5388 /* Correct cursor location */
5389 if (tb->cx > len) tb->mx = len;
5396 /* Kill rest of line */
5398 int len = strlen(tb->lines_list[tb->cy]);
5400 /* Correct cursor location */
5401 if (tb->cx > len) tb->cx = len;
5403 /* Ignore selection */
5409 tb->dirty_flags |= DIRTY_ALL;
5412 /* Append only if this command is repeated. */
5413 if (tb->old_com_id != com_id)
5415 kill_yank_chain(tb);
5419 /* Really deleted some text */
5422 /* Add deleted string to yank buffer */
5423 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5425 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5428 tb->dirty_line = tb->cy;
5430 /* Leave end of line character */
5434 /* Cut the end of line character only */
5435 if (tb->yank_eol) add_str_to_yank(tb, "");
5437 /* Cut end of line */
5438 tb->yank_eol = TRUE;
5440 do_editor_command(tb, EC_DELETE_CHAR);
5444 case EC_DELETE_CHAR:
5446 /* DELETE == go forward + BACK SPACE */
5450 /* Ignore selection */
5456 tb->dirty_flags |= DIRTY_ALL;
5460 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5464 /* Pass through the end of line to next line */
5465 len = strlen(tb->lines_list[tb->cy]);
5468 if (tb->lines_list[tb->cy + 1])
5480 do_editor_command(tb, EC_BACKSPACE);
5489 char buf[MAX_LINELEN];
5491 /* Ignore selection */
5497 tb->dirty_flags |= DIRTY_ALL;
5500 /* Move to correct collumn */
5501 len = strlen(tb->lines_list[tb->cy]);
5502 if (len < tb->cx) tb->cx = len;
5506 /* delete a return code and union two lines */
5507 if (tb->cy == 0) break;
5508 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5509 strcpy(buf, tb->lines_list[tb->cy-1]);
5510 strcat(buf, tb->lines_list[tb->cy]);
5511 string_free(tb->lines_list[tb->cy-1]);
5512 string_free(tb->lines_list[tb->cy]);
5513 tb->lines_list[tb->cy-1] = string_make(buf);
5515 for (i = tb->cy; tb->lines_list[i+1]; i++)
5516 tb->lines_list[i] = tb->lines_list[i+1];
5518 tb->lines_list[i] = NULL;
5522 tb->dirty_flags |= DIRTY_ALL;
5524 /* Expressions need re-evaluation */
5525 tb->dirty_flags |= DIRTY_EXPRESSION;
5527 /* Text is changed */
5533 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5537 if (iskanji(tb->lines_list[tb->cy][i]))
5538 buf[j++] = tb->lines_list[tb->cy][i++];
5540 buf[j++] = tb->lines_list[tb->cy][i];
5547 for (; tb->lines_list[tb->cy][i]; i++)
5548 buf[j++] = tb->lines_list[tb->cy][i];
5550 string_free(tb->lines_list[tb->cy]);
5551 tb->lines_list[tb->cy] = string_make(buf);
5554 tb->dirty_line = tb->cy;
5556 /* Expressions may need re-evaluation */
5557 check_expression_line(tb, tb->cy);
5559 /* Text is changed */
5569 /* Become dirty because of item/equip menu */
5570 tb->dirty_flags |= DIRTY_SCREEN;
5572 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5574 if (!search_dir) break;
5576 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5577 else do_editor_command(tb, EC_SEARCH_BACK);
5581 case EC_SEARCH_FORW:
5582 if (tb->search_o_ptr)
5584 search_for_object(tb, tb->search_o_ptr, TRUE);
5586 else if (tb->search_str && tb->search_str[0])
5588 search_for_string(tb, tb->search_str, TRUE);
5592 tb->dirty_flags |= DIRTY_NO_SEARCH;
5596 case EC_SEARCH_BACK:
5597 if (tb->search_o_ptr)
5599 search_for_object(tb, tb->search_o_ptr, FALSE);
5601 else if (tb->search_str && tb->search_str[0])
5603 search_for_string(tb, tb->search_str, FALSE);
5607 tb->dirty_flags |= DIRTY_NO_SEARCH;
5612 /* Become dirty because of item/equip menu */
5613 tb->dirty_flags |= DIRTY_SCREEN;
5615 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5617 do_editor_command(tb, EC_SEARCH_FORW);
5620 case EC_SEARCH_DESTROYED:
5621 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5623 /* There is no object to search */
5624 tb->dirty_flags |= DIRTY_NO_SEARCH;
5629 do_editor_command(tb, EC_SEARCH_FORW);
5632 case EC_INSERT_OBJECT:
5634 /* Insert choosen item name */
5636 autopick_type an_entry, *entry = &an_entry;
5638 if (!entry_from_choosed_object(entry))
5640 /* Now dirty because of item/equip menu */
5641 tb->dirty_flags |= DIRTY_SCREEN;
5646 insert_return_code(tb);
5647 string_free(tb->lines_list[tb->cy]);
5648 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5650 /* Now dirty because of item/equip menu */
5651 tb->dirty_flags |= DIRTY_SCREEN;
5656 case EC_INSERT_DESTROYED:
5657 /* Insert a name of last destroyed item */
5658 if (tb->last_destroyed)
5661 insert_return_code(tb);
5662 string_free(tb->lines_list[tb->cy]);
5663 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5666 tb->dirty_flags |= DIRTY_ALL;
5668 /* Text is changed */
5673 case EC_INSERT_BLOCK:
5675 /* Insert a conditinal expression line */
5676 char expression[80];
5678 /* Conditional Expression for Class and Race */
5679 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5681 rp_ptr->E_title, cp_ptr->E_title,
5683 rp_ptr->title, cp_ptr->title,
5689 insert_return_code(tb);
5690 string_free(tb->lines_list[tb->cy]);
5691 tb->lines_list[tb->cy] = string_make(expression);
5693 insert_return_code(tb);
5694 string_free(tb->lines_list[tb->cy]);
5695 tb->lines_list[tb->cy] = string_make("?:1");
5698 tb->dirty_flags |= DIRTY_ALL;
5700 /* Text is changed */
5706 case EC_INSERT_MACRO:
5707 /* Draw_everythig (delete menu) */
5708 draw_text_editor(tb);
5711 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5714 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
5715 if (insert_macro_line(tb))
5717 /* Prepare to input action */
5721 tb->dirty_flags |= DIRTY_ALL;
5723 /* Text is changed */
5729 case EC_INSERT_KEYMAP:
5730 /* Draw_everythig (delete menu) */
5731 draw_text_editor(tb);
5734 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5737 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
5738 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5740 if (insert_keymap_line(tb))
5742 /* Prepare to input action */
5746 tb->dirty_flags |= DIRTY_ALL;
5748 /* Text is changed */
5753 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5754 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5755 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5756 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5757 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5759 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5760 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5761 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5762 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5763 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5764 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5765 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5766 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5767 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5768 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5769 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5770 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5771 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5772 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5773 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5774 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5775 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5776 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5777 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5778 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5779 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5780 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5781 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5782 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5783 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5784 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5785 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5786 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5787 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5788 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5789 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5790 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5791 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5792 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5793 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5794 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5795 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5796 case EC_OK_UNREADABLE:
5797 toggle_keyword(tb, FLG_UNREADABLE);
5798 add_keyword(tb, FLG_SPELLBOOKS);
5801 toggle_keyword(tb, FLG_REALM1);
5802 add_keyword(tb, FLG_SPELLBOOKS);
5805 toggle_keyword(tb, FLG_REALM2);
5806 add_keyword(tb, FLG_SPELLBOOKS);
5809 toggle_keyword(tb, FLG_FIRST);
5810 add_keyword(tb, FLG_SPELLBOOKS);
5813 toggle_keyword(tb, FLG_SECOND);
5814 add_keyword(tb, FLG_SPELLBOOKS);
5817 toggle_keyword(tb, FLG_THIRD);
5818 add_keyword(tb, FLG_SPELLBOOKS);
5821 toggle_keyword(tb, FLG_FOURTH);
5822 add_keyword(tb, FLG_SPELLBOOKS);
5826 /* Save old command */
5827 tb->old_com_id = com_id;
5834 * Insert single letter at cursor position.
5836 static void insert_single_letter(text_body_type *tb, int key)
5839 char buf[MAX_LINELEN];
5841 /* Save preceding string */
5842 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5843 buf[j++] = tb->lines_list[tb->cy][i];
5845 /* Add a character */
5853 if (j+2 < MAX_LINELEN)
5855 buf[j++] = (char)key;
5856 buf[j++] = (char)next;
5865 if (j+1 < MAX_LINELEN)
5866 buf[j++] = (char)key;
5871 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5872 buf[j++] = tb->lines_list[tb->cy][i];
5875 /* Replace current line with new line */
5876 string_free(tb->lines_list[tb->cy]);
5877 tb->lines_list[tb->cy] = string_make(buf);
5879 /* Move to correct collumn */
5880 len = strlen(tb->lines_list[tb->cy]);
5881 if (len < tb->cx) tb->cx = len;
5884 tb->dirty_line = tb->cy;
5886 /* Expressions may need re-evaluation */
5887 check_expression_line(tb, tb->cy);
5889 /* Text is changed */
5895 * Check special key code and get a movement command id
5897 static int analyze_move_key(text_body_type *tb, int skey)
5901 /* Not a special key */
5902 if (!(skey & SKEY_MASK)) return 0;
5904 /* Convert from a special key code to an editor command */
5905 switch(skey & ~SKEY_MOD_MASK)
5907 case SKEY_DOWN: com_id = EC_DOWN; break;
5908 case SKEY_LEFT: com_id = EC_LEFT; break;
5909 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5910 case SKEY_UP: com_id = EC_UP; break;
5911 case SKEY_PGUP: com_id = EC_PGUP; break;
5912 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5913 case SKEY_TOP: com_id = EC_TOP; break;
5914 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5917 /* Not a special movement key */
5921 /* Without shift modifier */
5922 if (!(skey & SKEY_MOD_SHIFT))
5925 * Un-shifted cursor keys cancells
5926 * selection created by shift+cursor.
5928 if (tb->mark & MARK_BY_SHIFT)
5933 tb->dirty_flags |= DIRTY_ALL;
5937 /* With shift modifier */
5940 /* Start selection by shift + cursor keys */
5943 int len = strlen(tb->lines_list[tb->cy]);
5945 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5949 /* Correct cursor location */
5950 if (tb->cx > len) tb->mx = len;
5952 /* Need to redraw text */
5953 if (com_id == EC_UP || com_id == EC_DOWN)
5955 /* Redraw all text */
5956 tb->dirty_flags |= DIRTY_ALL;
5960 tb->dirty_line = tb->cy;
5969 * In-game editor of Object Auto-picker/Destoryer
5970 * @param player_ptr プレーヤーへの参照ポインタ
5972 void do_cmd_edit_autopick(player_type *player_ptr)
5974 static int cx_save = 0;
5975 static int cy_save = 0;
5977 text_body_type text_body, *tb = &text_body;
5979 autopick_type an_entry, *entry = &an_entry;
5980 char buf[MAX_LINELEN];
5985 static s32b old_autosave_turn = 0L;
5988 tb->changed = FALSE;
5991 tb->upper = tb->left = 0;
5993 tb->mx = tb->my = 0;
5994 tb->old_cy = tb->old_upper = tb->old_left = -1;
5995 tb->old_wid = tb->old_hgt = -1;
5999 tb->search_o_ptr = NULL;
6000 tb->search_str = NULL;
6001 tb->last_destroyed = NULL;
6002 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6003 tb->dirty_line = -1;
6004 tb->filename_mode = PT_DEFAULT;
6006 if (current_world_ptr->game_turn < old_autosave_turn)
6008 while (old_autosave_turn > current_world_ptr->game_turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
6012 if (current_world_ptr->game_turn > old_autosave_turn + 100L)
6014 do_cmd_save_game(player_ptr, TRUE);
6015 old_autosave_turn = current_world_ptr->game_turn;
6018 /* HACK -- Reset current_world_ptr->start_time to stop counting current_world_ptr->play_time while edit */
6021 /* Free old entries */
6024 /* Command Description of the 'Last Destroyed Item' */
6025 if (autopick_last_destroyed_object.k_idx)
6027 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6028 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6031 /* Read or initialize whole text */
6032 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6034 /* Reset cursor position if needed */
6035 for (i = 0; i < tb->cy; i++)
6037 if (!tb->lines_list[i])
6039 tb->cy = tb->cx = 0;
6045 /* Process requests until done */
6050 /* Draw_everythig */
6051 draw_text_editor(tb);
6053 /* Display header line */
6054 prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)",
6055 "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0);
6058 /* Display current position */
6059 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6063 /* Display current position and mark position */
6064 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6068 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6071 tb->dirty_flags = 0;
6072 tb->dirty_line = -1;
6074 /* Save old key and location */
6075 tb->old_cy = tb->cy;
6076 tb->old_upper = tb->upper;
6077 tb->old_left = tb->left;
6078 tb->old_wid = tb->wid;
6079 tb->old_hgt = tb->hgt;
6081 key = inkey_special(TRUE);
6084 if (key & SKEY_MASK)
6086 /* Get a movement command */
6087 com_id = analyze_move_key(tb, key);
6091 else if (key == ESCAPE)
6093 com_id = do_command_menu(0, 0);
6095 /* Redraw all text later */
6096 tb->dirty_flags |= DIRTY_SCREEN;
6099 /* Insert a character */
6100 else if (!iscntrl((unsigned char)key))
6102 /* Ignore selection */
6108 tb->dirty_flags |= DIRTY_ALL;
6111 insert_single_letter(tb, key);
6117 /* Other commands */
6120 com_id = get_com_id((char)key);
6123 if (com_id) quit = do_editor_command(tb, com_id);
6124 } /* while (TRUE) */
6127 /* Get the filename of preference */
6128 strcpy(buf, pickpref_filename(tb->filename_mode));
6130 if (quit == QUIT_AND_SAVE)
6131 write_text_lines(buf, tb->lines_list);
6133 free_text_lines(tb->lines_list);
6135 string_free(tb->search_str);
6136 string_free(tb->last_destroyed);
6138 /* Destroy string chain */
6139 kill_yank_chain(tb);
6141 /* Reload autopick pref */
6142 process_autopick_file(buf);
6144 /* HACK -- reset current_world_ptr->start_time so that current_world_ptr->play_time is not increase while edit */
6145 current_world_ptr->start_time = (u32b)time(NULL);
6147 /* Save cursor location */