OSDN Git Service

[Refactor] #38997 forget_lite() に floor_type * 引数を追加. / Add floor_type * argument...
[hengband/hengband.git] / src / files.c
1 /*!
2  * @file files.c
3  * @brief ファイル入出力管理 / Purpose: code dealing with files (and death)
4  * @date 2014/01/28
5  * @author
6  * <pre>
7  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  * 2014 Deskull rearranged comment for Doxygen.\n
12  * </pre>
13  */
14
15
16 #include "angband.h"
17 #include "util.h"
18 #include "files.h"
19 #include "core.h"
20
21 #include "birth.h"
22 #include "files.h"
23
24 #include "bldg.h"
25
26 #include "cmd-magiceat.h"
27 #include "cmd-dump.h"
28 #include "world.h"
29 #include "player-inventory.h"
30 #include "player-race.h"
31 #include "player-status.h"
32 #include "player-move.h"
33 #include "player-class.h"
34 #include "player-skill.h"
35 #include "player-personality.h"
36 #include "player-sex.h"
37 #include "player-effects.h"
38 #include "sort.h"
39 #include "mutation.h"
40 #include "quest.h"
41 #include "store.h"
42 #include "artifact.h"
43 #include "avatar.h"
44 #include "shoot.h"
45 #include "patron.h"
46 #include "monster.h"
47 #include "monster-process.h"
48 #include "monster-status.h"
49 #include "object-flavor.h"
50 #include "object-hook.h"
51 #include "realm.h"
52 #include "realm-hex.h"
53 #include "cmd-pet.h"
54 #include "spells.h"
55 #include "term.h"
56 #include "view-mainwindow.h"
57 #include "floor-events.h"
58 #include "floor-town.h"
59 #include "dungeon-file.h"
60 #include "init.h"
61 #include "monster-spell.h"
62 #include "floor.h"
63 #include "dungeon.h"
64 #include "melee.h"
65 #include "objectkind.h"
66 #include "autopick.h"
67 #include "save.h"
68 #include "realm-song.h"
69
70 concptr ANGBAND_DIR; //!< Path name: The main "lib" directory This variable is not actually used anywhere in the code
71 concptr ANGBAND_DIR_APEX; //!< High score files (binary) These files may be portable between platforms
72 concptr ANGBAND_DIR_BONE; //!< Bone files for player ghosts (ascii) These files are portable between platforms
73 concptr ANGBAND_DIR_DATA; //!< Binary image files for the "*_info" arrays (binary) These files are not portable between platforms
74 concptr ANGBAND_DIR_EDIT; //!< Textual template files for the "*_info" arrays (ascii) These files are portable between platforms
75 concptr ANGBAND_DIR_SCRIPT; //!< Script files These files are portable between platforms.
76 concptr ANGBAND_DIR_FILE; //!< Various extra files (ascii) These files may be portable between platforms
77 concptr ANGBAND_DIR_HELP; //!< Help files (normal) for the online help (ascii) These files are portable between platforms
78 concptr ANGBAND_DIR_INFO; //!< Help files (spoilers) for the online help (ascii) These files are portable between platforms
79 concptr ANGBAND_DIR_PREF; //!< Default user "preference" files (ascii) These files are rarely portable between platforms
80 concptr ANGBAND_DIR_SAVE; //!< Savefiles for current characters (binary)
81 concptr ANGBAND_DIR_USER; //!< User "preference" files (ascii) These files are rarely portable between platforms
82 concptr ANGBAND_DIR_XTRA; //!< Various extra files (binary) These files are rarely portable between platforms
83
84 s16b signal_count;              /* Hack -- Count interupts */
85
86 /*
87  * Buffer to hold the current savefile name
88  * 'savefile' holds full path name. 'savefile_base' holds only base name.
89  */
90 char savefile[1024];
91 char savefile_base[40];
92
93
94
95 /*
96  * You may or may not want to use the following "#undef".
97  */
98 /* #undef _POSIX_SAVED_IDS */
99
100
101 /*!
102  * @brief ファイルのドロップパーミッションチェック / Hack -- drop permissions
103  */
104 void safe_setuid_drop(void)
105 {
106
107 #ifdef SET_UID
108
109 # ifdef SAFE_SETUID
110
111 #  ifdef SAFE_SETUID_POSIX
112
113         if (setuid(getuid()) != 0)
114         {
115                 quit(_("setuid(): 正しく許可が取れません!", "setuid(): cannot set permissions correctly!"));
116         }
117         if (setgid(getgid()) != 0)
118         {
119                 quit(_("setgid(): 正しく許可が取れません!", "setgid(): cannot set permissions correctly!"));
120         }
121
122 #  else
123
124         if (setreuid(geteuid(), getuid()) != 0)
125         {
126                 quit(_("setreuid(): 正しく許可が取れません!", "setreuid(): cannot set permissions correctly!"));
127         }
128         if (setregid(getegid(), getgid()) != 0)
129         {
130                 quit(_("setregid(): 正しく許可が取れません!", "setregid(): cannot set permissions correctly!"));
131         }
132
133 #  endif
134
135 # endif
136
137 #endif
138
139 }
140
141
142 /*!
143  * @brief ファイルのグラブパーミッションチェック / Hack -- grab permissions
144  */
145 void safe_setuid_grab(void)
146 {
147
148 #ifdef SET_UID
149
150 # ifdef SAFE_SETUID
151
152 #  ifdef SAFE_SETUID_POSIX
153
154         if (setuid(p_ptr->player_egid) != 0)
155         {
156                 quit(_("setuid(): 正しく許可が取れません!", "setuid(): cannot set permissions correctly!"));
157         }
158         if (setgid(p_ptr->player_egid) != 0)
159         {
160                 quit(_("setgid(): 正しく許可が取れません!", "setgid(): cannot set permissions correctly!"));
161         }
162
163 #  else
164
165         if (setreuid(geteuid(), getuid()) != 0)
166         {
167                 quit(_("setreuid(): 正しく許可が取れません!", "setreuid(): cannot set permissions correctly!"));
168         }
169         if (setregid(getegid(), getgid()) != 0)
170         {
171                 quit(_("setregid(): 正しく許可が取れません!", "setregid(): cannot set permissions correctly!"));
172         }
173
174 #  endif /* SAFE_SETUID_POSIX */
175
176 # endif /* SAFE_SETUID */
177
178 #endif /* SET_UID */
179
180 }
181
182
183 /*!
184  * @brief 各種データテキストをトークン単位に分解する / Extract the first few "tokens" from a buffer
185  * @param buf データテキストの参照ポインタ
186  * @param num トークンの数
187  * @param tokens トークンを保管する文字列参照ポインタ配列
188  * @param mode オプション
189  * @return 解釈した文字列数
190  * @details
191  * <pre>
192  * This function uses "colon" and "slash" as the delimeter characters.
193  * We never extract more than "num" tokens.  The "last" token may include
194  * "delimeter" characters, allowing the buffer to include a "string" token.
195  * We save pointers to the tokens in "tokens", and return the number found.
196  * Hack -- Attempt to handle the 'c' character formalism
197  * Hack -- An empty buffer, or a final delimeter, yields an "empty" token.
198  * Hack -- We will always extract at least one token
199  * </pre>
200  */
201 s16b tokenize(char *buf, s16b num, char **tokens, BIT_FLAGS mode)
202 {
203         s16b i = 0;
204
205         char *s = buf;
206
207
208         /* Process */
209         while (i < num - 1)
210         {
211                 char *t;
212
213                 /* Scan the string */
214                 for (t = s; *t; t++)
215                 {
216                         /* Found a delimiter */
217                         if ((*t == ':') || (*t == '/')) break;
218
219                         /* Handle single quotes */
220                         if ((mode & TOKENIZE_CHECKQUOTE) && (*t == '\''))
221                         {
222                                 /* Advance */
223                                 t++;
224
225                                 /* Handle backslash */
226                                 if (*t == '\\') t++;
227
228                                 /* Require a character */
229                                 if (!*t) break;
230
231                                 /* Advance */
232                                 t++;
233
234                                 /* Hack -- Require a close quote */
235                                 if (*t != '\'') *t = '\'';
236                         }
237
238                         /* Handle back-slash */
239                         if (*t == '\\') t++;
240                 }
241
242                 /* Nothing left */
243                 if (!*t) break;
244
245                 /* Nuke and advance */
246                 *t++ = '\0';
247
248                 /* Save the token */
249                 tokens[i++] = s;
250
251                 /* Advance */
252                 s = t;
253         }
254
255         /* Save the token */
256         tokens[i++] = s;
257
258         /* Number found */
259         return (i);
260 }
261
262
263 /* A number with a name */
264 typedef struct named_num named_num;
265
266 struct named_num
267 {
268         concptr name;           /* The name of this thing */
269         int num;                        /* A number associated with it */
270 };
271
272
273 /* Index of spell type names */
274 static named_num gf_desc[] =
275 {
276         {"GF_ELEC",                             GF_ELEC                         },
277         {"GF_POIS",                             GF_POIS                         },
278         {"GF_ACID",                             GF_ACID                         },
279         {"GF_COLD",                             GF_COLD                         },
280         {"GF_FIRE",                                     GF_FIRE                         },
281         {"GF_PSY_SPEAR",                        GF_PSY_SPEAR            },
282         {"GF_MISSILE",                          GF_MISSILE                      },
283         {"GF_ARROW",                            GF_ARROW                        },
284         {"GF_PLASMA",                           GF_PLASMA                       },
285         {"GF_WATER",                            GF_WATER                        },
286         {"GF_LITE",                                     GF_LITE                         },
287         {"GF_DARK",                                     GF_DARK                         },
288         {"GF_LITE_WEAK",                        GF_LITE_WEAK            },
289         {"GF_DARK_WEAK",                        GF_DARK_WEAK            },
290         {"GF_SHARDS",                           GF_SHARDS                       },
291         {"GF_SOUND",                            GF_SOUND                        },
292         {"GF_CONFUSION",                        GF_CONFUSION            },
293         {"GF_FORCE",                            GF_FORCE                        },
294         {"GF_INERTIA",                          GF_INERTIAL                     },
295         {"GF_MANA",                                     GF_MANA                         },
296         {"GF_METEOR",                           GF_METEOR                       },
297         {"GF_ICE",                                      GF_ICE                          },
298         {"GF_CHAOS",                            GF_CHAOS                        },
299         {"GF_NETHER",                           GF_NETHER                       },
300         {"GF_DISENCHANT",                       GF_DISENCHANT           },
301         {"GF_NEXUS",                            GF_NEXUS                        },
302         {"GF_TIME",                                     GF_TIME                         },
303         {"GF_GRAVITY",                          GF_GRAVITY                      },
304         {"GF_KILL_WALL",                        GF_KILL_WALL            },
305         {"GF_KILL_DOOR",                        GF_KILL_DOOR            },
306         {"GF_KILL_TRAP",                        GF_KILL_TRAP            },
307         {"GF_MAKE_WALL",                        GF_MAKE_WALL            },
308         {"GF_MAKE_DOOR",                        GF_MAKE_DOOR            },
309         {"GF_MAKE_TRAP",                        GF_MAKE_TRAP            },
310         {"GF_MAKE_TREE",                        GF_MAKE_TREE            },
311         {"GF_OLD_CLONE",                        GF_OLD_CLONE            },
312         {"GF_OLD_POLY",                         GF_OLD_POLY                     },
313         {"GF_OLD_HEAL",                         GF_OLD_HEAL                     },
314         {"GF_OLD_SPEED",                        GF_OLD_SPEED            },
315         {"GF_OLD_SLOW",                         GF_OLD_SLOW                     },
316         {"GF_OLD_CONF",                         GF_OLD_CONF                     },
317         {"GF_OLD_SLEEP",                        GF_OLD_SLEEP            },
318         {"GF_HYPODYNAMIA",                      GF_HYPODYNAMIA          },
319         {"GF_AWAY_UNDEAD",                      GF_AWAY_UNDEAD          },
320         {"GF_AWAY_EVIL",                        GF_AWAY_EVIL            },
321         {"GF_AWAY_ALL",                         GF_AWAY_ALL                     },
322         {"GF_TURN_UNDEAD",                      GF_TURN_UNDEAD          },
323         {"GF_TURN_EVIL",                        GF_TURN_EVIL            },
324         {"GF_TURN_ALL",                         GF_TURN_ALL                     },
325         {"GF_DISP_UNDEAD",                      GF_DISP_UNDEAD          },
326         {"GF_DISP_EVIL",                        GF_DISP_EVIL            },
327         {"GF_DISP_ALL",                         GF_DISP_ALL                     },
328         {"GF_DISP_DEMON",                       GF_DISP_DEMON           },
329         {"GF_DISP_LIVING",                      GF_DISP_LIVING          },
330         {"GF_ROCKET",                           GF_ROCKET                       },
331         {"GF_NUKE",                                     GF_NUKE                         },
332         {"GF_MAKE_GLYPH",                       GF_MAKE_GLYPH           },
333         {"GF_STASIS",                           GF_STASIS                       },
334         {"GF_STONE_WALL",                       GF_STONE_WALL           },
335         {"GF_DEATH_RAY",                        GF_DEATH_RAY            },
336         {"GF_STUN",                                     GF_STUN                         },
337         {"GF_HOLY_FIRE",                        GF_HOLY_FIRE            },
338         {"GF_HELL_FIRE",                        GF_HELL_FIRE            },
339         {"GF_DISINTEGRATE",                     GF_DISINTEGRATE         },
340         {"GF_CHARM",                            GF_CHARM                        },
341         {"GF_CONTROL_UNDEAD",           GF_CONTROL_UNDEAD       },
342         {"GF_CONTROL_ANIMAL",           GF_CONTROL_ANIMAL       },
343         {"GF_PSI",                                      GF_PSI                          },
344         {"GF_PSI_DRAIN",                        GF_PSI_DRAIN            },
345         {"GF_TELEKINESIS",                      GF_TELEKINESIS          },
346         {"GF_JAM_DOOR",                         GF_JAM_DOOR                     },
347         {"GF_DOMINATION",                       GF_DOMINATION           },
348         {"GF_DISP_GOOD",                        GF_DISP_GOOD            },
349         {"GF_DRAIN_MANA",                       GF_DRAIN_MANA           },
350         {"GF_MIND_BLAST",                       GF_MIND_BLAST           },
351         {"GF_BRAIN_SMASH",                      GF_BRAIN_SMASH          },
352         {"GF_CAUSE_1",                          GF_CAUSE_1                      },
353         {"GF_CAUSE_2",                          GF_CAUSE_2                      },
354         {"GF_CAUSE_3",                          GF_CAUSE_3                      },
355         {"GF_CAUSE_4",                          GF_CAUSE_4                      },
356         {"GF_HAND_DOOM",                        GF_HAND_DOOM            },
357         {"GF_CAPTURE",                          GF_CAPTURE                      },
358         {"GF_ANIM_DEAD",                        GF_ANIM_DEAD            },
359         {"GF_CHARM_LIVING",                     GF_CHARM_LIVING         },
360         {"GF_IDENTIFY",                         GF_IDENTIFY                     },
361         {"GF_ATTACK",                           GF_ATTACK                       },
362         {"GF_ENGETSU",                          GF_ENGETSU                      },
363         {"GF_GENOCIDE",                         GF_GENOCIDE                     },
364         {"GF_PHOTO",                            GF_PHOTO                        },
365         {"GF_CONTROL_DEMON",            GF_CONTROL_DEMON        },
366         {"GF_LAVA_FLOW",                        GF_LAVA_FLOW            },
367         {"GF_BLOOD_CURSE",                      GF_BLOOD_CURSE          },
368         {"GF_SEEKER",                           GF_SEEKER                       },
369         {"GF_SUPER_RAY",                        GF_SUPER_RAY            },
370         {"GF_STAR_HEAL",                        GF_STAR_HEAL            },
371         {"GF_WATER_FLOW",                       GF_WATER_FLOW           },
372         {"GF_CRUSADE",                          GF_CRUSADE                      },
373         {"GF_STASIS_EVIL",                      GF_STASIS_EVIL          },
374         {"GF_WOUNDS",                           GF_WOUNDS                       },
375         {NULL,                                          0                                       }
376 };
377
378
379 /*!
380  * @brief 設定ファイルの各行から各種テキスト情報を取得する /
381  * Parse a sub-file of the "extra info" (format shown below)
382  * @param buf データテキストの参照ポインタ
383  * @return エラーコード
384  * @details
385  * <pre>
386  * Each "action" line has an "action symbol" in the first column,
387  * followed by a colon, followed by some command specific info,
388  * usually in the form of "tokens" separated by colons or slashes.
389  * Blank lines, lines starting with white space, and lines starting
390  * with pound signs ("#") are ignored (as comments).
391  * Note the use of "tokenize()" to allow the use of both colons and
392  * slashes as delimeters, while still allowing final tokens which
393  * may contain any characters including "delimiters".
394  * Note the use of "strtol()" to allow all "integers" to be encoded
395  * in decimal, hexidecimal, or octal form.
396  * Note that "monster zero" is used for the "player" attr/char, "object
397  * zero" will be used for the "stack" attr/char, and "feature zero" is
398  * used for the "nothing" attr/char.
399  * Parse another file recursively, see below for details
400  *   %:\<filename\>
401  * Specify the attr/char values for "monsters" by race index
402  *   R:\<num\>:\<a\>:\<c\>
403  * Specify the attr/char values for "objects" by kind index
404  *   K:\<num\>:\<a\>:\<c\>
405  * Specify the attr/char values for "features" by feature index
406  *   F:\<num\>:\<a\>:\<c\>
407  * Specify the attr/char values for unaware "objects" by kind tval
408  *   U:\<tv\>:\<a\>:\<c\>
409  * Specify the attr/char values for p_ptr->inventory_list "objects" by kind tval
410  *   E:\<tv\>:\<a\>:\<c\>
411  * Define a macro action, given an encoded macro action
412  *   A:\<str\>
413  * Create a normal macro, given an encoded macro trigger
414  *   P:\<str\>
415  * Create a command macro, given an encoded macro trigger
416  *   C:\<str\>
417  * Create a keyset mapping
418  *   S:\<key\>:\<key\>:\<dir\>
419  * Turn an option off, given its name
420  *   X:\<str\>
421  * Turn an option on, given its name
422  *   Y:\<str\>
423  * Specify visual information, given an index, and some data
424  *   V:\<num\>:\<kv\>:\<rv\>:\<gv\>:\<bv\>
425  * Specify the set of colors to use when drawing a zapped spell
426  *   Z:\<type\>:\<str\>
427  * Specify a macro trigger template and macro trigger names.
428  *   T:\<template\>:\<modifier chr\>:\<modifier name1\>:\<modifier name2\>:...
429  *   T:\<trigger\>:\<keycode\>:\<shift-keycode\>
430  * </pre>
431  */
432 errr process_pref_file_command(char *buf)
433 {
434         int i, j;
435         TERM_COLOR n1;
436         SYMBOL_CODE n2;
437
438
439         char *zz[16];
440
441
442         /* Require "?:*" format */
443         if (buf[1] != ':') return 1;
444
445
446         switch (buf[0])
447         {
448                 /* Mega-Hack -- read external player's history file */
449                 /* Process "H:<history>" */
450                 case 'H':
451                         add_history_from_pref_line(buf + 2);
452                         return 0;
453
454                 /* Process "R:<num>:<a>/<c>" -- attr/char for monster races */
455                 case 'R':
456                         if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
457                         {
458                                 monster_race *r_ptr;
459                                 i = (huge)strtol(zz[0], NULL, 0);
460                                 n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
461                                 n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
462                                 if (i >= max_r_idx) return 1;
463                                 r_ptr = &r_info[i];
464                                 if (n1 || (!(n2 & 0x80) && n2)) r_ptr->x_attr = n1; /* Allow TERM_DARK text */
465                                 if (n2) r_ptr->x_char = n2;
466                                 return 0;
467                         }
468                         break;
469
470                 /* Process "K:<num>:<a>/<c>"  -- attr/char for object kinds */
471                 case 'K':
472                         if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
473                         {
474                                 object_kind *k_ptr;
475                                 i = (huge)strtol(zz[0], NULL, 0);
476                                 n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
477                                 n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
478                                 if (i >= max_k_idx) return 1;
479                                 k_ptr = &k_info[i];
480                                 if (n1 || (!(n2 & 0x80) && n2)) k_ptr->x_attr = n1; /* Allow TERM_DARK text */
481                                 if (n2) k_ptr->x_char = n2;
482                                 return 0;
483                         }
484                         break;
485
486                 /* Process "F:<num>:<a>/<c>" -- attr/char for terrain features */
487                 /* "F:<num>:<a>/<c>" */
488                 /* "F:<num>:<a>/<c>:LIT" */
489                 /* "F:<num>:<a>/<c>:<la>/<lc>:<da>/<dc>" */
490                 case 'F':
491                         {
492                                 feature_type *f_ptr;
493                                 int num = tokenize(buf + 2, F_LIT_MAX * 2 + 1, zz, TOKENIZE_CHECKQUOTE);
494
495                                 if ((num != 3) && (num != 4) && (num != F_LIT_MAX * 2 + 1)) return 1;
496                                 else if ((num == 4) && !streq(zz[3], "LIT")) return 1;
497
498                                 i = (huge)strtol(zz[0], NULL, 0);
499                                 if (i >= max_f_idx) return 1;
500                                 f_ptr = &f_info[i];
501
502                                 n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
503                                 n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
504                                 if (n1 || (!(n2 & 0x80) && n2)) f_ptr->x_attr[F_LIT_STANDARD] = n1; /* Allow TERM_DARK text */
505                                 if (n2) f_ptr->x_char[F_LIT_STANDARD] = n2;
506
507                                 /* Mega-hack -- feat supports lighting */
508                                 switch (num)
509                                 {
510                                 /* No lighting support */
511                                 case 3:
512                                         n1 = f_ptr->x_attr[F_LIT_STANDARD];
513                                         n2 = f_ptr->x_char[F_LIT_STANDARD];
514                                         for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
515                                         {
516                                                 f_ptr->x_attr[j] = n1;
517                                                 f_ptr->x_char[j] = n2;
518                                         }
519                                         break;
520
521                                 /* Use default lighting */
522                                 case 4:
523                                         apply_default_feat_lighting(f_ptr->x_attr, f_ptr->x_char);
524                                         break;
525
526                                 /* Use desired lighting */
527                                 case F_LIT_MAX * 2 + 1:
528                                         for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
529                                         {
530                                                 n1 = (TERM_COLOR)strtol(zz[j * 2 + 1], NULL, 0);
531                                                 n2 = (SYMBOL_CODE)strtol(zz[j * 2 + 2], NULL, 0);
532                                                 if (n1 || (!(n2 & 0x80) && n2)) f_ptr->x_attr[j] = n1; /* Allow TERM_DARK text */
533                                                 if (n2) f_ptr->x_char[j] = n2;
534                                         }
535                                         break;
536                                 }
537                         }
538                         return 0;
539
540                 /* Process "S:<num>:<a>/<c>" -- attr/char for special things */
541                 case 'S':
542                         if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
543                         {
544                                 j = (byte)strtol(zz[0], NULL, 0);
545                                 n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
546                                 n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
547                                 misc_to_attr[j] = n1;
548                                 misc_to_char[j] = n2;
549                                 return 0;
550                         }
551                         break;
552
553                 /* Process "U:<tv>:<a>/<c>" -- attr/char for unaware items */
554                 case 'U':
555                         if (tokenize(buf+2, 3, zz, TOKENIZE_CHECKQUOTE) == 3)
556                         {
557                                 j = (huge)strtol(zz[0], NULL, 0);
558                                 n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
559                                 n2 = (SYMBOL_CODE)strtol(zz[2], NULL, 0);
560                                 for (i = 1; i < max_k_idx; i++)
561                                 {
562                                         object_kind *k_ptr = &k_info[i];
563                                         if (k_ptr->tval == j)
564                                         {
565                                                 if (n1) k_ptr->d_attr = n1;
566                                                 if (n2) k_ptr->d_char = n2;
567                                         }
568                                 }
569                                 return 0;
570                         }
571                         break;
572
573                 /* Process "E:<tv>:<a>" -- attribute for p_ptr->inventory_list objects */
574                 case 'E':
575                         if (tokenize(buf+2, 2, zz, TOKENIZE_CHECKQUOTE) == 2)
576                         {
577                                 j = (byte)strtol(zz[0], NULL, 0) % 128;
578                                 n1 = (TERM_COLOR)strtol(zz[1], NULL, 0);
579                                 if (n1) tval_to_attr[j] = n1;
580                                 return 0;
581                         }
582                         break;
583
584                 /* Process "A:<str>" -- save an "action" for later */
585                 case 'A':
586                         text_to_ascii(macro__buf, buf+2);
587                         return 0;
588
589                 /* Process "P:<str>" -- normal macro */
590                 case 'P':
591                 {
592                         char tmp[1024];
593
594                         text_to_ascii(tmp, buf+2);
595                         macro_add(tmp, macro__buf);
596                         return 0;
597                 }
598
599                 /* Process "C:<str>" -- create keymap */
600                 case 'C':
601                 {
602                         int mode;
603                         char tmp[1024];
604
605                         if (tokenize(buf+2, 2, zz, TOKENIZE_CHECKQUOTE) != 2) return 1;
606
607                         mode = strtol(zz[0], NULL, 0);
608                         if ((mode < 0) || (mode >= KEYMAP_MODES)) return 1;
609
610                         text_to_ascii(tmp, zz[1]);
611                         if (!tmp[0] || tmp[1]) return 1;
612                         i = (byte)(tmp[0]);
613
614                         string_free(keymap_act[mode][i]);
615
616                         keymap_act[mode][i] = string_make(macro__buf);
617
618                         return 0;
619                 }
620
621                 /* Process "V:<num>:<kv>:<rv>:<gv>:<bv>" -- visual info */
622                 case 'V':
623                         if (tokenize(buf+2, 5, zz, TOKENIZE_CHECKQUOTE) == 5)
624                         {
625                                 i = (byte)strtol(zz[0], NULL, 0);
626                                 angband_color_table[i][0] = (byte)strtol(zz[1], NULL, 0);
627                                 angband_color_table[i][1] = (byte)strtol(zz[2], NULL, 0);
628                                 angband_color_table[i][2] = (byte)strtol(zz[3], NULL, 0);
629                                 angband_color_table[i][3] = (byte)strtol(zz[4], NULL, 0);
630                                 return 0;
631                         }
632                         break;
633
634                 /* Process "X:<str>" -- current_world_ptr->game_turn option off */
635                 /* Process "Y:<str>" -- current_world_ptr->game_turn option on */
636                 case 'X':
637                 case 'Y':
638                         for (i = 0; option_info[i].o_desc; i++)
639                         {
640                                 if (option_info[i].o_var &&
641                                         option_info[i].o_text &&
642                                         streq(option_info[i].o_text, buf + 2))
643                                 {
644                                         int os = option_info[i].o_set;
645                                         int ob = option_info[i].o_bit;
646
647                                         if ((p_ptr->playing || current_world_ptr->character_xtra) &&
648                                                 (OPT_PAGE_BIRTH == option_info[i].o_page) && !current_world_ptr->wizard)
649                                         {
650                                                 msg_format(_("初期オプションは変更できません! '%s'", "Birth options can not changed! '%s'"), buf);
651                                                 msg_print(NULL);
652                                                 return 0;
653                                         }
654
655                                         if (buf[0] == 'X')
656                                         {
657                                                 option_flag[os] &= ~(1L << ob);
658                                                 (*option_info[i].o_var) = FALSE;
659                                         }
660                                         else
661                                         {
662                                                 /* Set */
663                                                 option_flag[os] |= (1L << ob);
664                                                 (*option_info[i].o_var) = TRUE;
665                                         }
666                                         return 0;
667                                 }
668                         }
669
670                         /* don't know that option. ignore it.*/
671                         msg_format(_("オプションの名前が正しくありません: %s", "Ignored invalid option: %s"), buf);
672                         msg_print(NULL);
673                         return 0;
674
675                 /* Process "Z:<type>:<str>" -- set spell color */
676                 case 'Z':
677                 {
678                         /* Find the colon */
679                         char *t = my_strchr(buf + 2, ':');
680
681                         if (!t) return 1;
682
683                         /* Nuke the colon */
684                         *(t++) = '\0';
685
686                         for (i = 0; gf_desc[i].name; i++)
687                         {
688                                 /* Match this type */
689                                 if (streq(gf_desc[i].name, buf + 2))
690                                 {
691                                         /* Remember this color set */
692                                         gf_color[gf_desc[i].num] = (TERM_COLOR)quark_add(t);
693
694                                         /* Success */
695                                         return 0;
696                                 }
697                         }
698
699                         break;
700                 }
701
702                 /* Initialize macro trigger names and a template */
703                 /* Process "T:<trigger>:<keycode>:<shift-keycode>" */
704                 /* Process "T:<template>:<modifier chr>:<modifier name>:..." */
705                 case 'T':
706                 {
707                         int tok = tokenize(buf+2, 2+MAX_MACRO_MOD, zz, 0);
708
709                         /* Process "T:<template>:<modifier chr>:<modifier name>:..." */
710                         if (tok >= 4)
711                         {
712                                 int num;
713
714                                 if (macro_template != NULL)
715                                 {
716                                         num = strlen(macro_modifier_chr);
717
718                                         /* Kill the template string */
719                                         string_free(macro_template);
720                                         macro_template = NULL;
721
722                                         /* Kill flag characters of modifier keys */
723                                         string_free(macro_modifier_chr);
724
725                                         /* Kill corresponding modifier names */
726                                         for (i = 0; i < num; i++)
727                                         {
728                                                 string_free(macro_modifier_name[i]);
729                                         }
730
731                                         /* Kill trigger name strings */
732                                         for (i = 0; i < max_macrotrigger; i++)
733                                         {
734                                                 string_free(macro_trigger_name[i]);
735                                                 string_free(macro_trigger_keycode[0][i]);
736                                                 string_free(macro_trigger_keycode[1][i]);
737                                         }
738
739                                         max_macrotrigger = 0;
740                                 }
741
742                                 if (*zz[0] == '\0') return 0; /* clear template */
743
744                                 /* Number of modifier flags */
745                                 num = strlen(zz[1]);
746
747                                 /* Limit the number */
748                                 num = MIN(MAX_MACRO_MOD, num);
749
750                                 /* Stop if number of modifier is not correct */
751                                 if (2 + num != tok) return 1;
752
753                                 /* Get a template string */
754                                 macro_template = string_make(zz[0]);
755
756                                 /* Get flag characters of modifier keys */
757                                 macro_modifier_chr = string_make(zz[1]);
758
759                                 /* Get corresponding modifier names */
760                                 for (i = 0; i < num; i++)
761                                 {
762                                         macro_modifier_name[i] = string_make(zz[2+i]);
763                                 }
764                         }
765
766                         /* Process "T:<trigger>:<keycode>:<shift-keycode>" */
767                         else if (tok >= 2)
768                         {
769                                 char buf_aux[1024];
770                                 int m;
771                                 char *t, *s;
772                                 if (max_macrotrigger >= MAX_MACRO_TRIG)
773                                 {
774                                         msg_print(_("マクロトリガーの設定が多すぎます!", "Too many macro triggers!"));
775                                         return 1;
776                                 }
777                                 m = max_macrotrigger;
778                                 max_macrotrigger++;
779
780                                 /* Take into account the escape character  */
781                                 t = buf_aux;
782                                 s = zz[0];
783                                 while (*s)
784                                 {
785                                         if ('\\' == *s) s++;
786                                         *t++ = *s++;
787                                 }
788                                 *t = '\0';
789
790                                 /* Get a trigger name */
791                                 macro_trigger_name[m] = string_make(buf_aux);
792
793                                 /* Get the corresponding key code */
794                                 macro_trigger_keycode[0][m] = string_make(zz[1]);
795
796                                 if (tok == 3)
797                                 {
798                                         /* Key code of a combination of it with the shift key */
799                                         macro_trigger_keycode[1][m] = string_make(zz[2]);
800                                 }
801                                 else
802                                 {
803                                         macro_trigger_keycode[1][m] = string_make(zz[1]);
804                                 }
805                         }
806
807                         /* No error */
808                         return 0;
809                 }
810         }
811
812         /* Failure */
813         return 1;
814 }
815
816
817 /*!
818  * @brief process_pref_fileのサブルーチンとして条件分岐処理の解釈と結果を返す /
819  * Helper function for "process_pref_file()"
820  * @param sp テキスト文字列の参照ポインタ
821  * @param fp 再帰中のポインタ参照
822  * @return
823  * @details
824  * <pre>
825  * Input:
826  *   v: output buffer array
827  *   f: final character
828  * Output:
829  *   result
830  * </pre>
831  */
832 concptr process_pref_file_expr(char **sp, char *fp)
833 {
834         concptr v;
835
836         char *b;
837         char *s;
838
839         char b1 = '[';
840         char b2 = ']';
841
842         char f = ' ';
843         static char tmp[16];
844
845         /* Initial */
846         s = (*sp);
847
848         /* Skip spaces */
849         while (iswspace(*s)) s++;
850
851         /* Save start */
852         b = s;
853
854         /* Default */
855         v = "?o?o?";
856
857         /* Analyze */
858         if (*s == b1)
859         {
860                 concptr p;
861                 concptr t;
862
863                 /* Skip b1 */
864                 s++;
865
866                 /* First */
867                 t = process_pref_file_expr(&s, &f);
868
869                 if (!*t)
870                 {
871                         /* Nothing */
872                 }
873
874                 /* Function: IOR */
875                 else if (streq(t, "IOR"))
876                 {
877                         v = "0";
878                         while (*s && (f != b2))
879                         {
880                                 t = process_pref_file_expr(&s, &f);
881                                 if (*t && !streq(t, "0")) v = "1";
882                         }
883                 }
884
885                 /* Function: AND */
886                 else if (streq(t, "AND"))
887                 {
888                         v = "1";
889                         while (*s && (f != b2))
890                         {
891                                 t = process_pref_file_expr(&s, &f);
892                                 if (*t && streq(t, "0")) v = "0";
893                         }
894                 }
895
896                 /* Function: NOT */
897                 else if (streq(t, "NOT"))
898                 {
899                         v = "1";
900                         while (*s && (f != b2))
901                         {
902                                 t = process_pref_file_expr(&s, &f);
903                                 if (*t && streq(t, "1")) v = "0";
904                         }
905                 }
906
907                 /* Function: EQU */
908                 else if (streq(t, "EQU"))
909                 {
910                         v = "0";
911                         if (*s && (f != b2))
912                         {
913                                 t = process_pref_file_expr(&s, &f);
914                         }
915                         while (*s && (f != b2))
916                         {
917                                 p = process_pref_file_expr(&s, &f);
918                                 if (streq(t, p)) v = "1";
919                         }
920                 }
921
922                 /* Function: LEQ */
923                 else if (streq(t, "LEQ"))
924                 {
925                         v = "1";
926                         if (*s && (f != b2))
927                         {
928                                 t = process_pref_file_expr(&s, &f);
929                         }
930                         while (*s && (f != b2))
931                         {
932                                 p = t;
933                                 t = process_pref_file_expr(&s, &f);
934                                 if (*t && atoi(p) > atoi(t)) v = "0";
935                         }
936                 }
937
938                 /* Function: GEQ */
939                 else if (streq(t, "GEQ"))
940                 {
941                         v = "1";
942                         if (*s && (f != b2))
943                         {
944                                 t = process_pref_file_expr(&s, &f);
945                         }
946                         while (*s && (f != b2))
947                         {
948                                 p = t;
949                                 t = process_pref_file_expr(&s, &f);
950
951                                 /* Compare two numbers instead of string */
952                                 if (*t && atoi(p) < atoi(t)) v = "0";
953                         }
954                 }
955
956                 else
957                 {
958                         while (*s && (f != b2))
959                         {
960                                 t = process_pref_file_expr(&s, &f);
961                         }
962                 }
963
964                 /* Verify ending */
965                 if (f != b2) v = "?x?x?";
966
967                 /* Extract final and Terminate */
968                 if ((f = *s) != '\0') *s++ = '\0';
969         }
970
971         /* Other */
972         else
973         {
974                 /* Accept all printables except spaces and brackets */
975 #ifdef JP
976                 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
977                 {
978                         if (iskanji(*s)) s++;
979                         s++;
980                 }
981 #else
982                 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
983 #endif
984
985                 /* Extract final and Terminate */
986                 if ((f = *s) != '\0') *s++ = '\0';
987
988                 /* Variable */
989                 if (*b == '$')
990                 {
991                         /* System */
992                         if (streq(b+1, "SYS"))
993                         {
994                                 v = ANGBAND_SYS;
995                         }
996
997                         else if (streq(b+1, "KEYBOARD"))
998                         {
999                                 v = ANGBAND_KEYBOARD;
1000                         }
1001
1002                         /* Graphics */
1003                         else if (streq(b+1, "GRAF"))
1004                         {
1005                                 v = ANGBAND_GRAF;
1006                         }
1007
1008                         /* Monochrome mode */
1009                         else if (streq(b+1, "MONOCHROME"))
1010                         {
1011                                 if (arg_monochrome)
1012                                         v = "ON";
1013                                 else
1014                                         v = "OFF";
1015                         }
1016
1017                         /* Race */
1018                         else if (streq(b+1, "RACE"))
1019                         {
1020 #ifdef JP
1021                                 v = rp_ptr->E_title;
1022 #else
1023                                 v = rp_ptr->title;
1024 #endif
1025                         }
1026
1027                         /* Class */
1028                         else if (streq(b+1, "CLASS"))
1029                         {
1030 #ifdef JP
1031                                 v = cp_ptr->E_title;
1032 #else
1033                                 v = cp_ptr->title;
1034 #endif
1035                         }
1036
1037                         /* Player */
1038                         else if (streq(b+1, "PLAYER"))
1039                         {
1040                                 static char tmp_player_name[32];
1041                                 char *pn, *tpn;
1042                                 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
1043                                 {
1044 #ifdef JP
1045                                         if (iskanji(*pn))
1046                                         {
1047                                                 *(tpn++) = *(pn++);
1048                                                 *tpn = *pn;
1049                                                 continue;
1050                                         }
1051 #endif
1052                                         *tpn = my_strchr(" []", *pn) ? '_' : *pn;
1053                                 }
1054                                 *tpn = '\0';
1055                                 v = tmp_player_name;
1056                         }
1057
1058                         /* First realm */
1059                         else if (streq(b+1, "REALM1"))
1060                         {
1061 #ifdef JP
1062                                 v = E_realm_names[p_ptr->realm1];
1063 #else
1064                                 v = realm_names[p_ptr->realm1];
1065 #endif
1066                         }
1067
1068                         /* Second realm */
1069                         else if (streq(b+1, "REALM2"))
1070                         {
1071 #ifdef JP
1072                                 v = E_realm_names[p_ptr->realm2];
1073 #else
1074                                 v = realm_names[p_ptr->realm2];
1075 #endif
1076                         }
1077
1078                         /* Level */
1079                         else if (streq(b+1, "LEVEL"))
1080                         {
1081                                 sprintf(tmp, "%02d", p_ptr->lev);
1082                                 v = tmp;
1083                         }
1084
1085                         /* Autopick auto-register is in-use or not? */
1086                         else if (streq(b+1, "AUTOREGISTER"))
1087                         {
1088                                 if (p_ptr->autopick_autoregister)
1089                                         v = "1";
1090                                 else
1091                                         v = "0";
1092                         }
1093
1094                         /* Money */
1095                         else if (streq(b+1, "MONEY"))
1096                         {
1097                                 sprintf(tmp, "%09ld", (long int)p_ptr->au);
1098                                 v = tmp;
1099                         }
1100                 }
1101
1102                 /* Constant */
1103                 else
1104                 {
1105                         v = b;
1106                 }
1107         }
1108
1109         /* Save */
1110         (*fp) = f;
1111         (*sp) = s;
1112         return (v);
1113 }
1114
1115
1116 #define PREF_TYPE_NORMAL   0
1117 #define PREF_TYPE_AUTOPICK 1
1118 #define PREF_TYPE_HISTPREF 2
1119
1120 /*!
1121  * @brief process_pref_fileのサブルーチン /
1122  * Open the "user pref file" and parse it.
1123  * @param name 読み込むファイル名
1124  * @param preftype prefファイルのタイプ
1125  * @return エラーコード
1126  * @details
1127  * <pre>
1128  * Input:
1129  *   v: output buffer array
1130  *   f: final character
1131  * Output:
1132  *   result
1133  * </pre>
1134  */
1135 static errr process_pref_file_aux(concptr name, int preftype)
1136 {
1137         FILE *fp;
1138
1139         char buf[1024];
1140
1141         char old[1024];
1142
1143         int line = -1;
1144
1145         errr err = 0;
1146
1147         bool bypass = FALSE;
1148
1149         fp = my_fopen(name, "r");
1150
1151         /* No such file */
1152         if (!fp) return (-1);
1153
1154         /* Process the file */
1155         while (0 == my_fgets(fp, buf, sizeof(buf)))
1156         {
1157                 /* Count lines */
1158                 line++;
1159
1160                 /* Skip "empty" lines */
1161                 if (!buf[0]) continue;
1162
1163                 /* Skip "blank" lines */
1164 #ifdef JP
1165                 if (!iskanji(buf[0]))
1166 #endif
1167                 if (iswspace(buf[0])) continue;
1168
1169                 /* Skip comments */
1170                 if (buf[0] == '#') continue;
1171
1172
1173                 /* Save a copy */
1174                 strcpy(old, buf);
1175
1176
1177                 /* Process "?:<expr>" */
1178                 if ((buf[0] == '?') && (buf[1] == ':'))
1179                 {
1180                         char f;
1181                         concptr v;
1182                         char *s;
1183
1184                         /* Start */
1185                         s = buf + 2;
1186
1187                         /* Parse the expr */
1188                         v = process_pref_file_expr(&s, &f);
1189
1190                         /* Set flag */
1191                         bypass = (streq(v, "0") ? TRUE : FALSE);
1192                         continue;
1193                 }
1194
1195                 /* Apply conditionals */
1196                 if (bypass) continue;
1197
1198
1199                 /* Process "%:<file>" */
1200                 if (buf[0] == '%')
1201                 {
1202                         static int depth_count = 0;
1203
1204                         /* Ignore if deeper than 20 level */
1205                         if (depth_count > 20) continue;
1206
1207                         /* Count depth level */
1208                         depth_count++;
1209
1210                         /* Process that file if allowed */
1211                         switch (preftype)
1212                         {
1213                         case PREF_TYPE_AUTOPICK:
1214                                 (void)process_autopick_file(buf + 2);
1215                                 break;
1216                         case PREF_TYPE_HISTPREF:
1217                                 (void)process_histpref_file(buf + 2);
1218                                 break;
1219                         default:
1220                                 (void)process_pref_file(buf + 2);
1221                                 break;
1222                         }
1223
1224                         /* Set back depth level */
1225                         depth_count--;
1226                         continue;
1227                 }
1228
1229
1230                 /* Process the line */
1231                 err = process_pref_file_command(buf);
1232
1233                 /* This is not original pref line... */
1234                 if (err)
1235                 {
1236                         if (preftype != PREF_TYPE_AUTOPICK)
1237                                 break;
1238                         err = process_autopick_file_command(buf);
1239                 }
1240         }
1241
1242
1243         /* Error */
1244         if (err)
1245         {
1246                 /* Print error message */
1247                 /* ToDo: Add better error messages */
1248                 msg_format(_("ファイル'%s'の%d行でエラー番号%dのエラー。", "Error %d in line %d of file '%s'."), 
1249                                         _(name, err), line, _(err, name));
1250                 msg_format(_("('%s'を解析中)", "Parsing '%s'"), old);
1251                 msg_print(NULL);
1252         }
1253         my_fclose(fp);
1254         return (err);
1255 }
1256
1257
1258 /*!
1259  * @brief pref設定ファイルを読み込み設定を反映させる /
1260  * Process the "user pref file" with the given name
1261  * @param name 読み込むファイル名
1262  * @return エラーコード
1263  * @details
1264  * <pre>
1265  * See the functions above for a list of legal "commands".
1266  * We also accept the special "?" and "%" directives, which
1267  * allow conditional evaluation and filename inclusion.
1268  * </pre>
1269  */
1270 errr process_pref_file(concptr name)
1271 {
1272         char buf[1024];
1273
1274         errr err1, err2;
1275         path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
1276
1277         /* Process the system pref file */
1278         err1 = process_pref_file_aux(buf, PREF_TYPE_NORMAL);
1279
1280         /* Stop at parser errors, but not at non-existing file */
1281         if (err1 > 0) return err1;
1282
1283         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
1284         
1285         /* Process the user pref file */
1286         err2 = process_pref_file_aux(buf, PREF_TYPE_NORMAL);
1287
1288
1289         /* User file does not exist, but read system pref file */
1290         if (err2 < 0 && !err1)
1291                 return -2;
1292
1293         /* Result of user file processing */
1294         return err2;
1295 }
1296
1297
1298
1299 #ifdef CHECK_TIME
1300
1301 /*
1302  * Operating hours for ANGBAND (defaults to non-work hours)
1303  */
1304 static char days[7][29] =
1305 {
1306         "SUN:XXXXXXXXXXXXXXXXXXXXXXXX",
1307         "MON:XXXXXXXX.........XXXXXXX",
1308         "TUE:XXXXXXXX.........XXXXXXX",
1309         "WED:XXXXXXXX.........XXXXXXX",
1310         "THU:XXXXXXXX.........XXXXXXX",
1311         "FRI:XXXXXXXX.........XXXXXXX",
1312         "SAT:XXXXXXXXXXXXXXXXXXXXXXXX"
1313 };
1314
1315 /*
1316  * Restict usage (defaults to no restrictions)
1317  */
1318 static bool check_time_flag = FALSE;
1319
1320 #endif
1321
1322
1323 /*!
1324  * @brief Angbandプレイ禁止時刻をチェック /
1325  * Handle CHECK_TIME
1326  * @return エラーコード
1327  */
1328 errr check_time(void)
1329 {
1330
1331 #ifdef CHECK_TIME
1332
1333         time_t      c;
1334         struct tm   *tp;
1335
1336         /* No restrictions */
1337         if (!check_time_flag) return (0);
1338
1339         /* Check for time violation */
1340         c = time((time_t *)0);
1341         tp = localtime(&c);
1342
1343         /* Violation */
1344         if (days[tp->tm_wday][tp->tm_hour + 4] != 'X') return (1);
1345
1346 #endif
1347
1348         /* Success */
1349         return (0);
1350 }
1351
1352
1353 /*!
1354  * @brief Angbandプレイ禁止時刻の初期化 /
1355  * Initialize CHECK_TIME
1356  * @return エラーコード
1357  */
1358 errr check_time_init(void)
1359 {
1360
1361 #ifdef CHECK_TIME
1362
1363         FILE        *fp;
1364
1365         char    buf[1024];
1366
1367         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "time.txt");
1368         fp = my_fopen(buf, "r");
1369
1370         /* No file, no restrictions */
1371         if (!fp) return (0);
1372
1373         /* Assume restrictions */
1374         check_time_flag = TRUE;
1375
1376         /* Parse the file */
1377         while (0 == my_fgets(fp, buf, sizeof(buf)))
1378         {
1379                 /* Skip comments and blank lines */
1380                 if (!buf[0] || (buf[0] == '#')) continue;
1381
1382                 /* Chop the buffer */
1383                 buf[29] = '\0';
1384
1385                 /* Extract the info */
1386                 if (prefix(buf, "SUN:")) strcpy(days[0], buf);
1387                 if (prefix(buf, "MON:")) strcpy(days[1], buf);
1388                 if (prefix(buf, "TUE:")) strcpy(days[2], buf);
1389                 if (prefix(buf, "WED:")) strcpy(days[3], buf);
1390                 if (prefix(buf, "THU:")) strcpy(days[4], buf);
1391                 if (prefix(buf, "FRI:")) strcpy(days[5], buf);
1392                 if (prefix(buf, "SAT:")) strcpy(days[6], buf);
1393         }
1394         my_fclose(fp);
1395
1396 #endif
1397
1398         /* Success */
1399         return (0);
1400 }
1401
1402
1403
1404 #ifdef CHECK_LOAD
1405
1406 #ifndef MAXHOSTNAMELEN
1407 # define MAXHOSTNAMELEN  64
1408 #endif
1409
1410 typedef struct statstime statstime;
1411
1412 struct statstime
1413 {
1414         int                 cp_time[4];
1415         int                 dk_xfer[4];
1416         unsigned int        v_pgpgin;
1417         unsigned int        v_pgpgout;
1418         unsigned int        v_pswpin;
1419         unsigned int        v_pswpout;
1420         unsigned int        v_intr;
1421         int                 if_ipackets;
1422         int                 if_ierrors;
1423         int                 if_opackets;
1424         int                 if_oerrors;
1425         int                 if_collisions;
1426         unsigned int        v_swtch;
1427         long                avenrun[3];
1428         struct timeval      boottime;
1429         struct timeval      curtime;
1430 };
1431
1432 /*
1433  * Maximal load (if any).
1434  */
1435 static int check_load_value = 0;
1436
1437 #endif
1438
1439
1440 /*!
1441  * @brief Angbandプレイ禁止ホストのチェック /
1442  * Handle CHECK_LOAD
1443  * @return エラーコード
1444  */
1445 errr check_load(void)
1446 {
1447
1448 #ifdef CHECK_LOAD
1449
1450         struct statstime    st;
1451
1452         /* Success if not checking */
1453         if (!check_load_value) return (0);
1454
1455         /* Check the load */
1456         if (0 == rstat("localhost", &st))
1457         {
1458                 long val1 = (long)(st.avenrun[2]);
1459                 long val2 = (long)(check_load_value) * FSCALE;
1460
1461                 /* Check for violation */
1462                 if (val1 >= val2) return (1);
1463         }
1464
1465 #endif
1466
1467         /* Success */
1468         return (0);
1469 }
1470
1471
1472 /*!
1473  * @brief Angbandプレイ禁止ホストの設定初期化 /
1474  * Initialize CHECK_LOAD
1475  * @return エラーコード
1476  */
1477 errr check_load_init(void)
1478 {
1479
1480 #ifdef CHECK_LOAD
1481
1482         FILE        *fp;
1483
1484         char    buf[1024];
1485
1486         char    temphost[MAXHOSTNAMELEN+1];
1487         char    thishost[MAXHOSTNAMELEN+1];
1488
1489         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "load.txt");
1490
1491         /* Open the "load" file */
1492         fp = my_fopen(buf, "r");
1493
1494         /* No file, no restrictions */
1495         if (!fp) return (0);
1496
1497         /* Default load */
1498         check_load_value = 100;
1499
1500         /* Get the host name */
1501         (void)gethostname(thishost, (sizeof thishost) - 1);
1502
1503         /* Parse it */
1504         while (0 == my_fgets(fp, buf, sizeof(buf)))
1505         {
1506                 int value;
1507
1508                 /* Skip comments and blank lines */
1509                 if (!buf[0] || (buf[0] == '#')) continue;
1510
1511                 /* Parse, or ignore */
1512                 if (sscanf(buf, "%s%d", temphost, &value) != 2) continue;
1513
1514                 /* Skip other hosts */
1515                 if (!streq(temphost, thishost) &&
1516                     !streq(temphost, "localhost")) continue;
1517
1518                 /* Use that value */
1519                 check_load_value = value;
1520
1521                 break;
1522         }
1523         my_fclose(fp);
1524
1525 #endif
1526
1527         /* Success */
1528         return (0);
1529 }
1530
1531
1532 #define ENTRY_BARE_HAND 0
1533 #define ENTRY_TWO_HANDS 1
1534 #define ENTRY_RIGHT_HAND1 2
1535 #define ENTRY_LEFT_HAND1 3
1536 #define ENTRY_LEFT_HAND2 4
1537 #define ENTRY_RIGHT_HAND2 5
1538 #define ENTRY_POSTURE 6
1539 #define ENTRY_SHOOT_HIT_DAM 7
1540 #define ENTRY_SHOOT_POWER 8
1541 #define ENTRY_SPEED 9
1542 #define ENTRY_BASE_AC 10
1543 #define ENTRY_LEVEL 11
1544 #define ENTRY_CUR_EXP 12
1545 #define ENTRY_MAX_EXP 13
1546 #define ENTRY_EXP_TO_ADV 14
1547 #define ENTRY_GOLD 15
1548 #define ENTRY_DAY 16
1549 #define ENTRY_HP 17
1550 #define ENTRY_SP 18
1551 #define ENTRY_PLAY_TIME 19
1552 #define ENTRY_SKILL_FIGHT 20
1553 #define ENTRY_SKILL_SHOOT 21
1554 #define ENTRY_SKILL_SAVING 22
1555 #define ENTRY_SKILL_STEALTH 23
1556 #define ENTRY_SKILL_PERCEP 24
1557 #define ENTRY_SKILL_SEARCH 25
1558 #define ENTRY_SKILL_DISARM 26
1559 #define ENTRY_SKILL_DEVICE 27
1560 #define ENTRY_SKILL_DIG 45
1561
1562
1563 #define ENTRY_BLOWS 28
1564 #define ENTRY_SHOTS 29
1565 #define ENTRY_AVG_DMG 30
1566 #define ENTRY_INFRA 31
1567
1568 #define ENTRY_NAME 32
1569 #define ENTRY_SEX 33
1570 #define ENTRY_RACE 34
1571 #define ENTRY_CLASS 35
1572 #define ENTRY_REALM 36
1573 #define ENTRY_PATRON 37
1574 #define ENTRY_AGE 38
1575 #define ENTRY_HEIGHT 39
1576 #define ENTRY_WEIGHT 40
1577 #define ENTRY_SOCIAL 41
1578 #define ENTRY_ALIGN 42
1579
1580 #define ENTRY_EXP_ANDR 43
1581 #define ENTRY_EXP_TO_ADV_ANDR 44
1582
1583
1584 static struct
1585 {
1586         int col;
1587         int row;
1588         int len;
1589         char header[20];
1590 } disp_player_line[]
1591 #ifdef JP
1592 = {
1593         { 1, 10, 25, "打撃修正(格闘)"},
1594         { 1, 10, 25, "打撃修正(両手)"},
1595         { 1, 10, 25, "打撃修正(右手)"},
1596         { 1, 10, 25, "打撃修正(左手)"},
1597         { 1, 11, 25, "打撃修正(左手)"},
1598         { 1, 11, 25, "打撃修正(右手)"},
1599         { 1, 11, 25, ""},
1600         { 1, 15, 25, "射撃攻撃修正"},
1601         { 1, 16, 25, "射撃武器倍率"},
1602         { 1, 20, 25, "加速"},
1603         { 1, 19, 25, "AC"},
1604         {29, 13, 21, "レベル"},
1605         {29, 14, 21, "経験値"},
1606         {29, 15, 21, "最大経験"},
1607         {29, 16, 21, "次レベル"},
1608         {29, 17, 21, "所持金"},
1609         {29, 19, 21, "日付"},
1610         {29, 10, 21, "HP"},
1611         {29, 11, 21, "MP"},
1612         {29, 20, 21, "プレイ時間"},
1613         {53, 10, -1, "打撃命中  :"},
1614         {53, 11, -1, "射撃命中  :"},
1615         {53, 12, -1, "魔法防御  :"},
1616         {53, 13, -1, "隠密行動  :"},
1617         {53, 15, -1, "知覚      :"},
1618         {53, 16, -1, "探索      :"},
1619         {53, 17, -1, "解除      :"},
1620         {53, 18, -1, "魔法道具  :"},
1621         { 1, 12, 25, "打撃回数"},
1622         { 1, 17, 25, "射撃回数"},
1623         { 1, 13, 25, "平均ダメージ"},
1624         {53, 20, -1, "赤外線視力:"},
1625         {26,  1, -1, "名前  : "},
1626         { 1,  3, -1, "性別     : "},
1627         { 1,  4, -1, "種族     : "},
1628         { 1,  5, -1, "職業     : "},
1629         { 1,  6, -1, "魔法     : "},
1630         { 1,  7, -1, "守護魔神 : "},
1631         {29,  3, 21, "年齢"},
1632         {29,  4, 21, "身長"},
1633         {29,  5, 21, "体重"},
1634         {29,  6, 21, "社会的地位"},
1635         {29,  7, 21, "属性"},
1636         {29, 14, 21, "強化度"},
1637         {29, 16, 21, "次レベル"},
1638         {53, 19, -1, "掘削      :" },
1639 };
1640 #else
1641 = {
1642         { 1, 10, 25, "Bare hand"},
1643         { 1, 10, 25, "Two hands"},
1644         { 1, 10, 25, "Right hand"},
1645         { 1, 10, 25, "Left hand"},
1646         { 1, 11, 25, "Left hand"},
1647         { 1, 11, 25, "Right hand"},
1648         { 1, 11, 25, "Posture"},
1649         { 1, 15, 25, "Shooting"},
1650         { 1, 16, 25, "Multiplier"},
1651         { 1, 20, 25, "Speed"},
1652         { 1, 19, 25, "AC"},
1653         {29, 13, 21, "Level"},
1654         {29, 14, 21, "Experience"},
1655         {29, 15, 21, "Max Exp"},
1656         {29, 16, 21, "Exp to Adv"},
1657         {29, 17, 21, "Gold"},
1658         {29, 19, 21, "Time"},
1659         {29, 10, 21, "Hit point"},
1660         {29, 11, 21, "SP (Mana)"},
1661         {29, 20, 21, "Play time"},
1662         {53, 10, -1, "Fighting   : "},
1663         {53, 11, -1, "Bows/Throw : "},
1664         {53, 12, -1, "SavingThrow: "},
1665         {53, 13, -1, "Stealth    : "},
1666         {53, 15, -1, "Perception : "},
1667         {53, 16, -1, "Searching  : "},
1668         {53, 17, -1, "Disarming  : "},
1669         {53, 18, -1, "MagicDevice: "},
1670         { 1, 12, 25, "Blows/Round"},
1671         { 1, 17, 25, "Shots/Round"},
1672         { 1, 13, 25, "AverageDmg/Rnd"},
1673         {53, 20, -1, "Infra-Vision: "},
1674         {26,  1, -1, "Name  : "},
1675         { 1,  3, -1, "Sex      : "},
1676         { 1,  4, -1, "Race     : "},
1677         { 1,  5, -1, "Class    : "},
1678         { 1,  6, -1, "Magic    : "},
1679         { 1,  7, -1, "Patron   : "},
1680         {29,  3, 21, "Age"},
1681         {29,  4, 21, "Height"},
1682         {29,  5, 21, "Weight"},
1683         {29,  6, 21, "Social Class"},
1684         {29,  7, 21, "Align"},
1685         {29, 14, 21, "Construction"},
1686         {29, 16, 21, "Const to Adv"},
1687         {53, 19, -1, "Digging    :" },
1688 };
1689 #endif
1690
1691 /*!
1692  * @brief プレイヤーのステータス1種を出力する
1693  * @param entry 項目ID
1694  * @param val 値を保管した文字列ポインタ
1695  * @param attr 項目表示の色
1696  * @return なし
1697  */
1698 static void display_player_one_line(int entry, concptr val, TERM_COLOR attr)
1699 {
1700         char buf[40];
1701
1702         int row = disp_player_line[entry].row;
1703         int col = disp_player_line[entry].col;
1704         int len = disp_player_line[entry].len;
1705         concptr head = disp_player_line[entry].header;
1706
1707         int head_len = strlen(head);
1708
1709         Term_putstr(col, row, -1, TERM_WHITE, head);
1710
1711         if (!val)
1712                 return;
1713
1714         if (len > 0)
1715         {
1716                 int val_len = len - head_len;
1717                 sprintf(buf, "%*.*s", val_len, val_len, val);
1718                 Term_putstr(col + head_len, row, -1, attr, buf);
1719         }
1720         else
1721         {
1722                 Term_putstr(col + head_len, row, -1, attr, val);
1723         }
1724
1725         return;
1726 }
1727
1728 /*!
1729  * @brief プレイヤーの打撃能力修正を表示する
1730  * @param hand 武器の装備部位ID
1731  * @param hand_entry 項目ID
1732  * @return なし
1733  */
1734 static void display_player_melee_bonus(int hand, int hand_entry)
1735 {
1736         char buf[160];
1737         HIT_PROB show_tohit = p_ptr->dis_to_h[hand];
1738         HIT_POINT show_todam = p_ptr->dis_to_d[hand];
1739         object_type *o_ptr = &p_ptr->inventory_list[INVEN_RARM + hand];
1740
1741         /* Hack -- add in weapon info if known */
1742         if (object_is_known(o_ptr)) show_tohit += o_ptr->to_h;
1743         if (object_is_known(o_ptr)) show_todam += o_ptr->to_d;
1744         
1745         show_tohit += p_ptr->skill_thn / BTH_PLUS_ADJ;
1746         
1747         /* Melee attacks */
1748         sprintf(buf, "(%+d,%+d)", (int)show_tohit, (int)show_todam);
1749
1750         /* Dump the bonuses to hit/dam */
1751         if (!has_melee_weapon(p_ptr, INVEN_RARM) && !has_melee_weapon(p_ptr, INVEN_LARM))
1752                 display_player_one_line(ENTRY_BARE_HAND, buf, TERM_L_BLUE);
1753         else if (p_ptr->ryoute)
1754                 display_player_one_line(ENTRY_TWO_HANDS, buf, TERM_L_BLUE);
1755         else
1756                 display_player_one_line(hand_entry, buf, TERM_L_BLUE);
1757 }
1758
1759
1760 /*!
1761  * @brief プレイヤーステータス表示の中央部分を表示するサブルーチン
1762  * Prints the following information on the screen.
1763  * @return なし
1764  */
1765 static void display_player_middle(player_type *creature_ptr)
1766 {
1767         char buf[160];
1768
1769         /* Base skill */
1770         HIT_PROB show_tohit = creature_ptr->dis_to_h_b;
1771         HIT_POINT show_todam = 0;
1772
1773         /* Range weapon */
1774         object_type *o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
1775
1776         int tmul = 0;
1777         int e;
1778
1779         if (creature_ptr->migite)
1780         {
1781                 display_player_melee_bonus(0, left_hander ? ENTRY_LEFT_HAND1 : ENTRY_RIGHT_HAND1);
1782         }
1783
1784         if (creature_ptr->hidarite)
1785         {
1786                 display_player_melee_bonus(1, left_hander ? ENTRY_RIGHT_HAND2: ENTRY_LEFT_HAND2);
1787         }
1788         else if ((creature_ptr->pclass == CLASS_MONK) && (empty_hands(creature_ptr, TRUE) & EMPTY_HAND_RARM))
1789         {
1790                 int i;
1791                 if (creature_ptr->special_defense & KAMAE_MASK)
1792                 {
1793                         for (i = 0; i < MAX_KAMAE; i++)
1794                         {
1795                                 if ((creature_ptr->special_defense >> i) & KAMAE_GENBU) break;
1796                         }
1797                         if (i < MAX_KAMAE)
1798                                 display_player_one_line(ENTRY_POSTURE, format(_("%sの構え", "%s form"), kamae_shurui[i].desc), TERM_YELLOW);
1799                 }
1800                 else
1801                                 display_player_one_line(ENTRY_POSTURE, _("構えなし", "none"), TERM_YELLOW);
1802         }
1803
1804         /* Apply weapon bonuses */
1805         if (object_is_known(o_ptr)) show_tohit += o_ptr->to_h;
1806         if (object_is_known(o_ptr)) show_todam += o_ptr->to_d;
1807
1808         if ((o_ptr->sval == SV_LIGHT_XBOW) || (o_ptr->sval == SV_HEAVY_XBOW))
1809                 show_tohit += creature_ptr->weapon_exp[0][o_ptr->sval] / 400;
1810         else
1811                 show_tohit += (creature_ptr->weapon_exp[0][o_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200;
1812         
1813         show_tohit += creature_ptr->skill_thb / BTH_PLUS_ADJ;
1814         
1815         /* Range attacks */
1816         display_player_one_line(ENTRY_SHOOT_HIT_DAM, format("(%+d,%+d)", show_tohit, show_todam), TERM_L_BLUE);
1817
1818         if (creature_ptr->inventory_list[INVEN_BOW].k_idx)
1819         {
1820                 tmul = bow_tmul(creature_ptr->inventory_list[INVEN_BOW].sval);
1821
1822                 /* Get extra "power" from "extra might" */
1823                 if (creature_ptr->xtra_might) tmul++;
1824
1825                 tmul = tmul * (100 + (int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128);
1826         }
1827
1828         /* shoot power */
1829         display_player_one_line(ENTRY_SHOOT_POWER, format("x%d.%02d", tmul/100, tmul%100), TERM_L_BLUE);
1830
1831         /* Dump the armor class */
1832         display_player_one_line(ENTRY_BASE_AC, format("[%d,%+d]", creature_ptr->dis_ac, creature_ptr->dis_to_a), TERM_L_BLUE);
1833
1834         /* Dump speed */
1835         {
1836                 int tmp_speed = 0;
1837                 TERM_COLOR attr;
1838                 int i;
1839
1840                 i = creature_ptr->pspeed-110;
1841
1842                 /* Hack -- Visually "undo" the Search Mode Slowdown */
1843                 if (creature_ptr->action == ACTION_SEARCH) i += 10;
1844
1845                 if (i > 0)
1846                 {
1847                         if (!creature_ptr->riding)
1848                                 attr = TERM_L_GREEN;
1849                         else
1850                                 attr = TERM_GREEN;
1851                 }
1852                 else if (i == 0)
1853                 {
1854                         if (!creature_ptr->riding)
1855                                 attr = TERM_L_BLUE;
1856                         else
1857                                 attr = TERM_GREEN;
1858                 }
1859                 else
1860                 {
1861                         if (!creature_ptr->riding)
1862                                 attr = TERM_L_UMBER;
1863                         else
1864                                 attr = TERM_RED;
1865                 }
1866
1867                 if (!creature_ptr->riding)
1868                 {
1869                         if (IS_FAST()) tmp_speed += 10;
1870                         if (creature_ptr->slow) tmp_speed -= 10;
1871                         if (creature_ptr->lightspeed) tmp_speed = 99;
1872                 }
1873                 else
1874                 {
1875                         if (MON_FAST(&current_floor_ptr->m_list[creature_ptr->riding])) tmp_speed += 10;
1876                         if (MON_SLOW(&current_floor_ptr->m_list[creature_ptr->riding])) tmp_speed -= 10;
1877                 }
1878
1879                 if (tmp_speed)
1880                 {
1881                         if (!creature_ptr->riding)
1882                                 sprintf(buf, "(%+d%+d)", i-tmp_speed, tmp_speed);
1883                         else
1884                                 sprintf(buf, _("乗馬中 (%+d%+d)", "Riding (%+d%+d)"), i-tmp_speed, tmp_speed);
1885
1886                         if (tmp_speed > 0)
1887                                 attr = TERM_YELLOW;
1888                         else
1889                                 attr = TERM_VIOLET;
1890                 }
1891                 else
1892                 {
1893                         if (!creature_ptr->riding)
1894                                 sprintf(buf, "(%+d)", i);
1895                         else
1896                                 sprintf(buf, _("乗馬中 (%+d)", "Riding (%+d)"), i);
1897                 }
1898         
1899                 display_player_one_line(ENTRY_SPEED, buf, attr);
1900         }
1901
1902         /* Dump character level */
1903         display_player_one_line(ENTRY_LEVEL, format("%d", creature_ptr->lev), TERM_L_GREEN);
1904
1905         /* Dump experience */
1906         if (creature_ptr->prace == RACE_ANDROID) e = ENTRY_EXP_ANDR;
1907         else e = ENTRY_CUR_EXP;
1908
1909         if (creature_ptr->exp >= creature_ptr->max_exp)
1910                 display_player_one_line(e, format("%ld", creature_ptr->exp), TERM_L_GREEN);
1911         else
1912                 display_player_one_line(e, format("%ld", creature_ptr->exp), TERM_YELLOW);
1913
1914         /* Dump max experience */
1915         if (creature_ptr->prace == RACE_ANDROID)
1916                 /* Nothing */;
1917         else
1918                 display_player_one_line(ENTRY_MAX_EXP, format("%ld", creature_ptr->max_exp), TERM_L_GREEN);
1919
1920         /* Dump exp to advance */
1921         if (creature_ptr->prace == RACE_ANDROID) e = ENTRY_EXP_TO_ADV_ANDR;
1922         else e = ENTRY_EXP_TO_ADV;
1923
1924         if (creature_ptr->lev >= PY_MAX_LEVEL)
1925                 display_player_one_line(e, "*****", TERM_L_GREEN);
1926         else if (creature_ptr->prace == RACE_ANDROID)
1927                 display_player_one_line(e, format("%ld", (s32b)(player_exp_a[creature_ptr->lev - 1] * creature_ptr->expfact / 100L)), TERM_L_GREEN);
1928         else
1929                 display_player_one_line(e, format("%ld", (s32b)(player_exp[creature_ptr->lev - 1] * creature_ptr->expfact / 100L)), TERM_L_GREEN);
1930
1931         /* Dump gold */
1932         display_player_one_line(ENTRY_GOLD, format("%ld", creature_ptr->au), TERM_L_GREEN);
1933
1934         /* Dump Day */
1935         {
1936                 int day, hour, min;
1937                 extract_day_hour_min(&day, &hour, &min);
1938
1939                 if (day < MAX_DAYS) sprintf(buf, _("%d日目 %2d:%02d", "Day %d %2d:%02d"), day, hour, min);
1940                 else sprintf(buf, _("*****日目 %2d:%02d", "Day ***** %2d:%02d"), hour, min);
1941         }
1942         display_player_one_line(ENTRY_DAY, buf, TERM_L_GREEN);
1943
1944         /* Dump hit point */
1945         if (creature_ptr->chp >= creature_ptr->mhp) 
1946                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp , creature_ptr->mhp), TERM_L_GREEN);
1947         else if (creature_ptr->chp > (creature_ptr->mhp * hitpoint_warn) / 10) 
1948                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp , creature_ptr->mhp), TERM_YELLOW);
1949         else
1950                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp , creature_ptr->mhp), TERM_RED);
1951
1952         /* Dump mana power */
1953         if (creature_ptr->csp >= creature_ptr->msp) 
1954                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp , creature_ptr->msp), TERM_L_GREEN);
1955         else if (creature_ptr->csp > (creature_ptr->msp * mana_warn) / 10) 
1956                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp , creature_ptr->msp), TERM_YELLOW);
1957         else
1958                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp , creature_ptr->msp), TERM_RED);
1959
1960         /* Dump play time */
1961         display_player_one_line(ENTRY_PLAY_TIME, format("%.2lu:%.2lu:%.2lu", current_world_ptr->play_time/(60*60), (current_world_ptr->play_time/60)%60, current_world_ptr->play_time%60), TERM_L_GREEN);
1962 }
1963
1964
1965 /*
1966  * Hack -- pass color info around this file
1967  */
1968 static TERM_COLOR likert_color = TERM_WHITE;
1969
1970
1971 /*!
1972  * @brief 技能ランクの表示基準を定める
1973  * Returns a "rating" of x depending on y
1974  * @param x 技能値
1975  * @param y 技能値に対するランク基準比
1976  * @return なし
1977  */
1978 static concptr likert(int x, int y)
1979 {
1980         static char dummy[20] = "", dummy2[20] = "";
1981         memset(dummy, 0, strlen(dummy));
1982         memset(dummy2, 0, strlen(dummy2));
1983         if (y <= 0) y = 1;
1984
1985         if(show_actual_value)
1986         {
1987                 sprintf(dummy, "%3d-", x);
1988         }
1989
1990         /* Negative value */
1991         if (x < 0)
1992         {
1993                 likert_color = TERM_L_DARK;
1994                 strcat(dummy, _("最低", "Very Bad"));
1995         }
1996         else
1997         {
1998
1999                 /* Analyze the value */
2000                 switch ((x / y))
2001                 {
2002                 case 0:
2003                 case 1:
2004                         likert_color = TERM_RED;
2005                         strcat(dummy, _("悪い", "Bad"));
2006                         break;
2007                 case 2:
2008                         likert_color = TERM_L_RED;
2009                         strcat(dummy, _("劣る", "Poor"));
2010                         break;
2011
2012                 case 3:
2013                 case 4:
2014                         likert_color = TERM_ORANGE;
2015                         strcat(dummy, _("普通", "Fair"));
2016                         break;
2017
2018                 case 5:
2019                         likert_color = TERM_YELLOW;
2020                         strcat(dummy, _("良い", "Good"));
2021                         break;
2022
2023                 case 6:
2024                         likert_color = TERM_YELLOW;
2025                         strcat(dummy, _("大変良い", "Very Good"));
2026                         break;
2027
2028                 case 7:
2029                 case 8:
2030                         likert_color = TERM_L_GREEN;
2031                         strcat(dummy, _("卓越", "Excellent"));
2032                         break;
2033
2034                 case 9:
2035                 case 10:
2036                 case 11:
2037                 case 12:
2038                 case 13:
2039                         likert_color = TERM_GREEN;
2040                         strcat(dummy, _("超越", "Superb"));
2041                         break;
2042
2043                 case 14:
2044                 case 15:
2045                 case 16:
2046                 case 17:
2047                         likert_color = TERM_BLUE;
2048                         strcat(dummy, _("英雄的", "Heroic"));
2049                         break;
2050
2051                 default:
2052                         likert_color = TERM_VIOLET;
2053                         sprintf(dummy2, _("伝説的[%d]", "Legendary[%d]"),
2054                                 (int)((((x / y) - 17) * 5) / 2));
2055                         strcat(dummy, dummy2);
2056
2057                         break;
2058                 }
2059         }
2060         return dummy;
2061
2062 }
2063
2064
2065 /*!
2066  * @brief プレイヤーステータスの1ページ目各種詳細をまとめて表示するサブルーチン
2067  * Prints ratings on certain abilities
2068  * @return なし
2069  * @details
2070  * This code is "imitated" elsewhere to "dump" a character sheet.
2071  */
2072 static void display_player_various(void)
2073 {
2074         int         tmp, damage[2], to_h[2], blows1, blows2, i, basedam;
2075         int                     xthn, xthb, xfos, xsrh;
2076         int                     xdis, xdev, xsav, xstl;
2077         int                     xdig;
2078         concptr         desc;
2079         int         muta_att = 0;
2080         BIT_FLAGS flgs[TR_FLAG_SIZE];
2081         int             shots, shot_frac;
2082         bool dokubari;
2083
2084         object_type *o_ptr;
2085
2086         if (p_ptr->muta2 & MUT2_HORNS)     muta_att++;
2087         if (p_ptr->muta2 & MUT2_SCOR_TAIL) muta_att++;
2088         if (p_ptr->muta2 & MUT2_BEAK)      muta_att++;
2089         if (p_ptr->muta2 & MUT2_TRUNK)     muta_att++;
2090         if (p_ptr->muta2 & MUT2_TENTACLES) muta_att++;
2091
2092         xthn = p_ptr->skill_thn + (p_ptr->to_h_m * BTH_PLUS_ADJ);
2093
2094         /* Shooting Skill (with current bow and normal missile) */
2095         o_ptr = &p_ptr->inventory_list[INVEN_BOW];
2096         tmp = p_ptr->to_h_b + o_ptr->to_h;
2097         xthb = p_ptr->skill_thb + (tmp * BTH_PLUS_ADJ);
2098
2099         /* If the player is wielding one? */
2100         if (o_ptr->k_idx)
2101         {
2102                 ENERGY energy_fire = bow_energy(o_ptr->sval);
2103
2104                 /* Calculate shots per round */
2105                 shots = p_ptr->num_fire * 100;
2106                 shot_frac = (shots * 100 / energy_fire) % 100;
2107                 shots = shots / energy_fire;
2108                 if (o_ptr->name1 == ART_CRIMSON)
2109                 {
2110                         shots = 1;
2111                         shot_frac = 0;
2112                         if (p_ptr->pclass == CLASS_ARCHER)
2113                         {
2114                                 /* Extra shot at level 10 */
2115                                 if (p_ptr->lev >= 10) shots++;
2116
2117                                 /* Extra shot at level 30 */
2118                                 if (p_ptr->lev >= 30) shots++;
2119
2120                                 /* Extra shot at level 45 */
2121                                 if (p_ptr->lev >= 45) shots++;
2122                         }
2123                 }
2124         }
2125         else
2126         {
2127                 shots = 0;
2128                 shot_frac = 0;
2129         }
2130
2131         for(i = 0; i < 2; i++)
2132         {
2133                 damage[i] = p_ptr->dis_to_d[i] * 100;
2134                 if (((p_ptr->pclass == CLASS_MONK) || (p_ptr->pclass == CLASS_FORCETRAINER)) && (empty_hands(p_ptr, TRUE) & EMPTY_HAND_RARM))
2135                 {
2136                         PLAYER_LEVEL level = p_ptr->lev;
2137                         if (i)
2138                         {
2139                                 damage[i] = 0;
2140                                 break;
2141                         }
2142                         if (p_ptr->pclass == CLASS_FORCETRAINER) level = MAX(1, level - 3);
2143                         if (p_ptr->special_defense & KAMAE_BYAKKO)
2144                                 basedam = monk_ave_damage[level][1];
2145                         else if (p_ptr->special_defense & (KAMAE_GENBU | KAMAE_SUZAKU))
2146                                 basedam = monk_ave_damage[level][2];
2147                         else
2148                                 basedam = monk_ave_damage[level][0];
2149                 }
2150                 else
2151                 {
2152                         o_ptr = &p_ptr->inventory_list[INVEN_RARM + i];
2153
2154                         /* Average damage per round */
2155                         if (o_ptr->k_idx)
2156                         {
2157                                 to_h[i] = 0;
2158                                 dokubari = FALSE;                               
2159                                 
2160                                 if((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) dokubari = TRUE;
2161                                 if (object_is_known(o_ptr))
2162                                 { 
2163                                         damage[i] += o_ptr->to_d * 100;
2164                                         to_h[i] += o_ptr->to_h;
2165                                 }
2166                                 basedam = ((o_ptr->dd + p_ptr->to_dd[i]) * (o_ptr->ds + p_ptr->to_ds[i] + 1)) * 50;
2167                                 object_flags_known(o_ptr, flgs);
2168                                                                 
2169                                 basedam = calc_expect_crit(o_ptr->weight, to_h[i], basedam, p_ptr->dis_to_h[i], dokubari);
2170                                 if ((o_ptr->ident & IDENT_MENTAL) && ((o_ptr->name1 == ART_VORPAL_BLADE) || (o_ptr->name1 == ART_CHAINSWORD)))
2171                                 {
2172                                         /* vorpal blade */
2173                                         basedam *= 5;
2174                                         basedam /= 3;
2175                                 }
2176                                 else if (have_flag(flgs, TR_VORPAL))
2177                                 {
2178                                         /* vorpal flag only */
2179                                         basedam *= 11;
2180                                         basedam /= 9;
2181                                 }
2182                                 if ((p_ptr->pclass != CLASS_SAMURAI) && have_flag(flgs, TR_FORCE_WEAPON) && (p_ptr->csp > (o_ptr->dd * o_ptr->ds / 5)))
2183                                         basedam = basedam * 7 / 2;
2184                         }
2185                         else basedam = 0;
2186                 }
2187                 damage[i] += basedam;
2188                 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DOKUBARI)) damage[i] = 1;
2189                 if (damage[i] < 0) damage[i] = 0;
2190         }
2191         blows1 = p_ptr->migite ? p_ptr->num_blow[0]: 0;
2192         blows2 = p_ptr->hidarite ? p_ptr->num_blow[1] : 0;
2193
2194         /* Basic abilities */
2195
2196         xdis = p_ptr->skill_dis;
2197         xdev = p_ptr->skill_dev;
2198         xsav = p_ptr->skill_sav;
2199         xstl = p_ptr->skill_stl;
2200         xsrh = p_ptr->skill_srh;
2201         xfos = p_ptr->skill_fos;
2202         xdig = p_ptr->skill_dig;
2203
2204
2205         desc = likert(xthn, 12);
2206         display_player_one_line(ENTRY_SKILL_FIGHT, desc, likert_color);
2207
2208         desc = likert(xthb, 12);
2209         display_player_one_line(ENTRY_SKILL_SHOOT, desc, likert_color);
2210
2211         desc = likert(xsav, 7);
2212         display_player_one_line(ENTRY_SKILL_SAVING, desc, likert_color);
2213
2214         /* Hack -- 0 is "minimum stealth value", so print "Very Bad" */
2215         desc = likert((xstl > 0) ? xstl : -1, 1);
2216         display_player_one_line(ENTRY_SKILL_STEALTH, desc, likert_color);
2217
2218         desc = likert(xfos, 6);
2219         display_player_one_line(ENTRY_SKILL_PERCEP, desc, likert_color);
2220
2221         desc = likert(xsrh, 6);
2222         display_player_one_line(ENTRY_SKILL_SEARCH, desc, likert_color);
2223
2224         desc = likert(xdis, 8);
2225         display_player_one_line(ENTRY_SKILL_DISARM, desc, likert_color);
2226
2227         desc = likert(xdev, 6);
2228         display_player_one_line(ENTRY_SKILL_DEVICE, desc, likert_color);
2229
2230         desc = likert(xdev, 6);
2231         display_player_one_line(ENTRY_SKILL_DEVICE, desc, likert_color);
2232
2233         desc = likert(xdig, 4);
2234         display_player_one_line(ENTRY_SKILL_DIG, desc, likert_color);
2235
2236         if (!muta_att)
2237                 display_player_one_line(ENTRY_BLOWS, format("%d+%d", blows1, blows2), TERM_L_BLUE);
2238         else
2239                 display_player_one_line(ENTRY_BLOWS, format("%d+%d+%d", blows1, blows2, muta_att), TERM_L_BLUE);
2240
2241         display_player_one_line(ENTRY_SHOTS, format("%d.%02d", shots, shot_frac), TERM_L_BLUE);
2242
2243
2244         if ((damage[0]+damage[1]) == 0)
2245                 desc = "nil!";
2246         else
2247                 desc = format("%d+%d", blows1 * damage[0] / 100, blows2 * damage[1] / 100);
2248
2249         display_player_one_line(ENTRY_AVG_DMG, desc, TERM_L_BLUE);
2250
2251         display_player_one_line(ENTRY_INFRA, format("%d feet", p_ptr->see_infra * 10), TERM_WHITE);
2252 }
2253
2254
2255
2256 /*!
2257  * @brief プレイヤーの職業、種族に応じた耐性フラグを返す
2258  * Prints ratings on certain abilities
2259  * @param flgs フラグを保管する配列
2260  * @return なし
2261  * @details
2262  * Obtain the "flags" for the player as if he was an item
2263  * @todo
2264  * xtra1.c周りと多重実装になっているのを何とかする
2265  */
2266 static void player_flags(BIT_FLAGS flgs[TR_FLAG_SIZE])
2267 {
2268         int i;
2269         for (i = 0; i < TR_FLAG_SIZE; i++)
2270                 flgs[i] = 0L;
2271
2272         /* Classes */
2273         switch (p_ptr->pclass)
2274         {
2275         case CLASS_WARRIOR:
2276                 if (p_ptr->lev > 44)
2277                         add_flag(flgs, TR_REGEN);
2278         case CLASS_SAMURAI:
2279                 if (p_ptr->lev > 29)
2280                         add_flag(flgs, TR_RES_FEAR);
2281                 break;
2282         case CLASS_PALADIN:
2283                 if (p_ptr->lev > 39)
2284                         add_flag(flgs, TR_RES_FEAR);
2285                 break;
2286         case CLASS_CHAOS_WARRIOR:
2287                 if (p_ptr->lev > 29)
2288                         add_flag(flgs, TR_RES_CHAOS);
2289                 if (p_ptr->lev > 39)
2290                         add_flag(flgs, TR_RES_FEAR);
2291                 break;
2292         case CLASS_MONK:
2293         case CLASS_FORCETRAINER:
2294                 if ((p_ptr->lev > 9) && !heavy_armor(p_ptr))
2295                         add_flag(flgs, TR_SPEED);
2296                 if ((p_ptr->lev>24) && !heavy_armor(p_ptr))
2297                         add_flag(flgs, TR_FREE_ACT);
2298                 break;
2299         case CLASS_NINJA:
2300                 if (heavy_armor(p_ptr))
2301                         add_flag(flgs, TR_SPEED);
2302                 else
2303                 {
2304                         if ((!p_ptr->inventory_list[INVEN_RARM].k_idx || p_ptr->migite) &&
2305                             (!p_ptr->inventory_list[INVEN_LARM].k_idx || p_ptr->hidarite))
2306                                 add_flag(flgs, TR_SPEED);
2307                         if (p_ptr->lev>24)
2308                                 add_flag(flgs, TR_FREE_ACT);
2309                 }
2310                 add_flag(flgs, TR_SLOW_DIGEST);
2311                 add_flag(flgs, TR_RES_FEAR);
2312                 if (p_ptr->lev > 19) add_flag(flgs, TR_RES_POIS);
2313                 if (p_ptr->lev > 24) add_flag(flgs, TR_SUST_DEX);
2314                 if (p_ptr->lev > 29) add_flag(flgs, TR_SEE_INVIS);
2315                 break;
2316         case CLASS_MINDCRAFTER:
2317                 if (p_ptr->lev > 9)
2318                         add_flag(flgs, TR_RES_FEAR);
2319                 if (p_ptr->lev > 19)
2320                         add_flag(flgs, TR_SUST_WIS);
2321                 if (p_ptr->lev > 29)
2322                         add_flag(flgs, TR_RES_CONF);
2323                 if (p_ptr->lev > 39)
2324                         add_flag(flgs, TR_TELEPATHY);
2325                 break;
2326         case CLASS_BARD:
2327                 add_flag(flgs, TR_RES_SOUND);
2328                 break;
2329         case CLASS_BERSERKER:
2330                 add_flag(flgs, TR_SUST_STR);
2331                 add_flag(flgs, TR_SUST_DEX);
2332                 add_flag(flgs, TR_SUST_CON);
2333                 add_flag(flgs, TR_REGEN);
2334                 add_flag(flgs, TR_FREE_ACT);
2335                 add_flag(flgs, TR_SPEED);
2336                 if (p_ptr->lev > 39) add_flag(flgs, TR_REFLECT);
2337                 break;
2338         case CLASS_MIRROR_MASTER:
2339                 if(p_ptr->lev > 39)add_flag(flgs, TR_REFLECT);
2340                 break;
2341         default:
2342                 break; /* Do nothing */
2343         }
2344
2345         /* Races */
2346         if (p_ptr->mimic_form)
2347         {
2348                 switch(p_ptr->mimic_form)
2349                 {
2350                 case MIMIC_DEMON:
2351                         add_flag(flgs, TR_HOLD_EXP);
2352                         add_flag(flgs, TR_RES_CHAOS);
2353                         add_flag(flgs, TR_RES_NETHER);
2354                         add_flag(flgs, TR_RES_FIRE);
2355                         add_flag(flgs, TR_SEE_INVIS);
2356                         add_flag(flgs, TR_SPEED);
2357                         break;
2358                 case MIMIC_DEMON_LORD:
2359                         add_flag(flgs, TR_HOLD_EXP);
2360                         add_flag(flgs, TR_RES_CHAOS);
2361                         add_flag(flgs, TR_RES_NETHER);
2362                         add_flag(flgs, TR_RES_FIRE);
2363                         add_flag(flgs, TR_RES_COLD);
2364                         add_flag(flgs, TR_RES_ELEC);
2365                         add_flag(flgs, TR_RES_ACID);
2366                         add_flag(flgs, TR_RES_POIS);
2367                         add_flag(flgs, TR_RES_CONF);
2368                         add_flag(flgs, TR_RES_DISEN);
2369                         add_flag(flgs, TR_RES_NEXUS);
2370                         add_flag(flgs, TR_RES_FEAR);
2371                         add_flag(flgs, TR_IM_FIRE);
2372                         add_flag(flgs, TR_SH_FIRE);
2373                         add_flag(flgs, TR_SEE_INVIS);
2374                         add_flag(flgs, TR_TELEPATHY);
2375                         add_flag(flgs, TR_LEVITATION);
2376                         add_flag(flgs, TR_SPEED);
2377                         break;
2378                 case MIMIC_VAMPIRE:
2379                         add_flag(flgs, TR_HOLD_EXP);
2380                         add_flag(flgs, TR_RES_DARK);
2381                         add_flag(flgs, TR_RES_NETHER);
2382                         if (p_ptr->pclass != CLASS_NINJA) add_flag(flgs, TR_LITE_1);
2383                         add_flag(flgs, TR_RES_POIS);
2384                         add_flag(flgs, TR_RES_COLD);
2385                         add_flag(flgs, TR_SEE_INVIS);
2386                         add_flag(flgs, TR_SPEED);
2387                         break;
2388                 }
2389         }
2390         else
2391         {
2392         switch (p_ptr->prace)
2393         {
2394         case RACE_ELF:
2395                 add_flag(flgs, TR_RES_LITE);
2396                 break;
2397         case RACE_HOBBIT:
2398                 add_flag(flgs, TR_HOLD_EXP);
2399                 break;
2400         case RACE_GNOME:
2401                 add_flag(flgs, TR_FREE_ACT);
2402                 break;
2403         case RACE_DWARF:
2404                 add_flag(flgs, TR_RES_BLIND);
2405                 break;
2406         case RACE_HALF_ORC:
2407                 add_flag(flgs, TR_RES_DARK);
2408                 break;
2409         case RACE_HALF_TROLL:
2410                 add_flag(flgs, TR_SUST_STR);
2411                 if (p_ptr->lev > 14)
2412                 {
2413                         add_flag(flgs, TR_REGEN);
2414                         if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_BERSERKER))
2415                         {
2416                                 add_flag(flgs, TR_SLOW_DIGEST);
2417                                 /*
2418                                  * Let's not make Regeneration a disadvantage
2419                                  * for the poor warriors who can never learn
2420                                  * a spell that satisfies hunger (actually
2421                                  * neither can rogues, but half-trolls are not
2422                                  * supposed to play rogues)
2423                                  */
2424                         }
2425                 }
2426                 break;
2427         case RACE_AMBERITE:
2428                 add_flag(flgs, TR_SUST_CON);
2429                 add_flag(flgs, TR_REGEN); /* Amberites heal fast */
2430                 break;
2431         case RACE_HIGH_ELF:
2432                 add_flag(flgs, TR_RES_LITE);
2433                 add_flag(flgs, TR_SEE_INVIS);
2434                 break;
2435         case RACE_BARBARIAN:
2436                 add_flag(flgs, TR_RES_FEAR);
2437                 break;
2438         case RACE_HALF_OGRE:
2439                 add_flag(flgs, TR_SUST_STR);
2440                 add_flag(flgs, TR_RES_DARK);
2441                 break;
2442         case RACE_HALF_GIANT:
2443                 add_flag(flgs, TR_RES_SHARDS);
2444                 add_flag(flgs, TR_SUST_STR);
2445                 break;
2446         case RACE_HALF_TITAN:
2447                 add_flag(flgs, TR_RES_CHAOS);
2448                 break;
2449         case RACE_CYCLOPS:
2450                 add_flag(flgs, TR_RES_SOUND);
2451                 break;
2452         case RACE_YEEK:
2453                 add_flag(flgs, TR_RES_ACID);
2454                 if (p_ptr->lev > 19)
2455                         add_flag(flgs, TR_IM_ACID);
2456                 break;
2457         case RACE_KLACKON:
2458                 add_flag(flgs, TR_RES_CONF);
2459                 add_flag(flgs, TR_RES_ACID);
2460                 if (p_ptr->lev > 9)
2461                         add_flag(flgs, TR_SPEED);
2462                 break;
2463         case RACE_KOBOLD:
2464                 add_flag(flgs, TR_RES_POIS);
2465                 break;
2466         case RACE_NIBELUNG:
2467                 add_flag(flgs, TR_RES_DISEN);
2468                 add_flag(flgs, TR_RES_DARK);
2469                 break;
2470         case RACE_DARK_ELF:
2471                 add_flag(flgs, TR_RES_DARK);
2472                 if (p_ptr->lev > 19)
2473                         add_flag(flgs, TR_SEE_INVIS);
2474                 break;
2475         case RACE_DRACONIAN:
2476                 add_flag(flgs, TR_LEVITATION);
2477                 if (p_ptr->lev > 4)
2478                         add_flag(flgs, TR_RES_FIRE);
2479                 if (p_ptr->lev > 9)
2480                         add_flag(flgs, TR_RES_COLD);
2481                 if (p_ptr->lev > 14)
2482                         add_flag(flgs, TR_RES_ACID);
2483                 if (p_ptr->lev > 19)
2484                         add_flag(flgs, TR_RES_ELEC);
2485                 if (p_ptr->lev > 34)
2486                         add_flag(flgs, TR_RES_POIS);
2487                 break;
2488         case RACE_MIND_FLAYER:
2489                 add_flag(flgs, TR_SUST_INT);
2490                 add_flag(flgs, TR_SUST_WIS);
2491                 if (p_ptr->lev > 14)
2492                         add_flag(flgs, TR_SEE_INVIS);
2493                 if (p_ptr->lev > 29)
2494                         add_flag(flgs, TR_TELEPATHY);
2495                 break;
2496         case RACE_IMP:
2497                 add_flag(flgs, TR_RES_FIRE);
2498                 if (p_ptr->lev > 9)
2499                         add_flag(flgs, TR_SEE_INVIS);
2500                 break;
2501         case RACE_GOLEM:
2502                 add_flag(flgs, TR_SEE_INVIS);
2503                 add_flag(flgs, TR_FREE_ACT);
2504                 add_flag(flgs, TR_RES_POIS);
2505                 add_flag(flgs, TR_SLOW_DIGEST);
2506                 if (p_ptr->lev > 34)
2507                         add_flag(flgs, TR_HOLD_EXP);
2508                 break;
2509         case RACE_SKELETON:
2510                 add_flag(flgs, TR_SEE_INVIS);
2511                 add_flag(flgs, TR_RES_SHARDS);
2512                 add_flag(flgs, TR_HOLD_EXP);
2513                 add_flag(flgs, TR_RES_POIS);
2514                 if (p_ptr->lev > 9)
2515                         add_flag(flgs, TR_RES_COLD);
2516                 break;
2517         case RACE_ZOMBIE:
2518                 add_flag(flgs, TR_SEE_INVIS);
2519                 add_flag(flgs, TR_HOLD_EXP);
2520                 add_flag(flgs, TR_RES_NETHER);
2521                 add_flag(flgs, TR_RES_POIS);
2522                 add_flag(flgs, TR_SLOW_DIGEST);
2523                 if (p_ptr->lev > 4)
2524                         add_flag(flgs, TR_RES_COLD);
2525                 break;
2526         case RACE_VAMPIRE:
2527                 add_flag(flgs, TR_HOLD_EXP);
2528                 add_flag(flgs, TR_RES_DARK);
2529                 add_flag(flgs, TR_RES_NETHER);
2530                 if (p_ptr->pclass != CLASS_NINJA) add_flag(flgs, TR_LITE_1);
2531                 add_flag(flgs, TR_RES_POIS);
2532                 add_flag(flgs, TR_RES_COLD);
2533                 break;
2534         case RACE_SPECTRE:
2535                 add_flag(flgs, TR_LEVITATION);
2536                 add_flag(flgs, TR_FREE_ACT);
2537                 add_flag(flgs, TR_RES_COLD);
2538                 add_flag(flgs, TR_SEE_INVIS);
2539                 add_flag(flgs, TR_HOLD_EXP);
2540                 add_flag(flgs, TR_RES_NETHER);
2541                 add_flag(flgs, TR_RES_POIS);
2542                 add_flag(flgs, TR_SLOW_DIGEST);
2543                 /* XXX pass_wall */
2544                 if (p_ptr->lev > 34)
2545                         add_flag(flgs, TR_TELEPATHY);
2546                 break;
2547         case RACE_SPRITE:
2548                 add_flag(flgs, TR_RES_LITE);
2549                 add_flag(flgs, TR_LEVITATION);
2550                 if (p_ptr->lev > 9)
2551                         add_flag(flgs, TR_SPEED);
2552                 break;
2553         case RACE_BEASTMAN:
2554                 add_flag(flgs, TR_RES_SOUND);
2555                 add_flag(flgs, TR_RES_CONF);
2556                 break;
2557         case RACE_ANGEL:
2558                 add_flag(flgs, TR_LEVITATION);
2559                 add_flag(flgs, TR_SEE_INVIS);
2560                 break;
2561         case RACE_DEMON:
2562                 add_flag(flgs, TR_RES_FIRE);
2563                 add_flag(flgs, TR_RES_NETHER);
2564                 add_flag(flgs, TR_HOLD_EXP);
2565                 if (p_ptr->lev > 9)
2566                         add_flag(flgs, TR_SEE_INVIS);
2567                 break;
2568         case RACE_DUNADAN:
2569                 add_flag(flgs, TR_SUST_CON);
2570                 break;
2571         case RACE_S_FAIRY:
2572                 add_flag(flgs, TR_LEVITATION);
2573                 break;
2574         case RACE_KUTAR:
2575                 add_flag(flgs, TR_RES_CONF);
2576                 break;
2577         case RACE_ANDROID:
2578                 add_flag(flgs, TR_FREE_ACT);
2579                 add_flag(flgs, TR_RES_POIS);
2580                 add_flag(flgs, TR_SLOW_DIGEST);
2581                 add_flag(flgs, TR_HOLD_EXP);
2582                 break;
2583         default:
2584                 ; /* Do nothing */
2585         }
2586         }
2587
2588         /* Mutations */
2589         if (p_ptr->muta3)
2590         {
2591                 if (p_ptr->muta3 & MUT3_FLESH_ROT)
2592                 {
2593                         remove_flag(flgs, TR_REGEN);
2594                 }
2595
2596                 if ((p_ptr->muta3 & MUT3_XTRA_FAT) ||
2597                         (p_ptr->muta3 & MUT3_XTRA_LEGS) ||
2598                         (p_ptr->muta3 & MUT3_SHORT_LEG))
2599                 {
2600                         add_flag(flgs, TR_SPEED);
2601                 }
2602
2603                 if (p_ptr->muta3  & MUT3_ELEC_TOUC)
2604                 {
2605                         add_flag(flgs, TR_SH_ELEC);
2606                 }
2607
2608                 if (p_ptr->muta3 & MUT3_FIRE_BODY)
2609                 {
2610                         add_flag(flgs, TR_SH_FIRE);
2611                         add_flag(flgs, TR_LITE_1);
2612                 }
2613
2614                 if (p_ptr->muta3 & MUT3_WINGS)
2615                 {
2616                         add_flag(flgs, TR_LEVITATION);
2617                 }
2618
2619                 if (p_ptr->muta3 & MUT3_FEARLESS)
2620                 {
2621                         add_flag(flgs, TR_RES_FEAR);
2622                 }
2623
2624                 if (p_ptr->muta3 & MUT3_REGEN)
2625                 {
2626                         add_flag(flgs, TR_REGEN);
2627                 }
2628
2629                 if (p_ptr->muta3 & MUT3_ESP)
2630                 {
2631                         add_flag(flgs, TR_TELEPATHY);
2632                 }
2633
2634                 if (p_ptr->muta3 & MUT3_MOTION)
2635                 {
2636                         add_flag(flgs, TR_FREE_ACT);
2637                 }
2638         }
2639
2640         if (p_ptr->pseikaku == SEIKAKU_SEXY)
2641                 add_flag(flgs, TR_AGGRAVATE);
2642         if (p_ptr->pseikaku == SEIKAKU_CHARGEMAN)
2643                 add_flag(flgs, TR_RES_CONF);
2644         if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
2645         {
2646                 add_flag(flgs, TR_RES_BLIND);
2647                 add_flag(flgs, TR_RES_CONF);
2648                 add_flag(flgs, TR_HOLD_EXP);
2649                 if (p_ptr->pclass != CLASS_NINJA) add_flag(flgs, TR_LITE_1);
2650                 if (p_ptr->lev > 9)
2651                         add_flag(flgs, TR_SPEED);
2652         }
2653         if (p_ptr->special_defense & KATA_FUUJIN)
2654                 add_flag(flgs, TR_REFLECT);
2655         if (p_ptr->special_defense & KAMAE_GENBU)
2656                 add_flag(flgs, TR_REFLECT);
2657         if (p_ptr->special_defense & KAMAE_SUZAKU)
2658                 add_flag(flgs, TR_LEVITATION);
2659         if (p_ptr->special_defense & KAMAE_SEIRYU)
2660         {
2661                 add_flag(flgs, TR_RES_FIRE);
2662                 add_flag(flgs, TR_RES_COLD);
2663                 add_flag(flgs, TR_RES_ACID);
2664                 add_flag(flgs, TR_RES_ELEC);
2665                 add_flag(flgs, TR_RES_POIS);
2666                 add_flag(flgs, TR_LEVITATION);
2667                 add_flag(flgs, TR_SH_FIRE);
2668                 add_flag(flgs, TR_SH_ELEC);
2669                 add_flag(flgs, TR_SH_COLD);
2670         }
2671         if (p_ptr->special_defense & KATA_MUSOU)
2672         {
2673                 add_flag(flgs, TR_RES_FEAR);
2674                 add_flag(flgs, TR_RES_LITE);
2675                 add_flag(flgs, TR_RES_DARK);
2676                 add_flag(flgs, TR_RES_BLIND);
2677                 add_flag(flgs, TR_RES_CONF);
2678                 add_flag(flgs, TR_RES_SOUND);
2679                 add_flag(flgs, TR_RES_SHARDS);
2680                 add_flag(flgs, TR_RES_NETHER);
2681                 add_flag(flgs, TR_RES_NEXUS);
2682                 add_flag(flgs, TR_RES_CHAOS);
2683                 add_flag(flgs, TR_RES_DISEN);
2684                 add_flag(flgs, TR_REFLECT);
2685                 add_flag(flgs, TR_HOLD_EXP);
2686                 add_flag(flgs, TR_FREE_ACT);
2687                 add_flag(flgs, TR_SH_FIRE);
2688                 add_flag(flgs, TR_SH_ELEC);
2689                 add_flag(flgs, TR_SH_COLD);
2690                 add_flag(flgs, TR_LEVITATION);
2691                 add_flag(flgs, TR_LITE_1);
2692                 add_flag(flgs, TR_SEE_INVIS);
2693                 add_flag(flgs, TR_TELEPATHY);
2694                 add_flag(flgs, TR_SLOW_DIGEST);
2695                 add_flag(flgs, TR_REGEN);
2696                 add_flag(flgs, TR_SUST_STR);
2697                 add_flag(flgs, TR_SUST_INT);
2698                 add_flag(flgs, TR_SUST_WIS);
2699                 add_flag(flgs, TR_SUST_DEX);
2700                 add_flag(flgs, TR_SUST_CON);
2701                 add_flag(flgs, TR_SUST_CHR);
2702         }
2703 }
2704
2705 /*!
2706  * @brief プレイヤーの一時的魔法効果による耐性を返す
2707  * Prints ratings on certain abilities
2708  * @param flgs フラグを保管する配列
2709  * @return なし
2710  * @todo
2711  * xtra1.c周りと多重実装になっているのを何とかする
2712  */
2713 static void tim_player_flags(player_type *creature_ptr, BIT_FLAGS flgs[TR_FLAG_SIZE])
2714 {
2715         int i;
2716         for (i = 0; i < TR_FLAG_SIZE; i++)
2717                 flgs[i] = 0L;
2718
2719         if (IS_HERO() || creature_ptr->shero)
2720                 add_flag(flgs, TR_RES_FEAR);
2721         if (creature_ptr->tim_invis)
2722                 add_flag(flgs, TR_SEE_INVIS);
2723         if (creature_ptr->tim_regen)
2724                 add_flag(flgs, TR_REGEN);
2725         if (IS_TIM_ESP())
2726                 add_flag(flgs, TR_TELEPATHY);
2727         if (IS_FAST() || creature_ptr->slow)
2728                 add_flag(flgs, TR_SPEED);
2729
2730         if (IS_OPPOSE_ACID() && !(creature_ptr->special_defense & DEFENSE_ACID) && !(PRACE_IS_(creature_ptr, RACE_YEEK) && (creature_ptr->lev > 19)))
2731                 add_flag(flgs, TR_RES_ACID);
2732         if (IS_OPPOSE_ELEC() && !(creature_ptr->special_defense & DEFENSE_ELEC))
2733                 add_flag(flgs, TR_RES_ELEC);
2734         if (IS_OPPOSE_FIRE() && !(creature_ptr->special_defense & DEFENSE_FIRE))
2735                 add_flag(flgs, TR_RES_FIRE);
2736         if (IS_OPPOSE_COLD() && !(creature_ptr->special_defense & DEFENSE_COLD))
2737                 add_flag(flgs, TR_RES_COLD);
2738         if (IS_OPPOSE_POIS())
2739                 add_flag(flgs, TR_RES_POIS);
2740
2741         if (creature_ptr->special_attack & ATTACK_ACID)
2742                 add_flag(flgs, TR_BRAND_ACID);
2743         if (creature_ptr->special_attack & ATTACK_ELEC)
2744                 add_flag(flgs, TR_BRAND_ELEC);
2745         if (creature_ptr->special_attack & ATTACK_FIRE)
2746                 add_flag(flgs, TR_BRAND_FIRE);
2747         if (creature_ptr->special_attack & ATTACK_COLD)
2748                 add_flag(flgs, TR_BRAND_COLD);
2749         if (creature_ptr->special_attack & ATTACK_POIS)
2750                 add_flag(flgs, TR_BRAND_POIS);
2751         if (creature_ptr->special_defense & DEFENSE_ACID)
2752                 add_flag(flgs, TR_IM_ACID);
2753         if (creature_ptr->special_defense & DEFENSE_ELEC)
2754                 add_flag(flgs, TR_IM_ELEC);
2755         if (creature_ptr->special_defense & DEFENSE_FIRE)
2756                 add_flag(flgs, TR_IM_FIRE);
2757         if (creature_ptr->special_defense & DEFENSE_COLD)
2758                 add_flag(flgs, TR_IM_COLD);
2759         if (creature_ptr->wraith_form)
2760                 add_flag(flgs, TR_REFLECT);
2761         /* by henkma */
2762         if (creature_ptr->tim_reflect)
2763                 add_flag(flgs, TR_REFLECT);
2764
2765         if (creature_ptr->magicdef)
2766         {
2767                 add_flag(flgs, TR_RES_BLIND);
2768                 add_flag(flgs, TR_RES_CONF);
2769                 add_flag(flgs, TR_REFLECT);
2770                 add_flag(flgs, TR_FREE_ACT);
2771                 add_flag(flgs, TR_LEVITATION);
2772         }
2773         if (creature_ptr->tim_res_nether)
2774         {
2775                 add_flag(flgs, TR_RES_NETHER);
2776         }
2777         if (creature_ptr->tim_sh_fire)
2778         {
2779                 add_flag(flgs, TR_SH_FIRE);
2780         }
2781         if (creature_ptr->ult_res)
2782         {
2783                 add_flag(flgs, TR_RES_FEAR);
2784                 add_flag(flgs, TR_RES_LITE);
2785                 add_flag(flgs, TR_RES_DARK);
2786                 add_flag(flgs, TR_RES_BLIND);
2787                 add_flag(flgs, TR_RES_CONF);
2788                 add_flag(flgs, TR_RES_SOUND);
2789                 add_flag(flgs, TR_RES_SHARDS);
2790                 add_flag(flgs, TR_RES_NETHER);
2791                 add_flag(flgs, TR_RES_NEXUS);
2792                 add_flag(flgs, TR_RES_CHAOS);
2793                 add_flag(flgs, TR_RES_DISEN);
2794                 add_flag(flgs, TR_REFLECT);
2795                 add_flag(flgs, TR_HOLD_EXP);
2796                 add_flag(flgs, TR_FREE_ACT);
2797                 add_flag(flgs, TR_SH_FIRE);
2798                 add_flag(flgs, TR_SH_ELEC);
2799                 add_flag(flgs, TR_SH_COLD);
2800                 add_flag(flgs, TR_LEVITATION);
2801                 add_flag(flgs, TR_LITE_1);
2802                 add_flag(flgs, TR_SEE_INVIS);
2803                 add_flag(flgs, TR_TELEPATHY);
2804                 add_flag(flgs, TR_SLOW_DIGEST);
2805                 add_flag(flgs, TR_REGEN);
2806                 add_flag(flgs, TR_SUST_STR);
2807                 add_flag(flgs, TR_SUST_INT);
2808                 add_flag(flgs, TR_SUST_WIS);
2809                 add_flag(flgs, TR_SUST_DEX);
2810                 add_flag(flgs, TR_SUST_CON);
2811                 add_flag(flgs, TR_SUST_CHR);
2812         }
2813
2814         /* Hex bonuses */
2815         if (creature_ptr->realm1 == REALM_HEX)
2816         {
2817                 if (hex_spelling(HEX_DEMON_AURA))
2818                 {
2819                         add_flag(flgs, TR_SH_FIRE);
2820                         add_flag(flgs, TR_REGEN);
2821                 }
2822                 if (hex_spelling(HEX_ICE_ARMOR)) add_flag(flgs, TR_SH_COLD);
2823                 if (hex_spelling(HEX_SHOCK_CLOAK)) add_flag(flgs, TR_SH_ELEC);
2824         }
2825 }
2826
2827
2828 /* Mode flags for displaying player flags */
2829 #define DP_CURSE   0x01
2830 #define DP_IMM     0x02
2831 #define DP_WP      0x08
2832
2833
2834 /*!
2835  * @brief プレイヤーの装備一覧をシンボルで並べる
2836  * Equippy chars
2837  * @param y 表示するコンソールの行
2838  * @param x 表示するコンソールの列
2839  * @param mode オプション
2840  * @return なし
2841  */
2842 void display_player_equippy(TERM_LEN y, TERM_LEN x, BIT_FLAGS16 mode)
2843 {
2844         int i, max_i;
2845
2846         TERM_COLOR a;
2847         char c;
2848
2849         object_type *o_ptr;
2850
2851         /* Weapon flags need only two column */
2852         if (mode & DP_WP) max_i = INVEN_LARM + 1;
2853         else max_i = INVEN_TOTAL;
2854
2855         /* Dump equippy chars */
2856         for (i = INVEN_RARM; i < max_i; i++)
2857         {
2858                 /* Object */
2859                 o_ptr = &p_ptr->inventory_list[i];
2860
2861                 a = object_attr(o_ptr);
2862                 c = object_char(o_ptr);
2863
2864                 /* Clear the part of the screen */
2865                 if (!equippy_chars || !o_ptr->k_idx)
2866                 {
2867                         c = ' ';
2868                         a = TERM_DARK;
2869                 }
2870
2871                 /* Dump */
2872                 Term_putch(x + i - INVEN_RARM, y, a, c);
2873         }
2874 }
2875
2876
2877 /*!
2878  * @brief プレイヤーの装備による免疫フラグを返す
2879  * @param flgs フラグを保管する配列
2880  * @return なし
2881  * @todo
2882  * xtra1.c周りと多重実装になっているのを何とかする
2883  */
2884 static void known_obj_immunity(BIT_FLAGS flgs[TR_FLAG_SIZE])
2885 {
2886         int i;
2887         for (i = 0; i < TR_FLAG_SIZE; i++)
2888                 flgs[i] = 0L;
2889
2890         /* Check equipment */
2891         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2892         {
2893                 u32b o_flgs[TR_FLAG_SIZE];
2894
2895                 object_type *o_ptr;
2896
2897                 /* Object */
2898                 o_ptr = &p_ptr->inventory_list[i];
2899
2900                 if (!o_ptr->k_idx) continue;
2901
2902                 /* Known flags */
2903                 object_flags_known(o_ptr, o_flgs);
2904
2905                 if (have_flag(o_flgs, TR_IM_ACID)) add_flag(flgs, TR_RES_ACID);
2906                 if (have_flag(o_flgs, TR_IM_ELEC)) add_flag(flgs, TR_RES_ELEC);
2907                 if (have_flag(o_flgs, TR_IM_FIRE)) add_flag(flgs, TR_RES_FIRE);
2908                 if (have_flag(o_flgs, TR_IM_COLD)) add_flag(flgs, TR_RES_COLD);
2909         }
2910 }
2911
2912 /*!
2913  * @brief プレイヤーの種族による免疫フラグを返す
2914  * @param flgs フラグを保管する配列
2915  * @return なし
2916  * @todo
2917  * xtra1.c周りと多重実装になっているのを何とかする
2918  */
2919 static void player_immunity(BIT_FLAGS flgs[TR_FLAG_SIZE])
2920 {
2921         int i;
2922         for (i = 0; i < TR_FLAG_SIZE; i++)
2923                 flgs[i] = 0L;
2924
2925         if (PRACE_IS_(p_ptr, RACE_SPECTRE))
2926                 add_flag(flgs, TR_RES_NETHER);
2927         if (p_ptr->mimic_form == MIMIC_VAMPIRE || PRACE_IS_(p_ptr, RACE_VAMPIRE))
2928                 add_flag(flgs, TR_RES_DARK);
2929         if (p_ptr->mimic_form == MIMIC_DEMON_LORD)
2930                 add_flag(flgs, TR_RES_FIRE);
2931         else if (PRACE_IS_(p_ptr, RACE_YEEK) && p_ptr->lev > 19)
2932                 add_flag(flgs, TR_RES_ACID);
2933 }
2934
2935 /*!
2936  * @brief プレイヤーの一時的魔法効果による免疫フラグを返す
2937  * @param flgs フラグを保管する配列
2938  * @return なし
2939  * @todo
2940  * xtra1.c周りと多重実装になっているのを何とかする
2941  */
2942 static void tim_player_immunity(BIT_FLAGS flgs[TR_FLAG_SIZE])
2943 {
2944         int i;
2945         for (i = 0; i < TR_FLAG_SIZE; i++)
2946                 flgs[i] = 0L;
2947
2948         if (p_ptr->special_defense & DEFENSE_ACID)
2949                 add_flag(flgs, TR_RES_ACID);
2950         if (p_ptr->special_defense & DEFENSE_ELEC)
2951                 add_flag(flgs, TR_RES_ELEC);
2952         if (p_ptr->special_defense & DEFENSE_FIRE)
2953                 add_flag(flgs, TR_RES_FIRE);
2954         if (p_ptr->special_defense & DEFENSE_COLD)
2955                 add_flag(flgs, TR_RES_COLD);
2956         if (p_ptr->wraith_form)
2957                 add_flag(flgs, TR_RES_DARK);
2958 }
2959
2960 /*!
2961  * @brief プレイヤーの種族による弱点フラグを返す
2962  * @param flgs フラグを保管する配列
2963  * @return なし
2964  * @todo
2965  * xtra1.c周りと多重実装になっているのを何とかする
2966  */
2967 static void player_vuln_flags(BIT_FLAGS flgs[TR_FLAG_SIZE])
2968 {
2969         int i;
2970         for (i = 0; i < TR_FLAG_SIZE; i++)
2971                 flgs[i] = 0L;
2972
2973         if ((p_ptr->muta3 & MUT3_VULN_ELEM) || (p_ptr->special_defense & KATA_KOUKIJIN))
2974         {
2975                 add_flag(flgs, TR_RES_ACID);
2976                 add_flag(flgs, TR_RES_ELEC);
2977                 add_flag(flgs, TR_RES_FIRE);
2978                 add_flag(flgs, TR_RES_COLD);
2979         }
2980         if (PRACE_IS_(p_ptr, RACE_ANDROID))
2981                 add_flag(flgs, TR_RES_ELEC);
2982         if (PRACE_IS_(p_ptr, RACE_ENT))
2983                 add_flag(flgs, TR_RES_FIRE);
2984         if (PRACE_IS_(p_ptr, RACE_VAMPIRE) || PRACE_IS_(p_ptr, RACE_S_FAIRY) ||
2985             (p_ptr->mimic_form == MIMIC_VAMPIRE))
2986                 add_flag(flgs, TR_RES_LITE);
2987 }
2988
2989
2990 /*
2991  * A struct for storing misc. flags
2992  */
2993 typedef struct {
2994         BIT_FLAGS player_flags[TR_FLAG_SIZE];
2995         BIT_FLAGS tim_player_flags[TR_FLAG_SIZE];
2996         BIT_FLAGS player_imm[TR_FLAG_SIZE];
2997         BIT_FLAGS tim_player_imm[TR_FLAG_SIZE];
2998         BIT_FLAGS player_vuln[TR_FLAG_SIZE];
2999         BIT_FLAGS known_obj_imm[TR_FLAG_SIZE];
3000 } all_player_flags;
3001
3002
3003 /*!
3004  * @brief プレイヤーの特性フラグ一種を表示するサブルーチン /
3005  * Helper function, see below
3006  * @param row コンソール表示位置の左上行
3007  * @param col コンソール表示位置の左上列
3008  * @param header コンソール上で表示する特性名
3009  * @param flag1 参照する特性ID
3010  * @param f プレイヤーの特性情報構造体
3011  * @param mode 表示オプション
3012  * @return なし
3013  */
3014 static void display_flag_aux(TERM_LEN row, TERM_LEN col, concptr header,
3015                                     int flag1, all_player_flags *f, u16b mode)
3016 {
3017         int     i;
3018         bool    vuln = FALSE;
3019         int max_i;
3020         byte header_color = TERM_L_DARK;
3021         int header_col = col;
3022
3023         if (have_flag(f->player_vuln, flag1) &&
3024             !(have_flag(f->known_obj_imm, flag1) ||
3025               have_flag(f->player_imm, flag1) ||
3026               have_flag(f->tim_player_imm, flag1)))
3027                 vuln = TRUE;
3028
3029         /* Advance */
3030         col += strlen(header) + 1;
3031
3032         /* Weapon flags need only two column */
3033         if (mode & DP_WP) max_i = INVEN_LARM + 1;
3034         else max_i = INVEN_TOTAL;
3035
3036         /* Check equipment */
3037         for (i = INVEN_RARM; i < max_i; i++)
3038         {
3039                 BIT_FLAGS flgs[TR_FLAG_SIZE];
3040                 object_type *o_ptr;
3041
3042                 /* Object */
3043                 o_ptr = &p_ptr->inventory_list[i];
3044
3045                 /* Known flags */
3046                 object_flags_known(o_ptr, flgs);
3047
3048                 /* Default */
3049                 if (!(mode & DP_IMM))
3050                         c_put_str((byte)(vuln ? TERM_RED : TERM_SLATE), ".", row, col);
3051
3052                 /* Check flags */
3053                 if (mode & DP_CURSE)
3054                 {
3055                         if (have_flag(flgs, TR_ADD_L_CURSE) || have_flag(flgs, TR_ADD_H_CURSE))
3056                         {
3057                                 c_put_str(TERM_L_DARK, "+", row, col);
3058                                 header_color = TERM_WHITE;
3059                         }
3060                         if (o_ptr->curse_flags & (TRC_CURSED | TRC_HEAVY_CURSE))
3061                         {
3062                                 c_put_str(TERM_WHITE, "+", row, col);
3063                                 header_color = TERM_WHITE;
3064                         }
3065                         if (o_ptr->curse_flags & TRC_PERMA_CURSE)
3066                         {
3067                                 c_put_str(TERM_WHITE, "*", row, col);
3068                                 header_color = TERM_WHITE;
3069                         }
3070                 }
3071                 else if (flag1 == TR_LITE_1)
3072                 {
3073                         if (HAVE_DARK_FLAG(flgs))
3074                         {
3075                                 c_put_str(TERM_L_DARK, "+", row, col);
3076                                 header_color = TERM_WHITE;
3077                         }
3078                         else if (HAVE_LITE_FLAG(flgs))
3079                         {
3080                                 c_put_str(TERM_WHITE, "+", row, col);
3081                                 header_color = TERM_WHITE;
3082                         }
3083                 }
3084                 else
3085                 {
3086                         if (have_flag(flgs, flag1))
3087                         {
3088                                 c_put_str((byte)(vuln ? TERM_L_RED : TERM_WHITE),
3089                                           (mode & DP_IMM) ? "*" : "+", row, col);
3090                                 header_color = TERM_WHITE;
3091                         }
3092                 }
3093
3094                 /* Advance */
3095                 col++;
3096         }
3097
3098         /* Assume that player flag is already written */
3099         if (mode & DP_IMM)
3100         {
3101                 if (header_color != TERM_L_DARK)
3102                 {
3103                         /* Overwrite Header Color */
3104                         c_put_str(header_color, header, row, header_col);
3105                 }
3106                 return;
3107         }
3108
3109         /* Default */
3110         c_put_str((byte)(vuln ? TERM_RED : TERM_SLATE), ".", row, col);
3111
3112         /* Player flags */
3113         if (have_flag(f->player_flags, flag1))
3114         {
3115                 c_put_str((byte)(vuln ? TERM_L_RED : TERM_WHITE), "+", row, col);
3116                 header_color = TERM_WHITE;
3117         }
3118
3119         /* Timed player flags */
3120         if (have_flag(f->tim_player_flags, flag1))
3121         {
3122                 c_put_str((byte)(vuln ? TERM_ORANGE : TERM_YELLOW), "#", row, col);
3123                 header_color = TERM_WHITE;
3124         }
3125
3126         /* Immunity */
3127         if (have_flag(f->tim_player_imm, flag1))
3128         {
3129                 c_put_str(TERM_YELLOW, "*", row, col);
3130                 header_color = TERM_WHITE;
3131         }
3132         if (have_flag(f->player_imm, flag1))
3133         {
3134                 c_put_str(TERM_WHITE, "*", row, col);
3135                 header_color = TERM_WHITE;
3136         }
3137
3138         /* Vulnerability */
3139         if (vuln) c_put_str(TERM_RED, "v", row, col + 1);
3140
3141         /* Header */
3142         c_put_str(header_color, header, row, header_col);
3143 }
3144
3145
3146 /*!
3147  * @brief プレイヤーの特性フラグ一覧表示1 /
3148  * Special display, part 1
3149  * @return なし
3150  */
3151 static void display_player_flag_info(void)
3152 {
3153         TERM_LEN row;
3154         TERM_LEN col;
3155
3156         all_player_flags f;
3157
3158         /* Extract flags and store */
3159         player_flags(f.player_flags);
3160         tim_player_flags(p_ptr, f.tim_player_flags);
3161         player_immunity(f.player_imm);
3162         tim_player_immunity(f.tim_player_imm);
3163         known_obj_immunity(f.known_obj_imm);
3164         player_vuln_flags(f.player_vuln);
3165
3166         /*** Set 1 ***/
3167
3168         row = 12;
3169         col = 1;
3170
3171         display_player_equippy(row-2, col+8, 0);
3172         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+8);
3173
3174 #ifdef JP
3175         display_flag_aux(row+0, col, "耐酸  :", TR_RES_ACID, &f, 0);
3176         display_flag_aux(row+0, col, "耐酸  :", TR_IM_ACID, &f, DP_IMM);
3177         display_flag_aux(row+1, col, "耐電撃:", TR_RES_ELEC, &f, 0);
3178         display_flag_aux(row+1, col, "耐電撃:", TR_IM_ELEC, &f, DP_IMM);
3179         display_flag_aux(row+2, col, "耐火炎:", TR_RES_FIRE, &f, 0);
3180         display_flag_aux(row+2, col, "耐火炎:", TR_IM_FIRE, &f, DP_IMM);
3181         display_flag_aux(row+3, col, "耐冷気:", TR_RES_COLD, &f, 0);
3182         display_flag_aux(row+3, col, "耐冷気:", TR_IM_COLD, &f, DP_IMM);
3183         display_flag_aux(row+4, col, "耐毒  :", TR_RES_POIS, &f, 0);
3184         display_flag_aux(row+5, col, "耐閃光:", TR_RES_LITE, &f, 0);
3185         display_flag_aux(row+6, col, "耐暗黒:", TR_RES_DARK, &f, 0);
3186         display_flag_aux(row+7, col, "耐破片:", TR_RES_SHARDS, &f, 0);
3187         display_flag_aux(row+8, col, "耐盲目:", TR_RES_BLIND, &f, 0);
3188         display_flag_aux(row+9, col, "耐混乱:", TR_RES_CONF, &f, 0);
3189 #else
3190         display_flag_aux(row+0, col, "Acid  :", TR_RES_ACID, &f, 0);
3191         display_flag_aux(row+0, col, "Acid  :", TR_IM_ACID, &f, DP_IMM);
3192         display_flag_aux(row+1, col, "Elec  :", TR_RES_ELEC, &f, 0);
3193         display_flag_aux(row+1, col, "Elec  :", TR_IM_ELEC, &f, DP_IMM);
3194         display_flag_aux(row+2, col, "Fire  :", TR_RES_FIRE, &f, 0);
3195         display_flag_aux(row+2, col, "Fire  :", TR_IM_FIRE, &f, DP_IMM);
3196         display_flag_aux(row+3, col, "Cold  :", TR_RES_COLD, &f, 0);
3197         display_flag_aux(row+3, col, "Cold  :", TR_IM_COLD, &f, DP_IMM);
3198         display_flag_aux(row+4, col, "Poison:", TR_RES_POIS, &f, 0);
3199         display_flag_aux(row+5, col, "Light :", TR_RES_LITE, &f, 0);
3200         display_flag_aux(row+6, col, "Dark  :", TR_RES_DARK, &f, 0);
3201         display_flag_aux(row+7, col, "Shard :", TR_RES_SHARDS, &f, 0);
3202         display_flag_aux(row+8, col, "Blind :", TR_RES_BLIND, &f, 0);
3203         display_flag_aux(row+9, col, "Conf  :", TR_RES_CONF, &f, 0);
3204 #endif
3205
3206
3207         /*** Set 2 ***/
3208
3209         row = 12;
3210         col = 26;
3211
3212         display_player_equippy(row-2, col+8, 0);
3213
3214         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+8);
3215
3216 #ifdef JP
3217         display_flag_aux(row+0, col, "耐轟音:", TR_RES_SOUND, &f, 0);
3218         display_flag_aux(row+1, col, "耐地獄:", TR_RES_NETHER, &f, 0);
3219         display_flag_aux(row+2, col, "耐因混:", TR_RES_NEXUS, &f, 0);
3220         display_flag_aux(row+3, col, "耐カオ:", TR_RES_CHAOS, &f, 0);
3221         display_flag_aux(row+4, col, "耐劣化:", TR_RES_DISEN, &f, 0);
3222         display_flag_aux(row+5, col, "耐恐怖:", TR_RES_FEAR, &f, 0);
3223         display_flag_aux(row+6, col, "反射  :", TR_REFLECT, &f, 0);
3224         display_flag_aux(row+7, col, "火炎オ:", TR_SH_FIRE, &f, 0);
3225         display_flag_aux(row+8, col, "電気オ:", TR_SH_ELEC, &f, 0);
3226         display_flag_aux(row+9, col, "冷気オ:", TR_SH_COLD, &f, 0);
3227 #else
3228         display_flag_aux(row+0, col, "Sound :", TR_RES_SOUND, &f, 0);
3229         display_flag_aux(row+1, col, "Nether:", TR_RES_NETHER, &f, 0);
3230         display_flag_aux(row+2, col, "Nexus :", TR_RES_NEXUS, &f, 0);
3231         display_flag_aux(row+3, col, "Chaos :", TR_RES_CHAOS, &f, 0);
3232         display_flag_aux(row+4, col, "Disnch:", TR_RES_DISEN, &f, 0);
3233         display_flag_aux(row+5, col, "Fear  :", TR_RES_FEAR, &f, 0);
3234         display_flag_aux(row+6, col, "Reflct:", TR_REFLECT, &f, 0);
3235         display_flag_aux(row+7, col, "AuFire:", TR_SH_FIRE, &f, 0);
3236         display_flag_aux(row+8, col, "AuElec:", TR_SH_ELEC, &f, 0);
3237         display_flag_aux(row+9, col, "AuCold:", TR_SH_COLD, &f, 0);
3238 #endif
3239
3240
3241         /*** Set 3 ***/
3242
3243         row = 12;
3244         col = 51;
3245
3246         display_player_equippy(row-2, col+12, 0);
3247
3248         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+12);
3249
3250 #ifdef JP
3251         display_flag_aux(row+0, col, "加速      :", TR_SPEED, &f, 0);
3252         display_flag_aux(row+1, col, "耐麻痺    :", TR_FREE_ACT, &f, 0);
3253         display_flag_aux(row+2, col, "透明体視認:", TR_SEE_INVIS, &f, 0);
3254         display_flag_aux(row+3, col, "経験値保持:", TR_HOLD_EXP, &f, 0);
3255         display_flag_aux(row+4, col, "警告      :", TR_WARNING, &f, 0);
3256         display_flag_aux(row+5, col, "遅消化    :", TR_SLOW_DIGEST, &f, 0);
3257         display_flag_aux(row+6, col, "急回復    :", TR_REGEN, &f, 0);
3258         display_flag_aux(row+7, col, "浮遊      :", TR_LEVITATION, &f, 0);
3259         display_flag_aux(row+8, col, "永遠光源  :", TR_LITE_1, &f, 0);
3260         display_flag_aux(row+9, col, "呪い      :", 0, &f, DP_CURSE);
3261 #else
3262         display_flag_aux(row+0, col, "Speed     :", TR_SPEED, &f, 0);
3263         display_flag_aux(row+1, col, "FreeAction:", TR_FREE_ACT, &f, 0);
3264         display_flag_aux(row+2, col, "SeeInvisi.:", TR_SEE_INVIS, &f, 0);
3265         display_flag_aux(row+3, col, "Hold Exp :", TR_HOLD_EXP, &f, 0);
3266         display_flag_aux(row+4, col, "Warning   :", TR_WARNING, &f, 0);
3267         display_flag_aux(row+5, col, "SlowDigest:", TR_SLOW_DIGEST, &f, 0);
3268         display_flag_aux(row+6, col, "Regene.   :", TR_REGEN, &f, 0);
3269         display_flag_aux(row+7, col, "Levitation:", TR_LEVITATION, &f, 0);
3270         display_flag_aux(row+8, col, "Perm Lite :", TR_LITE_1, &f, 0);
3271         display_flag_aux(row+9, col, "Cursed    :", 0, &f, DP_CURSE);
3272 #endif
3273
3274 }
3275
3276
3277 /*!
3278  * @brief プレイヤーの特性フラグ一覧表示2 /
3279  * Special display, part 2
3280  * @return なし
3281  */
3282 static void display_player_other_flag_info(void)
3283 {
3284         TERM_LEN row;
3285         TERM_LEN col;
3286
3287         all_player_flags f;
3288
3289         /* Extract flags and store */
3290         player_flags(f.player_flags);
3291         tim_player_flags(p_ptr, f.tim_player_flags);
3292         player_immunity(f.player_imm);
3293         tim_player_immunity(f.tim_player_imm);
3294         known_obj_immunity(f.known_obj_imm);
3295         player_vuln_flags(f.player_vuln);
3296
3297         /*** Set 1 ***/
3298
3299         row = 3;
3300         col = 1;
3301
3302         display_player_equippy(row-2, col+12, DP_WP);
3303
3304         c_put_str(TERM_WHITE, "ab@", row-1, col+12);
3305
3306 #ifdef JP
3307         display_flag_aux(row+ 0, col, "邪悪 倍打 :", TR_SLAY_EVIL, &f, DP_WP);
3308         display_flag_aux(row+ 0, col, "邪悪 倍打 :", TR_KILL_EVIL, &f, (DP_WP|DP_IMM));
3309         display_flag_aux(row+ 1, col, "不死 倍打 :", TR_SLAY_UNDEAD, &f, DP_WP);
3310         display_flag_aux(row+ 1, col, "不死 倍打 :", TR_KILL_UNDEAD, &f, (DP_WP|DP_IMM));
3311         display_flag_aux(row+ 2, col, "悪魔 倍打 :", TR_SLAY_DEMON, &f, DP_WP);
3312         display_flag_aux(row+ 2, col, "悪魔 倍打 :", TR_KILL_DEMON, &f, (DP_WP|DP_IMM));
3313         display_flag_aux(row+ 3, col, "龍 倍打   :", TR_SLAY_DRAGON, &f, DP_WP);
3314         display_flag_aux(row+ 3, col, "龍 倍打   :", TR_KILL_DRAGON, &f, (DP_WP|DP_IMM));
3315         display_flag_aux(row+ 4, col, "人間 倍打 :", TR_SLAY_HUMAN, &f, DP_WP);
3316         display_flag_aux(row+ 4, col, "人間 倍打 :", TR_KILL_HUMAN, &f, (DP_WP|DP_IMM));
3317         display_flag_aux(row+ 5, col, "動物 倍打 :", TR_SLAY_ANIMAL, &f, DP_WP);
3318         display_flag_aux(row+ 5, col, "動物 倍打 :", TR_KILL_ANIMAL, &f, (DP_WP|DP_IMM));
3319         display_flag_aux(row+ 6, col, "オーク倍打:", TR_SLAY_ORC, &f, DP_WP);
3320         display_flag_aux(row+ 6, col, "オーク倍打:", TR_KILL_ORC, &f, (DP_WP|DP_IMM));
3321         display_flag_aux(row+ 7, col, "トロル倍打:", TR_SLAY_TROLL, &f, DP_WP);
3322         display_flag_aux(row+ 7, col, "トロル倍打:", TR_KILL_TROLL, &f, (DP_WP|DP_IMM));
3323         display_flag_aux(row+ 8, col, "巨人 倍打 :", TR_SLAY_GIANT, &f, DP_WP);
3324         display_flag_aux(row+ 8, col, "巨人 倍打 :", TR_KILL_GIANT, &f, (DP_WP|DP_IMM));
3325         display_flag_aux(row+ 9, col, "溶解      :", TR_BRAND_ACID, &f, DP_WP);
3326         display_flag_aux(row+10, col, "電撃      :", TR_BRAND_ELEC, &f, DP_WP);
3327         display_flag_aux(row+11, col, "焼棄      :", TR_BRAND_FIRE, &f, DP_WP);
3328         display_flag_aux(row+12, col, "凍結      :", TR_BRAND_COLD, &f, DP_WP);
3329         display_flag_aux(row+13, col, "毒殺      :", TR_BRAND_POIS, &f, DP_WP);
3330         display_flag_aux(row+14, col, "切れ味    :", TR_VORPAL, &f, DP_WP);
3331         display_flag_aux(row+15, col, "地震      :", TR_IMPACT, &f, DP_WP);
3332         display_flag_aux(row+16, col, "吸血      :", TR_VAMPIRIC, &f, DP_WP);
3333         display_flag_aux(row+17, col, "カオス効果:", TR_CHAOTIC, &f, DP_WP);
3334         display_flag_aux(row+18, col, "理力      :", TR_FORCE_WEAPON, &f, DP_WP);
3335 #else
3336         display_flag_aux(row+ 0, col, "Slay Evil :", TR_SLAY_EVIL, &f, DP_WP);
3337         display_flag_aux(row+ 0, col, "Slay Evil :", TR_KILL_EVIL, &f, (DP_WP|DP_IMM));
3338         display_flag_aux(row+ 1, col, "Slay Und. :", TR_SLAY_UNDEAD, &f, DP_WP);
3339         display_flag_aux(row+ 1, col, "Slay Und. :", TR_KILL_UNDEAD, &f, (DP_WP|DP_IMM));
3340         display_flag_aux(row+ 2, col, "Slay Demon:", TR_SLAY_DEMON, &f, DP_WP);
3341         display_flag_aux(row+ 2, col, "Slay Demon:", TR_KILL_DEMON, &f, (DP_WP|DP_IMM));
3342         display_flag_aux(row+ 3, col, "Slay Drag.:", TR_SLAY_DRAGON, &f, DP_WP);
3343         display_flag_aux(row+ 3, col, "Slay Drag.:", TR_KILL_DRAGON, &f, (DP_WP|DP_IMM));
3344         display_flag_aux(row+ 4, col, "Slay Human:", TR_SLAY_HUMAN, &f, DP_WP);
3345         display_flag_aux(row+ 4, col, "Slay Human:", TR_KILL_HUMAN, &f, (DP_WP|DP_IMM));
3346         display_flag_aux(row+ 5, col, "Slay Anim.:", TR_SLAY_ANIMAL, &f, DP_WP);
3347         display_flag_aux(row+ 5, col, "Slay Anim.:", TR_KILL_ANIMAL, &f, (DP_WP|DP_IMM));
3348         display_flag_aux(row+ 6, col, "Slay Orc  :", TR_SLAY_ORC, &f, DP_WP);
3349         display_flag_aux(row+ 6, col, "Slay Orc  :", TR_KILL_ORC, &f, (DP_WP|DP_IMM));
3350         display_flag_aux(row+ 7, col, "Slay Troll:", TR_SLAY_TROLL, &f, DP_WP);
3351         display_flag_aux(row+ 7, col, "Slay Troll:", TR_KILL_TROLL, &f, (DP_WP|DP_IMM));
3352         display_flag_aux(row+ 8, col, "Slay Giant:", TR_SLAY_GIANT, &f, DP_WP);
3353         display_flag_aux(row+ 8, col, "Slay Giant:", TR_KILL_GIANT, &f, (DP_WP|DP_IMM));
3354         display_flag_aux(row+ 9, col, "Acid Brand:", TR_BRAND_ACID, &f, DP_WP);
3355         display_flag_aux(row+10, col, "Elec Brand:", TR_BRAND_ELEC, &f, DP_WP);
3356         display_flag_aux(row+11, col, "Fire Brand:", TR_BRAND_FIRE, &f, DP_WP);
3357         display_flag_aux(row+12, col, "Cold Brand:", TR_BRAND_COLD, &f, DP_WP);
3358         display_flag_aux(row+13, col, "Poison Brd:", TR_BRAND_POIS, &f, DP_WP);
3359         display_flag_aux(row+14, col, "Sharpness :", TR_VORPAL, &f, DP_WP);
3360         display_flag_aux(row+15, col, "Quake     :", TR_IMPACT, &f, DP_WP);
3361         display_flag_aux(row+16, col, "Vampiric  :", TR_VAMPIRIC, &f, DP_WP);
3362         display_flag_aux(row+17, col, "Chaotic   :", TR_CHAOTIC, &f, DP_WP);
3363         display_flag_aux(row+18, col, "Force Wep.:", TR_FORCE_WEAPON, &f, DP_WP);
3364 #endif
3365
3366
3367         /*** Set 2 ***/
3368
3369         row = 3;
3370         col = col + 12 + 7;
3371
3372         display_player_equippy(row-2, col+13, 0);
3373         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+13);
3374
3375 #ifdef JP
3376         display_flag_aux(row+ 0, col, "テレパシー :", TR_TELEPATHY, &f, 0);
3377         display_flag_aux(row+ 1, col, "邪悪ESP    :", TR_ESP_EVIL, &f, 0);
3378         display_flag_aux(row+ 2, col, "無生物ESP  :", TR_ESP_NONLIVING, &f, 0);
3379         display_flag_aux(row+ 3, col, "善良ESP    :", TR_ESP_GOOD, &f, 0);
3380         display_flag_aux(row+ 4, col, "不死ESP    :", TR_ESP_UNDEAD, &f, 0);
3381         display_flag_aux(row+ 5, col, "悪魔ESP    :", TR_ESP_DEMON, &f, 0);
3382         display_flag_aux(row+ 6, col, "龍ESP      :", TR_ESP_DRAGON, &f, 0);
3383         display_flag_aux(row+ 7, col, "人間ESP    :", TR_ESP_HUMAN, &f, 0);
3384         display_flag_aux(row+ 8, col, "動物ESP    :", TR_ESP_ANIMAL, &f, 0);
3385         display_flag_aux(row+ 9, col, "オークESP  :", TR_ESP_ORC, &f, 0);
3386         display_flag_aux(row+10, col, "トロルESP  :", TR_ESP_TROLL, &f, 0);
3387         display_flag_aux(row+11, col, "巨人ESP    :", TR_ESP_GIANT, &f, 0);
3388         display_flag_aux(row+12, col, "ユニークESP:", TR_ESP_UNIQUE, &f, 0);
3389         display_flag_aux(row+13, col, "腕力維持   :", TR_SUST_STR, &f, 0);
3390         display_flag_aux(row+14, col, "知力維持   :", TR_SUST_INT, &f, 0);
3391         display_flag_aux(row+15, col, "賢さ維持   :", TR_SUST_WIS, &f, 0);
3392         display_flag_aux(row+16, col, "器用維持   :", TR_SUST_DEX, &f, 0);
3393         display_flag_aux(row+17, col, "耐久維持   :", TR_SUST_CON, &f, 0);
3394         display_flag_aux(row+18, col, "魅力維持   :", TR_SUST_CHR, &f, 0);
3395 #else
3396         display_flag_aux(row+ 0, col, "Telepathy  :", TR_TELEPATHY, &f, 0);
3397         display_flag_aux(row+ 1, col, "ESP Evil   :", TR_ESP_EVIL, &f, 0);
3398         display_flag_aux(row+ 2, col, "ESP Noliv. :", TR_ESP_NONLIVING, &f, 0);
3399         display_flag_aux(row+ 3, col, "ESP Good   :", TR_ESP_GOOD, &f, 0);
3400         display_flag_aux(row+ 4, col, "ESP Undead :", TR_ESP_UNDEAD, &f, 0);
3401         display_flag_aux(row+ 5, col, "ESP Demon  :", TR_ESP_DEMON, &f, 0);
3402         display_flag_aux(row+ 6, col, "ESP Dragon :", TR_ESP_DRAGON, &f, 0);
3403         display_flag_aux(row+ 7, col, "ESP Human  :", TR_ESP_HUMAN, &f, 0);
3404         display_flag_aux(row+ 8, col, "ESP Animal :", TR_ESP_ANIMAL, &f, 0);
3405         display_flag_aux(row+ 9, col, "ESP Orc    :", TR_ESP_ORC, &f, 0);
3406         display_flag_aux(row+10, col, "ESP Troll  :", TR_ESP_TROLL, &f, 0);
3407         display_flag_aux(row+11, col, "ESP Giant  :", TR_ESP_GIANT, &f, 0);
3408         display_flag_aux(row+12, col, "ESP Unique :", TR_ESP_UNIQUE, &f, 0);
3409         display_flag_aux(row+13, col, "Sust Str   :", TR_SUST_STR, &f, 0);
3410         display_flag_aux(row+14, col, "Sust Int   :", TR_SUST_INT, &f, 0);
3411         display_flag_aux(row+15, col, "Sust Wis   :", TR_SUST_WIS, &f, 0);
3412         display_flag_aux(row+16, col, "Sust Dex   :", TR_SUST_DEX, &f, 0);
3413         display_flag_aux(row+17, col, "Sust Con   :", TR_SUST_CON, &f, 0);
3414         display_flag_aux(row+18, col, "Sust Chr   :", TR_SUST_CHR, &f, 0);
3415 #endif
3416
3417
3418         /*** Set 3 ***/
3419
3420         row = 3;
3421         col = col + 12 + 17;
3422
3423         display_player_equippy(row-2, col+14, 0);
3424
3425         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+14);
3426
3427 #ifdef JP
3428         display_flag_aux(row+ 0, col, "追加攻撃    :", TR_BLOWS, &f, 0);
3429         display_flag_aux(row+ 1, col, "採掘        :", TR_TUNNEL, &f, 0);
3430         display_flag_aux(row+ 2, col, "赤外線視力  :", TR_INFRA, &f, 0);
3431         display_flag_aux(row+ 3, col, "魔法道具支配:", TR_MAGIC_MASTERY, &f, 0);
3432         display_flag_aux(row+ 4, col, "隠密        :", TR_STEALTH, &f, 0);
3433         display_flag_aux(row+ 5, col, "探索        :", TR_SEARCH, &f, 0);
3434
3435         display_flag_aux(row+ 7, col, "乗馬        :", TR_RIDING, &f, 0);
3436         display_flag_aux(row+ 8, col, "投擲        :", TR_THROW, &f, 0);
3437         display_flag_aux(row+ 9, col, "祝福        :", TR_BLESSED, &f, 0);
3438         display_flag_aux(row+10, col, "反テレポート:", TR_NO_TELE, &f, 0);
3439         display_flag_aux(row+11, col, "反魔法      :", TR_NO_MAGIC, &f, 0);
3440         display_flag_aux(row+12, col, "消費魔力減少:", TR_DEC_MANA, &f, 0);
3441
3442         display_flag_aux(row+14, col, "経験値減少  :", TR_DRAIN_EXP, &f, 0);
3443         display_flag_aux(row+15, col, "乱テレポート:", TR_TELEPORT, &f, 0);
3444         display_flag_aux(row+16, col, "反感        :", TR_AGGRAVATE, &f, 0);
3445         display_flag_aux(row+17, col, "太古の怨念  :", TR_TY_CURSE, &f, 0);
3446 #else
3447         display_flag_aux(row+ 0, col, "Add Blows   :", TR_BLOWS, &f, 0);
3448         display_flag_aux(row+ 1, col, "Add Tunnel  :", TR_TUNNEL, &f, 0);
3449         display_flag_aux(row+ 2, col, "Add Infra   :", TR_INFRA, &f, 0);
3450         display_flag_aux(row+ 3, col, "Add Device  :", TR_MAGIC_MASTERY, &f, 0);
3451         display_flag_aux(row+ 4, col, "Add Stealth :", TR_STEALTH, &f, 0);
3452         display_flag_aux(row+ 5, col, "Add Search  :", TR_SEARCH, &f, 0);
3453
3454         display_flag_aux(row+ 7, col, "Riding      :", TR_RIDING, &f, 0);
3455         display_flag_aux(row+ 8, col, "Throw       :", TR_THROW, &f, 0);
3456         display_flag_aux(row+ 9, col, "Blessed     :", TR_BLESSED, &f, 0);
3457         display_flag_aux(row+10, col, "No Teleport :", TR_NO_TELE, &f, 0);
3458         display_flag_aux(row+11, col, "Anti Magic  :", TR_NO_MAGIC, &f, 0);
3459         display_flag_aux(row+12, col, "Econom. Mana:", TR_DEC_MANA, &f, 0);
3460
3461         display_flag_aux(row+14, col, "Drain Exp   :", TR_DRAIN_EXP, &f, 0);
3462         display_flag_aux(row+15, col, "Rnd.Teleport:", TR_TELEPORT, &f, 0);
3463         display_flag_aux(row+16, col, "Aggravate   :", TR_AGGRAVATE, &f, 0);
3464         display_flag_aux(row+17, col, "TY Curse    :", TR_TY_CURSE, &f, 0);
3465 #endif
3466
3467 }
3468
3469
3470 /*!
3471  * @brief プレイヤーの特性フラグ一覧表示2a /
3472  * Special display, part 2a
3473  * @return なし
3474  */
3475 static void display_player_misc_info(void)
3476 {
3477         char    buf[80];
3478         char    tmp[80];
3479
3480         /* Display basics */
3481 #ifdef JP
3482 put_str("名前  :", 1, 26);
3483 put_str("性別  :", 3, 1);
3484 put_str("種族  :", 4, 1);
3485 put_str("職業  :", 5, 1);
3486 #else
3487         put_str("Name  :", 1, 26);
3488         put_str("Sex   :", 3, 1);
3489         put_str("Race  :", 4, 1);
3490         put_str("Class :", 5, 1);
3491 #endif
3492
3493         strcpy(tmp,ap_ptr->title);
3494 #ifdef JP
3495         if(ap_ptr->no == 1)
3496                 strcat(tmp,"の");
3497 #else
3498                 strcat(tmp," ");
3499 #endif
3500         strcat(tmp,p_ptr->name);
3501
3502         c_put_str(TERM_L_BLUE, tmp, 1, 34);
3503         c_put_str(TERM_L_BLUE, sp_ptr->title, 3, 9);
3504         c_put_str(TERM_L_BLUE, (p_ptr->mimic_form ? mimic_info[p_ptr->mimic_form].title : rp_ptr->title), 4, 9);
3505         c_put_str(TERM_L_BLUE, cp_ptr->title, 5, 9);
3506
3507         /* Display extras */
3508 #ifdef JP
3509 put_str("レベル:", 6, 1);
3510 put_str("HP  :", 7, 1);
3511 put_str("MP  :", 8, 1);
3512 #else
3513         put_str("Level :", 6, 1);
3514         put_str("Hits  :", 7, 1);
3515         put_str("Mana  :", 8, 1);
3516 #endif
3517
3518
3519         (void)sprintf(buf, "%d", (int)p_ptr->lev);
3520         c_put_str(TERM_L_BLUE, buf, 6, 9);
3521         (void)sprintf(buf, "%d/%d", (int)p_ptr->chp, (int)p_ptr->mhp);
3522         c_put_str(TERM_L_BLUE, buf, 7, 9);
3523         (void)sprintf(buf, "%d/%d", (int)p_ptr->csp, (int)p_ptr->msp);
3524         c_put_str(TERM_L_BLUE, buf, 8, 9);
3525 }
3526
3527
3528 /*!
3529  * @brief プレイヤーの特性フラグ一覧表示2b /
3530  * Special display, part 2b
3531  * @return なし
3532  * @details
3533  * <pre>
3534  * How to print out the modifications and sustains.
3535  * Positive mods with no sustain will be light green.
3536  * Positive mods with a sustain will be dark green.
3537  * Sustains (with no modification) will be a dark green 's'.
3538  * Negative mods (from a curse) will be red.
3539  * Huge mods (>9), like from MICoMorgoth, will be a '*'
3540  * No mod, no sustain, will be a slate '.'
3541  * </pre>
3542  */
3543 static void display_player_stat_info(player_type *creature_ptr)
3544 {
3545         int i, e_adj;
3546         int stat_col, stat;
3547         int row, col;
3548
3549         object_type *o_ptr;
3550         BIT_FLAGS flgs[TR_FLAG_SIZE];
3551
3552         byte a;
3553         char c;
3554
3555         char buf[80];
3556
3557
3558         /* Column */
3559         stat_col = 22;
3560
3561         /* Row */
3562         row = 3;
3563
3564         /* Print out the labels for the columns */
3565         c_put_str(TERM_WHITE, _("能力", "Stat"), row, stat_col+1);
3566         c_put_str(TERM_BLUE, _("  基本", "  Base"), row, stat_col+7);
3567         c_put_str(TERM_L_BLUE, _(" 種 職 性 装 ", "RacClaPerMod"), row, stat_col+13);
3568         c_put_str(TERM_L_GREEN, _("合計", "Actual"), row, stat_col+28);
3569         c_put_str(TERM_YELLOW, _("現在", "Current"), row, stat_col+35);
3570
3571         /* Display the stats */
3572         for (i = 0; i < A_MAX; i++)
3573         {
3574                 int r_adj;
3575
3576                 if (creature_ptr->mimic_form) r_adj = mimic_info[creature_ptr->mimic_form].r_adj[i];
3577                 else r_adj = rp_ptr->r_adj[i];
3578
3579                 /* Calculate equipment adjustment */
3580                 e_adj = 0;
3581
3582                 /* Icky formula to deal with the 18 barrier */
3583                 if ((creature_ptr->stat_max[i] > 18) && (creature_ptr->stat_top[i] > 18))
3584                         e_adj = (creature_ptr->stat_top[i] - creature_ptr->stat_max[i]) / 10;
3585                 if ((creature_ptr->stat_max[i] <= 18) && (creature_ptr->stat_top[i] <= 18))
3586                         e_adj = creature_ptr->stat_top[i] - creature_ptr->stat_max[i];
3587                 if ((creature_ptr->stat_max[i] <= 18) && (creature_ptr->stat_top[i] > 18))
3588                         e_adj = (creature_ptr->stat_top[i] - 18) / 10 - creature_ptr->stat_max[i] + 18;
3589
3590                 if ((creature_ptr->stat_max[i] > 18) && (creature_ptr->stat_top[i] <= 18))
3591                         e_adj = creature_ptr->stat_top[i] - (creature_ptr->stat_max[i] - 19) / 10 - 19;
3592
3593                 if (PRACE_IS_(creature_ptr, RACE_ENT))
3594                 {
3595                         switch (i)
3596                         {
3597                                 case A_STR:
3598                                 case A_CON:
3599                                         if (creature_ptr->lev > 25) r_adj++;
3600                                         if (creature_ptr->lev > 40) r_adj++;
3601                                         if (creature_ptr->lev > 45) r_adj++;
3602                                         break;
3603                                 case A_DEX:
3604                                         if (creature_ptr->lev > 25) r_adj--;
3605                                         if (creature_ptr->lev > 40) r_adj--;
3606                                         if (creature_ptr->lev > 45) r_adj--;
3607                                         break;
3608                         }
3609                 }
3610
3611                 e_adj -= r_adj;
3612                 e_adj -= cp_ptr->c_adj[i];
3613                 e_adj -= ap_ptr->a_adj[i];
3614
3615                 if (creature_ptr->stat_cur[i] < creature_ptr->stat_max[i])
3616                         /* Reduced name of stat */
3617                         c_put_str(TERM_WHITE, stat_names_reduced[i], row + i+1, stat_col+1);
3618                 else
3619                         c_put_str(TERM_WHITE, stat_names[i], row + i+1, stat_col+1);
3620
3621
3622                 /* Internal "natural" max value.  Maxes at 18/100 */
3623                 /* This is useful to see if you are maxed out */
3624                 cnv_stat(creature_ptr->stat_max[i], buf);
3625                 if (creature_ptr->stat_max[i] == creature_ptr->stat_max_max[i])
3626                 {
3627                         c_put_str(TERM_WHITE, "!", row + i+1, _(stat_col + 6, stat_col + 4));
3628                 }
3629                 c_put_str(TERM_BLUE, buf, row + i+1, stat_col + 13 - strlen(buf));
3630
3631                 /* Race, class, and equipment modifiers */
3632                 (void)sprintf(buf, "%3d", r_adj);
3633                 c_put_str(TERM_L_BLUE, buf, row + i+1, stat_col + 13);
3634                 (void)sprintf(buf, "%3d", (int)cp_ptr->c_adj[i]);
3635                 c_put_str(TERM_L_BLUE, buf, row + i+1, stat_col + 16);
3636                 (void)sprintf(buf, "%3d", (int)ap_ptr->a_adj[i]);
3637                 c_put_str(TERM_L_BLUE, buf, row + i+1, stat_col + 19);
3638                 (void)sprintf(buf, "%3d", (int)e_adj);
3639                 c_put_str(TERM_L_BLUE, buf, row + i+1, stat_col + 22);
3640
3641                 /* Actual maximal modified value */
3642                 cnv_stat(creature_ptr->stat_top[i], buf);
3643                 c_put_str(TERM_L_GREEN, buf, row + i+1, stat_col + 26);
3644
3645                 /* Only display stat_use if not maximal */
3646                 if (creature_ptr->stat_use[i] < creature_ptr->stat_top[i])
3647                 {
3648                         cnv_stat(creature_ptr->stat_use[i], buf);
3649                         c_put_str(TERM_YELLOW, buf, row + i+1, stat_col + 33);
3650                 }
3651         }
3652
3653         /* Column */
3654         col = stat_col + 41;
3655
3656         /* Header and Footer */
3657         c_put_str(TERM_WHITE, "abcdefghijkl@", row, col);
3658         c_put_str(TERM_L_GREEN, _("能力修正", "Modification"), row - 1, col);
3659
3660         /* Process equipment */
3661         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
3662         {
3663                 o_ptr = &creature_ptr->inventory_list[i];
3664
3665                 /* Acquire "known" flags */
3666                 object_flags_known(o_ptr, flgs);
3667
3668                 /* Initialize color based of sign of pval. */
3669                 for (stat = 0; stat < A_MAX; stat++)
3670                 {
3671                         /* Default */
3672                         a = TERM_SLATE;
3673                         c = '.';
3674
3675                         /* Boost */
3676                         if (have_flag(flgs, stat))
3677                         {
3678                                 /* Default */
3679                                 c = '*';
3680
3681                                 /* Good */
3682                                 if (o_ptr->pval > 0)
3683                                 {
3684                                         /* Good */
3685                                         a = TERM_L_GREEN;
3686
3687                                         /* Label boost */
3688                                         if (o_ptr->pval < 10) c = '0' + o_ptr->pval;
3689                                 }
3690
3691                                 if (have_flag(flgs, stat + TR_SUST_STR))
3692                                 {
3693                                         /* Dark green for sustained stats */
3694                                         a = TERM_GREEN;
3695                                 }
3696
3697                                 /* Bad */
3698                                 if (o_ptr->pval < 0)
3699                                 {
3700                                         /* Bad */
3701                                         a = TERM_RED;
3702
3703                                         /* Label boost */
3704                                         if (o_ptr->pval > -10) c = '0' - o_ptr->pval;
3705                                 }
3706                         }
3707
3708                         /* Sustain */
3709                         else if (have_flag(flgs, stat + TR_SUST_STR))
3710                         {
3711                                 /* Dark green "s" */
3712                                 a = TERM_GREEN;
3713                                 c = 's';
3714                         }
3715
3716                         /* Dump proper character */
3717                         Term_putch(col, row + stat+1, a, c);
3718                 }
3719
3720                 /* Advance */
3721                 col++;
3722         }
3723
3724         /* Player flags */
3725         player_flags(flgs);
3726
3727         /* Check stats */
3728         for (stat = 0; stat < A_MAX; stat++)
3729         {
3730                 /* Default */
3731                 a = TERM_SLATE;
3732                 c = '.';
3733
3734                 /* Mutations ... */
3735                 if (creature_ptr->muta3 || creature_ptr->tsuyoshi)
3736                 {
3737                         int dummy = 0;
3738
3739                         if (stat == A_STR)
3740                         {
3741                                 if (creature_ptr->muta3 & MUT3_HYPER_STR) dummy += 4;
3742                                 if (creature_ptr->muta3 & MUT3_PUNY) dummy -= 4;
3743                                 if (creature_ptr->tsuyoshi) dummy += 4;
3744                         }
3745                         else if (stat == A_WIS || stat == A_INT)
3746                         {
3747                                 if (creature_ptr->muta3 & MUT3_HYPER_INT) dummy += 4;
3748                                 if (creature_ptr->muta3 & MUT3_MORONIC) dummy -= 4;
3749                         }
3750                         else if (stat == A_DEX)
3751                         {
3752                                 if (creature_ptr->muta3 & MUT3_IRON_SKIN) dummy -= 1;
3753                                 if (creature_ptr->muta3 & MUT3_LIMBER) dummy += 3;
3754                                 if (creature_ptr->muta3 & MUT3_ARTHRITIS) dummy -= 3;
3755                         }
3756                         else if (stat == A_CON)
3757                         {
3758                                 if (creature_ptr->muta3 & MUT3_RESILIENT) dummy += 4;
3759                                 if (creature_ptr->muta3 & MUT3_XTRA_FAT) dummy += 2;
3760                                 if (creature_ptr->muta3 & MUT3_ALBINO) dummy -= 4;
3761                                 if (creature_ptr->muta3 & MUT3_FLESH_ROT) dummy -= 2;
3762                                 if (creature_ptr->tsuyoshi) dummy += 4;
3763                         }
3764                         else if (stat == A_CHR)
3765                         {
3766                                 if (creature_ptr->muta3 & MUT3_SILLY_VOI) dummy -= 4;
3767                                 if (creature_ptr->muta3 & MUT3_BLANK_FAC) dummy -= 1;
3768                                 if (creature_ptr->muta3 & MUT3_FLESH_ROT) dummy -= 1;
3769                                 if (creature_ptr->muta3 & MUT3_SCALES) dummy -= 1;
3770                                 if (creature_ptr->muta3 & MUT3_WART_SKIN) dummy -= 2;
3771                                 if (creature_ptr->muta3 & MUT3_ILL_NORM) dummy = 0;
3772                         }
3773
3774                         /* Boost */
3775                         if (dummy)
3776                         {
3777                                 /* Default */
3778                                 c = '*';
3779
3780                                 /* Good */
3781                                 if (dummy > 0)
3782                                 {
3783                                         /* Good */
3784                                         a = TERM_L_GREEN;
3785
3786                                         /* Label boost */
3787                                         if (dummy < 10) c = '0' + dummy;
3788                                 }
3789
3790                                 /* Bad */
3791                                 if (dummy < 0)
3792                                 {
3793                                         /* Bad */
3794                                         a = TERM_RED;
3795
3796                                         /* Label boost */
3797                                         if (dummy > -10) c = '0' - dummy;
3798                                 }
3799                         }
3800                 }
3801
3802
3803                 /* Sustain */
3804                 if (have_flag(flgs, stat + TR_SUST_STR))
3805                 {
3806                         /* Dark green "s" */
3807                         a = TERM_GREEN;
3808                         c = 's';
3809                 }
3810
3811
3812                 /* Dump */
3813                 Term_putch(col, row + stat+1, a, c);
3814         }
3815 }
3816
3817
3818 /*!
3819  * @brief プレイヤーのステータス表示メイン処理
3820  * Display the character on the screen (various modes)
3821  * @param mode 表示モードID
3822  * @return なし
3823  * @details
3824  * <pre>
3825  * The top one and bottom two lines are left blank.
3826  * Mode 0 = standard display with skills
3827  * Mode 1 = standard display with history
3828  * Mode 2 = summary of various things
3829  * Mode 3 = summary of various things (part 2)
3830  * Mode 4 = mutations
3831  * </pre>
3832  */
3833 void display_player(player_type *creature_ptr, int mode)
3834 {
3835         int i;
3836         char buf[80];
3837         char tmp[64];
3838
3839         if ((creature_ptr->muta1 || creature_ptr->muta2 || creature_ptr->muta3) && display_mutations)
3840                 mode = (mode % 5);
3841         else
3842                 mode = (mode % 4);
3843
3844         /* Erase screen */
3845         clear_from(0);
3846
3847         /* Standard */
3848         if ((mode == 0) || (mode == 1))
3849         {
3850                 /* Name, Sex, Race, Class */
3851 #ifdef JP
3852                 sprintf(tmp, "%s%s%s", ap_ptr->title, ap_ptr->no == 1 ? "の":"", creature_ptr->name);
3853 #else
3854                 sprintf(tmp, "%s %s", ap_ptr->title, creature_ptr->name);
3855 #endif
3856
3857                 display_player_one_line(ENTRY_NAME, tmp, TERM_L_BLUE);
3858                 display_player_one_line(ENTRY_SEX, sp_ptr->title, TERM_L_BLUE);
3859                 display_player_one_line(ENTRY_RACE, (creature_ptr->mimic_form ? mimic_info[creature_ptr->mimic_form].title : rp_ptr->title), TERM_L_BLUE);
3860                 display_player_one_line(ENTRY_CLASS, cp_ptr->title, TERM_L_BLUE);
3861
3862                 if (creature_ptr->realm1)
3863                 {
3864                         if (creature_ptr->realm2)
3865                                 sprintf(tmp, "%s, %s", realm_names[creature_ptr->realm1], realm_names[creature_ptr->realm2]);
3866                         else
3867                                 strcpy(tmp, realm_names[creature_ptr->realm1]);
3868                         display_player_one_line(ENTRY_REALM, tmp, TERM_L_BLUE);
3869                 }
3870
3871                 if ((creature_ptr->pclass == CLASS_CHAOS_WARRIOR) || (creature_ptr->muta2 & MUT2_CHAOS_GIFT))
3872                         display_player_one_line(ENTRY_PATRON, chaos_patrons[creature_ptr->chaos_patron], TERM_L_BLUE);
3873
3874                 /* Age, Height, Weight, Social */
3875                 /* 身長はセンチメートルに、体重はキログラムに変更してあります */
3876 #ifdef JP
3877                 display_player_one_line(ENTRY_AGE, format("%d才" ,(int)creature_ptr->age), TERM_L_BLUE);
3878                 display_player_one_line(ENTRY_HEIGHT, format("%dcm" ,(int)((creature_ptr->ht*254)/100)), TERM_L_BLUE);
3879                 display_player_one_line(ENTRY_WEIGHT, format("%dkg" ,(int)((creature_ptr->wt*4536)/10000)), TERM_L_BLUE);
3880                 display_player_one_line(ENTRY_SOCIAL, format("%d  " ,(int)creature_ptr->sc), TERM_L_BLUE);
3881 #else
3882                 display_player_one_line(ENTRY_AGE, format("%d" ,(int)creature_ptr->age), TERM_L_BLUE);
3883                 display_player_one_line(ENTRY_HEIGHT, format("%d" ,(int)creature_ptr->ht), TERM_L_BLUE);
3884                 display_player_one_line(ENTRY_WEIGHT, format("%d" ,(int)creature_ptr->wt), TERM_L_BLUE);
3885                 display_player_one_line(ENTRY_SOCIAL, format("%d" ,(int)creature_ptr->sc), TERM_L_BLUE);
3886 #endif
3887                 display_player_one_line(ENTRY_ALIGN, format("%s" ,your_alignment(creature_ptr)), TERM_L_BLUE);
3888
3889
3890                 /* Display the stats */
3891                 for (i = 0; i < A_MAX; i++)
3892                 {
3893                         /* Special treatment of "injured" stats */
3894                         if (creature_ptr->stat_cur[i] < creature_ptr->stat_max[i])
3895                         {
3896                                 int value;
3897
3898                                 /* Use lowercase stat name */
3899                                 put_str(stat_names_reduced[i], 3 + i, 53);
3900
3901                                 /* Get the current stat */
3902                                 value = creature_ptr->stat_use[i];
3903
3904                                 /* Obtain the current stat (modified) */
3905                                 cnv_stat(value, buf);
3906
3907                                 /* Display the current stat (modified) */
3908                                 c_put_str(TERM_YELLOW, buf, 3 + i, 60);
3909
3910                                 /* Acquire the max stat */
3911                                 value = creature_ptr->stat_top[i];
3912
3913                                 /* Obtain the maximum stat (modified) */
3914                                 cnv_stat(value, buf);
3915
3916                                 /* Display the maximum stat (modified) */
3917                                 c_put_str(TERM_L_GREEN, buf, 3 + i, 67);
3918                         }
3919
3920                         /* Normal treatment of "normal" stats */
3921                         else
3922                         {
3923                                 /* Assume uppercase stat name */
3924                                 put_str(stat_names[i], 3 + i, 53);
3925
3926                                 /* Obtain the current stat (modified) */
3927                                 cnv_stat(creature_ptr->stat_use[i], buf);
3928
3929                                 /* Display the current stat (modified) */
3930                                 c_put_str(TERM_L_GREEN, buf, 3 + i, 60);
3931                         }
3932
3933                         if (creature_ptr->stat_max[i] == creature_ptr->stat_max_max[i])
3934                         {
3935                                 c_put_str(TERM_WHITE, "!", 3 + i, _(58, 58-2));
3936                         }
3937                 }
3938
3939                 /* Display "history" info */
3940                 if (mode == 1)
3941                 {
3942                         char statmsg[1000];
3943                         put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
3944
3945                         for (i = 0; i < 4; i++)
3946                         {
3947                                 put_str(creature_ptr->history[i], i + 12, 10);
3948                         }
3949
3950                         *statmsg = '\0';
3951
3952                         if (creature_ptr->is_dead)
3953                         {
3954                                 if (creature_ptr->total_winner)
3955                                 {
3956 #ifdef JP
3957                                         sprintf(statmsg, "…あなたは勝利の後%sした。", streq(creature_ptr->died_from, "Seppuku") ? "切腹" : "引退");
3958 #else
3959                                         sprintf(statmsg, "...You %s after the winning.", streq(creature_ptr->died_from, "Seppuku") ? "did Seppuku" : "retired from the adventure");
3960 #endif
3961                                 }
3962                                 else if (!current_floor_ptr->dun_level)
3963                                 {
3964 #ifdef JP
3965                                         sprintf(statmsg, "…あなたは%sで%sに殺された。", map_name(), creature_ptr->died_from);
3966 #else
3967                                         sprintf(statmsg, "...You were killed by %s in %s.", creature_ptr->died_from, map_name());
3968 #endif
3969                                 }
3970                                 else if (creature_ptr->inside_quest && is_fixed_quest_idx(creature_ptr->inside_quest))
3971                                 {
3972                                         /* Get the quest text */
3973                                         /* Bewere that INIT_ASSIGN resets the cur_num. */
3974                                         init_flags = INIT_NAME_ONLY;
3975
3976                                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3977
3978 #ifdef JP
3979                                         sprintf(statmsg, "…あなたは、クエスト「%s」で%sに殺された。", quest[creature_ptr->inside_quest].name, creature_ptr->died_from);
3980 #else
3981                                         sprintf(statmsg, "...You were killed by %s in the quest '%s'.", creature_ptr->died_from, quest[creature_ptr->inside_quest].name);
3982 #endif
3983                                 }
3984                                 else
3985                                 {
3986 #ifdef JP
3987                                         sprintf(statmsg, "…あなたは、%sの%d階で%sに殺された。", map_name(), (int)current_floor_ptr->dun_level, creature_ptr->died_from);
3988 #else
3989                                         sprintf(statmsg, "...You were killed by %s on level %d of %s.", creature_ptr->died_from, current_floor_ptr->dun_level, map_name());
3990 #endif
3991                                 }
3992                         }
3993                         else if (current_world_ptr->character_dungeon)
3994                         {
3995                                 if (!current_floor_ptr->dun_level)
3996                                 {
3997                                         sprintf(statmsg, _("…あなたは現在、 %s にいる。", "...Now, you are in %s."), map_name());
3998                                 }
3999                                 else if (creature_ptr->inside_quest && is_fixed_quest_idx(creature_ptr->inside_quest))
4000                                 {
4001                                         /* Clear the text */
4002                                         /* Must be done before doing INIT_SHOW_TEXT */
4003                                         for (i = 0; i < 10; i++)
4004                                         {
4005                                                 quest_text[i][0] = '\0';
4006                                         }
4007                                         quest_text_line = 0;
4008
4009                                         /* Get the quest text */
4010                                         init_flags = INIT_NAME_ONLY;
4011
4012                                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
4013
4014                                         sprintf(statmsg, _("…あなたは現在、 クエスト「%s」を遂行中だ。", "...Now, you are in the quest '%s'."), quest[creature_ptr->inside_quest].name);
4015                                 }
4016                                 else
4017                                 {
4018 #ifdef JP
4019                                         sprintf(statmsg, "…あなたは現在、 %s の %d 階で探索している。", map_name(), (int)current_floor_ptr->dun_level);
4020 #else
4021                                         sprintf(statmsg, "...Now, you are exploring level %d of %s.", current_floor_ptr->dun_level, map_name());
4022 #endif
4023                                 }
4024                         }
4025
4026                         if (*statmsg)
4027                         {
4028                                 char temp[64*2], *t;
4029                                 roff_to_buf(statmsg, 60, temp, sizeof(temp));
4030                                 t = temp;
4031                                 for(i=0 ; i<2 ; i++)
4032                                 {
4033                                         if(t[0]==0)
4034                                                 break; 
4035                                         else
4036                                         {
4037                                                 put_str(t, i + 5 + 12, 10);
4038                                                 t += strlen(t)+1;
4039                                         }
4040                                 }
4041                         }
4042
4043                 }
4044
4045                 /* Display "various" info */
4046                 else
4047                 {
4048                         display_player_middle(creature_ptr);
4049                         display_player_various();
4050                 }
4051         }
4052
4053         /* Special */
4054         else if (mode == 2)
4055         {
4056                 /* See "http://www.cs.berkeley.edu/~davidb/angband.html" */
4057
4058                 /* Dump the info */
4059                 display_player_misc_info();
4060                 display_player_stat_info(creature_ptr);
4061                 display_player_flag_info();
4062         }
4063
4064         /* Special */
4065         else if (mode == 3)
4066         {
4067                 display_player_other_flag_info();
4068         }
4069
4070         else if (mode == 4)
4071         {
4072                 do_cmd_knowledge_mutations(creature_ptr);
4073         }
4074 }
4075
4076 /*!
4077  * @brief プレイヤーのステータス表示をファイルにダンプする
4078  * @param fff ファイルポインタ
4079  * @return なし
4080  */
4081 static void dump_aux_display_player(FILE *fff)
4082 {
4083         TERM_LEN x, y;
4084         TERM_COLOR a;
4085         char c;
4086         char buf[1024];
4087
4088         display_player(p_ptr, 0);
4089
4090         /* Dump part of the screen */
4091         for (y = 1; y < 22; y++)
4092         {
4093                 /* Dump each row */
4094                 for (x = 0; x < 79; x++)
4095                 {
4096                         /* Get the attr/char */
4097                         (void)(Term_what(x, y, &a, &c));
4098
4099                         /* Dump it */
4100                         buf[x] = c;
4101                 }
4102
4103                 /* End the string */
4104                 buf[x] = '\0';
4105
4106                 /* Kill trailing spaces */
4107                 while ((x > 0) && (buf[x-1] == ' ')) buf[--x] = '\0';
4108
4109                 /* End the row */
4110                 fprintf(fff, _("%s\n", "%s\n"), buf);
4111         }
4112
4113         /* Display history */
4114         display_player(p_ptr, 1);
4115
4116         /* Dump part of the screen */
4117         for (y = 10; y < 19; y++)
4118         {
4119                 /* Dump each row */
4120                 for (x = 0; x < 79; x++)
4121                 {
4122                         /* Get the attr/char */
4123                         (void)(Term_what(x, y, &a, &c));
4124
4125                         /* Dump it */
4126                         buf[x] = c;
4127                 }
4128
4129                 /* End the string */
4130                 buf[x] = '\0';
4131
4132                 /* Kill trailing spaces */
4133                 while ((x > 0) && (buf[x-1] == ' ')) buf[--x] = '\0';
4134
4135                 /* End the row */
4136                 fprintf(fff, "%s\n", buf);
4137         }
4138
4139         fprintf(fff, "\n");
4140
4141         /* Display flags (part 1) */
4142         display_player(p_ptr, 2);
4143
4144         /* Dump part of the screen */
4145         for (y = 2; y < 22; y++)
4146         {
4147                 /* Dump each row */
4148                 for (x = 0; x < 79; x++)
4149                 {
4150                         /* Get the attr/char */
4151                         (void)(Term_what(x, y, &a, &c));
4152
4153                         /* Dump it (Ignore equippy tile graphic) */
4154                         if (a < 128)
4155                                 buf[x] = c;
4156                         else
4157                                 buf[x] = ' ';
4158                 }
4159
4160                 /* End the string */
4161                 buf[x] = '\0';
4162
4163                 /* Kill trailing spaces */
4164                 while ((x > 0) && (buf[x-1] == ' ')) buf[--x] = '\0';
4165
4166                 /* End the row */
4167                 fprintf(fff, "%s\n", buf);
4168         }
4169
4170         fprintf(fff, "\n");
4171
4172         /* Display flags (part 2) */
4173         display_player(p_ptr, 3);
4174
4175         /* Dump part of the screen */
4176         for (y = 1; y < 22; y++)
4177         {
4178                 /* Dump each row */
4179                 for (x = 0; x < 79; x++)
4180                 {
4181                         /* Get the attr/char */
4182                         (void)(Term_what(x, y, &a, &c));
4183
4184                         /* Dump it (Ignore equippy tile graphic) */
4185                         if (a < 128)
4186                                 buf[x] = c;
4187                         else
4188                                 buf[x] = ' ';
4189                 }
4190
4191                 /* End the string */
4192                 buf[x] = '\0';
4193
4194                 /* Kill trailing spaces */
4195                 while ((x > 0) && (buf[x-1] == ' ')) buf[--x] = '\0';
4196
4197                 /* End the row */
4198                 fprintf(fff, "%s\n", buf);
4199         }
4200
4201         fprintf(fff, "\n");
4202 }
4203
4204
4205 /*!
4206  * @brief プレイヤーのペット情報をファイルにダンプする
4207  * @param fff ファイルポインタ
4208  * @return なし
4209  */
4210 static void dump_aux_pet(FILE *fff)
4211 {
4212         int i;
4213         bool pet = FALSE;
4214         bool pet_settings = FALSE;
4215         GAME_TEXT pet_name[MAX_NLEN];
4216
4217         for (i = current_floor_ptr->m_max - 1; i >= 1; i--)
4218         {
4219                 monster_type *m_ptr = &current_floor_ptr->m_list[i];
4220
4221                 if (!monster_is_valid(m_ptr)) continue;
4222                 if (!is_pet(m_ptr)) continue;
4223                 pet_settings = TRUE;
4224                 if (!m_ptr->nickname && (p_ptr->riding != i)) continue;
4225                 if (!pet)
4226                 {
4227                         fprintf(fff, _("\n\n  [主なペット]\n\n", "\n\n  [Leading Pets]\n\n"));
4228                         pet = TRUE;
4229                 }
4230                 monster_desc(pet_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
4231                 fprintf(fff, "%s\n", pet_name);
4232         }
4233
4234         if (pet_settings)
4235         {
4236                 fprintf(fff, _("\n\n  [ペットへの命令]\n", "\n\n  [Command for Pets]\n"));
4237
4238                 fprintf(fff, _("\n ドアを開ける:                       %s", "\n Pets open doors:                    %s"), 
4239                                         (p_ptr->pet_extra_flags & PF_OPEN_DOORS) ? "ON" : "OFF");
4240
4241                 fprintf(fff, _("\n アイテムを拾う:                     %s", "\n Pets pick up items:                 %s"),
4242                                         (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS) ? "ON" : "OFF");
4243
4244                 fprintf(fff, _("\n テレポート系魔法を使う:             %s", "\n Allow teleport:                     %s"),
4245                                         (p_ptr->pet_extra_flags & PF_TELEPORT) ? "ON" : "OFF");
4246
4247                 fprintf(fff, _("\n 攻撃魔法を使う:                     %s", "\n Allow cast attack spell:            %s"),
4248                                         (p_ptr->pet_extra_flags & PF_ATTACK_SPELL) ? "ON" : "OFF");
4249
4250                 fprintf(fff, _("\n 召喚魔法を使う:                     %s", "\n Allow cast summon spell:            %s"),
4251                                         (p_ptr->pet_extra_flags & PF_SUMMON_SPELL) ? "ON" : "OFF");
4252
4253                 fprintf(fff, _("\n プレイヤーを巻き込む範囲魔法を使う: %s", "\n Allow involve player in area spell: %s"),
4254                                         (p_ptr->pet_extra_flags & PF_BALL_SPELL) ? "ON" : "OFF");
4255
4256                 fputc('\n', fff);
4257         }
4258 }
4259
4260
4261 /*!
4262  * @brief プレイヤーの職業能力情報をファイルにダンプする
4263  * @param fff ファイルポインタ
4264  * @return なし
4265  */
4266 static void dump_aux_class_special(FILE *fff)
4267 {
4268         if (p_ptr->pclass == CLASS_BLUE_MAGE)
4269         {
4270                 int i = 0;
4271                 int j = 0;
4272                 int l1 = 0;
4273                 int l2 = 0;
4274                 int num = 0;
4275                 int spellnum[MAX_MONSPELLS];
4276                 BIT_FLAGS f4 = 0, f5 = 0, f6 = 0;
4277                 char p[60][80];
4278                 int col = 0;
4279                 bool pcol = FALSE;
4280
4281                 for (i=0;i<60;i++) { p[i][0] = '\0'; }
4282
4283                 strcat(p[col], _("\n\n  [学習済みの青魔法]\n", "\n\n  [Learned Blue Magic]\n"));
4284
4285                 for (j=1;j<6;j++)
4286                 {
4287                         col++;
4288                         set_rf_masks(&f4, &f5, &f6, j);
4289                         switch(j)
4290                         {
4291                                 case MONSPELL_TYPE_BOLT:
4292                                         strcat(p[col], _("\n     [ボルト型]\n", "\n     [Bolt  Type]\n"));
4293                                         break;
4294
4295                                 case MONSPELL_TYPE_BALL:
4296                                         strcat(p[col], _("\n     [ボール型]\n", "\n     [Ball  Type]\n"));
4297                                         break;
4298
4299                                 case MONSPELL_TYPE_BREATH:
4300                                         strcat(p[col], _("\n     [ブレス型]\n", "\n     [  Breath  ]\n"));
4301                                         break;
4302
4303                                 case MONSPELL_TYPE_SUMMON:
4304                                         strcat(p[col], _("\n     [召喚魔法]\n", "\n     [Summonning]\n"));
4305                                         break;
4306
4307                                 case MONSPELL_TYPE_OTHER:
4308                                         strcat(p[col], _("\n     [ その他 ]\n", "\n     [Other Type]\n"));
4309                                         break;
4310                         }
4311
4312                         for (i = 0, num = 0; i < 32; i++)
4313                         {
4314                                 if ((0x00000001 << i) & f4) spellnum[num++] = i;
4315                         }
4316                         for (; i < 64; i++)
4317                         {
4318                                 if ((0x00000001 << (i - 32)) & f5) spellnum[num++] = i;
4319                         }
4320                         for (; i < 96; i++)
4321                         {
4322                                 if ((0x00000001 << (i - 64)) & f6) spellnum[num++] = i;
4323                         }
4324
4325                         col++;
4326                         pcol = FALSE;
4327                         strcat(p[col], "       ");
4328
4329                         for (i = 0; i < num; i++)
4330                         {
4331                                 if (p_ptr->magic_num2[spellnum[i]])
4332                                 {
4333                                         pcol = TRUE;
4334                                         /* Dump blue magic */
4335                                         l1 = strlen(p[col]);
4336                                         l2 = strlen(monster_powers_short[spellnum[i]]);
4337                                         if ((l1 + l2) >= 75)
4338                                         {
4339                                                 strcat(p[col], "\n");
4340                                                 col++;
4341                                                 strcat(p[col], "       ");
4342                                         }
4343                                         strcat(p[col], monster_powers_short[spellnum[i]]);
4344                                         strcat(p[col], ", ");
4345                                 }
4346                         }
4347                         
4348                         if (!pcol)
4349                         {
4350                                 strcat(p[col], _("なし", "None"));
4351                         }
4352                         else
4353                         {
4354                                 if (p[col][strlen(p[col])-2] == ',')
4355                                 {
4356                                         p[col][strlen(p[col])-2] = '\0';
4357                                 }
4358                                 else
4359                                 {
4360                                         p[col][strlen(p[col])-10] = '\0';
4361                                 }
4362                         }
4363                         
4364                         strcat(p[col], "\n");
4365                 }
4366
4367                 for (i=0;i<=col;i++)
4368                 {
4369                         fputs(p[i], fff);
4370                 }
4371         }
4372         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4373         {
4374                 char s[EATER_EXT][MAX_NLEN];
4375                 OBJECT_TYPE_VALUE tval = 0;
4376                 int ext;
4377                 KIND_OBJECT_IDX k_idx;
4378                 OBJECT_SUBTYPE_VALUE i;
4379                 int magic_num;
4380
4381                 fprintf(fff, _("\n\n  [取り込んだ魔法道具]\n", "\n\n  [Magic devices eaten]\n"));
4382
4383                 for (ext = 0; ext < 3; ext++)
4384                 {
4385                         int eat_num = 0;
4386
4387                         /* Dump an extent name */
4388                         switch (ext)
4389                         {
4390                         case 0:
4391                                 tval = TV_STAFF;
4392                                 fprintf(fff, _("\n[杖]\n", "\n[Staffs]\n"));
4393                                 break;
4394                         case 1:
4395                                 tval = TV_WAND;
4396                                 fprintf(fff, _("\n[魔法棒]\n", "\n[Wands]\n"));
4397                                 break;
4398                         case 2:
4399                                 tval = TV_ROD;
4400                                 fprintf(fff, _("\n[ロッド]\n", "\n[Rods]\n"));
4401                                 break;
4402                         }
4403
4404                         /* Get magic device names that were eaten */
4405                         for (i = 0; i < EATER_EXT; i++)
4406                         {
4407                                 int idx = EATER_EXT * ext + i;
4408
4409                                 magic_num = p_ptr->magic_num2[idx];
4410                                 if (!magic_num) continue;
4411
4412                                 k_idx = lookup_kind(tval, i);
4413                                 if (!k_idx) continue;
4414                                 sprintf(s[eat_num], "%23s (%2d)", (k_name + k_info[k_idx].name), magic_num);
4415                                 eat_num++;
4416                         }
4417
4418                         /* Dump magic devices in this extent */
4419                         if (eat_num > 0)
4420                         {
4421                                 for (i = 0; i < eat_num; i++)
4422                                 {
4423                                         fputs(s[i], fff);
4424                                         if (i % 3 < 2) fputs("    ", fff);
4425                                         else fputs("\n", fff);
4426                                 }
4427
4428                                 if (i % 3 > 0) fputs("\n", fff);
4429                         }
4430                         else /* Not found */
4431                         {
4432                                 fputs(_("  (なし)\n", "  (none)\n"), fff);
4433                         }
4434                 }
4435         }
4436         else if (p_ptr->pclass == CLASS_SMITH)
4437         {
4438                 int i, id[250], n = 0, row;
4439
4440                 fprintf(fff, _("\n\n  [手に入れたエッセンス]\n\n", "\n\n  [Get Essence]\n\n"));
4441                 fprintf(fff, _("エッセンス   個数     エッセンス   個数     エッセンス   個数", 
4442                                            "Essence      Num      Essence      Num      Essence      Num "));
4443                 for (i = 0; essence_name[i]; i++)
4444                 {
4445                         if (!essence_name[i][0]) continue;
4446                         id[n] = i;
4447                         n++;
4448                 }
4449
4450                 row = n / 3 + 1;
4451
4452                 for (i = 0; i < row; i++)
4453                 {
4454                         fprintf(fff, "\n");
4455                         fprintf(fff, "%-11s %5d     ", essence_name[id[i]], (int)p_ptr->magic_num1[id[i]]);
4456                         if(i + row < n) fprintf(fff, "%-11s %5d     ", essence_name[id[i + row]], (int)p_ptr->magic_num1[id[i + row]]);
4457                         if(i + row * 2 < n) fprintf(fff, "%-11s %5d", essence_name[id[i + row * 2]], (int)p_ptr->magic_num1[id[i + row * 2]]);
4458                 }
4459
4460                 fputs("\n", fff);
4461
4462         }
4463 }
4464
4465
4466 /*!
4467  * @brief クエスト情報をファイルにダンプする
4468  * @param fff ファイルポインタ
4469  * @return なし
4470  */
4471 static void dump_aux_quest(FILE *fff)
4472 {
4473         QUEST_IDX i;
4474         QUEST_IDX *quest_num;
4475         int dummy;
4476
4477         fprintf(fff, _("\n\n  [クエスト情報]\n", "\n\n  [Quest Information]\n"));
4478
4479         /* Allocate Memory */
4480         C_MAKE(quest_num, max_q_idx, QUEST_IDX);
4481
4482         /* Sort by compete level */
4483         for (i = 1; i < max_q_idx; i++) quest_num[i] = i;
4484         ang_sort(quest_num, &dummy, max_q_idx, ang_sort_comp_quest_num, ang_sort_swap_quest_num);
4485
4486         /* Dump Quest Information */
4487         fputc('\n', fff);
4488         do_cmd_knowledge_quests_completed(fff, quest_num);
4489         fputc('\n', fff);
4490         do_cmd_knowledge_quests_failed(fff, quest_num);
4491         fputc('\n', fff);
4492
4493         /* Free Memory */
4494         C_KILL(quest_num, max_q_idx, QUEST_IDX);
4495 }
4496
4497
4498 /*!
4499  * @brief 死の直前メッセージ並びに遺言をファイルにダンプする
4500  * @param fff ファイルポインタ
4501  * @return なし
4502  */
4503 static void dump_aux_last_message(FILE *fff)
4504 {
4505         if (p_ptr->is_dead)
4506         {
4507                 if (!p_ptr->total_winner)
4508                 {
4509                         int i;
4510
4511                         fprintf(fff, _("\n  [死ぬ直前のメッセージ]\n\n", "\n  [Last Messages]\n\n"));
4512                         for (i = MIN(message_num(), 30); i >= 0; i--)
4513                         {
4514                                 fprintf(fff,"> %s\n",message_str((s16b)i));
4515                         }
4516                         fputc('\n', fff);
4517                 }
4518
4519                 /* Hack -- *Winning* message */
4520                 else if (p_ptr->last_message)
4521                 {
4522                         fprintf(fff, _("\n  [*勝利*メッセージ]\n\n", "\n  [*Winning* Message]\n\n"));
4523                         fprintf(fff,"  %s\n", p_ptr->last_message);
4524                         fputc('\n', fff);
4525                 }
4526         }
4527 }
4528
4529 /*!
4530  * @brief 帰還場所情報をファイルにダンプする
4531  * @param fff ファイルポインタ
4532  * @return なし
4533  */
4534 static void dump_aux_recall(FILE *fff)
4535 {
4536         int y;
4537         fprintf(fff, _("\n  [帰還場所]\n\n", "\n  [Recall Depth]\n\n"));
4538
4539         for (y = 1; y < max_d_idx; y++)
4540         {
4541                 bool seiha = FALSE;
4542
4543                 if (!d_info[y].maxdepth) continue;
4544                 if (!max_dlv[y]) continue;
4545                 if (d_info[y].final_guardian)
4546                 {
4547                         if (!r_info[d_info[y].final_guardian].max_num) seiha = TRUE;
4548                 }
4549                 else if (max_dlv[y] == d_info[y].maxdepth) seiha = TRUE;
4550
4551                 fprintf(fff, _("   %c%-12s: %3d 階\n", "   %c%-16s: level %3d\n"),
4552                         seiha ? '!' : ' ', d_name+d_info[y].name, (int)max_dlv[y]);
4553         }
4554 }
4555
4556
4557 /*!
4558  * @brief オプション情報をファイルにダンプする
4559  * @param fff ファイルポインタ
4560  * @return なし
4561  */
4562 static void dump_aux_options(FILE *fff)
4563 {
4564         fprintf(fff, _("\n  [オプション設定]\n", "\n  [Option Settings]\n"));
4565
4566         if (preserve_mode)
4567                 fprintf(fff, _("\n 保存モード:         ON", "\n Preserve Mode:      ON"));
4568
4569         else
4570                 fprintf(fff, _("\n 保存モード:         OFF", "\n Preserve Mode:      OFF"));
4571
4572         if (ironman_small_levels)
4573                 fprintf(fff, _("\n 小さいダンジョン:   ALWAYS", "\n Small Levels:       ALWAYS"));
4574         else if (always_small_levels)
4575                 fprintf(fff, _("\n 小さいダンジョン:   ON", "\n Small Levels:       ON"));
4576         else if (small_levels)
4577                 fprintf(fff, _("\n 小さいダンジョン:   ENABLED", "\n Small Levels:       ENABLED"));
4578         else
4579                 fprintf(fff, _("\n 小さいダンジョン:   OFF", "\n Small Levels:       OFF"));
4580
4581
4582         if (vanilla_town)
4583                 fprintf(fff, _("\n 元祖の町のみ:       ON", "\n Vanilla Town:       ON"));
4584         else if (lite_town)
4585                 fprintf(fff, _("\n 小規模な町:         ON", "\n Lite Town:          ON"));
4586
4587
4588         if (ironman_shops)
4589                 fprintf(fff, _("\n 店なし:             ON", "\n No Shops:           ON"));
4590
4591         if (ironman_downward)
4592                 fprintf(fff, _("\n 階段を上がれない:   ON", "\n Diving Only:        ON"));
4593
4594         if (ironman_rooms)
4595                 fprintf(fff, _("\n 普通でない部屋:     ON", "\n Unusual Rooms:      ON"));
4596
4597         if (ironman_nightmare)
4598                 fprintf(fff, _("\n 悪夢モード:         ON", "\n Nightmare Mode:     ON"));
4599
4600
4601         if (ironman_empty_levels)
4602                 fprintf(fff, _("\n アリーナ:           ALWAYS", "\n Arena Levels:       ALWAYS"));
4603         else if (empty_levels)
4604                 fprintf(fff, _("\n アリーナ:           ENABLED", "\n Arena Levels:       ENABLED"));
4605         else
4606                 fprintf(fff, _("\n アリーナ:           OFF", "\n Arena Levels:       OFF"));
4607
4608         fputc('\n', fff);
4609
4610         if (p_ptr->noscore)
4611                 fprintf(fff, _("\n 何か不正なことをしてしまっています。\n", "\n You have done something illegal.\n"));
4612
4613         fputc('\n', fff);
4614 }
4615
4616
4617 /*!
4618  * @brief 闘技場の情報をファイルにダンプする
4619  * @param fff ファイルポインタ
4620  * @return なし
4621  */
4622 static void dump_aux_arena(FILE *fff)
4623 {
4624         if (lite_town || vanilla_town) return;
4625
4626         if (p_ptr->arena_number < 0)
4627         {
4628                 if (p_ptr->arena_number <= ARENA_DEFEATED_OLD_VER)
4629                 {
4630                         fprintf(fff, _("\n 闘技場: 敗北\n", "\n Arena: Defeated\n"));
4631                 }
4632                 else
4633                 {
4634 #ifdef JP
4635                         fprintf(fff, "\n 闘技場: %d回戦で%sの前に敗北\n", -p_ptr->arena_number,
4636                                 r_name + r_info[arena_info[-1 - p_ptr->arena_number].r_idx].name);
4637 #else
4638                         fprintf(fff, "\n Arena: Defeated by %s in the %d%s fight\n",
4639                                 r_name + r_info[arena_info[-1 - p_ptr->arena_number].r_idx].name,
4640                                 -p_ptr->arena_number, get_ordinal_number_suffix(-p_ptr->arena_number));
4641 #endif
4642                 }
4643         }
4644         else if (p_ptr->arena_number > MAX_ARENA_MONS + 2)
4645         {
4646                 fprintf(fff, _("\n 闘技場: 真のチャンピオン\n", "\n Arena: True Champion\n"));
4647         }
4648         else if (p_ptr->arena_number > MAX_ARENA_MONS - 1)
4649         {
4650                 fprintf(fff, _("\n 闘技場: チャンピオン\n", "\n Arena: Champion\n"));
4651         }
4652         else
4653         {
4654 #ifdef JP
4655                 fprintf(fff, "\n 闘技場: %2d勝\n", (p_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : p_ptr->arena_number));
4656 #else
4657                 fprintf(fff, "\n Arena: %2d Victor%s\n", (p_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : p_ptr->arena_number), (p_ptr->arena_number > 1) ? "ies" : "y");
4658 #endif
4659         }
4660
4661         fprintf(fff, "\n");
4662 }
4663
4664
4665 /*!
4666  * @brief 撃破モンスターの情報をファイルにダンプする
4667  * @param fff ファイルポインタ
4668  * @return なし
4669  */
4670 static void dump_aux_monsters(FILE *fff)
4671 {
4672         /* Monsters slain */
4673
4674         IDX k;
4675         long uniq_total = 0;
4676         long norm_total = 0;
4677         MONRACE_IDX *who;
4678
4679         /* Sort by monster level */
4680         u16b why = 2;
4681
4682         fprintf(fff, _("\n  [倒したモンスター]\n\n", "\n  [Defeated Monsters]\n\n"));
4683
4684         /* Allocate the "who" array */
4685         C_MAKE(who, max_r_idx, MONRACE_IDX);
4686
4687         /* Count monster kills */
4688         for (k = 1; k < max_r_idx; k++)
4689         {
4690                 monster_race *r_ptr = &r_info[k];
4691
4692                 /* Ignore unused index */
4693                 if (!r_ptr->name) continue;
4694
4695                 if (r_ptr->flags1 & RF1_UNIQUE)
4696                 {
4697                         bool dead = (r_ptr->max_num == 0);
4698                         if (dead)
4699                         {
4700                                 norm_total++;
4701
4702                                 /* Add a unique monster to the list */
4703                                 who[uniq_total++] = k;
4704                         }
4705                 }
4706                 else
4707                 {
4708                         if (r_ptr->r_pkills > 0)
4709                         {
4710                                 norm_total += r_ptr->r_pkills;
4711                         }
4712                 }
4713         }
4714
4715
4716         /* No monsters is defeated */
4717         if (norm_total < 1)
4718         {
4719                 fprintf(fff,_("まだ敵を倒していません。\n", "You have defeated no enemies yet.\n"));
4720         }
4721
4722         /* Defeated more than one normal monsters */
4723         else if (uniq_total == 0)
4724         {
4725 #ifdef JP
4726                 fprintf(fff,"%ld体の敵を倒しています。\n", norm_total);
4727 #else
4728                 fprintf(fff,"You have defeated %ld %s.\n", norm_total, norm_total == 1 ? "enemy" : "enemies");
4729 #endif
4730         }
4731
4732         /* Defeated more than one unique monsters */
4733         else /* if (uniq_total > 0) */
4734         {
4735 #ifdef JP
4736                 fprintf(fff, "%ld体のユニーク・モンスターを含む、合計%ld体の敵を倒しています。\n", uniq_total, norm_total); 
4737 #else
4738                 fprintf(fff, "You have defeated %ld %s including %ld unique monster%s in total.\n", norm_total, norm_total == 1 ? "enemy" : "enemies", uniq_total, (uniq_total == 1 ? "" : "s"));
4739 #endif
4740
4741                 /* Sort the array by dungeon depth of monsters */
4742                 ang_sort(who, &why, uniq_total, ang_sort_comp_hook, ang_sort_swap_hook);
4743                 fprintf(fff, _("\n《上位%ld体のユニーク・モンスター》\n", "\n< Unique monsters top %ld >\n"), MIN(uniq_total, 10));
4744
4745                 /* Print top 10 */
4746                 for (k = uniq_total - 1; k >= 0 && k >= uniq_total - 10; k--)
4747                 {
4748                         monster_race *r_ptr = &r_info[who[k]];
4749                         fprintf(fff, _("  %-40s (レベル%3d)\n", "  %-40s (level %3d)\n"), (r_name + r_ptr->name), (int)r_ptr->level);
4750                 }
4751
4752         }
4753
4754         /* Free the "who" array */
4755         C_KILL(who, max_r_idx, s16b);
4756 }
4757
4758
4759 /*!
4760  * @brief 元種族情報をファイルにダンプする
4761  * @param fff ファイルポインタ
4762  * @return なし
4763  */
4764 static void dump_aux_race_history(FILE *fff)
4765 {
4766         if (p_ptr->old_race1 || p_ptr->old_race2)
4767         {
4768                 int i;
4769
4770                 fprintf(fff, _("\n\n あなたは%sとして生まれた。", "\n\n You were born as %s."), race_info[p_ptr->start_race].title);
4771                 for (i = 0; i < MAX_RACES; i++)
4772                 {
4773                         if (p_ptr->start_race == i) continue;
4774                         if (i < 32)
4775                         {
4776                                 if (!(p_ptr->old_race1 & 1L << i)) continue;
4777                         }
4778                         else
4779                         {
4780                                 if (!(p_ptr->old_race2 & 1L << (i-32))) continue;
4781                         }
4782                         fprintf(fff, _("\n あなたはかつて%sだった。", "\n You were a %s before."), race_info[i].title);
4783                 }
4784
4785                 fputc('\n', fff);
4786         }
4787 }
4788
4789
4790 /*!
4791  * @brief 元魔法領域情報をファイルにダンプする
4792  * @param fff ファイルポインタ
4793  * @return なし
4794  */
4795 static void dump_aux_realm_history(FILE *fff)
4796 {
4797         if (p_ptr->old_realm)
4798         {
4799                 int i;
4800
4801                 fputc('\n', fff);
4802                 for (i = 0; i < MAX_MAGIC; i++)
4803                 {
4804                         if (!(p_ptr->old_realm & 1L << i)) continue;
4805                         fprintf(fff, _("\n あなたはかつて%s魔法を使えた。", "\n You were able to use %s magic before."), realm_names[i+1]);
4806                 }
4807                 fputc('\n', fff);
4808         }
4809 }
4810
4811
4812 /*!
4813  * @brief 徳の情報をファイルにダンプする
4814  * @param fff ファイルポインタ
4815  * @return なし
4816  */
4817 static void dump_aux_virtues(FILE *fff)
4818 {
4819         int v_nr, percent;
4820
4821         fprintf(fff, _("\n\n  [自分に関する情報]\n\n", "\n\n  [HP-rate & Max stat & Virtues]\n\n"));
4822
4823         percent = (int)(((long)p_ptr->player_hp[PY_MAX_LEVEL - 1] * 200L) /
4824                 (2 * p_ptr->hitdie +
4825                 ((PY_MAX_LEVEL - 1+3) * (p_ptr->hitdie + 1))));
4826
4827 #ifdef JP
4828                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "現在の体力ランク : %d/100\n\n", percent);
4829                 else fprintf(fff, "現在の体力ランク : ???\n\n");
4830                 fprintf(fff, "能力の最大値\n");
4831 #else
4832                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "Your current Life Rating is %d/100.\n\n", percent);
4833                 else fprintf(fff, "Your current Life Rating is ???.\n\n");
4834                 fprintf(fff, "Limits of maximum stats\n");
4835 #endif
4836                 for (v_nr = 0; v_nr < A_MAX; v_nr++)
4837                 {
4838                         if ((p_ptr->knowledge & KNOW_STAT) || p_ptr->stat_max[v_nr] == p_ptr->stat_max_max[v_nr]) fprintf(fff, "%s 18/%d\n", stat_names[v_nr], p_ptr->stat_max_max[v_nr]-18);
4839                         else fprintf(fff, "%s ???\n", stat_names[v_nr]);
4840                 }
4841
4842         fprintf(fff, _("\n属性 : %s\n", "\nYour alighnment : %s\n"), your_alignment(p_ptr));
4843         fprintf(fff, "\n");
4844         dump_virtues(p_ptr, fff);
4845 }
4846
4847
4848 /*!
4849  * @brief 突然変異の情報をファイルにダンプする
4850  * @param fff ファイルポインタ
4851  * @return なし
4852  */
4853 static void dump_aux_mutations(FILE *fff)
4854 {
4855         if (p_ptr->muta1 || p_ptr->muta2 || p_ptr->muta3)
4856         {
4857                 fprintf(fff, _("\n\n  [突然変異]\n\n", "\n\n  [Mutations]\n\n"));
4858                 dump_mutations(p_ptr, fff);
4859         }
4860 }
4861
4862
4863 /*!
4864  * @brief 所持品の情報をファイルにダンプする
4865  * @param fff ファイルポインタ
4866  * @return なし
4867  */
4868 static void dump_aux_equipment_inventory(FILE *fff)
4869 {
4870         int i;
4871         GAME_TEXT o_name[MAX_NLEN];
4872
4873         /* Dump the equipment */
4874         if (p_ptr->equip_cnt)
4875         {
4876                 fprintf(fff, _("  [キャラクタの装備]\n\n", "  [Character Equipment]\n\n"));
4877                 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
4878                 {
4879                         object_desc(o_name, &p_ptr->inventory_list[i], 0);
4880                         if ((((i == INVEN_RARM) && p_ptr->hidarite) || ((i == INVEN_LARM) && p_ptr->migite)) && p_ptr->ryoute)
4881                                 strcpy(o_name, _("(武器を両手持ち)", "(wielding with two-hands)"));
4882
4883                         fprintf(fff, "%c) %s\n",
4884                                 index_to_label(i), o_name);
4885                 }
4886                 fprintf(fff, "\n\n");
4887         }
4888
4889         /* Dump the p_ptr->inventory_list */
4890         fprintf(fff, _("  [キャラクタの持ち物]\n\n", "  [Character Inventory]\n\n"));
4891
4892         for (i = 0; i < INVEN_PACK; i++)
4893         {
4894                 /* Don't dump the empty slots */
4895                 if (!p_ptr->inventory_list[i].k_idx) break;
4896
4897                 /* Dump the p_ptr->inventory_list slots */
4898                 object_desc(o_name, &p_ptr->inventory_list[i], 0);
4899                 fprintf(fff, "%c) %s\n", index_to_label(i), o_name);
4900         }
4901
4902         /* Add an empty line */
4903         fprintf(fff, "\n\n");
4904 }
4905
4906
4907 /*!
4908  * @brief 我が家と博物館のオブジェクト情報をファイルにダンプする
4909  * @param fff ファイルポインタ
4910  * @return なし
4911  */
4912 static void dump_aux_home_museum(FILE *fff)
4913 {
4914         GAME_TEXT o_name[MAX_NLEN];
4915         store_type  *st_ptr;
4916
4917         /* Do we need it?? */
4918         /* process_dungeon_file("w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x); */
4919
4920         /* Print the home */
4921         st_ptr = &town_info[1].store[STORE_HOME];
4922
4923         /* Home -- if anything there */
4924         if (st_ptr->stock_num)
4925         {
4926                 int i;
4927                 TERM_LEN x = 1;
4928
4929                 fprintf(fff, _("  [我が家のアイテム]\n", "  [Home Inventory]\n"));
4930
4931                 /* Dump all available items */
4932                 for (i = 0; i < st_ptr->stock_num; i++)
4933                 {
4934                         if ((i % 12) == 0)
4935                                 fprintf(fff, _("\n ( %d ページ )\n", "\n ( page %d )\n"), x++);
4936                         object_desc(o_name, &st_ptr->stock[i], 0);
4937                         fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
4938                 }
4939
4940                 /* Add an empty line */
4941                 fprintf(fff, "\n\n");
4942         }
4943
4944
4945         /* Print the home */
4946         st_ptr = &town_info[1].store[STORE_MUSEUM];
4947
4948         /* Home -- if anything there */
4949         if (st_ptr->stock_num)
4950         {
4951                 int i;
4952                 TERM_LEN x = 1;
4953
4954                 fprintf(fff, _("  [博物館のアイテム]\n", "  [Museum]\n"));
4955
4956                 /* Dump all available items */
4957                 for (i = 0; i < st_ptr->stock_num; i++)
4958                 {
4959 #ifdef JP
4960                 if ((i % 12) == 0) fprintf(fff, "\n ( %d ページ )\n", x++);
4961                         object_desc(o_name, &st_ptr->stock[i], 0);
4962                         fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
4963 #else
4964                 if ((i % 12) == 0) fprintf(fff, "\n ( page %d )\n", x++);
4965                         object_desc(o_name, &st_ptr->stock[i], 0);
4966                         fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
4967 #endif
4968
4969                 }
4970
4971                 /* Add an empty line */
4972                 fprintf(fff, "\n\n");
4973         }
4974 }
4975
4976
4977 /*!
4978  * @brief ダンプ出力のメインルーチン
4979  * Output the character dump to a file
4980  * @param fff ファイルポインタ
4981  * @return エラーコード
4982  */
4983 errr make_character_dump(FILE *fff)
4984 {
4985 #ifdef JP
4986         fprintf(fff, "  [変愚蛮怒 %d.%d.%d キャラクタ情報]\n\n",
4987                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4988 #else
4989         fprintf(fff, "  [Hengband %d.%d.%d Character Dump]\n\n",
4990                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4991 #endif
4992
4993         update_playtime();
4994
4995         dump_aux_display_player(fff);
4996         dump_aux_last_message(fff);
4997         dump_aux_options(fff);
4998         dump_aux_recall(fff);
4999         dump_aux_quest(fff);
5000         dump_aux_arena(fff);
5001         dump_aux_monsters(fff);
5002         dump_aux_virtues(fff);
5003         dump_aux_race_history(fff);
5004         dump_aux_realm_history(fff);
5005         dump_aux_class_special(fff);
5006         dump_aux_mutations(fff);
5007         dump_aux_pet(fff);
5008         fputs("\n\n", fff);
5009         dump_aux_equipment_inventory(fff);
5010         dump_aux_home_museum(fff);
5011
5012         fprintf(fff, _("  [チェックサム: \"%s\"]\n\n", "  [Check Sum: \"%s\"]\n\n"), get_check_sum());
5013         return 0;
5014 }
5015
5016 /*!
5017  * @brief プレイヤーステータスをファイルダンプ出力する
5018  * Hack -- Dump a character description file
5019  * @param name 出力ファイル名
5020  * @return エラーコード
5021  * @details
5022  * Allow the "full" flag to dump additional info,
5023  * and trigger its usage from various places in the code.
5024  */
5025 errr file_character(concptr name)
5026 {
5027         int             fd = -1;
5028         FILE            *fff = NULL;
5029         char            buf[1024];
5030         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
5031
5032         /* File type is "TEXT" */
5033         FILE_TYPE(FILE_TYPE_TEXT);
5034
5035         /* Check for existing file */
5036         fd = fd_open(buf, O_RDONLY);
5037
5038         /* Existing file */
5039         if (fd >= 0)
5040         {
5041                 char out_val[160];
5042                 (void)fd_close(fd);
5043
5044                 /* Build query */
5045                 (void)sprintf(out_val, _("現存するファイル %s に上書きしますか? ", "Replace existing file %s? "), buf);
5046
5047                 /* Ask */
5048                 if (get_check_strict(out_val, CHECK_NO_HISTORY)) fd = -1;
5049         }
5050
5051         /* Open the non-existing file */
5052         if (fd < 0) fff = my_fopen(buf, "w");
5053
5054         /* Invalid file */
5055         if (!fff)
5056         {
5057                 prt(_("キャラクタ情報のファイルへの書き出しに失敗しました!", "Character dump failed!"), 0, 0);
5058
5059                 (void)inkey();
5060
5061                 /* Error */
5062                 return (-1);
5063         }
5064
5065         (void)make_character_dump(fff);
5066         my_fclose(fff);
5067
5068
5069         msg_print(_("キャラクタ情報のファイルへの書き出しに成功しました。", "Character dump successful."));
5070         msg_print(NULL);
5071
5072         /* Success */
5073         return (0);
5074 }
5075
5076
5077 /*!
5078  * @brief ファイル内容の一行をコンソールに出力する
5079  * Display single line of on-line help file
5080  * @param str 出力する文字列
5081  * @param cy コンソールの行
5082  * @param shower 確認中
5083  * @return なし
5084  * @details
5085  * <pre>
5086  * You can insert some special color tag to change text color.
5087  * Such as...
5088  * WHITETEXT [[[[y|SOME TEXT WHICH IS DISPLAYED IN YELLOW| WHITETEXT
5089  * A colored segment is between "[[[[y|" and the last "|".
5090  * You can use any single character in place of the "|".
5091  * </pre>
5092  */
5093 static void show_file_aux_line(concptr str, int cy, concptr shower)
5094 {
5095         static const char tag_str[] = "[[[[";
5096         byte color = TERM_WHITE;
5097         char in_tag = '\0';
5098         int cx = 0;
5099         int i;
5100         char lcstr[1024];
5101
5102         if (shower)
5103         {
5104                 /* Make a lower case version of str for searching */
5105                 strcpy(lcstr, str);
5106                 str_tolower(lcstr);
5107         }
5108
5109         /* Initial cursor position */
5110         Term_gotoxy(cx, cy);
5111
5112         for (i = 0; str[i];)
5113         {
5114                 int len = strlen(&str[i]);
5115                 int showercol = len + 1;
5116                 int bracketcol = len + 1;
5117                 int endcol = len;
5118                 concptr ptr;
5119
5120                 /* Search for a shower string in the line */
5121                 if (shower)
5122                 {
5123                         ptr = my_strstr(&lcstr[i], shower);
5124                         if (ptr) showercol = ptr - &lcstr[i];
5125                 }
5126
5127                 /* Search for a color segment tag */
5128                 ptr = in_tag ? my_strchr(&str[i], in_tag) : my_strstr(&str[i], tag_str);
5129                 if (ptr) bracketcol = ptr - &str[i];
5130
5131                 /* A color tag is found */
5132                 if (bracketcol < endcol) endcol = bracketcol;
5133
5134                 /* The shower string is found before the color tag */
5135                 if (showercol < endcol) endcol = showercol;
5136
5137                 /* Print a segment of the line */
5138                 Term_addstr(endcol, color, &str[i]);
5139                 cx += endcol;
5140                 i += endcol;
5141
5142                 /* Shower string? */
5143                 if (endcol == showercol)
5144                 {
5145                         int showerlen = strlen(shower);
5146
5147                         /* Print the shower string in yellow */
5148                         Term_addstr(showerlen, TERM_YELLOW, &str[i]);
5149                         cx += showerlen;
5150                         i += showerlen;
5151                 }
5152
5153                 /* Colored segment? */
5154                 else if (endcol == bracketcol)
5155                 {
5156                         if (in_tag)
5157                         {
5158                                 /* Found the end of colored segment */
5159                                 i++;
5160
5161                                 /* Now looking for an another tag_str */
5162                                 in_tag = '\0';
5163
5164                                 /* Set back to the default color */
5165                                 color = TERM_WHITE;
5166                         }
5167                         else
5168                         {
5169                                 /* Found a tag_str, and get a tag color */
5170                                 i += sizeof(tag_str)-1;
5171
5172                                 /* Get tag color */
5173                                 color = color_char_to_attr(str[i]);
5174
5175                                 /* Illegal color tag */
5176                                 if (color == 255 || str[i+1] == '\0')
5177                                 {
5178                                         /* Illegal color tag */
5179                                         color = TERM_WHITE;
5180
5181                                         /* Print the broken tag as a string */
5182                                         Term_addstr(-1, TERM_WHITE, tag_str);
5183                                         cx += sizeof(tag_str)-1;
5184                                 }
5185                                 else
5186                                 {
5187                                         /* Skip the color tag */
5188                                         i++;
5189
5190                                         /* Now looking for a close tag */
5191                                         in_tag = str[i];
5192
5193                                         /* Skip the close-tag-indicator */
5194                                         i++;
5195                                 }
5196                         }
5197                 }
5198
5199         } /* for (i = 0; str[i];) */
5200
5201         /* Clear rest of line */
5202         Term_erase(cx, cy, 255);
5203 }
5204
5205
5206 /*!
5207  * @brief ファイル内容をコンソールに出力する
5208  * Recursive file perusal.
5209  * @param show_version TRUEならばコンソール上にゲームのバージョンを表示する
5210  * @param name ファイル名の文字列
5211  * @param what 内容キャプションの文字列
5212  * @param line 表示の現在行
5213  * @param mode オプション
5214  * @return なし
5215  * @details
5216  * <pre>
5217  * Process various special text in the input file, including
5218  * the "menu" structures used by the "help file" system.
5219  * Return FALSE on 'q' to exit from a deep, otherwise TRUE.
5220  * </pre>
5221  */
5222 bool show_file(bool show_version, concptr name, concptr what, int line, BIT_FLAGS mode)
5223 {
5224         int i, n, skey;
5225
5226         /* Number of "real" lines passed by */
5227         int next = 0;
5228
5229         /* Number of "real" lines in the file */
5230         int size = 0;
5231
5232         /* Backup value for "line" */
5233         int back = 0;
5234
5235         /* This screen has sub-screens */
5236         bool menu = FALSE;
5237
5238         /* Current help file */
5239         FILE *fff = NULL;
5240
5241         /* Find this string (if any) */
5242         concptr find = NULL;
5243
5244         /* Jump to this tag */
5245         concptr tag = NULL;
5246
5247         /* Hold strings to find/show */
5248         char finder_str[81];
5249         char shower_str[81];
5250         char back_str[81];
5251
5252         /* String to show */
5253         concptr shower = NULL;
5254
5255         /* Filename */
5256         char filename[1024];
5257
5258         /* Describe this thing */
5259         char caption[128];
5260
5261         /* Path buffer */
5262         char path[1024];
5263
5264         /* General buffer */
5265         char buf[1024];
5266
5267         /* Sub-menu information */
5268         char hook[68][32];
5269
5270         bool reverse = (line < 0);
5271
5272         int wid, hgt, rows;
5273
5274         Term_get_size(&wid, &hgt);
5275         rows = hgt - 4;
5276
5277         strcpy(finder_str, "");
5278         strcpy(shower_str, "");
5279         strcpy(caption, "");
5280         for (i = 0; i < 68; i++)
5281         {
5282                 hook[i][0] = '\0';
5283         }
5284
5285         strcpy(filename, name);
5286
5287         n = strlen(filename);
5288
5289         /* Extract the tag from the filename */
5290         for (i = 0; i < n; i++)
5291         {
5292                 if (filename[i] == '#')
5293                 {
5294                         filename[i] = '\0';
5295                         tag = filename + i + 1;
5296                         break;
5297                 }
5298         }
5299
5300         /* Redirect the name */
5301         name = filename;
5302
5303         if (what)
5304         {
5305                 strcpy(caption, what);
5306                 strcpy(path, name);
5307                 fff = my_fopen(path, "r");
5308         }
5309
5310         /* Look in "help" */
5311         if (!fff)
5312         {
5313                 sprintf(caption, _("ヘルプ・ファイル'%s'", "Help file '%s'"), name);
5314                 path_build(path, sizeof(path), ANGBAND_DIR_HELP, name);
5315                 fff = my_fopen(path, "r");
5316         }
5317
5318         /* Look in "info" */
5319         if (!fff)
5320         {
5321                 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
5322                 path_build(path, sizeof(path), ANGBAND_DIR_INFO, name);
5323                 fff = my_fopen(path, "r");
5324         }
5325
5326         /* Look in "info" */
5327         if (!fff)
5328         {
5329                 path_build(path, sizeof(path), ANGBAND_DIR, name);
5330
5331                 for (i = 0; path[i]; i++)
5332                         if ('\\' == path[i])
5333                                 path[i] = PATH_SEP[0];
5334
5335                 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
5336                 fff = my_fopen(path, "r");
5337         }
5338
5339         if (!fff)
5340         {
5341                 msg_format(_("'%s'をオープンできません。", "Cannot open '%s'."), name);
5342                 msg_print(NULL);
5343
5344                 return (TRUE);
5345         }
5346
5347
5348         /* Pre-Parse the file */
5349         while (TRUE)
5350         {
5351                 char *str = buf;
5352
5353                 /* Read a line or stop */
5354                 if (my_fgets(fff, buf, sizeof(buf))) break;
5355
5356                 /* XXX Parse "menu" items */
5357                 if (prefix(str, "***** "))
5358                 {
5359                         /* Notice "menu" requests */
5360                         if ((str[6] == '[') && isalpha(str[7]))
5361                         {
5362                                 /* Extract the menu item */
5363                                 int k = str[7] - 'A';
5364
5365                                 /* This is a menu file */
5366                                 menu = TRUE;
5367
5368                                 if ((str[8] == ']') && (str[9] == ' '))
5369                                 {
5370                                         /* Extract the menu item */
5371                                         strncpy(hook[k], str + 10, 31);
5372
5373                                         /* Make sure it's null-terminated */
5374                                         hook[k][31] = '\0';
5375                                 }
5376                         }
5377                         /* Notice "tag" requests */
5378                         else if (str[6] == '<')
5379                         {
5380                                 size_t len = strlen(str);
5381
5382                                 if (str[len - 1] == '>')
5383                                 {
5384                                         str[len - 1] = '\0';
5385                                         if (tag && streq(str + 7, tag)) line = next;
5386                                 }
5387                         }
5388
5389                         /* Skip this */
5390                         continue;
5391                 }
5392
5393                 /* Count the "real" lines */
5394                 next++;
5395         }
5396
5397         /* Save the number of "real" lines */
5398         size = next;
5399
5400         /* start from bottom when reverse mode */
5401         if (line == -1) line = ((size-1)/rows)*rows;
5402         Term_clear();
5403
5404         /* Display the file */
5405         while (TRUE)
5406         {
5407                 /* Restart when necessary */
5408                 if (line >= size - rows) line = size - rows;
5409                 if (line < 0) line = 0;
5410
5411                 /* Re-open the file if needed */
5412                 if (next > line)
5413                 {
5414                         my_fclose(fff);
5415
5416                         /* Hack -- Re-Open the file */
5417                         fff = my_fopen(path, "r");
5418
5419                         if (!fff) return (FALSE);
5420
5421                         /* File has been restarted */
5422                         next = 0;
5423                 }
5424
5425                 /* Goto the selected line */
5426                 while (next < line)
5427                 {
5428                         /* Get a line */
5429                         if (my_fgets(fff, buf, sizeof(buf))) break;
5430
5431                         /* Skip tags/links */
5432                         if (prefix(buf, "***** ")) continue;
5433
5434                         /* Count the lines */
5435                         next++;
5436                 }
5437
5438                 /* Dump the next 20, or rows, lines of the file */
5439                 for (i = 0; i < rows; )
5440                 {
5441                         concptr str = buf;
5442
5443                         /* Hack -- track the "first" line */
5444                         if (!i) line = next;
5445
5446                         /* Get a line of the file or stop */
5447                         if (my_fgets(fff, buf, sizeof(buf))) break;
5448
5449                         /* Hack -- skip "special" lines */
5450                         if (prefix(buf, "***** ")) continue;
5451
5452                         /* Count the "real" lines */
5453                         next++;
5454
5455                         /* Hack -- keep searching */
5456                         if (find && !i)
5457                         {
5458                                 char lc_buf[1024];
5459
5460                                 /* Make a lower case version of str for searching */
5461                                 strcpy(lc_buf, str);
5462                                 str_tolower(lc_buf);
5463
5464                                 if (!my_strstr(lc_buf, find)) continue;
5465                         }
5466
5467                         /* Hack -- stop searching */
5468                         find = NULL;
5469
5470                         /* Dump the line */
5471                         show_file_aux_line(str, i + 2, shower);
5472
5473                         /* Count the printed lines */
5474                         i++;
5475                 }
5476
5477                 while (i < rows)
5478                 {
5479                         /* Clear rest of line */
5480                         Term_erase(0, i + 2, 255);
5481
5482                         i++;
5483                 }
5484
5485                 /* Hack -- failed search */
5486                 if (find)
5487                 {
5488                         bell();
5489                         line = back;
5490                         find = NULL;
5491                         continue;
5492                 }
5493
5494
5495                 /* Show a general "title" */
5496                 if (show_version)
5497                 {
5498                         prt(format(_("[変愚蛮怒 %d.%d.%d, %s, %d/%d]", "[Hengband %d.%d.%d, %s, Line %d/%d]"),
5499                            FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH,
5500                            caption, line, size), 0, 0);
5501                 }
5502                 else
5503                 {
5504                         prt(format(_("[%s, %d/%d]", "[%s, Line %d/%d]"),
5505                                 caption, line, size), 0, 0);
5506                 }
5507
5508                 /* Prompt -- small files */
5509                 if (size <= rows)
5510                 {
5511                         /* Wait for it */
5512                         prt(_("[キー:(?)ヘルプ (ESC)終了]", "[Press ESC to exit.]"), hgt - 1, 0);
5513                 }
5514
5515                 /* Prompt -- large files */
5516                 else
5517                 {
5518 #ifdef JP
5519                         if(reverse)
5520                                 prt("[キー:(RET/スペース)↑ (-)↓ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
5521                         else
5522                                 prt("[キー:(RET/スペース)↓ (-)↑ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
5523 #else
5524                         prt("[Press Return, Space, -, =, /, |, or ESC to exit.]", hgt - 1, 0);
5525 #endif
5526                 }
5527
5528                 /* Get a special key code */
5529                 skey = inkey_special(TRUE);
5530
5531                 switch (skey)
5532                 {
5533                 /* Show the help for the help */
5534                 case '?':
5535                         /* Hack - prevent silly recursion */
5536                         if (strcmp(name, _("jhelpinfo.txt", "helpinfo.txt")) != 0)
5537                                 show_file(TRUE, _("jhelpinfo.txt", "helpinfo.txt"), NULL, 0, mode);
5538                         break;
5539
5540                 /* Hack -- try showing */
5541                 case '=':
5542                         /* Get "shower" */
5543                         prt(_("強調: ", "Show: "), hgt - 1, 0);
5544
5545                         strcpy(back_str, shower_str);
5546                         if (askfor(shower_str, 80))
5547                         {
5548                                 if (shower_str[0])
5549                                 {
5550                                         /* Make it lowercase */
5551                                         str_tolower(shower_str);
5552
5553                                         /* Show it */
5554                                         shower = shower_str;
5555                                 }
5556                                 else shower = NULL; /* Stop showing */
5557                         }
5558                         else strcpy(shower_str, back_str);
5559                         break;
5560
5561                 /* Hack -- try finding */
5562                 case '/':
5563                 case KTRL('s'):
5564                         /* Get "finder" */
5565                         prt(_("検索: ", "Find: "), hgt - 1, 0);
5566
5567                         strcpy(back_str, finder_str);
5568                         if (askfor(finder_str, 80))
5569                         {
5570                                 if (finder_str[0])
5571                                 {
5572                                         /* Find it */
5573                                         find = finder_str;
5574                                         back = line;
5575                                         line = line + 1;
5576
5577                                         /* Make finder lowercase */
5578                                         str_tolower(finder_str);
5579
5580                                         /* Show it */
5581                                         shower = finder_str;
5582                                 }
5583                                 else shower = NULL; /* Stop showing */
5584                         }
5585                         else strcpy(finder_str, back_str);
5586                         break;
5587
5588                 /* Hack -- go to a specific line */
5589                 case '#':
5590                         {
5591                                 char tmp[81];
5592                                 prt(_("行: ", "Goto Line: "), hgt - 1, 0);
5593                                 strcpy(tmp, "0");
5594
5595                                 if (askfor(tmp, 80)) line = atoi(tmp);
5596                         }
5597                         break;
5598
5599                 /* Hack -- go to the top line */
5600                 case SKEY_TOP:
5601                         line = 0;
5602                         break;
5603
5604                 /* Hack -- go to the bottom line */
5605                 case SKEY_BOTTOM:
5606                         line = ((size - 1) / rows) * rows;
5607                         break;
5608
5609                 /* Hack -- go to a specific file */
5610                 case '%':
5611                         {
5612                                 char tmp[81];
5613                                 prt(_("ファイル・ネーム: ", "Goto File: "), hgt - 1, 0);
5614                                 strcpy(tmp, _("jhelp.hlp", "help.hlp"));
5615
5616                                 if (askfor(tmp, 80))
5617                                 {
5618                                         if (!show_file(TRUE, tmp, NULL, 0, mode)) skey = 'q';
5619                                 }
5620                         }
5621                         break;
5622
5623                 /* Allow backing up */
5624                 case '-':
5625                         line = line + (reverse ? rows : -rows);
5626                         if (line < 0) line = 0;
5627                         break;
5628
5629                 /* One page up */
5630                 case SKEY_PGUP:
5631                         line = line - rows;
5632                         if (line < 0) line = 0;
5633                         break;
5634
5635                 /* Advance a single line */
5636                 case '\n':
5637                 case '\r':
5638                         line = line + (reverse ? -1 : 1);
5639                         if (line < 0) line = 0;
5640                         break;
5641
5642                 /* Move up / down */
5643                 case '8':
5644                 case SKEY_UP:
5645                         line--;
5646                         if (line < 0) line = 0;
5647                         break;
5648
5649                 case '2':
5650                 case SKEY_DOWN:
5651                         line++;
5652                         break;
5653
5654                 /* Advance one page */
5655                 case ' ':
5656                         line = line + (reverse ? -rows : rows);
5657                         if (line < 0) line = 0;
5658                         break;
5659
5660                 /* One page down */
5661                 case SKEY_PGDOWN:
5662                         line = line + rows;
5663                         break;
5664                 }
5665
5666                 /* Recurse on numbers */
5667                 if (menu)
5668                 {
5669                         int key = -1;
5670
5671                         if (!(skey & SKEY_MASK) && isalpha(skey))
5672                                 key = skey - 'A';
5673
5674                         if ((key > -1) && hook[key][0])
5675                         {
5676                                 /* Recurse on that file */
5677                                 if (!show_file(TRUE, hook[key], NULL, 0, mode))
5678                                         skey = 'q';
5679                         }
5680                 }
5681
5682                 /* Hack, dump to file */
5683                 if (skey == '|')
5684                 {
5685                         FILE *ffp;
5686                         char buff[1024];
5687                         char xtmp[82];
5688
5689                         strcpy (xtmp, "");
5690
5691                         if (!get_string(_("ファイル名: ", "File name: "), xtmp, 80)) continue;
5692                         my_fclose(fff);
5693                         path_build(buff, sizeof(buff), ANGBAND_DIR_USER, xtmp);
5694
5695                         /* Hack -- Re-Open the file */
5696                         fff = my_fopen(path, "r");
5697
5698                         ffp = my_fopen(buff, "w");
5699
5700                         if (!(fff && ffp))
5701                         {
5702                                 msg_print(_("ファイルを開けません。", "Failed to open file."));
5703                                 skey = ESCAPE;
5704                                 break;
5705                         }
5706
5707                         sprintf(xtmp, "%s: %s", p_ptr->name, what ? what : caption);
5708                         my_fputs(ffp, xtmp, 80);
5709                         my_fputs(ffp, "\n", 80);
5710
5711                         while (!my_fgets(fff, buff, sizeof(buff)))
5712                                 my_fputs(ffp, buff, 80);
5713                         my_fclose(fff);
5714                         my_fclose(ffp);
5715
5716                         /* Hack -- Re-Open the file */
5717                         fff = my_fopen(path, "r");
5718                 }
5719
5720                 /* Return to last screen */
5721                 if ((skey == ESCAPE) || (skey == '<')) break;
5722
5723                 /* Exit on the ^q */
5724                 if (skey == KTRL('q')) skey = 'q';
5725
5726                 /* Exit on the q key */
5727                 if (skey == 'q') break;
5728         }
5729         my_fclose(fff);
5730
5731         /* Escape */
5732         if (skey == 'q') return (FALSE);
5733
5734         /* Normal return */
5735         return (TRUE);
5736 }
5737
5738
5739 /*!
5740  * @brief ヘルプを表示するコマンドのメインルーチン
5741  * Peruse the On-Line-Help
5742  * @return なし
5743  * @details
5744  */
5745 void do_cmd_help(void)
5746 {
5747         screen_save();
5748
5749         /* Peruse the main help file */
5750         (void)show_file(TRUE, _("jhelp.hlp", "help.hlp"), NULL, 0, 0);
5751         screen_load();
5752 }
5753
5754
5755 /*!
5756  * @brief プレイヤーの名前をチェックして修正する
5757  * Process the player name.
5758  * @param sf セーブファイル名に合わせた修正を行うならばTRUE
5759  * @return なし
5760  * @details
5761  * Extract a clean "base name".
5762  * Build the savefile name if needed.
5763  */
5764 void process_player_name(bool sf)
5765 {
5766         int i, k = 0;
5767         char old_player_base[32] = "";
5768
5769         if (current_world_ptr->character_generated) strcpy(old_player_base, p_ptr->base_name);
5770
5771         /* Cannot be too long */
5772 #if defined(MACINTOSH) || defined(ACORN)
5773         if (strlen(p_ptr->name) > 15)
5774         {
5775                 /* Name too long */
5776                 quit_fmt(_("'%s'という名前は長すぎます!", "The name '%s' is too long!"), p_ptr->name);
5777         }
5778 #endif
5779
5780         /* Cannot contain "icky" characters */
5781         for (i = 0; p_ptr->name[i]; i++)
5782         {
5783                 /* No control characters */
5784 #ifdef JP
5785                 if (iskanji(p_ptr->name[i])){i++;continue;}
5786                 if (iscntrl( (unsigned char)p_ptr->name[i]))
5787 #else
5788                 if (iscntrl(p_ptr->name[i]))
5789 #endif
5790
5791                 {
5792                         /* Illegal characters */
5793                         quit_fmt(_("'%s' という名前は不正なコントロールコードを含んでいます。", "The name '%s' contains control chars!"), p_ptr->name);
5794                 }
5795         }
5796
5797
5798 #ifdef MACINTOSH
5799
5800         /* Extract "useful" letters */
5801         for (i = 0; p_ptr->name[i]; i++)
5802         {
5803 #ifdef JP
5804                 unsigned char c = p_ptr->name[i];
5805 #else
5806                 char c = p_ptr->name[i];
5807 #endif
5808
5809
5810                 /* Convert "dot" to "underscore" */
5811                 if (c == '.') c = '_';
5812
5813                 /* Accept all the letters */
5814                 p_ptr->base_name[k++] = c;
5815         }
5816
5817 #else
5818
5819         /* Extract "useful" letters */
5820         for (i = 0; p_ptr->name[i]; i++)
5821         {
5822 #ifdef JP
5823                 unsigned char c = p_ptr->name[i];
5824 #else
5825                 char c = p_ptr->name[i];
5826 #endif
5827
5828                 /* Accept some letters */
5829 #ifdef JP
5830                 if(iskanji(c)){
5831                   if(k + 2 >= sizeof(p_ptr->base_name) || !p_ptr->name[i+1]) break;
5832                   p_ptr->base_name[k++] = c;
5833                   i++;
5834                   p_ptr->base_name[k++] = p_ptr->name[i];
5835                 }
5836 #ifdef SJIS
5837                 else if (iskana(c)) p_ptr->base_name[k++] = c;
5838 #endif
5839                 else
5840 #endif
5841                 /* Convert path separator to underscore */
5842                 if (!strncmp(PATH_SEP, p_ptr->name+i, strlen(PATH_SEP))){
5843                         p_ptr->base_name[k++] = '_';
5844                         i += strlen(PATH_SEP);
5845                 }
5846                 /* Convert some characters to underscore */
5847 #if defined(WINDOWS)
5848                 else if (my_strchr("\"*,/:;<>?\\|", c)) p_ptr->base_name[k++] = '_';
5849 #endif
5850                 else if (isprint(c)) p_ptr->base_name[k++] = c;
5851         }
5852
5853 #endif
5854
5855         /* Terminate */
5856         p_ptr->base_name[k] = '\0';
5857
5858         /* Require a "base" name */
5859         if (!p_ptr->base_name[0]) strcpy(p_ptr->base_name, "PLAYER");
5860
5861
5862 #ifdef SAVEFILE_MUTABLE
5863
5864         /* Accept */
5865         sf = TRUE;
5866
5867 #endif
5868         if (!savefile_base[0] && savefile[0])
5869         {
5870                 concptr s;
5871                 s = savefile;
5872                 while (1)
5873                 {
5874                         concptr t;
5875                         t = my_strstr(s, PATH_SEP);
5876                         if (!t)
5877                                 break;
5878                         s = t+1;
5879                 }
5880                 strcpy(savefile_base, s);
5881         }
5882
5883         if (!savefile_base[0] || !savefile[0])
5884                 sf = TRUE;
5885
5886         /* Change the savefile name */
5887         if (sf)
5888         {
5889                 char temp[128];
5890
5891                 strcpy(savefile_base, p_ptr->base_name);
5892
5893 #ifdef SAVEFILE_USE_UID
5894                 /* Rename the savefile, using the p_ptr->player_uid and p_ptr->base_name */
5895                 (void)sprintf(temp, "%d.%s", p_ptr->player_uid, p_ptr->base_name);
5896 #else
5897                 /* Rename the savefile, using the p_ptr->base_name */
5898                 (void)sprintf(temp, "%s", p_ptr->base_name);
5899 #endif
5900                 path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
5901         }
5902
5903         /* Load an autopick preference file */
5904         if (current_world_ptr->character_generated)
5905         {
5906                 if (!streq(old_player_base, p_ptr->base_name)) autopick_load_pref(FALSE);
5907         }
5908 }
5909
5910
5911 /*!
5912  * @brief プレイヤーの名前を変更するコマンドのメインルーチン
5913  * Gets a name for the character, reacting to name changes.
5914  * @return なし
5915  * @details
5916  * <pre>
5917  * Assumes that "display_player(p_ptr, 0)" has just been called
5918  * Perhaps we should NOT ask for a name (at "birth()") on
5919  * Unix machines?  XXX XXX
5920  * What a horrible name for a global function.  
5921  * </pre>
5922  */
5923 void get_name(void)
5924 {
5925         char tmp[64];
5926
5927         /* Save the player name */
5928         strcpy(tmp, p_ptr->name);
5929
5930         /* Prompt for a new name */
5931         if (get_string(_("キャラクターの名前を入力して下さい: ", "Enter a name for your character: "), tmp, 15))
5932         {
5933                 /* Use the name */
5934                 strcpy(p_ptr->name, tmp);
5935         }
5936
5937         if (0 == strlen(p_ptr->name))
5938         {
5939                 /* Use default name */
5940                 strcpy(p_ptr->name, "PLAYER");
5941         }
5942
5943         strcpy(tmp,ap_ptr->title);
5944 #ifdef JP
5945         if(ap_ptr->no == 1)
5946                 strcat(tmp,"の");
5947 #else
5948         strcat(tmp, " ");
5949 #endif
5950         strcat(tmp,p_ptr->name);
5951
5952         /* Re-Draw the name (in light blue) */
5953         Term_erase(34, 1, 255);
5954         c_put_str(TERM_L_BLUE, tmp, 1, 34);
5955
5956         /* Erase the prompt, etc */
5957         clear_from(22);
5958 }
5959
5960
5961
5962 /*!
5963  * @brief セーブするコマンドのメインルーチン
5964  * Save the game
5965  * @param is_autosave オートセーブ中の処理ならばTRUE
5966  * @return なし
5967  * @details
5968  */
5969 void do_cmd_save_game(int is_autosave)
5970 {
5971         /* Autosaves do not disturb */
5972         if (is_autosave)
5973         {
5974                 msg_print(_("自動セーブ中", "Autosaving the game..."));
5975         }
5976         else
5977         {
5978                 disturb(p_ptr, TRUE, TRUE);
5979         }
5980
5981         /* Clear messages */
5982         msg_print(NULL);
5983         handle_stuff();
5984
5985         prt(_("ゲームをセーブしています...", "Saving game..."), 0, 0);
5986
5987         Term_fresh();
5988
5989         /* The player is not dead */
5990         (void)strcpy(p_ptr->died_from, _("(セーブ)", "(saved)"));
5991
5992         /* Forbid suspend */
5993         signals_ignore_tstp();
5994
5995         /* Save the player */
5996         if (save_player())
5997         {
5998                 prt(_("ゲームをセーブしています... 終了", "Saving game... done."), 0, 0);
5999         }
6000
6001         /* Save failed (oops) */
6002         else
6003         {
6004                 prt(_("ゲームをセーブしています... 失敗!", "Saving game... failed!"), 0, 0);
6005         }
6006
6007         /* Allow suspend again */
6008         signals_handle_tstp();
6009
6010         Term_fresh();
6011
6012         /* Note that the player is not dead */
6013         (void)strcpy(p_ptr->died_from, _("(元気に生きている)", "(alive and well)"));
6014
6015         /* HACK -- don't get sanity blast on updating view */
6016         current_world_ptr->is_loading_now = FALSE;
6017
6018         update_creature(p_ptr);
6019
6020         /* Initialize monster process */
6021         mproc_init();
6022
6023         /* HACK -- reset the hackish flag */
6024         current_world_ptr->is_loading_now = TRUE;
6025 }
6026
6027
6028 /*!
6029  * @brief セーブ後にゲーム中断フラグを立てる/
6030  * Save the game and exit
6031  * @return なし
6032  * @details
6033  */
6034 void do_cmd_save_and_exit(void)
6035 {
6036         p_ptr->playing = FALSE;
6037         p_ptr->leaving = TRUE;
6038         exe_write_diary(p_ptr, NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
6039 }
6040
6041
6042 #define GRAVE_LINE_WIDTH 31
6043
6044 /*!
6045  * @brief 墓石の真ん中に文字列を書き込む /
6046  * Centers a string within a GRAVE_LINE_WIDTH character string          -JWT-
6047  * @return なし
6048  * @details
6049  */
6050 static void center_string(char *buf, concptr str)
6051 {
6052         int i, j;
6053
6054         /* Total length */
6055         i = strlen(str);
6056
6057         /* Necessary border */
6058         j = GRAVE_LINE_WIDTH / 2 - i / 2;
6059
6060         /* Mega-Hack */
6061         (void)sprintf(buf, "%*s%s%*s", j, "", str, GRAVE_LINE_WIDTH - i - j, "");
6062 }
6063
6064
6065 #if 0
6066 /*!
6067  * @brief 骨ファイル出力 /
6068  * Save a "bones" file for a dead character
6069  * @details
6070  * <pre>
6071  * Note that we will not use these files until Angband 2.8.0, and
6072  * then we will only use the name and level on which death occured.
6073  * Should probably attempt some form of locking...
6074  * </pre>
6075  */
6076 static void make_bones(void)
6077 {
6078         FILE                *fp;
6079
6080         char                str[1024];
6081
6082
6083         /* Ignore wizards and borgs */
6084         if (!(p_ptr->noscore & 0x00FF))
6085         {
6086                 /* Ignore people who die in town */
6087                 if (current_floor_ptr->dun_level)
6088                 {
6089                         char tmp[128];
6090
6091                         /* "Bones" name */
6092                         sprintf(tmp, "bone.%03d", current_floor_ptr->dun_level);
6093                         path_build(str, sizeof(str), ANGBAND_DIR_BONE, tmp);
6094
6095                         /* Attempt to open the bones file */
6096                         fp = my_fopen(str, "r");
6097
6098                         /* Close it right away */
6099                         if (fp) my_fclose(fp);
6100
6101                         /* Do not over-write a previous ghost */
6102                         if (fp) return;
6103
6104                         /* File type is "TEXT" */
6105                         FILE_TYPE(FILE_TYPE_TEXT);
6106
6107                         /* Grab permissions */
6108                         safe_setuid_grab();
6109
6110                         /* Try to write a new "Bones File" */
6111                         fp = my_fopen(str, "w");
6112
6113                         /* Drop permissions */
6114                         safe_setuid_drop();
6115
6116                         /* Not allowed to write it?  Weird. */
6117                         if (!fp) return;
6118
6119                         /* Save the info */
6120                         fprintf(fp, "%s\n", p_ptr->name);
6121                         fprintf(fp, "%d\n", p_ptr->mhp);
6122                         fprintf(fp, "%d\n", p_ptr->prace);
6123                         fprintf(fp, "%d\n", p_ptr->pclass);
6124
6125                         /* Close and save the Bones file */
6126                         my_fclose(fp);
6127                 }
6128         }
6129 }
6130 #endif
6131
6132
6133 /*
6134  * Redefinable "print_tombstone" action
6135  */
6136 bool (*tombstone_aux)(void) = NULL;
6137
6138
6139 /*!
6140  * @brief 墓石のアスキーアート表示 /
6141  * Display a "tomb-stone"
6142  * @return なし
6143  */
6144 void print_tomb(void)
6145 {
6146         bool done = FALSE;
6147
6148         /* Do we use a special tombstone ? */
6149         if (tombstone_aux)
6150         {
6151                 /* Use tombstone hook */
6152                 done = (*tombstone_aux)();
6153         }
6154
6155         /* Print the text-tombstone */
6156         if (!done)
6157         {
6158                 concptr   p;
6159                 char   tmp[160];
6160                 char   buf[1024];
6161                 char   dummy[80];
6162                 char   *t;
6163                 FILE   *fp;
6164                 time_t ct = time((time_t)0);
6165 #ifdef JP
6166                 int    extra_line = 0;
6167 #endif
6168                 Term_clear();
6169                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("dead_j.txt", "dead.txt"));
6170
6171                 /* Open the News file */
6172                 fp = my_fopen(buf, "r");
6173
6174                 /* Dump */
6175                 if (fp)
6176                 {
6177                         int i = 0;
6178
6179                         /* Dump the file to the screen */
6180                         while (0 == my_fgets(fp, buf, sizeof(buf)))
6181                         {
6182                                 /* Display and advance */
6183                                 put_str(buf, i++, 0);
6184                         }
6185
6186                         /* Close */
6187                         my_fclose(fp);
6188                 }
6189
6190                 /* King or Queen */
6191                 if (p_ptr->total_winner || (p_ptr->lev > PY_MAX_LEVEL))
6192                 {
6193 #ifdef JP
6194                         /* 英日切り替え */
6195                         p= "偉大なる者";
6196 #else
6197                         p = "Magnificent";
6198 #endif
6199                 }
6200
6201                 /* Normal */
6202                 else
6203                 {
6204                         p =  player_title[p_ptr->pclass][(p_ptr->lev - 1) / 5];
6205                 }
6206
6207                 center_string(buf, p_ptr->name);
6208                 put_str(buf, 6, 11);
6209
6210 #ifndef JP
6211                 center_string(buf, "the");
6212                 put_str(buf, 7, 11);
6213 #endif
6214
6215                 center_string(buf, p);
6216                 put_str(buf, 8, 11);
6217
6218                 center_string(buf, cp_ptr->title);
6219                 put_str(buf, 10, 11);
6220
6221                 (void)sprintf(tmp, _("レベル: %d", "Level: %d"), (int)p_ptr->lev);
6222                 center_string(buf, tmp);
6223                 put_str(buf, 11, 11);
6224
6225                 (void)sprintf(tmp, _("経験値: %ld", "Exp: %ld"), (long)p_ptr->exp);
6226                 center_string(buf, tmp);
6227                 put_str(buf, 12, 11);
6228
6229                 (void)sprintf(tmp, _("所持金: %ld", "AU: %ld"), (long)p_ptr->au);
6230                 center_string(buf, tmp);
6231                 put_str(buf, 13, 11);
6232
6233 #ifdef JP
6234                 /* 墓に刻む言葉をオリジナルより細かく表示 */
6235                 if (streq(p_ptr->died_from, "途中終了"))
6236                 {
6237                         strcpy(tmp, "<自殺>");
6238                 }
6239                 else if (streq(p_ptr->died_from, "ripe"))
6240                 {
6241                         strcpy(tmp, "引退後に天寿を全う");
6242                 }
6243                 else if (streq(p_ptr->died_from, "Seppuku"))
6244                 {
6245                         strcpy(tmp, "勝利の後、切腹");
6246                 }
6247                 else
6248                 {
6249                         roff_to_buf(p_ptr->died_from, GRAVE_LINE_WIDTH + 1, tmp, sizeof tmp);
6250                         t = tmp + strlen(tmp) + 1;
6251                         if (*t)
6252                         {
6253                                 strcpy(dummy, t); /* 2nd line */
6254                                 if (*(t + strlen(t) + 1)) /* Does 3rd line exist? */
6255                                 {
6256                                         for (t = dummy + strlen(dummy) - 2; iskanji(*(t - 1)); t--) /* Loop */;
6257                                         strcpy(t, "…");
6258                                 }
6259                                 else if (my_strstr(tmp, "『") && suffix(dummy, "』"))
6260                                 {
6261                                         char dummy2[80];
6262                                         char *name_head = my_strstr(tmp, "『");
6263                                         sprintf(dummy2, "%s%s", name_head, dummy);
6264                                         if (strlen(dummy2) <= GRAVE_LINE_WIDTH)
6265                                         {
6266                                                 strcpy(dummy, dummy2);
6267                                                 *name_head = '\0';
6268                                         }
6269                                 }
6270                                 else if (my_strstr(tmp, "「") && suffix(dummy, "」"))
6271                                 {
6272                                         char dummy2[80];
6273                                         char *name_head = my_strstr(tmp, "「");
6274                                         sprintf(dummy2, "%s%s", name_head, dummy);
6275                                         if (strlen(dummy2) <= GRAVE_LINE_WIDTH)
6276                                         {
6277                                                 strcpy(dummy, dummy2);
6278                                                 *name_head = '\0';
6279                                         }
6280                                 }
6281                                 center_string(buf, dummy);
6282                                 put_str(buf, 15, 11);
6283                                 extra_line = 1;
6284                         }
6285                 }
6286                 center_string(buf, tmp);
6287                 put_str(buf, 14, 11);
6288
6289                 if (!streq(p_ptr->died_from, "ripe") && !streq(p_ptr->died_from, "Seppuku"))
6290                 {
6291                         if (current_floor_ptr->dun_level == 0)
6292                         {
6293                                 concptr field_name = p_ptr->town_num ? "街" : "荒野";
6294                                 if (streq(p_ptr->died_from, "途中終了"))
6295                                 {
6296                                         sprintf(tmp, "%sで死んだ", field_name);
6297                                 }
6298                                 else
6299                                 {
6300                                         sprintf(tmp, "に%sで殺された", field_name);
6301                                 }
6302                         }
6303                         else
6304                         {
6305                                 if (streq(p_ptr->died_from, "途中終了"))
6306                                 {
6307                                         sprintf(tmp, "地下 %d 階で死んだ", (int)current_floor_ptr->dun_level);
6308                                 }
6309                                 else
6310                                 {
6311                                         sprintf(tmp, "に地下 %d 階で殺された", (int)current_floor_ptr->dun_level);
6312                                 }
6313                         }
6314                         center_string(buf, tmp);
6315                         put_str(buf, 15 + extra_line, 11);
6316                 }
6317 #else
6318                 (void)sprintf(tmp, "Killed on Level %d", current_floor_ptr->dun_level);
6319                 center_string(buf, tmp);
6320                 put_str(buf, 14, 11);
6321
6322                 roff_to_buf(format("by %s.", p_ptr->died_from), GRAVE_LINE_WIDTH + 1, tmp, sizeof tmp);
6323                 center_string(buf, tmp);
6324                 put_str(buf, 15, 11);
6325                 t = tmp + strlen(tmp) + 1;
6326                 if (*t)
6327                 {
6328                         strcpy(dummy, t); /* 2nd line */
6329                         if (*(t + strlen(t) + 1)) /* Does 3rd line exist? */
6330                         {
6331                                 int dummy_len = strlen(dummy);
6332                                 strcpy(dummy + MIN(dummy_len, GRAVE_LINE_WIDTH - 3), "...");
6333                         }
6334                         center_string(buf, dummy);
6335                         put_str(buf, 16, 11);
6336                 }
6337 #endif
6338
6339                 (void)sprintf(tmp, "%-.24s", ctime(&ct));
6340                 center_string(buf, tmp);
6341                 put_str(buf, 17, 11);
6342                 msg_format(_("さようなら、%s!", "Goodbye, %s!"), p_ptr->name);
6343         }
6344 }
6345
6346
6347 /*!
6348  * @brief 死亡、引退時の簡易ステータス表示 /
6349  * Display some character info
6350  * @return なし
6351  */
6352 void show_info(void)
6353 {
6354         int             i, j, k, l;
6355         object_type *o_ptr;
6356         store_type              *st_ptr;
6357
6358         /* Hack -- Know everything in the inven/equip */
6359         for (i = 0; i < INVEN_TOTAL; i++)
6360         {
6361                 o_ptr = &p_ptr->inventory_list[i];
6362                 if (!o_ptr->k_idx) continue;
6363
6364                 /* Aware and Known */
6365                 object_aware(o_ptr);
6366                 object_known(o_ptr);
6367         }
6368
6369         for (i = 1; i < max_towns; i++)
6370         {
6371                 st_ptr = &town_info[i].store[STORE_HOME];
6372
6373                 /* Hack -- Know everything in the home */
6374                 for (j = 0; j < st_ptr->stock_num; j++)
6375                 {
6376                         o_ptr = &st_ptr->stock[j];
6377                         if (!o_ptr->k_idx) continue;
6378
6379                         /* Aware and Known */
6380                         object_aware(o_ptr);
6381                         object_known(o_ptr);
6382                 }
6383         }
6384
6385         /* Hack -- Recalculate bonuses */
6386         p_ptr->update |= (PU_BONUS);
6387         handle_stuff();
6388
6389         /* Flush all input keys */
6390         flush();
6391
6392         msg_erase();
6393
6394
6395         /* Describe options */
6396         prt(_("キャラクターの記録をファイルに書き出すことができます。", "You may now dump a character record to one or more files."), 21, 0);
6397         prt(_("リターンキーでキャラクターを見ます。ESCで中断します。", "Then, hit RETURN to see the character, or ESC to abort."), 22, 0);
6398
6399         /* Dump character records as requested */
6400         while (TRUE)
6401         {
6402                 char out_val[160];
6403
6404                 /* Prompt */
6405                 put_str(_("ファイルネーム: ", "Filename: "), 23, 0);
6406
6407                 /* Default */
6408                 strcpy(out_val, "");
6409
6410                 /* Ask for filename (or abort) */
6411                 if (!askfor(out_val, 60)) return;
6412
6413                 /* Return means "show on screen" */
6414                 if (!out_val[0]) break;
6415                 screen_save();
6416
6417                 /* Dump a character file */
6418                 (void)file_character(out_val);
6419                 screen_load();
6420         }
6421
6422         update_playtime();
6423         display_player(p_ptr, 0);
6424
6425         /* Prompt for p_ptr->inventory_list */
6426         prt(_("何かキーを押すとさらに情報が続きます (ESCで中断): ", "Hit any key to see more information (ESC to abort): "), 23, 0);
6427
6428         /* Allow abort at this point */
6429         if (inkey() == ESCAPE) return;
6430
6431
6432         /* Show equipment and p_ptr->inventory_list */
6433
6434         /* Equipment -- if any */
6435         if (p_ptr->equip_cnt)
6436         {
6437                 Term_clear();
6438                 (void)show_equip(0, USE_FULL, 0);
6439                 prt(_("装備していたアイテム: -続く-", "You are using: -more-"), 0, 0);
6440
6441                 if (inkey() == ESCAPE) return;
6442         }
6443
6444         /* Inventory -- if any */
6445         if (p_ptr->inven_cnt)
6446         {
6447                 Term_clear();
6448                 (void)show_inven(0, USE_FULL, 0);
6449                 prt(_("持っていたアイテム: -続く-", "You are carrying: -more-"), 0, 0);
6450
6451                 if (inkey() == ESCAPE) return;
6452         }
6453
6454         /* Homes in the different towns */
6455         for (l = 1; l < max_towns; l++)
6456         {
6457                 st_ptr = &town_info[l].store[STORE_HOME];
6458
6459                 /* Home -- if anything there */
6460                 if (st_ptr->stock_num)
6461                 {
6462                         /* Display contents of the home */
6463                         for (k = 0, i = 0; i < st_ptr->stock_num; k++)
6464                         {
6465                                 Term_clear();
6466
6467                                 /* Show 12 items */
6468                                 for (j = 0; (j < 12) && (i < st_ptr->stock_num); j++, i++)
6469                                 {
6470                                         GAME_TEXT o_name[MAX_NLEN];
6471                                         char tmp_val[80];
6472
6473                                         /* Acquire item */
6474                                         o_ptr = &st_ptr->stock[i];
6475
6476                                         /* Print header, clear line */
6477                                         sprintf(tmp_val, "%c) ", I2A(j));
6478                                         prt(tmp_val, j+2, 4);
6479
6480                                         /* Display object description */
6481                                         object_desc(o_name, o_ptr, 0);
6482                                         c_put_str(tval_to_attr[o_ptr->tval], o_name, j+2, 7);
6483                                 }
6484
6485                                 prt(format(_("我が家に置いてあったアイテム ( %d ページ): -続く-", "Your home contains (page %d): -more-"), k+1), 0, 0);
6486
6487                                 /* Wait for it */
6488                                 if (inkey() == ESCAPE) return;
6489                         }
6490                 }
6491         }
6492 }
6493
6494
6495 /*!
6496  * @brief 異常発生時のゲーム緊急終了処理 /
6497  * Handle abrupt death of the visual system
6498  * @return なし
6499  * @details
6500  * <pre>
6501  * This routine is called only in very rare situations, and only
6502  * by certain visual systems, when they experience fatal errors.
6503  * XXX XXX Hack -- clear the death flag when creating a HANGUP
6504  * save file so that player can see tombstone when restart.
6505  * </pre>
6506  */
6507 void exit_game_panic(void)
6508 {
6509         /* If nothing important has happened, just quit */
6510         if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(_("緊急事態", "panic"));
6511
6512         /* Mega-Hack -- see "msg_print()" */
6513         msg_flag = FALSE;
6514
6515         /* Clear the top line */
6516         prt("", 0, 0);
6517
6518         /* Hack -- current_world_ptr->game_turn off some things */
6519         disturb(p_ptr, TRUE, TRUE);
6520
6521         /* Mega-Hack -- Delay death */
6522         if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
6523
6524         /* Hardcode panic save */
6525         p_ptr->panic_save = 1;
6526
6527         /* Forbid suspend */
6528         signals_ignore_tstp();
6529
6530         /* Indicate panic save */
6531         (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
6532
6533         /* Panic save, or get worried */
6534         if (!save_player()) quit(_("緊急セーブ失敗!", "panic save failed!"));
6535
6536         /* Successful panic save */
6537         quit(_("緊急セーブ成功!", "panic save succeeded!"));
6538 }
6539
6540
6541 /*!
6542  * @brief ファイルからランダムに行を一つ取得する /
6543  * Get a random line from a file
6544  * @param file_name ファイル名
6545  * @param entry 特定条件時のN:タグヘッダID
6546  * @param output 出力先の文字列参照ポインタ
6547  * @return エラーコード
6548  * @details
6549  * <pre>
6550  * Based on the monster speech patch by Matt Graham,
6551  * </pre>
6552  */
6553 errr get_rnd_line(concptr file_name, int entry, char *output)
6554 {
6555         FILE    *fp;
6556         char    buf[1024];
6557         int     counter, test;
6558         int     line_num = 0;
6559
6560         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, file_name);
6561         fp = my_fopen(buf, "r");
6562
6563         /* Failed */
6564         if (!fp) return -1;
6565
6566         /* Find the entry of the monster */
6567         while (TRUE)
6568         {
6569                 /* Get a line from the file */
6570                 if (my_fgets(fp, buf, sizeof(buf)) == 0)
6571                 {
6572                         /* Count the lines */
6573                         line_num++;
6574
6575                         /* Look for lines starting with 'N:' */
6576                         if ((buf[0] == 'N') && (buf[1] == ':'))
6577                         {
6578                                 /* Allow default lines */
6579                                 if (buf[2] == '*')
6580                                 {
6581                                         /* Default lines */
6582                                         break;
6583                                 }
6584                                 else if (buf[2] == 'M')
6585                                 {
6586                                         if (r_info[entry].flags1 & RF1_MALE) break;
6587                                 }
6588                                 else if (buf[2] == 'F')
6589                                 {
6590                                         if (r_info[entry].flags1 & RF1_FEMALE) break;
6591                                 }
6592                                 /* Get the monster number */
6593                                 else if (sscanf(&(buf[2]), "%d", &test) != EOF)
6594                                 {
6595                                         /* Is it the right number? */
6596                                         if (test == entry) break;
6597                                 }
6598                                 else
6599                                 {
6600                                         /* Error while converting the number */
6601                                         msg_format("Error in line %d of %s!", line_num, file_name);
6602                                         my_fclose(fp);
6603                                         return -1;
6604                                 }
6605                         }
6606                 }
6607                 else
6608                 {
6609                         /* Reached end of file */
6610                         my_fclose(fp);
6611                         return -1;
6612                 }
6613         }
6614
6615         /* Get the random line */
6616         for (counter = 0; ; counter++)
6617         {
6618                 while (TRUE)
6619                 {
6620                         test = my_fgets(fp, buf, sizeof(buf));
6621
6622                         /* Count the lines */
6623                         /* line_num++; No more needed */
6624
6625                         if (!test)
6626                         {
6627                                 /* Ignore lines starting with 'N:' */
6628                                 if ((buf[0] == 'N') && (buf[1] == ':')) continue;
6629
6630                                 if (buf[0] != '#') break;
6631                         }
6632                         else break;
6633                 }
6634
6635                 /* Abort */
6636                 if (!buf[0]) break;
6637
6638                 /* Copy the line */
6639                 if (one_in_(counter + 1)) strcpy(output, buf);
6640         }
6641         my_fclose(fp);
6642
6643         /* Success */
6644         return counter ? 0 : -1;
6645 }
6646
6647
6648 #ifdef JP
6649 /*!
6650  * @brief ファイルからランダムに行を一つ取得する(日本語文字列のみ) /
6651  * @param file_name ファイル名
6652  * @param entry 特定条件時のN:タグヘッダID
6653  * @param output 出力先の文字列参照ポインタ
6654  * @param count 試行回数
6655  * @return エラーコード
6656  * @details
6657  */
6658 errr get_rnd_line_jonly(concptr file_name, int entry, char *output, int count)
6659 {
6660         int  i, j, kanji;
6661         errr result = 1;
6662
6663         for (i = 0; i < count; i++)
6664         {
6665                 result = get_rnd_line(file_name, entry, output);
6666                 if (result) break;
6667                 kanji = 0;
6668                 for (j = 0; output[j]; j++) kanji |= iskanji(output[j]);
6669                 if (kanji) break;
6670         }
6671         return result;
6672 }
6673 #endif
6674
6675 /*!
6676  * @brief 自動拾いファイルを読み込む /
6677  * @param name ファイル名
6678  * @details
6679  */
6680 errr process_autopick_file(concptr name)
6681 {
6682         char buf[1024];
6683
6684         errr err = 0;
6685         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
6686
6687         err = process_pref_file_aux(buf, PREF_TYPE_AUTOPICK);
6688         return (err);
6689 }
6690
6691
6692 /*!
6693  * @brief プレイヤーの生い立ちファイルを読み込む /
6694  * Process file for player's history editor.
6695  * @param name ファイル名
6696  * @return エラーコード
6697  * @details
6698  */
6699 errr process_histpref_file(concptr name)
6700 {
6701         char buf[1024];
6702         errr err = 0;
6703         bool old_character_xtra = current_world_ptr->character_xtra;
6704         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
6705
6706         /* Hack -- prevent modification birth options in this file */
6707         current_world_ptr->character_xtra = TRUE;
6708
6709         err = process_pref_file_aux(buf, PREF_TYPE_HISTPREF);
6710
6711         current_world_ptr->character_xtra = old_character_xtra;
6712         return (err);
6713 }
6714
6715 /*!
6716  * @brief ファイル位置をシーク /
6717  * @param fd ファイルディスクリプタ
6718  * @param where ファイルバイト位置
6719  * @param flag FALSEならば現ファイルを超えた位置へシーク時エラー、TRUEなら足りない間を0で埋め尽くす
6720  * @return エラーコード
6721  * @details
6722  */
6723 static errr counts_seek(int fd, u32b where, bool flag)
6724 {
6725         huge seekpoint;
6726         char temp1[128], temp2[128];
6727         u32b zero_header[3] = {0L, 0L, 0L};
6728         int i;
6729
6730 #ifdef SAVEFILE_USE_UID
6731         (void)sprintf(temp1, "%d.%s.%d%d%d", p_ptr->player_uid, savefile_base, p_ptr->pclass, p_ptr->pseikaku, p_ptr->age);
6732 #else
6733         (void)sprintf(temp1, "%s.%d%d%d", savefile_base, p_ptr->pclass, p_ptr->pseikaku, p_ptr->age);
6734 #endif
6735         for (i = 0; temp1[i]; i++)
6736                 temp1[i] ^= (i+1) * 63;
6737
6738         seekpoint = 0;
6739         while (1)
6740         {
6741                 if (fd_seek(fd, seekpoint + 3 * sizeof(u32b)))
6742                         return 1;
6743                 if (fd_read(fd, (char*)(temp2), sizeof(temp2)))
6744                 {
6745                         if (!flag)
6746                                 return 1;
6747                         /* add new name */
6748                         fd_seek(fd, seekpoint);
6749                         fd_write(fd, (char*)zero_header, 3*sizeof(u32b));
6750                         fd_write(fd, (char*)(temp1), sizeof(temp1));
6751                         break;
6752                 }
6753
6754                 if (strcmp(temp1, temp2) == 0)
6755                         break;
6756
6757                 seekpoint += 128 + 3 * sizeof(u32b);
6758         }
6759
6760         return fd_seek(fd, seekpoint + where * sizeof(u32b));
6761 }
6762
6763 /*!
6764  * @brief ファイル位置を読み込む
6765  * @param where ファイルバイト位置
6766  * @return エラーコード
6767  * @details
6768  */
6769 u32b counts_read(int where)
6770 {
6771         int fd;
6772         u32b count = 0;
6773         char buf[1024];
6774
6775         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, _("z_info_j.raw", "z_info.raw"));
6776         fd = fd_open(buf, O_RDONLY);
6777
6778         if (counts_seek(fd, where, FALSE) ||
6779             fd_read(fd, (char*)(&count), sizeof(u32b)))
6780                 count = 0;
6781
6782         (void)fd_close(fd);
6783
6784         return count;
6785 }
6786
6787 /*!
6788  * @brief ファイル位置に書き込む /
6789  * @param where ファイルバイト位置
6790  * @param count 書き込む値
6791  * @return エラーコード
6792  * @details
6793  */
6794 errr counts_write(int where, u32b count)
6795 {
6796         int fd;
6797         char buf[1024];
6798         errr err;
6799
6800         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, _("z_info_j.raw", "z_info.raw"));
6801
6802         /* Grab permissions */
6803         safe_setuid_grab();
6804
6805         fd = fd_open(buf, O_RDWR);
6806
6807         /* Drop permissions */
6808         safe_setuid_drop();
6809
6810         if (fd < 0)
6811         {
6812                 /* File type is "DATA" */
6813                 FILE_TYPE(FILE_TYPE_DATA);
6814
6815                 /* Grab permissions */
6816                 safe_setuid_grab();
6817
6818                 /* Create a new high score file */
6819                 fd = fd_make(buf, 0644);
6820
6821                 /* Drop permissions */
6822                 safe_setuid_drop();
6823         }
6824
6825         /* Grab permissions */
6826         safe_setuid_grab();
6827
6828         err = fd_lock(fd, F_WRLCK);
6829
6830         /* Drop permissions */
6831         safe_setuid_drop();
6832
6833         if (err) return 1;
6834
6835         counts_seek(fd, where, TRUE);
6836         fd_write(fd, (char*)(&count), sizeof(u32b));
6837
6838         /* Grab permissions */
6839         safe_setuid_grab();
6840
6841         err = fd_lock(fd, F_UNLCK);
6842
6843         /* Drop permissions */
6844         safe_setuid_drop();
6845
6846         if (err) return 1;
6847
6848         (void)fd_close(fd);
6849
6850         return 0;
6851 }
6852
6853
6854 #ifdef HANDLE_SIGNALS
6855
6856
6857 #include <signal.h>
6858
6859
6860 /*!
6861  * @brief OSからのシグナルを受けてサスペンド状態に入る /
6862  * Handle signals -- suspend
6863  * @param sig 受け取ったシグナル
6864  * @details
6865  * Actually suspend the game, and then resume cleanly
6866  */
6867 static void handle_signal_suspend(int sig)
6868 {
6869         /* Disable handler */
6870         (void)signal(sig, SIG_IGN);
6871
6872 #ifdef SIGSTOP
6873
6874         /* Flush output */
6875         Term_fresh();
6876
6877         /* Suspend the "Term" */
6878         Term_xtra(TERM_XTRA_ALIVE, 0);
6879
6880         /* Suspend ourself */
6881         (void)kill(0, SIGSTOP);
6882
6883         /* Resume the "Term" */
6884         Term_xtra(TERM_XTRA_ALIVE, 1);
6885
6886         /* Redraw the term */
6887         Term_redraw();
6888
6889         /* Flush the term */
6890         Term_fresh();
6891
6892 #endif
6893
6894         /* Restore handler */
6895         (void)signal(sig, handle_signal_suspend);
6896 }
6897
6898
6899 /*!
6900  * @brief OSからのシグナルを受けて中断、終了する /
6901  * Handle signals -- simple (interrupt and quit)
6902  * @param sig 受け取ったシグナル
6903  * @details
6904  * <pre>
6905  * This function was causing a *huge* number of problems, so it has
6906  * been simplified greatly.  We keep a global variable which counts
6907  * the number of times the user attempts to kill the process, and
6908  * we commit suicide if the user does this a certain number of times.
6909  * We attempt to give "feedback" to the user as he approaches the
6910  * suicide thresh-hold, but without penalizing accidental keypresses.
6911  * To prevent messy accidents, we should reset this global variable
6912  * whenever the user enters a keypress, or something like that.
6913  * </pre>
6914  */
6915 static void handle_signal_simple(int sig)
6916 {
6917         /* Disable handler */
6918         (void)signal(sig, SIG_IGN);
6919
6920
6921         /* Nothing to save, just quit */
6922         if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(NULL);
6923
6924
6925         /* Count the signals */
6926         signal_count++;
6927
6928
6929         /* Terminate dead characters */
6930         if (p_ptr->is_dead)
6931         {
6932                 /* Mark the savefile */
6933                 (void)strcpy(p_ptr->died_from, _("強制終了", "Abortion"));
6934
6935                 forget_lite(current_floor_ptr);
6936                 forget_view();
6937                 clear_mon_lite(current_floor_ptr);
6938
6939                 /* Close stuff */
6940                 close_game();
6941
6942                 /* Quit */
6943                 quit(_("強制終了", "interrupt"));
6944         }
6945
6946         /* Allow suicide (after 5) */
6947         else if (signal_count >= 5)
6948         {
6949                 /* Cause of "death" */
6950                 (void)strcpy(p_ptr->died_from, _("強制終了中", "Interrupting"));
6951
6952                 forget_lite(current_floor_ptr);
6953                 forget_view();
6954                 clear_mon_lite(current_floor_ptr);
6955
6956                 /* Stop playing */
6957                 p_ptr->playing = FALSE;
6958
6959                 /* Suicide */
6960                 p_ptr->is_dead = TRUE;
6961                 p_ptr->leaving = TRUE;
6962
6963                 /* Close stuff */
6964                 close_game();
6965
6966                 /* Quit */
6967                 quit(_("強制終了", "interrupt"));
6968         }
6969
6970         /* Give warning (after 4) */
6971         else if (signal_count >= 4)
6972         {
6973                 /* Make a noise */
6974                 Term_xtra(TERM_XTRA_NOISE, 0);
6975
6976                 /* Clear the top line */
6977                 Term_erase(0, 0, 255);
6978
6979                 /* Display the cause */
6980                 Term_putstr(0, 0, -1, TERM_WHITE, _("熟慮の上の自殺!", "Contemplating suicide!"));
6981
6982                 Term_fresh();
6983         }
6984
6985         /* Give warning (after 2) */
6986         else if (signal_count >= 2)
6987         {
6988                 /* Make a noise */
6989                 Term_xtra(TERM_XTRA_NOISE, 0);
6990         }
6991
6992         /* Restore handler */
6993         (void)signal(sig, handle_signal_simple);
6994 }
6995
6996
6997 /*!
6998  * @brief OSからのシグナルを受けて強制終了する /
6999  * Handle signal -- abort, kill, etc
7000  * @param sig 受け取ったシグナル
7001  * @return なし
7002  * @details
7003  * <pre>
7004  * This function was causing a *huge* number of problems, so it has
7005  * been simplified greatly.  We keep a global variable which counts
7006  * the number of times the user attempts to kill the process, and
7007  * we commit suicide if the user does this a certain number of times.
7008  * We attempt to give "feedback" to the user as he approaches the
7009  * suicide thresh-hold, but without penalizing accidental keypresses.
7010  * To prevent messy accidents, we should reset this global variable
7011  * whenever the user enters a keypress, or something like that.
7012  * </pre>
7013  */
7014 static void handle_signal_abort(int sig)
7015 {
7016         int wid, hgt;
7017
7018         Term_get_size(&wid, &hgt);
7019
7020         /* Disable handler */
7021         (void)signal(sig, SIG_IGN);
7022
7023
7024         /* Nothing to save, just quit */
7025         if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(NULL);
7026
7027
7028         forget_lite(current_floor_ptr);
7029         forget_view();
7030         clear_mon_lite(current_floor_ptr);
7031
7032         /* Clear the bottom line */
7033         Term_erase(0, hgt - 1, 255);
7034
7035         /* Give a warning */
7036         Term_putstr(0, hgt - 1, -1, TERM_RED,
7037         _("恐ろしいソフトのバグが飛びかかってきた!", "A gruesome software bug LEAPS out at you!"));
7038
7039
7040         Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ...", "Panic save..."));
7041
7042         exe_write_diary(p_ptr, NIKKI_GAMESTART, 0, _("----ゲーム異常終了----", "---- Panic Save and Abort Game ----"));
7043
7044         /* Flush output */
7045         Term_fresh();
7046
7047         /* Panic Save */
7048         p_ptr->panic_save = 1;
7049
7050         /* Panic save */
7051         (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
7052
7053         /* Forbid suspend */
7054         signals_ignore_tstp();
7055
7056         /* Attempt to save */
7057         if (save_player())
7058         {
7059                 Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ成功!", "Panic save succeeded!"));
7060         }
7061
7062         /* Save failed */
7063         else
7064         {
7065                 Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ失敗!", "Panic save failed!"));
7066         }
7067
7068         /* Flush output */
7069         Term_fresh();
7070
7071         /* Quit */
7072         quit(_("ソフトのバグ", "software bug"));
7073 }
7074
7075 /*!
7076  * @brief OSからのSIGTSTPシグナルを無視する関数 /
7077  * Ignore SIGTSTP signals (keyboard suspend)
7078  * @return なし
7079  * @details
7080  */
7081 void signals_ignore_tstp(void)
7082 {
7083
7084 #ifdef SIGTSTP
7085         (void)signal(SIGTSTP, SIG_IGN);
7086 #endif
7087
7088 }
7089
7090 /*!
7091  * @brief OSからのSIGTSTPシグナルハンドラ /
7092  * Handle SIGTSTP signals (keyboard suspend)
7093  * @return なし
7094  * @details
7095  */
7096 void signals_handle_tstp(void)
7097 {
7098
7099 #ifdef SIGTSTP
7100         (void)signal(SIGTSTP, handle_signal_suspend);
7101 #endif
7102
7103 }
7104
7105
7106 /*!
7107  * @brief OSからのシグナルハンドルを初期化する /
7108  * Prepare to handle the relevant signals
7109  * @return なし
7110  * @details
7111  */
7112 void signals_init(void)
7113 {
7114
7115 #ifdef SIGHUP
7116         (void)signal(SIGHUP, SIG_IGN);
7117 #endif
7118
7119
7120 #ifdef SIGTSTP
7121         (void)signal(SIGTSTP, handle_signal_suspend);
7122 #endif
7123
7124
7125 #ifdef SIGINT
7126         (void)signal(SIGINT, handle_signal_simple);
7127 #endif
7128
7129 #ifdef SIGQUIT
7130         (void)signal(SIGQUIT, handle_signal_simple);
7131 #endif
7132
7133
7134 #ifdef SIGFPE
7135         (void)signal(SIGFPE, handle_signal_abort);
7136 #endif
7137
7138 #ifdef SIGILL
7139         (void)signal(SIGILL, handle_signal_abort);
7140 #endif
7141
7142 #ifdef SIGTRAP
7143         (void)signal(SIGTRAP, handle_signal_abort);
7144 #endif
7145
7146 #ifdef SIGIOT
7147         (void)signal(SIGIOT, handle_signal_abort);
7148 #endif
7149
7150 #ifdef SIGKILL
7151         (void)signal(SIGKILL, handle_signal_abort);
7152 #endif
7153
7154 #ifdef SIGBUS
7155         (void)signal(SIGBUS, handle_signal_abort);
7156 #endif
7157
7158 #ifdef SIGSEGV
7159         (void)signal(SIGSEGV, handle_signal_abort);
7160 #endif
7161
7162 #ifdef SIGTERM
7163         (void)signal(SIGTERM, handle_signal_abort);
7164 #endif
7165
7166 #ifdef SIGPIPE
7167         (void)signal(SIGPIPE, handle_signal_abort);
7168 #endif
7169
7170 #ifdef SIGEMT
7171         (void)signal(SIGEMT, handle_signal_abort);
7172 #endif
7173
7174 #ifdef SIGDANGER
7175         (void)signal(SIGDANGER, handle_signal_abort);
7176 #endif
7177
7178 #ifdef SIGSYS
7179         (void)signal(SIGSYS, handle_signal_abort);
7180 #endif
7181
7182 #ifdef SIGXCPU
7183         (void)signal(SIGXCPU, handle_signal_abort);
7184 #endif
7185
7186 #ifdef SIGPWR
7187         (void)signal(SIGPWR, handle_signal_abort);
7188 #endif
7189
7190 }
7191
7192
7193 #else   /* HANDLE_SIGNALS */
7194
7195
7196 /*!
7197  * @brief ダミー /
7198  * Do nothing
7199  */
7200 void signals_ignore_tstp(void)
7201 {
7202 }
7203
7204 /*!
7205  * @brief ダミー /
7206  * Do nothing
7207  */
7208 void signals_handle_tstp(void)
7209 {
7210 }
7211
7212 /*!
7213  * @brief ダミー /
7214  * Do nothing
7215  */
7216 void signals_init(void)
7217 {
7218 }
7219 #endif  /* HANDLE_SIGNALS */