OSDN Git Service

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