OSDN Git Service

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