OSDN Git Service

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