OSDN Git Service

Extend features of tiling. (separation of Cell size and Tile size / add offset position.)
[hengband/hengband.git] / src / init2.c
index ffa16b2..3e34b1f 100644 (file)
@@ -1,75 +1,82 @@
-/* File: init2.c */
-
-/* Purpose: Initialization (part 2) -BEN- */
-
-#include "angband.h"
-
-#include "init.h"
-
-#ifndef MACINTOSH
-#ifdef CHECK_MODIFICATION_TIME
-#include <sys/types.h>
-#include <sys/stat.h>
-#endif /* CHECK_MODIFICATION_TIME */
-#endif
-
-/*
+/*!
+ * @file init2.c
+ * @brief ¥²¡¼¥à¥Ç¡¼¥¿½é´ü²½2 / Initialization (part 2) -BEN-
+ * @date 2014/01/28
+ * @author
+ * <pre>
+ * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
+ * This software may be copied and distributed for educational, research,
+ * and not for profit purposes provided that this copyright and statement
+ * are included in all such copies.  Other copyrights may also apply.
+ * 2014 Deskull rearranged comment for Doxygen.\n
+ * </pre>
+ * @details
+ * <pre>
  * This file is used to initialize various variables and arrays for the
  * Angband game.  Note the use of "fd_read()" and "fd_write()" to bypass
  * the common limitation of "read()" and "write()" to only 32767 bytes
  * at a time.
- *
  * Several of the arrays for Angband are built from "template" files in
  * the "lib/file" directory, from which quick-load binary "image" files
  * are constructed whenever they are not present in the "lib/data"
  * directory, or if those files become obsolete, if we are allowed.
- *
  * Warning -- the "ascii" file parsers use a minor hack to collect the
  * name and text information in a single pass.  Thus, the game will not
  * be able to load any template file with more than 20K of names or 60K
  * of text, even though technically, up to 64K should be legal.
- *
  * The "init1.c" file is used only to parse the ascii template files,
  * to create the binary image files.  If you include the binary image
  * files instead of the ascii template files, then you can undefine
  * "ALLOW_TEMPLATES", saving about 20K by removing "init1.c".  Note
  * that the binary image files are extremely system dependant.
+ * </pre>
  */
 
+#include "angband.h"
+
+#include "init.h"
 
+#ifndef MACINTOSH
+#ifdef CHECK_MODIFICATION_TIME
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif /* CHECK_MODIFICATION_TIME */
+#endif
 
