From 86210648748aba525b37d33623ede31e04676232 Mon Sep 17 00:00:00 2001 From: Hourier Date: Sun, 31 May 2020 20:59:07 +0900 Subject: [PATCH] Separated check_fall_off_horse() from monster-attack-player.c and process_fall_off_horse() from cmd-pet.c to pet-fall-off.c/h --- Hengband/Hengband/Hengband.vcxproj | 2 + Hengband/Hengband/Hengband.vcxproj.filters | 6 ++ src/Makefile.am | 1 + src/cmd/cmd-pet.c | 143 +------------------------- src/cmd/cmd-pet.h | 1 - src/combat/melee-postprocess.c | 2 +- src/combat/monster-attack-player.c | 18 +--- src/effect/effect-monster-domination.c | 16 ++- src/effect/effect-monster-domination.h | 3 + src/monster/monster-process.c | 2 +- src/monster/monster-runaway.c | 4 +- src/monster/monster1.c | 2 +- src/monster/monster2.c | 2 +- src/monster/pet-fall-off.c | 158 +++++++++++++++++++++++++++++ src/monster/pet-fall-off.h | 7 ++ src/spell/process-effect.c | 2 +- src/spell/spells2.c | 1 + 17 files changed, 195 insertions(+), 175 deletions(-) create mode 100644 src/monster/pet-fall-off.c create mode 100644 src/monster/pet-fall-off.h diff --git a/Hengband/Hengband/Hengband.vcxproj b/Hengband/Hengband/Hengband.vcxproj index 88a96b17b..4f5db611d 100644 --- a/Hengband/Hengband/Hengband.vcxproj +++ b/Hengband/Hengband/Hengband.vcxproj @@ -209,6 +209,7 @@ + @@ -486,6 +487,7 @@ + diff --git a/Hengband/Hengband/Hengband.vcxproj.filters b/Hengband/Hengband/Hengband.vcxproj.filters index d194795da..deb322cd2 100644 --- a/Hengband/Hengband/Hengband.vcxproj.filters +++ b/Hengband/Hengband/Hengband.vcxproj.filters @@ -1061,6 +1061,9 @@ combat + + monster + @@ -2272,6 +2275,9 @@ combat + + monster + diff --git a/src/Makefile.am b/src/Makefile.am index ef2a03404..9e79a1f80 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -186,6 +186,7 @@ hengband_SOURCES = \ monster/monster-status.c monster/monster-status.h \ monster/monster1.c monster/monster2.c \ monster/horror-descriptions.c monster/horror-descriptions.h \ + monster/pet-fall-off.c monster/pet-fall-off.h \ \ mutation/mutation.c mutation/mutation.h \ mutation/mutation-processor.c mutation/mutation-processor.h \ diff --git a/src/cmd/cmd-pet.c b/src/cmd/cmd-pet.c index 8a34a0b42..6f91bf424 100644 --- a/src/cmd/cmd-pet.c +++ b/src/cmd/cmd-pet.c @@ -15,8 +15,8 @@ #include "object/object-hook.h" #include "monster/monster.h" #include "monster/monster-status.h" -#include "cmd-pet.h" -#include "cmd-basic.h" +#include "cmd/cmd-pet.h" +#include "cmd/cmd-basic.h" #include "view/display-main-window.h" #include "io/targeting.h" #include "world/world.h" @@ -902,142 +902,3 @@ void do_cmd_pet(player_type *creature_ptr) } } } - - -/*! -* @brief プレイヤーの落馬判定処理 -* @param dam 落馬判定を発した際に受けたダメージ量 -* @param force TRUEならば強制的に落馬する -* @return 実際に落馬したらTRUEを返す -*/ -bool process_fall_off_horse(player_type *creature_ptr, HIT_POINT dam, bool force) -{ - DIRECTION i; - POSITION y, x, oy, ox, sy = 0, sx = 0; - int sn = 0; - GAME_TEXT m_name[MAX_NLEN]; - monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding]; - monster_race *r_ptr = &r_info[m_ptr->r_idx]; - bool fall_dam = FALSE; - - if (!creature_ptr->riding) return FALSE; - if (creature_ptr->wild_mode) return FALSE; - - if (dam >= 0 || force) - { - if (!force) - { - int cur = creature_ptr->skill_exp[GINOU_RIDING]; - int max = s_info[creature_ptr->pclass].s_max[GINOU_RIDING]; - int ridinglevel = r_ptr->level; - - /* 落馬のしやすさ */ - int rakubalevel = r_ptr->level; - if (creature_ptr->riding_ryoute) rakubalevel += 20; - - if ((cur < max) && (max > 1000) && - (dam / 2 + ridinglevel) > (cur / 30 + 10)) - { - int inc = 0; - - if (ridinglevel > (cur / 100 + 15)) - inc += 1 + (ridinglevel - cur / 100 - 15); - else - inc += 1; - - creature_ptr->skill_exp[GINOU_RIDING] = MIN(max, cur + inc); - } - - /* レベルの低い乗馬からは落馬しにくい */ - if (randint0(dam / 2 + rakubalevel * 2) < cur / 30 + 10) - { - if ((((creature_ptr->pclass == CLASS_BEASTMASTER) || (creature_ptr->pclass == CLASS_CAVALRY)) && !creature_ptr->riding_ryoute) || !one_in_(creature_ptr->lev*(creature_ptr->riding_ryoute ? 2 : 3) + 30)) - { - return FALSE; - } - } - } - - /* Check around the player */ - for (i = 0; i < 8; i++) - { - grid_type *g_ptr; - - y = creature_ptr->y + ddy_ddd[i]; - x = creature_ptr->x + ddx_ddd[i]; - - g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x]; - - if (g_ptr->m_idx) continue; - - /* Skip non-empty grids */ - if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !cave_have_flag_grid(g_ptr, FF_CAN_FLY)) - { - if (!player_can_ride_aux(creature_ptr, g_ptr, FALSE)) continue; - } - - if (cave_have_flag_grid(g_ptr, FF_PATTERN)) continue; - - /* Count "safe" grids */ - sn++; - - /* Randomize choice */ - if (randint0(sn) > 0) continue; - - /* Save the safe location */ - sy = y; sx = x; - } - if (!sn) - { - monster_desc(creature_ptr, m_name, m_ptr, 0); - msg_format(_("%sから振り落とされそうになって、壁にぶつかった。", "You have nearly fallen from %s, but bumped into wall."), m_name); - take_hit(creature_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("壁への衝突", "bumping into wall"), -1); - return FALSE; - } - - oy = creature_ptr->y; - ox = creature_ptr->x; - - creature_ptr->y = sy; - creature_ptr->x = sx; - - /* Redraw the old spot */ - lite_spot(creature_ptr, oy, ox); - - /* Redraw the new spot */ - lite_spot(creature_ptr, creature_ptr->y, creature_ptr->x); - - /* Check for new panel */ - verify_panel(creature_ptr); - } - - creature_ptr->riding = 0; - creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS); - creature_ptr->riding_ryoute = creature_ptr->old_riding_ryoute = FALSE; - - creature_ptr->update |= (PU_BONUS | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS); - handle_stuff(creature_ptr); - - - creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON); - creature_ptr->redraw |= (PR_EXTRA); - - /* Update health track of mount */ - creature_ptr->redraw |= (PR_UHEALTH); - - if (creature_ptr->levitation && !force) - { - monster_desc(creature_ptr, m_name, m_ptr, 0); - msg_format(_("%sから落ちたが、空中でうまく体勢を立て直して着地した。", "You are thrown from %s, but make a good landing."), m_name); - } - else - { - take_hit(creature_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("落馬", "Falling from riding"), -1); - fall_dam = TRUE; - } - - if (sy && !creature_ptr->is_dead) - (void)move_player_effect(creature_ptr, creature_ptr->y, creature_ptr->x, MPE_DONT_PICKUP | MPE_DONT_SWAP_MON); - - return fall_dam; -} diff --git a/src/cmd/cmd-pet.h b/src/cmd/cmd-pet.h index b870bd79e..3aeae0d1b 100644 --- a/src/cmd/cmd-pet.h +++ b/src/cmd/cmd-pet.h @@ -6,7 +6,6 @@ extern bool do_cmd_riding(player_type *creature_ptr, bool force); extern void do_cmd_pet_dismiss(player_type *creature_pt); extern void do_cmd_pet(player_type *creature_ptr); extern bool player_can_ride_aux(player_type *creature_ptr, grid_type *g_ptr, bool now_riding); -extern bool process_fall_off_horse(player_type *creature_ptr, HIT_POINT dam, bool force); extern int total_friends; diff --git a/src/combat/melee-postprocess.c b/src/combat/melee-postprocess.c index ac92f4181..c0af6a8eb 100644 --- a/src/combat/melee-postprocess.c +++ b/src/combat/melee-postprocess.c @@ -11,13 +11,13 @@ */ #include "combat/melee-postprocess.h" -#include "cmd-pet.h" #include "combat/monster-attack-types.h" #include "grid/grid.h" #include "main/sound-definitions-table.h" #include "monster/monster-race-hook.h" #include "monster/monster-status.h" #include "monster/monster.h" +#include "monster/pet-fall-off.h" #include "mspell/monster-spell.h" #include "player/player-class.h" #include "player/player-move.h" diff --git a/src/combat/monster-attack-player.c b/src/combat/monster-attack-player.c index 609f82dc6..db7198c44 100644 --- a/src/combat/monster-attack-player.c +++ b/src/combat/monster-attack-player.c @@ -21,6 +21,7 @@ #include "main/sound-definitions-table.h" #include "mind/racial-samurai.h" #include "monster/monster-status.h" +#include "monster/pet-fall-off.h" #include "object/object-hook.h" #include "player/player-damage.h" #include "player/player-effects.h" @@ -349,23 +350,6 @@ static void increase_blow_type_seen(player_type *target_ptr, monap_type *monap_p r_ptr->r_blows[monap_ptr->ap_cnt]++; } -/*! - * @brief モンスターから直接攻撃を受けた時に落馬するかどうかを判定し、判定アウトならば落馬させる - * @param target_ptr プレーヤーへの参照ポインタ - * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ - * @return なし - */ -static void check_fall_off_horse(player_type *target_ptr, monap_type *monap_ptr) -{ - if ((target_ptr->riding == 0) || (monap_ptr->damage == 0)) - return; - - char m_steed_name[MAX_NLEN]; - monster_desc(target_ptr, m_steed_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0); - if (process_fall_off_horse(target_ptr, (monap_ptr->damage > 200) ? 200 : monap_ptr->damage, FALSE)) - msg_format(_("%^sから落ちてしまった!", "You have fallen from %s."), m_steed_name); -} - static bool process_monster_blows(player_type *target_ptr, monap_type *monap_ptr) { monster_race *r_ptr = &r_info[monap_ptr->m_ptr->r_idx]; diff --git a/src/effect/effect-monster-domination.c b/src/effect/effect-monster-domination.c index ef8b4dca0..d5878a5c2 100644 --- a/src/effect/effect-monster-domination.c +++ b/src/effect/effect-monster-domination.c @@ -1,15 +1,13 @@ -#include "system/angband.h" -#include "effect/effect-monster-util.h" -#include "effect/effect-monster-domination.h" -#include "floor/floor.h" -#include "player/player-effects.h" -#include "spell/spells-diceroll.h" -#include "monster/monster-status.h" -#include "effect/spells-effect-util.h" -#include "cmd/cmd-pet.h" // 暫定、後で消すかも. +#include "effect/effect-monster-domination.h" #include "dungeon/quest.h" +#include "effect/spells-effect-util.h" +#include "floor/floor.h" #include "monster/monster-race-hook.h" +#include "monster/monster-status.h" +#include "monster/pet-fall-off.h" #include "object/trc-types.h" +#include "player/player-effects.h" +#include "spell/spells-diceroll.h" static void effect_monster_domination_corrupted_addition(player_type *caster_ptr, effect_monster_type *em_ptr) { diff --git a/src/effect/effect-monster-domination.h b/src/effect/effect-monster-domination.h index b723597d7..e1c3f4fc6 100644 --- a/src/effect/effect-monster-domination.h +++ b/src/effect/effect-monster-domination.h @@ -1,5 +1,8 @@ #pragma once +#include "system/angband.h" +#include "effect/effect-monster-util.h" + gf_switch_result effect_monster_domination(player_type *caster_ptr, effect_monster_type *em_ptr); gf_switch_result effect_monster_crusade(player_type *caster_ptr, effect_monster_type *em_ptr); gf_switch_result effect_monster_capture(player_type *caster_ptr, effect_monster_type *em_ptr); diff --git a/src/monster/monster-process.c b/src/monster/monster-process.c index 4031f4dde..8f0b163d1 100644 --- a/src/monster/monster-process.c +++ b/src/monster/monster-process.c @@ -24,7 +24,7 @@ #include "io/write-diary.h" #include "cmd/cmd-dump.h" -#include "cmd/cmd-pet.h" +#include "monster/pet-fall-off.h" #include "monster/creature.h" #include "combat/melee-postprocess.h" #include "spell/spells-summon.h" diff --git a/src/monster/monster-runaway.c b/src/monster/monster-runaway.c index 7d9ab90c8..9b6888958 100644 --- a/src/monster/monster-runaway.c +++ b/src/monster/monster-runaway.c @@ -5,9 +5,9 @@ */ #include "monster/monster-runaway.h" -#include "player/player-move.h" -#include "cmd/cmd-pet.h" #include "dungeon/quest.h" +#include "monster/pet-fall-off.h" +#include "player/player-move.h" /*! * @brief HPが1/3未満になった有効的なユニークモンスターの逃走処理を行う diff --git a/src/monster/monster1.c b/src/monster/monster1.c index cda6e55c9..8da4a4b56 100644 --- a/src/monster/monster1.c +++ b/src/monster/monster1.c @@ -18,7 +18,7 @@ #include "io/write-diary.h" #include "cmd/cmd-dump.h" #include "cmd/cmd-building.h" -#include "cmd-pet.h" +#include "monster/pet-fall-off.h" #include "effect/effect-characteristics.h" #include "object/object-kind-hook.h" #include "player/player-personalities-table.h" diff --git a/src/monster/monster2.c b/src/monster/monster2.c index 371185423..5e39128b1 100644 --- a/src/monster/monster2.c +++ b/src/monster/monster2.c @@ -17,7 +17,7 @@ #include "io/write-diary.h" #include "cmd/cmd-dump.h" -#include "cmd-pet.h" +#include "monster/pet-fall-off.h" #include "dungeon/dungeon.h" #include "effect/effect-characteristics.h" #include "object/object2.h" diff --git a/src/monster/pet-fall-off.c b/src/monster/pet-fall-off.c new file mode 100644 index 000000000..612db8196 --- /dev/null +++ b/src/monster/pet-fall-off.c @@ -0,0 +1,158 @@ +#include "monster/pet-fall-off.h" +#include "cmd/cmd-pet.h" // 暫定、定数を見ているだけなのでutilへの分離を検討する. +#include "floor/floor.h" +#include "io/targeting.h" +#include "player/player-damage.h" +#include "player/player-move.h" +#include "player/player-skill.h" + +/*! + * @brief モンスターから直接攻撃を受けた時に落馬するかどうかを判定し、判定アウトならば落馬させる + * @param target_ptr プレーヤーへの参照ポインタ + * @param monap_ptr モンスターからプレーヤーへの直接攻撃構造体への参照ポインタ + * @return なし + */ +void check_fall_off_horse(player_type *target_ptr, monap_type *monap_ptr) +{ + if ((target_ptr->riding == 0) || (monap_ptr->damage == 0)) + return; + + char m_steed_name[MAX_NLEN]; + monster_desc(target_ptr, m_steed_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0); + if (process_fall_off_horse(target_ptr, (monap_ptr->damage > 200) ? 200 : monap_ptr->damage, FALSE)) + msg_format(_("%^sから落ちてしまった!", "You have fallen from %s."), m_steed_name); +} + +/*! + * @brief プレイヤーの落馬判定処理 + * @param dam 落馬判定を発した際に受けたダメージ量 + * @param force TRUEならば強制的に落馬する + * @return 実際に落馬したらTRUEを返す + */ +bool process_fall_off_horse(player_type *creature_ptr, HIT_POINT dam, bool force) +{ + DIRECTION i; + POSITION y, x, oy, ox, sy = 0, sx = 0; + int sn = 0; + GAME_TEXT m_name[MAX_NLEN]; + monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding]; + monster_race *r_ptr = &r_info[m_ptr->r_idx]; + bool fall_dam = FALSE; + + if (!creature_ptr->riding) + return FALSE; + if (creature_ptr->wild_mode) + return FALSE; + + if (dam >= 0 || force) { + if (!force) { + int cur = creature_ptr->skill_exp[GINOU_RIDING]; + int max = s_info[creature_ptr->pclass].s_max[GINOU_RIDING]; + int ridinglevel = r_ptr->level; + + /* 落馬のしやすさ */ + int rakubalevel = r_ptr->level; + if (creature_ptr->riding_ryoute) + rakubalevel += 20; + + if ((cur < max) && (max > 1000) && (dam / 2 + ridinglevel) > (cur / 30 + 10)) { + int inc = 0; + + if (ridinglevel > (cur / 100 + 15)) + inc += 1 + (ridinglevel - cur / 100 - 15); + else + inc += 1; + + creature_ptr->skill_exp[GINOU_RIDING] = MIN(max, cur + inc); + } + + /* レベルの低い乗馬からは落馬しにくい */ + if (randint0(dam / 2 + rakubalevel * 2) < cur / 30 + 10) { + if ((((creature_ptr->pclass == CLASS_BEASTMASTER) || (creature_ptr->pclass == CLASS_CAVALRY)) && !creature_ptr->riding_ryoute) + || !one_in_(creature_ptr->lev * (creature_ptr->riding_ryoute ? 2 : 3) + 30)) { + return FALSE; + } + } + } + + /* Check around the player */ + for (i = 0; i < 8; i++) { + grid_type *g_ptr; + + y = creature_ptr->y + ddy_ddd[i]; + x = creature_ptr->x + ddx_ddd[i]; + + g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x]; + + if (g_ptr->m_idx) + continue; + + /* Skip non-empty grids */ + if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !cave_have_flag_grid(g_ptr, FF_CAN_FLY)) { + if (!player_can_ride_aux(creature_ptr, g_ptr, FALSE)) + continue; + } + + if (cave_have_flag_grid(g_ptr, FF_PATTERN)) + continue; + + /* Count "safe" grids */ + sn++; + + /* Randomize choice */ + if (randint0(sn) > 0) + continue; + + /* Save the safe location */ + sy = y; + sx = x; + } + if (!sn) { + monster_desc(creature_ptr, m_name, m_ptr, 0); + msg_format(_("%sから振り落とされそうになって、壁にぶつかった。", "You have nearly fallen from %s, but bumped into wall."), m_name); + take_hit(creature_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("壁への衝突", "bumping into wall"), -1); + return FALSE; + } + + oy = creature_ptr->y; + ox = creature_ptr->x; + + creature_ptr->y = sy; + creature_ptr->x = sx; + + /* Redraw the old spot */ + lite_spot(creature_ptr, oy, ox); + + /* Redraw the new spot */ + lite_spot(creature_ptr, creature_ptr->y, creature_ptr->x); + + /* Check for new panel */ + verify_panel(creature_ptr); + } + + creature_ptr->riding = 0; + creature_ptr->pet_extra_flags &= ~(PF_TWO_HANDS); + creature_ptr->riding_ryoute = creature_ptr->old_riding_ryoute = FALSE; + + creature_ptr->update |= (PU_BONUS | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS); + handle_stuff(creature_ptr); + + creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON); + creature_ptr->redraw |= (PR_EXTRA); + + /* Update health track of mount */ + creature_ptr->redraw |= (PR_UHEALTH); + + if (creature_ptr->levitation && !force) { + monster_desc(creature_ptr, m_name, m_ptr, 0); + msg_format(_("%sから落ちたが、空中でうまく体勢を立て直して着地した。", "You are thrown from %s, but make a good landing."), m_name); + } else { + take_hit(creature_ptr, DAMAGE_NOESCAPE, r_ptr->level + 3, _("落馬", "Falling from riding"), -1); + fall_dam = TRUE; + } + + if (sy && !creature_ptr->is_dead) + (void)move_player_effect(creature_ptr, creature_ptr->y, creature_ptr->x, MPE_DONT_PICKUP | MPE_DONT_SWAP_MON); + + return fall_dam; +} diff --git a/src/monster/pet-fall-off.h b/src/monster/pet-fall-off.h new file mode 100644 index 000000000..45362e096 --- /dev/null +++ b/src/monster/pet-fall-off.h @@ -0,0 +1,7 @@ +#pragma once + +#include "system/angband.h" +#include "combat/monster-attack-util.h" + +void check_fall_off_horse(player_type *target_ptr, monap_type *monap_ptr); +bool process_fall_off_horse(player_type *creature_ptr, HIT_POINT dam, bool force); diff --git a/src/spell/process-effect.c b/src/spell/process-effect.c index 2510e1375..90c923472 100644 --- a/src/spell/process-effect.c +++ b/src/spell/process-effect.c @@ -2,7 +2,7 @@ #include "effect/spells-effect-util.h" #include "spell/process-effect.h" #include "floor/floor.h" -#include "cmd-pet.h" // 暫定、後で消すかも. +#include "monster/pet-fall-off.h" #include "core/stuff-handler.h" #include "effect/effect-feature.h" #include "effect/effect-item.h" diff --git a/src/spell/spells2.c b/src/spell/spells2.c index c76aec1a0..59be05157 100644 --- a/src/spell/spells2.c +++ b/src/spell/spells2.c @@ -22,6 +22,7 @@ #include "object/artifact.h" #include "io/write-diary.h" #include "cmd/cmd-pet.h" +#include "monster/pet-fall-off.h" #include "cmd/cmd-dump.h" #include "effect/effect-characteristics.h" #include "grid/grid.h" -- 2.11.0