OSDN Git Service

[Refactor] #39970 Moved dungeon*.c/h to dungeon/
[hengband/hengband.git] / src / save.c
index 6f83675..01355e2 100644 (file)
  */
 
 #include "angband.h"
+#include "util.h"
+#include "save.h"
+#include "load.h"
+#include "report.h"
+
+#include "core/angband-version.h"
+#include "artifact.h"
 #include "sort.h"
+#include "dungeon/dungeon.h"
 #include "quest.h"
-#include "store.h"
+#include "market/store.h"
+#include "market/store-util.h"
 #include "wild.h"
+#include "floor.h"
 #include "floor-events.h"
 #include "floor-save.h"
+#include "floor-town.h"
+#include "io/uid-checker.h"
 #include "files.h"
+#include "world/world.h"
+#include "object/object-kind.h"
+#include "monsterrace.h"
+#include "birth/birth.h"
+#include "market/building.h"
+#include "view/display-main-window.h"
 
-
-
-/*
- * Some "local" parameters, used to help write savefiles
- */
+ /*
+  * 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 */
 
-
-
 /*!
  * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
  * @param v 書き込むバイト値
@@ -49,6 +63,7 @@ static void sf_put(byte v)
        x_stamp += xor_byte;
 }
 
+
 /*!
  * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
  * @param v 書き込むバイト
@@ -59,6 +74,7 @@ static void wr_byte(byte v)
        sf_put(v);
 }
 
+
 /*!
  * @brief 符号なし16ビットをファイルに書き込む
  * @param v 書き込む符号なし16bit値
@@ -70,6 +86,7 @@ static void wr_u16b(u16b v)
        sf_put((byte)((v >> 8) & 0xFF));
 }
 
+
 /*!
  * @brief 符号あり16ビットをファイルに書き込む
  * @param v 書き込む符号あり16bit値
@@ -80,6 +97,7 @@ static void wr_s16b(s16b v)
        wr_u16b((u16b)v);
 }
 
+
 /*!
  * @brief 符号なし32ビットをファイルに書き込む
  * @param v 書き込む符号なし32bit値
@@ -93,6 +111,7 @@ static void wr_u32b(u32b v)
        sf_put((byte)((v >> 24) & 0xFF));
 }
 
+
 /*!
  * @brief 符号あり32ビットをファイルに書き込む
  * @param v 書き込む符号あり32bit値
@@ -103,6 +122,7 @@ static void wr_s32b(s32b v)
        wr_u32b((u32b)v);
 }
 
+
 /*!
  * @brief 文字列をファイルに書き込む
  * @param str 書き込む文字列
@@ -124,11 +144,11 @@ static void wr_string(concptr str)
  */
 
 
