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 (is_immune_elec(target_ptr)) {
92 ignore_wraith_form = TRUE;
95 dam = dam * calc_vuln_elec_rate(target_ptr) / 100;
96 if (target_ptr->resist_elec)
98 if (is_oppose_elec(target_ptr))
103 if (target_ptr->resist_pois)
105 if (is_oppose_pois(target_ptr))
110 if (is_immune_acid(target_ptr)) {
112 ignore_wraith_form = TRUE;
116 dam = dam * calc_vuln_acid_rate(target_ptr) / 100;
117 if (target_ptr->resist_acid)
119 if (is_oppose_acid(target_ptr))
125 if (is_immune_cold(target_ptr)) {
127 ignore_wraith_form = TRUE;
130 dam = dam * calc_vuln_cold_rate(target_ptr) / 100;
131 if (target_ptr->resist_cold)
133 if (is_oppose_cold(target_ptr))
138 if (is_immune_fire(target_ptr)) {
140 ignore_wraith_form = TRUE;
143 dam = dam * calc_vuln_fire_rate(target_ptr) / 100;
144 if (target_ptr->resist_fire)
146 if (is_oppose_fire(target_ptr))
151 ignore_wraith_form = TRUE;
155 if (!target_ptr->blind
156 && ((target_ptr->inventory_list[INVEN_RARM].k_idx && (target_ptr->inventory_list[INVEN_RARM].name1 == ART_ZANTETSU))
157 || (target_ptr->inventory_list[INVEN_LARM].k_idx && (target_ptr->inventory_list[INVEN_LARM].name1 == ART_ZANTETSU)))) {
159 ignore_wraith_form = TRUE;
165 if (target_ptr->resist_lite)
166 dam /= 2; /* Worst case of 4 / (d4 + 7) */
167 dam = dam * calc_vuln_lite_rate(target_ptr) / 100;
171 if (is_specific_player_race(target_ptr, RACE_VAMPIRE) || (target_ptr->mimic_form == MIMIC_VAMPIRE) || target_ptr->wraith_form) {
173 ignore_wraith_form = TRUE;
174 } else if (target_ptr->resist_dark)
175 dam /= 2; /* Worst case of 4 / (d4 + 7) */
179 if (target_ptr->resist_shard)
180 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
184 if (target_ptr->resist_sound)
185 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
189 if (target_ptr->resist_conf)
190 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
194 if (target_ptr->resist_chaos)
195 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
199 if (is_specific_player_race(target_ptr, RACE_SPECTRE)) {
201 ignore_wraith_form = TRUE;
202 } else if (target_ptr->resist_neth)
203 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
207 if (target_ptr->resist_disen)
208 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
212 if (target_ptr->resist_nexus)
213 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
217 if (target_ptr->resist_time)
218 dam /= 2; /* Worst case of 4 / (d4 + 7) */
222 if (target_ptr->levitation)
227 if (target_ptr->resist_shard)
232 if (target_ptr->resist_pois)
233 dam = (2 * dam + 2) / 5;
234 if (is_oppose_pois(target_ptr))
235 dam = (2 * dam + 2) / 5;
239 if (target_ptr->mimic_form) {
240 if (mimic_info[target_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
242 ignore_wraith_form = TRUE;
248 switch (target_ptr->prace) {
256 ignore_wraith_form = TRUE;
263 if (target_ptr->align > 10)
265 else if (target_ptr->align < -10)
270 if (target_ptr->align > 10)
276 if (100 + rlev / 2 <= MAX(5, target_ptr->skill_sav)) {
278 ignore_wraith_form = TRUE;
287 if (100 + rlev / 2 <= target_ptr->skill_sav) {
289 ignore_wraith_form = TRUE;
295 if ((100 + rlev / 2 <= target_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU)) {
297 ignore_wraith_form = TRUE;
303 if (target_ptr->wraith_form && !ignore_wraith_form) {
314 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
315 * Calculate spell damages
316 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
318 * @param m_idx 魔法を行使するモンスターのID
319 * @param max 算出した最大ダメージを返すポインタ
322 void spell_damcalc_by_spellnum(player_type *creature_ptr, monster_spell_type ms_type, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
324 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[m_idx];
325 HIT_POINT dam = monspell_damage(creature_ptr, ms_type, m_idx, DAM_MAX);
326 spell_damcalc(creature_ptr, m_ptr, typ, dam, max);
330 * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
331 * Calculate blow damages
332 * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
333 * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
334 * @return 算出された最大ダメージを返す。
336 static int blow_damcalc(monster_type *m_ptr, player_type *target_ptr, monster_blow *blow_ptr)
338 int dam = blow_ptr->d_dice * blow_ptr->d_side;
341 if (blow_ptr->method == RBM_EXPLODE) {
343 spell_damcalc(target_ptr, m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
348 ARMOUR_CLASS ac = target_ptr->ac + target_ptr->to_a;
349 bool check_wraith_form = TRUE;
350 switch (blow_ptr->effect) {
351 case RBE_SUPERHURT: {
352 int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
353 dam = MAX(dam, tmp_dam * 2);
359 dam -= (dam * ((ac < 150) ? ac : 150) / 250);
363 spell_damcalc(target_ptr, m_ptr, GF_ACID, dam, &dummy_max);
365 check_wraith_form = FALSE;
369 spell_damcalc(target_ptr, m_ptr, GF_ELEC, dam, &dummy_max);
371 check_wraith_form = FALSE;
375 spell_damcalc(target_ptr, m_ptr, GF_FIRE, dam, &dummy_max);
377 check_wraith_form = FALSE;
381 spell_damcalc(target_ptr, m_ptr, GF_COLD, dam, &dummy_max);
383 check_wraith_form = FALSE;
388 check_wraith_form = FALSE;
392 if (check_wraith_form && target_ptr->wraith_form) {
402 * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
403 * Examine the grid (xx,yy) and warn the player if there are any danger
404 * @param xx 危険性を調査するマスのX座標
405 * @param yy 危険性を調査するマスのY座標
406 * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
408 bool process_warning(player_type *creature_ptr, POSITION xx, POSITION yy)
412 GAME_TEXT o_name[MAX_NLEN];
414 #define WARNING_AWARE_RANGE 12
416 static int old_damage = 0;
418 for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++) {
419 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++) {
424 if (!in_bounds(creature_ptr->current_floor_ptr, my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE))
427 g_ptr = &creature_ptr->current_floor_ptr->grid_array[my][mx];
432 m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
434 if (monster_csleep_remaining(m_ptr))
436 if (!is_hostile(m_ptr))
439 r_ptr = &r_info[m_ptr->r_idx];
441 /* Monster spells (only powerful ones)*/
442 if (projectable(creature_ptr, my, mx, yy, xx)) {
443 BIT_FLAGS f4 = r_ptr->flags4;
444 BIT_FLAGS f5 = r_ptr->a_ability_flags1;
445 BIT_FLAGS f6 = r_ptr->a_ability_flags2;
447 if (!(d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC)) {
448 if (f4 & RF4_BA_CHAO)
449 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
450 if (f5 & RF5_BA_MANA)
451 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
452 if (f5 & RF5_BA_DARK)
453 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
454 if (f5 & RF5_BA_LITE)
455 spell_damcalc_by_spellnum(creature_ptr, MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
456 if (f6 & RF6_HAND_DOOM)
457 spell_damcalc_by_spellnum(creature_ptr, MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
458 if (f6 & RF6_PSY_SPEAR)
459 spell_damcalc_by_spellnum(creature_ptr, MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
463 spell_damcalc_by_spellnum(creature_ptr, MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
464 if (f4 & RF4_BR_ACID)
465 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
466 if (f4 & RF4_BR_ELEC)
467 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
468 if (f4 & RF4_BR_FIRE)
469 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
470 if (f4 & RF4_BR_COLD)
471 spell_damcalc_by_spellnum(creature_ptr, MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
472 if (f4 & RF4_BR_POIS)
473 spell_damcalc_by_spellnum(creature_ptr, MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
474 if (f4 & RF4_BR_NETH)
475 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
476 if (f4 & RF4_BR_LITE)
477 spell_damcalc_by_spellnum(creature_ptr, MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
478 if (f4 & RF4_BR_DARK)
479 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
480 if (f4 & RF4_BR_CONF)
481 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
482 if (f4 & RF4_BR_SOUN)
483 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
484 if (f4 & RF4_BR_CHAO)
485 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
486 if (f4 & RF4_BR_DISE)
487 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
488 if (f4 & RF4_BR_NEXU)
489 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
490 if (f4 & RF4_BR_TIME)
491 spell_damcalc_by_spellnum(creature_ptr, MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
492 if (f4 & RF4_BR_INER)
493 spell_damcalc_by_spellnum(creature_ptr, MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
494 if (f4 & RF4_BR_GRAV)
495 spell_damcalc_by_spellnum(creature_ptr, MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
496 if (f4 & RF4_BR_SHAR)
497 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
498 if (f4 & RF4_BR_PLAS)
499 spell_damcalc_by_spellnum(creature_ptr, MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
500 if (f4 & RF4_BR_WALL)
501 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
502 if (f4 & RF4_BR_MANA)
503 spell_damcalc_by_spellnum(creature_ptr, MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
504 if (f4 & RF4_BR_NUKE)
505 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
506 if (f4 & RF4_BR_DISI)
507 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
510 /* Monster melee attacks */
511 if ((r_ptr->flags1 & RF1_NEVER_BLOW) || (d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)) {
516 if (!(mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)) {
522 for (int m = 0; m < 4; m++) {
523 /* Skip non-attacks */
524 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT))
527 /* Extract the attack info */
528 dam_melee += blow_damcalc(m_ptr, creature_ptr, &r_ptr->blow[m]);
529 if (r_ptr->blow[m].method == RBM_EXPLODE)
533 if (dam_melee > dam_max0)
534 dam_max0 = dam_melee;
539 /* Prevent excessive warning */
540 if (dam_max > old_damage) {
541 old_damage = dam_max * 3 / 2;
543 if (dam_max > creature_ptr->chp / 2) {
544 object_type *o_ptr = choose_warning_item(creature_ptr);
547 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
549 strcpy(o_name, _("体", "body")); /* Warning ability without item */
550 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
552 disturb(creature_ptr, FALSE, TRUE);
553 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
556 old_damage = old_damage / 2;
558 g_ptr = &creature_ptr->current_floor_ptr->grid_array[yy][xx];
559 bool is_warning = (!easy_disarm && is_trap(creature_ptr, g_ptr->feat)) || (g_ptr->mimic && is_trap(creature_ptr, g_ptr->feat));
560 is_warning &= !one_in_(13);
564 object_type *o_ptr = choose_warning_item(creature_ptr);
566 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
568 strcpy(o_name, _("体", "body")); /* Warning ability without item */
569 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
570 disturb(creature_ptr, FALSE, TRUE);
571 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));