OSDN Git Service

[Refactor] #38997 PRACE_IS_ マクロに player_type の引数を追加.
[hengband/hengband.git] / src / warning.c
1 
2
3 #include "angband.h"
4 #include "util.h"
5
6 #include "artifact.h"
7 #include "player-move.h"
8 #include "feature.h"
9 #include "floor.h"
10 #include "warning.h"
11 #include "player-status.h"
12 #include "monster.h"
13 #include "monster-spell.h"
14 #include "spells.h"
15 #include "object-flavor.h"
16 #include "dungeon.h"
17 #include "player-race.h"
18 #include "player-class.h"
19 #include "melee.h"
20 #include "realm-song.h"
21
22 /*!
23  * @brief 警告を放つアイテムを選択する /
24  * Choose one of items that have warning flag
25  * Calculate spell damages
26  * @return 警告を行う
27  */
28 object_type *choose_warning_item(void)
29 {
30         int i;
31         int choices[INVEN_TOTAL - INVEN_RARM];
32         int number = 0;
33
34         /* Paranoia -- Player has no warning ability */
35         if (!p_ptr->warning) return NULL;
36
37         /* Search Inventory */
38         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
39         {
40                 BIT_FLAGS flgs[TR_FLAG_SIZE];
41                 object_type *o_ptr = &p_ptr->inventory_list[i];
42
43                 object_flags(o_ptr, flgs);
44                 if (have_flag(flgs, TR_WARNING))
45                 {
46                         choices[number] = i;
47                         number++;
48                 }
49         }
50
51         /* Choice one of them */
52         return number ? &p_ptr->inventory_list[choices[randint0(number)]] : NULL;
53 }
54
55 /*!
56  * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する /
57  * Calculate spell damages
58  * @param m_ptr 魔法を行使するモンスターの構造体参照ポインタ
59  * @param typ 効果属性のID
60  * @param dam 基本ダメージ
61  * @param max 算出した最大ダメージを返すポインタ
62  * @return なし
63  */
64 static void spell_damcalc(monster_type *m_ptr, EFFECT_ID typ, HIT_POINT dam, int *max)
65 {
66         monster_race *r_ptr = &r_info[m_ptr->r_idx];
67         int          rlev = r_ptr->level;
68         bool         ignore_wraith_form = FALSE;
69
70         /* Vulnerability, resistance and immunity */
71         switch (typ)
72         {
73         case GF_ELEC:
74                 if (p_ptr->immune_elec)
75                 {
76                         dam = 0;
77                         ignore_wraith_form = TRUE;
78                 }
79                 else
80                 {
81                         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
82                         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
83                         if (PRACE_IS_(p_ptr, RACE_ANDROID)) dam += dam / 3;
84                         if (p_ptr->resist_elec) dam = (dam + 2) / 3;
85                         if (IS_OPPOSE_ELEC())
86                                 dam = (dam + 2) / 3;
87                 }
88                 break;
89
90         case GF_POIS:
91                 if (p_ptr->resist_pois) dam = (dam + 2) / 3;
92                 if (IS_OPPOSE_POIS()) dam = (dam + 2) / 3;
93                 break;
94
95         case GF_ACID:
96                 if (p_ptr->immune_acid)
97                 {
98                         dam = 0;
99                         ignore_wraith_form = TRUE;
100                 }
101                 else
102                 {
103                         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
104                         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
105                         if (p_ptr->resist_acid) dam = (dam + 2) / 3;
106                         if (IS_OPPOSE_ACID()) dam = (dam + 2) / 3;
107                 }
108                 break;
109
110         case GF_COLD:
111         case GF_ICE:
112                 if (p_ptr->immune_cold)
113                 {
114                         dam = 0;
115                         ignore_wraith_form = TRUE;
116                 }
117                 else
118                 {
119                         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
120                         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
121                         if (p_ptr->resist_cold) dam = (dam + 2) / 3;
122                         if (IS_OPPOSE_COLD()) dam = (dam + 2) / 3;
123                 }
124                 break;
125
126         case GF_FIRE:
127                 if (p_ptr->immune_fire)
128                 {
129                         dam = 0;
130                         ignore_wraith_form = TRUE;
131                 }
132                 else
133                 {
134                         if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
135                         if (PRACE_IS_(p_ptr, RACE_ENT)) dam += dam / 3;
136                         if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
137                         if (p_ptr->resist_fire) dam = (dam + 2) / 3;
138                         if (IS_OPPOSE_FIRE()) dam = (dam + 2) / 3;
139                 }
140                 break;
141
142         case GF_PSY_SPEAR:
143                 ignore_wraith_form = TRUE;
144                 break;
145
146         case GF_ARROW:
147                 if (!p_ptr->blind &&
148                         ((p_ptr->inventory_list[INVEN_RARM].k_idx && (p_ptr->inventory_list[INVEN_RARM].name1 == ART_ZANTETSU)) ||
149                         (p_ptr->inventory_list[INVEN_LARM].k_idx && (p_ptr->inventory_list[INVEN_LARM].name1 == ART_ZANTETSU))))
150                 {
151                         dam = 0;
152                         ignore_wraith_form = TRUE;
153                 }
154                 break;
155
156         case GF_LITE:
157                 if (p_ptr->resist_lite) dam /= 2; /* Worst case of 4 / (d4 + 7) */
158                 if (PRACE_IS_(p_ptr, RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE)) dam *= 2;
159                 else if (PRACE_IS_(p_ptr, RACE_S_FAIRY)) dam = dam * 4 / 3;
160
161                 /*
162                  * Cannot use "ignore_wraith_form" strictly (for "random one damage")
163                  * "dam *= 2;" for later "dam /= 2"
164                  */
165                 if (p_ptr->wraith_form) dam *= 2;
166                 break;
167
168         case GF_DARK:
169                 if (PRACE_IS_(p_ptr, RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE) || p_ptr->wraith_form)
170                 {
171                         dam = 0;
172                         ignore_wraith_form = TRUE;
173                 }
174                 else if (p_ptr->resist_dark) dam /= 2; /* Worst case of 4 / (d4 + 7) */
175                 break;
176
177         case GF_SHARDS:
178                 if (p_ptr->resist_shard) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
179                 break;
180
181         case GF_SOUND:
182                 if (p_ptr->resist_sound) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
183                 break;
184
185         case GF_CONFUSION:
186                 if (p_ptr->resist_conf) dam = dam * 5 / 8; /* Worst case of 5 / (d4 + 7) */
187                 break;
188
189         case GF_CHAOS:
190                 if (p_ptr->resist_chaos) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
191                 break;
192
193         case GF_NETHER:
194                 if (PRACE_IS_(p_ptr, RACE_SPECTRE))
195                 {
196                         dam = 0;
197                         ignore_wraith_form = TRUE;
198                 }
199                 else if (p_ptr->resist_neth) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
200                 break;
201
202         case GF_DISENCHANT:
203                 if (p_ptr->resist_disen) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
204                 break;
205
206         case GF_NEXUS:
207                 if (p_ptr->resist_nexus) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
208                 break;
209
210         case GF_TIME:
211                 if (p_ptr->resist_time) dam /= 2; /* Worst case of 4 / (d4 + 7) */
212                 break;
213
214         case GF_GRAVITY:
215                 if (p_ptr->levitation) dam = (dam * 2) / 3;
216                 break;
217
218         case GF_ROCKET:
219                 if (p_ptr->resist_shard) dam /= 2;
220                 break;
221
222         case GF_NUKE:
223                 if (p_ptr->resist_pois) dam = (2 * dam + 2) / 5;
224                 if (IS_OPPOSE_POIS()) dam = (2 * dam + 2) / 5;
225                 break;
226
227         case GF_DEATH_RAY:
228                 if (p_ptr->mimic_form)
229                 {
230                         if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING)
231                         {
232                                 dam = 0;
233                                 ignore_wraith_form = TRUE;
234                         }
235                 }
236                 else
237                 {
238                         switch (p_ptr->prace)
239                         {
240                         case RACE_GOLEM:
241                         case RACE_SKELETON:
242                         case RACE_ZOMBIE:
243                         case RACE_VAMPIRE:
244                         case RACE_DEMON:
245                         case RACE_SPECTRE:
246                                 dam = 0;
247                                 ignore_wraith_form = TRUE;
248                                 break;
249                         }
250                 }
251                 break;
252
253         case GF_HOLY_FIRE:
254                 if (p_ptr->align > 10) dam /= 2;
255                 else if (p_ptr->align < -10) dam *= 2;
256                 break;
257
258         case GF_HELL_FIRE:
259                 if (p_ptr->align > 10) dam *= 2;
260                 break;
261
262         case GF_MIND_BLAST:
263         case GF_BRAIN_SMASH:
264                 if (100 + rlev / 2 <= MAX(5, p_ptr->skill_sav))
265                 {
266                         dam = 0;
267                         ignore_wraith_form = TRUE;
268                 }
269                 break;
270
271         case GF_CAUSE_1:
272         case GF_CAUSE_2:
273         case GF_CAUSE_3:
274         case GF_HAND_DOOM:
275                 if (100 + rlev / 2 <= p_ptr->skill_sav)
276                 {
277                         dam = 0;
278                         ignore_wraith_form = TRUE;
279                 }
280                 break;
281
282         case GF_CAUSE_4:
283                 if ((100 + rlev / 2 <= p_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU))
284                 {
285                         dam = 0;
286                         ignore_wraith_form = TRUE;
287                 }
288                 break;
289         }
290
291         if (p_ptr->wraith_form && !ignore_wraith_form)
292         {
293                 dam /= 2;
294                 if (!dam) dam = 1;
295         }
296
297         if (dam > *max) *max = dam;
298 }
299
300 /*!
301 * @brief 警告基準を定めるために魔法の効果属性に基づいて最大魔法ダメージを計算する。 /
302 * Calculate spell damages
303 * @param spell_num RF4ならRF4_SPELL_STARTのように32区切りのベースとなる数値
304 * @param typ 効果属性のID
305 * @param m_idx 魔法を行使するモンスターのID
306 * @param max 算出した最大ダメージを返すポインタ
307 * @return なし
308 */
309 void spell_damcalc_by_spellnum(int spell_num, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
310 {
311         monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
312         HIT_POINT dam = monspell_damage((spell_num), m_idx, DAM_MAX);
313         spell_damcalc(m_ptr, typ, dam, max);
314 }
315
316 /*!
317  * @brief 警告基準を定めるためにモンスターの打撃最大ダメージを算出する /
318  * Calculate blow damages
319  * @param m_ptr 打撃を行使するモンスターの構造体参照ポインタ
320  * @param blow_ptr モンスターの打撃能力の構造体参照ポインタ
321  * @return 算出された最大ダメージを返す。
322  */
323 static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
324 {
325         int  dam = blow_ptr->d_dice * blow_ptr->d_side;
326         int  dummy_max = 0;
327         bool check_wraith_form = TRUE;
328
329         if (blow_ptr->method != RBM_EXPLODE)
330         {
331                 ARMOUR_CLASS ac = p_ptr->ac + p_ptr->to_a;
332
333                 switch (blow_ptr->effect)
334                 {
335                 case RBE_SUPERHURT:
336                 {
337                         int tmp_dam = dam - (dam * ((ac < 150) ? ac : 150) / 250);
338                         dam = MAX(dam, tmp_dam * 2);
339                         break;
340                 }
341
342                 case RBE_HURT:
343                 case RBE_SHATTER:
344                         dam -= (dam * ((ac < 150) ? ac : 150) / 250);
345                         break;
346
347                 case RBE_ACID:
348                         spell_damcalc(m_ptr, GF_ACID, dam, &dummy_max);
349                         dam = dummy_max;
350                         check_wraith_form = FALSE;
351                         break;
352
353                 case RBE_ELEC:
354                         spell_damcalc(m_ptr, GF_ELEC, dam, &dummy_max);
355                         dam = dummy_max;
356                         check_wraith_form = FALSE;
357                         break;
358
359                 case RBE_FIRE:
360                         spell_damcalc(m_ptr, GF_FIRE, dam, &dummy_max);
361                         dam = dummy_max;
362                         check_wraith_form = FALSE;
363                         break;
364
365                 case RBE_COLD:
366                         spell_damcalc(m_ptr, GF_COLD, dam, &dummy_max);
367                         dam = dummy_max;
368                         check_wraith_form = FALSE;
369                         break;
370
371                 case RBE_DR_MANA:
372                         dam = 0;
373                         check_wraith_form = FALSE;
374                         break;
375                 }
376
377                 if (check_wraith_form && p_ptr->wraith_form)
378                 {
379                         dam /= 2;
380                         if (!dam) dam = 1;
381                 }
382         }
383         else
384         {
385                 dam = (dam + 1) / 2;
386                 spell_damcalc(m_ptr, mbe_info[blow_ptr->effect].explode_type, dam, &dummy_max);
387                 dam = dummy_max;
388         }
389
390         return dam;
391 }
392
393 /*!
394  * @brief プレイヤーが特定地点へ移動した場合に警告を発する処理 /
395  * Examine the grid (xx,yy) and warn the player if there are any danger
396  * @param xx 危険性を調査するマスのX座標
397  * @param yy 危険性を調査するマスのY座標
398  * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
399  */
400 bool process_warning(POSITION xx, POSITION yy)
401 {
402         POSITION mx, my;
403         grid_type *g_ptr;
404         GAME_TEXT o_name[MAX_NLEN];
405
406 #define WARNING_AWARE_RANGE 12
407         int dam_max = 0;
408         static int old_damage = 0;
409
410         for (mx = xx - WARNING_AWARE_RANGE; mx < xx + WARNING_AWARE_RANGE + 1; mx++)
411         {
412                 for (my = yy - WARNING_AWARE_RANGE; my < yy + WARNING_AWARE_RANGE + 1; my++)
413                 {
414                         int dam_max0 = 0;
415                         monster_type *m_ptr;
416                         monster_race *r_ptr;
417
418                         if (!in_bounds(my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) continue;
419
420                         g_ptr = &current_floor_ptr->grid_array[my][mx];
421
422                         if (!g_ptr->m_idx) continue;
423
424                         m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
425
426                         if (MON_CSLEEP(m_ptr)) continue;
427                         if (!is_hostile(m_ptr)) continue;
428
429                         r_ptr = &r_info[m_ptr->r_idx];
430
431                         /* Monster spells (only powerful ones)*/
432                         if (projectable(my, mx, yy, xx))
433                         {
434                                 BIT_FLAGS f4 = r_ptr->flags4;
435                                 BIT_FLAGS f5 = r_ptr->a_ability_flags1;
436                                 BIT_FLAGS f6 = r_ptr->a_ability_flags2;
437
438                                 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
439                                 {
440                                         if (f4 & RF4_BA_CHAO) spell_damcalc_by_spellnum(MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
441                                         if (f5 & RF5_BA_MANA) spell_damcalc_by_spellnum(MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
442                                         if (f5 & RF5_BA_DARK) spell_damcalc_by_spellnum(MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
443                                         if (f5 & RF5_BA_LITE) spell_damcalc_by_spellnum(MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
444                                         if (f6 & RF6_HAND_DOOM) spell_damcalc_by_spellnum(MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
445                                         if (f6 & RF6_PSY_SPEAR) spell_damcalc_by_spellnum(MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
446                                 }
447                                 if (f4 & RF4_ROCKET) spell_damcalc_by_spellnum(MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
448                                 if (f4 & RF4_BR_ACID) spell_damcalc_by_spellnum(MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
449                                 if (f4 & RF4_BR_ELEC) spell_damcalc_by_spellnum(MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
450                                 if (f4 & RF4_BR_FIRE) spell_damcalc_by_spellnum(MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
451                                 if (f4 & RF4_BR_COLD) spell_damcalc_by_spellnum(MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
452                                 if (f4 & RF4_BR_POIS) spell_damcalc_by_spellnum(MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
453                                 if (f4 & RF4_BR_NETH) spell_damcalc_by_spellnum(MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
454                                 if (f4 & RF4_BR_LITE) spell_damcalc_by_spellnum(MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
455                                 if (f4 & RF4_BR_DARK) spell_damcalc_by_spellnum(MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
456                                 if (f4 & RF4_BR_CONF) spell_damcalc_by_spellnum(MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
457                                 if (f4 & RF4_BR_SOUN) spell_damcalc_by_spellnum(MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
458                                 if (f4 & RF4_BR_CHAO) spell_damcalc_by_spellnum(MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
459                                 if (f4 & RF4_BR_DISE) spell_damcalc_by_spellnum(MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
460                                 if (f4 & RF4_BR_NEXU) spell_damcalc_by_spellnum(MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
461                                 if (f4 & RF4_BR_TIME) spell_damcalc_by_spellnum(MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
462                                 if (f4 & RF4_BR_INER) spell_damcalc_by_spellnum(MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
463                                 if (f4 & RF4_BR_GRAV) spell_damcalc_by_spellnum(MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
464                                 if (f4 & RF4_BR_SHAR) spell_damcalc_by_spellnum(MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
465                                 if (f4 & RF4_BR_PLAS) spell_damcalc_by_spellnum(MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
466                                 if (f4 & RF4_BR_WALL) spell_damcalc_by_spellnum(MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
467                                 if (f4 & RF4_BR_MANA) spell_damcalc_by_spellnum(MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
468                                 if (f4 & RF4_BR_NUKE) spell_damcalc_by_spellnum(MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
469                                 if (f4 & RF4_BR_DISI) spell_damcalc_by_spellnum(MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
470                         }
471
472                         /* Monster melee attacks */
473                         if (!(r_ptr->flags1 & RF1_NEVER_BLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
474                         {
475                                 if (mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)
476                                 {
477                                         int m;
478                                         int dam_melee = 0;
479                                         for (m = 0; m < 4; m++)
480                                         {
481                                                 /* Skip non-attacks */
482                                                 if (!r_ptr->blow[m].method || (r_ptr->blow[m].method == RBM_SHOOT)) continue;
483
484                                                 /* Extract the attack info */
485                                                 dam_melee += blow_damcalc(m_ptr, &r_ptr->blow[m]);
486                                                 if (r_ptr->blow[m].method == RBM_EXPLODE) break;
487                                         }
488                                         if (dam_melee > dam_max0) dam_max0 = dam_melee;
489                                 }
490                         }
491
492                         /* Contribution from this monster */
493                         dam_max += dam_max0;
494                 }
495         }
496
497         /* Prevent excessive warning */
498         if (dam_max > old_damage)
499         {
500                 old_damage = dam_max * 3 / 2;
501
502                 if (dam_max > p_ptr->chp / 2)
503                 {
504                         object_type *o_ptr = choose_warning_item();
505
506                         if (o_ptr)
507                                 object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
508                         else
509                                 strcpy(o_name, _("体", "body")); /* Warning ability without item */
510                         msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
511
512                         disturb(FALSE, TRUE);
513                         return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
514                 }
515         }
516         else old_damage = old_damage / 2;
517
518         g_ptr = &current_floor_ptr->grid_array[yy][xx];
519         if (((!easy_disarm && is_trap(g_ptr->feat))
520                 || (g_ptr->mimic && is_trap(g_ptr->feat))) && !one_in_(13))
521         {
522                 object_type *o_ptr = choose_warning_item();
523
524                 if (o_ptr)
525                         object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
526                 else
527                         strcpy(o_name, _("体", "body")); /* Warning ability without item */
528                 msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
529                 disturb(FALSE, TRUE);
530                 return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
531         }
532
533         return TRUE;
534 }
535