OSDN Git Service

[Refactor] #38997 get_monster_hook() にplayer_type * 引数を追加 / Added player_type * argum...
[hengband/hengband.git] / src / wild.c
index b495052..f3f0d9c 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "angband.h"
 #include "util.h"
+#include "core.h"
 
 #include "dungeon.h"
 #include "floor.h"
 #include "files.h"
 #include "feature.h"
 #include "floor-town.h"
+#include "realm.h"
+
+#include "view-mainwindow.h"
+
+#define MAX_FEAT_IN_TERRAIN 18
 
  /*
   * Wilderness
@@ -36,7 +42,6 @@ wilderness_type **wilderness;
 
 bool generate_encounter;
 
-
 /*!
  * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
  * @param feat_type 非一様確率を再現するための要素数100の配列
@@ -58,6 +63,7 @@ static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_F
        }
 }
 
+
 /*!
  * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
  * / Fill the arrays of floors and walls in the good proportions
@@ -97,7 +103,7 @@ void set_floor_and_wall(DUNGEON_IDX type)
  * @param depth_max 深みの最大値
  * @return なし
  */
-static void perturb_point_mid(FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, FEAT_IDX x4, POSITION xmid, POSITION ymid, FEAT_IDX rough, FEAT_IDX depth_max)
+static void perturb_point_mid(floor_type *floor_ptr, FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, FEAT_IDX x4, POSITION xmid, POSITION ymid, FEAT_IDX rough, FEAT_IDX depth_max)
 {
        /*
         * Average the four corners & perturb it a bit.
@@ -117,7 +123,7 @@ static void perturb_point_mid(FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, FEAT_IDX x4
        if (avg > depth_max) avg = depth_max;
 
        /* Set the new value. */
-       current_floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
+       floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
 }
 
 
