OSDN Git Service

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