OSDN Git Service

[Fix] #38997 wr_savefile_new() 内変数参照修正. / Fix variable references in wr_savefile_new().
[hengband/hengband.git] / src / save.c
index 711cf1d..18a9200 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"
 
 
 /*
@@ -474,7 +484,7 @@ 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;
@@ -512,11 +522,8 @@ static void wr_options(void)
                                /* Set */
                                option_flag[os] |= (1L << ob);
                        }
-
-                       /* Clear */
                        else
                        {
-                               /* Clear */
                                option_flag[os] &= ~(1L << ob);
                        }
                }
@@ -594,7 +601,7 @@ static void save_quick_start(void)
        wr_byte(0);
 
        /* No quick start after using debug mode or cheat options */
-       if (p_ptr->noscore) previous_char.quick_ok = FALSE;
+       if (current_world_ptr->noscore) previous_char.quick_ok = FALSE;
 
        wr_byte((byte)previous_char.quick_ok);
 }
@@ -604,73 +611,73 @@ static void save_quick_start(void)
  * @brief その他の情報を書き込む / Write some "extra" info
  * @return なし
  */
-static void wr_extra(void)
+static void wr_extra(player_type *creature_ptr)
 {
        int i,j;
        byte tmp8u;
 
-       wr_string(p_ptr->name);
-       wr_string(p_ptr->died_from);
-       wr_string(p_ptr->last_message ? p_ptr->last_message : "");
+       wr_string(creature_ptr->name);
+       wr_string(creature_ptr->died_from);
+       wr_string(creature_ptr->last_message ? creature_ptr->last_message : "");
 
        save_quick_start();
 
        for (i = 0; i < 4; i++)
        {
-               wr_string(p_ptr->history[i]);
+               wr_string(creature_ptr->history[i]);
        }
 
        /* Race/Class/Gender/Spells */
-       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((byte_hack)creature_ptr->prace);
+       wr_byte((byte_hack)creature_ptr->pclass);
+       wr_byte((byte_hack)creature_ptr->pseikaku);
+       wr_byte((byte_hack)creature_ptr->psex);
+       wr_byte((byte_hack)creature_ptr->realm1);
+       wr_byte((byte_hack)creature_ptr->realm2);
        wr_byte(0);
 
-       wr_byte((byte)p_ptr->hitdie);
-       wr_u16b(p_ptr->expfact);
+       wr_byte((byte)creature_ptr->hitdie);
+       wr_u16b(creature_ptr->expfact);
 
-       wr_s16b(p_ptr->age);
-       wr_s16b(p_ptr->ht);
-       wr_s16b(p_ptr->wt);
+       wr_s16b(creature_ptr->age);
+       wr_s16b(creature_ptr->ht);
+       wr_s16b(creature_ptr->wt);
 
        /* Dump the stats (maximum and current) */
-       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]);
+       for (i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max[i]);
+       for (i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max_max[i]);
+       for (i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_cur[i]);
 
        /* Ignore the transient stats */
        for (i = 0; i < 12; ++i) wr_s16b(0);
 
-       wr_u32b(p_ptr->au);
+       wr_u32b(creature_ptr->au);
 
-       wr_u32b(p_ptr->max_exp);
-       wr_u32b(p_ptr->max_max_exp);
-       wr_u32b(p_ptr->exp);
-       wr_u32b(p_ptr->exp_frac);
-       wr_s16b(p_ptr->lev);
+       wr_u32b(creature_ptr->max_exp);
+       wr_u32b(creature_ptr->max_max_exp);
+       wr_u32b(creature_ptr->exp);
+       wr_u32b(creature_ptr->exp_frac);
+       wr_s16b(creature_ptr->lev);
 
