From e2ab1c33527a2f0e7d57e5b7edb2d92d74190ff9 Mon Sep 17 00:00:00 2001 From: deskull Date: Mon, 1 Apr 2019 23:40:54 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#37353=20cnv=5Fstat()=20=E3=81=A8?= =?utf8?q?=20modify=5Fstat=5Fvalue()=20=E3=82=92=20player-status.c/h=20?= =?utf8?q?=E3=81=B8=E7=A7=BB=E5=8B=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/externs.h | 2 -- src/player-status.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/player-status.h | 4 +-- src/view-mainwindow.c | 86 -------------------------------------------------- 4 files changed, 89 insertions(+), 90 deletions(-) diff --git a/src/externs.h b/src/externs.h index d9f71f6c4..f8559e78e 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1038,8 +1038,6 @@ extern int inkey_special(bool numpad_cursor); /* xtra1.c */ -extern void cnv_stat(int val, char *out_val); -extern s16b modify_stat_value(int value, int amount); extern void prt_time(void); extern concptr map_name(void); extern int bow_tval_ammo(object_type *o_ptr); diff --git a/src/player-status.c b/src/player-status.c index a1a23cfe4..985463548 100644 --- a/src/player-status.c +++ b/src/player-status.c @@ -4513,3 +4513,90 @@ void check_experience(void) if (old_lev != p_ptr->lev) autopick_load_pref(FALSE); } +/*! + * @brief 現在の修正後能力値を3~17及び18/xxx形式に変換する / Converts stat num into a six-char (right justified) string + * @param val 能力値 + * @param out_val 出力先文字列ポインタ + * @return なし + */ +void cnv_stat(int val, char *out_val) +{ + /* Above 18 */ + if (val > 18) + { + int bonus = (val - 18); + + if (bonus >= 220) + { + sprintf(out_val, "18/%3s", "***"); + } + else if (bonus >= 100) + { + sprintf(out_val, "18/%03d", bonus); + } + else + { + sprintf(out_val, " 18/%02d", bonus); + } + } + + /* From 3 to 18 */ + else + { + sprintf(out_val, " %2d", val); + } +} + +/*! + * @brief 能力値現在値から3~17及び18/xxx様式に基づく加減算を行う。 + * Modify a stat value by a "modifier", return new value + * @param value 現在値 + * @param amount 加減算値 + * @return 加減算後の値 + * @details + *
+ * Stats go up: 3,4,...,17,18,18/10,18/20,...,18/220
+ * Or even: 18/13, 18/23, 18/33, ..., 18/220
+ * Stats go down: 18/220, 18/210,..., 18/10, 18, 17, ..., 3
+ * Or even: 18/13, 18/03, 18, 17, ..., 3
+ * 
+ */ +s16b modify_stat_value(int value, int amount) +{ + int i; + + /* Reward */ + if (amount > 0) + { + /* Apply each point */ + for (i = 0; i < amount; i++) + { + /* One point at a time */ + if (value < 18) value++; + + /* Ten "points" at a time */ + else value += 10; + } + } + + /* Penalty */ + else if (amount < 0) + { + /* Apply each point */ + for (i = 0; i < (0 - amount); i++) + { + /* Ten points at a time */ + if (value >= 18 + 10) value -= 10; + + /* Hack -- prevent weirdness */ + else if (value > 18) value = 18; + + /* One point at a time */ + else if (value > 3) value--; + } + } + + /* Return new value */ + return (s16b)(value); +} + diff --git a/src/player-status.h b/src/player-status.h index 70027e856..d105e906e 100644 --- a/src/player-status.h +++ b/src/player-status.h @@ -20,9 +20,9 @@ extern bool player_place(POSITION y, POSITION x); extern void sanity_blast(monster_type *m_ptr, bool necro); extern void check_experience(void); - - extern void wreck_the_pattern(void); +extern void cnv_stat(int val, char *out_val); +extern s16b modify_stat_value(int value, int amount); /* Temporary flags macro */ #define IS_FAST() (p_ptr->fast || music_singing(MUSIC_SPEED) || music_singing(MUSIC_SHERO)) diff --git a/src/view-mainwindow.c b/src/view-mainwindow.c index 770a5f46a..dcf7b2e6c 100644 --- a/src/view-mainwindow.c +++ b/src/view-mainwindow.c @@ -99,92 +99,6 @@ #define ROW_STATBAR (-1) #define COL_STATBAR 0 #define MAX_COL_STATBAR (-26) -/*! - * @brief 現在の修正後能力値を3~17及び18/xxx形式に変換する / Converts stat num into a six-char (right justified) string - * @param val 能力値 - * @param out_val 出力先文字列ポインタ - * @return なし - */ -void cnv_stat(int val, char *out_val) -{ - /* Above 18 */ - if (val > 18) - { - int bonus = (val - 18); - - if (bonus >= 220) - { - sprintf(out_val, "18/%3s", "***"); - } - else if (bonus >= 100) - { - sprintf(out_val, "18/%03d", bonus); - } - else - { - sprintf(out_val, " 18/%02d", bonus); - } - } - - /* From 3 to 18 */ - else - { - sprintf(out_val, " %2d", val); - } -} - -/*! - * @brief 能力値現在値から3~17及び18/xxx様式に基づく加減算を行う。 - * Modify a stat value by a "modifier", return new value - * @param value 現在値 - * @param amount 加減算値 - * @return 加減算後の値 - * @details - *
- * Stats go up: 3,4,...,17,18,18/10,18/20,...,18/220
- * Or even: 18/13, 18/23, 18/33, ..., 18/220
- * Stats go down: 18/220, 18/210,..., 18/10, 18, 17, ..., 3
- * Or even: 18/13, 18/03, 18, 17, ..., 3
- * 
- */ -s16b modify_stat_value(int value, int amount) -{ - int i; - - /* Reward */ - if (amount > 0) - { - /* Apply each point */ - for (i = 0; i < amount; i++) - { - /* One point at a time */ - if (value < 18) value++; - - /* Ten "points" at a time */ - else value += 10; - } - } - - /* Penalty */ - else if (amount < 0) - { - /* Apply each point */ - for (i = 0; i < (0 - amount); i++) - { - /* Ten points at a time */ - if (value >= 18+10) value -= 10; - - /* Hack -- prevent weirdness */ - else if (value > 18) value = 18; - - /* One point at a time */ - else if (value > 3) value--; - } - } - - /* Return new value */ - return (s16b)(value); -} -- 2.11.0