OSDN Git Service

[Refactor] #37353 MAGIC_* を player-status.h に移動。
[hengband/hengband.git] / src / load.c
index 7a8a089..b6205d9 100644 (file)
 
 #include "angband.h"
 #include "util.h"
+#include "core.h"
 
+#include "load.h"
+#include "bldg.h"
+#include "report.h"
+
+#include "dungeon.h"
 #include "feature.h"
 #include "floor-generate.h"
 #include "trap.h"
 #include "wild.h"
 #include "patron.h"
 
-#include "floor-save.h"
 #include "floor.h"
+#include "floor-save.h"
+#include "floor-town.h"
 #include "grid.h"
 
 #include "cmd-pet.h"
 #include "dungeon-file.h"
 #include "files.h"
-
+#include "player-skill.h"
+#include "player-class.h"
+#include "player-race.h"
+#include "player-personality.h"
+#include "player-sex.h"
+#include "birth.h"
+#include "world.h"
+#include "objectkind.h"
+#include "object-ego.h"
+#include "save.h"
+#include "japanese.h"
+#include "realm-song.h"
+#include "cmd-smith.h"
 
 /*
  * Maximum number of tries for selection of a proper quest monster
@@ -112,20 +131,20 @@ static byte kanji_code = 0;
 static bool h_older_than(byte major, byte minor, byte patch, byte extra)
 {
        /* Much older, or much more recent */
-       if (h_ver_major < major) return (TRUE);
-       if (h_ver_major > major) return (FALSE);
+       if (current_world_ptr->h_ver_major < major) return (TRUE);
+       if (current_world_ptr->h_ver_major > major) return (FALSE);
 
        /* Distinctly older, or distinctly more recent */
-       if (h_ver_minor < minor) return (TRUE);
-       if (h_ver_minor > minor) return (FALSE);
+       if (current_world_ptr->h_ver_minor < minor) return (TRUE);
+       if (current_world_ptr->h_ver_minor > minor) return (FALSE);
 
        /* Barely older, or barely more recent */
-       if (h_ver_patch < patch) return (TRUE);
-       if (h_ver_patch > patch) return (FALSE);
+       if (current_world_ptr->h_ver_patch < patch) return (TRUE);
+       if (current_world_ptr->h_ver_patch > patch) return (FALSE);
 
        /* Barely older, or barely more recent */
-       if (h_ver_extra < extra) return (TRUE);
-       if (h_ver_extra > extra) return (FALSE);
+       if (current_world_ptr->h_ver_extra < extra) return (TRUE);
+       if (current_world_ptr->h_ver_extra > extra) return (FALSE);
 
        /* Identical versions */
        return (FALSE);
@@ -142,16 +161,16 @@ static bool h_older_than(byte major, byte minor, byte patch, byte extra)
 static bool z_older_than(byte x, byte y, byte z)
 {
        /* Much older, or much more recent */
-       if (z_major < x) return (TRUE);
-       if (z_major > x) return (FALSE);
+       if (current_world_ptr->z_major < x) return (TRUE);
+       if (current_world_ptr->z_major > x) return (FALSE);
 
        /* Distinctly older, or distinctly more recent */
-       if (z_minor < y) return (TRUE);
-       if (z_minor > y) return (FALSE);
+       if (current_world_ptr->z_minor < y) return (TRUE);
+       if (current_world_ptr->z_minor > y) return (FALSE);
 
        /* Barely older, or barely more recent */
-       if (z_patch < z) return (TRUE);
-       if (z_patch > z) return (FALSE);
+       if (current_world_ptr->z_patch < z) return (TRUE);
+       if (current_world_ptr->z_patch > z) return (FALSE);
 
        /* Identical versions */
        return (FALSE);
@@ -940,7 +959,7 @@ static void rd_monster_old(monster_type *m_ptr)
        rd_byte(&tmp8u);
        m_ptr->mtimed[MTIMED_INVULNER] = (s16b)tmp8u;
 
-       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))
                rd_u32b(&m_ptr->smart);
        else
                m_ptr->smart = 0;
@@ -1295,7 +1314,7 @@ static void rd_lore(MONRACE_IDX r_idx)
 }
 
 /*!
- * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the inventory of the "Home"
+ * @brief 店置きのアイテムオブジェクトを読み込む / Add the item "o_ptr" to the p_ptr->inventory_list of the "Home"
  * @param st_ptr 店舗の参照ポインタ
  * @param o_ptr アイテムオブジェクト参照ポインタ
  * @return なし
@@ -2096,7 +2115,7 @@ static void rd_extra(void)
        else rd_s16b(&p_ptr->tsuyoshi);
 
        /* Old savefiles do not have the following fields... */
