2 * @brief prefファイルの内容を解釈しメモリに展開する
7 #include "io/interpret-pref-file.h"
8 #include "io/gf-descriptions.h"
9 #include "io/tokenizer.h"
10 #include "object/object-kind.h"
14 #include "view-mainwindow.h" // 暫定。apply_default_feat_lighting()。後で消す.
16 #define MAX_MACRO_CHARS 65536 // 1つのマクロキー押下で実行可能なコマンド最大数 (エスケープシーケンス含む).
19 * @brief Rトークンの解釈 / Process "R:<num>:<a>/<c>" -- attr/char for monster races
23 static errr interpret_r_token(char *buf)
26 if (tokenize(buf + 2, 3, zz, TOKENIZE_CHECKQUOTE) != 3) return 1;
29 int i = (int)strtol(zz[0], NULL, 0);
30 TERM_COLOR n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
31 SYMBOL_CODE n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
32 if (i >= max_r_idx) return 1;
35 if (n1 || (!(n2 & 0x80) && n2)) r_ptr->x_attr = n1; /* Allow TERM_DARK text */
36 if (n2) r_ptr->x_char = n2;
43 * @brief Kトークンの解釈 / Process "K:<num>:<a>/<c>" -- attr/char for object kinds
47 static errr interpret_k_token(char *buf)
50 if (tokenize(buf + 2, 3, zz, TOKENIZE_CHECKQUOTE) != 3) return 1;
53 int i = (int)strtol(zz[0], NULL, 0);
54 TERM_COLOR n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
55 SYMBOL_CODE n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
56 if (i >= max_k_idx) return 1;
59 if (n1 || (!(n2 & 0x80) && n2)) k_ptr->x_attr = n1; /* Allow TERM_DARK text */
60 if (n2) k_ptr->x_char = n2;
67 * @brief トークン数によって地形の文字形と色を決定する
72 static errr decide_feature_type(int i, int num, char **zz)
77 TERM_COLOR n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
78 SYMBOL_CODE n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
79 if (n1 || (!(n2 & 0x80) && n2)) f_ptr->x_attr[F_LIT_STANDARD] = n1; /* Allow TERM_DARK text */
80 if (n2) f_ptr->x_char[F_LIT_STANDARD] = n2;
86 /* No lighting support */
87 n1 = f_ptr->x_attr[F_LIT_STANDARD];
88 n2 = f_ptr->x_char[F_LIT_STANDARD];
89 for (int j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
91 f_ptr->x_attr[j] = n1;
92 f_ptr->x_char[j] = n2;
99 /* Use default lighting */
100 apply_default_feat_lighting(f_ptr->x_attr, f_ptr->x_char);
103 case F_LIT_MAX * 2 + 1:
105 /* Use desired lighting */
106 for (int j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
108 n1 = (TERM_COLOR)strtol(zz[j * 2 + 1], NULL, 0);
109 n2 = (SYMBOL_CODE)strtol(zz[j * 2 + 2], NULL, 0);
110 if (n1 || (!(n2 & 0x80) && n2)) f_ptr->x_attr[j] = n1; /* Allow TERM_DARK text */
111 if (n2) f_ptr->x_char[j] = n2;
123 * @brief Fトークンの解釈 / Process "F:<num>:<a>/<c>" -- attr/char for terrain features
128 * "F:<num>:<a>/<c>:LIT"
129 * "F:<num>:<a>/<c>:<la>/<lc>:<da>/<dc>"
131 static errr interpret_f_token(char *buf)
134 int num = tokenize(buf + 2, F_LIT_MAX * 2 + 1, zz, TOKENIZE_CHECKQUOTE);
136 if ((num != 3) && (num != 4) && (num != F_LIT_MAX * 2 + 1)) return 1;
137 else if ((num == 4) && !streq(zz[3], "LIT")) return 1;
139 int i = (int)strtol(zz[0], NULL, 0);
140 if (i >= max_f_idx) return 1;
142 return decide_feature_type(i, num, zz);
147 * @brief Fトークンの解釈 / Process "S:<num>:<a>/<c>" -- attr/char for special things
151 static errr interpret_s_token(char *buf)
154 if (tokenize(buf + 2, 3, zz, TOKENIZE_CHECKQUOTE) != 3) return 1;
156 int j = (byte)strtol(zz[0], NULL, 0);
157 TERM_COLOR n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
158 SYMBOL_CODE n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
159 misc_to_attr[j] = n1;
160 misc_to_char[j] = n2;
166 * @brief Uトークンの解釈 / Process "U:<tv>:<a>/<c>" -- attr/char for unaware items
170 static errr interpret_u_token(char *buf)
173 if (tokenize(buf + 2, 3, zz, TOKENIZE_CHECKQUOTE) != 3) return 1;
175 int j = (int)strtol(zz[0], NULL, 0);
176 TERM_COLOR n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
177 SYMBOL_CODE n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
178 for (int i = 1; i < max_k_idx; i++)
180 object_kind *k_ptr = &k_info[i];
181 if (k_ptr->tval == j)
183 if (n1) k_ptr->d_attr = n1;
184 if (n2) k_ptr->d_char = n2;
193 * @brief Eトークンの解釈 / Process "E:<tv>:<a>" -- attribute for inventory objects
197 static errr interpret_e_token(char *buf)
200 if (tokenize(buf + 2, 2, zz, TOKENIZE_CHECKQUOTE) != 2) return 1;
202 int j = (byte)strtol(zz[0], NULL, 0) % 128;
203 TERM_COLOR n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
204 if (n1) tval_to_attr[j] = n1;
210 * @brief Pトークンの解釈 / Process "P:<str>" -- normal macro
214 static errr interpret_p_token(char *buf)
217 text_to_ascii(tmp, buf + 2);
218 macro_add(tmp, macro__buf);
224 * @brief Cトークンの解釈 / Process "C:<str>" -- create keymap
228 static errr interpret_c_token(char *buf)
231 if (tokenize(buf + 2, 2, zz, TOKENIZE_CHECKQUOTE) != 2) return 1;
233 int mode = strtol(zz[0], NULL, 0);
234 if ((mode < 0) || (mode >= KEYMAP_MODES)) return 1;
237 text_to_ascii(tmp, zz[1]);
238 if (!tmp[0] || tmp[1]) return 1;
240 int i = (byte)(tmp[0]);
241 string_free(keymap_act[mode][i]);
242 keymap_act[mode][i] = string_make(macro__buf);
248 * @brief Vトークンの解釈 / Process "V:<num>:<kv>:<rv>:<gv>:<bv>" -- visual info
252 static errr interpret_v_token(char *buf)
255 if (tokenize(buf + 2, 5, zz, TOKENIZE_CHECKQUOTE) != 5) return 1;
257 int i = (byte)strtol(zz[0], NULL, 0);
258 angband_color_table[i][0] = (byte)strtol(zz[1], NULL, 0);
259 angband_color_table[i][1] = (byte)strtol(zz[2], NULL, 0);
260 angband_color_table[i][2] = (byte)strtol(zz[3], NULL, 0);
261 angband_color_table[i][3] = (byte)strtol(zz[4], NULL, 0);
268 * @param creature_ptr プレーヤーへの参照ポインタ
272 * Process "X:<str>" -- turn option off
273 * Process "Y:<str>" -- turn option on
275 static errr interpret_xy_token(player_type *creature_ptr, char *buf)
277 for (int i = 0; option_info[i].o_desc; i++)
279 bool is_option = option_info[i].o_var != NULL;
280 is_option &= option_info[i].o_text != NULL;
281 is_option &= streq(option_info[i].o_text, buf + 2);
282 if (!is_option) continue;
284 int os = option_info[i].o_set;
285 int ob = option_info[i].o_bit;
287 if ((creature_ptr->playing || current_world_ptr->character_xtra) &&
288 (OPT_PAGE_BIRTH == option_info[i].o_page) && !current_world_ptr->wizard)
290 msg_format(_("初期オプションは変更できません! '%s'", "Birth options can not changed! '%s'"), buf);
297 option_flag[os] &= ~(1L << ob);
298 (*option_info[i].o_var) = FALSE;
302 option_flag[os] |= (1L << ob);
303 (*option_info[i].o_var) = TRUE;
307 msg_format(_("オプションの名前が正しくありません: %s", "Ignored invalid option: %s"), buf);
314 * @brief Zトークンの解釈 / Process "Z:<type>:<str>" -- set spell color
316 * @param zz トークン保管文字列
319 static errr interpret_z_token(char *buf)
321 char *t = my_strchr(buf + 2, ':');
325 for (int i = 0; i < MAX_NAMED_NUM; i++)
327 if (!streq(gf_desc[i].name, buf + 2)) continue;
329 gf_color[gf_desc[i].num] = (TERM_COLOR)quark_add(t);
338 * @brief Tトークンの解釈 / Process "T:<template>:<modifier chr>:<modifier name>:..." for 4 tokens
340 * @param zz トークン保管文字列
343 static errr decide_template_modifier(int tok, char **zz)
345 if (macro_template != NULL)
347 int macro_modifier_length = strlen(macro_modifier_chr);
348 string_free(macro_template);
349 macro_template = NULL;
350 string_free(macro_modifier_chr);
351 for (int i = 0; i < macro_modifier_length; i++)
353 string_free(macro_modifier_name[i]);
356 for (int i = 0; i < max_macrotrigger; i++)
358 string_free(macro_trigger_name[i]);
359 string_free(macro_trigger_keycode[0][i]);
360 string_free(macro_trigger_keycode[1][i]);
363 max_macrotrigger = 0;
366 if (*zz[0] == '\0') return 0;
368 int zz_length = strlen(zz[1]);
369 zz_length = MIN(MAX_MACRO_MOD, zz_length);
370 if (2 + zz_length != tok) return 1;
372 macro_template = string_make(zz[0]);
373 macro_modifier_chr = string_make(zz[1]);
374 for (int i = 0; i < zz_length; i++)
376 macro_modifier_name[i] = string_make(zz[2 + i]);
384 * @brief Tトークンの解釈 / Process "T:<trigger>:<keycode>:<shift-keycode>" for 2 or 3 tokens
386 * @param zz トークン保管文字列
389 static errr interpret_macro_keycodes(int tok, char **zz)
391 char buf_aux[MAX_MACRO_CHARS];
393 if (max_macrotrigger >= MAX_MACRO_TRIG)
395 msg_print(_("マクロトリガーの設定が多すぎます!", "Too many macro triggers!"));
399 int m = max_macrotrigger;
410 macro_trigger_name[m] = string_make(buf_aux);
411 macro_trigger_keycode[0][m] = string_make(zz[1]);
414 macro_trigger_keycode[1][m] = string_make(zz[2]);
418 macro_trigger_keycode[1][m] = string_make(zz[1]);
424 * todo 2.2.1r時点のコードからトークン数0~1の場合もエラーコード0だが、1であるべきでは?
425 * @brief Tトークンの個数調査 (解釈はサブルーチンで) / Initialize macro trigger names and a template
429 static errr interpret_t_token(char *buf)
432 int tok = tokenize(buf + 2, 2 + MAX_MACRO_MOD, zz, 0);
433 if (tok >= 4) return decide_template_modifier(tok, zz);
434 if (tok < 2) return 0;
436 return interpret_macro_keycodes(tok, zz);
441 * @brief 設定ファイルの各行から各種テキスト情報を取得する /
442 * Parse a sub-file of the "extra info" (format shown below)
443 * @param creature_ptr プレーヤーへの参照ポインタ
444 * @param buf データテキストの参照ポインタ
448 * Each "action" line has an "action symbol" in the first column,
449 * followed by a colon, followed by some command specific info,
450 * usually in the form of "tokens" separated by colons or slashes.
451 * Blank lines, lines starting with white space, and lines starting
452 * with pound signs ("#") are ignored (as comments).
453 * Note the use of "tokenize()" to allow the use of both colons and
454 * slashes as delimeters, while still allowing final tokens which
455 * may contain any characters including "delimiters".
456 * Note the use of "strtol()" to allow all "integers" to be encoded
457 * in decimal, hexidecimal, or octal form.
458 * Note that "monster zero" is used for the "player" attr/char, "object
459 * zero" will be used for the "stack" attr/char, and "feature zero" is
460 * used for the "nothing" attr/char.
463 errr interpret_pref_file(player_type *creature_ptr, char *buf)
465 if (buf[1] != ':') return 1;
471 /* Process "H:<history>" */
472 add_history_from_pref_line(buf + 2);
476 return interpret_r_token(buf);
478 return interpret_k_token(buf);
480 return interpret_f_token(buf);
482 return interpret_s_token(buf);
484 return interpret_u_token(buf);
486 return interpret_e_token(buf);
489 /* Process "A:<str>" -- save an "action" for later */
490 text_to_ascii(macro__buf, buf + 2);
494 return interpret_p_token(buf);
496 return interpret_c_token(buf);
498 return interpret_v_token(buf);
501 return interpret_xy_token(creature_ptr, buf);
503 return interpret_z_token(buf);
505 return interpret_t_token(buf);