OSDN Git Service

[Refactor] #38997 calc_android_exp() に player_type * 引数を追加.
[hengband/hengband.git] / src / files.c
index 62fc3f3..1f4a655 100644 (file)
 
 #include "angband.h"
 #include "util.h"
+#include "files.h"
+#include "core.h"
 
 #include "birth.h"
 #include "files.h"
 
 #include "bldg.h"
 
+#include "cmd-magiceat.h"
+#include "cmd-dump.h"
 #include "world.h"
+#include "player-race.h"
 #include "player-status.h"
+#include "player-move.h"
+#include "player-class.h"
+#include "player-skill.h"
+#include "player-personality.h"
+#include "player-sex.h"
+#include "player-effects.h"
 #include "sort.h"
 #include "mutation.h"
 #include "quest.h"
 #include "artifact.h"
 #include "avatar.h"
 #include "shoot.h"
-#include "player-move.h"
 #include "patron.h"
 #include "monster.h"
 #include "monster-process.h"
 #include "monster-status.h"
 #include "object-flavor.h"
 #include "object-hook.h"
+#include "realm.h"
 #include "realm-hex.h"
 #include "cmd-pet.h"
 #include "spells.h"
 #include "term.h"
 #include "view-mainwindow.h"
 #include "floor-events.h"
+#include "floor-town.h"
 #include "dungeon-file.h"
 #include "init.h"
 #include "monster-spell.h"
-#include "player-skill.h"
 #include "floor.h"
 #include "dungeon.h"
 #include "melee.h"
+#include "objectkind.h"
+#include "autopick.h"
+#include "save.h"
+#include "realm-song.h"
+
+concptr ANGBAND_DIR; //!< Path name: The main "lib" directory This variable is not actually used anywhere in the code
+concptr ANGBAND_DIR_APEX; //!< High score files (binary) These files may be portable between platforms
+concptr ANGBAND_DIR_BONE; //!< Bone files for player ghosts (ascii) These files are portable between platforms
+concptr ANGBAND_DIR_DATA; //!< Binary image files for the "*_info" arrays (binary) These files are not portable between platforms
+concptr ANGBAND_DIR_EDIT; //!< Textual template files for the "*_info" arrays (ascii) These files are portable between platforms
+concptr ANGBAND_DIR_SCRIPT; //!< Script files These files are portable between platforms.
+concptr ANGBAND_DIR_FILE; //!< Various extra files (ascii) These files may be portable between platforms
+concptr ANGBAND_DIR_HELP; //!< Help files (normal) for the online help (ascii) These files are portable between platforms
+concptr ANGBAND_DIR_INFO; //!< Help files (spoilers) for the online help (ascii) These files are portable between platforms
+concptr ANGBAND_DIR_PREF; //!< Default user "preference" files (ascii) These files are rarely portable between platforms
+concptr ANGBAND_DIR_SAVE; //!< Savefiles for current characters (binary)
+concptr ANGBAND_DIR_USER; //!< User "preference" files (ascii) These files are rarely portable between platforms
+concptr ANGBAND_DIR_XTRA; //!< Various extra files (binary) These files are rarely portable between platforms
+
+s16b signal_count;             /* Hack -- Count interupts */
+
+/*
+ * Buffer to hold the current savefile name
+ * 'savefile' holds full path name. 'savefile_base' holds only base name.
+ */
+char savefile[1024];
+char savefile_base[40];
+
 
 
 /*
@@ -111,11 +150,11 @@ void safe_setuid_grab(void)
 
 #  ifdef SAFE_SETUID_POSIX
 
-       if (setuid(player_euid) != 0)
+       if (setuid(p_ptr->player_egid) != 0)
        {
                quit(_("setuid(): 正しく許可が取れません!", "setuid(): cannot set permissions correctly!"));
        }
-       if (setgid(player_egid) != 0)
+       if (setgid(p_ptr->player_egid) != 0)
        {
                quit(_("setgid(): 正しく許可が取れません!", "setgid(): cannot set permissions correctly!"));
        }
@@ -604,7 +643,7 @@ errr process_pref_file_command(char *buf)
                                        int os = option_info[i].o_set;
                                        int ob = option_info[i].o_bit;
 
-                                       if ((p_ptr->playing || character_xtra) &&
+                                       if ((p_ptr->playing || current_world_ptr->character_xtra) &&
                                                (OPT_PAGE_BIRTH == option_info[i].o_page) && !p_ptr->wizard)
                                        {
                                                msg_format(_("初期オプションは変更できません! '%s'", "Birth options can not changed! '%s'"), buf);
@@ -1235,8 +1274,6 @@ errr process_pref_file(concptr name)
        char buf[1024];
 
        errr err1, err2;
-
-       /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
 
        /* Process the system pref file */
