OSDN Git Service

[Fix] クイックメッセージの挙動が以前と異なる
[hengband/hengband.git] / src / main / angband-initializer.c
1 /*!
2  * @brief ゲームデータ初期化
3  * @date 2014/01/28
4  * @author
5  * <pre>
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7  * This software may be copied and distributed for educational, research,
8  * and not for profit purposes provided that this copyright and statement
9  * are included in all such copies.  Other copyrights may also apply.
10  * 2014 Deskull rearranged comment for Doxygen.\n
11  * </pre>
12  */
13
14 #include "main/angband-initializer.h"
15 #include "dungeon/dungeon.h"
16 #include "floor/wild.h"
17 #include "info-reader/feature-reader.h"
18 #include "io/files-util.h"
19 #include "io/read-pref-file.h"
20 #include "io/uid-checker.h"
21 #include "main/game-data-initializer.h"
22 #include "main/info-initializer.h"
23 #include "market/building-initializer.h"
24 #include "monster-race/monster-race.h"
25 #include "monster-race/race-flags7.h"
26 #include "system/angband-version.h"
27 #include "system/system-variables.h"
28 #include "term/screen-processor.h"
29 #include "term/term-color-types.h"
30 #include "util/angband-files.h"
31 #include "world/world.h"
32
33 char *file_read__buf;
34 char *file_read__swp;
35 char *file_read__tmp;
36
37 /*!
38  * @brief 各データファイルを読み取るためのパスを取得する
39  * Find the default paths to all of our important sub-directories.
40  * @param path パス保管先の文字列
41  * @return なし
42  */
43 void init_file_paths(char *libpath, char *varpath)
44 {
45     char *libtail, *vartail;
46
47 #ifdef PRIVATE_USER_PATH
48     char buf[1024];
49 #endif
50     string_free(ANGBAND_DIR);
51     string_free(ANGBAND_DIR_APEX);
52     string_free(ANGBAND_DIR_BONE);
53     string_free(ANGBAND_DIR_DATA);
54     string_free(ANGBAND_DIR_EDIT);
55     string_free(ANGBAND_DIR_SCRIPT);
56     string_free(ANGBAND_DIR_FILE);
57     string_free(ANGBAND_DIR_HELP);
58     string_free(ANGBAND_DIR_INFO);
59     string_free(ANGBAND_DIR_SAVE);
60     string_free(ANGBAND_DIR_USER);
61     string_free(ANGBAND_DIR_XTRA);
62
63     ANGBAND_DIR = string_make(libpath);
64     libtail = libpath + strlen(libpath);
65     vartail = varpath + strlen(varpath);
66     strcpy(vartail, "apex");
67     ANGBAND_DIR_APEX = string_make(varpath);
68     strcpy(vartail, "bone");
69     ANGBAND_DIR_BONE = string_make(varpath);
70     strcpy(vartail, "data");
71     ANGBAND_DIR_DATA = string_make(varpath);
72     strcpy(libtail, "edit");
73     ANGBAND_DIR_EDIT = string_make(libpath);
74     strcpy(libtail, "script");
75     ANGBAND_DIR_SCRIPT = string_make(libpath);
76     strcpy(libtail, "file");
77     ANGBAND_DIR_FILE = string_make(libpath);
78     strcpy(libtail, "help");
79     ANGBAND_DIR_HELP = string_make(libpath);
80     strcpy(libtail, "info");
81     ANGBAND_DIR_INFO = string_make(libpath);
82     strcpy(libtail, "pref");
83     ANGBAND_DIR_PREF = string_make(libpath);
84     strcpy(vartail, "save");
85     ANGBAND_DIR_SAVE = string_make(varpath);
86 #ifdef PRIVATE_USER_PATH
87     path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
88     ANGBAND_DIR_USER = string_make(buf);
89 #else
90     strcpy(vartail, "user");
91     ANGBAND_DIR_USER = string_make(varpath);
92 #endif
93     strcpy(libtail, "xtra");
94     ANGBAND_DIR_XTRA = string_make(libpath);
95 }
96
97 /*!
98  * @brief 画面左下にシステムメッセージを表示する / Take notes on line 23
99  * @param str 初期化中のコンテンツ文字列
100  * @return なし
101  */
102 static void init_note(concptr str)
103 {
104     term_erase(0, 23, 255);
105     term_putstr(20, 23, -1, TERM_WHITE, str);
106     term_fresh();
107 }
108
109 /*!
110  * @brief 全ゲームデータ読み込みのサブルーチン / Explain a broken "lib" folder and quit (see below).
111  * @param なし
112  * @return なし
113  * @note
114  * <pre>
115  * This function is "messy" because various things
116  * may or may not be initialized, but the "plog()" and "quit()"
117  * functions are "supposed" to work under any conditions.
118  * </pre>
119  */
120 static void init_angband_aux(concptr why)
121 {
122     plog(why);
123     plog(_("'lib'ディレクトリが存在しないか壊れているようです。", "The 'lib' directory is probably missing or broken."));
124     plog(_("ひょっとするとアーカイブが正しく解凍されていないのかもしれません。", "The 'lib' directory is probably missing or broken."));
125     plog(_("該当する'README'ファイルを読んで確認してみて下さい。", "See the 'README' file for more information."));
126     quit(_("致命的なエラー。", "Fatal Error."));
127 }
128
129 /*!
130  * @brief タイトル記述
131  * @param なし
132  * @return なし
133  */
134 static void put_title(void)
135 {
136     char title[120];
137     put_version(title);
138
139     int col = (80 - strlen(title)) / 2;
140     col = col < 0 ? 0 : col;
141     const int VER_INFO_ROW = 3; //!< タイトル表記(行)
142     prt(title, VER_INFO_ROW, col);
143 }
144
145 /*!
146  * @brief 全ゲームデータ読み込みのメインルーチン /
147  * @param player_ptr プレーヤーへの参照ポインタ
148  * @param process_autopick_file_command 自動拾いファイル読み込み関数への関数ポインタ
149  * @return なし
150  */
151 void init_angband(player_type *player_ptr, process_autopick_file_command_pf process_autopick_file_command)
152 {
153     C_MAKE(file_read__buf, FILE_READ_BUFF_SIZE, char);
154     C_MAKE(file_read__swp, FILE_READ_BUFF_SIZE, char);
155     C_MAKE(file_read__tmp, FILE_READ_BUFF_SIZE, char);
156     char buf[1024];
157     path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
158     int fd = fd_open(buf, O_RDONLY);
159     if (fd < 0) {
160         char why[1024];
161         sprintf(why, _("'%s'ファイルにアクセスできません!", "Cannot access the '%s' file!"), buf);
162         init_angband_aux(why);
163     }
164
165     (void)fd_close(fd);
166     term_clear();
167     path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
168     FILE *fp;
169     fp = angband_fopen(buf, "r");
170     if (fp) {
171         int i = 0;
172         while (0 == angband_fgets(fp, buf, sizeof(buf)))
173             term_putstr(0, i++, -1, TERM_WHITE, buf);
174
175         angband_fclose(fp);
176     }
177
178     term_flush();
179     path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
180     fd = fd_open(buf, O_RDONLY);
181     BIT_FLAGS file_permission = 0664;
182     if (fd < 0) {
183         safe_setuid_grab(player_ptr);
184         fd = fd_make(buf, file_permission);
185         safe_setuid_drop();
186         if (fd < 0) {
187             char why[1024];
188             sprintf(why, _("'%s'ファイルを作成できません!", "Cannot create the '%s' file!"), buf);
189             init_angband_aux(why);
190         }
191     }
192
193     (void)fd_close(fd);
194     put_title();
195
196     init_note(_("[変数を初期化しています...(その他)", "[Initializing values... (misc)]"));
197     if (init_misc(player_ptr))
198         quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
199
200     init_note(_("[データの初期化中... (地形)]", "[Initializing arrays... (features)]"));
201     if (init_f_info(player_ptr))
202         quit(_("地形初期化不能", "Cannot initialize features"));
203
204     if (init_feat_variables())
205         quit(_("地形初期化不能", "Cannot initialize features"));
206
207     init_note(_("[データの初期化中... (アイテム)]", "[Initializing arrays... (objects)]"));
208     if (init_k_info(player_ptr))
209         quit(_("アイテム初期化不能", "Cannot initialize objects"));
210
211     init_note(_("[データの初期化中... (伝説のアイテム)]", "[Initializing arrays... (artifacts)]"));
212     if (init_a_info(player_ptr))
213         quit(_("伝説のアイテム初期化不能", "Cannot initialize artifacts"));
214
215     init_note(_("[データの初期化中... (名のあるアイテム)]", "[Initializing arrays... (ego-items)]"));
216     if (init_e_info(player_ptr))
217         quit(_("名のあるアイテム初期化不能", "Cannot initialize ego-items"));
218
219     init_note(_("[データの初期化中... (モンスター)]", "[Initializing arrays... (monsters)]"));
220     if (init_r_info(player_ptr))
221         quit(_("モンスター初期化不能", "Cannot initialize monsters"));
222
223     init_note(_("[データの初期化中... (ダンジョン)]", "[Initializing arrays... (dungeon)]"));
224     if (init_d_info(player_ptr))
225         quit(_("ダンジョン初期化不能", "Cannot initialize dungeon"));
226
227     for (int i = 1; i < current_world_ptr->max_d_idx; i++)
228         if (d_info[i].final_guardian)
229             r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
230
231     init_note(_("[データの初期化中... (魔法)]", "[Initializing arrays... (magic)]"));
232     if (init_m_info(player_ptr))
233         quit(_("魔法初期化不能", "Cannot initialize magic"));
234
235     init_note(_("[データの初期化中... (熟練度)]", "[Initializing arrays... (skill)]"));
236     if (init_s_info(player_ptr))
237         quit(_("熟練度初期化不能", "Cannot initialize skill"));
238
239     init_note(_("[配列を初期化しています... (荒野)]", "[Initializing arrays... (wilderness)]"));
240     if (init_wilderness())
241         quit(_("荒野を初期化できません", "Cannot initialize wilderness"));
242
243     init_note(_("[配列を初期化しています... (街)]", "[Initializing arrays... (towns)]"));
244     if (init_towns())
245         quit(_("街を初期化できません", "Cannot initialize towns"));
246
247     init_note(_("[配列を初期化しています... (建物)]", "[Initializing arrays... (buildings)]"));
248     if (init_buildings())
249         quit(_("建物を初期化できません", "Cannot initialize buildings"));
250
251     init_note(_("[配列を初期化しています... (クエスト)]", "[Initializing arrays... (quests)]"));
252     if (init_quests())
253         quit(_("クエストを初期化できません", "Cannot initialize quests"));
254
255     if (init_v_info(player_ptr))
256         quit(_("vault 初期化不能", "Cannot initialize vaults"));
257
258     init_note(_("[データの初期化中... (その他)]", "[Initializing arrays... (other)]"));
259     if (init_other(player_ptr))
260         quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
261
262     init_note(_("[データの初期化中... (アロケーション)]", "[Initializing arrays... (alloc)]"));
263     if (init_alloc())
264         quit(_("アロケーション・スタッフ初期化不能", "Cannot initialize alloc stuff"));
265
266     init_note(_("[ユーザー設定ファイルを初期化しています...]", "[Initializing user pref files...]"));
267     strcpy(buf, "pref.prf");
268     process_pref_file(player_ptr, buf, process_autopick_file_command);
269     sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
270     process_pref_file(player_ptr, buf, process_autopick_file_command);
271     init_note(_("[初期化終了]", "[Initialization complete]"));
272 }