From 3b3632a5bd2408e59268422e059e3e00973b99eb Mon Sep 17 00:00:00 2001 From: deskull Date: Thu, 20 Jun 2019 23:31:15 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#38997=20inc=5Fstat(),=20do=5Fres?= =?utf8?q?=5Fstat()=20=E3=81=AB=20player=5Ftype=20*=20=E5=BC=95=E6=95=B0?= =?utf8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=EF=BC=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/cmd-eat.c | 4 ++-- src/cmd-quaff.c | 12 ++++++------ src/cmd-usestaff.c | 2 +- src/player-effects.c | 27 +++++++++++++-------------- src/player-effects.h | 4 ++-- src/spells-status.c | 12 ++++++------ 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/cmd-eat.c b/src/cmd-eat.c index f65a1afb1..03b9f5250 100644 --- a/src/cmd-eat.c +++ b/src/cmd-eat.c @@ -218,13 +218,13 @@ void exe_eat_food(INVENTORY_IDX item) case SV_FOOD_RESTORE_STR: { - if (do_res_stat(A_STR)) ident = TRUE; + if (do_res_stat(p_ptr, A_STR)) ident = TRUE; break; } case SV_FOOD_RESTORE_CON: { - if (do_res_stat(A_CON)) ident = TRUE; + if (do_res_stat(p_ptr, A_CON)) ident = TRUE; break; } diff --git a/src/cmd-quaff.c b/src/cmd-quaff.c index ec0c638eb..a6e0b2e75 100644 --- a/src/cmd-quaff.c +++ b/src/cmd-quaff.c @@ -345,27 +345,27 @@ void exe_quaff_potion(INVENTORY_IDX item) break; case SV_POTION_RES_STR: - if (do_res_stat(A_STR)) ident = TRUE; + if (do_res_stat(p_ptr, A_STR)) ident = TRUE; break; case SV_POTION_RES_INT: - if (do_res_stat(A_INT)) ident = TRUE; + if (do_res_stat(p_ptr, A_INT)) ident = TRUE; break; case SV_POTION_RES_WIS: - if (do_res_stat(A_WIS)) ident = TRUE; + if (do_res_stat(p_ptr, A_WIS)) ident = TRUE; break; case SV_POTION_RES_DEX: - if (do_res_stat(A_DEX)) ident = TRUE; + if (do_res_stat(p_ptr, A_DEX)) ident = TRUE; break; case SV_POTION_RES_CON: - if (do_res_stat(A_CON)) ident = TRUE; + if (do_res_stat(p_ptr, A_CON)) ident = TRUE; break; case SV_POTION_RES_CHR: - if (do_res_stat(A_CHR)) ident = TRUE; + if (do_res_stat(p_ptr, A_CHR)) ident = TRUE; break; case SV_POTION_INC_STR: diff --git a/src/cmd-usestaff.c b/src/cmd-usestaff.c index 3eded5410..95dc6cc46 100644 --- a/src/cmd-usestaff.c +++ b/src/cmd-usestaff.c @@ -177,7 +177,7 @@ int staff_effect(OBJECT_SUBTYPE_VALUE sval, bool *use_charge, bool powerful, boo case SV_STAFF_THE_MAGI: { - if (do_res_stat(A_INT)) ident = TRUE; + if (do_res_stat(p_ptr, A_INT)) ident = TRUE; ident |= restore_mana(FALSE); if (set_shero(0, TRUE)) ident = TRUE; break; diff --git a/src/player-effects.c b/src/player-effects.c index b83a71a6c..98dba225d 100644 --- a/src/player-effects.c +++ b/src/player-effects.c @@ -3213,15 +3213,15 @@ bool set_food(TIME_EFFECT v) * Note that this function (used by stat potions) now restores\n * the stat BEFORE increasing it.\n */ -bool inc_stat(int stat) +bool inc_stat(player_type *creature_ptr, int stat) { BASE_STATUS value, gain; /* Then augment the current/max stat */ - value = p_ptr->stat_cur[stat]; + value = creature_ptr->stat_cur[stat]; /* Cannot go above 18/100 */ - if (value < p_ptr->stat_max_max[stat]) + if (value < creature_ptr->stat_max_max[stat]) { /* Gain one (sometimes two) points */ if (value < 18) @@ -3231,17 +3231,17 @@ bool inc_stat(int stat) } /* Gain 1/6 to 1/3 of distance to 18/100 */ - else if (value < (p_ptr->stat_max_max[stat]-2)) + else if (value < (creature_ptr->stat_max_max[stat]-2)) { /* Approximate gain value */ - gain = (((p_ptr->stat_max_max[stat]) - value) / 2 + 3) / 2; + gain = (((creature_ptr->stat_max_max[stat]) - value) / 2 + 3) / 2; if (gain < 1) gain = 1; /* Apply the bonus */ value += randint1(gain) + gain / 2; /* Maximal value */ - if (value > (p_ptr->stat_max_max[stat]-1)) value = p_ptr->stat_max_max[stat]-1; + if (value > (creature_ptr->stat_max_max[stat]-1)) value = creature_ptr->stat_max_max[stat]-1; } /* Gain one point at a time */ @@ -3251,14 +3251,14 @@ bool inc_stat(int stat) } /* Save the new value */ - p_ptr->stat_cur[stat] = value; + creature_ptr->stat_cur[stat] = value; /* Bring up the maximum too */ - if (value > p_ptr->stat_max[stat]) + if (value > creature_ptr->stat_max[stat]) { - p_ptr->stat_max[stat] = value; + creature_ptr->stat_max[stat] = value; } - p_ptr->update |= (PU_BONUS); + creature_ptr->update |= (PU_BONUS); /* Success */ return (TRUE); @@ -3554,13 +3554,12 @@ bool do_dec_stat(player_type *creature_ptr, int stat) /* * Restore lost "points" in a stat */ -bool do_res_stat(int stat) +bool do_res_stat(player_type *creature_ptr, int stat) { /* Attempt to increase */ - if (res_stat(p_ptr, stat)) + if (res_stat(creature_ptr, stat)) { msg_format(_("元通りに%sなった気がする。", "You feel less %s."), desc_stat_pos[stat]); - return (TRUE); } @@ -3580,7 +3579,7 @@ bool do_inc_stat(int stat) res = res_stat(p_ptr, stat); /* Attempt to increase */ - if (inc_stat(stat)) + if (inc_stat(p_ptr, stat)) { if (stat == A_WIS) { diff --git a/src/player-effects.h b/src/player-effects.h index 8e4ace383..2610a26b1 100644 --- a/src/player-effects.h +++ b/src/player-effects.h @@ -57,12 +57,12 @@ extern bool set_oppose_pois(TIME_EFFECT v, bool do_dec); extern bool set_stun(TIME_EFFECT v); extern bool set_cut(TIME_EFFECT v); extern bool set_food(TIME_EFFECT v); -extern bool inc_stat(int stat); +extern bool inc_stat(player_type *creature_ptr, int stat); extern bool dec_stat(player_type *creature_ptr, int stat, int amount, int permanent); extern bool res_stat(player_type *creature_ptr, int stat); extern bool hp_player(int num); extern bool do_dec_stat(player_type *creature_ptr, int stat); -extern bool do_res_stat(int stat); +extern bool do_res_stat(player_type *creature_ptr, int stat); extern bool do_inc_stat(int stat); extern bool restore_level(void); extern bool lose_all_info(void); diff --git a/src/spells-status.c b/src/spells-status.c index 6fed51fdb..ba37074ba 100644 --- a/src/spells-status.c +++ b/src/spells-status.c @@ -395,12 +395,12 @@ bool_hack restore_mana(bool_hack magic_eater) bool restore_all_status(void) { bool ident = FALSE; - if (do_res_stat(A_STR)) ident = TRUE; - if (do_res_stat(A_INT)) ident = TRUE; - if (do_res_stat(A_WIS)) ident = TRUE; - if (do_res_stat(A_DEX)) ident = TRUE; - if (do_res_stat(A_CON)) ident = TRUE; - if (do_res_stat(A_CHR)) ident = TRUE; + if (do_res_stat(p_ptr, A_STR)) ident = TRUE; + if (do_res_stat(p_ptr, A_INT)) ident = TRUE; + if (do_res_stat(p_ptr, A_WIS)) ident = TRUE; + if (do_res_stat(p_ptr, A_DEX)) ident = TRUE; + if (do_res_stat(p_ptr, A_CON)) ident = TRUE; + if (do_res_stat(p_ptr, A_CHR)) ident = TRUE; return ident; } -- 2.11.0