OSDN Git Service

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