OSDN Git Service

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