OSDN Git Service

[Refactor] #37353 ウィザードモードフラグ を player_type 構造体から world_type 構造体へ移動.
[hengband/hengband.git] / src / save.c
index 8ff1894..44ad47a 100644 (file)
  */
 
 #include "angband.h"
-
+#include "util.h"
+#include "save.h"
+#include "load.h"
+#include "report.h"
+
+#include "core.h"
+#include "artifact.h"
+#include "sort.h"
+#include "dungeon.h"
+#include "quest.h"
+#include "store.h"
+#include "wild.h"
+#include "floor.h"
+#include "floor-events.h"
+#include "floor-save.h"
+#include "floor-town.h"
+#include "files.h"
+#include "world.h"
+#include "objectkind.h"
+#include "monsterrace.h"
+#include "birth.h"
+#include "bldg.h"
 
 
 /*
  * Some "local" parameters, used to help write savefiles
  */
 
-static FILE     *fff;           /* Current save "file" */
-
-static byte     xor_byte;       /* Simple encryption */
-
-static u32b     v_stamp = 0L;   /* A simple "checksum" on the actual values */
-static u32b     x_stamp = 0L;   /* A simple "checksum" on the encoded bytes */
+static FILE *fff;           /* Current save "file" */
+static byte xor_byte;       /* Simple encryption */
+static u32b v_stamp = 0L;   /* A simple "checksum" on the actual values */
+static u32b x_stamp = 0L;   /* A simple "checksum" on the encoded bytes */
 
 
 
@@ -103,7 +122,7 @@ static void wr_s32b(s32b v)
  * @param str 書き込む文字列
  * @return なし
  */
