3 * @brief 自動拾い機能の実装 / Object Auto-picker/Destroyer
6 * Copyright (c) 2002 Mogami\n
8 * This software may be copied and distributed for educational, research, and\n
9 * not for profit purposes provided that this copyright and statement are\n
10 * included in all such copies.\n
11 * 2014 Deskull rearranged comment for Doxygen.\n
23 #include "player-status.h"
24 #include "player-move.h"
25 #include "player-class.h"
26 #include "player-race.h"
27 #include "player-inventory.h"
28 #include "objectkind.h"
29 #include "object-ego.h"
30 #include "object-flavor.h"
31 #include "object-hook.h"
37 #include "monsterrace.h"
38 #include "view-mainwindow.h"
40 #define MAX_LINELEN 1024
47 #define FLG_UNIDENTIFIED 2
48 #define FLG_IDENTIFIED 3
49 #define FLG_STAR_IDENTIFIED 4
50 #define FLG_COLLECTING 5
51 #define FLG_ARTIFACT 6
54 #define FLG_NAMELESS 11
55 #define FLG_AVERAGE 12
56 #define FLG_WORTHLESS 13
59 #define FLG_BOOSTED 16
60 #define FLG_MORE_DICE 17
61 #define FLG_MORE_BONUS 18
65 #define FLG_UNREADABLE 22
74 #define FLG_WEAPONS 31
75 #define FLG_FAVORITE_WEAPONS 32
77 #define FLG_MISSILES 34
78 #define FLG_DEVICES 35
81 #define FLG_CORPSES 38
82 #define FLG_SPELLBOOKS 39
84 #define FLG_SHIELDS 41
87 #define FLG_AMULETS 44
94 #define FLG_NOUN_BEGIN FLG_ITEMS
95 #define FLG_NOUN_END FLG_BOOTS
99 static GAME_TEXT KEY_ALL[] = "すべての";
100 static GAME_TEXT KEY_UNAWARE[] = "未判明の";
101 static GAME_TEXT KEY_UNIDENTIFIED[] = "未鑑定の";
102 static GAME_TEXT KEY_IDENTIFIED[] = "鑑定済みの";
103 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*鑑定*済みの";
104 static GAME_TEXT KEY_COLLECTING[] = "収集中の";
105 static GAME_TEXT KEY_ARTIFACT[] = "アーティファクト";
106 static GAME_TEXT KEY_EGO[] = "エゴ";
107 static GAME_TEXT KEY_GOOD[] = "上質の";
108 static GAME_TEXT KEY_NAMELESS[] = "無銘の";
109 static GAME_TEXT KEY_AVERAGE[] = "並の";
110 static GAME_TEXT KEY_WORTHLESS[] = "無価値の";
111 static GAME_TEXT KEY_RARE[] = "レアな";
112 static GAME_TEXT KEY_COMMON[] = "ありふれた";
113 static GAME_TEXT KEY_BOOSTED[] = "ダイス目の違う";
114 static GAME_TEXT KEY_MORE_THAN[] = "ダイス目";
115 static GAME_TEXT KEY_DICE[] = "以上の";
116 static GAME_TEXT KEY_MORE_BONUS[] = "修正値";
117 static GAME_TEXT KEY_MORE_BONUS2[] = "以上の";
118 static GAME_TEXT KEY_WANTED[] = "賞金首の";
119 static GAME_TEXT KEY_UNIQUE[] = "ユニーク・モンスターの";
120 static GAME_TEXT KEY_HUMAN[] = "人間の";
121 static GAME_TEXT KEY_UNREADABLE[] = "読めない";
122 static GAME_TEXT KEY_REALM1[] = "第一領域の";
123 static GAME_TEXT KEY_REALM2[] = "第二領域の";
124 static GAME_TEXT KEY_FIRST[] = "1冊目の";
125 static GAME_TEXT KEY_SECOND[] = "2冊目の";
126 static GAME_TEXT KEY_THIRD[] = "3冊目の";
127 static GAME_TEXT KEY_FOURTH[] = "4冊目の";
128 static GAME_TEXT KEY_ITEMS[] = "アイテム";
129 static GAME_TEXT KEY_WEAPONS[] = "武器";
130 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "得意武器";
131 static GAME_TEXT KEY_ARMORS[] = "防具";
132 static GAME_TEXT KEY_MISSILES[] = "矢";
133 static GAME_TEXT KEY_DEVICES[] = "魔法アイテム";
134 static GAME_TEXT KEY_LIGHTS[] = "光源";
135 static GAME_TEXT KEY_JUNKS[] = "がらくた";
136 static GAME_TEXT KEY_CORPSES[] = "死体や骨";
137 static GAME_TEXT KEY_SPELLBOOKS[] = "魔法書";
138 static GAME_TEXT KEY_HAFTED[] = "鈍器";
139 static GAME_TEXT KEY_SHIELDS[] = "盾";
140 static GAME_TEXT KEY_BOWS[] = "弓";
141 static GAME_TEXT KEY_RINGS[] = "指輪";
142 static GAME_TEXT KEY_AMULETS[] = "アミュレット";
143 static GAME_TEXT KEY_SUITS[] = "鎧";
144 static GAME_TEXT KEY_CLOAKS[] = "クローク";
145 static GAME_TEXT KEY_HELMS[] = "兜";
146 static GAME_TEXT KEY_GLOVES[] = "籠手";
147 static GAME_TEXT KEY_BOOTS[] = "靴";
151 static GAME_TEXT KEY_ALL[] = "all";
152 static GAME_TEXT KEY_UNAWARE[] = "unaware";
153 static GAME_TEXT KEY_UNIDENTIFIED[] = "unidentified";
154 static GAME_TEXT KEY_IDENTIFIED[] = "identified";
155 static GAME_TEXT KEY_STAR_IDENTIFIED[] = "*identified*";
156 static GAME_TEXT KEY_COLLECTING[] = "collecting";
157 static GAME_TEXT KEY_ARTIFACT[] = "artifact";
158 static GAME_TEXT KEY_EGO[] = "ego";
159 static GAME_TEXT KEY_GOOD[] = "good";
160 static GAME_TEXT KEY_NAMELESS[] = "nameless";
161 static GAME_TEXT KEY_AVERAGE[] = "average";
162 static GAME_TEXT KEY_WORTHLESS[] = "worthless";
163 static GAME_TEXT KEY_RARE[] = "rare";
164 static GAME_TEXT KEY_COMMON[] = "common";
165 static GAME_TEXT KEY_BOOSTED[] = "dice boosted";
166 static GAME_TEXT KEY_MORE_THAN[] = "more than";
167 static GAME_TEXT KEY_DICE[] = " dice";
168 static GAME_TEXT KEY_MORE_BONUS[] = "more bonus than";
169 static GAME_TEXT KEY_MORE_BONUS2[] = "";
170 static GAME_TEXT KEY_WANTED[] = "wanted";
171 static GAME_TEXT KEY_UNIQUE[] = "unique monster's";
172 static GAME_TEXT KEY_HUMAN[] = "human";
173 static GAME_TEXT KEY_UNREADABLE[] = "unreadable";
174 static GAME_TEXT KEY_REALM1[] = "first realm's";
175 static GAME_TEXT KEY_REALM2[] = "second realm's";
176 static GAME_TEXT KEY_FIRST[] = "first";
177 static GAME_TEXT KEY_SECOND[] = "second";
178 static GAME_TEXT KEY_THIRD[] = "third";
179 static GAME_TEXT KEY_FOURTH[] = "fourth";
180 static GAME_TEXT KEY_ITEMS[] = "items";
181 static GAME_TEXT KEY_WEAPONS[] = "weapons";
182 static GAME_TEXT KEY_FAVORITE_WEAPONS[] = "favorite weapons";
183 static GAME_TEXT KEY_ARMORS[] = "armors";
184 static GAME_TEXT KEY_MISSILES[] = "missiles";
185 static GAME_TEXT KEY_DEVICES[] = "magical devices";
186 static GAME_TEXT KEY_LIGHTS[] = "lights";
187 static GAME_TEXT KEY_JUNKS[] = "junks";
188 static GAME_TEXT KEY_CORPSES[] = "corpses or skeletons";
189 static GAME_TEXT KEY_SPELLBOOKS[] = "spellbooks";
190 static GAME_TEXT KEY_HAFTED[] = "hafted weapons";
191 static GAME_TEXT KEY_SHIELDS[] = "shields";
192 static GAME_TEXT KEY_BOWS[] = "bows";
193 static GAME_TEXT KEY_RINGS[] = "rings";
194 static GAME_TEXT KEY_AMULETS[] = "amulets";
195 static GAME_TEXT KEY_SUITS[] = "suits";
196 static GAME_TEXT KEY_CLOAKS[] = "cloaks";
197 static GAME_TEXT KEY_HELMS[] = "helms";
198 static GAME_TEXT KEY_GLOVES[] = "gloves";
199 static GAME_TEXT KEY_BOOTS[] = "boots";
203 #define MAX_AUTOPICK_DEFAULT 200
206 #define PT_WITH_PNAME 1
208 #define MAX_YANK MAX_LINELEN
209 #define MAX_LINES 3000
211 #define MARK_MARK 0x01
212 #define MARK_BY_SHIFT 0x02
214 #define LSTAT_BYPASS 0x01
215 #define LSTAT_EXPRESSION 0x02
216 #define LSTAT_AUTOREGISTER 0x04
218 #define QUIT_WITHOUT_SAVE 1
219 #define QUIT_AND_SAVE 2
222 * Dirty flag for text editor
224 #define DIRTY_ALL 0x0001
225 #define DIRTY_MODE 0x0004
226 #define DIRTY_SCREEN 0x0008
227 #define DIRTY_NOT_FOUND 0x0010
228 #define DIRTY_NO_SEARCH 0x0020
229 #define DIRTY_EXPRESSION 0x0040
230 #define DIRTY_SKIP_INACTIVE 0x0080
231 #define DIRTY_INACTIVE 0x0100
233 #define DESCRIPT_HGT 3
235 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
236 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
237 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
238 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
241 #define ADD_KEY(KEY) strcat(ptr, KEY)
243 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
245 #define ADD_KEY2(KEY) strcat(ptr, KEY)
247 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
248 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
249 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
250 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
253 static char kanji_colon[] = ":";
257 * 自動拾い/破壊設定のリストに関する変数 / List for auto-picker/destroyer entries
259 int max_autopick = 0; /*!< 現在登録している自動拾い/破壊設定の数 */
260 int max_max_autopick = 0; /*!< 自動拾い/破壊設定の限界数 */
261 autopick_type *autopick_list = NULL; /*!< 自動拾い/破壊設定構造体のポインタ配列 */
264 * Automatically destroy an item if it is to be destroyed
266 * When always_pickup is 'yes', we disable auto-destroyer function of
267 * auto-picker/destroyer, and do only easy-auto-destroyer.
269 static object_type autopick_last_destroyed_object;
272 * Struct for yank buffer
274 typedef struct chain_str {
275 struct chain_str *next;
280 * Data struct for text editor
286 int old_wid, old_hgt;
288 int old_upper, old_left;
292 object_type *search_o_ptr;
294 concptr last_destroyed;
296 chain_str_type *yank;
300 byte states[MAX_LINES];
311 * Editor command id's
314 #define EC_SAVEQUIT 2
332 #define EC_KILL_LINE 20
333 #define EC_DELETE_CHAR 21
334 #define EC_BACKSPACE 22
335 #define EC_SEARCH_STR 23
336 #define EC_SEARCH_FORW 24
337 #define EC_SEARCH_BACK 25
338 #define EC_SEARCH_OBJ 26
339 #define EC_SEARCH_DESTROYED 27
340 #define EC_INSERT_OBJECT 28
341 #define EC_INSERT_DESTROYED 29
342 #define EC_INSERT_BLOCK 30
343 #define EC_INSERT_MACRO 31
344 #define EC_INSERT_KEYMAP 32
345 #define EC_CL_AUTOPICK 33
346 #define EC_CL_DESTROY 34
347 #define EC_CL_LEAVE 35
348 #define EC_CL_QUERY 36
349 #define EC_CL_NO_DISP 37
350 #define EC_OK_COLLECTING 38
351 #define EC_IK_UNAWARE 39
352 #define EC_IK_UNIDENTIFIED 40
353 #define EC_IK_IDENTIFIED 41
354 #define EC_IK_STAR_IDENTIFIED 42
355 #define EC_OK_BOOSTED 43
356 #define EC_OK_MORE_DICE 44
357 #define EC_OK_MORE_BONUS 45
358 #define EC_OK_WORTHLESS 46
359 #define EC_OK_ARTIFACT 47
361 #define EC_OK_GOOD 49
362 #define EC_OK_NAMELESS 50
363 #define EC_OK_AVERAGE 51
364 #define EC_OK_RARE 52
365 #define EC_OK_COMMON 53
366 #define EC_OK_WANTED 54
367 #define EC_OK_UNIQUE 55
368 #define EC_OK_HUMAN 56
369 #define EC_OK_UNREADABLE 57
370 #define EC_OK_REALM1 58
371 #define EC_OK_REALM2 59
372 #define EC_OK_FIRST 60
373 #define EC_OK_SECOND 61
374 #define EC_OK_THIRD 62
375 #define EC_OK_FOURTH 63
376 #define EC_KK_WEAPONS 64
377 #define EC_KK_FAVORITE_WEAPONS 65
378 #define EC_KK_ARMORS 66
379 #define EC_KK_MISSILES 67
380 #define EC_KK_DEVICES 68
381 #define EC_KK_LIGHTS 69
382 #define EC_KK_JUNKS 70
383 #define EC_KK_CORPSES 71
384 #define EC_KK_SPELLBOOKS 72
385 #define EC_KK_SHIELDS 73
386 #define EC_KK_BOWS 74
387 #define EC_KK_RINGS 75
388 #define EC_KK_AMULETS 76
389 #define EC_KK_SUITS 77
390 #define EC_KK_CLOAKS 78
391 #define EC_KK_HELMS 79
392 #define EC_KK_GLOVES 80
393 #define EC_KK_BOOTS 81
399 static GAME_TEXT MN_QUIT[] = "セーブ無しで終了";
400 static GAME_TEXT MN_SAVEQUIT[] = "セーブして終了";
401 static GAME_TEXT MN_REVERT[] = "全ての変更を破棄";
402 static GAME_TEXT MN_HELP[] = "ヘルプ";
404 static GAME_TEXT MN_MOVE[] = "カーソル移動";
405 static GAME_TEXT MN_LEFT[] = "左 (←矢印キー)";
406 static GAME_TEXT MN_DOWN[] = "下 (↓矢印キー)";
407 static GAME_TEXT MN_UP[] = "上 (↑矢印キー)";
408 static GAME_TEXT MN_RIGHT[] = "右 (→矢印キー)";
409 static GAME_TEXT MN_BOL[] = "行の先頭";
410 static GAME_TEXT MN_EOL[] = "行の終端";
411 static GAME_TEXT MN_PGUP[] = "上のページ (PageUpキー)";
412 static GAME_TEXT MN_PGDOWN[] = "下のページ (PageDownキー)";
413 static GAME_TEXT MN_TOP[] = "1行目へ移動 (Homeキー)";
414 static GAME_TEXT MN_BOTTOM[] = "最下行へ移動(Endキー)";
416 static GAME_TEXT MN_EDIT[] = "編集";
417 static GAME_TEXT MN_CUT[] = "カット";
418 static GAME_TEXT MN_COPY[] = "コピー";
419 static GAME_TEXT MN_PASTE[] = "ペースト";
420 static GAME_TEXT MN_BLOCK[] = "選択範囲の指定";
421 static GAME_TEXT MN_KILL_LINE[] = "行の残りを削除";
422 static GAME_TEXT MN_DELETE_CHAR[] = "1文字削除";
423 static GAME_TEXT MN_BACKSPACE[] = "バックスペース";
424 static GAME_TEXT MN_RETURN[] = "改行";
426 static GAME_TEXT MN_SEARCH[] = "検索";
427 static GAME_TEXT MN_SEARCH_STR[] = "文字列で検索";
428 static GAME_TEXT MN_SEARCH_FORW[] = "前方へ再検索";
429 static GAME_TEXT MN_SEARCH_BACK[] = "後方へ再検索";
430 static GAME_TEXT MN_SEARCH_OBJ[] = "アイテムを選択して検索";
431 static GAME_TEXT MN_SEARCH_DESTROYED[] = "自動破壊されたアイテムで検索";
433 static GAME_TEXT MN_INSERT[] = "色々挿入";
434 static GAME_TEXT MN_INSERT_OBJECT[] = "選択したアイテムの名前を挿入";
435 static GAME_TEXT MN_INSERT_DESTROYED[] = "自動破壊されたアイテムの名前を挿入";
436 static GAME_TEXT MN_INSERT_BLOCK[] = "条件分岐ブロックの例を挿入";
437 static GAME_TEXT MN_INSERT_MACRO[] = "マクロ定義を挿入";
438 static GAME_TEXT MN_INSERT_KEYMAP[] = "キーマップ定義を挿入";
440 static GAME_TEXT MN_COMMAND_LETTER[] = "拾い/破壊/放置の選択";
441 static GAME_TEXT MN_CL_AUTOPICK[] = "「 」 (自動拾い)";
442 static GAME_TEXT MN_CL_DESTROY[] = "「!」 (自動破壊)";
443 static GAME_TEXT MN_CL_LEAVE[] = "「~」 (放置)";
444 static GAME_TEXT MN_CL_QUERY[] = "「;」 (確認して拾う)";
445 static GAME_TEXT MN_CL_NO_DISP[] = "「(」 (マップコマンドで表示しない)";
447 static GAME_TEXT MN_ADJECTIVE_GEN[] = "形容詞(一般)の選択";
448 static GAME_TEXT MN_RARE[] = "レアな (装備)";
449 static GAME_TEXT MN_COMMON[] = "ありふれた (装備)";
451 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "形容詞(特殊)の選択";
452 static GAME_TEXT MN_BOOSTED[] = "ダイス目の違う (武器)";
453 static GAME_TEXT MN_MORE_DICE[] = "ダイス目 # 以上の (武器)";
454 static GAME_TEXT MN_MORE_BONUS[] = "修正値 # 以上の (指輪等)";
455 static GAME_TEXT MN_WANTED[] = "賞金首の (死体)";
456 static GAME_TEXT MN_UNIQUE[] = "ユニーク・モンスターの (死体)";
457 static GAME_TEXT MN_HUMAN[] = "人間の (死体)";
458 static GAME_TEXT MN_UNREADABLE[] = "読めない (魔法書)";
459 static GAME_TEXT MN_REALM1[] = "第一領域の (魔法書)";
460 static GAME_TEXT MN_REALM2[] = "第二領域の (魔法書)";
461 static GAME_TEXT MN_FIRST[] = "1冊目の (魔法書)";
462 static GAME_TEXT MN_SECOND[] = "2冊目の (魔法書)";
463 static GAME_TEXT MN_THIRD[] = "3冊目の (魔法書)";
464 static GAME_TEXT MN_FOURTH[] = "4冊目の (魔法書)";
466 static GAME_TEXT MN_NOUN[] = "名詞の選択";
470 static GAME_TEXT MN_QUIT[] = "Quit without save";
471 static GAME_TEXT MN_SAVEQUIT[] = "Save & Quit";
472 static GAME_TEXT MN_REVERT[] = "Revert all changes";
473 static GAME_TEXT MN_HELP[] = "Help";
475 static GAME_TEXT MN_MOVE[] = "Move cursor";
476 static GAME_TEXT MN_LEFT[] = "Left (Left Arrow key)";
477 static GAME_TEXT MN_DOWN[] = "Down (Down Arrow key)";
478 static GAME_TEXT MN_UP[] = "Up (Up Arrow key)";
479 static GAME_TEXT MN_RIGHT[] = "Right (Right Arrow key)";
480 static GAME_TEXT MN_BOL[] = "Beggining of line";
481 static GAME_TEXT MN_EOL[] = "End of line";
482 static GAME_TEXT MN_PGUP[] = "Page up (PageUp key)";
483 static GAME_TEXT MN_PGDOWN[] = "Page down(PageDown key)";
484 static GAME_TEXT MN_TOP[] = "Top (Home key)";
485 static GAME_TEXT MN_BOTTOM[] = "Bottom (End key)";
487 static GAME_TEXT MN_EDIT[] = "Edit";
488 static GAME_TEXT MN_CUT[] = "Cut";
489 static GAME_TEXT MN_COPY[] = "Copy";
490 static GAME_TEXT MN_PASTE[] = "Paste";
491 static GAME_TEXT MN_BLOCK[] = "Select block";
492 static GAME_TEXT MN_KILL_LINE[] = "Kill rest of line";
493 static GAME_TEXT MN_DELETE_CHAR[] = "Delete character";
494 static GAME_TEXT MN_BACKSPACE[] = "Backspace";
495 static GAME_TEXT MN_RETURN[] = "Return";
497 static GAME_TEXT MN_SEARCH[] = "Search";
498 static GAME_TEXT MN_SEARCH_STR[] = "Search by string";
499 static GAME_TEXT MN_SEARCH_FORW[] = "Search forward";
500 static GAME_TEXT MN_SEARCH_BACK[] = "Search backward";
501 static GAME_TEXT MN_SEARCH_OBJ[] = "Search by inventory list object";
502 static GAME_TEXT MN_SEARCH_DESTROYED[] = "Search by destroyed object";
504 static GAME_TEXT MN_INSERT[] = "Insert...";
505 static GAME_TEXT MN_INSERT_OBJECT[] = "Insert name of choosen object";
506 static GAME_TEXT MN_INSERT_DESTROYED[] = "Insert name of destroyed object";
507 static GAME_TEXT MN_INSERT_BLOCK[] = "Insert conditional block";
508 static GAME_TEXT MN_INSERT_MACRO[] = "Insert a macro definition";
509 static GAME_TEXT MN_INSERT_KEYMAP[] = "Insert a keymap definition";
511 static GAME_TEXT MN_COMMAND_LETTER[] = "Command letter";
512 static GAME_TEXT MN_CL_AUTOPICK[] = "' ' (Auto pick)";
513 static GAME_TEXT MN_CL_DESTROY[] = "'!' (Auto destroy)";
514 static GAME_TEXT MN_CL_LEAVE[] = "'~' (Leave it on the floor)";
515 static GAME_TEXT MN_CL_QUERY[] = "';' (Query to pick up)";
516 static GAME_TEXT MN_CL_NO_DISP[] = "'(' (No display on the large map)";
518 static GAME_TEXT MN_ADJECTIVE_GEN[] = "Adjective (general)";
519 static GAME_TEXT MN_RARE[] = "rare (equipment)";
520 static GAME_TEXT MN_COMMON[] = "common (equipment)";
522 static GAME_TEXT MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
523 static GAME_TEXT MN_BOOSTED[] = "dice boosted (weapons)";
524 static GAME_TEXT MN_MORE_DICE[] = "more than # dice (weapons)";
525 static GAME_TEXT MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
526 static GAME_TEXT MN_WANTED[] = "wanted (corpse)";
527 static GAME_TEXT MN_UNIQUE[] = "unique (corpse)";
528 static GAME_TEXT MN_HUMAN[] = "human (corpse)";
529 static GAME_TEXT MN_UNREADABLE[] = "unreadable (spellbooks)";
530 static GAME_TEXT MN_REALM1[] = "realm1 (spellbooks)";
531 static GAME_TEXT MN_REALM2[] = "realm2 (spellbooks)";
532 static GAME_TEXT MN_FIRST[] = "first (spellbooks)";
533 static GAME_TEXT MN_SECOND[] = "second (spellbooks)";
534 static GAME_TEXT MN_THIRD[] = "third (spellbooks)";
535 static GAME_TEXT MN_FOURTH[] = "fourth (spellbooks)";
537 static GAME_TEXT MN_NOUN[] = "Keywords (noun)";
550 command_menu_type menu_data[] =
552 {MN_HELP, 0, -1, EC_HELP},
553 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
554 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
555 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
557 {MN_EDIT, 0, -1, -1},
558 {MN_CUT, 1, KTRL('x'), EC_CUT},
559 {MN_COPY, 1, KTRL('c'), EC_COPY},
560 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
561 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
562 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
563 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
564 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
565 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
566 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
568 {MN_SEARCH, 0, -1, -1},
569 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
570 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
571 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
572 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
573 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
575 {MN_MOVE, 0, -1, -1},
576 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
577 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
578 {MN_UP, 1, KTRL('p'), EC_UP},
579 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
580 {MN_BOL, 1, KTRL('a'), EC_BOL},
581 {MN_EOL, 1, KTRL('e'), EC_EOL},
582 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
583 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
584 {MN_TOP, 1, KTRL('t'), EC_TOP},
585 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
587 {MN_INSERT, 0, -1, -1},
588 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
589 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
590 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
591 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
592 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
594 {MN_ADJECTIVE_GEN, 0, -1, -1},
595 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
596 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
597 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
598 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
599 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
600 {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
601 {KEY_EGO, 1, -1, EC_OK_EGO},
602 {KEY_GOOD, 1, -1, EC_OK_GOOD},
603 {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
604 {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
605 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
606 {MN_RARE, 1, -1, EC_OK_RARE},
607 {MN_COMMON, 1, -1, EC_OK_COMMON},
609 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
610 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
611 {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
612 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
613 {MN_WANTED, 1, -1, EC_OK_WANTED},
614 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
615 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
616 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
617 {MN_REALM1, 1, -1, EC_OK_REALM1},
618 {MN_REALM2, 1, -1, EC_OK_REALM2},
619 {MN_FIRST, 1, -1, EC_OK_FIRST},
620 {MN_SECOND, 1, -1, EC_OK_SECOND},
621 {MN_THIRD, 1, -1, EC_OK_THIRD},
622 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
624 {MN_NOUN, 0, -1, -1},
625 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
626 {KEY_FAVORITE_WEAPONS, 1, -1, EC_KK_FAVORITE_WEAPONS},
627 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
628 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
629 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
630 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
631 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
632 {KEY_CORPSES, 1, -1, EC_KK_CORPSES},
633 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
634 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
635 {KEY_BOWS, 1, -1, EC_KK_BOWS},
636 {KEY_RINGS, 1, -1, EC_KK_RINGS},
637 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
638 {KEY_SUITS, 1, -1, EC_KK_SUITS},
639 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
640 {KEY_HELMS, 1, -1, EC_KK_HELMS},
641 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
642 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
644 {MN_COMMAND_LETTER, 0, -1, -1},
645 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
646 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
647 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
648 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
649 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
651 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
658 * A function to create new entry
660 static bool autopick_new_entry(autopick_type *entry, concptr str, bool allow_default)
662 if (str[0] && str[1] == ':') switch (str[0])
665 case 'A': case 'P': case 'C':
669 entry->flag[0] = entry->flag[1] = 0L;
673 byte act = DO_AUTOPICK | DO_DISPLAY;
676 if ((act & DO_AUTOPICK) && *str == '!')
679 act |= DO_AUTODESTROY;
684 if ((act & DO_AUTOPICK) && *str == '~')
687 act |= DONT_AUTOPICK;
692 if ((act & DO_AUTOPICK) && *str == ';')
695 act |= DO_QUERY_AUTOPICK;
700 if ((act & DO_DISPLAY) && *str == '(')
710 /* don't mind upper or lower case */
712 char buf[MAX_LINELEN];
714 for (i = 0; *str; i++)
725 /* Auto-inscription? */
733 if (isupper(c)) c = (char)tolower(c);
740 /* Skip empty line unless allow_default */
741 if (!allow_default && *buf == 0) return FALSE;
743 /* Skip comment line */
744 if (*buf == 0 && insc) return FALSE;
746 concptr prev_ptr, ptr;
747 ptr = prev_ptr = buf;
748 concptr old_ptr = NULL;
750 while (old_ptr != ptr)
752 /* Save current location */
755 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
756 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
757 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
758 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
759 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
760 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
761 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
763 /*** Weapons whose dd*ds is more than nn ***/
764 if (MATCH_KEY2(KEY_MORE_THAN))
769 /* Drop leading spaces */
770 while (' ' == *ptr) ptr++;
773 while ('0' <= *ptr && *ptr <= '9')
775 entry->dice = 10 * entry->dice + (*ptr - '0');
782 (void)MATCH_KEY(KEY_DICE);
783 ADD_FLG(FLG_MORE_DICE);
789 /*** Items whose magical bonus is more than n ***/
790 if (MATCH_KEY2(KEY_MORE_BONUS))
795 /* Drop leading spaces */
796 while (' ' == *ptr) ptr++;
799 while ('0' <= *ptr && *ptr <= '9')
801 entry->bonus = 10 * entry->bonus + (*ptr - '0');
809 (void)MATCH_KEY(KEY_MORE_BONUS2);
811 if (' ' == *ptr) ptr++;
813 ADD_FLG(FLG_MORE_BONUS);
819 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
820 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
821 if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
822 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
823 if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
824 if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
825 if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
826 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
827 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
828 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
829 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
830 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
831 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
832 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
833 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
834 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
835 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
838 /* Not yet found any noun */
841 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
843 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
844 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
845 else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
846 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
847 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
848 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
849 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
850 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
851 else if (MATCH_KEY2(KEY_CORPSES)) ADD_FLG_NOUN(FLG_CORPSES);
852 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
853 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
854 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
855 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
856 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
857 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
858 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
859 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
860 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
861 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
862 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
864 /* Last 'keyword' must be at the correct location */
868 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
871 else if (*ptr == '\0')
873 /* There was no noun */
876 /* Add extra word "items" */
877 ADD_FLG_NOUN(FLG_ITEMS);
884 /* A noun type keyword didn't end correctly */
885 entry->flag[prev_flg / 32] &= ~(1L << (prev_flg % 32));
890 /* Save this auto-picker entry line */
891 entry->name = string_make(ptr);
893 entry->insc = string_make(insc);
900 * Get auto-picker entry from o_ptr.
902 static void autopick_entry_from_object(player_type *player_ptr, autopick_type *entry, object_type *o_ptr)
904 /* Assume that object name is to be added */
908 /* エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない */
909 bool bol_mark = FALSE;
911 /* We can always use the ^ mark in English */
912 bool bol_mark = TRUE;
915 GAME_TEXT name_str[MAX_NLEN];
917 /* Initialize name string */
920 entry->insc = string_make(quark_str(o_ptr->inscription));
921 entry->action = DO_AUTOPICK | DO_DISPLAY;
922 entry->flag[0] = entry->flag[1] = 0L;
926 if (!object_is_aware(o_ptr))
928 ADD_FLG(FLG_UNAWARE);
932 /* Not really identified */
933 else if (!object_is_known(o_ptr))
935 if (!(o_ptr->ident & IDENT_SENSE))
937 ADD_FLG(FLG_UNIDENTIFIED);
942 /* Pseudo-identified */
943 switch (o_ptr->feeling)
947 ADD_FLG(FLG_NAMELESS);
953 ADD_FLG(FLG_NAMELESS);
954 ADD_FLG(FLG_WORTHLESS);
960 ADD_FLG(FLG_WORTHLESS);
968 /* XXX No appropriate flag */
973 /* Never reach here */
983 if (object_is_ego(o_ptr))
985 if (object_is_weapon_armour_ammo(o_ptr))
988 * Base name of ego weapons and armors
989 * are almost meaningless.
990 * Register the ego type only.
992 ego_item_type *e_ptr = &e_info[o_ptr->name2];
994 /* エゴ銘には「^」マークが使える */
995 sprintf(name_str, "^%s", e_name + e_ptr->name);
997 /* We ommit the basename and cannot use the ^ mark */
998 strcpy(name_str, e_name + e_ptr->name);
1001 /* Don't use the object description */
1004 /* Restrict to 'common' equipments */
1005 if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
1012 else if (object_is_artifact(o_ptr))
1013 ADD_FLG(FLG_ARTIFACT);
1015 /* Non-ego, non-artifact */
1018 /* Wearable nameless object */
1019 if (object_is_equipment(o_ptr))
1020 ADD_FLG(FLG_NAMELESS);
1027 /* Melee weapon with boosted dice */
1028 if (object_is_melee_weapon(o_ptr))
1030 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1032 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1033 ADD_FLG(FLG_BOOSTED);
1036 /* Wanted monster's corpse */
1037 if (object_is_bounty(o_ptr))
1039 REM_FLG(FLG_WORTHLESS);
1040 ADD_FLG(FLG_WANTED);
1043 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
1044 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
1046 ADD_FLG(FLG_UNIQUE);
1049 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
1054 if (o_ptr->tval >= TV_LIFE_BOOK &&
1055 !check_book_realm(player_ptr, o_ptr->tval, o_ptr->sval))
1057 ADD_FLG(FLG_UNREADABLE);
1058 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
1061 if (REALM1_BOOK == o_ptr->tval &&
1062 player_ptr->pclass != CLASS_SORCERER &&
1063 player_ptr->pclass != CLASS_RED_MAGE)
1065 ADD_FLG(FLG_REALM1);
1069 if (REALM2_BOOK == o_ptr->tval &&
1070 player_ptr->pclass != CLASS_SORCERER &&
1071 player_ptr->pclass != CLASS_RED_MAGE)
1073 ADD_FLG(FLG_REALM2);
1077 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
1079 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
1080 ADD_FLG(FLG_SECOND);
1081 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
1083 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
1084 ADD_FLG(FLG_FOURTH);
1086 if (object_is_ammo(o_ptr))
1087 ADD_FLG(FLG_MISSILES);
1088 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
1089 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
1090 ADD_FLG(FLG_DEVICES);
1091 else if (o_ptr->tval == TV_LITE)
1092 ADD_FLG(FLG_LIGHTS);
1093 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
1094 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
1096 else if (o_ptr->tval == TV_CORPSE)
1097 ADD_FLG(FLG_CORPSES);
1098 else if (o_ptr->tval >= TV_LIFE_BOOK)
1099 ADD_FLG(FLG_SPELLBOOKS);
1100 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
1101 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
1102 ADD_FLG(FLG_WEAPONS);
1103 else if (o_ptr->tval == TV_SHIELD)
1104 ADD_FLG(FLG_SHIELDS);
1105 else if (o_ptr->tval == TV_BOW)
1107 else if (o_ptr->tval == TV_RING)
1109 else if (o_ptr->tval == TV_AMULET)
1110 ADD_FLG(FLG_AMULETS);
1111 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
1112 o_ptr->tval == TV_SOFT_ARMOR)
1114 else if (o_ptr->tval == TV_CLOAK)
1115 ADD_FLG(FLG_CLOAKS);
1116 else if (o_ptr->tval == TV_HELM)
1118 else if (o_ptr->tval == TV_GLOVES)
1119 ADD_FLG(FLG_GLOVES);
1120 else if (o_ptr->tval == TV_BOOTS)
1123 /* Prepare the object description */
1126 str_tolower(name_str);
1127 entry->name = string_make(name_str);
1131 GAME_TEXT o_name[MAX_NLEN];
1132 object_desc(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
1135 * If necessary, add a '^' which indicates the
1136 * beginning of line.
1138 sprintf(name_str, "%s%s", bol_mark ? "^" : "", o_name);
1139 str_tolower(name_str);
1140 entry->name = string_make(name_str);
1145 * A function to delete entry
1147 static void autopick_free_entry(autopick_type *entry)
1149 string_free(entry->name);
1150 string_free(entry->insc);
1157 * Initialize the autopick
1159 static void init_autopick(void)
1161 static const char easy_autopick_inscription[] = "(:=g";
1162 autopick_type entry;
1167 max_max_autopick = MAX_AUTOPICK_DEFAULT;
1168 C_MAKE(autopick_list, max_max_autopick, autopick_type);
1172 /* Clear old entries */
1173 for (i = 0; i < max_autopick; i++)
1174 autopick_free_entry(&autopick_list[i]);
1178 /* There is always one entry "=g" */
1179 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
1180 autopick_list[max_autopick++] = entry;
1185 * Get file name for autopick preference
1187 static concptr pickpref_filename(player_type *player_ptr, int filename_mode)
1189 static const char namebase[] = _("picktype", "pickpref");
1191 switch (filename_mode)
1194 return format("%s.prf", namebase);
1197 return format("%s-%s.prf", namebase, player_ptr->base_name);
1206 * Load an autopick preference file
1208 void autopick_load_pref(player_type *player_ptr, bool disp_mes)
1212 /* Free old entries */
1215 /* Try a filename with player name */
1216 my_strcpy(buf, pickpref_filename(player_ptr, PT_WITH_PNAME), sizeof(buf));
1219 errr err = process_autopick_file(player_ptr, buf);
1221 if (err == 0 && disp_mes)
1223 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
1229 /* Use default name */
1230 my_strcpy(buf, pickpref_filename(player_ptr, PT_DEFAULT), sizeof(buf));
1233 err = process_autopick_file(player_ptr, buf);
1235 if (err == 0 && disp_mes)
1238 msg_format(_("%sを読み込みました。", "Loaded '%s'."), buf);
1242 if (err && disp_mes)
1245 msg_print(_("自動拾い設定ファイルの読み込みに失敗しました。", "Failed to reload autopick preference."));
1251 * Add one line to autopick_list[]
1253 static void add_autopick_list(autopick_type *entry)
1255 /* There is no enough space to add one line */
1256 if (max_autopick >= max_max_autopick)
1258 int old_max_max_autopick = max_max_autopick;
1259 autopick_type *old_autopick_list = autopick_list;
1261 /* Increase size of list */
1262 max_max_autopick += MAX_AUTOPICK_DEFAULT;
1265 C_MAKE(autopick_list, max_max_autopick, autopick_type);
1267 /* Copy from old list to new list */
1268 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
1271 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
1275 autopick_list[max_autopick] = *entry;
1282 * Process line for auto picker/destroyer.
1284 errr process_autopick_file_command(char *buf)
1286 autopick_type an_entry, *entry = &an_entry;
1289 /* Nuke illegal char */
1290 for (i = 0; buf[i]; i++)
1293 if (iskanji(buf[i]))
1299 if (iswspace(buf[i]) && buf[i] != ' ')
1305 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
1307 /* Already has the same entry? */
1308 for (i = 0; i < max_autopick; i++)
1310 if (!strcmp(entry->name, autopick_list[i].name)
1311 && entry->flag[0] == autopick_list[i].flag[0]
1312 && entry->flag[1] == autopick_list[i].flag[1]
1313 && entry->dice == autopick_list[i].dice
1314 && entry->bonus == autopick_list[i].bonus)
1316 autopick_free_entry(entry);
1321 add_autopick_list(entry);
1327 * Reconstruct preference line from entry
1329 concptr autopick_line_from_entry(autopick_type *entry)
1331 char buf[MAX_LINELEN];
1333 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
1334 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
1335 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
1336 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
1341 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
1342 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
1343 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
1344 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
1345 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
1346 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
1347 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
1349 if (IS_FLG(FLG_MORE_DICE))
1351 ADD_KEY(KEY_MORE_THAN);
1352 strcat(ptr, format("%d", entry->dice));
1356 if (IS_FLG(FLG_MORE_BONUS))
1358 ADD_KEY(KEY_MORE_BONUS);
1359 strcat(ptr, format("%d", entry->bonus));
1360 ADD_KEY(KEY_MORE_BONUS2);
1363 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
1364 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
1365 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
1366 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
1367 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
1368 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
1369 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
1370 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
1371 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
1372 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
1373 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
1374 if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
1375 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
1376 if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
1377 if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
1378 if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
1379 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
1381 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
1383 bool sepa_flag = TRUE;
1384 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
1385 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
1386 else if (IS_FLG(FLG_FAVORITE_WEAPONS)) ADD_KEY2(KEY_FAVORITE_WEAPONS);
1387 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
1388 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
1389 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
1390 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
1391 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
1392 else if (IS_FLG(FLG_CORPSES)) ADD_KEY2(KEY_CORPSES);
1393 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
1394 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
1395 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
1396 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
1397 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
1398 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
1399 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
1400 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
1401 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
1402 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
1403 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
1405 /* You don't need sepalator after adjective */
1406 /* 'artifact' is not true adjective */
1407 else if (!IS_FLG(FLG_ARTIFACT))
1410 if (entry->name && entry->name[0])
1412 if (sepa_flag) strcat(buf, ":");
1414 int i = strlen(buf);
1416 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
1419 if (iskanji(entry->name[j]))
1420 buf[i++] = entry->name[j++];
1422 buf[i++] = entry->name[j++];
1427 if (!entry->insc) return string_make(buf);
1433 while (entry->insc[j] && i < MAX_LINELEN - 2)
1436 if (iskanji(entry->insc[j]))
1437 buf[i++] = entry->insc[j++];
1439 buf[i++] = entry->insc[j++];
1443 return string_make(buf);
1448 * Reconstruct preference line from entry and kill entry
1450 static concptr autopick_line_from_entry_kill(autopick_type *entry)
1452 concptr ptr = autopick_line_from_entry(entry);
1453 autopick_free_entry(entry);
1459 * A function for Auto-picker/destroyer
1460 * Examine whether the object matches to the entry
1462 static bool is_autopick_aux(player_type *player_ptr, object_type *o_ptr, autopick_type *entry, concptr o_name)
1464 concptr ptr = entry->name;
1466 /*** Unaware items ***/
1467 if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
1470 /*** Unidentified ***/
1471 if (IS_FLG(FLG_UNIDENTIFIED)
1472 && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
1475 /*** Identified ***/
1476 if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
1479 /*** *Identified* ***/
1480 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
1481 (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
1484 /*** Dice boosted (weapon of slaying) ***/
1485 if (IS_FLG(FLG_BOOSTED))
1487 object_kind *k_ptr = &k_info[o_ptr->k_idx];
1489 /* Require melee weapon */
1490 if (!object_is_melee_weapon(o_ptr))
1493 /* Require boosted dice */
1494 if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
1497 /* In Vault Quest, Dice must be hide.*/
1498 if (!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
1504 /*** Weapons which dd*ds is more than nn ***/
1505 if (IS_FLG(FLG_MORE_DICE))
1507 if (o_ptr->dd * o_ptr->ds < entry->dice)
1511 /*** Weapons whic dd*ds is more than nn ***/
1512 if (IS_FLG(FLG_MORE_BONUS))
1514 if (!object_is_known(o_ptr)) return FALSE;
1518 if (o_ptr->pval < entry->bonus) return FALSE;
1522 if (o_ptr->to_h < entry->bonus &&
1523 o_ptr->to_d < entry->bonus &&
1524 o_ptr->to_a < entry->bonus &&
1525 o_ptr->pval < entry->bonus)
1530 /*** Worthless items ***/
1531 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1534 /*** Artifact object ***/
1535 if (IS_FLG(FLG_ARTIFACT))
1537 if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
1541 /*** Ego object ***/
1542 if (IS_FLG(FLG_EGO))
1544 /* Need to be an ego item */
1545 if (!object_is_ego(o_ptr)) return FALSE;
1547 /* Need to be known to be an ego */
1548 if (!object_is_known(o_ptr) &&
1549 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1554 if (IS_FLG(FLG_GOOD))
1556 if (!object_is_equipment(o_ptr)) return FALSE;
1559 if (object_is_known(o_ptr))
1561 /* Artifacts and Ego objects are not okay */
1562 if (!object_is_nameless(o_ptr))
1565 /* Average are not okay */
1566 if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
1570 /* Pseudo-identified */
1571 else if (o_ptr->ident & IDENT_SENSE)
1573 switch (o_ptr->feeling)
1588 /* Not known to be good */
1594 if (IS_FLG(FLG_NAMELESS))
1596 if (!object_is_equipment(o_ptr)) return FALSE;
1599 if (object_is_known(o_ptr))
1601 /* Artifacts and Ego objects are not okay */
1602 if (!object_is_nameless(o_ptr))
1606 /* Pseudo-identified */
1607 else if (o_ptr->ident & IDENT_SENSE)
1609 switch (o_ptr->feeling)
1619 /* It's not nameless */
1627 /* Not known to be nameless */
1633 if (IS_FLG(FLG_AVERAGE))
1635 if (!object_is_equipment(o_ptr)) return FALSE;
1638 if (object_is_known(o_ptr))
1640 /* Artifacts and Ego objects are not okay */
1641 if (!object_is_nameless(o_ptr))
1644 /* Cursed or broken objects are not okay */
1645 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
1648 /* Good are not okay */
1649 if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
1653 /* Pseudo-identified */
1654 else if (o_ptr->ident & IDENT_SENSE)
1656 switch (o_ptr->feeling)
1663 /* It's not average */
1671 /* Not known to be average */
1676 /*** Rere equipments ***/
1677 if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
1680 /*** Common equipments ***/
1681 if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
1684 /*** Wanted monster's corpse/skeletons ***/
1685 if (IS_FLG(FLG_WANTED) && !object_is_bounty(o_ptr))
1688 /*** Unique monster's corpse/skeletons/statues ***/
1689 if (IS_FLG(FLG_UNIQUE) &&
1690 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1691 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1694 /*** Human corpse/skeletons (for Daemon magic) ***/
1695 if (IS_FLG(FLG_HUMAN) &&
1696 (o_ptr->tval != TV_CORPSE ||
1697 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1700 /*** Unreadable spellbooks ***/
1701 if (IS_FLG(FLG_UNREADABLE) &&
1702 (o_ptr->tval < TV_LIFE_BOOK ||
1703 check_book_realm(player_ptr, o_ptr->tval, o_ptr->sval)))
1706 /*** First realm spellbooks ***/
1707 if (IS_FLG(FLG_REALM1) &&
1708 (REALM1_BOOK != o_ptr->tval ||
1709 player_ptr->pclass == CLASS_SORCERER ||
1710 player_ptr->pclass == CLASS_RED_MAGE))
1713 /*** Second realm spellbooks ***/
1714 if (IS_FLG(FLG_REALM2) &&
1715 (REALM2_BOOK != o_ptr->tval ||
1716 player_ptr->pclass == CLASS_SORCERER ||
1717 player_ptr->pclass == CLASS_RED_MAGE))
1720 /*** First rank spellbooks ***/
1721 if (IS_FLG(FLG_FIRST) &&
1722 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1725 /*** Second rank spellbooks ***/
1726 if (IS_FLG(FLG_SECOND) &&
1727 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1730 /*** Third rank spellbooks ***/
1731 if (IS_FLG(FLG_THIRD) &&
1732 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1735 /*** Fourth rank spellbooks ***/
1736 if (IS_FLG(FLG_FOURTH) &&
1737 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1741 if (IS_FLG(FLG_WEAPONS))
1743 if (!object_is_weapon(o_ptr))
1746 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
1748 if (!object_is_favorite(o_ptr))
1751 else if (IS_FLG(FLG_ARMORS))
1753 if (!object_is_armour(o_ptr))
1756 else if (IS_FLG(FLG_MISSILES))
1758 if (!object_is_ammo(o_ptr)) return FALSE;
1760 else if (IS_FLG(FLG_DEVICES))
1762 switch (o_ptr->tval)
1764 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1766 default: return FALSE;
1769 else if (IS_FLG(FLG_LIGHTS))
1771 if (!(o_ptr->tval == TV_LITE))
1774 else if (IS_FLG(FLG_JUNKS))
1776 switch (o_ptr->tval)
1778 case TV_SKELETON: case TV_BOTTLE:
1779 case TV_JUNK: case TV_STATUE:
1781 default: return FALSE;
1784 else if (IS_FLG(FLG_CORPSES))
1786 if (o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_SKELETON)
1789 else if (IS_FLG(FLG_SPELLBOOKS))
1791 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1794 else if (IS_FLG(FLG_HAFTED))
1796 if (!(o_ptr->tval == TV_HAFTED))
1799 else if (IS_FLG(FLG_SHIELDS))
1801 if (!(o_ptr->tval == TV_SHIELD))
1804 else if (IS_FLG(FLG_BOWS))
1806 if (!(o_ptr->tval == TV_BOW))
1809 else if (IS_FLG(FLG_RINGS))
1811 if (!(o_ptr->tval == TV_RING))
1814 else if (IS_FLG(FLG_AMULETS))
1816 if (!(o_ptr->tval == TV_AMULET))
1819 else if (IS_FLG(FLG_SUITS))
1821 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1822 o_ptr->tval == TV_HARD_ARMOR ||
1823 o_ptr->tval == TV_SOFT_ARMOR))
1826 else if (IS_FLG(FLG_CLOAKS))
1828 if (!(o_ptr->tval == TV_CLOAK))
1831 else if (IS_FLG(FLG_HELMS))
1833 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1836 else if (IS_FLG(FLG_GLOVES))
1838 if (!(o_ptr->tval == TV_GLOVES))
1841 else if (IS_FLG(FLG_BOOTS))
1843 if (!(o_ptr->tval == TV_BOOTS))
1847 /* Keyword don't match */
1851 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1855 if (!my_strstr(o_name, ptr)) return FALSE;
1858 /* TRUE when it need not to be 'collecting' */
1859 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1861 /* Check if there is a same item */
1862 for (int j = 0; j < INVEN_PACK; j++)
1865 * 'Collecting' means the item must be absorbed
1866 * into an inventory slot.
1867 * But an item can not be absorbed into itself!
1869 if ((&player_ptr->inventory_list[j] != o_ptr) &&
1870 object_similar(&player_ptr->inventory_list[j], o_ptr))
1879 * A function for Auto-picker/destroyer
1880 * Examine whether the object matches to the list of keywords or not.
1882 int is_autopick(player_type *player_ptr, object_type *o_ptr)
1884 GAME_TEXT o_name[MAX_NLEN];
1886 if (o_ptr->tval == TV_GOLD) return -1;
1888 /* Prepare object name string first */
1889 object_desc(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
1891 /* Convert the string to lower case */
1892 str_tolower(o_name);
1894 /* Look for a matching entry in the list */
1895 for (int i = 0; i < max_autopick; i++)
1897 autopick_type *entry = &autopick_list[i];
1899 if (is_autopick_aux(player_ptr, o_ptr, entry, o_name)) return i;
1909 static void auto_inscribe_item(player_type *player_ptr, object_type *o_ptr, int idx)
1911 /* Are there auto-inscription? */
1912 if (idx < 0 || !autopick_list[idx].insc) return;
1914 if (!o_ptr->inscription)
1915 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1917 /* Redraw inscription */
1918 player_ptr->window |= (PW_EQUIP | PW_INVEN);
1920 /* {.} and {$} effect player_ptr->warning and TRC_TELEPORT_SELF */
1921 player_ptr->update |= (PU_BONUS);
1926 * Automatically destroy items in this grid.
1928 static bool is_opt_confirm_destroy(player_type *player_ptr, object_type *o_ptr)
1930 if (!destroy_items) return FALSE;
1932 /* Known to be worthless? */
1934 if (object_value(o_ptr) > 0) return FALSE;
1937 if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
1940 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1944 if (object_is_bounty(o_ptr)) return FALSE;
1948 if (o_ptr->tval == TV_CORPSE) return FALSE;
1951 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1955 if (player_ptr->prace == RACE_DEMON)
1957 if (o_ptr->tval == TV_CORPSE &&
1958 o_ptr->sval == SV_CORPSE &&
1959 my_strchr("pht", r_info[o_ptr->pval].d_char))
1963 if (player_ptr->pclass == CLASS_ARCHER)
1965 if (o_ptr->tval == TV_SKELETON ||
1966 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1969 else if (player_ptr->pclass == CLASS_NINJA)
1971 if (o_ptr->tval == TV_LITE &&
1972 o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
1975 else if (player_ptr->pclass == CLASS_BEASTMASTER ||
1976 player_ptr->pclass == CLASS_CAVALRY)
1978 if (o_ptr->tval == TV_WAND &&
1979 o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
1984 if (o_ptr->tval == TV_GOLD) return FALSE;
1990 static void auto_destroy_item(player_type *player_ptr, object_type *o_ptr, int autopick_idx)
1992 bool destroy = FALSE;
1994 /* Easy-Auto-Destroyer (3rd priority) */
1995 if (is_opt_confirm_destroy(player_ptr, o_ptr)) destroy = TRUE;
1997 /* Protected by auto-picker (2nd priotity) */
1998 if (autopick_idx >= 0 &&
1999 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
2002 /* Auto-destroyer works only when !always_pickup */
2005 /* Auto-picker/destroyer (1st priority) */
2006 if (autopick_idx >= 0 &&
2007 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
2011 /* Not to be destroyed */
2012 if (!destroy) return;
2014 /* Now decided to destroy */
2016 disturb(player_ptr, FALSE, FALSE);
2019 if (!can_player_destroy_object(o_ptr))
2021 GAME_TEXT o_name[MAX_NLEN];
2023 /* Describe the object (with {terrible/special}) */
2024 object_desc(player_ptr, o_name, o_ptr, 0);
2026 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
2031 /* Record name of destroyed item */
2032 (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
2035 o_ptr->marked |= OM_AUTODESTROY;
2036 player_ptr->update |= PU_AUTODESTROY;
2041 * Auto-destroy marked item
2043 static void autopick_delayed_alter_aux(player_type *player_ptr, INVENTORY_IDX item)
2046 o_ptr = REF_ITEM(player_ptr, player_ptr->current_floor_ptr, item);
2048 if (o_ptr->k_idx == 0 || !(o_ptr->marked & OM_AUTODESTROY)) return;
2050 GAME_TEXT o_name[MAX_NLEN];
2052 /* Describe the object (with {terrible/special}) */
2053 object_desc(player_ptr, o_name, o_ptr, 0);
2055 /* Eliminate the item (from the pack) */
2058 inven_item_increase(player_ptr, item, -(o_ptr->number));
2059 inven_item_optimize(player_ptr, item);
2062 /* Eliminate the item (from the floor) */
2065 delete_object_idx(player_ptr, 0 - item);
2068 msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name);
2073 * Auto-destroy marked items in inventry and on floor
2075 void autopick_delayed_alter(player_type *owner_ptr)
2080 * Scan inventry in reverse order to prevent
2081 * skipping after inven_item_optimize()
2083 for (item = INVEN_TOTAL - 1; item >= 0; item--)
2084 autopick_delayed_alter_aux(owner_ptr, item);
2086 /* Scan the pile of objects */
2087 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
2088 item = floor_ptr->grid_array[owner_ptr->y][owner_ptr->x].o_idx;
2091 OBJECT_IDX next = floor_ptr->o_list[item].next_o_idx;
2092 autopick_delayed_alter_aux(owner_ptr, -item);
2099 * Auto-inscription and/or destroy
2101 * Auto-destroyer works only on inventory or on floor stack only when
2104 void autopick_alter_item(player_type *player_ptr, INVENTORY_IDX item, bool destroy)
2109 o_ptr = REF_ITEM(player_ptr, player_ptr->current_floor_ptr, item);
2111 /* Get the index in the auto-pick/destroy list */
2112 idx = is_autopick(player_ptr, o_ptr);
2114 /* Do auto-inscription */
2115 auto_inscribe_item(player_ptr, o_ptr, idx);
2117 /* Do auto-destroy if needed */
2118 if (destroy && item <= INVEN_PACK)
2119 auto_destroy_item(player_ptr, o_ptr, idx);
2124 * Automatically pickup/destroy items in this grid.
2126 void autopick_pickup_items(player_type* player_ptr, grid_type *g_ptr)
2128 OBJECT_IDX this_o_idx, next_o_idx = 0;
2130 /* Scan the pile of objects */
2131 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
2134 object_type *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
2135 next_o_idx = o_ptr->next_o_idx;
2137 idx = is_autopick(player_ptr, o_ptr);
2139 /* Item index for floor -1,-2,-3,... */
2140 auto_inscribe_item(player_ptr, o_ptr, idx);
2142 bool is_auto_pickup = idx >= 0;
2143 is_auto_pickup &= autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK);
2144 if (!is_auto_pickup)
2146 auto_destroy_item(player_ptr, o_ptr, idx);
2150 disturb(player_ptr, FALSE, FALSE);
2152 if (!inven_carry_okay(o_ptr))
2154 GAME_TEXT o_name[MAX_NLEN];
2156 object_desc(player_ptr, o_name, o_ptr, 0);
2158 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
2159 /* Hack - remember that the item has given a message here. */
2160 o_ptr->marked |= OM_NOMSG;
2164 if (!(autopick_list[idx].action & DO_QUERY_AUTOPICK))
2166 py_pickup_aux(player_ptr, this_o_idx);
2170 char out_val[MAX_NLEN + 20];
2171 GAME_TEXT o_name[MAX_NLEN];
2173 if (o_ptr->marked & OM_NO_QUERY)
2175 /* Already answered as 'No' */
2179 object_desc(player_ptr, o_name, o_ptr, 0);
2181 sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
2183 if (!get_check(out_val))
2185 /* Hack - remember that the item has given a message here. */
2186 o_ptr->marked |= OM_NOMSG | OM_NO_QUERY;
2190 py_pickup_aux(player_ptr, this_o_idx);
2195 static const char autoregister_header[] = "?:$AUTOREGISTER";
2198 * Clear auto registered lines in the picktype.prf .
2200 static bool clear_auto_register(player_type *player_ptr)
2202 char tmp_file[1024];
2203 char pref_file[1024];
2208 bool autoregister = FALSE;
2211 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(player_ptr, PT_WITH_PNAME));
2212 pref_fff = my_fopen(pref_file, "r");
2216 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(player_ptr, PT_DEFAULT));
2217 pref_fff = my_fopen(pref_file, "r");
2226 /* Open a new (temporary) file */
2227 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
2231 /* Close the preference file */
2233 msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
2240 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
2244 if (buf[0] != '#' && buf[0] != '?') num++;
2248 if (streq(buf, autoregister_header))
2250 autoregister = TRUE;
2254 fprintf(tmp_fff, "%s\n", buf);
2258 my_fclose(pref_fff);
2263 msg_format(_("以前のキャラクター用の自動設定(%d行)が残っています。",
2264 "Auto registered lines (%d lines) for previous character are remaining."), num);
2265 strcpy(buf, _("古い設定行は削除します。よろしいですか?", "These lines will be deleted. Are you sure? "));
2267 /* You can cancel it */
2268 if (!get_check(buf))
2271 autoregister = FALSE;
2273 msg_print(_("エディタのカット&ペースト等を使って必要な行を避難してください。",
2274 "Use cut & paste of auto picker editor (_) to keep old prefs."));
2280 tmp_fff = my_fopen(tmp_file, "r");
2281 pref_fff = my_fopen(pref_file, "w");
2283 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
2284 fprintf(pref_fff, "%s\n", buf);
2286 my_fclose(pref_fff);
2296 * Automatically register an auto-destroy preference line
2298 bool autopick_autoregister(player_type *player_ptr, object_type *o_ptr)
2301 char pref_file[1024];
2303 autopick_type an_entry, *entry = &an_entry;
2305 int match_autopick = is_autopick(player_ptr, o_ptr);
2307 /* Already registered */
2308 if (match_autopick != -1)
2311 byte act = autopick_list[match_autopick].action;
2313 if (act & DO_AUTOPICK) what = _("自動で拾う", "auto-pickup");
2314 else if (act & DO_AUTODESTROY) what = _("自動破壊する", "auto-destroy");
2315 else if (act & DONT_AUTOPICK) what = _("放置する", "leave on floor");
2316 else /* if (act & DO_QUERY_AUTOPICK) */ what = _("確認して拾う", "query auto-pickup");
2318 msg_format(_("そのアイテムは既に%sように設定されています。", "The object is already registered to %s."), what);
2322 /* Known to be an artifact? */
2323 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
2324 ((o_ptr->ident & IDENT_SENSE) &&
2325 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
2327 GAME_TEXT o_name[MAX_NLEN];
2329 /* Describe the object (with {terrible/special}) */
2330 object_desc(player_ptr, o_name, o_ptr, 0);
2332 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
2337 if (!player_ptr->autopick_autoregister)
2339 /* Clear old auto registered lines */
2340 if (!clear_auto_register(player_ptr)) return FALSE;
2343 /* Try a filename with player name */
2344 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(player_ptr, PT_WITH_PNAME));
2345 pref_fff = my_fopen(pref_file, "r");
2349 /* Use default name */
2350 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(player_ptr, PT_DEFAULT));
2351 pref_fff = my_fopen(pref_file, "r");
2354 /* Check the header */
2359 if (my_fgets(pref_fff, buf, sizeof(buf)))
2361 player_ptr->autopick_autoregister = FALSE;
2365 if (streq(buf, autoregister_header))
2367 player_ptr->autopick_autoregister = TRUE;
2377 * File could not be opened for reading. Assume header not
2380 player_ptr->autopick_autoregister = FALSE;
2383 pref_fff = my_fopen(pref_file, "a");
2386 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), pref_file);
2391 if (!player_ptr->autopick_autoregister)
2393 /* Add the header */
2394 fprintf(pref_fff, "%s\n", autoregister_header);
2396 fprintf(pref_fff, "%s\n", _("# *警告!!* 以降の行は自動登録されたものです。",
2397 "# *Warning!* The lines below will be deleated later."));
2398 fprintf(pref_fff, "%s\n", _("# 後で自動的に削除されますので、必要な行は上の方へ移動しておいてください。",
2399 "# Keep it by cut & paste if you need these lines for future characters."));
2400 player_ptr->autopick_autoregister = TRUE;
2403 autopick_entry_from_object(player_ptr, entry, o_ptr);
2404 entry->action = DO_AUTODESTROY;
2406 /* Load the new line as preference */
2407 add_autopick_list(entry);
2409 /* Add a line to the file */
2410 /* Don't kill "entry" */
2411 concptr tmp = autopick_line_from_entry(entry);
2412 fprintf(pref_fff, "%s\n", tmp);
2421 * Describe which kind of object is Auto-picked/destroyed
2423 static void describe_autopick(char *buff, autopick_type *entry)
2425 concptr str = entry->name;
2426 byte act = entry->action;
2427 concptr insc = entry->insc;
2433 concptr before_str[100], body_str;
2438 /*** Collecting items ***/
2439 /*** Which can be absorbed into a slot as a bundle ***/
2440 if (IS_FLG(FLG_COLLECTING))
2441 before_str[before_n++] = "収集中で既に持っているスロットにまとめられる";
2443 /*** Unaware items ***/
2444 if (IS_FLG(FLG_UNAWARE))
2445 before_str[before_n++] = "未鑑定でその効果も判明していない";
2447 /*** Unidentified ***/
2448 if (IS_FLG(FLG_UNIDENTIFIED))
2449 before_str[before_n++] = "未鑑定の";
2451 /*** Identified ***/
2452 if (IS_FLG(FLG_IDENTIFIED))
2453 before_str[before_n++] = "鑑定済みの";
2455 /*** *Identified* ***/
2456 if (IS_FLG(FLG_STAR_IDENTIFIED))
2457 before_str[before_n++] = "完全に鑑定済みの";
2459 /*** Dice boosted (weapon of slaying) ***/
2460 if (IS_FLG(FLG_BOOSTED))
2462 before_str[before_n++] = "ダメージダイスが通常より大きい";
2466 /*** Weapons whose dd*ds is more than nn ***/
2467 if (IS_FLG(FLG_MORE_DICE))
2469 static char more_than_desc_str[] = "___";
2470 before_str[before_n++] = "ダメージダイスの最大値が";
2473 sprintf(more_than_desc_str, "%d", entry->dice);
2474 before_str[before_n++] = more_than_desc_str;
2475 before_str[before_n++] = "以上の";
2478 /*** Items whose magical bonus is more than nn ***/
2479 if (IS_FLG(FLG_MORE_BONUS))
2481 static char more_bonus_desc_str[] = "___";
2482 before_str[before_n++] = "修正値が(+";
2484 sprintf(more_bonus_desc_str, "%d", entry->bonus);
2485 before_str[before_n++] = more_bonus_desc_str;
2486 before_str[before_n++] = ")以上の";
2489 /*** Worthless items ***/
2490 if (IS_FLG(FLG_WORTHLESS))
2491 before_str[before_n++] = "店で無価値と判定される";
2494 if (IS_FLG(FLG_ARTIFACT))
2496 before_str[before_n++] = "アーティファクトの";
2501 if (IS_FLG(FLG_EGO))
2503 before_str[before_n++] = "エゴアイテムの";
2508 if (IS_FLG(FLG_GOOD))
2510 before_str[before_n++] = "上質の";
2515 if (IS_FLG(FLG_NAMELESS))
2517 before_str[before_n++] = "エゴでもアーティファクトでもない";
2522 if (IS_FLG(FLG_AVERAGE))
2524 before_str[before_n++] = "並の";
2528 /*** Rare equipments ***/
2529 if (IS_FLG(FLG_RARE))
2531 before_str[before_n++] = "ドラゴン装備やカオス・ブレード等を含む珍しい";
2535 /*** Common equipments ***/
2536 if (IS_FLG(FLG_COMMON))
2538 before_str[before_n++] = "ありふれた(ドラゴン装備やカオス・ブレード等の珍しい物ではない)";
2542 /*** Wanted monster's corpse/skeletons ***/
2543 if (IS_FLG(FLG_WANTED))
2545 before_str[before_n++] = "ハンター事務所で賞金首とされている";
2549 /*** Human corpse/skeletons (for Daemon magic) ***/
2550 if (IS_FLG(FLG_HUMAN))
2552 before_str[before_n++] = "悪魔魔法で使うための人間やヒューマノイドの";
2556 /*** Unique monster's corpse/skeletons/statues ***/
2557 if (IS_FLG(FLG_UNIQUE))
2559 before_str[before_n++] = "ユニークモンスターの";
2563 /*** Unreadable spellbooks ***/
2564 if (IS_FLG(FLG_UNREADABLE))
2566 before_str[before_n++] = "あなたが読めない領域の";
2570 /*** First realm spellbooks ***/
2571 if (IS_FLG(FLG_REALM1))
2573 before_str[before_n++] = "第一領域の";
2577 /*** Second realm spellbooks ***/
2578 if (IS_FLG(FLG_REALM2))
2580 before_str[before_n++] = "第二領域の";
2584 /*** First rank spellbooks ***/
2585 if (IS_FLG(FLG_FIRST))
2587 before_str[before_n++] = "全4冊の内の1冊目の";
2591 /*** Second rank spellbooks ***/
2592 if (IS_FLG(FLG_SECOND))
2594 before_str[before_n++] = "全4冊の内の2冊目の";
2598 /*** Third rank spellbooks ***/
2599 if (IS_FLG(FLG_THIRD))
2601 before_str[before_n++] = "全4冊の内の3冊目の";
2605 /*** Fourth rank spellbooks ***/
2606 if (IS_FLG(FLG_FOURTH))
2608 before_str[before_n++] = "全4冊の内の4冊目の";
2613 if (IS_FLG(FLG_ITEMS))
2614 ; /* Nothing to do */
2615 else if (IS_FLG(FLG_WEAPONS))
2617 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2619 else if (IS_FLG(FLG_ARMORS))
2621 else if (IS_FLG(FLG_MISSILES))
2622 body_str = "弾や矢やクロスボウの矢";
2623 else if (IS_FLG(FLG_DEVICES))
2624 body_str = "巻物や魔法棒や杖やロッド";
2625 else if (IS_FLG(FLG_LIGHTS))
2626 body_str = "光源用のアイテム";
2627 else if (IS_FLG(FLG_JUNKS))
2628 body_str = "折れた棒等のガラクタ";
2629 else if (IS_FLG(FLG_CORPSES))
2631 else if (IS_FLG(FLG_SPELLBOOKS))
2633 else if (IS_FLG(FLG_HAFTED))
2635 else if (IS_FLG(FLG_SHIELDS))
2637 else if (IS_FLG(FLG_BOWS))
2638 body_str = "スリングや弓やクロスボウ";
2639 else if (IS_FLG(FLG_RINGS))
2641 else if (IS_FLG(FLG_AMULETS))
2642 body_str = "アミュレット";
2643 else if (IS_FLG(FLG_SUITS))
2645 else if (IS_FLG(FLG_CLOAKS))
2647 else if (IS_FLG(FLG_HELMS))
2648 body_str = "ヘルメットや冠";
2649 else if (IS_FLG(FLG_GLOVES))
2651 else if (IS_FLG(FLG_BOOTS))
2656 strcat(buff, "全ての");
2657 else for (i = 0; i < before_n && before_str[i]; i++)
2658 strcat(buff, before_str[i]);
2660 strcat(buff, body_str);
2670 strcat(buff, "で、名前が「");
2671 strncat(buff, str, 80);
2673 strcat(buff, "」で始まるもの");
2675 strcat(buff, "」を含むもの");
2680 strncat(buff, format("に「%s」", insc), 80);
2682 if (my_strstr(insc, "%%all"))
2683 strcat(buff, "(%%allは全能力を表す英字の記号で置換)");
2684 else if (my_strstr(insc, "%all"))
2685 strcat(buff, "(%allは全能力を表す記号で置換)");
2686 else if (my_strstr(insc, "%%"))
2687 strcat(buff, "(%%は追加能力を表す英字の記号で置換)");
2688 else if (my_strstr(insc, "%"))
2689 strcat(buff, "(%は追加能力を表す記号で置換)");
2691 strcat(buff, "と刻んで");
2696 if (act & DONT_AUTOPICK)
2697 strcat(buff, "放置する。");
2698 else if (act & DO_AUTODESTROY)
2699 strcat(buff, "破壊する。");
2700 else if (act & DO_QUERY_AUTOPICK)
2701 strcat(buff, "確認の後に拾う。");
2703 strcat(buff, "拾う。");
2705 if (act & DO_DISPLAY)
2707 if (act & DONT_AUTOPICK)
2708 strcat(buff, "全体マップ('M')で'N'を押したときに表示する。");
2709 else if (act & DO_AUTODESTROY)
2710 strcat(buff, "全体マップ('M')で'K'を押したときに表示する。");
2712 strcat(buff, "全体マップ('M')で'M'を押したときに表示する。");
2715 strcat(buff, "全体マップには表示しない。");
2719 concptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2720 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2724 /*** Collecting items ***/
2725 /*** Which can be absorbed into a slot as a bundle ***/
2726 if (IS_FLG(FLG_COLLECTING))
2727 which_str[which_n++] = "can be absorbed into an existing inventory list slot";
2729 /*** Unaware items ***/
2730 if (IS_FLG(FLG_UNAWARE))
2732 before_str[before_n++] = "unidentified";
2733 whose_str[whose_n++] = "basic abilities are not known";
2736 /*** Unidentified ***/
2737 if (IS_FLG(FLG_UNIDENTIFIED))
2738 before_str[before_n++] = "unidentified";
2740 /*** Identified ***/
2741 if (IS_FLG(FLG_IDENTIFIED))
2742 before_str[before_n++] = "identified";
2744 /*** *Identified* ***/
2745 if (IS_FLG(FLG_STAR_IDENTIFIED))
2746 before_str[before_n++] = "fully identified";
2748 /*** Rare equipments ***/
2749 if (IS_FLG(FLG_RARE))
2751 before_str[before_n++] = "very rare";
2752 body_str = "equipments";
2753 after_str[after_n++] = "such as Dragon armor, Blades of Chaos, etc.";
2756 /*** Common equipments ***/
2757 if (IS_FLG(FLG_COMMON))
2759 before_str[before_n++] = "relatively common";
2760 body_str = "equipments";
2761 after_str[after_n++] = "compared to very rare Dragon armor, Blades of Chaos, etc.";
2764 /*** Worthless items ***/
2765 if (IS_FLG(FLG_WORTHLESS))
2767 before_str[before_n++] = "worthless";
2768 which_str[which_n++] = "can not be sold at stores";
2772 if (IS_FLG(FLG_ARTIFACT))
2774 before_str[before_n++] = "artifact";
2778 if (IS_FLG(FLG_EGO))
2780 before_str[before_n++] = "ego";
2784 if (IS_FLG(FLG_GOOD))
2786 body_str = "equipment";
2787 which_str[which_n++] = "have good quality";
2791 if (IS_FLG(FLG_NAMELESS))
2793 body_str = "equipment";
2794 which_str[which_n++] = "is neither ego-item nor artifact";
2798 if (IS_FLG(FLG_AVERAGE))
2800 body_str = "equipment";
2801 which_str[which_n++] = "have average quality";
2804 /*** Dice boosted (weapon of slaying) ***/
2805 if (IS_FLG(FLG_BOOSTED))
2807 body_str = "weapons";
2808 whose_str[whose_n++] = "damage dice is bigger than normal";
2811 /*** Weapons whose dd*ds is more than nn ***/
2812 if (IS_FLG(FLG_MORE_DICE))
2814 static char more_than_desc_str[] =
2815 "maximum damage from dice is bigger than __";
2816 body_str = "weapons";
2818 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2820 whose_str[whose_n++] = more_than_desc_str;
2823 /*** Items whose magical bonus is more than nn ***/
2824 if (IS_FLG(FLG_MORE_BONUS))
2826 static char more_bonus_desc_str[] =
2827 "magical bonus is bigger than (+__)";
2829 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2830 "%d)", entry->bonus);
2831 whose_str[whose_n++] = more_bonus_desc_str;
2834 /*** Wanted monster's corpse/skeletons ***/
2835 if (IS_FLG(FLG_WANTED))
2837 body_str = "corpse or skeletons";
2838 which_str[which_n++] = "is wanted at the Hunter's Office";
2841 /*** Human corpse/skeletons (for Daemon magic) ***/
2842 if (IS_FLG(FLG_HUMAN))
2844 before_str[before_n++] = "humanoid";
2845 body_str = "corpse or skeletons";
2846 which_str[which_n++] = "can be used for Daemon magic";
2849 /*** Unique monster's corpse/skeletons/statues ***/
2850 if (IS_FLG(FLG_UNIQUE))
2852 before_str[before_n++] = "unique monster's";
2853 body_str = "corpse or skeletons";
2856 /*** Unreadable spellbooks ***/
2857 if (IS_FLG(FLG_UNREADABLE))
2859 body_str = "spellbooks";
2860 after_str[after_n++] = "of different realms from yours";
2863 /*** First realm spellbooks ***/
2864 if (IS_FLG(FLG_REALM1))
2866 body_str = "spellbooks";
2867 after_str[after_n++] = "of your first realm";
2870 /*** Second realm spellbooks ***/
2871 if (IS_FLG(FLG_REALM2))
2873 body_str = "spellbooks";
2874 after_str[after_n++] = "of your second realm";
2877 /*** First rank spellbooks ***/
2878 if (IS_FLG(FLG_FIRST))
2880 before_str[before_n++] = "first one of four";
2881 body_str = "spellbooks";
2884 /*** Second rank spellbooks ***/
2885 if (IS_FLG(FLG_SECOND))
2887 before_str[before_n++] = "second one of four";
2888 body_str = "spellbooks";
2891 /*** Third rank spellbooks ***/
2892 if (IS_FLG(FLG_THIRD))
2894 before_str[before_n++] = "third one of four";
2895 body_str = "spellbooks";
2898 /*** Fourth rank spellbooks ***/
2899 if (IS_FLG(FLG_FOURTH))
2901 before_str[before_n++] = "fourth one of four";
2902 body_str = "spellbooks";
2906 if (IS_FLG(FLG_ITEMS))
2907 ; /* Nothing to do */
2908 else if (IS_FLG(FLG_WEAPONS))
2909 body_str = "weapons";
2910 else if (IS_FLG(FLG_FAVORITE_WEAPONS))
2911 body_str = "favorite weapons";
2912 else if (IS_FLG(FLG_ARMORS))
2913 body_str = "armors";
2914 else if (IS_FLG(FLG_MISSILES))
2915 body_str = "shots, arrows or crossbow bolts";
2916 else if (IS_FLG(FLG_DEVICES))
2917 body_str = "scrolls, wands, staves or rods";
2918 else if (IS_FLG(FLG_LIGHTS))
2919 body_str = "light sources";
2920 else if (IS_FLG(FLG_JUNKS))
2921 body_str = "junk such as broken sticks";
2922 else if (IS_FLG(FLG_CORPSES))
2923 body_str = "corpses or skeletons";
2924 else if (IS_FLG(FLG_SPELLBOOKS))
2925 body_str = "spellbooks";
2926 else if (IS_FLG(FLG_HAFTED))
2927 body_str = "hafted weapons";
2928 else if (IS_FLG(FLG_SHIELDS))
2929 body_str = "shields";
2930 else if (IS_FLG(FLG_BOWS))
2931 body_str = "slings, bows or crossbows";
2932 else if (IS_FLG(FLG_RINGS))
2934 else if (IS_FLG(FLG_AMULETS))
2935 body_str = "amulets";
2936 else if (IS_FLG(FLG_SUITS))
2937 body_str = "body armors";
2938 else if (IS_FLG(FLG_CLOAKS))
2939 body_str = "cloaks";
2940 else if (IS_FLG(FLG_HELMS))
2941 body_str = "helms or crowns";
2942 else if (IS_FLG(FLG_GLOVES))
2943 body_str = "gloves";
2944 else if (IS_FLG(FLG_BOOTS))
2947 /* Prepare a string for item name */
2954 whose_str[whose_n++] = "name begins with \"";
2957 which_str[which_n++] = "have \"";
2961 /* Describe action flag */
2962 if (act & DONT_AUTOPICK)
2963 strcpy(buff, "Leave on floor ");
2964 else if (act & DO_AUTODESTROY)
2965 strcpy(buff, "Destroy ");
2966 else if (act & DO_QUERY_AUTOPICK)
2967 strcpy(buff, "Ask to pick up ");
2969 strcpy(buff, "Pickup ");
2971 /* Auto-insctiption */
2974 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2976 if (my_strstr(insc, "%all"))
2977 strcat(buff, ", replacing %all with code string representing all abilities,");
2978 else if (my_strstr(insc, "%"))
2979 strcat(buff, ", replacing % with code string representing extra random abilities,");
2981 strcat(buff, " on ");
2986 strcat(buff, "all ");
2987 else for (i = 0; i < before_n && before_str[i]; i++)
2989 strcat(buff, before_str[i]);
2994 strcat(buff, body_str);
2997 for (i = 0; i < after_n && after_str[i]; i++)
3000 strcat(buff, after_str[i]);
3004 for (i = 0; i < whose_n && whose_str[i]; i++)
3007 strcat(buff, " whose ");
3009 strcat(buff, ", and ");
3011 strcat(buff, whose_str[i]);
3014 /* Item name ; whose name is beginning with "str" */
3021 /* whose ..., and which .... */
3022 if (whose_n && which_n)
3023 strcat(buff, ", and ");
3026 for (i = 0; i < which_n && which_str[i]; i++)
3029 strcat(buff, " which ");
3031 strcat(buff, ", and ");
3033 strcat(buff, which_str[i]);
3036 /* Item name ; which have "str" as part of its name */
3039 strncat(buff, str, 80);
3040 strcat(buff, "\" as part of its name");
3044 /* Describe whether it will be displayed on the full map or not */
3045 if (act & DO_DISPLAY)
3047 if (act & DONT_AUTOPICK)
3048 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
3049 else if (act & DO_AUTODESTROY)
3050 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
3052 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
3055 strcat(buff, " Not displayed in the full map.");
3062 * Read whole lines of a file to memory
3064 static concptr *read_text_lines(concptr filename)
3066 concptr *lines_list = NULL;
3072 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
3073 fff = my_fopen(buf, "r");
3074 if (!fff) return NULL;
3076 /* Allocate list of pointers */
3077 C_MAKE(lines_list, MAX_LINES, concptr);
3080 while (my_fgets(fff, buf, sizeof(buf)) == 0)
3082 lines_list[lines++] = string_make(buf);
3083 if (lines >= MAX_LINES - 1) break;
3087 lines_list[0] = string_make("");
3095 * Copy the default autopick file to the user directory
3097 static void prepare_default_pickpref(player_type *player_ptr)
3099 const concptr messages[] = {
3100 _("あなたは「自動拾いエディタ」を初めて起動しました。", "You have activated the Auto-Picker Editor for the first time."),
3101 _("自動拾いのユーザー設定ファイルがまだ書かれていないので、", "Since user pref file for autopick is not yet created,"),
3102 _("基本的な自動拾い設定ファイルをlib/pref/picktype.prfからコピーします。", "the default setting is loaded from lib/pref/pickpref.prf ."),
3106 concptr filename = pickpref_filename(player_ptr, PT_DEFAULT);
3108 /* Display messages */
3109 for (int i = 0; messages[i]; i++)
3111 msg_print(messages[i]);
3118 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
3120 user_fp = my_fopen(buf, "w");
3123 if (!user_fp) return;
3125 /* Write header messages for a notification */
3126 fprintf(user_fp, "#***\n");
3127 for (int i = 0; messages[i]; i++)
3129 fprintf(user_fp, "#*** %s\n", messages[i]);
3132 fprintf(user_fp, "#***\n\n\n");
3134 /* Open the default file */
3135 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
3137 pref_fp = my_fopen(buf, "r");
3146 /* Copy the contents of default file */
3147 while (!my_fgets(pref_fp, buf, sizeof(buf)))
3149 fprintf(user_fp, "%s\n", buf);
3157 * Read an autopick prefence file to memory
3158 * Prepare default if no user file is found
3160 static concptr *read_pickpref_text_lines(player_type *player_ptr, int *filename_mode_p)
3162 /* Try a filename with player name */
3163 *filename_mode_p = PT_WITH_PNAME;
3165 strcpy(buf, pickpref_filename(player_ptr, *filename_mode_p));
3166 concptr *lines_list;
3167 lines_list = read_text_lines(buf);
3171 *filename_mode_p = PT_DEFAULT;
3172 strcpy(buf, pickpref_filename(player_ptr, *filename_mode_p));
3173 lines_list = read_text_lines(buf);
3178 prepare_default_pickpref(player_ptr);
3179 lines_list = read_text_lines(buf);
3184 C_MAKE(lines_list, MAX_LINES, concptr);
3185 lines_list[0] = string_make("");
3193 * Write whole lines of memory to a file.
3195 static bool write_text_lines(concptr filename, concptr *lines_list)
3198 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
3200 fff = my_fopen(buf, "w");
3201 if (!fff) return FALSE;
3203 for (int lines = 0; lines_list[lines]; lines++)
3205 my_fputs(fff, lines_list[lines], 1024);
3214 * Free memory of lines_list.
3216 static void free_text_lines(concptr *lines_list)
3218 for (int lines = 0; lines_list[lines]; lines++)
3220 string_free(lines_list[lines]);
3223 /* free list of pointers */
3224 C_KILL(lines_list, MAX_LINES, concptr);
3229 * Delete or insert string
3231 static void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
3237 /* Some lines are selected */
3240 by1 = MIN(tb->my, tb->cy);
3241 by2 = MAX(tb->my, tb->cy);
3244 /* No mark -- Select current line */
3245 else /* if (!tb->mark) */
3251 /* Set/Reset flag of each line */
3252 for (int y = by1; y <= by2; y++)
3254 autopick_type an_entry, *entry = &an_entry;
3256 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
3258 string_free(tb->lines_list[y]);
3262 /* Add? or Remove? */
3263 if (!IS_FLG(flg)) add = TRUE;
3266 /* No more change */
3270 /* You can use only one noun flag */
3271 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3274 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3278 /* You can use only one identify state flag */
3279 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
3282 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
3286 /* You can use only one flag in artifact/ego/nameless */
3287 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
3290 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
3294 /* You can use only one flag in rare/common */
3295 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
3298 for (i = FLG_RARE; i <= FLG_COMMON; i++)
3302 if (add) ADD_FLG(flg);
3305 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3308 tb->dirty_flags |= DIRTY_ALL;
3310 /* Text is changed */
3317 * Change command letter
3319 static void toggle_command_letter(text_body_type *tb, byte flg)
3321 autopick_type an_entry, *entry = &an_entry;
3326 /* Some lines are selected */
3329 by1 = MIN(tb->my, tb->cy);
3330 by2 = MAX(tb->my, tb->cy);
3333 /* No mark -- Select current line */
3334 else /* if (!tb->mark) */
3340 /* Set/Reset flag of each line */
3341 for (y = by1; y <= by2; y++)
3345 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3347 string_free(tb->lines_list[y]);
3351 /* Add? or Remove? */
3352 if (!(entry->action & flg)) add = TRUE;
3355 /* No more change */
3359 /* Count number of letter (by negative number) */
3360 if (entry->action & DONT_AUTOPICK) wid--;
3361 else if (entry->action & DO_AUTODESTROY) wid--;
3362 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
3363 if (!(entry->action & DO_DISPLAY)) wid--;
3365 /* Set/Reset the flag */
3366 if (flg != DO_DISPLAY)
3368 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
3369 if (add) entry->action |= flg;
3370 else entry->action |= DO_AUTOPICK;
3374 entry->action &= ~(DO_DISPLAY);
3375 if (add) entry->action |= flg;
3378 /* Correct cursor location */
3381 if (entry->action & DONT_AUTOPICK) wid++;
3382 else if (entry->action & DO_AUTODESTROY) wid++;
3383 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
3384 if (!(entry->action & DO_DISPLAY)) wid++;
3386 if (wid > 0) tb->cx++;
3387 if (wid < 0 && tb->cx > 0) tb->cx--;
3390 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3393 tb->dirty_flags |= DIRTY_ALL;
3395 /* Text is changed */
3401 * Delete or insert string
3403 static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
3407 /* Some lines are selected */
3410 by1 = MIN(tb->my, tb->cy);
3411 by2 = MAX(tb->my, tb->cy);
3414 /* No mark -- Select current line */
3415 else /* if (!tb->mark) */
3420 /* Set/Reset flag of each line */
3421 for (int y = by1; y <= by2; y++)
3423 autopick_type an_entry, *entry = &an_entry;
3425 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
3429 autopick_free_entry(entry);
3433 string_free(tb->lines_list[y]);
3435 /* Remove all noun flag */
3436 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
3439 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
3445 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
3448 tb->dirty_flags |= DIRTY_ALL;
3450 /* Text is changed */
3457 * Check if this line is expression or not.
3458 * And update it if it is.
3460 static void check_expression_line(text_body_type *tb, int y)
3462 concptr s = tb->lines_list[y];
3464 if ((s[0] == '?' && s[1] == ':') ||
3465 (tb->states[y] & LSTAT_BYPASS))
3467 /* Expressions need re-evaluation */
3468 tb->dirty_flags |= DIRTY_EXPRESSION;
3474 * Add an empty line at the last of the file
3476 static bool add_empty_line(text_body_type *tb)
3480 for (k = 0; tb->lines_list[k]; k++)
3481 /* count number of lines */;
3483 /* Too many lines! */
3484 if (k >= MAX_LINES - 2) return FALSE;
3486 /* The last line is already empty */
3487 if (!tb->lines_list[k - 1][0]) return FALSE;
3489 /* Create new empty line */
3490 tb->lines_list[k] = string_make("");
3492 /* Expressions need re-evaluation */
3493 tb->dirty_flags |= DIRTY_EXPRESSION;
3495 /* Text is changed */
3498 /* A line is added */
3504 * Insert return code and split the line
3506 static bool insert_return_code(text_body_type *tb)
3508 char buf[MAX_LINELEN];
3511 for (k = 0; tb->lines_list[k]; k++)
3512 /* count number of lines */;
3514 if (k >= MAX_LINES - 2) return FALSE;
3517 /* Move down lines */
3518 for (; tb->cy < k; k--)
3520 tb->lines_list[k + 1] = tb->lines_list[k];
3521 tb->states[k + 1] = tb->states[k];
3524 /* Split current line */
3525 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3528 if (iskanji(tb->lines_list[tb->cy][i]))
3529 buf[j++] = tb->lines_list[tb->cy][i++];
3531 buf[j++] = tb->lines_list[tb->cy][i];
3535 tb->lines_list[tb->cy + 1] = string_make(&tb->lines_list[tb->cy][i]);
3536 string_free(tb->lines_list[tb->cy]);
3537 tb->lines_list[tb->cy] = string_make(buf);
3539 /* Expressions need re-evaluation */
3540 tb->dirty_flags |= DIRTY_EXPRESSION;
3542 /* Text is changed */
3549 * Choose an item and get auto-picker entry from it.
3551 static bool entry_from_choosed_object(player_type *player_ptr, autopick_type *entry)
3553 concptr q = _("どのアイテムを登録しますか? ", "Enter which item? ");
3554 concptr s = _("アイテムを持っていない。", "You have nothing to enter.");
3556 o_ptr = choose_object(player_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
3557 if (!o_ptr) return FALSE;
3559 autopick_entry_from_object(player_ptr, entry, o_ptr);
3565 * Choose an item for search
3567 static bool get_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
3569 concptr q = _("どのアイテムを検索しますか? ", "Enter which item? ");
3570 concptr s = _("アイテムを持っていない。", "You have nothing to enter.");
3572 o_ptr = choose_object(player_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
3573 if (!o_ptr) return FALSE;
3577 string_free(*search_strp);
3578 char buf[MAX_NLEN + 20];
3579 object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3580 *search_strp = string_make(format("<%s>", buf));
3586 * Prepare for search by destroyed object
3588 static bool get_destroyed_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
3590 if (!autopick_last_destroyed_object.k_idx) return FALSE;
3592 *o_handle = &autopick_last_destroyed_object;
3594 string_free(*search_strp);
3595 char buf[MAX_NLEN + 20];
3596 object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3597 *search_strp = string_make(format("<%s>", buf));
3603 * Choose an item or string for search
3605 static byte get_string_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
3609 * TERM_YELLOW : Overwrite mode
3610 * TERM_WHITE : Insert mode
3612 byte color = TERM_YELLOW;
3613 char buf[MAX_NLEN + 20];
3616 char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
3617 int col = sizeof(prompt) - 1;
3619 /* Prepare string buffer for edit */
3620 if (*search_strp) strcpy(buf, *search_strp);
3623 /* Object searching mode */
3624 if (*o_handle) color = TERM_L_GREEN;
3626 /* Display prompt */
3636 /* Display the string */
3637 Term_erase(col, 0, 255);
3638 Term_putstr(col, 0, -1, color, buf);
3641 Term_gotoxy(col + pos, 0);
3643 /* Get a special key code */
3644 skey = inkey_special(TRUE);
3646 /* Analyze the key */
3654 /* Now on insert mode */
3657 /* No move at beginning of line */
3658 if (0 == pos) break;
3662 int next_pos = i + 1;
3665 if (iskanji(buf[i])) next_pos++;
3668 /* Is there the cursor at next position? */
3669 if (next_pos >= pos) break;
3675 /* Get previous position */
3683 /* Now on insert mode */
3686 /* No move at end of line */
3687 if ('\0' == buf[pos]) break;
3691 if (iskanji(buf[pos])) pos += 2;
3709 if (*o_handle) return (back ? -1 : 1);
3710 string_free(*search_strp);
3711 *search_strp = string_make(buf);
3713 return (back ? -1 : 1);
3716 return get_object_for_search(player_ptr, o_handle, search_strp);
3719 /* Prepare string for destroyed object if there is one. */
3720 if (get_destroyed_object_for_search(player_ptr, o_handle, search_strp))
3730 /* Now on insert mode */
3733 /* No move at beginning of line */
3734 if (0 == pos) break;
3738 int next_pos = i + 1;
3741 if (iskanji(buf[i])) next_pos++;
3744 /* Is there the cursor at next position? */
3745 if (next_pos >= pos) break;
3751 /* Get previous position */
3754 /* Fall through to 'Delete key' */
3763 /* Now on insert mode */
3766 /* No move at end of line */
3767 if ('\0' == buf[pos]) break;
3769 /* Position of next character */
3773 /* Next character is one more byte away */
3774 if (iskanji(buf[pos])) src++;
3779 /* Move characters at src to dst */
3780 while ('\0' != (buf[dst++] = buf[src++]))
3788 /* Insert a character */
3793 /* Ignore special keys */
3794 if (skey & SKEY_MASK) break;
3796 /* Get a character code */
3799 /* Was non insert mode? */
3800 if (color != TERM_WHITE)
3802 /* Was object searching mode */
3803 if (color == TERM_L_GREEN)
3805 /* Cancel the mode */
3808 /* Remove indicating string */
3809 string_free(*search_strp);
3810 *search_strp = NULL;
3813 /* Overwrite default string */
3816 /* Go to insert mode */
3820 /* Save right part of string */
3821 strcpy(tmp, buf + pos);
3827 /* Bypass macro processing */
3845 if (pos < len && (isprint(c) || iskana(c)))
3847 if (pos < len && isprint(c))
3861 /* Write back the left part of string */
3862 my_strcat(buf, tmp, len + 1);
3869 /* Object searching mode was cancelled? */
3870 if (*o_handle == NULL || color == TERM_L_GREEN) continue;
3874 string_free(*search_strp);
3875 *search_strp = NULL;
3880 * Search next line matches for o_ptr
3882 static void search_for_object(player_type *player_ptr, text_body_type *tb, object_type *o_ptr, bool forward)
3884 autopick_type an_entry, *entry = &an_entry;
3885 GAME_TEXT o_name[MAX_NLEN];
3886 int bypassed_cy = -1;
3888 /* Start searching from current cursor position */
3891 /* Prepare object name string first */
3892 object_desc(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
3894 /* Convert the string to lower case */
3895 str_tolower(o_name);
3904 if (!tb->lines_list[++i]) break;
3911 /* Is this line is a correct entry? */
3912 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3914 /* Does this line match to the object? */
3915 match = is_autopick_aux(player_ptr, o_ptr, entry, o_name);
3916 autopick_free_entry(entry);
3917 if (!match) continue;
3919 /* Found a line but it's inactive */
3920 if (tb->states[i] & LSTAT_BYPASS)
3922 /* If it is first found, remember it */
3923 if (bypassed_cy == -1) bypassed_cy = i;
3927 /* Move to this line */
3931 if (bypassed_cy != -1)
3933 /* Mark as some lines are skipped */
3934 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3940 if (bypassed_cy == -1)
3942 tb->dirty_flags |= DIRTY_NOT_FOUND;
3947 tb->cy = bypassed_cy;
3948 tb->dirty_flags |= DIRTY_INACTIVE;
3953 * Search next line matches to the string
3955 static void search_for_string(text_body_type *tb, concptr search_str, bool forward)
3957 int bypassed_cy = -1;
3958 int bypassed_cx = 0;
3960 /* Start searching from current cursor position */
3970 if (!tb->lines_list[++i]) break;
3977 /* Look for the string pattern */
3978 pos = my_strstr(tb->lines_list[i], search_str);
3983 /* Found a line but it's inactive */
3984 if ((tb->states[i] & LSTAT_BYPASS) &&
3985 !(tb->states[i] & LSTAT_EXPRESSION))
3987 /* If it is first found, remember it */
3988 if (bypassed_cy == -1)
3991 bypassed_cx = (int)(pos - tb->lines_list[i]);
3997 tb->cx = (int)(pos - tb->lines_list[i]);
4000 if (bypassed_cy != -1)
4002 /* Mark as some lines are skipped */
4003 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
4009 if (bypassed_cy == -1)
4011 tb->dirty_flags |= DIRTY_NOT_FOUND;
4015 tb->cx = bypassed_cx;
4016 tb->cy = bypassed_cy;
4017 tb->dirty_flags |= DIRTY_INACTIVE;
4022 * Find a command by 'key'.
4024 static int get_com_id(char key)
4026 for (int i = 0; menu_data[i].name; i++)
4028 if (menu_data[i].key == key)
4030 return menu_data[i].com_id;
4039 * Display the menu, and get a command
4041 static int do_command_menu(int level, int start)
4045 int col0 = 5 + level * 7;
4046 int row0 = 1 + level * 3;
4048 int menu_id_list[26];
4050 char linestr[MAX_LINELEN];
4052 /* Get max length */
4054 for (int i = start; menu_data[i].level >= level; i++)
4058 /* Ignore lower level sub menus */
4059 if (menu_data[i].level > level) continue;
4061 len = strlen(menu_data[i].name);
4062 if (len > max_len) max_len = len;
4064 menu_id_list[menu_key] = i;
4068 while (menu_key < 26)
4070 menu_id_list[menu_key] = -1;
4074 /* Extra space for displaying menu key and command key */
4075 max_menu_wid = max_len + 3 + 3;
4077 /* Prepare box line */
4079 strcat(linestr, "+");
4080 for (int i = 0; i < max_menu_wid + 2; i++)
4082 strcat(linestr, "-");
4085 strcat(linestr, "+");
4095 int row1 = row0 + 1;
4098 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
4100 /* Draw menu items */
4102 for (int i = start; menu_data[i].level >= level; i++)
4104 char com_key_str[3];
4107 /* Ignore lower level sub menus */
4108 if (menu_data[i].level > level) continue;
4110 if (menu_data[i].com_id == -1)
4112 strcpy(com_key_str, _("▼", ">"));
4114 else if (menu_data[i].key != -1)
4116 com_key_str[0] = '^';
4117 com_key_str[1] = menu_data[i].key + '@';
4118 com_key_str[2] = '\0';
4122 com_key_str[0] = '\0';
4125 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4127 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4132 /* Draw bottom line */
4133 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4135 /* The menu was shown */
4139 prt(format(_("(a-%c) コマンド:", "(a-%c) Command:"), menu_key + 'a' - 1), 0, 0);
4142 if (key == ESCAPE) return 0;
4144 bool is_alphabet = key >= 'a' && key <= 'z';
4147 com_id = get_com_id(key);
4156 menu_id = menu_id_list[key - 'a'];
4158 if (menu_id < 0) continue;
4160 com_id = menu_data[menu_id].com_id;
4164 com_id = do_command_menu(level + 1, menu_id + 1);
4166 if (com_id) return com_id;
4177 static chain_str_type *new_chain_str(concptr str)
4179 chain_str_type *chain;
4180 size_t len = strlen(str);
4181 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4182 strcpy(chain->s, str);
4188 static void kill_yank_chain(text_body_type *tb)
4190 chain_str_type *chain = tb->yank;
4192 tb->yank_eol = TRUE;
4196 chain_str_type *next = chain->next;
4197 size_t len = strlen(chain->s);
4199 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4206 static void add_str_to_yank(text_body_type *tb, concptr str)
4208 tb->yank_eol = FALSE;
4209 if (NULL == tb->yank)
4211 tb->yank = new_chain_str(str);
4215 chain_str_type *chain;
4222 chain->next = new_chain_str(str);
4227 chain = chain->next;
4233 * Do work for the copy editor-command
4235 static void copy_text_to_yank(text_body_type *tb)
4237 int len = strlen(tb->lines_list[tb->cy]);
4239 /* Correct cursor location */
4240 if (tb->cx > len) tb->cx = len;
4242 /* Use single line? */
4245 /* Select a single line */
4251 kill_yank_chain(tb);
4253 if (tb->my != tb->cy)
4255 int by1 = MIN(tb->my, tb->cy);
4256 int by2 = MAX(tb->my, tb->cy);
4258 for (int y = by1; y <= by2; y++)
4260 add_str_to_yank(tb, tb->lines_list[y]);
4263 add_str_to_yank(tb, "");
4265 tb->dirty_flags |= DIRTY_ALL;
4269 char buf[MAX_LINELEN];
4270 int bx1 = MIN(tb->mx, tb->cx);
4271 int bx2 = MAX(tb->mx, tb->cx);
4273 /* Correct fake cursor position */
4274 if (bx2 > len) bx2 = len;
4276 if (bx1 == 0 && bx2 == len)
4278 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4279 add_str_to_yank(tb, "");
4283 int end = bx2 - bx1;
4284 for (int i = 0; i < bx2 - bx1; i++)
4286 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4290 add_str_to_yank(tb, buf);
4294 tb->dirty_flags |= DIRTY_ALL;
4301 static void draw_text_editor(player_type *player_ptr, text_body_type *tb)
4304 int by1 = 0, by2 = 0;
4306 Term_get_size(&tb->wid, &tb->hgt);
4309 * Top line (-1), description line (-3), separator (-1)
4312 tb->hgt -= 2 + DESCRIPT_HGT;
4315 /* Don't let cursor at second byte of kanji */
4316 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4317 if (iskanji(tb->lines_list[tb->cy][i]))
4323 * Move to a correct position in the
4326 if (i & 1) tb->cx--;
4333 /* Scroll if necessary */
4334 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4335 tb->upper = tb->cy - (tb->hgt) / 2;
4338 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4339 tb->left = tb->cx - (tb->wid) * 2 / 3;
4343 /* Redraw whole window after resize */
4344 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4345 tb->dirty_flags |= DIRTY_SCREEN;
4347 /* Redraw all text after scroll */
4348 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4349 tb->dirty_flags |= DIRTY_ALL;
4352 if (tb->dirty_flags & DIRTY_SCREEN)
4354 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4358 /* Redraw mode line */
4359 if (tb->dirty_flags & DIRTY_MODE)
4361 char buf[MAX_LINELEN];
4363 int sepa_length = tb->wid;
4366 for (i = 0; i < sepa_length; i++)
4370 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4373 if (tb->dirty_flags & DIRTY_EXPRESSION)
4378 for (y = 0; tb->lines_list[y]; y++)
4382 concptr s = tb->lines_list[y];
4386 /* Update this line's state */
4387 tb->states[y] = state;
4389 if (*s++ != '?') continue;
4390 if (*s++ != ':') continue;
4392 /* Lines below this line are auto-registered */
4393 if (streq(s, "$AUTOREGISTER"))
4394 state |= LSTAT_AUTOREGISTER;
4397 ss = (char *)string_make(s);
4400 /* Parse the expr */
4401 v = process_pref_file_expr(player_ptr, &ss, &f);
4404 if (streq(v, "0")) state |= LSTAT_BYPASS;
4405 else state &= ~LSTAT_BYPASS;
4407 /* Cannot use string_free() because the string was "destroyed" */
4408 C_KILL(s_keep, s_len + 1, char);
4410 /* Re-update this line's state */
4411 tb->states[y] = state | LSTAT_EXPRESSION;
4414 tb->dirty_flags |= DIRTY_ALL;
4419 tb->dirty_flags |= DIRTY_ALL;
4421 by1 = MIN(tb->my, tb->cy);
4422 by2 = MAX(tb->my, tb->cy);
4425 /* Dump up to tb->hgt lines of messages */
4426 for (i = 0; i < tb->hgt; i++)
4432 int y = tb->upper + i;
4434 /* clean or dirty? */
4435 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4438 msg = tb->lines_list[y];
4441 /* Apply horizontal scroll */
4442 for (j = 0; *msg; msg++, j++)
4444 if (j == tb->left) break;
4460 Term_erase(0, i + 1, tb->wid);
4462 if (tb->states[y] & LSTAT_AUTOREGISTER)
4464 /* Warning color -- These lines will be deleted later */
4469 /* Bypassed line will be displayed by darker color */
4470 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4471 else color = TERM_WHITE;
4474 /* No mark or Out of mark */
4475 if (!tb->mark || (y < by1 || by2 < y))
4477 /* Dump the messages, bottom to top */
4478 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4481 /* Multiple lines selected */
4482 else if (by1 != by2)
4484 /* Dump the messages, bottom to top */
4485 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4488 /* Single line selected */
4491 int x0 = leftcol + tb->left;
4492 int len = strlen(tb->lines_list[tb->cy]);
4493 int bx1 = MIN(tb->mx, tb->cx);
4494 int bx2 = MAX(tb->mx, tb->cx);
4496 /* Correct cursor location */
4497 if (bx2 > len) bx2 = len;
4499 Term_gotoxy(leftcol, i + 1);
4500 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4501 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4502 Term_addstr(-1, color, msg + (bx2 - x0));
4506 for (; i < tb->hgt; i++)
4509 Term_erase(0, i + 1, tb->wid);
4512 bool is_updated = tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy;
4513 if (is_updated) return;
4515 autopick_type an_entry, *entry = &an_entry;
4516 concptr str1 = NULL, str2 = NULL;
4519 /* Clear information line */
4520 for (i = 0; i < DESCRIPT_HGT; i++)
4523 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4526 /* Display information */
4527 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4529 str1 = format(_("パターンが見つかりません: %s", "Pattern not found: %s"), tb->search_str);
4531 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4533 str1 = format(_("無効状態の行をスキップしました。(%sを検索中)",
4534 "Some inactive lines are skipped. (Searching %s)"), tb->search_str);
4536 else if (tb->dirty_flags & DIRTY_INACTIVE)
4538 str1 = format(_("無効状態の行だけが見付かりました。(%sを検索中)",
4539 "Found only an inactive line. (Searching %s)"), tb->search_str);
4541 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4543 str1 = _("検索するパターンがありません(^S で検索)。", "No pattern to search. (Press ^S to search.)");
4545 else if (tb->lines_list[tb->cy][0] == '#')
4547 str1 = _("この行はコメントです。", "This line is a comment.");
4549 else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
4551 switch (tb->lines_list[tb->cy][0])
4554 str1 = _("この行は条件分岐式です。", "This line is a Conditional Expression.");
4557 str1 = _("この行はマクロの実行内容を定義します。", "This line defines a Macro action.");
4560 str1 = _("この行はマクロのトリガー・キーを定義します。", "This line defines a Macro trigger key.");
4563 str1 = _("この行はキー配置を定義します。", "This line defines a Keymap.");
4567 switch (tb->lines_list[tb->cy][0])
4570 if (tb->states[tb->cy] & LSTAT_BYPASS)
4572 str2 = _("現在の式の値は「偽(=0)」です。", "The expression is 'False'(=0) currently.");
4576 str2 = _("現在の式の値は「真(=1)」です。", "The expression is 'True'(=1) currently.");
4581 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4583 str2 = _("この行は後で削除されます。", "This line will be delete later.");
4586 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4588 str2 = _("この行は現在は無効な状態です。", "This line is bypassed currently.");
4594 /* Get description of an autopicker preference line */
4595 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4597 char buf[MAX_LINELEN];
4598 char temp[MAX_LINELEN];
4601 describe_autopick(buf, entry);
4603 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4605 strcat(buf, _("この行は後で削除されます。", " This line will be delete later."));
4608 if (tb->states[tb->cy] & LSTAT_BYPASS)
4610 strcat(buf, _("この行は現在は無効な状態です。", " This line is bypassed currently."));
4613 roff_to_buf(buf, 81, temp, sizeof(temp));
4615 for (i = 0; i < 3; i++)
4621 prt(t, tb->hgt + 1 + 1 + i, 0);
4625 autopick_free_entry(entry);
4628 /* Draw the first line */
4629 if (str1) prt(str1, tb->hgt + 1 + 1, 0);
4631 /* Draw the second line */
4632 if (str2) prt(str2, tb->hgt + 1 + 2, 0);
4637 * Kill segment of a line
4639 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4641 /* Kill whole line? */
4642 concptr s = tb->lines_list[y];
4643 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y + 1])
4645 string_free(tb->lines_list[y]);
4647 /* Shift lines up */
4649 for (i = y; tb->lines_list[i + 1]; i++)
4650 tb->lines_list[i] = tb->lines_list[i + 1];
4651 tb->lines_list[i] = NULL;
4653 /* Expressions need re-evaluation */
4654 tb->dirty_flags |= DIRTY_EXPRESSION;
4659 if (x0 == x1) return;
4661 char buf[MAX_LINELEN];
4663 for (int x = 0; x < x0; x++)
4666 for (int x = x1; s[x]; x++)
4671 string_free(tb->lines_list[y]);
4672 tb->lines_list[y] = string_make(buf);
4674 check_expression_line(tb, y);
4681 * Get a trigger key and insert ASCII string for the trigger
4683 static bool insert_macro_line(text_body_type *tb)
4690 /* Do not process macros */
4696 /* Read the pattern */
4703 /* Do not process macros */
4706 /* Do not wait for keys */
4709 /* Attempt to read a key */
4718 /* Convert the trigger */
4720 ascii_to_text(tmp, buf);
4723 if (!tmp[0]) return FALSE;
4727 /* Insert preference string */
4728 insert_return_code(tb);
4729 string_free(tb->lines_list[tb->cy]);
4730 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4732 /* Acquire action */
4733 i = macro_find_exact(buf);
4737 /* Nothing defined */
4742 /* Analyze the current action */
4743 ascii_to_text(tmp, macro__act[i]);
4746 /* Insert blank action preference line */
4747 insert_return_code(tb);
4748 string_free(tb->lines_list[tb->cy]);
4749 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4756 * Get a command key and insert ASCII string for the key
4758 static bool insert_keymap_line(text_body_type *tb)
4762 if (rogue_like_commands)
4764 mode = KEYMAP_MODE_ROGUE;
4770 mode = KEYMAP_MODE_ORIG;
4781 /* Convert the trigger */
4783 ascii_to_text(tmp, buf);
4786 if (!tmp[0]) return FALSE;
4790 /* Insert preference string */
4791 insert_return_code(tb);
4792 string_free(tb->lines_list[tb->cy]);
4793 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4795 /* Look up the keymap */
4796 concptr act = keymap_act[mode][(byte)(buf[0])];
4799 /* Analyze the current action */
4800 ascii_to_text(tmp, act);
4803 /* Insert blank action preference line */
4804 insert_return_code(tb);
4805 string_free(tb->lines_list[tb->cy]);
4806 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4813 * Execute a single editor command
4815 static bool do_editor_command(player_type *player_ptr, text_body_type *tb, int com_id)
4822 if (!get_check(_("全ての変更を破棄してから終了します。よろしいですか? ",
4823 "Discard all changes and quit. Are you sure? "))) break;
4826 return QUIT_WITHOUT_SAVE;
4829 return QUIT_AND_SAVE;
4832 /* Revert to original */
4833 if (!get_check(_("全ての変更を破棄して元の状態に戻します。よろしいですか? ",
4834 "Discard all changes and revert to original file. Are you sure? "))) break;
4836 free_text_lines(tb->lines_list);
4837 tb->lines_list = read_pickpref_text_lines(player_ptr, &tb->filename_mode);
4838 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4839 tb->cx = tb->cy = 0;
4842 /* Text is not changed */
4843 tb->changed = FALSE;
4847 /* Peruse the main help file */
4848 (void)show_file(player_ptr, TRUE, _("jeditor.txt", "editor.txt"), NULL, 0, 0);
4850 tb->dirty_flags |= DIRTY_SCREEN;
4855 /* Split a line or insert end of line */
4857 /* Ignore selection */
4863 tb->dirty_flags |= DIRTY_ALL;
4866 insert_return_code(tb);
4871 tb->dirty_flags |= DIRTY_ALL;
4885 len = strlen(tb->lines_list[tb->cy]);
4886 if (len < tb->cx) tb->cx = len;
4889 /* Don't let cursor at second byte of kanji */
4890 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4892 if (iskanji(tb->lines_list[tb->cy][i]))
4897 /* Move to the left */
4905 else if (tb->cy > 0)
4908 tb->cx = strlen(tb->lines_list[tb->cy]);
4917 /* Is this the last line? */
4918 if (!tb->lines_list[tb->cy + 1])
4920 /* Add one more empty line if possible */
4921 if (!add_empty_line(tb)) break;
4931 if (tb->cy > 0) tb->cy--;
4937 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4940 int len = strlen(tb->lines_list[tb->cy]);
4943 /* Correct the cursor position */
4946 /* Is this the last line? */
4947 if (!tb->lines_list[tb->cy + 1])
4949 /* Add one more empty line if possible */
4950 if (!add_empty_line(tb)) break;
4953 /* Move to the beginning of next line */
4962 /* Beginning of line */
4968 tb->cx = strlen(tb->lines_list[tb->cy]);
4972 while (0 < tb->cy && tb->upper <= tb->cy)
4974 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
4980 while (tb->cy < tb->upper + tb->hgt)
4982 /* Is this the last line? */
4983 if (!tb->lines_list[tb->cy + 1])
4985 /* Add one more empty line if possible */
4986 if (!add_empty_line(tb)) break;
5002 /* Is this the last line? */
5003 if (!tb->lines_list[tb->cy + 1])
5005 /* Add one more empty line if possible */
5006 if (!add_empty_line(tb)) break;
5012 /* Always at the biginning of the last line */
5018 /* Copy the text first */
5019 copy_text_to_yank(tb);
5021 /* Single line case */
5022 if (tb->my == tb->cy)
5024 int bx1 = MIN(tb->mx, tb->cx);
5025 int bx2 = MAX(tb->mx, tb->cx);
5026 int len = strlen(tb->lines_list[tb->cy]);
5028 /* Correct fake cursor position */
5029 if (bx2 > len) bx2 = len;
5031 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
5033 /* New cursor position */
5037 /* Multiple lines case */
5038 else /* if (tb->my != tb->cy) */
5042 int by1 = MIN(tb->my, tb->cy);
5043 int by2 = MAX(tb->my, tb->cy);
5045 /* Kill lines in reverse order */
5046 for (y = by2; y >= by1; y--)
5048 int len = strlen(tb->lines_list[y]);
5050 kill_line_segment(tb, y, 0, len, TRUE);
5053 /* New cursor position */
5058 /* Disable selection */
5062 tb->dirty_flags |= DIRTY_ALL;
5064 /* Text is changed */
5071 copy_text_to_yank(tb);
5074 * Move cursor position to the end of the selection
5076 * Pressing ^C ^V correctly duplicates the selection.
5078 if (tb->my != tb->cy)
5080 tb->cy = MAX(tb->cy, tb->my);
5081 if (!tb->lines_list[tb->cy + 1])
5083 if (!add_empty_line(tb)) break;
5090 tb->cx = MAX(tb->cx, tb->mx);
5091 if (!tb->lines_list[tb->cy][tb->cx])
5093 if (!tb->lines_list[tb->cy + 1])
5095 if (!add_empty_line(tb)) break;
5106 /* Paste killed text */
5108 chain_str_type *chain = tb->yank;
5109 int len = strlen(tb->lines_list[tb->cy]);
5111 /* Nothing to do? */
5114 /* Correct cursor location */
5115 if (tb->cx > len) tb->cx = len;
5117 /* Ignore selection */
5123 tb->dirty_flags |= DIRTY_ALL;
5129 concptr yank_str = chain->s;
5131 char buf[MAX_LINELEN];
5133 char rest[MAX_LINELEN], *rest_ptr = rest;
5135 /* Save preceding string */
5136 for (i = 0; i < tb->cx; i++)
5137 buf[i] = tb->lines_list[tb->cy][i];
5139 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5141 /* Paste yank buffer */
5142 while (*yank_str && i < MAX_LINELEN - 1)
5144 buf[i++] = *yank_str++;
5150 chain = chain->next;
5152 if (chain || tb->yank_eol)
5154 /* There is an end of line between chain nodes */
5156 insert_return_code(tb);
5158 /* Replace this line with new one */
5159 string_free(tb->lines_list[tb->cy]);
5160 tb->lines_list[tb->cy] = string_make(buf);
5162 /* Move to next line */
5169 /* Final line doesn't have end of line */
5171 tb->cx = strlen(buf);
5173 /* Rest of original line */
5174 while (*rest_ptr && i < MAX_LINELEN - 1)
5176 buf[i++] = *rest_ptr++;
5182 /* Replace this line with new one */
5183 string_free(tb->lines_list[tb->cy]);
5184 tb->lines_list[tb->cy] = string_make(buf);
5190 tb->dirty_flags |= DIRTY_ALL;
5191 tb->dirty_flags |= DIRTY_EXPRESSION;
5201 tb->dirty_flags |= DIRTY_ALL;
5205 tb->mark = MARK_MARK;
5207 /* Repeating this command swaps cursor position */
5208 if (com_id == tb->old_com_id)
5216 tb->dirty_flags |= DIRTY_ALL;
5220 int len = strlen(tb->lines_list[tb->cy]);
5224 if (tb->cx > len) tb->mx = len;
5230 /* Kill rest of line */
5232 int len = strlen(tb->lines_list[tb->cy]);
5234 /* Correct cursor location */
5235 if (tb->cx > len) tb->cx = len;
5237 /* Ignore selection */
5243 tb->dirty_flags |= DIRTY_ALL;
5246 /* Append only if this command is repeated. */
5247 if (tb->old_com_id != com_id)
5249 kill_yank_chain(tb);
5253 /* Really deleted some text */
5256 /* Add deleted string to yank buffer */
5257 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5259 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5262 tb->dirty_line = tb->cy;
5264 /* Leave end of line character */
5268 /* Cut the end of line character only */
5269 if (tb->yank_eol) add_str_to_yank(tb, "");
5271 /* Cut end of line */
5272 tb->yank_eol = TRUE;
5274 do_editor_command(player_ptr, tb, EC_DELETE_CHAR);
5278 case EC_DELETE_CHAR:
5285 tb->dirty_flags |= DIRTY_ALL;
5289 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5293 /* Pass through the end of line to next line */
5294 int len = strlen(tb->lines_list[tb->cy]);
5297 do_editor_command(player_ptr, tb, EC_BACKSPACE);
5301 if (tb->lines_list[tb->cy + 1])
5312 do_editor_command(player_ptr, tb, EC_BACKSPACE);
5321 char buf[MAX_LINELEN];
5323 /* Ignore selection */
5329 tb->dirty_flags |= DIRTY_ALL;
5332 /* Move to correct collumn */
5333 len = strlen(tb->lines_list[tb->cy]);
5334 if (len < tb->cx) tb->cx = len;
5338 /* delete a return code and union two lines */
5339 if (tb->cy == 0) break;
5340 tb->cx = strlen(tb->lines_list[tb->cy - 1]);
5341 strcpy(buf, tb->lines_list[tb->cy - 1]);
5342 strcat(buf, tb->lines_list[tb->cy]);
5343 string_free(tb->lines_list[tb->cy - 1]);
5344 string_free(tb->lines_list[tb->cy]);
5345 tb->lines_list[tb->cy - 1] = string_make(buf);
5347 for (i = tb->cy; tb->lines_list[i + 1]; i++)
5348 tb->lines_list[i] = tb->lines_list[i + 1];
5350 tb->lines_list[i] = NULL;
5354 tb->dirty_flags |= DIRTY_ALL;
5356 /* Expressions need re-evaluation */
5357 tb->dirty_flags |= DIRTY_EXPRESSION;
5359 /* Text is changed */
5365 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5369 if (iskanji(tb->lines_list[tb->cy][i]))
5370 buf[j++] = tb->lines_list[tb->cy][i++];
5372 buf[j++] = tb->lines_list[tb->cy][i];
5381 for (; tb->lines_list[tb->cy][i]; i++)
5383 buf[j++] = tb->lines_list[tb->cy][i];
5387 string_free(tb->lines_list[tb->cy]);
5388 tb->lines_list[tb->cy] = string_make(buf);
5389 tb->dirty_line = tb->cy;
5390 check_expression_line(tb, tb->cy);
5399 /* Become dirty because of item/equip menu */
5400 tb->dirty_flags |= DIRTY_SCREEN;
5402 search_dir = get_string_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str);
5404 if (!search_dir) break;
5406 if (search_dir == 1) do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
5407 else do_editor_command(player_ptr, tb, EC_SEARCH_BACK);
5411 case EC_SEARCH_FORW:
5412 if (tb->search_o_ptr)
5414 search_for_object(player_ptr, tb, tb->search_o_ptr, TRUE);
5418 if (tb->search_str && tb->search_str[0])
5420 search_for_string(tb, tb->search_str, TRUE);
5424 tb->dirty_flags |= DIRTY_NO_SEARCH;
5427 case EC_SEARCH_BACK:
5428 if (tb->search_o_ptr)
5430 search_for_object(player_ptr, tb, tb->search_o_ptr, FALSE);
5434 if (tb->search_str && tb->search_str[0])
5436 search_for_string(tb, tb->search_str, FALSE);
5440 tb->dirty_flags |= DIRTY_NO_SEARCH;
5444 /* Become dirty because of item/equip menu */
5445 tb->dirty_flags |= DIRTY_SCREEN;
5447 if (!get_object_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str)) break;
5449 do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
5452 case EC_SEARCH_DESTROYED:
5453 if (!get_destroyed_object_for_search(player_ptr, &tb->search_o_ptr, &tb->search_str))
5455 /* There is no object to search */
5456 tb->dirty_flags |= DIRTY_NO_SEARCH;
5461 do_editor_command(player_ptr, tb, EC_SEARCH_FORW);
5464 case EC_INSERT_OBJECT:
5466 /* Insert choosen item name */
5468 autopick_type an_entry, *entry = &an_entry;
5470 if (!entry_from_choosed_object(player_ptr, entry))
5472 /* Now dirty because of item/equip menu */
5473 tb->dirty_flags |= DIRTY_SCREEN;
5478 insert_return_code(tb);
5479 string_free(tb->lines_list[tb->cy]);
5480 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5482 /* Now dirty because of item/equip menu */
5483 tb->dirty_flags |= DIRTY_SCREEN;
5488 case EC_INSERT_DESTROYED:
5489 if (!tb->last_destroyed) break;
5492 insert_return_code(tb);
5493 string_free(tb->lines_list[tb->cy]);
5494 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5497 tb->dirty_flags |= DIRTY_ALL;
5499 /* Text is changed */
5503 case EC_INSERT_BLOCK:
5505 /* Insert a conditinal expression line */
5506 char expression[80];
5508 /* Conditional Expression for Class and Race */
5509 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5511 rp_ptr->E_title, cp_ptr->E_title,
5513 rp_ptr->title, cp_ptr->title,
5518 insert_return_code(tb);
5519 string_free(tb->lines_list[tb->cy]);
5520 tb->lines_list[tb->cy] = string_make(expression);
5522 insert_return_code(tb);
5523 string_free(tb->lines_list[tb->cy]);
5524 tb->lines_list[tb->cy] = string_make("?:1");
5527 tb->dirty_flags |= DIRTY_ALL;
5529 /* Text is changed */
5535 case EC_INSERT_MACRO:
5536 /* Draw_everythig (delete menu) */
5537 draw_text_editor(player_ptr, tb);
5540 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5543 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, _("P:<トリガーキー>: ", "P:<Trigger key>: "));
5544 if (!insert_macro_line(tb)) break;
5546 /* Prepare to input action */
5548 tb->dirty_flags |= DIRTY_ALL;
5552 case EC_INSERT_KEYMAP:
5553 /* Draw_everythig (delete menu) */
5554 draw_text_editor(player_ptr, tb);
5557 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5560 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW,
5561 format(_("C:%d:<コマンドキー>: ", "C:%d:<Keypress>: "), (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5563 if (!insert_keymap_line(tb)) break;
5565 /* Prepare to input action */
5567 tb->dirty_flags |= DIRTY_ALL;
5571 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5572 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5573 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5574 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5575 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5577 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5578 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5579 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5580 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5581 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5582 case EC_KK_FAVORITE_WEAPONS: toggle_keyword(tb, FLG_FAVORITE_WEAPONS); break;
5583 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5584 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5585 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5586 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5587 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5588 case EC_KK_CORPSES: toggle_keyword(tb, FLG_CORPSES); break;
5589 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5590 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5591 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5592 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5593 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5594 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5595 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5596 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5597 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5598 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5599 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5600 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5601 case EC_OK_MORE_DICE: toggle_keyword(tb, FLG_MORE_DICE); break;
5602 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5603 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5604 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5605 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5606 case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
5607 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5608 case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
5609 case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
5610 case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
5611 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5612 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5613 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5614 case EC_OK_UNREADABLE:
5615 toggle_keyword(tb, FLG_UNREADABLE);
5616 add_keyword(tb, FLG_SPELLBOOKS);
5619 toggle_keyword(tb, FLG_REALM1);
5620 add_keyword(tb, FLG_SPELLBOOKS);
5623 toggle_keyword(tb, FLG_REALM2);
5624 add_keyword(tb, FLG_SPELLBOOKS);
5627 toggle_keyword(tb, FLG_FIRST);
5628 add_keyword(tb, FLG_SPELLBOOKS);
5631 toggle_keyword(tb, FLG_SECOND);
5632 add_keyword(tb, FLG_SPELLBOOKS);
5635 toggle_keyword(tb, FLG_THIRD);
5636 add_keyword(tb, FLG_SPELLBOOKS);
5639 toggle_keyword(tb, FLG_FOURTH);
5640 add_keyword(tb, FLG_SPELLBOOKS);
5644 tb->old_com_id = com_id;
5650 * Insert single letter at cursor position.
5652 static void insert_single_letter(text_body_type *tb, int key)
5655 char buf[MAX_LINELEN];
5657 /* Save preceding string */
5658 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5660 buf[j++] = tb->lines_list[tb->cy][i];
5670 if (j + 2 < MAX_LINELEN)
5672 buf[j++] = (char)key;
5673 buf[j++] = (char)next;
5682 if (j + 1 < MAX_LINELEN)
5683 buf[j++] = (char)key;
5688 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5689 buf[j++] = tb->lines_list[tb->cy][i];
5692 /* Replace current line with new line */
5693 string_free(tb->lines_list[tb->cy]);
5694 tb->lines_list[tb->cy] = string_make(buf);
5696 /* Move to correct collumn */
5697 len = strlen(tb->lines_list[tb->cy]);
5698 if (len < tb->cx) tb->cx = len;
5701 tb->dirty_line = tb->cy;
5703 /* Expressions may need re-evaluation */
5704 check_expression_line(tb, tb->cy);
5706 /* Text is changed */
5712 * Check special key code and get a movement command id
5714 static int analyze_move_key(text_body_type *tb, int skey)
5718 /* Not a special key */
5719 if (!(skey & SKEY_MASK)) return 0;
5721 /* Convert from a special key code to an editor command */
5722 switch (skey & ~SKEY_MOD_MASK)
5724 case SKEY_DOWN: com_id = EC_DOWN; break;
5725 case SKEY_LEFT: com_id = EC_LEFT; break;
5726 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5727 case SKEY_UP: com_id = EC_UP; break;
5728 case SKEY_PGUP: com_id = EC_PGUP; break;
5729 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5730 case SKEY_TOP: com_id = EC_TOP; break;
5731 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5734 /* Not a special movement key */
5738 if (!(skey & SKEY_MOD_SHIFT))
5741 * Un-shifted cursor keys cancells
5742 * selection created by shift+cursor.
5744 if (tb->mark & MARK_BY_SHIFT)
5749 tb->dirty_flags |= DIRTY_ALL;
5755 if (tb->mark) return com_id;
5757 int len = strlen(tb->lines_list[tb->cy]);
5759 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5763 /* Correct cursor location */
5764 if (tb->cx > len) tb->mx = len;
5766 /* Need to redraw text */
5767 if (com_id == EC_UP || com_id == EC_DOWN)
5769 /* Redraw all text */
5770 tb->dirty_flags |= DIRTY_ALL;
5774 tb->dirty_line = tb->cy;
5781 * In-game editor of Object Auto-picker/Destoryer
5782 * @param player_ptr プレーヤーへの参照ポインタ
5784 void do_cmd_edit_autopick(player_type *player_ptr)
5786 static int cx_save = 0;
5787 static int cy_save = 0;
5789 text_body_type text_body, *tb = &text_body;
5791 autopick_type an_entry, *entry = &an_entry;
5792 char buf[MAX_LINELEN];
5797 static s32b old_autosave_turn = 0L;
5800 tb->changed = FALSE;
5803 tb->upper = tb->left = 0;
5805 tb->mx = tb->my = 0;
5806 tb->old_cy = tb->old_upper = tb->old_left = -1;
5807 tb->old_wid = tb->old_hgt = -1;
5811 tb->search_o_ptr = NULL;
5812 tb->search_str = NULL;
5813 tb->last_destroyed = NULL;
5814 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5815 tb->dirty_line = -1;
5816 tb->filename_mode = PT_DEFAULT;
5818 if (current_world_ptr->game_turn < old_autosave_turn)
5820 while (old_autosave_turn > current_world_ptr->game_turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
5824 if (current_world_ptr->game_turn > old_autosave_turn + 100L)
5826 do_cmd_save_game(player_ptr, TRUE);
5827 old_autosave_turn = current_world_ptr->game_turn;
5830 /* HACK -- Reset current_world_ptr->start_time to stop counting current_world_ptr->play_time while edit */
5833 /* Free old entries */
5836 /* Command Description of the 'Last Destroyed Item' */
5837 if (autopick_last_destroyed_object.k_idx)
5839 autopick_entry_from_object(player_ptr, entry, &autopick_last_destroyed_object);
5840 tb->last_destroyed = autopick_line_from_entry_kill(entry);
5843 /* Read or initialize whole text */
5844 tb->lines_list = read_pickpref_text_lines(player_ptr, &tb->filename_mode);
5846 /* Reset cursor position if needed */
5847 for (i = 0; i < tb->cy; i++)
5849 if (!tb->lines_list[i])
5851 tb->cy = tb->cx = 0;
5858 /* Process requests until done */
5863 /* Draw_everythig */
5864 draw_text_editor(player_ptr, tb);
5866 /* Display header line */
5867 prt(_("(^Q:終了 ^W:セーブして終了, ESC:メニュー, その他:入力)",
5868 "(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)"), 0, 0);
5871 /* Display current position */
5872 prt(format("(%d,%d)", tb->cx, tb->cy), 0, 60);
5876 /* Display current position and mark position */
5877 prt(format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
5881 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
5884 tb->dirty_flags = 0;
5885 tb->dirty_line = -1;
5887 /* Save old key and location */
5888 tb->old_cy = tb->cy;
5889 tb->old_upper = tb->upper;
5890 tb->old_left = tb->left;
5891 tb->old_wid = tb->wid;
5892 tb->old_hgt = tb->hgt;
5894 key = inkey_special(TRUE);
5897 if (key & SKEY_MASK)
5899 /* Get a movement command */
5900 com_id = analyze_move_key(tb, key);
5904 else if (key == ESCAPE)
5906 com_id = do_command_menu(0, 0);
5908 /* Redraw all text later */
5909 tb->dirty_flags |= DIRTY_SCREEN;
5912 /* Insert a character */
5913 else if (!iscntrl((unsigned char)key))
5915 /* Ignore selection */
5921 tb->dirty_flags |= DIRTY_ALL;
5924 insert_single_letter(tb, key);
5930 /* Other commands */
5933 com_id = get_com_id((char)key);
5936 if (com_id) quit = do_editor_command(player_ptr, tb, com_id);
5940 strcpy(buf, pickpref_filename(player_ptr, tb->filename_mode));
5942 if (quit == QUIT_AND_SAVE)
5943 write_text_lines(buf, tb->lines_list);
5945 free_text_lines(tb->lines_list);
5947 string_free(tb->search_str);
5948 string_free(tb->last_destroyed);
5950 /* Destroy string chain */
5951 kill_yank_chain(tb);
5953 /* Reload autopick pref */
5954 process_autopick_file(player_ptr, buf);
5956 /* HACK -- reset current_world_ptr->start_time so that current_world_ptr->play_time is not increase while edit */
5957 current_world_ptr->start_time = (u32b)time(NULL);
5959 /* Save cursor location */