@@ -1245,8 +1282,6 @@ errr process_pref_file(concptr name)
        /* Stop at parser errors, but not at non-existing file */
        if (err1 > 0) return err1;
 
-
-       /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
        
        /* Process the user pref file */
@@ -1331,8 +1366,6 @@ errr check_time_init(void)
 
        char    buf[1024];
 
-
-       /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "time.txt");
 
        /* Open the file */
@@ -1457,8 +1490,6 @@ errr check_load_init(void)
        char    temphost[MAXHOSTNAMELEN+1];
        char    thishost[MAXHOSTNAMELEN+1];
 
-
-       /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "load.txt");
 
        /* Open the "load" file */
@@ -2704,7 +2735,7 @@ static void tim_player_flags(BIT_FLAGS flgs[TR_FLAG_SIZE])
        if (IS_FAST() || p_ptr->slow)
                add_flag(flgs, TR_SPEED);
 
-       if (IS_OPPOSE_ACID() && !(p_ptr->special_defense & DEFENSE_ACID) && !(prace_is_(RACE_YEEK) && (p_ptr->lev > 19)))
+       if (IS_OPPOSE_ACID() && !(p_ptr->special_defense & DEFENSE_ACID) && !(PRACE_IS_(p_ptr, RACE_YEEK) && (p_ptr->lev > 19)))
                add_flag(flgs, TR_RES_ACID);
        if (IS_OPPOSE_ELEC() && !(p_ptr->special_defense & DEFENSE_ELEC))
                add_flag(flgs, TR_RES_ELEC);
@@ -2903,13 +2934,13 @@ static void player_immunity(BIT_FLAGS flgs[TR_FLAG_SIZE])
        for (i = 0; i < TR_FLAG_SIZE; i++)
                flgs[i] = 0L;
 
-       if (prace_is_(RACE_SPECTRE))
+       if (PRACE_IS_(p_ptr, RACE_SPECTRE))
                add_flag(flgs, TR_RES_NETHER);
-       if (p_ptr->mimic_form == MIMIC_VAMPIRE || prace_is_(RACE_VAMPIRE))
+       if (p_ptr->mimic_form == MIMIC_VAMPIRE || PRACE_IS_(p_ptr, RACE_VAMPIRE))
                add_flag(flgs, TR_RES_DARK);
        if (p_ptr->mimic_form == MIMIC_DEMON_LORD)
                add_flag(flgs, TR_RES_FIRE);
-       else if (prace_is_(RACE_YEEK) && p_ptr->lev > 19)
+       else if (PRACE_IS_(p_ptr, RACE_YEEK) && p_ptr->lev > 19)
                add_flag(flgs, TR_RES_ACID);
 }
 
@@ -2962,11 +2993,11 @@ static void player_vuln_flags(BIT_FLAGS flgs[TR_FLAG_SIZE])
                add_flag(flgs, TR_RES_FIRE);
                add_flag(flgs, TR_RES_COLD);
        }
-       if (prace_is_(RACE_ANDROID))
+       if (PRACE_IS_(p_ptr, RACE_ANDROID))
                add_flag(flgs, TR_RES_ELEC);