-static void wr_string(cptr str)
+static void wr_string(concptr str)
 {
        while (*str)
        {
@@ -126,7 +145,7 @@ static void wr_string(cptr str)
  */
 static void wr_item(object_type *o_ptr)
 {
-       u32b flags = 0x00000000;
+       BIT_FLAGS flags = 0x00000000;
 
        if (o_ptr->pval) flags |= SAVE_ITEM_PVAL;
        if (o_ptr->discount) flags |= SAVE_ITEM_DISCOUNT;
@@ -164,7 +183,6 @@ static void wr_item(object_type *o_ptr)
        /*** Write only un-obvious elements ***/
        wr_s16b(o_ptr->k_idx);
 
-       /* Location */
        wr_byte((byte_hack)o_ptr->iy);
        wr_byte((byte_hack)o_ptr->ix);
 
@@ -223,7 +241,7 @@ static void wr_item(object_type *o_ptr)
  */
 static void wr_monster(monster_type *m_ptr)
 {
-       u32b flags = 0x00000000;
+       BIT_FLAGS flags = 0x00000000;
        byte tmp8u;
 
        if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
@@ -262,7 +280,7 @@ static void wr_monster(monster_type *m_ptr)
        if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
        if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
 
-       wr_byte(m_ptr->mspeed);
+       wr_byte((byte)m_ptr->mspeed);
        wr_s16b(m_ptr->energy_need);
 
        if (flags & SAVE_MON_FAST)
@@ -352,7 +370,6 @@ static void wr_lore(MONRACE_IDX r_idx)
        wr_u32b(r_ptr->r_flags6);
        wr_u32b(r_ptr->r_flagsr);
 
-
        /* Monster limit per level */
        wr_byte((byte_hack)r_ptr->max_num);
 
@@ -382,7 +399,7 @@ static void wr_xtra(KIND_OBJECT_IDX k_idx)
 
 
 /*!
- * @brief 店舗情報を書き込む / Write a "store" record
+ * @brief セーブデータに店舗情報を書き込む / Write a "store" record
  * @param st_ptr 店舗情報の参照ポインタ
  * @return なし
  */
@@ -418,26 +435,20 @@ static void wr_store(store_type *st_ptr)
 
 
 /*!
- * @brief 乱数情報を書き込む / Write RNG state
- * @return なし
+ * @brief セーブデータに乱数情報を書き込む / Write RNG state
+ * @return 常に0(成功を返す) 
  */
 static errr wr_randomizer(void)
 {
        int i;
-
-       /* Zero */
        wr_u16b(0);
-
-       /* Place */
        wr_u16b(Rand_place);
 
-       /* State */
        for (i = 0; i < RAND_DEG; i++)
        {
                wr_u32b(Rand_state[i]);
        }
 
-       /* Success */
        return (0);
 }
 
@@ -455,7 +466,6 @@ static void wr_options(void)
 
        /*** Oops ***/
 
-       /* Oops */
        for (i = 0; i < 4; i++) wr_u32b(0L);
 
 
@@ -474,8 +484,9 @@ static void wr_options(void)
 
        c = 0;
 
-       if (p_ptr->wizard) c |= 0x0002;
+       if (current_world_ptr->wizard) c |= 0x0002;
 
+       if (cheat_sight) c |= 0x0040;
        if (cheat_turn) c |= 0x0080;
 
        if (cheat_peek) c |= 0x0100;
@@ -511,11 +522,8 @@ static void wr_options(void)
                                /* Set */
                                option_flag[os] |= (1L << ob);
                        }
-
-                       /* Clear */
                        else
                        {
-                               /* Clear */
                                option_flag[os] &= ~(1L << ob);
                        }
                }
@@ -566,9 +574,9 @@ static void save_quick_start(void)
        int i;
 
        wr_byte(previous_char.psex);
-       wr_byte(previous_char.prace);
-       wr_byte(previous_char.pclass);
-       wr_byte(previous_char.pseikaku);
+       wr_byte((byte_hack)previous_char.prace);
+       wr_byte((byte_hack)previous_char.pclass);
+       wr_byte((byte_hack)previous_char.pseikaku);
        wr_byte((byte_hack)previous_char.realm1);
        wr_byte((byte_hack)previous_char.realm2);
 
@@ -578,8 +586,8 @@ static void save_quick_start(void)
        wr_s16b(previous_char.sc);
        wr_s32b(previous_char.au);
 
-       for (i = 0; i < 6; i++) wr_s16b(previous_char.stat_max[i]);
-       for (i = 0; i < 6; i++) wr_s16b(previous_char.stat_max_max[i]);
+       for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
+       for (i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max_max[i]);
 
        for (i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
 
@@ -609,9 +617,7 @@ static void wr_extra(void)
        byte tmp8u;
 
        wr_string(p_ptr->name);
-
        wr_string(p_ptr->died_from);
-
        wr_string(p_ptr->last_message ? p_ptr->last_message : "");
 
        save_quick_start();
@@ -622,13 +628,13 @@ static void wr_extra(void)
        }
 
        /* Race/Class/Gender/Spells */
-       wr_byte(p_ptr->prace);
-       wr_byte(p_ptr->pclass);
-       wr_byte(p_ptr->pseikaku);
-       wr_byte(p_ptr->psex);
+       wr_byte((byte_hack)p_ptr->prace);
+       wr_byte((byte_hack)p_ptr->pclass);
+       wr_byte((byte_hack)p_ptr->pseikaku);
+       wr_byte((byte_hack)p_ptr->psex);
        wr_byte((byte_hack)p_ptr->realm1);
        wr_byte((byte_hack)p_ptr->realm2);
-       wr_byte(0);     /* oops */
+       wr_byte(0);
 
        wr_byte((byte)p_ptr->hitdie);
        wr_u16b(p_ptr->expfact);
@@ -638,9 +644,9 @@ static void wr_extra(void)
        wr_s16b(p_ptr->wt);
 
        /* Dump the stats (maximum and current) */
-       for (i = 0; i < 6; ++i) wr_s16b(p_ptr->stat_max[i]);
-       for (i = 0; i < 6; ++i) wr_s16b(p_ptr->stat_max_max[i]);
-       for (i = 0; i < 6; ++i) wr_s16b(p_ptr->stat_cur[i]);
+       for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max[i]);
+       for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_max_max[i]);
+       for (i = 0; i < A_MAX; ++i) wr_s16b(p_ptr->stat_cur[i]);
 
        /* Ignore the transient stats */
        for (i = 0; i < 12; ++i) wr_s16b(0);
@@ -659,7 +665,7 @@ static void wr_extra(void)
        for (i = 0; i < 108; i++) wr_s32b(p_ptr->magic_num1[i]);
        for (i = 0; i < 108; i++) wr_byte(p_ptr->magic_num2[i]);
 