-/*
+
+
+
+/*!
+ * @brief ³Æ¥Ç¡¼¥¿¥Õ¥¡¥¤¥ë¤òÆɤ߼è¤ë¤¿¤á¤Î¥Ñ¥¹¤ò¼èÆÀ¤¹¤ë
  * Find the default paths to all of our important sub-directories.
- *
+ * @param path ¥Ñ¥¹ÊÝ´ÉÀè¤Îʸ»úÎó
+ * @return ¤Ê¤·
+ * @details
+ * <pre>
  * The purpose of each sub-directory is described in "variable.c".
- *
  * All of the sub-directories should, by default, be located inside
  * the main "lib" directory, whose location is very system dependant.
- *
  * This function takes a writable buffer, initially containing the
  * "path" to the "lib" directory, for example, "/pkg/lib/angband/",
  * or a system dependant string, for example, ":lib:".  The buffer
  * must be large enough to contain at least 32 more characters.
- *
  * Various command line options may allow some of the important
  * directories to be changed to user-specified directories, most
  * importantly, the "info" and "user" and "save" directories,
  * but this is done after this function, see "main.c".
- *
  * In general, the initial path should end in the appropriate "PATH_SEP"
  * string.  All of the "sub-directory" paths (created below or supplied
  * by the user) will NOT end in the "PATH_SEP" string, see the special
  * "path_build()" function in "util.c" for more information.
- *
  * Mega-Hack -- support fat raw files under NEXTSTEP, using special
  * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
  * requiring the directories to be created by hand by the user.
- *
  * Hack -- first we free all the strings, since this is known
  * to succeed even if the strings have not been allocated yet,
  * as long as the variables start out as "NULL".  This allows
  * this function to be called multiple times, for example, to
  * try several base "path" values until a good one is found.
+ * </pre>
  */
 void init_file_paths(char *path)
 {
@@ -173,7 +180,7 @@ void init_file_paths(char *path)
 #ifdef PRIVATE_USER_PATH
 
        /* Build the path to the user specific directory */
-       path_build(buf, 1024, PRIVATE_USER_PATH, VERSION_NAME);
+       path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
 
        /* Build a relative path name */
        ANGBAND_DIR_USER = string_make(buf);
@@ -240,26 +247,27 @@ void init_file_paths(char *path)
 /*
  * Hack -- help give useful error messages
  */
-int error_idx;
-int error_line;
+int error_idx; /*!< ¥Ç¡¼¥¿Æɤ߹þ¤ß/½é´ü²½»þ¤ËÈÆÍÑŪ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÊݸ¤¹¤ë¥°¥í¡¼¥Ð¥ëÊÑ¿ô */
+int error_line; /*!< ¥Ç¡¼¥¿Æɤ߹þ¤ß/½é´ü²½»þ¤ËÈÆÍÑŪ¤Ë¥¨¥é¡¼¹Ô¿ô¤òÊݸ¤¹¤ë¥°¥í¡¼¥Ð¥ëÊÑ¿ô */
 
 
-/*
- * Standard error message text
+/*!
+ * ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤Î̾¾ÎÄêµÁ / Standard error message text
  */
 cptr err_str[PARSE_ERROR_MAX] =
 {
        NULL,
 #ifdef JP
-        "ʸˡ¥¨¥é¡¼",
-        "¸Å¤¤¥Õ¥¡¥¤¥ë",
-        "µ­Ï¿¥Ø¥Ã¥À¤¬¤Ê¤¤",
-        "ÉÔϢ³¥ì¥³¡¼¥É",
-        "¤ª¤«¤·¤Ê¥Õ¥é¥°Â¸ºß",
-        "̤ÄêµÁÌ¿Îá",
-        "¥á¥â¥êÉÔ­",
-        "ºÂɸÈϰϳ°",
-        "°ú¿ôÉÔ­",
+       "ʸˡ¥¨¥é¡¼",
+       "¸Å¤¤¥Õ¥¡¥¤¥ë",
+       "µ­Ï¿¥Ø¥Ã¥À¤¬¤Ê¤¤",
+       "ÉÔϢ³¥ì¥³¡¼¥É",
+       "¤ª¤«¤·¤Ê¥Õ¥é¥°Â¸ºß",
+       "̤ÄêµÁÌ¿Îá",
+       "¥á¥â¥êÉÔ­",
+       "ºÂɸÈϰϳ°",
+       "°ú¿ôÉÔ­",
+       "̤ÄêµÁÃÏ·Á¥¿¥°",
 #else
        "parse error",
        "obsolete file",
@@ -270,6 +278,7 @@ cptr err_str[PARSE_ERROR_MAX] =
        "out of memory",
        "coordinates out of bounds",
        "too few arguments",
+       "undefined terrain tag",
 #endif
 
 };
@@ -281,18 +290,25 @@ cptr err_str[PARSE_ERROR_MAX] =
 /*
  * File headers
  */
-header v_head;
-header f_head;
-header k_head;
-header a_head;
-header e_head;
-header r_head;
-header d_head;
-header s_head;
-header m_head;
+header v_head; /*!< Vault¾ðÊó¤Î¥Ø¥Ã¥À¹½Â¤ÂΠ*/
+header f_head; /*!< ÃÏ·Á¾ðÊó¤Î¥Ø¥Ã¥À¹½Â¤ÂΠ*/
+header k_head; /*!< ¥Ú¡¼¥¹¥¢¥¤¥Æ¥à¾ðÊó¤Î¥Ø¥Ã¥À¹½Â¤ÂΠ*/
+header a_head; /*!< ¸ÇÄꥢ¡¼¥Æ¥£¥Õ¥¡¥¯¥È¾ðÊó¤Î¥Ø¥Ã¥À¹½Â¤ÂΠ*/
+header e_head; /*!< ¥¢¥¤¥Æ¥à¥¨¥´¾ðÊó¤Î¥Ø¥Ã¥À¹½Â¤ÂΠ*/
+header r_head; /*!< ¥â¥ó¥¹¥¿¡¼¼ï²¾ðÊó¤Î¥Ø¥Ã¥À¹½Â¤ÂΠ*/
+header d_head; /*!< ¥À¥ó¥¸¥ç¥ó¾ðÊó¤Î¥Ø¥Ã¥À¹½Â¤ÂΠ*/
+header s_head; /*!< ¥×¥ì¥¤¥ä¡¼¿¦¶Èµ»Ç½¾ðÊó¤Î¥Ø¥Ã¥À¹½Â¤ÂΠ*/
+header m_head; /*!< ¥×¥ì¥¤¥ä¡¼¿¦¶ÈËâË¡¾ðÊó¤Î¥Ø¥Ã¥À¹½Â¤ÂΠ*/
 
 #ifdef CHECK_MODIFICATION_TIME
 
+/*!
+ * @brief ¥Æ¥­¥¹¥È¥Õ¥¡¥¤¥ë¤Èraw¥Õ¥¡¥¤¥ë¤Î¹¹¿·»þ¹ï¤òÈæ³Ó¤¹¤ë
+ * Find the default paths to all of our important sub-directories.
+ * @param fd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
+ * @param template_file ¥Õ¥¡¥¤¥ë̾
+ * @return ¥Æ¥­¥¹¥È¤ÎÊý¤¬¿·¤·¤¤¤«¡¢raw¥Õ¥¡¥¤¥ë¤¬¤Ê¤¯¹¹¿·¤ÎɬÍפ¬¤¢¤ë¾ì¹ç-1¡¢¹¹¿·¤ÎɬÍפ¬¤Ê¤¤¾ì¹ç0¡£
+ */
 static errr check_modification_date(int fd, cptr template_file)
 {
        char buf[1024];
@@ -300,7 +316,7 @@ static errr check_modification_date(int fd, cptr template_file)
        struct stat txt_stat, raw_stat;
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_EDIT, template_file);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
 
        /* Access stats on text file */
        if (stat(buf, &txt_stat))
@@ -332,8 +348,12 @@ static errr check_modification_date(int fd, cptr template_file)
 /*** Initialize from binary image files ***/
 
 
-/*
+/*!
+ * @brief raw¥Õ¥¡¥¤¥ë¤«¤é¤Î¥Ç¡¼¥¿¤ÎÆɤ߼è¤ê½èÍý
  * Initialize the "*_info" array, by parsing a binary "image" file
+ * @param fd ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
+ * @param head raw¥Õ¥¡¥¤¥ë¤Î¥Ø¥Ã¥À
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_info_raw(int fd, header *head)
 {
@@ -344,7 +364,6 @@ static errr init_info_raw(int fd, header *head)
            (test.v_major != head->v_major) ||
            (test.v_minor != head->v_minor) ||
            (test.v_patch != head->v_patch) ||
-           (test.v_extra != head->v_extra) ||
            (test.info_num != head->info_num) ||
            (test.info_len != head->info_len) ||
            (test.head_size != head->head_size) ||
@@ -385,14 +404,30 @@ static errr init_info_raw(int fd, header *head)
                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);
+       }
+
+
        /* Success */
        return (0);
 }
 
 
 
