OSDN Git Service

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