OSDN Git Service

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