OSDN Git Service

[Refactor] #40514 has_resist_lite() を BIT_FLAGS 返り値持ちに仕様変更. / has_resist_lite() was...
[hengband/hengband.git] / src / player / player-status-flags.c
1 #include "player/player-status-flags.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.h"
20 #include "player/special-defense-types.h"
21 #include "realm/realm-hex-numbers.h"
22 #include "realm/realm-song-numbers.h"
23 #include "realm/realm-types.h"
24 #include "spell-realm/spells-hex.h"
25 #include "sv-definition/sv-weapon-types.h"
26 #include "system/floor-type-definition.h"
27 #include "system/monster-type-definition.h"
28 #include "system/object-type-definition.h"
29 #include "util/bit-flags-calculator.h"
30 #include "util/quarks.h"
31 #include "util/string-processor.h"
32
33 static BIT_FLAGS check_equipment_flags(player_type *creature_ptr, tr_type tr_flag);
34
35 static BIT_FLAGS check_equipment_flags(player_type *creature_ptr, tr_type tr_flag)
36 {
37     object_type *o_ptr;
38     BIT_FLAGS flgs[TR_FLAG_SIZE];
39     BIT_FLAGS result = 0L;
40     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
41         o_ptr = &creature_ptr->inventory_list[i];
42         if (!o_ptr->k_idx)
43             continue;
44
45         object_flags(creature_ptr, o_ptr, flgs);
46
47         if (has_flag(flgs, tr_flag))
48             result |= 0x01 << (i - INVEN_RARM);
49     }
50     return result;
51 }
52
53 bool has_kill_wall(player_type *creature_ptr)
54 {
55     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD || music_singing(creature_ptr, MUSIC_WALL)) {
56         return TRUE;
57     }
58
59     if (creature_ptr->riding) {
60         monster_type *riding_m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
61         monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
62         if (riding_r_ptr->flags2 & RF2_KILL_WALL)
63             return TRUE;
64     }
65
66     return FALSE;
67 }
68
69 bool has_pass_wall(player_type *creature_ptr)
70 {
71     bool pow = FALSE;
72
73     if (creature_ptr->wraith_form || creature_ptr->tim_pass_wall || (!creature_ptr->mimic_form && creature_ptr->prace == RACE_SPECTRE)) {
74         pow = TRUE;
75     }
76
77     if (creature_ptr->riding) {
78         monster_type *riding_m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
79         monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
80         if (!(riding_r_ptr->flags2 & RF2_PASS_WALL))
81             pow = FALSE;
82     }
83
84     return pow;
85 }
86
87 BIT_FLAGS has_xtra_might(player_type *creature_ptr)
88 {
89     BIT_FLAGS result = 0L;
90     result |= check_equipment_flags(creature_ptr, TR_XTRA_MIGHT);
91     return result;
92 }
93
94 BIT_FLAGS has_esp_evil(player_type *creature_ptr)
95 {
96     BIT_FLAGS result = 0L;
97     if (creature_ptr->realm1 == REALM_HEX) {
98         if (hex_spelling(creature_ptr, HEX_DETECT_EVIL))
99             result |= 0x01 << FLAG_CAUSE_MAGIC_TIME_EFFECT;
100     }
101     result |= check_equipment_flags(creature_ptr, TR_ESP_EVIL);
102     return result;
103 }
104
105 BIT_FLAGS has_esp_animal(player_type *creature_ptr)
106 {
107     BIT_FLAGS result = 0L;
108     result |= check_equipment_flags(creature_ptr, TR_ESP_ANIMAL);
109     return result;
110 }
111
112 BIT_FLAGS has_esp_undead(player_type *creature_ptr)
113 {
114     BIT_FLAGS result = 0L;
115     result |= check_equipment_flags(creature_ptr, TR_ESP_UNDEAD);
116     return result;
117 }
118
119 BIT_FLAGS has_esp_demon(player_type *creature_ptr)
120 {
121     BIT_FLAGS result = 0L;
122     result |= check_equipment_flags(creature_ptr, TR_ESP_DEMON);
123     return result;
124 }
125
126 BIT_FLAGS has_esp_orc(player_type *creature_ptr)
127 {
128     BIT_FLAGS result = 0L;
129     result |= check_equipment_flags(creature_ptr, TR_ESP_ORC);
130     return result;
131 }
132
133 BIT_FLAGS has_esp_troll(player_type *creature_ptr)
134 {
135     BIT_FLAGS result = 0L;
136     result |= check_equipment_flags(creature_ptr, TR_ESP_TROLL);
137     return result;
138 }
139
140 BIT_FLAGS has_esp_giant(player_type *creature_ptr)
141 {
142     BIT_FLAGS result = 0L;
143     result |= check_equipment_flags(creature_ptr, TR_ESP_GIANT);
144     return result;
145 }
146
147 BIT_FLAGS has_esp_dragon(player_type *creature_ptr)
148 {
149     BIT_FLAGS result = 0L;
150     result |= check_equipment_flags(creature_ptr, TR_ESP_DRAGON);
151     return result;
152 }
153
154 BIT_FLAGS has_esp_human(player_type *creature_ptr)
155 {
156     BIT_FLAGS result = 0L;
157     result |= check_equipment_flags(creature_ptr, TR_ESP_HUMAN);
158     return result;
159 }
160
161 BIT_FLAGS has_esp_good(player_type *creature_ptr)
162 {
163     BIT_FLAGS result = 0L;
164     result |= check_equipment_flags(creature_ptr, TR_ESP_GOOD);
165     return result;
166 }
167
168 BIT_FLAGS has_esp_nonliving(player_type *creature_ptr)
169 {
170     BIT_FLAGS result = 0L;
171     result |= check_equipment_flags(creature_ptr, TR_ESP_GOOD);
172     return result;
173 }
174
175 BIT_FLAGS has_esp_unique(player_type *creature_ptr)
176 {
177     BIT_FLAGS result = 0L;
178     result |= check_equipment_flags(creature_ptr, TR_ESP_UNIQUE);
179     return result;
180 }
181
182 BIT_FLAGS has_esp_telepathy(player_type *creature_ptr)
183 {
184     BIT_FLAGS result = 0L;
185
186     if (is_time_limit_esp(creature_ptr) || creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
187         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
188     }
189
190     if (creature_ptr->muta3 & MUT3_ESP) {
191         result |= FLAG_CAUSE_MUTATION;
192     }
193
194     if (is_specific_player_race(creature_ptr, RACE_MIND_FLAYER) && creature_ptr->lev > 29)
195         result |= FLAG_CAUSE_RACE;
196
197     if (is_specific_player_race(creature_ptr, RACE_SPECTRE) && creature_ptr->lev > 34)
198         result |= FLAG_CAUSE_RACE;
199
200     if (creature_ptr->pclass == CLASS_MINDCRAFTER && creature_ptr->lev > 39)
201         result |= FLAG_CAUSE_CLASS;
202
203     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
204         result |= FLAG_CAUSE_RACE;
205     }
206
207     result |= check_equipment_flags(creature_ptr, TR_TELEPATHY);
208     return result;
209 }
210
211 BIT_FLAGS has_bless_blade(player_type *creature_ptr)
212 {
213     BIT_FLAGS result = 0L;
214     result |= check_equipment_flags(creature_ptr, TR_BLESSED);
215     return result;
216 }
217
218 BIT_FLAGS has_easy2_weapon(player_type *creature_ptr)
219 {
220     BIT_FLAGS result = 0L;
221     result |= check_equipment_flags(creature_ptr, TR_EASY2_WEAPON);
222     return result;
223 }
224
225 BIT_FLAGS has_down_saving(player_type *creature_ptr)
226 {
227     BIT_FLAGS result = 0L;
228     result |= check_equipment_flags(creature_ptr, TR_DOWN_SAVING);
229     return result;
230 }
231
232 BIT_FLAGS has_no_ac(player_type *creature_ptr)
233 {
234     BIT_FLAGS result = 0L;
235     result |= check_equipment_flags(creature_ptr, TR_NO_AC);
236     return result;
237 }
238
239 void has_no_flowed(player_type *creature_ptr)
240 {
241     object_type *o_ptr;
242     bool has_sw = FALSE, has_kabe = FALSE;
243     OBJECT_IDX this_o_idx, next_o_idx = 0;
244
245     creature_ptr->no_flowed = FALSE;
246
247     if (creature_ptr->pass_wall && !creature_ptr->kill_wall)
248         creature_ptr->no_flowed = TRUE;
249
250     for (int i = 0; i < INVEN_PACK; i++) {
251         if ((creature_ptr->inventory_list[i].tval == TV_NATURE_BOOK) && (creature_ptr->inventory_list[i].sval == 2))
252             has_sw = TRUE;
253         if ((creature_ptr->inventory_list[i].tval == TV_CRAFT_BOOK) && (creature_ptr->inventory_list[i].sval == 2))
254             has_kabe = TRUE;
255     }
256
257     for (this_o_idx = creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].o_idx; this_o_idx; this_o_idx = next_o_idx) {
258         o_ptr = &creature_ptr->current_floor_ptr->o_list[this_o_idx];
259         next_o_idx = o_ptr->next_o_idx;
260
261         if ((o_ptr->tval == TV_NATURE_BOOK) && (o_ptr->sval == 2))
262             has_sw = TRUE;
263         if ((o_ptr->tval == TV_CRAFT_BOOK) && (o_ptr->sval == 2))
264             has_kabe = TRUE;
265     }
266
267     if (has_sw && ((creature_ptr->realm1 == REALM_NATURE) || (creature_ptr->realm2 == REALM_NATURE) || (creature_ptr->pclass == CLASS_SORCERER))) {
268         const magic_type *s_ptr = &mp_ptr->info[REALM_NATURE - 1][SPELL_SW];
269         if (creature_ptr->lev >= s_ptr->slevel)
270             creature_ptr->no_flowed = TRUE;
271     }
272
273     if (has_kabe && ((creature_ptr->realm1 == REALM_CRAFT) || (creature_ptr->realm2 == REALM_CRAFT) || (creature_ptr->pclass == CLASS_SORCERER))) {
274         const magic_type *s_ptr = &mp_ptr->info[REALM_CRAFT - 1][SPELL_WALL];
275         if (creature_ptr->lev >= s_ptr->slevel)
276             creature_ptr->no_flowed = TRUE;
277     }
278 }
279
280 BIT_FLAGS has_mighty_throw(player_type *creature_ptr)
281 {
282     BIT_FLAGS result = 0L;
283     result |= check_equipment_flags(creature_ptr, TR_MIGHTY_THROW);
284     return result;
285 }
286
287 BIT_FLAGS has_dec_mana(player_type *creature_ptr)
288 {
289     BIT_FLAGS result = 0L;
290     result |= check_equipment_flags(creature_ptr, TR_DEC_MANA);
291     return result;
292 }
293
294 BIT_FLAGS has_reflect(player_type *creature_ptr)
295 {
296     BIT_FLAGS result = 0L;
297
298     if (creature_ptr->pclass == CLASS_BERSERKER && creature_ptr->lev > 39)
299         result |= FLAG_CAUSE_CLASS;
300
301     if (creature_ptr->pclass == CLASS_MIRROR_MASTER && creature_ptr->lev > 39)
302         result |= FLAG_CAUSE_CLASS;
303
304     if (creature_ptr->special_defense & KAMAE_GENBU || creature_ptr->special_defense & KATA_MUSOU) {
305         result |= FLAG_CAUSE_BATTLE_FORM;
306     }
307
308     if (creature_ptr->ult_res || creature_ptr->wraith_form || creature_ptr->magicdef || creature_ptr->tim_reflect) {
309         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
310     }
311
312     result |= check_equipment_flags(creature_ptr, TR_REFLECT);
313     return result;
314 }
315
316 BIT_FLAGS has_see_nocto(player_type *creature_ptr) { return creature_ptr->pclass == CLASS_NINJA ? FLAG_CAUSE_CLASS : 0L; }
317
318 void has_warning(player_type *creature_ptr)
319 {
320     object_type *o_ptr;
321     BIT_FLAGS flgs[TR_FLAG_SIZE];
322
323     creature_ptr->warning = FALSE;
324
325     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
326         o_ptr = &creature_ptr->inventory_list[i];
327         if (!o_ptr->k_idx)
328             continue;
329
330         object_flags(creature_ptr, o_ptr, flgs);
331
332         if (has_flag(flgs, TR_WARNING)) {
333             if (!o_ptr->inscription || !(angband_strchr(quark_str(o_ptr->inscription), '$')))
334                 creature_ptr->warning = TRUE;
335         }
336     }
337 }
338
339 BIT_FLAGS has_anti_magic(player_type *creature_ptr)
340 {
341     BIT_FLAGS result = 0L;
342     result |= check_equipment_flags(creature_ptr, TR_NO_MAGIC);
343     return result;
344 }
345
346 BIT_FLAGS has_anti_tele(player_type *creature_ptr)
347 {
348     BIT_FLAGS result = 0L;
349     result |= check_equipment_flags(creature_ptr, TR_NO_TELE);
350     return result;
351 }
352
353 BIT_FLAGS has_sh_fire(player_type *creature_ptr)
354 {
355     BIT_FLAGS result = 0L;
356
357     if (creature_ptr->muta3 & MUT3_FIRE_BODY) {
358         result |= FLAG_CAUSE_MUTATION;
359     }
360
361     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
362         result |= FLAG_CAUSE_RACE;
363     }
364
365     if (creature_ptr->special_defense & KAMAE_SEIRYU || creature_ptr->special_defense & KATA_MUSOU) {
366         result |= FLAG_CAUSE_BATTLE_FORM;
367     }
368
369     if (hex_spelling(creature_ptr, HEX_DEMON_AURA) || creature_ptr->ult_res || creature_ptr->tim_sh_fire) {
370         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
371     }
372
373     result |= check_equipment_flags(creature_ptr, TR_SH_FIRE);
374     return result;
375 }
376
377 BIT_FLAGS has_sh_elec(player_type *creature_ptr)
378 {
379     BIT_FLAGS result = 0L;
380
381     if (creature_ptr->muta3 & MUT3_ELEC_TOUC)
382         result |= FLAG_CAUSE_MUTATION;
383
384     if (hex_spelling(creature_ptr, HEX_SHOCK_CLOAK) || creature_ptr->ult_res) {
385         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
386     }
387
388     if (creature_ptr->special_defense & KAMAE_SEIRYU || (creature_ptr->special_defense & KATA_MUSOU)) {
389         result |= FLAG_CAUSE_BATTLE_FORM;
390     }
391
392     result |= check_equipment_flags(creature_ptr, TR_SH_ELEC);
393     return result;
394 }
395
396 BIT_FLAGS has_sh_cold(player_type *creature_ptr)
397 {
398     BIT_FLAGS result = 0L;
399
400     if (creature_ptr->special_defense & KAMAE_SEIRYU || creature_ptr->special_defense & KATA_MUSOU) {
401         result |= FLAG_CAUSE_BATTLE_FORM;
402     }
403
404     if (creature_ptr->ult_res || hex_spelling(creature_ptr, HEX_ICE_ARMOR)) {
405         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
406     }
407
408     result |= check_equipment_flags(creature_ptr, TR_SH_COLD);
409     return result;
410 }
411
412 BIT_FLAGS has_easy_spell(player_type *creature_ptr)
413 {
414     BIT_FLAGS result = 0L;
415     result |= check_equipment_flags(creature_ptr, TR_EASY_SPELL);
416     return result;
417 }
418
419 BIT_FLAGS has_heavy_spell(player_type *creature_ptr)
420 {
421     BIT_FLAGS result = 0L;
422     result |= check_equipment_flags(creature_ptr, TR_HEAVY_SPELL);
423     return result;
424 }
425
426 BIT_FLAGS has_hold_exp(player_type *creature_ptr)
427 {
428     BIT_FLAGS result = 0L;
429
430     if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
431         result |= FLAG_CAUSE_PERSONALITY;
432     }
433
434     if (creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_DEMON_LORD || creature_ptr->mimic_form == MIMIC_VAMPIRE) {
435         result |= FLAG_CAUSE_RACE;
436     }
437
438     if (is_specific_player_race(creature_ptr, RACE_HOBBIT) || is_specific_player_race(creature_ptr, RACE_SKELETON)
439         || is_specific_player_race(creature_ptr, RACE_ZOMBIE) || is_specific_player_race(creature_ptr, RACE_VAMPIRE)
440         || is_specific_player_race(creature_ptr, RACE_SPECTRE) || is_specific_player_race(creature_ptr, RACE_BALROG)
441         || is_specific_player_race(creature_ptr, RACE_ANDROID)) {
442         result |= FLAG_CAUSE_RACE;
443     }
444
445     if (is_specific_player_race(creature_ptr, RACE_GOLEM)) {
446         if (creature_ptr->lev > 34)
447             result |= FLAG_CAUSE_RACE;
448     }
449
450     if (creature_ptr->special_defense & KATA_MUSOU) {
451         result |= FLAG_CAUSE_BATTLE_FORM;
452     }
453
454     if (creature_ptr->ult_res) {
455         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
456     }
457
458     result |= check_equipment_flags(creature_ptr, TR_HOLD_EXP);
459     return result;
460 }
461
462 BIT_FLAGS has_see_inv(player_type *creature_ptr)
463 {
464     BIT_FLAGS result = 0L;
465
466     if (creature_ptr->pclass == CLASS_NINJA || creature_ptr->lev > 29)
467         result |= FLAG_CAUSE_CLASS;
468
469     if (creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_DEMON_LORD || creature_ptr->mimic_form == MIMIC_VAMPIRE) {
470         result |= FLAG_CAUSE_RACE;
471     }
472
473     if (!creature_ptr->mimic_form
474         && (creature_ptr->prace == RACE_HIGH_ELF || creature_ptr->prace == RACE_GOLEM || creature_ptr->prace == RACE_SKELETON
475             || creature_ptr->prace == RACE_ZOMBIE || creature_ptr->prace == RACE_SPECTRE || creature_ptr->prace == RACE_ARCHON)) {
476         result |= FLAG_CAUSE_RACE;
477     }
478
479     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DARK_ELF) {
480         if (creature_ptr->lev > 19)
481             result |= FLAG_CAUSE_RACE;
482     }
483
484     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_MIND_FLAYER) {
485         if (creature_ptr->lev > 14)
486             result |= FLAG_CAUSE_RACE;
487     }
488
489     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_IMP || creature_ptr->prace == RACE_BALROG)) {
490         if (creature_ptr->lev > 9)
491             result |= FLAG_CAUSE_RACE;
492     }
493
494     if (creature_ptr->special_defense & KATA_MUSOU) {
495         result |= FLAG_CAUSE_BATTLE_FORM;
496     }
497
498     if (creature_ptr->ult_res || creature_ptr->tim_invis) {
499         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
500     }
501
502         result |= check_equipment_flags(creature_ptr, TR_SEE_INVIS);
503     return result;
504
505 }
506
507 BIT_FLAGS has_free_act(player_type *creature_ptr)
508 {
509     BIT_FLAGS result = 0L;
510
511     if (creature_ptr->muta3 & MUT3_MOTION)
512         result |= FLAG_CAUSE_MUTATION;
513
514     if (is_specific_player_race(creature_ptr, RACE_GNOME) || is_specific_player_race(creature_ptr, RACE_GOLEM)
515         || is_specific_player_race(creature_ptr, RACE_SPECTRE) || is_specific_player_race(creature_ptr, RACE_ANDROID)) {
516         result |= FLAG_CAUSE_RACE;
517     }
518
519     if (heavy_armor(creature_ptr) && (!creature_ptr->inventory_list[INVEN_RARM].k_idx || has_right_hand_weapon(creature_ptr))
520         && (!creature_ptr->inventory_list[INVEN_LARM].k_idx || has_left_hand_weapon(creature_ptr))) {
521         if (creature_ptr->lev > 24)
522             result |= FLAG_CAUSE_CLASS;
523     }
524
525     if (creature_ptr->pclass == CLASS_MONK || creature_ptr->pclass == CLASS_FORCETRAINER) {
526         if (!(heavy_armor(creature_ptr))) {
527             if (creature_ptr->lev > 24)
528                 result |= FLAG_CAUSE_CLASS;
529         }
530     }
531
532     if (creature_ptr->pclass == CLASS_BERSERKER) {
533         result |= FLAG_CAUSE_CLASS;
534     }
535
536     if (creature_ptr->ult_res || creature_ptr->magicdef) {
537         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
538     }
539
540     if (creature_ptr->special_defense & KATA_MUSOU) {
541         result |= FLAG_CAUSE_BATTLE_FORM;
542     }
543
544     result |= check_equipment_flags(creature_ptr, TR_FREE_ACT);
545     return result;
546 }
547
548 BIT_FLAGS has_sustain_str(player_type *creature_ptr)
549 {
550     BIT_FLAGS result = 0L;
551
552     if (creature_ptr->pclass == CLASS_BERSERKER) {
553         result |= FLAG_CAUSE_CLASS;
554     }
555     if (is_specific_player_race(creature_ptr, RACE_HALF_TROLL) || is_specific_player_race(creature_ptr, RACE_HALF_OGRE)
556         || is_specific_player_race(creature_ptr, RACE_HALF_GIANT)) {
557         result |= FLAG_CAUSE_RACE;
558     }
559
560     if (creature_ptr->ult_res) {
561         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
562     }
563
564     if (creature_ptr->special_defense & KATA_MUSOU) {
565         result |= FLAG_CAUSE_BATTLE_FORM;
566     }
567
568     result |= check_equipment_flags(creature_ptr, TR_SUST_STR);
569     return result;
570 }
571
572 BIT_FLAGS has_sustain_int(player_type *creature_ptr)
573 {
574     BIT_FLAGS result = 0L;
575
576     if (is_specific_player_race(creature_ptr, RACE_MIND_FLAYER)) {
577         result |= FLAG_CAUSE_RACE;
578     }
579
580     if (creature_ptr->ult_res) {
581         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
582     }
583
584     if (creature_ptr->special_defense & KATA_MUSOU) {
585         result |= FLAG_CAUSE_BATTLE_FORM;
586     }
587
588     result |= check_equipment_flags(creature_ptr, TR_SUST_INT);
589     return result;
590 }
591
592 BIT_FLAGS has_sustain_wis(player_type *creature_ptr)
593 {
594     BIT_FLAGS result = 0L;
595
596     result = FALSE;
597     if (creature_ptr->pclass == CLASS_MINDCRAFTER && creature_ptr->lev > 19)
598         result |= FLAG_CAUSE_CLASS;
599
600     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_MIND_FLAYER)) {
601         result |= FLAG_CAUSE_RACE;
602     }
603
604     if (creature_ptr->ult_res) {
605         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
606     }
607
608     if (creature_ptr->special_defense & KATA_MUSOU) {
609         result |= FLAG_CAUSE_BATTLE_FORM;
610     }
611
612     result |= check_equipment_flags(creature_ptr, TR_SUST_WIS);
613     return result;
614 }
615
616 BIT_FLAGS has_sustain_dex(player_type *creature_ptr)
617 {
618     BIT_FLAGS result = 0L;
619     if (creature_ptr->pclass == CLASS_BERSERKER) {
620         result |= FLAG_CAUSE_CLASS;
621     }
622
623     if (creature_ptr->pclass == CLASS_NINJA && creature_ptr->lev > 24)
624         result |= FLAG_CAUSE_CLASS;
625
626     if (creature_ptr->ult_res) {
627         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
628     }
629
630     if (creature_ptr->special_defense & KATA_MUSOU) {
631         result |= FLAG_CAUSE_BATTLE_FORM;
632     }
633
634     result |= check_equipment_flags(creature_ptr, TR_SUST_DEX);
635     return result;
636 }
637
638 BIT_FLAGS has_sustain_con(player_type *creature_ptr)
639 {
640     BIT_FLAGS result = 0L;
641     if (creature_ptr->pclass == CLASS_BERSERKER) {
642         result |= FLAG_CAUSE_CLASS;
643     }
644
645     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_AMBERITE || creature_ptr->prace == RACE_DUNADAN)) {
646         result |= FLAG_CAUSE_RACE;
647     }
648
649     if (creature_ptr->ult_res) {
650         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
651     }
652
653     if (creature_ptr->special_defense & KATA_MUSOU) {
654         result |= FLAG_CAUSE_BATTLE_FORM;
655     }
656
657     result |= check_equipment_flags(creature_ptr, TR_SUST_CON);
658     return result;
659 }
660
661 BIT_FLAGS has_sustain_chr(player_type *creature_ptr)
662 {
663     BIT_FLAGS result = 0L;
664
665     if (creature_ptr->ult_res) {
666         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
667     }
668
669     if (creature_ptr->special_defense & KATA_MUSOU) {
670         result |= FLAG_CAUSE_BATTLE_FORM;
671     }
672
673     result |= check_equipment_flags(creature_ptr, TR_SUST_CHR);
674     return result;
675 }
676
677 BIT_FLAGS has_levitation(player_type *creature_ptr)
678 {
679     BIT_FLAGS result = 0L;
680
681     if (creature_ptr->muta3 & MUT3_WINGS)
682         result = FLAG_CAUSE_MUTATION;
683
684     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
685         result = FLAG_CAUSE_RACE;
686     }
687
688     if (is_specific_player_race(creature_ptr, RACE_DRACONIAN) || is_specific_player_race(creature_ptr, RACE_SPECTRE)
689         || is_specific_player_race(creature_ptr, RACE_SPRITE) || is_specific_player_race(creature_ptr, RACE_ARCHON)
690         || is_specific_player_race(creature_ptr, RACE_S_FAIRY)) {
691         result = FLAG_CAUSE_RACE;
692     }
693
694     if (creature_ptr->special_defense & KAMAE_SEIRYU || creature_ptr->special_defense & KAMAE_SUZAKU || (creature_ptr->special_defense & KATA_MUSOU)) {
695         result = FLAG_CAUSE_BATTLE_FORM;
696     }
697
698     if (creature_ptr->ult_res) {
699         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
700     }
701
702     if (creature_ptr->riding) {
703         monster_type *riding_m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
704         monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
705         result = (riding_r_ptr->flags7 & RF7_CAN_FLY) ? result : 0;
706     }
707
708     if (creature_ptr->tim_levitation) {
709         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
710     }
711
712     result |= check_equipment_flags(creature_ptr, TR_LEVITATION);
713     return result;
714 }
715
716 void has_can_swim(player_type *creature_ptr)
717 {
718     creature_ptr->can_swim = FALSE;
719     if (creature_ptr->riding) {
720         monster_type *riding_m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
721         monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
722         if (riding_r_ptr->flags7 & (RF7_CAN_SWIM | RF7_AQUATIC))
723             creature_ptr->can_swim = TRUE;
724     }
725 }
726
727 void has_slow_digest(player_type *creature_ptr)
728 {
729     object_type *o_ptr;
730     BIT_FLAGS flgs[TR_FLAG_SIZE];
731     creature_ptr->slow_digest = FALSE;
732
733     if (creature_ptr->pclass == CLASS_NINJA) {
734         creature_ptr->slow_digest = TRUE;
735     }
736
737     if (creature_ptr->lev > 14 && !creature_ptr->mimic_form && creature_ptr->prace == RACE_HALF_TROLL) {
738         if (creature_ptr->pclass == CLASS_WARRIOR || creature_ptr->pclass == CLASS_BERSERKER) {
739             creature_ptr->slow_digest = TRUE;
740             /* Let's not make Regeneration
741              * a disadvantage for the poor warriors who can
742              * never learn a spell that satisfies hunger (actually
743              * neither can rogues, but half-trolls are not
744              * supposed to play rogues) */
745         }
746     }
747
748     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
749         creature_ptr->slow_digest = TRUE;
750     }
751
752     if (!creature_ptr->mimic_form
753         && (creature_ptr->prace == RACE_GOLEM || creature_ptr->prace == RACE_ZOMBIE || creature_ptr->prace == RACE_SPECTRE
754             || creature_ptr->prace == RACE_ANDROID)) {
755         creature_ptr->slow_digest = TRUE;
756     }
757
758     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
759         o_ptr = &creature_ptr->inventory_list[i];
760         if (!o_ptr->k_idx)
761             continue;
762         object_flags(creature_ptr, o_ptr, flgs);
763         if (has_flag(flgs, TR_SLOW_DIGEST))
764             creature_ptr->slow_digest = TRUE;
765     }
766 }
767
768 BIT_FLAGS has_regenerate(player_type *creature_ptr)
769 {
770     BIT_FLAGS result = 0L;
771
772     if (is_specific_player_race(creature_ptr, RACE_HALF_TROLL) && creature_ptr->lev > 14) {
773         result |= FLAG_CAUSE_RACE;
774     }
775
776     if (is_specific_player_race(creature_ptr, RACE_AMBERITE)) {
777         result |= FLAG_CAUSE_RACE;
778     }
779
780     if (creature_ptr->pclass == CLASS_WARRIOR && creature_ptr->lev > 44) {
781         result |= FLAG_CAUSE_RACE;    
782         }
783
784         if (creature_ptr->pclass == CLASS_BERSERKER) {
785         result |= FLAG_CAUSE_RACE;
786     }
787
788     if (creature_ptr->muta3 & MUT3_REGEN)
789         result |= FLAG_CAUSE_MUTATION;
790
791     if (creature_ptr->special_defense & KATA_MUSOU) {
792         result |= FLAG_CAUSE_MUTATION;
793     }
794
795     if (hex_spelling(creature_ptr, HEX_DEMON_AURA) || creature_ptr->ult_res || creature_ptr->tim_regen) {
796         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
797     }
798
799     result |= check_equipment_flags(creature_ptr, TR_REGEN);
800
801     if (creature_ptr->muta3 & MUT3_FLESH_ROT)
802         result = 0L;
803
804     return result;
805 }
806
807 void has_curses(player_type *creature_ptr)
808 {
809     object_type *o_ptr;
810     BIT_FLAGS flgs[TR_FLAG_SIZE];
811     creature_ptr->cursed = 0L;
812
813     if (creature_ptr->pseikaku == PERSONALITY_SEXY)
814         creature_ptr->cursed |= (TRC_AGGRAVATE);
815
816     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
817         o_ptr = &creature_ptr->inventory_list[i];
818         if (!o_ptr->k_idx)
819             continue;
820         object_flags(creature_ptr, o_ptr, flgs);
821         if (has_flag(flgs, TR_AGGRAVATE))
822             creature_ptr->cursed |= TRC_AGGRAVATE;
823         if (has_flag(flgs, TR_DRAIN_EXP))
824             creature_ptr->cursed |= TRC_DRAIN_EXP;
825         if (has_flag(flgs, TR_TY_CURSE))
826             creature_ptr->cursed |= TRC_TY_CURSE;
827         if (has_flag(flgs, TR_ADD_L_CURSE))
828             creature_ptr->cursed |= TRC_ADD_L_CURSE;
829         if (has_flag(flgs, TR_ADD_H_CURSE))
830             creature_ptr->cursed |= TRC_ADD_H_CURSE;
831         if (has_flag(flgs, TR_DRAIN_HP))
832             creature_ptr->cursed |= TRC_DRAIN_HP;
833         if (has_flag(flgs, TR_DRAIN_MANA))
834             creature_ptr->cursed |= TRC_DRAIN_MANA;
835         if (has_flag(flgs, TR_CALL_ANIMAL))
836             creature_ptr->cursed |= TRC_CALL_ANIMAL;
837         if (has_flag(flgs, TR_CALL_DEMON))
838             creature_ptr->cursed |= TRC_CALL_DEMON;
839         if (has_flag(flgs, TR_CALL_DRAGON))
840             creature_ptr->cursed |= TRC_CALL_DRAGON;
841         if (has_flag(flgs, TR_CALL_UNDEAD))
842             creature_ptr->cursed |= TRC_CALL_UNDEAD;
843         if (has_flag(flgs, TR_COWARDICE))
844             creature_ptr->cursed |= TRC_COWARDICE;
845         if (has_flag(flgs, TR_LOW_MELEE))
846             creature_ptr->cursed |= TRC_LOW_MELEE;
847         if (has_flag(flgs, TR_LOW_AC))
848             creature_ptr->cursed |= TRC_LOW_AC;
849         if (has_flag(flgs, TR_LOW_MAGIC))
850             creature_ptr->cursed |= TRC_LOW_MAGIC;
851         if (has_flag(flgs, TR_FAST_DIGEST))
852             creature_ptr->cursed |= TRC_FAST_DIGEST;
853         if (has_flag(flgs, TR_SLOW_REGEN))
854             creature_ptr->cursed |= TRC_SLOW_REGEN;
855
856         creature_ptr->cursed |= (o_ptr->curse_flags & (0xFFFFFFF0L));
857         if (o_ptr->name1 == ART_CHAINSWORD)
858             creature_ptr->cursed |= TRC_CHAINSWORD;
859
860         if (has_flag(flgs, TR_TELEPORT)) {
861             if (object_is_cursed(o_ptr))
862                 creature_ptr->cursed |= TRC_TELEPORT;
863             else {
864                 concptr insc = quark_str(o_ptr->inscription);
865
866                 /* {.} will stop random teleportation. */
867                 if (o_ptr->inscription && angband_strchr(insc, '.')) {
868                 } else {
869                     creature_ptr->cursed |= TRC_TELEPORT_SELF;
870                 }
871             }
872         }
873     }
874
875     if (creature_ptr->cursed & TRC_TELEPORT)
876         creature_ptr->cursed &= ~(TRC_TELEPORT_SELF);
877
878     if ((is_specific_player_race(creature_ptr, RACE_S_FAIRY)) && (creature_ptr->pseikaku != PERSONALITY_SEXY) && (creature_ptr->cursed & TRC_AGGRAVATE)) {
879         creature_ptr->cursed &= ~(TRC_AGGRAVATE);
880     }
881 }
882
883 BIT_FLAGS has_impact(player_type *creature_ptr)
884 {
885     BIT_FLAGS result = 0L;
886     result |= check_equipment_flags(creature_ptr, TR_IMPACT);
887     return result;
888 }
889
890 void has_extra_blow(player_type *creature_ptr)
891 {
892     object_type *o_ptr;
893     BIT_FLAGS flgs[TR_FLAG_SIZE];
894     creature_ptr->extra_blows[0] = creature_ptr->extra_blows[1] = 0;
895
896     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
897         o_ptr = &creature_ptr->inventory_list[i];
898         if (!o_ptr->k_idx)
899             continue;
900
901         object_flags(creature_ptr, o_ptr, flgs);
902
903         if (has_flag(flgs, TR_INFRA))
904             creature_ptr->see_infra += o_ptr->pval;
905         if (has_flag(flgs, TR_BLOWS)) {
906             if ((i == INVEN_RARM || i == INVEN_RIGHT) && !has_two_handed_weapons(creature_ptr))
907                 creature_ptr->extra_blows[0] += o_ptr->pval;
908             else if ((i == INVEN_LARM || i == INVEN_LEFT) && !has_two_handed_weapons(creature_ptr))
909                 creature_ptr->extra_blows[1] += o_ptr->pval;
910             else {
911                 creature_ptr->extra_blows[0] += o_ptr->pval;
912                 creature_ptr->extra_blows[1] += o_ptr->pval;
913             }
914         }
915     }
916 }
917
918 BIT_FLAGS has_resist_acid(player_type *creature_ptr)
919 {
920     BIT_FLAGS result = 0L;
921
922     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
923         result |= FLAG_CAUSE_RACE;
924     }
925
926     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_YEEK || creature_ptr->prace == RACE_KLACKON)) {
927         result |= FLAG_CAUSE_RACE;
928     }
929
930     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DRACONIAN && creature_ptr->lev > 14) {
931         result |= FLAG_CAUSE_RACE;
932     }
933
934     if (creature_ptr->special_defense & KAMAE_SEIRYU || creature_ptr->special_defense & KATA_MUSOU) {
935         result |= FLAG_CAUSE_BATTLE_FORM;
936     }
937
938     if (creature_ptr->ult_res) {
939         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
940     }
941
942     result |= has_immune_acid(creature_ptr);
943
944     result |= check_equipment_flags(creature_ptr, TR_RES_ACID);
945     return result;
946
947 }
948
949 BIT_FLAGS has_resist_elec(player_type *creature_ptr)
950 {
951     BIT_FLAGS result = 0L;
952
953     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
954         result |= FLAG_CAUSE_RACE;
955     }
956
957     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DRACONIAN && creature_ptr->lev > 19) {
958         result |= FLAG_CAUSE_RACE;
959     }
960
961     if (creature_ptr->special_defense & KAMAE_SEIRYU || creature_ptr->special_defense & KATA_MUSOU) {
962         result |= FLAG_CAUSE_BATTLE_FORM;
963     }
964
965     if (creature_ptr->ult_res) {
966         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
967     }
968
969     result |= check_equipment_flags(creature_ptr, TR_RES_ELEC);
970     result |= has_immune_elec(creature_ptr);
971     return result;
972 }
973
974 BIT_FLAGS has_resist_fire(player_type *creature_ptr)
975 {
976     BIT_FLAGS result = 0L;
977
978     if (creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
979         result |= FLAG_CAUSE_RACE;
980     }
981
982     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DRACONIAN && creature_ptr->lev > 4) {
983         result |= FLAG_CAUSE_RACE;
984     }
985
986     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_IMP || creature_ptr->prace == RACE_BALROG)) {
987         result |= FLAG_CAUSE_RACE;
988     }
989
990     if (creature_ptr->special_defense & KAMAE_SEIRYU || creature_ptr->special_defense & KATA_MUSOU) {
991         result |= FLAG_CAUSE_BATTLE_FORM;
992     }
993
994     if (creature_ptr->ult_res) {
995         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
996         }
997
998     result |= check_equipment_flags(creature_ptr, TR_RES_FIRE);
999     result |= has_immune_fire(creature_ptr);
1000     return result;
1001 }
1002
1003 BIT_FLAGS has_resist_cold(player_type *creature_ptr)
1004 {
1005     BIT_FLAGS result = 0L;
1006
1007     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD || creature_ptr->mimic_form == MIMIC_VAMPIRE) {
1008         result |= FLAG_CAUSE_RACE;
1009     }
1010
1011     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_ZOMBIE) && creature_ptr->lev > 4) {
1012         result |= FLAG_CAUSE_RACE;
1013     }
1014
1015     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_DRACONIAN || creature_ptr->prace == RACE_SKELETON) && creature_ptr->lev > 9) {
1016         result |= FLAG_CAUSE_RACE;
1017     }
1018
1019     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_VAMPIRE || creature_ptr->prace == RACE_SPECTRE)) {
1020         result |= FLAG_CAUSE_RACE;
1021     }
1022
1023     if (creature_ptr->special_defense & KAMAE_SEIRYU || creature_ptr->special_defense & KATA_MUSOU) {
1024         result |= FLAG_CAUSE_BATTLE_FORM;
1025     }
1026
1027     if (creature_ptr->ult_res) {
1028         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
1029     }
1030
1031     result |= check_equipment_flags(creature_ptr, TR_RES_COLD);
1032     result |= has_immune_cold(creature_ptr);
1033     return result;
1034 }
1035
1036 BIT_FLAGS has_resist_pois(player_type *creature_ptr)
1037 {
1038     BIT_FLAGS result = 0L;
1039
1040     if (creature_ptr->pclass == CLASS_NINJA && creature_ptr->lev > 19)
1041         result |= FLAG_CAUSE_CLASS;
1042
1043     if (creature_ptr->mimic_form == MIMIC_VAMPIRE || creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1044         result |= FLAG_CAUSE_RACE;
1045     }
1046
1047     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DRACONIAN && creature_ptr->lev > 34) {
1048         result |= FLAG_CAUSE_RACE;
1049     }
1050
1051     if (!creature_ptr->mimic_form
1052         && (creature_ptr->prace == RACE_KOBOLD || creature_ptr->prace == RACE_GOLEM || creature_ptr->prace == RACE_SKELETON
1053             || creature_ptr->prace == RACE_VAMPIRE || creature_ptr->prace == RACE_SPECTRE || creature_ptr->prace == RACE_ANDROID)) {
1054         result |= FLAG_CAUSE_RACE;
1055     }
1056
1057     if (creature_ptr->special_defense & KAMAE_SEIRYU || creature_ptr->special_defense & KATA_MUSOU) {
1058         result |= FLAG_CAUSE_BATTLE_FORM;
1059     }
1060
1061     if (creature_ptr->ult_res) {
1062         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
1063     }
1064
1065     result |= check_equipment_flags(creature_ptr, TR_RES_POIS);
1066     return result;
1067 }
1068
1069 BIT_FLAGS has_resist_conf(player_type *creature_ptr)
1070 {
1071     BIT_FLAGS result = 0L;
1072
1073     if (creature_ptr->pclass == CLASS_MINDCRAFTER && creature_ptr->lev > 29)
1074         result |= FLAG_CAUSE_CLASS;
1075
1076     if (creature_ptr->pseikaku == PERSONALITY_CHARGEMAN || creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
1077         result |= FLAG_CAUSE_PERSONALITY;
1078     }
1079
1080     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_KLACKON || creature_ptr->prace == RACE_BEASTMAN || creature_ptr->prace == RACE_KUTAR)) {
1081         result |= FLAG_CAUSE_RACE;
1082     }
1083
1084     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1085         result |= FLAG_CAUSE_RACE;
1086     }
1087
1088     if (creature_ptr->ult_res || creature_ptr->magicdef) {
1089         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
1090     }
1091
1092     if (creature_ptr->special_defense & KATA_MUSOU) {
1093         result |= FLAG_CAUSE_BATTLE_FORM;
1094     }
1095
1096     result |= check_equipment_flags(creature_ptr, TR_RES_CONF);
1097     return result;
1098 }
1099
1100 BIT_FLAGS has_resist_sound(player_type *creature_ptr)
1101 {
1102     BIT_FLAGS result = 0L;
1103
1104     if (creature_ptr->pclass == CLASS_BARD) {
1105         result |= FLAG_CAUSE_CLASS;
1106     }
1107
1108     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_CYCLOPS || creature_ptr->prace == RACE_BEASTMAN)) {
1109         result |= FLAG_CAUSE_RACE;
1110     }
1111
1112     if (creature_ptr->special_defense & KATA_MUSOU) {
1113         result |= FLAG_CAUSE_BATTLE_FORM;
1114     }
1115
1116     if (creature_ptr->ult_res) {
1117         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
1118     }
1119
1120     result |= check_equipment_flags(creature_ptr, TR_RES_SOUND);
1121     return result;
1122 }
1123
1124 BIT_FLAGS has_resist_lite(player_type *creature_ptr)
1125 {
1126     BIT_FLAGS result = 0L;
1127
1128     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_ELF || creature_ptr->prace == RACE_HIGH_ELF || creature_ptr->prace == RACE_SPRITE)) {
1129         result |= FLAG_CAUSE_RACE;
1130     }
1131
1132     if (creature_ptr->special_defense & KATA_MUSOU) {
1133         result |= FLAG_CAUSE_BATTLE_FORM;
1134     }
1135
1136     if (creature_ptr->ult_res) {
1137         result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
1138     }
1139
1140     result |= check_equipment_flags(creature_ptr, TR_RES_LITE);
1141     return result;
1142 }
1143
1144 void has_resist_dark(player_type *creature_ptr)
1145 {
1146     object_type *o_ptr;
1147     BIT_FLAGS flgs[TR_FLAG_SIZE];
1148     creature_ptr->resist_dark = FALSE;
1149
1150     if (creature_ptr->mimic_form == MIMIC_VAMPIRE) {
1151         creature_ptr->resist_dark = TRUE;
1152     }
1153
1154     if (!creature_ptr->mimic_form
1155         && (creature_ptr->prace == RACE_HALF_ORC || creature_ptr->prace == RACE_HALF_OGRE || creature_ptr->prace == RACE_NIBELUNG
1156             || creature_ptr->prace == RACE_DARK_ELF || creature_ptr->prace == RACE_VAMPIRE)) {
1157         creature_ptr->resist_lite = TRUE;
1158     }
1159
1160     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1161         creature_ptr->resist_dark = TRUE;
1162     }
1163
1164     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1165         o_ptr = &creature_ptr->inventory_list[i];
1166         if (!o_ptr->k_idx)
1167             continue;
1168
1169         object_flags(creature_ptr, o_ptr, flgs);
1170
1171         if (has_flag(flgs, TR_RES_DARK))
1172             creature_ptr->resist_dark = TRUE;
1173     }
1174 }
1175
1176 void has_resist_chaos(player_type *creature_ptr)
1177 {
1178     object_type *o_ptr;
1179     BIT_FLAGS flgs[TR_FLAG_SIZE];
1180     creature_ptr->resist_chaos = FALSE;
1181
1182     if (creature_ptr->pclass == CLASS_CHAOS_WARRIOR && creature_ptr->lev > 29)
1183         creature_ptr->resist_chaos = TRUE;
1184
1185     if (creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1186         creature_ptr->resist_chaos = TRUE;
1187     }
1188
1189     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_HALF_TITAN)
1190         creature_ptr->resist_chaos = TRUE;
1191
1192     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1193         creature_ptr->resist_chaos = TRUE;
1194     }
1195
1196     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1197         o_ptr = &creature_ptr->inventory_list[i];
1198         if (!o_ptr->k_idx)
1199             continue;
1200
1201         object_flags(creature_ptr, o_ptr, flgs);
1202
1203         if (has_flag(flgs, TR_RES_CHAOS))
1204             creature_ptr->resist_chaos = TRUE;
1205     }
1206 }
1207
1208 void has_resist_disen(player_type *creature_ptr)
1209 {
1210     object_type *o_ptr;
1211     BIT_FLAGS flgs[TR_FLAG_SIZE];
1212     creature_ptr->resist_disen = FALSE;
1213
1214     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1215         creature_ptr->resist_disen = TRUE;
1216     }
1217
1218     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_NIBELUNG)
1219         creature_ptr->resist_disen = TRUE;
1220
1221     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1222         creature_ptr->resist_disen = TRUE;
1223     }
1224
1225     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1226         o_ptr = &creature_ptr->inventory_list[i];
1227         if (!o_ptr->k_idx)
1228             continue;
1229
1230         object_flags(creature_ptr, o_ptr, flgs);
1231
1232         if (has_flag(flgs, TR_RES_DISEN))
1233             creature_ptr->resist_disen = TRUE;
1234     }
1235 }
1236
1237 void has_resist_shard(player_type *creature_ptr)
1238 {
1239     object_type *o_ptr;
1240     BIT_FLAGS flgs[TR_FLAG_SIZE];
1241     creature_ptr->resist_shard = FALSE;
1242
1243     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_HALF_TITAN || creature_ptr->prace == RACE_SKELETON))
1244         creature_ptr->resist_shard = TRUE;
1245
1246     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1247         creature_ptr->resist_shard = TRUE;
1248     }
1249
1250     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1251         o_ptr = &creature_ptr->inventory_list[i];
1252         if (!o_ptr->k_idx)
1253             continue;
1254
1255         object_flags(creature_ptr, o_ptr, flgs);
1256
1257         if (has_flag(flgs, TR_RES_DISEN))
1258             creature_ptr->resist_shard = TRUE;
1259     }
1260 }
1261
1262 void has_resist_nexus(player_type *creature_ptr)
1263 {
1264     object_type *o_ptr;
1265     BIT_FLAGS flgs[TR_FLAG_SIZE];
1266     creature_ptr->resist_nexus = FALSE;
1267
1268     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1269         creature_ptr->resist_nexus = TRUE;
1270     }
1271
1272     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1273         creature_ptr->resist_nexus = TRUE;
1274     }
1275
1276     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1277         o_ptr = &creature_ptr->inventory_list[i];
1278         if (!o_ptr->k_idx)
1279             continue;
1280
1281         object_flags(creature_ptr, o_ptr, flgs);
1282
1283         if (has_flag(flgs, TR_RES_NEXUS))
1284             creature_ptr->resist_nexus = TRUE;
1285     }
1286 }
1287
1288 void has_resist_blind(player_type *creature_ptr)
1289 {
1290     object_type *o_ptr;
1291     BIT_FLAGS flgs[TR_FLAG_SIZE];
1292     creature_ptr->resist_blind = FALSE;
1293
1294     if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
1295         creature_ptr->resist_blind = TRUE;
1296     }
1297
1298     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DWARF)
1299         creature_ptr->resist_blind = TRUE;
1300
1301     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1302         creature_ptr->resist_blind = TRUE;
1303     }
1304
1305     if (creature_ptr->magicdef) {
1306         creature_ptr->resist_blind = TRUE;
1307     }
1308
1309     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1310         o_ptr = &creature_ptr->inventory_list[i];
1311         if (!o_ptr->k_idx)
1312             continue;
1313
1314         object_flags(creature_ptr, o_ptr, flgs);
1315
1316         if (has_flag(flgs, TR_RES_BLIND))
1317             creature_ptr->resist_blind = TRUE;
1318     }
1319 }
1320
1321 void has_resist_neth(player_type *creature_ptr)
1322 {
1323     object_type *o_ptr;
1324     BIT_FLAGS flgs[TR_FLAG_SIZE];
1325
1326     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD || creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_VAMPIRE) {
1327         creature_ptr->resist_neth = TRUE;
1328     }
1329
1330     if (!creature_ptr->mimic_form
1331         && (creature_ptr->prace == RACE_ZOMBIE || creature_ptr->prace == RACE_VAMPIRE || creature_ptr->prace == RACE_SPECTRE
1332             || creature_ptr->prace == RACE_BALROG))
1333         creature_ptr->resist_neth = TRUE;
1334
1335     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1336         creature_ptr->resist_neth = TRUE;
1337     }
1338
1339     if (creature_ptr->tim_res_nether) {
1340         creature_ptr->resist_neth = TRUE;
1341     }
1342
1343     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1344         o_ptr = &creature_ptr->inventory_list[i];
1345         if (!o_ptr->k_idx)
1346             continue;
1347
1348         object_flags(creature_ptr, o_ptr, flgs);
1349
1350         if (has_flag(flgs, TR_RES_NETHER))
1351             creature_ptr->resist_neth = TRUE;
1352     }
1353 }
1354
1355 void has_resist_time(player_type *creature_ptr)
1356 {
1357     object_type *o_ptr;
1358     BIT_FLAGS flgs[TR_FLAG_SIZE];
1359     creature_ptr->resist_time = FALSE;
1360
1361     if (creature_ptr->tim_res_time) {
1362         creature_ptr->resist_time = TRUE;
1363     }
1364
1365     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1366         o_ptr = &creature_ptr->inventory_list[i];
1367         if (!o_ptr->k_idx)
1368             continue;
1369
1370         object_flags(creature_ptr, o_ptr, flgs);
1371         if (o_ptr->name2 == EGO_RING_RES_TIME)
1372             creature_ptr->resist_time = TRUE;
1373     }
1374 }
1375
1376 void has_resist_water(player_type *creature_ptr)
1377 {
1378     creature_ptr->resist_water = FALSE;
1379
1380     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_MERFOLK)
1381         creature_ptr->resist_water = TRUE;
1382 }
1383
1384 void has_resist_fear(player_type *creature_ptr)
1385 {
1386     object_type *o_ptr;
1387     BIT_FLAGS flgs[TR_FLAG_SIZE];
1388     creature_ptr->resist_fear = FALSE;
1389
1390     if (creature_ptr->muta3 & MUT3_FEARLESS)
1391         creature_ptr->resist_fear = TRUE;
1392
1393     switch (creature_ptr->pclass) {
1394     case CLASS_WARRIOR:
1395         if (creature_ptr->lev > 29)
1396             creature_ptr->resist_fear = TRUE;
1397         break;
1398     case CLASS_PALADIN:
1399         if (creature_ptr->lev > 39)
1400             creature_ptr->resist_fear = TRUE;
1401         break;
1402     case CLASS_CHAOS_WARRIOR:
1403         if (creature_ptr->lev > 39)
1404             creature_ptr->resist_fear = TRUE;
1405         break;
1406     case CLASS_MINDCRAFTER:
1407         if (creature_ptr->lev > 9)
1408             creature_ptr->resist_fear = TRUE;
1409         break;
1410     case CLASS_SAMURAI:
1411         if (creature_ptr->lev > 29)
1412             creature_ptr->resist_fear = TRUE;
1413         break;
1414     case CLASS_NINJA:
1415         creature_ptr->resist_fear = TRUE;
1416         break;
1417     }
1418
1419     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1420         creature_ptr->resist_fear = TRUE;
1421     }
1422
1423     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_BARBARIAN)
1424         creature_ptr->resist_fear = TRUE;
1425
1426     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1427         creature_ptr->resist_fear = TRUE;
1428     }
1429
1430     if (is_hero(creature_ptr) || creature_ptr->shero) {
1431         creature_ptr->resist_fear = TRUE;
1432     }
1433
1434     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1435         o_ptr = &creature_ptr->inventory_list[i];
1436         if (!o_ptr->k_idx)
1437             continue;
1438
1439         object_flags(creature_ptr, o_ptr, flgs);
1440         if (has_flag(flgs, TR_RES_FEAR))
1441             creature_ptr->resist_fear = TRUE;
1442     }
1443 }
1444
1445 BIT_FLAGS has_immune_acid(player_type *creature_ptr)
1446 {
1447     BIT_FLAGS result = 0L;
1448     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_YEEK && creature_ptr->lev > 19)
1449         result |= FLAG_CAUSE_RACE;
1450
1451     if (creature_ptr->ele_immune) {
1452         if (creature_ptr->special_defense & DEFENSE_ACID)
1453             result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
1454     }
1455
1456     result |= check_equipment_flags(creature_ptr, TR_IM_ACID);
1457     return result;
1458 }
1459
1460 BIT_FLAGS has_immune_elec(player_type *creature_ptr)
1461 {
1462     BIT_FLAGS result = 0L;
1463
1464         if (creature_ptr->ele_immune) {
1465         if (creature_ptr->special_defense & DEFENSE_ELEC)
1466             result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
1467     }
1468
1469     result |= check_equipment_flags(creature_ptr, TR_IM_ELEC);
1470     return result;
1471 }
1472
1473 BIT_FLAGS has_immune_fire(player_type *creature_ptr)
1474 {
1475     BIT_FLAGS result = 0L;
1476
1477         if (creature_ptr->ele_immune) {
1478         if (creature_ptr->special_defense & DEFENSE_FIRE)
1479             result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
1480     }
1481
1482     result |= check_equipment_flags(creature_ptr, TR_IM_FIRE);
1483     return result;
1484 }
1485
1486 BIT_FLAGS has_immune_cold(player_type *creature_ptr)
1487 {
1488     BIT_FLAGS result = 0L;
1489
1490         if (creature_ptr->ele_immune) {
1491         if (creature_ptr->special_defense & DEFENSE_COLD)
1492            result |= FLAG_CAUSE_MAGIC_TIME_EFFECT;
1493     }
1494
1495     result |= check_equipment_flags(creature_ptr, TR_IM_COLD);
1496     return result;
1497 }
1498
1499 bool has_right_hand_weapon(player_type *creature_ptr)
1500 {
1501     if (has_melee_weapon(creature_ptr, INVEN_RARM))
1502         return TRUE;
1503
1504     if (can_two_hands_wielding(creature_ptr)) {
1505         switch (creature_ptr->pclass) {
1506         case CLASS_MONK:
1507         case CLASS_FORCETRAINER:
1508         case CLASS_BERSERKER:
1509             if (empty_hands(creature_ptr, FALSE) == (EMPTY_HAND_RARM | EMPTY_HAND_LARM)) {
1510                 return TRUE;
1511             }
1512             break;
1513         }
1514     }
1515
1516     return FALSE;
1517 }
1518
1519 bool has_left_hand_weapon(player_type *creature_ptr) { return has_melee_weapon(creature_ptr, INVEN_LARM); }
1520
1521 bool has_two_handed_weapons(player_type *creature_ptr)
1522 {
1523     if (can_two_hands_wielding(creature_ptr)) {
1524         if (has_right_hand_weapon(creature_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_LARM)
1525             && object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_RARM])) {
1526             return TRUE;
1527         } else if (has_left_hand_weapon(creature_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_RARM)
1528             && object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_LARM])) {
1529             return TRUE;
1530         }
1531     }
1532     return FALSE;
1533 }
1534
1535 void has_lite(player_type *creature_ptr)
1536 {
1537     creature_ptr->lite = FALSE;
1538     if (creature_ptr->pclass == CLASS_NINJA)
1539         return;
1540
1541     if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
1542         creature_ptr->lite = TRUE;
1543     }
1544
1545     if (creature_ptr->mimic_form == MIMIC_VAMPIRE) {
1546         creature_ptr->lite = TRUE;
1547     }
1548
1549     if (creature_ptr->muta3 & MUT3_FIRE_BODY) {
1550         creature_ptr->lite = TRUE;
1551     }
1552
1553     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_VAMPIRE)
1554         creature_ptr->lite = TRUE;
1555
1556     if (creature_ptr->sh_fire)
1557         creature_ptr->lite = TRUE;
1558
1559     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1560         creature_ptr->lite = TRUE;
1561     }
1562 }
1563
1564 bool is_disable_two_handed_bonus(player_type *creature_ptr, int i)
1565 {
1566     object_type *o_ptr;
1567     o_ptr = &creature_ptr->inventory_list[INVEN_RARM + i];
1568     if (has_melee_weapon(creature_ptr, INVEN_RARM + i)) {
1569         if (calc_weapon_weight_limit(creature_ptr) * 2 >= o_ptr->weight / 10 && has_two_handed_weapons(creature_ptr)
1570             && (calc_weapon_weight_limit(creature_ptr) * 2 < o_ptr->weight / 5))
1571             return TRUE;
1572     }
1573     return FALSE;
1574 }
1575
1576 bool is_icky_wield_weapon(player_type *creature_ptr, int i)
1577 {
1578     object_type *o_ptr;
1579     BIT_FLAGS flgs[TR_FLAG_SIZE];
1580     o_ptr = &creature_ptr->inventory_list[INVEN_RARM + i];
1581     object_flags(creature_ptr, o_ptr, flgs);
1582
1583     if ((creature_ptr->pclass == CLASS_PRIEST) && (!(has_flag(flgs, TR_BLESSED))) && ((o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM))) {
1584         return TRUE;
1585     } else if (creature_ptr->pclass == CLASS_SORCERER) {
1586         if (!((o_ptr->tval == TV_HAFTED) && ((o_ptr->sval == SV_WIZSTAFF) || (o_ptr->sval == SV_NAMAKE_HAMMER)))) {
1587             return TRUE;
1588         }
1589     }
1590     if (is_not_monk_weapon(creature_ptr, i) || is_not_ninja_weapon(creature_ptr, i)) {
1591         return TRUE;
1592     }
1593     return FALSE;
1594 }
1595
1596 bool is_riding_wield_weapon(player_type *creature_ptr, int i)
1597 {
1598     object_type *o_ptr;
1599     BIT_FLAGS flgs[TR_FLAG_SIZE];
1600     o_ptr = &creature_ptr->inventory_list[INVEN_RARM + i];
1601     object_flags(creature_ptr, o_ptr, flgs);
1602     if (creature_ptr->riding != 0 && !(o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE))
1603         && !has_flag(flgs, TR_RIDING)) {
1604         return TRUE;
1605     }
1606     return FALSE;
1607 }
1608
1609 bool is_not_ninja_weapon(player_type *creature_ptr, int i)
1610 {
1611     tval_type tval = creature_ptr->inventory_list[INVEN_RARM + i].tval - TV_WEAPON_BEGIN;
1612     OBJECT_SUBTYPE_VALUE sval = creature_ptr->inventory_list[INVEN_RARM + i].sval;
1613     return creature_ptr->pclass == CLASS_NINJA
1614         && !((s_info[CLASS_NINJA].w_max[tval][sval] > WEAPON_EXP_BEGINNER) && (creature_ptr->inventory_list[INVEN_LARM - i].tval != TV_SHIELD));
1615 }
1616
1617 bool is_not_monk_weapon(player_type *creature_ptr, int i)
1618 {
1619     tval_type tval = creature_ptr->inventory_list[INVEN_RARM + i].tval - TV_WEAPON_BEGIN;
1620     OBJECT_SUBTYPE_VALUE sval = creature_ptr->inventory_list[INVEN_RARM + i].sval;
1621     return (creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER) && (!s_info[creature_ptr->pclass].w_max[tval][sval]);
1622 }
1623
1624 bool has_good_luck(player_type *creature_ptr) { return (creature_ptr->pseikaku == PERSONALITY_LUCKY) || (creature_ptr->muta3 |= MUT3_GOOD_LUCK); };