3 * @brief 自動拾い機能の実装 / Object Auto-picker/Destroyer
6 * Copyright (c) 2002 Mogami\n
8 * This software may be copied and distributed for educational, research, and\n
9 * not for profit purposes provided that this copyright and statement are\n
10 * included in all such copies.\n
11 * 2014 Deskull rearranged comment for Doxygen.\n
21 #include "player-status.h"
22 #include "player-move.h"
23 #include "player-class.h"
24 #include "player-race.h"
25 #include "objectkind.h"
26 #include "object-ego.h"
27 #include "object-flavor.h"
28 #include "object-hook.h"
34 #include "monsterrace.h"
36 #define MAX_LINELEN 1024
43 #define FLG_UNIDENTIFIED 2
44 #define FLG_IDENTIFIED 3
45 #define FLG_STAR_IDENTIFIED 4
46 #define FLG_COLLECTING 5
47 #define FLG_ARTIFACT 6
50 #define FLG_NAMELESS 11
51 #define FLG_AVERAGE 12
52 #define FLG_WORTHLESS 13
55 #define FLG_BOOSTED 16
56 #define FLG_MORE_DICE 17
57 #define FLG_MORE_BONUS 18
61 #define FLG_UNREADABLE 22
70 #define FLG_WEAPONS 31
71 #define FLG_FAVORITE_WEAPONS 32
73 #define FLG_MISSILES 34
74 #define FLG_DEVICES 35
77 #define FLG_CORPSES 38
78 #define FLG_SPELLBOOKS 39
80 #define FLG_SHIELDS 41
83 #define FLG_AMULETS 44
90 #define FLG_NOUN_BEGIN FLG_ITEMS
91 #define FLG_NOUN_END FLG_BOOTS
95 static GAME_TEXT KEY_ALL[] = "すべての";
96 static GAME_TEXT KEY_UNAWARE[] = "未判明の";
97 static GAME_TEXT KEY_UNIDENTIFIED[] = "未鑑定の";
98 static GAME_TEXT KEY_IDENTIFIED[] = "鑑定済みの";
99 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*鑑定*済みの";
100 static GAME_TEXT KEY_COLLECTING[] = "収集中の";
101 static GAME_TEXT KEY_ARTIFACT[] = "アーティファクト";
102 static GAME_TEXT KEY_EGO[] = "エゴ";
103 static GAME_TEXT KEY_GOOD[] = "上質の";
104 static GAME_TEXT KEY_NAMELESS[] = "無銘の";
105 static GAME_TEXT KEY_AVERAGE[] = "並の";
106 static GAME_TEXT KEY_WORTHLESS[] = "無価値の";
107 static GAME_TEXT KEY_RARE[] = "レアな";
108 static GAME_TEXT KEY_COMMON[] = "ありふれた";
109 static GAME_TEXT KEY_BOOSTED[] = "ダイス目の違う";
110 static GAME_TEXT KEY_MORE_THAN[] = "ダイス目";
111 static GAME_TEXT KEY_DICE[] = "以上の";
112 static GAME_TEXT KEY_MORE_BONUS[] = "修正値";
113 static GAME_TEXT KEY_MORE_BONUS2[] = "以上の";
114 static GAME_TEXT KEY_WANTED[] = "賞金首の";
115 static GAME_TEXT KEY_UNIQUE[] = "ユニーク・モンスターの";
116 static GAME_TEXT KEY_HUMAN[] = "人間の";
117 static GAME_TEXT KEY_UNREADABLE[] = "読めない";
118 static GAME_TEXT KEY_REALM1[] = "第一領域の";
119 static GAME_TEXT KEY_REALM2[] = "第二領域の";
120 static GAME_TEXT KEY_FIRST[] = "1冊目の";
121 static GAME_TEXT KEY_SECOND[] = "2冊目の";
122 static GAME_TEXT KEY_THIRD[] = "3冊目の";
123 static GAME_TEXT KEY_FOURTH[] = "4冊目の";
124 static GAME_TEXT KEY_ITEMS[] = "アイテム";
125 static GAME_TEXT KEY_WEAPONS[] = "武器";
126 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "得意武器";
127 static GAME_TEXT KEY_ARMORS[] = "防具";
128 static GAME_TEXT KEY_MISSILES[] = "矢";
129 static GAME_TEXT KEY_DEVICES[] = "魔法アイテム";
130 static GAME_TEXT KEY_LIGHTS[] = "光源";
131 static GAME_TEXT KEY_JUNKS[] = "がらくた";
132 static GAME_TEXT KEY_CORPSES[] = "死体や骨";
133 static GAME_TEXT KEY_SPELLBOOKS[] = "魔法書";
134 static GAME_TEXT KEY_HAFTED[] = "鈍器";
135 static GAME_TEXT KEY_SHIELDS[] = "盾";
136 static GAME_TEXT KEY_BOWS[] = "弓";
137 static GAME_TEXT KEY_RINGS[] = "指輪";
138 static GAME_TEXT KEY_AMULETS[] = "アミュレット";
139 static GAME_TEXT KEY_SUITS[] = "鎧";
140 static GAME_TEXT KEY_CLOAKS[] = "クローク";
141 static GAME_TEXT KEY_HELMS[] = "兜";
142 static GAME_TEXT KEY_GLOVES[] = "籠手";
143 static GAME_TEXT KEY_BOOTS[] = "靴";
147 static GAME_TEXT KEY_ALL[] = "all";
148 static GAME_TEXT KEY_UNAWARE[] = "unaware";
149 static GAME_TEXT KEY_UNIDENTIFIED[] = "unidentified";
150 static GAME_TEXT KEY_IDENTIFIED[] = "identified";
151 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*identified*";
152 static GAME_TEXT KEY_COLLECTING[] = "collecting";
153 static GAME_TEXT KEY_ARTIFACT[] = "artifact";
154 static GAME_TEXT KEY_EGO[] = "ego";
155 static GAME_TEXT KEY_GOOD[] = "good";
156 static GAME_TEXT KEY_nameLESS[] = "nameless";
157 static GAME_TEXT KEY_AVERAGE[] = "average";
158 static GAME_TEXT KEY_WORTHLESS[] = "worthless";
159 static GAME_TEXT KEY_RARE[] = "rare";
160 static GAME_TEXT KEY_COMMON[] = "common";
161 static GAME_TEXT KEY_BOOSTED[] = "dice boosted";
162 static GAME_TEXT KEY_MORE_THAN[] = "more than";
163 static GAME_TEXT KEY_DICE[] = " dice";
164 static GAME_TEXT KEY_MORE_BONUS[] = "more bonus than";
165 static GAME_TEXT KEY_MORE_BONUS2[] = "";
166 static GAME_TEXT KEY_WANTED[] = "wanted";
167 static GAME_TEXT KEY_UNIQUE[] = "unique monster's";
168 static GAME_TEXT KEY_HUMAN[] = "human";
169 static GAME_TEXT KEY_UNREADABLE[] = "unreadable";
170 static GAME_TEXT KEY_REALM1[] = "first realm's";
171 static GAME_TEXT KEY_REALM2[] = "second realm's";
172 static GAME_TEXT KEY_FIRST[] = "first";
173 static GAME_TEXT KEY_SECOND[] = "second";
174 static GAME_TEXT KEY_THIRD[] = "third";
175 static GAME_TEXT KEY_FOURTH[] = "fourth";
176 static GAME_TEXT KEY_ITEMS[] = "items";
177 static GAME_TEXT KEY_WEAPONS[] = "weapons";
178 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "favorite weapons";
179 static GAME_TEXT KEY_ARMORS[] = "armors";
180 static GAME_TEXT KEY_MISSILES[] = "missiles";
181 static GAME_TEXT KEY_DEVICES[] = "magical devices";
182 static GAME_TEXT KEY_LIGHTS[] = "lights";
183 static GAME_TEXT KEY_JUNKS[] = "junks";
184 static GAME_TEXT KEY_CORPSES[] = "corpses or skeletons";
185 static GAME_TEXT KEY_SPELLBOOKS[] = "spellbooks";
186 static GAME_TEXT KEY_HAFTED[] = "hafted weapons";
187 static GAME_TEXT KEY_SHIELDS[] = "shields";
188 static GAME_TEXT KEY_BOWS[] = "bows";
189 static GAME_TEXT KEY_RINGS[] = "rings";
190 static GAME_TEXT KEY_AMULETS[] = "amulets";
191 static GAME_TEXT KEY_SUITS[] = "suits";
192 static GAME_TEXT KEY_CLOAKS[] = "cloaks";
193 static GAME_TEXT KEY_HELMS[] = "helms";
194 static GAME_TEXT KEY_GLOVES[] = "gloves";
195 static GAME_TEXT KEY_BOOTS[] = "boots";
199 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
200 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
201 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
202 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
205 #define ADD_KEY(KEY) strcat(ptr, KEY)
207 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
209 #define ADD_KEY2(KEY) strcat(ptr, KEY)
211 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
212 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
213 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
214 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
217 static char kanji_colon[] = ":";
222 * 自動拾い/破壊設定のリストに関する変数 / List for auto-picker/destroyer entries
224 int max_autopick = 0; /*!< 現在登録している自動拾い/破壊設定の数 */
225 int max_max_autopick = 0; /*!< 自動拾い/破壊設定の限界数 */
226 autopick_type *autopick_list = NULL; /*!< 自動拾い/破壊設定構造体のポインタ配列 */
229 * A function to create new entry
231 static bool autopick_new_entry(autopick_type *entry, concptr str, bool allow_default)
236 char buf[MAX_LINELEN];
237 concptr prev_ptr, ptr, old_ptr;
240 if (str[0] && str[1] == ':') switch (str[0])
243 case 'A': case 'P': case 'C':
247 entry->flag[0] = entry->flag[1] = 0L;
251 act = DO_AUTOPICK | DO_DISPLAY;
254 if ((act & DO_AUTOPICK) && *str == '!')
257 act |= DO_AUTODESTROY;
260 else if ((act & DO_AUTOPICK) && *str == '~')
263 act |= DONT_AUTOPICK;
266 else if ((act & DO_AUTOPICK) && *str == ';')
269 act |= DO_QUERY_AUTOPICK;
272 else if ((act & DO_DISPLAY) && *str == '(')
281 /* don't mind upper or lower case */
283 for (i = 0; *str; i++)
294 /* Auto-inscription? */
302 if (isupper(c)) c = (char)tolower(c);
308 /* Skip empty line unless allow_default */
309 if (!allow_default && *buf == 0) return FALSE;
311 /* Skip comment line */
312 if (*buf == 0 && insc) return FALSE;
314 ptr = prev_ptr = buf;
317 while (old_ptr != ptr)
319 /* Save current location */
322 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
323 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
324 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
325 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
326 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
327 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
328 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
330 /*** Weapons whose dd*ds is more than nn ***/
331 if (MATCH_KEY2(KEY_MORE_THAN))
336 /* Drop leading spaces */
337 while (' ' == *ptr) ptr++;
340 while ('0' <= *ptr && *ptr <= '9')
342 entry->dice = 10 * entry->dice + (*ptr - '0');
349 (void)MATCH_KEY(KEY_DICE);
350 ADD_FLG(FLG_MORE_DICE);
356 /*** Items whose magical bonus is more than n ***/
357 if (MATCH_KEY2(KEY_MORE_BONUS))
362 /* Drop leading spaces */
363 while (' ' == *ptr) ptr++;
366 while ('0' <= *ptr && *ptr <= '9')
368 entry->bonus = 10 * entry->bonus + (*ptr - '0');
376 (void)MATCH_KEY(KEY_MORE_BONUS2);
378 if (' ' == *ptr) ptr++;
380 ADD_FLG(FLG_MORE_BONUS);
386 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
387 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
388 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
389 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
390 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
391 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
392 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
393 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
394 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
395 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
396 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
397 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
398 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
399 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
400 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
401 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
402 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
405 /* Not yet found any noun */
408 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
410 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
411 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
412 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
413 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
414 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
415 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
416 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
417 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
418 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
419 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
420 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
421 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
422 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
423 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
424 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
425 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
426 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
427 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
428 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
429 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
431 /* Last 'keyword' must be at the correct location */
435 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
438 else if (*ptr == '\0')
440 /* There was no noun */
443 /* Add extra word "items" */
444 ADD_FLG_NOUN(FLG_ITEMS);
451 /* A noun type keyword didn't end correctly */
452 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
457 /* Save this auto-picker entry line */
458 entry->name = string_make(ptr);
460 entry->insc = string_make(insc);
467 * Get auto-picker entry from o_ptr.
469 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
471 /* Assume that object name is to be added */
475 /* エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない */
476 bool bol_mark = FALSE;
478 /* We can always use the ^ mark in English */
479 bool bol_mark = TRUE;
482 GAME_TEXT name_str[MAX_NLEN];
484 /* Initialize name string */
487 entry->insc = string_make(quark_str(o_ptr->inscription));
488 entry->action = DO_AUTOPICK | DO_DISPLAY;
489 entry->flag[0] = entry->flag[1] = 0L;
493 if (!object_is_aware(o_ptr))
495 ADD_FLG(FLG_UNAWARE);
499 /* Not really identified */
500 else if (!object_is_known(o_ptr))
502 if (!(o_ptr->ident & IDENT_SENSE))
504 ADD_FLG(FLG_UNIDENTIFIED);
509 /* Pseudo-identified */
510 switch (o_ptr->feeling)
514 ADD_FLG(FLG_NAMELESS);
520 ADD_FLG(FLG_NAMELESS);
521 ADD_FLG(FLG_WORTHLESS);
527 ADD_FLG(FLG_WORTHLESS);
535 /* XXX No appropriate flag */
540 /* Never reach here */
550 if (object_is_ego(o_ptr))
552 if (object_is_weapon_armour_ammo(o_ptr))
555 * Base name of ego weapons and armors
556 * are almost meaningless.
557 * Register the ego type only.
559 ego_item_type *e_ptr = &e_info[o_ptr->name2];
561 /* エゴ銘には「^」マークが使える */
562 sprintf(name_str, "^%s", e_name + e_ptr->name);
564 /* We ommit the basename and cannot use the ^ mark */
565 strcpy(name_str, e_name + e_ptr->name);
568 /* Don't use the object description */
571 /* Restrict to 'common' equipments */
572 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
579 else if (object_is_artifact(o_ptr))
580 ADD_FLG(FLG_ARTIFACT);
582 /* Non-ego, non-artifact */
585 /* Wearable nameless object */
586 if (object_is_equipment(o_ptr))
587 ADD_FLG(FLG_NAMELESS);
594 /* Melee weapon with boosted dice */
595 if (object_is_melee_weapon(o_ptr))
597 object_kind *k_ptr = &k_info[o_ptr->k_idx];
599 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
600 ADD_FLG(FLG_BOOSTED);
603 /* Wanted monster's corpse */
604 if (object_is_shoukinkubi(o_ptr))
606 REM_FLG(FLG_WORTHLESS);
610 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
611 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
616 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
621 if (o_ptr->tval >= TV_LIFE_BOOK &&
622 !check_book_realm(o_ptr->tval, o_ptr->sval))
624 ADD_FLG(FLG_UNREADABLE);
625 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
628 if (REALM1_BOOK == o_ptr->tval &&
629 p_ptr->pclass != CLASS_SORCERER &&
630 p_ptr->pclass != CLASS_RED_MAGE)
636 if (REALM2_BOOK == o_ptr->tval &&
637 p_ptr->pclass != CLASS_SORCERER &&
638 p_ptr->pclass != CLASS_RED_MAGE)
644 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
646 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
648 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
650 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
653 if (object_is_ammo(o_ptr))
654 ADD_FLG(FLG_MISSILES);
655 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
656 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
657 ADD_FLG(FLG_DEVICES);
658 else if (o_ptr->tval == TV_LITE)
660 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
661 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
663 else if (o_ptr->tval == TV_CORPSE)
664 ADD_FLG(FLG_CORPSES);
665 else if (o_ptr->tval >= TV_LIFE_BOOK)
666 ADD_FLG(FLG_SPELLBOOKS);
667 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
668 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
669 ADD_FLG(FLG_WEAPONS);
670 else if (o_ptr->tval == TV_SHIELD)
671 ADD_FLG(FLG_SHIELDS);
672 else if (o_ptr->tval == TV_BOW)
674 else if (o_ptr->tval == TV_RING)
676 else if (o_ptr->tval == TV_AMULET)
677 ADD_FLG(FLG_AMULETS);
678 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
679 o_ptr->tval == TV_SOFT_ARMOR)
681 else if (o_ptr->tval == TV_CLOAK)
683 else if (o_ptr->tval == TV_HELM)
685 else if (o_ptr->tval == TV_GLOVES)
687 else if (o_ptr->tval == TV_BOOTS)
690 /* Prepare the object description */
693 GAME_TEXT o_name[MAX_NLEN];
695 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
698 * If necessary, add a '^' which indicates the
701 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
704 /* Register the name in lowercase */
705 str_tolower(name_str);
706 entry->name = string_make(name_str);
713 * A function to delete entry
715 static void autopick_free_entry(autopick_type *entry)
717 string_free(entry->name);
718 string_free(entry->insc);
724 #define MAX_AUTOPICK_DEFAULT 200
727 * Initialize the autopick
729 static void init_autopick(void)
731 static const char easy_autopick_inscription[] = "(:=g";
737 max_max_autopick = MAX_AUTOPICK_DEFAULT;
738 C_MAKE(autopick_list, max_max_autopick, autopick_type);
742 /* Clear old entries */
743 for( i = 0; i < max_autopick; i++)
744 autopick_free_entry(&autopick_list[i]);
748 /* There is always one entry "=g" */
749 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
750 autopick_list[max_autopick++] = entry;
755 #define PT_WITH_PNAME 1
758 * Get file name for autopick preference
760 static concptr pickpref_filename(int filename_mode)
762 static const char namebase[] = _("picktype", "pickpref");
764 switch (filename_mode)
767 return format("%s.prf", namebase);
770 return format("%s-%s.prf", namebase, player_base);
779 * Load an autopick preference file
781 void autopick_load_pref(bool disp_mes)
786 /* Free old entries */
789 /* Try a filename with player name */
790 my_strcpy(buf, pickpref_filename(PT_WITH_PNAME), sizeof(buf));
793 err = process_autopick_file(buf);
795 if (err == 0 && disp_mes)
798 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
804 /* Use default name */
805 my_strcpy(buf, pickpref_filename(PT_DEFAULT), sizeof(buf));
808 err = process_autopick_file(buf);
810 if (err == 0 && disp_mes)
813 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
820 msg_print(_("自動拾い設定ファイルの読み込みに失敗しました。", "Failed to reload autopick preference."));
826 * Add one line to autopick_list[]
828 static void add_autopick_list(autopick_type *entry)
830 /* There is no enough space to add one line */
831 if (max_autopick >= max_max_autopick)
833 int old_max_max_autopick = max_max_autopick;
834 autopick_type *old_autopick_list = autopick_list;
836 /* Increase size of list */
837 max_max_autopick += MAX_AUTOPICK_DEFAULT;
840 C_MAKE(autopick_list, max_max_autopick, autopick_type);
842 /* Copy from old list to new list */
843 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
846 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
850 autopick_list[max_autopick] = *entry;
857 * Process line for auto picker/destroyer.
859 errr process_autopick_file_command(char *buf)
861 autopick_type an_entry, *entry = &an_entry;
864 /* Nuke illegal char */
865 for(i = 0; buf[i]; i++)
874 if (iswspace(buf[i]) && buf[i] != ' ')
879 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
881 /* Already has the same entry? */
882 for(i = 0; i < max_autopick; i++)
883 if(!strcmp(entry->name, autopick_list[i].name)
884 && entry->flag[0] == autopick_list[i].flag[0]
885 && entry->flag[1] == autopick_list[i].flag[1]
886 && entry->dice == autopick_list[i].dice
887 && entry->bonus == autopick_list[i].bonus)
889 autopick_free_entry(entry);
893 add_autopick_list(entry);
899 * Reconstruct preference line from entry
901 concptr autopick_line_from_entry(autopick_type *entry)
903 char buf[MAX_LINELEN];
905 bool sepa_flag = TRUE;
908 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
909 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
910 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
911 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
915 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
916 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
917 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
918 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
919 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
920 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
921 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
923 if (IS_FLG(FLG_MORE_DICE))
925 ADD_KEY(KEY_MORE_THAN);
926 strcat(ptr, format("%d", entry->dice));
930 if (IS_FLG(FLG_MORE_BONUS))
932 ADD_KEY(KEY_MORE_BONUS);
933 strcat(ptr, format("%d", entry->bonus));
934 ADD_KEY(KEY_MORE_BONUS2);
937 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
938 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
939 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
940 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
941 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
942 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
943 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
944 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
945 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
946 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
947 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
948 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
949 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
950 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
951 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
952 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
953 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
955 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
957 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
958 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
959 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
960 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
961 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
962 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
963 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
964 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
965 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
966 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
967 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
968 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
969 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
970 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
971 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
972 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
973 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
974 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
975 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
976 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
978 /* You don't need sepalator after adjective */
979 /* 'artifact' is not true adjective */
980 else if (!IS_FLG(FLG_ARTIFACT))
983 if (entry->name && entry->name[0])
987 if (sepa_flag) strcat(buf, ":");
990 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
993 if (iskanji(entry->name[j]))
994 buf[i++] = entry->name[j++];
996 buf[i++] = entry->name[j++];
1007 while (entry->insc[j] && i < MAX_LINELEN - 2)
1010 if (iskanji(entry->insc[j]))
1011 buf[i++] = entry->insc[j++];
1013 buf[i++] = entry->insc[j++];
1018 return string_make(buf);
1023 * Reconstruct preference line from entry and kill entry
1025 static concptr autopick_line_from_entry_kill(autopick_type *entry)
1027 concptr ptr = autopick_line_from_entry(entry);
1029 /* Free memory for original entry */
1030 autopick_free_entry(entry);
1037 * A function for Auto-picker/destroyer
1038 * Examine whether the object matches to the entry
1040 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_name)
1043 concptr ptr = entry->name;
1045 /*** Unaware items ***/
1046 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1049 /*** Unidentified ***/
1050 if (IS_FLG(FLG_UNIDENTIFIED)
1051 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1054 /*** Identified ***/
1055 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1058 /*** *Identified* ***/
1059 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1060 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1063 /*** Dice boosted (weapon of slaying) ***/
1064 if (IS_FLG(FLG_BOOSTED))
1066 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1068 /* Require melee weapon */
1069 if (!object_is_melee_weapon(o_ptr))
1072 /* Require boosted dice */
1073 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1076 /* In Vault Quest, Dice must be hide.*/
1077 if(!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
1083 /*** Weapons which dd*ds is more than nn ***/
1084 if (IS_FLG(FLG_MORE_DICE))
1086 if (o_ptr->dd * o_ptr->ds < entry->dice)
1090 /*** Weapons whic dd*ds is more than nn ***/
1091 if (IS_FLG(FLG_MORE_BONUS))
1093 if (!object_is_known(o_ptr)) return FALSE;
1097 if (o_ptr->pval < entry->bonus) return FALSE;
1101 if (o_ptr->to_h < entry->bonus &&
1102 o_ptr->to_d < entry->bonus &&
1103 o_ptr->to_a < entry->bonus &&
1104 o_ptr->pval < entry->bonus)
1109 /*** Worthless items ***/
1110 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1113 /*** Artifact object ***/
1114 if (IS_FLG(FLG_ARTIFACT))
1116 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1120 /*** Ego object ***/
1121 if (IS_FLG(FLG_EGO))
1123 /* Need to be an ego item */
1124 if (!object_is_ego(o_ptr)) return FALSE;
1126 /* Need to be known to be an ego */
1127 if (!object_is_known(o_ptr) &&
1128 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1133 if (IS_FLG(FLG_GOOD))
1135 if (!object_is_equipment(o_ptr)) return FALSE;
1138 if (object_is_known(o_ptr))
1140 /* Artifacts and Ego objects are not okay */
1141 if (!object_is_nameless(o_ptr))
1144 /* Average are not okay */
1145 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1149 /* Pseudo-identified */
1150 else if (o_ptr->ident & IDENT_SENSE)
1152 switch (o_ptr->feeling)
1167 /* Not known to be good */
1173 if (IS_FLG(FLG_NAMELESS))
1175 if (!object_is_equipment(o_ptr)) return FALSE;
1178 if (object_is_known(o_ptr))
1180 /* Artifacts and Ego objects are not okay */
1181 if (!object_is_nameless(o_ptr))
1185 /* Pseudo-identified */
1186 else if (o_ptr->ident & IDENT_SENSE)
1188 switch (o_ptr->feeling)
1198 /* It's not nameless */
1206 /* Not known to be nameless */
1212 if (IS_FLG(FLG_AVERAGE))
1214 if (!object_is_equipment(o_ptr)) return FALSE;
1217 if (object_is_known(o_ptr))
1219 /* Artifacts and Ego objects are not okay */
1220 if (!object_is_nameless(o_ptr))
1223 /* Cursed or broken objects are not okay */
1224 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1227 /* Good are not okay */
1228 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1232 /* Pseudo-identified */
1233 else if (o_ptr->ident & IDENT_SENSE)
1235 switch (o_ptr->feeling)
1242 /* It's not average */
1250 /* Not known to be average */
1255 /*** Rere equipments ***/
1256 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1259 /*** Common equipments ***/
1260 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1263 /*** Wanted monster's corpse/skeletons ***/
1264 if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
1267 /*** Unique monster's corpse/skeletons/statues ***/
1268 if (IS_FLG(FLG_UNIQUE) &&
1269 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1270 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1273 /*** Human corpse/skeletons (for Daemon magic) ***/
1274 if (IS_FLG(FLG_HUMAN) &&
1275 (o_ptr->tval != TV_CORPSE ||
1276 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1279 /*** Unreadable spellbooks ***/
1280 if (IS_FLG(FLG_UNREADABLE) &&
1281 (o_ptr->tval < TV_LIFE_BOOK ||
1282 check_book_realm(o_ptr->tval, o_ptr->sval)))
1285 /*** First realm spellbooks ***/
1286 if (IS_FLG(FLG_REALM1) &&
1287 (REALM1_BOOK != o_ptr->tval ||
1288 p_ptr->pclass == CLASS_SORCERER ||
1289 p_ptr->pclass == CLASS_RED_MAGE))
1292 /*** Second realm spellbooks ***/
1293 if (IS_FLG(FLG_REALM2) &&
1294 (REALM2_BOOK != o_ptr->tval ||
1295 p_ptr->pclass == CLASS_SORCERER ||
1296 p_ptr->pclass == CLASS_RED_MAGE))
1299 /*** First rank spellbooks ***/
1300 if (IS_FLG(FLG_FIRST) &&
1301 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1304 /*** Second rank spellbooks ***/
1305 if (IS_FLG(FLG_SECOND) &&
1306 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1309 /*** Third rank spellbooks ***/
1310 if (IS_FLG(FLG_THIRD) &&
1311 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1314 /*** Fourth rank spellbooks ***/
1315 if (IS_FLG(FLG_FOURTH) &&
1316 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1320 if (IS_FLG(FLG_WEAPONS))
1322 if (!object_is_weapon(o_ptr))
1325 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1327 if (!object_is_favorite(o_ptr))
1330 else if (IS_FLG(FLG_ARMORS))
1332 if (!object_is_armour(o_ptr))
1335 else if (IS_FLG(FLG_MISSILES))
1337 if (!object_is_ammo(o_ptr)) return FALSE;
1339 else if (IS_FLG(FLG_DEVICES))
1343 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1345 default: return FALSE;
1348 else if (IS_FLG(FLG_LIGHTS))
1350 if (!(o_ptr->tval == TV_LITE))
1353 else if (IS_FLG(FLG_JUNKS))
1357 case TV_SKELETON: case TV_BOTTLE:
1358 case TV_JUNK: case TV_STATUE:
1360 default: return FALSE;
1363 else if (IS_FLG(FLG_CORPSES))
1365 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1368 else if (IS_FLG(FLG_SPELLBOOKS))
1370 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1373 else if (IS_FLG(FLG_HAFTED))
1375 if (!(o_ptr->tval == TV_HAFTED))
1378 else if (IS_FLG(FLG_SHIELDS))
1380 if (!(o_ptr->tval == TV_SHIELD))
1383 else if (IS_FLG(FLG_BOWS))
1385 if (!(o_ptr->tval == TV_BOW))
1388 else if (IS_FLG(FLG_RINGS))
1390 if (!(o_ptr->tval == TV_RING))
1393 else if (IS_FLG(FLG_AMULETS))
1395 if (!(o_ptr->tval == TV_AMULET))
1398 else if (IS_FLG(FLG_SUITS))
1400 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1401 o_ptr->tval == TV_HARD_ARMOR ||
1402 o_ptr->tval == TV_SOFT_ARMOR))
1405 else if (IS_FLG(FLG_CLOAKS))
1407 if (!(o_ptr->tval == TV_CLOAK))
1410 else if (IS_FLG(FLG_HELMS))
1412 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1415 else if (IS_FLG(FLG_GLOVES))
1417 if (!(o_ptr->tval == TV_GLOVES))
1420 else if (IS_FLG(FLG_BOOTS))
1422 if (!(o_ptr->tval == TV_BOOTS))
1426 /* Keyword don't match */
1430 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1434 if (!my_strstr(o_name, ptr)) return FALSE;
1437 /* TRUE when it need not to be 'collecting' */
1438 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1440 /* Check if there is a same item */
1441 for (j = 0; j < INVEN_PACK; j++)
1444 * 'Collecting' means the item must be absorbed
1445 * into an p_ptr->inventory_list slot.
1446 * But an item can not be absorbed into itself!
1448 if ((&p_ptr->inventory_list[j] != o_ptr) &&
1449 object_similar(&p_ptr->inventory_list[j], o_ptr))
1453 /* Not collecting */
1459 * A function for Auto-picker/destroyer
1460 * Examine whether the object matches to the list of keywords or not.
1462 int is_autopick(object_type *o_ptr)
1465 GAME_TEXT o_name[MAX_NLEN];
1467 if (o_ptr->tval == TV_GOLD) return -1;
1469 /* Prepare object name string first */
1470 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1472 /* Convert the string to lower case */
1473 str_tolower(o_name);
1475 /* Look for a matching entry in the list */
1476 for (i=0; i < max_autopick; i++)
1478 autopick_type *entry = &autopick_list[i];
1480 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1483 /* No matching entry */
1491 static void auto_inscribe_item(object_type *o_ptr, int idx)
1493 /* Are there auto-inscription? */
1494 if (idx < 0 || !autopick_list[idx].insc) return;
1496 if (!o_ptr->inscription)
1497 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1499 /* Redraw inscription */
1500 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1502 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1503 p_ptr->update |= (PU_BONUS);
1508 * Automatically destroy items in this grid.
1510 static bool is_opt_confirm_destroy(object_type *o_ptr)
1512 if (!destroy_items) return FALSE;
1514 /* Known to be worthless? */
1516 if (object_value(o_ptr) > 0) return FALSE;
1519 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1522 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1526 if (object_is_shoukinkubi(o_ptr)) return FALSE;
1530 if (o_ptr->tval == TV_CORPSE) return FALSE;
1533 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1537 if (p_ptr->prace == RACE_DEMON)
1539 if (o_ptr->tval == TV_CORPSE &&
1540 o_ptr->sval == SV_CORPSE &&
1541 my_strchr("pht", r_info[o_ptr->pval].d_char))
1545 if (p_ptr->pclass == CLASS_ARCHER)
1547 if (o_ptr->tval == TV_SKELETON ||
1548 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1551 else if (p_ptr->pclass == CLASS_NINJA)
1553 if (o_ptr->tval == TV_LITE &&
1554 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1557 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1558 p_ptr->pclass == CLASS_CAVALRY)
1560 if (o_ptr->tval == TV_WAND &&
1561 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1566 if (o_ptr->tval == TV_GOLD) return FALSE;
1573 * Automatically destroy an item if it is to be destroyed
1575 * When always_pickup is 'yes', we disable auto-destroyer function of
1576 * auto-picker/destroyer, and do only easy-auto-destroyer.
1578 static object_type autopick_last_destroyed_object;
1580 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1582 bool destroy = FALSE;
1584 /* Easy-Auto-Destroyer (3rd priority) */
1585 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1587 /* Protected by auto-picker (2nd priotity) */
1588 if (autopick_idx >= 0 &&
1589 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1592 /* Auto-destroyer works only when !always_pickup */
1595 /* Auto-picker/destroyer (1st priority) */
1596 if (autopick_idx >= 0 &&
1597 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1601 /* Not to be destroyed */
1602 if (!destroy) return;
1604 /* Now decided to destroy */
1606 disturb(FALSE, FALSE);
1609 if (!can_player_destroy_object(o_ptr))
1611 GAME_TEXT o_name[MAX_NLEN];
1613 /* Describe the object (with {terrible/special}) */
1614 object_desc(o_name, o_ptr, 0);
1616 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1621 /* Record name of destroyed item */
1622 (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1625 o_ptr->marked |= OM_AUTODESTROY;
1626 p_ptr->update |= PU_AUTODESTROY;
1633 * Auto-destroy marked item
1635 static void autopick_delayed_alter_aux(INVENTORY_IDX item)
1639 /* Get the item (in the pack) */
1640 if (item >= 0) o_ptr = &p_ptr->inventory_list[item];
1642 /* Get the item (on the floor) */
1643 else o_ptr = ¤t_floor_ptr->o_list[0 - item];
1645 if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
1647 GAME_TEXT o_name[MAX_NLEN];
1649 /* Describe the object (with {terrible/special}) */
1650 object_desc(o_name, o_ptr, 0);
1652 /* Eliminate the item (from the pack) */
1655 inven_item_increase(item, -(o_ptr->number));
1656 inven_item_optimize(item);
1659 /* Eliminate the item (from the floor) */
1662 delete_object_idx(0 - item);
1665 msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name);
1671 * Auto-destroy marked items in inventry and on floor
1673 void autopick_delayed_alter(void)
1678 * Scan inventry in reverse order to prevent
1679 * skipping after inven_item_optimize()
1681 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1682 autopick_delayed_alter_aux(item);
1684 /* Scan the pile of objects */
1685 item = current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx;
1688 OBJECT_IDX next = current_floor_ptr->o_list[item].next_o_idx;
1689 autopick_delayed_alter_aux(-item);
1696 * Auto-inscription and/or destroy
1698 * Auto-destroyer works only on p_ptr->inventory_list or on floor stack only when
1701 void autopick_alter_item(INVENTORY_IDX item, bool destroy)
1706 /* Get the item (in the pack) */
1707 if (item >= 0) o_ptr = &p_ptr->inventory_list[item];
1709 /* Get the item (on the floor) */
1710 else o_ptr = ¤t_floor_ptr->o_list[0 - item];
1712 /* Get the index in the auto-pick/destroy list */
1713 idx = is_autopick(o_ptr);
1715 /* Do auto-inscription */
1716 auto_inscribe_item(o_ptr, idx);
1718 /* Do auto-destroy if needed */
1719 if (destroy && item <= INVEN_PACK)
1720 auto_destroy_item(o_ptr, idx);
1725 * Automatically pickup/destroy items in this grid.
1727 void autopick_pickup_items(grid_type *g_ptr)
1729 OBJECT_IDX this_o_idx, next_o_idx = 0;
1731 /* Scan the pile of objects */
1732 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1735 object_type *o_ptr = ¤t_floor_ptr->o_list[this_o_idx];
1736 next_o_idx = o_ptr->next_o_idx;
1738 idx = is_autopick(o_ptr);
1740 /* Item index for floor -1,-2,-3,... */
1741 auto_inscribe_item(o_ptr, idx);
1744 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1746 disturb(FALSE, FALSE);
1748 if (!inven_carry_okay(o_ptr))
1750 GAME_TEXT o_name[MAX_NLEN];
1752 object_desc(o_name, o_ptr, 0);
1754 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
1755 /* Hack - remember that the item has given a message here. */
1756 o_ptr->marked |= OM_NOMSG;
1760 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1762 char out_val[MAX_NLEN+20];
1763 GAME_TEXT o_name[MAX_NLEN];
1765 if (o_ptr->marked & OM_NO_QUERY)
1767 /* Already answered as 'No' */
1771 object_desc(o_name, o_ptr, 0);
1773 sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
1775 if (!get_check(out_val))
1777 /* Hack - remember that the item has given a message here. */
1778 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1783 py_pickup_aux(this_o_idx);
1788 * When always_pickup is 'yes', we disable
1789 * auto-destroyer from autopick function, and do only
1790 * easy-auto-destroyer.
1794 auto_destroy_item(o_ptr, idx);
1800 static const char autoregister_header[] = "?:$AUTOREGISTER";
1803 * Clear auto registered lines in the picktype.prf .
1805 static bool clear_auto_register(void)
1807 char tmp_file[1024];
1808 char pref_file[1024];
1813 bool autoregister = FALSE;
1816 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1817 pref_fff = my_fopen(pref_file, "r");
1821 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1822 pref_fff = my_fopen(pref_file, "r");
1831 /* Open a new (temporary) file */
1832 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1836 /* Close the preference file */
1838 msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
1844 /* Loop for every line */
1848 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1852 /* Delete auto-registered line */
1854 /* Count auto-destroy preference lines */
1855 if (buf[0] != '#' && buf[0] != '?') num++;
1858 /* We are looking for auto-registered line */
1861 if (streq(buf, autoregister_header))
1863 /* Delete all further lines */
1864 autoregister = TRUE;
1868 /* Copy orginally lines */
1869 fprintf(tmp_fff, "%s\n", buf);
1875 my_fclose(pref_fff);
1880 msg_format(_("以前のキャラクター用の自動設定(%d行)が残っています。",
1881 "Auto registered lines (%d lines) for previous character are remaining."), num);
1882 strcpy(buf, _("古い設定行は削除します。よろしいですか?", "These lines will be deleted. Are you sure? "));
1884 /* You can cancel it */
1885 if (!get_check(buf))
1888 autoregister = FALSE;
1890 msg_print(_("エディタのカット&ペースト等を使って必要な行を避難してください。",
1891 "Use cut & paste of auto picker editor (_) to keep old prefs."));
1896 /* If there are some changes, overwrite the original file with new one */
1899 /* Copy contents of temporary file */
1901 tmp_fff = my_fopen(tmp_file, "r");
1902 pref_fff = my_fopen(pref_file, "w");
1904 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1905 fprintf(pref_fff, "%s\n", buf);
1907 my_fclose(pref_fff);
1911 /* Kill the temporary file */
1919 * Automatically register an auto-destroy preference line
1921 bool autopick_autoregister(object_type *o_ptr)
1924 char pref_file[1024];
1926 autopick_type an_entry, *entry = &an_entry;
1928 int match_autopick = is_autopick(o_ptr);
1930 /* Already registered */
1931 if (match_autopick != -1)
1934 byte act = autopick_list[match_autopick].action;
1936 if (act & DO_AUTOPICK) what = _("自動で拾う", "auto-pickup");
1937 else if (act & DO_AUTODESTROY) what = _("自動破壊する", "auto-destroy");
1938 else if (act & DONT_AUTOPICK) what = _("放置する", "leave on floor");
1939 else /* if (act & DO_QUERY_AUTOPICK) */ what = _("確認して拾う", "query auto-pickup");
1941 msg_format(_("そのアイテムは既に%sように設定されています。", "The object is already registered to %s."), what);
1945 /* Known to be an artifact? */
1946 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
1947 ((o_ptr->ident & IDENT_SENSE) &&
1948 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
1950 GAME_TEXT o_name[MAX_NLEN];
1952 /* Describe the object (with {terrible/special}) */
1953 object_desc(o_name, o_ptr, 0);
1955 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
1961 if (!p_ptr->autopick_autoregister)
1963 /* Clear old auto registered lines */
1964 if (!clear_auto_register()) return FALSE;
1967 /* Try a filename with player name */
1968 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1969 pref_fff = my_fopen(pref_file, "r");
1973 /* Use default name */
1974 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1975 pref_fff = my_fopen(pref_file, "r");
1978 /* Check the header */
1982 if (my_fgets(pref_fff, buf, sizeof(buf)))
1984 /* No header found */
1985 p_ptr->autopick_autoregister = FALSE;
1990 if (streq(buf, autoregister_header))
1992 /* Found the header */
1993 p_ptr->autopick_autoregister = TRUE;
1999 /* Close read only FILE* */
2002 /* Open for append */
2003 pref_fff = my_fopen(pref_file, "a");
2007 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), pref_file);
2014 if (!p_ptr->autopick_autoregister)
2016 /* Add the header */
2017 fprintf(pref_fff, "%s\n", autoregister_header);
2019 fprintf(pref_fff, "%s\n", _("# *警告!!* 以降の行は自動登録されたものです。",
2020 "# *Waring!* The lines below will be deleated later."));
2021 fprintf(pref_fff, "%s\n", _("# 後で自動的に削除されますので、必要な行は上の方へ移動しておいてください。",
2022 "# Keep it by cut & paste if you need these lines for future characters."));
2024 /* Now auto register is in-use */
2025 p_ptr->autopick_autoregister = TRUE;
2028 /* Get a preference entry */
2029 autopick_entry_from_object(entry, o_ptr);
2031 /* Set to auto-destroy (with no-display) */
2032 entry->action = DO_AUTODESTROY;
2034 /* Load the new line as preference */
2035 add_autopick_list(entry);
2037 /* Add a line to the file */
2038 /* Don't kill "entry" */
2039 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
2046 /******** Auto-picker/destroyer editor **********/
2048 #define MAX_YANK MAX_LINELEN
2049 #define MAX_LINES 3000
2051 #define MARK_MARK 0x01
2052 #define MARK_BY_SHIFT 0x02
2054 #define LSTAT_BYPASS 0x01
2055 #define LSTAT_EXPRESSION 0x02
2056 #define LSTAT_AUTOREGISTER 0x04
2058 #define QUIT_WITHOUT_SAVE 1
2059 #define QUIT_AND_SAVE 2
2062 * Struct for yank buffer
2064 typedef struct chain_str {
2065 struct chain_str *next;
2071 * Data struct for text editor
2077 int old_wid, old_hgt;
2079 int old_upper, old_left;
2083 object_type *search_o_ptr;
2085 concptr last_destroyed;
2087 chain_str_type *yank;
2090 concptr *lines_list;
2091 byte states[MAX_LINES];
2103 * Dirty flag for text editor
2105 #define DIRTY_ALL 0x0001
2106 #define DIRTY_MODE 0x0004
2107 #define DIRTY_SCREEN 0x0008
2108 #define DIRTY_NOT_FOUND 0x0010
2109 #define DIRTY_NO_SEARCH 0x0020
2110 #define DIRTY_EXPRESSION 0x0040
2111 #define DIRTY_SKIP_INACTIVE 0x0080
2112 #define DIRTY_INACTIVE 0x0100
2115 * Describe which kind of object is Auto-picked/destroyed
2117 static void describe_autopick(char *buff, autopick_type *entry)
2119 concptr str = entry->name;
2120 byte act = entry->action;
2121 concptr insc = entry->insc;
2127 concptr before_str[100], body_str;
2132 /*** Collecting items ***/
2133 /*** Which can be absorbed into a slot as a bundle ***/
2134 if (IS_FLG(FLG_COLLECTING))
2135 before_str[before_n++] = "収集中で既に持っているスロットにまとめられる";
2137 /*** Unaware items ***/
2138 if (IS_FLG(FLG_UNAWARE))
2139 before_str[before_n++] = "未鑑定でその効果も判明していない";
2141 /*** Unidentified ***/
2142 if (IS_FLG(FLG_UNIDENTIFIED))
2143 before_str[before_n++] = "未鑑定の";
2145 /*** Identified ***/
2146 if (IS_FLG(FLG_IDENTIFIED))
2147 before_str[before_n++] = "鑑定済みの";
2149 /*** *Identified* ***/
2150 if (IS_FLG(FLG_STAR_IDENTIFIED))
2151 before_str[before_n++] = "完全に鑑定済みの";
2153 /*** Dice boosted (weapon of slaying) ***/
2154 if (IS_FLG(FLG_BOOSTED))
2156 before_str[before_n++] = "ダメージダイスが通常より大きい";
2160 /*** Weapons whose dd*ds is more than nn ***/
2161 if (IS_FLG(FLG_MORE_DICE))
2163 static char more_than_desc_str[] = "___";
2164 before_str[before_n++] = "ダメージダイスの最大値が";
2167 sprintf(more_than_desc_str,"%d", entry->dice);
2168 before_str[before_n++] = more_than_desc_str;
2169 before_str[before_n++] = "以上の";
2172 /*** Items whose magical bonus is more than nn ***/
2173 if (IS_FLG(FLG_MORE_BONUS))
2175 static char more_bonus_desc_str[] = "___";
2176 before_str[before_n++] = "修正値が(+";
2178 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2179 before_str[before_n++] = more_bonus_desc_str;
2180 before_str[before_n++] = ")以上の";
2183 /*** Worthless items ***/
2184 if (IS_FLG(FLG_WORTHLESS))
2185 before_str[before_n++] = "店で無価値と判定される";
2188 if (IS_FLG(FLG_ARTIFACT))
2190 before_str[before_n++] = "アーティファクトの";
2195 if (IS_FLG(FLG_EGO))
2197 before_str[before_n++] = "エゴアイテムの";
2202 if (IS_FLG(FLG_GOOD))
2204 before_str[before_n++] = "上質の";
2209 if (IS_FLG(FLG_NAMELESS))
2211 before_str[before_n++] = "エゴでもアーティファクトでもない";
2216 if (IS_FLG(FLG_AVERAGE))
2218 before_str[before_n++] = "並の";
2222 /*** Rare equipments ***/
2223 if (IS_FLG(FLG_RARE))
2225 before_str[before_n++] = "ドラゴン装備やカオス・ブレード等を含む珍しい";
2229 /*** Common equipments ***/
2230 if (IS_FLG(FLG_COMMON))
2232 before_str[before_n++] = "ありふれた(ドラゴン装備やカオス・ブレード等の珍しい物ではない)";
2236 /*** Wanted monster's corpse/skeletons ***/
2237 if (IS_FLG(FLG_WANTED))
2239 before_str[before_n++] = "ハンター事務所で賞金首とされている";
2243 /*** Human corpse/skeletons (for Daemon magic) ***/
2244 if (IS_FLG(FLG_HUMAN))
2246 before_str[before_n++] = "悪魔魔法で使うための人間やヒューマノイドの";
2250 /*** Unique monster's corpse/skeletons/statues ***/
2251 if (IS_FLG(FLG_UNIQUE))
2253 before_str[before_n++] = "ユニークモンスターの";
2257 /*** Unreadable spellbooks ***/
2258 if (IS_FLG(FLG_UNREADABLE))
2260 before_str[before_n++] = "あなたが読めない領域の";
2264 /*** First realm spellbooks ***/
2265 if (IS_FLG(FLG_REALM1))
2267 before_str[before_n++] = "第一領域の";
2271 /*** Second realm spellbooks ***/
2272 if (IS_FLG(FLG_REALM2))
2274 before_str[before_n++] = "第二領域の";
2278 /*** First rank spellbooks ***/
2279 if (IS_FLG(FLG_FIRST))
2281 before_str[before_n++] = "全4冊の内の1冊目の";
2285 /*** Second rank spellbooks ***/
2286 if (IS_FLG(FLG_SECOND))
2288 before_str[before_n++] = "全4冊の内の2冊目の";
2292 /*** Third rank spellbooks ***/
2293 if (IS_FLG(FLG_THIRD))
2295 before_str[before_n++] = "全4冊の内の3冊目の";
2299 /*** Fourth rank spellbooks ***/
2300 if (IS_FLG(FLG_FOURTH))
2302 before_str[before_n++] = "全4冊の内の4冊目の";
2307 if (IS_FLG(FLG_ITEMS))
2308 ; /* Nothing to do */
2309 else if (IS_FLG(FLG_WEAPONS))
2311 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2313 else if (IS_FLG(FLG_ARMORS))
2315 else if (IS_FLG(FLG_MISSILES))
2316 body_str = "弾や矢やクロスボウの矢";
2317 else if (IS_FLG(FLG_DEVICES))
2318 body_str = "巻物や魔法棒や杖やロッド";
2319 else if (IS_FLG(FLG_LIGHTS))
2320 body_str = "光源用のアイテム";
2321 else if (IS_FLG(FLG_JUNKS))
2322 body_str = "折れた棒等のガラクタ";
2323 else if (IS_FLG(FLG_CORPSES))
2325 else if (IS_FLG(FLG_SPELLBOOKS))
2327 else if (IS_FLG(FLG_HAFTED))
2329 else if (IS_FLG(FLG_SHIELDS))
2331 else if (IS_FLG(FLG_BOWS))
2332 body_str = "スリングや弓やクロスボウ";
2333 else if (IS_FLG(FLG_RINGS))
2335 else if (IS_FLG(FLG_AMULETS))
2336 body_str = "アミュレット";
2337 else if (IS_FLG(FLG_SUITS))
2339 else if (IS_FLG(FLG_CLOAKS))
2341 else if (IS_FLG(FLG_HELMS))
2342 body_str = "ヘルメットや冠";
2343 else if (IS_FLG(FLG_GLOVES))
2345 else if (IS_FLG(FLG_BOOTS))
2350 strcat(buff, "全ての");
2351 else for (i = 0; i < before_n && before_str[i]; i++)
2352 strcat(buff, before_str[i]);
2354 strcat(buff, body_str);
2364 strcat(buff, "で、名前が「");
2365 strncat(buff, str, 80);
2367 strcat(buff, "」で始まるもの");
2369 strcat(buff, "」を含むもの");
2374 strncat(buff, format("に「%s」", insc), 80);
2376 if (my_strstr(insc, "%%all"))
2377 strcat(buff, "(%%allは全能力を表す英字の記号で置換)");
2378 else if (my_strstr(insc, "%all"))
2379 strcat(buff, "(%allは全能力を表す記号で置換)");
2380 else if (my_strstr(insc, "%%"))
2381 strcat(buff, "(%%は追加能力を表す英字の記号で置換)");
2382 else if (my_strstr(insc, "%"))
2383 strcat(buff, "(%は追加能力を表す記号で置換)");
2385 strcat(buff, "と刻んで");
2390 if (act & DONT_AUTOPICK)
2391 strcat(buff, "放置する。");
2392 else if (act & DO_AUTODESTROY)
2393 strcat(buff, "破壊する。");
2394 else if (act & DO_QUERY_AUTOPICK)
2395 strcat(buff, "確認の後に拾う。");
2397 strcat(buff, "拾う。");
2399 if (act & DO_DISPLAY)
2401 if (act & DONT_AUTOPICK)
2402 strcat(buff, "全体マップ('M')で'N'を押したときに表示する。");
2403 else if (act & DO_AUTODESTROY)
2404 strcat(buff, "全体マップ('M')で'K'を押したときに表示する。");
2406 strcat(buff, "全体マップ('M')で'M'を押したときに表示する。");
2409 strcat(buff, "全体マップには表示しない。");
2413 concptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2414 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2418 /*** Collecting items ***/
2419 /*** Which can be absorbed into a slot as a bundle ***/
2420 if (IS_FLG(FLG_COLLECTING))
2421 which_str[which_n++] = "can be absorbed into an existing p_ptr->inventory_list slot";
2423 /*** Unaware items ***/
2424 if (IS_FLG(FLG_UNAWARE))
2426 before_str[before_n++] = "unidentified";
2427 whose_str[whose_n++] = "basic abilities are not known";
2430 /*** Unidentified ***/
2431 if (IS_FLG(FLG_UNIDENTIFIED))
2432 before_str[before_n++] = "unidentified";
2434 /*** Identified ***/
2435 if (IS_FLG(FLG_IDENTIFIED))
2436 before_str[before_n++] = "identified";
2438 /*** *Identified* ***/
2439 if (IS_FLG(FLG_STAR_IDENTIFIED))
2440 before_str[before_n++] = "fully identified";
2442 /*** Rare equipments ***/
2443 if (IS_FLG(FLG_RARE))
2445 before_str[before_n++] = "very rare";
2446 body_str = "equipments";
2447 after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
2450 /*** Common equipments ***/
2451 if (IS_FLG(FLG_COMMON))
2453 before_str[before_n++] = "relatively common";
2454 body_str = "equipments";
2455 after_str[after_n++] = "compared to very rare Dragon armors, Blades of Chaos, etc.";
2458 /*** Worthless items ***/
2459 if (IS_FLG(FLG_WORTHLESS))
2461 before_str[before_n++] = "worthless";
2462 which_str[which_n++] = "can not be sold at stores";
2466 if (IS_FLG(FLG_ARTIFACT))
2468 before_str[before_n++] = "artifact";
2472 if (IS_FLG(FLG_EGO))
2474 before_str[before_n++] = "ego";
2478 if (IS_FLG(FLG_GOOD))
2480 body_str = "equipment";
2481 which_str[which_n++] = "have good quality";
2485 if (IS_FLG(FLG_NAMELESS))
2487 body_str = "equipment";
2488 which_str[which_n++] = "is neither ego-item nor artifact";
2492 if (IS_FLG(FLG_AVERAGE))
2494 body_str = "equipment";
2495 which_str[which_n++] = "have average quality";
2498 /*** Dice boosted (weapon of slaying) ***/
2499 if (IS_FLG(FLG_BOOSTED))
2501 body_str = "weapons";
2502 whose_str[whose_n++] = "damage dice is bigger than normal";
2505 /*** Weapons whose dd*ds is more than nn ***/
2506 if (IS_FLG(FLG_MORE_DICE))
2508 static char more_than_desc_str[] =
2509 "maximum damage from dice is bigger than __";
2510 body_str = "weapons";
2512 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2514 whose_str[whose_n++] = more_than_desc_str;
2517 /*** Items whose magical bonus is more than nn ***/
2518 if (IS_FLG(FLG_MORE_BONUS))
2520 static char more_bonus_desc_str[] =
2521 "magical bonus is bigger than (+__)";
2523 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2524 "%d)", entry->bonus);
2525 whose_str[whose_n++] = more_bonus_desc_str;
2528 /*** Wanted monster's corpse/skeletons ***/
2529 if (IS_FLG(FLG_WANTED))
2531 body_str = "corpse or skeletons";
2532 which_str[which_n++] = "is wanted at the Hunter's Office";
2535 /*** Human corpse/skeletons (for Daemon magic) ***/
2536 if (IS_FLG(FLG_HUMAN))
2538 before_str[before_n++] = "humanoid";
2539 body_str = "corpse or skeletons";
2540 which_str[which_n++] = "can be used for Daemon magic";
2543 /*** Unique monster's corpse/skeletons/statues ***/
2544 if (IS_FLG(FLG_UNIQUE))
2546 before_str[before_n++] = "unique monster's";
2547 body_str = "corpse or skeletons";
2550 /*** Unreadable spellbooks ***/
2551 if (IS_FLG(FLG_UNREADABLE))
2553 body_str = "spellbooks";
2554 after_str[after_n++] = "of different realms from yours";
2557 /*** First realm spellbooks ***/
2558 if (IS_FLG(FLG_REALM1))
2560 body_str = "spellbooks";
2561 after_str[after_n++] = "of your first realm";
2564 /*** Second realm spellbooks ***/
2565 if (IS_FLG(FLG_REALM2))
2567 body_str = "spellbooks";
2568 after_str[after_n++] = "of your second realm";
2571 /*** First rank spellbooks ***/
2572 if (IS_FLG(FLG_FIRST))
2574 before_str[before_n++] = "first one of four";
2575 body_str = "spellbooks";
2578 /*** Second rank spellbooks ***/
2579 if (IS_FLG(FLG_SECOND))
2581 before_str[before_n++] = "second one of four";
2582 body_str = "spellbooks";
2585 /*** Third rank spellbooks ***/
2586 if (IS_FLG(FLG_THIRD))
2588 before_str[before_n++] = "third one of four";
2589 body_str = "spellbooks";
2592 /*** Fourth rank spellbooks ***/
2593 if (IS_FLG(FLG_FOURTH))
2595 before_str[before_n++] = "fourth one of four";
2596 body_str = "spellbooks";
2600 if (IS_FLG(FLG_ITEMS))
2601 ; /* Nothing to do */
2602 else if (IS_FLG(FLG_WEAPONS))
2603 body_str = "weapons";
2604 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2605 body_str = "favorite weapons";
2606 else if (IS_FLG(FLG_ARMORS))
2607 body_str = "armors";
2608 else if (IS_FLG(FLG_MISSILES))
2609 body_str = "shots, arrows or crossbow bolts";
2610 else if (IS_FLG(FLG_DEVICES))
2611 body_str = "scrolls, wands, staves or rods";
2612 else if (IS_FLG(FLG_LIGHTS))
2613 body_str = "light sources";
2614 else if (IS_FLG(FLG_JUNKS))
2615 body_str = "junk such as broken sticks";
2616 else if (IS_FLG(FLG_CORPSES))
2617 body_str = "corpses or skeletons";
2618 else if (IS_FLG(FLG_SPELLBOOKS))
2619 body_str = "spellbooks";
2620 else if (IS_FLG(FLG_HAFTED))
2621 body_str = "hafted weapons";
2622 else if (IS_FLG(FLG_SHIELDS))
2623 body_str = "shields";
2624 else if (IS_FLG(FLG_BOWS))
2625 body_str = "slings, bows or crossbows";
2626 else if (IS_FLG(FLG_RINGS))
2628 else if (IS_FLG(FLG_AMULETS))
2629 body_str = "amulets";
2630 else if (IS_FLG(FLG_SUITS))
2631 body_str = "body armors";
2632 else if (IS_FLG(FLG_CLOAKS))
2633 body_str = "cloaks";
2634 else if (IS_FLG(FLG_HELMS))
2635 body_str = "helms or crowns";
2636 else if (IS_FLG(FLG_GLOVES))
2637 body_str = "gloves";
2638 else if (IS_FLG(FLG_BOOTS))
2641 /* Prepare a string for item name */
2648 whose_str[whose_n++] = "name is beginning with \"";
2651 which_str[which_n++] = "have \"";
2655 /* Describe action flag */
2656 if (act & DONT_AUTOPICK)
2657 strcpy(buff, "Leave on floor ");
2658 else if (act & DO_AUTODESTROY)
2659 strcpy(buff, "Destroy ");
2660 else if (act & DO_QUERY_AUTOPICK)
2661 strcpy(buff, "Ask to pick up ");
2663 strcpy(buff, "Pickup ");
2665 /* Auto-insctiption */
2668 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2670 if (my_strstr(insc, "%all"))
2671 strcat(buff, ", replacing %all with code string representing all abilities,");
2672 else if (my_strstr(insc, "%"))
2673 strcat(buff, ", replacing % with code string representing extra random abilities,");
2675 strcat(buff, " on ");
2680 strcat(buff, "all ");
2681 else for (i = 0; i < before_n && before_str[i]; i++)
2683 strcat(buff, before_str[i]);
2688 strcat(buff, body_str);
2691 for (i = 0; i < after_n && after_str[i]; i++)
2694 strcat(buff, after_str[i]);
2698 for (i = 0; i < whose_n && whose_str[i]; i++)
2701 strcat(buff, " whose ");
2703 strcat(buff, ", and ");
2705 strcat(buff, whose_str[i]);
2708 /* Item name ; whose name is beginning with "str" */
2715 /* whose ..., and which .... */
2716 if (whose_n && which_n)
2717 strcat(buff, ", and ");
2720 for (i = 0; i < which_n && which_str[i]; i++)
2723 strcat(buff, " which ");
2725 strcat(buff, ", and ");
2727 strcat(buff, which_str[i]);
2730 /* Item name ; which have "str" as part of its name */
2733 strncat(buff, str, 80);
2734 strcat(buff, "\" as part of its name");
2738 /* Describe whether it will be displayed on the full map or not */
2739 if (act & DO_DISPLAY)
2741 if (act & DONT_AUTOPICK)
2742 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2743 else if (act & DO_AUTODESTROY)
2744 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2746 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2749 strcat(buff, " Not displayed in the full map.");
2756 * Read whole lines of a file to memory
2758 static concptr *read_text_lines(concptr filename)
2760 concptr *lines_list = NULL;
2766 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2769 fff = my_fopen(buf, "r");
2773 /* Allocate list of pointers */
2774 C_MAKE(lines_list, MAX_LINES, concptr);
2777 while (0 == my_fgets(fff, buf, sizeof(buf)))
2779 lines_list[lines++] = string_make(buf);
2780 if (lines >= MAX_LINES - 1) break;
2783 lines_list[0] = string_make("");
2788 if (!fff) return NULL;
2794 * Copy the default autopick file to the user directory
2796 static void prepare_default_pickpref(void)
2798 const concptr messages[] = {
2799 _("あなたは「自動拾いエディタ」を初めて起動しました。", "You have activated the Auto-Picker Editor for the first time."),
2800 _("自動拾いのユーザー設定ファイルがまだ書かれていないので、", "Since user pref file for autopick is not yet created,"),
2801 _("基本的な自動拾い設定ファイルをlib/pref/picktype.prfからコピーします。", "the default setting is loaded from lib/pref/pickpref.prf ."),
2809 concptr filename = pickpref_filename(PT_DEFAULT);
2811 /* Display messages */
2812 for (i = 0; messages[i]; i++) msg_print(messages[i]);
2817 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2818 user_fp = my_fopen(buf, "w");
2821 if (!user_fp) return;
2823 /* Write header messages for a notification */
2824 fprintf(user_fp, "#***\n");
2825 for (i = 0; messages[i]; i++)
2827 fprintf(user_fp, "#*** %s\n", messages[i]);
2829 fprintf(user_fp, "#***\n\n\n");
2832 /* Open the default file */
2833 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2834 pref_fp = my_fopen(buf, "r");
2843 /* Copy the contents of default file */
2844 while (!my_fgets(pref_fp, buf, sizeof(buf)))
2845 fprintf(user_fp, "%s\n", buf);
2852 * Read an autopick prefence file to memory
2853 * Prepare default if no user file is found
2855 static concptr *read_pickpref_text_lines(int *filename_mode_p)
2858 concptr *lines_list;
2860 /* Try a filename with player name */
2861 *filename_mode_p = PT_WITH_PNAME;
2862 strcpy(buf, pickpref_filename(*filename_mode_p));
2863 lines_list = read_text_lines(buf);
2867 /* Use default name */
2868 *filename_mode_p = PT_DEFAULT;
2869 strcpy(buf, pickpref_filename(*filename_mode_p));
2870 lines_list = read_text_lines(buf);
2875 /* There is no preference file in the user directory */
2877 /* Copy the default autopick file to the user directory */
2878 prepare_default_pickpref();
2880 /* Use default name again */
2881 lines_list = read_text_lines(buf);
2886 /* Allocate list of pointers */
2887 C_MAKE(lines_list, MAX_LINES, concptr);
2888 lines_list[0] = string_make("");
2895 * Write whole lines of memory to a file.
2897 static bool write_text_lines(concptr filename, concptr *lines_list)
2904 /* Build the filename */
2905 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2908 fff = my_fopen(buf, "w");
2911 for (lines = 0; lines_list[lines]; lines++)
2912 my_fputs(fff, lines_list[lines], 1024);
2917 if (!fff) return FALSE;
2923 * Free memory of lines_list.
2925 static void free_text_lines(concptr *lines_list)
2929 for (lines = 0; lines_list[lines]; lines++)
2930 string_free(lines_list[lines]);
2932 /* free list of pointers */
2933 C_KILL(lines_list, MAX_LINES, concptr);
2938 * Delete or insert string
2940 static void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
2946 /* Some lines are selected */
2949 by1 = MIN(tb->my, tb->cy);
2950 by2 = MAX(tb->my, tb->cy);
2953 /* No mark -- Select current line */
2954 else /* if (!tb->mark) */
2960 /* Set/Reset flag of each line */
2961 for (y = by1; y <= by2; y++)
2963 autopick_type an_entry, *entry = &an_entry;
2965 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2967 string_free(tb->lines_list[y]);
2971 /* Add? or Remove? */
2972 if (!IS_FLG(flg)) add = TRUE;
2975 /* No more change */
2979 /* You can use only one noun flag */
2980 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2983 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2987 /* You can use only one identify state flag */
2988 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2991 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2995 /* You can use only one flag in artifact/ego/nameless */
2996 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
2999 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
3003 /* You can use only one flag in rare/common */
3004 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
3007 for (i = FLG_RARE; i <= FLG_COMMON; i++)
3011 if (add) ADD_FLG(flg);
3014 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3017 tb->dirty_flags |= DIRTY_ALL;
3019 /* Text is changed */
3026 * Change command letter
3028 static void toggle_command_letter(text_body_type *tb, byte flg)
3030 autopick_type an_entry, *entry = &an_entry;
3035 /* Some lines are selected */
3038 by1 = MIN(tb->my, tb->cy);
3039 by2 = MAX(tb->my, tb->cy);
3042 /* No mark -- Select current line */
3043 else /* if (!tb->mark) */
3049 /* Set/Reset flag of each line */
3050 for (y = by1; y <= by2; y++)
3054 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3056 string_free(tb->lines_list[y]);
3060 /* Add? or Remove? */
3061 if (!(entry->action & flg)) add = TRUE;
3064 /* No more change */
3068 /* Count number of letter (by negative number) */
3069 if (entry->action & DONT_AUTOPICK) wid--;
3070 else if (entry->action & DO_AUTODESTROY) wid--;
3071 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3072 if (!(entry->action & DO_DISPLAY)) wid--;
3074 /* Set/Reset the flag */
3075 if (flg != DO_DISPLAY)
3077 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3078 if (add) entry->action |= flg;
3079 else entry->action |= DO_AUTOPICK;
3083 entry->action &= ~(DO_DISPLAY);
3084 if (add) entry->action |= flg;
3087 /* Correct cursor location */
3090 if (entry->action & DONT_AUTOPICK) wid++;
3091 else if (entry->action & DO_AUTODESTROY) wid++;
3092 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3093 if (!(entry->action & DO_DISPLAY)) wid++;
3095 if (wid > 0) tb->cx++;
3096 if (wid < 0 && tb->cx > 0) tb->cx--;
3099 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3102 tb->dirty_flags |= DIRTY_ALL;
3104 /* Text is changed */
3110 * Delete or insert string
3112 static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
3116 /* Some lines are selected */
3119 by1 = MIN(tb->my, tb->cy);
3120 by2 = MAX(tb->my, tb->cy);
3123 /* No mark -- Select current line */
3124 else /* if (!tb->mark) */
3130 /* Set/Reset flag of each line */
3131 for (y = by1; y <= by2; y++)
3133 autopick_type an_entry, *entry = &an_entry;
3135 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3137 /* There is the flag already */
3140 /* Free memory for the entry */
3141 autopick_free_entry(entry);
3146 string_free(tb->lines_list[y]);
3148 /* Remove all noun flag */
3149 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3152 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3158 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3161 tb->dirty_flags |= DIRTY_ALL;
3163 /* Text is changed */
3170 * Check if this line is expression or not.
3171 * And update it if it is.
3173 static void check_expression_line(text_body_type *tb, int y)
3175 concptr s = tb->lines_list[y];
3177 if ((s[0] == '?' && s[1] == ':') ||
3178 (tb->states[y] & LSTAT_BYPASS))
3180 /* Expressions need re-evaluation */
3181 tb->dirty_flags |= DIRTY_EXPRESSION;
3187 * Add an empty line at the last of the file
3189 static bool add_empty_line(text_body_type *tb)
3193 for (k = 0; tb->lines_list[k]; k++)
3194 /* count number of lines */ ;
3196 /* Too many lines! */
3197 if (k >= MAX_LINES - 2) return FALSE;
3199 /* The last line is already empty */
3200 if (!tb->lines_list[k-1][0]) return FALSE;
3202 /* Create new empty line */
3203 tb->lines_list[k] = string_make("");
3205 /* Expressions need re-evaluation */
3206 tb->dirty_flags |= DIRTY_EXPRESSION;
3208 /* Text is changed */
3211 /* A line is added */
3217 * Insert return code and split the line
3219 static bool insert_return_code(text_body_type *tb)
3221 char buf[MAX_LINELEN];
3224 for (k = 0; tb->lines_list[k]; k++)
3225 /* count number of lines */ ;
3227 if (k >= MAX_LINES - 2) return FALSE;
3230 /* Move down lines */
3231 for (; tb->cy < k; k--)
3233 tb->lines_list[k+1] = tb->lines_list[k];
3234 tb->states[k+1] = tb->states[k];
3237 /* Split current line */
3238 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3241 if (iskanji(tb->lines_list[tb->cy][i]))
3242 buf[j++] = tb->lines_list[tb->cy][i++];
3244 buf[j++] = tb->lines_list[tb->cy][i];
3247 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3248 string_free(tb->lines_list[tb->cy]);
3249 tb->lines_list[tb->cy] = string_make(buf);
3251 /* Expressions need re-evaluation */
3252 tb->dirty_flags |= DIRTY_EXPRESSION;
3254 /* Text is changed */
3262 * Choose an item and get auto-picker entry from it.
3264 static bool entry_from_choosed_object(autopick_type *entry)
3269 q = _("どのアイテムを登録しますか? ", "Enter which item? ");
3270 s = _("アイテムを持っていない。", "You have nothing to enter.");
3271 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3272 if (!o_ptr) return FALSE;
3274 autopick_entry_from_object(entry, o_ptr);
3280 * Choose an item for search
3282 static byte get_object_for_search(object_type **o_handle, concptr *search_strp)
3284 char buf[MAX_NLEN+20];
3288 q = _("どのアイテムを検索しますか? ", "Enter which item? ");
3289 s = _("アイテムを持っていない。", "You have nothing to enter.");
3290 o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
3291 if (!o_ptr) return 0;
3295 string_free(*search_strp);
3296 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3297 *search_strp = string_make(format("<%s>", buf));
3303 * Prepare for search by destroyed object
3305 static byte get_destroyed_object_for_search(object_type **o_handle, concptr *search_strp)
3307 char buf[MAX_NLEN+20];
3309 if (!autopick_last_destroyed_object.k_idx) return 0;
3311 *o_handle = &autopick_last_destroyed_object;
3313 string_free(*search_strp);
3314 object_desc(buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3315 *search_strp = string_make(format("<%s>", buf));
3321 * Choose an item or string for search
3323 static byte get_string_for_search(object_type **o_handle, concptr *search_strp)
3329 * TERM_YELLOW : Overwrite mode
3330 * TERM_WHITE : Insert mode
3332 byte color = TERM_YELLOW;
3333 char buf[MAX_NLEN+20];
3336 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
3337 int col = sizeof(prompt) - 1;
3339 /* Prepare string buffer for edit */
3340 if (*search_strp) strcpy(buf, *search_strp);
3343 /* Object searching mode */
3346 color = TERM_L_GREEN;
3349 /* Display prompt */
3359 /* Display the string */
3360 Term_erase(col, 0, 255);
3361 Term_putstr(col, 0, -1, color, buf);
3364 Term_gotoxy(col + pos, 0);
3366 /* Get a special key code */
3367 skey = inkey_special(TRUE);
3369 /* Analyze the key */
3377 /* Now on insert mode */
3380 /* No move at beginning of line */
3381 if (0 == pos) break;
3385 int next_pos = i + 1;
3388 if (iskanji(buf[i])) next_pos++;
3391 /* Is there the cursor at next position? */
3392 if (next_pos >= pos) break;
3398 /* Get previous position */
3406 /* Now on insert mode */
3409 /* No move at end of line */
3410 if ('\0' == buf[pos]) break;
3414 if (iskanji(buf[pos])) pos += 2;
3432 if (*o_handle) return (back ? -1 : 1);
3433 string_free(*search_strp);
3434 *search_strp = string_make(buf);
3436 return (back ? -1 : 1);
3439 return get_object_for_search(o_handle, search_strp);
3442 /* Prepare string for destroyed object if there is one. */
3443 if (get_destroyed_object_for_search(o_handle, search_strp))
3453 /* Now on insert mode */
3456 /* No move at beginning of line */
3457 if (0 == pos) break;
3461 int next_pos = i + 1;
3464 if (iskanji(buf[i])) next_pos++;
3467 /* Is there the cursor at next position? */
3468 if (next_pos >= pos) break;
3474 /* Get previous position */
3477 /* Fall through to 'Delete key' */
3486 /* Now on insert mode */
3489 /* No move at end of line */
3490 if ('\0' == buf[pos]) break;
3492 /* Position of next character */
3496 /* Next character is one more byte away */
3497 if (iskanji(buf[pos])) src++;
3502 /* Move characters at src to dst */
3503 while ('\0' != (buf[dst++] = buf[src++]))
3511 /* Insert a character */
3516 /* Ignore special keys */
3517 if (skey & SKEY_MASK) break;
3519 /* Get a character code */
3522 /* Was non insert mode? */
3523 if (color != TERM_WHITE)
3525 /* Was object searching mode */
3526 if (color == TERM_L_GREEN)
3528 /* Cancel the mode */
3531 /* Remove indicating string */
3532 string_free(*search_strp);
3533 *search_strp = NULL;
3536 /* Overwrite default string */
3539 /* Go to insert mode */
3543 /* Save right part of string */
3544 strcpy(tmp, buf + pos);
3550 /* Bypass macro processing */
3568 if (pos < len && (isprint(c) || iskana(c)))
3570 if (pos < len && isprint(c))
3584 /* Write back the left part of string */
3585 my_strcat(buf, tmp, len + 1);
3592 /* Object searching mode was cancelled? */
3593 if (*o_handle && color != TERM_L_GREEN)
3595 /* Cancel the mode */
3598 /* Remove indicating string */
3600 string_free(*search_strp);
3601 *search_strp = NULL;
3606 } /* while (TRUE) */
3611 * Search next line matches for o_ptr
3613 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3615 autopick_type an_entry, *entry = &an_entry;
3616 GAME_TEXT o_name[MAX_NLEN];
3617 int bypassed_cy = -1;
3619 /* Start searching from current cursor position */
3622 /* Prepare object name string first */
3623 object_desc(o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3625 /* Convert the string to lower case */
3626 str_tolower(o_name);
3635 if (!tb->lines_list[++i]) break;
3642 /* Is this line is a correct entry? */
3643 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3645 /* Does this line match to the object? */
3646 match = is_autopick_aux(o_ptr, entry, o_name);
3647 autopick_free_entry(entry);
3648 if (!match) continue;
3650 /* Found a line but it's inactive */
3651 if (tb->states[i] & LSTAT_BYPASS)
3653 /* If it is first found, remember it */
3654 if (bypassed_cy == -1) bypassed_cy = i;
3657 /* Found an active line! */
3660 /* Move to this line */
3664 if (bypassed_cy != -1)
3666 /* Mark as some lines are skipped */
3667 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3675 if (bypassed_cy != -1)
3677 /* Move to the remembered line */
3679 tb->cy = bypassed_cy;
3681 /* Mark as this line is inactive */
3682 tb->dirty_flags |= DIRTY_INACTIVE;
3687 /* Mark as NOT FOUND */
3688 tb->dirty_flags |= DIRTY_NOT_FOUND;
3696 * Search next line matches to the string
3698 static void search_for_string(text_body_type *tb, concptr search_str, bool forward)
3700 int bypassed_cy = -1;
3701 int bypassed_cx = 0;
3703 /* Start searching from current cursor position */
3713 if (!tb->lines_list[++i]) break;
3720 /* Look for the string pattern */
3721 pos = my_strstr(tb->lines_list[i], search_str);
3726 /* Found a line but it's inactive */
3727 if ((tb->states[i] & LSTAT_BYPASS) &&
3728 !(tb->states[i] & LSTAT_EXPRESSION))
3730 /* If it is first found, remember it */
3731 if (bypassed_cy == -1)
3734 bypassed_cx = (int)(pos - tb->lines_list[i]);
3738 /* Found an active line! */
3741 /* Move to this location */
3742 tb->cx = (int)(pos - tb->lines_list[i]);
3745 if (bypassed_cy != -1)
3747 /* Mark as some lines are skipped */
3748 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3756 if (bypassed_cy != -1)
3758 /* Move to the remembered line */
3759 tb->cx = bypassed_cx;
3760 tb->cy = bypassed_cy;
3762 /* Mark as this line is inactive */
3763 tb->dirty_flags |= DIRTY_INACTIVE;
3768 /* Mark as NOT FOUND */
3769 tb->dirty_flags |= DIRTY_NOT_FOUND;
3779 * Editor command id's
3782 #define EC_SAVEQUIT 2
3793 #define EC_PGDOWN 13
3795 #define EC_BOTTOM 15
3800 #define EC_KILL_LINE 20
3801 #define EC_DELETE_CHAR 21
3802 #define EC_BACKSPACE 22
3803 #define EC_SEARCH_STR 23
3804 #define EC_SEARCH_FORW 24
3805 #define EC_SEARCH_BACK 25
3806 #define EC_SEARCH_OBJ 26
3807 #define EC_SEARCH_DESTROYED 27
3808 #define EC_INSERT_OBJECT 28
3809 #define EC_INSERT_DESTROYED 29
3810 #define EC_INSERT_BLOCK 30
3811 #define EC_INSERT_MACRO 31
3812 #define EC_INSERT_KEYMAP 32
3813 #define EC_CL_AUTOPICK 33
3814 #define EC_CL_DESTROY 34
3815 #define EC_CL_LEAVE 35
3816 #define EC_CL_QUERY 36
3817 #define EC_CL_NO_DISP 37
3818 #define EC_OK_COLLECTING 38
3819 #define EC_IK_UNAWARE 39
3820 #define EC_IK_UNIDENTIFIED 40
3821 #define EC_IK_IDENTIFIED 41
3822 #define EC_IK_STAR_IDENTIFIED 42
3823 #define EC_OK_BOOSTED 43
3824 #define EC_OK_MORE_DICE 44
3825 #define EC_OK_MORE_BONUS 45
3826 #define EC_OK_WORTHLESS 46
3827 #define EC_OK_ARTIFACT 47
3828 #define EC_OK_EGO 48
3829 #define EC_OK_GOOD 49
3830 #define EC_OK_NAMELESS 50
3831 #define EC_OK_AVERAGE 51
3832 #define EC_OK_RARE 52
3833 #define EC_OK_COMMON 53
3834 #define EC_OK_WANTED 54
3835 #define EC_OK_UNIQUE 55
3836 #define EC_OK_HUMAN 56
3837 #define EC_OK_UNREADABLE 57
3838 #define EC_OK_REALM1 58
3839 #define EC_OK_REALM2 59
3840 #define EC_OK_FIRST 60
3841 #define EC_OK_SECOND 61
3842 #define EC_OK_THIRD 62
3843 #define EC_OK_FOURTH 63
3844 #define EC_KK_WEAPONS 64
3845 #define EC_KK_FAVORITE_WEAPONS 65
3846 #define EC_KK_ARMORS 66
3847 #define EC_KK_MISSILES 67
3848 #define EC_KK_DEVICES 68
3849 #define EC_KK_LIGHTS 69
3850 #define EC_KK_JUNKS 70
3851 #define EC_KK_CORPSES 71
3852 #define EC_KK_SPELLBOOKS 72
3853 #define EC_KK_SHIELDS 73
3854 #define EC_KK_BOWS 74
3855 #define EC_KK_RINGS 75
3856 #define EC_KK_AMULETS 76
3857 #define EC_KK_SUITS 77
3858 #define EC_KK_CLOAKS 78
3859 #define EC_KK_HELMS 79
3860 #define EC_KK_GLOVES 80
3861 #define EC_KK_BOOTS 81
3867 static GAME_TEXT MN_QUIT[] = "セーブ無しで終了";
3868 static GAME_TEXT MN_SAVEQUIT[] = "セーブして終了";
3869 static GAME_TEXT MN_REVERT[] = "全ての変更を破棄";
3870 static GAME_TEXT MN_HELP[] = "ヘルプ";
3872 static GAME_TEXT MN_MOVE[] = "カーソル移動";
3873 static GAME_TEXT MN_LEFT[] = "左 (←矢印キー)";
3874 static GAME_TEXT MN_DOWN[] = "下 (↓矢印キー)";
3875 static GAME_TEXT MN_UP[] = "上 (↑矢印キー)";
3876 static GAME_TEXT MN_RIGHT[] = "右 (→矢印キー)";
3877 static GAME_TEXT MN_BOL[] = "行の先頭";
3878 static GAME_TEXT MN_EOL[] = "行の終端";
3879 static GAME_TEXT MN_PGUP[] = "上のページ (PageUpキー)";
3880 static GAME_TEXT MN_PGDOWN[] = "下のページ (PageDownキー)";
3881 static GAME_TEXT MN_TOP[] = "1行目へ移動 (Homeキー)";
3882 static GAME_TEXT MN_BOTTOM[] = "最下行へ移動(Endキー)";
3884 static GAME_TEXT MN_EDIT[] = "編集";
3885 static GAME_TEXT MN_CUT[] = "カット";
3886 static GAME_TEXT MN_COPY[] = "コピー";
3887 static GAME_TEXT MN_PASTE[] = "ペースト";
3888 static GAME_TEXT MN_BLOCK[] = "選択範囲の指定";
3889 static GAME_TEXT MN_KILL_LINE[] = "行の残りを削除";
3890 static GAME_TEXT MN_DELETE_CHAR[] = "1文字削除";
3891 static GAME_TEXT MN_BACKSPACE[] = "バックスペース";
3892 static GAME_TEXT MN_RETURN[] = "改行";
3894 static GAME_TEXT MN_SEARCH[] = "検索";
3895 static GAME_TEXT MN_SEARCH_STR[] = "文字列で検索";
3896 static GAME_TEXT MN_SEARCH_FORW[] = "前方へ再検索";
3897 static GAME_TEXT MN_SEARCH_BACK[] = "後方へ再検索";
3898 static GAME_TEXT MN_SEARCH_OBJ[] = "アイテムを選択して検索";
3899 static GAME_TEXT MN_SEARCH_DESTROYED[] = "自動破壊されたアイテムで検索";
3901 static GAME_TEXT MN_INSERT[] = "色々挿入";
3902 static GAME_TEXT MN_INSERT_OBJECT[] = "選択したアイテムの名前を挿入";
3903 static GAME_TEXT MN_INSERT_DESTROYED[] = "自動破壊されたアイテムの名前を挿入";
3904 static GAME_TEXT MN_INSERT_BLOCK[] = "条件分岐ブロックの例を挿入";
3905 static GAME_TEXT MN_INSERT_MACRO[] = "マクロ定義を挿入";
3906 static GAME_TEXT MN_INSERT_KEYMAP[] = "キーマップ定義を挿入";
3908 static GAME_TEXT MN_COMMAND_LETTER[] = "拾い/破壊/放置の選択";
3909 static GAME_TEXT MN_CL_AUTOPICK[] = "「 」 (自動拾い)";
3910 static GAME_TEXT MN_CL_DESTROY[] = "「!」 (自動破壊)";
3911 static GAME_TEXT MN_CL_LEAVE[] = "「~」 (放置)";
3912 static GAME_TEXT MN_CL_QUERY[] = "「;」 (確認して拾う)";
3913 static GAME_TEXT MN_CL_NO_DISP[] = "「(」 (マップコマンドで表示しない)";
3915 static GAME_TEXT MN_ADJECTIVE_GEN[] = "形容詞(一般)の選択";
3916 static GAME_TEXT MN_RARE[] = "レアな (装備)";
3917 static GAME_TEXT MN_COMMON[] = "ありふれた (装備)";
3919 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "形容詞(特殊)の選択";
3920 static GAME_TEXT MN_BOOSTED[] = "ダイス目の違う (武器)";
3921 static GAME_TEXT MN_MORE_DICE[] = "ダイス目 # 以上の (武器)";
3922 static GAME_TEXT MN_MORE_BONUS[] = "修正値 # 以上の (指輪等)";
3923 static GAME_TEXT MN_WANTED[] = "賞金首の (死体)";
3924 static GAME_TEXT MN_UNIQUE[] = "ユニーク・モンスターの (死体)";
3925 static GAME_TEXT MN_HUMAN[] = "人間の (死体)";
3926 static GAME_TEXT MN_UNREADABLE[] = "読めない (魔法書)";
3927 static GAME_TEXT MN_REALM1[] = "第一領域の (魔法書)";
3928 static GAME_TEXT MN_REALM2[] = "第二領域の (魔法書)";
3929 static GAME_TEXT MN_FIRST[] = "1冊目の (魔法書)";
3930 static GAME_TEXT MN_SECOND[] = "2冊目の (魔法書)";
3931 static GAME_TEXT MN_THIRD[] = "3冊目の (魔法書)";
3932 static GAME_TEXT MN_FOURTH[] = "4冊目の (魔法書)";
3934 static GAME_TEXT MN_NOUN[] = "名詞の選択";
3938 static GAME_TEXT MN_QUIT[] = "Quit without save";
3939 static GAME_TEXT MN_SAVEQUIT[] = "Save & Quit";
3940 static GAME_TEXT MN_REVERT[] = "Revert all changes";
3941 static GAME_TEXT MN_HELP[] = "Help";
3943 static GAME_TEXT MN_MOVE[] = "Move cursor";
3944 static GAME_TEXT MN_LEFT[] = "Left (Left Arrow key)";
3945 static GAME_TEXT MN_DOWN[] = "Down (Down Arrow key)";
3946 static GAME_TEXT MN_UP[] = "Up (Up Arrow key)";
3947 static GAME_TEXT MN_RIGHT[] = "Right (Right Arrow key)";
3948 static GAME_TEXT MN_BOL[] = "Beggining of line";
3949 static GAME_TEXT MN_EOL[] = "End of line";
3950 static GAME_TEXT MN_PGUP[] = "Page up (PageUp key)";
3951 static GAME_TEXT MN_PGDOWN[] = "Page down(PageDown key)";
3952 static GAME_TEXT MN_TOP[] = "Top (Home key)";
3953 static GAME_TEXT MN_BOTTOM[] = "Bottom (End key)";
3955 static GAME_TEXT MN_EDIT[] = "Edit";
3956 static GAME_TEXT MN_CUT[] = "Cut";
3957 static GAME_TEXT MN_COPY[] = "Copy";
3958 static GAME_TEXT MN_PASTE[] = "Paste";
3959 static GAME_TEXT MN_BLOCK[] = "Select block";
3960 static GAME_TEXT MN_KILL_LINE[] = "Kill rest of line";
3961 static GAME_TEXT MN_DELETE_CHAR[] = "Delete character";
3962 static GAME_TEXT MN_BACKSPACE[] = "Backspace";
3963 static GAME_TEXT MN_RETURN[] = "Return";
3965 static GAME_TEXT MN_SEARCH[] = "Search";
3966 static GAME_TEXT MN_SEARCH_STR[] = "Search by string";
3967 static GAME_TEXT MN_SEARCH_FORW[] = "Search forward";
3968 static GAME_TEXT MN_SEARCH_BACK[] = "Search backward";
3969 static GAME_TEXT MN_SEARCH_OBJ[] = "Search by p_ptr->inventory_list object";
3970 static GAME_TEXT MN_SEARCH_DESTROYED[] = "Search by destroyed object";
3972 static GAME_TEXT MN_INSERT[] = "Insert...";
3973 static GAME_TEXT MN_INSERT_OBJECT[] = "Insert name of choosen object";
3974 static GAME_TEXT MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
3975 static GAME_TEXT MN_INSERT_BLOCK[] = "Insert conditional block";
3976 static GAME_TEXT MN_INSERT_MACRO[] = "Insert a macro definition";
3977 static GAME_TEXT MN_INSERT_KEYMAP[] = "Insert a keymap definition";
3979 static GAME_TEXT MN_COMMAND_LETTER[] = "Command letter";
3980 static GAME_TEXT MN_CL_AUTOPICK[] = "' ' (Auto pick)";
3981 static GAME_TEXT MN_CL_DESTROY[] = "'!' (Auto destroy)";
3982 static GAME_TEXT MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
3983 static GAME_TEXT MN_CL_QUERY[] = "';' (Query to pick up)";
3984 static GAME_TEXT MN_CL_NO_DISP[] = "'(' (No display on the large map)";
3986 static GAME_TEXT MN_ADJECTIVE_GEN[] = "Adjective (general)";
3987 static GAME_TEXT MN_RARE[] = "rare (equipments)";
3988 static GAME_TEXT MN_COMMON[] = "common (equipments)";
3990 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
3991 static GAME_TEXT MN_BOOSTED[] = "dice boosted (weapons)";
3992 static GAME_TEXT MN_MORE_DICE[] = "more than # dice (weapons)";
3993 static GAME_TEXT MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
3994 static GAME_TEXT MN_WANTED[] = "wanted (corpse)";
3995 static GAME_TEXT MN_UNIQUE[] = "unique (corpse)";
3996 static GAME_TEXT MN_HUMAN[] = "human (corpse)";
3997 static GAME_TEXT MN_UNREADABLE[] = "unreadable (spellbooks)";
3998 static GAME_TEXT MN_REALM1[] = "realm1 (spellbooks)";
3999 static GAME_TEXT MN_REALM2[] = "realm2 (spellbooks)";
4000 static GAME_TEXT MN_FIRST[] = "first (spellbooks)";
4001 static GAME_TEXT MN_SECOND[] = "second (spellbooks)";
4002 static GAME_TEXT MN_THIRD[] = "third (spellbooks)";
4003 static GAME_TEXT MN_FOURTH[] = "fourth (spellbooks)";
4005 static GAME_TEXT MN_NOUN[] = "Keywords (noun)";
4015 } command_menu_type;
4018 command_menu_type menu_data[] =
4020 {MN_HELP, 0, -1, EC_HELP},
4021 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
4022 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
4023 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
4025 {MN_EDIT, 0, -1, -1},
4026 {MN_CUT, 1, KTRL('x'), EC_CUT},
4027 {MN_COPY, 1, KTRL('c'), EC_COPY},
4028 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
4029 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
4030 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
4031 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
4032 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
4033 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
4034 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
4036 {MN_SEARCH, 0, -1, -1},
4037 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
4038 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
4039 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
4040 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
4041 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
4043 {MN_MOVE, 0, -1, -1},
4044 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
4045 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
4046 {MN_UP, 1, KTRL('p'), EC_UP},
4047 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
4048 {MN_BOL, 1, KTRL('a'), EC_BOL},
4049 {MN_EOL, 1, KTRL('e'), EC_EOL},
4050 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
4051 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
4052 {MN_TOP, 1, KTRL('t'), EC_TOP},
4053 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
4055 {MN_INSERT, 0, -1, -1},
4056 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
4057 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
4058 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
4059 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
4060 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
4062 {MN_ADJECTIVE_GEN, 0, -1, -1},
4063 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
4064 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
4065 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
4066 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
4067 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
4068 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
4069 {KEY_EGO, 1, -1, EC_OK_EGO},
4070 {KEY_GOOD, 1, -1, EC_OK_GOOD},
4071 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
4072 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
4073 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
4074 {MN_RARE, 1, -1, EC_OK_RARE},
4075 {MN_COMMON, 1, -1, EC_OK_COMMON},
4077 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
4078 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
4079 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
4080 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
4081 {MN_WANTED, 1, -1, EC_OK_WANTED},
4082 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
4083 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
4084 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
4085 {MN_REALM1, 1, -1, EC_OK_REALM1},
4086 {MN_REALM2, 1, -1, EC_OK_REALM2},
4087 {MN_FIRST, 1, -1, EC_OK_FIRST},
4088 {MN_SECOND, 1, -1, EC_OK_SECOND},
4089 {MN_THIRD, 1, -1, EC_OK_THIRD},
4090 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
4092 {MN_NOUN, 0, -1, -1},
4093 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
4094 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
4095 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
4096 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
4097 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
4098 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
4099 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
4100 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
4101 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
4102 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
4103 {KEY_BOWS, 1, -1, EC_KK_BOWS},
4104 {KEY_RINGS, 1, -1, EC_KK_RINGS},
4105 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
4106 {KEY_SUITS, 1, -1, EC_KK_SUITS},
4107 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
4108 {KEY_HELMS, 1, -1, EC_KK_HELMS},
4109 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
4110 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
4112 {MN_COMMAND_LETTER, 0, -1, -1},
4113 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
4114 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
4115 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
4116 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
4117 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
4119 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
4126 * Find a command by 'key'.
4128 static int get_com_id(char key)
4132 for (i = 0; menu_data[i].name; i++)
4134 if (menu_data[i].key == key)
4136 return menu_data[i].com_id;
4145 * Display the menu, and get a command
4147 static int do_command_menu(int level, int start)
4152 int col0 = 5 + level*7;
4153 int row0 = 1 + level*3;
4155 int menu_id_list[26];
4157 char linestr[MAX_LINELEN];
4159 /* Get max length */
4161 for (i = start; menu_data[i].level >= level; i++)
4165 /* Ignore lower level sub menus */
4166 if (menu_data[i].level > level) continue;
4168 len = strlen(menu_data[i].name);
4169 if (len > max_len) max_len = len;
4171 menu_id_list[menu_key] = i;
4175 while (menu_key < 26)
4177 menu_id_list[menu_key] = -1;
4181 /* Extra space for displaying menu key and command key */
4182 max_menu_wid = max_len + 3 + 3;
4184 /* Prepare box line */
4186 strcat(linestr, "+");
4187 for (i = 0; i < max_menu_wid + 2; i++)
4189 strcat(linestr, "-");
4191 strcat(linestr, "+");
4201 int row1 = row0 + 1;
4204 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4206 /* Draw menu items */
4208 for (i = start; menu_data[i].level >= level; i++)
4210 char com_key_str[3];
4213 /* Ignore lower level sub menus */
4214 if (menu_data[i].level > level) continue;
4216 if (menu_data[i].com_id == -1)
4218 strcpy(com_key_str, _("▼", ">"));
4220 else if (menu_data[i].key != -1)
4222 com_key_str[0] = '^';
4223 com_key_str[1] = menu_data[i].key + '@';
4224 com_key_str[2] = '\0';
4228 com_key_str[0] = '\0';
4231 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4233 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4238 /* Draw bottom line */
4239 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4241 /* The menu was shown */
4244 prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
4247 if (key == ESCAPE) return 0;
4249 if ('a' <= key && key <= 'z')
4251 menu_id = menu_id_list[key - 'a'];
4255 com_id = menu_data[menu_id].com_id;
4259 com_id = do_command_menu(level + 1, menu_id + 1);
4261 if (com_id) return com_id;
4273 com_id = get_com_id(key);
4274 if (com_id) return com_id;
4281 static chain_str_type *new_chain_str(concptr str)
4283 chain_str_type *chain;
4285 size_t len = strlen(str);
4287 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4289 strcpy(chain->s, str);
4296 static void kill_yank_chain(text_body_type *tb)
4298 chain_str_type *chain = tb->yank;
4300 tb->yank_eol = TRUE;
4304 chain_str_type *next = chain->next;
4305 size_t len = strlen(chain->s);
4307 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4314 static void add_str_to_yank(text_body_type *tb, concptr str)
4316 chain_str_type *chain;
4318 tb->yank_eol = FALSE;
4320 if (NULL == tb->yank)
4322 tb->yank = new_chain_str(str);
4332 chain->next = new_chain_str(str);
4337 chain = chain->next;
4343 * Do work for the copy editor-command
4345 static void copy_text_to_yank(text_body_type *tb)
4347 int len = strlen(tb->lines_list[tb->cy]);
4349 /* Correct cursor location */
4350 if (tb->cx > len) tb->cx = len;
4352 /* Use single line? */
4355 /* Select a single line */
4361 /* Kill old yank buffer */
4362 kill_yank_chain(tb);
4365 /* Single line case */
4366 if (tb->my == tb->cy)
4369 char buf[MAX_LINELEN];
4370 int bx1 = MIN(tb->mx, tb->cx);
4371 int bx2 = MAX(tb->mx, tb->cx);
4373 /* Correct fake cursor position */
4374 if (bx2 > len) bx2 = len;
4376 /* Whole part of this line is selected */
4377 if (bx1 == 0 && bx2 == len)
4379 /* Copy this line */
4380 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4382 /* Add end of line to the buffer */
4383 add_str_to_yank(tb, "");
4386 /* Segment of this line is selected */
4389 for (i = 0; i < bx2 - bx1; i++)
4391 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4395 /* Copy this segment of line */
4396 add_str_to_yank(tb, buf);
4400 /* Multiple lines case */
4401 else /* if (tb->my != tb->cy) */
4405 int by1 = MIN(tb->my, tb->cy);
4406 int by2 = MAX(tb->my, tb->cy);
4409 for (y = by1; y <= by2; y++)
4411 /* Copy this line */
4412 add_str_to_yank(tb, tb->lines_list[y]);
4415 /* Add final end of line to the buffer */
4416 add_str_to_yank(tb, "");
4419 /* Disable selection */
4423 tb->dirty_flags |= DIRTY_ALL;
4427 #define DESCRIPT_HGT 3
4432 static void draw_text_editor(text_body_type *tb)
4435 int by1 = 0, by2 = 0;
4437 Term_get_size(&tb->wid, &tb->hgt);
4440 * Top line (-1), description line (-3), separator (-1)
4443 tb->hgt -= 2 + DESCRIPT_HGT;
4446 /* Don't let cursor at second byte of kanji */
4447 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4448 if (iskanji(tb->lines_list[tb->cy][i]))
4454 * Move to a correct position in the
4457 if (i & 1) tb->cx--;
4464 /* Scroll if necessary */
4465 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4466 tb->upper = tb->cy - (tb->hgt)/2;
4469 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4470 tb->left = tb->cx - (tb->wid)*2/3;
4474 /* Redraw whole window after resize */
4475 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4476 tb->dirty_flags |= DIRTY_SCREEN;
4478 /* Redraw all text after scroll */
4479 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4480 tb->dirty_flags |= DIRTY_ALL;
4483 if (tb->dirty_flags & DIRTY_SCREEN)
4485 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4489 /* Redraw mode line */
4490 if (tb->dirty_flags & DIRTY_MODE)
4492 char buf[MAX_LINELEN];
4494 int sepa_length = tb->wid;
4497 for (i = 0; i < sepa_length; i++)
4501 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4504 if (tb->dirty_flags & DIRTY_EXPRESSION)
4509 for (y = 0; tb->lines_list[y]; y++)
4513 concptr s = tb->lines_list[y];
4517 /* Update this line's state */
4518 tb->states[y] = state;
4520 if (*s++ != '?') continue;
4521 if (*s++ != ':') continue;
4523 /* Lines below this line are auto-registered */
4524 if (streq(s, "$AUTOREGISTER"))
4525 state |= LSTAT_AUTOREGISTER;
4528 ss = (char *)string_make(s);
4531 /* Parse the expr */
4532 v = process_pref_file_expr(&ss, &f);
4535 if (streq(v, "0")) state |= LSTAT_BYPASS;
4536 else state &= ~LSTAT_BYPASS;
4538 /* Cannot use string_free() because the string was "destroyed" */
4539 C_KILL(s_keep, s_len + 1, char);
4541 /* Re-update this line's state */
4542 tb->states[y] = state | LSTAT_EXPRESSION;
4545 tb->dirty_flags |= DIRTY_ALL;
4550 tb->dirty_flags |= DIRTY_ALL;
4552 by1 = MIN(tb->my, tb->cy);
4553 by2 = MAX(tb->my, tb->cy);
4556 /* Dump up to tb->hgt lines of messages */
4557 for (i = 0; i < tb->hgt; i++)
4563 int y = tb->upper+i;
4565 /* clean or dirty? */
4566 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4569 msg = tb->lines_list[y];
4572 /* Apply horizontal scroll */
4573 for (j = 0; *msg; msg++, j++)
4575 if (j == tb->left) break;
4591 Term_erase(0, i + 1, tb->wid);
4593 if (tb->states[y] & LSTAT_AUTOREGISTER)
4595 /* Warning color -- These lines will be deleted later */
4600 /* Bypassed line will be displayed by darker color */
4601 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4602 else color = TERM_WHITE;
4605 /* No mark or Out of mark */
4606 if (!tb->mark || (y < by1 || by2 < y))
4608 /* Dump the messages, bottom to top */
4609 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4612 /* Multiple lines selected */
4613 else if (by1 != by2)
4615 /* Dump the messages, bottom to top */
4616 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4619 /* Single line selected */
4622 int x0 = leftcol + tb->left;
4623 int len = strlen(tb->lines_list[tb->cy]);
4624 int bx1 = MIN(tb->mx, tb->cx);
4625 int bx2 = MAX(tb->mx, tb->cx);
4627 /* Correct cursor location */
4628 if (bx2 > len) bx2 = len;
4630 Term_gotoxy(leftcol, i + 1);
4631 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4632 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4633 Term_addstr(-1, color, msg + (bx2 - x0));
4637 for (; i < tb->hgt; i++)
4640 Term_erase(0, i + 1, tb->wid);
4643 /* Display information when updated */
4644 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4646 autopick_type an_entry, *entry = &an_entry;
4647 concptr str1 = NULL, str2 = NULL;
4650 /* Clear information line */
4651 for (i = 0; i < DESCRIPT_HGT; i++)
4654 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4657 /* Display information */
4658 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4660 str1 = format(_("パターンが見つかりません: %s", "Pattern not found: %s"), tb->search_str);
4662 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4664 str1 = format(_("無効状態の行をスキップしました。(%sを検索中)",
4665 "Some inactive lines are skipped. (Searching %s)"), tb->search_str);
4667 else if (tb->dirty_flags & DIRTY_INACTIVE)
4669 str1 = format(_("無効状態の行だけが見付かりました。(%sを検索中)",
4670 "Found only an inactive line. (Searching %s)"), tb->search_str);
4672 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4674 str1 = _("検索するパターンがありません(^S で検索)。", "No pattern to search. (Press ^S to search.)");
4676 else if (tb->lines_list[tb->cy][0] == '#')
4678 str1 = _("この行はコメントです。", "This line is a comment.");
4680 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4682 switch(tb->lines_list[tb->cy][0])
4685 str1 = _("この行は条件分岐式です。", "This line is a Conditional Expression.");
4688 str1 = _("この行はマクロの実行内容を定義します。", "This line defines a Macro action.");
4691 str1 = _("この行はマクロのトリガー・キーを定義します。", "This line defines a Macro trigger key.");
4694 str1 = _("この行はキー配置を定義します。", "This line defines a Keymap.");
4698 switch(tb->lines_list[tb->cy][0])
4701 if (tb->states[tb->cy] & LSTAT_BYPASS)
4703 str2 = _("現在の式の値は「偽(=0)」です。", "The expression is 'False'(=0) currently.");
4707 str2 = _("現在の式の値は「真(=1)」です。", "The expression is 'True'(=1) currently.");
4712 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4714 str2 = _("この行は後で削除されます。", "This line will be delete later.");
4717 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4719 str2 = _("この行は現在は無効な状態です。", "This line is bypassed currently.");
4725 /* Get description of an autopicker preference line */
4726 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4728 char buf[MAX_LINELEN];
4729 char temp[MAX_LINELEN];
4732 describe_autopick(buf, entry);
4734 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4736 strcat(buf, _("この行は後で削除されます。", " This line will be delete later."));
4739 if (tb->states[tb->cy] & LSTAT_BYPASS)
4741 strcat(buf, _("この行は現在は無効な状態です。", " This line is bypassed currently."));
4744 roff_to_buf(buf, 81, temp, sizeof(temp));
4746 for (i = 0; i < 3; i++)
4752 prt(t, tb->hgt +1 + 1 + i, 0);
4756 autopick_free_entry(entry);
4759 /* Draw the first line */
4760 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4762 /* Draw the second line */
4763 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4769 * Kill segment of a line
4771 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4773 char buf[MAX_LINELEN];
4774 concptr s = tb->lines_list[y];
4778 /* Kill whole line? */
4779 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4783 string_free(tb->lines_list[y]);
4785 /* Shift lines up */
4786 for (i = y; tb->lines_list[i+1]; i++)
4787 tb->lines_list[i] = tb->lines_list[i+1];
4788 tb->lines_list[i] = NULL;
4790 /* Expressions need re-evaluation */
4791 tb->dirty_flags |= DIRTY_EXPRESSION;
4797 if (x0 == x1) return;
4799 /* Before the segment */
4800 for (x = 0; x < x0; x++)
4803 /* After the segment */
4804 for (x = x1; s[x]; x++)
4810 string_free(tb->lines_list[y]);
4811 tb->lines_list[y] = string_make(buf);
4813 /* Expressions may need re-evaluation */
4814 check_expression_line(tb, y);
4816 /* Text is changed */
4822 * Get a trigger key and insert ASCII string for the trigger
4824 static bool insert_macro_line(text_body_type *tb)
4833 /* Do not process macros */
4839 /* Read the pattern */
4845 /* Do not process macros */
4848 /* Do not wait for keys */
4851 /* Attempt to read a key */
4860 /* Convert the trigger */
4861 ascii_to_text(tmp, buf);
4864 if(!tmp[0]) return FALSE;
4868 /* Insert preference string */
4869 insert_return_code(tb);
4870 string_free(tb->lines_list[tb->cy]);
4871 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4873 /* Acquire action */
4874 i = macro_find_exact(buf);
4878 /* Nothing defined */
4883 /* Analyze the current action */
4884 ascii_to_text(tmp, macro__act[i]);
4887 /* Insert blank action preference line */
4888 insert_return_code(tb);
4889 string_free(tb->lines_list[tb->cy]);
4890 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4897 * Get a command key and insert ASCII string for the key
4899 static bool insert_keymap_line(text_body_type *tb)
4907 if (rogue_like_commands)
4909 mode = KEYMAP_MODE_ROGUE;
4915 mode = KEYMAP_MODE_ORIG;
4926 /* Convert the trigger */
4927 ascii_to_text(tmp, buf);
4930 if(!tmp[0]) return FALSE;
4934 /* Insert preference string */
4935 insert_return_code(tb);
4936 string_free(tb->lines_list[tb->cy]);
4937 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4939 /* Look up the keymap */
4940 act = keymap_act[mode][(byte)(buf[0])];
4944 /* Analyze the current action */
4945 ascii_to_text(tmp, act);
4949 /* No keymap defined -- Use trigger key itself as a default */
4951 /* Nothing to do (use tmp) */
4954 /* Insert blank action preference line */
4955 insert_return_code(tb);
4956 string_free(tb->lines_list[tb->cy]);
4957 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4964 * Execute a single editor command
4966 static bool do_editor_command(text_body_type *tb, int com_id)
4973 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
4974 "Discard all changes and quit. Are you sure? "))) break;
4976 return QUIT_WITHOUT_SAVE;
4979 return QUIT_AND_SAVE;
4982 /* Revert to original */
4983 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
4984 "Discard all changes and revert to original file. Are you sure? "))) break;
4986 free_text_lines(tb->lines_list);
4987 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4988 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4989 tb->cx = tb->cy = 0;
4992 /* Text is not changed */
4993 tb->changed = FALSE;
4997 /* Peruse the main help file */
4998 (void)show_file(TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
5000 tb->dirty_flags |= DIRTY_SCREEN;
5005 /* Split a line or insert end of line */
5007 /* Ignore selection */
5013 tb->dirty_flags |= DIRTY_ALL;
5016 insert_return_code(tb);
5021 tb->dirty_flags |= DIRTY_ALL;
5034 len = strlen(tb->lines_list[tb->cy]);
5035 if (len < tb->cx) tb->cx = len;
5038 /* Don't let cursor at second byte of kanji */
5039 for (i = 0; tb->lines_list[tb->cy][i]; i++)
5041 if (iskanji(tb->lines_list[tb->cy][i]))
5046 /* Move to the left */
5054 else if (tb->cy > 0)
5057 tb->cx = strlen(tb->lines_list[tb->cy]);
5064 /* Is this the last line? */
5065 if (!tb->lines_list[tb->cy + 1])
5067 /* Add one more empty line if possible */
5068 if (!add_empty_line(tb)) break;
5078 if (tb->cy > 0) tb->cy--;
5087 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5090 len = strlen(tb->lines_list[tb->cy]);
5093 /* Correct the cursor position */
5096 /* Is this the last line? */
5097 if (!tb->lines_list[tb->cy + 1])
5099 /* Add one more empty line if possible */
5100 if (!add_empty_line(tb)) break;
5103 /* Move to the beginning of next line */
5111 /* Beginning of line */
5117 tb->cx = strlen(tb->lines_list[tb->cy]);
5121 while (0 < tb->cy && tb->upper <= tb->cy)
5123 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
5129 while (tb->cy < tb->upper + tb->hgt)
5131 /* Is this the last line? */
5132 if (!tb->lines_list[tb->cy + 1])
5134 /* Add one more empty line if possible */
5135 if (!add_empty_line(tb)) break;
5151 /* Is this the last line? */
5152 if (!tb->lines_list[tb->cy + 1])
5154 /* Add one more empty line if possible */
5155 if (!add_empty_line(tb)) break;
5161 /* Always at the biginning of the last line */
5168 /* Copy the text first */
5169 copy_text_to_yank(tb);
5171 /* Single line case */
5172 if (tb->my == tb->cy)
5174 int bx1 = MIN(tb->mx, tb->cx);
5175 int bx2 = MAX(tb->mx, tb->cx);
5176 int len = strlen(tb->lines_list[tb->cy]);
5178 /* Correct fake cursor position */
5179 if (bx2 > len) bx2 = len;
5181 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5183 /* New cursor position */
5187 /* Multiple lines case */
5188 else /* if (tb->my != tb->cy) */
5192 int by1 = MIN(tb->my, tb->cy);
5193 int by2 = MAX(tb->my, tb->cy);
5195 /* Kill lines in reverse order */
5196 for (y = by2; y >= by1; y--)
5198 int len = strlen(tb->lines_list[y]);
5200 kill_line_segment(tb, y, 0, len, TRUE);
5203 /* New cursor position */
5209 /* Disable selection */
5213 tb->dirty_flags |= DIRTY_ALL;
5215 /* Text is changed */
5222 copy_text_to_yank(tb);
5225 * Move cursor position to the end of the selection
5227 * Pressing ^C ^V correctly duplicates the selection.
5229 if (tb->my == tb->cy)
5231 tb->cx = MAX(tb->cx, tb->mx);
5234 * When whole line is selected, the end of
5235 * line code is also copyed.
5237 if (!tb->lines_list[tb->cy][tb->cx])
5239 /* Is this the last line? */
5240 if (!tb->lines_list[tb->cy + 1])
5242 /* Add one more empty line if possible */
5243 if (!add_empty_line(tb)) break;
5246 /* Go to the beginning of next line */
5253 tb->cy = MAX(tb->cy, tb->my);
5255 /* Is this the last line? */
5256 if (!tb->lines_list[tb->cy + 1])
5258 /* Add one more empty line if possible */
5259 if (!add_empty_line(tb)) break;
5270 /* Paste killed text */
5272 chain_str_type *chain = tb->yank;
5273 int len = strlen(tb->lines_list[tb->cy]);
5275 /* Nothing to do? */
5278 /* Correct cursor location */
5279 if (tb->cx > len) tb->cx = len;
5281 /* Ignore selection */
5287 tb->dirty_flags |= DIRTY_ALL;
5293 concptr yank_str = chain->s;
5295 char buf[MAX_LINELEN];
5297 char rest[MAX_LINELEN], *rest_ptr = rest;
5299 /* Save preceding string */
5300 for(i = 0; i < tb->cx; i++)
5301 buf[i] = tb->lines_list[tb->cy][i];
5303 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5305 /* Paste yank buffer */
5306 while (*yank_str && i < MAX_LINELEN-1)
5308 buf[i++] = *yank_str++;
5314 chain = chain->next;
5316 if (chain || tb->yank_eol)
5318 /* There is an end of line between chain nodes */
5320 insert_return_code(tb);
5322 /* Replace this line with new one */
5323 string_free(tb->lines_list[tb->cy]);
5324 tb->lines_list[tb->cy] = string_make(buf);
5326 /* Move to next line */
5333 /* Final line doesn't have end of line */
5335 tb->cx = strlen(buf);
5337 /* Rest of original line */
5338 while (*rest_ptr && i < MAX_LINELEN-1)
5340 buf[i++] = *rest_ptr++;
5346 /* Replace this line with new one */
5347 string_free(tb->lines_list[tb->cy]);
5348 tb->lines_list[tb->cy] = string_make(buf);
5355 tb->dirty_flags |= DIRTY_ALL;
5357 /* Expressions need re-evaluation */
5358 tb->dirty_flags |= DIRTY_EXPRESSION;
5360 /* Text is changed */
5369 /* Disable the selection */
5373 tb->dirty_flags |= DIRTY_ALL;
5377 tb->mark = MARK_MARK;
5379 /* Repeating this command swaps cursor position */
5380 if (com_id == tb->old_com_id)
5392 tb->dirty_flags |= DIRTY_ALL;
5396 int len = strlen(tb->lines_list[tb->cy]);
5398 /* Mark the point 1 */
5402 /* Correct cursor location */
5403 if (tb->cx > len) tb->mx = len;
5410 /* Kill rest of line */
5412 int len = strlen(tb->lines_list[tb->cy]);
5414 /* Correct cursor location */
5415 if (tb->cx > len) tb->cx = len;
5417 /* Ignore selection */
5423 tb->dirty_flags |= DIRTY_ALL;
5426 /* Append only if this command is repeated. */
5427 if (tb->old_com_id != com_id)
5429 kill_yank_chain(tb);
5433 /* Really deleted some text */
5436 /* Add deleted string to yank buffer */
5437 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5439 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5442 tb->dirty_line = tb->cy;
5444 /* Leave end of line character */
5448 /* Cut the end of line character only */
5449 if (tb->yank_eol) add_str_to_yank(tb, "");
5451 /* Cut end of line */
5452 tb->yank_eol = TRUE;
5454 do_editor_command(tb, EC_DELETE_CHAR);
5458 case EC_DELETE_CHAR:
5460 /* DELETE == go forward + BACK SPACE */
5464 /* Ignore selection */
5470 tb->dirty_flags |= DIRTY_ALL;
5474 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5478 /* Pass through the end of line to next line */
5479 len = strlen(tb->lines_list[tb->cy]);
5482 if (tb->lines_list[tb->cy + 1])
5494 do_editor_command(tb, EC_BACKSPACE);
5503 char buf[MAX_LINELEN];
5505 /* Ignore selection */
5511 tb->dirty_flags |= DIRTY_ALL;
5514 /* Move to correct collumn */
5515 len = strlen(tb->lines_list[tb->cy]);
5516 if (len < tb->cx) tb->cx = len;
5520 /* delete a return code and union two lines */
5521 if (tb->cy == 0) break;
5522 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5523 strcpy(buf, tb->lines_list[tb->cy-1]);
5524 strcat(buf, tb->lines_list[tb->cy]);
5525 string_free(tb->lines_list[tb->cy-1]);
5526 string_free(tb->lines_list[tb->cy]);
5527 tb->lines_list[tb->cy-1] = string_make(buf);
5529 for (i = tb->cy; tb->lines_list[i+1]; i++)
5530 tb->lines_list[i] = tb->lines_list[i+1];
5532 tb->lines_list[i] = NULL;
5536 tb->dirty_flags |= DIRTY_ALL;
5538 /* Expressions need re-evaluation */
5539 tb->dirty_flags |= DIRTY_EXPRESSION;
5541 /* Text is changed */
5547 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5551 if (iskanji(tb->lines_list[tb->cy][i]))
5552 buf[j++] = tb->lines_list[tb->cy][i++];
5554 buf[j++] = tb->lines_list[tb->cy][i];
5561 for (; tb->lines_list[tb->cy][i]; i++)
5562 buf[j++] = tb->lines_list[tb->cy][i];
5564 string_free(tb->lines_list[tb->cy]);
5565 tb->lines_list[tb->cy] = string_make(buf);
5568 tb->dirty_line = tb->cy;
5570 /* Expressions may need re-evaluation */
5571 check_expression_line(tb, tb->cy);
5573 /* Text is changed */
5583 /* Become dirty because of item/equip menu */
5584 tb->dirty_flags |= DIRTY_SCREEN;
5586 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5588 if (!search_dir) break;
5590 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5591 else do_editor_command(tb, EC_SEARCH_BACK);
5595 case EC_SEARCH_FORW:
5596 if (tb->search_o_ptr)
5598 search_for_object(tb, tb->search_o_ptr, TRUE);
5600 else if (tb->search_str && tb->search_str[0])
5602 search_for_string(tb, tb->search_str, TRUE);
5606 tb->dirty_flags |= DIRTY_NO_SEARCH;
5610 case EC_SEARCH_BACK:
5611 if (tb->search_o_ptr)
5613 search_for_object(tb, tb->search_o_ptr, FALSE);
5615 else if (tb->search_str && tb->search_str[0])
5617 search_for_string(tb, tb->search_str, FALSE);
5621 tb->dirty_flags |= DIRTY_NO_SEARCH;
5626 /* Become dirty because of item/equip menu */
5627 tb->dirty_flags |= DIRTY_SCREEN;
5629 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5631 do_editor_command(tb, EC_SEARCH_FORW);
5634 case EC_SEARCH_DESTROYED:
5635 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5637 /* There is no object to search */
5638 tb->dirty_flags |= DIRTY_NO_SEARCH;
5643 do_editor_command(tb, EC_SEARCH_FORW);
5646 case EC_INSERT_OBJECT:
5648 /* Insert choosen item name */
5650 autopick_type an_entry, *entry = &an_entry;
5652 if (!entry_from_choosed_object(entry))
5654 /* Now dirty because of item/equip menu */
5655 tb->dirty_flags |= DIRTY_SCREEN;
5660 insert_return_code(tb);
5661 string_free(tb->lines_list[tb->cy]);
5662 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5664 /* Now dirty because of item/equip menu */
5665 tb->dirty_flags |= DIRTY_SCREEN;
5670 case EC_INSERT_DESTROYED:
5671 /* Insert a name of last destroyed item */
5672 if (tb->last_destroyed)
5675 insert_return_code(tb);
5676 string_free(tb->lines_list[tb->cy]);
5677 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5680 tb->dirty_flags |= DIRTY_ALL;
5682 /* Text is changed */
5687 case EC_INSERT_BLOCK:
5689 /* Insert a conditinal expression line */
5690 char expression[80];
5692 /* Conditional Expression for Class and Race */
5693 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5695 rp_ptr->E_title, cp_ptr->E_title,
5697 rp_ptr->title, cp_ptr->title,
5703 insert_return_code(tb);
5704 string_free(tb->lines_list[tb->cy]);
5705 tb->lines_list[tb->cy] = string_make(expression);
5707 insert_return_code(tb);
5708 string_free(tb->lines_list[tb->cy]);
5709 tb->lines_list[tb->cy] = string_make("?:1");
5712 tb->dirty_flags |= DIRTY_ALL;
5714 /* Text is changed */
5720 case EC_INSERT_MACRO:
5721 /* Draw_everythig (delete menu) */
5722 draw_text_editor(tb);
5725 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5728 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
5729 if (insert_macro_line(tb))
5731 /* Prepare to input action */
5735 tb->dirty_flags |= DIRTY_ALL;
5737 /* Text is changed */
5743 case EC_INSERT_KEYMAP:
5744 /* Draw_everythig (delete menu) */
5745 draw_text_editor(tb);
5748 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5751 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
5752 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5754 if (insert_keymap_line(tb))
5756 /* Prepare to input action */
5760 tb->dirty_flags |= DIRTY_ALL;
5762 /* Text is changed */
5767 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5768 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5769 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5770 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5771 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5773 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5774 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5775 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5776 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5777 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5778 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5779 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5780 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5781 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5782 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5783 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5784 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5785 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5786 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5787 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5788 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5789 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5790 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5791 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5792 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5793 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5794 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5795 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5796 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5797 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5798 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5799 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5800 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5801 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5802 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5803 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5804 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5805 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5806 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5807 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5808 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5809 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5810 case EC_OK_UNREADABLE:
5811 toggle_keyword(tb, FLG_UNREADABLE);
5812 add_keyword(tb, FLG_SPELLBOOKS);
5815 toggle_keyword(tb, FLG_REALM1);
5816 add_keyword(tb, FLG_SPELLBOOKS);
5819 toggle_keyword(tb, FLG_REALM2);
5820 add_keyword(tb, FLG_SPELLBOOKS);
5823 toggle_keyword(tb, FLG_FIRST);
5824 add_keyword(tb, FLG_SPELLBOOKS);
5827 toggle_keyword(tb, FLG_SECOND);
5828 add_keyword(tb, FLG_SPELLBOOKS);
5831 toggle_keyword(tb, FLG_THIRD);
5832 add_keyword(tb, FLG_SPELLBOOKS);
5835 toggle_keyword(tb, FLG_FOURTH);
5836 add_keyword(tb, FLG_SPELLBOOKS);
5840 /* Save old command */
5841 tb->old_com_id = com_id;
5848 * Insert single letter at cursor position.
5850 static void insert_single_letter(text_body_type *tb, int key)
5853 char buf[MAX_LINELEN];
5855 /* Save preceding string */
5856 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5857 buf[j++] = tb->lines_list[tb->cy][i];
5859 /* Add a character */
5867 if (j+2 < MAX_LINELEN)
5869 buf[j++] = (char)key;
5870 buf[j++] = (char)next;
5879 if (j+1 < MAX_LINELEN)
5880 buf[j++] = (char)key;
5885 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5886 buf[j++] = tb->lines_list[tb->cy][i];
5889 /* Replace current line with new line */
5890 string_free(tb->lines_list[tb->cy]);
5891 tb->lines_list[tb->cy] = string_make(buf);
5893 /* Move to correct collumn */
5894 len = strlen(tb->lines_list[tb->cy]);
5895 if (len < tb->cx) tb->cx = len;
5898 tb->dirty_line = tb->cy;
5900 /* Expressions may need re-evaluation */
5901 check_expression_line(tb, tb->cy);
5903 /* Text is changed */
5909 * Check special key code and get a movement command id
5911 static int analyze_move_key(text_body_type *tb, int skey)
5915 /* Not a special key */
5916 if (!(skey & SKEY_MASK)) return 0;
5918 /* Convert from a special key code to an editor command */
5919 switch(skey & ~SKEY_MOD_MASK)
5921 case SKEY_DOWN: com_id = EC_DOWN; break;
5922 case SKEY_LEFT: com_id = EC_LEFT; break;
5923 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5924 case SKEY_UP: com_id = EC_UP; break;
5925 case SKEY_PGUP: com_id = EC_PGUP; break;
5926 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5927 case SKEY_TOP: com_id = EC_TOP; break;
5928 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5931 /* Not a special movement key */
5935 /* Without shift modifier */
5936 if (!(skey & SKEY_MOD_SHIFT))
5939 * Un-shifted cursor keys cancells
5940 * selection created by shift+cursor.
5942 if (tb->mark & MARK_BY_SHIFT)
5947 tb->dirty_flags |= DIRTY_ALL;
5951 /* With shift modifier */
5954 /* Start selection by shift + cursor keys */
5957 int len = strlen(tb->lines_list[tb->cy]);
5959 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5963 /* Correct cursor location */
5964 if (tb->cx > len) tb->mx = len;
5966 /* Need to redraw text */
5967 if (com_id == EC_UP || com_id == EC_DOWN)
5969 /* Redraw all text */
5970 tb->dirty_flags |= DIRTY_ALL;
5974 tb->dirty_line = tb->cy;
5983 * In-game editor of Object Auto-picker/Destoryer
5985 void do_cmd_edit_autopick(void)
5987 static int cx_save = 0;
5988 static int cy_save = 0;
5990 text_body_type text_body, *tb = &text_body;
5992 autopick_type an_entry, *entry = &an_entry;
5993 char buf[MAX_LINELEN];
5998 static s32b old_autosave_turn = 0L;
6001 tb->changed = FALSE;
6004 tb->upper = tb->left = 0;
6006 tb->mx = tb->my = 0;
6007 tb->old_cy = tb->old_upper = tb->old_left = -1;
6008 tb->old_wid = tb->old_hgt = -1;
6012 tb->search_o_ptr = NULL;
6013 tb->search_str = NULL;
6014 tb->last_destroyed = NULL;
6015 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
6016 tb->dirty_line = -1;
6017 tb->filename_mode = PT_DEFAULT;
6019 if (current_world_ptr->game_turn < old_autosave_turn)
6021 while (old_autosave_turn > current_world_ptr->game_turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
6025 if (current_world_ptr->game_turn > old_autosave_turn + 100L)
6027 do_cmd_save_game(TRUE);
6028 old_autosave_turn = current_world_ptr->game_turn;
6031 /* HACK -- Reset start_time to stop counting current_world_ptr->play_time while edit */
6034 /* Free old entries */
6037 /* Command Description of the 'Last Destroyed Item' */
6038 if (autopick_last_destroyed_object.k_idx)
6040 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
6041 tb->last_destroyed = autopick_line_from_entry_kill(entry);
6044 /* Read or initialize whole text */
6045 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
6047 /* Reset cursor position if needed */
6048 for (i = 0; i < tb->cy; i++)
6050 if (!tb->lines_list[i])
6052 tb->cy = tb->cx = 0;
6058 /* Process requests until done */
6063 /* Draw_everythig */
6064 draw_text_editor(tb);
6066 /* Display header line */
6067 prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)",
6068 "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0);
6071 /* Display current position */
6072 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
6076 /* Display current position and mark position */
6077 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
6081 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
6084 tb->dirty_flags = 0;
6085 tb->dirty_line = -1;
6087 /* Save old key and location */
6088 tb->old_cy = tb->cy;
6089 tb->old_upper = tb->upper;
6090 tb->old_left = tb->left;
6091 tb->old_wid = tb->wid;
6092 tb->old_hgt = tb->hgt;
6094 key = inkey_special(TRUE);
6097 if (key & SKEY_MASK)
6099 /* Get a movement command */
6100 com_id = analyze_move_key(tb, key);
6104 else if (key == ESCAPE)
6106 com_id = do_command_menu(0, 0);
6108 /* Redraw all text later */
6109 tb->dirty_flags |= DIRTY_SCREEN;
6112 /* Insert a character */
6113 else if (!iscntrl((unsigned char)key))
6115 /* Ignore selection */
6121 tb->dirty_flags |= DIRTY_ALL;
6124 insert_single_letter(tb, key);
6130 /* Other commands */
6133 com_id = get_com_id((char)key);
6136 if (com_id) quit = do_editor_command(tb, com_id);
6137 } /* while (TRUE) */
6140 /* Get the filename of preference */
6141 strcpy(buf, pickpref_filename(tb->filename_mode));
6143 if (quit == QUIT_AND_SAVE)
6144 write_text_lines(buf, tb->lines_list);
6146 free_text_lines(tb->lines_list);
6148 string_free(tb->search_str);
6149 string_free(tb->last_destroyed);
6151 /* Destroy string chain */
6152 kill_yank_chain(tb);
6154 /* Reload autopick pref */
6155 process_autopick_file(buf);
6157 /* HACK -- reset start_time so that current_world_ptr->play_time is not increase while edit */
6158 start_time = (u32b)time(NULL);
6160 /* Save cursor location */