OSDN Git Service

[Refactor] #37353 noscore を world_type へ移動. / Move noscore to world_type structure.
[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 inventory "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 inventory 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>" -- turn option off */
635                 /* Process "Y:<str>" -- 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(creature_ptr)) 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(&p_ptr->current_floor_ptr->m_list[creature_ptr->riding])) tmp_speed += 10;
1876                         if (MON_SLOW(&p_ptr->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(player_type *creature_ptr)
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 (creature_ptr->muta2 & MUT2_HORNS)     muta_att++;
2087         if (creature_ptr->muta2 & MUT2_SCOR_TAIL) muta_att++;
2088         if (creature_ptr->muta2 & MUT2_BEAK)      muta_att++;
2089         if (creature_ptr->muta2 & MUT2_TRUNK)     muta_att++;
2090         if (creature_ptr->muta2 & MUT2_TENTACLES) muta_att++;
2091
2092         xthn = creature_ptr->skill_thn + (creature_ptr->to_h_m * BTH_PLUS_ADJ);
2093
2094         /* Shooting Skill (with current bow and normal missile) */
2095         o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
2096         tmp = creature_ptr->to_h_b + o_ptr->to_h;
2097         xthb = creature_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 = creature_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 (creature_ptr->pclass == CLASS_ARCHER)
2113                         {
2114                                 /* Extra shot at level 10 */
2115                                 if (creature_ptr->lev >= 10) shots++;
2116
2117                                 /* Extra shot at level 30 */
2118                                 if (creature_ptr->lev >= 30) shots++;
2119
2120                                 /* Extra shot at level 45 */
2121                                 if (creature_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] = creature_ptr->dis_to_d[i] * 100;
2134                 if (((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER)) && (empty_hands(creature_ptr, TRUE) & EMPTY_HAND_RARM))
2135                 {
2136                         PLAYER_LEVEL level = creature_ptr->lev;
2137                         if (i)
2138                         {
2139                                 damage[i] = 0;
2140                                 break;
2141                         }
2142                         if (creature_ptr->pclass == CLASS_FORCETRAINER) level = MAX(1, level - 3);
2143                         if (creature_ptr->special_defense & KAMAE_BYAKKO)
2144                                 basedam = monk_ave_damage[level][1];
2145                         else if (creature_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 = &creature_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 + creature_ptr->to_dd[i]) * (o_ptr->ds + creature_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, creature_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 ((creature_ptr->pclass != CLASS_SAMURAI) && have_flag(flgs, TR_FORCE_WEAPON) && (creature_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 = creature_ptr->migite ? creature_ptr->num_blow[0]: 0;
2192         blows2 = creature_ptr->hidarite ? creature_ptr->num_blow[1] : 0;
2193
2194         /* Basic abilities */
2195
2196         xdis = creature_ptr->skill_dis;
2197         xdev = creature_ptr->skill_dev;
2198         xsav = creature_ptr->skill_sav;
2199         xstl = creature_ptr->skill_stl;
2200         xsrh = creature_ptr->skill_srh;
2201         xfos = creature_ptr->skill_fos;
2202         xdig = creature_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", creature_ptr->see_infra * 10), TERM_WHITE);
2252 }
2253
2254
2255
2256 /*!
2257  * @brief プレイヤーの職業、種族に応じた耐性フラグを返す
2258  * Prints ratings on certain abilities
2259  * @param creature_ptr 参照元クリーチャーポインタ
2260  * @param flgs フラグを保管する配列
2261  * @return なし
2262  * @details
2263  * Obtain the "flags" for the player as if he was an item
2264  * @todo
2265  * xtra1.c周りと多重実装になっているのを何とかする
2266  */
2267 static void player_flags(player_type *creature_ptr, BIT_FLAGS flgs[TR_FLAG_SIZE])
2268 {
2269         int i;
2270         for (i = 0; i < TR_FLAG_SIZE; i++)
2271                 flgs[i] = 0L;
2272
2273         /* Classes */
2274         switch (creature_ptr->pclass)
2275         {
2276         case CLASS_WARRIOR:
2277                 if (creature_ptr->lev > 44)
2278                         add_flag(flgs, TR_REGEN);
2279         case CLASS_SAMURAI:
2280                 if (creature_ptr->lev > 29)
2281                         add_flag(flgs, TR_RES_FEAR);
2282                 break;
2283         case CLASS_PALADIN:
2284                 if (creature_ptr->lev > 39)
2285                         add_flag(flgs, TR_RES_FEAR);
2286                 break;
2287         case CLASS_CHAOS_WARRIOR:
2288                 if (creature_ptr->lev > 29)
2289                         add_flag(flgs, TR_RES_CHAOS);
2290                 if (creature_ptr->lev > 39)
2291                         add_flag(flgs, TR_RES_FEAR);
2292                 break;
2293         case CLASS_MONK:
2294         case CLASS_FORCETRAINER:
2295                 if ((creature_ptr->lev > 9) && !heavy_armor(creature_ptr))
2296                         add_flag(flgs, TR_SPEED);
2297                 if ((creature_ptr->lev>24) && !heavy_armor(creature_ptr))
2298                         add_flag(flgs, TR_FREE_ACT);
2299                 break;
2300         case CLASS_NINJA:
2301                 if (heavy_armor(creature_ptr))
2302                         add_flag(flgs, TR_SPEED);
2303                 else
2304                 {
2305                         if ((!creature_ptr->inventory_list[INVEN_RARM].k_idx || creature_ptr->migite) &&
2306                             (!creature_ptr->inventory_list[INVEN_LARM].k_idx || creature_ptr->hidarite))
2307                                 add_flag(flgs, TR_SPEED);
2308                         if (creature_ptr->lev>24)
2309                                 add_flag(flgs, TR_FREE_ACT);
2310                 }
2311                 add_flag(flgs, TR_SLOW_DIGEST);
2312                 add_flag(flgs, TR_RES_FEAR);
2313                 if (creature_ptr->lev > 19) add_flag(flgs, TR_RES_POIS);
2314                 if (creature_ptr->lev > 24) add_flag(flgs, TR_SUST_DEX);
2315                 if (creature_ptr->lev > 29) add_flag(flgs, TR_SEE_INVIS);
2316                 break;
2317         case CLASS_MINDCRAFTER:
2318                 if (creature_ptr->lev > 9)
2319                         add_flag(flgs, TR_RES_FEAR);
2320                 if (creature_ptr->lev > 19)
2321                         add_flag(flgs, TR_SUST_WIS);
2322                 if (creature_ptr->lev > 29)
2323                         add_flag(flgs, TR_RES_CONF);
2324                 if (creature_ptr->lev > 39)
2325                         add_flag(flgs, TR_TELEPATHY);
2326                 break;
2327         case CLASS_BARD:
2328                 add_flag(flgs, TR_RES_SOUND);
2329                 break;
2330         case CLASS_BERSERKER:
2331                 add_flag(flgs, TR_SUST_STR);
2332                 add_flag(flgs, TR_SUST_DEX);
2333                 add_flag(flgs, TR_SUST_CON);
2334                 add_flag(flgs, TR_REGEN);
2335                 add_flag(flgs, TR_FREE_ACT);
2336                 add_flag(flgs, TR_SPEED);
2337                 if (creature_ptr->lev > 39) add_flag(flgs, TR_REFLECT);
2338                 break;
2339         case CLASS_MIRROR_MASTER:
2340                 if(creature_ptr->lev > 39)add_flag(flgs, TR_REFLECT);
2341                 break;
2342         default:
2343                 break; /* Do nothing */
2344         }
2345
2346         /* Races */
2347         if (creature_ptr->mimic_form)
2348         {
2349                 switch(creature_ptr->mimic_form)
2350                 {
2351                 case MIMIC_DEMON:
2352                         add_flag(flgs, TR_HOLD_EXP);
2353                         add_flag(flgs, TR_RES_CHAOS);
2354                         add_flag(flgs, TR_RES_NETHER);
2355                         add_flag(flgs, TR_RES_FIRE);
2356                         add_flag(flgs, TR_SEE_INVIS);
2357                         add_flag(flgs, TR_SPEED);
2358                         break;
2359                 case MIMIC_DEMON_LORD:
2360                         add_flag(flgs, TR_HOLD_EXP);
2361                         add_flag(flgs, TR_RES_CHAOS);
2362                         add_flag(flgs, TR_RES_NETHER);
2363                         add_flag(flgs, TR_RES_FIRE);
2364                         add_flag(flgs, TR_RES_COLD);
2365                         add_flag(flgs, TR_RES_ELEC);
2366                         add_flag(flgs, TR_RES_ACID);
2367                         add_flag(flgs, TR_RES_POIS);
2368                         add_flag(flgs, TR_RES_CONF);
2369                         add_flag(flgs, TR_RES_DISEN);
2370                         add_flag(flgs, TR_RES_NEXUS);
2371                         add_flag(flgs, TR_RES_FEAR);
2372                         add_flag(flgs, TR_IM_FIRE);
2373                         add_flag(flgs, TR_SH_FIRE);
2374                         add_flag(flgs, TR_SEE_INVIS);
2375                         add_flag(flgs, TR_TELEPATHY);
2376                         add_flag(flgs, TR_LEVITATION);
2377                         add_flag(flgs, TR_SPEED);
2378                         break;
2379                 case MIMIC_VAMPIRE:
2380                         add_flag(flgs, TR_HOLD_EXP);
2381                         add_flag(flgs, TR_RES_DARK);
2382                         add_flag(flgs, TR_RES_NETHER);
2383                         if (creature_ptr->pclass != CLASS_NINJA) add_flag(flgs, TR_LITE_1);
2384                         add_flag(flgs, TR_RES_POIS);
2385                         add_flag(flgs, TR_RES_COLD);
2386                         add_flag(flgs, TR_SEE_INVIS);
2387                         add_flag(flgs, TR_SPEED);
2388                         break;
2389                 }
2390         }
2391         else
2392         {
2393         switch (creature_ptr->prace)
2394         {
2395         case RACE_ELF:
2396                 add_flag(flgs, TR_RES_LITE);
2397                 break;
2398         case RACE_HOBBIT:
2399                 add_flag(flgs, TR_HOLD_EXP);
2400                 break;
2401         case RACE_GNOME:
2402                 add_flag(flgs, TR_FREE_ACT);
2403                 break;
2404         case RACE_DWARF:
2405                 add_flag(flgs, TR_RES_BLIND);
2406                 break;
2407         case RACE_HALF_ORC:
2408                 add_flag(flgs, TR_RES_DARK);
2409                 break;
2410         case RACE_HALF_TROLL:
2411                 add_flag(flgs, TR_SUST_STR);
2412                 if (creature_ptr->lev > 14)
2413                 {
2414                         add_flag(flgs, TR_REGEN);
2415                         if ((creature_ptr->pclass == CLASS_WARRIOR) || (creature_ptr->pclass == CLASS_BERSERKER))
2416                         {
2417                                 add_flag(flgs, TR_SLOW_DIGEST);
2418                                 /*
2419                                  * Let's not make Regeneration a disadvantage
2420                                  * for the poor warriors who can never learn
2421                                  * a spell that satisfies hunger (actually
2422                                  * neither can rogues, but half-trolls are not
2423                                  * supposed to play rogues)
2424                                  */
2425                         }
2426                 }
2427                 break;
2428         case RACE_AMBERITE:
2429                 add_flag(flgs, TR_SUST_CON);
2430                 add_flag(flgs, TR_REGEN); /* Amberites heal fast */
2431                 break;
2432         case RACE_HIGH_ELF:
2433                 add_flag(flgs, TR_RES_LITE);
2434                 add_flag(flgs, TR_SEE_INVIS);
2435                 break;
2436         case RACE_BARBARIAN:
2437                 add_flag(flgs, TR_RES_FEAR);
2438                 break;
2439         case RACE_HALF_OGRE:
2440                 add_flag(flgs, TR_SUST_STR);
2441                 add_flag(flgs, TR_RES_DARK);
2442                 break;
2443         case RACE_HALF_GIANT:
2444                 add_flag(flgs, TR_RES_SHARDS);
2445                 add_flag(flgs, TR_SUST_STR);
2446                 break;
2447         case RACE_HALF_TITAN:
2448                 add_flag(flgs, TR_RES_CHAOS);
2449                 break;
2450         case RACE_CYCLOPS:
2451                 add_flag(flgs, TR_RES_SOUND);
2452                 break;
2453         case RACE_YEEK:
2454                 add_flag(flgs, TR_RES_ACID);
2455                 if (creature_ptr->lev > 19)
2456                         add_flag(flgs, TR_IM_ACID);
2457                 break;
2458         case RACE_KLACKON:
2459                 add_flag(flgs, TR_RES_CONF);
2460                 add_flag(flgs, TR_RES_ACID);
2461                 if (creature_ptr->lev > 9)
2462                         add_flag(flgs, TR_SPEED);
2463                 break;
2464         case RACE_KOBOLD:
2465                 add_flag(flgs, TR_RES_POIS);
2466                 break;
2467         case RACE_NIBELUNG:
2468                 add_flag(flgs, TR_RES_DISEN);
2469                 add_flag(flgs, TR_RES_DARK);
2470                 break;
2471         case RACE_DARK_ELF:
2472                 add_flag(flgs, TR_RES_DARK);
2473                 if (creature_ptr->lev > 19)
2474                         add_flag(flgs, TR_SEE_INVIS);
2475                 break;
2476         case RACE_DRACONIAN:
2477                 add_flag(flgs, TR_LEVITATION);
2478                 if (creature_ptr->lev > 4)
2479                         add_flag(flgs, TR_RES_FIRE);
2480                 if (creature_ptr->lev > 9)
2481                         add_flag(flgs, TR_RES_COLD);
2482                 if (creature_ptr->lev > 14)
2483                         add_flag(flgs, TR_RES_ACID);
2484                 if (creature_ptr->lev > 19)
2485                         add_flag(flgs, TR_RES_ELEC);
2486                 if (creature_ptr->lev > 34)
2487                         add_flag(flgs, TR_RES_POIS);
2488                 break;
2489         case RACE_MIND_FLAYER:
2490                 add_flag(flgs, TR_SUST_INT);
2491                 add_flag(flgs, TR_SUST_WIS);
2492                 if (creature_ptr->lev > 14)
2493                         add_flag(flgs, TR_SEE_INVIS);
2494                 if (creature_ptr->lev > 29)
2495                         add_flag(flgs, TR_TELEPATHY);
2496                 break;
2497         case RACE_IMP:
2498                 add_flag(flgs, TR_RES_FIRE);
2499                 if (creature_ptr->lev > 9)
2500                         add_flag(flgs, TR_SEE_INVIS);
2501                 break;
2502         case RACE_GOLEM:
2503                 add_flag(flgs, TR_SEE_INVIS);
2504                 add_flag(flgs, TR_FREE_ACT);
2505                 add_flag(flgs, TR_RES_POIS);
2506                 add_flag(flgs, TR_SLOW_DIGEST);
2507                 if (creature_ptr->lev > 34)
2508                         add_flag(flgs, TR_HOLD_EXP);
2509                 break;
2510         case RACE_SKELETON:
2511                 add_flag(flgs, TR_SEE_INVIS);
2512                 add_flag(flgs, TR_RES_SHARDS);
2513                 add_flag(flgs, TR_HOLD_EXP);
2514                 add_flag(flgs, TR_RES_POIS);
2515                 if (creature_ptr->lev > 9)
2516                         add_flag(flgs, TR_RES_COLD);
2517                 break;
2518         case RACE_ZOMBIE:
2519                 add_flag(flgs, TR_SEE_INVIS);
2520                 add_flag(flgs, TR_HOLD_EXP);
2521                 add_flag(flgs, TR_RES_NETHER);
2522                 add_flag(flgs, TR_RES_POIS);
2523                 add_flag(flgs, TR_SLOW_DIGEST);
2524                 if (creature_ptr->lev > 4)
2525                         add_flag(flgs, TR_RES_COLD);
2526                 break;
2527         case RACE_VAMPIRE:
2528                 add_flag(flgs, TR_HOLD_EXP);
2529                 add_flag(flgs, TR_RES_DARK);
2530                 add_flag(flgs, TR_RES_NETHER);
2531                 if (creature_ptr->pclass != CLASS_NINJA) add_flag(flgs, TR_LITE_1);
2532                 add_flag(flgs, TR_RES_POIS);
2533                 add_flag(flgs, TR_RES_COLD);
2534                 break;
2535         case RACE_SPECTRE:
2536                 add_flag(flgs, TR_LEVITATION);
2537                 add_flag(flgs, TR_FREE_ACT);
2538                 add_flag(flgs, TR_RES_COLD);
2539                 add_flag(flgs, TR_SEE_INVIS);
2540                 add_flag(flgs, TR_HOLD_EXP);
2541                 add_flag(flgs, TR_RES_NETHER);
2542                 add_flag(flgs, TR_RES_POIS);
2543                 add_flag(flgs, TR_SLOW_DIGEST);
2544                 /* XXX pass_wall */
2545                 if (creature_ptr->lev > 34)
2546                         add_flag(flgs, TR_TELEPATHY);
2547                 break;
2548         case RACE_SPRITE:
2549                 add_flag(flgs, TR_RES_LITE);
2550                 add_flag(flgs, TR_LEVITATION);
2551                 if (creature_ptr->lev > 9)
2552                         add_flag(flgs, TR_SPEED);
2553                 break;
2554         case RACE_BEASTMAN:
2555                 add_flag(flgs, TR_RES_SOUND);
2556                 add_flag(flgs, TR_RES_CONF);
2557                 break;
2558         case RACE_ANGEL:
2559                 add_flag(flgs, TR_LEVITATION);
2560                 add_flag(flgs, TR_SEE_INVIS);
2561                 break;
2562         case RACE_DEMON:
2563                 add_flag(flgs, TR_RES_FIRE);
2564                 add_flag(flgs, TR_RES_NETHER);
2565                 add_flag(flgs, TR_HOLD_EXP);
2566                 if (creature_ptr->lev > 9)
2567                         add_flag(flgs, TR_SEE_INVIS);
2568                 break;
2569         case RACE_DUNADAN:
2570                 add_flag(flgs, TR_SUST_CON);
2571                 break;
2572         case RACE_S_FAIRY:
2573                 add_flag(flgs, TR_LEVITATION);
2574                 break;
2575         case RACE_KUTAR:
2576                 add_flag(flgs, TR_RES_CONF);
2577                 break;
2578         case RACE_ANDROID:
2579                 add_flag(flgs, TR_FREE_ACT);
2580                 add_flag(flgs, TR_RES_POIS);
2581                 add_flag(flgs, TR_SLOW_DIGEST);
2582                 add_flag(flgs, TR_HOLD_EXP);
2583                 break;
2584         default:
2585                 ; /* Do nothing */
2586         }
2587         }
2588
2589         /* Mutations */
2590         if (creature_ptr->muta3)
2591         {
2592                 if (creature_ptr->muta3 & MUT3_FLESH_ROT)
2593                 {
2594                         remove_flag(flgs, TR_REGEN);
2595                 }
2596
2597                 if ((creature_ptr->muta3 & MUT3_XTRA_FAT) ||
2598                         (creature_ptr->muta3 & MUT3_XTRA_LEGS) ||
2599                         (creature_ptr->muta3 & MUT3_SHORT_LEG))
2600                 {
2601                         add_flag(flgs, TR_SPEED);
2602                 }
2603
2604                 if (creature_ptr->muta3  & MUT3_ELEC_TOUC)
2605                 {
2606                         add_flag(flgs, TR_SH_ELEC);
2607                 }
2608
2609                 if (creature_ptr->muta3 & MUT3_FIRE_BODY)
2610                 {
2611                         add_flag(flgs, TR_SH_FIRE);
2612                         add_flag(flgs, TR_LITE_1);
2613                 }
2614
2615                 if (creature_ptr->muta3 & MUT3_WINGS)
2616                 {
2617                         add_flag(flgs, TR_LEVITATION);
2618                 }
2619
2620                 if (creature_ptr->muta3 & MUT3_FEARLESS)
2621                 {
2622                         add_flag(flgs, TR_RES_FEAR);
2623                 }
2624
2625                 if (creature_ptr->muta3 & MUT3_REGEN)
2626                 {
2627                         add_flag(flgs, TR_REGEN);
2628                 }
2629
2630                 if (creature_ptr->muta3 & MUT3_ESP)
2631                 {
2632                         add_flag(flgs, TR_TELEPATHY);
2633                 }
2634
2635                 if (creature_ptr->muta3 & MUT3_MOTION)
2636                 {
2637                         add_flag(flgs, TR_FREE_ACT);
2638                 }
2639         }
2640
2641         if (creature_ptr->pseikaku == SEIKAKU_SEXY)
2642                 add_flag(flgs, TR_AGGRAVATE);
2643         if (creature_ptr->pseikaku == SEIKAKU_CHARGEMAN)
2644                 add_flag(flgs, TR_RES_CONF);
2645         if (creature_ptr->pseikaku == SEIKAKU_MUNCHKIN)
2646         {
2647                 add_flag(flgs, TR_RES_BLIND);
2648                 add_flag(flgs, TR_RES_CONF);
2649                 add_flag(flgs, TR_HOLD_EXP);
2650                 if (creature_ptr->pclass != CLASS_NINJA) add_flag(flgs, TR_LITE_1);
2651                 if (creature_ptr->lev > 9)
2652                         add_flag(flgs, TR_SPEED);
2653         }
2654         if (creature_ptr->special_defense & KATA_FUUJIN)
2655                 add_flag(flgs, TR_REFLECT);
2656         if (creature_ptr->special_defense & KAMAE_GENBU)
2657                 add_flag(flgs, TR_REFLECT);
2658         if (creature_ptr->special_defense & KAMAE_SUZAKU)
2659                 add_flag(flgs, TR_LEVITATION);
2660         if (creature_ptr->special_defense & KAMAE_SEIRYU)
2661         {
2662                 add_flag(flgs, TR_RES_FIRE);
2663                 add_flag(flgs, TR_RES_COLD);
2664                 add_flag(flgs, TR_RES_ACID);
2665                 add_flag(flgs, TR_RES_ELEC);
2666                 add_flag(flgs, TR_RES_POIS);
2667                 add_flag(flgs, TR_LEVITATION);
2668                 add_flag(flgs, TR_SH_FIRE);
2669                 add_flag(flgs, TR_SH_ELEC);
2670                 add_flag(flgs, TR_SH_COLD);
2671         }
2672         if (creature_ptr->special_defense & KATA_MUSOU)
2673         {
2674                 add_flag(flgs, TR_RES_FEAR);
2675                 add_flag(flgs, TR_RES_LITE);
2676                 add_flag(flgs, TR_RES_DARK);
2677                 add_flag(flgs, TR_RES_BLIND);
2678                 add_flag(flgs, TR_RES_CONF);
2679                 add_flag(flgs, TR_RES_SOUND);
2680                 add_flag(flgs, TR_RES_SHARDS);
2681                 add_flag(flgs, TR_RES_NETHER);
2682                 add_flag(flgs, TR_RES_NEXUS);
2683                 add_flag(flgs, TR_RES_CHAOS);
2684                 add_flag(flgs, TR_RES_DISEN);
2685                 add_flag(flgs, TR_REFLECT);
2686                 add_flag(flgs, TR_HOLD_EXP);
2687                 add_flag(flgs, TR_FREE_ACT);
2688                 add_flag(flgs, TR_SH_FIRE);
2689                 add_flag(flgs, TR_SH_ELEC);
2690                 add_flag(flgs, TR_SH_COLD);
2691                 add_flag(flgs, TR_LEVITATION);
2692                 add_flag(flgs, TR_LITE_1);
2693                 add_flag(flgs, TR_SEE_INVIS);
2694                 add_flag(flgs, TR_TELEPATHY);
2695                 add_flag(flgs, TR_SLOW_DIGEST);
2696                 add_flag(flgs, TR_REGEN);
2697                 add_flag(flgs, TR_SUST_STR);
2698                 add_flag(flgs, TR_SUST_INT);
2699                 add_flag(flgs, TR_SUST_WIS);
2700                 add_flag(flgs, TR_SUST_DEX);
2701                 add_flag(flgs, TR_SUST_CON);
2702                 add_flag(flgs, TR_SUST_CHR);
2703         }
2704 }
2705
2706 /*!
2707  * @brief プレイヤーの一時的魔法効果による耐性を返す
2708  * Prints ratings on certain abilities
2709  * @param flgs フラグを保管する配列
2710  * @return なし
2711  * @todo
2712  * xtra1.c周りと多重実装になっているのを何とかする
2713  */
2714 static void tim_player_flags(player_type *creature_ptr, BIT_FLAGS flgs[TR_FLAG_SIZE])
2715 {
2716         int i;
2717         for (i = 0; i < TR_FLAG_SIZE; i++)
2718                 flgs[i] = 0L;
2719
2720         if (IS_HERO() || creature_ptr->shero)
2721                 add_flag(flgs, TR_RES_FEAR);
2722         if (creature_ptr->tim_invis)
2723                 add_flag(flgs, TR_SEE_INVIS);
2724         if (creature_ptr->tim_regen)
2725                 add_flag(flgs, TR_REGEN);
2726         if (IS_TIM_ESP())
2727                 add_flag(flgs, TR_TELEPATHY);
2728         if (IS_FAST(creature_ptr) || creature_ptr->slow)
2729                 add_flag(flgs, TR_SPEED);
2730
2731         if (IS_OPPOSE_ACID() && !(creature_ptr->special_defense & DEFENSE_ACID) && !(PRACE_IS_(creature_ptr, RACE_YEEK) && (creature_ptr->lev > 19)))
2732                 add_flag(flgs, TR_RES_ACID);
2733         if (IS_OPPOSE_ELEC() && !(creature_ptr->special_defense & DEFENSE_ELEC))
2734                 add_flag(flgs, TR_RES_ELEC);
2735         if (IS_OPPOSE_FIRE() && !(creature_ptr->special_defense & DEFENSE_FIRE))
2736                 add_flag(flgs, TR_RES_FIRE);
2737         if (IS_OPPOSE_COLD() && !(creature_ptr->special_defense & DEFENSE_COLD))
2738                 add_flag(flgs, TR_RES_COLD);
2739         if (IS_OPPOSE_POIS())
2740                 add_flag(flgs, TR_RES_POIS);
2741
2742         if (creature_ptr->special_attack & ATTACK_ACID)
2743                 add_flag(flgs, TR_BRAND_ACID);
2744         if (creature_ptr->special_attack & ATTACK_ELEC)
2745                 add_flag(flgs, TR_BRAND_ELEC);
2746         if (creature_ptr->special_attack & ATTACK_FIRE)
2747                 add_flag(flgs, TR_BRAND_FIRE);
2748         if (creature_ptr->special_attack & ATTACK_COLD)
2749                 add_flag(flgs, TR_BRAND_COLD);
2750         if (creature_ptr->special_attack & ATTACK_POIS)
2751                 add_flag(flgs, TR_BRAND_POIS);
2752         if (creature_ptr->special_defense & DEFENSE_ACID)
2753                 add_flag(flgs, TR_IM_ACID);
2754         if (creature_ptr->special_defense & DEFENSE_ELEC)
2755                 add_flag(flgs, TR_IM_ELEC);
2756         if (creature_ptr->special_defense & DEFENSE_FIRE)
2757                 add_flag(flgs, TR_IM_FIRE);
2758         if (creature_ptr->special_defense & DEFENSE_COLD)
2759                 add_flag(flgs, TR_IM_COLD);
2760         if (creature_ptr->wraith_form)
2761                 add_flag(flgs, TR_REFLECT);
2762         /* by henkma */
2763         if (creature_ptr->tim_reflect)
2764                 add_flag(flgs, TR_REFLECT);
2765
2766         if (creature_ptr->magicdef)
2767         {
2768                 add_flag(flgs, TR_RES_BLIND);
2769                 add_flag(flgs, TR_RES_CONF);
2770                 add_flag(flgs, TR_REFLECT);
2771                 add_flag(flgs, TR_FREE_ACT);
2772                 add_flag(flgs, TR_LEVITATION);
2773         }
2774         if (creature_ptr->tim_res_nether)
2775         {
2776                 add_flag(flgs, TR_RES_NETHER);
2777         }
2778         if (creature_ptr->tim_sh_fire)
2779         {
2780                 add_flag(flgs, TR_SH_FIRE);
2781         }
2782         if (creature_ptr->ult_res)
2783         {
2784                 add_flag(flgs, TR_RES_FEAR);
2785                 add_flag(flgs, TR_RES_LITE);
2786                 add_flag(flgs, TR_RES_DARK);
2787                 add_flag(flgs, TR_RES_BLIND);
2788                 add_flag(flgs, TR_RES_CONF);
2789                 add_flag(flgs, TR_RES_SOUND);
2790                 add_flag(flgs, TR_RES_SHARDS);
2791                 add_flag(flgs, TR_RES_NETHER);
2792                 add_flag(flgs, TR_RES_NEXUS);
2793                 add_flag(flgs, TR_RES_CHAOS);
2794                 add_flag(flgs, TR_RES_DISEN);
2795                 add_flag(flgs, TR_REFLECT);
2796                 add_flag(flgs, TR_HOLD_EXP);
2797                 add_flag(flgs, TR_FREE_ACT);
2798                 add_flag(flgs, TR_SH_FIRE);
2799                 add_flag(flgs, TR_SH_ELEC);
2800                 add_flag(flgs, TR_SH_COLD);
2801                 add_flag(flgs, TR_LEVITATION);
2802                 add_flag(flgs, TR_LITE_1);
2803                 add_flag(flgs, TR_SEE_INVIS);
2804                 add_flag(flgs, TR_TELEPATHY);
2805                 add_flag(flgs, TR_SLOW_DIGEST);
2806                 add_flag(flgs, TR_REGEN);
2807                 add_flag(flgs, TR_SUST_STR);
2808                 add_flag(flgs, TR_SUST_INT);
2809                 add_flag(flgs, TR_SUST_WIS);
2810                 add_flag(flgs, TR_SUST_DEX);
2811                 add_flag(flgs, TR_SUST_CON);
2812                 add_flag(flgs, TR_SUST_CHR);
2813         }
2814
2815         /* Hex bonuses */
2816         if (creature_ptr->realm1 == REALM_HEX)
2817         {
2818                 if (hex_spelling(HEX_DEMON_AURA))
2819                 {
2820                         add_flag(flgs, TR_SH_FIRE);
2821                         add_flag(flgs, TR_REGEN);
2822                 }
2823                 if (hex_spelling(HEX_ICE_ARMOR)) add_flag(flgs, TR_SH_COLD);
2824                 if (hex_spelling(HEX_SHOCK_CLOAK)) add_flag(flgs, TR_SH_ELEC);
2825         }
2826 }
2827
2828
2829 /* Mode flags for displaying player flags */
2830 #define DP_CURSE   0x01
2831 #define DP_IMM     0x02
2832 #define DP_WP      0x08
2833
2834
2835 /*!
2836  * @brief プレイヤーの装備一覧をシンボルで並べる
2837  * Equippy chars
2838  * @param y 表示するコンソールの行
2839  * @param x 表示するコンソールの列
2840  * @param mode オプション
2841  * @return なし
2842  */
2843 void display_player_equippy(TERM_LEN y, TERM_LEN x, BIT_FLAGS16 mode)
2844 {
2845         int i, max_i;
2846
2847         TERM_COLOR a;
2848         char c;
2849
2850         object_type *o_ptr;
2851
2852         /* Weapon flags need only two column */
2853         if (mode & DP_WP) max_i = INVEN_LARM + 1;
2854         else max_i = INVEN_TOTAL;
2855
2856         /* Dump equippy chars */
2857         for (i = INVEN_RARM; i < max_i; i++)
2858         {
2859                 /* Object */
2860                 o_ptr = &p_ptr->inventory_list[i];
2861
2862                 a = object_attr(o_ptr);
2863                 c = object_char(o_ptr);
2864
2865                 /* Clear the part of the screen */
2866                 if (!equippy_chars || !o_ptr->k_idx)
2867                 {
2868                         c = ' ';
2869                         a = TERM_DARK;
2870                 }
2871
2872                 /* Dump */
2873                 Term_putch(x + i - INVEN_RARM, y, a, c);
2874         }
2875 }
2876
2877
2878 /*!
2879  * @brief プレイヤーの装備による免疫フラグを返す
2880  * @param flgs フラグを保管する配列
2881  * @return なし
2882  * @todo
2883  * xtra1.c周りと多重実装になっているのを何とかする
2884  */
2885 static void known_obj_immunity(BIT_FLAGS flgs[TR_FLAG_SIZE])
2886 {
2887         int i;
2888         for (i = 0; i < TR_FLAG_SIZE; i++)
2889                 flgs[i] = 0L;
2890
2891         /* Check equipment */
2892         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
2893         {
2894                 u32b o_flgs[TR_FLAG_SIZE];
2895
2896                 object_type *o_ptr;
2897
2898                 /* Object */
2899                 o_ptr = &p_ptr->inventory_list[i];
2900
2901                 if (!o_ptr->k_idx) continue;
2902
2903                 /* Known flags */
2904                 object_flags_known(o_ptr, o_flgs);
2905
2906                 if (have_flag(o_flgs, TR_IM_ACID)) add_flag(flgs, TR_RES_ACID);
2907                 if (have_flag(o_flgs, TR_IM_ELEC)) add_flag(flgs, TR_RES_ELEC);
2908                 if (have_flag(o_flgs, TR_IM_FIRE)) add_flag(flgs, TR_RES_FIRE);
2909                 if (have_flag(o_flgs, TR_IM_COLD)) add_flag(flgs, TR_RES_COLD);
2910         }
2911 }
2912
2913 /*!
2914  * @brief プレイヤーの種族による免疫フラグを返す
2915  * @param flgs フラグを保管する配列
2916  * @return なし
2917  * @todo
2918  * xtra1.c周りと多重実装になっているのを何とかする
2919  */
2920 static void player_immunity(BIT_FLAGS flgs[TR_FLAG_SIZE])
2921 {
2922         int i;
2923         for (i = 0; i < TR_FLAG_SIZE; i++)
2924                 flgs[i] = 0L;
2925
2926         if (PRACE_IS_(p_ptr, RACE_SPECTRE))
2927                 add_flag(flgs, TR_RES_NETHER);
2928         if (p_ptr->mimic_form == MIMIC_VAMPIRE || PRACE_IS_(p_ptr, RACE_VAMPIRE))
2929                 add_flag(flgs, TR_RES_DARK);
2930         if (p_ptr->mimic_form == MIMIC_DEMON_LORD)
2931                 add_flag(flgs, TR_RES_FIRE);
2932         else if (PRACE_IS_(p_ptr, RACE_YEEK) && p_ptr->lev > 19)
2933                 add_flag(flgs, TR_RES_ACID);
2934 }
2935
2936 /*!
2937  * @brief プレイヤーの一時的魔法効果による免疫フラグを返す
2938  * @param flgs フラグを保管する配列
2939  * @return なし
2940  * @todo
2941  * xtra1.c周りと多重実装になっているのを何とかする
2942  */
2943 static void tim_player_immunity(player_type *creature_ptr, BIT_FLAGS flgs[TR_FLAG_SIZE])
2944 {
2945         int i;
2946         for (i = 0; i < TR_FLAG_SIZE; i++)
2947                 flgs[i] = 0L;
2948
2949         if (creature_ptr->special_defense & DEFENSE_ACID)
2950                 add_flag(flgs, TR_RES_ACID);
2951         if (creature_ptr->special_defense & DEFENSE_ELEC)
2952                 add_flag(flgs, TR_RES_ELEC);
2953         if (creature_ptr->special_defense & DEFENSE_FIRE)
2954                 add_flag(flgs, TR_RES_FIRE);
2955         if (creature_ptr->special_defense & DEFENSE_COLD)
2956                 add_flag(flgs, TR_RES_COLD);
2957         if (creature_ptr->wraith_form)
2958                 add_flag(flgs, TR_RES_DARK);
2959 }
2960
2961 /*!
2962  * @brief プレイヤーの種族による弱点フラグを返す
2963  * @param flgs フラグを保管する配列
2964  * @return なし
2965  * @todo
2966  * xtra1.c周りと多重実装になっているのを何とかする
2967  */
2968 static void player_vuln_flags(player_type *creature_ptr, BIT_FLAGS flgs[TR_FLAG_SIZE])
2969 {
2970         int i;
2971         for (i = 0; i < TR_FLAG_SIZE; i++)
2972                 flgs[i] = 0L;
2973
2974         if ((creature_ptr->muta3 & MUT3_VULN_ELEM) || (creature_ptr->special_defense & KATA_KOUKIJIN))
2975         {
2976                 add_flag(flgs, TR_RES_ACID);
2977                 add_flag(flgs, TR_RES_ELEC);
2978                 add_flag(flgs, TR_RES_FIRE);
2979                 add_flag(flgs, TR_RES_COLD);
2980         }
2981         if (PRACE_IS_(creature_ptr, RACE_ANDROID))
2982                 add_flag(flgs, TR_RES_ELEC);
2983         if (PRACE_IS_(creature_ptr, RACE_ENT))
2984                 add_flag(flgs, TR_RES_FIRE);
2985         if (PRACE_IS_(creature_ptr, RACE_VAMPIRE) || PRACE_IS_(creature_ptr, RACE_S_FAIRY) ||
2986             (creature_ptr->mimic_form == MIMIC_VAMPIRE))
2987                 add_flag(flgs, TR_RES_LITE);
2988 }
2989
2990
2991 /*
2992  * A struct for storing misc. flags
2993  */
2994 typedef struct {
2995         BIT_FLAGS player_flags[TR_FLAG_SIZE];
2996         BIT_FLAGS tim_player_flags[TR_FLAG_SIZE];
2997         BIT_FLAGS player_imm[TR_FLAG_SIZE];
2998         BIT_FLAGS tim_player_imm[TR_FLAG_SIZE];
2999         BIT_FLAGS player_vuln[TR_FLAG_SIZE];
3000         BIT_FLAGS known_obj_imm[TR_FLAG_SIZE];
3001 } all_player_flags;
3002
3003
3004 /*!
3005  * @brief プレイヤーの特性フラグ一種を表示するサブルーチン /
3006  * Helper function, see below
3007  * @param row コンソール表示位置の左上行
3008  * @param col コンソール表示位置の左上列
3009  * @param header コンソール上で表示する特性名
3010  * @param flag1 参照する特性ID
3011  * @param f プレイヤーの特性情報構造体
3012  * @param mode 表示オプション
3013  * @return なし
3014  */
3015 static void display_flag_aux(TERM_LEN row, TERM_LEN col, concptr header,
3016                                     int flag1, all_player_flags *f, u16b mode)
3017 {
3018         int     i;
3019         bool    vuln = FALSE;
3020         int max_i;
3021         byte header_color = TERM_L_DARK;
3022         int header_col = col;
3023
3024         if (have_flag(f->player_vuln, flag1) &&
3025             !(have_flag(f->known_obj_imm, flag1) ||
3026               have_flag(f->player_imm, flag1) ||
3027               have_flag(f->tim_player_imm, flag1)))
3028                 vuln = TRUE;
3029
3030         /* Advance */
3031         col += strlen(header) + 1;
3032
3033         /* Weapon flags need only two column */
3034         if (mode & DP_WP) max_i = INVEN_LARM + 1;
3035         else max_i = INVEN_TOTAL;
3036
3037         /* Check equipment */
3038         for (i = INVEN_RARM; i < max_i; i++)
3039         {
3040                 BIT_FLAGS flgs[TR_FLAG_SIZE];
3041                 object_type *o_ptr;
3042
3043                 /* Object */
3044                 o_ptr = &p_ptr->inventory_list[i];
3045
3046                 /* Known flags */
3047                 object_flags_known(o_ptr, flgs);
3048
3049                 /* Default */
3050                 if (!(mode & DP_IMM))
3051                         c_put_str((byte)(vuln ? TERM_RED : TERM_SLATE), ".", row, col);
3052
3053                 /* Check flags */
3054                 if (mode & DP_CURSE)
3055                 {
3056                         if (have_flag(flgs, TR_ADD_L_CURSE) || have_flag(flgs, TR_ADD_H_CURSE))
3057                         {
3058                                 c_put_str(TERM_L_DARK, "+", row, col);
3059                                 header_color = TERM_WHITE;
3060                         }
3061                         if (o_ptr->curse_flags & (TRC_CURSED | TRC_HEAVY_CURSE))
3062                         {
3063                                 c_put_str(TERM_WHITE, "+", row, col);
3064                                 header_color = TERM_WHITE;
3065                         }
3066                         if (o_ptr->curse_flags & TRC_PERMA_CURSE)
3067                         {
3068                                 c_put_str(TERM_WHITE, "*", row, col);
3069                                 header_color = TERM_WHITE;
3070                         }
3071                 }
3072                 else if (flag1 == TR_LITE_1)
3073                 {
3074                         if (HAVE_DARK_FLAG(flgs))
3075                         {
3076                                 c_put_str(TERM_L_DARK, "+", row, col);
3077                                 header_color = TERM_WHITE;
3078                         }
3079                         else if (HAVE_LITE_FLAG(flgs))
3080                         {
3081                                 c_put_str(TERM_WHITE, "+", row, col);
3082                                 header_color = TERM_WHITE;
3083                         }
3084                 }
3085                 else
3086                 {
3087                         if (have_flag(flgs, flag1))
3088                         {
3089                                 c_put_str((byte)(vuln ? TERM_L_RED : TERM_WHITE),
3090                                           (mode & DP_IMM) ? "*" : "+", row, col);
3091                                 header_color = TERM_WHITE;
3092                         }
3093                 }
3094
3095                 /* Advance */
3096                 col++;
3097         }
3098
3099         /* Assume that player flag is already written */
3100         if (mode & DP_IMM)
3101         {
3102                 if (header_color != TERM_L_DARK)
3103                 {
3104                         /* Overwrite Header Color */
3105                         c_put_str(header_color, header, row, header_col);
3106                 }
3107                 return;
3108         }
3109
3110         /* Default */
3111         c_put_str((byte)(vuln ? TERM_RED : TERM_SLATE), ".", row, col);
3112
3113         /* Player flags */
3114         if (have_flag(f->player_flags, flag1))
3115         {
3116                 c_put_str((byte)(vuln ? TERM_L_RED : TERM_WHITE), "+", row, col);
3117                 header_color = TERM_WHITE;
3118         }
3119
3120         /* Timed player flags */
3121         if (have_flag(f->tim_player_flags, flag1))
3122         {
3123                 c_put_str((byte)(vuln ? TERM_ORANGE : TERM_YELLOW), "#", row, col);
3124                 header_color = TERM_WHITE;
3125         }
3126
3127         /* Immunity */
3128         if (have_flag(f->tim_player_imm, flag1))
3129         {
3130                 c_put_str(TERM_YELLOW, "*", row, col);
3131                 header_color = TERM_WHITE;
3132         }
3133         if (have_flag(f->player_imm, flag1))
3134         {
3135                 c_put_str(TERM_WHITE, "*", row, col);
3136                 header_color = TERM_WHITE;
3137         }
3138
3139         /* Vulnerability */
3140         if (vuln) c_put_str(TERM_RED, "v", row, col + 1);
3141
3142         /* Header */
3143         c_put_str(header_color, header, row, header_col);
3144 }
3145
3146
3147 /*!
3148  * @brief プレイヤーの特性フラグ一覧表示1 /
3149  * Special display, part 1
3150  * @return なし
3151  */
3152 static void display_player_flag_info(void)
3153 {
3154         TERM_LEN row;
3155         TERM_LEN col;
3156
3157         all_player_flags f;
3158
3159         /* Extract flags and store */
3160         player_flags(p_ptr, f.player_flags);
3161         tim_player_flags(p_ptr, f.tim_player_flags);
3162         player_immunity(f.player_imm);
3163         tim_player_immunity(p_ptr, f.tim_player_imm);
3164         known_obj_immunity(f.known_obj_imm);
3165         player_vuln_flags(p_ptr, f.player_vuln);
3166
3167         /*** Set 1 ***/
3168
3169         row = 12;
3170         col = 1;
3171
3172         display_player_equippy(row-2, col+8, 0);
3173         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+8);
3174
3175 #ifdef JP
3176         display_flag_aux(row+0, col, "耐酸  :", TR_RES_ACID, &f, 0);
3177         display_flag_aux(row+0, col, "耐酸  :", TR_IM_ACID, &f, DP_IMM);
3178         display_flag_aux(row+1, col, "耐電撃:", TR_RES_ELEC, &f, 0);
3179         display_flag_aux(row+1, col, "耐電撃:", TR_IM_ELEC, &f, DP_IMM);
3180         display_flag_aux(row+2, col, "耐火炎:", TR_RES_FIRE, &f, 0);
3181         display_flag_aux(row+2, col, "耐火炎:", TR_IM_FIRE, &f, DP_IMM);
3182         display_flag_aux(row+3, col, "耐冷気:", TR_RES_COLD, &f, 0);
3183         display_flag_aux(row+3, col, "耐冷気:", TR_IM_COLD, &f, DP_IMM);
3184         display_flag_aux(row+4, col, "耐毒  :", TR_RES_POIS, &f, 0);
3185         display_flag_aux(row+5, col, "耐閃光:", TR_RES_LITE, &f, 0);
3186         display_flag_aux(row+6, col, "耐暗黒:", TR_RES_DARK, &f, 0);
3187         display_flag_aux(row+7, col, "耐破片:", TR_RES_SHARDS, &f, 0);
3188         display_flag_aux(row+8, col, "耐盲目:", TR_RES_BLIND, &f, 0);
3189         display_flag_aux(row+9, col, "耐混乱:", TR_RES_CONF, &f, 0);
3190 #else
3191         display_flag_aux(row+0, col, "Acid  :", TR_RES_ACID, &f, 0);
3192         display_flag_aux(row+0, col, "Acid  :", TR_IM_ACID, &f, DP_IMM);
3193         display_flag_aux(row+1, col, "Elec  :", TR_RES_ELEC, &f, 0);
3194         display_flag_aux(row+1, col, "Elec  :", TR_IM_ELEC, &f, DP_IMM);
3195         display_flag_aux(row+2, col, "Fire  :", TR_RES_FIRE, &f, 0);
3196         display_flag_aux(row+2, col, "Fire  :", TR_IM_FIRE, &f, DP_IMM);
3197         display_flag_aux(row+3, col, "Cold  :", TR_RES_COLD, &f, 0);
3198         display_flag_aux(row+3, col, "Cold  :", TR_IM_COLD, &f, DP_IMM);
3199         display_flag_aux(row+4, col, "Poison:", TR_RES_POIS, &f, 0);
3200         display_flag_aux(row+5, col, "Light :", TR_RES_LITE, &f, 0);
3201         display_flag_aux(row+6, col, "Dark  :", TR_RES_DARK, &f, 0);
3202         display_flag_aux(row+7, col, "Shard :", TR_RES_SHARDS, &f, 0);
3203         display_flag_aux(row+8, col, "Blind :", TR_RES_BLIND, &f, 0);
3204         display_flag_aux(row+9, col, "Conf  :", TR_RES_CONF, &f, 0);
3205 #endif
3206
3207
3208         /*** Set 2 ***/
3209
3210         row = 12;
3211         col = 26;
3212
3213         display_player_equippy(row-2, col+8, 0);
3214
3215         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+8);
3216
3217 #ifdef JP
3218         display_flag_aux(row+0, col, "耐轟音:", TR_RES_SOUND, &f, 0);
3219         display_flag_aux(row+1, col, "耐地獄:", TR_RES_NETHER, &f, 0);
3220         display_flag_aux(row+2, col, "耐因混:", TR_RES_NEXUS, &f, 0);
3221         display_flag_aux(row+3, col, "耐カオ:", TR_RES_CHAOS, &f, 0);
3222         display_flag_aux(row+4, col, "耐劣化:", TR_RES_DISEN, &f, 0);
3223         display_flag_aux(row+5, col, "耐恐怖:", TR_RES_FEAR, &f, 0);
3224         display_flag_aux(row+6, col, "反射  :", TR_REFLECT, &f, 0);
3225         display_flag_aux(row+7, col, "火炎オ:", TR_SH_FIRE, &f, 0);
3226         display_flag_aux(row+8, col, "電気オ:", TR_SH_ELEC, &f, 0);
3227         display_flag_aux(row+9, col, "冷気オ:", TR_SH_COLD, &f, 0);
3228 #else
3229         display_flag_aux(row+0, col, "Sound :", TR_RES_SOUND, &f, 0);
3230         display_flag_aux(row+1, col, "Nether:", TR_RES_NETHER, &f, 0);
3231         display_flag_aux(row+2, col, "Nexus :", TR_RES_NEXUS, &f, 0);
3232         display_flag_aux(row+3, col, "Chaos :", TR_RES_CHAOS, &f, 0);
3233         display_flag_aux(row+4, col, "Disnch:", TR_RES_DISEN, &f, 0);
3234         display_flag_aux(row+5, col, "Fear  :", TR_RES_FEAR, &f, 0);
3235         display_flag_aux(row+6, col, "Reflct:", TR_REFLECT, &f, 0);
3236         display_flag_aux(row+7, col, "AuFire:", TR_SH_FIRE, &f, 0);
3237         display_flag_aux(row+8, col, "AuElec:", TR_SH_ELEC, &f, 0);
3238         display_flag_aux(row+9, col, "AuCold:", TR_SH_COLD, &f, 0);
3239 #endif
3240
3241
3242         /*** Set 3 ***/
3243
3244         row = 12;
3245         col = 51;
3246
3247         display_player_equippy(row-2, col+12, 0);
3248
3249         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+12);
3250
3251 #ifdef JP
3252         display_flag_aux(row+0, col, "加速      :", TR_SPEED, &f, 0);
3253         display_flag_aux(row+1, col, "耐麻痺    :", TR_FREE_ACT, &f, 0);
3254         display_flag_aux(row+2, col, "透明体視認:", TR_SEE_INVIS, &f, 0);
3255         display_flag_aux(row+3, col, "経験値保持:", TR_HOLD_EXP, &f, 0);
3256         display_flag_aux(row+4, col, "警告      :", TR_WARNING, &f, 0);
3257         display_flag_aux(row+5, col, "遅消化    :", TR_SLOW_DIGEST, &f, 0);
3258         display_flag_aux(row+6, col, "急回復    :", TR_REGEN, &f, 0);
3259         display_flag_aux(row+7, col, "浮遊      :", TR_LEVITATION, &f, 0);
3260         display_flag_aux(row+8, col, "永遠光源  :", TR_LITE_1, &f, 0);
3261         display_flag_aux(row+9, col, "呪い      :", 0, &f, DP_CURSE);
3262 #else
3263         display_flag_aux(row+0, col, "Speed     :", TR_SPEED, &f, 0);
3264         display_flag_aux(row+1, col, "FreeAction:", TR_FREE_ACT, &f, 0);
3265         display_flag_aux(row+2, col, "SeeInvisi.:", TR_SEE_INVIS, &f, 0);
3266         display_flag_aux(row+3, col, "Hold Exp  :", TR_HOLD_EXP, &f, 0);
3267         display_flag_aux(row+4, col, "Warning   :", TR_WARNING, &f, 0);
3268         display_flag_aux(row+5, col, "SlowDigest:", TR_SLOW_DIGEST, &f, 0);
3269         display_flag_aux(row+6, col, "Regene.   :", TR_REGEN, &f, 0);
3270         display_flag_aux(row+7, col, "Levitation:", TR_LEVITATION, &f, 0);
3271         display_flag_aux(row+8, col, "Perm Lite :", TR_LITE_1, &f, 0);
3272         display_flag_aux(row+9, col, "Cursed    :", 0, &f, DP_CURSE);
3273 #endif
3274
3275 }
3276
3277
3278 /*!
3279  * @brief プレイヤーの特性フラグ一覧表示2 /
3280  * Special display, part 2
3281  * @return なし
3282  */
3283 static void display_player_other_flag_info(void)
3284 {
3285         TERM_LEN row;
3286         TERM_LEN col;
3287
3288         all_player_flags f;
3289
3290         /* Extract flags and store */
3291         player_flags(p_ptr, f.player_flags);
3292         tim_player_flags(p_ptr, f.tim_player_flags);
3293         player_immunity(f.player_imm);
3294         tim_player_immunity(p_ptr, f.tim_player_imm);
3295         known_obj_immunity(f.known_obj_imm);
3296         player_vuln_flags(p_ptr, f.player_vuln);
3297
3298         /*** Set 1 ***/
3299
3300         row = 3;
3301         col = 1;
3302
3303         display_player_equippy(row-2, col+12, DP_WP);
3304
3305         c_put_str(TERM_WHITE, "ab@", row-1, col+12);
3306
3307 #ifdef JP
3308         display_flag_aux(row+ 0, col, "邪悪 倍打 :", TR_SLAY_EVIL, &f, DP_WP);
3309         display_flag_aux(row+ 0, col, "邪悪 倍打 :", TR_KILL_EVIL, &f, (DP_WP|DP_IMM));
3310         display_flag_aux(row+ 1, col, "不死 倍打 :", TR_SLAY_UNDEAD, &f, DP_WP);
3311         display_flag_aux(row+ 1, col, "不死 倍打 :", TR_KILL_UNDEAD, &f, (DP_WP|DP_IMM));
3312         display_flag_aux(row+ 2, col, "悪魔 倍打 :", TR_SLAY_DEMON, &f, DP_WP);
3313         display_flag_aux(row+ 2, col, "悪魔 倍打 :", TR_KILL_DEMON, &f, (DP_WP|DP_IMM));
3314         display_flag_aux(row+ 3, col, "龍 倍打   :", TR_SLAY_DRAGON, &f, DP_WP);
3315         display_flag_aux(row+ 3, col, "龍 倍打   :", TR_KILL_DRAGON, &f, (DP_WP|DP_IMM));
3316         display_flag_aux(row+ 4, col, "人間 倍打 :", TR_SLAY_HUMAN, &f, DP_WP);
3317         display_flag_aux(row+ 4, col, "人間 倍打 :", TR_KILL_HUMAN, &f, (DP_WP|DP_IMM));
3318         display_flag_aux(row+ 5, col, "動物 倍打 :", TR_SLAY_ANIMAL, &f, DP_WP);
3319         display_flag_aux(row+ 5, col, "動物 倍打 :", TR_KILL_ANIMAL, &f, (DP_WP|DP_IMM));
3320         display_flag_aux(row+ 6, col, "オーク倍打:", TR_SLAY_ORC, &f, DP_WP);
3321         display_flag_aux(row+ 6, col, "オーク倍打:", TR_KILL_ORC, &f, (DP_WP|DP_IMM));
3322         display_flag_aux(row+ 7, col, "トロル倍打:", TR_SLAY_TROLL, &f, DP_WP);
3323         display_flag_aux(row+ 7, col, "トロル倍打:", TR_KILL_TROLL, &f, (DP_WP|DP_IMM));
3324         display_flag_aux(row+ 8, col, "巨人 倍打 :", TR_SLAY_GIANT, &f, DP_WP);
3325         display_flag_aux(row+ 8, col, "巨人 倍打 :", TR_KILL_GIANT, &f, (DP_WP|DP_IMM));
3326         display_flag_aux(row+ 9, col, "溶解      :", TR_BRAND_ACID, &f, DP_WP);
3327         display_flag_aux(row+10, col, "電撃      :", TR_BRAND_ELEC, &f, DP_WP);
3328         display_flag_aux(row+11, col, "焼棄      :", TR_BRAND_FIRE, &f, DP_WP);
3329         display_flag_aux(row+12, col, "凍結      :", TR_BRAND_COLD, &f, DP_WP);
3330         display_flag_aux(row+13, col, "毒殺      :", TR_BRAND_POIS, &f, DP_WP);
3331         display_flag_aux(row+14, col, "切れ味    :", TR_VORPAL, &f, DP_WP);
3332         display_flag_aux(row+15, col, "地震      :", TR_IMPACT, &f, DP_WP);
3333         display_flag_aux(row+16, col, "吸血      :", TR_VAMPIRIC, &f, DP_WP);
3334         display_flag_aux(row+17, col, "カオス効果:", TR_CHAOTIC, &f, DP_WP);
3335         display_flag_aux(row+18, col, "理力      :", TR_FORCE_WEAPON, &f, DP_WP);
3336 #else
3337         display_flag_aux(row+ 0, col, "Slay Evil :", TR_SLAY_EVIL, &f, DP_WP);
3338         display_flag_aux(row+ 0, col, "Slay Evil :", TR_KILL_EVIL, &f, (DP_WP|DP_IMM));
3339         display_flag_aux(row+ 1, col, "Slay Und. :", TR_SLAY_UNDEAD, &f, DP_WP);
3340         display_flag_aux(row+ 1, col, "Slay Und. :", TR_KILL_UNDEAD, &f, (DP_WP|DP_IMM));
3341         display_flag_aux(row+ 2, col, "Slay Demon:", TR_SLAY_DEMON, &f, DP_WP);
3342         display_flag_aux(row+ 2, col, "Slay Demon:", TR_KILL_DEMON, &f, (DP_WP|DP_IMM));
3343         display_flag_aux(row+ 3, col, "Slay Drag.:", TR_SLAY_DRAGON, &f, DP_WP);
3344         display_flag_aux(row+ 3, col, "Slay Drag.:", TR_KILL_DRAGON, &f, (DP_WP|DP_IMM));
3345         display_flag_aux(row+ 4, col, "Slay Human:", TR_SLAY_HUMAN, &f, DP_WP);
3346         display_flag_aux(row+ 4, col, "Slay Human:", TR_KILL_HUMAN, &f, (DP_WP|DP_IMM));
3347         display_flag_aux(row+ 5, col, "Slay Anim.:", TR_SLAY_ANIMAL, &f, DP_WP);
3348         display_flag_aux(row+ 5, col, "Slay Anim.:", TR_KILL_ANIMAL, &f, (DP_WP|DP_IMM));
3349         display_flag_aux(row+ 6, col, "Slay Orc  :", TR_SLAY_ORC, &f, DP_WP);
3350         display_flag_aux(row+ 6, col, "Slay Orc  :", TR_KILL_ORC, &f, (DP_WP|DP_IMM));
3351         display_flag_aux(row+ 7, col, "Slay Troll:", TR_SLAY_TROLL, &f, DP_WP);
3352         display_flag_aux(row+ 7, col, "Slay Troll:", TR_KILL_TROLL, &f, (DP_WP|DP_IMM));
3353         display_flag_aux(row+ 8, col, "Slay Giant:", TR_SLAY_GIANT, &f, DP_WP);
3354         display_flag_aux(row+ 8, col, "Slay Giant:", TR_KILL_GIANT, &f, (DP_WP|DP_IMM));
3355         display_flag_aux(row+ 9, col, "Acid Brand:", TR_BRAND_ACID, &f, DP_WP);
3356         display_flag_aux(row+10, col, "Elec Brand:", TR_BRAND_ELEC, &f, DP_WP);
3357         display_flag_aux(row+11, col, "Fire Brand:", TR_BRAND_FIRE, &f, DP_WP);
3358         display_flag_aux(row+12, col, "Cold Brand:", TR_BRAND_COLD, &f, DP_WP);
3359         display_flag_aux(row+13, col, "Poison Brd:", TR_BRAND_POIS, &f, DP_WP);
3360         display_flag_aux(row+14, col, "Sharpness :", TR_VORPAL, &f, DP_WP);
3361         display_flag_aux(row+15, col, "Quake     :", TR_IMPACT, &f, DP_WP);
3362         display_flag_aux(row+16, col, "Vampiric  :", TR_VAMPIRIC, &f, DP_WP);
3363         display_flag_aux(row+17, col, "Chaotic   :", TR_CHAOTIC, &f, DP_WP);
3364         display_flag_aux(row+18, col, "Force Wep.:", TR_FORCE_WEAPON, &f, DP_WP);
3365 #endif
3366
3367
3368         /*** Set 2 ***/
3369
3370         row = 3;
3371         col = col + 12 + 7;
3372
3373         display_player_equippy(row-2, col+13, 0);
3374         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+13);
3375
3376 #ifdef JP
3377         display_flag_aux(row+ 0, col, "テレパシー :", TR_TELEPATHY, &f, 0);
3378         display_flag_aux(row+ 1, col, "邪悪ESP    :", TR_ESP_EVIL, &f, 0);
3379         display_flag_aux(row+ 2, col, "無生物ESP  :", TR_ESP_NONLIVING, &f, 0);
3380         display_flag_aux(row+ 3, col, "善良ESP    :", TR_ESP_GOOD, &f, 0);
3381         display_flag_aux(row+ 4, col, "不死ESP    :", TR_ESP_UNDEAD, &f, 0);
3382         display_flag_aux(row+ 5, col, "悪魔ESP    :", TR_ESP_DEMON, &f, 0);
3383         display_flag_aux(row+ 6, col, "龍ESP      :", TR_ESP_DRAGON, &f, 0);
3384         display_flag_aux(row+ 7, col, "人間ESP    :", TR_ESP_HUMAN, &f, 0);
3385         display_flag_aux(row+ 8, col, "動物ESP    :", TR_ESP_ANIMAL, &f, 0);
3386         display_flag_aux(row+ 9, col, "オークESP  :", TR_ESP_ORC, &f, 0);
3387         display_flag_aux(row+10, col, "トロルESP  :", TR_ESP_TROLL, &f, 0);
3388         display_flag_aux(row+11, col, "巨人ESP    :", TR_ESP_GIANT, &f, 0);
3389         display_flag_aux(row+12, col, "ユニークESP:", TR_ESP_UNIQUE, &f, 0);
3390         display_flag_aux(row+13, col, "腕力維持   :", TR_SUST_STR, &f, 0);
3391         display_flag_aux(row+14, col, "知力維持   :", TR_SUST_INT, &f, 0);
3392         display_flag_aux(row+15, col, "賢さ維持   :", TR_SUST_WIS, &f, 0);
3393         display_flag_aux(row+16, col, "器用維持   :", TR_SUST_DEX, &f, 0);
3394         display_flag_aux(row+17, col, "耐久維持   :", TR_SUST_CON, &f, 0);
3395         display_flag_aux(row+18, col, "魅力維持   :", TR_SUST_CHR, &f, 0);
3396 #else
3397         display_flag_aux(row+ 0, col, "Telepathy  :", TR_TELEPATHY, &f, 0);
3398         display_flag_aux(row+ 1, col, "ESP Evil   :", TR_ESP_EVIL, &f, 0);
3399         display_flag_aux(row+ 2, col, "ESP Noliv. :", TR_ESP_NONLIVING, &f, 0);
3400         display_flag_aux(row+ 3, col, "ESP Good   :", TR_ESP_GOOD, &f, 0);
3401         display_flag_aux(row+ 4, col, "ESP Undead :", TR_ESP_UNDEAD, &f, 0);
3402         display_flag_aux(row+ 5, col, "ESP Demon  :", TR_ESP_DEMON, &f, 0);
3403         display_flag_aux(row+ 6, col, "ESP Dragon :", TR_ESP_DRAGON, &f, 0);
3404         display_flag_aux(row+ 7, col, "ESP Human  :", TR_ESP_HUMAN, &f, 0);
3405         display_flag_aux(row+ 8, col, "ESP Animal :", TR_ESP_ANIMAL, &f, 0);
3406         display_flag_aux(row+ 9, col, "ESP Orc    :", TR_ESP_ORC, &f, 0);
3407         display_flag_aux(row+10, col, "ESP Troll  :", TR_ESP_TROLL, &f, 0);
3408         display_flag_aux(row+11, col, "ESP Giant  :", TR_ESP_GIANT, &f, 0);
3409         display_flag_aux(row+12, col, "ESP Unique :", TR_ESP_UNIQUE, &f, 0);
3410         display_flag_aux(row+13, col, "Sust Str   :", TR_SUST_STR, &f, 0);
3411         display_flag_aux(row+14, col, "Sust Int   :", TR_SUST_INT, &f, 0);
3412         display_flag_aux(row+15, col, "Sust Wis   :", TR_SUST_WIS, &f, 0);
3413         display_flag_aux(row+16, col, "Sust Dex   :", TR_SUST_DEX, &f, 0);
3414         display_flag_aux(row+17, col, "Sust Con   :", TR_SUST_CON, &f, 0);
3415         display_flag_aux(row+18, col, "Sust Chr   :", TR_SUST_CHR, &f, 0);
3416 #endif
3417
3418
3419         /*** Set 3 ***/
3420
3421         row = 3;
3422         col = col + 12 + 17;
3423
3424         display_player_equippy(row-2, col+14, 0);
3425
3426         c_put_str(TERM_WHITE, "abcdefghijkl@", row-1, col+14);
3427
3428 #ifdef JP
3429         display_flag_aux(row+ 0, col, "追加攻撃    :", TR_BLOWS, &f, 0);
3430         display_flag_aux(row+ 1, col, "採掘        :", TR_TUNNEL, &f, 0);
3431         display_flag_aux(row+ 2, col, "赤外線視力  :", TR_INFRA, &f, 0);
3432         display_flag_aux(row+ 3, col, "魔法道具支配:", TR_MAGIC_MASTERY, &f, 0);
3433         display_flag_aux(row+ 4, col, "隠密        :", TR_STEALTH, &f, 0);
3434         display_flag_aux(row+ 5, col, "探索        :", TR_SEARCH, &f, 0);
3435
3436         display_flag_aux(row+ 7, col, "乗馬        :", TR_RIDING, &f, 0);
3437         display_flag_aux(row+ 8, col, "投擲        :", TR_THROW, &f, 0);
3438         display_flag_aux(row+ 9, col, "祝福        :", TR_BLESSED, &f, 0);
3439         display_flag_aux(row+10, col, "反テレポート:", TR_NO_TELE, &f, 0);
3440         display_flag_aux(row+11, col, "反魔法      :", TR_NO_MAGIC, &f, 0);
3441         display_flag_aux(row+12, col, "消費魔力減少:", TR_DEC_MANA, &f, 0);
3442
3443         display_flag_aux(row+14, col, "経験値減少  :", TR_DRAIN_EXP, &f, 0);
3444         display_flag_aux(row+15, col, "乱テレポート:", TR_TELEPORT, &f, 0);
3445         display_flag_aux(row+16, col, "反感        :", TR_AGGRAVATE, &f, 0);
3446         display_flag_aux(row+17, col, "太古の怨念  :", TR_TY_CURSE, &f, 0);
3447 #else
3448         display_flag_aux(row+ 0, col, "Add Blows   :", TR_BLOWS, &f, 0);
3449         display_flag_aux(row+ 1, col, "Add Tunnel  :", TR_TUNNEL, &f, 0);
3450         display_flag_aux(row+ 2, col, "Add Infra   :", TR_INFRA, &f, 0);
3451         display_flag_aux(row+ 3, col, "Add Device  :", TR_MAGIC_MASTERY, &f, 0);
3452         display_flag_aux(row+ 4, col, "Add Stealth :", TR_STEALTH, &f, 0);
3453         display_flag_aux(row+ 5, col, "Add Search  :", TR_SEARCH, &f, 0);
3454
3455         display_flag_aux(row+ 7, col, "Riding      :", TR_RIDING, &f, 0);
3456         display_flag_aux(row+ 8, col, "Throw       :", TR_THROW, &f, 0);
3457         display_flag_aux(row+ 9, col, "Blessed     :", TR_BLESSED, &f, 0);
3458         display_flag_aux(row+10, col, "No Teleport :", TR_NO_TELE, &f, 0);
3459         display_flag_aux(row+11, col, "Anti Magic  :", TR_NO_MAGIC, &f, 0);
3460         display_flag_aux(row+12, col, "Econom. Mana:", TR_DEC_MANA, &f, 0);
3461
3462         display_flag_aux(row+14, col, "Drain Exp   :", TR_DRAIN_EXP, &f, 0);
3463         display_flag_aux(row+15, col, "Rnd.Teleport:", TR_TELEPORT, &f, 0);
3464         display_flag_aux(row+16, col, "Aggravate   :", TR_AGGRAVATE, &f, 0);
3465         display_flag_aux(row+17, col, "TY Curse    :", TR_TY_CURSE, &f, 0);
3466 #endif
3467
3468 }
3469
3470
3471 /*!
3472  * @brief プレイヤーの特性フラグ一覧表示2a /
3473  * Special display, part 2a
3474  * @return なし
3475  */
3476 static void display_player_misc_info(void)
3477 {
3478         char    buf[80];
3479         char    tmp[80];
3480
3481         /* Display basics */
3482 #ifdef JP
3483 put_str("名前  :", 1, 26);
3484 put_str("性別  :", 3, 1);
3485 put_str("種族  :", 4, 1);
3486 put_str("職業  :", 5, 1);
3487 #else
3488         put_str("Name  :", 1, 26);
3489         put_str("Sex   :", 3, 1);
3490         put_str("Race  :", 4, 1);
3491         put_str("Class :", 5, 1);
3492 #endif
3493
3494         strcpy(tmp,ap_ptr->title);
3495 #ifdef JP
3496         if(ap_ptr->no == 1)
3497                 strcat(tmp,"の");
3498 #else
3499                 strcat(tmp," ");
3500 #endif
3501         strcat(tmp,p_ptr->name);
3502
3503         c_put_str(TERM_L_BLUE, tmp, 1, 34);
3504         c_put_str(TERM_L_BLUE, sp_ptr->title, 3, 9);
3505         c_put_str(TERM_L_BLUE, (p_ptr->mimic_form ? mimic_info[p_ptr->mimic_form].title : rp_ptr->title), 4, 9);
3506         c_put_str(TERM_L_BLUE, cp_ptr->title, 5, 9);
3507
3508         /* Display extras */
3509 #ifdef JP
3510 put_str("レベル:", 6, 1);
3511 put_str("HP  :", 7, 1);
3512 put_str("MP  :", 8, 1);
3513 #else
3514         put_str("Level :", 6, 1);
3515         put_str("Hits  :", 7, 1);
3516         put_str("Mana  :", 8, 1);
3517 #endif
3518
3519
3520         (void)sprintf(buf, "%d", (int)p_ptr->lev);
3521         c_put_str(TERM_L_BLUE, buf, 6, 9);
3522         (void)sprintf(buf, "%d/%d", (int)p_ptr->chp, (int)p_ptr->mhp);
3523         c_put_str(TERM_L_BLUE, buf, 7, 9);
3524         (void)sprintf(buf, "%d/%d", (int)p_ptr->csp, (int)p_ptr->msp);
3525         c_put_str(TERM_L_BLUE, buf, 8, 9);
3526 }
3527
3528
3529 /*!
3530  * @brief プレイヤーの特性フラグ一覧表示2b /
3531  * Special display, part 2b
3532  * @return なし
3533  * @details
3534  * <pre>
3535  * How to print out the modifications and sustains.
3536  * Positive mods with no sustain will be light green.
3537  * Positive mods with a sustain will be dark green.
3538  * Sustains (with no modification) will be a dark green 's'.
3539  * Negative mods (from a curse) will be red.
3540  * Huge mods (>9), like from MICoMorgoth, will be a '*'
3541  * No mod, no sustain, will be a slate '.'
3542  * </pre>
3543  */
3544 static void display_player_stat_info(player_type *creature_ptr)
3545 {
3546         int i, e_adj;
3547         int stat_col, stat;
3548         int row, col;
3549
3550         object_type *o_ptr;
3551         BIT_FLAGS flgs[TR_FLAG_SIZE];
3552
3553         byte a;
3554         char c;
3555
3556         char buf[80];
3557
3558
3559         /* Column */
3560         stat_col = 22;
3561
3562         /* Row */
3563         row = 3;
3564
3565         /* Print out the labels for the columns */
3566         c_put_str(TERM_WHITE, _("能力", "Stat"), row, stat_col+1);
3567         c_put_str(TERM_BLUE, _("  基本", "  Base"), row, stat_col+7);
3568         c_put_str(TERM_L_BLUE, _(" 種 職 性 装 ", "RacClaPerMod"), row, stat_col+13);
3569         c_put_str(TERM_L_GREEN, _("合計", "Actual"), row, stat_col+28);
3570         c_put_str(TERM_YELLOW, _("現在", "Current"), row, stat_col+35);
3571
3572         /* Display the stats */
3573         for (i = 0; i < A_MAX; i++)
3574         {
3575                 int r_adj;
3576
3577                 if (creature_ptr->mimic_form) r_adj = mimic_info[creature_ptr->mimic_form].r_adj[i];
3578                 else r_adj = rp_ptr->r_adj[i];
3579
3580                 /* Calculate equipment adjustment */
3581                 e_adj = 0;
3582
3583                 /* Icky formula to deal with the 18 barrier */
3584                 if ((creature_ptr->stat_max[i] > 18) && (creature_ptr->stat_top[i] > 18))
3585                         e_adj = (creature_ptr->stat_top[i] - creature_ptr->stat_max[i]) / 10;
3586                 if ((creature_ptr->stat_max[i] <= 18) && (creature_ptr->stat_top[i] <= 18))
3587                         e_adj = creature_ptr->stat_top[i] - creature_ptr->stat_max[i];
3588                 if ((creature_ptr->stat_max[i] <= 18) && (creature_ptr->stat_top[i] > 18))
3589                         e_adj = (creature_ptr->stat_top[i] - 18) / 10 - creature_ptr->stat_max[i] + 18;
3590
3591                 if ((creature_ptr->stat_max[i] > 18) && (creature_ptr->stat_top[i] <= 18))
3592                         e_adj = creature_ptr->stat_top[i] - (creature_ptr->stat_max[i] - 19) / 10 - 19;
3593
3594                 if (PRACE_IS_(creature_ptr, RACE_ENT))
3595                 {
3596                         switch (i)
3597                         {
3598                                 case A_STR:
3599                                 case A_CON:
3600                                         if (creature_ptr->lev > 25) r_adj++;
3601                                         if (creature_ptr->lev > 40) r_adj++;
3602                                         if (creature_ptr->lev > 45) r_adj++;
3603                                         break;
3604                                 case A_DEX:
3605                                         if (creature_ptr->lev > 25) r_adj--;
3606                                         if (creature_ptr->lev > 40) r_adj--;
3607                                         if (creature_ptr->lev > 45) r_adj--;
3608                                         break;
3609                         }
3610                 }
3611
3612                 e_adj -= r_adj;
3613                 e_adj -= cp_ptr->c_adj[i];
3614                 e_adj -= ap_ptr->a_adj[i];
3615
3616                 if (creature_ptr->stat_cur[i] < creature_ptr->stat_max[i])
3617                         /* Reduced name of stat */
3618                         c_put_str(TERM_WHITE, stat_names_reduced[i], row + i+1, stat_col+1);
3619                 else
3620                         c_put_str(TERM_WHITE, stat_names[i], row + i+1, stat_col+1);
3621
3622
3623                 /* Internal "natural" max value.  Maxes at 18/100 */
3624                 /* This is useful to see if you are maxed out */
3625                 cnv_stat(creature_ptr->stat_max[i], buf);
3626                 if (creature_ptr->stat_max[i] == creature_ptr->stat_max_max[i])
3627                 {
3628                         c_put_str(TERM_WHITE, "!", row + i+1, _(stat_col + 6, stat_col + 4));
3629                 }
3630                 c_put_str(TERM_BLUE, buf, row + i+1, stat_col + 13 - strlen(buf));
3631
3632                 /* Race, class, and equipment modifiers */
3633                 (void)sprintf(buf, "%3d", r_adj);
3634                 c_put_str(TERM_L_BLUE, buf, row + i+1, stat_col + 13);
3635                 (void)sprintf(buf, "%3d", (int)cp_ptr->c_adj[i]);
3636                 c_put_str(TERM_L_BLUE, buf, row + i+1, stat_col + 16);
3637                 (void)sprintf(buf, "%3d", (int)ap_ptr->a_adj[i]);
3638                 c_put_str(TERM_L_BLUE, buf, row + i+1, stat_col + 19);
3639                 (void)sprintf(buf, "%3d", (int)e_adj);
3640                 c_put_str(TERM_L_BLUE, buf, row + i+1, stat_col + 22);
3641
3642                 /* Actual maximal modified value */
3643                 cnv_stat(creature_ptr->stat_top[i], buf);
3644                 c_put_str(TERM_L_GREEN, buf, row + i+1, stat_col + 26);
3645
3646                 /* Only display stat_use if not maximal */
3647                 if (creature_ptr->stat_use[i] < creature_ptr->stat_top[i])
3648                 {
3649                         cnv_stat(creature_ptr->stat_use[i], buf);
3650                         c_put_str(TERM_YELLOW, buf, row + i+1, stat_col + 33);
3651                 }
3652         }
3653
3654         /* Column */
3655         col = stat_col + 41;
3656
3657         /* Header and Footer */
3658         c_put_str(TERM_WHITE, "abcdefghijkl@", row, col);
3659         c_put_str(TERM_L_GREEN, _("能力修正", "Modification"), row - 1, col);
3660
3661         /* Process equipment */
3662         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
3663         {
3664                 o_ptr = &creature_ptr->inventory_list[i];
3665
3666                 /* Acquire "known" flags */
3667                 object_flags_known(o_ptr, flgs);
3668
3669                 /* Initialize color based of sign of pval. */
3670                 for (stat = 0; stat < A_MAX; stat++)
3671                 {
3672                         /* Default */
3673                         a = TERM_SLATE;
3674                         c = '.';
3675
3676                         /* Boost */
3677                         if (have_flag(flgs, stat))
3678                         {
3679                                 /* Default */
3680                                 c = '*';
3681
3682                                 /* Good */
3683                                 if (o_ptr->pval > 0)
3684                                 {
3685                                         /* Good */
3686                                         a = TERM_L_GREEN;
3687
3688                                         /* Label boost */
3689                                         if (o_ptr->pval < 10) c = '0' + o_ptr->pval;
3690                                 }
3691
3692                                 if (have_flag(flgs, stat + TR_SUST_STR))
3693                                 {
3694                                         /* Dark green for sustained stats */
3695                                         a = TERM_GREEN;
3696                                 }
3697
3698                                 /* Bad */
3699                                 if (o_ptr->pval < 0)
3700                                 {
3701                                         /* Bad */
3702                                         a = TERM_RED;
3703
3704                                         /* Label boost */
3705                                         if (o_ptr->pval > -10) c = '0' - o_ptr->pval;
3706                                 }
3707                         }
3708
3709                         /* Sustain */
3710                         else if (have_flag(flgs, stat + TR_SUST_STR))
3711                         {
3712                                 /* Dark green "s" */
3713                                 a = TERM_GREEN;
3714                                 c = 's';
3715                         }
3716
3717                         /* Dump proper character */
3718                         Term_putch(col, row + stat+1, a, c);
3719                 }
3720
3721                 /* Advance */
3722                 col++;
3723         }
3724
3725         /* Player flags */
3726         player_flags(p_ptr, flgs);
3727
3728         /* Check stats */
3729         for (stat = 0; stat < A_MAX; stat++)
3730         {
3731                 /* Default */
3732                 a = TERM_SLATE;
3733                 c = '.';
3734
3735                 /* Mutations ... */
3736                 if (creature_ptr->muta3 || creature_ptr->tsuyoshi)
3737                 {
3738                         int dummy = 0;
3739
3740                         if (stat == A_STR)
3741                         {
3742                                 if (creature_ptr->muta3 & MUT3_HYPER_STR) dummy += 4;
3743                                 if (creature_ptr->muta3 & MUT3_PUNY) dummy -= 4;
3744                                 if (creature_ptr->tsuyoshi) dummy += 4;
3745                         }
3746                         else if (stat == A_WIS || stat == A_INT)
3747                         {
3748                                 if (creature_ptr->muta3 & MUT3_HYPER_INT) dummy += 4;
3749                                 if (creature_ptr->muta3 & MUT3_MORONIC) dummy -= 4;
3750                         }
3751                         else if (stat == A_DEX)
3752                         {
3753                                 if (creature_ptr->muta3 & MUT3_IRON_SKIN) dummy -= 1;
3754                                 if (creature_ptr->muta3 & MUT3_LIMBER) dummy += 3;
3755                                 if (creature_ptr->muta3 & MUT3_ARTHRITIS) dummy -= 3;
3756                         }
3757                         else if (stat == A_CON)
3758                         {
3759                                 if (creature_ptr->muta3 & MUT3_RESILIENT) dummy += 4;
3760                                 if (creature_ptr->muta3 & MUT3_XTRA_FAT) dummy += 2;
3761                                 if (creature_ptr->muta3 & MUT3_ALBINO) dummy -= 4;
3762                                 if (creature_ptr->muta3 & MUT3_FLESH_ROT) dummy -= 2;
3763                                 if (creature_ptr->tsuyoshi) dummy += 4;
3764                         }
3765                         else if (stat == A_CHR)
3766                         {
3767                                 if (creature_ptr->muta3 & MUT3_SILLY_VOI) dummy -= 4;
3768                                 if (creature_ptr->muta3 & MUT3_BLANK_FAC) dummy -= 1;
3769                                 if (creature_ptr->muta3 & MUT3_FLESH_ROT) dummy -= 1;
3770                                 if (creature_ptr->muta3 & MUT3_SCALES) dummy -= 1;
3771                                 if (creature_ptr->muta3 & MUT3_WART_SKIN) dummy -= 2;
3772                                 if (creature_ptr->muta3 & MUT3_ILL_NORM) dummy = 0;
3773                         }
3774
3775                         /* Boost */
3776                         if (dummy)
3777                         {
3778                                 /* Default */
3779                                 c = '*';
3780
3781                                 /* Good */
3782                                 if (dummy > 0)
3783                                 {
3784                                         /* Good */
3785                                         a = TERM_L_GREEN;
3786
3787                                         /* Label boost */
3788                                         if (dummy < 10) c = '0' + dummy;
3789                                 }
3790
3791                                 /* Bad */
3792                                 if (dummy < 0)
3793                                 {
3794                                         /* Bad */
3795                                         a = TERM_RED;
3796
3797                                         /* Label boost */
3798                                         if (dummy > -10) c = '0' - dummy;
3799                                 }
3800                         }
3801                 }
3802
3803
3804                 /* Sustain */
3805                 if (have_flag(flgs, stat + TR_SUST_STR))
3806                 {
3807                         /* Dark green "s" */
3808                         a = TERM_GREEN;
3809                         c = 's';
3810                 }
3811
3812
3813                 /* Dump */
3814                 Term_putch(col, row + stat+1, a, c);
3815         }
3816 }
3817
3818
3819 /*!
3820  * @brief プレイヤーのステータス表示メイン処理
3821  * Display the character on the screen (various modes)
3822  * @param mode 表示モードID
3823  * @return なし
3824  * @details
3825  * <pre>
3826  * The top one and bottom two lines are left blank.
3827  * Mode 0 = standard display with skills
3828  * Mode 1 = standard display with history
3829  * Mode 2 = summary of various things
3830  * Mode 3 = summary of various things (part 2)
3831  * Mode 4 = mutations
3832  * </pre>
3833  */
3834 void display_player(player_type *creature_ptr, int mode)
3835 {
3836         int i;
3837         char buf[80];
3838         char tmp[64];
3839
3840         if ((creature_ptr->muta1 || creature_ptr->muta2 || creature_ptr->muta3) && display_mutations)
3841                 mode = (mode % 5);
3842         else
3843                 mode = (mode % 4);
3844
3845         /* Erase screen */
3846         clear_from(0);
3847
3848         /* Standard */
3849         if ((mode == 0) || (mode == 1))
3850         {
3851                 /* Name, Sex, Race, Class */
3852 #ifdef JP
3853                 sprintf(tmp, "%s%s%s", ap_ptr->title, ap_ptr->no == 1 ? "の":"", creature_ptr->name);
3854 #else
3855                 sprintf(tmp, "%s %s", ap_ptr->title, creature_ptr->name);
3856 #endif
3857
3858                 display_player_one_line(ENTRY_NAME, tmp, TERM_L_BLUE);
3859                 display_player_one_line(ENTRY_SEX, sp_ptr->title, TERM_L_BLUE);
3860                 display_player_one_line(ENTRY_RACE, (creature_ptr->mimic_form ? mimic_info[creature_ptr->mimic_form].title : rp_ptr->title), TERM_L_BLUE);
3861                 display_player_one_line(ENTRY_CLASS, cp_ptr->title, TERM_L_BLUE);
3862
3863                 if (creature_ptr->realm1)
3864                 {
3865                         if (creature_ptr->realm2)
3866                                 sprintf(tmp, "%s, %s", realm_names[creature_ptr->realm1], realm_names[creature_ptr->realm2]);
3867                         else
3868                                 strcpy(tmp, realm_names[creature_ptr->realm1]);
3869                         display_player_one_line(ENTRY_REALM, tmp, TERM_L_BLUE);
3870                 }
3871
3872                 if ((creature_ptr->pclass == CLASS_CHAOS_WARRIOR) || (creature_ptr->muta2 & MUT2_CHAOS_GIFT))
3873                         display_player_one_line(ENTRY_PATRON, chaos_patrons[creature_ptr->chaos_patron], TERM_L_BLUE);
3874
3875                 /* Age, Height, Weight, Social */
3876                 /* 身長はセンチメートルに、体重はキログラムに変更してあります */
3877 #ifdef JP
3878                 display_player_one_line(ENTRY_AGE, format("%d才" ,(int)creature_ptr->age), TERM_L_BLUE);
3879                 display_player_one_line(ENTRY_HEIGHT, format("%dcm" ,(int)((creature_ptr->ht*254)/100)), TERM_L_BLUE);
3880                 display_player_one_line(ENTRY_WEIGHT, format("%dkg" ,(int)((creature_ptr->wt*4536)/10000)), TERM_L_BLUE);
3881                 display_player_one_line(ENTRY_SOCIAL, format("%d  " ,(int)creature_ptr->sc), TERM_L_BLUE);
3882 #else
3883                 display_player_one_line(ENTRY_AGE, format("%d" ,(int)creature_ptr->age), TERM_L_BLUE);
3884                 display_player_one_line(ENTRY_HEIGHT, format("%d" ,(int)creature_ptr->ht), TERM_L_BLUE);
3885                 display_player_one_line(ENTRY_WEIGHT, format("%d" ,(int)creature_ptr->wt), TERM_L_BLUE);
3886                 display_player_one_line(ENTRY_SOCIAL, format("%d" ,(int)creature_ptr->sc), TERM_L_BLUE);
3887 #endif
3888                 display_player_one_line(ENTRY_ALIGN, format("%s" ,your_alignment(creature_ptr)), TERM_L_BLUE);
3889
3890
3891                 /* Display the stats */
3892                 for (i = 0; i < A_MAX; i++)
3893                 {
3894                         /* Special treatment of "injured" stats */
3895                         if (creature_ptr->stat_cur[i] < creature_ptr->stat_max[i])
3896                         {
3897                                 int value;
3898
3899                                 /* Use lowercase stat name */
3900                                 put_str(stat_names_reduced[i], 3 + i, 53);
3901
3902                                 /* Get the current stat */
3903                                 value = creature_ptr->stat_use[i];
3904
3905                                 /* Obtain the current stat (modified) */
3906                                 cnv_stat(value, buf);
3907
3908                                 /* Display the current stat (modified) */
3909                                 c_put_str(TERM_YELLOW, buf, 3 + i, 60);
3910
3911                                 /* Acquire the max stat */
3912                                 value = creature_ptr->stat_top[i];
3913
3914                                 /* Obtain the maximum stat (modified) */
3915                                 cnv_stat(value, buf);
3916
3917                                 /* Display the maximum stat (modified) */
3918                                 c_put_str(TERM_L_GREEN, buf, 3 + i, 67);
3919                         }
3920
3921                         /* Normal treatment of "normal" stats */
3922                         else
3923                         {
3924                                 /* Assume uppercase stat name */
3925                                 put_str(stat_names[i], 3 + i, 53);
3926
3927                                 /* Obtain the current stat (modified) */
3928                                 cnv_stat(creature_ptr->stat_use[i], buf);
3929
3930                                 /* Display the current stat (modified) */
3931                                 c_put_str(TERM_L_GREEN, buf, 3 + i, 60);
3932                         }
3933
3934                         if (creature_ptr->stat_max[i] == creature_ptr->stat_max_max[i])
3935                         {
3936                                 c_put_str(TERM_WHITE, "!", 3 + i, _(58, 58-2));
3937                         }
3938                 }
3939
3940                 /* Display "history" info */
3941                 if (mode == 1)
3942                 {
3943                         char statmsg[1000];
3944                         put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
3945
3946                         for (i = 0; i < 4; i++)
3947                         {
3948                                 put_str(creature_ptr->history[i], i + 12, 10);
3949                         }
3950
3951                         *statmsg = '\0';
3952
3953                         if (creature_ptr->is_dead)
3954                         {
3955                                 if (creature_ptr->total_winner)
3956                                 {
3957 #ifdef JP
3958                                         sprintf(statmsg, "…あなたは勝利の後%sした。", streq(creature_ptr->died_from, "Seppuku") ? "切腹" : "引退");
3959 #else
3960                                         sprintf(statmsg, "...You %s after the winning.", streq(creature_ptr->died_from, "Seppuku") ? "did Seppuku" : "retired from the adventure");
3961 #endif
3962                                 }
3963                                 else if (!p_ptr->current_floor_ptr->dun_level)
3964                                 {
3965 #ifdef JP
3966                                         sprintf(statmsg, "…あなたは%sで%sに殺された。", map_name(), creature_ptr->died_from);
3967 #else
3968                                         sprintf(statmsg, "...You were killed by %s in %s.", creature_ptr->died_from, map_name());
3969 #endif
3970                                 }
3971                                 else if (creature_ptr->current_floor_ptr->inside_quest && is_fixed_quest_idx(creature_ptr->current_floor_ptr->inside_quest))
3972                                 {
3973                                         /* Get the quest text */
3974                                         /* Bewere that INIT_ASSIGN resets the cur_num. */
3975                                         init_flags = INIT_NAME_ONLY;
3976
3977                                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
3978
3979 #ifdef JP
3980                                         sprintf(statmsg, "…あなたは、クエスト「%s」で%sに殺された。", quest[creature_ptr->current_floor_ptr->inside_quest].name, creature_ptr->died_from);
3981 #else
3982                                         sprintf(statmsg, "...You were killed by %s in the quest '%s'.", creature_ptr->died_from, quest[creature_ptr->current_floor_ptr->inside_quest].name);
3983 #endif
3984                                 }
3985                                 else
3986                                 {
3987 #ifdef JP
3988                                         sprintf(statmsg, "…あなたは、%sの%d階で%sに殺された。", map_name(), (int)p_ptr->current_floor_ptr->dun_level, creature_ptr->died_from);
3989 #else
3990                                         sprintf(statmsg, "...You were killed by %s on level %d of %s.", creature_ptr->died_from, p_ptr->current_floor_ptr->dun_level, map_name());
3991 #endif
3992                                 }
3993                         }
3994                         else if (current_world_ptr->character_dungeon)
3995                         {
3996                                 if (!p_ptr->current_floor_ptr->dun_level)
3997                                 {
3998                                         sprintf(statmsg, _("…あなたは現在、 %s にいる。", "...Now, you are in %s."), map_name());
3999                                 }
4000                                 else if (creature_ptr->current_floor_ptr->inside_quest && is_fixed_quest_idx(creature_ptr->current_floor_ptr->inside_quest))
4001                                 {
4002                                         /* Clear the text */
4003                                         /* Must be done before doing INIT_SHOW_TEXT */
4004                                         for (i = 0; i < 10; i++)
4005                                         {
4006                                                 quest_text[i][0] = '\0';
4007                                         }
4008                                         quest_text_line = 0;
4009
4010                                         /* Get the quest text */
4011                                         init_flags = INIT_NAME_ONLY;
4012
4013                                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
4014
4015                                         sprintf(statmsg, _("…あなたは現在、 クエスト「%s」を遂行中だ。", "...Now, you are in the quest '%s'."), quest[creature_ptr->current_floor_ptr->inside_quest].name);
4016                                 }
4017                                 else
4018                                 {
4019 #ifdef JP
4020                                         sprintf(statmsg, "…あなたは現在、 %s の %d 階で探索している。", map_name(), (int)p_ptr->current_floor_ptr->dun_level);
4021 #else
4022                                         sprintf(statmsg, "...Now, you are exploring level %d of %s.", p_ptr->current_floor_ptr->dun_level, map_name());
4023 #endif
4024                                 }
4025                         }
4026
4027                         if (*statmsg)
4028                         {
4029                                 char temp[64*2], *t;
4030                                 roff_to_buf(statmsg, 60, temp, sizeof(temp));
4031                                 t = temp;
4032                                 for(i=0 ; i<2 ; i++)
4033                                 {
4034                                         if(t[0]==0)
4035                                                 break; 
4036                                         else
4037                                         {
4038                                                 put_str(t, i + 5 + 12, 10);
4039                                                 t += strlen(t)+1;
4040                                         }
4041                                 }
4042                         }
4043
4044                 }
4045
4046                 /* Display "various" info */
4047                 else
4048                 {
4049                         display_player_middle(creature_ptr);
4050                         display_player_various(creature_ptr);
4051                 }
4052         }
4053
4054         /* Special */
4055         else if (mode == 2)
4056         {
4057                 /* See "http://www.cs.berkeley.edu/~davidb/angband.html" */
4058
4059                 /* Dump the info */
4060                 display_player_misc_info();
4061                 display_player_stat_info(creature_ptr);
4062                 display_player_flag_info();
4063         }
4064
4065         /* Special */
4066         else if (mode == 3)
4067         {
4068                 display_player_other_flag_info();
4069         }
4070
4071         else if (mode == 4)
4072         {
4073                 do_cmd_knowledge_mutations(creature_ptr);
4074         }
4075 }
4076
4077 /*!
4078  * @brief プレイヤーのステータス表示をファイルにダンプする
4079  * @param fff ファイルポインタ
4080  * @return なし
4081  */
4082 static void dump_aux_display_player(FILE *fff)
4083 {
4084         TERM_LEN x, y;
4085         TERM_COLOR a;
4086         char c;
4087         char buf[1024];
4088
4089         display_player(p_ptr, 0);
4090
4091         /* Dump part of the screen */
4092         for (y = 1; y < 22; y++)
4093         {
4094                 /* Dump each row */
4095                 for (x = 0; x < 79; x++)
4096                 {
4097                         /* Get the attr/char */
4098                         (void)(Term_what(x, y, &a, &c));
4099
4100                         /* Dump it */
4101                         buf[x] = c;
4102                 }
4103
4104                 /* End the string */
4105                 buf[x] = '\0';
4106
4107                 /* Kill trailing spaces */
4108                 while ((x > 0) && (buf[x-1] == ' ')) buf[--x] = '\0';
4109
4110                 /* End the row */
4111                 fprintf(fff, _("%s\n", "%s\n"), buf);
4112         }
4113
4114         /* Display history */
4115         display_player(p_ptr, 1);
4116
4117         /* Dump part of the screen */
4118         for (y = 10; y < 19; y++)
4119         {
4120                 /* Dump each row */
4121                 for (x = 0; x < 79; x++)
4122                 {
4123                         /* Get the attr/char */
4124                         (void)(Term_what(x, y, &a, &c));
4125
4126                         /* Dump it */
4127                         buf[x] = c;
4128                 }
4129
4130                 /* End the string */
4131                 buf[x] = '\0';
4132
4133                 /* Kill trailing spaces */
4134                 while ((x > 0) && (buf[x-1] == ' ')) buf[--x] = '\0';
4135
4136                 /* End the row */
4137                 fprintf(fff, "%s\n", buf);
4138         }
4139
4140         fprintf(fff, "\n");
4141
4142         /* Display flags (part 1) */
4143         display_player(p_ptr, 2);
4144
4145         /* Dump part of the screen */
4146         for (y = 2; y < 22; y++)
4147         {
4148                 /* Dump each row */
4149                 for (x = 0; x < 79; x++)
4150                 {
4151                         /* Get the attr/char */
4152                         (void)(Term_what(x, y, &a, &c));
4153
4154                         /* Dump it (Ignore equippy tile graphic) */
4155                         if (a < 128)
4156                                 buf[x] = c;
4157                         else
4158                                 buf[x] = ' ';
4159                 }
4160
4161                 /* End the string */
4162                 buf[x] = '\0';
4163
4164                 /* Kill trailing spaces */
4165                 while ((x > 0) && (buf[x-1] == ' ')) buf[--x] = '\0';
4166
4167                 /* End the row */
4168                 fprintf(fff, "%s\n", buf);
4169         }
4170
4171         fprintf(fff, "\n");
4172
4173         /* Display flags (part 2) */
4174         display_player(p_ptr, 3);
4175
4176         /* Dump part of the screen */
4177         for (y = 1; y < 22; y++)
4178         {
4179                 /* Dump each row */
4180                 for (x = 0; x < 79; x++)
4181                 {
4182                         /* Get the attr/char */
4183                         (void)(Term_what(x, y, &a, &c));
4184
4185                         /* Dump it (Ignore equippy tile graphic) */
4186                         if (a < 128)
4187                                 buf[x] = c;
4188                         else
4189                                 buf[x] = ' ';
4190                 }
4191
4192                 /* End the string */
4193                 buf[x] = '\0';
4194
4195                 /* Kill trailing spaces */
4196                 while ((x > 0) && (buf[x-1] == ' ')) buf[--x] = '\0';
4197
4198                 /* End the row */
4199                 fprintf(fff, "%s\n", buf);
4200         }
4201
4202         fprintf(fff, "\n");
4203 }
4204
4205
4206 /*!
4207  * @brief プレイヤーのペット情報をファイルにダンプする
4208  * @param fff ファイルポインタ
4209  * @return なし
4210  */
4211 static void dump_aux_pet(player_type *master_ptr, FILE *fff)
4212 {
4213         int i;
4214         bool pet = FALSE;
4215         bool pet_settings = FALSE;
4216         GAME_TEXT pet_name[MAX_NLEN];
4217
4218         for (i = master_ptr->current_floor_ptr->m_max - 1; i >= 1; i--)
4219         {
4220                 monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[i];
4221
4222                 if (!monster_is_valid(m_ptr)) continue;
4223                 if (!is_pet(m_ptr)) continue;
4224                 pet_settings = TRUE;
4225                 if (!m_ptr->nickname && (master_ptr->riding != i)) continue;
4226                 if (!pet)
4227                 {
4228                         fprintf(fff, _("\n\n  [主なペット]\n\n", "\n\n  [Leading Pets]\n\n"));
4229                         pet = TRUE;
4230                 }
4231                 monster_desc(pet_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
4232                 fprintf(fff, "%s\n", pet_name);
4233         }
4234
4235         if (pet_settings)
4236         {
4237                 fprintf(fff, _("\n\n  [ペットへの命令]\n", "\n\n  [Command for Pets]\n"));
4238
4239                 fprintf(fff, _("\n ドアを開ける:                       %s", "\n Pets open doors:                    %s"), 
4240                                         (master_ptr->pet_extra_flags & PF_OPEN_DOORS) ? "ON" : "OFF");
4241
4242                 fprintf(fff, _("\n アイテムを拾う:                     %s", "\n Pets pick up items:                 %s"),
4243                                         (master_ptr->pet_extra_flags & PF_PICKUP_ITEMS) ? "ON" : "OFF");
4244
4245                 fprintf(fff, _("\n テレポート系魔法を使う:             %s", "\n Allow teleport:                     %s"),
4246                                         (master_ptr->pet_extra_flags & PF_TELEPORT) ? "ON" : "OFF");
4247
4248                 fprintf(fff, _("\n 攻撃魔法を使う:                     %s", "\n Allow cast attack spell:            %s"),
4249                                         (master_ptr->pet_extra_flags & PF_ATTACK_SPELL) ? "ON" : "OFF");
4250
4251                 fprintf(fff, _("\n 召喚魔法を使う:                     %s", "\n Allow cast summon spell:            %s"),
4252                                         (master_ptr->pet_extra_flags & PF_SUMMON_SPELL) ? "ON" : "OFF");
4253
4254                 fprintf(fff, _("\n プレイヤーを巻き込む範囲魔法を使う: %s", "\n Allow involve player in area spell: %s"),
4255                                         (master_ptr->pet_extra_flags & PF_BALL_SPELL) ? "ON" : "OFF");
4256
4257                 fputc('\n', fff);
4258         }
4259 }
4260
4261
4262 /*!
4263  * @brief プレイヤーの職業能力情報をファイルにダンプする
4264  * @param fff ファイルポインタ
4265  * @return なし
4266  */
4267 static void dump_aux_class_special(FILE *fff)
4268 {
4269         if (p_ptr->pclass == CLASS_BLUE_MAGE)
4270         {
4271                 int i = 0;
4272                 int j = 0;
4273                 int l1 = 0;
4274                 int l2 = 0;
4275                 int num = 0;
4276                 int spellnum[MAX_MONSPELLS];
4277                 BIT_FLAGS f4 = 0, f5 = 0, f6 = 0;
4278                 char p[60][80];
4279                 int col = 0;
4280                 bool pcol = FALSE;
4281
4282                 for (i=0;i<60;i++) { p[i][0] = '\0'; }
4283
4284                 strcat(p[col], _("\n\n  [学習済みの青魔法]\n", "\n\n  [Learned Blue Magic]\n"));
4285
4286                 for (j=1;j<6;j++)
4287                 {
4288                         col++;
4289                         set_rf_masks(&f4, &f5, &f6, j);
4290                         switch(j)
4291                         {
4292                                 case MONSPELL_TYPE_BOLT:
4293                                         strcat(p[col], _("\n     [ボルト型]\n", "\n     [Bolt  Type]\n"));
4294                                         break;
4295
4296                                 case MONSPELL_TYPE_BALL:
4297                                         strcat(p[col], _("\n     [ボール型]\n", "\n     [Ball  Type]\n"));
4298                                         break;
4299
4300                                 case MONSPELL_TYPE_BREATH:
4301                                         strcat(p[col], _("\n     [ブレス型]\n", "\n     [  Breath  ]\n"));
4302                                         break;
4303
4304                                 case MONSPELL_TYPE_SUMMON:
4305                                         strcat(p[col], _("\n     [召喚魔法]\n", "\n     [Summonning]\n"));
4306                                         break;
4307
4308                                 case MONSPELL_TYPE_OTHER:
4309                                         strcat(p[col], _("\n     [ その他 ]\n", "\n     [Other Type]\n"));
4310                                         break;
4311                         }
4312
4313                         for (i = 0, num = 0; i < 32; i++)
4314                         {
4315                                 if ((0x00000001 << i) & f4) spellnum[num++] = i;
4316                         }
4317                         for (; i < 64; i++)
4318                         {
4319                                 if ((0x00000001 << (i - 32)) & f5) spellnum[num++] = i;
4320                         }
4321                         for (; i < 96; i++)
4322                         {
4323                                 if ((0x00000001 << (i - 64)) & f6) spellnum[num++] = i;
4324                         }
4325
4326                         col++;
4327                         pcol = FALSE;
4328                         strcat(p[col], "       ");
4329
4330                         for (i = 0; i < num; i++)
4331                         {
4332                                 if (p_ptr->magic_num2[spellnum[i]])
4333                                 {
4334                                         pcol = TRUE;
4335                                         /* Dump blue magic */
4336                                         l1 = strlen(p[col]);
4337                                         l2 = strlen(monster_powers_short[spellnum[i]]);
4338                                         if ((l1 + l2) >= 75)
4339                                         {
4340                                                 strcat(p[col], "\n");
4341                                                 col++;
4342                                                 strcat(p[col], "       ");
4343                                         }
4344                                         strcat(p[col], monster_powers_short[spellnum[i]]);
4345                                         strcat(p[col], ", ");
4346                                 }
4347                         }
4348                         
4349                         if (!pcol)
4350                         {
4351                                 strcat(p[col], _("なし", "None"));
4352                         }
4353                         else
4354                         {
4355                                 if (p[col][strlen(p[col])-2] == ',')
4356                                 {
4357                                         p[col][strlen(p[col])-2] = '\0';
4358                                 }
4359                                 else
4360                                 {
4361                                         p[col][strlen(p[col])-10] = '\0';
4362                                 }
4363                         }
4364                         
4365                         strcat(p[col], "\n");
4366                 }
4367
4368                 for (i=0;i<=col;i++)
4369                 {
4370                         fputs(p[i], fff);
4371                 }
4372         }
4373         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4374         {
4375                 char s[EATER_EXT][MAX_NLEN];
4376                 OBJECT_TYPE_VALUE tval = 0;
4377                 int ext;
4378                 KIND_OBJECT_IDX k_idx;
4379                 OBJECT_SUBTYPE_VALUE i;
4380                 int magic_num;
4381
4382                 fprintf(fff, _("\n\n  [取り込んだ魔法道具]\n", "\n\n  [Magic devices eaten]\n"));
4383
4384                 for (ext = 0; ext < 3; ext++)
4385                 {
4386                         int eat_num = 0;
4387
4388                         /* Dump an extent name */
4389                         switch (ext)
4390                         {
4391                         case 0:
4392                                 tval = TV_STAFF;
4393                                 fprintf(fff, _("\n[杖]\n", "\n[Staffs]\n"));
4394                                 break;
4395                         case 1:
4396                                 tval = TV_WAND;
4397                                 fprintf(fff, _("\n[魔法棒]\n", "\n[Wands]\n"));
4398                                 break;
4399                         case 2:
4400                                 tval = TV_ROD;
4401                                 fprintf(fff, _("\n[ロッド]\n", "\n[Rods]\n"));
4402                                 break;
4403                         }
4404
4405                         /* Get magic device names that were eaten */
4406                         for (i = 0; i < EATER_EXT; i++)
4407                         {
4408                                 int idx = EATER_EXT * ext + i;
4409
4410                                 magic_num = p_ptr->magic_num2[idx];
4411                                 if (!magic_num) continue;
4412
4413                                 k_idx = lookup_kind(tval, i);
4414                                 if (!k_idx) continue;
4415                                 sprintf(s[eat_num], "%23s (%2d)", (k_name + k_info[k_idx].name), magic_num);
4416                                 eat_num++;
4417                         }
4418
4419                         /* Dump magic devices in this extent */
4420                         if (eat_num > 0)
4421                         {
4422                                 for (i = 0; i < eat_num; i++)
4423                                 {
4424                                         fputs(s[i], fff);
4425                                         if (i % 3 < 2) fputs("    ", fff);
4426                                         else fputs("\n", fff);
4427                                 }
4428
4429                                 if (i % 3 > 0) fputs("\n", fff);
4430                         }
4431                         else /* Not found */
4432                         {
4433                                 fputs(_("  (なし)\n", "  (none)\n"), fff);
4434                         }
4435                 }
4436         }
4437         else if (p_ptr->pclass == CLASS_SMITH)
4438         {
4439                 int i, id[250], n = 0, row;
4440
4441                 fprintf(fff, _("\n\n  [手に入れたエッセンス]\n\n", "\n\n  [Get Essence]\n\n"));
4442                 fprintf(fff, _("エッセンス   個数     エッセンス   個数     エッセンス   個数", 
4443                                            "Essence      Num      Essence      Num      Essence      Num "));
4444                 for (i = 0; essence_name[i]; i++)
4445                 {
4446                         if (!essence_name[i][0]) continue;
4447                         id[n] = i;
4448                         n++;
4449                 }
4450
4451                 row = n / 3 + 1;
4452
4453                 for (i = 0; i < row; i++)
4454                 {
4455                         fprintf(fff, "\n");
4456                         fprintf(fff, "%-11s %5d     ", essence_name[id[i]], (int)p_ptr->magic_num1[id[i]]);
4457                         if(i + row < n) fprintf(fff, "%-11s %5d     ", essence_name[id[i + row]], (int)p_ptr->magic_num1[id[i + row]]);
4458                         if(i + row * 2 < n) fprintf(fff, "%-11s %5d", essence_name[id[i + row * 2]], (int)p_ptr->magic_num1[id[i + row * 2]]);
4459                 }
4460
4461                 fputs("\n", fff);
4462
4463         }
4464 }
4465
4466
4467 /*!
4468  * @brief クエスト情報をファイルにダンプする
4469  * @param fff ファイルポインタ
4470  * @return なし
4471  */
4472 static void dump_aux_quest(FILE *fff)
4473 {
4474         QUEST_IDX i;
4475         QUEST_IDX *quest_num;
4476         int dummy;
4477
4478         fprintf(fff, _("\n\n  [クエスト情報]\n", "\n\n  [Quest Information]\n"));
4479
4480         /* Allocate Memory */
4481         C_MAKE(quest_num, max_q_idx, QUEST_IDX);
4482
4483         /* Sort by compete level */
4484         for (i = 1; i < max_q_idx; i++) quest_num[i] = i;
4485         ang_sort(quest_num, &dummy, max_q_idx, ang_sort_comp_quest_num, ang_sort_swap_quest_num);
4486
4487         /* Dump Quest Information */
4488         fputc('\n', fff);
4489         do_cmd_knowledge_quests_completed(fff, quest_num);
4490         fputc('\n', fff);
4491         do_cmd_knowledge_quests_failed(fff, quest_num);
4492         fputc('\n', fff);
4493
4494         /* Free Memory */
4495         C_KILL(quest_num, max_q_idx, QUEST_IDX);
4496 }
4497
4498
4499 /*!
4500  * @brief 死の直前メッセージ並びに遺言をファイルにダンプする
4501  * @param fff ファイルポインタ
4502  * @return なし
4503  */
4504 static void dump_aux_last_message(FILE *fff)
4505 {
4506         if (p_ptr->is_dead)
4507         {
4508                 if (!p_ptr->total_winner)
4509                 {
4510                         int i;
4511
4512                         fprintf(fff, _("\n  [死ぬ直前のメッセージ]\n\n", "\n  [Last Messages]\n\n"));
4513                         for (i = MIN(message_num(), 30); i >= 0; i--)
4514                         {
4515                                 fprintf(fff,"> %s\n",message_str((s16b)i));
4516                         }
4517                         fputc('\n', fff);
4518                 }
4519
4520                 /* Hack -- *Winning* message */
4521                 else if (p_ptr->last_message)
4522                 {
4523                         fprintf(fff, _("\n  [*勝利*メッセージ]\n\n", "\n  [*Winning* Message]\n\n"));
4524                         fprintf(fff,"  %s\n", p_ptr->last_message);
4525                         fputc('\n', fff);
4526                 }
4527         }
4528 }
4529
4530 /*!
4531  * @brief 帰還場所情報をファイルにダンプする
4532  * @param fff ファイルポインタ
4533  * @return なし
4534  */
4535 static void dump_aux_recall(FILE *fff)
4536 {
4537         int y;
4538         fprintf(fff, _("\n  [帰還場所]\n\n", "\n  [Recall Depth]\n\n"));
4539
4540         for (y = 1; y < current_world_ptr->max_d_idx; y++)
4541         {
4542                 bool seiha = FALSE;
4543
4544                 if (!d_info[y].maxdepth) continue;
4545                 if (!max_dlv[y]) continue;
4546                 if (d_info[y].final_guardian)
4547                 {
4548                         if (!r_info[d_info[y].final_guardian].max_num) seiha = TRUE;
4549                 }
4550                 else if (max_dlv[y] == d_info[y].maxdepth) seiha = TRUE;
4551
4552                 fprintf(fff, _("   %c%-12s: %3d 階\n", "   %c%-16s: level %3d\n"),
4553                         seiha ? '!' : ' ', d_name+d_info[y].name, (int)max_dlv[y]);
4554         }
4555 }
4556
4557
4558 /*!
4559  * @brief オプション情報をファイルにダンプする
4560  * @param fff ファイルポインタ
4561  * @return なし
4562  */
4563 static void dump_aux_options(FILE *fff)
4564 {
4565         fprintf(fff, _("\n  [オプション設定]\n", "\n  [Option Settings]\n"));
4566
4567         if (preserve_mode)
4568                 fprintf(fff, _("\n 保存モード:         ON", "\n Preserve Mode:      ON"));
4569
4570         else
4571                 fprintf(fff, _("\n 保存モード:         OFF", "\n Preserve Mode:      OFF"));
4572
4573         if (ironman_small_levels)
4574                 fprintf(fff, _("\n 小さいダンジョン:   ALWAYS", "\n Small Levels:       ALWAYS"));
4575         else if (always_small_levels)
4576                 fprintf(fff, _("\n 小さいダンジョン:   ON", "\n Small Levels:       ON"));
4577         else if (small_levels)
4578                 fprintf(fff, _("\n 小さいダンジョン:   ENABLED", "\n Small Levels:       ENABLED"));
4579         else
4580                 fprintf(fff, _("\n 小さいダンジョン:   OFF", "\n Small Levels:       OFF"));
4581
4582
4583         if (vanilla_town)
4584                 fprintf(fff, _("\n 元祖の町のみ:       ON", "\n Vanilla Town:       ON"));
4585         else if (lite_town)
4586                 fprintf(fff, _("\n 小規模な町:         ON", "\n Lite Town:          ON"));
4587
4588
4589         if (ironman_shops)
4590                 fprintf(fff, _("\n 店なし:             ON", "\n No Shops:           ON"));
4591
4592         if (ironman_downward)
4593                 fprintf(fff, _("\n 階段を上がれない:   ON", "\n Diving Only:        ON"));
4594
4595         if (ironman_rooms)
4596                 fprintf(fff, _("\n 普通でない部屋:     ON", "\n Unusual Rooms:      ON"));
4597
4598         if (ironman_nightmare)
4599                 fprintf(fff, _("\n 悪夢モード:         ON", "\n Nightmare Mode:     ON"));
4600
4601
4602         if (ironman_empty_levels)
4603                 fprintf(fff, _("\n アリーナ:           ALWAYS", "\n Arena Levels:       ALWAYS"));
4604         else if (empty_levels)
4605                 fprintf(fff, _("\n アリーナ:           ENABLED", "\n Arena Levels:       ENABLED"));
4606         else
4607                 fprintf(fff, _("\n アリーナ:           OFF", "\n Arena Levels:       OFF"));
4608
4609         fputc('\n', fff);
4610
4611         if (current_world_ptr->noscore)
4612                 fprintf(fff, _("\n 何か不正なことをしてしまっています。\n", "\n You have done something illegal.\n"));
4613
4614         fputc('\n', fff);
4615 }
4616
4617
4618 /*!
4619  * @brief 闘技場の情報をファイルにダンプする
4620  * @param fff ファイルポインタ
4621  * @return なし
4622  */
4623 static void dump_aux_arena(FILE *fff)
4624 {
4625         if (lite_town || vanilla_town) return;
4626
4627         if (p_ptr->arena_number < 0)
4628         {
4629                 if (p_ptr->arena_number <= ARENA_DEFEATED_OLD_VER)
4630                 {
4631                         fprintf(fff, _("\n 闘技場: 敗北\n", "\n Arena: Defeated\n"));
4632                 }
4633                 else
4634                 {
4635 #ifdef JP
4636                         fprintf(fff, "\n 闘技場: %d回戦で%sの前に敗北\n", -p_ptr->arena_number,
4637                                 r_name + r_info[arena_info[-1 - p_ptr->arena_number].r_idx].name);
4638 #else
4639                         fprintf(fff, "\n Arena: Defeated by %s in the %d%s fight\n",
4640                                 r_name + r_info[arena_info[-1 - p_ptr->arena_number].r_idx].name,
4641                                 -p_ptr->arena_number, get_ordinal_number_suffix(-p_ptr->arena_number));
4642 #endif
4643                 }
4644         }
4645         else if (p_ptr->arena_number > MAX_ARENA_MONS + 2)
4646         {
4647                 fprintf(fff, _("\n 闘技場: 真のチャンピオン\n", "\n Arena: True Champion\n"));
4648         }
4649         else if (p_ptr->arena_number > MAX_ARENA_MONS - 1)
4650         {
4651                 fprintf(fff, _("\n 闘技場: チャンピオン\n", "\n Arena: Champion\n"));
4652         }
4653         else
4654         {
4655 #ifdef JP
4656                 fprintf(fff, "\n 闘技場: %2d勝\n", (p_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : p_ptr->arena_number));
4657 #else
4658                 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");
4659 #endif
4660         }
4661
4662         fprintf(fff, "\n");
4663 }
4664
4665
4666 /*!
4667  * @brief 撃破モンスターの情報をファイルにダンプする
4668  * @param fff ファイルポインタ
4669  * @return なし
4670  */
4671 static void dump_aux_monsters(FILE *fff)
4672 {
4673         /* Monsters slain */
4674
4675         IDX k;
4676         long uniq_total = 0;
4677         long norm_total = 0;
4678         MONRACE_IDX *who;
4679
4680         /* Sort by monster level */
4681         u16b why = 2;
4682
4683         fprintf(fff, _("\n  [倒したモンスター]\n\n", "\n  [Defeated Monsters]\n\n"));
4684
4685         /* Allocate the "who" array */
4686         C_MAKE(who, max_r_idx, MONRACE_IDX);
4687
4688         /* Count monster kills */
4689         for (k = 1; k < max_r_idx; k++)
4690         {
4691                 monster_race *r_ptr = &r_info[k];
4692
4693                 /* Ignore unused index */
4694                 if (!r_ptr->name) continue;
4695
4696                 if (r_ptr->flags1 & RF1_UNIQUE)
4697                 {
4698                         bool dead = (r_ptr->max_num == 0);
4699                         if (dead)
4700                         {
4701                                 norm_total++;
4702
4703                                 /* Add a unique monster to the list */
4704                                 who[uniq_total++] = k;
4705                         }
4706                 }
4707                 else
4708                 {
4709                         if (r_ptr->r_pkills > 0)
4710                         {
4711                                 norm_total += r_ptr->r_pkills;
4712                         }
4713                 }
4714         }
4715
4716
4717         /* No monsters is defeated */
4718         if (norm_total < 1)
4719         {
4720                 fprintf(fff,_("まだ敵を倒していません。\n", "You have defeated no enemies yet.\n"));
4721         }
4722
4723         /* Defeated more than one normal monsters */
4724         else if (uniq_total == 0)
4725         {
4726 #ifdef JP
4727                 fprintf(fff,"%ld体の敵を倒しています。\n", norm_total);
4728 #else
4729                 fprintf(fff,"You have defeated %ld %s.\n", norm_total, norm_total == 1 ? "enemy" : "enemies");
4730 #endif
4731         }
4732
4733         /* Defeated more than one unique monsters */
4734         else /* if (uniq_total > 0) */
4735         {
4736 #ifdef JP
4737                 fprintf(fff, "%ld体のユニーク・モンスターを含む、合計%ld体の敵を倒しています。\n", uniq_total, norm_total); 
4738 #else
4739                 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"));
4740 #endif
4741
4742                 /* Sort the array by dungeon depth of monsters */
4743                 ang_sort(who, &why, uniq_total, ang_sort_comp_hook, ang_sort_swap_hook);
4744                 fprintf(fff, _("\n《上位%ld体のユニーク・モンスター》\n", "\n< Unique monsters top %ld >\n"), MIN(uniq_total, 10));
4745
4746                 /* Print top 10 */
4747                 for (k = uniq_total - 1; k >= 0 && k >= uniq_total - 10; k--)
4748                 {
4749                         monster_race *r_ptr = &r_info[who[k]];
4750                         fprintf(fff, _("  %-40s (レベル%3d)\n", "  %-40s (level %3d)\n"), (r_name + r_ptr->name), (int)r_ptr->level);
4751                 }
4752
4753         }
4754
4755         /* Free the "who" array */
4756         C_KILL(who, max_r_idx, s16b);
4757 }
4758
4759
4760 /*!
4761  * @brief 元種族情報をファイルにダンプする
4762  * @param fff ファイルポインタ
4763  * @return なし
4764  */
4765 static void dump_aux_race_history(player_type *creature_ptr, FILE *fff)
4766 {
4767         if (creature_ptr->old_race1 || creature_ptr->old_race2)
4768         {
4769                 int i;
4770
4771                 fprintf(fff, _("\n\n あなたは%sとして生まれた。", "\n\n You were born as %s."), race_info[creature_ptr->start_race].title);
4772                 for (i = 0; i < MAX_RACES; i++)
4773                 {
4774                         if (creature_ptr->start_race == i) continue;
4775                         if (i < 32)
4776                         {
4777                                 if (!(creature_ptr->old_race1 & 1L << i)) continue;
4778                         }
4779                         else
4780                         {
4781                                 if (!(creature_ptr->old_race2 & 1L << (i-32))) continue;
4782                         }
4783                         fprintf(fff, _("\n あなたはかつて%sだった。", "\n You were a %s before."), race_info[i].title);
4784                 }
4785
4786                 fputc('\n', fff);
4787         }
4788 }
4789
4790
4791 /*!
4792  * @brief 元魔法領域情報をファイルにダンプする
4793  * @param fff ファイルポインタ
4794  * @return なし
4795  */
4796 static void dump_aux_realm_history(FILE *fff)
4797 {
4798         if (p_ptr->old_realm)
4799         {
4800                 int i;
4801
4802                 fputc('\n', fff);
4803                 for (i = 0; i < MAX_MAGIC; i++)
4804                 {
4805                         if (!(p_ptr->old_realm & 1L << i)) continue;
4806                         fprintf(fff, _("\n あなたはかつて%s魔法を使えた。", "\n You were able to use %s magic before."), realm_names[i+1]);
4807                 }
4808                 fputc('\n', fff);
4809         }
4810 }
4811
4812
4813 /*!
4814  * @brief 徳の情報をファイルにダンプする
4815  * @param fff ファイルポインタ
4816  * @return なし
4817  */
4818 static void dump_aux_virtues(FILE *fff)
4819 {
4820         int v_nr, percent;
4821
4822         fprintf(fff, _("\n\n  [自分に関する情報]\n\n", "\n\n  [HP-rate & Max stat & Virtues]\n\n"));
4823
4824         percent = (int)(((long)p_ptr->player_hp[PY_MAX_LEVEL - 1] * 200L) /
4825                 (2 * p_ptr->hitdie +
4826                 ((PY_MAX_LEVEL - 1+3) * (p_ptr->hitdie + 1))));
4827
4828 #ifdef JP
4829                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "現在の体力ランク : %d/100\n\n", percent);
4830                 else fprintf(fff, "現在の体力ランク : ???\n\n");
4831                 fprintf(fff, "能力の最大値\n");
4832 #else
4833                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "Your current Life Rating is %d/100.\n\n", percent);
4834                 else fprintf(fff, "Your current Life Rating is ???.\n\n");
4835                 fprintf(fff, "Limits of maximum stats\n");
4836 #endif
4837                 for (v_nr = 0; v_nr < A_MAX; v_nr++)
4838                 {
4839                         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);
4840                         else fprintf(fff, "%s ???\n", stat_names[v_nr]);
4841                 }
4842
4843         fprintf(fff, _("\n属性 : %s\n", "\nYour alighnment : %s\n"), your_alignment(p_ptr));
4844         fprintf(fff, "\n");
4845         dump_virtues(p_ptr, fff);
4846 }
4847
4848
4849 /*!
4850  * @brief 突然変異の情報をファイルにダンプする
4851  * @param fff ファイルポインタ
4852  * @return なし
4853  */
4854 static void dump_aux_mutations(FILE *fff)
4855 {
4856         if (p_ptr->muta1 || p_ptr->muta2 || p_ptr->muta3)
4857         {
4858                 fprintf(fff, _("\n\n  [突然変異]\n\n", "\n\n  [Mutations]\n\n"));
4859                 dump_mutations(p_ptr, fff);
4860         }
4861 }
4862
4863
4864 /*!
4865  * @brief 所持品の情報をファイルにダンプする
4866  * @param fff ファイルポインタ
4867  * @return なし
4868  */
4869 static void dump_aux_equipment_inventory(FILE *fff)
4870 {
4871         int i;
4872         GAME_TEXT o_name[MAX_NLEN];
4873
4874         /* Dump the equipment */
4875         if (p_ptr->equip_cnt)
4876         {
4877                 fprintf(fff, _("  [キャラクタの装備]\n\n", "  [Character Equipment]\n\n"));
4878                 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
4879                 {
4880                         object_desc(o_name, &p_ptr->inventory_list[i], 0);
4881                         if ((((i == INVEN_RARM) && p_ptr->hidarite) || ((i == INVEN_LARM) && p_ptr->migite)) && p_ptr->ryoute)
4882                                 strcpy(o_name, _("(武器を両手持ち)", "(wielding with two-hands)"));
4883
4884                         fprintf(fff, "%c) %s\n",
4885                                 index_to_label(i), o_name);
4886                 }
4887                 fprintf(fff, "\n\n");
4888         }
4889
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                 object_desc(o_name, &p_ptr->inventory_list[i], 0);
4898                 fprintf(fff, "%c) %s\n", index_to_label(i), o_name);
4899         }
4900
4901         /* Add an empty line */
4902         fprintf(fff, "\n\n");
4903 }
4904
4905
4906 /*!
4907  * @brief 我が家と博物館のオブジェクト情報をファイルにダンプする
4908  * @param fff ファイルポインタ
4909  * @return なし
4910  */
4911 static void dump_aux_home_museum(FILE *fff)
4912 {
4913         GAME_TEXT o_name[MAX_NLEN];
4914         store_type  *st_ptr;
4915
4916         /* Do we need it?? */
4917         /* process_dungeon_file("w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x); */
4918
4919         /* Print the home */
4920         st_ptr = &town_info[1].store[STORE_HOME];
4921
4922         /* Home -- if anything there */
4923         if (st_ptr->stock_num)
4924         {
4925                 int i;
4926                 TERM_LEN x = 1;
4927
4928                 fprintf(fff, _("  [我が家のアイテム]\n", "  [Home Inventory]\n"));
4929
4930                 /* Dump all available items */
4931                 for (i = 0; i < st_ptr->stock_num; i++)
4932                 {
4933                         if ((i % 12) == 0)
4934                                 fprintf(fff, _("\n ( %d ページ )\n", "\n ( page %d )\n"), x++);
4935                         object_desc(o_name, &st_ptr->stock[i], 0);
4936                         fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
4937                 }
4938
4939                 /* Add an empty line */
4940                 fprintf(fff, "\n\n");
4941         }
4942
4943
4944         /* Print the home */
4945         st_ptr = &town_info[1].store[STORE_MUSEUM];
4946
4947         /* Home -- if anything there */
4948         if (st_ptr->stock_num)
4949         {
4950                 int i;
4951                 TERM_LEN x = 1;
4952
4953                 fprintf(fff, _("  [博物館のアイテム]\n", "  [Museum]\n"));
4954
4955                 /* Dump all available items */
4956                 for (i = 0; i < st_ptr->stock_num; i++)
4957                 {
4958 #ifdef JP
4959                 if ((i % 12) == 0) fprintf(fff, "\n ( %d ページ )\n", x++);
4960                         object_desc(o_name, &st_ptr->stock[i], 0);
4961                         fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
4962 #else
4963                 if ((i % 12) == 0) fprintf(fff, "\n ( page %d )\n", x++);
4964                         object_desc(o_name, &st_ptr->stock[i], 0);
4965                         fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
4966 #endif
4967
4968                 }
4969
4970                 /* Add an empty line */
4971                 fprintf(fff, "\n\n");
4972         }
4973 }
4974
4975
4976 /*!
4977  * @brief ダンプ出力のメインルーチン
4978  * Output the character dump to a file
4979  * @param fff ファイルポインタ
4980  * @return エラーコード
4981  */
4982 errr make_character_dump(FILE *fff)
4983 {
4984 #ifdef JP
4985         fprintf(fff, "  [変愚蛮怒 %d.%d.%d キャラクタ情報]\n\n",
4986                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4987 #else
4988         fprintf(fff, "  [Hengband %d.%d.%d Character Dump]\n\n",
4989                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4990 #endif
4991
4992         update_playtime();
4993
4994         dump_aux_display_player(fff);
4995         dump_aux_last_message(fff);
4996         dump_aux_options(fff);
4997         dump_aux_recall(fff);
4998         dump_aux_quest(fff);
4999         dump_aux_arena(fff);
5000         dump_aux_monsters(fff);
5001         dump_aux_virtues(fff);
5002         dump_aux_race_history(p_ptr, fff);
5003         dump_aux_realm_history(fff);
5004         dump_aux_class_special(fff);
5005         dump_aux_mutations(fff);
5006         dump_aux_pet(p_ptr, fff);
5007         fputs("\n\n", fff);
5008         dump_aux_equipment_inventory(fff);
5009         dump_aux_home_museum(fff);
5010
5011         fprintf(fff, _("  [チェックサム: \"%s\"]\n\n", "  [Check Sum: \"%s\"]\n\n"), get_check_sum());
5012         return 0;
5013 }
5014
5015 /*!
5016  * @brief プレイヤーステータスをファイルダンプ出力する
5017  * Hack -- Dump a character description file
5018  * @param name 出力ファイル名
5019  * @return エラーコード
5020  * @details
5021  * Allow the "full" flag to dump additional info,
5022  * and trigger its usage from various places in the code.
5023  */
5024 errr file_character(concptr name)
5025 {
5026         int             fd = -1;
5027         FILE            *fff = NULL;
5028         char            buf[1024];
5029         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
5030
5031         /* File type is "TEXT" */
5032         FILE_TYPE(FILE_TYPE_TEXT);
5033
5034         /* Check for existing file */
5035         fd = fd_open(buf, O_RDONLY);
5036
5037         /* Existing file */
5038         if (fd >= 0)
5039         {
5040                 char out_val[160];
5041                 (void)fd_close(fd);
5042
5043                 /* Build query */
5044                 (void)sprintf(out_val, _("現存するファイル %s に上書きしますか? ", "Replace existing file %s? "), buf);
5045
5046                 /* Ask */
5047                 if (get_check_strict(out_val, CHECK_NO_HISTORY)) fd = -1;
5048         }
5049
5050         /* Open the non-existing file */
5051         if (fd < 0) fff = my_fopen(buf, "w");
5052
5053         /* Invalid file */
5054         if (!fff)
5055         {
5056                 prt(_("キャラクタ情報のファイルへの書き出しに失敗しました!", "Character dump failed!"), 0, 0);
5057
5058                 (void)inkey();
5059
5060                 /* Error */
5061                 return (-1);
5062         }
5063
5064         (void)make_character_dump(fff);
5065         my_fclose(fff);
5066
5067
5068         msg_print(_("キャラクタ情報のファイルへの書き出しに成功しました。", "Character dump successful."));
5069         msg_print(NULL);
5070
5071         /* Success */
5072         return (0);
5073 }
5074
5075
5076 /*!
5077  * @brief ファイル内容の一行をコンソールに出力する
5078  * Display single line of on-line help file
5079  * @param str 出力する文字列
5080  * @param cy コンソールの行
5081  * @param shower 確認中
5082  * @return なし
5083  * @details
5084  * <pre>
5085  * You can insert some special color tag to change text color.
5086  * Such as...
5087  * WHITETEXT [[[[y|SOME TEXT WHICH IS DISPLAYED IN YELLOW| WHITETEXT
5088  * A colored segment is between "[[[[y|" and the last "|".
5089  * You can use any single character in place of the "|".
5090  * </pre>
5091  */
5092 static void show_file_aux_line(concptr str, int cy, concptr shower)
5093 {
5094         static const char tag_str[] = "[[[[";
5095         byte color = TERM_WHITE;
5096         char in_tag = '\0';
5097         int cx = 0;
5098         int i;
5099         char lcstr[1024];
5100
5101         if (shower)
5102         {
5103                 /* Make a lower case version of str for searching */
5104                 strcpy(lcstr, str);
5105                 str_tolower(lcstr);
5106         }
5107
5108         /* Initial cursor position */
5109         Term_gotoxy(cx, cy);
5110
5111         for (i = 0; str[i];)
5112         {
5113                 int len = strlen(&str[i]);
5114                 int showercol = len + 1;
5115                 int bracketcol = len + 1;
5116                 int endcol = len;
5117                 concptr ptr;
5118
5119                 /* Search for a shower string in the line */
5120                 if (shower)
5121                 {
5122                         ptr = my_strstr(&lcstr[i], shower);
5123                         if (ptr) showercol = ptr - &lcstr[i];
5124                 }
5125
5126                 /* Search for a color segment tag */
5127                 ptr = in_tag ? my_strchr(&str[i], in_tag) : my_strstr(&str[i], tag_str);
5128                 if (ptr) bracketcol = ptr - &str[i];
5129
5130                 /* A color tag is found */
5131                 if (bracketcol < endcol) endcol = bracketcol;
5132
5133                 /* The shower string is found before the color tag */
5134                 if (showercol < endcol) endcol = showercol;
5135
5136                 /* Print a segment of the line */
5137                 Term_addstr(endcol, color, &str[i]);
5138                 cx += endcol;
5139                 i += endcol;
5140
5141                 /* Shower string? */
5142                 if (endcol == showercol)
5143                 {
5144                         int showerlen = strlen(shower);
5145
5146                         /* Print the shower string in yellow */
5147                         Term_addstr(showerlen, TERM_YELLOW, &str[i]);
5148                         cx += showerlen;
5149                         i += showerlen;
5150                 }
5151
5152                 /* Colored segment? */
5153                 else if (endcol == bracketcol)
5154                 {
5155                         if (in_tag)
5156                         {
5157                                 /* Found the end of colored segment */
5158                                 i++;
5159
5160                                 /* Now looking for an another tag_str */
5161                                 in_tag = '\0';
5162
5163                                 /* Set back to the default color */
5164                                 color = TERM_WHITE;
5165                         }
5166                         else
5167                         {
5168                                 /* Found a tag_str, and get a tag color */
5169                                 i += sizeof(tag_str)-1;
5170
5171                                 /* Get tag color */
5172                                 color = color_char_to_attr(str[i]);
5173
5174                                 /* Illegal color tag */
5175                                 if (color == 255 || str[i+1] == '\0')
5176                                 {
5177                                         /* Illegal color tag */
5178                                         color = TERM_WHITE;
5179
5180                                         /* Print the broken tag as a string */
5181                                         Term_addstr(-1, TERM_WHITE, tag_str);
5182                                         cx += sizeof(tag_str)-1;
5183                                 }
5184                                 else
5185                                 {
5186                                         /* Skip the color tag */
5187                                         i++;
5188
5189                                         /* Now looking for a close tag */
5190                                         in_tag = str[i];
5191
5192                                         /* Skip the close-tag-indicator */
5193                                         i++;
5194                                 }
5195                         }
5196                 }
5197
5198         } /* for (i = 0; str[i];) */
5199
5200         /* Clear rest of line */
5201         Term_erase(cx, cy, 255);
5202 }
5203
5204
5205 /*!
5206  * @brief ファイル内容をコンソールに出力する
5207  * Recursive file perusal.
5208  * @param show_version TRUEならばコンソール上にゲームのバージョンを表示する
5209  * @param name ファイル名の文字列
5210  * @param what 内容キャプションの文字列
5211  * @param line 表示の現在行
5212  * @param mode オプション
5213  * @return なし
5214  * @details
5215  * <pre>
5216  * Process various special text in the input file, including
5217  * the "menu" structures used by the "help file" system.
5218  * Return FALSE on 'q' to exit from a deep, otherwise TRUE.
5219  * </pre>
5220  */
5221 bool show_file(bool show_version, concptr name, concptr what, int line, BIT_FLAGS mode)
5222 {
5223         int i, n, skey;
5224
5225         /* Number of "real" lines passed by */
5226         int next = 0;
5227
5228         /* Number of "real" lines in the file */
5229         int size = 0;
5230
5231         /* Backup value for "line" */
5232         int back = 0;
5233
5234         /* This screen has sub-screens */
5235         bool menu = FALSE;
5236
5237         /* Current help file */
5238         FILE *fff = NULL;
5239
5240         /* Find this string (if any) */
5241         concptr find = NULL;
5242
5243         /* Jump to this tag */
5244         concptr tag = NULL;
5245
5246         /* Hold strings to find/show */
5247         char finder_str[81];
5248         char shower_str[81];
5249         char back_str[81];
5250
5251         /* String to show */
5252         concptr shower = NULL;
5253
5254         /* Filename */
5255         char filename[1024];
5256
5257         /* Describe this thing */
5258         char caption[128];
5259
5260         /* Path buffer */
5261         char path[1024];
5262
5263         /* General buffer */
5264         char buf[1024];
5265
5266         /* Sub-menu information */
5267         char hook[68][32];
5268
5269         bool reverse = (line < 0);
5270
5271         int wid, hgt, rows;
5272
5273         Term_get_size(&wid, &hgt);
5274         rows = hgt - 4;
5275
5276         strcpy(finder_str, "");
5277         strcpy(shower_str, "");
5278         strcpy(caption, "");
5279         for (i = 0; i < 68; i++)
5280         {
5281                 hook[i][0] = '\0';
5282         }
5283
5284         strcpy(filename, name);
5285
5286         n = strlen(filename);
5287
5288         /* Extract the tag from the filename */
5289         for (i = 0; i < n; i++)
5290         {
5291                 if (filename[i] == '#')
5292                 {
5293                         filename[i] = '\0';
5294                         tag = filename + i + 1;
5295                         break;
5296                 }
5297         }
5298
5299         /* Redirect the name */
5300         name = filename;
5301
5302         if (what)
5303         {
5304                 strcpy(caption, what);
5305                 strcpy(path, name);
5306                 fff = my_fopen(path, "r");
5307         }
5308
5309         /* Look in "help" */
5310         if (!fff)
5311         {
5312                 sprintf(caption, _("ヘルプ・ファイル'%s'", "Help file '%s'"), name);
5313                 path_build(path, sizeof(path), ANGBAND_DIR_HELP, name);
5314                 fff = my_fopen(path, "r");
5315         }
5316
5317         /* Look in "info" */
5318         if (!fff)
5319         {
5320                 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
5321                 path_build(path, sizeof(path), ANGBAND_DIR_INFO, name);
5322                 fff = my_fopen(path, "r");
5323         }
5324
5325         /* Look in "info" */
5326         if (!fff)
5327         {
5328                 path_build(path, sizeof(path), ANGBAND_DIR, name);
5329
5330                 for (i = 0; path[i]; i++)
5331                         if ('\\' == path[i])
5332                                 path[i] = PATH_SEP[0];
5333
5334                 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
5335                 fff = my_fopen(path, "r");
5336         }
5337
5338         if (!fff)
5339         {
5340                 msg_format(_("'%s'をオープンできません。", "Cannot open '%s'."), name);
5341                 msg_print(NULL);
5342
5343                 return (TRUE);
5344         }
5345
5346
5347         /* Pre-Parse the file */
5348         while (TRUE)
5349         {
5350                 char *str = buf;
5351
5352                 /* Read a line or stop */
5353                 if (my_fgets(fff, buf, sizeof(buf))) break;
5354
5355                 /* XXX Parse "menu" items */
5356                 if (prefix(str, "***** "))
5357                 {
5358                         /* Notice "menu" requests */
5359                         if ((str[6] == '[') && isalpha(str[7]))
5360                         {
5361                                 /* Extract the menu item */
5362                                 int k = str[7] - 'A';
5363
5364                                 /* This is a menu file */
5365                                 menu = TRUE;
5366
5367                                 if ((str[8] == ']') && (str[9] == ' '))
5368                                 {
5369                                         /* Extract the menu item */
5370                                         strncpy(hook[k], str + 10, 31);
5371
5372                                         /* Make sure it's null-terminated */
5373                                         hook[k][31] = '\0';
5374                                 }
5375                         }
5376                         /* Notice "tag" requests */
5377                         else if (str[6] == '<')
5378                         {
5379                                 size_t len = strlen(str);
5380
5381                                 if (str[len - 1] == '>')
5382                                 {
5383                                         str[len - 1] = '\0';
5384                                         if (tag && streq(str + 7, tag)) line = next;
5385                                 }
5386                         }
5387
5388                         /* Skip this */
5389                         continue;
5390                 }
5391
5392                 /* Count the "real" lines */
5393                 next++;
5394         }
5395
5396         /* Save the number of "real" lines */
5397         size = next;
5398
5399         /* start from bottom when reverse mode */
5400         if (line == -1) line = ((size-1)/rows)*rows;
5401         Term_clear();
5402
5403         /* Display the file */
5404         while (TRUE)
5405         {
5406                 /* Restart when necessary */
5407                 if (line >= size - rows) line = size - rows;
5408                 if (line < 0) line = 0;
5409
5410                 /* Re-open the file if needed */
5411                 if (next > line)
5412                 {
5413                         my_fclose(fff);
5414
5415                         /* Hack -- Re-Open the file */
5416                         fff = my_fopen(path, "r");
5417
5418                         if (!fff) return (FALSE);
5419
5420                         /* File has been restarted */
5421                         next = 0;
5422                 }
5423
5424                 /* Goto the selected line */
5425                 while (next < line)
5426                 {
5427                         /* Get a line */
5428                         if (my_fgets(fff, buf, sizeof(buf))) break;
5429
5430                         /* Skip tags/links */
5431                         if (prefix(buf, "***** ")) continue;
5432
5433                         /* Count the lines */
5434                         next++;
5435                 }
5436
5437                 /* Dump the next 20, or rows, lines of the file */
5438                 for (i = 0; i < rows; )
5439                 {
5440                         concptr str = buf;
5441
5442                         /* Hack -- track the "first" line */
5443                         if (!i) line = next;
5444
5445                         /* Get a line of the file or stop */
5446                         if (my_fgets(fff, buf, sizeof(buf))) break;
5447
5448                         /* Hack -- skip "special" lines */
5449                         if (prefix(buf, "***** ")) continue;
5450
5451                         /* Count the "real" lines */
5452                         next++;
5453
5454                         /* Hack -- keep searching */
5455                         if (find && !i)
5456                         {
5457                                 char lc_buf[1024];
5458
5459                                 /* Make a lower case version of str for searching */
5460                                 strcpy(lc_buf, str);
5461                                 str_tolower(lc_buf);
5462
5463                                 if (!my_strstr(lc_buf, find)) continue;
5464                         }
5465
5466                         /* Hack -- stop searching */
5467                         find = NULL;
5468
5469                         /* Dump the line */
5470                         show_file_aux_line(str, i + 2, shower);
5471
5472                         /* Count the printed lines */
5473                         i++;
5474                 }
5475
5476                 while (i < rows)
5477                 {
5478                         /* Clear rest of line */
5479                         Term_erase(0, i + 2, 255);
5480
5481                         i++;
5482                 }
5483
5484                 /* Hack -- failed search */
5485                 if (find)
5486                 {
5487                         bell();
5488                         line = back;
5489                         find = NULL;
5490                         continue;
5491                 }
5492
5493
5494                 /* Show a general "title" */
5495                 if (show_version)
5496                 {
5497                         prt(format(_("[変愚蛮怒 %d.%d.%d, %s, %d/%d]", "[Hengband %d.%d.%d, %s, Line %d/%d]"),
5498                            FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH,
5499                            caption, line, size), 0, 0);
5500                 }
5501                 else
5502                 {
5503                         prt(format(_("[%s, %d/%d]", "[%s, Line %d/%d]"),
5504                                 caption, line, size), 0, 0);
5505                 }
5506
5507                 /* Prompt -- small files */
5508                 if (size <= rows)
5509                 {
5510                         /* Wait for it */
5511                         prt(_("[キー:(?)ヘルプ (ESC)終了]", "[Press ESC to exit.]"), hgt - 1, 0);
5512                 }
5513
5514                 /* Prompt -- large files */
5515                 else
5516                 {
5517 #ifdef JP
5518                         if(reverse)
5519                                 prt("[キー:(RET/スペース)↑ (-)↓ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
5520                         else
5521                                 prt("[キー:(RET/スペース)↓ (-)↑ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
5522 #else
5523                         prt("[Press Return, Space, -, =, /, |, or ESC to exit.]", hgt - 1, 0);
5524 #endif
5525                 }
5526
5527                 /* Get a special key code */
5528                 skey = inkey_special(TRUE);
5529
5530                 switch (skey)
5531                 {
5532                 /* Show the help for the help */
5533                 case '?':
5534                         /* Hack - prevent silly recursion */
5535                         if (strcmp(name, _("jhelpinfo.txt", "helpinfo.txt")) != 0)
5536                                 show_file(TRUE, _("jhelpinfo.txt", "helpinfo.txt"), NULL, 0, mode);
5537                         break;
5538
5539                 /* Hack -- try showing */
5540                 case '=':
5541                         /* Get "shower" */
5542                         prt(_("強調: ", "Show: "), hgt - 1, 0);
5543
5544                         strcpy(back_str, shower_str);
5545                         if (askfor(shower_str, 80))
5546                         {
5547                                 if (shower_str[0])
5548                                 {
5549                                         /* Make it lowercase */
5550                                         str_tolower(shower_str);
5551
5552                                         /* Show it */
5553                                         shower = shower_str;
5554                                 }
5555                                 else shower = NULL; /* Stop showing */
5556                         }
5557                         else strcpy(shower_str, back_str);
5558                         break;
5559
5560                 /* Hack -- try finding */
5561                 case '/':
5562                 case KTRL('s'):
5563                         /* Get "finder" */
5564                         prt(_("検索: ", "Find: "), hgt - 1, 0);
5565
5566                         strcpy(back_str, finder_str);
5567                         if (askfor(finder_str, 80))
5568                         {
5569                                 if (finder_str[0])
5570                                 {
5571                                         /* Find it */
5572                                         find = finder_str;
5573                                         back = line;
5574                                         line = line + 1;
5575
5576                                         /* Make finder lowercase */
5577                                         str_tolower(finder_str);
5578
5579                                         /* Show it */
5580                                         shower = finder_str;
5581                                 }
5582                                 else shower = NULL; /* Stop showing */
5583                         }
5584                         else strcpy(finder_str, back_str);
5585                         break;
5586
5587                 /* Hack -- go to a specific line */
5588                 case '#':
5589                         {
5590                                 char tmp[81];
5591                                 prt(_("行: ", "Goto Line: "), hgt - 1, 0);
5592                                 strcpy(tmp, "0");
5593
5594                                 if (askfor(tmp, 80)) line = atoi(tmp);
5595                         }
5596                         break;
5597
5598                 /* Hack -- go to the top line */
5599                 case SKEY_TOP:
5600                         line = 0;
5601                         break;
5602
5603                 /* Hack -- go to the bottom line */
5604                 case SKEY_BOTTOM:
5605                         line = ((size - 1) / rows) * rows;
5606                         break;
5607
5608                 /* Hack -- go to a specific file */
5609                 case '%':
5610                         {
5611                                 char tmp[81];
5612                                 prt(_("ファイル・ネーム: ", "Goto File: "), hgt - 1, 0);
5613                                 strcpy(tmp, _("jhelp.hlp", "help.hlp"));
5614
5615                                 if (askfor(tmp, 80))
5616                                 {
5617                                         if (!show_file(TRUE, tmp, NULL, 0, mode)) skey = 'q';
5618                                 }
5619                         }
5620                         break;
5621
5622                 /* Allow backing up */
5623                 case '-':
5624                         line = line + (reverse ? rows : -rows);
5625                         if (line < 0) line = 0;
5626                         break;
5627
5628                 /* One page up */
5629                 case SKEY_PGUP:
5630                         line = line - rows;
5631                         if (line < 0) line = 0;
5632                         break;
5633
5634                 /* Advance a single line */
5635                 case '\n':
5636                 case '\r':
5637                         line = line + (reverse ? -1 : 1);
5638                         if (line < 0) line = 0;
5639                         break;
5640
5641                 /* Move up / down */
5642                 case '8':
5643                 case SKEY_UP:
5644                         line--;
5645                         if (line < 0) line = 0;
5646                         break;
5647
5648                 case '2':
5649                 case SKEY_DOWN:
5650                         line++;
5651                         break;
5652
5653                 /* Advance one page */
5654                 case ' ':
5655                         line = line + (reverse ? -rows : rows);
5656                         if (line < 0) line = 0;
5657                         break;
5658
5659                 /* One page down */
5660                 case SKEY_PGDOWN:
5661                         line = line + rows;
5662                         break;
5663                 }
5664
5665                 /* Recurse on numbers */
5666                 if (menu)
5667                 {
5668                         int key = -1;
5669
5670                         if (!(skey & SKEY_MASK) && isalpha(skey))
5671                                 key = skey - 'A';
5672
5673                         if ((key > -1) && hook[key][0])
5674                         {
5675                                 /* Recurse on that file */
5676                                 if (!show_file(TRUE, hook[key], NULL, 0, mode))
5677                                         skey = 'q';
5678                         }
5679                 }
5680
5681                 /* Hack, dump to file */
5682                 if (skey == '|')
5683                 {
5684                         FILE *ffp;
5685                         char buff[1024];
5686                         char xtmp[82];
5687
5688                         strcpy (xtmp, "");
5689
5690                         if (!get_string(_("ファイル名: ", "File name: "), xtmp, 80)) continue;
5691                         my_fclose(fff);
5692                         path_build(buff, sizeof(buff), ANGBAND_DIR_USER, xtmp);
5693
5694                         /* Hack -- Re-Open the file */
5695                         fff = my_fopen(path, "r");
5696
5697                         ffp = my_fopen(buff, "w");
5698
5699                         if (!(fff && ffp))
5700                         {
5701                                 msg_print(_("ファイルを開けません。", "Failed to open file."));
5702                                 skey = ESCAPE;
5703                                 break;
5704                         }
5705
5706                         sprintf(xtmp, "%s: %s", p_ptr->name, what ? what : caption);
5707                         my_fputs(ffp, xtmp, 80);
5708                         my_fputs(ffp, "\n", 80);
5709
5710                         while (!my_fgets(fff, buff, sizeof(buff)))
5711                                 my_fputs(ffp, buff, 80);
5712                         my_fclose(fff);
5713                         my_fclose(ffp);
5714
5715                         /* Hack -- Re-Open the file */
5716                         fff = my_fopen(path, "r");
5717                 }
5718
5719                 /* Return to last screen */
5720                 if ((skey == ESCAPE) || (skey == '<')) break;
5721
5722                 /* Exit on the ^q */
5723                 if (skey == KTRL('q')) skey = 'q';
5724
5725                 /* Exit on the q key */
5726                 if (skey == 'q') break;
5727         }
5728         my_fclose(fff);
5729
5730         /* Escape */
5731         if (skey == 'q') return (FALSE);
5732
5733         /* Normal return */
5734         return (TRUE);
5735 }
5736
5737
5738 /*!
5739  * @brief ヘルプを表示するコマンドのメインルーチン
5740  * Peruse the On-Line-Help
5741  * @return なし
5742  * @details
5743  */
5744 void do_cmd_help(void)
5745 {
5746         screen_save();
5747
5748         /* Peruse the main help file */
5749         (void)show_file(TRUE, _("jhelp.hlp", "help.hlp"), NULL, 0, 0);
5750         screen_load();
5751 }
5752
5753
5754 /*!
5755  * @brief プレイヤーの名前をチェックして修正する
5756  * Process the player name.
5757  * @param sf セーブファイル名に合わせた修正を行うならばTRUE
5758  * @return なし
5759  * @details
5760  * Extract a clean "base name".
5761  * Build the savefile name if needed.
5762  */
5763 void process_player_name(bool sf)
5764 {
5765         int i, k = 0;
5766         char old_player_base[32] = "";
5767
5768         if (current_world_ptr->character_generated) strcpy(old_player_base, p_ptr->base_name);
5769
5770         /* Cannot be too long */
5771 #if defined(MACINTOSH) || defined(ACORN)
5772         if (strlen(p_ptr->name) > 15)
5773         {
5774                 /* Name too long */
5775                 quit_fmt(_("'%s'という名前は長すぎます!", "The name '%s' is too long!"), p_ptr->name);
5776         }
5777 #endif
5778
5779         /* Cannot contain "icky" characters */
5780         for (i = 0; p_ptr->name[i]; i++)
5781         {
5782                 /* No control characters */
5783 #ifdef JP
5784                 if (iskanji(p_ptr->name[i])){i++;continue;}
5785                 if (iscntrl( (unsigned char)p_ptr->name[i]))
5786 #else
5787                 if (iscntrl(p_ptr->name[i]))
5788 #endif
5789
5790                 {
5791                         /* Illegal characters */
5792                         quit_fmt(_("'%s' という名前は不正なコントロールコードを含んでいます。", "The name '%s' contains control chars!"), p_ptr->name);
5793                 }
5794         }
5795
5796
5797 #ifdef MACINTOSH
5798
5799         /* Extract "useful" letters */
5800         for (i = 0; p_ptr->name[i]; i++)
5801         {
5802 #ifdef JP
5803                 unsigned char c = p_ptr->name[i];
5804 #else
5805                 char c = p_ptr->name[i];
5806 #endif
5807
5808
5809                 /* Convert "dot" to "underscore" */
5810                 if (c == '.') c = '_';
5811
5812                 /* Accept all the letters */
5813                 p_ptr->base_name[k++] = c;
5814         }
5815
5816 #else
5817
5818         /* Extract "useful" letters */
5819         for (i = 0; p_ptr->name[i]; i++)
5820         {
5821 #ifdef JP
5822                 unsigned char c = p_ptr->name[i];
5823 #else
5824                 char c = p_ptr->name[i];
5825 #endif
5826
5827                 /* Accept some letters */
5828 #ifdef JP
5829                 if(iskanji(c)){
5830                   if(k + 2 >= sizeof(p_ptr->base_name) || !p_ptr->name[i+1]) break;
5831                   p_ptr->base_name[k++] = c;
5832                   i++;
5833                   p_ptr->base_name[k++] = p_ptr->name[i];
5834                 }
5835 #ifdef SJIS
5836                 else if (iskana(c)) p_ptr->base_name[k++] = c;
5837 #endif
5838                 else
5839 #endif
5840                 /* Convert path separator to underscore */
5841                 if (!strncmp(PATH_SEP, p_ptr->name+i, strlen(PATH_SEP))){
5842                         p_ptr->base_name[k++] = '_';
5843                         i += strlen(PATH_SEP);
5844                 }
5845                 /* Convert some characters to underscore */
5846 #if defined(WINDOWS)
5847                 else if (my_strchr("\"*,/:;<>?\\|", c)) p_ptr->base_name[k++] = '_';
5848 #endif
5849                 else if (isprint(c)) p_ptr->base_name[k++] = c;
5850         }
5851
5852 #endif
5853
5854         /* Terminate */
5855         p_ptr->base_name[k] = '\0';
5856
5857         /* Require a "base" name */
5858         if (!p_ptr->base_name[0]) strcpy(p_ptr->base_name, "PLAYER");
5859
5860
5861 #ifdef SAVEFILE_MUTABLE
5862
5863         /* Accept */
5864         sf = TRUE;
5865
5866 #endif
5867         if (!savefile_base[0] && savefile[0])
5868         {
5869                 concptr s;
5870                 s = savefile;
5871                 while (1)
5872                 {
5873                         concptr t;
5874                         t = my_strstr(s, PATH_SEP);
5875                         if (!t)
5876                                 break;
5877                         s = t+1;
5878                 }
5879                 strcpy(savefile_base, s);
5880         }
5881
5882         if (!savefile_base[0] || !savefile[0])
5883                 sf = TRUE;
5884
5885         /* Change the savefile name */
5886         if (sf)
5887         {
5888                 char temp[128];
5889
5890                 strcpy(savefile_base, p_ptr->base_name);
5891
5892 #ifdef SAVEFILE_USE_UID
5893                 /* Rename the savefile, using the p_ptr->player_uid and p_ptr->base_name */
5894                 (void)sprintf(temp, "%d.%s", p_ptr->player_uid, p_ptr->base_name);
5895 #else
5896                 /* Rename the savefile, using the p_ptr->base_name */
5897                 (void)sprintf(temp, "%s", p_ptr->base_name);
5898 #endif
5899                 path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
5900         }
5901
5902         /* Load an autopick preference file */
5903         if (current_world_ptr->character_generated)
5904         {
5905                 if (!streq(old_player_base, p_ptr->base_name)) autopick_load_pref(FALSE);
5906         }
5907 }
5908
5909
5910 /*!
5911  * @brief プレイヤーの名前を変更するコマンドのメインルーチン
5912  * Gets a name for the character, reacting to name changes.
5913  * @return なし
5914  * @details
5915  * <pre>
5916  * Assumes that "display_player()" has just been called
5917  * Perhaps we should NOT ask for a name (at "birth()") on
5918  * Unix machines?  XXX XXX
5919  * What a horrible name for a global function.  
5920  * </pre>
5921  */
5922 void get_name(void)
5923 {
5924         char tmp[64];
5925
5926         /* Save the player name */
5927         strcpy(tmp, p_ptr->name);
5928
5929         /* Prompt for a new name */
5930         if (get_string(_("キャラクターの名前を入力して下さい: ", "Enter a name for your character: "), tmp, 15))
5931         {
5932                 /* Use the name */
5933                 strcpy(p_ptr->name, tmp);
5934         }
5935
5936         if (0 == strlen(p_ptr->name))
5937         {
5938                 /* Use default name */
5939                 strcpy(p_ptr->name, "PLAYER");
5940         }
5941
5942         strcpy(tmp,ap_ptr->title);
5943 #ifdef JP
5944         if(ap_ptr->no == 1)
5945                 strcat(tmp,"の");
5946 #else
5947         strcat(tmp, " ");
5948 #endif
5949         strcat(tmp,p_ptr->name);
5950
5951         /* Re-Draw the name (in light blue) */
5952         Term_erase(34, 1, 255);
5953         c_put_str(TERM_L_BLUE, tmp, 1, 34);
5954
5955         /* Erase the prompt, etc */
5956         clear_from(22);
5957 }
5958
5959
5960
5961 /*!
5962  * @brief セーブするコマンドのメインルーチン
5963  * Save the game
5964  * @param is_autosave オートセーブ中の処理ならばTRUE
5965  * @return なし
5966  * @details
5967  */
5968 void do_cmd_save_game(int is_autosave)
5969 {
5970         /* Autosaves do not disturb */
5971         if (is_autosave)
5972         {
5973                 msg_print(_("自動セーブ中", "Autosaving the game..."));
5974         }
5975         else
5976         {
5977                 disturb(p_ptr, TRUE, TRUE);
5978         }
5979
5980         /* Clear messages */
5981         msg_print(NULL);
5982         handle_stuff();
5983
5984         prt(_("ゲームをセーブしています...", "Saving game..."), 0, 0);
5985
5986         Term_fresh();
5987
5988         /* The player is not dead */
5989         (void)strcpy(p_ptr->died_from, _("(セーブ)", "(saved)"));
5990
5991         /* Forbid suspend */
5992         signals_ignore_tstp();
5993
5994         /* Save the player */
5995         if (save_player())
5996         {
5997                 prt(_("ゲームをセーブしています... 終了", "Saving game... done."), 0, 0);
5998         }
5999
6000         /* Save failed (oops) */
6001         else
6002         {
6003                 prt(_("ゲームをセーブしています... 失敗!", "Saving game... failed!"), 0, 0);
6004         }
6005
6006         /* Allow suspend again */
6007         signals_handle_tstp();
6008
6009         Term_fresh();
6010
6011         /* Note that the player is not dead */
6012         (void)strcpy(p_ptr->died_from, _("(元気に生きている)", "(alive and well)"));
6013
6014         /* HACK -- don't get sanity blast on updating view */
6015         current_world_ptr->is_loading_now = FALSE;
6016
6017         update_creature(p_ptr);
6018
6019         /* Initialize monster process */
6020         mproc_init();
6021
6022         /* HACK -- reset the hackish flag */
6023         current_world_ptr->is_loading_now = TRUE;
6024 }
6025
6026
6027 /*!
6028  * @brief セーブ後にゲーム中断フラグを立てる/
6029  * Save the game and exit
6030  * @return なし
6031  * @details
6032  */
6033 void do_cmd_save_and_exit(void)
6034 {
6035         p_ptr->playing = FALSE;
6036         p_ptr->leaving = TRUE;
6037         exe_write_diary(p_ptr, NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
6038 }
6039
6040
6041 #define GRAVE_LINE_WIDTH 31
6042
6043 /*!
6044  * @brief 墓石の真ん中に文字列を書き込む /
6045  * Centers a string within a GRAVE_LINE_WIDTH character string          -JWT-
6046  * @return なし
6047  * @details
6048  */
6049 static void center_string(char *buf, concptr str)
6050 {
6051         int i, j;
6052
6053         /* Total length */
6054         i = strlen(str);
6055
6056         /* Necessary border */
6057         j = GRAVE_LINE_WIDTH / 2 - i / 2;
6058
6059         /* Mega-Hack */
6060         (void)sprintf(buf, "%*s%s%*s", j, "", str, GRAVE_LINE_WIDTH - i - j, "");
6061 }
6062
6063
6064 #if 0
6065 /*!
6066  * @brief 骨ファイル出力 /
6067  * Save a "bones" file for a dead character
6068  * @details
6069  * <pre>
6070  * Note that we will not use these files until Angband 2.8.0, and
6071  * then we will only use the name and level on which death occured.
6072  * Should probably attempt some form of locking...
6073  * </pre>
6074  */
6075 static void make_bones(void)
6076 {
6077         FILE                *fp;
6078
6079         char                str[1024];
6080
6081
6082         /* Ignore wizards and borgs */
6083         if (!(current_world_ptr->noscore & 0x00FF))
6084         {
6085                 /* Ignore people who die in town */
6086                 if (p_ptr->current_floor_ptr->dun_level)
6087                 {
6088                         char tmp[128];
6089
6090                         /* "Bones" name */
6091                         sprintf(tmp, "bone.%03d", p_ptr->current_floor_ptr->dun_level);
6092                         path_build(str, sizeof(str), ANGBAND_DIR_BONE, tmp);
6093
6094                         /* Attempt to open the bones file */
6095                         fp = my_fopen(str, "r");
6096
6097                         /* Close it right away */
6098                         if (fp) my_fclose(fp);
6099
6100                         /* Do not over-write a previous ghost */
6101                         if (fp) return;
6102
6103                         /* File type is "TEXT" */
6104                         FILE_TYPE(FILE_TYPE_TEXT);
6105
6106                         /* Grab permissions */
6107                         safe_setuid_grab();
6108
6109                         /* Try to write a new "Bones File" */
6110                         fp = my_fopen(str, "w");
6111
6112                         /* Drop permissions */
6113                         safe_setuid_drop();
6114
6115                         /* Not allowed to write it?  Weird. */
6116                         if (!fp) return;
6117
6118                         /* Save the info */
6119                         fprintf(fp, "%s\n", p_ptr->name);
6120                         fprintf(fp, "%d\n", p_ptr->mhp);
6121                         fprintf(fp, "%d\n", p_ptr->prace);
6122                         fprintf(fp, "%d\n", p_ptr->pclass);
6123
6124                         /* Close and save the Bones file */
6125                         my_fclose(fp);
6126                 }
6127         }
6128 }
6129 #endif
6130
6131
6132 /*
6133  * Redefinable "print_tombstone" action
6134  */
6135 bool (*tombstone_aux)(void) = NULL;
6136
6137
6138 /*!
6139  * @brief 墓石のアスキーアート表示 /
6140  * Display a "tomb-stone"
6141  * @return なし
6142  */
6143 void print_tomb(void)
6144 {
6145         bool done = FALSE;
6146
6147         /* Do we use a special tombstone ? */
6148         if (tombstone_aux)
6149         {
6150                 /* Use tombstone hook */
6151                 done = (*tombstone_aux)();
6152         }
6153
6154         /* Print the text-tombstone */
6155         if (!done)
6156         {
6157                 concptr   p;
6158                 char   tmp[160];
6159                 char   buf[1024];
6160                 char   dummy[80];
6161                 char   *t;
6162                 FILE   *fp;
6163                 time_t ct = time((time_t)0);
6164 #ifdef JP
6165                 int    extra_line = 0;
6166 #endif
6167                 Term_clear();
6168                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("dead_j.txt", "dead.txt"));
6169
6170                 /* Open the News file */
6171                 fp = my_fopen(buf, "r");
6172
6173                 /* Dump */
6174                 if (fp)
6175                 {
6176                         int i = 0;
6177
6178                         /* Dump the file to the screen */
6179                         while (0 == my_fgets(fp, buf, sizeof(buf)))
6180                         {
6181                                 /* Display and advance */
6182                                 put_str(buf, i++, 0);
6183                         }
6184
6185                         /* Close */
6186                         my_fclose(fp);
6187                 }
6188
6189                 /* King or Queen */
6190                 if (p_ptr->total_winner || (p_ptr->lev > PY_MAX_LEVEL))
6191                 {
6192 #ifdef JP
6193                         /* 英日切り替え */
6194                         p= "偉大なる者";
6195 #else
6196                         p = "Magnificent";
6197 #endif
6198                 }
6199
6200                 /* Normal */
6201                 else
6202                 {
6203                         p =  player_title[p_ptr->pclass][(p_ptr->lev - 1) / 5];
6204                 }
6205
6206                 center_string(buf, p_ptr->name);
6207                 put_str(buf, 6, 11);
6208
6209 #ifndef JP
6210                 center_string(buf, "the");
6211                 put_str(buf, 7, 11);
6212 #endif
6213
6214                 center_string(buf, p);
6215                 put_str(buf, 8, 11);
6216
6217                 center_string(buf, cp_ptr->title);
6218                 put_str(buf, 10, 11);
6219
6220                 (void)sprintf(tmp, _("レベル: %d", "Level: %d"), (int)p_ptr->lev);
6221                 center_string(buf, tmp);
6222                 put_str(buf, 11, 11);
6223
6224                 (void)sprintf(tmp, _("経験値: %ld", "Exp: %ld"), (long)p_ptr->exp);
6225                 center_string(buf, tmp);
6226                 put_str(buf, 12, 11);
6227
6228                 (void)sprintf(tmp, _("所持金: %ld", "AU: %ld"), (long)p_ptr->au);
6229                 center_string(buf, tmp);
6230                 put_str(buf, 13, 11);
6231
6232 #ifdef JP
6233                 /* 墓に刻む言葉をオリジナルより細かく表示 */
6234                 if (streq(p_ptr->died_from, "途中終了"))
6235                 {
6236                         strcpy(tmp, "<自殺>");
6237                 }
6238                 else if (streq(p_ptr->died_from, "ripe"))
6239                 {
6240                         strcpy(tmp, "引退後に天寿を全う");
6241                 }
6242                 else if (streq(p_ptr->died_from, "Seppuku"))
6243                 {
6244                         strcpy(tmp, "勝利の後、切腹");
6245                 }
6246                 else
6247                 {
6248                         roff_to_buf(p_ptr->died_from, GRAVE_LINE_WIDTH + 1, tmp, sizeof tmp);
6249                         t = tmp + strlen(tmp) + 1;
6250                         if (*t)
6251                         {
6252                                 strcpy(dummy, t); /* 2nd line */
6253                                 if (*(t + strlen(t) + 1)) /* Does 3rd line exist? */
6254                                 {
6255                                         for (t = dummy + strlen(dummy) - 2; iskanji(*(t - 1)); t--) /* Loop */;
6256                                         strcpy(t, "…");
6257                                 }
6258                                 else if (my_strstr(tmp, "『") && suffix(dummy, "』"))
6259                                 {
6260                                         char dummy2[80];
6261                                         char *name_head = my_strstr(tmp, "『");
6262                                         sprintf(dummy2, "%s%s", name_head, dummy);
6263                                         if (strlen(dummy2) <= GRAVE_LINE_WIDTH)
6264                                         {
6265                                                 strcpy(dummy, dummy2);
6266                                                 *name_head = '\0';
6267                                         }
6268                                 }
6269                                 else if (my_strstr(tmp, "「") && suffix(dummy, "」"))
6270                                 {
6271                                         char dummy2[80];
6272                                         char *name_head = my_strstr(tmp, "「");
6273                                         sprintf(dummy2, "%s%s", name_head, dummy);
6274                                         if (strlen(dummy2) <= GRAVE_LINE_WIDTH)
6275                                         {
6276                                                 strcpy(dummy, dummy2);
6277                                                 *name_head = '\0';
6278                                         }
6279                                 }
6280                                 center_string(buf, dummy);
6281                                 put_str(buf, 15, 11);
6282                                 extra_line = 1;
6283                         }
6284                 }
6285                 center_string(buf, tmp);
6286                 put_str(buf, 14, 11);
6287
6288                 if (!streq(p_ptr->died_from, "ripe") && !streq(p_ptr->died_from, "Seppuku"))
6289                 {
6290                         if (p_ptr->current_floor_ptr->dun_level == 0)
6291                         {
6292                                 concptr field_name = p_ptr->town_num ? "街" : "荒野";
6293                                 if (streq(p_ptr->died_from, "途中終了"))
6294                                 {
6295                                         sprintf(tmp, "%sで死んだ", field_name);
6296                                 }
6297                                 else
6298                                 {
6299                                         sprintf(tmp, "に%sで殺された", field_name);
6300                                 }
6301                         }
6302                         else
6303                         {
6304                                 if (streq(p_ptr->died_from, "途中終了"))
6305                                 {
6306                                         sprintf(tmp, "地下 %d 階で死んだ", (int)p_ptr->current_floor_ptr->dun_level);
6307                                 }
6308                                 else
6309                                 {
6310                                         sprintf(tmp, "に地下 %d 階で殺された", (int)p_ptr->current_floor_ptr->dun_level);
6311                                 }
6312                         }
6313                         center_string(buf, tmp);
6314                         put_str(buf, 15 + extra_line, 11);
6315                 }
6316 #else
6317                 (void)sprintf(tmp, "Killed on Level %d", p_ptr->current_floor_ptr->dun_level);
6318                 center_string(buf, tmp);
6319                 put_str(buf, 14, 11);
6320
6321                 roff_to_buf(format("by %s.", p_ptr->died_from), GRAVE_LINE_WIDTH + 1, tmp, sizeof tmp);
6322                 center_string(buf, tmp);
6323                 put_str(buf, 15, 11);
6324                 t = tmp + strlen(tmp) + 1;
6325                 if (*t)
6326                 {
6327                         strcpy(dummy, t); /* 2nd line */
6328                         if (*(t + strlen(t) + 1)) /* Does 3rd line exist? */
6329                         {
6330                                 int dummy_len = strlen(dummy);
6331                                 strcpy(dummy + MIN(dummy_len, GRAVE_LINE_WIDTH - 3), "...");
6332                         }
6333                         center_string(buf, dummy);
6334                         put_str(buf, 16, 11);
6335                 }
6336 #endif
6337
6338                 (void)sprintf(tmp, "%-.24s", ctime(&ct));
6339                 center_string(buf, tmp);
6340                 put_str(buf, 17, 11);
6341                 msg_format(_("さようなら、%s!", "Goodbye, %s!"), p_ptr->name);
6342         }
6343 }
6344
6345
6346 /*!
6347  * @brief 死亡、引退時の簡易ステータス表示 /
6348  * Display some character info
6349  * @return なし
6350  */
6351 void show_info(void)
6352 {
6353         int             i, j, k, l;
6354         object_type *o_ptr;
6355         store_type              *st_ptr;
6356
6357         /* Hack -- Know everything in the inven/equip */
6358         for (i = 0; i < INVEN_TOTAL; i++)
6359         {
6360                 o_ptr = &p_ptr->inventory_list[i];
6361                 if (!o_ptr->k_idx) continue;
6362
6363                 /* Aware and Known */
6364                 object_aware(o_ptr);
6365                 object_known(o_ptr);
6366         }
6367
6368         for (i = 1; i < max_towns; i++)
6369         {
6370                 st_ptr = &town_info[i].store[STORE_HOME];
6371
6372                 /* Hack -- Know everything in the home */
6373                 for (j = 0; j < st_ptr->stock_num; j++)
6374                 {
6375                         o_ptr = &st_ptr->stock[j];
6376                         if (!o_ptr->k_idx) continue;
6377
6378                         /* Aware and Known */
6379                         object_aware(o_ptr);
6380                         object_known(o_ptr);
6381                 }
6382         }
6383
6384         /* Hack -- Recalculate bonuses */
6385         p_ptr->update |= (PU_BONUS);
6386         handle_stuff();
6387
6388         /* Flush all input keys */
6389         flush();
6390
6391         msg_erase();
6392
6393
6394         /* Describe options */
6395         prt(_("キャラクターの記録をファイルに書き出すことができます。", "You may now dump a character record to one or more files."), 21, 0);
6396         prt(_("リターンキーでキャラクターを見ます。ESCで中断します。", "Then, hit RETURN to see the character, or ESC to abort."), 22, 0);
6397
6398         /* Dump character records as requested */
6399         while (TRUE)
6400         {
6401                 char out_val[160];
6402
6403                 /* Prompt */
6404                 put_str(_("ファイルネーム: ", "Filename: "), 23, 0);
6405
6406                 /* Default */
6407                 strcpy(out_val, "");
6408
6409                 /* Ask for filename (or abort) */
6410                 if (!askfor(out_val, 60)) return;
6411
6412                 /* Return means "show on screen" */
6413                 if (!out_val[0]) break;
6414                 screen_save();
6415
6416                 /* Dump a character file */
6417                 (void)file_character(out_val);
6418                 screen_load();
6419         }
6420
6421         update_playtime();
6422         display_player(p_ptr, 0);
6423
6424         prt(_("何かキーを押すとさらに情報が続きます (ESCで中断): ", "Hit any key to see more information (ESC to abort): "), 23, 0);
6425
6426         /* Allow abort at this point */
6427         if (inkey() == ESCAPE) return;
6428
6429         /* Equipment -- if any */
6430         if (p_ptr->equip_cnt)
6431         {
6432                 Term_clear();
6433                 (void)show_equip(0, USE_FULL, 0);
6434                 prt(_("装備していたアイテム: -続く-", "You are using: -more-"), 0, 0);
6435
6436                 if (inkey() == ESCAPE) return;
6437         }
6438
6439         /* Inventory -- if any */
6440         if (p_ptr->inven_cnt)
6441         {
6442                 Term_clear();
6443                 (void)show_inven(0, USE_FULL, 0);
6444                 prt(_("持っていたアイテム: -続く-", "You are carrying: -more-"), 0, 0);
6445
6446                 if (inkey() == ESCAPE) return;
6447         }
6448
6449         /* Homes in the different towns */
6450         for (l = 1; l < max_towns; l++)
6451         {
6452                 st_ptr = &town_info[l].store[STORE_HOME];
6453
6454                 /* Home -- if anything there */
6455                 if (st_ptr->stock_num)
6456                 {
6457                         /* Display contents of the home */
6458                         for (k = 0, i = 0; i < st_ptr->stock_num; k++)
6459                         {
6460                                 Term_clear();
6461
6462                                 /* Show 12 items */
6463                                 for (j = 0; (j < 12) && (i < st_ptr->stock_num); j++, i++)
6464                                 {
6465                                         GAME_TEXT o_name[MAX_NLEN];
6466                                         char tmp_val[80];
6467
6468                                         /* Acquire item */
6469                                         o_ptr = &st_ptr->stock[i];
6470
6471                                         /* Print header, clear line */
6472                                         sprintf(tmp_val, "%c) ", I2A(j));
6473                                         prt(tmp_val, j+2, 4);
6474
6475                                         /* Display object description */
6476                                         object_desc(o_name, o_ptr, 0);
6477                                         c_put_str(tval_to_attr[o_ptr->tval], o_name, j+2, 7);
6478                                 }
6479
6480                                 prt(format(_("我が家に置いてあったアイテム ( %d ページ): -続く-", "Your home contains (page %d): -more-"), k+1), 0, 0);
6481
6482                                 /* Wait for it */
6483                                 if (inkey() == ESCAPE) return;
6484                         }
6485                 }
6486         }
6487 }
6488
6489
6490 /*!
6491  * @brief 異常発生時のゲーム緊急終了処理 /
6492  * Handle abrupt death of the visual system
6493  * @return なし
6494  * @details
6495  * <pre>
6496  * This routine is called only in very rare situations, and only
6497  * by certain visual systems, when they experience fatal errors.
6498  * XXX XXX Hack -- clear the death flag when creating a HANGUP
6499  * save file so that player can see tombstone when restart.
6500  * </pre>
6501  */
6502 void exit_game_panic(void)
6503 {
6504         /* If nothing important has happened, just quit */
6505         if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(_("緊急事態", "panic"));
6506
6507         /* Mega-Hack -- see "msg_print()" */
6508         msg_flag = FALSE;
6509
6510         /* Clear the top line */
6511         prt("", 0, 0);
6512
6513         /* Hack -- turn off some things */
6514         disturb(p_ptr, TRUE, TRUE);
6515
6516         /* Mega-Hack -- Delay death */
6517         if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
6518
6519         /* Hardcode panic save */
6520         p_ptr->panic_save = 1;
6521
6522         /* Forbid suspend */
6523         signals_ignore_tstp();
6524
6525         /* Indicate panic save */
6526         (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
6527
6528         /* Panic save, or get worried */
6529         if (!save_player()) quit(_("緊急セーブ失敗!", "panic save failed!"));
6530
6531         /* Successful panic save */
6532         quit(_("緊急セーブ成功!", "panic save succeeded!"));
6533 }
6534
6535
6536 /*!
6537  * @brief ファイルからランダムに行を一つ取得する /
6538  * Get a random line from a file
6539  * @param file_name ファイル名
6540  * @param entry 特定条件時のN:タグヘッダID
6541  * @param output 出力先の文字列参照ポインタ
6542  * @return エラーコード
6543  * @details
6544  * <pre>
6545  * Based on the monster speech patch by Matt Graham,
6546  * </pre>
6547  */
6548 errr get_rnd_line(concptr file_name, int entry, char *output)
6549 {
6550         FILE    *fp;
6551         char    buf[1024];
6552         int     counter, test;
6553         int     line_num = 0;
6554
6555         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, file_name);
6556         fp = my_fopen(buf, "r");
6557
6558         /* Failed */
6559         if (!fp) return -1;
6560
6561         /* Find the entry of the monster */
6562         while (TRUE)
6563         {
6564                 /* Get a line from the file */
6565                 if (my_fgets(fp, buf, sizeof(buf)) == 0)
6566                 {
6567                         /* Count the lines */
6568                         line_num++;
6569
6570                         /* Look for lines starting with 'N:' */
6571                         if ((buf[0] == 'N') && (buf[1] == ':'))
6572                         {
6573                                 /* Allow default lines */
6574                                 if (buf[2] == '*')
6575                                 {
6576                                         /* Default lines */
6577                                         break;
6578                                 }
6579                                 else if (buf[2] == 'M')
6580                                 {
6581                                         if (r_info[entry].flags1 & RF1_MALE) break;
6582                                 }
6583                                 else if (buf[2] == 'F')
6584                                 {
6585                                         if (r_info[entry].flags1 & RF1_FEMALE) break;
6586                                 }
6587                                 /* Get the monster number */
6588                                 else if (sscanf(&(buf[2]), "%d", &test) != EOF)
6589                                 {
6590                                         /* Is it the right number? */
6591                                         if (test == entry) break;
6592                                 }
6593                                 else
6594                                 {
6595                                         /* Error while converting the number */
6596                                         msg_format("Error in line %d of %s!", line_num, file_name);
6597                                         my_fclose(fp);
6598                                         return -1;
6599                                 }
6600                         }
6601                 }
6602                 else
6603                 {
6604                         /* Reached end of file */
6605                         my_fclose(fp);
6606                         return -1;
6607                 }
6608         }
6609
6610         /* Get the random line */
6611         for (counter = 0; ; counter++)
6612         {
6613                 while (TRUE)
6614                 {
6615                         test = my_fgets(fp, buf, sizeof(buf));
6616
6617                         /* Count the lines */
6618                         /* line_num++; No more needed */
6619
6620                         if (!test)
6621                         {
6622                                 /* Ignore lines starting with 'N:' */
6623                                 if ((buf[0] == 'N') && (buf[1] == ':')) continue;
6624
6625                                 if (buf[0] != '#') break;
6626                         }
6627                         else break;
6628                 }
6629
6630                 /* Abort */
6631                 if (!buf[0]) break;
6632
6633                 /* Copy the line */
6634                 if (one_in_(counter + 1)) strcpy(output, buf);
6635         }
6636         my_fclose(fp);
6637
6638         /* Success */
6639         return counter ? 0 : -1;
6640 }
6641
6642
6643 #ifdef JP
6644 /*!
6645  * @brief ファイルからランダムに行を一つ取得する(日本語文字列のみ) /
6646  * @param file_name ファイル名
6647  * @param entry 特定条件時のN:タグヘッダID
6648  * @param output 出力先の文字列参照ポインタ
6649  * @param count 試行回数
6650  * @return エラーコード
6651  * @details
6652  */
6653 errr get_rnd_line_jonly(concptr file_name, int entry, char *output, int count)
6654 {
6655         int  i, j, kanji;
6656         errr result = 1;
6657
6658         for (i = 0; i < count; i++)
6659         {
6660                 result = get_rnd_line(file_name, entry, output);
6661                 if (result) break;
6662                 kanji = 0;
6663                 for (j = 0; output[j]; j++) kanji |= iskanji(output[j]);
6664                 if (kanji) break;
6665         }
6666         return result;
6667 }
6668 #endif
6669
6670 /*!
6671  * @brief 自動拾いファイルを読み込む /
6672  * @param name ファイル名
6673  * @details
6674  */
6675 errr process_autopick_file(concptr name)
6676 {
6677         char buf[1024];
6678
6679         errr err = 0;
6680         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
6681
6682         err = process_pref_file_aux(buf, PREF_TYPE_AUTOPICK);
6683         return (err);
6684 }
6685
6686
6687 /*!
6688  * @brief プレイヤーの生い立ちファイルを読み込む /
6689  * Process file for player's history editor.
6690  * @param name ファイル名
6691  * @return エラーコード
6692  * @details
6693  */
6694 errr process_histpref_file(concptr name)
6695 {
6696         char buf[1024];
6697         errr err = 0;
6698         bool old_character_xtra = current_world_ptr->character_xtra;
6699         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
6700
6701         /* Hack -- prevent modification birth options in this file */
6702         current_world_ptr->character_xtra = TRUE;
6703
6704         err = process_pref_file_aux(buf, PREF_TYPE_HISTPREF);
6705
6706         current_world_ptr->character_xtra = old_character_xtra;
6707         return (err);
6708 }
6709
6710 /*!
6711  * @brief ファイル位置をシーク /
6712  * @param fd ファイルディスクリプタ
6713  * @param where ファイルバイト位置
6714  * @param flag FALSEならば現ファイルを超えた位置へシーク時エラー、TRUEなら足りない間を0で埋め尽くす
6715  * @return エラーコード
6716  * @details
6717  */
6718 static errr counts_seek(int fd, u32b where, bool flag)
6719 {
6720         huge seekpoint;
6721         char temp1[128], temp2[128];
6722         u32b zero_header[3] = {0L, 0L, 0L};
6723         int i;
6724
6725 #ifdef SAVEFILE_USE_UID
6726         (void)sprintf(temp1, "%d.%s.%d%d%d", p_ptr->player_uid, savefile_base, p_ptr->pclass, p_ptr->pseikaku, p_ptr->age);
6727 #else
6728         (void)sprintf(temp1, "%s.%d%d%d", savefile_base, p_ptr->pclass, p_ptr->pseikaku, p_ptr->age);
6729 #endif
6730         for (i = 0; temp1[i]; i++)
6731                 temp1[i] ^= (i+1) * 63;
6732
6733         seekpoint = 0;
6734         while (1)
6735         {
6736                 if (fd_seek(fd, seekpoint + 3 * sizeof(u32b)))
6737                         return 1;
6738                 if (fd_read(fd, (char*)(temp2), sizeof(temp2)))
6739                 {
6740                         if (!flag)
6741                                 return 1;
6742                         /* add new name */
6743                         fd_seek(fd, seekpoint);
6744                         fd_write(fd, (char*)zero_header, 3*sizeof(u32b));
6745                         fd_write(fd, (char*)(temp1), sizeof(temp1));
6746                         break;
6747                 }
6748
6749                 if (strcmp(temp1, temp2) == 0)
6750                         break;
6751
6752                 seekpoint += 128 + 3 * sizeof(u32b);
6753         }
6754
6755         return fd_seek(fd, seekpoint + where * sizeof(u32b));
6756 }
6757
6758 /*!
6759  * @brief ファイル位置を読み込む
6760  * @param where ファイルバイト位置
6761  * @return エラーコード
6762  * @details
6763  */
6764 u32b counts_read(int where)
6765 {
6766         int fd;
6767         u32b count = 0;
6768         char buf[1024];
6769
6770         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, _("z_info_j.raw", "z_info.raw"));
6771         fd = fd_open(buf, O_RDONLY);
6772
6773         if (counts_seek(fd, where, FALSE) ||
6774             fd_read(fd, (char*)(&count), sizeof(u32b)))
6775                 count = 0;
6776
6777         (void)fd_close(fd);
6778
6779         return count;
6780 }
6781
6782 /*!
6783  * @brief ファイル位置に書き込む /
6784  * @param where ファイルバイト位置
6785  * @param count 書き込む値
6786  * @return エラーコード
6787  * @details
6788  */
6789 errr counts_write(int where, u32b count)
6790 {
6791         int fd;
6792         char buf[1024];
6793         errr err;
6794
6795         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, _("z_info_j.raw", "z_info.raw"));
6796
6797         /* Grab permissions */
6798         safe_setuid_grab();
6799
6800         fd = fd_open(buf, O_RDWR);
6801
6802         /* Drop permissions */
6803         safe_setuid_drop();
6804
6805         if (fd < 0)
6806         {
6807                 /* File type is "DATA" */
6808                 FILE_TYPE(FILE_TYPE_DATA);
6809
6810                 /* Grab permissions */
6811                 safe_setuid_grab();
6812
6813                 /* Create a new high score file */
6814                 fd = fd_make(buf, 0644);
6815
6816                 /* Drop permissions */
6817                 safe_setuid_drop();
6818         }
6819
6820         /* Grab permissions */
6821         safe_setuid_grab();
6822
6823         err = fd_lock(fd, F_WRLCK);
6824
6825         /* Drop permissions */
6826         safe_setuid_drop();
6827
6828         if (err) return 1;
6829
6830         counts_seek(fd, where, TRUE);
6831         fd_write(fd, (char*)(&count), sizeof(u32b));
6832
6833         /* Grab permissions */
6834         safe_setuid_grab();
6835
6836         err = fd_lock(fd, F_UNLCK);
6837
6838         /* Drop permissions */
6839         safe_setuid_drop();
6840
6841         if (err) return 1;
6842
6843         (void)fd_close(fd);
6844
6845         return 0;
6846 }
6847
6848
6849 #ifdef HANDLE_SIGNALS
6850
6851
6852 #include <signal.h>
6853
6854
6855 /*!
6856  * @brief OSからのシグナルを受けてサスペンド状態に入る /
6857  * Handle signals -- suspend
6858  * @param sig 受け取ったシグナル
6859  * @details
6860  * Actually suspend the game, and then resume cleanly
6861  */
6862 static void handle_signal_suspend(int sig)
6863 {
6864         /* Disable handler */
6865         (void)signal(sig, SIG_IGN);
6866
6867 #ifdef SIGSTOP
6868
6869         /* Flush output */
6870         Term_fresh();
6871
6872         /* Suspend the "Term" */
6873         Term_xtra(TERM_XTRA_ALIVE, 0);
6874
6875         /* Suspend ourself */
6876         (void)kill(0, SIGSTOP);
6877
6878         /* Resume the "Term" */
6879         Term_xtra(TERM_XTRA_ALIVE, 1);
6880
6881         /* Redraw the term */
6882         Term_redraw();
6883
6884         /* Flush the term */
6885         Term_fresh();
6886
6887 #endif
6888
6889         /* Restore handler */
6890         (void)signal(sig, handle_signal_suspend);
6891 }
6892
6893
6894 /*!
6895  * @brief OSからのシグナルを受けて中断、終了する /
6896  * Handle signals -- simple (interrupt and quit)
6897  * @param sig 受け取ったシグナル
6898  * @details
6899  * <pre>
6900  * This function was causing a *huge* number of problems, so it has
6901  * been simplified greatly.  We keep a global variable which counts
6902  * the number of times the user attempts to kill the process, and
6903  * we commit suicide if the user does this a certain number of times.
6904  * We attempt to give "feedback" to the user as he approaches the
6905  * suicide thresh-hold, but without penalizing accidental keypresses.
6906  * To prevent messy accidents, we should reset this global variable
6907  * whenever the user enters a keypress, or something like that.
6908  * </pre>
6909  */
6910 static void handle_signal_simple(int sig)
6911 {
6912         /* Disable handler */
6913         (void)signal(sig, SIG_IGN);
6914
6915
6916         /* Nothing to save, just quit */
6917         if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(NULL);
6918
6919
6920         /* Count the signals */
6921         signal_count++;
6922
6923
6924         /* Terminate dead characters */
6925         if (p_ptr->is_dead)
6926         {
6927                 /* Mark the savefile */
6928                 (void)strcpy(p_ptr->died_from, _("強制終了", "Abortion"));
6929
6930                 forget_lite(p_ptr->current_floor_ptr);
6931                 forget_view(p_ptr->current_floor_ptr);
6932                 clear_mon_lite(p_ptr->current_floor_ptr);
6933
6934                 /* Close stuff */
6935                 close_game();
6936
6937                 /* Quit */
6938                 quit(_("強制終了", "interrupt"));
6939         }
6940
6941         /* Allow suicide (after 5) */
6942         else if (signal_count >= 5)
6943         {
6944                 /* Cause of "death" */
6945                 (void)strcpy(p_ptr->died_from, _("強制終了中", "Interrupting"));
6946
6947                 forget_lite(p_ptr->current_floor_ptr);
6948                 forget_view(p_ptr->current_floor_ptr);
6949                 clear_mon_lite(p_ptr->current_floor_ptr);
6950
6951                 /* Stop playing */
6952                 p_ptr->playing = FALSE;
6953
6954                 /* Suicide */
6955                 p_ptr->is_dead = TRUE;
6956                 p_ptr->leaving = TRUE;
6957
6958                 /* Close stuff */
6959                 close_game();
6960
6961                 /* Quit */
6962                 quit(_("強制終了", "interrupt"));
6963         }
6964
6965         /* Give warning (after 4) */
6966         else if (signal_count >= 4)
6967         {
6968                 /* Make a noise */
6969                 Term_xtra(TERM_XTRA_NOISE, 0);
6970
6971                 /* Clear the top line */
6972                 Term_erase(0, 0, 255);
6973
6974                 /* Display the cause */
6975                 Term_putstr(0, 0, -1, TERM_WHITE, _("熟慮の上の自殺!", "Contemplating suicide!"));
6976
6977                 Term_fresh();
6978         }
6979
6980         /* Give warning (after 2) */
6981         else if (signal_count >= 2)
6982         {
6983                 /* Make a noise */
6984                 Term_xtra(TERM_XTRA_NOISE, 0);
6985         }
6986
6987         /* Restore handler */
6988         (void)signal(sig, handle_signal_simple);
6989 }
6990
6991
6992 /*!
6993  * @brief OSからのシグナルを受けて強制終了する /
6994  * Handle signal -- abort, kill, etc
6995  * @param sig 受け取ったシグナル
6996  * @return なし
6997  * @details
6998  * <pre>
6999  * This function was causing a *huge* number of problems, so it has
7000  * been simplified greatly.  We keep a global variable which counts
7001  * the number of times the user attempts to kill the process, and
7002  * we commit suicide if the user does this a certain number of times.
7003  * We attempt to give "feedback" to the user as he approaches the
7004  * suicide thresh-hold, but without penalizing accidental keypresses.
7005  * To prevent messy accidents, we should reset this global variable
7006  * whenever the user enters a keypress, or something like that.
7007  * </pre>
7008  */
7009 static void handle_signal_abort(int sig)
7010 {
7011         int wid, hgt;
7012
7013         Term_get_size(&wid, &hgt);
7014
7015         /* Disable handler */
7016         (void)signal(sig, SIG_IGN);
7017
7018
7019         /* Nothing to save, just quit */
7020         if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(NULL);
7021
7022
7023         forget_lite(p_ptr->current_floor_ptr);
7024         forget_view(p_ptr->current_floor_ptr);
7025         clear_mon_lite(p_ptr->current_floor_ptr);
7026
7027         /* Clear the bottom line */
7028         Term_erase(0, hgt - 1, 255);
7029
7030         /* Give a warning */
7031         Term_putstr(0, hgt - 1, -1, TERM_RED,
7032         _("恐ろしいソフトのバグが飛びかかってきた!", "A gruesome software bug LEAPS out at you!"));
7033
7034
7035         Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ...", "Panic save..."));
7036
7037         exe_write_diary(p_ptr, NIKKI_GAMESTART, 0, _("----ゲーム異常終了----", "---- Panic Save and Abort Game ----"));
7038
7039         /* Flush output */
7040         Term_fresh();
7041
7042         /* Panic Save */
7043         p_ptr->panic_save = 1;
7044
7045         /* Panic save */
7046         (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
7047
7048         /* Forbid suspend */
7049         signals_ignore_tstp();
7050
7051         /* Attempt to save */
7052         if (save_player())
7053         {
7054                 Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ成功!", "Panic save succeeded!"));
7055         }
7056
7057         /* Save failed */
7058         else
7059         {
7060                 Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ失敗!", "Panic save failed!"));
7061         }
7062
7063         /* Flush output */
7064         Term_fresh();
7065
7066         /* Quit */
7067         quit(_("ソフトのバグ", "software bug"));
7068 }
7069
7070 /*!
7071  * @brief OSからのSIGTSTPシグナルを無視する関数 /
7072  * Ignore SIGTSTP signals (keyboard suspend)
7073  * @return なし
7074  * @details
7075  */
7076 void signals_ignore_tstp(void)
7077 {
7078
7079 #ifdef SIGTSTP
7080         (void)signal(SIGTSTP, SIG_IGN);
7081 #endif
7082
7083 }
7084
7085 /*!
7086  * @brief OSからのSIGTSTPシグナルハンドラ /
7087  * Handle SIGTSTP signals (keyboard suspend)
7088  * @return なし
7089  * @details
7090  */
7091 void signals_handle_tstp(void)
7092 {
7093
7094 #ifdef SIGTSTP
7095         (void)signal(SIGTSTP, handle_signal_suspend);
7096 #endif
7097
7098 }
7099
7100
7101 /*!
7102  * @brief OSからのシグナルハンドルを初期化する /
7103  * Prepare to handle the relevant signals
7104  * @return なし
7105  * @details
7106  */
7107 void signals_init(void)
7108 {
7109
7110 #ifdef SIGHUP
7111         (void)signal(SIGHUP, SIG_IGN);
7112 #endif
7113
7114
7115 #ifdef SIGTSTP
7116         (void)signal(SIGTSTP, handle_signal_suspend);
7117 #endif
7118
7119
7120 #ifdef SIGINT
7121         (void)signal(SIGINT, handle_signal_simple);
7122 #endif
7123
7124 #ifdef SIGQUIT
7125         (void)signal(SIGQUIT, handle_signal_simple);
7126 #endif
7127
7128
7129 #ifdef SIGFPE
7130         (void)signal(SIGFPE, handle_signal_abort);
7131 #endif
7132
7133 #ifdef SIGILL
7134         (void)signal(SIGILL, handle_signal_abort);
7135 #endif
7136
7137 #ifdef SIGTRAP
7138         (void)signal(SIGTRAP, handle_signal_abort);
7139 #endif
7140
7141 #ifdef SIGIOT
7142         (void)signal(SIGIOT, handle_signal_abort);
7143 #endif
7144
7145 #ifdef SIGKILL
7146         (void)signal(SIGKILL, handle_signal_abort);
7147 #endif
7148
7149 #ifdef SIGBUS
7150         (void)signal(SIGBUS, handle_signal_abort);
7151 #endif
7152
7153 #ifdef SIGSEGV
7154         (void)signal(SIGSEGV, handle_signal_abort);
7155 #endif
7156
7157 #ifdef SIGTERM
7158         (void)signal(SIGTERM, handle_signal_abort);
7159 #endif
7160
7161 #ifdef SIGPIPE
7162         (void)signal(SIGPIPE, handle_signal_abort);
7163 #endif
7164
7165 #ifdef SIGEMT
7166         (void)signal(SIGEMT, handle_signal_abort);
7167 #endif
7168
7169 #ifdef SIGDANGER
7170         (void)signal(SIGDANGER, handle_signal_abort);
7171 #endif
7172
7173 #ifdef SIGSYS
7174         (void)signal(SIGSYS, handle_signal_abort);
7175 #endif
7176
7177 #ifdef SIGXCPU
7178         (void)signal(SIGXCPU, handle_signal_abort);
7179 #endif
7180
7181 #ifdef SIGPWR
7182         (void)signal(SIGPWR, handle_signal_abort);
7183 #endif
7184
7185 }
7186
7187
7188 #else   /* HANDLE_SIGNALS */
7189
7190
7191 /*!
7192  * @brief ダミー /
7193  * Do nothing
7194  */
7195 void signals_ignore_tstp(void)
7196 {
7197 }
7198
7199 /*!
7200  * @brief ダミー /
7201  * Do nothing
7202  */
7203 void signals_handle_tstp(void)
7204 {
7205 }
7206
7207 /*!
7208  * @brief ダミー /
7209  * Do nothing
7210  */
7211 void signals_init(void)
7212 {
7213 }
7214 #endif  /* HANDLE_SIGNALS */