From 1a9733831aaea5676c39871ea03e5f47d546942d Mon Sep 17 00:00:00 2001 From: Hourier Date: Tue, 19 May 2020 20:50:21 +0900 Subject: [PATCH] [Refactor] #40392 Separated interpret_race_select_key_move() from get_player_race() --- src/birth/birth-select-personality.c | 12 +++++----- src/birth/birth-select-race.c | 45 ++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/birth/birth-select-personality.c b/src/birth/birth-select-personality.c index 4baa6112b..2374d1a0c 100644 --- a/src/birth/birth-select-personality.c +++ b/src/birth/birth-select-personality.c @@ -9,7 +9,7 @@ static void interpret_personality_select_key_move(player_type *creature_ptr, cha if (c == '8') { if (*cs >= 4) *cs -= 4; - if (*cs != MAX_SEIKAKU && seikaku_info[*cs].sex && (seikaku_info[*cs].sex != (creature_ptr->psex + 1))) { + if ((*cs != MAX_SEIKAKU) && seikaku_info[*cs].sex && (seikaku_info[*cs].sex != (creature_ptr->psex + 1))) { if ((*cs - 4) > 0) *cs -= 4; else @@ -19,8 +19,8 @@ static void interpret_personality_select_key_move(player_type *creature_ptr, cha if (c == '4') { if (*cs > 0) - *cs--; - if (*cs != MAX_SEIKAKU && seikaku_info[*cs].sex && (seikaku_info[*cs].sex != (creature_ptr->psex + 1))) { + (*cs)--; + if ((*cs != MAX_SEIKAKU) && seikaku_info[*cs].sex && (seikaku_info[*cs].sex != (creature_ptr->psex + 1))) { if ((*cs - 1) > 0) (*cs)--; else @@ -30,8 +30,8 @@ static void interpret_personality_select_key_move(player_type *creature_ptr, cha if (c == '6') { if (*cs < MAX_SEIKAKU) - *cs++; - if (*cs != MAX_SEIKAKU && seikaku_info[*cs].sex && (seikaku_info[*cs].sex != (creature_ptr->psex + 1))) { + (*cs)++; + if ((*cs != MAX_SEIKAKU) && seikaku_info[*cs].sex && (seikaku_info[*cs].sex != (creature_ptr->psex + 1))) { if ((*cs + 1) <= MAX_SEIKAKU) (*cs)++; else @@ -42,7 +42,7 @@ static void interpret_personality_select_key_move(player_type *creature_ptr, cha if (c == '2') { if ((*cs + 4) <= MAX_SEIKAKU) *cs += 4; - if (*cs != MAX_SEIKAKU && seikaku_info[*cs].sex && (seikaku_info[*cs].sex != (creature_ptr->psex + 1))) { + if ((*cs != MAX_SEIKAKU) && seikaku_info[*cs].sex && (seikaku_info[*cs].sex != (creature_ptr->psex + 1))) { if ((*cs + 4) <= MAX_SEIKAKU) *cs += 4; else diff --git a/src/birth/birth-select-race.c b/src/birth/birth-select-race.c index 535bebf20..f5b5ba5de 100644 --- a/src/birth/birth-select-race.c +++ b/src/birth/birth-select-race.c @@ -3,6 +3,29 @@ #include "term/gameterm.h" #include "birth/birth-util.h" +static void interpret_race_select_key_move(char c, int *cs) +{ + if (c == '8') { + if (*cs >= 5) + cs -= 5; + } + + if (c == '4') { + if (*cs > 0) + (*cs)--; + } + + if (c == '6') { + if (*cs < MAX_RACES) + (*cs)++; + } + + if (c == '2') { + if ((*cs + 5) <= MAX_RACES) + *cs += 5; + } +} + /*! * @brief プレイヤーの種族選択を行う / Player race * @return なし @@ -56,6 +79,7 @@ bool get_player_race(player_type *creature_ptr) rp_ptr->r_adj[4], rp_ptr->r_adj[5], (rp_ptr->r_exp - 100)); c_put_str(TERM_L_BLUE, buf, 5, 40); } + c_put_str(TERM_YELLOW, cur, 12 + (cs / 5), 1 + 16 * (cs % 5)); os = cs; } @@ -88,26 +112,7 @@ bool get_player_race(player_type *creature_ptr) continue; } - if (c == '8') { - if (cs >= 5) - cs -= 5; - } - - if (c == '4') { - if (cs > 0) - cs--; - } - - if (c == '6') { - if (cs < MAX_RACES) - cs++; - } - - if (c == '2') { - if ((cs + 5) <= MAX_RACES) - cs += 5; - } - + interpret_race_select_key_move(c, &cs); k = (islower(c) ? A2I(c) : -1); if ((k >= 0) && (k < MAX_RACES)) { cs = k; -- 2.11.0