OSDN Git Service

refactor lite flags
[hengband/hengband.git] / src / save.c
index 170e888..d8ef353 100644 (file)
@@ -186,18 +186,19 @@ static void wr_item(object_type *o_ptr)
 static void wr_monster(monster_type *m_ptr)
 {
        u32b flags = 0x00000000;
+       byte tmp8u;
 
-       if (m_ptr->ap_r_idx != m_ptr->r_idx) flags |= SAVE_MON_AP_R_IDX;
+       if (!is_original_ap(m_ptr)) flags |= SAVE_MON_AP_R_IDX;
        if (m_ptr->sub_align) flags |= SAVE_MON_SUB_ALIGN;
-       if (m_ptr->csleep) flags |= SAVE_MON_CSLEEP;
-       if (m_ptr->fast) flags |= SAVE_MON_FAST;
-       if (m_ptr->slow) flags |= SAVE_MON_SLOW;
-       if (m_ptr->stunned) flags |= SAVE_MON_STUNNED;
-       if (m_ptr->confused) flags |= SAVE_MON_CONFUSED;
-       if (m_ptr->monfear) flags |= SAVE_MON_MONFEAR;
+       if (MON_CSLEEP(m_ptr)) flags |= SAVE_MON_CSLEEP;
+       if (MON_FAST(m_ptr)) flags |= SAVE_MON_FAST;
+       if (MON_SLOW(m_ptr)) flags |= SAVE_MON_SLOW;
+       if (MON_STUNNED(m_ptr)) flags |= SAVE_MON_STUNNED;
+       if (MON_CONFUSED(m_ptr)) flags |= SAVE_MON_CONFUSED;
+       if (MON_MONFEAR(m_ptr)) flags |= SAVE_MON_MONFEAR;
        if (m_ptr->target_y) flags |= SAVE_MON_TARGET_Y;
        if (m_ptr->target_x) flags |= SAVE_MON_TARGET_X;
-       if (m_ptr->invulner) flags |= SAVE_MON_INVULNER;
+       if (MON_INVULNER(m_ptr)) flags |= SAVE_MON_INVULNER;
        if (m_ptr->smart) flags |= SAVE_MON_SMART;
        if (m_ptr->exp) flags |= SAVE_MON_EXP;
        if (m_ptr->mflag2) flags |= SAVE_MON_MFLAG2;
@@ -214,24 +215,50 @@ static void wr_monster(monster_type *m_ptr)
        wr_s16b(m_ptr->hp);
        wr_s16b(m_ptr->maxhp);
        wr_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);
 
        if (flags & SAVE_MON_SUB_ALIGN) wr_byte(m_ptr->sub_align);
-       if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->csleep);
+       if (flags & SAVE_MON_CSLEEP) wr_s16b(m_ptr->mtimed[MTIMED_CSLEEP]);
 
        wr_byte(m_ptr->mspeed);
        wr_s16b(m_ptr->energy_need);
 
-       if (flags & SAVE_MON_FAST) wr_byte(m_ptr->fast);
-       if (flags & SAVE_MON_SLOW) wr_byte(m_ptr->slow);
-       if (flags & SAVE_MON_STUNNED) wr_byte(m_ptr->stunned);
-       if (flags & SAVE_MON_CONFUSED) wr_byte(m_ptr->confused);
-       if (flags & SAVE_MON_MONFEAR) wr_byte(m_ptr->monfear);
+       if (flags & SAVE_MON_FAST)
+       {
+               tmp8u = (byte)m_ptr->mtimed[MTIMED_FAST];
+               wr_byte(tmp8u);
+       }
+       if (flags & SAVE_MON_SLOW)
+       {
+               tmp8u = (byte)m_ptr->mtimed[MTIMED_SLOW];
+               wr_byte(tmp8u);
+       }
+       if (flags & SAVE_MON_STUNNED)
+       {
+               tmp8u = (byte)m_ptr->mtimed[MTIMED_STUNNED];
+               wr_byte(tmp8u);
+       }
+       if (flags & SAVE_MON_CONFUSED)
+       {
+               tmp8u = (byte)m_ptr->mtimed[MTIMED_CONFUSED];
+               wr_byte(tmp8u);
+       }
+       if (flags & SAVE_MON_MONFEAR)
+       {
+               tmp8u = (byte)m_ptr->mtimed[MTIMED_MONFEAR];
+               wr_byte(tmp8u);
+       }
        if (flags & SAVE_MON_TARGET_Y) wr_s16b(m_ptr->target_y);
        if (flags & SAVE_MON_TARGET_X) wr_s16b(m_ptr->target_x);
