+ return (152);
+ }
+
+
+ /* Acquire place */
+ o_ptr = &o_list[o_idx];
+
+ /* Read the item */
+ rd_item(o_ptr);
+
+
+ /* XXX XXX XXX XXX XXX */
+
+ /* Monster */
+ if (o_ptr->held_m_idx)
+ {
+ monster_type *m_ptr;
+
+ /* Monster */
+ m_ptr = &m_list[o_ptr->held_m_idx];
+
+ /* Build a stack */
+ o_ptr->next_o_idx = m_ptr->hold_o_idx;
+
+ /* Place the object */
+ m_ptr->hold_o_idx = o_idx;
+ }
+
+ /* Dungeon */
+ else
+ {
+ /* Access the item location */
+ c_ptr = &cave[o_ptr->iy][o_ptr->ix];
+
+ /* Build a stack */
+ o_ptr->next_o_idx = c_ptr->o_idx;
+
+ /* Place the object */
+ c_ptr->o_idx = o_idx;
+ }
+ }
+
+
+ /*** Monsters ***/
+
+ /* Read the monster count */
+ rd_u16b(&limit);
+
+ /* Hack -- verify */
+ if (limit > max_m_idx)
+ {
+#ifdef JP
+note(format("¥â¥ó¥¹¥¿¡¼¤ÎÇÛÎó¤¬Â礤¹¤®¤ë(%d)¡ª", limit));
+#else
+ note(format("Too many (%d) monster entries!", limit));
+#endif
+
+ return (161);
+ }
+
+ /* Read the monsters */
+ for (i = 1; i < limit; i++)
+ {
+ int m_idx;
+ monster_type *m_ptr;
+
+ /* Get a new record */
+ m_idx = m_pop();
+
+ /* Oops */
+ if (i != m_idx)
+ {
+#ifdef JP
+note(format("¥â¥ó¥¹¥¿¡¼ÇÛÃÖ¥¨¥é¡¼ (%d <> %d)", i, m_idx));
+#else
+ note(format("Monster allocation error (%d <> %d)", i, m_idx));
+#endif
+
+ return (162);
+ }
+
+
+ /* Acquire monster */
+ m_ptr = &m_list[m_idx];
+
+ /* Read the monster */
+ rd_monster(m_ptr);
+
+
+ /* Access grid */
+ c_ptr = &cave[m_ptr->fy][m_ptr->fx];
+
+ /* Mark the location */
+ c_ptr->m_idx = m_idx;
+
+ /* Count */
+ real_r_ptr(m_ptr)->cur_num++;
+ }
+
+ /*** Success ***/
+
+ /* The dungeon is ready */
+ if (z_older_than(10, 3, 13) && !dun_level && !p_ptr->inside_arena)
+ character_dungeon = FALSE;
+ else
+ character_dungeon = TRUE;
+
+ /* Success */
+ return (0);
+}
+
+
+
+/*
+ * Read the saved floor
+ *
+ * The monsters/objects must be loaded in the same order
+ * that they were stored, since the actual indexes matter.
+ */
+static errr rd_saved_floor(saved_floor_type *sf_ptr)
+{
+ int ymax, xmax;
+ int i, y, x;
+ byte count;
+ byte tmp8u;
+ s16b tmp16s;
+ u16b tmp16u;
+ s32b tmp32s;
+ u32b tmp32u;
+ u16b limit;
+
+ cave_template_type *template;
+
+
+ /*** Wipe all cave ***/
+ clear_cave();
+
+
+ /*** Basic info ***/
+
+ /* Dungeon floor specific info follows */
+
+ if (!sf_ptr)
+ {
+ /*** Not a saved floor ***/
+
+ rd_s16b(&dun_level);
+ base_level = dun_level;
+ }
+ else
+ {
+ /*** The saved floor ***/
+
+ rd_s16b(&tmp16s);
+ if (tmp16s != sf_ptr->floor_id) return 171;
+
+ rd_byte(&tmp8u);
+ if (tmp8u != sf_ptr->savefile_id) return 171;
+
+ rd_s16b(&tmp16s);
+ if (tmp16s != sf_ptr->dun_level) return 171;
+ dun_level = sf_ptr->dun_level;
+
+ rd_s32b(&tmp32s);
+ if (tmp32s != sf_ptr->last_visit) return 171;
+
+ rd_u32b(&tmp32u);
+ if (tmp32u != sf_ptr->visit_mark) return 171;
+
+ rd_s16b(&tmp16s);
+ if (tmp16s != sf_ptr->upper_floor_id) return 171;
+
+ rd_s16b(&tmp16s);
+ if (tmp16s != sf_ptr->lower_floor_id) return 171;
+ }
+
+ rd_s16b(&base_level);
+ rd_s16b(&num_repro);
+
+ rd_u16b(&tmp16u);
+ py = (int)tmp16u;
+
+ rd_u16b(&tmp16u);
+ px = (int)tmp16u;
+
+ rd_s16b(&cur_hgt);
+ rd_s16b(&cur_wid);
+
+ rd_byte(&p_ptr->feeling);
+
+
+
+ /*** Read template for cave_type ***/
+
+ /* Read the template count */
+ rd_u16b(&limit);
+
+ /* Allocate the "template" array */
+ C_MAKE(template, limit, cave_template_type);
+
+ /* Read the templates */
+ for (i = 0; i < limit; i++)
+ {
+ cave_template_type *ct_ptr = &template[i];
+
+ /* Read it */
+ rd_u16b(&ct_ptr->info);
+ if (h_older_than(1, 7, 0, 2))
+ {
+ rd_byte(&tmp8u);
+ ct_ptr->feat = (s16b)tmp8u;
+ rd_byte(&tmp8u);
+ ct_ptr->mimic = (s16b)tmp8u;
+ }
+ else
+ {
+ rd_s16b(&ct_ptr->feat);
+ rd_s16b(&ct_ptr->mimic);
+ }
+ rd_s16b(&ct_ptr->special);
+ }
+
+ /* Maximal size */
+ ymax = cur_hgt;
+ xmax = cur_wid;
+
+
+ /*** Run length decoding ***/
+
+ /* Load the dungeon data */
+ for (x = y = 0; y < ymax; )
+ {
+ u16b id;
+
+ /* Grab RLE info */
+ rd_byte(&count);
+
+ id = 0;
+ do
+ {
+ rd_byte(&tmp8u);
+ id += tmp8u;
+ } while (tmp8u == MAX_UCHAR);
+
+ /* Apply the RLE info */
+ for (i = count; i > 0; i--)
+ {
+ /* Access the cave */
+ cave_type *c_ptr = &cave[y][x];
+
+ /* Extract cave data */
+ c_ptr->info = template[id].info;
+ c_ptr->feat = template[id].feat;
+ c_ptr->mimic = template[id].mimic;
+ c_ptr->special = template[id].special;
+
+ /* Advance/Wrap */
+ if (++x >= xmax)
+ {
+ /* Wrap */
+ x = 0;
+
+ /* Advance/Wrap */
+ if (++y >= ymax) break;
+ }
+ }
+ }
+
+ /* Quest 18 was removed */
+ if (h_older_than(1, 7, 0, 6) && !vanilla_town)
+ {
+ for (y = 0; y < ymax; y++) for (x = 0; x < xmax; x++)
+ {
+ /* Access the cave */
+ cave_type *c_ptr = &cave[y][x];
+
+ if ((c_ptr->special == OLD_QUEST_WATER_CAVE) && !dun_level)
+ {
+ if (c_ptr->feat == OLD_FEAT_QUEST_ENTER)
+ {
+ c_ptr->feat = feat_tree;
+ c_ptr->special = 0;
+ }
+ else if (c_ptr->feat == OLD_FEAT_BLDG_1)
+ {
+ c_ptr->special = lite_town ? QUEST_OLD_CASTLE : QUEST_ROYAL_CRYPT;
+ }
+ }
+ else if ((c_ptr->feat == OLD_FEAT_QUEST_EXIT) &&
+ (p_ptr->inside_quest == OLD_QUEST_WATER_CAVE))
+ {
+ c_ptr->feat = feat_up_stair;
+ c_ptr->special = 0;
+ }
+ }
+ }
+
+ /* Free the "template" array */
+ C_FREE(template, limit, cave_template_type);
+
+
+ /*** Objects ***/
+
+ /* Read the item count */
+ rd_u16b(&limit);
+
+ /* Verify maximum */
+ if (limit > max_o_idx) return 151;
+
+
+ /* Read the dungeon items */
+ for (i = 1; i < limit; i++)
+ {
+ int o_idx;
+ object_type *o_ptr;
+