* @author Hourier
*/
-#include <algorithm>
-
#include "monster/monster-damage.h"
#include "avatar/avatar-changer.h"
#include "core/player-redraw-types.h"
#include "core/speed-table.h"
#include "core/stuff-handler.h"
#include "game-option/birth-options.h"
-#include "game-option/game-play-options.h"
#include "game-option/play-record-options.h"
#include "io/files-util.h"
#include "io/report.h"
#include "spell-kind/spells-random.h"
#include "status/experience.h"
#include "system/floor-type-definition.h"
-#include "system/monster-race-definition.h"
-#include "system/monster-type-definition.h"
+#include "system/monster-entity.h"
+#include "system/monster-race-info.h"
#include "system/player-type-definition.h"
+#include "timed-effect/player-hallucination.h"
+#include "timed-effect/timed-effects.h"
#include "util/bit-flags-calculator.h"
#include "view/display-messages.h"
#include "world/world.h"
+#include <algorithm>
/*
* @brief コンストラクタ
* @param m_idx ダメージを与えたモンスターのID
* @param dam 与えたダメージ量
* @param fear ダメージによってモンスターが恐慌状態に陥ったならばtrue
- * @param type 与えたダメージの種類
+ * @param attribute 与えたダメージの種類 (単一属性)
* @param note モンスターが倒された際の特別なメッセージ述語
*/
-MonsterDamageProcessor::MonsterDamageProcessor(player_type *player_ptr, MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, EFFECT_ID effect_type)
+MonsterDamageProcessor::MonsterDamageProcessor(PlayerType *player_ptr, MONSTER_IDX m_idx, int dam, bool *fear, AttributeType attribute)
: player_ptr(player_ptr)
, m_idx(m_idx)
, dam(dam)
, fear(fear)
- , effect_type(effect_type)
+{
+ this->attribute_flags.clear();
+ this->attribute_flags.set((AttributeType)attribute);
+}
+
+/*
+ * @brief コンストラクタ
+ * @param player_ptr プレイヤーへの参照ポインタ
+ * @param m_idx ダメージを与えたモンスターのID
+ * @param dam 与えたダメージ量
+ * @param fear ダメージによってモンスターが恐慌状態に陥ったならばtrue
+ * @param attribute_flags 与えたダメージの種類 (複数属性)
+ * @param note モンスターが倒された際の特別なメッセージ述語
+ */
+MonsterDamageProcessor::MonsterDamageProcessor(PlayerType *player_ptr, MONSTER_IDX m_idx, int dam, bool *fear, AttributeFlags attribute_flags)
+ : player_ptr(player_ptr)
+ , m_idx(m_idx)
+ , dam(dam)
+ , fear(fear)
+ , attribute_flags(attribute_flags)
{
}
m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
}
- if (allow_debug_options) {
- msg_format(_("合計%d/%dのダメージを与えた。(EffectID: %d)", "You do %d (out of %d) damage. (EffectID: %d)"), m_ptr->dealt_damage, m_ptr->maxhp, this->effect_type);
+ if (w_ptr->wizard) {
+ msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
}
if (this->process_dead_exp_virtue(note, &exp_mon)) {
bool MonsterDamageProcessor::genocide_chaos_patron()
{
auto *m_ptr = &this->player_ptr->current_floor_ptr->m_list[this->m_idx];
- if (!monster_is_valid(m_ptr)) {
+ if (!m_ptr->is_valid()) {
this->m_idx = 0;
}
return this->m_idx == 0;
}
-bool MonsterDamageProcessor::process_dead_exp_virtue(concptr note, monster_type *exp_mon)
+bool MonsterDamageProcessor::process_dead_exp_virtue(concptr note, MonsterEntity *exp_mon)
{
auto *m_ptr = &this->player_ptr->current_floor_ptr->m_list[this->m_idx];
- auto *r_ptr = real_r_ptr(m_ptr);
+ auto &r_ref = m_ptr->get_real_r_ref();
if (m_ptr->hp >= 0) {
return false;
}
this->death_special_flag_monster();
- if (r_ptr->r_akills < MAX_SHORT) {
- r_ptr->r_akills++;
+ if (r_ref.r_akills < MAX_SHORT) {
+ r_ref.r_akills++;
}
this->increase_kill_numbers();
this->dying_scream(m_name);
AvatarChanger ac(player_ptr, m_ptr);
ac.change_virtue();
- if (any_bits(r_ptr->flags1, RF1_UNIQUE) && record_destroy_uniq) {
- char note_buf[160];
- sprintf(note_buf, "%s%s", r_ptr->name.c_str(), m_ptr->mflag2.has(MFLAG2::CLONED) ? _("(クローン)", "(Clone)") : "");
- exe_write_diary(this->player_ptr, DIARY_UNIQUE, 0, note_buf);
+ if (r_ref.kind_flags.has(MonsterKindType::UNIQUE) && record_destroy_uniq) {
+ exe_write_diary(this->player_ptr, DIARY_UNIQUE, 0, std::string(r_ref.name).append(m_ptr->mflag2.has(MonsterConstantFlagType::CLONED) ? _("(クローン)", "(Clone)") : "").data());
}
sound(SOUND_KILL);
this->show_kill_message(note, m_name);
this->show_bounty_message(m_name);
- monster_death(this->player_ptr, this->m_idx, true, this->effect_type);
+ monster_death(this->player_ptr, this->m_idx, true, this->attribute_flags);
this->summon_special_unique();
this->get_exp_from_mon(exp_mon, exp_mon->max_maxhp * 2);
*this->fear = false;
{
auto *m_ptr = &this->player_ptr->current_floor_ptr->m_list[this->m_idx];
auto r_idx = m_ptr->r_idx;
- auto *r_ptr = &r_info[r_idx];
- if (any_bits(r_info[r_idx].flags7, RF7_TANUKI)) {
- r_ptr = &r_info[r_idx];
+ auto *r_ptr = &monraces_info[r_idx];
+ if (any_bits(monraces_info[r_idx].flags7, RF7_TANUKI)) {
+ r_ptr = &monraces_info[r_idx];
m_ptr->ap_r_idx = r_idx;
if (r_ptr->r_sights < MAX_SHORT) {
r_ptr->r_sights++;
}
}
- if (m_ptr->mflag2.has(MFLAG2::CHAMELEON)) {
- r_ptr = real_r_ptr(m_ptr);
- r_idx = real_r_idx(m_ptr);
- if (r_ptr->r_sights < MAX_SHORT) {
- r_ptr->r_sights++;
+ if (m_ptr->mflag2.has(MonsterConstantFlagType::CHAMELEON)) {
+ auto &real_r_ref = m_ptr->get_real_r_ref();
+ r_idx = m_ptr->get_real_r_idx();
+ if (real_r_ref.r_sights < MAX_SHORT) {
+ real_r_ref.r_sights++;
}
}
- if (m_ptr->mflag2.has(MFLAG2::CLONED)) {
+ if (m_ptr->mflag2.has(MonsterConstantFlagType::CLONED)) {
return;
}
- if (any_bits(r_ptr->flags7, RF7_NAZGUL)) {
+ if (r_ptr->population_flags.has(MonsterPopulationType::NAZGUL)) {
r_ptr->max_num--;
return;
}
- if (none_bits(r_ptr->flags1, RF1_UNIQUE)) {
+ if (r_ptr->kind_flags.has_not(MonsterKindType::UNIQUE)) {
return;
}
- this->death_unique_monster((monster_race_type)r_idx);
+ this->death_unique_monster(r_idx);
}
/*
* @brief ユニークの死亡処理
* @param r_idx 死亡したユニークの種族番号
*/
-void MonsterDamageProcessor::death_unique_monster(monster_race_type r_idx)
+void MonsterDamageProcessor::death_unique_monster(MonsterRaceId r_idx)
{
- r_info[r_idx].max_num = 0;
- std::vector<monster_race_type> combined_unique_vec;
+ monraces_info[r_idx].max_num = 0;
+ std::vector<MonsterRaceId> combined_unique_vec;
if (!check_combined_unique(r_idx, &combined_unique_vec)) {
return;
}
uniques.push_back(unique);
}
- this->death_combined_uniques(r_idx, &uniques);
+ this->death_combined_uniques(r_idx, uniques);
}
/*
* @param united_uniques 分裂/合体を行う特殊ユニーク
* @details 合体後、合体前1、合体前2 の順にpush_backすること
*/
-bool MonsterDamageProcessor::check_combined_unique(const monster_race_type r_idx, std::vector<monster_race_type> *combined_unique_vec)
+bool MonsterDamageProcessor::check_combined_unique(const MonsterRaceId r_idx, std::vector<MonsterRaceId> *combined_unique_vec)
{
- combined_unique_vec->push_back(MON_BANORLUPART);
- combined_unique_vec->push_back(MON_BANOR);
- combined_unique_vec->push_back(MON_LUPART);
+ combined_unique_vec->push_back(MonsterRaceId::BANORLUPART);
+ combined_unique_vec->push_back(MonsterRaceId::BANOR);
+ combined_unique_vec->push_back(MonsterRaceId::LUPART);
for (const auto &unique : *combined_unique_vec) {
if (r_idx == unique) {
return false;
}
-/*
+/*!
* @brief 分裂/合体を行う特殊ユニークの死亡処理
- * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
- * @uniques 分裂/合体を行う特殊ユニークのリスト
+ * @details 分裂/合体が A = B + C という図式の時、Aが死亡した場合BとCも死亡処理を行う。
+ * BもしくはCが死亡した場合、Aの死亡処理を行う。
+ * @param r_idx 実際に死亡したモンスターの種族ID
+ * @param combined_uniques 分裂/合体を行う特殊ユニークのリスト
*/
-void MonsterDamageProcessor::death_combined_uniques(const monster_race_type r_idx, combined_uniques *combined_uniques)
+void MonsterDamageProcessor::death_combined_uniques(const MonsterRaceId r_idx, const combined_uniques &combined_uniques)
{
- for (const auto &unique : *combined_uniques) {
- auto united = (monster_race_type)0;
- auto split1 = (monster_race_type)0;
- auto split2 = (monster_race_type)0;
- std::tie(united, split1, split2) = unique;
- if ((r_idx == split1) || (r_idx == split2)) {
- r_info[united].max_num = 0;
- r_info[united].r_pkills++;
- r_info[united].r_akills++;
- if (r_info[united].r_tkills < MAX_SHORT) {
- r_info[united].r_tkills++;
- }
+ auto death_r_idx = [](MonsterRaceId r_idx) {
+ auto &r_ref = monraces_info[r_idx];
+ r_ref.max_num = 0;
+ r_ref.r_pkills++;
+ r_ref.r_akills++;
+ if (r_ref.r_tkills < MAX_SHORT) {
+ r_ref.r_tkills++;
+ }
+ };
+ for (auto [united, split1, split2] : combined_uniques) {
+ if ((r_idx == split1) || (r_idx == split2)) {
+ death_r_idx(united);
continue;
}
continue;
}
- r_info[split1].max_num = 0;
- r_info[split1].r_pkills++;
- r_info[split1].r_akills++;
- if (r_info[split1].r_tkills < MAX_SHORT) {
- r_info[split1].r_tkills++;
- }
-
- r_info[split2].max_num = 0;
- r_info[split2].r_pkills++;
- r_info[split2].r_akills++;
- if (r_info[split2].r_tkills < MAX_SHORT) {
- r_info[split2].r_tkills++;
- }
+ death_r_idx(split1);
+ death_r_idx(split2);
}
}
void MonsterDamageProcessor::increase_kill_numbers()
{
auto *m_ptr = &this->player_ptr->current_floor_ptr->m_list[this->m_idx];
- auto *r_ptr = real_r_ptr(m_ptr);
- if (((m_ptr->ml == 0) || this->player_ptr->hallucinated) && none_bits(r_ptr->flags1, RF1_UNIQUE)) {
+ auto &r_ref = m_ptr->get_real_r_ref();
+ auto is_hallucinated = this->player_ptr->effects()->hallucination()->is_hallucinated();
+ if (((m_ptr->ml == 0) || is_hallucinated) && r_ref.kind_flags.has_not(MonsterKindType::UNIQUE)) {
return;
}
- if (m_ptr->mflag2.has(MFLAG2::KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) {
- r_info[MON_KAGE].r_pkills++;
- } else if (r_ptr->r_pkills < MAX_SHORT) {
- r_ptr->r_pkills++;
+ if (m_ptr->mflag2.has(MonsterConstantFlagType::KAGE) && (monraces_info[MonsterRaceId::KAGE].r_pkills < MAX_SHORT)) {
+ monraces_info[MonsterRaceId::KAGE].r_pkills++;
+ } else if (r_ref.r_pkills < MAX_SHORT) {
+ r_ref.r_pkills++;
}
- if (m_ptr->mflag2.has(MFLAG2::KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) {
- r_info[MON_KAGE].r_tkills++;
- } else if (r_ptr->r_tkills < MAX_SHORT) {
- r_ptr->r_tkills++;
+ if (m_ptr->mflag2.has(MonsterConstantFlagType::KAGE) && (monraces_info[MonsterRaceId::KAGE].r_tkills < MAX_SHORT)) {
+ monraces_info[MonsterRaceId::KAGE].r_tkills++;
+ } else if (r_ref.r_tkills < MAX_SHORT) {
+ r_ref.r_tkills++;
}
monster_race_track(this->player_ptr, m_ptr->ap_r_idx);
void MonsterDamageProcessor::death_amberites(GAME_TEXT *m_name)
{
auto *m_ptr = &this->player_ptr->current_floor_ptr->m_list[this->m_idx];
- auto *r_ptr = real_r_ptr(m_ptr);
- if (none_bits(r_ptr->flags3, RF3_AMBERITE) || one_in_(2)) {
+ const auto &r_ref = m_ptr->get_real_r_ref();
+ if (r_ref.kind_flags.has_not(MonsterKindType::AMBERITE) || one_in_(2)) {
return;
}
void MonsterDamageProcessor::dying_scream(GAME_TEXT *m_name)
{
auto *m_ptr = &this->player_ptr->current_floor_ptr->m_list[this->m_idx];
- auto *r_ptr = real_r_ptr(m_ptr);
- if (none_bits(r_ptr->flags2, RF2_CAN_SPEAK)) {
+ const auto &r_ref = m_ptr->get_real_r_ref();
+ if (r_ref.speak_flags.has_none_of({ MonsterSpeakType::SPEAK_ALL, MonsterSpeakType::SPEAK_DEATH })) {
return;
}
char line_got[1024];
- if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got)) {
+ if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), enum2i(m_ptr->r_idx), line_got)) {
msg_format("%^s %s", m_name, line_got);
}
#ifdef WORLD_SCORE
- if (m_ptr->r_idx == MON_SERPENT) {
+ if (m_ptr->r_idx == MonsterRaceId::SERPENT) {
screen_dump = make_screen_dump(this->player_ptr);
}
#endif
{
auto *floor_ptr = this->player_ptr->current_floor_ptr;
auto *m_ptr = &floor_ptr->m_list[this->m_idx];
- auto *r_ptr = real_r_ptr(m_ptr);
+ const auto &r_ref = m_ptr->get_real_r_ref();
if (note != nullptr) {
msg_format("%^s%s", m_name, note);
return;
auto explode = false;
for (auto i = 0; i < 4; i++) {
- if (r_ptr->blow[i].method == RBM_EXPLODE) {
+ if (r_ref.blow[i].method == RaceBlowMethodType::EXPLODE) {
explode = true;
}
}
{
auto *floor_ptr = this->player_ptr->current_floor_ptr;
auto *m_ptr = &floor_ptr->m_list[this->m_idx];
- auto *r_ptr = real_r_ptr(m_ptr);
- if (none_bits(r_ptr->flags1, RF1_UNIQUE) || m_ptr->mflag2.has(MFLAG2::CLONED) || vanilla_town) {
+ const auto &r_ref = m_ptr->get_real_r_ref();
+ if (r_ref.kind_flags.has_not(MonsterKindType::UNIQUE) || m_ptr->mflag2.has(MonsterConstantFlagType::CLONED) || vanilla_town) {
return;
}
- for (auto i = 0; i < MAX_BOUNTY; i++) {
- if ((w_ptr->bounty_r_idx[i] == m_ptr->r_idx) && m_ptr->mflag2.has_not(MFLAG2::CHAMELEON)) {
- msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
- break;
- }
+ if (m_ptr->mflag2.has(MonsterConstantFlagType::CHAMELEON)) {
+ return;
+ }
+
+ if (MonsterRace(m_ptr->r_idx).is_bounty(true)) {
+ msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
}
}
* experience point of a monster later.
* </pre>
*/
-void MonsterDamageProcessor::get_exp_from_mon(monster_type *m_ptr, HIT_POINT exp_dam)
+void MonsterDamageProcessor::get_exp_from_mon(MonsterEntity *m_ptr, int exp_dam)
{
- auto *r_ptr = &r_info[m_ptr->r_idx];
- if (!monster_is_valid(m_ptr) || is_pet(m_ptr) || this->player_ptr->phase_out) {
+ auto *r_ptr = &monraces_info[m_ptr->r_idx];
+ if (!m_ptr->is_valid() || m_ptr->is_pet() || this->player_ptr->phase_out) {
return;
}
* - Varying speed effects
* - Get a fraction in proportion of damage point
*/
- auto new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * exp_dam;
+ auto new_exp = r_ptr->level * speed_to_energy(m_ptr->mspeed) * exp_dam;
auto new_exp_frac = 0U;
auto div_h = 0;
- auto div_l = (uint)((this->player_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed));
+ auto div_l = (uint)((this->player_ptr->max_plv + 2) * speed_to_energy(r_ptr->speed));
/* Use (average maxhp * 2) as a denominator */
auto compensation = any_bits(r_ptr->flags1, RF1_FORCE_MAXHP) ? r_ptr->hside * 2 : r_ptr->hside + 1;
s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * compensation);
/* Special penalty in the wilderness */
- if (!this->player_ptr->current_floor_ptr->dun_level && (none_bits(r_ptr->flags8, RF8_WILD_ONLY) || none_bits(r_ptr->flags1, RF1_UNIQUE))) {
+ if (!this->player_ptr->current_floor_ptr->dun_level && (r_ptr->wilderness_flags.has_not(MonsterWildernessType::WILD_ONLY) || r_ptr->kind_flags.has_not(MonsterKindType::UNIQUE))) {
s64b_mul(&div_h, &div_l, 0, 5);
}
s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
/* Special penalty for mutiply-monster */
- if (any_bits(r_ptr->flags2, RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN)) {
+ if (any_bits(r_ptr->flags2, RF2_MULTIPLY) || (m_ptr->r_idx == MonsterRaceId::DAWN)) {
int monnum_penarty = r_ptr->r_akills / 400;
if (monnum_penarty > 8) {
monnum_penarty = 8;
void MonsterDamageProcessor::summon_special_unique()
{
auto *m_ptr = &this->player_ptr->current_floor_ptr->m_list[this->m_idx];
- bool is_special_summon = m_ptr->r_idx == MON_IKETA;
- is_special_summon |= m_ptr->r_idx == MON_DOPPIO;
+ bool is_special_summon = m_ptr->r_idx == MonsterRaceId::IKETA;
+ is_special_summon |= m_ptr->r_idx == MonsterRaceId::DOPPIO;
if (!is_special_summon || this->player_ptr->current_floor_ptr->inside_arena || this->player_ptr->phase_out) {
delete_monster_idx(this->player_ptr, this->m_idx);
return;
auto dummy_y = m_ptr->fy;
auto dummy_x = m_ptr->fx;
auto mode = (BIT_FLAGS)0;
- if (is_pet(m_ptr)) {
+ if (m_ptr->is_pet()) {
mode |= PM_FORCE_PET;
}
- MONRACE_IDX new_unique_idx;
+ MonsterRaceId new_unique_idx;
concptr mes;
switch (m_ptr->r_idx) {
- case MON_IKETA:
- new_unique_idx = MON_BIKETAL;
+ case MonsterRaceId::IKETA:
+ new_unique_idx = MonsterRaceId::BIKETAL;
mes = _("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha! *I* am Biketal!");
break;
- case MON_DOPPIO:
- new_unique_idx = MON_DIAVOLO;
+ case MonsterRaceId::DOPPIO:
+ new_unique_idx = MonsterRaceId::DIAVOLO;
mes = _("「これは『試練』だ 過去に打ち勝てという『試練』とオレは受けとった」", "This is a 'trial'. I took it as a 'trial' to overcome in the past.");
break;
default: // バグでなければ入らない.
- new_unique_idx = 0;
+ new_unique_idx = MonsterRace::empty_id();
mes = "";
break;
}
void MonsterDamageProcessor::add_monster_fear()
{
auto *m_ptr = &this->player_ptr->current_floor_ptr->m_list[this->m_idx];
- if (monster_fear_remaining(m_ptr) && (this->dam > 0)) {
- auto fear_remining = monster_fear_remaining(m_ptr) - randint1(this->dam);
+ if (m_ptr->is_fearful() && (this->dam > 0)) {
+ auto fear_remining = m_ptr->get_remaining_fear() - randint1(this->dam);
if (set_monster_monfear(this->player_ptr, this->m_idx, fear_remining)) {
*this->fear = false;
}
}
- auto *r_ptr = &r_info[m_ptr->r_idx];
- if (monster_fear_remaining(m_ptr) || any_bits(r_ptr->flags3, RF3_NO_FEAR)) {
+ auto *r_ptr = &monraces_info[m_ptr->r_idx];
+ if (m_ptr->is_fearful() || any_bits(r_ptr->flags3, RF3_NO_FEAR)) {
return;
}