1 #include "player/player-status-resist.h"
2 #include "player/mimic-info-table.h"
3 #include "art-definition/art-sword-types.h"
5 #include "inventory/inventory-slot-types.h"
6 #include "monster-race/monster-race.h"
7 #include "monster-race/race-flags2.h"
8 #include "monster-race/race-flags7.h"
9 #include "mutation/mutation-flag-types.h"
10 #include "object-enchant/object-ego.h"
11 #include "object-enchant/tr-types.h"
12 #include "object-enchant/trc-types.h"
13 #include "object-hook/hook-checker.h"
14 #include "object-hook/hook-weapon.h"
15 #include "object/object-flags.h"
16 #include "player/player-class.h"
17 #include "player/player-race-types.h"
18 #include "player/player-race.h"
19 #include "player/player-skill.h"
20 #include "player/player-status-flags.h"
21 #include "player/player-status.h"
22 #include "player/special-defense-types.h"
23 #include "realm/realm-hex-numbers.h"
24 #include "realm/realm-song-numbers.h"
25 #include "realm/realm-types.h"
26 #include "spell-realm/spells-hex.h"
27 #include "status/element-resistance.h"
28 #include "sv-definition/sv-weapon-types.h"
29 #include "system/floor-type-definition.h"
30 #include "system/monster-type-definition.h"
31 #include "system/object-type-definition.h"
32 #include "util/bit-flags-calculator.h"
33 #include "util/quarks.h"
34 #include "util/string-processor.h"
36 PERCENTAGE randrate(int dice, int fix, rate_calc_type_mode mode)
40 return randint1(dice) * 100 + fix * 100;
43 return (dice + 1) * 50 + fix * 100;
46 return (fix + 1) * 100;
49 return (dice + fix) * 100;
52 return (fix + 1) * 100;
57 PERCENTAGE calc_acid_damage_rate(player_type *creature_ptr)
62 if (is_immune_acid(creature_ptr)) {
66 BIT_FLAGS flgs = is_vuln_acid(creature_ptr);
67 for (i = 0; i < FLAG_CAUSE_MAX; i++) {
68 if (flgs & (0x01 << i)) {
69 if (i == FLAG_CAUSE_MUTATION) {
77 if (creature_ptr->resist_acid)
79 if (is_oppose_acid(creature_ptr))
85 PERCENTAGE calc_elec_damage_rate(player_type *creature_ptr)
90 if (is_immune_elec(creature_ptr)) {
94 BIT_FLAGS flgs = is_vuln_elec(creature_ptr);
95 for (i = 0; i < FLAG_CAUSE_MAX; i++) {
96 if (flgs & (0x01 << i)) {
97 if (i == FLAG_CAUSE_MUTATION) {
105 if (creature_ptr->resist_elec)
107 if (is_oppose_elec(creature_ptr))
113 PERCENTAGE calc_fire_damage_rate(player_type *creature_ptr)
115 PERCENTAGE per = 100;
117 BIT_FLAGS flgs = is_vuln_fire(creature_ptr);
118 for (i = 0; i < FLAG_CAUSE_MAX; i++) {
119 if (flgs & (0x01 << i)) {
120 if (i == FLAG_CAUSE_MUTATION) {
128 /* Resist the damage */
129 if (creature_ptr->resist_fire)
131 if (is_oppose_fire(creature_ptr))
137 PERCENTAGE calc_cold_damage_rate(player_type *creature_ptr)
139 PERCENTAGE per = 100;
141 BIT_FLAGS flgs = is_vuln_cold(creature_ptr);
142 for (i = 0; i < FLAG_CAUSE_MAX; i++) {
143 if (flgs & (0x01 << i)) {
144 if (i == FLAG_CAUSE_MUTATION) {
152 if (creature_ptr->resist_cold)
154 if (is_oppose_cold(creature_ptr))
160 PERCENTAGE calc_pois_damage_rate(player_type *creature_ptr)
162 PERCENTAGE per = 100;
163 if (creature_ptr->resist_pois)
165 if (is_oppose_pois(creature_ptr))
171 PERCENTAGE calc_nuke_damage_rate(player_type *creature_ptr)
174 PERCENTAGE per = 100;
175 if (creature_ptr->resist_pois)
176 per = (2 * per + 2) / 5;
177 if (is_oppose_pois(creature_ptr))
178 per = (2 * per + 2) / 5;
183 PERCENTAGE calc_deathray_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
186 if (creature_ptr->mimic_form) {
187 if (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) {
192 switch (creature_ptr->prace) {
206 PERCENTAGE calc_lite_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
208 PERCENTAGE per = 100;
209 if (is_specific_player_race(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE)) {
211 } else if (is_specific_player_race(creature_ptr, RACE_S_FAIRY)) {
215 if (creature_ptr->resist_lite) {
217 per /= randrate(4, 7, mode);
220 if (creature_ptr->wraith_form)
226 PERCENTAGE calc_dark_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
228 PERCENTAGE per = 100;
230 if (is_specific_player_race(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE) || creature_ptr->wraith_form) {
234 if (creature_ptr->resist_dark) {
236 per /= randrate(4, 7, mode);
242 PERCENTAGE calc_shards_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
244 PERCENTAGE per = 100;
246 if (creature_ptr->resist_shard) {
248 per /= randrate(4, 7, mode);
254 PERCENTAGE calc_sound_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
256 PERCENTAGE per = 100;
258 if (creature_ptr->resist_sound) {
260 per /= randrate(4, 7, mode);
266 PERCENTAGE calc_conf_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
268 PERCENTAGE per = 100;
270 if (creature_ptr->resist_conf) {
272 per /= randrate(4, 7, mode);
278 PERCENTAGE calc_chaos_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
280 PERCENTAGE per = 100;
282 if (creature_ptr->resist_chaos) {
284 per /= randrate(4, 7, mode);
290 PERCENTAGE calc_disenchant_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
292 PERCENTAGE per = 100;
294 if (creature_ptr->resist_disen) {
296 per /= randrate(4, 7, mode);
302 PERCENTAGE calc_nexus_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
304 PERCENTAGE per = 100;
306 if (creature_ptr->resist_disen) {
308 per /= randrate(4, 7, mode);
314 PERCENTAGE calc_rocket_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
317 PERCENTAGE per = 100;
319 if (creature_ptr->resist_shard) {
326 PERCENTAGE calc_nether_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
328 PERCENTAGE per = 100;
330 if (creature_ptr->resist_neth) {
331 if (!is_specific_player_race(creature_ptr, RACE_SPECTRE))
334 per /= randrate(4, 7, mode);
340 PERCENTAGE calc_time_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
343 PERCENTAGE per = 100;
345 if (creature_ptr->resist_time) {
347 per /= randrate(4, 7, mode);
353 PERCENTAGE calc_holy_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
356 PERCENTAGE per = 100;
357 if (creature_ptr->align > 10)
359 else if (creature_ptr->align < -10)
364 PERCENTAGE calc_hell_fire_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
367 PERCENTAGE per = 100;
368 if (creature_ptr->align > 10)
373 PERCENTAGE calc_gravity_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
376 PERCENTAGE per = 100;
377 if (creature_ptr->levitation) {