OSDN Git Service

e92131df2b90951a6899ea42a4fa89569ff907f1
[hengband/hengband.git] / src / player / player-status-resist.c
1 #include "player/player-status-resist.h"
2 #include "art-definition/art-sword-types.h"
3 #include "grid/grid.h"
4 #include "inventory/inventory-slot-types.h"
5 #include "monster-race/monster-race.h"
6 #include "monster-race/race-flags2.h"
7 #include "monster-race/race-flags7.h"
8 #include "mutation/mutation-flag-types.h"
9 #include "object-enchant/object-ego.h"
10 #include "object-enchant/tr-types.h"
11 #include "object-enchant/trc-types.h"
12 #include "object-hook/hook-checker.h"
13 #include "object-hook/hook-weapon.h"
14 #include "object/object-flags.h"
15 #include "player/player-class.h"
16 #include "player/player-race-types.h"
17 #include "player/player-race.h"
18 #include "player/player-skill.h"
19 #include "player/player-status-flags.h"
20 #include "player/player-status.h"
21 #include "player/special-defense-types.h"
22 #include "realm/realm-hex-numbers.h"
23 #include "realm/realm-song-numbers.h"
24 #include "realm/realm-types.h"
25 #include "spell-realm/spells-hex.h"
26 #include "status/element-resistance.h"
27 #include "sv-definition/sv-weapon-types.h"
28 #include "system/floor-type-definition.h"
29 #include "system/monster-type-definition.h"
30 #include "system/object-type-definition.h"
31 #include "util/bit-flags-calculator.h"
32 #include "util/quarks.h"
33 #include "util/string-processor.h"
34
35 PERCENTAGE randrate(int dice, int fix, rate_calc_type_mode mode)
36 {
37     switch (mode) {
38     case CALC_RAND:
39         return randint1(dice) * 100 + fix * 100;
40         break;
41     case CALC_AVERAGE:
42         return (dice + 1) * 50 + fix * 100;
43         break;
44     case CALC_MIN:
45         return (fix + 1) * 100;
46         break;
47     case CALC_MAX:
48         return (dice + fix) * 100;
49         break;
50     default:
51         return (fix + 1) * 100;
52         break;
53     }
54 }
55
56 PERCENTAGE calc_acid_damage_rate(player_type *creature_ptr)
57 {
58     PERCENTAGE per = 100;
59     int i;
60
61     BIT_FLAGS flgs = is_vuln_acid(creature_ptr);
62     for (i = 0; i < FLAG_CAUSE_MAX; i++) {
63         if (flgs & (0x01 << i)) {
64             if (i == FLAG_CAUSE_MUTATION) {
65                 per *= 2;
66             } else {
67                 per += per / 3;
68             }
69         }
70     }
71
72     if (creature_ptr->resist_acid)
73         per = (per + 2) / 3;
74     if (is_oppose_acid(creature_ptr))
75         per = (per + 2) / 3;
76
77     return per;
78 }
79
80 PERCENTAGE calc_elec_damage_rate(player_type *creature_ptr)
81 {
82     PERCENTAGE per = 100;
83     int i;
84
85     if (is_immune_elec(creature_ptr)) {
86         return 0;
87     }
88
89     BIT_FLAGS flgs = is_vuln_elec(creature_ptr);
90     for (i = 0; i < FLAG_CAUSE_MAX; i++) {
91         if (flgs & (0x01 << i)) {
92             if (i == FLAG_CAUSE_MUTATION) {
93                 per *= 2;
94             } else {
95                 per += per / 3;
96             }
97         }
98     }
99
100     if (creature_ptr->resist_elec)
101         per = (per + 2) / 3;
102     if (is_oppose_elec(creature_ptr))
103         per = (per + 2) / 3;
104
105     return per;
106 }
107
108 PERCENTAGE calc_fire_damage_rate(player_type *creature_ptr)
109 {
110     PERCENTAGE per = 100;
111     int i;
112     BIT_FLAGS flgs = is_vuln_fire(creature_ptr);
113     for (i = 0; i < FLAG_CAUSE_MAX; i++) {
114         if (flgs & (0x01 << i)) {
115             if (i == FLAG_CAUSE_MUTATION) {
116                 per *= 2;
117             } else {
118                 per += per / 3;
119             }
120         }
121     }
122
123     /* Resist the damage */
124     if (creature_ptr->resist_fire)
125         per = (per + 2) / 3;
126     if (is_oppose_fire(creature_ptr))
127         per = (per + 2) / 3;
128
129     return per;
130 }
131
132 PERCENTAGE calc_cold_damage_rate(player_type *creature_ptr)
133 {
134     PERCENTAGE per = 100;
135     int i;
136     BIT_FLAGS flgs = is_vuln_cold(creature_ptr);
137     for (i = 0; i < FLAG_CAUSE_MAX; i++) {
138         if (flgs & (0x01 << i)) {
139             if (i == FLAG_CAUSE_MUTATION) {
140                 per *= 2;
141             } else {
142                 per += per / 3;
143             }
144         }
145     }
146
147     if (creature_ptr->resist_cold)
148         per = (per + 2) / 3;
149     if (is_oppose_cold(creature_ptr))
150         per = (per + 2) / 3;
151
152     return per;
153 }
154
155 PERCENTAGE calc_pois_damage_rate(player_type *creature_ptr)
156 {
157     PERCENTAGE per = 100;
158     if (creature_ptr->resist_pois)
159         per = (per + 2) / 3;
160     if (is_oppose_pois(creature_ptr))
161         per = (per + 2) / 3;
162
163     return per;
164 }
165
166 PERCENTAGE calc_nuke_damage_rate(player_type *creature_ptr)
167 {
168     PERCENTAGE per = 100;
169     if (creature_ptr->resist_pois)
170         per = (per + 2) / 3;
171     if (is_oppose_pois(creature_ptr))
172         per = (per + 2) / 3;
173
174     return per;
175 }
176
177 PERCENTAGE calc_lite_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
178 {
179     PERCENTAGE per = 100;
180     if (is_specific_player_race(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE)) {
181         per *= 2;
182     } else if (is_specific_player_race(creature_ptr, RACE_S_FAIRY)) {
183         per = per * 4 / 3;
184     }
185
186     if (creature_ptr->resist_lite) {
187         per *= 400;
188         per /= randrate(4, 7, mode);
189     }
190
191     if (creature_ptr->wraith_form)
192         per *= 2;
193
194     return per;
195 }
196
197 PERCENTAGE calc_dark_damage_rate(player_type *creature_ptr, rate_calc_type_mode mode)
198 {
199     PERCENTAGE per = 100;
200
201     if (is_specific_player_race(creature_ptr, RACE_VAMPIRE) || (creature_ptr->mimic_form == MIMIC_VAMPIRE) || creature_ptr->wraith_form) {
202         return 0;
203     }
204
205     if (creature_ptr->resist_dark) {
206         per *= 400;
207         per /= randrate(4, 7, mode);
208     }
209
210     return per;
211 }