2 * @brief 自動拾いにアイテムを登録する
8 #include "autopick/autopick-registry.h"
9 #include "autopick/autopick-util.h"
10 #include "autopick/autopick-methods-table.h"
11 #include "autopick/autopick-reader-writer.h"
12 #include "autopick/autopick-entry.h"
13 #include "autopick/autopick-finder.h"
14 #include "autopick/autopick-adder.h"
15 #include "object-hook.h"
16 #include "object/object-kind.h"
17 #include "object-flavor.h"
21 static const char autoregister_header[] = "?:$AUTOREGISTER";
24 * Clear auto registered lines in the picktype.prf .
26 static bool clear_auto_register(player_type *player_ptr)
29 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(player_ptr, PT_WITH_PNAME));
31 pref_fff = my_fopen(pref_file, "r");
35 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(player_ptr, PT_DEFAULT));
36 pref_fff = my_fopen(pref_file, "r");
46 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
50 msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
55 bool autoregister = FALSE;
60 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
64 if (buf[0] != '#' && buf[0] != '?') num++;
68 if (streq(buf, autoregister_header))
74 fprintf(tmp_fff, "%s\n", buf);
84 msg_format(_("以前のキャラクター用の自動設定(%d行)が残っています。",
85 "Auto registered lines (%d lines) for previous character are remaining."), num);
86 strcpy(buf, _("古い設定行は削除します。よろしいですか?", "These lines will be deleted. Are you sure? "));
93 msg_print(_("エディタのカット&ペースト等を使って必要な行を避難してください。",
94 "Use cut & paste of auto picker editor (_) to keep old prefs."));
100 tmp_fff = my_fopen(tmp_file, "r");
101 pref_fff = my_fopen(pref_file, "w");
103 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
104 fprintf(pref_fff, "%s\n", buf);
116 * Automatically register an auto-destroy preference line
118 bool autopick_autoregister(player_type *player_ptr, object_type *o_ptr)
120 autopick_type an_entry, *entry = &an_entry;
121 int match_autopick = find_autopick_list(player_ptr, o_ptr);
122 if (match_autopick != -1)
125 byte act = autopick_list[match_autopick].action;
126 if (act & DO_AUTOPICK) what = _("自動で拾う", "auto-pickup");
127 else if (act & DO_AUTODESTROY) what = _("自動破壊する", "auto-destroy");
128 else if (act & DONT_AUTOPICK) what = _("放置する", "leave on floor");
129 else what = _("確認して拾う", "query auto-pickup");
131 msg_format(_("そのアイテムは既に%sように設定されています。", "The object is already registered to %s."), what);
135 if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
136 ((o_ptr->ident & IDENT_SENSE) &&
137 (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
139 GAME_TEXT o_name[MAX_NLEN];
140 object_desc(player_ptr, o_name, o_ptr, 0);
141 msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
145 if (!player_ptr->autopick_autoregister)
147 if (!clear_auto_register(player_ptr)) return FALSE;
151 char pref_file[1024];
153 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(player_ptr, PT_WITH_PNAME));
154 pref_fff = my_fopen(pref_file, "r");
158 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(player_ptr, PT_DEFAULT));
159 pref_fff = my_fopen(pref_file, "r");
166 if (my_fgets(pref_fff, buf, sizeof(buf)))
168 player_ptr->autopick_autoregister = FALSE;
172 if (streq(buf, autoregister_header))
174 player_ptr->autopick_autoregister = TRUE;
184 * File could not be opened for reading. Assume header not
187 player_ptr->autopick_autoregister = FALSE;
190 pref_fff = my_fopen(pref_file, "a");
193 msg_format(_("%s を開くことができませんでした。", "Failed to open %s."), pref_file);
198 if (!player_ptr->autopick_autoregister)
200 fprintf(pref_fff, "%s\n", autoregister_header);
202 fprintf(pref_fff, "%s\n", _("# *警告!!* 以降の行は自動登録されたものです。",
203 "# *Warning!* The lines below will be deleted later."));
204 fprintf(pref_fff, "%s\n", _("# 後で自動的に削除されますので、必要な行は上の方へ移動しておいてください。",
205 "# Keep it by cut & paste if you need these lines for future characters."));
206 player_ptr->autopick_autoregister = TRUE;
209 autopick_entry_from_object(player_ptr, entry, o_ptr);
210 entry->action = DO_AUTODESTROY;
211 add_autopick_list(entry);
213 concptr tmp = autopick_line_from_entry(entry);
214 fprintf(pref_fff, "%s\n", tmp);