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 "player/player-status-resist.h"
35 #include "spell/spell-types.h"
36 #include "status/element-resistance.h"
37 #include "system/floor-type-definition.h"
38 #include "target/projection-path-calculator.h"
39 #include "util/bit-flags-calculator.h"
40 #include "view/display-messages.h"
43 * @brief 警告を放つアイテムを選択する /
44 * Choose one of items that have warning flag
45 * Calculate spell damages
48 object_type *choose_warning_item(player_type *creature_ptr)
50 int choices[INVEN_TOTAL - INVEN_RARM];
52 /* Paranoia -- Player has no warning ability */
53 if (!creature_ptr->warning)
56 /* Search Inventory */
58 for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
59 BIT_FLAGS flgs[TR_FLAG_SIZE];
60 object_type *o_ptr = &creature_ptr->inventory_list[i];
62 object_flags(creature_ptr, o_ptr, flgs);
63 if (has_flag(flgs, TR_WARNING)) {
69 /* Choice one of them */
70 return number ? &creature_ptr->inventory_list[choices[randint0(number)]] : NULL;
74 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する /
75 * Calculate spell damages
76 * @param m_ptr 魔法を行使するモンスターの構造体参照ポインタ
79 * @param max 算出した最大ダメージを返すポインタ
82 static void spell_damcalc(player_type *target_ptr, monster_type *m_ptr, EFFECT_ID typ, HIT_POINT dam, int *max)
84 monster_race *r_ptr = &r_info[m_ptr->r_idx];
85 int rlev = r_ptr->level;
86 bool ignore_wraith_form = FALSE;
88 /* Vulnerability, resistance and immunity */
91 if (is_immune_elec(target_ptr)) {
92 ignore_wraith_form = TRUE;
94 dam = dam * calc_elec_damage_rate(target_ptr) / 100;
98 dam = dam * calc_pois_damage_rate(target_ptr) / 100;
102 if (is_immune_acid(target_ptr)) {
104 ignore_wraith_form = TRUE;
108 dam = dam * calc_acid_damage_rate(target_ptr) / 100;
113 if (is_immune_cold(target_ptr)) {
115 ignore_wraith_form = TRUE;
118 dam = dam * calc_cold_damage_rate(target_ptr) / 100;
122 if (is_immune_fire(target_ptr)) {
124 ignore_wraith_form = TRUE;
127 dam = dam * calc_fire_damage_rate(target_ptr) / 100;
130 ignore_wraith_form = TRUE;
134 if (!target_ptr->blind
135 && ((target_ptr->inventory_list[INVEN_RARM].k_idx && (target_ptr->inventory_list[INVEN_RARM].name1 == ART_ZANTETSU))
136 || (target_ptr->inventory_list[INVEN_LARM].k_idx && (target_ptr->inventory_list[INVEN_LARM].name1 == ART_ZANTETSU)))) {
138 ignore_wraith_form = TRUE;
144 dam = dam * calc_lite_damage_rate(target_ptr, RAND_MAX) / 100;
148 dam = dam * calc_dark_damage_rate(target_ptr, RAND_MAX) / 100;
149 if (is_specific_player_race(target_ptr, RACE_VAMPIRE) || (target_ptr->mimic_form == MIMIC_VAMPIRE) || target_ptr->wraith_form)
150 ignore_wraith_form = TRUE;
154 if (target_ptr->resist_shard)
155 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
159 if (target_ptr->resist_sound)
160 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
164 if (target_ptr->resist_conf)
165 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
169 if (target_ptr->resist_chaos)
170 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
174 if (is_specific_player_race(target_ptr, RACE_SPECTRE)) {
176 ignore_wraith_form = TRUE;
177 } else if (target_ptr->resist_neth)
178 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
182 if (target_ptr->resist_disen)
183 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
187 if (target_ptr->resist_nexus)
188 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
192 if (target_ptr->resist_time)
193 dam /= 2; /* Worst case of 4 / (d4 + 7) */
197 if (target_ptr->levitation)
202 if (target_ptr->resist_shard)
207 dam = dam * calc_nuke_damage_rate(target_ptr) / 100;
211 if (target_ptr->mimic_form) {
212 if (mimic_info[target_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
214 ignore_wraith_form = TRUE;
220 switch (target_ptr->prace) {
228 ignore_wraith_form = TRUE;
235 if (target_ptr->align > 10)
237 else if (target_ptr->align < -10)
242 if (target_ptr->align > 10)
248 if (100 + rlev / 2 <= MAX(5, target_ptr->skill_sav)) {
250 ignore_wraith_form = TRUE;
259 if (100 + rlev / 2 <= target_ptr->skill_sav) {
261 ignore_wraith_form = TRUE;
267 if ((100 + rlev / 2 <= target_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU)) {
269 ignore_wraith_form = TRUE;
275 if (target_ptr->wraith_form && !ignore_wraith_form) {
286 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
287 * Calculate spell damages
288 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
290 * @param m_idx 魔法を行使するモンスターのID
291 * @param max 算出した最大ダメージを返すポインタ
294 void spell_damcalc_by_spellnum(player_type *creature_ptr, monster_spell_type ms_type, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
296 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[m_idx];
297 HIT_POINT dam = monspell_damage(creature_ptr, ms_type, m_idx, DAM_MAX);
298 spell_damcalc(creature_ptr, m_ptr, typ, dam, max);
302 * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
303 * Calculate blow damages
304 * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
305 * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
306 * @return 算出された最大ダメージを返す。
308 static int blow_damcalc(monster_type *m_ptr, player_type *target_ptr, monster_blow *blow_ptr)
310 int dam = blow_ptr->d_dice * blow_ptr->d_side;
313 if (blow_ptr->method == RBM_EXPLODE) {
315 spell_damcalc(target_ptr, m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
320 ARMOUR_CLASS ac = target_ptr->ac + target_ptr->to_a;
321 bool check_wraith_form = TRUE;
322 switch (blow_ptr->effect) {
323 case RBE_SUPERHURT: {
324 int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
325 dam = MAX(dam, tmp_dam * 2);
331 dam -= (dam * ((ac < 150) ? ac : 150) / 250);
335 spell_damcalc(target_ptr, m_ptr, GF_ACID, dam, &dummy_max);
337 check_wraith_form = FALSE;
341 spell_damcalc(target_ptr, m_ptr, GF_ELEC, dam, &dummy_max);
343 check_wraith_form = FALSE;
347 spell_damcalc(target_ptr, m_ptr, GF_FIRE, dam, &dummy_max);
349 check_wraith_form = FALSE;
353 spell_damcalc(target_ptr, m_ptr, GF_COLD, dam, &dummy_max);
355 check_wraith_form = FALSE;
360 check_wraith_form = FALSE;
364 if (check_wraith_form && target_ptr->wraith_form) {
374 * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
375 * Examine the grid (xx,yy) and warn the player if there are any danger
376 * @param xx 危険性を調査するマスのX座標
377 * @param yy 危険性を調査するマスのY座標
378 * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
380 bool process_warning(player_type *creature_ptr, POSITION xx, POSITION yy)
384 GAME_TEXT o_name[MAX_NLEN];
386 #define WARNING_AWARE_RANGE 12
388 static int old_damage = 0;
390 for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++) {
391 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++) {
396 if (!in_bounds(creature_ptr->current_floor_ptr, my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE))
399 g_ptr = &creature_ptr->current_floor_ptr->grid_array[my][mx];
404 m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
406 if (monster_csleep_remaining(m_ptr))
408 if (!is_hostile(m_ptr))
411 r_ptr = &r_info[m_ptr->r_idx];
413 /* Monster spells (only powerful ones)*/
414 if (projectable(creature_ptr, my, mx, yy, xx)) {
415 BIT_FLAGS f4 = r_ptr->flags4;
416 BIT_FLAGS f5 = r_ptr->a_ability_flags1;
417 BIT_FLAGS f6 = r_ptr->a_ability_flags2;
419 if (!(d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC)) {
420 if (f4 & RF4_BA_CHAO)
421 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
422 if (f5 & RF5_BA_MANA)
423 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
424 if (f5 & RF5_BA_DARK)
425 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
426 if (f5 & RF5_BA_LITE)
427 spell_damcalc_by_spellnum(creature_ptr, MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
428 if (f6 & RF6_HAND_DOOM)
429 spell_damcalc_by_spellnum(creature_ptr, MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
430 if (f6 & RF6_PSY_SPEAR)
431 spell_damcalc_by_spellnum(creature_ptr, MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
435 spell_damcalc_by_spellnum(creature_ptr, MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
436 if (f4 & RF4_BR_ACID)
437 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
438 if (f4 & RF4_BR_ELEC)
439 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
440 if (f4 & RF4_BR_FIRE)
441 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
442 if (f4 & RF4_BR_COLD)
443 spell_damcalc_by_spellnum(creature_ptr, MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
444 if (f4 & RF4_BR_POIS)
445 spell_damcalc_by_spellnum(creature_ptr, MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
446 if (f4 & RF4_BR_NETH)
447 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
448 if (f4 & RF4_BR_LITE)
449 spell_damcalc_by_spellnum(creature_ptr, MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
450 if (f4 & RF4_BR_DARK)
451 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
452 if (f4 & RF4_BR_CONF)
453 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
454 if (f4 & RF4_BR_SOUN)
455 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
456 if (f4 & RF4_BR_CHAO)
457 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
458 if (f4 & RF4_BR_DISE)
459 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
460 if (f4 & RF4_BR_NEXU)
461 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
462 if (f4 & RF4_BR_TIME)
463 spell_damcalc_by_spellnum(creature_ptr, MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
464 if (f4 & RF4_BR_INER)
465 spell_damcalc_by_spellnum(creature_ptr, MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
466 if (f4 & RF4_BR_GRAV)
467 spell_damcalc_by_spellnum(creature_ptr, MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
468 if (f4 & RF4_BR_SHAR)
469 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
470 if (f4 & RF4_BR_PLAS)
471 spell_damcalc_by_spellnum(creature_ptr, MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
472 if (f4 & RF4_BR_WALL)
473 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
474 if (f4 & RF4_BR_MANA)
475 spell_damcalc_by_spellnum(creature_ptr, MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
476 if (f4 & RF4_BR_NUKE)
477 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
478 if (f4 & RF4_BR_DISI)
479 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
482 /* Monster melee attacks */
483 if ((r_ptr->flags1 & RF1_NEVER_BLOW) || (d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)) {
488 if (!(mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)) {
494 for (int m = 0; m < 4; m++) {
495 /* Skip non-attacks */
496 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT))
499 /* Extract the attack info */
500 dam_melee += blow_damcalc(m_ptr, creature_ptr, &r_ptr->blow[m]);
501 if (r_ptr->blow[m].method == RBM_EXPLODE)
505 if (dam_melee > dam_max0)
506 dam_max0 = dam_melee;
511 /* Prevent excessive warning */
512 if (dam_max > old_damage) {
513 old_damage = dam_max * 3 / 2;
515 if (dam_max > creature_ptr->chp / 2) {
516 object_type *o_ptr = choose_warning_item(creature_ptr);
519 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
521 strcpy(o_name, _("体", "body")); /* Warning ability without item */
522 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
524 disturb(creature_ptr, FALSE, TRUE);
525 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
528 old_damage = old_damage / 2;
530 g_ptr = &creature_ptr->current_floor_ptr->grid_array[yy][xx];
531 bool is_warning = (!easy_disarm && is_trap(creature_ptr, g_ptr->feat)) || (g_ptr->mimic && is_trap(creature_ptr, g_ptr->feat));
532 is_warning &= !one_in_(13);
536 object_type *o_ptr = choose_warning_item(creature_ptr);
538 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
540 strcpy(o_name, _("体", "body")); /* Warning ability without item */
541 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
542 disturb(creature_ptr, FALSE, TRUE);
543 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));