OSDN Git Service

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