OSDN Git Service

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