OSDN Git Service

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