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 (IS_TIM_ESP()) 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 (IS_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 (IS_HERO()) ADD_FLG(BAR_HEROISM);
517
518         /* Super Heroism / berserk */
519         if (p_ptr->shero) ADD_FLG(BAR_BERSERK);
520
521         /* Blessed */
522         if (IS_BLESSED()) 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 (IS_OPPOSE_ACID()) ADD_FLG(BAR_RESACID);
536
537         /* Oppose Lightning */
538         if (p_ptr->special_defense & DEFENSE_ELEC) ADD_FLG(BAR_IMMELEC);
539         if (IS_OPPOSE_ELEC()) ADD_FLG(BAR_RESELEC);
540
541         /* Oppose Fire */
542         if (p_ptr->special_defense & DEFENSE_FIRE) ADD_FLG(BAR_IMMFIRE);
543         if (IS_OPPOSE_FIRE()) ADD_FLG(BAR_RESFIRE);
544
545         /* Oppose Cold */
546         if (p_ptr->special_defense & DEFENSE_COLD) ADD_FLG(BAR_IMMCOLD);
547         if (IS_OPPOSE_COLD()) ADD_FLG(BAR_RESCOLD);
548
549         /* Oppose Poison */
550         if (IS_OPPOSE_POIS()) 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         if (p_ptr->tim_sh_fire) ADD_FLG(BAR_SHFIRE);
590
591         /* tim stealth */
592         if (IS_TIM_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 = IS_FAST();
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 (IS_HERO()) 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 #if 0
3015         bool            have_dd_s = FALSE, have_dd_t = FALSE;
3016 #endif
3017         bool            have_sw = FALSE, have_kabe = FALSE;
3018         bool            easy_2weapon = FALSE;
3019         s16b this_o_idx, next_o_idx = 0;
3020         player_race *tmp_rp_ptr;
3021
3022
3023         /* Save the old speed */
3024         old_speed = p_ptr->pspeed;
3025
3026         /* Save the old vision stuff */
3027         old_telepathy = p_ptr->telepathy;
3028         old_esp_animal = p_ptr->esp_animal;
3029         old_esp_undead = p_ptr->esp_undead;
3030         old_esp_demon = p_ptr->esp_demon;
3031         old_esp_orc = p_ptr->esp_orc;
3032         old_esp_troll = p_ptr->esp_troll;
3033         old_esp_giant = p_ptr->esp_giant;
3034         old_esp_dragon = p_ptr->esp_dragon;
3035         old_esp_human = p_ptr->esp_human;
3036         old_esp_evil = p_ptr->esp_evil;
3037         old_esp_good = p_ptr->esp_good;
3038         old_esp_nonliving = p_ptr->esp_nonliving;
3039         old_esp_unique = p_ptr->esp_unique;
3040
3041         old_see_inv = p_ptr->see_inv;
3042
3043         /* Save the old armor class */
3044         old_dis_ac = p_ptr->dis_ac;
3045         old_dis_to_a = p_ptr->dis_to_a;
3046
3047
3048         /* Clear extra blows/shots */
3049         extra_blows[0] = extra_blows[1] = extra_shots = 0;
3050
3051         /* Clear the stat modifiers */
3052         for (i = 0; i < 6; i++) p_ptr->stat_add[i] = 0;
3053
3054
3055         /* Clear the Displayed/Real armor class */
3056         p_ptr->dis_ac = p_ptr->ac = 0;
3057
3058         /* Clear the Displayed/Real Bonuses */
3059         p_ptr->dis_to_h[0] = p_ptr->to_h[0] = 0;
3060         p_ptr->dis_to_h[1] = p_ptr->to_h[1] = 0;
3061         p_ptr->dis_to_d[0] = p_ptr->to_d[0] = 0;
3062         p_ptr->dis_to_d[1] = p_ptr->to_d[1] = 0;
3063         p_ptr->dis_to_h_b = p_ptr->to_h_b = 0;
3064         p_ptr->dis_to_a = p_ptr->to_a = 0;
3065         p_ptr->to_h_m = 0;
3066         p_ptr->to_d_m = 0;
3067
3068         p_ptr->to_m_chance = 0;
3069
3070         /* Start with "normal" speed */
3071         p_ptr->pspeed = 110;
3072
3073         /* Start with a single blow per turn */
3074         p_ptr->num_blow[0] = 1;
3075         p_ptr->num_blow[1] = 1;
3076
3077         /* Start with a single shot per turn */
3078         p_ptr->num_fire = 100;
3079
3080         /* Reset the "xtra" tval */
3081         p_ptr->tval_xtra = 0;
3082
3083         /* Reset the "ammo" tval */
3084         p_ptr->tval_ammo = 0;
3085
3086         /* Clear all the flags */
3087         p_ptr->cursed = 0L;
3088         p_ptr->bless_blade = FALSE;
3089         p_ptr->xtra_might = FALSE;
3090         p_ptr->impact[0] = FALSE;
3091         p_ptr->impact[1] = FALSE;
3092         p_ptr->pass_wall = FALSE;
3093         p_ptr->kill_wall = FALSE;
3094         p_ptr->dec_mana = FALSE;
3095         p_ptr->easy_spell = FALSE;
3096         p_ptr->heavy_spell = FALSE;
3097         p_ptr->see_inv = FALSE;
3098         p_ptr->free_act = FALSE;
3099         p_ptr->slow_digest = FALSE;
3100         p_ptr->regenerate = FALSE;
3101         p_ptr->can_swim = FALSE;
3102         p_ptr->ffall = FALSE;
3103         p_ptr->hold_life = FALSE;
3104         p_ptr->telepathy = FALSE;
3105         p_ptr->esp_animal = FALSE;
3106         p_ptr->esp_undead = FALSE;
3107         p_ptr->esp_demon = FALSE;
3108         p_ptr->esp_orc = FALSE;
3109         p_ptr->esp_troll = FALSE;
3110         p_ptr->esp_giant = FALSE;
3111         p_ptr->esp_dragon = FALSE;
3112         p_ptr->esp_human = FALSE;
3113         p_ptr->esp_evil = FALSE;
3114         p_ptr->esp_good = FALSE;
3115         p_ptr->esp_nonliving = FALSE;
3116         p_ptr->esp_unique = FALSE;
3117         p_ptr->lite = FALSE;
3118         p_ptr->sustain_str = FALSE;
3119         p_ptr->sustain_int = FALSE;
3120         p_ptr->sustain_wis = FALSE;
3121         p_ptr->sustain_con = FALSE;
3122         p_ptr->sustain_dex = FALSE;
3123         p_ptr->sustain_chr = FALSE;
3124         p_ptr->resist_acid = FALSE;
3125         p_ptr->resist_elec = FALSE;
3126         p_ptr->resist_fire = FALSE;
3127         p_ptr->resist_cold = FALSE;
3128         p_ptr->resist_pois = FALSE;
3129         p_ptr->resist_conf = FALSE;
3130         p_ptr->resist_sound = FALSE;
3131         p_ptr->resist_lite = FALSE;
3132         p_ptr->resist_dark = FALSE;
3133         p_ptr->resist_chaos = FALSE;
3134         p_ptr->resist_disen = FALSE;
3135         p_ptr->resist_shard = FALSE;
3136         p_ptr->resist_nexus = FALSE;
3137         p_ptr->resist_blind = FALSE;
3138         p_ptr->resist_neth = FALSE;
3139         p_ptr->resist_time = FALSE;
3140         p_ptr->resist_fear = FALSE;
3141         p_ptr->reflect = FALSE;
3142         p_ptr->sh_fire = FALSE;
3143         p_ptr->sh_elec = FALSE;
3144         p_ptr->sh_cold = FALSE;
3145         p_ptr->anti_magic = FALSE;
3146         p_ptr->anti_tele = FALSE;
3147         p_ptr->warning = FALSE;
3148         p_ptr->mighty_throw = FALSE;
3149
3150         p_ptr->immune_acid = FALSE;
3151         p_ptr->immune_elec = FALSE;
3152         p_ptr->immune_fire = FALSE;
3153         p_ptr->immune_cold = FALSE;
3154
3155         p_ptr->ryoute = FALSE;
3156         p_ptr->migite = FALSE;
3157         p_ptr->hidarite = FALSE;
3158         p_ptr->no_flowed = FALSE;
3159
3160         p_ptr->align = 0;
3161
3162         if (p_ptr->mimic_form) tmp_rp_ptr = &mimic_info[p_ptr->mimic_form];
3163         else tmp_rp_ptr = &race_info[p_ptr->prace];
3164
3165         /* Base infravision (purely racial) */
3166         p_ptr->see_infra = tmp_rp_ptr->infra;
3167
3168         /* Base skill -- disarming */
3169         p_ptr->skill_dis = tmp_rp_ptr->r_dis + cp_ptr->c_dis + ap_ptr->a_dis;
3170
3171         /* Base skill -- magic devices */
3172         p_ptr->skill_dev = tmp_rp_ptr->r_dev + cp_ptr->c_dev + ap_ptr->a_dev;
3173
3174         /* Base skill -- saving throw */
3175         p_ptr->skill_sav = tmp_rp_ptr->r_sav + cp_ptr->c_sav + ap_ptr->a_sav;
3176
3177         /* Base skill -- stealth */
3178         p_ptr->skill_stl = tmp_rp_ptr->r_stl + cp_ptr->c_stl + ap_ptr->a_stl;
3179
3180         /* Base skill -- searching ability */
3181         p_ptr->skill_srh = tmp_rp_ptr->r_srh + cp_ptr->c_srh + ap_ptr->a_srh;
3182
3183         /* Base skill -- searching frequency */
3184         p_ptr->skill_fos = tmp_rp_ptr->r_fos + cp_ptr->c_fos + ap_ptr->a_fos;
3185
3186         /* Base skill -- combat (normal) */
3187         p_ptr->skill_thn = tmp_rp_ptr->r_thn + cp_ptr->c_thn + ap_ptr->a_thn;
3188
3189         /* Base skill -- combat (shooting) */
3190         p_ptr->skill_thb = tmp_rp_ptr->r_thb + cp_ptr->c_thb + ap_ptr->a_thb;
3191
3192         /* Base skill -- combat (throwing) */
3193         p_ptr->skill_tht = tmp_rp_ptr->r_thb + cp_ptr->c_thb + ap_ptr->a_thb;
3194
3195         /* Base skill -- digging */
3196         p_ptr->skill_dig = 0;
3197
3198         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;
3199         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;
3200         if (buki_motteruka(INVEN_RARM) || !buki_motteruka(INVEN_LARM)) p_ptr->migite = TRUE;
3201         if (buki_motteruka(INVEN_LARM)) p_ptr->hidarite = TRUE;
3202
3203         if (p_ptr->special_defense & KAMAE_MASK)
3204         {
3205                 if (empty_hands(TRUE) < 2)
3206                 {
3207                         set_action(ACTION_NONE);
3208                 }
3209         }
3210
3211         switch (p_ptr->pclass)
3212         {
3213                 case CLASS_WARRIOR:
3214                         if (p_ptr->lev > 29) p_ptr->resist_fear = TRUE;
3215                         if (p_ptr->lev > 44) p_ptr->regenerate = TRUE;
3216                         break;
3217                 case CLASS_PALADIN:
3218                         if (p_ptr->lev > 39) p_ptr->resist_fear = TRUE;
3219                         break;
3220                 case CLASS_CHAOS_WARRIOR:
3221                         if (p_ptr->lev > 29) p_ptr->resist_chaos = TRUE;
3222                         if (p_ptr->lev > 39) p_ptr->resist_fear = TRUE;
3223                         break;
3224                 case CLASS_MINDCRAFTER:
3225                         if (p_ptr->lev >  9) p_ptr->resist_fear = TRUE;
3226                         if (p_ptr->lev > 19) p_ptr->sustain_wis = TRUE;
3227                         if (p_ptr->lev > 29) p_ptr->resist_conf = TRUE;
3228                         if (p_ptr->lev > 39) p_ptr->telepathy = TRUE;
3229                         break;
3230                 case CLASS_MONK:
3231                 case CLASS_FORCETRAINER:
3232                         /* Unencumbered Monks become faster every 10 levels */
3233                         if (!(heavy_armor()))
3234                         {
3235                                 if (!(prace_is_(RACE_KLACKON) ||
3236                                       prace_is_(RACE_SPRITE) ||
3237                                       (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)))
3238                                         p_ptr->pspeed += (p_ptr->lev) / 10;
3239
3240                                 /* Free action if unencumbered at level 25 */
3241                                 if  (p_ptr->lev > 24)
3242                                         p_ptr->free_act = TRUE;
3243                         }
3244                         break;
3245                 case CLASS_SORCERER:
3246                         p_ptr->to_a -= 50;
3247                         p_ptr->dis_to_a -= 50;
3248                         break;
3249                 case CLASS_BARD:
3250                         p_ptr->resist_sound = TRUE;
3251                         break;
3252                 case CLASS_SAMURAI:
3253                         if (p_ptr->lev > 29) p_ptr->resist_fear = TRUE;
3254                         break;
3255                 case CLASS_BERSERKER:
3256                         p_ptr->shero = 1;
3257                         p_ptr->sustain_str = TRUE;
3258                         p_ptr->sustain_dex = TRUE;
3259                         p_ptr->sustain_con = TRUE;
3260                         p_ptr->regenerate = TRUE;
3261                         p_ptr->free_act = TRUE;
3262                         p_ptr->pspeed += 2;
3263                         if (p_ptr->lev > 29) p_ptr->pspeed++;
3264                         if (p_ptr->lev > 39) p_ptr->pspeed++;
3265                         if (p_ptr->lev > 44) p_ptr->pspeed++;
3266                         if (p_ptr->lev > 49) p_ptr->pspeed++;
3267                         p_ptr->to_a += 10+p_ptr->lev/2;
3268                         p_ptr->dis_to_a += 10+p_ptr->lev/2;
3269                         p_ptr->skill_dig += (100+p_ptr->lev*8);
3270                         if (p_ptr->lev > 39) p_ptr->reflect = TRUE;
3271                         p_ptr->redraw |= PR_STATUS;
3272                         break;
3273                 case CLASS_MIRROR_MASTER:
3274                         if (p_ptr->lev > 39) p_ptr->reflect = TRUE;
3275                         break;
3276                 case CLASS_NINJA:
3277                         /* Unencumbered Monks become faster every 10 levels */
3278                         if (heavy_armor())
3279                         {
3280                                 p_ptr->pspeed -= (p_ptr->lev) / 10;
3281                                 p_ptr->skill_stl -= (p_ptr->lev)/10;
3282                         }
3283                         else if (!inventory[INVEN_LARM].tval || p_ptr->hidarite)
3284                         {
3285                                 p_ptr->pspeed += 3;
3286                                 if (!(prace_is_(RACE_KLACKON) ||
3287                                       prace_is_(RACE_SPRITE) ||
3288                                       (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)))
3289                                         p_ptr->pspeed += (p_ptr->lev) / 10;
3290                                 p_ptr->skill_stl += (p_ptr->lev)/10;
3291
3292                                 /* Free action if unencumbered at level 25 */
3293                                 if  (p_ptr->lev > 24)
3294                                         p_ptr->free_act = TRUE;
3295                         }
3296                         if (!inventory[INVEN_LARM].tval || p_ptr->hidarite)
3297                         {
3298                                 p_ptr->to_a += p_ptr->lev/2+5;
3299                                 p_ptr->dis_to_a += p_ptr->lev/2+5;
3300                         }
3301                         p_ptr->slow_digest = TRUE;
3302                         p_ptr->resist_fear = TRUE;
3303                         if (p_ptr->lev > 19) p_ptr->resist_pois = TRUE;
3304                         if (p_ptr->lev > 24) p_ptr->sustain_dex = TRUE;
3305                         if (p_ptr->lev > 29) p_ptr->see_inv = TRUE;
3306                         if (p_ptr->lev > 44)
3307                         {
3308                                 p_ptr->oppose_pois = 1;
3309                                 p_ptr->redraw |= PR_STATUS;
3310                         }
3311                         break;
3312         }
3313
3314         /***** Races ****/
3315         if (p_ptr->mimic_form)
3316         {
3317                 switch(p_ptr->mimic_form)
3318                 {
3319                 case MIMIC_DEMON:
3320                         p_ptr->hold_life=TRUE;
3321                         p_ptr->resist_chaos=TRUE;
3322                         p_ptr->resist_neth=TRUE;
3323                         p_ptr->resist_fire=TRUE;
3324                         p_ptr->oppose_fire = 1;
3325                         p_ptr->see_inv=TRUE;
3326                         p_ptr->pspeed += 3;
3327                         p_ptr->redraw |= PR_STATUS;
3328                         p_ptr->to_a += 10;
3329                         p_ptr->dis_to_a += 10;
3330                         break;
3331                 case MIMIC_DEMON_LORD:
3332                         p_ptr->hold_life=TRUE;
3333                         p_ptr->resist_chaos=TRUE;
3334                         p_ptr->resist_neth=TRUE;
3335                         p_ptr->immune_fire=TRUE;
3336                         p_ptr->resist_acid = TRUE;
3337                         p_ptr->resist_fire=TRUE;
3338                         p_ptr->resist_cold = TRUE;
3339                         p_ptr->resist_elec = TRUE;
3340                         p_ptr->resist_pois = TRUE;
3341                         p_ptr->resist_conf = TRUE;
3342                         p_ptr->resist_disen = TRUE;
3343                         p_ptr->resist_nexus = TRUE;
3344                         p_ptr->resist_fear = TRUE;
3345                         p_ptr->sh_fire = TRUE;
3346                         p_ptr->see_inv = TRUE;
3347                         p_ptr->telepathy = TRUE;
3348                         p_ptr->ffall = TRUE;
3349                         p_ptr->kill_wall = TRUE;
3350                         p_ptr->pspeed += 5;
3351                         p_ptr->to_a += 20;
3352                         p_ptr->dis_to_a += 20;
3353                         break;
3354                 case MIMIC_VAMPIRE:
3355                         p_ptr->resist_dark = TRUE;
3356                         p_ptr->hold_life = TRUE;
3357                         p_ptr->resist_neth = TRUE;
3358                         p_ptr->resist_cold = TRUE;
3359                         p_ptr->resist_pois = TRUE;
3360                         p_ptr->see_inv = TRUE;
3361                         p_ptr->pspeed += 3;
3362                         p_ptr->to_a += 10;
3363                         p_ptr->dis_to_a += 10;
3364                         if (p_ptr->pclass != CLASS_NINJA) p_ptr->lite = TRUE;
3365                         break;
3366                 }
3367         }
3368         else
3369         {
3370         switch (p_ptr->prace)
3371         {
3372                 case RACE_ELF:
3373                         p_ptr->resist_lite = TRUE;
3374                         break;
3375                 case RACE_HOBBIT:
3376                         p_ptr->sustain_dex = TRUE;
3377                         break;
3378                 case RACE_GNOME:
3379                         p_ptr->free_act = TRUE;
3380                         break;
3381                 case RACE_DWARF:
3382                         p_ptr->resist_blind = TRUE;
3383                         break;
3384                 case RACE_HALF_ORC:
3385                         p_ptr->resist_dark = TRUE;
3386                         break;
3387                 case RACE_HALF_TROLL:
3388                         p_ptr->sustain_str = TRUE;
3389
3390                         if (p_ptr->lev > 14)
3391                         {
3392                                 /* High level trolls heal fast... */
3393                                 p_ptr->regenerate = TRUE;
3394
3395                                 if (p_ptr->pclass == CLASS_WARRIOR || p_ptr->pclass == CLASS_BERSERKER)
3396                                 {
3397                                         p_ptr->slow_digest = TRUE;
3398                                         /* Let's not make Regeneration
3399                                          * a disadvantage for the poor warriors who can
3400                                          * never learn a spell that satisfies hunger (actually
3401                                          * neither can rogues, but half-trolls are not
3402                                          * supposed to play rogues) */
3403                                 }
3404                         }
3405                         break;
3406                 case RACE_AMBERITE:
3407                         p_ptr->sustain_con = TRUE;
3408                         p_ptr->regenerate = TRUE;  /* Amberites heal fast... */
3409                         break;
3410                 case RACE_HIGH_ELF:
3411                         p_ptr->resist_lite = TRUE;
3412                         p_ptr->see_inv = TRUE;
3413                         break;
3414                 case RACE_BARBARIAN:
3415                         p_ptr->resist_fear = TRUE;
3416                         break;
3417                 case RACE_HALF_OGRE:
3418                         p_ptr->resist_dark = TRUE;
3419                         p_ptr->sustain_str = TRUE;
3420                         break;
3421                 case RACE_HALF_GIANT:
3422                         p_ptr->sustain_str = TRUE;
3423                         p_ptr->resist_shard = TRUE;
3424                         break;
3425                 case RACE_HALF_TITAN:
3426                         p_ptr->resist_chaos = TRUE;
3427                         break;
3428                 case RACE_CYCLOPS:
3429                         p_ptr->resist_sound = TRUE;
3430                         break;
3431                 case RACE_YEEK:
3432                         p_ptr->resist_acid = TRUE;
3433                         if (p_ptr->lev > 19) p_ptr->immune_acid = TRUE;
3434                         break;
3435                 case RACE_KLACKON:
3436                         p_ptr->resist_conf = TRUE;
3437                         p_ptr->resist_acid = TRUE;
3438
3439                         /* Klackons become faster */
3440                         p_ptr->pspeed += (p_ptr->lev) / 10;
3441                         break;
3442                 case RACE_KOBOLD:
3443                         p_ptr->resist_pois = TRUE;
3444                         break;
3445                 case RACE_NIBELUNG:
3446                         p_ptr->resist_disen = TRUE;
3447                         p_ptr->resist_dark = TRUE;
3448                         break;
3449                 case RACE_DARK_ELF:
3450                         p_ptr->resist_dark = TRUE;
3451                         if (p_ptr->lev > 19) p_ptr->see_inv = TRUE;
3452                         break;
3453                 case RACE_DRACONIAN:
3454                         p_ptr->ffall = TRUE;
3455                         if (p_ptr->lev >  4) p_ptr->resist_fire = TRUE;
3456                         if (p_ptr->lev >  9) p_ptr->resist_cold = TRUE;
3457                         if (p_ptr->lev > 14) p_ptr->resist_acid = TRUE;
3458                         if (p_ptr->lev > 19) p_ptr->resist_elec = TRUE;
3459                         if (p_ptr->lev > 34) p_ptr->resist_pois = TRUE;
3460                         break;
3461                 case RACE_MIND_FLAYER:
3462                         p_ptr->sustain_int = TRUE;
3463                         p_ptr->sustain_wis = TRUE;
3464                         if (p_ptr->lev > 14) p_ptr->see_inv = TRUE;
3465                         if (p_ptr->lev > 29) p_ptr->telepathy = TRUE;
3466                         break;
3467                 case RACE_IMP:
3468                         p_ptr->resist_fire = TRUE;
3469                         if (p_ptr->lev > 9) p_ptr->see_inv = TRUE;
3470                         break;
3471                 case RACE_GOLEM:
3472                         p_ptr->slow_digest = TRUE;
3473                         p_ptr->free_act = TRUE;
3474                         p_ptr->see_inv = TRUE;
3475                         p_ptr->resist_pois = TRUE;
3476                         if (p_ptr->lev > 34) p_ptr->hold_life = TRUE;
3477                         break;
3478                 case RACE_SKELETON:
3479                         p_ptr->resist_shard = TRUE;
3480                         p_ptr->hold_life = TRUE;
3481                         p_ptr->see_inv = TRUE;
3482                         p_ptr->resist_pois = TRUE;
3483                         if (p_ptr->lev > 9) p_ptr->resist_cold = TRUE;
3484                         break;
3485                 case RACE_ZOMBIE:
3486                         p_ptr->resist_neth = TRUE;
3487                         p_ptr->hold_life = TRUE;
3488                         p_ptr->see_inv = TRUE;
3489                         p_ptr->resist_pois = TRUE;
3490                         p_ptr->slow_digest = TRUE;
3491                         if (p_ptr->lev > 4) p_ptr->resist_cold = TRUE;
3492                         break;
3493                 case RACE_VAMPIRE:
3494                         p_ptr->resist_dark = TRUE;
3495                         p_ptr->hold_life = TRUE;
3496                         p_ptr->resist_neth = TRUE;
3497                         p_ptr->resist_cold = TRUE;
3498                         p_ptr->resist_pois = TRUE;
3499                         if (p_ptr->pclass != CLASS_NINJA) p_ptr->lite = TRUE;
3500                         break;
3501                 case RACE_SPECTRE:
3502                         p_ptr->ffall = TRUE;
3503                         p_ptr->free_act = TRUE;
3504                         p_ptr->resist_neth = TRUE;
3505                         p_ptr->hold_life = TRUE;
3506                         p_ptr->see_inv = TRUE;
3507                         p_ptr->resist_pois = TRUE;
3508                         p_ptr->slow_digest = TRUE;
3509                         p_ptr->resist_cold = TRUE;
3510                         p_ptr->pass_wall = TRUE;
3511                         if (p_ptr->lev > 34) p_ptr->telepathy = TRUE;
3512                         break;
3513                 case RACE_SPRITE:
3514                         p_ptr->ffall = TRUE;
3515                         p_ptr->resist_lite = TRUE;
3516
3517                         /* Sprites become faster */
3518                         p_ptr->pspeed += (p_ptr->lev) / 10;
3519                         break;
3520                 case RACE_BEASTMAN:
3521                         p_ptr->resist_conf  = TRUE;
3522                         p_ptr->resist_sound = TRUE;
3523                         break;
3524                 case RACE_ENT:
3525                         /* Ents dig like maniacs, but only with their hands. */
3526                         if (!inventory[INVEN_RARM].k_idx) 
3527                                 p_ptr->skill_dig += p_ptr->lev * 10;
3528                         /* Ents get tougher and stronger as they age, but lose dexterity. */
3529                         if (p_ptr->lev > 25) p_ptr->stat_add[A_STR]++;
3530                         if (p_ptr->lev > 40) p_ptr->stat_add[A_STR]++;
3531                         if (p_ptr->lev > 45) p_ptr->stat_add[A_STR]++;
3532
3533                         if (p_ptr->lev > 25) p_ptr->stat_add[A_DEX]--;
3534                         if (p_ptr->lev > 40) p_ptr->stat_add[A_DEX]--;
3535                         if (p_ptr->lev > 45) p_ptr->stat_add[A_DEX]--;
3536
3537                         if (p_ptr->lev > 25) p_ptr->stat_add[A_CON]++;
3538                         if (p_ptr->lev > 40) p_ptr->stat_add[A_CON]++;
3539                         if (p_ptr->lev > 45) p_ptr->stat_add[A_CON]++;
3540                         break;
3541                 case RACE_ANGEL:
3542                         p_ptr->ffall = TRUE;
3543                         p_ptr->see_inv = TRUE;
3544                         break;
3545                 case RACE_DEMON:
3546                         p_ptr->resist_fire  = TRUE;
3547                         p_ptr->resist_neth  = TRUE;
3548                         p_ptr->hold_life = TRUE;
3549                         if (p_ptr->lev > 9)
3550                                 p_ptr->see_inv = TRUE;
3551                         if (p_ptr->lev > 44)
3552                         {
3553                                 p_ptr->oppose_fire = 1;
3554                                 p_ptr->redraw |= PR_STATUS;
3555                         }
3556                         break;
3557                 case RACE_DUNADAN:
3558                         p_ptr->sustain_con = TRUE;
3559                         break;
3560                 case RACE_S_FAIRY:
3561                         p_ptr->ffall = TRUE;
3562                         break;
3563                 case RACE_KUTA:
3564                         p_ptr->resist_conf = TRUE;
3565                         break;
3566                 case RACE_ANDROID:
3567                         p_ptr->slow_digest = TRUE;
3568                         p_ptr->free_act = TRUE;
3569                         p_ptr->resist_pois = TRUE;
3570                         p_ptr->hold_life = TRUE;
3571                         break;
3572                 default:
3573                         /* Do nothing */
3574                         ;
3575         }
3576         }
3577
3578         if (p_ptr->ult_res || (p_ptr->special_defense & KATA_MUSOU))
3579         {
3580                 p_ptr->see_inv = TRUE;
3581                 p_ptr->free_act = TRUE;
3582                 p_ptr->slow_digest = TRUE;
3583                 p_ptr->regenerate = TRUE;
3584                 p_ptr->ffall = TRUE;
3585                 p_ptr->hold_life = TRUE;
3586                 p_ptr->telepathy = TRUE;
3587                 p_ptr->lite = TRUE;
3588                 p_ptr->sustain_str = TRUE;
3589                 p_ptr->sustain_int = TRUE;
3590                 p_ptr->sustain_wis = TRUE;
3591                 p_ptr->sustain_con = TRUE;
3592                 p_ptr->sustain_dex = TRUE;
3593                 p_ptr->sustain_chr = TRUE;
3594                 p_ptr->resist_acid = TRUE;
3595                 p_ptr->resist_elec = TRUE;
3596                 p_ptr->resist_fire = TRUE;
3597                 p_ptr->resist_cold = TRUE;
3598                 p_ptr->resist_pois = TRUE;
3599                 p_ptr->resist_conf = TRUE;
3600                 p_ptr->resist_sound = TRUE;
3601                 p_ptr->resist_lite = TRUE;
3602                 p_ptr->resist_dark = TRUE;
3603                 p_ptr->resist_chaos = TRUE;
3604                 p_ptr->resist_disen = TRUE;
3605                 p_ptr->resist_shard = TRUE;
3606                 p_ptr->resist_nexus = TRUE;
3607                 p_ptr->resist_blind = TRUE;
3608                 p_ptr->resist_neth = TRUE;
3609                 p_ptr->resist_fear = TRUE;
3610                 p_ptr->reflect = TRUE;
3611                 p_ptr->sh_fire = TRUE;
3612                 p_ptr->sh_elec = TRUE;
3613                 p_ptr->sh_cold = TRUE;
3614                 p_ptr->to_a += 100;
3615                 p_ptr->dis_to_a += 100;
3616         }
3617         /* Temporary shield */
3618         else if (p_ptr->tsubureru || p_ptr->shield || p_ptr->magicdef)
3619         {
3620                 p_ptr->to_a += 50;
3621                 p_ptr->dis_to_a += 50;
3622         }
3623
3624         if (p_ptr->tim_res_nether)
3625         {
3626                 p_ptr->resist_neth = TRUE;
3627         }
3628         if (p_ptr->tim_sh_fire)
3629         {
3630                 p_ptr->sh_fire = TRUE;
3631         }
3632         if (p_ptr->tim_res_time)
3633         {
3634                 p_ptr->resist_time = TRUE;
3635         }
3636
3637         /* Sexy Gal */
3638         if (p_ptr->pseikaku == SEIKAKU_SEXY) p_ptr->cursed |= (TRC_AGGRAVATE);
3639         if (p_ptr->pseikaku == SEIKAKU_NAMAKE) p_ptr->to_m_chance += 10;
3640         if (p_ptr->pseikaku == SEIKAKU_KIREMONO) p_ptr->to_m_chance -= 3;
3641         if ((p_ptr->pseikaku == SEIKAKU_GAMAN) || (p_ptr->pseikaku == SEIKAKU_CHIKARA)) p_ptr->to_m_chance++;
3642
3643         /* Lucky man */
3644         if (p_ptr->pseikaku == SEIKAKU_LUCKY) p_ptr->muta3 |= MUT3_GOOD_LUCK;
3645
3646         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
3647         {
3648                 p_ptr->resist_blind = TRUE;
3649                 p_ptr->resist_conf  = TRUE;
3650                 p_ptr->hold_life = TRUE;
3651                 if (p_ptr->pclass != CLASS_NINJA) p_ptr->lite = TRUE;
3652
3653                 if ((p_ptr->prace != RACE_KLACKON) && (p_ptr->prace != RACE_SPRITE))
3654                         /* Munchkin become faster */
3655                         p_ptr->pspeed += (p_ptr->lev) / 10 + 5;
3656         }
3657
3658         if (p_ptr->riding)
3659         {
3660                 if (!(r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_PASS_WALL))
3661                         p_ptr->pass_wall = FALSE;
3662                 if (r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_KILL_WALL)
3663                         p_ptr->pass_wall = TRUE;
3664         }
3665         if (music_singing(MUSIC_WALL)) p_ptr->kill_wall = TRUE;
3666
3667         if (p_ptr->kill_wall) p_ptr->pass_wall = TRUE;
3668
3669         /* Hack -- apply racial/class stat maxes */
3670         /* Apply the racial modifiers */
3671         for (i = 0; i < 6; i++)
3672         {
3673                 /* Modify the stats for "race" */
3674                 p_ptr->stat_add[i] += (tmp_rp_ptr->r_adj[i] + cp_ptr->c_adj[i] + ap_ptr->a_adj[i]);
3675         }
3676
3677
3678         /* I'm adding the mutations here for the lack of a better place... */
3679         if (p_ptr->muta3)
3680         {
3681                 /* Hyper Strength */
3682                 if (p_ptr->muta3 & MUT3_HYPER_STR)
3683                 {
3684                         p_ptr->stat_add[A_STR] += 4;
3685                 }
3686
3687                 /* Puny */
3688                 if (p_ptr->muta3 & MUT3_PUNY)
3689                 {
3690                         p_ptr->stat_add[A_STR] -= 4;
3691                 }
3692
3693                 /* Living computer */
3694                 if (p_ptr->muta3 & MUT3_HYPER_INT)
3695                 {
3696                         p_ptr->stat_add[A_INT] += 4;
3697                         p_ptr->stat_add[A_WIS] += 4;
3698                 }
3699
3700                 /* Moronic */
3701                 if (p_ptr->muta3 & MUT3_MORONIC)
3702                 {
3703                         p_ptr->stat_add[A_INT] -= 4;
3704                         p_ptr->stat_add[A_WIS] -= 4;
3705                 }
3706
3707                 if (p_ptr->muta3 & MUT3_RESILIENT)
3708                 {
3709                         p_ptr->stat_add[A_CON] += 4;
3710                 }
3711
3712                 if (p_ptr->muta3 & MUT3_XTRA_FAT)
3713                 {
3714                         p_ptr->stat_add[A_CON] += 2;
3715                         p_ptr->pspeed -= 2;
3716                 }
3717
3718                 if (p_ptr->muta3 & MUT3_ALBINO)
3719                 {
3720                         p_ptr->stat_add[A_CON] -= 4;
3721                 }
3722
3723                 if (p_ptr->muta3 & MUT3_FLESH_ROT)
3724                 {
3725                         p_ptr->stat_add[A_CON] -= 2;
3726                         p_ptr->stat_add[A_CHR] -= 1;
3727                         p_ptr->regenerate = FALSE;
3728                         /* Cancel innate regeneration */
3729                 }
3730
3731                 if (p_ptr->muta3 & MUT3_SILLY_VOI)
3732                 {
3733                         p_ptr->stat_add[A_CHR] -= 4;
3734                 }
3735
3736                 if (p_ptr->muta3 & MUT3_BLANK_FAC)
3737                 {
3738                         p_ptr->stat_add[A_CHR] -= 1;
3739                 }
3740
3741                 if (p_ptr->muta3 & MUT3_XTRA_EYES)
3742                 {
3743                         p_ptr->skill_fos += 15;
3744                         p_ptr->skill_srh += 15;
3745                 }
3746
3747                 if (p_ptr->muta3 & MUT3_MAGIC_RES)
3748                 {
3749                         p_ptr->skill_sav += (15 + (p_ptr->lev / 5));
3750                 }
3751
3752                 if (p_ptr->muta3 & MUT3_XTRA_NOIS)
3753                 {
3754                         p_ptr->skill_stl -= 3;
3755                 }
3756
3757                 if (p_ptr->muta3 & MUT3_INFRAVIS)
3758                 {
3759                         p_ptr->see_infra += 3;
3760                 }
3761
3762                 if (p_ptr->muta3 & MUT3_XTRA_LEGS)
3763                 {
3764                         p_ptr->pspeed += 3;
3765                 }
3766
3767                 if (p_ptr->muta3 & MUT3_SHORT_LEG)
3768                 {
3769                         p_ptr->pspeed -= 3;
3770                 }
3771
3772                 if (p_ptr->muta3 & MUT3_ELEC_TOUC)
3773                 {
3774                         p_ptr->sh_elec = TRUE;
3775                 }
3776
3777                 if (p_ptr->muta3 & MUT3_FIRE_BODY)
3778                 {
3779                         p_ptr->sh_fire = TRUE;
3780                         p_ptr->lite = TRUE;
3781                 }
3782
3783                 if (p_ptr->muta3 & MUT3_WART_SKIN)
3784                 {
3785                         p_ptr->stat_add[A_CHR] -= 2;
3786                         p_ptr->to_a += 5;
3787                         p_ptr->dis_to_a += 5;
3788                 }
3789
3790                 if (p_ptr->muta3 & MUT3_SCALES)
3791                 {
3792                         p_ptr->stat_add[A_CHR] -= 1;
3793                         p_ptr->to_a += 10;
3794                         p_ptr->dis_to_a += 10;
3795                 }
3796
3797                 if (p_ptr->muta3 & MUT3_IRON_SKIN)
3798                 {
3799                         p_ptr->stat_add[A_DEX] -= 1;
3800                         p_ptr->to_a += 25;
3801                         p_ptr->dis_to_a += 25;
3802                 }
3803
3804                 if (p_ptr->muta3 & MUT3_WINGS)
3805                 {
3806                         p_ptr->ffall = TRUE;
3807                 }
3808
3809                 if (p_ptr->muta3 & MUT3_FEARLESS)
3810                 {
3811                         p_ptr->resist_fear = TRUE;
3812                 }
3813
3814                 if (p_ptr->muta3 & MUT3_REGEN)
3815                 {
3816                         p_ptr->regenerate = TRUE;
3817                 }
3818
3819                 if (p_ptr->muta3 & MUT3_ESP)
3820                 {
3821                         p_ptr->telepathy = TRUE;
3822                 }
3823
3824                 if (p_ptr->muta3 & MUT3_LIMBER)
3825                 {
3826                         p_ptr->stat_add[A_DEX] += 3;
3827                 }
3828
3829                 if (p_ptr->muta3 & MUT3_ARTHRITIS)
3830                 {
3831                         p_ptr->stat_add[A_DEX] -= 3;
3832                 }
3833
3834                 if (p_ptr->muta3 & MUT3_MOTION)
3835                 {
3836                         p_ptr->free_act = TRUE;
3837                         p_ptr->skill_stl += 1;
3838                 }
3839
3840                 if (p_ptr->muta3 & MUT3_ILL_NORM)
3841                 {
3842                         p_ptr->stat_add[A_CHR] = 0;
3843                 }
3844         }
3845
3846         if (p_ptr->tsuyoshi)
3847         {
3848                 p_ptr->stat_add[A_STR] += 4;
3849                 p_ptr->stat_add[A_CON] += 4;
3850         }
3851
3852         /* Scan the usable inventory */
3853         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
3854         {
3855                 int bonus_to_h, bonus_to_d;
3856                 o_ptr = &inventory[i];
3857
3858                 /* Skip non-objects */
3859                 if (!o_ptr->k_idx) continue;
3860
3861                 /* Extract the item flags */
3862                 object_flags(o_ptr, flgs);
3863
3864                 p_ptr->cursed |= (o_ptr->curse_flags & (0xFFFFFFF0L));
3865                 if (o_ptr->name1 == ART_CHAINSWORD) p_ptr->cursed |= TRC_CHAINSWORD;
3866
3867                 /* Affect stats */
3868                 if (have_flag(flgs, TR_STR)) p_ptr->stat_add[A_STR] += o_ptr->pval;
3869                 if (have_flag(flgs, TR_INT)) p_ptr->stat_add[A_INT] += o_ptr->pval;
3870                 if (have_flag(flgs, TR_WIS)) p_ptr->stat_add[A_WIS] += o_ptr->pval;
3871                 if (have_flag(flgs, TR_DEX)) p_ptr->stat_add[A_DEX] += o_ptr->pval;
3872                 if (have_flag(flgs, TR_CON)) p_ptr->stat_add[A_CON] += o_ptr->pval;
3873                 if (have_flag(flgs, TR_CHR)) p_ptr->stat_add[A_CHR] += o_ptr->pval;
3874
3875                 if (have_flag(flgs, TR_MAGIC_MASTERY))    p_ptr->skill_dev += 8*o_ptr->pval;
3876
3877                 /* Affect stealth */
3878                 if (have_flag(flgs, TR_STEALTH)) p_ptr->skill_stl += o_ptr->pval;
3879
3880                 /* Affect searching ability (factor of five) */
3881                 if (have_flag(flgs, TR_SEARCH)) p_ptr->skill_srh += (o_ptr->pval * 5);
3882
3883                 /* Affect searching frequency (factor of five) */
3884                 if (have_flag(flgs, TR_SEARCH)) p_ptr->skill_fos += (o_ptr->pval * 5);
3885
3886                 /* Affect infravision */
3887                 if (have_flag(flgs, TR_INFRA)) p_ptr->see_infra += o_ptr->pval;
3888
3889                 /* Affect digging (factor of 20) */
3890                 if (have_flag(flgs, TR_TUNNEL)) p_ptr->skill_dig += (o_ptr->pval * 20);
3891
3892                 /* Affect speed */
3893                 if (have_flag(flgs, TR_SPEED)) p_ptr->pspeed += o_ptr->pval;
3894
3895                 /* Affect blows */
3896                 if (have_flag(flgs, TR_BLOWS))
3897                 {
3898                         if((i == INVEN_RARM || i == INVEN_RIGHT) && !p_ptr->ryoute) extra_blows[0] += o_ptr->pval;
3899                         else if((i == INVEN_LARM || i == INVEN_LEFT) && !p_ptr->ryoute) extra_blows[1] += o_ptr->pval;
3900                         else {extra_blows[0] += o_ptr->pval; extra_blows[1] += o_ptr->pval;}
3901                 }
3902
3903                 /* Hack -- cause earthquakes */
3904                 if (have_flag(flgs, TR_IMPACT)) p_ptr->impact[(i == INVEN_RARM) ? 0 : 1] = TRUE;
3905
3906                 /* Boost shots */
3907                 if (have_flag(flgs, TR_XTRA_SHOTS)) extra_shots++;
3908
3909                 /* Various flags */
3910                 if (have_flag(flgs, TR_AGGRAVATE))   p_ptr->cursed |= TRC_AGGRAVATE;
3911                 if (have_flag(flgs, TR_DRAIN_EXP))   p_ptr->cursed |= TRC_DRAIN_EXP;
3912                 if (have_flag(flgs, TR_TY_CURSE))    p_ptr->cursed |= TRC_TY_CURSE;
3913                 if (have_flag(flgs, TR_DEC_MANA))    p_ptr->dec_mana = TRUE;
3914                 if (have_flag(flgs, TR_BLESSED))     p_ptr->bless_blade = TRUE;
3915                 if (have_flag(flgs, TR_XTRA_MIGHT))  p_ptr->xtra_might = TRUE;
3916                 if (have_flag(flgs, TR_SLOW_DIGEST)) p_ptr->slow_digest = TRUE;
3917                 if (have_flag(flgs, TR_REGEN))       p_ptr->regenerate = TRUE;
3918                 if (have_flag(flgs, TR_TELEPATHY))   p_ptr->telepathy = TRUE;
3919                 if (have_flag(flgs, TR_ESP_ANIMAL))  p_ptr->esp_animal = TRUE;
3920                 if (have_flag(flgs, TR_ESP_UNDEAD))  p_ptr->esp_undead = TRUE;
3921                 if (have_flag(flgs, TR_ESP_DEMON))   p_ptr->esp_demon = TRUE;
3922                 if (have_flag(flgs, TR_ESP_ORC))     p_ptr->esp_orc = TRUE;
3923                 if (have_flag(flgs, TR_ESP_TROLL))   p_ptr->esp_troll = TRUE;
3924                 if (have_flag(flgs, TR_ESP_GIANT))   p_ptr->esp_giant = TRUE;
3925                 if (have_flag(flgs, TR_ESP_DRAGON))  p_ptr->esp_dragon = TRUE;
3926                 if (have_flag(flgs, TR_ESP_HUMAN))   p_ptr->esp_human = TRUE;
3927                 if (have_flag(flgs, TR_ESP_EVIL))    p_ptr->esp_evil = TRUE;
3928                 if (have_flag(flgs, TR_ESP_GOOD))    p_ptr->esp_good = TRUE;
3929                 if (have_flag(flgs, TR_ESP_NONLIVING)) p_ptr->esp_nonliving = TRUE;
3930                 if (have_flag(flgs, TR_ESP_UNIQUE))  p_ptr->esp_unique = TRUE;
3931
3932                 if (have_flag(flgs, TR_SEE_INVIS))   p_ptr->see_inv = TRUE;
3933                 if (have_flag(flgs, TR_FEATHER))     p_ptr->ffall = TRUE;
3934                 if (have_flag(flgs, TR_FREE_ACT))    p_ptr->free_act = TRUE;
3935                 if (have_flag(flgs, TR_HOLD_LIFE))   p_ptr->hold_life = TRUE;
3936                 if (have_flag(flgs, TR_WARNING)){
3937                         if (!o_ptr->inscription || !(strchr(quark_str(o_ptr->inscription),'$')))
3938                           p_ptr->warning = TRUE;
3939                 }
3940
3941                 if (have_flag(flgs, TR_TELEPORT))
3942                 {
3943                         if (cursed_p(o_ptr)) p_ptr->cursed |= TRC_TELEPORT;
3944                         else
3945                         {
3946                                 cptr insc = quark_str(o_ptr->inscription);
3947
3948                                 if (o_ptr->inscription &&
3949                                     (strchr(insc, '.') || strchr(insc, '%')))
3950                                 {
3951                                         /*
3952                                          * {.} will stop random teleportation.
3953                                          * {%} includes '.' after conversion.
3954                                          */
3955                                 }
3956                                 else
3957                                 {
3958                                         /* Controlled random teleportation */
3959                                         p_ptr->cursed |= TRC_TELEPORT_SELF;
3960                                 }
3961                         }
3962                 }
3963
3964                 /* Immunity flags */
3965                 if (have_flag(flgs, TR_IM_FIRE)) p_ptr->immune_fire = TRUE;
3966                 if (have_flag(flgs, TR_IM_ACID)) p_ptr->immune_acid = TRUE;
3967                 if (have_flag(flgs, TR_IM_COLD)) p_ptr->immune_cold = TRUE;
3968                 if (have_flag(flgs, TR_IM_ELEC)) p_ptr->immune_elec = TRUE;
3969
3970                 /* Resistance flags */
3971                 if (have_flag(flgs, TR_RES_ACID))   p_ptr->resist_acid = TRUE;
3972                 if (have_flag(flgs, TR_RES_ELEC))   p_ptr->resist_elec = TRUE;
3973                 if (have_flag(flgs, TR_RES_FIRE))   p_ptr->resist_fire = TRUE;
3974                 if (have_flag(flgs, TR_RES_COLD))   p_ptr->resist_cold = TRUE;
3975                 if (have_flag(flgs, TR_RES_POIS))   p_ptr->resist_pois = TRUE;
3976                 if (have_flag(flgs, TR_RES_FEAR))   p_ptr->resist_fear = TRUE;
3977                 if (have_flag(flgs, TR_RES_CONF))   p_ptr->resist_conf = TRUE;
3978                 if (have_flag(flgs, TR_RES_SOUND))  p_ptr->resist_sound = TRUE;
3979                 if (have_flag(flgs, TR_RES_LITE))   p_ptr->resist_lite = TRUE;
3980                 if (have_flag(flgs, TR_RES_DARK))   p_ptr->resist_dark = TRUE;
3981                 if (have_flag(flgs, TR_RES_CHAOS))  p_ptr->resist_chaos = TRUE;
3982                 if (have_flag(flgs, TR_RES_DISEN))  p_ptr->resist_disen = TRUE;
3983                 if (have_flag(flgs, TR_RES_SHARDS)) p_ptr->resist_shard = TRUE;
3984                 if (have_flag(flgs, TR_RES_NEXUS))  p_ptr->resist_nexus = TRUE;
3985                 if (have_flag(flgs, TR_RES_BLIND))  p_ptr->resist_blind = TRUE;
3986                 if (have_flag(flgs, TR_RES_NETHER)) p_ptr->resist_neth = TRUE;
3987
3988                 if (have_flag(flgs, TR_REFLECT))  p_ptr->reflect = TRUE;
3989                 if (have_flag(flgs, TR_SH_FIRE))  p_ptr->sh_fire = TRUE;
3990                 if (have_flag(flgs, TR_SH_ELEC))  p_ptr->sh_elec = TRUE;
3991                 if (have_flag(flgs, TR_SH_COLD))  p_ptr->sh_cold = TRUE;
3992                 if (have_flag(flgs, TR_NO_MAGIC)) p_ptr->anti_magic = TRUE;
3993                 if (have_flag(flgs, TR_NO_TELE))  p_ptr->anti_tele = TRUE;
3994
3995                 /* Sustain flags */
3996                 if (have_flag(flgs, TR_SUST_STR)) p_ptr->sustain_str = TRUE;
3997                 if (have_flag(flgs, TR_SUST_INT)) p_ptr->sustain_int = TRUE;
3998                 if (have_flag(flgs, TR_SUST_WIS)) p_ptr->sustain_wis = TRUE;
3999                 if (have_flag(flgs, TR_SUST_DEX)) p_ptr->sustain_dex = TRUE;
4000                 if (have_flag(flgs, TR_SUST_CON)) p_ptr->sustain_con = TRUE;
4001                 if (have_flag(flgs, TR_SUST_CHR)) p_ptr->sustain_chr = TRUE;
4002
4003                 if (o_ptr->name2 == EGO_YOIYAMI) yoiyami = TRUE;
4004                 if (o_ptr->name2 == EGO_2WEAPON) easy_2weapon = TRUE;
4005                 if (o_ptr->name2 == EGO_RING_RES_TIME) p_ptr->resist_time = TRUE;
4006                 if (o_ptr->name2 == EGO_RING_THROW) p_ptr->mighty_throw = TRUE;
4007                 if (have_flag(flgs, TR_EASY_SPELL)) p_ptr->easy_spell = TRUE;
4008                 if (o_ptr->name2 == EGO_AMU_FOOL) p_ptr->heavy_spell = TRUE;
4009                 if (o_ptr->name2 == EGO_AMU_NAIVETY) down_saving = TRUE;
4010
4011                 if (o_ptr->curse_flags & TRC_LOW_MAGIC)
4012                 {
4013                         if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
4014                         {
4015                                 p_ptr->to_m_chance += 10;
4016                         }
4017                         else
4018                         {
4019                                 p_ptr->to_m_chance += 3;
4020                         }
4021                 }
4022
4023                 if (o_ptr->tval == TV_CAPTURE) continue;
4024
4025                 /* Modify the base armor class */
4026                 p_ptr->ac += o_ptr->ac;
4027
4028                 /* The base armor class is always known */
4029                 p_ptr->dis_ac += o_ptr->ac;
4030
4031                 /* Apply the bonuses to armor class */
4032                 p_ptr->to_a += o_ptr->to_a;
4033
4034                 /* Apply the mental bonuses to armor class, if known */
4035                 if (object_known_p(o_ptr)) p_ptr->dis_to_a += o_ptr->to_a;
4036
4037                 if (o_ptr->curse_flags & TRC_LOW_MELEE)
4038                 {
4039                         int slot = i - INVEN_RARM;
4040                         if (slot < 2)
4041                         {
4042                                 if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
4043                                 {
4044                                         p_ptr->to_h[slot] -= 15;
4045                                         if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_h[slot] -= 15;
4046                                 }
4047                                 else
4048                                 {
4049                                         p_ptr->to_h[slot] -= 5;
4050                                         if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_h[slot] -= 5;
4051                                 }
4052                         }
4053                         else
4054                         {
4055                                 if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
4056                                 {
4057                                         p_ptr->to_h_b -= 15;
4058                                         if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_h_b -= 15;
4059                                 }
4060                                 else
4061                                 {
4062                                         p_ptr->to_h_b -= 5;
4063                                         if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_h_b -= 5;
4064                                 }
4065                         }
4066                 }
4067
4068                 if (o_ptr->curse_flags & TRC_LOW_AC)
4069                 {
4070                         if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
4071                         {
4072                                 p_ptr->to_a -= 30;
4073                                 if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_a -= 30;
4074                         }
4075                         else
4076                         {
4077                                 p_ptr->to_a -= 10;
4078                                 if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_a -= 10;
4079                         }
4080                 }
4081
4082                 /* Hack -- do not apply "weapon" bonuses */
4083                 if (i == INVEN_RARM && buki_motteruka(i)) continue;
4084                 if (i == INVEN_LARM && buki_motteruka(i)) continue;
4085
4086                 /* Hack -- do not apply "bow" bonuses */
4087                 if (i == INVEN_BOW) continue;
4088
4089                 bonus_to_h = o_ptr->to_h;
4090                 bonus_to_d = o_ptr->to_d;
4091
4092                 if (p_ptr->pclass == CLASS_NINJA)
4093                 {
4094                         if (o_ptr->to_h > 0) bonus_to_h = (o_ptr->to_h+1)/2;
4095                         if (o_ptr->to_d > 0) bonus_to_d = (o_ptr->to_d+1)/2;
4096                 }
4097
4098                 /* To Bow and Natural attack */
4099
4100                 /* Apply the bonuses to hit/damage */
4101                 p_ptr->to_h_b += bonus_to_h;
4102                 p_ptr->to_h_m += bonus_to_h;
4103                 p_ptr->to_d_m += bonus_to_d;
4104
4105                 /* Apply the mental bonuses tp hit/damage, if known */
4106                 if (object_known_p(o_ptr)) p_ptr->dis_to_h_b += bonus_to_h;
4107
4108                 /* To Melee */
4109                 if ((i == INVEN_LEFT || i == INVEN_RIGHT) && !p_ptr->ryoute)
4110                 {
4111                         /* Apply the bonuses to hit/damage */
4112                         p_ptr->to_h[i-INVEN_RIGHT] += bonus_to_h;
4113                         p_ptr->to_d[i-INVEN_RIGHT] += bonus_to_d;
4114
4115                         /* Apply the mental bonuses tp hit/damage, if known */
4116                         if (object_known_p(o_ptr))
4117                         {
4118                                 p_ptr->dis_to_h[i-INVEN_RIGHT] += bonus_to_h;
4119                                 p_ptr->dis_to_d[i-INVEN_RIGHT] += bonus_to_d;
4120                         }
4121                 }
4122                 else if (p_ptr->migite && p_ptr->hidarite)
4123                 {
4124                         /* Apply the bonuses to hit/damage */
4125                         p_ptr->to_h[0] += (bonus_to_h > 0) ? (bonus_to_h+1)/2 : bonus_to_h;
4126                         p_ptr->to_h[1] += (bonus_to_h > 0) ? bonus_to_h/2 : bonus_to_h;
4127                         p_ptr->to_d[0] += (bonus_to_d > 0) ? (bonus_to_d+1)/2 : bonus_to_d;
4128                         p_ptr->to_d[1] += (bonus_to_d > 0) ? bonus_to_d/2 : bonus_to_d;
4129
4130                         /* Apply the mental bonuses tp hit/damage, if known */
4131                         if (object_known_p(o_ptr))
4132                         {
4133                                 p_ptr->dis_to_h[0] += (bonus_to_h > 0) ? (bonus_to_h+1)/2 : bonus_to_h;
4134                                 p_ptr->dis_to_h[1] += (bonus_to_h > 0) ? bonus_to_h/2 : bonus_to_h;
4135                                 p_ptr->dis_to_d[0] += (bonus_to_d > 0) ? (bonus_to_d+1)/2 : bonus_to_d;
4136                                 p_ptr->dis_to_d[1] += (bonus_to_d > 0) ? bonus_to_d/2 : bonus_to_d;
4137                         }
4138                 }
4139                 else
4140                 {
4141                         /* Apply the bonuses to hit/damage */
4142                         p_ptr->to_h[0] += bonus_to_h;
4143                         p_ptr->to_d[0] += bonus_to_d;
4144
4145                         /* Apply the mental bonuses tp hit/damage, if known */
4146                         if (object_known_p(o_ptr))
4147                         {
4148                                 p_ptr->dis_to_h[0] += bonus_to_h;
4149                                 p_ptr->dis_to_d[0] += bonus_to_d;
4150                         }
4151                 }
4152         }
4153
4154         if (p_ptr->cursed & TRC_TELEPORT) p_ptr->cursed &= ~(TRC_TELEPORT_SELF);
4155
4156         /* Monks get extra ac for armour _not worn_ */
4157         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER)) && !heavy_armor())
4158         {
4159                 if (!(inventory[INVEN_BODY].k_idx))
4160                 {
4161                         p_ptr->to_a += (p_ptr->lev * 3) / 2;
4162                         p_ptr->dis_to_a += (p_ptr->lev * 3) / 2;
4163                 }
4164                 if (!(inventory[INVEN_OUTER].k_idx) && (p_ptr->lev > 15))
4165                 {
4166                         p_ptr->to_a += ((p_ptr->lev - 13) / 3);
4167                         p_ptr->dis_to_a += ((p_ptr->lev - 13) / 3);
4168                 }
4169                 if (!(inventory[INVEN_LARM].k_idx) && (p_ptr->lev > 10))
4170                 {
4171                         p_ptr->to_a += ((p_ptr->lev - 8) / 3);
4172                         p_ptr->dis_to_a += ((p_ptr->lev - 8) / 3);
4173                 }
4174                 if (!(inventory[INVEN_HEAD].k_idx) && (p_ptr->lev > 4))
4175                 {
4176                         p_ptr->to_a += (p_ptr->lev - 2) / 3;
4177                         p_ptr->dis_to_a += (p_ptr->lev -2) / 3;
4178                 }
4179                 if (!(inventory[INVEN_HANDS].k_idx))
4180                 {
4181                         p_ptr->to_a += (p_ptr->lev / 2);
4182                         p_ptr->dis_to_a += (p_ptr->lev / 2);
4183                 }
4184                 if (!(inventory[INVEN_FEET].k_idx))
4185                 {
4186                         p_ptr->to_a += (p_ptr->lev / 3);
4187                         p_ptr->dis_to_a += (p_ptr->lev / 3);
4188                 }
4189                 if (p_ptr->special_defense & KAMAE_BYAKKO)
4190                 {
4191                         p_ptr->stat_add[A_STR] += 2;
4192                         p_ptr->stat_add[A_DEX] += 2;
4193                         p_ptr->stat_add[A_CON] -= 3;
4194                 }
4195                 else if (p_ptr->special_defense & KAMAE_SEIRYU)
4196                 {
4197                 }
4198                 else if (p_ptr->special_defense & KAMAE_GENBU)
4199                 {
4200                         p_ptr->stat_add[A_INT] -= 1;
4201                         p_ptr->stat_add[A_WIS] -= 1;
4202                         p_ptr->stat_add[A_DEX] -= 2;
4203                         p_ptr->stat_add[A_CON] += 3;
4204                 }
4205                 else if (p_ptr->special_defense & KAMAE_SUZAKU)
4206                 {
4207                         p_ptr->stat_add[A_STR] -= 2;
4208                         p_ptr->stat_add[A_INT] += 1;
4209                         p_ptr->stat_add[A_WIS] += 1;
4210                         p_ptr->stat_add[A_DEX] += 2;
4211                         p_ptr->stat_add[A_CON] -= 2;
4212                 }
4213         }
4214
4215         if (p_ptr->special_defense & KATA_KOUKIJIN)
4216         {
4217                 for (i = 0; i < 6; i++)
4218                         p_ptr->stat_add[i] += 5;
4219                 p_ptr->to_a -= 50;
4220                 p_ptr->dis_to_a -= 50;
4221         }
4222
4223         /* Hack -- aura of fire also provides light */
4224         if (p_ptr->sh_fire) p_ptr->lite = TRUE;
4225
4226         /* Golems also get an intrinsic AC bonus */
4227         if (prace_is_(RACE_GOLEM) || prace_is_(RACE_ANDROID))
4228         {
4229                 p_ptr->to_a += 10 + (p_ptr->lev * 2 / 5);
4230                 p_ptr->dis_to_a += 10 + (p_ptr->lev * 2 / 5);
4231         }
4232
4233         /* Calculate stats */
4234         for (i = 0; i < 6; i++)
4235         {
4236                 int top, use, ind;
4237
4238                 /* Extract the new "stat_use" value for the stat */
4239                 top = modify_stat_value(p_ptr->stat_max[i], p_ptr->stat_add[i]);
4240
4241                 /* Notice changes */
4242                 if (p_ptr->stat_top[i] != top)
4243                 {
4244                         /* Save the new value */
4245                         p_ptr->stat_top[i] = top;
4246
4247                         /* Redisplay the stats later */
4248                         p_ptr->redraw |= (PR_STATS);
4249
4250                         /* Window stuff */
4251                         p_ptr->window |= (PW_PLAYER);
4252                 }
4253
4254
4255                 /* Extract the new "stat_use" value for the stat */
4256                 use = modify_stat_value(p_ptr->stat_cur[i], p_ptr->stat_add[i]);
4257
4258                 if ((i == A_CHR) && (p_ptr->muta3 & MUT3_ILL_NORM))
4259                 {
4260                         /* 10 to 18/90 charisma, guaranteed, based on level */
4261                         if (use < 8 + 2 * p_ptr->lev)
4262                         {
4263                                 use = 8 + 2 * p_ptr->lev;
4264                         }
4265                 }
4266
4267                 /* Notice changes */
4268                 if (p_ptr->stat_use[i] != use)
4269                 {
4270                         /* Save the new value */
4271                         p_ptr->stat_use[i] = use;
4272
4273                         /* Redisplay the stats later */
4274                         p_ptr->redraw |= (PR_STATS);
4275
4276                         /* Window stuff */
4277                         p_ptr->window |= (PW_PLAYER);
4278                 }
4279
4280
4281                 /* Values: 3, 4, ..., 17 */
4282                 if (use <= 18) ind = (use - 3);
4283
4284                 /* Ranges: 18/00-18/09, ..., 18/210-18/219 */
4285                 else if (use <= 18+219) ind = (15 + (use - 18) / 10);
4286
4287                 /* Range: 18/220+ */
4288                 else ind = (37);
4289
4290                 /* Notice changes */
4291                 if (p_ptr->stat_ind[i] != ind)
4292                 {
4293                         /* Save the new index */
4294                         p_ptr->stat_ind[i] = ind;
4295
4296                         /* Change in CON affects Hitpoints */
4297                         if (i == A_CON)
4298                         {
4299                                 p_ptr->update |= (PU_HP);
4300                         }
4301
4302                         /* Change in INT may affect Mana/Spells */
4303                         else if (i == A_INT)
4304                         {
4305                                 if (mp_ptr->spell_stat == A_INT)
4306                                 {
4307                                         p_ptr->update |= (PU_MANA | PU_SPELLS);
4308                                 }
4309                         }
4310
4311                         /* Change in WIS may affect Mana/Spells */
4312                         else if (i == A_WIS)
4313                         {
4314                                 if (mp_ptr->spell_stat == A_WIS)
4315                                 {
4316                                         p_ptr->update |= (PU_MANA | PU_SPELLS);
4317                                 }
4318                         }
4319
4320                         /* Change in WIS may affect Mana/Spells */
4321                         else if (i == A_CHR)
4322                         {
4323                                 if (mp_ptr->spell_stat == A_CHR)
4324                                 {
4325                                         p_ptr->update |= (PU_MANA | PU_SPELLS);
4326                                 }
4327                         }
4328
4329                         /* Window stuff */
4330                         p_ptr->window |= (PW_PLAYER);
4331                 }
4332         }
4333
4334
4335         /* Apply temporary "stun" */
4336         if (p_ptr->stun > 50)
4337         {
4338                 p_ptr->to_h[0] -= 20;
4339                 p_ptr->to_h[1] -= 20;
4340                 p_ptr->to_h_b  -= 20;
4341                 p_ptr->to_h_m  -= 20;
4342                 p_ptr->dis_to_h[0] -= 20;
4343                 p_ptr->dis_to_h[1] -= 20;
4344                 p_ptr->dis_to_h_b  -= 20;
4345                 p_ptr->to_d[0] -= 20;
4346                 p_ptr->to_d[1] -= 20;
4347                 p_ptr->to_d_m -= 20;
4348                 p_ptr->dis_to_d[0] -= 20;
4349                 p_ptr->dis_to_d[1] -= 20;
4350         }
4351         else if (p_ptr->stun)
4352         {
4353                 p_ptr->to_h[0] -= 5;
4354                 p_ptr->to_h[1] -= 5;
4355                 p_ptr->to_h_b -= 5;
4356                 p_ptr->to_h_m -= 5;
4357                 p_ptr->dis_to_h[0] -= 5;
4358                 p_ptr->dis_to_h[1] -= 5;
4359                 p_ptr->dis_to_h_b -= 5;
4360                 p_ptr->to_d[0] -= 5;
4361                 p_ptr->to_d[1] -= 5;
4362                 p_ptr->to_d_m -= 5;
4363                 p_ptr->dis_to_d[0] -= 5;
4364                 p_ptr->dis_to_d[1] -= 5;
4365         }
4366
4367         /* wraith_form */
4368         if (p_ptr->wraith_form)
4369         {
4370                 p_ptr->reflect = TRUE;
4371         }
4372
4373         /* Temporary blessing */
4374         if (IS_BLESSED())
4375         {
4376                 p_ptr->to_a += 5;
4377                 p_ptr->dis_to_a += 5;
4378                 p_ptr->to_h[0] += 10;
4379                 p_ptr->to_h[1] += 10;
4380                 p_ptr->to_h_b  += 10;
4381                 p_ptr->to_h_m  += 10;
4382                 p_ptr->dis_to_h[0] += 10;
4383                 p_ptr->dis_to_h[1] += 10;
4384                 p_ptr->dis_to_h_b += 10;
4385         }
4386
4387         if (p_ptr->magicdef)
4388         {
4389                 p_ptr->resist_blind = TRUE;
4390                 p_ptr->resist_conf = TRUE;
4391                 p_ptr->reflect = TRUE;
4392                 p_ptr->free_act = TRUE;
4393                 p_ptr->ffall = TRUE;
4394         }
4395
4396         /* Temporary "Hero" */
4397         if (IS_HERO())
4398         {
4399                 p_ptr->to_h[0] += 12;
4400                 p_ptr->to_h[1] += 12;
4401                 p_ptr->to_h_b  += 12;
4402                 p_ptr->to_h_m  += 12;
4403                 p_ptr->dis_to_h[0] += 12;
4404                 p_ptr->dis_to_h[1] += 12;
4405                 p_ptr->dis_to_h_b  += 12;
4406         }
4407
4408         /* Temporary "Beserk" */
4409         if (p_ptr->shero)
4410         {
4411                 p_ptr->to_h[0] += 12;
4412                 p_ptr->to_h[1] += 12;
4413                 p_ptr->to_h_b  -= 12;
4414                 p_ptr->to_h_m  += 12;
4415                 p_ptr->to_d[0] += 3+(p_ptr->lev/5);
4416                 p_ptr->to_d[1] += 3+(p_ptr->lev/5);
4417                 p_ptr->to_d_m  += 3+(p_ptr->lev/5);
4418                 p_ptr->dis_to_h[0] += 12;
4419                 p_ptr->dis_to_h[1] += 12;
4420                 p_ptr->dis_to_h_b  -= 12;
4421                 p_ptr->dis_to_d[0] += 3+(p_ptr->lev/5);
4422                 p_ptr->dis_to_d[1] += 3+(p_ptr->lev/5);
4423                 p_ptr->to_a -= 10;
4424                 p_ptr->dis_to_a -= 10;
4425                 p_ptr->skill_stl -= 7;
4426                 p_ptr->skill_dev -= 20;
4427                 p_ptr->skill_sav -= 30;
4428                 p_ptr->skill_srh -= 15;
4429                 p_ptr->skill_fos -= 15;
4430                 p_ptr->skill_tht -= 20;
4431                 p_ptr->skill_dig += 30;
4432         }
4433
4434         /* Temporary "fast" */
4435         if (IS_FAST())
4436         {
4437                 p_ptr->pspeed += 10;
4438         }
4439
4440         /* Temporary "slow" */
4441         if (p_ptr->slow)
4442         {
4443                 p_ptr->pspeed -= 10;
4444         }
4445
4446         /* Temporary "telepathy" */
4447         if (IS_TIM_ESP())
4448         {
4449                 p_ptr->telepathy = TRUE;
4450         }
4451
4452         if (p_ptr->ele_immune)
4453         {
4454                 if (p_ptr->special_defense & DEFENSE_ACID)
4455                         p_ptr->immune_acid = TRUE;
4456                 else if (p_ptr->special_defense & DEFENSE_ELEC)
4457                         p_ptr->immune_elec = TRUE;
4458                 else if (p_ptr->special_defense & DEFENSE_FIRE)
4459                         p_ptr->immune_fire = TRUE;
4460                 else if (p_ptr->special_defense & DEFENSE_COLD)
4461                         p_ptr->immune_cold = TRUE;
4462         }
4463
4464         /* Temporary see invisible */
4465         if (p_ptr->tim_invis)
4466         {
4467                 p_ptr->see_inv = TRUE;
4468         }
4469
4470         /* Temporary infravision boost */
4471         if (p_ptr->tim_infra)
4472         {
4473                 p_ptr->see_infra+=3;
4474         }
4475
4476         /* Temporary regeneration boost */
4477         if (p_ptr->tim_regen)
4478         {
4479                 p_ptr->regenerate = TRUE;
4480         }
4481
4482         /* Temporary levitation */
4483         if (p_ptr->tim_ffall)
4484         {
4485                 p_ptr->ffall = TRUE;
4486         }
4487
4488         /* Hack -- Hero/Shero -> Res fear */
4489         if (IS_HERO() || p_ptr->shero)
4490         {
4491                 p_ptr->resist_fear = TRUE;
4492         }
4493
4494
4495         /* Hack -- Telepathy Change */
4496         if (p_ptr->telepathy != old_telepathy)
4497         {
4498                 p_ptr->update |= (PU_MONSTERS);
4499         }
4500
4501         if ((p_ptr->esp_animal != old_esp_animal) ||
4502             (p_ptr->esp_undead != old_esp_undead) ||
4503             (p_ptr->esp_demon != old_esp_demon) ||
4504             (p_ptr->esp_orc != old_esp_orc) ||
4505             (p_ptr->esp_troll != old_esp_troll) ||
4506             (p_ptr->esp_giant != old_esp_giant) ||
4507             (p_ptr->esp_dragon != old_esp_dragon) ||
4508             (p_ptr->esp_human != old_esp_human) ||
4509             (p_ptr->esp_evil != old_esp_evil) ||
4510             (p_ptr->esp_good != old_esp_good) ||
4511             (p_ptr->esp_nonliving != old_esp_nonliving) ||
4512             (p_ptr->esp_unique != old_esp_unique))
4513         {
4514                 p_ptr->update |= (PU_MONSTERS);
4515         }
4516
4517         /* Hack -- See Invis Change */
4518         if (p_ptr->see_inv != old_see_inv)
4519         {
4520                 p_ptr->update |= (PU_MONSTERS);
4521         }
4522
4523         /* Bloating slows the player down (a little) */
4524         if (p_ptr->food >= PY_FOOD_MAX) p_ptr->pspeed -= 10;
4525
4526         if (p_ptr->special_defense & KAMAE_SUZAKU) p_ptr->pspeed += 10;
4527
4528         if (!buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM))
4529         {
4530                 p_ptr->to_h[0] += (p_ptr->skill_exp[GINOU_SUDE] - WEAPON_EXP_BEGINNER) / 200;
4531                 p_ptr->dis_to_h[0] += (p_ptr->skill_exp[GINOU_SUDE] - WEAPON_EXP_BEGINNER) / 200;
4532         }
4533
4534         if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
4535         {
4536                 int penalty1, penalty2;
4537                 penalty1 = ((100 - p_ptr->skill_exp[GINOU_NITOURYU] / 160) - (130 - inventory[INVEN_RARM].weight) / 8);
4538                 penalty2 = ((100 - p_ptr->skill_exp[GINOU_NITOURYU] / 160) - (130 - inventory[INVEN_LARM].weight) / 8);
4539                 if ((inventory[INVEN_RARM].name1 == ART_QUICKTHORN) && (inventory[INVEN_LARM].name1 == ART_TINYTHORN))
4540                 {
4541                         penalty1 = penalty1 / 2 - 5;
4542                         penalty2 = penalty2 / 2 - 5;
4543                         p_ptr->pspeed += 7;
4544                         p_ptr->to_a += 10;
4545                         p_ptr->dis_to_a += 10;
4546                 }
4547                 if (easy_2weapon)
4548                 {
4549                         if (penalty1 > 0) penalty1 /= 2;
4550                         if (penalty2 > 0) penalty2 /= 2;
4551                 }
4552                 else if ((inventory[INVEN_LARM].tval == TV_SWORD) && ((inventory[INVEN_LARM].sval == SV_MAIN_GAUCHE) || (inventory[INVEN_LARM].sval == SV_WAKIZASHI)))
4553                 {
4554                         penalty1 = MAX(0, penalty1 - 10);
4555                         penalty2 = MAX(0, penalty2 - 10);
4556                 }
4557                 if ((inventory[INVEN_RARM].name1 == ART_MUSASI_KATANA) && (inventory[INVEN_LARM].name1 == ART_MUSASI_WAKIZASI))
4558                 {
4559                         penalty1 = MIN(0, penalty1);
4560                         penalty2 = MIN(0, penalty2);
4561                         p_ptr->to_a += 10;
4562                         p_ptr->dis_to_a += 10;
4563                 }
4564                 else
4565                 {
4566                         if ((inventory[INVEN_RARM].name1 == ART_MUSASI_KATANA) && (penalty1 > 0))
4567                                 penalty1 /= 2;
4568                         if ((inventory[INVEN_LARM].name1 == ART_MUSASI_WAKIZASI) && (penalty2 > 0))
4569                                 penalty2 /= 2;
4570                 }
4571                 if (inventory[INVEN_RARM].tval == TV_POLEARM) penalty1 += 10;
4572                 if (inventory[INVEN_LARM].tval == TV_POLEARM) penalty2 += 10;
4573                 p_ptr->to_h[0] -= penalty1;
4574                 p_ptr->to_h[1] -= penalty2;
4575                 p_ptr->dis_to_h[0] -= penalty1;
4576                 p_ptr->dis_to_h[1] -= penalty2;
4577         }
4578
4579         /* Extract the current weight (in tenth pounds) */
4580         j = p_ptr->total_weight;
4581
4582         /* Extract the "weight limit" (in tenth pounds) */
4583         i = weight_limit();
4584
4585         if (p_ptr->riding)
4586         {
4587                 int speed = m_list[p_ptr->riding].mspeed;
4588                 if (m_list[p_ptr->riding].mspeed > 110)
4589                 {
4590                         p_ptr->pspeed = 110 + (s16b)((speed - 110) * (p_ptr->skill_exp[GINOU_RIDING] * 3 + p_ptr->lev * 160L - 10000L) / (22000L));
4591                         if (p_ptr->pspeed < 110) p_ptr->pspeed = 110;
4592                 }
4593                 else
4594                 {
4595                         p_ptr->pspeed = speed;
4596                 }
4597                 if (m_list[p_ptr->riding].fast) p_ptr->pspeed += 10;
4598                 if (m_list[p_ptr->riding].slow) p_ptr->pspeed -= 10;
4599                 if (r_info[m_list[p_ptr->riding].r_idx].flags7 & RF7_CAN_FLY) p_ptr->ffall = TRUE;
4600                 if (r_info[m_list[p_ptr->riding].r_idx].flags7 & (RF7_CAN_SWIM | RF7_AQUATIC)) p_ptr->can_swim = TRUE;
4601
4602                 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;
4603
4604                 i = 3000 + r_info[m_list[p_ptr->riding].r_idx].level * 50;
4605         }
4606
4607         /* XXX XXX XXX Apply "encumbrance" from weight */
4608         if (j > i/2) p_ptr->pspeed -= ((j - (i/2)) / (i / 10));
4609
4610         /* Searching slows the player down */
4611         if (p_ptr->action == ACTION_SEARCH) p_ptr->pspeed -= 10;
4612
4613         /* Actual Modifier Bonuses (Un-inflate stat bonuses) */
4614         p_ptr->to_a += ((int)(adj_dex_ta[p_ptr->stat_ind[A_DEX]]) - 128);
4615         p_ptr->to_d[0] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4616         p_ptr->to_d[1] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4617         p_ptr->to_d_m  += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4618         p_ptr->to_h[0] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4619         p_ptr->to_h[1] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4620         p_ptr->to_h_b  += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4621         p_ptr->to_h_m  += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4622         p_ptr->to_h[0] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4623         p_ptr->to_h[1] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4624         p_ptr->to_h_b  += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4625         p_ptr->to_h_m  += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4626
4627         /* Displayed Modifier Bonuses (Un-inflate stat bonuses) */
4628         p_ptr->dis_to_a += ((int)(adj_dex_ta[p_ptr->stat_ind[A_DEX]]) - 128);
4629         p_ptr->dis_to_d[0] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4630         p_ptr->dis_to_d[1] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4631         p_ptr->dis_to_h[0] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4632         p_ptr->dis_to_h[1] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4633         p_ptr->dis_to_h_b  += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4634         p_ptr->dis_to_h[0] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4635         p_ptr->dis_to_h[1] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4636         p_ptr->dis_to_h_b  += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4637
4638
4639         /* Obtain the "hold" value */
4640         hold = adj_str_hold[p_ptr->stat_ind[A_STR]];
4641
4642
4643         /* Examine the "current bow" */
4644         o_ptr = &inventory[INVEN_BOW];
4645
4646
4647         /* Assume not heavy */
4648         p_ptr->heavy_shoot = FALSE;
4649
4650         /* It is hard to carholdry a heavy bow */
4651         if (hold < o_ptr->weight / 10)
4652         {
4653                 /* Hard to wield a heavy bow */
4654                 p_ptr->to_h_b  += 2 * (hold - o_ptr->weight / 10);
4655                 p_ptr->dis_to_h_b  += 2 * (hold - o_ptr->weight / 10);
4656
4657                 /* Heavy Bow */
4658                 p_ptr->heavy_shoot = TRUE;
4659         }
4660
4661
4662         /* Compute "extra shots" if needed */
4663         if (o_ptr->k_idx)
4664         {
4665                 /* Analyze the launcher */
4666                 switch (o_ptr->sval)
4667                 {
4668                         case SV_SLING:
4669                         {
4670                                 p_ptr->tval_ammo = TV_SHOT;
4671                                 break;
4672                         }
4673
4674                         case SV_SHORT_BOW:
4675                         case SV_LONG_BOW:
4676                         case SV_NAMAKE_BOW:
4677                         {
4678                                 p_ptr->tval_ammo = TV_ARROW;
4679                                 break;
4680                         }
4681
4682                         case SV_LIGHT_XBOW:
4683                         case SV_HEAVY_XBOW:
4684                         {
4685                                 p_ptr->tval_ammo = TV_BOLT;
4686                                 break;
4687                         }
4688                         case SV_CRIMSON:
4689                         {
4690                                 p_ptr->tval_ammo = TV_NO_AMMO;
4691                                 break;
4692                         }
4693                 }
4694
4695                 /* Apply special flags */
4696                 if (o_ptr->k_idx && !p_ptr->heavy_shoot)
4697                 {
4698                         /* Extra shots */
4699                         p_ptr->num_fire += (extra_shots * 100);
4700
4701                         /* Hack -- Rangers love Bows */
4702                         if ((p_ptr->pclass == CLASS_RANGER) &&
4703                             (p_ptr->tval_ammo == TV_ARROW))
4704                         {
4705                                 p_ptr->num_fire += (p_ptr->lev * 4);
4706                         }
4707
4708                         if ((p_ptr->pclass == CLASS_CAVALRY) &&
4709                             (p_ptr->tval_ammo == TV_ARROW))
4710                         {
4711                                 p_ptr->num_fire += (p_ptr->lev * 3);
4712                         }
4713
4714                         if (p_ptr->pclass == CLASS_ARCHER)
4715                         {
4716                                 if (p_ptr->tval_ammo == TV_ARROW)
4717                                         p_ptr->num_fire += ((p_ptr->lev * 5)+50);
4718                                 else if ((p_ptr->tval_ammo == TV_BOLT) || (p_ptr->tval_ammo == TV_SHOT))
4719                                         p_ptr->num_fire += (p_ptr->lev * 4);
4720                         }
4721
4722                         /*
4723                          * Addendum -- also "Reward" high level warriors,
4724                          * with _any_ missile weapon -- TY
4725                          */
4726                         if (p_ptr->pclass == CLASS_WARRIOR &&
4727                            (p_ptr->tval_ammo <= TV_BOLT) &&
4728                            (p_ptr->tval_ammo >= TV_SHOT))
4729                         {
4730                                 p_ptr->num_fire += (p_ptr->lev * 2);
4731                         }
4732                         if ((p_ptr->pclass == CLASS_ROGUE) &&
4733                             (p_ptr->tval_ammo == TV_SHOT))
4734                         {
4735                                 p_ptr->num_fire += (p_ptr->lev * 4);
4736                         }
4737                 }
4738         }
4739
4740         if (p_ptr->ryoute)
4741                 hold *= 2;
4742
4743         for(i = 0 ; i < 2 ; i++)
4744         {
4745                 /* Examine the "main weapon" */
4746                 o_ptr = &inventory[INVEN_RARM+i];
4747
4748                 object_flags(o_ptr, flgs);
4749
4750                 /* Assume not heavy */
4751                 p_ptr->heavy_wield[i] = FALSE;
4752                 p_ptr->icky_wield[i] = FALSE;
4753                 p_ptr->riding_wield[i] = FALSE;
4754
4755                 if (!buki_motteruka(INVEN_RARM+i)) {p_ptr->num_blow[i]=1;continue;}
4756                 /* It is hard to hold a heavy weapon */
4757                 if (hold < o_ptr->weight / 10)
4758                 {
4759                         /* Hard to wield a heavy weapon */
4760                         p_ptr->to_h[i] += 2 * (hold - o_ptr->weight / 10);
4761                         p_ptr->dis_to_h[i] += 2 * (hold - o_ptr->weight / 10);
4762
4763                         /* Heavy weapon */
4764                         p_ptr->heavy_wield[i] = TRUE;
4765                 }
4766                 else if (p_ptr->ryoute && (hold < o_ptr->weight/5)) omoi = TRUE;
4767
4768                 if ((i == 1) && (o_ptr->tval == TV_SWORD) && ((o_ptr->sval == SV_MAIN_GAUCHE) || (o_ptr->sval == SV_WAKIZASHI)))
4769                 {
4770                         p_ptr->to_a += 5;
4771                         p_ptr->dis_to_a += 5;
4772                 }
4773
4774                 /* Normal weapons */
4775                 if (o_ptr->k_idx && !p_ptr->heavy_wield[i])
4776                 {
4777                         int str_index, dex_index;
4778
4779                         int num = 0, wgt = 0, mul = 0, div = 0;
4780
4781                         /* Analyze the class */
4782                         switch (p_ptr->pclass)
4783                         {
4784                                 /* Warrior */
4785                                 case CLASS_WARRIOR:
4786                                         num = 6; wgt = 70; mul = 5; break;
4787
4788                                 /* Berserker */
4789                                 case CLASS_BERSERKER:
4790                                         num = 6; wgt = 70; mul = 7; break;
4791
4792                                 /* Mage */
4793                                 case CLASS_MAGE:
4794                                 case CLASS_HIGH_MAGE:
4795                                 case CLASS_BLUE_MAGE:
4796                                         num = 3; wgt = 100; mul = 2; break;
4797
4798                                 /* Priest, Mindcrafter */
4799                                 case CLASS_PRIEST:
4800                                 case CLASS_MAGIC_EATER:
4801                                 case CLASS_MINDCRAFTER:
4802                                         num = 5; wgt = 100; mul = 3; break;
4803
4804                                 /* Rogue */
4805                                 case CLASS_ROGUE:
4806                                         num = 5; wgt = 40; mul = 3; break;
4807
4808                                 /* Ranger */
4809                                 case CLASS_RANGER:
4810                                         num = 5; wgt = 70; mul = 4; break;
4811
4812                                 /* Paladin */
4813                                 case CLASS_PALADIN:
4814                                 case CLASS_SAMURAI:
4815                                         num = 5; wgt = 70; mul = 4; break;
4816
4817                                 /* Kaji */
4818                                 case CLASS_SMITH:
4819                                         num = 5; wgt = 150; mul = 5; break;
4820
4821                                 /* Warrior-Mage */
4822                                 case CLASS_WARRIOR_MAGE:
4823                                 case CLASS_RED_MAGE:
4824                                         num = 5; wgt = 70; mul = 3; break;
4825
4826                                 /* Chaos Warrior */
4827                                 case CLASS_CHAOS_WARRIOR:
4828                                         num = 5; wgt = 70; mul = 4; break;
4829
4830                                 /* Monk */
4831                                 case CLASS_MONK:
4832                                         num = 5; wgt = 60; mul = 3; break;
4833
4834                                 /* Tourist */
4835                                 case CLASS_TOURIST:
4836                                         num = 4; wgt = 100; mul = 3; break;
4837
4838                                 /* Imitator */
4839                                 case CLASS_IMITATOR:
4840                                         num = 5; wgt = 70; mul = 4; break;
4841
4842                                 /* Beastmaster */
4843                                 case CLASS_BEASTMASTER:
4844                                         num = 5; wgt = 70; mul = 3; break;
4845
4846                                 case CLASS_CAVALRY:
4847                                         if ((p_ptr->riding) && (have_flag(flgs, TR_RIDING))) {num = 5; wgt = 70; mul = 4;}
4848                                         else {num = 5; wgt = 100; mul = 3;}
4849                                         break;
4850
4851                                 /* Sorcerer */
4852                                 case CLASS_SORCERER:
4853                                         num = 1; wgt = 1; mul = 1; break;
4854
4855                                 /* Archer, Magic eater */
4856                                 case CLASS_ARCHER:
4857                                 case CLASS_BARD:
4858                                         num = 4; wgt = 70; mul = 2; break;
4859
4860                                 /* ForceTrainer */
4861                                 case CLASS_FORCETRAINER:
4862                                         num = 4; wgt = 60; mul = 2; break;
4863
4864                                 /* Mirror Master */
4865                                 case CLASS_MIRROR_MASTER:
4866                                         num = 3; wgt = 100; mul = 3; break;
4867
4868                                 /* Ninja */
4869                                 case CLASS_NINJA:
4870                                         num = 4; wgt = 20; mul = 1; break;
4871                         }
4872
4873                         /* Enforce a minimum "weight" (tenth pounds) */
4874                         div = ((o_ptr->weight < wgt) ? wgt : o_ptr->weight);
4875
4876                         /* Access the strength vs weight */
4877                         str_index = (adj_str_blow[p_ptr->stat_ind[A_STR]] * mul / div);
4878
4879                         if (p_ptr->ryoute && !omoi) str_index++;
4880                         if (p_ptr->pclass == CLASS_NINJA) str_index = MAX(0, str_index-1);
4881
4882                         /* Maximal value */
4883                         if (str_index > 11) str_index = 11;
4884
4885                         /* Index by dexterity */
4886                         dex_index = (adj_dex_blow[p_ptr->stat_ind[A_DEX]]);
4887
4888                         /* Maximal value */
4889                         if (dex_index > 11) dex_index = 11;
4890
4891                         /* Use the blows table */
4892                         p_ptr->num_blow[i] = blows_table[str_index][dex_index];
4893
4894                         /* Maximal value */
4895                         if (p_ptr->num_blow[i] > num) p_ptr->num_blow[i] = num;
4896
4897                         /* Add in the "bonus blows" */
4898                         p_ptr->num_blow[i] += extra_blows[i];
4899
4900
4901                         if (p_ptr->pclass == CLASS_WARRIOR) p_ptr->num_blow[i] += (p_ptr->lev / 40);
4902                         else if (p_ptr->pclass == CLASS_BERSERKER)
4903                         {
4904                                 p_ptr->num_blow[i] += (p_ptr->lev / 23);
4905                         }
4906                         else if ((p_ptr->pclass == CLASS_ROGUE) && (o_ptr->weight < 50) && (p_ptr->stat_ind[A_DEX] >= 30)) p_ptr->num_blow[i] ++;
4907
4908                         if (p_ptr->special_defense & KATA_FUUJIN) p_ptr->num_blow[i] -= 1;
4909
4910                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) p_ptr->num_blow[i] = 1;
4911
4912
4913                         /* Require at least one blow */
4914                         if (p_ptr->num_blow[i] < 1) p_ptr->num_blow[i] = 1;
4915
4916                         /* Boost digging skill by weapon weight */
4917                         p_ptr->skill_dig += (o_ptr->weight / 10);
4918                 }
4919
4920                 /* Assume okay */
4921                 /* Priest weapon penalty for non-blessed edged weapons */
4922                 if ((p_ptr->pclass == CLASS_PRIEST) && (!(have_flag(flgs, TR_BLESSED))) &&
4923                     ((o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM)))
4924                 {
4925                         /* Reduce the real bonuses */
4926                         p_ptr->to_h[i] -= 2;
4927                         p_ptr->to_d[i] -= 2;
4928
4929                         /* Reduce the mental bonuses */
4930                         p_ptr->dis_to_h[i] -= 2;
4931                         p_ptr->dis_to_d[i] -= 2;
4932
4933                         /* Icky weapon */
4934                         p_ptr->icky_wield[i] = TRUE;
4935                 }
4936                 else if (p_ptr->pclass == CLASS_BERSERKER)
4937                 {
4938                         p_ptr->to_h[i] += p_ptr->lev/5;
4939                         p_ptr->to_d[i] += p_ptr->lev/6;
4940                         p_ptr->dis_to_h[i] += p_ptr->lev/5;
4941                         p_ptr->dis_to_d[i] += p_ptr->lev/6;
4942                         if (!p_ptr->hidarite || p_ptr->ryoute)
4943                         {
4944                                 p_ptr->to_h[i] += p_ptr->lev/5;
4945                                 p_ptr->to_d[i] += p_ptr->lev/6;
4946                                 p_ptr->dis_to_h[i] += p_ptr->lev/5;
4947                                 p_ptr->dis_to_d[i] += p_ptr->lev/6;
4948                         }
4949                 }
4950                 else if (p_ptr->pclass == CLASS_SORCERER)
4951                 {
4952                         if (!((o_ptr->tval == TV_HAFTED) && ((o_ptr->sval == SV_WIZSTAFF) || (o_ptr->sval == SV_NAMAKE_HAMMER))))
4953                         {
4954                                 /* Reduce the real bonuses */
4955                                 p_ptr->to_h[i] -= 200;
4956                                 p_ptr->to_d[i] -= 200;
4957
4958                                 /* Reduce the mental bonuses */
4959                                 p_ptr->dis_to_h[i] -= 200;
4960                                 p_ptr->dis_to_d[i] -= 200;
4961
4962                                 /* Icky weapon */
4963                                 p_ptr->icky_wield[i] = TRUE;
4964                         }
4965                         else
4966                         {
4967                                 /* Reduce the real bonuses */
4968                                 p_ptr->to_h[i] -= 30;
4969                                 p_ptr->to_d[i] -= 10;
4970
4971                                 /* Reduce the mental bonuses */
4972                                 p_ptr->dis_to_h[i] -= 30;
4973                                 p_ptr->dis_to_d[i] -= 10;
4974                         }
4975                 }
4976                 if (p_ptr->riding)
4977                 {
4978                         if ((o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE)))
4979                         {
4980                                 p_ptr->to_h[i] +=15;
4981                                 p_ptr->dis_to_h[i] +=15;
4982                         }
4983                         else if (!(have_flag(flgs, TR_RIDING)))
4984                         {
4985                                 int penalty;
4986                                 if ((p_ptr->pclass == CLASS_BEASTMASTER) || (p_ptr->pclass == CLASS_CAVALRY))
4987                                 {
4988                                         penalty = 5;
4989                                 }
4990                                 else
4991                                 {
4992                                         penalty = r_info[m_list[p_ptr->riding].r_idx].level - p_ptr->skill_exp[GINOU_RIDING] / 80;
4993                                         penalty += 30;
4994                                         if (penalty < 30) penalty = 30;
4995                                 }
4996                                 p_ptr->to_h[i] -= penalty;
4997                                 p_ptr->dis_to_h[i] -= penalty;
4998
4999                                 /* Riding weapon */
5000                                 p_ptr->riding_wield[i] = TRUE;
5001                         }
5002                 }
5003         }
5004
5005         if (p_ptr->riding)
5006         {
5007                 int penalty = 0;
5008
5009                 p_ptr->riding_ryoute = FALSE;
5010                 if (p_ptr->ryoute || !empty_hands(FALSE)) p_ptr->riding_ryoute = TRUE;
5011
5012                 if ((p_ptr->pclass == CLASS_BEASTMASTER) || (p_ptr->pclass == CLASS_CAVALRY))
5013                 {
5014                         if (p_ptr->tval_ammo != TV_ARROW) penalty = 5;
5015                 }
5016                 else
5017                 {
5018                         penalty = r_info[m_list[p_ptr->riding].r_idx].level - p_ptr->skill_exp[GINOU_RIDING] / 80;
5019                         penalty += 30;
5020                         if (penalty < 30) penalty = 30;
5021                 }
5022                 if (p_ptr->tval_ammo == TV_BOLT) penalty *= 2;
5023                 p_ptr->to_h_b -= penalty;
5024                 p_ptr->dis_to_h_b -= penalty;
5025         }
5026
5027         /* Different calculation for monks with empty hands */
5028         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER) || (p_ptr->pclass == CLASS_BERSERKER)) && (empty_hands(TRUE) > 1))
5029         {
5030                 int blow_base = p_ptr->lev + adj_dex_blow[p_ptr->stat_ind[A_DEX]];
5031                 p_ptr->num_blow[0] = 0;
5032
5033                 if (p_ptr->pclass == CLASS_FORCETRAINER)
5034                 {
5035                         if (blow_base > 18) p_ptr->num_blow[0]++;
5036                         if (blow_base > 31) p_ptr->num_blow[0]++;
5037                         if (blow_base > 44) p_ptr->num_blow[0]++;
5038                         if (blow_base > 58) p_ptr->num_blow[0]++;
5039                         if (p_ptr->magic_num1[0])
5040                         {
5041                                 p_ptr->to_d[0] += (p_ptr->magic_num1[0]/5);
5042                                 p_ptr->dis_to_d[0] += (p_ptr->magic_num1[0]/5);
5043                         }
5044                 }
5045                 else
5046                 {
5047                         if (blow_base > 12) p_ptr->num_blow[0]++;
5048                         if (blow_base > 22) p_ptr->num_blow[0]++;
5049                         if (blow_base > 31) p_ptr->num_blow[0]++;
5050                         if (blow_base > 39) p_ptr->num_blow[0]++;
5051                         if (blow_base > 46) p_ptr->num_blow[0]++;
5052                         if (blow_base > 53) p_ptr->num_blow[0]++;
5053                         if (blow_base > 59) p_ptr->num_blow[0]++;
5054                 }
5055
5056                 if (heavy_armor() && (p_ptr->pclass != CLASS_BERSERKER))
5057                         p_ptr->num_blow[0] /= 2;
5058                 else
5059                 {
5060                         p_ptr->to_h[0] += (p_ptr->lev / 3);
5061                         p_ptr->dis_to_h[0] += (p_ptr->lev / 3);
5062
5063                         p_ptr->to_d[0] += (p_ptr->lev / 6);
5064                         p_ptr->dis_to_d[0] += (p_ptr->lev / 6);
5065                 }
5066
5067                 if (p_ptr->special_defense & KAMAE_BYAKKO)
5068                 {
5069                         p_ptr->to_a -= 40;
5070                         p_ptr->dis_to_a -= 40;
5071                         
5072                 }
5073                 else if (p_ptr->special_defense & KAMAE_SEIRYU)
5074                 {
5075                         p_ptr->to_a -= 50;
5076                         p_ptr->dis_to_a -= 50;
5077                         p_ptr->resist_acid = TRUE;
5078                         p_ptr->resist_fire = TRUE;
5079                         p_ptr->resist_elec = TRUE;
5080                         p_ptr->resist_cold = TRUE;
5081                         p_ptr->resist_pois = TRUE;
5082                         p_ptr->sh_fire = TRUE;
5083                         p_ptr->sh_elec = TRUE;
5084                         p_ptr->sh_cold = TRUE;
5085                         p_ptr->ffall = TRUE;
5086                 }
5087                 else if (p_ptr->special_defense & KAMAE_GENBU)
5088                 {
5089                         p_ptr->to_a += (p_ptr->lev*p_ptr->lev)/50;
5090                         p_ptr->dis_to_a += (p_ptr->lev*p_ptr->lev)/50;
5091                         p_ptr->reflect = TRUE;
5092                         p_ptr->num_blow[0] -= 2;
5093                         if ((p_ptr->pclass == CLASS_MONK) && (p_ptr->lev > 42)) p_ptr->num_blow[0]--;
5094                         if (p_ptr->num_blow[0] < 0) p_ptr->num_blow[0] = 0;
5095                 }
5096                 else if (p_ptr->special_defense & KAMAE_SUZAKU)
5097                 {
5098                         p_ptr->to_h[0] -= (p_ptr->lev / 3);
5099                         p_ptr->to_d[0] -= (p_ptr->lev / 6);
5100
5101                         p_ptr->dis_to_h[0] -= (p_ptr->lev / 3);
5102                         p_ptr->dis_to_d[0] -= (p_ptr->lev / 6);
5103                         p_ptr->num_blow[0] /= 2;
5104                         p_ptr->ffall = TRUE;
5105                 }
5106
5107                 p_ptr->num_blow[0] += 1+extra_blows[0];
5108         }
5109
5110         monk_armour_aux = FALSE;
5111
5112         if (heavy_armor())
5113         {
5114                 monk_armour_aux = TRUE;
5115         }
5116
5117         for (i = 0 ; i < 2 ; i++)
5118         {
5119                 if (buki_motteruka(INVEN_RARM+i))
5120                 {
5121                         int tval = inventory[INVEN_RARM+i].tval - TV_BOW;
5122                         int sval = inventory[INVEN_RARM+i].sval;
5123
5124                         p_ptr->to_h[i] += (p_ptr->weapon_exp[tval][sval] - WEAPON_EXP_BEGINNER) / 200;
5125                         p_ptr->dis_to_h[i] += (p_ptr->weapon_exp[tval][sval] - WEAPON_EXP_BEGINNER) / 200;
5126                         if ((p_ptr->pclass == CLASS_MONK) && !(s_info[CLASS_MONK].w_max[tval][sval]))
5127                         {
5128                                 p_ptr->to_h[i] -= 40;
5129                                 p_ptr->dis_to_h[i] -= 40;
5130                                 p_ptr->icky_wield[i] = TRUE;
5131                         }
5132                         else if ((p_ptr->pclass == CLASS_FORCETRAINER) && !(s_info[CLASS_FORCETRAINER].w_max[tval][sval]))
5133                         {
5134                                 p_ptr->to_h[i] -= 40;
5135                                 p_ptr->dis_to_h[i] -= 40;
5136                                 p_ptr->icky_wield[i] = TRUE;
5137                         }
5138                         else if (p_ptr->pclass == CLASS_NINJA)
5139                         {
5140                                 if ((s_info[CLASS_NINJA].w_max[tval][sval] <= WEAPON_EXP_BEGINNER) || (inventory[INVEN_LARM-i].tval == TV_SHIELD))
5141                                 {
5142                                         p_ptr->to_h[i] -= 40;
5143                                         p_ptr->dis_to_h[i] -= 40;
5144                                         p_ptr->icky_wield[i] = TRUE;
5145                                         p_ptr->num_blow[i] /= 2;
5146                                         if (p_ptr->num_blow[i] < 1) p_ptr->num_blow[i] = 1;
5147                                 }
5148                         }
5149                 }
5150         }
5151
5152         /* Temporary lightspeed */
5153         if ((p_ptr->lightspeed && !p_ptr->riding) || (p_ptr->pspeed > 209))
5154         {
5155                 p_ptr->pspeed = 209;
5156         }
5157         if (p_ptr->pspeed < 11) p_ptr->pspeed = 11;
5158
5159         /* Display the speed (if needed) */
5160         if (p_ptr->pspeed != old_speed) p_ptr->redraw |= (PR_SPEED);
5161
5162         if (yoiyami)
5163         {
5164                 if (p_ptr->to_a > (0 - p_ptr->ac))
5165                         p_ptr->to_a = 0 - p_ptr->ac;
5166                 if (p_ptr->dis_to_a > (0 - p_ptr->dis_ac))
5167                         p_ptr->dis_to_a = 0 - p_ptr->dis_ac;
5168         }
5169
5170         /* Redraw armor (if needed) */
5171         if ((p_ptr->dis_ac != old_dis_ac) || (p_ptr->dis_to_a != old_dis_to_a))
5172         {
5173                 /* Redraw */
5174                 p_ptr->redraw |= (PR_ARMOR);
5175
5176                 /* Window stuff */
5177                 p_ptr->window |= (PW_PLAYER);
5178         }
5179
5180
5181         if (p_ptr->ryoute && !omoi)
5182         {
5183                 int bonus_to_h=0, bonus_to_d=0;
5184                 bonus_to_d = ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128)/2;
5185                 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);
5186
5187                 p_ptr->to_h[0] += MAX(bonus_to_h,1);
5188                 p_ptr->dis_to_h[0] += MAX(bonus_to_h,1);
5189                 p_ptr->to_d[0] += MAX(bonus_to_d,1);
5190                 p_ptr->dis_to_d[0] += MAX(bonus_to_d,1);
5191         }
5192
5193         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER) || (p_ptr->pclass == CLASS_BERSERKER)) && (empty_hands(TRUE) == 3)) p_ptr->ryoute = FALSE;
5194
5195         /* Affect Skill -- stealth (bonus one) */
5196         p_ptr->skill_stl += 1;
5197
5198         if (IS_TIM_STEALTH()) p_ptr->skill_stl += 99;
5199
5200         /* Affect Skill -- disarming (DEX and INT) */
5201         p_ptr->skill_dis += adj_dex_dis[p_ptr->stat_ind[A_DEX]];
5202         p_ptr->skill_dis += adj_int_dis[p_ptr->stat_ind[A_INT]];
5203
5204         /* Affect Skill -- magic devices (INT) */
5205         p_ptr->skill_dev += adj_int_dev[p_ptr->stat_ind[A_INT]];
5206
5207         /* Affect Skill -- saving throw (WIS) */
5208         p_ptr->skill_sav += adj_wis_sav[p_ptr->stat_ind[A_WIS]];
5209
5210         /* Affect Skill -- digging (STR) */
5211         p_ptr->skill_dig += adj_str_dig[p_ptr->stat_ind[A_STR]];
5212
5213         /* Affect Skill -- disarming (Level, by Class) */
5214         p_ptr->skill_dis += ((cp_ptr->x_dis * p_ptr->lev / 10) + (ap_ptr->a_dis * p_ptr->lev / 50));
5215
5216         /* Affect Skill -- magic devices (Level, by Class) */
5217         p_ptr->skill_dev += ((cp_ptr->x_dev * p_ptr->lev / 10) + (ap_ptr->a_dev * p_ptr->lev / 50));
5218
5219         /* Affect Skill -- saving throw (Level, by Class) */
5220         p_ptr->skill_sav += ((cp_ptr->x_sav * p_ptr->lev / 10) + (ap_ptr->a_sav * p_ptr->lev / 50));
5221
5222         /* Affect Skill -- stealth (Level, by Class) */
5223         p_ptr->skill_stl += (cp_ptr->x_stl * p_ptr->lev / 10);
5224
5225         /* Affect Skill -- search ability (Level, by Class) */
5226         p_ptr->skill_srh += (cp_ptr->x_srh * p_ptr->lev / 10);
5227
5228         /* Affect Skill -- search frequency (Level, by Class) */
5229         p_ptr->skill_fos += (cp_ptr->x_fos * p_ptr->lev / 10);
5230
5231         /* Affect Skill -- combat (normal) (Level, by Class) */
5232         p_ptr->skill_thn += ((cp_ptr->x_thn * p_ptr->lev / 10) + (ap_ptr->a_thn * p_ptr->lev / 50));
5233
5234         /* Affect Skill -- combat (shooting) (Level, by Class) */
5235         p_ptr->skill_thb += ((cp_ptr->x_thb * p_ptr->lev / 10) + (ap_ptr->a_thb * p_ptr->lev / 50));
5236
5237         /* Affect Skill -- combat (throwing) (Level, by Class) */
5238         p_ptr->skill_tht += ((cp_ptr->x_thb * p_ptr->lev / 10) + (ap_ptr->a_thb * p_ptr->lev / 50));
5239
5240
5241         if ((prace_is_(RACE_S_FAIRY)) && (p_ptr->pseikaku != SEIKAKU_SEXY) && (p_ptr->cursed & TRC_AGGRAVATE))
5242         {
5243                 p_ptr->cursed &= ~(TRC_AGGRAVATE);
5244                 p_ptr->skill_stl = MIN(p_ptr->skill_stl - 3, (p_ptr->skill_stl + 2) / 2);
5245         }
5246
5247         /* Limit Skill -- stealth from 0 to 30 */
5248         if (p_ptr->skill_stl > 30) p_ptr->skill_stl = 30;
5249         if (p_ptr->skill_stl < 0) p_ptr->skill_stl = 0;
5250
5251         /* Limit Skill -- digging from 1 up */
5252         if (p_ptr->skill_dig < 1) p_ptr->skill_dig = 1;
5253
5254         if (p_ptr->anti_magic && (p_ptr->skill_sav < (90 + p_ptr->lev))) p_ptr->skill_sav = 90 + p_ptr->lev;
5255
5256         if (p_ptr->tsubureru) p_ptr->skill_sav = 10;
5257
5258         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;
5259
5260         if (down_saving) p_ptr->skill_sav /= 2;
5261
5262         /* Hack -- handle "xtra" mode */
5263         if (character_xtra) return;
5264
5265         /* Take note when "heavy bow" changes */
5266         if (p_ptr->old_heavy_shoot != p_ptr->heavy_shoot)
5267         {
5268                 /* Message */
5269                 if (p_ptr->heavy_shoot)
5270                 {
5271 #ifdef JP
5272                         msg_print("¤³¤ó¤Ê½Å¤¤µÝ¤òÁõÈ÷¤·¤Æ¤¤¤ë¤Î¤ÏÂçÊѤÀ¡£");
5273 #else
5274                         msg_print("You have trouble wielding such a heavy bow.");
5275 #endif
5276
5277                 }
5278                 else if (inventory[INVEN_BOW].k_idx)
5279                 {
5280 #ifdef JP
5281                         msg_print("¤³¤ÎµÝ¤Ê¤éÁõÈ÷¤·¤Æ¤¤¤Æ¤â¿É¤¯¤Ê¤¤¡£");
5282 #else
5283                         msg_print("You have no trouble wielding your bow.");
5284 #endif
5285
5286                 }
5287                 else
5288                 {
5289 #ifdef JP
5290                         msg_print("½Å¤¤µÝ¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤ÆÂΤ¬³Ú¤Ë¤Ê¤Ã¤¿¡£");
5291 #else
5292                         msg_print("You feel relieved to put down your heavy bow.");
5293 #endif
5294
5295                 }
5296
5297                 /* Save it */
5298                 p_ptr->old_heavy_shoot = p_ptr->heavy_shoot;
5299         }
5300
5301         for(i = 0 ; i < 2 ; i++)
5302         {
5303                 /* Take note when "heavy weapon" changes */
5304                 if (p_ptr->old_heavy_wield[i] != p_ptr->heavy_wield[i])
5305                 {
5306                         /* Message */
5307                         if (p_ptr->heavy_wield[i])
5308                         {
5309 #ifdef JP
5310                                 msg_print("¤³¤ó¤Ê½Å¤¤Éð´ï¤òÁõÈ÷¤·¤Æ¤¤¤ë¤Î¤ÏÂçÊѤÀ¡£");
5311 #else
5312                                 msg_print("You have trouble wielding such a heavy weapon.");
5313 #endif
5314
5315                         }
5316                         else if (buki_motteruka(INVEN_RARM+i))
5317                         {
5318 #ifdef JP
5319                                 msg_print("¤³¤ì¤Ê¤éÁõÈ÷¤·¤Æ¤¤¤Æ¤â¿É¤¯¤Ê¤¤¡£");
5320 #else
5321                                 msg_print("You have no trouble wielding your weapon.");
5322 #endif
5323
5324                         }
5325                         else if (p_ptr->heavy_wield[1-i])
5326                         {
5327 #ifdef JP
5328                                 msg_print("¤Þ¤ÀÉð´ï¤¬½Å¤¤¡£");
5329 #else
5330                                 msg_print("You have still trouble wielding a heavy weapon.");
5331 #endif
5332
5333                         }
5334                         else
5335                         {
5336 #ifdef JP
5337                                 msg_print("½Å¤¤Éð´ï¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤ÆÂΤ¬³Ú¤Ë¤Ê¤Ã¤¿¡£");
5338 #else
5339                                 msg_print("You feel relieved to put down your heavy weapon.");
5340 #endif
5341
5342                         }
5343
5344                         /* Save it */
5345                         p_ptr->old_heavy_wield[i] = p_ptr->heavy_wield[i];
5346                 }
5347
5348                 /* Take note when "heavy weapon" changes */
5349                 if (p_ptr->old_riding_wield[i] != p_ptr->riding_wield[i])
5350                 {
5351                         /* Message */
5352                         if (p_ptr->riding_wield[i])
5353                         {
5354 #ifdef JP
5355                                 msg_print("¤³¤ÎÉð´ï¤Ï¾èÇÏÃæ¤Ë»È¤¦¤Ë¤Ï¤à¤«¤Ê¤¤¤è¤¦¤À¡£");
5356 #else
5357                                 msg_print("This weapon is not suitable for use while riding.");
5358 #endif
5359
5360                         }
5361                         else if (!p_ptr->riding)
5362                         {
5363 #ifdef JP
5364                                 msg_print("¤³¤ÎÉð´ï¤ÏÅÌÊâ¤Ç»È¤¤¤ä¤¹¤¤¡£");
5365 #else
5366                                 msg_print("This weapon was not suitable for use while riding.");
5367 #endif
5368
5369                         }
5370                         else if (buki_motteruka(INVEN_RARM+i))
5371                         {
5372 #ifdef JP
5373                                 msg_print("¤³¤ì¤Ê¤é¾èÇÏÃæ¤Ë¤Ô¤Ã¤¿¤ê¤À¡£");
5374 #else
5375                                 msg_print("This weapon is suitable for use while riding.");
5376 #endif
5377
5378                         }
5379                         /* Save it */
5380                         p_ptr->old_riding_wield[i] = p_ptr->riding_wield[i];
5381                 }
5382
5383                 /* Take note when "illegal weapon" changes */
5384                 if (p_ptr->old_icky_wield[i] != p_ptr->icky_wield[i])
5385                 {
5386                         /* Message */
5387                         if (p_ptr->icky_wield[i])
5388                         {
5389 #ifdef JP
5390                                 msg_print("º£¤ÎÁõÈ÷¤Ï¤É¤¦¤â¼«Ê¬¤Ë¤Õ¤µ¤ï¤·¤¯¤Ê¤¤µ¤¤¬¤¹¤ë¡£");
5391 #else
5392                                 msg_print("You do not feel comfortable with your weapon.");
5393 #endif
5394                                 if (hack_mind)
5395                                 {
5396                                         chg_virtue(V_FAITH, -1);
5397                                 }
5398                         }
5399                         else if (buki_motteruka(INVEN_RARM+i))
5400                         {
5401 #ifdef JP
5402                                 msg_print("º£¤ÎÁõÈ÷¤Ï¼«Ê¬¤Ë¤Õ¤µ¤ï¤·¤¤µ¤¤¬¤¹¤ë¡£");
5403 #else
5404                                 msg_print("You feel comfortable with your weapon.");
5405 #endif
5406
5407                         }
5408                         else
5409                         {
5410 #ifdef JP
5411                                 msg_print("ÁõÈ÷¤ò¤Ï¤º¤·¤¿¤é¿ïʬ¤Èµ¤¤¬³Ú¤Ë¤Ê¤Ã¤¿¡£");
5412 #else
5413                                 msg_print("You feel more comfortable after removing your weapon.");
5414 #endif
5415
5416                         }
5417
5418                         /* Save it */
5419                         p_ptr->old_icky_wield[i] = p_ptr->icky_wield[i];
5420                 }
5421         }
5422
5423         if (p_ptr->riding && (p_ptr->old_riding_ryoute != p_ptr->riding_ryoute))
5424         {
5425                 /* Message */
5426                 if (p_ptr->riding_ryoute)
5427                 {
5428 #ifdef JP
5429                         msg_print("ξ¼ê¤¬¤Õ¤µ¤¬¤Ã¤Æ¤¤¤ÆÇϤòÁà¤ì¤Ê¤¤¡£");
5430 #else
5431                         msg_print("You are using both hand for fighting, and you can't control a riding pet.");
5432 #endif
5433                 }
5434                 else
5435                 {
5436 #ifdef JP
5437                         msg_print("¼ê¤¬¶õ¤¤¤ÆÇϤòÁà¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£");
5438 #else
5439                         msg_print("You began to control riding pet with one hand.");
5440 #endif
5441                 }
5442
5443                 p_ptr->old_riding_ryoute = p_ptr->riding_ryoute;
5444         }
5445
5446         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER) || (p_ptr->pclass == CLASS_NINJA)) && (monk_armour_aux != monk_notify_aux))
5447         {
5448                 if (heavy_armor())
5449                 {
5450 #ifdef JP
5451 msg_print("ÁõÈ÷¤¬½Å¤¯¤Æ¥Ð¥é¥ó¥¹¤ò¼è¤ì¤Ê¤¤¡£");
5452 #else
5453                         msg_print("The weight of your armor disrupts your balance.");
5454 #endif
5455
5456                         if (hack_mind)
5457                         {
5458                                 chg_virtue(V_HARMONY, -1);
5459                         }
5460                 }
5461                 else
5462 #ifdef JP
5463 msg_print("¥Ð¥é¥ó¥¹¤¬¤È¤ì¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£");
5464 #else
5465                         msg_print("You regain your balance.");
5466 #endif
5467
5468                 monk_notify_aux = monk_armour_aux;
5469         }
5470
5471         j = 0;
5472         p_ptr->align = friend_align;
5473
5474         /* Determine player alignment */
5475         for (i = 0; i < 8; i++)
5476         {
5477                 if ((p_ptr->vir_types[i] == V_HARMONY) || (p_ptr->vir_types[i] == V_NATURE))
5478                 {
5479                         neutral[j] = i;
5480                         j++;
5481                 }
5482                 else if (p_ptr->vir_types[i] == V_UNLIFE) p_ptr->align -= p_ptr->virtues[i];
5483                 else if (p_ptr->vir_types[i] == V_JUSTICE) p_ptr->align += (p_ptr->virtues[i]*2);
5484                 else if (p_ptr->vir_types[i] != V_CHANCE) p_ptr->align += p_ptr->virtues[i];
5485         }
5486         if ((inventory[INVEN_RARM].name1 == ART_IRON_BALL) || (inventory[INVEN_LARM].name1 == ART_IRON_BALL)) p_ptr->align -= 1000;
5487         if (prace_is_(RACE_ANGEL)) p_ptr->align += 200;
5488         if ((prace_is_(RACE_DEMON)) || (p_ptr->mimic_form == MIMIC_DEMON_LORD) || (p_ptr->mimic_form == MIMIC_DEMON)) p_ptr->align -= 200;
5489         while (j)
5490         {
5491                 j--;
5492                 if (p_ptr->align > 0)
5493                 {
5494                         p_ptr->align -= (p_ptr->virtues[neutral[j]]/2);
5495                         if (p_ptr->align < 0) p_ptr->align = 0;
5496                 }
5497                 else if (p_ptr->align < 0)
5498                 {
5499                         p_ptr->align += (p_ptr->virtues[neutral[j]]/2);
5500                         if (p_ptr->align > 0) p_ptr->align = 0;
5501                 }
5502         }
5503
5504         for (i = 0; i < INVEN_PACK; i++)
5505         {
5506 #if 0
5507                 if ((inventory[i].tval == TV_SORCERY_BOOK) && (inventory[i].sval == 2)) have_dd_s = TRUE;
5508                 if ((inventory[i].tval == TV_TRUMP_BOOK) && (inventory[i].sval == 1)) have_dd_t = TRUE;
5509 #endif
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 0
5524                 if ((o_ptr->tval == TV_SORCERY_BOOK) && (o_ptr->sval == 3)) have_dd_s = TRUE;
5525                 if ((o_ptr->tval == TV_TRUMP_BOOK) && (o_ptr->sval == 1)) have_dd_t = TRUE;
5526 #endif
5527                 if ((o_ptr->tval == TV_NATURE_BOOK) && (o_ptr->sval == 2)) have_sw = TRUE;
5528                 if ((o_ptr->tval == TV_ENCHANT_BOOK) && (o_ptr->sval == 2)) have_kabe = TRUE;
5529         }
5530
5531         if ((p_ptr->pass_wall && !p_ptr->kill_wall) || p_ptr->kabenuke || p_ptr->wraith_form) p_ptr->no_flowed = TRUE;
5532 #if 0
5533         if (have_dd_s && ((p_ptr->realm1 == REALM_SORCERY) || (p_ptr->realm2 == REALM_SORCERY) || (p_ptr->pclass == CLASS_SORCERER)))
5534         {
5535                 magic_type *s_ptr = &mp_ptr->info[REALM_SORCERY-1][SPELL_DD_S];
5536                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5537         }
5538
5539         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)))
5540         {
5541                 magic_type *s_ptr = &mp_ptr->info[REALM_TRUMP-1][SPELL_DD_T];
5542                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5543         }
5544 #endif
5545         if (have_sw && ((p_ptr->realm1 == REALM_NATURE) || (p_ptr->realm2 == REALM_NATURE) || (p_ptr->pclass == CLASS_SORCERER)))
5546         {
5547                 magic_type *s_ptr = &mp_ptr->info[REALM_NATURE-1][SPELL_SW];
5548                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5549         }
5550
5551         if (have_kabe && ((p_ptr->realm1 == REALM_ENCHANT) || (p_ptr->realm2 == REALM_ENCHANT) || (p_ptr->pclass == CLASS_SORCERER)))
5552         {
5553                 magic_type *s_ptr = &mp_ptr->info[REALM_ENCHANT-1][SPELL_KABE];
5554                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5555         }
5556 }
5557
5558
5559
5560 /*
5561  * Handle "p_ptr->notice"
5562  */
5563 void notice_stuff(void)
5564 {
5565         /* Notice stuff */
5566         if (!p_ptr->notice) return;
5567
5568
5569         /* Actually do auto-destroy */
5570         if (p_ptr->notice & (PN_AUTODESTROY))
5571         {
5572                 p_ptr->notice &= ~(PN_AUTODESTROY);
5573                 delayed_auto_destroy();
5574         }
5575
5576         /* Combine the pack */
5577         if (p_ptr->notice & (PN_COMBINE))
5578         {
5579                 p_ptr->notice &= ~(PN_COMBINE);
5580                 combine_pack();
5581         }
5582
5583         /* Reorder the pack */
5584         if (p_ptr->notice & (PN_REORDER))
5585         {
5586                 p_ptr->notice &= ~(PN_REORDER);
5587                 reorder_pack();
5588         }
5589 }
5590
5591
5592 /*
5593  * Handle "p_ptr->update"
5594  */
5595 void update_stuff(void)
5596 {
5597         /* Update stuff */
5598         if (!p_ptr->update) return;
5599
5600
5601         if (p_ptr->update & (PU_BONUS))
5602         {
5603                 p_ptr->update &= ~(PU_BONUS);
5604                 calc_bonuses();
5605         }
5606
5607         if (p_ptr->update & (PU_TORCH))
5608         {
5609                 p_ptr->update &= ~(PU_TORCH);
5610                 calc_torch();
5611         }
5612
5613         if (p_ptr->update & (PU_HP))
5614         {
5615                 p_ptr->update &= ~(PU_HP);
5616                 calc_hitpoints();
5617         }
5618
5619         if (p_ptr->update & (PU_MANA))
5620         {
5621                 p_ptr->update &= ~(PU_MANA);
5622                 calc_mana();
5623         }
5624
5625         if (p_ptr->update & (PU_SPELLS))
5626         {
5627                 p_ptr->update &= ~(PU_SPELLS);
5628                 calc_spells();
5629         }
5630
5631
5632         /* Character is not ready yet, no screen updates */
5633         if (!character_generated) return;
5634
5635
5636         /* Character is in "icky" mode, no screen updates */
5637         if (character_icky) return;
5638
5639
5640         if (p_ptr->update & (PU_UN_LITE))
5641         {
5642                 p_ptr->update &= ~(PU_UN_LITE);
5643                 forget_lite();
5644         }
5645
5646         if (p_ptr->update & (PU_UN_VIEW))
5647         {
5648                 p_ptr->update &= ~(PU_UN_VIEW);
5649                 forget_view();
5650         }
5651
5652         if (p_ptr->update & (PU_VIEW))
5653         {
5654                 p_ptr->update &= ~(PU_VIEW);
5655                 update_view();
5656         }
5657
5658         if (p_ptr->update & (PU_LITE))
5659         {
5660                 p_ptr->update &= ~(PU_LITE);
5661                 update_lite();
5662         }
5663
5664
5665         if (p_ptr->update & (PU_FLOW))
5666         {
5667                 p_ptr->update &= ~(PU_FLOW);
5668                 update_flow();
5669         }
5670
5671         if (p_ptr->update & (PU_DISTANCE))
5672         {
5673                 p_ptr->update &= ~(PU_DISTANCE);
5674
5675                 /* Still need to call update_monsters(FALSE) after update_mon_lite() */ 
5676                 /* p_ptr->update &= ~(PU_MONSTERS); */
5677
5678                 update_monsters(TRUE);
5679         }
5680
5681         if (p_ptr->update & (PU_MON_LITE))
5682         {
5683                 p_ptr->update &= ~(PU_MON_LITE);
5684                 update_mon_lite();
5685         }
5686
5687         if (p_ptr->update & (PU_MONSTERS))
5688         {
5689                 p_ptr->update &= ~(PU_MONSTERS);
5690                 update_monsters(FALSE);
5691         }
5692 }
5693
5694
5695 /*
5696  * Handle "p_ptr->redraw"
5697  */
5698 void redraw_stuff(void)
5699 {
5700         /* Redraw stuff */
5701         if (!p_ptr->redraw) return;
5702
5703
5704         /* Character is not ready yet, no screen updates */
5705         if (!character_generated) return;
5706
5707
5708         /* Character is in "icky" mode, no screen updates */
5709         if (character_icky) return;
5710
5711
5712
5713         /* Hack -- clear the screen */
5714         if (p_ptr->redraw & (PR_WIPE))
5715         {
5716                 p_ptr->redraw &= ~(PR_WIPE);
5717                 msg_print(NULL);
5718                 Term_clear();
5719         }
5720
5721
5722         if (p_ptr->redraw & (PR_MAP))
5723         {
5724                 p_ptr->redraw &= ~(PR_MAP);
5725                 prt_map();
5726         }
5727
5728
5729         if (p_ptr->redraw & (PR_BASIC))
5730         {
5731                 p_ptr->redraw &= ~(PR_BASIC);
5732                 p_ptr->redraw &= ~(PR_MISC | PR_TITLE | PR_STATS);
5733                 p_ptr->redraw &= ~(PR_LEV | PR_EXP | PR_GOLD);
5734                 p_ptr->redraw &= ~(PR_ARMOR | PR_HP | PR_MANA);
5735                 p_ptr->redraw &= ~(PR_DEPTH | PR_HEALTH | PR_UHEALTH);
5736                 prt_frame_basic();
5737                 prt_time();
5738                 prt_dungeon();
5739         }
5740
5741         if (p_ptr->redraw & (PR_EQUIPPY))
5742         {
5743                 p_ptr->redraw &= ~(PR_EQUIPPY);
5744                 print_equippy(); /* To draw / delete equippy chars */
5745         }
5746
5747         if (p_ptr->redraw & (PR_MISC))
5748         {
5749                 p_ptr->redraw &= ~(PR_MISC);
5750                 prt_field(rp_ptr->title, ROW_RACE, COL_RACE);
5751 /*              prt_field(cp_ptr->title, ROW_CLASS, COL_CLASS); */
5752
5753         }
5754
5755         if (p_ptr->redraw & (PR_TITLE))
5756         {
5757                 p_ptr->redraw &= ~(PR_TITLE);
5758                 prt_title();
5759         }
5760
5761         if (p_ptr->redraw & (PR_LEV))
5762         {
5763                 p_ptr->redraw &= ~(PR_LEV);
5764                 prt_level();
5765         }
5766
5767         if (p_ptr->redraw & (PR_EXP))
5768         {
5769                 p_ptr->redraw &= ~(PR_EXP);
5770                 prt_exp();
5771         }
5772
5773         if (p_ptr->redraw & (PR_STATS))
5774         {
5775                 p_ptr->redraw &= ~(PR_STATS);
5776                 prt_stat(A_STR);
5777                 prt_stat(A_INT);
5778                 prt_stat(A_WIS);
5779                 prt_stat(A_DEX);
5780                 prt_stat(A_CON);
5781                 prt_stat(A_CHR);
5782         }
5783
5784         if (p_ptr->redraw & (PR_STATUS))
5785         {
5786                 p_ptr->redraw &= ~(PR_STATUS);
5787                 prt_status();
5788         }
5789
5790         if (p_ptr->redraw & (PR_ARMOR))
5791         {
5792                 p_ptr->redraw &= ~(PR_ARMOR);
5793                 prt_ac();
5794         }
5795
5796         if (p_ptr->redraw & (PR_HP))
5797         {
5798                 p_ptr->redraw &= ~(PR_HP);
5799                 prt_hp();
5800         }
5801
5802         if (p_ptr->redraw & (PR_MANA))
5803         {
5804                 p_ptr->redraw &= ~(PR_MANA);
5805                 prt_sp();
5806         }
5807
5808         if (p_ptr->redraw & (PR_GOLD))
5809         {
5810                 p_ptr->redraw &= ~(PR_GOLD);
5811                 prt_gold();
5812         }
5813
5814         if (p_ptr->redraw & (PR_DEPTH))
5815         {
5816                 p_ptr->redraw &= ~(PR_DEPTH);
5817                 prt_depth();
5818         }
5819
5820         if (p_ptr->redraw & (PR_HEALTH))
5821         {
5822                 p_ptr->redraw &= ~(PR_HEALTH);
5823                 health_redraw();
5824         }
5825
5826         if (p_ptr->redraw & (PR_UHEALTH))
5827         {
5828                 p_ptr->redraw &= ~(PR_UHEALTH);
5829                 riding_health_redraw();
5830         }
5831
5832
5833         if (p_ptr->redraw & (PR_EXTRA))
5834         {
5835                 p_ptr->redraw &= ~(PR_EXTRA);
5836                 p_ptr->redraw &= ~(PR_CUT | PR_STUN);
5837                 p_ptr->redraw &= ~(PR_HUNGER);
5838                 p_ptr->redraw &= ~(PR_STATE | PR_SPEED | PR_STUDY | PR_MANE | PR_STATUS);
5839                 prt_frame_extra();
5840         }
5841
5842         if (p_ptr->redraw & (PR_CUT))
5843         {
5844                 p_ptr->redraw &= ~(PR_CUT);
5845                 prt_cut();
5846         }
5847
5848         if (p_ptr->redraw & (PR_STUN))
5849         {
5850                 p_ptr->redraw &= ~(PR_STUN);
5851                 prt_stun();
5852         }
5853
5854         if (p_ptr->redraw & (PR_HUNGER))
5855         {
5856                 p_ptr->redraw &= ~(PR_HUNGER);
5857                 prt_hunger();
5858         }
5859
5860         if (p_ptr->redraw & (PR_STATE))
5861         {
5862                 p_ptr->redraw &= ~(PR_STATE);
5863                 prt_state();
5864         }
5865
5866         if (p_ptr->redraw & (PR_SPEED))
5867         {
5868                 p_ptr->redraw &= ~(PR_SPEED);
5869                 prt_speed();
5870         }
5871
5872         if (p_ptr->pclass == CLASS_IMITATOR)
5873         {
5874                 if (p_ptr->redraw & (PR_MANE))
5875                 {
5876                         p_ptr->redraw &= ~(PR_MANE);
5877                         prt_mane();
5878                 }
5879         }
5880         else if (p_ptr->redraw & (PR_STUDY))
5881         {
5882                 p_ptr->redraw &= ~(PR_STUDY);
5883                 prt_study();
5884         }
5885 }
5886
5887
5888 /*
5889  * Handle "p_ptr->window"
5890  */
5891 void window_stuff(void)
5892 {
5893         int j;
5894
5895         u32b mask = 0L;
5896
5897
5898         /* Nothing to do */
5899         if (!p_ptr->window) return;
5900
5901         /* Scan windows */
5902         for (j = 0; j < 8; j++)
5903         {
5904                 /* Save usable flags */
5905                 if (angband_term[j]) mask |= window_flag[j];
5906         }
5907
5908         /* Apply usable flags */
5909         p_ptr->window &= mask;
5910
5911         /* Nothing to do */
5912         if (!p_ptr->window) return;
5913
5914
5915         /* Display inventory */
5916         if (p_ptr->window & (PW_INVEN))
5917         {
5918                 p_ptr->window &= ~(PW_INVEN);
5919                 fix_inven();
5920         }
5921
5922         /* Display equipment */
5923         if (p_ptr->window & (PW_EQUIP))
5924         {
5925                 p_ptr->window &= ~(PW_EQUIP);
5926                 fix_equip();
5927         }
5928
5929         /* Display spell list */
5930         if (p_ptr->window & (PW_SPELL))
5931         {
5932                 p_ptr->window &= ~(PW_SPELL);
5933                 fix_spell();
5934         }
5935
5936         /* Display player */
5937         if (p_ptr->window & (PW_PLAYER))
5938         {
5939                 p_ptr->window &= ~(PW_PLAYER);
5940                 fix_player();
5941         }
5942
5943         /* Display overhead view */
5944         if (p_ptr->window & (PW_MESSAGE))
5945         {
5946                 p_ptr->window &= ~(PW_MESSAGE);
5947                 fix_message();
5948         }
5949
5950         /* Display overhead view */
5951         if (p_ptr->window & (PW_OVERHEAD))
5952         {
5953                 p_ptr->window &= ~(PW_OVERHEAD);
5954                 fix_overhead();
5955         }
5956
5957         /* Display overhead view */
5958         if (p_ptr->window & (PW_DUNGEON))
5959         {
5960                 p_ptr->window &= ~(PW_DUNGEON);
5961                 fix_dungeon();
5962         }
5963
5964         /* Display monster recall */
5965         if (p_ptr->window & (PW_MONSTER))
5966         {
5967                 p_ptr->window &= ~(PW_MONSTER);
5968                 fix_monster();
5969         }
5970
5971         /* Display object recall */
5972         if (p_ptr->window & (PW_OBJECT))
5973         {
5974                 p_ptr->window &= ~(PW_OBJECT);
5975                 fix_object();
5976         }
5977 }
5978
5979
5980 /*
5981  * Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window"
5982  */
5983 void handle_stuff(void)
5984 {
5985         /* Update stuff */
5986         if (p_ptr->update) update_stuff();
5987
5988         /* Redraw stuff */
5989         if (p_ptr->redraw) redraw_stuff();
5990
5991         /* Window stuff */
5992         if (p_ptr->window) window_stuff();
5993 }
5994
5995
5996 s16b empty_hands(bool is_monk)
5997 {
5998         s16b kaerichi = 0;
5999         if (is_monk && (p_ptr->pclass != CLASS_MONK) && (p_ptr->pclass != CLASS_FORCETRAINER) && (p_ptr->pclass != CLASS_BERSERKER)) return FALSE;
6000
6001         if (!(inventory[INVEN_RARM].k_idx)) kaerichi +=2;
6002         if (!(inventory[INVEN_LARM].k_idx)) kaerichi +=1;
6003         return kaerichi;
6004 }
6005
6006
6007 bool heavy_armor(void)
6008 {
6009         u16b monk_arm_wgt = 0;
6010
6011         if ((p_ptr->pclass != CLASS_MONK) && (p_ptr->pclass != CLASS_FORCETRAINER) && (p_ptr->pclass != CLASS_NINJA)) return FALSE;
6012
6013         /* Weight the armor */
6014         if(inventory[INVEN_RARM].tval > TV_SWORD) monk_arm_wgt += inventory[INVEN_RARM].weight;
6015         if(inventory[INVEN_LARM].tval > TV_SWORD) monk_arm_wgt += inventory[INVEN_LARM].weight;
6016         monk_arm_wgt += inventory[INVEN_BODY].weight;
6017         monk_arm_wgt += inventory[INVEN_HEAD].weight;
6018         monk_arm_wgt += inventory[INVEN_OUTER].weight;
6019         monk_arm_wgt += inventory[INVEN_HANDS].weight;
6020         monk_arm_wgt += inventory[INVEN_FEET].weight;
6021
6022         return (monk_arm_wgt > (100 + (p_ptr->lev * 4)));
6023 }
6024
6025 int number_of_quests(void)
6026 {
6027         int i, j;
6028
6029         /* Clear the counter */
6030         i = 0;
6031
6032         for (j = MIN_RANDOM_QUEST; j < MAX_RANDOM_QUEST+1; j++)
6033         {
6034                 if (quest[j].status != QUEST_STATUS_UNTAKEN)
6035                 {
6036                         /* Increment count of quests taken. */
6037                         i++;
6038                 }
6039         }
6040
6041         /* Return the number of quests taken */
6042         return (i);
6043 }