OSDN Git Service

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