-/*!
- * @brief アイテムオブジェクトを書き込む / Write an "item" record
- * @param o_ptr アイテムオブジェクト保存元ポインタ
- * @return なし
- */
+ /*!
 * @brief アイテムオブジェクトを書き込む / Write an "item" record
 * @param o_ptr アイテムオブジェクト保存元ポインタ
 * @return なし
 */
 static void wr_item(object_type *o_ptr)
 {
        BIT_FLAGS flags = 0x00000000;
@@ -169,26 +189,26 @@ static void wr_item(object_type *o_ptr)
        /*** Write only un-obvious elements ***/
        wr_s16b(o_ptr->k_idx);
 
-       wr_byte((byte_hack)o_ptr->iy);
-       wr_byte((byte_hack)o_ptr->ix);
+       wr_byte((byte)o_ptr->iy);
+       wr_byte((byte)o_ptr->ix);
 
        if (flags & SAVE_ITEM_PVAL) wr_s16b(o_ptr->pval);
 
        if (flags & SAVE_ITEM_DISCOUNT) wr_byte(o_ptr->discount);
-       if (flags & SAVE_ITEM_NUMBER) wr_byte((byte_hack)o_ptr->number);
+       if (flags & SAVE_ITEM_NUMBER) wr_byte((byte)o_ptr->number);
 
        wr_s16b((s16b)o_ptr->weight);
 
-       if (flags & SAVE_ITEM_NAME1) wr_byte((byte_hack)o_ptr->name1);
-       if (flags & SAVE_ITEM_NAME2) wr_byte((byte_hack)o_ptr->name2);
+       if (flags & SAVE_ITEM_NAME1) wr_byte((byte)o_ptr->name1);
+       if (flags & SAVE_ITEM_NAME2) wr_byte((byte)o_ptr->name2);
        if (flags & SAVE_ITEM_TIMEOUT) wr_s16b(o_ptr->timeout);
 
        if (flags & SAVE_ITEM_TO_H) wr_s16b(o_ptr->to_h);
        if (flags & SAVE_ITEM_TO_D) wr_s16b((s16b)o_ptr->to_d);
        if (flags & SAVE_ITEM_TO_A) wr_s16b(o_ptr->to_a);
        if (flags & SAVE_ITEM_AC) wr_s16b(o_ptr->ac);
-       if (flags & SAVE_ITEM_DD) wr_byte((byte_hack)o_ptr->dd);
-       if (flags & SAVE_ITEM_DS) wr_byte((byte_hack)o_ptr->ds);
+       if (flags & SAVE_ITEM_DD) wr_byte((byte)o_ptr->dd);
+       if (flags & SAVE_ITEM_DS) wr_byte((byte)o_ptr->ds);
 
        if (flags & SAVE_ITEM_IDENT) wr_byte(o_ptr->ident);
 
@@ -228,8 +248,6 @@ static void wr_item(object_type *o_ptr)
 static void wr_monster(monster_type *m_ptr)
 {
        BIT_FLAGS flags = 0x00000000;
-       byte tmp8u;
-
        if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
        if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
        if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
@@ -252,13 +270,12 @@ static void wr_monster(monster_type *m_ptr)
 
        /*** Write only un-obvious elements ***/
        wr_s16b(m_ptr->r_idx);
-       wr_byte((byte_hack)m_ptr->fy);
-       wr_byte((byte_hack)m_ptr->fx);
+       wr_byte((byte)m_ptr->fy);
+       wr_byte((byte)m_ptr->fx);
        wr_s16b((s16b)m_ptr->hp);
        wr_s16b((s16b)m_ptr->maxhp);
        wr_s16b((s16b)m_ptr->max_maxhp);
        wr_u32b(m_ptr->dealt_damage);
-       
 
        /* Monster race index of its appearance */
        if (flags & SAVE_MON_AP_R_IDX) wr_s16b(m_ptr->ap_r_idx);
@@ -269,6 +286,7 @@ static void wr_monster(monster_type *m_ptr)
        wr_byte((byte)m_ptr->mspeed);
        wr_s16b(m_ptr->energy_need);
 
+       byte tmp8u;
        if (flags & SAVE_MON_FAST)
        {
                tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
@@ -316,9 +334,8 @@ static void wr_monster(monster_type *m_ptr)
  */
 static void wr_lore(MONRACE_IDX r_idx)
 {
-       monster_race *r_ptr = &r_info[r_idx];
-
        /* Count sights/deaths/kills */
+       monster_race *r_ptr = &r_info[r_idx];
        wr_s16b((s16b)r_ptr->r_sights);
        wr_s16b((s16b)r_ptr->r_deaths);
        wr_s16b((s16b)r_ptr->r_pkills);
@@ -334,8 +351,8 @@ static void wr_lore(MONRACE_IDX r_idx)
        wr_byte(r_ptr->r_xtra2);
 
        /* Count drops */
-       wr_byte((byte_hack)r_ptr->r_drop_gold);
-       wr_byte((byte_hack)r_ptr->r_drop_item);
+       wr_byte((byte)r_ptr->r_drop_gold);
+       wr_byte((byte)r_ptr->r_drop_item);
 
        /* Count spells */
        wr_byte(0); /* unused now */
@@ -357,15 +374,15 @@ static void wr_lore(MONRACE_IDX r_idx)
        wr_u32b(r_ptr->r_flagsr);
 
        /* Monster limit per level */
-       wr_byte((byte_hack)r_ptr->max_num);
+       wr_byte((byte)r_ptr->max_num);
 
        /* Location in saved floor */
        wr_s16b(r_ptr->floor_id);
 
-       /* Later (?) */
        wr_byte(0);
 }
 
+
 /*!
  * @brief その他のゲーム情報を書き込む(実質はアイテムの鑑定情報のみ) / Write an "xtra" record
  * @param k_idx ベースアイテムのID
@@ -386,56 +403,53 @@ static void wr_xtra(KIND_OBJECT_IDX k_idx)
 
 /*!
  * @brief セーブデータに店舗情報を書き込む / Write a "store" record
- * @param st_ptr 店舗情報の参照ポインタ
+ * @param store_ptr 店舗情報の参照ポインタ
  * @return なし
  */
-static void wr_store(store_type *st_ptr)
+static void wr_store(store_type *store_ptr)
 {
-       int j;
-
        /* Save the "open" counter */
-       wr_u32b(st_ptr->store_open);
+       wr_u32b(store_ptr->store_open);
 
        /* Save the "insults" */
-       wr_s16b(st_ptr->insult_cur);
+       wr_s16b(store_ptr->insult_cur);
 
        /* Save the current owner */
-       wr_byte(st_ptr->owner);
+       wr_byte(store_ptr->owner);
 
        /* Save the stock size */
-       wr_s16b(st_ptr->stock_num);
+       wr_s16b(store_ptr->stock_num);
 
        /* Save the "haggle" info */
-       wr_s16b(st_ptr->good_buy);
-       wr_s16b(st_ptr->bad_buy);
+       wr_s16b(store_ptr->good_buy);
+       wr_s16b(store_ptr->bad_buy);
 
-       wr_s32b(st_ptr->last_visit);
+       wr_s32b(store_ptr->last_visit);
 
        /* Save the stock */
-       for (j = 0; j < st_ptr->stock_num; j++)
+       for (int j = 0; j < store_ptr->stock_num; j++)
        {
                /* Save each item in stock */
-               wr_item(&st_ptr->stock[j]);
+               wr_item(&store_ptr->stock[j]);
        }
 }
 
 
 /*!
  * @brief セーブデータに乱数情報を書き込む / Write RNG state
- * @return 常に0(成功を返す) 
+ * @return 常に0(成功を返す)
  */
 static errr wr_randomizer(void)
 {
-       int i;
        wr_u16b(0);
        wr_u16b(Rand_place);
 
-       for (i = 0; i < RAND_DEG; i++)
+       for (int i = 0; i < RAND_DEG; i++)
        {
                wr_u32b(Rand_state[i]);
        }
 
-       return (0);
+       return 0;
 }
 
 
@@ -445,18 +459,9 @@ static errr wr_randomizer(void)
  */
 static void wr_options(void)
 {
-       int i;
-
-       u16b c;
-
-
-       /*** Oops ***/
-
-       for (i = 0; i < 4; i++) wr_u32b(0L);
-
-
-       /*** Special Options ***/
+       for (int i = 0; i < 4; i++) wr_u32b(0L);
 
+       /*** Special options ***/
        /* Write "delay_factor" */
        wr_byte(delay_factor);
 
@@ -468,9 +473,8 @@ static void wr_options(void)
 
        /*** Cheating options ***/
 
-       c = 0;
-
-       if (p_ptr->wizard) c |= 0x0002;
+       u16b c = 0;
+       if (current_world_ptr->wizard) c |= 0x0002;
 
        if (cheat_sight) c |= 0x0040;
        if (cheat_turn) c |= 0x0080;
@@ -492,49 +496,38 @@ static void wr_options(void)
        wr_s16b(autosave_freq);
 
        /*** Extract options ***/
-
        /* Analyze 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;
 
                /* Process real entries */
-               if (option_info[i].o_var)
-               {
-                       /* Set */
-                       if (*option_info[i].o_var)
-                       {
-                               /* Set */
-                               option_flag[os] |= (1L << ob);
-                       }
+               if (!option_info[i].o_var) continue;
 
-                       /* Clear */
-                       else
-                       {
-                               /* Clear */
-                               option_flag[os] &= ~(1L << ob);
-                       }
+               if (*option_info[i].o_var)
+               {
+                       option_flag[os] |= (1L << ob);
+               }
+               else
+               {
+                       option_flag[os] &= ~(1L << ob);
                }
        }
 
-
        /*** Normal options ***/
-
        /* Dump the flags */
-       for (i = 0; i < 8; i++) wr_u32b(option_flag[i]);
+       for (int i = 0; i < 8; i++) wr_u32b(option_flag[i]);
 
        /* Dump the masks */
-       for (i = 0; i < 8; i++) wr_u32b(option_mask[i]);
-
+       for (int i = 0; i < 8; i++) wr_u32b(option_mask[i]);
 
        /*** Window options ***/
-
        /* Dump the flags */
-       for (i = 0; i < 8; i++) wr_u32b(window_flag[i]);
+       for (int i = 0; i < 8; i++) wr_u32b(window_flag[i]);
 
        /* Dump the masks */
-       for (i = 0; i < 8; i++) wr_u32b(window_mask[i]);
+       for (int i = 0; i < 8; i++) wr_u32b(window_mask[i]);
 }
 
 
@@ -544,13 +537,10 @@ static void wr_options(void)
  */
 static void wr_ghost(void)
 {
-       int i;
-
-       /* Name */
        wr_string(_("不正なゴースト", "Broken Ghost"));
 
        /* Hack -- stupid data */
-       for (i = 0; i < 60; i++) wr_byte(0);
+       for (int i = 0; i < 60; i++) wr_byte(0);
 }
 
 
@@ -560,14 +550,12 @@ static void wr_ghost(void)
  */
 static void save_quick_start(void)
 {
-       int i;
-
        wr_byte(previous_char.psex);
-       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);
+       wr_byte((byte)previous_char.prace);
+       wr_byte((byte)previous_char.pclass);
+       wr_byte((byte)previous_char.pseikaku);
+       wr_byte((byte)previous_char.realm1);
+       wr_byte((byte)previous_char.realm2);
 
        wr_s16b(previous_char.age);
        wr_s16b(previous_char.ht);
@@ -575,22 +563,22 @@ static void save_quick_start(void)
        wr_s16b(previous_char.sc);
        wr_s32b(previous_char.au);
 
-       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 (int i = 0; i < A_MAX; i++) wr_s16b(previous_char.stat_max[i]);
+       for (int 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]);
+       for (int i = 0; i < PY_MAX_LEVEL; i++) wr_s16b((s16b)previous_char.player_hp[i]);
 
        wr_s16b(previous_char.chaos_patron);
 
-       for (i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
+       for (int i = 0; i < 8; i++) wr_s16b(previous_char.vir_types[i]);
 
-       for (i = 0; i < 4; i++) wr_string(previous_char.history[i]);
+       for (int i = 0; i < 4; i++) wr_string(previous_char.history[i]);
 
        /* UNUSED : Was number of random quests */
        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);
 }
@@ -600,112 +588,113 @@ 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++)
+       for (int 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)creature_ptr->prace);
+       wr_byte((byte)creature_ptr->pclass);
+       wr_byte((byte)creature_ptr->pseikaku);
+       wr_byte((byte)creature_ptr->psex);
+       wr_byte((byte)creature_ptr->realm1);
+       wr_byte((byte)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 (int i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max[i]);
+       for (int i = 0; i < A_MAX; ++i) wr_s16b(creature_ptr->stat_max_max[i]);
+       for (int 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);
+       for (int i = 0; i < 12; ++i) wr_s16b(0);
+
+       wr_u32b(creature_ptr->au);
 
-       wr_u32b(p_ptr->au);
+       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);
 
