OSDN Git Service

[Refactor] #40479 Continuous reshaped remove_bad_spells()
[hengband/hengband.git] / src / mspell / improper-mspell-remover.c
1 #include "mspell/improper-mspell-remover.h"
2 #include "game-option/birth-options.h"
3 #include "monster-race/monster-race.h"
4 #include "monster-race/race-flags-ability1.h"
5 #include "monster-race/race-flags-ability2.h"
6 #include "monster-race/race-flags2.h"
7 #include "monster-race/race-flags4.h"
8 #include "monster/smart-learn-types.h"
9 #include "player/player-race.h"
10 #include "status/element-resistance.h"
11 #include "system/floor-type-definition.h"
12 #include "system/monster-type-definition.h"
13
14 /*!
15  * @brief モンスターがプレイヤーの弱点をついた選択を取るかどうかの判定 /
16  * Internal probability routine
17  * @param r_ptr モンスター種族の構造体参照ポインタ
18  * @param prob 基本確率(%)
19  * @return 適した選択を取るならばTRUEを返す。
20  */
21 static bool int_outof(monster_race *r_ptr, PERCENTAGE prob)
22 {
23     if (!(r_ptr->flags2 & RF2_SMART))
24         prob = prob / 2;
25
26     return (randint0(100) < prob);
27 }
28
29 /*!
30  * @brief モンスターの魔法一覧から戦術的に適さない魔法を除外する /
31  * Remove the "bad" spells from a spell list
32  * @param m_idx モンスターの構造体参照ポインタ
33  * @param f4p モンスター魔法のフラグリスト1
34  * @param f5p モンスター魔法のフラグリスト2
35  * @param f6p モンスター魔法のフラグリスト3
36  * @return なし
37  */
38 void remove_bad_spells(MONSTER_IDX m_idx, player_type *target_ptr, u32b *f4p, u32b *f5p, u32b *f6p)
39 {
40     monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
41     monster_race *r_ptr = &r_info[m_ptr->r_idx];
42     u32b f4 = *f4p;
43     u32b f5 = *f5p;
44     u32b f6 = *f6p;
45     u32b smart = 0L;
46     if (r_ptr->flags2 & RF2_STUPID)
47         return;
48
49     if (!smart_cheat && !smart_learn)
50         return;
51
52     if (smart_learn) {
53         if (m_ptr->smart && (randint0(100) < 1))
54             m_ptr->smart &= SM_FRIENDLY | SM_PET | SM_CLONED;
55
56         smart = m_ptr->smart;
57     }
58
59     if (smart_cheat) {
60         if (target_ptr->resist_acid)
61             smart |= SM_RES_ACID;
62
63         if (is_oppose_acid(target_ptr))
64             smart |= SM_OPP_ACID;
65
66         if (target_ptr->immune_acid)
67             smart |= SM_IMM_ACID;
68
69         if (target_ptr->resist_elec)
70             smart |= SM_RES_ELEC;
71
72         if (is_oppose_elec(target_ptr))
73             smart |= SM_OPP_ELEC;
74
75         if (target_ptr->immune_elec)
76             smart |= SM_IMM_ELEC;
77
78         if (target_ptr->resist_fire)
79             smart |= SM_RES_FIRE;
80
81         if (is_oppose_fire(target_ptr))
82             smart |= SM_OPP_FIRE;
83
84         if (target_ptr->immune_fire)
85             smart |= SM_IMM_FIRE;
86
87         if (target_ptr->resist_cold)
88             smart |= SM_RES_COLD;
89         if (is_oppose_cold(target_ptr))
90             smart |= SM_OPP_COLD;
91
92         if (target_ptr->immune_cold)
93             smart |= SM_IMM_COLD;
94
95         if (target_ptr->resist_pois)
96             smart |= SM_RES_POIS;
97
98         if (is_oppose_pois(target_ptr))
99             smart |= SM_OPP_POIS;
100
101         if (target_ptr->resist_neth)
102             smart |= SM_RES_NETH;
103
104         if (target_ptr->resist_lite)
105             smart |= SM_RES_LITE;
106
107         if (target_ptr->resist_dark)
108             smart |= SM_RES_DARK;
109
110         if (target_ptr->resist_fear)
111             smart |= SM_RES_FEAR;
112
113         if (target_ptr->resist_conf)
114             smart |= SM_RES_CONF;
115
116         if (target_ptr->resist_chaos)
117             smart |= SM_RES_CHAOS;
118
119         if (target_ptr->resist_disen)
120             smart |= SM_RES_DISEN;
121
122         if (target_ptr->resist_blind)
123             smart |= SM_RES_BLIND;
124
125         if (target_ptr->resist_nexus)
126             smart |= SM_RES_NEXUS;
127
128         if (target_ptr->resist_sound)
129             smart |= SM_RES_SOUND;
130
131         if (target_ptr->resist_shard)
132             smart |= SM_RES_SHARD;
133
134         if (target_ptr->reflect)
135             smart |= SM_IMM_REFLECT;
136
137         if (target_ptr->free_act)
138             smart |= SM_IMM_FREE;
139
140         if (!target_ptr->msp)
141             smart |= SM_IMM_MANA;
142     }
143
144     if (!smart)
145         return;
146
147     if (smart & SM_IMM_ACID) {
148         f4 &= ~(RF4_BR_ACID);
149         f5 &= ~(RF5_BA_ACID);
150         f5 &= ~(RF5_BO_ACID);
151     } else if ((smart & SM_OPP_ACID) && (smart & SM_RES_ACID)) {
152         if (int_outof(r_ptr, 80))
153             f4 &= ~(RF4_BR_ACID);
154
155         if (int_outof(r_ptr, 80))
156             f5 &= ~(RF5_BA_ACID);
157
158         if (int_outof(r_ptr, 80))
159             f5 &= ~(RF5_BO_ACID);
160     } else if ((smart & SM_OPP_ACID) || (smart & SM_RES_ACID)) {
161         if (int_outof(r_ptr, 30))
162             f4 &= ~(RF4_BR_ACID);
163
164         if (int_outof(r_ptr, 30))
165             f5 &= ~(RF5_BA_ACID);
166
167         if (int_outof(r_ptr, 30))
168             f5 &= ~(RF5_BO_ACID);
169     }
170
171     if (smart & SM_IMM_ELEC) {
172         f4 &= ~(RF4_BR_ELEC);
173         f5 &= ~(RF5_BA_ELEC);
174         f5 &= ~(RF5_BO_ELEC);
175     } else if ((smart & SM_OPP_ELEC) && (smart & SM_RES_ELEC)) {
176         if (int_outof(r_ptr, 80))
177             f4 &= ~(RF4_BR_ELEC);
178
179         if (int_outof(r_ptr, 80))
180             f5 &= ~(RF5_BA_ELEC);
181
182         if (int_outof(r_ptr, 80))
183             f5 &= ~(RF5_BO_ELEC);
184     } else if ((smart & SM_OPP_ELEC) || (smart & SM_RES_ELEC)) {
185         if (int_outof(r_ptr, 30))
186             f4 &= ~(RF4_BR_ELEC);
187
188         if (int_outof(r_ptr, 30))
189             f5 &= ~(RF5_BA_ELEC);
190
191         if (int_outof(r_ptr, 30))
192             f5 &= ~(RF5_BO_ELEC);
193     }
194
195     if (smart & (SM_IMM_FIRE)) {
196         f4 &= ~(RF4_BR_FIRE);
197         f5 &= ~(RF5_BA_FIRE);
198         f5 &= ~(RF5_BO_FIRE);
199     } else if ((smart & SM_OPP_FIRE) && (smart & SM_RES_FIRE)) {
200         if (int_outof(r_ptr, 80))
201             f4 &= ~(RF4_BR_FIRE);
202
203         if (int_outof(r_ptr, 80))
204             f5 &= ~(RF5_BA_FIRE);
205
206         if (int_outof(r_ptr, 80))
207             f5 &= ~(RF5_BO_FIRE);
208     } else if ((smart & SM_OPP_FIRE) || (smart & SM_RES_FIRE)) {
209         if (int_outof(r_ptr, 30))
210             f4 &= ~(RF4_BR_FIRE);
211
212         if (int_outof(r_ptr, 30))
213             f5 &= ~(RF5_BA_FIRE);
214
215         if (int_outof(r_ptr, 30))
216             f5 &= ~(RF5_BO_FIRE);
217     }
218
219     if (smart & (SM_IMM_COLD)) {
220         f4 &= ~(RF4_BR_COLD);
221         f5 &= ~(RF5_BA_COLD);
222         f5 &= ~(RF5_BO_COLD);
223         f5 &= ~(RF5_BO_ICEE);
224     } else if ((smart & SM_OPP_COLD) && (smart & SM_RES_COLD)) {
225         if (int_outof(r_ptr, 80))
226             f4 &= ~(RF4_BR_COLD);
227
228         if (int_outof(r_ptr, 80))
229             f5 &= ~(RF5_BA_COLD);
230
231         if (int_outof(r_ptr, 80))
232             f5 &= ~(RF5_BO_COLD);
233
234         if (int_outof(r_ptr, 80))
235             f5 &= ~(RF5_BO_ICEE);
236     } else if ((smart & SM_OPP_COLD) || (smart & SM_RES_COLD)) {
237         if (int_outof(r_ptr, 30))
238             f4 &= ~(RF4_BR_COLD);
239
240         if (int_outof(r_ptr, 30))
241             f5 &= ~(RF5_BA_COLD);
242
243         if (int_outof(r_ptr, 30))
244             f5 &= ~(RF5_BO_COLD);
245
246         if (int_outof(r_ptr, 20))
247             f5 &= ~(RF5_BO_ICEE);
248     }
249
250     if ((smart & SM_OPP_POIS) && (smart & SM_RES_POIS)) {
251         if (int_outof(r_ptr, 80))
252             f4 &= ~(RF4_BR_POIS);
253
254         if (int_outof(r_ptr, 80))
255             f5 &= ~(RF5_BA_POIS);
256
257         if (int_outof(r_ptr, 60))
258             f4 &= ~(RF4_BA_NUKE);
259
260         if (int_outof(r_ptr, 60))
261             f4 &= ~(RF4_BR_NUKE);
262     } else if ((smart & SM_OPP_POIS) || (smart & SM_RES_POIS)) {
263         if (int_outof(r_ptr, 30))
264             f4 &= ~(RF4_BR_POIS);
265
266         if (int_outof(r_ptr, 30))
267             f5 &= ~(RF5_BA_POIS);
268     }
269
270     if (smart & SM_RES_NETH) {
271         if (is_specific_player_race(target_ptr, RACE_SPECTRE)) {
272             f4 &= ~(RF4_BR_NETH);
273             f5 &= ~(RF5_BA_NETH);
274             f5 &= ~(RF5_BO_NETH);
275         } else {
276             if (int_outof(r_ptr, 20))
277                 f4 &= ~(RF4_BR_NETH);
278
279             if (int_outof(r_ptr, 50))
280                 f5 &= ~(RF5_BA_NETH);
281
282             if (int_outof(r_ptr, 50))
283                 f5 &= ~(RF5_BO_NETH);
284         }
285     }
286
287     if (smart & SM_RES_LITE) {
288         if (int_outof(r_ptr, 50))
289             f4 &= ~(RF4_BR_LITE);
290
291         if (int_outof(r_ptr, 50))
292             f5 &= ~(RF5_BA_LITE);
293     }
294
295     if (smart & SM_RES_DARK) {
296         if (is_specific_player_race(target_ptr, RACE_VAMPIRE)) {
297             f4 &= ~(RF4_BR_DARK);
298             f5 &= ~(RF5_BA_DARK);
299         } else {
300             if (int_outof(r_ptr, 50))
301                 f4 &= ~(RF4_BR_DARK);
302
303             if (int_outof(r_ptr, 50))
304                 f5 &= ~(RF5_BA_DARK);
305         }
306     }
307
308     if (smart & SM_RES_FEAR) {
309         f5 &= ~(RF5_SCARE);
310     }
311
312     if (smart & SM_RES_CONF) {
313         f5 &= ~(RF5_CONF);
314         if (int_outof(r_ptr, 50))
315             f4 &= ~(RF4_BR_CONF);
316     }
317
318     if (smart & SM_RES_CHAOS) {
319         if (int_outof(r_ptr, 20))
320             f4 &= ~(RF4_BR_CHAO);
321
322         if (int_outof(r_ptr, 50))
323             f4 &= ~(RF4_BA_CHAO);
324     }
325
326     if (((smart & SM_RES_DISEN) != 0) && int_outof(r_ptr, 40))
327         f4 &= ~(RF4_BR_DISE);
328
329     if (smart & SM_RES_BLIND)
330         f5 &= ~(RF5_BLIND);
331
332     if (smart & SM_RES_NEXUS) {
333         if (int_outof(r_ptr, 50))
334             f4 &= ~(RF4_BR_NEXU);
335
336         f6 &= ~(RF6_TELE_LEVEL);
337     }
338
339     if (((smart & SM_RES_SOUND) != 0) && int_outof(r_ptr, 50))
340         f4 &= ~(RF4_BR_SOUN);
341
342     if (((smart & SM_RES_SHARD) != 0) && int_outof(r_ptr, 40))
343         f4 &= ~(RF4_BR_SHAR);
344
345     if (smart & SM_IMM_REFLECT) {
346         if (int_outof(r_ptr, 150))
347             f5 &= ~(RF5_BO_COLD);
348
349         if (int_outof(r_ptr, 150))
350             f5 &= ~(RF5_BO_FIRE);
351
352         if (int_outof(r_ptr, 150))
353             f5 &= ~(RF5_BO_ACID);
354
355         if (int_outof(r_ptr, 150))
356             f5 &= ~(RF5_BO_ELEC);
357
358         if (int_outof(r_ptr, 150))
359             f5 &= ~(RF5_BO_NETH);
360
361         if (int_outof(r_ptr, 150))
362             f5 &= ~(RF5_BO_WATE);
363
364         if (int_outof(r_ptr, 150))
365             f5 &= ~(RF5_BO_MANA);
366
367         if (int_outof(r_ptr, 150))
368             f5 &= ~(RF5_BO_PLAS);
369
370         if (int_outof(r_ptr, 150))
371             f5 &= ~(RF5_BO_ICEE);
372
373         if (int_outof(r_ptr, 150))
374             f5 &= ~(RF5_MISSILE);
375     }
376
377     if (smart & SM_IMM_FREE) {
378         f5 &= ~(RF5_HOLD);
379         f5 &= ~(RF5_SLOW);
380     }
381
382     if (smart & SM_IMM_MANA)
383         f5 &= ~(RF5_DRAIN_MANA);
384
385     *f4p = f4;
386     *f5p = f5;
387     *f6p = f6;
388 }