OSDN Git Service

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