OSDN Git Service

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