OSDN Git Service

[Refactor] #40635 Reshaped init.c
authorHourier <hourier@users.sourceforge.jp>
Thu, 20 Aug 2020 11:30:26 +0000 (20:30 +0900)
committerHourier <hourier@users.sourceforge.jp>
Fri, 21 Aug 2020 00:51:14 +0000 (09:51 +0900)
src/main/init.c
src/main/init.h

index 7e225e8..b72d3ed 100644 (file)
@@ -46,7 +46,7 @@
 #include "info-reader/dungeon-reader.h"
 #include "info-reader/ego-reader.h"
 #include "info-reader/feature-reader.h"
-#include "info-reader/fixed-map-parser.h" // 相互参照、後で何とかする.
+#include "info-reader/fixed-map-parser.h"
 #include "info-reader/general-parser.h"
 #include "info-reader/kind-reader.h"
 #include "info-reader/magic-reader.h"
@@ -127,17 +127,10 @@ static const int MACRO_MAX = 256;
 void init_file_paths(char *path)
 {
     char *tail;
-
 #ifdef PRIVATE_USER_PATH
     char buf[1024];
-#endif /* PRIVATE_USER_PATH */
-
-    /*** Free everything ***/
-
-    /* Free the main path */
+#endif
     string_free(ANGBAND_DIR);
-
-    /* Free the sub-paths */
     string_free(ANGBAND_DIR_APEX);
     string_free(ANGBAND_DIR_BONE);
     string_free(ANGBAND_DIR_DATA);
@@ -150,73 +143,35 @@ void init_file_paths(char *path)
     string_free(ANGBAND_DIR_USER);
     string_free(ANGBAND_DIR_XTRA);
 
-    /*** Prepare the "path" ***/
-
-    /* Hack -- save the main directory */
     ANGBAND_DIR = string_make(path);
-
-    /* Prepare to append to the Base Path */
     tail = path + strlen(path);
-
-    /*** Build the sub-directory names ***/
-
-    /* Build a path name */
     strcpy(tail, "apex");
     ANGBAND_DIR_APEX = string_make(path);
-
-    /* Build a path name */
     strcpy(tail, "bone");
     ANGBAND_DIR_BONE = string_make(path);
-
-    /* Build a path name */
     strcpy(tail, "data");
     ANGBAND_DIR_DATA = string_make(path);
-
-    /* Build a path name */
     strcpy(tail, "edit");
     ANGBAND_DIR_EDIT = string_make(path);
-
-    /* Build a path name */
     strcpy(tail, "script");
     ANGBAND_DIR_SCRIPT = string_make(path);
-
-    /* Build a path name */
     strcpy(tail, "file");
     ANGBAND_DIR_FILE = string_make(path);
-
-    /* Build a path name */
     strcpy(tail, "help");
     ANGBAND_DIR_HELP = string_make(path);
-
-    /* Build a path name */
     strcpy(tail, "info");
     ANGBAND_DIR_INFO = string_make(path);
-
-    /* Build a path name */
     strcpy(tail, "pref");
     ANGBAND_DIR_PREF = string_make(path);
-
-    /* Build a path name */
     strcpy(tail, "save");
     ANGBAND_DIR_SAVE = string_make(path);
-
 #ifdef PRIVATE_USER_PATH
-
-    /* Build the path to the user specific directory */
     path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
-
-    /* Build a relative path name */
     ANGBAND_DIR_USER = string_make(buf);
-
-#else /* PRIVATE_USER_PATH */
-
-    /* Build a path name */
+#else
     strcpy(tail, "user");
     ANGBAND_DIR_USER = string_make(path);
-
-#endif /* PRIVATE_USER_PATH */
-
-    /* Build a path name */
+#endif
     strcpy(tail, "xtra");
     ANGBAND_DIR_XTRA = string_make(path);
 }
@@ -232,30 +187,16 @@ int error_line; /*!< データ読み込み/初期化時に汎用的にエラー
  */
 concptr err_str[PARSE_ERROR_MAX] = {
     NULL,
-#ifdef JP
-    "文法エラー",
-    "古いファイル",
-    "記録ヘッダがない",
-    "不連続レコード",
-    "おかしなフラグ存在",
-    "未定義命令",
-    "メモリ不足",
-    "座標範囲外",
-    "引数不足",
-    "未定義地形タグ",
-#else
-    "parse error",
-    "obsolete file",
-    "missing record header",
-    "non-sequential records",
-    "invalid flag specification",
-    "undefined directive",
-    "out of memory",
-    "coordinates out of bounds",
-    "too few arguments",
-    "undefined terrain tag",
-#endif
-
+    _("文法エラー", "parse error"),
+    _("古いファイル", "obsolete file"),
+    _("記録ヘッダがない", "missing record header"),
+    _("不連続レコード", "non-sequential records"),
+    _("おかしなフラグ存在", "invalid flag specification"),
+    _("未定義命令", "undefined directive"),
+    _("メモリ不足", "out of memory"),
+    _("座標範囲外", "coordinates out of bounds"),
+    _("引数不足", "too few arguments"),
+    _("未定義地形タグ", "undefined terrain tag"),
 };
 
 /*
@@ -282,21 +223,14 @@ static errr check_modification_date(int fd, concptr template_file)
     struct stat txt_stat, raw_stat;
     char buf[1024];
     path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
-
-    /* Access stats on text file */
-    if (stat(buf, &txt_stat)) {
+    if (stat(buf, &txt_stat))
         return 0;
-    }
 