@@ -133,7 +139,7 @@ static void perturb_point_mid(FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, FEAT_IDX x4
  * @param depth_max 深みの最大値
  * @return なし
  */
-static void perturb_point_end(FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, POSITION xmid, POSITION ymid, FEAT_IDX rough, FEAT_IDX depth_max)
+static void perturb_point_end(floor_type *floor_ptr, FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, POSITION xmid, POSITION ymid, FEAT_IDX rough, FEAT_IDX depth_max)
 {
        /*
         * Average the three corners & perturb it a bit.
@@ -152,7 +158,7 @@ static void perturb_point_end(FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, POSITION xm
        if (avg > depth_max) avg = depth_max;
 
        /* Set the new value. */
-       current_floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
+       floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
 }
 
 
@@ -175,7 +181,7 @@ static void perturb_point_end(FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, POSITION xm
  * need to be converted to features.
  * </pre>
  */
-static void plasma_recursive(POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
+static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
 {
        /* Find middle */
        POSITION xmid = (x2 - x1) / 2 + x1;
@@ -184,32 +190,30 @@ static void plasma_recursive(POSITION x1, POSITION y1, POSITION x2, POSITION y2,
        /* Are we done? */
        if (x1 + 1 == x2) return;
 
-       perturb_point_mid(current_floor_ptr->grid_array[y1][x1].feat, current_floor_ptr->grid_array[y2][x1].feat, current_floor_ptr->grid_array[y1][x2].feat,
-               current_floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
+       perturb_point_mid(floor_ptr, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[y1][x2].feat,
+               floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
 
-       perturb_point_end(current_floor_ptr->grid_array[y1][x1].feat, current_floor_ptr->grid_array[y1][x2].feat, current_floor_ptr->grid_array[ymid][xmid].feat,
+       perturb_point_end(floor_ptr, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[y1][x2].feat, floor_ptr->grid_array[ymid][xmid].feat,
                xmid, y1, rough, depth_max);
 
-       perturb_point_end(current_floor_ptr->grid_array[y1][x2].feat, current_floor_ptr->grid_array[y2][x2].feat, current_floor_ptr->grid_array[ymid][xmid].feat,
+       perturb_point_end(floor_ptr, floor_ptr->grid_array[y1][x2].feat, floor_ptr->grid_array[y2][x2].feat, floor_ptr->grid_array[ymid][xmid].feat,
                x2, ymid, rough, depth_max);
 
-       perturb_point_end(current_floor_ptr->grid_array[y2][x2].feat, current_floor_ptr->grid_array[y2][x1].feat, current_floor_ptr->grid_array[ymid][xmid].feat,
+       perturb_point_end(floor_ptr, floor_ptr->grid_array[y2][x2].feat, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[ymid][xmid].feat,
                xmid, y2, rough, depth_max);
 
-       perturb_point_end(current_floor_ptr->grid_array[y2][x1].feat, current_floor_ptr->grid_array[y1][x1].feat, current_floor_ptr->grid_array[ymid][xmid].feat,
+       perturb_point_end(floor_ptr, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[ymid][xmid].feat,
                x1, ymid, rough, depth_max);
 
 
        /* Recurse the four quadrants */
-       plasma_recursive(x1, y1, xmid, ymid, depth_max, rough);
-       plasma_recursive(xmid, y1, x2, ymid, depth_max, rough);
-       plasma_recursive(x1, ymid, xmid, y2, depth_max, rough);
-       plasma_recursive(xmid, ymid, x2, y2, depth_max, rough);
+       plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
+       plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
+       plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
+       plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
 }
 
 
-#define MAX_FEAT_IN_TERRAIN 18
-
 /*
  * The default table in terrain level generation.
  */
@@ -223,47 +227,39 @@ static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
  * @param corner 広域マップの角部分としての生成ならばTRUE
  * @return なし
  */
-static void generate_wilderness_area(int terrain, u32b seed, bool border, bool corner)
+static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
 {
-       POSITION x1, y1;
-       int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
-       FEAT_IDX roughness = 1; /* The roughness of the level. */
-       u32b state_backup[4];
-
-       /* Unused */
-       (void)border;
-
        /* The outer wall is easy */
        if (terrain == TERRAIN_EDGE)
        {
                /* Create level background */
-               for (y1 = 0; y1 < MAX_HGT; y1++)
+               for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
                {
-                       for (x1 = 0; x1 < MAX_WID; x1++)
+                       for (POSITION x1 = 0; x1 < MAX_WID; x1++)
                        {
-                               current_floor_ptr->grid_array[y1][x1].feat = feat_permanent;
+                               floor_ptr->grid_array[y1][x1].feat = feat_permanent;
                        }
                }
 
-               /* We are done already */
                return;
        }
 
-
        /* Hack -- Backup the RNG state */
+       u32b state_backup[4];
        Rand_state_backup(state_backup);
 
        /* Hack -- Induce consistant flavors */
        Rand_state_set(seed);
 
+       int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
        if (!corner)
        {
                /* Create level background */
-               for (y1 = 0; y1 < MAX_HGT; y1++)
+               for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
                {
-                       for (x1 = 0; x1 < MAX_WID; x1++)
+                       for (POSITION x1 = 0; x1 < MAX_WID; x1++)
                        {
-                               current_floor_ptr->grid_array[y1][x1].feat = table_size / 2;
+                               floor_ptr->grid_array[y1][x1].feat = table_size / 2;
                        }
                }
        }
@@ -273,53 +269,54 @@ static void generate_wilderness_area(int terrain, u32b seed, bool border, bool c
         * ToDo: calculate the medium height of the adjacent
         * terrains for every corner.
         */
-       current_floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
-       current_floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
-       current_floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
-       current_floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
+       floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
+       floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
+       floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
+       floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
 
-       if (!corner)
+       /* Hack -- only four corners */
+       if (corner)
        {
-               /* Hack -- preserve four corners */
-               s16b north_west = current_floor_ptr->grid_array[1][1].feat;
-               s16b south_west = current_floor_ptr->grid_array[MAX_HGT - 2][1].feat;
-               s16b north_east = current_floor_ptr->grid_array[1][MAX_WID - 2].feat;
-               s16b south_east = current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
-
-               /* x1, y1, x2, y2, num_depths, roughness */
-               plasma_recursive(1, 1, MAX_WID-2, MAX_HGT-2, table_size-1, roughness);
-
-               /* Hack -- copyback four corners */
-               current_floor_ptr->grid_array[1][1].feat = north_west;
-               current_floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
-               current_floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
-               current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
-
-               for (y1 = 1; y1 < MAX_HGT - 1; y1++)
-               {
-                       for (x1 = 1; x1 < MAX_WID - 1; x1++)
-                       {
-                               current_floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][current_floor_ptr->grid_array[y1][x1].feat];
-                       }
-               }
+               floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
+               floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
+               floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
+               floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat];
+               Rand_state_restore(state_backup);
+               return;
        }
-       else /* Hack -- only four corners */
+
+       /* Hack -- preserve four corners */
+       s16b north_west = floor_ptr->grid_array[1][1].feat;
+       s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
+       s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
+       s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
+
+       /* x1, y1, x2, y2, num_depths, roughness */
+       FEAT_IDX roughness = 1; /* The roughness of the level. */
+       plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
+
+       /* Hack -- copyback four corners */
+       floor_ptr->grid_array[1][1].feat = north_west;
+       floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
+       floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
+       floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
+
+       for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
        {
-               current_floor_ptr->grid_array[1][1].feat = terrain_table[terrain][current_floor_ptr->grid_array[1][1].feat];
-               current_floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][current_floor_ptr->grid_array[MAX_HGT - 2][1].feat];
-               current_floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][current_floor_ptr->grid_array[1][MAX_WID - 2].feat];
-               current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = terrain_table[terrain][current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat];
+               for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
+               {
+                       floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
+               }
        }
 
-       /* Hack -- Restore the RNG state */
        Rand_state_restore(state_backup);
 }
 
 
-
 /*!
  * @brief 荒野フロア生成のメインルーチン /
  * Load a town or generate a terrain level using "plasma" fractals.
+ * @param player_ptr プレーヤーへの参照ポインタ
  * @param y 広域Y座標
  * @param x 広域X座標
  * @param border 広域マップの辺部分としての生成ならばTRUE
@@ -335,28 +332,27 @@ static void generate_wilderness_area(int terrain, u32b seed, bool border, bool c
  * If corner is set then only the corners of the area are needed.
  * </pre>
  */
-static void generate_area(POSITION y, POSITION x, bool border, bool corner)
+static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
 {
-       POSITION x1, y1;
-
        /* Number of the town (if any) */
-       p_ptr->town_num = wilderness[y][x].town;
+       player_ptr->town_num = wilderness[y][x].town;
 
        /* Set the base level */
-       current_floor_ptr->base_level = wilderness[y][x].level;
+       floor_type *floor_ptr = player_ptr->current_floor_ptr;
+       floor_ptr->base_level = wilderness[y][x].level;
 
        /* Set the dungeon level */
-       current_floor_ptr->dun_level = 0;
+       floor_ptr->dun_level = 0;
 
        /* Set the monster generation level */
-       current_floor_ptr->monster_level = current_floor_ptr->base_level;
+       floor_ptr->monster_level = floor_ptr->base_level;
 
        /* Set the object generation level */
-       current_floor_ptr->object_level = current_floor_ptr->base_level;
+       floor_ptr->object_level = floor_ptr->base_level;
 
 
        /* Create the town */
-       if (p_ptr->town_num)
+       if (player_ptr->town_num)
        {
                /* Reset the buildings */
                init_buildings();
@@ -367,16 +363,16 @@ static void generate_area(POSITION y, POSITION x, bool border, bool corner)
                else
                        init_flags = INIT_CREATE_DUNGEON;
 
-               process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
+               process_dungeon_file(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
 
-               if (!corner && !border) p_ptr->visit |= (1L << (p_ptr->town_num - 1));
+               if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
        }
        else
        {
                int terrain = wilderness[y][x].terrain;
                u32b seed = wilderness[y][x].seed;
 
-               generate_wilderness_area(terrain, seed, border, corner);
+               generate_wilderness_area(floor_ptr, terrain, seed, corner);
        }
 
        if (!corner && !wilderness[y][x].town)
@@ -387,15 +383,16 @@ static void generate_area(POSITION y, POSITION x, bool border, bool corner)
                 */
                if (wilderness[y][x].road)
                {
-                       current_floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
+                       floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
 
+                       POSITION x1, y1;
                        if (wilderness[y-1][x].road)
                        {
                                /* North road */
                                for (y1 = 1; y1 < MAX_HGT/2; y1++)
                                {
                                        x1 = MAX_WID/2;
-                                       current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
+                                       floor_ptr->grid_array[y1][x1].feat = feat_floor;
                                }
                        }
 
@@ -405,7 +402,7 @@ static void generate_area(POSITION y, POSITION x, bool border, bool corner)
                                for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
                                {
                                        x1 = MAX_WID/2;
-                                       current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
+                                       floor_ptr->grid_array[y1][x1].feat = feat_floor;
                                }
                        }
 
@@ -415,7 +412,7 @@ static void generate_area(POSITION y, POSITION x, bool border, bool corner)
                                for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
                                {
                                        y1 = MAX_HGT/2;
-                                       current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
+                                       floor_ptr->grid_array[y1][x1].feat = feat_floor;
                                }
                        }
 
@@ -425,32 +422,32 @@ static void generate_area(POSITION y, POSITION x, bool border, bool corner)
                                for (x1 = 1; x1 < MAX_WID/2; x1++)
                                {
                                        y1 = MAX_HGT/2;
-                                       current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
+                                       floor_ptr->grid_array[y1][x1].feat = feat_floor;
                                }
                        }
                }
        }
 
-       if (wilderness[y][x].entrance && !wilderness[y][x].town && (p_ptr->total_winner || !(d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER)))
-       {
-               int dy, dx;
-               u32b state_backup[4];
+       bool is_winner = wilderness[y][x].entrance;
+       is_winner &= !wilderness[y][x].town;
+       is_winner &= (current_world_ptr->total_winner || !(d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER));
+       if (!is_winner) return;
 
-               /* Hack -- Backup the RNG state */
-               Rand_state_backup(state_backup);
+       /* Hack -- Backup the RNG state */
+       u32b state_backup[4];
+       Rand_state_backup(state_backup);
 
-               /* Hack -- Induce consistant flavors */
-               Rand_state_set(wilderness[y][x].seed);
+       /* Hack -- Induce consistant flavors */
+       Rand_state_set(wilderness[y][x].seed);
 
-               dy = rand_range(6, current_floor_ptr->height - 6);
-               dx = rand_range(6, current_floor_ptr->width - 6);
+       int dy = rand_range(6, floor_ptr->height - 6);
+       int dx = rand_range(6, floor_ptr->width - 6);
 
-               current_floor_ptr->grid_array[dy][dx].feat = feat_entrance;
-               current_floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
+       floor_ptr->grid_array[dy][dx].feat = feat_entrance;
+       floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
 
-               /* Hack -- Restore the RNG state */
-               Rand_state_restore(state_backup);
-       }
+       /* Hack -- Restore the RNG state */
+       Rand_state_restore(state_backup);
 }
 
 
@@ -459,249 +456,243 @@ static void generate_area(POSITION y, POSITION x, bool border, bool corner)
  */
 static border_type border;
 
-
 /*!
  * @brief 広域マップの生成 /
  * Build the wilderness area outside of the town.
+ * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
+ * @param creature_ptr プレーヤーへの参照ポインタ
  * @return なし
  */
-void wilderness_gen(void)
+void wilderness_gen(player_type *creature_ptr)
 {
-       int i, lim;
-       POSITION y, x;
-       grid_type *g_ptr;
-       feature_type *f_ptr;
-
        /* Big town */
-       current_floor_ptr->height = MAX_HGT;
-       current_floor_ptr->width = MAX_WID;
+       floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+       floor_ptr->height = MAX_HGT;
+       floor_ptr->width = MAX_WID;
 
        /* Assume illegal panel */
-       panel_row_min = current_floor_ptr->height;
-       panel_col_min = current_floor_ptr->width;
-
-       /* Init the wilderness */
+       panel_row_min = floor_ptr->height;
+       panel_col_min = floor_ptr->width;
 
-       process_dungeon_file("w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
-
-       x = p_ptr->wilderness_x;
-       y = p_ptr->wilderness_y;
-       get_mon_num_prep(get_monster_hook(), NULL);
+       process_dungeon_file(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
+       POSITION x = creature_ptr->wilderness_x;
+       POSITION y = creature_ptr->wilderness_y;
+       get_mon_num_prep(get_monster_hook(creature_ptr), NULL);
 
        /* North border */
-       generate_area(y - 1, x, TRUE, FALSE);
+       generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
 
-       for (i = 1; i < MAX_WID - 1; i++)
+       for (int i = 1; i < MAX_WID - 1; i++)
        {
-               border.north[i] = current_floor_ptr->grid_array[MAX_HGT - 2][i].feat;
+               border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
        }
 
        /* South border */
-       generate_area(y + 1, x, TRUE, FALSE);
+       generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
 
-       for (i = 1; i < MAX_WID - 1; i++)
+       for (int i = 1; i < MAX_WID - 1; i++)
        {
-               border.south[i] = current_floor_ptr->grid_array[1][i].feat;
+               border.south[i] = floor_ptr->grid_array[1][i].feat;
        }
 
        /* West border */
-       generate_area(y, x - 1, TRUE, FALSE);
+       generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
 
-       for (i = 1; i < MAX_HGT - 1; i++)
+       for (int i = 1; i < MAX_HGT - 1; i++)
        {
-               border.west[i] = current_floor_ptr->grid_array[i][MAX_WID - 2].feat;
+               border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
        }
 
        /* East border */
-       generate_area(y, x + 1, TRUE, FALSE);
+       generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
 
-       for (i = 1; i < MAX_HGT - 1; i++)
+       for (int i = 1; i < MAX_HGT - 1; i++)
        {
-               border.east[i] = current_floor_ptr->grid_array[i][1].feat;
+               border.east[i] = floor_ptr->grid_array[i][1].feat;
        }
 
        /* North west corner */
-       generate_area(y - 1, x - 1, FALSE, TRUE);
-       border.north_west = current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
+       generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
+       border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
 
        /* North east corner */
-       generate_area(y - 1, x + 1, FALSE, TRUE);
-       border.north_east = current_floor_ptr->grid_array[MAX_HGT - 2][1].feat;
+       generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
+       border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
 
        /* South west corner */
-       generate_area(y + 1, x - 1, FALSE, TRUE);
-       border.south_west = current_floor_ptr->grid_array[1][MAX_WID - 2].feat;
+       generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
+       border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
 
        /* South east corner */
-       generate_area(y + 1, x + 1, FALSE, TRUE);
-       border.south_east = current_floor_ptr->grid_array[1][1].feat;
-
+       generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
+       border.south_east = floor_ptr->grid_array[1][1].feat;
 
        /* Create terrain of the current area */
-       generate_area(y, x, FALSE, FALSE);
-
+       generate_area(creature_ptr, y, x, FALSE, FALSE);
 
        /* Special boundary walls -- North */
-       for (i = 0; i < MAX_WID; i++)
+       for (int i = 0; i < MAX_WID; i++)
        {
-               current_floor_ptr->grid_array[0][i].feat = feat_permanent;
-               current_floor_ptr->grid_array[0][i].mimic = border.north[i];
+               floor_ptr->grid_array[0][i].feat = feat_permanent;
+               floor_ptr->grid_array[0][i].mimic = border.north[i];
        }
 
        /* Special boundary walls -- South */
-       for (i = 0; i < MAX_WID; i++)
+       for (int i = 0; i < MAX_WID; i++)
        {
-               current_floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
-               current_floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
+               floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
+               floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
        }
 
        /* Special boundary walls -- West */
-       for (i = 0; i < MAX_HGT; i++)
+       for (int i = 0; i < MAX_HGT; i++)
        {
-               current_floor_ptr->grid_array[i][0].feat = feat_permanent;
-               current_floor_ptr->grid_array[i][0].mimic = border.west[i];
+               floor_ptr->grid_array[i][0].feat = feat_permanent;
+               floor_ptr->grid_array[i][0].mimic = border.west[i];
        }
 
        /* Special boundary walls -- East */
-       for (i = 0; i < MAX_HGT; i++)
+       for (int i = 0; i < MAX_HGT; i++)
        {
-               current_floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
-               current_floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
+               floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
+               floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
        }
 
-       /* North west corner */
-       current_floor_ptr->grid_array[0][0].mimic = border.north_west;
-
-       /* North east corner */
-       current_floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
-
-       /* South west corner */
-       current_floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
-
-       /* South east corner */
-       current_floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
+       floor_ptr->grid_array[0][0].mimic = border.north_west;
+       floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
+       floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
+       floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
 
        /* Light up or darken the area */
-       for (y = 0; y < current_floor_ptr->height; y++)
+       for (y = 0; y < floor_ptr->height; y++)
        {
-               for (x = 0; x < current_floor_ptr->width; x++)
+               for (x = 0; x < floor_ptr->width; x++)
                {
-                       g_ptr = &current_floor_ptr->grid_array[y][x];
+                       grid_type *g_ptr;
+                       g_ptr = &floor_ptr->grid_array[y][x];
 
                        if (is_daytime())
                        {
                                /* Assume lit */
-                               g_ptr->info |= (CAVE_GLOW);
+                               g_ptr->info |= CAVE_GLOW;
 
                                /* Hack -- Memorize lit grids if allowed */
-                               if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
+                               if (view_perma_grids) g_ptr->info |= CAVE_MARK;
+                               continue;
                        }
-                       else
+
+                       /* Feature code (applying "mimic" field) */
+                       feature_type *f_ptr;
+                       f_ptr = &f_info[get_feat_mimic(g_ptr)];
+
+                       if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
+                               !have_flag(f_ptr->flags, FF_ENTRANCE))
                        {
-                               /* Feature code (applying "mimic" field) */
-                               f_ptr = &f_info[get_feat_mimic(g_ptr)];
+                               /* Assume dark */
+                               g_ptr->info &= ~(CAVE_GLOW);
 
-                               if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
-                                   !have_flag(f_ptr->flags, FF_ENTRANCE))
+                               /* Darken "boring" features */
+                               if (!have_flag(f_ptr->flags, FF_REMEMBER))
                                {
-                                       /* Assume dark */
-                                       g_ptr->info &= ~(CAVE_GLOW);
-
-                                       /* Darken "boring" features */
-                                       if (!have_flag(f_ptr->flags, FF_REMEMBER))
-                                       {
-                                               /* Forget the grid */
-                                               g_ptr->info &= ~(CAVE_MARK);
-                                       }
+                                       /* Forget the grid */
+                                       g_ptr->info &= ~(CAVE_MARK);
                                }
-                               else if (have_flag(f_ptr->flags, FF_ENTRANCE))
-                               {
-                                       /* Assume lit */
-                                       g_ptr->info |= (CAVE_GLOW);
 
-                                       /* Hack -- Memorize lit grids if allowed */
-                                       if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
-                               }
+                               continue;
                        }
+                       
+                       if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
+
+                       g_ptr->info |= CAVE_GLOW;
+
+                       /* Hack -- Memorize lit grids if allowed */
+                       if (view_perma_grids) g_ptr->info |= CAVE_MARK;
                }
        }
 
-       if (p_ptr->teleport_town)
+       if (creature_ptr->teleport_town)
        {
-               for (y = 0; y < current_floor_ptr->height; y++)
+               for (y = 0; y < floor_ptr->height; y++)
                {
-                       for (x = 0; x < current_floor_ptr->width; x++)
+                       for (x = 0; x < floor_ptr->width; x++)
                        {
-                               g_ptr = &current_floor_ptr->grid_array[y][x];
+                               grid_type *g_ptr;
+                               g_ptr = &floor_ptr->grid_array[y][x];
 
                                /* Seeing true feature code (ignore mimic) */
+                               feature_type *f_ptr;
                                f_ptr = &f_info[g_ptr->feat];
 
-                               if (have_flag(f_ptr->flags, FF_BLDG))
+                               if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
+
+                               if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
+                                       continue;
+
+                               if (g_ptr->m_idx)
                                {
-                                       if ((f_ptr->subtype == 4) || ((p_ptr->town_num == 1) && (f_ptr->subtype == 0)))
-                                       {
-                                               if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
-                                               p_ptr->oldpy = y;
-                                               p_ptr->oldpx = x;
-                                       }
+                                       delete_monster_idx(g_ptr->m_idx);
                                }
+
+                               creature_ptr->oldpy = y;
+                               creature_ptr->oldpx = x;
                        }
                }
-               p_ptr->teleport_town = FALSE;
-       }
 
-       else if (p_ptr->leaving_dungeon)
+               creature_ptr->teleport_town = FALSE;
+       }
+       else if (creature_ptr->leaving_dungeon)
        {
-               for (y = 0; y < current_floor_ptr->height; y++)
+               for (y = 0; y < floor_ptr->height; y++)
                {
-                       for (x = 0; x < current_floor_ptr->width; x++)
+                       for (x = 0; x < floor_ptr->width; x++)
                        {
-                               g_ptr = &current_floor_ptr->grid_array[y][x];
+                               grid_type *g_ptr;
+                               g_ptr = &floor_ptr->grid_array[y][x];
 
-                               if (cave_have_flag_grid(g_ptr, FF_ENTRANCE))
+                               if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
+
+                               if (g_ptr->m_idx)
                                {
-                                       if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
-                                       p_ptr->oldpy = y;
-                                       p_ptr->oldpx = x;
+                                       delete_monster_idx(g_ptr->m_idx);
                                }
+
+                               creature_ptr->oldpy = y;
+                               creature_ptr->oldpx = x;
                        }
                }
-               p_ptr->teleport_town = FALSE;
-       }
 
-       player_place(p_ptr->oldpy, p_ptr->oldpx);
-       /* p_ptr->leaving_dungeon = FALSE;*/
+               creature_ptr->teleport_town = FALSE;
+       }
 
-       lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
+       player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
+       int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
 
        /* Make some residents */
-       for (i = 0; i < lim; i++)
+       for (int i = 0; i < lim; i++)
        {
                BIT_FLAGS mode = 0;
 
-               if (!(generate_encounter || (one_in_(2) && (!p_ptr->town_num))))
+               if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
                        mode |= PM_ALLOW_SLEEP;
 
                /* Make a resident */
                (void)alloc_monster(generate_encounter ? 0 : 3, mode);
        }
 
-       if(generate_encounter) p_ptr->ambush_flag = TRUE;
+       if(generate_encounter) creature_ptr->ambush_flag = TRUE;
        generate_encounter = FALSE;
 
        /* Fill the arrays of floors and walls in the good proportions */
        set_floor_and_wall(0);
 
        /* Set rewarded quests to finished */
-       for (i = 0; i < max_q_idx; i++)
+       for (int i = 0; i < max_q_idx; i++)
        {
                if (quest[i].status == QUEST_STATUS_REWARDED)
                        quest[i].status = QUEST_STATUS_FINISHED;
        }
 }
 
-
 static s16b conv_terrain2feat[MAX_WILDERNESS];
 
 /*!
@@ -709,55 +700,66 @@ static s16b conv_terrain2feat[MAX_WILDERNESS];
  * Build the wilderness area. -DG-
  * @return なし
  */
-void wilderness_gen_small(void)
+void wilderness_gen_small(player_type *creature_ptr)
 {
-       int i, j;
-
        /* To prevent stupid things */
-       for (i = 0; i < MAX_WID; i++)
-       for (j = 0; j < MAX_HGT; j++)
+       floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+       for (int i = 0; i < MAX_WID; i++)
        {
-               current_floor_ptr->grid_array[j][i].feat = feat_permanent;
+               for (int j = 0; j < MAX_HGT; j++)
+               {
+                       floor_ptr->grid_array[j][i].feat = feat_permanent;
+               }
        }
 
-       /* Init the wilderness */
-       process_dungeon_file("w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
+       process_dungeon_file(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
 
        /* Fill the map */
-       for (i = 0; i < current_world_ptr->max_wild_x; i++)
-       for (j = 0; j < current_world_ptr->max_wild_y; j++)
+       for (int i = 0; i < current_world_ptr->max_wild_x; i++)
        {
-               if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
-               {
-                       current_floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
-                       current_floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
-               }
-               else if (wilderness[j][i].road) current_floor_ptr->grid_array[j][i].feat = feat_floor;
-               else if (wilderness[j][i].entrance && (p_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
+               for (int j = 0; j < current_world_ptr->max_wild_y; j++)
                {
-                       current_floor_ptr->grid_array[j][i].feat = feat_entrance;
-                       current_floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
-               }
-               else current_floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
+                       if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
+                       {
+                               floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
+                               floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
+                               floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
+                               continue;
+                       }
+                       
+                       if (wilderness[j][i].road)
+                       {
+                               floor_ptr->grid_array[j][i].feat = feat_floor;
+                               floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
+                               continue;
+                       }
+                       
+                       if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
+                       {
+                               floor_ptr->grid_array[j][i].feat = feat_entrance;
+                               floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
+                               floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
+                               continue;
+                       }
 
-               current_floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
+                       floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
+                       floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
+               }
        }
 
-       current_floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
-       current_floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
+       floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
+       floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
 
-       if (current_floor_ptr->height > MAX_HGT) current_floor_ptr->height = MAX_HGT;
-       if (current_floor_ptr->width > MAX_WID) current_floor_ptr->width = MAX_WID;
+       if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
+       if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
 
        /* Assume illegal panel */
-       panel_row_min = current_floor_ptr->height;
-       panel_col_min = current_floor_ptr->width;
+       panel_row_min = floor_ptr->height;
+       panel_col_min = floor_ptr->width;
 
-       /* Place the player */
-       p_ptr->x = p_ptr->wilderness_x;
-       p_ptr->y = p_ptr->wilderness_y;
-
-       p_ptr->town_num = 0;
+       creature_ptr->x = creature_ptr->wilderness_x;
+       creature_ptr->y = creature_ptr->wilderness_y;
+       creature_ptr->town_num = 0;
 }
 
 
@@ -775,7 +777,6 @@ struct wilderness_grid
 
 static wilderness_grid w_letter[255];
 
-
 /*!
  * @brief w_info.txtのデータ解析 /
  * Parse a sub-file of the "extra info"
@@ -788,16 +789,12 @@ static wilderness_grid w_letter[255];
  * @param x 広域マップの幅を返す参照ポインタ
  * @return なし
  */
-errr parse_line_wilderness(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
+errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
 {
-       int i, num;
-       char *zz[33];
-
-       /* Unused */
-       (void)ymin;
-       (void)ymax;
        if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
 
+       int num;
+       char *zz[33];
        switch (buf[2])
        {
                /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
@@ -855,12 +852,9 @@ errr parse_line_wilderness(char *buf, int ymin, int xmin, int ymax, int xmax, in
        /* Layout of the wilderness */
        case 'D':
        {
-               /* Acquire the text */
                char *s = buf+4;
-               
-               /* Length of the text */
                int len = strlen(s);
-               
+               int i;
                for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
                {
                        int id = s[0];
@@ -872,57 +866,53 @@ errr parse_line_wilderness(char *buf, int ymin, int xmin, int ymax, int xmax, in
                }
                
                (*y)++;
-               
                break;
        }
        
        /* Process "W:P:<x>:<y> - starting position in the wilderness */
        case 'P':
        {
-               if ((p_ptr->wilderness_x == 0) &&
-                   (p_ptr->wilderness_y == 0))
+               bool is_corner = creature_ptr->wilderness_x == 0;
+               is_corner = creature_ptr->wilderness_y == 0;
+               if (!is_corner) break;
+
+               if (tokenize(buf + 4, 2, zz, 0) != 2)
                {
-                       if (tokenize(buf+4, 2, zz, 0) == 2)
-                       {
-                               p_ptr->wilderness_y = atoi(zz[0]);
-                               p_ptr->wilderness_x = atoi(zz[1]);
-                               
-                               if ((p_ptr->wilderness_x < 1) ||
-                                   (p_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
-                                   (p_ptr->wilderness_y < 1) ||
-                                   (p_ptr->wilderness_y > current_world_ptr->max_wild_y))
-                               {
-                                       return (PARSE_ERROR_OUT_OF_BOUNDS);
-                               }
-                       }
-                       else
-                       {
-                               return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
-                       }
+                       return PARSE_ERROR_TOO_FEW_ARGUMENTS;
                }
-               
+
+               creature_ptr->wilderness_y = atoi(zz[0]);
+               creature_ptr->wilderness_x = atoi(zz[1]);
+
+               if ((creature_ptr->wilderness_x < 1) ||
+                       (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
+                       (creature_ptr->wilderness_y < 1) ||
+                       (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
+               {
+                       return PARSE_ERROR_OUT_OF_BOUNDS;
+               }
+
                break;
        }
        
        default:
-               /* Failure */
-               return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
+               return PARSE_ERROR_UNDEFINED_DIRECTIVE;
        }
        
-       for (i = 1; i < max_d_idx; i++)
+       for (int i = 1; i < current_world_ptr->max_d_idx; i++)
        {
                if (!d_info[i].maxdepth) continue;
                wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte_hack)i;
                if (!wilderness[d_info[i].dy][d_info[i].dx].town)
+               {
                        wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
+               }
        }
 
-       /* Success */
-       return (0);
+       return 0;
 }
 
 
-
 /*!
  * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
  * Generate the random seeds for the wilderness
@@ -930,12 +920,9 @@ errr parse_line_wilderness(char *buf, int ymin, int xmin, int ymax, int xmax, in
  */
 void seed_wilderness(void)
 {
-       POSITION x, y;
-
-       /* Init wilderness seeds */
-       for (x = 0; x < current_world_ptr->max_wild_x; x++)
+       for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
        {
-               for (y = 0; y < current_world_ptr->max_wild_y; y++)
+               for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
                {
                        wilderness[y][x].seed = randint0(0x10000000);
                        wilderness[y][x].entrance = 0;
@@ -949,7 +936,6 @@ void seed_wilderness(void)
  */
 typedef wilderness_type *wilderness_type_ptr;
 
-
 /*!
  * @brief ゲーム開始時の荒野初期化メインルーチン /
  * Initialize wilderness array
@@ -957,21 +943,21 @@ typedef wilderness_type *wilderness_type_ptr;
  */
 errr init_wilderness(void)
 {
-       int i;
-
        /* Allocate the wilderness (two-dimension array) */
        C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
        C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
 
        /* Init the other pointers */
-       for (i = 1; i < current_world_ptr->max_wild_y; i++)
+       for (int i = 1; i < current_world_ptr->max_wild_y; i++)
+       {
                wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
+       }
 
        generate_encounter = FALSE;
-
        return 0;
 }
 
+
 /*!
  * @brief 荒野の地勢設定を初期化する /
  * Initialize wilderness array
@@ -982,47 +968,43 @@ errr init_wilderness(void)
  */
 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
 {
-       va_list vp;
-       concptr    p;
-       int     cur = 0;
-       char    check = 'a';
-       FEAT_IDX feat;
-       int     num;
-
        /* Begin the varargs stuff */
+       va_list vp;
        va_start(vp, fmt);
 
        /* Wilderness terrains on global map */
        conv_terrain2feat[terrain] = feat_global;
 
        /* Wilderness terrains on local map */
-       for (p = fmt; *p; p++)
+       int cur = 0;
+       char check = 'a';
+       for (concptr p = fmt; *p; p++)
        {
-               if (*p == check)
+               if (*p != check)
                {
-                       int lim;
-
-                       feat = (s16b)va_arg(vp, int);
-                       num = va_arg(vp, int);
-                       lim = cur + num;
+                       plog_fmt("Format error");
+                       continue;
+               }
 
-                       for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
-                               terrain_table[terrain][cur] = feat;
-                       if (cur >= MAX_FEAT_IN_TERRAIN) break;
+               FEAT_IDX feat = (s16b)va_arg(vp, int);
+               int num = va_arg(vp, int);
+               int lim = cur + num;
 
-                       check++;
-               }
-               else
+               for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
                {
-                       plog_fmt("Format error");
+                       terrain_table[terrain][cur] = feat;
                }
+
+               if (cur >= MAX_FEAT_IN_TERRAIN) break;
+
+               check++;
        }
+
        if (cur < MAX_FEAT_IN_TERRAIN)
        {
                plog_fmt("Too few parameters");
        }
 
-       /* End the varargs stuff */
        va_end(vp);
 }
 
@@ -1107,21 +1089,19 @@ void init_wilderness_terrains(void)
                feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
 }
 
+
 /*!
  * @brief 荒野から広域マップへの切り替え処理 /
  * Initialize arrays for wilderness terrains
  * @param encount 襲撃時TRUE
  * @return 切り替えが行われた場合はTRUEを返す。
  */
-bool change_wild_mode(bool encount)
+bool change_wild_mode(player_type *creature_ptr, bool encount)
 {
-       int i;
-       bool have_pet = FALSE;
        generate_encounter = encount;
 
        /* It is in the middle of changing map */
-       if (p_ptr->leaving) return FALSE;
-
+       if (creature_ptr->leaving) return FALSE;
 
        if (lite_town || vanilla_town)
        {
@@ -1129,35 +1109,34 @@ bool change_wild_mode(bool encount)
                return FALSE;
        }
 
-       if (p_ptr->wild_mode)
+       if (creature_ptr->wild_mode)
        {
                /* Save the location in the global map */
-               p_ptr->wilderness_x = p_ptr->x;
-               p_ptr->wilderness_y = p_ptr->y;
+               creature_ptr->wilderness_x = creature_ptr->x;
+               creature_ptr->wilderness_y = creature_ptr->y;
 
                /* Give first move to the player */
-               p_ptr->energy_need = 0;
+               creature_ptr->energy_need = 0;
 
                /* Go back to the ordinary map */
-               p_ptr->wild_mode = FALSE;
-               p_ptr->leaving = TRUE;
-
-               /* Succeed */
+               creature_ptr->wild_mode = FALSE;
+               creature_ptr->leaving = TRUE;
                return TRUE;
        }
 
-       for (i = 1; i < current_floor_ptr->m_max; i++)
+       bool have_pet = FALSE;
+       for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
        {
-               monster_type *m_ptr = &current_floor_ptr->m_list[i];
+               monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
 
                if (!monster_is_valid(m_ptr)) continue;
-               if (is_pet(m_ptr) && i != p_ptr->riding) have_pet = TRUE;
+               if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
                if (MON_CSLEEP(m_ptr)) continue;
                if (m_ptr->cdis > MAX_SIGHT) continue;
                if (!is_hostile(m_ptr)) continue;
                msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
                        "You cannot enter global map, since there is some monsters nearby!"));
-               free_turn(p_ptr);
+               free_turn(creature_ptr);
                return FALSE;
        }
 
@@ -1168,27 +1147,25 @@ bool change_wild_mode(bool encount)
 
                if (!get_check_strict(msg, CHECK_OKAY_CANCEL))
                {
-                       free_turn(p_ptr);
+                       free_turn(creature_ptr);
                        return FALSE;
                }
        }
 
-       take_turn(p_ptr, 1000);
+       take_turn(creature_ptr, 1000);
 
        /* Remember the position */
-       p_ptr->oldpx = p_ptr->x;
-       p_ptr->oldpy = p_ptr->y;
+       creature_ptr->oldpx = creature_ptr->x;
+       creature_ptr->oldpy = creature_ptr->y;
 
        /* Cancel hex spelling */
-       if (hex_spelling_any()) stop_hex_spell_all();
+       if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
 
        /* Cancel any special action */
-       set_action(ACTION_NONE);
+       set_action(creature_ptr, ACTION_NONE);
 
        /* Go into the global map */
-       p_ptr->wild_mode = TRUE;
-       p_ptr->leaving = TRUE;
-
-       /* Succeed */
+       creature_ptr->wild_mode = TRUE;
+       creature_ptr->leaving = TRUE;
        return TRUE;
 }