-       for (i = 0; i < 64; i++) wr_s16b(p_ptr->spell_exp[i]);
-       for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(p_ptr->weapon_exp[i][j]);
-       for (i = 0; i < GINOU_MAX; i++) wr_s16b(p_ptr->skill_exp[i]);
-       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]);
+       for (i = 0; i < 64; i++) wr_s16b(creature_ptr->spell_exp[i]);
+       for (i = 0; i < 5; i++) for (j = 0; j < 64; j++) wr_s16b(creature_ptr->weapon_exp[i][j]);
+       for (i = 0; i < GINOU_MAX; i++) wr_s16b(creature_ptr->skill_exp[i]);
+       for (i = 0; i < 108; i++) wr_s32b(creature_ptr->magic_num1[i]);
+       for (i = 0; i < 108; i++) wr_byte(creature_ptr->magic_num2[i]);
 
-       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);
+       wr_byte((byte_hack)creature_ptr->start_race);
+       wr_s32b(creature_ptr->old_race1);
+       wr_s32b(creature_ptr->old_race2);
+       wr_s16b(creature_ptr->old_realm);
 
        for (i = 0; i < MAX_MANE; i++)
        {
-               wr_s16b((s16b)p_ptr->mane_spell[i]);
-               wr_s16b((s16b)p_ptr->mane_dam[i]);
+               wr_s16b((s16b)creature_ptr->mane_spell[i]);
+               wr_s16b((s16b)creature_ptr->mane_dam[i]);
        }
-       wr_s16b(p_ptr->mane_num);
+       wr_s16b(creature_ptr->mane_num);
 
-       for (i = 0; i < MAX_KUBI; i++)
+       for (i = 0; i < MAX_BOUNTY; i++)
        {
                wr_s16b(current_world_ptr->bounty_r_idx[i]);
        }
@@ -681,33 +688,33 @@ static void wr_extra(void)
                wr_u32b(mon_odds[i]);
        }
 
-       wr_s16b(p_ptr->town_num); /* -KMW- */
+       wr_s16b(creature_ptr->town_num); /* -KMW- */
 
        /* Write arena and rewards information -KMW- */
-       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_byte(p_ptr->exit_bldg);
+       wr_s16b(creature_ptr->arena_number);
+       wr_s16b(creature_ptr->current_floor_ptr->inside_arena);
+       wr_s16b(creature_ptr->current_floor_ptr->inside_quest);
+       wr_s16b(creature_ptr->phase_out);
+       wr_byte(creature_ptr->exit_bldg);
        wr_byte(0); /* Unused */
 
-       wr_s16b((s16b)p_ptr->oldpx);
-       wr_s16b((s16b)p_ptr->oldpy);
+       wr_s16b((s16b)creature_ptr->oldpx);
+       wr_s16b((s16b)creature_ptr->oldpy);
 
-       /* Was number of p_ptr->rewards[] */
+       /* Was number of creature_ptr->rewards[] */
        wr_s16b(0);
 
-       wr_s32b(p_ptr->mhp);
-       wr_s32b(p_ptr->chp);
-       wr_u32b(p_ptr->chp_frac);
+       wr_s32b(creature_ptr->mhp);
+       wr_s32b(creature_ptr->chp);
+       wr_u32b(creature_ptr->chp_frac);
 
-       wr_s32b(p_ptr->msp);
-       wr_s32b(p_ptr->csp);
-       wr_u32b(p_ptr->csp_frac);
+       wr_s32b(creature_ptr->msp);
+       wr_s32b(creature_ptr->csp);
+       wr_u32b(creature_ptr->csp_frac);
 
        /* Max Player and Dungeon Levels */
-       wr_s16b(p_ptr->max_plv);
-       tmp8u = (byte)max_d_idx;
+       wr_s16b(creature_ptr->max_plv);
+       tmp8u = (byte)current_world_ptr->max_d_idx;
        wr_byte(tmp8u);
        for (i = 0; i < tmp8u; i++)
                wr_s16b((s16b)max_dlv[i]);
@@ -717,89 +724,89 @@ static void wr_extra(void)
        wr_s16b(0);
        wr_s16b(0);
        wr_s16b(0);
