OSDN Git Service

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