-/*
+/*!
+ * @brief ¥Ø¥Ã¥À¹½Â¤ÂΤι¹¿·
  * Initialize the header of an *_info.raw file.
+ * @param head raw¥Õ¥¡¥¤¥ë¤Î¥Ø¥Ã¥À
+ * @param num ¥Ç¡¼¥¿¿ô
+ * @param len ¥Ç¡¼¥¿¤ÎŤµ
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static void init_header(header *head, int num, int len)
 {
@@ -412,14 +447,22 @@ static void init_header(header *head, int num, int len)
 }
 
 
-/*
+/*!
+ * @brief ¥Ø¥Ã¥À¹½Â¤ÂΤι¹¿·
  * Initialize the "*_info" array
- *
+ * @param filename ¥Õ¥¡¥¤¥ë̾(³ÈÄ¥»Òtxt/raw)
+ * @param head ½èÍý¤ËÍѤ¤¤ë¥Ø¥Ã¥À¹½Â¤ÂÎ
+ * @param info ¥Ç¡¼¥¿ÊÝ´ÉÀè¤Î¹½Â¤ÂΥݥ¤¥ó¥¿
+ * @param name Ì¾¾ÎÍѲÄÊÑʸ»úÎó¤ÎÊÝ´ÉÀè
+ * @param text ¥Æ¥­¥¹¥ÈÍѲÄÊÑʸ»úÎó¤ÎÊÝ´ÉÀè
+ * @param tag ¥¿¥°ÍѲÄÊÑʸ»úÎó¤ÎÊÝ´ÉÀè
+ * @return ¥¨¥é¡¼¥³¡¼¥É
+ * @note
  * Note that we let each entry have a unique "name" and "text" string,
  * even if the string happens to be empty (everyone has a unique '\0').
  */
 static errr init_info(cptr filename, header *head,
-                       void **info, char **name, char **text)
+                     void **info, char **name, char **text, char **tag)
 {
        int fd;
 
@@ -439,9 +482,9 @@ static errr init_info(cptr filename, header *head,
 
        /* Build the filename */
 #ifdef JP
-       path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s_j.raw", filename));
+       path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
 #else
-       path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s.raw", filename));
+       path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
 #endif
 
 
@@ -453,7 +496,7 @@ static errr init_info(cptr filename, header *head,
        {
 #ifdef CHECK_MODIFICATION_TIME
 
-                err = check_modification_date(fd, format("%s_j.txt", filename));
+               err = check_modification_date(fd, format("%s.txt", filename));
 
 #endif /* CHECK_MODIFICATION_TIME */
 
@@ -477,23 +520,25 @@ static errr init_info(cptr filename, header *head,
                /* 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;
                if (name) (*name) = head->name_ptr;
                if (text) (*text) = head->text_ptr;
+               if (tag)  (*tag)  = head->tag_ptr;
 
                /*** Load the ascii template file ***/
 
                /* Build the filename */
 
-               path_build(buf, 1024, ANGBAND_DIR_EDIT, format("%s_j.txt", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
 
                /* Open the file */
                fp = my_fopen(buf, "r");
 
                /* Parse it */
 #ifdef JP
-               if (!fp) quit(format("'%s_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£", filename));
+               if (!fp) quit(format("'%s.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£", filename));
 #else
                if (!fp) quit(format("Cannot open '%s.txt' file.", filename));
 #endif
@@ -512,16 +557,16 @@ static errr init_info(cptr filename, header *head,
 
 #ifdef JP
                        /* Error string */
-                       oops = ((err > 0) ? err_str[err] : "̤ÃΤÎ");
+                       oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "̤ÃΤÎ");
 
                        /* Oops */
-                       msg_format("'%s_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", filename, error_line);
+                       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_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼", filename));
+                       quit(format("'%s.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼", filename));
 #else
                        /* Error string */
                        oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
@@ -539,6 +584,14 @@ static errr init_info(cptr filename, header *head,
                }
 
 
+               /*** Make final retouch on fake tags ***/
+
+               if (head->retouch)
+               {
+                       (*head->retouch)(head);
+               }
+
+
                /*** Dump the binary image file ***/
 
                /* File type is "DATA" */
@@ -546,25 +599,31 @@ static errr init_info(cptr filename, header *head,
 
                /* Build the filename */
 #ifdef JP
-               path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s_j.raw", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
 #else
-               path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s.raw", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
 #endif
 
 
+               /* Grab permissions */
+               safe_setuid_grab();
+
                /* Kill the old file */
                (void)fd_kill(buf);
 
                /* Attempt to create the raw file */
                fd = fd_make(buf, mode);
 
+               /* Drop permissions */
+               safe_setuid_drop();
+
                /* Dump to the file */
                if (fd >= 0)
                {
                        /* Dump it */
                        fd_write(fd, (cptr)(head), head->head_size);
 
-               /* Dump the "*_info" array */
+                       /* Dump the "*_info" array */
                        fd_write(fd, head->info_ptr, head->info_size);
 
                        /* Dump the "*_name" array */
@@ -573,6 +632,9 @@ static errr init_info(cptr filename, header *head,
                        /* 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);
                }
@@ -586,6 +648,7 @@ static errr init_info(cptr filename, header *head,
                /* 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);
 
 #endif /* ALLOW_TEMPLATES */
 
@@ -594,9 +657,9 @@ static errr init_info(cptr filename, header *head,
 
                /* Build the filename */
 #ifdef JP
-               path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s_j.raw", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
 #else
-               path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s.raw", filename));
+               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
 #endif
 
 
@@ -631,14 +694,17 @@ static errr init_info(cptr filename, header *head,
        if (info) (*info) = head->info_ptr;
        if (name) (*name) = head->name_ptr;
        if (text) (*text) = head->text_ptr;
+       if (tag)  (*tag)  = head->tag_ptr;
 
        /* Success */
        return (0);
 }
 
 
-/*
+/*!
+ * @brief ÃÏ·Á¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize the "f_info" array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_f_info(void)
 {
@@ -650,15 +716,20 @@ static errr init_f_info(void)
        /* 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;
+
 #endif /* ALLOW_TEMPLATES */
 
        return init_info("f_info", &f_head,
-                        (void*)&f_info, (void*)&f_name, (void*)&f_text);
+                        (void*)&f_info, &f_name, NULL, &f_tag);
 }
 
 
-/*
+/*!
+ * @brief ¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize the "k_info" array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_k_info(void)
 {
@@ -673,13 +744,15 @@ static errr init_k_info(void)
 #endif /* ALLOW_TEMPLATES */
 
        return init_info("k_info", &k_head,
-                        (void*)&k_info, (void*)&k_name, (void*)&k_text);
+                        (void*)&k_info, &k_name, &k_text, NULL);
 }
 
 
 
-/*
+/*!
+ * @brief ¸ÇÄꥢ¡¼¥Æ¥£¥Õ¥¡¥¯¥È¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize the "a_info" array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_a_info(void)
 {
@@ -694,13 +767,15 @@ static errr init_a_info(void)
 #endif /* ALLOW_TEMPLATES */
 
        return init_info("a_info", &a_head,
-                        (void*)&a_info, (void*)&a_name, (void*)&a_text);
+                        (void*)&a_info, &a_name, &a_text, NULL);
 }
 
 
 
-/*
+/*!
+ * @brief ¸ÇÄꥢ¡¼¥Æ¥£¥Õ¥¡¥¯¥È¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize the "e_info" array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_e_info(void)
 {
@@ -715,13 +790,15 @@ static errr init_e_info(void)
 #endif /* ALLOW_TEMPLATES */
 
        return init_info("e_info", &e_head,
-                        (void*)&e_info, (void*)&e_name, (void*)&e_text);
+                        (void*)&e_info, &e_name, &e_text, NULL);
 }
 
 
 
-/*
+/*!
+ * @brief ¥â¥ó¥¹¥¿¡¼¼ï²¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize the "r_info" array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_r_info(void)
 {
@@ -736,13 +813,15 @@ static errr init_r_info(void)
 #endif /* ALLOW_TEMPLATES */
 
        return init_info("r_info", &r_head,
-                        (void*)&r_info, (void*)&r_name, (void*)&r_text);
+                        (void*)&r_info, &r_name, &r_text, NULL);
 }
 
 
 
-/*
+/*!
+ * @brief ¥À¥ó¥¸¥ç¥ó¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize the "d_info" array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_d_info(void)
 {
@@ -757,13 +836,15 @@ static errr init_d_info(void)
 #endif /* ALLOW_TEMPLATES */
 
        return init_info("d_info", &d_head,
-                        (void*)&d_info, (void*)&d_name, (void*)&d_text);
+                        (void*)&d_info, &d_name, &d_text, NULL);
 }
 
 