-       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))
        {
                p_ptr->tim_esp = 0;
                p_ptr->wraith_form = 0;
@@ -2242,8 +2261,8 @@ static void rd_extra(void)
 
 
        /* Hack -- the two "special seeds" */
-       rd_u32b(&seed_flavor);
-       rd_u32b(&seed_town);
+       rd_u32b(&current_world_ptr->seed_flavor);
+       rd_u32b(&current_world_ptr->seed_town);
 
 
        /* Special stuff */
@@ -2305,9 +2324,9 @@ static void rd_extra(void)
 
        if (z_older_than(10, 3, 13))
        {
-               old_battle = current_world_ptr->game_turn;
+               current_world_ptr->arena_start_turn = current_world_ptr->game_turn;
        }
-       else rd_s32b(&old_battle);
+       else rd_s32b(&current_world_ptr->arena_start_turn);
 
        if (z_older_than(10,0,3))
        {
@@ -2387,16 +2406,16 @@ static void rd_extra(void)
 
 
 /*!
- * @brief プレイヤーの所持品情報を読み込む / Read the player inventory
+ * @brief プレイヤーの所持品情報を読み込む / Read the player p_ptr->inventory_list
  * @return なし
  * @details
- * Note that the inventory changed in Angband 2.7.4.  Two extra
+ * Note that the p_ptr->inventory_list changed in Angband 2.7.4.  Two extra
  * pack slots were added and the equipment was rearranged.  Note
  * that these two features combine when parsing old save-files, in
  * which items from the old "aux" slot are "carried", perhaps into
- * one of the two new "inventory" slots.
+ * one of the two new "p_ptr->inventory_list" slots.
  *
- * Note that the inventory is "re-sorted" later by "dungeon()".
+ * Note that the p_ptr->inventory_list is "re-sorted" later by "dungeon()".
  */
 static errr rd_inventory(void)
 {
@@ -2409,8 +2428,11 @@ static errr rd_inventory(void)
        p_ptr->total_weight = 0;
 
        /* No items */
-       inven_cnt = 0;
-       equip_cnt = 0;
+       p_ptr->inven_cnt = 0;
+       p_ptr->equip_cnt = 0;
+
+       if (p_ptr->inventory_list != NULL) C_WIPE(p_ptr->inventory_list, INVEN_TOTAL, object_type);
+       C_MAKE(p_ptr->inventory_list, INVEN_TOTAL, object_type);
 
        /* Read until done */
        while (1)
@@ -2435,38 +2457,38 @@ static errr rd_inventory(void)
                if (n >= INVEN_RARM)
                {
                        q_ptr->marked |= OM_TOUCHED;
-                       object_copy(&inventory[n], q_ptr);
+                       object_copy(&p_ptr->inventory_list[n], q_ptr);
 
                        /* Add the weight */
                        p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
 
                        /* One more item */
-                       equip_cnt++;
+                       p_ptr->equip_cnt++;
                }
 
                /* Warning -- backpack is full */
-               else if (inven_cnt == INVEN_PACK)
+               else if (p_ptr->inven_cnt == INVEN_PACK)
                {
-                       note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
+                       note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the p_ptr->inventory_list!"));
 
                        /* Fail */
                        return (54);
                }
 
-               /* Carry inventory */
+               /* Carry p_ptr->inventory_list */
                else
                {
                        /* Get a slot */
                        n = slot++;
 
                        q_ptr->marked |= OM_TOUCHED;
-                       object_copy(&inventory[n], q_ptr);
+                       object_copy(&p_ptr->inventory_list[n], q_ptr);
 
                        /* Add the weight */
                        p_ptr->total_weight += (q_ptr->number * q_ptr->weight);
 
                        /* One more item */
-                       inven_cnt++;
+                       p_ptr->inven_cnt++;
                }
        }
 
@@ -2951,9 +2973,9 @@ static errr rd_dungeon_old(void)
 
        /* The dungeon is ready */
        if (z_older_than(10, 3, 13) && !current_floor_ptr->dun_level && !p_ptr->inside_arena)
-               character_dungeon = FALSE;
+               current_world_ptr->character_dungeon = FALSE;
        else
-               character_dungeon = TRUE;
+               current_world_ptr->character_dungeon = TRUE;
 
        /* Success */
        return (0);
@@ -2986,7 +3008,7 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
        u32b tmp32u;
        u16b limit;
 
-       cave_template_type *templates;
+       grid_template_type *templates;
 
 
        /*** Wipe all current_floor_ptr->grid_array ***/
@@ -3058,12 +3080,12 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
        rd_u16b(&limit);
 
        /* Allocate the "template" array */
-       C_MAKE(templates, limit, cave_template_type);
+       C_MAKE(templates, limit, grid_template_type);
 
        /* Read the templates */
        for (i = 0; i < limit; i++)
        {
-               cave_template_type *ct_ptr = &templates[i];
+               grid_template_type *ct_ptr = &templates[i];
 
                /* Read it */
                rd_u16b(&tmp16u);
@@ -3159,7 +3181,7 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
        }
 
        /* Free the "template" array */
-       C_KILL(templates, limit, cave_template_type);
+       C_KILL(templates, limit, grid_template_type);
 
 
        /*** Objects ***/
@@ -3399,7 +3421,7 @@ static errr rd_dungeon(void)
        }
 
        /* The dungeon is ready */
-       character_dungeon = TRUE;
+       current_world_ptr->character_dungeon = TRUE;
 
        /* Success or Error */
        return err;
@@ -3433,7 +3455,7 @@ static errr rd_savefile_new_aux(void)
        strip_bytes(4);
 
        /* Hack -- decrypt */
-       xor_byte = sf_extra;
+       xor_byte = current_world_ptr->sf_extra;
 
 
        /* Clear the checksums */
@@ -3442,28 +3464,28 @@ static errr rd_savefile_new_aux(void)
 
        /* Read the version number of the savefile */
        /* Old savefile will be version 0.0.0.3 */
-       rd_byte(&h_ver_extra);
-       rd_byte(&h_ver_patch);
-       rd_byte(&h_ver_minor);
-       rd_byte(&h_ver_major);
+       rd_byte(&current_world_ptr->h_ver_extra);
+       rd_byte(&current_world_ptr->h_ver_patch);
+       rd_byte(&current_world_ptr->h_ver_minor);
+       rd_byte(&current_world_ptr->h_ver_major);
 
        /* Mention the savefile version */
        note(format(
                _("バージョン %d.%d.%d.%d のセーブ・ファイルをロード中...", "Loading a %d.%d.%d.%d savefile..."),
-               (h_ver_major > 9) ? h_ver_major - 10 : h_ver_major, h_ver_minor, h_ver_patch, h_ver_extra));
+               (current_world_ptr->h_ver_major > 9) ? current_world_ptr->h_ver_major - 10 : current_world_ptr->h_ver_major, current_world_ptr->h_ver_minor, current_world_ptr->h_ver_patch, current_world_ptr->h_ver_extra));
 
 
        /* Operating system info */
