OSDN Git Service

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