5 #include "player-move.h"
9 #include "player-status.h"
11 #include "monster-spell.h"
14 * @brief 警告を放つアイテムを選択する /
15 * Choose one of items that have warning flag
16 * Calculate spell damages
19 object_type *choose_warning_item(void)
22 int choices[INVEN_TOTAL - INVEN_RARM];
25 /* Paranoia -- Player has no warning ability */
26 if (!p_ptr->warning) return NULL;
28 /* Search Inventory */
29 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
31 BIT_FLAGS flgs[TR_FLAG_SIZE];
32 object_type *o_ptr = &inventory[i];
34 object_flags(o_ptr, flgs);
35 if (have_flag(flgs, TR_WARNING))
42 /* Choice one of them */
43 return number ? &inventory[choices[randint0(number)]] : NULL;
47 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する /
48 * Calculate spell damages
49 * @param m_ptr 魔法を行使するモンスターの構造体参照ポインタ
52 * @param max 算出した最大ダメージを返すポインタ
55 static void spell_damcalc(monster_type *m_ptr, EFFECT_ID typ, HIT_POINT dam, int *max)
57 monster_race *r_ptr = &r_info[m_ptr->r_idx];
58 int rlev = r_ptr->level;
59 bool ignore_wraith_form = FALSE;
61 /* Vulnerability, resistance and immunity */
65 if (p_ptr->immune_elec)
68 ignore_wraith_form = TRUE;
72 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
73 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
74 if (prace_is_(RACE_ANDROID)) dam += dam / 3;
75 if (p_ptr->resist_elec) dam = (dam + 2) / 3;
82 if (p_ptr->resist_pois) dam = (dam + 2) / 3;
83 if (IS_OPPOSE_POIS()) dam = (dam + 2) / 3;
87 if (p_ptr->immune_acid)
90 ignore_wraith_form = TRUE;
94 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
95 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
96 if (p_ptr->resist_acid) dam = (dam + 2) / 3;
97 if (IS_OPPOSE_ACID()) dam = (dam + 2) / 3;
103 if (p_ptr->immune_cold)
106 ignore_wraith_form = TRUE;
110 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
111 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
112 if (p_ptr->resist_cold) dam = (dam + 2) / 3;
113 if (IS_OPPOSE_COLD()) dam = (dam + 2) / 3;
118 if (p_ptr->immune_fire)
121 ignore_wraith_form = TRUE;
125 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
126 if (prace_is_(RACE_ENT)) dam += dam / 3;
127 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
128 if (p_ptr->resist_fire) dam = (dam + 2) / 3;
129 if (IS_OPPOSE_FIRE()) dam = (dam + 2) / 3;
134 ignore_wraith_form = TRUE;
139 ((inventory[INVEN_RARM].k_idx && (inventory[INVEN_RARM].name1 == ART_ZANTETSU)) ||
140 (inventory[INVEN_LARM].k_idx && (inventory[INVEN_LARM].name1 == ART_ZANTETSU))))
143 ignore_wraith_form = TRUE;
148 if (p_ptr->resist_lite) dam /= 2; /* Worst case of 4 / (d4 + 7) */
149 if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE)) dam *= 2;
150 else if (prace_is_(RACE_S_FAIRY)) dam = dam * 4 / 3;
153 * Cannot use "ignore_wraith_form" strictly (for "random one damage")
154 * "dam *= 2;" for later "dam /= 2"
156 if (p_ptr->wraith_form) dam *= 2;
160 if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE) || p_ptr->wraith_form)
163 ignore_wraith_form = TRUE;
165 else if (p_ptr->resist_dark) dam /= 2; /* Worst case of 4 / (d4 + 7) */
169 if (p_ptr->resist_shard) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
173 if (p_ptr->resist_sound) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
177 if (p_ptr->resist_conf) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
181 if (p_ptr->resist_chaos) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
185 if (prace_is_(RACE_SPECTRE))
188 ignore_wraith_form = TRUE;
190 else if (p_ptr->resist_neth) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
194 if (p_ptr->resist_disen) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
198 if (p_ptr->resist_nexus) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
202 if (p_ptr->resist_time) dam /= 2; /* Worst case of 4 / (d4 + 7) */
206 if (p_ptr->levitation) dam = (dam * 2) / 3;
210 if (p_ptr->resist_shard) dam /= 2;
214 if (p_ptr->resist_pois) dam = (2 * dam + 2) / 5;
215 if (IS_OPPOSE_POIS()) dam = (2 * dam + 2) / 5;
219 if (p_ptr->mimic_form)
221 if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING)
224 ignore_wraith_form = TRUE;
229 switch (p_ptr->prace)
238 ignore_wraith_form = TRUE;
245 if (p_ptr->align > 10) dam /= 2;
246 else if (p_ptr->align < -10) dam *= 2;
250 if (p_ptr->align > 10) dam *= 2;
255 if (100 + rlev / 2 <= MAX(5, p_ptr->skill_sav))
258 ignore_wraith_form = TRUE;
266 if (100 + rlev / 2 <= p_ptr->skill_sav)
269 ignore_wraith_form = TRUE;
274 if ((100 + rlev / 2 <= p_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU))
277 ignore_wraith_form = TRUE;
282 if (p_ptr->wraith_form && !ignore_wraith_form)
288 if (dam > *max) *max = dam;
292 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
293 * Calculate spell damages
294 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
296 * @param m_idx 魔法を行使するモンスターのID
297 * @param max 算出した最大ダメージを返すポインタ
300 void spell_damcalc_by_spellnum(int spell_num, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
302 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
303 HIT_POINT dam = monspell_damage((spell_num), m_idx, DAM_MAX);
304 spell_damcalc(m_ptr, typ, dam, max);
308 * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
309 * Calculate blow damages
310 * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
311 * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
312 * @return 算出された最大ダメージを返す。
314 static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
316 int dam = blow_ptr->d_dice * blow_ptr->d_side;
318 bool check_wraith_form = TRUE;
320 if (blow_ptr->method != RBM_EXPLODE)
322 ARMOUR_CLASS ac = p_ptr->ac + p_ptr->to_a;
324 switch (blow_ptr->effect)
328 int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
329 dam = MAX(dam, tmp_dam * 2);
335 dam -= (dam * ((ac < 150) ? ac : 150) / 250);
339 spell_damcalc(m_ptr, GF_ACID, dam, &dummy_max);
341 check_wraith_form = FALSE;
345 spell_damcalc(m_ptr, GF_ELEC, dam, &dummy_max);
347 check_wraith_form = FALSE;
351 spell_damcalc(m_ptr, GF_FIRE, dam, &dummy_max);
353 check_wraith_form = FALSE;
357 spell_damcalc(m_ptr, GF_COLD, dam, &dummy_max);
359 check_wraith_form = FALSE;
364 check_wraith_form = FALSE;
368 if (check_wraith_form && p_ptr->wraith_form)
377 spell_damcalc(m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
385 * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
386 * Examine the grid (xx,yy) and warn the player if there are any danger
387 * @param xx 危険性を調査するマスのX座標
388 * @param yy 危険性を調査するマスのY座標
389 * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
391 bool process_warning(POSITION xx, POSITION yy)
395 GAME_TEXT o_name[MAX_NLEN];
397 #define WARNING_AWARE_RANGE 12
399 static int old_damage = 0;
401 for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++)
403 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++)
409 if (!in_bounds(my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) continue;
411 g_ptr = ¤t_floor_ptr->grid_array[my][mx];
413 if (!g_ptr->m_idx) continue;
415 m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
417 if (MON_CSLEEP(m_ptr)) continue;
418 if (!is_hostile(m_ptr)) continue;
420 r_ptr = &r_info[m_ptr->r_idx];
422 /* Monster spells (only powerful ones)*/
423 if (projectable(my, mx, yy, xx))
425 BIT_FLAGS f4 = r_ptr->flags4;
426 BIT_FLAGS f5 = r_ptr->a_ability_flags1;
427 BIT_FLAGS f6 = r_ptr->a_ability_flags2;
429 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
431 if (f4 & RF4_BA_CHAO) spell_damcalc_by_spellnum(MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
432 if (f5 & RF5_BA_MANA) spell_damcalc_by_spellnum(MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
433 if (f5 & RF5_BA_DARK) spell_damcalc_by_spellnum(MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
434 if (f5 & RF5_BA_LITE) spell_damcalc_by_spellnum(MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
435 if (f6 & RF6_HAND_DOOM) spell_damcalc_by_spellnum(MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
436 if (f6 & RF6_PSY_SPEAR) spell_damcalc_by_spellnum(MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
438 if (f4 & RF4_ROCKET) spell_damcalc_by_spellnum(MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
439 if (f4 & RF4_BR_ACID) spell_damcalc_by_spellnum(MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
440 if (f4 & RF4_BR_ELEC) spell_damcalc_by_spellnum(MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
441 if (f4 & RF4_BR_FIRE) spell_damcalc_by_spellnum(MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
442 if (f4 & RF4_BR_COLD) spell_damcalc_by_spellnum(MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
443 if (f4 & RF4_BR_POIS) spell_damcalc_by_spellnum(MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
444 if (f4 & RF4_BR_NETH) spell_damcalc_by_spellnum(MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
445 if (f4 & RF4_BR_LITE) spell_damcalc_by_spellnum(MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
446 if (f4 & RF4_BR_DARK) spell_damcalc_by_spellnum(MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
447 if (f4 & RF4_BR_CONF) spell_damcalc_by_spellnum(MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
448 if (f4 & RF4_BR_SOUN) spell_damcalc_by_spellnum(MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
449 if (f4 & RF4_BR_CHAO) spell_damcalc_by_spellnum(MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
450 if (f4 & RF4_BR_DISE) spell_damcalc_by_spellnum(MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
451 if (f4 & RF4_BR_NEXU) spell_damcalc_by_spellnum(MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
452 if (f4 & RF4_BR_TIME) spell_damcalc_by_spellnum(MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
453 if (f4 & RF4_BR_INER) spell_damcalc_by_spellnum(MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
454 if (f4 & RF4_BR_GRAV) spell_damcalc_by_spellnum(MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
455 if (f4 & RF4_BR_SHAR) spell_damcalc_by_spellnum(MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
456 if (f4 & RF4_BR_PLAS) spell_damcalc_by_spellnum(MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
457 if (f4 & RF4_BR_WALL) spell_damcalc_by_spellnum(MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
458 if (f4 & RF4_BR_MANA) spell_damcalc_by_spellnum(MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
459 if (f4 & RF4_BR_NUKE) spell_damcalc_by_spellnum(MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
460 if (f4 & RF4_BR_DISI) spell_damcalc_by_spellnum(MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
463 /* Monster melee attacks */
464 if (!(r_ptr->flags1 & RF1_NEVER_BLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
466 if (mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)
470 for (m = 0; m < 4; m++)
472 /* Skip non-attacks */
473 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT)) continue;
475 /* Extract the attack info */
476 dam_melee += blow_damcalc(m_ptr, &r_ptr->blow[m]);
477 if (r_ptr->blow[m].method == RBM_EXPLODE) break;
479 if (dam_melee > dam_max0) dam_max0 = dam_melee;
483 /* Contribution from this monster */
488 /* Prevent excessive warning */
489 if (dam_max > old_damage)
491 old_damage = dam_max * 3 / 2;
493 if (dam_max > p_ptr->chp / 2)
495 object_type *o_ptr = choose_warning_item();
498 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
500 strcpy(o_name, _("体", "body")); /* Warning ability without item */
501 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
503 disturb(FALSE, TRUE);
504 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
507 else old_damage = old_damage / 2;
509 g_ptr = ¤t_floor_ptr->grid_array[yy][xx];
510 if (((!easy_disarm && is_trap(g_ptr->feat))
511 || (g_ptr->mimic && is_trap(g_ptr->feat))) && !one_in_(13))
513 object_type *o_ptr = choose_warning_item();
516 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
518 strcpy(o_name, _("体", "body")); /* Warning ability without item */
519 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
520 disturb(FALSE, TRUE);
521 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));