OSDN Git Service

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