-       wr_s16b(p_ptr->sc);
-       wr_s16b(p_ptr->concent);
+       wr_s16b(creature_ptr->sc);
+       wr_s16b(creature_ptr->concent);
 
        wr_s16b(0);             /* old "rest" */
-       wr_s16b(p_ptr->blind);
-       wr_s16b(p_ptr->paralyzed);
-       wr_s16b(p_ptr->confused);
-       wr_s16b(p_ptr->food);
+       wr_s16b(creature_ptr->blind);
+       wr_s16b(creature_ptr->paralyzed);
+       wr_s16b(creature_ptr->confused);
+       wr_s16b(creature_ptr->food);
        wr_s16b(0);     /* old "food_digested" */
        wr_s16b(0);     /* old "protection" */
-       wr_s16b(p_ptr->energy_need);
-       wr_s16b(p_ptr->enchant_energy_need);
-       wr_s16b(p_ptr->fast);
-       wr_s16b(p_ptr->slow);
-       wr_s16b(p_ptr->afraid);
-       wr_s16b(p_ptr->cut);
-       wr_s16b(p_ptr->stun);
-       wr_s16b(p_ptr->poisoned);
-       wr_s16b(p_ptr->image);
-       wr_s16b(p_ptr->protevil);
-       wr_s16b(p_ptr->invuln);
-       wr_s16b(p_ptr->ult_res);
-       wr_s16b(p_ptr->hero);
-       wr_s16b(p_ptr->shero);
-       wr_s16b(p_ptr->shield);
-       wr_s16b(p_ptr->blessed);
-       wr_s16b(p_ptr->tim_invis);
-       wr_s16b(p_ptr->word_recall);
-       wr_s16b(p_ptr->recall_dungeon);
-       wr_s16b(p_ptr->alter_reality);
-       wr_s16b(p_ptr->see_infra);
-       wr_s16b(p_ptr->tim_infra);
-       wr_s16b(p_ptr->oppose_fire);
-       wr_s16b(p_ptr->oppose_cold);
-       wr_s16b(p_ptr->oppose_acid);
-       wr_s16b(p_ptr->oppose_elec);
-       wr_s16b(p_ptr->oppose_pois);
-       wr_s16b(p_ptr->tsuyoshi);
-       wr_s16b(p_ptr->tim_esp);
-       wr_s16b(p_ptr->wraith_form);
-       wr_s16b(p_ptr->resist_magic);
-       wr_s16b(p_ptr->tim_regen);
-       wr_s16b(p_ptr->kabenuke);
-       wr_s16b(p_ptr->tim_stealth);
-       wr_s16b(p_ptr->tim_levitation);
-       wr_s16b(p_ptr->tim_sh_touki);
-       wr_s16b(p_ptr->lightspeed);
-       wr_s16b(p_ptr->tsubureru);
-       wr_s16b(p_ptr->magicdef);
-       wr_s16b(p_ptr->tim_res_nether);
-       wr_s16b(p_ptr->tim_res_time);
-       wr_byte((byte)p_ptr->mimic_form);
-       wr_s16b(p_ptr->tim_mimic);
-       wr_s16b(p_ptr->tim_sh_fire);
-       wr_s16b(p_ptr->tim_sh_holy);
-       wr_s16b(p_ptr->tim_eyeeye);
+       wr_s16b(creature_ptr->energy_need);
+       wr_s16b(creature_ptr->enchant_energy_need);
+       wr_s16b(creature_ptr->fast);
+       wr_s16b(creature_ptr->slow);
+       wr_s16b(creature_ptr->afraid);
+       wr_s16b(creature_ptr->cut);
+       wr_s16b(creature_ptr->stun);
+       wr_s16b(creature_ptr->poisoned);
+       wr_s16b(creature_ptr->image);
+       wr_s16b(creature_ptr->protevil);
+       wr_s16b(creature_ptr->invuln);
+       wr_s16b(creature_ptr->ult_res);
+       wr_s16b(creature_ptr->hero);
+       wr_s16b(creature_ptr->shero);
+       wr_s16b(creature_ptr->shield);
+       wr_s16b(creature_ptr->blessed);
+       wr_s16b(creature_ptr->tim_invis);
+       wr_s16b(creature_ptr->word_recall);
+       wr_s16b(creature_ptr->recall_dungeon);
+       wr_s16b(creature_ptr->alter_reality);
+       wr_s16b(creature_ptr->see_infra);
+       wr_s16b(creature_ptr->tim_infra);
+       wr_s16b(creature_ptr->oppose_fire);
+       wr_s16b(creature_ptr->oppose_cold);
+       wr_s16b(creature_ptr->oppose_acid);
+       wr_s16b(creature_ptr->oppose_elec);
+       wr_s16b(creature_ptr->oppose_pois);
+       wr_s16b(creature_ptr->tsuyoshi);
+       wr_s16b(creature_ptr->tim_esp);
+       wr_s16b(creature_ptr->wraith_form);
+       wr_s16b(creature_ptr->resist_magic);
+       wr_s16b(creature_ptr->tim_regen);
+       wr_s16b(creature_ptr->kabenuke);
+       wr_s16b(creature_ptr->tim_stealth);
+       wr_s16b(creature_ptr->tim_levitation);
+       wr_s16b(creature_ptr->tim_sh_touki);
+       wr_s16b(creature_ptr->lightspeed);
+       wr_s16b(creature_ptr->tsubureru);
+       wr_s16b(creature_ptr->magicdef);
+       wr_s16b(creature_ptr->tim_res_nether);
+       wr_s16b(creature_ptr->tim_res_time);
+       wr_byte((byte)creature_ptr->mimic_form);
+       wr_s16b(creature_ptr->tim_mimic);
+       wr_s16b(creature_ptr->tim_sh_fire);
+       wr_s16b(creature_ptr->tim_sh_holy);
+       wr_s16b(creature_ptr->tim_eyeeye);
 
        /* by henkma */
