6 #include "player-move.h"
10 #include "player-status.h"
12 #include "monster-spell.h"
14 #include "object-flavor.h"
16 #include "player-race.h"
17 #include "player-class.h"
19 #include "realm-song.h"
22 * @brief 警告を放つアイテムを選択する /
23 * Choose one of items that have warning flag
24 * Calculate spell damages
27 object_type *choose_warning_item(player_type *creature_ptr)
29 int choices[INVEN_TOTAL - INVEN_RARM];
31 /* Paranoia -- Player has no warning ability */
32 if (!creature_ptr->warning) return NULL;
34 /* Search Inventory */
36 for (int i = INVEN_RARM; i < INVEN_TOTAL; i++)
38 BIT_FLAGS flgs[TR_FLAG_SIZE];
39 object_type *o_ptr = &creature_ptr->inventory_list[i];
41 object_flags(o_ptr, flgs);
42 if (have_flag(flgs, TR_WARNING))
49 /* Choice one of them */
50 return number ? &creature_ptr->inventory_list[choices[randint0(number)]] : NULL;
54 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する /
55 * Calculate spell damages
56 * @param m_ptr 魔法を行使するモンスターの構造体参照ポインタ
59 * @param max 算出した最大ダメージを返すポインタ
62 static void spell_damcalc(player_type *target_ptr, monster_type *m_ptr, EFFECT_ID typ, HIT_POINT dam, int *max)
64 monster_race *r_ptr = &r_info[m_ptr->r_idx];
65 int rlev = r_ptr->level;
66 bool ignore_wraith_form = FALSE;
68 /* Vulnerability, resistance and immunity */
72 if (target_ptr->immune_elec)
75 ignore_wraith_form = TRUE;
79 if (target_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
80 if (target_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
81 if (PRACE_IS_(target_ptr, RACE_ANDROID)) dam += dam / 3;
82 if (target_ptr->resist_elec) dam = (dam + 2) / 3;
83 if (is_oppose_elec(target_ptr)) dam = (dam + 2) / 3;
87 if (target_ptr->resist_pois) dam = (dam + 2) / 3;
88 if (is_oppose_pois(target_ptr)) dam = (dam + 2) / 3;
92 if (target_ptr->immune_acid)
95 ignore_wraith_form = TRUE;
99 if (target_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
100 if (target_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
101 if (target_ptr->resist_acid) dam = (dam + 2) / 3;
102 if (is_oppose_acid(target_ptr)) dam = (dam + 2) / 3;
107 if (target_ptr->immune_cold)
110 ignore_wraith_form = TRUE;
114 if (target_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
115 if (target_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
116 if (target_ptr->resist_cold) dam = (dam + 2) / 3;
117 if (is_oppose_cold(target_ptr)) dam = (dam + 2) / 3;
121 if (target_ptr->immune_fire)
124 ignore_wraith_form = TRUE;
128 if (target_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
129 if (PRACE_IS_(target_ptr, RACE_ENT)) dam += dam / 3;
130 if (target_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
131 if (target_ptr->resist_fire) dam = (dam + 2) / 3;
132 if (is_oppose_fire(target_ptr)) dam = (dam + 2) / 3;
136 ignore_wraith_form = TRUE;
140 if (!target_ptr->blind &&
141 ((target_ptr->inventory_list[INVEN_RARM].k_idx && (target_ptr->inventory_list[INVEN_RARM].name1 == ART_ZANTETSU)) ||
142 (target_ptr->inventory_list[INVEN_LARM].k_idx && (target_ptr->inventory_list[INVEN_LARM].name1 == ART_ZANTETSU))))
145 ignore_wraith_form = TRUE;
151 if (target_ptr->resist_lite) dam /= 2; /* Worst case of 4 / (d4 + 7) */
152 if (PRACE_IS_(target_ptr, RACE_VAMPIRE) || (target_ptr->mimic_form == MIMIC_VAMPIRE)) dam *= 2;
153 else if (PRACE_IS_(target_ptr, RACE_S_FAIRY)) dam = dam * 4 / 3;
155 if (target_ptr->wraith_form) dam *= 2;
159 if (PRACE_IS_(target_ptr, RACE_VAMPIRE) || (target_ptr->mimic_form == MIMIC_VAMPIRE) || target_ptr->wraith_form)
162 ignore_wraith_form = TRUE;
164 else if (target_ptr->resist_dark) dam /= 2; /* Worst case of 4 / (d4 + 7) */
168 if (target_ptr->resist_shard) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
172 if (target_ptr->resist_sound) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
176 if (target_ptr->resist_conf) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
180 if (target_ptr->resist_chaos) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
184 if (PRACE_IS_(target_ptr, RACE_SPECTRE))
187 ignore_wraith_form = TRUE;
189 else if (target_ptr->resist_neth) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
193 if (target_ptr->resist_disen) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
197 if (target_ptr->resist_nexus) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
201 if (target_ptr->resist_time) dam /= 2; /* Worst case of 4 / (d4 + 7) */
205 if (target_ptr->levitation) dam = (dam * 2) / 3;
209 if (target_ptr->resist_shard) dam /= 2;
213 if (target_ptr->resist_pois) dam = (2 * dam + 2) / 5;
214 if (is_oppose_pois(target_ptr)) dam = (2 * dam + 2) / 5;
218 if (target_ptr->mimic_form)
220 if (mimic_info[target_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING)
223 ignore_wraith_form = TRUE;
229 switch (target_ptr->prace)
238 ignore_wraith_form = TRUE;
245 if (target_ptr->align > 10) dam /= 2;
246 else if (target_ptr->align < -10) dam *= 2;
250 if (target_ptr->align > 10) dam *= 2;
255 if (100 + rlev / 2 <= MAX(5, target_ptr->skill_sav))
258 ignore_wraith_form = TRUE;
267 if (100 + rlev / 2 <= target_ptr->skill_sav)
270 ignore_wraith_form = TRUE;
276 if ((100 + rlev / 2 <= target_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU))
279 ignore_wraith_form = TRUE;
285 if (target_ptr->wraith_form && !ignore_wraith_form)
291 if (dam > *max) *max = dam;
295 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
296 * Calculate spell damages
297 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
299 * @param m_idx 魔法を行使するモンスターのID
300 * @param max 算出した最大ダメージを返すポインタ
303 void spell_damcalc_by_spellnum(player_type *creature_ptr, int spell_num, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
305 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[m_idx];
306 HIT_POINT dam = monspell_damage(creature_ptr, spell_num, m_idx, DAM_MAX);
307 spell_damcalc(creature_ptr, m_ptr, typ, dam, max);
311 * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
312 * Calculate blow damages
313 * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
314 * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
315 * @return 算出された最大ダメージを返す。
317 static int blow_damcalc(monster_type *m_ptr, player_type *target_ptr, monster_blow *blow_ptr)
319 int dam = blow_ptr->d_dice * blow_ptr->d_side;
322 if (blow_ptr->method == RBM_EXPLODE)
325 spell_damcalc(target_ptr, m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
330 ARMOUR_CLASS ac = target_ptr->ac + target_ptr->to_a;
331 bool check_wraith_form = TRUE;
332 switch (blow_ptr->effect)
336 int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
337 dam = MAX(dam, tmp_dam * 2);
343 dam -= (dam * ((ac < 150) ? ac : 150) / 250);
347 spell_damcalc(target_ptr, m_ptr, GF_ACID, dam, &dummy_max);
349 check_wraith_form = FALSE;
353 spell_damcalc(target_ptr, m_ptr, GF_ELEC, dam, &dummy_max);
355 check_wraith_form = FALSE;
359 spell_damcalc(target_ptr, m_ptr, GF_FIRE, dam, &dummy_max);
361 check_wraith_form = FALSE;
365 spell_damcalc(target_ptr, m_ptr, GF_COLD, dam, &dummy_max);
367 check_wraith_form = FALSE;
372 check_wraith_form = FALSE;
376 if (check_wraith_form && target_ptr->wraith_form)
387 * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
388 * Examine the grid (xx,yy) and warn the player if there are any danger
389 * @param xx 危険性を調査するマスのX座標
390 * @param yy 危険性を調査するマスのY座標
391 * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
393 bool process_warning(player_type *creature_ptr, POSITION xx, POSITION yy)
397 GAME_TEXT o_name[MAX_NLEN];
399 #define WARNING_AWARE_RANGE 12
401 static int old_damage = 0;
403 for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++)
405 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++)
411 if (!in_bounds(creature_ptr->current_floor_ptr, my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) continue;
413 g_ptr = &creature_ptr->current_floor_ptr->grid_array[my][mx];
415 if (!g_ptr->m_idx) continue;
417 m_ptr = &creature_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
419 if (MON_CSLEEP(m_ptr)) continue;
420 if (!is_hostile(m_ptr)) continue;
422 r_ptr = &r_info[m_ptr->r_idx];
424 /* Monster spells (only powerful ones)*/
425 if (projectable(creature_ptr, my, mx, yy, xx))
427 BIT_FLAGS f4 = r_ptr->flags4;
428 BIT_FLAGS f5 = r_ptr->a_ability_flags1;
429 BIT_FLAGS f6 = r_ptr->a_ability_flags2;
431 if (!(d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
433 if (f4 & RF4_BA_CHAO) spell_damcalc_by_spellnum(creature_ptr, MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
434 if (f5 & RF5_BA_MANA) spell_damcalc_by_spellnum(creature_ptr, MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
435 if (f5 & RF5_BA_DARK) spell_damcalc_by_spellnum(creature_ptr, MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
436 if (f5 & RF5_BA_LITE) spell_damcalc_by_spellnum(creature_ptr, MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
437 if (f6 & RF6_HAND_DOOM) spell_damcalc_by_spellnum(creature_ptr, MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
438 if (f6 & RF6_PSY_SPEAR) spell_damcalc_by_spellnum(creature_ptr, MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
441 if (f4 & RF4_ROCKET) spell_damcalc_by_spellnum(creature_ptr, MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
442 if (f4 & RF4_BR_ACID) spell_damcalc_by_spellnum(creature_ptr, MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
443 if (f4 & RF4_BR_ELEC) spell_damcalc_by_spellnum(creature_ptr, MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
444 if (f4 & RF4_BR_FIRE) spell_damcalc_by_spellnum(creature_ptr, MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
445 if (f4 & RF4_BR_COLD) spell_damcalc_by_spellnum(creature_ptr, MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
446 if (f4 & RF4_BR_POIS) spell_damcalc_by_spellnum(creature_ptr, MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
447 if (f4 & RF4_BR_NETH) spell_damcalc_by_spellnum(creature_ptr, MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
448 if (f4 & RF4_BR_LITE) spell_damcalc_by_spellnum(creature_ptr, MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
449 if (f4 & RF4_BR_DARK) spell_damcalc_by_spellnum(creature_ptr, MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
450 if (f4 & RF4_BR_CONF) spell_damcalc_by_spellnum(creature_ptr, MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
451 if (f4 & RF4_BR_SOUN) spell_damcalc_by_spellnum(creature_ptr, MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
452 if (f4 & RF4_BR_CHAO) spell_damcalc_by_spellnum(creature_ptr, MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
453 if (f4 & RF4_BR_DISE) spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
454 if (f4 & RF4_BR_NEXU) spell_damcalc_by_spellnum(creature_ptr, MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
455 if (f4 & RF4_BR_TIME) spell_damcalc_by_spellnum(creature_ptr, MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
456 if (f4 & RF4_BR_INER) spell_damcalc_by_spellnum(creature_ptr, MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
457 if (f4 & RF4_BR_GRAV) spell_damcalc_by_spellnum(creature_ptr, MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
458 if (f4 & RF4_BR_SHAR) spell_damcalc_by_spellnum(creature_ptr, MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
459 if (f4 & RF4_BR_PLAS) spell_damcalc_by_spellnum(creature_ptr, MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
460 if (f4 & RF4_BR_WALL) spell_damcalc_by_spellnum(creature_ptr, MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
461 if (f4 & RF4_BR_MANA) spell_damcalc_by_spellnum(creature_ptr, MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
462 if (f4 & RF4_BR_NUKE) spell_damcalc_by_spellnum(creature_ptr, MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
463 if (f4 & RF4_BR_DISI) spell_damcalc_by_spellnum(creature_ptr, MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
466 /* Monster melee attacks */
467 if ((r_ptr->flags1 & RF1_NEVER_BLOW) || (d_info[creature_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
473 if (!(mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1))
480 for (int m = 0; m < 4; m++)
482 /* Skip non-attacks */
483 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT)) continue;
485 /* Extract the attack info */
486 dam_melee += blow_damcalc(m_ptr, creature_ptr, &r_ptr->blow[m]);
487 if (r_ptr->blow[m].method == RBM_EXPLODE) break;
490 if (dam_melee > dam_max0) dam_max0 = dam_melee;
495 /* Prevent excessive warning */
496 if (dam_max > old_damage)
498 old_damage = dam_max * 3 / 2;
500 if (dam_max > creature_ptr->chp / 2)
502 object_type *o_ptr = choose_warning_item(creature_ptr);
505 object_desc(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
507 strcpy(o_name, _("体", "body")); /* Warning ability without item */
508 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
510 disturb(creature_ptr, FALSE, TRUE);
511 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
514 else old_damage = old_damage / 2;
516 g_ptr = &creature_ptr->current_floor_ptr->grid_array[yy][xx];
517 bool is_warning = (!easy_disarm && is_trap(creature_ptr, g_ptr->feat)) || (g_ptr->mimic && is_trap(creature_ptr, g_ptr->feat));
518 is_warning &= !one_in_(13);
519 if (!is_warning) return TRUE;
521 object_type *o_ptr = choose_warning_item(creature_ptr);
523 object_desc(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
525 strcpy(o_name, _("体", "body")); /* Warning ability without item */
526 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
527 disturb(creature_ptr, FALSE, TRUE);
528 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));