-       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);
+       for (int i = 0; i < 64; i++) wr_s16b(creature_ptr->spell_exp[i]);
+       for (int i = 0; i < 5; i++)
+               for (int j = 0; j < 64; j++)
+                       wr_s16b(creature_ptr->weapon_exp[i][j]);
 
-       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 (int i = 0; i < GINOU_MAX; i++) wr_s16b(creature_ptr->skill_exp[i]);
+       for (int i = 0; i < 108; i++) wr_s32b(creature_ptr->magic_num1[i]);
+       for (int 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)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++)
+       for (int 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);
 
-       for (i = 0; i < MAX_KUBI; i++)
+       wr_s16b(creature_ptr->mane_num);
+
+       for (int i = 0; i < MAX_BOUNTY; i++)
        {
                wr_s16b(current_world_ptr->bounty_r_idx[i]);
        }
 
-       for (i = 0; i < 4; i++)
+       for (int i = 0; i < 4; i++)
        {
                wr_s16b(battle_mon[i]);
                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);
+       byte tmp8u = (byte)current_world_ptr->max_d_idx;
        wr_byte(tmp8u);
-       for (i = 0; i < tmp8u; i++)
+       for (int i = 0; i < tmp8u; i++)
                wr_s16b((s16b)max_dlv[i]);
 
        /* More info */
@@ -713,144 +702,139 @@ 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(p_ptr->chaos_patron);
-       wr_u32b(p_ptr->muta1);
-       wr_u32b(p_ptr->muta2);
-       wr_u32b(p_ptr->muta3);
-
-       for (i = 0; i<8; i++)
-               wr_s16b(p_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->tim_reflect);
+       wr_s16b(creature_ptr->multishadow);
+       wr_s16b(creature_ptr->dustrobe);
+
+       wr_s16b(creature_ptr->chaos_patron);
+       wr_u32b(creature_ptr->muta1);
+       wr_u32b(creature_ptr->muta2);
+       wr_u32b(creature_ptr->muta3);
+
+       for (int i = 0; i < 8; i++)
+               wr_s16b(creature_ptr->virtues[i]);
+       for (int i = 0; i < 8; i++)
+               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)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);
+       for (int i = 0; i < 12; i++) wr_u32b(0L);
 
        /* Ignore some flags */
        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 */
-       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_u32b(p_ptr->count);
+       wr_s32b(creature_ptr->visit);
+       wr_u32b(creature_ptr->count);
 }
 
 
@@ -859,37 +843,23 @@ static void wr_extra(void)
  * @param sf_ptr 保存したいフロアの参照ポインタ
  * @return なし
  */