-       wr_s16b(p_ptr->tim_reflect);
-       wr_s16b(p_ptr->multishadow);
-       wr_s16b(p_ptr->dustrobe);
+       wr_s16b(creature_ptr->tim_reflect);
+       wr_s16b(creature_ptr->multishadow);
+       wr_s16b(creature_ptr->dustrobe);
 
-       wr_s16b(p_ptr->chaos_patron);
-       wr_u32b(p_ptr->muta1);
-       wr_u32b(p_ptr->muta2);
-       wr_u32b(p_ptr->muta3);
+       wr_s16b(creature_ptr->chaos_patron);
+       wr_u32b(creature_ptr->muta1);
+       wr_u32b(creature_ptr->muta2);
+       wr_u32b(creature_ptr->muta3);
 
        for (i = 0; i<8; i++)
-               wr_s16b(p_ptr->virtues[i]);
+               wr_s16b(creature_ptr->virtues[i]);
        for (i = 0; i<8; i++)
-               wr_s16b(p_ptr->vir_types[i]);
-
-       wr_s16b(p_ptr->ele_attack);
-       wr_u32b(p_ptr->special_attack);
-       wr_s16b(p_ptr->ele_immune);
-       wr_u32b(p_ptr->special_defense);
-       wr_byte(p_ptr->knowledge);
-       wr_byte(p_ptr->autopick_autoregister);
+               wr_s16b(creature_ptr->vir_types[i]);
+
+       wr_s16b(creature_ptr->ele_attack);
+       wr_u32b(creature_ptr->special_attack);
+       wr_s16b(creature_ptr->ele_immune);
+       wr_u32b(creature_ptr->special_defense);
+       wr_byte(creature_ptr->knowledge);
+       wr_byte(creature_ptr->autopick_autoregister);
        wr_byte(0);
