OSDN Git Service

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