OSDN Git Service

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