-static void wr_saved_floor(saved_floor_type *sf_ptr)
+static void wr_saved_floor(player_type *player_ptr, saved_floor_type *sf_ptr)
 {
-       cave_template_type *templates;
-       u16b max_num_temp;
-       u16b num_temp = 0;
-       int dummy_why;
-
-       int i, y, x;
-
-       u16b tmp16u;
-
-       byte count;
-       u16b prev_u16b;
-
-
        /*** Basic info ***/
-
        /* Dungeon floor specific info follows */
-
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
        if (!sf_ptr)
        {
                /*** Not a saved floor ***/
 
-               wr_s16b((s16b)current_floor_ptr->dun_level);
+               wr_s16b((s16b)floor_ptr->dun_level);
        }
        else
        {
                /*** The saved floor ***/
 
                wr_s16b(sf_ptr->floor_id);
-               wr_byte((byte_hack)sf_ptr->savefile_id);
+               wr_byte((byte)sf_ptr->savefile_id);
                wr_s16b((s16b)sf_ptr->dun_level);
                wr_s32b(sf_ptr->last_visit);
                wr_u32b(sf_ptr->visit_mark);
@@ -897,15 +867,13 @@ 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->y);
-       wr_u16b((u16b)p_ptr->x);
-       wr_u16b((u16b)current_floor_ptr->height);
-       wr_u16b((u16b)current_floor_ptr->width);
-       wr_byte(p_ptr->feeling);
-
-
+       wr_u16b((u16b)floor_ptr->base_level);
+       wr_u16b((s16b)player_ptr->current_floor_ptr->num_repro);
+       wr_u16b((u16b)player_ptr->y);
+       wr_u16b((u16b)player_ptr->x);
+       wr_u16b((u16b)floor_ptr->height);
+       wr_u16b((u16b)floor_ptr->width);
+       wr_byte(player_ptr->feeling);
 
        /*********** Make template for grid_type **********/
 
@@ -920,25 +888,28 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
         *     515 will be "0xff" "0xff" "0x03"
         */
 
-       /* Fake max number */
-       max_num_temp = 255;
+        /* Fake max number */
+       u16b max_num_temp = 255;
 
        /* Allocate the "template" array */
-       C_MAKE(templates, max_num_temp, cave_template_type);
+       grid_template_type *templates;
+       C_MAKE(templates, max_num_temp, grid_template_type);
 
        /* Extract template array */
-       for (y = 0; y < current_floor_ptr->height; y++)
+       u16b num_temp = 0;
+       for (int y = 0; y < floor_ptr->height; y++)
        {
-               for (x = 0; x < current_floor_ptr->width; x++)
+               for (int x = 0; x < floor_ptr->width; x++)
                {
-                       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
+                       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
 
+                       int i;
                        for (i = 0; i < num_temp; i++)
                        {
                                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)
+                                       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++;
@@ -952,12 +923,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;
                        }
 
@@ -974,6 +945,7 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        }
 
        /* Sort by occurrence */
+       int dummy_why;
        ang_sort(templates, &dummy_why, num_temp, ang_sort_comp_cave_temp, ang_sort_swap_cave_temp);
 
        /*** Dump templates ***/
@@ -982,71 +954,62 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        wr_u16b(num_temp);
 
        /* Dump the templates */
-       for (i = 0; i < num_temp; i++)
+       for (int i = 0; i < num_temp; i++)
        {
-               cave_template_type *ct_ptr = &templates[i];
-
-               /* Dump it */
+               grid_template_type *ct_ptr = &templates[i];
                wr_u16b((u16b)ct_ptr->info);
                wr_s16b(ct_ptr->feat);
                wr_s16b(ct_ptr->mimic);
                wr_s16b(ct_ptr->special);
        }
 
-
-
-       /*** "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;
+       byte count = 0;
+       u16b prev_u16b = 0;
 
-       /* Dump the current_floor_ptr->grid_array */
-       for (y = 0; y < current_floor_ptr->height; y++)
+       for (int y = 0; y < floor_ptr->height; y++)
        {
-               for (x = 0; x < current_floor_ptr->width; x++)
+               for (int x = 0; x < floor_ptr->width; x++)
                {
-                       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
-
+                       grid_type *g_ptr = &floor_ptr->grid_array[y][x];
+                       int i;
                        for (i = 0; i < num_temp; i++)
                        {
                                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)
+                                       templates[i].feat == g_ptr->feat &&
+                                       templates[i].mimic == g_ptr->mimic &&
+                                       templates[i].special == g_ptr->special)
                                        break;
                        }
 
                        /* Extract an ID */
-                       tmp16u = (u16b)i;
+                       u16b tmp16u = (u16b)i;
 
                        /* If the run is broken, or too full, flush it */
-                       if ((tmp16u != prev_u16b) || (count == MAX_UCHAR))
+                       if ((tmp16u == prev_u16b) && (count != MAX_UCHAR))
                        {
-                               wr_byte((byte)count);
-
-                               while (prev_u16b >= MAX_UCHAR)
-                               {
-                                       /* Mark as actual data is larger than 254 */
-                                       wr_byte(MAX_UCHAR);
-                                       prev_u16b -= MAX_UCHAR;
-                               }
-
-                               wr_byte((byte)prev_u16b);
-                               prev_u16b = tmp16u;
-                               count = 1;
+                               count++;
+                               continue;
                        }
 
-                       /* Continue the run */
-                       else
+                       wr_byte((byte)count);
+
+                       while (prev_u16b >= MAX_UCHAR)
                        {
-                               count++;
+                               /* Mark as actual data is larger than 254 */
+                               wr_byte(MAX_UCHAR);
+                               prev_u16b -= MAX_UCHAR;
                        }
+
+                       wr_byte((byte)prev_u16b);
+                       prev_u16b = tmp16u;
+                       count = 1;
                }
        }
 
        /* Flush the data (if any) */
-       if (count)
+       if (count > 0)
        {
                wr_byte((byte)count);
 
@@ -1056,40 +1019,34 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
                        wr_byte(MAX_UCHAR);
                        prev_u16b -= MAX_UCHAR;
                }
+
                wr_byte((byte)prev_u16b);
        }
 
-
        /* 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(floor_ptr->o_max);
 
        /* Dump the objects */
-       for (i = 1; i < o_max; i++)
+       for (int i = 1; i < floor_ptr->o_max; i++)
        {
-               object_type *o_ptr = &current_floor_ptr->o_list[i];
-
-               /* Dump it */
+               object_type *o_ptr = &floor_ptr->o_list[i];
                wr_item(o_ptr);
        }
 
-
        /*** Dump the monsters ***/
 
        /* Total monsters */
-       wr_u16b(m_max);
+       wr_u16b(floor_ptr->m_max);
 
        /* Dump the monsters */
-       for (i = 1; i < m_max; i++)
+       for (int i = 1; i < floor_ptr->m_max; i++)
        {
-               monster_type *m_ptr = &current_floor_ptr->m_list[i];
-
-               /* Dump it */
+               monster_type *m_ptr = &floor_ptr->m_list[i];
                wr_monster(m_ptr);
        }
 }
