OSDN Git Service

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