-       wr_byte(p_ptr->start_race);
+       wr_byte((byte_hack)p_ptr->start_race);
        wr_s32b(p_ptr->old_race1);
        wr_s32b(p_ptr->old_race2);
        wr_s16b(p_ptr->old_realm);
@@ -673,7 +679,7 @@ static void wr_extra(void)
 
        for (i = 0; i < MAX_KUBI; i++)
        {
-               wr_s16b(kubi_r_idx[i]);
+               wr_s16b(current_world_ptr->bounty_r_idx[i]);
        }
 
        for (i = 0; i < 4; i++)
@@ -688,7 +694,7 @@ static void wr_extra(void)
        wr_s16b(p_ptr->arena_number);
        wr_s16b(p_ptr->inside_arena);
        wr_s16b(p_ptr->inside_quest);
-       wr_s16b(p_ptr->inside_battle);
+       wr_s16b(p_ptr->phase_out);
        wr_byte(p_ptr->exit_bldg);
        wr_byte(0); /* Unused */
 
@@ -714,10 +720,10 @@ static void wr_extra(void)
                wr_s16b((s16b)max_dlv[i]);
 
        /* More info */
-       wr_s16b(0);     /* oops */
-       wr_s16b(0);     /* oops */
-       wr_s16b(0);     /* oops */
-       wr_s16b(0);     /* oops */
+       wr_s16b(0);
+       wr_s16b(0);
+       wr_s16b(0);
+       wr_s16b(0);
        wr_s16b(p_ptr->sc);
        wr_s16b(p_ptr->concent);
 
@@ -796,7 +802,7 @@ static void wr_extra(void)
        wr_u32b(p_ptr->special_defense);
        wr_byte(p_ptr->knowledge);
        wr_byte(p_ptr->autopick_autoregister);
-       wr_byte(0);     /* oops */
+       wr_byte(0);
        wr_byte((byte_hack)p_ptr->action);
        wr_byte(0);
        wr_byte(preserve_mode);
@@ -806,14 +812,14 @@ static void wr_extra(void)
        for (i = 0; i < 12; i++) wr_u32b(0L);
 
        /* Ignore some flags */
-       wr_u32b(0L);    /* oops */
-       wr_u32b(0L);    /* oops */
-       wr_u32b(0L);    /* oops */
+       wr_u32b(0L);
+       wr_u32b(0L);
+       wr_u32b(0L);
 
 
        /* Write the "object seeds" */
-       wr_u32b(seed_flavor);
-       wr_u32b(seed_town);
+       wr_u32b(current_world_ptr->seed_flavor);
+       wr_u32b(current_world_ptr->seed_town);
 
 
        /* Special stuff */
@@ -829,17 +835,17 @@ static void wr_extra(void)
        wr_byte(p_ptr->feeling);
 
        /* Turn when level began */
-       wr_s32b(old_turn);
+       wr_s32b(current_floor_ptr->generated_turn);
 
        /* Turn of last "feeling" */
        wr_s32b(p_ptr->feeling_turn);
 
-       /* Current turn */
-       wr_s32b(turn);
+       /* Current current_world_ptr->game_turn */
+       wr_s32b(current_world_ptr->game_turn);
 
-       wr_s32b(dungeon_turn);
+       wr_s32b(current_world_ptr->dungeon_turn);
 
-       wr_s32b(old_battle);
+       wr_s32b(current_world_ptr->arena_start_turn);
 
        wr_s16b(today_mon);
        wr_s16b(p_ptr->today_mon);
@@ -851,7 +857,7 @@ static void wr_extra(void)
        /* Save temporary preserved pets (obsolated) */
        wr_s16b(0);
 
-       wr_u32b(playtime);
+       wr_u32b(current_world_ptr->play_time);
 
        wr_s32b(p_ptr->visit);
 
