OSDN Git Service

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