OSDN Git Service

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