OSDN Git Service

d51f0a46d3f2d95077b740c422cdf82a3e7c30c8
[hengband/hengband.git] / src / player-status.c
1 #include "angband.h"
2 #include "core.h"
3 #include "util.h"
4
5 #include "bldg.h"
6 #include "quest.h"
7 #include "player-move.h"
8 #include "player-status.h"
9 #include "player-effects.h"
10 #include "player-skill.h"
11 #include "player-race.h"
12 #include "player-class.h"
13 #include "player-personality.h"
14 #include "player-damage.h"
15 #include "floor.h"
16 #include "floor-events.h"
17 #include "feature.h"
18 #include "artifact.h"
19 #include "avatar.h"
20 #include "spells.h"
21 #include "spells-status.h"
22 #include "object.h"
23 #include "object-hook.h"
24 #include "object-ego.h"
25 #include "monster.h"
26 #include "monster-status.h"
27 #include "monsterrace-hook.h"
28 #include "mutation.h"
29 #include "patron.h"
30 #include "realm-hex.h"
31 #include "realm-song.h"
32 #include "cmd-pet.h"
33 #include "cmd-spell.h"
34 #include "dungeon.h"
35 #include "objectkind.h"
36 #include "monsterrace.h"
37 #include "autopick.h"
38 #include "cmd-dump.h"
39 #include "melee.h"
40 #include "world.h"
41 #include "view-mainwindow.h"
42 #include "files.h"
43 #include "cmd-magiceat.h"
44
45 /*!
46  * @brief 能力値テーブル / Abbreviations of healthy stats
47  */
48 const concptr stat_names[6] =
49 {
50 #ifdef JP
51         "腕力 :", "知能 :", "賢さ :", "器用 :", "耐久 :", "魅力 :"
52 #else
53         "STR : ", "INT : ", "WIS : ", "DEX : ", "CON : ", "CHR : "
54 #endif
55
56 };
57
58 /*!
59  * @brief 能力値テーブル(能力低下時) / Abbreviations of damaged stats
60  */
61 const concptr stat_names_reduced[6] =
62 {
63 #ifdef JP
64         "腕力x:", "知能x:", "賢さx:", "器用x:", "耐久x:", "魅力x:"
65 #else
66         "Str : ", "Int : ", "Wis : ", "Dex : ", "Con : ", "Chr : "
67 #endif
68
69 };
70
71 /* ELDRITCH_HORRORによるsanity blast処理に関するメッセージの最大数 / Number of entries in the sanity-blast descriptions */
72 #define MAX_SAN_HORROR 20 /*!< 恐ろしい対象の形容数(正常時) */
73 #define MAX_SAN_FUNNY 22  /*!< 恐ろしい対象の形容数(幻覚時) */
74 #define MAX_SAN_COMMENT 5 /*!< 恐ろしい対象を見たときの絶叫メッセージ数(幻覚時) */
75
76 /*!
77  * @var horror_desc
78  * @brief ELDRITCH HORROR効果時のモンスターの形容メッセージ(通常時)
79  */
80 static concptr horror_desc[MAX_SAN_HORROR] =
81 {
82 #ifdef JP
83         "忌まわしい",
84         "底知れぬ",
85         "ぞっとする",
86         "破滅的な",
87         "冒涜的な",
88
89         "いやな",
90         "恐ろしい",
91         "不潔な",
92         "容赦のない",
93         "おぞましい",
94
95         "地獄の",
96         "身の毛もよだつ",
97         "地獄の",
98         "忌まわしい",
99         "悪夢のような",
100
101         "嫌悪を感じる",
102         "罰当たりな",
103         "恐い",
104         "不浄な",
105         "言うもおぞましい",
106 #else
107         "abominable",
108         "abysmal",
109         "appalling",
110         "baleful",
111         "blasphemous",
112
113         "disgusting",
114         "dreadful",
115         "filthy",
116         "grisly",
117         "hideous",
118
119         "hellish",
120         "horrible",
121         "infernal",
122         "loathsome",
123         "nightmarish",
124
125         "repulsive",
126         "sacrilegious",
127         "terrible",
128         "unclean",
129         "unspeakable",
130 #endif
131
132 };
133
134 /*!
135  * @var funny_desc
136  * @brief ELDRITCH HORROR効果時のモンスターの形容メッセージ(幻覚状態時)
137  */
138 static concptr funny_desc[MAX_SAN_FUNNY] =
139 {
140 #ifdef JP
141         "間抜けな",
142         "滑稽な",
143         "ばからしい",
144         "無味乾燥な",
145         "馬鹿げた",
146
147         "笑える",
148         "ばかばかしい",
149         "ぶっとんだ",
150         "いかした",
151         "ポストモダンな",
152
153         "ファンタスティックな",
154         "ダダイズム的な",
155         "キュビズム的な",
156         "宇宙的な",
157         "卓越した",
158
159         "理解不能な",
160         "ものすごい",
161         "驚くべき",
162         "信じられない",
163         "カオティックな",
164
165         "野性的な",
166         "非常識な",
167 #else
168         "silly",
169         "hilarious",
170         "absurd",
171         "insipid",
172         "ridiculous",
173
174         "laughable",
175         "ludicrous",
176         "far-out",
177         "groovy",
178         "postmodern",
179
180         "fantastic",
181         "dadaistic",
182         "cubistic",
183         "cosmic",
184         "awesome",
185
186         "incomprehensible",
187         "fabulous",
188         "amazing",
189         "incredible",
190         "chaotic",
191
192         "wild",
193         "preposterous",
194 #endif
195
196 };
197
198 /*!
199  * @var funny_comments
200  * @brief ELDRITCH HORROR効果時の幻覚時間延長を示す錯乱表現
201  */
202 static concptr funny_comments[MAX_SAN_COMMENT] =
203 {
204 #ifdef JP
205         /* nuke me */
206           "最高だぜ!",
207           "うひょー!",
208           "いかすぜ!",
209           "すんばらしい!",
210           "ぶっとびー!"
211   #else
212           "Wow, cosmic, man!",
213           "Rad!",
214           "Groovy!",
215           "Cool!",
216           "Far out!"
217   #endif
218
219 };
220
221 /*!
222  * @brief 基本必要経験値テーブル /
223  * Base experience levels, may be adjusted up for race and/or class
224  */
225 const s32b player_exp[PY_MAX_LEVEL] =
226 {
227         10,
228         25,
229         45,
230         70,
231         100,
232         140,
233         200,
234         280,
235         380,/*10*/
236         500,
237         650,
238         850,
239         1100,
240         1400,
241         1800,
242         2300,
243         2900,
244         3600,
245         4400,/*20*/
246         5400,
247         6800,
248         8400,
249         10200,
250         12500,
251         17500,
252         25000,
253         35000L,
254         50000L,
255         75000L,/*30*/
256         100000L,
257         150000L,
258         200000L,
259         275000L,
260         350000L,
261         450000L,
262         550000L,
263         700000L,
264         850000L,
265         1000000L,/*40*/
266         1250000L,
267         1500000L,
268         1800000L,
269         2100000L,
270         2400000L,
271         2700000L,
272         3000000L,
273         3500000L,
274         4000000L,
275         4500000L,/*50*/
276         5000000L
277 };
278
279 /*!
280  * @brief 基本必要強化値テーブル(アンドロイド専用)
281  */
282 const s32b player_exp_a[PY_MAX_LEVEL] =
283 {
284         20,
285         50,
286         100,
287         170,
288         280,
289         430,
290         650,
291         950,
292         1400,/*10*/
293         1850,
294         2300,
295         2900,
296         3600,
297         4400,
298         5400,
299         6800,
300         8400,
301         10400,
302         12500,/*20*/
303         17500,
304         25000,
305         35000,
306         50000L,
307         75000L,
308         100000L,
309         150000L,
310         200000L,
311         275000L,
312         350000L,/*30*/
313         450000L,
314         550000L,
315         650000L,
316         800000L,
317         950000L,
318         1100000L,
319         1250000L,
320         1400000L,
321         1550000L,
322         1700000L,/*40*/
323         1900000L,
324         2100000L,
325         2300000L,
326         2550000L,
327         2800000L,
328         3050000L,
329         3300000L,
330         3700000L,
331         4100000L,
332         4500000L,/*50*/
333         5000000L
334 };
335
336 /*!
337  * 知力/賢さによるレベル毎の習得可能魔法数テーブル
338  * Stat Table (INT/WIS) -- Number of half-spells per level
339  */
340 const byte adj_mag_study[] =
341 {
342         0       /* 3 */,
343         0       /* 4 */,
344         0       /* 5 */,
345         0       /* 6 */,
346         0       /* 7 */,
347         1       /* 8 */,
348         1       /* 9 */,
349         1       /* 10 */,
350         1       /* 11 */,
351         2       /* 12 */,
352         2       /* 13 */,
353         2       /* 14 */,
354         2       /* 15 */,
355         2       /* 16 */,
356         2       /* 17 */,
357         2       /* 18/00-18/09 */,
358         2       /* 18/10-18/19 */,
359         2       /* 18/20-18/29 */,
360         2       /* 18/30-18/39 */,
361         2       /* 18/40-18/49 */,
362         3       /* 18/50-18/59 */,
363         3       /* 18/60-18/69 */,
364         3       /* 18/70-18/79 */,
365         3       /* 18/80-18/89 */,
366         4       /* 18/90-18/99 */,
367         4       /* 18/100-18/109 */,
368         4       /* 18/110-18/119 */,
369         5       /* 18/120-18/129 */,
370         5       /* 18/130-18/139 */,
371         5       /* 18/140-18/149 */,
372         5       /* 18/150-18/159 */,
373         5       /* 18/160-18/169 */,
374         5       /* 18/170-18/179 */,
375         5       /* 18/180-18/189 */,
376         5       /* 18/190-18/199 */,
377         5       /* 18/200-18/209 */,
378         6       /* 18/210-18/219 */,
379         6       /* 18/220+ */
380 };
381
382 /*!
383  * 知力/賢さによるMP修正テーブル
384  * Stat Table (INT/WIS) -- extra 1/4-mana-points per level
385  */
386 const byte adj_mag_mana[] =
387 {
388         0       /* 3 */,
389         0       /* 4 */,
390         0       /* 5 */,
391         0       /* 6 */,
392         0       /* 7 */,
393         1       /* 8 */,
394         2       /* 9 */,
395         3       /* 10 */,
396         4       /* 11 */,
397         5       /* 12 */,
398         5       /* 13 */,
399         6       /* 14 */,
400         7       /* 15 */,
401         8       /* 16 */,
402         9       /* 17 */,
403         10      /* 18/00-18/09 */,
404         11      /* 18/10-18/19 */,
405         11      /* 18/20-18/29 */,
406         12      /* 18/30-18/39 */,
407         12      /* 18/40-18/49 */,
408         13      /* 18/50-18/59 */,
409         14      /* 18/60-18/69 */,
410         15      /* 18/70-18/79 */,
411         16      /* 18/80-18/89 */,
412         17      /* 18/90-18/99 */,
413         18      /* 18/100-18/109 */,
414         19      /* 18/110-18/119 */,
415         20      /* 18/120-18/129 */,
416         21      /* 18/130-18/139 */,
417         22      /* 18/140-18/149 */,
418         23      /* 18/150-18/159 */,
419         24      /* 18/160-18/169 */,
420         25      /* 18/170-18/179 */,
421         26      /* 18/180-18/189 */,
422         27      /* 18/190-18/199 */,
423         28      /* 18/200-18/209 */,
424         29      /* 18/210-18/219 */,
425         30      /* 18/220+ */
426 };
427
428 /*!
429  * 知力/賢さによる最低魔法失敗率テーブル
430  * Stat Table (INT/WIS) -- Minimum failure rate (percentage)
431  */
432 const byte adj_mag_fail[] =
433 {
434         99      /* 3 */,
435         99      /* 4 */,
436         99      /* 5 */,
437         99      /* 6 */,
438         99      /* 7 */,
439         50      /* 8 */,
440         30      /* 9 */,
441         20      /* 10 */,
442         15      /* 11 */,
443         12      /* 12 */,
444         11      /* 13 */,
445         10      /* 14 */,
446         9       /* 15 */,
447         8       /* 16 */,
448         7       /* 17 */,
449         6       /* 18/00-18/09 */,
450         6       /* 18/10-18/19 */,
451         5       /* 18/20-18/29 */,
452         5       /* 18/30-18/39 */,
453         5       /* 18/40-18/49 */,
454         4       /* 18/50-18/59 */,
455         4       /* 18/60-18/69 */,
456         4       /* 18/70-18/79 */,
457         4       /* 18/80-18/89 */,
458         3       /* 18/90-18/99 */,
459         3       /* 18/100-18/109 */,
460         2       /* 18/110-18/119 */,
461         2       /* 18/120-18/129 */,
462         2       /* 18/130-18/139 */,
463         2       /* 18/140-18/149 */,
464         1       /* 18/150-18/159 */,
465         1       /* 18/160-18/169 */,
466         1       /* 18/170-18/179 */,
467         1       /* 18/180-18/189 */,
468         1       /* 18/190-18/199 */,
469         0       /* 18/200-18/209 */,
470         0       /* 18/210-18/219 */,
471         0       /* 18/220+ */
472 };
473
474 /*!
475  * 知力/賢さによる魔法失敗率修正テーブル
476  * Stat Table (INT/WIS) -- Various things
477  */
478 const byte adj_mag_stat[] =
479 {
480         0       /* 3 */,
481         0       /* 4 */,
482         0       /* 5 */,
483         0       /* 6 */,
484         0       /* 7 */,
485         1       /* 8 */,
486         1       /* 9 */,
487         1       /* 10 */,
488         1       /* 11 */,
489         1       /* 12 */,
490         1       /* 13 */,
491         1       /* 14 */,
492         2       /* 15 */,
493         2       /* 16 */,
494         2       /* 17 */,
495         3       /* 18/00-18/09 */,
496         3       /* 18/10-18/19 */,
497         3       /* 18/20-18/29 */,
498         3       /* 18/30-18/39 */,
499         3       /* 18/40-18/49 */,
500         4       /* 18/50-18/59 */,
501         4       /* 18/60-18/69 */,
502         5       /* 18/70-18/79 */,
503         6       /* 18/80-18/89 */,
504         7       /* 18/90-18/99 */,
505         8       /* 18/100-18/109 */,
506         9       /* 18/110-18/119 */,
507         10      /* 18/120-18/129 */,
508         11      /* 18/130-18/139 */,
509         12      /* 18/140-18/149 */,
510         13      /* 18/150-18/159 */,
511         14      /* 18/160-18/169 */,
512         15      /* 18/170-18/179 */,
513         16      /* 18/180-18/189 */,
514         17      /* 18/190-18/199 */,
515         18      /* 18/200-18/209 */,
516         19      /* 18/210-18/219 */,
517         20      /* 18/220+ */
518 };
519
520 /*!
521  * 魅力による店での取引修正テーブル
522  * Stat Table (CHR) -- payment percentages
523  */
524 const byte adj_chr_gold[] =
525 {
526         130     /* 3 */,
527         125     /* 4 */,
528         122     /* 5 */,
529         120     /* 6 */,
530         118     /* 7 */,
531         116     /* 8 */,
532         114     /* 9 */,
533         112     /* 10 */,
534         110     /* 11 */,
535         108     /* 12 */,
536         106     /* 13 */,
537         104     /* 14 */,
538         103     /* 15 */,
539         102     /* 16 */,
540         101     /* 17 */,
541         100     /* 18/00-18/09 */,
542         99      /* 18/10-18/19 */,
543         98      /* 18/20-18/29 */,
544         97      /* 18/30-18/39 */,
545         96      /* 18/40-18/49 */,
546         95      /* 18/50-18/59 */,
547         94      /* 18/60-18/69 */,
548         93      /* 18/70-18/79 */,
549         92      /* 18/80-18/89 */,
550         91      /* 18/90-18/99 */,
551         90      /* 18/100-18/109 */,
552         89      /* 18/110-18/119 */,
553         88      /* 18/120-18/129 */,
554         87      /* 18/130-18/139 */,
555         86      /* 18/140-18/149 */,
556         85      /* 18/150-18/159 */,
557         84      /* 18/160-18/169 */,
558         83      /* 18/170-18/179 */,
559         82      /* 18/180-18/189 */,
560         81      /* 18/190-18/199 */,
561         80      /* 18/200-18/209 */,
562         79      /* 18/210-18/219 */,
563         78      /* 18/220+ */
564 };
565
566 /*!
567  * 知力による魔道具使用修正テーブル
568  * Stat Table (INT) -- Magic devices
569  */
570 const byte adj_int_dev[] =
571 {
572         0       /* 3 */,
573         0       /* 4 */,
574         0       /* 5 */,
575         0       /* 6 */,
576         0       /* 7 */,
577         1       /* 8 */,
578         1       /* 9 */,
579         1       /* 10 */,
580         1       /* 11 */,
581         1       /* 12 */,
582         1       /* 13 */,
583         1       /* 14 */,
584         2       /* 15 */,
585         2       /* 16 */,
586         2       /* 17 */,
587         3       /* 18/00-18/09 */,
588         3       /* 18/10-18/19 */,
589         4       /* 18/20-18/29 */,
590         4       /* 18/30-18/39 */,
591         5       /* 18/40-18/49 */,
592         5       /* 18/50-18/59 */,
593         6       /* 18/60-18/69 */,
594         6       /* 18/70-18/79 */,
595         7       /* 18/80-18/89 */,
596         7       /* 18/90-18/99 */,
597         8       /* 18/100-18/109 */,
598         9       /* 18/110-18/119 */,
599         10      /* 18/120-18/129 */,
600         11      /* 18/130-18/139 */,
601         12      /* 18/140-18/149 */,
602         13      /* 18/150-18/159 */,
603         14      /* 18/160-18/169 */,
604         15      /* 18/170-18/179 */,
605         16      /* 18/180-18/189 */,
606         17      /* 18/190-18/199 */,
607         18      /* 18/200-18/209 */,
608         19      /* 18/210-18/219 */,
609         20      /* 18/220+ */
610 };
611
612 /*!
613  * 賢さによる魔法防御修正テーブル
614  * Stat Table (WIS) -- Saving throw
615  */
616 const byte adj_wis_sav[] =
617 {
618         0       /* 3 */,
619         0       /* 4 */,
620         0       /* 5 */,
621         0       /* 6 */,
622         0       /* 7 */,
623         1       /* 8 */,
624         1       /* 9 */,
625         1       /* 10 */,
626         1       /* 11 */,
627         1       /* 12 */,
628         1       /* 13 */,
629         1       /* 14 */,
630         2       /* 15 */,
631         2       /* 16 */,
632         2       /* 17 */,
633         3       /* 18/00-18/09 */,
634         3       /* 18/10-18/19 */,
635         3       /* 18/20-18/29 */,
636         3       /* 18/30-18/39 */,
637         3       /* 18/40-18/49 */,
638         4       /* 18/50-18/59 */,
639         4       /* 18/60-18/69 */,
640         5       /* 18/70-18/79 */,
641         5       /* 18/80-18/89 */,
642         6       /* 18/90-18/99 */,
643         7       /* 18/100-18/109 */,
644         8       /* 18/110-18/119 */,
645         9       /* 18/120-18/129 */,
646         10      /* 18/130-18/139 */,
647         11      /* 18/140-18/149 */,
648         12      /* 18/150-18/159 */,
649         13      /* 18/160-18/169 */,
650         14      /* 18/170-18/179 */,
651         15      /* 18/180-18/189 */,
652         16      /* 18/190-18/199 */,
653         17      /* 18/200-18/209 */,
654         18      /* 18/210-18/219 */,
655         19      /* 18/220+ */
656 };
657
658 /*!
659  * 器用さによるトラップ解除修正テーブル
660  * Stat Table (DEX) -- disarming
661  */
662 const byte adj_dex_dis[] =
663 {
664         0       /* 3 */,
665         0       /* 4 */,
666         0       /* 5 */,
667         0       /* 6 */,
668         0       /* 7 */,
669         0       /* 8 */,
670         0       /* 9 */,
671         0       /* 10 */,
672         0       /* 11 */,
673         0       /* 12 */,
674         1       /* 13 */,
675         1       /* 14 */,
676         1       /* 15 */,
677         2       /* 16 */,
678         2       /* 17 */,
679         4       /* 18/00-18/09 */,
680         4       /* 18/10-18/19 */,
681         4       /* 18/20-18/29 */,
682         4       /* 18/30-18/39 */,
683         5       /* 18/40-18/49 */,
684         5       /* 18/50-18/59 */,
685         5       /* 18/60-18/69 */,
686         6       /* 18/70-18/79 */,
687         6       /* 18/80-18/89 */,
688         7       /* 18/90-18/99 */,
689         8       /* 18/100-18/109 */,
690         8       /* 18/110-18/119 */,
691         8       /* 18/120-18/129 */,
692         8       /* 18/130-18/139 */,
693         8       /* 18/140-18/149 */,
694         9       /* 18/150-18/159 */,
695         9       /* 18/160-18/169 */,
696         9       /* 18/170-18/179 */,
697         9       /* 18/180-18/189 */,
698         9       /* 18/190-18/199 */,
699         10      /* 18/200-18/209 */,
700         10      /* 18/210-18/219 */,
701         10      /* 18/220+ */
702 };
703
704 /*!
705  * 知力によるトラップ解除修正テーブル
706  * Stat Table (INT) -- disarming
707  */
708 const byte adj_int_dis[] =
709 {
710         0       /* 3 */,
711         0       /* 4 */,
712         0       /* 5 */,
713         0       /* 6 */,
714         0       /* 7 */,
715         1       /* 8 */,
716         1       /* 9 */,
717         1       /* 10 */,
718         1       /* 11 */,
719         1       /* 12 */,
720         1       /* 13 */,
721         1       /* 14 */,
722         2       /* 15 */,
723         2       /* 16 */,
724         2       /* 17 */,
725         3       /* 18/00-18/09 */,
726         3       /* 18/10-18/19 */,
727         3       /* 18/20-18/29 */,
728         4       /* 18/30-18/39 */,
729         4       /* 18/40-18/49 */,
730         5       /* 18/50-18/59 */,
731         6       /* 18/60-18/69 */,
732         7       /* 18/70-18/79 */,
733         8       /* 18/80-18/89 */,
734         9       /* 18/90-18/99 */,
735         10      /* 18/100-18/109 */,
736         10      /* 18/110-18/119 */,
737         11      /* 18/120-18/129 */,
738         12      /* 18/130-18/139 */,
739         13      /* 18/140-18/149 */,
740         14      /* 18/150-18/159 */,
741         15      /* 18/160-18/169 */,
742         16      /* 18/170-18/179 */,
743         17      /* 18/180-18/189 */,
744         18      /* 18/190-18/199 */,
745         19      /* 18/200-18/209 */,
746         19      /* 18/210-18/219 */,
747         20      /* 18/220+ */
748 };
749
750 /*!
751  * 器用さによるAC修正テーブル
752  * Stat Table (DEX) -- bonus to ac (plus 128)
753  */
754 const byte adj_dex_ta[] =
755 {
756         128 + -4    /*  3 */,
757         128 + -3    /*  4 */,
758         128 + -2    /*  5 */,
759         128 + -1    /*  6 */,
760         128 + 0     /*  7 */,
761         128 + 0     /*  8 */,
762         128 + 0     /*  9 */,
763         128 + 0     /* 10 */,
764         128 + 0     /* 11 */,
765         128 + 0     /* 12 */,
766         128 + 0     /* 13 */,
767         128 + 0     /* 14 */,
768         128 + 1     /* 15 */,
769         128 + 1     /* 16 */,
770         128 + 1     /* 17 */,
771         128 + 2     /* 18/00-18/09 */,
772         128 + 2     /* 18/10-18/19 */,
773         128 + 2     /* 18/20-18/29 */,
774         128 + 2     /* 18/30-18/39 */,
775         128 + 2     /* 18/40-18/49 */,
776         128 + 3     /* 18/50-18/59 */,
777         128 + 3     /* 18/60-18/69 */,
778         128 + 3     /* 18/70-18/79 */,
779         128 + 4     /* 18/80-18/89 */,
780         128 + 5     /* 18/90-18/99 */,
781         128 + 6     /* 18/100-18/109 */,
782         128 + 7     /* 18/110-18/119 */,
783         128 + 8     /* 18/120-18/129 */,
784         128 + 9     /* 18/130-18/139 */,
785         128 + 9     /* 18/140-18/149 */,
786         128 + 10    /* 18/150-18/159 */,
787         128 + 11    /* 18/160-18/169 */,
788         128 + 12    /* 18/170-18/179 */,
789         128 + 13    /* 18/180-18/189 */,
790         128 + 14    /* 18/190-18/199 */,
791         128 + 15    /* 18/200-18/209 */,
792         128 + 15    /* 18/210-18/219 */,
793         128 + 16    /* 18/220+ */
794 };
795
796 /*!
797  * 腕力によるダメージ修正テーブル
798  * Stat Table (STR) -- bonus to dam (plus 128)
799  */
800 const byte adj_str_td[] =
801 {
802         128 + -2    /*  3 */,
803         128 + -2    /*  4 */,
804         128 + -1    /*  5 */,
805         128 + -1    /*  6 */,
806         128 + 0     /*  7 */,
807         128 + 0     /*  8 */,
808         128 + 0     /*  9 */,
809         128 + 0     /* 10 */,
810         128 + 0     /* 11 */,
811         128 + 0     /* 12 */,
812         128 + 0     /* 13 */,
813         128 + 0     /* 14 */,
814         128 + 0     /* 15 */,
815         128 + 1     /* 16 */,
816         128 + 2     /* 17 */,
817         128 + 2     /* 18/00-18/09 */,
818         128 + 2     /* 18/10-18/19 */,
819         128 + 3     /* 18/20-18/29 */,
820         128 + 3     /* 18/30-18/39 */,
821         128 + 3     /* 18/40-18/49 */,
822         128 + 3     /* 18/50-18/59 */,
823         128 + 3     /* 18/60-18/69 */,
824         128 + 4     /* 18/70-18/79 */,
825         128 + 5     /* 18/80-18/89 */,
826         128 + 5     /* 18/90-18/99 */,
827         128 + 6     /* 18/100-18/109 */,
828         128 + 7     /* 18/110-18/119 */,
829         128 + 8     /* 18/120-18/129 */,
830         128 + 9     /* 18/130-18/139 */,
831         128 + 10    /* 18/140-18/149 */,
832         128 + 11    /* 18/150-18/159 */,
833         128 + 12    /* 18/160-18/169 */,
834         128 + 13    /* 18/170-18/179 */,
835         128 + 14    /* 18/180-18/189 */,
836         128 + 15    /* 18/190-18/199 */,
837         128 + 16    /* 18/200-18/209 */,
838         128 + 18    /* 18/210-18/219 */,
839         128 + 20    /* 18/220+ */
840 };
841
842 /*!
843  * 器用度による命中修正テーブル
844  * Stat Table (DEX) -- bonus to hit (plus 128)
845  */
846 const byte adj_dex_th[] =
847 {
848         128 + -3        /* 3 */,
849         128 + -2        /* 4 */,
850         128 + -2        /* 5 */,
851         128 + -1        /* 6 */,
852         128 + -1        /* 7 */,
853         128 + 0 /* 8 */,
854         128 + 0 /* 9 */,
855         128 + 0 /* 10 */,
856         128 + 0 /* 11 */,
857         128 + 0 /* 12 */,
858         128 + 0 /* 13 */,
859         128 + 0 /* 14 */,
860         128 + 0 /* 15 */,
861         128 + 1 /* 16 */,
862         128 + 2 /* 17 */,
863         128 + 3 /* 18/00-18/09 */,
864         128 + 3 /* 18/10-18/19 */,
865         128 + 3 /* 18/20-18/29 */,
866         128 + 3 /* 18/30-18/39 */,
867         128 + 3 /* 18/40-18/49 */,
868         128 + 4 /* 18/50-18/59 */,
869         128 + 4 /* 18/60-18/69 */,
870         128 + 4 /* 18/70-18/79 */,
871         128 + 4 /* 18/80-18/89 */,
872         128 + 5 /* 18/90-18/99 */,
873         128 + 6 /* 18/100-18/109 */,
874         128 + 7 /* 18/110-18/119 */,
875         128 + 8 /* 18/120-18/129 */,
876         128 + 9 /* 18/130-18/139 */,
877         128 + 9 /* 18/140-18/149 */,
878         128 + 10        /* 18/150-18/159 */,
879         128 + 11        /* 18/160-18/169 */,
880         128 + 12        /* 18/170-18/179 */,
881         128 + 13        /* 18/180-18/189 */,
882         128 + 14        /* 18/190-18/199 */,
883         128 + 15        /* 18/200-18/209 */,
884         128 + 15        /* 18/210-18/219 */,
885         128 + 16        /* 18/220+ */
886 };
887
888 /*!
889  * 腕力による命中修正テーブル
890  * Stat Table (STR) -- bonus to hit (plus 128)
891  */
892 const byte adj_str_th[] =
893 {
894         128 + -3        /* 3 */,
895         128 + -2        /* 4 */,
896         128 + -1        /* 5 */,
897         128 + -1        /* 6 */,
898         128 + 0 /* 7 */,
899         128 + 0 /* 8 */,
900         128 + 0 /* 9 */,
901         128 + 0 /* 10 */,
902         128 + 0 /* 11 */,
903         128 + 0 /* 12 */,
904         128 + 0 /* 13 */,
905         128 + 0 /* 14 */,
906         128 + 0 /* 15 */,
907         128 + 0 /* 16 */,
908         128 + 0 /* 17 */,
909         128 + 1 /* 18/00-18/09 */,
910         128 + 1 /* 18/10-18/19 */,
911         128 + 1 /* 18/20-18/29 */,
912         128 + 1 /* 18/30-18/39 */,
913         128 + 1 /* 18/40-18/49 */,
914         128 + 1 /* 18/50-18/59 */,
915         128 + 1 /* 18/60-18/69 */,
916         128 + 2 /* 18/70-18/79 */,
917         128 + 3 /* 18/80-18/89 */,
918         128 + 4 /* 18/90-18/99 */,
919         128 + 5 /* 18/100-18/109 */,
920         128 + 6 /* 18/110-18/119 */,
921         128 + 7 /* 18/120-18/129 */,
922         128 + 8 /* 18/130-18/139 */,
923         128 + 9 /* 18/140-18/149 */,
924         128 + 10        /* 18/150-18/159 */,
925         128 + 11        /* 18/160-18/169 */,
926         128 + 12        /* 18/170-18/179 */,
927         128 + 13        /* 18/180-18/189 */,
928         128 + 14        /* 18/190-18/199 */,
929         128 + 15        /* 18/200-18/209 */,
930         128 + 15        /* 18/210-18/219 */,
931         128 + 16        /* 18/220+ */
932 };
933
934 /*!
935  * 腕力による基本所持重量値テーブル
936  * Stat Table (STR) -- weight limit in deca-pounds
937  */
938 const byte adj_str_wgt[] =
939 {
940         10      /* 3 */,
941         11      /* 4 */,
942         12      /* 5 */,
943         13      /* 6 */,
944         14      /* 7 */,
945         15      /* 8 */,
946         16      /* 9 */,
947         17      /* 10 */,
948         18      /* 11 */,
949         19      /* 12 */,
950         20      /* 13 */,
951         21      /* 14 */,
952         22      /* 15 */,
953         23      /* 16 */,
954         24      /* 17 */,
955         25      /* 18/00-18/09 */,
956         26      /* 18/10-18/19 */,
957         27      /* 18/20-18/29 */,
958         28      /* 18/30-18/39 */,
959         29      /* 18/40-18/49 */,
960         30      /* 18/50-18/59 */,
961         31      /* 18/60-18/69 */,
962         31      /* 18/70-18/79 */,
963         32      /* 18/80-18/89 */,
964         32      /* 18/90-18/99 */,
965         33      /* 18/100-18/109 */,
966         33      /* 18/110-18/119 */,
967         34      /* 18/120-18/129 */,
968         34      /* 18/130-18/139 */,
969         35      /* 18/140-18/149 */,
970         35      /* 18/150-18/159 */,
971         36      /* 18/160-18/169 */,
972         36      /* 18/170-18/179 */,
973         37      /* 18/180-18/189 */,
974         37      /* 18/190-18/199 */,
975         38      /* 18/200-18/209 */,
976         38      /* 18/210-18/219 */,
977         39      /* 18/220+ */
978 };
979
980 /*!
981  * 腕力による武器重量限界値テーブル
982  * Stat Table (STR) -- weapon weight limit in pounds
983  */
984 const byte adj_str_hold[] =
985 {
986         4       /* 3 */,
987         5       /* 4 */,
988         6       /* 5 */,
989         7       /* 6 */,
990         8       /* 7 */,
991         9       /* 8 */,
992         10      /* 9 */,
993         11      /* 10 */,
994         12      /* 11 */,
995         13      /* 12 */,
996         14      /* 13 */,
997         15      /* 14 */,
998         16      /* 15 */,
999         17      /* 16 */,
1000         18      /* 17 */,
1001         19      /* 18/00-18/09 */,
1002         20      /* 18/10-18/19 */,
1003         21      /* 18/20-18/29 */,
1004         22      /* 18/30-18/39 */,
1005         23      /* 18/40-18/49 */,
1006         24      /* 18/50-18/59 */,
1007         25      /* 18/60-18/69 */,
1008         26      /* 18/70-18/79 */,
1009         27      /* 18/80-18/89 */,
1010         28      /* 18/90-18/99 */,
1011         30      /* 18/100-18/109 */,
1012         31      /* 18/110-18/119 */,
1013         32      /* 18/120-18/129 */,
1014         33      /* 18/130-18/139 */,
1015         34      /* 18/140-18/149 */,
1016         35      /* 18/150-18/159 */,
1017         37      /* 18/160-18/169 */,
1018         40      /* 18/170-18/179 */,
1019         44      /* 18/180-18/189 */,
1020         48      /* 18/190-18/199 */,
1021         50     /* 18/200-18/209 */,
1022         50     /* 18/210-18/219 */,
1023         50     /* 18/220+ */
1024 };
1025
1026 /*!
1027  * 腕力による採掘能力修正値テーブル
1028  * Stat Table (STR) -- digging value
1029  */
1030 const byte adj_str_dig[] =
1031 {
1032         0       /* 3 */,
1033         0       /* 4 */,
1034         1       /* 5 */,
1035         2       /* 6 */,
1036         3       /* 7 */,
1037         4       /* 8 */,
1038         4       /* 9 */,
1039         5       /* 10 */,
1040         5       /* 11 */,
1041         6       /* 12 */,
1042         6       /* 13 */,
1043         7       /* 14 */,
1044         7       /* 15 */,
1045         8       /* 16 */,
1046         8       /* 17 */,
1047         9       /* 18/00-18/09 */,
1048         10      /* 18/10-18/19 */,
1049         12      /* 18/20-18/29 */,
1050         15      /* 18/30-18/39 */,
1051         20      /* 18/40-18/49 */,
1052         25      /* 18/50-18/59 */,
1053         30      /* 18/60-18/69 */,
1054         35      /* 18/70-18/79 */,
1055         40      /* 18/80-18/89 */,
1056         45      /* 18/90-18/99 */,
1057         50      /* 18/100-18/109 */,
1058         55      /* 18/110-18/119 */,
1059         60      /* 18/120-18/129 */,
1060         65      /* 18/130-18/139 */,
1061         70      /* 18/140-18/149 */,
1062         75      /* 18/150-18/159 */,
1063         80      /* 18/160-18/169 */,
1064         85      /* 18/170-18/179 */,
1065         90      /* 18/180-18/189 */,
1066         95      /* 18/190-18/199 */,
1067         100     /* 18/200-18/209 */,
1068         100     /* 18/210-18/219 */,
1069         100     /* 18/220+ */
1070 };
1071
1072 /*!
1073  * 器用さによる盗難防止&体当たり成功判定修正テーブル
1074  * Stat Table (DEX) -- chance of avoiding "theft" and "falling"
1075  */
1076 const byte adj_dex_safe[] =
1077 {
1078         0       /* 3 */,
1079         1       /* 4 */,
1080         2       /* 5 */,
1081         3       /* 6 */,
1082         4       /* 7 */,
1083         5       /* 8 */,
1084         5       /* 9 */,
1085         6       /* 10 */,
1086         6       /* 11 */,
1087         7       /* 12 */,
1088         7       /* 13 */,
1089         8       /* 14 */,
1090         8       /* 15 */,
1091         9       /* 16 */,
1092         9       /* 17 */,
1093         10      /* 18/00-18/09 */,
1094         10      /* 18/10-18/19 */,
1095         15      /* 18/20-18/29 */,
1096         15      /* 18/30-18/39 */,
1097         20      /* 18/40-18/49 */,
1098         25      /* 18/50-18/59 */,
1099         30      /* 18/60-18/69 */,
1100         35      /* 18/70-18/79 */,
1101         40      /* 18/80-18/89 */,
1102         45      /* 18/90-18/99 */,
1103         50      /* 18/100-18/109 */,
1104         60      /* 18/110-18/119 */,
1105         70      /* 18/120-18/129 */,
1106         80      /* 18/130-18/139 */,
1107         90      /* 18/140-18/149 */,
1108         100     /* 18/150-18/159 */,
1109         100     /* 18/160-18/169 */,
1110         100     /* 18/170-18/179 */,
1111         100     /* 18/180-18/189 */,
1112         100     /* 18/190-18/199 */,
1113         100     /* 18/200-18/209 */,
1114         100     /* 18/210-18/219 */,
1115         100     /* 18/220+ */
1116 };
1117
1118 /*!
1119  * 耐久による基本HP自然治癒値テーブル /
1120  * Stat Table (CON) -- base regeneration rate
1121  */
1122 const byte adj_con_fix[] =
1123 {
1124         0       /* 3 */,
1125         0       /* 4 */,
1126         0       /* 5 */,
1127         0       /* 6 */,
1128         0       /* 7 */,
1129         0       /* 8 */,
1130         0       /* 9 */,
1131         0       /* 10 */,
1132         0       /* 11 */,
1133         0       /* 12 */,
1134         0       /* 13 */,
1135         1       /* 14 */,
1136         1       /* 15 */,
1137         1       /* 16 */,
1138         1       /* 17 */,
1139         2       /* 18/00-18/09 */,
1140         2       /* 18/10-18/19 */,
1141         2       /* 18/20-18/29 */,
1142         2       /* 18/30-18/39 */,
1143         2       /* 18/40-18/49 */,
1144         3       /* 18/50-18/59 */,
1145         3       /* 18/60-18/69 */,
1146         3       /* 18/70-18/79 */,
1147         3       /* 18/80-18/89 */,
1148         3       /* 18/90-18/99 */,
1149         4       /* 18/100-18/109 */,
1150         4       /* 18/110-18/119 */,
1151         5       /* 18/120-18/129 */,
1152         6       /* 18/130-18/139 */,
1153         6       /* 18/140-18/149 */,
1154         7       /* 18/150-18/159 */,
1155         7       /* 18/160-18/169 */,
1156         8       /* 18/170-18/179 */,
1157         8       /* 18/180-18/189 */,
1158         8       /* 18/190-18/199 */,
1159         9       /* 18/200-18/209 */,
1160         9       /* 18/210-18/219 */,
1161         9       /* 18/220+ */
1162 };
1163
1164 /*!
1165  * 耐久による基本HP自然治癒値テーブル /
1166  * Stat Table (CON) -- extra 1/4-hitpoints per level (plus 128)
1167  */
1168 const byte adj_con_mhp[] =
1169 {
1170         128 + -8        /* 3 */,
1171         128 + -6        /* 4 */,
1172         128 + -4        /* 5 */,
1173         128 + -2        /* 6 */,
1174         128 + -1 /* 7 */,
1175         128 + 0 /* 8 */,
1176         128 + 0 /* 9 */,
1177         128 + 0 /* 10 */,
1178         128 + 0 /* 11 */,
1179         128 + 0 /* 12 */,
1180         128 + 0 /* 13 */,
1181         128 + 1 /* 14 */,
1182         128 + 1 /* 15 */,
1183         128 + 2 /* 16 */,
1184         128 + 3 /* 17 */,
1185         128 + 4 /* 18/00-18/09 */,
1186         128 + 5 /* 18/10-18/19 */,
1187         128 + 6 /* 18/20-18/29 */,
1188         128 + 7 /* 18/30-18/39 */,
1189         128 + 8 /* 18/40-18/49 */,
1190         128 + 9 /* 18/50-18/59 */,
1191         128 + 10  /* 18/60-18/69 */,
1192         128 + 11 /* 18/70-18/79 */,
1193         128 + 12 /* 18/80-18/89 */,
1194         128 + 14 /* 18/90-18/99 */,
1195         128 + 17         /* 18/100-18/109 */,
1196         128 + 20        /* 18/110-18/119 */,
1197         128 + 23        /* 18/120-18/129 */,
1198         128 + 26        /* 18/130-18/139 */,
1199         128 + 29        /* 18/140-18/149 */,
1200         128 + 32        /* 18/150-18/159 */,
1201         128 + 35        /* 18/160-18/169 */,
1202         128 + 38        /* 18/170-18/179 */,
1203         128 + 40        /* 18/180-18/189 */,
1204         128 + 42        /* 18/190-18/199 */,
1205         128 + 44        /* 18/200-18/209 */,
1206         128 + 46        /* 18/210-18/219 */,
1207         128 + 48        /* 18/220+ */
1208 };
1209
1210 /*!
1211  * 魅力による魅了能力修正テーブル /
1212  * Stat Table (CHR) -- charm
1213  */
1214 const byte adj_chr_chm[] =
1215 {
1216         0       /* 3 */,
1217         0       /* 4 */,
1218         1       /* 5 */,
1219         2       /* 6 */,
1220         3       /* 7 */,
1221         4       /* 8 */,
1222         4       /* 9 */,
1223         5       /* 10 */,
1224         5       /* 11 */,
1225         6       /* 12 */,
1226         6       /* 13 */,
1227         7       /* 14 */,
1228         7       /* 15 */,
1229         8       /* 16 */,
1230         8       /* 17 */,
1231         9       /* 18/00-18/09 */,
1232         10      /* 18/10-18/19 */,
1233         12      /* 18/20-18/29 */,
1234         15      /* 18/30-18/39 */,
1235         18      /* 18/40-18/49 */,
1236         21      /* 18/50-18/59 */,
1237         24      /* 18/60-18/69 */,
1238         28      /* 18/70-18/79 */,
1239         32      /* 18/80-18/89 */,
1240         36      /* 18/90-18/99 */,
1241         39      /* 18/100-18/109 */,
1242         42      /* 18/110-18/119 */,
1243         45      /* 18/120-18/129 */,
1244         49      /* 18/130-18/139 */,
1245         53      /* 18/140-18/149 */,
1246         57      /* 18/150-18/159 */,
1247         61      /* 18/160-18/169 */,
1248         65      /* 18/170-18/179 */,
1249         69      /* 18/180-18/189 */,
1250         73      /* 18/190-18/199 */,
1251         77      /* 18/200-18/209 */,
1252         81      /* 18/210-18/219 */,
1253         85      /* 18/220+ */
1254 };
1255
1256 /*** Player information ***/
1257
1258 /*
1259  * Static player info record
1260  */
1261 player_type p_body;
1262
1263 /*
1264  * Pointer to the player info
1265  */
1266 player_type *p_ptr = &p_body;
1267
1268 /*
1269  * Return alignment title
1270  */
1271 concptr your_alignment(player_type *creature_ptr)
1272 {
1273         if (creature_ptr->align > 150) return _("大善", "Lawful");
1274         else if (creature_ptr->align > 50) return _("中善", "Good");
1275         else if (creature_ptr->align > 10) return _("小善", "Neutral Good");
1276         else if (creature_ptr->align > -11) return _("中立", "Neutral");
1277         else if (creature_ptr->align > -51) return _("小悪", "Neutral Evil");
1278         else if (creature_ptr->align > -151) return _("中悪", "Evil");
1279         else return _("大悪", "Chaotic");
1280 }
1281
1282
1283 /*
1284  * Return proficiency level of weapons and misc. skills (except riding)
1285  */
1286 int weapon_exp_level(int weapon_exp)
1287 {
1288         if (weapon_exp < WEAPON_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
1289         else if (weapon_exp < WEAPON_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
1290         else if (weapon_exp < WEAPON_EXP_EXPERT) return EXP_LEVEL_SKILLED;
1291         else if (weapon_exp < WEAPON_EXP_MASTER) return EXP_LEVEL_EXPERT;
1292         else return EXP_LEVEL_MASTER;
1293 }
1294
1295
1296 /*
1297  * Return proficiency level of riding
1298  */
1299 int riding_exp_level(int riding_exp)
1300 {
1301         if (riding_exp < RIDING_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
1302         else if (riding_exp < RIDING_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
1303         else if (riding_exp < RIDING_EXP_EXPERT) return EXP_LEVEL_SKILLED;
1304         else if (riding_exp < RIDING_EXP_MASTER) return EXP_LEVEL_EXPERT;
1305         else return EXP_LEVEL_MASTER;
1306 }
1307
1308
1309 /*
1310  * Return proficiency level of spells
1311  */
1312 int spell_exp_level(int spell_exp)
1313 {
1314         if (spell_exp < SPELL_EXP_BEGINNER) return EXP_LEVEL_UNSKILLED;
1315         else if (spell_exp < SPELL_EXP_SKILLED) return EXP_LEVEL_BEGINNER;
1316         else if (spell_exp < SPELL_EXP_EXPERT) return EXP_LEVEL_SKILLED;
1317         else if (spell_exp < SPELL_EXP_MASTER) return EXP_LEVEL_EXPERT;
1318         else return EXP_LEVEL_MASTER;
1319 }
1320
1321
1322 /*!
1323  * @brief プレイヤーの全ステータスを更新する /
1324  * Calculate the players current "state", taking into account
1325  * not only race/class intrinsics, but also objects being worn
1326  * and temporary spell effects.
1327  * @return なし
1328  * @details
1329  * <pre>
1330  * See also calc_mana() and calc_hitpoints().
1331  *
1332  * Take note of the new "speed code", in particular, a very strong
1333  * player will start slowing down as soon as he reaches 150 pounds,
1334  * but not until he reaches 450 pounds will he be half as fast as
1335  * a normal kobold.  This both hurts and helps the player, hurts
1336  * because in the old days a player could just avoid 300 pounds,
1337  * and helps because now carrying 300 pounds is not very painful.
1338  *
1339  * The "weapon" and "bow" do *not* add to the bonuses to hit or to
1340  * damage, since that would affect non-combat things.  These values
1341  * are actually added in later, at the appropriate place.
1342  *
1343  * This function induces various "status" messages.
1344  * </pre>
1345  */
1346 void calc_bonuses(player_type *creature_ptr)
1347 {
1348         int hold;
1349         int new_speed;
1350         int default_hand = 0;
1351         int empty_hands_status = empty_hands(creature_ptr, TRUE);
1352         int extra_blows[2];
1353         object_type *o_ptr;
1354         BIT_FLAGS flgs[TR_FLAG_SIZE];
1355         bool omoi = FALSE;
1356         bool yoiyami = FALSE;
1357         bool down_saving = FALSE;
1358
1359         bool have_sw = FALSE, have_kabe = FALSE;
1360         bool easy_2weapon = FALSE;
1361         bool riding_levitation = FALSE;
1362         OBJECT_IDX this_o_idx, next_o_idx = 0;
1363         const player_race *tmp_rp_ptr;
1364
1365         /* Save the old vision stuff */
1366         bool old_telepathy = creature_ptr->telepathy;
1367         bool old_esp_animal = creature_ptr->esp_animal;
1368         bool old_esp_undead = creature_ptr->esp_undead;
1369         bool old_esp_demon = creature_ptr->esp_demon;
1370         bool old_esp_orc = creature_ptr->esp_orc;
1371         bool old_esp_troll = creature_ptr->esp_troll;
1372         bool old_esp_giant = creature_ptr->esp_giant;
1373         bool old_esp_dragon = creature_ptr->esp_dragon;
1374         bool old_esp_human = creature_ptr->esp_human;
1375         bool old_esp_evil = creature_ptr->esp_evil;
1376         bool old_esp_good = creature_ptr->esp_good;
1377         bool old_esp_nonliving = creature_ptr->esp_nonliving;
1378         bool old_esp_unique = creature_ptr->esp_unique;
1379         bool old_see_inv = creature_ptr->see_inv;
1380         bool old_mighty_throw = creature_ptr->mighty_throw;
1381
1382         /* Current feature under player. */
1383         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
1384         feature_type *f_ptr = &f_info[floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].feat];
1385
1386         /* Save the old armor class */
1387         ARMOUR_CLASS old_dis_ac = creature_ptr->dis_ac;
1388         ARMOUR_CLASS old_dis_to_a = creature_ptr->dis_to_a;
1389
1390         /* Clear extra blows/shots */
1391         extra_blows[0] = extra_blows[1] = 0;
1392
1393         /* Clear the stat modifiers */
1394         for (int i = 0; i < A_MAX; i++) creature_ptr->stat_add[i] = 0;
1395
1396
1397         /* Clear the Displayed/Real armor class */
1398         creature_ptr->dis_ac = creature_ptr->ac = 0;
1399
1400         /* Clear the Displayed/Real Bonuses */
1401         creature_ptr->dis_to_h[0] = creature_ptr->to_h[0] = 0;
1402         creature_ptr->dis_to_h[1] = creature_ptr->to_h[1] = 0;
1403         creature_ptr->dis_to_d[0] = creature_ptr->to_d[0] = 0;
1404         creature_ptr->dis_to_d[1] = creature_ptr->to_d[1] = 0;
1405         creature_ptr->dis_to_h_b = creature_ptr->to_h_b = 0;
1406         creature_ptr->dis_to_a = creature_ptr->to_a = 0;
1407         creature_ptr->to_h_m = 0;
1408         creature_ptr->to_d_m = 0;
1409
1410         creature_ptr->to_m_chance = 0;
1411
1412         /* Clear the Extra Dice Bonuses */
1413         creature_ptr->to_dd[0] = creature_ptr->to_ds[0] = 0;
1414         creature_ptr->to_dd[1] = creature_ptr->to_ds[1] = 0;
1415
1416         /* Start with "normal" speed */
1417         new_speed = 110;
1418
1419         /* Start with a single blow per turn */
1420         creature_ptr->num_blow[0] = 1;
1421         creature_ptr->num_blow[1] = 1;
1422
1423         /* Start with a single shot per turn */
1424         creature_ptr->num_fire = 100;
1425
1426         /* Reset the "xtra" tval */
1427         creature_ptr->tval_xtra = 0;
1428
1429         /* Reset the "ammo" tval */
1430         creature_ptr->tval_ammo = 0;
1431
1432         /* Clear all the flags */
1433         creature_ptr->cursed = 0L;
1434         creature_ptr->bless_blade = FALSE;
1435         creature_ptr->xtra_might = FALSE;
1436         creature_ptr->impact[0] = FALSE;
1437         creature_ptr->impact[1] = FALSE;
1438         creature_ptr->pass_wall = FALSE;
1439         creature_ptr->kill_wall = FALSE;
1440         creature_ptr->dec_mana = FALSE;
1441         creature_ptr->easy_spell = FALSE;
1442         creature_ptr->heavy_spell = FALSE;
1443         creature_ptr->see_inv = FALSE;
1444         creature_ptr->free_act = FALSE;
1445         creature_ptr->slow_digest = FALSE;
1446         creature_ptr->regenerate = FALSE;
1447         creature_ptr->can_swim = FALSE;
1448         creature_ptr->levitation = FALSE;
1449         creature_ptr->hold_exp = FALSE;
1450         creature_ptr->telepathy = FALSE;
1451         creature_ptr->esp_animal = FALSE;
1452         creature_ptr->esp_undead = FALSE;
1453         creature_ptr->esp_demon = FALSE;
1454         creature_ptr->esp_orc = FALSE;
1455         creature_ptr->esp_troll = FALSE;
1456         creature_ptr->esp_giant = FALSE;
1457         creature_ptr->esp_dragon = FALSE;
1458         creature_ptr->esp_human = FALSE;
1459         creature_ptr->esp_evil = FALSE;
1460         creature_ptr->esp_good = FALSE;
1461         creature_ptr->esp_nonliving = FALSE;
1462         creature_ptr->esp_unique = FALSE;
1463         creature_ptr->lite = FALSE;
1464         creature_ptr->sustain_str = FALSE;
1465         creature_ptr->sustain_int = FALSE;
1466         creature_ptr->sustain_wis = FALSE;
1467         creature_ptr->sustain_con = FALSE;
1468         creature_ptr->sustain_dex = FALSE;
1469         creature_ptr->sustain_chr = FALSE;
1470         creature_ptr->resist_acid = FALSE;
1471         creature_ptr->resist_elec = FALSE;
1472         creature_ptr->resist_fire = FALSE;
1473         creature_ptr->resist_cold = FALSE;
1474         creature_ptr->resist_pois = FALSE;
1475         creature_ptr->resist_conf = FALSE;
1476         creature_ptr->resist_sound = FALSE;
1477         creature_ptr->resist_lite = FALSE;
1478         creature_ptr->resist_dark = FALSE;
1479         creature_ptr->resist_chaos = FALSE;
1480         creature_ptr->resist_disen = FALSE;
1481         creature_ptr->resist_shard = FALSE;
1482         creature_ptr->resist_nexus = FALSE;
1483         creature_ptr->resist_blind = FALSE;
1484         creature_ptr->resist_neth = FALSE;
1485         creature_ptr->resist_time = FALSE;
1486         creature_ptr->resist_water = FALSE;
1487         creature_ptr->resist_fear = FALSE;
1488         creature_ptr->reflect = FALSE;
1489         creature_ptr->sh_fire = FALSE;
1490         creature_ptr->sh_elec = FALSE;
1491         creature_ptr->sh_cold = FALSE;
1492         creature_ptr->anti_magic = FALSE;
1493         creature_ptr->anti_tele = FALSE;
1494         creature_ptr->warning = FALSE;
1495         creature_ptr->mighty_throw = FALSE;
1496         creature_ptr->see_nocto = FALSE;
1497
1498         creature_ptr->immune_acid = FALSE;
1499         creature_ptr->immune_elec = FALSE;
1500         creature_ptr->immune_fire = FALSE;
1501         creature_ptr->immune_cold = FALSE;
1502
1503         creature_ptr->ryoute = FALSE;
1504         creature_ptr->migite = FALSE;
1505         creature_ptr->hidarite = FALSE;
1506         creature_ptr->no_flowed = FALSE;
1507
1508         if (creature_ptr->mimic_form) tmp_rp_ptr = &mimic_info[creature_ptr->mimic_form];
1509         else tmp_rp_ptr = &race_info[creature_ptr->prace];
1510
1511         /* Base infravision (purely racial) */
1512         creature_ptr->see_infra = tmp_rp_ptr->infra;
1513
1514         /* Base skill -- disarming */
1515         creature_ptr->skill_dis = tmp_rp_ptr->r_dis + cp_ptr->c_dis + ap_ptr->a_dis;
1516
1517         /* Base skill -- magic devices */
1518         creature_ptr->skill_dev = tmp_rp_ptr->r_dev + cp_ptr->c_dev + ap_ptr->a_dev;
1519
1520         /* Base skill -- saving throw */
1521         creature_ptr->skill_sav = tmp_rp_ptr->r_sav + cp_ptr->c_sav + ap_ptr->a_sav;
1522
1523         /* Base skill -- stealth */
1524         creature_ptr->skill_stl = tmp_rp_ptr->r_stl + cp_ptr->c_stl + ap_ptr->a_stl;
1525
1526         /* Base skill -- searching ability */
1527         creature_ptr->skill_srh = tmp_rp_ptr->r_srh + cp_ptr->c_srh + ap_ptr->a_srh;
1528
1529         /* Base skill -- searching frequency */
1530         creature_ptr->skill_fos = tmp_rp_ptr->r_fos + cp_ptr->c_fos + ap_ptr->a_fos;
1531
1532         /* Base skill -- combat (normal) */
1533         creature_ptr->skill_thn = tmp_rp_ptr->r_thn + cp_ptr->c_thn + ap_ptr->a_thn;
1534
1535         /* Base skill -- combat (shooting) */
1536         creature_ptr->skill_thb = tmp_rp_ptr->r_thb + cp_ptr->c_thb + ap_ptr->a_thb;
1537
1538         /* Base skill -- combat (throwing) */
1539         creature_ptr->skill_tht = tmp_rp_ptr->r_thb + cp_ptr->c_thb + ap_ptr->a_thb;
1540
1541         /* Base skill -- digging */
1542         creature_ptr->skill_dig = 0;
1543
1544         if (has_melee_weapon(creature_ptr, INVEN_RARM)) creature_ptr->migite = TRUE;
1545         if (has_melee_weapon(creature_ptr, INVEN_LARM))
1546         {
1547                 creature_ptr->hidarite = TRUE;
1548                 if (!creature_ptr->migite) default_hand = 1;
1549         }
1550
1551         if (can_two_hands_wielding(creature_ptr))
1552         {
1553                 if (creature_ptr->migite && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_LARM) &&
1554                         object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_RARM]))
1555                 {
1556                         creature_ptr->ryoute = TRUE;
1557                 }
1558                 else if (creature_ptr->hidarite && (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_RARM) &&
1559                         object_allow_two_hands_wielding(&creature_ptr->inventory_list[INVEN_LARM]))
1560                 {
1561                         creature_ptr->ryoute = TRUE;
1562                 }
1563                 else
1564                 {
1565                         switch (creature_ptr->pclass)
1566                         {
1567                         case CLASS_MONK:
1568                         case CLASS_FORCETRAINER:
1569                         case CLASS_BERSERKER:
1570                                 if (empty_hands(creature_ptr, FALSE) == (EMPTY_HAND_RARM | EMPTY_HAND_LARM))
1571                                 {
1572                                         creature_ptr->migite = TRUE;
1573                                         creature_ptr->ryoute = TRUE;
1574                                 }
1575                                 break;
1576                         }
1577                 }
1578         }
1579
1580         if (!creature_ptr->migite && !creature_ptr->hidarite)
1581         {
1582                 if (empty_hands_status & EMPTY_HAND_RARM) creature_ptr->migite = TRUE;
1583                 else if (empty_hands_status == EMPTY_HAND_LARM)
1584                 {
1585                         creature_ptr->hidarite = TRUE;
1586                         default_hand = 1;
1587                 }
1588         }
1589
1590         if (creature_ptr->special_defense & KAMAE_MASK)
1591         {
1592                 if (!(empty_hands_status & EMPTY_HAND_RARM))
1593                 {
1594                         set_action(creature_ptr, ACTION_NONE);
1595                 }
1596         }
1597
1598         switch (creature_ptr->pclass)
1599         {
1600         case CLASS_WARRIOR:
1601                 if (creature_ptr->lev > 29) creature_ptr->resist_fear = TRUE;
1602                 if (creature_ptr->lev > 44) creature_ptr->regenerate = TRUE;
1603                 break;
1604         case CLASS_PALADIN:
1605                 if (creature_ptr->lev > 39) creature_ptr->resist_fear = TRUE;
1606                 break;
1607         case CLASS_CHAOS_WARRIOR:
1608                 if (creature_ptr->lev > 29) creature_ptr->resist_chaos = TRUE;
1609                 if (creature_ptr->lev > 39) creature_ptr->resist_fear = TRUE;
1610                 break;
1611         case CLASS_MINDCRAFTER:
1612                 if (creature_ptr->lev > 9) creature_ptr->resist_fear = TRUE;
1613                 if (creature_ptr->lev > 19) creature_ptr->sustain_wis = TRUE;
1614                 if (creature_ptr->lev > 29) creature_ptr->resist_conf = TRUE;
1615                 if (creature_ptr->lev > 39) creature_ptr->telepathy = TRUE;
1616                 break;
1617         case CLASS_MONK:
1618         case CLASS_FORCETRAINER:
1619                 /* Unencumbered Monks become faster every 10 levels */
1620                 if (!(heavy_armor(creature_ptr)))
1621                 {
1622                         if (!(PRACE_IS_(creature_ptr, RACE_KLACKON) ||
1623                                 PRACE_IS_(creature_ptr, RACE_SPRITE) ||
1624                                 (creature_ptr->pseikaku == SEIKAKU_MUNCHKIN)))
1625                                 new_speed += (creature_ptr->lev) / 10;
1626
1627                         /* Free action if unencumbered at level 25 */
1628                         if (creature_ptr->lev > 24)
1629                                 creature_ptr->free_act = TRUE;
1630                 }
1631                 break;
1632         case CLASS_SORCERER:
1633                 creature_ptr->to_a -= 50;
1634                 creature_ptr->dis_to_a -= 50;
1635                 break;
1636         case CLASS_BARD:
1637                 creature_ptr->resist_sound = TRUE;
1638                 break;
1639         case CLASS_SAMURAI:
1640                 if (creature_ptr->lev > 29) creature_ptr->resist_fear = TRUE;
1641                 break;
1642         case CLASS_BERSERKER:
1643                 creature_ptr->shero = 1;
1644                 creature_ptr->sustain_str = TRUE;
1645                 creature_ptr->sustain_dex = TRUE;
1646                 creature_ptr->sustain_con = TRUE;
1647                 creature_ptr->regenerate = TRUE;
1648                 creature_ptr->free_act = TRUE;
1649                 new_speed += 2;
1650                 if (creature_ptr->lev > 29) new_speed++;
1651                 if (creature_ptr->lev > 39) new_speed++;
1652                 if (creature_ptr->lev > 44) new_speed++;
1653                 if (creature_ptr->lev > 49) new_speed++;
1654                 creature_ptr->to_a += 10 + creature_ptr->lev / 2;
1655                 creature_ptr->dis_to_a += 10 + creature_ptr->lev / 2;
1656                 creature_ptr->skill_dig += (100 + creature_ptr->lev * 8);
1657                 if (creature_ptr->lev > 39) creature_ptr->reflect = TRUE;
1658                 creature_ptr->redraw |= PR_STATUS;
1659                 break;
1660         case CLASS_MIRROR_MASTER:
1661                 if (creature_ptr->lev > 39) creature_ptr->reflect = TRUE;
1662                 break;
1663         case CLASS_NINJA:
1664                 /* Unencumbered Ninjas become faster every 10 levels */
1665                 if (heavy_armor(creature_ptr))
1666                 {
1667                         new_speed -= (creature_ptr->lev) / 10;
1668                         creature_ptr->skill_stl -= (creature_ptr->lev) / 10;
1669                 }
1670                 else if ((!creature_ptr->inventory_list[INVEN_RARM].k_idx || creature_ptr->migite) &&
1671                         (!creature_ptr->inventory_list[INVEN_LARM].k_idx || creature_ptr->hidarite))
1672                 {
1673                         new_speed += 3;
1674                         if (!(PRACE_IS_(creature_ptr, RACE_KLACKON) ||
1675                                 PRACE_IS_(creature_ptr, RACE_SPRITE) ||
1676                                 (creature_ptr->pseikaku == SEIKAKU_MUNCHKIN)))
1677                                 new_speed += (creature_ptr->lev) / 10;
1678                         creature_ptr->skill_stl += (creature_ptr->lev) / 10;
1679
1680                         /* Free action if unencumbered at level 25 */
1681                         if (creature_ptr->lev > 24)
1682                                 creature_ptr->free_act = TRUE;
1683                 }
1684                 if ((!creature_ptr->inventory_list[INVEN_RARM].k_idx || creature_ptr->migite) &&
1685                         (!creature_ptr->inventory_list[INVEN_LARM].k_idx || creature_ptr->hidarite))
1686                 {
1687                         creature_ptr->to_a += creature_ptr->lev / 2 + 5;
1688                         creature_ptr->dis_to_a += creature_ptr->lev / 2 + 5;
1689                 }
1690                 creature_ptr->slow_digest = TRUE;
1691                 creature_ptr->resist_fear = TRUE;
1692                 if (creature_ptr->lev > 19) creature_ptr->resist_pois = TRUE;
1693                 if (creature_ptr->lev > 24) creature_ptr->sustain_dex = TRUE;
1694                 if (creature_ptr->lev > 29) creature_ptr->see_inv = TRUE;
1695                 if (creature_ptr->lev > 44)
1696                 {
1697                         creature_ptr->oppose_pois = 1;
1698                         creature_ptr->redraw |= PR_STATUS;
1699                 }
1700                 creature_ptr->see_nocto = TRUE;
1701                 break;
1702         }
1703
1704         /***** Races ****/
1705         if (creature_ptr->mimic_form)
1706         {
1707                 switch (creature_ptr->mimic_form)
1708                 {
1709                 case MIMIC_DEMON:
1710                         creature_ptr->hold_exp = TRUE;
1711                         creature_ptr->resist_chaos = TRUE;
1712                         creature_ptr->resist_neth = TRUE;
1713                         creature_ptr->resist_fire = TRUE;
1714                         creature_ptr->oppose_fire = 1;
1715                         creature_ptr->see_inv = TRUE;
1716                         new_speed += 3;
1717                         creature_ptr->redraw |= PR_STATUS;
1718                         creature_ptr->to_a += 10;
1719                         creature_ptr->dis_to_a += 10;
1720                         break;
1721                 case MIMIC_DEMON_LORD:
1722                         creature_ptr->hold_exp = TRUE;
1723                         creature_ptr->resist_chaos = TRUE;
1724                         creature_ptr->resist_neth = TRUE;
1725                         creature_ptr->immune_fire = TRUE;
1726                         creature_ptr->resist_acid = TRUE;
1727                         creature_ptr->resist_fire = TRUE;
1728                         creature_ptr->resist_cold = TRUE;
1729                         creature_ptr->resist_elec = TRUE;
1730                         creature_ptr->resist_pois = TRUE;
1731                         creature_ptr->resist_conf = TRUE;
1732                         creature_ptr->resist_disen = TRUE;
1733                         creature_ptr->resist_nexus = TRUE;
1734                         creature_ptr->resist_fear = TRUE;
1735                         creature_ptr->sh_fire = TRUE;
1736                         creature_ptr->see_inv = TRUE;
1737                         creature_ptr->telepathy = TRUE;
1738                         creature_ptr->levitation = TRUE;
1739                         creature_ptr->kill_wall = TRUE;
1740                         new_speed += 5;
1741                         creature_ptr->to_a += 20;
1742                         creature_ptr->dis_to_a += 20;
1743                         break;
1744                 case MIMIC_VAMPIRE:
1745                         creature_ptr->resist_dark = TRUE;
1746                         creature_ptr->hold_exp = TRUE;
1747                         creature_ptr->resist_neth = TRUE;
1748                         creature_ptr->resist_cold = TRUE;
1749                         creature_ptr->resist_pois = TRUE;
1750                         creature_ptr->see_inv = TRUE;
1751                         new_speed += 3;
1752                         creature_ptr->to_a += 10;
1753                         creature_ptr->dis_to_a += 10;
1754                         if (creature_ptr->pclass != CLASS_NINJA) creature_ptr->lite = TRUE;
1755                         break;
1756                 }
1757         }
1758         else
1759         {
1760                 switch (creature_ptr->prace)
1761                 {
1762                 case RACE_ELF:
1763                         creature_ptr->resist_lite = TRUE;
1764                         break;
1765                 case RACE_HOBBIT:
1766                         creature_ptr->hold_exp = TRUE;
1767                         break;
1768                 case RACE_GNOME:
1769                         creature_ptr->free_act = TRUE;
1770                         break;
1771                 case RACE_DWARF:
1772                         creature_ptr->resist_blind = TRUE;
1773                         break;
1774                 case RACE_HALF_ORC:
1775                         creature_ptr->resist_dark = TRUE;
1776                         break;
1777                 case RACE_HALF_TROLL:
1778                         creature_ptr->sustain_str = TRUE;
1779
1780                         if (creature_ptr->lev > 14)
1781                         {
1782                                 /* High level trolls heal fast... */
1783                                 creature_ptr->regenerate = TRUE;
1784
1785                                 if (creature_ptr->pclass == CLASS_WARRIOR || creature_ptr->pclass == CLASS_BERSERKER)
1786                                 {
1787                                         creature_ptr->slow_digest = TRUE;
1788                                         /* Let's not make Regeneration
1789                                          * a disadvantage for the poor warriors who can
1790                                          * never learn a spell that satisfies hunger (actually
1791                                          * neither can rogues, but half-trolls are not
1792                                          * supposed to play rogues) */
1793                                 }
1794                         }
1795                         break;
1796                 case RACE_AMBERITE:
1797                         creature_ptr->sustain_con = TRUE;
1798                         creature_ptr->regenerate = TRUE;  /* Amberites heal fast... */
1799                         break;
1800                 case RACE_HIGH_ELF:
1801                         creature_ptr->resist_lite = TRUE;
1802                         creature_ptr->see_inv = TRUE;
1803                         break;
1804                 case RACE_BARBARIAN:
1805                         creature_ptr->resist_fear = TRUE;
1806                         break;
1807                 case RACE_HALF_OGRE:
1808                         creature_ptr->resist_dark = TRUE;
1809                         creature_ptr->sustain_str = TRUE;
1810                         break;
1811                 case RACE_HALF_GIANT:
1812                         creature_ptr->sustain_str = TRUE;
1813                         creature_ptr->resist_shard = TRUE;
1814                         break;
1815                 case RACE_HALF_TITAN:
1816                         creature_ptr->resist_chaos = TRUE;
1817                         break;
1818                 case RACE_CYCLOPS:
1819                         creature_ptr->resist_sound = TRUE;
1820                         break;
1821                 case RACE_YEEK:
1822                         creature_ptr->resist_acid = TRUE;
1823                         if (creature_ptr->lev > 19) creature_ptr->immune_acid = TRUE;
1824                         break;
1825                 case RACE_KLACKON:
1826                         creature_ptr->resist_conf = TRUE;
1827                         creature_ptr->resist_acid = TRUE;
1828
1829                         /* Klackons become faster */
1830                         new_speed += (creature_ptr->lev) / 10;
1831                         break;
1832                 case RACE_KOBOLD:
1833                         creature_ptr->resist_pois = TRUE;
1834                         break;
1835                 case RACE_NIBELUNG:
1836                         creature_ptr->resist_disen = TRUE;
1837                         creature_ptr->resist_dark = TRUE;
1838                         break;
1839                 case RACE_DARK_ELF:
1840                         creature_ptr->resist_dark = TRUE;
1841                         if (creature_ptr->lev > 19) creature_ptr->see_inv = TRUE;
1842                         break;
1843                 case RACE_DRACONIAN:
1844                         creature_ptr->levitation = TRUE;
1845                         if (creature_ptr->lev > 4) creature_ptr->resist_fire = TRUE;
1846                         if (creature_ptr->lev > 9) creature_ptr->resist_cold = TRUE;
1847                         if (creature_ptr->lev > 14) creature_ptr->resist_acid = TRUE;
1848                         if (creature_ptr->lev > 19) creature_ptr->resist_elec = TRUE;
1849                         if (creature_ptr->lev > 34) creature_ptr->resist_pois = TRUE;
1850                         break;
1851                 case RACE_MIND_FLAYER:
1852                         creature_ptr->sustain_int = TRUE;
1853                         creature_ptr->sustain_wis = TRUE;
1854                         if (creature_ptr->lev > 14) creature_ptr->see_inv = TRUE;
1855                         if (creature_ptr->lev > 29) creature_ptr->telepathy = TRUE;
1856                         break;
1857                 case RACE_IMP:
1858                         creature_ptr->resist_fire = TRUE;
1859                         if (creature_ptr->lev > 9) creature_ptr->see_inv = TRUE;
1860                         break;
1861                 case RACE_GOLEM:
1862                         creature_ptr->slow_digest = TRUE;
1863                         creature_ptr->free_act = TRUE;
1864                         creature_ptr->see_inv = TRUE;
1865                         creature_ptr->resist_pois = TRUE;
1866                         if (creature_ptr->lev > 34) creature_ptr->hold_exp = TRUE;
1867                         break;
1868                 case RACE_SKELETON:
1869                         creature_ptr->resist_shard = TRUE;
1870                         creature_ptr->hold_exp = TRUE;
1871                         creature_ptr->see_inv = TRUE;
1872                         creature_ptr->resist_pois = TRUE;
1873                         if (creature_ptr->lev > 9) creature_ptr->resist_cold = TRUE;
1874                         break;
1875                 case RACE_ZOMBIE:
1876                         creature_ptr->resist_neth = TRUE;
1877                         creature_ptr->hold_exp = TRUE;
1878                         creature_ptr->see_inv = TRUE;
1879                         creature_ptr->resist_pois = TRUE;
1880                         creature_ptr->slow_digest = TRUE;
1881                         if (creature_ptr->lev > 4) creature_ptr->resist_cold = TRUE;
1882                         break;
1883                 case RACE_VAMPIRE:
1884                         creature_ptr->resist_dark = TRUE;
1885                         creature_ptr->hold_exp = TRUE;
1886                         creature_ptr->resist_neth = TRUE;
1887                         creature_ptr->resist_cold = TRUE;
1888                         creature_ptr->resist_pois = TRUE;
1889                         if (creature_ptr->pclass != CLASS_NINJA) creature_ptr->lite = TRUE;
1890                         break;
1891                 case RACE_SPECTRE:
1892                         creature_ptr->levitation = TRUE;
1893                         creature_ptr->free_act = TRUE;
1894                         creature_ptr->resist_neth = TRUE;
1895                         creature_ptr->hold_exp = TRUE;
1896                         creature_ptr->see_inv = TRUE;
1897                         creature_ptr->resist_pois = TRUE;
1898                         creature_ptr->slow_digest = TRUE;
1899                         creature_ptr->resist_cold = TRUE;
1900                         creature_ptr->pass_wall = TRUE;
1901                         if (creature_ptr->lev > 34) creature_ptr->telepathy = TRUE;
1902                         break;
1903                 case RACE_SPRITE:
1904                         creature_ptr->levitation = TRUE;
1905                         creature_ptr->resist_lite = TRUE;
1906
1907                         /* Sprites become faster */
1908                         new_speed += (creature_ptr->lev) / 10;
1909                         break;
1910                 case RACE_BEASTMAN:
1911                         creature_ptr->resist_conf = TRUE;
1912                         creature_ptr->resist_sound = TRUE;
1913                         break;
1914                 case RACE_ENT:
1915                         /* Ents dig like maniacs, but only with their hands. */
1916                         if (!creature_ptr->inventory_list[INVEN_RARM].k_idx)
1917                                 creature_ptr->skill_dig += creature_ptr->lev * 10;
1918                         /* Ents get tougher and stronger as they age, but lose dexterity. */
1919                         if (creature_ptr->lev > 25) creature_ptr->stat_add[A_STR]++;
1920                         if (creature_ptr->lev > 40) creature_ptr->stat_add[A_STR]++;
1921                         if (creature_ptr->lev > 45) creature_ptr->stat_add[A_STR]++;
1922
1923                         if (creature_ptr->lev > 25) creature_ptr->stat_add[A_DEX]--;
1924                         if (creature_ptr->lev > 40) creature_ptr->stat_add[A_DEX]--;
1925                         if (creature_ptr->lev > 45) creature_ptr->stat_add[A_DEX]--;
1926
1927                         if (creature_ptr->lev > 25) creature_ptr->stat_add[A_CON]++;
1928                         if (creature_ptr->lev > 40) creature_ptr->stat_add[A_CON]++;
1929                         if (creature_ptr->lev > 45) creature_ptr->stat_add[A_CON]++;
1930                         break;
1931                 case RACE_ANGEL:
1932                         creature_ptr->levitation = TRUE;
1933                         creature_ptr->see_inv = TRUE;
1934                         break;
1935                 case RACE_DEMON:
1936                         creature_ptr->resist_fire = TRUE;
1937                         creature_ptr->resist_neth = TRUE;
1938                         creature_ptr->hold_exp = TRUE;
1939                         if (creature_ptr->lev > 9) creature_ptr->see_inv = TRUE;
1940                         if (creature_ptr->lev > 44)
1941                         {
1942                                 creature_ptr->oppose_fire = 1;
1943                                 creature_ptr->redraw |= PR_STATUS;
1944                         }
1945                         break;
1946                 case RACE_DUNADAN:
1947                         creature_ptr->sustain_con = TRUE;
1948                         break;
1949                 case RACE_S_FAIRY:
1950                         creature_ptr->levitation = TRUE;
1951                         break;
1952                 case RACE_KUTAR:
1953                         creature_ptr->resist_conf = TRUE;
1954                         break;
1955                 case RACE_ANDROID:
1956                         creature_ptr->slow_digest = TRUE;
1957                         creature_ptr->free_act = TRUE;
1958                         creature_ptr->resist_pois = TRUE;
1959                         creature_ptr->hold_exp = TRUE;
1960                         break;
1961                 case RACE_MERFOLK:
1962                         creature_ptr->resist_water = TRUE;
1963                         break;
1964                 default:
1965                         /* Do nothing */
1966                         ;
1967                 }
1968         }
1969
1970         if (creature_ptr->ult_res || (creature_ptr->special_defense & KATA_MUSOU))
1971         {
1972                 creature_ptr->see_inv = TRUE;
1973                 creature_ptr->free_act = TRUE;
1974                 creature_ptr->slow_digest = TRUE;
1975                 creature_ptr->regenerate = TRUE;
1976                 creature_ptr->levitation = TRUE;
1977                 creature_ptr->hold_exp = TRUE;
1978                 creature_ptr->telepathy = TRUE;
1979                 creature_ptr->lite = TRUE;
1980                 creature_ptr->sustain_str = TRUE;
1981                 creature_ptr->sustain_int = TRUE;
1982                 creature_ptr->sustain_wis = TRUE;
1983                 creature_ptr->sustain_con = TRUE;
1984                 creature_ptr->sustain_dex = TRUE;
1985                 creature_ptr->sustain_chr = TRUE;
1986                 creature_ptr->resist_acid = TRUE;
1987                 creature_ptr->resist_elec = TRUE;
1988                 creature_ptr->resist_fire = TRUE;
1989                 creature_ptr->resist_cold = TRUE;
1990                 creature_ptr->resist_pois = TRUE;
1991                 creature_ptr->resist_conf = TRUE;
1992                 creature_ptr->resist_sound = TRUE;
1993                 creature_ptr->resist_lite = TRUE;
1994                 creature_ptr->resist_dark = TRUE;
1995                 creature_ptr->resist_chaos = TRUE;
1996                 creature_ptr->resist_disen = TRUE;
1997                 creature_ptr->resist_shard = TRUE;
1998                 creature_ptr->resist_nexus = TRUE;
1999                 creature_ptr->resist_blind = TRUE;
2000                 creature_ptr->resist_neth = TRUE;
2001                 creature_ptr->resist_fear = TRUE;
2002                 creature_ptr->reflect = TRUE;
2003                 creature_ptr->sh_fire = TRUE;
2004                 creature_ptr->sh_elec = TRUE;
2005                 creature_ptr->sh_cold = TRUE;
2006                 creature_ptr->to_a += 100;
2007                 creature_ptr->dis_to_a += 100;
2008         }
2009         /* Temporary shield */
2010         else if (creature_ptr->tsubureru || creature_ptr->shield || creature_ptr->magicdef)
2011         {
2012                 creature_ptr->to_a += 50;
2013                 creature_ptr->dis_to_a += 50;
2014         }
2015
2016         if (creature_ptr->tim_res_nether)
2017         {
2018                 creature_ptr->resist_neth = TRUE;
2019         }
2020
2021         if (creature_ptr->tim_sh_fire)
2022         {
2023                 creature_ptr->sh_fire = TRUE;
2024         }
2025
2026         if (creature_ptr->tim_res_time)
2027         {
2028                 creature_ptr->resist_time = TRUE;
2029         }
2030
2031         /* Sexy Gal */
2032         if (creature_ptr->pseikaku == SEIKAKU_SEXY) creature_ptr->cursed |= (TRC_AGGRAVATE);
2033
2034         if (creature_ptr->pseikaku == SEIKAKU_NAMAKE) creature_ptr->to_m_chance += 10;
2035         if (creature_ptr->pseikaku == SEIKAKU_KIREMONO) creature_ptr->to_m_chance -= 3;
2036         if ((creature_ptr->pseikaku == SEIKAKU_GAMAN) || (creature_ptr->pseikaku == SEIKAKU_CHIKARA)) creature_ptr->to_m_chance++;
2037
2038         if (creature_ptr->pseikaku == SEIKAKU_CHARGEMAN)
2039         {
2040                 creature_ptr->to_m_chance += 5;
2041                 creature_ptr->resist_conf = TRUE;
2042         }
2043
2044         /* Lucky man */
2045         if (creature_ptr->pseikaku == SEIKAKU_LUCKY) creature_ptr->muta3 |= MUT3_GOOD_LUCK;
2046
2047         if (creature_ptr->pseikaku == SEIKAKU_MUNCHKIN)
2048         {
2049                 creature_ptr->resist_blind = TRUE;
2050                 creature_ptr->resist_conf = TRUE;
2051                 creature_ptr->hold_exp = TRUE;
2052                 if (creature_ptr->pclass != CLASS_NINJA) creature_ptr->lite = TRUE;
2053
2054                 if ((creature_ptr->prace != RACE_KLACKON) && (creature_ptr->prace != RACE_SPRITE))
2055                         /* Munchkin become faster */
2056                         new_speed += (creature_ptr->lev) / 10 + 5;
2057         }
2058
2059         if (music_singing(creature_ptr, MUSIC_WALL))
2060         {
2061                 creature_ptr->kill_wall = TRUE;
2062         }
2063
2064         /* Hack -- apply racial/class stat maxes */
2065         /* Apply the racial modifiers */
2066         for (int i = 0; i < A_MAX; i++)
2067         {
2068                 /* Modify the stats for "race" */
2069                 creature_ptr->stat_add[i] += (tmp_rp_ptr->r_adj[i] + cp_ptr->c_adj[i] + ap_ptr->a_adj[i]);
2070         }
2071
2072         /* I'm adding the mutations here for the lack of a better place... */
2073         if (creature_ptr->muta3)
2074         {
2075                 /* Hyper Strength */
2076                 if (creature_ptr->muta3 & MUT3_HYPER_STR)
2077                 {
2078                         creature_ptr->stat_add[A_STR] += 4;
2079                 }
2080
2081                 /* Puny */
2082                 if (creature_ptr->muta3 & MUT3_PUNY)
2083                 {
2084                         creature_ptr->stat_add[A_STR] -= 4;
2085                 }
2086
2087                 /* Living computer */
2088                 if (creature_ptr->muta3 & MUT3_HYPER_INT)
2089                 {
2090                         creature_ptr->stat_add[A_INT] += 4;
2091                         creature_ptr->stat_add[A_WIS] += 4;
2092                 }
2093
2094                 /* Moronic */
2095                 if (creature_ptr->muta3 & MUT3_MORONIC)
2096                 {
2097                         creature_ptr->stat_add[A_INT] -= 4;
2098                         creature_ptr->stat_add[A_WIS] -= 4;
2099                 }
2100
2101                 if (creature_ptr->muta3 & MUT3_RESILIENT)
2102                 {
2103                         creature_ptr->stat_add[A_CON] += 4;
2104                 }
2105
2106                 if (creature_ptr->muta3 & MUT3_XTRA_FAT)
2107                 {
2108                         creature_ptr->stat_add[A_CON] += 2;
2109                         new_speed -= 2;
2110                 }
2111
2112                 if (creature_ptr->muta3 & MUT3_ALBINO)
2113                 {
2114                         creature_ptr->stat_add[A_CON] -= 4;
2115                 }
2116
2117                 if (creature_ptr->muta3 & MUT3_FLESH_ROT)
2118                 {
2119                         creature_ptr->stat_add[A_CON] -= 2;
2120                         creature_ptr->stat_add[A_CHR] -= 1;
2121                         creature_ptr->regenerate = FALSE;
2122                         /* Cancel innate regeneration */
2123                 }
2124
2125                 if (creature_ptr->muta3 & MUT3_SILLY_VOI)
2126                 {
2127                         creature_ptr->stat_add[A_CHR] -= 4;
2128                 }
2129
2130                 if (creature_ptr->muta3 & MUT3_BLANK_FAC)
2131                 {
2132                         creature_ptr->stat_add[A_CHR] -= 1;
2133                 }
2134
2135                 if (creature_ptr->muta3 & MUT3_XTRA_EYES)
2136                 {
2137                         creature_ptr->skill_fos += 15;
2138                         creature_ptr->skill_srh += 15;
2139                 }
2140
2141                 if (creature_ptr->muta3 & MUT3_MAGIC_RES)
2142                 {
2143                         creature_ptr->skill_sav += (15 + (creature_ptr->lev / 5));
2144                 }
2145
2146                 if (creature_ptr->muta3 & MUT3_XTRA_NOIS)
2147                 {
2148                         creature_ptr->skill_stl -= 3;
2149                 }
2150
2151                 if (creature_ptr->muta3 & MUT3_INFRAVIS)
2152                 {
2153                         creature_ptr->see_infra += 3;
2154                 }
2155
2156                 if (creature_ptr->muta3 & MUT3_XTRA_LEGS)
2157                 {
2158                         new_speed += 3;
2159                 }
2160
2161                 if (creature_ptr->muta3 & MUT3_SHORT_LEG)
2162                 {
2163                         new_speed -= 3;
2164                 }
2165
2166                 if (creature_ptr->muta3 & MUT3_ELEC_TOUC)
2167                 {
2168                         creature_ptr->sh_elec = TRUE;
2169                 }
2170
2171                 if (creature_ptr->muta3 & MUT3_FIRE_BODY)
2172                 {
2173                         creature_ptr->sh_fire = TRUE;
2174                         creature_ptr->lite = TRUE;
2175                 }
2176
2177                 if (creature_ptr->muta3 & MUT3_WART_SKIN)
2178                 {
2179                         creature_ptr->stat_add[A_CHR] -= 2;
2180                         creature_ptr->to_a += 5;
2181                         creature_ptr->dis_to_a += 5;
2182                 }
2183
2184                 if (creature_ptr->muta3 & MUT3_SCALES)
2185                 {
2186                         creature_ptr->stat_add[A_CHR] -= 1;
2187                         creature_ptr->to_a += 10;
2188                         creature_ptr->dis_to_a += 10;
2189                 }
2190
2191                 if (creature_ptr->muta3 & MUT3_IRON_SKIN)
2192                 {
2193                         creature_ptr->stat_add[A_DEX] -= 1;
2194                         creature_ptr->to_a += 25;
2195                         creature_ptr->dis_to_a += 25;
2196                 }
2197
2198                 if (creature_ptr->muta3 & MUT3_WINGS)
2199                 {
2200                         creature_ptr->levitation = TRUE;
2201                 }
2202
2203                 if (creature_ptr->muta3 & MUT3_FEARLESS)
2204                 {
2205                         creature_ptr->resist_fear = TRUE;
2206                 }
2207
2208                 if (creature_ptr->muta3 & MUT3_REGEN)
2209                 {
2210                         creature_ptr->regenerate = TRUE;
2211                 }
2212
2213                 if (creature_ptr->muta3 & MUT3_ESP)
2214                 {
2215                         creature_ptr->telepathy = TRUE;
2216                 }
2217
2218                 if (creature_ptr->muta3 & MUT3_LIMBER)
2219                 {
2220                         creature_ptr->stat_add[A_DEX] += 3;
2221                 }
2222
2223                 if (creature_ptr->muta3 & MUT3_ARTHRITIS)
2224                 {
2225                         creature_ptr->stat_add[A_DEX] -= 3;
2226                 }
2227
2228                 if (creature_ptr->muta3 & MUT3_MOTION)
2229                 {
2230                         creature_ptr->free_act = TRUE;
2231                         creature_ptr->skill_stl += 1;
2232                 }
2233
2234                 if (creature_ptr->muta3 & MUT3_ILL_NORM)
2235                 {
2236                         creature_ptr->stat_add[A_CHR] = 0;
2237                 }
2238         }
2239
2240         if (creature_ptr->tsuyoshi)
2241         {
2242                 creature_ptr->stat_add[A_STR] += 4;
2243                 creature_ptr->stat_add[A_CON] += 4;
2244         }
2245
2246         /* Scan the usable creature_ptr->inventory_list */
2247         for (int i = INVEN_RARM; i < INVEN_TOTAL; i++)
2248         {
2249                 int bonus_to_h, bonus_to_d;
2250                 o_ptr = &creature_ptr->inventory_list[i];
2251                 if (!o_ptr->k_idx) continue;
2252
2253                 object_flags(o_ptr, flgs);
2254
2255                 creature_ptr->cursed |= (o_ptr->curse_flags & (0xFFFFFFF0L));
2256                 if (o_ptr->name1 == ART_CHAINSWORD) creature_ptr->cursed |= TRC_CHAINSWORD;
2257
2258                 /* Affect stats */
2259                 if (have_flag(flgs, TR_STR)) creature_ptr->stat_add[A_STR] += o_ptr->pval;
2260                 if (have_flag(flgs, TR_INT)) creature_ptr->stat_add[A_INT] += o_ptr->pval;
2261                 if (have_flag(flgs, TR_WIS)) creature_ptr->stat_add[A_WIS] += o_ptr->pval;
2262                 if (have_flag(flgs, TR_DEX)) creature_ptr->stat_add[A_DEX] += o_ptr->pval;
2263                 if (have_flag(flgs, TR_CON)) creature_ptr->stat_add[A_CON] += o_ptr->pval;
2264                 if (have_flag(flgs, TR_CHR)) creature_ptr->stat_add[A_CHR] += o_ptr->pval;
2265
2266                 if (have_flag(flgs, TR_MAGIC_MASTERY))    creature_ptr->skill_dev += 8 * o_ptr->pval;
2267
2268                 /* Affect stealth */
2269                 if (have_flag(flgs, TR_STEALTH)) creature_ptr->skill_stl += o_ptr->pval;
2270
2271                 /* Affect searching ability (factor of five) */
2272                 if (have_flag(flgs, TR_SEARCH)) creature_ptr->skill_srh += (o_ptr->pval * 5);
2273
2274                 /* Affect searching frequency (factor of five) */
2275                 if (have_flag(flgs, TR_SEARCH)) creature_ptr->skill_fos += (o_ptr->pval * 5);
2276
2277                 /* Affect infravision */
2278                 if (have_flag(flgs, TR_INFRA)) creature_ptr->see_infra += o_ptr->pval;
2279
2280                 /* Affect digging (factor of 20) */
2281                 if (have_flag(flgs, TR_TUNNEL)) creature_ptr->skill_dig += (o_ptr->pval * 20);
2282
2283                 /* Affect speed */
2284                 if (have_flag(flgs, TR_SPEED)) new_speed += o_ptr->pval;
2285
2286                 /* Affect blows */
2287                 if (have_flag(flgs, TR_BLOWS))
2288                 {
2289                         if ((i == INVEN_RARM || i == INVEN_RIGHT) && !creature_ptr->ryoute) extra_blows[0] += o_ptr->pval;
2290                         else if ((i == INVEN_LARM || i == INVEN_LEFT) && !creature_ptr->ryoute) extra_blows[1] += o_ptr->pval;
2291                         else { extra_blows[0] += o_ptr->pval; extra_blows[1] += o_ptr->pval; }
2292                 }
2293
2294                 /* Hack -- cause earthquakes */
2295                 if (have_flag(flgs, TR_IMPACT)) creature_ptr->impact[(i == INVEN_RARM) ? 0 : 1] = TRUE;
2296
2297                 /* Various flags */
2298                 if (have_flag(flgs, TR_AGGRAVATE))   creature_ptr->cursed |= TRC_AGGRAVATE;
2299                 if (have_flag(flgs, TR_DRAIN_EXP))   creature_ptr->cursed |= TRC_DRAIN_EXP;
2300                 if (have_flag(flgs, TR_TY_CURSE))    creature_ptr->cursed |= TRC_TY_CURSE;
2301                 if (have_flag(flgs, TR_ADD_L_CURSE)) creature_ptr->cursed |= TRC_ADD_L_CURSE;
2302                 if (have_flag(flgs, TR_ADD_H_CURSE)) creature_ptr->cursed |= TRC_ADD_H_CURSE;
2303                 if (have_flag(flgs, TR_DRAIN_HP))    creature_ptr->cursed |= TRC_DRAIN_HP;
2304                 if (have_flag(flgs, TR_DRAIN_MANA))  creature_ptr->cursed |= TRC_DRAIN_MANA;
2305                 if (have_flag(flgs, TR_CALL_ANIMAL)) creature_ptr->cursed |= TRC_CALL_ANIMAL;
2306                 if (have_flag(flgs, TR_CALL_DEMON))  creature_ptr->cursed |= TRC_CALL_DEMON;
2307                 if (have_flag(flgs, TR_CALL_DRAGON)) creature_ptr->cursed |= TRC_CALL_DRAGON;
2308                 if (have_flag(flgs, TR_CALL_UNDEAD)) creature_ptr->cursed |= TRC_CALL_UNDEAD;
2309                 if (have_flag(flgs, TR_COWARDICE))   creature_ptr->cursed |= TRC_COWARDICE;
2310                 if (have_flag(flgs, TR_LOW_MELEE))   creature_ptr->cursed |= TRC_LOW_MELEE;
2311                 if (have_flag(flgs, TR_LOW_AC))      creature_ptr->cursed |= TRC_LOW_AC;
2312                 if (have_flag(flgs, TR_LOW_MAGIC))   creature_ptr->cursed |= TRC_LOW_MAGIC;
2313                 if (have_flag(flgs, TR_FAST_DIGEST)) creature_ptr->cursed |= TRC_FAST_DIGEST;
2314                 if (have_flag(flgs, TR_SLOW_REGEN))  creature_ptr->cursed |= TRC_SLOW_REGEN;
2315                 if (have_flag(flgs, TR_DEC_MANA))    creature_ptr->dec_mana = TRUE;
2316                 if (have_flag(flgs, TR_BLESSED))     creature_ptr->bless_blade = TRUE;
2317                 if (have_flag(flgs, TR_XTRA_MIGHT))  creature_ptr->xtra_might = TRUE;
2318                 if (have_flag(flgs, TR_SLOW_DIGEST)) creature_ptr->slow_digest = TRUE;
2319                 if (have_flag(flgs, TR_REGEN))       creature_ptr->regenerate = TRUE;
2320                 if (have_flag(flgs, TR_TELEPATHY))   creature_ptr->telepathy = TRUE;
2321                 if (have_flag(flgs, TR_ESP_ANIMAL))  creature_ptr->esp_animal = TRUE;
2322                 if (have_flag(flgs, TR_ESP_UNDEAD))  creature_ptr->esp_undead = TRUE;
2323                 if (have_flag(flgs, TR_ESP_DEMON))   creature_ptr->esp_demon = TRUE;
2324                 if (have_flag(flgs, TR_ESP_ORC))     creature_ptr->esp_orc = TRUE;
2325                 if (have_flag(flgs, TR_ESP_TROLL))   creature_ptr->esp_troll = TRUE;
2326                 if (have_flag(flgs, TR_ESP_GIANT))   creature_ptr->esp_giant = TRUE;
2327                 if (have_flag(flgs, TR_ESP_DRAGON))  creature_ptr->esp_dragon = TRUE;
2328                 if (have_flag(flgs, TR_ESP_HUMAN))   creature_ptr->esp_human = TRUE;
2329                 if (have_flag(flgs, TR_ESP_EVIL))    creature_ptr->esp_evil = TRUE;
2330                 if (have_flag(flgs, TR_ESP_GOOD))    creature_ptr->esp_good = TRUE;
2331                 if (have_flag(flgs, TR_ESP_NONLIVING)) creature_ptr->esp_nonliving = TRUE;
2332                 if (have_flag(flgs, TR_ESP_UNIQUE))  creature_ptr->esp_unique = TRUE;
2333
2334                 if (have_flag(flgs, TR_SEE_INVIS))   creature_ptr->see_inv = TRUE;
2335                 if (have_flag(flgs, TR_LEVITATION))     creature_ptr->levitation = TRUE;
2336                 if (have_flag(flgs, TR_FREE_ACT))    creature_ptr->free_act = TRUE;
2337                 if (have_flag(flgs, TR_HOLD_EXP))   creature_ptr->hold_exp = TRUE;
2338                 if (have_flag(flgs, TR_WARNING)) {
2339                         if (!o_ptr->inscription || !(my_strchr(quark_str(o_ptr->inscription), '$')))
2340                                 creature_ptr->warning = TRUE;
2341                 }
2342
2343                 if (have_flag(flgs, TR_TELEPORT))
2344                 {
2345                         if (object_is_cursed(o_ptr)) creature_ptr->cursed |= TRC_TELEPORT;
2346                         else
2347                         {
2348                                 concptr insc = quark_str(o_ptr->inscription);
2349
2350                                 if (o_ptr->inscription && my_strchr(insc, '.'))
2351                                 {
2352                                         /*
2353                                          * {.} will stop random teleportation.
2354                                          */
2355                                 }
2356                                 else
2357                                 {
2358                                         /* Controlled random teleportation */
2359                                         creature_ptr->cursed |= TRC_TELEPORT_SELF;
2360                                 }
2361                         }
2362                 }
2363
2364                 /* Immunity flags */
2365                 if (have_flag(flgs, TR_IM_FIRE)) creature_ptr->immune_fire = TRUE;
2366                 if (have_flag(flgs, TR_IM_ACID)) creature_ptr->immune_acid = TRUE;
2367                 if (have_flag(flgs, TR_IM_COLD)) creature_ptr->immune_cold = TRUE;
2368                 if (have_flag(flgs, TR_IM_ELEC)) creature_ptr->immune_elec = TRUE;
2369
2370                 /* Resistance flags */
2371                 if (have_flag(flgs, TR_RES_ACID))   creature_ptr->resist_acid = TRUE;
2372                 if (have_flag(flgs, TR_RES_ELEC))   creature_ptr->resist_elec = TRUE;
2373                 if (have_flag(flgs, TR_RES_FIRE))   creature_ptr->resist_fire = TRUE;
2374                 if (have_flag(flgs, TR_RES_COLD))   creature_ptr->resist_cold = TRUE;
2375                 if (have_flag(flgs, TR_RES_POIS))   creature_ptr->resist_pois = TRUE;
2376                 if (have_flag(flgs, TR_RES_FEAR))   creature_ptr->resist_fear = TRUE;
2377                 if (have_flag(flgs, TR_RES_CONF))   creature_ptr->resist_conf = TRUE;
2378                 if (have_flag(flgs, TR_RES_SOUND))  creature_ptr->resist_sound = TRUE;
2379                 if (have_flag(flgs, TR_RES_LITE))   creature_ptr->resist_lite = TRUE;
2380                 if (have_flag(flgs, TR_RES_DARK))   creature_ptr->resist_dark = TRUE;
2381                 if (have_flag(flgs, TR_RES_CHAOS))  creature_ptr->resist_chaos = TRUE;
2382                 if (have_flag(flgs, TR_RES_DISEN))  creature_ptr->resist_disen = TRUE;
2383                 if (have_flag(flgs, TR_RES_SHARDS)) creature_ptr->resist_shard = TRUE;
2384                 if (have_flag(flgs, TR_RES_NEXUS))  creature_ptr->resist_nexus = TRUE;
2385                 if (have_flag(flgs, TR_RES_BLIND))  creature_ptr->resist_blind = TRUE;
2386                 if (have_flag(flgs, TR_RES_NETHER)) creature_ptr->resist_neth = TRUE;
2387
2388                 if (have_flag(flgs, TR_REFLECT))  creature_ptr->reflect = TRUE;
2389                 if (have_flag(flgs, TR_SH_FIRE))  creature_ptr->sh_fire = TRUE;
2390                 if (have_flag(flgs, TR_SH_ELEC))  creature_ptr->sh_elec = TRUE;
2391                 if (have_flag(flgs, TR_SH_COLD))  creature_ptr->sh_cold = TRUE;
2392                 if (have_flag(flgs, TR_NO_MAGIC)) creature_ptr->anti_magic = TRUE;
2393                 if (have_flag(flgs, TR_NO_TELE))  creature_ptr->anti_tele = TRUE;
2394
2395                 /* Sustain flags */
2396                 if (have_flag(flgs, TR_SUST_STR)) creature_ptr->sustain_str = TRUE;
2397                 if (have_flag(flgs, TR_SUST_INT)) creature_ptr->sustain_int = TRUE;
2398                 if (have_flag(flgs, TR_SUST_WIS)) creature_ptr->sustain_wis = TRUE;
2399                 if (have_flag(flgs, TR_SUST_DEX)) creature_ptr->sustain_dex = TRUE;
2400                 if (have_flag(flgs, TR_SUST_CON)) creature_ptr->sustain_con = TRUE;
2401                 if (have_flag(flgs, TR_SUST_CHR)) creature_ptr->sustain_chr = TRUE;
2402
2403                 if (o_ptr->name2 == EGO_YOIYAMI) yoiyami = TRUE;
2404                 if (o_ptr->name2 == EGO_2WEAPON) easy_2weapon = TRUE;
2405                 if (o_ptr->name2 == EGO_RING_RES_TIME) creature_ptr->resist_time = TRUE;
2406                 if (o_ptr->name2 == EGO_RING_THROW) creature_ptr->mighty_throw = TRUE;
2407                 if (have_flag(flgs, TR_EASY_SPELL)) creature_ptr->easy_spell = TRUE;
2408                 if (o_ptr->name2 == EGO_AMU_FOOL) creature_ptr->heavy_spell = TRUE;
2409                 if (o_ptr->name2 == EGO_AMU_NAIVETY) down_saving = TRUE;
2410
2411                 if (o_ptr->curse_flags & TRC_LOW_MAGIC)
2412                 {
2413                         if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
2414                         {
2415                                 creature_ptr->to_m_chance += 10;
2416                         }
2417                         else
2418                         {
2419                                 creature_ptr->to_m_chance += 3;
2420                         }
2421                 }
2422
2423                 if (o_ptr->tval == TV_CAPTURE) continue;
2424
2425                 /* Modify the base armor class */
2426                 creature_ptr->ac += o_ptr->ac;
2427
2428                 /* The base armor class is always known */
2429                 creature_ptr->dis_ac += o_ptr->ac;
2430
2431                 /* Apply the bonuses to armor class */
2432                 creature_ptr->to_a += o_ptr->to_a;
2433
2434                 /* Apply the mental bonuses to armor class, if known */
2435                 if (object_is_known(o_ptr)) creature_ptr->dis_to_a += o_ptr->to_a;
2436
2437                 if (o_ptr->curse_flags & TRC_LOW_MELEE)
2438                 {
2439                         int slot = i - INVEN_RARM;
2440                         if (slot < 2)
2441                         {
2442                                 if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
2443                                 {
2444                                         creature_ptr->to_h[slot] -= 15;
2445                                         if (o_ptr->ident & IDENT_MENTAL) creature_ptr->dis_to_h[slot] -= 15;
2446                                 }
2447                                 else
2448                                 {
2449                                         creature_ptr->to_h[slot] -= 5;
2450                                         if (o_ptr->ident & IDENT_MENTAL) creature_ptr->dis_to_h[slot] -= 5;
2451                                 }
2452                         }
2453                         else
2454                         {
2455                                 if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
2456                                 {
2457                                         creature_ptr->to_h_b -= 15;
2458                                         if (o_ptr->ident & IDENT_MENTAL) creature_ptr->dis_to_h_b -= 15;
2459                                 }
2460                                 else
2461                                 {
2462                                         creature_ptr->to_h_b -= 5;
2463                                         if (o_ptr->ident & IDENT_MENTAL) creature_ptr->dis_to_h_b -= 5;
2464                                 }
2465                         }
2466                 }
2467
2468                 if (o_ptr->curse_flags & TRC_LOW_AC)
2469                 {
2470                         if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
2471                         {
2472                                 creature_ptr->to_a -= 30;
2473                                 if (o_ptr->ident & IDENT_MENTAL) creature_ptr->dis_to_a -= 30;
2474                         }
2475                         else
2476                         {
2477                                 creature_ptr->to_a -= 10;
2478                                 if (o_ptr->ident & IDENT_MENTAL) creature_ptr->dis_to_a -= 10;
2479                         }
2480                 }
2481
2482                 /* Hack -- do not apply "weapon" bonuses */
2483                 if (i == INVEN_RARM && has_melee_weapon(creature_ptr, i)) continue;
2484                 if (i == INVEN_LARM && has_melee_weapon(creature_ptr, i)) continue;
2485
2486                 /* Hack -- do not apply "bow" bonuses */
2487                 if (i == INVEN_BOW) continue;
2488
2489                 bonus_to_h = o_ptr->to_h;
2490                 bonus_to_d = o_ptr->to_d;
2491
2492                 if (creature_ptr->pclass == CLASS_NINJA)
2493                 {
2494                         if (o_ptr->to_h > 0) bonus_to_h = (o_ptr->to_h + 1) / 2;
2495                         if (o_ptr->to_d > 0) bonus_to_d = (o_ptr->to_d + 1) / 2;
2496                 }
2497
2498                 /* To Bow and Natural attack */
2499
2500                 /* Apply the bonuses to hit/damage */
2501                 creature_ptr->to_h_b += (s16b)bonus_to_h;
2502                 creature_ptr->to_h_m += (s16b)bonus_to_h;
2503                 creature_ptr->to_d_m += (s16b)bonus_to_d;
2504
2505                 /* Apply the mental bonuses tp hit/damage, if known */
2506                 if (object_is_known(o_ptr)) creature_ptr->dis_to_h_b += (s16b)bonus_to_h;
2507
2508                 /* To Melee */
2509                 if ((i == INVEN_LEFT || i == INVEN_RIGHT) && !creature_ptr->ryoute)
2510                 {
2511                         /* Apply the bonuses to hit/damage */
2512                         creature_ptr->to_h[i - INVEN_RIGHT] += (s16b)bonus_to_h;
2513                         creature_ptr->to_d[i - INVEN_RIGHT] += (s16b)bonus_to_d;
2514
2515                         /* Apply the mental bonuses tp hit/damage, if known */
2516                         if (object_is_known(o_ptr))
2517                         {
2518                                 creature_ptr->dis_to_h[i - INVEN_RIGHT] += (s16b)bonus_to_h;
2519                                 creature_ptr->dis_to_d[i - INVEN_RIGHT] += (s16b)bonus_to_d;
2520                         }
2521
2522                         continue;
2523                 }
2524
2525                 if (creature_ptr->migite && creature_ptr->hidarite)
2526                 {
2527                         /* Apply the bonuses to hit/damage */
2528                         creature_ptr->to_h[0] += (bonus_to_h > 0) ? (bonus_to_h + 1) / 2 : bonus_to_h;
2529                         creature_ptr->to_h[1] += (bonus_to_h > 0) ? bonus_to_h / 2 : bonus_to_h;
2530                         creature_ptr->to_d[0] += (bonus_to_d > 0) ? (bonus_to_d + 1) / 2 : bonus_to_d;
2531                         creature_ptr->to_d[1] += (bonus_to_d > 0) ? bonus_to_d / 2 : bonus_to_d;
2532
2533                         /* Apply the mental bonuses tp hit/damage, if known */
2534                         if (!object_is_known(o_ptr)) continue;
2535
2536                         creature_ptr->dis_to_h[0] += (bonus_to_h > 0) ? (bonus_to_h + 1) / 2 : bonus_to_h;
2537                         creature_ptr->dis_to_h[1] += (bonus_to_h > 0) ? bonus_to_h / 2 : bonus_to_h;
2538                         creature_ptr->dis_to_d[0] += (bonus_to_d > 0) ? (bonus_to_d + 1) / 2 : bonus_to_d;
2539                         creature_ptr->dis_to_d[1] += (bonus_to_d > 0) ? bonus_to_d / 2 : bonus_to_d;
2540                         continue;
2541                 }
2542
2543                 /* Apply the bonuses to hit/damage */
2544                 creature_ptr->to_h[default_hand] += (s16b)bonus_to_h;
2545                 creature_ptr->to_d[default_hand] += (s16b)bonus_to_d;
2546
2547                 /* Apply the mental bonuses to hit/damage, if known */
2548                 if (!object_is_known(o_ptr)) continue;
2549
2550                 creature_ptr->dis_to_h[default_hand] += (s16b)bonus_to_h;
2551                 creature_ptr->dis_to_d[default_hand] += (s16b)bonus_to_d;
2552         }
2553
2554         /* Shield skill bonus */
2555         if (object_is_armour(&creature_ptr->inventory_list[INVEN_RARM]) || object_is_armour(&creature_ptr->inventory_list[INVEN_LARM]))
2556         {
2557                 creature_ptr->ac += creature_ptr->skill_exp[GINOU_SHIELD] * (1 + creature_ptr->lev / 22) / 2000;
2558                 creature_ptr->dis_ac += creature_ptr->skill_exp[GINOU_SHIELD] * (1 + creature_ptr->lev / 22) / 2000;
2559         }
2560
2561         if (old_mighty_throw != creature_ptr->mighty_throw)
2562         {
2563                 /* Redraw average damege display of Shuriken */
2564                 creature_ptr->window |= PW_INVEN;
2565         }
2566
2567         if (creature_ptr->cursed & TRC_TELEPORT) creature_ptr->cursed &= ~(TRC_TELEPORT_SELF);
2568
2569         /* Monks get extra ac for armour _not worn_ */
2570         if (((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER)) && !heavy_armor(creature_ptr))
2571         {
2572                 if (!(creature_ptr->inventory_list[INVEN_BODY].k_idx))
2573                 {
2574                         creature_ptr->to_a += (creature_ptr->lev * 3) / 2;
2575                         creature_ptr->dis_to_a += (creature_ptr->lev * 3) / 2;
2576                 }
2577                 if (!(creature_ptr->inventory_list[INVEN_OUTER].k_idx) && (creature_ptr->lev > 15))
2578                 {
2579                         creature_ptr->to_a += ((creature_ptr->lev - 13) / 3);
2580                         creature_ptr->dis_to_a += ((creature_ptr->lev - 13) / 3);
2581                 }
2582                 if (!(creature_ptr->inventory_list[INVEN_LARM].k_idx) && (creature_ptr->lev > 10))
2583                 {
2584                         creature_ptr->to_a += ((creature_ptr->lev - 8) / 3);
2585                         creature_ptr->dis_to_a += ((creature_ptr->lev - 8) / 3);
2586                 }
2587                 if (!(creature_ptr->inventory_list[INVEN_HEAD].k_idx) && (creature_ptr->lev > 4))
2588                 {
2589                         creature_ptr->to_a += (creature_ptr->lev - 2) / 3;
2590                         creature_ptr->dis_to_a += (creature_ptr->lev - 2) / 3;
2591                 }
2592                 if (!(creature_ptr->inventory_list[INVEN_HANDS].k_idx))
2593                 {
2594                         creature_ptr->to_a += (creature_ptr->lev / 2);
2595                         creature_ptr->dis_to_a += (creature_ptr->lev / 2);
2596                 }
2597                 if (!(creature_ptr->inventory_list[INVEN_FEET].k_idx))
2598                 {
2599                         creature_ptr->to_a += (creature_ptr->lev / 3);
2600                         creature_ptr->dis_to_a += (creature_ptr->lev / 3);
2601                 }
2602                 if (creature_ptr->special_defense & KAMAE_BYAKKO)
2603                 {
2604                         creature_ptr->stat_add[A_STR] += 2;
2605                         creature_ptr->stat_add[A_DEX] += 2;
2606                         creature_ptr->stat_add[A_CON] -= 3;
2607                 }
2608                 else if (creature_ptr->special_defense & KAMAE_SEIRYU)
2609                 {
2610                 }
2611                 else if (creature_ptr->special_defense & KAMAE_GENBU)
2612                 {
2613                         creature_ptr->stat_add[A_INT] -= 1;
2614                         creature_ptr->stat_add[A_WIS] -= 1;
2615                         creature_ptr->stat_add[A_DEX] -= 2;
2616                         creature_ptr->stat_add[A_CON] += 3;
2617                 }
2618                 else if (creature_ptr->special_defense & KAMAE_SUZAKU)
2619                 {
2620                         creature_ptr->stat_add[A_STR] -= 2;
2621                         creature_ptr->stat_add[A_INT] += 1;
2622                         creature_ptr->stat_add[A_WIS] += 1;
2623                         creature_ptr->stat_add[A_DEX] += 2;
2624                         creature_ptr->stat_add[A_CON] -= 2;
2625                 }
2626         }
2627
2628         if (creature_ptr->special_defense & KATA_KOUKIJIN)
2629         {
2630                 for (int i = 0; i < A_MAX; i++)
2631                         creature_ptr->stat_add[i] += 5;
2632                 creature_ptr->to_a -= 50;
2633                 creature_ptr->dis_to_a -= 50;
2634         }
2635
2636         /* Hack -- aura of fire also provides light */
2637         if (creature_ptr->sh_fire) creature_ptr->lite = TRUE;
2638
2639         /* Golems also get an intrinsic AC bonus */
2640         if (PRACE_IS_(creature_ptr, RACE_GOLEM) || PRACE_IS_(creature_ptr, RACE_ANDROID))
2641         {
2642                 creature_ptr->to_a += 10 + (creature_ptr->lev * 2 / 5);
2643                 creature_ptr->dis_to_a += 10 + (creature_ptr->lev * 2 / 5);
2644         }
2645
2646         /* Hex bonuses */
2647         if (creature_ptr->realm1 == REALM_HEX)
2648         {
2649                 if (hex_spelling_any(creature_ptr)) creature_ptr->skill_stl -= (1 + CASTING_HEX_NUM(creature_ptr));
2650                 if (hex_spelling(creature_ptr, HEX_DETECT_EVIL)) creature_ptr->esp_evil = TRUE;
2651                 if (hex_spelling(creature_ptr, HEX_XTRA_MIGHT)) creature_ptr->stat_add[A_STR] += 4;
2652                 if (hex_spelling(creature_ptr, HEX_BUILDING))
2653                 {
2654                         creature_ptr->stat_add[A_STR] += 4;
2655                         creature_ptr->stat_add[A_DEX] += 4;
2656                         creature_ptr->stat_add[A_CON] += 4;
2657                 }
2658
2659                 if (hex_spelling(creature_ptr, HEX_DEMON_AURA))
2660                 {
2661                         creature_ptr->sh_fire = TRUE;
2662                         creature_ptr->regenerate = TRUE;
2663                 }
2664
2665                 if (hex_spelling(creature_ptr, HEX_ICE_ARMOR))
2666                 {
2667                         creature_ptr->sh_cold = TRUE;
2668                         creature_ptr->to_a += 30;
2669                         creature_ptr->dis_to_a += 30;
2670                 }
2671
2672                 if (hex_spelling(creature_ptr, HEX_SHOCK_CLOAK))
2673                 {
2674                         creature_ptr->sh_elec = TRUE;
2675                         new_speed += 3;
2676                 }
2677
2678                 for (int i = INVEN_RARM; i <= INVEN_FEET; i++)
2679                 {
2680                         ARMOUR_CLASS ac = 0;
2681                         o_ptr = &creature_ptr->inventory_list[i];
2682                         if (!o_ptr->k_idx) continue;
2683                         if (!object_is_armour(o_ptr)) continue;
2684                         if (!object_is_cursed(o_ptr)) continue;
2685                         ac += 5;
2686                         if (o_ptr->curse_flags & TRC_HEAVY_CURSE) ac += 7;
2687                         if (o_ptr->curse_flags & TRC_PERMA_CURSE) ac += 13;
2688                         creature_ptr->to_a += (s16b)ac;
2689                         creature_ptr->dis_to_a += (s16b)ac;
2690                 }
2691         }
2692
2693         /* Calculate stats */
2694         int count = 0;
2695         for (int i = 0; i < A_MAX; i++)
2696         {
2697                 int top, use, ind;
2698
2699                 /* Extract the new "stat_use" value for the stat */
2700                 top = modify_stat_value(creature_ptr->stat_max[i], creature_ptr->stat_add[i]);
2701
2702                 /* Notice changes */
2703                 if (creature_ptr->stat_top[i] != top)
2704                 {
2705                         /* Save the new value */
2706                         creature_ptr->stat_top[i] = (s16b)top;
2707                         creature_ptr->redraw |= (PR_STATS);
2708                         creature_ptr->window |= (PW_PLAYER);
2709                 }
2710
2711                 /* Extract the new "stat_use" value for the stat */
2712                 use = modify_stat_value(creature_ptr->stat_cur[i], creature_ptr->stat_add[i]);
2713
2714                 if ((i == A_CHR) && (creature_ptr->muta3 & MUT3_ILL_NORM))
2715                 {
2716                         /* 10 to 18/90 charisma, guaranteed, based on level */
2717                         if (use < 8 + 2 * creature_ptr->lev)
2718                         {
2719                                 use = 8 + 2 * creature_ptr->lev;
2720                         }
2721                 }
2722
2723                 /* Notice changes */
2724                 if (creature_ptr->stat_use[i] != use)
2725                 {
2726                         /* Save the new value */
2727                         creature_ptr->stat_use[i] = (s16b)use;
2728                         creature_ptr->redraw |= (PR_STATS);
2729                         creature_ptr->window |= (PW_PLAYER);
2730                 }
2731
2732                 /* Values: 3, 4, ..., 17 */
2733                 if (use <= 18) ind = (use - 3);
2734
2735                 /* Ranges: 18/00-18/09, ..., 18/210-18/219 */
2736                 else if (use <= 18 + 219) ind = (15 + (use - 18) / 10);
2737
2738                 /* Range: 18/220+ */
2739                 else ind = (37);
2740
2741                 /* Notice changes */
2742                 if (creature_ptr->stat_ind[i] == ind) continue;
2743
2744                 /* Save the new index */
2745                 creature_ptr->stat_ind[i] = (s16b)ind;
2746
2747                 /* Change in CON affects Hitpoints */
2748                 if (i == A_CON)
2749                 {
2750                         creature_ptr->update |= (PU_HP);
2751                 }
2752
2753                 /* Change in INT may affect Mana/Spells */
2754                 else if (i == A_INT)
2755                 {
2756                         if (mp_ptr->spell_stat == A_INT)
2757                         {
2758                                 creature_ptr->update |= (PU_MANA | PU_SPELLS);
2759                         }
2760                 }
2761
2762                 /* Change in WIS may affect Mana/Spells */
2763                 else if (i == A_WIS)
2764                 {
2765                         if (mp_ptr->spell_stat == A_WIS)
2766                         {
2767                                 creature_ptr->update |= (PU_MANA | PU_SPELLS);
2768                         }
2769                 }
2770
2771                 /* Change in WIS may affect Mana/Spells */
2772                 else if (i == A_CHR)
2773                 {
2774                         if (mp_ptr->spell_stat == A_CHR)
2775                         {
2776                                 creature_ptr->update |= (PU_MANA | PU_SPELLS);
2777                         }
2778                 }
2779
2780                 creature_ptr->window |= (PW_PLAYER);
2781                 count++;
2782         }
2783
2784         /* Apply temporary "stun" */
2785         if (creature_ptr->stun > 50)
2786         {
2787                 creature_ptr->to_h[0] -= 20;
2788                 creature_ptr->to_h[1] -= 20;
2789                 creature_ptr->to_h_b -= 20;
2790                 creature_ptr->to_h_m -= 20;
2791                 creature_ptr->dis_to_h[0] -= 20;
2792                 creature_ptr->dis_to_h[1] -= 20;
2793                 creature_ptr->dis_to_h_b -= 20;
2794                 creature_ptr->to_d[0] -= 20;
2795                 creature_ptr->to_d[1] -= 20;
2796                 creature_ptr->to_d_m -= 20;
2797                 creature_ptr->dis_to_d[0] -= 20;
2798                 creature_ptr->dis_to_d[1] -= 20;
2799         }
2800         else if (creature_ptr->stun)
2801         {
2802                 creature_ptr->to_h[0] -= 5;
2803                 creature_ptr->to_h[1] -= 5;
2804                 creature_ptr->to_h_b -= 5;
2805                 creature_ptr->to_h_m -= 5;
2806                 creature_ptr->dis_to_h[0] -= 5;
2807                 creature_ptr->dis_to_h[1] -= 5;
2808                 creature_ptr->dis_to_h_b -= 5;
2809                 creature_ptr->to_d[0] -= 5;
2810                 creature_ptr->to_d[1] -= 5;
2811                 creature_ptr->to_d_m -= 5;
2812                 creature_ptr->dis_to_d[0] -= 5;
2813                 creature_ptr->dis_to_d[1] -= 5;
2814         }
2815
2816         /* Wraith form */
2817         if (creature_ptr->wraith_form)
2818         {
2819                 creature_ptr->reflect = TRUE;
2820                 creature_ptr->pass_wall = TRUE;
2821         }
2822
2823         if (creature_ptr->kabenuke)
2824         {
2825                 creature_ptr->pass_wall = TRUE;
2826         }
2827
2828         /* Temporary blessing */
2829         if (is_blessed(creature_ptr))
2830         {
2831                 creature_ptr->to_a += 5;
2832                 creature_ptr->dis_to_a += 5;
2833                 creature_ptr->to_h[0] += 10;
2834                 creature_ptr->to_h[1] += 10;
2835                 creature_ptr->to_h_b += 10;
2836                 creature_ptr->to_h_m += 10;
2837                 creature_ptr->dis_to_h[0] += 10;
2838                 creature_ptr->dis_to_h[1] += 10;
2839                 creature_ptr->dis_to_h_b += 10;
2840         }
2841
2842         if (creature_ptr->magicdef)
2843         {
2844                 creature_ptr->resist_blind = TRUE;
2845                 creature_ptr->resist_conf = TRUE;
2846                 creature_ptr->reflect = TRUE;
2847                 creature_ptr->free_act = TRUE;
2848                 creature_ptr->levitation = TRUE;
2849         }
2850
2851         /* Temporary "Hero" */
2852         if (IS_HERO(creature_ptr))
2853         {
2854                 creature_ptr->to_h[0] += 12;
2855                 creature_ptr->to_h[1] += 12;
2856                 creature_ptr->to_h_b += 12;
2857                 creature_ptr->to_h_m += 12;
2858                 creature_ptr->dis_to_h[0] += 12;
2859                 creature_ptr->dis_to_h[1] += 12;
2860                 creature_ptr->dis_to_h_b += 12;
2861         }
2862
2863         /* Temporary "Beserk" */
2864         if (creature_ptr->shero)
2865         {
2866                 creature_ptr->to_h[0] += 12;
2867                 creature_ptr->to_h[1] += 12;
2868                 creature_ptr->to_h_b -= 12;
2869                 creature_ptr->to_h_m += 12;
2870                 creature_ptr->to_d[0] += 3 + (creature_ptr->lev / 5);
2871                 creature_ptr->to_d[1] += 3 + (creature_ptr->lev / 5);
2872                 creature_ptr->to_d_m += 3 + (creature_ptr->lev / 5);
2873                 creature_ptr->dis_to_h[0] += 12;
2874                 creature_ptr->dis_to_h[1] += 12;
2875                 creature_ptr->dis_to_h_b -= 12;
2876                 creature_ptr->dis_to_d[0] += 3 + (creature_ptr->lev / 5);
2877                 creature_ptr->dis_to_d[1] += 3 + (creature_ptr->lev / 5);
2878                 creature_ptr->to_a -= 10;
2879                 creature_ptr->dis_to_a -= 10;
2880                 creature_ptr->skill_stl -= 7;
2881                 creature_ptr->skill_dev -= 20;
2882                 creature_ptr->skill_sav -= 30;
2883                 creature_ptr->skill_srh -= 15;
2884                 creature_ptr->skill_fos -= 15;
2885                 creature_ptr->skill_tht -= 20;
2886                 creature_ptr->skill_dig += 30;
2887         }
2888
2889         /* Temporary "fast" */
2890         if (IS_FAST(creature_ptr))
2891         {
2892                 new_speed += 10;
2893         }
2894
2895         /* Temporary "slow" */
2896         if (creature_ptr->slow)
2897         {
2898                 new_speed -= 10;
2899         }
2900
2901         /* Temporary "telepathy" */
2902         if (is_time_limit_esp(creature_ptr))
2903         {
2904                 creature_ptr->telepathy = TRUE;
2905         }
2906
2907         if (creature_ptr->ele_immune)
2908         {
2909                 if (creature_ptr->special_defense & DEFENSE_ACID)
2910                         creature_ptr->immune_acid = TRUE;
2911                 else if (creature_ptr->special_defense & DEFENSE_ELEC)
2912                         creature_ptr->immune_elec = TRUE;
2913                 else if (creature_ptr->special_defense & DEFENSE_FIRE)
2914                         creature_ptr->immune_fire = TRUE;
2915                 else if (creature_ptr->special_defense & DEFENSE_COLD)
2916                         creature_ptr->immune_cold = TRUE;
2917         }
2918
2919         /* Temporary see invisible */
2920         if (creature_ptr->tim_invis)
2921         {
2922                 creature_ptr->see_inv = TRUE;
2923         }
2924
2925         /* Temporary infravision boost */
2926         if (creature_ptr->tim_infra)
2927         {
2928                 creature_ptr->see_infra += 3;
2929         }
2930
2931         /* Temporary regeneration boost */
2932         if (creature_ptr->tim_regen)
2933         {
2934                 creature_ptr->regenerate = TRUE;
2935         }
2936
2937         /* Temporary levitation */
2938         if (creature_ptr->tim_levitation)
2939         {
2940                 creature_ptr->levitation = TRUE;
2941         }
2942
2943         /* Temporary reflection */
2944         if (creature_ptr->tim_reflect)
2945         {
2946                 creature_ptr->reflect = TRUE;
2947         }
2948
2949         /* Hack -- Hero/Shero -> Res fear */
2950         if (IS_HERO(creature_ptr) || creature_ptr->shero)
2951         {
2952                 creature_ptr->resist_fear = TRUE;
2953         }
2954
2955         /* Hack -- Telepathy Change */
2956         if (creature_ptr->telepathy != old_telepathy)
2957         {
2958                 creature_ptr->update |= (PU_MONSTERS);
2959         }
2960
2961         if ((creature_ptr->esp_animal != old_esp_animal) ||
2962                 (creature_ptr->esp_undead != old_esp_undead) ||
2963                 (creature_ptr->esp_demon != old_esp_demon) ||
2964                 (creature_ptr->esp_orc != old_esp_orc) ||
2965                 (creature_ptr->esp_troll != old_esp_troll) ||
2966                 (creature_ptr->esp_giant != old_esp_giant) ||
2967                 (creature_ptr->esp_dragon != old_esp_dragon) ||
2968                 (creature_ptr->esp_human != old_esp_human) ||
2969                 (creature_ptr->esp_evil != old_esp_evil) ||
2970                 (creature_ptr->esp_good != old_esp_good) ||
2971                 (creature_ptr->esp_nonliving != old_esp_nonliving) ||
2972                 (creature_ptr->esp_unique != old_esp_unique))
2973         {
2974                 creature_ptr->update |= (PU_MONSTERS);
2975         }
2976
2977         /* Hack -- See Invis Change */
2978         if (creature_ptr->see_inv != old_see_inv)
2979         {
2980                 creature_ptr->update |= (PU_MONSTERS);
2981         }
2982
2983         /* Bloating slows the player down (a little) */
2984         if (creature_ptr->food >= PY_FOOD_MAX) new_speed -= 10;
2985
2986         if (creature_ptr->special_defense & KAMAE_SUZAKU) new_speed += 10;
2987
2988         if ((creature_ptr->migite && (empty_hands_status & EMPTY_HAND_RARM)) ||
2989                 (creature_ptr->hidarite && (empty_hands_status & EMPTY_HAND_LARM)))
2990         {
2991                 creature_ptr->to_h[default_hand] += (creature_ptr->skill_exp[GINOU_SUDE] - WEAPON_EXP_BEGINNER) / 200;
2992                 creature_ptr->dis_to_h[default_hand] += (creature_ptr->skill_exp[GINOU_SUDE] - WEAPON_EXP_BEGINNER) / 200;
2993         }
2994
2995         if (has_melee_weapon(creature_ptr, INVEN_RARM) && has_melee_weapon(creature_ptr, INVEN_LARM))
2996         {
2997                 int penalty1, penalty2;
2998                 penalty1 = ((100 - creature_ptr->skill_exp[GINOU_NITOURYU] / 160) - (130 - creature_ptr->inventory_list[INVEN_RARM].weight) / 8);
2999                 penalty2 = ((100 - creature_ptr->skill_exp[GINOU_NITOURYU] / 160) - (130 - creature_ptr->inventory_list[INVEN_LARM].weight) / 8);
3000                 if ((creature_ptr->inventory_list[INVEN_RARM].name1 == ART_QUICKTHORN) && (creature_ptr->inventory_list[INVEN_LARM].name1 == ART_TINYTHORN))
3001                 {
3002                         penalty1 = penalty1 / 2 - 5;
3003                         penalty2 = penalty2 / 2 - 5;
3004                         new_speed += 7;
3005                         creature_ptr->to_a += 10;
3006                         creature_ptr->dis_to_a += 10;
3007                 }
3008                 if (easy_2weapon)
3009                 {
3010                         if (penalty1 > 0) penalty1 /= 2;
3011                         if (penalty2 > 0) penalty2 /= 2;
3012                 }
3013                 else if ((creature_ptr->inventory_list[INVEN_LARM].tval == TV_SWORD) && ((creature_ptr->inventory_list[INVEN_LARM].sval == SV_MAIN_GAUCHE) || (creature_ptr->inventory_list[INVEN_LARM].sval == SV_WAKIZASHI)))
3014                 {
3015                         penalty1 = MAX(0, penalty1 - 10);
3016                         penalty2 = MAX(0, penalty2 - 10);
3017                 }
3018                 if ((creature_ptr->inventory_list[INVEN_RARM].name1 == ART_MUSASI_KATANA) && (creature_ptr->inventory_list[INVEN_LARM].name1 == ART_MUSASI_WAKIZASI))
3019                 {
3020                         penalty1 = MIN(0, penalty1);
3021                         penalty2 = MIN(0, penalty2);
3022                         creature_ptr->to_a += 10;
3023                         creature_ptr->dis_to_a += 10;
3024                 }
3025                 else
3026                 {
3027                         if ((creature_ptr->inventory_list[INVEN_RARM].name1 == ART_MUSASI_KATANA) && (penalty1 > 0))
3028                                 penalty1 /= 2;
3029                         if ((creature_ptr->inventory_list[INVEN_LARM].name1 == ART_MUSASI_WAKIZASI) && (penalty2 > 0))
3030                                 penalty2 /= 2;
3031                 }
3032
3033                 if (creature_ptr->inventory_list[INVEN_RARM].tval == TV_POLEARM) penalty1 += 10;
3034                 if (creature_ptr->inventory_list[INVEN_LARM].tval == TV_POLEARM) penalty2 += 10;
3035                 creature_ptr->to_h[0] -= (s16b)penalty1;
3036                 creature_ptr->to_h[1] -= (s16b)penalty2;
3037                 creature_ptr->dis_to_h[0] -= (s16b)penalty1;
3038                 creature_ptr->dis_to_h[1] -= (s16b)penalty2;
3039         }
3040
3041         /* Extract the current weight (in tenth pounds) */
3042         int j = creature_ptr->total_weight;
3043
3044         if (!creature_ptr->riding)
3045         {
3046                 /* Extract the "weight limit" (in tenth pounds) */
3047                 count = (int)weight_limit(creature_ptr);
3048         }
3049         else
3050         {
3051                 monster_type *riding_m_ptr = &floor_ptr->m_list[creature_ptr->riding];
3052                 monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
3053                 SPEED speed = riding_m_ptr->mspeed;
3054
3055                 if (riding_m_ptr->mspeed > 110)
3056                 {
3057                         new_speed = 110 + (s16b)((speed - 110) * (creature_ptr->skill_exp[GINOU_RIDING] * 3 + creature_ptr->lev * 160L - 10000L) / (22000L));
3058                         if (new_speed < 110) new_speed = 110;
3059                 }
3060                 else
3061                 {
3062                         new_speed = speed;
3063                 }
3064                 new_speed += (creature_ptr->skill_exp[GINOU_RIDING] + creature_ptr->lev * 160L) / 3200;
3065                 if (MON_FAST(riding_m_ptr)) new_speed += 10;
3066                 if (MON_SLOW(riding_m_ptr)) new_speed -= 10;
3067                 riding_levitation = (riding_r_ptr->flags7 & RF7_CAN_FLY) ? TRUE : FALSE;
3068                 if (riding_r_ptr->flags7 & (RF7_CAN_SWIM | RF7_AQUATIC)) creature_ptr->can_swim = TRUE;
3069
3070                 if (!(riding_r_ptr->flags2 & RF2_PASS_WALL)) creature_ptr->pass_wall = FALSE;
3071                 if (riding_r_ptr->flags2 & RF2_KILL_WALL) creature_ptr->kill_wall = TRUE;
3072
3073                 if (creature_ptr->skill_exp[GINOU_RIDING] < RIDING_EXP_SKILLED) j += (creature_ptr->wt * 3 * (RIDING_EXP_SKILLED - creature_ptr->skill_exp[GINOU_RIDING])) / RIDING_EXP_SKILLED;
3074
3075                 /* Extract the "weight limit" */
3076                 count = 1500 + riding_r_ptr->level * 25;
3077         }
3078
3079         /* Apply "encumbrance" from weight */
3080         if (j > count) new_speed -= ((j - count) / (count / 5));
3081
3082         /* Searching slows the player down */
3083         if (creature_ptr->action == ACTION_SEARCH) new_speed -= 10;
3084
3085         /* Feature bonus */
3086         if (creature_ptr->prace == RACE_MERFOLK)
3087         {
3088                 if (have_flag(f_ptr->flags, FF_WATER))
3089                 {
3090                         new_speed += (2 + creature_ptr->lev / 10);
3091                 }
3092                 else if (!creature_ptr->levitation)
3093                 {
3094                         new_speed -= 2;
3095                 }
3096         }
3097
3098         /* Actual Modifier Bonuses (Un-inflate stat bonuses) */
3099         creature_ptr->to_a += ((int)(adj_dex_ta[creature_ptr->stat_ind[A_DEX]]) - 128);
3100         creature_ptr->to_d[0] += ((int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128);
3101         creature_ptr->to_d[1] += ((int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128);
3102         creature_ptr->to_d_m += ((int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128);
3103         creature_ptr->to_h[0] += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
3104         creature_ptr->to_h[1] += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
3105         creature_ptr->to_h_b += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
3106         creature_ptr->to_h_m += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
3107         creature_ptr->to_h[0] += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
3108         creature_ptr->to_h[1] += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
3109         creature_ptr->to_h_b += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
3110         creature_ptr->to_h_m += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
3111
3112         /* Displayed Modifier Bonuses (Un-inflate stat bonuses) */
3113         creature_ptr->dis_to_a += ((int)(adj_dex_ta[creature_ptr->stat_ind[A_DEX]]) - 128);
3114         creature_ptr->dis_to_d[0] += ((int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128);
3115         creature_ptr->dis_to_d[1] += ((int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128);
3116         creature_ptr->dis_to_h[0] += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
3117         creature_ptr->dis_to_h[1] += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
3118         creature_ptr->dis_to_h_b += ((int)(adj_dex_th[creature_ptr->stat_ind[A_DEX]]) - 128);
3119         creature_ptr->dis_to_h[0] += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
3120         creature_ptr->dis_to_h[1] += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
3121         creature_ptr->dis_to_h_b += ((int)(adj_str_th[creature_ptr->stat_ind[A_STR]]) - 128);
3122
3123         /* Obtain the "hold" value */
3124         hold = adj_str_hold[creature_ptr->stat_ind[A_STR]];
3125
3126         /* Examine the "current bow" */
3127         o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
3128
3129         /* It is hard to carholdry a heavy bow */
3130         creature_ptr->heavy_shoot = is_heavy_shoot(creature_ptr, o_ptr);
3131         if (creature_ptr->heavy_shoot)
3132         {
3133                 /* Hard to wield a heavy bow */
3134                 creature_ptr->to_h_b += 2 * (hold - o_ptr->weight / 10);
3135                 creature_ptr->dis_to_h_b += 2 * (hold - o_ptr->weight / 10);
3136         }
3137
3138         /* Compute "extra shots" if needed */
3139         if (o_ptr->k_idx)
3140         {
3141                 creature_ptr->tval_ammo = (byte_hack)bow_tval_ammo(o_ptr);
3142
3143                 /* Apply special flags */
3144                 if (o_ptr->k_idx && !creature_ptr->heavy_shoot)
3145                 {
3146                         /* Extra shots */
3147                         creature_ptr->num_fire = calc_num_fire(creature_ptr, o_ptr);
3148
3149                         /* Snipers love Cross bows */
3150                         if ((creature_ptr->pclass == CLASS_SNIPER) &&
3151                                 (creature_ptr->tval_ammo == TV_BOLT))
3152                         {
3153                                 creature_ptr->to_h_b += (10 + (creature_ptr->lev / 5));
3154                                 creature_ptr->dis_to_h_b += (10 + (creature_ptr->lev / 5));
3155                         }
3156                 }
3157         }
3158
3159         if (creature_ptr->ryoute) hold *= 2;
3160
3161         for (int i = 0; i < 2; i++)
3162         {
3163                 /* Examine the "main weapon" */
3164                 o_ptr = &creature_ptr->inventory_list[INVEN_RARM + i];
3165
3166                 object_flags(o_ptr, flgs);
3167
3168                 /* Assume not heavy */
3169                 creature_ptr->heavy_wield[i] = FALSE;
3170                 creature_ptr->icky_wield[i] = FALSE;
3171                 creature_ptr->riding_wield[i] = FALSE;
3172
3173                 if (!has_melee_weapon(creature_ptr, INVEN_RARM + i))
3174                 {
3175                         creature_ptr->num_blow[i] = 1;
3176                         continue;
3177                 }
3178
3179                 /* It is hard to hold a heavy weapon */
3180                 if (hold < o_ptr->weight / 10)
3181                 {
3182                         /* Hard to wield a heavy weapon */
3183                         creature_ptr->to_h[i] += 2 * (hold - o_ptr->weight / 10);
3184                         creature_ptr->dis_to_h[i] += 2 * (hold - o_ptr->weight / 10);
3185
3186                         /* Heavy weapon */
3187                         creature_ptr->heavy_wield[i] = TRUE;
3188                 }
3189                 else if (creature_ptr->ryoute && (hold < o_ptr->weight / 5)) omoi = TRUE;
3190
3191                 if ((i == 1) && (o_ptr->tval == TV_SWORD) && ((o_ptr->sval == SV_MAIN_GAUCHE) || (o_ptr->sval == SV_WAKIZASHI)))
3192                 {
3193                         creature_ptr->to_a += 5;
3194                         creature_ptr->dis_to_a += 5;
3195                 }
3196
3197                 /* Normal weapons */
3198                 if (o_ptr->k_idx && !creature_ptr->heavy_wield[i])
3199                 {
3200                         int str_index, dex_index;
3201
3202                         int num = 0, wgt = 0, mul = 0, div = 0;
3203
3204                         /* Analyze the class */
3205                         switch (creature_ptr->pclass)
3206                         {
3207                         case CLASS_WARRIOR:
3208                                 num = 6; wgt = 70; mul = 5; break;
3209
3210                         case CLASS_BERSERKER:
3211                                 num = 6; wgt = 70; mul = 7; break;
3212
3213                         case CLASS_MAGE:
3214                         case CLASS_HIGH_MAGE:
3215                         case CLASS_BLUE_MAGE:
3216                                 num = 3; wgt = 100; mul = 2; break;
3217
3218                         case CLASS_PRIEST:
3219                         case CLASS_MAGIC_EATER:
3220                         case CLASS_MINDCRAFTER:
3221                                 num = 5; wgt = 100; mul = 3; break;
3222
3223                         case CLASS_ROGUE:
3224                                 num = 5; wgt = 40; mul = 3; break;
3225
3226                         case CLASS_RANGER:
3227                                 num = 5; wgt = 70; mul = 4; break;
3228
3229                         case CLASS_PALADIN:
3230                         case CLASS_SAMURAI:
3231                                 num = 5; wgt = 70; mul = 4; break;
3232
3233                         case CLASS_SMITH:
3234                                 num = 5; wgt = 150; mul = 5; break;
3235
3236                         case CLASS_WARRIOR_MAGE:
3237                         case CLASS_RED_MAGE:
3238                                 num = 5; wgt = 70; mul = 3; break;
3239
3240                         case CLASS_CHAOS_WARRIOR:
3241                                 num = 5; wgt = 70; mul = 4; break;
3242
3243                         case CLASS_MONK:
3244                                 num = 5; wgt = 60; mul = 3; break;
3245
3246                         case CLASS_TOURIST:
3247                                 num = 4; wgt = 100; mul = 3; break;
3248
3249                         case CLASS_IMITATOR:
3250                                 num = 5; wgt = 70; mul = 4; break;
3251
3252                         case CLASS_BEASTMASTER:
3253                                 num = 5; wgt = 70; mul = 3; break;
3254
3255                         case CLASS_CAVALRY:
3256                                 if ((creature_ptr->riding) && (have_flag(flgs, TR_RIDING))) { num = 5; wgt = 70; mul = 4; }
3257                                 else { num = 5; wgt = 100; mul = 3; }
3258                                 break;
3259
3260                         case CLASS_SORCERER:
3261                                 num = 1; wgt = 1; mul = 1; break;
3262
3263                         case CLASS_ARCHER:
3264                         case CLASS_BARD:
3265                         case CLASS_SNIPER:
3266                                 num = 4; wgt = 70; mul = 2; break;
3267
3268                         case CLASS_FORCETRAINER:
3269                                 num = 4; wgt = 60; mul = 2; break;
3270
3271                         case CLASS_MIRROR_MASTER:
3272                                 num = 3; wgt = 100; mul = 3; break;
3273
3274                         case CLASS_NINJA:
3275                                 num = 4; wgt = 20; mul = 1; break;
3276                         }
3277
3278                         /* Hex - extra mights gives +1 bonus to max blows */
3279                         if (hex_spelling(creature_ptr, HEX_XTRA_MIGHT) || hex_spelling(creature_ptr, HEX_BUILDING)) { num++; wgt /= 2; mul += 2; }
3280
3281                         /* Enforce a minimum "weight" (tenth pounds) */
3282                         div = ((o_ptr->weight < wgt) ? wgt : o_ptr->weight);
3283
3284                         /* Access the strength vs weight */
3285                         str_index = (adj_str_blow[creature_ptr->stat_ind[A_STR]] * mul / div);
3286
3287                         if (creature_ptr->ryoute && !omoi) str_index++;
3288                         if (creature_ptr->pclass == CLASS_NINJA) str_index = MAX(0, str_index - 1);
3289
3290                         /* Maximal value */
3291                         if (str_index > 11) str_index = 11;
3292
3293                         /* Index by dexterity */
3294                         dex_index = (adj_dex_blow[creature_ptr->stat_ind[A_DEX]]);
3295
3296                         /* Maximal value */
3297                         if (dex_index > 11) dex_index = 11;
3298
3299                         /* Use the blows table */
3300                         creature_ptr->num_blow[i] = blows_table[str_index][dex_index];
3301
3302                         /* Maximal value */
3303                         if (creature_ptr->num_blow[i] > num) creature_ptr->num_blow[i] = (s16b)num;
3304
3305                         /* Add in the "bonus blows" */
3306                         creature_ptr->num_blow[i] += (s16b)extra_blows[i];
3307
3308
3309                         if (creature_ptr->pclass == CLASS_WARRIOR) creature_ptr->num_blow[i] += (creature_ptr->lev / 40);
3310                         else if (creature_ptr->pclass == CLASS_BERSERKER)
3311                         {
3312                                 creature_ptr->num_blow[i] += (creature_ptr->lev / 23);
3313                         }
3314                         else if ((creature_ptr->pclass == CLASS_ROGUE) && (o_ptr->weight < 50) && (creature_ptr->stat_ind[A_DEX] >= 30)) creature_ptr->num_blow[i] ++;
3315
3316                         if (creature_ptr->special_defense & KATA_FUUJIN) creature_ptr->num_blow[i] -= 1;
3317
3318                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) creature_ptr->num_blow[i] = 1;
3319
3320
3321                         /* Require at least one blow */
3322                         if (creature_ptr->num_blow[i] < 1) creature_ptr->num_blow[i] = 1;
3323
3324                         /* Boost digging skill by weapon weight */
3325                         creature_ptr->skill_dig += (o_ptr->weight / 10);
3326                 }
3327
3328                 /* Assume okay */
3329                 /* Priest weapon penalty for non-blessed edged weapons */
3330                 if ((creature_ptr->pclass == CLASS_PRIEST) && (!(have_flag(flgs, TR_BLESSED))) &&
3331                         ((o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM)))
3332                 {
3333                         /* Reduce the real bonuses */
3334                         creature_ptr->to_h[i] -= 2;
3335                         creature_ptr->to_d[i] -= 2;
3336
3337                         /* Reduce the mental bonuses */
3338                         creature_ptr->dis_to_h[i] -= 2;
3339                         creature_ptr->dis_to_d[i] -= 2;
3340
3341                         /* Icky weapon */
3342                         creature_ptr->icky_wield[i] = TRUE;
3343                 }
3344                 else if (creature_ptr->pclass == CLASS_BERSERKER)
3345                 {
3346                         creature_ptr->to_h[i] += creature_ptr->lev / 5;
3347                         creature_ptr->to_d[i] += creature_ptr->lev / 6;
3348                         creature_ptr->dis_to_h[i] += creature_ptr->lev / 5;
3349                         creature_ptr->dis_to_d[i] += creature_ptr->lev / 6;
3350                         if (((i == 0) && !creature_ptr->hidarite) || creature_ptr->ryoute)
3351                         {
3352                                 creature_ptr->to_h[i] += creature_ptr->lev / 5;
3353                                 creature_ptr->to_d[i] += creature_ptr->lev / 6;
3354                                 creature_ptr->dis_to_h[i] += creature_ptr->lev / 5;
3355                                 creature_ptr->dis_to_d[i] += creature_ptr->lev / 6;
3356                         }
3357                 }
3358                 else if (creature_ptr->pclass == CLASS_SORCERER)
3359                 {
3360                         if (!((o_ptr->tval == TV_HAFTED) && ((o_ptr->sval == SV_WIZSTAFF) || (o_ptr->sval == SV_NAMAKE_HAMMER))))
3361                         {
3362                                 /* Reduce the real bonuses */
3363                                 creature_ptr->to_h[i] -= 200;
3364                                 creature_ptr->to_d[i] -= 200;
3365
3366                                 /* Reduce the mental bonuses */
3367                                 creature_ptr->dis_to_h[i] -= 200;
3368                                 creature_ptr->dis_to_d[i] -= 200;
3369
3370                                 /* Icky weapon */
3371                                 creature_ptr->icky_wield[i] = TRUE;
3372                         }
3373                         else
3374                         {
3375                                 /* Reduce the real bonuses */
3376                                 creature_ptr->to_h[i] -= 30;
3377                                 creature_ptr->to_d[i] -= 10;
3378
3379                                 /* Reduce the mental bonuses */
3380                                 creature_ptr->dis_to_h[i] -= 30;
3381                                 creature_ptr->dis_to_d[i] -= 10;
3382                         }
3383                 }
3384
3385                 /* Hex bonuses */
3386                 if ((creature_ptr->realm1 == REALM_HEX) && object_is_cursed(o_ptr))
3387                 {
3388                         if (o_ptr->curse_flags & (TRC_CURSED)) { creature_ptr->to_h[i] += 5; creature_ptr->dis_to_h[i] += 5; }
3389                         if (o_ptr->curse_flags & (TRC_HEAVY_CURSE)) { creature_ptr->to_h[i] += 7; creature_ptr->dis_to_h[i] += 7; }
3390                         if (o_ptr->curse_flags & (TRC_PERMA_CURSE)) { creature_ptr->to_h[i] += 13; creature_ptr->dis_to_h[i] += 13; }
3391                         if (o_ptr->curse_flags & (TRC_TY_CURSE)) { creature_ptr->to_h[i] += 5; creature_ptr->dis_to_h[i] += 5; }
3392                         if (hex_spelling(creature_ptr, HEX_RUNESWORD))
3393                         {
3394                                 if (o_ptr->curse_flags & (TRC_CURSED)) { creature_ptr->to_d[i] += 5; creature_ptr->dis_to_d[i] += 5; }
3395                                 if (o_ptr->curse_flags & (TRC_HEAVY_CURSE)) { creature_ptr->to_d[i] += 7; creature_ptr->dis_to_d[i] += 7; }
3396                                 if (o_ptr->curse_flags & (TRC_PERMA_CURSE)) { creature_ptr->to_d[i] += 13; creature_ptr->dis_to_d[i] += 13; }
3397                         }
3398                 }
3399
3400                 if (creature_ptr->riding == 0) continue;
3401
3402                 if ((o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE)))
3403                 {
3404                         creature_ptr->to_h[i] += 15;
3405                         creature_ptr->dis_to_h[i] += 15;
3406                         creature_ptr->to_dd[i] += 2;
3407                         continue;
3408                 }
3409
3410                 if (have_flag(flgs, TR_RIDING)) continue;
3411
3412                 int penalty;
3413                 if ((creature_ptr->pclass == CLASS_BEASTMASTER) || (creature_ptr->pclass == CLASS_CAVALRY))
3414                 {
3415                         penalty = 5;
3416                 }
3417                 else
3418                 {
3419                         penalty = r_info[floor_ptr->m_list[creature_ptr->riding].r_idx].level - creature_ptr->skill_exp[GINOU_RIDING] / 80;
3420                         penalty += 30;
3421                         if (penalty < 30) penalty = 30;
3422                 }
3423
3424                 creature_ptr->to_h[i] -= (s16b)penalty;
3425                 creature_ptr->dis_to_h[i] -= (s16b)penalty;
3426
3427                 /* Riding weapon */
3428                 creature_ptr->riding_wield[i] = TRUE;
3429         }
3430
3431         if (creature_ptr->riding)
3432         {
3433                 int penalty = 0;
3434
3435                 creature_ptr->riding_ryoute = FALSE;
3436
3437                 if (creature_ptr->ryoute || (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_NONE)) creature_ptr->riding_ryoute = TRUE;
3438                 else if (creature_ptr->pet_extra_flags & PF_TWO_HANDS)
3439                 {
3440                         switch (creature_ptr->pclass)
3441                         {
3442                         case CLASS_MONK:
3443                         case CLASS_FORCETRAINER:
3444                         case CLASS_BERSERKER:
3445                                 if ((empty_hands(creature_ptr, FALSE) != EMPTY_HAND_NONE) && !has_melee_weapon(creature_ptr, INVEN_RARM) && !has_melee_weapon(creature_ptr, INVEN_LARM))
3446                                         creature_ptr->riding_ryoute = TRUE;
3447                                 break;
3448                         }
3449                 }
3450
3451                 if ((creature_ptr->pclass == CLASS_BEASTMASTER) || (creature_ptr->pclass == CLASS_CAVALRY))
3452                 {
3453                         if (creature_ptr->tval_ammo != TV_ARROW) penalty = 5;
3454                 }
3455                 else
3456                 {
3457                         penalty = r_info[floor_ptr->m_list[creature_ptr->riding].r_idx].level - creature_ptr->skill_exp[GINOU_RIDING] / 80;
3458                         penalty += 30;
3459                         if (penalty < 30) penalty = 30;
3460                 }
3461
3462                 if (creature_ptr->tval_ammo == TV_BOLT) penalty *= 2;
3463                 creature_ptr->to_h_b -= (s16b)penalty;
3464                 creature_ptr->dis_to_h_b -= (s16b)penalty;
3465         }
3466
3467         /* Different calculation for monks with empty hands */
3468         if (((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER) || (creature_ptr->pclass == CLASS_BERSERKER)) &&
3469                 (empty_hands_status & EMPTY_HAND_RARM) && !creature_ptr->hidarite)
3470         {
3471                 int blow_base = creature_ptr->lev + adj_dex_blow[creature_ptr->stat_ind[A_DEX]];
3472                 creature_ptr->num_blow[0] = 0;
3473
3474                 if (creature_ptr->pclass == CLASS_FORCETRAINER)
3475                 {
3476                         if (blow_base > 18) creature_ptr->num_blow[0]++;
3477                         if (blow_base > 31) creature_ptr->num_blow[0]++;
3478                         if (blow_base > 44) creature_ptr->num_blow[0]++;
3479                         if (blow_base > 58) creature_ptr->num_blow[0]++;
3480                         if (P_PTR_KI)
3481                         {
3482                                 creature_ptr->to_d[0] += P_PTR_KI / 5;
3483                                 creature_ptr->dis_to_d[0] += P_PTR_KI / 5;
3484                         }
3485                 }
3486                 else
3487                 {
3488                         if (blow_base > 12) creature_ptr->num_blow[0]++;
3489                         if (blow_base > 22) creature_ptr->num_blow[0]++;
3490                         if (blow_base > 31) creature_ptr->num_blow[0]++;
3491                         if (blow_base > 39) creature_ptr->num_blow[0]++;
3492                         if (blow_base > 46) creature_ptr->num_blow[0]++;
3493                         if (blow_base > 53) creature_ptr->num_blow[0]++;
3494                         if (blow_base > 59) creature_ptr->num_blow[0]++;
3495                 }
3496
3497                 if (heavy_armor(creature_ptr) && (creature_ptr->pclass != CLASS_BERSERKER))
3498                         creature_ptr->num_blow[0] /= 2;
3499                 else
3500                 {
3501                         creature_ptr->to_h[0] += (creature_ptr->lev / 3);
3502                         creature_ptr->dis_to_h[0] += (creature_ptr->lev / 3);
3503
3504                         creature_ptr->to_d[0] += (creature_ptr->lev / 6);
3505                         creature_ptr->dis_to_d[0] += (creature_ptr->lev / 6);
3506                 }
3507
3508                 if (creature_ptr->special_defense & KAMAE_BYAKKO)
3509                 {
3510                         creature_ptr->to_a -= 40;
3511                         creature_ptr->dis_to_a -= 40;
3512
3513                 }
3514                 else if (creature_ptr->special_defense & KAMAE_SEIRYU)
3515                 {
3516                         creature_ptr->to_a -= 50;
3517                         creature_ptr->dis_to_a -= 50;
3518                         creature_ptr->resist_acid = TRUE;
3519                         creature_ptr->resist_fire = TRUE;
3520                         creature_ptr->resist_elec = TRUE;
3521                         creature_ptr->resist_cold = TRUE;
3522                         creature_ptr->resist_pois = TRUE;
3523                         creature_ptr->sh_fire = TRUE;
3524                         creature_ptr->sh_elec = TRUE;
3525                         creature_ptr->sh_cold = TRUE;
3526                         creature_ptr->levitation = TRUE;
3527                 }
3528                 else if (creature_ptr->special_defense & KAMAE_GENBU)
3529                 {
3530                         creature_ptr->to_a += (creature_ptr->lev*creature_ptr->lev) / 50;
3531                         creature_ptr->dis_to_a += (creature_ptr->lev*creature_ptr->lev) / 50;
3532                         creature_ptr->reflect = TRUE;
3533                         creature_ptr->num_blow[0] -= 2;
3534                         if ((creature_ptr->pclass == CLASS_MONK) && (creature_ptr->lev > 42)) creature_ptr->num_blow[0]--;
3535                         if (creature_ptr->num_blow[0] < 0) creature_ptr->num_blow[0] = 0;
3536                 }
3537                 else if (creature_ptr->special_defense & KAMAE_SUZAKU)
3538                 {
3539                         creature_ptr->to_h[0] -= (creature_ptr->lev / 3);
3540                         creature_ptr->to_d[0] -= (creature_ptr->lev / 6);
3541
3542                         creature_ptr->dis_to_h[0] -= (creature_ptr->lev / 3);
3543                         creature_ptr->dis_to_d[0] -= (creature_ptr->lev / 6);
3544                         creature_ptr->num_blow[0] /= 2;
3545                         creature_ptr->levitation = TRUE;
3546                 }
3547
3548                 creature_ptr->num_blow[0] += 1 + extra_blows[0];
3549         }
3550
3551         if (creature_ptr->riding) creature_ptr->levitation = riding_levitation;
3552
3553         creature_ptr->monk_armour_aux = FALSE;
3554
3555         if (heavy_armor(creature_ptr))
3556         {
3557                 creature_ptr->monk_armour_aux = TRUE;
3558         }
3559
3560         for (int i = 0; i < 2; i++)
3561         {
3562                 if (!has_melee_weapon(creature_ptr, INVEN_RARM + i)) continue;
3563
3564                 OBJECT_TYPE_VALUE tval = creature_ptr->inventory_list[INVEN_RARM + i].tval - TV_WEAPON_BEGIN;
3565                 OBJECT_SUBTYPE_VALUE sval = creature_ptr->inventory_list[INVEN_RARM + i].sval;
3566
3567                 creature_ptr->to_h[i] += (creature_ptr->weapon_exp[tval][sval] - WEAPON_EXP_BEGINNER) / 200;
3568                 creature_ptr->dis_to_h[i] += (creature_ptr->weapon_exp[tval][sval] - WEAPON_EXP_BEGINNER) / 200;
3569                 if ((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER))
3570                 {
3571                         if (!s_info[creature_ptr->pclass].w_max[tval][sval])
3572                         {
3573                                 creature_ptr->to_h[i] -= 40;
3574                                 creature_ptr->dis_to_h[i] -= 40;
3575                                 creature_ptr->icky_wield[i] = TRUE;
3576                         }
3577
3578                         continue;
3579                 }
3580
3581                 if (creature_ptr->pclass != CLASS_NINJA) continue;
3582
3583                 if ((s_info[CLASS_NINJA].w_max[tval][sval] > WEAPON_EXP_BEGINNER) && (creature_ptr->inventory_list[INVEN_LARM - i].tval != TV_SHIELD))
3584                         continue;
3585
3586                 creature_ptr->to_h[i] -= 40;
3587                 creature_ptr->dis_to_h[i] -= 40;
3588                 creature_ptr->icky_wield[i] = TRUE;
3589                 creature_ptr->num_blow[i] /= 2;
3590                 if (creature_ptr->num_blow[i] < 1) creature_ptr->num_blow[i] = 1;
3591         }
3592
3593         /* Maximum speed is (+99). (internally it's 110 + 99) */
3594         /* Temporary lightspeed forces to be maximum speed */
3595         if ((creature_ptr->lightspeed && !creature_ptr->riding) || (new_speed > 209))
3596         {
3597                 new_speed = 209;
3598         }
3599
3600         /* Minimum speed is (-99). (internally it's 110 - 99) */
3601         if (new_speed < 11) new_speed = 11;
3602
3603         /* Display the speed (if needed) */
3604         if (creature_ptr->pspeed != (byte)new_speed)
3605         {
3606                 creature_ptr->pspeed = (byte)new_speed;
3607                 creature_ptr->redraw |= (PR_SPEED);
3608         }
3609
3610         if (yoiyami)
3611         {
3612                 if (creature_ptr->to_a > (0 - creature_ptr->ac))
3613                         creature_ptr->to_a = 0 - creature_ptr->ac;
3614                 if (creature_ptr->dis_to_a > (0 - creature_ptr->dis_ac))
3615                         creature_ptr->dis_to_a = 0 - creature_ptr->dis_ac;
3616         }
3617
3618         /* Redraw armor (if needed) */
3619         if ((creature_ptr->dis_ac != old_dis_ac) || (creature_ptr->dis_to_a != old_dis_to_a))
3620         {
3621                 creature_ptr->redraw |= (PR_ARMOR);
3622                 creature_ptr->window |= (PW_PLAYER);
3623         }
3624
3625         if (creature_ptr->ryoute && !omoi)
3626         {
3627                 int bonus_to_h = 0, bonus_to_d = 0;
3628                 bonus_to_d = ((int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128) / 2;
3629                 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);
3630
3631                 creature_ptr->to_h[default_hand] += MAX(bonus_to_h, 1);
3632                 creature_ptr->dis_to_h[default_hand] += MAX(bonus_to_h, 1);
3633                 creature_ptr->to_d[default_hand] += MAX(bonus_to_d, 1);
3634                 creature_ptr->dis_to_d[default_hand] += MAX(bonus_to_d, 1);
3635         }
3636
3637         bool is_special_class = creature_ptr->pclass == CLASS_MONK;
3638         is_special_class |= creature_ptr->pclass == CLASS_FORCETRAINER;
3639         is_special_class |= creature_ptr->pclass == CLASS_BERSERKER;
3640         if (is_special_class && (empty_hands(creature_ptr, FALSE) == (EMPTY_HAND_RARM | EMPTY_HAND_LARM)))
3641                 creature_ptr->ryoute = FALSE;
3642
3643         /* Affect Skill -- stealth (bonus one) */
3644         creature_ptr->skill_stl += 1;
3645
3646         if (is_time_limit_stealth(creature_ptr)) creature_ptr->skill_stl += 99;
3647
3648         /* Affect Skill -- disarming (DEX and INT) */
3649         creature_ptr->skill_dis += adj_dex_dis[creature_ptr->stat_ind[A_DEX]];
3650         creature_ptr->skill_dis += adj_int_dis[creature_ptr->stat_ind[A_INT]];
3651
3652         /* Affect Skill -- magic devices (INT) */
3653         creature_ptr->skill_dev += adj_int_dev[creature_ptr->stat_ind[A_INT]];
3654
3655         /* Affect Skill -- saving throw (WIS) */
3656         creature_ptr->skill_sav += adj_wis_sav[creature_ptr->stat_ind[A_WIS]];
3657
3658         /* Affect Skill -- digging (STR) */
3659         creature_ptr->skill_dig += adj_str_dig[creature_ptr->stat_ind[A_STR]];
3660
3661         /* Affect Skill -- disarming (Level, by Class) */
3662         creature_ptr->skill_dis += ((cp_ptr->x_dis * creature_ptr->lev / 10) + (ap_ptr->a_dis * creature_ptr->lev / 50));
3663
3664         /* Affect Skill -- magic devices (Level, by Class) */
3665         creature_ptr->skill_dev += ((cp_ptr->x_dev * creature_ptr->lev / 10) + (ap_ptr->a_dev * creature_ptr->lev / 50));
3666
3667         /* Affect Skill -- saving throw (Level, by Class) */
3668         creature_ptr->skill_sav += ((cp_ptr->x_sav * creature_ptr->lev / 10) + (ap_ptr->a_sav * creature_ptr->lev / 50));
3669
3670         /* Affect Skill -- stealth (Level, by Class) */
3671         creature_ptr->skill_stl += (cp_ptr->x_stl * creature_ptr->lev / 10);
3672
3673         /* Affect Skill -- search ability (Level, by Class) */
3674         creature_ptr->skill_srh += (cp_ptr->x_srh * creature_ptr->lev / 10);
3675
3676         /* Affect Skill -- search frequency (Level, by Class) */
3677         creature_ptr->skill_fos += (cp_ptr->x_fos * creature_ptr->lev / 10);
3678
3679         /* Affect Skill -- combat (normal) (Level, by Class) */
3680         creature_ptr->skill_thn += ((cp_ptr->x_thn * creature_ptr->lev / 10) + (ap_ptr->a_thn * creature_ptr->lev / 50));
3681
3682         /* Affect Skill -- combat (shooting) (Level, by Class) */
3683         creature_ptr->skill_thb += ((cp_ptr->x_thb * creature_ptr->lev / 10) + (ap_ptr->a_thb * creature_ptr->lev / 50));
3684
3685         /* Affect Skill -- combat (throwing) (Level, by Class) */
3686         creature_ptr->skill_tht += ((cp_ptr->x_thb * creature_ptr->lev / 10) + (ap_ptr->a_thb * creature_ptr->lev / 50));
3687
3688         if ((PRACE_IS_(creature_ptr, RACE_S_FAIRY)) && (creature_ptr->pseikaku != SEIKAKU_SEXY) && (creature_ptr->cursed & TRC_AGGRAVATE))
3689         {
3690                 creature_ptr->cursed &= ~(TRC_AGGRAVATE);
3691                 creature_ptr->skill_stl = MIN(creature_ptr->skill_stl - 3, (creature_ptr->skill_stl + 2) / 2);
3692         }
3693
3694         /* Limit Skill -- stealth from 0 to 30 */
3695         if (creature_ptr->skill_stl > 30) creature_ptr->skill_stl = 30;
3696         if (creature_ptr->skill_stl < 0) creature_ptr->skill_stl = 0;
3697
3698         /* Limit Skill -- digging from 1 up */
3699         if (creature_ptr->skill_dig < 1) creature_ptr->skill_dig = 1;
3700
3701         if (creature_ptr->anti_magic && (creature_ptr->skill_sav < (90 + creature_ptr->lev))) creature_ptr->skill_sav = 90 + creature_ptr->lev;
3702
3703         if (creature_ptr->tsubureru) creature_ptr->skill_sav = 10;
3704
3705         if ((creature_ptr->ult_res || creature_ptr->resist_magic || creature_ptr->magicdef) && (creature_ptr->skill_sav < (95 + creature_ptr->lev))) creature_ptr->skill_sav = 95 + creature_ptr->lev;
3706
3707         if (down_saving) creature_ptr->skill_sav /= 2;
3708
3709         /* Hack -- Each elemental immunity includes resistance */
3710         if (creature_ptr->immune_acid) creature_ptr->resist_acid = TRUE;
3711         if (creature_ptr->immune_elec) creature_ptr->resist_elec = TRUE;
3712         if (creature_ptr->immune_fire) creature_ptr->resist_fire = TRUE;
3713         if (creature_ptr->immune_cold) creature_ptr->resist_cold = TRUE;
3714
3715         /* Hack -- handle "xtra" mode */
3716         if (current_world_ptr->character_xtra) return;
3717
3718         /* Take note when "heavy bow" changes */
3719         if (creature_ptr->old_heavy_shoot != creature_ptr->heavy_shoot)
3720         {
3721                 if (creature_ptr->heavy_shoot)
3722                 {
3723                         msg_print(_("こんな重い弓を装備しているのは大変だ。", "You have trouble wielding such a heavy bow."));
3724                 }
3725                 else if (creature_ptr->inventory_list[INVEN_BOW].k_idx)
3726                 {
3727                         msg_print(_("この弓なら装備していても辛くない。", "You have no trouble wielding your bow."));
3728                 }
3729                 else
3730                 {
3731                         msg_print(_("重い弓を装備からはずして体が楽になった。", "You feel relieved to put down your heavy bow."));
3732                 }
3733
3734                 creature_ptr->old_heavy_shoot = creature_ptr->heavy_shoot;
3735         }
3736
3737         for (int i = 0; i < 2; i++)
3738         {
3739                 /* Take note when "heavy weapon" changes */
3740                 if (creature_ptr->old_heavy_wield[i] != creature_ptr->heavy_wield[i])
3741                 {
3742                         if (creature_ptr->heavy_wield[i])
3743                         {
3744                                 msg_print(_("こんな重い武器を装備しているのは大変だ。", "You have trouble wielding such a heavy weapon."));
3745                         }
3746                         else if (has_melee_weapon(creature_ptr, INVEN_RARM + i))
3747                         {
3748                                 msg_print(_("これなら装備していても辛くない。", "You have no trouble wielding your weapon."));
3749                         }
3750                         else if (creature_ptr->heavy_wield[1 - i])
3751                         {
3752                                 msg_print(_("まだ武器が重い。", "You have still trouble wielding a heavy weapon."));
3753                         }
3754                         else
3755                         {
3756                                 msg_print(_("重い武器を装備からはずして体が楽になった。", "You feel relieved to put down your heavy weapon."));
3757                         }
3758
3759                         creature_ptr->old_heavy_wield[i] = creature_ptr->heavy_wield[i];
3760                 }
3761
3762                 /* Take note when "heavy weapon" changes */
3763                 if (creature_ptr->old_riding_wield[i] != creature_ptr->riding_wield[i])
3764                 {
3765                         if (creature_ptr->riding_wield[i])
3766                         {
3767                                 msg_print(_("この武器は乗馬中に使うにはむかないようだ。", "This weapon is not suitable for use while riding."));
3768                         }
3769                         else if (!creature_ptr->riding)
3770                         {
3771                                 msg_print(_("この武器は徒歩で使いやすい。", "This weapon was not suitable for use while riding."));
3772                         }
3773                         else if (has_melee_weapon(creature_ptr, INVEN_RARM + i))
3774                         {
3775                                 msg_print(_("これなら乗馬中にぴったりだ。", "This weapon is suitable for use while riding."));
3776                         }
3777
3778                         creature_ptr->old_riding_wield[i] = creature_ptr->riding_wield[i];
3779                 }
3780
3781                 /* Take note when "illegal weapon" changes */
3782                 if (creature_ptr->old_icky_wield[i] == creature_ptr->icky_wield[i]) continue;
3783
3784                 if (creature_ptr->icky_wield[i])
3785                 {
3786                         msg_print(_("今の装備はどうも自分にふさわしくない気がする。", "You do not feel comfortable with your weapon."));
3787                         if (current_world_ptr->is_loading_now)
3788                         {
3789                                 chg_virtue(creature_ptr, V_FAITH, -1);
3790                         }
3791                 }
3792                 else if (has_melee_weapon(creature_ptr, INVEN_RARM + i))
3793                 {
3794                         msg_print(_("今の装備は自分にふさわしい気がする。", "You feel comfortable with your weapon."));
3795                 }
3796                 else
3797                 {
3798                         msg_print(_("装備をはずしたら随分と気が楽になった。", "You feel more comfortable after removing your weapon."));
3799                 }
3800
3801                 creature_ptr->old_icky_wield[i] = creature_ptr->icky_wield[i];
3802         }
3803
3804         if (creature_ptr->riding && (creature_ptr->old_riding_ryoute != creature_ptr->riding_ryoute))
3805         {
3806                 if (creature_ptr->riding_ryoute)
3807                 {
3808 #ifdef JP
3809                         msg_format("%s馬を操れない。", (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_NONE) ? "両手がふさがっていて" : "");
3810 #else
3811                         msg_print("You are using both hand for fighting, and you can't control a riding pet.");
3812 #endif
3813                 }
3814                 else
3815                 {
3816 #ifdef JP
3817                         msg_format("%s馬を操れるようになった。", (empty_hands(creature_ptr, FALSE) == EMPTY_HAND_NONE) ? "手が空いて" : "");
3818 #else
3819                         msg_print("You began to control riding pet with one hand.");
3820 #endif
3821                 }
3822
3823                 creature_ptr->old_riding_ryoute = creature_ptr->riding_ryoute;
3824         }
3825
3826         if (((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER) || (creature_ptr->pclass == CLASS_NINJA)) && (creature_ptr->monk_armour_aux != creature_ptr->monk_notify_aux))
3827         {
3828                 if (heavy_armor(creature_ptr))
3829                 {
3830                         msg_print(_("装備が重くてバランスを取れない。", "The weight of your armor disrupts your balance."));
3831                         if (current_world_ptr->is_loading_now)
3832                         {
3833                                 chg_virtue(creature_ptr, V_HARMONY, -1);
3834                         }
3835                 }
3836                 else
3837                 {
3838                         msg_print(_("バランスがとれるようになった。", "You regain your balance."));
3839                 }
3840
3841                 creature_ptr->monk_notify_aux = creature_ptr->monk_armour_aux;
3842         }
3843
3844         for (int i = 0; i < INVEN_PACK; i++)
3845         {
3846                 if ((creature_ptr->inventory_list[i].tval == TV_NATURE_BOOK) && (creature_ptr->inventory_list[i].sval == 2)) have_sw = TRUE;
3847                 if ((creature_ptr->inventory_list[i].tval == TV_CRAFT_BOOK) && (creature_ptr->inventory_list[i].sval == 2)) have_kabe = TRUE;
3848         }
3849
3850         for (this_o_idx = floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].o_idx; this_o_idx; this_o_idx = next_o_idx)
3851         {
3852                 o_ptr = &floor_ptr->o_list[this_o_idx];
3853                 next_o_idx = o_ptr->next_o_idx;
3854
3855                 if ((o_ptr->tval == TV_NATURE_BOOK) && (o_ptr->sval == 2)) have_sw = TRUE;
3856                 if ((o_ptr->tval == TV_CRAFT_BOOK) && (o_ptr->sval == 2)) have_kabe = TRUE;
3857         }
3858
3859         if (creature_ptr->pass_wall && !creature_ptr->kill_wall) creature_ptr->no_flowed = TRUE;
3860
3861         if (have_sw && ((creature_ptr->realm1 == REALM_NATURE) || (creature_ptr->realm2 == REALM_NATURE) || (creature_ptr->pclass == CLASS_SORCERER)))
3862         {
3863                 const magic_type *s_ptr = &mp_ptr->info[REALM_NATURE - 1][SPELL_SW];
3864                 if (creature_ptr->lev >= s_ptr->slevel) creature_ptr->no_flowed = TRUE;
3865         }
3866
3867         if (have_kabe && ((creature_ptr->realm1 == REALM_CRAFT) || (creature_ptr->realm2 == REALM_CRAFT) || (creature_ptr->pclass == CLASS_SORCERER)))
3868         {
3869                 const magic_type *s_ptr = &mp_ptr->info[REALM_CRAFT - 1][SPELL_KABE];
3870                 if (creature_ptr->lev >= s_ptr->slevel) creature_ptr->no_flowed = TRUE;
3871         }
3872 }
3873
3874
3875 static void calc_alignment(player_type *creature_ptr)
3876 {
3877         creature_ptr->align = 0;
3878         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
3879         for (MONSTER_IDX m_idx = floor_ptr->m_max - 1; m_idx >= 1; m_idx--)
3880         {
3881                 monster_type *m_ptr;
3882                 monster_race *r_ptr;
3883                 m_ptr = &floor_ptr->m_list[m_idx];
3884                 if (!monster_is_valid(m_ptr)) continue;
3885                 r_ptr = &r_info[m_ptr->r_idx];
3886
3887                 if (!is_pet(m_ptr)) continue;
3888
3889                 if (r_ptr->flags3 & RF3_GOOD) creature_ptr->align += r_ptr->level;
3890                 if (r_ptr->flags3 & RF3_EVIL) creature_ptr->align -= r_ptr->level;
3891         }
3892
3893         if (creature_ptr->mimic_form)
3894         {
3895                 switch (creature_ptr->mimic_form)
3896                 {
3897                 case MIMIC_DEMON:
3898                         creature_ptr->align -= 200;
3899                         break;
3900                 case MIMIC_DEMON_LORD:
3901                         creature_ptr->align -= 200;
3902                         break;
3903                 }
3904         }
3905         else
3906         {
3907                 switch (creature_ptr->prace)
3908                 {
3909                 case RACE_ANGEL:
3910                         creature_ptr->align += 200;
3911                         break;
3912                 case RACE_DEMON:
3913                         creature_ptr->align -= 200;
3914                         break;
3915                 }
3916         }
3917
3918         for (int i = 0; i < 2; i++)
3919         {
3920                 if (!has_melee_weapon(creature_ptr, INVEN_RARM + i)) continue;
3921                 if (creature_ptr->inventory_list[INVEN_RARM + i].name1 != ART_IRON_BALL) continue;
3922                 creature_ptr->align -= 1000;
3923         }
3924
3925         /* Determine player alignment */
3926         int j = 0;
3927         int neutral[2];
3928         for (int i = 0; i < 8; i++)
3929         {
3930                 switch (creature_ptr->vir_types[i])
3931                 {
3932                 case V_JUSTICE:
3933                         creature_ptr->align += creature_ptr->virtues[i] * 2;
3934                         break;
3935                 case V_CHANCE:
3936                         /* Do nothing */
3937                         break;
3938                 case V_NATURE:
3939                 case V_HARMONY:
3940                         neutral[j++] = i;
3941                         break;
3942                 case V_UNLIFE:
3943                         creature_ptr->align -= creature_ptr->virtues[i];
3944                         break;
3945                 default:
3946                         creature_ptr->align += creature_ptr->virtues[i];
3947                         break;
3948                 }
3949         }
3950
3951         for (int i = 0; i < j; i++)
3952         {
3953                 if (creature_ptr->align > 0)
3954                 {
3955                         creature_ptr->align -= creature_ptr->virtues[neutral[i]] / 2;
3956                         if (creature_ptr->align < 0) creature_ptr->align = 0;
3957                 }
3958                 else if (creature_ptr->align < 0)
3959                 {
3960                         creature_ptr->align += creature_ptr->virtues[neutral[i]] / 2;
3961                         if (creature_ptr->align > 0) creature_ptr->align = 0;
3962                 }
3963         }
3964 }
3965
3966
3967 /*!
3968  * @brief プレイヤーの最大HPを計算する /
3969  * Calculate the players (maximal) hit points
3970  * Adjust current hitpoints if necessary
3971  * @return なし
3972  * @details
3973  */
3974 static void calc_hitpoints(player_type *creature_ptr)
3975 {
3976         /* Un-inflate "half-hitpoint bonus per level" value */
3977         int bonus = ((int)(adj_con_mhp[creature_ptr->stat_ind[A_CON]]) - 128) * creature_ptr->lev / 4;
3978
3979         /* Calculate hitpoints */
3980         int mhp = creature_ptr->player_hp[creature_ptr->lev - 1];
3981
3982         byte tmp_hitdie;
3983         if (creature_ptr->mimic_form)
3984         {
3985                 if (creature_ptr->pclass == CLASS_SORCERER)
3986                         tmp_hitdie = mimic_info[creature_ptr->mimic_form].r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
3987                 else
3988                         tmp_hitdie = mimic_info[creature_ptr->mimic_form].r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
3989                 mhp = mhp * tmp_hitdie / creature_ptr->hitdie;
3990         }
3991
3992         if (creature_ptr->pclass == CLASS_SORCERER)
3993         {
3994                 if (creature_ptr->lev < 30)
3995                         mhp = (mhp * (45 + creature_ptr->lev) / 100);
3996                 else
3997                         mhp = (mhp * 75 / 100);
3998                 bonus = (bonus * 65 / 100);
3999         }
4000
4001         mhp += bonus;
4002
4003         if (creature_ptr->pclass == CLASS_BERSERKER)
4004         {
4005                 mhp = mhp * (110 + (((creature_ptr->lev + 40) * (creature_ptr->lev + 40) - 1550) / 110)) / 100;
4006         }
4007
4008         /* Always have at least one hitpoint per level */
4009         if (mhp < creature_ptr->lev + 1) mhp = creature_ptr->lev + 1;
4010
4011         /* Factor in the hero / superhero settings */
4012         if (IS_HERO(creature_ptr)) mhp += 10;
4013         if (creature_ptr->shero && (creature_ptr->pclass != CLASS_BERSERKER)) mhp += 30;
4014         if (creature_ptr->tsuyoshi) mhp += 50;
4015
4016         /* Factor in the hex spell settings */
4017         if (hex_spelling(creature_ptr, HEX_XTRA_MIGHT)) mhp += 15;
4018         if (hex_spelling(creature_ptr, HEX_BUILDING)) mhp += 60;
4019
4020         /* New maximum hitpoints */
4021         if (creature_ptr->mhp == mhp) return;
4022
4023         /* Enforce maximum */
4024         if (creature_ptr->chp >= mhp)
4025         {
4026                 creature_ptr->chp = mhp;
4027                 creature_ptr->chp_frac = 0;
4028         }
4029
4030 #ifdef JP
4031         /* レベルアップの時は上昇量を表示する */
4032         if (creature_ptr->level_up_message && (mhp > creature_ptr->mhp))
4033         {
4034                 msg_format("最大ヒット・ポイントが %d 増加した!", (mhp - creature_ptr->mhp));
4035         }
4036 #endif
4037         creature_ptr->mhp = mhp;
4038
4039         creature_ptr->redraw |= PR_HP;
4040         creature_ptr->window |= PW_PLAYER;
4041 }
4042
4043
4044 /*!
4045  * @brief プレイヤーの光源半径を計算する / Extract and set the current "lite radius"
4046  * @return なし
4047  * @details
4048  * SWD: Experimental modification: multiple light sources have additive effect.
4049  */
4050 static void calc_torch(player_type *creature_ptr)
4051 {
4052         creature_ptr->cur_lite = 0;
4053
4054         /* Loop through all wielded items */
4055         for (int i = INVEN_RARM; i < INVEN_TOTAL; i++)
4056         {
4057                 object_type *o_ptr;
4058                 o_ptr = &creature_ptr->inventory_list[i];
4059                 /* Skip empty slots */
4060                 if (!o_ptr->k_idx) continue;
4061
4062                 if (o_ptr->name2 == EGO_LITE_SHINE) creature_ptr->cur_lite++;
4063
4064                 /* Need Fuels */
4065                 if (o_ptr->name2 != EGO_LITE_DARKNESS)
4066                 {
4067                         if (o_ptr->tval == TV_LITE)
4068                         {
4069                                 if ((o_ptr->sval == SV_LITE_TORCH) && !(o_ptr->xtra4 > 0)) continue;
4070                                 if ((o_ptr->sval == SV_LITE_LANTERN) && !(o_ptr->xtra4 > 0)) continue;
4071                         }
4072                 }
4073
4074                 BIT_FLAGS flgs[TR_FLAG_SIZE];
4075                 object_flags(o_ptr, flgs);
4076
4077                 POSITION rad = 0;
4078                 if (have_flag(flgs, TR_LITE_1) && o_ptr->name2 != EGO_LITE_DARKNESS)  rad += 1;
4079                 if (have_flag(flgs, TR_LITE_2) && o_ptr->name2 != EGO_LITE_DARKNESS)  rad += 2;
4080                 if (have_flag(flgs, TR_LITE_3) && o_ptr->name2 != EGO_LITE_DARKNESS)  rad += 3;
4081                 if (have_flag(flgs, TR_LITE_M1)) rad -= 1;
4082                 if (have_flag(flgs, TR_LITE_M2)) rad -= 2;
4083                 if (have_flag(flgs, TR_LITE_M3)) rad -= 3;
4084                 creature_ptr->cur_lite += rad;
4085         }
4086
4087         /* max radius is 14 (was 5) without rewriting other code -- */
4088         if (d_info[creature_ptr->dungeon_idx].flags1 & DF1_DARKNESS && creature_ptr->cur_lite > 1)
4089                 creature_ptr->cur_lite = 1;
4090
4091         /*
4092          * check if the player doesn't have light radius,
4093          * but does weakly glow as an intrinsic.
4094          */
4095         if (creature_ptr->cur_lite <= 0 && creature_ptr->lite) creature_ptr->cur_lite++;
4096
4097         if (creature_ptr->cur_lite > 14) creature_ptr->cur_lite = 14;
4098         if (creature_ptr->cur_lite < 0) creature_ptr->cur_lite = 0;
4099
4100         /* Notice changes in the "lite radius" */
4101         if (creature_ptr->old_lite == creature_ptr->cur_lite) return;
4102
4103         /* Hack -- PU_MON_LITE for monsters' darkness */
4104         creature_ptr->update |= (PU_LITE | PU_MON_LITE | PU_MONSTERS);
4105
4106         /* Remember the old lite */
4107         creature_ptr->old_lite = creature_ptr->cur_lite;
4108
4109         if ((creature_ptr->cur_lite > 0) && (creature_ptr->special_defense & NINJA_S_STEALTH))
4110                 set_superstealth(creature_ptr, FALSE);
4111
4112 }
4113
4114
4115 /*!
4116  * @brief プレイヤーの現在学習可能な魔法数を計算し、増減に応じて魔法の忘却、再学習を処置する。 /
4117  * Calculate number of spells player should have, and forget,
4118  * or remember, spells until that number is properly reflected.
4119  * @return なし
4120  * @details
4121  * Note that this function induces various "status" messages,
4122  * which must be bypasses until the character is created.
4123  */
4124 static void calc_spells(player_type *creature_ptr)
4125 {
4126         /* Hack -- must be literate */
4127         if (!mp_ptr->spell_book) return;
4128
4129         /* Hack -- wait for creation */
4130         if (!current_world_ptr->character_generated) return;
4131
4132         /* Hack -- handle "xtra" mode */
4133         if (current_world_ptr->character_xtra) return;
4134
4135         if ((creature_ptr->pclass == CLASS_SORCERER) || (creature_ptr->pclass == CLASS_RED_MAGE))
4136         {
4137                 creature_ptr->new_spells = 0;
4138                 return;
4139         }
4140
4141         concptr p = spell_category_name(mp_ptr->spell_book);
4142
4143         /* Determine the number of spells allowed */
4144         int levels = creature_ptr->lev - mp_ptr->spell_first + 1;
4145
4146         /* Hack -- no negative spells */
4147         if (levels < 0) levels = 0;
4148
4149         /* Extract total allowed spells */
4150         int num_allowed = (adj_mag_study[creature_ptr->stat_ind[mp_ptr->spell_stat]] * levels / 2);
4151
4152         int bonus = 0;
4153         if ((creature_ptr->pclass != CLASS_SAMURAI) && (mp_ptr->spell_book != TV_LIFE_BOOK))
4154         {
4155                 bonus = 4;
4156         }
4157
4158         if (creature_ptr->pclass == CLASS_SAMURAI)
4159         {
4160                 num_allowed = 32;
4161         }
4162         else if (creature_ptr->realm2 == REALM_NONE)
4163         {
4164                 num_allowed = (num_allowed + 1) / 2;
4165                 if (num_allowed > (32 + bonus)) num_allowed = 32 + bonus;
4166         }
4167         else if ((creature_ptr->pclass == CLASS_MAGE) || (creature_ptr->pclass == CLASS_PRIEST))
4168         {
4169                 if (num_allowed > (96 + bonus)) num_allowed = 96 + bonus;
4170         }
4171         else
4172         {
4173                 if (num_allowed > (80 + bonus)) num_allowed = 80 + bonus;
4174         }
4175
4176         /* Count the number of spells we know */
4177         int num_boukyaku = 0;
4178         for (int j = 0; j < 64; j++)
4179         {
4180                 /* Count known spells */
4181                 if ((j < 32) ?
4182                         (creature_ptr->spell_forgotten1 & (1L << j)) :
4183                         (creature_ptr->spell_forgotten2 & (1L << (j - 32))))
4184                 {
4185                         num_boukyaku++;
4186                 }
4187         }
4188
4189         /* See how many spells we must forget or may learn */
4190         creature_ptr->new_spells = num_allowed + creature_ptr->add_spells + num_boukyaku - creature_ptr->learned_spells;
4191
4192         /* Forget spells which are too hard */
4193         for (int i = 63; i >= 0; i--)
4194         {
4195                 /* Efficiency -- all done */
4196                 if (!creature_ptr->spell_learned1 && !creature_ptr->spell_learned2) break;
4197
4198                 /* Access the spell */
4199                 int j = creature_ptr->spell_order[i];
4200
4201                 /* Skip non-spells */
4202                 if (j >= 99) continue;
4203
4204                 /* Get the spell */
4205                 const magic_type *s_ptr;
4206                 if (!is_magic((j < 32) ? creature_ptr->realm1 : creature_ptr->realm2))
4207                 {
4208                         if (j < 32)
4209                                 s_ptr = &technic_info[creature_ptr->realm1 - MIN_TECHNIC][j];
4210                         else
4211                                 s_ptr = &technic_info[creature_ptr->realm2 - MIN_TECHNIC][j % 32];
4212                 }
4213                 else if (j < 32)
4214                         s_ptr = &mp_ptr->info[creature_ptr->realm1 - 1][j];
4215                 else
4216                         s_ptr = &mp_ptr->info[creature_ptr->realm2 - 1][j % 32];
4217
4218                 /* Skip spells we are allowed to know */
4219                 if (s_ptr->slevel <= creature_ptr->lev) continue;
4220
4221                 /* Is it known? */
4222                 bool is_spell_learned = (j < 32) ?
4223                         (creature_ptr->spell_learned1 & (1L << j)) :
4224                         (creature_ptr->spell_learned2 & (1L << (j - 32)));
4225                 if (!is_spell_learned) continue;
4226
4227                 /* Mark as forgotten */
4228                 REALM_IDX which;
4229                 if (j < 32)
4230                 {
4231                         creature_ptr->spell_forgotten1 |= (1L << j);
4232                         which = creature_ptr->realm1;
4233                 }
4234                 else
4235                 {
4236                         creature_ptr->spell_forgotten2 |= (1L << (j - 32));
4237                         which = creature_ptr->realm2;
4238                 }
4239
4240                 /* No longer known */
4241                 if (j < 32)
4242                 {
4243                         creature_ptr->spell_learned1 &= ~(1L << j);
4244                         which = creature_ptr->realm1;
4245                 }
4246                 else
4247                 {
4248                         creature_ptr->spell_learned2 &= ~(1L << (j - 32));
4249                         which = creature_ptr->realm2;
4250                 }
4251
4252 #ifdef JP
4253                 msg_format("%sの%sを忘れてしまった。", exe_spell(creature_ptr, which, j % 32, SPELL_NAME), p);
4254 #else
4255                 msg_format("You have forgotten the %s of %s.", p, exe_spell(creature_ptr, which, j % 32, SPELL_NAME));
4256 #endif
4257                 creature_ptr->new_spells++;
4258         }
4259
4260         /* Forget spells if we know too many spells */
4261         for (int i = 63; i >= 0; i--)
4262         {
4263                 /* Stop when possible */
4264                 if (creature_ptr->new_spells >= 0) break;
4265
4266                 /* Efficiency -- all done */
4267                 if (!creature_ptr->spell_learned1 && !creature_ptr->spell_learned2) break;
4268
4269                 /* Get the (i+1)th spell learned */
4270                 int j = creature_ptr->spell_order[i];
4271
4272                 /* Skip unknown spells */
4273                 if (j >= 99) continue;
4274
4275                 bool is_spell_learned = (j < 32) ?
4276                         (creature_ptr->spell_learned1 & (1L << j)) :
4277                         (creature_ptr->spell_learned2 & (1L << (j - 32)));
4278                 if (!is_spell_learned) continue;
4279
4280                 /* Mark as forgotten */
4281                 REALM_IDX which;
4282                 if (j < 32)
4283                 {
4284                         creature_ptr->spell_forgotten1 |= (1L << j);
4285                         which = creature_ptr->realm1;
4286                 }
4287                 else
4288                 {
4289                         creature_ptr->spell_forgotten2 |= (1L << (j - 32));
4290                         which = creature_ptr->realm2;
4291                 }
4292
4293                 /* No longer known */
4294                 if (j < 32)
4295                 {
4296                         creature_ptr->spell_learned1 &= ~(1L << j);
4297                         which = creature_ptr->realm1;
4298                 }
4299                 else
4300                 {
4301                         creature_ptr->spell_learned2 &= ~(1L << (j - 32));
4302                         which = creature_ptr->realm2;
4303                 }
4304
4305 #ifdef JP
4306                 msg_format("%sの%sを忘れてしまった。", exe_spell(creature_ptr, which, j % 32, SPELL_NAME), p);
4307 #else
4308                 msg_format("You have forgotten the %s of %s.", p, exe_spell(creature_ptr, which, j % 32, SPELL_NAME));
4309 #endif
4310                 creature_ptr->new_spells++;
4311         }
4312
4313         /* Check for spells to remember */
4314         for (int i = 0; i < 64; i++)
4315         {
4316                 /* None left to remember */
4317                 if (creature_ptr->new_spells <= 0) break;
4318
4319                 /* Efficiency -- all done */
4320                 if (!creature_ptr->spell_forgotten1 && !creature_ptr->spell_forgotten2) break;
4321
4322                 /* Get the next spell we learned */
4323                 int j = creature_ptr->spell_order[i];
4324
4325                 /* Skip unknown spells */
4326                 if (j >= 99) break;
4327
4328                 /* Access the spell */
4329                 const magic_type *s_ptr;
4330                 if (!is_magic((j < 32) ? creature_ptr->realm1 : creature_ptr->realm2))
4331                 {
4332                         if (j < 32)
4333                                 s_ptr = &technic_info[creature_ptr->realm1 - MIN_TECHNIC][j];
4334                         else
4335                                 s_ptr = &technic_info[creature_ptr->realm2 - MIN_TECHNIC][j % 32];
4336                 }
4337                 else if (j < 32)
4338                         s_ptr = &mp_ptr->info[creature_ptr->realm1 - 1][j];
4339                 else
4340                         s_ptr = &mp_ptr->info[creature_ptr->realm2 - 1][j % 32];
4341
4342                 /* Skip spells we cannot remember */
4343                 if (s_ptr->slevel > creature_ptr->lev) continue;
4344
4345                 bool is_spell_learned = (j < 32) ?
4346                         (creature_ptr->spell_forgotten1 & (1L << j)) :
4347                         (creature_ptr->spell_forgotten2 & (1L << (j - 32)));
4348                 if (!is_spell_learned) continue;
4349
4350                 /* No longer forgotten */
4351                 REALM_IDX which;
4352                 if (j < 32)
4353                 {
4354                         creature_ptr->spell_forgotten1 &= ~(1L << j);
4355                         which = creature_ptr->realm1;
4356                 }
4357                 else
4358                 {
4359                         creature_ptr->spell_forgotten2 &= ~(1L << (j - 32));
4360                         which = creature_ptr->realm2;
4361                 }
4362
4363                 /* Known once more */
4364                 if (j < 32)
4365                 {
4366                         creature_ptr->spell_learned1 |= (1L << j);
4367                         which = creature_ptr->realm1;
4368                 }
4369                 else
4370                 {
4371                         creature_ptr->spell_learned2 |= (1L << (j - 32));
4372                         which = creature_ptr->realm2;
4373                 }
4374
4375 #ifdef JP
4376                 msg_format("%sの%sを思い出した。", exe_spell(creature_ptr, which, j % 32, SPELL_NAME), p);
4377 #else
4378                 msg_format("You have remembered the %s of %s.", p, exe_spell(creature_ptr, which, j % 32, SPELL_NAME));
4379 #endif
4380                 creature_ptr->new_spells--;
4381         }
4382
4383         if (creature_ptr->realm2 == REALM_NONE)
4384         {
4385                 /* Count spells that can be learned */
4386                 int k = 0;
4387                 for (int j = 0; j < 32; j++)
4388                 {
4389                         const magic_type *s_ptr;
4390                         if (!is_magic(creature_ptr->realm1)) s_ptr = &technic_info[creature_ptr->realm1 - MIN_TECHNIC][j];
4391                         else s_ptr = &mp_ptr->info[creature_ptr->realm1 - 1][j];
4392
4393                         /* Skip spells we cannot remember */
4394                         if (s_ptr->slevel > creature_ptr->lev) continue;
4395
4396                         /* Skip spells we already know */
4397                         if (creature_ptr->spell_learned1 & (1L << j))
4398                         {
4399                                 continue;
4400                         }
4401
4402                         /* Count it */
4403                         k++;
4404                 }
4405
4406                 if (k > 32) k = 32;
4407                 if ((creature_ptr->new_spells > k) &&
4408                         ((mp_ptr->spell_book == TV_LIFE_BOOK) || (mp_ptr->spell_book == TV_HISSATSU_BOOK)))
4409                 {
4410                         creature_ptr->new_spells = (s16b)k;
4411                 }
4412         }
4413
4414         if (creature_ptr->new_spells < 0) creature_ptr->new_spells = 0;
4415
4416         /* Spell count changed */
4417         if (creature_ptr->old_spells == creature_ptr->new_spells) return;
4418
4419         /* Message if needed */
4420         if (creature_ptr->new_spells)
4421         {
4422 #ifdef JP
4423                 if (creature_ptr->new_spells < 10) {
4424                         msg_format("あと %d つの%sを学べる。", creature_ptr->new_spells, p);
4425                 }
4426                 else {
4427                         msg_format("あと %d 個の%sを学べる。", creature_ptr->new_spells, p);
4428                 }
4429 #else
4430                 msg_format("You can learn %d more %s%s.",
4431                         creature_ptr->new_spells, p,
4432                         (creature_ptr->new_spells != 1) ? "s" : "");
4433 #endif
4434         }
4435
4436         creature_ptr->old_spells = creature_ptr->new_spells;
4437         creature_ptr->redraw |= PR_STUDY;
4438         creature_ptr->window |= PW_OBJECT;
4439 }
4440
4441
4442 /*!
4443  * @brief プレイヤーの最大MPを計算する /
4444  * Calculate maximum mana.  You do not need to know any spells.
4445  * Note that mana is lowered by heavy (or inappropriate) armor.
4446  * @return なし
4447  * @details
4448  * This function induces status messages.
4449  */
4450 static void calc_mana(player_type *creature_ptr)
4451 {
4452         /* Hack -- Must be literate */
4453         if (!mp_ptr->spell_book) return;
4454
4455         int levels;
4456         if ((creature_ptr->pclass == CLASS_MINDCRAFTER) ||
4457                 (creature_ptr->pclass == CLASS_MIRROR_MASTER) ||
4458                 (creature_ptr->pclass == CLASS_BLUE_MAGE))
4459         {
4460                 levels = creature_ptr->lev;
4461         }
4462         else
4463         {
4464                 if (mp_ptr->spell_first > creature_ptr->lev)
4465                 {
4466                         /* Save new mana */
4467                         creature_ptr->msp = 0;
4468
4469                         /* Display mana later */
4470                         creature_ptr->redraw |= (PR_MANA);
4471                         return;
4472                 }
4473
4474                 /* Extract "effective" player level */
4475                 levels = (creature_ptr->lev - mp_ptr->spell_first) + 1;
4476         }
4477
4478         int msp;
4479         if (creature_ptr->pclass == CLASS_SAMURAI)
4480         {
4481                 msp = (adj_mag_mana[creature_ptr->stat_ind[mp_ptr->spell_stat]] + 10) * 2;
4482                 if (msp) msp += (msp * rp_ptr->r_adj[mp_ptr->spell_stat] / 20);
4483         }
4484         else
4485         {
4486                 /* Extract total mana */
4487                 msp = adj_mag_mana[creature_ptr->stat_ind[mp_ptr->spell_stat]] * (levels + 3) / 4;
4488
4489                 /* Hack -- usually add one mana */
4490                 if (msp) msp++;
4491
4492                 if (msp) msp += (msp * rp_ptr->r_adj[mp_ptr->spell_stat] / 20);
4493
4494                 if (msp && (creature_ptr->pseikaku == SEIKAKU_MUNCHKIN)) msp += msp / 2;
4495
4496                 /* Hack: High mages have a 25% mana bonus */
4497                 if (msp && (creature_ptr->pclass == CLASS_HIGH_MAGE)) msp += msp / 4;
4498
4499                 if (msp && (creature_ptr->pclass == CLASS_SORCERER)) msp += msp * (25 + creature_ptr->lev) / 100;
4500         }
4501
4502         /* Only mages are affected */
4503         if (mp_ptr->spell_xtra & MAGIC_GLOVE_REDUCE_MANA)
4504         {
4505                 BIT_FLAGS flgs[TR_FLAG_SIZE];
4506
4507                 /* Assume player is not encumbered by gloves */
4508                 creature_ptr->cumber_glove = FALSE;
4509
4510                 /* Get the gloves */
4511                 object_type *o_ptr;
4512                 o_ptr = &creature_ptr->inventory_list[INVEN_HANDS];
4513
4514                 /* Examine the gloves */
4515                 object_flags(o_ptr, flgs);
4516
4517                 /* Normal gloves hurt mage-type spells */
4518                 if (o_ptr->k_idx &&
4519                         !(have_flag(flgs, TR_FREE_ACT)) &&
4520                         !(have_flag(flgs, TR_DEC_MANA)) &&
4521                         !(have_flag(flgs, TR_EASY_SPELL)) &&
4522                         !((have_flag(flgs, TR_MAGIC_MASTERY)) && (o_ptr->pval > 0)) &&
4523                         !((have_flag(flgs, TR_DEX)) && (o_ptr->pval > 0)))
4524                 {
4525                         /* Encumbered */
4526                         creature_ptr->cumber_glove = TRUE;
4527
4528                         /* Reduce mana */
4529                         msp = (3 * msp) / 4;
4530                 }
4531         }
4532
4533         /* Assume player not encumbered by armor */
4534         creature_ptr->cumber_armor = FALSE;
4535
4536         /* Weigh the armor */
4537         int cur_wgt = 0;
4538         if (creature_ptr->inventory_list[INVEN_RARM].tval > TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_RARM].weight;
4539         if (creature_ptr->inventory_list[INVEN_LARM].tval > TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_LARM].weight;
4540         cur_wgt += creature_ptr->inventory_list[INVEN_BODY].weight;
4541         cur_wgt += creature_ptr->inventory_list[INVEN_HEAD].weight;
4542         cur_wgt += creature_ptr->inventory_list[INVEN_OUTER].weight;
4543         cur_wgt += creature_ptr->inventory_list[INVEN_HANDS].weight;
4544         cur_wgt += creature_ptr->inventory_list[INVEN_FEET].weight;
4545
4546         /* Subtract a percentage of maximum mana. */
4547         switch (creature_ptr->pclass)
4548         {
4549                 /* For these classes, mana is halved if armour
4550                  * is 30 pounds over their weight limit. */
4551         case CLASS_MAGE:
4552         case CLASS_HIGH_MAGE:
4553         case CLASS_BLUE_MAGE:
4554         case CLASS_MONK:
4555         case CLASS_FORCETRAINER:
4556         case CLASS_SORCERER:
4557         {
4558                 if (creature_ptr->inventory_list[INVEN_RARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_RARM].weight;
4559                 if (creature_ptr->inventory_list[INVEN_LARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_LARM].weight;
4560                 break;
4561         }
4562
4563         /* Mana halved if armour is 40 pounds over weight limit. */
4564         case CLASS_PRIEST:
4565         case CLASS_BARD:
4566         case CLASS_TOURIST:
4567         {
4568                 if (creature_ptr->inventory_list[INVEN_RARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_RARM].weight * 2 / 3;
4569                 if (creature_ptr->inventory_list[INVEN_LARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_LARM].weight * 2 / 3;
4570                 break;
4571         }
4572
4573         case CLASS_MINDCRAFTER:
4574         case CLASS_BEASTMASTER:
4575         case CLASS_MIRROR_MASTER:
4576         {
4577                 if (creature_ptr->inventory_list[INVEN_RARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_RARM].weight / 2;
4578                 if (creature_ptr->inventory_list[INVEN_LARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_LARM].weight / 2;
4579                 break;
4580         }
4581
4582         /* Mana halved if armour is 50 pounds over weight limit. */
4583         case CLASS_ROGUE:
4584         case CLASS_RANGER:
4585         case CLASS_RED_MAGE:
4586         case CLASS_WARRIOR_MAGE:
4587         {
4588                 if (creature_ptr->inventory_list[INVEN_RARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_RARM].weight / 3;
4589                 if (creature_ptr->inventory_list[INVEN_LARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_LARM].weight / 3;
4590                 break;
4591         }
4592
4593         /* Mana halved if armour is 60 pounds over weight limit. */
4594         case CLASS_PALADIN:
4595         case CLASS_CHAOS_WARRIOR:
4596         {
4597                 if (creature_ptr->inventory_list[INVEN_RARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_RARM].weight / 5;
4598                 if (creature_ptr->inventory_list[INVEN_LARM].tval <= TV_SWORD) cur_wgt += creature_ptr->inventory_list[INVEN_LARM].weight / 5;
4599                 break;
4600         }
4601
4602         /* For new classes created, but not yet added to this formula. */
4603         default:
4604         {
4605                 break;
4606         }
4607         }
4608
4609         /* Determine the weight allowance */
4610         int max_wgt = mp_ptr->spell_weight;
4611
4612         /* Heavy armor penalizes mana by a percentage.  -LM- */
4613         if ((cur_wgt - max_wgt) > 0)
4614         {
4615                 /* Encumbered */
4616                 creature_ptr->cumber_armor = TRUE;
4617
4618                 /* Subtract a percentage of maximum mana. */
4619                 switch (creature_ptr->pclass)
4620                 {
4621                         /* For these classes, mana is halved if armour
4622                          * is 30 pounds over their weight limit. */
4623                 case CLASS_MAGE:
4624                 case CLASS_HIGH_MAGE:
4625                 case CLASS_BLUE_MAGE:
4626                 {
4627                         msp -= msp * (cur_wgt - max_wgt) / 600;
4628                         break;
4629                 }
4630
4631                 /* Mana halved if armour is 40 pounds over weight limit. */
4632                 case CLASS_PRIEST:
4633                 case CLASS_MINDCRAFTER:
4634                 case CLASS_BEASTMASTER:
4635                 case CLASS_BARD:
4636                 case CLASS_FORCETRAINER:
4637                 case CLASS_TOURIST:
4638                 case CLASS_MIRROR_MASTER:
4639                 {
4640                         msp -= msp * (cur_wgt - max_wgt) / 800;
4641                         break;
4642                 }
4643
4644                 case CLASS_SORCERER:
4645                 {
4646                         msp -= msp * (cur_wgt - max_wgt) / 900;
4647                         break;
4648                 }
4649
4650                 /* Mana halved if armour is 50 pounds over weight limit. */
4651                 case CLASS_ROGUE:
4652                 case CLASS_RANGER:
4653                 case CLASS_MONK:
4654                 case CLASS_RED_MAGE:
4655                 {
4656                         msp -= msp * (cur_wgt - max_wgt) / 1000;
4657                         break;
4658                 }
4659
4660                 /* Mana halved if armour is 60 pounds over weight limit. */
4661                 case CLASS_PALADIN:
4662                 case CLASS_CHAOS_WARRIOR:
4663                 case CLASS_WARRIOR_MAGE:
4664                 {
4665                         msp -= msp * (cur_wgt - max_wgt) / 1200;
4666                         break;
4667                 }
4668
4669                 case CLASS_SAMURAI:
4670                 {
4671                         creature_ptr->cumber_armor = FALSE;
4672                         break;
4673                 }
4674
4675                 /* For new classes created, but not yet added to this formula. */
4676                 default:
4677                 {
4678                         msp -= msp * (cur_wgt - max_wgt) / 800;
4679                         break;
4680                 }
4681                 }
4682         }
4683
4684         /* Mana can never be negative */
4685         if (msp < 0) msp = 0;
4686
4687         /* Maximum mana has changed */
4688         if (creature_ptr->msp != msp)
4689         {
4690                 /* Enforce maximum */
4691                 if ((creature_ptr->csp >= msp) && (creature_ptr->pclass != CLASS_SAMURAI))
4692                 {
4693                         creature_ptr->csp = msp;
4694                         creature_ptr->csp_frac = 0;
4695                 }
4696
4697 #ifdef JP
4698                 /* レベルアップの時は上昇量を表示する */
4699                 if (creature_ptr->level_up_message && (msp > creature_ptr->msp))
4700                 {
4701                         msg_format("最大マジック・ポイントが %d 増加した!", (msp - creature_ptr->msp));
4702                 }
4703 #endif
4704                 /* Save new mana */
4705                 creature_ptr->msp = msp;
4706
4707                 /* Display mana later */
4708                 creature_ptr->redraw |= (PR_MANA);
4709                 creature_ptr->window |= (PW_PLAYER | PW_SPELL);
4710         }
4711
4712         /* Hack -- handle "xtra" mode */
4713         if (current_world_ptr->character_xtra) return;
4714
4715         /* Take note when "glove state" changes */
4716         if (creature_ptr->old_cumber_glove != creature_ptr->cumber_glove)
4717         {
4718                 if (creature_ptr->cumber_glove)
4719                 {
4720                         msg_print(_("手が覆われて呪文が唱えにくい感じがする。", "Your covered hands feel unsuitable for spellcasting."));
4721                 }
4722                 else
4723                 {
4724                         msg_print(_("この手の状態なら、ぐっと呪文が唱えやすい感じだ。", "Your hands feel more suitable for spellcasting."));
4725                 }
4726
4727                 creature_ptr->old_cumber_glove = creature_ptr->cumber_glove;
4728         }
4729
4730         /* Take note when "armor state" changes */
4731         if (creature_ptr->old_cumber_armor == creature_ptr->cumber_armor) return;
4732
4733         if (creature_ptr->cumber_armor)
4734         {
4735                 msg_print(_("装備の重さで動きが鈍くなってしまっている。", "The weight of your equipment encumbers your movement."));
4736         }
4737         else
4738         {
4739                 msg_print(_("ぐっと楽に体を動かせるようになった。", "You feel able to move more freely."));
4740         }
4741
4742         creature_ptr->old_cumber_armor = creature_ptr->cumber_armor;
4743 }
4744
4745
4746 /*!
4747  * @brief 装備中の射撃武器の威力倍率を返す /
4748  * calcurate the fire rate of target object
4749  * @param o_ptr 計算する射撃武器のアイテム情報参照ポインタ
4750  * @return 射撃倍率の値(100で1.00倍)
4751  */
4752 s16b calc_num_fire(player_type *creature_ptr, object_type *o_ptr)
4753 {
4754         /* Scan the usable creature_ptr->inventory_list */
4755         int extra_shots = 0;
4756         BIT_FLAGS flgs[TR_FLAG_SIZE];
4757         for (int i = INVEN_RARM; i < INVEN_TOTAL; i++)
4758         {
4759                 object_type *q_ptr;
4760                 q_ptr = &creature_ptr->inventory_list[i];
4761                 if (!q_ptr->k_idx) continue;
4762
4763                 /* Do not apply current equip */
4764                 if (i == INVEN_BOW) continue;
4765
4766                 object_flags(q_ptr, flgs);
4767
4768                 /* Boost shots */
4769                 if (have_flag(flgs, TR_XTRA_SHOTS)) extra_shots++;
4770         }
4771
4772         object_flags(o_ptr, flgs);
4773         if (have_flag(flgs, TR_XTRA_SHOTS)) extra_shots++;
4774
4775         int num = 0;
4776         if (o_ptr->k_idx == 0 || is_heavy_shoot(creature_ptr, o_ptr))
4777                 return (s16b)num;
4778
4779         num = 100;
4780         /* Extra shots */
4781         num += (extra_shots * 100);
4782
4783         /* Hack -- Rangers love Bows */
4784         OBJECT_TYPE_VALUE tval_ammo = bow_tval_ammo(o_ptr);
4785         if ((creature_ptr->pclass == CLASS_RANGER) &&
4786                 (tval_ammo == TV_ARROW))
4787         {
4788                 num += (creature_ptr->lev * 4);
4789         }
4790
4791         if ((creature_ptr->pclass == CLASS_CAVALRY) &&
4792                 (tval_ammo == TV_ARROW))
4793         {
4794                 num += (creature_ptr->lev * 3);
4795         }
4796
4797         if (creature_ptr->pclass == CLASS_ARCHER)
4798         {
4799                 if (tval_ammo == TV_ARROW)
4800                         num += ((creature_ptr->lev * 5) + 50);
4801                 else if ((tval_ammo == TV_BOLT) || (tval_ammo == TV_SHOT))
4802                         num += (creature_ptr->lev * 4);
4803         }
4804
4805         /*
4806          * Addendum -- also "Reward" high level warriors,
4807          * with _any_ missile weapon -- TY
4808          */
4809         if (creature_ptr->pclass == CLASS_WARRIOR &&
4810                 (tval_ammo <= TV_BOLT) &&
4811                 (tval_ammo >= TV_SHOT))
4812         {
4813                 num += (creature_ptr->lev * 2);
4814         }
4815         if ((creature_ptr->pclass == CLASS_ROGUE) &&
4816                 (tval_ammo == TV_SHOT))
4817         {
4818                 num += (creature_ptr->lev * 4);
4819         }
4820
4821         return (s16b)num;
4822 }
4823
4824
4825 /*!
4826  * @brief プレイヤーの所持重量制限を計算する /
4827  * Computes current weight limit.
4828  * @return 制限重量(ポンド)
4829  */
4830 WEIGHT weight_limit(player_type *creature_ptr)
4831 {
4832         /* Weight limit based only on strength */
4833         WEIGHT i = (WEIGHT)adj_str_wgt[creature_ptr->stat_ind[A_STR]] * 50; /* Constant was 100 */
4834         if (creature_ptr->pclass == CLASS_BERSERKER) i = i * 3 / 2;
4835
4836         /* Return the result */
4837         return i;
4838 }
4839
4840
4841 /*!
4842  * @brief プレイヤーが現在右手/左手に武器を持っているか判定する /
4843  * @param i 判定する手のID(右手:0 左手:1)
4844  * @return 持っているならばTRUE
4845  */
4846 bool has_melee_weapon(player_type *creature_ptr, int i)
4847 {
4848         return ((creature_ptr->inventory_list[i].k_idx && object_is_melee_weapon(&creature_ptr->inventory_list[i])) ? TRUE : FALSE);
4849 }
4850
4851
4852 /*!
4853  * @brief プレイヤーの現在開いている手の状態を返す
4854  * @param riding_control 乗馬中により片手を必要としている状態ならばTRUEを返す。
4855  * @return 開いている手のビットフラグ
4856  */
4857 BIT_FLAGS16 empty_hands(player_type *creature_ptr, bool riding_control)
4858 {
4859         BIT_FLAGS16 status = EMPTY_HAND_NONE;
4860         if (!creature_ptr->inventory_list[INVEN_RARM].k_idx) status |= EMPTY_HAND_RARM;
4861         if (!creature_ptr->inventory_list[INVEN_LARM].k_idx) status |= EMPTY_HAND_LARM;
4862
4863         if (riding_control && (status != EMPTY_HAND_NONE) && creature_ptr->riding && !(creature_ptr->pet_extra_flags & PF_TWO_HANDS))
4864         {
4865                 if (status & EMPTY_HAND_LARM) status &= ~(EMPTY_HAND_LARM);
4866                 else if (status & EMPTY_HAND_RARM) status &= ~(EMPTY_HAND_RARM);
4867         }
4868
4869         return status;
4870 }
4871
4872
4873 /*!
4874  * @brief プレイヤーが防具重量制限のある職業時にペナルティを受ける状態にあるかどうかを返す。
4875  * @return ペナルティが適用されるならばTRUE。
4876  */
4877 bool heavy_armor(player_type *creature_ptr)
4878 {
4879         if ((creature_ptr->pclass != CLASS_MONK) && (creature_ptr->pclass != CLASS_FORCETRAINER) && (creature_ptr->pclass != CLASS_NINJA)) return FALSE;
4880
4881         /* Weight the armor */
4882         WEIGHT monk_arm_wgt = 0;
4883         if (creature_ptr->inventory_list[INVEN_RARM].tval > TV_SWORD) monk_arm_wgt += creature_ptr->inventory_list[INVEN_RARM].weight;
4884         if (creature_ptr->inventory_list[INVEN_LARM].tval > TV_SWORD) monk_arm_wgt += creature_ptr->inventory_list[INVEN_LARM].weight;
4885         monk_arm_wgt += creature_ptr->inventory_list[INVEN_BODY].weight;
4886         monk_arm_wgt += creature_ptr->inventory_list[INVEN_HEAD].weight;
4887         monk_arm_wgt += creature_ptr->inventory_list[INVEN_OUTER].weight;
4888         monk_arm_wgt += creature_ptr->inventory_list[INVEN_HANDS].weight;
4889         monk_arm_wgt += creature_ptr->inventory_list[INVEN_FEET].weight;
4890
4891         return (monk_arm_wgt > (100 + (creature_ptr->lev * 4)));
4892 }
4893
4894
4895 /*!
4896  * @brief update のフラグに応じた更新をまとめて行う / Handle "update"
4897  * @return なし
4898  * @details 更新処理の対象はプレイヤーの能力修正/光源寿命/HP/MP/魔法の学習状態、他多数の外界の状態判定。
4899  */
4900 void update_creature(player_type *creature_ptr)
4901 {
4902         if (!creature_ptr->update) return;
4903
4904         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
4905         if (creature_ptr->update & (PU_AUTODESTROY))
4906         {
4907                 creature_ptr->update &= ~(PU_AUTODESTROY);
4908                 autopick_delayed_alter(creature_ptr);
4909         }
4910
4911         if (creature_ptr->update & (PU_COMBINE))
4912         {
4913                 creature_ptr->update &= ~(PU_COMBINE);
4914                 combine_pack(creature_ptr);
4915         }
4916
4917         /* Reorder the pack */
4918         if (creature_ptr->update & (PU_REORDER))
4919         {
4920                 creature_ptr->update &= ~(PU_REORDER);
4921                 reorder_pack(creature_ptr);
4922         }
4923
4924         if (creature_ptr->update & (PU_BONUS))
4925         {
4926                 creature_ptr->update &= ~(PU_BONUS);
4927                 calc_alignment(creature_ptr);
4928                 calc_bonuses(creature_ptr);
4929         }
4930
4931         if (creature_ptr->update & (PU_TORCH))
4932         {
4933                 creature_ptr->update &= ~(PU_TORCH);
4934                 calc_torch(creature_ptr);
4935         }
4936
4937         if (creature_ptr->update & (PU_HP))
4938         {
4939                 creature_ptr->update &= ~(PU_HP);
4940                 calc_hitpoints(creature_ptr);
4941         }
4942
4943         if (creature_ptr->update & (PU_MANA))
4944         {
4945                 creature_ptr->update &= ~(PU_MANA);
4946                 calc_mana(creature_ptr);
4947         }
4948
4949         if (creature_ptr->update & (PU_SPELLS))
4950         {
4951                 creature_ptr->update &= ~(PU_SPELLS);
4952                 calc_spells(creature_ptr);
4953         }
4954
4955         /* Character is not ready yet, no screen updates */
4956         if (!current_world_ptr->character_generated) return;
4957
4958         /* Character is in "icky" mode, no screen updates */
4959         if (current_world_ptr->character_icky) return;
4960
4961         if (creature_ptr->update & (PU_UN_LITE))
4962         {
4963                 creature_ptr->update &= ~(PU_UN_LITE);
4964                 forget_lite(floor_ptr);
4965         }
4966
4967         if (creature_ptr->update & (PU_UN_VIEW))
4968         {
4969                 creature_ptr->update &= ~(PU_UN_VIEW);
4970                 forget_view(floor_ptr);
4971         }
4972
4973         if (creature_ptr->update & (PU_VIEW))
4974         {
4975                 creature_ptr->update &= ~(PU_VIEW);
4976                 update_view(creature_ptr, floor_ptr);
4977         }
4978
4979         if (creature_ptr->update & (PU_LITE))
4980         {
4981                 creature_ptr->update &= ~(PU_LITE);
4982                 update_lite(creature_ptr);
4983         }
4984
4985         if (creature_ptr->update & (PU_FLOW))
4986         {
4987                 creature_ptr->update &= ~(PU_FLOW);
4988                 update_flow(creature_ptr);
4989         }
4990
4991         if (creature_ptr->update & (PU_DISTANCE))
4992         {
4993                 creature_ptr->update &= ~(PU_DISTANCE);
4994
4995                 /* Still need to call update_monsters(FALSE) after update_mon_lite() */
4996                 /* creature_ptr->update &= ~(PU_MONSTERS); */
4997
4998                 update_monsters(TRUE);
4999         }
5000
5001         if (creature_ptr->update & (PU_MON_LITE))
5002         {
5003                 creature_ptr->update &= ~(PU_MON_LITE);
5004                 update_mon_lite(creature_ptr);
5005         }
5006
5007         /*
5008          * Mega-Hack -- Delayed visual update
5009          * Only used if update_view(), update_lite() or update_mon_lite() was called
5010          */
5011         if (creature_ptr->update & (PU_DELAY_VIS))
5012         {
5013                 creature_ptr->update &= ~(PU_DELAY_VIS);
5014                 delayed_visual_update(creature_ptr);
5015         }
5016
5017         if (creature_ptr->update & (PU_MONSTERS))
5018         {
5019                 creature_ptr->update &= ~(PU_MONSTERS);
5020                 update_monsters(FALSE);
5021         }
5022 }
5023
5024
5025 /*!
5026  * @brief プレイヤーが魔道書を一冊も持っていないかを判定する
5027  * @return 魔道書を一冊も持っていないならTRUEを返す
5028  */
5029 bool player_has_no_spellbooks(player_type *creature_ptr)
5030 {
5031         object_type *o_ptr;
5032         for (int i = 0; i < INVEN_PACK; i++)
5033         {
5034                 o_ptr = &creature_ptr->inventory_list[i];
5035                 if (o_ptr->k_idx && check_book_realm(creature_ptr, o_ptr->tval, o_ptr->sval)) return FALSE;
5036         }
5037
5038         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
5039         for (int i = floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].o_idx; i; i = o_ptr->next_o_idx)
5040         {
5041                 o_ptr = &floor_ptr->o_list[i];
5042                 if (o_ptr->k_idx && (o_ptr->marked & OM_FOUND) && check_book_realm(creature_ptr, o_ptr->tval, o_ptr->sval)) return FALSE;
5043         }
5044
5045         return TRUE;
5046 }
5047
5048
5049 void take_turn(player_type *creature_ptr, PERCENTAGE need_cost)
5050 {
5051         creature_ptr->energy_use = (ENERGY)need_cost;
5052 }
5053
5054
5055 void free_turn(player_type *creature_ptr)
5056 {
5057         creature_ptr->energy_use = 0;
5058 }
5059
5060
5061 /*!
5062  * @brief プレイヤーを指定座標に配置する / Place the player in the dungeon XXX XXX
5063  * @param x 配置先X座標
5064  * @param y 配置先Y座標
5065  * @return 配置に成功したらTRUE
5066  */
5067 bool player_place(player_type *creature_ptr, POSITION y, POSITION x)
5068 {
5069         if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx != 0) return FALSE;
5070
5071         /* Save player location */
5072         creature_ptr->y = y;
5073         creature_ptr->x = x;
5074         return TRUE;
5075 }
5076
5077
5078 /*!
5079  * @brief 種族アンバライトが出血時パターンの上に乗った際のペナルティ処理
5080  * @return なし
5081  */
5082 void wreck_the_pattern(player_type *creature_ptr)
5083 {
5084         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
5085         int pattern_type = f_info[floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].feat].subtype;
5086         if (pattern_type == PATTERN_TILE_WRECKED) return;
5087
5088         msg_print(_("パターンを血で汚してしまった!", "You bleed on the Pattern!"));
5089         msg_print(_("何か恐ろしい事が起こった!", "Something terrible happens!"));
5090
5091         if (!IS_INVULN(creature_ptr))
5092                 take_hit(creature_ptr, DAMAGE_NOESCAPE, damroll(10, 8), _("パターン損壊", "corrupting the Pattern"), -1);
5093
5094         int to_ruin = randint1(45) + 35;
5095         while (to_ruin--)
5096         {
5097                 POSITION r_y, r_x;
5098                 scatter(creature_ptr, &r_y, &r_x, creature_ptr->y, creature_ptr->x, 4, 0);
5099
5100                 if (pattern_tile(r_y, r_x) &&
5101                         (f_info[floor_ptr->grid_array[r_y][r_x].feat].subtype != PATTERN_TILE_WRECKED))
5102                 {
5103                         cave_set_feat(creature_ptr, r_y, r_x, feat_pattern_corrupted);
5104                 }
5105         }
5106
5107         cave_set_feat(creature_ptr, creature_ptr->y, creature_ptr->x, feat_pattern_corrupted);
5108 }
5109
5110
5111 /*!
5112  * @brief ELDRITCH_HORRORによるプレイヤーの精神破壊処理
5113  * @param m_ptr ELDRITCH_HORRORを引き起こしたモンスターの参照ポインタ
5114  * @param necro 暗黒領域魔法の詠唱失敗によるものならばTRUEを返す
5115  * @return なし
5116  */
5117 void sanity_blast(player_type *creature_ptr, monster_type *m_ptr, bool necro)
5118 {
5119         if (creature_ptr->phase_out || !current_world_ptr->character_dungeon) return;
5120
5121         int power = 100;
5122         if (!necro && m_ptr)
5123         {
5124                 GAME_TEXT m_name[MAX_NLEN];
5125                 monster_race *r_ptr = &r_info[m_ptr->ap_r_idx];
5126
5127                 power = r_ptr->level / 2;
5128
5129                 monster_desc(creature_ptr, m_name, m_ptr, 0);
5130
5131                 if (!(r_ptr->flags1 & RF1_UNIQUE))
5132                 {
5133                         if (r_ptr->flags1 & RF1_FRIENDS)
5134                                 power /= 2;
5135                 }
5136                 else power *= 2;
5137
5138                 if (!current_world_ptr->is_loading_now)
5139                         return; /* No effect yet, just loaded... */
5140
5141                 if (!m_ptr->ml)
5142                         return; /* Cannot see it for some reason */
5143
5144                 if (!(r_ptr->flags2 & RF2_ELDRITCH_HORROR))
5145                         return;
5146
5147                 if (is_pet(m_ptr))
5148                         return; /* Pet eldritch horrors are safe most of the time */
5149
5150                 if (randint1(100) > power) return;
5151
5152                 if (saving_throw(creature_ptr->skill_sav - power))
5153                 {
5154                         return; /* Save, no adverse effects */
5155                 }
5156
5157                 if (creature_ptr->image)
5158                 {
5159                         /* Something silly happens... */
5160                         msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
5161                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
5162
5163                         if (one_in_(3))
5164                         {
5165                                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
5166                                 creature_ptr->image = creature_ptr->image + randint1(r_ptr->level);
5167                         }
5168
5169                         return; /* Never mind; we can't see it clearly enough */
5170                 }
5171
5172                 /* Something frightening happens... */
5173                 msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
5174                         horror_desc[randint0(MAX_SAN_HORROR)], m_name);
5175
5176                 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
5177
5178                 /* Demon characters are unaffected */
5179                 if (PRACE_IS_(creature_ptr, RACE_IMP) || PRACE_IS_(creature_ptr, RACE_DEMON) || (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
5180                 if (current_world_ptr->wizard) return;
5181
5182                 /* Undead characters are 50% likely to be unaffected */
5183                 if (PRACE_IS_(creature_ptr, RACE_SKELETON) || PRACE_IS_(creature_ptr, RACE_ZOMBIE)
5184                         || PRACE_IS_(creature_ptr, RACE_VAMPIRE) || PRACE_IS_(creature_ptr, RACE_SPECTRE) ||
5185                         (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD))
5186                 {
5187                         if (saving_throw(25 + creature_ptr->lev)) return;
5188                 }
5189         }
5190         else if (!necro)
5191         {
5192                 monster_race *r_ptr;
5193                 GAME_TEXT m_name[MAX_NLEN];
5194                 concptr desc;
5195
5196                 get_mon_num_prep(creature_ptr, get_nightmare, NULL);
5197
5198                 r_ptr = &r_info[get_mon_num(creature_ptr, MAX_DEPTH)];
5199                 power = r_ptr->level + 10;
5200                 desc = r_name + r_ptr->name;
5201
5202                 get_mon_num_prep(creature_ptr, NULL, NULL);
5203
5204 #ifdef JP
5205 #else
5206
5207                 if (!(r_ptr->flags1 & RF1_UNIQUE))
5208                         sprintf(m_name, "%s %s", (is_a_vowel(desc[0]) ? "an" : "a"), desc);
5209                 else
5210 #endif
5211                         sprintf(m_name, "%s", desc);
5212
5213                 if (!(r_ptr->flags1 & RF1_UNIQUE))
5214                 {
5215                         if (r_ptr->flags1 & RF1_FRIENDS) power /= 2;
5216                 }
5217                 else power *= 2;
5218
5219                 if (saving_throw(creature_ptr->skill_sav * 100 / power))
5220                 {
5221                         msg_format(_("夢の中で%sに追いかけられた。", "%^s chases you through your dreams."), m_name);
5222                         /* Safe */
5223                         return;
5224                 }
5225
5226                 if (creature_ptr->image)
5227                 {
5228                         /* Something silly happens... */
5229                         msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
5230                                 funny_desc[randint0(MAX_SAN_FUNNY)], m_name);
5231
5232                         if (one_in_(3))
5233                         {
5234                                 msg_print(funny_comments[randint0(MAX_SAN_COMMENT)]);
5235                                 creature_ptr->image = creature_ptr->image + randint1(r_ptr->level);
5236                         }
5237
5238                         /* Never mind; we can't see it clearly enough */
5239                         return;
5240                 }
5241
5242                 /* Something frightening happens... */
5243                 msg_format(_("%s%sの顔を見てしまった!", "You behold the %s visage of %s!"),
5244                         horror_desc[randint0(MAX_SAN_HORROR)], desc);
5245
5246                 r_ptr->r_flags2 |= RF2_ELDRITCH_HORROR;
5247
5248                 if (!creature_ptr->mimic_form)
5249                 {
5250                         switch (creature_ptr->prace)
5251                         {
5252                                 /* Demons may make a saving throw */
5253                         case RACE_IMP:
5254                         case RACE_DEMON:
5255                                 if (saving_throw(20 + creature_ptr->lev)) return;
5256                                 break;
5257                                 /* Undead may make a saving throw */
5258                         case RACE_SKELETON:
5259                         case RACE_ZOMBIE:
5260                         case RACE_SPECTRE:
5261                         case RACE_VAMPIRE:
5262                                 if (saving_throw(10 + creature_ptr->lev)) return;
5263                                 break;
5264                         }
5265                 }
5266                 else
5267                 {
5268                         /* Demons may make a saving throw */
5269                         if (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)
5270                         {
5271                                 if (saving_throw(20 + creature_ptr->lev)) return;
5272                         }
5273                         /* Undead may make a saving throw */
5274                         else if (mimic_info[creature_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_UNDEAD)
5275                         {
5276                                 if (saving_throw(10 + creature_ptr->lev)) return;
5277                         }
5278                 }
5279         }
5280         else
5281         {
5282                 msg_print(_("ネクロノミコンを読んで正気を失った!", "Your sanity is shaken by reading the Necronomicon!"));
5283         }
5284
5285         /* 過去の効果無効率再現のため5回saving_throw 実行 */
5286         if (saving_throw(creature_ptr->skill_sav - power)
5287                 && saving_throw(creature_ptr->skill_sav - power)
5288                 && saving_throw(creature_ptr->skill_sav - power)
5289                 && saving_throw(creature_ptr->skill_sav - power)
5290                 && saving_throw(creature_ptr->skill_sav - power)
5291                 )
5292         {
5293                 return;
5294         }
5295
5296         switch (randint1(22))
5297         {
5298         case 1:
5299                 if (!(creature_ptr->muta3 & MUT3_MORONIC))
5300                 {
5301                         if ((creature_ptr->stat_use[A_INT] < 4) && (creature_ptr->stat_use[A_WIS] < 4))
5302                         {
5303                                 msg_print(_("あなたは完璧な馬鹿になったような気がした。しかしそれは元々だった。", "You turn into an utter moron!"));
5304                         }
5305                         else
5306                         {
5307                                 msg_print(_("あなたは完璧な馬鹿になった!", "You turn into an utter moron!"));
5308                         }
5309
5310                         if (creature_ptr->muta3 & MUT3_HYPER_INT)
5311                         {
5312                                 msg_print(_("あなたの脳は生体コンピュータではなくなった。", "Your brain is no longer a living computer."));
5313                                 creature_ptr->muta3 &= ~(MUT3_HYPER_INT);
5314                         }
5315                         creature_ptr->muta3 |= MUT3_MORONIC;
5316                 }
5317                 break;
5318         case 2:
5319                 if (!(creature_ptr->muta2 & MUT2_COWARDICE) && !creature_ptr->resist_fear)
5320                 {
5321                         msg_print(_("あなたはパラノイアになった!", "You become paranoid!"));
5322
5323                         /* Duh, the following should never happen, but anyway... */
5324                         if (creature_ptr->muta3 & MUT3_FEARLESS)
5325                         {
5326                                 msg_print(_("あなたはもう恐れ知らずではなくなった。", "You are no longer fearless."));
5327                                 creature_ptr->muta3 &= ~(MUT3_FEARLESS);
5328                         }
5329
5330                         creature_ptr->muta2 |= MUT2_COWARDICE;
5331                 }
5332                 break;
5333         case 3:
5334                 if (!(creature_ptr->muta2 & MUT2_HALLU) && !creature_ptr->resist_chaos)
5335                 {
5336                         msg_print(_("幻覚をひき起こす精神錯乱に陥った!", "You are afflicted by a hallucinatory insanity!"));
5337                         creature_ptr->muta2 |= MUT2_HALLU;
5338                 }
5339                 break;
5340         case 4:
5341                 if (!(creature_ptr->muta2 & MUT2_BERS_RAGE) && !creature_ptr->resist_conf)
5342                 {
5343                         msg_print(_("激烈な感情の発作におそわれるようになった!", "You become subject to fits of berserk rage!"));
5344                         creature_ptr->muta2 |= MUT2_BERS_RAGE;
5345                 }
5346                 break;
5347         case 5:
5348         case 6:
5349         case 7:
5350         case 8:
5351         case 9:
5352         case 10:
5353         case 11:
5354         case 12:
5355                 /* Mind blast */
5356                 if (!creature_ptr->resist_conf)
5357                 {
5358                         (void)set_confused(creature_ptr, creature_ptr->confused + randint0(4) + 4);
5359                 }
5360                 if (!creature_ptr->resist_chaos && one_in_(3))
5361                 {
5362                         (void)set_image(creature_ptr, creature_ptr->image + randint0(250) + 150);
5363                 }
5364                 return;
5365                 break;
5366         case 13:
5367         case 14:
5368         case 15:
5369                 /* Brain smash */
5370                 if (!creature_ptr->resist_conf)
5371                 {
5372                         (void)set_confused(creature_ptr, creature_ptr->confused + randint0(4) + 4);
5373                 }
5374                 if (!creature_ptr->free_act)
5375                 {
5376                         (void)set_paralyzed(creature_ptr, creature_ptr->paralyzed + randint0(4) + 4);
5377                 }
5378                 if (!creature_ptr->resist_chaos)
5379                 {
5380                         (void)set_image(creature_ptr, creature_ptr->image + randint0(250) + 150);
5381                 }
5382                 do {
5383                         (void)do_dec_stat(creature_ptr, A_INT);
5384                 } while (randint0(100) > creature_ptr->skill_sav && one_in_(2));
5385
5386                 do {
5387                         (void)do_dec_stat(creature_ptr, A_WIS);
5388                 } while (randint0(100) > creature_ptr->skill_sav && one_in_(2));
5389
5390                 break;
5391         case 16:
5392         case 17:
5393                 /* Amnesia */
5394                 if (lose_all_info(creature_ptr))
5395                         msg_print(_("あまりの恐怖に全てのことを忘れてしまった!", "You forget everything in your utmost terror!"));
5396                 break;
5397         case 18:
5398         case 19:
5399         case 20:
5400         case 21:
5401         case 22:
5402                 /* Lose int & wis */
5403                 do_dec_stat(creature_ptr, A_INT);
5404                 do_dec_stat(creature_ptr, A_WIS);
5405                 break;
5406         default:
5407                 break;
5408         }
5409
5410         creature_ptr->update |= PU_BONUS;
5411         handle_stuff(creature_ptr);
5412 }
5413
5414
5415 /*!
5416  * @brief プレイヤーの経験値について整合性のためのチェックと調整を行う /
5417  * Advance experience levels and print experience
5418  * @return なし
5419  */
5420 void check_experience(player_type *creature_ptr)
5421 {
5422         /* Hack -- lower limit */
5423         if (creature_ptr->exp < 0) creature_ptr->exp = 0;
5424         if (creature_ptr->max_exp < 0) creature_ptr->max_exp = 0;
5425         if (creature_ptr->max_max_exp < 0) creature_ptr->max_max_exp = 0;
5426
5427         /* Hack -- upper limit */
5428         if (creature_ptr->exp > PY_MAX_EXP) creature_ptr->exp = PY_MAX_EXP;
5429         if (creature_ptr->max_exp > PY_MAX_EXP) creature_ptr->max_exp = PY_MAX_EXP;
5430         if (creature_ptr->max_max_exp > PY_MAX_EXP) creature_ptr->max_max_exp = PY_MAX_EXP;
5431
5432         /* Hack -- maintain "max" experience */
5433         if (creature_ptr->exp > creature_ptr->max_exp) creature_ptr->max_exp = creature_ptr->exp;
5434
5435         /* Hack -- maintain "max max" experience */
5436         if (creature_ptr->max_exp > creature_ptr->max_max_exp) creature_ptr->max_max_exp = creature_ptr->max_exp;
5437
5438         /* Redraw experience */
5439         creature_ptr->redraw |= (PR_EXP);
5440         handle_stuff(creature_ptr);
5441
5442         /* Lose levels while possible */
5443         bool android = (creature_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
5444         PLAYER_LEVEL old_lev = creature_ptr->lev;
5445         while ((creature_ptr->lev > 1) &&
5446                 (creature_ptr->exp < ((android ? player_exp_a : player_exp)[creature_ptr->lev - 2] * creature_ptr->expfact / 100L)))
5447         {
5448                 /* Lose a level */
5449                 creature_ptr->lev--;
5450                 creature_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
5451                 creature_ptr->redraw |= (PR_LEV | PR_TITLE);
5452                 creature_ptr->window |= (PW_PLAYER);
5453                 handle_stuff(creature_ptr);
5454         }
5455
5456         /* Gain levels while possible */
5457         bool level_reward = FALSE;
5458         bool level_mutation = FALSE;
5459         bool level_inc_stat = FALSE;
5460         while ((creature_ptr->lev < PY_MAX_LEVEL) &&
5461                 (creature_ptr->exp >= ((android ? player_exp_a : player_exp)[creature_ptr->lev - 1] * creature_ptr->expfact / 100L)))
5462         {
5463                 /* Gain a level */
5464                 creature_ptr->lev++;
5465
5466                 /* Save the highest level */
5467                 if (creature_ptr->lev > creature_ptr->max_plv)
5468                 {
5469                         creature_ptr->max_plv = creature_ptr->lev;
5470
5471                         if ((creature_ptr->pclass == CLASS_CHAOS_WARRIOR) ||
5472                                 (creature_ptr->muta2 & MUT2_CHAOS_GIFT))
5473                         {
5474                                 level_reward = TRUE;
5475                         }
5476                         if (creature_ptr->prace == RACE_BEASTMAN)
5477                         {
5478                                 if (one_in_(5)) level_mutation = TRUE;
5479                         }
5480                         level_inc_stat = TRUE;
5481
5482                         exe_write_diary(creature_ptr, DIARY_LEVELUP, creature_ptr->lev, NULL);
5483                 }
5484
5485                 sound(SOUND_LEVEL);
5486
5487                 msg_format(_("レベル %d にようこそ。", "Welcome to level %d."), creature_ptr->lev);
5488
5489                 creature_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
5490                 creature_ptr->redraw |= (PR_LEV | PR_TITLE | PR_EXP);
5491                 creature_ptr->window |= (PW_PLAYER | PW_SPELL | PW_INVEN);
5492
5493                 /* HPとMPの上昇量を表示 */
5494                 creature_ptr->level_up_message = TRUE;
5495                 handle_stuff(creature_ptr);
5496
5497                 creature_ptr->level_up_message = FALSE;
5498
5499                 if (level_inc_stat)
5500                 {
5501                         if (!(creature_ptr->max_plv % 10))
5502                         {
5503                                 int choice;
5504                                 screen_save();
5505                                 while (TRUE)
5506                                 {
5507                                         int n;
5508                                         char tmp[32];
5509
5510                                         cnv_stat(creature_ptr->stat_max[0], tmp);
5511                                         prt(format(_("        a) 腕力 (現在値 %s)", "        a) Str (cur %s)"), tmp), 2, 14);
5512                                         cnv_stat(creature_ptr->stat_max[1], tmp);
5513                                         prt(format(_("        b) 知能 (現在値 %s)", "        b) Int (cur %s)"), tmp), 3, 14);
5514                                         cnv_stat(creature_ptr->stat_max[2], tmp);
5515                                         prt(format(_("        c) 賢さ (現在値 %s)", "        c) Wis (cur %s)"), tmp), 4, 14);
5516                                         cnv_stat(creature_ptr->stat_max[3], tmp);
5517                                         prt(format(_("        d) 器用 (現在値 %s)", "        d) Dex (cur %s)"), tmp), 5, 14);
5518                                         cnv_stat(creature_ptr->stat_max[4], tmp);
5519                                         prt(format(_("        e) 耐久 (現在値 %s)", "        e) Con (cur %s)"), tmp), 6, 14);
5520                                         cnv_stat(creature_ptr->stat_max[5], tmp);
5521                                         prt(format(_("        f) 魅力 (現在値 %s)", "        f) Chr (cur %s)"), tmp), 7, 14);
5522
5523                                         prt("", 8, 14);
5524                                         prt(_("        どの能力値を上げますか?", "        Which stat do you want to raise?"), 1, 14);
5525
5526                                         while (TRUE)
5527                                         {
5528                                                 choice = inkey();
5529                                                 if ((choice >= 'a') && (choice <= 'f')) break;
5530                                         }
5531                                         for (n = 0; n < A_MAX; n++)
5532                                                 if (n != choice - 'a')
5533                                                         prt("", n + 2, 14);
5534                                         if (get_check(_("よろしいですか?", "Are you sure? "))) break;
5535                                 }
5536                                 do_inc_stat(creature_ptr, choice - 'a');
5537                                 screen_load();
5538                         }
5539                         else if (!(creature_ptr->max_plv % 2))
5540                                 do_inc_stat(creature_ptr, randint0(6));
5541                 }
5542
5543                 if (level_mutation)
5544                 {
5545                         msg_print(_("あなたは変わった気がする...", "You feel different..."));
5546                         (void)gain_mutation(creature_ptr, 0);
5547                         level_mutation = FALSE;
5548                 }
5549
5550                 /*
5551                  * 報酬でレベルが上ると再帰的に check_experience(creature_ptr) が
5552                  * 呼ばれるので順番を最後にする。
5553                  */
5554                 if (level_reward)
5555                 {
5556                         gain_level_reward(creature_ptr, 0);
5557                         level_reward = FALSE;
5558                 }
5559
5560                 creature_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
5561                 creature_ptr->redraw |= (PR_LEV | PR_TITLE);
5562                 creature_ptr->window |= (PW_PLAYER | PW_SPELL);
5563                 handle_stuff(creature_ptr);
5564         }
5565
5566         /* Load an autopick preference file */
5567         if (old_lev != creature_ptr->lev) autopick_load_pref(creature_ptr, FALSE);
5568 }
5569
5570
5571 /*!
5572  * @brief 現在の修正後能力値を3~17及び18/xxx形式に変換する / Converts stat num into a six-char (right justified) string
5573  * @param val 能力値
5574  * @param out_val 出力先文字列ポインタ
5575  * @return なし
5576  */
5577 void cnv_stat(int val, char *out_val)
5578 {
5579         if (val <= 18)
5580         {
5581                 sprintf(out_val, "    %2d", val);
5582                 return;
5583         }
5584
5585         int bonus = (val - 18);
5586         if (bonus >= 220)
5587         {
5588                 sprintf(out_val, "18/%3s", "***");
5589         }
5590         else if (bonus >= 100)
5591         {
5592                 sprintf(out_val, "18/%03d", bonus);
5593         }
5594         else
5595         {
5596                 sprintf(out_val, " 18/%02d", bonus);
5597         }
5598 }
5599
5600
5601 /*!
5602  * @brief 能力値現在値から3~17及び18/xxx様式に基づく加減算を行う。
5603  * Modify a stat value by a "modifier", return new value
5604  * @param value 現在値
5605  * @param amount 加減算値
5606  * @return 加減算後の値
5607  * @details
5608  * <pre>
5609  * Stats go up: 3,4,...,17,18,18/10,18/20,...,18/220
5610  * Or even: 18/13, 18/23, 18/33, ..., 18/220
5611  * Stats go down: 18/220, 18/210,..., 18/10, 18, 17, ..., 3
5612  * Or even: 18/13, 18/03, 18, 17, ..., 3
5613  * </pre>
5614  */
5615 s16b modify_stat_value(int value, int amount)
5616 {
5617         /* Reward */
5618         if (amount > 0)
5619         {
5620                 /* Apply each point */
5621                 for (int i = 0; i < amount; i++)
5622                 {
5623                         /* One point at a time */
5624                         if (value < 18) value++;
5625
5626                         /* Ten "points" at a time */
5627                         else value += 10;
5628                 }
5629         }
5630
5631         /* Penalty */
5632         else if (amount < 0)
5633         {
5634                 /* Apply each point */
5635                 for (int i = 0; i < (0 - amount); i++)
5636                 {
5637                         /* Ten points at a time */
5638                         if (value >= 18 + 10) value -= 10;
5639
5640                         /* Hack -- prevent weirdness */
5641                         else if (value > 18) value = 18;
5642
5643                         /* One point at a time */
5644                         else if (value > 3) value--;
5645                 }
5646         }
5647
5648         /* Return new value */
5649         return (s16b)value;
5650 }
5651
5652
5653 /*!
5654  * @brief スコアを計算する /
5655  * Hack -- Calculates the total number of points earned         -JWT-
5656  * @return なし
5657  * @details
5658  */
5659 long calc_score(player_type *creature_ptr)
5660 {
5661         int arena_win = MIN(creature_ptr->arena_number, MAX_ARENA_MONS);
5662
5663         int mult = 100;
5664         if (!preserve_mode) mult += 10;
5665         if (!autoroller) mult += 10;
5666         if (!smart_learn) mult -= 20;
5667         if (smart_cheat) mult += 30;
5668         if (ironman_shops) mult += 50;
5669         if (ironman_small_levels) mult += 10;
5670         if (ironman_empty_levels) mult += 20;
5671         if (!powerup_home) mult += 50;
5672         if (ironman_rooms) mult += 100;
5673         if (ironman_nightmare) mult += 100;
5674
5675         if (mult < 5) mult = 5;
5676
5677         DEPTH max_dl = 0;
5678         for (int i = 0; i < current_world_ptr->max_d_idx; i++)
5679                 if (max_dlv[i] > max_dl)
5680                         max_dl = max_dlv[i];
5681
5682         u32b point_l = (creature_ptr->max_max_exp + (100 * max_dl));
5683         u32b point_h = point_l / 0x10000L;
5684         point_l = point_l % 0x10000L;
5685         point_h *= mult;
5686         point_l *= mult;
5687         point_h += point_l / 0x10000L;
5688         point_l %= 0x10000L;
5689
5690         point_l += ((point_h % 100) << 16);
5691         point_h /= 100;
5692         point_l /= 100;
5693
5694         u32b point = (point_h << 16) + (point_l);
5695         if (creature_ptr->arena_number >= 0)
5696                 point += (arena_win * arena_win * (arena_win > 29 ? 1000 : 100));
5697
5698         if (ironman_downward) point *= 2;
5699         if (creature_ptr->pclass == CLASS_BERSERKER)
5700         {
5701                 if (creature_ptr->prace == RACE_SPECTRE)
5702                         point = point / 5;
5703         }
5704
5705         if ((creature_ptr->pseikaku == SEIKAKU_MUNCHKIN) && point)
5706         {
5707                 point = 1;
5708                 if (current_world_ptr->total_winner) point = 2;
5709         }
5710
5711         if (easy_band) point = (0 - point);
5712
5713         return point;
5714 }
5715
5716
5717 void cheat_death(player_type *creature_ptr)
5718 {
5719         /* Mark social class, reset age, if needed */
5720         if (creature_ptr->sc) creature_ptr->sc = creature_ptr->age = 0;
5721
5722         /* Increase age */
5723         creature_ptr->age++;
5724
5725         /* Mark savefile */
5726         current_world_ptr->noscore |= 0x0001;
5727
5728         msg_print(_("ウィザードモードに念を送り、死を欺いた。", "You invoke wizard mode and cheat death."));
5729         msg_print(NULL);
5730
5731         (void)life_stream(creature_ptr, FALSE, FALSE);
5732
5733         if (creature_ptr->pclass == CLASS_MAGIC_EATER)
5734         {
5735                 int magic_idx;
5736                 for (magic_idx = 0; magic_idx < EATER_EXT * 2; magic_idx++)
5737                 {
5738                         creature_ptr->magic_num1[magic_idx] = creature_ptr->magic_num2[magic_idx] * EATER_CHARGE;
5739                 }
5740                 for (; magic_idx < EATER_EXT * 3; magic_idx++)
5741                 {
5742                         creature_ptr->magic_num1[magic_idx] = 0;
5743                 }
5744         }
5745
5746         /* Restore spell points */
5747         creature_ptr->csp = creature_ptr->msp;
5748         creature_ptr->csp_frac = 0;
5749
5750         /* Hack -- cancel recall */
5751         if (creature_ptr->word_recall)
5752         {
5753                 msg_print(_("張りつめた大気が流れ去った...", "A tension leaves the air around you..."));
5754                 msg_print(NULL);
5755
5756                 /* Hack -- Prevent recall */
5757                 creature_ptr->word_recall = 0;
5758                 creature_ptr->redraw |= (PR_STATUS);
5759         }
5760
5761         /* Hack -- cancel alter */
5762         if (creature_ptr->alter_reality)
5763         {
5764                 /* Hack -- Prevent alter */
5765                 creature_ptr->alter_reality = 0;
5766                 creature_ptr->redraw |= (PR_STATUS);
5767         }
5768
5769         /* Note cause of death */
5770         (void)strcpy(creature_ptr->died_from, _("死の欺き", "Cheating death"));
5771
5772         /* Do not die */
5773         creature_ptr->is_dead = FALSE;
5774
5775         /* Hack -- Prevent starvation */
5776         (void)set_food(creature_ptr, PY_FOOD_MAX - 1);
5777
5778         floor_type *floor_ptr = creature_ptr->current_floor_ptr;
5779         floor_ptr->dun_level = 0;
5780         floor_ptr->inside_arena = FALSE;
5781         creature_ptr->phase_out = FALSE;
5782         leaving_quest = 0;
5783         floor_ptr->inside_quest = 0;
5784         if (creature_ptr->dungeon_idx) creature_ptr->recall_dungeon = creature_ptr->dungeon_idx;
5785         creature_ptr->dungeon_idx = 0;
5786         if (lite_town || vanilla_town)
5787         {
5788                 creature_ptr->wilderness_y = 1;
5789                 creature_ptr->wilderness_x = 1;
5790                 if (vanilla_town)
5791                 {
5792                         creature_ptr->oldpy = 10;
5793                         creature_ptr->oldpx = 34;
5794                 }
5795                 else
5796                 {
5797                         creature_ptr->oldpy = 33;
5798                         creature_ptr->oldpx = 131;
5799                 }
5800         }
5801         else
5802         {
5803                 creature_ptr->wilderness_y = 48;
5804                 creature_ptr->wilderness_x = 5;
5805                 creature_ptr->oldpy = 33;
5806                 creature_ptr->oldpx = 131;
5807         }
5808
5809         creature_ptr->wild_mode = FALSE;
5810         creature_ptr->leaving = TRUE;
5811
5812         exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1,
5813                 _("                            しかし、生き返った。",
5814                         "                            but revived."));
5815
5816         /* Prepare next floor */
5817         leave_floor(creature_ptr);
5818         wipe_monsters_list(creature_ptr);
5819 }
5820
5821
5822 /*!
5823  * @param creature_ptr プレーヤーへの参照ポインタ
5824  * @return 祝福状態ならばTRUE
5825  */
5826 bool is_blessed(player_type *creature_ptr)
5827 {
5828         return creature_ptr->blessed || music_singing(creature_ptr, MUSIC_BLESS) || hex_spelling(creature_ptr, HEX_BLESS);
5829 }
5830
5831
5832 bool is_oppose_acid(player_type *creature_ptr)
5833 {
5834         return creature_ptr->oppose_acid || music_singing(creature_ptr, MUSIC_RESIST) || (creature_ptr->special_defense & KATA_MUSOU);
5835 }
5836
5837
5838 bool is_oppose_elec(player_type *creature_ptr)
5839 {
5840         return creature_ptr->oppose_elec || music_singing(creature_ptr, MUSIC_RESIST) || (creature_ptr->special_defense & KATA_MUSOU);
5841 }
5842
5843
5844 bool is_oppose_fire(player_type *creature_ptr)
5845 {
5846         return creature_ptr->oppose_fire || music_singing(creature_ptr, MUSIC_RESIST) || (creature_ptr->special_defense & KATA_MUSOU);
5847 }
5848
5849
5850 bool is_oppose_cold(player_type *creature_ptr)
5851 {
5852         return creature_ptr->oppose_cold || music_singing(creature_ptr, MUSIC_RESIST) || (creature_ptr->special_defense & KATA_MUSOU);
5853 }
5854
5855
5856 bool is_oppose_pois(player_type *creature_ptr)
5857 {
5858         return creature_ptr->oppose_pois || music_singing(creature_ptr, MUSIC_RESIST) || (creature_ptr->special_defense & KATA_MUSOU);
5859 }
5860
5861
5862 bool is_tim_esp(player_type *creature_ptr)
5863 {
5864         return creature_ptr->tim_esp || music_singing(creature_ptr, MUSIC_MIND) || (creature_ptr->concent >= CONCENT_TELE_THRESHOLD);
5865 }
5866
5867
5868 bool is_tim_stealth(player_type *creature_ptr)
5869 {
5870         return creature_ptr->tim_stealth || music_singing(creature_ptr, MUSIC_STEALTH);
5871 }
5872
5873
5874 bool is_time_limit_esp(player_type *creature_ptr)
5875 {
5876         return creature_ptr->tim_esp || music_singing(creature_ptr, MUSIC_MIND) || (creature_ptr->concent >= CONCENT_TELE_THRESHOLD);
5877 }
5878
5879
5880 bool is_time_limit_stealth(player_type *creature_ptr)
5881 {
5882         return creature_ptr->tim_stealth || music_singing(creature_ptr, MUSIC_STEALTH);
5883 }
5884
5885
5886 bool can_two_hands_wielding(player_type *creature_ptr)
5887 {
5888         return !creature_ptr->riding || (creature_ptr->pet_extra_flags & PF_TWO_HANDS);
5889 }