OSDN Git Service

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