OSDN Git Service

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