OSDN Git Service

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