OSDN Git Service

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