2 * @brief モンスターの攻撃に関する処理
7 #include "monster-attack/monster-attack-processor.h"
8 #include "dungeon/dungeon-flag-types.h"
9 #include "dungeon/dungeon.h"
10 #include "floor/cave.h"
11 #include "melee/monster-attack-monster.h"
12 #include "monster-attack/monster-attack-player.h"
13 #include "monster-race/monster-race.h"
14 #include "monster-race/race-flags1.h"
15 #include "monster-race/race-flags2.h"
16 #include "monster/monster-info.h"
17 #include "monster/monster-processor-util.h"
18 #include "monster/monster-status-setter.h"
19 #include "monster/monster-status.h"
20 #include "system/floor-type-definition.h"
21 #include "system/grid-type-definition.h"
22 #include "system/monster-race-definition.h"
23 #include "system/monster-type-definition.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 ny 移動後の、モンスターのY座標
33 * @param nx 移動後の、モンスターのX座標
35 * 反攻撃の洞窟など、直接攻撃ができない場所では処理をスキップする
37 void exe_monster_attack_to_player(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, POSITION ny, POSITION nx)
39 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
40 monster_race *r_ptr = &r_info[m_ptr->r_idx];
41 if (!turn_flags_ptr->do_move || !player_bold(player_ptr, ny, nx))
44 if (r_ptr->behavior_flags.has(MonsterBehaviorType::NEVER_BLOW)) {
45 if (is_original_ap_and_seen(player_ptr, m_ptr))
46 r_ptr->r_behavior_flags.set(MonsterBehaviorType::NEVER_BLOW);
48 turn_flags_ptr->do_move = false;
51 if (turn_flags_ptr->do_move && d_info[player_ptr->dungeon_idx].flags.has(DungeonFeatureType::NO_MELEE) && !monster_confused_remaining(m_ptr)) {
52 if (r_ptr->behavior_flags.has_not(MonsterBehaviorType::STUPID))
53 turn_flags_ptr->do_move = false;
54 else if (is_original_ap_and_seen(player_ptr, m_ptr))
55 r_ptr->r_behavior_flags.set(MonsterBehaviorType::STUPID);
58 if (!turn_flags_ptr->do_move)
61 if (!player_ptr->riding || one_in_(2)) {
62 MonsterAttackPlayer(player_ptr, m_idx).make_attack_normal();
63 turn_flags_ptr->do_move = false;
64 turn_flags_ptr->do_turn = true;
69 * @brief モンスターからモンスターへの直接攻撃を実行する
70 * @param player_ptr プレイヤーへの参照ポインタ
71 * @param m_idx モンスターID
72 * @param g_ptr グリッドへの参照ポインタ
74 static bool exe_monster_attack_to_monster(PlayerType *player_ptr, MONSTER_IDX m_idx, grid_type *g_ptr)
76 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
77 monster_race *r_ptr = &r_info[m_ptr->r_idx];
79 y_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
80 if (r_ptr->behavior_flags.has(MonsterBehaviorType::NEVER_BLOW))
83 if ((r_ptr->behavior_flags.has_not(MonsterBehaviorType::KILL_BODY)) && is_original_ap_and_seen(player_ptr, m_ptr))
84 r_ptr->r_behavior_flags.set(MonsterBehaviorType::KILL_BODY);
86 if ((y_ptr->r_idx == 0) || (y_ptr->hp < 0))
88 if (monst_attack_monst(player_ptr, m_idx, g_ptr->m_idx))
90 if (d_info[player_ptr->dungeon_idx].flags.has_not(DungeonFeatureType::NO_MELEE))
92 if (monster_confused_remaining(m_ptr))
94 if (r_ptr->behavior_flags.has_not(MonsterBehaviorType::STUPID))
97 if (is_original_ap_and_seen(player_ptr, m_ptr))
98 r_ptr->r_behavior_flags.set(MonsterBehaviorType::STUPID);
104 * @brief モンスターからモンスターへの攻撃処理
105 * @param player_ptr プレイヤーへの参照ポインタ
106 * @param turn_flags_ptr ターン経過処理フラグへの参照ポインタ
107 * @param m_idx モンスターID
108 * @param g_ptr グリッドへの参照ポインタ
109 * @param can_cross モンスターが地形を踏破できるならばTRUE
110 * @return ターン消費が発生したらTRUE
112 bool process_monster_attack_to_monster(PlayerType *player_ptr, turn_flags *turn_flags_ptr, MONSTER_IDX m_idx, grid_type *g_ptr, bool can_cross)
114 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
115 monster_race *r_ptr = &r_info[m_ptr->r_idx];
117 y_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
118 if (!turn_flags_ptr->do_move || (g_ptr->m_idx == 0))
121 monster_race *z_ptr = &r_info[y_ptr->r_idx];
122 turn_flags_ptr->do_move = false;
124 bool do_kill_body = r_ptr->behavior_flags.has(MonsterBehaviorType::KILL_BODY) && r_ptr->behavior_flags.has_not(MonsterBehaviorType::NEVER_BLOW);
125 do_kill_body &= (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level);
126 do_kill_body &= (g_ptr->m_idx != player_ptr->riding);
128 if (do_kill_body || are_enemies(player_ptr, m_ptr, y_ptr) || monster_confused_remaining(m_ptr)) {
129 return exe_monster_attack_to_monster(player_ptr, m_idx, g_ptr);
132 bool do_move_body = r_ptr->behavior_flags.has(MonsterBehaviorType::MOVE_BODY) && r_ptr->behavior_flags.has_not(MonsterBehaviorType::NEVER_MOVE);
133 do_move_body &= (r_ptr->mexp > z_ptr->mexp);
134 do_move_body &= can_cross;
135 do_move_body &= (g_ptr->m_idx != player_ptr->riding);
136 do_move_body &= monster_can_cross_terrain(player_ptr, player_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0);
139 turn_flags_ptr->do_move = true;
140 turn_flags_ptr->did_move_body = true;
141 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, 0);