@@ -860,59 +866,13 @@ static void wr_extra(void)
 
 
 /*!
- * @brief フロア保存時のcave情報テンプレートをソートするための比較処理
- * @param u caveテンプレートの参照ポインタ
- * @param v 未使用
- * @param a スワップするモンスター種族のID1
- * @param b スワップするモンスター種族のID2
- * @return aの方が大きければtrue
- */
-static bool ang_sort_comp_cave_temp(vptr u, vptr v, int a, int b)
-{
-       cave_template_type *who = (cave_template_type *)(u);
-
-       u16b o1 = who[a].occurrence;
-       u16b o2 = who[b].occurrence;
-
-       /* Unused */
-       (void)v;
-
-       return o2 <= o1;
-}
-
-
-/*!
- * @brief フロア保存時のcave情報テンプレートをソートするためのスワップ処理 / Sorting hook -- Swap function
- * @param u caveテンプレートの参照ポインタ
- * @param v 未使用
- * @param a スワップするモンスター種族のID1
- * @param b スワップするモンスター種族のID2
- * @return なし
- */
-static void ang_sort_swap_cave_temp(vptr u, vptr v, int a, int b)
-{
-       cave_template_type *who = (cave_template_type *)(u);
-
-       cave_template_type holder;
-
-       /* Unused */
-       (void)v;
-
-       /* Swap */
-       holder = who[a];
-       who[a] = who[b];
-       who[b] = holder;
-}
-
-
-/*!
  * @brief 保存フロアの書き込み / Actually write a saved floor data using effectively compressed format.
  * @param sf_ptr 保存したいフロアの参照ポインタ
  * @return なし
  */
 static void wr_saved_floor(saved_floor_type *sf_ptr)
 {
-       cave_template_type *templates;
+       grid_template_type *templates;
        u16b max_num_temp;
        u16b num_temp = 0;
        int dummy_why;
@@ -933,14 +893,14 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        {
                /*** Not a saved floor ***/
 
-               wr_s16b((s16b)dun_level);
+               wr_s16b((s16b)current_floor_ptr->dun_level);
        }
        else
        {
                /*** The saved floor ***/
 
                wr_s16b(sf_ptr->floor_id);
-               wr_byte(sf_ptr->savefile_id);
+               wr_byte((byte_hack)sf_ptr->savefile_id);
                wr_s16b((s16b)sf_ptr->dun_level);
                wr_s32b(sf_ptr->last_visit);
                wr_u32b(sf_ptr->visit_mark);
@@ -948,17 +908,17 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
                wr_s16b(sf_ptr->lower_floor_id);
        }
 
-       wr_u16b((u16b)base_level);
-       wr_u16b(num_repro);
+       wr_u16b((u16b)current_floor_ptr->base_level);
+       wr_u16b((s16b)current_floor_ptr->num_repro);
        wr_u16b((u16b)p_ptr->y);
        wr_u16b((u16b)p_ptr->x);
-       wr_u16b((u16b)cur_hgt);
-       wr_u16b((u16b)cur_wid);
+       wr_u16b((u16b)current_floor_ptr->height);
+       wr_u16b((u16b)current_floor_ptr->width);
        wr_byte(p_ptr->feeling);
 
 
 
-       /*********** Make template for cave_type **********/
+       /*********** Make template for grid_type **********/
 
        /*
         * Usually number of templates are fewer than 255.  Even if
@@ -975,21 +935,21 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        max_num_temp = 255;
 
        /* Allocate the "template" array */
-       C_MAKE(templates, max_num_temp, cave_template_type);
+       C_MAKE(templates, max_num_temp, grid_template_type);
 
        /* Extract template array */
-       for (y = 0; y < cur_hgt; y++)
+       for (y = 0; y < current_floor_ptr->height; y++)
        {
-               for (x = 0; x < cur_wid; x++)
+               for (x = 0; x < current_floor_ptr->width; x++)
                {
-                       cave_type *c_ptr = &cave[y][x];
+                       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
 
                        for (i = 0; i < num_temp; i++)
                        {
-                               if (templates[i].info == c_ptr->info &&
-                                   templates[i].feat == c_ptr->feat &&
-                                   templates[i].mimic == c_ptr->mimic &&
-                                   templates[i].special == c_ptr->special)
+                               if (templates[i].info == g_ptr->info &&
+                                   templates[i].feat == g_ptr->feat &&
+                                   templates[i].mimic == g_ptr->mimic &&
+                                   templates[i].special == g_ptr->special)
                                {
                                        /* Same terrain is exist */
                                        templates[i].occurrence++;
@@ -1003,20 +963,20 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
                        /* If the max_num_temp is too small, increase it. */
                        if (num_temp >= max_num_temp)
                        {
-                               cave_template_type *old_template = templates;
+                               grid_template_type *old_template = templates;
 
                                /* Re-allocate the "template" array */
-                               C_MAKE(templates, max_num_temp + 255, cave_template_type);
-                               (void)C_COPY(templates, old_template, max_num_temp, cave_template_type);
-                               C_KILL(old_template, max_num_temp, cave_template_type);
+                               C_MAKE(templates, max_num_temp + 255, grid_template_type);
+                               (void)C_COPY(templates, old_template, max_num_temp, grid_template_type);
+                               C_KILL(old_template, max_num_temp, grid_template_type);
                                max_num_temp += 255;
                        }
 
                        /* Add new template */
-                       templates[num_temp].info = c_ptr->info;
-                       templates[num_temp].feat = c_ptr->feat;
-                       templates[num_temp].mimic = c_ptr->mimic;
-                       templates[num_temp].special = c_ptr->special;
+                       templates[num_temp].info = g_ptr->info;
+                       templates[num_temp].feat = g_ptr->feat;
+                       templates[num_temp].mimic = g_ptr->mimic;
+                       templates[num_temp].special = g_ptr->special;
                        templates[num_temp].occurrence = 1;
 
                        /* Increase number of template */
@@ -1024,13 +984,8 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
                }
        }
 
-       /* Select the sort method */
-       ang_sort_comp = ang_sort_comp_cave_temp;
-       ang_sort_swap = ang_sort_swap_cave_temp;
-
        /* Sort by occurrence */
-       ang_sort(templates, &dummy_why, num_temp);
-
+       ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
 
        /*** Dump templates ***/
 
@@ -1040,10 +995,10 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        /* Dump the templates */
        for (i = 0; i < num_temp; i++)
        {
-               cave_template_type *ct_ptr = &templates[i];
+               grid_template_type *ct_ptr = &templates[i];
 
                /* Dump it */
-               wr_u16b(ct_ptr->info);
+               wr_u16b((u16b)ct_ptr->info);
                wr_s16b(ct_ptr->feat);
                wr_s16b(ct_ptr->mimic);
                wr_s16b(ct_ptr->special);
@@ -1051,25 +1006,25 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
 
 
 
-       /*** "Run-Length-Encoding" of cave ***/
+       /*** "Run-Length-Encoding" of current_floor_ptr->grid_array ***/
 
        /* Note that this will induce two wasted bytes */
        count = 0;
        prev_u16b = 0;
 
-       /* Dump the cave */
-       for (y = 0; y < cur_hgt; y++)
+       /* Dump the current_floor_ptr->grid_array */
+       for (y = 0; y < current_floor_ptr->height; y++)
        {
-               for (x = 0; x < cur_wid; x++)
+               for (x = 0; x < current_floor_ptr->width; x++)
                {
-                       cave_type *c_ptr = &cave[y][x];
+                       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
 
                        for (i = 0; i < num_temp; i++)
                        {
-                               if (templates[i].info == c_ptr->info &&
-                                   templates[i].feat == c_ptr->feat &&
-                                   templates[i].mimic == c_ptr->mimic &&
-                                   templates[i].special == c_ptr->special)
+                               if (templates[i].info == g_ptr->info &&
+                                   templates[i].feat == g_ptr->feat &&
+                                   templates[i].mimic == g_ptr->mimic &&
+                                   templates[i].special == g_ptr->special)
                                        break;
                        }
 
@@ -1117,18 +1072,18 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
 
 
        /* Free the "template" array */
-       C_KILL(templates, max_num_temp, cave_template_type);
+       C_KILL(templates, max_num_temp, grid_template_type);
 
 
        /*** Dump objects ***/
 
        /* Total objects */
-       wr_u16b(o_max);
+       wr_u16b(current_floor_ptr->o_max);
 
        /* Dump the objects */
-       for (i = 1; i < o_max; i++)
+       for (i = 1; i < current_floor_ptr->o_max; i++)
        {
-               object_type *o_ptr = &o_list[i];
+               object_type *o_ptr = &current_floor_ptr->o_list[i];
 
                /* Dump it */
                wr_item(o_ptr);
@@ -1138,12 +1093,12 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        /*** Dump the monsters ***/
 
        /* Total monsters */
-       wr_u16b(m_max);
+       wr_u16b(current_floor_ptr->m_max);
 
        /* Dump the monsters */
-       for (i = 1; i < m_max; i++)
+       for (i = 1; i < current_floor_ptr->m_max; i++)
        {
-               monster_type *m_ptr = &m_list[i];
+               monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
                /* Dump it */
                wr_monster(m_ptr);
@@ -1161,29 +1116,21 @@ static bool wr_dungeon(void)
        saved_floor_type *cur_sf_ptr;
        int i;
 
-       /* Forget the lite */
        forget_lite();
-
-       /* Forget the view */
        forget_view();
-
-       /* Forget the view */
        clear_mon_lite();
 
        /* Update lite/view */
        p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
-
-       /* Update monsters */
        p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
 
-
        /*** Meta info ***/
 
        /* Number of floor_id used from birth */
        wr_s16b(max_floor_id);
 
        /* Current dungeon type */
-       wr_byte((byte_hack)dungeon_type);
+       wr_byte((byte_hack)p_ptr->dungeon_idx);
 
 
        /*** No saved floor (On the surface etc.) ***/
@@ -1211,7 +1158,7 @@ static bool wr_dungeon(void)
                saved_floor_type *sf_ptr = &saved_floors[i];
 
                wr_s16b(sf_ptr->floor_id);
-               wr_byte(sf_ptr->savefile_id);
+               wr_byte((byte_hack)sf_ptr->savefile_id);
                wr_s16b((s16b)sf_ptr->dun_level);
                wr_s32b(sf_ptr->last_visit);
                wr_u32b(sf_ptr->visit_mark);
@@ -1285,13 +1232,13 @@ static bool wr_savefile_new(void)
 
 
        /* Note the operating system */
-       sf_system = 0L;
+       current_world_ptr->sf_system = 0L;
 
        /* Note when the file was saved */
-       sf_when = now;
+       current_world_ptr->sf_when = now;
 
        /* Note the number of saves */
-       sf_saves++;
+       current_world_ptr->sf_saves++;
 
 
        /*** Actually write the file ***/
@@ -1321,17 +1268,17 @@ static bool wr_savefile_new(void)
        wr_byte(H_VER_MAJOR);
 
        /* Operating system */
-       wr_u32b(sf_system);
+       wr_u32b(current_world_ptr->sf_system);
 
 
        /* Time file last saved */
-       wr_u32b(sf_when);
+       wr_u32b(current_world_ptr->sf_when);
 
        /* Number of past lives */
-       wr_u16b(sf_lives);
+       wr_u16b(current_world_ptr->sf_lives);
 
        /* Number of times saved */
-       wr_u16b(sf_saves);
+       wr_u16b(current_world_ptr->sf_saves);
 
 
        /* Space */
@@ -1387,14 +1334,14 @@ static bool wr_savefile_new(void)
        wr_u16b(tmp16u);
 
        /* Dump the quests */
-       tmp16u = max_quests;
+       tmp16u = max_q_idx;
        wr_u16b(tmp16u);
 
        /* Dump the quests */
        tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
        wr_byte(tmp8u);
 
-       for (i = 0; i < max_quests; i++)
+       for (i = 0; i < max_q_idx; i++)
        {
                quest_type* const q_ptr = &quest[i];
 
@@ -1426,15 +1373,15 @@ static bool wr_savefile_new(void)
        wr_s32b(p_ptr->wilderness_y);
 
        wr_byte(p_ptr->wild_mode);
-       wr_byte(ambush_flag);
+       wr_byte(p_ptr->ambush_flag);
 
-       wr_s32b(max_wild_x);
-       wr_s32b(max_wild_y);
+       wr_s32b(current_world_ptr->max_wild_x);
+       wr_s32b(current_world_ptr->max_wild_y);
 
        /* Dump the wilderness seeds */
-       for (i = 0; i < max_wild_x; i++)
+       for (i = 0; i < current_world_ptr->max_wild_x; i++)
        {
-               for (j = 0; j < max_wild_y; j++)
+               for (j = 0; j < current_world_ptr->max_wild_y; j++)
                {
                        wr_u32b(wilderness[j][i].seed);
                }
@@ -1482,12 +1429,10 @@ static bool wr_savefile_new(void)
        }
 
 
-       /* Write the inventory */
+       /* Write the p_ptr->inventory_list */
        for (i = 0; i < INVEN_TOTAL; i++)
        {
-               object_type *o_ptr = &inventory[i];
-
-               /* Skip non-objects */
+               object_type *o_ptr = &p_ptr->inventory_list[i];
                if (!o_ptr->k_idx) continue;
 
                /* Dump index */
@@ -1513,7 +1458,7 @@ static bool wr_savefile_new(void)
        {
                for (j = 0; j < MAX_STORES; j++)
                {
-                       wr_store(&town[i].store[j]);
+                       wr_store(&town_info[i].store[j]);
                }
        }
 
@@ -1565,25 +1510,20 @@ static bool wr_savefile_new(void)
  * Medium level player saver
  * @return 成功すればtrue
  * @details
- * XXX XXX XXX Angband 2.8.0 will use "fd" instead of "fff" if possible
+ * Angband 2.8.0 will use "fd" instead of "fff" if possible
  */
 static bool save_player_aux(char *name)
 {
-       bool    ok = FALSE;
-
-       int             fd = -1;
-
-       int             mode = 0644;
-
+       bool ok = FALSE;
+       int fd = -1;
+       int mode = 0644;
 
        /* No file yet */
        fff = NULL;
 
-
        /* File type is "SAVE" */
        FILE_TYPE(FILE_TYPE_SAVE);
 
-
        /* Grab permissions */
        safe_setuid_grab();
 
@@ -1632,10 +1572,10 @@ static bool save_player_aux(char *name)
        /* Failure */
        if (!ok) return (FALSE);
 
-       counts_write(0, playtime);
+       counts_write(0, current_world_ptr->play_time);
 
        /* Successful save */
-       character_saved = TRUE;
+       current_world_ptr->character_saved = TRUE;
 
        /* Success */
        return (TRUE);
@@ -1710,7 +1650,7 @@ bool save_player(void)
                safe_setuid_drop();
 
                /* Hack -- Pretend the character was loaded */
-               character_loaded = TRUE;
+               current_world_ptr->character_loaded = TRUE;
 
 #ifdef VERIFY_SAVEFILE
 
@@ -1771,7 +1711,7 @@ bool save_player(void)
  * allowed to save his game when he quits.
  *
  * We return "TRUE" if the savefile was usable, and we set the global
- * flag "character_loaded" if a real, living, character was loaded.
+ * flag "current_world_ptr->character_loaded" if a real, living, character was loaded.
  *
  * Note that we always try to load the "current" savefile, even if
  * there is no such file, so we must check for "empty" savefile names.
@@ -1789,13 +1729,9 @@ bool load_player(void)
        struct stat     statbuf;
 #endif
 
-       cptr    what = "generic";
+       concptr    what = "generic";
 
-
-       /* Paranoia */
-       turn = 0;
-
-       /* Paranoia */
+       current_world_ptr->game_turn = 0;
        p_ptr->is_dead = FALSE;
 
 
@@ -1805,7 +1741,7 @@ bool load_player(void)
 
 #if !defined(MACINTOSH) && !defined(WINDOWS)
 
-       /* XXX XXX XXX Fix this */
+       /* Fix this */
 
        /* Verify the existance of the savefile */
        if (access(savefile, 0) < 0)
@@ -1841,14 +1777,11 @@ bool load_player(void)
                /* Oops, lock exists */
                if (fkk)
                {
-                       /* Close the file */
                        my_fclose(fkk);
 
-                       /* Message */
                        msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
                        msg_print(NULL);
 
-                       /* Oops */
                        return (FALSE);
                }
 
@@ -1865,7 +1798,6 @@ bool load_player(void)
 #endif
 
 
-       /* Okay */
        if (!err)
        {
                /* Open the savefile */
@@ -1892,8 +1824,6 @@ bool load_player(void)
 
                /* What */
                if (err) what = _("セーブファイルを読めません。", "Cannot read savefile");
-
-               /* Close the file */
                (void)fd_close(fd);
        }
 
@@ -1902,13 +1832,11 @@ bool load_player(void)
        {
 
                /* Extract version */
-               z_major = vvv[0];
-               z_minor = vvv[1];
-               z_patch = vvv[2];
-               sf_extra = vvv[3];
-
+               current_world_ptr->z_major = vvv[0];
+               current_world_ptr->z_minor = vvv[1];
+               current_world_ptr->z_patch = vvv[2];
+               current_world_ptr->sf_extra = vvv[3];
 
-               /* Clear screen */
                Term_clear();
 
                /* Attempt to load */
@@ -1917,12 +1845,10 @@ bool load_player(void)
                /* Message (below) */
                if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
        }
-
-       /* Paranoia */
        if (!err)
        {
-               /* Invalid turn */
-               if (!turn) err = -1;
+               /* Invalid current_world_ptr->game_turn */
+               if (!current_world_ptr->game_turn) err = -1;
 
                /* Message (below) */
                if (err) what = _("セーブファイルが壊れています", "Broken savefile");
@@ -1933,41 +1859,32 @@ bool load_player(void)
        if (!err && !arg_wizard)
        {
                /* Hack -- Verify the timestamp */
-               if (sf_when > (statbuf.st_ctime + 100) ||
-                   sf_when < (statbuf.st_ctime - 100))
+               if (current_world_ptr->sf_when > (statbuf.st_ctime + 100) ||
+                   current_world_ptr->sf_when < (statbuf.st_ctime - 100))
                {
-                       /* Message */
                        what = _("無効なタイム・スタンプです", "Invalid timestamp");
 
-                       /* Oops */
                        err = -1;
                }
        }
 #endif
 
 
-       /* Okay */
        if (!err)
        {
                /* Give a conversion warning */
-               if ((FAKE_VER_MAJOR != z_major) ||
-                   (FAKE_VER_MINOR != z_minor) ||
-                   (FAKE_VER_PATCH != z_patch))
+               if ((FAKE_VER_MAJOR != current_world_ptr->z_major) ||
+                   (FAKE_VER_MINOR != current_world_ptr->z_minor) ||
+                   (FAKE_VER_PATCH != current_world_ptr->z_patch))
                {
-                       if (z_major == 2 && z_minor == 0 && z_patch == 6)
+                       if (current_world_ptr->z_major == 2 && current_world_ptr->z_minor == 0 && current_world_ptr->z_patch == 6)
                        {
                                msg_print(_("バージョン 2.0.* 用のセーブファイルを変換しました。", "Converted a 2.0.* savefile."));
                        }
                        else
                        {
-                               /* Message */
-#ifdef JP
-                               msg_format("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。",
-                                   (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
-#else
-                               msg_format("Converted a %d.%d.%d savefile.",
-                                   (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
-#endif
+                               msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
+                                   (current_world_ptr->z_major > 9) ? current_world_ptr->z_major-10 : current_world_ptr->z_major , current_world_ptr->z_minor, current_world_ptr->z_patch);
                        }
                        msg_print(NULL);
                }
@@ -1979,9 +1896,7 @@ bool load_player(void)
                        if (arg_wizard)
                        {
                                /* A character was loaded */
-                               character_loaded = TRUE;
-
-                               /* Done */
+                               current_world_ptr->character_loaded = TRUE;
                                return (TRUE);
                        }
 
@@ -1989,22 +1904,21 @@ bool load_player(void)
                        p_ptr->is_dead = FALSE;
 
                        /* Count lives */
-                       sf_lives++;
+                       current_world_ptr->sf_lives++;
 
-                       /* Done */
                        return (TRUE);
                }
 
                /* A character was loaded */
-               character_loaded = TRUE;
+               current_world_ptr->character_loaded = TRUE;
 
                {
                        u32b tmp = counts_read(2);
                        if (tmp > p_ptr->count)
                                p_ptr->count = tmp;
-                       if (counts_read(0) > playtime || counts_read(1) == playtime)
+                       if (counts_read(0) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
                                counts_write(2, ++p_ptr->count);
-                       counts_write(1, playtime);
+                       counts_write(1, current_world_ptr->play_time);
                }
 
                /* Success */
@@ -2029,18 +1943,11 @@ bool load_player(void)
 
 #endif
 
+       msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
+               what, (current_world_ptr->z_major>9) ? current_world_ptr->z_major - 10 : current_world_ptr->z_major, current_world_ptr->z_minor, current_world_ptr->z_patch);
 
-       /* Message */
-#ifdef JP
-       msg_format("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。",
-                  what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
-#else
-       msg_format("Error (%s) reading %d.%d.%d savefile.",
-                  what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
-#endif
        msg_print(NULL);
 
-       /* Oops */
        return (FALSE);
 }