OSDN Git Service

Changed to match the For2.2.2-Refactoring-Cocoa2 branch. Put se_maoudamashii_voice_m...
[hengbandforosx/hengbandosx.git] / src / floor-save.c
index f2128fc..225d4ab 100644 (file)
  */
 
 #include "angband.h"
+#include "floor.h"
 #include "generate.h"
 #include "grid.h"
+#include "monster.h"
+#include "quest.h"
+#include "wild.h"
+#include "spells-floor.h"
+#include "monster-status.h"
 
 
-static s16b new_floor_id;       /*!<次のフロアのID / floor_id of the destination */
+static FLOOR_IDX new_floor_id;  /*!<次のフロアのID / floor_id of the destination */
 static u32b change_floor_mode;  /*!<フロア移行処理に関するフラグ / Mode flags for changing floor */
 static u32b latest_visit_mark;  /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */
 
@@ -23,7 +29,7 @@ static u32b latest_visit_mark;  /*!<フロアを渡った回数?(確認中) /
 /*!
  * @brief 保存フロア配列を初期化する / Initialize saved_floors array. 
  * @param force テンポラリファイルが残っていた場合も警告なしで強制的に削除する。
- * @details Make sure that old temporal files are not remaining as gurbages.
+ * @details Make sure that old temporary files are not remaining as gurbages.
  * @return なし
  */
 void init_saved_floors(bool force)
@@ -44,46 +50,48 @@ void init_saved_floors(bool force)
        {
                saved_floor_type *sf_ptr = &saved_floors[i];
 
-               /* File name */
-               sprintf(floor_savefile, "%s.F%02d", savefile, i);
+               if (savefile[0]) {
+                       /* File name */
+                       sprintf(floor_savefile, "%s.F%02d", savefile, i);
 
-               /* Grab permissions */
-               safe_setuid_grab();
+                       /* Grab permissions */
+                       safe_setuid_grab();
 
-               /* Try to create the file */
-               fd = fd_make(floor_savefile, mode);
+                       /* Try to create the file */
+                       fd = fd_make(floor_savefile, mode);
 
-               /* Drop permissions */
-               safe_setuid_drop();
+                       /* Drop permissions */
+                       safe_setuid_drop();
 
-               /* Failed! */
-               if (fd < 0)
-               {
-                       if (!force)
+                       /* Failed! */
+                       if (fd < 0)
                        {
-                               msg_print(_("エラー:古いテンポラリ・ファイルが残っています。", "Error: There are old temporal files."));
-                               msg_print(_("変愚蛮怒を二重に起動していないか確認してください。", "Make sure you are not running two game processes simultaneously."));
-                               msg_print(_("過去に変愚蛮怒がクラッシュした場合は一時ファイルを", "If the temporal files are garbages of old crashed process, "));
-                               msg_print(_("強制的に削除して実行を続けられます。", "you can delete it safely."));
-                               if (!get_check(_("強制的に削除してもよろしいですか?", "Do you delete old temporal files? ")))
-                                       quit(_("実行中止", "Aborted."));
-                               force = TRUE;
+                               if (!force)
+                               {
+                                       msg_print(_("エラー:古いテンポラリ・ファイルが残っています。", "Error: There are old temporary files."));
+                                       msg_print(_("変愚蛮怒を二重に起動していないか確認してください。", "Make sure you are not running two game processes simultaneously."));
+                                       msg_print(_("過去に変愚蛮怒がクラッシュした場合は一時ファイルを", "If the temporary files are garbage from an old crashed process, "));
+                                       msg_print(_("強制的に削除して実行を続けられます。", "you can delete them safely."));
+                                       if (!get_check(_("強制的に削除してもよろしいですか?", "Do you delete the old temporary files? ")))
+                                               quit(_("実行中止", "Aborted."));
+                                       force = TRUE;
+                               }
+                       }
+                       else
+                       {
+                               /* Close the "fd" */
+                               (void)fd_close(fd);
                        }
-               }
-               else
-               {
-                       /* Close the "fd" */
-                       (void)fd_close(fd);
-               }
 
-               /* Grab permissions */
-               safe_setuid_grab();
+                       /* Grab permissions */
+                       safe_setuid_grab();
 
-               /* Simply kill the temporal file */ 
-               (void)fd_kill(floor_savefile);
+                       /* Simply kill the temporary file */ 
+                       (void)fd_kill(floor_savefile);
 
-               /* Drop permissions */
-               safe_setuid_drop();
+                       /* Drop permissions */
+                       safe_setuid_drop();
+               }
 
                sf_ptr->floor_id = 0;
        }
