1 #include "object/warning.h"
2 #include "art-definition/art-sword-types.h"
3 #include "core/asking-player.h"
4 #include "core/disturbance.h"
5 #include "dungeon/dungeon-flag-types.h"
6 #include "dungeon/dungeon.h"
7 #include "flavor/flavor-describer.h"
8 #include "flavor/object-flavor-types.h"
9 #include "floor/cave.h"
10 #include "floor/floor.h"
11 #include "game-option/input-options.h"
12 #include "grid/feature.h"
13 #include "grid/grid.h"
14 #include "inventory/inventory-slot-types.h"
15 #include "monster-attack/monster-attack-effect.h"
16 #include "monster-attack/monster-attack-types.h"
17 #include "monster-race/monster-race.h"
18 #include "monster-race/race-flags-ability1.h"
19 #include "monster-race/race-flags-ability2.h"
20 #include "monster-race/race-flags1.h"
21 #include "monster-race/race-flags4.h"
22 #include "monster-race/race-indice-types.h"
23 #include "monster/monster-info.h"
24 #include "monster/monster-status.h"
25 #include "mspell/mspell-damage-calculator.h"
26 #include "mspell/mspell-type.h"
27 #include "mutation/mutation-flag-types.h"
28 #include "object-enchant/tr-types.h"
29 #include "object/object-flags.h"
30 #include "player/mimic-info-table.h"
31 #include "player/player-class.h"
32 #include "player/player-race-types.h"
33 #include "player/special-defense-types.h"
34 #include "spell/spell-types.h"
35 #include "status/element-resistance.h"
36 #include "system/floor-type-definition.h"
37 #include "util/bit-flags-calculator.h"
38 #include "view/display-messages.h"
41 * @brief 警告を放つアイテムを選択する /
42 * Choose one of items that have warning flag
43 * Calculate spell damages
46 object_type *choose_warning_item(player_type *creature_ptr)
48 int choices[INVEN_TOTAL - INVEN_RARM];
50 /* Paranoia -- Player has no warning ability */
51 if (!creature_ptr->warning)
54 /* Search Inventory */
56 for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
57 BIT_FLAGS flgs[TR_FLAG_SIZE];
58 object_type *o_ptr = &creature_ptr->inventory_list[i];
60 object_flags(creature_ptr, o_ptr, flgs);
61 if (have_flag(flgs, TR_WARNING)) {
67 /* Choice one of them */
68 return number ? &creature_ptr->inventory_list[choices[randint0(number)]] : NULL;
72 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する /
73 * Calculate spell damages
74 * @param m_ptr 魔法を行使するモンスターの構造体参照ポインタ
77 * @param max 算出した最大ダメージを返すポインタ
80 static void spell_damcalc(player_type *target_ptr, monster_type *m_ptr, EFFECT_ID typ, HIT_POINT dam, int *max)
82 monster_race *r_ptr = &r_info[m_ptr->r_idx];
83 int rlev = r_ptr->level;
84 bool ignore_wraith_form = FALSE;
86 /* Vulnerability, resistance and immunity */
89 if (target_ptr->immune_elec) {
91 ignore_wraith_form = TRUE;
95 if (target_ptr->muta3 & MUT3_VULN_ELEM)
97 if (target_ptr->special_defense & KATA_KOUKIJIN)
99 if (is_specific_player_race(target_ptr, RACE_ANDROID))
101 if (target_ptr->resist_elec)
103 if (is_oppose_elec(target_ptr))
108 if (target_ptr->resist_pois)
110 if (is_oppose_pois(target_ptr))
115 if (target_ptr->immune_acid) {
117 ignore_wraith_form = TRUE;
121 if (target_ptr->muta3 & MUT3_VULN_ELEM)
123 if (target_ptr->special_defense & KATA_KOUKIJIN)
125 if (target_ptr->resist_acid)
127 if (is_oppose_acid(target_ptr))
133 if (target_ptr->immune_cold) {
135 ignore_wraith_form = TRUE;
139 if (target_ptr->muta3 & MUT3_VULN_ELEM)
141 if (target_ptr->special_defense & KATA_KOUKIJIN)
143 if (target_ptr->resist_cold)
145 if (is_oppose_cold(target_ptr))
150 if (target_ptr->immune_fire) {
152 ignore_wraith_form = TRUE;
156 if (target_ptr->muta3 & MUT3_VULN_ELEM)
158 if (is_specific_player_race(target_ptr, RACE_ENT))
160 if (target_ptr->special_defense & KATA_KOUKIJIN)
162 if (target_ptr->resist_fire)
164 if (is_oppose_fire(target_ptr))
169 ignore_wraith_form = TRUE;
173 if (!target_ptr->blind
174 && ((target_ptr->inventory_list[INVEN_RARM].k_idx && (target_ptr->inventory_list[INVEN_RARM].name1 == ART_ZANTETSU))
175 || (target_ptr->inventory_list[INVEN_LARM].k_idx && (target_ptr->inventory_list[INVEN_LARM].name1 == ART_ZANTETSU)))) {
177 ignore_wraith_form = TRUE;
183 if (target_ptr->resist_lite)
184 dam /= 2; /* Worst case of 4 / (d4 + 7) */
185 if (is_specific_player_race(target_ptr, RACE_VAMPIRE) || (target_ptr->mimic_form == MIMIC_VAMPIRE))
187 else if (is_specific_player_race(target_ptr, RACE_S_FAIRY))
190 if (target_ptr->wraith_form)
195 if (is_specific_player_race(target_ptr, RACE_VAMPIRE) || (target_ptr->mimic_form == MIMIC_VAMPIRE) || target_ptr->wraith_form) {
197 ignore_wraith_form = TRUE;
198 } else if (target_ptr->resist_dark)
199 dam /= 2; /* Worst case of 4 / (d4 + 7) */
203 if (target_ptr->resist_shard)
204 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
208 if (target_ptr->resist_sound)
209 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
213 if (target_ptr->resist_conf)
214 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
218 if (target_ptr->resist_chaos)
219 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
223 if (is_specific_player_race(target_ptr, RACE_SPECTRE)) {
225 ignore_wraith_form = TRUE;
226 } else if (target_ptr->resist_neth)
227 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
231 if (target_ptr->resist_disen)
232 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
236 if (target_ptr->resist_nexus)
237 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
241 if (target_ptr->resist_time)
242 dam /= 2; /* Worst case of 4 / (d4 + 7) */
246 if (target_ptr->levitation)
251 if (target_ptr->resist_shard)
256 if (target_ptr->resist_pois)
257 dam = (2 * dam + 2) / 5;
258 if (is_oppose_pois(target_ptr))
259 dam = (2 * dam + 2) / 5;
263 if (target_ptr->mimic_form) {
264 if (mimic_info[target_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
266 ignore_wraith_form = TRUE;
272 switch (target_ptr->prace) {
280 ignore_wraith_form = TRUE;
287 if (target_ptr->align > 10)
289 else if (target_ptr->align < -10)
294 if (target_ptr->align > 10)
300 if (100 + rlev / 2 <= MAX(5, target_ptr->skill_sav)) {
302 ignore_wraith_form = TRUE;
311 if (100 + rlev / 2 <= target_ptr->skill_sav) {
313 ignore_wraith_form = TRUE;
319 if ((100 + rlev / 2 <= target_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU)) {
321 ignore_wraith_form = TRUE;
327 if (target_ptr->wraith_form && !ignore_wraith_form) {
338 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
339 * Calculate spell damages
340 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
342 * @param m_idx 魔法を行使するモンスターのID
343 * @param max 算出した最大ダメージを返すポインタ
346 void spell_damcalc_by_spellnum(player_type *creature_ptr, monster_spell_type ms_type, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
348 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[m_idx];
349 HIT_POINT dam = monspell_damage(creature_ptr, ms_type, m_idx, DAM_MAX);
350 spell_damcalc(creature_ptr, m_ptr, typ, dam, max);
354 * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
355 * Calculate blow damages
356 * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
357 * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
358 * @return 算出された最大ダメージを返す。
360 static int blow_damcalc(monster_type *m_ptr, player_type *target_ptr, monster_blow *blow_ptr)
362 int dam = blow_ptr->d_dice * blow_ptr->d_side;
365 if (blow_ptr->method == RBM_EXPLODE) {
367 spell_damcalc(target_ptr, m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
372 ARMOUR_CLASS ac = target_ptr->ac + target_ptr->to_a;
373 bool check_wraith_form = TRUE;
374 switch (blow_ptr->effect) {
375 case RBE_SUPERHURT: {
376 int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
377 dam = MAX(dam, tmp_dam * 2);
383 dam -= (dam * ((ac < 150) ? ac : 150) / 250);
387 spell_damcalc(target_ptr, m_ptr, GF_ACID, dam, &dummy_max);
389 check_wraith_form = FALSE;
393 spell_damcalc(target_ptr, m_ptr, GF_ELEC, dam, &dummy_max);
395 check_wraith_form = FALSE;
399 spell_damcalc(target_ptr, m_ptr, GF_FIRE, dam, &dummy_max);
401 check_wraith_form = FALSE;
405 spell_damcalc(target_ptr, m_ptr, GF_COLD, dam, &dummy_max);
407 check_wraith_form = FALSE;
412 check_wraith_form = FALSE;
416 if (check_wraith_form && target_ptr->wraith_form) {
426 * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
427 * Examine the grid (xx,yy) and warn the player if there are any danger
428 * @param xx 危険性を調査するマスのX座標
429 * @param yy 危険性を調査するマスのY座標
430 * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
432 bool process_warning(player_type *creature_ptr, POSITION xx, POSITION yy)
436 GAME_TEXT o_name[MAX_NLEN];
438 #define WARNING_AWARE_RANGE 12
440 static int old_damage = 0;
442 for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++) {
443 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++) {
448 if (!in_bounds(creature_ptr->current_floor_ptr, my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE))
451 g_ptr = &creature_ptr->current_floor_ptr->grid_array[my][mx];
456 m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
458 if (monster_csleep_remaining(m_ptr))
460 if (!is_hostile(m_ptr))
463 r_ptr = &r_info[m_ptr->r_idx];
465 /* Monster spells (only powerful ones)*/
466 if (projectable(creature_ptr, my, mx, yy, xx)) {
467 BIT_FLAGS f4 = r_ptr->flags4;
468 BIT_FLAGS f5 = r_ptr->a_ability_flags1;
469 BIT_FLAGS f6 = r_ptr->a_ability_flags2;
471 if (!(d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC)) {
472 if (f4 & RF4_BA_CHAO)
473 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
474 if (f5 & RF5_BA_MANA)
475 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
476 if (f5 & RF5_BA_DARK)
477 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
478 if (f5 & RF5_BA_LITE)
479 spell_damcalc_by_spellnum(creature_ptr, MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
480 if (f6 & RF6_HAND_DOOM)
481 spell_damcalc_by_spellnum(creature_ptr, MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
482 if (f6 & RF6_PSY_SPEAR)
483 spell_damcalc_by_spellnum(creature_ptr, MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
487 spell_damcalc_by_spellnum(creature_ptr, MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
488 if (f4 & RF4_BR_ACID)
489 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
490 if (f4 & RF4_BR_ELEC)
491 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
492 if (f4 & RF4_BR_FIRE)
493 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
494 if (f4 & RF4_BR_COLD)
495 spell_damcalc_by_spellnum(creature_ptr, MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
496 if (f4 & RF4_BR_POIS)
497 spell_damcalc_by_spellnum(creature_ptr, MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
498 if (f4 & RF4_BR_NETH)
499 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
500 if (f4 & RF4_BR_LITE)
501 spell_damcalc_by_spellnum(creature_ptr, MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
502 if (f4 & RF4_BR_DARK)
503 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
504 if (f4 & RF4_BR_CONF)
505 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
506 if (f4 & RF4_BR_SOUN)
507 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
508 if (f4 & RF4_BR_CHAO)
509 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
510 if (f4 & RF4_BR_DISE)
511 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
512 if (f4 & RF4_BR_NEXU)
513 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
514 if (f4 & RF4_BR_TIME)
515 spell_damcalc_by_spellnum(creature_ptr, MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
516 if (f4 & RF4_BR_INER)
517 spell_damcalc_by_spellnum(creature_ptr, MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
518 if (f4 & RF4_BR_GRAV)
519 spell_damcalc_by_spellnum(creature_ptr, MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
520 if (f4 & RF4_BR_SHAR)
521 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
522 if (f4 & RF4_BR_PLAS)
523 spell_damcalc_by_spellnum(creature_ptr, MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
524 if (f4 & RF4_BR_WALL)
525 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
526 if (f4 & RF4_BR_MANA)
527 spell_damcalc_by_spellnum(creature_ptr, MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
528 if (f4 & RF4_BR_NUKE)
529 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
530 if (f4 & RF4_BR_DISI)
531 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
534 /* Monster melee attacks */
535 if ((r_ptr->flags1 & RF1_NEVER_BLOW) || (d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)) {
540 if (!(mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)) {
546 for (int m = 0; m < 4; m++) {
547 /* Skip non-attacks */
548 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT))
551 /* Extract the attack info */
552 dam_melee += blow_damcalc(m_ptr, creature_ptr, &r_ptr->blow[m]);
553 if (r_ptr->blow[m].method == RBM_EXPLODE)
557 if (dam_melee > dam_max0)
558 dam_max0 = dam_melee;
563 /* Prevent excessive warning */
564 if (dam_max > old_damage) {
565 old_damage = dam_max * 3 / 2;
567 if (dam_max > creature_ptr->chp / 2) {
568 object_type *o_ptr = choose_warning_item(creature_ptr);
571 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
573 strcpy(o_name, _("体", "body")); /* Warning ability without item */
574 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
576 disturb(creature_ptr, FALSE, TRUE);
577 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
580 old_damage = old_damage / 2;
582 g_ptr = &creature_ptr->current_floor_ptr->grid_array[yy][xx];
583 bool is_warning = (!easy_disarm && is_trap(creature_ptr, g_ptr->feat)) || (g_ptr->mimic && is_trap(creature_ptr, g_ptr->feat));
584 is_warning &= !one_in_(13);
588 object_type *o_ptr = choose_warning_item(creature_ptr);
590 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
592 strcpy(o_name, _("体", "body")); /* Warning ability without item */
593 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
594 disturb(creature_ptr, FALSE, TRUE);
595 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));