* 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.
+ * to create the binary image files. Note that the binary image files
+ * are extremely system dependant.
* </pre>
*/
#include "angband.h"
#include "util.h"
+#include "io/uid-checker.h"
#include "files.h"
#include "core.h"
-#include "term.h"
+#include "core/angband-version.h"
+#include "io/read-pref-file.h"
+#include "gameterm.h"
#include "artifact.h"
-#include "bldg.h"
+#include "market/building.h"
#include "init.h"
#include "quest.h"
#include "trap.h"
#include "rooms.h"
-#include "store.h"
+#include "market/store.h"
#include "wild.h"
#include "dungeon-file.h"
#include "files.h"
#include "rooms-vault.h"
#include "player-skill.h"
#include "player-class.h"
-#include "objectkind.h"
+#include "object/object-kind.h"
#include "object-ego.h"
#include "rooms-vault.h"
-#include "world.h"
+#include "world/world.h"
+#include "market/articles-on-sale.h"
+#include "market/store-util.h"
-#ifndef MACINTOSH
-#ifdef CHECK_MODIFICATION_TIME
#include <sys/types.h>
#include <sys/stat.h>
-#endif /* CHECK_MODIFICATION_TIME */
-#endif
static void put_title(void);
string_free(ANGBAND_DIR_USER);
string_free(ANGBAND_DIR_XTRA);
-
/*** Prepare the "path" ***/
/* Hack -- save the main directory */
/* Build a path name */
strcpy(tail, "xtra");
ANGBAND_DIR_XTRA = string_make(path);
-
-
-#ifdef NeXT
-
- /* Allow "fat binary" usage with NeXT */
- if (TRUE)
- {
- concptr next = NULL;
-
-# if defined(m68k)
- next = "m68k";
-# endif
-
-# if defined(i386)
- next = "i386";
-# endif
-
-# if defined(sparc)
- next = "sparc";
-# endif
-
-# if defined(hppa)
- next = "hppa";
-# endif
-
- /* Use special directory */
- if (next)
- {
- /* Forget the old path name */
- string_free(ANGBAND_DIR_DATA);
-
- /* Build a new path name */
- sprintf(tail, "data-%s", next);
- ANGBAND_DIR_DATA = string_make(path);
- }
- }
-
-#endif /* NeXT */
-
}
-
-#ifdef ALLOW_TEMPLATES
-
-
/*
* Hack -- help give useful error messages
*/
int error_idx; /*!< データ読み込み/初期化時に汎用的にエラーコードを保存するグローバル変数 */
int error_line; /*!< データ読み込み/初期化時に汎用的にエラー行数を保存するグローバル変数 */
-
/*!
* エラーメッセージの名称定義 / Standard error message text
*/
};
-#endif /* ALLOW_TEMPLATES */
-
-
/*
* File headers
*/
header s_head; /*!< プレイヤー職業技能情報のヘッダ構造体 */
header m_head; /*!< プレイヤー職業魔法情報のヘッダ構造体 */
-#ifdef CHECK_MODIFICATION_TIME
-
/*!
* @brief テキストファイルとrawファイルの更新時刻を比較する
* Find the default paths to all of our important sub-directories.
*/
static errr check_modification_date(int fd, concptr template_file)
{
- char buf[1024];
-
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))
{
- /* No text file - continue */
+ return 0;
}
/* Access stats on raw file */
- else if (fstat(fd, &raw_stat))
+ if (fstat(fd, &raw_stat))
{
- /* Error */
- return (-1);
+ return -1;
}
/* Ensure text file is not newer than raw file */
- else if (txt_stat.st_mtime > raw_stat.st_mtime)
+ if (txt_stat.st_mtime > raw_stat.st_mtime)
{
- /* Reprocess text file */
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
-#endif /* CHECK_MODIFICATION_TIME */
-
-
/*** Initialize from binary image files ***/
-
/*!
* @brief rawファイルからのデータの読み取り処理
* Initialize the "*_info" array, by parsing a binary "image" file
/* Read and Verify the header */
if (fd_read(fd, (char*)(&test), sizeof(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))
+ (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);
+ return -1;
}
-
/* Accept the header */
(*head) = test;
-
/* Allocate the "*_info" array */
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 */
fd_read(fd, head->name_ptr, head->name_size);
}
-
if (head->text_size)
{
/* Allocate the "*_text" array */
fd_read(fd, head->text_ptr, head->text_size);
}
-
if (head->tag_size)
{
/* Allocate the "*_tag" array */
fd_read(fd, head->tag_ptr, head->tag_size);
}
-
- /* Success */
- return (0);
+ return 0;
}
}
+static void update_header(header *head, void **info, char **name, char **text, char **tag)
+{
+ if (info) *info = head->info_ptr;
+ if (name) *name = head->name_ptr;
+ if (text) *text = head->text_ptr;
+ if (tag) *tag = head->tag_ptr;
+}
+
+
/*!
* @brief ヘッダ構造体の更新
* Initialize the "*_info" array
* 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(concptr filename, header *head,
- void **info, char **name, char **text, char **tag)
+static errr init_info(concptr filename, header *head, void **info, char **name, char **text, char **tag)
{
- int fd;
-
- BIT_FLAGS mode = 0644;
-
- errr err = 1;
-
- FILE *fp;
-
/* General buffer */
char buf[1024];
-
-#ifdef ALLOW_TEMPLATES
-
/*** 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);
+ int fd = fd_open(buf, O_RDONLY);
/* Process existing "raw" file */
+ errr err = 1;
if (fd >= 0)
{
-#ifdef CHECK_MODIFICATION_TIME
-
err = check_modification_date(fd, format("%s.txt", filename));
-#endif /* CHECK_MODIFICATION_TIME */
-
/* 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? */
- if (err)
+ BIT_FLAGS file_permission = 0644;
+ if (err == 0)
{
- /*** Make the fake arrays ***/
-
- /* Allocate the "*_info" array */
- C_MAKE(head->info_ptr, head->info_size, char);
+ update_header(head, info, name, text, tag);
+ return 0;
+ }
- /* 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);
+ /*** Make the fake arrays ***/
+ C_MAKE(head->info_ptr, head->info_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;
+ /* 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);
- /*** Load the ascii template file ***/
+ if (info) (*info) = head->info_ptr;
+ if (name) (*name) = head->name_ptr;
+ if (text) (*text) = head->text_ptr;
+ if (tag) (*tag) = head->tag_ptr;
- path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
- fp = my_fopen(buf, "r");
+ /*** Load the ascii template file ***/
+ path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
+ FILE *fp;
+ fp = my_fopen(buf, "r");
- /* Parse it */
- if (!fp) quit(format(_("'%s.txt'ファイルをオープンできません。", "Cannot open '%s.txt' file."), filename));
+ /* 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);
- my_fclose(fp);
+ /* Parse the file */
+ err = init_info_txt(fp, buf, head, head->parse_info_txt);
+ my_fclose(fp);
- /* Errors */
- if (err)
- {
- concptr oops;
+ /* Errors */
+ if (err)
+ {
+ concptr oops;
#ifdef JP
- /* Error string */
- oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "未知の");
+ /* 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);
+ 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));
+ /* Quit */
+ quit(format("'%s.txt'ファイルにエラー", filename));
#else
- /* Error string */
- oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
+ /* 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);
+ 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));
+ /* Quit */
+ quit(format("Error in '%s.txt' file.", filename));
#endif
+ }
- }
-
-
- /*** Make final retouch on fake tags ***/
-
- if (head->retouch)
- {
- (*head->retouch)(head);
- }
-
-
- /*** Dump the binary image file ***/
-
- /* File type is "DATA" */
- FILE_TYPE(FILE_TYPE_DATA);
- path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
-
-
- /* 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();
+ /*** Make final retouch on fake tags ***/
+ if (head->retouch)
+ {
+ (*head->retouch)(head);
+ }
- /* Dump to the file */
- if (fd >= 0)
- {
- /* Dump it */
- fd_write(fd, (concptr)(head), head->head_size);
+ /*** Dump the binary image file ***/
+ /* File type is "DATA" */
+ FILE_TYPE(FILE_TYPE_DATA);
+ path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
- /* Dump the "*_info" array */
- fd_write(fd, head->info_ptr, head->info_size);
+ /* Grab permissions */
+ safe_setuid_grab();
- /* Dump the "*_name" array */
- fd_write(fd, head->name_ptr, head->name_size);
+ /* Kill the old file */
+ (void)fd_kill(buf);
- /* Dump the "*_text" array */
- fd_write(fd, head->text_ptr, head->text_size);
+ /* Attempt to create the raw file */
+ fd = fd_make(buf, file_permission);
- /* Dump the "*_tag" array */
- fd_write(fd, head->tag_ptr, head->tag_size);
+ /* Drop permissions */
+ safe_setuid_drop();
- /* Close */
- (void)fd_close(fd);
- }
+ /* 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);
- /*** Kill the fake arrays ***/
+ /* Dump the "*_name" array */
+ fd_write(fd, head->name_ptr, head->name_size);
- /* Free the "*_info" array */
- C_KILL(head->info_ptr, head->info_size, char);
+ /* Dump the "*_text" array */
+ fd_write(fd, head->text_ptr, head->text_size);
- /* 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);
+ /* Dump the "*_tag" array */
+ fd_write(fd, head->tag_ptr, head->tag_size);
-#endif /* ALLOW_TEMPLATES */
+ /* Close */
+ (void)fd_close(fd);
+ }
+ /*** Kill the fake arrays ***/
- /*** Load the binary image file ***/
- path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
+ /* Free the "*_info" array */
+ C_KILL(head->info_ptr, head->info_size, char);
- /* Attempt to open the "raw" file */
- fd = fd_open(buf, O_RDONLY);
+ /* 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);
- /* Process existing "raw" file */
- if (fd < 0) quit(format(_("'%s_j.raw'ファイルをロードできません。", "Cannot load '%s.raw' file."), filename));
+ /*** Load the binary image file ***/
+ path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
- /* Attempt to parse the "raw" file */
- err = init_info_raw(fd, head);
- (void)fd_close(fd);
+ /* Attempt to open the "raw" file */
+ fd = fd_open(buf, O_RDONLY);
- /* Error */
- if (err) quit(format(_("'%s_j.raw'ファイルを解析できません。", "Cannot parse '%s.raw' file."), filename));
+ /* Process existing "raw" file */
+ if (fd < 0) quit(format(_("'%s_j.raw'ファイルをロードできません。", "Cannot load '%s.raw' file."), filename));
-#ifdef ALLOW_TEMPLATES
- }
-#endif
+ /* Attempt to parse the "raw" file */
+ err = init_info_raw(fd, head);
+ (void)fd_close(fd);
- if (info) (*info) = head->info_ptr;
- if (name) (*name) = head->name_ptr;
- if (text) (*text) = head->text_ptr;
- if (tag) (*tag) = head->tag_ptr;
+ /* Error */
+ if (err) quit(format(_("'%s_j.raw'ファイルを解析できません。", "Cannot parse '%s.raw' file."), filename));
- /* Success */
- return (0);
+ update_header(head, info, name, text, tag);
+ return 0;
}
/* Init the header */
init_header(&f_head, max_f_idx, sizeof(feature_type));
-#ifdef ALLOW_TEMPLATES
-
/* 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, &f_name, NULL, &f_tag);
+ (void*)&f_info, &f_name, NULL, &f_tag);
}
/* Init the header */
init_header(&k_head, max_k_idx, sizeof(object_kind));
-#ifdef ALLOW_TEMPLATES
-
/* Save a pointer to the parsing function */
k_head.parse_info_txt = parse_k_info;
-#endif /* ALLOW_TEMPLATES */
-
return init_info("k_info", &k_head,
- (void*)&k_info, &k_name, &k_text, NULL);
+ (void*)&k_info, &k_name, &k_text, NULL);
}
-
/*!
* @brief 固定アーティファクト情報読み込みのメインルーチン /
* Initialize the "a_info" array
/* Init the header */
init_header(&a_head, max_a_idx, sizeof(artifact_type));
-#ifdef ALLOW_TEMPLATES
-
/* Save a pointer to the parsing function */
a_head.parse_info_txt = parse_a_info;
-#endif /* ALLOW_TEMPLATES */
-
return init_info("a_info", &a_head,
- (void*)&a_info, &a_name, &a_text, NULL);
+ (void*)&a_info, &a_name, &a_text, NULL);
}
-
/*!
* @brief 固定アーティファクト情報読み込みのメインルーチン /
* Initialize the "e_info" array
/* Init the header */
init_header(&e_head, max_e_idx, sizeof(ego_item_type));
-#ifdef ALLOW_TEMPLATES
-
/* Save a pointer to the parsing function */
e_head.parse_info_txt = parse_e_info;
-#endif /* ALLOW_TEMPLATES */
-
return init_info("e_info", &e_head,
- (void*)&e_info, &e_name, &e_text, NULL);
+ (void*)&e_info, &e_name, &e_text, NULL);
}
-
/*!
* @brief モンスター種族情報読み込みのメインルーチン /
* Initialize the "r_info" array
/* Init the header */
init_header(&r_head, max_r_idx, sizeof(monster_race));
-#ifdef ALLOW_TEMPLATES
-
/* Save a pointer to the parsing function */
r_head.parse_info_txt = parse_r_info;
-#endif /* ALLOW_TEMPLATES */
-
return init_info("r_info", &r_head,
- (void*)&r_info, &r_name, &r_text, NULL);
+ (void*)&r_info, &r_name, &r_text, NULL);
}
-
/*!
* @brief ダンジョン情報読み込みのメインルーチン /
* Initialize the "d_info" array
/* Init the header */
init_header(&d_head, current_world_ptr->max_d_idx, sizeof(dungeon_type));
-#ifdef ALLOW_TEMPLATES
-
/* Save a pointer to the parsing function */
d_head.parse_info_txt = parse_d_info;
-#endif /* ALLOW_TEMPLATES */
-
return init_info("d_info", &d_head,
- (void*)&d_info, &d_name, &d_text, NULL);
+ (void*)&d_info, &d_name, &d_text, NULL);
}
/* Init the header */
init_header(&v_head, max_v_idx, sizeof(vault_type));
-#ifdef ALLOW_TEMPLATES
-
/* Save a pointer to the parsing function */
v_head.parse_info_txt = parse_v_info;
-#endif /* ALLOW_TEMPLATES */
-
return init_info("v_info", &v_head,
- (void*)&v_info, &v_name, &v_text, NULL);
+ (void*)&v_info, &v_name, &v_text, NULL);
}
/* Init the header */
init_header(&s_head, MAX_CLASS, sizeof(skill_table));
-#ifdef ALLOW_TEMPLATES
-
/* Save a pointer to the parsing function */
s_head.parse_info_txt = parse_s_info;
-#endif /* ALLOW_TEMPLATES */
-
return init_info("s_info", &s_head,
- (void*)&s_info, NULL, NULL, NULL);
+ (void*)&s_info, NULL, NULL, NULL);
}
/* Init the header */
init_header(&m_head, MAX_CLASS, sizeof(player_magic));
-#ifdef ALLOW_TEMPLATES
-
/* Save a pointer to the parsing function */
m_head.parse_info_txt = parse_m_info;
-#endif /* ALLOW_TEMPLATES */
-
return init_info("m_info", &m_head,
- (void*)&m_info, NULL, NULL, NULL);
+ (void*)&m_info, NULL, NULL, NULL);
}
-
-
-
/*!
* @brief 基本情報読み込みのメインルーチン /
* Initialize misc. values
+ * @param player_ptr プレーヤーへの参照ポインタ
* @return エラーコード
*/
-static errr init_misc(void)
+static errr init_misc(player_type *player_ptr)
{
- /* Initialize the values */
- process_dungeon_file("misc.txt", 0, 0, 0, 0);
-
- return 0;
+ return process_dungeon_file(player_ptr, "misc.txt", 0, 0, 0, 0);
}
*/
static errr init_towns(void)
{
- int i, j, k;
-
- /*** Prepare the Towns ***/
-
/* Allocate the towns */
C_MAKE(town_info, max_towns, town_type);
- for (i = 1; i < max_towns; i++)
+ for (int i = 1; i < max_towns; i++)
{
/*** Prepare the Stores ***/
C_MAKE(town_info[i].store, MAX_STORES, store_type);
/* Fill in each store */
- for (j = 0; j < MAX_STORES; j++)
+ for (int j = 0; j < MAX_STORES; j++)
{
/* Access the store */
- store_type *st_ptr = &town_info[i].store[j];
+ store_type *store_ptr = &town_info[i].store[j];
if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
/* Assume full stock */
- /*
- * 我が家が 20 ページまで使える隠し機能のための準備。
- * オプションが有効でもそうでなくても一応スペース
- * を作っておく。
- */
- if (j == STORE_HOME)
- {
- st_ptr->stock_size = (STORE_INVEN_MAX * 10);
- }
- else if (j == STORE_MUSEUM)
- {
- st_ptr->stock_size = (STORE_INVEN_MAX * 50);
- }
- else
- {
- st_ptr->stock_size = STORE_INVEN_MAX;
- }
+ /*
+ * 我が家が 20 ページまで使える隠し機能のための準備。
+ * オプションが有効でもそうでなくても一応スペースを作っておく。
+ */
+ if (j == STORE_HOME)
+ {
+ store_ptr->stock_size = (STORE_INVEN_MAX * 10);
+ }
+ else if (j == STORE_MUSEUM)
+ {
+ store_ptr->stock_size = (STORE_INVEN_MAX * 50);
+ }
+ else
+ {
+ store_ptr->stock_size = STORE_INVEN_MAX;
+ }
+
/* Allocate the stock */
- C_MAKE(st_ptr->stock, st_ptr->stock_size, object_type);
+ 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 */
- st_ptr->table_size = STORE_CHOICES;
+ store_ptr->table_size = STORE_CHOICES;
/* Allocate the stock */
- C_MAKE(st_ptr->table, st_ptr->table_size, s16b);
+ C_MAKE(store_ptr->table, store_ptr->table_size, s16b);
/* Scan the choices */
- for (k = 0; k < STORE_CHOICES; k++)
+ for (int k = 0; k < STORE_CHOICES; k++)
{
KIND_OBJECT_IDX k_idx;
if (k_idx == max_k_idx) continue;
/* Add that item index to the table */
- st_ptr->table[st_ptr->table_num++] = k_idx;
+ store_ptr->table[store_ptr->table_num++] = k_idx;
}
}
}
*/
errr init_buildings(void)
{
- int i, j;
-
- for (i = 0; i < MAX_BLDG; i++)
+ for (int i = 0; i < MAX_BLDG; i++)
{
building[i].name[0] = '\0';
building[i].owner_name[0] = '\0';
building[i].owner_race[0] = '\0';
- for (j = 0; j < 8; j++)
+ for (int j = 0; j < 8; j++)
{
building[i].act_names[j][0] = '\0';
building[i].member_costs[j] = 0;
building[i].action_restr[j] = 0;
}
- for (j = 0; j < MAX_CLASS; j++)
+ for (int j = 0; j < MAX_CLASS; j++)
{
building[i].member_class[j] = 0;
}
- for (j = 0; j < MAX_RACES; j++)
+ for (int j = 0; j < MAX_RACES; j++)
{
building[i].member_race[j] = 0;
}
- for (j = 0; j < MAX_MAGIC+1; j++)
+ for (int j = 0; j < MAX_MAGIC + 1; j++)
{
building[i].member_realm[j] = 0;
}
}
- return (0);
+ return 0;
}
*/
static errr init_quests(void)
{
- int i;
-
- /*** Prepare the quests ***/
-
/* Allocate the quests */
C_MAKE(quest, max_q_idx, quest_type);
/* Set all quest to "untaken" */
- for (i = 0; i < max_q_idx; i++)
+ for (int i = 0; i < max_q_idx; i++)
{
quest[i].status = QUEST_STATUS_UNTAKEN;
}
*/
static errr init_feat_variables(void)
{
- FEAT_IDX 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 */
+ FEAT_IDX i;
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;
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;
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;
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;
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;
}
* Initialize some other arrays
* @return エラーコード
*/
-static errr init_other(void)
+static errr init_other(player_type *player_ptr)
{
- int i, n;
-
- p_ptr->current_floor_ptr = &floor_info; // TODO:本当はこんなところで初期化したくない
-
+ 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(p_ptr->current_floor_ptr->o_list, current_world_ptr->max_o_idx, object_type);
+ C_MAKE(floor_ptr->o_list, current_world_ptr->max_o_idx, object_type);
/* Allocate and Wipe the monster list */
- C_MAKE(p_ptr->current_floor_ptr->m_list, current_world_ptr->max_m_idx, monster_type);
+ C_MAKE(floor_ptr->m_list, current_world_ptr->max_m_idx, monster_type);
/* Allocate and Wipe the monster process list */
- for (i = 0; i < MAX_MTIMED; i++)
+ for (int i = 0; i < MAX_MTIMED; i++)
{
- C_MAKE(p_ptr->current_floor_ptr->mproc_list[i], current_world_ptr->max_m_idx, s16b);
+ 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);
- /* Allocate and wipe each line of the p_ptr->current_floor_ptr->grid_array */
- for (i = 0; i < MAX_HGT; i++)
+ for (int i = 0; i < MAX_HGT; i++)
{
- /* Allocate one row of the p_ptr->current_floor_ptr->grid_array */
- C_MAKE(p_ptr->current_floor_ptr->grid_array[i], MAX_WID, grid_type);
+ C_MAKE(floor_ptr->grid_array[i], MAX_WID, grid_type);
}
-
/*** Prepare the various "bizarre" arrays ***/
/* Macro variables */
/*** Prepare the options ***/
/* Scan the options */
- for (i = 0; option_info[i].o_desc; i++)
+ 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)
- {
- /* Accept */
- option_mask[os] |= (1L << ob);
+ 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)
- {
- /* Set */
- option_flag[os] |= (1L << ob);
- }
- else
- {
- option_flag[os] &= ~(1L << ob);
- }
+ option_flag[os] |= (1L << ob);
+ }
+ else
+ {
+ option_flag[os] &= ~(1L << ob);
}
}
/* Analyze the windows */
- for (n = 0; n < 8; n++)
+ for (int n = 0; n < 8; n++)
{
/* Analyze the options */
- for (i = 0; i < 32; i++)
+ for (int i = 0; i < 32; i++)
{
/* Accept */
if (window_flag_desc[i])
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);
-
-
- /* Success */
- return (0);
+ return 0;
}
*/
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 */
+ s16b num[MAX_DEPTH];
(void)C_WIPE(&num, MAX_DEPTH, s16b);
/* Free the old "alloc_kind_table" (if it exists) */
alloc_kind_size = 0;
/* Scan the objects */
- for (i = 1; i < max_k_idx; i++)
+ for (int i = 1; i < max_k_idx; i++)
{
+ object_kind *k_ptr;
k_ptr = &k_info[i];
/* Scan allocation pairs */
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
{
/* Count the "legal" entries */
if (k_ptr->chance[j])
}
/* Collect the level indexes */
- for (i = 1; i < MAX_DEPTH; i++)
+ for (int i = 1; i < MAX_DEPTH; i++)
{
/* Group by level */
- num[i] += num[i-1];
+ num[i] += num[i - 1];
}
+
if (!num[0]) quit(_("町のアイテムがない!", "No town objects!"));
/*** Initialize object allocation info ***/
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 (i = 1; i < max_k_idx; i++)
+ for (int i = 1; i < max_k_idx; i++)
{
+ object_kind *k_ptr;
k_ptr = &k_info[i];
/* Scan allocation pairs */
- for (j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++)
{
/* Count the "legal" entries */
- if (k_ptr->chance[j])
- {
- int p, x, y, z;
+ if (k_ptr->chance[j] == 0) continue;
- /* Extract the base level */
- x = k_ptr->locale[j];
+ /* Extract the base level */
+ int x = k_ptr->locale[j];
- /* Extract the base probability */
- p = (100 / k_ptr->chance[j]);
+ /* Extract the base probability */
+ int p = (100 / k_ptr->chance[j]);
- /* Skip entries preceding our locale */
- y = (x > 0) ? num[x-1] : 0;
+ /* Skip entries preceding our locale */
+ int y = (x > 0) ? num[x - 1] : 0;
- /* Skip previous entries at this locale */
- z = y + aux[x];
+ /* 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;
+ /* 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]++;
- }
+ /* Another entry complete for this locale */
+ aux[x]++;
}
}
- /* Success */
- return (0);
+ return 0;
}
*/
static errr init_alloc(void)
{
- int i;
monster_race *r_ptr;
-
-#ifdef SORT_R_INFO
-
tag_type *elements;
/* Allocate the "r_info" array */
C_MAKE(elements, max_r_idx, tag_type);
/* Scan the monsters */
- for (i = 1; i < max_r_idx; i++)
+ for (int i = 1; i < max_r_idx; i++)
{
elements[i].tag = r_info[i].level;
elements[i].index = i;
C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
/* Scan the monsters */
- for (i = 1; i < max_r_idx; i++)
+ 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)
- {
- int p, x;
+ if (r_ptr->rarity == 0) continue;
- /* Extract the base level */
- x = r_ptr->level;
+ /* Extract the base level */
+ int x = r_ptr->level;
- /* Extract the base probability */
- p = (100 / r_ptr->rarity);
+ /* 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;
- alloc_race_table[i].prob2 = (PROB)p;
- alloc_race_table[i].prob3 = (PROB)p;
- }
+ /* 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;
+ alloc_race_table[i].prob2 = (PROB)p;
+ alloc_race_table[i].prob3 = (PROB)p;
}
/* Free the "r_info" array */
C_KILL(elements, max_r_idx, tag_type);
-
-#else /* SORT_R_INFO */
-
- int j;
- alloc_entry *table;
- s16b num[MAX_DEPTH];
- s16b aux[MAX_DEPTH];
-
- /*** Analyze monster allocation info ***/
-
- /* Clear the "aux" array */
- C_WIPE(&aux, MAX_DEPTH, s16b);
-
- /* Clear the "num" array */
- C_WIPE(&num, MAX_DEPTH, s16b);
-
- /* Size of "alloc_race_table" */
- alloc_race_size = 0;
-
- /* Scan the monsters */
- for (i = 1; i < max_r_idx; i++)
- {
- /* Get the i'th race */
- r_ptr = &r_info[i];
-
- /* Legal monsters */
- if (r_ptr->rarity)
- {
- /* Count the entries */
- alloc_race_size++;
-
- /* Group by level */
- num[r_ptr->level]++;
- }
- }
-
- /* Collect the level indexes */
- for (i = 1; i < MAX_DEPTH; i++)
- {
- /* Group by level */
- num[i] += num[i-1];
- }
- if (!num[0]) quit(_("町のモンスターがない!", "No town monsters!"));
-
- /*** Initialize monster allocation info ***/
-
- /* Allocate the alloc_race_table */
- C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
-
- /* Access the table entry */
- table = alloc_race_table;
-
- /* Scan the monsters */
- for (i = 1; i < max_r_idx; i++)
- {
- /* Get the i'th race */
- r_ptr = &r_info[i];
-
- /* Count valid pairs */
- if (r_ptr->rarity)
- {
- int p, x, y, z;
-
- /* Extract the base level */
- x = r_ptr->level;
-
- /* Extract the base probability */
- p = (100 / r_ptr->rarity);
-
- /* 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]++;
- }
- }
-
-#endif /* SORT_R_INFO */
-
- /* Init the "alloc_kind_table" */
(void)init_object_alloc();
-
- /* Success */
- return (0);
+ return 0;
}
-
/*!
* @brief 画面左下にシステムメッセージを表示する /
* Hack -- take notes on line 23
}
-
/*!
* @brief 全ゲームデータ読み込みのサブルーチン /
* Hack -- Explain a broken "lib" folder and quit (see below).
*/
static void init_angband_aux(concptr why)
{
- /* Why */
plog(why);
#ifdef JP
* if needed, in the first (?) pass through "TERM_XTRA_REACT".
* </pre>
*/
-void init_angband(void)
+void init_angband(player_type *player_ptr, void(*process_autopick_file_command)(char*))
{
- int fd = -1;
-
- BIT_FLAGS mode = 0664;
-
- FILE *fp;
-
- char buf[1024];
-
-
/*** 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 */
- fd = fd_open(buf, O_RDONLY);
+ int fd = fd_open(buf, O_RDONLY);
/* Failure */
if (fd < 0)
/* Crash and burn */
init_angband_aux(why);
}
- (void)fd_close(fd);
+ (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 = my_fopen(buf, "r");
/* Dump */
if (fp)
{
- int i = 0;
-
/* Dump the file to the screen */
+ int i = 0;
while (0 == my_fgets(fp, buf, sizeof(buf)))
{
/* Display and advance */
Term_putstr(0, i++, -1, TERM_WHITE, buf);
}
- /* Close */
my_fclose(fp);
}
- /* Flush it */
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);
- /* Failure */
+ BIT_FLAGS file_permission = 0664;
if (fd < 0)
{
/* File type is "DATA" */
safe_setuid_grab();
/* Create a new high score file */
- fd = fd_make(buf, mode);
+ fd = fd_make(buf, file_permission);
/* Drop permissions */
safe_setuid_drop();
init_angband_aux(why);
}
}
+
(void)fd_close(fd);
put_title();
/* Initialize misc. values */
note(_("[変数を初期化しています...(その他)", "[Initializing values... (misc)]"));
- if (init_misc()) quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
+ if (init_misc(player_ptr)) quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
/* Initialize feature info */
#ifdef JP
if (init_feat_variables()) quit("Cannot initialize features");
#endif
-
/* Initialize object info */
note(_("[データの初期化中... (アイテム)]", "[Initializing arrays... (objects)]"));
if (init_k_info()) quit(_("アイテム初期化不能", "Cannot initialize objects"));
-
/* Initialize artifact info */
note(_("[データの初期化中... (伝説のアイテム)]", "[Initializing arrays... (artifacts)]"));
if (init_a_info()) quit(_("伝説のアイテム初期化不能", "Cannot initialize artifacts"));
note(_("[データの初期化中... (ダンジョン)]", "[Initializing arrays... (dungeon)]"));
if (init_d_info()) quit(_("ダンジョン初期化不能", "Cannot initialize dungeon"));
{
- int i;
- for (i = 1; i < current_world_ptr->max_d_idx; i++)
+ 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;
}
if (init_wilderness()) quit(_("荒野を初期化できません", "Cannot initialize wilderness"));
-
/* Initialize town array */
note(_("[配列を初期化しています... (街)]", "[Initializing arrays... (towns)]"));
if (init_towns()) quit(_("街を初期化できません", "Cannot initialize towns"));
-
/* Initialize building array */
note(_("[配列を初期化しています... (建物)]", "[Initializing arrays... (buildings)]"));
if (init_buildings()) quit(_("建物を初期化できません", "Cannot initialize buildings"));
-
/* Initialize quest array */
note(_("[配列を初期化しています... (クエスト)]", "[Initializing arrays... (quests)]"));
if (init_quests()) quit(_("クエストを初期化できません", "Cannot initialize quests"));
/* Initialize some other arrays */
note(_("[データの初期化中... (その他)]", "[Initializing arrays... (other)]"));
- if (init_other()) quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
-
+ if (init_other(player_ptr)) quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
/* Initialize some other arrays */
note(_("[データの初期化中... (アロケーション)]", "[Initializing arrays... (alloc)]"));
if (init_alloc()) quit(_("アロケーション・スタッフ初期化不能", "Cannot initialize alloc stuff"));
-
-
/*** Load default user pref files ***/
/* Initialize feature info */
strcpy(buf, "pref.prf");
/* Process that file */
- process_pref_file(buf);
+ 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(buf);
+ process_pref_file(player_ptr, buf, process_autopick_file_command);
note(_("[初期化終了]", "[Initialization complete]"));
}
+
/*!
* @brief タイトル記述
* @return なし
static void put_title(void)
{
char title[120];
- int col;
#if H_VER_EXTRA > 0
sprintf(title, _("変愚蛮怒 %d.%d.%d.%d(%s)", "Hengband %d.%d.%d.%d(%s)"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH, H_VER_EXTRA,
#else
sprintf(title, _("変愚蛮怒 %d.%d.%d(%s)", "Hengband %d.%d.%d(%s)"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH,
#endif
- IS_STABLE_VERSION ? _("安定版", "Stable") : _("開発版", "Developing"));
- col = (80 - strlen(title)) / 2;
+ IS_STABLE_VERSION ? _("安定版", "Stable") : _("開発版", "Developing"));
+ int col = (80 - strlen(title)) / 2;
col = col < 0 ? 0 : col;
prt(title, VER_INFO_ROW, col);
}
+
/*!
* @brief サムチェック情報を出力 / Get check sum in string form
* @return サムチェック情報の文字列
*/
concptr 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);
+ 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);
}
-