OSDN Git Service

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