OSDN Git Service

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