-/*
+/*!
+ * @brief Vault¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize the "v_info" array
- *
+ * @return ¥¨¥é¡¼¥³¡¼¥É
+ * @note
  * Note that we let each entry have a unique "name" and "text" string,
  * even if the string happens to be empty (everyone has a unique '\0').
  */
@@ -780,12 +861,14 @@ errr init_v_info(void)
 #endif /* ALLOW_TEMPLATES */
 
        return init_info("v_info", &v_head,
-                        (void*)&v_info, (void*)&v_name, (void*)&v_text);
+                        (void*)&v_info, &v_name, &v_text, NULL);
 }
 
 
-/*
+/*!
+ * @brief ¿¦¶Èµ»Ç½¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize the "s_info" array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_s_info(void)
 {
@@ -800,12 +883,14 @@ static errr init_s_info(void)
 #endif /* ALLOW_TEMPLATES */
 
        return init_info("s_info", &s_head,
-                        (void*)&s_info, (void*)&s_name, (void*)&s_text);
+                        (void*)&s_info, NULL, NULL, NULL);
 }
 
 
-/*
+/*!
+ * @brief ¿¦¶ÈËâË¡¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize the "m_info" array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_m_info(void)
 {
@@ -820,15 +905,15 @@ static errr init_m_info(void)
 #endif /* ALLOW_TEMPLATES */
 
        return init_info("m_info", &m_head,
-                        (void*)&m_info, (void*)&m_name, (void*)&m_text);
+                        (void*)&m_info, NULL, NULL, NULL);
 }
 
 
 
 /*** Initialize others ***/
 