-       if (prace_is_(RACE_ENT))
+       if (PRACE_IS_(p_ptr, RACE_ENT))
                add_flag(flgs, TR_RES_FIRE);
-       if (prace_is_(RACE_VAMPIRE) || prace_is_(RACE_S_FAIRY) ||
+       if (PRACE_IS_(p_ptr, RACE_VAMPIRE) || PRACE_IS_(p_ptr, RACE_S_FAIRY) ||
            (p_ptr->mimic_form == MIMIC_VAMPIRE))
                add_flag(flgs, TR_RES_LITE);
 }
@@ -3055,12 +3086,12 @@ static void display_flag_aux(TERM_LEN row, TERM_LEN col, concptr header,
                }
                else if (flag1 == TR_LITE_1)
                {
-                       if (have_dark_flag(flgs))
+                       if (HAVE_DARK_FLAG(flgs))
                        {
                                c_put_str(TERM_L_DARK, "+", row, col);
                                header_color = TERM_WHITE;
                        }
-                       else if (have_lite_flag(flgs))
+                       else if (HAVE_LITE_FLAG(flgs))
                        {
                                c_put_str(TERM_WHITE, "+", row, col);
                                header_color = TERM_WHITE;
@@ -3575,7 +3606,7 @@ static void display_player_stat_info(void)
                if ((p_ptr->stat_max[i] > 18) && (p_ptr->stat_top[i] <= 18))
                        e_adj = p_ptr->stat_top[i] - (p_ptr->stat_max[i] - 19) / 10 - 19;
 
-               if (prace_is_(RACE_ENT))
+               if (PRACE_IS_(p_ptr, RACE_ENT))
                {
                        switch (i)
                        {
@@ -3975,7 +4006,7 @@ void display_player(int mode)
 #endif
                                }
                        }
-                       else if (character_dungeon)
+                       else if (current_world_ptr->character_dungeon)
                        {
                                if (!current_floor_ptr->dun_level)
                                {
@@ -4199,7 +4230,7 @@ static void dump_aux_pet(FILE *fff)
        bool pet_settings = FALSE;
        GAME_TEXT pet_name[MAX_NLEN];
 
-       for (i = m_max - 1; i >= 1; i--)
+       for (i = current_floor_ptr->m_max - 1; i >= 1; i--)
        {
                monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
@@ -5012,8 +5043,6 @@ errr file_character(concptr name)
        int             fd = -1;
        FILE            *fff = NULL;
        char            buf[1024];
-
-       /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
 
        /* File type is "TEXT" */
@@ -5261,22 +5290,14 @@ bool show_file(bool show_version, concptr name, concptr what, int line, BIT_FLAG
        Term_get_size(&wid, &hgt);
        rows = hgt - 4;
 
-       /* Wipe finder */
        strcpy(finder_str, "");
-
-       /* Wipe shower */
        strcpy(shower_str, "");
-
-       /* Wipe caption */
        strcpy(caption, "");
-
-       /* Wipe the hooks */
        for (i = 0; i < 68; i++)
        {
                hook[i][0] = '\0';
        }
 
-       /* Copy the filename */
        strcpy(filename, name);
 
        n = strlen(filename);
@@ -5295,7 +5316,6 @@ bool show_file(bool show_version, concptr name, concptr what, int line, BIT_FLAG
        /* Redirect the name */
        name = filename;
 
-       /* Hack */
        if (what)
        {
                /* Caption */
@@ -5313,8 +5333,6 @@ bool show_file(bool show_version, concptr name, concptr what, int line, BIT_FLAG
        {
                /* Caption */
                sprintf(caption, _("ヘルプ・ファイル'%s'", "Help file '%s'"), name);
-
-               /* Build the filename */
                path_build(path, sizeof(path), ANGBAND_DIR_HELP, name);
 
                /* Open the file */
@@ -5326,8 +5344,6 @@ bool show_file(bool show_version, concptr name, concptr what, int line, BIT_FLAG
        {
                /* Caption */
                sprintf(caption, _("スポイラー・ファイル'%s'", "Info file '%s'"), name);
-
-               /* Build the filename */
                path_build(path, sizeof(path), ANGBAND_DIR_INFO, name);
 
                /* Open the file */
@@ -5337,7 +5353,6 @@ bool show_file(bool show_version, concptr name, concptr what, int line, BIT_FLAG
        /* Look in "info" */
        if (!fff)
        {
-               /* Build the filename */
                path_build(path, sizeof(path), ANGBAND_DIR, name);
 
                for (i = 0; path[i]; i++)
@@ -5705,8 +5720,6 @@ bool show_file(bool show_version, concptr name, concptr what, int line, BIT_FLAG
 
                        if (!get_string(_("ファイル名: ", "File name: "), xtmp, 80)) continue;
                        my_fclose(fff);
-
-                       /* Build the filename */
                        path_build(buff, sizeof(buff), ANGBAND_DIR_USER, xtmp);
 
                        /* Hack -- Re-Open the file */
@@ -5783,7 +5796,7 @@ void process_player_name(bool sf)
        int i, k = 0;
        char old_player_base[32] = "";
 
-       if (character_generated) strcpy(old_player_base, player_base);
+       if (current_world_ptr->character_generated) strcpy(old_player_base, p_ptr->base_name);
 
        /* Cannot be too long */
 #if defined(MACINTOSH) || defined(ACORN)
@@ -5828,7 +5841,7 @@ void process_player_name(bool sf)
                if (c == '.') c = '_';
 
                /* Accept all the letters */
-               player_base[k++] = c;
+               p_ptr->base_name[k++] = c;
        }
 
 #else
@@ -5845,35 +5858,35 @@ void process_player_name(bool sf)
                /* Accept some letters */
 #ifdef JP
                if(iskanji(c)){
-                 if(k + 2 >= sizeof(player_base) || !p_ptr->name[i+1]) break;
-                 player_base[k++] = c;
+                 if(k + 2 >= sizeof(p_ptr->base_name) || !p_ptr->name[i+1]) break;
+                 p_ptr->base_name[k++] = c;
                  i++;
-                 player_base[k++] = p_ptr->name[i];
+                 p_ptr->base_name[k++] = p_ptr->name[i];
                }
 #ifdef SJIS
-               else if (iskana(c)) player_base[k++] = c;
+               else if (iskana(c)) p_ptr->base_name[k++] = c;
 #endif
                else
 #endif
                /* Convert path separator to underscore */
                if (!strncmp(PATH_SEP, p_ptr->name+i, strlen(PATH_SEP))){
-                       player_base[k++] = '_';
+                       p_ptr->base_name[k++] = '_';
                        i += strlen(PATH_SEP);
                }
                /* Convert some characters to underscore */
 #if defined(WINDOWS)
-               else if (my_strchr("\"*,/:;<>?\\|", c)) player_base[k++] = '_';
+               else if (my_strchr("\"*,/:;<>?\\|", c)) p_ptr->base_name[k++] = '_';
 #endif
-               else if (isprint(c)) player_base[k++] = c;
+               else if (isprint(c)) p_ptr->base_name[k++] = c;
        }
 
 #endif
 
        /* Terminate */
-       player_base[k] = '\0';
+       p_ptr->base_name[k] = '\0';
 
        /* Require a "base" name */
-       if (!player_base[0]) strcpy(player_base, "PLAYER");
+       if (!p_ptr->base_name[0]) strcpy(p_ptr->base_name, "PLAYER");
 
 
 #ifdef SAVEFILE_MUTABLE
@@ -5905,24 +5918,22 @@ void process_player_name(bool sf)
        {
                char temp[128];
 
-               strcpy(savefile_base, player_base);
+               strcpy(savefile_base, p_ptr->base_name);
 
 #ifdef SAVEFILE_USE_UID
-               /* Rename the savefile, using the player_uid and player_base */
-               (void)sprintf(temp, "%d.%s", player_uid, player_base);
+               /* Rename the savefile, using the p_ptr->player_uid and p_ptr->base_name */
+               (void)sprintf(temp, "%d.%s", p_ptr->player_uid, p_ptr->base_name);
 #else
-               /* Rename the savefile, using the player_base */
-               (void)sprintf(temp, "%s", player_base);
+               /* Rename the savefile, using the p_ptr->base_name */
+               (void)sprintf(temp, "%s", p_ptr->base_name);
 #endif
-
-               /* Build the filename */
                path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
        }
 
        /* Load an autopick preference file */
-       if (character_generated)
+       if (current_world_ptr->character_generated)
        {
-               if (!streq(old_player_base, player_base)) autopick_load_pref(FALSE);
+               if (!streq(old_player_base, p_ptr->base_name)) autopick_load_pref(FALSE);
        }
 }
 
@@ -6032,7 +6043,7 @@ void do_cmd_save_game(int is_autosave)
        (void)strcpy(p_ptr->died_from, _("(元気に生きている)", "(alive and well)"));
 
        /* HACK -- don't get sanity blast on updating view */
-       is_loading_now = FALSE;
+       current_world_ptr->is_loading_now = FALSE;
 
        update_creature(p_ptr);
 
@@ -6040,7 +6051,7 @@ void do_cmd_save_game(int is_autosave)
        mproc_init();
 
        /* HACK -- reset the hackish flag */
-       is_loading_now = TRUE;
+       current_world_ptr->is_loading_now = TRUE;
 }
 
 
@@ -6109,8 +6120,6 @@ static void make_bones(void)
 
                        /* "Bones" name */
                        sprintf(tmp, "bone.%03d", current_floor_ptr->dun_level);
-
-                       /* Build the filename */
                        path_build(str, sizeof(str), ANGBAND_DIR_BONE, tmp);
 
                        /* Attempt to open the bones file */
@@ -6187,8 +6196,6 @@ void print_tomb(void)
                int    extra_line = 0;
 #endif
                Term_clear();
-
-               /* Build the filename */
                path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("dead_j.txt", "dead.txt"));
 
                /* Open the News file */
@@ -6458,7 +6465,7 @@ void show_info(void)
        if (p_ptr->equip_cnt)
        {
                Term_clear();
-               (void)show_equip(0, USE_FULL);
+               (void)show_equip(0, USE_FULL, 0);
                prt(_("装備していたアイテム: -続く-", "You are using: -more-"), 0, 0);
 
                if (inkey() == ESCAPE) return;
@@ -6468,7 +6475,7 @@ void show_info(void)
        if (p_ptr->inven_cnt)
        {
                Term_clear();
-               (void)show_inven(0, USE_FULL);
+               (void)show_inven(0, USE_FULL, 0);
                prt(_("持っていたアイテム: -続く-", "You are carrying: -more-"), 0, 0);
 
                if (inkey() == ESCAPE) return;
@@ -6515,71 +6522,6 @@ void show_info(void)
        }
 }
 
-/*!
- * @brief スコアファイル出力
- * Display some character info
- * @return なし
- */
-bool check_score(void)
-{
-       Term_clear();
-
-       /* No score file */
-       if (highscore_fd < 0)
-       {
-               msg_print(_("スコア・ファイルが使用できません。", "Score file unavailable."));
-               msg_print(NULL);
-               return FALSE;
-       }
-
-#ifndef SCORE_WIZARDS
-       /* Wizard-mode pre-empts scoring */
-       if (p_ptr->noscore & 0x000F)
-       {
-               msg_print(_("ウィザード・モードではスコアが記録されません。", "Score not registered for wizards."));
-               msg_print(NULL);
-               return FALSE;
-       }
-#endif
-
-#ifndef SCORE_BORGS
-       /* Borg-mode pre-empts scoring */
-       if (p_ptr->noscore & 0x00F0)
-       {
-               msg_print(_("ボーグ・モードではスコアが記録されません。", "Score not registered for borgs."));
-               msg_print(NULL);
-               return FALSE;
-       }
-#endif
-
-#ifndef SCORE_CHEATERS
-       /* Cheaters are not scored */
-       if (p_ptr->noscore & 0xFF00)
-       {
-               msg_print(_("詐欺をやった人はスコアが記録されません。", "Score not registered for cheaters."));
-               msg_print(NULL);
-               return FALSE;
-       }
-#endif
-
-       /* Interupted */
-       if (!p_ptr->total_winner && streq(p_ptr->died_from, _("強制終了", "Interrupting")))
-       {
-               msg_print(_("強制終了のためスコアが記録されません。", "Score not registered due to interruption."));
-               msg_print(NULL);
-               return FALSE;
-       }
-
-       /* Quitter */
-       if (!p_ptr->total_winner && streq(p_ptr->died_from, _("途中終了", "Quitting")))
-       {
-               msg_print(_("途中終了のためスコアが記録されません。", "Score not registered due to quitting."));
-               msg_print(NULL);
-               return FALSE;
-       }
-       return TRUE;
-}
-
 
 /*!
  * @brief 異常発生時のゲーム緊急終了処理 /
@@ -6596,7 +6538,7 @@ bool check_score(void)
 void exit_game_panic(void)
 {
        /* If nothing important has happened, just quit */
-       if (!character_generated || character_saved) quit(_("緊急事態", "panic"));
+       if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(_("緊急事態", "panic"));
 
        /* Mega-Hack -- see "msg_print()" */
        msg_flag = FALSE;
@@ -6646,8 +6588,6 @@ errr get_rnd_line(concptr file_name, int entry, char *output)
        int     counter, test;
        int     line_num = 0;
 
-
-       /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, file_name);
 
        /* Open the file */
@@ -6775,8 +6715,6 @@ errr process_autopick_file(concptr name)
        char buf[1024];
 
        errr err = 0;
-
-       /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
 
        err = process_pref_file_aux(buf, PREF_TYPE_AUTOPICK);
@@ -6795,17 +6733,15 @@ errr process_histpref_file(concptr name)
 {
        char buf[1024];
        errr err = 0;
-       bool old_character_xtra = character_xtra;
-
-       /* Build the filename */
+       bool old_character_xtra = current_world_ptr->character_xtra;
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
 
        /* Hack -- prevent modification birth options in this file */
-       character_xtra = TRUE;
+       current_world_ptr->character_xtra = TRUE;
 
        err = process_pref_file_aux(buf, PREF_TYPE_HISTPREF);
 
-       character_xtra = old_character_xtra;
+       current_world_ptr->character_xtra = old_character_xtra;
        return (err);
 }
 
@@ -6825,7 +6761,7 @@ static errr counts_seek(int fd, u32b where, bool flag)
        int i;
 
 #ifdef SAVEFILE_USE_UID
-       (void)sprintf(temp1, "%d.%s.%d%d%d", player_uid, savefile_base, p_ptr->pclass, p_ptr->pseikaku, p_ptr->age);
+       (void)sprintf(temp1, "%d.%s.%d%d%d", p_ptr->player_uid, savefile_base, p_ptr->pclass, p_ptr->pseikaku, p_ptr->age);
 #else
        (void)sprintf(temp1, "%s.%d%d%d", savefile_base, p_ptr->pclass, p_ptr->pseikaku, p_ptr->age);
 #endif
@@ -7016,7 +6952,7 @@ static void handle_signal_simple(int sig)
 
 
        /* Nothing to save, just quit */
-       if (!character_generated || character_saved) quit(NULL);
+       if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(NULL);
 
 
        /* Count the signals */
@@ -7119,7 +7055,7 @@ static void handle_signal_abort(int sig)
 
 
        /* Nothing to save, just quit */
-       if (!character_generated || character_saved) quit(NULL);
+       if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(NULL);
 
 
        forget_lite();