OSDN Git Service

[Fix] オートローラーで「'p' 前の数値」が無効になっていたので修正。 / Can switch 'P'revious result on auto roller.
[hengband/hengband.git] / src / birth / birth-wizard.c
1 #include "birth/birth-wizard.h"
2 #include "birth/auto-roller.h"
3 #include "birth/birth-body-spec.h"
4 #include "birth/birth-explanations-table.h"
5 #include "birth/birth-select-class.h"
6 #include "birth/birth-select-personality.h"
7 #include "birth/birth-select-race.h"
8 #include "birth/birth-select-realm.h"
9 #include "birth/birth-stat.h"
10 #include "birth/birth-util.h"
11 #include "birth/game-play-initializer.h"
12 #include "birth/history-editor.h"
13 #include "birth/history-generator.h"
14 #include "birth/quick-start.h"
15 #include "cmd-io/cmd-gameoption.h"
16 #include "cmd-io/cmd-help.h"
17 #include "core/asking-player.h"
18 #include "core/player-update-types.h"
19 #include "game-option/birth-options.h"
20 #include "io/input-key-acceptor.h"
21 #include "main/sound-definitions-table.h"
22 #include "main/sound-of-music.h"
23 #include "player-info/avatar.h"
24 #include "player/patron.h"
25 #include "player/player-class.h"
26 #include "player/player-race.h"
27 #include "player/player-sex.h"
28 #include "player/process-name.h"
29 #include "player/player-status-table.h"
30 #include "system/game-option-types.h"
31 #include "term/screen-processor.h"
32 #include "term/term-color-types.h"
33 #include "util/buffer-shaper.h"
34 #include "util/int-char-converter.h"
35 #include "view/display-birth.h" // 暫定。後で消す予定。
36 #include "view/display-player.h" // 暫定。後で消す.
37 #include "world/world.h"
38
39 /*!
40  * オートローラーの内容を描画する間隔 /
41  * How often the autoroller will update the display and pause
42  * to check for user interuptions.
43  * Bigger values will make the autoroller faster, but slower
44  * system may have problems because the user can't stop the
45  * autoroller for this number of rolls.
46  */
47 #define AUTOROLLER_STEP 5431L
48
49 static void display_initial_birth_message(player_type *creature_ptr)
50 {
51     term_clear();
52     put_str(_("名前  :", "Name  :"), 1, 26);
53     put_str(_("性別        :", "Sex         :"), 3, 1);
54     put_str(_("種族        :", "Race        :"), 4, 1);
55     put_str(_("職業        :", "Class       :"), 5, 1);
56     c_put_str(TERM_L_BLUE, creature_ptr->name, 1, 34);
57     put_str(_("キャラクターを作成します。('S'やり直す, 'Q'終了, '?'ヘルプ)", "Make your character. ('S' Restart, 'Q' Quit, '?' Help)"), 8, 10);
58     put_str(_("注意:《性別》の違いはゲーム上ほとんど影響を及ぼしません。", "Note: Your 'sex' does not have any significant gameplay effects."), 23, 5);
59 }
60
61 /*!
62  * @prief 性別選択画面でヘルプを表示させる
63  * @param creature_ptr プレーヤーへの参照ポインタ
64  * @param c 入力したコマンド
65  * @return なし
66  * @details 他の関数名と被りそうだったので少し眺め
67  */
68 static void display_help_on_sex_select(player_type *creature_ptr, char c)
69 {
70     if (c == '?')
71         do_cmd_help(creature_ptr);
72     else if (c == '=') {
73         screen_save();
74         do_cmd_options_aux(creature_ptr, OPT_PAGE_BIRTH, _("初期オプション((*)はスコアに影響)", "Birth Option((*)s effect score)"));
75         screen_load();
76     } else if (c != '4' && c != '6')
77         bell();
78 }
79
80 /*!
81  * @brief プレイヤーの性別選択を行う / Player sex
82  * @param creature_ptr プレーヤーへの参照ポインタ
83  * @buf 表示用バッファ
84  * @return やり直すならFALSE、それ以外はTRUE
85  */
86 static bool get_player_sex(player_type *creature_ptr, char *buf)
87 {
88     const char p2 = ')';
89     char cur[80];
90     sprintf(cur, _("%c%c%s", "%c%c %s"), '*', p2, _("ランダム", "Random"));
91     int k = -1;
92     int cs = 0;
93     int os = MAX_SEXES;
94     while (TRUE) {
95         if (cs != os) {
96             put_str(cur, 12 + (os / 5), 2 + 15 * (os % 5));
97             if (cs == MAX_SEXES)
98                 sprintf(cur, _("%c%c%s", "%c%c %s"), '*', p2, _("ランダム", "Random"));
99             else {
100                 sp_ptr = &sex_info[cs];
101                 concptr str = sp_ptr->title;
102                 sprintf(cur, _("%c%c%s", "%c%c %s"), I2A(cs), p2, str);
103             }
104
105             c_put_str(TERM_YELLOW, cur, 12 + (cs / 5), 2 + 15 * (cs % 5));
106             os = cs;
107         }
108
109         if (k >= 0)
110             break;
111
112         sprintf(buf, _("性別を選んで下さい (%c-%c) ('='初期オプション設定): ", "Choose a sex (%c-%c) ('=' for options): "), I2A(0), I2A(1));
113         put_str(buf, 10, 10);
114         char c = inkey();
115         if (c == 'Q')
116             birth_quit();
117
118         if (c == 'S')
119             return FALSE;
120
121         if (c == ' ' || c == '\r' || c == '\n') {
122             k = cs == MAX_SEXES ? randint0(MAX_SEXES) : cs;
123             break;
124         }
125
126         if (c == '*') {
127             k = randint0(MAX_SEXES);
128             break;
129         }
130
131         if (c == '4') {
132             if (cs > 0)
133                 cs--;
134         }
135
136         if (c == '6') {
137             if (cs < MAX_SEXES)
138                 cs++;
139         }
140
141         k = (islower(c) ? A2I(c) : -1);
142         if ((k >= 0) && (k < MAX_SEXES)) {
143             cs = k;
144             continue;
145         } else
146             k = -1;
147
148         display_help_on_sex_select(creature_ptr, c);
149     }
150
151     creature_ptr->psex = (byte)k;
152     sp_ptr = &sex_info[creature_ptr->psex];
153     c_put_str(TERM_L_BLUE, sp_ptr->title, 3, 15);
154     return TRUE;
155 }
156
157 static bool let_player_select_race(player_type *creature_ptr)
158 {
159     clear_from(10);
160     creature_ptr->prace = 0;
161     while (TRUE) {
162         char temp[80 * 10];
163         if (!get_player_race(creature_ptr))
164             return FALSE;
165
166         clear_from(10);
167         shape_buffer(race_explanations[creature_ptr->prace], 74, temp, sizeof(temp));
168         concptr t = temp;
169         for (int i = 0; i < 10; i++) {
170             if (t[0] == 0)
171                 break;
172             else {
173                 prt(t, 12 + i, 3);
174                 t += strlen(t) + 1;
175             }
176         }
177         if (get_check_strict(creature_ptr, _("よろしいですか?", "Are you sure? "), CHECK_DEFAULT_Y))
178             break;
179
180         clear_from(10);
181         c_put_str(TERM_WHITE, "              ", 4, 15);
182     }
183
184     return TRUE;
185 }
186
187 static bool let_player_select_class(player_type *creature_ptr)
188 {
189     clear_from(10);
190     creature_ptr->pclass = 0;
191     while (TRUE) {
192         char temp[80 * 9];
193         if (!get_player_class(creature_ptr))
194             return FALSE;
195
196         clear_from(10);
197         shape_buffer(class_explanations[creature_ptr->pclass], 74, temp, sizeof(temp));
198         concptr t = temp;
199         for (int i = 0; i < 9; i++) {
200             if (t[0] == 0)
201                 break;
202             else {
203                 prt(t, 12 + i, 3);
204                 t += strlen(t) + 1;
205             }
206         }
207
208         if (get_check_strict(creature_ptr, _("よろしいですか?", "Are you sure? "), CHECK_DEFAULT_Y))
209             break;
210
211         c_put_str(TERM_WHITE, "              ", 5, 15);
212     }
213
214     return TRUE;
215 }
216
217 static bool let_player_select_personality(player_type *creature_ptr)
218 {
219     creature_ptr->pseikaku = 0;
220     while (TRUE) {
221         char temp[80 * 8];
222         if (!get_player_personality(creature_ptr))
223             return FALSE;
224
225         clear_from(10);
226         shape_buffer(personality_explanations[creature_ptr->pseikaku], 74, temp, sizeof(temp));
227         concptr t = temp;
228         for (int i = 0; i < A_MAX; i++) {
229             if (t[0] == 0)
230                 break;
231             else {
232                 prt(t, 12 + i, 3);
233                 t += strlen(t) + 1;
234             }
235         }
236
237         if (get_check_strict(creature_ptr, _("よろしいですか?", "Are you sure? "), CHECK_DEFAULT_Y))
238             break;
239
240         c_put_str(TERM_L_BLUE, creature_ptr->name, 1, 34);
241         prt("", 1, 34 + strlen(creature_ptr->name));
242     }
243
244     return TRUE;
245 }
246
247 static bool let_player_build_character(player_type *creature_ptr)
248 {
249     char buf[80];
250     if (!get_player_sex(creature_ptr, buf))
251         return FALSE;
252
253     if (!let_player_select_race(creature_ptr))
254         return FALSE;
255
256     if (!let_player_select_class(creature_ptr))
257         return FALSE;
258
259     if (!get_player_realms(creature_ptr))
260         return FALSE;
261
262     if (!let_player_select_personality(creature_ptr))
263         return FALSE;
264
265     return TRUE;
266 }
267
268 static void display_initial_options(player_type *creature_ptr)
269 {
270     clear_from(10);
271     put_str("                                   ", 3, 40);
272     put_str("                                   ", 4, 40);
273     put_str("                                   ", 5, 40);
274     screen_save();
275     do_cmd_options_aux(creature_ptr, OPT_PAGE_BIRTH, _("初期オプション((*)はスコアに影響)", "Birth Option((*)s effect score)"));
276     screen_load();
277 }
278
279 static void display_auto_roller_success_rate(const int col)
280 {
281     if (!autoroller)
282         return;
283
284     put_str(_("最小値", " Limit"), 2, col + 5);
285     put_str(_("成功率", "  Freq"), 2, col + 13);
286     put_str(_("現在値", "  Roll"), 2, col + 24);
287     for (int i = 0; i < A_MAX; i++) {
288         put_str(stat_names[i], 3 + i, col);
289         int j = rp_ptr->r_adj[i] + cp_ptr->c_adj[i] + ap_ptr->a_adj[i];
290         int m = adjust_stat(stat_limit[i], j);
291         char buf[32];
292         cnv_stat(m, buf);
293         c_put_str(TERM_L_BLUE, buf, 3 + i, col + 5);
294     }
295 }
296
297 static void auto_roller_count(void)
298 {
299     if (auto_round < 1000000000L)
300         return;
301
302     auto_round = 1;
303     if (!autoroller)
304         return;
305
306     for (int i = 0; i < A_MAX; i++) {
307         stat_match[i] = 0;
308     }
309 }
310
311 static bool decide_initial_stat(player_type *creature_ptr)
312 {
313     if (!autoroller)
314         return TRUE;
315
316     bool accept = TRUE;
317     for (int i = 0; i < A_MAX; i++) {
318         if (creature_ptr->stat_max[i] >= stat_limit[i])
319             stat_match[i]++;
320         else
321             accept = FALSE;
322     }
323
324     return accept;
325 }
326
327 static bool decide_body_spec(player_type *creature_ptr, chara_limit_type chara_limit, bool *accept)
328 {
329     if (!*accept)
330         return FALSE;
331
332     get_ahw(creature_ptr);
333     get_history(creature_ptr);
334
335     if (autochara) {
336         if ((creature_ptr->age < chara_limit.agemin) || (creature_ptr->age > chara_limit.agemax))
337             *accept = FALSE;
338         if ((creature_ptr->ht < chara_limit.htmin) || (creature_ptr->ht > chara_limit.htmax))
339             *accept = FALSE;
340         if ((creature_ptr->wt < chara_limit.wtmin) || (creature_ptr->wt > chara_limit.wtmax))
341             *accept = FALSE;
342         if ((creature_ptr->sc < chara_limit.scmin) || (creature_ptr->sc > chara_limit.scmax))
343             *accept = FALSE;
344     }
345
346     return *accept;
347 }
348
349 static bool display_auto_roller_count(player_type *creature_ptr, const int col)
350 {
351     if ((auto_round % AUTOROLLER_STEP) != 0)
352         return FALSE;
353
354     birth_put_stats(creature_ptr);
355     put_str(format("%10ld", auto_round), 10, col + 20);
356     term_fresh();
357     inkey_scan = TRUE;
358     if (inkey()) {
359         get_ahw(creature_ptr);
360         get_history(creature_ptr);
361         return TRUE;
362     }
363
364     return FALSE;
365 }
366
367 static void exe_auto_roller(player_type *creature_ptr, chara_limit_type chara_limit, const int col)
368 {
369     while (autoroller || autochara) {
370         get_stats(creature_ptr);
371         auto_round++;
372         auto_roller_count();
373         bool accept = decide_initial_stat(creature_ptr);
374         if (decide_body_spec(creature_ptr, chara_limit, &accept))
375             return;
376
377         if (display_auto_roller_count(creature_ptr, col))
378             return;
379     }
380 }
381
382 static bool display_auto_roller_result(player_type *creature_ptr, bool prev, char *c)
383 {
384     BIT_FLAGS mode = 0;
385     while (TRUE) {
386         creature_ptr->update |= (PU_BONUS | PU_HP);
387         update_creature(creature_ptr);
388         creature_ptr->chp = creature_ptr->mhp;
389         creature_ptr->csp = creature_ptr->msp;
390         display_player(creature_ptr, mode);
391         term_gotoxy(2, 23);
392         const char b1 = '[';
393         term_addch(TERM_WHITE, b1);
394         term_addstr(-1, TERM_WHITE, _("'r' 次の数値", "'r'eroll"));
395         if (prev)
396             term_addstr(-1, TERM_WHITE, _(", 'p' 前の数値", "'p'previous"));
397
398         if (mode)
399             term_addstr(-1, TERM_WHITE, _(", 'h' その他の情報", ", 'h' Misc."));
400         else
401             term_addstr(-1, TERM_WHITE, _(", 'h' 生い立ちを表示", ", 'h'istory"));
402
403         term_addstr(-1, TERM_WHITE, _(", Enter この数値に決定", ", or Enter to accept"));
404         const char b2 = ']';
405         term_addch(TERM_WHITE, b2);
406         *c = inkey();
407         if (*c == 'Q')
408             birth_quit();
409
410         if (*c == 'S')
411             return FALSE;
412
413         if (*c == '\r' || *c == '\n' || *c == ESCAPE)
414             break;
415
416         if ((*c == ' ') || (*c == 'r'))
417             break;
418
419         if (prev && (*c == 'p')) {
420             load_prev_data(creature_ptr, TRUE);
421             continue;
422         }
423
424         if ((*c == 'H') || (*c == 'h')) {
425             mode = ((mode != 0) ? 0 : 1);
426             continue;
427         }
428
429         birth_help_option(creature_ptr, *c, BK_AUTO_ROLLER);
430         bell();
431     }
432
433     return TRUE;
434 }
435
436 /*
437  * @brief オートロールを回して結果を表示し、その数値に決めるかさらに回すか確認する。
438  * @param creature_ptr プレーヤーへの参照ポインタ
439  * @param chara_limit 社会的地位の要求水準
440  * @detail 2つめの結果以降は、'p'キーで1つ前のロール結果に戻せる。
441  */
442 static bool display_auto_roller(player_type *creature_ptr, chara_limit_type chara_limit)
443 {
444     bool prev = FALSE;
445
446     while (TRUE) {
447         int col = 42;
448         if (autoroller || autochara) {
449             term_clear();
450             put_str(_("回数 :", "Round:"), 10, col + 13);
451             put_str(_("(ESCで停止)", "(Hit ESC to stop)"), 12, col + 13);
452         } else {
453             get_stats(creature_ptr);
454             get_ahw(creature_ptr);
455             get_history(creature_ptr);
456         }
457
458         display_auto_roller_success_rate(col);
459         exe_auto_roller(creature_ptr, chara_limit, col);
460         if (autoroller || autochara)
461             sound(SOUND_LEVEL);
462
463         flush();
464
465         get_extra(creature_ptr, TRUE);
466         get_money(creature_ptr);
467         creature_ptr->chaos_patron = (s16b)randint0(MAX_PATRON);
468
469         char c;
470         if (!display_auto_roller_result(creature_ptr, prev, &c))
471             return FALSE;
472
473         if (c == '\r' || c == '\n' || c == ESCAPE)
474             break;
475
476         save_prev_data(creature_ptr, &previous_char);
477         previous_char.quick_ok = FALSE;
478         prev = TRUE;
479     }
480
481     return TRUE;
482 }
483
484 /*!
485  * @brief 名前と生い立ちを設定する
486  * @param creature_ptr プレーヤーへの参照ポインタ
487  * @param process_autopick_file_command 自動拾いコマンドへの関数ポインタ
488  * @return なし
489  * @details ついでにステータス限界もここで決めている
490  */
491 static void set_name_history(player_type *creature_ptr, void (*process_autopick_file_command)(char *))
492 {
493     clear_from(23);
494     get_name(creature_ptr);
495     process_player_name(creature_ptr, current_world_ptr->creating_savefile);
496     edit_history(creature_ptr, process_autopick_file_command);
497     get_max_stats(creature_ptr);
498     get_virtues(creature_ptr);
499     prt(_("[ 'Q' 中断, 'S' 初めから, Enter ゲーム開始 ]", "['Q'uit, 'S'tart over, or Enter to continue]"), 23, _(14, 10));
500 }
501
502 /*!
503  * @brief プレーヤーキャラ作成ウィザード
504  * @details
505  * The delay may be reduced, but is recommended to keep players
506  * from continuously rolling up characters, which can be VERY
507  * expensive CPU wise.  And it cuts down on player stupidity.
508  * @return なし
509  */
510 bool player_birth_wizard(player_type *creature_ptr, void (*process_autopick_file_command)(char *))
511 {
512     display_initial_birth_message(creature_ptr);
513     const char p2 = ')';
514     char buf[80];
515     for (int n = 0; n < MAX_SEXES; n++) {
516         sp_ptr = &sex_info[n];
517         sprintf(buf, _("%c%c%s", "%c%c %s"), I2A(n), p2, sp_ptr->title);
518         put_str(buf, 12 + (n / 5), 2 + 15 * (n % 5));
519     }
520
521     if (!let_player_build_character(creature_ptr))
522         return FALSE;
523
524     display_initial_options(creature_ptr);
525     if (autoroller || autochara)
526         auto_round = 0L;
527
528     if (autoroller)
529         if (!get_stat_limits(creature_ptr))
530             return FALSE;
531
532     chara_limit_type chara_limit;
533     initialize_chara_limit(&chara_limit);
534     if (autochara)
535         if (!get_chara_limits(creature_ptr, &chara_limit))
536             return FALSE;
537
538     clear_from(10);
539     init_turn(creature_ptr);
540     if (!display_auto_roller(creature_ptr, chara_limit))
541         return FALSE;
542
543     set_name_history(creature_ptr, process_autopick_file_command);
544     char c = inkey();
545     if (c == 'Q')
546         birth_quit();
547
548     if (c == 'S')
549         return FALSE;
550
551     init_dungeon_quests(creature_ptr);
552     save_prev_data(creature_ptr, &previous_char);
553     previous_char.quick_ok = TRUE;
554     return TRUE;
555 }