OSDN Git Service

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