-/*
- * Hack -- Objects sold in the stores -- by tval/sval pair.
+/*!
+ * Å¹ÊÞ¤ÇÈÎÇ䤹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤òÄêµÁ¤¹¤ë / Hack -- Objects sold in the stores -- by tval/sval pair.
  */
 static byte store_table[MAX_STORES][STORE_CHOICES][2] =
 {
@@ -880,16 +965,14 @@ static byte store_table[MAX_STORES][STORE_CHOICES][2] =
                { TV_FOOD, SV_FOOD_RATION },
                { TV_FOOD, SV_FOOD_RATION },
 
-               { TV_LITE, SV_LITE_TORCH },
-               { TV_LITE, SV_LITE_TORCH },
+               { TV_POTION, SV_POTION_WATER },
+               { TV_POTION, SV_POTION_WATER },
                { TV_LITE, SV_LITE_LANTERN },
                { TV_LITE, SV_LITE_LANTERN },
 
-               { TV_FLASK, 0 },
-               { TV_FLASK, 0 },
-
+               { TV_FOOD, SV_FOOD_WAYBREAD },
+               { TV_FOOD, SV_FOOD_WAYBREAD },
                { TV_CAPTURE, 0 },
-
                { TV_FIGURINE, 0 },
 
                { TV_SHOT, SV_AMMO_NORMAL },
@@ -995,30 +1078,30 @@ static byte store_table[MAX_STORES][STORE_CHOICES][2] =
                { TV_BOW, SV_SLING },
                { TV_BOW, SV_SHORT_BOW },
 
-               { TV_BOW, SV_LONG_BOW },
                { TV_BOW, SV_LIGHT_XBOW },
                { TV_SHOT, SV_AMMO_NORMAL },
                { TV_SHOT, SV_AMMO_NORMAL },
-
                { TV_ARROW, SV_AMMO_NORMAL },
+
                { TV_ARROW, SV_AMMO_NORMAL },
                { TV_BOLT, SV_AMMO_NORMAL },
                { TV_BOLT, SV_AMMO_NORMAL },
-
-               { TV_BOW, SV_LONG_BOW },
                { TV_BOW, SV_LIGHT_XBOW },
+
                { TV_ARROW, SV_AMMO_NORMAL },
                { TV_BOLT, SV_AMMO_NORMAL },
-
                { TV_BOW, SV_SHORT_BOW },
+               { TV_BOW, SV_LIGHT_XBOW },
+
                { TV_SWORD, SV_DAGGER },
                { TV_SWORD, SV_TANTO },
                { TV_SWORD, SV_RAPIER },
-
                { TV_SWORD, SV_SMALL_SWORD },
+
                { TV_SWORD, SV_SHORT_SWORD },
                { TV_SWORD, SV_LONG_SWORD },
                { TV_SWORD, SV_SCIMITAR },
+               { TV_SWORD, SV_BROAD_SWORD },
 
                { TV_HISSATSU_BOOK, 0 },
                { TV_HISSATSU_BOOK, 0 },
@@ -1061,14 +1144,14 @@ static byte store_table[MAX_STORES][STORE_CHOICES][2] =
 
                { TV_LIFE_BOOK, 0 },
                { TV_LIFE_BOOK, 0 },
-               { TV_LIFE_BOOK, 0 },
-               { TV_LIFE_BOOK, 0 },
-
-               { TV_LIFE_BOOK, 1 },
-               { TV_LIFE_BOOK, 1 },
                { TV_LIFE_BOOK, 1 },
                { TV_LIFE_BOOK, 1 },
 
+               { TV_CRUSADE_BOOK, 0 },
+               { TV_CRUSADE_BOOK, 0 },
+               { TV_CRUSADE_BOOK, 1 },
+               { TV_CRUSADE_BOOK, 1 },
+
                { TV_HAFTED, SV_WHIP },
                { TV_HAFTED, SV_MACE },
                { TV_HAFTED, SV_BALL_AND_CHAIN },
@@ -1116,7 +1199,7 @@ static byte store_table[MAX_STORES][STORE_CHOICES][2] =
 
                { TV_SCROLL, SV_SCROLL_DETECT_INVIS },
                { TV_SCROLL, SV_SCROLL_RECHARGING },
-               { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER },
+               { TV_SCROLL, SV_SCROLL_TELEPORT },
                { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
 
                { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
@@ -1150,9 +1233,9 @@ static byte store_table[MAX_STORES][STORE_CHOICES][2] =
                { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
 
                { TV_SCROLL, SV_SCROLL_RECHARGING },
-               { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER },
-               { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER },
-               { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER }
+               { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
+               { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT },
+               { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM },
 
        },
 
@@ -1160,7 +1243,7 @@ static byte store_table[MAX_STORES][STORE_CHOICES][2] =
                /* Magic-User store */
 
                { TV_RING, SV_RING_PROTECTION },
-               { TV_RING, SV_RING_FEATHER_FALL },
+               { TV_RING, SV_RING_LEVITATION_FALL },
                { TV_RING, SV_RING_PROTECTION },
                { TV_RING, SV_RING_RESIST_FIRE },
 
@@ -1326,10 +1409,10 @@ static byte store_table[MAX_STORES][STORE_CHOICES][2] =
                { TV_ARCANE_BOOK, 2 },
                { TV_ARCANE_BOOK, 3 },
 
-               { TV_ENCHANT_BOOK, 0 },
-               { TV_ENCHANT_BOOK, 0 },
-               { TV_ENCHANT_BOOK, 1 },
-               { TV_ENCHANT_BOOK, 1 },
+               { TV_CRAFT_BOOK, 0 },
+               { TV_CRAFT_BOOK, 0 },
+               { TV_CRAFT_BOOK, 1 },
+               { TV_CRAFT_BOOK, 1 },
 
                { TV_DAEMON_BOOK, 0 },
                { TV_DAEMON_BOOK, 0 },
@@ -1340,6 +1423,11 @@ static byte store_table[MAX_STORES][STORE_CHOICES][2] =
                { TV_MUSIC_BOOK, 0 },
                { TV_MUSIC_BOOK, 1 },
                { TV_MUSIC_BOOK, 1 },
+
+               { TV_HEX_BOOK, 0 },
+               { TV_HEX_BOOK, 0 },
+               { TV_HEX_BOOK, 1 },
+               { TV_HEX_BOOK, 1 },
        },
 
        {
@@ -1380,20 +1468,24 @@ static byte store_table[MAX_STORES][STORE_CHOICES][2] =
 };
 
 
-/*
+/*!
+ * @brief ´ðËܾðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize misc. values
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_misc(void)
 {
        /* Initialize the values */
-       process_dungeon_file("misc_j.txt", 0, 0, 0, 0);
+       process_dungeon_file("misc.txt", 0, 0, 0, 0);
 
        return 0;
 }
 
 
-/*
+/*!
+ * @brief Ä®¾ðÊóÆɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize town array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_towns(void)
 {
@@ -1482,8 +1574,10 @@ static errr init_towns(void)
        return 0;
 }
 
-/*
+/*!
+ * @brief Å¹¾ðÊó½é´ü²½¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize buildings
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 errr init_buildings(void)
 {
@@ -1525,8 +1619,10 @@ errr init_buildings(void)
 }
 
 
-/*
+/*!
+ * @brief ¥¯¥¨¥¹¥È¾ðÊó½é´ü²½¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Initialize quest array
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_quests(void)
 {
@@ -1546,9 +1642,176 @@ static errr init_quests(void)
        return 0;
 }
 
+/*! ÃÏ·Á¥¿¥°¾ðÊ󤫤éÃÏ·ÁID¤òÆÀ¤é¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤ËTRUE¤òÊÖ¤¹¥°¥í¡¼¥Ð¥ëÊÑ¿ô */
+static bool feat_tag_is_not_found = FALSE;
 
-/*
+/*!
+ * @brief ÃÏ·Á¥¿¥°¤«¤éID¤òÆÀ¤ë /
+ * Initialize quest array
+ * @return ÃÏ·ÁID
+ */
+s16b f_tag_to_index_in_init(cptr str)
+{
+       s16b feat = f_tag_to_index(str);
+
+       if (feat < 0) feat_tag_is_not_found = TRUE;
+
+       return feat;
+}
+
+
+/*!
+ * @brief ÃÏ·Á¤ÎÈÆÍÑÄêµÁ¤ò¥¿¥°¤òÄ̤¸¤Æ¼èÆÀ¤¹¤ë /
+ * Initialize feature variables
+ * @return ¥¨¥é¡¼¥³¡¼¥É
+ */
+static errr init_feat_variables(void)
+{
+       int i;
+
+       /* Nothing */
+       feat_none = f_tag_to_index_in_init("NONE");
+
+       /* Floor */
+       feat_floor = f_tag_to_index_in_init("FLOOR");
+
+       /* Objects */
+       feat_glyph = f_tag_to_index_in_init("GLYPH");
+       feat_explosive_rune = f_tag_to_index_in_init("EXPLOSIVE_RUNE");
+       feat_mirror = f_tag_to_index_in_init("MIRROR");
+
+       /* Doors */
+       feat_door[DOOR_DOOR].open = f_tag_to_index_in_init("OPEN_DOOR");
+       feat_door[DOOR_DOOR].broken = f_tag_to_index_in_init("BROKEN_DOOR");
+       feat_door[DOOR_DOOR].closed = f_tag_to_index_in_init("CLOSED_DOOR");
+
+       /* Locked doors */
+       for (i = 1; i < MAX_LJ_DOORS; i++)
+       {
+               s16b door = f_tag_to_index(format("LOCKED_DOOR_%d", i));
+               if (door < 0) break;
+               feat_door[DOOR_DOOR].locked[i - 1] = door;
+       }
+       if (i == 1) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
+       feat_door[DOOR_DOOR].num_locked = i - 1;
+
+       /* Jammed doors */
+       for (i = 0; i < MAX_LJ_DOORS; i++)
+       {
+               s16b door = f_tag_to_index(format("JAMMED_DOOR_%d", i));
+               if (door < 0) break;
+               feat_door[DOOR_DOOR].jammed[i] = door;
+       }
+       if (!i) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
+       feat_door[DOOR_DOOR].num_jammed = i;
+
+       /* Glass doors */
+       feat_door[DOOR_GLASS_DOOR].open = f_tag_to_index_in_init("OPEN_GLASS_DOOR");
+       feat_door[DOOR_GLASS_DOOR].broken = f_tag_to_index_in_init("BROKEN_GLASS_DOOR");
+       feat_door[DOOR_GLASS_DOOR].closed = f_tag_to_index_in_init("CLOSED_GLASS_DOOR");
+
+       /* Locked glass doors */
+       for (i = 1; i < MAX_LJ_DOORS; i++)
+       {
+               s16b door = f_tag_to_index(format("LOCKED_GLASS_DOOR_%d", i));
+               if (door < 0) break;
+               feat_door[DOOR_GLASS_DOOR].locked[i - 1] = door;
+       }
+       if (i == 1) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
+       feat_door[DOOR_GLASS_DOOR].num_locked = i - 1;
+
+       /* Jammed glass doors */
+       for (i = 0; i < MAX_LJ_DOORS; i++)
+       {
+               s16b door = f_tag_to_index(format("JAMMED_GLASS_DOOR_%d", i));
+               if (door < 0) break;
+               feat_door[DOOR_GLASS_DOOR].jammed[i] = door;
+       }
+       if (!i) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
+       feat_door[DOOR_GLASS_DOOR].num_jammed = i;
+
+       /* Curtains */
+       feat_door[DOOR_CURTAIN].open = f_tag_to_index_in_init("OPEN_CURTAIN");
+       feat_door[DOOR_CURTAIN].broken = feat_door[DOOR_CURTAIN].open;
+       feat_door[DOOR_CURTAIN].closed = f_tag_to_index_in_init("CLOSED_CURTAIN");
+       feat_door[DOOR_CURTAIN].locked[0] = feat_door[DOOR_CURTAIN].closed;
+       feat_door[DOOR_CURTAIN].num_locked = 1;
+       feat_door[DOOR_CURTAIN].jammed[0] = feat_door[DOOR_CURTAIN].closed;
+       feat_door[DOOR_CURTAIN].num_jammed = 1;
+
+       /* Stairs */
+       feat_up_stair = f_tag_to_index_in_init("UP_STAIR");
+       feat_down_stair = f_tag_to_index_in_init("DOWN_STAIR");
+       feat_entrance = f_tag_to_index_in_init("ENTRANCE");
+
+       /* Normal traps */
+       init_normal_traps();
+
+       /* Special traps */
+       feat_trap_open = f_tag_to_index_in_init("TRAP_OPEN");
+       feat_trap_armageddon = f_tag_to_index_in_init("TRAP_ARMAGEDDON");
+       feat_trap_piranha = f_tag_to_index_in_init("TRAP_PIRANHA");
+
+       /* Rubble */
+       feat_rubble = f_tag_to_index_in_init("RUBBLE");
+
+       /* Seams */
+       feat_magma_vein = f_tag_to_index_in_init("MAGMA_VEIN");
+       feat_quartz_vein = f_tag_to_index_in_init("QUARTZ_VEIN");
+
+       /* Walls */
+       feat_granite = f_tag_to_index_in_init("GRANITE");
+       feat_permanent = f_tag_to_index_in_init("PERMANENT");
+
+       /* Glass floor */
+       feat_glass_floor = f_tag_to_index_in_init("GLASS_FLOOR");
+
+       /* Glass walls */
+       feat_glass_wall = f_tag_to_index_in_init("GLASS_WALL");
+       feat_permanent_glass_wall = f_tag_to_index_in_init("PERMANENT_GLASS_WALL");
+
+       /* Pattern */
+       feat_pattern_start = f_tag_to_index_in_init("PATTERN_START");
+       feat_pattern_1 = f_tag_to_index_in_init("PATTERN_1");
+       feat_pattern_2 = f_tag_to_index_in_init("PATTERN_2");
+       feat_pattern_3 = f_tag_to_index_in_init("PATTERN_3");
+       feat_pattern_4 = f_tag_to_index_in_init("PATTERN_4");
+       feat_pattern_end = f_tag_to_index_in_init("PATTERN_END");
+       feat_pattern_old = f_tag_to_index_in_init("PATTERN_OLD");
+       feat_pattern_exit = f_tag_to_index_in_init("PATTERN_EXIT");
+       feat_pattern_corrupted = f_tag_to_index_in_init("PATTERN_CORRUPTED");
+
+       /* Various */
+       feat_black_market = f_tag_to_index_in_init("BLACK_MARKET");
+       feat_town = f_tag_to_index_in_init("TOWN");
+
+       /* Terrains */
+       feat_deep_water = f_tag_to_index_in_init("DEEP_WATER");
+       feat_shallow_water = f_tag_to_index_in_init("SHALLOW_WATER");
+       feat_deep_lava = f_tag_to_index_in_init("DEEP_LAVA");
+       feat_shallow_lava = f_tag_to_index_in_init("SHALLOW_LAVA");
+       feat_dirt = f_tag_to_index_in_init("DIRT");
+       feat_grass = f_tag_to_index_in_init("GRASS");
+       feat_flower = f_tag_to_index_in_init("FLOWER");
+       feat_brake = f_tag_to_index_in_init("BRAKE");
+       feat_tree = f_tag_to_index_in_init("TREE");
+       feat_mountain = f_tag_to_index_in_init("MOUNTAIN");
+       feat_swamp = f_tag_to_index_in_init("SWAMP");
+
+       /* Unknown grid (not detected) */
+       feat_undetected = f_tag_to_index_in_init("UNDETECTED");
+
+       /* Wilderness terrains */
+       init_wilderness_terrains();
+
+       return feat_tag_is_not_found ? PARSE_ERROR_UNDEFINED_TERRAIN_TAG : 0;
+}
+
+
+/*!
+ * @brief ¤½¤Î¾¤Î½é´ü¾ðÊ󹹿· /
  * Initialize some other arrays
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_other(void)
 {
@@ -1563,8 +1826,14 @@ static errr init_other(void)
        /* Allocate and Wipe the monster list */
        C_MAKE(m_list, max_m_idx, monster_type);
 
-        /* Allocate and Wipe the max dungeon level */
-        C_MAKE(max_dlv, max_d_idx, s16b);
+       /* Allocate and Wipe the monster process list */
+       for (i = 0; i < MAX_MTIMED; i++)
+       {
+               C_MAKE(mproc_list[i], max_m_idx, s16b);
+       }
+
+       /* Allocate and Wipe the max dungeon level */
+       C_MAKE(max_dlv, max_d_idx, s16b);
 
        /* Allocate and wipe each line of the cave */
        for (i = 0; i < MAX_HGT; i++)
@@ -1585,7 +1854,7 @@ static errr init_other(void)
        C_MAKE(macro__buf, 1024, char);
 
        /* Quark variables */
-       C_MAKE(quark__str, QUARK_MAX, cptr);
+       quark_init();
 
        /* Message variables */
        C_MAKE(message__ptr, MESSAGE_MAX, u16b);
@@ -1601,47 +1870,6 @@ static errr init_other(void)
        C_MAKE(inventory, INVEN_TOTAL, object_type);
 
 
-       /*** Pre-allocate the basic "auto-inscriptions" ***/
-
-       /* The "basic" feelings */
-#ifdef JP
-       (void)quark_add("¼ö¤ï¤ì¤Æ¤¤¤ë");
-       (void)quark_add("²õ¤ì¤Æ¤¤¤ë");
-       (void)quark_add("ÊÂ");
-       (void)quark_add("¾å¼Á");
-#else
-       (void)quark_add("cursed");
-       (void)quark_add("broken");
-       (void)quark_add("average");
-       (void)quark_add("good");
-#endif
-
-
-       /* The "extra" feelings */
-#ifdef JP
-       (void)quark_add("¹âµéÉÊ");
-       (void)quark_add("̵²ÁÃÍ");
-       (void)quark_add("ÆÃÊÌÀ½");
-       (void)quark_add("¶²¤í¤·¤¤");
-#else
-       (void)quark_add("excellent");
-       (void)quark_add("worthless");
-       (void)quark_add("special");
-       (void)quark_add("terrible");
-#endif
-
-
-       /* Some extra strings */
-#ifdef JP
-       (void)quark_add("¼ö¤¤¤Ê¤·");
-       (void)quark_add("Çä½ÐÃæ");
-#else
-       (void)quark_add("uncursed");
-       (void)quark_add("on sale");
-#endif
-
-
-
        /*** Prepare the options ***/
 
        /* Scan the options */
@@ -1688,12 +1916,12 @@ static errr init_other(void)
        }
 
        /*
-         *  Set the "default" window flags
+        *  Set the "default" window flags
         *  Window 1 : Display messages
         *  Window 2 : Display inven/equip
         */
-        window_flag[1] = 1L << 6;
-        window_flag[2] = 1L << 0;
+       window_flag[1] = 1L << 6;
+       window_flag[2] = 1L << 0;
 
 
        /*** Pre-allocate space for the "format()" buffer ***/
@@ -1707,9 +1935,128 @@ static errr init_other(void)
 }
 
 
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥ÈÇÛÎó¤ò½é´ü²½¤¹¤ë /
+ * Initialize some other arrays
+ * @return ¥¨¥é¡¼¥³¡¼¥É
+ */
+static errr init_object_alloc(void)
+{
+       int i, j;
+       object_kind *k_ptr;
+       alloc_entry *table;
+       s16b num[MAX_DEPTH];
+       s16b aux[MAX_DEPTH];
 
-/*
+
+       /*** Analyze object allocation info ***/
+
+       /* Clear the "aux" array */
+       (void)C_WIPE(&aux, MAX_DEPTH, s16b);
+
+       /* Clear the "num" array */
+       (void)C_WIPE(&num, MAX_DEPTH, s16b);
+
+       /* Free the old "alloc_kind_table" (if it exists) */
+       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 (i = 1; i < max_k_idx; i++)
+       {
+               k_ptr = &k_info[i];
+
+               /* Scan allocation pairs */
+               for (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 (i = 1; i < MAX_DEPTH; i++)
+       {
+               /* Group by level */
+               num[i] += num[i-1];
+       }
+
+       /* Paranoia */
+#ifdef JP
+if (!num[0]) quit("Ä®¤Î¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡ª");
+#else
+       if (!num[0]) quit("No town objects!");
+#endif
+
+
+
+       /*** Initialize object allocation info ***/
+
+       /* Allocate the alloc_kind_table */
+       C_MAKE(alloc_kind_table, alloc_kind_size, alloc_entry);
+
+       /* Access the table entry */
+       table = alloc_kind_table;
+
+       /* Scan the objects */
+       for (i = 1; i < max_k_idx; i++)
+       {
+               k_ptr = &k_info[i];
+
+               /* Scan allocation pairs */
+               for (j = 0; j < 4; j++)
+               {
+                       /* Count the "legal" entries */
+                       if (k_ptr->chance[j])
+                       {
+                               int p, x, y, z;
+
+                               /* Extract the base level */
+                               x = k_ptr->locale[j];
+
+                               /* Extract the base probability */
+                               p = (100 / k_ptr->chance[j]);
+
+                               /* Skip entries preceding our locale */
+                               y = (x > 0) ? num[x-1] : 0;
+
+                               /* Skip previous entries at this locale */
+                               z = y + aux[x];
+
+                               /* Load the entry */
+                               table[z].index = i;
+                               table[z].level = x;
+                               table[z].prob1 = p;
+                               table[z].prob2 = p;
+                               table[z].prob3 = p;
+
+                               /* Another entry complete for this locale */
+                               aux[x]++;
+                       }
+               }
+       }
+
+       /* Success */
+       return (0);
+}
+
+
+/*!
+ * @brief ¥â¥ó¥¹¥¿¡¼ÇÛÎó¤ÈÀ¸À®¥Æ¡¼¥Ö¥ë¤ò½é´ü²½¤¹¤ë /
  * Initialize some other arrays
+ * @return ¥¨¥é¡¼¥³¡¼¥É
  */
 static errr init_alloc(void)
 {
@@ -1727,7 +2074,7 @@ static errr init_alloc(void)
        for (i = 1; i < max_r_idx; i++)
        {
                elements[i].tag = r_info[i].level;
-               elements[i].pointer = (void*)i;
+               elements[i].index = i;
        }
 
        tag_sort(elements, max_r_idx);
@@ -1744,7 +2091,7 @@ static errr init_alloc(void)
        for (i = 1; i < max_r_idx; i++)
        {
                /* Get the i'th race */
-               r_ptr = &r_info[(int)elements[i].pointer];
+               r_ptr = &r_info[elements[i].index];
 
                /* Count valid pairs */
                if (r_ptr->rarity)
@@ -1758,7 +2105,7 @@ static errr init_alloc(void)
                        p = (100 / r_ptr->rarity);
 
                        /* Load the entry */
-                       alloc_race_table[i].index = (int)elements[i].pointer;
+                       alloc_race_table[i].index = elements[i].index;
                        alloc_race_table[i].level = x;
                        alloc_race_table[i].prob1 = p;
                        alloc_race_table[i].prob2 = p;
@@ -1766,6 +2113,9 @@ static errr init_alloc(void)
                }
        }
 
+       /* Free the "r_info" array */
+       C_KILL(elements, max_r_idx, tag_type);
+
 #else /* SORT_R_INFO */
 
        int j;
@@ -1871,8 +2221,10 @@ static errr init_alloc(void)
 
 
 
-/*
+/*!
+ * @brief ²èÌ̺¸²¼¤Ë¥·¥¹¥Æ¥à¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë /
  * Hack -- take notes on line 23
+ * @return ¤Ê¤·
  */
 static void note(cptr str)
 {
@@ -1883,12 +2235,16 @@ static void note(cptr str)
 
 
 
-/*
+/*!
+ * @brief Á´¥²¡¼¥à¥Ç¡¼¥¿Æɤ߹þ¤ß¤Î¥µ¥Ö¥ë¡¼¥Á¥ó /
  * Hack -- Explain a broken "lib" folder and quit (see below).
- *
+ * @return ¤Ê¤·
+ * @note
+ * <pre>
  * XXX XXX XXX 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.
+ * </pre>
  */
 static void init_angband_aux(cptr why)
 {
@@ -1924,26 +2280,29 @@ static void init_angband_aux(cptr why)
 }
 
 
-/*
+/*!
+ * @brief Á´¥²¡¼¥à¥Ç¡¼¥¿Æɤ߹þ¤ß¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Hack -- main Angband initialization entry point
- *
+ * @return ¤Ê¤·
+ * @note
+ * <pre>
+ * XXX XXX XXX 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
@@ -1954,28 +2313,24 @@ static void init_angband_aux(cptr why)
  * 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(void)
 {
        int fd = -1;
 
-       int mode = 0644;
+       int mode = 0664;
 
        FILE *fp;
 
@@ -1986,9 +2341,9 @@ void init_angband(void)
 
        /* Build the filename */
 #ifdef JP
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "news_j.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news_j.txt");
 #else
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "news.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt");
 #endif
 
 
@@ -2023,9 +2378,9 @@ void init_angband(void)
 
        /* Build the filename */
 #ifdef JP
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "news_j.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news_j.txt");
 #else
