1 #include "player/process-name.h"
2 #include "autopick/autopick-reader-writer.h"
3 #include "core/asking-player.h"
4 #include "io/files-util.h"
5 #include "player/player-personality.h"
6 #include "term/screen-processor.h"
7 #include "term/term-color-types.h"
8 #include "util/angband-files.h"
9 #include "util/string-processor.h"
10 #include "world/world.h"
13 * @brief プレイヤーの名前をチェックして修正する
14 * Process the player name.
15 * @param player_ptr プレーヤーへの参照ポインタ
16 * @param sf セーブファイル名に合わせた修正を行うならばTRUE
19 * Extract a clean "base name".
20 * Build the savefile name if needed.
22 void process_player_name(player_type *creature_ptr, bool sf)
24 char old_player_base[32] = "";
25 if (current_world_ptr->character_generated)
26 strcpy(old_player_base, creature_ptr->base_name);
28 for (int i = 0; creature_ptr->name[i]; i++)
31 if (iskanji(creature_ptr->name[i]))
37 if (iscntrl((unsigned char)creature_ptr->name[i]))
39 if (iscntrl(creature_ptr->name[i]))
42 quit_fmt(_("'%s' という名前は不正なコントロールコードを含んでいます。", "The name '%s' contains control chars!"), creature_ptr->name);
47 for (int i = 0; creature_ptr->name[i]; i++)
50 unsigned char c = creature_ptr->name[i];
52 char c = creature_ptr->name[i];
57 if (k + 2 >= (int)sizeof(creature_ptr->base_name) || !creature_ptr->name[i + 1])
60 creature_ptr->base_name[k++] = c;
62 creature_ptr->base_name[k++] = creature_ptr->name[i];
65 else if (iskana(c)) creature_ptr->base_name[k++] = c;
69 if (!strncmp(PATH_SEP, creature_ptr->name + i, strlen(PATH_SEP)))
71 creature_ptr->base_name[k++] = '_';
72 i += strlen(PATH_SEP);
75 else if (angband_strchr("\"*,/:;<>?\\|", c))
76 creature_ptr->base_name[k++] = '_';
79 creature_ptr->base_name[k++] = c;
82 creature_ptr->base_name[k] = '\0';
83 if (!creature_ptr->base_name[0])
84 strcpy(creature_ptr->base_name, "PLAYER");
86 #ifdef SAVEFILE_MUTABLE
89 if (!savefile_base[0] && savefile[0])
95 t = angband_strstr(s, PATH_SEP);
101 strcpy(savefile_base, s);
104 if (!savefile_base[0] || !savefile[0])
110 strcpy(savefile_base, creature_ptr->base_name);
112 #ifdef SAVEFILE_USE_UID
113 /* Rename the savefile, using the creature_ptr->player_uid and creature_ptr->base_name */
114 (void)sprintf(temp, "%d.%s", creature_ptr->player_uid, creature_ptr->base_name);
116 /* Rename the savefile, using the creature_ptr->base_name */
117 (void)sprintf(temp, "%s", creature_ptr->base_name);
119 path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
122 if (current_world_ptr->character_generated && !streq(old_player_base, creature_ptr->base_name))
124 autopick_load_pref(creature_ptr, FALSE);
130 * @brief プレイヤーの名前を変更するコマンドのメインルーチン
131 * Gets a name for the character, reacting to name changes.
132 * @param creature_ptr プレーヤーへの参照ポインタ
136 * Assumes that "display_player()" has just been called
137 * Perhaps we should NOT ask for a name (at "birth()") on
138 * Unix machines? XXX XXX
139 * What a horrible name for a global function.
142 void get_name(player_type *creature_ptr)
145 strcpy(tmp, creature_ptr->name);
147 if (get_string(_("キャラクターの名前を入力して下さい: ", "Enter a name for your character: "), tmp, 15))
149 strcpy(creature_ptr->name, tmp);
152 if (strlen(creature_ptr->name) == 0)
154 strcpy(creature_ptr->name, "PLAYER");
157 strcpy(tmp, ap_ptr->title);
164 strcat(tmp, creature_ptr->name);
166 term_erase(34, 1, 255);
167 c_put_str(TERM_L_BLUE, tmp, 1, 34);