-       wr_byte((byte_hack)p_ptr->action);
+       wr_byte((byte_hack)creature_ptr->action);
        wr_byte(0);
        wr_byte(preserve_mode);
-       wr_byte(p_ptr->wait_report_score);
+       wr_byte(creature_ptr->wait_report_score);
 
        /* Future use */
        for (i = 0; i < 12; i++) wr_u32b(0L);
@@ -811,50 +818,50 @@ static void wr_extra(void)
 
 
        /* 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 */
-       wr_u16b(p_ptr->panic_save);
-       wr_u16b(p_ptr->total_winner);
-       wr_u16b(p_ptr->noscore);
+       wr_u16b(creature_ptr->panic_save);
+       wr_u16b(current_world_ptr->total_winner);
+       wr_u16b(current_world_ptr->noscore);
 
 
        /* Write death */
-       wr_byte(p_ptr->is_dead);
+       wr_byte(creature_ptr->is_dead);
 
        /* Write feeling */
-       wr_byte(p_ptr->feeling);
+       wr_byte(creature_ptr->feeling);
 
        /* Turn when level began */
-       wr_s32b(current_floor_ptr->generated_turn);
+       wr_s32b(creature_ptr->current_floor_ptr->generated_turn);
 
        /* Turn of last "feeling" */
-       wr_s32b(p_ptr->feeling_turn);
+       wr_s32b(creature_ptr->feeling_turn);
 
-       /* Current current_world_ptr->game_turn */
+       /* Current turn */
        wr_s32b(current_world_ptr->game_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);
-       wr_s16b(p_ptr->riding);
+       wr_s16b(creature_ptr->today_mon);
+       wr_s16b(creature_ptr->riding);
 
        /* Current floor_id */
-       wr_s16b(p_ptr->floor_id);
+       wr_s16b(creature_ptr->floor_id);
 
        /* Save temporary preserved pets (obsolated) */
        wr_s16b(0);
 
        wr_u32b(current_world_ptr->play_time);
 
-       wr_s32b(p_ptr->visit);
+       wr_s32b(creature_ptr->visit);
 
-       wr_u32b(p_ptr->count);
+       wr_u32b(creature_ptr->count);
 }
 
 
@@ -865,7 +872,7 @@ static void wr_extra(void)
  */
 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;
@@ -886,7 +893,7 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        {
                /*** Not a saved floor ***/
 
-               wr_s16b((s16b)current_floor_ptr->dun_level);
+               wr_s16b((s16b)p_ptr->current_floor_ptr->dun_level);
        }
        else
        {
@@ -901,12 +908,12 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
                wr_s16b(sf_ptr->lower_floor_id);
        }
 
-       wr_u16b((u16b)current_floor_ptr->base_level);
-       wr_u16b((s16b)current_floor_ptr->num_repro);
+       wr_u16b((u16b)p_ptr->current_floor_ptr->base_level);
+       wr_u16b((s16b)p_ptr->current_floor_ptr->num_repro);
        wr_u16b((u16b)p_ptr->y);
        wr_u16b((u16b)p_ptr->x);
-       wr_u16b((u16b)current_floor_ptr->height);
-       wr_u16b((u16b)current_floor_ptr->width);
+       wr_u16b((u16b)p_ptr->current_floor_ptr->height);
+       wr_u16b((u16b)p_ptr->current_floor_ptr->width);
        wr_byte(p_ptr->feeling);
 
 