-       if (flags & SAVE_MON_INVULNER) wr_byte(m_ptr->invulner);
+       if (flags & SAVE_MON_INVULNER)
+       {
+               tmp8u = (byte)m_ptr->mtimed[MTIMED_INVULNER];
+               wr_byte(tmp8u);
+       }
        if (flags & SAVE_MON_SMART) wr_u32b(m_ptr->smart);
        if (flags & SAVE_MON_EXP) wr_u32b(m_ptr->exp);
        if (flags & SAVE_MON_MFLAG2) wr_byte(m_ptr->mflag2);
@@ -251,6 +278,7 @@ static void wr_lore(int r_idx)
        wr_s16b(r_ptr->r_sights);
        wr_s16b(r_ptr->r_deaths);
        wr_s16b(r_ptr->r_pkills);
+       wr_s16b(r_ptr->r_akills);
        wr_s16b(r_ptr->r_tkills);
 
        /* Count wakes and ignores */
@@ -644,7 +672,7 @@ static void wr_extra(void)
        wr_s16b(0);     /* oops */
        wr_s16b(0);     /* oops */
        wr_s16b(p_ptr->sc);
-       wr_s16b(0);     /* oops */
+       wr_s16b(p_ptr->concent);
 
        wr_s16b(0);             /* old "rest" */
        wr_s16b(p_ptr->blind);
@@ -654,6 +682,7 @@ static void wr_extra(void)
        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);
@@ -686,7 +715,7 @@ static void wr_extra(void)
        wr_s16b(p_ptr->tim_regen);
        wr_s16b(p_ptr->kabenuke);
        wr_s16b(p_ptr->tim_stealth);
-       wr_s16b(p_ptr->tim_ffall);
+       wr_s16b(p_ptr->tim_levitation);
        wr_s16b(p_ptr->tim_sh_touki);
        wr_s16b(p_ptr->lightspeed);
        wr_s16b(p_ptr->tsubureru);
@@ -750,11 +779,14 @@ static void wr_extra(void)
        wr_byte(p_ptr->is_dead);
 
        /* Write feeling */
-       wr_byte(feeling);
+       wr_byte(p_ptr->feeling);
 
-       /* Turn of last "feeling" */
+       /* Turn when level began */
        wr_s32b(old_turn);
 
+       /* Turn of last "feeling" */
+       wr_s32b(p_ptr->feeling_turn);
+
        /* Current turn */
        wr_s32b(turn);
 
@@ -823,7 +855,7 @@ static void ang_sort_swap_cave_temp(vptr u, vptr v, int a, int b)
  */
 static void wr_saved_floor(saved_floor_type *sf_ptr)
 {
-       cave_template_type *template;
+       cave_template_type *templates;
        u16b max_num_temp;
        u16b num_temp = 0;
        int dummy_why;
@@ -865,7 +897,7 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        wr_u16b((u16b)px);
        wr_u16b(cur_hgt);
        wr_u16b(cur_wid);
-       wr_byte(feeling);
+       wr_byte(p_ptr->feeling);
 
 
 
@@ -886,7 +918,7 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        max_num_temp = 255;
 
        /* Allocate the "template" array */
-       C_MAKE(template, max_num_temp, cave_template_type);
+       C_MAKE(templates, max_num_temp, cave_template_type);
 
        /* Extract template array */
        for (y = 0; y < cur_hgt; y++)
@@ -897,13 +929,13 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
 
                        for (i = 0; i < num_temp; i++)
                        {
-                               if (template[i].info == c_ptr->info &&
-                                   template[i].feat == c_ptr->feat &&
-                                   template[i].mimic == c_ptr->mimic &&
-                                   template[i].special == c_ptr->special)
+                               if (templates[i].info == c_ptr->info &&
+                                   templates[i].feat == c_ptr->feat &&
+                                   templates[i].mimic == c_ptr->mimic &&
+                                   templates[i].special == c_ptr->special)
                                {
                                        /* Same terrain is exist */
-                                       template[i].occurrence++;
+                                       templates[i].occurrence++;
                                        break;
                                }
                        }
@@ -914,21 +946,21 @@ 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 = template;
+                               cave_template_type *old_template = templates;
 
                                /* Re-allocate the "template" array */
-                               C_MAKE(template, max_num_temp + 255, cave_template_type);
-                               C_COPY(template, old_template, max_num_temp, cave_template_type);
-                               C_FREE(old_template, max_num_temp, cave_template_type);
+                               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);
                                max_num_temp += 255;
                        }
 
                        /* Add new template */
