OSDN Git Service

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