7 #include "player-move.h"
11 #include "player-status.h"
13 #include "monster-spell.h"
15 #include "object-flavor.h"
19 * @brief 警告を放つアイテムを選択する /
20 * Choose one of items that have warning flag
21 * Calculate spell damages
24 object_type *choose_warning_item(void)
27 int choices[INVEN_TOTAL - INVEN_RARM];
30 /* Paranoia -- Player has no warning ability */
31 if (!p_ptr->warning) return NULL;
33 /* Search Inventory */
34 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
36 BIT_FLAGS flgs[TR_FLAG_SIZE];
37 object_type *o_ptr = &inventory[i];
39 object_flags(o_ptr, flgs);
40 if (have_flag(flgs, TR_WARNING))
47 /* Choice one of them */
48 return number ? &inventory[choices[randint0(number)]] : NULL;
52 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する /
53 * Calculate spell damages
54 * @param m_ptr 魔法を行使するモンスターの構造体参照ポインタ
57 * @param max 算出した最大ダメージを返すポインタ
60 static void spell_damcalc(monster_type *m_ptr, EFFECT_ID typ, HIT_POINT dam, int *max)
62 monster_race *r_ptr = &r_info[m_ptr->r_idx];
63 int rlev = r_ptr->level;
64 bool ignore_wraith_form = FALSE;
66 /* Vulnerability, resistance and immunity */
70 if (p_ptr->immune_elec)
73 ignore_wraith_form = TRUE;
77 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
78 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
79 if (prace_is_(RACE_ANDROID)) dam += dam / 3;
80 if (p_ptr->resist_elec) dam = (dam + 2) / 3;
87 if (p_ptr->resist_pois) dam = (dam + 2) / 3;
88 if (IS_OPPOSE_POIS()) dam = (dam + 2) / 3;
92 if (p_ptr->immune_acid)
95 ignore_wraith_form = TRUE;
99 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
100 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
101 if (p_ptr->resist_acid) dam = (dam + 2) / 3;
102 if (IS_OPPOSE_ACID()) dam = (dam + 2) / 3;
108 if (p_ptr->immune_cold)
111 ignore_wraith_form = TRUE;
115 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
116 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
117 if (p_ptr->resist_cold) dam = (dam + 2) / 3;
118 if (IS_OPPOSE_COLD()) dam = (dam + 2) / 3;
123 if (p_ptr->immune_fire)
126 ignore_wraith_form = TRUE;
130 if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
131 if (prace_is_(RACE_ENT)) dam += dam / 3;
132 if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
133 if (p_ptr->resist_fire) dam = (dam + 2) / 3;
134 if (IS_OPPOSE_FIRE()) dam = (dam + 2) / 3;
139 ignore_wraith_form = TRUE;
144 ((inventory[INVEN_RARM].k_idx && (inventory[INVEN_RARM].name1 == ART_ZANTETSU)) ||
145 (inventory[INVEN_LARM].k_idx && (inventory[INVEN_LARM].name1 == ART_ZANTETSU))))
148 ignore_wraith_form = TRUE;
153 if (p_ptr->resist_lite) dam /= 2; /* Worst case of 4 / (d4 + 7) */
154 if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE)) dam *= 2;
155 else if (prace_is_(RACE_S_FAIRY)) dam = dam * 4 / 3;
158 * Cannot use "ignore_wraith_form" strictly (for "random one damage")
159 * "dam *= 2;" for later "dam /= 2"
161 if (p_ptr->wraith_form) dam *= 2;
165 if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE) || p_ptr->wraith_form)
168 ignore_wraith_form = TRUE;
170 else if (p_ptr->resist_dark) dam /= 2; /* Worst case of 4 / (d4 + 7) */
174 if (p_ptr->resist_shard) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
178 if (p_ptr->resist_sound) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
182 if (p_ptr->resist_conf) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
186 if (p_ptr->resist_chaos) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
190 if (prace_is_(RACE_SPECTRE))
193 ignore_wraith_form = TRUE;
195 else if (p_ptr->resist_neth) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
199 if (p_ptr->resist_disen) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
203 if (p_ptr->resist_nexus) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
207 if (p_ptr->resist_time) dam /= 2; /* Worst case of 4 / (d4 + 7) */
211 if (p_ptr->levitation) dam = (dam * 2) / 3;
215 if (p_ptr->resist_shard) dam /= 2;
219 if (p_ptr->resist_pois) dam = (2 * dam + 2) / 5;
220 if (IS_OPPOSE_POIS()) dam = (2 * dam + 2) / 5;
224 if (p_ptr->mimic_form)
226 if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING)
229 ignore_wraith_form = TRUE;
234 switch (p_ptr->prace)
243 ignore_wraith_form = TRUE;
250 if (p_ptr->align > 10) dam /= 2;
251 else if (p_ptr->align < -10) dam *= 2;
255 if (p_ptr->align > 10) dam *= 2;
260 if (100 + rlev / 2 <= MAX(5, p_ptr->skill_sav))
263 ignore_wraith_form = TRUE;
271 if (100 + rlev / 2 <= p_ptr->skill_sav)
274 ignore_wraith_form = TRUE;
279 if ((100 + rlev / 2 <= p_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU))
282 ignore_wraith_form = TRUE;
287 if (p_ptr->wraith_form && !ignore_wraith_form)
293 if (dam > *max) *max = dam;
297 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
298 * Calculate spell damages
299 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
301 * @param m_idx 魔法を行使するモンスターのID
302 * @param max 算出した最大ダメージを返すポインタ
305 void spell_damcalc_by_spellnum(int spell_num, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
307 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
308 HIT_POINT dam = monspell_damage((spell_num), m_idx, DAM_MAX);
309 spell_damcalc(m_ptr, typ, dam, max);
313 * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
314 * Calculate blow damages
315 * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
316 * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
317 * @return 算出された最大ダメージを返す。
319 static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
321 int dam = blow_ptr->d_dice * blow_ptr->d_side;
323 bool check_wraith_form = TRUE;
325 if (blow_ptr->method != RBM_EXPLODE)
327 ARMOUR_CLASS ac = p_ptr->ac + p_ptr->to_a;
329 switch (blow_ptr->effect)
333 int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
334 dam = MAX(dam, tmp_dam * 2);
340 dam -= (dam * ((ac < 150) ? ac : 150) / 250);
344 spell_damcalc(m_ptr, GF_ACID, dam, &dummy_max);
346 check_wraith_form = FALSE;
350 spell_damcalc(m_ptr, GF_ELEC, dam, &dummy_max);
352 check_wraith_form = FALSE;
356 spell_damcalc(m_ptr, GF_FIRE, dam, &dummy_max);
358 check_wraith_form = FALSE;
362 spell_damcalc(m_ptr, GF_COLD, dam, &dummy_max);
364 check_wraith_form = FALSE;
369 check_wraith_form = FALSE;
373 if (check_wraith_form && p_ptr->wraith_form)
382 spell_damcalc(m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
390 * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
391 * Examine the grid (xx,yy) and warn the player if there are any danger
392 * @param xx 危険性を調査するマスのX座標
393 * @param yy 危険性を調査するマスのY座標
394 * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
396 bool process_warning(POSITION xx, POSITION yy)
400 GAME_TEXT o_name[MAX_NLEN];
402 #define WARNING_AWARE_RANGE 12
404 static int old_damage = 0;
406 for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++)
408 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++)
414 if (!in_bounds(my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) continue;
416 g_ptr = ¤t_floor_ptr->grid_array[my][mx];
418 if (!g_ptr->m_idx) continue;
420 m_ptr = ¤t_floor_ptr->m_list[g_ptr->m_idx];
422 if (MON_CSLEEP(m_ptr)) continue;
423 if (!is_hostile(m_ptr)) continue;
425 r_ptr = &r_info[m_ptr->r_idx];
427 /* Monster spells (only powerful ones)*/
428 if (projectable(my, mx, yy, xx))
430 BIT_FLAGS f4 = r_ptr->flags4;
431 BIT_FLAGS f5 = r_ptr->a_ability_flags1;
432 BIT_FLAGS f6 = r_ptr->a_ability_flags2;
434 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
436 if (f4 & RF4_BA_CHAO) spell_damcalc_by_spellnum(MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
437 if (f5 & RF5_BA_MANA) spell_damcalc_by_spellnum(MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
438 if (f5 & RF5_BA_DARK) spell_damcalc_by_spellnum(MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
439 if (f5 & RF5_BA_LITE) spell_damcalc_by_spellnum(MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
440 if (f6 & RF6_HAND_DOOM) spell_damcalc_by_spellnum(MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
441 if (f6 & RF6_PSY_SPEAR) spell_damcalc_by_spellnum(MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
443 if (f4 & RF4_ROCKET) spell_damcalc_by_spellnum(MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
444 if (f4 & RF4_BR_ACID) spell_damcalc_by_spellnum(MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
445 if (f4 & RF4_BR_ELEC) spell_damcalc_by_spellnum(MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
446 if (f4 & RF4_BR_FIRE) spell_damcalc_by_spellnum(MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
447 if (f4 & RF4_BR_COLD) spell_damcalc_by_spellnum(MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
448 if (f4 & RF4_BR_POIS) spell_damcalc_by_spellnum(MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
449 if (f4 & RF4_BR_NETH) spell_damcalc_by_spellnum(MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
450 if (f4 & RF4_BR_LITE) spell_damcalc_by_spellnum(MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
451 if (f4 & RF4_BR_DARK) spell_damcalc_by_spellnum(MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
452 if (f4 & RF4_BR_CONF) spell_damcalc_by_spellnum(MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
453 if (f4 & RF4_BR_SOUN) spell_damcalc_by_spellnum(MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
454 if (f4 & RF4_BR_CHAO) spell_damcalc_by_spellnum(MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
455 if (f4 & RF4_BR_DISE) spell_damcalc_by_spellnum(MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
456 if (f4 & RF4_BR_NEXU) spell_damcalc_by_spellnum(MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
457 if (f4 & RF4_BR_TIME) spell_damcalc_by_spellnum(MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
458 if (f4 & RF4_BR_INER) spell_damcalc_by_spellnum(MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
459 if (f4 & RF4_BR_GRAV) spell_damcalc_by_spellnum(MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
460 if (f4 & RF4_BR_SHAR) spell_damcalc_by_spellnum(MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
461 if (f4 & RF4_BR_PLAS) spell_damcalc_by_spellnum(MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
462 if (f4 & RF4_BR_WALL) spell_damcalc_by_spellnum(MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
463 if (f4 & RF4_BR_MANA) spell_damcalc_by_spellnum(MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
464 if (f4 & RF4_BR_NUKE) spell_damcalc_by_spellnum(MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
465 if (f4 & RF4_BR_DISI) spell_damcalc_by_spellnum(MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
468 /* Monster melee attacks */
469 if (!(r_ptr->flags1 & RF1_NEVER_BLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
471 if (mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)
475 for (m = 0; m < 4; m++)
477 /* Skip non-attacks */
478 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT)) continue;
480 /* Extract the attack info */
481 dam_melee += blow_damcalc(m_ptr, &r_ptr->blow[m]);
482 if (r_ptr->blow[m].method == RBM_EXPLODE) break;
484 if (dam_melee > dam_max0) dam_max0 = dam_melee;
488 /* Contribution from this monster */
493 /* Prevent excessive warning */
494 if (dam_max > old_damage)
496 old_damage = dam_max * 3 / 2;
498 if (dam_max > p_ptr->chp / 2)
500 object_type *o_ptr = choose_warning_item();
503 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
505 strcpy(o_name, _("体", "body")); /* Warning ability without item */
506 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
508 disturb(FALSE, TRUE);
509 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
512 else old_damage = old_damage / 2;
514 g_ptr = ¤t_floor_ptr->grid_array[yy][xx];
515 if (((!easy_disarm && is_trap(g_ptr->feat))
516 || (g_ptr->mimic && is_trap(g_ptr->feat))) && !one_in_(13))
518 object_type *o_ptr = choose_warning_item();
521 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
523 strcpy(o_name, _("体", "body")); /* Warning ability without item */
524 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
525 disturb(FALSE, TRUE);
526 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));