OSDN Git Service

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