OSDN Git Service

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