#include "mspell/mspell-judgement.h"
#include "mspell/mspell-util.h"
#include "pet/pet-util.h"
+#include "player-base/player-class.h"
#include "spell-kind/spells-world.h"
#include "system/floor-type-definition.h"
#include "system/grid-type-definition.h"
#include "system/monster-type-definition.h"
#include "system/player-type-definition.h"
#include "target/projection-path-calculator.h"
+#include "util/bit-flags-calculator.h"
#include <iterator>
static void decide_melee_spell_target(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if ((player_ptr->pet_t_m_idx == 0) || !ms_ptr->pet)
+ if ((player_ptr->pet_t_m_idx == 0) || !ms_ptr->pet) {
return;
+ }
ms_ptr->target_idx = player_ptr->pet_t_m_idx;
ms_ptr->t_ptr = &player_ptr->current_floor_ptr->m_list[ms_ptr->target_idx];
- if ((ms_ptr->m_idx == ms_ptr->target_idx) || !projectable(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx))
+ if ((ms_ptr->m_idx == ms_ptr->target_idx) || !projectable(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx)) {
ms_ptr->target_idx = 0;
+ }
}
static void decide_indirection_melee_spell(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if ((ms_ptr->target_idx != 0) || (ms_ptr->m_ptr->target_y == 0))
+ if ((ms_ptr->target_idx != 0) || (ms_ptr->m_ptr->target_y == 0)) {
return;
+ }
- floor_type *floor_ptr = player_ptr->current_floor_ptr;
+ auto *floor_ptr = player_ptr->current_floor_ptr;
ms_ptr->target_idx = floor_ptr->grid_array[ms_ptr->m_ptr->target_y][ms_ptr->m_ptr->target_x].m_idx;
- if (ms_ptr->target_idx == 0)
+ if (ms_ptr->target_idx == 0) {
return;
+ }
ms_ptr->t_ptr = &floor_ptr->m_list[ms_ptr->target_idx];
if ((ms_ptr->m_idx == ms_ptr->target_idx) || ((ms_ptr->target_idx != player_ptr->pet_t_m_idx) && !are_enemies(player_ptr, ms_ptr->m_ptr, ms_ptr->t_ptr))) {
return;
}
- if (projectable(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx))
+ if (projectable(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx)) {
return;
+ }
ms_ptr->ability_flags &= RF_ABILITY_INDIRECT_MASK;
}
static bool check_melee_spell_projection(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->target_idx != 0)
+ if (ms_ptr->target_idx != 0) {
return true;
+ }
int start;
int plus = 1;
- floor_type *floor_ptr = player_ptr->current_floor_ptr;
+ auto *floor_ptr = player_ptr->current_floor_ptr;
if (player_ptr->phase_out) {
start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
- if (randint0(2))
+ if (randint0(2)) {
plus = -1;
- } else
+ }
+ } else {
start = floor_ptr->m_max + 1;
+ }
for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus) {
MONSTER_IDX dummy = (i % floor_ptr->m_max);
- if (!dummy)
+ if (!dummy) {
continue;
+ }
ms_ptr->target_idx = dummy;
ms_ptr->t_ptr = &floor_ptr->m_list[ms_ptr->target_idx];
- if (!monster_is_valid(ms_ptr->t_ptr) || (ms_ptr->m_idx == ms_ptr->target_idx) || !are_enemies(player_ptr, ms_ptr->m_ptr, ms_ptr->t_ptr) || !projectable(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx))
+ if (!monster_is_valid(ms_ptr->t_ptr) || (ms_ptr->m_idx == ms_ptr->target_idx) || !are_enemies(player_ptr, ms_ptr->m_ptr, ms_ptr->t_ptr) || !projectable(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx)) {
continue;
+ }
return true;
}
static void check_darkness(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->ability_flags.has_not(MonsterAbilityType::DARKNESS))
+ if (ms_ptr->ability_flags.has_not(MonsterAbilityType::DARKNESS)) {
return;
+ }
- bool vs_ninja = (player_ptr->pclass == PlayerClassType::NINJA) && !is_hostile(ms_ptr->t_ptr);
- bool can_use_lite_area = vs_ninja && !(ms_ptr->r_ptr->flags3 & (RF3_UNDEAD | RF3_HURT_LITE)) && !(ms_ptr->r_ptr->flags7 & RF7_DARK_MASK);
- if (ms_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID))
+ bool vs_ninja = PlayerClass(player_ptr).equals(PlayerClassType::NINJA) && !ms_ptr->t_ptr->is_hostile();
+ bool can_use_lite_area = vs_ninja && ms_ptr->r_ptr->kind_flags.has_not(MonsterKindType::UNDEAD) && ms_ptr->r_ptr->resistance_flags.has_not(MonsterResistanceType::HURT_LITE) && !(ms_ptr->r_ptr->flags7 & RF7_DARK_MASK);
+ if (ms_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID)) {
return;
+ }
if (d_info[player_ptr->dungeon_idx].flags.has(DungeonFeatureType::DARKNESS)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::DARKNESS);
return;
}
- if (vs_ninja && !can_use_lite_area)
+ if (vs_ninja && !can_use_lite_area) {
ms_ptr->ability_flags.reset(MonsterAbilityType::DARKNESS);
+ }
}
static void check_stupid(melee_spell_type *ms_ptr)
{
- if (!ms_ptr->in_no_magic_dungeon || ms_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID))
+ if (!ms_ptr->in_no_magic_dungeon || ms_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID)) {
return;
+ }
ms_ptr->ability_flags &= RF_ABILITY_NOMAGIC_MASK;
}
static void check_arena(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (!player_ptr->current_floor_ptr->inside_arena && !player_ptr->phase_out)
+ if (!player_ptr->current_floor_ptr->inside_arena && !player_ptr->phase_out) {
return;
+ }
ms_ptr->ability_flags.reset(RF_ABILITY_SUMMON_MASK).reset(MonsterAbilityType::TELE_LEVEL);
- if (ms_ptr->m_ptr->r_idx == MON_ROLENTO)
+ if (ms_ptr->m_ptr->r_idx == MonsterRaceId::ROLENTO) {
ms_ptr->ability_flags.reset(MonsterAbilityType::SPECIAL);
+ }
}
static void check_melee_spell_distance(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
auto ball_mask_except_rocket = RF_ABILITY_BALL_MASK;
ball_mask_except_rocket.reset(MonsterAbilityType::ROCKET);
- if (ms_ptr->ability_flags.has_none_of(ball_mask_except_rocket))
+ if (ms_ptr->ability_flags.has_none_of(ball_mask_except_rocket)) {
return;
+ }
POSITION real_y = ms_ptr->y;
POSITION real_x = ms_ptr->x;
return;
}
- if (dist > 4)
+ if (dist > 4) {
return;
+ }
ms_ptr->ability_flags.reset(RF_ABILITY_BIG_BALL_MASK);
}
static void check_melee_spell_rocket(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->ability_flags.has_not(MonsterAbilityType::ROCKET))
+ if (ms_ptr->ability_flags.has_not(MonsterAbilityType::ROCKET)) {
return;
+ }
POSITION real_y = ms_ptr->y;
POSITION real_x = ms_ptr->x;
get_project_point(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, &real_y, &real_x, PROJECT_STOP);
- if (projectable(player_ptr, real_y, real_x, player_ptr->y, player_ptr->x) && (distance(real_y, real_x, player_ptr->y, player_ptr->x) <= 2))
+ if (projectable(player_ptr, real_y, real_x, player_ptr->y, player_ptr->x) && (distance(real_y, real_x, player_ptr->y, player_ptr->x) <= 2)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::ROCKET);
+ }
}
static void check_melee_spell_beam(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->ability_flags.has_none_of(RF_ABILITY_BEAM_MASK) || direct_beam(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx, ms_ptr->m_ptr))
+ if (ms_ptr->ability_flags.has_none_of(RF_ABILITY_BEAM_MASK) || direct_beam(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx, ms_ptr->m_ptr)) {
return;
+ }
ms_ptr->ability_flags.reset(RF_ABILITY_BEAM_MASK);
}
static void check_melee_spell_breath(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->ability_flags.has_none_of(RF_ABILITY_BREATH_MASK))
+ if (ms_ptr->ability_flags.has_none_of(RF_ABILITY_BREATH_MASK)) {
return;
+ }
POSITION rad = (ms_ptr->r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2;
if (!breath_direct(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx, rad, AttributeType::NONE, true)) {
static void check_melee_spell_special(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->ability_flags.has_not(MonsterAbilityType::SPECIAL))
+ if (ms_ptr->ability_flags.has_not(MonsterAbilityType::SPECIAL)) {
return;
+ }
- if (ms_ptr->m_ptr->r_idx == MON_ROLENTO) {
- if ((player_ptr->pet_extra_flags & (PF_ATTACK_SPELL | PF_SUMMON_SPELL)) != (PF_ATTACK_SPELL | PF_SUMMON_SPELL))
+ if (ms_ptr->m_ptr->r_idx == MonsterRaceId::ROLENTO) {
+ if ((player_ptr->pet_extra_flags & (PF_ATTACK_SPELL | PF_SUMMON_SPELL)) != (PF_ATTACK_SPELL | PF_SUMMON_SPELL)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::SPECIAL);
+ }
return;
}
if (ms_ptr->r_ptr->d_char == 'B') {
- if ((player_ptr->pet_extra_flags & (PF_ATTACK_SPELL | PF_TELEPORT)) != (PF_ATTACK_SPELL | PF_TELEPORT))
+ if ((player_ptr->pet_extra_flags & (PF_ATTACK_SPELL | PF_TELEPORT)) != (PF_ATTACK_SPELL | PF_TELEPORT)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::SPECIAL);
+ }
return;
}
static void check_riding(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->m_idx != player_ptr->riding)
+ if (ms_ptr->m_idx != player_ptr->riding) {
return;
+ }
ms_ptr->ability_flags.reset(RF_ABILITY_RIDING_MASK);
}
static void check_pet(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (!ms_ptr->pet)
+ if (!ms_ptr->pet) {
return;
+ }
ms_ptr->ability_flags.reset({ MonsterAbilityType::SHRIEK, MonsterAbilityType::DARKNESS, MonsterAbilityType::TRAPS });
- if (!(player_ptr->pet_extra_flags & PF_TELEPORT))
+ if (!(player_ptr->pet_extra_flags & PF_TELEPORT)) {
ms_ptr->ability_flags.reset({ MonsterAbilityType::BLINK, MonsterAbilityType::TPORT, MonsterAbilityType::TELE_TO, MonsterAbilityType::TELE_AWAY, MonsterAbilityType::TELE_LEVEL });
+ }
if (!(player_ptr->pet_extra_flags & PF_ATTACK_SPELL)) {
ms_ptr->ability_flags.reset(RF_ABILITY_ATTACK_MASK);
static void check_non_stupid(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID))
+ if (ms_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID)) {
return;
+ }
if (ms_ptr->ability_flags.has_any_of(RF_ABILITY_BOLT_MASK) && !clean_shot(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx, ms_ptr->pet)) {
ms_ptr->ability_flags.reset(RF_ABILITY_BOLT_MASK);
ms_ptr->ability_flags.reset(RF_ABILITY_SUMMON_MASK);
}
- if (ms_ptr->ability_flags.has(MonsterAbilityType::DISPEL) && !dispel_check_monster(player_ptr, ms_ptr->m_idx, ms_ptr->target_idx))
+ if (ms_ptr->ability_flags.has(MonsterAbilityType::DISPEL) && !dispel_check_monster(player_ptr, ms_ptr->m_idx, ms_ptr->target_idx)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::DISPEL);
+ }
- if (ms_ptr->ability_flags.has(MonsterAbilityType::RAISE_DEAD) && !raise_possible(player_ptr, ms_ptr->m_ptr))
+ if (ms_ptr->ability_flags.has(MonsterAbilityType::RAISE_DEAD) && !raise_possible(player_ptr, ms_ptr->m_ptr)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::RAISE_DEAD);
+ }
- if (ms_ptr->ability_flags.has(MonsterAbilityType::SPECIAL) && (ms_ptr->m_ptr->r_idx == MON_ROLENTO) && !summon_possible(player_ptr, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx))
+ if (ms_ptr->ability_flags.has(MonsterAbilityType::SPECIAL) && (ms_ptr->m_ptr->r_idx == MonsterRaceId::ROLENTO) && !summon_possible(player_ptr, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::SPECIAL);
+ }
}
static void check_smart(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->r_ptr->behavior_flags.has_not(MonsterBehaviorType::SMART))
+ if (ms_ptr->r_ptr->behavior_flags.has_not(MonsterBehaviorType::SMART)) {
return;
+ }
if ((ms_ptr->m_ptr->hp < ms_ptr->m_ptr->maxhp / 10) && (randint0(100) < 50)) {
ms_ptr->ability_flags &= RF_ABILITY_INT_MASK;
}
- if (ms_ptr->ability_flags.has(MonsterAbilityType::TELE_LEVEL) && is_teleport_level_ineffective(player_ptr, (ms_ptr->target_idx == player_ptr->riding) ? 0 : ms_ptr->target_idx))
+ if (ms_ptr->ability_flags.has(MonsterAbilityType::TELE_LEVEL) && is_teleport_level_ineffective(player_ptr, (ms_ptr->target_idx == player_ptr->riding) ? 0 : ms_ptr->target_idx)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::TELE_LEVEL);
+ }
}
static bool set_melee_spell_set(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (ms_ptr->ability_flags.none())
+ if (ms_ptr->ability_flags.none()) {
return false;
+ }
EnumClassFlagGroup<MonsterAbilityType>::get_flags(ms_ptr->ability_flags, std::back_inserter(ms_ptr->spells));
bool check_melee_spell_set(PlayerType *player_ptr, melee_spell_type *ms_ptr)
{
- if (monster_confused_remaining(ms_ptr->m_ptr))
+ if (monster_confused_remaining(ms_ptr->m_ptr)) {
return false;
+ }
ms_ptr->ability_flags = ms_ptr->r_ptr->ability_flags;
decide_melee_spell_target(player_ptr, ms_ptr);
decide_indirection_melee_spell(player_ptr, ms_ptr);
- if (!check_melee_spell_projection(player_ptr, ms_ptr))
+ if (!check_melee_spell_projection(player_ptr, ms_ptr)) {
return false;
+ }
ms_ptr->y = ms_ptr->t_ptr->fy;
ms_ptr->x = ms_ptr->t_ptr->fx;
reset_target(ms_ptr->m_ptr);
ms_ptr->ability_flags.reset({ MonsterAbilityType::WORLD, MonsterAbilityType::TRAPS, MonsterAbilityType::FORGET });
- if (ms_ptr->ability_flags.has(MonsterAbilityType::BR_LITE) && !los(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx))
+ if (ms_ptr->ability_flags.has(MonsterAbilityType::BR_LITE) && !los(player_ptr, ms_ptr->m_ptr->fy, ms_ptr->m_ptr->fx, ms_ptr->t_ptr->fy, ms_ptr->t_ptr->fx)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::BR_LITE);
+ }
- if (ms_ptr->ability_flags.has(MonsterAbilityType::SPECIAL) && (ms_ptr->m_ptr->r_idx != MON_ROLENTO) && (ms_ptr->r_ptr->d_char != 'B'))
+ if (ms_ptr->ability_flags.has(MonsterAbilityType::SPECIAL) && (ms_ptr->m_ptr->r_idx != MonsterRaceId::ROLENTO) && (ms_ptr->r_ptr->d_char != 'B')) {
ms_ptr->ability_flags.reset(MonsterAbilityType::SPECIAL);
+ }
check_darkness(player_ptr, ms_ptr);
check_stupid(ms_ptr);
check_arena(player_ptr, ms_ptr);
- if (player_ptr->phase_out && !one_in_(3))
+ if (player_ptr->phase_out && !one_in_(3)) {
ms_ptr->ability_flags.reset(MonsterAbilityType::HEAL);
+ }
check_riding(player_ptr, ms_ptr);
check_pet(player_ptr, ms_ptr);