OSDN Git Service

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