From ed5340a2082d6688b29e55c06e3fc55173f3f4bf Mon Sep 17 00:00:00 2001 From: Hourier Date: Thu, 23 Jul 2020 21:15:27 +0900 Subject: [PATCH] [Refactor] #40020 Moved calc_lite_radius() from player-status.c to torch.c/h --- src/player/player-status.c | 70 +------------------------------ src/specific-object/torch.c | 100 ++++++++++++++++++++++++++++++++++++++++---- src/specific-object/torch.h | 1 + 3 files changed, 94 insertions(+), 77 deletions(-) diff --git a/src/player/player-status.c b/src/player/player-status.c index d55c26127..41ac5efa8 100644 --- a/src/player/player-status.c +++ b/src/player/player-status.c @@ -76,6 +76,7 @@ #include "realm/realm-names-table.h" #include "realm/realm-song-numbers.h" #include "specific-object/bow.h" +#include "specific-object/torch.h" #include "spell-realm/spells-hex.h" #include "spell/range-calc.h" #include "spell/spells-describer.h" @@ -2596,73 +2597,6 @@ static void calc_hitpoints(player_type *creature_ptr) } /*! - * @brief プレイヤーの光源半径を計算する / Extract and set the current "lite radius" - * @return なし - * @details - * SWD: Experimental modification: multiple light sources have additive effect. - */ -static void calc_torch(player_type *creature_ptr) -{ - creature_ptr->cur_lite = 0; - for (int i = INVEN_RARM; i < INVEN_TOTAL; i++) { - object_type *o_ptr; - o_ptr = &creature_ptr->inventory_list[i]; - if (!o_ptr->k_idx) - continue; - - if (o_ptr->name2 == EGO_LITE_SHINE) - creature_ptr->cur_lite++; - if (o_ptr->name2 != EGO_LITE_DARKNESS) { - if (o_ptr->tval == TV_LITE) { - if ((o_ptr->sval == SV_LITE_TORCH) && !(o_ptr->xtra4 > 0)) - continue; - if ((o_ptr->sval == SV_LITE_LANTERN) && !(o_ptr->xtra4 > 0)) - continue; - } - } - - BIT_FLAGS flgs[TR_FLAG_SIZE]; - object_flags(creature_ptr, o_ptr, flgs); - - POSITION rad = 0; - if (have_flag(flgs, TR_LITE_1) && o_ptr->name2 != EGO_LITE_DARKNESS) - rad += 1; - if (have_flag(flgs, TR_LITE_2) && o_ptr->name2 != EGO_LITE_DARKNESS) - rad += 2; - if (have_flag(flgs, TR_LITE_3) && o_ptr->name2 != EGO_LITE_DARKNESS) - rad += 3; - if (have_flag(flgs, TR_LITE_M1)) - rad -= 1; - if (have_flag(flgs, TR_LITE_M2)) - rad -= 2; - if (have_flag(flgs, TR_LITE_M3)) - rad -= 3; - creature_ptr->cur_lite += rad; - } - - if (d_info[creature_ptr->dungeon_idx].flags1 & DF1_DARKNESS && creature_ptr->cur_lite > 1) - creature_ptr->cur_lite = 1; - - if (creature_ptr->cur_lite <= 0 && creature_ptr->lite) - creature_ptr->cur_lite++; - - if (creature_ptr->cur_lite > 14) - creature_ptr->cur_lite = 14; - - if (creature_ptr->cur_lite < 0) - creature_ptr->cur_lite = 0; - - if (creature_ptr->old_lite == creature_ptr->cur_lite) - return; - - creature_ptr->update |= (PU_LITE | PU_MON_LITE | PU_MONSTERS); - creature_ptr->old_lite = creature_ptr->cur_lite; - - if ((creature_ptr->cur_lite > 0) && (creature_ptr->special_defense & NINJA_S_STEALTH)) - set_superstealth(creature_ptr, FALSE); -} - -/*! * @brief プレイヤーの現在学習可能な魔法数を計算し、増減に応じて魔法の忘却、再学習を処置する。 / * Calculate number of spells player should have, and forget, * or remember, spells until that number is properly reflected. @@ -3318,7 +3252,7 @@ void update_creature(player_type *creature_ptr) if (creature_ptr->update & (PU_TORCH)) { creature_ptr->update &= ~(PU_TORCH); - calc_torch(creature_ptr); + calc_lite_radius(creature_ptr); } if (creature_ptr->update & (PU_HP)) { diff --git a/src/specific-object/torch.c b/src/specific-object/torch.c index e1afa58d3..af1026516 100644 --- a/src/specific-object/torch.c +++ b/src/specific-object/torch.c @@ -1,6 +1,14 @@ #include "specific-object/torch.h" -#include "sv-definition/sv-lite-types.h" +#include "core/player-update-types.h" +#include "dungeon/dungeon-flag-types.h" +#include "dungeon/dungeon.h" +#include "inventory/inventory-slot-types.h" +#include "mind/mind-ninja.h" +#include "object-enchant/object-ego.h" #include "object-enchant/tr-types.h" +#include "object/object-flags.h" +#include "player/special-defense-types.h" +#include "sv-definition/sv-lite-types.h" #include "util/bit-flags-calculator.h" /*! @@ -12,10 +20,9 @@ */ void torch_flags(object_type *o_ptr, BIT_FLAGS *flgs) { - if ((o_ptr->tval != TV_LITE) || (o_ptr->sval != SV_LITE_TORCH)) - return; - if (o_ptr->xtra4 <= 0) + if ((o_ptr->tval != TV_LITE) || (o_ptr->sval != SV_LITE_TORCH) || (o_ptr->xtra4 <= 0)) return; + add_flag(flgs, TR_BRAND_FIRE); add_flag(flgs, TR_KILL_UNDEAD); add_flag(flgs, TR_THROW); @@ -31,12 +38,11 @@ void torch_flags(object_type *o_ptr, BIT_FLAGS *flgs) */ void torch_dice(object_type *o_ptr, DICE_NUMBER *dd, DICE_SID *ds) { - if ((o_ptr->tval != TV_LITE) || (o_ptr->sval != SV_LITE_TORCH)) - return; - if (o_ptr->xtra4 <= 0) + if ((o_ptr->tval != TV_LITE) || (o_ptr->sval != SV_LITE_TORCH) || (o_ptr->xtra4 <= 0)) return; - (*dd) = 1; - (*ds) = 6; + + *dd = 1; + *ds = 6; } /*! @@ -49,7 +55,83 @@ void torch_lost_fuel(object_type *o_ptr) { if ((o_ptr->tval != TV_LITE) || (o_ptr->sval != SV_LITE_TORCH)) return; + o_ptr->xtra4 -= (FUEL_TORCH / 25); if (o_ptr->xtra4 < 0) o_ptr->xtra4 = 0; } + +/*! + * @brief プレイヤーの光源半径を計算する / Extract and set the current "lite radius" + * @return なし + * @details + * SWD: Experimental modification: multiple light sources have additive effect. + */ +void calc_lite_radius(player_type *creature_ptr) +{ + creature_ptr->cur_lite = 0; + for (int i = INVEN_RARM; i < INVEN_TOTAL; i++) { + object_type *o_ptr; + o_ptr = &creature_ptr->inventory_list[i]; + if (!o_ptr->k_idx) + continue; + + if (o_ptr->name2 == EGO_LITE_SHINE) + creature_ptr->cur_lite++; + + if (o_ptr->name2 != EGO_LITE_DARKNESS) { + if (o_ptr->tval == TV_LITE) { + if ((o_ptr->sval == SV_LITE_TORCH) && !(o_ptr->xtra4 > 0)) + continue; + + if ((o_ptr->sval == SV_LITE_LANTERN) && !(o_ptr->xtra4 > 0)) + continue; + } + } + + BIT_FLAGS flgs[TR_FLAG_SIZE]; + object_flags(creature_ptr, o_ptr, flgs); + + POSITION rad = 0; + if (have_flag(flgs, TR_LITE_1) && o_ptr->name2 != EGO_LITE_DARKNESS) + rad += 1; + + if (have_flag(flgs, TR_LITE_2) && o_ptr->name2 != EGO_LITE_DARKNESS) + rad += 2; + + if (have_flag(flgs, TR_LITE_3) && o_ptr->name2 != EGO_LITE_DARKNESS) + rad += 3; + + if (have_flag(flgs, TR_LITE_M1)) + rad -= 1; + + if (have_flag(flgs, TR_LITE_M2)) + rad -= 2; + + if (have_flag(flgs, TR_LITE_M3)) + rad -= 3; + + creature_ptr->cur_lite += rad; + } + + if (d_info[creature_ptr->dungeon_idx].flags1 & DF1_DARKNESS && creature_ptr->cur_lite > 1) + creature_ptr->cur_lite = 1; + + if (creature_ptr->cur_lite <= 0 && creature_ptr->lite) + creature_ptr->cur_lite++; + + if (creature_ptr->cur_lite > 14) + creature_ptr->cur_lite = 14; + + if (creature_ptr->cur_lite < 0) + creature_ptr->cur_lite = 0; + + if (creature_ptr->old_lite == creature_ptr->cur_lite) + return; + + creature_ptr->update |= PU_LITE | PU_MON_LITE | PU_MONSTERS; + creature_ptr->old_lite = creature_ptr->cur_lite; + + if ((creature_ptr->cur_lite > 0) && (creature_ptr->special_defense & NINJA_S_STEALTH)) + set_superstealth(creature_ptr, FALSE); +} diff --git a/src/specific-object/torch.h b/src/specific-object/torch.h index 7239443f0..dada6bba5 100644 --- a/src/specific-object/torch.h +++ b/src/specific-object/torch.h @@ -6,3 +6,4 @@ void torch_flags(object_type *o_ptr, BIT_FLAGS *flgs); void torch_dice(object_type *o_ptr, DICE_NUMBER *dd, DICE_SID *ds); void torch_lost_fuel(object_type *o_ptr); +void calc_lite_radius(player_type *creature_ptr); -- 2.11.0