OSDN Git Service

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