OSDN Git Service

アライメントの計算で先にjをデクリメントしないとSEGVるので修正。
[hengband/hengband.git] / src / xtra1.c
1
2 /* File: misc.c */
3
4 /* Purpose: misc code */
5
6 /*
7  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
8  *
9  * This software may be copied and distributed for educational, research, and
10  * not for profit purposes provided that this copyright and statement are
11  * included in all such copies.
12  */
13
14 #include "angband.h"
15
16
17
18
19 /*
20  * Converts stat num into a six-char (right justified) string
21  */
22 void cnv_stat(int val, char *out_val)
23 {
24         /* Above 18 */
25         if (val > 18)
26         {
27                 int bonus = (val - 18);
28
29                 if (bonus >= 220)
30                 {
31                         sprintf(out_val, "18/%3s", "***");
32                 }
33                 else if (bonus >= 100)
34                 {
35                         sprintf(out_val, "18/%03d", bonus);
36                 }
37                 else
38                 {
39                         sprintf(out_val, " 18/%02d", bonus);
40                 }
41         }
42
43         /* From 3 to 18 */
44         else
45         {
46                 sprintf(out_val, "    %2d", val);
47         }
48 }
49
50
51
52 /*
53  * Modify a stat value by a "modifier", return new value
54  *
55  * Stats go up: 3,4,...,17,18,18/10,18/20,...,18/220
56  * Or even: 18/13, 18/23, 18/33, ..., 18/220
57  *
58  * Stats go down: 18/220, 18/210,..., 18/10, 18, 17, ..., 3
59  * Or even: 18/13, 18/03, 18, 17, ..., 3
60  */
61 s16b modify_stat_value(int value, int amount)
62 {
63         int    i;
64
65         /* Reward */
66         if (amount > 0)
67         {
68                 /* Apply each point */
69                 for (i = 0; i < amount; i++)
70                 {
71                         /* One point at a time */
72                         if (value < 18) value++;
73
74                         /* Ten "points" at a time */
75                         else value += 10;
76                 }
77         }
78
79         /* Penalty */
80         else if (amount < 0)
81         {
82                 /* Apply each point */
83                 for (i = 0; i < (0 - amount); i++)
84                 {
85                         /* Ten points at a time */
86                         if (value >= 18+10) value -= 10;
87
88                         /* Hack -- prevent weirdness */
89                         else if (value > 18) value = 18;
90
91                         /* One point at a time */
92                         else if (value > 3) value--;
93                 }
94         }
95
96         /* Return new value */
97         return (value);
98 }
99
100
101
102 /*
103  * Print character info at given row, column in a 13 char field
104  */
105 static void prt_field(cptr info, int row, int col)
106 {
107         /* Dump 13 spaces to clear */
108         c_put_str(TERM_WHITE, "             ", row, col);
109
110         /* Dump the info itself */
111         c_put_str(TERM_L_BLUE, info, row, col);
112 }
113
114
115 /*
116  * Print time
117  */
118 void prt_time(void)
119 {
120         s32b len = 20L * TOWN_DAWN;
121         s32b tick = turn % len + len / 4;
122
123         /* Dump 13 spaces to clear */
124         c_put_str(TERM_WHITE, "             ", ROW_DAY, COL_DAY);
125
126         /* Dump the info itself */
127         c_put_str(TERM_WHITE, format(
128 #ifdef JP
129                 "%2dÆüÌÜ",
130 #else
131                 "Day %-2d",
132 #endif
133                 ((p_ptr->prace == RACE_VAMPIRE) ||
134                  (p_ptr->prace == RACE_SKELETON) ||
135                  (p_ptr->prace == RACE_ZOMBIE) ||
136                  (p_ptr->prace == RACE_SPECTRE))
137                 ? (turn - (15L * TOWN_DAWN)) / len + 1
138                 : (turn + (5L * TOWN_DAWN))/ len + 1),
139                   ROW_DAY, COL_DAY);
140         
141         c_put_str(TERM_WHITE, format("%2d:%02d",
142                                       (24 * tick / len) % 24,
143                                       (1440 * tick / len) % 60),
144                   ROW_DAY, COL_DAY+7);
145 }
146
147
148 cptr map_name(void)
149 {
150         if (p_ptr->inside_quest && (p_ptr->inside_quest < MIN_RANDOM_QUEST)
151             && (quest[p_ptr->inside_quest].flags & QUEST_FLAG_PRESET))
152 #ifdef JP
153                 return "¥¯¥¨¥¹¥È";
154 #else
155                 return "Quest";
156 #endif
157         else if (p_ptr->wild_mode)
158 #ifdef JP
159                 return "ÃϾå";
160 #else
161                 return "Surface";
162 #endif
163         else if (p_ptr->inside_arena)
164 #ifdef JP
165                 return "¥¢¥ê¡¼¥Ê";
166 #else
167                 return "Monster Arena";
168 #endif
169         else if (p_ptr->inside_battle)
170 #ifdef JP
171                 return "Æ®µ»¾ì";
172 #else
173                 return "Arena";
174 #endif
175         else if (!dun_level && p_ptr->town_num)
176                 return town[p_ptr->town_num].name;
177         else
178                 return d_name+d_info[dungeon_type].name;
179 }
180
181 /*
182  * Print dungeon
183  */
184 static void prt_dungeon(void)
185 {
186         cptr dungeon_name;
187         int col;
188
189         /* Dump 13 spaces to clear */
190         c_put_str(TERM_WHITE, "             ", ROW_DUNGEON, COL_DUNGEON);
191
192         dungeon_name = map_name();
193
194         col = COL_DUNGEON + 6 - strlen(dungeon_name)/2;
195         if (col < 0) col = 0;
196
197         /* Dump the info itself */
198         c_put_str(TERM_L_UMBER, format("%s",dungeon_name),
199                   ROW_DUNGEON, col);
200 }
201
202
203
204
205 /*
206  * Print character stat in given row, column
207  */
208 static void prt_stat(int stat)
209 {
210         char tmp[32];
211
212         /* Display "injured" stat */
213         if (p_ptr->stat_cur[stat] < p_ptr->stat_max[stat])
214         {
215                 put_str(stat_names_reduced[stat], ROW_STAT + stat, 0);
216                 cnv_stat(p_ptr->stat_use[stat], tmp);
217                 c_put_str(TERM_YELLOW, tmp, ROW_STAT + stat, COL_STAT + 6);
218         }
219
220         /* Display "healthy" stat */
221         else
222         {
223                 put_str(stat_names[stat], ROW_STAT + stat, 0);
224                 cnv_stat(p_ptr->stat_use[stat], tmp);
225                 c_put_str(TERM_L_GREEN, tmp, ROW_STAT + stat, COL_STAT + 6);
226         }
227
228         /* Indicate natural maximum */
229         if (p_ptr->stat_max[stat] == p_ptr->stat_max_max[stat])
230         {
231 #ifdef JP
232                 /* ÆüËܸì¤Ë¤«¤Ö¤é¤Ê¤¤¤è¤¦¤Ëɽ¼¨°ÌÃÖ¤òÊѹ¹ */
233                 put_str("!", ROW_STAT + stat, 5);
234 #else
235                 put_str("!", ROW_STAT + stat, 3);
236 #endif
237
238         }
239 }
240
241
242 /* Show status bar */
243
244 static void prt_status(void)
245 {
246         /* Tsuyoshi  */
247         if (p_ptr->tsuyoshi)
248         {
249 #ifdef JP
250                 c_put_str(TERM_YELLOW, "¤Ä", ROW_STATBAR, COL_STATBAR);
251 #else
252                 c_put_str(TERM_YELLOW, "Ts", ROW_STATBAR, COL_STATBAR);
253 #endif
254         }
255
256         /* Hallucinating */
257         else if (p_ptr->image)
258         {
259 #ifdef JP
260                 c_put_str(TERM_VIOLET, "¸¸", ROW_STATBAR, COL_STATBAR);
261 #else
262                 c_put_str(TERM_VIOLET, "Hu", ROW_STATBAR, COL_STATBAR);
263 #endif
264         }
265         else
266         {
267                 put_str("  ", ROW_STATBAR, COL_STATBAR);
268         }
269
270         /* Blindness */
271         if (p_ptr->blind)
272         {
273 #ifdef JP
274                 c_put_str(TERM_L_DARK, "ÌÕ", ROW_STATBAR, COL_STATBAR+2);
275 #else
276                 c_put_str(TERM_L_DARK, "Bl", ROW_STATBAR, COL_STATBAR+2);
277 #endif
278         }
279         else
280         {
281                 put_str("  ", ROW_STATBAR, COL_STATBAR+2);
282         }
283
284         /* Paralysis */
285         if (p_ptr->paralyzed)
286         {
287 #ifdef JP
288                 c_put_str(TERM_RED, "áã", ROW_STATBAR, COL_STATBAR+4);
289 #else
290                 c_put_str(TERM_RED, "Pa", ROW_STATBAR, COL_STATBAR+4);
291 #endif
292         }
293         else
294         {
295                 put_str("  ", ROW_STATBAR, COL_STATBAR+4);
296         }
297
298         /* Confusion */
299         if (p_ptr->confused)
300         {
301 #ifdef JP
302                 c_put_str(TERM_VIOLET, "Íð", ROW_STATBAR, COL_STATBAR+6);
303 #else
304                 c_put_str(TERM_VIOLET, "Cf", ROW_STATBAR, COL_STATBAR+6);
305 #endif
306         }
307         else
308         {
309                 put_str("  ", ROW_STATBAR, COL_STATBAR+6);
310         }
311
312         /* Afraid */
313         if (p_ptr->poisoned)
314         {
315 #ifdef JP
316                 c_put_str(TERM_GREEN, "ÆÇ", ROW_STATBAR, COL_STATBAR+8);
317 #else
318                 c_put_str(TERM_GREEN, "Po", ROW_STATBAR, COL_STATBAR+8);
319 #endif
320         }
321         else
322         {
323                 put_str("  ", ROW_STATBAR, COL_STATBAR+8);
324         }
325
326         /* Times see-invisible */
327         if (p_ptr->tim_invis)
328         {
329 #ifdef JP
330                 c_put_str(TERM_L_BLUE, "»ë", ROW_STATBAR, COL_STATBAR+10);
331 #else
332                 c_put_str(TERM_L_BLUE, "Se", ROW_STATBAR, COL_STATBAR+10);
333 #endif
334         }
335         else
336         {
337                 put_str("  ", ROW_STATBAR, COL_STATBAR+10);
338         }
339
340         /* Timed esp */
341         if (p_ptr->tim_esp || music_singing(MUSIC_MIND))
342         {
343 #ifdef JP
344                 c_put_str(TERM_ORANGE, "¥Æ", ROW_STATBAR, COL_STATBAR+12);
345 #else
346                 c_put_str(TERM_ORANGE, "Te", ROW_STATBAR, COL_STATBAR+12);
347 #endif
348         }
349         else
350         {
351                 put_str("  ", ROW_STATBAR, COL_STATBAR+12);
352         }
353
354         /* Timed regenerate */
355         if (p_ptr->tim_regen)
356         {
357 #ifdef JP
358                 c_put_str(TERM_L_BLUE, "²ó", ROW_STATBAR, COL_STATBAR+14);
359 #else
360                 c_put_str(TERM_L_BLUE, "Rg", ROW_STATBAR, COL_STATBAR+14);
361 #endif
362         }
363         else
364         {
365                 put_str("  ", ROW_STATBAR, COL_STATBAR+14);
366         }
367
368         /* Timed infra-vision */
369         if (p_ptr->tim_infra)
370         {
371 #ifdef JP
372                 c_put_str(TERM_L_RED, "ÀÖ", ROW_STATBAR, COL_STATBAR+16);
373 #else
374                 c_put_str(TERM_L_RED, "If", ROW_STATBAR, COL_STATBAR+16);
375 #endif
376         }
377         else
378         {
379                 put_str("  ", ROW_STATBAR, COL_STATBAR+16);
380         }
381
382         /* Protection from evil */
383         if (p_ptr->protevil)
384         {
385 #ifdef JP
386                 c_put_str(TERM_SLATE, "¼Ù", ROW_STATBAR, COL_STATBAR+18);
387 #else
388                 c_put_str(TERM_SLATE, "Ev", ROW_STATBAR, COL_STATBAR+18);
389 #endif
390         }
391         else
392         {
393                 put_str("  ", ROW_STATBAR, COL_STATBAR+18);
394         }
395
396         /* Invulnerability */
397         if (p_ptr->invuln || music_singing(MUSIC_INVULN))
398         {
399 #ifdef JP
400                 c_put_str(TERM_YELLOW, "̵", ROW_STATBAR, COL_STATBAR+20);
401 #else
402                 c_put_str(TERM_YELLOW, "Iv", ROW_STATBAR, COL_STATBAR+20);
403 #endif
404         }
405         else
406         {
407                 put_str("  ", ROW_STATBAR, COL_STATBAR+20);
408         }
409
410         /* Wraith form */
411         if (p_ptr->wraith_form)
412         {
413 #ifdef JP
414                 c_put_str(TERM_L_DARK, "ͩ", ROW_STATBAR, COL_STATBAR+22);
415 #else
416                 c_put_str(TERM_L_DARK, "Gh", ROW_STATBAR, COL_STATBAR+22);
417 #endif
418         }
419         /* Kabenuke */
420         else if (p_ptr->kabenuke)
421         {
422 #ifdef JP
423                 c_put_str(TERM_SLATE, "ÊÉ", ROW_STATBAR, COL_STATBAR+22);
424 #else
425                 c_put_str(TERM_SLATE, "Wp", ROW_STATBAR, COL_STATBAR+22);
426 #endif
427         }
428         else if (p_ptr->tim_reflect)
429         {
430 #ifdef JP
431                 c_put_str(TERM_SLATE, "ȿ", ROW_STATBAR, COL_STATBAR+22);
432 #else
433                 c_put_str(TERM_SLATE, "Rf", ROW_STATBAR, COL_STATBAR+22);
434 #endif
435         }
436         else
437         {
438                 put_str("  ", ROW_STATBAR, COL_STATBAR+22);
439         }
440
441         /* Heroism */
442         if (p_ptr->hero || music_singing(MUSIC_HERO) || music_singing(MUSIC_SHERO))
443         {
444 #ifdef JP
445                 c_put_str(TERM_WHITE, "ͦ", ROW_STATBAR, COL_STATBAR+24);
446 #else
447                 c_put_str(TERM_WHITE, "He", ROW_STATBAR, COL_STATBAR+24);
448 #endif
449         }
450         else
451         {
452                 put_str("  ", ROW_STATBAR, COL_STATBAR+24);
453         }
454
455         /* Super Heroism / berserk */
456         if (p_ptr->shero)
457         {
458 #ifdef JP
459                 c_put_str(TERM_RED, "¶¸", ROW_STATBAR, COL_STATBAR+26);
460 #else
461                 c_put_str(TERM_RED, "Br", ROW_STATBAR, COL_STATBAR+26);
462 #endif
463         }
464         else
465         {
466                 put_str("  ", ROW_STATBAR, COL_STATBAR+26);
467         }
468
469         /* Blessed */
470         if (p_ptr->blessed || music_singing(MUSIC_BLESS))
471         {
472 #ifdef JP
473                 c_put_str(TERM_WHITE, "½Ë", ROW_STATBAR, COL_STATBAR+28);
474 #else
475                 c_put_str(TERM_WHITE, "Bs", ROW_STATBAR, COL_STATBAR+28);
476 #endif
477         }
478         else
479         {
480                 put_str("  ", ROW_STATBAR, COL_STATBAR+28);
481         }
482
483         /* Shield */
484         if (p_ptr->magicdef)
485         {
486 #ifdef JP
487                 c_put_str(TERM_YELLOW, "Ëâ", ROW_STATBAR, COL_STATBAR+30);
488 #else
489                 c_put_str(TERM_YELLOW, "Md", ROW_STATBAR, COL_STATBAR+30);
490 #endif
491         }
492         else if (p_ptr->tsubureru)
493         {
494 #ifdef JP
495                 c_put_str(TERM_L_UMBER, "¿­", ROW_STATBAR, COL_STATBAR+30);
496 #else
497                 c_put_str(TERM_L_UMBER, "Eh", ROW_STATBAR, COL_STATBAR+30);
498 #endif
499         }
500         else if (p_ptr->shield)
501         {
502 #ifdef JP
503                 c_put_str(TERM_WHITE, "ÀÐ", ROW_STATBAR, COL_STATBAR+30);
504 #else
505                 c_put_str(TERM_WHITE, "Ss", ROW_STATBAR, COL_STATBAR+30);
506 #endif
507         }
508         else if (p_ptr->special_defense & NINJA_KAWARIMI)
509         {
510 #ifdef JP
511                 c_put_str(TERM_VIOLET, "ÊÑ", ROW_STATBAR, COL_STATBAR+30);
512 #else
513                 c_put_str(TERM_VIOLET, "Qa", ROW_STATBAR, COL_STATBAR+30);
514 #endif
515         }
516         else
517         {
518                 put_str("  ", ROW_STATBAR, COL_STATBAR+30);
519         }
520
521         /* Oppose Acid */
522         if (p_ptr->special_defense & DEFENSE_ACID)
523         {
524 #ifdef JP
525                 c_put_str(TERM_L_GREEN, "»À", ROW_STATBAR, COL_STATBAR+32);
526 #else
527                 c_put_str(TERM_L_GREEN, "Ac", ROW_STATBAR, COL_STATBAR+32);
528 #endif
529         }
530         else if (p_ptr->oppose_acid || music_singing(MUSIC_RESIST) || (p_ptr->special_defense & KATA_MUSOU))
531         {
532 #ifdef JP
533                 c_put_str(TERM_GREEN, "»À", ROW_STATBAR, COL_STATBAR+32);
534 #else
535                 c_put_str(TERM_GREEN, "Ac", ROW_STATBAR, COL_STATBAR+32);
536 #endif
537         }
538         else
539         {
540                 put_str("  ", ROW_STATBAR, COL_STATBAR+32);
541         }
542
543         /* Oppose Lightning */
544         if (p_ptr->special_defense & DEFENSE_ELEC)
545         {
546 #ifdef JP
547                 c_put_str(TERM_L_BLUE, "ÅÅ", ROW_STATBAR, COL_STATBAR+34);
548 #else
549                 c_put_str(TERM_L_BLUE, "El", ROW_STATBAR, COL_STATBAR+34);
550 #endif
551         }
552         else if (p_ptr->oppose_elec || music_singing(MUSIC_RESIST) || (p_ptr->special_defense & KATA_MUSOU))
553         {
554 #ifdef JP
555                 c_put_str(TERM_BLUE, "ÅÅ", ROW_STATBAR, COL_STATBAR+34);
556 #else
557                 c_put_str(TERM_BLUE, "El", ROW_STATBAR, COL_STATBAR+34);
558 #endif
559         }
560         else
561         {
562                 put_str("  ", ROW_STATBAR, COL_STATBAR+34);
563         }
564
565         /* Oppose Fire */
566         if (p_ptr->special_defense & DEFENSE_FIRE)
567         {
568 #ifdef JP
569                 c_put_str(TERM_L_RED, "²Ð", ROW_STATBAR, COL_STATBAR+36);
570 #else
571                 c_put_str(TERM_L_RED, "Fi", ROW_STATBAR, COL_STATBAR+36);
572 #endif
573         }
574         else if (p_ptr->oppose_fire || music_singing(MUSIC_RESIST) || (p_ptr->special_defense & KATA_MUSOU))
575         {
576 #ifdef JP
577                 c_put_str(TERM_RED, "²Ð", ROW_STATBAR, COL_STATBAR+36);
578 #else
579                 c_put_str(TERM_RED, "Fi", ROW_STATBAR, COL_STATBAR+36);
580 #endif
581         }
582         else
583         {
584                 put_str("  ", ROW_STATBAR, COL_STATBAR+36);
585         }
586
587         /* Oppose Cold */
588         if (p_ptr->special_defense & DEFENSE_COLD)
589         {
590 #ifdef JP
591                 c_put_str(TERM_WHITE, "Îä", ROW_STATBAR, COL_STATBAR+38);
592 #else
593                 c_put_str(TERM_WHITE, "Co", ROW_STATBAR, COL_STATBAR+38);
594 #endif
595         }
596         else if (p_ptr->oppose_cold || music_singing(MUSIC_RESIST) || (p_ptr->special_defense & KATA_MUSOU))
597         {
598 #ifdef JP
599                 c_put_str(TERM_SLATE, "Îä", ROW_STATBAR, COL_STATBAR+38);
600 #else
601                 c_put_str(TERM_SLATE, "Co", ROW_STATBAR, COL_STATBAR+38);
602 #endif
603         }
604         else
605         {
606                 put_str("  ", ROW_STATBAR, COL_STATBAR+38);
607         }
608
609         /* Oppose Poison */
610         if (p_ptr->oppose_pois || music_singing(MUSIC_RESIST) || (p_ptr->special_defense & KATA_MUSOU))
611         {
612 #ifdef JP
613                 c_put_str(TERM_GREEN, "ÆÇ", ROW_STATBAR, COL_STATBAR+40);
614 #else
615                 c_put_str(TERM_GREEN, "Po", ROW_STATBAR, COL_STATBAR+40);
616 #endif
617         }
618         else
619         {
620                 put_str("  ", ROW_STATBAR, COL_STATBAR+40);
621         }
622
623         /* Word of Recall */
624         if (p_ptr->word_recall)
625         {
626 #ifdef JP
627                 c_put_str(TERM_WHITE, "µ¢", ROW_STATBAR, COL_STATBAR+42);
628 #else
629                 c_put_str(TERM_WHITE, "Wr", ROW_STATBAR, COL_STATBAR+42);
630 #endif
631         }
632         else
633         {
634                 put_str("  ", ROW_STATBAR, COL_STATBAR+42);
635         }
636
637         /* Afraid */
638         if (p_ptr->afraid)
639         {
640 #ifdef JP
641                 c_put_str(TERM_BLUE, "¶²", ROW_STATBAR, COL_STATBAR+44);
642 #else
643                 c_put_str(TERM_BLUE, "Fe", ROW_STATBAR, COL_STATBAR+44);
644 #endif
645         }
646         else
647         {
648                 put_str("  ", ROW_STATBAR, COL_STATBAR+44);
649         }
650
651         /* Blindness */
652         if (p_ptr->tim_res_time)
653         {
654 #ifdef JP
655                 c_put_str(TERM_L_BLUE, "»þ", ROW_STATBAR, COL_STATBAR+46);
656 #else
657                 c_put_str(TERM_L_BLUE, "Ti", ROW_STATBAR, COL_STATBAR+46);
658 #endif
659         }
660         else if (p_ptr->multishadow)
661         {
662 #ifdef JP
663                 c_put_str(TERM_L_BLUE, "ʬ", ROW_STATBAR, COL_STATBAR+46);
664 #else
665                 c_put_str(TERM_L_BLUE, "Ms", ROW_STATBAR, COL_STATBAR+46);
666 #endif
667         }
668         else
669         {
670                 put_str("  ", ROW_STATBAR, COL_STATBAR+46);
671         }
672
673         /* Confusing Hands */
674         if (p_ptr->special_attack & ATTACK_CONFUSE)
675         {
676 #ifdef JP
677                 c_put_str(TERM_RED, "Íð", ROW_STATBAR, COL_STATBAR+48);
678 #else
679                 c_put_str(TERM_RED, "Cf", ROW_STATBAR, COL_STATBAR+48);
680 #endif
681         }
682         else
683         {
684                 put_str("  ", ROW_STATBAR, COL_STATBAR+48);
685         }
686
687         if (p_ptr->resist_magic)
688         {
689 #ifdef JP
690                 c_put_str(TERM_SLATE, "ËÉ", ROW_STATBAR, COL_STATBAR+50);
691 #else
692                 c_put_str(TERM_SLATE, "Rm", ROW_STATBAR, COL_STATBAR+50);
693 #endif
694         }
695         else
696         {
697                 put_str("  ", ROW_STATBAR, COL_STATBAR+50);
698         }
699
700         /* Ultimate-resistance */
701         if (p_ptr->ult_res)
702         {
703 #ifdef JP
704                 c_put_str(TERM_YELLOW, "µæ", ROW_STATBAR, COL_STATBAR+52);
705 #else
706                 c_put_str(TERM_YELLOW, "Ul", ROW_STATBAR, COL_STATBAR+52);
707 #endif
708         }
709         /* tim levitation */
710         else if (p_ptr->tim_ffall)
711         {
712 #ifdef JP
713                 c_put_str(TERM_L_BLUE, "Éâ", ROW_STATBAR, COL_STATBAR+52);
714 #else
715                 c_put_str(TERM_L_BLUE, "Lv", ROW_STATBAR, COL_STATBAR+52);
716 #endif
717         }
718         else if (p_ptr->tim_res_nether)
719         {
720 #ifdef JP
721                 c_put_str(TERM_L_DARK, "¹ö", ROW_STATBAR, COL_STATBAR+52);
722 #else
723                 c_put_str(TERM_L_DARK, "Nt", ROW_STATBAR, COL_STATBAR+52);
724 #endif
725         }
726         else if (p_ptr->dustrobe)
727         {
728 #ifdef JP
729                 c_put_str(TERM_L_DARK, "¶À", ROW_STATBAR, COL_STATBAR+52);
730 #else
731                 c_put_str(TERM_L_DARK, "Am", ROW_STATBAR, COL_STATBAR+52);
732 #endif
733         }
734         else
735         {
736                 put_str("  ", ROW_STATBAR, COL_STATBAR+52);
737         }
738
739         /* Mahouken */
740         if (p_ptr->special_attack & ATTACK_FIRE)
741         {
742 #ifdef JP
743                 c_put_str(TERM_L_RED, "²Ð", ROW_STATBAR, COL_STATBAR+54);
744 #else
745                 c_put_str(TERM_L_RED, "Fi", ROW_STATBAR, COL_STATBAR+54);
746 #endif
747         }
748         else if (p_ptr->special_attack & ATTACK_COLD)
749         {
750 #ifdef JP
751                 c_put_str(TERM_WHITE, "Îä", ROW_STATBAR, COL_STATBAR+54);
752 #else
753                 c_put_str(TERM_WHITE, "Co", ROW_STATBAR, COL_STATBAR+54);
754 #endif
755         }
756         else if (p_ptr->special_attack & ATTACK_ELEC)
757         {
758 #ifdef JP
759                 c_put_str(TERM_L_BLUE, "ÅÅ", ROW_STATBAR, COL_STATBAR+54);
760 #else
761                 c_put_str(TERM_L_BLUE, "El", ROW_STATBAR, COL_STATBAR+54);
762 #endif
763         }
764         else if (p_ptr->special_attack & ATTACK_ACID)
765         {
766 #ifdef JP
767                 c_put_str(TERM_SLATE, "»À", ROW_STATBAR, COL_STATBAR+54);
768 #else
769                 c_put_str(TERM_SLATE, "Ac", ROW_STATBAR, COL_STATBAR+54);
770 #endif
771         }
772         else if (p_ptr->special_attack & ATTACK_POIS)
773         {
774 #ifdef JP
775                 c_put_str(TERM_L_GREEN, "ÆÇ", ROW_STATBAR, COL_STATBAR+54);
776 #else
777                 c_put_str(TERM_L_GREEN, "Po", ROW_STATBAR, COL_STATBAR+54);
778 #endif
779         }
780         else if (p_ptr->special_defense & NINJA_S_STEALTH)
781         {
782 #ifdef JP
783                 c_put_str(TERM_YELLOW, "Ķ", ROW_STATBAR, COL_STATBAR+54);
784 #else
785                 c_put_str(TERM_YELLOW, "St", ROW_STATBAR, COL_STATBAR+54);
786 #endif
787         }
788         else
789         {
790                 put_str("  ", ROW_STATBAR, COL_STATBAR+54);
791         }
792
793         /* tim stealth */
794         if (p_ptr->tim_sh_fire)
795         {
796 #ifdef JP
797                 c_put_str(TERM_L_RED, "¥ª", ROW_STATBAR, COL_STATBAR+56);
798 #else
799                 c_put_str(TERM_L_RED, "Sf", ROW_STATBAR, COL_STATBAR+56);
800 #endif
801         }
802         else if (p_ptr->tim_stealth || music_singing(MUSIC_STEALTH))
803         {
804 #ifdef JP
805                 c_put_str(TERM_UMBER, "±£", ROW_STATBAR, COL_STATBAR+56);
806 #else
807                 c_put_str(TERM_UMBER, "Sl", ROW_STATBAR, COL_STATBAR+56);
808 #endif
809         }
810         else if (p_ptr->special_defense & NINJA_S_STEALTH)
811         {
812 #ifdef JP
813                 c_put_str(TERM_YELLOW, "±£", ROW_STATBAR, COL_STATBAR+56);
814 #else
815                 c_put_str(TERM_YELLOW, "lt", ROW_STATBAR, COL_STATBAR+56);
816 #endif
817         }
818         else if (p_ptr->tim_sh_touki)
819         {
820 #ifdef JP
821                 c_put_str(TERM_WHITE, "Ʈ", ROW_STATBAR, COL_STATBAR+56);
822 #else
823                 c_put_str(TERM_WHITE, "Ae", ROW_STATBAR, COL_STATBAR+56);
824 #endif
825         }
826         else
827         {
828                 put_str("  ", ROW_STATBAR, COL_STATBAR+56);
829         }
830 }
831
832
833
834 /*
835  * Prints "title", including "wizard" or "winner" as needed.
836  */
837 static void prt_title(void)
838 {
839         cptr p = "";
840         char str[14];
841
842         /* Wizard */
843         if (wizard)
844         {
845 #ifdef JP
846                 /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½ ¾Î¹æ */
847                 p = "[¥¦¥£¥¶¡¼¥É]";
848 #else
849                 p = "[=-WIZARD-=]";
850 #endif
851
852         }
853
854         /* Winner */
855         else if (total_winner || (p_ptr->lev > PY_MAX_LEVEL))
856         {
857                 if ((p_ptr->arena_number > MAX_ARENA_MONS+2) && (p_ptr->arena_number < 99))
858                 {
859 #ifdef JP
860                         /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½ ¾Î¹æ */
861                         p = "*¿¿¡¦¾¡Íø¼Ô*";
862
863 #else
864                         p = "*TRUEWINNER*";
865 #endif
866                 }
867                 else
868                 {
869 #ifdef JP
870                         /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½ ¾Î¹æ */
871                         p = "***¾¡Íø¼Ô***";
872
873 #else
874                         p = "***WINNER***";
875 #endif
876                 }
877         }
878
879         /* Normal */
880         else
881         {
882 #ifdef JP
883                 mb_strlcpy(str, player_title[p_ptr->pclass][(p_ptr->lev - 1) / 5], 14);
884 #else
885                 strncpy(str, player_title[p_ptr->pclass][(p_ptr->lev - 1) / 5], 13);
886                 str[13] = '\0';
887 #endif
888                 p = str;
889         }
890
891         prt_field(p, ROW_TITLE, COL_TITLE);
892 }
893
894
895 /*
896  * Prints level
897  */
898 static void prt_level(void)
899 {
900         char tmp[32];
901
902 #ifdef JP
903         sprintf(tmp, "%5d", p_ptr->lev);
904 #else
905         sprintf(tmp, "%6d", p_ptr->lev);
906 #endif
907
908
909         if (p_ptr->lev >= p_ptr->max_plv)
910         {
911 #ifdef JP
912                 put_str("¥ì¥Ù¥ë ", ROW_LEVEL, 0);
913                 c_put_str(TERM_L_GREEN, tmp, ROW_LEVEL, COL_LEVEL + 7);
914 #else
915                 put_str("LEVEL ", ROW_LEVEL, 0);
916                 c_put_str(TERM_L_GREEN, tmp, ROW_LEVEL, COL_LEVEL + 6);
917 #endif
918
919         }
920         else
921         {
922 #ifdef JP
923                 put_str("x¥ì¥Ù¥ë", ROW_LEVEL, 0);
924                 c_put_str(TERM_YELLOW, tmp, ROW_LEVEL, COL_LEVEL + 7);
925 #else
926                 put_str("Level ", ROW_LEVEL, 0);
927                 c_put_str(TERM_YELLOW, tmp, ROW_LEVEL, COL_LEVEL + 6);
928 #endif
929
930         }
931 }
932
933
934 /*
935  * Display the experience
936  */
937 static void prt_exp(void)
938 {
939         char out_val[32];
940
941         if ((p_ptr->prace == RACE_ANDROID) && !cheat_xtra)
942                 (void)strcpy(out_val, "*******");
943         else
944 #ifdef JP
945 (void)sprintf(out_val, "%7ld", (long)p_ptr->exp);
946 #else
947         (void)sprintf(out_val, "%8ld", (long)p_ptr->exp);
948 #endif
949
950
951         if (p_ptr->exp >= p_ptr->max_exp)
952         {
953 #ifdef JP
954                 put_str("·Ð¸³ ", ROW_EXP, 0);
955                 c_put_str(TERM_L_GREEN, out_val, ROW_EXP, COL_EXP + 5);
956 #else
957                 put_str("EXP ", ROW_EXP, 0);
958                 c_put_str(TERM_L_GREEN, out_val, ROW_EXP, COL_EXP + 4);
959 #endif
960
961         }
962         else
963         {
964 #ifdef JP
965                 put_str("x·Ð¸³", ROW_EXP, 0);
966                 c_put_str(TERM_YELLOW, out_val, ROW_EXP, COL_EXP + 5);
967 #else
968                 put_str("Exp ", ROW_EXP, 0);
969                 c_put_str(TERM_YELLOW, out_val, ROW_EXP, COL_EXP + 4);
970 #endif
971
972         }
973 }
974
975
976 /*
977  * Prints current gold
978  */
979 static void prt_gold(void)
980 {
981         char tmp[32];
982
983 #ifdef JP
984         put_str("¡ð ", ROW_GOLD, COL_GOLD);
985 #else
986         put_str("AU ", ROW_GOLD, COL_GOLD);
987 #endif
988
989         sprintf(tmp, "%9ld", (long)p_ptr->au);
990         c_put_str(TERM_L_GREEN, tmp, ROW_GOLD, COL_GOLD + 3);
991 }
992
993
994
995 /*
996  * Prints current AC
997  */
998 static void prt_ac(void)
999 {
1000         char tmp[32];
1001
1002 #ifdef JP
1003 /* AC ¤Îɽ¼¨Êý¼°¤òÊѹ¹¤·¤Æ¤¤¤ë */
1004         put_str(" £Á£Ã(     )", ROW_AC, COL_AC);
1005         sprintf(tmp, "%5d", p_ptr->dis_ac + p_ptr->dis_to_a);
1006         c_put_str(TERM_L_GREEN, tmp, ROW_AC, COL_AC + 6);
1007 #else
1008         put_str("Cur AC ", ROW_AC, COL_AC);
1009         sprintf(tmp, "%5d", p_ptr->dis_ac + p_ptr->dis_to_a);
1010         c_put_str(TERM_L_GREEN, tmp, ROW_AC, COL_AC + 7);
1011 #endif
1012
1013 }
1014
1015
1016 /*
1017  * Prints Cur/Max hit points
1018  */
1019 static void prt_hp(void)
1020 {
1021 /* ¥Ò¥Ã¥È¥Ý¥¤¥ó¥È¤Îɽ¼¨ÊýË¡¤òÊѹ¹ */
1022         char tmp[32];
1023   
1024         byte color;
1025   
1026         /* ¥¿¥¤¥È¥ë */
1027 /*      put_str(" £È£Ð¡¦£Í£Ð", ROW_HPMP, COL_HPMP); */
1028
1029         put_str("HP", ROW_CURHP, COL_CURHP);
1030
1031         /* ¸½ºß¤Î¥Ò¥Ã¥È¥Ý¥¤¥ó¥È */
1032         sprintf(tmp, "%4d", p_ptr->chp);
1033
1034         if (p_ptr->chp >= p_ptr->mhp)
1035         {
1036                 color = TERM_L_GREEN;
1037         }
1038         else if (p_ptr->chp > (p_ptr->mhp * hitpoint_warn) / 10)
1039         {
1040                 color = TERM_YELLOW;
1041         }
1042         else
1043         {
1044                 color = TERM_RED;
1045         }
1046
1047         c_put_str(color, tmp, ROW_CURHP, COL_CURHP+3);
1048
1049         /* ¶èÀÚ¤ê */
1050         put_str( "/", ROW_CURHP, COL_CURHP + 7 );
1051
1052         /* ºÇÂç¥Ò¥Ã¥È¥Ý¥¤¥ó¥È */
1053         sprintf(tmp, "%4d", p_ptr->mhp);
1054         color = TERM_L_GREEN;
1055
1056         c_put_str(color, tmp, ROW_CURHP, COL_CURHP + 8 );
1057 }
1058
1059
1060 /*
1061  * Prints players max/cur spell points
1062  */
1063 static void prt_sp(void)
1064 {
1065 /* ¥Þ¥¸¥Ã¥¯¥Ý¥¤¥ó¥È¤Îɽ¼¨ÊýË¡¤òÊѹ¹¤·¤Æ¤¤¤ë */
1066         char tmp[32];
1067         byte color;
1068
1069
1070         /* Do not show mana unless it matters */
1071         if (!mp_ptr->spell_book) return;
1072
1073         /* ¥¿¥¤¥È¥ë */
1074 /*      put_str(" £Í£Ð / ºÇÂç", ROW_MAXSP, COL_MAXSP); */
1075
1076 #ifdef JP
1077         put_str("MP", ROW_CURSP, COL_CURSP);
1078 #else
1079         put_str("SP", ROW_CURSP, COL_CURSP);
1080 #endif
1081
1082         /* ¸½ºß¤Î¥Þ¥¸¥Ã¥¯¥Ý¥¤¥ó¥È */
1083         sprintf(tmp, "%4d", p_ptr->csp);
1084
1085         if (p_ptr->csp >= p_ptr->msp)
1086         {
1087                 color = TERM_L_GREEN;
1088         }
1089         else if (p_ptr->csp > (p_ptr->msp * hitpoint_warn) / 10)
1090         {
1091                 color = TERM_YELLOW;
1092         }
1093         else
1094         {
1095                 color = TERM_RED;
1096         }
1097
1098         c_put_str(color, tmp, ROW_CURSP, COL_CURSP+3);
1099
1100         /* ¶èÀÚ¤ê */
1101         put_str( "/", ROW_CURSP, COL_CURSP + 7 );
1102
1103         /* ºÇÂç¥Þ¥¸¥Ã¥¯¥Ý¥¤¥ó¥È */
1104         sprintf(tmp, "%4d", p_ptr->msp);
1105         color = TERM_L_GREEN;
1106
1107         c_put_str(color, tmp, ROW_CURSP, COL_CURSP + 8);
1108 }
1109
1110
1111 /*
1112  * Prints depth in stat area
1113  */
1114 static void prt_depth(void)
1115 {
1116         char depths[32];
1117
1118         if (!dun_level)
1119         {
1120 #ifdef JP
1121                 strcpy(depths, "ÃϾå");
1122 #else
1123                 strcpy(depths, "Surf.");
1124 #endif
1125         }
1126         else if (p_ptr->inside_quest && !dungeon_type)
1127         {
1128 #ifdef JP
1129 strcpy(depths, "ÃϾå");
1130 #else
1131                 strcpy(depths, "Quest");
1132 #endif
1133
1134         }
1135         else if (depth_in_feet)
1136         {
1137 #ifdef JP
1138 (void)sprintf(depths, "%d ft", dun_level * 50);
1139 #else
1140                 (void)sprintf(depths, "%d ft", dun_level * 50);
1141 #endif
1142
1143         }
1144         else
1145         {
1146 #ifdef JP
1147 sprintf(depths, "%d ³¬", dun_level);
1148 #else
1149                 (void)sprintf(depths, "Lev %d", dun_level);
1150 #endif
1151
1152         }
1153
1154         /* Right-Adjust the "depth", and clear old values */
1155         prt(format("%7s", depths), ROW_DEPTH, COL_DEPTH);
1156 }
1157
1158
1159 /*
1160  * Prints status of hunger
1161  */
1162 static void prt_hunger(void)
1163 {
1164         /* Fainting / Starving */
1165         if (p_ptr->food < PY_FOOD_FAINT)
1166         {
1167 #ifdef JP
1168                 c_put_str(TERM_RED, "¿ê¼å  ", ROW_HUNGRY, COL_HUNGRY);
1169 #else
1170                 c_put_str(TERM_RED, "Weak  ", ROW_HUNGRY, COL_HUNGRY);
1171 #endif
1172
1173         }
1174
1175         /* Weak */
1176         else if (p_ptr->food < PY_FOOD_WEAK)
1177         {
1178 #ifdef JP
1179                 c_put_str(TERM_ORANGE, "¿ê¼å  ", ROW_HUNGRY, COL_HUNGRY);
1180 #else
1181                 c_put_str(TERM_ORANGE, "Weak  ", ROW_HUNGRY, COL_HUNGRY);
1182 #endif
1183
1184         }
1185
1186         /* Hungry */
1187         else if (p_ptr->food < PY_FOOD_ALERT)
1188         {
1189 #ifdef JP
1190                 c_put_str(TERM_YELLOW, "¶õÊ¢  ", ROW_HUNGRY, COL_HUNGRY);
1191 #else
1192                 c_put_str(TERM_YELLOW, "Hungry", ROW_HUNGRY, COL_HUNGRY);
1193 #endif
1194
1195         }
1196
1197         /* Normal */
1198         else if (p_ptr->food < PY_FOOD_FULL)
1199         {
1200                 c_put_str(TERM_L_GREEN, "      ", ROW_HUNGRY, COL_HUNGRY);
1201         }
1202
1203         /* Full */
1204         else if (p_ptr->food < PY_FOOD_MAX)
1205         {
1206 #ifdef JP
1207                 c_put_str(TERM_L_GREEN, "ËþÊ¢  ", ROW_HUNGRY, COL_HUNGRY);
1208 #else
1209                 c_put_str(TERM_L_GREEN, "Full  ", ROW_HUNGRY, COL_HUNGRY);
1210 #endif
1211
1212         }
1213
1214         /* Gorged */
1215         else
1216         {
1217 #ifdef JP
1218                 c_put_str(TERM_GREEN, "¿©²á¤®", ROW_HUNGRY, COL_HUNGRY);
1219 #else
1220                 c_put_str(TERM_GREEN, "Gorged", ROW_HUNGRY, COL_HUNGRY);
1221 #endif
1222
1223         }
1224 }
1225
1226
1227 /*
1228  * Prints Searching, Resting, Paralysis, or 'count' status
1229  * Display is always exactly 10 characters wide (see below)
1230  *
1231  * This function was a major bottleneck when resting, so a lot of
1232  * the text formatting code was optimized in place below.
1233  */
1234 static void prt_state(void)
1235 {
1236         byte attr = TERM_WHITE;
1237
1238         char text[5];
1239
1240         /* Repeating */
1241         if (command_rep)
1242         {
1243                 if (command_rep > 999)
1244                 {
1245 #ifdef JP
1246 sprintf(text, "%2d00", command_rep / 100);
1247 #else
1248                         (void)sprintf(text, "%2d00", command_rep / 100);
1249 #endif
1250
1251                 }
1252                 else
1253                 {
1254 #ifdef JP
1255 sprintf(text, "  %2d", command_rep);
1256 #else
1257                         (void)sprintf(text, "  %2d", command_rep);
1258 #endif
1259
1260                 }
1261         }
1262
1263         /* Action */
1264         else
1265         {
1266                 switch(p_ptr->action)
1267                 {
1268                         case ACTION_SEARCH:
1269                         {
1270 #ifdef JP
1271                                 strcpy(text, "õº÷");
1272 #else
1273                                 strcpy(text, "Sear");
1274 #endif
1275                                 break;
1276                         }
1277                         case ACTION_REST:
1278                         {
1279                                 int i;
1280
1281                                 /* Start with "Rest" */
1282 #ifdef JP
1283                                 strcpy(text, "    ");
1284 #else
1285                                 strcpy(text, "    ");
1286 #endif
1287
1288
1289                                 /* Extensive (timed) rest */
1290                                 if (resting >= 1000)
1291                                 {
1292                                         i = resting / 100;
1293                                         text[3] = '0';
1294                                         text[2] = '0';
1295                                         text[1] = '0' + (i % 10);
1296                                         text[0] = '0' + (i / 10);
1297                                 }
1298
1299                                 /* Long (timed) rest */
1300                                 else if (resting >= 100)
1301                                 {
1302                                         i = resting;
1303                                         text[3] = '0' + (i % 10);
1304                                         i = i / 10;
1305                                         text[2] = '0' + (i % 10);
1306                                         text[1] = '0' + (i / 10);
1307                                 }
1308
1309                                 /* Medium (timed) rest */
1310                                 else if (resting >= 10)
1311                                 {
1312                                         i = resting;
1313                                         text[3] = '0' + (i % 10);
1314                                         text[2] = '0' + (i / 10);
1315                                 }
1316
1317                                 /* Short (timed) rest */
1318                                 else if (resting > 0)
1319                                 {
1320                                         i = resting;
1321                                         text[3] = '0' + (i);
1322                                 }
1323
1324                                 /* Rest until healed */
1325                                 else if (resting == -1)
1326                                 {
1327                                         text[0] = text[1] = text[2] = text[3] = '*';
1328                                 }
1329
1330                                 /* Rest until done */
1331                                 else if (resting == -2)
1332                                 {
1333                                         text[0] = text[1] = text[2] = text[3] = '&';
1334                                 }
1335                                 break;
1336                         }
1337                         case ACTION_LEARN:
1338                         {
1339 #ifdef JP
1340                                 strcpy(text, "³Ø½¬");
1341 #else
1342                                 strcpy(text, "lear");
1343 #endif
1344                                 if (new_mane) attr = TERM_L_RED;
1345                                 break;
1346                         }
1347                         case ACTION_FISH:
1348                         {
1349 #ifdef JP
1350                                 strcpy(text, "Äà¤ê");
1351 #else
1352                                 strcpy(text, "fish");
1353 #endif
1354                                 break;
1355                         }
1356                         case ACTION_KAMAE:
1357                         {
1358                                 int i;
1359                                 for (i = 0; i < MAX_KAMAE; i++)
1360                                         if (p_ptr->special_defense & (KAMAE_GENBU << i)) break;
1361                                 switch (i)
1362                                 {
1363                                         case 0: attr = TERM_GREEN;break;
1364                                         case 1: attr = TERM_WHITE;break;
1365                                         case 2: attr = TERM_L_BLUE;break;
1366                                         case 3: attr = TERM_L_RED;break;
1367                                 }
1368                                 strcpy(text, kamae_shurui[i].desc);
1369                                 break;
1370                         }
1371                         case ACTION_KATA:
1372                         {
1373                                 int i;
1374                                 for (i = 0; i < MAX_KATA; i++)
1375                                         if (p_ptr->special_defense & (KATA_IAI << i)) break;
1376                                 strcpy(text, kata_shurui[i].desc);
1377                                 break;
1378                         }
1379                         case ACTION_SING:
1380                         {
1381 #ifdef JP
1382                                 strcpy(text, "²Î  ");
1383 #else
1384                                 strcpy(text, "Sing");
1385 #endif
1386                                 break;
1387                         }
1388                         case ACTION_HAYAGAKE:
1389                         {
1390 #ifdef JP
1391                                 strcpy(text, "®¶î");
1392 #else
1393                                 strcpy(text, "Fast");
1394 #endif
1395                                 break;
1396                         }
1397                         default:
1398                         {
1399                                 strcpy(text, "    ");
1400                                 break;
1401                         }
1402                 }
1403         }
1404
1405         /* Display the info (or blanks) */
1406         c_put_str(attr, format("%5.5s",text), ROW_STATE, COL_STATE);
1407 }
1408
1409
1410 /*
1411  * Prints the speed of a character.                     -CJS-
1412  */
1413 static void prt_speed(void)
1414 {
1415         int i = p_ptr->pspeed;
1416         bool is_fast = (p_ptr->fast || music_singing(MUSIC_SPEED) || music_singing(MUSIC_SHERO));
1417
1418         byte attr = TERM_WHITE;
1419         char buf[32] = "";
1420
1421         /* Hack -- Visually "undo" the Search Mode Slowdown */
1422         if (p_ptr->action == ACTION_SEARCH) i += 10;
1423
1424         /* Fast */
1425         if (i > 110)
1426         {
1427                 if (p_ptr->riding)
1428                 {
1429                         if (m_list[p_ptr->riding].fast && !m_list[p_ptr->riding].slow) attr = TERM_L_BLUE;
1430                         else if (m_list[p_ptr->riding].slow && !m_list[p_ptr->riding].fast) attr = TERM_VIOLET;
1431                         else attr = TERM_GREEN;
1432                 }
1433                 else if ((is_fast && !p_ptr->slow) || p_ptr->lightspeed) attr = TERM_YELLOW;
1434                 else if (p_ptr->slow && !is_fast) attr = TERM_VIOLET;
1435                 else attr = TERM_L_GREEN;
1436 #ifdef JP
1437                 sprintf(buf, "%s(+%d)", (p_ptr->riding ? "¾èÇÏ" : "²Ã®"), (i - 110));
1438 #else
1439                 sprintf(buf, "Fast(+%d)", (i - 110));
1440 #endif
1441
1442         }
1443
1444         /* Slow */
1445         else if (i < 110)
1446         {
1447                 if (p_ptr->riding)
1448                 {
1449                         if (m_list[p_ptr->riding].fast && !m_list[p_ptr->riding].slow) attr = TERM_L_BLUE;
1450                         else if (m_list[p_ptr->riding].slow && !m_list[p_ptr->riding].fast) attr = TERM_VIOLET;
1451                         else attr = TERM_RED;
1452                 }
1453                 else if (is_fast && !p_ptr->slow) attr = TERM_YELLOW;
1454                 else if (p_ptr->slow && !is_fast) attr = TERM_VIOLET;
1455                 else attr = TERM_L_UMBER;
1456 #ifdef JP
1457                 sprintf(buf, "%s(-%d)", (p_ptr->riding ? "¾èÇÏ" : "¸ºÂ®"), (110 - i));
1458 #else
1459                 sprintf(buf, "Slow(-%d)", (110 - i));
1460 #endif
1461         }
1462         else if (p_ptr->riding)
1463         {
1464                 attr = TERM_GREEN;
1465 #ifdef JP
1466                 strcpy(buf, "¾èÇÏÃæ");
1467 #else
1468                 strcpy(buf, "Riding");
1469 #endif
1470         }
1471
1472         /* Display the speed */
1473         c_put_str(attr, format("%-9s", buf), ROW_SPEED, COL_SPEED);
1474 }
1475
1476
1477 static void prt_study(void)
1478 {
1479         if (p_ptr->new_spells)
1480         {
1481 #ifdef JP
1482                 put_str("³Ø½¬", ROW_STUDY, COL_STUDY);
1483 #else
1484                 put_str("Stud", ROW_STUDY, COL_STUDY);
1485 #endif
1486
1487         }
1488         else
1489         {
1490                 put_str("    ", ROW_STUDY, COL_STUDY);
1491         }
1492 }
1493
1494
1495 static void prt_mane(void)
1496 {
1497         if (p_ptr->pclass == CLASS_IMITATOR)
1498         {
1499                 if (mane_num)
1500                 {
1501                         byte attr;
1502                         if (new_mane) attr = TERM_L_RED;
1503                         else attr = TERM_WHITE;
1504 #ifdef JP
1505                         c_put_str(attr, "¤Þ¤Í", ROW_STUDY, COL_STUDY);
1506 #else
1507                         c_put_str(attr, "Mane", ROW_STUDY, COL_STUDY);
1508 #endif
1509                 }
1510                 else
1511                 {
1512                         put_str("    ", ROW_STUDY, COL_STUDY);
1513                 }
1514         }
1515 }
1516
1517
1518 static void prt_cut(void)
1519 {
1520         int c = p_ptr->cut;
1521
1522         if (c > 1000)
1523         {
1524 #ifdef JP
1525                 c_put_str(TERM_L_RED, "Ã×Ì¿½ý      ", ROW_CUT, COL_CUT);
1526 #else
1527                 c_put_str(TERM_L_RED, "Mortal wound", ROW_CUT, COL_CUT);
1528 #endif
1529
1530         }
1531         else if (c > 200)
1532         {
1533 #ifdef JP
1534                 c_put_str(TERM_RED, "¤Ò¤É¤¤¿¼¼ê  ", ROW_CUT, COL_CUT);
1535 #else
1536                 c_put_str(TERM_RED, "Deep gash   ", ROW_CUT, COL_CUT);
1537 #endif
1538
1539         }
1540         else if (c > 100)
1541         {
1542 #ifdef JP
1543                 c_put_str(TERM_RED, "½Å½ý        ", ROW_CUT, COL_CUT);
1544 #else
1545                 c_put_str(TERM_RED, "Severe cut  ", ROW_CUT, COL_CUT);
1546 #endif
1547
1548         }
1549         else if (c > 50)
1550         {
1551 #ifdef JP
1552                 c_put_str(TERM_ORANGE, "ÂçÊѤʽý    ", ROW_CUT, COL_CUT);
1553 #else
1554                 c_put_str(TERM_ORANGE, "Nasty cut   ", ROW_CUT, COL_CUT);
1555 #endif
1556
1557         }
1558         else if (c > 25)
1559         {
1560 #ifdef JP
1561                 c_put_str(TERM_ORANGE, "¤Ò¤É¤¤½ý    ", ROW_CUT, COL_CUT);
1562 #else
1563                 c_put_str(TERM_ORANGE, "Bad cut     ", ROW_CUT, COL_CUT);
1564 #endif
1565
1566         }
1567         else if (c > 10)
1568         {
1569 #ifdef JP
1570                 c_put_str(TERM_YELLOW, "·Ú½ý        ", ROW_CUT, COL_CUT);
1571 #else
1572                 c_put_str(TERM_YELLOW, "Light cut   ", ROW_CUT, COL_CUT);
1573 #endif
1574
1575         }
1576         else if (c)
1577         {
1578 #ifdef JP
1579                 c_put_str(TERM_YELLOW, "¤«¤¹¤ê½ý    ", ROW_CUT, COL_CUT);
1580 #else
1581                 c_put_str(TERM_YELLOW, "Graze       ", ROW_CUT, COL_CUT);
1582 #endif
1583
1584         }
1585         else
1586         {
1587                 put_str("            ", ROW_CUT, COL_CUT);
1588         }
1589 }
1590
1591
1592
1593 static void prt_stun(void)
1594 {
1595         int s = p_ptr->stun;
1596
1597         if (s > 100)
1598         {
1599 #ifdef JP
1600                 c_put_str(TERM_RED, "°Õ¼±ÉÔÌÀÎÆ  ", ROW_STUN, COL_STUN);
1601 #else
1602                 c_put_str(TERM_RED, "Knocked out ", ROW_STUN, COL_STUN);
1603 #endif
1604
1605         }
1606         else if (s > 50)
1607         {
1608 #ifdef JP
1609                 c_put_str(TERM_ORANGE, "¤Ò¤É¤¯Û¯Û°  ", ROW_STUN, COL_STUN);
1610 #else
1611                 c_put_str(TERM_ORANGE, "Heavy stun  ", ROW_STUN, COL_STUN);
1612 #endif
1613
1614         }
1615         else if (s)
1616         {
1617 #ifdef JP
1618                 c_put_str(TERM_ORANGE, "ۯ۰        ", ROW_STUN, COL_STUN);
1619 #else
1620                 c_put_str(TERM_ORANGE, "Stun        ", ROW_STUN, COL_STUN);
1621 #endif
1622
1623         }
1624         else
1625         {
1626                 put_str("            ", ROW_STUN, COL_STUN);
1627         }
1628 }
1629
1630
1631
1632 /*
1633  * Redraw the "monster health bar"      -DRS-
1634  * Rather extensive modifications by    -BEN-
1635  *
1636  * The "monster health bar" provides visual feedback on the "health"
1637  * of the monster currently being "tracked".  There are several ways
1638  * to "track" a monster, including targetting it, attacking it, and
1639  * affecting it (and nobody else) with a ranged attack.
1640  *
1641  * Display the monster health bar (affectionately known as the
1642  * "health-o-meter").  Clear health bar if nothing is being tracked.
1643  * Auto-track current target monster when bored.  Note that the
1644  * health-bar stops tracking any monster that "disappears".
1645  */
1646 static void health_redraw(void)
1647 {
1648
1649 #ifdef DRS_SHOW_HEALTH_BAR
1650
1651         /* Not tracking */
1652         if (!p_ptr->health_who)
1653         {
1654                 /* Erase the health bar */
1655                 Term_erase(COL_INFO, ROW_INFO, 12);
1656         }
1657
1658         /* Tracking an unseen monster */
1659         else if (!m_list[p_ptr->health_who].ml)
1660         {
1661                 /* Indicate that the monster health is "unknown" */
1662                 Term_putstr(COL_INFO, ROW_INFO, 12, TERM_WHITE, "[----------]");
1663         }
1664
1665         /* Tracking a hallucinatory monster */
1666         else if (p_ptr->image)
1667         {
1668                 /* Indicate that the monster health is "unknown" */
1669                 Term_putstr(COL_INFO, ROW_INFO, 12, TERM_WHITE, "[----------]");
1670         }
1671
1672         /* Tracking a dead monster (???) */
1673         else if (!m_list[p_ptr->health_who].hp < 0)
1674         {
1675                 /* Indicate that the monster health is "unknown" */
1676                 Term_putstr(COL_INFO, ROW_INFO, 12, TERM_WHITE, "[----------]");
1677         }
1678
1679         /* Tracking a visible monster */
1680         else
1681         {
1682                 int pct, pct2, len;
1683
1684                 monster_type *m_ptr = &m_list[p_ptr->health_who];
1685
1686                 /* Default to almost dead */
1687                 byte attr = TERM_RED;
1688
1689                 /* Extract the "percent" of health */
1690                 pct = 100L * m_ptr->hp / m_ptr->maxhp;
1691                 pct2 = 100L * m_ptr->hp / m_ptr->max_maxhp;
1692
1693                 /* Badly wounded */
1694                 if (pct >= 10) attr = TERM_L_RED;
1695
1696                 /* Wounded */
1697                 if (pct >= 25) attr = TERM_ORANGE;
1698
1699                 /* Somewhat Wounded */
1700                 if (pct >= 60) attr = TERM_YELLOW;
1701
1702                 /* Healthy */
1703                 if (pct >= 100) attr = TERM_L_GREEN;
1704
1705                 /* Afraid */
1706                 if (m_ptr->monfear) attr = TERM_VIOLET;
1707
1708                 /* Asleep */
1709                 if (m_ptr->csleep) attr = TERM_BLUE;
1710
1711                 /* Invulnerable */
1712                 if (m_ptr->invulner) attr = TERM_WHITE;
1713
1714                 /* Convert percent into "health" */
1715                 len = (pct2 < 10) ? 1 : (pct2 < 90) ? (pct2 / 10 + 1) : 10;
1716
1717                 /* Default to "unknown" */
1718                 Term_putstr(COL_INFO, ROW_INFO, 12, TERM_WHITE, "[----------]");
1719
1720                 /* Dump the current "health" (use '*' symbols) */
1721                 Term_putstr(COL_INFO + 1, ROW_INFO, len, attr, "**********");
1722         }
1723
1724 #endif
1725
1726 }
1727
1728
1729
1730 static void riding_health_redraw(void)
1731 {
1732
1733 #ifdef DRS_SHOW_HEALTH_BAR
1734
1735         /* Not tracking */
1736         if (!p_ptr->riding)
1737         {
1738                 /* Erase the health bar */
1739                 Term_erase(COL_RIDING_INFO, ROW_RIDING_INFO, 12);
1740         }
1741
1742         /* Tracking a hallucinatory monster */
1743         else if (p_ptr->image)
1744         {
1745                 /* Indicate that the monster health is "unknown" */
1746                 Term_putstr(COL_RIDING_INFO, ROW_RIDING_INFO, 12, TERM_WHITE, "[----------]");
1747         }
1748
1749         /* Tracking a dead monster (???) */
1750         else if (!m_list[p_ptr->health_who].hp < 0)
1751         {
1752                 /* Indicate that the monster health is "unknown" */
1753                 Term_putstr(COL_RIDING_INFO, ROW_RIDING_INFO, 12, TERM_WHITE, "[----------]");
1754         }
1755
1756         /* Tracking a visible monster */
1757         else
1758         {
1759                 int pct, pct2, len;
1760
1761                 monster_type *m_ptr = &m_list[p_ptr->riding];
1762
1763                 /* Default to almost dead */
1764                 byte attr = TERM_RED;
1765
1766                 /* Extract the "percent" of health */
1767                 pct = 100L * m_ptr->hp / m_ptr->maxhp;
1768                 pct2 = 100L * m_ptr->hp / m_ptr->max_maxhp;
1769
1770                 /* Badly wounded */
1771                 if (pct >= 10) attr = TERM_L_RED;
1772
1773                 /* Wounded */
1774                 if (pct >= 25) attr = TERM_ORANGE;
1775
1776                 /* Somewhat Wounded */
1777                 if (pct >= 60) attr = TERM_YELLOW;
1778
1779                 /* Healthy */
1780                 if (pct >= 100) attr = TERM_L_GREEN;
1781
1782                 /* Afraid */
1783                 if (m_ptr->monfear) attr = TERM_VIOLET;
1784
1785                 /* Asleep */
1786                 if (m_ptr->csleep) attr = TERM_BLUE;
1787
1788                 /* Invulnerable */
1789                 if (m_ptr->invulner) attr = TERM_WHITE;
1790
1791                 /* Convert percent into "health" */
1792                 len = (pct2 < 10) ? 1 : (pct2 < 90) ? (pct2 / 10 + 1) : 10;
1793
1794                 /* Default to "unknown" */
1795                 Term_putstr(COL_RIDING_INFO, ROW_RIDING_INFO, 12, TERM_WHITE, "[----------]");
1796
1797                 /* Dump the current "health" (use '*' symbols) */
1798                 Term_putstr(COL_RIDING_INFO + 1, ROW_RIDING_INFO, len, attr, "**********");
1799         }
1800
1801 #endif
1802
1803 }
1804
1805
1806
1807 /*
1808  * Display basic info (mostly left of map)
1809  */
1810 static void prt_frame_basic(void)
1811 {
1812         int i;
1813
1814         /* Race and Class */
1815         if (p_ptr->mimic_form)
1816                 prt_field(mimic_info[p_ptr->mimic_form].title, ROW_RACE, COL_RACE);
1817         else
1818         {
1819 #ifdef JP
1820                 char str[14];
1821                 mb_strlcpy(str, rp_ptr->title, 14);
1822                 prt_field(str, ROW_RACE, COL_RACE);
1823 #else
1824                 prt_field(rp_ptr->title, ROW_RACE, COL_RACE);
1825 #endif
1826         }
1827 /*      prt_field(cp_ptr->title, ROW_CLASS, COL_CLASS); */
1828 /*      prt_field(ap_ptr->title, ROW_SEIKAKU, COL_SEIKAKU); */
1829
1830
1831         /* Title */
1832         prt_title();
1833
1834         /* Level/Experience */
1835         prt_level();
1836         prt_exp();
1837
1838         /* All Stats */
1839         for (i = 0; i < 6; i++) prt_stat(i);
1840
1841         /* Armor */
1842         prt_ac();
1843
1844         /* Hitpoints */
1845         prt_hp();
1846
1847         /* Spellpoints */
1848         prt_sp();
1849
1850         /* Gold */
1851         prt_gold();
1852
1853         /* Current depth */
1854         prt_depth();
1855
1856         /* Special */
1857         health_redraw();
1858         riding_health_redraw();
1859 }
1860
1861
1862 /*
1863  * Display extra info (mostly below map)
1864  */
1865 static void prt_frame_extra(void)
1866 {
1867         /* Cut/Stun */
1868         prt_cut();
1869         prt_stun();
1870
1871         /* Food */
1872         prt_hunger();
1873
1874         /* State */
1875         prt_state();
1876
1877         /* Speed */
1878         prt_speed();
1879
1880         /* Study spells */
1881         prt_study();
1882
1883         prt_mane();
1884
1885         prt_status();
1886 }
1887
1888
1889 /*
1890  * Hack -- display inventory in sub-windows
1891  */
1892 static void fix_inven(void)
1893 {
1894         int j;
1895
1896         /* Scan windows */
1897         for (j = 0; j < 8; j++)
1898         {
1899                 term *old = Term;
1900
1901                 /* No window */
1902                 if (!angband_term[j]) continue;
1903
1904                 /* No relevant flags */
1905                 if (!(window_flag[j] & (PW_INVEN))) continue;
1906
1907                 /* Activate */
1908                 Term_activate(angband_term[j]);
1909
1910                 /* Display inventory */
1911                 display_inven();
1912
1913                 /* Fresh */
1914                 Term_fresh();
1915
1916                 /* Restore */
1917                 Term_activate(old);
1918         }
1919 }
1920
1921
1922
1923 /*
1924  * Hack -- display equipment in sub-windows
1925  */
1926 static void fix_equip(void)
1927 {
1928         int j;
1929
1930         /* Scan windows */
1931         for (j = 0; j < 8; j++)
1932         {
1933                 term *old = Term;
1934
1935                 /* No window */
1936                 if (!angband_term[j]) continue;
1937
1938                 /* No relevant flags */
1939                 if (!(window_flag[j] & (PW_EQUIP))) continue;
1940
1941                 /* Activate */
1942                 Term_activate(angband_term[j]);
1943
1944                 /* Display equipment */
1945                 display_equip();
1946
1947                 /* Fresh */
1948                 Term_fresh();
1949
1950                 /* Restore */
1951                 Term_activate(old);
1952         }
1953 }
1954
1955
1956 /*
1957  * Hack -- display equipment in sub-windows
1958  */
1959 static void fix_spell(void)
1960 {
1961         int j;
1962
1963         /* Scan windows */
1964         for (j = 0; j < 8; j++)
1965         {
1966                 term *old = Term;
1967
1968                 /* No window */
1969                 if (!angband_term[j]) continue;
1970
1971                 /* No relevant flags */
1972                 if (!(window_flag[j] & (PW_SPELL))) continue;
1973
1974                 /* Activate */
1975                 Term_activate(angband_term[j]);
1976
1977                 /* Display spell list */
1978                 display_spell_list();
1979
1980                 /* Fresh */
1981                 Term_fresh();
1982
1983                 /* Restore */
1984                 Term_activate(old);
1985         }
1986 }
1987
1988
1989 /*
1990  * Hack -- display character in sub-windows
1991  */
1992 static void fix_player(void)
1993 {
1994         int j;
1995
1996         /* Scan windows */
1997         for (j = 0; j < 8; j++)
1998         {
1999                 term *old = Term;
2000
2001                 /* No window */
2002                 if (!angband_term[j]) continue;
2003
2004                 /* No relevant flags */
2005                 if (!(window_flag[j] & (PW_PLAYER))) continue;
2006
2007                 /* Activate */
2008                 Term_activate(angband_term[j]);
2009
2010                 update_playtime();
2011
2012                 /* Display player */
2013                 display_player(0);
2014
2015                 /* Fresh */
2016                 Term_fresh();
2017
2018                 /* Restore */
2019                 Term_activate(old);
2020         }
2021 }
2022
2023
2024
2025 /*
2026  * Hack -- display recent messages in sub-windows
2027  *
2028  * XXX XXX XXX Adjust for width and split messages
2029  */
2030 static void fix_message(void)
2031 {
2032         int j, i;
2033         int w, h;
2034         int x, y;
2035
2036         /* Scan windows */
2037         for (j = 0; j < 8; j++)
2038         {
2039                 term *old = Term;
2040
2041                 /* No window */
2042                 if (!angband_term[j]) continue;
2043
2044                 /* No relevant flags */
2045                 if (!(window_flag[j] & (PW_MESSAGE))) continue;
2046
2047                 /* Activate */
2048                 Term_activate(angband_term[j]);
2049
2050                 /* Get size */
2051                 Term_get_size(&w, &h);
2052
2053                 /* Dump messages */
2054                 for (i = 0; i < h; i++)
2055                 {
2056                         /* Dump the message on the appropriate line */
2057                         Term_putstr(0, (h - 1) - i, -1, (byte)((i < now_message) ? TERM_WHITE : TERM_SLATE), message_str((s16b)i));
2058
2059                         /* Cursor */
2060                         Term_locate(&x, &y);
2061
2062                         /* Clear to end of line */
2063                         Term_erase(x, y, 255);
2064                 }
2065
2066                 /* Fresh */
2067                 Term_fresh();
2068
2069                 /* Restore */
2070                 Term_activate(old);
2071         }
2072 }
2073
2074
2075 /*
2076  * Hack -- display overhead view in sub-windows
2077  *
2078  * Note that the "player" symbol does NOT appear on the map.
2079  */
2080 static void fix_overhead(void)
2081 {
2082         int j;
2083
2084         int cy, cx;
2085
2086         /* Scan windows */
2087         for (j = 0; j < 8; j++)
2088         {
2089                 term *old = Term;
2090
2091                 /* No window */
2092                 if (!angband_term[j]) continue;
2093
2094                 /* No relevant flags */
2095                 if (!(window_flag[j] & (PW_OVERHEAD))) continue;
2096
2097                 /* Activate */
2098                 Term_activate(angband_term[j]);
2099
2100                 /* Redraw map */
2101                 display_map(&cy, &cx);
2102
2103                 /* Fresh */
2104                 Term_fresh();
2105
2106                 /* Restore */
2107                 Term_activate(old);
2108         }
2109 }
2110
2111
2112 /*
2113  * Hack -- display dungeon view in sub-windows
2114  */
2115 static void fix_dungeon(void)
2116 {
2117         int j;
2118
2119         /* Scan windows */
2120         for (j = 0; j < 8; j++)
2121         {
2122                 term *old = Term;
2123
2124                 /* No window */
2125                 if (!angband_term[j]) continue;
2126
2127                 /* No relevant flags */
2128                 if (!(window_flag[j] & (PW_DUNGEON))) continue;
2129
2130                 /* Activate */
2131                 Term_activate(angband_term[j]);
2132
2133                 /* Redraw dungeon view */
2134                 display_dungeon();
2135
2136                 /* Fresh */
2137                 Term_fresh();
2138
2139                 /* Restore */
2140                 Term_activate(old);
2141         }
2142 }
2143
2144
2145 /*
2146  * Hack -- display monster recall in sub-windows
2147  */
2148 static void fix_monster(void)
2149 {
2150         int j;
2151
2152         /* Scan windows */
2153         for (j = 0; j < 8; j++)
2154         {
2155                 term *old = Term;
2156
2157                 /* No window */
2158                 if (!angband_term[j]) continue;
2159
2160                 /* No relevant flags */
2161                 if (!(window_flag[j] & (PW_MONSTER))) continue;
2162
2163                 /* Activate */
2164                 Term_activate(angband_term[j]);
2165
2166                 /* Display monster race info */
2167                 if (p_ptr->monster_race_idx) display_roff(p_ptr->monster_race_idx);
2168
2169                 /* Fresh */
2170                 Term_fresh();
2171
2172                 /* Restore */
2173                 Term_activate(old);
2174         }
2175 }
2176
2177
2178 /*
2179  * Hack -- display object recall in sub-windows
2180  */
2181 static void fix_object(void)
2182 {
2183         int j;
2184
2185         /* Scan windows */
2186         for (j = 0; j < 8; j++)
2187         {
2188                 term *old = Term;
2189
2190                 /* No window */
2191                 if (!angband_term[j]) continue;
2192
2193                 /* No relevant flags */
2194                 if (!(window_flag[j] & (PW_OBJECT))) continue;
2195
2196                 /* Activate */
2197                 Term_activate(angband_term[j]);
2198
2199                 /* Display monster race info */
2200                 if (p_ptr->object_kind_idx) display_koff(p_ptr->object_kind_idx);
2201
2202                 /* Fresh */
2203                 Term_fresh();
2204
2205                 /* Restore */
2206                 Term_activate(old);
2207         }
2208 }
2209
2210
2211 /*
2212  * Calculate number of spells player should have, and forget,
2213  * or remember, spells until that number is properly reflected.
2214  *
2215  * Note that this function induces various "status" messages,
2216  * which must be bypasses until the character is created.
2217  */
2218 static void calc_spells(void)
2219 {
2220         int                     i, j, k, levels;
2221         int                     num_allowed;
2222         int                     num_boukyaku = 0;
2223
2224         magic_type              *s_ptr;
2225         int use_realm1 = p_ptr->realm1 - 1;
2226         int use_realm2 = p_ptr->realm2 - 1;
2227         int which;
2228         int bonus = 0;
2229
2230
2231         cptr p;
2232
2233         /* Hack -- must be literate */
2234         if (!mp_ptr->spell_book) return;
2235
2236         /* Hack -- wait for creation */
2237         if (!character_generated) return;
2238
2239         /* Hack -- handle "xtra" mode */
2240         if (character_xtra) return;
2241
2242         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
2243         {
2244                 p_ptr->new_spells = 0;
2245                 return;
2246         }
2247
2248         p = spell_categoly_name(mp_ptr->spell_book);
2249
2250         /* Determine the number of spells allowed */
2251         levels = p_ptr->lev - mp_ptr->spell_first + 1;
2252
2253         /* Hack -- no negative spells */
2254         if (levels < 0) levels = 0;
2255
2256         /* Extract total allowed spells */
2257         num_allowed = (adj_mag_study[p_ptr->stat_ind[mp_ptr->spell_stat]] * levels / 2);
2258
2259         if ((p_ptr->pclass != CLASS_SAMURAI) && (mp_ptr->spell_book != TV_LIFE_BOOK))
2260         {
2261                 bonus = 4;
2262         }
2263         if (p_ptr->pclass == CLASS_SAMURAI)
2264         {
2265                 num_allowed = 32;
2266         }
2267         else if (p_ptr->realm2 == REALM_NONE)
2268         {
2269                 num_allowed = (num_allowed+1)/2;
2270                 if (num_allowed>(32+bonus)) num_allowed = 32+bonus;
2271         }
2272         else if ((p_ptr->pclass == CLASS_MAGE) || (p_ptr->pclass == CLASS_PRIEST))
2273         {
2274                 if (num_allowed>(96+bonus)) num_allowed = 96+bonus;
2275         }
2276         else
2277         {
2278                 if (num_allowed>(80+bonus)) num_allowed = 80+bonus;
2279         }
2280
2281         /* Count the number of spells we know */
2282         for (j = 0; j < 64; j++)
2283         {
2284                 /* Count known spells */
2285                 if ((j < 32) ?
2286                     (spell_forgotten1 & (1L << j)) :
2287                     (spell_forgotten2 & (1L << (j - 32))))
2288                 {
2289                         num_boukyaku++;
2290                 }
2291         }
2292
2293         /* See how many spells we must forget or may learn */
2294         p_ptr->new_spells = num_allowed + p_ptr->add_spells + num_boukyaku - p_ptr->learned_spells;
2295
2296         /* Forget spells which are too hard */
2297         for (i = 63; i >= 0; i--)
2298         {
2299                 /* Efficiency -- all done */
2300                 if (!spell_learned1 && !spell_learned2) break;
2301
2302                 /* Access the spell */
2303                 j = spell_order[i];
2304
2305                 /* Skip non-spells */
2306                 if (j >= 99) continue;
2307
2308
2309                 /* Get the spell */
2310                 if (!is_magic(((j < 32) ? use_realm1 : use_realm2)+1))
2311                 {
2312                         if (j < 32)
2313                                 s_ptr = &technic_info[use_realm1 - MIN_TECHNIC][j];
2314                         else
2315                                 s_ptr = &technic_info[use_realm2 - MIN_TECHNIC][j%32];
2316                 }
2317                 else if (j < 32)
2318                         s_ptr = &mp_ptr->info[use_realm1][j];
2319                 else
2320                         s_ptr = &mp_ptr->info[use_realm2][j%32];
2321
2322                 /* Skip spells we are allowed to know */
2323                 if (s_ptr->slevel <= p_ptr->lev) continue;
2324
2325                 /* Is it known? */
2326                 if ((j < 32) ?
2327                     (spell_learned1 & (1L << j)) :
2328                     (spell_learned2 & (1L << (j - 32))))
2329                 {
2330                         /* Mark as forgotten */
2331                         if (j < 32)
2332                         {
2333                                 spell_forgotten1 |= (1L << j);
2334                                 which = use_realm1;
2335                         }
2336                         else
2337                         {
2338                                 spell_forgotten2 |= (1L << (j - 32));
2339                                 which = use_realm2;
2340                         }
2341
2342                         /* No longer known */
2343                         if (j < 32)
2344                         {
2345                                 spell_learned1 &= ~(1L << j);
2346                                 which = use_realm1;
2347                         }
2348                         else
2349                         {
2350                                 spell_learned2 &= ~(1L << (j - 32));
2351                                 which = use_realm2;
2352                         }
2353
2354                         /* Message */
2355 #ifdef JP
2356                         msg_format("%s¤Î%s¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡£",
2357                                    spell_names[technic2magic(which+1)-1][j%32], p );
2358 #else
2359                         msg_format("You have forgotten the %s of %s.", p,
2360                         spell_names[technic2magic(which+1)-1][j%32]);
2361 #endif
2362
2363
2364                         /* One more can be learned */
2365                         p_ptr->new_spells++;
2366                 }
2367         }
2368
2369
2370         /* Forget spells if we know too many spells */
2371         for (i = 63; i >= 0; i--)
2372         {
2373                 /* Stop when possible */
2374                 if (p_ptr->new_spells >= 0) break;
2375
2376                 /* Efficiency -- all done */
2377                 if (!spell_learned1 && !spell_learned2) break;
2378
2379                 /* Get the (i+1)th spell learned */
2380                 j = spell_order[i];
2381
2382                 /* Skip unknown spells */
2383                 if (j >= 99) continue;
2384
2385                 /* Forget it (if learned) */
2386                 if ((j < 32) ?
2387                     (spell_learned1 & (1L << j)) :
2388                     (spell_learned2 & (1L << (j - 32))))
2389                 {
2390                         /* Mark as forgotten */
2391                         if (j < 32)
2392                         {
2393                                 spell_forgotten1 |= (1L << j);
2394                                 which = use_realm1;
2395                         }
2396                         else
2397                         {
2398                                 spell_forgotten2 |= (1L << (j - 32));
2399                                 which = use_realm2;
2400                         }
2401
2402                         /* No longer known */
2403                         if (j < 32)
2404                         {
2405                                 spell_learned1 &= ~(1L << j);
2406                                 which = use_realm1;
2407                         }
2408                         else
2409                         {
2410                                 spell_learned2 &= ~(1L << (j - 32));
2411                                 which = use_realm2;
2412                         }
2413
2414                         /* Message */
2415 #ifdef JP
2416                         msg_format("%s¤Î%s¤ò˺¤ì¤Æ¤·¤Þ¤Ã¤¿¡£",
2417                                    spell_names[technic2magic(which+1)-1][j%32], p );
2418 #else
2419                         msg_format("You have forgotten the %s of %s.", p,
2420                                    spell_names[technic2magic(which+1)-1][j%32]);
2421 #endif
2422
2423
2424                         /* One more can be learned */
2425                         p_ptr->new_spells++;
2426                 }
2427         }
2428
2429
2430         /* Check for spells to remember */
2431         for (i = 0; i < 64; i++)
2432         {
2433                 /* None left to remember */
2434                 if (p_ptr->new_spells <= 0) break;
2435
2436                 /* Efficiency -- all done */
2437                 if (!spell_forgotten1 && !spell_forgotten2) break;
2438
2439                 /* Get the next spell we learned */
2440                 j = spell_order[i];
2441
2442                 /* Skip unknown spells */
2443                 if (j >= 99) break;
2444
2445                 /* Access the spell */
2446                 if (!is_magic(((j < 32) ? use_realm1 : use_realm2)+1))
2447                 {
2448                         if (j < 32)
2449                                 s_ptr = &technic_info[use_realm1 - MIN_TECHNIC][j];
2450                         else
2451                                 s_ptr = &technic_info[use_realm2 - MIN_TECHNIC][j%32];
2452                 }
2453                 else if (j<32)
2454                         s_ptr = &mp_ptr->info[use_realm1][j];
2455                 else
2456                         s_ptr = &mp_ptr->info[use_realm2][j%32];
2457
2458                 /* Skip spells we cannot remember */
2459                 if (s_ptr->slevel > p_ptr->lev) continue;
2460
2461                 /* First set of spells */
2462                 if ((j < 32) ?
2463                     (spell_forgotten1 & (1L << j)) :
2464                     (spell_forgotten2 & (1L << (j - 32))))
2465                 {
2466                         /* No longer forgotten */
2467                         if (j < 32)
2468                         {
2469                                 spell_forgotten1 &= ~(1L << j);
2470                                 which = use_realm1;
2471                         }
2472                         else
2473                         {
2474                                 spell_forgotten2 &= ~(1L << (j - 32));
2475                                 which = use_realm2;
2476                         }
2477
2478                         /* Known once more */
2479                         if (j < 32)
2480                         {
2481                                 spell_learned1 |= (1L << j);
2482                                 which = use_realm1;
2483                         }
2484                         else
2485                         {
2486                                 spell_learned2 |= (1L << (j - 32));
2487                                 which = use_realm2;
2488                         }
2489
2490                         /* Message */
2491 #ifdef JP
2492                         msg_format("%s¤Î%s¤ò»×¤¤½Ð¤·¤¿¡£",
2493                                    spell_names[technic2magic(which+1)-1][j%32], p );
2494 #else
2495                         msg_format("You have remembered the %s of %s.",
2496                                    p, spell_names[technic2magic(which+1)-1][j%32]);
2497 #endif
2498
2499
2500                         /* One less can be learned */
2501                         p_ptr->new_spells--;
2502                 }
2503         }
2504
2505         k = 0;
2506
2507         if (p_ptr->realm2 == REALM_NONE)
2508         {
2509                 /* Count spells that can be learned */
2510                 for (j = 0; j < 32; j++)
2511                 {
2512                         if (!is_magic(use_realm1+1)) s_ptr = &technic_info[use_realm1-MIN_TECHNIC][j];
2513                         else s_ptr = &mp_ptr->info[use_realm1][j];
2514
2515                         /* Skip spells we cannot remember */
2516                         if (s_ptr->slevel > p_ptr->lev) continue;
2517
2518                         /* Skip spells we already know */
2519                         if (spell_learned1 & (1L << j))
2520                         {
2521                                 continue;
2522                         }
2523
2524                         /* Count it */
2525                         k++;
2526                 }
2527                 if (k>32) k = 32;
2528                 if ((p_ptr->new_spells > k) && ((mp_ptr->spell_book == TV_LIFE_BOOK) || (mp_ptr->spell_book == TV_HISSATSU_BOOK))) p_ptr->new_spells = k;
2529         }
2530
2531         if (p_ptr->new_spells < 0) p_ptr->new_spells = 0;
2532
2533         /* Spell count changed */
2534         if (p_ptr->old_spells != p_ptr->new_spells)
2535         {
2536                 /* Message if needed */
2537                 if (p_ptr->new_spells)
2538                 {
2539                         /* Message */
2540 #ifdef JP
2541                         if( p_ptr->new_spells < 10 ){
2542                                 msg_format("¤¢¤È %d ¤Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
2543                         }else{
2544                                 msg_format("¤¢¤È %d ¸Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
2545                         }
2546 #else
2547                         msg_format("You can learn %d more %s%s.",
2548                                    p_ptr->new_spells, p,
2549                                    (p_ptr->new_spells != 1) ? "s" : "");
2550 #endif
2551
2552                 }
2553
2554                 /* Save the new_spells value */
2555                 p_ptr->old_spells = p_ptr->new_spells;
2556
2557                 /* Redraw Study Status */
2558                 p_ptr->redraw |= (PR_STUDY);
2559         }
2560 }
2561
2562
2563 /*
2564  * Calculate maximum mana.  You do not need to know any spells.
2565  * Note that mana is lowered by heavy (or inappropriate) armor.
2566  *
2567  * This function induces status messages.
2568  */
2569 static void calc_mana(void)
2570 {
2571         int             msp, levels, cur_wgt, max_wgt;
2572
2573         object_type     *o_ptr;
2574
2575
2576         /* Hack -- Must be literate */
2577         if (!mp_ptr->spell_book) return;
2578
2579         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
2580             (p_ptr->pclass == CLASS_MIRROR_MASTER) ||
2581             (p_ptr->pclass == CLASS_BLUE_MAGE))
2582         {
2583                 levels = p_ptr->lev;
2584         }
2585         else
2586         {
2587                 if(mp_ptr->spell_first > p_ptr->lev)
2588                 {
2589                         /* Save new mana */
2590                         p_ptr->msp = 0;
2591
2592                         /* Display mana later */
2593                         p_ptr->redraw |= (PR_MANA);
2594                         return;
2595                 }
2596
2597                 /* Extract "effective" player level */
2598                 levels = (p_ptr->lev - mp_ptr->spell_first) + 1;
2599         }
2600
2601         if (p_ptr->pclass == CLASS_SAMURAI)
2602         {
2603                 msp = (adj_mag_mana[p_ptr->stat_ind[mp_ptr->spell_stat]] + 10) * 2;
2604                 if (msp) msp += (msp * rp_ptr->r_adj[mp_ptr->spell_stat] / 20);
2605         }
2606         else
2607         {
2608                 /* Extract total mana */
2609                 msp = adj_mag_mana[p_ptr->stat_ind[mp_ptr->spell_stat]] * (levels+3) / 4;
2610
2611                 /* Hack -- usually add one mana */
2612                 if (msp) msp++;
2613
2614                 if (msp) msp += (msp * rp_ptr->r_adj[mp_ptr->spell_stat] / 20);
2615
2616                 if (msp && (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)) msp += msp/2;
2617
2618                 /* Hack: High mages have a 25% mana bonus */
2619                 if (msp && (p_ptr->pclass == CLASS_HIGH_MAGE)) msp += msp / 4;
2620
2621                 if (msp && (p_ptr->pclass == CLASS_SORCERER)) msp += msp*(25+p_ptr->lev)/100;
2622         }
2623
2624         /* Only mages are affected */
2625         if (mp_ptr->spell_xtra & MAGIC_GLOVE_REDUCE_MANA)
2626         {
2627                 u32b f1, f2, f3;
2628
2629                 /* Assume player is not encumbered by gloves */
2630                 p_ptr->cumber_glove = FALSE;
2631
2632                 /* Get the gloves */
2633                 o_ptr = &inventory[INVEN_HANDS];
2634
2635                 /* Examine the gloves */
2636                 object_flags(o_ptr, &f1, &f2, &f3);
2637
2638                 /* Normal gloves hurt mage-type spells */
2639                 if (o_ptr->k_idx &&
2640                     !(f2 & (TR2_FREE_ACT)) &&
2641                     !(f1 & (TR1_MAGIC_MASTERY)) &&
2642                     !((f1 & (TR1_DEX)) && (o_ptr->pval > 0)))
2643                 {
2644                         /* Encumbered */
2645                         p_ptr->cumber_glove = TRUE;
2646
2647                         /* Reduce mana */
2648                         msp = (3 * msp) / 4;
2649                 }
2650         }
2651
2652
2653         /* Assume player not encumbered by armor */
2654         p_ptr->cumber_armor = FALSE;
2655
2656         /* Weigh the armor */
2657         cur_wgt = 0;
2658         if(inventory[INVEN_RARM].tval> TV_SWORD) cur_wgt += inventory[INVEN_RARM].weight;
2659         if(inventory[INVEN_LARM].tval> TV_SWORD) cur_wgt += inventory[INVEN_LARM].weight;
2660         cur_wgt += inventory[INVEN_BODY].weight;
2661         cur_wgt += inventory[INVEN_HEAD].weight;
2662         cur_wgt += inventory[INVEN_OUTER].weight;
2663         cur_wgt += inventory[INVEN_HANDS].weight;
2664         cur_wgt += inventory[INVEN_FEET].weight;
2665
2666         /* Subtract a percentage of maximum mana. */
2667         switch (p_ptr->pclass)
2668         {
2669                 /* For these classes, mana is halved if armour 
2670                  * is 30 pounds over their weight limit. */
2671                 case CLASS_MAGE:
2672                 case CLASS_HIGH_MAGE:
2673                 case CLASS_BLUE_MAGE:
2674                 case CLASS_MONK:
2675                 case CLASS_FORCETRAINER:
2676                 case CLASS_SORCERER:
2677                 {
2678                         if (inventory[INVEN_RARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_RARM].weight;
2679                         if (inventory[INVEN_LARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_LARM].weight;
2680                         break;
2681                 }
2682
2683                 /* Mana halved if armour is 40 pounds over weight limit. */
2684                 case CLASS_PRIEST:
2685                 case CLASS_BARD:
2686                 case CLASS_TOURIST:
2687                 {
2688                         if (inventory[INVEN_RARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_RARM].weight*2/3;
2689                         if (inventory[INVEN_LARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_LARM].weight*2/3;
2690                         break;
2691                 }
2692
2693                 case CLASS_MINDCRAFTER:
2694                 case CLASS_BEASTMASTER:
2695                 case CLASS_MIRROR_MASTER:
2696                 {
2697                         if (inventory[INVEN_RARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_RARM].weight/2;
2698                         if (inventory[INVEN_LARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_LARM].weight/2;
2699                         break;
2700                 }
2701
2702                 /* Mana halved if armour is 50 pounds over weight limit. */
2703                 case CLASS_ROGUE:
2704                 case CLASS_RANGER:
2705                 case CLASS_RED_MAGE:
2706                 case CLASS_WARRIOR_MAGE:
2707                 {
2708                         if (inventory[INVEN_RARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_RARM].weight/3;
2709                         if (inventory[INVEN_LARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_LARM].weight/3;
2710                         break;
2711                 }
2712
2713                 /* Mana halved if armour is 60 pounds over weight limit. */
2714                 case CLASS_PALADIN:
2715                 case CLASS_CHAOS_WARRIOR:
2716                 {
2717                         if (inventory[INVEN_RARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_RARM].weight/5;
2718                         if (inventory[INVEN_LARM].tval <= TV_SWORD) cur_wgt += inventory[INVEN_LARM].weight/5;
2719                         break;
2720                 }
2721
2722                 /* For new classes created, but not yet added to this formula. */
2723                 default:
2724                 {
2725                         break;
2726                 }
2727         }
2728
2729         /* Determine the weight allowance */
2730         max_wgt = mp_ptr->spell_weight;
2731
2732         /* Heavy armor penalizes mana by a percentage.  -LM- */
2733         if ((cur_wgt - max_wgt) > 0)
2734         {
2735                 /* Encumbered */
2736                 p_ptr->cumber_armor = TRUE;
2737
2738                 /* Subtract a percentage of maximum mana. */
2739                 switch (p_ptr->pclass)
2740                 {
2741                         /* For these classes, mana is halved if armour 
2742                          * is 30 pounds over their weight limit. */
2743                         case CLASS_MAGE:
2744                         case CLASS_HIGH_MAGE:
2745                         case CLASS_BLUE_MAGE:
2746                         {
2747                                 msp -= msp * (cur_wgt - max_wgt) / 600;
2748                                 break;
2749                         }
2750
2751                         /* Mana halved if armour is 40 pounds over weight limit. */
2752                         case CLASS_PRIEST:
2753                         case CLASS_MINDCRAFTER:
2754                         case CLASS_BEASTMASTER:
2755                         case CLASS_BARD:
2756                         case CLASS_FORCETRAINER:
2757                         case CLASS_TOURIST:
2758                         case CLASS_MIRROR_MASTER:
2759                         {
2760                                 msp -= msp * (cur_wgt - max_wgt) / 800;
2761                                 break;
2762                         }
2763
2764                         case CLASS_SORCERER:
2765                         {
2766                                 msp -= msp * (cur_wgt - max_wgt) / 900;
2767                                 break;
2768                         }
2769
2770                         /* Mana halved if armour is 50 pounds over weight limit. */
2771                         case CLASS_ROGUE:
2772                         case CLASS_RANGER:
2773                         case CLASS_MONK:
2774                         case CLASS_RED_MAGE:
2775                         {
2776                                 msp -= msp * (cur_wgt - max_wgt) / 1000;
2777                                 break;
2778                         }
2779
2780                         /* Mana halved if armour is 60 pounds over weight limit. */
2781                         case CLASS_PALADIN:
2782                         case CLASS_CHAOS_WARRIOR:
2783                         case CLASS_WARRIOR_MAGE:
2784                         {
2785                                 msp -= msp * (cur_wgt - max_wgt) / 1200;
2786                                 break;
2787                         }
2788
2789                         case CLASS_SAMURAI:
2790                         {
2791                                 p_ptr->cumber_armor = FALSE;
2792                                 break;
2793                         }
2794
2795                         /* For new classes created, but not yet added to this formula. */
2796                         default:
2797                         {
2798                                 msp -= msp * (cur_wgt - max_wgt) / 800;
2799                                 break;
2800                         }
2801                 }
2802         }
2803
2804         /* Mana can never be negative */
2805         if (msp < 0) msp = 0;
2806
2807
2808         /* Maximum mana has changed */
2809         if (p_ptr->msp != msp)
2810         {
2811                 /* Enforce maximum */
2812                 if ((p_ptr->csp >= msp) && (p_ptr->pclass != CLASS_SAMURAI))
2813                 {
2814                         p_ptr->csp = msp;
2815                         p_ptr->csp_frac = 0;
2816                 }
2817
2818 #ifdef JP
2819                 /* ¥ì¥Ù¥ë¥¢¥Ã¥×¤Î»þ¤Ï¾å¾ºÎ̤òɽ¼¨¤¹¤ë */
2820                 if ((level_up == 1) && (msp > p_ptr->msp))
2821                 {
2822                         msg_format("ºÇÂç¥Þ¥¸¥Ã¥¯¡¦¥Ý¥¤¥ó¥È¤¬ %d Áý²Ã¤·¤¿¡ª",
2823                                    (msp - p_ptr->msp));
2824                 }
2825 #endif
2826                 /* Save new mana */
2827                 p_ptr->msp = msp;
2828
2829                 /* Display mana later */
2830                 p_ptr->redraw |= (PR_MANA);
2831
2832                 /* Window stuff */
2833                 p_ptr->window |= (PW_PLAYER);
2834                 p_ptr->window |= (PW_SPELL);
2835         }
2836
2837
2838         /* Hack -- handle "xtra" mode */
2839         if (character_xtra) return;
2840
2841         /* Take note when "glove state" changes */
2842         if (p_ptr->old_cumber_glove != p_ptr->cumber_glove)
2843         {
2844                 /* Message */
2845                 if (p_ptr->cumber_glove)
2846                 {
2847 #ifdef JP
2848                         msg_print("¼ê¤¬Ê¤¤ï¤ì¤Æ¼öʸ¤¬¾§¤¨¤Ë¤¯¤¤´¶¤¸¤¬¤¹¤ë¡£");
2849 #else
2850                         msg_print("Your covered hands feel unsuitable for spellcasting.");
2851 #endif
2852
2853                 }
2854                 else
2855                 {
2856 #ifdef JP
2857                         msg_print("¤³¤Î¼ê¤Î¾õÂ֤ʤ顢¤°¤Ã¤È¼öʸ¤¬¾§¤¨¤ä¤¹¤¤´¶¤¸¤À¡£");
2858 #else
2859                         msg_print("Your hands feel more suitable for spellcasting.");
2860 #endif
2861
2862                 }
2863
2864                 /* Save it */
2865                 p_ptr->old_cumber_glove = p_ptr->cumber_glove;
2866         }
2867
2868
2869         /* Take note when "armor state" changes */
2870         if (p_ptr->old_cumber_armor != p_ptr->cumber_armor)
2871         {
2872                 /* Message */
2873                 if (p_ptr->cumber_armor)
2874                 {
2875 #ifdef JP
2876                         msg_print("ÁõÈ÷¤Î½Å¤µ¤ÇÆ°¤­¤¬Æߤ¯¤Ê¤Ã¤Æ¤·¤Þ¤Ã¤Æ¤¤¤ë¡£");
2877 #else
2878                         msg_print("The weight of your equipment encumbers your movement.");
2879 #endif
2880
2881                 }
2882                 else
2883                 {
2884 #ifdef JP
2885                         msg_print("¤°¤Ã¤È³Ú¤ËÂΤòÆ°¤«¤»¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£");
2886 #else
2887                         msg_print("You feel able to move more freely.");
2888 #endif
2889
2890                 }
2891
2892                 /* Save it */
2893                 p_ptr->old_cumber_armor = p_ptr->cumber_armor;
2894         }
2895 }
2896
2897
2898
2899 /*
2900  * Calculate the players (maximal) hit points
2901  * Adjust current hitpoints if necessary
2902  */
2903 static void calc_hitpoints(void)
2904 {
2905         int bonus, mhp;
2906         byte tmp_hitdie;
2907
2908         /* Un-inflate "half-hitpoint bonus per level" value */
2909         bonus = ((int)(adj_con_mhp[p_ptr->stat_ind[A_CON]]) - 128) * p_ptr->lev / 4;
2910
2911         /* Calculate hitpoints */
2912         mhp = player_hp[p_ptr->lev - 1];
2913
2914         if (p_ptr->mimic_form)
2915         {
2916                 if (p_ptr->pclass == CLASS_SORCERER)
2917                         tmp_hitdie = mimic_info[p_ptr->mimic_form].r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2918                 else
2919                         tmp_hitdie = mimic_info[p_ptr->mimic_form].r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2920                 mhp = mhp * tmp_hitdie / p_ptr->hitdie;
2921         }
2922
2923         if (p_ptr->pclass == CLASS_SORCERER)
2924         {
2925                 if (p_ptr->lev < 30)
2926                         mhp = (mhp * (45+p_ptr->lev) / 100);
2927                 else
2928                         mhp = (mhp * 75 / 100);
2929                 bonus = (bonus * 65 / 100);
2930         }
2931
2932         mhp += bonus;
2933
2934         if (p_ptr->pclass == CLASS_BERSERKER)
2935         {
2936                 mhp = mhp*(110+(((p_ptr->lev + 40) * (p_ptr->lev + 40) - 1550) / 110))/100;
2937         }
2938
2939         /* Always have at least one hitpoint per level */
2940         if (mhp < p_ptr->lev + 1) mhp = p_ptr->lev + 1;
2941
2942         /* Factor in the hero / superhero settings */
2943         if (p_ptr->hero || music_singing(MUSIC_HERO) || music_singing(MUSIC_SHERO))
2944         if (p_ptr->shero) mhp += 30;
2945         if (p_ptr->tsuyoshi) mhp += 50;
2946
2947         /* New maximum hitpoints */
2948         if (p_ptr->mhp != mhp)
2949         {
2950                 /* Enforce maximum */
2951                 if (p_ptr->chp >= mhp)
2952                 {
2953                         p_ptr->chp = mhp;
2954                         p_ptr->chp_frac = 0;
2955                 }
2956
2957 #ifdef JP
2958                 /* ¥ì¥Ù¥ë¥¢¥Ã¥×¤Î»þ¤Ï¾å¾ºÎ̤òɽ¼¨¤¹¤ë */
2959                 if ((level_up == 1) && (mhp > p_ptr->mhp))
2960                 {
2961                         msg_format("ºÇÂç¥Ò¥Ã¥È¡¦¥Ý¥¤¥ó¥È¤¬ %d Áý²Ã¤·¤¿¡ª",
2962                                    (mhp - p_ptr->mhp) );
2963                 }
2964 #endif
2965                 /* Save the new max-hitpoints */
2966                 p_ptr->mhp = mhp;
2967
2968                 /* Display hitpoints (later) */
2969                 p_ptr->redraw |= (PR_HP);
2970
2971                 /* Window stuff */
2972                 p_ptr->window |= (PW_PLAYER);
2973         }
2974 }
2975
2976
2977
2978 /*
2979  * Extract and set the current "lite radius"
2980  *
2981  * SWD: Experimental modification: multiple light sources have additive effect.
2982  *
2983  */
2984 static void calc_torch(void)
2985 {
2986         int i;
2987         object_type *o_ptr;
2988         u32b f1, f2, f3;
2989
2990         /* Assume no light */
2991         p_ptr->cur_lite = 0;
2992
2993         /* Loop through all wielded items */
2994         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2995         {
2996                 o_ptr = &inventory[i];
2997
2998                 /* Examine actual lites */
2999                 if ((i == INVEN_LITE) && (o_ptr->k_idx) && (o_ptr->tval == TV_LITE))
3000                 {
3001                         if (o_ptr->name2 == EGO_LITE_DARKNESS)
3002                         {
3003                                 if (o_ptr->sval == SV_LITE_TORCH)
3004                                 {
3005                                         p_ptr->cur_lite -= 1;
3006                                 }
3007
3008                                 /* Lanterns (with fuel) provide more lite */
3009                                 else if (o_ptr->sval == SV_LITE_LANTERN)
3010                                 {
3011                                         p_ptr->cur_lite -= 2;
3012                                 }
3013
3014                                 else if (o_ptr->sval == SV_LITE_FEANOR)
3015                                 {
3016                                         p_ptr->cur_lite -= 3;
3017                                 }
3018                         }
3019                         /* Torches (with fuel) provide some lite */
3020                         else if ((o_ptr->sval == SV_LITE_TORCH) && (o_ptr->xtra4 > 0))
3021                         {
3022                                 p_ptr->cur_lite += 1;
3023                         }
3024
3025                         /* Lanterns (with fuel) provide more lite */
3026                         else if ((o_ptr->sval == SV_LITE_LANTERN) && (o_ptr->xtra4 > 0))
3027                         {
3028                                 p_ptr->cur_lite += 2;
3029                         }
3030
3031                         else if (o_ptr->sval == SV_LITE_FEANOR)
3032                         {
3033                                 p_ptr->cur_lite += 2;
3034                         }
3035
3036                         /* Artifact Lites provide permanent, bright, lite */
3037                         else if (artifact_p(o_ptr))
3038                         {
3039                                 p_ptr->cur_lite += 3;
3040                         }
3041
3042                         if (o_ptr->name2 == EGO_LITE_SHINE) p_ptr->cur_lite++;
3043                 }
3044                 else
3045                 {
3046                         /* Skip empty slots */
3047                         if (!o_ptr->k_idx) continue;
3048
3049                         /* Extract the flags */
3050                         object_flags(o_ptr, &f1, &f2, &f3);
3051
3052                         /* does this item glow? */
3053                         if (f3 & TR3_LITE)
3054                         {
3055                                 if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name1 == ART_NIGHT)) p_ptr->cur_lite--;
3056                                 else p_ptr->cur_lite++;
3057                         }
3058                 }
3059
3060         }
3061
3062         /* max radius is 5 without rewriting other code -- */
3063         /* see cave.c:update_lite() and defines.h:LITE_MAX */
3064         if (d_info[dungeon_type].flags1 & DF1_DARKNESS && p_ptr->cur_lite > 1)
3065                 p_ptr->cur_lite = 1;
3066         if (p_ptr->cur_lite > 5) p_ptr->cur_lite = 5;
3067         if (p_ptr->cur_lite < 0) p_ptr->cur_lite = 0;
3068
3069         /* check if the player doesn't have a lite source, */
3070         /* but does glow as an intrinsic.                  */
3071         if (p_ptr->cur_lite == 0 && p_ptr->lite) p_ptr->cur_lite = 1;
3072
3073         /* end experimental mods */
3074
3075         /* Reduce lite when running if requested */
3076         if (running && view_reduce_lite)
3077         {
3078                 /* Reduce the lite radius if needed */
3079                 if (p_ptr->cur_lite > 1) p_ptr->cur_lite = 1;
3080         }
3081
3082         /* Notice changes in the "lite radius" */
3083         if (p_ptr->old_lite != p_ptr->cur_lite)
3084         {
3085                 /* Update the lite */
3086                 p_ptr->update |= (PU_LITE);
3087
3088                 /* Update the monsters */
3089                 p_ptr->update |= (PU_MONSTERS);
3090
3091                 /* Remember the old lite */
3092                 p_ptr->old_lite = p_ptr->cur_lite;
3093
3094                 if ((p_ptr->cur_lite > 0) && (p_ptr->special_defense & NINJA_S_STEALTH))
3095                         set_superstealth(FALSE);
3096         }
3097 }
3098
3099
3100
3101 /*
3102  * Computes current weight limit.
3103  */
3104 static int weight_limit(void)
3105 {
3106         int i;
3107
3108         /* Weight limit based only on strength */
3109         i = adj_str_wgt[p_ptr->stat_ind[A_STR]] * 100;
3110         if (p_ptr->pclass == CLASS_BERSERKER) i = i*3/2;
3111
3112         /* Return the result */
3113         return (i);
3114 }
3115
3116
3117 bool buki_motteruka(int i)
3118 {
3119         return ((inventory[i].k_idx && inventory[i].tval >= TV_DIGGING && inventory[i].tval <= TV_SWORD) ? TRUE : FALSE);
3120 }
3121
3122 /*
3123  * Calculate the players current "state", taking into account
3124  * not only race/class intrinsics, but also objects being worn
3125  * and temporary spell effects.
3126  *
3127  * See also calc_mana() and calc_hitpoints().
3128  *
3129  * Take note of the new "speed code", in particular, a very strong
3130  * player will start slowing down as soon as he reaches 150 pounds,
3131  * but not until he reaches 450 pounds will he be half as fast as
3132  * a normal kobold.  This both hurts and helps the player, hurts
3133  * because in the old days a player could just avoid 300 pounds,
3134  * and helps because now carrying 300 pounds is not very painful.
3135  *
3136  * The "weapon" and "bow" do *not* add to the bonuses to hit or to
3137  * damage, since that would affect non-combat things.  These values
3138  * are actually added in later, at the appropriate place.
3139  *
3140  * This function induces various "status" messages.
3141  */
3142 void calc_bonuses(void)
3143 {
3144         int             i, j, hold, neutral[2];
3145         int             old_speed;
3146         int             old_telepathy;
3147         int             old_see_inv;
3148         int             old_dis_ac;
3149         int             old_dis_to_a;
3150         int             extra_blows[2];
3151         int             extra_shots;
3152         object_type     *o_ptr;
3153         u32b            f1, f2, f3;
3154         bool            omoi = FALSE;
3155         bool            yoiyami = FALSE;
3156         bool            down_saving = FALSE;
3157         bool            have_dd_s, have_dd_t, have_sw, have_kabe;
3158         bool            easy_2weapon = FALSE;
3159         s16b this_o_idx, next_o_idx = 0;
3160         player_race *tmp_rp_ptr;
3161
3162
3163         /* Save the old speed */
3164         old_speed = p_ptr->pspeed;
3165
3166         /* Save the old vision stuff */
3167         old_telepathy = p_ptr->telepathy;
3168         old_see_inv = p_ptr->see_inv;
3169
3170         /* Save the old armor class */
3171         old_dis_ac = p_ptr->dis_ac;
3172         old_dis_to_a = p_ptr->dis_to_a;
3173
3174
3175         /* Clear extra blows/shots */
3176         extra_blows[0] = extra_blows[1] = extra_shots = 0;
3177
3178         /* Clear the stat modifiers */
3179         for (i = 0; i < 6; i++) p_ptr->stat_add[i] = 0;
3180
3181
3182         /* Clear the Displayed/Real armor class */
3183         p_ptr->dis_ac = p_ptr->ac = 0;
3184
3185         /* Clear the Displayed/Real Bonuses */
3186         p_ptr->dis_to_h[0] = p_ptr->to_h[0] = 0;
3187         p_ptr->dis_to_h[1] = p_ptr->to_h[1] = 0;
3188         p_ptr->dis_to_d[0] = p_ptr->to_d[0] = 0;
3189         p_ptr->dis_to_d[1] = p_ptr->to_d[1] = 0;
3190         p_ptr->dis_to_h_b = p_ptr->to_h_b = 0;
3191         p_ptr->dis_to_a = p_ptr->to_a = 0;
3192         p_ptr->to_h_m = 0;
3193         p_ptr->to_d_m = 0;
3194
3195         /* Start with "normal" speed */
3196         p_ptr->pspeed = 110;
3197
3198         /* Start with a single blow per turn */
3199         p_ptr->num_blow[0] = 1;
3200         p_ptr->num_blow[1] = 1;
3201
3202         /* Start with a single shot per turn */
3203         p_ptr->num_fire = 100;
3204
3205         /* Reset the "xtra" tval */
3206         p_ptr->tval_xtra = 0;
3207
3208         /* Reset the "ammo" tval */
3209         p_ptr->tval_ammo = 0;
3210
3211         /* Clear all the flags */
3212         p_ptr->aggravate = FALSE;
3213         p_ptr->teleport = FALSE;
3214         p_ptr->exp_drain = FALSE;
3215         p_ptr->bless_blade = FALSE;
3216         p_ptr->xtra_might = FALSE;
3217         p_ptr->impact[0] = FALSE;
3218         p_ptr->impact[1] = FALSE;
3219         p_ptr->pass_wall = FALSE;
3220         p_ptr->kill_wall = FALSE;
3221         p_ptr->dec_mana = FALSE;
3222         p_ptr->easy_spell = FALSE;
3223         p_ptr->heavy_spell = FALSE;
3224         p_ptr->see_inv = FALSE;
3225         p_ptr->free_act = FALSE;
3226         p_ptr->slow_digest = FALSE;
3227         p_ptr->regenerate = FALSE;
3228         p_ptr->can_swim = FALSE;
3229         p_ptr->ffall = FALSE;
3230         p_ptr->hold_life = FALSE;
3231         p_ptr->telepathy = FALSE;
3232         p_ptr->lite = FALSE;
3233         p_ptr->sustain_str = FALSE;
3234         p_ptr->sustain_int = FALSE;
3235         p_ptr->sustain_wis = FALSE;
3236         p_ptr->sustain_con = FALSE;
3237         p_ptr->sustain_dex = FALSE;
3238         p_ptr->sustain_chr = FALSE;
3239         p_ptr->resist_acid = FALSE;
3240         p_ptr->resist_elec = FALSE;
3241         p_ptr->resist_fire = FALSE;
3242         p_ptr->resist_cold = FALSE;
3243         p_ptr->resist_pois = FALSE;
3244         p_ptr->resist_conf = FALSE;
3245         p_ptr->resist_sound = FALSE;
3246         p_ptr->resist_lite = FALSE;
3247         p_ptr->resist_dark = FALSE;
3248         p_ptr->resist_chaos = FALSE;
3249         p_ptr->resist_disen = FALSE;
3250         p_ptr->resist_shard = FALSE;
3251         p_ptr->resist_nexus = FALSE;
3252         p_ptr->resist_blind = FALSE;
3253         p_ptr->resist_neth = FALSE;
3254         p_ptr->resist_time = FALSE;
3255         p_ptr->resist_fear = FALSE;
3256         p_ptr->reflect = FALSE;
3257         p_ptr->sh_fire = FALSE;
3258         p_ptr->sh_elec = FALSE;
3259         p_ptr->sh_cold = FALSE;
3260         p_ptr->anti_magic = FALSE;
3261         p_ptr->anti_tele = FALSE;
3262         p_ptr->warning = FALSE;
3263         p_ptr->mighty_throw = FALSE;
3264
3265         p_ptr->immune_acid = FALSE;
3266         p_ptr->immune_elec = FALSE;
3267         p_ptr->immune_fire = FALSE;
3268         p_ptr->immune_cold = FALSE;
3269
3270         p_ptr->ryoute = FALSE;
3271         p_ptr->migite = FALSE;
3272         p_ptr->hidarite = FALSE;
3273         p_ptr->no_flowed = FALSE;
3274
3275         p_ptr->align = 0;
3276
3277         if (p_ptr->mimic_form) tmp_rp_ptr = &mimic_info[p_ptr->mimic_form];
3278         else tmp_rp_ptr = &race_info[p_ptr->prace];
3279
3280         /* Base infravision (purely racial) */
3281         p_ptr->see_infra = tmp_rp_ptr->infra;
3282
3283         /* Base skill -- disarming */
3284         p_ptr->skill_dis = tmp_rp_ptr->r_dis + cp_ptr->c_dis + ap_ptr->a_dis;
3285
3286         /* Base skill -- magic devices */
3287         p_ptr->skill_dev = tmp_rp_ptr->r_dev + cp_ptr->c_dev + ap_ptr->a_dev;
3288
3289         /* Base skill -- saving throw */
3290         p_ptr->skill_sav = tmp_rp_ptr->r_sav + cp_ptr->c_sav + ap_ptr->a_sav;
3291
3292         /* Base skill -- stealth */
3293         p_ptr->skill_stl = tmp_rp_ptr->r_stl + cp_ptr->c_stl + ap_ptr->a_stl;
3294
3295         /* Base skill -- searching ability */
3296         p_ptr->skill_srh = tmp_rp_ptr->r_srh + cp_ptr->c_srh + ap_ptr->a_srh;
3297
3298         /* Base skill -- searching frequency */
3299         p_ptr->skill_fos = tmp_rp_ptr->r_fos + cp_ptr->c_fos + ap_ptr->a_fos;
3300
3301         /* Base skill -- combat (normal) */
3302         p_ptr->skill_thn = tmp_rp_ptr->r_thn + cp_ptr->c_thn + ap_ptr->a_thn;
3303
3304         /* Base skill -- combat (shooting) */
3305         p_ptr->skill_thb = tmp_rp_ptr->r_thb + cp_ptr->c_thb + ap_ptr->a_thb;
3306
3307         /* Base skill -- combat (throwing) */
3308         p_ptr->skill_tht = tmp_rp_ptr->r_thb + cp_ptr->c_thb + ap_ptr->a_thb;
3309
3310         /* Base skill -- digging */
3311         p_ptr->skill_dig = 0;
3312
3313         if (buki_motteruka(INVEN_RARM) && (empty_hands(FALSE) & 0x00000001) && ((inventory[INVEN_RARM].weight > 99) || (inventory[INVEN_RARM].tval == TV_POLEARM)) && (!p_ptr->riding || (p_ptr->pet_extra_flags & PF_RYOUTE))) p_ptr->ryoute = TRUE;
3314         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER) || (p_ptr->pclass == CLASS_BERSERKER)) && (empty_hands(TRUE) == 3) && (!p_ptr->riding || (p_ptr->pet_extra_flags & PF_RYOUTE))) p_ptr->ryoute = TRUE;
3315         if (buki_motteruka(INVEN_RARM) || !buki_motteruka(INVEN_LARM)) p_ptr->migite = TRUE;
3316         if (buki_motteruka(INVEN_LARM)) p_ptr->hidarite = TRUE;
3317
3318         if (p_ptr->special_defense & KAMAE_MASK)
3319         {
3320                 if (empty_hands(TRUE) < 2)
3321                 {
3322                         set_action(ACTION_NONE);
3323                 }
3324         }
3325
3326         switch (p_ptr->pclass)
3327         {
3328                 case CLASS_WARRIOR:
3329                         if (p_ptr->lev > 29) p_ptr->resist_fear = TRUE;
3330                         if (p_ptr->lev > 44) p_ptr->regenerate = TRUE;
3331                         break;
3332                 case CLASS_PALADIN:
3333                         if (p_ptr->lev > 39) p_ptr->resist_fear = TRUE;
3334                         break;
3335                 case CLASS_CHAOS_WARRIOR:
3336                         if (p_ptr->lev > 29) p_ptr->resist_chaos = TRUE;
3337                         if (p_ptr->lev > 39) p_ptr->resist_fear = TRUE;
3338                         break;
3339                 case CLASS_MINDCRAFTER:
3340                         if (p_ptr->lev >  9) p_ptr->resist_fear = TRUE;
3341                         if (p_ptr->lev > 19) p_ptr->sustain_wis = TRUE;
3342                         if (p_ptr->lev > 29) p_ptr->resist_conf = TRUE;
3343                         if (p_ptr->lev > 39) p_ptr->telepathy = TRUE;
3344                         break;
3345                 case CLASS_MONK:
3346                 case CLASS_FORCETRAINER:
3347                         /* Unencumbered Monks become faster every 10 levels */
3348                         if (!(heavy_armor()))
3349                         {
3350                                 if (!((p_ptr->prace == RACE_KLACKON) ||
3351                                       (p_ptr->prace == RACE_SPRITE) ||
3352                                       (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)))
3353                                         p_ptr->pspeed += (p_ptr->lev) / 10;
3354
3355                                 /* Free action if unencumbered at level 25 */
3356                                 if  (p_ptr->lev > 24)
3357                                         p_ptr->free_act = TRUE;
3358                         }
3359                         break;
3360                 case CLASS_SORCERER:
3361                         p_ptr->to_a -= 50;
3362                         p_ptr->dis_to_a -= 50;
3363                         break;
3364                 case CLASS_BARD:
3365                         p_ptr->resist_sound = TRUE;
3366                         break;
3367                 case CLASS_SAMURAI:
3368                         if (p_ptr->lev > 29) p_ptr->resist_fear = TRUE;
3369                         break;
3370                 case CLASS_BERSERKER:
3371                         p_ptr->shero = 1;
3372                         p_ptr->sustain_str = TRUE;
3373                         p_ptr->sustain_dex = TRUE;
3374                         p_ptr->sustain_con = TRUE;
3375                         p_ptr->regenerate = TRUE;
3376                         p_ptr->free_act = TRUE;
3377                         p_ptr->pspeed += 2;
3378                         if (p_ptr->lev > 29) p_ptr->pspeed++;
3379                         if (p_ptr->lev > 39) p_ptr->pspeed++;
3380                         if (p_ptr->lev > 44) p_ptr->pspeed++;
3381                         if (p_ptr->lev > 49) p_ptr->pspeed++;
3382                         p_ptr->to_a += 10+p_ptr->lev/2;
3383                         p_ptr->dis_to_a += 10+p_ptr->lev/2;
3384                         p_ptr->skill_dig += (100+p_ptr->lev*8);
3385                         if (p_ptr->lev > 39) p_ptr->reflect = TRUE;
3386                         p_ptr->redraw |= PR_STATUS;
3387                         break;
3388                 case CLASS_MIRROR_MASTER:
3389                         if (p_ptr->lev > 39) p_ptr->reflect = TRUE;
3390                         break;
3391                 case CLASS_NINJA:
3392                         /* Unencumbered Monks become faster every 10 levels */
3393                         if (heavy_armor())
3394                         {
3395                                 p_ptr->pspeed -= (p_ptr->lev) / 10;
3396                                 p_ptr->skill_stl -= (p_ptr->lev)/10;
3397                         }
3398                         else if (!inventory[INVEN_LARM].tval || p_ptr->hidarite)
3399                         {
3400                                 p_ptr->pspeed += 3;
3401                                 if (!((p_ptr->prace == RACE_KLACKON) ||
3402                                       (p_ptr->prace == RACE_SPRITE) ||
3403                                       (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)))
3404                                         p_ptr->pspeed += (p_ptr->lev) / 10;
3405                                 p_ptr->skill_stl += (p_ptr->lev)/10;
3406
3407                                 /* Free action if unencumbered at level 25 */
3408                                 if  (p_ptr->lev > 24)
3409                                         p_ptr->free_act = TRUE;
3410                         }
3411                         if (!inventory[INVEN_LARM].tval || p_ptr->hidarite)
3412                         {
3413                                 p_ptr->to_a += p_ptr->lev/2+5;
3414                                 p_ptr->dis_to_a += p_ptr->lev/2+5;
3415                         }
3416                         p_ptr->slow_digest = TRUE;
3417                         p_ptr->resist_fear = TRUE;
3418                         if (p_ptr->lev > 19) p_ptr->resist_pois = TRUE;
3419                         if (p_ptr->lev > 24) p_ptr->sustain_dex = TRUE;
3420                         if (p_ptr->lev > 29) p_ptr->see_inv = TRUE;
3421                         if (p_ptr->lev > 44)
3422                         {
3423                                 p_ptr->oppose_pois = 1;
3424                                 p_ptr->redraw |= PR_STATUS;
3425                         }
3426                         break;
3427         }
3428
3429         /***** Races ****/
3430         if (p_ptr->mimic_form)
3431         {
3432                 switch(p_ptr->mimic_form)
3433                 {
3434                 case MIMIC_DEMON:
3435                         p_ptr->hold_life=TRUE;
3436                         p_ptr->resist_chaos=TRUE;
3437                         p_ptr->resist_neth=TRUE;
3438                         p_ptr->resist_fire=TRUE;
3439                         p_ptr->oppose_fire = 1;
3440                         p_ptr->see_inv=TRUE;
3441                         p_ptr->pspeed += 3;
3442                         p_ptr->redraw |= PR_STATUS;
3443                         p_ptr->to_a += 10;
3444                         p_ptr->dis_to_a += 10;
3445                         break;
3446                 case MIMIC_DEMON_LORD:
3447                         p_ptr->hold_life=TRUE;
3448                         p_ptr->resist_chaos=TRUE;
3449                         p_ptr->resist_neth=TRUE;
3450                         p_ptr->immune_fire=TRUE;
3451                         p_ptr->resist_acid = TRUE;
3452                         p_ptr->resist_fire=TRUE;
3453                         p_ptr->resist_cold = TRUE;
3454                         p_ptr->resist_elec = TRUE;
3455                         p_ptr->resist_pois = TRUE;
3456                         p_ptr->resist_conf = TRUE;
3457                         p_ptr->resist_disen = TRUE;
3458                         p_ptr->resist_nexus = TRUE;
3459                         p_ptr->resist_fear = TRUE;
3460                         p_ptr->sh_fire = TRUE;
3461                         p_ptr->see_inv = TRUE;
3462                         p_ptr->telepathy = TRUE;
3463                         p_ptr->ffall = TRUE;
3464                         p_ptr->kill_wall = TRUE;
3465                         p_ptr->pspeed += 5;
3466                         p_ptr->to_a += 20;
3467                         p_ptr->dis_to_a += 20;
3468                         break;
3469                 case MIMIC_VAMPIRE:
3470                         p_ptr->resist_dark = TRUE;
3471                         p_ptr->hold_life = TRUE;
3472                         p_ptr->resist_neth = TRUE;
3473                         p_ptr->resist_cold = TRUE;
3474                         p_ptr->resist_pois = TRUE;
3475                         p_ptr->see_inv = TRUE;
3476                         p_ptr->pspeed += 3;
3477                         p_ptr->to_a += 10;
3478                         p_ptr->dis_to_a += 10;
3479                         if (p_ptr->pclass != CLASS_NINJA) p_ptr->lite = TRUE;
3480                         break;
3481                 }
3482         }
3483         else
3484         {
3485         switch (p_ptr->prace)
3486         {
3487                 case RACE_ELF:
3488                         p_ptr->resist_lite = TRUE;
3489                         break;
3490                 case RACE_HOBBIT:
3491                         p_ptr->sustain_dex = TRUE;
3492                         break;
3493                 case RACE_GNOME:
3494                         p_ptr->free_act = TRUE;
3495                         break;
3496                 case RACE_DWARF:
3497                         p_ptr->resist_blind = TRUE;
3498                         break;
3499                 case RACE_HALF_ORC:
3500                         p_ptr->resist_dark = TRUE;
3501                         break;
3502                 case RACE_HALF_TROLL:
3503                         p_ptr->sustain_str = TRUE;
3504
3505                         if (p_ptr->lev > 14)
3506                         {
3507                                 /* High level trolls heal fast... */
3508                                 p_ptr->regenerate = TRUE;
3509
3510                                 if (p_ptr->pclass == CLASS_WARRIOR || p_ptr->pclass == CLASS_BERSERKER)
3511                                 {
3512                                         p_ptr->slow_digest = TRUE;
3513                                         /* Let's not make Regeneration
3514                                          * a disadvantage for the poor warriors who can
3515                                          * never learn a spell that satisfies hunger (actually
3516                                          * neither can rogues, but half-trolls are not
3517                                          * supposed to play rogues) */
3518                                 }
3519                         }
3520                         break;
3521                 case RACE_AMBERITE:
3522                         p_ptr->sustain_con = TRUE;
3523                         p_ptr->regenerate = TRUE;  /* Amberites heal fast... */
3524                         break;
3525                 case RACE_HIGH_ELF:
3526                         p_ptr->resist_lite = TRUE;
3527                         p_ptr->see_inv = TRUE;
3528                         break;
3529                 case RACE_BARBARIAN:
3530                         p_ptr->resist_fear = TRUE;
3531                         break;
3532                 case RACE_HALF_OGRE:
3533                         p_ptr->resist_dark = TRUE;
3534                         p_ptr->sustain_str = TRUE;
3535                         break;
3536                 case RACE_HALF_GIANT:
3537                         p_ptr->sustain_str = TRUE;
3538                         p_ptr->resist_shard = TRUE;
3539                         break;
3540                 case RACE_HALF_TITAN:
3541                         p_ptr->resist_chaos = TRUE;
3542                         break;
3543                 case RACE_CYCLOPS:
3544                         p_ptr->resist_sound = TRUE;
3545                         break;
3546                 case RACE_YEEK:
3547                         p_ptr->resist_acid = TRUE;
3548                         if (p_ptr->lev > 19) p_ptr->immune_acid = TRUE;
3549                         break;
3550                 case RACE_KLACKON:
3551                         p_ptr->resist_conf = TRUE;
3552                         p_ptr->resist_acid = TRUE;
3553
3554                         /* Klackons become faster */
3555                         p_ptr->pspeed += (p_ptr->lev) / 10;
3556                         break;
3557                 case RACE_KOBOLD:
3558                         p_ptr->resist_pois = TRUE;
3559                         break;
3560                 case RACE_NIBELUNG:
3561                         p_ptr->resist_disen = TRUE;
3562                         p_ptr->resist_dark = TRUE;
3563                         break;
3564                 case RACE_DARK_ELF:
3565                         p_ptr->resist_dark = TRUE;
3566                         if (p_ptr->lev > 19) p_ptr->see_inv = TRUE;
3567                         break;
3568                 case RACE_DRACONIAN:
3569                         p_ptr->ffall = TRUE;
3570                         if (p_ptr->lev >  4) p_ptr->resist_fire = TRUE;
3571                         if (p_ptr->lev >  9) p_ptr->resist_cold = TRUE;
3572                         if (p_ptr->lev > 14) p_ptr->resist_acid = TRUE;
3573                         if (p_ptr->lev > 19) p_ptr->resist_elec = TRUE;
3574                         if (p_ptr->lev > 34) p_ptr->resist_pois = TRUE;
3575                         break;
3576                 case RACE_MIND_FLAYER:
3577                         p_ptr->sustain_int = TRUE;
3578                         p_ptr->sustain_wis = TRUE;
3579                         if (p_ptr->lev > 14) p_ptr->see_inv = TRUE;
3580                         if (p_ptr->lev > 29) p_ptr->telepathy = TRUE;
3581                         break;
3582                 case RACE_IMP:
3583                         p_ptr->resist_fire = TRUE;
3584                         if (p_ptr->lev > 9) p_ptr->see_inv = TRUE;
3585                         break;
3586                 case RACE_GOLEM:
3587                         p_ptr->slow_digest = TRUE;
3588                         p_ptr->free_act = TRUE;
3589                         p_ptr->see_inv = TRUE;
3590                         p_ptr->resist_pois = TRUE;
3591                         if (p_ptr->lev > 34) p_ptr->hold_life = TRUE;
3592                         break;
3593                 case RACE_SKELETON:
3594                         p_ptr->resist_shard = TRUE;
3595                         p_ptr->hold_life = TRUE;
3596                         p_ptr->see_inv = TRUE;
3597                         p_ptr->resist_pois = TRUE;
3598                         if (p_ptr->lev > 9) p_ptr->resist_cold = TRUE;
3599                         break;
3600                 case RACE_ZOMBIE:
3601                         p_ptr->resist_neth = TRUE;
3602                         p_ptr->hold_life = TRUE;
3603                         p_ptr->see_inv = TRUE;
3604                         p_ptr->resist_pois = TRUE;
3605                         p_ptr->slow_digest = TRUE;
3606                         if (p_ptr->lev > 4) p_ptr->resist_cold = TRUE;
3607                         break;
3608                 case RACE_VAMPIRE:
3609                         p_ptr->resist_dark = TRUE;
3610                         p_ptr->hold_life = TRUE;
3611                         p_ptr->resist_neth = TRUE;
3612                         p_ptr->resist_cold = TRUE;
3613                         p_ptr->resist_pois = TRUE;
3614                         if (p_ptr->pclass != CLASS_NINJA) p_ptr->lite = TRUE;
3615                         break;
3616                 case RACE_SPECTRE:
3617                         p_ptr->ffall = TRUE;
3618                         p_ptr->free_act = TRUE;
3619                         p_ptr->resist_neth = TRUE;
3620                         p_ptr->hold_life = TRUE;
3621                         p_ptr->see_inv = TRUE;
3622                         p_ptr->resist_pois = TRUE;
3623                         p_ptr->slow_digest = TRUE;
3624                         p_ptr->resist_cold = TRUE;
3625                         p_ptr->pass_wall = TRUE;
3626                         if (p_ptr->lev > 34) p_ptr->telepathy = TRUE;
3627                         break;
3628                 case RACE_SPRITE:
3629                         p_ptr->ffall = TRUE;
3630                         p_ptr->resist_lite = TRUE;
3631
3632                         /* Sprites become faster */
3633                         p_ptr->pspeed += (p_ptr->lev) / 10;
3634                         break;
3635                 case RACE_BEASTMAN:
3636                         p_ptr->resist_conf  = TRUE;
3637                         p_ptr->resist_sound = TRUE;
3638                         break;
3639                 case RACE_ENT:
3640                         /* Ents dig like maniacs, but only with their hands. */
3641                         if (!inventory[INVEN_RARM].k_idx) 
3642                                 p_ptr->skill_dig += p_ptr->lev * 10;
3643                         /* Ents get tougher and stronger as they age, but lose dexterity. */
3644                         if (p_ptr->lev > 25) p_ptr->stat_add[A_STR]++;
3645                         if (p_ptr->lev > 40) p_ptr->stat_add[A_STR]++;
3646                         if (p_ptr->lev > 45) p_ptr->stat_add[A_STR]++;
3647
3648                         if (p_ptr->lev > 25) p_ptr->stat_add[A_DEX]--;
3649                         if (p_ptr->lev > 40) p_ptr->stat_add[A_DEX]--;
3650                         if (p_ptr->lev > 45) p_ptr->stat_add[A_DEX]--;
3651
3652                         if (p_ptr->lev > 25) p_ptr->stat_add[A_CON]++;
3653                         if (p_ptr->lev > 40) p_ptr->stat_add[A_CON]++;
3654                         if (p_ptr->lev > 45) p_ptr->stat_add[A_CON]++;
3655                         break;
3656                 case RACE_ANGEL:
3657                         p_ptr->ffall = TRUE;
3658                         p_ptr->see_inv = TRUE;
3659                         break;
3660                 case RACE_DEMON:
3661                         p_ptr->resist_fire  = TRUE;
3662                         p_ptr->resist_neth  = TRUE;
3663                         p_ptr->hold_life = TRUE;
3664                         if (p_ptr->lev > 9)
3665                                 p_ptr->see_inv = TRUE;
3666                         if (p_ptr->lev > 44)
3667                         {
3668                                 p_ptr->oppose_fire = 1;
3669                                 p_ptr->redraw |= PR_STATUS;
3670                         }
3671                         break;
3672                 case RACE_DUNADAN:
3673                         p_ptr->sustain_con = TRUE;
3674                         break;
3675                 case RACE_S_FAIRY:
3676                         p_ptr->ffall = TRUE;
3677                         break;
3678                 case RACE_KUTA:
3679                         p_ptr->resist_conf = TRUE;
3680                         break;
3681                 case RACE_ANDROID:
3682                         p_ptr->slow_digest = TRUE;
3683                         p_ptr->free_act = TRUE;
3684                         p_ptr->resist_pois = TRUE;
3685                         p_ptr->hold_life = TRUE;
3686                         break;
3687                 default:
3688                         /* Do nothing */
3689                         ;
3690         }
3691         }
3692
3693         if (p_ptr->ult_res || (p_ptr->special_defense & KATA_MUSOU))
3694         {
3695                 p_ptr->see_inv = TRUE;
3696                 p_ptr->free_act = TRUE;
3697                 p_ptr->slow_digest = TRUE;
3698                 p_ptr->regenerate = TRUE;
3699                 p_ptr->ffall = TRUE;
3700                 p_ptr->hold_life = TRUE;
3701                 p_ptr->telepathy = TRUE;
3702                 p_ptr->lite = TRUE;
3703                 p_ptr->sustain_str = TRUE;
3704                 p_ptr->sustain_int = TRUE;
3705                 p_ptr->sustain_wis = TRUE;
3706                 p_ptr->sustain_con = TRUE;
3707                 p_ptr->sustain_dex = TRUE;
3708                 p_ptr->sustain_chr = TRUE;
3709                 p_ptr->resist_acid = TRUE;
3710                 p_ptr->resist_elec = TRUE;
3711                 p_ptr->resist_fire = TRUE;
3712                 p_ptr->resist_cold = TRUE;
3713                 p_ptr->resist_pois = TRUE;
3714                 p_ptr->resist_conf = TRUE;
3715                 p_ptr->resist_sound = TRUE;
3716                 p_ptr->resist_lite = TRUE;
3717                 p_ptr->resist_dark = TRUE;
3718                 p_ptr->resist_chaos = TRUE;
3719                 p_ptr->resist_disen = TRUE;
3720                 p_ptr->resist_shard = TRUE;
3721                 p_ptr->resist_nexus = TRUE;
3722                 p_ptr->resist_blind = TRUE;
3723                 p_ptr->resist_neth = TRUE;
3724                 p_ptr->resist_fear = TRUE;
3725                 p_ptr->reflect = TRUE;
3726                 p_ptr->sh_fire = TRUE;
3727                 p_ptr->sh_elec = TRUE;
3728                 p_ptr->sh_cold = TRUE;
3729                 p_ptr->to_a += 100;
3730                 p_ptr->dis_to_a += 100;
3731         }
3732         if (p_ptr->tim_res_nether)
3733         {
3734                 p_ptr->resist_neth = TRUE;
3735         }
3736         if (p_ptr->tim_sh_fire)
3737         {
3738                 p_ptr->sh_fire = TRUE;
3739         }
3740         if (p_ptr->tim_res_time)
3741         {
3742                 p_ptr->resist_time = TRUE;
3743         }
3744
3745         /* Sexy Gal */
3746         if (p_ptr->pseikaku == SEIKAKU_SEXY) p_ptr->aggravate = TRUE;
3747
3748         /* Lucky man */
3749         if (p_ptr->pseikaku == SEIKAKU_LUCKY) p_ptr->muta3 |= MUT3_GOOD_LUCK;
3750
3751         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
3752         {
3753                 p_ptr->resist_blind = TRUE;
3754                 p_ptr->resist_conf  = TRUE;
3755                 p_ptr->hold_life = TRUE;
3756                 if (p_ptr->pclass != CLASS_NINJA) p_ptr->lite = TRUE;
3757
3758                 if ((p_ptr->prace != RACE_KLACKON) && (p_ptr->prace != RACE_SPRITE))
3759                         /* Munchkin become faster */
3760                         p_ptr->pspeed += (p_ptr->lev) / 10 + 5;
3761         }
3762
3763         if (p_ptr->riding)
3764         {
3765                 if (!(r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_PASS_WALL))
3766                         p_ptr->pass_wall = FALSE;
3767                 if (r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_KILL_WALL)
3768                         p_ptr->pass_wall = TRUE;
3769         }
3770         if (music_singing(MUSIC_WALL)) p_ptr->kill_wall = TRUE;
3771
3772         if (p_ptr->kill_wall) p_ptr->pass_wall = TRUE;
3773
3774         /* Hack -- apply racial/class stat maxes */
3775         /* Apply the racial modifiers */
3776         for (i = 0; i < 6; i++)
3777         {
3778                 /* Modify the stats for "race" */
3779                 p_ptr->stat_add[i] += (tmp_rp_ptr->r_adj[i] + cp_ptr->c_adj[i] + ap_ptr->a_adj[i]);
3780         }
3781
3782
3783         /* I'm adding the mutations here for the lack of a better place... */
3784         if (p_ptr->muta3)
3785         {
3786                 /* Hyper Strength */
3787                 if (p_ptr->muta3 & MUT3_HYPER_STR)
3788                 {
3789                         p_ptr->stat_add[A_STR] += 4;
3790                 }
3791
3792                 /* Puny */
3793                 if (p_ptr->muta3 & MUT3_PUNY)
3794                 {
3795                         p_ptr->stat_add[A_STR] -= 4;
3796                 }
3797
3798                 /* Living computer */
3799                 if (p_ptr->muta3 & MUT3_HYPER_INT)
3800                 {
3801                         p_ptr->stat_add[A_INT] += 4;
3802                         p_ptr->stat_add[A_WIS] += 4;
3803                 }
3804
3805                 /* Moronic */
3806                 if (p_ptr->muta3 & MUT3_MORONIC)
3807                 {
3808                         p_ptr->stat_add[A_INT] -= 4;
3809                         p_ptr->stat_add[A_WIS] -= 4;
3810                 }
3811
3812                 if (p_ptr->muta3 & MUT3_RESILIENT)
3813                 {
3814                         p_ptr->stat_add[A_CON] += 4;
3815                 }
3816
3817                 if (p_ptr->muta3 & MUT3_XTRA_FAT)
3818                 {
3819                         p_ptr->stat_add[A_CON] += 2;
3820                         p_ptr->pspeed -= 2;
3821                 }
3822
3823                 if (p_ptr->muta3 & MUT3_ALBINO)
3824                 {
3825                         p_ptr->stat_add[A_CON] -= 4;
3826                 }
3827
3828                 if (p_ptr->muta3 & MUT3_FLESH_ROT)
3829                 {
3830                         p_ptr->stat_add[A_CON] -= 2;
3831                         p_ptr->stat_add[A_CHR] -= 1;
3832                         p_ptr->regenerate = FALSE;
3833                         /* Cancel innate regeneration */
3834                 }
3835
3836                 if (p_ptr->muta3 & MUT3_SILLY_VOI)
3837                 {
3838                         p_ptr->stat_add[A_CHR] -= 4;
3839                 }
3840
3841                 if (p_ptr->muta3 & MUT3_BLANK_FAC)
3842                 {
3843                         p_ptr->stat_add[A_CHR] -= 1;
3844                 }
3845
3846                 if (p_ptr->muta3 & MUT3_XTRA_EYES)
3847                 {
3848                         p_ptr->skill_fos += 15;
3849                         p_ptr->skill_srh += 15;
3850                 }
3851
3852                 if (p_ptr->muta3 & MUT3_MAGIC_RES)
3853                 {
3854                         p_ptr->skill_sav += (15 + (p_ptr->lev / 5));
3855                 }
3856
3857                 if (p_ptr->muta3 & MUT3_XTRA_NOIS)
3858                 {
3859                         p_ptr->skill_stl -= 3;
3860                 }
3861
3862                 if (p_ptr->muta3 & MUT3_INFRAVIS)
3863                 {
3864                         p_ptr->see_infra += 3;
3865                 }
3866
3867                 if (p_ptr->muta3 & MUT3_XTRA_LEGS)
3868                 {
3869                         p_ptr->pspeed += 3;
3870                 }
3871
3872                 if (p_ptr->muta3 & MUT3_SHORT_LEG)
3873                 {
3874                         p_ptr->pspeed -= 3;
3875                 }
3876
3877                 if (p_ptr->muta3 & MUT3_ELEC_TOUC)
3878                 {
3879                         p_ptr->sh_elec = TRUE;
3880                 }
3881
3882                 if (p_ptr->muta3 & MUT3_FIRE_BODY)
3883                 {
3884                         p_ptr->sh_fire = TRUE;
3885                         p_ptr->lite = TRUE;
3886                 }
3887
3888                 if (p_ptr->muta3 & MUT3_WART_SKIN)
3889                 {
3890                         p_ptr->stat_add[A_CHR] -= 2;
3891                         p_ptr->to_a += 5;
3892                         p_ptr->dis_to_a += 5;
3893                 }
3894
3895                 if (p_ptr->muta3 & MUT3_SCALES)
3896                 {
3897                         p_ptr->stat_add[A_CHR] -= 1;
3898                         p_ptr->to_a += 10;
3899                         p_ptr->dis_to_a += 10;
3900                 }
3901
3902                 if (p_ptr->muta3 & MUT3_IRON_SKIN)
3903                 {
3904                         p_ptr->stat_add[A_DEX] -= 1;
3905                         p_ptr->to_a += 25;
3906                         p_ptr->dis_to_a += 25;
3907                 }
3908
3909                 if (p_ptr->muta3 & MUT3_WINGS)
3910                 {
3911                         p_ptr->ffall = TRUE;
3912                 }
3913
3914                 if (p_ptr->muta3 & MUT3_FEARLESS)
3915                 {
3916                         p_ptr->resist_fear = TRUE;
3917                 }
3918
3919                 if (p_ptr->muta3 & MUT3_REGEN)
3920                 {
3921                         p_ptr->regenerate = TRUE;
3922                 }
3923
3924                 if (p_ptr->muta3 & MUT3_ESP)
3925                 {
3926                         p_ptr->telepathy = TRUE;
3927                 }
3928
3929                 if (p_ptr->muta3 & MUT3_LIMBER)
3930                 {
3931                         p_ptr->stat_add[A_DEX] += 3;
3932                 }
3933
3934                 if (p_ptr->muta3 & MUT3_ARTHRITIS)
3935                 {
3936                         p_ptr->stat_add[A_DEX] -= 3;
3937                 }
3938
3939                 if (p_ptr->muta3 & MUT3_MOTION)
3940                 {
3941                         p_ptr->free_act = TRUE;
3942                         p_ptr->skill_stl += 1;
3943                 }
3944
3945                 if (p_ptr->muta3 & MUT3_ILL_NORM)
3946                 {
3947                         p_ptr->stat_add[A_CHR] = 0;
3948                 }
3949         }
3950
3951         if (p_ptr->tsuyoshi)
3952         {
3953                 p_ptr->stat_add[A_STR] += 4;
3954                 p_ptr->stat_add[A_CON] += 4;
3955         }
3956
3957         /* Scan the usable inventory */
3958         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
3959         {
3960                 int bonus_to_h, bonus_to_d;
3961                 o_ptr = &inventory[i];
3962
3963                 /* Skip non-objects */
3964                 if (!o_ptr->k_idx) continue;
3965                 if (o_ptr->tval == TV_CAPTURE) continue;
3966
3967                 /* Extract the item flags */
3968                 object_flags(o_ptr, &f1, &f2, &f3);
3969
3970                 /* Affect stats */
3971                 if (f1 & (TR1_STR)) p_ptr->stat_add[A_STR] += o_ptr->pval;
3972                 if (f1 & (TR1_INT)) p_ptr->stat_add[A_INT] += o_ptr->pval;
3973                 if (f1 & (TR1_WIS)) p_ptr->stat_add[A_WIS] += o_ptr->pval;
3974                 if (f1 & (TR1_DEX)) p_ptr->stat_add[A_DEX] += o_ptr->pval;
3975                 if (f1 & (TR1_CON)) p_ptr->stat_add[A_CON] += o_ptr->pval;
3976                 if (f1 & (TR1_CHR)) p_ptr->stat_add[A_CHR] += o_ptr->pval;
3977
3978                 if (f1 & (TR1_MAGIC_MASTERY))    p_ptr->skill_dev += 8*o_ptr->pval;
3979
3980                 /* Affect stealth */
3981                 if (f1 & (TR1_STEALTH)) p_ptr->skill_stl += o_ptr->pval;
3982
3983                 /* Affect searching ability (factor of five) */
3984                 if (f1 & (TR1_SEARCH)) p_ptr->skill_srh += (o_ptr->pval * 5);
3985
3986                 /* Affect searching frequency (factor of five) */
3987                 if (f1 & (TR1_SEARCH)) p_ptr->skill_fos += (o_ptr->pval * 5);
3988
3989                 /* Affect infravision */
3990                 if (f1 & (TR1_INFRA)) p_ptr->see_infra += o_ptr->pval;
3991
3992                 /* Affect digging (factor of 20) */
3993                 if (f1 & (TR1_TUNNEL)) p_ptr->skill_dig += (o_ptr->pval * 20);
3994
3995                 /* Affect speed */
3996                 if (f1 & (TR1_SPEED)) p_ptr->pspeed += o_ptr->pval;
3997
3998                 /* Affect blows */
3999                 if (f1 & (TR1_BLOWS))
4000                 {
4001                         if((i == INVEN_RARM || i == INVEN_RIGHT) && !p_ptr->ryoute) extra_blows[0] += o_ptr->pval;
4002                         else if((i == INVEN_LARM || i == INVEN_LEFT) && !p_ptr->ryoute) extra_blows[1] += o_ptr->pval;
4003                         else {extra_blows[0] += o_ptr->pval; extra_blows[1] += o_ptr->pval;}
4004                 }
4005
4006                 /* Hack -- cause earthquakes */
4007                 if (f1 & (TR1_IMPACT)) p_ptr->impact[(i == INVEN_RARM) ? 0 : 1] = TRUE;
4008
4009                 /* Boost shots */
4010                 if (f3 & (TR3_XTRA_SHOTS)) extra_shots++;
4011
4012                 /* Various flags */
4013                 if (f3 & (TR3_DEC_MANA))    p_ptr->dec_mana = TRUE;
4014                 if (f3 & (TR3_AGGRAVATE))   p_ptr->aggravate = TRUE;
4015                 if (f3 & (TR3_TELEPORT))    p_ptr->teleport = TRUE;
4016                 if (f3 & (TR3_DRAIN_EXP))   p_ptr->exp_drain = TRUE;
4017                 if (f3 & (TR3_BLESSED))     p_ptr->bless_blade = TRUE;
4018                 if (f3 & (TR3_XTRA_MIGHT))  p_ptr->xtra_might = TRUE;
4019                 if (f3 & (TR3_SLOW_DIGEST)) p_ptr->slow_digest = TRUE;
4020                 if (f3 & (TR3_REGEN))       p_ptr->regenerate = TRUE;
4021                 if (f3 & (TR3_TELEPATHY))   p_ptr->telepathy = TRUE;
4022                 if (f3 & (TR3_SEE_INVIS))   p_ptr->see_inv = TRUE;
4023                 if (f3 & (TR3_FEATHER))     p_ptr->ffall = TRUE;
4024                 if (f2 & (TR2_FREE_ACT))    p_ptr->free_act = TRUE;
4025                 if (f2 & (TR2_HOLD_LIFE))   p_ptr->hold_life = TRUE;
4026                 if (f3 & (TR3_WARNING))     p_ptr->warning = TRUE;
4027
4028                 /* Immunity flags */
4029                 if (f2 & (TR2_IM_FIRE)) p_ptr->immune_fire = TRUE;
4030                 if (f2 & (TR2_IM_ACID)) p_ptr->immune_acid = TRUE;
4031                 if (f2 & (TR2_IM_COLD)) p_ptr->immune_cold = TRUE;
4032                 if (f2 & (TR2_IM_ELEC)) p_ptr->immune_elec = TRUE;
4033
4034                 /* Resistance flags */
4035                 if (f2 & (TR2_RES_ACID))   p_ptr->resist_acid = TRUE;
4036                 if (f2 & (TR2_RES_ELEC))   p_ptr->resist_elec = TRUE;
4037                 if (f2 & (TR2_RES_FIRE))   p_ptr->resist_fire = TRUE;
4038                 if (f2 & (TR2_RES_COLD))   p_ptr->resist_cold = TRUE;
4039                 if (f2 & (TR2_RES_POIS))   p_ptr->resist_pois = TRUE;
4040                 if (f2 & (TR2_RES_FEAR))   p_ptr->resist_fear = TRUE;
4041                 if (f2 & (TR2_RES_CONF))   p_ptr->resist_conf = TRUE;
4042                 if (f2 & (TR2_RES_SOUND))  p_ptr->resist_sound = TRUE;
4043                 if (f2 & (TR2_RES_LITE))   p_ptr->resist_lite = TRUE;
4044                 if (f2 & (TR2_RES_DARK))   p_ptr->resist_dark = TRUE;
4045                 if (f2 & (TR2_RES_CHAOS))  p_ptr->resist_chaos = TRUE;
4046                 if (f2 & (TR2_RES_DISEN))  p_ptr->resist_disen = TRUE;
4047                 if (f2 & (TR2_RES_SHARDS)) p_ptr->resist_shard = TRUE;
4048                 if (f2 & (TR2_RES_NEXUS))  p_ptr->resist_nexus = TRUE;
4049                 if (f2 & (TR2_RES_BLIND))  p_ptr->resist_blind = TRUE;
4050                 if (f2 & (TR2_RES_NETHER)) p_ptr->resist_neth = TRUE;
4051
4052                 if (f2 & (TR2_REFLECT))  p_ptr->reflect = TRUE;
4053                 if (f3 & (TR3_SH_FIRE))  p_ptr->sh_fire = TRUE;
4054                 if (f3 & (TR3_SH_ELEC))  p_ptr->sh_elec = TRUE;
4055                 if (f3 & (TR3_SH_COLD))  p_ptr->sh_cold = TRUE;
4056                 if (f3 & (TR3_NO_MAGIC)) p_ptr->anti_magic = TRUE;
4057                 if (f3 & (TR3_NO_TELE))  p_ptr->anti_tele = TRUE;
4058
4059                 /* Sustain flags */
4060                 if (f2 & (TR2_SUST_STR)) p_ptr->sustain_str = TRUE;
4061                 if (f2 & (TR2_SUST_INT)) p_ptr->sustain_int = TRUE;
4062                 if (f2 & (TR2_SUST_WIS)) p_ptr->sustain_wis = TRUE;
4063                 if (f2 & (TR2_SUST_DEX)) p_ptr->sustain_dex = TRUE;
4064                 if (f2 & (TR2_SUST_CON)) p_ptr->sustain_con = TRUE;
4065                 if (f2 & (TR2_SUST_CHR)) p_ptr->sustain_chr = TRUE;
4066
4067                 if (o_ptr->name2 == EGO_YOIYAMI) yoiyami = TRUE;
4068                 if (o_ptr->name2 == EGO_2WEAPON) easy_2weapon = TRUE;
4069                 if (o_ptr->name2 == EGO_RING_RES_TIME) p_ptr->resist_time = TRUE;
4070                 if (o_ptr->name2 == EGO_RING_THROW) p_ptr->mighty_throw = TRUE;
4071                 if (o_ptr->name2 == EGO_RING_WIZARD) p_ptr->easy_spell = TRUE;
4072                 if (o_ptr->name2 == EGO_AMU_FOOL) p_ptr->heavy_spell = TRUE;
4073                 if (o_ptr->name2 == EGO_AMU_NAIVETY) down_saving = TRUE;
4074
4075                 /* Modify the base armor class */
4076                 p_ptr->ac += o_ptr->ac;
4077
4078                 /* The base armor class is always known */
4079                 p_ptr->dis_ac += o_ptr->ac;
4080
4081                 /* Apply the bonuses to armor class */
4082                 p_ptr->to_a += o_ptr->to_a;
4083
4084                 /* Apply the mental bonuses to armor class, if known */
4085                 if (object_known_p(o_ptr)) p_ptr->dis_to_a += o_ptr->to_a;
4086
4087                 /* Hack -- do not apply "weapon" bonuses */
4088                 if (i == INVEN_RARM && buki_motteruka(i)) continue;
4089                 if (i == INVEN_LARM && buki_motteruka(i)) continue;
4090
4091                 /* Hack -- do not apply "bow" bonuses */
4092                 if (i == INVEN_BOW) continue;
4093
4094                 bonus_to_h = o_ptr->to_h;
4095                 bonus_to_d = o_ptr->to_d;
4096
4097                 if (p_ptr->pclass == CLASS_NINJA)
4098                 {
4099                         if (o_ptr->to_h > 0) bonus_to_h = (o_ptr->to_h+1)/2;
4100                         if (o_ptr->to_d > 0) bonus_to_d = (o_ptr->to_d+1)/2;
4101                 }
4102
4103                 /* To Bow and Natural attack */
4104
4105                 /* Apply the bonuses to hit/damage */
4106                 p_ptr->to_h_b += bonus_to_h;
4107                 p_ptr->to_h_m += bonus_to_h;
4108                 p_ptr->to_d_m += bonus_to_d;
4109
4110                 /* Apply the mental bonuses tp hit/damage, if known */
4111                 if (object_known_p(o_ptr)) p_ptr->dis_to_h_b += bonus_to_h;
4112
4113                 /* To Melee */
4114                 if ((i == INVEN_LEFT || i == INVEN_RIGHT) && !p_ptr->ryoute)
4115                 {
4116                         /* Apply the bonuses to hit/damage */
4117                         p_ptr->to_h[i-INVEN_RIGHT] += bonus_to_h;
4118                         p_ptr->to_d[i-INVEN_RIGHT] += bonus_to_d;
4119
4120                         /* Apply the mental bonuses tp hit/damage, if known */
4121                         if (object_known_p(o_ptr))
4122                         {
4123                                 p_ptr->dis_to_h[i-INVEN_RIGHT] += bonus_to_h;
4124                                 p_ptr->dis_to_d[i-INVEN_RIGHT] += bonus_to_d;
4125                         }
4126                 }
4127                 else if (p_ptr->migite && p_ptr->hidarite)
4128                 {
4129                         /* Apply the bonuses to hit/damage */
4130                         p_ptr->to_h[0] += (bonus_to_h > 0) ? (bonus_to_h+1)/2 : bonus_to_h;
4131                         p_ptr->to_h[1] += (bonus_to_h > 0) ? bonus_to_h/2 : bonus_to_h;
4132                         p_ptr->to_d[0] += (bonus_to_d > 0) ? (bonus_to_d+1)/2 : bonus_to_d;
4133                         p_ptr->to_d[1] += (bonus_to_d > 0) ? bonus_to_d/2 : bonus_to_d;
4134
4135                         /* Apply the mental bonuses tp hit/damage, if known */
4136                         if (object_known_p(o_ptr))
4137                         {
4138                                 p_ptr->dis_to_h[0] += (bonus_to_h > 0) ? (bonus_to_h+1)/2 : bonus_to_h;
4139                                 p_ptr->dis_to_h[1] += (bonus_to_h > 0) ? bonus_to_h/2 : bonus_to_h;
4140                                 p_ptr->dis_to_d[0] += (bonus_to_d > 0) ? (bonus_to_d+1)/2 : bonus_to_d;
4141                                 p_ptr->dis_to_d[1] += (bonus_to_d > 0) ? bonus_to_d/2 : bonus_to_d;
4142                         }
4143                 }
4144                 else
4145                 {
4146                         /* Apply the bonuses to hit/damage */
4147                         p_ptr->to_h[0] += bonus_to_h;
4148                         p_ptr->to_d[0] += bonus_to_d;
4149
4150                         /* Apply the mental bonuses tp hit/damage, if known */
4151                         if (object_known_p(o_ptr))
4152                         {
4153                                 p_ptr->dis_to_h[0] += bonus_to_h;
4154                                 p_ptr->dis_to_d[0] += bonus_to_d;
4155                         }
4156                 }
4157         }
4158
4159         /* Monks get extra ac for armour _not worn_ */
4160         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER)) && !heavy_armor())
4161         {
4162                 if (!(inventory[INVEN_BODY].k_idx))
4163                 {
4164                         p_ptr->to_a += (p_ptr->lev * 3) / 2;
4165                         p_ptr->dis_to_a += (p_ptr->lev * 3) / 2;
4166                 }
4167                 if (!(inventory[INVEN_OUTER].k_idx) && (p_ptr->lev > 15))
4168                 {
4169                         p_ptr->to_a += ((p_ptr->lev - 13) / 3);
4170                         p_ptr->dis_to_a += ((p_ptr->lev - 13) / 3);
4171                 }
4172                 if (!(inventory[INVEN_LARM].k_idx) && (p_ptr->lev > 10))
4173                 {
4174                         p_ptr->to_a += ((p_ptr->lev - 8) / 3);
4175                         p_ptr->dis_to_a += ((p_ptr->lev - 8) / 3);
4176                 }
4177                 if (!(inventory[INVEN_HEAD].k_idx) && (p_ptr->lev > 4))
4178                 {
4179                         p_ptr->to_a += (p_ptr->lev - 2) / 3;
4180                         p_ptr->dis_to_a += (p_ptr->lev -2) / 3;
4181                 }
4182                 if (!(inventory[INVEN_HANDS].k_idx))
4183                 {
4184                         p_ptr->to_a += (p_ptr->lev / 2);
4185                         p_ptr->dis_to_a += (p_ptr->lev / 2);
4186                 }
4187                 if (!(inventory[INVEN_FEET].k_idx))
4188                 {
4189                         p_ptr->to_a += (p_ptr->lev / 3);
4190                         p_ptr->dis_to_a += (p_ptr->lev / 3);
4191                 }
4192                 if (p_ptr->special_defense & KAMAE_BYAKKO)
4193                 {
4194                         p_ptr->stat_add[A_STR] += 2;
4195                         p_ptr->stat_add[A_DEX] += 2;
4196                         p_ptr->stat_add[A_CON] -= 3;
4197                 }
4198                 else if (p_ptr->special_defense & KAMAE_SEIRYU)
4199                 {
4200                 }
4201                 else if (p_ptr->special_defense & KAMAE_GENBU)
4202                 {
4203                         p_ptr->stat_add[A_INT] -= 1;
4204                         p_ptr->stat_add[A_WIS] -= 1;
4205                         p_ptr->stat_add[A_DEX] -= 2;
4206                         p_ptr->stat_add[A_CON] += 3;
4207                 }
4208                 else if (p_ptr->special_defense & KAMAE_SUZAKU)
4209                 {
4210                         p_ptr->stat_add[A_STR] -= 2;
4211                         p_ptr->stat_add[A_INT] += 1;
4212                         p_ptr->stat_add[A_WIS] += 1;
4213                         p_ptr->stat_add[A_DEX] += 2;
4214                         p_ptr->stat_add[A_CON] -= 2;
4215                 }
4216         }
4217
4218         if (p_ptr->special_defense & KATA_KOUKIJIN)
4219         {
4220                 for (i = 0; i < 6; i++)
4221                         p_ptr->stat_add[i] += 5;
4222                 p_ptr->ac -= 50;
4223         }
4224
4225         /* Hack -- aura of fire also provides light */
4226         if (p_ptr->sh_fire) p_ptr->lite = TRUE;
4227
4228         /* Golems also get an intrinsic AC bonus */
4229         if ((p_ptr->prace == RACE_GOLEM) || (p_ptr->prace == RACE_ANDROID))
4230         {
4231                 p_ptr->to_a += 10 + (p_ptr->lev * 2 / 5);
4232                 p_ptr->dis_to_a += 10 + (p_ptr->lev * 2 / 5);
4233         }
4234
4235         /* Calculate stats */
4236         for (i = 0; i < 6; i++)
4237         {
4238                 int top, use, ind;
4239
4240                 /* Extract the new "stat_use" value for the stat */
4241                 top = modify_stat_value(p_ptr->stat_max[i], p_ptr->stat_add[i]);
4242
4243                 /* Notice changes */
4244                 if (p_ptr->stat_top[i] != top)
4245                 {
4246                         /* Save the new value */
4247                         p_ptr->stat_top[i] = top;
4248
4249                         /* Redisplay the stats later */
4250                         p_ptr->redraw |= (PR_STATS);
4251
4252                         /* Window stuff */
4253                         p_ptr->window |= (PW_PLAYER);
4254                 }
4255
4256
4257                 /* Extract the new "stat_use" value for the stat */
4258                 use = modify_stat_value(p_ptr->stat_cur[i], p_ptr->stat_add[i]);
4259
4260                 if ((i == A_CHR) && (p_ptr->muta3 & MUT3_ILL_NORM))
4261                 {
4262                         /* 10 to 18/90 charisma, guaranteed, based on level */
4263                         if (use < 8 + 2 * p_ptr->lev)
4264                         {
4265                                 use = 8 + 2 * p_ptr->lev;
4266                         }
4267                 }
4268
4269                 /* Notice changes */
4270                 if (p_ptr->stat_use[i] != use)
4271                 {
4272                         /* Save the new value */
4273                         p_ptr->stat_use[i] = use;
4274
4275                         /* Redisplay the stats later */
4276                         p_ptr->redraw |= (PR_STATS);
4277
4278                         /* Window stuff */
4279                         p_ptr->window |= (PW_PLAYER);
4280                 }
4281
4282
4283                 /* Values: 3, 4, ..., 17 */
4284                 if (use <= 18) ind = (use - 3);
4285
4286                 /* Ranges: 18/00-18/09, ..., 18/210-18/219 */
4287                 else if (use <= 18+219) ind = (15 + (use - 18) / 10);
4288
4289                 /* Range: 18/220+ */
4290                 else ind = (37);
4291
4292                 /* Notice changes */
4293                 if (p_ptr->stat_ind[i] != ind)
4294                 {
4295                         /* Save the new index */
4296                         p_ptr->stat_ind[i] = ind;
4297
4298                         /* Change in CON affects Hitpoints */
4299                         if (i == A_CON)
4300                         {
4301                                 p_ptr->update |= (PU_HP);
4302                         }
4303
4304                         /* Change in INT may affect Mana/Spells */
4305                         else if (i == A_INT)
4306                         {
4307                                 if (mp_ptr->spell_stat == A_INT)
4308                                 {
4309                                         p_ptr->update |= (PU_MANA | PU_SPELLS);
4310                                 }
4311                         }
4312
4313                         /* Change in WIS may affect Mana/Spells */
4314                         else if (i == A_WIS)
4315                         {
4316                                 if (mp_ptr->spell_stat == A_WIS)
4317                                 {
4318                                         p_ptr->update |= (PU_MANA | PU_SPELLS);
4319                                 }
4320                         }
4321
4322                         /* Change in WIS may affect Mana/Spells */
4323                         else if (i == A_CHR)
4324                         {
4325                                 if (mp_ptr->spell_stat == A_CHR)
4326                                 {
4327                                         p_ptr->update |= (PU_MANA | PU_SPELLS);
4328                                 }
4329                         }
4330
4331                         /* Window stuff */
4332                         p_ptr->window |= (PW_PLAYER);
4333                 }
4334         }
4335
4336
4337         /* Apply temporary "stun" */
4338         if (p_ptr->stun > 50)
4339         {
4340                 p_ptr->to_h[0] -= 20;
4341                 p_ptr->to_h[1] -= 20;
4342                 p_ptr->to_h_b  -= 20;
4343                 p_ptr->to_h_m  -= 20;
4344                 p_ptr->dis_to_h[0] -= 20;
4345                 p_ptr->dis_to_h[1] -= 20;
4346                 p_ptr->dis_to_h_b  -= 20;
4347                 p_ptr->to_d[0] -= 20;
4348                 p_ptr->to_d[1] -= 20;
4349                 p_ptr->to_d_m -= 20;
4350                 p_ptr->dis_to_d[0] -= 20;
4351                 p_ptr->dis_to_d[1] -= 20;
4352         }
4353         else if (p_ptr->stun)
4354         {
4355                 p_ptr->to_h[0] -= 5;
4356                 p_ptr->to_h[1] -= 5;
4357                 p_ptr->to_h_b -= 5;
4358                 p_ptr->to_h_m -= 5;
4359                 p_ptr->dis_to_h[0] -= 5;
4360                 p_ptr->dis_to_h[1] -= 5;
4361                 p_ptr->dis_to_h_b -= 5;
4362                 p_ptr->to_d[0] -= 5;
4363                 p_ptr->to_d[1] -= 5;
4364                 p_ptr->to_d_m -= 5;
4365                 p_ptr->dis_to_d[0] -= 5;
4366                 p_ptr->dis_to_d[1] -= 5;
4367         }
4368
4369         /* wraith_form */
4370         if (p_ptr->wraith_form)
4371         {
4372                 p_ptr->reflect = TRUE;
4373         }
4374
4375         /* Temporary blessing */
4376         if (p_ptr->blessed || music_singing(MUSIC_BLESS))
4377         {
4378                 p_ptr->to_a += 5;
4379                 p_ptr->dis_to_a += 5;
4380                 p_ptr->to_h[0] += 10;
4381                 p_ptr->to_h[1] += 10;
4382                 p_ptr->to_h_b  += 10;
4383                 p_ptr->to_h_m  += 10;
4384                 p_ptr->dis_to_h[0] += 10;
4385                 p_ptr->dis_to_h[1] += 10;
4386                 p_ptr->dis_to_h_b += 10;
4387         }
4388
4389         /* Temporary shield */
4390         if (p_ptr->tsubureru || p_ptr->shield || p_ptr->magicdef)
4391         {
4392                 p_ptr->to_a += 50;
4393                 p_ptr->dis_to_a += 50;
4394         }
4395         if (p_ptr->magicdef)
4396         {
4397                 p_ptr->resist_blind = TRUE;
4398                 p_ptr->resist_conf = TRUE;
4399                 p_ptr->reflect = TRUE;
4400                 p_ptr->free_act = TRUE;
4401                 p_ptr->ffall = TRUE;
4402         }
4403
4404         /* Temporary "Hero" */
4405         if (p_ptr->hero || music_singing(MUSIC_HERO) || music_singing(MUSIC_SHERO))
4406         {
4407                 p_ptr->to_h[0] += 12;
4408                 p_ptr->to_h[1] += 12;
4409                 p_ptr->to_h_b  += 12;
4410                 p_ptr->to_h_m  += 12;
4411                 p_ptr->dis_to_h[0] += 12;
4412                 p_ptr->dis_to_h[1] += 12;
4413                 p_ptr->dis_to_h_b  += 12;
4414         }
4415
4416         /* Temporary "Beserk" */
4417         if (p_ptr->shero)
4418         {
4419                 p_ptr->to_h[0] += 12;
4420                 p_ptr->to_h[1] += 12;
4421                 p_ptr->to_h_b  -= 12;
4422                 p_ptr->to_h_m  += 12;
4423                 p_ptr->to_d[0] += 3+(p_ptr->lev/5);
4424                 p_ptr->to_d[1] += 3+(p_ptr->lev/5);
4425                 p_ptr->to_d_m  += 3+(p_ptr->lev/5);
4426                 p_ptr->dis_to_h[0] += 12;
4427                 p_ptr->dis_to_h[1] += 12;
4428                 p_ptr->dis_to_h_b  -= 12;
4429                 p_ptr->dis_to_d[0] += 3+(p_ptr->lev/5);
4430                 p_ptr->dis_to_d[1] += 3+(p_ptr->lev/5);
4431                 p_ptr->to_a -= 10;
4432                 p_ptr->dis_to_a -= 10;
4433                 p_ptr->skill_stl -= 7;
4434                 p_ptr->skill_dev -= 20;
4435                 p_ptr->skill_sav -= 30;
4436                 p_ptr->skill_srh -= 15;
4437                 p_ptr->skill_fos -= 15;
4438                 p_ptr->skill_tht -= 20;
4439                 p_ptr->skill_dig += 30;
4440         }
4441
4442 /* Temporary "fast" */
4443         if (p_ptr->fast || music_singing(MUSIC_SPEED) || music_singing(MUSIC_SHERO))
4444         {
4445                 p_ptr->pspeed += 10;
4446         }
4447
4448         /* Temporary "slow" */
4449         if (p_ptr->slow)
4450         {
4451                 p_ptr->pspeed -= 10;
4452         }
4453
4454         /* Temporary "telepathy" */
4455         if (p_ptr->tim_esp || music_singing(MUSIC_MIND))
4456         {
4457                 p_ptr->telepathy = TRUE;
4458         }
4459
4460         if (p_ptr->ele_immune)
4461         {
4462                 if (p_ptr->special_defense & DEFENSE_ACID)
4463                         p_ptr->immune_acid = TRUE;
4464                 else if (p_ptr->special_defense & DEFENSE_ELEC)
4465                         p_ptr->immune_elec = TRUE;
4466                 else if (p_ptr->special_defense & DEFENSE_FIRE)
4467                         p_ptr->immune_fire = TRUE;
4468                 else if (p_ptr->special_defense & DEFENSE_COLD)
4469                         p_ptr->immune_cold = TRUE;
4470         }
4471
4472         /* Temporary see invisible */
4473         if (p_ptr->tim_invis)
4474         {
4475                 p_ptr->see_inv = TRUE;
4476         }
4477
4478         /* Temporary infravision boost */
4479         if (p_ptr->tim_infra)
4480         {
4481                 p_ptr->see_infra+=3;
4482         }
4483
4484         /* Temporary regeneration boost */
4485         if (p_ptr->tim_regen)
4486         {
4487                 p_ptr->regenerate = TRUE;
4488         }
4489
4490         /* Temporary levitation */
4491         if (p_ptr->tim_ffall)
4492         {
4493                 p_ptr->ffall = TRUE;
4494         }
4495
4496         /* Hack -- Hero/Shero -> Res fear */
4497         if (p_ptr->hero || p_ptr->shero || music_singing(MUSIC_HERO) || music_singing(MUSIC_SHERO))
4498         {
4499                 p_ptr->resist_fear = TRUE;
4500         }
4501
4502
4503         /* Hack -- Telepathy Change */
4504         if (p_ptr->telepathy != old_telepathy)
4505         {
4506                 p_ptr->update |= (PU_MONSTERS);
4507         }
4508
4509         /* Hack -- See Invis Change */
4510         if (p_ptr->see_inv != old_see_inv)
4511         {
4512                 p_ptr->update |= (PU_MONSTERS);
4513         }
4514
4515         /* Bloating slows the player down (a little) */
4516         if (p_ptr->food >= PY_FOOD_MAX) p_ptr->pspeed -= 10;
4517
4518         if (p_ptr->special_defense & KAMAE_SUZAKU) p_ptr->pspeed += 10;
4519
4520         if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM))
4521         {
4522                 p_ptr->to_h[0] += (skill_exp[GINOU_SUDE]-4000)/200;
4523                 p_ptr->dis_to_h[0] += (skill_exp[GINOU_SUDE]-4000)/200;
4524         }
4525
4526         if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
4527         {
4528                 int penalty1, penalty2;
4529                 penalty1 = ((100-skill_exp[GINOU_NITOURYU]/160) - (130-inventory[INVEN_RARM].weight)/8);
4530                 penalty2 = ((100-skill_exp[GINOU_NITOURYU]/160) - (130-inventory[INVEN_LARM].weight)/8);
4531                 if ((inventory[INVEN_RARM].name1 == ART_QUICKTHORN) && (inventory[INVEN_LARM].name1 == ART_TINYTHORN))
4532                 {
4533                         penalty1 = penalty1 / 2 - 5;
4534                         penalty2 = penalty2 / 2 - 5;
4535                         p_ptr->pspeed += 7;
4536                         p_ptr->to_a += 10;
4537                         p_ptr->dis_to_a += 10;
4538                 }
4539                 if (easy_2weapon)
4540                 {
4541                         if (penalty1 > 0) penalty1 /= 2;
4542                         if (penalty2 > 0) penalty2 /= 2;
4543                 }
4544                 else if ((inventory[INVEN_LARM].tval == TV_SWORD) && ((inventory[INVEN_LARM].sval == SV_MAIN_GAUCHE) || (inventory[INVEN_LARM].sval == SV_WAKIZASHI)))
4545                 {
4546                         penalty1 = MAX(0, penalty1 - 10);
4547                         penalty2 = MAX(0, penalty2 - 10);
4548                 }
4549                 if ((inventory[INVEN_RARM].name1 == ART_MUSASI_KATANA) && (inventory[INVEN_LARM].name1 == ART_MUSASI_WAKIZASI))
4550                 {
4551                         penalty1 = MIN(0, penalty1);
4552                         penalty2 = MIN(0, penalty2);
4553                 }
4554                 if (inventory[INVEN_RARM].tval == TV_POLEARM) penalty1 += 10;
4555                 if (inventory[INVEN_LARM].tval == TV_POLEARM) penalty2 += 10;
4556                 p_ptr->to_h[0] -= penalty1;
4557                 p_ptr->to_h[1] -= penalty2;
4558                 p_ptr->dis_to_h[0] -= penalty1;
4559                 p_ptr->dis_to_h[1] -= penalty2;
4560         }
4561
4562         /* Extract the current weight (in tenth pounds) */
4563         j = p_ptr->total_weight;
4564
4565         /* Extract the "weight limit" (in tenth pounds) */
4566         i = weight_limit();
4567
4568         if (p_ptr->riding)
4569         {
4570                 int speed = m_list[p_ptr->riding].mspeed;
4571                 if (m_list[p_ptr->riding].mspeed > 110)
4572                 {
4573                         p_ptr->pspeed = 110 + (s16b)((speed-110)*(skill_exp[GINOU_RIDING]*3 + p_ptr->lev*160L - 10000L)/(22000L));
4574                         if (p_ptr->pspeed < 110) p_ptr->pspeed = 110;
4575                 }
4576                 else
4577                 {
4578                         p_ptr->pspeed = speed;
4579                 }
4580                 if (m_list[p_ptr->riding].fast) p_ptr->pspeed += 10;
4581                 if (m_list[p_ptr->riding].slow) p_ptr->pspeed -= 10;
4582                 if (r_info[m_list[p_ptr->riding].r_idx].flags7 & RF7_CAN_FLY) p_ptr->ffall = TRUE;
4583                 if (r_info[m_list[p_ptr->riding].r_idx].flags7 & (RF7_CAN_SWIM | RF7_AQUATIC)) p_ptr->can_swim = TRUE;
4584
4585                 if (skill_exp[GINOU_RIDING] < 2000) j += (p_ptr->wt*3*(2000 - skill_exp[GINOU_RIDING]))/2000;
4586
4587                 i = 3000 + r_info[m_list[p_ptr->riding].r_idx].level * 50;
4588         }
4589
4590         /* XXX XXX XXX Apply "encumbrance" from weight */
4591         if (j > i/2) p_ptr->pspeed -= ((j - (i/2)) / (i / 10));
4592
4593         /* Searching slows the player down */
4594         if (p_ptr->action == ACTION_SEARCH) p_ptr->pspeed -= 10;
4595
4596         /* Actual Modifier Bonuses (Un-inflate stat bonuses) */
4597         p_ptr->to_a += ((int)(adj_dex_ta[p_ptr->stat_ind[A_DEX]]) - 128);
4598         p_ptr->to_d[0] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4599         p_ptr->to_d[1] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4600         p_ptr->to_d_m  += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4601         p_ptr->to_h[0] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4602         p_ptr->to_h[1] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4603         p_ptr->to_h_b  += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4604         p_ptr->to_h_m  += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4605         p_ptr->to_h[0] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4606         p_ptr->to_h[1] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4607         p_ptr->to_h_b  += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4608         p_ptr->to_h_m  += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4609
4610         /* Displayed Modifier Bonuses (Un-inflate stat bonuses) */
4611         p_ptr->dis_to_a += ((int)(adj_dex_ta[p_ptr->stat_ind[A_DEX]]) - 128);
4612         p_ptr->dis_to_d[0] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4613         p_ptr->dis_to_d[1] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4614         p_ptr->dis_to_h[0] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4615         p_ptr->dis_to_h[1] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4616         p_ptr->dis_to_h_b  += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4617         p_ptr->dis_to_h[0] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4618         p_ptr->dis_to_h[1] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4619         p_ptr->dis_to_h_b  += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4620
4621
4622         /* Obtain the "hold" value */
4623         hold = adj_str_hold[p_ptr->stat_ind[A_STR]];
4624
4625
4626         /* Examine the "current bow" */
4627         o_ptr = &inventory[INVEN_BOW];
4628
4629
4630         /* Assume not heavy */
4631         p_ptr->heavy_shoot = FALSE;
4632
4633         /* It is hard to carholdry a heavy bow */
4634         if (hold < o_ptr->weight / 10)
4635         {
4636                 /* Hard to wield a heavy bow */
4637                 p_ptr->to_h_b  += 2 * (hold - o_ptr->weight / 10);
4638                 p_ptr->dis_to_h_b  += 2 * (hold - o_ptr->weight / 10);
4639
4640                 /* Heavy Bow */
4641                 p_ptr->heavy_shoot = TRUE;
4642         }
4643
4644
4645         /* Compute "extra shots" if needed */
4646         if (o_ptr->k_idx)
4647         {
4648                 /* Analyze the launcher */
4649                 switch (o_ptr->sval)
4650                 {
4651                         case SV_SLING:
4652                         {
4653                                 p_ptr->tval_ammo = TV_SHOT;
4654                                 break;
4655                         }
4656
4657                         case SV_SHORT_BOW:
4658                         case SV_LONG_BOW:
4659                         case SV_NAMAKE_BOW:
4660                         {
4661                                 p_ptr->tval_ammo = TV_ARROW;
4662                                 break;
4663                         }
4664
4665                         case SV_LIGHT_XBOW:
4666                         case SV_HEAVY_XBOW:
4667                         {
4668                                 p_ptr->tval_ammo = TV_BOLT;
4669                                 break;
4670                         }
4671                         case SV_CRIMSON:
4672                         {
4673                                 p_ptr->tval_ammo = TV_NO_AMMO;
4674                                 break;
4675                         }
4676                 }
4677
4678                 /* Apply special flags */
4679                 if (o_ptr->k_idx && !p_ptr->heavy_shoot)
4680                 {
4681                         /* Extra shots */
4682                         p_ptr->num_fire += (extra_shots * 100);
4683
4684                         /* Hack -- Rangers love Bows */
4685                         if ((p_ptr->pclass == CLASS_RANGER) &&
4686                             (p_ptr->tval_ammo == TV_ARROW))
4687                         {
4688                                 p_ptr->num_fire += (p_ptr->lev * 4);
4689                         }
4690
4691                         if ((p_ptr->pclass == CLASS_CAVALRY) &&
4692                             (p_ptr->tval_ammo == TV_ARROW))
4693                         {
4694                                 p_ptr->num_fire += (p_ptr->lev * 3);
4695                         }
4696
4697                         if (p_ptr->pclass == CLASS_ARCHER)
4698                         {
4699                                 if (p_ptr->tval_ammo == TV_ARROW)
4700                                         p_ptr->num_fire += (p_ptr->lev * 6);
4701                                 else if ((p_ptr->tval_ammo == TV_BOLT) || (p_ptr->tval_ammo == TV_SHOT))
4702                                         p_ptr->num_fire += (p_ptr->lev * 4);
4703                         }
4704
4705                         /*
4706                          * Addendum -- also "Reward" high level warriors,
4707                          * with _any_ missile weapon -- TY
4708                          */
4709                         if (p_ptr->pclass == CLASS_WARRIOR &&
4710                            (p_ptr->tval_ammo <= TV_BOLT) &&
4711                            (p_ptr->tval_ammo >= TV_SHOT))
4712                         {
4713                                 p_ptr->num_fire += (p_ptr->lev * 2);
4714                         }
4715                         if ((p_ptr->pclass == CLASS_ROGUE) &&
4716                             (p_ptr->tval_ammo == TV_SHOT))
4717                         {
4718                                 p_ptr->num_fire += (p_ptr->lev * 4);
4719                         }
4720                 }
4721         }
4722
4723         if (p_ptr->ryoute)
4724                 hold *= 2;
4725
4726         for(i = 0 ; i < 2 ; i++)
4727         {
4728                 /* Examine the "main weapon" */
4729                 o_ptr = &inventory[INVEN_RARM+i];
4730
4731                 object_flags(o_ptr, &f1, &f2, &f3);
4732
4733                 /* Assume not heavy */
4734                 p_ptr->heavy_wield[i] = FALSE;
4735                 p_ptr->icky_wield[i] = FALSE;
4736                 p_ptr->riding_wield[i] = FALSE;
4737
4738                 if (!buki_motteruka(INVEN_RARM+i)) {p_ptr->num_blow[i]=1;continue;}
4739                 /* It is hard to hold a heavy weapon */
4740                 if (hold < o_ptr->weight / 10)
4741                 {
4742                         /* Hard to wield a heavy weapon */
4743                         p_ptr->to_h[i] += 2 * (hold - o_ptr->weight / 10);
4744                         p_ptr->dis_to_h[i] += 2 * (hold - o_ptr->weight / 10);
4745
4746                         /* Heavy weapon */
4747                         p_ptr->heavy_wield[i] = TRUE;
4748                 }
4749                 else if (p_ptr->ryoute && (hold < o_ptr->weight/5)) omoi = TRUE;
4750
4751                 if ((i == 1) && (o_ptr->tval == TV_SWORD) && ((o_ptr->sval == SV_MAIN_GAUCHE) || (o_ptr->sval == SV_WAKIZASHI)))
4752                 {
4753                         p_ptr->to_a += 5;
4754                         p_ptr->dis_to_a += 5;
4755                 }
4756
4757                 /* Normal weapons */
4758                 if (o_ptr->k_idx && !p_ptr->heavy_wield[i])
4759                 {
4760                         int str_index, dex_index;
4761
4762                         int num = 0, wgt = 0, mul = 0, div = 0;
4763
4764                         /* Analyze the class */
4765                         switch (p_ptr->pclass)
4766                         {
4767                                 /* Warrior */
4768                                 case CLASS_WARRIOR:
4769                                         num = 6; wgt = 70; mul = 5; break;
4770
4771                                 /* Berserker */
4772                                 case CLASS_BERSERKER:
4773                                         num = 6; wgt = 70; mul = 7; break;
4774
4775                                 /* Mage */
4776                                 case CLASS_MAGE:
4777                                 case CLASS_HIGH_MAGE:
4778                                 case CLASS_BLUE_MAGE:
4779                                         num = 3; wgt = 100; mul = 2; break;
4780
4781                                 /* Priest, Mindcrafter */
4782                                 case CLASS_PRIEST:
4783                                 case CLASS_MAGIC_EATER:
4784                                 case CLASS_MINDCRAFTER:
4785                                         num = 5; wgt = 100; mul = 3; break;
4786
4787                                 /* Rogue */
4788                                 case CLASS_ROGUE:
4789                                         num = 5; wgt = 40; mul = 3; break;
4790
4791                                 /* Ranger */
4792                                 case CLASS_RANGER:
4793                                         num = 5; wgt = 70; mul = 4; break;
4794
4795                                 /* Paladin */
4796                                 case CLASS_PALADIN:
4797                                 case CLASS_SAMURAI:
4798                                         num = 5; wgt = 70; mul = 4; break;
4799
4800                                 /* Kaji */
4801                                 case CLASS_SMITH:
4802                                         num = 5; wgt = 150; mul = 5; break;
4803
4804                                 /* Warrior-Mage */
4805                                 case CLASS_WARRIOR_MAGE:
4806                                 case CLASS_RED_MAGE:
4807                                         num = 5; wgt = 70; mul = 3; break;
4808
4809                                 /* Chaos Warrior */
4810                                 case CLASS_CHAOS_WARRIOR:
4811                                         num = 5; wgt = 70; mul = 4; break;
4812
4813                                 /* Monk */
4814                                 case CLASS_MONK:
4815                                         num = 5; wgt = 60; mul = 3; break;
4816
4817                                 /* Tourist */
4818                                 case CLASS_TOURIST:
4819                                         num = 4; wgt = 100; mul = 3; break;
4820
4821                                 /* Imitator */
4822                                 case CLASS_IMITATOR:
4823                                         num = 5; wgt = 70; mul = 4; break;
4824
4825                                 /* Beastmaster */
4826                                 case CLASS_BEASTMASTER:
4827                                         num = 5; wgt = 70; mul = 3; break;
4828
4829                                 case CLASS_CAVALRY:
4830                                         if ((p_ptr->riding) && (f2 & TR2_RIDING)) {num = 5; wgt = 70; mul = 4;}
4831                                         else {num = 5; wgt = 100; mul = 3;}
4832                                         break;
4833
4834                                 /* Sorcerer */
4835                                 case CLASS_SORCERER:
4836                                         num = 1; wgt = 1; mul = 1; break;
4837
4838                                 /* Archer, Magic eater */
4839                                 case CLASS_ARCHER:
4840                                 case CLASS_BARD:
4841                                         num = 4; wgt = 70; mul = 2; break;
4842
4843                                 /* ForceTrainer */
4844                                 case CLASS_FORCETRAINER:
4845                                         num = 4; wgt = 60; mul = 2; break;
4846
4847                                 /* Mirror Master */
4848                                 case CLASS_MIRROR_MASTER:
4849                                         num = 3; wgt = 100; mul = 3; break;
4850
4851                                 /* Ninja */
4852                                 case CLASS_NINJA:
4853                                         num = 4; wgt = 20; mul = 1; break;
4854                         }
4855
4856                         /* Enforce a minimum "weight" (tenth pounds) */
4857                         div = ((o_ptr->weight < wgt) ? wgt : o_ptr->weight);
4858
4859                         /* Access the strength vs weight */
4860                         str_index = (adj_str_blow[p_ptr->stat_ind[A_STR]] * mul / div);
4861
4862                         if (p_ptr->ryoute && !omoi) str_index++;
4863                         if (p_ptr->pclass == CLASS_NINJA) str_index = MAX(0, str_index-1);
4864
4865                         /* Maximal value */
4866                         if (str_index > 11) str_index = 11;
4867
4868                         /* Index by dexterity */
4869                         dex_index = (adj_dex_blow[p_ptr->stat_ind[A_DEX]]);
4870
4871                         /* Maximal value */
4872                         if (dex_index > 11) dex_index = 11;
4873
4874                         /* Use the blows table */
4875                         p_ptr->num_blow[i] = blows_table[str_index][dex_index];
4876
4877                         /* Maximal value */
4878                         if (p_ptr->num_blow[i] > num) p_ptr->num_blow[i] = num;
4879
4880                         /* Add in the "bonus blows" */
4881                         p_ptr->num_blow[i] += extra_blows[i];
4882
4883
4884                         if (p_ptr->pclass == CLASS_WARRIOR) p_ptr->num_blow[i] += (p_ptr->lev / 40);
4885                         else if (p_ptr->pclass == CLASS_BERSERKER)
4886                         {
4887                                 p_ptr->num_blow[i] += (p_ptr->lev / 23);
4888                         }
4889                         else if ((p_ptr->pclass == CLASS_ROGUE) && (o_ptr->weight < 50) && (p_ptr->stat_ind[A_DEX] >= 30)) p_ptr->num_blow[i] ++;
4890
4891                         if (p_ptr->special_defense & KATA_FUUJIN) p_ptr->num_blow[i] -= 1;
4892
4893                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) p_ptr->num_blow[i] = 1;
4894
4895
4896                         /* Require at least one blow */
4897                         if (p_ptr->num_blow[i] < 1) p_ptr->num_blow[i] = 1;
4898
4899                         /* Boost digging skill by weapon weight */
4900                         p_ptr->skill_dig += (o_ptr->weight / 10);
4901                 }
4902
4903                 /* Assume okay */
4904                 /* Priest weapon penalty for non-blessed edged weapons */
4905                 if ((p_ptr->pclass == CLASS_PRIEST) && (!(f3 & (TR3_BLESSED))) &&
4906                     ((o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM)))
4907                 {
4908                         /* Reduce the real bonuses */
4909                         p_ptr->to_h[i] -= 2;
4910                         p_ptr->to_d[i] -= 2;
4911
4912                         /* Reduce the mental bonuses */
4913                         p_ptr->dis_to_h[i] -= 2;
4914                         p_ptr->dis_to_d[i] -= 2;
4915
4916                         /* Icky weapon */
4917                         p_ptr->icky_wield[i] = TRUE;
4918                 }
4919                 else if (p_ptr->pclass == CLASS_BERSERKER)
4920                 {
4921                         p_ptr->to_h[i] += p_ptr->lev/5;
4922                         p_ptr->to_d[i] += p_ptr->lev/6;
4923                         p_ptr->dis_to_h[i] += p_ptr->lev/5;
4924                         p_ptr->dis_to_d[i] += p_ptr->lev/6;
4925                         if (!p_ptr->hidarite || p_ptr->ryoute)
4926                         {
4927                                 p_ptr->to_h[i] += p_ptr->lev/5;
4928                                 p_ptr->to_d[i] += p_ptr->lev/6;
4929                                 p_ptr->dis_to_h[i] += p_ptr->lev/5;
4930                                 p_ptr->dis_to_d[i] += p_ptr->lev/6;
4931                         }
4932                 }
4933                 else if (p_ptr->pclass == CLASS_SORCERER)
4934                 {
4935                         if (!((o_ptr->tval == TV_HAFTED) && ((o_ptr->sval == SV_WIZSTAFF) || (o_ptr->sval == SV_NAMAKE_HAMMER))))
4936                         {
4937                                 /* Reduce the real bonuses */
4938                                 p_ptr->to_h[i] -= 200;
4939                                 p_ptr->to_d[i] -= 200;
4940
4941                                 /* Reduce the mental bonuses */
4942                                 p_ptr->dis_to_h[i] -= 200;
4943                                 p_ptr->dis_to_d[i] -= 200;
4944
4945                                 /* Icky weapon */
4946                                 p_ptr->icky_wield[i] = TRUE;
4947                         }
4948                         else
4949                         {
4950                                 /* Reduce the real bonuses */
4951                                 p_ptr->to_h[i] -= 30;
4952                                 p_ptr->to_d[i] -= 10;
4953
4954                                 /* Reduce the mental bonuses */
4955                                 p_ptr->dis_to_h[i] -= 30;
4956                                 p_ptr->dis_to_d[i] -= 10;
4957                         }
4958                 }
4959                 if (p_ptr->riding)
4960                 {
4961                         if ((o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE)))
4962                         {
4963                                 p_ptr->to_h[i] +=15;
4964                                 p_ptr->dis_to_h[i] +=15;
4965                         }
4966                         else if (!(f2 & TR2_RIDING))
4967                         {
4968                                 int penalty;
4969                                 if ((p_ptr->pclass == CLASS_BEASTMASTER) || (p_ptr->pclass == CLASS_CAVALRY))
4970                                 {
4971                                         penalty = 5;
4972                                 }
4973                                 else
4974                                 {
4975                                         penalty = r_info[m_list[p_ptr->riding].r_idx].level - skill_exp[GINOU_RIDING] / 80;
4976                                         penalty += 30;
4977                                         if (penalty < 30) penalty = 30;
4978                                 }
4979                                 p_ptr->to_h[i] -= penalty;
4980                                 p_ptr->dis_to_h[i] -= penalty;
4981
4982                                 /* Riding weapon */
4983                                 p_ptr->riding_wield[i] = TRUE;
4984                         }
4985                 }
4986         }
4987
4988         if (p_ptr->riding)
4989         {
4990                 int penalty = 0;
4991
4992                 p_ptr->riding_ryoute = FALSE;
4993                 if (p_ptr->ryoute || !empty_hands(FALSE)) p_ptr->riding_ryoute = TRUE;
4994
4995                 if ((p_ptr->pclass == CLASS_BEASTMASTER) || (p_ptr->pclass == CLASS_CAVALRY))
4996                 {
4997                         if (p_ptr->tval_ammo != TV_ARROW) penalty = 5;
4998                 }
4999                 else
5000                 {
5001                         penalty = r_info[m_list[p_ptr->riding].r_idx].level - skill_exp[GINOU_RIDING] / 80;
5002                         penalty += 30;
5003                         if (penalty < 30) penalty = 30;
5004                 }
5005                 if (p_ptr->tval_ammo == TV_BOLT) penalty *= 2;
5006                 p_ptr->to_h_b -= penalty;
5007                 p_ptr->dis_to_h_b -= penalty;
5008         }
5009
5010         /* Different calculation for monks with empty hands */
5011         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER) || (p_ptr->pclass == CLASS_BERSERKER)) && (empty_hands(TRUE) > 1))
5012         {
5013                 int blow_base = p_ptr->lev + adj_dex_blow[p_ptr->stat_ind[A_DEX]];
5014                 p_ptr->num_blow[0] = 0;
5015
5016                 if (p_ptr->pclass == CLASS_FORCETRAINER)
5017                 {
5018                         if (blow_base > 18) p_ptr->num_blow[0]++;
5019                         if (blow_base > 31) p_ptr->num_blow[0]++;
5020                         if (blow_base > 44) p_ptr->num_blow[0]++;
5021                         if (blow_base > 58) p_ptr->num_blow[0]++;
5022                 }
5023                 else
5024                 {
5025                         if (blow_base > 12) p_ptr->num_blow[0]++;
5026                         if (blow_base > 22) p_ptr->num_blow[0]++;
5027                         if (blow_base > 31) p_ptr->num_blow[0]++;
5028                         if (blow_base > 39) p_ptr->num_blow[0]++;
5029                         if (blow_base > 46) p_ptr->num_blow[0]++;
5030                         if (blow_base > 53) p_ptr->num_blow[0]++;
5031                         if (blow_base > 59) p_ptr->num_blow[0]++;
5032                 }
5033
5034                 if (heavy_armor() && (p_ptr->pclass != CLASS_BERSERKER))
5035                         p_ptr->num_blow[0] /= 2;
5036                 else
5037                 {
5038                         p_ptr->to_h[0] += (p_ptr->lev / 3);
5039                         p_ptr->dis_to_h[0] += (p_ptr->lev / 3);
5040
5041                         p_ptr->to_d[0] += (p_ptr->lev / 6);
5042                         p_ptr->dis_to_d[0] += (p_ptr->lev / 6);
5043                 }
5044
5045                 if (p_ptr->special_defense & KAMAE_BYAKKO)
5046                 {
5047                         p_ptr->to_a -= 40;
5048                         p_ptr->dis_to_a -= 40;
5049                         
5050                 }
5051                 else if (p_ptr->special_defense & KAMAE_SEIRYU)
5052                 {
5053                         p_ptr->to_a -= 50;
5054                         p_ptr->dis_to_a -= 50;
5055                         p_ptr->resist_acid = TRUE;
5056                         p_ptr->resist_fire = TRUE;
5057                         p_ptr->resist_elec = TRUE;
5058                         p_ptr->resist_cold = TRUE;
5059                         p_ptr->resist_pois = TRUE;
5060                         p_ptr->sh_fire = TRUE;
5061                         p_ptr->sh_elec = TRUE;
5062                         p_ptr->sh_cold = TRUE;
5063                         p_ptr->ffall = TRUE;
5064                 }
5065                 else if (p_ptr->special_defense & KAMAE_GENBU)
5066                 {
5067                         p_ptr->to_a += (p_ptr->lev*p_ptr->lev)/50;
5068                         p_ptr->dis_to_a += (p_ptr->lev*p_ptr->lev)/50;
5069                         p_ptr->reflect = TRUE;
5070                         p_ptr->num_blow[0] -= 2;
5071                         if ((p_ptr->pclass == CLASS_MONK) && (p_ptr->lev > 42)) p_ptr->num_blow[0]--;
5072                         if (p_ptr->num_blow[0] < 0) p_ptr->num_blow[0] = 0;
5073                 }
5074                 else if (p_ptr->special_defense & KAMAE_SUZAKU)
5075                 {
5076                         p_ptr->to_h[0] -= (p_ptr->lev / 3);
5077                         p_ptr->to_d[0] -= (p_ptr->lev / 6);
5078
5079                         p_ptr->dis_to_h[0] -= (p_ptr->lev / 3);
5080                         p_ptr->dis_to_d[0] -= (p_ptr->lev / 6);
5081                         p_ptr->num_blow[0] /= 2;
5082                         p_ptr->ffall = TRUE;
5083                 }
5084
5085                 p_ptr->num_blow[0] += 1+extra_blows[0];
5086         }
5087
5088         monk_armour_aux = FALSE;
5089
5090         if (heavy_armor())
5091         {
5092                 monk_armour_aux = TRUE;
5093         }
5094
5095         for (i = 0 ; i < 2 ; i++)
5096         {
5097                 if(buki_motteruka(INVEN_RARM+i))
5098                 {
5099                         int tval = inventory[INVEN_RARM+i].tval - TV_BOW;
5100                         int sval = inventory[INVEN_RARM+i].sval;
5101
5102                         p_ptr->to_h[i] += (weapon_exp[tval][sval]-4000)/200;
5103                         p_ptr->dis_to_h[i] += (weapon_exp[tval][sval]-4000)/200;
5104                         if ((p_ptr->pclass == CLASS_MONK) && !(s_info[CLASS_MONK].w_max[tval][sval]))
5105                         {
5106                                 p_ptr->to_h[i] -= 40;
5107                                 p_ptr->dis_to_h[i] -= 40;
5108                                 p_ptr->icky_wield[i] = TRUE;
5109                         }
5110                         else if ((p_ptr->pclass == CLASS_FORCETRAINER) && !(s_info[CLASS_FORCETRAINER].w_max[tval][sval]))
5111                         {
5112                                 p_ptr->to_h[i] -= 40;
5113                                 p_ptr->dis_to_h[i] -= 40;
5114                                 p_ptr->icky_wield[i] = TRUE;
5115                         }
5116                         else if (p_ptr->pclass == CLASS_NINJA)
5117                         {
5118                                 if ((s_info[CLASS_NINJA].w_max[tval][sval] <= 4000) || (inventory[INVEN_LARM-i].tval == TV_SHIELD))
5119                                 {
5120                                         p_ptr->to_h[i] -= 40;
5121                                         p_ptr->dis_to_h[i] -= 40;
5122                                         p_ptr->icky_wield[i] = TRUE;
5123                                         p_ptr->num_blow[i] /= 2;
5124                                         if (p_ptr->num_blow[i] < 1) p_ptr->num_blow[i] = 1;
5125                                 }
5126                         }
5127                 }
5128         }
5129
5130         /* Temporary lightspeed */
5131         if ((p_ptr->lightspeed && !p_ptr->riding) || (p_ptr->pspeed > 209))
5132         {
5133                 p_ptr->pspeed = 209;
5134         }
5135         if (p_ptr->pspeed < 11) p_ptr->pspeed = 11;
5136
5137         /* Display the speed (if needed) */
5138         if (p_ptr->pspeed != old_speed) p_ptr->redraw |= (PR_SPEED);
5139
5140         if (yoiyami)
5141         {
5142                 if (p_ptr->to_a > (0 - p_ptr->ac))
5143                         p_ptr->to_a = 0 - p_ptr->ac;
5144                 if (p_ptr->dis_to_a > (0 - p_ptr->dis_ac))
5145                         p_ptr->dis_to_a = 0 - p_ptr->dis_ac;
5146         }
5147
5148         /* Redraw armor (if needed) */
5149         if ((p_ptr->dis_ac != old_dis_ac) || (p_ptr->dis_to_a != old_dis_to_a))
5150         {
5151                 /* Redraw */
5152                 p_ptr->redraw |= (PR_ARMOR);
5153
5154                 /* Window stuff */
5155                 p_ptr->window |= (PW_PLAYER);
5156         }
5157
5158
5159         if (p_ptr->ryoute && !omoi)
5160         {
5161                 int bonus_to_h=0, bonus_to_d=0;
5162                 bonus_to_d = ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
5163                 bonus_to_h = ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128) + ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
5164
5165                 p_ptr->to_h[0] += MAX(bonus_to_h,1);
5166                 p_ptr->dis_to_h[0] += MAX(bonus_to_h,1);
5167                 p_ptr->to_d[0] += MAX(bonus_to_d,1);
5168                 p_ptr->dis_to_d[0] += MAX(bonus_to_d,1);
5169         }
5170
5171         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER) || (p_ptr->pclass == CLASS_BERSERKER)) && (empty_hands(TRUE) == 3)) p_ptr->ryoute = FALSE;
5172
5173         /* Affect Skill -- stealth (bonus one) */
5174         p_ptr->skill_stl += 1;
5175
5176         if (p_ptr->tim_stealth || music_singing(MUSIC_STEALTH))
5177                 p_ptr->skill_stl += 99;
5178
5179         /* Affect Skill -- disarming (DEX and INT) */
5180         p_ptr->skill_dis += adj_dex_dis[p_ptr->stat_ind[A_DEX]];
5181         p_ptr->skill_dis += adj_int_dis[p_ptr->stat_ind[A_INT]];
5182
5183         /* Affect Skill -- magic devices (INT) */
5184         p_ptr->skill_dev += adj_int_dev[p_ptr->stat_ind[A_INT]];
5185
5186         /* Affect Skill -- saving throw (WIS) */
5187         p_ptr->skill_sav += adj_wis_sav[p_ptr->stat_ind[A_WIS]];
5188
5189         /* Affect Skill -- digging (STR) */
5190         p_ptr->skill_dig += adj_str_dig[p_ptr->stat_ind[A_STR]];
5191
5192         /* Affect Skill -- disarming (Level, by Class) */
5193         p_ptr->skill_dis += ((cp_ptr->x_dis * p_ptr->lev / 10) + (ap_ptr->a_dis * p_ptr->lev / 50));
5194
5195         /* Affect Skill -- magic devices (Level, by Class) */
5196         p_ptr->skill_dev += ((cp_ptr->x_dev * p_ptr->lev / 10) + (ap_ptr->a_dev * p_ptr->lev / 50));
5197
5198         /* Affect Skill -- saving throw (Level, by Class) */
5199         p_ptr->skill_sav += ((cp_ptr->x_sav * p_ptr->lev / 10) + (ap_ptr->a_sav * p_ptr->lev / 50));
5200
5201         /* Affect Skill -- stealth (Level, by Class) */
5202         p_ptr->skill_stl += (cp_ptr->x_stl * p_ptr->lev / 10);
5203
5204         /* Affect Skill -- search ability (Level, by Class) */
5205         p_ptr->skill_srh += (cp_ptr->x_srh * p_ptr->lev / 10);
5206
5207         /* Affect Skill -- search frequency (Level, by Class) */
5208         p_ptr->skill_fos += (cp_ptr->x_fos * p_ptr->lev / 10);
5209
5210         /* Affect Skill -- combat (normal) (Level, by Class) */
5211         p_ptr->skill_thn += ((cp_ptr->x_thn * p_ptr->lev / 10) + (ap_ptr->a_thn * p_ptr->lev / 50));
5212
5213         /* Affect Skill -- combat (shooting) (Level, by Class) */
5214         p_ptr->skill_thb += ((cp_ptr->x_thb * p_ptr->lev / 10) + (ap_ptr->a_thb * p_ptr->lev / 50));
5215
5216         /* Affect Skill -- combat (throwing) (Level, by Class) */
5217         p_ptr->skill_tht += ((cp_ptr->x_thb * p_ptr->lev / 10) + (ap_ptr->a_thb * p_ptr->lev / 50));
5218
5219
5220         if ((prace_is_(RACE_S_FAIRY)) && (p_ptr->pseikaku != SEIKAKU_SEXY) && p_ptr->aggravate)
5221         {
5222                 p_ptr->aggravate = FALSE;
5223                 p_ptr->skill_stl = MIN(p_ptr->skill_stl - 3, (p_ptr->skill_stl + 2) / 2);
5224         }
5225
5226         /* Limit Skill -- stealth from 0 to 30 */
5227         if (p_ptr->skill_stl > 30) p_ptr->skill_stl = 30;
5228         if (p_ptr->skill_stl < 0) p_ptr->skill_stl = 0;
5229
5230         /* Limit Skill -- digging from 1 up */
5231         if (p_ptr->skill_dig < 1) p_ptr->skill_dig = 1;
5232
5233         if (p_ptr->anti_magic && (p_ptr->skill_sav < (90 + p_ptr->lev))) p_ptr->skill_sav = 90 + p_ptr->lev;
5234
5235         if (p_ptr->tsubureru) p_ptr->skill_sav = 10;
5236
5237         if ((p_ptr->ult_res || p_ptr->resist_magic || p_ptr->magicdef) && (p_ptr->skill_sav < (95 + p_ptr->lev))) p_ptr->skill_sav = 95 + p_ptr->lev;
5238
5239         if (down_saving) p_ptr->skill_sav /= 2;
5240
5241         /* Hack -- handle "xtra" mode */
5242         if (character_xtra) return;
5243
5244         /* Take note when "heavy bow" changes */
5245         if (p_ptr->old_heavy_shoot != p_ptr->heavy_shoot)
5246         {
5247                 /* Message */
5248                 if (p_ptr->heavy_shoot)
5249                 {
5250 #ifdef JP
5251                         msg_print("¤³¤ó¤Ê½Å¤¤µÝ¤òÁõÈ÷¤·¤Æ¤¤¤ë¤Î¤ÏÂçÊѤÀ¡£");
5252 #else
5253                         msg_print("You have trouble wielding such a heavy bow.");
5254 #endif
5255
5256                 }
5257                 else if (inventory[INVEN_BOW].k_idx)
5258                 {
5259 #ifdef JP
5260                         msg_print("¤³¤ÎµÝ¤Ê¤éÁõÈ÷¤·¤Æ¤¤¤Æ¤â¿É¤¯¤Ê¤¤¡£");
5261 #else
5262                         msg_print("You have no trouble wielding your bow.");
5263 #endif
5264
5265                 }
5266                 else
5267                 {
5268 #ifdef JP
5269                         msg_print("½Å¤¤µÝ¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤ÆÂΤ¬³Ú¤Ë¤Ê¤Ã¤¿¡£");
5270 #else
5271                         msg_print("You feel relieved to put down your heavy bow.");
5272 #endif
5273
5274                 }
5275
5276                 /* Save it */
5277                 p_ptr->old_heavy_shoot = p_ptr->heavy_shoot;
5278         }
5279
5280         for(i = 0 ; i < 2 ; i++)
5281         {
5282                 /* Take note when "heavy weapon" changes */
5283                 if (p_ptr->old_heavy_wield[i] != p_ptr->heavy_wield[i])
5284                 {
5285                         /* Message */
5286                         if (p_ptr->heavy_wield[i])
5287                         {
5288 #ifdef JP
5289                                 msg_print("¤³¤ó¤Ê½Å¤¤Éð´ï¤òÁõÈ÷¤·¤Æ¤¤¤ë¤Î¤ÏÂçÊѤÀ¡£");
5290 #else
5291                                 msg_print("You have trouble wielding such a heavy weapon.");
5292 #endif
5293
5294                         }
5295                         else if (buki_motteruka(INVEN_RARM+i))
5296                         {
5297 #ifdef JP
5298                                 msg_print("¤³¤ì¤Ê¤éÁõÈ÷¤·¤Æ¤¤¤Æ¤â¿É¤¯¤Ê¤¤¡£");
5299 #else
5300                                 msg_print("You have no trouble wielding your weapon.");
5301 #endif
5302
5303                         }
5304                         else if (p_ptr->heavy_wield[1-i])
5305                         {
5306 #ifdef JP
5307                                 msg_print("¤Þ¤ÀÉð´ï¤¬½Å¤¤¡£");
5308 #else
5309                                 msg_print("You have still trouble wielding a heavy weapon.");
5310 #endif
5311
5312                         }
5313                         else
5314                         {
5315 #ifdef JP
5316                                 msg_print("½Å¤¤Éð´ï¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤ÆÂΤ¬³Ú¤Ë¤Ê¤Ã¤¿¡£");
5317 #else
5318                                 msg_print("You feel relieved to put down your heavy weapon.");
5319 #endif
5320
5321                         }
5322
5323                         /* Save it */
5324                         p_ptr->old_heavy_wield[i] = p_ptr->heavy_wield[i];
5325                 }
5326
5327                 /* Take note when "heavy weapon" changes */
5328                 if (p_ptr->old_riding_wield[i] != p_ptr->riding_wield[i])
5329                 {
5330                         /* Message */
5331                         if (p_ptr->riding_wield[i])
5332                         {
5333 #ifdef JP
5334                                 msg_print("¤³¤ÎÉð´ï¤Ï¾èÇÏÃæ¤Ë»È¤¦¤Ë¤Ï¤à¤«¤Ê¤¤¤è¤¦¤À¡£");
5335 #else
5336                                 msg_print("This weapon is not suitable for riding.");
5337 #endif
5338
5339                         }
5340                         else if (!p_ptr->riding)
5341                         {
5342 #ifdef JP
5343                                 msg_print("¤³¤ÎÉð´ï¤ÏÅÌÊâ¤Ç»È¤¤¤ä¤¹¤¤¡£");
5344 #else
5345                                 msg_print("This weapon was not suitable for riding.");
5346 #endif
5347
5348                         }
5349                         else if (buki_motteruka(INVEN_RARM+i))
5350                         {
5351 #ifdef JP
5352                                 msg_print("¤³¤ì¤Ê¤é¾èÇÏÃæ¤Ë¤Ô¤Ã¤¿¤ê¤À¡£");
5353 #else
5354                                 msg_print("This weapon is suitable for riding.");
5355 #endif
5356
5357                         }
5358                         /* Save it */
5359                         p_ptr->old_riding_wield[i] = p_ptr->riding_wield[i];
5360                 }
5361
5362                 /* Take note when "illegal weapon" changes */
5363                 if (p_ptr->old_icky_wield[i] != p_ptr->icky_wield[i])
5364                 {
5365                         /* Message */
5366                         if (p_ptr->icky_wield[i])
5367                         {
5368 #ifdef JP
5369                                 msg_print("º£¤ÎÁõÈ÷¤Ï¤É¤¦¤â¼«Ê¬¤Ë¤Õ¤µ¤ï¤·¤¯¤Ê¤¤µ¤¤¬¤¹¤ë¡£");
5370 #else
5371                                 msg_print("You do not feel comfortable with your weapon.");
5372 #endif
5373                                 if (hack_mind)
5374                                 {
5375                                         chg_virtue(V_FAITH, -1);
5376                                 }
5377                         }
5378                         else if (buki_motteruka(INVEN_RARM+i))
5379                         {
5380 #ifdef JP
5381                                 msg_print("º£¤ÎÁõÈ÷¤Ï¼«Ê¬¤Ë¤Õ¤µ¤ï¤·¤¤µ¤¤¬¤¹¤ë¡£");
5382 #else
5383                                 msg_print("You feel comfortable with your weapon.");
5384 #endif
5385
5386                         }
5387                         else
5388                         {
5389 #ifdef JP
5390                                 msg_print("ÁõÈ÷¤ò¤Ï¤º¤·¤¿¤é¿ïʬ¤Èµ¤¤¬³Ú¤Ë¤Ê¤Ã¤¿¡£");
5391 #else
5392                                 msg_print("You feel more comfortable after removing your weapon.");
5393 #endif
5394
5395                         }
5396
5397                         /* Save it */
5398                         p_ptr->old_icky_wield[i] = p_ptr->icky_wield[i];
5399                 }
5400         }
5401
5402         if (p_ptr->riding && (p_ptr->old_riding_ryoute != p_ptr->riding_ryoute))
5403         {
5404                 /* Message */
5405                 if (p_ptr->riding_ryoute)
5406                 {
5407 #ifdef JP
5408                         msg_print("ξ¼ê¤¬¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ÆÇϤòÁà¤ì¤Ê¤¤¡£");
5409 #else
5410                         msg_print("You are using both hand for fighting, and you can't control a riding pet.");
5411 #endif
5412                 }
5413                 else
5414                 {
5415 #ifdef JP
5416                         msg_print("¼ê¤¬¶õ¤¤¤ÆÇϤòÁà¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£");
5417 #else
5418                         msg_print("You began to control riding pet with one hand.");
5419 #endif
5420                 }
5421
5422                 p_ptr->old_riding_ryoute = p_ptr->riding_ryoute;
5423         }
5424
5425         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER) || (p_ptr->pclass == CLASS_NINJA)) && (monk_armour_aux != monk_notify_aux))
5426         {
5427                 if (heavy_armor())
5428                 {
5429 #ifdef JP
5430 msg_print("ÁõÈ÷¤¬½Å¤¯¤Æ¥Ð¥é¥ó¥¹¤ò¼è¤ì¤Ê¤¤¡£");
5431 #else
5432                         msg_print("The weight of your armor disrupts your balance.");
5433 #endif
5434
5435                         if (hack_mind)
5436                         {
5437                                 chg_virtue(V_HARMONY, -1);
5438                         }
5439                 }
5440                 else
5441 #ifdef JP
5442 msg_print("¥Ð¥é¥ó¥¹¤¬¤È¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£");
5443 #else
5444                         msg_print("You regain your balance.");
5445 #endif
5446
5447                 monk_notify_aux = monk_armour_aux;
5448         }
5449
5450         j = 0;
5451         p_ptr->align = friend_align;
5452
5453         /* Determine player alignment */
5454         for (i = 0; i < 8; i++)
5455         {
5456                 if ((p_ptr->vir_types[i] == V_HARMONY) || (p_ptr->vir_types[i] == V_NATURE))
5457                 {
5458                         neutral[j] = i;
5459                         j++;
5460                 }
5461                 else if (p_ptr->vir_types[i] == V_UNLIFE) p_ptr->align -= p_ptr->virtues[i];
5462                 else if (p_ptr->vir_types[i] == V_JUSTICE) p_ptr->align += (p_ptr->virtues[i]*2);
5463                 else if (p_ptr->vir_types[i] != V_CHANCE) p_ptr->align += p_ptr->virtues[i];
5464         }
5465         while (j)
5466         {
5467                 j--;
5468                 if (p_ptr->align > 0)
5469                 {
5470                         p_ptr->align -= (p_ptr->virtues[neutral[j]]/2);
5471                         if (p_ptr->align < 0) p_ptr->align = 0;
5472                 }
5473                 else if (p_ptr->align < 0)
5474                 {
5475                         p_ptr->align += (p_ptr->virtues[neutral[j]]/2);
5476                         if (p_ptr->align > 0) p_ptr->align = 0;
5477                 }
5478         }
5479         if ((inventory[INVEN_RARM].name1 == ART_IRON_BALL) || (inventory[INVEN_LARM].name1 == ART_IRON_BALL)) p_ptr->align -= 1000;
5480         if (prace_is_(RACE_ANGEL)) p_ptr->align += 200;
5481         if ((prace_is_(RACE_DEMON)) || (p_ptr->mimic_form == MIMIC_DEMON_LORD) || (p_ptr->mimic_form == MIMIC_DEMON)) p_ptr->align -= 200;
5482
5483         have_dd_s = FALSE;
5484         have_dd_t = FALSE;
5485         have_sw = FALSE;
5486         have_kabe = FALSE;
5487         for (i = 0; i < INVEN_PACK; i++)
5488         {
5489                 if ((inventory[i].tval == TV_SORCERY_BOOK) && (inventory[i].sval == 3)) have_dd_s = TRUE;
5490                 if ((inventory[i].tval == TV_TRUMP_BOOK) && (inventory[i].sval == 1)) have_dd_t = TRUE;
5491                 if ((inventory[i].tval == TV_NATURE_BOOK) && (inventory[i].sval == 2)) have_sw = TRUE;
5492                 if ((inventory[i].tval == TV_ENCHANT_BOOK) && (inventory[i].sval == 2)) have_kabe = TRUE;
5493         }
5494         for (this_o_idx = cave[py][px].o_idx; this_o_idx; this_o_idx = next_o_idx)
5495         {
5496                 object_type *o_ptr;
5497
5498                 /* Acquire object */
5499                 o_ptr = &o_list[this_o_idx];
5500
5501                 /* Acquire next object */
5502                 next_o_idx = o_ptr->next_o_idx;
5503
5504                 if ((o_ptr->tval == TV_SORCERY_BOOK) && (o_ptr->sval == 3)) have_dd_s = TRUE;
5505                 if ((o_ptr->tval == TV_TRUMP_BOOK) && (o_ptr->sval == 1)) have_dd_t = TRUE;
5506                 if ((o_ptr->tval == TV_NATURE_BOOK) && (o_ptr->sval == 2)) have_sw = TRUE;
5507                 if ((o_ptr->tval == TV_ENCHANT_BOOK) && (o_ptr->sval == 2)) have_kabe = TRUE;
5508         }
5509
5510         if ((p_ptr->pass_wall && !p_ptr->kill_wall) || p_ptr->kabenuke || p_ptr->wraith_form) p_ptr->no_flowed = TRUE;
5511 #if 0
5512         if (have_dd_s && ((p_ptr->realm1 == REALM_SORCERY) || (p_ptr->realm2 == REALM_SORCERY) || (p_ptr->pclass == CLASS_SORCERER)))
5513         {
5514                 magic_type *s_ptr = &mp_ptr->info[REALM_SORCERY-1][SPELL_DD_S];
5515                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5516         }
5517
5518         if (have_dd_t && ((p_ptr->realm1 == REALM_TRUMP) || (p_ptr->realm2 == REALM_TRUMP) || (p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE)))
5519         {
5520                 magic_type *s_ptr = &mp_ptr->info[REALM_TRUMP-1][SPELL_DD_T];
5521                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5522         }
5523 #endif
5524         if (have_sw && ((p_ptr->realm1 == REALM_NATURE) || (p_ptr->realm2 == REALM_NATURE) || (p_ptr->pclass == CLASS_SORCERER)))
5525         {
5526                 magic_type *s_ptr = &mp_ptr->info[REALM_NATURE-1][SPELL_SW];
5527                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5528         }
5529
5530         if (have_kabe && ((p_ptr->realm1 == REALM_ENCHANT) || (p_ptr->realm2 == REALM_ENCHANT) || (p_ptr->pclass == CLASS_SORCERER)))
5531         {
5532                 magic_type *s_ptr = &mp_ptr->info[REALM_ENCHANT-1][SPELL_KABE];
5533                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5534         }
5535 }
5536
5537
5538
5539 /*
5540  * Handle "p_ptr->notice"
5541  */
5542 void notice_stuff(void)
5543 {
5544         /* Notice stuff */
5545         if (!p_ptr->notice) return;
5546
5547
5548         /* Combine the pack */
5549         if (p_ptr->notice & (PN_COMBINE))
5550         {
5551                 p_ptr->notice &= ~(PN_COMBINE);
5552                 combine_pack();
5553         }
5554
5555         /* Reorder the pack */
5556         if (p_ptr->notice & (PN_REORDER))
5557         {
5558                 p_ptr->notice &= ~(PN_REORDER);
5559                 reorder_pack();
5560         }
5561 }
5562
5563
5564 /*
5565  * Handle "p_ptr->update"
5566  */
5567 void update_stuff(void)
5568 {
5569         /* Update stuff */
5570         if (!p_ptr->update) return;
5571
5572
5573         if (p_ptr->update & (PU_BONUS))
5574         {
5575                 p_ptr->update &= ~(PU_BONUS);
5576                 calc_bonuses();
5577         }
5578
5579         if (p_ptr->update & (PU_TORCH))
5580         {
5581                 p_ptr->update &= ~(PU_TORCH);
5582                 calc_torch();
5583         }
5584
5585         if (p_ptr->update & (PU_HP))
5586         {
5587                 p_ptr->update &= ~(PU_HP);
5588                 calc_hitpoints();
5589         }
5590
5591         if (p_ptr->update & (PU_MANA))
5592         {
5593                 p_ptr->update &= ~(PU_MANA);
5594                 calc_mana();
5595         }
5596
5597         if (p_ptr->update & (PU_SPELLS))
5598         {
5599                 p_ptr->update &= ~(PU_SPELLS);
5600                 calc_spells();
5601         }
5602
5603
5604         /* Character is not ready yet, no screen updates */
5605         if (!character_generated) return;
5606
5607
5608         /* Character is in "icky" mode, no screen updates */
5609         if (character_icky) return;
5610
5611
5612         if (p_ptr->update & (PU_UN_LITE))
5613         {
5614                 p_ptr->update &= ~(PU_UN_LITE);
5615                 forget_lite();
5616         }
5617
5618         if (p_ptr->update & (PU_UN_VIEW))
5619         {
5620                 p_ptr->update &= ~(PU_UN_VIEW);
5621                 forget_view();
5622         }
5623
5624         if (p_ptr->update & (PU_VIEW))
5625         {
5626                 p_ptr->update &= ~(PU_VIEW);
5627                 update_view();
5628         }
5629
5630         if (p_ptr->update & (PU_LITE))
5631         {
5632                 p_ptr->update &= ~(PU_LITE);
5633                 update_lite();
5634         }
5635
5636
5637         if (p_ptr->update & (PU_FLOW))
5638         {
5639                 p_ptr->update &= ~(PU_FLOW);
5640                 update_flow();
5641         }
5642
5643         if (p_ptr->update & (PU_MON_LITE))
5644         {
5645                 p_ptr->update &= ~(PU_MON_LITE);
5646                 update_mon_lite();
5647         }
5648
5649         if (p_ptr->update & (PU_DISTANCE))
5650         {
5651                 p_ptr->update &= ~(PU_DISTANCE);
5652                 p_ptr->update &= ~(PU_MONSTERS);
5653                 update_monsters(TRUE);
5654         }
5655
5656         if (p_ptr->update & (PU_MONSTERS))
5657         {
5658                 p_ptr->update &= ~(PU_MONSTERS);
5659                 update_monsters(FALSE);
5660         }
5661 }
5662
5663
5664 /*
5665  * Handle "p_ptr->redraw"
5666  */
5667 void redraw_stuff(void)
5668 {
5669         /* Redraw stuff */
5670         if (!p_ptr->redraw) return;
5671
5672
5673         /* Character is not ready yet, no screen updates */
5674         if (!character_generated) return;
5675
5676
5677         /* Character is in "icky" mode, no screen updates */
5678         if (character_icky) return;
5679
5680
5681
5682         /* Hack -- clear the screen */
5683         if (p_ptr->redraw & (PR_WIPE))
5684         {
5685                 p_ptr->redraw &= ~(PR_WIPE);
5686                 msg_print(NULL);
5687                 Term_clear();
5688         }
5689
5690
5691         if (p_ptr->redraw & (PR_MAP))
5692         {
5693                 p_ptr->redraw &= ~(PR_MAP);
5694                 prt_map();
5695         }
5696
5697
5698         if (p_ptr->redraw & (PR_BASIC))
5699         {
5700                 p_ptr->redraw &= ~(PR_BASIC);
5701                 p_ptr->redraw &= ~(PR_MISC | PR_TITLE | PR_STATS);
5702                 p_ptr->redraw &= ~(PR_LEV | PR_EXP | PR_GOLD);
5703                 p_ptr->redraw &= ~(PR_ARMOR | PR_HP | PR_MANA);
5704                 p_ptr->redraw &= ~(PR_DEPTH | PR_HEALTH | PR_UHEALTH);
5705                 prt_frame_basic();
5706                 prt_time();
5707                 prt_dungeon();
5708         }
5709
5710         if (p_ptr->redraw & (PR_DUNGEON))
5711         {
5712                 p_ptr->redraw &= ~(PR_DUNGEON);
5713         }
5714
5715         if (p_ptr->redraw & (PR_EQUIPPY))
5716         {
5717                 p_ptr->redraw &= ~(PR_EQUIPPY);
5718                 print_equippy(); /* To draw / delete equippy chars */
5719         }
5720
5721         if (p_ptr->redraw & (PR_MISC))
5722         {
5723                 p_ptr->redraw &= ~(PR_MISC);
5724                 prt_field(rp_ptr->title, ROW_RACE, COL_RACE);
5725 /*              prt_field(cp_ptr->title, ROW_CLASS, COL_CLASS); */
5726
5727         }
5728
5729         if (p_ptr->redraw & (PR_TITLE))
5730         {
5731                 p_ptr->redraw &= ~(PR_TITLE);
5732                 prt_title();
5733         }
5734
5735         if (p_ptr->redraw & (PR_LEV))
5736         {
5737                 p_ptr->redraw &= ~(PR_LEV);
5738                 prt_level();
5739         }
5740
5741         if (p_ptr->redraw & (PR_EXP))
5742         {
5743                 p_ptr->redraw &= ~(PR_EXP);
5744                 prt_exp();
5745         }
5746
5747         if (p_ptr->redraw & (PR_STATS))
5748         {
5749                 p_ptr->redraw &= ~(PR_STATS);
5750                 prt_stat(A_STR);
5751                 prt_stat(A_INT);
5752                 prt_stat(A_WIS);
5753                 prt_stat(A_DEX);
5754                 prt_stat(A_CON);
5755                 prt_stat(A_CHR);
5756         }
5757
5758         if (p_ptr->redraw & (PR_STATUS))
5759         {
5760                 p_ptr->redraw &= ~(PR_STATUS);
5761                 prt_status();
5762         }
5763
5764         if (p_ptr->redraw & (PR_ARMOR))
5765         {
5766                 p_ptr->redraw &= ~(PR_ARMOR);
5767                 prt_ac();
5768         }
5769
5770         if (p_ptr->redraw & (PR_HP))
5771         {
5772                 p_ptr->redraw &= ~(PR_HP);
5773                 prt_hp();
5774         }
5775
5776         if (p_ptr->redraw & (PR_MANA))
5777         {
5778                 p_ptr->redraw &= ~(PR_MANA);
5779                 prt_sp();
5780         }
5781
5782         if (p_ptr->redraw & (PR_GOLD))
5783         {
5784                 p_ptr->redraw &= ~(PR_GOLD);
5785                 prt_gold();
5786         }
5787
5788         if (p_ptr->redraw & (PR_DEPTH))
5789         {
5790                 p_ptr->redraw &= ~(PR_DEPTH);
5791                 prt_depth();
5792         }
5793
5794         if (p_ptr->redraw & (PR_HEALTH))
5795         {
5796                 p_ptr->redraw &= ~(PR_HEALTH);
5797                 health_redraw();
5798         }
5799
5800         if (p_ptr->redraw & (PR_UHEALTH))
5801         {
5802                 p_ptr->redraw &= ~(PR_UHEALTH);
5803                 riding_health_redraw();
5804         }
5805
5806
5807         if (p_ptr->redraw & (PR_EXTRA))
5808         {
5809                 p_ptr->redraw &= ~(PR_EXTRA);
5810                 p_ptr->redraw &= ~(PR_CUT | PR_STUN);
5811                 p_ptr->redraw &= ~(PR_HUNGER);
5812                 p_ptr->redraw &= ~(PR_STATE | PR_SPEED | PR_STUDY | PR_MANE | PR_STATUS);
5813                 prt_frame_extra();
5814         }
5815
5816         if (p_ptr->redraw & (PR_CUT))
5817         {
5818                 p_ptr->redraw &= ~(PR_CUT);
5819                 prt_cut();
5820         }
5821
5822         if (p_ptr->redraw & (PR_STUN))
5823         {
5824                 p_ptr->redraw &= ~(PR_STUN);
5825                 prt_stun();
5826         }
5827
5828         if (p_ptr->redraw & (PR_HUNGER))
5829         {
5830                 p_ptr->redraw &= ~(PR_HUNGER);
5831                 prt_hunger();
5832         }
5833
5834         if (p_ptr->redraw & (PR_STATE))
5835         {
5836                 p_ptr->redraw &= ~(PR_STATE);
5837                 prt_state();
5838         }
5839
5840         if (p_ptr->redraw & (PR_SPEED))
5841         {
5842                 p_ptr->redraw &= ~(PR_SPEED);
5843                 prt_speed();
5844         }
5845
5846         if (p_ptr->pclass == CLASS_IMITATOR)
5847         {
5848                 if (p_ptr->redraw & (PR_MANE))
5849                 {
5850                         p_ptr->redraw &= ~(PR_MANE);
5851                         prt_mane();
5852                 }
5853         }
5854         else if (p_ptr->redraw & (PR_STUDY))
5855         {
5856                 p_ptr->redraw &= ~(PR_STUDY);
5857                 prt_study();
5858         }
5859 }
5860
5861
5862 /*
5863  * Handle "p_ptr->window"
5864  */
5865 void window_stuff(void)
5866 {
5867         int j;
5868
5869         u32b mask = 0L;
5870
5871
5872         /* Nothing to do */
5873         if (!p_ptr->window) return;
5874
5875         /* Scan windows */
5876         for (j = 0; j < 8; j++)
5877         {
5878                 /* Save usable flags */
5879                 if (angband_term[j]) mask |= window_flag[j];
5880         }
5881
5882         /* Apply usable flags */
5883         p_ptr->window &= mask;
5884
5885         /* Nothing to do */
5886         if (!p_ptr->window) return;
5887
5888
5889         /* Display inventory */
5890         if (p_ptr->window & (PW_INVEN))
5891         {
5892                 p_ptr->window &= ~(PW_INVEN);
5893                 fix_inven();
5894         }
5895
5896         /* Display equipment */
5897         if (p_ptr->window & (PW_EQUIP))
5898         {
5899                 p_ptr->window &= ~(PW_EQUIP);
5900                 fix_equip();
5901         }
5902
5903         /* Display spell list */
5904         if (p_ptr->window & (PW_SPELL))
5905         {
5906                 p_ptr->window &= ~(PW_SPELL);
5907                 fix_spell();
5908         }
5909
5910         /* Display player */
5911         if (p_ptr->window & (PW_PLAYER))
5912         {
5913                 p_ptr->window &= ~(PW_PLAYER);
5914                 fix_player();
5915         }
5916
5917         /* Display overhead view */
5918         if (p_ptr->window & (PW_MESSAGE))
5919         {
5920                 p_ptr->window &= ~(PW_MESSAGE);
5921                 fix_message();
5922         }
5923
5924         /* Display overhead view */
5925         if (p_ptr->window & (PW_OVERHEAD))
5926         {
5927                 p_ptr->window &= ~(PW_OVERHEAD);
5928                 fix_overhead();
5929         }
5930
5931         /* Display overhead view */
5932         if (p_ptr->window & (PW_DUNGEON))
5933         {
5934                 p_ptr->window &= ~(PW_DUNGEON);
5935                 fix_dungeon();
5936         }
5937
5938         /* Display monster recall */
5939         if (p_ptr->window & (PW_MONSTER))
5940         {
5941                 p_ptr->window &= ~(PW_MONSTER);
5942                 fix_monster();
5943         }
5944
5945         /* Display object recall */
5946         if (p_ptr->window & (PW_OBJECT))
5947         {
5948                 p_ptr->window &= ~(PW_OBJECT);
5949                 fix_object();
5950         }
5951 }
5952
5953
5954 /*
5955  * Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window"
5956  */
5957 void handle_stuff(void)
5958 {
5959         /* Update stuff */
5960         if (p_ptr->update) update_stuff();
5961
5962         /* Redraw stuff */
5963         if (p_ptr->redraw) redraw_stuff();
5964
5965         /* Window stuff */
5966         if (p_ptr->window) window_stuff();
5967 }
5968
5969
5970 s16b empty_hands(bool is_monk)
5971 {
5972         s16b kaerichi = 0;
5973         if (is_monk && (p_ptr->pclass != CLASS_MONK) && (p_ptr->pclass != CLASS_FORCETRAINER) && (p_ptr->pclass != CLASS_BERSERKER)) return FALSE;
5974
5975         if (!(inventory[INVEN_RARM].k_idx)) kaerichi +=2;
5976         if (!(inventory[INVEN_LARM].k_idx)) kaerichi +=1;
5977         return kaerichi;
5978 }
5979
5980
5981 bool heavy_armor(void)
5982 {
5983         u16b monk_arm_wgt = 0;
5984
5985         if ((p_ptr->pclass != CLASS_MONK) && (p_ptr->pclass != CLASS_FORCETRAINER) && (p_ptr->pclass != CLASS_NINJA)) return FALSE;
5986
5987         /* Weight the armor */
5988         if(inventory[INVEN_RARM].tval > TV_SWORD) monk_arm_wgt += inventory[INVEN_RARM].weight;
5989         if(inventory[INVEN_LARM].tval > TV_SWORD) monk_arm_wgt += inventory[INVEN_LARM].weight;
5990         monk_arm_wgt += inventory[INVEN_BODY].weight;
5991         monk_arm_wgt += inventory[INVEN_HEAD].weight;
5992         monk_arm_wgt += inventory[INVEN_OUTER].weight;
5993         monk_arm_wgt += inventory[INVEN_HANDS].weight;
5994         monk_arm_wgt += inventory[INVEN_FEET].weight;
5995
5996         return (monk_arm_wgt > (100 + (p_ptr->lev * 4)));
5997 }
5998
5999 int number_of_quests(void)
6000 {
6001         int i, j;
6002
6003         /* Clear the counter */
6004         i = 0;
6005
6006         for (j = MIN_RANDOM_QUEST; j < MAX_RANDOM_QUEST+1; j++)
6007         {
6008                 if (quest[j].status != QUEST_STATUS_UNTAKEN)
6009                 {
6010                         /* Increment count of quests taken. */
6011                         i++;
6012                 }
6013         }
6014
6015         /* Return the number of quests taken */
6016         return (i);
6017 }