OSDN Git Service

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