OSDN Git Service

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