OSDN Git Service

[Refactor] #37287 #37353 型の置換。 / Type replacement.
[hengband/hengband.git] / src / xtra1.c
1 /*!
2  * @file xtra1.c
3  * @brief プレイヤーのステータス処理 / status
4  * @date 2018/09/25
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 (s16b)(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  * @return 日中ならば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  * @brief 下部に状態表示を行う / 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 (HEX_REVENGE_TURN(p_ptr))
678                 {
679                         if (HEX_REVENGE_TYPE(p_ptr) == 1) ADD_FLG(BAR_PATIENCE);
680                         if (HEX_REVENGE_TYPE(p_ptr) == 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  * @brief プレイヤーの称号を表示する / 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  * @brief プレイヤーのレベルを表示する / 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  * @brief プレイヤーの経験値を表示する / 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  * @brief プレイヤーの所持金を表示する / 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  * @brief プレイヤーの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  * @brief プレイヤーの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  * @brief プレイヤーの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  * @brief 現在のフロアの深さを表示する / 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"), (int)dun_level * 50);
1034                 else (void)sprintf(depths, _("%d 階", "Lev %d"), (int)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  * @brief プレイヤーの空腹状態を表示する / 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  * @brief プレイヤーの行動状態を表示する / 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[16];
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 == COMMAND_ARG_REST_FULL_HEALING)
1185                                 {
1186                                         text[0] = text[1] = text[2] = text[3] = '*';
1187                                 }
1188
1189                                 /* Rest until done */
1190                                 else if (resting == COMMAND_ARG_REST_UNTIL_DONE)
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  * @brief プレイヤーの行動速度を表示する / 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  * @brief プレイヤーの呪文学習可能状態を表示する
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  * @brief プレイヤーのものまね可能状態を表示する
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  * @brief プレイヤーの負傷状態を表示する
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  * @brief プレイヤーの朦朧状態を表示する
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  * @brief モンスターの体力ゲージを表示する
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  * @brief プレイヤーのステータスを一括表示する(左側部分) / 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  * @brief プレイヤーのステータスを一括表示する(下部分) / 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  * @brief サブウィンドウに所持品一覧を表示する / 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  * @brief モンスターの現在数を一行で表現する / 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         MONRACE_IDX 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", (int)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  * @brief モンスターの出現リストを表示する / 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                         MONRACE_IDX 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  * @brief 出現中モンスターのリストをサブウィンドウに表示する / 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  * @brief 現在の装備品をサブウィンドウに表示する / 
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  * @brief 現在の習得済魔法をサブウィンドウに表示する / 
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  * @brief 現在のプレイヤーステータスをサブウィンドウに表示する / 
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  * @brief ゲームメッセージ履歴をサブウィンドウに表示する / 
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  * @brief 簡易マップをサブウィンドウに表示する / 
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  * @brief ダンジョンの地形をサブウィンドウに表示する / 
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  * @brief モンスターの思い出をサブウィンドウに表示する / 
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  * @brief ベースアイテム情報をサブウィンドウに表示する / 
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  * @brief プレイヤーの現在学習可能な魔法数を計算し、増減に応じて魔法の忘却、再学習を処置する。 /
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         REALM_IDX 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を忘れてしまった。", do_spell(which, j%32, SPELL_NAME), p );
2335 #else
2336                         msg_format("You have forgotten the %s of %s.", p, do_spell(which, j%32, SPELL_NAME));
2337 #endif
2338
2339
2340                         /* One more can be learned */
2341                         p_ptr->new_spells++;
2342                 }
2343         }
2344
2345
2346         /* Forget spells if we know too many spells */
2347         for (i = 63; i >= 0; i--)
2348         {
2349                 /* Stop when possible */
2350                 if (p_ptr->new_spells >= 0) break;
2351
2352                 /* Efficiency -- all done */
2353                 if (!p_ptr->spell_learned1 && !p_ptr->spell_learned2) break;
2354
2355                 /* Get the (i+1)th spell learned */
2356                 j = p_ptr->spell_order[i];
2357
2358                 /* Skip unknown spells */
2359                 if (j >= 99) continue;
2360
2361                 /* Forget it (if learned) */
2362                 if ((j < 32) ?
2363                     (p_ptr->spell_learned1 & (1L << j)) :
2364                     (p_ptr->spell_learned2 & (1L << (j - 32))))
2365                 {
2366                         /* Mark as forgotten */
2367                         if (j < 32)
2368                         {
2369                                 p_ptr->spell_forgotten1 |= (1L << j);
2370                                 which = p_ptr->realm1;
2371                         }
2372                         else
2373                         {
2374                                 p_ptr->spell_forgotten2 |= (1L << (j - 32));
2375                                 which = p_ptr->realm2;
2376                         }
2377
2378                         /* No longer known */
2379                         if (j < 32)
2380                         {
2381                                 p_ptr->spell_learned1 &= ~(1L << j);
2382                                 which = p_ptr->realm1;
2383                         }
2384                         else
2385                         {
2386                                 p_ptr->spell_learned2 &= ~(1L << (j - 32));
2387                                 which = p_ptr->realm2;
2388                         }
2389
2390                         /* Message */
2391 #ifdef JP
2392                         msg_format("%sの%sを忘れてしまった。",
2393                                    do_spell(which, j%32, SPELL_NAME), p );
2394 #else
2395                         msg_format("You have forgotten the %s of %s.", p,
2396                                    do_spell(which, j%32, SPELL_NAME));
2397 #endif
2398
2399
2400                         /* One more can be learned */
2401                         p_ptr->new_spells++;
2402                 }
2403         }
2404
2405
2406         /* Check for spells to remember */
2407         for (i = 0; i < 64; i++)
2408         {
2409                 /* None left to remember */
2410                 if (p_ptr->new_spells <= 0) break;
2411
2412                 /* Efficiency -- all done */
2413                 if (!p_ptr->spell_forgotten1 && !p_ptr->spell_forgotten2) break;
2414
2415                 /* Get the next spell we learned */
2416                 j = p_ptr->spell_order[i];
2417
2418                 /* Skip unknown spells */
2419                 if (j >= 99) break;
2420
2421                 /* Access the spell */
2422                 if (!is_magic((j < 32) ? p_ptr->realm1 : p_ptr->realm2))
2423                 {
2424                         if (j < 32)
2425                                 s_ptr = &technic_info[p_ptr->realm1 - MIN_TECHNIC][j];
2426                         else
2427                                 s_ptr = &technic_info[p_ptr->realm2 - MIN_TECHNIC][j%32];
2428                 }
2429                 else if (j<32)
2430                         s_ptr = &mp_ptr->info[p_ptr->realm1-1][j];
2431                 else
2432                         s_ptr = &mp_ptr->info[p_ptr->realm2-1][j%32];
2433
2434                 /* Skip spells we cannot remember */
2435                 if (s_ptr->slevel > p_ptr->lev) continue;
2436
2437                 /* First set of spells */
2438                 if ((j < 32) ?
2439                     (p_ptr->spell_forgotten1 & (1L << j)) :
2440                     (p_ptr->spell_forgotten2 & (1L << (j - 32))))
2441                 {
2442                         /* No longer forgotten */
2443                         if (j < 32)
2444                         {
2445                                 p_ptr->spell_forgotten1 &= ~(1L << j);
2446                                 which = p_ptr->realm1;
2447                         }
2448                         else
2449                         {
2450                                 p_ptr->spell_forgotten2 &= ~(1L << (j - 32));
2451                                 which = p_ptr->realm2;
2452                         }
2453
2454                         /* Known once more */
2455                         if (j < 32)
2456                         {
2457                                 p_ptr->spell_learned1 |= (1L << j);
2458                                 which = p_ptr->realm1;
2459                         }
2460                         else
2461                         {
2462                                 p_ptr->spell_learned2 |= (1L << (j - 32));
2463                                 which = p_ptr->realm2;
2464                         }
2465
2466                         /* Message */
2467 #ifdef JP
2468                         msg_format("%sの%sを思い出した。", do_spell(which, j%32, SPELL_NAME), p );
2469 #else
2470                         msg_format("You have remembered the %s of %s.", p, do_spell(which, j%32, SPELL_NAME));
2471 #endif
2472
2473
2474                         /* One less can be learned */
2475                         p_ptr->new_spells--;
2476                 }
2477         }
2478
2479         k = 0;
2480
2481         if (p_ptr->realm2 == REALM_NONE)
2482         {
2483                 /* Count spells that can be learned */
2484                 for (j = 0; j < 32; j++)
2485                 {
2486                         if (!is_magic(p_ptr->realm1)) s_ptr = &technic_info[p_ptr->realm1-MIN_TECHNIC][j];
2487                         else s_ptr = &mp_ptr->info[p_ptr->realm1-1][j];
2488
2489                         /* Skip spells we cannot remember */
2490                         if (s_ptr->slevel > p_ptr->lev) continue;
2491
2492                         /* Skip spells we already know */
2493                         if (p_ptr->spell_learned1 & (1L << j))
2494                         {
2495                                 continue;
2496                         }
2497
2498                         /* Count it */
2499                         k++;
2500                 }
2501                 if (k > 32) k = 32;
2502                 if ((p_ptr->new_spells > k) &&
2503                         ((mp_ptr->spell_book == TV_LIFE_BOOK) || (mp_ptr->spell_book == TV_HISSATSU_BOOK)))
2504                 {
2505                         p_ptr->new_spells = (s16b)k;
2506                 }
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  * @brief プレイヤーの最大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 増加した!", (msp - p_ptr->msp));
2807                 }
2808 #endif
2809                 /* Save new mana */
2810                 p_ptr->msp = msp;
2811
2812                 /* Display mana later */
2813                 p_ptr->redraw |= (PR_MANA);
2814
2815                 /* Window stuff */
2816                 p_ptr->window |= (PW_PLAYER);
2817                 p_ptr->window |= (PW_SPELL);
2818         }
2819
2820
2821         /* Hack -- handle "xtra" mode */
2822         if (character_xtra) return;
2823
2824         /* Take note when "glove state" changes */
2825         if (p_ptr->old_cumber_glove != p_ptr->cumber_glove)
2826         {
2827                 /* Message */
2828                 if (p_ptr->cumber_glove)
2829                 {
2830                         msg_print(_("手が覆われて呪文が唱えにくい感じがする。", "Your covered hands feel unsuitable for spellcasting."));
2831                 }
2832                 else
2833                 {
2834                         msg_print(_("この手の状態なら、ぐっと呪文が唱えやすい感じだ。", "Your hands feel more suitable for spellcasting."));
2835                 }
2836
2837                 /* Save it */
2838                 p_ptr->old_cumber_glove = p_ptr->cumber_glove;
2839         }
2840
2841
2842         /* Take note when "armor state" changes */
2843         if (p_ptr->old_cumber_armor != p_ptr->cumber_armor)
2844         {
2845                 /* Message */
2846                 if (p_ptr->cumber_armor)
2847                 {
2848                         msg_print(_("装備の重さで動きが鈍くなってしまっている。", "The weight of your equipment encumbers your movement."));
2849                 }
2850                 else
2851                 {
2852                         msg_print(_("ぐっと楽に体を動かせるようになった。", "You feel able to move more freely."));
2853                 }
2854
2855                 /* Save it */
2856                 p_ptr->old_cumber_armor = p_ptr->cumber_armor;
2857         }
2858 }
2859
2860
2861
2862 /*!
2863  * @brief プレイヤーの最大HPを計算する /
2864  * Calculate the players (maximal) hit points
2865  * Adjust current hitpoints if necessary
2866  * @return なし
2867  * @details
2868  */
2869 static void calc_hitpoints(void)
2870 {
2871         int bonus, mhp;
2872         byte tmp_hitdie;
2873
2874         /* Un-inflate "half-hitpoint bonus per level" value */
2875         bonus = ((int)(adj_con_mhp[p_ptr->stat_ind[A_CON]]) - 128) * p_ptr->lev / 4;
2876
2877         /* Calculate hitpoints */
2878         mhp = p_ptr->player_hp[p_ptr->lev - 1];
2879
2880         if (p_ptr->mimic_form)
2881         {
2882                 if (p_ptr->pclass == CLASS_SORCERER)
2883                         tmp_hitdie = mimic_info[p_ptr->mimic_form].r_mhp/2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
2884                 else
2885                         tmp_hitdie = mimic_info[p_ptr->mimic_form].r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
2886                 mhp = mhp * tmp_hitdie / p_ptr->hitdie;
2887         }
2888
2889         if (p_ptr->pclass == CLASS_SORCERER)
2890         {
2891                 if (p_ptr->lev < 30)
2892                         mhp = (mhp * (45+p_ptr->lev) / 100);
2893                 else
2894                         mhp = (mhp * 75 / 100);
2895                 bonus = (bonus * 65 / 100);
2896         }
2897
2898         mhp += bonus;
2899
2900         if (p_ptr->pclass == CLASS_BERSERKER)
2901         {
2902                 mhp = mhp*(110+(((p_ptr->lev + 40) * (p_ptr->lev + 40) - 1550) / 110))/100;
2903         }
2904
2905         /* Always have at least one hitpoint per level */
2906         if (mhp < p_ptr->lev + 1) mhp = p_ptr->lev + 1;
2907
2908         /* Factor in the hero / superhero settings */
2909         if (IS_HERO()) mhp += 10;
2910         if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER)) mhp += 30;
2911         if (p_ptr->tsuyoshi) mhp += 50;
2912
2913         /* Factor in the hex spell settings */
2914         if (hex_spelling(HEX_XTRA_MIGHT)) mhp += 15;
2915         if (hex_spelling(HEX_BUILDING)) mhp += 60;
2916
2917         /* New maximum hitpoints */
2918         if (p_ptr->mhp != mhp)
2919         {
2920                 /* Enforce maximum */
2921                 if (p_ptr->chp >= mhp)
2922                 {
2923                         p_ptr->chp = mhp;
2924                         p_ptr->chp_frac = 0;
2925                 }
2926
2927 #ifdef JP
2928                 /* レベルアップの時は上昇量を表示する */
2929                 if ((level_up == 1) && (mhp > p_ptr->mhp))
2930                 {
2931                         msg_format("最大ヒット・ポイントが %d 増加した!", (mhp - p_ptr->mhp) );
2932                 }
2933 #endif
2934                 /* Save the new max-hitpoints */
2935                 p_ptr->mhp = mhp;
2936
2937                 /* Display hitpoints (later) */
2938                 p_ptr->redraw |= (PR_HP);
2939
2940                 /* Window stuff */
2941                 p_ptr->window |= (PW_PLAYER);
2942         }
2943 }
2944
2945 /*!
2946  * @brief プレイヤーの光源半径を計算する / Extract and set the current "lite radius"
2947  * @return なし
2948  * @details
2949  * SWD: Experimental modification: multiple light sources have additive effect.
2950  */
2951 static void calc_torch(void)
2952 {
2953         int i, rad;
2954         object_type *o_ptr;
2955         u32b flgs[TR_FLAG_SIZE];
2956
2957         /* Assume no light */
2958         p_ptr->cur_lite = 0;
2959
2960         /* Loop through all wielded items */
2961         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2962         {
2963                 o_ptr = &inventory[i];
2964                 /* Skip empty slots */
2965                 if (!o_ptr->k_idx) continue;
2966                 
2967                 if (o_ptr->name2 == EGO_LITE_SHINE) p_ptr->cur_lite++;
2968                 
2969                 /* Need Fuels */
2970                 if (o_ptr->name2 != EGO_LITE_DARKNESS)
2971                 {
2972                         if (o_ptr->tval == TV_LITE)
2973                         {
2974                                 if((o_ptr->sval == SV_LITE_TORCH) && !(o_ptr->xtra4 > 0)) continue;
2975                                 if((o_ptr->sval == SV_LITE_LANTERN) && !(o_ptr->xtra4 > 0)) continue;
2976                         }
2977                 }
2978
2979                 /* Extract the flags */
2980                 object_flags(o_ptr, flgs);
2981
2982                 /* calc the lite_radius */
2983                 
2984                 rad = 0;
2985                 if (have_flag(flgs, TR_LITE_1) && o_ptr->name2 != EGO_LITE_DARKNESS)  rad += 1;
2986                 if (have_flag(flgs, TR_LITE_2) && o_ptr->name2 != EGO_LITE_DARKNESS)  rad += 2;
2987                 if (have_flag(flgs, TR_LITE_3) && o_ptr->name2 != EGO_LITE_DARKNESS)  rad += 3;
2988                 if (have_flag(flgs, TR_LITE_M1)) rad -= 1;
2989                 if (have_flag(flgs, TR_LITE_M2)) rad -= 2;
2990                 if (have_flag(flgs, TR_LITE_M3)) rad -= 3;
2991                 p_ptr->cur_lite += (s16b)rad;
2992         }
2993
2994         /* max radius is 14 (was 5) without rewriting other code -- */
2995         /* see cave.c:update_lite() and defines.h:LITE_MAX */
2996         if (d_info[dungeon_type].flags1 & DF1_DARKNESS && p_ptr->cur_lite > 1)
2997                 p_ptr->cur_lite = 1;
2998
2999         /*
3000          * check if the player doesn't have light radius, 
3001          * but does weakly glow as an intrinsic.
3002          */
3003         if (p_ptr->cur_lite <= 0 && p_ptr->lite) p_ptr->cur_lite++;
3004
3005         if (p_ptr->cur_lite > 14) p_ptr->cur_lite = 14;
3006         if (p_ptr->cur_lite < 0) p_ptr->cur_lite = 0;
3007
3008         /* end experimental mods */
3009
3010         /* Notice changes in the "lite radius" */
3011         if (p_ptr->old_lite != p_ptr->cur_lite)
3012         {
3013                 /* Update stuff */
3014                 /* Hack -- PU_MON_LITE for monsters' darkness */
3015                 p_ptr->update |= (PU_LITE | PU_MON_LITE | PU_MONSTERS);
3016
3017                 /* Remember the old lite */
3018                 p_ptr->old_lite = p_ptr->cur_lite;
3019
3020                 if ((p_ptr->cur_lite > 0) && (p_ptr->special_defense & NINJA_S_STEALTH))
3021                         set_superstealth(FALSE);
3022         }
3023 }
3024
3025
3026 /*!
3027  * @brief プレイヤーの所持重量制限を計算する /
3028  * Computes current weight limit.
3029  * @return 制限重量(ポンド)
3030  */
3031 WEIGHT weight_limit(void)
3032 {
3033         WEIGHT i;
3034
3035         /* Weight limit based only on strength */
3036         i = (WEIGHT)adj_str_wgt[p_ptr->stat_ind[A_STR]] * 50; /* Constant was 100 */
3037         if (p_ptr->pclass == CLASS_BERSERKER) i = i * 3 / 2;
3038
3039         /* Return the result */
3040         return i;
3041 }
3042
3043 /*!
3044  * @brief プレイヤーが現在右手/左手に武器を持っているか判定する /
3045  * @param i 判定する手のID(右手:0 左手:1)
3046  * @return 持っているならばTRUE
3047  */
3048 bool buki_motteruka(int i)
3049 {
3050         return ((inventory[i].k_idx && object_is_melee_weapon(&inventory[i])) ? TRUE : FALSE);
3051 }
3052
3053 /*!
3054  * @brief 射撃武器がプレイヤーにとって重すぎるかどうかの判定 /
3055  * @param o_ptr 判定する射撃武器のアイテム情報参照ポインタ
3056  * @return 重すぎるならばTRUE
3057  */
3058 bool is_heavy_shoot(object_type *o_ptr)
3059 {
3060         int hold = adj_str_hold[p_ptr->stat_ind[A_STR]];
3061         /* It is hard to carholdry a heavy bow */
3062         return (hold < o_ptr->weight / 10);
3063 }
3064
3065 /*!
3066  * @brief 射撃武器に対応する矢/弾薬のベースアイテムIDを返す /
3067  * @param o_ptr 判定する射撃武器のアイテム情報参照ポインタ
3068  * @return 対応する矢/弾薬のベースアイテムID
3069  */
3070 int bow_tval_ammo(object_type *o_ptr)
3071 {
3072         /* Analyze the launcher */
3073         switch (o_ptr->sval)
3074         {
3075                 case SV_SLING:
3076                 {
3077                         return TV_SHOT;
3078                 }
3079
3080                 case SV_SHORT_BOW:
3081                 case SV_LONG_BOW:
3082                 case SV_NAMAKE_BOW:
3083                 {
3084                         return TV_ARROW;
3085                 }
3086
3087                 case SV_LIGHT_XBOW:
3088                 case SV_HEAVY_XBOW:
3089                 {
3090                         return TV_BOLT;
3091                 }
3092                 case SV_CRIMSON:
3093                 case SV_HARP:
3094                 {
3095                         return TV_NO_AMMO;
3096                 }
3097         }
3098         
3099         return 0;
3100 }
3101
3102 /*!
3103  * @brief 装備中の射撃武器の威力倍率を返す /
3104  * calcurate the fire rate of target object
3105  * @param o_ptr 計算する射撃武器のアイテム情報参照ポインタ
3106  * @return 射撃倍率の値(100で1.00倍)
3107  */
3108 s16b calc_num_fire(object_type *o_ptr)
3109 {
3110         int extra_shots = 0;
3111         int i;
3112         int num = 0;
3113         OBJECT_TYPE_VALUE tval_ammo = bow_tval_ammo(o_ptr);
3114         object_type *q_ptr;
3115         u32b flgs[TR_FLAG_SIZE];
3116         
3117         /* Scan the usable inventory */
3118         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
3119         {
3120                 q_ptr = &inventory[i];
3121
3122                 /* Skip non-objects */
3123                 if (!q_ptr->k_idx) continue;
3124                 
3125                 /* Do not apply current equip */
3126                 if (i == INVEN_BOW) continue;
3127
3128                 /* Extract the item flags */
3129                 object_flags(q_ptr, flgs);
3130
3131                 /* Boost shots */
3132                 if (have_flag(flgs, TR_XTRA_SHOTS)) extra_shots++;
3133         }
3134         
3135         object_flags(o_ptr, flgs);
3136         if (have_flag(flgs, TR_XTRA_SHOTS)) extra_shots++;
3137         
3138         if (o_ptr->k_idx && !is_heavy_shoot(o_ptr))
3139         {
3140                 num = 100;
3141                 /* Extra shots */
3142                 num += (extra_shots * 100);
3143
3144                 /* Hack -- Rangers love Bows */
3145                 if ((p_ptr->pclass == CLASS_RANGER) && 
3146                                         (tval_ammo == TV_ARROW))
3147                 {
3148                         num += (p_ptr->lev * 4);
3149                 }
3150
3151                 if ((p_ptr->pclass == CLASS_CAVALRY) &&
3152                     (tval_ammo == TV_ARROW))
3153                 {
3154                         num += (p_ptr->lev * 3);
3155                 }
3156
3157                 if (p_ptr->pclass == CLASS_ARCHER)
3158                 {
3159                         if (tval_ammo == TV_ARROW)
3160                                 num += ((p_ptr->lev * 5)+50);
3161                         else if ((tval_ammo == TV_BOLT) || (tval_ammo == TV_SHOT))
3162                                 num += (p_ptr->lev * 4);
3163                 }
3164
3165                 /*
3166                  * Addendum -- also "Reward" high level warriors,
3167                  * with _any_ missile weapon -- TY
3168                  */
3169                 if (p_ptr->pclass == CLASS_WARRIOR &&
3170                    (tval_ammo <= TV_BOLT) &&
3171                    (tval_ammo >= TV_SHOT))
3172                 {
3173                         num += (p_ptr->lev * 2);
3174                 }
3175                 if ((p_ptr->pclass == CLASS_ROGUE) &&
3176                     (tval_ammo == TV_SHOT))
3177                 {
3178                         num += (p_ptr->lev * 4);
3179                 }
3180         }
3181         return (s16b)num;
3182 }
3183
3184 /*!
3185  * @brief プレイヤーの全ステータスを更新する / 
3186  * Calculate the players current "state", taking into account
3187  * not only race/class intrinsics, but also objects being worn
3188  * and temporary spell effects.
3189  * @return なし
3190  * @details
3191  * <pre>
3192  * See also calc_mana() and calc_hitpoints().
3193  *
3194  * Take note of the new "speed code", in particular, a very strong
3195  * player will start slowing down as soon as he reaches 150 pounds,
3196  * but not until he reaches 450 pounds will he be half as fast as
3197  * a normal kobold.  This both hurts and helps the player, hurts
3198  * because in the old days a player could just avoid 300 pounds,
3199  * and helps because now carrying 300 pounds is not very painful.
3200  *
3201  * The "weapon" and "bow" do *not* add to the bonuses to hit or to
3202  * damage, since that would affect non-combat things.  These values
3203  * are actually added in later, at the appropriate place.
3204  *
3205  * This function induces various "status" messages.
3206  * </pre>
3207  */
3208 void calc_bonuses(void)
3209 {
3210         int             i, j, hold, neutral[2];
3211         int             new_speed;
3212         int             default_hand = 0;
3213         int             empty_hands_status = empty_hands(TRUE);
3214         int             extra_blows[2];
3215         object_type     *o_ptr;
3216         u32b flgs[TR_FLAG_SIZE];
3217         bool            omoi = FALSE;
3218         bool            yoiyami = FALSE;
3219         bool            down_saving = FALSE;
3220 #if 0
3221         bool            have_dd_s = FALSE, have_dd_t = FALSE;
3222 #endif
3223         bool            have_sw = FALSE, have_kabe = FALSE;
3224         bool            easy_2weapon = FALSE;
3225         bool            riding_levitation = FALSE;
3226         s16b this_o_idx, next_o_idx = 0;
3227         const player_race *tmp_rp_ptr;
3228
3229         /* Save the old vision stuff */
3230         bool old_telepathy = p_ptr->telepathy;
3231         bool old_esp_animal = p_ptr->esp_animal;
3232         bool old_esp_undead = p_ptr->esp_undead;
3233         bool old_esp_demon = p_ptr->esp_demon;
3234         bool old_esp_orc = p_ptr->esp_orc;
3235         bool old_esp_troll = p_ptr->esp_troll;
3236         bool old_esp_giant = p_ptr->esp_giant;
3237         bool old_esp_dragon = p_ptr->esp_dragon;
3238         bool old_esp_human = p_ptr->esp_human;
3239         bool old_esp_evil = p_ptr->esp_evil;
3240         bool old_esp_good = p_ptr->esp_good;
3241         bool old_esp_nonliving = p_ptr->esp_nonliving;
3242         bool old_esp_unique = p_ptr->esp_unique;
3243         bool old_see_inv = p_ptr->see_inv;
3244         bool old_mighty_throw = p_ptr->mighty_throw;
3245
3246         /* Save the old armor class */
3247         s16b old_dis_ac = p_ptr->dis_ac;
3248         s16b old_dis_to_a = p_ptr->dis_to_a;
3249
3250
3251         /* Clear extra blows/shots */
3252         extra_blows[0] = extra_blows[1] = 0;
3253
3254         /* Clear the stat modifiers */
3255         for (i = 0; i < 6; i++) p_ptr->stat_add[i] = 0;
3256
3257
3258         /* Clear the Displayed/Real armor class */
3259         p_ptr->dis_ac = p_ptr->ac = 0;
3260
3261         /* Clear the Displayed/Real Bonuses */
3262         p_ptr->dis_to_h[0] = p_ptr->to_h[0] = 0;
3263         p_ptr->dis_to_h[1] = p_ptr->to_h[1] = 0;
3264         p_ptr->dis_to_d[0] = p_ptr->to_d[0] = 0;
3265         p_ptr->dis_to_d[1] = p_ptr->to_d[1] = 0;
3266         p_ptr->dis_to_h_b = p_ptr->to_h_b = 0;
3267         p_ptr->dis_to_a = p_ptr->to_a = 0;
3268         p_ptr->to_h_m = 0;
3269         p_ptr->to_d_m = 0;
3270
3271         p_ptr->to_m_chance = 0;
3272
3273         /* Clear the Extra Dice Bonuses */
3274         p_ptr->to_dd[0] = p_ptr->to_ds[0] = 0;
3275         p_ptr->to_dd[1] = p_ptr->to_ds[1] = 0;
3276
3277         /* Start with "normal" speed */
3278         new_speed = 110;
3279
3280         /* Start with a single blow per turn */
3281         p_ptr->num_blow[0] = 1;
3282         p_ptr->num_blow[1] = 1;
3283
3284         /* Start with a single shot per turn */
3285         p_ptr->num_fire = 100;
3286
3287         /* Reset the "xtra" tval */
3288         p_ptr->tval_xtra = 0;
3289
3290         /* Reset the "ammo" tval */
3291         p_ptr->tval_ammo = 0;
3292
3293         /* Clear all the flags */
3294         p_ptr->cursed = 0L;
3295         p_ptr->bless_blade = FALSE;
3296         p_ptr->xtra_might = FALSE;
3297         p_ptr->impact[0] = FALSE;
3298         p_ptr->impact[1] = FALSE;
3299         p_ptr->pass_wall = FALSE;
3300         p_ptr->kill_wall = FALSE;
3301         p_ptr->dec_mana = FALSE;
3302         p_ptr->easy_spell = FALSE;
3303         p_ptr->heavy_spell = FALSE;
3304         p_ptr->see_inv = FALSE;
3305         p_ptr->free_act = FALSE;
3306         p_ptr->slow_digest = FALSE;
3307         p_ptr->regenerate = FALSE;
3308         p_ptr->can_swim = FALSE;
3309         p_ptr->levitation = FALSE;
3310         p_ptr->hold_exp = FALSE;
3311         p_ptr->telepathy = FALSE;
3312         p_ptr->esp_animal = FALSE;
3313         p_ptr->esp_undead = FALSE;
3314         p_ptr->esp_demon = FALSE;
3315         p_ptr->esp_orc = FALSE;
3316         p_ptr->esp_troll = FALSE;
3317         p_ptr->esp_giant = FALSE;
3318         p_ptr->esp_dragon = FALSE;
3319         p_ptr->esp_human = FALSE;
3320         p_ptr->esp_evil = FALSE;
3321         p_ptr->esp_good = FALSE;
3322         p_ptr->esp_nonliving = FALSE;
3323         p_ptr->esp_unique = FALSE;
3324         p_ptr->lite = FALSE;
3325         p_ptr->sustain_str = FALSE;
3326         p_ptr->sustain_int = FALSE;
3327         p_ptr->sustain_wis = FALSE;
3328         p_ptr->sustain_con = FALSE;
3329         p_ptr->sustain_dex = FALSE;
3330         p_ptr->sustain_chr = FALSE;
3331         p_ptr->resist_acid = FALSE;
3332         p_ptr->resist_elec = FALSE;
3333         p_ptr->resist_fire = FALSE;
3334         p_ptr->resist_cold = FALSE;
3335         p_ptr->resist_pois = FALSE;
3336         p_ptr->resist_conf = FALSE;
3337         p_ptr->resist_sound = FALSE;
3338         p_ptr->resist_lite = FALSE;
3339         p_ptr->resist_dark = FALSE;
3340         p_ptr->resist_chaos = FALSE;
3341         p_ptr->resist_disen = FALSE;
3342         p_ptr->resist_shard = FALSE;
3343         p_ptr->resist_nexus = FALSE;
3344         p_ptr->resist_blind = FALSE;
3345         p_ptr->resist_neth = FALSE;
3346         p_ptr->resist_time = FALSE;
3347         p_ptr->resist_fear = FALSE;
3348         p_ptr->reflect = FALSE;
3349         p_ptr->sh_fire = FALSE;
3350         p_ptr->sh_elec = FALSE;
3351         p_ptr->sh_cold = FALSE;
3352         p_ptr->anti_magic = FALSE;
3353         p_ptr->anti_tele = FALSE;
3354         p_ptr->warning = FALSE;
3355         p_ptr->mighty_throw = FALSE;
3356         p_ptr->see_nocto = FALSE;
3357
3358         p_ptr->immune_acid = FALSE;
3359         p_ptr->immune_elec = FALSE;
3360         p_ptr->immune_fire = FALSE;
3361         p_ptr->immune_cold = FALSE;
3362
3363         p_ptr->ryoute = FALSE;
3364         p_ptr->migite = FALSE;
3365         p_ptr->hidarite = FALSE;
3366         p_ptr->no_flowed = FALSE;
3367
3368         p_ptr->align = friend_align;
3369
3370         if (p_ptr->mimic_form) tmp_rp_ptr = &mimic_info[p_ptr->mimic_form];
3371         else tmp_rp_ptr = &race_info[p_ptr->prace];
3372
3373         /* Base infravision (purely racial) */
3374         p_ptr->see_infra = tmp_rp_ptr->infra;
3375
3376         /* Base skill -- disarming */
3377         p_ptr->skill_dis = tmp_rp_ptr->r_dis + cp_ptr->c_dis + ap_ptr->a_dis;
3378
3379         /* Base skill -- magic devices */
3380         p_ptr->skill_dev = tmp_rp_ptr->r_dev + cp_ptr->c_dev + ap_ptr->a_dev;
3381
3382         /* Base skill -- saving throw */
3383         p_ptr->skill_sav = tmp_rp_ptr->r_sav + cp_ptr->c_sav + ap_ptr->a_sav;
3384
3385         /* Base skill -- stealth */
3386         p_ptr->skill_stl = tmp_rp_ptr->r_stl + cp_ptr->c_stl + ap_ptr->a_stl;
3387
3388         /* Base skill -- searching ability */
3389         p_ptr->skill_srh = tmp_rp_ptr->r_srh + cp_ptr->c_srh + ap_ptr->a_srh;
3390
3391         /* Base skill -- searching frequency */
3392         p_ptr->skill_fos = tmp_rp_ptr->r_fos + cp_ptr->c_fos + ap_ptr->a_fos;
3393
3394         /* Base skill -- combat (normal) */
3395         p_ptr->skill_thn = tmp_rp_ptr->r_thn + cp_ptr->c_thn + ap_ptr->a_thn;
3396
3397         /* Base skill -- combat (shooting) */
3398         p_ptr->skill_thb = tmp_rp_ptr->r_thb + cp_ptr->c_thb + ap_ptr->a_thb;
3399
3400         /* Base skill -- combat (throwing) */
3401         p_ptr->skill_tht = tmp_rp_ptr->r_thb + cp_ptr->c_thb + ap_ptr->a_thb;
3402
3403         /* Base skill -- digging */
3404         p_ptr->skill_dig = 0;
3405
3406         if (buki_motteruka(INVEN_RARM)) p_ptr->migite = TRUE;
3407         if (buki_motteruka(INVEN_LARM))
3408         {
3409                 p_ptr->hidarite = TRUE;
3410                 if (!p_ptr->migite) default_hand = 1;
3411         }
3412
3413         if (CAN_TWO_HANDS_WIELDING())
3414         {
3415                 if (p_ptr->migite && (empty_hands(FALSE) == EMPTY_HAND_LARM) &&
3416                         object_allow_two_hands_wielding(&inventory[INVEN_RARM]))
3417                 {
3418                         p_ptr->ryoute = TRUE;
3419                 }
3420                 else if (p_ptr->hidarite && (empty_hands(FALSE) == EMPTY_HAND_RARM) &&
3421                         object_allow_two_hands_wielding(&inventory[INVEN_LARM]))
3422                 {
3423                         p_ptr->ryoute = TRUE;
3424                 }
3425                 else
3426                 {
3427                         switch (p_ptr->pclass)
3428                         {
3429                         case CLASS_MONK:
3430                         case CLASS_FORCETRAINER:
3431                         case CLASS_BERSERKER:
3432                                 if (empty_hands(FALSE) == (EMPTY_HAND_RARM | EMPTY_HAND_LARM))
3433                                 {
3434                                         p_ptr->migite = TRUE;
3435                                         p_ptr->ryoute = TRUE;
3436                                 }
3437                                 break;
3438                         }
3439                 }
3440         }
3441
3442         if (!p_ptr->migite && !p_ptr->hidarite)
3443         {
3444                 if (empty_hands_status & EMPTY_HAND_RARM) p_ptr->migite = TRUE;
3445                 else if (empty_hands_status == EMPTY_HAND_LARM)
3446                 {
3447                         p_ptr->hidarite = TRUE;
3448                         default_hand = 1;
3449                 }
3450         }
3451
3452         if (p_ptr->special_defense & KAMAE_MASK)
3453         {
3454                 if (!(empty_hands_status & EMPTY_HAND_RARM))
3455                 {
3456                         set_action(ACTION_NONE);
3457                 }
3458         }
3459
3460         switch (p_ptr->pclass)
3461         {
3462                 case CLASS_WARRIOR:
3463                         if (p_ptr->lev > 29) p_ptr->resist_fear = TRUE;
3464                         if (p_ptr->lev > 44) p_ptr->regenerate = TRUE;
3465                         break;
3466                 case CLASS_PALADIN:
3467                         if (p_ptr->lev > 39) p_ptr->resist_fear = TRUE;
3468                         break;
3469                 case CLASS_CHAOS_WARRIOR:
3470                         if (p_ptr->lev > 29) p_ptr->resist_chaos = TRUE;
3471                         if (p_ptr->lev > 39) p_ptr->resist_fear = TRUE;
3472                         break;
3473                 case CLASS_MINDCRAFTER:
3474                         if (p_ptr->lev >  9) p_ptr->resist_fear = TRUE;
3475                         if (p_ptr->lev > 19) p_ptr->sustain_wis = TRUE;
3476                         if (p_ptr->lev > 29) p_ptr->resist_conf = TRUE;
3477                         if (p_ptr->lev > 39) p_ptr->telepathy = TRUE;
3478                         break;
3479                 case CLASS_MONK:
3480                 case CLASS_FORCETRAINER:
3481                         /* Unencumbered Monks become faster every 10 levels */
3482                         if (!(heavy_armor()))
3483                         {
3484                                 if (!(prace_is_(RACE_KLACKON) ||
3485                                       prace_is_(RACE_SPRITE) ||
3486                                       (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)))
3487                                         new_speed += (p_ptr->lev) / 10;
3488
3489                                 /* Free action if unencumbered at level 25 */
3490                                 if  (p_ptr->lev > 24)
3491                                         p_ptr->free_act = TRUE;
3492                         }
3493                         break;
3494                 case CLASS_SORCERER:
3495                         p_ptr->to_a -= 50;
3496                         p_ptr->dis_to_a -= 50;
3497                         break;
3498                 case CLASS_BARD:
3499                         p_ptr->resist_sound = TRUE;
3500                         break;
3501                 case CLASS_SAMURAI:
3502                         if (p_ptr->lev > 29) p_ptr->resist_fear = TRUE;
3503                         break;
3504                 case CLASS_BERSERKER:
3505                         p_ptr->shero = 1;
3506                         p_ptr->sustain_str = TRUE;
3507                         p_ptr->sustain_dex = TRUE;
3508                         p_ptr->sustain_con = TRUE;
3509                         p_ptr->regenerate = TRUE;
3510                         p_ptr->free_act = TRUE;
3511                         new_speed += 2;
3512                         if (p_ptr->lev > 29) new_speed++;
3513                         if (p_ptr->lev > 39) new_speed++;
3514                         if (p_ptr->lev > 44) new_speed++;
3515                         if (p_ptr->lev > 49) new_speed++;
3516                         p_ptr->to_a += 10+p_ptr->lev/2;
3517                         p_ptr->dis_to_a += 10+p_ptr->lev/2;
3518                         p_ptr->skill_dig += (100+p_ptr->lev*8);
3519                         if (p_ptr->lev > 39) p_ptr->reflect = TRUE;
3520                         p_ptr->redraw |= PR_STATUS;
3521                         break;
3522                 case CLASS_MIRROR_MASTER:
3523                         if (p_ptr->lev > 39) p_ptr->reflect = TRUE;
3524                         break;
3525                 case CLASS_NINJA:
3526                         /* Unencumbered Ninjas become faster every 10 levels */
3527                         if (heavy_armor())
3528                         {
3529                                 new_speed -= (p_ptr->lev) / 10;
3530                                 p_ptr->skill_stl -= (p_ptr->lev)/10;
3531                         }
3532                         else if ((!inventory[INVEN_RARM].k_idx || p_ptr->migite) &&
3533                                  (!inventory[INVEN_LARM].k_idx || p_ptr->hidarite))
3534                         {
3535                                 new_speed += 3;
3536                                 if (!(prace_is_(RACE_KLACKON) ||
3537                                       prace_is_(RACE_SPRITE) ||
3538                                       (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)))
3539                                         new_speed += (p_ptr->lev) / 10;
3540                                 p_ptr->skill_stl += (p_ptr->lev)/10;
3541
3542                                 /* Free action if unencumbered at level 25 */
3543                                 if  (p_ptr->lev > 24)
3544                                         p_ptr->free_act = TRUE;
3545                         }
3546                         if ((!inventory[INVEN_RARM].k_idx || p_ptr->migite) &&
3547                             (!inventory[INVEN_LARM].k_idx || p_ptr->hidarite))
3548                         {
3549                                 p_ptr->to_a += p_ptr->lev/2+5;
3550                                 p_ptr->dis_to_a += p_ptr->lev/2+5;
3551                         }
3552                         p_ptr->slow_digest = TRUE;
3553                         p_ptr->resist_fear = TRUE;
3554                         if (p_ptr->lev > 19) p_ptr->resist_pois = TRUE;
3555                         if (p_ptr->lev > 24) p_ptr->sustain_dex = TRUE;
3556                         if (p_ptr->lev > 29) p_ptr->see_inv = TRUE;
3557                         if (p_ptr->lev > 44)
3558                         {
3559                                 p_ptr->oppose_pois = 1;
3560                                 p_ptr->redraw |= PR_STATUS;
3561                         }
3562                         p_ptr->see_nocto = TRUE;
3563                         break;
3564         }
3565
3566         /***** Races ****/
3567         if (p_ptr->mimic_form)
3568         {
3569                 switch (p_ptr->mimic_form)
3570                 {
3571                 case MIMIC_DEMON:
3572                         p_ptr->hold_exp = TRUE;
3573                         p_ptr->resist_chaos = TRUE;
3574                         p_ptr->resist_neth = TRUE;
3575                         p_ptr->resist_fire = TRUE;
3576                         p_ptr->oppose_fire = 1;
3577                         p_ptr->see_inv=TRUE;
3578                         new_speed += 3;
3579                         p_ptr->redraw |= PR_STATUS;
3580                         p_ptr->to_a += 10;
3581                         p_ptr->dis_to_a += 10;
3582                         p_ptr->align -= 200;
3583                         break;
3584                 case MIMIC_DEMON_LORD:
3585                         p_ptr->hold_exp = TRUE;
3586                         p_ptr->resist_chaos = TRUE;
3587                         p_ptr->resist_neth = TRUE;
3588                         p_ptr->immune_fire = TRUE;
3589                         p_ptr->resist_acid = TRUE;
3590                         p_ptr->resist_fire = TRUE;
3591                         p_ptr->resist_cold = TRUE;
3592                         p_ptr->resist_elec = TRUE;
3593                         p_ptr->resist_pois = TRUE;
3594                         p_ptr->resist_conf = TRUE;
3595                         p_ptr->resist_disen = TRUE;
3596                         p_ptr->resist_nexus = TRUE;
3597                         p_ptr->resist_fear = TRUE;
3598                         p_ptr->sh_fire = TRUE;
3599                         p_ptr->see_inv = TRUE;
3600                         p_ptr->telepathy = TRUE;
3601                         p_ptr->levitation = TRUE;
3602                         p_ptr->kill_wall = TRUE;
3603                         new_speed += 5;
3604                         p_ptr->to_a += 20;
3605                         p_ptr->dis_to_a += 20;
3606                         p_ptr->align -= 200;
3607                         break;
3608                 case MIMIC_VAMPIRE:
3609                         p_ptr->resist_dark = TRUE;
3610                         p_ptr->hold_exp = TRUE;
3611                         p_ptr->resist_neth = TRUE;
3612                         p_ptr->resist_cold = TRUE;
3613                         p_ptr->resist_pois = TRUE;
3614                         p_ptr->see_inv = TRUE;
3615                         new_speed += 3;
3616                         p_ptr->to_a += 10;
3617                         p_ptr->dis_to_a += 10;
3618                         if (p_ptr->pclass != CLASS_NINJA) p_ptr->lite = TRUE;
3619                         break;
3620                 }
3621         }
3622         else
3623         {
3624                 switch (p_ptr->prace)
3625                 {
3626                 case RACE_ELF:
3627                         p_ptr->resist_lite = TRUE;
3628                         break;
3629                 case RACE_HOBBIT:
3630                         p_ptr->hold_exp = TRUE;
3631                         break;
3632                 case RACE_GNOME:
3633                         p_ptr->free_act = TRUE;
3634                         break;
3635                 case RACE_DWARF:
3636                         p_ptr->resist_blind = TRUE;
3637                         break;
3638                 case RACE_HALF_ORC:
3639                         p_ptr->resist_dark = TRUE;
3640                         break;
3641                 case RACE_HALF_TROLL:
3642                         p_ptr->sustain_str = TRUE;
3643
3644                         if (p_ptr->lev > 14)
3645                         {
3646                                 /* High level trolls heal fast... */
3647                                 p_ptr->regenerate = TRUE;
3648
3649                                 if (p_ptr->pclass == CLASS_WARRIOR || p_ptr->pclass == CLASS_BERSERKER)
3650                                 {
3651                                         p_ptr->slow_digest = TRUE;
3652                                         /* Let's not make Regeneration
3653                                          * a disadvantage for the poor warriors who can
3654                                          * never learn a spell that satisfies hunger (actually
3655                                          * neither can rogues, but half-trolls are not
3656                                          * supposed to play rogues) */
3657                                 }
3658                         }
3659                         break;
3660                 case RACE_AMBERITE:
3661                         p_ptr->sustain_con = TRUE;
3662                         p_ptr->regenerate = TRUE;  /* Amberites heal fast... */
3663                         break;
3664                 case RACE_HIGH_ELF:
3665                         p_ptr->resist_lite = TRUE;
3666                         p_ptr->see_inv = TRUE;
3667                         break;
3668                 case RACE_BARBARIAN:
3669                         p_ptr->resist_fear = TRUE;
3670                         break;
3671                 case RACE_HALF_OGRE:
3672                         p_ptr->resist_dark = TRUE;
3673                         p_ptr->sustain_str = TRUE;
3674                         break;
3675                 case RACE_HALF_GIANT:
3676                         p_ptr->sustain_str = TRUE;
3677                         p_ptr->resist_shard = TRUE;
3678                         break;
3679                 case RACE_HALF_TITAN:
3680                         p_ptr->resist_chaos = TRUE;
3681                         break;
3682                 case RACE_CYCLOPS:
3683                         p_ptr->resist_sound = TRUE;
3684                         break;
3685                 case RACE_YEEK:
3686                         p_ptr->resist_acid = TRUE;
3687                         if (p_ptr->lev > 19) p_ptr->immune_acid = TRUE;
3688                         break;
3689                 case RACE_KLACKON:
3690                         p_ptr->resist_conf = TRUE;
3691                         p_ptr->resist_acid = TRUE;
3692
3693                         /* Klackons become faster */
3694                         new_speed += (p_ptr->lev) / 10;
3695                         break;
3696                 case RACE_KOBOLD:
3697                         p_ptr->resist_pois = TRUE;
3698                         break;
3699                 case RACE_NIBELUNG:
3700                         p_ptr->resist_disen = TRUE;
3701                         p_ptr->resist_dark = TRUE;
3702                         break;
3703                 case RACE_DARK_ELF:
3704                         p_ptr->resist_dark = TRUE;
3705                         if (p_ptr->lev > 19) p_ptr->see_inv = TRUE;
3706                         break;
3707                 case RACE_DRACONIAN:
3708                         p_ptr->levitation = TRUE;
3709                         if (p_ptr->lev >  4) p_ptr->resist_fire = TRUE;
3710                         if (p_ptr->lev >  9) p_ptr->resist_cold = TRUE;
3711                         if (p_ptr->lev > 14) p_ptr->resist_acid = TRUE;
3712                         if (p_ptr->lev > 19) p_ptr->resist_elec = TRUE;
3713                         if (p_ptr->lev > 34) p_ptr->resist_pois = TRUE;
3714                         break;
3715                 case RACE_MIND_FLAYER:
3716                         p_ptr->sustain_int = TRUE;
3717                         p_ptr->sustain_wis = TRUE;
3718                         if (p_ptr->lev > 14) p_ptr->see_inv = TRUE;
3719                         if (p_ptr->lev > 29) p_ptr->telepathy = TRUE;
3720                         break;
3721                 case RACE_IMP:
3722                         p_ptr->resist_fire = TRUE;
3723                         if (p_ptr->lev > 9) p_ptr->see_inv = TRUE;
3724                         break;
3725                 case RACE_GOLEM:
3726                         p_ptr->slow_digest = TRUE;
3727                         p_ptr->free_act = TRUE;
3728                         p_ptr->see_inv = TRUE;
3729                         p_ptr->resist_pois = TRUE;
3730                         if (p_ptr->lev > 34) p_ptr->hold_exp = TRUE;
3731                         break;
3732                 case RACE_SKELETON:
3733                         p_ptr->resist_shard = TRUE;
3734                         p_ptr->hold_exp = TRUE;
3735                         p_ptr->see_inv = TRUE;
3736                         p_ptr->resist_pois = TRUE;
3737                         if (p_ptr->lev > 9) p_ptr->resist_cold = TRUE;
3738                         break;
3739                 case RACE_ZOMBIE:
3740                         p_ptr->resist_neth = TRUE;
3741                         p_ptr->hold_exp = TRUE;
3742                         p_ptr->see_inv = TRUE;
3743                         p_ptr->resist_pois = TRUE;
3744                         p_ptr->slow_digest = TRUE;
3745                         if (p_ptr->lev > 4) p_ptr->resist_cold = TRUE;
3746                         break;
3747                 case RACE_VAMPIRE:
3748                         p_ptr->resist_dark = TRUE;
3749                         p_ptr->hold_exp = TRUE;
3750                         p_ptr->resist_neth = TRUE;
3751                         p_ptr->resist_cold = TRUE;
3752                         p_ptr->resist_pois = TRUE;
3753                         if (p_ptr->pclass != CLASS_NINJA) p_ptr->lite = TRUE;
3754                         break;
3755                 case RACE_SPECTRE:
3756                         p_ptr->levitation = TRUE;
3757                         p_ptr->free_act = TRUE;
3758                         p_ptr->resist_neth = TRUE;
3759                         p_ptr->hold_exp = TRUE;
3760                         p_ptr->see_inv = TRUE;
3761                         p_ptr->resist_pois = TRUE;
3762                         p_ptr->slow_digest = TRUE;
3763                         p_ptr->resist_cold = TRUE;
3764                         p_ptr->pass_wall = TRUE;
3765                         if (p_ptr->lev > 34) p_ptr->telepathy = TRUE;
3766                         break;
3767                 case RACE_SPRITE:
3768                         p_ptr->levitation = TRUE;
3769                         p_ptr->resist_lite = TRUE;
3770
3771                         /* Sprites become faster */
3772                         new_speed += (p_ptr->lev) / 10;
3773                         break;
3774                 case RACE_BEASTMAN:
3775                         p_ptr->resist_conf  = TRUE;
3776                         p_ptr->resist_sound = TRUE;
3777                         break;
3778                 case RACE_ENT:
3779                         /* Ents dig like maniacs, but only with their hands. */
3780                         if (!inventory[INVEN_RARM].k_idx) 
3781                                 p_ptr->skill_dig += p_ptr->lev * 10;
3782                         /* Ents get tougher and stronger as they age, but lose dexterity. */
3783                         if (p_ptr->lev > 25) p_ptr->stat_add[A_STR]++;
3784                         if (p_ptr->lev > 40) p_ptr->stat_add[A_STR]++;
3785                         if (p_ptr->lev > 45) p_ptr->stat_add[A_STR]++;
3786
3787                         if (p_ptr->lev > 25) p_ptr->stat_add[A_DEX]--;
3788                         if (p_ptr->lev > 40) p_ptr->stat_add[A_DEX]--;
3789                         if (p_ptr->lev > 45) p_ptr->stat_add[A_DEX]--;
3790
3791                         if (p_ptr->lev > 25) p_ptr->stat_add[A_CON]++;
3792                         if (p_ptr->lev > 40) p_ptr->stat_add[A_CON]++;
3793                         if (p_ptr->lev > 45) p_ptr->stat_add[A_CON]++;
3794                         break;
3795                 case RACE_ANGEL:
3796                         p_ptr->levitation = TRUE;
3797                         p_ptr->see_inv = TRUE;
3798                         p_ptr->align += 200;
3799                         break;
3800                 case RACE_DEMON:
3801                         p_ptr->resist_fire  = TRUE;
3802                         p_ptr->resist_neth  = TRUE;
3803                         p_ptr->hold_exp = TRUE;
3804                         if (p_ptr->lev > 9) p_ptr->see_inv = TRUE;
3805                         if (p_ptr->lev > 44)
3806                         {
3807                                 p_ptr->oppose_fire = 1;
3808                                 p_ptr->redraw |= PR_STATUS;
3809                         }
3810                         p_ptr->align -= 200;
3811                         break;
3812                 case RACE_DUNADAN:
3813                         p_ptr->sustain_con = TRUE;
3814                         break;
3815                 case RACE_S_FAIRY:
3816                         p_ptr->levitation = TRUE;
3817                         break;
3818                 case RACE_KUTAR:
3819                         p_ptr->resist_conf = TRUE;
3820                         break;
3821                 case RACE_ANDROID:
3822                         p_ptr->slow_digest = TRUE;
3823                         p_ptr->free_act = TRUE;
3824                         p_ptr->resist_pois = TRUE;
3825                         p_ptr->hold_exp = TRUE;
3826                         break;
3827                 default:
3828                         /* Do nothing */
3829                         ;
3830                 }
3831         }
3832
3833         if (p_ptr->ult_res || (p_ptr->special_defense & KATA_MUSOU))
3834         {
3835                 p_ptr->see_inv = TRUE;
3836                 p_ptr->free_act = TRUE;
3837                 p_ptr->slow_digest = TRUE;
3838                 p_ptr->regenerate = TRUE;
3839                 p_ptr->levitation = TRUE;
3840                 p_ptr->hold_exp = TRUE;
3841                 p_ptr->telepathy = TRUE;
3842                 p_ptr->lite = TRUE;
3843                 p_ptr->sustain_str = TRUE;
3844                 p_ptr->sustain_int = TRUE;
3845                 p_ptr->sustain_wis = TRUE;
3846                 p_ptr->sustain_con = TRUE;
3847                 p_ptr->sustain_dex = TRUE;
3848                 p_ptr->sustain_chr = TRUE;
3849                 p_ptr->resist_acid = TRUE;
3850                 p_ptr->resist_elec = TRUE;
3851                 p_ptr->resist_fire = TRUE;
3852                 p_ptr->resist_cold = TRUE;
3853                 p_ptr->resist_pois = TRUE;
3854                 p_ptr->resist_conf = TRUE;
3855                 p_ptr->resist_sound = TRUE;
3856                 p_ptr->resist_lite = TRUE;
3857                 p_ptr->resist_dark = TRUE;
3858                 p_ptr->resist_chaos = TRUE;
3859                 p_ptr->resist_disen = TRUE;
3860                 p_ptr->resist_shard = TRUE;
3861                 p_ptr->resist_nexus = TRUE;
3862                 p_ptr->resist_blind = TRUE;
3863                 p_ptr->resist_neth = TRUE;
3864                 p_ptr->resist_fear = TRUE;
3865                 p_ptr->reflect = TRUE;
3866                 p_ptr->sh_fire = TRUE;
3867                 p_ptr->sh_elec = TRUE;
3868                 p_ptr->sh_cold = TRUE;
3869                 p_ptr->to_a += 100;
3870                 p_ptr->dis_to_a += 100;
3871         }
3872         /* Temporary shield */
3873         else if (p_ptr->tsubureru || p_ptr->shield || p_ptr->magicdef)
3874         {
3875                 p_ptr->to_a += 50;
3876                 p_ptr->dis_to_a += 50;
3877         }
3878
3879         if (p_ptr->tim_res_nether)
3880         {
3881                 p_ptr->resist_neth = TRUE;
3882         }
3883         if (p_ptr->tim_sh_fire)
3884         {
3885                 p_ptr->sh_fire = TRUE;
3886         }
3887         if (p_ptr->tim_res_time)
3888         {
3889                 p_ptr->resist_time = TRUE;
3890         }
3891
3892         /* Sexy Gal */
3893         if (p_ptr->pseikaku == SEIKAKU_SEXY) p_ptr->cursed |= (TRC_AGGRAVATE);
3894         if (p_ptr->pseikaku == SEIKAKU_NAMAKE) p_ptr->to_m_chance += 10;
3895         if (p_ptr->pseikaku == SEIKAKU_KIREMONO) p_ptr->to_m_chance -= 3;
3896         if ((p_ptr->pseikaku == SEIKAKU_GAMAN) || (p_ptr->pseikaku == SEIKAKU_CHIKARA)) p_ptr->to_m_chance++;
3897
3898         /* Lucky man */
3899         if (p_ptr->pseikaku == SEIKAKU_LUCKY) p_ptr->muta3 |= MUT3_GOOD_LUCK;
3900
3901         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
3902         {
3903                 p_ptr->resist_blind = TRUE;
3904                 p_ptr->resist_conf  = TRUE;
3905                 p_ptr->hold_exp = TRUE;
3906                 if (p_ptr->pclass != CLASS_NINJA) p_ptr->lite = TRUE;
3907
3908                 if ((p_ptr->prace != RACE_KLACKON) && (p_ptr->prace != RACE_SPRITE))
3909                         /* Munchkin become faster */
3910                         new_speed += (p_ptr->lev) / 10 + 5;
3911         }
3912
3913         if (music_singing(MUSIC_WALL))
3914         {
3915                 p_ptr->kill_wall = TRUE;
3916         }
3917
3918         /* Hack -- apply racial/class stat maxes */
3919         /* Apply the racial modifiers */
3920         for (i = 0; i < 6; i++)
3921         {
3922                 /* Modify the stats for "race" */
3923                 p_ptr->stat_add[i] += (tmp_rp_ptr->r_adj[i] + cp_ptr->c_adj[i] + ap_ptr->a_adj[i]);
3924         }
3925
3926
3927         /* I'm adding the mutations here for the lack of a better place... */
3928         if (p_ptr->muta3)
3929         {
3930                 /* Hyper Strength */
3931                 if (p_ptr->muta3 & MUT3_HYPER_STR)
3932                 {
3933                         p_ptr->stat_add[A_STR] += 4;
3934                 }
3935
3936                 /* Puny */
3937                 if (p_ptr->muta3 & MUT3_PUNY)
3938                 {
3939                         p_ptr->stat_add[A_STR] -= 4;
3940                 }
3941
3942                 /* Living computer */
3943                 if (p_ptr->muta3 & MUT3_HYPER_INT)
3944                 {
3945                         p_ptr->stat_add[A_INT] += 4;
3946                         p_ptr->stat_add[A_WIS] += 4;
3947                 }
3948
3949                 /* Moronic */
3950                 if (p_ptr->muta3 & MUT3_MORONIC)
3951                 {
3952                         p_ptr->stat_add[A_INT] -= 4;
3953                         p_ptr->stat_add[A_WIS] -= 4;
3954                 }
3955
3956                 if (p_ptr->muta3 & MUT3_RESILIENT)
3957                 {
3958                         p_ptr->stat_add[A_CON] += 4;
3959                 }
3960
3961                 if (p_ptr->muta3 & MUT3_XTRA_FAT)
3962                 {
3963                         p_ptr->stat_add[A_CON] += 2;
3964                         new_speed -= 2;
3965                 }
3966
3967                 if (p_ptr->muta3 & MUT3_ALBINO)
3968                 {
3969                         p_ptr->stat_add[A_CON] -= 4;
3970                 }
3971
3972                 if (p_ptr->muta3 & MUT3_FLESH_ROT)
3973                 {
3974                         p_ptr->stat_add[A_CON] -= 2;
3975                         p_ptr->stat_add[A_CHR] -= 1;
3976                         p_ptr->regenerate = FALSE;
3977                         /* Cancel innate regeneration */
3978                 }
3979
3980                 if (p_ptr->muta3 & MUT3_SILLY_VOI)
3981                 {
3982                         p_ptr->stat_add[A_CHR] -= 4;
3983                 }
3984
3985                 if (p_ptr->muta3 & MUT3_BLANK_FAC)
3986                 {
3987                         p_ptr->stat_add[A_CHR] -= 1;
3988                 }
3989
3990                 if (p_ptr->muta3 & MUT3_XTRA_EYES)
3991                 {
3992                         p_ptr->skill_fos += 15;
3993                         p_ptr->skill_srh += 15;
3994                 }
3995
3996                 if (p_ptr->muta3 & MUT3_MAGIC_RES)
3997                 {
3998                         p_ptr->skill_sav += (15 + (p_ptr->lev / 5));
3999                 }
4000
4001                 if (p_ptr->muta3 & MUT3_XTRA_NOIS)
4002                 {
4003                         p_ptr->skill_stl -= 3;
4004                 }
4005
4006                 if (p_ptr->muta3 & MUT3_INFRAVIS)
4007                 {
4008                         p_ptr->see_infra += 3;
4009                 }
4010
4011                 if (p_ptr->muta3 & MUT3_XTRA_LEGS)
4012                 {
4013                         new_speed += 3;
4014                 }
4015
4016                 if (p_ptr->muta3 & MUT3_SHORT_LEG)
4017                 {
4018                         new_speed -= 3;
4019                 }
4020
4021                 if (p_ptr->muta3 & MUT3_ELEC_TOUC)
4022                 {
4023                         p_ptr->sh_elec = TRUE;
4024                 }
4025
4026                 if (p_ptr->muta3 & MUT3_FIRE_BODY)
4027                 {
4028                         p_ptr->sh_fire = TRUE;
4029                         p_ptr->lite = TRUE;
4030                 }
4031
4032                 if (p_ptr->muta3 & MUT3_WART_SKIN)
4033                 {
4034                         p_ptr->stat_add[A_CHR] -= 2;
4035                         p_ptr->to_a += 5;
4036                         p_ptr->dis_to_a += 5;
4037                 }
4038
4039                 if (p_ptr->muta3 & MUT3_SCALES)
4040                 {
4041                         p_ptr->stat_add[A_CHR] -= 1;
4042                         p_ptr->to_a += 10;
4043                         p_ptr->dis_to_a += 10;
4044                 }
4045
4046                 if (p_ptr->muta3 & MUT3_IRON_SKIN)
4047                 {
4048                         p_ptr->stat_add[A_DEX] -= 1;
4049                         p_ptr->to_a += 25;
4050                         p_ptr->dis_to_a += 25;
4051                 }
4052
4053                 if (p_ptr->muta3 & MUT3_WINGS)
4054                 {
4055                         p_ptr->levitation = TRUE;
4056                 }
4057
4058                 if (p_ptr->muta3 & MUT3_FEARLESS)
4059                 {
4060                         p_ptr->resist_fear = TRUE;
4061                 }
4062
4063                 if (p_ptr->muta3 & MUT3_REGEN)
4064                 {
4065                         p_ptr->regenerate = TRUE;
4066                 }
4067
4068                 if (p_ptr->muta3 & MUT3_ESP)
4069                 {
4070                         p_ptr->telepathy = TRUE;
4071                 }
4072
4073                 if (p_ptr->muta3 & MUT3_LIMBER)
4074                 {
4075                         p_ptr->stat_add[A_DEX] += 3;
4076                 }
4077
4078                 if (p_ptr->muta3 & MUT3_ARTHRITIS)
4079                 {
4080                         p_ptr->stat_add[A_DEX] -= 3;
4081                 }
4082
4083                 if (p_ptr->muta3 & MUT3_MOTION)
4084                 {
4085                         p_ptr->free_act = TRUE;
4086                         p_ptr->skill_stl += 1;
4087                 }
4088
4089                 if (p_ptr->muta3 & MUT3_ILL_NORM)
4090                 {
4091                         p_ptr->stat_add[A_CHR] = 0;
4092                 }
4093         }
4094
4095         if (p_ptr->tsuyoshi)
4096         {
4097                 p_ptr->stat_add[A_STR] += 4;
4098                 p_ptr->stat_add[A_CON] += 4;
4099         }
4100
4101         /* Scan the usable inventory */
4102         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
4103         {
4104                 int bonus_to_h, bonus_to_d;
4105                 o_ptr = &inventory[i];
4106
4107                 /* Skip non-objects */
4108                 if (!o_ptr->k_idx) continue;
4109
4110                 /* Extract the item flags */
4111                 object_flags(o_ptr, flgs);
4112
4113                 p_ptr->cursed |= (o_ptr->curse_flags & (0xFFFFFFF0L));
4114                 if (o_ptr->name1 == ART_CHAINSWORD) p_ptr->cursed |= TRC_CHAINSWORD;
4115
4116                 /* Affect stats */
4117                 if (have_flag(flgs, TR_STR)) p_ptr->stat_add[A_STR] += o_ptr->pval;
4118                 if (have_flag(flgs, TR_INT)) p_ptr->stat_add[A_INT] += o_ptr->pval;
4119                 if (have_flag(flgs, TR_WIS)) p_ptr->stat_add[A_WIS] += o_ptr->pval;
4120                 if (have_flag(flgs, TR_DEX)) p_ptr->stat_add[A_DEX] += o_ptr->pval;
4121                 if (have_flag(flgs, TR_CON)) p_ptr->stat_add[A_CON] += o_ptr->pval;
4122                 if (have_flag(flgs, TR_CHR)) p_ptr->stat_add[A_CHR] += o_ptr->pval;
4123
4124                 if (have_flag(flgs, TR_MAGIC_MASTERY))    p_ptr->skill_dev += 8*o_ptr->pval;
4125
4126                 /* Affect stealth */
4127                 if (have_flag(flgs, TR_STEALTH)) p_ptr->skill_stl += o_ptr->pval;
4128
4129                 /* Affect searching ability (factor of five) */
4130                 if (have_flag(flgs, TR_SEARCH)) p_ptr->skill_srh += (o_ptr->pval * 5);
4131
4132                 /* Affect searching frequency (factor of five) */
4133                 if (have_flag(flgs, TR_SEARCH)) p_ptr->skill_fos += (o_ptr->pval * 5);
4134
4135                 /* Affect infravision */
4136                 if (have_flag(flgs, TR_INFRA)) p_ptr->see_infra += o_ptr->pval;
4137
4138                 /* Affect digging (factor of 20) */
4139                 if (have_flag(flgs, TR_TUNNEL)) p_ptr->skill_dig += (o_ptr->pval * 20);
4140
4141                 /* Affect speed */
4142                 if (have_flag(flgs, TR_SPEED)) new_speed += o_ptr->pval;
4143
4144                 /* Affect blows */
4145                 if (have_flag(flgs, TR_BLOWS))
4146                 {
4147                         if((i == INVEN_RARM || i == INVEN_RIGHT) && !p_ptr->ryoute) extra_blows[0] += o_ptr->pval;
4148                         else if((i == INVEN_LARM || i == INVEN_LEFT) && !p_ptr->ryoute) extra_blows[1] += o_ptr->pval;
4149                         else {extra_blows[0] += o_ptr->pval; extra_blows[1] += o_ptr->pval;}
4150                 }
4151
4152                 /* Hack -- cause earthquakes */
4153                 if (have_flag(flgs, TR_IMPACT)) p_ptr->impact[(i == INVEN_RARM) ? 0 : 1] = TRUE;
4154
4155                 /* Various flags */
4156                 if (have_flag(flgs, TR_AGGRAVATE))   p_ptr->cursed |= TRC_AGGRAVATE;
4157                 if (have_flag(flgs, TR_DRAIN_EXP))   p_ptr->cursed |= TRC_DRAIN_EXP;
4158                 if (have_flag(flgs, TR_TY_CURSE))    p_ptr->cursed |= TRC_TY_CURSE;
4159                 if (have_flag(flgs, TR_ADD_L_CURSE)) p_ptr->cursed |= TRC_ADD_L_CURSE;
4160                 if (have_flag(flgs, TR_ADD_H_CURSE)) p_ptr->cursed |= TRC_ADD_H_CURSE;
4161                 if (have_flag(flgs, TR_DRAIN_HP))    p_ptr->cursed |= TRC_DRAIN_HP;
4162                 if (have_flag(flgs, TR_DRAIN_MANA))  p_ptr->cursed |= TRC_DRAIN_MANA;
4163                 if (have_flag(flgs, TR_CALL_ANIMAL)) p_ptr->cursed |= TRC_CALL_ANIMAL;
4164                 if (have_flag(flgs, TR_CALL_DEMON))  p_ptr->cursed |= TRC_CALL_DEMON;
4165                 if (have_flag(flgs, TR_CALL_DRAGON)) p_ptr->cursed |= TRC_CALL_DRAGON;
4166                 if (have_flag(flgs, TR_CALL_UNDEAD)) p_ptr->cursed |= TRC_CALL_UNDEAD;
4167                 if (have_flag(flgs, TR_COWARDICE))   p_ptr->cursed |= TRC_COWARDICE;
4168                 if (have_flag(flgs, TR_LOW_MELEE))   p_ptr->cursed |= TRC_LOW_MELEE;
4169                 if (have_flag(flgs, TR_LOW_AC))      p_ptr->cursed |= TRC_LOW_AC;
4170                 if (have_flag(flgs, TR_LOW_MAGIC))   p_ptr->cursed |= TRC_LOW_MAGIC;
4171                 if (have_flag(flgs, TR_FAST_DIGEST)) p_ptr->cursed |= TRC_FAST_DIGEST;
4172                 if (have_flag(flgs, TR_SLOW_REGEN))  p_ptr->cursed |= TRC_SLOW_REGEN;
4173                 if (have_flag(flgs, TR_DEC_MANA))    p_ptr->dec_mana = TRUE;
4174                 if (have_flag(flgs, TR_BLESSED))     p_ptr->bless_blade = TRUE;
4175                 if (have_flag(flgs, TR_XTRA_MIGHT))  p_ptr->xtra_might = TRUE;
4176                 if (have_flag(flgs, TR_SLOW_DIGEST)) p_ptr->slow_digest = TRUE;
4177                 if (have_flag(flgs, TR_REGEN))       p_ptr->regenerate = TRUE;
4178                 if (have_flag(flgs, TR_TELEPATHY))   p_ptr->telepathy = TRUE;
4179                 if (have_flag(flgs, TR_ESP_ANIMAL))  p_ptr->esp_animal = TRUE;
4180                 if (have_flag(flgs, TR_ESP_UNDEAD))  p_ptr->esp_undead = TRUE;
4181                 if (have_flag(flgs, TR_ESP_DEMON))   p_ptr->esp_demon = TRUE;
4182                 if (have_flag(flgs, TR_ESP_ORC))     p_ptr->esp_orc = TRUE;
4183                 if (have_flag(flgs, TR_ESP_TROLL))   p_ptr->esp_troll = TRUE;
4184                 if (have_flag(flgs, TR_ESP_GIANT))   p_ptr->esp_giant = TRUE;
4185                 if (have_flag(flgs, TR_ESP_DRAGON))  p_ptr->esp_dragon = TRUE;
4186                 if (have_flag(flgs, TR_ESP_HUMAN))   p_ptr->esp_human = TRUE;
4187                 if (have_flag(flgs, TR_ESP_EVIL))    p_ptr->esp_evil = TRUE;
4188                 if (have_flag(flgs, TR_ESP_GOOD))    p_ptr->esp_good = TRUE;
4189                 if (have_flag(flgs, TR_ESP_NONLIVING)) p_ptr->esp_nonliving = TRUE;
4190                 if (have_flag(flgs, TR_ESP_UNIQUE))  p_ptr->esp_unique = TRUE;
4191
4192                 if (have_flag(flgs, TR_SEE_INVIS))   p_ptr->see_inv = TRUE;
4193                 if (have_flag(flgs, TR_LEVITATION))     p_ptr->levitation = TRUE;
4194                 if (have_flag(flgs, TR_FREE_ACT))    p_ptr->free_act = TRUE;
4195                 if (have_flag(flgs, TR_HOLD_EXP))   p_ptr->hold_exp = TRUE;
4196                 if (have_flag(flgs, TR_WARNING)){
4197                         if (!o_ptr->inscription || !(my_strchr(quark_str(o_ptr->inscription),'$')))
4198                           p_ptr->warning = TRUE;
4199                 }
4200
4201                 if (have_flag(flgs, TR_TELEPORT))
4202                 {
4203                         if (object_is_cursed(o_ptr)) p_ptr->cursed |= TRC_TELEPORT;
4204                         else
4205                         {
4206                                 cptr insc = quark_str(o_ptr->inscription);
4207
4208                                 if (o_ptr->inscription && my_strchr(insc, '.'))
4209                                 {
4210                                         /*
4211                                          * {.} will stop random teleportation.
4212                                          */
4213                                 }
4214                                 else
4215                                 {
4216                                         /* Controlled random teleportation */
4217                                         p_ptr->cursed |= TRC_TELEPORT_SELF;
4218                                 }
4219                         }
4220                 }
4221
4222                 /* Immunity flags */
4223                 if (have_flag(flgs, TR_IM_FIRE)) p_ptr->immune_fire = TRUE;
4224                 if (have_flag(flgs, TR_IM_ACID)) p_ptr->immune_acid = TRUE;
4225                 if (have_flag(flgs, TR_IM_COLD)) p_ptr->immune_cold = TRUE;
4226                 if (have_flag(flgs, TR_IM_ELEC)) p_ptr->immune_elec = TRUE;
4227
4228                 /* Resistance flags */
4229                 if (have_flag(flgs, TR_RES_ACID))   p_ptr->resist_acid = TRUE;
4230                 if (have_flag(flgs, TR_RES_ELEC))   p_ptr->resist_elec = TRUE;
4231                 if (have_flag(flgs, TR_RES_FIRE))   p_ptr->resist_fire = TRUE;
4232                 if (have_flag(flgs, TR_RES_COLD))   p_ptr->resist_cold = TRUE;
4233                 if (have_flag(flgs, TR_RES_POIS))   p_ptr->resist_pois = TRUE;
4234                 if (have_flag(flgs, TR_RES_FEAR))   p_ptr->resist_fear = TRUE;
4235                 if (have_flag(flgs, TR_RES_CONF))   p_ptr->resist_conf = TRUE;
4236                 if (have_flag(flgs, TR_RES_SOUND))  p_ptr->resist_sound = TRUE;
4237                 if (have_flag(flgs, TR_RES_LITE))   p_ptr->resist_lite = TRUE;
4238                 if (have_flag(flgs, TR_RES_DARK))   p_ptr->resist_dark = TRUE;
4239                 if (have_flag(flgs, TR_RES_CHAOS))  p_ptr->resist_chaos = TRUE;
4240                 if (have_flag(flgs, TR_RES_DISEN))  p_ptr->resist_disen = TRUE;
4241                 if (have_flag(flgs, TR_RES_SHARDS)) p_ptr->resist_shard = TRUE;
4242                 if (have_flag(flgs, TR_RES_NEXUS))  p_ptr->resist_nexus = TRUE;
4243                 if (have_flag(flgs, TR_RES_BLIND))  p_ptr->resist_blind = TRUE;
4244                 if (have_flag(flgs, TR_RES_NETHER)) p_ptr->resist_neth = TRUE;
4245
4246                 if (have_flag(flgs, TR_REFLECT))  p_ptr->reflect = TRUE;
4247                 if (have_flag(flgs, TR_SH_FIRE))  p_ptr->sh_fire = TRUE;
4248                 if (have_flag(flgs, TR_SH_ELEC))  p_ptr->sh_elec = TRUE;
4249                 if (have_flag(flgs, TR_SH_COLD))  p_ptr->sh_cold = TRUE;
4250                 if (have_flag(flgs, TR_NO_MAGIC)) p_ptr->anti_magic = TRUE;
4251                 if (have_flag(flgs, TR_NO_TELE))  p_ptr->anti_tele = TRUE;
4252
4253                 /* Sustain flags */
4254                 if (have_flag(flgs, TR_SUST_STR)) p_ptr->sustain_str = TRUE;
4255                 if (have_flag(flgs, TR_SUST_INT)) p_ptr->sustain_int = TRUE;
4256                 if (have_flag(flgs, TR_SUST_WIS)) p_ptr->sustain_wis = TRUE;
4257                 if (have_flag(flgs, TR_SUST_DEX)) p_ptr->sustain_dex = TRUE;
4258                 if (have_flag(flgs, TR_SUST_CON)) p_ptr->sustain_con = TRUE;
4259                 if (have_flag(flgs, TR_SUST_CHR)) p_ptr->sustain_chr = TRUE;
4260
4261                 if (o_ptr->name2 == EGO_YOIYAMI) yoiyami = TRUE;
4262                 if (o_ptr->name2 == EGO_2WEAPON) easy_2weapon = TRUE;
4263                 if (o_ptr->name2 == EGO_RING_RES_TIME) p_ptr->resist_time = TRUE;
4264                 if (o_ptr->name2 == EGO_RING_THROW) p_ptr->mighty_throw = TRUE;
4265                 if (have_flag(flgs, TR_EASY_SPELL)) p_ptr->easy_spell = TRUE;
4266                 if (o_ptr->name2 == EGO_AMU_FOOL) p_ptr->heavy_spell = TRUE;
4267                 if (o_ptr->name2 == EGO_AMU_NAIVETY) down_saving = TRUE;
4268
4269                 if (o_ptr->curse_flags & TRC_LOW_MAGIC)
4270                 {
4271                         if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
4272                         {
4273                                 p_ptr->to_m_chance += 10;
4274                         }
4275                         else
4276                         {
4277                                 p_ptr->to_m_chance += 3;
4278                         }
4279                 }
4280
4281                 if (o_ptr->tval == TV_CAPTURE) continue;
4282
4283                 /* Modify the base armor class */
4284                 p_ptr->ac += o_ptr->ac;
4285
4286                 /* The base armor class is always known */
4287                 p_ptr->dis_ac += o_ptr->ac;
4288
4289                 /* Apply the bonuses to armor class */
4290                 p_ptr->to_a += o_ptr->to_a;
4291
4292                 /* Apply the mental bonuses to armor class, if known */
4293                 if (object_is_known(o_ptr)) p_ptr->dis_to_a += o_ptr->to_a;
4294
4295                 if (o_ptr->curse_flags & TRC_LOW_MELEE)
4296                 {
4297                         int slot = i - INVEN_RARM;
4298                         if (slot < 2)
4299                         {
4300                                 if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
4301                                 {
4302                                         p_ptr->to_h[slot] -= 15;
4303                                         if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_h[slot] -= 15;
4304                                 }
4305                                 else
4306                                 {
4307                                         p_ptr->to_h[slot] -= 5;
4308                                         if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_h[slot] -= 5;
4309                                 }
4310                         }
4311                         else
4312                         {
4313                                 if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
4314                                 {
4315                                         p_ptr->to_h_b -= 15;
4316                                         if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_h_b -= 15;
4317                                 }
4318                                 else
4319                                 {
4320                                         p_ptr->to_h_b -= 5;
4321                                         if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_h_b -= 5;
4322                                 }
4323                         }
4324                 }
4325
4326                 if (o_ptr->curse_flags & TRC_LOW_AC)
4327                 {
4328                         if (o_ptr->curse_flags & TRC_HEAVY_CURSE)
4329                         {
4330                                 p_ptr->to_a -= 30;
4331                                 if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_a -= 30;
4332                         }
4333                         else
4334                         {
4335                                 p_ptr->to_a -= 10;
4336                                 if (o_ptr->ident & IDENT_MENTAL) p_ptr->dis_to_a -= 10;
4337                         }
4338                 }
4339
4340                 /* Hack -- do not apply "weapon" bonuses */
4341                 if (i == INVEN_RARM && buki_motteruka(i)) continue;
4342                 if (i == INVEN_LARM && buki_motteruka(i)) continue;
4343
4344                 /* Hack -- do not apply "bow" bonuses */
4345                 if (i == INVEN_BOW) continue;
4346
4347                 bonus_to_h = o_ptr->to_h;
4348                 bonus_to_d = o_ptr->to_d;
4349
4350                 if (p_ptr->pclass == CLASS_NINJA)
4351                 {
4352                         if (o_ptr->to_h > 0) bonus_to_h = (o_ptr->to_h+1)/2;
4353                         if (o_ptr->to_d > 0) bonus_to_d = (o_ptr->to_d+1)/2;
4354                 }
4355
4356                 /* To Bow and Natural attack */
4357
4358                 /* Apply the bonuses to hit/damage */
4359                 p_ptr->to_h_b += (s16b)bonus_to_h;
4360                 p_ptr->to_h_m += (s16b)bonus_to_h;
4361                 p_ptr->to_d_m += (s16b)bonus_to_d;
4362
4363                 /* Apply the mental bonuses tp hit/damage, if known */
4364                 if (object_is_known(o_ptr)) p_ptr->dis_to_h_b += (s16b)bonus_to_h;
4365
4366                 /* To Melee */
4367                 if ((i == INVEN_LEFT || i == INVEN_RIGHT) && !p_ptr->ryoute)
4368                 {
4369                         /* Apply the bonuses to hit/damage */
4370                         p_ptr->to_h[i-INVEN_RIGHT] += (s16b)bonus_to_h;
4371                         p_ptr->to_d[i-INVEN_RIGHT] += (s16b)bonus_to_d;
4372
4373                         /* Apply the mental bonuses tp hit/damage, if known */
4374                         if (object_is_known(o_ptr))
4375                         {
4376                                 p_ptr->dis_to_h[i-INVEN_RIGHT] += (s16b)bonus_to_h;
4377                                 p_ptr->dis_to_d[i-INVEN_RIGHT] += (s16b)bonus_to_d;
4378                         }
4379                 }
4380                 else if (p_ptr->migite && p_ptr->hidarite)
4381                 {
4382                         /* Apply the bonuses to hit/damage */
4383                         p_ptr->to_h[0] += (bonus_to_h > 0) ? (bonus_to_h+1)/2 : bonus_to_h;
4384                         p_ptr->to_h[1] += (bonus_to_h > 0) ? bonus_to_h/2 : bonus_to_h;
4385                         p_ptr->to_d[0] += (bonus_to_d > 0) ? (bonus_to_d+1)/2 : bonus_to_d;
4386                         p_ptr->to_d[1] += (bonus_to_d > 0) ? bonus_to_d/2 : bonus_to_d;
4387
4388                         /* Apply the mental bonuses tp hit/damage, if known */
4389                         if (object_is_known(o_ptr))
4390                         {
4391                                 p_ptr->dis_to_h[0] += (bonus_to_h > 0) ? (bonus_to_h+1)/2 : bonus_to_h;
4392                                 p_ptr->dis_to_h[1] += (bonus_to_h > 0) ? bonus_to_h/2 : bonus_to_h;
4393                                 p_ptr->dis_to_d[0] += (bonus_to_d > 0) ? (bonus_to_d+1)/2 : bonus_to_d;
4394                                 p_ptr->dis_to_d[1] += (bonus_to_d > 0) ? bonus_to_d/2 : bonus_to_d;
4395                         }
4396                 }
4397                 else
4398                 {
4399                         /* Apply the bonuses to hit/damage */
4400                         p_ptr->to_h[default_hand] += (s16b)bonus_to_h;
4401                         p_ptr->to_d[default_hand] += (s16b)bonus_to_d;
4402
4403                         /* Apply the mental bonuses to hit/damage, if known */
4404                         if (object_is_known(o_ptr))
4405                         {
4406                                 p_ptr->dis_to_h[default_hand] += (s16b)bonus_to_h;
4407                                 p_ptr->dis_to_d[default_hand] += (s16b)bonus_to_d;
4408                         }
4409                 }
4410         }
4411
4412         if (old_mighty_throw != p_ptr->mighty_throw)
4413         {
4414                 /* Redraw average damege display of Shuriken */
4415                 p_ptr->window |= PW_INVEN;
4416         }
4417
4418         if (p_ptr->cursed & TRC_TELEPORT) p_ptr->cursed &= ~(TRC_TELEPORT_SELF);
4419
4420         /* Monks get extra ac for armour _not worn_ */
4421         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER)) && !heavy_armor())
4422         {
4423                 if (!(inventory[INVEN_BODY].k_idx))
4424                 {
4425                         p_ptr->to_a += (p_ptr->lev * 3) / 2;
4426                         p_ptr->dis_to_a += (p_ptr->lev * 3) / 2;
4427                 }
4428                 if (!(inventory[INVEN_OUTER].k_idx) && (p_ptr->lev > 15))
4429                 {
4430                         p_ptr->to_a += ((p_ptr->lev - 13) / 3);
4431                         p_ptr->dis_to_a += ((p_ptr->lev - 13) / 3);
4432                 }
4433                 if (!(inventory[INVEN_LARM].k_idx) && (p_ptr->lev > 10))
4434                 {
4435                         p_ptr->to_a += ((p_ptr->lev - 8) / 3);
4436                         p_ptr->dis_to_a += ((p_ptr->lev - 8) / 3);
4437                 }
4438                 if (!(inventory[INVEN_HEAD].k_idx) && (p_ptr->lev > 4))
4439                 {
4440                         p_ptr->to_a += (p_ptr->lev - 2) / 3;
4441                         p_ptr->dis_to_a += (p_ptr->lev -2) / 3;
4442                 }
4443                 if (!(inventory[INVEN_HANDS].k_idx))
4444                 {
4445                         p_ptr->to_a += (p_ptr->lev / 2);
4446                         p_ptr->dis_to_a += (p_ptr->lev / 2);
4447                 }
4448                 if (!(inventory[INVEN_FEET].k_idx))
4449                 {
4450                         p_ptr->to_a += (p_ptr->lev / 3);
4451                         p_ptr->dis_to_a += (p_ptr->lev / 3);
4452                 }
4453                 if (p_ptr->special_defense & KAMAE_BYAKKO)
4454                 {
4455                         p_ptr->stat_add[A_STR] += 2;
4456                         p_ptr->stat_add[A_DEX] += 2;
4457                         p_ptr->stat_add[A_CON] -= 3;
4458                 }
4459                 else if (p_ptr->special_defense & KAMAE_SEIRYU)
4460                 {
4461                 }
4462                 else if (p_ptr->special_defense & KAMAE_GENBU)
4463                 {
4464                         p_ptr->stat_add[A_INT] -= 1;
4465                         p_ptr->stat_add[A_WIS] -= 1;
4466                         p_ptr->stat_add[A_DEX] -= 2;
4467                         p_ptr->stat_add[A_CON] += 3;
4468                 }
4469                 else if (p_ptr->special_defense & KAMAE_SUZAKU)
4470                 {
4471                         p_ptr->stat_add[A_STR] -= 2;
4472                         p_ptr->stat_add[A_INT] += 1;
4473                         p_ptr->stat_add[A_WIS] += 1;
4474                         p_ptr->stat_add[A_DEX] += 2;
4475                         p_ptr->stat_add[A_CON] -= 2;
4476                 }
4477         }
4478
4479         if (p_ptr->special_defense & KATA_KOUKIJIN)
4480         {
4481                 for (i = 0; i < 6; i++)
4482                         p_ptr->stat_add[i] += 5;
4483                 p_ptr->to_a -= 50;
4484                 p_ptr->dis_to_a -= 50;
4485         }
4486
4487         /* Hack -- aura of fire also provides light */
4488         if (p_ptr->sh_fire) p_ptr->lite = TRUE;
4489
4490         /* Golems also get an intrinsic AC bonus */
4491         if (prace_is_(RACE_GOLEM) || prace_is_(RACE_ANDROID))
4492         {
4493                 p_ptr->to_a += 10 + (p_ptr->lev * 2 / 5);
4494                 p_ptr->dis_to_a += 10 + (p_ptr->lev * 2 / 5);
4495         }
4496
4497         /* Hex bonuses */
4498         if (p_ptr->realm1 == REALM_HEX)
4499         {
4500                 if (hex_spelling_any()) p_ptr->skill_stl -= (1 + CASTING_HEX_NUM(p_ptr));
4501                 if (hex_spelling(HEX_DETECT_EVIL)) p_ptr->esp_evil = TRUE;
4502                 if (hex_spelling(HEX_XTRA_MIGHT)) p_ptr->stat_add[A_STR] += 4;
4503                 if (hex_spelling(HEX_BUILDING))
4504                 {
4505                         p_ptr->stat_add[A_STR] += 4;
4506                         p_ptr->stat_add[A_DEX] += 4;
4507                         p_ptr->stat_add[A_CON] += 4;
4508                 }
4509                 if (hex_spelling(HEX_DEMON_AURA))
4510                 {
4511                         p_ptr->sh_fire = TRUE;
4512                         p_ptr->regenerate = TRUE;
4513                 }
4514                 if (hex_spelling(HEX_ICE_ARMOR))
4515                 {
4516                         p_ptr->sh_cold = TRUE; 
4517                         p_ptr->to_a += 30;
4518                         p_ptr->dis_to_a += 30;
4519                 }
4520                 if (hex_spelling(HEX_SHOCK_CLOAK))
4521                 {
4522                         p_ptr->sh_elec = TRUE;
4523                         new_speed += 3;
4524                 }
4525                 for (i = INVEN_RARM; i <= INVEN_FEET; i++)
4526                 {
4527                         int ac = 0;
4528                         o_ptr = &inventory[i];
4529                         if (!o_ptr->k_idx) continue;
4530                         if (!object_is_armour(o_ptr)) continue;
4531                         if (!object_is_cursed(o_ptr)) continue;
4532                         ac += 5;
4533                         if (o_ptr->curse_flags & TRC_HEAVY_CURSE) ac += 7;
4534                         if (o_ptr->curse_flags & TRC_PERMA_CURSE) ac += 13;
4535                         p_ptr->to_a += (s16b)ac;
4536                         p_ptr->dis_to_a += (s16b)ac;
4537                 }
4538         }
4539
4540         /* Calculate stats */
4541         for (i = 0; i < 6; i++)
4542         {
4543                 int top, use, ind;
4544
4545                 /* Extract the new "stat_use" value for the stat */
4546                 top = modify_stat_value(p_ptr->stat_max[i], p_ptr->stat_add[i]);
4547
4548                 /* Notice changes */
4549                 if (p_ptr->stat_top[i] != top)
4550                 {
4551                         /* Save the new value */
4552                         p_ptr->stat_top[i] = (s16b)top;
4553
4554                         /* Redisplay the stats later */
4555                         p_ptr->redraw |= (PR_STATS);
4556
4557                         /* Window stuff */
4558                         p_ptr->window |= (PW_PLAYER);
4559                 }
4560
4561
4562                 /* Extract the new "stat_use" value for the stat */
4563                 use = modify_stat_value(p_ptr->stat_cur[i], p_ptr->stat_add[i]);
4564
4565                 if ((i == A_CHR) && (p_ptr->muta3 & MUT3_ILL_NORM))
4566                 {
4567                         /* 10 to 18/90 charisma, guaranteed, based on level */
4568                         if (use < 8 + 2 * p_ptr->lev)
4569                         {
4570                                 use = 8 + 2 * p_ptr->lev;
4571                         }
4572                 }
4573
4574                 /* Notice changes */
4575                 if (p_ptr->stat_use[i] != use)
4576                 {
4577                         /* Save the new value */
4578                         p_ptr->stat_use[i] = (s16b)use;
4579
4580                         /* Redisplay the stats later */
4581                         p_ptr->redraw |= (PR_STATS);
4582
4583                         /* Window stuff */
4584                         p_ptr->window |= (PW_PLAYER);
4585                 }
4586
4587
4588                 /* Values: 3, 4, ..., 17 */
4589                 if (use <= 18) ind = (use - 3);
4590
4591                 /* Ranges: 18/00-18/09, ..., 18/210-18/219 */
4592                 else if (use <= 18+219) ind = (15 + (use - 18) / 10);
4593
4594                 /* Range: 18/220+ */
4595                 else ind = (37);
4596
4597                 /* Notice changes */
4598                 if (p_ptr->stat_ind[i] != ind)
4599                 {
4600                         /* Save the new index */
4601                         p_ptr->stat_ind[i] = (s16b)ind;
4602
4603                         /* Change in CON affects Hitpoints */
4604                         if (i == A_CON)
4605                         {
4606                                 p_ptr->update |= (PU_HP);
4607                         }
4608
4609                         /* Change in INT may affect Mana/Spells */
4610                         else if (i == A_INT)
4611                         {
4612                                 if (mp_ptr->spell_stat == A_INT)
4613                                 {
4614                                         p_ptr->update |= (PU_MANA | PU_SPELLS);
4615                                 }
4616                         }
4617
4618                         /* Change in WIS may affect Mana/Spells */
4619                         else if (i == A_WIS)
4620                         {
4621                                 if (mp_ptr->spell_stat == A_WIS)
4622                                 {
4623                                         p_ptr->update |= (PU_MANA | PU_SPELLS);
4624                                 }
4625                         }
4626
4627                         /* Change in WIS may affect Mana/Spells */
4628                         else if (i == A_CHR)
4629                         {
4630                                 if (mp_ptr->spell_stat == A_CHR)
4631                                 {
4632                                         p_ptr->update |= (PU_MANA | PU_SPELLS);
4633                                 }
4634                         }
4635
4636                         /* Window stuff */
4637                         p_ptr->window |= (PW_PLAYER);
4638                 }
4639         }
4640
4641
4642         /* Apply temporary "stun" */
4643         if (p_ptr->stun > 50)
4644         {
4645                 p_ptr->to_h[0] -= 20;
4646                 p_ptr->to_h[1] -= 20;
4647                 p_ptr->to_h_b  -= 20;
4648                 p_ptr->to_h_m  -= 20;
4649                 p_ptr->dis_to_h[0] -= 20;
4650                 p_ptr->dis_to_h[1] -= 20;
4651                 p_ptr->dis_to_h_b  -= 20;
4652                 p_ptr->to_d[0] -= 20;
4653                 p_ptr->to_d[1] -= 20;
4654                 p_ptr->to_d_m -= 20;
4655                 p_ptr->dis_to_d[0] -= 20;
4656                 p_ptr->dis_to_d[1] -= 20;
4657         }
4658         else if (p_ptr->stun)
4659         {
4660                 p_ptr->to_h[0] -= 5;
4661                 p_ptr->to_h[1] -= 5;
4662                 p_ptr->to_h_b -= 5;
4663                 p_ptr->to_h_m -= 5;
4664                 p_ptr->dis_to_h[0] -= 5;
4665                 p_ptr->dis_to_h[1] -= 5;
4666                 p_ptr->dis_to_h_b -= 5;
4667                 p_ptr->to_d[0] -= 5;
4668                 p_ptr->to_d[1] -= 5;
4669                 p_ptr->to_d_m -= 5;
4670                 p_ptr->dis_to_d[0] -= 5;
4671                 p_ptr->dis_to_d[1] -= 5;
4672         }
4673
4674         /* Wraith form */
4675         if (p_ptr->wraith_form)
4676         {
4677                 p_ptr->reflect = TRUE;
4678                 p_ptr->pass_wall = TRUE;
4679         }
4680
4681         if (p_ptr->kabenuke)
4682         {
4683                 p_ptr->pass_wall = TRUE;
4684         }
4685
4686         /* Temporary blessing */
4687         if (IS_BLESSED())
4688         {
4689                 p_ptr->to_a += 5;
4690                 p_ptr->dis_to_a += 5;
4691                 p_ptr->to_h[0] += 10;
4692                 p_ptr->to_h[1] += 10;
4693                 p_ptr->to_h_b  += 10;
4694                 p_ptr->to_h_m  += 10;
4695                 p_ptr->dis_to_h[0] += 10;
4696                 p_ptr->dis_to_h[1] += 10;
4697                 p_ptr->dis_to_h_b += 10;
4698         }
4699
4700         if (p_ptr->magicdef)
4701         {
4702                 p_ptr->resist_blind = TRUE;
4703                 p_ptr->resist_conf = TRUE;
4704                 p_ptr->reflect = TRUE;
4705                 p_ptr->free_act = TRUE;
4706                 p_ptr->levitation = TRUE;
4707         }
4708
4709         /* Temporary "Hero" */
4710         if (IS_HERO())
4711         {
4712                 p_ptr->to_h[0] += 12;
4713                 p_ptr->to_h[1] += 12;
4714                 p_ptr->to_h_b  += 12;
4715                 p_ptr->to_h_m  += 12;
4716                 p_ptr->dis_to_h[0] += 12;
4717                 p_ptr->dis_to_h[1] += 12;
4718                 p_ptr->dis_to_h_b  += 12;
4719         }
4720
4721         /* Temporary "Beserk" */
4722         if (p_ptr->shero)
4723         {
4724                 p_ptr->to_h[0] += 12;
4725                 p_ptr->to_h[1] += 12;
4726                 p_ptr->to_h_b  -= 12;
4727                 p_ptr->to_h_m  += 12;
4728                 p_ptr->to_d[0] += 3+(p_ptr->lev/5);
4729                 p_ptr->to_d[1] += 3+(p_ptr->lev/5);
4730                 p_ptr->to_d_m  += 3+(p_ptr->lev/5);
4731                 p_ptr->dis_to_h[0] += 12;
4732                 p_ptr->dis_to_h[1] += 12;
4733                 p_ptr->dis_to_h_b  -= 12;
4734                 p_ptr->dis_to_d[0] += 3+(p_ptr->lev/5);
4735                 p_ptr->dis_to_d[1] += 3+(p_ptr->lev/5);
4736                 p_ptr->to_a -= 10;
4737                 p_ptr->dis_to_a -= 10;
4738                 p_ptr->skill_stl -= 7;
4739                 p_ptr->skill_dev -= 20;
4740                 p_ptr->skill_sav -= 30;
4741                 p_ptr->skill_srh -= 15;
4742                 p_ptr->skill_fos -= 15;
4743                 p_ptr->skill_tht -= 20;
4744                 p_ptr->skill_dig += 30;
4745         }
4746
4747         /* Temporary "fast" */
4748         if (IS_FAST())
4749         {
4750                 new_speed += 10;
4751         }
4752
4753         /* Temporary "slow" */
4754         if (p_ptr->slow)
4755         {
4756                 new_speed -= 10;
4757         }
4758
4759         /* Temporary "telepathy" */
4760         if (IS_TIM_ESP())
4761         {
4762                 p_ptr->telepathy = TRUE;
4763         }
4764
4765         if (p_ptr->ele_immune)
4766         {
4767                 if (p_ptr->special_defense & DEFENSE_ACID)
4768                         p_ptr->immune_acid = TRUE;
4769                 else if (p_ptr->special_defense & DEFENSE_ELEC)
4770                         p_ptr->immune_elec = TRUE;
4771                 else if (p_ptr->special_defense & DEFENSE_FIRE)
4772                         p_ptr->immune_fire = TRUE;
4773                 else if (p_ptr->special_defense & DEFENSE_COLD)
4774                         p_ptr->immune_cold = TRUE;
4775         }
4776
4777         /* Temporary see invisible */
4778         if (p_ptr->tim_invis)
4779         {
4780                 p_ptr->see_inv = TRUE;
4781         }
4782
4783         /* Temporary infravision boost */
4784         if (p_ptr->tim_infra)
4785         {
4786                 p_ptr->see_infra+=3;
4787         }
4788
4789         /* Temporary regeneration boost */
4790         if (p_ptr->tim_regen)
4791         {
4792                 p_ptr->regenerate = TRUE;
4793         }
4794
4795         /* Temporary levitation */
4796         if (p_ptr->tim_levitation)
4797         {
4798                 p_ptr->levitation = TRUE;
4799         }
4800
4801         /* Temporary reflection */
4802         if (p_ptr->tim_reflect)
4803         {
4804                 p_ptr->reflect = TRUE;
4805         }
4806
4807         /* Hack -- Hero/Shero -> Res fear */
4808         if (IS_HERO() || p_ptr->shero)
4809         {
4810                 p_ptr->resist_fear = TRUE;
4811         }
4812
4813
4814         /* Hack -- Telepathy Change */
4815         if (p_ptr->telepathy != old_telepathy)
4816         {
4817                 p_ptr->update |= (PU_MONSTERS);
4818         }
4819
4820         if ((p_ptr->esp_animal != old_esp_animal) ||
4821             (p_ptr->esp_undead != old_esp_undead) ||
4822             (p_ptr->esp_demon != old_esp_demon) ||
4823             (p_ptr->esp_orc != old_esp_orc) ||
4824             (p_ptr->esp_troll != old_esp_troll) ||
4825             (p_ptr->esp_giant != old_esp_giant) ||
4826             (p_ptr->esp_dragon != old_esp_dragon) ||
4827             (p_ptr->esp_human != old_esp_human) ||
4828             (p_ptr->esp_evil != old_esp_evil) ||
4829             (p_ptr->esp_good != old_esp_good) ||
4830             (p_ptr->esp_nonliving != old_esp_nonliving) ||
4831             (p_ptr->esp_unique != old_esp_unique))
4832         {
4833                 p_ptr->update |= (PU_MONSTERS);
4834         }
4835
4836         /* Hack -- See Invis Change */
4837         if (p_ptr->see_inv != old_see_inv)
4838         {
4839                 p_ptr->update |= (PU_MONSTERS);
4840         }
4841
4842         /* Bloating slows the player down (a little) */
4843         if (p_ptr->food >= PY_FOOD_MAX) new_speed -= 10;
4844
4845         if (p_ptr->special_defense & KAMAE_SUZAKU) new_speed += 10;
4846
4847         if ((p_ptr->migite && (empty_hands_status & EMPTY_HAND_RARM)) ||
4848             (p_ptr->hidarite && (empty_hands_status & EMPTY_HAND_LARM)))
4849         {
4850                 p_ptr->to_h[default_hand] += (p_ptr->skill_exp[GINOU_SUDE] - WEAPON_EXP_BEGINNER) / 200;
4851                 p_ptr->dis_to_h[default_hand] += (p_ptr->skill_exp[GINOU_SUDE] - WEAPON_EXP_BEGINNER) / 200;
4852         }
4853
4854         if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
4855         {
4856                 int penalty1, penalty2;
4857                 penalty1 = ((100 - p_ptr->skill_exp[GINOU_NITOURYU] / 160) - (130 - inventory[INVEN_RARM].weight) / 8);
4858                 penalty2 = ((100 - p_ptr->skill_exp[GINOU_NITOURYU] / 160) - (130 - inventory[INVEN_LARM].weight) / 8);
4859                 if ((inventory[INVEN_RARM].name1 == ART_QUICKTHORN) && (inventory[INVEN_LARM].name1 == ART_TINYTHORN))
4860                 {
4861                         penalty1 = penalty1 / 2 - 5;
4862                         penalty2 = penalty2 / 2 - 5;
4863                         new_speed += 7;
4864                         p_ptr->to_a += 10;
4865                         p_ptr->dis_to_a += 10;
4866                 }
4867                 if (easy_2weapon)
4868                 {
4869                         if (penalty1 > 0) penalty1 /= 2;
4870                         if (penalty2 > 0) penalty2 /= 2;
4871                 }
4872                 else if ((inventory[INVEN_LARM].tval == TV_SWORD) && ((inventory[INVEN_LARM].sval == SV_MAIN_GAUCHE) || (inventory[INVEN_LARM].sval == SV_WAKIZASHI)))
4873                 {
4874                         penalty1 = MAX(0, penalty1 - 10);
4875                         penalty2 = MAX(0, penalty2 - 10);
4876                 }
4877                 if ((inventory[INVEN_RARM].name1 == ART_MUSASI_KATANA) && (inventory[INVEN_LARM].name1 == ART_MUSASI_WAKIZASI))
4878                 {
4879                         penalty1 = MIN(0, penalty1);
4880                         penalty2 = MIN(0, penalty2);
4881                         p_ptr->to_a += 10;
4882                         p_ptr->dis_to_a += 10;
4883                 }
4884                 else
4885                 {
4886                         if ((inventory[INVEN_RARM].name1 == ART_MUSASI_KATANA) && (penalty1 > 0))
4887                                 penalty1 /= 2;
4888                         if ((inventory[INVEN_LARM].name1 == ART_MUSASI_WAKIZASI) && (penalty2 > 0))
4889                                 penalty2 /= 2;
4890                 }
4891                 if (inventory[INVEN_RARM].tval == TV_POLEARM) penalty1 += 10;
4892                 if (inventory[INVEN_LARM].tval == TV_POLEARM) penalty2 += 10;
4893                 p_ptr->to_h[0] -= (s16b)penalty1;
4894                 p_ptr->to_h[1] -= (s16b)penalty2;
4895                 p_ptr->dis_to_h[0] -= (s16b)penalty1;
4896                 p_ptr->dis_to_h[1] -= (s16b)penalty2;
4897         }
4898
4899         /* Extract the current weight (in tenth pounds) */
4900         j = p_ptr->total_weight;
4901
4902         if (!p_ptr->riding)
4903         {
4904                 /* Extract the "weight limit" (in tenth pounds) */
4905                 i = (int)weight_limit();
4906         }
4907         else
4908         {
4909                 monster_type *riding_m_ptr = &m_list[p_ptr->riding];
4910                 monster_race *riding_r_ptr = &r_info[riding_m_ptr->r_idx];
4911                 int speed = riding_m_ptr->mspeed;
4912
4913                 if (riding_m_ptr->mspeed > 110)
4914                 {
4915                         new_speed = 110 + (s16b)((speed - 110) * (p_ptr->skill_exp[GINOU_RIDING] * 3 + p_ptr->lev * 160L - 10000L) / (22000L));
4916                         if (new_speed < 110) new_speed = 110;
4917                 }
4918                 else
4919                 {
4920                         new_speed = speed;
4921                 }
4922                 new_speed += (p_ptr->skill_exp[GINOU_RIDING] + p_ptr->lev *160L)/3200;
4923                 if (MON_FAST(riding_m_ptr)) new_speed += 10;
4924                 if (MON_SLOW(riding_m_ptr)) new_speed -= 10;
4925                 riding_levitation = (riding_r_ptr->flags7 & RF7_CAN_FLY) ? TRUE : FALSE;
4926                 if (riding_r_ptr->flags7 & (RF7_CAN_SWIM | RF7_AQUATIC)) p_ptr->can_swim = TRUE;
4927
4928                 if (!(riding_r_ptr->flags2 & RF2_PASS_WALL)) p_ptr->pass_wall = FALSE;
4929                 if (riding_r_ptr->flags2 & RF2_KILL_WALL) p_ptr->kill_wall = TRUE;
4930
4931                 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;
4932
4933                 /* Extract the "weight limit" */
4934                 i = 1500 + riding_r_ptr->level * 25;
4935         }
4936
4937         /* XXX XXX XXX Apply "encumbrance" from weight */
4938         if (j > i) new_speed -= ((j - i) / (i / 5));
4939
4940         /* Searching slows the player down */
4941         if (p_ptr->action == ACTION_SEARCH) new_speed -= 10;
4942
4943         /* Actual Modifier Bonuses (Un-inflate stat bonuses) */
4944         p_ptr->to_a += ((int)(adj_dex_ta[p_ptr->stat_ind[A_DEX]]) - 128);
4945         p_ptr->to_d[0] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4946         p_ptr->to_d[1] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4947         p_ptr->to_d_m  += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4948         p_ptr->to_h[0] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4949         p_ptr->to_h[1] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4950         p_ptr->to_h_b  += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4951         p_ptr->to_h_m  += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4952         p_ptr->to_h[0] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4953         p_ptr->to_h[1] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4954         p_ptr->to_h_b  += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4955         p_ptr->to_h_m  += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4956
4957         /* Displayed Modifier Bonuses (Un-inflate stat bonuses) */
4958         p_ptr->dis_to_a += ((int)(adj_dex_ta[p_ptr->stat_ind[A_DEX]]) - 128);
4959         p_ptr->dis_to_d[0] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4960         p_ptr->dis_to_d[1] += ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128);
4961         p_ptr->dis_to_h[0] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4962         p_ptr->dis_to_h[1] += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4963         p_ptr->dis_to_h_b  += ((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
4964         p_ptr->dis_to_h[0] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4965         p_ptr->dis_to_h[1] += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4966         p_ptr->dis_to_h_b  += ((int)(adj_str_th[p_ptr->stat_ind[A_STR]]) - 128);
4967
4968
4969         /* Obtain the "hold" value */
4970         hold = adj_str_hold[p_ptr->stat_ind[A_STR]];
4971
4972
4973         /* Examine the "current bow" */
4974         o_ptr = &inventory[INVEN_BOW];
4975
4976         /* It is hard to carholdry a heavy bow */
4977         p_ptr->heavy_shoot = is_heavy_shoot(o_ptr);
4978         if (p_ptr->heavy_shoot)
4979         {
4980                 /* Hard to wield a heavy bow */
4981                 p_ptr->to_h_b  += 2 * (hold - o_ptr->weight / 10);
4982                 p_ptr->dis_to_h_b  += 2 * (hold - o_ptr->weight / 10);
4983         }
4984
4985         /* Compute "extra shots" if needed */
4986         if (o_ptr->k_idx)
4987         {
4988                 p_ptr->tval_ammo = (byte_hack)bow_tval_ammo(o_ptr);
4989
4990                 /* Apply special flags */
4991                 if (o_ptr->k_idx && !p_ptr->heavy_shoot)
4992                 {
4993                         /* Extra shots */
4994                         p_ptr->num_fire = calc_num_fire(o_ptr);
4995
4996                         /* Snipers love Cross bows */
4997                         if ((p_ptr->pclass == CLASS_SNIPER) &&
4998                                 (p_ptr->tval_ammo == TV_BOLT))
4999                         {
5000                                 p_ptr->to_h_b += (10 + (p_ptr->lev / 5));
5001                                 p_ptr->dis_to_h_b += (10 + (p_ptr->lev / 5));
5002                         }
5003                 }
5004         }
5005
5006         if (p_ptr->ryoute) hold *= 2;
5007
5008         for(i = 0 ; i < 2 ; i++)
5009         {
5010                 /* Examine the "main weapon" */
5011                 o_ptr = &inventory[INVEN_RARM+i];
5012
5013                 object_flags(o_ptr, flgs);
5014
5015                 /* Assume not heavy */
5016                 p_ptr->heavy_wield[i] = FALSE;
5017                 p_ptr->icky_wield[i] = FALSE;
5018                 p_ptr->riding_wield[i] = FALSE;
5019
5020                 if (!buki_motteruka(INVEN_RARM+i)) {p_ptr->num_blow[i]=1;continue;}
5021                 /* It is hard to hold a heavy weapon */
5022                 if (hold < o_ptr->weight / 10)
5023                 {
5024                         /* Hard to wield a heavy weapon */
5025                         p_ptr->to_h[i] += 2 * (hold - o_ptr->weight / 10);
5026                         p_ptr->dis_to_h[i] += 2 * (hold - o_ptr->weight / 10);
5027
5028                         /* Heavy weapon */
5029                         p_ptr->heavy_wield[i] = TRUE;
5030                 }
5031                 else if (p_ptr->ryoute && (hold < o_ptr->weight/5)) omoi = TRUE;
5032
5033                 if ((i == 1) && (o_ptr->tval == TV_SWORD) && ((o_ptr->sval == SV_MAIN_GAUCHE) || (o_ptr->sval == SV_WAKIZASHI)))
5034                 {
5035                         p_ptr->to_a += 5;
5036                         p_ptr->dis_to_a += 5;
5037                 }
5038
5039                 /* Normal weapons */
5040                 if (o_ptr->k_idx && !p_ptr->heavy_wield[i])
5041                 {
5042                         int str_index, dex_index;
5043
5044                         int num = 0, wgt = 0, mul = 0, div = 0;
5045
5046                         /* Analyze the class */
5047                         switch (p_ptr->pclass)
5048                         {
5049                                 /* Warrior */
5050                                 case CLASS_WARRIOR:
5051                                         num = 6; wgt = 70; mul = 5; break;
5052
5053                                 /* Berserker */
5054                                 case CLASS_BERSERKER:
5055                                         num = 6; wgt = 70; mul = 7; break;
5056
5057                                 /* Mage */
5058                                 case CLASS_MAGE:
5059                                 case CLASS_HIGH_MAGE:
5060                                 case CLASS_BLUE_MAGE:
5061                                         num = 3; wgt = 100; mul = 2; break;
5062
5063                                 /* Priest, Mindcrafter, Magic-Eater */
5064                                 case CLASS_PRIEST:
5065                                 case CLASS_MAGIC_EATER:
5066                                 case CLASS_MINDCRAFTER:
5067                                         num = 5; wgt = 100; mul = 3; break;
5068
5069                                 /* Rogue */
5070                                 case CLASS_ROGUE:
5071                                         num = 5; wgt = 40; mul = 3; break;
5072
5073                                 /* Ranger */
5074                                 case CLASS_RANGER:
5075                                         num = 5; wgt = 70; mul = 4; break;
5076
5077                                 /* Paladin */
5078                                 case CLASS_PALADIN:
5079                                 case CLASS_SAMURAI:
5080                                         num = 5; wgt = 70; mul = 4; break;
5081
5082                                 /* Weaponsmith */
5083                                 case CLASS_SMITH:
5084                                         num = 5; wgt = 150; mul = 5; break;
5085
5086                                 /* Warrior-Mage */
5087                                 case CLASS_WARRIOR_MAGE:
5088                                 case CLASS_RED_MAGE:
5089                                         num = 5; wgt = 70; mul = 3; break;
5090
5091                                 /* Chaos Warrior */
5092                                 case CLASS_CHAOS_WARRIOR:
5093                                         num = 5; wgt = 70; mul = 4; break;
5094
5095                                 /* Monk */
5096                                 case CLASS_MONK:
5097                                         num = 5; wgt = 60; mul = 3; break;
5098
5099                                 /* Tourist */
5100                                 case CLASS_TOURIST:
5101                                         num = 4; wgt = 100; mul = 3; break;
5102
5103                                 /* Imitator */
5104                                 case CLASS_IMITATOR:
5105                                         num = 5; wgt = 70; mul = 4; break;
5106
5107                                 /* Beastmaster */
5108                                 case CLASS_BEASTMASTER:
5109                                         num = 5; wgt = 70; mul = 3; break;
5110
5111                                 /* Cavalry */
5112                                 case CLASS_CAVALRY:
5113                                         if ((p_ptr->riding) && (have_flag(flgs, TR_RIDING))) {num = 5; wgt = 70; mul = 4;}
5114                                         else {num = 5; wgt = 100; mul = 3;}
5115                                         break;
5116
5117                                 /* Sorcerer */
5118                                 case CLASS_SORCERER:
5119                                         num = 1; wgt = 1; mul = 1; break;
5120
5121                                 /* Archer, Bard, Sniper */
5122                                 case CLASS_ARCHER:
5123                                 case CLASS_BARD:
5124                                 case CLASS_SNIPER:
5125                                         num = 4; wgt = 70; mul = 2; break;
5126
5127                                 /* ForceTrainer */
5128                                 case CLASS_FORCETRAINER:
5129                                         num = 4; wgt = 60; mul = 2; break;
5130
5131                                 /* Mirror Master */
5132                                 case CLASS_MIRROR_MASTER:
5133                                         num = 3; wgt = 100; mul = 3; break;
5134
5135                                 /* Ninja */
5136                                 case CLASS_NINJA:
5137                                         num = 4; wgt = 20; mul = 1; break;
5138                         }
5139
5140                         /* Hex - extra mights gives +1 bonus to max blows */
5141                         if (hex_spelling(HEX_XTRA_MIGHT) || hex_spelling(HEX_BUILDING)) { num++; wgt /= 2; mul += 2; }
5142
5143                         /* Enforce a minimum "weight" (tenth pounds) */
5144                         div = ((o_ptr->weight < wgt) ? wgt : o_ptr->weight);
5145
5146                         /* Access the strength vs weight */
5147                         str_index = (adj_str_blow[p_ptr->stat_ind[A_STR]] * mul / div);
5148
5149                         if (p_ptr->ryoute && !omoi) str_index++;
5150                         if (p_ptr->pclass == CLASS_NINJA) str_index = MAX(0, str_index-1);
5151
5152                         /* Maximal value */
5153                         if (str_index > 11) str_index = 11;
5154
5155                         /* Index by dexterity */
5156                         dex_index = (adj_dex_blow[p_ptr->stat_ind[A_DEX]]);
5157
5158                         /* Maximal value */
5159                         if (dex_index > 11) dex_index = 11;
5160
5161                         /* Use the blows table */
5162                         p_ptr->num_blow[i] = blows_table[str_index][dex_index];
5163
5164                         /* Maximal value */
5165                         if (p_ptr->num_blow[i] > num) p_ptr->num_blow[i] = (s16b)num;
5166
5167                         /* Add in the "bonus blows" */
5168                         p_ptr->num_blow[i] += (s16b)extra_blows[i];
5169
5170
5171                         if (p_ptr->pclass == CLASS_WARRIOR) p_ptr->num_blow[i] += (p_ptr->lev / 40);
5172                         else if (p_ptr->pclass == CLASS_BERSERKER)
5173                         {
5174                                 p_ptr->num_blow[i] += (p_ptr->lev / 23);
5175                         }
5176                         else if ((p_ptr->pclass == CLASS_ROGUE) && (o_ptr->weight < 50) && (p_ptr->stat_ind[A_DEX] >= 30)) p_ptr->num_blow[i] ++;
5177
5178                         if (p_ptr->special_defense & KATA_FUUJIN) p_ptr->num_blow[i] -= 1;
5179
5180                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) p_ptr->num_blow[i] = 1;
5181
5182
5183                         /* Require at least one blow */
5184                         if (p_ptr->num_blow[i] < 1) p_ptr->num_blow[i] = 1;
5185
5186                         /* Boost digging skill by weapon weight */
5187                         p_ptr->skill_dig += (o_ptr->weight / 10);
5188                 }
5189
5190                 /* Assume okay */
5191                 /* Priest weapon penalty for non-blessed edged weapons */
5192                 if ((p_ptr->pclass == CLASS_PRIEST) && (!(have_flag(flgs, TR_BLESSED))) &&
5193                     ((o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM)))
5194                 {
5195                         /* Reduce the real bonuses */
5196                         p_ptr->to_h[i] -= 2;
5197                         p_ptr->to_d[i] -= 2;
5198
5199                         /* Reduce the mental bonuses */
5200                         p_ptr->dis_to_h[i] -= 2;
5201                         p_ptr->dis_to_d[i] -= 2;
5202
5203                         /* Icky weapon */
5204                         p_ptr->icky_wield[i] = TRUE;
5205                 }
5206                 else if (p_ptr->pclass == CLASS_BERSERKER)
5207                 {
5208                         p_ptr->to_h[i] += p_ptr->lev/5;
5209                         p_ptr->to_d[i] += p_ptr->lev/6;
5210                         p_ptr->dis_to_h[i] += p_ptr->lev/5;
5211                         p_ptr->dis_to_d[i] += p_ptr->lev/6;
5212                         if (((i == 0) && !p_ptr->hidarite) || p_ptr->ryoute)
5213                         {
5214                                 p_ptr->to_h[i] += p_ptr->lev/5;
5215                                 p_ptr->to_d[i] += p_ptr->lev/6;
5216                                 p_ptr->dis_to_h[i] += p_ptr->lev/5;
5217                                 p_ptr->dis_to_d[i] += p_ptr->lev/6;
5218                         }
5219                 }
5220                 else if (p_ptr->pclass == CLASS_SORCERER)
5221                 {
5222                         if (!((o_ptr->tval == TV_HAFTED) && ((o_ptr->sval == SV_WIZSTAFF) || (o_ptr->sval == SV_NAMAKE_HAMMER))))
5223                         {
5224                                 /* Reduce the real bonuses */
5225                                 p_ptr->to_h[i] -= 200;
5226                                 p_ptr->to_d[i] -= 200;
5227
5228                                 /* Reduce the mental bonuses */
5229                                 p_ptr->dis_to_h[i] -= 200;
5230                                 p_ptr->dis_to_d[i] -= 200;
5231
5232                                 /* Icky weapon */
5233                                 p_ptr->icky_wield[i] = TRUE;
5234                         }
5235                         else
5236                         {
5237                                 /* Reduce the real bonuses */
5238                                 p_ptr->to_h[i] -= 30;
5239                                 p_ptr->to_d[i] -= 10;
5240
5241                                 /* Reduce the mental bonuses */
5242                                 p_ptr->dis_to_h[i] -= 30;
5243                                 p_ptr->dis_to_d[i] -= 10;
5244                         }
5245                 }
5246                 /* Hex bonuses */
5247                 if (p_ptr->realm1 == REALM_HEX)
5248                 {
5249                         if (object_is_cursed(o_ptr))
5250                         {
5251                                 if (o_ptr->curse_flags & (TRC_CURSED)) { p_ptr->to_h[i] += 5; p_ptr->dis_to_h[i] += 5; }
5252                                 if (o_ptr->curse_flags & (TRC_HEAVY_CURSE)) { p_ptr->to_h[i] += 7; p_ptr->dis_to_h[i] += 7; }
5253                                 if (o_ptr->curse_flags & (TRC_PERMA_CURSE)) { p_ptr->to_h[i] += 13; p_ptr->dis_to_h[i] += 13; }
5254                                 if (o_ptr->curse_flags & (TRC_TY_CURSE)) { p_ptr->to_h[i] += 5; p_ptr->dis_to_h[i] += 5; }
5255                                 if (hex_spelling(HEX_RUNESWORD))
5256                                 {
5257                                         if (o_ptr->curse_flags & (TRC_CURSED)) { p_ptr->to_d[i] += 5; p_ptr->dis_to_d[i] += 5; }
5258                                         if (o_ptr->curse_flags & (TRC_HEAVY_CURSE)) { p_ptr->to_d[i] += 7; p_ptr->dis_to_d[i] += 7; }
5259                                         if (o_ptr->curse_flags & (TRC_PERMA_CURSE)) { p_ptr->to_d[i] += 13; p_ptr->dis_to_d[i] += 13; }
5260                                 }
5261                         }
5262                 }
5263                 if (p_ptr->riding)
5264                 {
5265                         if ((o_ptr->tval == TV_POLEARM) && ((o_ptr->sval == SV_LANCE) || (o_ptr->sval == SV_HEAVY_LANCE)))
5266                         {
5267                                 p_ptr->to_h[i] +=15;
5268                                 p_ptr->dis_to_h[i] +=15;
5269                                 p_ptr->to_dd[i] += 2;
5270                         }
5271                         else if (!(have_flag(flgs, TR_RIDING)))
5272                         {
5273                                 int penalty;
5274                                 if ((p_ptr->pclass == CLASS_BEASTMASTER) || (p_ptr->pclass == CLASS_CAVALRY))
5275                                 {
5276                                         penalty = 5;
5277                                 }
5278                                 else
5279                                 {
5280                                         penalty = r_info[m_list[p_ptr->riding].r_idx].level - p_ptr->skill_exp[GINOU_RIDING] / 80;
5281                                         penalty += 30;
5282                                         if (penalty < 30) penalty = 30;
5283                                 }
5284                                 p_ptr->to_h[i] -= (s16b)penalty;
5285                                 p_ptr->dis_to_h[i] -= (s16b)penalty;
5286
5287                                 /* Riding weapon */
5288                                 p_ptr->riding_wield[i] = TRUE;
5289                         }
5290                 }
5291         }
5292
5293         if (p_ptr->riding)
5294         {
5295                 int penalty = 0;
5296
5297                 p_ptr->riding_ryoute = FALSE;
5298
5299                 if (p_ptr->ryoute || (empty_hands(FALSE) == EMPTY_HAND_NONE)) p_ptr->riding_ryoute = TRUE;
5300                 else if (p_ptr->pet_extra_flags & PF_RYOUTE)
5301                 {
5302                         switch (p_ptr->pclass)
5303                         {
5304                         case CLASS_MONK:
5305                         case CLASS_FORCETRAINER:
5306                         case CLASS_BERSERKER:
5307                                 if ((empty_hands(FALSE) != EMPTY_HAND_NONE) && !buki_motteruka(INVEN_RARM) && !buki_motteruka(INVEN_LARM))
5308                                         p_ptr->riding_ryoute = TRUE;
5309                                 break;
5310                         }
5311                 }
5312
5313                 if ((p_ptr->pclass == CLASS_BEASTMASTER) || (p_ptr->pclass == CLASS_CAVALRY))
5314                 {
5315                         if (p_ptr->tval_ammo != TV_ARROW) penalty = 5;
5316                 }
5317                 else
5318                 {
5319                         penalty = r_info[m_list[p_ptr->riding].r_idx].level - p_ptr->skill_exp[GINOU_RIDING] / 80;
5320                         penalty += 30;
5321                         if (penalty < 30) penalty = 30;
5322                 }
5323                 if (p_ptr->tval_ammo == TV_BOLT) penalty *= 2;
5324                 p_ptr->to_h_b -= (s16b)penalty;
5325                 p_ptr->dis_to_h_b -= (s16b)penalty;
5326         }
5327
5328         /* Different calculation for monks with empty hands */
5329         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER) || (p_ptr->pclass == CLASS_BERSERKER)) &&
5330                 (empty_hands_status & EMPTY_HAND_RARM) && !p_ptr->hidarite)
5331         {
5332                 int blow_base = p_ptr->lev + adj_dex_blow[p_ptr->stat_ind[A_DEX]];
5333                 p_ptr->num_blow[0] = 0;
5334
5335                 if (p_ptr->pclass == CLASS_FORCETRAINER)
5336                 {
5337                         if (blow_base > 18) p_ptr->num_blow[0]++;
5338                         if (blow_base > 31) p_ptr->num_blow[0]++;
5339                         if (blow_base > 44) p_ptr->num_blow[0]++;
5340                         if (blow_base > 58) p_ptr->num_blow[0]++;
5341                         if (P_PTR_KI)
5342                         {
5343                                 p_ptr->to_d[0] += P_PTR_KI / 5;
5344                                 p_ptr->dis_to_d[0] += P_PTR_KI / 5;
5345                         }
5346                 }
5347                 else
5348                 {
5349                         if (blow_base > 12) p_ptr->num_blow[0]++;
5350                         if (blow_base > 22) p_ptr->num_blow[0]++;
5351                         if (blow_base > 31) p_ptr->num_blow[0]++;
5352                         if (blow_base > 39) p_ptr->num_blow[0]++;
5353                         if (blow_base > 46) p_ptr->num_blow[0]++;
5354                         if (blow_base > 53) p_ptr->num_blow[0]++;
5355                         if (blow_base > 59) p_ptr->num_blow[0]++;
5356                 }
5357
5358                 if (heavy_armor() && (p_ptr->pclass != CLASS_BERSERKER))
5359                         p_ptr->num_blow[0] /= 2;
5360                 else
5361                 {
5362                         p_ptr->to_h[0] += (p_ptr->lev / 3);
5363                         p_ptr->dis_to_h[0] += (p_ptr->lev / 3);
5364
5365                         p_ptr->to_d[0] += (p_ptr->lev / 6);
5366                         p_ptr->dis_to_d[0] += (p_ptr->lev / 6);
5367                 }
5368
5369                 if (p_ptr->special_defense & KAMAE_BYAKKO)
5370                 {
5371                         p_ptr->to_a -= 40;
5372                         p_ptr->dis_to_a -= 40;
5373                         
5374                 }
5375                 else if (p_ptr->special_defense & KAMAE_SEIRYU)
5376                 {
5377                         p_ptr->to_a -= 50;
5378                         p_ptr->dis_to_a -= 50;
5379                         p_ptr->resist_acid = TRUE;
5380                         p_ptr->resist_fire = TRUE;
5381                         p_ptr->resist_elec = TRUE;
5382                         p_ptr->resist_cold = TRUE;
5383                         p_ptr->resist_pois = TRUE;
5384                         p_ptr->sh_fire = TRUE;
5385                         p_ptr->sh_elec = TRUE;
5386                         p_ptr->sh_cold = TRUE;
5387                         p_ptr->levitation = TRUE;
5388                 }
5389                 else if (p_ptr->special_defense & KAMAE_GENBU)
5390                 {
5391                         p_ptr->to_a += (p_ptr->lev*p_ptr->lev)/50;
5392                         p_ptr->dis_to_a += (p_ptr->lev*p_ptr->lev)/50;
5393                         p_ptr->reflect = TRUE;
5394                         p_ptr->num_blow[0] -= 2;
5395                         if ((p_ptr->pclass == CLASS_MONK) && (p_ptr->lev > 42)) p_ptr->num_blow[0]--;
5396                         if (p_ptr->num_blow[0] < 0) p_ptr->num_blow[0] = 0;
5397                 }
5398                 else if (p_ptr->special_defense & KAMAE_SUZAKU)
5399                 {
5400                         p_ptr->to_h[0] -= (p_ptr->lev / 3);
5401                         p_ptr->to_d[0] -= (p_ptr->lev / 6);
5402
5403                         p_ptr->dis_to_h[0] -= (p_ptr->lev / 3);
5404                         p_ptr->dis_to_d[0] -= (p_ptr->lev / 6);
5405                         p_ptr->num_blow[0] /= 2;
5406                         p_ptr->levitation = TRUE;
5407                 }
5408
5409                 p_ptr->num_blow[0] += 1+extra_blows[0];
5410         }
5411
5412         if (p_ptr->riding) p_ptr->levitation = riding_levitation;
5413
5414         monk_armour_aux = FALSE;
5415
5416         if (heavy_armor())
5417         {
5418                 monk_armour_aux = TRUE;
5419         }
5420
5421         for (i = 0; i < 2; i++)
5422         {
5423                 if (buki_motteruka(INVEN_RARM+i))
5424                 {
5425                         OBJECT_TYPE_VALUE tval = inventory[INVEN_RARM+i].tval - TV_WEAPON_BEGIN;
5426                         OBJECT_SUBTYPE_VALUE sval = inventory[INVEN_RARM+i].sval;
5427
5428                         p_ptr->to_h[i] += (p_ptr->weapon_exp[tval][sval] - WEAPON_EXP_BEGINNER) / 200;
5429                         p_ptr->dis_to_h[i] += (p_ptr->weapon_exp[tval][sval] - WEAPON_EXP_BEGINNER) / 200;
5430                         if ((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER))
5431                         {
5432                                 if (!s_info[p_ptr->pclass].w_max[tval][sval])
5433                                 {
5434                                         p_ptr->to_h[i] -= 40;
5435                                         p_ptr->dis_to_h[i] -= 40;
5436                                         p_ptr->icky_wield[i] = TRUE;
5437                                 }
5438                         }
5439                         else if (p_ptr->pclass == CLASS_NINJA)
5440                         {
5441                                 if ((s_info[CLASS_NINJA].w_max[tval][sval] <= WEAPON_EXP_BEGINNER) || (inventory[INVEN_LARM-i].tval == TV_SHIELD))
5442                                 {
5443                                         p_ptr->to_h[i] -= 40;
5444                                         p_ptr->dis_to_h[i] -= 40;
5445                                         p_ptr->icky_wield[i] = TRUE;
5446                                         p_ptr->num_blow[i] /= 2;
5447                                         if (p_ptr->num_blow[i] < 1) p_ptr->num_blow[i] = 1;
5448                                 }
5449                         }
5450
5451                         if (inventory[INVEN_RARM + i].name1 == ART_IRON_BALL) p_ptr->align -= 1000;
5452                 }
5453         }
5454
5455         /* Maximum speed is (+99). (internally it's 110 + 99) */
5456         /* Temporary lightspeed forces to be maximum speed */
5457         if ((p_ptr->lightspeed && !p_ptr->riding) || (new_speed > 209))
5458         {
5459                 new_speed = 209;
5460         }
5461
5462         /* Minimum speed is (-99). (internally it's 110 - 99) */
5463         if (new_speed < 11) new_speed = 11;
5464
5465         /* Display the speed (if needed) */
5466         if (p_ptr->pspeed != (byte)new_speed)
5467         {
5468                 p_ptr->pspeed = (byte)new_speed;
5469                 p_ptr->redraw |= (PR_SPEED);
5470         }
5471
5472         if (yoiyami)
5473         {
5474                 if (p_ptr->to_a > (0 - p_ptr->ac))
5475                         p_ptr->to_a = 0 - p_ptr->ac;
5476                 if (p_ptr->dis_to_a > (0 - p_ptr->dis_ac))
5477                         p_ptr->dis_to_a = 0 - p_ptr->dis_ac;
5478         }
5479
5480         /* Redraw armor (if needed) */
5481         if ((p_ptr->dis_ac != old_dis_ac) || (p_ptr->dis_to_a != old_dis_to_a))
5482         {
5483                 /* Redraw */
5484                 p_ptr->redraw |= (PR_ARMOR);
5485
5486                 /* Window stuff */
5487                 p_ptr->window |= (PW_PLAYER);
5488         }
5489
5490
5491         if (p_ptr->ryoute && !omoi)
5492         {
5493                 int bonus_to_h=0, bonus_to_d=0;
5494                 bonus_to_d = ((int)(adj_str_td[p_ptr->stat_ind[A_STR]]) - 128)/2;
5495                 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);
5496
5497                 p_ptr->to_h[default_hand] += MAX(bonus_to_h,1);
5498                 p_ptr->dis_to_h[default_hand] += MAX(bonus_to_h,1);
5499                 p_ptr->to_d[default_hand] += MAX(bonus_to_d,1);
5500                 p_ptr->dis_to_d[default_hand] += MAX(bonus_to_d,1);
5501         }
5502
5503         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;
5504
5505         /* Affect Skill -- stealth (bonus one) */
5506         p_ptr->skill_stl += 1;
5507
5508         if (IS_TIM_STEALTH()) p_ptr->skill_stl += 99;
5509
5510         /* Affect Skill -- disarming (DEX and INT) */
5511         p_ptr->skill_dis += adj_dex_dis[p_ptr->stat_ind[A_DEX]];
5512         p_ptr->skill_dis += adj_int_dis[p_ptr->stat_ind[A_INT]];
5513
5514         /* Affect Skill -- magic devices (INT) */
5515         p_ptr->skill_dev += adj_int_dev[p_ptr->stat_ind[A_INT]];
5516
5517         /* Affect Skill -- saving throw (WIS) */
5518         p_ptr->skill_sav += adj_wis_sav[p_ptr->stat_ind[A_WIS]];
5519
5520         /* Affect Skill -- digging (STR) */
5521         p_ptr->skill_dig += adj_str_dig[p_ptr->stat_ind[A_STR]];
5522
5523         /* Affect Skill -- disarming (Level, by Class) */
5524         p_ptr->skill_dis += ((cp_ptr->x_dis * p_ptr->lev / 10) + (ap_ptr->a_dis * p_ptr->lev / 50));
5525
5526         /* Affect Skill -- magic devices (Level, by Class) */
5527         p_ptr->skill_dev += ((cp_ptr->x_dev * p_ptr->lev / 10) + (ap_ptr->a_dev * p_ptr->lev / 50));
5528
5529         /* Affect Skill -- saving throw (Level, by Class) */
5530         p_ptr->skill_sav += ((cp_ptr->x_sav * p_ptr->lev / 10) + (ap_ptr->a_sav * p_ptr->lev / 50));
5531
5532         /* Affect Skill -- stealth (Level, by Class) */
5533         p_ptr->skill_stl += (cp_ptr->x_stl * p_ptr->lev / 10);
5534
5535         /* Affect Skill -- search ability (Level, by Class) */
5536         p_ptr->skill_srh += (cp_ptr->x_srh * p_ptr->lev / 10);
5537
5538         /* Affect Skill -- search frequency (Level, by Class) */
5539         p_ptr->skill_fos += (cp_ptr->x_fos * p_ptr->lev / 10);
5540
5541         /* Affect Skill -- combat (normal) (Level, by Class) */
5542         p_ptr->skill_thn += ((cp_ptr->x_thn * p_ptr->lev / 10) + (ap_ptr->a_thn * p_ptr->lev / 50));
5543
5544         /* Affect Skill -- combat (shooting) (Level, by Class) */
5545         p_ptr->skill_thb += ((cp_ptr->x_thb * p_ptr->lev / 10) + (ap_ptr->a_thb * p_ptr->lev / 50));
5546
5547         /* Affect Skill -- combat (throwing) (Level, by Class) */
5548         p_ptr->skill_tht += ((cp_ptr->x_thb * p_ptr->lev / 10) + (ap_ptr->a_thb * p_ptr->lev / 50));
5549
5550
5551         if ((prace_is_(RACE_S_FAIRY)) && (p_ptr->pseikaku != SEIKAKU_SEXY) && (p_ptr->cursed & TRC_AGGRAVATE))
5552         {
5553                 p_ptr->cursed &= ~(TRC_AGGRAVATE);
5554                 p_ptr->skill_stl = MIN(p_ptr->skill_stl - 3, (p_ptr->skill_stl + 2) / 2);
5555         }
5556
5557         /* Limit Skill -- stealth from 0 to 30 */
5558         if (p_ptr->skill_stl > 30) p_ptr->skill_stl = 30;
5559         if (p_ptr->skill_stl < 0) p_ptr->skill_stl = 0;
5560
5561         /* Limit Skill -- digging from 1 up */
5562         if (p_ptr->skill_dig < 1) p_ptr->skill_dig = 1;
5563
5564         if (p_ptr->anti_magic && (p_ptr->skill_sav < (90 + p_ptr->lev))) p_ptr->skill_sav = 90 + p_ptr->lev;
5565
5566         if (p_ptr->tsubureru) p_ptr->skill_sav = 10;
5567
5568         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;
5569
5570         if (down_saving) p_ptr->skill_sav /= 2;
5571
5572         /* Hack -- Each elemental immunity includes resistance */
5573         if (p_ptr->immune_acid) p_ptr->resist_acid = TRUE;
5574         if (p_ptr->immune_elec) p_ptr->resist_elec = TRUE;
5575         if (p_ptr->immune_fire) p_ptr->resist_fire = TRUE;
5576         if (p_ptr->immune_cold) p_ptr->resist_cold = TRUE;
5577
5578         /* Determine player alignment */
5579         for (i = 0, j = 0; i < 8; i++)
5580         {
5581                 switch (p_ptr->vir_types[i])
5582                 {
5583                 case V_JUSTICE:
5584                         p_ptr->align += p_ptr->virtues[i] * 2;
5585                         break;
5586                 case V_CHANCE:
5587                         /* Do nothing */
5588                         break;
5589                 case V_NATURE:
5590                 case V_HARMONY:
5591                         neutral[j++] = i;
5592                         break;
5593                 case V_UNLIFE:
5594                         p_ptr->align -= p_ptr->virtues[i];
5595                         break;
5596                 default:
5597                         p_ptr->align += p_ptr->virtues[i];
5598                         break;
5599                 }
5600         }
5601
5602         for (i = 0; i < j; i++)
5603         {
5604                 if (p_ptr->align > 0)
5605                 {
5606                         p_ptr->align -= p_ptr->virtues[neutral[i]] / 2;
5607                         if (p_ptr->align < 0) p_ptr->align = 0;
5608                 }
5609                 else if (p_ptr->align < 0)
5610                 {
5611                         p_ptr->align += p_ptr->virtues[neutral[i]] / 2;
5612                         if (p_ptr->align > 0) p_ptr->align = 0;
5613                 }
5614         }
5615
5616         /* Hack -- handle "xtra" mode */
5617         if (character_xtra) return;
5618
5619         /* Take note when "heavy bow" changes */
5620         if (p_ptr->old_heavy_shoot != p_ptr->heavy_shoot)
5621         {
5622                 /* Message */
5623                 if (p_ptr->heavy_shoot)
5624                 {
5625                         msg_print(_("こんな重い弓を装備しているのは大変だ。", "You have trouble wielding such a heavy bow."));
5626                 }
5627                 else if (inventory[INVEN_BOW].k_idx)
5628                 {
5629                         msg_print(_("この弓なら装備していても辛くない。", "You have no trouble wielding your bow."));
5630                 }
5631                 else
5632                 {
5633                         msg_print(_("重い弓を装備からはずして体が楽になった。", "You feel relieved to put down your heavy bow."));
5634                 }
5635
5636                 /* Save it */
5637                 p_ptr->old_heavy_shoot = p_ptr->heavy_shoot;
5638         }
5639
5640         for (i = 0 ; i < 2 ; i++)
5641         {
5642                 /* Take note when "heavy weapon" changes */
5643                 if (p_ptr->old_heavy_wield[i] != p_ptr->heavy_wield[i])
5644                 {
5645                         /* Message */
5646                         if (p_ptr->heavy_wield[i])
5647                         {
5648                                 msg_print(_("こんな重い武器を装備しているのは大変だ。", "You have trouble wielding such a heavy weapon."));
5649                         }
5650                         else if (buki_motteruka(INVEN_RARM+i))
5651                         {
5652                                 msg_print(_("これなら装備していても辛くない。", "You have no trouble wielding your weapon."));
5653                         }
5654                         else if (p_ptr->heavy_wield[1-i])
5655                         {
5656                                 msg_print(_("まだ武器が重い。", "You have still trouble wielding a heavy weapon."));
5657                         }
5658                         else
5659                         {
5660                                 msg_print(_("重い武器を装備からはずして体が楽になった。", "You feel relieved to put down your heavy weapon."));
5661                         }
5662
5663                         /* Save it */
5664                         p_ptr->old_heavy_wield[i] = p_ptr->heavy_wield[i];
5665                 }
5666
5667                 /* Take note when "heavy weapon" changes */
5668                 if (p_ptr->old_riding_wield[i] != p_ptr->riding_wield[i])
5669                 {
5670                         /* Message */
5671                         if (p_ptr->riding_wield[i])
5672                         {
5673                                 msg_print(_("この武器は乗馬中に使うにはむかないようだ。", "This weapon is not suitable for use while riding."));
5674                         }
5675                         else if (!p_ptr->riding)
5676                         {
5677                                 msg_print(_("この武器は徒歩で使いやすい。", "This weapon was not suitable for use while riding."));
5678                         }
5679                         else if (buki_motteruka(INVEN_RARM+i))
5680                         {
5681                                 msg_print(_("これなら乗馬中にぴったりだ。", "This weapon is suitable for use while riding."));
5682                         }
5683                         /* Save it */
5684                         p_ptr->old_riding_wield[i] = p_ptr->riding_wield[i];
5685                 }
5686
5687                 /* Take note when "illegal weapon" changes */
5688                 if (p_ptr->old_icky_wield[i] != p_ptr->icky_wield[i])
5689                 {
5690                         /* Message */
5691                         if (p_ptr->icky_wield[i])
5692                         {
5693                                 msg_print(_("今の装備はどうも自分にふさわしくない気がする。", "You do not feel comfortable with your weapon."));
5694                                 if (is_loading_now)
5695                                 {
5696                                         chg_virtue(V_FAITH, -1);
5697                                 }
5698                         }
5699                         else if (buki_motteruka(INVEN_RARM+i))
5700                         {
5701                                 msg_print(_("今の装備は自分にふさわしい気がする。", "You feel comfortable with your weapon."));
5702                         }
5703                         else
5704                         {
5705                                 msg_print(_("装備をはずしたら随分と気が楽になった。", "You feel more comfortable after removing your weapon."));
5706                         }
5707
5708                         /* Save it */
5709                         p_ptr->old_icky_wield[i] = p_ptr->icky_wield[i];
5710                 }
5711         }
5712
5713         if (p_ptr->riding && (p_ptr->old_riding_ryoute != p_ptr->riding_ryoute))
5714         {
5715                 /* Message */
5716                 if (p_ptr->riding_ryoute)
5717                 {
5718 #ifdef JP
5719                         msg_format("%s馬を操れない。", (empty_hands(FALSE) == EMPTY_HAND_NONE) ? "両手がふさがっていて" : "");
5720 #else
5721                         msg_print("You are using both hand for fighting, and you can't control a riding pet.");
5722 #endif
5723                 }
5724                 else
5725                 {
5726 #ifdef JP
5727                         msg_format("%s馬を操れるようになった。", (empty_hands(FALSE) == EMPTY_HAND_NONE) ? "手が空いて" : "");
5728 #else
5729                         msg_print("You began to control riding pet with one hand.");
5730 #endif
5731                 }
5732
5733                 p_ptr->old_riding_ryoute = p_ptr->riding_ryoute;
5734         }
5735
5736         if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER) || (p_ptr->pclass == CLASS_NINJA)) && (monk_armour_aux != monk_notify_aux))
5737         {
5738                 if (heavy_armor())
5739                 {
5740                         msg_print(_("装備が重くてバランスを取れない。", "The weight of your armor disrupts your balance."));
5741                         if (is_loading_now)
5742                         {
5743                                 chg_virtue(V_HARMONY, -1);
5744                         }
5745                 }
5746                 else
5747                 {
5748                         msg_print(_("バランスがとれるようになった。", "You regain your balance."));
5749                 }
5750                 
5751                 monk_notify_aux = monk_armour_aux;
5752         }
5753
5754         for (i = 0; i < INVEN_PACK; i++)
5755         {
5756 #if 0
5757                 if ((inventory[i].tval == TV_SORCERY_BOOK) && (inventory[i].sval == 2)) have_dd_s = TRUE;
5758                 if ((inventory[i].tval == TV_TRUMP_BOOK) && (inventory[i].sval == 1)) have_dd_t = TRUE;
5759 #endif
5760                 if ((inventory[i].tval == TV_NATURE_BOOK) && (inventory[i].sval == 2)) have_sw = TRUE;
5761                 if ((inventory[i].tval == TV_CRAFT_BOOK) && (inventory[i].sval == 2)) have_kabe = TRUE;
5762         }
5763
5764         for (this_o_idx = cave[p_ptr->y][p_ptr->x].o_idx; this_o_idx; this_o_idx = next_o_idx)
5765         {
5766                 /* Acquire object */
5767                 o_ptr = &o_list[this_o_idx];
5768
5769                 /* Acquire next object */
5770                 next_o_idx = o_ptr->next_o_idx;
5771
5772 #if 0
5773                 if ((o_ptr->tval == TV_SORCERY_BOOK) && (o_ptr->sval == 3)) have_dd_s = TRUE;
5774                 if ((o_ptr->tval == TV_TRUMP_BOOK) && (o_ptr->sval == 1)) have_dd_t = TRUE;
5775 #endif
5776                 if ((o_ptr->tval == TV_NATURE_BOOK) && (o_ptr->sval == 2)) have_sw = TRUE;
5777                 if ((o_ptr->tval == TV_CRAFT_BOOK) && (o_ptr->sval == 2)) have_kabe = TRUE;
5778         }
5779
5780         if (p_ptr->pass_wall && !p_ptr->kill_wall) p_ptr->no_flowed = TRUE;
5781 #if 0
5782         if (have_dd_s && ((p_ptr->realm1 == REALM_SORCERY) || (p_ptr->realm2 == REALM_SORCERY) || (p_ptr->pclass == CLASS_SORCERER)))
5783         {
5784                 const magic_type *s_ptr = &mp_ptr->info[REALM_SORCERY-1][SPELL_DD_S];
5785                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5786         }
5787
5788         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)))
5789         {
5790                 const magic_type *s_ptr = &mp_ptr->info[REALM_TRUMP-1][SPELL_DD_T];
5791                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5792         }
5793 #endif
5794         if (have_sw && ((p_ptr->realm1 == REALM_NATURE) || (p_ptr->realm2 == REALM_NATURE) || (p_ptr->pclass == CLASS_SORCERER)))
5795         {
5796                 const magic_type *s_ptr = &mp_ptr->info[REALM_NATURE-1][SPELL_SW];
5797                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5798         }
5799
5800         if (have_kabe && ((p_ptr->realm1 == REALM_CRAFT) || (p_ptr->realm2 == REALM_CRAFT) || (p_ptr->pclass == CLASS_SORCERER)))
5801         {
5802                 const magic_type *s_ptr = &mp_ptr->info[REALM_CRAFT-1][SPELL_KABE];
5803                 if (p_ptr->lev >= s_ptr->slevel) p_ptr->no_flowed = TRUE;
5804         }
5805 }
5806
5807
5808
5809 /*! 
5810  * @brief p_ptr->notice のフラグに応じた更新をまとめて行う / Handle "p_ptr->notice"
5811  * @return なし
5812  * @details 更新処理の対象はアイテムの自動破壊/アイテムの結合/アイテムの並び替え。
5813  */
5814 void notice_stuff(void)
5815 {
5816         /* Notice stuff */
5817         if (!p_ptr->notice) return;
5818
5819
5820         /* Actually do auto-destroy */
5821         if (p_ptr->notice & (PN_AUTODESTROY))
5822         {
5823                 p_ptr->notice &= ~(PN_AUTODESTROY);
5824                 autopick_delayed_alter();
5825         }
5826
5827         /* Combine the pack */
5828         if (p_ptr->notice & (PN_COMBINE))
5829         {
5830                 p_ptr->notice &= ~(PN_COMBINE);
5831                 combine_pack();
5832         }
5833
5834         /* Reorder the pack */
5835         if (p_ptr->notice & (PN_REORDER))
5836         {
5837                 p_ptr->notice &= ~(PN_REORDER);
5838                 reorder_pack();
5839         }
5840 }
5841
5842
5843 /*! 
5844  * @brief p_ptr->update のフラグに応じた更新をまとめて行う / Handle "p_ptr->update"
5845  * @return なし
5846  * @details 更新処理の対象はプレイヤーの能力修正/光源寿命/HP/MP/魔法の学習状態、他多数の外界の状態判定。
5847  */
5848 void update_stuff(void)
5849 {
5850         /* Update stuff */
5851         if (!p_ptr->update) return;
5852
5853
5854         if (p_ptr->update & (PU_BONUS))
5855         {
5856                 p_ptr->update &= ~(PU_BONUS);
5857                 calc_bonuses();
5858         }
5859
5860         if (p_ptr->update & (PU_TORCH))
5861         {
5862                 p_ptr->update &= ~(PU_TORCH);
5863                 calc_torch();
5864         }
5865
5866         if (p_ptr->update & (PU_HP))
5867         {
5868                 p_ptr->update &= ~(PU_HP);
5869                 calc_hitpoints();
5870         }
5871
5872         if (p_ptr->update & (PU_MANA))
5873         {
5874                 p_ptr->update &= ~(PU_MANA);
5875                 calc_mana();
5876         }
5877
5878         if (p_ptr->update & (PU_SPELLS))
5879         {
5880                 p_ptr->update &= ~(PU_SPELLS);
5881                 calc_spells();
5882         }
5883
5884
5885         /* Character is not ready yet, no screen updates */
5886         if (!character_generated) return;
5887
5888
5889         /* Character is in "icky" mode, no screen updates */
5890         if (character_icky) return;
5891
5892
5893         if (p_ptr->update & (PU_UN_LITE))
5894         {
5895                 p_ptr->update &= ~(PU_UN_LITE);
5896                 forget_lite();
5897         }
5898
5899         if (p_ptr->update & (PU_UN_VIEW))
5900         {
5901                 p_ptr->update &= ~(PU_UN_VIEW);
5902                 forget_view();
5903         }
5904
5905         if (p_ptr->update & (PU_VIEW))
5906         {
5907                 p_ptr->update &= ~(PU_VIEW);
5908                 update_view();
5909         }
5910
5911         if (p_ptr->update & (PU_LITE))
5912         {
5913                 p_ptr->update &= ~(PU_LITE);
5914                 update_lite();
5915         }
5916
5917
5918         if (p_ptr->update & (PU_FLOW))
5919         {
5920                 p_ptr->update &= ~(PU_FLOW);
5921                 update_flow();
5922         }
5923
5924         if (p_ptr->update & (PU_DISTANCE))
5925         {
5926                 p_ptr->update &= ~(PU_DISTANCE);
5927
5928                 /* Still need to call update_monsters(FALSE) after update_mon_lite() */ 
5929                 /* p_ptr->update &= ~(PU_MONSTERS); */
5930
5931                 update_monsters(TRUE);
5932         }
5933
5934         if (p_ptr->update & (PU_MON_LITE))
5935         {
5936                 p_ptr->update &= ~(PU_MON_LITE);
5937                 update_mon_lite();
5938         }
5939
5940         /*
5941          * Mega-Hack -- Delayed visual update
5942          * Only used if update_view(), update_lite() or update_mon_lite() was called
5943          */
5944         if (p_ptr->update & (PU_DELAY_VIS))
5945         {
5946                 p_ptr->update &= ~(PU_DELAY_VIS);
5947                 delayed_visual_update();
5948         }
5949
5950         if (p_ptr->update & (PU_MONSTERS))
5951         {
5952                 p_ptr->update &= ~(PU_MONSTERS);
5953                 update_monsters(FALSE);
5954         }
5955 }
5956
5957
5958 /*! 
5959  * @brief p_ptr->redraw のフラグに応じた更新をまとめて行う / Handle "p_ptr->redraw"
5960  * @return なし
5961  * @details 更新処理の対象はゲーム中の全描画処理
5962  */
5963 void redraw_stuff(void)
5964 {
5965         /* Redraw stuff */
5966         if (!p_ptr->redraw) return;
5967
5968
5969         /* Character is not ready yet, no screen updates */
5970         if (!character_generated) return;
5971
5972
5973         /* Character is in "icky" mode, no screen updates */
5974         if (character_icky) return;
5975
5976
5977
5978         /* Hack -- clear the screen */
5979         if (p_ptr->redraw & (PR_WIPE))
5980         {
5981                 p_ptr->redraw &= ~(PR_WIPE);
5982                 msg_print(NULL);
5983                 Term_clear();
5984         }
5985
5986
5987         if (p_ptr->redraw & (PR_MAP))
5988         {
5989                 p_ptr->redraw &= ~(PR_MAP);
5990                 prt_map();
5991         }
5992
5993
5994         if (p_ptr->redraw & (PR_BASIC))
5995         {
5996                 p_ptr->redraw &= ~(PR_BASIC);
5997                 p_ptr->redraw &= ~(PR_MISC | PR_TITLE | PR_STATS);
5998                 p_ptr->redraw &= ~(PR_LEV | PR_EXP | PR_GOLD);
5999                 p_ptr->redraw &= ~(PR_ARMOR | PR_HP | PR_MANA);
6000                 p_ptr->redraw &= ~(PR_DEPTH | PR_HEALTH | PR_UHEALTH);
6001                 prt_frame_basic();
6002                 prt_time();
6003                 prt_dungeon();
6004         }
6005
6006         if (p_ptr->redraw & (PR_EQUIPPY))
6007         {
6008                 p_ptr->redraw &= ~(PR_EQUIPPY);
6009                 print_equippy(); /* To draw / delete equippy chars */
6010         }
6011
6012         if (p_ptr->redraw & (PR_MISC))
6013         {
6014                 p_ptr->redraw &= ~(PR_MISC);
6015                 prt_field(rp_ptr->title, ROW_RACE, COL_RACE);
6016 /*              prt_field(cp_ptr->title, ROW_CLASS, COL_CLASS); */
6017
6018         }
6019
6020         if (p_ptr->redraw & (PR_TITLE))
6021         {
6022                 p_ptr->redraw &= ~(PR_TITLE);
6023                 prt_title();
6024         }
6025
6026         if (p_ptr->redraw & (PR_LEV))
6027         {
6028                 p_ptr->redraw &= ~(PR_LEV);
6029                 prt_level();
6030         }
6031
6032         if (p_ptr->redraw & (PR_EXP))
6033         {
6034                 p_ptr->redraw &= ~(PR_EXP);
6035                 prt_exp();
6036         }
6037
6038         if (p_ptr->redraw & (PR_STATS))
6039         {
6040                 p_ptr->redraw &= ~(PR_STATS);
6041                 prt_stat(A_STR);
6042                 prt_stat(A_INT);
6043                 prt_stat(A_WIS);
6044                 prt_stat(A_DEX);
6045                 prt_stat(A_CON);
6046                 prt_stat(A_CHR);
6047         }
6048
6049         if (p_ptr->redraw & (PR_STATUS))
6050         {
6051                 p_ptr->redraw &= ~(PR_STATUS);
6052                 prt_status();
6053         }
6054
6055         if (p_ptr->redraw & (PR_ARMOR))
6056         {
6057                 p_ptr->redraw &= ~(PR_ARMOR);
6058                 prt_ac();
6059         }
6060
6061         if (p_ptr->redraw & (PR_HP))
6062         {
6063                 p_ptr->redraw &= ~(PR_HP);
6064                 prt_hp();
6065         }
6066
6067         if (p_ptr->redraw & (PR_MANA))
6068         {
6069                 p_ptr->redraw &= ~(PR_MANA);
6070                 prt_sp();
6071         }
6072
6073         if (p_ptr->redraw & (PR_GOLD))
6074         {
6075                 p_ptr->redraw &= ~(PR_GOLD);
6076                 prt_gold();
6077         }
6078
6079         if (p_ptr->redraw & (PR_DEPTH))
6080         {
6081                 p_ptr->redraw &= ~(PR_DEPTH);
6082                 prt_depth();
6083         }
6084
6085         if (p_ptr->redraw & (PR_HEALTH))
6086         {
6087                 p_ptr->redraw &= ~(PR_HEALTH);
6088                 health_redraw(FALSE);
6089         }
6090
6091         if (p_ptr->redraw & (PR_UHEALTH))
6092         {
6093                 p_ptr->redraw &= ~(PR_UHEALTH);
6094                 health_redraw(TRUE);
6095         }
6096
6097
6098         if (p_ptr->redraw & (PR_EXTRA))
6099         {
6100                 p_ptr->redraw &= ~(PR_EXTRA);
6101                 p_ptr->redraw &= ~(PR_CUT | PR_STUN);
6102                 p_ptr->redraw &= ~(PR_HUNGER);
6103                 p_ptr->redraw &= ~(PR_STATE | PR_SPEED | PR_STUDY | PR_IMITATION | PR_STATUS);
6104                 prt_frame_extra();
6105         }
6106
6107         if (p_ptr->redraw & (PR_CUT))
6108         {
6109                 p_ptr->redraw &= ~(PR_CUT);
6110                 prt_cut();
6111         }
6112
6113         if (p_ptr->redraw & (PR_STUN))
6114         {
6115                 p_ptr->redraw &= ~(PR_STUN);
6116                 prt_stun();
6117         }
6118
6119         if (p_ptr->redraw & (PR_HUNGER))
6120         {
6121                 p_ptr->redraw &= ~(PR_HUNGER);
6122                 prt_hunger();
6123         }
6124
6125         if (p_ptr->redraw & (PR_STATE))
6126         {
6127                 p_ptr->redraw &= ~(PR_STATE);
6128                 prt_state();
6129         }
6130
6131         if (p_ptr->redraw & (PR_SPEED))
6132         {
6133                 p_ptr->redraw &= ~(PR_SPEED);
6134                 prt_speed();
6135         }
6136
6137         if (p_ptr->pclass == CLASS_IMITATOR)
6138         {
6139                 if (p_ptr->redraw & (PR_IMITATION))
6140                 {
6141                         p_ptr->redraw &= ~(PR_IMITATION);
6142                         prt_imitation();
6143                 }
6144         }
6145         else if (p_ptr->redraw & (PR_STUDY))
6146         {
6147                 p_ptr->redraw &= ~(PR_STUDY);
6148                 prt_study();
6149         }
6150 }
6151
6152
6153 /*! 
6154  * @brief p_ptr->window のフラグに応じた更新をまとめて行う / Handle "p_ptr->window"
6155  * @return なし
6156  * @details 更新処理の対象はサブウィンドウ全般
6157  */
6158 void window_stuff(void)
6159 {
6160         int j;
6161
6162         u32b mask = 0L;
6163
6164
6165         /* Nothing to do */
6166         if (!p_ptr->window) return;
6167
6168         /* Scan windows */
6169         for (j = 0; j < 8; j++)
6170         {
6171                 /* Save usable flags */
6172                 if (angband_term[j]) mask |= window_flag[j];
6173         }
6174
6175         /* Apply usable flags */
6176         p_ptr->window &= mask;
6177
6178         /* Nothing to do */
6179         if (!p_ptr->window) return;
6180
6181
6182         /* Display inventory */
6183         if (p_ptr->window & (PW_INVEN))
6184         {
6185                 p_ptr->window &= ~(PW_INVEN);
6186                 fix_inven();
6187         }
6188
6189         /* Display equipment */
6190         if (p_ptr->window & (PW_EQUIP))
6191         {
6192                 p_ptr->window &= ~(PW_EQUIP);
6193                 fix_equip();
6194         }
6195
6196         /* Display spell list */
6197         if (p_ptr->window & (PW_SPELL))
6198         {
6199                 p_ptr->window &= ~(PW_SPELL);
6200                 fix_spell();
6201         }
6202
6203         /* Display player */
6204         if (p_ptr->window & (PW_PLAYER))
6205         {
6206                 p_ptr->window &= ~(PW_PLAYER);
6207                 fix_player();
6208         }
6209         
6210         /* Display monster list */
6211         if (p_ptr->window & (PW_MONSTER_LIST))
6212         {
6213                 p_ptr->window &= ~(PW_MONSTER_LIST);
6214                 fix_monster_list();
6215         }
6216         
6217         /* Display overhead view */
6218         if (p_ptr->window & (PW_MESSAGE))
6219         {
6220                 p_ptr->window &= ~(PW_MESSAGE);
6221                 fix_message();
6222         }
6223
6224         /* Display overhead view */
6225         if (p_ptr->window & (PW_OVERHEAD))
6226         {
6227                 p_ptr->window &= ~(PW_OVERHEAD);
6228                 fix_overhead();
6229         }
6230
6231         /* Display overhead view */
6232         if (p_ptr->window & (PW_DUNGEON))
6233         {
6234                 p_ptr->window &= ~(PW_DUNGEON);
6235                 fix_dungeon();
6236         }
6237
6238         /* Display monster recall */
6239         if (p_ptr->window & (PW_MONSTER))
6240         {
6241                 p_ptr->window &= ~(PW_MONSTER);
6242                 fix_monster();
6243         }
6244
6245         /* Display object recall */
6246         if (p_ptr->window & (PW_OBJECT))
6247         {
6248                 p_ptr->window &= ~(PW_OBJECT);
6249                 fix_object();
6250         }
6251 }
6252
6253
6254 /*!
6255  * @brief 全更新処理をチェックして処理していく
6256  * Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window"
6257  * @return なし
6258  */
6259 void handle_stuff(void)
6260 {
6261         /* Update stuff */
6262         if (p_ptr->update) update_stuff();
6263
6264         /* Redraw stuff */
6265         if (p_ptr->redraw) redraw_stuff();
6266
6267         /* Window stuff */
6268         if (p_ptr->window) window_stuff();
6269 }
6270
6271 /*!
6272  * @brief プレイヤーの現在開いている手の状態を返す
6273  * @param riding_control 乗馬中により片手を必要としている状態ならばTRUEを返す。
6274  * @return 開いている手のビットフラグ
6275  */
6276 s16b empty_hands(bool riding_control)
6277 {
6278         s16b status = EMPTY_HAND_NONE;
6279
6280         if (!inventory[INVEN_RARM].k_idx) status |= EMPTY_HAND_RARM;
6281         if (!inventory[INVEN_LARM].k_idx) status |= EMPTY_HAND_LARM;
6282
6283         if (riding_control && (status != EMPTY_HAND_NONE) && p_ptr->riding && !(p_ptr->pet_extra_flags & PF_RYOUTE))
6284         {
6285                 if (status & EMPTY_HAND_LARM) status &= ~(EMPTY_HAND_LARM);
6286                 else if (status & EMPTY_HAND_RARM) status &= ~(EMPTY_HAND_RARM);
6287         }
6288
6289         return status;
6290 }
6291
6292
6293 /*!
6294  * @brief プレイヤーが防具重量制限のある職業時にペナルティを受ける状態にあるかどうかを返す。
6295  * @return ペナルティが適用されるならばTRUE。
6296  */
6297 bool heavy_armor(void)
6298 {
6299         WEIGHT monk_arm_wgt = 0;
6300
6301         if ((p_ptr->pclass != CLASS_MONK) && (p_ptr->pclass != CLASS_FORCETRAINER) && (p_ptr->pclass != CLASS_NINJA)) return FALSE;
6302
6303         /* Weight the armor */
6304         if(inventory[INVEN_RARM].tval > TV_SWORD) monk_arm_wgt += inventory[INVEN_RARM].weight;
6305         if(inventory[INVEN_LARM].tval > TV_SWORD) monk_arm_wgt += inventory[INVEN_LARM].weight;
6306         monk_arm_wgt += inventory[INVEN_BODY].weight;
6307         monk_arm_wgt += inventory[INVEN_HEAD].weight;
6308         monk_arm_wgt += inventory[INVEN_OUTER].weight;
6309         monk_arm_wgt += inventory[INVEN_HANDS].weight;
6310         monk_arm_wgt += inventory[INVEN_FEET].weight;
6311
6312         return (monk_arm_wgt > (100 + (p_ptr->lev * 4)));
6313 }
6314
6315 /*!
6316  * @brief 実ゲームプレイ時間を更新する
6317  */
6318 void update_playtime(void)
6319 {
6320         /* Check if the game has started */
6321         if (start_time != 0)
6322         {
6323                 u32b tmp = (u32b)time(NULL);
6324                 playtime += (tmp - start_time);
6325                 start_time = tmp;
6326         }
6327 }