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++) {
30 if (iskanji(creature_ptr->name[i])) {
35 if (iscntrl((unsigned char)creature_ptr->name[i]))
37 if (iscntrl(creature_ptr->name[i]))
40 quit_fmt(_("'%s' という名前は不正なコントロールコードを含んでいます。", "The name '%s' contains control chars!"), creature_ptr->name);
45 for (int i = 0; creature_ptr->name[i]; i++) {
47 unsigned char c = creature_ptr->name[i];
49 char c = creature_ptr->name[i];
54 if (k + 2 >= (int)sizeof(creature_ptr->base_name) || !creature_ptr->name[i + 1])
57 creature_ptr->base_name[k++] = c;
59 creature_ptr->base_name[k++] = creature_ptr->name[i];
63 creature_ptr->base_name[k++] = c;
67 if (!strncmp(PATH_SEP, creature_ptr->name + i, strlen(PATH_SEP))) {
68 creature_ptr->base_name[k++] = '_';
69 i += strlen(PATH_SEP);
72 else if (angband_strchr("\"*,/:;<>?\\|", c))
73 creature_ptr->base_name[k++] = '_';
76 creature_ptr->base_name[k++] = c;
79 creature_ptr->base_name[k] = '\0';
80 if (!creature_ptr->base_name[0])
81 strcpy(creature_ptr->base_name, "PLAYER");
83 #ifdef SAVEFILE_MUTABLE
86 if (!savefile_base[0] && savefile[0]) {
90 t = angband_strstr(s, PATH_SEP);
96 strcpy(savefile_base, s);
99 if (!savefile_base[0] || !savefile[0])
104 strcpy(savefile_base, creature_ptr->base_name);
106 #ifdef SAVEFILE_USE_UID
107 /* Rename the savefile, using the creature_ptr->player_uid and creature_ptr->base_name */
108 (void)sprintf(temp, "%d.%s", creature_ptr->player_uid, creature_ptr->base_name);
110 /* Rename the savefile, using the creature_ptr->base_name */
111 (void)sprintf(temp, "%s", creature_ptr->base_name);
113 path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
116 if (current_world_ptr->character_generated && !streq(old_player_base, creature_ptr->base_name)) {
117 autopick_load_pref(creature_ptr, FALSE);
122 * @brief プレイヤーの名前を変更するコマンドのメインルーチン
123 * Gets a name for the character, reacting to name changes.
124 * @param creature_ptr プレーヤーへの参照ポインタ
128 * Assumes that "display_player()" has just been called
129 * Perhaps we should NOT ask for a name (at "birth()") on
130 * Unix machines? XXX XXX
131 * What a horrible name for a global function.
134 void get_name(player_type *creature_ptr)
137 strcpy(tmp, creature_ptr->name);
139 if (get_string(_("キャラクターの名前を入力して下さい: ", "Enter a name for your character: "), tmp, 15)) {
140 strcpy(creature_ptr->name, tmp);
143 if (strlen(creature_ptr->name) == 0) {
144 strcpy(creature_ptr->name, "PLAYER");
147 strcpy(tmp, ap_ptr->title);
154 strcat(tmp, creature_ptr->name);
156 term_erase(34, 1, 255);
157 c_put_str(TERM_L_BLUE, tmp, 1, 34);