1 #include "player/process-name.h"
2 #include "autopick/autopick-reader-writer.h"
3 #include "core/asking-player.h"
4 #include "game-option/birth-options.h"
5 #include "io/files-util.h"
6 #include "player/player-personality.h"
7 #include "term/screen-processor.h"
8 #include "term/term-color-types.h"
9 #include "util/angband-files.h"
10 #include "util/string-processor.h"
11 #include "world/world.h"
14 * @brief プレイヤーの名前をチェックして修正する
15 * Process the player name.
16 * @param player_ptr プレーヤーへの参照ポインタ
17 * @param sf セーブファイル名に合わせた修正を行うならばTRUE
20 * Extract a clean "base name".
21 * Build the savefile name if needed.
23 void process_player_name(player_type *creature_ptr, bool sf)
25 char old_player_base[32] = "";
26 if (current_world_ptr->character_generated)
27 strcpy(old_player_base, creature_ptr->base_name);
29 for (int i = 0; creature_ptr->name[i]; i++) {
31 if (iskanji(creature_ptr->name[i])) {
36 if (iscntrl((unsigned char)creature_ptr->name[i]))
38 if (iscntrl(creature_ptr->name[i]))
41 quit_fmt(_("'%s' という名前は不正なコントロールコードを含んでいます。", "The name '%s' contains control chars!"), creature_ptr->name);
46 for (int i = 0; creature_ptr->name[i]; i++) {
48 unsigned char c = creature_ptr->name[i];
50 char c = creature_ptr->name[i];
55 if (k + 2 >= (int)sizeof(creature_ptr->base_name) || !creature_ptr->name[i + 1])
58 creature_ptr->base_name[k++] = c;
60 creature_ptr->base_name[k++] = creature_ptr->name[i];
64 creature_ptr->base_name[k++] = c;
68 if (!strncmp(PATH_SEP, creature_ptr->name + i, strlen(PATH_SEP))) {
69 creature_ptr->base_name[k++] = '_';
70 i += strlen(PATH_SEP);
73 else if (angband_strchr("\"*,/:;<>?\\|", c))
74 creature_ptr->base_name[k++] = '_';
77 creature_ptr->base_name[k++] = c;
80 creature_ptr->base_name[k] = '\0';
81 if (!creature_ptr->base_name[0])
82 strcpy(creature_ptr->base_name, "PLAYER");
84 if (!keep_savefile || !savefile[0]) {
85 #ifdef SAVEFILE_MUTABLE
88 if (!savefile_base[0] && savefile[0]) {
92 t = angband_strstr(s, PATH_SEP);
98 strcpy(savefile_base, s);
101 if (!savefile_base[0] || !savefile[0])
106 strcpy(savefile_base, creature_ptr->base_name);
108 #ifdef SAVEFILE_USE_UID
109 /* Rename the savefile, using the creature_ptr->player_uid and creature_ptr->base_name */
110 (void)sprintf(temp, "%d.%s", creature_ptr->player_uid, creature_ptr->base_name);
112 /* Rename the savefile, using the creature_ptr->base_name */
113 (void)sprintf(temp, "%s", creature_ptr->base_name);
115 path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
119 if (current_world_ptr->character_generated && !streq(old_player_base, creature_ptr->base_name)) {
120 autopick_load_pref(creature_ptr, FALSE);
125 * @brief プレイヤーの名前を変更するコマンドのメインルーチン
126 * Gets a name for the character, reacting to name changes.
127 * @param creature_ptr プレーヤーへの参照ポインタ
131 * Assumes that "display_player()" has just been called
132 * Perhaps we should NOT ask for a name (at "birth()") on
133 * Unix machines? XXX XXX
134 * What a horrible name for a global function.
137 void get_name(player_type *creature_ptr)
140 strcpy(tmp, creature_ptr->name);
142 if (get_string(_("キャラクターの名前を入力して下さい: ", "Enter a name for your character: "), tmp, 15)) {
143 strcpy(creature_ptr->name, tmp);
146 if (strlen(creature_ptr->name) == 0) {
147 strcpy(creature_ptr->name, "PLAYER");
150 strcpy(tmp, ap_ptr->title);
157 strcat(tmp, creature_ptr->name);
159 term_erase(34, 1, 255);
160 c_put_str(TERM_L_BLUE, tmp, 1, 34);