OSDN Git Service

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