OSDN Git Service

c5eacad526adf66f1dba7016ebf646ddea7cac16
[hengbandforosx/hengbandosx.git] / src / player / player-status.cpp
1 #include "player/player-status.h"
2 #include "artifact/fixed-art-types.h"
3 #include "autopick/autopick-reader-writer.h"
4 #include "autopick/autopick.h"
5 #include "cmd-action/cmd-pet.h"
6 #include "cmd-action/cmd-spell.h"
7 #include "cmd-io/cmd-dump.h"
8 #include "cmd-item/cmd-magiceat.h"
9 #include "combat/attack-power-table.h"
10 #include "core/asking-player.h"
11 #include "core/player-redraw-types.h"
12 #include "core/player-update-types.h"
13 #include "core/stuff-handler.h"
14 #include "core/window-redrawer.h"
15 #include "dungeon/dungeon-flag-types.h"
16 #include "dungeon/dungeon.h"
17 #include "effect/effect-characteristics.h"
18 #include "floor/cave.h"
19 #include "floor/floor-events.h"
20 #include "floor/floor-leaver.h"
21 #include "floor/floor-save.h"
22 #include "floor/floor-util.h"
23 #include "game-option/birth-options.h"
24 #include "game-option/text-display-options.h"
25 #include "grid/feature.h"
26 #include "grid/grid.h"
27 #include "inventory/inventory-object.h"
28 #include "inventory/inventory-slot-types.h"
29 #include "io/input-key-acceptor.h"
30 #include "io/write-diary.h"
31 #include "main/sound-definitions-table.h"
32 #include "main/sound-of-music.h"
33 #include "market/arena-info-table.h"
34 #include "mind/mind-force-trainer.h"
35 #include "mind/mind-ninja.h"
36 #include "monster-floor/monster-lite.h"
37 #include "monster-floor/monster-remover.h"
38 #include "monster-race/monster-race-hook.h"
39 #include "monster-race/monster-race.h"
40 #include "monster-race/race-flags1.h"
41 #include "monster-race/race-flags2.h"
42 #include "monster-race/race-flags3.h"
43 #include "monster-race/race-flags7.h"
44 #include "monster/monster-info.h"
45 #include "monster/monster-status.h"
46 #include "monster/monster-update.h"
47 #include "monster/smart-learn-types.h"
48 #include "mutation/mutation-calculator.h"
49 #include "mutation/mutation-flag-types.h"
50 #include "mutation/mutation-investor-remover.h"
51 #include "object-enchant/object-ego.h"
52 #include "object-enchant/special-object-flags.h"
53 #include "object-enchant/tr-types.h"
54 #include "object-enchant/trc-types.h"
55 #include "object-hook/hook-armor.h"
56 #include "object-hook/hook-checker.h"
57 #include "object-hook/hook-weapon.h"
58 #include "object/object-flags.h"
59 #include "object/object-info.h"
60 #include "object/object-mark-types.h"
61 #include "perception/object-perception.h"
62 #include "pet/pet-util.h"
63 #include "player-info/avatar.h"
64 #include "player-status/player-basic-statistics.h"
65 #include "player-status/player-hand-types.h"
66 #include "player-status/player-infravision.h"
67 #include "player-status/player-speed.h"
68 #include "player-status/player-stealth.h"
69 #include "player/attack-defense-types.h"
70 #include "player/digestion-processor.h"
71 #include "player/mimic-info-table.h"
72 #include "player/patron.h"
73 #include "player/player-class.h"
74 #include "player/player-damage.h"
75 #include "player/player-move.h"
76 #include "player/player-personality-types.h"
77 #include "player/player-personality.h"
78 #include "player/player-race-types.h"
79 #include "player/player-skill.h"
80 #include "player/player-status-flags.h"
81 #include "player/player-status-table.h"
82 #include "player/player-view.h"
83 #include "player/race-info-table.h"
84 #include "player/special-defense-types.h"
85 #include "realm/realm-hex-numbers.h"
86 #include "realm/realm-names-table.h"
87 #include "realm/realm-song-numbers.h"
88 #include "specific-object/bow.h"
89 #include "specific-object/torch.h"
90 #include "spell-realm/spells-hex.h"
91 #include "spell-realm/spells-song.h"
92 #include "spell/range-calc.h"
93 #include "spell/spells-describer.h"
94 #include "spell/spells-execution.h"
95 #include "spell/spells-status.h"
96 #include "spell/technic-info-table.h"
97 #include "status/action-setter.h"
98 #include "status/base-status.h"
99 #include "sv-definition/sv-lite-types.h"
100 #include "sv-definition/sv-weapon-types.h"
101 #include "system/floor-type-definition.h"
102 #include "system/monster-race-definition.h"
103 #include "system/monster-type-definition.h"
104 #include "system/object-type-definition.h"
105 #include "system/player-type-definition.h"
106 #include "term/screen-processor.h"
107 #include "util/bit-flags-calculator.h"
108 #include "util/quarks.h"
109 #include "util/string-processor.h"
110 #include "view/display-messages.h"
111 #include "world/world.h"
112
113 static const int extra_magic_glove_reduce_mana = 1;
114
115 static bool is_martial_arts_mode(player_type *creature_ptr);
116
117 static ACTION_SKILL_POWER calc_disarming(player_type *creature_ptr);
118 static ACTION_SKILL_POWER calc_device_ability(player_type *creature_ptr);
119 static ACTION_SKILL_POWER calc_saving_throw(player_type *creature_ptr);
120 static ACTION_SKILL_POWER calc_search(player_type *creature_ptr);
121 static ACTION_SKILL_POWER calc_search_freq(player_type *creature_ptr);
122 static ACTION_SKILL_POWER calc_to_hit_melee(player_type *creature_ptr);
123 static ACTION_SKILL_POWER calc_to_hit_shoot(player_type *creature_ptr);
124 static ACTION_SKILL_POWER calc_to_hit_throw(player_type *creature_ptr);
125 static ACTION_SKILL_POWER calc_skill_dig(player_type *creature_ptr);
126 static bool is_heavy_wield(player_type *creature_ptr, int i);
127 static s16b calc_num_blow(player_type *creature_ptr, int i);
128 static s16b calc_to_magic_chance(player_type *creature_ptr);
129 static ARMOUR_CLASS calc_base_ac(player_type *creature_ptr);
130 static ARMOUR_CLASS calc_to_ac(player_type *creature_ptr, bool is_real_value);
131 static s16b calc_double_weapon_penalty(player_type *creature_ptr, INVENTORY_IDX slot);
132 static bool is_riding_two_hands(player_type *creature_ptr);
133 static s16b calc_riding_bow_penalty(player_type *creature_ptr);
134 static void put_equipment_warning(player_type *creature_ptr);
135
136 static s16b calc_to_damage(player_type *creature_ptr, INVENTORY_IDX slot, bool is_real_value);
137 static s16b calc_to_hit(player_type *creature_ptr, INVENTORY_IDX slot, bool is_real_value);
138
139 static s16b calc_to_hit_bow(player_type *creature_ptr, bool is_real_value);
140
141 static s16b calc_to_damage_misc(player_type *creature_ptr);
142 static s16b calc_to_hit_misc(player_type *creature_ptr);
143
144 static DICE_NUMBER calc_to_weapon_dice_num(player_type *creature_ptr, INVENTORY_IDX slot);
145 static DICE_NUMBER calc_to_weapon_dice_side(player_type *creature_ptr, INVENTORY_IDX slot);
146
147 static player_hand main_attack_hand(player_type *creature_ptr);
148
149 /*** Player information ***/
150
151 /*!
152  * @brief 武器や各種スキル(騎乗以外)の抽象的表現ランクを返す。 /  Return proficiency level of weapons and misc. skills (except riding)
153  * @param weapon_exp 経験値
154  * @return ランク値
155  */
156 int weapon_exp_level(int weapon_exp)
157 {
158     if (weapon_exp < WEAPON_EXP_BEGINNER)
159         return EXP_LEVEL_UNSKILLED;
160     else if (weapon_exp < WEAPON_EXP_SKILLED)
161         return EXP_LEVEL_BEGINNER;
162     else if (weapon_exp < WEAPON_EXP_EXPERT)
163         return EXP_LEVEL_SKILLED;
164     else if (weapon_exp < WEAPON_EXP_MASTER)
165         return EXP_LEVEL_EXPERT;
166     else
167         return EXP_LEVEL_MASTER;
168 }
169
170 /*!
171  * @brief 騎乗スキルの抽象的ランクを返す。 / Return proficiency level of riding
172  * @param weapon_exp 経験値
173  * @return ランク値
174  */
175 int riding_exp_level(int riding_exp)
176 {
177     if (riding_exp < RIDING_EXP_BEGINNER)
178         return EXP_LEVEL_UNSKILLED;
179     else if (riding_exp < RIDING_EXP_SKILLED)
180         return EXP_LEVEL_BEGINNER;
181     else if (riding_exp < RIDING_EXP_EXPERT)
182         return EXP_LEVEL_SKILLED;
183     else if (riding_exp < RIDING_EXP_MASTER)
184         return EXP_LEVEL_EXPERT;
185     else
186         return EXP_LEVEL_MASTER;
187 }
188
189 /*!
190  * @brief クリーチャーの呪文レベルの抽象的ランクを返す。 / Return proficiency level of spells
191  * @param spell_exp 経験値
192  * @return ランク値
193  */
194 int spell_exp_level(int spell_exp)
195 {
196     if (spell_exp < SPELL_EXP_BEGINNER)
197         return EXP_LEVEL_UNSKILLED;
198     else if (spell_exp < SPELL_EXP_SKILLED)
199         return EXP_LEVEL_BEGINNER;
200     else if (spell_exp < SPELL_EXP_EXPERT)
201         return EXP_LEVEL_SKILLED;
202     else if (spell_exp < SPELL_EXP_MASTER)
203         return EXP_LEVEL_EXPERT;
204     else
205         return EXP_LEVEL_MASTER;
206 }
207
208 /*!
209  * @brief 遅延描画更新 / Delayed visual update
210  * @details update_view(), update_lite(), update_mon_lite() においてのみ更新すること / Only used if update_view(), update_lite() or update_mon_lite() was called
211  * @param player_ptr 主観となるプレイヤー構造体参照ポインタ
212  * @todo 将来独自インターフェース実装にはz-term系に追い出すべきか?
213  * @return なし
214  */
215 static void delayed_visual_update(player_type *player_ptr)
216 {
217     floor_type *floor_ptr = player_ptr->current_floor_ptr;
218     for (int i = 0; i < floor_ptr->redraw_n; i++) {
219         POSITION y = floor_ptr->redraw_y[i];
220         POSITION x = floor_ptr->redraw_x[i];
221         grid_type *g_ptr;
222         g_ptr = &floor_ptr->grid_array[y][x];
223         if (none_bits(g_ptr->info, CAVE_REDRAW))
224             continue;
225
226         if (any_bits(g_ptr->info, CAVE_NOTE))
227             note_spot(player_ptr, y, x);
228
229         lite_spot(player_ptr, y, x);
230         if (g_ptr->m_idx)
231             update_monster(player_ptr, g_ptr->m_idx, FALSE);
232
233         reset_bits(g_ptr->info, (CAVE_NOTE | CAVE_REDRAW));
234     }
235
236     floor_ptr->redraw_n = 0;
237 }
238
239 /*!
240  * @brief 射撃武器がプレイヤーにとって重すぎるかどうかの判定 /
241  * @param o_ptr 判定する射撃武器のアイテム情報参照ポインタ
242  * @return 重すぎるならばTRUE
243  */
244 static bool is_heavy_shoot(player_type *creature_ptr, object_type *o_ptr)
245 {
246     int hold = adj_str_hold[creature_ptr->stat_index[A_STR]];
247     return (hold < o_ptr->weight / 10);
248 }
249
250 /*!
251  * @brief 所持品総重量を計算する
252  * @param creature_ptr 計算対象となるクリーチャーの参照ポインタ
253  * @return 総重量
254  */
255 WEIGHT calc_inventory_weight(player_type *creature_ptr)
256 {
257     WEIGHT weight = 0;
258
259     object_type *o_ptr;
260     for (int i = 0; i < INVEN_TOTAL; i++) {
261         o_ptr = &creature_ptr->inventory_list[i];
262         if (!o_ptr->k_idx)
263             continue;
264         weight += o_ptr->weight * o_ptr->number;
265     }
266     return weight;
267 }
268 /*!
269  * @brief プレイヤーの全ステータスを更新する /
270  * Calculate the players current "state", taking into account
271  * not only race/class intrinsics, but also objects being worn
272  * and temporary spell effects.
273  * @return なし
274  * @details
275  * <pre>
276  * See also update_max_mana() and update_max_hitpoints().
277  *
278  * Take note of the new "speed code", in particular, a very strong
279  * player will start slowing down as soon as he reaches 150 pounds,
280  * but not until he reaches 450 pounds will he be half as fast as
281  * a normal kobold.  This both hurts and helps the player, hurts
282  * because in the old days a player could just avoid 300 pounds,
283  * and helps because now carrying 300 pounds is not very painful.
284  *
285  * The "weapon" and "bow" do *not* add to the bonuses to hit or to
286  * damage, since that would affect non-combat things.  These values
287  * are actually added in later, at the appropriate place.
288  *
289  * This function induces various "status" messages.
290  * </pre>
291  * @todo ここで計算していた各値は一部の状態変化メッセージ処理を除き、今後必要な時に適示計算する形に移行するためほぼすべて削られる。
292  */
293 static void update_bonuses(player_type *creature_ptr)
294 {
295     int empty_hands_status = empty_hands(creature_ptr, TRUE);
296     object_type *o_ptr;
297
298     /* Save the old vision stuff */
299     BIT_FLAGS old_telepathy = creature_ptr->telepathy;
300     BIT_FLAGS old_esp_animal = creature_ptr->esp_animal;
301     BIT_FLAGS old_esp_undead = creature_ptr->esp_undead;
302     BIT_FLAGS old_esp_demon = creature_ptr->esp_demon;
303     BIT_FLAGS old_esp_orc = creature_ptr->esp_orc;
304     BIT_FLAGS old_esp_troll = creature_ptr->esp_troll;
305     BIT_FLAGS old_esp_giant = creature_ptr->esp_giant;
306     BIT_FLAGS old_esp_dragon = creature_ptr->esp_dragon;
307     BIT_FLAGS old_esp_human = creature_ptr->esp_human;
308     BIT_FLAGS old_esp_evil = creature_ptr->esp_evil;
309     BIT_FLAGS old_esp_good = creature_ptr->esp_good;
310     BIT_FLAGS old_esp_nonliving = creature_ptr->esp_nonliving;
311     BIT_FLAGS old_esp_unique = creature_ptr->esp_unique;
312     BIT_FLAGS old_see_inv = creature_ptr->see_inv;
313     BIT_FLAGS old_mighty_throw = creature_ptr->mighty_throw;
314     s16b old_speed = creature_ptr->pspeed;
315
316     ARMOUR_CLASS old_dis_ac = creature_ptr->dis_ac;
317     ARMOUR_CLASS old_dis_to_a = creature_ptr->dis_to_a;
318
319     creature_ptr->xtra_might = has_xtra_might(creature_ptr);
320     creature_ptr->esp_evil = has_esp_evil(creature_ptr);
321     creature_ptr->esp_animal = has_esp_animal(creature_ptr);
322     creature_ptr->esp_undead = has_esp_undead(creature_ptr);
323     creature_ptr->esp_demon = has_esp_demon(creature_ptr);
324     creature_ptr->esp_orc = has_esp_orc(creature_ptr);
325     creature_ptr->esp_troll = has_esp_troll(creature_ptr);
326     creature_ptr->esp_giant = has_esp_giant(creature_ptr);
327     creature_ptr->esp_dragon = has_esp_dragon(creature_ptr);
328     creature_ptr->esp_human = has_esp_human(creature_ptr);
329     creature_ptr->esp_good = has_esp_good(creature_ptr);
330     creature_ptr->esp_nonliving = has_esp_nonliving(creature_ptr);
331     creature_ptr->esp_unique = has_esp_unique(creature_ptr);
332     creature_ptr->telepathy = has_esp_telepathy(creature_ptr);
333     creature_ptr->bless_blade = has_bless_blade(creature_ptr);
334     creature_ptr->easy_2weapon = has_easy2_weapon(creature_ptr);
335     creature_ptr->down_saving = has_down_saving(creature_ptr);
336     creature_ptr->yoiyami = has_no_ac(creature_ptr);
337     creature_ptr->mighty_throw = has_mighty_throw(creature_ptr);
338     creature_ptr->dec_mana = has_dec_mana(creature_ptr);
339     creature_ptr->see_nocto = has_see_nocto(creature_ptr);
340     creature_ptr->warning = has_warning(creature_ptr);
341     creature_ptr->anti_magic = has_anti_magic(creature_ptr);
342     creature_ptr->anti_tele = has_anti_tele(creature_ptr);
343     creature_ptr->easy_spell = has_easy_spell(creature_ptr);
344     creature_ptr->heavy_spell = has_heavy_spell(creature_ptr);
345     creature_ptr->hold_exp = has_hold_exp(creature_ptr);
346     creature_ptr->see_inv = has_see_inv(creature_ptr);
347     creature_ptr->free_act = has_free_act(creature_ptr);
348     creature_ptr->levitation = has_levitation(creature_ptr);
349     creature_ptr->can_swim = has_can_swim(creature_ptr);
350     creature_ptr->slow_digest = has_slow_digest(creature_ptr);
351     creature_ptr->regenerate = has_regenerate(creature_ptr);
352     update_curses(creature_ptr);
353     creature_ptr->impact = has_impact(creature_ptr);
354     creature_ptr->earthquake = has_earthquake(creature_ptr);
355     update_extra_blows(creature_ptr);
356
357     creature_ptr->lite = has_lite(creature_ptr);
358
359     if (any_bits(creature_ptr->special_defense, KAMAE_MASK)) {
360         if (none_bits(empty_hands_status, EMPTY_HAND_MAIN)) {
361             set_action(creature_ptr, ACTION_NONE);
362         }
363     }
364
365     creature_ptr->stat_add[A_STR] = PlayerStrength(creature_ptr).modification_value();
366     creature_ptr->stat_add[A_INT] = PlayerIntelligence(creature_ptr).modification_value();
367     creature_ptr->stat_add[A_WIS] = PlayerWisdom(creature_ptr).modification_value();
368     creature_ptr->stat_add[A_DEX] = PlayerDexterity(creature_ptr).modification_value();
369     creature_ptr->stat_add[A_CON] = PlayerConstitution(creature_ptr).modification_value();
370     creature_ptr->stat_add[A_CHR] = PlayerCharisma(creature_ptr).modification_value();
371
372     PlayerStrength(creature_ptr).update_value();
373     PlayerIntelligence(creature_ptr).update_value();
374     PlayerWisdom(creature_ptr).update_value();
375     PlayerDexterity(creature_ptr).update_value();
376     PlayerConstitution(creature_ptr).update_value();
377     PlayerCharisma(creature_ptr).update_value();
378
379     o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
380     if (o_ptr->k_idx) {
381         creature_ptr->tval_ammo = (byte)bow_tval_ammo(o_ptr);
382         if (o_ptr->k_idx && !is_heavy_shoot(creature_ptr, &creature_ptr->inventory_list[INVEN_BOW])) {
383             creature_ptr->num_fire = calc_num_fire(creature_ptr, o_ptr);
384         }
385     }
386
387     for (int i = 0; i < 2; i++) {
388         creature_ptr->icky_wield[i] = has_icky_wield_weapon(creature_ptr, i);
389         creature_ptr->riding_wield[i] = has_riding_wield_weapon(creature_ptr, i);
390         creature_ptr->heavy_wield[i] = is_heavy_wield(creature_ptr, i);
391         creature_ptr->num_blow[i] = calc_num_blow(creature_ptr, i);
392         creature_ptr->to_dd[i] = calc_to_weapon_dice_num(creature_ptr, INVEN_MAIN_HAND + i);
393         creature_ptr->to_ds[i] = calc_to_weapon_dice_side(creature_ptr, INVEN_MAIN_HAND + i);
394     }
395
396     creature_ptr->pspeed = PlayerSpeed(creature_ptr).get_value();
397     creature_ptr->see_infra = PlayerInfravision(creature_ptr).get_value();
398     creature_ptr->skill_stl = PlayerStealth(creature_ptr).get_value();
399     creature_ptr->skill_dis = calc_disarming(creature_ptr);
400     creature_ptr->skill_dev = calc_device_ability(creature_ptr);
401     creature_ptr->skill_sav = calc_saving_throw(creature_ptr);
402     creature_ptr->skill_srh = calc_search(creature_ptr);
403     creature_ptr->skill_fos = calc_search_freq(creature_ptr);
404     creature_ptr->skill_thn = calc_to_hit_melee(creature_ptr);
405     creature_ptr->skill_thb = calc_to_hit_shoot(creature_ptr);
406     creature_ptr->skill_tht = calc_to_hit_throw(creature_ptr);
407     creature_ptr->riding_ryoute = is_riding_two_hands(creature_ptr);
408     creature_ptr->to_d[0] = calc_to_damage(creature_ptr, INVEN_MAIN_HAND, TRUE);
409     creature_ptr->to_d[1] = calc_to_damage(creature_ptr, INVEN_SUB_HAND, TRUE);
410     creature_ptr->dis_to_d[0] = calc_to_damage(creature_ptr, INVEN_MAIN_HAND, FALSE);
411     creature_ptr->dis_to_d[1] = calc_to_damage(creature_ptr, INVEN_SUB_HAND, FALSE);
412     creature_ptr->to_h[0] = calc_to_hit(creature_ptr, INVEN_MAIN_HAND, TRUE);
413     creature_ptr->to_h[1] = calc_to_hit(creature_ptr, INVEN_SUB_HAND, TRUE);
414     creature_ptr->dis_to_h[0] = calc_to_hit(creature_ptr, INVEN_MAIN_HAND, FALSE);
415     creature_ptr->dis_to_h[1] = calc_to_hit(creature_ptr, INVEN_SUB_HAND, FALSE);
416     creature_ptr->to_h_b = calc_to_hit_bow(creature_ptr, TRUE);
417     creature_ptr->dis_to_h_b = calc_to_hit_bow(creature_ptr, FALSE);
418     creature_ptr->to_d_m = calc_to_damage_misc(creature_ptr);
419     creature_ptr->to_h_m = calc_to_hit_misc(creature_ptr);
420     creature_ptr->skill_dig = calc_skill_dig(creature_ptr);
421     creature_ptr->to_m_chance = calc_to_magic_chance(creature_ptr);
422     creature_ptr->ac = calc_base_ac(creature_ptr);
423     creature_ptr->to_a = calc_to_ac(creature_ptr, TRUE);
424     creature_ptr->dis_ac = calc_base_ac(creature_ptr);
425     creature_ptr->dis_to_a = calc_to_ac(creature_ptr, FALSE);
426
427     if (old_mighty_throw != creature_ptr->mighty_throw) {
428         creature_ptr->window_flags |= PW_INVEN;
429     }
430
431     if (creature_ptr->telepathy != old_telepathy) {
432         set_bits(creature_ptr->update, PU_MONSTERS);
433     }
434
435     if ((creature_ptr->esp_animal != old_esp_animal) || (creature_ptr->esp_undead != old_esp_undead) || (creature_ptr->esp_demon != old_esp_demon)
436         || (creature_ptr->esp_orc != old_esp_orc) || (creature_ptr->esp_troll != old_esp_troll) || (creature_ptr->esp_giant != old_esp_giant)
437         || (creature_ptr->esp_dragon != old_esp_dragon) || (creature_ptr->esp_human != old_esp_human) || (creature_ptr->esp_evil != old_esp_evil)
438         || (creature_ptr->esp_good != old_esp_good) || (creature_ptr->esp_nonliving != old_esp_nonliving) || (creature_ptr->esp_unique != old_esp_unique)) {
439         set_bits(creature_ptr->update, PU_MONSTERS);
440     }
441
442     if (creature_ptr->see_inv != old_see_inv) {
443         set_bits(creature_ptr->update, PU_MONSTERS);
444     }
445
446     if (creature_ptr->pspeed != old_speed) {
447         set_bits(creature_ptr->redraw, PR_SPEED);
448     }
449
450     if ((creature_ptr->dis_ac != old_dis_ac) || (creature_ptr->dis_to_a != old_dis_to_a)) {
451         set_bits(creature_ptr->redraw, PR_ARMOR);
452         set_bits(creature_ptr->window_flags, PW_PLAYER);
453     }
454
455     if (current_world_ptr->character_xtra)
456         return;
457
458     put_equipment_warning(creature_ptr);
459     check_no_flowed(creature_ptr);
460 }
461
462 static void update_alignment(player_type *creature_ptr)
463 {
464     creature_ptr->alignment = 0;
465     floor_type *floor_ptr = creature_ptr->current_floor_ptr;
466     for (MONSTER_IDX m_idx = floor_ptr->m_max - 1; m_idx >= 1; m_idx--) {
467         monster_type *m_ptr;
468         monster_race *r_ptr;
469         m_ptr = &floor_ptr->m_list[m_idx];
470         if (!monster_is_valid(m_ptr))
471             continue;
472         r_ptr = &r_info[m_ptr->r_idx];
473
474         if (!is_pet(m_ptr))
475             continue;
476
477         if (any_bits(r_ptr->flags3, RF3_GOOD))
478             creature_ptr->alignment += r_ptr->level;
479         if (any_bits(r_ptr->flags3, RF3_EVIL))
480             creature_ptr->alignment -= r_ptr->level;
481     }
482
483     if (creature_ptr->mimic_form) {
484         switch (creature_ptr->mimic_form) {
485         case MIMIC_DEMON:
486             creature_ptr->alignment -= 200;
487             break;
488         case MIMIC_DEMON_LORD:
489             creature_ptr->alignment -= 200;
490             break;
491         }
492     } else {
493         switch (creature_ptr->prace) {
494         case RACE_ARCHON:
495             creature_ptr->alignment += 200;
496             break;
497         case RACE_BALROG:
498             creature_ptr->alignment -= 200;
499             break;
500
501         default:
502             break;
503         }
504     }
505
506     for (int i = 0; i < 2; i++) {
507         if (!has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i))
508             continue;
509         if (creature_ptr->inventory_list[INVEN_MAIN_HAND + i].name1 != ART_IRON_BALL)
510             continue;
511         creature_ptr->alignment -= 1000;
512     }
513
514     int j = 0;
515     int neutral[2];
516     for (int i = 0; i < 8; i++) {
517         switch (creature_ptr->vir_types[i]) {
518         case V_JUSTICE:
519             creature_ptr->alignment += creature_ptr->virtues[i] * 2;
520             break;
521         case V_CHANCE:
522             break;
523         case V_NATURE:
524         case V_HARMONY:
525             neutral[j++] = i;
526             break;
527         case V_UNLIFE:
528             creature_ptr->alignment -= creature_ptr->virtues[i];
529             break;
530         default:
531             creature_ptr->alignment += creature_ptr->virtues[i];
532             break;
533         }
534     }
535
536     for (int i = 0; i < j; i++) {
537         if (creature_ptr->alignment > 0) {
538             creature_ptr->alignment -= creature_ptr->virtues[neutral[i]] / 2;
539             if (creature_ptr->alignment < 0)
540                 creature_ptr->alignment = 0;
541         } else if (creature_ptr->alignment < 0) {
542             creature_ptr->alignment += creature_ptr->virtues[neutral[i]] / 2;
543             if (creature_ptr->alignment > 0)
544                 creature_ptr->alignment = 0;
545         }
546     }
547 }
548
549 /*!
550  * @brief プレイヤーの最大HPを更新する /
551  * Update the players maximal hit points
552  * Adjust current hitpoints if necessary
553  * @return なし
554  * @details
555  */
556 static void update_max_hitpoints(player_type *creature_ptr)
557 {
558     int bonus = ((int)(adj_con_mhp[creature_ptr->stat_index[A_CON]]) - 128) * creature_ptr->lev / 4;
559     int mhp = creature_ptr->player_hp[creature_ptr->lev - 1];
560
561     byte tmp_hitdie;
562     if (creature_ptr->mimic_form) {
563         if (creature_ptr->pclass == CLASS_SORCERER)
564             tmp_hitdie = mimic_info[creature_ptr->mimic_form].r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
565         else
566             tmp_hitdie = mimic_info[creature_ptr->mimic_form].r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
567         mhp = mhp * tmp_hitdie / creature_ptr->hitdie;
568     }
569
570     if (creature_ptr->pclass == CLASS_SORCERER) {
571         if (creature_ptr->lev < 30)
572             mhp = (mhp * (45 + creature_ptr->lev) / 100);
573         else
574             mhp = (mhp * 75 / 100);
575         bonus = (bonus * 65 / 100);
576     }
577
578     mhp += bonus;
579
580     if (creature_ptr->pclass == CLASS_BERSERKER) {
581         mhp = mhp * (110 + (((creature_ptr->lev + 40) * (creature_ptr->lev + 40) - 1550) / 110)) / 100;
582     }
583
584     if (mhp < creature_ptr->lev + 1)
585         mhp = creature_ptr->lev + 1;
586     if (is_hero(creature_ptr))
587         mhp += 10;
588     if (is_shero(creature_ptr))
589         mhp += 30;
590     if (creature_ptr->tsuyoshi)
591         mhp += 50;
592     if (hex_spelling(creature_ptr, HEX_XTRA_MIGHT))
593         mhp += 15;
594     if (hex_spelling(creature_ptr, HEX_BUILDING))
595         mhp += 60;
596     if (creature_ptr->mhp == mhp)
597         return;
598
599     if (creature_ptr->chp >= mhp) {
600         creature_ptr->chp = mhp;
601         creature_ptr->chp_frac = 0;
602     }
603
604 #ifdef JP
605     if (creature_ptr->level_up_message && (mhp > creature_ptr->mhp)) {
606         msg_format("最大ヒット・ポイントが %d 増加した!", (mhp - creature_ptr->mhp));
607     }
608 #endif
609     creature_ptr->mhp = mhp;
610
611     creature_ptr->redraw |= PR_HP;
612     creature_ptr->window_flags |= PW_PLAYER;
613 }
614
615 /*!
616  * @brief プレイヤーの現在学習可能な魔法数を計算し、増減に応じて魔法の忘却、再学習を処置する。 /
617  * Calculate number of spells player should have, and forget,
618  * or remember, spells until that number is properly reflected.
619  * @return なし
620  * @details
621  * Note that this function induces various "status" messages,
622  * which must be bypasses until the character is created.
623  */
624 static void update_num_of_spells(player_type *creature_ptr)
625 {
626     if (!mp_ptr->spell_book)
627         return;
628     if (!current_world_ptr->character_generated)
629         return;
630     if (current_world_ptr->character_xtra)
631         return;
632     if ((creature_ptr->pclass == CLASS_SORCERER) || (creature_ptr->pclass == CLASS_RED_MAGE)) {
633         creature_ptr->new_spells = 0;
634         return;
635     }
636
637     concptr p = spell_category_name(mp_ptr->spell_book);
638     int levels = creature_ptr->lev - mp_ptr->spell_first + 1;
639     if (levels < 0)
640         levels = 0;
641
642     int num_allowed = (adj_mag_study[creature_ptr->stat_index[mp_ptr->spell_stat]] * levels / 2);
643     int bonus = 0;
644     if ((creature_ptr->pclass != CLASS_SAMURAI) && (mp_ptr->spell_book != TV_LIFE_BOOK)) {
645         bonus = 4;
646     }
647
648     if (creature_ptr->pclass == CLASS_SAMURAI) {
649         num_allowed = 32;
650     } else if (creature_ptr->realm2 == REALM_NONE) {
651         num_allowed = (num_allowed + 1) / 2;
652         if (num_allowed > (32 + bonus))
653             num_allowed = 32 + bonus;
654     } else if ((creature_ptr->pclass == CLASS_MAGE) || (creature_ptr->pclass == CLASS_PRIEST)) {
655         if (num_allowed > (96 + bonus))
656             num_allowed = 96 + bonus;
657     } else {
658         if (num_allowed > (80 + bonus))
659             num_allowed = 80 + bonus;
660     }
661
662     int num_boukyaku = 0;
663     for (int j = 0; j < 64; j++) {
664         if ((j < 32) ? any_bits(creature_ptr->spell_forgotten1, (1UL << j)) : any_bits(creature_ptr->spell_forgotten2, (1UL << (j - 32)))) {
665             num_boukyaku++;
666         }
667     }
668
669     creature_ptr->new_spells = num_allowed + creature_ptr->add_spells + num_boukyaku - creature_ptr->learned_spells;
670     for (int i = 63; i >= 0; i--) {
671         if (!creature_ptr->spell_learned1 && !creature_ptr->spell_learned2)
672             break;
673
674         int j = creature_ptr->spell_order[i];
675         if (j >= 99)
676             continue;
677
678         const magic_type *s_ptr;
679         if (!is_magic((j < 32) ? creature_ptr->realm1 : creature_ptr->realm2)) {
680             if (j < 32)
681                 s_ptr = &technic_info[creature_ptr->realm1 - MIN_TECHNIC][j];
682             else
683                 s_ptr = &technic_info[creature_ptr->realm2 - MIN_TECHNIC][j % 32];
684         } else if (j < 32)
685             s_ptr = &mp_ptr->info[creature_ptr->realm1 - 1][j];
686         else
687             s_ptr = &mp_ptr->info[creature_ptr->realm2 - 1][j % 32];
688
689         if (s_ptr->slevel <= creature_ptr->lev)
690             continue;
691
692         bool is_spell_learned = (j < 32) ? any_bits(creature_ptr->spell_learned1, (1UL << j)) : any_bits(creature_ptr->spell_learned2, (1UL << (j - 32)));
693         if (!is_spell_learned)
694             continue;
695
696         REALM_IDX which;
697         if (j < 32) {
698             set_bits(creature_ptr->spell_forgotten1, (1UL << j));
699             which = creature_ptr->realm1;
700         } else {
701             set_bits(creature_ptr->spell_forgotten2, (1UL << (j - 32)));
702             which = creature_ptr->realm2;
703         }
704
705         if (j < 32) {
706             reset_bits(creature_ptr->spell_learned1, (1UL << j));
707             which = creature_ptr->realm1;
708         } else {
709             reset_bits(creature_ptr->spell_learned2, (1UL << (j - 32)));
710             which = creature_ptr->realm2;
711         }
712
713 #ifdef JP
714         msg_format("%sの%sを忘れてしまった。", exe_spell(creature_ptr, which, j % 32, SPELL_NAME), p);
715 #else
716         msg_format("You have forgotten the %s of %s.", p, exe_spell(creature_ptr, which, j % 32, SPELL_NAME));
717 #endif
718         creature_ptr->new_spells++;
719     }
720
721     /* Forget spells if we know too many spells */
722     for (int i = 63; i >= 0; i--) {
723         if (creature_ptr->new_spells >= 0)
724             break;
725         if (!creature_ptr->spell_learned1 && !creature_ptr->spell_learned2)
726             break;
727
728         int j = creature_ptr->spell_order[i];
729         if (j >= 99)
730             continue;
731
732         bool is_spell_learned = (j < 32) ? any_bits(creature_ptr->spell_learned1, (1UL << j)) : any_bits(creature_ptr->spell_learned2, (1UL << (j - 32)));
733         if (!is_spell_learned)
734             continue;
735
736         REALM_IDX which;
737         if (j < 32) {
738             set_bits(creature_ptr->spell_forgotten1, (1UL << j));
739             which = creature_ptr->realm1;
740         } else {
741             set_bits(creature_ptr->spell_forgotten2, (1UL << (j - 32)));
742             which = creature_ptr->realm2;
743         }
744
745         if (j < 32) {
746             reset_bits(creature_ptr->spell_learned1, (1UL << j));
747             which = creature_ptr->realm1;
748         } else {
749             reset_bits(creature_ptr->spell_learned2, (1UL << (j - 32)));
750             which = creature_ptr->realm2;
751         }
752
753 #ifdef JP
754         msg_format("%sの%sを忘れてしまった。", exe_spell(creature_ptr, which, j % 32, SPELL_NAME), p);
755 #else
756         msg_format("You have forgotten the %s of %s.", p, exe_spell(creature_ptr, which, j % 32, SPELL_NAME));
757 #endif
758         creature_ptr->new_spells++;
759     }
760
761     /* Check for spells to remember */
762     for (int i = 0; i < 64; i++) {
763         if (creature_ptr->new_spells <= 0)
764             break;
765         if (!creature_ptr->spell_forgotten1 && !creature_ptr->spell_forgotten2)
766             break;
767         int j = creature_ptr->spell_order[i];
768         if (j >= 99)
769             break;
770
771         const magic_type *s_ptr;
772         if (!is_magic((j < 32) ? creature_ptr->realm1 : creature_ptr->realm2)) {
773             if (j < 32)
774                 s_ptr = &technic_info[creature_ptr->realm1 - MIN_TECHNIC][j];
775             else
776                 s_ptr = &technic_info[creature_ptr->realm2 - MIN_TECHNIC][j % 32];
777         } else if (j < 32)
778             s_ptr = &mp_ptr->info[creature_ptr->realm1 - 1][j];
779         else
780             s_ptr = &mp_ptr->info[creature_ptr->realm2 - 1][j % 32];
781
782         if (s_ptr->slevel > creature_ptr->lev)
783             continue;
784
785         bool is_spell_learned = (j < 32) ? any_bits(creature_ptr->spell_forgotten1, (1UL << j)) : any_bits(creature_ptr->spell_forgotten2, (1UL << (j - 32)));
786         if (!is_spell_learned)
787             continue;
788
789         REALM_IDX which;
790         if (j < 32) {
791             reset_bits(creature_ptr->spell_forgotten1, (1UL << j));
792             which = creature_ptr->realm1;
793         } else {
794             reset_bits(creature_ptr->spell_forgotten2, (1UL << (j - 32)));
795             which = creature_ptr->realm2;
796         }
797
798         if (j < 32) {
799             set_bits(creature_ptr->spell_learned1, (1UL << j));
800             which = creature_ptr->realm1;
801         } else {
802             set_bits(creature_ptr->spell_learned2, (1UL << (j - 32)));
803             which = creature_ptr->realm2;
804         }
805
806 #ifdef JP
807         msg_format("%sの%sを思い出した。", exe_spell(creature_ptr, which, j % 32, SPELL_NAME), p);
808 #else
809         msg_format("You have remembered the %s of %s.", p, exe_spell(creature_ptr, which, j % 32, SPELL_NAME));
810 #endif
811         creature_ptr->new_spells--;
812     }
813
814     if (creature_ptr->realm2 == REALM_NONE) {
815         int k = 0;
816         for (int j = 0; j < 32; j++) {
817             const magic_type *s_ptr;
818             if (!is_magic(creature_ptr->realm1))
819                 s_ptr = &technic_info[creature_ptr->realm1 - MIN_TECHNIC][j];
820             else
821                 s_ptr = &mp_ptr->info[creature_ptr->realm1 - 1][j];
822
823             if (s_ptr->slevel > creature_ptr->lev)
824                 continue;
825
826             if (any_bits(creature_ptr->spell_learned1, (1UL << j))) {
827                 continue;
828             }
829
830             k++;
831         }
832
833         if (k > 32)
834             k = 32;
835         if ((creature_ptr->new_spells > k) && ((mp_ptr->spell_book == TV_LIFE_BOOK) || (mp_ptr->spell_book == TV_HISSATSU_BOOK))) {
836             creature_ptr->new_spells = (s16b)k;
837         }
838     }
839
840     if (creature_ptr->new_spells < 0)
841         creature_ptr->new_spells = 0;
842
843     if (creature_ptr->old_spells == creature_ptr->new_spells)
844         return;
845
846     if (creature_ptr->new_spells) {
847 #ifdef JP
848         if (creature_ptr->new_spells < 10) {
849             msg_format("あと %d つの%sを学べる。", creature_ptr->new_spells, p);
850         } else {
851             msg_format("あと %d 個の%sを学べる。", creature_ptr->new_spells, p);
852         }
853 #else
854         msg_format("You can learn %d more %s%s.", creature_ptr->new_spells, p, (creature_ptr->new_spells != 1) ? "s" : "");
855 #endif
856     }
857
858     creature_ptr->old_spells = creature_ptr->new_spells;
859     set_bits(creature_ptr->redraw, PR_STUDY);
860     set_bits(creature_ptr->window_flags, PW_OBJECT);
861 }
862
863 /*!
864  * @brief プレイヤーの最大MPを更新する /
865  * Update maximum mana.  You do not need to know any spells.
866  * Note that mana is lowered by heavy (or inappropriate) armor.
867  * @return なし
868  * @details
869  * This function induces status messages.
870  */
871 static void update_max_mana(player_type *creature_ptr)
872 {
873     if (!mp_ptr->spell_book && mp_ptr->spell_first == SPELL_FIRST_NO_SPELL)
874         return;
875
876     int levels;
877     if ((creature_ptr->pclass == CLASS_MINDCRAFTER) || (creature_ptr->pclass == CLASS_MIRROR_MASTER) || (creature_ptr->pclass == CLASS_BLUE_MAGE)
878         || creature_ptr->pclass == CLASS_ELEMENTALIST) {
879         levels = creature_ptr->lev;
880     } else {
881         if (mp_ptr->spell_first > creature_ptr->lev) {
882             creature_ptr->msp = 0;
883             set_bits(creature_ptr->redraw, PR_MANA);
884             return;
885         }
886
887         levels = (creature_ptr->lev - mp_ptr->spell_first) + 1;
888     }
889
890     int msp;
891     if (creature_ptr->pclass == CLASS_SAMURAI) {
892         msp = (adj_mag_mana[creature_ptr->stat_index[mp_ptr->spell_stat]] + 10) * 2;
893         if (msp)
894             msp += (msp * rp_ptr->r_adj[mp_ptr->spell_stat] / 20);
895     } else {
896         msp = adj_mag_mana[creature_ptr->stat_index[mp_ptr->spell_stat]] * (levels + 3) / 4;
897         if (msp)
898             msp++;
899         if (msp)
900             msp += (msp * rp_ptr->r_adj[mp_ptr->spell_stat] / 20);
901         if (msp && (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN))
902             msp += msp / 2;
903         if (msp && (creature_ptr->pclass == CLASS_HIGH_MAGE))
904             msp += msp / 4;
905         if (msp && (creature_ptr->pclass == CLASS_SORCERER))
906             msp += msp * (25 + creature_ptr->lev) / 100;
907     }
908
909     if (any_bits(mp_ptr->spell_xtra, extra_magic_glove_reduce_mana)) {
910         BIT_FLAGS flgs[TR_FLAG_SIZE];
911         creature_ptr->cumber_glove = FALSE;
912         object_type *o_ptr;
913         o_ptr = &creature_ptr->inventory_list[INVEN_ARMS];
914         object_flags(creature_ptr, o_ptr, flgs);
915         if (o_ptr->k_idx && !(has_flag(flgs, TR_FREE_ACT)) && !(has_flag(flgs, TR_DEC_MANA)) && !(has_flag(flgs, TR_EASY_SPELL))
916             && !((has_flag(flgs, TR_MAGIC_MASTERY)) && (o_ptr->pval > 0)) && !((has_flag(flgs, TR_DEX)) && (o_ptr->pval > 0))) {
917             creature_ptr->cumber_glove = TRUE;
918             msp = (3 * msp) / 4;
919         }
920     }
921
922     creature_ptr->cumber_armor = FALSE;
923
924     int cur_wgt = 0;
925     if (creature_ptr->inventory_list[INVEN_MAIN_HAND].tval > TV_SWORD)
926         cur_wgt += creature_ptr->inventory_list[INVEN_MAIN_HAND].weight;
927     if (creature_ptr->inventory_list[INVEN_SUB_HAND].tval > TV_SWORD)
928         cur_wgt += creature_ptr->inventory_list[INVEN_SUB_HAND].weight;
929     cur_wgt += creature_ptr->inventory_list[INVEN_BODY].weight;
930     cur_wgt += creature_ptr->inventory_list[INVEN_HEAD].weight;
931     cur_wgt += creature_ptr->inventory_list[INVEN_OUTER].weight;
932     cur_wgt += creature_ptr->inventory_list[INVEN_ARMS].weight;
933     cur_wgt += creature_ptr->inventory_list[INVEN_FEET].weight;
934
935     switch (creature_ptr->pclass) {
936     case CLASS_MAGE:
937     case CLASS_HIGH_MAGE:
938     case CLASS_BLUE_MAGE:
939     case CLASS_MONK:
940     case CLASS_FORCETRAINER:
941     case CLASS_SORCERER:
942     case CLASS_ELEMENTALIST: {
943         if (creature_ptr->inventory_list[INVEN_MAIN_HAND].tval <= TV_SWORD)
944             cur_wgt += creature_ptr->inventory_list[INVEN_MAIN_HAND].weight;
945         if (creature_ptr->inventory_list[INVEN_SUB_HAND].tval <= TV_SWORD)
946             cur_wgt += creature_ptr->inventory_list[INVEN_SUB_HAND].weight;
947         break;
948     }
949     case CLASS_PRIEST:
950     case CLASS_BARD:
951     case CLASS_TOURIST: {
952         if (creature_ptr->inventory_list[INVEN_MAIN_HAND].tval <= TV_SWORD)
953             cur_wgt += creature_ptr->inventory_list[INVEN_MAIN_HAND].weight * 2 / 3;
954         if (creature_ptr->inventory_list[INVEN_SUB_HAND].tval <= TV_SWORD)
955             cur_wgt += creature_ptr->inventory_list[INVEN_SUB_HAND].weight * 2 / 3;
956         break;
957     }
958     case CLASS_MINDCRAFTER:
959     case CLASS_BEASTMASTER:
960     case CLASS_MIRROR_MASTER: {
961         if (creature_ptr->inventory_list[INVEN_MAIN_HAND].tval <= TV_SWORD)
962             cur_wgt += creature_ptr->inventory_list[INVEN_MAIN_HAND].weight / 2;
963         if (creature_ptr->inventory_list[INVEN_SUB_HAND].tval <= TV_SWORD)
964             cur_wgt += creature_ptr->inventory_list[INVEN_SUB_HAND].weight / 2;
965         break;
966     }
967     case CLASS_ROGUE:
968     case CLASS_RANGER:
969     case CLASS_RED_MAGE:
970     case CLASS_WARRIOR_MAGE: {
971         if (creature_ptr->inventory_list[INVEN_MAIN_HAND].tval <= TV_SWORD)
972             cur_wgt += creature_ptr->inventory_list[INVEN_MAIN_HAND].weight / 3;
973         if (creature_ptr->inventory_list[INVEN_SUB_HAND].tval <= TV_SWORD)
974             cur_wgt += creature_ptr->inventory_list[INVEN_SUB_HAND].weight / 3;
975         break;
976     }
977     case CLASS_PALADIN:
978     case CLASS_CHAOS_WARRIOR: {
979         if (creature_ptr->inventory_list[INVEN_MAIN_HAND].tval <= TV_SWORD)
980             cur_wgt += creature_ptr->inventory_list[INVEN_MAIN_HAND].weight / 5;
981         if (creature_ptr->inventory_list[INVEN_SUB_HAND].tval <= TV_SWORD)
982             cur_wgt += creature_ptr->inventory_list[INVEN_SUB_HAND].weight / 5;
983         break;
984     }
985     default: {
986         break;
987     }
988     }
989
990     int max_wgt = mp_ptr->spell_weight;
991     if ((cur_wgt - max_wgt) > 0) {
992         creature_ptr->cumber_armor = TRUE;
993         switch (creature_ptr->pclass) {
994         case CLASS_MAGE:
995         case CLASS_HIGH_MAGE:
996         case CLASS_BLUE_MAGE:
997         case CLASS_ELEMENTALIST: {
998             msp -= msp * (cur_wgt - max_wgt) / 600;
999             break;
1000         }
1001         case CLASS_PRIEST:
1002         case CLASS_MINDCRAFTER:
1003         case CLASS_BEASTMASTER:
1004         case CLASS_BARD:
1005         case CLASS_FORCETRAINER:
1006         case CLASS_TOURIST:
1007         case CLASS_MIRROR_MASTER: {
1008             msp -= msp * (cur_wgt - max_wgt) / 800;
1009             break;
1010         }
1011         case CLASS_SORCERER: {
1012             msp -= msp * (cur_wgt - max_wgt) / 900;
1013             break;
1014         }
1015         case CLASS_ROGUE:
1016         case CLASS_RANGER:
1017         case CLASS_MONK:
1018         case CLASS_RED_MAGE: {
1019             msp -= msp * (cur_wgt - max_wgt) / 1000;
1020             break;
1021         }
1022         case CLASS_PALADIN:
1023         case CLASS_CHAOS_WARRIOR:
1024         case CLASS_WARRIOR_MAGE: {
1025             msp -= msp * (cur_wgt - max_wgt) / 1200;
1026             break;
1027         }
1028         case CLASS_SAMURAI: {
1029             creature_ptr->cumber_armor = FALSE;
1030             break;
1031         }
1032         default: {
1033             msp -= msp * (cur_wgt - max_wgt) / 800;
1034             break;
1035         }
1036         }
1037     }
1038
1039     if (msp < 0)
1040         msp = 0;
1041
1042     if (creature_ptr->msp != msp) {
1043         if ((creature_ptr->csp >= msp) && (creature_ptr->pclass != CLASS_SAMURAI)) {
1044             creature_ptr->csp = msp;
1045             creature_ptr->csp_frac = 0;
1046         }
1047
1048 #ifdef JP
1049         if (creature_ptr->level_up_message && (msp > creature_ptr->msp)) {
1050             msg_format("最大マジック・ポイントが %d 増加した!", (msp - creature_ptr->msp));
1051         }
1052 #endif
1053         creature_ptr->msp = msp;
1054         set_bits(creature_ptr->redraw, PR_MANA);
1055         set_bits(creature_ptr->window_flags, (PW_PLAYER | PW_SPELL));
1056     }
1057
1058     if (current_world_ptr->character_xtra)
1059         return;
1060
1061     if (creature_ptr->old_cumber_glove != creature_ptr->cumber_glove) {
1062         if (creature_ptr->cumber_glove)
1063             msg_print(_("手が覆われて呪文が唱えにくい感じがする。", "Your covered hands feel unsuitable for spellcasting."));
1064         else
1065             msg_print(_("この手の状態なら、ぐっと呪文が唱えやすい感じだ。", "Your hands feel more suitable for spellcasting."));
1066
1067         creature_ptr->old_cumber_glove = creature_ptr->cumber_glove;
1068     }
1069
1070     if (creature_ptr->old_cumber_armor == creature_ptr->cumber_armor)
1071         return;
1072
1073     if (creature_ptr->cumber_armor)
1074         msg_print(_("装備の重さで動きが鈍くなってしまっている。", "The weight of your equipment encumbers your movement."));
1075     else
1076         msg_print(_("ぐっと楽に体を動かせるようになった。", "You feel able to move more freely."));
1077
1078     creature_ptr->old_cumber_armor = creature_ptr->cumber_armor;
1079 }
1080
1081 /*!
1082  * @brief 装備中の射撃武器の威力倍率を返す /
1083  * calcurate the fire rate of target object
1084  * @param o_ptr 計算する射撃武器のアイテム情報参照ポインタ
1085  * @return 射撃倍率の値(100で1.00倍)
1086  */
1087 s16b calc_num_fire(player_type *creature_ptr, object_type *o_ptr)
1088 {
1089     int extra_shots = 0;
1090     BIT_FLAGS flgs[TR_FLAG_SIZE];
1091
1092     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
1093         object_type *q_ptr;
1094         q_ptr = &creature_ptr->inventory_list[i];
1095         if (!q_ptr->k_idx)
1096             continue;
1097
1098         if (i == INVEN_BOW)
1099             continue;
1100
1101         object_flags(creature_ptr, q_ptr, flgs);
1102         if (has_flag(flgs, TR_XTRA_SHOTS))
1103             extra_shots++;
1104     }
1105
1106     object_flags(creature_ptr, o_ptr, flgs);
1107     if (has_flag(flgs, TR_XTRA_SHOTS))
1108         extra_shots++;
1109
1110     int num = 0;
1111     if (o_ptr->k_idx == 0 || is_heavy_shoot(creature_ptr, o_ptr))
1112         return (s16b)num;
1113
1114     num = 100;
1115     num += (extra_shots * 100);
1116
1117     tval_type tval_ammo = static_cast<tval_type>(bow_tval_ammo(o_ptr));
1118     if ((creature_ptr->pclass == CLASS_RANGER) && (tval_ammo == TV_ARROW)) {
1119         num += (creature_ptr->lev * 4);
1120     }
1121
1122     if ((creature_ptr->pclass == CLASS_CAVALRY) && (tval_ammo == TV_ARROW)) {
1123         num += (creature_ptr->lev * 3);
1124     }
1125
1126     if (creature_ptr->pclass == CLASS_ARCHER) {
1127         if (tval_ammo == TV_ARROW)
1128             num += ((creature_ptr->lev * 5) + 50);
1129         else if ((tval_ammo == TV_BOLT) || (tval_ammo == TV_SHOT))
1130             num += (creature_ptr->lev * 4);
1131     }
1132
1133     if (creature_ptr->pclass == CLASS_WARRIOR && (tval_ammo <= TV_BOLT) && (tval_ammo >= TV_SHOT)) {
1134         num += (creature_ptr->lev * 2);
1135     }
1136
1137     if ((creature_ptr->pclass == CLASS_ROGUE) && (tval_ammo == TV_SHOT)) {
1138         num += (creature_ptr->lev * 4);
1139     }
1140
1141     return (s16b)num;
1142 }
1143
1144 /*!
1145  * @brief 解除能力計算
1146  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1147  * @return 解除能力
1148  * @details
1149  * * 種族/職業/性格による加算
1150  * * 職業と性格とレベルによる追加加算
1151  * * 器用さに応じたadj_dex_disテーブルによる加算
1152  * * 知力に応じたadj_int_disテーブルによる加算
1153  */
1154 static ACTION_SKILL_POWER calc_disarming(player_type *creature_ptr)
1155 {
1156     ACTION_SKILL_POWER pow;
1157     const player_race *tmp_rp_ptr;
1158
1159     if (creature_ptr->mimic_form)
1160         tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
1161     else
1162         tmp_rp_ptr = &race_info[creature_ptr->prace];
1163     const player_class *c_ptr = &class_info[creature_ptr->pclass];
1164     const player_personality *a_ptr = &personality_info[creature_ptr->pseikaku];
1165
1166     pow = tmp_rp_ptr->r_dis + c_ptr->c_dis + a_ptr->a_dis;
1167     pow += ((cp_ptr->x_dis * creature_ptr->lev / 10) + (ap_ptr->a_dis * creature_ptr->lev / 50));
1168     pow += adj_dex_dis[creature_ptr->stat_index[A_DEX]];
1169     pow += adj_int_dis[creature_ptr->stat_index[A_INT]];
1170     return pow;
1171 }
1172
1173 /*!
1174  * @brief 魔法防御計算
1175  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1176  * @return 魔法防御
1177  * @details
1178  * * 種族/職業/性格による加算
1179  * * 職業と性格とレベルによる追加加算
1180  * * 装備による加算(TR_MAGIC_MASTERYを持っていたら+pval*8)
1181  * * 知力に応じたadj_int_devテーブルによる加算
1182  * * 狂戦士化による減算(-20)
1183  */
1184 static ACTION_SKILL_POWER calc_device_ability(player_type *creature_ptr)
1185 {
1186     ACTION_SKILL_POWER pow;
1187     const player_race *tmp_rp_ptr;
1188
1189     if (creature_ptr->mimic_form)
1190         tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
1191     else
1192         tmp_rp_ptr = &race_info[creature_ptr->prace];
1193     const player_class *c_ptr = &class_info[creature_ptr->pclass];
1194     const player_personality *a_ptr = &personality_info[creature_ptr->pseikaku];
1195
1196     pow = tmp_rp_ptr->r_dev + c_ptr->c_dev + a_ptr->a_dev;
1197     pow += ((c_ptr->x_dev * creature_ptr->lev / 10) + (ap_ptr->a_dev * creature_ptr->lev / 50));
1198
1199     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
1200         object_type *o_ptr;
1201         BIT_FLAGS flgs[TR_FLAG_SIZE];
1202         o_ptr = &creature_ptr->inventory_list[i];
1203         if (!o_ptr->k_idx)
1204             continue;
1205         object_flags(creature_ptr, o_ptr, flgs);
1206         if (has_flag(flgs, TR_MAGIC_MASTERY))
1207             pow += 8 * o_ptr->pval;
1208     }
1209
1210     pow += adj_int_dev[creature_ptr->stat_index[A_INT]];
1211
1212     if (is_shero(creature_ptr)) {
1213         pow -= 20;
1214     }
1215     return pow;
1216 }
1217
1218 /*!
1219  * @brief 魔法防御計算
1220  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1221  * @return 魔法防御
1222  * @details
1223  * * 種族/職業/性格による加算
1224  * * 職業と性格とレベルによる追加加算
1225  * * 変異MUT3_MAGIC_RESによる加算(15 + レベル / 5)
1226  * * 呪力耐性の装備による加算(30)
1227  * * 祝福された装備による加算(5 + レベル / 10)
1228  * * 賢さによるadj_wis_savテーブル加算
1229  * * 狂戦士化による減算(-30)
1230  * * 反魔法持ちで大なり上書き(90+レベル未満ならその値に上書き)
1231  * * クターのつぶれ状態なら(10に上書き)
1232  * * 生命の「究極の耐性」や regist_magic,magicdef持ちなら大なり上書き(95+レベル未満ならその値に上書き)
1233  * * 呪いのdown_savingがかかっているなら半減
1234  */
1235 static ACTION_SKILL_POWER calc_saving_throw(player_type *creature_ptr)
1236 {
1237     ACTION_SKILL_POWER pow;
1238     const player_race *tmp_rp_ptr;
1239
1240     if (creature_ptr->mimic_form)
1241         tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
1242     else
1243         tmp_rp_ptr = &race_info[creature_ptr->prace];
1244     const player_class *c_ptr = &class_info[creature_ptr->pclass];
1245     const player_personality *a_ptr = &personality_info[creature_ptr->pseikaku];
1246
1247     pow = tmp_rp_ptr->r_sav + c_ptr->c_sav + a_ptr->a_sav;
1248     pow += ((cp_ptr->x_sav * creature_ptr->lev / 10) + (ap_ptr->a_sav * creature_ptr->lev / 50));
1249
1250     if (creature_ptr->muta.has(MUTA::MAGIC_RES))
1251         pow += (15 + (creature_ptr->lev / 5));
1252
1253     if (has_resist_curse(creature_ptr))
1254         pow += 30;
1255
1256     if (creature_ptr->blessed)
1257         pow += 6 + (creature_ptr->lev - 1) / 10;
1258
1259     pow += adj_wis_sav[creature_ptr->stat_index[A_WIS]];
1260
1261     if (is_shero(creature_ptr))
1262         pow -= 30;
1263
1264     if (creature_ptr->anti_magic && (pow < (90 + creature_ptr->lev)))
1265         pow = 90 + creature_ptr->lev;
1266
1267     if (creature_ptr->tsubureru)
1268         pow = 10;
1269
1270     if ((creature_ptr->ult_res || creature_ptr->resist_magic || creature_ptr->magicdef) && (pow < (95 + creature_ptr->lev)))
1271         pow = 95 + creature_ptr->lev;
1272
1273     if (creature_ptr->down_saving)
1274         pow /= 2;
1275
1276     return pow;
1277 }
1278
1279 /*!
1280  * @brief 探索深度計算
1281  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1282  * @return 探索深度
1283  * @details
1284  * * 種族/職業/性格による加算
1285  * * 職業とレベルによる追加加算
1286  * * 各装備による加算(TR_SEARCHがあれば+pval*5)
1287  * * 狂戦士化による減算(-15)
1288  * * 変異(MUT3_XTRA_EYES)による加算(+15)
1289  */
1290 static ACTION_SKILL_POWER calc_search(player_type *creature_ptr)
1291 {
1292     ACTION_SKILL_POWER pow;
1293     const player_race *tmp_rp_ptr;
1294
1295     if (creature_ptr->mimic_form)
1296         tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
1297     else
1298         tmp_rp_ptr = &race_info[creature_ptr->prace];
1299     const player_class *c_ptr = &class_info[creature_ptr->pclass];
1300     const player_personality *a_ptr = &personality_info[creature_ptr->pseikaku];
1301
1302     pow = tmp_rp_ptr->r_srh + c_ptr->c_srh + a_ptr->a_srh;
1303     pow += (c_ptr->x_srh * creature_ptr->lev / 10);
1304
1305     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
1306         object_type *o_ptr;
1307         BIT_FLAGS flgs[TR_FLAG_SIZE];
1308         o_ptr = &creature_ptr->inventory_list[i];
1309         if (!o_ptr->k_idx)
1310             continue;
1311         object_flags(creature_ptr, o_ptr, flgs);
1312         if (has_flag(flgs, TR_SEARCH))
1313             pow += (o_ptr->pval * 5);
1314     }
1315
1316     if (creature_ptr->muta.has(MUTA::XTRA_EYES)) {
1317         pow += 15;
1318     }
1319
1320     if (is_shero(creature_ptr)) {
1321         pow -= 15;
1322     }
1323
1324     return pow;
1325 }
1326
1327 /*!
1328  * @brief 探索頻度計算
1329  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1330  * @return 探索頻度
1331  * @details
1332  * * 種族/職業/性格による加算
1333  * * 職業とレベルによる追加加算
1334  * * 各装備による加算(TR_SEARCHがあれば+pval*5)
1335  * * 狂戦士化による減算(-15)
1336  * * 変異(MUT3_XTRA_EYES)による加算(+15)
1337  */
1338 static ACTION_SKILL_POWER calc_search_freq(player_type *creature_ptr)
1339 {
1340     ACTION_SKILL_POWER pow;
1341     const player_race *tmp_rp_ptr;
1342
1343     if (creature_ptr->mimic_form)
1344         tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
1345     else
1346         tmp_rp_ptr = &race_info[creature_ptr->prace];
1347     const player_class *c_ptr = &class_info[creature_ptr->pclass];
1348     const player_personality *a_ptr = &personality_info[creature_ptr->pseikaku];
1349
1350     pow = tmp_rp_ptr->r_fos + c_ptr->c_fos + a_ptr->a_fos;
1351     pow += (c_ptr->x_fos * creature_ptr->lev / 10);
1352
1353     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
1354         object_type *o_ptr;
1355         BIT_FLAGS flgs[TR_FLAG_SIZE];
1356         o_ptr = &creature_ptr->inventory_list[i];
1357         if (!o_ptr->k_idx)
1358             continue;
1359         object_flags(creature_ptr, o_ptr, flgs);
1360         if (has_flag(flgs, TR_SEARCH))
1361             pow += (o_ptr->pval * 5);
1362     }
1363
1364     if (is_shero(creature_ptr)) {
1365         pow -= 15;
1366     }
1367
1368     if (creature_ptr->muta.has(MUTA::XTRA_EYES)) {
1369         pow += 15;
1370     }
1371
1372     return pow;
1373 }
1374
1375 /*!
1376  * @brief 打撃命中能力計算
1377  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1378  * @return 打撃命中能力
1379  * @details
1380  * * 種族/職業/性格による加算とレベルによる追加加算
1381  */
1382 static ACTION_SKILL_POWER calc_to_hit_melee(player_type *creature_ptr)
1383 {
1384     ACTION_SKILL_POWER pow;
1385     const player_race *tmp_rp_ptr;
1386     const player_class *c_ptr = &class_info[creature_ptr->pclass];
1387     const player_personality *a_ptr = &personality_info[creature_ptr->pseikaku];
1388
1389     if (creature_ptr->mimic_form)
1390         tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
1391     else
1392         tmp_rp_ptr = &race_info[creature_ptr->prace];
1393
1394     pow = tmp_rp_ptr->r_thn + c_ptr->c_thn + a_ptr->a_thn;
1395     pow += ((c_ptr->x_thn * creature_ptr->lev / 10) + (a_ptr->a_thn * creature_ptr->lev / 50));
1396     return pow;
1397 }
1398
1399 /*!
1400  * @brief 射撃命中能力計算
1401  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1402  * @return 射撃命中能力
1403  * @details
1404  * * 種族/職業/性格による加算とレベルによる追加加算
1405  */
1406 static ACTION_SKILL_POWER calc_to_hit_shoot(player_type *creature_ptr)
1407 {
1408     ACTION_SKILL_POWER pow;
1409     const player_race *tmp_rp_ptr;
1410     const player_class *c_ptr = &class_info[creature_ptr->pclass];
1411     const player_personality *a_ptr = &personality_info[creature_ptr->pseikaku];
1412
1413     if (creature_ptr->mimic_form)
1414         tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
1415     else
1416         tmp_rp_ptr = &race_info[creature_ptr->prace];
1417
1418     pow = tmp_rp_ptr->r_thb + c_ptr->c_thb + a_ptr->a_thb;
1419     pow += ((c_ptr->x_thb * creature_ptr->lev / 10) + (a_ptr->a_thb * creature_ptr->lev / 50));
1420     return pow;
1421 }
1422
1423 /*!
1424  * @brief 投擲命中能力計算
1425  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1426  * @return 投擲命中能力
1427  * @details
1428  * * 種族/職業/性格による加算とレベルによる追加加算
1429  * * 狂戦士による減算(-20)
1430  */
1431 static ACTION_SKILL_POWER calc_to_hit_throw(player_type *creature_ptr)
1432 {
1433     ACTION_SKILL_POWER pow;
1434     const player_race *tmp_rp_ptr;
1435     const player_class *c_ptr = &class_info[creature_ptr->pclass];
1436     const player_personality *a_ptr = &personality_info[creature_ptr->pseikaku];
1437
1438     if (creature_ptr->mimic_form)
1439         tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
1440     else
1441         tmp_rp_ptr = &race_info[creature_ptr->prace];
1442
1443     pow = tmp_rp_ptr->r_thb + c_ptr->c_thb + a_ptr->a_thb;
1444     pow += ((c_ptr->x_thb * creature_ptr->lev / 10) + (a_ptr->a_thb * creature_ptr->lev / 50));
1445
1446     if (is_shero(creature_ptr)) {
1447         pow -= 20;
1448     }
1449
1450     return pow;
1451 }
1452
1453 /*!
1454  * @brief 掘削能力計算
1455  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1456  * @return 掘削能力値
1457  * @details
1458  * * エントが素手の場合のプラス修正
1459  * * 狂戦士化時のプラス修正
1460  * * 腕力によるテーブルプラス修正
1461  * * 職業狂戦士のプラス修正
1462  * * 装備の特性によるプラス修正
1463  * * 武器重量によるプラス修正
1464  * * 最終算出値に1を保証
1465  */
1466 static ACTION_SKILL_POWER calc_skill_dig(player_type *creature_ptr)
1467 {
1468     object_type *o_ptr;
1469     BIT_FLAGS flgs[TR_FLAG_SIZE];
1470
1471     ACTION_SKILL_POWER pow;
1472
1473     pow = 0;
1474
1475     if (!creature_ptr->mimic_form && creature_ptr->prace == RACE_ENT && !creature_ptr->inventory_list[INVEN_MAIN_HAND].k_idx) {
1476         pow += creature_ptr->lev * 10;
1477     }
1478
1479     if (is_shero(creature_ptr))
1480         pow += 30;
1481
1482     pow += adj_str_dig[creature_ptr->stat_index[A_STR]];
1483
1484     if (creature_ptr->pclass == CLASS_BERSERKER)
1485         pow += (100 + creature_ptr->lev * 8);
1486
1487     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
1488         o_ptr = &creature_ptr->inventory_list[i];
1489         if (!o_ptr->k_idx)
1490             continue;
1491         object_flags(creature_ptr, o_ptr, flgs);
1492         if (has_flag(flgs, TR_TUNNEL))
1493             pow += (o_ptr->pval * 20);
1494     }
1495
1496     for (int i = 0; i < 2; i++) {
1497         o_ptr = &creature_ptr->inventory_list[INVEN_MAIN_HAND + i];
1498         if (has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i) && !creature_ptr->heavy_wield[i]) {
1499             pow += (o_ptr->weight / 10);
1500         }
1501     }
1502
1503     if (is_shero(creature_ptr)) {
1504         pow += 30;
1505     }
1506
1507     if (pow < 1)
1508         pow = 1;
1509
1510     return pow;
1511 }
1512
1513 static bool is_martial_arts_mode(player_type *creature_ptr)
1514 {
1515     return ((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER) || (creature_ptr->pclass == CLASS_BERSERKER))
1516         && (any_bits(empty_hands(creature_ptr, TRUE), EMPTY_HAND_MAIN)) && !can_attack_with_sub_hand(creature_ptr);
1517 }
1518
1519 static bool is_heavy_wield(player_type *creature_ptr, int i)
1520 {
1521     const object_type *o_ptr = &creature_ptr->inventory_list[INVEN_MAIN_HAND + i];
1522
1523     return has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i) && (calc_weapon_weight_limit(creature_ptr) < o_ptr->weight / 10);
1524 }
1525
1526 static s16b calc_num_blow(player_type *creature_ptr, int i)
1527 {
1528     object_type *o_ptr;
1529     BIT_FLAGS flgs[TR_FLAG_SIZE];
1530     s16b num_blow = 1;
1531
1532     o_ptr = &creature_ptr->inventory_list[INVEN_MAIN_HAND + i];
1533     object_flags(creature_ptr, o_ptr, flgs);
1534     if (has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i)) {
1535         if (o_ptr->k_idx && !creature_ptr->heavy_wield[i]) {
1536             int str_index, dex_index;
1537             int num = 0, wgt = 0, mul = 0, div = 0;
1538
1539             num = class_info[creature_ptr->pclass].num;
1540             wgt = class_info[creature_ptr->pclass].wgt;
1541             mul = class_info[creature_ptr->pclass].mul;
1542
1543             if (creature_ptr->pclass == CLASS_CAVALRY && (creature_ptr->riding) && (has_flag(flgs, TR_RIDING))) {
1544                 num = 5;
1545                 wgt = 70;
1546                 mul = 4;
1547             }
1548
1549             if (hex_spelling(creature_ptr, HEX_XTRA_MIGHT) || hex_spelling(creature_ptr, HEX_BUILDING)) {
1550                 num++;
1551                 wgt /= 2;
1552                 mul += 2;
1553             }
1554
1555             div = ((o_ptr->weight < wgt) ? wgt : o_ptr->weight);
1556             str_index = (adj_str_blow[creature_ptr->stat_index[A_STR]] * mul / div);
1557
1558             if (has_two_handed_weapons(creature_ptr) && !has_disable_two_handed_bonus(creature_ptr, 0))
1559                 str_index++;
1560             if (creature_ptr->pclass == CLASS_NINJA)
1561                 str_index = MAX(0, str_index - 1);
1562             if (str_index > 11)
1563                 str_index = 11;
1564
1565             dex_index = (adj_dex_blow[creature_ptr->stat_index[A_DEX]]);
1566             if (dex_index > 11)
1567                 dex_index = 11;
1568
1569             num_blow = blows_table[str_index][dex_index];
1570             if (num_blow > num)
1571                 num_blow = (s16b)num;
1572
1573             num_blow += (s16b)creature_ptr->extra_blows[i];
1574             if (creature_ptr->pclass == CLASS_WARRIOR)
1575                 num_blow += (creature_ptr->lev / 40);
1576             else if (creature_ptr->pclass == CLASS_BERSERKER)
1577                 num_blow += (creature_ptr->lev / 23);
1578             else if ((creature_ptr->pclass == CLASS_ROGUE) && (o_ptr->weight < 50) && (creature_ptr->stat_index[A_DEX] >= 30))
1579                 num_blow++;
1580
1581             if (any_bits(creature_ptr->special_defense, KATA_FUUJIN))
1582                 num_blow -= 1;
1583
1584             if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE))
1585                 num_blow = 1;
1586
1587             if (num_blow < 1)
1588                 num_blow = 1;
1589         }
1590     }
1591
1592     if (i != 0)
1593         return num_blow;
1594     /* Different calculation for monks with empty hands */
1595     if (is_martial_arts_mode(creature_ptr)) {
1596         int blow_base = creature_ptr->lev + adj_dex_blow[creature_ptr->stat_index[A_DEX]];
1597         num_blow = 0;
1598
1599         if (creature_ptr->pclass == CLASS_FORCETRAINER) {
1600             if (blow_base > 18)
1601                 num_blow++;
1602             if (blow_base > 31)
1603                 num_blow++;
1604             if (blow_base > 44)
1605                 num_blow++;
1606             if (blow_base > 58)
1607                 num_blow++;
1608         } else {
1609             if (blow_base > 12)
1610                 num_blow++;
1611             if (blow_base > 22)
1612                 num_blow++;
1613             if (blow_base > 31)
1614                 num_blow++;
1615             if (blow_base > 39)
1616                 num_blow++;
1617             if (blow_base > 46)
1618                 num_blow++;
1619             if (blow_base > 53)
1620                 num_blow++;
1621             if (blow_base > 59)
1622                 num_blow++;
1623         }
1624
1625         if (heavy_armor(creature_ptr) && (creature_ptr->pclass != CLASS_BERSERKER))
1626             num_blow /= 2;
1627
1628         if (any_bits(creature_ptr->special_defense, KAMAE_GENBU)) {
1629             num_blow -= 2;
1630             if ((creature_ptr->pclass == CLASS_MONK) && (creature_ptr->lev > 42))
1631                 num_blow--;
1632             if (num_blow < 0)
1633                 num_blow = 0;
1634         } else if (any_bits(creature_ptr->special_defense, KAMAE_SUZAKU)) {
1635             num_blow /= 2;
1636         }
1637
1638         num_blow += 1 + creature_ptr->extra_blows[0];
1639     }
1640
1641     if (has_not_ninja_weapon(creature_ptr, i)) {
1642         num_blow /= 2;
1643         if (num_blow < 1)
1644             num_blow = 1;
1645     }
1646
1647     return num_blow;
1648 }
1649
1650 /*!
1651  * @brief 魔法失敗値計算
1652  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1653  * @return 魔法失敗値
1654  * @details
1655  * * 性格なまけものなら加算(+10)
1656  * * 性格きれものなら減算(-3)
1657  * * 性格ちからじまんとがまんづよいなら加算(+1)
1658  * * 性格チャージマンなら加算(+5)
1659  * * 装備品にTRC_HARD_SPELLがあるなら加算(軽い呪いなら+3/重い呪いなら+10)
1660  */
1661 static s16b calc_to_magic_chance(player_type *creature_ptr)
1662 {
1663     s16b chance = 0;
1664
1665     if (creature_ptr->pseikaku == PERSONALITY_LAZY)
1666         chance += 10;
1667     if (creature_ptr->pseikaku == PERSONALITY_SHREWD)
1668         chance -= 3;
1669     if ((creature_ptr->pseikaku == PERSONALITY_PATIENT) || (creature_ptr->pseikaku == PERSONALITY_MIGHTY))
1670         chance++;
1671     if (creature_ptr->pseikaku == PERSONALITY_CHARGEMAN)
1672         chance += 5;
1673
1674     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
1675         object_type *o_ptr;
1676         BIT_FLAGS flgs[TR_FLAG_SIZE];
1677         o_ptr = &creature_ptr->inventory_list[i];
1678         if (!o_ptr->k_idx)
1679             continue;
1680         object_flags(creature_ptr, o_ptr, flgs);
1681         if (any_bits(o_ptr->curse_flags, TRC_HARD_SPELL)) {
1682             if (any_bits(o_ptr->curse_flags, TRC_HEAVY_CURSE)) {
1683                 chance += 10;
1684             } else {
1685                 chance += 3;
1686             }
1687         }
1688     }
1689     return chance;
1690 }
1691
1692 static ARMOUR_CLASS calc_base_ac(player_type *creature_ptr)
1693 {
1694     ARMOUR_CLASS ac = 0;
1695     if (creature_ptr->yoiyami)
1696         return 0;
1697
1698     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
1699         object_type *o_ptr;
1700         o_ptr = &creature_ptr->inventory_list[i];
1701         if (!o_ptr->k_idx)
1702             continue;
1703         ac += o_ptr->ac;
1704     }
1705
1706     if (object_is_armour(creature_ptr, &creature_ptr->inventory_list[INVEN_MAIN_HAND])
1707         || object_is_armour(creature_ptr, &creature_ptr->inventory_list[INVEN_SUB_HAND])) {
1708         ac += creature_ptr->skill_exp[GINOU_SHIELD] * (1 + creature_ptr->lev / 22) / 2000;
1709     }
1710
1711     return ac;
1712 }
1713
1714 static ARMOUR_CLASS calc_to_ac(player_type *creature_ptr, bool is_real_value)
1715 {
1716     ARMOUR_CLASS ac = 0;
1717     BIT_FLAGS flags[TR_FLAG_SIZE];
1718     if (creature_ptr->yoiyami)
1719         return 0;
1720
1721     ac += ((int)(adj_dex_ta[creature_ptr->stat_index[A_DEX]]) - 128);
1722
1723     if (creature_ptr->mimic_form) {
1724         switch (creature_ptr->mimic_form) {
1725         case MIMIC_DEMON:
1726             ac += 10;
1727             break;
1728         case MIMIC_DEMON_LORD:
1729             ac += 20;
1730             break;
1731         case MIMIC_VAMPIRE:
1732             ac += 10;
1733         }
1734     }
1735
1736     if (creature_ptr->pclass == CLASS_BERSERKER) {
1737         ac += 10 + creature_ptr->lev / 2;
1738     }
1739     if (creature_ptr->pclass == CLASS_SORCERER) {
1740         ac -= 50;
1741     }
1742
1743     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
1744         object_type *o_ptr;
1745         o_ptr = &creature_ptr->inventory_list[i];
1746         object_flags(creature_ptr, o_ptr, flags);
1747         if (!o_ptr->k_idx)
1748             continue;
1749         if (is_real_value || object_is_known(o_ptr))
1750             ac += o_ptr->to_a;
1751
1752         if (any_bits(o_ptr->curse_flags, TRC_LOW_AC)) {
1753             if (any_bits(o_ptr->curse_flags, TRC_HEAVY_CURSE)) {
1754                 if (is_real_value || object_is_fully_known(o_ptr))
1755                     ac -= 30;
1756             } else {
1757                 if (is_real_value || object_is_fully_known(o_ptr))
1758                     ac -= 10;
1759             }
1760         }
1761
1762         if ((i == INVEN_SUB_HAND) && has_flag(flags, TR_SUPPORTIVE)) {
1763             ac += 5;
1764         }
1765     }
1766
1767     if (is_specific_player_race(creature_ptr, RACE_GOLEM) || is_specific_player_race(creature_ptr, RACE_ANDROID)) {
1768         ac += 10 + (creature_ptr->lev * 2 / 5);
1769     }
1770
1771     if ((creature_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_QUICKTHORN) && (creature_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_TINYTHORN)) {
1772         ac += 10;
1773     }
1774
1775     if ((creature_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_MUSASI_KATANA)
1776         && (creature_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_MUSASI_WAKIZASI)) {
1777         ac += 10;
1778     }
1779
1780     if ((creature_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_ICINGDEATH) && (creature_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_TWINKLE)) {
1781         ac += 5;
1782     }
1783
1784     if (creature_ptr->muta.has(MUTA::WART_SKIN)) {
1785         ac += 5;
1786     }
1787
1788     if (creature_ptr->muta.has(MUTA::SCALES)) {
1789         ac += 10;
1790     }
1791
1792     if (creature_ptr->muta.has(MUTA::IRON_SKIN)) {
1793         ac += 25;
1794     }
1795
1796     if (((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER)) && !heavy_armor(creature_ptr)) {
1797         if (!(creature_ptr->inventory_list[INVEN_BODY].k_idx)) {
1798             ac += (creature_ptr->lev * 3) / 2;
1799         }
1800         if (!(creature_ptr->inventory_list[INVEN_OUTER].k_idx) && (creature_ptr->lev > 15)) {
1801             ac += ((creature_ptr->lev - 13) / 3);
1802         }
1803         if (!(creature_ptr->inventory_list[INVEN_SUB_HAND].k_idx) && (creature_ptr->lev > 10)) {
1804             ac += ((creature_ptr->lev - 8) / 3);
1805         }
1806         if (!(creature_ptr->inventory_list[INVEN_HEAD].k_idx) && (creature_ptr->lev > 4)) {
1807             ac += (creature_ptr->lev - 2) / 3;
1808         }
1809         if (!(creature_ptr->inventory_list[INVEN_ARMS].k_idx)) {
1810             ac += (creature_ptr->lev / 2);
1811         }
1812         if (!(creature_ptr->inventory_list[INVEN_FEET].k_idx)) {
1813             ac += (creature_ptr->lev / 3);
1814         }
1815     }
1816
1817     if (creature_ptr->realm1 == REALM_HEX) {
1818         if (hex_spelling(creature_ptr, HEX_ICE_ARMOR)) {
1819             ac += 30;
1820         }
1821
1822         for (int i = INVEN_MAIN_HAND; i <= INVEN_FEET; i++) {
1823             object_type *o_ptr = &creature_ptr->inventory_list[i];
1824             if (!o_ptr->k_idx)
1825                 continue;
1826             if (!object_is_armour(creature_ptr, o_ptr))
1827                 continue;
1828             if (!object_is_cursed(o_ptr))
1829                 continue;
1830             if (any_bits(o_ptr->curse_flags, TRC_CURSED))
1831                 ac += 5;
1832             if (any_bits(o_ptr->curse_flags, TRC_HEAVY_CURSE))
1833                 ac += 7;
1834             if (any_bits(o_ptr->curse_flags, TRC_PERMA_CURSE))
1835                 ac += 13;
1836         }
1837     }
1838
1839     if (any_bits(creature_ptr->special_defense, KAMAE_GENBU)) {
1840         ac += (creature_ptr->lev * creature_ptr->lev) / 50;
1841     } else if (any_bits(creature_ptr->special_defense, KAMAE_BYAKKO)) {
1842         ac -= 40;
1843     } else if (any_bits(creature_ptr->special_defense, KAMAE_SEIRYU)) {
1844         ac -= 50;
1845     } else if (any_bits(creature_ptr->special_defense, KATA_KOUKIJIN)) {
1846         ac -= 50;
1847     }
1848
1849     if (creature_ptr->ult_res || (any_bits(creature_ptr->special_defense, KATA_MUSOU))) {
1850         ac += 100;
1851     } else if (creature_ptr->tsubureru || creature_ptr->shield || creature_ptr->magicdef) {
1852         ac += 50;
1853     }
1854
1855     if (is_blessed(creature_ptr)) {
1856         ac += 5;
1857     }
1858
1859     if (is_shero(creature_ptr)) {
1860         ac -= 10;
1861     }
1862
1863     if (creature_ptr->pclass == CLASS_NINJA) {
1864         if ((!creature_ptr->inventory_list[INVEN_MAIN_HAND].k_idx || can_attack_with_main_hand(creature_ptr))
1865             && (!creature_ptr->inventory_list[INVEN_SUB_HAND].k_idx || can_attack_with_sub_hand(creature_ptr))) {
1866             ac += creature_ptr->lev / 2 + 5;
1867         }
1868     }
1869
1870     return ac;
1871 }
1872
1873 /*!
1874  * @brief 二刀流ペナルティ量計算
1875  * @param creature_ptr 計算するクリーチャーの参照ポインタ
1876  * @param slot ペナルティ量を計算する武器スロット
1877  * @return 二刀流ペナルティ量
1878  * @details
1879  * * 二刀流にしていなければ0
1880  * * 特別セットによる軽減
1881  * * EASY2_WEAPONによる軽減
1882  * * SUPPORTIVEを左に装備した場合の軽減
1883  * * 武蔵セットによる免除
1884  * * 竿状武器による増加
1885  */
1886 s16b calc_double_weapon_penalty(player_type *creature_ptr, INVENTORY_IDX slot)
1887 {
1888     int penalty = 0;
1889     BIT_FLAGS flags[TR_FLAG_SIZE];
1890
1891     if (has_melee_weapon(creature_ptr, INVEN_MAIN_HAND) && has_melee_weapon(creature_ptr, INVEN_SUB_HAND)) {
1892         object_flags(creature_ptr, &creature_ptr->inventory_list[INVEN_SUB_HAND], flags);
1893
1894         penalty = ((100 - creature_ptr->skill_exp[GINOU_NITOURYU] / 160) - (130 - creature_ptr->inventory_list[slot].weight) / 8);
1895         if (((creature_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_QUICKTHORN) && (creature_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_TINYTHORN))
1896             || ((creature_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_ICINGDEATH)
1897                 && (creature_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_TWINKLE))) {
1898             penalty = penalty / 2 - 5;
1899         }
1900
1901         for (unsigned int i = FLAG_CAUSE_INVEN_MAIN_HAND; i < FLAG_CAUSE_MAX; i <<= 1)
1902             if (penalty > 0 && any_bits(creature_ptr->easy_2weapon, i))
1903                 penalty /= 2;
1904
1905         if (has_flag(flags, TR_SUPPORTIVE))
1906             penalty = MAX(0, penalty - 10);
1907
1908         if ((creature_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_MUSASI_KATANA)
1909             && (creature_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_MUSASI_WAKIZASI)) {
1910             penalty = MIN(0, penalty);
1911         }
1912
1913         if (creature_ptr->inventory_list[slot].tval == TV_POLEARM)
1914             penalty += 10;
1915     }
1916     return (s16b)penalty;
1917 }
1918
1919 static bool is_riding_two_hands(player_type *creature_ptr)
1920 {
1921     if (!creature_ptr->riding) {
1922         return FALSE;
1923     }
1924
1925     if (has_two_handed_weapons(creature_ptr) || (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_NONE))
1926         return TRUE;
1927     else if (any_bits(creature_ptr->pet_extra_flags, PF_TWO_HANDS)) {
1928         switch (creature_ptr->pclass) {
1929         case CLASS_MONK:
1930         case CLASS_FORCETRAINER:
1931         case CLASS_BERSERKER:
1932             if ((empty_hands(creature_ptr, FALSE) != EMPTY_HAND_NONE) && !has_melee_weapon(creature_ptr, INVEN_MAIN_HAND)
1933                 && !has_melee_weapon(creature_ptr, INVEN_SUB_HAND))
1934                 return TRUE;
1935
1936         default:
1937             break;
1938         }
1939     }
1940
1941     return FALSE;
1942 }
1943
1944 static s16b calc_riding_bow_penalty(player_type *creature_ptr)
1945 {
1946     floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1947     if (!creature_ptr->riding)
1948         return 0;
1949
1950     s16b penalty = 0;
1951
1952     if ((creature_ptr->pclass == CLASS_BEASTMASTER) || (creature_ptr->pclass == CLASS_CAVALRY)) {
1953         if (creature_ptr->tval_ammo != TV_ARROW)
1954             penalty = 5;
1955     } else {
1956         penalty = r_info[floor_ptr->m_list[creature_ptr->riding].r_idx].level - creature_ptr->skill_exp[GINOU_RIDING] / 80;
1957         penalty += 30;
1958         if (penalty < 30)
1959             penalty = 30;
1960     }
1961
1962     if (creature_ptr->tval_ammo == TV_BOLT)
1963         penalty *= 2;
1964
1965     return penalty;
1966 }
1967
1968 void put_equipment_warning(player_type *creature_ptr)
1969 {
1970     bool heavy_shoot = is_heavy_shoot(creature_ptr, &creature_ptr->inventory_list[INVEN_BOW]);
1971     if (creature_ptr->old_heavy_shoot != heavy_shoot) {
1972         if (heavy_shoot) {
1973             msg_print(_("こんな重い弓を装備しているのは大変だ。", "You have trouble wielding such a heavy bow."));
1974         } else if (creature_ptr->inventory_list[INVEN_BOW].k_idx) {
1975             msg_print(_("この弓なら装備していても辛くない。", "You have no trouble wielding your bow."));
1976         } else {
1977             msg_print(_("重い弓を装備からはずして体が楽になった。", "You feel relieved to put down your heavy bow."));
1978         }
1979         creature_ptr->old_heavy_shoot = heavy_shoot;
1980     }
1981
1982     for (int i = 0; i < 2; i++) {
1983         if (creature_ptr->old_heavy_wield[i] != creature_ptr->heavy_wield[i]) {
1984             if (creature_ptr->heavy_wield[i]) {
1985                 msg_print(_("こんな重い武器を装備しているのは大変だ。", "You have trouble wielding such a heavy weapon."));
1986             } else if (has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i)) {
1987                 msg_print(_("これなら装備していても辛くない。", "You have no trouble wielding your weapon."));
1988             } else if (creature_ptr->heavy_wield[1 - i]) {
1989                 msg_print(_("まだ武器が重い。", "You still have trouble wielding a heavy weapon."));
1990             } else {
1991                 msg_print(_("重い武器を装備からはずして体が楽になった。", "You feel relieved to put down your heavy weapon."));
1992             }
1993
1994             creature_ptr->old_heavy_wield[i] = creature_ptr->heavy_wield[i];
1995         }
1996
1997         if (creature_ptr->old_riding_wield[i] != creature_ptr->riding_wield[i]) {
1998             if (creature_ptr->riding_wield[i]) {
1999                 msg_print(_("この武器は乗馬中に使うにはむかないようだ。", "This weapon is not suitable for use while riding."));
2000             } else if (!creature_ptr->riding) {
2001                 msg_print(_("この武器は徒歩で使いやすい。", "This weapon is suitable for use on foot."));
2002             } else if (has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i)) {
2003                 msg_print(_("これなら乗馬中にぴったりだ。", "This weapon is suitable for use while riding."));
2004             }
2005
2006             creature_ptr->old_riding_wield[i] = creature_ptr->riding_wield[i];
2007         }
2008
2009         if (creature_ptr->old_icky_wield[i] == creature_ptr->icky_wield[i])
2010             continue;
2011
2012         if (creature_ptr->icky_wield[i]) {
2013             msg_print(_("今の装備はどうも自分にふさわしくない気がする。", "You do not feel comfortable with your weapon."));
2014             if (current_world_ptr->is_loading_now) {
2015                 chg_virtue(creature_ptr, V_FAITH, -1);
2016             }
2017         } else if (has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i)) {
2018             msg_print(_("今の装備は自分にふさわしい気がする。", "You feel comfortable with your weapon."));
2019         } else {
2020             msg_print(_("装備をはずしたら随分と気が楽になった。", "You feel more comfortable after removing your weapon."));
2021         }
2022
2023         creature_ptr->old_icky_wield[i] = creature_ptr->icky_wield[i];
2024     }
2025
2026     if (creature_ptr->riding && (creature_ptr->old_riding_ryoute != creature_ptr->riding_ryoute)) {
2027         if (creature_ptr->riding_ryoute) {
2028 #ifdef JP
2029             msg_format("%s馬を操れない。", (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_NONE) ? "両手がふさがっていて" : "");
2030 #else
2031             msg_print("You are using both hand for fighting, and you can't control the pet you're riding.");
2032 #endif
2033         } else {
2034 #ifdef JP
2035             msg_format("%s馬を操れるようになった。", (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_NONE) ? "手が空いて" : "");
2036 #else
2037             msg_print("You began to control the pet you're riding with one hand.");
2038 #endif
2039         }
2040
2041         creature_ptr->old_riding_ryoute = creature_ptr->riding_ryoute;
2042     }
2043
2044     if (((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER) || (creature_ptr->pclass == CLASS_NINJA))
2045         && (heavy_armor(creature_ptr) != creature_ptr->monk_notify_aux)) {
2046         if (heavy_armor(creature_ptr)) {
2047             msg_print(_("装備が重くてバランスを取れない。", "The weight of your armor disrupts your balance."));
2048             if (current_world_ptr->is_loading_now) {
2049                 chg_virtue(creature_ptr, V_HARMONY, -1);
2050             }
2051         } else {
2052             msg_print(_("バランスがとれるようになった。", "You regain your balance."));
2053         }
2054
2055         creature_ptr->monk_notify_aux = heavy_armor(creature_ptr);
2056     }
2057 }
2058
2059 static s16b calc_to_damage(player_type *creature_ptr, INVENTORY_IDX slot, bool is_real_value)
2060 {
2061     object_type *o_ptr = &creature_ptr->inventory_list[slot];
2062     BIT_FLAGS flgs[TR_FLAG_SIZE];
2063     object_flags(creature_ptr, o_ptr, flgs);
2064
2065     player_hand calc_hand = PLAYER_HAND_OTHER;
2066     if (slot == INVEN_MAIN_HAND)
2067         calc_hand = PLAYER_HAND_MAIN;
2068     if (slot == INVEN_SUB_HAND)
2069         calc_hand = PLAYER_HAND_SUB;
2070
2071     s16b damage = 0;
2072     damage += ((int)(adj_str_td[creature_ptr->stat_index[A_STR]]) - 128);
2073
2074     if (is_shero(creature_ptr)) {
2075         damage += 3 + (creature_ptr->lev / 5);
2076     }
2077
2078     if (creature_ptr->stun > 50) {
2079         damage -= 20;
2080     } else if (creature_ptr->stun) {
2081         damage -= 5;
2082     }
2083
2084     if ((creature_ptr->pclass == CLASS_PRIEST) && (!(has_flag(flgs, TR_BLESSED))) && ((o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM))) {
2085         damage -= 2;
2086     } else if (creature_ptr->pclass == CLASS_BERSERKER) {
2087         damage += creature_ptr->lev / 6;
2088         if (((calc_hand == PLAYER_HAND_MAIN) && !can_attack_with_sub_hand(creature_ptr)) || has_two_handed_weapons(creature_ptr)) {
2089             damage += creature_ptr->lev / 6;
2090         }
2091     } else if (creature_ptr->pclass == CLASS_SORCERER) {
2092         if (!((o_ptr->tval == TV_HAFTED) && ((o_ptr->sval == SV_WIZSTAFF) || (o_ptr->sval == SV_NAMAKE_HAMMER)))) {
2093             damage -= 200;
2094         } else {
2095             damage -= 10;
2096         }
2097     } else if (creature_ptr->pclass == CLASS_FORCETRAINER) {
2098         // 練気術師は格闘ダメージに (気)/5 の修正を得る。
2099         if (is_martial_arts_mode(creature_ptr) && calc_hand == PLAYER_HAND_MAIN) {
2100             damage += get_current_ki(creature_ptr) / 5;
2101         }
2102     }
2103
2104     if ((creature_ptr->realm1 == REALM_HEX) && object_is_cursed(o_ptr)) {
2105         if (hex_spelling(creature_ptr, HEX_RUNESWORD)) {
2106             if (any_bits(o_ptr->curse_flags, (TRC_CURSED))) {
2107                 damage += 5;
2108             }
2109             if (any_bits(o_ptr->curse_flags, (TRC_HEAVY_CURSE))) {
2110                 damage += 7;
2111             }
2112             if (any_bits(o_ptr->curse_flags, (TRC_PERMA_CURSE))) {
2113                 damage += 13;
2114             }
2115         }
2116     }
2117
2118     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
2119         int bonus_to_d = 0;
2120         o_ptr = &creature_ptr->inventory_list[i];
2121         if (!o_ptr->k_idx || o_ptr->tval == TV_CAPTURE || (i == INVEN_MAIN_HAND && has_melee_weapon(creature_ptr, i))
2122             || (i == INVEN_SUB_HAND && has_melee_weapon(creature_ptr, i)) || i == INVEN_BOW)
2123             continue;
2124
2125         if (!object_is_known(o_ptr) && !is_real_value)
2126             continue;
2127         bonus_to_d = o_ptr->to_d;
2128
2129         if (creature_ptr->pclass == CLASS_NINJA) {
2130             if (o_ptr->to_d > 0)
2131                 bonus_to_d = (o_ptr->to_d + 1) / 2;
2132         }
2133
2134         switch (player_melee_type(creature_ptr)) {
2135         case MELEE_TYPE_BAREHAND_TWO: /* fall through */
2136         case MELEE_TYPE_WEAPON_TWOHAND:
2137             if (calc_hand == main_attack_hand(creature_ptr))
2138                 damage += (s16b)bonus_to_d;
2139             break;
2140
2141         case MELEE_TYPE_BAREHAND_MAIN: /* fall through */
2142         case MELEE_TYPE_WEAPON_MAIN:
2143             if ((calc_hand == PLAYER_HAND_MAIN) && (i != INVEN_SUB_RING))
2144                 damage += (s16b)bonus_to_d;
2145             break;
2146
2147         case MELEE_TYPE_BAREHAND_SUB: /* fall through */
2148         case MELEE_TYPE_WEAPON_SUB:
2149             if ((calc_hand == PLAYER_HAND_SUB) && (i != INVEN_MAIN_RING))
2150                 damage += (s16b)bonus_to_d;
2151             break;
2152
2153         case MELEE_TYPE_WEAPON_DOUBLE:
2154             if (calc_hand == PLAYER_HAND_MAIN) {
2155                 if (i == INVEN_MAIN_RING) {
2156                     damage += (s16b)bonus_to_d;
2157                 } else if (i != INVEN_SUB_RING) {
2158                     damage += (bonus_to_d > 0) ? (bonus_to_d + 1) / 2 : bonus_to_d;
2159                 }
2160             }
2161             if (calc_hand == PLAYER_HAND_SUB) {
2162                 if (i == INVEN_SUB_RING) {
2163                     damage += (s16b)bonus_to_d;
2164                 } else if (i != INVEN_MAIN_RING) {
2165                     damage += (bonus_to_d > 0) ? bonus_to_d / 2 : bonus_to_d;
2166                 }
2167             }
2168             break;
2169
2170         case MELEE_TYPE_SHIELD_DOUBLE:
2171             break;
2172
2173         default:
2174             break;
2175         }
2176     }
2177
2178     if (main_attack_hand(creature_ptr) == calc_hand) {
2179         if ((is_martial_arts_mode(creature_ptr) && empty_hands(creature_ptr, FALSE) == (EMPTY_HAND_MAIN | EMPTY_HAND_SUB))
2180             || !has_disable_two_handed_bonus(creature_ptr, calc_hand)) {
2181             int bonus_to_d = 0;
2182             bonus_to_d = ((int)(adj_str_td[creature_ptr->stat_index[A_STR]]) - 128) / 2;
2183             damage += MAX(bonus_to_d, 1);
2184         }
2185     }
2186
2187     if (is_martial_arts_mode(creature_ptr) && (!heavy_armor(creature_ptr) || creature_ptr->pclass != CLASS_BERSERKER)) {
2188         damage += (creature_ptr->lev / 6);
2189     }
2190
2191     // 朱雀の構えをとっているとき、格闘ダメージに -(レベル)/6 の修正を得る。
2192     if (any_bits(creature_ptr->special_defense, KAMAE_SUZAKU)) {
2193         if (is_martial_arts_mode(creature_ptr) && calc_hand == PLAYER_HAND_MAIN) {
2194             damage -= (creature_ptr->lev / 6);
2195         }
2196     }
2197
2198     return damage;
2199 }
2200
2201 /*!
2202  * @brief 武器の命中修正を計算する。 / Calculate hit bonus from a wielded weapon.
2203  * @details
2204  * 'slot' MUST be INVEN_MAIN_HAND or INVEM_SUB_HAND.
2205  */
2206 static s16b calc_to_hit(player_type *creature_ptr, INVENTORY_IDX slot, bool is_real_value)
2207 {
2208     s16b hit = 0;
2209
2210     /* Base bonuses */
2211     hit += ((int)(adj_dex_th[creature_ptr->stat_index[A_DEX]]) - 128);
2212     hit += ((int)(adj_str_th[creature_ptr->stat_index[A_STR]]) - 128);
2213
2214     /* Temporary bonuses */
2215     if (is_blessed(creature_ptr)) {
2216         hit += 10;
2217     }
2218
2219     if (is_hero(creature_ptr)) {
2220         hit += 12;
2221     }
2222
2223     if (is_shero(creature_ptr)) {
2224         hit += 12;
2225     }
2226
2227     if (creature_ptr->stun > 50) {
2228         hit -= 20;
2229     } else if (creature_ptr->stun) {
2230         hit -= 5;
2231     }
2232
2233     player_hand calc_hand = PLAYER_HAND_OTHER;
2234     if (slot == INVEN_MAIN_HAND)
2235         calc_hand = PLAYER_HAND_MAIN;
2236     if (slot == INVEN_SUB_HAND)
2237         calc_hand = PLAYER_HAND_SUB;
2238
2239     /* Default hand bonuses */
2240     if (main_attack_hand(creature_ptr) == calc_hand) {
2241         switch (player_melee_type(creature_ptr)) {
2242         case MELEE_TYPE_BAREHAND_MAIN:
2243             if (creature_ptr->riding)
2244                 break;
2245             /* fall through */
2246         case MELEE_TYPE_BAREHAND_SUB:
2247             if (creature_ptr->riding)
2248                 break;
2249             /* fall through */
2250         case MELEE_TYPE_BAREHAND_TWO:
2251             hit += (creature_ptr->skill_exp[GINOU_SUDE] - WEAPON_EXP_BEGINNER) / 200;
2252             break;
2253
2254         default:
2255             break;
2256         }
2257
2258         if ((is_martial_arts_mode(creature_ptr) && empty_hands(creature_ptr, FALSE) == (EMPTY_HAND_MAIN | EMPTY_HAND_SUB))
2259             || !has_disable_two_handed_bonus(creature_ptr, calc_hand)) {
2260             int bonus_to_h = 0;
2261             bonus_to_h = ((int)(adj_str_th[creature_ptr->stat_index[A_STR]]) - 128) + ((int)(adj_dex_th[creature_ptr->stat_index[A_DEX]]) - 128);
2262             hit += MAX(bonus_to_h, 1);
2263         }
2264     }
2265
2266     /* Bonuses and penalties by weapon */
2267     if (has_melee_weapon(creature_ptr, slot)) {
2268         object_type *o_ptr = &creature_ptr->inventory_list[slot];
2269         BIT_FLAGS flgs[TR_FLAG_SIZE];
2270         object_flags(creature_ptr, o_ptr, flgs);
2271
2272         int tval = o_ptr->tval - TV_WEAPON_BEGIN;
2273         OBJECT_SUBTYPE_VALUE sval = o_ptr->sval;
2274
2275         /* Traind bonuses */
2276         hit += (creature_ptr->weapon_exp[tval][sval] - WEAPON_EXP_BEGINNER) / 200;
2277
2278         /* Weight penalty */
2279         if (calc_weapon_weight_limit(creature_ptr) < o_ptr->weight / 10) {
2280             hit += 2 * (calc_weapon_weight_limit(creature_ptr) - o_ptr->weight / 10);
2281         }
2282
2283         /* Low melee penalty */
2284         if ((object_is_fully_known(o_ptr) || is_real_value) && any_bits(o_ptr->curse_flags, TRC_LOW_MELEE)) {
2285             if (any_bits(o_ptr->curse_flags, TRC_HEAVY_CURSE)) {
2286                 hit -= 15;
2287             } else {
2288                 hit -= 5;
2289             }
2290         }
2291
2292         /* Riding bonus and penalty */
2293         if (creature_ptr->riding) {
2294             if ((o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE))) {
2295                 hit += 15;
2296             }
2297         }
2298
2299         if (creature_ptr->riding != 0 && !(o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE))
2300             && !has_flag(flgs, TR_RIDING)) {
2301             int penalty;
2302             if ((creature_ptr->pclass == CLASS_BEASTMASTER) || (creature_ptr->pclass == CLASS_CAVALRY)) {
2303                 penalty = 5;
2304             } else {
2305                 penalty = r_info[creature_ptr->current_floor_ptr->m_list[creature_ptr->riding].r_idx].level - creature_ptr->skill_exp[GINOU_RIDING] / 80;
2306                 penalty += 30;
2307                 if (penalty < 30)
2308                     penalty = 30;
2309             }
2310             hit -= (s16b)penalty;
2311         }
2312
2313         /* Class penalties */
2314         if ((creature_ptr->pclass == CLASS_PRIEST) && (!(has_flag(flgs, TR_BLESSED))) && ((o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM))) {
2315             hit -= 2;
2316         } else if (creature_ptr->pclass == CLASS_BERSERKER) {
2317             hit += creature_ptr->lev / 5;
2318             if (((calc_hand == PLAYER_HAND_MAIN) && !can_attack_with_sub_hand(creature_ptr)) || has_two_handed_weapons(creature_ptr)) {
2319                 hit += creature_ptr->lev / 5;
2320             }
2321         } else if (creature_ptr->pclass == CLASS_SORCERER) {
2322             if (!((o_ptr->tval == TV_HAFTED) && ((o_ptr->sval == SV_WIZSTAFF) || (o_ptr->sval == SV_NAMAKE_HAMMER)))) {
2323                 hit -= 200;
2324             } else {
2325                 hit -= 30;
2326             }
2327         }
2328
2329         if (has_not_ninja_weapon(creature_ptr, (int)calc_hand) || has_not_monk_weapon(creature_ptr, (int)calc_hand)) {
2330             hit -= 40;
2331         }
2332
2333         /* Hex realm bonuses */
2334         if ((creature_ptr->realm1 == REALM_HEX) && object_is_cursed(o_ptr)) {
2335             if (any_bits(o_ptr->curse_flags, (TRC_CURSED))) {
2336                 hit += 5;
2337             }
2338             if (any_bits(o_ptr->curse_flags, (TRC_HEAVY_CURSE))) {
2339                 hit += 7;
2340             }
2341             if (any_bits(o_ptr->curse_flags, (TRC_PERMA_CURSE))) {
2342                 hit += 13;
2343             }
2344             if (any_bits(o_ptr->curse_flags, (TRC_TY_CURSE))) {
2345                 hit += 5;
2346             }
2347         }
2348     }
2349
2350     /* Bonuses from inventory */
2351     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
2352         object_type *o_ptr = &creature_ptr->inventory_list[i];
2353
2354         /* Ignore empty hands, handed weapons, bows and capture balls */
2355         if (!o_ptr->k_idx || o_ptr->tval == TV_CAPTURE || (i == INVEN_MAIN_HAND && has_melee_weapon(creature_ptr, i))
2356             || (i == INVEN_SUB_HAND && has_melee_weapon(creature_ptr, i)) || i == INVEN_BOW)
2357             continue;
2358
2359         /* Fake value does not include unknown objects' value */
2360         if (!object_is_known(o_ptr) && !is_real_value)
2361             continue;
2362
2363         int bonus_to_h = o_ptr->to_h;
2364
2365         /* When wields only a weapon */
2366         if (creature_ptr->pclass == CLASS_NINJA) {
2367             if (o_ptr->to_h > 0)
2368                 bonus_to_h = (o_ptr->to_h + 1) / 2;
2369         }
2370
2371         switch (player_melee_type(creature_ptr)) {
2372         case MELEE_TYPE_BAREHAND_TWO: /* fall through */
2373         case MELEE_TYPE_WEAPON_TWOHAND:
2374             if (calc_hand == main_attack_hand(creature_ptr))
2375                 hit += (s16b)bonus_to_h;
2376             break;
2377
2378         case MELEE_TYPE_BAREHAND_MAIN: /* fall through */
2379         case MELEE_TYPE_WEAPON_MAIN:
2380             if ((calc_hand == PLAYER_HAND_MAIN) && (i != INVEN_SUB_RING))
2381                 hit += (s16b)bonus_to_h;
2382             break;
2383
2384         case MELEE_TYPE_BAREHAND_SUB: /* fall through */
2385         case MELEE_TYPE_WEAPON_SUB:
2386             if ((calc_hand == PLAYER_HAND_SUB) && (i != INVEN_MAIN_RING))
2387                 hit += (s16b)bonus_to_h;
2388             break;
2389
2390         case MELEE_TYPE_WEAPON_DOUBLE:
2391             if (calc_hand == PLAYER_HAND_MAIN) {
2392                 if (i == INVEN_MAIN_RING) {
2393                     hit += (s16b)bonus_to_h;
2394                 } else if (i != INVEN_SUB_RING) {
2395                     hit += (bonus_to_h > 0) ? (bonus_to_h + 1) / 2 : bonus_to_h;
2396                 }
2397             }
2398             if (calc_hand == PLAYER_HAND_SUB) {
2399                 if (i == INVEN_SUB_RING) {
2400                     hit += (s16b)bonus_to_h;
2401                 } else if (i != INVEN_MAIN_RING) {
2402                     hit += (bonus_to_h > 0) ? bonus_to_h / 2 : bonus_to_h;
2403                 }
2404             }
2405             break;
2406
2407         case MELEE_TYPE_SHIELD_DOUBLE:
2408             break;
2409
2410         default:
2411             break;
2412         }
2413     }
2414
2415     /* Martial arts bonus */
2416     if (is_martial_arts_mode(creature_ptr) && (!heavy_armor(creature_ptr) || creature_ptr->pclass != CLASS_BERSERKER)) {
2417         hit += (creature_ptr->lev / 3);
2418     }
2419
2420     /* Two handed combat penalty */
2421     hit -= calc_double_weapon_penalty(creature_ptr, slot);
2422
2423     // 朱雀の構えをとっているとき、格闘命中に -(レベル)/3 の修正を得る。
2424     if (any_bits(creature_ptr->special_defense, KAMAE_SUZAKU)) {
2425         if (is_martial_arts_mode(creature_ptr) && calc_hand == PLAYER_HAND_MAIN) {
2426             hit -= (creature_ptr->lev / 3);
2427         }
2428     }
2429
2430     return hit;
2431 }
2432
2433 static s16b calc_to_hit_bow(player_type *creature_ptr, bool is_real_value)
2434 {
2435     s16b pow = 0;
2436
2437     pow += ((int)(adj_dex_th[creature_ptr->stat_index[A_DEX]]) - 128);
2438     pow += ((int)(adj_str_th[creature_ptr->stat_index[A_STR]]) - 128);
2439
2440     {
2441         object_type *o_ptr;
2442         BIT_FLAGS flgs[TR_FLAG_SIZE];
2443         o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
2444         if (o_ptr->k_idx) {
2445             object_flags(creature_ptr, o_ptr, flgs);
2446
2447             if (any_bits(o_ptr->curse_flags, TRC_LOW_MELEE)) {
2448                 if (any_bits(o_ptr->curse_flags, TRC_HEAVY_CURSE)) {
2449                     pow -= 15;
2450                 } else {
2451                     pow -= 5;
2452                 }
2453             }
2454         }
2455     }
2456
2457     if (creature_ptr->stun > 50) {
2458         pow -= 20;
2459     } else if (creature_ptr->stun) {
2460         pow -= 5;
2461     }
2462
2463     if (is_blessed(creature_ptr)) {
2464         pow += 10;
2465     }
2466
2467     if (is_hero(creature_ptr)) {
2468         pow += 12;
2469     }
2470
2471     if (is_shero(creature_ptr)) {
2472         pow -= 12;
2473     }
2474
2475     object_type *o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
2476
2477     if (is_heavy_shoot(creature_ptr, o_ptr)) {
2478         pow += 2 * (calc_weapon_weight_limit(creature_ptr) - o_ptr->weight / 10);
2479     }
2480
2481     if (o_ptr->k_idx) {
2482         if (o_ptr->k_idx && !is_heavy_shoot(creature_ptr, &creature_ptr->inventory_list[INVEN_BOW])) {
2483             if ((creature_ptr->pclass == CLASS_SNIPER) && (creature_ptr->tval_ammo == TV_BOLT)) {
2484                 pow += (10 + (creature_ptr->lev / 5));
2485             }
2486         }
2487     }
2488
2489     // 武器以外の装備による修正
2490     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
2491         int bonus_to_h;
2492         o_ptr = &creature_ptr->inventory_list[i];
2493         if (!o_ptr->k_idx || o_ptr->tval == TV_CAPTURE || (i == INVEN_MAIN_HAND && has_melee_weapon(creature_ptr, i))
2494             || (i == INVEN_SUB_HAND && has_melee_weapon(creature_ptr, i)) || i == INVEN_BOW)
2495             continue;
2496
2497         bonus_to_h = o_ptr->to_h;
2498
2499         if (creature_ptr->pclass == CLASS_NINJA) {
2500             if (o_ptr->to_h > 0)
2501                 bonus_to_h = (o_ptr->to_h + 1) / 2;
2502         }
2503
2504         if (is_real_value || object_is_known(o_ptr))
2505             pow += (s16b)bonus_to_h;
2506     }
2507
2508     pow -= calc_riding_bow_penalty(creature_ptr);
2509
2510     return pow;
2511 }
2512
2513 static s16b calc_to_damage_misc(player_type *creature_ptr)
2514 {
2515     object_type *o_ptr;
2516     BIT_FLAGS flgs[TR_FLAG_SIZE];
2517
2518     s16b to_dam = 0;
2519
2520     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
2521         o_ptr = &creature_ptr->inventory_list[i];
2522         if (!o_ptr->k_idx)
2523             continue;
2524
2525         object_flags(creature_ptr, o_ptr, flgs);
2526
2527         int bonus_to_d = o_ptr->to_d;
2528         if (creature_ptr->pclass == CLASS_NINJA) {
2529             if (o_ptr->to_d > 0)
2530                 bonus_to_d = (o_ptr->to_d + 1) / 2;
2531         }
2532         to_dam += (s16b)bonus_to_d;
2533     }
2534
2535     if (is_shero(creature_ptr)) {
2536         to_dam += 3 + (creature_ptr->lev / 5);
2537     }
2538
2539     if (creature_ptr->stun > 50) {
2540         to_dam -= 20;
2541     } else if (creature_ptr->stun) {
2542         to_dam -= 5;
2543     }
2544
2545     to_dam += ((int)(adj_str_td[creature_ptr->stat_index[A_STR]]) - 128);
2546     return to_dam;
2547 }
2548
2549 static s16b calc_to_hit_misc(player_type *creature_ptr)
2550 {
2551     object_type *o_ptr;
2552     BIT_FLAGS flgs[TR_FLAG_SIZE];
2553
2554     s16b to_hit = 0;
2555
2556     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
2557         o_ptr = &creature_ptr->inventory_list[i];
2558         if (!o_ptr->k_idx)
2559             continue;
2560
2561         object_flags(creature_ptr, o_ptr, flgs);
2562
2563         int bonus_to_h = o_ptr->to_h;
2564         if (creature_ptr->pclass == CLASS_NINJA) {
2565             if (o_ptr->to_h > 0)
2566                 bonus_to_h = (o_ptr->to_h + 1) / 2;
2567         }
2568         to_hit += (s16b)bonus_to_h;
2569     }
2570
2571     if (is_blessed(creature_ptr)) {
2572         to_hit += 10;
2573     }
2574
2575     if (is_hero(creature_ptr)) {
2576         to_hit += 12;
2577     }
2578
2579     if (is_shero(creature_ptr)) {
2580         to_hit += 12;
2581     }
2582
2583     if (creature_ptr->stun > 50) {
2584         to_hit -= 20;
2585     } else if (creature_ptr->stun) {
2586         to_hit -= 5;
2587     }
2588
2589     to_hit += ((int)(adj_dex_th[creature_ptr->stat_index[A_DEX]]) - 128);
2590     to_hit += ((int)(adj_str_th[creature_ptr->stat_index[A_STR]]) - 128);
2591
2592     return to_hit;
2593 }
2594
2595 static DICE_NUMBER calc_to_weapon_dice_num(player_type *creature_ptr, INVENTORY_IDX slot)
2596 {
2597     object_type *o_ptr = &creature_ptr->inventory_list[slot];
2598     DICE_NUMBER dn = 0;
2599
2600     if (creature_ptr->riding) {
2601         if ((o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE))) {
2602             dn += 2;
2603         }
2604     }
2605
2606     return dn;
2607 }
2608
2609 static DICE_NUMBER calc_to_weapon_dice_side(player_type *creature_ptr, INVENTORY_IDX slot)
2610 {
2611     (void)creature_ptr; // unused
2612     (void)slot; // unused
2613     return 0;
2614 }
2615
2616 /*!
2617  * @brief プレイヤーの所持重量制限を計算する /
2618  * Computes current weight limit.
2619  * @return 制限重量(ポンド)
2620  */
2621 WEIGHT calc_weight_limit(player_type *creature_ptr)
2622 {
2623     WEIGHT i = (WEIGHT)adj_str_wgt[creature_ptr->stat_index[A_STR]] * 50;
2624     if (creature_ptr->pclass == CLASS_BERSERKER)
2625         i = i * 3 / 2;
2626     return i;
2627 }
2628
2629 /*!
2630  * @brief プレイヤーが現在右手/左手に武器を持っているか判定する /
2631  * @param i 判定する手のID(右手:INVEN_MAIN_HAND 左手:INVEN_SUB_HAND)
2632  * @return 持っているならばTRUE
2633  */
2634 bool has_melee_weapon(player_type *creature_ptr, int slot)
2635 {
2636     return ((creature_ptr->inventory_list[slot].k_idx) && object_is_melee_weapon(&creature_ptr->inventory_list[slot]));
2637 }
2638
2639 /*!
2640  * @brief プレイヤーの現在開いている手の状態を返す
2641  * @param riding_control 乗馬中により片手を必要としている状態ならばTRUEを返す。
2642  * @return 開いている手のビットフラグ
2643  */
2644 BIT_FLAGS16 empty_hands(player_type *creature_ptr, bool riding_control)
2645 {
2646     BIT_FLAGS16 status = EMPTY_HAND_NONE;
2647     if (!creature_ptr->inventory_list[INVEN_MAIN_HAND].k_idx)
2648         status |= EMPTY_HAND_MAIN;
2649     if (!creature_ptr->inventory_list[INVEN_SUB_HAND].k_idx)
2650         status |= EMPTY_HAND_SUB;
2651
2652     if (riding_control && (status != EMPTY_HAND_NONE) && creature_ptr->riding && none_bits(creature_ptr->pet_extra_flags, PF_TWO_HANDS)) {
2653         if (any_bits(status, EMPTY_HAND_SUB))
2654             reset_bits(status, EMPTY_HAND_SUB);
2655         else if (any_bits(status, EMPTY_HAND_MAIN))
2656             reset_bits(status, EMPTY_HAND_MAIN);
2657     }
2658
2659     return status;
2660 }
2661
2662 /*!
2663  * @brief プレイヤーが防具重量制限のある職業時にペナルティを受ける状態にあるかどうかを返す。
2664  * @return ペナルティが適用されるならばTRUE。
2665  */
2666 bool heavy_armor(player_type *creature_ptr)
2667 {
2668     if ((creature_ptr->pclass != CLASS_MONK) && (creature_ptr->pclass != CLASS_FORCETRAINER) && (creature_ptr->pclass != CLASS_NINJA))
2669         return FALSE;
2670
2671     WEIGHT monk_arm_wgt = 0;
2672     if (creature_ptr->inventory_list[INVEN_MAIN_HAND].tval > TV_SWORD)
2673         monk_arm_wgt += creature_ptr->inventory_list[INVEN_MAIN_HAND].weight;
2674     if (creature_ptr->inventory_list[INVEN_SUB_HAND].tval > TV_SWORD)
2675         monk_arm_wgt += creature_ptr->inventory_list[INVEN_SUB_HAND].weight;
2676     monk_arm_wgt += creature_ptr->inventory_list[INVEN_BODY].weight;
2677     monk_arm_wgt += creature_ptr->inventory_list[INVEN_HEAD].weight;
2678     monk_arm_wgt += creature_ptr->inventory_list[INVEN_OUTER].weight;
2679     monk_arm_wgt += creature_ptr->inventory_list[INVEN_ARMS].weight;
2680     monk_arm_wgt += creature_ptr->inventory_list[INVEN_FEET].weight;
2681
2682     return (monk_arm_wgt > (100 + (creature_ptr->lev * 4)));
2683 }
2684
2685 /*!
2686  * @brief update のフラグに応じた更新をまとめて行う / Handle "update"
2687  * @return なし
2688  * @details 更新処理の対象はプレイヤーの能力修正/光源寿命/HP/MP/魔法の学習状態、他多数の外界の状態判定。
2689  */
2690 void update_creature(player_type *creature_ptr)
2691 {
2692     if (!creature_ptr->update)
2693         return;
2694
2695     floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2696     if (any_bits(creature_ptr->update, (PU_AUTODESTROY))) {
2697         reset_bits(creature_ptr->update, PU_AUTODESTROY);
2698         autopick_delayed_alter(creature_ptr);
2699     }
2700
2701     if (any_bits(creature_ptr->update, (PU_COMBINE))) {
2702         reset_bits(creature_ptr->update, PU_COMBINE);
2703         combine_pack(creature_ptr);
2704     }
2705
2706     if (any_bits(creature_ptr->update, (PU_REORDER))) {
2707         reset_bits(creature_ptr->update, PU_REORDER);
2708         reorder_pack(creature_ptr);
2709     }
2710
2711     if (any_bits(creature_ptr->update, (PU_BONUS))) {
2712         reset_bits(creature_ptr->update, PU_BONUS);
2713         update_alignment(creature_ptr);
2714         update_bonuses(creature_ptr);
2715     }
2716
2717     if (any_bits(creature_ptr->update, (PU_TORCH))) {
2718         reset_bits(creature_ptr->update, PU_TORCH);
2719         update_lite_radius(creature_ptr);
2720     }
2721
2722     if (any_bits(creature_ptr->update, (PU_HP))) {
2723         reset_bits(creature_ptr->update, PU_HP);
2724         update_max_hitpoints(creature_ptr);
2725     }
2726
2727     if (any_bits(creature_ptr->update, (PU_MANA))) {
2728         reset_bits(creature_ptr->update, PU_MANA);
2729         update_max_mana(creature_ptr);
2730     }
2731
2732     if (any_bits(creature_ptr->update, (PU_SPELLS))) {
2733         reset_bits(creature_ptr->update, PU_SPELLS);
2734         update_num_of_spells(creature_ptr);
2735     }
2736
2737     if (!current_world_ptr->character_generated)
2738         return;
2739     if (current_world_ptr->character_icky_depth > 0)
2740         return;
2741     if (any_bits(creature_ptr->update, (PU_UN_LITE))) {
2742         reset_bits(creature_ptr->update, PU_UN_LITE);
2743         forget_lite(floor_ptr);
2744     }
2745
2746     if (any_bits(creature_ptr->update, (PU_UN_VIEW))) {
2747         reset_bits(creature_ptr->update, PU_UN_VIEW);
2748         forget_view(floor_ptr);
2749     }
2750
2751     if (any_bits(creature_ptr->update, (PU_VIEW))) {
2752         reset_bits(creature_ptr->update, PU_VIEW);
2753         update_view(creature_ptr);
2754     }
2755
2756     if (any_bits(creature_ptr->update, (PU_LITE))) {
2757         reset_bits(creature_ptr->update, PU_LITE);
2758         update_lite(creature_ptr);
2759     }
2760
2761     if (any_bits(creature_ptr->update, (PU_FLOW))) {
2762         reset_bits(creature_ptr->update, PU_FLOW);
2763         update_flow(creature_ptr);
2764     }
2765
2766     if (any_bits(creature_ptr->update, (PU_DISTANCE))) {
2767         reset_bits(creature_ptr->update, PU_DISTANCE);
2768
2769         update_monsters(creature_ptr, TRUE);
2770     }
2771
2772     if (any_bits(creature_ptr->update, (PU_MON_LITE))) {
2773         reset_bits(creature_ptr->update, PU_MON_LITE);
2774         update_mon_lite(creature_ptr);
2775     }
2776
2777     if (any_bits(creature_ptr->update, (PU_DELAY_VIS))) {
2778         reset_bits(creature_ptr->update, PU_DELAY_VIS);
2779         delayed_visual_update(creature_ptr);
2780     }
2781
2782     if (any_bits(creature_ptr->update, (PU_MONSTERS))) {
2783         reset_bits(creature_ptr->update, PU_MONSTERS);
2784         update_monsters(creature_ptr, FALSE);
2785     }
2786 }
2787
2788 /*!
2789  * @brief プレイヤーが魔道書を一冊も持っていないかを判定する
2790  * @return 魔道書を一冊も持っていないならTRUEを返す
2791  */
2792 bool player_has_no_spellbooks(player_type *creature_ptr)
2793 {
2794     object_type *o_ptr;
2795     for (int i = 0; i < INVEN_PACK; i++) {
2796         o_ptr = &creature_ptr->inventory_list[i];
2797         if (o_ptr->k_idx && check_book_realm(creature_ptr, o_ptr->tval, o_ptr->sval))
2798             return FALSE;
2799     }
2800
2801     floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2802     for (int i = floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].o_idx; i; i = o_ptr->next_o_idx) {
2803         o_ptr = &floor_ptr->o_list[i];
2804         if (o_ptr->k_idx && any_bits(o_ptr->marked, OM_FOUND) && check_book_realm(creature_ptr, o_ptr->tval, o_ptr->sval))
2805             return FALSE;
2806     }
2807
2808     return TRUE;
2809 }
2810
2811 /*!
2812  * @brief プレイヤーを指定座標に配置する / Place the player in the dungeon XXX XXX
2813  * @param x 配置先X座標
2814  * @param y 配置先Y座標
2815  * @return 配置に成功したらTRUE
2816  */
2817 bool player_place(player_type *creature_ptr, POSITION y, POSITION x)
2818 {
2819     if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx != 0)
2820         return FALSE;
2821
2822     /* Save player location */
2823     creature_ptr->y = y;
2824     creature_ptr->x = x;
2825     return TRUE;
2826 }
2827
2828 /*!
2829  * @brief 種族アンバライトが出血時パターンの上に乗った際のペナルティ処理
2830  * @return なし
2831  */
2832 void wreck_the_pattern(player_type *creature_ptr)
2833 {
2834     floor_type *floor_ptr = creature_ptr->current_floor_ptr;
2835     int pattern_type = f_info[floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].feat].subtype;
2836     if (pattern_type == PATTERN_TILE_WRECKED)
2837         return;
2838
2839     msg_print(_("パターンを血で汚してしまった!", "You bleed on the Pattern!"));
2840     msg_print(_("何か恐ろしい事が起こった!", "Something terrible happens!"));
2841
2842     if (!is_invuln(creature_ptr))
2843         take_hit(creature_ptr, DAMAGE_NOESCAPE, damroll(10, 8), _("パターン損壊", "corrupting the Pattern"));
2844
2845     int to_ruin = randint1(45) + 35;
2846     while (to_ruin--) {
2847         POSITION r_y, r_x;
2848         scatter(creature_ptr, &r_y, &r_x, creature_ptr->y, creature_ptr->x, 4, PROJECT_NONE);
2849
2850         if (pattern_tile(floor_ptr, r_y, r_x) && (f_info[floor_ptr->grid_array[r_y][r_x].feat].subtype != PATTERN_TILE_WRECKED)) {
2851             cave_set_feat(creature_ptr, r_y, r_x, feat_pattern_corrupted);
2852         }
2853     }
2854
2855     cave_set_feat(creature_ptr, creature_ptr->y, creature_ptr->x, feat_pattern_corrupted);
2856 }
2857
2858 /*!
2859  * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
2860  * Advance experience levels and print experience
2861  * @return なし
2862  */
2863 void check_experience(player_type *creature_ptr)
2864 {
2865     if (creature_ptr->exp < 0)
2866         creature_ptr->exp = 0;
2867     if (creature_ptr->max_exp < 0)
2868         creature_ptr->max_exp = 0;
2869     if (creature_ptr->max_max_exp < 0)
2870         creature_ptr->max_max_exp = 0;
2871
2872     if (creature_ptr->exp > PY_MAX_EXP)
2873         creature_ptr->exp = PY_MAX_EXP;
2874     if (creature_ptr->max_exp > PY_MAX_EXP)
2875         creature_ptr->max_exp = PY_MAX_EXP;
2876     if (creature_ptr->max_max_exp > PY_MAX_EXP)
2877         creature_ptr->max_max_exp = PY_MAX_EXP;
2878
2879     if (creature_ptr->exp > creature_ptr->max_exp)
2880         creature_ptr->max_exp = creature_ptr->exp;
2881     if (creature_ptr->max_exp > creature_ptr->max_max_exp)
2882         creature_ptr->max_max_exp = creature_ptr->max_exp;
2883
2884     set_bits(creature_ptr->redraw, PR_EXP);
2885     handle_stuff(creature_ptr);
2886
2887     bool android = (creature_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
2888     PLAYER_LEVEL old_lev = creature_ptr->lev;
2889     while ((creature_ptr->lev > 1) && (creature_ptr->exp < ((android ? player_exp_a : player_exp)[creature_ptr->lev - 2] * creature_ptr->expfact / 100L))) {
2890         creature_ptr->lev--;
2891         set_bits(creature_ptr->update, PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
2892         set_bits(creature_ptr->redraw, PR_LEV | PR_TITLE);
2893         set_bits(creature_ptr->window_flags, PW_PLAYER);
2894         handle_stuff(creature_ptr);
2895     }
2896
2897     bool level_reward = FALSE;
2898     bool level_mutation = FALSE;
2899     bool level_inc_stat = FALSE;
2900     while ((creature_ptr->lev < PY_MAX_LEVEL)
2901         && (creature_ptr->exp >= ((android ? player_exp_a : player_exp)[creature_ptr->lev - 1] * creature_ptr->expfact / 100L))) {
2902         creature_ptr->lev++;
2903         if (creature_ptr->lev > creature_ptr->max_plv) {
2904             creature_ptr->max_plv = creature_ptr->lev;
2905
2906             if ((creature_ptr->pclass == CLASS_CHAOS_WARRIOR) || creature_ptr->muta.has(MUTA::CHAOS_GIFT)) {
2907                 level_reward = TRUE;
2908             }
2909             if (creature_ptr->prace == RACE_BEASTMAN) {
2910                 if (one_in_(5))
2911                     level_mutation = TRUE;
2912             }
2913             level_inc_stat = TRUE;
2914
2915             exe_write_diary(creature_ptr, DIARY_LEVELUP, creature_ptr->lev, NULL);
2916         }
2917
2918         sound(SOUND_LEVEL);
2919         msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), creature_ptr->lev);
2920         set_bits(creature_ptr->update, (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS));
2921         set_bits(creature_ptr->redraw, (PR_LEV | PR_TITLE | PR_EXP));
2922         set_bits(creature_ptr->window_flags, (PW_PLAYER | PW_SPELL | PW_INVEN));
2923         creature_ptr->level_up_message = TRUE;
2924         handle_stuff(creature_ptr);
2925
2926         creature_ptr->level_up_message = FALSE;
2927         if (level_inc_stat) {
2928             if (!(creature_ptr->max_plv % 10)) {
2929                 int choice;
2930                 screen_save();
2931                 while (TRUE) {
2932                     int n;
2933                     char tmp[32];
2934
2935                     cnv_stat(creature_ptr->stat_max[0], tmp);
2936                     prt(format(_("        a) 腕力 (現在値 %s)", "        a) Str (cur %s)"), tmp), 2, 14);
2937                     cnv_stat(creature_ptr->stat_max[1], tmp);
2938                     prt(format(_("        b) 知能 (現在値 %s)", "        b) Int (cur %s)"), tmp), 3, 14);
2939                     cnv_stat(creature_ptr->stat_max[2], tmp);
2940                     prt(format(_("        c) 賢さ (現在値 %s)", "        c) Wis (cur %s)"), tmp), 4, 14);
2941                     cnv_stat(creature_ptr->stat_max[3], tmp);
2942                     prt(format(_("        d) 器用 (現在値 %s)", "        d) Dex (cur %s)"), tmp), 5, 14);
2943                     cnv_stat(creature_ptr->stat_max[4], tmp);
2944                     prt(format(_("        e) 耐久 (現在値 %s)", "        e) Con (cur %s)"), tmp), 6, 14);
2945                     cnv_stat(creature_ptr->stat_max[5], tmp);
2946                     prt(format(_("        f) 魅力 (現在値 %s)", "        f) Chr (cur %s)"), tmp), 7, 14);
2947
2948                     prt("", 8, 14);
2949                     prt(_("        どの能力値を上げますか?", "        Which stat do you want to raise?"), 1, 14);
2950
2951                     while (TRUE) {
2952                         choice = inkey();
2953                         if ((choice >= 'a') && (choice <= 'f'))
2954                             break;
2955                     }
2956                     for (n = 0; n < A_MAX; n++)
2957                         if (n != choice - 'a')
2958                             prt("", n + 2, 14);
2959                     if (get_check(_("よろしいですか?", "Are you sure? ")))
2960                         break;
2961                 }
2962                 do_inc_stat(creature_ptr, choice - 'a');
2963                 screen_load();
2964             } else if (!(creature_ptr->max_plv % 2))
2965                 do_inc_stat(creature_ptr, randint0(6));
2966         }
2967
2968         if (level_mutation) {
2969             msg_print(_("あなたは変わった気がする...", "You feel different..."));
2970             (void)gain_mutation(creature_ptr, 0);
2971             level_mutation = FALSE;
2972         }
2973
2974         /*
2975          * 報酬でレベルが上ると再帰的に check_experience(creature_ptr) が
2976          * 呼ばれるので順番を最後にする。
2977          */
2978         if (level_reward) {
2979             gain_level_reward(creature_ptr, 0);
2980             level_reward = FALSE;
2981         }
2982
2983         set_bits(creature_ptr->update, PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
2984         set_bits(creature_ptr->redraw, (PR_LEV | PR_TITLE));
2985         set_bits(creature_ptr->window_flags, (PW_PLAYER | PW_SPELL));
2986         handle_stuff(creature_ptr);
2987     }
2988
2989     if (old_lev != creature_ptr->lev)
2990         autopick_load_pref(creature_ptr, FALSE);
2991 }
2992
2993 /*!
2994  * @brief 現在の修正後能力値を3~17及び18/xxx形式に変換する / Converts stat num into a six-char (right justified) string
2995  * @param val 能力値
2996  * @param out_val 出力先文字列ポインタ
2997  * @return なし
2998  */
2999 void cnv_stat(int val, char *out_val)
3000 {
3001     if (val <= 18) {
3002         sprintf(out_val, "    %2d", val);
3003         return;
3004     }
3005
3006     int bonus = (val - 18);
3007     if (bonus >= 220) {
3008         sprintf(out_val, "18/%3s", "***");
3009     } else if (bonus >= 100) {
3010         sprintf(out_val, "18/%03d", bonus);
3011     } else {
3012         sprintf(out_val, " 18/%02d", bonus);
3013     }
3014 }
3015
3016 /*!
3017  * @brief 能力値現在値から3~17及び18/xxx様式に基づく加減算を行う。
3018  * Modify a stat value by a "modifier", return new value
3019  * @param value 現在値
3020  * @param amount 加減算値
3021  * @return 加減算後の値
3022  * @details
3023  * <pre>
3024  * Stats go up: 3,4,...,17,18,18/10,18/20,...,18/220
3025  * Or even: 18/13, 18/23, 18/33, ..., 18/220
3026  * Stats go down: 18/220, 18/210,..., 18/10, 18, 17, ..., 3
3027  * Or even: 18/13, 18/03, 18, 17, ..., 3
3028  * </pre>
3029  */
3030 s16b modify_stat_value(int value, int amount)
3031 {
3032     if (amount > 0) {
3033         for (int i = 0; i < amount; i++) {
3034             if (value < 18)
3035                 value++;
3036             else
3037                 value += 10;
3038         }
3039     } else if (amount < 0) {
3040         for (int i = 0; i < (0 - amount); i++) {
3041             if (value >= 18 + 10)
3042                 value -= 10;
3043             else if (value > 18)
3044                 value = 18;
3045             else if (value > 3)
3046                 value--;
3047         }
3048     }
3049
3050     return (s16b)value;
3051 }
3052
3053 /*!
3054  * @brief スコアを計算する /
3055  * Hack -- Calculates the total number of points earned         -JWT-
3056  * @return なし
3057  * @details
3058  */
3059 long calc_score(player_type *creature_ptr)
3060 {
3061     int arena_win = MIN(creature_ptr->arena_number, MAX_ARENA_MONS);
3062
3063     int mult = 100;
3064     if (!preserve_mode)
3065         mult += 10;
3066     if (!autoroller)
3067         mult += 10;
3068     if (!smart_learn)
3069         mult -= 20;
3070     if (smart_cheat)
3071         mult += 30;
3072     if (ironman_shops)
3073         mult += 50;
3074     if (ironman_small_levels)
3075         mult += 10;
3076     if (ironman_empty_levels)
3077         mult += 20;
3078     if (!powerup_home)
3079         mult += 50;
3080     if (ironman_rooms)
3081         mult += 100;
3082     if (ironman_nightmare)
3083         mult += 100;
3084
3085     if (mult < 5)
3086         mult = 5;
3087
3088     DEPTH max_dl = 0;
3089     for (int i = 0; i < current_world_ptr->max_d_idx; i++)
3090         if (max_dlv[i] > max_dl)
3091             max_dl = max_dlv[i];
3092
3093     u32b point_l = (creature_ptr->max_max_exp + (100 * max_dl));
3094     u32b point_h = point_l / 0x10000L;
3095     point_l = point_l % 0x10000L;
3096     point_h *= mult;
3097     point_l *= mult;
3098     point_h += point_l / 0x10000L;
3099     point_l %= 0x10000L;
3100
3101     point_l += ((point_h % 100) << 16);
3102     point_h /= 100;
3103     point_l /= 100;
3104
3105     u32b point = (point_h << 16) + (point_l);
3106     if (creature_ptr->arena_number >= 0)
3107         point += (arena_win * arena_win * (arena_win > 29 ? 1000 : 100));
3108
3109     if (ironman_downward)
3110         point *= 2;
3111     if (creature_ptr->pclass == CLASS_BERSERKER) {
3112         if (creature_ptr->prace == RACE_SPECTRE)
3113             point = point / 5;
3114     }
3115
3116     if ((creature_ptr->pseikaku == PERSONALITY_MUNCHKIN) && point) {
3117         point = 1;
3118         if (current_world_ptr->total_winner)
3119             point = 2;
3120     }
3121
3122     if (easy_band)
3123         point = (0 - point);
3124
3125     return point;
3126 }
3127
3128 /*!
3129  * @param creature_ptr プレーヤーへの参照ポインタ
3130  * @return 祝福状態ならばTRUE
3131  */
3132 bool is_blessed(player_type *creature_ptr)
3133 {
3134     return creature_ptr->blessed || music_singing(creature_ptr, MUSIC_BLESS) || hex_spelling(creature_ptr, HEX_BLESS);
3135 }
3136
3137 bool is_tim_esp(player_type *creature_ptr)
3138 {
3139     return creature_ptr->tim_esp || music_singing(creature_ptr, MUSIC_MIND) || (creature_ptr->concent >= CONCENT_TELE_THRESHOLD);
3140 }
3141
3142 bool is_tim_stealth(player_type *creature_ptr)
3143 {
3144     return creature_ptr->tim_stealth || music_singing(creature_ptr, MUSIC_STEALTH);
3145 }
3146
3147 bool is_time_limit_esp(player_type *creature_ptr)
3148 {
3149     return creature_ptr->tim_esp || music_singing(creature_ptr, MUSIC_MIND) || (creature_ptr->concent >= CONCENT_TELE_THRESHOLD);
3150 }
3151
3152 bool is_time_limit_stealth(player_type *creature_ptr)
3153 {
3154     return creature_ptr->tim_stealth || music_singing(creature_ptr, MUSIC_STEALTH);
3155 }
3156
3157 bool can_two_hands_wielding(player_type *creature_ptr)
3158 {
3159     return !creature_ptr->riding || any_bits(creature_ptr->pet_extra_flags, PF_TWO_HANDS);
3160 }
3161
3162 /*!
3163  * @brief 口を使う継続的な処理を中断する
3164  * @param caster_ptr プレーヤーへの参照ポインタ
3165  * @return なし
3166  */
3167 void stop_mouth(player_type *caster_ptr)
3168 {
3169     if (music_singing_any(caster_ptr))
3170         stop_singing(caster_ptr);
3171     if (hex_spelling_any(caster_ptr))
3172         stop_hex_spell_all(caster_ptr);
3173 }
3174
3175 bool is_fast(player_type *creature_ptr)
3176 {
3177     return creature_ptr->fast || music_singing(creature_ptr, MUSIC_SPEED) || music_singing(creature_ptr, MUSIC_SHERO);
3178 }
3179
3180 bool is_invuln(player_type *creature_ptr)
3181 {
3182     return creature_ptr->invuln || music_singing(creature_ptr, MUSIC_INVULN);
3183 }
3184
3185 bool is_hero(player_type *creature_ptr)
3186 {
3187     return creature_ptr->hero || music_singing(creature_ptr, MUSIC_HERO) || music_singing(creature_ptr, MUSIC_SHERO);
3188 }
3189
3190 bool is_shero(player_type *creature_ptr)
3191 {
3192     return creature_ptr->shero || creature_ptr->pclass == CLASS_BERSERKER;
3193 }
3194
3195 bool is_echizen(player_type *creature_ptr)
3196 {
3197     return (creature_ptr->pseikaku == PERSONALITY_COMBAT) || (creature_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON);
3198 }
3199
3200 int calc_weapon_weight_limit(player_type *creature_ptr)
3201 {
3202     int weight = adj_str_hold[creature_ptr->stat_index[A_STR]];
3203
3204     if (has_two_handed_weapons(creature_ptr))
3205         weight *= 2;
3206
3207     return weight;
3208 }
3209
3210 static player_hand main_attack_hand(player_type *creature_ptr)
3211 {
3212     switch (player_melee_type(creature_ptr)) {
3213     case MELEE_TYPE_BAREHAND_TWO:
3214         return PLAYER_HAND_MAIN;
3215     case MELEE_TYPE_BAREHAND_MAIN:
3216         return PLAYER_HAND_MAIN;
3217     case MELEE_TYPE_BAREHAND_SUB:
3218         return PLAYER_HAND_SUB;
3219     case MELEE_TYPE_WEAPON_MAIN:
3220         return PLAYER_HAND_MAIN;
3221     case MELEE_TYPE_WEAPON_SUB:
3222         return PLAYER_HAND_SUB;
3223     case MELEE_TYPE_WEAPON_TWOHAND:
3224         return has_melee_weapon(creature_ptr, INVEN_MAIN_HAND) ? PLAYER_HAND_MAIN : PLAYER_HAND_SUB;
3225     case MELEE_TYPE_WEAPON_DOUBLE:
3226         return PLAYER_HAND_MAIN;
3227     case MELEE_TYPE_SHIELD_DOUBLE:
3228         return PLAYER_HAND_MAIN;
3229     }
3230     return PLAYER_HAND_MAIN;
3231 }