OSDN Git Service

[Refactor] #38862 Moved floor*.c to floor/
[hengband/hengband.git] / src / birth / birth.c
1 /*!
2  * @file birth.c
3  * @brief プレイヤーの作成を行う / Create a player character
4  * @date 2013/12/28
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
7  *\n
8  * This software may be copied and distributed for educational, research,\n
9  * and not for profit purposes provided that this copyright and statement\n
10  * are included in all such copies.  Other copyrights may also apply.\n
11  * 2013 Deskull Doxygen向けのコメント整理\n
12  */
13
14 #include "angband.h"
15 #include "core/system-variables.h"
16 #include "core/show-file.h"
17 #include "gameterm.h"
18 #include "io/read-pref-file.h"
19 #include "main/music-definitions-table.h"
20 #include "main/sound-definitions-table.h"
21 #include "market/building.h"
22 #include "util.h"
23
24 #include "artifact.h"
25 #include "autopick/autopick.h"
26 #include "avatar.h"
27 #include "birth/birth.h"
28 #include "birth/birth-explanations-table.h"
29 #include "cmd-pet.h"
30 #include "cmd/cmd-dump.h"
31 #include "cmd/cmd-help.h"
32 #include "dungeon/dungeon-file.h"
33 #include "dungeon/dungeon.h"
34 #include "floor/floor-town.h"
35 #include "floor/floor.h"
36 #include "history.h"
37 #include "io/write-diary.h"
38 #include "japanese.h"
39 #include "market/store.h"
40 #include "monster.h"
41 #include "monsterrace-hook.h"
42 #include "monsterrace.h"
43 #include "object-ego.h"
44 #include "object/object-kind.h"
45 #include "patron.h"
46 #include "player-class.h"
47 #include "player-personality.h"
48 #include "player-sex.h"
49 #include "player-skill.h"
50 #include "player-status.h"
51 #include "player/process-name.h"
52 #include "player/race-info-table.h"
53 #include "quest.h"
54 #include "realm/realm.h"
55 #include "save.h"
56 #include "spell/spells-util.h"
57 #include "spells-status.h"
58 #include "view/display-main-window.h" // 暫定。後で消す.
59 #include "view/display-player.h" // 暫定。後で消す.
60 #include "wild.h"
61 #include "world/world.h"
62
63 /*
64   * The last character rolled,
65   * holded for quick start
66   */
67 birther previous_char;
68
69 /*!
70  * オートローラーの内容を描画する間隔 /
71  * How often the autoroller will update the display and pause
72  * to check for user interuptions.
73  * Bigger values will make the autoroller faster, but slower
74  * system may have problems because the user can't stop the
75  * autoroller for this number of rolls.
76  */
77 #define AUTOROLLER_STEP 5431L
78
79 /*!
80   * ランダムクエストのモンスターを確定するために試行する回数 / Maximum number of tries for selection of a proper quest monster
81   */
82 #define MAX_TRIES 100
83
84 /* 選択可能な職業の最大数 */
85 #define MAX_CLASS_CHOICE MAX_CLASS
86
87 /*! オートローラの能力値的要求水準 / Autoroll limit */
88 static s16b stat_limit[6];
89
90 /*! オートローラの年齢、身長、体重、社会的地位の要求水準 */
91 static struct {
92     s16b agemin, agemax;
93     s16b htmin, htmax;
94     s16b wtmin, wtmax;
95     s16b scmin, scmax;
96 } chara_limit;
97
98 /*! オートローラ中、各能力値が水準を超えた回数 / Autoroll matches */
99 static s32b stat_match[6];
100
101 /*! オートローラの試行回数 / Autoroll round */
102 static s32b auto_round;
103
104 /*!
105  * @brief プレイヤー作成を中断して変愚蛮怒を終了する
106  * @return なし
107  */
108 static void birth_quit(void)
109 {
110     quit(NULL);
111 }
112
113 /*!
114  * @brief 指定されたヘルプファイルを表示する / Show specific help file
115  * @param creature_ptr プレーヤーへの参照ポインタ
116  * @param helpfile ファイル名
117  * @return なし
118  */
119 static void show_help(player_type* creature_ptr, concptr helpfile)
120 {
121     screen_save();
122     (void)show_file(creature_ptr, TRUE, helpfile, NULL, 0, 0);
123     screen_load();
124 }
125
126 /*!
127  * @brief プレイヤーの魔法領域を選択する / Choose from one of the available magical realms
128  * @param choices 選択可能な魔法領域のビット配列
129  * @param count 選択可能な魔法領域を返すポインタ群。
130  * @return 選択した魔法領域のID
131  */
132 static byte choose_realm(player_type* creature_ptr, s32b choices, int* count)
133 {
134     int picks[VALID_REALM] = { 0 };
135     int k, i, cs, os;
136     byte auto_select = REALM_NONE;
137     int n = 0;
138     char c;
139     char sym[VALID_REALM];
140     char p2 = ')';
141     char buf[80], cur[80];
142
143     /* Count the choices */
144     if (choices & CH_LIFE) {
145         (*count)++;
146         auto_select = REALM_LIFE;
147     }
148
149     if (choices & CH_SORCERY) {
150         (*count)++;
151         auto_select = REALM_SORCERY;
152     }
153
154     if (choices & CH_NATURE) {
155         (*count)++;
156         auto_select = REALM_NATURE;
157     }
158
159     if (choices & CH_CHAOS) {
160         (*count)++;
161         auto_select = REALM_CHAOS;
162     }
163
164     if (choices & CH_DEATH) {
165         (*count)++;
166         auto_select = REALM_DEATH;
167     }
168
169     if (choices & CH_TRUMP) {
170         (*count)++;
171         auto_select = REALM_TRUMP;
172     }
173
174     if (choices & CH_ARCANE) {
175         (*count)++;
176         auto_select = REALM_ARCANE;
177     }
178
179     if (choices & CH_ENCHANT) {
180         (*count)++;
181         auto_select = REALM_CRAFT;
182     }
183
184     if (choices & CH_DAEMON) {
185         (*count)++;
186         auto_select = REALM_DAEMON;
187     }
188
189     if (choices & CH_CRUSADE) {
190         (*count)++;
191         auto_select = REALM_CRUSADE;
192     }
193
194     if (choices & CH_MUSIC) {
195         (*count)++;
196         auto_select = REALM_MUSIC;
197     }
198
199     if (choices & CH_HISSATSU) {
200         (*count)++;
201         auto_select = REALM_HISSATSU;
202     }
203
204     if (choices & CH_HEX) {
205         (*count)++;
206         auto_select = REALM_HEX;
207     }
208
209     clear_from(10);
210
211     /* Auto-select the realm */
212     if ((*count) < 2)
213         return auto_select;
214
215     /* Constraint to the 1st realm */
216     if (creature_ptr->realm2 != 255) {
217         if (creature_ptr->pclass == CLASS_PRIEST) {
218             if (is_good_realm(creature_ptr->realm1)) {
219                 choices &= ~(CH_DEATH | CH_DAEMON);
220             } else {
221                 choices &= ~(CH_LIFE | CH_CRUSADE);
222             }
223         }
224     }
225
226     /* Extra info */
227     put_str(_("注意:魔法の領域の選択によりあなたが習得する呪文のタイプが決まります。",
228         "Note: The realm of magic will determine which spells you can learn."), 23, 5);
229
230     cs = 0;
231     for (i = 0; i < 32; i++) {
232         /* Analize realms */
233         if (choices & (1L << i)) {
234             if (creature_ptr->realm1 == i + 1) {
235                 if (creature_ptr->realm2 == 255)
236                     cs = n;
237                 else
238                     continue;
239             }
240             if (creature_ptr->realm2 == i + 1)
241                 cs = n;
242
243             sym[n] = I2A(n);
244
245             sprintf(buf, "%c%c %s", sym[n], p2, realm_names[i + 1]);
246             put_str(buf, 12 + (n / 5), 2 + 15 * (n % 5));
247             picks[n++] = i + 1;
248         }
249     }
250     sprintf(cur, "%c%c %s", '*', p2, _("ランダム", "Random"));
251
252     /* Get a realm */
253     k = -1;
254     os = n;
255     while (TRUE) {
256         /* Move Cursol */
257         if (cs != os) {
258             c_put_str(TERM_WHITE, cur, 12 + (os / 5), 2 + 15 * (os % 5));
259
260             if (cs == n) {
261                 sprintf(cur, "%c%c %s", '*', p2, _("ランダム", "Random"));
262             } else {
263                 sprintf(cur, "%c%c %s", sym[cs], p2, realm_names[picks[cs]]);
264                 sprintf(buf, "%s", realm_names[picks[cs]]);
265                 c_put_str(TERM_L_BLUE, buf, 3, 40);
266                 prt(_("の特徴", ": Characteristic"), 3, 40 + strlen(buf));
267                 prt(realm_subinfo[technic2magic(picks[cs]) - 1], 4, 40);
268             }
269             c_put_str(TERM_YELLOW, cur, 12 + (cs / 5), 2 + 15 * (cs % 5));
270             os = cs;
271         }
272
273         if (k >= 0)
274             break;
275
276         sprintf(buf, _("領域を選んで下さい(%c-%c) ('='初期オプション設定): ", "Choose a realm (%c-%c) ('=' for options): "), sym[0], sym[n - 1]);
277
278         put_str(buf, 10, 10);
279         c = inkey();
280         if (c == 'Q')
281             birth_quit();
282
283         if (c == 'S')
284             return 255;
285
286         if (c == ' ' || c == '\r' || c == '\n') {
287             if (cs == n) {
288                 k = randint0(n);
289                 break;
290             } else {
291                 k = cs;
292                 break;
293             }
294         }
295
296         if (c == '*') {
297             k = randint0(n);
298             break;
299         }
300
301         if (c == '8') {
302             if (cs >= 5)
303                 cs -= 5;
304         }
305
306         if (c == '4') {
307             if (cs > 0)
308                 cs--;
309         }
310
311         if (c == '6') {
312             if (cs < n)
313                 cs++;
314         }
315
316         if (c == '2') {
317             if ((cs + 5) <= n)
318                 cs += 5;
319         }
320
321         k = (islower(c) ? A2I(c) : -1);
322         if ((k >= 0) && (k < n)) {
323             cs = k;
324             continue;
325         }
326
327         k = (isupper(c) ? (26 + c - 'A') : -1);
328         if ((k >= 26) && (k < n)) {
329             cs = k;
330             continue;
331         } else
332             k = -1;
333
334         if (c == '?') {
335             show_help(creature_ptr, _("jmagic.txt#MagicRealms", "magic.txt#MagicRealms"));
336         } else if (c == '=') {
337             screen_save();
338             do_cmd_options_aux(OPT_PAGE_BIRTH, _("初期オプション((*)はスコアに影響)", "Birth option((*)s effect score)"));
339
340             screen_load();
341         } else if (c != '2' && c != '4' && c != '6' && c != '8')
342             bell();
343     }
344
345     clear_from(10);
346     return (byte)(picks[k]);
347 }
348
349 /*!
350  * @brief 選択した魔法領域の解説を表示する / Choose the magical realms
351  * @return ユーザが魔法領域の確定を選んだらTRUEを返す。
352  */
353 static bool get_player_realms(player_type* creature_ptr)
354 {
355     int i, count;
356
357     /* Clean up infomation of modifications */
358     put_str("                                   ", 3, 40);
359     put_str("                                   ", 4, 40);
360     put_str("                                   ", 5, 40);
361
362     /* Select the first realm */
363     creature_ptr->realm1 = REALM_NONE;
364     creature_ptr->realm2 = 255;
365     while (TRUE) {
366         char temp[80 * 10];
367         concptr t;
368         count = 0;
369         creature_ptr->realm1 = choose_realm(creature_ptr, realm_choices1[creature_ptr->pclass], &count);
370
371         if (255 == creature_ptr->realm1)
372             return FALSE;
373         if (!creature_ptr->realm1)
374             break;
375
376         /* Clean up*/
377         clear_from(10);
378         put_str("                                   ", 3, 40);
379         put_str("                                   ", 4, 40);
380         put_str("                                   ", 5, 40);
381
382         roff_to_buf(realm_explanations[technic2magic(creature_ptr->realm1) - 1], 74, temp, sizeof(temp));
383         t = temp;
384         for (i = 0; i < 10; i++) {
385             if (t[0] == 0)
386                 break;
387             else {
388                 prt(t, 12 + i, 3);
389                 t += strlen(t) + 1;
390             }
391         }
392
393         if (count < 2) {
394             prt(_("何かキーを押してください", "Hit any key."), 0, 0);
395             (void)inkey();
396             prt("", 0, 0);
397             break;
398         } else if (get_check_strict(_("よろしいですか?", "Are you sure? "), CHECK_DEFAULT_Y))
399             break;
400     }
401
402     /* Select the second realm */
403     creature_ptr->realm2 = REALM_NONE;
404     if (creature_ptr->realm1) {
405         /* Print the realm */
406         put_str(_("魔法        :", "Magic       :"), 6, 1);
407         c_put_str(TERM_L_BLUE, realm_names[creature_ptr->realm1], 6, 15);
408
409         /* Select the second realm */
410         while (TRUE) {
411             char temp[80 * 8];
412             concptr t;
413
414             count = 0;
415             creature_ptr->realm2 = choose_realm(creature_ptr, realm_choices2[creature_ptr->pclass], &count);
416
417             if (255 == creature_ptr->realm2)
418                 return FALSE;
419             if (!creature_ptr->realm2)
420                 break;
421
422             /* Clean up*/
423             clear_from(10);
424             put_str("                                   ", 3, 40);
425             put_str("                                   ", 4, 40);
426             put_str("                                   ", 5, 40);
427
428             roff_to_buf(realm_explanations[technic2magic(creature_ptr->realm2) - 1], 74, temp, sizeof(temp));
429             t = temp;
430             for (i = 0; i < A_MAX; i++) {
431                 if (t[0] == 0)
432                     break;
433                 else {
434                     prt(t, 12 + i, 3);
435                     t += strlen(t) + 1;
436                 }
437             }
438
439             if (count < 2) {
440                 prt(_("何かキーを押してください", "Hit any key."), 0, 0);
441                 (void)inkey();
442                 prt("", 0, 0);
443                 break;
444             } else if (get_check_strict(_("よろしいですか?", "Are you sure? "), CHECK_DEFAULT_Y))
445                 break;
446         }
447         if (creature_ptr->realm2) {
448             /* Print the realm */
449             c_put_str(TERM_L_BLUE, format("%s, %s", realm_names[creature_ptr->realm1], realm_names[creature_ptr->realm2]), 6, 15);
450         }
451     }
452
453     return TRUE;
454 }
455
456 /*!
457  * @brief プレイヤーのクイックスタート情報をプレイヤー構造体から保存する / Save the current data for later
458  * @param birther_ptr クイックスタート構造体の参照ポインタ
459  * @return なし。
460  */
461 static void save_prev_data(player_type* creature_ptr, birther* birther_ptr)
462 {
463     int i;
464
465     /* Save the data */
466     birther_ptr->psex = creature_ptr->psex;
467     birther_ptr->prace = creature_ptr->prace;
468     birther_ptr->pclass = creature_ptr->pclass;
469     birther_ptr->pseikaku = creature_ptr->pseikaku;
470     birther_ptr->realm1 = creature_ptr->realm1;
471     birther_ptr->realm2 = creature_ptr->realm2;
472     birther_ptr->age = creature_ptr->age;
473     birther_ptr->ht = creature_ptr->ht;
474     birther_ptr->wt = creature_ptr->wt;
475     birther_ptr->sc = creature_ptr->sc;
476     birther_ptr->au = creature_ptr->au;
477
478     /* Save the stats */
479     for (i = 0; i < A_MAX; i++) {
480         birther_ptr->stat_max[i] = creature_ptr->stat_max[i];
481         birther_ptr->stat_max_max[i] = creature_ptr->stat_max_max[i];
482     }
483
484     /* Save the hp */
485     for (i = 0; i < PY_MAX_LEVEL; i++) {
486         birther_ptr->player_hp[i] = creature_ptr->player_hp[i];
487     }
488
489     birther_ptr->chaos_patron = creature_ptr->chaos_patron;
490
491     /* Save the virtues */
492     for (i = 0; i < 8; i++) {
493         birther_ptr->vir_types[i] = creature_ptr->vir_types[i];
494     }
495
496     /* Save the history */
497     for (i = 0; i < 4; i++) {
498         strcpy(birther_ptr->history[i], creature_ptr->history[i]);
499     }
500 }
501
502 /*!
503  * @brief プレイヤーのクイックスタート情報をプレイヤー構造体へ読み込む / Load the previous data
504  * @param swap TRUEならば現在のプレイヤー構造体上との内容をスワップする形で読み込む。
505  * @return なし。
506  */
507 static void load_prev_data(player_type* creature_ptr, bool swap)
508 {
509     int i;
510
511     birther temp;
512
513     /*** Save the current data ***/
514     if (swap)
515         save_prev_data(creature_ptr, &temp);
516
517     /*** Load the previous data ***/
518
519     /* Load the data */
520     creature_ptr->psex = previous_char.psex;
521     creature_ptr->prace = previous_char.prace;
522     creature_ptr->pclass = previous_char.pclass;
523     creature_ptr->pseikaku = previous_char.pseikaku;
524     creature_ptr->realm1 = previous_char.realm1;
525     creature_ptr->realm2 = previous_char.realm2;
526     creature_ptr->age = previous_char.age;
527     creature_ptr->ht = previous_char.ht;
528     creature_ptr->wt = previous_char.wt;
529     creature_ptr->sc = previous_char.sc;
530     creature_ptr->au = previous_char.au;
531
532     /* Load the stats */
533     for (i = 0; i < A_MAX; i++) {
534         creature_ptr->stat_cur[i] = creature_ptr->stat_max[i] = previous_char.stat_max[i];
535         creature_ptr->stat_max_max[i] = previous_char.stat_max_max[i];
536     }
537
538     /* Load the hp */
539     for (i = 0; i < PY_MAX_LEVEL; i++) {
540         creature_ptr->player_hp[i] = previous_char.player_hp[i];
541     }
542     creature_ptr->mhp = creature_ptr->player_hp[0];
543     creature_ptr->chp = creature_ptr->player_hp[0];
544
545     creature_ptr->chaos_patron = previous_char.chaos_patron;
546
547     for (i = 0; i < 8; i++) {
548         creature_ptr->vir_types[i] = previous_char.vir_types[i];
549     }
550
551     /* Load the history */
552     for (i = 0; i < 4; i++) {
553         strcpy(creature_ptr->history[i], previous_char.history[i]);
554     }
555
556     /*** Save the previous data ***/
557     if (swap) {
558         (void)COPY(&previous_char, &temp, birther);
559     }
560 }
561
562 /*!
563  * @brief プレイヤーの能力値表現に基づいて加減算を行う。
564  * @param value 現在の能力値
565  * @param amount 加減算する値
566  * @return 加減算の結果
567  */
568 static int adjust_stat(int value, int amount)
569 {
570     int i;
571
572     /* Negative amounts */
573     if (amount < 0) {
574         /* Apply penalty */
575         for (i = 0; i < (0 - amount); i++) {
576             if (value >= 18 + 10) {
577                 value -= 10;
578             } else if (value > 18) {
579                 value = 18;
580             } else if (value > 3) {
581                 value--;
582             }
583         }
584     }
585
586     /* Positive amounts */
587     else if (amount > 0) {
588         /* Apply reward */
589         for (i = 0; i < amount; i++) {
590             if (value < 18) {
591                 value++;
592             } else {
593                 value += 10;
594             }
595         }
596     }
597
598     /* Return the result */
599     return (value);
600 }
601
602 /*!
603  * @brief プレイヤーの能力値を一通りロールする。 / Roll for a characters stats
604  * @details
605  * calc_bonuses()による、独立ステータスからの副次ステータス算出も行っている。
606  * For efficiency, we include a chunk of "calc_bonuses()".\n
607  * @return なし
608  */
609 static void get_stats(player_type* creature_ptr)
610 {
611     /* Roll and verify some stats */
612     while (TRUE) {
613         int i;
614         int sum = 0;
615
616         /* Roll some dice */
617         for (i = 0; i < 2; i++) {
618             s32b tmp = randint0(60 * 60 * 60);
619             BASE_STATUS val;
620
621             /* Extract 5 + 1d3 + 1d4 + 1d5 */
622             val = 5 + 3;
623             val += tmp % 3;
624             tmp /= 3;
625             val += tmp % 4;
626             tmp /= 4;
627             val += tmp % 5;
628             tmp /= 5;
629
630             /* Save that value */
631             sum += val;
632             creature_ptr->stat_cur[3 * i] = creature_ptr->stat_max[3 * i] = val;
633
634             /* Extract 5 + 1d3 + 1d4 + 1d5 */
635             val = 5 + 3;
636             val += tmp % 3;
637             tmp /= 3;
638             val += tmp % 4;
639             tmp /= 4;
640             val += tmp % 5;
641             tmp /= 5;
642
643             /* Save that value */
644             sum += val;
645             creature_ptr->stat_cur[3 * i + 1] = creature_ptr->stat_max[3 * i + 1] = val;
646
647             /* Extract 5 + 1d3 + 1d4 + 1d5 */
648             val = 5 + 3;
649             val += tmp % 3;
650             tmp /= 3;
651             val += tmp % 4;
652             tmp /= 4;
653             val += (BASE_STATUS)tmp;
654
655             /* Save that value */
656             sum += val;
657             creature_ptr->stat_cur[3 * i + 2] = creature_ptr->stat_max[3 * i + 2] = val;
658         }
659
660         /* Verify totals */
661         if ((sum > 42 + 5 * 6) && (sum < 57 + 5 * 6))
662             break;
663         /* 57 was 54... I hate 'magic numbers' :< TY */
664     }
665 }
666
667 /*!
668  * @brief プレイヤーの限界ステータスを決める。
669  * @return なし
670  */
671 void get_max_stats(player_type* creature_ptr)
672 {
673     int i, j;
674     int dice[6];
675
676     /* Roll and verify some stats */
677     while (TRUE) {
678         /* Roll some dice */
679         for (j = i = 0; i < A_MAX; i++) {
680             /* Roll the dice */
681             dice[i] = randint1(7);
682
683             /* Collect the maximum */
684             j += dice[i];
685         }
686
687         /* Verify totals */
688         if (j == 24)
689             break;
690     }
691
692     /* Acquire the stats */
693     for (i = 0; i < A_MAX; i++) {
694         BASE_STATUS max_max = 18 + 60 + dice[i] * 10;
695
696         /* Save that value */
697         creature_ptr->stat_max_max[i] = max_max;
698         if (creature_ptr->stat_max[i] > max_max)
699             creature_ptr->stat_max[i] = max_max;
700         if (creature_ptr->stat_cur[i] > max_max)
701             creature_ptr->stat_cur[i] = max_max;
702     }
703     creature_ptr->knowledge &= ~(KNOW_STAT);
704     creature_ptr->redraw |= (PR_STATS);
705 }
706
707 /*!
708  * @brief その他「オートローラ中は算出の対象にしない」副次ステータスを処理する / Roll for some info that the auto-roller ignores
709  * @return なし
710  */
711 static void get_extra(player_type* creature_ptr, bool roll_hitdie)
712 {
713     int i, j;
714
715     /* Experience factor */
716     if (creature_ptr->prace == RACE_ANDROID)
717         creature_ptr->expfact = rp_ptr->r_exp;
718     else
719         creature_ptr->expfact = rp_ptr->r_exp + cp_ptr->c_exp;
720
721     if (((creature_ptr->pclass == CLASS_MONK) ||
722         (creature_ptr->pclass == CLASS_FORCETRAINER) ||
723         (creature_ptr->pclass == CLASS_NINJA)) && ((creature_ptr->prace == RACE_KLACKON) ||
724             (creature_ptr->prace == RACE_SPRITE)))
725         creature_ptr->expfact -= 15;
726
727     /* Reset record of race/realm changes */
728     creature_ptr->start_race = creature_ptr->prace;
729     creature_ptr->old_race1 = 0L;
730     creature_ptr->old_race2 = 0L;
731     creature_ptr->old_realm = 0;
732
733     for (i = 0; i < 64; i++) {
734         if (creature_ptr->pclass == CLASS_SORCERER)
735             creature_ptr->spell_exp[i] = SPELL_EXP_MASTER;
736         else if (creature_ptr->pclass == CLASS_RED_MAGE)
737             creature_ptr->spell_exp[i] = SPELL_EXP_SKILLED;
738         else
739             creature_ptr->spell_exp[i] = SPELL_EXP_UNSKILLED;
740     }
741
742     for (i = 0; i < 5; i++)
743         for (j = 0; j < 64; j++)
744             creature_ptr->weapon_exp[i][j] = s_info[creature_ptr->pclass].w_start[i][j];
745     if ((creature_ptr->pseikaku == SEIKAKU_SEXY) && (creature_ptr->weapon_exp[TV_HAFTED - TV_WEAPON_BEGIN][SV_WHIP] < WEAPON_EXP_BEGINNER)) {
746         creature_ptr->weapon_exp[TV_HAFTED - TV_WEAPON_BEGIN][SV_WHIP] = WEAPON_EXP_BEGINNER;
747     }
748
749     for (i = 0; i < GINOU_MAX; i++)
750         creature_ptr->skill_exp[i] = s_info[creature_ptr->pclass].s_start[i];
751
752     /* Hitdice */
753     if (creature_ptr->pclass == CLASS_SORCERER)
754         creature_ptr->hitdie = rp_ptr->r_mhp / 2 + cp_ptr->c_mhp + ap_ptr->a_mhp;
755     else
756         creature_ptr->hitdie = rp_ptr->r_mhp + cp_ptr->c_mhp + ap_ptr->a_mhp;
757
758     /* Roll for hit point unless quick-start */
759     if (roll_hitdie)
760         roll_hitdice(creature_ptr, SPOP_NO_UPDATE);
761
762     /* Initial hitpoints */
763     creature_ptr->mhp = creature_ptr->player_hp[0];
764 }
765
766 /*!
767  * @brief プレイヤーの生い立ちの自動生成を行う。 / Get the racial history, and social class, using the "history charts".
768  * @return なし
769  */
770 static void get_history(player_type* creature_ptr)
771 {
772     int i, n, chart, roll, social_class;
773
774     char *s, *t;
775
776     char buf[240];
777
778     /* Clear the previous history strings */
779     for (i = 0; i < 4; i++)
780         creature_ptr->history[i][0] = '\0';
781
782     /* Clear the history text */
783     buf[0] = '\0';
784
785     /* Initial social class */
786     social_class = randint1(4);
787
788     /* Starting place */
789     switch (creature_ptr->prace) {
790     case RACE_AMBERITE: {
791         chart = 67;
792         break;
793     }
794     case RACE_HUMAN:
795     case RACE_BARBARIAN:
796     case RACE_DUNADAN: {
797         chart = 1;
798         break;
799     }
800     case RACE_HALF_ELF: {
801         chart = 4;
802         break;
803     }
804     case RACE_ELF:
805     case RACE_HIGH_ELF: {
806         chart = 7;
807         break;
808     }
809     case RACE_HOBBIT: {
810         chart = 10;
811         break;
812     }
813     case RACE_GNOME: {
814         chart = 13;
815         break;
816     }
817     case RACE_DWARF: {
818         chart = 16;
819         break;
820     }
821     case RACE_HALF_ORC: {
822         chart = 19;
823         break;
824     }
825     case RACE_HALF_TROLL: {
826         chart = 22;
827         break;
828     }
829     case RACE_DARK_ELF: {
830         chart = 69;
831         break;
832     }
833     case RACE_HALF_OGRE: {
834         chart = 74;
835         break;
836     }
837     case RACE_HALF_GIANT: {
838         chart = 75;
839         break;
840     }
841     case RACE_HALF_TITAN: {
842         chart = 76;
843         break;
844     }
845     case RACE_CYCLOPS: {
846         chart = 77;
847         break;
848     }
849     case RACE_YEEK: {
850         chart = 78;
851         break;
852     }
853     case RACE_KOBOLD: {
854         chart = 82;
855         break;
856     }
857     case RACE_KLACKON: {
858         chart = 84;
859         break;
860     }
861     case RACE_NIBELUNG: {
862         chart = 87;
863         break;
864     }
865     case RACE_DRACONIAN: {
866         chart = 89;
867         break;
868     }
869     case RACE_MIND_FLAYER: {
870         chart = 92;
871         break;
872     }
873     case RACE_IMP: {
874         chart = 94;
875         break;
876     }
877     case RACE_GOLEM: {
878         chart = 98;
879         break;
880     }
881     case RACE_SKELETON: {
882         chart = 102;
883         break;
884     }
885     case RACE_ZOMBIE: {
886         chart = 107;
887         break;
888     }
889     case RACE_VAMPIRE: {
890         chart = 113;
891         break;
892     }
893     case RACE_SPECTRE: {
894         chart = 118;
895         break;
896     }
897     case RACE_SPRITE: {
898         chart = 124;
899         break;
900     }
901     case RACE_BEASTMAN: {
902         chart = 129;
903         break;
904     }
905     case RACE_ENT: {
906         chart = 137;
907         break;
908     }
909     case RACE_ANGEL: {
910         chart = 142;
911         break;
912     }
913     case RACE_DEMON: {
914         chart = 145;
915         break;
916     }
917     case RACE_S_FAIRY: {
918         chart = 148;
919         break;
920     }
921     case RACE_KUTAR: {
922         chart = 154;
923         break;
924     }
925     case RACE_ANDROID: {
926         chart = 155;
927         break;
928     }
929     case RACE_MERFOLK: {
930         chart = 170;
931         break;
932     }
933     default: {
934         chart = 0;
935         break;
936     }
937     }
938
939     /* Process the history */
940     while (chart) {
941         /* Start over */
942         i = 0;
943
944         /* Roll for nobility */
945         roll = randint1(100);
946
947         /* Access the proper entry in the table */
948         while ((chart != bg[i].chart) || (roll > bg[i].roll)) {
949             i++;
950         }
951
952         /* Acquire the textual history */
953         (void)strcat(buf, bg[i].info);
954
955         /* Add in the social class */
956         social_class += (int)(bg[i].bonus) - 50;
957
958         /* Enter the next chart */
959         chart = bg[i].next;
960     }
961
962     /* Verify social class */
963     if (social_class > 100)
964         social_class = 100;
965     else if (social_class < 1)
966         social_class = 1;
967
968     /* Save the social class */
969     creature_ptr->sc = (s16b)social_class;
970
971     /* Skip leading spaces */
972     for (s = buf; *s == ' '; s++) /* loop */
973         ;
974
975     /* Get apparent length */
976     n = strlen(s);
977
978     /* Kill trailing spaces */
979
980     while ((n > 0) && (s[n - 1] == ' '))
981         s[--n] = '\0';
982
983     {
984         char temp[64 * 4];
985         roff_to_buf(s, 60, temp, sizeof(temp));
986         t = temp;
987         for (i = 0; i < 4; i++) {
988             if (t[0] == 0)
989                 break;
990             else {
991                 strcpy(creature_ptr->history[i], t);
992                 t += strlen(t) + 1;
993             }
994         }
995     }
996 }
997
998 /*!
999  * @brief プレイヤーの身長体重を決める / Get character's height and weight
1000  * @return なし
1001  */
1002 void get_height_weight(player_type* creature_ptr)
1003 {
1004     int h_percent; /* 身長が平均にくらべてどのくらい違うか. */
1005
1006     /* Calculate the height/weight for males */
1007     if (creature_ptr->psex == SEX_MALE) {
1008         creature_ptr->ht = randnor(rp_ptr->m_b_ht, rp_ptr->m_m_ht);
1009         h_percent = (int)(creature_ptr->ht) * 100 / (int)(rp_ptr->m_b_ht);
1010         creature_ptr->wt = randnor((int)(rp_ptr->m_b_wt) * h_percent / 100, (int)(rp_ptr->m_m_wt) * h_percent / 300);
1011     }
1012
1013     /* Calculate the height/weight for females */
1014     else if (creature_ptr->psex == SEX_FEMALE) {
1015         creature_ptr->ht = randnor(rp_ptr->f_b_ht, rp_ptr->f_m_ht);
1016         h_percent = (int)(creature_ptr->ht) * 100 / (int)(rp_ptr->f_b_ht);
1017         creature_ptr->wt = randnor((int)(rp_ptr->f_b_wt) * h_percent / 100, (int)(rp_ptr->f_m_wt) * h_percent / 300);
1018     }
1019 }
1020
1021 /*!
1022  * @brief プレイヤーの年齢を決める。 / Computes character's age, height, and weight by henkma
1023  * @details 内部でget_height_weight()も呼び出している。
1024  * @return なし
1025  */
1026 static void get_ahw(player_type* creature_ptr)
1027 {
1028     /* Get character's age */
1029     creature_ptr->age = rp_ptr->b_age + randint1(rp_ptr->m_age);
1030
1031     /* Get character's height and weight */
1032     get_height_weight(creature_ptr);
1033 }
1034
1035 /*!
1036  * @brief プレイヤーの初期所持金を決める。 / Get the player's starting money
1037  * @return なし
1038  */
1039 static void get_money(player_type* creature_ptr)
1040 {
1041     int i, gold;
1042
1043     /* Social Class determines starting gold */
1044     gold = (creature_ptr->sc * 6) + randint1(100) + 300;
1045     if (creature_ptr->pclass == CLASS_TOURIST)
1046         gold += 2000;
1047
1048     /* Process the stats */
1049     for (i = 0; i < A_MAX; i++) {
1050         /* Mega-Hack -- reduce gold for high stats */
1051         if (creature_ptr->stat_max[i] >= 18 + 50)
1052             gold -= 300;
1053         else if (creature_ptr->stat_max[i] >= 18 + 20)
1054             gold -= 200;
1055         else if (creature_ptr->stat_max[i] > 18)
1056             gold -= 150;
1057         else
1058             gold -= (creature_ptr->stat_max[i] - 8) * 10;
1059     }
1060
1061     /* Minimum 100 gold */
1062     if (gold < 100)
1063         gold = 100;
1064
1065     if (creature_ptr->pseikaku == SEIKAKU_NAMAKE)
1066         gold /= 2;
1067     else if (creature_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1068         gold = 10000000;
1069     if (creature_ptr->prace == RACE_ANDROID)
1070         gold /= 5;
1071
1072     /* Save the gold */
1073     creature_ptr->au = gold;
1074 }
1075
1076 /*!
1077  * @brief put_stats()のサブルーチンとして、オートロール中のステータスを表示する / Display stat values, subset of "put_stats()"
1078  * @details See 'display_player(p_ptr, )' for screen layout constraints.
1079  * @return なし
1080  */
1081 static void birth_put_stats(player_type* creature_ptr)
1082 {
1083     int i, j, m, p;
1084     int col;
1085     TERM_COLOR attr;
1086     char buf[80];
1087
1088     if (autoroller) {
1089         col = 42;
1090         /* Put the stats (and percents) */
1091         for (i = 0; i < A_MAX; i++) {
1092             /* Race/Class bonus */
1093             j = rp_ptr->r_adj[i] + cp_ptr->c_adj[i] + ap_ptr->a_adj[i];
1094
1095             /* Obtain the current stat */
1096             m = adjust_stat(creature_ptr->stat_max[i], j);
1097
1098             /* Put the stat */
1099             cnv_stat(m, buf);
1100             c_put_str(TERM_L_GREEN, buf, 3 + i, col + 24);
1101
1102             /* Put the percent */
1103             if (stat_match[i]) {
1104                 if (stat_match[i] > 1000000L) {
1105                     /* Prevent overflow */
1106                     p = stat_match[i] / (auto_round / 1000L);
1107                 } else {
1108                     p = 1000L * stat_match[i] / auto_round;
1109                 }
1110
1111                 attr = (p < 100) ? TERM_YELLOW : TERM_L_GREEN;
1112                 sprintf(buf, "%3d.%d%%", p / 10, p % 10);
1113                 c_put_str(attr, buf, 3 + i, col + 13);
1114             }
1115
1116             /* Never happened */
1117             else {
1118                 c_put_str(TERM_RED, _("(なし)", "(NONE)"), 3 + i, col + 13);
1119             }
1120         }
1121     }
1122 }
1123
1124 /*!
1125  * @brief ベースアイテム構造体の鑑定済みフラグをリセットする。
1126  * @return なし
1127  */
1128 static void k_info_reset(void)
1129 {
1130     int i;
1131
1132     /* Reset the "objects" */
1133     for (i = 1; i < max_k_idx; i++) {
1134         object_kind* k_ptr = &k_info[i];
1135
1136         /* Reset "tried" */
1137         k_ptr->tried = FALSE;
1138
1139         /* Reset "aware" */
1140         k_ptr->aware = FALSE;
1141     }
1142 }
1143
1144 /*!
1145  * @brief プレイヤー構造体の内容を初期値で消去する(名前を除く) / Clear all the global "character" data (without name)
1146  * @return なし
1147  */
1148 static void player_wipe_without_name(player_type* creature_ptr)
1149 {
1150     int i;
1151     player_type tmp;
1152
1153     /* Temporary copy for migration - written back later */
1154     COPY(&tmp, creature_ptr, player_type);
1155
1156     /* Hack -- free the "last message" string */
1157     if (creature_ptr->last_message)
1158         string_free(creature_ptr->last_message);
1159
1160     if (creature_ptr->inventory_list != NULL)
1161         C_WIPE(creature_ptr->inventory_list, INVEN_TOTAL, object_type);
1162
1163     /* Hack -- zero the struct */
1164     (void)WIPE(creature_ptr, player_type);
1165
1166     //TODO: キャラ作成からゲーム開始までに  current_floor_ptr を参照しなければならない処理は今後整理して外す。
1167     creature_ptr->current_floor_ptr = &floor_info;
1168
1169     C_MAKE(creature_ptr->inventory_list, INVEN_TOTAL, object_type);
1170
1171     /* Wipe the history */
1172     for (i = 0; i < 4; i++) {
1173         strcpy(creature_ptr->history[i], "");
1174     }
1175
1176     /* Wipe the quests */
1177     for (i = 0; i < max_q_idx; i++) {
1178         quest_type* const q_ptr = &quest[i];
1179
1180         q_ptr->status = QUEST_STATUS_UNTAKEN;
1181
1182         q_ptr->cur_num = 0;
1183         q_ptr->max_num = 0;
1184         q_ptr->type = 0;
1185         q_ptr->level = 0;
1186         q_ptr->r_idx = 0;
1187         q_ptr->complev = 0;
1188         q_ptr->comptime = 0;
1189     }
1190
1191     /* No weight */
1192     creature_ptr->total_weight = 0;
1193
1194     /* No items */
1195     creature_ptr->inven_cnt = 0;
1196     creature_ptr->equip_cnt = 0;
1197
1198     /* Clear the inventory */
1199     for (i = 0; i < INVEN_TOTAL; i++) {
1200         object_wipe(&creature_ptr->inventory_list[i]);
1201     }
1202
1203     /* Start with no artifacts made yet */
1204     for (i = 0; i < max_a_idx; i++) {
1205         artifact_type* a_ptr = &a_info[i];
1206         a_ptr->cur_num = 0;
1207     }
1208
1209     /* Reset the objects */
1210     k_info_reset();
1211
1212     /* Reset the "monsters" */
1213     for (i = 1; i < max_r_idx; i++) {
1214         monster_race* r_ptr = &r_info[i];
1215
1216         /* Hack -- Reset the counter */
1217         r_ptr->cur_num = 0;
1218
1219         /* Hack -- Reset the max counter */
1220         r_ptr->max_num = 100;
1221
1222         /* Hack -- Reset the max counter */
1223         if (r_ptr->flags1 & RF1_UNIQUE)
1224             r_ptr->max_num = 1;
1225
1226         /* Hack -- Non-unique Nazguls are semi-unique */
1227         else if (r_ptr->flags7 & RF7_NAZGUL)
1228             r_ptr->max_num = MAX_NAZGUL_NUM;
1229
1230         /* Clear visible kills in this life */
1231         r_ptr->r_pkills = 0;
1232
1233         /* Clear all kills in this life */
1234         r_ptr->r_akills = 0;
1235     }
1236
1237     /* Hack -- Well fed player */
1238     creature_ptr->food = PY_FOOD_FULL - 1;
1239
1240     /* Wipe the spells */
1241     if (creature_ptr->pclass == CLASS_SORCERER) {
1242         creature_ptr->spell_learned1 = creature_ptr->spell_learned2 = 0xffffffffL;
1243         creature_ptr->spell_worked1 = creature_ptr->spell_worked2 = 0xffffffffL;
1244     } else {
1245         creature_ptr->spell_learned1 = creature_ptr->spell_learned2 = 0L;
1246         creature_ptr->spell_worked1 = creature_ptr->spell_worked2 = 0L;
1247     }
1248     creature_ptr->spell_forgotten1 = creature_ptr->spell_forgotten2 = 0L;
1249     for (i = 0; i < 64; i++)
1250         creature_ptr->spell_order[i] = 99;
1251     creature_ptr->learned_spells = 0;
1252     creature_ptr->add_spells = 0;
1253     creature_ptr->knowledge = 0;
1254
1255     /* Clean the mutation count */
1256     creature_ptr->mutant_regenerate_mod = 100;
1257
1258     /* Clear "cheat" options */
1259     cheat_peek = FALSE;
1260     cheat_hear = FALSE;
1261     cheat_room = FALSE;
1262     cheat_xtra = FALSE;
1263     cheat_know = FALSE;
1264     cheat_live = FALSE;
1265     cheat_save = FALSE;
1266     cheat_diary_output = FALSE;
1267     cheat_turn = FALSE;
1268
1269     /* Assume no winning game */
1270     current_world_ptr->total_winner = FALSE;
1271
1272     creature_ptr->timewalk = FALSE;
1273
1274     /* Assume no panic save */
1275     creature_ptr->panic_save = 0;
1276
1277     /* Assume no cheating */
1278     current_world_ptr->noscore = 0;
1279     current_world_ptr->wizard = FALSE;
1280
1281     /* Not waiting to report score */
1282     creature_ptr->wait_report_score = FALSE;
1283
1284     /* Default pet command settings */
1285     creature_ptr->pet_follow_distance = PET_FOLLOW_DIST;
1286     creature_ptr->pet_extra_flags = (PF_TELEPORT | PF_ATTACK_SPELL | PF_SUMMON_SPELL);
1287
1288     /* Wipe the recall depths */
1289     for (i = 0; i < current_world_ptr->max_d_idx; i++) {
1290         max_dlv[i] = 0;
1291     }
1292
1293     creature_ptr->visit = 1;
1294
1295     /* Reset wild_mode to FALSE */
1296     creature_ptr->wild_mode = FALSE;
1297
1298     for (i = 0; i < 108; i++) {
1299         creature_ptr->magic_num1[i] = 0;
1300         creature_ptr->magic_num2[i] = 0;
1301     }
1302
1303     /* Level one */
1304     creature_ptr->max_plv = creature_ptr->lev = 1;
1305
1306     /* Initialize arena and rewards information -KMW- */
1307     creature_ptr->arena_number = 0;
1308     creature_ptr->current_floor_ptr->inside_arena = FALSE;
1309     creature_ptr->current_floor_ptr->inside_quest = 0;
1310     for (i = 0; i < MAX_MANE; i++) {
1311         creature_ptr->mane_spell[i] = -1;
1312         creature_ptr->mane_dam[i] = 0;
1313     }
1314
1315     creature_ptr->mane_num = 0;
1316     creature_ptr->exit_bldg = TRUE; /* only used for arena now -KMW- */
1317
1318     /* Bounty */
1319     creature_ptr->today_mon = 0;
1320
1321     /* Reset monster arena */
1322     update_gambling_monsters(creature_ptr);
1323
1324     /* Reset mutations */
1325     creature_ptr->muta1 = 0;
1326     creature_ptr->muta2 = 0;
1327     creature_ptr->muta3 = 0;
1328
1329     /* Reset virtues */
1330     for (i = 0; i < 8; i++)
1331         creature_ptr->virtues[i] = 0;
1332
1333     creature_ptr->dungeon_idx = 0;
1334
1335     /* Set the recall dungeon accordingly */
1336     if (vanilla_town || ironman_downward) {
1337         creature_ptr->recall_dungeon = DUNGEON_ANGBAND;
1338     } else {
1339         creature_ptr->recall_dungeon = DUNGEON_GALGALS;
1340     }
1341
1342     /* Data migration */
1343     memcpy(creature_ptr->name, tmp.name, sizeof(tmp.name));
1344 }
1345
1346 /*!
1347  * @brief ダンジョン内部のクエストを初期化する / Initialize random quests and final quests
1348  * @param creature_ptr プレーヤーへの参照ポインタ
1349  * @return なし
1350  */
1351 static void init_dungeon_quests(player_type* creature_ptr)
1352 {
1353     int number_of_quests = MAX_RANDOM_QUEST - MIN_RANDOM_QUEST + 1;
1354     int i;
1355
1356     /* Init the random quests */
1357     init_flags = INIT_ASSIGN;
1358     floor_type* floor_ptr = creature_ptr->current_floor_ptr;
1359     floor_ptr->inside_quest = MIN_RANDOM_QUEST;
1360
1361     process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
1362
1363     floor_ptr->inside_quest = 0;
1364
1365     /* Generate quests */
1366     for (i = MIN_RANDOM_QUEST + number_of_quests - 1; i >= MIN_RANDOM_QUEST; i--) {
1367         quest_type* q_ptr = &quest[i];
1368         monster_race* quest_r_ptr;
1369
1370         q_ptr->status = QUEST_STATUS_TAKEN;
1371         determine_random_questor(creature_ptr, q_ptr);
1372
1373         /* Mark uniques */
1374         quest_r_ptr = &r_info[q_ptr->r_idx];
1375         quest_r_ptr->flags1 |= RF1_QUESTOR;
1376
1377         q_ptr->max_num = 1;
1378     }
1379
1380     /* Init the two main quests (Oberon + Serpent) */
1381     init_flags = INIT_ASSIGN;
1382     floor_ptr->inside_quest = QUEST_OBERON;
1383
1384     process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
1385
1386     quest[QUEST_OBERON].status = QUEST_STATUS_TAKEN;
1387
1388     floor_ptr->inside_quest = QUEST_SERPENT;
1389
1390     process_dungeon_file(creature_ptr, "q_info.txt", 0, 0, 0, 0);
1391
1392     quest[QUEST_SERPENT].status = QUEST_STATUS_TAKEN;
1393     floor_ptr->inside_quest = 0;
1394 }
1395
1396 /*!
1397  * @brief ゲームターンを初期化する / Reset turn
1398  * @details アンデッド系種族は開始時刻を夜からにする。
1399  * @return なし
1400  */
1401 static void init_turn(player_type* creature_ptr)
1402 {
1403     if ((creature_ptr->prace == RACE_VAMPIRE) || (creature_ptr->prace == RACE_SKELETON) || (creature_ptr->prace == RACE_ZOMBIE) || (creature_ptr->prace == RACE_SPECTRE)) {
1404         /* Undead start just after midnight */
1405         current_world_ptr->game_turn = (TURNS_PER_TICK * 3 * TOWN_DAWN) / 4 + 1;
1406         current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
1407     } else {
1408         current_world_ptr->game_turn = 1;
1409         current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
1410     }
1411
1412     current_world_ptr->dungeon_turn = 1;
1413     current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
1414 }
1415
1416 /*!
1417  * @brief 所持状態にあるアイテムの中から一部枠の装備可能なものを装備させる。
1418  * @return なし
1419  */
1420 static void wield_all(player_type* creature_ptr)
1421 {
1422     object_type* o_ptr;
1423     object_type* i_ptr;
1424     object_type object_type_body;
1425
1426     int slot;
1427     INVENTORY_IDX item;
1428
1429     /* Scan through the slots backwards */
1430     for (item = INVEN_PACK - 1; item >= 0; item--) {
1431         o_ptr = &creature_ptr->inventory_list[item];
1432
1433         /* Skip non-objects */
1434         if (!o_ptr->k_idx)
1435             continue;
1436
1437         /* Make sure we can wield it and that there's nothing else in that slot */
1438         slot = wield_slot(creature_ptr, o_ptr);
1439         if (slot < INVEN_RARM)
1440             continue;
1441         if (slot == INVEN_LITE)
1442             continue; /* Does not wield toaches because buys a lantern soon */
1443         if (creature_ptr->inventory_list[slot].k_idx)
1444             continue;
1445
1446         i_ptr = &object_type_body;
1447         object_copy(i_ptr, o_ptr);
1448         i_ptr->number = 1;
1449
1450         /* Decrease the item (from the pack) */
1451         if (item >= 0) {
1452             inven_item_increase(creature_ptr, item, -1);
1453             inven_item_optimize(creature_ptr, item);
1454         }
1455
1456         /* Decrease the item (from the floor) */
1457         else {
1458             floor_item_increase(creature_ptr->current_floor_ptr, 0 - item, -1);
1459             floor_item_optimize(creature_ptr, 0 - item);
1460         }
1461
1462         o_ptr = &creature_ptr->inventory_list[slot];
1463         object_copy(o_ptr, i_ptr);
1464         creature_ptr->total_weight += i_ptr->weight;
1465
1466         /* Increment the equip counter by hand */
1467         creature_ptr->equip_cnt++;
1468     }
1469     return;
1470 }
1471
1472 /*!
1473  * プレイヤーの職業毎の初期装備テーブル。/\n
1474  * Each player starts out with a few items, given as tval/sval pairs.\n
1475  * In addition, he always has some food and a few torches.\n
1476  */
1477 static byte player_init[MAX_CLASS][3][2] = {
1478     { /* Warrior */
1479         { TV_RING, SV_RING_RES_FEAR }, /* Warriors need it! */
1480         { TV_HARD_ARMOR, SV_CHAIN_MAIL },
1481         { TV_SWORD, SV_BROAD_SWORD } },
1482
1483     { /* Mage */
1484         { TV_SORCERY_BOOK, 0 }, /* Hack: for realm1 book */
1485         { TV_DEATH_BOOK, 0 }, /* Hack: for realm2 book */
1486         { TV_SWORD, SV_DAGGER } },
1487
1488     { /* Priest */
1489         { TV_SORCERY_BOOK, 0 }, /* Hack: for Life / Death book */
1490         { TV_DEATH_BOOK, 0 }, /* Hack: for realm2 book */
1491         { TV_HAFTED, SV_MACE } },
1492
1493     { /* Rogue */
1494         { TV_SORCERY_BOOK, 0 }, /* Hack: for realm1 book */
1495         { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
1496         { TV_SWORD, SV_DAGGER } },
1497
1498     { /* Ranger */
1499         { TV_NATURE_BOOK, 0 },
1500         { TV_DEATH_BOOK, 0 }, /* Hack: for realm2 book */
1501         { TV_SWORD, SV_DAGGER } },
1502
1503     { /* Paladin */
1504         { TV_SORCERY_BOOK, 0 },
1505         { TV_SCROLL, SV_SCROLL_PROTECTION_FROM_EVIL },
1506         { TV_SWORD, SV_BROAD_SWORD } },
1507
1508     { /* Warrior-Mage */
1509         { TV_SORCERY_BOOK, 0 }, /* Hack: for realm1 book */
1510         { TV_DEATH_BOOK, 0 }, /* Hack: for realm2 book */
1511         { TV_SWORD, SV_SHORT_SWORD } },
1512
1513     { /* Chaos Warrior */
1514         { TV_SORCERY_BOOK, 0 }, /* Hack: For realm1 book */
1515         { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
1516         { TV_SWORD, SV_BROAD_SWORD } },
1517
1518     { /* Monk */
1519         { TV_SORCERY_BOOK, 0 },
1520         { TV_POTION, SV_POTION_SPEED },
1521         { TV_POTION, SV_POTION_HEROISM } },
1522
1523     { /* Mindcrafter */
1524         { TV_POTION, SV_POTION_SPEED },
1525         { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
1526         { TV_SWORD, SV_SMALL_SWORD } },
1527
1528     { /* High Mage */
1529         { TV_SORCERY_BOOK, 0 }, /* Hack: for realm1 book */
1530         { TV_RING, SV_RING_SUSTAIN_INT },
1531         { TV_SWORD, SV_DAGGER } },
1532
1533     { /* Tourist */
1534         { TV_FOOD, SV_FOOD_JERKY },
1535         { TV_SCROLL, SV_SCROLL_MAPPING },
1536         { TV_BOW, SV_SLING } },
1537
1538     { /* Imitator */
1539         { TV_POTION, SV_POTION_SPEED },
1540         { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
1541         { TV_SWORD, SV_SHORT_SWORD } },
1542
1543     { /* Beastmaster */
1544         { TV_TRUMP_BOOK, 0 },
1545         { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
1546         { TV_POLEARM, SV_SPEAR } },
1547
1548     { /* Sorcerer */
1549         { TV_HAFTED, SV_WIZSTAFF }, /* Hack: for realm1 book */
1550         { TV_RING, SV_RING_SUSTAIN_INT },
1551         { TV_WAND, SV_WAND_MAGIC_MISSILE } },
1552
1553     {
1554         /* Archer */
1555         { TV_BOW, SV_SHORT_BOW },
1556         { TV_SOFT_ARMOR, SV_LEATHER_SCALE_MAIL },
1557         { TV_SWORD, SV_SHORT_SWORD },
1558     },
1559
1560     {
1561         /* Magic eater */
1562         { TV_WAND, SV_WAND_MAGIC_MISSILE },
1563         { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
1564         { TV_SWORD, SV_SHORT_SWORD },
1565     },
1566
1567     {
1568         /* Bard */
1569         { TV_MUSIC_BOOK, 0 },
1570         { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
1571         { TV_SWORD, SV_SHORT_SWORD },
1572     },
1573
1574     {
1575         /* Red Mage */
1576         { TV_ARCANE_BOOK, 0 },
1577         { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
1578         { TV_SWORD, SV_SHORT_SWORD },
1579     },
1580
1581     { /* Samurai */
1582         { TV_HISSATSU_BOOK, 0 },
1583         { TV_HARD_ARMOR, SV_CHAIN_MAIL },
1584         { TV_SWORD, SV_BROAD_SWORD } },
1585
1586     { /* ForceTrainer */
1587         { TV_SORCERY_BOOK, 0 },
1588         { TV_POTION, SV_POTION_SPEED },
1589         { TV_POTION, SV_POTION_RESTORE_MANA } },
1590
1591     { /* Blue Mage */
1592         { TV_SOFT_ARMOR, SV_ROBE },
1593         { TV_WAND, SV_WAND_MAGIC_MISSILE },
1594         { TV_SWORD, SV_DAGGER } },
1595
1596     { /* Cavalry */
1597         { TV_BOW, SV_SHORT_BOW },
1598         { TV_SOFT_ARMOR, SV_LEATHER_SCALE_MAIL },
1599         { TV_POLEARM, SV_BROAD_SPEAR } },
1600
1601     { /* Berserker */
1602         { TV_POTION, SV_POTION_HEALING },
1603         { TV_HARD_ARMOR, SV_AUGMENTED_CHAIN_MAIL },
1604         { TV_POLEARM, SV_BROAD_AXE } },
1605
1606     { /* Weaponsmith */
1607         { TV_RING, SV_RING_RES_FEAR }, /* Warriors need it! */
1608         { TV_HARD_ARMOR, SV_CHAIN_MAIL },
1609         { TV_POLEARM, SV_BROAD_AXE } },
1610     { /* Mirror-Master */
1611         { TV_POTION, SV_POTION_SPEED },
1612         { TV_RING, SV_RING_SUSTAIN_INT },
1613         { TV_SWORD, SV_DAGGER } },
1614     { /* Ninja */
1615         { TV_POTION, SV_POTION_SPEED },
1616         { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
1617         { TV_SWORD, SV_DAGGER } },
1618     { /* Sniper */
1619         { TV_BOW, SV_LIGHT_XBOW },
1620         { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
1621         { TV_SWORD, SV_DAGGER } },
1622 };
1623
1624 /*!
1625  * @brief 初期所持アイテムの処理 / Add an outfit object
1626  * @details アイテムを既知のものとした上でwield_all()関数により装備させる。
1627  * @param o_ptr 処理したいオブジェクト構造体の参照ポインタ
1628  * @return なし
1629  */
1630 static void add_outfit(player_type* creature_ptr, object_type* o_ptr)
1631 {
1632     s16b slot;
1633
1634     object_aware(creature_ptr, o_ptr);
1635     object_known(o_ptr);
1636     slot = inven_carry(creature_ptr, o_ptr);
1637
1638     /* Auto-inscription */
1639     autopick_alter_item(creature_ptr, slot, FALSE);
1640
1641     /* Now try wielding everything */
1642     wield_all(creature_ptr);
1643 }
1644
1645 /*!
1646  * @brief 種族/職業/性格などに基づき初期所持アイテムを設定するメインセット関数。 / Init players with some belongings
1647  * @details Having an item makes the player "aware" of its purpose.
1648  * @return なし
1649  */
1650 void player_outfit(player_type* creature_ptr)
1651 {
1652     int i;
1653     OBJECT_TYPE_VALUE tv;
1654     OBJECT_SUBTYPE_VALUE sv;
1655
1656     object_type forge;
1657     object_type* q_ptr;
1658
1659     q_ptr = &forge;
1660
1661     /* Give the player some food */
1662     switch (creature_ptr->prace) {
1663     case RACE_VAMPIRE:
1664         /* Nothing! */
1665         /* Vampires can drain blood of creatures */
1666         break;
1667
1668     case RACE_DEMON:
1669         /* Demon can drain vitality from humanoid corpse */
1670         get_mon_num_prep(creature_ptr, monster_hook_human, NULL);
1671
1672         for (i = rand_range(3, 4); i > 0; i--) {
1673             object_prep(q_ptr, lookup_kind(TV_CORPSE, SV_CORPSE));
1674             q_ptr->pval = get_mon_num(creature_ptr, 2, 0);
1675             if (q_ptr->pval) {
1676                 q_ptr->number = 1;
1677                 add_outfit(creature_ptr, q_ptr);
1678             }
1679         }
1680         break;
1681
1682     case RACE_SKELETON:
1683     case RACE_GOLEM:
1684     case RACE_ZOMBIE:
1685     case RACE_SPECTRE:
1686         /* Staff (of Nothing) */
1687         object_prep(q_ptr, lookup_kind(TV_STAFF, SV_STAFF_NOTHING));
1688         q_ptr->number = 1;
1689
1690         add_outfit(creature_ptr, q_ptr);
1691         break;
1692
1693     case RACE_ENT:
1694         /* Potions of Water */
1695         object_prep(q_ptr, lookup_kind(TV_POTION, SV_POTION_WATER));
1696         q_ptr->number = (ITEM_NUMBER)rand_range(15, 23);
1697         add_outfit(creature_ptr, q_ptr);
1698
1699         break;
1700
1701     case RACE_ANDROID:
1702         /* Flasks of oil */
1703         object_prep(q_ptr, lookup_kind(TV_FLASK, SV_ANY));
1704
1705         /* Fuel with oil (move pval to xtra4) */
1706         apply_magic(creature_ptr, q_ptr, 1, AM_NO_FIXED_ART);
1707
1708         q_ptr->number = (ITEM_NUMBER)rand_range(7, 12);
1709         add_outfit(creature_ptr, q_ptr);
1710
1711         break;
1712
1713     default:
1714         /* Food rations */
1715         object_prep(q_ptr, lookup_kind(TV_FOOD, SV_FOOD_RATION));
1716         q_ptr->number = (ITEM_NUMBER)rand_range(3, 7);
1717
1718         add_outfit(creature_ptr, q_ptr);
1719     }
1720     q_ptr = &forge;
1721
1722     if ((creature_ptr->prace == RACE_VAMPIRE) && (creature_ptr->pclass != CLASS_NINJA)) {
1723         /* Hack -- Give the player scrolls of DARKNESS! */
1724         object_prep(q_ptr, lookup_kind(TV_SCROLL, SV_SCROLL_DARKNESS));
1725
1726         q_ptr->number = (ITEM_NUMBER)rand_range(2, 5);
1727
1728         add_outfit(creature_ptr, q_ptr);
1729     } else if (creature_ptr->pclass != CLASS_NINJA) {
1730         /* Hack -- Give the player some torches */
1731         object_prep(q_ptr, lookup_kind(TV_LITE, SV_LITE_TORCH));
1732         q_ptr->number = (ITEM_NUMBER)rand_range(3, 7);
1733         q_ptr->xtra4 = rand_range(3, 7) * 500;
1734
1735         add_outfit(creature_ptr, q_ptr);
1736     }
1737     q_ptr = &forge;
1738
1739     if (creature_ptr->prace == RACE_MERFOLK) {
1740         object_prep(q_ptr, lookup_kind(TV_RING, SV_RING_LEVITATION_FALL));
1741         q_ptr->number = 1;
1742         add_outfit(creature_ptr, q_ptr);
1743     }
1744
1745     if ((creature_ptr->pclass == CLASS_RANGER) || (creature_ptr->pclass == CLASS_CAVALRY)) {
1746         /* Hack -- Give the player some arrows */
1747         object_prep(q_ptr, lookup_kind(TV_ARROW, SV_AMMO_NORMAL));
1748         q_ptr->number = (byte)rand_range(15, 20);
1749
1750         add_outfit(creature_ptr, q_ptr);
1751     }
1752     if (creature_ptr->pclass == CLASS_RANGER) {
1753         /* Hack -- Give the player some arrows */
1754         object_prep(q_ptr, lookup_kind(TV_BOW, SV_SHORT_BOW));
1755
1756         add_outfit(creature_ptr, q_ptr);
1757     } else if (creature_ptr->pclass == CLASS_ARCHER) {
1758         /* Hack -- Give the player some arrows */
1759         object_prep(q_ptr, lookup_kind(TV_ARROW, SV_AMMO_NORMAL));
1760         q_ptr->number = (ITEM_NUMBER)rand_range(15, 20);
1761
1762         add_outfit(creature_ptr, q_ptr);
1763     } else if (creature_ptr->pclass == CLASS_HIGH_MAGE) {
1764         /* Hack -- Give the player some arrows */
1765         object_prep(q_ptr, lookup_kind(TV_WAND, SV_WAND_MAGIC_MISSILE));
1766         q_ptr->number = 1;
1767         q_ptr->pval = (PARAMETER_VALUE)rand_range(25, 30);
1768
1769         add_outfit(creature_ptr, q_ptr);
1770     } else if (creature_ptr->pclass == CLASS_SORCERER) {
1771         OBJECT_TYPE_VALUE book_tval;
1772         for (book_tval = TV_LIFE_BOOK; book_tval <= TV_LIFE_BOOK + MAX_MAGIC - 1; book_tval++) {
1773             /* Hack -- Give the player some arrows */
1774             object_prep(q_ptr, lookup_kind(book_tval, 0));
1775             q_ptr->number = 1;
1776
1777             add_outfit(creature_ptr, q_ptr);
1778         }
1779     } else if (creature_ptr->pclass == CLASS_TOURIST) {
1780         if (creature_ptr->pseikaku != SEIKAKU_SEXY) {
1781             /* Hack -- Give the player some arrows */
1782             object_prep(q_ptr, lookup_kind(TV_SHOT, SV_AMMO_LIGHT));
1783             q_ptr->number = rand_range(15, 20);
1784
1785             add_outfit(creature_ptr, q_ptr);
1786         }
1787
1788         object_prep(q_ptr, lookup_kind(TV_FOOD, SV_FOOD_BISCUIT));
1789         q_ptr->number = rand_range(2, 4);
1790
1791         add_outfit(creature_ptr, q_ptr);
1792
1793         object_prep(q_ptr, lookup_kind(TV_FOOD, SV_FOOD_WAYBREAD));
1794         q_ptr->number = rand_range(2, 4);
1795
1796         add_outfit(creature_ptr, q_ptr);
1797
1798         object_prep(q_ptr, lookup_kind(TV_FOOD, SV_FOOD_JERKY));
1799         q_ptr->number = rand_range(1, 3);
1800
1801         add_outfit(creature_ptr, q_ptr);
1802
1803         object_prep(q_ptr, lookup_kind(TV_FOOD, SV_FOOD_PINT_OF_ALE));
1804         q_ptr->number = rand_range(2, 4);
1805
1806         add_outfit(creature_ptr, q_ptr);
1807
1808         object_prep(q_ptr, lookup_kind(TV_FOOD, SV_FOOD_PINT_OF_WINE));
1809         q_ptr->number = rand_range(2, 4);
1810
1811         add_outfit(creature_ptr, q_ptr);
1812     } else if (creature_ptr->pclass == CLASS_NINJA) {
1813         /* Hack -- Give the player some arrows */
1814         object_prep(q_ptr, lookup_kind(TV_SPIKE, 0));
1815         q_ptr->number = rand_range(15, 20);
1816
1817         add_outfit(creature_ptr, q_ptr);
1818     } else if (creature_ptr->pclass == CLASS_SNIPER) {
1819         /* Hack -- Give the player some bolts */
1820         object_prep(q_ptr, lookup_kind(TV_BOLT, SV_AMMO_NORMAL));
1821         q_ptr->number = rand_range(15, 20);
1822
1823         add_outfit(creature_ptr, q_ptr);
1824     }
1825
1826     if (creature_ptr->pseikaku == SEIKAKU_SEXY) {
1827         player_init[creature_ptr->pclass][2][0] = TV_HAFTED;
1828         player_init[creature_ptr->pclass][2][1] = SV_WHIP;
1829     }
1830
1831     /* Hack -- Give the player three useful objects */
1832     for (i = 0; i < 3; i++) {
1833         /* Look up standard equipment */
1834         tv = player_init[creature_ptr->pclass][i][0];
1835         sv = player_init[creature_ptr->pclass][i][1];
1836
1837         if ((creature_ptr->prace == RACE_ANDROID) && ((tv == TV_SOFT_ARMOR) || (tv == TV_HARD_ARMOR)))
1838             continue;
1839         /* Hack to initialize spellbooks */
1840         if (tv == TV_SORCERY_BOOK)
1841             tv = TV_LIFE_BOOK + creature_ptr->realm1 - 1;
1842         else if (tv == TV_DEATH_BOOK)
1843             tv = TV_LIFE_BOOK + creature_ptr->realm2 - 1;
1844
1845         else if (tv == TV_RING && sv == SV_RING_RES_FEAR && creature_ptr->prace == RACE_BARBARIAN)
1846             /* Barbarians do not need a ring of resist fear */
1847             sv = SV_RING_SUSTAIN_STR;
1848
1849         else if (tv == TV_RING && sv == SV_RING_SUSTAIN_INT && creature_ptr->prace == RACE_MIND_FLAYER) {
1850             tv = TV_POTION;
1851             sv = SV_POTION_RESTORE_MANA;
1852         }
1853         q_ptr = &forge;
1854
1855         /* Hack -- Give the player an object */
1856         object_prep(q_ptr, lookup_kind(tv, sv));
1857
1858         /* Assassins begin the game with a poisoned dagger */
1859         if ((tv == TV_SWORD || tv == TV_HAFTED) && (creature_ptr->pclass == CLASS_ROGUE && creature_ptr->realm1 == REALM_DEATH)) /* Only assassins get a poisoned weapon */
1860         {
1861             q_ptr->name2 = EGO_BRAND_POIS;
1862         }
1863
1864         add_outfit(creature_ptr, q_ptr);
1865     }
1866
1867     /* Hack -- make aware of the water */
1868     k_info[lookup_kind(TV_POTION, SV_POTION_WATER)].aware = TRUE;
1869 }
1870
1871 /*!
1872  * @brief プレイヤーの種族選択を行う / Player race
1873  * @return なし
1874  */
1875 static bool get_player_race(player_type* creature_ptr)
1876 {
1877     int k, n, cs, os;
1878     concptr str;
1879     char c;
1880     char sym[MAX_RACES];
1881     char p2 = ')';
1882     char buf[80], cur[80];
1883
1884     /* Extra info */
1885     clear_from(10);
1886     put_str(_("注意:《種族》によってキャラクターの先天的な資質やボーナスが変化します。",
1887                 "Note: Your 'race' determines various intrinsic factors and bonuses."),
1888         23, 5);
1889
1890     /* Dump races */
1891     for (n = 0; n < MAX_RACES; n++) {
1892         /* Analyze */
1893         rp_ptr = &race_info[n];
1894         str = rp_ptr->title;
1895
1896         /* Display */
1897         if (n < 26)
1898             sym[n] = I2A(n);
1899         else
1900             sym[n] = ('A' + n - 26);
1901         sprintf(buf, "%c%c%s", sym[n], p2, str);
1902         put_str(buf, 12 + (n / 5), 1 + 16 * (n % 5));
1903     }
1904
1905     sprintf(cur, "%c%c%s", '*', p2, _("ランダム", "Random"));
1906
1907     /* Choose */
1908     k = -1;
1909     cs = creature_ptr->prace;
1910     os = MAX_RACES;
1911     while (TRUE) {
1912         /* Move Cursol */
1913         if (cs != os) {
1914             c_put_str(TERM_WHITE, cur, 12 + (os / 5), 1 + 16 * (os % 5));
1915             put_str("                                   ", 3, 40);
1916             if (cs == MAX_RACES) {
1917                 sprintf(cur, "%c%c%s", '*', p2, _("ランダム", "Random"));
1918                 put_str("                                   ", 4, 40);
1919                 put_str("                                   ", 5, 40);
1920             } else {
1921                 rp_ptr = &race_info[cs];
1922                 str = rp_ptr->title;
1923                 sprintf(cur, "%c%c%s", sym[cs], p2, str);
1924                 c_put_str(TERM_L_BLUE, rp_ptr->title, 3, 40);
1925                 put_str(_("腕力 知能 賢さ 器用 耐久 魅力 経験 ", "Str  Int  Wis  Dex  Con  Chr   EXP "), 4, 40);
1926                 put_str(_("の種族修正", ": Race modification"), 3, 40 + strlen(rp_ptr->title));
1927
1928                 sprintf(buf, "%+3d  %+3d  %+3d  %+3d  %+3d  %+3d %+4d%% ",
1929                     rp_ptr->r_adj[0], rp_ptr->r_adj[1], rp_ptr->r_adj[2], rp_ptr->r_adj[3],
1930                     rp_ptr->r_adj[4], rp_ptr->r_adj[5], (rp_ptr->r_exp - 100));
1931                 c_put_str(TERM_L_BLUE, buf, 5, 40);
1932             }
1933             c_put_str(TERM_YELLOW, cur, 12 + (cs / 5), 1 + 16 * (cs % 5));
1934             os = cs;
1935         }
1936
1937         if (k >= 0)
1938             break;
1939
1940         sprintf(buf, _("種族を選んで下さい (%c-%c) ('='初期オプション設定): ", "Choose a race (%c-%c) ('=' for options): "), sym[0], sym[MAX_RACES - 1]);
1941
1942         put_str(buf, 10, 10);
1943         c = inkey();
1944         if (c == 'Q')
1945             birth_quit();
1946         if (c == 'S')
1947             return FALSE;
1948         if (c == ' ' || c == '\r' || c == '\n') {
1949             if (cs == MAX_RACES) {
1950                 k = randint0(MAX_RACES);
1951                 cs = k;
1952                 continue;
1953             } else {
1954                 k = cs;
1955                 break;
1956             }
1957         }
1958         if (c == '*') {
1959             k = randint0(MAX_RACES);
1960             cs = k;
1961             continue;
1962         }
1963         if (c == '8') {
1964             if (cs >= 5)
1965                 cs -= 5;
1966         }
1967         if (c == '4') {
1968             if (cs > 0)
1969                 cs--;
1970         }
1971         if (c == '6') {
1972             if (cs < MAX_RACES)
1973                 cs++;
1974         }
1975         if (c == '2') {
1976             if ((cs + 5) <= MAX_RACES)
1977                 cs += 5;
1978         }
1979         k = (islower(c) ? A2I(c) : -1);
1980         if ((k >= 0) && (k < MAX_RACES)) {
1981             cs = k;
1982             continue;
1983         }
1984         k = (isupper(c) ? (26 + c - 'A') : -1);
1985         if ((k >= 26) && (k < MAX_RACES)) {
1986             cs = k;
1987             continue;
1988         } else
1989             k = -1;
1990         if (c == '?') {
1991 #ifdef JP
1992             show_help(creature_ptr, "jraceclas.txt#TheRaces");
1993 #else
1994             show_help(creature_ptr, "raceclas.txt#TheRaces");
1995 #endif
1996         } else if (c == '=') {
1997             screen_save();
1998             do_cmd_options_aux(OPT_PAGE_BIRTH, _("初期オプション((*)はスコアに影響)", "Birth Option((*)s effect score)"));
1999             screen_load();
2000         } else if (c != '2' && c != '4' && c != '6' && c != '8')
2001             bell();
2002     }
2003
2004     /* Set race */
2005     creature_ptr->prace = (byte)k;
2006
2007     rp_ptr = &race_info[creature_ptr->prace];
2008
2009     /* Display */
2010     c_put_str(TERM_L_BLUE, rp_ptr->title, 4, 15);
2011
2012     /* Success */
2013     return TRUE;
2014 }
2015
2016 /*!
2017  * @brief プレイヤーの職業選択を行う / Player class
2018  * @return なし
2019  */
2020 static bool get_player_class(player_type* creature_ptr)
2021 {
2022     int k, n, cs, os;
2023     char c;
2024     char sym[MAX_CLASS_CHOICE];
2025     char p2 = ')';
2026     char buf[80], cur[80];
2027     concptr str;
2028
2029     /* Extra info */
2030     clear_from(10);
2031     put_str(_("注意:《職業》によってキャラクターの先天的な能力やボーナスが変化します。",
2032                 "Note: Your 'class' determines various intrinsic abilities and bonuses."),
2033         23, 5);
2034
2035     put_str(_("()で囲まれた選択肢はこの種族には似合わない職業です。",
2036                 "Any entries in parentheses should only be used by advanced players."),
2037         11, 5);
2038
2039     /* Dump classes */
2040     for (n = 0; n < MAX_CLASS_CHOICE; n++) {
2041         /* Analyze */
2042         cp_ptr = &class_info[n];
2043         mp_ptr = &m_info[n];
2044         str = cp_ptr->title;
2045         if (n < 26)
2046             sym[n] = I2A(n);
2047         else
2048             sym[n] = ('A' + n - 26);
2049
2050         /* Display */
2051         if (!(rp_ptr->choice & (1L << n)))
2052             sprintf(buf, "%c%c(%s)", sym[n], p2, str);
2053         else
2054             sprintf(buf, "%c%c%s", sym[n], p2, str);
2055
2056         put_str(buf, 13 + (n / 4), 2 + 19 * (n % 4));
2057     }
2058
2059     sprintf(cur, "%c%c%s", '*', p2, _("ランダム", "Random"));
2060
2061     /* Get a class */
2062     k = -1;
2063     cs = creature_ptr->pclass;
2064     os = MAX_CLASS_CHOICE;
2065     while (TRUE) {
2066         /* Move Cursol */
2067         if (cs != os) {
2068             c_put_str(TERM_WHITE, cur, 13 + (os / 4), 2 + 19 * (os % 4));
2069             put_str("                                   ", 3, 40);
2070             if (cs == MAX_CLASS_CHOICE) {
2071                 sprintf(cur, "%c%c%s", '*', p2, _("ランダム", "Random"));
2072                 put_str("                                   ", 4, 40);
2073                 put_str("                                   ", 5, 40);
2074             } else {
2075                 cp_ptr = &class_info[cs];
2076                 mp_ptr = &m_info[cs];
2077                 str = cp_ptr->title;
2078                 if (!(rp_ptr->choice & (1L << cs)))
2079                     sprintf(cur, "%c%c(%s)", sym[cs], p2, str);
2080                 else
2081                     sprintf(cur, "%c%c%s", sym[cs], p2, str);
2082
2083                 c_put_str(TERM_L_BLUE, cp_ptr->title, 3, 40);
2084                 put_str(_("の職業修正", ": Class modification"), 3, 40 + strlen(cp_ptr->title));
2085                 put_str(_("腕力 知能 賢さ 器用 耐久 魅力 経験 ", "Str  Int  Wis  Dex  Con  Chr   EXP "), 4, 40);
2086                 sprintf(buf, "%+3d  %+3d  %+3d  %+3d  %+3d  %+3d %+4d%% ",
2087                     cp_ptr->c_adj[0], cp_ptr->c_adj[1], cp_ptr->c_adj[2], cp_ptr->c_adj[3],
2088                     cp_ptr->c_adj[4], cp_ptr->c_adj[5], cp_ptr->c_exp);
2089                 c_put_str(TERM_L_BLUE, buf, 5, 40);
2090             }
2091             c_put_str(TERM_YELLOW, cur, 13 + (cs / 4), 2 + 19 * (cs % 4));
2092             os = cs;
2093         }
2094
2095         if (k >= 0)
2096             break;
2097
2098         sprintf(buf, _("職業を選んで下さい (%c-%c) ('='初期オプション設定): ", "Choose a class (%c-%c) ('=' for options): "), sym[0], sym[MAX_CLASS_CHOICE - 1]);
2099
2100         put_str(buf, 10, 10);
2101         c = inkey();
2102         if (c == 'Q')
2103             birth_quit();
2104         if (c == 'S')
2105             return FALSE;
2106         if (c == ' ' || c == '\r' || c == '\n') {
2107             if (cs == MAX_CLASS_CHOICE) {
2108                 k = randint0(MAX_CLASS_CHOICE);
2109                 cs = k;
2110                 continue;
2111             } else {
2112                 k = cs;
2113                 break;
2114             }
2115         }
2116         if (c == '*') {
2117             k = randint0(MAX_CLASS_CHOICE);
2118             cs = k;
2119             continue;
2120         }
2121         if (c == '8') {
2122             if (cs >= 4)
2123                 cs -= 4;
2124         }
2125         if (c == '4') {
2126             if (cs > 0)
2127                 cs--;
2128         }
2129         if (c == '6') {
2130             if (cs < MAX_CLASS_CHOICE)
2131                 cs++;
2132         }
2133         if (c == '2') {
2134             if ((cs + 4) <= MAX_CLASS_CHOICE)
2135                 cs += 4;
2136         }
2137         k = (islower(c) ? A2I(c) : -1);
2138         if ((k >= 0) && (k < MAX_CLASS_CHOICE)) {
2139             cs = k;
2140             continue;
2141         }
2142         k = (isupper(c) ? (26 + c - 'A') : -1);
2143         if ((k >= 26) && (k < MAX_CLASS_CHOICE)) {
2144             cs = k;
2145             continue;
2146         } else
2147             k = -1;
2148         if (c == '?') {
2149 #ifdef JP
2150             show_help(creature_ptr, "jraceclas.txt#TheClasses");
2151 #else
2152             show_help(creature_ptr, "raceclas.txt#TheClasses");
2153 #endif
2154         } else if (c == '=') {
2155             screen_save();
2156             do_cmd_options_aux(OPT_PAGE_BIRTH, _("初期オプション((*)はスコアに影響)", "Birth Option((*)s effect score)"));
2157             screen_load();
2158         } else if (c != '2' && c != '4' && c != '6' && c != '8')
2159             bell();
2160     }
2161
2162     /* Set class */
2163     creature_ptr->pclass = (byte)k;
2164     cp_ptr = &class_info[creature_ptr->pclass];
2165     mp_ptr = &m_info[creature_ptr->pclass];
2166
2167     /* Display */
2168     c_put_str(TERM_L_BLUE, cp_ptr->title, 5, 15);
2169
2170     return TRUE;
2171 }
2172
2173 /*!
2174  * @brief プレイヤーの性格選択を行う / Player Player seikaku
2175  * @return なし
2176  */
2177 static bool get_player_seikaku(player_type* creature_ptr)
2178 {
2179     int k;
2180     int n, os, cs;
2181     char c;
2182     char sym[MAX_SEIKAKU];
2183     char p2 = ')';
2184     char buf[80], cur[80];
2185     char tmp[64];
2186     concptr str;
2187
2188     /* Extra info */
2189     clear_from(10);
2190     put_str(_("注意:《性格》によってキャラクターの能力やボーナスが変化します。", "Note: Your personality determines various intrinsic abilities and bonuses."), 23, 5);
2191
2192     /* Dump seikakus */
2193     for (n = 0; n < MAX_SEIKAKU; n++) {
2194         if (seikaku_info[n].sex && (seikaku_info[n].sex != (creature_ptr->psex + 1)))
2195             continue;
2196
2197         /* Analyze */
2198         ap_ptr = &seikaku_info[n];
2199         str = ap_ptr->title;
2200         if (n < 26)
2201             sym[n] = I2A(n);
2202         else
2203             sym[n] = ('A' + n - 26);
2204
2205         /* Display */
2206         sprintf(buf, "%c%c%s", I2A(n), p2, str);
2207         put_str(buf, 12 + (n / 4), 2 + 18 * (n % 4));
2208     }
2209
2210     sprintf(cur, "%c%c%s", '*', p2, _("ランダム", "Random"));
2211
2212     /* Get a seikaku */
2213     k = -1;
2214     cs = creature_ptr->pseikaku;
2215     os = MAX_SEIKAKU;
2216     while (TRUE) {
2217         /* Move Cursol */
2218         if (cs != os) {
2219             c_put_str(TERM_WHITE, cur, 12 + (os / 4), 2 + 18 * (os % 4));
2220             put_str("                                   ", 3, 40);
2221             if (cs == MAX_SEIKAKU) {
2222                 sprintf(cur, "%c%c%s", '*', p2, _("ランダム", "Random"));
2223                 put_str("                                   ", 4, 40);
2224                 put_str("                                   ", 5, 40);
2225             } else {
2226                 ap_ptr = &seikaku_info[cs];
2227                 str = ap_ptr->title;
2228                 sprintf(cur, "%c%c%s", sym[cs], p2, str);
2229                 c_put_str(TERM_L_BLUE, ap_ptr->title, 3, 40);
2230                 put_str(_("の性格修正", ": Personality modification"), 3, 40 + strlen(ap_ptr->title));
2231                 put_str(_("腕力 知能 賢さ 器用 耐久 魅力      ", "Str  Int  Wis  Dex  Con  Chr       "), 4, 40);
2232                 sprintf(buf, "%+3d  %+3d  %+3d  %+3d  %+3d  %+3d       ",
2233                     ap_ptr->a_adj[0], ap_ptr->a_adj[1], ap_ptr->a_adj[2], ap_ptr->a_adj[3],
2234                     ap_ptr->a_adj[4], ap_ptr->a_adj[5]);
2235                 c_put_str(TERM_L_BLUE, buf, 5, 40);
2236             }
2237             c_put_str(TERM_YELLOW, cur, 12 + (cs / 4), 2 + 18 * (cs % 4));
2238             os = cs;
2239         }
2240
2241         if (k >= 0)
2242             break;
2243
2244         sprintf(buf, _("性格を選んで下さい (%c-%c) ('='初期オプション設定): ", "Choose a personality (%c-%c) ('=' for options): "), sym[0], sym[MAX_SEIKAKU - 1]);
2245
2246         put_str(buf, 10, 10);
2247         c = inkey();
2248         if (c == 'Q')
2249             birth_quit();
2250         if (c == 'S')
2251             return FALSE;
2252         if (c == ' ' || c == '\r' || c == '\n') {
2253             if (cs == MAX_SEIKAKU) {
2254                 do {
2255                     k = randint0(MAX_SEIKAKU);
2256                 } while (seikaku_info[k].sex && (seikaku_info[k].sex != (creature_ptr->psex + 1)));
2257                 cs = k;
2258                 continue;
2259             } else {
2260                 k = cs;
2261                 break;
2262             }
2263         }
2264         if (c == '*') {
2265             do {
2266                 k = randint0(n);
2267             } while (seikaku_info[k].sex && (seikaku_info[k].sex != (creature_ptr->psex + 1)));
2268             cs = k;
2269             continue;
2270         }
2271         if (c == '8') {
2272             if (cs >= 4)
2273                 cs -= 4;
2274             if (cs != MAX_SEIKAKU && seikaku_info[cs].sex && (seikaku_info[cs].sex != (creature_ptr->psex + 1))) {
2275                 if ((cs - 4) > 0)
2276                     cs -= 4;
2277                 else
2278                     cs += 4;
2279             }
2280         }
2281         if (c == '4') {
2282             if (cs > 0)
2283                 cs--;
2284             if (cs != MAX_SEIKAKU && seikaku_info[cs].sex && (seikaku_info[cs].sex != (creature_ptr->psex + 1))) {
2285                 if ((cs - 1) > 0)
2286                     cs--;
2287                 else
2288                     cs++;
2289             }
2290         }
2291         if (c == '6') {
2292             if (cs < MAX_SEIKAKU)
2293                 cs++;
2294             if (cs != MAX_SEIKAKU && seikaku_info[cs].sex && (seikaku_info[cs].sex != (creature_ptr->psex + 1))) {
2295                 if ((cs + 1) <= MAX_SEIKAKU)
2296                     cs++;
2297                 else
2298                     cs--;
2299             }
2300         }
2301         if (c == '2') {
2302             if ((cs + 4) <= MAX_SEIKAKU)
2303                 cs += 4;
2304             if (cs != MAX_SEIKAKU && seikaku_info[cs].sex && (seikaku_info[cs].sex != (creature_ptr->psex + 1))) {
2305                 if ((cs + 4) <= MAX_SEIKAKU)
2306                     cs += 4;
2307                 else
2308                     cs -= 4;
2309             }
2310         }
2311         k = (islower(c) ? A2I(c) : -1);
2312         if ((k >= 0) && (k < MAX_SEIKAKU)) {
2313             if ((seikaku_info[k].sex == 0) || (seikaku_info[k].sex == (creature_ptr->psex + 1))) {
2314                 cs = k;
2315                 continue;
2316             }
2317         }
2318         k = (isupper(c) ? (26 + c - 'A') : -1);
2319         if ((k >= 26) && (k < MAX_SEIKAKU)) {
2320             if ((seikaku_info[k].sex == 0) || (seikaku_info[k].sex == (creature_ptr->psex + 1))) {
2321                 cs = k;
2322                 continue;
2323             }
2324         } else
2325             k = -1;
2326         if (c == '?') {
2327 #ifdef JP
2328             show_help(creature_ptr, "jraceclas.txt#ThePersonalities");
2329 #else
2330             show_help(creature_ptr, "raceclas.txt#ThePersonalities");
2331 #endif
2332         } else if (c == '=') {
2333             screen_save();
2334             do_cmd_options_aux(OPT_PAGE_BIRTH, _("初期オプション((*)はスコアに影響)", "Birth Option((*)s effect score)"));
2335             screen_load();
2336         } else if (c != '2' && c != '4' && c != '6' && c != '8')
2337             bell();
2338     }
2339
2340     /* Set seikaku */
2341     creature_ptr->pseikaku = (CHARACTER_IDX)k;
2342     ap_ptr = &seikaku_info[creature_ptr->pseikaku];
2343 #ifdef JP
2344     strcpy(tmp, ap_ptr->title);
2345     if (ap_ptr->no == 1)
2346         strcat(tmp, "の");
2347 #else
2348     strcpy(tmp, ap_ptr->title);
2349     strcat(tmp, " ");
2350 #endif
2351     strcat(tmp, creature_ptr->name);
2352
2353     c_put_str(TERM_L_BLUE, tmp, 1, 34);
2354
2355     return TRUE;
2356 }
2357
2358 /*!
2359  * @brief オートローラで得たい能力値の基準を決める。
2360  * @param creature_ptr プレーヤーへの参照ポインタ
2361  * @return なし
2362  */
2363 static bool get_stat_limits(player_type* creature_ptr)
2364 {
2365     int i, j, m, cs, os;
2366     int cval[6];
2367     char c;
2368     char buf[80], cur[80];
2369     char inp[80];
2370
2371     /* Clean up */
2372     clear_from(10);
2373
2374     /* Extra infomation */
2375     put_str(_("最低限得たい能力値を設定して下さい。", "Set minimum stats."), 10, 10);
2376     put_str(_("2/8で項目選択、4/6で値の増減、Enterで次へ", "2/8 for Select, 4/6 for Change value, Enter for Goto next"), 11, 10);
2377
2378     put_str(_("         基本値  種族 職業 性格     合計値  最大値", "           Base   Rac  Cla  Per      Total  Maximum"), 13, 10);
2379
2380     /* Output the maximum stats */
2381     for (i = 0; i < A_MAX; i++) {
2382         /* Reset the "success" counter */
2383         stat_match[i] = 0;
2384         cval[i] = 3;
2385
2386         /* Race/Class bonus */
2387         j = rp_ptr->r_adj[i] + cp_ptr->c_adj[i] + ap_ptr->a_adj[i];
2388
2389         /* Obtain the "maximal" stat */
2390         m = adjust_stat(17, j);
2391
2392         /* Above 18 */
2393         if (m > 18) {
2394             sprintf(cur, "18/%02d", (m - 18));
2395         }
2396
2397         /* From 3 to 18 */
2398         else {
2399             sprintf(cur, "%2d", m);
2400         }
2401
2402         /* Obtain the current stat */
2403         m = adjust_stat(cval[i], j);
2404
2405         /* Above 18 */
2406         if (m > 18) {
2407             sprintf(inp, "18/%02d", (m - 18));
2408         }
2409
2410         /* From 3 to 18 */
2411         else {
2412             sprintf(inp, "%2d", m);
2413         }
2414
2415         /* Prepare a prompt */
2416         sprintf(buf, "%6s       %2d   %+3d  %+3d  %+3d  =  %6s  %6s",
2417             stat_names[i], cval[i], rp_ptr->r_adj[i], cp_ptr->c_adj[i],
2418             ap_ptr->a_adj[i], inp, cur);
2419
2420         /* Dump the prompt */
2421         put_str(buf, 14 + i, 10);
2422     }
2423
2424     /* Get a minimum stat */
2425     cs = 0;
2426     os = 6;
2427     while (TRUE) {
2428         /* Move Cursol */
2429         if (cs != os) {
2430             if (os == 6) {
2431                 c_put_str(TERM_WHITE, _("決定する", "Accept"), 21, 35);
2432             } else if (os < A_MAX) {
2433                 c_put_str(TERM_WHITE, cur, 14 + os, 10);
2434             }
2435             if (cs == 6) {
2436                 c_put_str(TERM_YELLOW, _("決定する", "Accept"), 21, 35);
2437             } else {
2438                 /* Race/Class bonus */
2439                 j = rp_ptr->r_adj[cs] + cp_ptr->c_adj[cs] + ap_ptr->a_adj[cs];
2440
2441                 /* Obtain the current stat */
2442                 m = adjust_stat(cval[cs], j);
2443
2444                 /* Above 18 */
2445                 if (m > 18) {
2446                     sprintf(inp, "18/%02d", (m - 18));
2447                 }
2448
2449                 /* From 3 to 18 */
2450                 else {
2451                     sprintf(inp, "%2d", m);
2452                 }
2453
2454                 /* Prepare a prompt */
2455                 sprintf(cur, "%6s       %2d   %+3d  %+3d  %+3d  =  %6s",
2456                     stat_names[cs], cval[cs], rp_ptr->r_adj[cs],
2457                     cp_ptr->c_adj[cs], ap_ptr->a_adj[cs], inp);
2458                 c_put_str(TERM_YELLOW, cur, 14 + cs, 10);
2459             }
2460             os = cs;
2461         }
2462
2463         /* Prompt for the minimum stats */
2464         c = inkey();
2465         switch (c) {
2466         case 'Q':
2467             birth_quit();
2468             break;
2469         case 'S':
2470             return FALSE;
2471         case ESCAPE:
2472             break;
2473         case ' ':
2474         case '\r':
2475         case '\n':
2476             if (cs == 6)
2477                 break;
2478             cs++;
2479             c = '2';
2480             break;
2481         case '8':
2482         case 'k':
2483             if (cs > 0)
2484                 cs--;
2485             break;
2486         case '2':
2487         case 'j':
2488             if (cs < A_MAX)
2489                 cs++;
2490             break;
2491         case '4':
2492         case 'h':
2493             if (cs != 6) {
2494                 if (cval[cs] == 3) {
2495                     cval[cs] = 17;
2496                     os = 7;
2497                 } else if (cval[cs] > 3) {
2498                     cval[cs]--;
2499                     os = 7;
2500                 } else
2501                     return FALSE;
2502             }
2503             break;
2504         case '6':
2505         case 'l':
2506             if (cs != 6) {
2507                 if (cval[cs] == 17) {
2508                     cval[cs] = 3;
2509                     os = 7;
2510                 } else if (cval[cs] < 17) {
2511                     cval[cs]++;
2512                     os = 7;
2513                 } else
2514                     return FALSE;
2515             }
2516             break;
2517         case 'm':
2518             if (cs != 6) {
2519                 cval[cs] = 17;
2520                 os = 7;
2521             }
2522             break;
2523         case 'n':
2524             if (cs != 6) {
2525                 cval[cs] = 3;
2526                 os = 7;
2527             }
2528             break;
2529         case '?':
2530 #ifdef JP
2531             show_help(creature_ptr, "jbirth.txt#AutoRoller");
2532 #else
2533             show_help(creature_ptr, "birth.txt#AutoRoller");
2534 #endif
2535             break;
2536         case '=':
2537             screen_save();
2538 #ifdef JP
2539             do_cmd_options_aux(OPT_PAGE_BIRTH, "初期オプション((*)はスコアに影響)");
2540 #else
2541             do_cmd_options_aux(OPT_PAGE_BIRTH, "Birth Option((*)s effect score)");
2542 #endif
2543
2544             screen_load();
2545             break;
2546         default:
2547             bell();
2548             break;
2549         }
2550         if (c == ESCAPE || ((c == ' ' || c == '\r' || c == '\n') && cs == 6))
2551             break;
2552     }
2553
2554     for (i = 0; i < A_MAX; i++) {
2555         /* Save the minimum stat */
2556         stat_limit[i] = (s16b)cval[i];
2557     }
2558
2559     return TRUE;
2560 }
2561
2562 /*!
2563  * @brief オートローラで得たい年齢、身長、体重、社会的地位の基準を決める。
2564  * @return なし
2565  */
2566 static bool get_chara_limits(player_type* creature_ptr)
2567 {
2568 #define MAXITEMS 8
2569
2570     int i, j, m, cs, os;
2571     int mval[MAXITEMS], cval[MAXITEMS];
2572     int max_percent, min_percent;
2573     char c;
2574     char buf[80], cur[80];
2575     concptr itemname[] = {
2576         _("年齢", "age"),
2577         _("身長(インチ)", "height"),
2578         _("体重(ポンド)", "weight"),
2579         _("社会的地位", "social class")
2580     };
2581
2582     clear_from(10);
2583
2584     /* Prompt for the minimum stats */
2585     put_str(_("2/4/6/8で項目選択、+/-で値の増減、Enterで次へ",
2586         "2/4/6/8 for Select, +/- for Change value, Enter for Goto next"), 11, 10);
2587     put_str(_("注意:身長と体重の最大値/最小値ぎりぎりの値は非常に出現確率が低くなります。",
2588         "Caution: Values near minimum or maximum are extremely rare."), 23, 2);
2589
2590     if (creature_ptr->psex == SEX_MALE) {
2591         max_percent = (int)(rp_ptr->m_b_ht + rp_ptr->m_m_ht * 4 - 1) * 100 / (int)(rp_ptr->m_b_ht);
2592         min_percent = (int)(rp_ptr->m_b_ht - rp_ptr->m_m_ht * 4 + 1) * 100 / (int)(rp_ptr->m_b_ht);
2593     } else {
2594         max_percent = (int)(rp_ptr->f_b_ht + rp_ptr->f_m_ht * 4 - 1) * 100 / (int)(rp_ptr->f_b_ht);
2595         min_percent = (int)(rp_ptr->f_b_ht - rp_ptr->f_m_ht * 4 + 1) * 100 / (int)(rp_ptr->f_b_ht);
2596     }
2597
2598     put_str(_("体格/地位の最小値/最大値を設定して下さい。", "Set minimum/maximum attribute."), 10, 10);
2599     put_str(_("  項    目                 最小値  最大値", " Parameter                    Min     Max"), 13, 20);
2600
2601     /* Output the maximum stats */
2602     for (i = 0; i < MAXITEMS; i++) {
2603         /* Obtain the "maximal" stat */
2604         switch (i) {
2605         case 0: /* Minimum age */
2606             m = rp_ptr->b_age + 1;
2607             break;
2608         case 1: /* Maximum age */
2609             m = rp_ptr->b_age + rp_ptr->m_age;
2610             break;
2611
2612         case 2: /* Minimum height */
2613             if (creature_ptr->psex == SEX_MALE)
2614                 m = rp_ptr->m_b_ht - rp_ptr->m_m_ht * 4 + 1;
2615             else
2616                 m = rp_ptr->f_b_ht - rp_ptr->f_m_ht * 4 + 1;
2617             break;
2618         case 3: /* Maximum height */
2619             if (creature_ptr->psex == SEX_MALE)
2620                 m = rp_ptr->m_b_ht + rp_ptr->m_m_ht * 4 - 1;
2621             else
2622                 m = rp_ptr->f_b_ht + rp_ptr->f_m_ht * 4 - 1;
2623             break;
2624         case 4: /* Minimum weight */
2625             if (creature_ptr->psex == SEX_MALE)
2626                 m = (rp_ptr->m_b_wt * min_percent / 100) - (rp_ptr->m_m_wt * min_percent / 75) + 1;
2627             else
2628                 m = (rp_ptr->f_b_wt * min_percent / 100) - (rp_ptr->f_m_wt * min_percent / 75) + 1;
2629             break;
2630         case 5: /* Maximum weight */
2631             if (creature_ptr->psex == SEX_MALE)
2632                 m = (rp_ptr->m_b_wt * max_percent / 100) + (rp_ptr->m_m_wt * max_percent / 75) - 1;
2633             else
2634                 m = (rp_ptr->f_b_wt * max_percent / 100) + (rp_ptr->f_m_wt * max_percent / 75) - 1;
2635             break;
2636         case 6: /* Minimum social class */
2637             m = 1;
2638             break;
2639         case 7: /* Maximum social class */
2640             m = 100;
2641             break;
2642         default:
2643             m = 1;
2644             break;
2645         }
2646
2647         /* Save the maximum or minimum */
2648         mval[i] = m;
2649         cval[i] = m;
2650     }
2651
2652     for (i = 0; i < 4; i++) {
2653         /* Prepare a prompt */
2654         sprintf(buf, "%-12s (%3d - %3d)", itemname[i], mval[i * 2], mval[i * 2 + 1]);
2655
2656         /* Dump the prompt */
2657         put_str(buf, 14 + i, 20);
2658
2659         for (j = 0; j < 2; j++) {
2660             sprintf(buf, "     %3d", cval[i * 2 + j]);
2661             put_str(buf, 14 + i, 45 + 8 * j);
2662         }
2663     }
2664
2665     /* Get a minimum stat */
2666     cs = 0;
2667     os = MAXITEMS;
2668     while (TRUE) {
2669         /* Move Cursol */
2670         if (cs != os) {
2671             const char accept[] = _("決定する", "Accept");
2672
2673             if (os == MAXITEMS) {
2674                 c_put_str(TERM_WHITE, accept, 19, 35);
2675             } else {
2676                 c_put_str(TERM_WHITE, cur, 14 + os / 2, 45 + 8 * (os % 2));
2677             }
2678
2679             if (cs == MAXITEMS) {
2680                 c_put_str(TERM_YELLOW, accept, 19, 35);
2681             } else {
2682                 /* Prepare a prompt */
2683                 sprintf(cur, "     %3d", cval[cs]);
2684                 c_put_str(TERM_YELLOW, cur, 14 + cs / 2, 45 + 8 * (cs % 2));
2685             }
2686             os = cs;
2687         }
2688
2689         /* Prompt for the minimum stats */
2690         c = inkey();
2691         switch (c) {
2692         case 'Q':
2693             birth_quit();
2694             break;
2695         case 'S':
2696             return FALSE;
2697         case ESCAPE:
2698             break; /*後でもう一回breakせんと*/
2699         case ' ':
2700         case '\r':
2701         case '\n':
2702             if (cs == MAXITEMS)
2703                 break;
2704             cs++;
2705             c = '6';
2706             break;
2707         case '8':
2708         case 'k':
2709             if (cs - 2 >= 0)
2710                 cs -= 2;
2711             break;
2712         case '2':
2713         case 'j':
2714             if (cs < MAXITEMS)
2715                 cs += 2;
2716             if (cs > MAXITEMS)
2717                 cs = MAXITEMS;
2718             break;
2719         case '4':
2720         case 'h':
2721             if (cs > 0)
2722                 cs--;
2723             break;
2724         case '6':
2725         case 'l':
2726             if (cs < MAXITEMS)
2727                 cs++;
2728             break;
2729         case '-':
2730         case '<':
2731             if (cs != MAXITEMS) {
2732                 if (cs % 2) {
2733                     if (cval[cs] > cval[cs - 1]) {
2734                         cval[cs]--;
2735                         os = 127;
2736                     }
2737                 } else {
2738                     if (cval[cs] > mval[cs]) {
2739                         cval[cs]--;
2740                         os = 127;
2741                     }
2742                 }
2743             }
2744             break;
2745         case '+':
2746         case '>':
2747             if (cs != MAXITEMS) {
2748                 if (cs % 2) {
2749                     if (cval[cs] < mval[cs]) {
2750                         cval[cs]++;
2751                         os = 127;
2752                     }
2753                 } else {
2754                     if (cval[cs] < cval[cs + 1]) {
2755                         cval[cs]++;
2756                         os = 127;
2757                     }
2758                 }
2759             }
2760             break;
2761         case 'm':
2762             if (cs != MAXITEMS) {
2763                 if (cs % 2) {
2764                     if (cval[cs] < mval[cs]) {
2765                         cval[cs] = mval[cs];
2766                         os = 127;
2767                     }
2768                 } else {
2769                     if (cval[cs] < cval[cs + 1]) {
2770                         cval[cs] = cval[cs + 1];
2771                         os = 127;
2772                     }
2773                 }
2774             }
2775             break;
2776         case 'n':
2777             if (cs != MAXITEMS) {
2778                 if (cs % 2) {
2779                     if (cval[cs] > cval[cs - 1]) {
2780                         cval[cs] = cval[cs - 1];
2781                         os = 255;
2782                     }
2783                 } else {
2784                     if (cval[cs] > mval[cs]) {
2785                         cval[cs] = mval[cs];
2786                         os = 255;
2787                     }
2788                 }
2789             }
2790             break;
2791         case '?':
2792 #ifdef JP
2793             show_help(creature_ptr, "jbirth.txt#AutoRoller");
2794 #else
2795             show_help(creature_ptr, "birth.txt#AutoRoller");
2796 #endif
2797             break;
2798         case '=':
2799             screen_save();
2800             do_cmd_options_aux(OPT_PAGE_BIRTH, _("初期オプション((*)はスコアに影響)", "Birth Option((*)s effect score)"));
2801             screen_load();
2802             break;
2803         default:
2804             bell();
2805             break;
2806         }
2807         if (c == ESCAPE || ((c == ' ' || c == '\r' || c == '\n') && cs == MAXITEMS))
2808             break;
2809     }
2810
2811     /* Input the minimum stats */
2812     chara_limit.agemin = (s16b)cval[0];
2813     chara_limit.agemax = (s16b)cval[1];
2814     chara_limit.htmin = (s16b)cval[2];
2815     chara_limit.htmax = (s16b)cval[3];
2816     chara_limit.wtmin = (s16b)cval[4];
2817     chara_limit.wtmax = (s16b)cval[5];
2818     chara_limit.scmin = (s16b)cval[6];
2819     chara_limit.scmax = (s16b)cval[7];
2820
2821     return TRUE;
2822 }
2823
2824 #define HISTPREF_LIMIT 1024
2825 static char* histpref_buf = NULL;
2826
2827 /*!
2828  * @brief 生い立ちメッセージの内容をバッファに加える。 / Hook function for reading the histpref.prf file.
2829  * @return なし
2830  */
2831 void add_history_from_pref_line(concptr t)
2832 {
2833     /* Do nothing if the buffer is not ready */
2834     if (!histpref_buf)
2835         return;
2836
2837     my_strcat(histpref_buf, t, HISTPREF_LIMIT);
2838 }
2839
2840 /*!
2841  * @brief 生い立ちメッセージをファイルからロードする。
2842  * @return なし
2843  */
2844 static bool do_cmd_histpref(player_type* creature_ptr, void (*process_autopick_file_command)(char*))
2845 {
2846     char buf[80];
2847     errr err;
2848     int i, j, n;
2849     char *s, *t;
2850     char temp[64 * 4];
2851     char histbuf[HISTPREF_LIMIT];
2852
2853     if (!get_check(_("生い立ち設定ファイルをロードしますか? ", "Load background history preference file? ")))
2854         return FALSE;
2855
2856     /* Prepare the buffer */
2857     histbuf[0] = '\0';
2858     histpref_buf = histbuf;
2859
2860 #ifdef JP
2861     sprintf(buf, "histedit-%s.prf", creature_ptr->base_name);
2862 #else
2863     sprintf(buf, "histpref-%s.prf", creature_ptr->base_name);
2864 #endif
2865     err = process_histpref_file(creature_ptr, buf, process_autopick_file_command);
2866
2867     /* Process 'hist????.prf' if 'hist????-<name>.prf' doesn't exist */
2868     if (0 > err) {
2869 #ifdef JP
2870         strcpy(buf, "histedit.prf");
2871 #else
2872         strcpy(buf, "histpref.prf");
2873 #endif
2874         err = process_histpref_file(creature_ptr, buf, process_autopick_file_command);
2875     }
2876
2877     if (err) {
2878         msg_print(_("生い立ち設定ファイルの読み込みに失敗しました。", "Failed to load background history preference."));
2879         msg_print(NULL);
2880
2881         /* Kill the buffer */
2882         histpref_buf = NULL;
2883
2884         return FALSE;
2885     } else if (!histpref_buf[0]) {
2886         msg_print(_("有効な生い立ち設定はこのファイルにありません。", "There does not exist valid background history preference."));
2887         msg_print(NULL);
2888
2889         /* Kill the buffer */
2890         histpref_buf = NULL;
2891
2892         return FALSE;
2893     }
2894
2895     /* Clear the previous history strings */
2896     for (i = 0; i < 4; i++)
2897         creature_ptr->history[i][0] = '\0';
2898
2899     /* Skip leading spaces */
2900     for (s = histpref_buf; *s == ' '; s++) /* loop */
2901         ;
2902
2903     /* Get apparent length */
2904     n = strlen(s);
2905
2906     /* Kill trailing spaces */
2907     while ((n > 0) && (s[n - 1] == ' '))
2908         s[--n] = '\0';
2909
2910     roff_to_buf(s, 60, temp, sizeof(temp));
2911     t = temp;
2912     for (i = 0; i < 4; i++) {
2913         if (t[0] == 0)
2914             break;
2915         else {
2916             strcpy(creature_ptr->history[i], t);
2917             t += strlen(t) + 1;
2918         }
2919     }
2920
2921     /* Fill the remaining spaces */
2922     for (i = 0; i < 4; i++) {
2923         for (j = 0; creature_ptr->history[i][j]; j++) /* loop */
2924             ;
2925
2926         for (; j < 59; j++)
2927             creature_ptr->history[i][j] = ' ';
2928         creature_ptr->history[i][59] = '\0';
2929     }
2930
2931     /* Kill the buffer */
2932     histpref_buf = NULL;
2933
2934     return TRUE;
2935 }
2936
2937 /*!
2938  * @brief 生い立ちメッセージを編集する。/Character background edit-mode
2939  * @return なし
2940  */
2941 static void edit_history(player_type* creature_ptr, void (*process_autopick_file_command)(char*))
2942 {
2943     char old_history[4][60];
2944     TERM_LEN y = 0, x = 0;
2945     int i, j;
2946
2947     /* Edit character background */
2948     for (i = 0; i < 4; i++) {
2949         sprintf(old_history[i], "%s", creature_ptr->history[i]);
2950     }
2951     /* Turn 0 to space */
2952     for (i = 0; i < 4; i++) {
2953         for (j = 0; creature_ptr->history[i][j]; j++) /* loop */
2954             ;
2955
2956         for (; j < 59; j++)
2957             creature_ptr->history[i][j] = ' ';
2958         creature_ptr->history[i][59] = '\0';
2959     }
2960
2961     display_player(creature_ptr, 1, map_name);
2962 #ifdef JP
2963     c_put_str(TERM_L_GREEN, "(キャラクターの生い立ち - 編集モード)", 11, 20);
2964     put_str("[ カーソルキーで移動、Enterで終了、Ctrl-Aでファイル読み込み ]", 17, 10);
2965 #else
2966     c_put_str(TERM_L_GREEN, "(Character Background - Edit Mode)", 11, 20);
2967     put_str("[ Cursor key for Move, Enter for End, Ctrl-A for Read pref ]", 17, 10);
2968 #endif
2969
2970     while (TRUE) {
2971         int skey;
2972         char c;
2973
2974         for (i = 0; i < 4; i++) {
2975             put_str(creature_ptr->history[i], i + 12, 10);
2976         }
2977 #ifdef JP
2978         if (iskanji2(creature_ptr->history[y], x))
2979             c_put_str(TERM_L_BLUE, format("%c%c", creature_ptr->history[y][x], creature_ptr->history[y][x + 1]), y + 12, x + 10);
2980         else
2981 #endif
2982             c_put_str(TERM_L_BLUE, format("%c", creature_ptr->history[y][x]), y + 12, x + 10);
2983
2984         /* Place cursor just after cost of current stat */
2985         Term_gotoxy(x + 10, y + 12);
2986
2987         /* Get special key code */
2988         skey = inkey_special(TRUE);
2989
2990         /* Get a character code */
2991         if (!(skey & SKEY_MASK))
2992             c = (char)skey;
2993         else
2994             c = 0;
2995
2996         if (skey == SKEY_UP || c == KTRL('p')) {
2997             y--;
2998             if (y < 0)
2999                 y = 3;
3000 #ifdef JP
3001             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
3002                 x--;
3003 #endif
3004         } else if (skey == SKEY_DOWN || c == KTRL('n')) {
3005             y++;
3006             if (y > 3)
3007                 y = 0;
3008 #ifdef JP
3009             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
3010                 x--;
3011 #endif
3012         } else if (skey == SKEY_RIGHT || c == KTRL('f')) {
3013 #ifdef JP
3014             if (iskanji2(creature_ptr->history[y], x))
3015                 x++;
3016 #endif
3017             x++;
3018             if (x > 58) {
3019                 x = 0;
3020                 if (y < 3)
3021                     y++;
3022             }
3023         } else if (skey == SKEY_LEFT || c == KTRL('b')) {
3024             x--;
3025             if (x < 0) {
3026                 if (y) {
3027                     y--;
3028                     x = 58;
3029                 } else
3030                     x = 0;
3031             }
3032
3033 #ifdef JP
3034             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
3035                 x--;
3036 #endif
3037         } else if (c == '\r' || c == '\n') {
3038             Term_erase(0, 11, 255);
3039             Term_erase(0, 17, 255);
3040 #ifdef JP
3041             put_str("(キャラクターの生い立ち - 編集済み)", 11, 20);
3042 #else
3043             put_str("(Character Background - Edited)", 11, 20);
3044 #endif
3045             break;
3046         } else if (c == ESCAPE) {
3047             clear_from(11);
3048 #ifdef JP
3049             put_str("(キャラクターの生い立ち)", 11, 25);
3050 #else
3051             put_str("(Character Background)", 11, 25);
3052 #endif
3053
3054             for (i = 0; i < 4; i++) {
3055                 sprintf(creature_ptr->history[i], "%s", old_history[i]);
3056                 put_str(creature_ptr->history[i], i + 12, 10);
3057             }
3058             break;
3059         } else if (c == KTRL('A')) {
3060             if (do_cmd_histpref(creature_ptr, process_autopick_file_command)) {
3061 #ifdef JP
3062                 if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1)))
3063                     x--;
3064 #endif
3065             }
3066         } else if (c == '\010') {
3067             x--;
3068             if (x < 0) {
3069                 if (y) {
3070                     y--;
3071                     x = 58;
3072                 } else
3073                     x = 0;
3074             }
3075
3076             creature_ptr->history[y][x] = ' ';
3077 #ifdef JP
3078             if ((x > 0) && (iskanji2(creature_ptr->history[y], x - 1))) {
3079                 x--;
3080                 creature_ptr->history[y][x] = ' ';
3081             }
3082 #endif
3083         }
3084 #ifdef JP
3085         else if (iskanji(c) || isprint(c))
3086 #else
3087         else if (isprint(c)) /* BUGFIX */
3088 #endif
3089         {
3090 #ifdef JP
3091             if (iskanji2(creature_ptr->history[y], x)) {
3092                 creature_ptr->history[y][x + 1] = ' ';
3093             }
3094
3095             if (iskanji(c)) {
3096                 if (x > 57) {
3097                     x = 0;
3098                     y++;
3099                     if (y > 3)
3100                         y = 0;
3101                 }
3102
3103                 if (iskanji2(creature_ptr->history[y], x + 1)) {
3104                     creature_ptr->history[y][x + 2] = ' ';
3105                 }
3106
3107                 creature_ptr->history[y][x++] = c;
3108
3109                 c = inkey();
3110             }
3111 #endif
3112             creature_ptr->history[y][x++] = c;
3113             if (x > 58) {
3114                 x = 0;
3115                 y++;
3116                 if (y > 3)
3117                     y = 0;
3118             }
3119         }
3120     } /* while (TRUE) */
3121 }
3122
3123 /*!
3124  * @brief player_birth()関数のサブセット/Helper function for 'player_birth()'
3125  * @details
3126  * The delay may be reduced, but is recommended to keep players
3127  * from continuously rolling up characters, which can be VERY
3128  * expensive CPU wise.  And it cuts down on player stupidity.
3129  * @return なし
3130  */
3131 static bool player_birth_aux(player_type* creature_ptr, void (*process_autopick_file_command)(char*))
3132 {
3133     int i, k, n, cs, os;
3134
3135     BIT_FLAGS mode = 0;
3136
3137     bool flag = FALSE;
3138     bool prev = FALSE;
3139
3140     concptr str;
3141
3142     char c;
3143
3144     char p2 = ')';
3145     char b1 = '[';
3146     char b2 = ']';
3147
3148     char buf[80], cur[80];
3149
3150     /*** Intro ***/
3151     Term_clear();
3152
3153     /* Title everything */
3154     put_str(_("名前  :", "Name  :"), 1, 26);
3155     put_str(_("性別        :", "Sex         :"), 3, 1);
3156     put_str(_("種族        :", "Race        :"), 4, 1);
3157     put_str(_("職業        :", "Class       :"), 5, 1);
3158
3159     /* Dump the default name */
3160     c_put_str(TERM_L_BLUE, creature_ptr->name, 1, 34);
3161
3162     /*** Instructions ***/
3163
3164     /* Display some helpful information */
3165     put_str(_("キャラクターを作成します。('S'やり直す, 'Q'終了, '?'ヘルプ)",
3166         "Make your charactor. ('S' Restart, 'Q' Quit, '?' Help)"), 8, 10);
3167
3168     /*** Player sex ***/
3169
3170     /* Extra info */
3171     put_str(_("注意:《性別》の違いはゲーム上ほとんど影響を及ぼしません。",
3172         "Note: Your 'sex' does not have any significant gameplay effects."), 23, 5);
3173
3174     /* Prompt for "Sex" */
3175     for (n = 0; n < MAX_SEXES; n++) {
3176         /* Analyze */
3177         sp_ptr = &sex_info[n];
3178
3179         /* Display */
3180 #ifdef JP
3181         sprintf(buf, "%c%c%s", I2A(n), p2, sp_ptr->title);
3182 #else
3183         sprintf(buf, "%c%c %s", I2A(n), p2, sp_ptr->title);
3184 #endif
3185         put_str(buf, 12 + (n / 5), 2 + 15 * (n % 5));
3186     }
3187
3188 #ifdef JP
3189     sprintf(cur, "%c%c%s", '*', p2, "ランダム");
3190 #else
3191     sprintf(cur, "%c%c %s", '*', p2, "Random");
3192 #endif
3193
3194     /* Choose */
3195     k = -1;
3196     cs = 0;
3197     os = MAX_SEXES;
3198     while (TRUE) {
3199         if (cs != os) {
3200             put_str(cur, 12 + (os / 5), 2 + 15 * (os % 5));
3201             if (cs == MAX_SEXES)
3202 #ifdef JP
3203                 sprintf(cur, "%c%c%s", '*', p2, "ランダム");
3204 #else
3205                 sprintf(cur, "%c%c %s", '*', p2, "Random");
3206 #endif
3207             else {
3208                 sp_ptr = &sex_info[cs];
3209                 str = sp_ptr->title;
3210 #ifdef JP
3211                 sprintf(cur, "%c%c%s", I2A(cs), p2, str);
3212 #else
3213                 sprintf(cur, "%c%c %s", I2A(cs), p2, str);
3214 #endif
3215             }
3216             c_put_str(TERM_YELLOW, cur, 12 + (cs / 5), 2 + 15 * (cs % 5));
3217             os = cs;
3218         }
3219
3220         if (k >= 0)
3221             break;
3222
3223 #ifdef JP
3224         sprintf(buf, "性別を選んで下さい (%c-%c) ('='初期オプション設定): ", I2A(0), I2A(n - 1));
3225 #else
3226         sprintf(buf, "Choose a sex (%c-%c) ('=' for options): ", I2A(0), I2A(n - 1));
3227 #endif
3228
3229         put_str(buf, 10, 10);
3230         c = inkey();
3231         if (c == 'Q')
3232             birth_quit();
3233         if (c == 'S')
3234             return FALSE;
3235         if (c == ' ' || c == '\r' || c == '\n') {
3236             if (cs == MAX_SEXES)
3237                 k = randint0(MAX_SEXES);
3238             else
3239                 k = cs;
3240             break;
3241         }
3242         if (c == '*') {
3243             k = randint0(MAX_SEXES);
3244             break;
3245         }
3246         if (c == '4') {
3247             if (cs > 0)
3248                 cs--;
3249         }
3250         if (c == '6') {
3251             if (cs < MAX_SEXES)
3252                 cs++;
3253         }
3254         k = (islower(c) ? A2I(c) : -1);
3255         if ((k >= 0) && (k < MAX_SEXES)) {
3256             cs = k;
3257             continue;
3258         } else
3259             k = -1;
3260         if (c == '?')
3261             do_cmd_help(creature_ptr);
3262         else if (c == '=') {
3263             screen_save();
3264 #ifdef JP
3265             do_cmd_options_aux(OPT_PAGE_BIRTH, "初期オプション((*)はスコアに影響)");
3266 #else
3267             do_cmd_options_aux(OPT_PAGE_BIRTH, "Birth Option((*)s effect score)");
3268 #endif
3269
3270             screen_load();
3271         } else if (c != '4' && c != '6')
3272             bell();
3273     }
3274
3275     /* Set sex */
3276     creature_ptr->psex = (byte)k;
3277     sp_ptr = &sex_info[creature_ptr->psex];
3278
3279     /* Display */
3280     c_put_str(TERM_L_BLUE, sp_ptr->title, 3, 15);
3281
3282     /* Clean up */
3283     clear_from(10);
3284
3285     /* Choose the players race */
3286     creature_ptr->prace = 0;
3287     while (TRUE) {
3288         char temp[80 * 10];
3289         concptr t;
3290
3291         if (!get_player_race(creature_ptr))
3292             return FALSE;
3293
3294         clear_from(10);
3295
3296         roff_to_buf(race_explanations[creature_ptr->prace], 74, temp, sizeof(temp));
3297         t = temp;
3298
3299         for (i = 0; i < 10; i++) {
3300             if (t[0] == 0)
3301                 break;
3302             else {
3303                 prt(t, 12 + i, 3);
3304                 t += strlen(t) + 1;
3305             }
3306         }
3307 #ifdef JP
3308         if (get_check_strict("よろしいですか?", CHECK_DEFAULT_Y))
3309             break;
3310 #else
3311         if (get_check_strict("Are you sure? ", CHECK_DEFAULT_Y))
3312             break;
3313 #endif
3314         clear_from(10);
3315         c_put_str(TERM_WHITE, "              ", 4, 15);
3316     }
3317
3318     /* Clean up */
3319     clear_from(10);
3320
3321     /* Choose the players class */
3322     creature_ptr->pclass = 0;
3323     while (TRUE) {
3324         char temp[80 * 9];
3325         concptr t;
3326
3327         if (!get_player_class(creature_ptr))
3328             return FALSE;
3329
3330         clear_from(10);
3331         roff_to_buf(class_explanations[creature_ptr->pclass], 74, temp, sizeof(temp));
3332         t = temp;
3333
3334         for (i = 0; i < 9; i++) {
3335             if (t[0] == 0)
3336                 break;
3337             else {
3338                 prt(t, 12 + i, 3);
3339                 t += strlen(t) + 1;
3340             }
3341         }
3342
3343 #ifdef JP
3344         if (get_check_strict("よろしいですか?", CHECK_DEFAULT_Y))
3345             break;
3346 #else
3347         if (get_check_strict("Are you sure? ", CHECK_DEFAULT_Y))
3348             break;
3349 #endif
3350         c_put_str(TERM_WHITE, "              ", 5, 15);
3351     }
3352
3353     /* Choose the magic realms */
3354     if (!get_player_realms(creature_ptr))
3355         return FALSE;
3356
3357     /* Choose the players seikaku */
3358     creature_ptr->pseikaku = 0;
3359     while (TRUE) {
3360         char temp[80 * 8];
3361         concptr t;
3362
3363         if (!get_player_seikaku(creature_ptr))
3364             return FALSE;
3365
3366         clear_from(10);
3367         roff_to_buf(personality_explanations[creature_ptr->pseikaku], 74, temp, sizeof(temp));
3368         t = temp;
3369
3370         for (i = 0; i < A_MAX; i++) {
3371             if (t[0] == 0)
3372                 break;
3373             else {
3374                 prt(t, 12 + i, 3);
3375                 t += strlen(t) + 1;
3376             }
3377         }
3378 #ifdef JP
3379         if (get_check_strict("よろしいですか?", CHECK_DEFAULT_Y))
3380             break;
3381 #else
3382         if (get_check_strict("Are you sure? ", CHECK_DEFAULT_Y))
3383             break;
3384 #endif
3385         c_put_str(TERM_L_BLUE, creature_ptr->name, 1, 34);
3386         prt("", 1, 34 + strlen(creature_ptr->name));
3387     }
3388
3389     /* Clean up */
3390     clear_from(10);
3391     put_str("                                   ", 3, 40);
3392     put_str("                                   ", 4, 40);
3393     put_str("                                   ", 5, 40);
3394
3395     screen_save();
3396 #ifdef JP
3397     do_cmd_options_aux(OPT_PAGE_BIRTH, "初期オプション((*)はスコアに影響)");
3398 #else
3399     do_cmd_options_aux(OPT_PAGE_BIRTH, "Birth Option((*)s effect score)");
3400 #endif
3401
3402     screen_load();
3403
3404     if (autoroller || autochara) {
3405         /* Clear fields */
3406         auto_round = 0L;
3407     }
3408
3409     if (autoroller) {
3410         if (!get_stat_limits(creature_ptr))
3411             return FALSE;
3412     }
3413
3414     if (autochara) {
3415         if (!get_chara_limits(creature_ptr))
3416             return FALSE;
3417     }
3418
3419     clear_from(10);
3420
3421     /* Reset turn; before auto-roll and after choosing race */
3422     init_turn(creature_ptr);
3423
3424     /*** Generate ***/
3425
3426     /* Roll */
3427     while (TRUE) {
3428         int col;
3429
3430         col = 42;
3431
3432         if (autoroller || autochara) {
3433             Term_clear();
3434
3435             /* Label count */
3436 #ifdef JP
3437             put_str("回数 :", 10, col + 13);
3438 #else
3439             put_str("Round:", 10, col + 13);
3440 #endif
3441
3442             /* Indicate the state */
3443 #ifdef JP
3444             put_str("(ESCで停止)", 12, col + 13);
3445 #else
3446             put_str("(Hit ESC to stop)", 12, col + 13);
3447 #endif
3448         }
3449
3450         /* Otherwise just get a character */
3451         else {
3452             get_stats(creature_ptr);
3453             get_ahw(creature_ptr);
3454             get_history(creature_ptr);
3455         }
3456
3457         /* Feedback */
3458         if (autoroller) {
3459             /* Label */
3460 #ifdef JP
3461             put_str("最小値", 2, col + 5);
3462 #else
3463             put_str(" Limit", 2, col + 5);
3464 #endif
3465
3466             /* Label */
3467 #ifdef JP
3468             put_str("成功率", 2, col + 13);
3469 #else
3470             put_str("  Freq", 2, col + 13);
3471 #endif
3472
3473             /* Label */
3474 #ifdef JP
3475             put_str("現在値", 2, col + 24);
3476 #else
3477             put_str("  Roll", 2, col + 24);
3478 #endif
3479
3480             /* Put the minimal stats */
3481             for (i = 0; i < A_MAX; i++) {
3482                 int j, m;
3483
3484                 /* Label stats */
3485                 put_str(stat_names[i], 3 + i, col);
3486
3487                 /* Race/Class bonus */
3488                 j = rp_ptr->r_adj[i] + cp_ptr->c_adj[i] + ap_ptr->a_adj[i];
3489
3490                 /* Obtain the current stat */
3491                 m = adjust_stat(stat_limit[i], j);
3492
3493                 /* Put the stat */
3494                 cnv_stat(m, buf);
3495                 c_put_str(TERM_L_BLUE, buf, 3 + i, col + 5);
3496             }
3497         }
3498
3499         /* Auto-roll */
3500         while (autoroller || autochara) {
3501             bool accept = TRUE;
3502
3503             /* Get a new character */
3504             get_stats(creature_ptr);
3505
3506             /* Advance the round */
3507             auto_round++;
3508
3509             /* Hack -- Prevent overflow */
3510             if (auto_round >= 1000000000L) {
3511                 auto_round = 1;
3512
3513                 if (autoroller) {
3514                     for (i = 0; i < A_MAX; i++) {
3515                         stat_match[i] = 0;
3516                     }
3517                 }
3518             }
3519
3520             if (autoroller) {
3521                 /* Check and count acceptable stats */
3522                 for (i = 0; i < A_MAX; i++) {
3523                     /* This stat is okay */
3524                     if (creature_ptr->stat_max[i] >= stat_limit[i]) {
3525                         stat_match[i]++;
3526                     }
3527
3528                     /* This stat is not okay */
3529                     else {
3530                         accept = FALSE;
3531                     }
3532                 }
3533             }
3534
3535             /* Break if "happy" */
3536             if (accept) {
3537                 get_ahw(creature_ptr);
3538                 get_history(creature_ptr);
3539
3540                 if (autochara) {
3541                     if ((creature_ptr->age < chara_limit.agemin) || (creature_ptr->age > chara_limit.agemax))
3542                         accept = FALSE;
3543                     if ((creature_ptr->ht < chara_limit.htmin) || (creature_ptr->ht > chara_limit.htmax))
3544                         accept = FALSE;
3545                     if ((creature_ptr->wt < chara_limit.wtmin) || (creature_ptr->wt > chara_limit.wtmax))
3546                         accept = FALSE;
3547                     if ((creature_ptr->sc < chara_limit.scmin) || (creature_ptr->sc > chara_limit.scmax))
3548                         accept = FALSE;
3549                 }
3550                 if (accept)
3551                     break;
3552             }
3553
3554             /* Take note every x rolls */
3555             flag = (!(auto_round % AUTOROLLER_STEP));
3556
3557             /* Update display occasionally */
3558             if (flag) {
3559                 /* Dump data */
3560                 birth_put_stats(creature_ptr);
3561
3562                 /* Dump round */
3563                 put_str(format("%10ld", auto_round), 10, col + 20);
3564
3565                 /* Make sure they see everything */
3566                 Term_fresh();
3567
3568                 /* Do not wait for a key */
3569                 inkey_scan = TRUE;
3570
3571                 /* Check for a keypress */
3572                 if (inkey()) {
3573                     get_ahw(creature_ptr);
3574                     get_history(creature_ptr);
3575                     break;
3576                 }
3577             }
3578         }
3579
3580         if (autoroller || autochara)
3581             sound(SOUND_LEVEL);
3582
3583         flush();
3584
3585         /*** Display ***/
3586
3587         mode = 0;
3588
3589         /* Roll for base hitpoints */
3590         get_extra(creature_ptr, TRUE);
3591
3592         /* Roll for gold */
3593         get_money(creature_ptr);
3594
3595         /* Hack -- get a chaos patron even if you are not a chaos warrior */
3596         creature_ptr->chaos_patron = (s16b)randint0(MAX_PATRON);
3597
3598         /* Input loop */
3599         while (TRUE) {
3600             /* Calculate the bonuses and hitpoints */
3601             creature_ptr->update |= (PU_BONUS | PU_HP);
3602             update_creature(creature_ptr);
3603
3604             creature_ptr->chp = creature_ptr->mhp;
3605             creature_ptr->csp = creature_ptr->msp;
3606
3607             display_player(creature_ptr, mode, map_name);
3608
3609             /* Prepare a prompt (must squeeze everything in) */
3610             Term_gotoxy(2, 23);
3611             Term_addch(TERM_WHITE, b1);
3612             Term_addstr(-1, TERM_WHITE, _("'r' 次の数値", "'r'eroll"));
3613
3614             if (prev)
3615                 Term_addstr(-1, TERM_WHITE, _(", 'p' 前の数値", "'p'previous"));
3616             if (mode)
3617                 Term_addstr(-1, TERM_WHITE, _(", 'h' その他の情報", ", 'h' Misc."));
3618             else
3619                 Term_addstr(-1, TERM_WHITE, _(", 'h' 生い立ちを表示", ", 'h'istory"));
3620             Term_addstr(-1, TERM_WHITE, _(", Enter この数値に決定", ", or Enter to accept"));
3621             Term_addch(TERM_WHITE, b2);
3622
3623             c = inkey();
3624
3625             /* Quit */
3626             if (c == 'Q')
3627                 birth_quit();
3628
3629             /* Start over */
3630             if (c == 'S')
3631                 return FALSE;
3632
3633             /* Escape accepts the roll */
3634             if (c == '\r' || c == '\n' || c == ESCAPE)
3635                 break;
3636
3637             /* Reroll this character */
3638             if ((c == ' ') || (c == 'r'))
3639                 break;
3640
3641             /* Previous character */
3642             if (prev && (c == 'p')) {
3643                 load_prev_data(creature_ptr, TRUE);
3644                 continue;
3645             }
3646
3647             if ((c == 'H') || (c == 'h')) {
3648                 mode = ((mode != 0) ? 0 : 1);
3649                 continue;
3650             }
3651
3652             /* Help */
3653             if (c == '?') {
3654 #ifdef JP
3655                 show_help(creature_ptr, "jbirth.txt#AutoRoller");
3656 #else
3657                 show_help(creature_ptr, "birth.txt#AutoRoller");
3658 #endif
3659                 continue;
3660             } else if (c == '=') {
3661                 screen_save();
3662                 do_cmd_options_aux(OPT_PAGE_BIRTH, _("初期オプション((*)はスコアに影響)", "Birth Option((*)s effect score)"));
3663                 screen_load();
3664                 continue;
3665             }
3666
3667             /* Warning */
3668             bell();
3669         }
3670
3671         /* Are we done? */
3672         if (c == '\r' || c == '\n' || c == ESCAPE)
3673             break;
3674
3675         /* Save this for the "previous" character */
3676         save_prev_data(creature_ptr, &previous_char);
3677         previous_char.quick_ok = FALSE;
3678
3679         /* Note that a previous roll exists */
3680         prev = TRUE;
3681     }
3682
3683     /* Clear prompt */
3684     clear_from(23);
3685
3686     /* Get a name, recolor it, prepare savefile */
3687     get_name(creature_ptr);
3688
3689     /* Process the player name */
3690     process_player_name(creature_ptr, current_world_ptr->creating_savefile);
3691
3692     /*** Edit character background ***/
3693     edit_history(creature_ptr, process_autopick_file_command);
3694
3695     /*** Finish up ***/
3696
3697     get_max_stats(creature_ptr);
3698
3699     get_virtues(creature_ptr);
3700
3701     /* Prompt for it */
3702 #ifdef JP
3703     prt("[ 'Q' 中断, 'S' 初めから, Enter ゲーム開始 ]", 23, 14);
3704 #else
3705     prt("['Q'uit, 'S'tart over, or Enter to continue]", 23, 10);
3706 #endif
3707
3708     /* Get a key */
3709     c = inkey();
3710
3711     /* Quit */
3712     if (c == 'Q')
3713         birth_quit();
3714
3715     /* Start over */
3716     if (c == 'S')
3717         return FALSE;
3718
3719     /* Initialize random quests */
3720     init_dungeon_quests(creature_ptr);
3721
3722     /* Save character data for quick start */
3723     save_prev_data(creature_ptr, &previous_char);
3724     previous_char.quick_ok = TRUE;
3725
3726     /* Accept */
3727     return TRUE;
3728 }
3729
3730 /*!
3731  * @brief クイックスタート処理の問い合わせと実行を行う。/Ask whether the player use Quick Start or not.
3732  * @return なし
3733  */
3734 static bool ask_quick_start(player_type* creature_ptr)
3735 {
3736     /* Doesn't have previous data */
3737     if (!previous_char.quick_ok)
3738         return FALSE;
3739
3740     Term_clear();
3741
3742     /* Extra info */
3743     put_str(_("クイック・スタートを使うと以前と全く同じキャラクターで始められます。",
3744         "Do you want to use the quick start function(same character as your last one)."), 11, 2);
3745
3746     /* Choose */
3747     while (TRUE) {
3748         char c;
3749
3750         put_str(_("クイック・スタートを使いますか?[y/N]", "Use quick start? [y/N]"), 14, 10);
3751         c = inkey();
3752
3753         if (c == 'Q')
3754             quit(NULL);
3755         else if (c == 'S')
3756             return FALSE;
3757         else if (c == '?') {
3758 #ifdef JP
3759             show_help(creature_ptr, "jbirth.txt#QuickStart");
3760 #else
3761             show_help(creature_ptr, "birth.txt#QuickStart");
3762 #endif
3763         } else if ((c == 'y') || (c == 'Y')) {
3764             /* Yes */
3765             break;
3766         } else {
3767             /* No */
3768             return FALSE;
3769         }
3770     }
3771
3772     load_prev_data(creature_ptr, FALSE);
3773     init_turn(creature_ptr);
3774     init_dungeon_quests(creature_ptr);
3775
3776     sp_ptr = &sex_info[creature_ptr->psex];
3777     rp_ptr = &race_info[creature_ptr->prace];
3778     cp_ptr = &class_info[creature_ptr->pclass];
3779     mp_ptr = &m_info[creature_ptr->pclass];
3780     ap_ptr = &seikaku_info[creature_ptr->pseikaku];
3781
3782     /* Calc hitdie, but don't roll */
3783     get_extra(creature_ptr, FALSE);
3784
3785     creature_ptr->update |= (PU_BONUS | PU_HP);
3786     update_creature(creature_ptr);
3787     creature_ptr->chp = creature_ptr->mhp;
3788     creature_ptr->csp = creature_ptr->msp;
3789
3790     /* Process the player name */
3791     process_player_name(creature_ptr, FALSE);
3792
3793     return TRUE;
3794 }
3795
3796 /*!
3797  * @brief プレイヤー作成処理のメインルーチン/ Create a new character.
3798  * @details
3799  * Note that we may be called with "junk" leftover in the various
3800  * fields, so we must be sure to clear them first.
3801  * @return なし
3802  */
3803 void player_birth(player_type* creature_ptr, void (*process_autopick_file_command)(char*))
3804 {
3805     int i, j;
3806     char buf[80];
3807
3808     current_world_ptr->play_time = 0;
3809
3810     wipe_monsters_list(creature_ptr);
3811
3812     /* Wipe the player */
3813     player_wipe_without_name(creature_ptr);
3814
3815     /* Create a new character */
3816
3817     /* Quick start? */
3818     if (!ask_quick_start(creature_ptr)) {
3819         play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_DEFAULT);
3820
3821         /* No, normal start */
3822         while (TRUE) {
3823             /* Roll up a new character */
3824             if (player_birth_aux(creature_ptr, process_autopick_file_command))
3825                 break;
3826
3827             /* Wipe the player */
3828             player_wipe_without_name(creature_ptr);
3829         }
3830     }
3831
3832     /* Note player birth in the message recall */
3833     message_add(" ");
3834     message_add("  ");
3835     message_add("====================");
3836     message_add(" ");
3837     message_add("  ");
3838
3839     exe_write_diary(creature_ptr, DIARY_GAMESTART, 1, _("-------- 新規ゲーム開始 --------", "------- Started New Game -------"));
3840     exe_write_diary(creature_ptr, DIARY_DIALY, 0, NULL);
3841
3842     sprintf(buf, _("                            性別に%sを選択した。", "                            chose %s gender."),
3843         sex_info[creature_ptr->psex].title);
3844     exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1, buf);
3845
3846     sprintf(buf, _("                            種族に%sを選択した。", "                            chose %s race."),
3847         race_info[creature_ptr->prace].title);
3848     exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1, buf);
3849
3850     sprintf(buf, _("                            職業に%sを選択した。", "                            chose %s class."),
3851         class_info[creature_ptr->pclass].title);
3852     exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1, buf);
3853
3854     if (creature_ptr->realm1) {
3855         sprintf(buf, _("                            魔法の領域に%s%sを選択した。", "                            chose %s%s."),
3856             realm_names[creature_ptr->realm1], creature_ptr->realm2 ? format(_("と%s", " and %s realms"), realm_names[creature_ptr->realm2]) : _("", " realm"));
3857         exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1, buf);
3858     }
3859
3860     sprintf(buf, _("                            性格に%sを選択した。", "                            chose %s personality."),
3861         seikaku_info[creature_ptr->pseikaku].title);
3862     exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1, buf);
3863
3864     /* Init the shops */
3865     for (i = 1; i < max_towns; i++) {
3866         for (j = 0; j < MAX_STORES; j++) {
3867             store_init(i, j);
3868         }
3869     }
3870
3871     /* Generate the random seeds for the wilderness */
3872     seed_wilderness();
3873
3874     /* Give beastman a mutation at character birth */
3875     if (creature_ptr->prace == RACE_BEASTMAN)
3876         creature_ptr->hack_mutation = TRUE;
3877     else
3878         creature_ptr->hack_mutation = FALSE;
3879
3880     /* Set the message window flag as default */
3881     if (!window_flag[1])
3882         window_flag[1] |= PW_MESSAGE;
3883
3884     /* Set the inv/equip window flag as default */
3885     if (!window_flag[2])
3886         window_flag[2] |= PW_INVEN;
3887 }
3888
3889 /*!
3890  * @brief プレイヤー作成処理中のステータス表示処理
3891  * @param fff ファイルポインタ
3892  * @return なし
3893  */
3894 void dump_yourself(player_type* creature_ptr, FILE* fff)
3895 {
3896     char temp[80 * 10];
3897     int i;
3898     concptr t;
3899
3900     if (!fff)
3901         return;
3902
3903     roff_to_buf(race_explanations[creature_ptr->prace], 78, temp, sizeof(temp));
3904     fprintf(fff, "\n\n");
3905     fprintf(fff, _("種族: %s\n", "Race: %s\n"), race_info[creature_ptr->prace].title);
3906
3907     t = temp;
3908     for (i = 0; i < 10; i++) {
3909         if (t[0] == 0)
3910             break;
3911         fprintf(fff, "%s\n", t);
3912         t += strlen(t) + 1;
3913     }
3914     roff_to_buf(class_explanations[creature_ptr->pclass], 78, temp, sizeof(temp));
3915     fprintf(fff, "\n");
3916     fprintf(fff, _("職業: %s\n", "Class: %s\n"), class_info[creature_ptr->pclass].title);
3917
3918     t = temp;
3919     for (i = 0; i < 10; i++) {
3920         if (t[0] == 0)
3921             break;
3922         fprintf(fff, "%s\n", t);
3923         t += strlen(t) + 1;
3924     }
3925     roff_to_buf(personality_explanations[creature_ptr->pseikaku], 78, temp, sizeof(temp));
3926     fprintf(fff, "\n");
3927     fprintf(fff, _("性格: %s\n", "Pesonality: %s\n"), seikaku_info[creature_ptr->pseikaku].title);
3928
3929     t = temp;
3930     for (i = 0; i < A_MAX; i++) {
3931         if (t[0] == 0)
3932             break;
3933         fprintf(fff, "%s\n", t);
3934         t += strlen(t) + 1;
3935     }
3936     fprintf(fff, "\n");
3937     if (creature_ptr->realm1) {
3938         roff_to_buf(realm_explanations[technic2magic(creature_ptr->realm1) - 1], 78, temp, sizeof(temp));
3939         fprintf(fff, _("魔法: %s\n", "Realm: %s\n"), realm_names[creature_ptr->realm1]);
3940
3941         t = temp;
3942         for (i = 0; i < A_MAX; i++) {
3943             if (t[0] == 0)
3944                 break;
3945             fprintf(fff, "%s\n", t);
3946             t += strlen(t) + 1;
3947         }
3948     }
3949     fprintf(fff, "\n");
3950     if (creature_ptr->realm2) {
3951         roff_to_buf(realm_explanations[technic2magic(creature_ptr->realm2) - 1], 78, temp, sizeof(temp));
3952         fprintf(fff, _("魔法: %s\n", "Realm: %s\n"), realm_names[creature_ptr->realm2]);
3953
3954         t = temp;
3955         for (i = 0; i < A_MAX; i++) {
3956             if (t[0] == 0)
3957                 break;
3958             fprintf(fff, "%s\n", t);
3959             t += strlen(t) + 1;
3960         }
3961     }
3962 }