1 #include "mspell/element-resistance-checker.h"
2 #include "game-option/birth-options.h"
3 #include "monster-race/race-flags-ability1.h"
4 #include "monster-race/race-flags4.h"
5 #include "monster/smart-learn-types.h"
6 #include "mspell/smart-mspell-util.h"
7 #include "status/element-resistance.h"
8 #include "player/player-status-flags.h"
10 void add_cheat_remove_flags_element(player_type *target_ptr, msr_type *msr_ptr)
12 if (has_resist_acid(target_ptr))
13 msr_ptr->smart |= SM_RES_ACID;
15 if (is_oppose_acid(target_ptr))
16 msr_ptr->smart |= SM_OPP_ACID;
18 if (has_immune_acid(target_ptr))
19 msr_ptr->smart |= SM_IMM_ACID;
21 if (target_ptr->resist_elec)
22 msr_ptr->smart |= SM_RES_ELEC;
24 if (is_oppose_elec(target_ptr))
25 msr_ptr->smart |= SM_OPP_ELEC;
27 if (has_immune_elec(target_ptr))
28 msr_ptr->smart |= SM_IMM_ELEC;
30 if (has_resist_fire(target_ptr))
31 msr_ptr->smart |= SM_RES_FIRE;
33 if (is_oppose_fire(target_ptr))
34 msr_ptr->smart |= SM_OPP_FIRE;
36 if (has_immune_fire(target_ptr))
37 msr_ptr->smart |= SM_IMM_FIRE;
39 if (target_ptr->resist_cold)
40 msr_ptr->smart |= SM_RES_COLD;
42 if (is_oppose_cold(target_ptr))
43 msr_ptr->smart |= SM_OPP_COLD;
45 if (has_immune_cold(target_ptr))
46 msr_ptr->smart |= SM_IMM_COLD;
48 if (target_ptr->resist_pois)
49 msr_ptr->smart |= SM_RES_POIS;
51 if (is_oppose_pois(target_ptr))
52 msr_ptr->smart |= SM_OPP_POIS;
55 static void check_acid_resistance(msr_type *msr_ptr)
57 if (msr_ptr->smart & SM_IMM_ACID) {
58 msr_ptr->f4 &= ~(RF4_BR_ACID);
59 msr_ptr->f5 &= ~(RF5_BA_ACID);
60 msr_ptr->f5 &= ~(RF5_BO_ACID);
64 if ((msr_ptr->smart & SM_OPP_ACID) && (msr_ptr->smart & SM_RES_ACID)) {
65 if (int_outof(msr_ptr->r_ptr, 80))
66 msr_ptr->f4 &= ~(RF4_BR_ACID);
68 if (int_outof(msr_ptr->r_ptr, 80))
69 msr_ptr->f5 &= ~(RF5_BA_ACID);
71 if (int_outof(msr_ptr->r_ptr, 80))
72 msr_ptr->f5 &= ~(RF5_BO_ACID);
77 if ((msr_ptr->smart & SM_OPP_ACID) || (msr_ptr->smart & SM_RES_ACID)) {
78 if (int_outof(msr_ptr->r_ptr, 30))
79 msr_ptr->f4 &= ~(RF4_BR_ACID);
81 if (int_outof(msr_ptr->r_ptr, 30))
82 msr_ptr->f5 &= ~(RF5_BA_ACID);
84 if (int_outof(msr_ptr->r_ptr, 30))
85 msr_ptr->f5 &= ~(RF5_BO_ACID);
89 static void check_elec_resistance(msr_type *msr_ptr)
91 if (msr_ptr->smart & SM_IMM_ELEC) {
92 msr_ptr->f4 &= ~(RF4_BR_ELEC);
93 msr_ptr->f5 &= ~(RF5_BA_ELEC);
94 msr_ptr->f5 &= ~(RF5_BO_ELEC);
98 if ((msr_ptr->smart & SM_OPP_ELEC) && (msr_ptr->smart & SM_RES_ELEC)) {
99 if (int_outof(msr_ptr->r_ptr, 80))
100 msr_ptr->f4 &= ~(RF4_BR_ELEC);
102 if (int_outof(msr_ptr->r_ptr, 80))
103 msr_ptr->f5 &= ~(RF5_BA_ELEC);
105 if (int_outof(msr_ptr->r_ptr, 80))
106 msr_ptr->f5 &= ~(RF5_BO_ELEC);
111 if ((msr_ptr->smart & SM_OPP_ELEC) || (msr_ptr->smart & SM_RES_ELEC)) {
112 if (int_outof(msr_ptr->r_ptr, 30))
113 msr_ptr->f4 &= ~(RF4_BR_ELEC);
115 if (int_outof(msr_ptr->r_ptr, 30))
116 msr_ptr->f5 &= ~(RF5_BA_ELEC);
118 if (int_outof(msr_ptr->r_ptr, 30))
119 msr_ptr->f5 &= ~(RF5_BO_ELEC);
123 static void check_fire_resistance(msr_type *msr_ptr)
125 if (msr_ptr->smart & SM_IMM_FIRE) {
126 msr_ptr->f4 &= ~(RF4_BR_FIRE);
127 msr_ptr->f5 &= ~(RF5_BA_FIRE);
128 msr_ptr->f5 &= ~(RF5_BO_FIRE);
132 if ((msr_ptr->smart & SM_OPP_FIRE) && (msr_ptr->smart & SM_RES_FIRE)) {
133 if (int_outof(msr_ptr->r_ptr, 80))
134 msr_ptr->f4 &= ~(RF4_BR_FIRE);
136 if (int_outof(msr_ptr->r_ptr, 80))
137 msr_ptr->f5 &= ~(RF5_BA_FIRE);
139 if (int_outof(msr_ptr->r_ptr, 80))
140 msr_ptr->f5 &= ~(RF5_BO_FIRE);
145 if ((msr_ptr->smart & SM_OPP_FIRE) || (msr_ptr->smart & SM_RES_FIRE)) {
146 if (int_outof(msr_ptr->r_ptr, 30))
147 msr_ptr->f4 &= ~(RF4_BR_FIRE);
149 if (int_outof(msr_ptr->r_ptr, 30))
150 msr_ptr->f5 &= ~(RF5_BA_FIRE);
152 if (int_outof(msr_ptr->r_ptr, 30))
153 msr_ptr->f5 &= ~(RF5_BO_FIRE);
157 static void check_cold_resistance(msr_type *msr_ptr)
159 if (msr_ptr->smart & (SM_IMM_COLD)) {
160 msr_ptr->f4 &= ~(RF4_BR_COLD);
161 msr_ptr->f5 &= ~(RF5_BA_COLD);
162 msr_ptr->f5 &= ~(RF5_BO_COLD);
163 msr_ptr->f5 &= ~(RF5_BO_ICEE);
167 if ((msr_ptr->smart & SM_OPP_COLD) && (msr_ptr->smart & SM_RES_COLD)) {
168 if (int_outof(msr_ptr->r_ptr, 80))
169 msr_ptr->f4 &= ~(RF4_BR_COLD);
171 if (int_outof(msr_ptr->r_ptr, 80))
172 msr_ptr->f5 &= ~(RF5_BA_COLD);
174 if (int_outof(msr_ptr->r_ptr, 80))
175 msr_ptr->f5 &= ~(RF5_BO_COLD);
177 if (int_outof(msr_ptr->r_ptr, 80))
178 msr_ptr->f5 &= ~(RF5_BO_ICEE);
183 if ((msr_ptr->smart & SM_OPP_COLD) || (msr_ptr->smart & SM_RES_COLD)) {
184 if (int_outof(msr_ptr->r_ptr, 30))
185 msr_ptr->f4 &= ~(RF4_BR_COLD);
187 if (int_outof(msr_ptr->r_ptr, 30))
188 msr_ptr->f5 &= ~(RF5_BA_COLD);
190 if (int_outof(msr_ptr->r_ptr, 30))
191 msr_ptr->f5 &= ~(RF5_BO_COLD);
193 if (int_outof(msr_ptr->r_ptr, 20))
194 msr_ptr->f5 &= ~(RF5_BO_ICEE);
198 static void check_pois_resistance(msr_type *msr_ptr)
200 if ((msr_ptr->smart & SM_OPP_POIS) && (msr_ptr->smart & SM_RES_POIS)) {
201 if (int_outof(msr_ptr->r_ptr, 80))
202 msr_ptr->f4 &= ~(RF4_BR_POIS);
204 if (int_outof(msr_ptr->r_ptr, 80))
205 msr_ptr->f5 &= ~(RF5_BA_POIS);
207 if (int_outof(msr_ptr->r_ptr, 60))
208 msr_ptr->f4 &= ~(RF4_BA_NUKE);
210 if (int_outof(msr_ptr->r_ptr, 60))
211 msr_ptr->f4 &= ~(RF4_BR_NUKE);
216 if ((msr_ptr->smart & SM_OPP_POIS) || (msr_ptr->smart & SM_RES_POIS)) {
217 if (int_outof(msr_ptr->r_ptr, 30))
218 msr_ptr->f4 &= ~(RF4_BR_POIS);
220 if (int_outof(msr_ptr->r_ptr, 30))
221 msr_ptr->f5 &= ~(RF5_BA_POIS);
225 void check_element_resistance(msr_type *msr_ptr)
227 check_acid_resistance(msr_ptr);
228 check_elec_resistance(msr_ptr);
229 check_fire_resistance(msr_ptr);
230 check_cold_resistance(msr_ptr);
231 check_pois_resistance(msr_ptr);