-    /* Access stats on raw file */
-    if (fstat(fd, &raw_stat)) {
+    if (fstat(fd, &raw_stat))
         return -1;
-    }
 
-    /* Ensure text file is not newer than raw file */
-    if (txt_stat.st_mtime > raw_stat.st_mtime) {
+    if (txt_stat.st_mtime > raw_stat.st_mtime)
         return -1;
-    }
 
     return 0;
 }
@@ -313,45 +247,27 @@ static errr check_modification_date(int fd, concptr template_file)
 static errr init_info_raw(int fd, angband_header *head)
 {
     angband_header test;
-
-    /* Read and Verify the header */
     if (fd_read(fd, (char *)(&test), sizeof(angband_header)) || (test.v_major != head->v_major) || (test.v_minor != head->v_minor)
         || (test.v_patch != head->v_patch) || (test.info_num != head->info_num) || (test.info_len != head->info_len) || (test.head_size != head->head_size)
         || (test.info_size != head->info_size)) {
-        /* Error */
         return -1;
     }
 
-    /* Accept the header */
-    (*head) = test;
-
-    /* Allocate the "*_info" array */
+    *head = test;
     C_MAKE(head->info_ptr, head->info_size, char);
-
-    /* Read the "*_info" array */
     fd_read(fd, head->info_ptr, head->info_size);
-
     if (head->name_size) {
-        /* Allocate the "*_name" array */
         C_MAKE(head->name_ptr, head->name_size, char);
-
-        /* Read the "*_name" array */
         fd_read(fd, head->name_ptr, head->name_size);
     }
 
     if (head->text_size) {
-        /* Allocate the "*_text" array */
         C_MAKE(head->text_ptr, head->text_size, char);
-
-        /* Read the "*_text" array */
         fd_read(fd, head->text_ptr, head->text_size);
     }
 
     if (head->tag_size) {
-        /* Allocate the "*_tag" array */
         C_MAKE(head->tag_ptr, head->tag_size, char);
-
-        /* Read the "*_tag" array */
         fd_read(fd, head->tag_ptr, head->tag_size);
     }
 
@@ -368,17 +284,14 @@ static errr init_info_raw(int fd, angband_header *head)
  */
 static void init_header(angband_header *head, IDX num, int len)
 {
-    /* Save the "version" */
     head->v_major = FAKE_VER_MAJOR;
     head->v_minor = FAKE_VER_MINOR;
     head->v_patch = FAKE_VER_PATCH;
     head->v_extra = 0;
 
-    /* Save the "record" information */
     head->info_num = (IDX)num;
     head->info_len = len;
 
-    /* Save the size of "*_head" and "*_info" */
     head->head_size = sizeof(angband_header);
     head->info_size = head->info_num * head->info_len;
 }
@@ -387,10 +300,13 @@ static void update_header(angband_header *head, void **info, char **name, char *
 {
     if (info)
         *info = head->info_ptr;
+
     if (name)
         *name = head->name_ptr;
+
     if (text)
         *text = head->text_ptr;
+
     if (tag)
         *tag = head->tag_ptr;
 }
@@ -411,164 +327,102 @@ static void update_header(angband_header *head, void **info, char **name, char *
  */
 static errr init_info(player_type *player_ptr, concptr filename, angband_header *head, void **info, char **name, char **text, char **tag)
 {
-    /* General buffer */
     char buf[1024];
-
-    /*** Load the binary image file ***/
     path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
-
-    /* Attempt to open the "raw" file */
     int fd = fd_open(buf, O_RDONLY);
-
-    /* Process existing "raw" file */
     errr err = 1;
     if (fd >= 0) {
         err = check_modification_date(fd, format("%s.txt", filename));
-
-        /* Attempt to parse the "raw" file */
         if (!err)
             err = init_info_raw(fd, head);
+
         (void)fd_close(fd);
     }
 
-    /* Do we have to parse the *.txt file? */
     BIT_FLAGS file_permission = 0644;
     if (err == 0) {
         update_header(head, info, name, text, tag);
         return 0;
     }
 
-    /*** Make the fake arrays ***/
     C_MAKE(head->info_ptr, head->info_size, char);
-
-    /* Hack -- make "fake" arrays */
     if (name)
         C_MAKE(head->name_ptr, FAKE_NAME_SIZE, char);
+
     if (text)
         C_MAKE(head->text_ptr, FAKE_TEXT_SIZE, char);
+
     if (tag)
         C_MAKE(head->tag_ptr, FAKE_TAG_SIZE, char);
 
     if (info)
-        (*info) = head->info_ptr;
+        *info = head->info_ptr;
+
     if (name)
-        (*name) = head->name_ptr;
+        *name = head->name_ptr;
+
     if (text)
-        (*text) = head->text_ptr;
+        *text = head->text_ptr;
+
     if (tag)
-        (*tag) = head->tag_ptr;
+        *tag = head->tag_ptr;
 
-    /*** Load the ascii template file ***/
     path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
     FILE *fp;
     fp = angband_fopen(buf, "r");
-
-    /* Parse it */
     if (!fp)
         quit(format(_("'%s.txt'ファイルをオープンできません。", "Cannot open '%s.txt' file."), filename));
 
-    /* Parse the file */
     err = init_info_txt(fp, buf, head, head->parse_info_txt);
     angband_fclose(fp);
-
-    /* Errors */
     if (err) {
         concptr oops;
-
+        oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : _("未知の", "unknown"));
 #ifdef JP
-        /* Error string */
-        oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "未知の");
-
         msg_format("'%s.txt'ファイルの %d 行目にエラー。", filename, error_line);
-        msg_format("レコード %d は '%s' エラーがあります。", error_idx, oops);
-        msg_format("構文 '%s'。", buf);
-        msg_print(NULL);
-
-        /* Quit */
-        quit(format("'%s.txt'ファイルにエラー", filename));
 #else
-        /* Error string */
-        oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
-
         msg_format("Error %d at line %d of '%s.txt'.", err, error_line, filename);
-        msg_format("Record %d contains a '%s' error.", error_idx, oops);
-        msg_format("Parsing '%s'.", buf);
-        msg_print(NULL);
-
-        /* Quit */
-        quit(format("Error in '%s.txt' file.", filename));
 #endif
+        msg_format(_("レコード %d は '%s' エラーがあります。", "Record %d contains a '%s' error."), error_idx, oops);
+        msg_format(_("構文 '%s'。", "Parsing '%s'."), buf);
+        msg_print(NULL);
+        quit(format(_("'%s.txt'ファイルにエラー", "Error in '%s.txt' file."), filename));
     }
 
-    /*** Make final retouch on fake tags ***/
-    if (head->retouch) {
+    if (head->retouch)
         (*head->retouch)(head);
-    }
 
-    /*** Dump the binary image file ***/
     path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
-
-    /* Grab permissions */
     safe_setuid_grab(player_ptr);
-
-    /* Kill the old file */
     (void)fd_kill(buf);
-
-    /* Attempt to create the raw file */
     fd = fd_make(buf, file_permission);
-
-    /* Drop permissions */
     safe_setuid_drop();
-
-    /* Dump to the file */
     if (fd >= 0) {
-        /* Dump it */
         fd_write(fd, (concptr)(head), head->head_size);
-
-        /* Dump the "*_info" array */
         fd_write(fd, head->info_ptr, head->info_size);
-
-        /* Dump the "*_name" array */
         fd_write(fd, head->name_ptr, head->name_size);
-
-        /* Dump the "*_text" array */
         fd_write(fd, head->text_ptr, head->text_size);
-
-        /* Dump the "*_tag" array */
         fd_write(fd, head->tag_ptr, head->tag_size);
-
-        /* Close */
         (void)fd_close(fd);
     }
 
-    /*** Kill the fake arrays ***/
-
-    /* Free the "*_info" array */
     C_KILL(head->info_ptr, head->info_size, char);
-
-    /* Hack -- Free the "fake" arrays */
     if (name)
         C_KILL(head->name_ptr, FAKE_NAME_SIZE, char);
+
     if (text)
         C_KILL(head->text_ptr, FAKE_TEXT_SIZE, char);
+
     if (tag)
         C_KILL(head->tag_ptr, FAKE_TAG_SIZE, char);
 
-    /*** Load the binary image file ***/
     path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
-
-    /* Attempt to open the "raw" file */
     fd = fd_open(buf, O_RDONLY);
-
-    /* Process existing "raw" file */
     if (fd < 0)
         quit(format(_("'%s_j.raw'ファイルをロードできません。", "Cannot load '%s.raw' file."), filename));
 
-    /* Attempt to parse the "raw" file */
     err = init_info_raw(fd, head);
     (void)fd_close(fd);
-
-    /* Error */
     if (err)
         quit(format(_("'%s_j.raw'ファイルを解析できません。", "Cannot parse '%s.raw' file."), filename));
 
@@ -583,15 +437,9 @@ static errr init_info(player_type *player_ptr, concptr filename, angband_header
  */
 static errr init_f_info(player_type *player_ptr)
 {
-    /* Init the header */
     init_header(&f_head, max_f_idx, sizeof(feature_type));
-
-    /* Save a pointer to the parsing function */
     f_head.parse_info_txt = parse_f_info;
-
-    /* Save a pointer to the retouch fake tags */
     f_head.retouch = retouch_f_info;
-
     return init_info(player_ptr, "f_info", &f_head, (void *)&f_info, &f_name, NULL, &f_tag);
 }
 
@@ -602,12 +450,8 @@ static errr init_f_info(player_type *player_ptr)
  */
 static errr init_k_info(player_type *player_ptr)
 {
-    /* Init the header */
     init_header(&k_head, max_k_idx, sizeof(object_kind));
-
-    /* Save a pointer to the parsing function */
     k_head.parse_info_txt = parse_k_info;
-
     return init_info(player_ptr, "k_info", &k_head, (void *)&k_info, &k_name, &k_text, NULL);
 }
 
@@ -618,12 +462,8 @@ static errr init_k_info(player_type *player_ptr)
  */
 static errr init_a_info(player_type *player_ptr)
 {
-    /* Init the header */
     init_header(&a_head, max_a_idx, sizeof(artifact_type));
-
-    /* Save a pointer to the parsing function */
     a_head.parse_info_txt = parse_a_info;
-
     return init_info(player_ptr, "a_info", &a_head, (void *)&a_info, &a_name, &a_text, NULL);
 }
 
@@ -634,12 +474,8 @@ static errr init_a_info(player_type *player_ptr)
  */
 static errr init_e_info(player_type *player_ptr)
 {
-    /* Init the header */
     init_header(&e_head, max_e_idx, sizeof(ego_item_type));
-
-    /* Save a pointer to the parsing function */
     e_head.parse_info_txt = parse_e_info;
-
     return init_info(player_ptr, "e_info", &e_head, (void *)&e_info, &e_name, &e_text, NULL);
 }
 
@@ -650,12 +486,8 @@ static errr init_e_info(player_type *player_ptr)
  */
 static errr init_r_info(player_type *player_ptr)
 {
-    /* Init the header */
     init_header(&r_head, max_r_idx, sizeof(monster_race));
-
-    /* Save a pointer to the parsing function */
     r_head.parse_info_txt = parse_r_info;
-
     return init_info(player_ptr, "r_info", &r_head, (void *)&r_info, &r_name, &r_text, NULL);
 }
 
@@ -666,12 +498,8 @@ static errr init_r_info(player_type *player_ptr)
  */
 static errr init_d_info(player_type *player_ptr)
 {
-    /* Init the header */
     init_header(&d_head, current_world_ptr->max_d_idx, sizeof(dungeon_type));
-
-    /* Save a pointer to the parsing function */
     d_head.parse_info_txt = parse_d_info;
-
     return init_info(player_ptr, "d_info", &d_head, (void *)&d_info, &d_name, &d_text, NULL);
 }
 
@@ -685,12 +513,8 @@ static errr init_d_info(player_type *player_ptr)
  */
 errr init_v_info(player_type *player_ptr)
 {
-    /* Init the header */
     init_header(&v_head, max_v_idx, sizeof(vault_type));
-
-    /* Save a pointer to the parsing function */
     v_head.parse_info_txt = parse_v_info;
-
     return init_info(player_ptr, "v_info", &v_head, (void *)&v_info, &v_name, &v_text, NULL);
 }
 
@@ -701,12 +525,8 @@ errr init_v_info(player_type *player_ptr)
  */
 static errr init_s_info(player_type *player_ptr)
 {
-    /* Init the header */
     init_header(&s_head, MAX_CLASS, sizeof(skill_table));
-
-    /* Save a pointer to the parsing function */
     s_head.parse_info_txt = parse_s_info;
-
     return init_info(player_ptr, "s_info", &s_head, (void *)&s_info, NULL, NULL, NULL);
 }
 
@@ -717,12 +537,8 @@ static errr init_s_info(player_type *player_ptr)
  */
 static errr init_m_info(player_type *player_ptr)
 {
-    /* Init the header */
     init_header(&m_head, MAX_CLASS, sizeof(player_magic));
-
-    /* Save a pointer to the parsing function */
     m_head.parse_info_txt = parse_m_info;
-
     return init_info(player_ptr, "m_info", &m_head, (void *)&m_info, NULL, NULL, NULL);
 }
 
@@ -741,25 +557,14 @@ static errr init_misc(player_type *player_ptr) { return parse_fixed_map(player_p
  */
 static errr init_towns(void)
 {
-    /* Allocate the towns */
     C_MAKE(town_info, max_towns, town_type);
-
     for (int i = 1; i < max_towns; i++) {
-        /*** Prepare the Stores ***/
-
-        /* Allocate the stores */
         C_MAKE(town_info[i].store, MAX_STORES, store_type);
-
-        /* Fill in each store */
         for (int j = 0; j < MAX_STORES; j++) {
-            /* Access the store */
             store_type *store_ptr = &town_info[i].store[j];
-
             if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME))
                 continue;
 
-            /* Assume full stock */
-
             /*
              * 我が家が 20 ページまで使える隠し機能のための準備。
              * オプションが有効でもそうでなくても一応スペースを作っておく。
@@ -772,41 +577,25 @@ static errr init_towns(void)
                 store_ptr->stock_size = STORE_INVEN_MAX;
             }
 
-            /* Allocate the stock */
             C_MAKE(store_ptr->stock, store_ptr->stock_size, object_type);
-
-            /* No table for the black market or home */
             if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM))
                 continue;
 
-            /* Assume full table */
             store_ptr->table_size = STORE_CHOICES;
-
-            /* Allocate the stock */
             C_MAKE(store_ptr->table, store_ptr->table_size, s16b);
-
-            /* Scan the choices */
             for (int k = 0; k < STORE_CHOICES; k++) {
                 KIND_OBJECT_IDX k_idx;
-
-                /* Extract the tval/sval codes */
                 int tv = store_table[j][k][0];
                 int sv = store_table[j][k][1];
-
-                /* Look for it */
                 for (k_idx = 1; k_idx < max_k_idx; k_idx++) {
                     object_kind *k_ptr = &k_info[k_idx];
-
-                    /* Found a match */
                     if ((k_ptr->tval == tv) && (k_ptr->sval == sv))
                         break;
                 }
 
-                /* Catch errors */
                 if (k_idx == max_k_idx)
                     continue;
 
-                /* Add that item index to the table */
                 store_ptr->table[store_ptr->table_num++] = k_idx;
             }
         }
@@ -836,17 +625,14 @@ errr init_buildings(void)
             building[i].action_restr[j] = 0;
         }
 
-        for (int j = 0; j < MAX_CLASS; j++) {
+        for (int j = 0; j < MAX_CLASS; j++)
             building[i].member_class[j] = 0;
-        }
 
-        for (int j = 0; j < MAX_RACES; j++) {
+        for (int j = 0; j < MAX_RACES; j++)
             building[i].member_race[j] = 0;
-        }
 
-        for (int j = 0; j < MAX_MAGIC + 1; j++) {
+        for (int j = 0; j < MAX_MAGIC + 1; j++)
             building[i].member_realm[j] = 0;
-        }
     }
 
     return 0;
@@ -859,13 +645,9 @@ errr init_buildings(void)
  */
 static errr init_quests(void)
 {
-    /* Allocate the quests */
     C_MAKE(quest, max_q_idx, quest_type);
-
-    /* Set all quest to "untaken" */
-    for (int i = 0; i < max_q_idx; i++) {
+    for (int i = 0; i < max_q_idx; i++)
         quest[i].status = QUEST_STATUS_UNTAKEN;
-    }
 
     return 0;
 }
@@ -879,81 +661,42 @@ static errr init_other(player_type *player_ptr)
 {
     player_ptr->current_floor_ptr = &floor_info; // TODO:本当はこんなところで初期化したくない
     floor_type *floor_ptr = player_ptr->current_floor_ptr;
-
-    /*** Prepare the "dungeon" information ***/
-
-    /* Allocate and Wipe the object list */
     C_MAKE(floor_ptr->o_list, current_world_ptr->max_o_idx, object_type);
-
-    /* Allocate and Wipe the monster list */
     C_MAKE(floor_ptr->m_list, current_world_ptr->max_m_idx, monster_type);
-
-    /* Allocate and Wipe the monster process list */
-    for (int i = 0; i < MAX_MTIMED; i++) {
+    for (int i = 0; i < MAX_MTIMED; i++)
         C_MAKE(floor_ptr->mproc_list[i], current_world_ptr->max_m_idx, s16b);
-    }
 
-    /* Allocate and Wipe the max dungeon level */
     C_MAKE(max_dlv, current_world_ptr->max_d_idx, DEPTH);
-
-    for (int i = 0; i < MAX_HGT; i++) {
+    for (int i = 0; i < MAX_HGT; i++)
         C_MAKE(floor_ptr->grid_array[i], MAX_WID, grid_type);
-    }
 
-    /*** Prepare the various "bizarre" arrays ***/
-
-    /* Macro variables */
     C_MAKE(macro__pat, MACRO_MAX, concptr);
     C_MAKE(macro__act, MACRO_MAX, concptr);
     C_MAKE(macro__cmd, MACRO_MAX, bool);
-
-    /* Macro action buffer */
     C_MAKE(macro__buf, 1024, char);
-
-    /* Quark variables */
     quark_init();
 
-    /* Message variables */
     C_MAKE(message__ptr, MESSAGE_MAX, u32b);
     C_MAKE(message__buf, MESSAGE_BUF, char);
-
-    /* Hack -- No messages yet */
     message__tail = MESSAGE_BUF;
 
-    /*** Prepare the options ***/
-
-    /* Scan the options */
     for (int i = 0; option_info[i].o_desc; i++) {
         int os = option_info[i].o_set;
         int ob = option_info[i].o_bit;
-
-        /* Set the "default" options */
         if (!option_info[i].o_var)
             continue;
 
-        /* Accept */
         option_mask[os] |= (1L << ob);
-
-        /* Set */
-        if (option_info[i].o_norm) {
-            /* Set */
+        if (option_info[i].o_norm)
             option_flag[os] |= (1L << ob);
-        } else {
+        else
             option_flag[os] &= ~(1L << ob);
-        }
     }
 
-    /* Analyze the windows */
-    for (int n = 0; n < 8; n++) {
-        /* Analyze the options */
-        for (int i = 0; i < 32; i++) {
-            /* Accept */
-            if (window_flag_desc[i]) {
-                /* Accept */
+    for (int n = 0; n < 8; n++)
+        for (int i = 0; i < 32; i++)
+            if (window_flag_desc[i])
                 window_mask[n] |= (1L << i);
-            }
-        }
-    }
 
     /*
      *  Set the "default" window flags
@@ -962,10 +705,6 @@ static errr init_other(player_type *player_ptr)
      */
     window_flag[1] = 1L << A_MAX;
     window_flag[2] = 1L << 0;
-
-    /*** Pre-allocate space for the "format()" buffer ***/
-
-    /* Hack -- Just call the "format()" function */
     (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
     return 0;
 }
@@ -983,81 +722,46 @@ static errr init_object_alloc(void)
     s16b num[MAX_DEPTH];
     (void)C_WIPE(&num, MAX_DEPTH, s16b);
 
-    /* Free the old "alloc_kind_table" (if it exists) */
-    if (alloc_kind_table) {
+    if (alloc_kind_table)
         C_KILL(alloc_kind_table, alloc_kind_size, alloc_entry);
-    }
 
-    /* Size of "alloc_kind_table" */
     alloc_kind_size = 0;
-
-    /* Scan the objects */
     for (int i = 1; i < max_k_idx; i++) {
         object_kind *k_ptr;
         k_ptr = &k_info[i];
-
-        /* Scan allocation pairs */
         for (int j = 0; j < 4; j++) {
-            /* Count the "legal" entries */
             if (k_ptr->chance[j]) {
-                /* Count the entries */
                 alloc_kind_size++;
-
-                /* Group by level */
                 num[k_ptr->locale[j]]++;
             }
         }
     }
 
-    /* Collect the level indexes */
-    for (int i = 1; i < MAX_DEPTH; i++) {
-        /* Group by level */
+    for (int i = 1; i < MAX_DEPTH; i++)
         num[i] += num[i - 1];
-    }
 
     if (!num[0])
         quit(_("町のアイテムがない!", "No town objects!"));
 
-    /*** Initialize object allocation info ***/
-
-    /* Allocate the alloc_kind_table */
     C_MAKE(alloc_kind_table, alloc_kind_size, alloc_entry);
-
-    /* Access the table entry */
     alloc_entry *table;
     table = alloc_kind_table;
-
-    /* Scan the objects */
     for (int i = 1; i < max_k_idx; i++) {
         object_kind *k_ptr;
         k_ptr = &k_info[i];
-
-        /* Scan allocation pairs */
         for (int j = 0; j < 4; j++) {
-            /* Count the "legal" entries */
             if (k_ptr->chance[j] == 0)
                 continue;
 
-            /* Extract the base level */
             int x = k_ptr->locale[j];
-
-            /* Extract the base probability */
             int p = (100 / k_ptr->chance[j]);
-
-            /* Skip entries preceding our locale */
             int y = (x > 0) ? num[x - 1] : 0;
-
-            /* Skip previous entries at this locale */
             int z = y + aux[x];
-
-            /* Load the entry */
             table[z].index = (KIND_OBJECT_IDX)i;
             table[z].level = (DEPTH)x;
             table[z].prob1 = (PROB)p;
             table[z].prob2 = (PROB)p;
             table[z].prob3 = (PROB)p;
-
-            /* Another entry complete for this locale */
             aux[x]++;
         }
     }
@@ -1074,42 +778,22 @@ static errr init_alloc(void)
 {
     monster_race *r_ptr;
     tag_type *elements;
-
-    /* Allocate the "r_info" array */
     C_MAKE(elements, max_r_idx, tag_type);
-
-    /* Scan the monsters */
     for (int i = 1; i < max_r_idx; i++) {
         elements[i].tag = r_info[i].level;
         elements[i].index = i;
     }
 
     tag_sort(elements, max_r_idx);
-
-    /*** Initialize monster allocation info ***/
-
-    /* Size of "alloc_race_table" */
     alloc_race_size = max_r_idx;
-
-    /* Allocate the alloc_race_table */
     C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
-
-    /* Scan the monsters */
     for (int i = 1; i < max_r_idx; i++) {
-        /* Get the i'th race */
         r_ptr = &r_info[elements[i].index];
-
-        /* Count valid pairs */
         if (r_ptr->rarity == 0)
             continue;
 
-        /* Extract the base level */
         int x = r_ptr->level;
-
-        /* Extract the base probability */
         int p = (100 / r_ptr->rarity);
-
-        /* Load the entry */
         alloc_race_table[i].index = (KIND_OBJECT_IDX)elements[i].index;
         alloc_race_table[i].level = (DEPTH)x;
         alloc_race_table[i].prob1 = (PROB)p;
@@ -1117,7 +801,6 @@ static errr init_alloc(void)
         alloc_race_table[i].prob3 = (PROB)p;
     }
 
-    /* Free the "r_info" array */
     C_KILL(elements, max_r_idx, tag_type);
     (void)init_object_alloc();
     return 0;
@@ -1149,32 +832,10 @@ static void init_note(concptr str)
 static void init_angband_aux(concptr why)
 {
     plog(why);
-
-#ifdef JP
-    /* Explain */
-    plog("'lib'ディレクトリが存在しないか壊れているようです。");
-
-    /* More details */
-    plog("ひょっとするとアーカイブが正しく解凍されていないのかもしれません。");
-
-    /* Explain */
-    plog("該当する'README'ファイルを読んで確認してみて下さい。");
-
-    /* Quit with error */
-    quit("致命的なエラー。");
-#else
-    /* Explain */
-    plog("The 'lib' directory is probably missing or broken.");
-
-    /* More details */
-    plog("Perhaps the archive was not extracted correctly.");
-
-    /* Explain */
-    plog("See the 'README' file for more information.");
-
-    /* Quit with error */
-    quit("Fatal Error.");
-#endif
+    plog(_("'lib'ディレクトリが存在しないか壊れているようです。", "The 'lib' directory is probably missing or broken."));
+    plog(_("ひょっとするとアーカイブが正しく解凍されていないのかもしれません。", "The 'lib' directory is probably missing or broken."));
+    plog(_("該当する'README'ファイルを読んで確認してみて下さい。", "See the 'README' file for more information."));
+    quit(_("致命的なエラー。", "Fatal Error."));
 }
 
 /*!
@@ -1198,128 +859,52 @@ static void put_title(void)
 
 /*!
  * @brief 全ゲームデータ読み込みのメインルーチン /
- * Hack -- main Angband initialization entry point
+ * @param player_ptr プレーヤーへの参照ポインタ
+ * @param process_autopick_file_command 自動拾いファイル読み込み関数への関数ポインタ
  * @return なし
- * @note
- * <pre>
- * This function is "messy" because various things
- * may or may not be initialized, but the "plog()" and "quit()"
- * functions are "supposed" to work under any conditions.
- * Verify some files, display the "news.txt" file, create
- * the high score file, initialize all internal arrays, and
- * load the basic "user pref files".
- * Be very careful to keep track of the order in which things
- * are initialized, in particular, the only thing *known* to
- * be available when this function is called is the "z-term.c"
- * package, and that may not be fully initialized until the
- * end of this function, when the default "user pref files"
- * are loaded and "term_xtra(TERM_XTRA_REACT,0)" is called.
- * Note that this function attempts to verify the "news" file,
- * and the game aborts (cleanly) on failure, since without the
- * "news" file, it is likely that the "lib" folder has not been
- * correctly located.  Otherwise, the news file is displayed for
- * the user.
- * Note that this function attempts to verify (or create) the
- * "high score" file, and the game aborts (cleanly) on failure,
- * since one of the most common "extraction" failures involves
- * failing to extract all sub-directories (even empty ones), such
- * as by failing to use the "-d" option of "pkunzip", or failing
- * to use the "save empty directories" option with "Compact Pro".
- * This error will often be caught by the "high score" creation
- * code below, since the "lib/apex" directory, being empty in the
- * standard distributions, is most likely to be "lost", making it
- * impossible to create the high score file.
- * Note that various things are initialized by this function,
- * including everything that was once done by "init_some_arrays".
- * This initialization involves the parsing of special files
- * in the "lib/data" and sometimes the "lib/edit" directories.
- * Note that the "template" files are initialized first, since they
- * often contain errors.  This means that macros and message recall
- * and things like that are not available until after they are done.
- * We load the default "user pref files" here in case any "color"
- * changes are needed before character creation.
- * Note that the "graf-xxx.prf" file must be loaded separately,
- * if needed, in the first (?) pass through "TERM_XTRA_REACT".
- * </pre>
  */
-void init_angband(player_type *player_ptr, void (*process_autopick_file_command)(char *))
+void init_angband(player_type *player_ptr, process_autopick_file_command_pf process_autopick_file_command)
 {
-    /*** Verify the "news" file ***/
     char buf[1024];
     path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
-
-    /* Attempt to open the file */
     int fd = fd_open(buf, O_RDONLY);
-
-    /* Failure */
     if (fd < 0) {
         char why[1024];
-
         sprintf(why, _("'%s'ファイルにアクセスできません!", "Cannot access the '%s' file!"), buf);
-
-        /* Crash and burn */
         init_angband_aux(why);
     }
 
     (void)fd_close(fd);
-
-    /*** Display the "news" file ***/
     term_clear();
     path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
-
-    /* Open the News file */
     FILE *fp;
     fp = angband_fopen(buf, "r");
-
-    /* Dump */
     if (fp) {
-        /* Dump the file to the screen */
         int i = 0;
-        while (0 == angband_fgets(fp, buf, sizeof(buf))) {
-            /* Display and advance */
+        while (0 == angband_fgets(fp, buf, sizeof(buf)))
             term_putstr(0, i++, -1, TERM_WHITE, buf);
-        }
 
         angband_fclose(fp);
     }
 
     term_flush();
-
-    /*** Verify (or create) the "high score" file ***/
     path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
-
-    /* Attempt to open the high score file */
     fd = fd_open(buf, O_RDONLY);
-
     BIT_FLAGS file_permission = 0664;
     if (fd < 0) {
-        /* Grab permissions */
         safe_setuid_grab(player_ptr);
-
-        /* Create a new high score file */
         fd = fd_make(buf, file_permission);
-
-        /* Drop permissions */
         safe_setuid_drop();
-
-        /* Failure */
         if (fd < 0) {
             char why[1024];
-
             sprintf(why, _("'%s'ファイルを作成できません!", "Cannot create the '%s' file!"), buf);
-
-            /* Crash and burn */
             init_angband_aux(why);
         }
     }
 
     (void)fd_close(fd);
-
     put_title();
 
-    /*** Initialize some arrays ***/
-
-    /* Initialize misc. values */
     init_note(_("[変数を初期化しています...(その他)", "[Initializing values... (misc)]"));
     if (init_misc(player_ptr))
         quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
@@ -1327,101 +912,74 @@ void init_angband(player_type *player_ptr, void (*process_autopick_file_command)
     init_note(_("[データの初期化中... (地形)]", "[Initializing arrays... (features)]"));
     if (init_f_info(player_ptr))
         quit(_("地形初期化不能", "Cannot initialize features"));
+
     if (init_feat_variables())
         quit(_("地形初期化不能", "Cannot initialize features"));
 
-    /* Initialize object info */
     init_note(_("[データの初期化中... (アイテム)]", "[Initializing arrays... (objects)]"));
     if (init_k_info(player_ptr))
         quit(_("アイテム初期化不能", "Cannot initialize objects"));
 
-    /* Initialize artifact info */
     init_note(_("[データの初期化中... (伝説のアイテム)]", "[Initializing arrays... (artifacts)]"));
     if (init_a_info(player_ptr))
         quit(_("伝説のアイテム初期化不能", "Cannot initialize artifacts"));
 
-    /* Initialize ego-item info */
     init_note(_("[データの初期化中... (名のあるアイテム)]", "[Initializing arrays... (ego-items)]"));
     if (init_e_info(player_ptr))
         quit(_("名のあるアイテム初期化不能", "Cannot initialize ego-items"));
 
-    /* Initialize monster info */
     init_note(_("[データの初期化中... (モンスター)]", "[Initializing arrays... (monsters)]"));
     if (init_r_info(player_ptr))
         quit(_("モンスター初期化不能", "Cannot initialize monsters"));
 
-    /* Initialize dungeon info */
     init_note(_("[データの初期化中... (ダンジョン)]", "[Initializing arrays... (dungeon)]"));
     if (init_d_info(player_ptr))
         quit(_("ダンジョン初期化不能", "Cannot initialize dungeon"));
-    {
-        for (int i = 1; i < current_world_ptr->max_d_idx; i++)
-            if (d_info[i].final_guardian)
-                r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
-    }
 
-    /* Initialize magic info */
+    for (int i = 1; i < current_world_ptr->max_d_idx; i++)
+        if (d_info[i].final_guardian)
+            r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
+
     init_note(_("[データの初期化中... (魔法)]", "[Initializing arrays... (magic)]"));
     if (init_m_info(player_ptr))
         quit(_("魔法初期化不能", "Cannot initialize magic"));
 
-    /* Initialize weapon_exp info */
     init_note(_("[データの初期化中... (熟練度)]", "[Initializing arrays... (skill)]"));
     if (init_s_info(player_ptr))
         quit(_("熟練度初期化不能", "Cannot initialize skill"));
 
-    /* Initialize wilderness array */
     init_note(_("[配列を初期化しています... (荒野)]", "[Initializing arrays... (wilderness)]"));
-
     if (init_wilderness())
         quit(_("荒野を初期化できません", "Cannot initialize wilderness"));
 
-    /* Initialize town array */
     init_note(_("[配列を初期化しています... (街)]", "[Initializing arrays... (towns)]"));
     if (init_towns())
         quit(_("街を初期化できません", "Cannot initialize towns"));
 
-    /* Initialize building array */
     init_note(_("[配列を初期化しています... (建物)]", "[Initializing arrays... (buildings)]"));
     if (init_buildings())
         quit(_("建物を初期化できません", "Cannot initialize buildings"));
 
-    /* Initialize quest array */
     init_note(_("[配列を初期化しています... (クエスト)]", "[Initializing arrays... (quests)]"));
     if (init_quests())
         quit(_("クエストを初期化できません", "Cannot initialize quests"));
 
-    /* Initialize vault info */
     if (init_v_info(player_ptr))
         quit(_("vault 初期化不能", "Cannot initialize vaults"));
 
-    /* Initialize some other arrays */
     init_note(_("[データの初期化中... (その他)]", "[Initializing arrays... (other)]"));
     if (init_other(player_ptr))
         quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
 
-    /* Initialize some other arrays */
     init_note(_("[データの初期化中... (アロケーション)]", "[Initializing arrays... (alloc)]"));
     if (init_alloc())
         quit(_("アロケーション・スタッフ初期化不能", "Cannot initialize alloc stuff"));
 
-    /*** Load default user pref files ***/
-
-    /* Initialize feature info */
     init_note(_("[ユーザー設定ファイルを初期化しています...]", "[Initializing user pref files...]"));
-
-    /* Access the "basic" pref file */
     strcpy(buf, "pref.prf");
-
-    /* Process that file */
     process_pref_file(player_ptr, buf, process_autopick_file_command);
-
-    /* Access the "basic" system pref file */
     sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
-
-    /* Process that file */
     process_pref_file(player_ptr, buf, process_autopick_file_command);
-
     init_note(_("[初期化終了]", "[Initialization complete]"));
 }
 
index 82c6426..2f07c6c 100644 (file)
@@ -16,7 +16,8 @@
 #include "system/angband.h"
 #include "info-reader/info-reader-util.h"
 
-void init_angband(player_type *player_ptr, void(*process_autopick_file_command)(char*));
+typedef void (*process_autopick_file_command_pf)(char *);
+void init_angband(player_type *player_ptr, process_autopick_file_command_pf process_autopick_file_command);
 concptr get_check_sum(void);
 void init_file_paths(char *path);
 errr init_v_info(player_type *player_ptr);