OSDN Git Service

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