OSDN Git Service

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