OSDN Git Service

Revert "Revert "Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband""
[hengband/hengband.git] / src / mspell / element-resistance-checker.c
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
9 void add_cheat_remove_flags_element(player_type *target_ptr, msr_type *msr_ptr)
10 {
11     if (target_ptr->resist_acid)
12         msr_ptr->smart |= SM_RES_ACID;
13
14     if (is_oppose_acid(target_ptr))
15         msr_ptr->smart |= SM_OPP_ACID;
16
17     if (target_ptr->immune_acid)
18         msr_ptr->smart |= SM_IMM_ACID;
19
20     if (target_ptr->resist_elec)
21         msr_ptr->smart |= SM_RES_ELEC;
22
23     if (is_oppose_elec(target_ptr))
24         msr_ptr->smart |= SM_OPP_ELEC;
25
26     if (target_ptr->immune_elec)
27         msr_ptr->smart |= SM_IMM_ELEC;
28
29     if (target_ptr->resist_fire)
30         msr_ptr->smart |= SM_RES_FIRE;
31
32     if (is_oppose_fire(target_ptr))
33         msr_ptr->smart |= SM_OPP_FIRE;
34
35     if (target_ptr->immune_fire)
36         msr_ptr->smart |= SM_IMM_FIRE;
37
38     if (target_ptr->resist_cold)
39         msr_ptr->smart |= SM_RES_COLD;
40
41     if (is_oppose_cold(target_ptr))
42         msr_ptr->smart |= SM_OPP_COLD;
43
44     if (target_ptr->immune_cold)
45         msr_ptr->smart |= SM_IMM_COLD;
46
47     if (target_ptr->resist_pois)
48         msr_ptr->smart |= SM_RES_POIS;
49
50     if (is_oppose_pois(target_ptr))
51         msr_ptr->smart |= SM_OPP_POIS;
52 }
53
54 static void check_acid_resistance(msr_type *msr_ptr)
55 {
56     if (msr_ptr->smart & SM_IMM_ACID) {
57         msr_ptr->f4 &= ~(RF4_BR_ACID);
58         msr_ptr->f5 &= ~(RF5_BA_ACID);
59         msr_ptr->f5 &= ~(RF5_BO_ACID);
60         return;
61     }
62
63     if ((msr_ptr->smart & SM_OPP_ACID) && (msr_ptr->smart & SM_RES_ACID)) {
64         if (int_outof(msr_ptr->r_ptr, 80))
65             msr_ptr->f4 &= ~(RF4_BR_ACID);
66
67         if (int_outof(msr_ptr->r_ptr, 80))
68             msr_ptr->f5 &= ~(RF5_BA_ACID);
69
70         if (int_outof(msr_ptr->r_ptr, 80))
71             msr_ptr->f5 &= ~(RF5_BO_ACID);
72
73         return;
74     }
75
76     if ((msr_ptr->smart & SM_OPP_ACID) || (msr_ptr->smart & SM_RES_ACID)) {
77         if (int_outof(msr_ptr->r_ptr, 30))
78             msr_ptr->f4 &= ~(RF4_BR_ACID);
79
80         if (int_outof(msr_ptr->r_ptr, 30))
81             msr_ptr->f5 &= ~(RF5_BA_ACID);
82
83         if (int_outof(msr_ptr->r_ptr, 30))
84             msr_ptr->f5 &= ~(RF5_BO_ACID);
85     }
86 }
87
88 static void check_elec_resistance(msr_type *msr_ptr)
89 {
90     if (msr_ptr->smart & SM_IMM_ELEC) {
91         msr_ptr->f4 &= ~(RF4_BR_ELEC);
92         msr_ptr->f5 &= ~(RF5_BA_ELEC);
93         msr_ptr->f5 &= ~(RF5_BO_ELEC);
94         return;
95     }
96
97     if ((msr_ptr->smart & SM_OPP_ELEC) && (msr_ptr->smart & SM_RES_ELEC)) {
98         if (int_outof(msr_ptr->r_ptr, 80))
99             msr_ptr->f4 &= ~(RF4_BR_ELEC);
100
101         if (int_outof(msr_ptr->r_ptr, 80))
102             msr_ptr->f5 &= ~(RF5_BA_ELEC);
103
104         if (int_outof(msr_ptr->r_ptr, 80))
105             msr_ptr->f5 &= ~(RF5_BO_ELEC);
106
107         return;
108     }
109
110     if ((msr_ptr->smart & SM_OPP_ELEC) || (msr_ptr->smart & SM_RES_ELEC)) {
111         if (int_outof(msr_ptr->r_ptr, 30))
112             msr_ptr->f4 &= ~(RF4_BR_ELEC);
113
114         if (int_outof(msr_ptr->r_ptr, 30))
115             msr_ptr->f5 &= ~(RF5_BA_ELEC);
116
117         if (int_outof(msr_ptr->r_ptr, 30))
118             msr_ptr->f5 &= ~(RF5_BO_ELEC);
119     }
120 }
121
122 static void check_fire_resistance(msr_type *msr_ptr)
123 {
124     if (msr_ptr->smart & SM_IMM_FIRE) {
125         msr_ptr->f4 &= ~(RF4_BR_FIRE);
126         msr_ptr->f5 &= ~(RF5_BA_FIRE);
127         msr_ptr->f5 &= ~(RF5_BO_FIRE);
128         return;
129     }
130
131     if ((msr_ptr->smart & SM_OPP_FIRE) && (msr_ptr->smart & SM_RES_FIRE)) {
132         if (int_outof(msr_ptr->r_ptr, 80))
133             msr_ptr->f4 &= ~(RF4_BR_FIRE);
134
135         if (int_outof(msr_ptr->r_ptr, 80))
136             msr_ptr->f5 &= ~(RF5_BA_FIRE);
137
138         if (int_outof(msr_ptr->r_ptr, 80))
139             msr_ptr->f5 &= ~(RF5_BO_FIRE);
140
141         return;
142     }
143
144     if ((msr_ptr->smart & SM_OPP_FIRE) || (msr_ptr->smart & SM_RES_FIRE)) {
145         if (int_outof(msr_ptr->r_ptr, 30))
146             msr_ptr->f4 &= ~(RF4_BR_FIRE);
147
148         if (int_outof(msr_ptr->r_ptr, 30))
149             msr_ptr->f5 &= ~(RF5_BA_FIRE);
150
151         if (int_outof(msr_ptr->r_ptr, 30))
152             msr_ptr->f5 &= ~(RF5_BO_FIRE);
153     }
154 }
155
156 static void check_cold_resistance(msr_type *msr_ptr)
157 {
158     if (msr_ptr->smart & (SM_IMM_COLD)) {
159         msr_ptr->f4 &= ~(RF4_BR_COLD);
160         msr_ptr->f5 &= ~(RF5_BA_COLD);
161         msr_ptr->f5 &= ~(RF5_BO_COLD);
162         msr_ptr->f5 &= ~(RF5_BO_ICEE);
163         return;
164     }
165
166     if ((msr_ptr->smart & SM_OPP_COLD) && (msr_ptr->smart & SM_RES_COLD)) {
167         if (int_outof(msr_ptr->r_ptr, 80))
168             msr_ptr->f4 &= ~(RF4_BR_COLD);
169
170         if (int_outof(msr_ptr->r_ptr, 80))
171             msr_ptr->f5 &= ~(RF5_BA_COLD);
172
173         if (int_outof(msr_ptr->r_ptr, 80))
174             msr_ptr->f5 &= ~(RF5_BO_COLD);
175
176         if (int_outof(msr_ptr->r_ptr, 80))
177             msr_ptr->f5 &= ~(RF5_BO_ICEE);
178
179         return;
180     }
181
182     if ((msr_ptr->smart & SM_OPP_COLD) || (msr_ptr->smart & SM_RES_COLD)) {
183         if (int_outof(msr_ptr->r_ptr, 30))
184             msr_ptr->f4 &= ~(RF4_BR_COLD);
185
186         if (int_outof(msr_ptr->r_ptr, 30))
187             msr_ptr->f5 &= ~(RF5_BA_COLD);
188
189         if (int_outof(msr_ptr->r_ptr, 30))
190             msr_ptr->f5 &= ~(RF5_BO_COLD);
191
192         if (int_outof(msr_ptr->r_ptr, 20))
193             msr_ptr->f5 &= ~(RF5_BO_ICEE);
194     }
195 }
196
197 static void check_pois_resistance(msr_type *msr_ptr)
198 {
199     if ((msr_ptr->smart & SM_OPP_POIS) && (msr_ptr->smart & SM_RES_POIS)) {
200         if (int_outof(msr_ptr->r_ptr, 80))
201             msr_ptr->f4 &= ~(RF4_BR_POIS);
202
203         if (int_outof(msr_ptr->r_ptr, 80))
204             msr_ptr->f5 &= ~(RF5_BA_POIS);
205
206         if (int_outof(msr_ptr->r_ptr, 60))
207             msr_ptr->f4 &= ~(RF4_BA_NUKE);
208
209         if (int_outof(msr_ptr->r_ptr, 60))
210             msr_ptr->f4 &= ~(RF4_BR_NUKE);
211
212         return;
213     }
214
215     if ((msr_ptr->smart & SM_OPP_POIS) || (msr_ptr->smart & SM_RES_POIS)) {
216         if (int_outof(msr_ptr->r_ptr, 30))
217             msr_ptr->f4 &= ~(RF4_BR_POIS);
218
219         if (int_outof(msr_ptr->r_ptr, 30))
220             msr_ptr->f5 &= ~(RF5_BA_POIS);
221     }
222 }
223
224 void check_element_resistance(msr_type *msr_ptr)
225 {
226     check_acid_resistance(msr_ptr);
227     check_elec_resistance(msr_ptr);
228     check_fire_resistance(msr_ptr);
229     check_cold_resistance(msr_ptr);
230     check_pois_resistance(msr_ptr);
231 }