OSDN Git Service

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