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 "game-option/input-options.h"
11 #include "grid/feature.h"
12 #include "grid/grid.h"
13 #include "inventory/inventory-slot-types.h"
14 #include "monster-attack/monster-attack-effect.h"
15 #include "monster-attack/monster-attack-types.h"
16 #include "monster-race/monster-race.h"
17 #include "monster-race/race-flags-ability1.h"
18 #include "monster-race/race-flags-ability2.h"
19 #include "monster-race/race-flags1.h"
20 #include "monster-race/race-flags4.h"
21 #include "monster-race/race-indice-types.h"
22 #include "monster/monster-info.h"
23 #include "monster/monster-status.h"
24 #include "mspell/mspell-damage-calculator.h"
25 #include "mspell/mspell-type.h"
26 #include "mutation/mutation-flag-types.h"
27 #include "object-enchant/tr-types.h"
28 #include "object/object-flags.h"
29 #include "player/mimic-info-table.h"
30 #include "player/player-class.h"
31 #include "player/player-race-types.h"
32 #include "player/special-defense-types.h"
33 #include "player/player-status-flags.h"
34 #include "spell/spell-types.h"
35 #include "status/element-resistance.h"
36 #include "system/floor-type-definition.h"
37 #include "target/projection-path-calculator.h"
38 #include "util/bit-flags-calculator.h"
39 #include "view/display-messages.h"
42 * @brief 警告を放つアイテムを選択する /
43 * Choose one of items that have warning flag
44 * Calculate spell damages
47 object_type *choose_warning_item(player_type *creature_ptr)
49 int choices[INVEN_TOTAL - INVEN_RARM];
51 /* Paranoia -- Player has no warning ability */
52 if (!creature_ptr->warning)
55 /* Search Inventory */
57 for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
58 BIT_FLAGS flgs[TR_FLAG_SIZE];
59 object_type *o_ptr = &creature_ptr->inventory_list[i];
61 object_flags(creature_ptr, o_ptr, flgs);
62 if (has_flag(flgs, TR_WARNING)) {
68 /* Choice one of them */
69 return number ? &creature_ptr->inventory_list[choices[randint0(number)]] : NULL;
73 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する /
74 * Calculate spell damages
75 * @param m_ptr 魔法を行使するモンスターの構造体参照ポインタ
78 * @param max 算出した最大ダメージを返すポインタ
81 static void spell_damcalc(player_type *target_ptr, monster_type *m_ptr, EFFECT_ID typ, HIT_POINT dam, int *max)
83 monster_race *r_ptr = &r_info[m_ptr->r_idx];
84 int rlev = r_ptr->level;
85 bool ignore_wraith_form = FALSE;
87 /* Vulnerability, resistance and immunity */
90 if (has_immune_elec(target_ptr)) {
92 ignore_wraith_form = TRUE;
96 if (target_ptr->muta3 & MUT3_VULN_ELEM)
98 if (target_ptr->special_defense & KATA_KOUKIJIN)
100 if (is_specific_player_race(target_ptr, RACE_ANDROID))
102 if (target_ptr->resist_elec)
104 if (is_oppose_elec(target_ptr))
109 if (target_ptr->resist_pois)
111 if (is_oppose_pois(target_ptr))
116 if (has_immune_acid(target_ptr)) {
118 ignore_wraith_form = TRUE;
122 if (target_ptr->muta3 & MUT3_VULN_ELEM)
124 if (target_ptr->special_defense & KATA_KOUKIJIN)
126 if (target_ptr->resist_acid)
128 if (is_oppose_acid(target_ptr))
134 if (has_immune_cold(target_ptr)) {
136 ignore_wraith_form = TRUE;
140 if (target_ptr->muta3 & MUT3_VULN_ELEM)
142 if (target_ptr->special_defense & KATA_KOUKIJIN)
144 if (target_ptr->resist_cold)
146 if (is_oppose_cold(target_ptr))
151 if (has_immune_fire(target_ptr)) {
153 ignore_wraith_form = TRUE;
157 if (target_ptr->muta3 & MUT3_VULN_ELEM)
159 if (is_specific_player_race(target_ptr, RACE_ENT))
161 if (target_ptr->special_defense & KATA_KOUKIJIN)
163 if (target_ptr->resist_fire)
165 if (is_oppose_fire(target_ptr))
170 ignore_wraith_form = TRUE;
174 if (!target_ptr->blind
175 && ((target_ptr->inventory_list[INVEN_RARM].k_idx && (target_ptr->inventory_list[INVEN_RARM].name1 == ART_ZANTETSU))
176 || (target_ptr->inventory_list[INVEN_LARM].k_idx && (target_ptr->inventory_list[INVEN_LARM].name1 == ART_ZANTETSU)))) {
178 ignore_wraith_form = TRUE;
184 if (target_ptr->resist_lite)
185 dam /= 2; /* Worst case of 4 / (d4 + 7) */
186 if (is_specific_player_race(target_ptr, RACE_VAMPIRE) || (target_ptr->mimic_form == MIMIC_VAMPIRE))
188 else if (is_specific_player_race(target_ptr, RACE_S_FAIRY))
191 if (target_ptr->wraith_form)
196 if (is_specific_player_race(target_ptr, RACE_VAMPIRE) || (target_ptr->mimic_form == MIMIC_VAMPIRE) || target_ptr->wraith_form) {
198 ignore_wraith_form = TRUE;
199 } else if (target_ptr->resist_dark)
200 dam /= 2; /* Worst case of 4 / (d4 + 7) */
204 if (target_ptr->resist_shard)
205 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
209 if (target_ptr->resist_sound)
210 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
214 if (target_ptr->resist_conf)
215 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
219 if (target_ptr->resist_chaos)
220 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
224 if (is_specific_player_race(target_ptr, RACE_SPECTRE)) {
226 ignore_wraith_form = TRUE;
227 } else if (target_ptr->resist_neth)
228 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
232 if (target_ptr->resist_disen)
233 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
237 if (target_ptr->resist_nexus)
238 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
242 if (target_ptr->resist_time)
243 dam /= 2; /* Worst case of 4 / (d4 + 7) */
247 if (target_ptr->levitation)
252 if (target_ptr->resist_shard)
257 if (target_ptr->resist_pois)
258 dam = (2 * dam + 2) / 5;
259 if (is_oppose_pois(target_ptr))
260 dam = (2 * dam + 2) / 5;
264 if (target_ptr->mimic_form) {
265 if (mimic_info[target_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
267 ignore_wraith_form = TRUE;
273 switch (target_ptr->prace) {
281 ignore_wraith_form = TRUE;
288 if (target_ptr->align > 10)
290 else if (target_ptr->align < -10)
295 if (target_ptr->align > 10)
301 if (100 + rlev / 2 <= MAX(5, target_ptr->skill_sav)) {
303 ignore_wraith_form = TRUE;
312 if (100 + rlev / 2 <= target_ptr->skill_sav) {
314 ignore_wraith_form = TRUE;
320 if ((100 + rlev / 2 <= target_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU)) {
322 ignore_wraith_form = TRUE;
328 if (target_ptr->wraith_form && !ignore_wraith_form) {
339 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
340 * Calculate spell damages
341 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
343 * @param m_idx 魔法を行使するモンスターのID
344 * @param max 算出した最大ダメージを返すポインタ
347 void spell_damcalc_by_spellnum(player_type *creature_ptr, monster_spell_type ms_type, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
349 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[m_idx];
350 HIT_POINT dam = monspell_damage(creature_ptr, ms_type, m_idx, DAM_MAX);
351 spell_damcalc(creature_ptr, m_ptr, typ, dam, max);
355 * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
356 * Calculate blow damages
357 * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
358 * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
359 * @return 算出された最大ダメージを返す。
361 static int blow_damcalc(monster_type *m_ptr, player_type *target_ptr, monster_blow *blow_ptr)
363 int dam = blow_ptr->d_dice * blow_ptr->d_side;
366 if (blow_ptr->method == RBM_EXPLODE) {
368 spell_damcalc(target_ptr, m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
373 ARMOUR_CLASS ac = target_ptr->ac + target_ptr->to_a;
374 bool check_wraith_form = TRUE;
375 switch (blow_ptr->effect) {
376 case RBE_SUPERHURT: {
377 int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
378 dam = MAX(dam, tmp_dam * 2);
384 dam -= (dam * ((ac < 150) ? ac : 150) / 250);
388 spell_damcalc(target_ptr, m_ptr, GF_ACID, dam, &dummy_max);
390 check_wraith_form = FALSE;
394 spell_damcalc(target_ptr, m_ptr, GF_ELEC, dam, &dummy_max);
396 check_wraith_form = FALSE;
400 spell_damcalc(target_ptr, m_ptr, GF_FIRE, dam, &dummy_max);
402 check_wraith_form = FALSE;
406 spell_damcalc(target_ptr, m_ptr, GF_COLD, dam, &dummy_max);
408 check_wraith_form = FALSE;
413 check_wraith_form = FALSE;
417 if (check_wraith_form && target_ptr->wraith_form) {
427 * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
428 * Examine the grid (xx,yy) and warn the player if there are any danger
429 * @param xx 危険性を調査するマスのX座標
430 * @param yy 危険性を調査するマスのY座標
431 * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
433 bool process_warning(player_type *creature_ptr, POSITION xx, POSITION yy)
437 GAME_TEXT o_name[MAX_NLEN];
439 #define WARNING_AWARE_RANGE 12
441 static int old_damage = 0;
443 for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++) {
444 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++) {
449 if (!in_bounds(creature_ptr->current_floor_ptr, my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE))
452 g_ptr = &creature_ptr->current_floor_ptr->grid_array[my][mx];
457 m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
459 if (monster_csleep_remaining(m_ptr))
461 if (!is_hostile(m_ptr))
464 r_ptr = &r_info[m_ptr->r_idx];
466 /* Monster spells (only powerful ones)*/
467 if (projectable(creature_ptr, my, mx, yy, xx)) {
468 BIT_FLAGS f4 = r_ptr->flags4;
469 BIT_FLAGS f5 = r_ptr->a_ability_flags1;
470 BIT_FLAGS f6 = r_ptr->a_ability_flags2;
472 if (!(d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC)) {
473 if (f4 & RF4_BA_CHAO)
474 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
475 if (f5 & RF5_BA_MANA)
476 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
477 if (f5 & RF5_BA_DARK)
478 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
479 if (f5 & RF5_BA_LITE)
480 spell_damcalc_by_spellnum(creature_ptr, MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
481 if (f6 & RF6_HAND_DOOM)
482 spell_damcalc_by_spellnum(creature_ptr, MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
483 if (f6 & RF6_PSY_SPEAR)
484 spell_damcalc_by_spellnum(creature_ptr, MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
488 spell_damcalc_by_spellnum(creature_ptr, MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
489 if (f4 & RF4_BR_ACID)
490 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
491 if (f4 & RF4_BR_ELEC)
492 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
493 if (f4 & RF4_BR_FIRE)
494 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
495 if (f4 & RF4_BR_COLD)
496 spell_damcalc_by_spellnum(creature_ptr, MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
497 if (f4 & RF4_BR_POIS)
498 spell_damcalc_by_spellnum(creature_ptr, MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
499 if (f4 & RF4_BR_NETH)
500 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
501 if (f4 & RF4_BR_LITE)
502 spell_damcalc_by_spellnum(creature_ptr, MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
503 if (f4 & RF4_BR_DARK)
504 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
505 if (f4 & RF4_BR_CONF)
506 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
507 if (f4 & RF4_BR_SOUN)
508 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
509 if (f4 & RF4_BR_CHAO)
510 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
511 if (f4 & RF4_BR_DISE)
512 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
513 if (f4 & RF4_BR_NEXU)
514 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
515 if (f4 & RF4_BR_TIME)
516 spell_damcalc_by_spellnum(creature_ptr, MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
517 if (f4 & RF4_BR_INER)
518 spell_damcalc_by_spellnum(creature_ptr, MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
519 if (f4 & RF4_BR_GRAV)
520 spell_damcalc_by_spellnum(creature_ptr, MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
521 if (f4 & RF4_BR_SHAR)
522 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
523 if (f4 & RF4_BR_PLAS)
524 spell_damcalc_by_spellnum(creature_ptr, MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
525 if (f4 & RF4_BR_WALL)
526 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
527 if (f4 & RF4_BR_MANA)
528 spell_damcalc_by_spellnum(creature_ptr, MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
529 if (f4 & RF4_BR_NUKE)
530 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
531 if (f4 & RF4_BR_DISI)
532 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
535 /* Monster melee attacks */
536 if ((r_ptr->flags1 & RF1_NEVER_BLOW) || (d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)) {
541 if (!(mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)) {
547 for (int m = 0; m < 4; m++) {
548 /* Skip non-attacks */
549 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT))
552 /* Extract the attack info */
553 dam_melee += blow_damcalc(m_ptr, creature_ptr, &r_ptr->blow[m]);
554 if (r_ptr->blow[m].method == RBM_EXPLODE)
558 if (dam_melee > dam_max0)
559 dam_max0 = dam_melee;
564 /* Prevent excessive warning */
565 if (dam_max > old_damage) {
566 old_damage = dam_max * 3 / 2;
568 if (dam_max > creature_ptr->chp / 2) {
569 object_type *o_ptr = choose_warning_item(creature_ptr);
572 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
574 strcpy(o_name, _("体", "body")); /* Warning ability without item */
575 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
577 disturb(creature_ptr, FALSE, TRUE);
578 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
581 old_damage = old_damage / 2;
583 g_ptr = &creature_ptr->current_floor_ptr->grid_array[yy][xx];
584 bool is_warning = (!easy_disarm && is_trap(creature_ptr, g_ptr->feat)) || (g_ptr->mimic && is_trap(creature_ptr, g_ptr->feat));
585 is_warning &= !one_in_(13);
589 object_type *o_ptr = choose_warning_item(creature_ptr);
591 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
593 strcpy(o_name, _("体", "body")); /* Warning ability without item */
594 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
595 disturb(creature_ptr, FALSE, TRUE);
596 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));