-                       template[num_temp].info = c_ptr->info;
-                       template[num_temp].feat = c_ptr->feat;
-                       template[num_temp].mimic = c_ptr->mimic;
-                       template[num_temp].special = c_ptr->special;
-                       template[num_temp].occurrence = 1;
+                       templates[num_temp].info = c_ptr->info;
+                       templates[num_temp].feat = c_ptr->feat;
+                       templates[num_temp].mimic = c_ptr->mimic;
+                       templates[num_temp].special = c_ptr->special;
+                       templates[num_temp].occurrence = 1;
 
                        /* Increase number of template */
                        num_temp++;
@@ -940,7 +972,7 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        ang_sort_swap = ang_sort_swap_cave_temp;
 
        /* Sort by occurrence */
-       ang_sort(template, &dummy_why, num_temp);
+       ang_sort(templates, &dummy_why, num_temp);
 
 
        /*** Dump templates ***/
@@ -951,7 +983,7 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
        /* Dump the templates */
        for (i = 0; i < num_temp; i++)
        {
-               cave_template_type *ct_ptr = &template[i];
+               cave_template_type *ct_ptr = &templates[i];
 
                /* Dump it */
                wr_u16b(ct_ptr->info);
@@ -977,10 +1009,10 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
 
                        for (i = 0; i < num_temp; i++)
                        {
-                               if (template[i].info == c_ptr->info &&
-                                   template[i].feat == c_ptr->feat &&
-                                   template[i].mimic == c_ptr->mimic &&
-                                   template[i].special == c_ptr->special)
+                               if (templates[i].info == c_ptr->info &&
+                                   templates[i].feat == c_ptr->feat &&
+                                   templates[i].mimic == c_ptr->mimic &&
+                                   templates[i].special == c_ptr->special)
                                        break;
                        }
 
@@ -1028,7 +1060,7 @@ static void wr_saved_floor(saved_floor_type *sf_ptr)
 
 
        /* Free the "template" array */
-       C_FREE(template, max_num_temp, cave_template_type);
+       C_KILL(templates, max_num_temp, cave_template_type);
 
 
        /*** Dump objects ***/
@@ -1088,7 +1120,7 @@ static bool wr_dungeon(void)
 
        /*** Meta info ***/
 
-        /* Number of floor_id used from birth */
+       /* Number of floor_id used from birth */
        wr_s16b(max_floor_id);
 
        /* Current dungeon type */
@@ -1303,25 +1335,28 @@ static bool wr_savefile_new(void)
 
        for (i = 0; i < max_quests; i++)
        {
+               quest_type* const q_ptr = &quest[i];
+
                /* Save status for every quest */
-               wr_s16b(quest[i].status);
+               wr_s16b(q_ptr->status);
 
                /* And the dungeon level too */
                /* (prevents problems with multi-level quests) */
-               wr_s16b(quest[i].level);
+               wr_s16b(q_ptr->level);
 
-               wr_byte(quest[i].complev);
+               wr_byte(q_ptr->complev);
+               wr_u32b(q_ptr->comptime);
 
                /* Save quest status if quest is running */
-               if (quest[i].status == QUEST_STATUS_TAKEN || quest[i].status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
+               if (q_ptr->status == QUEST_STATUS_TAKEN || q_ptr->status == QUEST_STATUS_COMPLETED || !is_fixed_quest_idx(i))
                {
-                       wr_s16b(quest[i].cur_num);
-                       wr_s16b(quest[i].max_num);
-                       wr_s16b(quest[i].type);
-                       wr_s16b(quest[i].r_idx);
-                       wr_s16b(quest[i].k_idx);
-                       wr_byte(quest[i].flags);
-                       wr_byte(quest[i].dungeon);
+                       wr_s16b(q_ptr->cur_num);
+                       wr_s16b(q_ptr->max_num);
+                       wr_s16b(q_ptr->type);
+                       wr_s16b(q_ptr->r_idx);
+                       wr_s16b(q_ptr->k_idx);
+                       wr_byte(q_ptr->flags);
+                       wr_byte(q_ptr->dungeon);
                }
        }
 
@@ -1939,9 +1974,6 @@ bool load_player(void)
                        /* Count lives */
                        sf_lives++;
 
-                       /* Forget turns */
-                       turn = old_turn = 0;
-
                        /* Done */
                        return (TRUE);
                }