OSDN Git Service

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