OSDN Git Service

[Refactor] #38997 show_inven() に player_type * 引数を追加 / Added player_type * argument...
[hengband/hengband.git] / src / files.c
1 /*!
2  * @file files.c
3  * @brief ファイル入出力管理 / Purpose: code dealing with files (and death)
4  * @date 2014/01/28
5  * @author
6  * <pre>
7  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  * 2014 Deskull rearranged comment for Doxygen.\n
12  * </pre>
13  */
14
15
16 #include "angband.h"
17 #include "util.h"
18 #include "files.h"
19 #include "core.h"
20
21 #include "birth.h"
22 #include "files.h"
23
24 #include "bldg.h"
25
26 #include "cmd-magiceat.h"
27 #include "cmd-dump.h"
28 #include "world.h"
29 #include "player-inventory.h"
30 #include "player-race.h"
31 #include "player-status.h"
32 #include "player-move.h"
33 #include "player-class.h"
34 #include "player-skill.h"
35 #include "player-personality.h"
36 #include "player-sex.h"
37 #include "player-effects.h"
38 #include "sort.h"
39 #include "mutation.h"
40 #include "quest.h"
41 #include "store.h"
42 #include "artifact.h"
43 #include "avatar.h"
44 #include "shoot.h"
45 #include "patron.h"
46 #include "monster.h"
47 #include "monster-process.h"
48 #include "monster-status.h"
49 #include "object-flavor.h"
50 #include "object-hook.h"
51 #include "realm.h"
52 #include "realm-hex.h"
53 #include "cmd-pet.h"
54 #include "spells.h"
55 #include "term.h"
56 #include "view-mainwindow.h"
57 #include "floor-events.h"
58 #include "floor-town.h"
59 #include "dungeon-file.h"
60 #include "init.h"
61 #include "monster-spell.h"
62 #include "floor.h"
63 #include "dungeon.h"
64 #include "melee.h"
65 #include "objectkind.h"
66 #include "autopick.h"
67 #include "save.h"
68 #include "realm-song.h"
69
70 concptr ANGBAND_DIR; //!< Path name: The main "lib" directory This variable is not actually used anywhere in the code
71 concptr ANGBAND_DIR_APEX; //!< High score files (binary) These files may be portable between platforms
72 concptr ANGBAND_DIR_BONE; //!< Bone files for player ghosts (ascii) These files are portable between platforms
73 concptr ANGBAND_DIR_DATA; //!< Binary image files for the "*_info" arrays (binary) These files are not portable between platforms
74 concptr ANGBAND_DIR_EDIT; //!< Textual template files for the "*_info" arrays (ascii) These files are portable between platforms
75 concptr ANGBAND_DIR_SCRIPT; //!< Script files These files are portable between platforms.
76 concptr ANGBAND_DIR_FILE; //!< Various extra files (ascii) These files may be portable between platforms
77 concptr ANGBAND_DIR_HELP; //!< Help files (normal) for the online help (ascii) These files are portable between platforms
78 concptr ANGBAND_DIR_INFO; //!< Help files (spoilers) for the online help (ascii) These files are portable between platforms
79 concptr ANGBAND_DIR_PREF; //!< Default user "preference" files (ascii) These files are rarely portable between platforms
80 concptr ANGBAND_DIR_SAVE; //!< Savefiles for current characters (binary)
81 concptr ANGBAND_DIR_USER; //!< User "preference" files (ascii) These files are rarely portable between platforms
82 concptr ANGBAND_DIR_XTRA; //!< Various extra files (binary) These files are rarely portable between platforms
83
84 s16b signal_count;              /* Hack -- Count interupts */
85
86 /*
87  * Buffer to hold the current savefile name
88  * 'savefile' holds full path name. 'savefile_base' holds only base name.
89  */
90 char savefile[1024];
91 char savefile_base[40];
92
93
94
95 /*
96  * You may or may not want to use the following "#undef".
97  */
98 /* #undef _POSIX_SAVED_IDS */
99
100
101 /*!
102  * @brief ファイルのドロップパーミッションチェック / Hack -- drop permissions
103  */
104 void safe_setuid_drop(void)
105 {
106
107 #ifdef SET_UID
108
109 # ifdef SAFE_SETUID
110
111 #  ifdef SAFE_SETUID_POSIX
112
113         if (setuid(getuid()) != 0)
114         {
115                 quit(_("setuid(): 正しく許可が取れません!", "setuid(): cannot set permissions correctly!"));
116         }
117         if (setgid(getgid()) != 0)
118         {
119                 quit(_("setgid(): 正しく許可が取れません!", "setgid(): cannot set permissions correctly!"));
120         }
121
122 #  else
123
124         if (setreuid(geteuid(), getuid()) != 0)
125         {
126                 quit(_("setreuid(): 正しく許可が取れません!", "setreuid(): cannot set permissions correctly!"));
127         }
128         if (setregid(getegid(), getgid()) != 0)
129         {
130                 quit(_("setregid(): 正しく許可が取れません!", "setregid(): cannot set permissions correctly!"));
131         }
132
133 #  endif
134
135 # endif
136
137 #endif
138
139 }
140
141
142 /*!
143  * @brief ファイルのグラブパーミッションチェック / Hack -- grab permissions
144  */
145 void safe_setuid_grab(void)
146 {
147
148 #ifdef SET_UID
149
150 # ifdef SAFE_SETUID
151
152 #  ifdef SAFE_SETUID_POSIX
153
154         if (setuid(p_ptr->player_egid) != 0)
155         {
156                 quit(_("setuid(): 正しく許可が取れません!", "setuid(): cannot set permissions correctly!"));
157         }
158         if (setgid(p_ptr->player_egid) != 0)
159         {
160                 quit(_("setgid(): 正しく許可が取れません!", "setgid(): cannot set permissions correctly!"));
161         }
162
163 #  else
164
165         if (setreuid(geteuid(), getuid()) != 0)
166         {
167                 quit(_("setreuid(): 正しく許可が取れません!", "setreuid(): cannot set permissions correctly!"));
168         }
169         if (setregid(getegid(), getgid()) != 0)
170         {
171                 quit(_("setregid(): 正しく許可が取れません!", "setregid(): cannot set permissions correctly!"));
172         }
173
174 #  endif /* SAFE_SETUID_POSIX */
175
176 # endif /* SAFE_SETUID */
177
178 #endif /* SET_UID */
179
180 }
181
182
183 /*!
184  * @brief 各種データテキストをトークン単位に分解する / Extract the first few "tokens" from a buffer
185  * @param buf データテキストの参照ポインタ
186  * @param num トークンの数
187  * @param tokens トークンを保管する文字列参照ポインタ配列
188  * @param mode オプション
189  * @return 解釈した文字列数
190  * @details
191  * <pre>
192  * This function uses "colon" and "slash" as the delimeter characters.
193  * We never extract more than "num" tokens.  The "last" token may include
194  * "delimeter" characters, allowing the buffer to include a "string" token.
195  * We save pointers to the tokens in "tokens", and return the number found.
196  * Hack -- Attempt to handle the 'c' character formalism
197  * Hack -- An empty buffer, or a final delimeter, yields an "empty" token.
198  * Hack -- We will always extract at least one token
199  * </pre>
200  */
201 s16b tokenize(char *buf, s16b num, char **tokens, BIT_FLAGS mode)
202 {
203         s16b i = 0;
204
205         char *s = buf;
206
207
208         /* Process */
209         while (i < num - 1)
210         {
211                 char *t;
212
213                 /* Scan the string */
214                 for (t = s; *t; t++)
215                 {
216                         /* Found a delimiter */
217                         if ((*t == ':') || (*t == '/')) break;
218
219                         /* Handle single quotes */
220                         if ((mode & TOKENIZE_CHECKQUOTE) && (*t == '\''))
221                         {
222                                 /* Advance */
223                                 t++;
224
225                                 /* Handle backslash */
226                                 if (*t == '\\') t++;
227
228                                 /* Require a character */
229                                 if (!*t) break;
230
231                                 /* Advance */
232                                 t++;
233
234                                 /* Hack -- Require a close quote */
235                                 if (*t != '\'') *t = '\'';
236                         }
237
238                         /* Handle back-slash */
239                         if (*t == '\\') t++;
240                 }
241
242                 /* Nothing left */
243                 if (!*t) break;
244
245                 /* Nuke and advance */
246                 *t++ = '\0';
247
248                 /* Save the token */
249                 tokens[i++] = s;
250
251                 /* Advance */
252                 s = t;
253         }
254
255         /* Save the token */
256         tokens[i++] = s;
257
258         /* Number found */
259         return (i);
260 }
261
262
263 /* A number with a name */
264 typedef struct named_num named_num;
265
266 struct named_num
267 {
268         concptr name;           /* The name of this thing */
269         int num;                        /* A number associated with it */
270 };
271
272
273 /* Index of spell type names */
274 static named_num gf_desc[] =
275 {
276         {"GF_ELEC",                             GF_ELEC                         },
277         {"GF_POIS",                             GF_POIS                         },
278         {"GF_ACID",                             GF_ACID                         },
279         {"GF_COLD",                             GF_COLD                         },
280         {"GF_FIRE",                                     GF_FIRE                         },
281         {"GF_PSY_SPEAR",                        GF_PSY_SPEAR            },
282         {"GF_MISSILE",                          GF_MISSILE                      },
283         {"GF_ARROW",                            GF_ARROW                        },
284         {"GF_PLASMA",                           GF_PLASMA                       },
285         {"GF_WATER",                            GF_WATER                        },
286         {"GF_LITE",                                     GF_LITE                         },
287         {"GF_DARK",                                     GF_DARK                         },
288         {"GF_LITE_WEAK",                        GF_LITE_WEAK            },
289         {"GF_DARK_WEAK",                        GF_DARK_WEAK            },
290         {"GF_SHARDS",                           GF_SHARDS                       },
291         {"GF_SOUND",                            GF_SOUND                        },
292         {"GF_CONFUSION",                        GF_CONFUSION            },
293         {"GF_FORCE",                            GF_FORCE                        },
294         {"GF_INERTIA",                          GF_INERTIAL                     },
295         {"GF_MANA",                                     GF_MANA                         },
296         {"GF_METEOR",                           GF_METEOR                       },
297         {"GF_ICE",                                      GF_ICE                          },
298         {"GF_CHAOS",                            GF_CHAOS                        },
299         {"GF_NETHER",                           GF_NETHER                       },
300         {"GF_DISENCHANT",                       GF_DISENCHANT           },
301         {"GF_NEXUS",                            GF_NEXUS                        },
302         {"GF_TIME",                                     GF_TIME                         },
303         {"GF_GRAVITY",                          GF_GRAVITY                      },
304         {"GF_KILL_WALL",                        GF_KILL_WALL            },
305         {"GF_KILL_DOOR",                        GF_KILL_DOOR            },
306         {"GF_KILL_TRAP",                        GF_KILL_TRAP            },
307         {"GF_MAKE_WALL",                        GF_MAKE_WALL            },
308         {"GF_MAKE_DOOR",                        GF_MAKE_DOOR            },
309         {"GF_MAKE_TRAP",                        GF_MAKE_TRAP            },
310         {"GF_MAKE_TREE",                        GF_MAKE_TREE            },
311         {"GF_OLD_CLONE",                        GF_OLD_CLONE            },
312         {"GF_OLD_POLY",                         GF_OLD_POLY                     },
313         {"GF_OLD_HEAL",                         GF_OLD_HEAL                     },
314         {"GF_OLD_SPEED",                        GF_OLD_SPEED            },
315         {"GF_OLD_SLOW",                         GF_OLD_SLOW                     },
316         {"GF_OLD_CONF",                         GF_OLD_CONF                     },
317         {"GF_OLD_SLEEP",                        GF_OLD_SLEEP            },
318         {"GF_HYPODYNAMIA",                      GF_HYPODYNAMIA          },
319         {"GF_AWAY_UNDEAD",                      GF_AWAY_UNDEAD          },
320         {"GF_AWAY_EVIL",                        GF_AWAY_EVIL            },
321         {"GF_AWAY_ALL",                         GF_AWAY_ALL                     },
322         {"GF_TURN_UNDEAD",                      GF_TURN_UNDEAD          },
323         {"GF_TURN_EVIL",                        GF_TURN_EVIL            },
324         {"GF_TURN_ALL",                         GF_TURN_ALL                     },
325         {"GF_DISP_UNDEAD",                      GF_DISP_UNDEAD          },
326         {"GF_DISP_EVIL",                        GF_DISP_EVIL            },
327         {"GF_DISP_ALL",                         GF_DISP_ALL                     },
328         {"GF_DISP_DEMON",                       GF_DISP_DEMON           },
329         {"GF_DISP_LIVING",                      GF_DISP_LIVING          },
330         {"GF_ROCKET",                           GF_ROCKET                       },
331         {"GF_NUKE",                                     GF_NUKE                         },
332         {"GF_MAKE_GLYPH",                       GF_MAKE_GLYPH           },
333         {"GF_STASIS",                           GF_STASIS                       },
334         {"GF_STONE_WALL",                       GF_STONE_WALL           },
335         {"GF_DEATH_RAY",                        GF_DEATH_RAY            },
336         {"GF_STUN",                                     GF_STUN                         },
337         {"GF_HOLY_FIRE",                        GF_HOLY_FIRE            },
338         {"GF_HELL_FIRE",                        GF_HELL_FIRE            },
339         {"GF_DISINTEGRATE",                     GF_DISINTEGRATE         },
340         {"GF_CHARM",                            GF_CHARM                        },
341         {"GF_CONTROL_UNDEAD",           GF_CONTROL_UNDEAD       },
342         {"GF_CONTROL_ANIMAL",           GF_CONTROL_ANIMAL       },
343         {"GF_PSI",                                      GF_PSI                          },
344         {"GF_PSI_DRAIN",                        GF_PSI_DRAIN            },
345         {"GF_TELEKINESIS",                      GF_TELEKINESIS          },
346         {"GF_JAM_DOOR",                         GF_JAM_DOOR                     },
347         {"GF_DOMINATION",                       GF_DOMINATION           },
348         {"GF_DISP_GOOD",                        GF_DISP_GOOD            },
349         {"GF_DRAIN_MANA",                       GF_DRAIN_MANA           },
350         {"GF_MIND_BLAST",                       GF_MIND_BLAST           },
351         {"GF_BRAIN_SMASH",                      GF_BRAIN_SMASH          },
352         {"GF_CAUSE_1",                          GF_CAUSE_1                      },
353         {"GF_CAUSE_2",                          GF_CAUSE_2                      },
354         {"GF_CAUSE_3",                          GF_CAUSE_3                      },
355         {"GF_CAUSE_4",                          GF_CAUSE_4                      },
356         {"GF_HAND_DOOM",                        GF_HAND_DOOM            },
357         {"GF_CAPTURE",                          GF_CAPTURE                      },
358         {"GF_ANIM_DEAD",                        GF_ANIM_DEAD            },
359         {"GF_CHARM_LIVING",                     GF_CHARM_LIVING         },
360         {"GF_IDENTIFY",                         GF_IDENTIFY                     },
361         {"GF_ATTACK",                           GF_ATTACK                       },
362         {"GF_ENGETSU",                          GF_ENGETSU                      },
363         {"GF_GENOCIDE",                         GF_GENOCIDE                     },
364         {"GF_PHOTO",                            GF_PHOTO                        },
365         {"GF_CONTROL_DEMON",            GF_CONTROL_DEMON        },
366         {"GF_LAVA_FLOW",                        GF_LAVA_FLOW            },
367         {"GF_BLOOD_CURSE",                      GF_BLOOD_CURSE          },
368         {"GF_SEEKER",                           GF_SEEKER                       },
369         {"GF_SUPER_RAY",                        GF_SUPER_RAY            },
370         {"GF_STAR_HEAL",                        GF_STAR_HEAL            },
371         {"GF_WATER_FLOW",                       GF_WATER_FLOW           },
372         {"GF_CRUSADE",                          GF_CRUSADE                      },
373         {"GF_STASIS_EVIL",                      GF_STASIS_EVIL          },
374         {"GF_WOUNDS",                           GF_WOUNDS                       },
375         {NULL,                                          0                                       }
376 };
377
378
379 /*!
380  * @brief 設定ファイルの各行から各種テキスト情報を取得する /
381  * Parse a sub-file of the "extra info" (format shown below)
382  * @param buf データテキストの参照ポインタ
383  * @return エラーコード
384  * @details
385  * <pre>
386  * Each "action" line has an "action symbol" in the first column,
387  * followed by a colon, followed by some command specific info,
388  * usually in the form of "tokens" separated by colons or slashes.
389  * Blank lines, lines starting with white space, and lines starting
390  * with pound signs ("#") are ignored (as comments).
391  * Note the use of "tokenize()" to allow the use of both colons and
392  * slashes as delimeters, while still allowing final tokens which
393  * may contain any characters including "delimiters".
394  * Note the use of "strtol()" to allow all "integers" to be encoded
395  * in decimal, hexidecimal, or octal form.
396  * Note that "monster zero" is used for the "player" attr/char, "object
397  * zero" will be used for the "stack" attr/char, and "feature zero" is
398  * used for the "nothing" attr/char.
399  * Parse another file recursively, see below for details
400  *   %:\<filename\>
401  * Specify the attr/char values for "monsters" by race index
402  *   R:\<num\>:\<a\>:\<c\>
403  * Specify the attr/char values for "objects" by kind index
404  *   K:\<num\>:\<a\>:\<c\>
405  * Specify the attr/char values for "features" by feature index
406  *   F:\<num\>:\<a\>:\<c\>
407  * Specify the attr/char values for unaware "objects" by kind tval
408  *   U:\<tv\>:\<a\>:\<c\>
409  * Specify the attr/char values for 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) || 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(player_type *creature_ptr, 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 = &creature_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(player_type *creature_ptr, 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_(creature_ptr, RACE_SPECTRE))
2927                 add_flag(flgs, TR_RES_NETHER);
2928         if (creature_ptr->mimic_form == MIMIC_VAMPIRE || PRACE_IS_(creature_ptr, RACE_VAMPIRE))
2929                 add_flag(flgs, TR_RES_DARK);
2930         if (creature_ptr->mimic_form == MIMIC_DEMON_LORD)
2931                 add_flag(flgs, TR_RES_FIRE);
2932         else if (PRACE_IS_(creature_ptr, RACE_YEEK) && creature_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(p_ptr, f.player_imm);
3163         tim_player_immunity(p_ptr, f.tim_player_imm);
3164         known_obj_immunity(p_ptr, 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(p_ptr, f.player_imm);
3294         tim_player_immunity(p_ptr, f.tim_player_imm);
3295         known_obj_immunity(p_ptr, 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 (current_world_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(player_type *creature_ptr, FILE *fff)
4083 {
4084         TERM_LEN x, y;
4085         TERM_COLOR a;
4086         char c;
4087         char buf[1024];
4088
4089         display_player(creature_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(creature_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(creature_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(creature_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 creature_ptr プレーヤーへの参照ポインタ
4470  * @param fff ファイルポインタ
4471  * @return なし
4472  */
4473 static void dump_aux_quest(player_type *creature_ptr, FILE *fff)
4474 {
4475         QUEST_IDX i;
4476         QUEST_IDX *quest_num;
4477         int dummy;
4478
4479         fprintf(fff, _("\n\n  [クエスト情報]\n", "\n\n  [Quest Information]\n"));
4480
4481         /* Allocate Memory */
4482         C_MAKE(quest_num, max_q_idx, QUEST_IDX);
4483
4484         /* Sort by compete level */
4485         for (i = 1; i < max_q_idx; i++) quest_num[i] = i;
4486         ang_sort(quest_num, &dummy, max_q_idx, ang_sort_comp_quest_num, ang_sort_swap_quest_num);
4487
4488         /* Dump Quest Information */
4489         fputc('\n', fff);
4490         do_cmd_knowledge_quests_completed(creature_ptr, fff, quest_num);
4491         fputc('\n', fff);
4492         do_cmd_knowledge_quests_failed(creature_ptr, fff, quest_num);
4493         fputc('\n', fff);
4494
4495         /* Free Memory */
4496         C_KILL(quest_num, max_q_idx, QUEST_IDX);
4497 }
4498
4499
4500 /*!
4501  * @brief 死の直前メッセージ並びに遺言をファイルにダンプする
4502  * @param fff ファイルポインタ
4503  * @return なし
4504  */
4505 static void dump_aux_last_message(FILE *fff)
4506 {
4507         if (p_ptr->is_dead)
4508         {
4509                 if (!current_world_ptr->total_winner)
4510                 {
4511                         int i;
4512
4513                         fprintf(fff, _("\n  [死ぬ直前のメッセージ]\n\n", "\n  [Last Messages]\n\n"));
4514                         for (i = MIN(message_num(), 30); i >= 0; i--)
4515                         {
4516                                 fprintf(fff,"> %s\n",message_str((s16b)i));
4517                         }
4518                         fputc('\n', fff);
4519                 }
4520
4521                 /* Hack -- *Winning* message */
4522                 else if (p_ptr->last_message)
4523                 {
4524                         fprintf(fff, _("\n  [*勝利*メッセージ]\n\n", "\n  [*Winning* Message]\n\n"));
4525                         fprintf(fff,"  %s\n", p_ptr->last_message);
4526                         fputc('\n', fff);
4527                 }
4528         }
4529 }
4530
4531 /*!
4532  * @brief 帰還場所情報をファイルにダンプする
4533  * @param fff ファイルポインタ
4534  * @return なし
4535  */
4536 static void dump_aux_recall(FILE *fff)
4537 {
4538         int y;
4539         fprintf(fff, _("\n  [帰還場所]\n\n", "\n  [Recall Depth]\n\n"));
4540
4541         for (y = 1; y < current_world_ptr->max_d_idx; y++)
4542         {
4543                 bool seiha = FALSE;
4544
4545                 if (!d_info[y].maxdepth) continue;
4546                 if (!max_dlv[y]) continue;
4547                 if (d_info[y].final_guardian)
4548                 {
4549                         if (!r_info[d_info[y].final_guardian].max_num) seiha = TRUE;
4550                 }
4551                 else if (max_dlv[y] == d_info[y].maxdepth) seiha = TRUE;
4552
4553                 fprintf(fff, _("   %c%-12s: %3d 階\n", "   %c%-16s: level %3d\n"),
4554                         seiha ? '!' : ' ', d_name+d_info[y].name, (int)max_dlv[y]);
4555         }
4556 }
4557
4558
4559 /*!
4560  * @brief オプション情報をファイルにダンプする
4561  * @param fff ファイルポインタ
4562  * @return なし
4563  */
4564 static void dump_aux_options(FILE *fff)
4565 {
4566         fprintf(fff, _("\n  [オプション設定]\n", "\n  [Option Settings]\n"));
4567
4568         if (preserve_mode)
4569                 fprintf(fff, _("\n 保存モード:         ON", "\n Preserve Mode:      ON"));
4570
4571         else
4572                 fprintf(fff, _("\n 保存モード:         OFF", "\n Preserve Mode:      OFF"));
4573
4574         if (ironman_small_levels)
4575                 fprintf(fff, _("\n 小さいダンジョン:   ALWAYS", "\n Small Levels:       ALWAYS"));
4576         else if (always_small_levels)
4577                 fprintf(fff, _("\n 小さいダンジョン:   ON", "\n Small Levels:       ON"));
4578         else if (small_levels)
4579                 fprintf(fff, _("\n 小さいダンジョン:   ENABLED", "\n Small Levels:       ENABLED"));
4580         else
4581                 fprintf(fff, _("\n 小さいダンジョン:   OFF", "\n Small Levels:       OFF"));
4582
4583
4584         if (vanilla_town)
4585                 fprintf(fff, _("\n 元祖の町のみ:       ON", "\n Vanilla Town:       ON"));
4586         else if (lite_town)
4587                 fprintf(fff, _("\n 小規模な町:         ON", "\n Lite Town:          ON"));
4588
4589
4590         if (ironman_shops)
4591                 fprintf(fff, _("\n 店なし:             ON", "\n No Shops:           ON"));
4592
4593         if (ironman_downward)
4594                 fprintf(fff, _("\n 階段を上がれない:   ON", "\n Diving Only:        ON"));
4595
4596         if (ironman_rooms)
4597                 fprintf(fff, _("\n 普通でない部屋:     ON", "\n Unusual Rooms:      ON"));
4598
4599         if (ironman_nightmare)
4600                 fprintf(fff, _("\n 悪夢モード:         ON", "\n Nightmare Mode:     ON"));
4601
4602
4603         if (ironman_empty_levels)
4604                 fprintf(fff, _("\n アリーナ:           ALWAYS", "\n Arena Levels:       ALWAYS"));
4605         else if (empty_levels)
4606                 fprintf(fff, _("\n アリーナ:           ENABLED", "\n Arena Levels:       ENABLED"));
4607         else
4608                 fprintf(fff, _("\n アリーナ:           OFF", "\n Arena Levels:       OFF"));
4609
4610         fputc('\n', fff);
4611
4612         if (current_world_ptr->noscore)
4613                 fprintf(fff, _("\n 何か不正なことをしてしまっています。\n", "\n You have done something illegal.\n"));
4614
4615         fputc('\n', fff);
4616 }
4617
4618
4619 /*!
4620  * @brief 闘技場の情報をファイルにダンプする
4621  * @param fff ファイルポインタ
4622  * @return なし
4623  */
4624 static void dump_aux_arena(player_type *creature_ptr, FILE *fff)
4625 {
4626         if (lite_town || vanilla_town) return;
4627
4628         if (creature_ptr->arena_number < 0)
4629         {
4630                 if (creature_ptr->arena_number <= ARENA_DEFEATED_OLD_VER)
4631                 {
4632                         fprintf(fff, _("\n 闘技場: 敗北\n", "\n Arena: Defeated\n"));
4633                 }
4634                 else
4635                 {
4636 #ifdef JP
4637                         fprintf(fff, "\n 闘技場: %d回戦で%sの前に敗北\n", -creature_ptr->arena_number,
4638                                 r_name + r_info[arena_info[-1 - creature_ptr->arena_number].r_idx].name);
4639 #else
4640                         fprintf(fff, "\n Arena: Defeated by %s in the %d%s fight\n",
4641                                 r_name + r_info[arena_info[-1 - creature_ptr->arena_number].r_idx].name,
4642                                 -creature_ptr->arena_number, get_ordinal_number_suffix(-creature_ptr->arena_number));
4643 #endif
4644                 }
4645         }
4646         else if (creature_ptr->arena_number > MAX_ARENA_MONS + 2)
4647         {
4648                 fprintf(fff, _("\n 闘技場: 真のチャンピオン\n", "\n Arena: True Champion\n"));
4649         }
4650         else if (creature_ptr->arena_number > MAX_ARENA_MONS - 1)
4651         {
4652                 fprintf(fff, _("\n 闘技場: チャンピオン\n", "\n Arena: Champion\n"));
4653         }
4654         else
4655         {
4656 #ifdef JP
4657                 fprintf(fff, "\n 闘技場: %2d勝\n", (creature_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : creature_ptr->arena_number));
4658 #else
4659                 fprintf(fff, "\n Arena: %2d Victor%s\n", (creature_ptr->arena_number > MAX_ARENA_MONS ? MAX_ARENA_MONS : creature_ptr->arena_number), (creature_ptr->arena_number > 1) ? "ies" : "y");
4660 #endif
4661         }
4662
4663         fprintf(fff, "\n");
4664 }
4665
4666
4667 /*!
4668  * @brief 撃破モンスターの情報をファイルにダンプする
4669  * @param fff ファイルポインタ
4670  * @return なし
4671  */
4672 static void dump_aux_monsters(FILE *fff)
4673 {
4674         /* Monsters slain */
4675
4676         IDX k;
4677         long uniq_total = 0;
4678         long norm_total = 0;
4679         MONRACE_IDX *who;
4680
4681         /* Sort by monster level */
4682         u16b why = 2;
4683
4684         fprintf(fff, _("\n  [倒したモンスター]\n\n", "\n  [Defeated Monsters]\n\n"));
4685
4686         /* Allocate the "who" array */
4687         C_MAKE(who, max_r_idx, MONRACE_IDX);
4688
4689         /* Count monster kills */
4690         for (k = 1; k < max_r_idx; k++)
4691         {
4692                 monster_race *r_ptr = &r_info[k];
4693
4694                 /* Ignore unused index */
4695                 if (!r_ptr->name) continue;
4696
4697                 if (r_ptr->flags1 & RF1_UNIQUE)
4698                 {
4699                         bool dead = (r_ptr->max_num == 0);
4700                         if (dead)
4701                         {
4702                                 norm_total++;
4703
4704                                 /* Add a unique monster to the list */
4705                                 who[uniq_total++] = k;
4706                         }
4707                 }
4708                 else
4709                 {
4710                         if (r_ptr->r_pkills > 0)
4711                         {
4712                                 norm_total += r_ptr->r_pkills;
4713                         }
4714                 }
4715         }
4716
4717
4718         /* No monsters is defeated */
4719         if (norm_total < 1)
4720         {
4721                 fprintf(fff,_("まだ敵を倒していません。\n", "You have defeated no enemies yet.\n"));
4722         }
4723
4724         /* Defeated more than one normal monsters */
4725         else if (uniq_total == 0)
4726         {
4727 #ifdef JP
4728                 fprintf(fff,"%ld体の敵を倒しています。\n", norm_total);
4729 #else
4730                 fprintf(fff,"You have defeated %ld %s.\n", norm_total, norm_total == 1 ? "enemy" : "enemies");
4731 #endif
4732         }
4733
4734         /* Defeated more than one unique monsters */
4735         else /* if (uniq_total > 0) */
4736         {
4737 #ifdef JP
4738                 fprintf(fff, "%ld体のユニーク・モンスターを含む、合計%ld体の敵を倒しています。\n", uniq_total, norm_total); 
4739 #else
4740                 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"));
4741 #endif
4742
4743                 /* Sort the array by dungeon depth of monsters */
4744                 ang_sort(who, &why, uniq_total, ang_sort_comp_hook, ang_sort_swap_hook);
4745                 fprintf(fff, _("\n《上位%ld体のユニーク・モンスター》\n", "\n< Unique monsters top %ld >\n"), MIN(uniq_total, 10));
4746
4747                 /* Print top 10 */
4748                 for (k = uniq_total - 1; k >= 0 && k >= uniq_total - 10; k--)
4749                 {
4750                         monster_race *r_ptr = &r_info[who[k]];
4751                         fprintf(fff, _("  %-40s (レベル%3d)\n", "  %-40s (level %3d)\n"), (r_name + r_ptr->name), (int)r_ptr->level);
4752                 }
4753
4754         }
4755
4756         /* Free the "who" array */
4757         C_KILL(who, max_r_idx, s16b);
4758 }
4759
4760
4761 /*!
4762  * @brief 元種族情報をファイルにダンプする
4763  * @param fff ファイルポインタ
4764  * @return なし
4765  */
4766 static void dump_aux_race_history(player_type *creature_ptr, FILE *fff)
4767 {
4768         if (creature_ptr->old_race1 || creature_ptr->old_race2)
4769         {
4770                 int i;
4771
4772                 fprintf(fff, _("\n\n あなたは%sとして生まれた。", "\n\n You were born as %s."), race_info[creature_ptr->start_race].title);
4773                 for (i = 0; i < MAX_RACES; i++)
4774                 {
4775                         if (creature_ptr->start_race == i) continue;
4776                         if (i < 32)
4777                         {
4778                                 if (!(creature_ptr->old_race1 & 1L << i)) continue;
4779                         }
4780                         else
4781                         {
4782                                 if (!(creature_ptr->old_race2 & 1L << (i-32))) continue;
4783                         }
4784                         fprintf(fff, _("\n あなたはかつて%sだった。", "\n You were a %s before."), race_info[i].title);
4785                 }
4786
4787                 fputc('\n', fff);
4788         }
4789 }
4790
4791
4792 /*!
4793  * @brief 元魔法領域情報をファイルにダンプする
4794  * @param fff ファイルポインタ
4795  * @return なし
4796  */
4797 static void dump_aux_realm_history(FILE *fff)
4798 {
4799         if (p_ptr->old_realm)
4800         {
4801                 int i;
4802
4803                 fputc('\n', fff);
4804                 for (i = 0; i < MAX_MAGIC; i++)
4805                 {
4806                         if (!(p_ptr->old_realm & 1L << i)) continue;
4807                         fprintf(fff, _("\n あなたはかつて%s魔法を使えた。", "\n You were able to use %s magic before."), realm_names[i+1]);
4808                 }
4809                 fputc('\n', fff);
4810         }
4811 }
4812
4813
4814 /*!
4815  * @brief 徳の情報をファイルにダンプする
4816  * @param fff ファイルポインタ
4817  * @return なし
4818  */
4819 static void dump_aux_virtues(FILE *fff)
4820 {
4821         int v_nr, percent;
4822
4823         fprintf(fff, _("\n\n  [自分に関する情報]\n\n", "\n\n  [HP-rate & Max stat & Virtues]\n\n"));
4824
4825         percent = (int)(((long)p_ptr->player_hp[PY_MAX_LEVEL - 1] * 200L) /
4826                 (2 * p_ptr->hitdie +
4827                 ((PY_MAX_LEVEL - 1+3) * (p_ptr->hitdie + 1))));
4828
4829 #ifdef JP
4830                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "現在の体力ランク : %d/100\n\n", percent);
4831                 else fprintf(fff, "現在の体力ランク : ???\n\n");
4832                 fprintf(fff, "能力の最大値\n");
4833 #else
4834                 if (p_ptr->knowledge & KNOW_HPRATE) fprintf(fff, "Your current Life Rating is %d/100.\n\n", percent);
4835                 else fprintf(fff, "Your current Life Rating is ???.\n\n");
4836                 fprintf(fff, "Limits of maximum stats\n");
4837 #endif
4838                 for (v_nr = 0; v_nr < A_MAX; v_nr++)
4839                 {
4840                         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);
4841                         else fprintf(fff, "%s ???\n", stat_names[v_nr]);
4842                 }
4843
4844         fprintf(fff, _("\n属性 : %s\n", "\nYour alighnment : %s\n"), your_alignment(p_ptr));
4845         fprintf(fff, "\n");
4846         dump_virtues(p_ptr, fff);
4847 }
4848
4849
4850 /*!
4851  * @brief 突然変異の情報をファイルにダンプする
4852  * @param fff ファイルポインタ
4853  * @return なし
4854  */
4855 static void dump_aux_mutations(FILE *fff)
4856 {
4857         if (p_ptr->muta1 || p_ptr->muta2 || p_ptr->muta3)
4858         {
4859                 fprintf(fff, _("\n\n  [突然変異]\n\n", "\n\n  [Mutations]\n\n"));
4860                 dump_mutations(p_ptr, fff);
4861         }
4862 }
4863
4864
4865 /*!
4866  * @brief 所持品の情報をファイルにダンプする
4867  * @param fff ファイルポインタ
4868  * @return なし
4869  */
4870 static void dump_aux_equipment_inventory(FILE *fff)
4871 {
4872         int i;
4873         GAME_TEXT o_name[MAX_NLEN];
4874
4875         /* Dump the equipment */
4876         if (p_ptr->equip_cnt)
4877         {
4878                 fprintf(fff, _("  [キャラクタの装備]\n\n", "  [Character Equipment]\n\n"));
4879                 for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
4880                 {
4881                         object_desc(o_name, &p_ptr->inventory_list[i], 0);
4882                         if ((((i == INVEN_RARM) && p_ptr->hidarite) || ((i == INVEN_LARM) && p_ptr->migite)) && p_ptr->ryoute)
4883                                 strcpy(o_name, _("(武器を両手持ち)", "(wielding with two-hands)"));
4884
4885                         fprintf(fff, "%c) %s\n",
4886                                 index_to_label(i), o_name);
4887                 }
4888                 fprintf(fff, "\n\n");
4889         }
4890
4891         fprintf(fff, _("  [キャラクタの持ち物]\n\n", "  [Character Inventory]\n\n"));
4892
4893         for (i = 0; i < INVEN_PACK; i++)
4894         {
4895                 /* Don't dump the empty slots */
4896                 if (!p_ptr->inventory_list[i].k_idx) break;
4897
4898                 object_desc(o_name, &p_ptr->inventory_list[i], 0);
4899                 fprintf(fff, "%c) %s\n", index_to_label(i), o_name);
4900         }
4901
4902         /* Add an empty line */
4903         fprintf(fff, "\n\n");
4904 }
4905
4906
4907 /*!
4908  * @brief 我が家と博物館のオブジェクト情報をファイルにダンプする
4909  * @param fff ファイルポインタ
4910  * @return なし
4911  */
4912 static void dump_aux_home_museum(FILE *fff)
4913 {
4914         GAME_TEXT o_name[MAX_NLEN];
4915         store_type  *st_ptr;
4916
4917         /* Do we need it?? */
4918         /* process_dungeon_file("w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x); */
4919
4920         /* Print the home */
4921         st_ptr = &town_info[1].store[STORE_HOME];
4922
4923         /* Home -- if anything there */
4924         if (st_ptr->stock_num)
4925         {
4926                 int i;
4927                 TERM_LEN x = 1;
4928
4929                 fprintf(fff, _("  [我が家のアイテム]\n", "  [Home Inventory]\n"));
4930
4931                 /* Dump all available items */
4932                 for (i = 0; i < st_ptr->stock_num; i++)
4933                 {
4934                         if ((i % 12) == 0)
4935                                 fprintf(fff, _("\n ( %d ページ )\n", "\n ( page %d )\n"), x++);
4936                         object_desc(o_name, &st_ptr->stock[i], 0);
4937                         fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
4938                 }
4939
4940                 /* Add an empty line */
4941                 fprintf(fff, "\n\n");
4942         }
4943
4944
4945         /* Print the home */
4946         st_ptr = &town_info[1].store[STORE_MUSEUM];
4947
4948         /* Home -- if anything there */
4949         if (st_ptr->stock_num)
4950         {
4951                 int i;
4952                 TERM_LEN x = 1;
4953
4954                 fprintf(fff, _("  [博物館のアイテム]\n", "  [Museum]\n"));
4955
4956                 /* Dump all available items */
4957                 for (i = 0; i < st_ptr->stock_num; i++)
4958                 {
4959 #ifdef JP
4960                 if ((i % 12) == 0) fprintf(fff, "\n ( %d ページ )\n", x++);
4961                         object_desc(o_name, &st_ptr->stock[i], 0);
4962                         fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
4963 #else
4964                 if ((i % 12) == 0) fprintf(fff, "\n ( page %d )\n", x++);
4965                         object_desc(o_name, &st_ptr->stock[i], 0);
4966                         fprintf(fff, "%c) %s\n", I2A(i%12), o_name);
4967 #endif
4968
4969                 }
4970
4971                 /* Add an empty line */
4972                 fprintf(fff, "\n\n");
4973         }
4974 }
4975
4976
4977 /*!
4978  * @brief ダンプ出力のメインルーチン
4979  * Output the character dump to a file
4980  * @param creature_ptr プレーヤーへの参照ポインタ
4981  * @param fff ファイルポインタ
4982  * @return エラーコード
4983  */
4984 errr make_character_dump(player_type *creature_ptr, FILE *fff)
4985 {
4986 #ifdef JP
4987         fprintf(fff, "  [変愚蛮怒 %d.%d.%d キャラクタ情報]\n\n",
4988                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4989 #else
4990         fprintf(fff, "  [Hengband %d.%d.%d Character Dump]\n\n",
4991                 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
4992 #endif
4993
4994         update_playtime();
4995
4996         dump_aux_display_player(p_ptr, fff);
4997         dump_aux_last_message(fff);
4998         dump_aux_options(fff);
4999         dump_aux_recall(fff);
5000         dump_aux_quest(creature_ptr, fff);
5001         dump_aux_arena(p_ptr, fff);
5002         dump_aux_monsters(fff);
5003         dump_aux_virtues(fff);
5004         dump_aux_race_history(p_ptr, fff);
5005         dump_aux_realm_history(fff);
5006         dump_aux_class_special(fff);
5007         dump_aux_mutations(fff);
5008         dump_aux_pet(p_ptr, fff);
5009         fputs("\n\n", fff);
5010         dump_aux_equipment_inventory(fff);
5011         dump_aux_home_museum(fff);
5012
5013         fprintf(fff, _("  [チェックサム: \"%s\"]\n\n", "  [Check Sum: \"%s\"]\n\n"), get_check_sum());
5014         return 0;
5015 }
5016
5017 /*!
5018  * @brief プレイヤーステータスをファイルダンプ出力する
5019  * Hack -- Dump a character description file
5020  * @param creature_ptr プレーヤーへの参照ポインタ
5021  * @param name 出力ファイル名
5022  * @return エラーコード
5023  * @details
5024  * Allow the "full" flag to dump additional info,
5025  * and trigger its usage from various places in the code.
5026  */
5027 errr file_character(player_type *creature_ptr, concptr name)
5028 {
5029         int             fd = -1;
5030         FILE            *fff = NULL;
5031         char            buf[1024];
5032         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
5033
5034         /* File type is "TEXT" */
5035         FILE_TYPE(FILE_TYPE_TEXT);
5036
5037         /* Check for existing file */
5038         fd = fd_open(buf, O_RDONLY);
5039
5040         /* Existing file */
5041         if (fd >= 0)
5042         {
5043                 char out_val[160];
5044                 (void)fd_close(fd);
5045
5046                 /* Build query */
5047                 (void)sprintf(out_val, _("現存するファイル %s に上書きしますか? ", "Replace existing file %s? "), buf);
5048
5049                 /* Ask */
5050                 if (get_check_strict(out_val, CHECK_NO_HISTORY)) fd = -1;
5051         }
5052
5053         /* Open the non-existing file */
5054         if (fd < 0) fff = my_fopen(buf, "w");
5055
5056         /* Invalid file */
5057         if (!fff)
5058         {
5059                 prt(_("キャラクタ情報のファイルへの書き出しに失敗しました!", "Character dump failed!"), 0, 0);
5060
5061                 (void)inkey();
5062
5063                 /* Error */
5064                 return (-1);
5065         }
5066
5067         (void)make_character_dump(creature_ptr, fff);
5068         my_fclose(fff);
5069
5070
5071         msg_print(_("キャラクタ情報のファイルへの書き出しに成功しました。", "Character dump successful."));
5072         msg_print(NULL);
5073
5074         /* Success */
5075         return (0);
5076 }
5077
5078
5079 /*!
5080  * @brief ファイル内容の一行をコンソールに出力する
5081  * Display single line of on-line help file
5082  * @param str 出力する文字列
5083  * @param cy コンソールの行
5084  * @param shower 確認中
5085  * @return なし
5086  * @details
5087  * <pre>
5088  * You can insert some special color tag to change text color.
5089  * Such as...
5090  * WHITETEXT [[[[y|SOME TEXT WHICH IS DISPLAYED IN YELLOW| WHITETEXT
5091  * A colored segment is between "[[[[y|" and the last "|".
5092  * You can use any single character in place of the "|".
5093  * </pre>
5094  */
5095 static void show_file_aux_line(concptr str, int cy, concptr shower)
5096 {
5097         static const char tag_str[] = "[[[[";
5098         byte color = TERM_WHITE;
5099         char in_tag = '\0';
5100         int cx = 0;
5101         int i;
5102         char lcstr[1024];
5103
5104         if (shower)
5105         {
5106                 /* Make a lower case version of str for searching */
5107                 strcpy(lcstr, str);
5108                 str_tolower(lcstr);
5109         }
5110
5111         /* Initial cursor position */
5112         Term_gotoxy(cx, cy);
5113
5114         for (i = 0; str[i];)
5115         {
5116                 int len = strlen(&str[i]);
5117                 int showercol = len + 1;
5118                 int bracketcol = len + 1;
5119                 int endcol = len;
5120                 concptr ptr;
5121
5122                 /* Search for a shower string in the line */
5123                 if (shower)
5124                 {
5125                         ptr = my_strstr(&lcstr[i], shower);
5126                         if (ptr) showercol = ptr - &lcstr[i];
5127                 }
5128
5129                 /* Search for a color segment tag */
5130                 ptr = in_tag ? my_strchr(&str[i], in_tag) : my_strstr(&str[i], tag_str);
5131                 if (ptr) bracketcol = ptr - &str[i];
5132
5133                 /* A color tag is found */
5134                 if (bracketcol < endcol) endcol = bracketcol;
5135
5136                 /* The shower string is found before the color tag */
5137                 if (showercol < endcol) endcol = showercol;
5138
5139                 /* Print a segment of the line */
5140                 Term_addstr(endcol, color, &str[i]);
5141                 cx += endcol;
5142                 i += endcol;
5143
5144                 /* Shower string? */
5145                 if (endcol == showercol)
5146                 {
5147                         int showerlen = strlen(shower);
5148
5149                         /* Print the shower string in yellow */
5150                         Term_addstr(showerlen, TERM_YELLOW, &str[i]);
5151                         cx += showerlen;
5152                         i += showerlen;
5153                 }
5154
5155                 /* Colored segment? */
5156                 else if (endcol == bracketcol)
5157                 {
5158                         if (in_tag)
5159                         {
5160                                 /* Found the end of colored segment */
5161                                 i++;
5162
5163                                 /* Now looking for an another tag_str */
5164                                 in_tag = '\0';
5165
5166                                 /* Set back to the default color */
5167                                 color = TERM_WHITE;
5168                         }
5169                         else
5170                         {
5171                                 /* Found a tag_str, and get a tag color */
5172                                 i += sizeof(tag_str)-1;
5173
5174                                 /* Get tag color */
5175                                 color = color_char_to_attr(str[i]);
5176
5177                                 /* Illegal color tag */
5178                                 if (color == 255 || str[i+1] == '\0')
5179                                 {
5180                                         /* Illegal color tag */
5181                                         color = TERM_WHITE;
5182
5183                                         /* Print the broken tag as a string */
5184                                         Term_addstr(-1, TERM_WHITE, tag_str);
5185                                         cx += sizeof(tag_str)-1;
5186                                 }
5187                                 else
5188                                 {
5189                                         /* Skip the color tag */
5190                                         i++;
5191
5192                                         /* Now looking for a close tag */
5193                                         in_tag = str[i];
5194
5195                                         /* Skip the close-tag-indicator */
5196                                         i++;
5197                                 }
5198                         }
5199                 }
5200
5201         } /* for (i = 0; str[i];) */
5202
5203         /* Clear rest of line */
5204         Term_erase(cx, cy, 255);
5205 }
5206
5207
5208 /*!
5209  * @brief ファイル内容をコンソールに出力する
5210  * Recursive file perusal.
5211  * @param show_version TRUEならばコンソール上にゲームのバージョンを表示する
5212  * @param name ファイル名の文字列
5213  * @param what 内容キャプションの文字列
5214  * @param line 表示の現在行
5215  * @param mode オプション
5216  * @return なし
5217  * @details
5218  * <pre>
5219  * Process various special text in the input file, including
5220  * the "menu" structures used by the "help file" system.
5221  * Return FALSE on 'q' to exit from a deep, otherwise TRUE.
5222  * </pre>
5223  */
5224 bool show_file(bool show_version, concptr name, concptr what, int line, BIT_FLAGS mode)
5225 {
5226         int i, n, skey;
5227
5228         /* Number of "real" lines passed by */
5229         int next = 0;
5230
5231         /* Number of "real" lines in the file */
5232         int size = 0;
5233
5234         /* Backup value for "line" */
5235         int back = 0;
5236
5237         /* This screen has sub-screens */
5238         bool menu = FALSE;
5239
5240         /* Current help file */
5241         FILE *fff = NULL;
5242
5243         /* Find this string (if any) */
5244         concptr find = NULL;
5245
5246         /* Jump to this tag */
5247         concptr tag = NULL;
5248
5249         /* Hold strings to find/show */
5250         char finder_str[81];
5251         char shower_str[81];
5252         char back_str[81];
5253
5254         /* String to show */
5255         concptr shower = NULL;
5256
5257         /* Filename */
5258         char filename[1024];
5259
5260         /* Describe this thing */
5261         char caption[128];
5262
5263         /* Path buffer */
5264         char path[1024];
5265
5266         /* General buffer */
5267         char buf[1024];
5268
5269         /* Sub-menu information */
5270         char hook[68][32];
5271
5272         bool reverse = (line < 0);
5273
5274         int wid, hgt, rows;
5275
5276         Term_get_size(&wid, &hgt);
5277         rows = hgt - 4;
5278
5279         strcpy(finder_str, "");
5280         strcpy(shower_str, "");
5281         strcpy(caption, "");
5282         for (i = 0; i < 68; i++)
5283         {
5284                 hook[i][0] = '\0';
5285         }
5286
5287         strcpy(filename, name);
5288
5289         n = strlen(filename);
5290
5291         /* Extract the tag from the filename */
5292         for (i = 0; i < n; i++)
5293         {
5294                 if (filename[i] == '#')
5295                 {
5296                         filename[i] = '\0';
5297                         tag = filename + i + 1;
5298                         break;
5299                 }
5300         }
5301
5302         /* Redirect the name */
5303         name = filename;
5304
5305         if (what)
5306         {
5307                 strcpy(caption, what);
5308                 strcpy(path, name);
5309                 fff = my_fopen(path, "r");
5310         }
5311
5312         /* Look in "help" */
5313         if (!fff)
5314         {
5315                 sprintf(caption, _("ヘルプ・ファイル'%s'", "Help file '%s'"), name);
5316                 path_build(path, sizeof(path), ANGBAND_DIR_HELP, name);
5317                 fff = my_fopen(path, "r");
5318         }
5319
5320         /* Look in "info" */
5321         if (!fff)
5322         {
5323                 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
5324                 path_build(path, sizeof(path), ANGBAND_DIR_INFO, name);
5325                 fff = my_fopen(path, "r");
5326         }
5327
5328         /* Look in "info" */
5329         if (!fff)
5330         {
5331                 path_build(path, sizeof(path), ANGBAND_DIR, name);
5332
5333                 for (i = 0; path[i]; i++)
5334                         if ('\\' == path[i])
5335                                 path[i] = PATH_SEP[0];
5336
5337                 sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
5338                 fff = my_fopen(path, "r");
5339         }
5340
5341         if (!fff)
5342         {
5343                 msg_format(_("'%s'をオープンできません。", "Cannot open '%s'."), name);
5344                 msg_print(NULL);
5345
5346                 return (TRUE);
5347         }
5348
5349
5350         /* Pre-Parse the file */
5351         while (TRUE)
5352         {
5353                 char *str = buf;
5354
5355                 /* Read a line or stop */
5356                 if (my_fgets(fff, buf, sizeof(buf))) break;
5357
5358                 /* XXX Parse "menu" items */
5359                 if (prefix(str, "***** "))
5360                 {
5361                         /* Notice "menu" requests */
5362                         if ((str[6] == '[') && isalpha(str[7]))
5363                         {
5364                                 /* Extract the menu item */
5365                                 int k = str[7] - 'A';
5366
5367                                 /* This is a menu file */
5368                                 menu = TRUE;
5369
5370                                 if ((str[8] == ']') && (str[9] == ' '))
5371                                 {
5372                                         /* Extract the menu item */
5373                                         strncpy(hook[k], str + 10, 31);
5374
5375                                         /* Make sure it's null-terminated */
5376                                         hook[k][31] = '\0';
5377                                 }
5378                         }
5379                         /* Notice "tag" requests */
5380                         else if (str[6] == '<')
5381                         {
5382                                 size_t len = strlen(str);
5383
5384                                 if (str[len - 1] == '>')
5385                                 {
5386                                         str[len - 1] = '\0';
5387                                         if (tag && streq(str + 7, tag)) line = next;
5388                                 }
5389                         }
5390
5391                         /* Skip this */
5392                         continue;
5393                 }
5394
5395                 /* Count the "real" lines */
5396                 next++;
5397         }
5398
5399         /* Save the number of "real" lines */
5400         size = next;
5401
5402         /* start from bottom when reverse mode */
5403         if (line == -1) line = ((size-1)/rows)*rows;
5404         Term_clear();
5405
5406         /* Display the file */
5407         while (TRUE)
5408         {
5409                 /* Restart when necessary */
5410                 if (line >= size - rows) line = size - rows;
5411                 if (line < 0) line = 0;
5412
5413                 /* Re-open the file if needed */
5414                 if (next > line)
5415                 {
5416                         my_fclose(fff);
5417
5418                         /* Hack -- Re-Open the file */
5419                         fff = my_fopen(path, "r");
5420
5421                         if (!fff) return (FALSE);
5422
5423                         /* File has been restarted */
5424                         next = 0;
5425                 }
5426
5427                 /* Goto the selected line */
5428                 while (next < line)
5429                 {
5430                         /* Get a line */
5431                         if (my_fgets(fff, buf, sizeof(buf))) break;
5432
5433                         /* Skip tags/links */
5434                         if (prefix(buf, "***** ")) continue;
5435
5436                         /* Count the lines */
5437                         next++;
5438                 }
5439
5440                 /* Dump the next 20, or rows, lines of the file */
5441                 for (i = 0; i < rows; )
5442                 {
5443                         concptr str = buf;
5444
5445                         /* Hack -- track the "first" line */
5446                         if (!i) line = next;
5447
5448                         /* Get a line of the file or stop */
5449                         if (my_fgets(fff, buf, sizeof(buf))) break;
5450
5451                         /* Hack -- skip "special" lines */
5452                         if (prefix(buf, "***** ")) continue;
5453
5454                         /* Count the "real" lines */
5455                         next++;
5456
5457                         /* Hack -- keep searching */
5458                         if (find && !i)
5459                         {
5460                                 char lc_buf[1024];
5461
5462                                 /* Make a lower case version of str for searching */
5463                                 strcpy(lc_buf, str);
5464                                 str_tolower(lc_buf);
5465
5466                                 if (!my_strstr(lc_buf, find)) continue;
5467                         }
5468
5469                         /* Hack -- stop searching */
5470                         find = NULL;
5471
5472                         /* Dump the line */
5473                         show_file_aux_line(str, i + 2, shower);
5474
5475                         /* Count the printed lines */
5476                         i++;
5477                 }
5478
5479                 while (i < rows)
5480                 {
5481                         /* Clear rest of line */
5482                         Term_erase(0, i + 2, 255);
5483
5484                         i++;
5485                 }
5486
5487                 /* Hack -- failed search */
5488                 if (find)
5489                 {
5490                         bell();
5491                         line = back;
5492                         find = NULL;
5493                         continue;
5494                 }
5495
5496
5497                 /* Show a general "title" */
5498                 if (show_version)
5499                 {
5500                         prt(format(_("[変愚蛮怒 %d.%d.%d, %s, %d/%d]", "[Hengband %d.%d.%d, %s, Line %d/%d]"),
5501                            FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH,
5502                            caption, line, size), 0, 0);
5503                 }
5504                 else
5505                 {
5506                         prt(format(_("[%s, %d/%d]", "[%s, Line %d/%d]"),
5507                                 caption, line, size), 0, 0);
5508                 }
5509
5510                 /* Prompt -- small files */
5511                 if (size <= rows)
5512                 {
5513                         /* Wait for it */
5514                         prt(_("[キー:(?)ヘルプ (ESC)終了]", "[Press ESC to exit.]"), hgt - 1, 0);
5515                 }
5516
5517                 /* Prompt -- large files */
5518                 else
5519                 {
5520 #ifdef JP
5521                         if(reverse)
5522                                 prt("[キー:(RET/スペース)↑ (-)↓ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
5523                         else
5524                                 prt("[キー:(RET/スペース)↓ (-)↑ (?)ヘルプ (ESC)終了]", hgt - 1, 0);
5525 #else
5526                         prt("[Press Return, Space, -, =, /, |, or ESC to exit.]", hgt - 1, 0);
5527 #endif
5528                 }
5529
5530                 /* Get a special key code */
5531                 skey = inkey_special(TRUE);
5532
5533                 switch (skey)
5534                 {
5535                 /* Show the help for the help */
5536                 case '?':
5537                         /* Hack - prevent silly recursion */
5538                         if (strcmp(name, _("jhelpinfo.txt", "helpinfo.txt")) != 0)
5539                                 show_file(TRUE, _("jhelpinfo.txt", "helpinfo.txt"), NULL, 0, mode);
5540                         break;
5541
5542                 /* Hack -- try showing */
5543                 case '=':
5544                         /* Get "shower" */
5545                         prt(_("強調: ", "Show: "), hgt - 1, 0);
5546
5547                         strcpy(back_str, shower_str);
5548                         if (askfor(shower_str, 80))
5549                         {
5550                                 if (shower_str[0])
5551                                 {
5552                                         /* Make it lowercase */
5553                                         str_tolower(shower_str);
5554
5555                                         /* Show it */
5556                                         shower = shower_str;
5557                                 }
5558                                 else shower = NULL; /* Stop showing */
5559                         }
5560                         else strcpy(shower_str, back_str);
5561                         break;
5562
5563                 /* Hack -- try finding */
5564                 case '/':
5565                 case KTRL('s'):
5566                         /* Get "finder" */
5567                         prt(_("検索: ", "Find: "), hgt - 1, 0);
5568
5569                         strcpy(back_str, finder_str);
5570                         if (askfor(finder_str, 80))
5571                         {
5572                                 if (finder_str[0])
5573                                 {
5574                                         /* Find it */
5575                                         find = finder_str;
5576                                         back = line;
5577                                         line = line + 1;
5578
5579                                         /* Make finder lowercase */
5580                                         str_tolower(finder_str);
5581
5582                                         /* Show it */
5583                                         shower = finder_str;
5584                                 }
5585                                 else shower = NULL; /* Stop showing */
5586                         }
5587                         else strcpy(finder_str, back_str);
5588                         break;
5589
5590                 /* Hack -- go to a specific line */
5591                 case '#':
5592                         {
5593                                 char tmp[81];
5594                                 prt(_("行: ", "Goto Line: "), hgt - 1, 0);
5595                                 strcpy(tmp, "0");
5596
5597                                 if (askfor(tmp, 80)) line = atoi(tmp);
5598                         }
5599                         break;
5600
5601                 /* Hack -- go to the top line */
5602                 case SKEY_TOP:
5603                         line = 0;
5604                         break;
5605
5606                 /* Hack -- go to the bottom line */
5607                 case SKEY_BOTTOM:
5608                         line = ((size - 1) / rows) * rows;
5609                         break;
5610
5611                 /* Hack -- go to a specific file */
5612                 case '%':
5613                         {
5614                                 char tmp[81];
5615                                 prt(_("ファイル・ネーム: ", "Goto File: "), hgt - 1, 0);
5616                                 strcpy(tmp, _("jhelp.hlp", "help.hlp"));
5617
5618                                 if (askfor(tmp, 80))
5619                                 {
5620                                         if (!show_file(TRUE, tmp, NULL, 0, mode)) skey = 'q';
5621                                 }
5622                         }
5623                         break;
5624
5625                 /* Allow backing up */
5626                 case '-':
5627                         line = line + (reverse ? rows : -rows);
5628                         if (line < 0) line = 0;
5629                         break;
5630
5631                 /* One page up */
5632                 case SKEY_PGUP:
5633                         line = line - rows;
5634                         if (line < 0) line = 0;
5635                         break;
5636
5637                 /* Advance a single line */
5638                 case '\n':
5639                 case '\r':
5640                         line = line + (reverse ? -1 : 1);
5641                         if (line < 0) line = 0;
5642                         break;
5643
5644                 /* Move up / down */
5645                 case '8':
5646                 case SKEY_UP:
5647                         line--;
5648                         if (line < 0) line = 0;
5649                         break;
5650
5651                 case '2':
5652                 case SKEY_DOWN:
5653                         line++;
5654                         break;
5655
5656                 /* Advance one page */
5657                 case ' ':
5658                         line = line + (reverse ? -rows : rows);
5659                         if (line < 0) line = 0;
5660                         break;
5661
5662                 /* One page down */
5663                 case SKEY_PGDOWN:
5664                         line = line + rows;
5665                         break;
5666                 }
5667
5668                 /* Recurse on numbers */
5669                 if (menu)
5670                 {
5671                         int key = -1;
5672
5673                         if (!(skey & SKEY_MASK) && isalpha(skey))
5674                                 key = skey - 'A';
5675
5676                         if ((key > -1) && hook[key][0])
5677                         {
5678                                 /* Recurse on that file */
5679                                 if (!show_file(TRUE, hook[key], NULL, 0, mode))
5680                                         skey = 'q';
5681                         }
5682                 }
5683
5684                 /* Hack, dump to file */
5685                 if (skey == '|')
5686                 {
5687                         FILE *ffp;
5688                         char buff[1024];
5689                         char xtmp[82];
5690
5691                         strcpy (xtmp, "");
5692
5693                         if (!get_string(_("ファイル名: ", "File name: "), xtmp, 80)) continue;
5694                         my_fclose(fff);
5695                         path_build(buff, sizeof(buff), ANGBAND_DIR_USER, xtmp);
5696
5697                         /* Hack -- Re-Open the file */
5698                         fff = my_fopen(path, "r");
5699
5700                         ffp = my_fopen(buff, "w");
5701
5702                         if (!(fff && ffp))
5703                         {
5704                                 msg_print(_("ファイルを開けません。", "Failed to open file."));
5705                                 skey = ESCAPE;
5706                                 break;
5707                         }
5708
5709                         sprintf(xtmp, "%s: %s", p_ptr->name, what ? what : caption);
5710                         my_fputs(ffp, xtmp, 80);
5711                         my_fputs(ffp, "\n", 80);
5712
5713                         while (!my_fgets(fff, buff, sizeof(buff)))
5714                                 my_fputs(ffp, buff, 80);
5715                         my_fclose(fff);
5716                         my_fclose(ffp);
5717
5718                         /* Hack -- Re-Open the file */
5719                         fff = my_fopen(path, "r");
5720                 }
5721
5722                 /* Return to last screen */
5723                 if ((skey == ESCAPE) || (skey == '<')) break;
5724
5725                 /* Exit on the ^q */
5726                 if (skey == KTRL('q')) skey = 'q';
5727
5728                 /* Exit on the q key */
5729                 if (skey == 'q') break;
5730         }
5731         my_fclose(fff);
5732
5733         /* Escape */
5734         if (skey == 'q') return (FALSE);
5735
5736         /* Normal return */
5737         return (TRUE);
5738 }
5739
5740
5741 /*!
5742  * @brief ヘルプを表示するコマンドのメインルーチン
5743  * Peruse the On-Line-Help
5744  * @return なし
5745  * @details
5746  */
5747 void do_cmd_help(void)
5748 {
5749         screen_save();
5750
5751         /* Peruse the main help file */
5752         (void)show_file(TRUE, _("jhelp.hlp", "help.hlp"), NULL, 0, 0);
5753         screen_load();
5754 }
5755
5756
5757 /*!
5758  * @brief プレイヤーの名前をチェックして修正する
5759  * Process the player name.
5760  * @param sf セーブファイル名に合わせた修正を行うならばTRUE
5761  * @return なし
5762  * @details
5763  * Extract a clean "base name".
5764  * Build the savefile name if needed.
5765  */
5766 void process_player_name(bool sf)
5767 {
5768         int i, k = 0;
5769         char old_player_base[32] = "";
5770
5771         if (current_world_ptr->character_generated) strcpy(old_player_base, p_ptr->base_name);
5772
5773         /* Cannot be too long */
5774 #if defined(MACINTOSH) || defined(ACORN)
5775         if (strlen(p_ptr->name) > 15)
5776         {
5777                 /* Name too long */
5778                 quit_fmt(_("'%s'という名前は長すぎます!", "The name '%s' is too long!"), p_ptr->name);
5779         }
5780 #endif
5781
5782         /* Cannot contain "icky" characters */
5783         for (i = 0; p_ptr->name[i]; i++)
5784         {
5785                 /* No control characters */
5786 #ifdef JP
5787                 if (iskanji(p_ptr->name[i])){i++;continue;}
5788                 if (iscntrl( (unsigned char)p_ptr->name[i]))
5789 #else
5790                 if (iscntrl(p_ptr->name[i]))
5791 #endif
5792
5793                 {
5794                         /* Illegal characters */
5795                         quit_fmt(_("'%s' という名前は不正なコントロールコードを含んでいます。", "The name '%s' contains control chars!"), p_ptr->name);
5796                 }
5797         }
5798
5799
5800 #ifdef MACINTOSH
5801
5802         /* Extract "useful" letters */
5803         for (i = 0; p_ptr->name[i]; i++)
5804         {
5805 #ifdef JP
5806                 unsigned char c = p_ptr->name[i];
5807 #else
5808                 char c = p_ptr->name[i];
5809 #endif
5810
5811
5812                 /* Convert "dot" to "underscore" */
5813                 if (c == '.') c = '_';
5814
5815                 /* Accept all the letters */
5816                 p_ptr->base_name[k++] = c;
5817         }
5818
5819 #else
5820
5821         /* Extract "useful" letters */
5822         for (i = 0; p_ptr->name[i]; i++)
5823         {
5824 #ifdef JP
5825                 unsigned char c = p_ptr->name[i];
5826 #else
5827                 char c = p_ptr->name[i];
5828 #endif
5829
5830                 /* Accept some letters */
5831 #ifdef JP
5832                 if(iskanji(c)){
5833                   if(k + 2 >= sizeof(p_ptr->base_name) || !p_ptr->name[i+1]) break;
5834                   p_ptr->base_name[k++] = c;
5835                   i++;
5836                   p_ptr->base_name[k++] = p_ptr->name[i];
5837                 }
5838 #ifdef SJIS
5839                 else if (iskana(c)) p_ptr->base_name[k++] = c;
5840 #endif
5841                 else
5842 #endif
5843                 /* Convert path separator to underscore */
5844                 if (!strncmp(PATH_SEP, p_ptr->name+i, strlen(PATH_SEP))){
5845                         p_ptr->base_name[k++] = '_';
5846                         i += strlen(PATH_SEP);
5847                 }
5848                 /* Convert some characters to underscore */
5849 #if defined(WINDOWS)
5850                 else if (my_strchr("\"*,/:;<>?\\|", c)) p_ptr->base_name[k++] = '_';
5851 #endif
5852                 else if (isprint(c)) p_ptr->base_name[k++] = c;
5853         }
5854
5855 #endif
5856
5857         /* Terminate */
5858         p_ptr->base_name[k] = '\0';
5859
5860         /* Require a "base" name */
5861         if (!p_ptr->base_name[0]) strcpy(p_ptr->base_name, "PLAYER");
5862
5863
5864 #ifdef SAVEFILE_MUTABLE
5865
5866         /* Accept */
5867         sf = TRUE;
5868
5869 #endif
5870         if (!savefile_base[0] && savefile[0])
5871         {
5872                 concptr s;
5873                 s = savefile;
5874                 while (1)
5875                 {
5876                         concptr t;
5877                         t = my_strstr(s, PATH_SEP);
5878                         if (!t)
5879                                 break;
5880                         s = t+1;
5881                 }
5882                 strcpy(savefile_base, s);
5883         }
5884
5885         if (!savefile_base[0] || !savefile[0])
5886                 sf = TRUE;
5887
5888         /* Change the savefile name */
5889         if (sf)
5890         {
5891                 char temp[128];
5892
5893                 strcpy(savefile_base, p_ptr->base_name);
5894
5895 #ifdef SAVEFILE_USE_UID
5896                 /* Rename the savefile, using the p_ptr->player_uid and p_ptr->base_name */
5897                 (void)sprintf(temp, "%d.%s", p_ptr->player_uid, p_ptr->base_name);
5898 #else
5899                 /* Rename the savefile, using the p_ptr->base_name */
5900                 (void)sprintf(temp, "%s", p_ptr->base_name);
5901 #endif
5902                 path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
5903         }
5904
5905         /* Load an autopick preference file */
5906         if (current_world_ptr->character_generated)
5907         {
5908                 if (!streq(old_player_base, p_ptr->base_name)) autopick_load_pref(FALSE);
5909         }
5910 }
5911
5912
5913 /*!
5914  * @brief プレイヤーの名前を変更するコマンドのメインルーチン
5915  * Gets a name for the character, reacting to name changes.
5916  * @return なし
5917  * @details
5918  * <pre>
5919  * Assumes that "display_player()" has just been called
5920  * Perhaps we should NOT ask for a name (at "birth()") on
5921  * Unix machines?  XXX XXX
5922  * What a horrible name for a global function.  
5923  * </pre>
5924  */
5925 void get_name(player_type *creature_ptr)
5926 {
5927         char tmp[64];
5928
5929         /* Save the player name */
5930         strcpy(tmp, creature_ptr->name);
5931
5932         /* Prompt for a new name */
5933         if (get_string(_("キャラクターの名前を入力して下さい: ", "Enter a name for your character: "), tmp, 15))
5934         {
5935                 /* Use the name */
5936                 strcpy(creature_ptr->name, tmp);
5937         }
5938
5939         if (0 == strlen(creature_ptr->name))
5940         {
5941                 /* Use default name */
5942                 strcpy(creature_ptr->name, "PLAYER");
5943         }
5944
5945         strcpy(tmp,ap_ptr->title);
5946 #ifdef JP
5947         if(ap_ptr->no == 1)
5948                 strcat(tmp,"の");
5949 #else
5950         strcat(tmp, " ");
5951 #endif
5952         strcat(tmp,creature_ptr->name);
5953
5954         /* Re-Draw the name (in light blue) */
5955         Term_erase(34, 1, 255);
5956         c_put_str(TERM_L_BLUE, tmp, 1, 34);
5957
5958         /* Erase the prompt, etc */
5959         clear_from(22);
5960 }
5961
5962
5963
5964 /*!
5965  * @brief セーブするコマンドのメインルーチン
5966  * Save the game
5967  * @param creature_ptr プレーヤーへの参照ポインタ
5968  * @param is_autosave オートセーブ中の処理ならばTRUE
5969  * @return なし
5970  * @details
5971  */
5972 void do_cmd_save_game(player_type *creature_ptr, int is_autosave)
5973 {
5974         /* Autosaves do not disturb */
5975         if (is_autosave)
5976         {
5977                 msg_print(_("自動セーブ中", "Autosaving the game..."));
5978         }
5979         else
5980         {
5981                 disturb(p_ptr, TRUE, TRUE);
5982         }
5983
5984         /* Clear messages */
5985         msg_print(NULL);
5986         handle_stuff();
5987
5988         prt(_("ゲームをセーブしています...", "Saving game..."), 0, 0);
5989
5990         Term_fresh();
5991
5992         /* The player is not dead */
5993         (void)strcpy(p_ptr->died_from, _("(セーブ)", "(saved)"));
5994
5995         /* Forbid suspend */
5996         signals_ignore_tstp();
5997
5998         /* Save the player */
5999         if (save_player(creature_ptr))
6000         {
6001                 prt(_("ゲームをセーブしています... 終了", "Saving game... done."), 0, 0);
6002         }
6003
6004         /* Save failed (oops) */
6005         else
6006         {
6007                 prt(_("ゲームをセーブしています... 失敗!", "Saving game... failed!"), 0, 0);
6008         }
6009
6010         /* Allow suspend again */
6011         signals_handle_tstp();
6012
6013         Term_fresh();
6014
6015         /* Note that the player is not dead */
6016         (void)strcpy(p_ptr->died_from, _("(元気に生きている)", "(alive and well)"));
6017
6018         /* HACK -- don't get sanity blast on updating view */
6019         current_world_ptr->is_loading_now = FALSE;
6020
6021         update_creature(p_ptr);
6022
6023         /* Initialize monster process */
6024         mproc_init();
6025
6026         /* HACK -- reset the hackish flag */
6027         current_world_ptr->is_loading_now = TRUE;
6028 }
6029
6030
6031 /*!
6032  * @brief セーブ後にゲーム中断フラグを立てる/
6033  * Save the game and exit
6034  * @return なし
6035  * @details
6036  */
6037 void do_cmd_save_and_exit(void)
6038 {
6039         p_ptr->playing = FALSE;
6040         p_ptr->leaving = TRUE;
6041         exe_write_diary(p_ptr, NIKKI_GAMESTART, 0, _("----ゲーム中断----", "---- Save and Exit Game ----"));
6042 }
6043
6044
6045 #define GRAVE_LINE_WIDTH 31
6046
6047 /*!
6048  * @brief 墓石の真ん中に文字列を書き込む /
6049  * Centers a string within a GRAVE_LINE_WIDTH character string          -JWT-
6050  * @return なし
6051  * @details
6052  */
6053 static void center_string(char *buf, concptr str)
6054 {
6055         int i, j;
6056
6057         /* Total length */
6058         i = strlen(str);
6059
6060         /* Necessary border */
6061         j = GRAVE_LINE_WIDTH / 2 - i / 2;
6062
6063         /* Mega-Hack */
6064         (void)sprintf(buf, "%*s%s%*s", j, "", str, GRAVE_LINE_WIDTH - i - j, "");
6065 }
6066
6067
6068 #if 0
6069 /*!
6070  * @brief 骨ファイル出力 /
6071  * Save a "bones" file for a dead character
6072  * @details
6073  * <pre>
6074  * Note that we will not use these files until Angband 2.8.0, and
6075  * then we will only use the name and level on which death occured.
6076  * Should probably attempt some form of locking...
6077  * </pre>
6078  */
6079 static void make_bones(void)
6080 {
6081         FILE                *fp;
6082
6083         char                str[1024];
6084
6085
6086         /* Ignore wizards and borgs */
6087         if (!(current_world_ptr->noscore & 0x00FF))
6088         {
6089                 /* Ignore people who die in town */
6090                 if (p_ptr->current_floor_ptr->dun_level)
6091                 {
6092                         char tmp[128];
6093
6094                         /* "Bones" name */
6095                         sprintf(tmp, "bone.%03d", p_ptr->current_floor_ptr->dun_level);
6096                         path_build(str, sizeof(str), ANGBAND_DIR_BONE, tmp);
6097
6098                         /* Attempt to open the bones file */
6099                         fp = my_fopen(str, "r");
6100
6101                         /* Close it right away */
6102                         if (fp) my_fclose(fp);
6103
6104                         /* Do not over-write a previous ghost */
6105                         if (fp) return;
6106
6107                         /* File type is "TEXT" */
6108                         FILE_TYPE(FILE_TYPE_TEXT);
6109
6110                         /* Grab permissions */
6111                         safe_setuid_grab();
6112
6113                         /* Try to write a new "Bones File" */
6114                         fp = my_fopen(str, "w");
6115
6116                         /* Drop permissions */
6117                         safe_setuid_drop();
6118
6119                         /* Not allowed to write it?  Weird. */
6120                         if (!fp) return;
6121
6122                         /* Save the info */
6123                         fprintf(fp, "%s\n", p_ptr->name);
6124                         fprintf(fp, "%d\n", p_ptr->mhp);
6125                         fprintf(fp, "%d\n", p_ptr->prace);
6126                         fprintf(fp, "%d\n", p_ptr->pclass);
6127
6128                         /* Close and save the Bones file */
6129                         my_fclose(fp);
6130                 }
6131         }
6132 }
6133 #endif
6134
6135
6136 /*
6137  * Redefinable "print_tombstone" action
6138  */
6139 bool (*tombstone_aux)(void) = NULL;
6140
6141
6142 /*!
6143  * @brief 墓石のアスキーアート表示 /
6144  * Display a "tomb-stone"
6145  * @return なし
6146  */
6147 void print_tomb(void)
6148 {
6149         bool done = FALSE;
6150
6151         /* Do we use a special tombstone ? */
6152         if (tombstone_aux)
6153         {
6154                 /* Use tombstone hook */
6155                 done = (*tombstone_aux)();
6156         }
6157
6158         /* Print the text-tombstone */
6159         if (!done)
6160         {
6161                 concptr   p;
6162                 char   tmp[160];
6163                 char   buf[1024];
6164                 char   dummy[80];
6165                 char   *t;
6166                 FILE   *fp;
6167                 time_t ct = time((time_t)0);
6168 #ifdef JP
6169                 int    extra_line = 0;
6170 #endif
6171                 Term_clear();
6172                 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("dead_j.txt", "dead.txt"));
6173
6174                 /* Open the News file */
6175                 fp = my_fopen(buf, "r");
6176
6177                 /* Dump */
6178                 if (fp)
6179                 {
6180                         int i = 0;
6181
6182                         /* Dump the file to the screen */
6183                         while (0 == my_fgets(fp, buf, sizeof(buf)))
6184                         {
6185                                 /* Display and advance */
6186                                 put_str(buf, i++, 0);
6187                         }
6188
6189                         /* Close */
6190                         my_fclose(fp);
6191                 }
6192
6193                 /* King or Queen */
6194                 if (current_world_ptr->total_winner || (p_ptr->lev > PY_MAX_LEVEL))
6195                 {
6196 #ifdef JP
6197                         /* 英日切り替え */
6198                         p= "偉大なる者";
6199 #else
6200                         p = "Magnificent";
6201 #endif
6202                 }
6203
6204                 /* Normal */
6205                 else
6206                 {
6207                         p =  player_title[p_ptr->pclass][(p_ptr->lev - 1) / 5];
6208                 }
6209
6210                 center_string(buf, p_ptr->name);
6211                 put_str(buf, 6, 11);
6212
6213 #ifndef JP
6214                 center_string(buf, "the");
6215                 put_str(buf, 7, 11);
6216 #endif
6217
6218                 center_string(buf, p);
6219                 put_str(buf, 8, 11);
6220
6221                 center_string(buf, cp_ptr->title);
6222                 put_str(buf, 10, 11);
6223
6224                 (void)sprintf(tmp, _("レベル: %d", "Level: %d"), (int)p_ptr->lev);
6225                 center_string(buf, tmp);
6226                 put_str(buf, 11, 11);
6227
6228                 (void)sprintf(tmp, _("経験値: %ld", "Exp: %ld"), (long)p_ptr->exp);
6229                 center_string(buf, tmp);
6230                 put_str(buf, 12, 11);
6231
6232                 (void)sprintf(tmp, _("所持金: %ld", "AU: %ld"), (long)p_ptr->au);
6233                 center_string(buf, tmp);
6234                 put_str(buf, 13, 11);
6235
6236 #ifdef JP
6237                 /* 墓に刻む言葉をオリジナルより細かく表示 */
6238                 if (streq(p_ptr->died_from, "途中終了"))
6239                 {
6240                         strcpy(tmp, "<自殺>");
6241                 }
6242                 else if (streq(p_ptr->died_from, "ripe"))
6243                 {
6244                         strcpy(tmp, "引退後に天寿を全う");
6245                 }
6246                 else if (streq(p_ptr->died_from, "Seppuku"))
6247                 {
6248                         strcpy(tmp, "勝利の後、切腹");
6249                 }
6250                 else
6251                 {
6252                         roff_to_buf(p_ptr->died_from, GRAVE_LINE_WIDTH + 1, tmp, sizeof tmp);
6253                         t = tmp + strlen(tmp) + 1;
6254                         if (*t)
6255                         {
6256                                 strcpy(dummy, t); /* 2nd line */
6257                                 if (*(t + strlen(t) + 1)) /* Does 3rd line exist? */
6258                                 {
6259                                         for (t = dummy + strlen(dummy) - 2; iskanji(*(t - 1)); t--) /* Loop */;
6260                                         strcpy(t, "…");
6261                                 }
6262                                 else if (my_strstr(tmp, "『") && suffix(dummy, "』"))
6263                                 {
6264                                         char dummy2[80];
6265                                         char *name_head = my_strstr(tmp, "『");
6266                                         sprintf(dummy2, "%s%s", name_head, dummy);
6267                                         if (strlen(dummy2) <= GRAVE_LINE_WIDTH)
6268                                         {
6269                                                 strcpy(dummy, dummy2);
6270                                                 *name_head = '\0';
6271                                         }
6272                                 }
6273                                 else if (my_strstr(tmp, "「") && suffix(dummy, "」"))
6274                                 {
6275                                         char dummy2[80];
6276                                         char *name_head = my_strstr(tmp, "「");
6277                                         sprintf(dummy2, "%s%s", name_head, dummy);
6278                                         if (strlen(dummy2) <= GRAVE_LINE_WIDTH)
6279                                         {
6280                                                 strcpy(dummy, dummy2);
6281                                                 *name_head = '\0';
6282                                         }
6283                                 }
6284                                 center_string(buf, dummy);
6285                                 put_str(buf, 15, 11);
6286                                 extra_line = 1;
6287                         }
6288                 }
6289                 center_string(buf, tmp);
6290                 put_str(buf, 14, 11);
6291
6292                 if (!streq(p_ptr->died_from, "ripe") && !streq(p_ptr->died_from, "Seppuku"))
6293                 {
6294                         if (p_ptr->current_floor_ptr->dun_level == 0)
6295                         {
6296                                 concptr field_name = p_ptr->town_num ? "街" : "荒野";
6297                                 if (streq(p_ptr->died_from, "途中終了"))
6298                                 {
6299                                         sprintf(tmp, "%sで死んだ", field_name);
6300                                 }
6301                                 else
6302                                 {
6303                                         sprintf(tmp, "に%sで殺された", field_name);
6304                                 }
6305                         }
6306                         else
6307                         {
6308                                 if (streq(p_ptr->died_from, "途中終了"))
6309                                 {
6310                                         sprintf(tmp, "地下 %d 階で死んだ", (int)p_ptr->current_floor_ptr->dun_level);
6311                                 }
6312                                 else
6313                                 {
6314                                         sprintf(tmp, "に地下 %d 階で殺された", (int)p_ptr->current_floor_ptr->dun_level);
6315                                 }
6316                         }
6317                         center_string(buf, tmp);
6318                         put_str(buf, 15 + extra_line, 11);
6319                 }
6320 #else
6321                 (void)sprintf(tmp, "Killed on Level %d", p_ptr->current_floor_ptr->dun_level);
6322                 center_string(buf, tmp);
6323                 put_str(buf, 14, 11);
6324
6325                 roff_to_buf(format("by %s.", p_ptr->died_from), GRAVE_LINE_WIDTH + 1, tmp, sizeof tmp);
6326                 center_string(buf, tmp);
6327                 put_str(buf, 15, 11);
6328                 t = tmp + strlen(tmp) + 1;
6329                 if (*t)
6330                 {
6331                         strcpy(dummy, t); /* 2nd line */
6332                         if (*(t + strlen(t) + 1)) /* Does 3rd line exist? */
6333                         {
6334                                 int dummy_len = strlen(dummy);
6335                                 strcpy(dummy + MIN(dummy_len, GRAVE_LINE_WIDTH - 3), "...");
6336                         }
6337                         center_string(buf, dummy);
6338                         put_str(buf, 16, 11);
6339                 }
6340 #endif
6341
6342                 (void)sprintf(tmp, "%-.24s", ctime(&ct));
6343                 center_string(buf, tmp);
6344                 put_str(buf, 17, 11);
6345                 msg_format(_("さようなら、%s!", "Goodbye, %s!"), p_ptr->name);
6346         }
6347 }
6348
6349
6350 /*!
6351  * @brief 死亡、引退時の簡易ステータス表示 /
6352  * Display some character info
6353  * @param creature_ptr プレーヤーへの参照ポインタ
6354  * @return なし
6355  */
6356 void show_info(player_type *creature_ptr)
6357 {
6358         int             i, j, k, l;
6359         object_type *o_ptr;
6360         store_type              *st_ptr;
6361
6362         /* Hack -- Know everything in the inven/equip */
6363         for (i = 0; i < INVEN_TOTAL; i++)
6364         {
6365                 o_ptr = &creature_ptr->inventory_list[i];
6366                 if (!o_ptr->k_idx) continue;
6367
6368                 /* Aware and Known */
6369                 object_aware(o_ptr);
6370                 object_known(o_ptr);
6371         }
6372
6373         for (i = 1; i < max_towns; i++)
6374         {
6375                 st_ptr = &town_info[i].store[STORE_HOME];
6376
6377                 /* Hack -- Know everything in the home */
6378                 for (j = 0; j < st_ptr->stock_num; j++)
6379                 {
6380                         o_ptr = &st_ptr->stock[j];
6381                         if (!o_ptr->k_idx) continue;
6382
6383                         /* Aware and Known */
6384                         object_aware(o_ptr);
6385                         object_known(o_ptr);
6386                 }
6387         }
6388
6389         /* Hack -- Recalculate bonuses */
6390         creature_ptr->update |= (PU_BONUS);
6391         handle_stuff();
6392
6393         /* Flush all input keys */
6394         flush();
6395
6396         msg_erase();
6397
6398
6399         /* Describe options */
6400         prt(_("キャラクターの記録をファイルに書き出すことができます。", "You may now dump a character record to one or more files."), 21, 0);
6401         prt(_("リターンキーでキャラクターを見ます。ESCで中断します。", "Then, hit RETURN to see the character, or ESC to abort."), 22, 0);
6402
6403         /* Dump character records as requested */
6404         while (TRUE)
6405         {
6406                 char out_val[160];
6407
6408                 /* Prompt */
6409                 put_str(_("ファイルネーム: ", "Filename: "), 23, 0);
6410
6411                 /* Default */
6412                 strcpy(out_val, "");
6413
6414                 /* Ask for filename (or abort) */
6415                 if (!askfor(out_val, 60)) return;
6416
6417                 /* Return means "show on screen" */
6418                 if (!out_val[0]) break;
6419                 screen_save();
6420
6421                 /* Dump a character file */
6422                 (void)file_character(creature_ptr, out_val);
6423                 screen_load();
6424         }
6425
6426         update_playtime();
6427         display_player(creature_ptr, 0);
6428
6429         prt(_("何かキーを押すとさらに情報が続きます (ESCで中断): ", "Hit any key to see more information (ESC to abort): "), 23, 0);
6430
6431         /* Allow abort at this point */
6432         if (inkey() == ESCAPE) return;
6433
6434         /* Equipment -- if any */
6435         if (creature_ptr->equip_cnt)
6436         {
6437                 Term_clear();
6438                 (void)show_equip(creature_ptr, 0, USE_FULL, 0);
6439                 prt(_("装備していたアイテム: -続く-", "You are using: -more-"), 0, 0);
6440
6441                 if (inkey() == ESCAPE) return;
6442         }
6443
6444         /* Inventory -- if any */
6445         if (creature_ptr->inven_cnt)
6446         {
6447                 Term_clear();
6448                 (void)show_inven(creature_ptr, 0, USE_FULL, 0);
6449                 prt(_("持っていたアイテム: -続く-", "You are carrying: -more-"), 0, 0);
6450
6451                 if (inkey() == ESCAPE) return;
6452         }
6453
6454         /* Homes in the different towns */
6455         for (l = 1; l < max_towns; l++)
6456         {
6457                 st_ptr = &town_info[l].store[STORE_HOME];
6458
6459                 /* Home -- if anything there */
6460                 if (st_ptr->stock_num)
6461                 {
6462                         /* Display contents of the home */
6463                         for (k = 0, i = 0; i < st_ptr->stock_num; k++)
6464                         {
6465                                 Term_clear();
6466
6467                                 /* Show 12 items */
6468                                 for (j = 0; (j < 12) && (i < st_ptr->stock_num); j++, i++)
6469                                 {
6470                                         GAME_TEXT o_name[MAX_NLEN];
6471                                         char tmp_val[80];
6472
6473                                         /* Acquire item */
6474                                         o_ptr = &st_ptr->stock[i];
6475
6476                                         /* Print header, clear line */
6477                                         sprintf(tmp_val, "%c) ", I2A(j));
6478                                         prt(tmp_val, j+2, 4);
6479
6480                                         /* Display object description */
6481                                         object_desc(o_name, o_ptr, 0);
6482                                         c_put_str(tval_to_attr[o_ptr->tval], o_name, j+2, 7);
6483                                 }
6484
6485                                 prt(format(_("我が家に置いてあったアイテム ( %d ページ): -続く-", "Your home contains (page %d): -more-"), k+1), 0, 0);
6486
6487                                 /* Wait for it */
6488                                 if (inkey() == ESCAPE) return;
6489                         }
6490                 }
6491         }
6492 }
6493
6494
6495 /*!
6496  * @brief 異常発生時のゲーム緊急終了処理 /
6497  * Handle abrupt death of the visual system
6498  * @param creature_ptr プレーヤーへの参照ポインタ
6499  * @return なし
6500  * @details
6501  * <pre>
6502  * This routine is called only in very rare situations, and only
6503  * by certain visual systems, when they experience fatal errors.
6504  * XXX XXX Hack -- clear the death flag when creating a HANGUP
6505  * save file so that player can see tombstone when restart.
6506  * </pre>
6507  */
6508 void exit_game_panic(player_type *creature_ptr)
6509 {
6510         /* If nothing important has happened, just quit */
6511         if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(_("緊急事態", "panic"));
6512
6513         /* Mega-Hack -- see "msg_print()" */
6514         msg_flag = FALSE;
6515
6516         /* Clear the top line */
6517         prt("", 0, 0);
6518
6519         /* Hack -- turn off some things */
6520         disturb(p_ptr, TRUE, TRUE);
6521
6522         /* Mega-Hack -- Delay death */
6523         if (p_ptr->chp < 0) p_ptr->is_dead = FALSE;
6524
6525         /* Hardcode panic save */
6526         p_ptr->panic_save = 1;
6527
6528         /* Forbid suspend */
6529         signals_ignore_tstp();
6530
6531         /* Indicate panic save */
6532         (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
6533
6534         /* Panic save, or get worried */
6535         if (!save_player(creature_ptr)) quit(_("緊急セーブ失敗!", "panic save failed!"));
6536
6537         /* Successful panic save */
6538         quit(_("緊急セーブ成功!", "panic save succeeded!"));
6539 }
6540
6541
6542 /*!
6543  * @brief ファイルからランダムに行を一つ取得する /
6544  * Get a random line from a file
6545  * @param file_name ファイル名
6546  * @param entry 特定条件時のN:タグヘッダID
6547  * @param output 出力先の文字列参照ポインタ
6548  * @return エラーコード
6549  * @details
6550  * <pre>
6551  * Based on the monster speech patch by Matt Graham,
6552  * </pre>
6553  */
6554 errr get_rnd_line(concptr file_name, int entry, char *output)
6555 {
6556         FILE    *fp;
6557         char    buf[1024];
6558         int     counter, test;
6559         int     line_num = 0;
6560
6561         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, file_name);
6562         fp = my_fopen(buf, "r");
6563
6564         /* Failed */
6565         if (!fp) return -1;
6566
6567         /* Find the entry of the monster */
6568         while (TRUE)
6569         {
6570                 /* Get a line from the file */
6571                 if (my_fgets(fp, buf, sizeof(buf)) == 0)
6572                 {
6573                         /* Count the lines */
6574                         line_num++;
6575
6576                         /* Look for lines starting with 'N:' */
6577                         if ((buf[0] == 'N') && (buf[1] == ':'))
6578                         {
6579                                 /* Allow default lines */
6580                                 if (buf[2] == '*')
6581                                 {
6582                                         /* Default lines */
6583                                         break;
6584                                 }
6585                                 else if (buf[2] == 'M')
6586                                 {
6587                                         if (r_info[entry].flags1 & RF1_MALE) break;
6588                                 }
6589                                 else if (buf[2] == 'F')
6590                                 {
6591                                         if (r_info[entry].flags1 & RF1_FEMALE) break;
6592                                 }
6593                                 /* Get the monster number */
6594                                 else if (sscanf(&(buf[2]), "%d", &test) != EOF)
6595                                 {
6596                                         /* Is it the right number? */
6597                                         if (test == entry) break;
6598                                 }
6599                                 else
6600                                 {
6601                                         /* Error while converting the number */
6602                                         msg_format("Error in line %d of %s!", line_num, file_name);
6603                                         my_fclose(fp);
6604                                         return -1;
6605                                 }
6606                         }
6607                 }
6608                 else
6609                 {
6610                         /* Reached end of file */
6611                         my_fclose(fp);
6612                         return -1;
6613                 }
6614         }
6615
6616         /* Get the random line */
6617         for (counter = 0; ; counter++)
6618         {
6619                 while (TRUE)
6620                 {
6621                         test = my_fgets(fp, buf, sizeof(buf));
6622
6623                         /* Count the lines */
6624                         /* line_num++; No more needed */
6625
6626                         if (!test)
6627                         {
6628                                 /* Ignore lines starting with 'N:' */
6629                                 if ((buf[0] == 'N') && (buf[1] == ':')) continue;
6630
6631                                 if (buf[0] != '#') break;
6632                         }
6633                         else break;
6634                 }
6635
6636                 /* Abort */
6637                 if (!buf[0]) break;
6638
6639                 /* Copy the line */
6640                 if (one_in_(counter + 1)) strcpy(output, buf);
6641         }
6642         my_fclose(fp);
6643
6644         /* Success */
6645         return counter ? 0 : -1;
6646 }
6647
6648
6649 #ifdef JP
6650 /*!
6651  * @brief ファイルからランダムに行を一つ取得する(日本語文字列のみ) /
6652  * @param file_name ファイル名
6653  * @param entry 特定条件時のN:タグヘッダID
6654  * @param output 出力先の文字列参照ポインタ
6655  * @param count 試行回数
6656  * @return エラーコード
6657  * @details
6658  */
6659 errr get_rnd_line_jonly(concptr file_name, int entry, char *output, int count)
6660 {
6661         int  i, j, kanji;
6662         errr result = 1;
6663
6664         for (i = 0; i < count; i++)
6665         {
6666                 result = get_rnd_line(file_name, entry, output);
6667                 if (result) break;
6668                 kanji = 0;
6669                 for (j = 0; output[j]; j++) kanji |= iskanji(output[j]);
6670                 if (kanji) break;
6671         }
6672         return result;
6673 }
6674 #endif
6675
6676 /*!
6677  * @brief 自動拾いファイルを読み込む /
6678  * @param name ファイル名
6679  * @details
6680  */
6681 errr process_autopick_file(concptr name)
6682 {
6683         char buf[1024];
6684
6685         errr err = 0;
6686         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
6687
6688         err = process_pref_file_aux(buf, PREF_TYPE_AUTOPICK);
6689         return (err);
6690 }
6691
6692
6693 /*!
6694  * @brief プレイヤーの生い立ちファイルを読み込む /
6695  * Process file for player's history editor.
6696  * @param name ファイル名
6697  * @return エラーコード
6698  * @details
6699  */
6700 errr process_histpref_file(concptr name)
6701 {
6702         char buf[1024];
6703         errr err = 0;
6704         bool old_character_xtra = current_world_ptr->character_xtra;
6705         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
6706
6707         /* Hack -- prevent modification birth options in this file */
6708         current_world_ptr->character_xtra = TRUE;
6709
6710         err = process_pref_file_aux(buf, PREF_TYPE_HISTPREF);
6711
6712         current_world_ptr->character_xtra = old_character_xtra;
6713         return (err);
6714 }
6715
6716 /*!
6717  * @brief ファイル位置をシーク /
6718  * @param fd ファイルディスクリプタ
6719  * @param where ファイルバイト位置
6720  * @param flag FALSEならば現ファイルを超えた位置へシーク時エラー、TRUEなら足りない間を0で埋め尽くす
6721  * @return エラーコード
6722  * @details
6723  */
6724 static errr counts_seek(int fd, u32b where, bool flag)
6725 {
6726         huge seekpoint;
6727         char temp1[128], temp2[128];
6728         u32b zero_header[3] = {0L, 0L, 0L};
6729         int i;
6730
6731 #ifdef SAVEFILE_USE_UID
6732         (void)sprintf(temp1, "%d.%s.%d%d%d", p_ptr->player_uid, savefile_base, p_ptr->pclass, p_ptr->pseikaku, p_ptr->age);
6733 #else
6734         (void)sprintf(temp1, "%s.%d%d%d", savefile_base, p_ptr->pclass, p_ptr->pseikaku, p_ptr->age);
6735 #endif
6736         for (i = 0; temp1[i]; i++)
6737                 temp1[i] ^= (i+1) * 63;
6738
6739         seekpoint = 0;
6740         while (1)
6741         {
6742                 if (fd_seek(fd, seekpoint + 3 * sizeof(u32b)))
6743                         return 1;
6744                 if (fd_read(fd, (char*)(temp2), sizeof(temp2)))
6745                 {
6746                         if (!flag)
6747                                 return 1;
6748                         /* add new name */
6749                         fd_seek(fd, seekpoint);
6750                         fd_write(fd, (char*)zero_header, 3*sizeof(u32b));
6751                         fd_write(fd, (char*)(temp1), sizeof(temp1));
6752                         break;
6753                 }
6754
6755                 if (strcmp(temp1, temp2) == 0)
6756                         break;
6757
6758                 seekpoint += 128 + 3 * sizeof(u32b);
6759         }
6760
6761         return fd_seek(fd, seekpoint + where * sizeof(u32b));
6762 }
6763
6764 /*!
6765  * @brief ファイル位置を読み込む
6766  * @param where ファイルバイト位置
6767  * @return エラーコード
6768  * @details
6769  */
6770 u32b counts_read(int where)
6771 {
6772         int fd;
6773         u32b count = 0;
6774         char buf[1024];
6775
6776         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, _("z_info_j.raw", "z_info.raw"));
6777         fd = fd_open(buf, O_RDONLY);
6778
6779         if (counts_seek(fd, where, FALSE) ||
6780             fd_read(fd, (char*)(&count), sizeof(u32b)))
6781                 count = 0;
6782
6783         (void)fd_close(fd);
6784
6785         return count;
6786 }
6787
6788 /*!
6789  * @brief ファイル位置に書き込む /
6790  * @param where ファイルバイト位置
6791  * @param count 書き込む値
6792  * @return エラーコード
6793  * @details
6794  */
6795 errr counts_write(int where, u32b count)
6796 {
6797         int fd;
6798         char buf[1024];
6799         errr err;
6800
6801         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, _("z_info_j.raw", "z_info.raw"));
6802
6803         /* Grab permissions */
6804         safe_setuid_grab();
6805
6806         fd = fd_open(buf, O_RDWR);
6807
6808         /* Drop permissions */
6809         safe_setuid_drop();
6810
6811         if (fd < 0)
6812         {
6813                 /* File type is "DATA" */
6814                 FILE_TYPE(FILE_TYPE_DATA);
6815
6816                 /* Grab permissions */
6817                 safe_setuid_grab();
6818
6819                 /* Create a new high score file */
6820                 fd = fd_make(buf, 0644);
6821
6822                 /* Drop permissions */
6823                 safe_setuid_drop();
6824         }
6825
6826         /* Grab permissions */
6827         safe_setuid_grab();
6828
6829         err = fd_lock(fd, F_WRLCK);
6830
6831         /* Drop permissions */
6832         safe_setuid_drop();
6833
6834         if (err) return 1;
6835
6836         counts_seek(fd, where, TRUE);
6837         fd_write(fd, (char*)(&count), sizeof(u32b));
6838
6839         /* Grab permissions */
6840         safe_setuid_grab();
6841
6842         err = fd_lock(fd, F_UNLCK);
6843
6844         /* Drop permissions */
6845         safe_setuid_drop();
6846
6847         if (err) return 1;
6848
6849         (void)fd_close(fd);
6850
6851         return 0;
6852 }
6853
6854
6855 #ifdef HANDLE_SIGNALS
6856
6857
6858 #include <signal.h>
6859
6860
6861 /*!
6862  * @brief OSからのシグナルを受けてサスペンド状態に入る /
6863  * Handle signals -- suspend
6864  * @param sig 受け取ったシグナル
6865  * @details
6866  * Actually suspend the game, and then resume cleanly
6867  */
6868 static void handle_signal_suspend(int sig)
6869 {
6870         /* Disable handler */
6871         (void)signal(sig, SIG_IGN);
6872
6873 #ifdef SIGSTOP
6874
6875         /* Flush output */
6876         Term_fresh();
6877
6878         /* Suspend the "Term" */
6879         Term_xtra(TERM_XTRA_ALIVE, 0);
6880
6881         /* Suspend ourself */
6882         (void)kill(0, SIGSTOP);
6883
6884         /* Resume the "Term" */
6885         Term_xtra(TERM_XTRA_ALIVE, 1);
6886
6887         /* Redraw the term */
6888         Term_redraw();
6889
6890         /* Flush the term */
6891         Term_fresh();
6892
6893 #endif
6894
6895         /* Restore handler */
6896         (void)signal(sig, handle_signal_suspend);
6897 }
6898
6899
6900 /*!
6901  * @brief OSからのシグナルを受けて中断、終了する /
6902  * Handle signals -- simple (interrupt and quit)
6903  * @param sig 受け取ったシグナル
6904  * @details
6905  * <pre>
6906  * This function was causing a *huge* number of problems, so it has
6907  * been simplified greatly.  We keep a global variable which counts
6908  * the number of times the user attempts to kill the process, and
6909  * we commit suicide if the user does this a certain number of times.
6910  * We attempt to give "feedback" to the user as he approaches the
6911  * suicide thresh-hold, but without penalizing accidental keypresses.
6912  * To prevent messy accidents, we should reset this global variable
6913  * whenever the user enters a keypress, or something like that.
6914  * </pre>
6915  */
6916 static void handle_signal_simple(int sig)
6917 {
6918         /* Disable handler */
6919         (void)signal(sig, SIG_IGN);
6920
6921
6922         /* Nothing to save, just quit */
6923         if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(NULL);
6924
6925
6926         /* Count the signals */
6927         signal_count++;
6928
6929
6930         /* Terminate dead characters */
6931         if (p_ptr->is_dead)
6932         {
6933                 /* Mark the savefile */
6934                 (void)strcpy(p_ptr->died_from, _("強制終了", "Abortion"));
6935
6936                 forget_lite(p_ptr->current_floor_ptr);
6937                 forget_view(p_ptr->current_floor_ptr);
6938                 clear_mon_lite(p_ptr->current_floor_ptr);
6939
6940                 /* Close stuff */
6941                 close_game(p_ptr);
6942
6943                 /* Quit */
6944                 quit(_("強制終了", "interrupt"));
6945         }
6946
6947         /* Allow suicide (after 5) */
6948         else if (signal_count >= 5)
6949         {
6950                 /* Cause of "death" */
6951                 (void)strcpy(p_ptr->died_from, _("強制終了中", "Interrupting"));
6952
6953                 forget_lite(p_ptr->current_floor_ptr);
6954                 forget_view(p_ptr->current_floor_ptr);
6955                 clear_mon_lite(p_ptr->current_floor_ptr);
6956
6957                 /* Stop playing */
6958                 p_ptr->playing = FALSE;
6959
6960                 /* Suicide */
6961                 p_ptr->is_dead = TRUE;
6962                 p_ptr->leaving = TRUE;
6963
6964                 /* Close stuff */
6965                 close_game(p_ptr);
6966
6967                 /* Quit */
6968                 quit(_("強制終了", "interrupt"));
6969         }
6970
6971         /* Give warning (after 4) */
6972         else if (signal_count >= 4)
6973         {
6974                 /* Make a noise */
6975                 Term_xtra(TERM_XTRA_NOISE, 0);
6976
6977                 /* Clear the top line */
6978                 Term_erase(0, 0, 255);
6979
6980                 /* Display the cause */
6981                 Term_putstr(0, 0, -1, TERM_WHITE, _("熟慮の上の自殺!", "Contemplating suicide!"));
6982
6983                 Term_fresh();
6984         }
6985
6986         /* Give warning (after 2) */
6987         else if (signal_count >= 2)
6988         {
6989                 /* Make a noise */
6990                 Term_xtra(TERM_XTRA_NOISE, 0);
6991         }
6992
6993         /* Restore handler */
6994         (void)signal(sig, handle_signal_simple);
6995 }
6996
6997
6998 /*!
6999  * @brief OSからのシグナルを受けて強制終了する /
7000  * Handle signal -- abort, kill, etc
7001  * @param sig 受け取ったシグナル
7002  * @return なし
7003  * @details
7004  * <pre>
7005  * This function was causing a *huge* number of problems, so it has
7006  * been simplified greatly.  We keep a global variable which counts
7007  * the number of times the user attempts to kill the process, and
7008  * we commit suicide if the user does this a certain number of times.
7009  * We attempt to give "feedback" to the user as he approaches the
7010  * suicide thresh-hold, but without penalizing accidental keypresses.
7011  * To prevent messy accidents, we should reset this global variable
7012  * whenever the user enters a keypress, or something like that.
7013  * </pre>
7014  */
7015 static void handle_signal_abort(int sig)
7016 {
7017         int wid, hgt;
7018
7019         Term_get_size(&wid, &hgt);
7020
7021         /* Disable handler */
7022         (void)signal(sig, SIG_IGN);
7023
7024
7025         /* Nothing to save, just quit */
7026         if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(NULL);
7027
7028
7029         forget_lite(p_ptr->current_floor_ptr);
7030         forget_view(p_ptr->current_floor_ptr);
7031         clear_mon_lite(p_ptr->current_floor_ptr);
7032
7033         /* Clear the bottom line */
7034         Term_erase(0, hgt - 1, 255);
7035
7036         /* Give a warning */
7037         Term_putstr(0, hgt - 1, -1, TERM_RED,
7038         _("恐ろしいソフトのバグが飛びかかってきた!", "A gruesome software bug LEAPS out at you!"));
7039
7040
7041         Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ...", "Panic save..."));
7042
7043         exe_write_diary(p_ptr, NIKKI_GAMESTART, 0, _("----ゲーム異常終了----", "---- Panic Save and Abort Game ----"));
7044
7045         /* Flush output */
7046         Term_fresh();
7047
7048         /* Panic Save */
7049         p_ptr->panic_save = 1;
7050
7051         /* Panic save */
7052         (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
7053
7054         /* Forbid suspend */
7055         signals_ignore_tstp();
7056
7057         /* Attempt to save */
7058         if (save_player(p_ptr))
7059         {
7060                 Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ成功!", "Panic save succeeded!"));
7061         }
7062
7063         /* Save failed */
7064         else
7065         {
7066                 Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ失敗!", "Panic save failed!"));
7067         }
7068
7069         /* Flush output */
7070         Term_fresh();
7071
7072         /* Quit */
7073         quit(_("ソフトのバグ", "software bug"));
7074 }
7075
7076 /*!
7077  * @brief OSからのSIGTSTPシグナルを無視する関数 /
7078  * Ignore SIGTSTP signals (keyboard suspend)
7079  * @return なし
7080  * @details
7081  */
7082 void signals_ignore_tstp(void)
7083 {
7084
7085 #ifdef SIGTSTP
7086         (void)signal(SIGTSTP, SIG_IGN);
7087 #endif
7088
7089 }
7090
7091 /*!
7092  * @brief OSからのSIGTSTPシグナルハンドラ /
7093  * Handle SIGTSTP signals (keyboard suspend)
7094  * @return なし
7095  * @details
7096  */
7097 void signals_handle_tstp(void)
7098 {
7099
7100 #ifdef SIGTSTP
7101         (void)signal(SIGTSTP, handle_signal_suspend);
7102 #endif
7103
7104 }
7105
7106
7107 /*!
7108  * @brief OSからのシグナルハンドルを初期化する /
7109  * Prepare to handle the relevant signals
7110  * @return なし
7111  * @details
7112  */
7113 void signals_init(void)
7114 {
7115
7116 #ifdef SIGHUP
7117         (void)signal(SIGHUP, SIG_IGN);
7118 #endif
7119
7120
7121 #ifdef SIGTSTP
7122         (void)signal(SIGTSTP, handle_signal_suspend);
7123 #endif
7124
7125
7126 #ifdef SIGINT
7127         (void)signal(SIGINT, handle_signal_simple);
7128 #endif
7129
7130 #ifdef SIGQUIT
7131         (void)signal(SIGQUIT, handle_signal_simple);
7132 #endif
7133
7134
7135 #ifdef SIGFPE
7136         (void)signal(SIGFPE, handle_signal_abort);
7137 #endif
7138
7139 #ifdef SIGILL
7140         (void)signal(SIGILL, handle_signal_abort);
7141 #endif
7142
7143 #ifdef SIGTRAP
7144         (void)signal(SIGTRAP, handle_signal_abort);
7145 #endif
7146
7147 #ifdef SIGIOT
7148         (void)signal(SIGIOT, handle_signal_abort);
7149 #endif
7150
7151 #ifdef SIGKILL
7152         (void)signal(SIGKILL, handle_signal_abort);
7153 #endif
7154
7155 #ifdef SIGBUS
7156         (void)signal(SIGBUS, handle_signal_abort);
7157 #endif
7158
7159 #ifdef SIGSEGV
7160         (void)signal(SIGSEGV, handle_signal_abort);
7161 #endif
7162
7163 #ifdef SIGTERM
7164         (void)signal(SIGTERM, handle_signal_abort);
7165 #endif
7166
7167 #ifdef SIGPIPE
7168         (void)signal(SIGPIPE, handle_signal_abort);
7169 #endif
7170
7171 #ifdef SIGEMT
7172         (void)signal(SIGEMT, handle_signal_abort);
7173 #endif
7174
7175 #ifdef SIGDANGER
7176         (void)signal(SIGDANGER, handle_signal_abort);
7177 #endif
7178
7179 #ifdef SIGSYS
7180         (void)signal(SIGSYS, handle_signal_abort);
7181 #endif
7182
7183 #ifdef SIGXCPU
7184         (void)signal(SIGXCPU, handle_signal_abort);
7185 #endif
7186
7187 #ifdef SIGPWR
7188         (void)signal(SIGPWR, handle_signal_abort);
7189 #endif
7190
7191 }
7192
7193
7194 #else   /* HANDLE_SIGNALS */
7195
7196
7197 /*!
7198  * @brief ダミー /
7199  * Do nothing
7200  */
7201 void signals_ignore_tstp(void)
7202 {
7203 }
7204
7205 /*!
7206  * @brief ダミー /
7207  * Do nothing
7208  */
7209 void signals_handle_tstp(void)
7210 {
7211 }
7212
7213 /*!
7214  * @brief ダミー /
7215  * Do nothing
7216  */
7217 void signals_init(void)
7218 {
7219 }
7220 #endif  /* HANDLE_SIGNALS */