OSDN Git Service

Merge pull request #765 from sikabane-works/release/3.0.0Alpha17
[hengbandforosx/hengbandosx.git] / src / birth / quick-start.cpp
1 #include "birth/quick-start.h"
2 #include "birth/birth-stat.h"
3 #include "birth/birth-util.h"
4 #include "birth/game-play-initializer.h"
5 #include "core/player-update-types.h"
6 #include "io/input-key-acceptor.h"
7 #include "player/player-class.h"
8 #include "player/player-personality.h"
9 #include "player/player-race.h"
10 #include "player/player-sex.h"
11 #include "player/process-name.h"
12 #include "player/race-info-table.h"
13 #include "term/screen-processor.h"
14
15 /*
16  * The last character rolled,
17  * holded for quick start
18  */
19 birther previous_char;
20
21 /*!
22  * @brief クイックスタート処理の問い合わせと実行を行う。/Ask whether the player use Quick Start or not.
23  * @return なし
24  */
25 bool ask_quick_start(player_type *creature_ptr)
26 {
27     if (!previous_char.quick_ok)
28         return FALSE;
29
30     term_clear();
31     put_str(_("クイック・スタートを使うと以前と全く同じキャラクターで始められます。",
32                 "Do you want to use the quick start function (same character as your last one)."),
33         11, 2);
34     while (TRUE) {
35         char c;
36         put_str(_("クイック・スタートを使いますか?[y/N]", "Use quick start? [y/N]"), 14, 10);
37         c = inkey();
38         if (c == 'Q')
39             quit(NULL);
40         else if (c == 'S')
41             return FALSE;
42         else if (c == '?')
43             show_help(creature_ptr, _("jbirth.txt#QuickStart", "birth.txt#QuickStart"));
44         else if ((c == 'y') || (c == 'Y'))
45             break;
46         else
47             return FALSE;
48     }
49
50     load_prev_data(creature_ptr, FALSE);
51     init_turn(creature_ptr);
52     init_dungeon_quests(creature_ptr);
53
54     sp_ptr = &sex_info[creature_ptr->psex];
55     rp_ptr = &race_info[creature_ptr->prace];
56     cp_ptr = &class_info[creature_ptr->pclass];
57     mp_ptr = &m_info[creature_ptr->pclass];
58     ap_ptr = &personality_info[creature_ptr->pseikaku];
59
60     get_extra(creature_ptr, FALSE);
61     creature_ptr->update |= (PU_BONUS | PU_HP);
62     update_creature(creature_ptr);
63     creature_ptr->chp = creature_ptr->mhp;
64     creature_ptr->csp = creature_ptr->msp;
65     process_player_name(creature_ptr);
66     return TRUE;
67 }
68 /*!
69  * @brief プレイヤーのクイックスタート情報をプレイヤー構造体から保存する / Save the current data for later
70  * @param birther_ptr クイックスタート構造体の参照ポインタ
71  * @return なし。
72  */
73 void save_prev_data(player_type *creature_ptr, birther *birther_ptr)
74 {
75     birther_ptr->psex = creature_ptr->psex;
76     birther_ptr->prace = creature_ptr->prace;
77     birther_ptr->pclass = creature_ptr->pclass;
78     birther_ptr->pseikaku = creature_ptr->pseikaku;
79
80     if (creature_ptr->pclass == CLASS_ELEMENTALIST)
81         birther_ptr->realm1 = creature_ptr->element;
82     else
83         birther_ptr->realm1 = creature_ptr->realm1;
84
85     birther_ptr->realm2 = creature_ptr->realm2;
86     birther_ptr->age = creature_ptr->age;
87     birther_ptr->ht = creature_ptr->ht;
88     birther_ptr->wt = creature_ptr->wt;
89     birther_ptr->sc = creature_ptr->sc;
90     birther_ptr->au = creature_ptr->au;
91
92     for (int i = 0; i < A_MAX; i++) {
93         birther_ptr->stat_max[i] = creature_ptr->stat_max[i];
94         birther_ptr->stat_max_max[i] = creature_ptr->stat_max_max[i];
95     }
96
97     for (int i = 0; i < PY_MAX_LEVEL; i++) {
98         birther_ptr->player_hp[i] = creature_ptr->player_hp[i];
99     }
100
101     birther_ptr->chaos_patron = creature_ptr->chaos_patron;
102     for (int i = 0; i < 8; i++) {
103         birther_ptr->vir_types[i] = creature_ptr->vir_types[i];
104     }
105
106     for (int i = 0; i < 4; i++) {
107         strcpy(birther_ptr->history[i], creature_ptr->history[i]);
108     }
109 }
110
111 /*!
112  * @brief プレイヤーのクイックスタート情報をプレイヤー構造体へ読み込む / Load the previous data
113  * @param swap TRUEならば現在のプレイヤー構造体上との内容をスワップする形で読み込む。
114  * @return なし。
115  */
116 void load_prev_data(player_type *creature_ptr, bool swap)
117 {
118     birther temp;
119     if (swap)
120         save_prev_data(creature_ptr, &temp);
121
122     creature_ptr->psex = previous_char.psex;
123     creature_ptr->prace = previous_char.prace;
124     creature_ptr->pclass = previous_char.pclass;
125     creature_ptr->pseikaku = previous_char.pseikaku;
126
127     if (creature_ptr->pclass == CLASS_ELEMENTALIST)
128         creature_ptr->element = previous_char.realm1;
129     else
130         creature_ptr->realm1 = previous_char.realm1;
131
132     creature_ptr->realm2 = previous_char.realm2;
133     creature_ptr->age = previous_char.age;
134     creature_ptr->ht = previous_char.ht;
135     creature_ptr->wt = previous_char.wt;
136     creature_ptr->sc = previous_char.sc;
137     creature_ptr->au = previous_char.au;
138
139     for (int i = 0; i < A_MAX; i++) {
140         creature_ptr->stat_cur[i] = creature_ptr->stat_max[i] = previous_char.stat_max[i];
141         creature_ptr->stat_max_max[i] = previous_char.stat_max_max[i];
142     }
143
144     for (int i = 0; i < PY_MAX_LEVEL; i++) {
145         creature_ptr->player_hp[i] = previous_char.player_hp[i];
146     }
147
148     creature_ptr->mhp = creature_ptr->player_hp[0];
149     creature_ptr->chp = creature_ptr->player_hp[0];
150     creature_ptr->chaos_patron = previous_char.chaos_patron;
151     for (int i = 0; i < 8; i++) {
152         creature_ptr->vir_types[i] = previous_char.vir_types[i];
153     }
154
155     for (int i = 0; i < 4; i++) {
156         strcpy(creature_ptr->history[i], previous_char.history[i]);
157     }
158
159     if (swap) {
160         (void)COPY(&previous_char, &temp, birther);
161     }
162 }