OSDN Git Service

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