1 #include "object/warning.h"
2 #include "artifact/fixed-art-types.h"
3 #include "core/asking-player.h"
4 #include "core/disturbance.h"
5 #include "dungeon/dungeon-flag-types.h"
6 #include "flavor/flavor-describer.h"
7 #include "flavor/object-flavor-types.h"
8 #include "floor/cave.h"
9 #include "floor/geometry.h"
10 #include "game-option/input-options.h"
11 #include "grid/feature.h"
12 #include "inventory/inventory-slot-types.h"
13 #include "monster-attack/monster-attack-effect.h"
14 #include "monster-attack/monster-attack-table.h"
15 #include "monster-race/monster-race.h"
16 #include "monster-race/race-ability-flags.h"
17 #include "monster-race/race-flags1.h"
18 #include "monster-race/race-indice-types.h"
19 #include "monster/monster-info.h"
20 #include "monster/monster-status.h"
21 #include "mspell/mspell-damage-calculator.h"
22 #include "mutation/mutation-flag-types.h"
23 #include "object-enchant/tr-types.h"
24 #include "player-base/player-race.h"
25 #include "player/player-status-flags.h"
26 #include "player/player-status-resist.h"
27 #include "player/special-defense-types.h"
28 #include "status/element-resistance.h"
29 #include "system/dungeon-info.h"
30 #include "system/floor-type-definition.h"
31 #include "system/grid-type-definition.h"
32 #include "system/item-entity.h"
33 #include "system/monster-entity.h"
34 #include "system/monster-race-info.h"
35 #include "system/player-type-definition.h"
36 #include "target/projection-path-calculator.h"
37 #include "timed-effect/player-blindness.h"
38 #include "timed-effect/timed-effects.h"
39 #include "util/bit-flags-calculator.h"
40 #include "view/display-messages.h"
44 * @brief 警告を放つアイテムを選択する /
45 * Choose one of items that have warning flag
46 * Calculate spell damages
49 ItemEntity *choose_warning_item(PlayerType *player_ptr)
51 /* Paranoia -- Player has no warning ability */
52 if (!player_ptr->warning) {
56 /* Search Inventory */
57 std::vector<int> candidates;
58 for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
59 const auto *o_ptr = &player_ptr->inventory_list[i];
60 if (o_ptr->get_flags().has(TR_WARNING)) {
61 candidates.push_back(i);
65 /* Choice one of them */
66 return candidates.empty() ? nullptr : &player_ptr->inventory_list[rand_choice(candidates)];
70 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する /
71 * Calculate spell damages
72 * @param m_ptr 魔法を行使するモンスターの構造体参照ポインタ
75 * @param max 算出した最大ダメージを返すポインタ
77 static void spell_damcalc(PlayerType *player_ptr, MonsterEntity *m_ptr, AttributeType typ, int dam, int *max)
79 auto *r_ptr = &m_ptr->get_monrace();
80 int rlev = r_ptr->level;
81 bool ignore_wraith_form = false;
83 /* Vulnerability, resistance and immunity */
85 case AttributeType::ELEC:
86 if (has_immune_elec(player_ptr)) {
87 ignore_wraith_form = true;
89 dam = dam * calc_elec_damage_rate(player_ptr) / 100;
92 case AttributeType::POIS:
93 dam = dam * calc_pois_damage_rate(player_ptr) / 100;
96 case AttributeType::ACID:
97 if (has_immune_acid(player_ptr)) {
98 ignore_wraith_form = true;
100 dam = dam * calc_acid_damage_rate(player_ptr) / 100;
103 case AttributeType::COLD:
104 case AttributeType::ICE:
105 if (has_immune_cold(player_ptr)) {
106 ignore_wraith_form = true;
108 dam = dam * calc_cold_damage_rate(player_ptr) / 100;
111 case AttributeType::FIRE:
112 if (has_immune_fire(player_ptr)) {
113 ignore_wraith_form = true;
115 dam = dam * calc_fire_damage_rate(player_ptr) / 100;
118 case AttributeType::PSY_SPEAR:
119 ignore_wraith_form = true;
122 case AttributeType::MONSTER_SHOOT:
123 if (!player_ptr->effects()->blindness()->is_blind() && (has_invuln_arrow(player_ptr))) {
125 ignore_wraith_form = true;
129 case AttributeType::LITE:
130 dam = dam * calc_lite_damage_rate(player_ptr, CALC_MAX) / 100;
133 case AttributeType::DARK:
134 dam = dam * calc_dark_damage_rate(player_ptr, CALC_MAX) / 100;
135 if (has_immune_dark(player_ptr) || player_ptr->wraith_form) {
136 ignore_wraith_form = true;
140 case AttributeType::SHARDS:
141 dam = dam * calc_shards_damage_rate(player_ptr, CALC_MAX) / 100;
144 case AttributeType::SOUND:
145 dam = dam * calc_sound_damage_rate(player_ptr, CALC_MAX) / 100;
148 case AttributeType::CONFUSION:
149 dam = dam * calc_conf_damage_rate(player_ptr, CALC_MAX) / 100;
152 case AttributeType::CHAOS:
153 dam = dam * calc_chaos_damage_rate(player_ptr, CALC_MAX) / 100;
156 case AttributeType::NETHER:
157 dam = dam * calc_nether_damage_rate(player_ptr, CALC_MAX) / 100;
158 if (PlayerRace(player_ptr).equals(PlayerRaceType::SPECTRE)) {
159 ignore_wraith_form = true;
164 case AttributeType::DISENCHANT:
165 dam = dam * calc_disenchant_damage_rate(player_ptr, CALC_MAX) / 100;
168 case AttributeType::NEXUS:
169 dam = dam * calc_nexus_damage_rate(player_ptr, CALC_MAX) / 100;
172 case AttributeType::TIME:
173 dam = dam * calc_time_damage_rate(player_ptr, CALC_MAX) / 100;
176 case AttributeType::GRAVITY:
177 dam = dam * calc_gravity_damage_rate(player_ptr, CALC_MAX) / 100;
180 case AttributeType::ROCKET:
181 dam = dam * calc_rocket_damage_rate(player_ptr, CALC_MAX) / 100;
184 case AttributeType::NUKE:
185 dam = dam * calc_nuke_damage_rate(player_ptr) / 100;
188 case AttributeType::DEATH_RAY:
189 dam = dam * calc_deathray_damage_rate(player_ptr, CALC_MAX) / 100;
191 ignore_wraith_form = true;
195 case AttributeType::HOLY_FIRE:
196 dam = dam * calc_holy_fire_damage_rate(player_ptr, CALC_MAX) / 100;
199 case AttributeType::HELL_FIRE:
200 dam = dam * calc_hell_fire_damage_rate(player_ptr, CALC_MAX) / 100;
203 case AttributeType::ABYSS:
204 dam = dam * calc_abyss_damage_rate(player_ptr, CALC_MAX) / 100;
207 case AttributeType::VOID_MAGIC:
208 dam = dam * calc_void_damage_rate(player_ptr, CALC_MAX) / 100;
211 case AttributeType::MIND_BLAST:
212 case AttributeType::BRAIN_SMASH:
213 if (100 + rlev / 2 <= std::max<short>(5, player_ptr->skill_sav)) {
215 ignore_wraith_form = true;
220 case AttributeType::CAUSE_1:
221 case AttributeType::CAUSE_2:
222 case AttributeType::CAUSE_3:
223 case AttributeType::HAND_DOOM:
224 if (100 + rlev / 2 <= player_ptr->skill_sav) {
226 ignore_wraith_form = true;
231 case AttributeType::CAUSE_4:
232 if ((100 + rlev / 2 <= player_ptr->skill_sav) && (m_ptr->r_idx != MonsterRaceId::KENSHIROU)) {
234 ignore_wraith_form = true;
242 if (player_ptr->wraith_form && !ignore_wraith_form) {
255 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
256 * Calculate spell damages
257 * @param spell_num RF4ならRF_ABILITY::SPELL_STARTのように32区切りのベースとなる数値
259 * @param m_idx 魔法を行使するモンスターのID
260 * @param max 算出した最大ダメージを返すポインタ
262 static void spell_damcalc_by_spellnum(PlayerType *player_ptr, MonsterAbilityType ms_type, AttributeType typ, MONSTER_IDX m_idx, int *max)
264 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
265 int dam = monspell_damage(player_ptr, ms_type, m_idx, DAM_MAX);
266 spell_damcalc(player_ptr, m_ptr, typ, dam, max);
270 * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
271 * Calculate blow damages
272 * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
273 * @param blow モンスターの打撃能力の構造体参照
274 * @return 算出された最大ダメージを返す。
276 static int blow_damcalc(MonsterEntity *m_ptr, PlayerType *player_ptr, const MonsterBlow &blow)
278 int dam = blow.d_dice * blow.d_side;
281 if (blow.method == RaceBlowMethodType::EXPLODE) {
283 spell_damcalc(player_ptr, m_ptr, mbe_info[enum2i(blow.effect)].explode_type, dam, &dummy_max);
288 ARMOUR_CLASS ac = player_ptr->ac + player_ptr->to_a;
289 bool check_wraith_form = true;
290 switch (blow.effect) {
291 case RaceBlowEffectType::SUPERHURT: {
292 int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
293 dam = std::max(dam, tmp_dam * 2);
297 case RaceBlowEffectType::HURT:
298 case RaceBlowEffectType::SHATTER:
299 dam -= (dam * ((ac < 150) ? ac : 150) / 250);
302 case RaceBlowEffectType::ACID:
303 spell_damcalc(player_ptr, m_ptr, AttributeType::ACID, dam, &dummy_max);
305 check_wraith_form = false;
308 case RaceBlowEffectType::ELEC:
309 spell_damcalc(player_ptr, m_ptr, AttributeType::ELEC, dam, &dummy_max);
311 check_wraith_form = false;
314 case RaceBlowEffectType::FIRE:
315 spell_damcalc(player_ptr, m_ptr, AttributeType::FIRE, dam, &dummy_max);
317 check_wraith_form = false;
320 case RaceBlowEffectType::COLD:
321 spell_damcalc(player_ptr, m_ptr, AttributeType::COLD, dam, &dummy_max);
323 check_wraith_form = false;
326 case RaceBlowEffectType::DR_MANA:
328 check_wraith_form = false;
335 if (check_wraith_form && player_ptr->wraith_form) {
346 * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
347 * Examine the grid (xx,yy) and warn the player if there are any danger
348 * @param xx 危険性を調査するマスのX座標
349 * @param yy 危険性を調査するマスのY座標
350 * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
352 bool process_warning(PlayerType *player_ptr, POSITION xx, POSITION yy)
355 #define WARNING_AWARE_RANGE 12
357 static int old_damage = 0;
359 auto &floor = *player_ptr->current_floor_ptr;
360 const auto &dungeon = floor.get_dungeon_definition();
361 for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++) {
362 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++) {
364 if (!in_bounds(&floor, my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) {
368 const auto *g_ptr = &floor.grid_array[my][mx];
374 auto *m_ptr = &floor.m_list[g_ptr->m_idx];
376 if (m_ptr->is_asleep()) {
379 if (!m_ptr->is_hostile()) {
383 auto *r_ptr = &m_ptr->get_monrace();
385 /* Monster spells (only powerful ones)*/
386 if (projectable(player_ptr, my, mx, yy, xx)) {
387 const auto flags = r_ptr->ability_flags;
389 if (dungeon.flags.has_not(DungeonFeatureType::NO_MAGIC)) {
390 if (flags.has(MonsterAbilityType::BA_CHAO)) {
391 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BA_CHAO, AttributeType::CHAOS, g_ptr->m_idx, &dam_max0);
393 if (flags.has(MonsterAbilityType::BA_MANA)) {
394 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BA_MANA, AttributeType::MANA, g_ptr->m_idx, &dam_max0);
396 if (flags.has(MonsterAbilityType::BA_DARK)) {
397 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BA_DARK, AttributeType::DARK, g_ptr->m_idx, &dam_max0);
399 if (flags.has(MonsterAbilityType::BA_LITE)) {
400 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BA_LITE, AttributeType::LITE, g_ptr->m_idx, &dam_max0);
402 if (flags.has(MonsterAbilityType::HAND_DOOM)) {
403 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::HAND_DOOM, AttributeType::HAND_DOOM, g_ptr->m_idx, &dam_max0);
405 if (flags.has(MonsterAbilityType::PSY_SPEAR)) {
406 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::PSY_SPEAR, AttributeType::PSY_SPEAR, g_ptr->m_idx, &dam_max0);
408 if (flags.has(MonsterAbilityType::BA_VOID)) {
409 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BA_VOID, AttributeType::VOID_MAGIC, g_ptr->m_idx, &dam_max0);
411 if (flags.has(MonsterAbilityType::BA_ABYSS)) {
412 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BA_ABYSS, AttributeType::ABYSS, g_ptr->m_idx, &dam_max0);
416 if (flags.has(MonsterAbilityType::ROCKET)) {
417 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::ROCKET, AttributeType::ROCKET, g_ptr->m_idx, &dam_max0);
419 if (flags.has(MonsterAbilityType::BR_ACID)) {
420 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_ACID, AttributeType::ACID, g_ptr->m_idx, &dam_max0);
422 if (flags.has(MonsterAbilityType::BR_ELEC)) {
423 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_ELEC, AttributeType::ELEC, g_ptr->m_idx, &dam_max0);
425 if (flags.has(MonsterAbilityType::BR_FIRE)) {
426 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_FIRE, AttributeType::FIRE, g_ptr->m_idx, &dam_max0);
428 if (flags.has(MonsterAbilityType::BR_COLD)) {
429 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_COLD, AttributeType::COLD, g_ptr->m_idx, &dam_max0);
431 if (flags.has(MonsterAbilityType::BR_POIS)) {
432 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_POIS, AttributeType::POIS, g_ptr->m_idx, &dam_max0);
434 if (flags.has(MonsterAbilityType::BR_NETH)) {
435 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_NETH, AttributeType::NETHER, g_ptr->m_idx, &dam_max0);
437 if (flags.has(MonsterAbilityType::BR_LITE)) {
438 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_LITE, AttributeType::LITE, g_ptr->m_idx, &dam_max0);
440 if (flags.has(MonsterAbilityType::BR_DARK)) {
441 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_DARK, AttributeType::DARK, g_ptr->m_idx, &dam_max0);
443 if (flags.has(MonsterAbilityType::BR_CONF)) {
444 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_CONF, AttributeType::CONFUSION, g_ptr->m_idx, &dam_max0);
446 if (flags.has(MonsterAbilityType::BR_SOUN)) {
447 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_SOUN, AttributeType::SOUND, g_ptr->m_idx, &dam_max0);
449 if (flags.has(MonsterAbilityType::BR_CHAO)) {
450 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_CHAO, AttributeType::CHAOS, g_ptr->m_idx, &dam_max0);
452 if (flags.has(MonsterAbilityType::BR_DISE)) {
453 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_DISE, AttributeType::DISENCHANT, g_ptr->m_idx, &dam_max0);
455 if (flags.has(MonsterAbilityType::BR_NEXU)) {
456 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_NEXU, AttributeType::NEXUS, g_ptr->m_idx, &dam_max0);
458 if (flags.has(MonsterAbilityType::BR_TIME)) {
459 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_TIME, AttributeType::TIME, g_ptr->m_idx, &dam_max0);
461 if (flags.has(MonsterAbilityType::BR_INER)) {
462 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_INER, AttributeType::INERTIAL, g_ptr->m_idx, &dam_max0);
464 if (flags.has(MonsterAbilityType::BR_GRAV)) {
465 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_GRAV, AttributeType::GRAVITY, g_ptr->m_idx, &dam_max0);
467 if (flags.has(MonsterAbilityType::BR_SHAR)) {
468 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_SHAR, AttributeType::SHARDS, g_ptr->m_idx, &dam_max0);
470 if (flags.has(MonsterAbilityType::BR_PLAS)) {
471 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_PLAS, AttributeType::PLASMA, g_ptr->m_idx, &dam_max0);
473 if (flags.has(MonsterAbilityType::BR_FORC)) {
474 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_FORC, AttributeType::FORCE, g_ptr->m_idx, &dam_max0);
476 if (flags.has(MonsterAbilityType::BR_MANA)) {
477 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_MANA, AttributeType::MANA, g_ptr->m_idx, &dam_max0);
479 if (flags.has(MonsterAbilityType::BR_NUKE)) {
480 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_NUKE, AttributeType::NUKE, g_ptr->m_idx, &dam_max0);
482 if (flags.has(MonsterAbilityType::BR_DISI)) {
483 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_DISI, AttributeType::DISINTEGRATE, g_ptr->m_idx, &dam_max0);
485 if (flags.has(MonsterAbilityType::BR_VOID)) {
486 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_VOID, AttributeType::VOID_MAGIC, g_ptr->m_idx, &dam_max0);
488 if (flags.has(MonsterAbilityType::BR_ABYSS)) {
489 spell_damcalc_by_spellnum(player_ptr, MonsterAbilityType::BR_ABYSS, AttributeType::ABYSS, g_ptr->m_idx, &dam_max0);
492 /* Monster melee attacks */
493 if (r_ptr->behavior_flags.has(MonsterBehaviorType::NEVER_BLOW) || dungeon.flags.has(DungeonFeatureType::NO_MELEE)) {
498 if (!(mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)) {
504 for (const auto &blow : r_ptr->blows) {
505 /* Skip non-attacks */
506 if (blow.method == RaceBlowMethodType::NONE || (blow.method == RaceBlowMethodType::SHOOT)) {
510 /* Extract the attack info */
511 dam_melee += blow_damcalc(m_ptr, player_ptr, blow);
512 if (blow.method == RaceBlowMethodType::EXPLODE) {
517 if (dam_melee > dam_max0) {
518 dam_max0 = dam_melee;
524 /* Prevent excessive warning */
525 if (dam_max > old_damage) {
526 old_damage = dam_max * 3 / 2;
528 if (dam_max > player_ptr->chp / 2) {
529 auto *o_ptr = choose_warning_item(player_ptr);
530 std::string item_name;
531 if (o_ptr != nullptr) {
532 item_name = describe_flavor(player_ptr, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
534 item_name = _("体", "body");
537 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), item_name.data());
539 disturb(player_ptr, false, true);
540 return input_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
543 old_damage = old_damage / 2;
546 auto *g_ptr = &floor.grid_array[yy][xx];
547 bool is_warning = (!easy_disarm && is_trap(player_ptr, g_ptr->feat)) || (g_ptr->mimic && is_trap(player_ptr, g_ptr->feat));
548 is_warning &= !one_in_(13);
553 auto *o_ptr = choose_warning_item(player_ptr);
554 std::string item_name;
555 if (o_ptr != nullptr) {
556 item_name = describe_flavor(player_ptr, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
558 item_name = _("体", "body");
561 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), item_name.data());
562 disturb(player_ptr, false, true);
563 return input_check(_("本当にこのまま進むか?", "Really want to go ahead? "));