-       path_build(buf, 1024, ANGBAND_DIR_FILE, "news.txt");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt");
 #endif
 
 
@@ -2038,7 +2393,7 @@ void init_angband(void)
                int i = 0;
 
                /* Dump the file to the screen */
-               while (0 == my_fgets(fp, buf, 1024))
+               while (0 == my_fgets(fp, buf, sizeof(buf)))
                {
                        /* Display and advance */
                        Term_putstr(0, i++, -1, TERM_WHITE, buf);
@@ -2049,13 +2404,13 @@ void init_angband(void)
        }
 
        /* Flush it */
-       Term_fresh();
+       Term_flush();
 
 
        /*** Verify (or create) the "high score" file ***/
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+       path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
        /* Attempt to open the high score file */
        fd = fd_open(buf, O_RDONLY);
@@ -2066,9 +2421,15 @@ void init_angband(void)
                /* File type is "DATA" */
                FILE_TYPE(FILE_TYPE_DATA);
 
+               /* Grab permissions */
+               safe_setuid_grab();
+
                /* Create a new high score file */
                fd = fd_make(buf, mode);
 
+               /* Drop permissions */
+               safe_setuid_drop();
+
                /* Failure */
                if (fd < 0)
                {
@@ -2111,9 +2472,11 @@ if (init_misc()) quit("
 #ifdef JP
        note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ÃÏ·Á)]");
        if (init_f_info()) quit("ÃÏ·Á½é´ü²½ÉÔǽ");
