OSDN Git Service

[Refactor] #37353 コメント整理 / Refactor comments.
[hengband/hengband.git] / src / load.c
index f21f6f2..eb589ff 100644 (file)
  * the existing "number of turns to protect for", and where each hit
  * by a monster will reduce the shield by that amount.
  *
- * XXX XXX XXX
+ * 
  */
 
 #include "angband.h"
+#include "generate.h"
+#include "trap.h"
 
 
 /*
@@ -144,7 +146,7 @@ static bool z_older_than(byte x, byte y, byte z)
  */
 static void note(cptr msg)
 {
-       static int y = 2;
+       static TERM_LEN y = 2;
 
        /* Draw the message */
        prt(msg, y, 0);
@@ -345,7 +347,6 @@ static void rd_item_old(object_type *o_ptr)
        /* Kind */
        rd_s16b(&o_ptr->k_idx);
 
-       /* Location */
        rd_byte(&tmp8u);
        o_ptr->iy = (POSITION)tmp8u;
        rd_byte(&tmp8u);
@@ -370,7 +371,9 @@ static void rd_item_old(object_type *o_ptr)
        rd_byte(&o_ptr->discount);
        rd_byte(&tmp8u);
        o_ptr->number = (ITEM_NUMBER)tmp8u;
-       rd_s16b(&o_ptr->weight);
+
+       rd_s16b(&tmp16s);
+       o_ptr->weight = tmp16s;
 
        rd_byte(&tmp8u);
        o_ptr->name1 = tmp8u;
@@ -606,7 +609,7 @@ static void rd_item_old(object_type *o_ptr)
 static void rd_item(object_type *o_ptr)
 {
        object_kind *k_ptr;
-       u32b flags;
+       BIT_FLAGS flags;
        char buf[128];
        byte_hack tmp8u;
        s16b tmp16s;
@@ -624,7 +627,6 @@ static void rd_item(object_type *o_ptr)
        /* Kind */
        rd_s16b(&o_ptr->k_idx);
 
-       /* Location */
        rd_byte(&tmp8u);
        o_ptr->iy = (POSITION)tmp8u;
        rd_byte(&tmp8u);
@@ -647,7 +649,8 @@ static void rd_item(object_type *o_ptr)
        }       
        else o_ptr->number = 1;
 
-       rd_s16b(&o_ptr->weight);
+       rd_s16b(&tmp16s);
+       o_ptr->weight = tmp16s;
 
        if (flags & SAVE_ITEM_NAME1)
        {
@@ -749,7 +752,7 @@ static void rd_item(object_type *o_ptr)
        
        if(h_older_than(2,1,2,4))
        {
-               u32b flgs[TR_FLAG_SIZE];
+               BIT_FLAGS flgs[TR_FLAG_SIZE];
                object_flags(o_ptr, flgs);
                
                if ((o_ptr->name2 == EGO_DARK) || (o_ptr->name2 == EGO_ANCIENT_CURSE) || (o_ptr->name1 == ART_NIGHT))
@@ -864,7 +867,7 @@ static void rd_monster_old(monster_type *m_ptr)
        }
        else
        {
-               rd_u32b(&m_ptr->dealt_damage); 
+               rd_s32b(&m_ptr->dealt_damage); 
        }
        
        rd_s16b(&m_ptr->mtimed[MTIMED_CSLEEP]);
@@ -923,12 +926,12 @@ static void rd_monster_old(monster_type *m_ptr)
        else
                m_ptr->smart = 0;
 
-       if (z_older_than(10, 4, 5))
+       if (z_older_than(10, 4, 5)) {
                m_ptr->exp = 0;
-       else
-               tmp32u = 0;
+       } else {
                rd_u32b(&tmp32u);
                m_ptr->exp = tmp32u;
+       }
 
        if (z_older_than(10, 2, 2))
        {
@@ -970,7 +973,7 @@ static void rd_monster_old(monster_type *m_ptr)
  */
 static void rd_monster(monster_type *m_ptr)
 {
-       u32b flags;
+       BIT_FLAGS flags;
        char buf[128];
        byte tmp8u;
        s16b tmp16s;
@@ -1009,7 +1012,7 @@ static void rd_monster(monster_type *m_ptr)
        }
        else
        {
-               rd_u32b(&m_ptr->dealt_damage); 
+               rd_s32b(&m_ptr->dealt_damage); 
        }
 
        /* Monster race index of its appearance */
@@ -1156,22 +1159,28 @@ static void rd_monster(monster_type *m_ptr)
 static void rd_lore(MONRACE_IDX r_idx)
 {
        byte tmp8u;
+       s16b tmp16s;
 
        monster_race *r_ptr = &r_info[r_idx];
 
        /* Count sights/deaths/kills */
-       rd_s16b(&r_ptr->r_sights);
-       rd_s16b(&r_ptr->r_deaths);
-       rd_s16b(&r_ptr->r_pkills);
+       rd_s16b(&tmp16s);
+       r_ptr->r_sights = (MONSTER_NUMBER)tmp16s;
+       rd_s16b(&tmp16s);
+       r_ptr->r_deaths = (MONSTER_NUMBER)tmp16s;
+       rd_s16b(&tmp16s);
+       r_ptr->r_pkills = (MONSTER_NUMBER)tmp16s;
        if (h_older_than(1, 7, 0, 5))
        {
                r_ptr->r_akills = r_ptr->r_pkills;
        }
        else
        {
-               rd_s16b(&r_ptr->r_akills);
+               rd_s16b(&tmp16s);
+               r_ptr->r_akills = (MONSTER_NUMBER)tmp16s; 
        }
-       rd_s16b(&r_ptr->r_tkills);
+       rd_s16b(&tmp16s);
+       r_ptr->r_tkills = (MONSTER_NUMBER)tmp16s;
 
        /* Count wakes and ignores */
        rd_byte(&r_ptr->r_wake);
@@ -1182,8 +1191,10 @@ static void rd_lore(MONRACE_IDX r_idx)
        rd_byte(&r_ptr->r_xtra2);
 
        /* Count drops */
-       rd_byte(&r_ptr->r_drop_gold);
-       rd_byte(&r_ptr->r_drop_item);
+       rd_byte(&tmp8u);
+       r_ptr->r_drop_gold = (ITEM_NUMBER)tmp8u;
+       rd_byte(&tmp8u);
+       r_ptr->r_drop_item = (ITEM_NUMBER)tmp8u;
 
        /* Count spells */
        rd_byte(&tmp8u);
@@ -1244,7 +1255,8 @@ static void rd_lore(MONRACE_IDX r_idx)
        }
 
        /* Read the "Racial" monster limit per level */
-       rd_byte(&r_ptr->max_num);
+       rd_byte(&tmp8u);
+       r_ptr->max_num = (MONSTER_NUMBER)tmp8u;
 
        /* Location in saved floor */
        rd_s16b(&r_ptr->floor_id);
@@ -1466,16 +1478,12 @@ static void rd_options(void)
 
        u16b c;
 
-       u32b flag[8];
-       u32b mask[8];
-
-
-       /*** Oops ***/
+       BIT_FLAGS flag[8];
+       BIT_FLAGS mask[8];
 
        /* Ignore old options */
        strip_bytes(16);
 
-
        /*** Special info */
 
        /* Read "delay_factor" */
@@ -1513,6 +1521,7 @@ static void rd_options(void)
        cheat_save = (c & 0x4000) ? TRUE : FALSE;
        cheat_diary_output = (c & 0x8000) ? TRUE : FALSE;
        cheat_turn = (c & 0x0080) ? TRUE : FALSE;
+       cheat_sight = (c & 0x0040) ? TRUE : FALSE;
 
        rd_byte((byte *)&autosave_l);
        rd_byte((byte *)&autosave_t);
@@ -1628,7 +1637,7 @@ static void rd_options(void)
  * @brief ダミー情報スキップ / Hack -- strip the "ghost" info
  * @return なし
  * @details
- * XXX XXX XXX This is such a nasty hack it hurts.
+ * This is such a nasty hack it hurts.
  */
 static void rd_ghost(void)
 {
@@ -1737,7 +1746,7 @@ static void rd_extra(void)
        p_ptr->realm1 = (REALM_IDX)tmp8u;
        rd_byte(&tmp8u);
        p_ptr->realm2 = (REALM_IDX)tmp8u;
-       rd_byte(&tmp8u); /* oops */
+       rd_byte(&tmp8u);
 
        if (z_older_than(10, 4, 4))
        {
@@ -1762,8 +1771,7 @@ static void rd_extra(void)
        for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_max_max[i]);
        for (i = 0; i < 6; i++) rd_s16b(&p_ptr->stat_cur[i]);
 
-       strip_bytes(24); /* oops */
-
+       strip_bytes(24);
        rd_s32b(&p_ptr->au);
 
        rd_s32b(&p_ptr->max_exp);
@@ -2001,7 +2009,7 @@ static void rd_extra(void)
                }
        }
 
-       /* Repair maximum player level XXX XXX XXX */
+       /* Repair maximum player level */
        if (p_ptr->max_plv < p_ptr->lev) p_ptr->max_plv = p_ptr->lev;
 
        /* More info */
@@ -2195,8 +2203,9 @@ static void rd_extra(void)
        rd_byte(&tmp8u);
        p_ptr->autopick_autoregister = tmp8u ? TRUE : FALSE;
 
-       rd_byte(&tmp8u); /* oops */
-       rd_byte(&p_ptr->action);
+       rd_byte(&tmp8u);
+       rd_byte(&tmp8u);
+       p_ptr->action = (ACTION_IDX)tmp8u;
        if (!z_older_than(10, 4, 3))
        {
                rd_byte(&tmp8u);
@@ -2425,7 +2434,6 @@ static errr rd_inventory(void)
                /* Warning -- backpack is full */
                else if (inven_cnt == INVEN_PACK)
                {
-                       /* Oops */
                        note(_("持ち物の中のアイテムが多すぎる!", "Too many items in the inventory!"));
 
                        /* Fail */
@@ -2465,6 +2473,7 @@ static void rd_messages(void)
 {
        int i;
        char buf[128];
+       int message_max;
 
 
        if (h_older_than(2, 2, 0, 75))
@@ -2472,9 +2481,10 @@ static void rd_messages(void)
                u16b num;
                /* Total */
                rd_u16b(&num);
+               message_max = (int)num;
 
                /* Read the messages */
-               for (i = 0; i < num; i++)
+               for (i = 0; i < message_max; i++)
                {
                        /* Read the message */
                        rd_string(buf, sizeof(buf));
@@ -2488,9 +2498,10 @@ static void rd_messages(void)
                u32b num;
                /* Total */
                rd_u32b(&num);
+               message_max = (int)num;
 
                /* Read the messages */
-               for (i = 0; i < num; i++)
+               for (i = 0; i < message_max; i++)
                {
                        /* Read the message */
                        rd_string(buf, sizeof(buf));
@@ -2559,7 +2570,8 @@ static errr rd_dungeon_old(void)
        rd_s16b(&tmp16s);
        base_level = (DEPTH)tmp16s;
 
-       rd_s16b(&num_repro);
+       rd_s16b(&tmp16s);
+       num_repro = (MONSTER_NUMBER)tmp16s;
        rd_s16b(&tmp16s);
        p_ptr->y = (POSITION)tmp16s;
        rd_s16b(&tmp16s);
@@ -2831,7 +2843,7 @@ static errr rd_dungeon_old(void)
        /* Read the dungeon items */
        for (i = 1; i < limit; i++)
        {
-               IDX o_idx;
+               OBJECT_IDX o_idx;
 
                object_type *o_ptr;
 
@@ -2839,7 +2851,6 @@ static errr rd_dungeon_old(void)
                /* Get a new record */
                o_idx = o_pop();
 
-               /* Oops */
                if (i != o_idx)
                {
                        note(format(_("アイテム配置エラー (%d <> %d)", "Object allocation error (%d <> %d)"), i, o_idx));
@@ -2854,7 +2865,7 @@ static errr rd_dungeon_old(void)
                rd_item(o_ptr);
 
 
-               /* XXX XXX XXX XXX XXX */
+               /* XXX XXX */
 
                /* Monster */
                if (o_ptr->held_m_idx)
@@ -2907,7 +2918,6 @@ static errr rd_dungeon_old(void)
                /* Get a new record */
                m_idx = m_pop();
 
-               /* Oops */
                if (i != m_idx)
                {
                        note(format(_("モンスター配置エラー (%d <> %d)", "Monster allocation error (%d <> %d)"), i, m_idx));
@@ -3019,7 +3029,8 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
 
        rd_s16b(&tmp16s);
        base_level = (DEPTH)tmp16s;
-       rd_s16b(&num_repro);
+       rd_s16b(&tmp16s);
+       num_repro = (MONSTER_NUMBER)tmp16s;
 
        rd_u16b(&tmp16u);
        p_ptr->y = (POSITION)tmp16u;
@@ -3050,7 +3061,8 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
                cave_template_type *ct_ptr = &templates[i];
 
                /* Read it */
-               rd_u16b(&ct_ptr->info);
+               rd_u16b(&tmp16u);
+               ct_ptr->info = (BIT_FLAGS)tmp16u;
                if (h_older_than(1, 7, 0, 2))
                {
                        rd_byte(&tmp8u);
@@ -3157,14 +3169,13 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
        /* Read the dungeon items */
        for (i = 1; i < limit; i++)
        {
-               IDX o_idx;
+               OBJECT_IDX o_idx;
                object_type *o_ptr;
 
 
                /* Get a new record */
                o_idx = o_pop();
 
-               /* Oops */
                if (i != o_idx) return 152;
 
                /* Acquire place */
@@ -3222,7 +3233,6 @@ static errr rd_saved_floor(saved_floor_type *sf_ptr)
                /* Get a new record */
                m_idx = m_pop();
 
-               /* Oops */
                if (i != m_idx) return 162;
 
 
@@ -3311,7 +3321,8 @@ static errr rd_dungeon(void)
                        saved_floor_type *sf_ptr = &saved_floors[i];
 
                        rd_s16b(&sf_ptr->floor_id);
-                       rd_byte(&sf_ptr->savefile_id);
+                       rd_byte(&tmp8u);
+                       sf_ptr->savefile_id = (s16b)tmp8u;
 
                        rd_s16b(&tmp16s);
                        sf_ptr->dun_level = (DEPTH)tmp16s;
@@ -3565,7 +3576,7 @@ static errr rd_savefile_new_aux(void)
                }
 
                /* Incompatible save files */
-               if (max_quests_load > max_quests)
+               if (max_quests_load > max_q_idx)
                {
                        note(format(_("クエストが多すぎる(%u)!", "Too many (%u) quests!"), max_quests_load));
                        return (23);
@@ -3573,7 +3584,7 @@ static errr rd_savefile_new_aux(void)
 
                for (i = 0; i < max_quests_load; i++)
                {
-                       if (i < max_quests)
+                       if (i < max_q_idx)
                        {
                                quest_type* const q_ptr = &quest[i];
                                
@@ -3905,7 +3916,7 @@ static errr rd_savefile_new_aux(void)
 
        if (!z_older_than(11, 0, 9))
        {
-               char buf[SCREEN_BUF_SIZE];
+               char buf[SCREEN_BUF_MAX_SIZE];
                rd_string(buf, sizeof(buf));
                if (buf[0]) screen_dump = string_make(buf);
        }