OSDN Git Service

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