OSDN Git Service

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