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)) {
103 ignore_wraith_form = TRUE;
105 dam = dam * calc_acid_damage_rate(target_ptr) / 100;
110 if (is_immune_cold(target_ptr)) {
112 ignore_wraith_form = TRUE;
115 dam = dam * calc_cold_damage_rate(target_ptr) / 100;
119 if (is_immune_fire(target_ptr)) {
121 ignore_wraith_form = TRUE;
124 dam = dam * calc_fire_damage_rate(target_ptr) / 100;
127 ignore_wraith_form = TRUE;
131 if (!target_ptr->blind
132 && (has_invuln_arrow(target_ptr))) {
134 ignore_wraith_form = TRUE;
140 dam = dam * calc_lite_damage_rate(target_ptr, RAND_MAX) / 100;
144 dam = dam * calc_dark_damage_rate(target_ptr, RAND_MAX) / 100;
145 if (is_specific_player_race(target_ptr, RACE_VAMPIRE) || (target_ptr->mimic_form == MIMIC_VAMPIRE) || target_ptr->wraith_form)
146 ignore_wraith_form = TRUE;
150 if (target_ptr->resist_shard)
151 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
155 if (target_ptr->resist_sound)
156 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
160 if (target_ptr->resist_conf)
161 dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
165 if (target_ptr->resist_chaos)
166 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
170 if (is_specific_player_race(target_ptr, RACE_SPECTRE)) {
172 ignore_wraith_form = TRUE;
173 } else if (target_ptr->resist_neth)
174 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
178 if (target_ptr->resist_disen)
179 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
183 if (target_ptr->resist_nexus)
184 dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
188 if (target_ptr->resist_time)
189 dam /= 2; /* Worst case of 4 / (d4 + 7) */
193 if (target_ptr->levitation)
198 if (target_ptr->resist_shard)
203 dam = dam * calc_nuke_damage_rate(target_ptr) / 100;
207 if (target_ptr->mimic_form) {
208 if (mimic_info[target_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
210 ignore_wraith_form = TRUE;
216 switch (target_ptr->prace) {
224 ignore_wraith_form = TRUE;
231 dam = dam * calc_holy_fire_damage_rate(target_ptr, CALC_MAX) / 100;
235 if (target_ptr->align > 10)
241 if (100 + rlev / 2 <= MAX(5, target_ptr->skill_sav)) {
243 ignore_wraith_form = TRUE;
252 if (100 + rlev / 2 <= target_ptr->skill_sav) {
254 ignore_wraith_form = TRUE;
260 if ((100 + rlev / 2 <= target_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU)) {
262 ignore_wraith_form = TRUE;
268 if (target_ptr->wraith_form && !ignore_wraith_form) {
279 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
280 * Calculate spell damages
281 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
283 * @param m_idx 魔法を行使するモンスターのID
284 * @param max 算出した最大ダメージを返すポインタ
287 void spell_damcalc_by_spellnum(player_type *creature_ptr, monster_spell_type ms_type, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
289 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[m_idx];
290 HIT_POINT dam = monspell_damage(creature_ptr, ms_type, m_idx, DAM_MAX);
291 spell_damcalc(creature_ptr, m_ptr, typ, dam, max);
295 * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
296 * Calculate blow damages
297 * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
298 * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
299 * @return 算出された最大ダメージを返す。
301 static int blow_damcalc(monster_type *m_ptr, player_type *target_ptr, monster_blow *blow_ptr)
303 int dam = blow_ptr->d_dice * blow_ptr->d_side;
306 if (blow_ptr->method == RBM_EXPLODE) {
308 spell_damcalc(target_ptr, m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
313 ARMOUR_CLASS ac = target_ptr->ac + target_ptr->to_a;
314 bool check_wraith_form = TRUE;
315 switch (blow_ptr->effect) {
316 case RBE_SUPERHURT: {
317 int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
318 dam = MAX(dam, tmp_dam * 2);
324 dam -= (dam * ((ac < 150) ? ac : 150) / 250);
328 spell_damcalc(target_ptr, m_ptr, GF_ACID, dam, &dummy_max);
330 check_wraith_form = FALSE;
334 spell_damcalc(target_ptr, m_ptr, GF_ELEC, dam, &dummy_max);
336 check_wraith_form = FALSE;
340 spell_damcalc(target_ptr, m_ptr, GF_FIRE, dam, &dummy_max);
342 check_wraith_form = FALSE;
346 spell_damcalc(target_ptr, m_ptr, GF_COLD, dam, &dummy_max);
348 check_wraith_form = FALSE;
353 check_wraith_form = FALSE;
357 if (check_wraith_form && target_ptr->wraith_form) {
367 * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
368 * Examine the grid (xx,yy) and warn the player if there are any danger
369 * @param xx 危険性を調査するマスのX座標
370 * @param yy 危険性を調査するマスのY座標
371 * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
373 bool process_warning(player_type *creature_ptr, POSITION xx, POSITION yy)
377 GAME_TEXT o_name[MAX_NLEN];
379 #define WARNING_AWARE_RANGE 12
381 static int old_damage = 0;
383 for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++) {
384 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++) {
389 if (!in_bounds(creature_ptr->current_floor_ptr, my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE))
392 g_ptr = &creature_ptr->current_floor_ptr->grid_array[my][mx];
397 m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
399 if (monster_csleep_remaining(m_ptr))
401 if (!is_hostile(m_ptr))
404 r_ptr = &r_info[m_ptr->r_idx];
406 /* Monster spells (only powerful ones)*/
407 if (projectable(creature_ptr, my, mx, yy, xx)) {
408 BIT_FLAGS f4 = r_ptr->flags4;
409 BIT_FLAGS f5 = r_ptr->a_ability_flags1;
410 BIT_FLAGS f6 = r_ptr->a_ability_flags2;
412 if (!(d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC)) {
413 if (f4 & RF4_BA_CHAO)
414 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
415 if (f5 & RF5_BA_MANA)
416 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
417 if (f5 & RF5_BA_DARK)
418 spell_damcalc_by_spellnum(creature_ptr, MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
419 if (f5 & RF5_BA_LITE)
420 spell_damcalc_by_spellnum(creature_ptr, MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
421 if (f6 & RF6_HAND_DOOM)
422 spell_damcalc_by_spellnum(creature_ptr, MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
423 if (f6 & RF6_PSY_SPEAR)
424 spell_damcalc_by_spellnum(creature_ptr, MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
428 spell_damcalc_by_spellnum(creature_ptr, MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
429 if (f4 & RF4_BR_ACID)
430 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
431 if (f4 & RF4_BR_ELEC)
432 spell_damcalc_by_spellnum(creature_ptr, MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
433 if (f4 & RF4_BR_FIRE)
434 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
435 if (f4 & RF4_BR_COLD)
436 spell_damcalc_by_spellnum(creature_ptr, MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
437 if (f4 & RF4_BR_POIS)
438 spell_damcalc_by_spellnum(creature_ptr, MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
439 if (f4 & RF4_BR_NETH)
440 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
441 if (f4 & RF4_BR_LITE)
442 spell_damcalc_by_spellnum(creature_ptr, MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
443 if (f4 & RF4_BR_DARK)
444 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
445 if (f4 & RF4_BR_CONF)
446 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
447 if (f4 & RF4_BR_SOUN)
448 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
449 if (f4 & RF4_BR_CHAO)
450 spell_damcalc_by_spellnum(creature_ptr, MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
451 if (f4 & RF4_BR_DISE)
452 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
453 if (f4 & RF4_BR_NEXU)
454 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
455 if (f4 & RF4_BR_TIME)
456 spell_damcalc_by_spellnum(creature_ptr, MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
457 if (f4 & RF4_BR_INER)
458 spell_damcalc_by_spellnum(creature_ptr, MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
459 if (f4 & RF4_BR_GRAV)
460 spell_damcalc_by_spellnum(creature_ptr, MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
461 if (f4 & RF4_BR_SHAR)
462 spell_damcalc_by_spellnum(creature_ptr, MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
463 if (f4 & RF4_BR_PLAS)
464 spell_damcalc_by_spellnum(creature_ptr, MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
465 if (f4 & RF4_BR_WALL)
466 spell_damcalc_by_spellnum(creature_ptr, MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
467 if (f4 & RF4_BR_MANA)
468 spell_damcalc_by_spellnum(creature_ptr, MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
469 if (f4 & RF4_BR_NUKE)
470 spell_damcalc_by_spellnum(creature_ptr, MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
471 if (f4 & RF4_BR_DISI)
472 spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
475 /* Monster melee attacks */
476 if ((r_ptr->flags1 & RF1_NEVER_BLOW) || (d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MELEE)) {
481 if (!(mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)) {
487 for (int m = 0; m < 4; m++) {
488 /* Skip non-attacks */
489 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT))
492 /* Extract the attack info */
493 dam_melee += blow_damcalc(m_ptr, creature_ptr, &r_ptr->blow[m]);
494 if (r_ptr->blow[m].method == RBM_EXPLODE)
498 if (dam_melee > dam_max0)
499 dam_max0 = dam_melee;
504 /* Prevent excessive warning */
505 if (dam_max > old_damage) {
506 old_damage = dam_max * 3 / 2;
508 if (dam_max > creature_ptr->chp / 2) {
509 object_type *o_ptr = choose_warning_item(creature_ptr);
512 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
514 strcpy(o_name, _("体", "body")); /* Warning ability without item */
515 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
517 disturb(creature_ptr, FALSE, TRUE);
518 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
521 old_damage = old_damage / 2;
523 g_ptr = &creature_ptr->current_floor_ptr->grid_array[yy][xx];
524 bool is_warning = (!easy_disarm && is_trap(creature_ptr, g_ptr->feat)) || (g_ptr->mimic && is_trap(creature_ptr, g_ptr->feat));
525 is_warning &= !one_in_(13);
529 object_type *o_ptr = choose_warning_item(creature_ptr);
531 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
533 strcpy(o_name, _("体", "body")); /* Warning ability without item */
534 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
535 disturb(creature_ptr, FALSE, TRUE);
536 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));