OSDN Git Service

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