@@ -1098,20 +1055,18 @@ 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(player_ptr->current_floor_ptr);
+       forget_view(player_ptr->current_floor_ptr);
+       clear_mon_lite(player_ptr->current_floor_ptr);
 
        /* Update lite/view */
-       p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
-       p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
+       player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
+       player_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
 
        /*** Meta info ***/
 
@@ -1119,17 +1074,17 @@ static bool wr_dungeon(void)
        wr_s16b(max_floor_id);
 
        /* Current dungeon type */
-       wr_byte((byte_hack)p_ptr->dungeon_idx);
+       wr_byte((byte)player_ptr->dungeon_idx);
 
 
        /*** No saved floor (On the surface etc.) ***/
-       if (!p_ptr->floor_id)
+       if (!player_ptr->floor_id)
        {
                /* No array elements */
                wr_byte(0);
 
                /* Write the current floor data */
-               wr_saved_floor(NULL);
+               wr_saved_floor(player_ptr, NULL);
 
                /* Success */
                return TRUE;
@@ -1142,12 +1097,12 @@ static bool wr_dungeon(void)
        wr_byte(MAX_SAVED_FLOORS);
 
        /* Write the saved_floors array */
-       for (i = 0; i < MAX_SAVED_FLOORS; i++)
+       for (int i = 0; i < MAX_SAVED_FLOORS; i++)
        {
                saved_floor_type *sf_ptr = &saved_floors[i];
 
                wr_s16b(sf_ptr->floor_id);
-               wr_byte((byte_hack)sf_ptr->savefile_id);
+               wr_byte((byte)sf_ptr->savefile_id);
                wr_s16b((s16b)sf_ptr->dun_level);
                wr_s32b(sf_ptr->last_visit);
                wr_u32b(sf_ptr->visit_mark);
@@ -1156,39 +1111,28 @@ static bool wr_dungeon(void)
        }
 
        /* Extract pointer to current floor */
-       cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
+       saved_floor_type *cur_sf_ptr;
+       cur_sf_ptr = get_sf_ptr(player_ptr->floor_id);
 
-       /* Save current floor to temporal file */
-       if (!save_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
+       /* Save current floor to temporary file */
+       if (!save_floor(player_ptr, cur_sf_ptr, (SLF_SECOND))) return FALSE;
 
-       /* Move data in temporal files to the savefile */
-       for (i = 0; i < MAX_SAVED_FLOORS; i++)
+       /* Move data in temporary files to the savefile */
+       for (int i = 0; i < MAX_SAVED_FLOORS; i++)
        {
                saved_floor_type *sf_ptr = &saved_floors[i];
-
-               /* Unused element */
                if (!sf_ptr->floor_id) continue;
-
-               /* Load temporal saved floor file */
-               if (load_floor(sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
-               {
-                       /* Mark success */
-                       wr_byte(0);
-
-                       /* Write saved floor data to the save file */
-                       wr_saved_floor(sf_ptr);
-               }
-               else
+               if (!load_floor(player_ptr, sf_ptr, (SLF_SECOND | SLF_NO_KILL)))
                {
-                       /* Mark failure */
                        wr_byte(1);
+                       continue;
                }
-       }
 
-       /* Restore current floor */
-       if (!load_floor(cur_sf_ptr, (SLF_SECOND))) return FALSE;
+               wr_byte(0);
+               wr_saved_floor(player_ptr, sf_ptr);
+       }
 
-       /* Success */
+       if (!load_floor(player_ptr, cur_sf_ptr, (SLF_SECOND))) return FALSE;
        return TRUE;
 }
 
@@ -1196,42 +1140,30 @@ 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;
-
-       u32b              now;
-
-       byte            tmp8u;
-       u16b            tmp16u;
-       u32b            tmp32u;
-
-       MONRACE_IDX r_idx;
-       KIND_OBJECT_IDX k_idx;
-
        /* Compact the objects */
-       compact_objects(0);
+       compact_objects(player_ptr, 0);
+
        /* Compact the monsters */
-       compact_monsters(0);
+       compact_monsters(player_ptr, 0);
 
        /* Guess at the current time */
-       now = (u32b)time((time_t *)0);
-
+       u32b now = (u32b)time((time_t *)0);
 
        /* 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 ***/
-
        /* Dump the file header */
        xor_byte = 0;
        wr_byte(FAKE_VER_MAJOR);
@@ -1242,10 +1174,9 @@ static bool wr_savefile_new(void)
        xor_byte = 0;
 
        /* Initial value of xor_byte */
-       tmp8u = (byte)Rand_external(256);
+       byte tmp8u = (byte)Rand_external(256);
        wr_byte(tmp8u);
 
-
        /* Reset the checksum */
        v_stamp = 0L;
        x_stamp = 0L;
@@ -1257,20 +1188,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 */
        wr_u32b(0L);
        wr_u16b(0);
        wr_byte(0);
@@ -1292,31 +1220,35 @@ static bool wr_savefile_new(void)
        /* Write the RNG state */
        wr_randomizer();
 
-
        /* Write the boolean "options" */
        wr_options();
 
-
        /* Dump the number of "messages" */
-       tmp32u = message_num();
+       u32b tmp32u = message_num();
        if (compress_savefile && (tmp32u > 40)) tmp32u = 40;
        wr_u32b(tmp32u);
 
        /* Dump the messages (oldest first!) */
-       for (i = tmp32u - 1; i >= 0; i--)
+       for (int i = tmp32u - 1; i >= 0; i--)
        {
                wr_string(message_str((s16b)i));
        }
 
        /* Dump the monster lore */
-       tmp16u = max_r_idx;
+       u16b tmp16u = max_r_idx;
        wr_u16b(tmp16u);
-       for (r_idx = 0; r_idx < tmp16u; r_idx++) wr_lore(r_idx);
+       for (MONRACE_IDX r_idx = 0; r_idx < tmp16u; r_idx++)
+       {
+               wr_lore(r_idx);
+       }
 
        /* Dump the object memory */
        tmp16u = max_k_idx;
        wr_u16b(tmp16u);
-       for (k_idx = 0; k_idx < tmp16u; k_idx++) wr_xtra(k_idx);
+       for (KIND_OBJECT_IDX k_idx = 0; k_idx < tmp16u; k_idx++)
+       {
+               wr_xtra(k_idx);
+       }
 
        /* Dump the towns */
        tmp16u = max_towns;
@@ -1327,10 +1259,10 @@ static bool wr_savefile_new(void)
        wr_u16b(tmp16u);
 
        /* Dump the quests */
-       tmp8u = MAX_RANDOM_QUEST-MIN_RANDOM_QUEST;
+       tmp8u = MAX_RANDOM_QUEST - MIN_RANDOM_QUEST;
        wr_byte(tmp8u);
 
-       for (i = 0; i < max_q_idx; i++)
+       for (int i = 0; i < max_q_idx; i++)
        {
                quest_type* const q_ptr = &quest[i];
 
@@ -1341,36 +1273,37 @@ static bool wr_savefile_new(void)
                /* (prevents problems with multi-level quests) */
                wr_s16b((s16b)q_ptr->level);
 
-               wr_byte((byte_hack)q_ptr->complev);
+               wr_byte((byte)q_ptr->complev);
                wr_u32b(q_ptr->comptime);
 
-               /* Save quest status if quest is running */
-               if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
-               {
-                       wr_s16b((s16b)q_ptr->cur_num);
-                       wr_s16b((s16b)q_ptr->max_num);
-                       wr_s16b(q_ptr->type);
-                       wr_s16b(q_ptr->r_idx);
-                       wr_s16b(q_ptr->k_idx);
-                       wr_byte((byte_hack)q_ptr->flags);
-                       wr_byte((byte_hack)q_ptr->dungeon);
-               }
+               bool is_quest_running = q_ptr->status == QUEST_STATUS_TAKEN;
+               is_quest_running |= q_ptr->status == QUEST_STATUS_COMPLETED;
+               is_quest_running |= !is_fixed_quest_idx(i);
+               if (!is_quest_running) continue;
+
+               wr_s16b((s16b)q_ptr->cur_num);
+               wr_s16b((s16b)q_ptr->max_num);
+               wr_s16b(q_ptr->type);
+               wr_s16b(q_ptr->r_idx);
+               wr_s16b(q_ptr->k_idx);
+               wr_byte((byte)q_ptr->flags);
+               wr_byte((byte)q_ptr->dungeon);
        }
 
        /* 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);
 
        /* Dump the wilderness seeds */
-       for (i = 0; i < current_world_ptr->max_wild_x; i++)
+       for (int i = 0; i < current_world_ptr->max_wild_x; i++)
        {
-               for (j = 0; j < current_world_ptr->max_wild_y; j++)
+               for (int j = 0; j < current_world_ptr->max_wild_y; j++)
                {
                        wr_u32b(wilderness[j][i].seed);
                }
@@ -1379,51 +1312,44 @@ static bool wr_savefile_new(void)
        /* Hack -- Dump the artifacts */
        tmp16u = max_a_idx;
        wr_u16b(tmp16u);
-       for (i = 0; i < tmp16u; i++)
+       for (int i = 0; i < tmp16u; i++)
        {
                artifact_type *a_ptr = &a_info[i];
                wr_byte(a_ptr->cur_num);
                wr_s16b(a_ptr->floor_id);
        }
 
-
-
        /* 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++)
+       for (int 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++)
+       for (int i = 0; i < 64; i++)
        {
-               wr_byte((byte_hack)p_ptr->spell_order[i]);
+               wr_byte((byte)player_ptr->spell_order[i]);
        }
 
-
-       /* Write the inventory */
-       for (i = 0; i < INVEN_TOTAL; i++)
+       for (int i = 0; i < INVEN_TOTAL; i++)
        {
-               object_type *o_ptr = &inventory[i];
-
-               /* Skip non-objects */
+               object_type *o_ptr = &player_ptr->inventory_list[i];
                if (!o_ptr->k_idx) continue;
 
                /* Dump index */
@@ -1445,20 +1371,20 @@ static bool wr_savefile_new(void)
        wr_u16b(tmp16u);
 
        /* Dump the stores of all towns */
-       for (i = 1; i < max_towns; i++)
+       for (int i = 1; i < max_towns; i++)
        {
-               for (j = 0; j < MAX_STORES; j++)
+               for (int j = 0; j < MAX_STORES; j++)
                {
                        wr_store(&town_info[i].store[j]);
                }
        }
 
        /* 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);
        }
@@ -1468,10 +1394,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();
@@ -1480,18 +1406,13 @@ static bool wr_savefile_new(void)
                wr_s32b(0);
        }
 
-
        /* Write the "value check-sum" */
        wr_u32b(v_stamp);
 
        /* Write the "encoded checksum" */
        wr_u32b(x_stamp);
 
-
-       /* Error in save */
        if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
-
-       /* Successful save */
        return TRUE;
 }
 
@@ -1499,32 +1420,27 @@ 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;
-       int mode = 0644;
-
-       /* No file yet */
-       fff = NULL;
-
-       /* File type is "SAVE" */
        FILE_TYPE(FILE_TYPE_SAVE);
 
        /* Grab permissions */
        safe_setuid_grab();
 
        /* Create the savefile */
-       fd = fd_make(name, mode);
+       int file_permission = 0644;
+       int fd = fd_make(name, file_permission);
 
        /* Drop permissions */
        safe_setuid_drop();
 
-       /* File is okay */
+       bool is_save_successful = FALSE;
+       fff = NULL;
        if (fd >= 0)
        {
                /* Close the "fd" */
@@ -1543,78 +1459,54 @@ static bool save_player_aux(char *name)
                if (fff)
                {
                        /* Write the savefile */
-                       if (wr_savefile_new()) ok = TRUE;
+                       if (wr_savefile_new(player_ptr)) is_save_successful = TRUE;
 
                        /* Attempt to close it */
-                       if (my_fclose(fff)) ok = FALSE;
+                       if (my_fclose(fff)) is_save_successful = FALSE;
                }
 
                /* Grab permissions */
                safe_setuid_grab();
 
                /* Remove "broken" files */
-               if (!ok) (void)fd_kill(name);
+               if (!is_save_successful) (void)fd_kill(name);
 
                /* Drop permissions */
                safe_setuid_drop();
        }
 
+       if (!is_save_successful) return FALSE;
 
-       /* Failure */
-       if (!ok) return (FALSE);
-
-       counts_write(0, current_world_ptr->play_time);
-
-       /* Successful save */
-       character_saved = TRUE;
-
-       /* Success */
-       return (TRUE);
+       counts_write(player_ptr, 0, current_world_ptr->play_time);
+       current_world_ptr->character_saved = TRUE;
+       return TRUE;
 }
 
 
-
 /*!
  * @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;
-
        char safe[1024];
-
-
-#ifdef SET_UID
-
-# ifdef SECURE
-
-       /* Get "games" permissions */
-       beGames();
-
-# endif
-
-#endif
-
-
-       /* New savefile */
        strcpy(safe, savefile);
        strcat(safe, ".new");
 
        /* Grab permissions */
        safe_setuid_grab();
 
-       /* Remove it */
        fd_kill(safe);
 
        /* Drop permissions */
        safe_setuid_drop();
-
        update_playtime();
 
        /* Attempt to save the player */
-       if (save_player_aux(safe))
+       bool result = FALSE;
+       if (save_player_aux(player_ptr, safe))
        {
                char temp[1024];
 
@@ -1641,49 +1533,20 @@ bool save_player(void)
                safe_setuid_drop();
 
                /* Hack -- Pretend the character was loaded */
-               character_loaded = TRUE;
-
-#ifdef VERIFY_SAVEFILE
-
-               /* Lock on savefile */
-               strcpy(temp, savefile);
-               strcat(temp, ".lok");
-
-               /* Grab permissions */
-               safe_setuid_grab();
-
-               /* Remove lock file */
-               fd_kill(temp);
-
-               /* Drop permissions */
-               safe_setuid_drop();
-
-#endif
+               current_world_ptr->character_loaded = TRUE;
 
-               /* Success */
                result = TRUE;
        }
 
-
-#ifdef SET_UID
-
-# ifdef SECURE
-
-       /* Drop "games" permissions */
-       bePlayer();
-
-# endif
-
-#endif
-
        /* Return the result */
-       return (result);
+       return result;
 }
 
 
 /*!
  * @brief セーブデータ読み込みのメインルーチン /
  * Attempt to Load a "savefile"
+ * @param creature_ptr プレーヤーへの参照ポインタ
  * @return 成功すればtrue
  * @details
  * <pre>
@@ -1702,35 +1565,25 @@ 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.
  * </pre>
  */
-bool load_player(void)
+bool load_player(player_type *player_ptr)
 {
-       int             fd = -1;
-
-       errr    err = 0;
-
-       byte    vvv[4];
-
-#ifdef VERIFY_TIMESTAMP
-       struct stat     statbuf;
-#endif
-
        concptr    what = "generic";
 
        current_world_ptr->game_turn = 0;
-       p_ptr->is_dead = FALSE;
+       player_ptr->is_dead = FALSE;
 
 
        /* Allow empty savefile name */
-       if (!savefile[0]) return (TRUE);
+       if (!savefile[0]) return TRUE;
 
 
-#if !defined(MACINTOSH) && !defined(WINDOWS)
+#if !defined(WINDOWS)
 
        /* Fix this */
 
@@ -1743,52 +1596,14 @@ bool load_player(void)
                msg_print(NULL);
 
                /* Allow this */
-               return (TRUE);
-       }
-
-#endif
-
-
-#ifdef VERIFY_SAVEFILE
-
-       /* Verify savefile usage */
-       if (!err)
-       {
-               FILE *fkk;
-
-               char temp[1024];
-
-               /* Extract name of lock file */
-               strcpy(temp, savefile);
-               strcat(temp, ".lok");
-
-               /* Check for lock */
-               fkk = my_fopen(temp, "r");
-
-               /* Oops, lock exists */
-               if (fkk)
-               {
-                       my_fclose(fkk);
-
-                       msg_print(_("セーブファイルは現在使用中です。", "Savefile is currently in use."));
-                       msg_print(NULL);
-
-                       return (FALSE);
-               }
-
-               /* Create a lock file */
-               fkk = my_fopen(temp, "w");
-
-               /* Dump a line of info */
-               fprintf(fkk, "Lock file for savefile '%s'\n", savefile);
-
-               /* Close the lock file */
-               my_fclose(fkk);
+               return TRUE;
        }
 
 #endif
 
-
+       errr err = 0;
+       int fd = -1;
+       byte vvv[4];
        if (!err)
        {
                /* Open the savefile */
@@ -1804,12 +1619,6 @@ bool load_player(void)
        /* Process file */
        if (!err)
        {
-
-#ifdef VERIFY_TIMESTAMP
-               /* Get the timestamp */
-               (void)fstat(fd, &statbuf);
-#endif
-
                /* Read the first four bytes */
                if (fd_read(fd, (char*)(vvv), 4)) err = -1;
 
@@ -1821,192 +1630,111 @@ bool load_player(void)
        /* Process file */
        if (!err)
        {
-
                /* 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();
 
                /* Attempt to load */
-               err = rd_savefile_new();
+               err = rd_savefile_new(player_ptr);
 
                /* Message (below) */
                if (err) what = _("セーブファイルを解析出来ません。", "Cannot parse savefile");
        }
+
        if (!err)
        {
-               /* Invalid current_world_ptr->game_turn */
+               /* Invalid turn */
                if (!current_world_ptr->game_turn) err = -1;
 
                /* Message (below) */
                if (err) what = _("セーブファイルが壊れています", "Broken savefile");
        }
 
-#ifdef VERIFY_TIMESTAMP
-       /* Verify timestamp */
-       if (!err && !arg_wizard)
-       {
-               /* Hack -- Verify the timestamp */
-               if (sf_when > (statbuf.st_ctime + 100) ||
-                   sf_when < (statbuf.st_ctime - 100))
-               {
-                       what = _("無効なタイム・スタンプです", "Invalid timestamp");
-
-                       err = -1;
-               }
-       }
-#endif
-
-
        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);
                }
 
                /* Player is dead */
-               if (p_ptr->is_dead)
+               if (player_ptr->is_dead)
                {
                        /* Cheat death */
                        if (arg_wizard)
                        {
                                /* A character was loaded */
-                               character_loaded = TRUE;
-                               return (TRUE);
+                               current_world_ptr->character_loaded = TRUE;
+                               return TRUE;
                        }
 
                        /* Player is no longer "dead" */
-                       p_ptr->is_dead = FALSE;
+                       player_ptr->is_dead = FALSE;
 
                        /* Count lives */
-                       sf_lives++;
+                       current_world_ptr->sf_lives++;
 
-                       return (TRUE);
+                       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) > current_world_ptr->play_time || counts_read(1) == current_world_ptr->play_time)
-                               counts_write(2, ++p_ptr->count);
-                       counts_write(1, current_world_ptr->play_time);
+                       u32b tmp = counts_read(player_ptr, 2);
+                       if (tmp > player_ptr->count)
+                               player_ptr->count = tmp;
+                       if (counts_read(player_ptr, 0) > current_world_ptr->play_time || counts_read(player_ptr, 1) == current_world_ptr->play_time)
+                               counts_write(player_ptr, 2, ++player_ptr->count);
+                       counts_write(player_ptr, 1, current_world_ptr->play_time);
                }
 
                /* Success */
