OSDN Git Service

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