-       rd_u32b(&sf_system);
+       rd_u32b(&current_world_ptr->sf_system);
 
        /* Time of savefile creation */
-       rd_u32b(&sf_when);
+       rd_u32b(&current_world_ptr->sf_when);
 
        /* Number of resurrections */
-       rd_u16b(&sf_lives);
+       rd_u16b(&current_world_ptr->sf_lives);
 
        /* Number of times played */
-       rd_u16b(&sf_saves);
+       rd_u16b(&current_world_ptr->sf_saves);
 
 
        /* Later use (always zero) */
@@ -3851,10 +3873,10 @@ static errr rd_savefile_new_aux(void)
        }
 
 
-       /* Read the inventory */
+       /* Read the p_ptr->inventory_list */
        if (rd_inventory())
        {
-               note(_("持ち物情報を読み込むことができません", "Unable to read inventory"));
+               note(_("持ち物情報を読み込むことができません", "Unable to read p_ptr->inventory_list"));
                return (21);
        }
 
@@ -4053,10 +4075,10 @@ static bool load_floor_aux(saved_floor_type *sf_ptr)
 
        /* Set the version number to current version */
        /* Never load old temporal files */
-       h_ver_extra = H_VER_EXTRA;
-       h_ver_patch = H_VER_PATCH;
-       h_ver_minor = H_VER_MINOR;
-       h_ver_major = H_VER_MAJOR;
+       current_world_ptr->h_ver_extra = H_VER_EXTRA;
+       current_world_ptr->h_ver_patch = H_VER_PATCH;
+       current_world_ptr->h_ver_minor = H_VER_MINOR;
+       current_world_ptr->h_ver_major = H_VER_MAJOR;
 
        /* Verify the sign */
        rd_u32b(&tmp32u);
@@ -4140,10 +4162,10 @@ bool load_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
                old_xor_byte = xor_byte;
                old_v_check = v_check;
                old_x_check = x_check;
-               old_h_ver_major = h_ver_major;
-               old_h_ver_minor = h_ver_minor;
-               old_h_ver_patch = h_ver_patch;
-               old_h_ver_extra = h_ver_extra;
+               old_h_ver_major = current_world_ptr->h_ver_major;
+               old_h_ver_minor = current_world_ptr->h_ver_minor;
+               old_h_ver_patch = current_world_ptr->h_ver_patch;
+               old_h_ver_extra = current_world_ptr->h_ver_extra;
        }
 
        /* floor savefile */
@@ -4189,10 +4211,10 @@ bool load_floor(saved_floor_type *sf_ptr, BIT_FLAGS mode)
                xor_byte = old_xor_byte;
                v_check = old_v_check;
                x_check = old_x_check;
-               h_ver_major = old_h_ver_major;
-               h_ver_minor = old_h_ver_minor;
-               h_ver_patch = old_h_ver_patch;
-               h_ver_extra = old_h_ver_extra;
+               current_world_ptr->h_ver_major = old_h_ver_major;
+               current_world_ptr->h_ver_minor = old_h_ver_minor;
+               current_world_ptr->h_ver_patch = old_h_ver_patch;
+               current_world_ptr->h_ver_extra = old_h_ver_extra;
        }
 
        /* Restore old knowledge */