-               return (TRUE);
-       }
-
-
-#ifdef VERIFY_SAVEFILE
-
-       /* Verify savefile usage */
-       if (TRUE)
-       {
-               char temp[1024];
-
-               /* Extract name of lock file */
-               strcpy(temp, savefile);
-               strcat(temp, ".lok");
-
-               /* Remove lock */
-               fd_kill(temp);
+               return TRUE;
        }
 
-#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);
-
-       return (FALSE);
-}
-
-/*!
- * @brief ファイルロック処理
- * @return なし
- */
-void remove_loc(void)
-{
-#ifdef VERIFY_SAVEFILE
-       char temp[1024];
-#endif /* VERIFY_SAVEFILE */
-
-#ifdef SET_UID
-# ifdef SECURE
-
-       /* Get "games" permissions */
-       beGames();
-
-# endif /* SECURE */
-#endif /* SET_UID */
-
-#ifdef VERIFY_SAVEFILE
-
-       /* Lock on savefile */
-       strcpy(temp, savefile);
-       strcat(temp, ".lok");
-
-       /* Remove lock file */
-       fd_kill(temp);
-
-#endif /* VERIFY_SAVEFILE */
-
-#ifdef SET_UID
-# ifdef SECURE
-
-       /* Drop "games" permissions */
-       bePlayer();
-
-# endif /* SECURE */
-#endif /* SET_UID */
-
+       return FALSE;
 }
 
 
 /*!
- * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporal saved floor file
+ * @brief ゲームプレイ中のフロア一時保存出力処理サブルーチン / Actually write a temporary saved floor file
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param sf_ptr 保存フロア参照ポインタ
  * @return なし
  */
