OSDN Git Service

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