@@ -928,14 +935,14 @@ 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 < current_floor_ptr->height; y++)
+       for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
        {
-               for (x = 0; x < current_floor_ptr->width; x++)
+               for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
                {
-                       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
+                       grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
                        for (i = 0; i < num_temp; i++)
                        {
@@ -956,12 +963,12 @@ 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;
                        }
 
@@ -988,7 +995,7 @@ 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((u16b)ct_ptr->info);
@@ -999,18 +1006,17 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
 
 
 
-       /*** "Run-Length-Encoding" of current_floor_ptr->grid_array ***/
+       /*** "Run-Length-Encoding" of floor ***/
 
        /* Note that this will induce two wasted bytes */
        count = 0;
        prev_u16b = 0;
 
-       /* Dump the current_floor_ptr->grid_array */
-       for (y = 0; y < current_floor_ptr->height; y++)
+       for (y = 0; y < p_ptr->current_floor_ptr->height; y++)
        {
-               for (x = 0; x < current_floor_ptr->width; x++)
+               for (x = 0; x < p_ptr->current_floor_ptr->width; x++)
                {
-                       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
+                       grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
                        for (i = 0; i < num_temp; i++)
                        {
@@ -1065,18 +1071,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(p_ptr->current_floor_ptr->o_max);
 
        /* Dump the objects */
-       for (i = 1; i < o_max; i++)
+       for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
        {
-               object_type *o_ptr = &current_floor_ptr->o_list[i];
+               object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[i];
 
                /* Dump it */
                wr_item(o_ptr);
@@ -1086,12 +1092,12 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        /*** Dump the monsters ***/
 
        /* Total monsters */
-       wr_u16b(m_max);
+       wr_u16b(p_ptr->current_floor_ptr->m_max);
 
        /* Dump the monsters */
-       for (i = 1; i < m_max; i++)
+       for (i = 1; i < p_ptr->current_floor_ptr->m_max; i++)
        {
-               monster_type *m_ptr = &current_floor_ptr->m_list[i];
+               monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[i];
 
                /* Dump it */
                wr_monster(m_ptr);
@@ -1102,16 +1108,17 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
 /*!
  * @brief 現在フロアの書き込み /
  * Write the current dungeon (new method)
- * @return なし
+ * @player_ptr プレーヤーへの参照ポインタ
+ * @return 保存に成功したらTRUE
  */
-static bool wr_dungeon(void)
+static bool wr_dungeon(player_type *player_ptr)
 {
        saved_floor_type *cur_sf_ptr;
        int i;
 
-       forget_lite();
-       forget_view();
-       clear_mon_lite();
+       forget_lite(p_ptr->current_floor_ptr);
+       forget_view(p_ptr->current_floor_ptr);
+       clear_mon_lite(p_ptr->current_floor_ptr);
 
        /* Update lite/view */
        p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
@@ -1174,7 +1181,7 @@ static bool wr_dungeon(void)
                if (!sf_ptr->floor_id) continue;
 
                /* Load temporal saved floor file */
-               if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
+               if (load_floor(player_ptr, sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
                {
                        /* Mark success */
                        wr_byte(0);
@@ -1190,7 +1197,7 @@ static bool wr_dungeon(void)
        }
 
        /* Restore current floor */
-       if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
+       if (!load_floor(player_ptr, cur_sf_ptr, (SLF_SECOND))) return FALSE;
 
        /* Success */
        return TRUE;
@@ -1200,9 +1207,10 @@ static bool wr_dungeon(void)
 /*!
  * @brief セーブデータの書き込み /
  * Actually write a save-file
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return 成功すればtrue
  */
-static bool wr_savefile_new(void)
+static bool wr_savefile_new(player_type *player_ptr)
 {
        int        i, j;
 
@@ -1216,7 +1224,7 @@ static bool wr_savefile_new(void)
        KIND_OBJECT_IDX k_idx;
 
        /* Compact the objects */
-       compact_objects(0);
+       compact_objects(player_ptr->current_floor_ptr, 0);
        /* Compact the monsters */
        compact_monsters(0);
 
@@ -1225,13 +1233,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 ***/
@@ -1261,17 +1269,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 */
@@ -1362,11 +1370,11 @@ static bool wr_savefile_new(void)
        }
 
        /* Dump the position in the wilderness */
-       wr_s32b(p_ptr->wilderness_x);
-       wr_s32b(p_ptr->wilderness_y);
+       wr_s32b(player_ptr->wilderness_x);
+       wr_s32b(player_ptr->wilderness_y);
 
-       wr_byte(p_ptr->wild_mode);
-       wr_byte(p_ptr->ambush_flag);
+       wr_byte(player_ptr->wild_mode);
+       wr_byte(player_ptr->ambush_flag);
 
        wr_s32b(current_world_ptr->max_wild_x);
        wr_s32b(current_world_ptr->max_wild_y);
@@ -1393,39 +1401,37 @@ static bool wr_savefile_new(void)
 
 
        /* Write the "extra" information */
-       wr_extra();
+       wr_extra(player_ptr);
 
        /* Dump the "player hp" entries */
        tmp16u = PY_MAX_LEVEL;
        wr_u16b(tmp16u);
        for (i = 0; i < tmp16u; i++)
        {
-               wr_s16b((s16b)p_ptr->player_hp[i]);
+               wr_s16b((s16b)player_ptr->player_hp[i]);
        }
 
 
        /* Write spell data */
-       wr_u32b(p_ptr->spell_learned1);
-       wr_u32b(p_ptr->spell_learned2);
-       wr_u32b(p_ptr->spell_worked1);
-       wr_u32b(p_ptr->spell_worked2);
-       wr_u32b(p_ptr->spell_forgotten1);
-       wr_u32b(p_ptr->spell_forgotten2);
+       wr_u32b(player_ptr->spell_learned1);
+       wr_u32b(player_ptr->spell_learned2);
+       wr_u32b(player_ptr->spell_worked1);
+       wr_u32b(player_ptr->spell_worked2);
+       wr_u32b(player_ptr->spell_forgotten1);
+       wr_u32b(player_ptr->spell_forgotten2);
 
-       wr_s16b(p_ptr->learned_spells);
-       wr_s16b(p_ptr->add_spells);
+       wr_s16b(player_ptr->learned_spells);
+       wr_s16b(player_ptr->add_spells);
 
        /* Dump the ordered spells */
        for (i = 0; i < 64; i++)
        {
-               wr_byte((byte_hack)p_ptr->spell_order[i]);
+               wr_byte((byte_hack)player_ptr->spell_order[i]);
        }
 
-
-       /* Write the p_ptr->inventory_list */
        for (i = 0; i < INVEN_TOTAL; i++)
        {
-               object_type *o_ptr = &p_ptr->inventory_list[i];
+               object_type *o_ptr = &player_ptr->inventory_list[i];
                if (!o_ptr->k_idx) continue;
 
                /* Dump index */
@@ -1456,11 +1462,11 @@ static bool wr_savefile_new(void)
        }
 
        /* Write the pet command settings */
-       wr_s16b(p_ptr->pet_follow_distance);
-       wr_s16b(p_ptr->pet_extra_flags);
+       wr_s16b(player_ptr->pet_follow_distance);
+       wr_s16b(player_ptr->pet_extra_flags);
 
        /* Write screen dump for sending score */
-       if (screen_dump && (p_ptr->wait_report_score || !p_ptr->is_dead))
+       if (screen_dump && (player_ptr->wait_report_score || !player_ptr->is_dead))
        {
                wr_string(screen_dump);
        }
@@ -1470,10 +1476,10 @@ static bool wr_savefile_new(void)
        }
 
        /* Player is not dead, write the dungeon */
-       if (!p_ptr->is_dead)
+       if (!player_ptr->is_dead)
        {
                /* Dump the dungeon */
-               if (!wr_dungeon()) return FALSE;
+               if (!wr_dungeon(player_ptr)) return FALSE;
 
                /* Dump the ghost */
                wr_ghost();
@@ -1501,11 +1507,12 @@ static bool wr_savefile_new(void)
 /*!
  * @brief セーブデータ書き込みのサブルーチン /
  * Medium level player saver
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return 成功すればtrue
  * @details
  * Angband 2.8.0 will use "fd" instead of "fff" if possible
  */
-static bool save_player_aux(char *name)
+static bool save_player_aux(player_type *player_ptr, char *name)
 {
        bool ok = FALSE;
        int fd = -1;
@@ -1545,7 +1552,7 @@ static bool save_player_aux(char *name)
                if (fff)
                {
                        /* Write the savefile */
-                       if (wr_savefile_new()) ok = TRUE;
+                       if (wr_savefile_new(player_ptr)) ok = TRUE;
 
                        /* Attempt to close it */
                        if (my_fclose(fff)) ok = FALSE;
@@ -1568,7 +1575,7 @@ static bool save_player_aux(char *name)
        counts_write(0, current_world_ptr->play_time);
 
        /* Successful save */
-       character_saved = TRUE;
+       current_world_ptr->character_saved = TRUE;
 
        /* Success */
        return (TRUE);
@@ -1579,9 +1586,10 @@ static bool save_player_aux(char *name)
 /*!
  * @brief セーブデータ書き込みのメインルーチン /
  * Attempt to save the player in a savefile
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @return 成功すればtrue
  */
-bool save_player(void)
+bool save_player(player_type *player_ptr)
 {
        bool result = FALSE;
 
@@ -1616,7 +1624,7 @@ bool save_player(void)
        update_playtime();
 
        /* Attempt to save the player */
-       if (save_player_aux(safe))
+       if (save_player_aux(player_ptr, safe))
        {
                char temp[1024];
 
@@ -1643,7 +1651,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
 
@@ -1704,7 +1712,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.
@@ -1825,10 +1833,10 @@ 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];
 
                Term_clear();
 
@@ -1840,7 +1848,7 @@ bool load_player(void)
        }
        if (!err)
        {
-               /* Invalid current_world_ptr->game_turn */
+               /* Invalid turn */
                if (!current_world_ptr->game_turn) err = -1;
 
                /* Message (below) */
@@ -1852,8 +1860,8 @@ 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))
                {
                        what = _("無効なタイム・スタンプです", "Invalid timestamp");
 
@@ -1866,18 +1874,18 @@ bool load_player(void)
        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
                        {
                                msg_format(_("バージョン %d.%d.%d 用のセーブ・ファイルを変換しました。", "Converted a %d.%d.%d savefile."),
-                                   (z_major > 9) ? z_major-10 : z_major , z_minor, z_patch);
+                                   (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);
                }
@@ -1889,7 +1897,7 @@ bool load_player(void)
                        if (arg_wizard)
                        {
                                /* A character was loaded */
-                               character_loaded = TRUE;
+                               current_world_ptr->character_loaded = TRUE;
                                return (TRUE);
                        }
 
@@ -1897,13 +1905,13 @@ bool load_player(void)
                        p_ptr->is_dead = FALSE;
 
                        /* Count lives */
-                       sf_lives++;
+                       current_world_ptr->sf_lives++;
 
                        return (TRUE);
                }
 
                /* A character was loaded */
-               character_loaded = TRUE;
+               current_world_ptr->character_loaded = TRUE;
 
                {
                        u32b tmp = counts_read(2);
@@ -1937,7 +1945,7 @@ bool load_player(void)
 #endif
 
        msg_format(_("エラー(%s)がバージョン%d.%d.%d 用セーブファイル読み込み中に発生。", "Error (%s) reading %d.%d.%d savefile."),
-               what, (z_major>9) ? z_major - 10 : z_major, z_minor, z_patch);
+               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);
 
        msg_print(NULL);
 
@@ -1996,7 +2004,7 @@ static bool save_floor_aux(saved_floor_type *sf_ptr)
        byte tmp8u;
 
        /* Compact the objects */
-       compact_objects(0);
+       compact_objects(p_ptr->current_floor_ptr, 0);
        /* Compact the monsters */
        compact_monsters(0);