OSDN Git Service

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