OSDN Git Service

Merge remote-tracking branch 'remotes/origin/For2.2.2-Fix-Hourier' into For2.2.2...
[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 bool have_kill_wall(player_type *creature_ptr)
34 {
35     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD || music_singing(creature_ptr, MUSIC_WALL)) {
36         return TRUE;
37     }
38
39     if (creature_ptr->riding) {
40         monster_type *riding_m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
41         monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
42         if (riding_r_ptr->flags2 & RF2_KILL_WALL)
43             return TRUE;
44     }
45
46         return FALSE;
47 }
48
49 bool have_pass_wall(player_type *creature_ptr)
50 {
51     bool pow = FALSE;
52
53     if (creature_ptr->wraith_form || creature_ptr->tim_pass_wall || (!creature_ptr->mimic_form && creature_ptr->prace == RACE_SPECTRE)) {
54         pow = TRUE;
55     }
56
57     if (creature_ptr->riding) {
58         monster_type *riding_m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
59         monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
60         if (!(riding_r_ptr->flags2 & RF2_PASS_WALL))
61             pow = FALSE;
62     }
63
64         return pow;
65 }
66
67 void have_xtra_might(player_type *creature_ptr)
68 {
69     object_type *o_ptr;
70     BIT_FLAGS flgs[TR_FLAG_SIZE];
71
72     creature_ptr->xtra_might = FALSE;
73
74     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
75         o_ptr = &creature_ptr->inventory_list[i];
76         if (!o_ptr->k_idx)
77             continue;
78
79         object_flags(creature_ptr, o_ptr, flgs);
80
81         if (have_flag(flgs, TR_XTRA_MIGHT))
82             creature_ptr->xtra_might = TRUE;
83     }
84 }
85
86 void have_esp_evil(player_type *creature_ptr)
87 {
88     object_type *o_ptr;
89     BIT_FLAGS flgs[TR_FLAG_SIZE];
90
91     creature_ptr->esp_evil = FALSE;
92
93     if (creature_ptr->realm1 == REALM_HEX) {
94         if (hex_spelling(creature_ptr, HEX_DETECT_EVIL))
95             creature_ptr->esp_evil = TRUE;
96     }
97
98     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
99         o_ptr = &creature_ptr->inventory_list[i];
100         if (!o_ptr->k_idx)
101             continue;
102
103         object_flags(creature_ptr, o_ptr, flgs);
104
105         if (have_flag(flgs, TR_ESP_EVIL))
106             creature_ptr->esp_evil = TRUE;
107     }
108 }
109
110 void have_esp_animal(player_type *creature_ptr)
111 {
112     object_type *o_ptr;
113     BIT_FLAGS flgs[TR_FLAG_SIZE];
114
115     creature_ptr->esp_animal = FALSE;
116
117     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
118         o_ptr = &creature_ptr->inventory_list[i];
119         if (!o_ptr->k_idx)
120             continue;
121
122         object_flags(creature_ptr, o_ptr, flgs);
123
124         if (have_flag(flgs, TR_ESP_ANIMAL))
125             creature_ptr->esp_animal = TRUE;
126     }
127 }
128
129 void have_esp_undead(player_type *creature_ptr)
130 {
131     object_type *o_ptr;
132     BIT_FLAGS flgs[TR_FLAG_SIZE];
133
134     creature_ptr->esp_undead = FALSE;
135
136     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
137         o_ptr = &creature_ptr->inventory_list[i];
138         if (!o_ptr->k_idx)
139             continue;
140
141         object_flags(creature_ptr, o_ptr, flgs);
142
143         if (have_flag(flgs, TR_ESP_UNDEAD))
144             creature_ptr->esp_undead = TRUE;
145     }
146 }
147
148 void have_esp_demon(player_type *creature_ptr)
149 {
150     object_type *o_ptr;
151     BIT_FLAGS flgs[TR_FLAG_SIZE];
152
153     creature_ptr->esp_demon = FALSE;
154
155     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
156         o_ptr = &creature_ptr->inventory_list[i];
157         if (!o_ptr->k_idx)
158             continue;
159
160         object_flags(creature_ptr, o_ptr, flgs);
161
162         if (have_flag(flgs, TR_ESP_DEMON))
163             creature_ptr->esp_demon = TRUE;
164     }
165 }
166
167 void have_esp_orc(player_type *creature_ptr)
168 {
169     object_type *o_ptr;
170     BIT_FLAGS flgs[TR_FLAG_SIZE];
171
172     creature_ptr->esp_orc = FALSE;
173
174     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
175         o_ptr = &creature_ptr->inventory_list[i];
176         if (!o_ptr->k_idx)
177             continue;
178
179         object_flags(creature_ptr, o_ptr, flgs);
180
181         if (have_flag(flgs, TR_ESP_ORC))
182             creature_ptr->esp_orc = TRUE;
183     }
184 }
185
186 void have_esp_troll(player_type *creature_ptr)
187 {
188     object_type *o_ptr;
189     BIT_FLAGS flgs[TR_FLAG_SIZE];
190
191     creature_ptr->esp_troll = FALSE;
192
193     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
194         o_ptr = &creature_ptr->inventory_list[i];
195         if (!o_ptr->k_idx)
196             continue;
197
198         object_flags(creature_ptr, o_ptr, flgs);
199
200         if (have_flag(flgs, TR_ESP_TROLL))
201             creature_ptr->esp_troll = TRUE;
202     }
203 }
204
205 void have_esp_giant(player_type *creature_ptr)
206 {
207     object_type *o_ptr;
208     BIT_FLAGS flgs[TR_FLAG_SIZE];
209
210     creature_ptr->esp_giant = FALSE;
211
212     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
213         o_ptr = &creature_ptr->inventory_list[i];
214         if (!o_ptr->k_idx)
215             continue;
216
217         object_flags(creature_ptr, o_ptr, flgs);
218
219         if (have_flag(flgs, TR_ESP_GIANT))
220             creature_ptr->esp_giant = TRUE;
221     }
222 }
223
224 void have_esp_dragon(player_type *creature_ptr)
225 {
226     object_type *o_ptr;
227     BIT_FLAGS flgs[TR_FLAG_SIZE];
228
229     creature_ptr->esp_dragon = FALSE;
230
231     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
232         o_ptr = &creature_ptr->inventory_list[i];
233         if (!o_ptr->k_idx)
234             continue;
235
236         object_flags(creature_ptr, o_ptr, flgs);
237
238         if (have_flag(flgs, TR_ESP_DRAGON))
239             creature_ptr->esp_dragon = TRUE;
240     }
241 }
242
243 void have_esp_human(player_type *creature_ptr)
244 {
245     object_type *o_ptr;
246     BIT_FLAGS flgs[TR_FLAG_SIZE];
247
248     creature_ptr->esp_human = FALSE;
249
250     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
251         o_ptr = &creature_ptr->inventory_list[i];
252         if (!o_ptr->k_idx)
253             continue;
254
255         object_flags(creature_ptr, o_ptr, flgs);
256
257         if (have_flag(flgs, TR_ESP_HUMAN))
258             creature_ptr->esp_human = TRUE;
259     }
260 }
261
262 void have_esp_good(player_type *creature_ptr)
263 {
264     object_type *o_ptr;
265     BIT_FLAGS flgs[TR_FLAG_SIZE];
266
267     creature_ptr->esp_good = FALSE;
268
269     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
270         o_ptr = &creature_ptr->inventory_list[i];
271         if (!o_ptr->k_idx)
272             continue;
273
274         object_flags(creature_ptr, o_ptr, flgs);
275
276         if (have_flag(flgs, TR_ESP_GOOD))
277             creature_ptr->esp_good = TRUE;
278     }
279 }
280
281 void have_esp_nonliving(player_type *creature_ptr)
282 {
283     object_type *o_ptr;
284     BIT_FLAGS flgs[TR_FLAG_SIZE];
285
286     creature_ptr->esp_nonliving = FALSE;
287
288     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
289         o_ptr = &creature_ptr->inventory_list[i];
290         if (!o_ptr->k_idx)
291             continue;
292
293         object_flags(creature_ptr, o_ptr, flgs);
294
295         if (have_flag(flgs, TR_ESP_NONLIVING))
296             creature_ptr->esp_nonliving = TRUE;
297     }
298 }
299
300 void have_esp_unique(player_type *creature_ptr)
301 {
302     object_type *o_ptr;
303     BIT_FLAGS flgs[TR_FLAG_SIZE];
304
305     creature_ptr->esp_unique = FALSE;
306
307     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
308         o_ptr = &creature_ptr->inventory_list[i];
309         if (!o_ptr->k_idx)
310             continue;
311
312         object_flags(creature_ptr, o_ptr, flgs);
313
314         if (have_flag(flgs, TR_ESP_UNIQUE))
315             creature_ptr->esp_unique = TRUE;
316     }
317 }
318
319 void have_esp_telepathy(player_type *creature_ptr)
320 {
321     object_type *o_ptr;
322     BIT_FLAGS flgs[TR_FLAG_SIZE];
323
324     creature_ptr->telepathy = FALSE;
325
326     if (is_time_limit_esp(creature_ptr)) {
327         creature_ptr->telepathy = TRUE;
328     }
329
330     if (creature_ptr->muta3 & MUT3_ESP) {
331         creature_ptr->telepathy = TRUE;
332     }
333
334     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_MIND_FLAYER && creature_ptr->lev > 29)
335         creature_ptr->telepathy = TRUE;
336
337     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_SPECTRE && creature_ptr->lev > 34)
338         creature_ptr->telepathy = TRUE;
339
340     if (creature_ptr->pclass == CLASS_MINDCRAFTER && creature_ptr->lev > 39)
341         creature_ptr->telepathy = TRUE;
342
343     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
344         creature_ptr->telepathy = TRUE;
345     }
346
347     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
348         creature_ptr->telepathy = TRUE;
349     }
350
351     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
352         o_ptr = &creature_ptr->inventory_list[i];
353         if (!o_ptr->k_idx)
354             continue;
355
356         object_flags(creature_ptr, o_ptr, flgs);
357
358         if (have_flag(flgs, TR_TELEPATHY))
359             creature_ptr->telepathy = TRUE;
360     }
361 }
362
363 void have_bless_blade(player_type *creature_ptr)
364 {
365     object_type *o_ptr;
366     BIT_FLAGS flgs[TR_FLAG_SIZE];
367
368     creature_ptr->bless_blade = FALSE;
369
370     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
371         o_ptr = &creature_ptr->inventory_list[i];
372         if (!o_ptr->k_idx)
373             continue;
374
375         object_flags(creature_ptr, o_ptr, flgs);
376
377         if (have_flag(flgs, TR_BLESSED))
378             creature_ptr->bless_blade = TRUE;
379     }
380 }
381
382 void have_easy2_weapon(player_type *creature_ptr)
383 {
384     object_type *o_ptr;
385     BIT_FLAGS flgs[TR_FLAG_SIZE];
386
387     creature_ptr->easy_2weapon = FALSE;
388
389     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
390         o_ptr = &creature_ptr->inventory_list[i];
391         if (!o_ptr->k_idx)
392             continue;
393
394         object_flags(creature_ptr, o_ptr, flgs);
395
396         if (o_ptr->name2 == EGO_2WEAPON)
397             creature_ptr->easy_2weapon = TRUE;
398     }
399 }
400
401 void have_down_saving(player_type *creature_ptr)
402 {
403     object_type *o_ptr;
404     BIT_FLAGS flgs[TR_FLAG_SIZE];
405
406     creature_ptr->down_saving = FALSE;
407
408     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
409         o_ptr = &creature_ptr->inventory_list[i];
410         if (!o_ptr->k_idx)
411             continue;
412
413         object_flags(creature_ptr, o_ptr, flgs);
414
415         if (o_ptr->name2 == EGO_AMU_NAIVETY)
416             creature_ptr->down_saving = TRUE;
417     }
418 }
419
420 void have_no_ac(player_type *creature_ptr)
421 {
422     object_type *o_ptr;
423     BIT_FLAGS flgs[TR_FLAG_SIZE];
424
425     creature_ptr->yoiyami = FALSE;
426
427     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
428         o_ptr = &creature_ptr->inventory_list[i];
429         if (!o_ptr->k_idx)
430             continue;
431
432         object_flags(creature_ptr, o_ptr, flgs);
433
434         if (o_ptr->name2 == EGO_YOIYAMI)
435             creature_ptr->yoiyami = TRUE;
436     }
437 }
438
439 void have_no_flowed(player_type *creature_ptr)
440 {
441     object_type *o_ptr;
442     bool have_sw = FALSE, have_kabe = FALSE;
443     OBJECT_IDX this_o_idx, next_o_idx = 0;
444
445     creature_ptr->no_flowed = FALSE;
446
447     if (creature_ptr->pass_wall && !creature_ptr->kill_wall)
448         creature_ptr->no_flowed = TRUE;
449
450     for (int i = 0; i < INVEN_PACK; i++) {
451         if ((creature_ptr->inventory_list[i].tval == TV_NATURE_BOOK) && (creature_ptr->inventory_list[i].sval == 2))
452             have_sw = TRUE;
453         if ((creature_ptr->inventory_list[i].tval == TV_CRAFT_BOOK) && (creature_ptr->inventory_list[i].sval == 2))
454             have_kabe = TRUE;
455     }
456
457     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) {
458         o_ptr = &creature_ptr->current_floor_ptr->o_list[this_o_idx];
459         next_o_idx = o_ptr->next_o_idx;
460
461         if ((o_ptr->tval == TV_NATURE_BOOK) && (o_ptr->sval == 2))
462             have_sw = TRUE;
463         if ((o_ptr->tval == TV_CRAFT_BOOK) && (o_ptr->sval == 2))
464             have_kabe = TRUE;
465     }
466
467     if (have_sw && ((creature_ptr->realm1 == REALM_NATURE) || (creature_ptr->realm2 == REALM_NATURE) || (creature_ptr->pclass == CLASS_SORCERER))) {
468         const magic_type *s_ptr = &mp_ptr->info[REALM_NATURE - 1][SPELL_SW];
469         if (creature_ptr->lev >= s_ptr->slevel)
470             creature_ptr->no_flowed = TRUE;
471     }
472
473     if (have_kabe && ((creature_ptr->realm1 == REALM_CRAFT) || (creature_ptr->realm2 == REALM_CRAFT) || (creature_ptr->pclass == CLASS_SORCERER))) {
474         const magic_type *s_ptr = &mp_ptr->info[REALM_CRAFT - 1][SPELL_WALL];
475         if (creature_ptr->lev >= s_ptr->slevel)
476             creature_ptr->no_flowed = TRUE;
477     }
478 }
479
480 void have_mighty_throw(player_type *creature_ptr)
481 {
482     object_type *o_ptr;
483
484     creature_ptr->mighty_throw = FALSE;
485
486     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
487         o_ptr = &creature_ptr->inventory_list[i];
488         if (!o_ptr->k_idx)
489             continue;
490
491         if (o_ptr->name2 == EGO_RING_THROW)
492             creature_ptr->mighty_throw = TRUE;
493     }
494 }
495
496 void have_dec_mana(player_type *creature_ptr)
497 {
498     object_type *o_ptr;
499     BIT_FLAGS flgs[TR_FLAG_SIZE];
500
501     creature_ptr->xtra_might = FALSE;
502
503     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
504         o_ptr = &creature_ptr->inventory_list[i];
505         if (!o_ptr->k_idx)
506             continue;
507
508         object_flags(creature_ptr, o_ptr, flgs);
509
510         if (have_flag(flgs, TR_DEC_MANA))
511             creature_ptr->dec_mana = TRUE;
512     }
513 }
514
515 void have_reflect(player_type *creature_ptr)
516 {
517     object_type *o_ptr;
518     BIT_FLAGS flgs[TR_FLAG_SIZE];
519
520     creature_ptr->reflect = FALSE;
521
522     if (creature_ptr->pclass == CLASS_BERSERKER && creature_ptr->lev > 39)
523         creature_ptr->reflect = TRUE;
524
525     if (creature_ptr->pclass == CLASS_MIRROR_MASTER && creature_ptr->lev > 39)
526         creature_ptr->reflect = TRUE;
527
528     if (creature_ptr->special_defense & KAMAE_GENBU) {
529         creature_ptr->reflect = TRUE;
530     }
531
532     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
533         creature_ptr->reflect = TRUE;
534     }
535
536     if (creature_ptr->wraith_form) {
537         creature_ptr->reflect = TRUE;
538     }
539
540     if (creature_ptr->magicdef) {
541         creature_ptr->reflect = TRUE;
542     }
543
544     if (creature_ptr->tim_reflect) {
545         creature_ptr->reflect = TRUE;
546     }
547
548     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
549         o_ptr = &creature_ptr->inventory_list[i];
550         if (!o_ptr->k_idx)
551             continue;
552
553         object_flags(creature_ptr, o_ptr, flgs);
554
555         if (have_flag(flgs, TR_REFLECT))
556             creature_ptr->reflect = TRUE;
557     }
558 }
559
560 void have_see_nocto(player_type *creature_ptr)
561 {
562     creature_ptr->see_nocto = FALSE;
563
564     if (creature_ptr->pclass == CLASS_NINJA)
565         creature_ptr->see_nocto = TRUE;
566 }
567
568 void have_warning(player_type *creature_ptr)
569 {
570     object_type *o_ptr;
571     BIT_FLAGS flgs[TR_FLAG_SIZE];
572
573     creature_ptr->warning = FALSE;
574
575     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
576         o_ptr = &creature_ptr->inventory_list[i];
577         if (!o_ptr->k_idx)
578             continue;
579
580         object_flags(creature_ptr, o_ptr, flgs);
581
582         if (have_flag(flgs, TR_WARNING)) {
583             if (!o_ptr->inscription || !(angband_strchr(quark_str(o_ptr->inscription), '$')))
584                 creature_ptr->warning = TRUE;
585         }
586     }
587 }
588
589 void have_anti_magic(player_type *creature_ptr)
590 {
591     object_type *o_ptr;
592     BIT_FLAGS flgs[TR_FLAG_SIZE];
593
594     creature_ptr->anti_magic = FALSE;
595
596     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
597         o_ptr = &creature_ptr->inventory_list[i];
598         if (!o_ptr->k_idx)
599             continue;
600
601         object_flags(creature_ptr, o_ptr, flgs);
602
603         if (have_flag(flgs, TR_NO_MAGIC))
604             creature_ptr->anti_magic = TRUE;
605     }
606 }
607
608 void have_anti_tele(player_type *creature_ptr)
609 {
610     object_type *o_ptr;
611     BIT_FLAGS flgs[TR_FLAG_SIZE];
612
613     creature_ptr->anti_tele = FALSE;
614
615     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
616         o_ptr = &creature_ptr->inventory_list[i];
617         if (!o_ptr->k_idx)
618             continue;
619
620         object_flags(creature_ptr, o_ptr, flgs);
621
622         if (have_flag(flgs, TR_NO_TELE))
623             creature_ptr->anti_tele = TRUE;
624     }
625 }
626
627 void have_sh_fire(player_type *creature_ptr)
628 {
629     object_type *o_ptr;
630     BIT_FLAGS flgs[TR_FLAG_SIZE];
631     creature_ptr->sh_fire = FALSE;
632
633     if (creature_ptr->muta3 & MUT3_FIRE_BODY) {
634         creature_ptr->sh_fire = TRUE;
635     }
636
637     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
638         creature_ptr->sh_fire = TRUE;
639     }
640
641     if (creature_ptr->realm1 == REALM_HEX) {
642         if (hex_spelling(creature_ptr, HEX_DEMON_AURA)) {
643             creature_ptr->sh_fire = TRUE;
644         }
645     }
646
647     if (creature_ptr->special_defense & KAMAE_SEIRYU) {
648         creature_ptr->sh_fire = TRUE;
649     }
650
651     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
652         creature_ptr->sh_fire = TRUE;
653     }
654
655     if (creature_ptr->tim_sh_fire) {
656         creature_ptr->sh_fire = TRUE;
657     }
658
659     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
660         o_ptr = &creature_ptr->inventory_list[i];
661         if (!o_ptr->k_idx)
662             continue;
663
664         object_flags(creature_ptr, o_ptr, flgs);
665         if (have_flag(flgs, TR_SH_FIRE))
666             creature_ptr->sh_fire = TRUE;
667     }
668 }
669
670 void have_sh_elec(player_type *creature_ptr)
671 {
672     object_type *o_ptr;
673     BIT_FLAGS flgs[TR_FLAG_SIZE];
674     creature_ptr->sh_elec = FALSE;
675
676     if (creature_ptr->muta3 & MUT3_ELEC_TOUC)
677         creature_ptr->sh_elec = TRUE;
678
679     if (creature_ptr->realm1 == REALM_HEX) {
680         if (hex_spelling(creature_ptr, HEX_SHOCK_CLOAK)) {
681             creature_ptr->sh_elec = TRUE;
682         }
683     }
684
685     if (creature_ptr->special_defense & KAMAE_SEIRYU) {
686         creature_ptr->sh_elec = TRUE;
687     }
688
689     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
690         creature_ptr->sh_elec = TRUE;
691     }
692
693     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
694         o_ptr = &creature_ptr->inventory_list[i];
695         if (!o_ptr->k_idx)
696             continue;
697
698         object_flags(creature_ptr, o_ptr, flgs);
699         if (have_flag(flgs, TR_SH_ELEC))
700             creature_ptr->sh_elec = TRUE;
701     }
702 }
703
704 void have_sh_cold(player_type *creature_ptr)
705 {
706     object_type *o_ptr;
707     BIT_FLAGS flgs[TR_FLAG_SIZE];
708     creature_ptr->sh_cold = FALSE;
709
710     if (creature_ptr->realm1 == REALM_HEX) {
711         if (hex_spelling(creature_ptr, HEX_ICE_ARMOR)) {
712             creature_ptr->sh_cold = TRUE;
713         }
714     }
715
716     if (creature_ptr->special_defense & KAMAE_SEIRYU) {
717         creature_ptr->sh_cold = TRUE;
718     }
719
720     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
721         creature_ptr->sh_cold = TRUE;
722     }
723
724     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
725         o_ptr = &creature_ptr->inventory_list[i];
726         if (!o_ptr->k_idx)
727             continue;
728
729         object_flags(creature_ptr, o_ptr, flgs);
730         if (have_flag(flgs, TR_SH_COLD))
731             creature_ptr->sh_cold = TRUE;
732     }
733 }
734
735 void have_easy_spell(player_type *creature_ptr)
736 {
737     object_type *o_ptr;
738     BIT_FLAGS flgs[TR_FLAG_SIZE];
739     creature_ptr->easy_spell = FALSE;
740     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
741         o_ptr = &creature_ptr->inventory_list[i];
742         if (!o_ptr->k_idx)
743             continue;
744
745         object_flags(creature_ptr, o_ptr, flgs);
746         if (have_flag(flgs, TR_EASY_SPELL))
747             creature_ptr->easy_spell = TRUE;
748     }
749 }
750
751 void have_heavy_spell(player_type *creature_ptr)
752 {
753     object_type *o_ptr;
754     BIT_FLAGS flgs[TR_FLAG_SIZE];
755     creature_ptr->heavy_spell = FALSE;
756     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
757         o_ptr = &creature_ptr->inventory_list[i];
758         if (!o_ptr->k_idx)
759             continue;
760
761         object_flags(creature_ptr, o_ptr, flgs);
762         if (o_ptr->name2 == EGO_AMU_FOOL)
763             creature_ptr->heavy_spell = TRUE;
764     }
765 }
766
767 void have_hold_exp(player_type *creature_ptr)
768 {
769     object_type *o_ptr;
770     BIT_FLAGS flgs[TR_FLAG_SIZE];
771
772     creature_ptr->hold_exp = FALSE;
773
774     if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
775         creature_ptr->hold_exp = TRUE;
776     }
777
778     if (creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_DEMON_LORD || creature_ptr->mimic_form == MIMIC_VAMPIRE) {
779         creature_ptr->hold_exp = TRUE;
780     }
781
782     if (is_specific_player_race(creature_ptr, RACE_HOBBIT) || is_specific_player_race(creature_ptr, RACE_SKELETON) ||
783         is_specific_player_race(creature_ptr, RACE_ZOMBIE) || is_specific_player_race(creature_ptr, RACE_VAMPIRE) ||
784                 is_specific_player_race(creature_ptr, RACE_SPECTRE) || is_specific_player_race(creature_ptr, RACE_BALROG) ||
785         is_specific_player_race(creature_ptr, RACE_ANDROID)) {
786         creature_ptr->hold_exp = TRUE;
787     }
788
789     if (is_specific_player_race(creature_ptr, RACE_GOLEM)) {
790         if (creature_ptr->lev > 34)
791             creature_ptr->hold_exp = TRUE;
792     }
793
794     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
795         creature_ptr->hold_exp = TRUE;
796     }
797
798     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
799         o_ptr = &creature_ptr->inventory_list[i];
800         if (!o_ptr->k_idx)
801             continue;
802
803         object_flags(creature_ptr, o_ptr, flgs);
804         if (have_flag(flgs, TR_HOLD_EXP))
805             creature_ptr->hold_exp = TRUE;
806     }
807 }
808
809 void have_see_inv(player_type *creature_ptr)
810 {
811     object_type *o_ptr;
812     BIT_FLAGS flgs[TR_FLAG_SIZE];
813     creature_ptr->see_inv = FALSE;
814
815     if (creature_ptr->pclass == CLASS_NINJA || creature_ptr->lev > 29)
816         creature_ptr->see_inv = TRUE;
817
818     if (creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_DEMON_LORD || creature_ptr->mimic_form == MIMIC_VAMPIRE) {
819         creature_ptr->see_inv = TRUE;
820     }
821
822     if (!creature_ptr->mimic_form
823         && (creature_ptr->prace == RACE_HIGH_ELF || creature_ptr->prace == RACE_GOLEM || creature_ptr->prace == RACE_SKELETON
824             || creature_ptr->prace == RACE_ZOMBIE || creature_ptr->prace == RACE_SPECTRE || creature_ptr->prace == RACE_ARCHON)) {
825         creature_ptr->see_inv = TRUE;
826     }
827
828     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DARK_ELF) {
829         if (creature_ptr->lev > 19)
830             creature_ptr->see_inv = TRUE;
831     }
832
833     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_MIND_FLAYER) {
834         if (creature_ptr->lev > 14)
835             creature_ptr->see_inv = TRUE;
836     }
837
838     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_IMP || creature_ptr->prace == RACE_BALROG)) {
839         if (creature_ptr->lev > 9)
840             creature_ptr->see_inv = TRUE;
841     }
842
843     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
844         creature_ptr->see_inv = TRUE;
845     }
846
847     if (creature_ptr->tim_invis) {
848         creature_ptr->see_inv = TRUE;
849     }
850
851     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
852         o_ptr = &creature_ptr->inventory_list[i];
853         if (!o_ptr->k_idx)
854             continue;
855
856         object_flags(creature_ptr, o_ptr, flgs);
857         if (have_flag(flgs, TR_SEE_INVIS))
858             creature_ptr->see_inv = TRUE;
859     }
860 }
861
862 void have_free_act(player_type *creature_ptr)
863 {
864     object_type *o_ptr;
865     BIT_FLAGS flgs[TR_FLAG_SIZE];
866     creature_ptr->free_act = FALSE;
867
868     if (creature_ptr->muta3 & MUT3_MOTION)
869         creature_ptr->free_act = TRUE;
870
871     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_GNOME) {
872         creature_ptr->free_act = TRUE;
873     }
874
875     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_GOLEM) {
876         creature_ptr->free_act = TRUE;
877     }
878
879     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_SPECTRE) {
880         creature_ptr->free_act = TRUE;
881     }
882
883     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_ANDROID) {
884         creature_ptr->free_act = TRUE;
885     }
886
887     if (heavy_armor(creature_ptr) && (!creature_ptr->inventory_list[INVEN_RARM].k_idx || have_right_hand_weapon(creature_ptr))
888         && (!creature_ptr->inventory_list[INVEN_LARM].k_idx || have_left_hand_weapon(creature_ptr))) {
889         if (creature_ptr->lev > 24)
890             creature_ptr->free_act = TRUE;
891     }
892
893     if (creature_ptr->pclass == CLASS_MONK || creature_ptr->pclass == CLASS_FORCETRAINER) {
894         if (!(heavy_armor(creature_ptr))) {
895             if (creature_ptr->lev > 24)
896                 creature_ptr->free_act = TRUE;
897         }
898     }
899
900     if (creature_ptr->pclass == CLASS_BERSERKER) {
901         creature_ptr->free_act = TRUE;
902     }
903
904     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
905         creature_ptr->free_act = TRUE;
906     }
907
908     if (creature_ptr->magicdef) {
909         creature_ptr->free_act = TRUE;
910     }
911
912     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
913         o_ptr = &creature_ptr->inventory_list[i];
914         if (!o_ptr->k_idx)
915             continue;
916
917         object_flags(creature_ptr, o_ptr, flgs);
918         if (have_flag(flgs, TR_FREE_ACT))
919             creature_ptr->free_act = TRUE;
920     }
921 }
922
923 void have_sustain_str(player_type *creature_ptr)
924 {
925     object_type *o_ptr;
926     BIT_FLAGS flgs[TR_FLAG_SIZE];
927     creature_ptr->sustain_str = FALSE;
928     if (creature_ptr->pclass == CLASS_BERSERKER) {
929         creature_ptr->sustain_str = TRUE;
930     }
931     if (!creature_ptr->mimic_form
932         && (creature_ptr->prace == RACE_HALF_TROLL || creature_ptr->prace == RACE_HALF_OGRE || creature_ptr->prace == RACE_HALF_GIANT)) {
933         creature_ptr->sustain_str = TRUE;
934     }
935     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
936         creature_ptr->sustain_str = TRUE;
937     }
938
939     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
940         o_ptr = &creature_ptr->inventory_list[i];
941         if (!o_ptr->k_idx)
942             continue;
943
944         object_flags(creature_ptr, o_ptr, flgs);
945         if (have_flag(flgs, TR_SUST_STR))
946             creature_ptr->sustain_str = TRUE;
947     }
948 }
949
950 void have_sustain_int(player_type *creature_ptr)
951 {
952     object_type *o_ptr;
953     BIT_FLAGS flgs[TR_FLAG_SIZE];
954     creature_ptr->sustain_int = FALSE;
955     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_MIND_FLAYER)) {
956         creature_ptr->sustain_int = TRUE;
957     }
958
959     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
960         creature_ptr->sustain_int = TRUE;
961     }
962
963     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
964         o_ptr = &creature_ptr->inventory_list[i];
965         if (!o_ptr->k_idx)
966             continue;
967
968         object_flags(creature_ptr, o_ptr, flgs);
969         if (have_flag(flgs, TR_SUST_INT))
970             creature_ptr->sustain_int = TRUE;
971     }
972 }
973
974 void have_sustain_wis(player_type *creature_ptr)
975 {
976     object_type *o_ptr;
977     BIT_FLAGS flgs[TR_FLAG_SIZE];
978     creature_ptr->sustain_wis = FALSE;
979     if (creature_ptr->pclass == CLASS_MINDCRAFTER && creature_ptr->lev > 19)
980         creature_ptr->sustain_wis = TRUE;
981
982     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_MIND_FLAYER)) {
983         creature_ptr->sustain_wis = TRUE;
984     }
985
986     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
987         creature_ptr->sustain_wis = TRUE;
988     }
989
990     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
991         o_ptr = &creature_ptr->inventory_list[i];
992         if (!o_ptr->k_idx)
993             continue;
994
995         object_flags(creature_ptr, o_ptr, flgs);
996         if (have_flag(flgs, TR_SUST_WIS))
997             creature_ptr->sustain_wis = TRUE;
998     }
999 }
1000
1001 void have_sustain_dex(player_type *creature_ptr)
1002 {
1003     object_type *o_ptr;
1004     BIT_FLAGS flgs[TR_FLAG_SIZE];
1005     creature_ptr->sustain_dex = FALSE;
1006     if (creature_ptr->pclass == CLASS_BERSERKER) {
1007         creature_ptr->sustain_dex = TRUE;
1008     }
1009
1010     if (creature_ptr->pclass == CLASS_NINJA && creature_ptr->lev > 24)
1011         creature_ptr->sustain_dex = TRUE;
1012
1013     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1014         creature_ptr->sustain_dex = TRUE;
1015     }
1016
1017     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1018         o_ptr = &creature_ptr->inventory_list[i];
1019         if (!o_ptr->k_idx)
1020             continue;
1021
1022         object_flags(creature_ptr, o_ptr, flgs);
1023         if (have_flag(flgs, TR_SUST_DEX))
1024             creature_ptr->sustain_dex = TRUE;
1025     }
1026 }
1027
1028 void have_sustain_con(player_type *creature_ptr)
1029 {
1030     object_type *o_ptr;
1031     BIT_FLAGS flgs[TR_FLAG_SIZE];
1032     creature_ptr->sustain_con = FALSE;
1033     if (creature_ptr->pclass == CLASS_BERSERKER) {
1034         creature_ptr->sustain_con = TRUE;
1035     }
1036
1037     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_AMBERITE || creature_ptr->prace == RACE_DUNADAN)) {
1038         creature_ptr->sustain_con = TRUE;
1039     }
1040
1041     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1042         creature_ptr->sustain_con = TRUE;
1043     }
1044
1045     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1046         o_ptr = &creature_ptr->inventory_list[i];
1047         if (!o_ptr->k_idx)
1048             continue;
1049
1050         object_flags(creature_ptr, o_ptr, flgs);
1051         if (have_flag(flgs, TR_SUST_CON))
1052             creature_ptr->sustain_con = TRUE;
1053     }
1054 }
1055
1056 void have_sustain_chr(player_type *creature_ptr)
1057 {
1058     object_type *o_ptr;
1059     BIT_FLAGS flgs[TR_FLAG_SIZE];
1060     creature_ptr->sustain_chr = FALSE;
1061
1062     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1063         creature_ptr->sustain_chr = TRUE;
1064     }
1065
1066     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1067         o_ptr = &creature_ptr->inventory_list[i];
1068         if (!o_ptr->k_idx)
1069             continue;
1070
1071         object_flags(creature_ptr, o_ptr, flgs);
1072         if (have_flag(flgs, TR_SUST_CHR))
1073             creature_ptr->sustain_chr = TRUE;
1074     }
1075 }
1076
1077 void have_levitation(player_type *creature_ptr)
1078 {
1079     object_type *o_ptr;
1080     BIT_FLAGS flgs[TR_FLAG_SIZE];
1081     creature_ptr->levitation = FALSE;
1082
1083     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1084         creature_ptr->levitation = TRUE;
1085     }
1086
1087     if (creature_ptr->muta3 & MUT3_WINGS)
1088         creature_ptr->levitation = TRUE;
1089
1090     if (!creature_ptr->mimic_form
1091         && (creature_ptr->prace == RACE_DRACONIAN || creature_ptr->prace == RACE_SPECTRE || creature_ptr->prace == RACE_SPRITE
1092             || creature_ptr->prace == RACE_ARCHON || creature_ptr->prace == RACE_S_FAIRY)) {
1093         creature_ptr->levitation = TRUE;
1094     }
1095
1096     if (creature_ptr->special_defense & KAMAE_SEIRYU || creature_ptr->special_defense & KAMAE_SUZAKU) {
1097         creature_ptr->levitation = TRUE;
1098     }
1099
1100     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1101         creature_ptr->levitation = TRUE;
1102     }
1103
1104     if (creature_ptr->magicdef) {
1105     }
1106
1107     if (creature_ptr->riding) {
1108         monster_type *riding_m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1109         monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
1110         creature_ptr->levitation = (riding_r_ptr->flags7 & RF7_CAN_FLY) ? TRUE : FALSE;
1111     }
1112
1113     if (creature_ptr->tim_levitation) {
1114         creature_ptr->levitation = TRUE;
1115     }
1116
1117     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1118         o_ptr = &creature_ptr->inventory_list[i];
1119         if (!o_ptr->k_idx)
1120             continue;
1121         object_flags(creature_ptr, o_ptr, flgs);
1122         if (have_flag(flgs, TR_LEVITATION))
1123             creature_ptr->levitation = TRUE;
1124     }
1125 }
1126
1127 void have_can_swim(player_type *creature_ptr)
1128 {
1129     creature_ptr->can_swim = FALSE;
1130     if (creature_ptr->riding) {
1131         monster_type *riding_m_ptr = &creature_ptr->current_floor_ptr->m_list[creature_ptr->riding];
1132         monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
1133         if (riding_r_ptr->flags7 & (RF7_CAN_SWIM | RF7_AQUATIC))
1134             creature_ptr->can_swim = TRUE;
1135     }
1136 }
1137
1138 void have_slow_digest(player_type *creature_ptr)
1139 {
1140     object_type *o_ptr;
1141     BIT_FLAGS flgs[TR_FLAG_SIZE];
1142     creature_ptr->slow_digest = FALSE;
1143
1144     if (creature_ptr->pclass == CLASS_NINJA) {
1145         creature_ptr->slow_digest = TRUE;
1146     }
1147
1148     if (creature_ptr->lev > 14 && !creature_ptr->mimic_form && creature_ptr->prace == RACE_HALF_TROLL) {
1149         if (creature_ptr->pclass == CLASS_WARRIOR || creature_ptr->pclass == CLASS_BERSERKER) {
1150             creature_ptr->slow_digest = TRUE;
1151             /* Let's not make Regeneration
1152              * a disadvantage for the poor warriors who can
1153              * never learn a spell that satisfies hunger (actually
1154              * neither can rogues, but half-trolls are not
1155              * supposed to play rogues) */
1156         }
1157     }
1158
1159     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1160         creature_ptr->slow_digest = TRUE;
1161     }
1162
1163     if (!creature_ptr->mimic_form
1164         && (creature_ptr->prace == RACE_GOLEM || creature_ptr->prace == RACE_ZOMBIE || creature_ptr->prace == RACE_SPECTRE
1165             || creature_ptr->prace == RACE_ANDROID)) {
1166         creature_ptr->slow_digest = TRUE;
1167     }
1168
1169     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1170         o_ptr = &creature_ptr->inventory_list[i];
1171         if (!o_ptr->k_idx)
1172             continue;
1173         object_flags(creature_ptr, o_ptr, flgs);
1174         if (have_flag(flgs, TR_SLOW_DIGEST))
1175             creature_ptr->slow_digest = TRUE;
1176     }
1177 }
1178
1179 void have_regenerate(player_type *creature_ptr)
1180 {
1181     object_type *o_ptr;
1182     BIT_FLAGS flgs[TR_FLAG_SIZE];
1183     creature_ptr->regenerate = FALSE;
1184
1185     if (!creature_ptr->mimic_form) {
1186         switch (creature_ptr->prace) {
1187         case RACE_HALF_TROLL:
1188             if (creature_ptr->lev > 14) {
1189                 creature_ptr->regenerate = TRUE;
1190             }
1191             break;
1192         case RACE_AMBERITE:
1193             creature_ptr->regenerate = TRUE;
1194             break;
1195         }
1196     }
1197
1198     switch (creature_ptr->pclass) {
1199     case CLASS_WARRIOR:
1200         if (creature_ptr->lev > 44)
1201             creature_ptr->regenerate = TRUE;
1202         break;
1203     case CLASS_BERSERKER:
1204         creature_ptr->regenerate = TRUE;
1205         break;
1206     }
1207
1208     if (creature_ptr->muta3 & MUT3_FLESH_ROT)
1209         creature_ptr->regenerate = FALSE;
1210
1211     if (creature_ptr->muta3 & MUT3_REGEN)
1212         creature_ptr->regenerate = TRUE;
1213
1214     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1215         creature_ptr->regenerate = TRUE;
1216     }
1217
1218     if (creature_ptr->realm1 == REALM_HEX) {
1219         if (hex_spelling(creature_ptr, HEX_DEMON_AURA)) {
1220             creature_ptr->regenerate = TRUE;
1221         }
1222     }
1223
1224     if (creature_ptr->tim_regen) {
1225         creature_ptr->regenerate = TRUE;
1226     }
1227
1228     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1229         o_ptr = &creature_ptr->inventory_list[i];
1230         if (!o_ptr->k_idx)
1231             continue;
1232         object_flags(creature_ptr, o_ptr, flgs);
1233         if (have_flag(flgs, TR_REGEN))
1234             creature_ptr->regenerate = TRUE;
1235     }
1236 }
1237
1238 void have_curses(player_type *creature_ptr)
1239 {
1240     object_type *o_ptr;
1241     BIT_FLAGS flgs[TR_FLAG_SIZE];
1242     creature_ptr->cursed = 0L;
1243
1244     if (creature_ptr->pseikaku == PERSONALITY_SEXY)
1245         creature_ptr->cursed |= (TRC_AGGRAVATE);
1246
1247     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1248         o_ptr = &creature_ptr->inventory_list[i];
1249         if (!o_ptr->k_idx)
1250             continue;
1251         object_flags(creature_ptr, o_ptr, flgs);
1252         if (have_flag(flgs, TR_AGGRAVATE))
1253             creature_ptr->cursed |= TRC_AGGRAVATE;
1254         if (have_flag(flgs, TR_DRAIN_EXP))
1255             creature_ptr->cursed |= TRC_DRAIN_EXP;
1256         if (have_flag(flgs, TR_TY_CURSE))
1257             creature_ptr->cursed |= TRC_TY_CURSE;
1258         if (have_flag(flgs, TR_ADD_L_CURSE))
1259             creature_ptr->cursed |= TRC_ADD_L_CURSE;
1260         if (have_flag(flgs, TR_ADD_H_CURSE))
1261             creature_ptr->cursed |= TRC_ADD_H_CURSE;
1262         if (have_flag(flgs, TR_DRAIN_HP))
1263             creature_ptr->cursed |= TRC_DRAIN_HP;
1264         if (have_flag(flgs, TR_DRAIN_MANA))
1265             creature_ptr->cursed |= TRC_DRAIN_MANA;
1266         if (have_flag(flgs, TR_CALL_ANIMAL))
1267             creature_ptr->cursed |= TRC_CALL_ANIMAL;
1268         if (have_flag(flgs, TR_CALL_DEMON))
1269             creature_ptr->cursed |= TRC_CALL_DEMON;
1270         if (have_flag(flgs, TR_CALL_DRAGON))
1271             creature_ptr->cursed |= TRC_CALL_DRAGON;
1272         if (have_flag(flgs, TR_CALL_UNDEAD))
1273             creature_ptr->cursed |= TRC_CALL_UNDEAD;
1274         if (have_flag(flgs, TR_COWARDICE))
1275             creature_ptr->cursed |= TRC_COWARDICE;
1276         if (have_flag(flgs, TR_LOW_MELEE))
1277             creature_ptr->cursed |= TRC_LOW_MELEE;
1278         if (have_flag(flgs, TR_LOW_AC))
1279             creature_ptr->cursed |= TRC_LOW_AC;
1280         if (have_flag(flgs, TR_LOW_MAGIC))
1281             creature_ptr->cursed |= TRC_LOW_MAGIC;
1282         if (have_flag(flgs, TR_FAST_DIGEST))
1283             creature_ptr->cursed |= TRC_FAST_DIGEST;
1284         if (have_flag(flgs, TR_SLOW_REGEN))
1285             creature_ptr->cursed |= TRC_SLOW_REGEN;
1286
1287         creature_ptr->cursed |= (o_ptr->curse_flags & (0xFFFFFFF0L));
1288         if (o_ptr->name1 == ART_CHAINSWORD)
1289             creature_ptr->cursed |= TRC_CHAINSWORD;
1290
1291         if (have_flag(flgs, TR_TELEPORT)) {
1292             if (object_is_cursed(o_ptr))
1293                 creature_ptr->cursed |= TRC_TELEPORT;
1294             else {
1295                 concptr insc = quark_str(o_ptr->inscription);
1296
1297                 /* {.} will stop random teleportation. */
1298                 if (o_ptr->inscription && angband_strchr(insc, '.')) {
1299                 } else {
1300                     creature_ptr->cursed |= TRC_TELEPORT_SELF;
1301                 }
1302             }
1303         }
1304     }
1305
1306     if (creature_ptr->cursed & TRC_TELEPORT)
1307         creature_ptr->cursed &= ~(TRC_TELEPORT_SELF);
1308
1309     if ((is_specific_player_race(creature_ptr, RACE_S_FAIRY)) && (creature_ptr->pseikaku != PERSONALITY_SEXY) && (creature_ptr->cursed & TRC_AGGRAVATE)) {
1310         creature_ptr->cursed &= ~(TRC_AGGRAVATE);
1311     }
1312 }
1313
1314 void have_impact(player_type *creature_ptr)
1315 {
1316     object_type *o_ptr;
1317     BIT_FLAGS flgs[TR_FLAG_SIZE];
1318     creature_ptr->impact[0] = FALSE;
1319     creature_ptr->impact[1] = FALSE;
1320
1321     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1322         o_ptr = &creature_ptr->inventory_list[i];
1323         if (!o_ptr->k_idx)
1324             continue;
1325         object_flags(creature_ptr, o_ptr, flgs);
1326         if (have_flag(flgs, TR_IMPACT))
1327             creature_ptr->impact[(i == INVEN_RARM) ? 0 : 1] = TRUE;
1328     }
1329 }
1330
1331 void have_extra_blow(player_type *creature_ptr)
1332 {
1333     object_type *o_ptr;
1334     BIT_FLAGS flgs[TR_FLAG_SIZE];
1335     creature_ptr->extra_blows[0] = creature_ptr->extra_blows[1] = 0;
1336
1337     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1338         o_ptr = &creature_ptr->inventory_list[i];
1339         if (!o_ptr->k_idx)
1340             continue;
1341
1342         object_flags(creature_ptr, o_ptr, flgs);
1343
1344         if (have_flag(flgs, TR_INFRA))
1345             creature_ptr->see_infra += o_ptr->pval;
1346         if (have_flag(flgs, TR_BLOWS)) {
1347             if ((i == INVEN_RARM || i == INVEN_RIGHT) && !have_two_handed_weapons(creature_ptr))
1348                 creature_ptr->extra_blows[0] += o_ptr->pval;
1349             else if ((i == INVEN_LARM || i == INVEN_LEFT) && !have_two_handed_weapons(creature_ptr))
1350                 creature_ptr->extra_blows[1] += o_ptr->pval;
1351             else {
1352                 creature_ptr->extra_blows[0] += o_ptr->pval;
1353                 creature_ptr->extra_blows[1] += o_ptr->pval;
1354             }
1355         }
1356     }
1357 }
1358
1359 void have_resist_acid(player_type *creature_ptr)
1360 {
1361     object_type *o_ptr;
1362     BIT_FLAGS flgs[TR_FLAG_SIZE];
1363     creature_ptr->resist_acid = FALSE;
1364
1365     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1366         creature_ptr->resist_acid = TRUE;
1367     }
1368
1369     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_YEEK || creature_ptr->prace == RACE_KLACKON)) {
1370         creature_ptr->resist_acid = TRUE;
1371     }
1372
1373     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DRACONIAN && creature_ptr->lev > 14) {
1374         creature_ptr->resist_acid = TRUE;
1375     }
1376
1377     if (creature_ptr->special_defense & KAMAE_SEIRYU) {
1378         creature_ptr->resist_acid = TRUE;
1379     }
1380
1381     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1382         creature_ptr->resist_acid = TRUE;
1383     }
1384
1385     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1386         o_ptr = &creature_ptr->inventory_list[i];
1387         if (!o_ptr->k_idx)
1388             continue;
1389
1390         object_flags(creature_ptr, o_ptr, flgs);
1391         if (have_flag(flgs, TR_RES_ACID))
1392             creature_ptr->resist_acid = TRUE;
1393     }
1394
1395     if (creature_ptr->immune_acid)
1396         creature_ptr->resist_acid = TRUE;
1397 }
1398
1399 void have_resist_elec(player_type *creature_ptr)
1400 {
1401     object_type *o_ptr;
1402     BIT_FLAGS flgs[TR_FLAG_SIZE];
1403     creature_ptr->resist_elec = FALSE;
1404
1405     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1406         creature_ptr->resist_elec = TRUE;
1407     }
1408
1409     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DRACONIAN && creature_ptr->lev > 19) {
1410         creature_ptr->resist_elec = TRUE;
1411     }
1412
1413     if (creature_ptr->special_defense & KAMAE_SEIRYU) {
1414         creature_ptr->resist_elec = TRUE;
1415     }
1416
1417     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1418         creature_ptr->resist_elec = TRUE;
1419     }
1420
1421     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1422         o_ptr = &creature_ptr->inventory_list[i];
1423         if (!o_ptr->k_idx)
1424             continue;
1425
1426         object_flags(creature_ptr, o_ptr, flgs);
1427         if (have_flag(flgs, TR_RES_ELEC))
1428             creature_ptr->resist_elec = TRUE;
1429     }
1430
1431     if (creature_ptr->immune_elec)
1432         creature_ptr->resist_elec = TRUE;
1433 }
1434
1435 void have_resist_fire(player_type *creature_ptr)
1436 {
1437     object_type *o_ptr;
1438     BIT_FLAGS flgs[TR_FLAG_SIZE];
1439     creature_ptr->resist_fire = FALSE;
1440
1441     if (creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1442         creature_ptr->resist_fire = TRUE;
1443     }
1444
1445     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DRACONIAN && creature_ptr->lev > 4) {
1446         creature_ptr->resist_fire = TRUE;
1447     }
1448
1449     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_IMP || creature_ptr->prace == RACE_BALROG)) {
1450         creature_ptr->resist_fire = TRUE;
1451     }
1452
1453     if (creature_ptr->special_defense & KAMAE_SEIRYU) {
1454         creature_ptr->resist_fire = TRUE;
1455     }
1456
1457     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1458         creature_ptr->resist_fire = TRUE;
1459     }
1460
1461     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1462         o_ptr = &creature_ptr->inventory_list[i];
1463         if (!o_ptr->k_idx)
1464             continue;
1465
1466         object_flags(creature_ptr, o_ptr, flgs);
1467
1468         if (have_flag(flgs, TR_RES_FIRE))
1469             creature_ptr->resist_fire = TRUE;
1470     }
1471
1472     if (creature_ptr->immune_fire)
1473         creature_ptr->resist_fire = TRUE;
1474 }
1475
1476 void have_resist_cold(player_type *creature_ptr)
1477 {
1478     object_type *o_ptr;
1479     BIT_FLAGS flgs[TR_FLAG_SIZE];
1480     creature_ptr->resist_cold = FALSE;
1481
1482     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD || creature_ptr->mimic_form == MIMIC_VAMPIRE) {
1483         creature_ptr->resist_cold = TRUE;
1484     }
1485
1486     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_ZOMBIE) && creature_ptr->lev > 4) {
1487         creature_ptr->resist_cold = TRUE;
1488     }
1489
1490     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_DRACONIAN || creature_ptr->prace == RACE_SKELETON) && creature_ptr->lev > 9) {
1491         creature_ptr->resist_cold = TRUE;
1492     }
1493
1494     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_VAMPIRE || creature_ptr->prace == RACE_SPECTRE)) {
1495         creature_ptr->resist_fire = TRUE;
1496     }
1497
1498     if (creature_ptr->special_defense & KAMAE_SEIRYU) {
1499         creature_ptr->resist_cold = TRUE;
1500     }
1501
1502     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1503         creature_ptr->resist_cold = TRUE;
1504     }
1505
1506     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1507         o_ptr = &creature_ptr->inventory_list[i];
1508         if (!o_ptr->k_idx)
1509             continue;
1510
1511         object_flags(creature_ptr, o_ptr, flgs);
1512
1513         if (have_flag(flgs, TR_RES_COLD))
1514             creature_ptr->resist_cold = TRUE;
1515     }
1516
1517     if (creature_ptr->immune_cold)
1518         creature_ptr->resist_cold = TRUE;
1519 }
1520
1521 void have_resist_pois(player_type *creature_ptr)
1522 {
1523     object_type *o_ptr;
1524     BIT_FLAGS flgs[TR_FLAG_SIZE];
1525     creature_ptr->resist_pois = FALSE;
1526
1527     if (creature_ptr->pclass == CLASS_NINJA && creature_ptr->lev > 19)
1528         creature_ptr->resist_pois = TRUE;
1529
1530     if (creature_ptr->mimic_form == MIMIC_VAMPIRE || creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1531         creature_ptr->resist_pois = TRUE;
1532     }
1533
1534     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DRACONIAN && creature_ptr->lev > 34) {
1535         creature_ptr->resist_pois = TRUE;
1536     }
1537
1538     if (!creature_ptr->mimic_form
1539         && (creature_ptr->prace == RACE_KOBOLD || creature_ptr->prace == RACE_GOLEM || creature_ptr->prace == RACE_SKELETON
1540             || creature_ptr->prace == RACE_VAMPIRE || creature_ptr->prace == RACE_SPECTRE || creature_ptr->prace == RACE_ANDROID)) {
1541         creature_ptr->resist_pois = TRUE;
1542     }
1543
1544     if (creature_ptr->special_defense & KAMAE_SEIRYU) {
1545         creature_ptr->resist_pois = TRUE;
1546     }
1547
1548     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1549         creature_ptr->resist_pois = TRUE;
1550     }
1551
1552     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1553         o_ptr = &creature_ptr->inventory_list[i];
1554         if (!o_ptr->k_idx)
1555             continue;
1556
1557         object_flags(creature_ptr, o_ptr, flgs);
1558
1559         if (have_flag(flgs, TR_RES_POIS))
1560             creature_ptr->resist_pois = TRUE;
1561     }
1562 }
1563
1564 void have_resist_conf(player_type *creature_ptr)
1565 {
1566     object_type *o_ptr;
1567     BIT_FLAGS flgs[TR_FLAG_SIZE];
1568     creature_ptr->resist_conf = FALSE;
1569
1570     if (creature_ptr->pclass == CLASS_MINDCRAFTER && creature_ptr->lev > 29)
1571         creature_ptr->resist_conf = TRUE;
1572
1573     if (creature_ptr->pseikaku == PERSONALITY_CHARGEMAN || creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
1574         creature_ptr->resist_conf = TRUE;
1575     }
1576
1577     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_KLACKON || creature_ptr->prace == RACE_BEASTMAN || creature_ptr->prace == RACE_KUTAR)) {
1578         creature_ptr->resist_conf = TRUE;
1579     }
1580
1581     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1582         creature_ptr->resist_conf = TRUE;
1583     }
1584
1585     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1586         creature_ptr->resist_conf = TRUE;
1587     }
1588
1589     if (creature_ptr->magicdef) {
1590         creature_ptr->resist_conf = TRUE;
1591     }
1592
1593     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1594         o_ptr = &creature_ptr->inventory_list[i];
1595         if (!o_ptr->k_idx)
1596             continue;
1597
1598         object_flags(creature_ptr, o_ptr, flgs);
1599
1600         if (have_flag(flgs, TR_RES_CONF))
1601             creature_ptr->resist_conf = TRUE;
1602     }
1603 }
1604
1605 void have_resist_sound(player_type *creature_ptr)
1606 {
1607     object_type *o_ptr;
1608     BIT_FLAGS flgs[TR_FLAG_SIZE];
1609     creature_ptr->resist_sound = FALSE;
1610
1611     if (creature_ptr->pclass == CLASS_BARD) {
1612         creature_ptr->resist_sound = TRUE;
1613     }
1614
1615     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_CYCLOPS || creature_ptr->prace == RACE_BEASTMAN)) {
1616         creature_ptr->resist_sound = TRUE;
1617     }
1618
1619     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1620         creature_ptr->resist_sound = TRUE;
1621     }
1622
1623     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1624         o_ptr = &creature_ptr->inventory_list[i];
1625         if (!o_ptr->k_idx)
1626             continue;
1627
1628         object_flags(creature_ptr, o_ptr, flgs);
1629
1630         if (have_flag(flgs, TR_RES_SOUND))
1631             creature_ptr->resist_sound = TRUE;
1632     }
1633 }
1634
1635 void have_resist_lite(player_type *creature_ptr)
1636 {
1637     object_type *o_ptr;
1638     BIT_FLAGS flgs[TR_FLAG_SIZE];
1639     creature_ptr->resist_lite = FALSE;
1640
1641     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_ELF || creature_ptr->prace == RACE_HIGH_ELF || creature_ptr->prace == RACE_SPRITE)) {
1642         creature_ptr->resist_lite = TRUE;
1643     }
1644
1645     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1646         creature_ptr->resist_lite = TRUE;
1647     }
1648
1649     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1650         o_ptr = &creature_ptr->inventory_list[i];
1651         if (!o_ptr->k_idx)
1652             continue;
1653
1654         object_flags(creature_ptr, o_ptr, flgs);
1655
1656         if (have_flag(flgs, TR_RES_LITE))
1657             creature_ptr->resist_lite = TRUE;
1658     }
1659 }
1660
1661 void have_resist_dark(player_type *creature_ptr)
1662 {
1663     object_type *o_ptr;
1664     BIT_FLAGS flgs[TR_FLAG_SIZE];
1665     creature_ptr->resist_dark = FALSE;
1666
1667     if (creature_ptr->mimic_form == MIMIC_VAMPIRE) {
1668         creature_ptr->resist_dark = TRUE;
1669     }
1670
1671     if (!creature_ptr->mimic_form
1672         && (creature_ptr->prace == RACE_HALF_ORC || creature_ptr->prace == RACE_HALF_OGRE || creature_ptr->prace == RACE_NIBELUNG
1673             || creature_ptr->prace == RACE_DARK_ELF || creature_ptr->prace == RACE_VAMPIRE)) {
1674         creature_ptr->resist_lite = TRUE;
1675     }
1676
1677     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1678         creature_ptr->resist_dark = TRUE;
1679     }
1680
1681     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1682         o_ptr = &creature_ptr->inventory_list[i];
1683         if (!o_ptr->k_idx)
1684             continue;
1685
1686         object_flags(creature_ptr, o_ptr, flgs);
1687
1688         if (have_flag(flgs, TR_RES_DARK))
1689             creature_ptr->resist_dark = TRUE;
1690     }
1691 }
1692
1693 void have_resist_chaos(player_type *creature_ptr)
1694 {
1695     object_type *o_ptr;
1696     BIT_FLAGS flgs[TR_FLAG_SIZE];
1697     creature_ptr->resist_chaos = FALSE;
1698
1699     if (creature_ptr->pclass == CLASS_CHAOS_WARRIOR && creature_ptr->lev > 29)
1700         creature_ptr->resist_chaos = TRUE;
1701
1702     if (creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1703         creature_ptr->resist_chaos = TRUE;
1704     }
1705
1706     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_HALF_TITAN)
1707         creature_ptr->resist_chaos = TRUE;
1708
1709     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1710         creature_ptr->resist_chaos = TRUE;
1711     }
1712
1713     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1714         o_ptr = &creature_ptr->inventory_list[i];
1715         if (!o_ptr->k_idx)
1716             continue;
1717
1718         object_flags(creature_ptr, o_ptr, flgs);
1719
1720         if (have_flag(flgs, TR_RES_CHAOS))
1721             creature_ptr->resist_chaos = TRUE;
1722     }
1723 }
1724
1725 void have_resist_disen(player_type *creature_ptr)
1726 {
1727     object_type *o_ptr;
1728     BIT_FLAGS flgs[TR_FLAG_SIZE];
1729     creature_ptr->resist_disen = FALSE;
1730
1731     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1732         creature_ptr->resist_disen = TRUE;
1733     }
1734
1735     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_NIBELUNG)
1736         creature_ptr->resist_disen = TRUE;
1737
1738     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1739         creature_ptr->resist_disen = TRUE;
1740     }
1741
1742     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1743         o_ptr = &creature_ptr->inventory_list[i];
1744         if (!o_ptr->k_idx)
1745             continue;
1746
1747         object_flags(creature_ptr, o_ptr, flgs);
1748
1749         if (have_flag(flgs, TR_RES_DISEN))
1750             creature_ptr->resist_disen = TRUE;
1751     }
1752 }
1753
1754 void have_resist_shard(player_type *creature_ptr)
1755 {
1756     object_type *o_ptr;
1757     BIT_FLAGS flgs[TR_FLAG_SIZE];
1758     creature_ptr->resist_shard = FALSE;
1759
1760     if (!creature_ptr->mimic_form && (creature_ptr->prace == RACE_HALF_TITAN || creature_ptr->prace == RACE_SKELETON))
1761         creature_ptr->resist_shard = TRUE;
1762
1763     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1764         creature_ptr->resist_shard = TRUE;
1765     }
1766
1767     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1768         o_ptr = &creature_ptr->inventory_list[i];
1769         if (!o_ptr->k_idx)
1770             continue;
1771
1772         object_flags(creature_ptr, o_ptr, flgs);
1773
1774         if (have_flag(flgs, TR_RES_DISEN))
1775             creature_ptr->resist_shard = TRUE;
1776     }
1777 }
1778
1779 void have_resist_nexus(player_type *creature_ptr)
1780 {
1781     object_type *o_ptr;
1782     BIT_FLAGS flgs[TR_FLAG_SIZE];
1783     creature_ptr->resist_nexus = FALSE;
1784
1785     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1786         creature_ptr->resist_nexus = TRUE;
1787     }
1788
1789     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1790         creature_ptr->resist_nexus = TRUE;
1791     }
1792
1793     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1794         o_ptr = &creature_ptr->inventory_list[i];
1795         if (!o_ptr->k_idx)
1796             continue;
1797
1798         object_flags(creature_ptr, o_ptr, flgs);
1799
1800         if (have_flag(flgs, TR_RES_NEXUS))
1801             creature_ptr->resist_nexus = TRUE;
1802     }
1803 }
1804
1805 void have_resist_blind(player_type *creature_ptr)
1806 {
1807     object_type *o_ptr;
1808     BIT_FLAGS flgs[TR_FLAG_SIZE];
1809     creature_ptr->resist_blind = FALSE;
1810
1811     if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
1812         creature_ptr->resist_blind = TRUE;
1813     }
1814
1815     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_DWARF)
1816         creature_ptr->resist_blind = TRUE;
1817
1818     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1819         creature_ptr->resist_blind = TRUE;
1820     }
1821
1822     if (creature_ptr->magicdef) {
1823         creature_ptr->resist_blind = TRUE;
1824     }
1825
1826     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1827         o_ptr = &creature_ptr->inventory_list[i];
1828         if (!o_ptr->k_idx)
1829             continue;
1830
1831         object_flags(creature_ptr, o_ptr, flgs);
1832
1833         if (have_flag(flgs, TR_RES_BLIND))
1834             creature_ptr->resist_blind = TRUE;
1835     }
1836 }
1837
1838 void have_resist_neth(player_type *creature_ptr)
1839 {
1840     object_type *o_ptr;
1841     BIT_FLAGS flgs[TR_FLAG_SIZE];
1842
1843     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD || creature_ptr->mimic_form == MIMIC_DEMON || creature_ptr->mimic_form == MIMIC_VAMPIRE) {
1844         creature_ptr->resist_neth = TRUE;
1845     }
1846
1847     if (!creature_ptr->mimic_form
1848         && (creature_ptr->prace == RACE_ZOMBIE || creature_ptr->prace == RACE_VAMPIRE || creature_ptr->prace == RACE_SPECTRE
1849             || creature_ptr->prace == RACE_BALROG))
1850         creature_ptr->resist_neth = TRUE;
1851
1852     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1853         creature_ptr->resist_neth = TRUE;
1854     }
1855
1856     if (creature_ptr->tim_res_nether) {
1857         creature_ptr->resist_neth = TRUE;
1858     }
1859
1860     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1861         o_ptr = &creature_ptr->inventory_list[i];
1862         if (!o_ptr->k_idx)
1863             continue;
1864
1865         object_flags(creature_ptr, o_ptr, flgs);
1866
1867         if (have_flag(flgs, TR_RES_NETHER))
1868             creature_ptr->resist_neth = TRUE;
1869     }
1870 }
1871
1872 void have_resist_time(player_type *creature_ptr)
1873 {
1874     object_type *o_ptr;
1875     BIT_FLAGS flgs[TR_FLAG_SIZE];
1876     creature_ptr->resist_time = FALSE;
1877
1878     if (creature_ptr->tim_res_time) {
1879         creature_ptr->resist_time = TRUE;
1880     }
1881
1882     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1883         o_ptr = &creature_ptr->inventory_list[i];
1884         if (!o_ptr->k_idx)
1885             continue;
1886
1887         object_flags(creature_ptr, o_ptr, flgs);
1888         if (o_ptr->name2 == EGO_RING_RES_TIME)
1889             creature_ptr->resist_time = TRUE;
1890     }
1891 }
1892
1893 void have_resist_water(player_type *creature_ptr)
1894 {
1895     creature_ptr->resist_water = FALSE;
1896
1897     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_MERFOLK)
1898         creature_ptr->resist_water = TRUE;
1899 }
1900
1901 void have_resist_fear(player_type *creature_ptr)
1902 {
1903     object_type *o_ptr;
1904     BIT_FLAGS flgs[TR_FLAG_SIZE];
1905     creature_ptr->resist_fear = FALSE;
1906
1907     if (creature_ptr->muta3 & MUT3_FEARLESS)
1908         creature_ptr->resist_fear = TRUE;
1909
1910     switch (creature_ptr->pclass) {
1911     case CLASS_WARRIOR:
1912         if (creature_ptr->lev > 29)
1913             creature_ptr->resist_fear = TRUE;
1914         break;
1915     case CLASS_PALADIN:
1916         if (creature_ptr->lev > 39)
1917             creature_ptr->resist_fear = TRUE;
1918         break;
1919     case CLASS_CHAOS_WARRIOR:
1920         if (creature_ptr->lev > 39)
1921             creature_ptr->resist_fear = TRUE;
1922         break;
1923     case CLASS_MINDCRAFTER:
1924         if (creature_ptr->lev > 9)
1925             creature_ptr->resist_fear = TRUE;
1926         break;
1927     case CLASS_SAMURAI:
1928         if (creature_ptr->lev > 29)
1929             creature_ptr->resist_fear = TRUE;
1930         break;
1931     case CLASS_NINJA:
1932         creature_ptr->resist_fear = TRUE;
1933         break;
1934     }
1935
1936     if (creature_ptr->mimic_form == MIMIC_DEMON_LORD) {
1937         creature_ptr->resist_fear = TRUE;
1938     }
1939
1940     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_BARBARIAN)
1941         creature_ptr->resist_fear = TRUE;
1942
1943     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
1944         creature_ptr->resist_fear = TRUE;
1945     }
1946
1947     if (is_hero(creature_ptr) || creature_ptr->shero) {
1948         creature_ptr->resist_fear = TRUE;
1949     }
1950
1951     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1952         o_ptr = &creature_ptr->inventory_list[i];
1953         if (!o_ptr->k_idx)
1954             continue;
1955
1956         object_flags(creature_ptr, o_ptr, flgs);
1957         if (have_flag(flgs, TR_RES_FEAR))
1958             creature_ptr->resist_fear = TRUE;
1959     }
1960 }
1961
1962 void have_immune_acid(player_type *creature_ptr)
1963 {
1964     object_type *o_ptr;
1965     BIT_FLAGS flgs[TR_FLAG_SIZE];
1966     creature_ptr->immune_acid = FALSE;
1967
1968     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_YEEK && creature_ptr->lev > 19)
1969         creature_ptr->immune_acid = TRUE;
1970
1971     if (creature_ptr->ele_immune) {
1972         if (creature_ptr->special_defense & DEFENSE_ACID)
1973             creature_ptr->immune_acid = TRUE;
1974     }
1975
1976     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1977         o_ptr = &creature_ptr->inventory_list[i];
1978         if (!o_ptr->k_idx)
1979             continue;
1980
1981         object_flags(creature_ptr, o_ptr, flgs);
1982         if (have_flag(flgs, TR_IM_ACID))
1983             creature_ptr->immune_acid = TRUE;
1984     }
1985 }
1986
1987 void have_immune_elec(player_type *creature_ptr)
1988 {
1989     object_type *o_ptr;
1990     BIT_FLAGS flgs[TR_FLAG_SIZE];
1991     creature_ptr->immune_elec = FALSE;
1992     if (creature_ptr->ele_immune) {
1993         if (creature_ptr->special_defense & DEFENSE_ELEC)
1994             creature_ptr->immune_elec = TRUE;
1995     }
1996
1997     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
1998         o_ptr = &creature_ptr->inventory_list[i];
1999         if (!o_ptr->k_idx)
2000             continue;
2001
2002         object_flags(creature_ptr, o_ptr, flgs);
2003         if (have_flag(flgs, TR_IM_ELEC))
2004             creature_ptr->immune_elec = TRUE;
2005     }
2006 }
2007
2008 void have_immune_fire(player_type *creature_ptr)
2009 {
2010     object_type *o_ptr;
2011     BIT_FLAGS flgs[TR_FLAG_SIZE];
2012     creature_ptr->immune_fire = FALSE;
2013     if (creature_ptr->ele_immune) {
2014         if (creature_ptr->special_defense & DEFENSE_FIRE)
2015             creature_ptr->immune_fire = TRUE;
2016     }
2017
2018     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
2019         o_ptr = &creature_ptr->inventory_list[i];
2020         if (!o_ptr->k_idx)
2021             continue;
2022
2023         object_flags(creature_ptr, o_ptr, flgs);
2024         if (have_flag(flgs, TR_IM_FIRE))
2025             creature_ptr->immune_fire = TRUE;
2026     }
2027 }
2028
2029 void have_immune_cold(player_type *creature_ptr)
2030 {
2031     object_type *o_ptr;
2032     BIT_FLAGS flgs[TR_FLAG_SIZE];
2033     creature_ptr->immune_cold = FALSE;
2034     if (creature_ptr->ele_immune) {
2035         if (creature_ptr->special_defense & DEFENSE_COLD)
2036             creature_ptr->immune_cold = TRUE;
2037     }
2038
2039     for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++) {
2040         o_ptr = &creature_ptr->inventory_list[i];
2041         if (!o_ptr->k_idx)
2042             continue;
2043
2044         object_flags(creature_ptr, o_ptr, flgs);
2045         if (have_flag(flgs, TR_IM_COLD))
2046             creature_ptr->immune_cold = TRUE;
2047     }
2048 }
2049
2050 bool have_right_hand_weapon(player_type *creature_ptr)
2051 {
2052     if (has_melee_weapon(creature_ptr, INVEN_RARM))
2053         return TRUE;
2054
2055     if (can_two_hands_wielding(creature_ptr)) {
2056         switch (creature_ptr->pclass) {
2057         case CLASS_MONK:
2058         case CLASS_FORCETRAINER:
2059         case CLASS_BERSERKER:
2060             if (empty_hands(creature_ptr, FALSE) == (EMPTY_HAND_RARM | EMPTY_HAND_LARM)) {
2061                 return TRUE;
2062             }
2063             break;
2064         }
2065     }
2066
2067         return FALSE;
2068 }
2069
2070 bool have_left_hand_weapon(player_type *creature_ptr)
2071 {
2072     return has_melee_weapon(creature_ptr, INVEN_LARM);
2073 }
2074
2075 bool have_two_handed_weapons(player_type *creature_ptr)
2076 {
2077     if (can_two_hands_wielding(creature_ptr)) {
2078         if (have_right_hand_weapon(creature_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_LARM)
2079             && object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_RARM])) {
2080             return TRUE;
2081         } else if (have_left_hand_weapon(creature_ptr) && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_RARM)
2082             && object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_LARM])) {
2083             return TRUE;
2084         }
2085     }
2086     return FALSE;
2087 }
2088
2089 void have_lite(player_type *creature_ptr)
2090 {
2091     creature_ptr->lite = FALSE;
2092     if (creature_ptr->pclass == CLASS_NINJA)
2093         return;
2094
2095     if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
2096         creature_ptr->lite = TRUE;
2097     }
2098
2099     if (creature_ptr->mimic_form == MIMIC_VAMPIRE) {
2100         creature_ptr->lite = TRUE;
2101     }
2102
2103     if (creature_ptr->muta3 & MUT3_FIRE_BODY) {
2104         creature_ptr->lite = TRUE;
2105     }
2106
2107     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_VAMPIRE)
2108         creature_ptr->lite = TRUE;
2109
2110     if (creature_ptr->sh_fire)
2111         creature_ptr->lite = TRUE;
2112
2113     if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU)) {
2114         creature_ptr->lite = TRUE;
2115     }
2116 }
2117
2118 bool is_disable_two_handed_bonus(player_type *creature_ptr, int i)
2119 {
2120     object_type *o_ptr;
2121     o_ptr = &creature_ptr->inventory_list[INVEN_RARM + i];
2122     if (has_melee_weapon(creature_ptr, INVEN_RARM + i)) {
2123         if (calc_weapon_weight_limit(creature_ptr) * 2 >= o_ptr->weight / 10 && have_two_handed_weapons(creature_ptr) && (calc_weapon_weight_limit(creature_ptr) * 2 < o_ptr->weight / 5))
2124             return TRUE;
2125     }
2126     return FALSE;
2127 }
2128
2129 bool is_icky_wield_weapon(player_type *creature_ptr, int i)
2130 {
2131     object_type *o_ptr;
2132     BIT_FLAGS flgs[TR_FLAG_SIZE];
2133     o_ptr = &creature_ptr->inventory_list[INVEN_RARM + i];
2134     object_flags(creature_ptr, o_ptr, flgs);
2135
2136     if ((creature_ptr->pclass == CLASS_PRIEST) && (!(have_flag(flgs, TR_BLESSED))) && ((o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM))) {
2137         return TRUE;
2138     } else if (creature_ptr->pclass == CLASS_SORCERER) {
2139         if (!((o_ptr->tval == TV_HAFTED) && ((o_ptr->sval == SV_WIZSTAFF) || (o_ptr->sval == SV_NAMAKE_HAMMER)))) {
2140             return TRUE;
2141         }
2142     }
2143     if (is_not_monk_weapon(creature_ptr, i) || is_not_ninja_weapon(creature_ptr, i)) {
2144         return TRUE;
2145     }
2146     return FALSE;
2147 }
2148
2149 bool is_riding_wield_weapon(player_type *creature_ptr, int i)
2150 {
2151     object_type *o_ptr;
2152     BIT_FLAGS flgs[TR_FLAG_SIZE];
2153     o_ptr = &creature_ptr->inventory_list[INVEN_RARM + i];
2154     object_flags(creature_ptr, o_ptr, flgs);
2155     if (creature_ptr->riding != 0 && !(o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE))
2156         && !have_flag(flgs, TR_RIDING)) {
2157         return TRUE;
2158     }
2159     return FALSE;
2160 }
2161
2162 bool is_not_ninja_weapon(player_type *creature_ptr, int i)
2163 {
2164     tval_type tval = creature_ptr->inventory_list[INVEN_RARM + i].tval - TV_WEAPON_BEGIN;
2165     OBJECT_SUBTYPE_VALUE sval = creature_ptr->inventory_list[INVEN_RARM + i].sval;
2166     return creature_ptr->pclass == CLASS_NINJA
2167         && !((s_info[CLASS_NINJA].w_max[tval][sval] > WEAPON_EXP_BEGINNER) && (creature_ptr->inventory_list[INVEN_LARM - i].tval != TV_SHIELD));
2168 }
2169
2170 bool is_not_monk_weapon(player_type *creature_ptr, int i)
2171 {
2172     tval_type tval = creature_ptr->inventory_list[INVEN_RARM + i].tval - TV_WEAPON_BEGIN;
2173     OBJECT_SUBTYPE_VALUE sval = creature_ptr->inventory_list[INVEN_RARM + i].sval;
2174     return (creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER) && (!s_info[creature_ptr->pclass].w_max[tval][sval]);
2175 }
2176
2177 bool have_good_luck(player_type *creature_ptr) { return (creature_ptr->pseikaku == PERSONALITY_LUCKY) || (creature_ptr->muta3 |= MUT3_GOOD_LUCK); };