OSDN Git Service

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