OSDN Git Service

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