+       if (init_feat_variables()) quit("ÃÏ·Á½é´ü²½ÉÔǽ");
 #else
        note("[Initializing arrays... (features)]");
        if (init_f_info()) quit("Cannot initialize features");
+       if (init_feat_variables()) quit("Cannot initialize features");
 #endif
 
 
@@ -2246,6 +2609,14 @@ if (init_quests()) quit("
 #endif
 
 
+       /* Initialize vault info */
+#ifdef JP
+       if (init_v_info()) quit("vault ½é´ü²½ÉÔǽ");
+#else
+       if (init_v_info()) quit("Cannot initialize vaults");
+#endif
+
+
        /* Initialize some other arrays */
 #ifdef JP
        note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¤½¤Î¾)]");
@@ -2284,24 +2655,12 @@ note("[
        /* Process that file */
        process_pref_file(buf);
 
-       /* Access the "user" pref file */
-       sprintf(buf, "user.prf");
-
-       /* Process that file */
-       process_pref_file(buf);
-
        /* Access the "basic" system pref file */
        sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
 
        /* Process that file */
        process_pref_file(buf);
 
-       /* Access the "user" system pref file */
-       sprintf(buf, "user-%s.prf", ANGBAND_SYS);
-
-       /* Process that file */
-       process_pref_file(buf);
-
        /* Done */
 #ifdef JP
        note("[½é´ü²½½ªÎ»]");
@@ -2310,3 +2669,22 @@ note("[
 #endif
 
 }
+
+/*!
+ * @brief ¥µ¥à¥Á¥§¥Ã¥¯¾ðÊó¤ò½ÐÎÏ / Get check sum in string form
+ * @return ¥µ¥à¥Á¥§¥Ã¥¯¾ðÊó¤Îʸ»úÎó
+ */
+cptr get_check_sum(void)
+{
+       return format("%02x%02x%02x%02x%02x%02x%02x%02x%02x", 
+                     f_head.v_extra, 
+                     k_head.v_extra, 
+                     a_head.v_extra, 
+                     e_head.v_extra, 
+                     r_head.v_extra, 
+                     d_head.v_extra, 
+                     m_head.v_extra, 
+                     s_head.v_extra, 
+                     v_head.v_extra);
+}
+