@@ -94,7 +102,7 @@ void init_saved_floors(bool force)
        /* vist_mark is from 1 */
        latest_visit_mark = 1;
 
-       /* A sign to mark temporal files */
+       /* A sign to mark temporary files */
        saved_floor_file_sign = (u32b)time(NULL);
 
        /* No next floor yet */
@@ -112,7 +120,7 @@ void init_saved_floors(bool force)
 }
 
 /*!
- * @brief 保存フロア用テンポラリファイルを削除する / Kill temporal files
+ * @brief 保存フロア用テンポラリファイルを削除する / Kill temporary files
  * @details Should be called just before the game quit.
  * @return なし
  */
@@ -132,7 +140,7 @@ void clear_saved_floor_files(void)
        {
                saved_floor_type *sf_ptr = &saved_floors[i];
 
-               /* No temporal file */
+               /* No temporary file */
                if (!sf_ptr->floor_id) continue;
                if (sf_ptr->floor_id == p_ptr->floor_id) continue;
 
@@ -142,7 +150,7 @@ void clear_saved_floor_files(void)
                /* Grab permissions */
                safe_setuid_grab();
 
-               /* Simply kill the temporal file */ 
+               /* Simply kill the temporary file */ 
                (void)fd_kill(floor_savefile);
 
                /* Drop permissions */
@@ -189,8 +197,6 @@ saved_floor_type *get_sf_ptr(FLOOR_IDX floor_id)
 static void kill_saved_floor(saved_floor_type *sf_ptr)
 {
        char floor_savefile[1024];
-
-       /* Paranoia */
        if (!sf_ptr) return;
 
        /* Already empty */
@@ -201,7 +207,7 @@ static void kill_saved_floor(saved_floor_type *sf_ptr)
                /* Kill current floor */
                p_ptr->floor_id = 0;
 
-               /* Current floor doesn't have temporal file */
+               /* Current floor doesn't have temporary file */
        }
        else 
        {
@@ -211,7 +217,7 @@ static void kill_saved_floor(saved_floor_type *sf_ptr)
                /* Grab permissions */
                safe_setuid_grab();
 
-               /* Simply kill the temporal file */ 
+               /* Simply kill the temporary file */ 
                (void)fd_kill(floor_savefile);
 
                /* Drop permissions */
@@ -229,10 +235,10 @@ static void kill_saved_floor(saved_floor_type *sf_ptr)
  * @details
  * If number of saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
  */
-s16b get_new_floor_id(void)
+FLOOR_IDX get_new_floor_id(void)
 {
        saved_floor_type *sf_ptr = NULL;
-       s16b i;
+       FLOOR_IDX i;
 
        /* Look for empty space */
        for (i = 0; i < MAX_SAVED_FLOORS; i++)
@@ -280,7 +286,7 @@ s16b get_new_floor_id(void)
        sf_ptr->visit_mark = latest_visit_mark++;
 
        /* sf_ptr->dun_level may be changed later */
-       sf_ptr->dun_level = dun_level;
+       sf_ptr->dun_level = current_floor_ptr->dun_level;
 
 
        /* Increment number of floor_id */
@@ -311,15 +317,15 @@ static void build_dead_end(void)
 {
        POSITION x, y;
 
-       /* Clear and empty the cave */
+       /* Clear and empty the current_floor_ptr->grid_array */
        clear_cave();
 
        /* Fill the arrays of floors and walls in the good proportions */
        set_floor_and_wall(0);
 
        /* Smallest area */
-       cur_hgt = SCREEN_HGT;
-       cur_wid = SCREEN_WID;
+       current_floor_ptr->height = SCREEN_HGT;
+       current_floor_ptr->width = SCREEN_WID;
 
        /* Filled with permanent walls */
        for (y = 0; y < MAX_HGT; y++)
@@ -332,13 +338,13 @@ static void build_dead_end(void)
        }
 
        /* Place at center of the floor */
-       p_ptr->y = cur_hgt / 2;
-       p_ptr->x = cur_wid / 2;
+       p_ptr->y = current_floor_ptr->height / 2;
+       p_ptr->x = current_floor_ptr->width / 2;
 
        /* Give one square */
        place_floor_bold(p_ptr->y, p_ptr->x);
 
-       wipe_generate_cave_flags();
+       wipe_generate_random_floor_flags();
 }
 
 
@@ -362,7 +368,7 @@ static void preserve_pet(void)
 
        if (p_ptr->riding)
        {
-               monster_type *m_ptr = &m_list[p_ptr->riding];
+               monster_type *m_ptr = &current_floor_ptr->m_list[p_ptr->riding];
 
                /* Pet of other pet don't follow. */
                if (m_ptr->parent_m_idx)
@@ -389,9 +395,9 @@ static void preserve_pet(void)
        {
                for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
                {
-                       monster_type *m_ptr = &m_list[i];
+                       monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
-                       if (!m_ptr->r_idx) continue;
+                       if (!monster_is_valid(m_ptr)) continue;
                        if (!is_pet(m_ptr)) continue;
                        if (i == p_ptr->riding) continue;
 
@@ -425,7 +431,7 @@ static void preserve_pet(void)
                                }
                        }
 
-                       (void)COPY(&party_mon[num], &m_list[i], monster_type);
+                       (void)COPY(&party_mon[num], &current_floor_ptr->m_list[i], monster_type);
 
                        num++;
 
@@ -438,10 +444,10 @@ static void preserve_pet(void)
        {
                for (i = m_max - 1; i >=1; i--)
                {
-                       monster_type *m_ptr = &m_list[i];
+                       monster_type *m_ptr = &current_floor_ptr->m_list[i];
                        GAME_TEXT m_name[MAX_NLEN];
 
-                       if (!m_ptr->r_idx) continue;
+                       if (!monster_is_valid(m_ptr)) continue;
                        if (!is_pet(m_ptr)) continue;
                        if (!m_ptr->nickname) continue;
                        if (p_ptr->riding == i) continue;
@@ -455,10 +461,10 @@ static void preserve_pet(void)
        /* Pet of other pet may disappear. */
        for (i = m_max - 1; i >=1; i--)
        {
-               monster_type *m_ptr = &m_list[i];
+               monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
                /* Are there its parent? */
-               if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
+               if (m_ptr->parent_m_idx && !current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx)
                {
                        /* Its parent have gone, it also goes away. */
 
@@ -492,7 +498,7 @@ void precalc_cur_num_of_pet(void)
                m_ptr = &party_mon[i];
 
                /* Skip empty monsters */
-               if (!m_ptr->r_idx) continue;
+               if (!monster_is_valid(m_ptr)) continue;
 
                /* Hack -- Increase the racial counter */
                real_r_ptr(m_ptr)->cur_num++;
@@ -530,7 +536,7 @@ static void place_pet(void)
                        int j;
                        POSITION d;
 
-                       for (d = 1; d < 6; d++)
+                       for (d = 1; d < A_MAX; d++)
                        {
                                for (j = 1000; j > 0; j--)
                                {
@@ -544,10 +550,10 @@ static void place_pet(void)
 
                if (m_idx)
                {
-                       monster_type *m_ptr = &m_list[m_idx];
+                       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
                        monster_race *r_ptr;
 
-                       cave[cy][cx].m_idx = m_idx;
+                       current_floor_ptr->grid_array[cy][cx].m_idx = m_idx;
 
                        m_ptr->r_idx = party_mon[i].r_idx;
 
@@ -559,8 +565,6 @@ static void place_pet(void)
                        m_ptr->fx = cx;
                        m_ptr->ml = TRUE;
                        m_ptr->mtimed[MTIMED_CSLEEP] = 0;
-
-                       /* Paranoia */
                        m_ptr->hold_o_idx = 0;
                        m_ptr->target_y = 0;
 
@@ -579,7 +583,7 @@ static void place_pet(void)
                        /* r_ptr->cur_num++; */
 
                        /* Hack -- Count the number of "reproducers" */
-                       if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
+                       if (r_ptr->flags2 & RF2_MULTIPLY) current_floor_ptr->num_repro++;
 
                        /* Hack -- Notice new multi-hued monsters */
                        {
@@ -629,10 +633,9 @@ static void update_unique_artifact(s16b cur_floor_id)
        for (i = 1; i < m_max; i++)
        {
                monster_race *r_ptr;
-               monster_type *m_ptr = &m_list[i];
+               monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
-               /* Skip dead monsters */
-               if (!m_ptr->r_idx) continue;
+               if (!monster_is_valid(m_ptr)) continue;
 
                /* Extract real monster race */
                r_ptr = real_r_ptr(m_ptr);
@@ -648,7 +651,7 @@ static void update_unique_artifact(s16b cur_floor_id)
        /* Maintain artifatcs */
        for (i = 1; i < o_max; i++)
        {
-               object_type *o_ptr = &o_list[i];
+               object_type *o_ptr = &current_floor_ptr->o_list[i];
 
                /* Skip dead objects */
                if (!o_ptr->k_idx) continue;
@@ -672,7 +675,7 @@ static void get_out_monster(void)
        POSITION dis = 1;
        POSITION oy = p_ptr->y;
        POSITION ox = p_ptr->x;
-       MONSTER_IDX m_idx = cave[oy][ox].m_idx;
+       MONSTER_IDX m_idx = current_floor_ptr->grid_array[oy][ox].m_idx;
 
        /* Nothing to do if no monster */
        if (!m_idx) return;
@@ -704,21 +707,21 @@ static void get_out_monster(void)
                if (!cave_empty_bold(ny, nx)) continue;
 
                /* Hack -- no teleport onto glyph of warding */
-               if (is_glyph_grid(&cave[ny][nx])) continue;
-               if (is_explosive_rune_grid(&cave[ny][nx])) continue;
+               if (is_glyph_grid(&current_floor_ptr->grid_array[ny][nx])) continue;
+               if (is_explosive_rune_grid(&current_floor_ptr->grid_array[ny][nx])) continue;
 
                /* ...nor onto the Pattern */
                if (pattern_tile(ny, nx)) continue;
 
                /*** It's a good place ***/
 
-               m_ptr = &m_list[m_idx];
+               m_ptr = &current_floor_ptr->m_list[m_idx];
 
                /* Update the old location */
-               cave[oy][ox].m_idx = 0;
+               current_floor_ptr->grid_array[oy][ox].m_idx = 0;
 
                /* Update the new location */
-               cave[ny][nx].m_idx = m_idx;
+               current_floor_ptr->grid_array[ny][nx].m_idx = m_idx;
 
                /* Move the monster */
                m_ptr->fy = ny;
@@ -732,7 +735,7 @@ static void get_out_monster(void)
 }
 
 /*!
- * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with c_ptr->special?
+ * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
  */
 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
 
@@ -751,12 +754,12 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr)
        int i;
 
        /* Search usable stairs */
-       for (y = 0; y < cur_hgt; y++)
+       for (y = 0; y < current_floor_ptr->height; y++)
        {
-               for (x = 0; x < cur_wid; x++)
+               for (x = 0; x < current_floor_ptr->width; x++)
                {
-                       cave_type *c_ptr = &cave[y][x];
-                       feature_type *f_ptr = &f_info[c_ptr->feat];
+                       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
+                       feature_type *f_ptr = &f_info[g_ptr->feat];
                        bool ok = FALSE;
 
                        if (change_floor_mode & CFM_UP)
@@ -767,8 +770,8 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr)
                                        ok = TRUE;
 
                                        /* Found fixed stairs? */
-                                       if (c_ptr->special &&
-                                           c_ptr->special == sf_ptr->upper_floor_id)
+                                       if (g_ptr->special &&
+                                           g_ptr->special == sf_ptr->upper_floor_id)
                                        {
                                                sx = x;
                                                sy = y;
@@ -784,8 +787,8 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr)
                                        ok = TRUE;
 
                                        /* Found fixed stairs */
-                                       if (c_ptr->special &&
-                                           c_ptr->special == sf_ptr->lower_floor_id)
+                                       if (g_ptr->special &&
+                                           g_ptr->special == sf_ptr->lower_floor_id)
                                        {
                                                sx = x;
                                                sy = y;
@@ -822,7 +825,7 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr)
                prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
 
                /* Mega Hack -- It's not the stairs you enter.  Disable it.  */
-               if (!feat_uses_special(cave[p_ptr->y][p_ptr->x].feat)) cave[p_ptr->y][p_ptr->x].special = 0;
+               if (!feat_uses_special(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].feat)) current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].special = 0;
        }
        else
        {
@@ -842,7 +845,7 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr)
  */
 void leave_floor(void)
 {
-       cave_type *c_ptr = NULL;
+       grid_type *g_ptr = NULL;
        feature_type *f_ptr;
        saved_floor_type *sf_ptr;
        MONRACE_IDX quest_r_idx = 0;
@@ -859,24 +862,23 @@ void leave_floor(void)
        /* New floor is not yet prepared */
        new_floor_id = 0;
 
-       /* Temporary get a floor_id (for Arena) */
+       /* Temporarily get a floor_id (for Arena) */
        if (!p_ptr->floor_id &&
            (change_floor_mode & CFM_SAVE_FLOORS) &&
            !(change_floor_mode & CFM_NO_RETURN))
        {
-           /* Get temporal floor_id */
+           /* Get temporary floor_id */
            p_ptr->floor_id = get_new_floor_id();
        }
 
-
        /* Search the quest monster index */
        for (i = 0; i < max_q_idx; i++)
        {
                if ((quest[i].status == QUEST_STATUS_TAKEN) &&
                    ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
                    (quest[i].type == QUEST_TYPE_RANDOM)) &&
-                   (quest[i].level == dun_level) &&
-                   (dungeon_type == quest[i].dungeon) &&
+                   (quest[i].level == current_floor_ptr->dun_level) &&
+                   (p_ptr->dungeon_idx == quest[i].dungeon) &&
                    !(quest[i].flags & QUEST_FLAG_PRESET))
                {
                        quest_r_idx = quest[i].r_idx;
@@ -887,10 +889,9 @@ void leave_floor(void)
        for (i = 1; i < m_max; i++)
        {
                monster_race *r_ptr;
-               monster_type *m_ptr = &m_list[i];
+               monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
-               /* Skip dead monsters */
-               if (!m_ptr->r_idx) continue;
+               if (!monster_is_valid(m_ptr)) continue;
 
                /* Only maintain quest monsters */
                if (quest_r_idx != m_ptr->r_idx) continue;
@@ -934,14 +935,14 @@ void leave_floor(void)
        if (change_floor_mode & CFM_SAVE_FLOORS)
        {
                /* Extract stair position */
-               c_ptr = &cave[p_ptr->y][p_ptr->x];
-               f_ptr = &f_info[c_ptr->feat];
+               g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
+               f_ptr = &f_info[g_ptr->feat];
 
                /* Get back to old saved floor? */
-               if (c_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(c_ptr->special))
+               if (g_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(g_ptr->special))
                {
                        /* Saved floor is exist.  Use it. */
-                       new_floor_id = c_ptr->special;
+                       new_floor_id = g_ptr->special;
                }
 
                /* Mark shaft up/down */
@@ -967,29 +968,29 @@ void leave_floor(void)
                /* Get out from or Enter the dungeon */
                if (change_floor_mode & CFM_DOWN)
                {
-                       if (!dun_level)
-                               move_num = d_info[dungeon_type].mindepth;
+                       if (!current_floor_ptr->dun_level)
+                               move_num = d_info[p_ptr->dungeon_idx].mindepth;
                }
                else if (change_floor_mode & CFM_UP)
                {
-                       if (dun_level + move_num < d_info[dungeon_type].mindepth)
-                               move_num = -dun_level;
+                       if (current_floor_ptr->dun_level + move_num < d_info[p_ptr->dungeon_idx].mindepth)
+                               move_num = -current_floor_ptr->dun_level;
                }
 
-               dun_level += move_num;
+               current_floor_ptr->dun_level += move_num;
        }
 
        /* Leaving the dungeon to town */
-       if (!dun_level && dungeon_type)
+       if (!current_floor_ptr->dun_level && p_ptr->dungeon_idx)
        {
                p_ptr->leaving_dungeon = TRUE;
                if (!vanilla_town && !lite_town)
                {
-                       p_ptr->wilderness_y = d_info[dungeon_type].dy;
-                       p_ptr->wilderness_x = d_info[dungeon_type].dx;
+                       p_ptr->wilderness_y = d_info[p_ptr->dungeon_idx].dy;
+                       p_ptr->wilderness_x = d_info[p_ptr->dungeon_idx].dx;
                }
-               p_ptr->recall_dungeon = dungeon_type;
-               dungeon_type = 0;
+               p_ptr->recall_dungeon = p_ptr->dungeon_idx;
+               p_ptr->dungeon_idx = 0;
 
                /* Reach to the surface -- Clear all saved floors */
                change_floor_mode &= ~CFM_SAVE_FLOORS;
@@ -1026,9 +1027,9 @@ void leave_floor(void)
                new_floor_id = get_new_floor_id();
 
                /* Connect from here */
-               if (c_ptr && !feat_uses_special(c_ptr->feat))
+               if (g_ptr && !feat_uses_special(g_ptr->feat))
                {
-                       c_ptr->special = new_floor_id;
+                       g_ptr->special = new_floor_id;
                }
        }
 
@@ -1048,8 +1049,8 @@ void leave_floor(void)
                /* Get out of the my way! */
                get_out_monster();
 
-               /* Record the last visit turn of current floor */
-               sf_ptr->last_visit = turn;
+               /* Record the last visit current_world_ptr->game_turn of current floor */
+               sf_ptr->last_visit = current_world_ptr->game_turn;
 
                forget_lite();
                forget_view();
@@ -1073,7 +1074,7 @@ void leave_floor(void)
  * @return なし
  * @details
  * If the floor is an old saved floor, it will be\n
- * restored from the temporal file.  If the floor is new one, new cave\n
+ * restored from the temporary file.  If the floor is new one, new current_floor_ptr->grid_array\n
  * will be generated.\n
  */
 void change_floor(void)
@@ -1094,14 +1095,14 @@ void change_floor(void)
        panel_col_max = 0;
 
        /* Mega-Hack -- not ambushed on the wildness? */
-       ambush_flag = FALSE;
+       p_ptr->ambush_flag = FALSE;
 
        /* No saved floors (On the surface etc.) */
        if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
            !(change_floor_mode & CFM_FIRST_FLOOR))
        {
-               /* Create cave */
-               generate_cave();
+               /* Create current_floor_ptr->grid_array */
+               generate_random_floor();
 
                /* Paranoia -- No new saved floor */
                new_floor_id = 0;
@@ -1131,17 +1132,17 @@ void change_floor(void)
                                /* Forbid return stairs */
                                if (change_floor_mode & CFM_NO_RETURN)
                                {
-                                       cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
+                                       grid_type *g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
 
-                                       if (!feat_uses_special(c_ptr->feat))
+                                       if (!feat_uses_special(g_ptr->feat))
                                        {
                                                if (change_floor_mode & (CFM_DOWN | CFM_UP))
                                                {
                                                        /* Reset to floor */
-                                                       c_ptr->feat = floor_type[randint0(100)];
+                                                       g_ptr->feat = feat_ground_type[randint0(100)];
                                                }
 
-                                               c_ptr->special = 0;
+                                               g_ptr->special = 0;
                                        }
                                }
                        }
@@ -1184,23 +1185,22 @@ void change_floor(void)
                /* Maintain monsters and artifacts */
                if (loaded)
                {
-                       IDX i;
-                       s32b tmp_last_visit = sf_ptr->last_visit;
-                       s32b absence_ticks;
-                       int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
-                       int alloc_times;
+                       MONSTER_IDX i;
+                       GAME_TURN tmp_last_visit = sf_ptr->last_visit;
+                       GAME_TURN absence_ticks;
+                       int alloc_chance = d_info[p_ptr->dungeon_idx].max_m_alloc_chance;
+                       GAME_TURN alloc_times;
 
-                       while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
-                       absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK;
+                       while (tmp_last_visit > current_world_ptr->game_turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
+                       absence_ticks = (current_world_ptr->game_turn - tmp_last_visit) / TURNS_PER_TICK;
 
                        /* Maintain monsters */
                        for (i = 1; i < m_max; i++)
                        {
                                monster_race *r_ptr;
-                               monster_type *m_ptr = &m_list[i];
+                               monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
-                               /* Skip dead monsters */
-                               if (!m_ptr->r_idx) continue;
+                               if (!monster_is_valid(m_ptr)) continue;
 
                                if (!is_pet(m_ptr))
                                {
@@ -1234,7 +1234,7 @@ void change_floor(void)
                        /* Maintain artifatcs */
                        for (i = 1; i < o_max; i++)
                        {
-                               object_type *o_ptr = &o_list[i];
+                               object_type *o_ptr = &current_floor_ptr->o_list[i];
 
                                /* Skip dead objects */
                                if (!o_ptr->k_idx) continue;
@@ -1276,7 +1276,7 @@ void change_floor(void)
                {
                        if (sf_ptr->last_visit)
                        {
-                               /* Temporal file is broken? */
+                               /* Temporary file is broken? */
                                msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
 
                                /* Create simple dead end */
@@ -1294,41 +1294,41 @@ void change_floor(void)
                        }
                        else
                        {
-                               /* Newly create cave */
-                               generate_cave();
+                               /* Newly create current_floor_ptr->grid_array */
+                               generate_random_floor();
                        }
 
-                       /* Record last visit turn */
-                       sf_ptr->last_visit = turn;
+                       /* Record last visit current_world_ptr->game_turn */
+                       sf_ptr->last_visit = current_world_ptr->game_turn;
 
-                       /* Set correct dun_level value */
-                       sf_ptr->dun_level = dun_level;
+                       /* Set correct current_floor_ptr->dun_level value */
+                       sf_ptr->dun_level = current_floor_ptr->dun_level;
 
                        /* Create connected stairs */
                        if (!(change_floor_mode & CFM_NO_RETURN))
                        {
                                /* Extract stair position */
-                               cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
+                               grid_type *g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
 
                                /*** Create connected stairs ***/
 
                                /* No stairs down from Quest */
-                               if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
+                               if ((change_floor_mode & CFM_UP) && !quest_number(current_floor_ptr->dun_level))
                                {
-                                       c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
+                                       g_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
                                }
 
                                /* No stairs up when ironman_downward */
                                else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
                                {
-                                       c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
+                                       g_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
                                }
 
                                /* Paranoia -- Clear mimic */
-                               c_ptr->mimic = 0;
+                               g_ptr->mimic = 0;
 
                                /* Connect to previous floor */
-                               c_ptr->special = p_ptr->floor_id;
+                               g_ptr->special = p_ptr->floor_id;
                        }
                }
 
@@ -1339,8 +1339,7 @@ void change_floor(void)
                }
 
                /* You see stairs blocked */
-               else if ((change_floor_mode & CFM_NO_RETURN) &&
-                        (change_floor_mode & (CFM_DOWN | CFM_UP)))
+               else if ((change_floor_mode & CFM_NO_RETURN) && (change_floor_mode & (CFM_DOWN | CFM_UP)))
                {
                        if (!p_ptr->blind)
                        {
@@ -1355,9 +1354,9 @@ void change_floor(void)
                /*
                 * Update visit mark
                 *
-                * The "turn" is not always different number because
-                * the level teleport doesn't take any turn.  Use
-                * visit mark instead of last visit turn to find the
+                * The "current_world_ptr->game_turn" is not always different number because
+                * the level teleport doesn't take any current_world_ptr->game_turn.  Use
+                * visit mark instead of last visit current_world_ptr->game_turn to find the
                 * oldest saved floor.
                 */
                sf_ptr->visit_mark = latest_visit_mark++;
@@ -1383,10 +1382,10 @@ void change_floor(void)
                wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
 
        /* Remember when this level was "created" */
-       old_turn = turn;
+       current_floor_ptr->generated_turn = current_world_ptr->game_turn;
 
        /* No dungeon feeling yet */
-       p_ptr->feeling_turn = old_turn;
+       p_ptr->feeling_turn = current_floor_ptr->generated_turn;
        p_ptr->feeling = 0;
 
        /* Clear all flags */
@@ -1407,17 +1406,17 @@ void stair_creation(void)
 
        bool up = TRUE;
        bool down = TRUE;
-       s16b dest_floor_id = 0;
+       FLOOR_IDX dest_floor_id = 0;
 
 
        /* Forbid up staircases on Ironman mode */
        if (ironman_downward) up = FALSE;
 
        /* Forbid down staircases on quest level */
-       if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
+       if (quest_number(current_floor_ptr->dun_level) || (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth)) down = FALSE;
 
        /* No effect out of standard dungeon floor */
-       if (!dun_level || (!up && !down) ||
+       if (!current_floor_ptr->dun_level || (!up && !down) ||
            (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
            p_ptr->inside_arena || p_ptr->inside_battle)
        {
@@ -1438,8 +1437,6 @@ void stair_creation(void)
 
        /* Extract current floor data */
        sf_ptr = get_sf_ptr(p_ptr->floor_id);
-
-       /* Paranoia */
        if (!sf_ptr)
        {
                /* No floor id? -- Create now! */
@@ -1470,19 +1467,19 @@ void stair_creation(void)
        {
                POSITION x, y;
 
-               for (y = 0; y < cur_hgt; y++)
+               for (y = 0; y < current_floor_ptr->height; y++)
                {
-                       for (x = 0; x < cur_wid; x++)
+                       for (x = 0; x < current_floor_ptr->width; x++)
                        {
-                               cave_type *c_ptr = &cave[y][x];
+                               grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
 
-                               if (!c_ptr->special) continue;
-                               if (feat_uses_special(c_ptr->feat)) continue;
-                               if (c_ptr->special != dest_floor_id) continue;
+                               if (!g_ptr->special) continue;
+                               if (feat_uses_special(g_ptr->feat)) continue;
+                               if (g_ptr->special != dest_floor_id) continue;
 
                                /* Remove old stairs */
-                               c_ptr->special = 0;
-                               cave_set_feat(y, x, floor_type[randint0(100)]);
+                               g_ptr->special = 0;
+                               cave_set_feat(y, x, feat_ground_type[randint0(100)]);
                        }
                }
        }
@@ -1507,17 +1504,17 @@ void stair_creation(void)
        if (up)
        {
                cave_set_feat(p_ptr->y, p_ptr->x,
-                       (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= dun_level - 2)) ?
+                       (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= current_floor_ptr->dun_level - 2)) ?
                        feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair);
        }
        else
        {
                cave_set_feat(p_ptr->y, p_ptr->x,
-                       (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= dun_level + 2)) ?
+                       (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= current_floor_ptr->dun_level + 2)) ?
                        feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair);
        }
 
 
        /* Connect this stairs to the destination */
-       cave[p_ptr->y][p_ptr->x].special = dest_floor_id;
+       current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].special = dest_floor_id;
 }