From 0cae5a1dbbf8a28659df09d074f38e6fac5541fd Mon Sep 17 00:00:00 2001 From: Hourier Date: Sun, 10 May 2020 21:09:27 +0900 Subject: [PATCH] [Refactor] #39970 Separated digestion-processor.c/h from core.c --- Hengband/Hengband/Hengband.vcxproj | 2 ++ Hengband/Hengband/Hengband.vcxproj.filters | 6 ++++ src/Makefile.am | 1 + src/core.c | 54 ++-------------------------- src/player/digestion-processor.c | 56 ++++++++++++++++++++++++++++++ src/player/digestion-processor.h | 3 ++ 6 files changed, 70 insertions(+), 52 deletions(-) create mode 100644 src/player/digestion-processor.c create mode 100644 src/player/digestion-processor.h diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index 2500f397b..787062bff 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -177,6 +177,7 @@ + @@ -381,6 +382,7 @@ + diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index 24fa6bd6a..fcc43cbfa 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -814,6 +814,9 @@ spell + + player + @@ -1661,6 +1664,9 @@ spell + + player + diff --git a/src/Makefile.am b/src/Makefile.am index 40ae8730b..f8c7c6686 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -68,6 +68,7 @@ hengband_SOURCES = \ player/race-resistances.c player/race-resistances.h \ player/permanent-resistances.c player/permanent-resistances.h \ player/temporary-resistances.c player/temporary-resistances.h \ + player/digestion-processor.c player/digestion-processor.h \ \ io/dump-remover.c io/dump-remover.h \ io/gf-descriptions.c io/gf-descriptions.h \ diff --git a/src/core.c b/src/core.c index dc69b9f59..ba6d1080f 100644 --- a/src/core.c +++ b/src/core.c @@ -21,7 +21,6 @@ #include "chuukei.h" #include "creature.h" - #include "birth/birth.h" #include "market/building.h" #include "io/write-diary.h" @@ -44,7 +43,6 @@ #include "player-class.h" #include "player-race.h" #include "player-personality.h" -#include "player-damage.h" #include "player-effects.h" #include "wild.h" #include "monster-process.h" @@ -76,6 +74,7 @@ #include "inventory/recharge-processor.h" #include "io/input-key-processor.h" #include "core/player-processor.h" +#include "player/digestion-processor.h" #include "cmd/cmd-save.h" #include "cmd/cmd-dump.h" @@ -112,55 +111,6 @@ concptr ANGBAND_GRAF = "ascii"; int init_flags; /*! - * @brief 10ゲームターンが進行するごとにプレイヤーの腹を減らす - * @param creature_ptr プレーヤーへの参照ポインタ - * @return なし - */ -static void process_world_aux_digestion(player_type *creature_ptr) -{ - if (creature_ptr->phase_out) return; - - if (creature_ptr->food >= PY_FOOD_MAX) - { - (void)set_food(creature_ptr, creature_ptr->food - 100); - } - else if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * 5))) - { - int digestion = SPEED_TO_ENERGY(creature_ptr->pspeed); - if (creature_ptr->regenerate) - digestion += 20; - if (creature_ptr->special_defense & (KAMAE_MASK | KATA_MASK)) - digestion += 20; - if (creature_ptr->cursed & TRC_FAST_DIGEST) - digestion += 30; - - if (creature_ptr->slow_digest) - digestion -= 5; - - if (digestion < 1) digestion = 1; - if (digestion > 100) digestion = 100; - - (void)set_food(creature_ptr, creature_ptr->food - digestion); - } - - if ((creature_ptr->food >= PY_FOOD_FAINT)) return; - - if (!creature_ptr->paralyzed && (randint0(100) < 10)) - { - msg_print(_("あまりにも空腹で気絶してしまった。", "You faint from the lack of food.")); - disturb(creature_ptr, TRUE, TRUE); - (void)set_paralyzed(creature_ptr, creature_ptr->paralyzed + 1 + randint0(5)); - } - - if (creature_ptr->food < PY_FOOD_STARVE) - { - HIT_POINT dam = (PY_FOOD_STARVE - creature_ptr->food) / 10; - if (!IS_INVULN(creature_ptr)) take_hit(creature_ptr, DAMAGE_LOSELIFE, dam, _("空腹", "starvation"), -1); - } -} - - -/*! * @brief 10ゲームターンが進行するごとに帰還や現実変容などの残り時間カウントダウンと発動を処理する。 * / Handle involuntary movement once every 10 game turns * @return なし @@ -510,7 +460,7 @@ static void process_world(player_type *player_ptr) } } - process_world_aux_digestion(player_ptr); + starve_player(player_ptr); process_player_hp_mp(player_ptr); reduce_magic_effects_timeout(player_ptr); reduce_lite_life(player_ptr); diff --git a/src/player/digestion-processor.c b/src/player/digestion-processor.c new file mode 100644 index 000000000..0db1bbff2 --- /dev/null +++ b/src/player/digestion-processor.c @@ -0,0 +1,56 @@ +#include "angband.h" +#include "player/digestion-processor.h" +#include "world.h" +#include "realm/realm-song.h" +#include "player-damage.h" +#include "player-effects.h" +#include "creature.h" +#include "player-move.h" + +/*! + * @brief 10ゲームターンが進行するごとにプレイヤーの腹を減らす + * @param creature_ptr プレーヤーへの参照ポインタ + * @return なし + */ +void starve_player(player_type* creature_ptr) +{ + if (creature_ptr->phase_out) + return; + + if (creature_ptr->food >= PY_FOOD_MAX) { + (void)set_food(creature_ptr, creature_ptr->food - 100); + } else if (!(current_world_ptr->game_turn % (TURNS_PER_TICK * 5))) { + int digestion = SPEED_TO_ENERGY(creature_ptr->pspeed); + if (creature_ptr->regenerate) + digestion += 20; + if (creature_ptr->special_defense & (KAMAE_MASK | KATA_MASK)) + digestion += 20; + if (creature_ptr->cursed & TRC_FAST_DIGEST) + digestion += 30; + + if (creature_ptr->slow_digest) + digestion -= 5; + + if (digestion < 1) + digestion = 1; + if (digestion > 100) + digestion = 100; + + (void)set_food(creature_ptr, creature_ptr->food - digestion); + } + + if ((creature_ptr->food >= PY_FOOD_FAINT)) + return; + + if (!creature_ptr->paralyzed && (randint0(100) < 10)) { + msg_print(_("あまりにも空腹で気絶してしまった。", "You faint from the lack of food.")); + disturb(creature_ptr, TRUE, TRUE); + (void)set_paralyzed(creature_ptr, creature_ptr->paralyzed + 1 + randint0(5)); + } + + if (creature_ptr->food < PY_FOOD_STARVE) { + HIT_POINT dam = (PY_FOOD_STARVE - creature_ptr->food) / 10; + if (!IS_INVULN(creature_ptr)) + take_hit(creature_ptr, DAMAGE_LOSELIFE, dam, _("空腹", "starvation"), -1); + } +} diff --git a/src/player/digestion-processor.h b/src/player/digestion-processor.h new file mode 100644 index 000000000..bf0b90e94 --- /dev/null +++ b/src/player/digestion-processor.h @@ -0,0 +1,3 @@ +#pragma once + +void starve_player(player_type* creature_ptr); -- 2.11.0