2 * @brief モンスターの攻撃に関する処理
7 #include "monster-attack/monster-attack-processor.h"
8 #include "dungeon/dungeon-flag-types.h"
9 #include "floor/cave.h"
10 #include "melee/monster-attack-monster.h"
11 #include "monster-attack/monster-attack-player.h"
12 #include "monster-race/monster-race.h"
13 #include "monster-race/race-flags1.h"
14 #include "monster-race/race-flags2.h"
15 #include "monster/monster-info.h"
16 #include "monster/monster-processor-util.h"
17 #include "monster/monster-status-setter.h"
18 #include "monster/monster-status.h"
19 #include "system/dungeon-info.h"
20 #include "system/floor-type-definition.h"
21 #include "system/grid-type-definition.h"
22 #include "system/monster-entity.h"
23 #include "system/monster-race-info.h"
24 #include "system/player-type-definition.h"
25 #include "util/bit-flags-calculator.h"
28 * @brief モンスターが移動した結果、そこにプレイヤーがいたら直接攻撃を行う
29 * @param player_ptr プレイヤーへの参照ポインタ
30 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
31 * @param m_idx モンスターID
32 * @param pos モンスターの移動先座標
34 * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
36 void exe_monster_attack_to_player(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, const Pos2D &pos)
38 auto &floor = *player_ptr->current_floor_ptr;
39 auto *m_ptr = &floor.m_list[m_idx];
40 auto *r_ptr = &m_ptr->get_monrace();
41 if (!turn_flags_ptr->do_move || !player_ptr->is_located_at(pos)) {
45 if (r_ptr->behavior_flags.has(MonsterBehaviorType::NEVER_BLOW)) {
46 if (is_original_ap_and_seen(player_ptr, m_ptr)) {
47 r_ptr->r_behavior_flags.set(MonsterBehaviorType::NEVER_BLOW);
50 turn_flags_ptr->do_move = false;
53 if (turn_flags_ptr->do_move && floor.get_dungeon_definition().flags.has(DungeonFeatureType::NO_MELEE) && !m_ptr->is_confused()) {
54 if (r_ptr->behavior_flags.has_not(MonsterBehaviorType::STUPID)) {
55 turn_flags_ptr->do_move = false;
56 } else if (is_original_ap_and_seen(player_ptr, m_ptr)) {
57 r_ptr->r_behavior_flags.set(MonsterBehaviorType::STUPID);
61 if (!turn_flags_ptr->do_move) {
65 if (!player_ptr->riding || one_in_(2)) {
66 MonsterAttackPlayer(player_ptr, m_idx).make_attack_normal();
67 turn_flags_ptr->do_move = false;
68 turn_flags_ptr->do_turn = true;
73 * @brief モンスターからモンスターへの直接攻撃を実行する
74 * @param player_ptr プレイヤーへの参照ポインタ
75 * @param m_idx モンスターID
76 * @param g_ptr グリッドへの参照ポインタ
78 static bool exe_monster_attack_to_monster(PlayerType *player_ptr, MONSTER_IDX m_idx, Grid *g_ptr)
80 auto &floor = *player_ptr->current_floor_ptr;
81 auto *m_ptr = &floor.m_list[m_idx];
82 auto *r_ptr = &m_ptr->get_monrace();
84 y_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
85 if (r_ptr->behavior_flags.has(MonsterBehaviorType::NEVER_BLOW)) {
89 if ((r_ptr->behavior_flags.has_not(MonsterBehaviorType::KILL_BODY)) && is_original_ap_and_seen(player_ptr, m_ptr)) {
90 r_ptr->r_behavior_flags.set(MonsterBehaviorType::KILL_BODY);
93 if (!MonsterRace(y_ptr->r_idx).is_valid() || (y_ptr->hp < 0)) {
96 if (monst_attack_monst(player_ptr, m_idx, g_ptr->m_idx)) {
99 if (floor.get_dungeon_definition().flags.has_not(DungeonFeatureType::NO_MELEE)) {
102 if (m_ptr->is_confused()) {
105 if (r_ptr->behavior_flags.has_not(MonsterBehaviorType::STUPID)) {
109 if (is_original_ap_and_seen(player_ptr, m_ptr)) {
110 r_ptr->r_behavior_flags.set(MonsterBehaviorType::STUPID);
117 * @brief モンスターからモンスターへの攻撃処理
118 * @param player_ptr プレイヤーへの参照ポインタ
119 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
120 * @param m_idx モンスターID
121 * @param g_ptr グリッドへの参照ポインタ
122 * @param can_cross モンスターが地形を踏破できるならばTRUE
123 * @return ターン消費が発生したらTRUE
125 bool process_monster_attack_to_monster(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, Grid *g_ptr, bool can_cross)
127 if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0)) {
131 turn_flags_ptr->do_move = false;
132 const auto &monster_from = player_ptr->current_floor_ptr->m_list[m_idx];
133 const auto &monrace_from = monster_from.get_monrace();
134 const auto &monster_to = player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
135 const auto &monrace_to = monster_to.get_monrace();
136 auto do_kill_body = monrace_from.behavior_flags.has(MonsterBehaviorType::KILL_BODY) && monrace_from.behavior_flags.has_not(MonsterBehaviorType::NEVER_BLOW);
137 do_kill_body &= (monrace_from.mexp * monrace_from.level > monrace_to.mexp * monrace_to.level);
138 do_kill_body &= (g_ptr->m_idx != player_ptr->riding);
139 if (do_kill_body || monster_from.is_hostile_to_melee(monster_to) || monster_from.is_confused()) {
140 return exe_monster_attack_to_monster(player_ptr, m_idx, g_ptr);
143 auto do_move_body = monrace_from.behavior_flags.has(MonsterBehaviorType::MOVE_BODY) && monrace_from.behavior_flags.has_not(MonsterBehaviorType::NEVER_MOVE);
144 do_move_body &= (monrace_from.mexp > monrace_to.mexp);
145 do_move_body &= can_cross;
146 do_move_body &= (g_ptr->m_idx != player_ptr->riding);
147 do_move_body &= monster_can_cross_terrain(player_ptr, player_ptr->current_floor_ptr->grid_array[monster_from.fy][monster_from.fx].feat, &monrace_to, 0);
149 turn_flags_ptr->do_move = true;
150 turn_flags_ptr->did_move_body = true;
151 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, 0);