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 "system/player-type-definition.h"
8 #include "term/screen-processor.h"
9 #include "term/term-color-types.h"
10 #include "util/angband-files.h"
11 #include "util/string-processor.h"
12 #include "world/world.h"
15 * @brief プレイヤーの名前をチェックして修正する
16 * Process the player name.
17 * @param player_ptr プレイヤーへの参照ポインタ
18 * @param sf セーブファイル名に合わせた修正を行うならばTRUE
20 * Extract a clean "base name".
21 * Build the savefile name if needed.
23 void process_player_name(PlayerType *player_ptr, bool is_new_savefile)
25 char old_player_base[32] = "";
26 if (w_ptr->character_generated) {
27 strcpy(old_player_base, player_ptr->base_name);
30 for (int i = 0; player_ptr->name[i]; i++) {
32 if (iskanji(player_ptr->name[i])) {
37 if (iscntrl((unsigned char)player_ptr->name[i]))
39 if (iscntrl(player_ptr->name[i]))
42 quit_fmt(_("'%s' という名前は不正なコントロールコードを含んでいます。", "The name '%s' contains control chars!"), player_ptr->name);
47 for (int i = 0; player_ptr->name[i]; i++) {
49 unsigned char c = player_ptr->name[i];
51 char c = player_ptr->name[i];
56 if (k + 2 >= (int)sizeof(player_ptr->base_name) || !player_ptr->name[i + 1]) {
60 player_ptr->base_name[k++] = c;
62 player_ptr->base_name[k++] = player_ptr->name[i];
66 player_ptr->base_name[k++] = c;
70 if (!strncmp(PATH_SEP, player_ptr->name + i, strlen(PATH_SEP))) {
71 player_ptr->base_name[k++] = '_';
72 i += strlen(PATH_SEP);
75 else if (angband_strchr("\"*,/:;<>?\\|", c))
76 player_ptr->base_name[k++] = '_';
78 else if (isprint(c)) {
79 player_ptr->base_name[k++] = c;
83 player_ptr->base_name[k] = '\0';
84 if (!player_ptr->base_name[0]) {
85 strcpy(player_ptr->base_name, "PLAYER");
88 auto is_modified = false;
89 if (is_new_savefile && (!savefile[0] || !keep_savefile)) {
92 #ifdef SAVEFILE_USE_UID
93 /* Rename the savefile, using the player_ptr->player_uid and player_ptr->base_name */
94 (void)sprintf(temp, "%d.%s", player_ptr->player_uid, player_ptr->base_name);
96 /* Rename the savefile, using the player_ptr->base_name */
97 (void)sprintf(temp, "%s", player_ptr->base_name);
99 path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
103 if (is_modified || !savefile_base[0]) {
104 concptr s = savefile;
107 t = angband_strstr(s, PATH_SEP);
114 #ifdef SAVEFILE_USE_UID
115 strcpy(savefile_base, angband_strstr(s, ".") + 1);
117 strcpy(savefile_base, s);
121 if (w_ptr->character_generated && !streq(old_player_base, player_ptr->base_name)) {
122 autopick_load_pref(player_ptr, false);
127 * @brief プレイヤーの名前を変更するコマンドのメインルーチン
128 * Gets a name for the character, reacting to name changes.
129 * @param player_ptr プレイヤーへの参照ポインタ
132 * Assumes that "display_player()" has just been called
133 * Perhaps we should NOT ask for a name (at "birth()") on
134 * Unix machines? XXX XXX
135 * What a horrible name for a global function.
138 void get_name(PlayerType *player_ptr)
141 strcpy(tmp, player_ptr->name);
143 if (get_string(_("キャラクターの名前を入力して下さい: ", "Enter a name for your character: "), tmp, 15)) {
144 strcpy(player_ptr->name, tmp);
147 if (strlen(player_ptr->name) == 0) {
148 strcpy(player_ptr->name, "PLAYER");
151 strcpy(tmp, ap_ptr->title);
153 if (ap_ptr->no == 1) {
159 strcat(tmp, player_ptr->name);
161 term_erase(34, 1, 255);
162 c_put_str(TERM_L_BLUE, tmp, 1, 34);