OSDN Git Service

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