-static bool save_floor_aux(saved_floor_type *sf_ptr)
+static bool save_floor_aux(player_type *player_ptr, saved_floor_type *sf_ptr)
 {
-       byte tmp8u;
-
        /* Compact the objects */
-       compact_objects(0);
+       compact_objects(player_ptr, 0);
        /* Compact the monsters */
-       compact_monsters(0);
-
+       compact_monsters(player_ptr, 0);
 
        /*** Actually write the file ***/
-
        /* Initial value of xor_byte */
-       tmp8u = (byte)randint0(256);
+       byte tmp8u = (byte)randint0(256);
        xor_byte = 0;
        wr_byte(tmp8u);
 
-
        /* Reset the checksum */
        v_stamp = 0L;
        x_stamp = 0L;
@@ -2015,8 +1743,7 @@ static bool save_floor_aux(saved_floor_type *sf_ptr)
        wr_u32b(saved_floor_file_sign);
 
        /* Dump the dungeon floor */
-       wr_saved_floor(sf_ptr);
-
+       wr_saved_floor(player_ptr, sf_ptr);
 
        /* Write the "value check-sum" */
        wr_u32b(v_stamp);
@@ -2024,22 +1751,19 @@ static bool save_floor_aux(saved_floor_type *sf_ptr)
        /* Write the "encoded checksum" */
        wr_u32b(x_stamp);
 
-
-       /* Error in save */
        if (ferror(fff) || (fflush(fff) == EOF)) return FALSE;
-
-       /* Successful save */
        return TRUE;
 }
 
 
 /*!
- * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporally saved-floor data
+ * @brief ゲームプレイ中のフロア一時保存出力処理メインルーチン / Attempt to save the temporarily saved-floor data
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param sf_ptr 保存フロア参照ポインタ
  * @param mode 保存オプション
  * @return なし
  */
-bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
+bool save_floor(player_type *player_ptr, saved_floor_type *sf_ptr, BIT_FLAGS mode)
 {
        FILE *old_fff = NULL;
        byte old_xor_byte = 0;
@@ -2047,17 +1771,8 @@ bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
        u32b old_x_stamp = 0;
 
        char floor_savefile[1024];
-       int fd = -1;
-       bool ok = FALSE;
-
        if (!(mode & SLF_SECOND))
        {
-#ifdef SET_UID
-# ifdef SECURE
-               /* Get "games" permissions */
-               beGames();
-# endif
-#endif
        }
 
        /* We have one file already opened */
@@ -2082,7 +1797,6 @@ bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
        /* Drop permissions */
        safe_setuid_drop();
 
-
        /* Attempt to save the player */
 
        /* No file yet */
@@ -2095,12 +1809,12 @@ bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
        safe_setuid_grab();
 
        /* Create the savefile */
-       fd = fd_make(floor_savefile, 0644);
+       int fd = fd_make(floor_savefile, 0644);
 
        /* Drop permissions */
        safe_setuid_drop();
 
-       /* File is okay */
+       bool is_save_successful = FALSE;
        if (fd >= 0)
        {
                /* Close the "fd" */
@@ -2119,14 +1833,14 @@ bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
                if (fff)
                {
                        /* Write the savefile */
-                       if (save_floor_aux(sf_ptr)) ok = TRUE;
+                       if (save_floor_aux(player_ptr, sf_ptr)) is_save_successful = TRUE;
 
                        /* Attempt to close it */
-                       if (my_fclose(fff)) ok = FALSE;
+                       if (my_fclose(fff)) is_save_successful = FALSE;
                }
 
                /* Remove "broken" files */
-               if (!ok)
+               if (!is_save_successful)
                {
                        /* Grab permissions */
                        safe_setuid_grab();
@@ -2140,12 +1854,6 @@ bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
 
        if (!(mode & SLF_SECOND))
        {
-#ifdef SET_UID
-# ifdef SECURE
-               /* Drop "games" permissions */
-               bePlayer();
-# endif
-#endif
        }
 
        /* We have one file already opened */
@@ -2158,6 +1866,5 @@ bool save_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
                x_stamp = old_x_stamp;
        }
 
-       /* Return the result */
-       return ok;
+       return is_save_successful;
 }