OSDN Git Service

Merge pull request #1510 from habu1010/feature/refactor-smith-info-class
[hengbandforosx/hengbandosx.git] / src / birth / game-play-initializer.cpp
1 #include "birth/game-play-initializer.h"
2 #include "dungeon/dungeon.h"
3 #include "dungeon/quest.h"
4 #include "floor/floor-util.h"
5 #include "game-option/birth-options.h"
6 #include "game-option/cheat-options.h"
7 #include "info-reader/fixed-map-parser.h"
8 #include "inventory/inventory-slot-types.h"
9 #include "market/arena.h"
10 #include "monster-race/monster-race.h"
11 #include "monster-race/race-flags1.h"
12 #include "monster-race/race-flags7.h"
13 #include "object/object-kind.h"
14 #include "pet/pet-util.h"
15 #include "player-info/race-info.h"
16 #include "player-info/race-types.h"
17 #include "player/digestion-processor.h"
18 #include "system/artifact-type-definition.h"
19 #include "system/floor-type-definition.h"
20 #include "system/monster-race-definition.h"
21 #include "system/player-type-definition.h"
22 #include "world/world.h"
23
24 /*!
25  * @brief ベースアイテム構造体の鑑定済みフラグをリセットする。
26  * @details
27  * 不具合対策で0からリセットする(セーブは0から)
28  */
29 static void k_info_reset(void)
30 {
31     for (int i = 0; i < max_k_idx; i++) {
32         object_kind *k_ptr = &k_info[i];
33         k_ptr->tried = false;
34         k_ptr->aware = false;
35     }
36 }
37
38 /*!
39  * @brief プレイヤー構造体の内容を初期値で消去する(名前を除く) / Clear all the global "character" data (without name)
40  * @param player_ptr プレーヤーへの参照ポインタ
41  * @details 少し長いが、これ1つで処理が完結しているので分割は見送る
42  */
43 void player_wipe_without_name(player_type *player_ptr)
44 {
45     player_type tmp;
46
47 #ifdef SET_UID
48     int uid = player_ptr->player_uid;
49 #endif
50     COPY(&tmp, player_ptr, player_type);
51     if (player_ptr->last_message)
52         string_free(player_ptr->last_message);
53
54     if (player_ptr->inventory_list != nullptr)
55         C_KILL(player_ptr->inventory_list, INVEN_TOTAL, object_type);
56
57     (void)WIPE(player_ptr, player_type);
58
59     // TODO: キャラ作成からゲーム開始までに  current_floor_ptr を参照しなければならない処理は今後整理して外す。
60     player_ptr->current_floor_ptr = &floor_info;
61     C_MAKE(player_ptr->inventory_list, INVEN_TOTAL, object_type);
62     for (int i = 0; i < 4; i++)
63         strcpy(player_ptr->history[i], "");
64
65     for (int i = 0; i < max_q_idx; i++) {
66         quest_type *const q_ptr = &quest[i];
67         q_ptr->status = QUEST_STATUS_UNTAKEN;
68         q_ptr->cur_num = 0;
69         q_ptr->max_num = 0;
70         q_ptr->type = 0;
71         q_ptr->level = 0;
72         q_ptr->r_idx = 0;
73         q_ptr->complev = 0;
74         q_ptr->comptime = 0;
75     }
76
77     player_ptr->inven_cnt = 0;
78     player_ptr->equip_cnt = 0;
79     for (int i = 0; i < INVEN_TOTAL; i++)
80         (&player_ptr->inventory_list[i])->wipe();
81
82     for (int i = 0; i < max_a_idx; i++) {
83         artifact_type *a_ptr = &a_info[i];
84         a_ptr->cur_num = 0;
85     }
86
87     k_info_reset();
88     for (int i = 1; i < max_r_idx; i++) {
89         monster_race *r_ptr = &r_info[i];
90         r_ptr->cur_num = 0;
91         r_ptr->max_num = 100;
92         if (r_ptr->flags1 & RF1_UNIQUE)
93             r_ptr->max_num = 1;
94         else if (r_ptr->flags7 & RF7_NAZGUL)
95             r_ptr->max_num = MAX_NAZGUL_NUM;
96
97         r_ptr->r_pkills = 0;
98         r_ptr->r_akills = 0;
99     }
100
101     player_ptr->food = PY_FOOD_FULL - 1;
102     if (player_ptr->pclass == CLASS_SORCERER) {
103         player_ptr->spell_learned1 = player_ptr->spell_learned2 = 0xffffffffL;
104         player_ptr->spell_worked1 = player_ptr->spell_worked2 = 0xffffffffL;
105     } else {
106         player_ptr->spell_learned1 = player_ptr->spell_learned2 = 0L;
107         player_ptr->spell_worked1 = player_ptr->spell_worked2 = 0L;
108     }
109
110     player_ptr->spell_forgotten1 = player_ptr->spell_forgotten2 = 0L;
111     for (int i = 0; i < 64; i++)
112         player_ptr->spell_order[i] = 99;
113
114     player_ptr->learned_spells = 0;
115     player_ptr->add_spells = 0;
116     player_ptr->knowledge = 0;
117     player_ptr->mutant_regenerate_mod = 100;
118
119     cheat_peek = false;
120     cheat_hear = false;
121     cheat_room = false;
122     cheat_xtra = false;
123     cheat_know = false;
124     cheat_live = false;
125     cheat_save = false;
126     cheat_diary_output = false;
127     cheat_turn = false;
128     cheat_immortal = false;
129
130     current_world_ptr->total_winner = false;
131     player_ptr->timewalk = false;
132     player_ptr->panic_save = 0;
133
134     current_world_ptr->noscore = 0;
135     current_world_ptr->wizard = false;
136     player_ptr->wait_report_score = false;
137     player_ptr->pet_follow_distance = PET_FOLLOW_DIST;
138     player_ptr->pet_extra_flags = (PF_TELEPORT | PF_ATTACK_SPELL | PF_SUMMON_SPELL);
139
140     for (int i = 0; i < current_world_ptr->max_d_idx; i++)
141         max_dlv[i] = 0;
142
143     player_ptr->visit = 1;
144     player_ptr->wild_mode = false;
145
146     for (int i = 0; i < MAX_SPELLS; i++) {
147         player_ptr->magic_num1[i] = 0;
148         player_ptr->magic_num2[i] = 0;
149     }
150
151     player_ptr->max_plv = player_ptr->lev = 1;
152     player_ptr->arena_number = 0;
153     player_ptr->current_floor_ptr->inside_arena = false;
154     player_ptr->current_floor_ptr->inside_quest = 0;
155     for (int i = 0; i < MAX_MANE; i++) {
156         player_ptr->mane_spell[i] = RF_ABILITY::MAX;
157         player_ptr->mane_dam[i] = 0;
158     }
159
160     player_ptr->mane_num = 0;
161     player_ptr->exit_bldg = true;
162     player_ptr->today_mon = 0;
163     update_gambling_monsters(player_ptr);
164     player_ptr->muta.clear();
165
166     for (int i = 0; i < 8; i++)
167         player_ptr->virtues[i] = 0;
168
169     player_ptr->dungeon_idx = 0;
170     if (vanilla_town || ironman_downward) {
171         player_ptr->recall_dungeon = DUNGEON_ANGBAND;
172     } else {
173         player_ptr->recall_dungeon = DUNGEON_GALGALS;
174     }
175
176     memcpy(player_ptr->name, tmp.name, sizeof(tmp.name));
177
178 #ifdef SET_UID
179     player_ptr->player_uid = uid;
180 #endif
181 }
182
183 /*!
184  * @brief ダンジョン内部のクエストを初期化する / Initialize random quests and final quests
185  * @param player_ptr プレーヤーへの参照ポインタ
186  */
187 void init_dungeon_quests(player_type *player_ptr)
188 {
189     int number_of_quests = MAX_RANDOM_QUEST - MIN_RANDOM_QUEST + 1;
190     init_flags = INIT_ASSIGN;
191     floor_type *floor_ptr = player_ptr->current_floor_ptr;
192     floor_ptr->inside_quest = MIN_RANDOM_QUEST;
193     parse_fixed_map(player_ptr, "q_info.txt", 0, 0, 0, 0);
194     floor_ptr->inside_quest = 0;
195     for (int i = MIN_RANDOM_QUEST + number_of_quests - 1; i >= MIN_RANDOM_QUEST; i--) {
196         quest_type *q_ptr = &quest[i];
197         monster_race *quest_r_ptr;
198         q_ptr->status = QUEST_STATUS_TAKEN;
199         determine_random_questor(player_ptr, q_ptr);
200         quest_r_ptr = &r_info[q_ptr->r_idx];
201         quest_r_ptr->flags1 |= RF1_QUESTOR;
202         q_ptr->max_num = 1;
203     }
204
205     init_flags = INIT_ASSIGN;
206     floor_ptr->inside_quest = QUEST_OBERON;
207     parse_fixed_map(player_ptr, "q_info.txt", 0, 0, 0, 0);
208     quest[QUEST_OBERON].status = QUEST_STATUS_TAKEN;
209
210     floor_ptr->inside_quest = QUEST_SERPENT;
211     parse_fixed_map(player_ptr, "q_info.txt", 0, 0, 0, 0);
212     quest[QUEST_SERPENT].status = QUEST_STATUS_TAKEN;
213     floor_ptr->inside_quest = 0;
214 }
215
216 /*!
217  * @brief ゲームターンを初期化する / Reset turn
218  * @param player_ptr プレーヤーへの参照ポインタ
219  * @details アンデッド系種族は開始時刻を夜からにする / Undead start just sunset
220  * @details
221  */
222 void init_turn(player_type *player_ptr)
223 {
224     if (player_race_life(player_ptr) == PlayerRaceLife::UNDEAD) {
225         current_world_ptr->game_turn = (TURNS_PER_TICK * 3 * TOWN_DAWN) / 4 + 1;
226         current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * MAX_DAYS + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
227     } else {
228         current_world_ptr->game_turn = 1;
229         current_world_ptr->game_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
230     }
231
232     current_world_ptr->dungeon_turn = 1;
233     current_world_ptr->dungeon_turn_limit = TURNS_PER_TICK * TOWN_DAWN * (MAX_DAYS - 1) + TURNS_PER_TICK * TOWN_DAWN * 3 / 4;
234 }