OSDN Git Service

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