OSDN Git Service

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