OSDN Git Service

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