OSDN Git Service

孤立した部屋ができるバグのうち, 直線通路作成関数build_tunnel()の失敗
authornothere <nothere@0568b783-4c39-0410-ac80-bf13821ea2a2>
Wed, 21 Jul 2004 19:31:47 +0000 (19:31 +0000)
committernothere <nothere@0568b783-4c39-0410-ac80-bf13821ea2a2>
Wed, 21 Jul 2004 19:31:47 +0000 (19:31 +0000)
によるものを修正. 不定形通路作成関数build_tunnel2()によるものは
build_tunnel()の場合以上に起きにくいが, build_tunnel()と同じ対処を行
うと生成失敗判定によるダンジョン再作成が増えすぎ, まだ対処できない.

src/generate.c
src/grid.c
src/grid.h

index 02e67f5..a5a542f 100644 (file)
@@ -802,6 +802,8 @@ static bool cave_gen(void)
        /* Build some rooms */
        else
        {
+               int tunnel_fail_count = 0;
+
                /*
                 * Build each type of room in turn until we cannot build any more.
                 */
@@ -886,14 +888,16 @@ static bool cave_gen(void)
                        if (randint1(dun_level) > d_info[dungeon_type].tunnel_percent)
                        {
                                /* make cave-like tunnel */
-                               build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
+                               (void)build_tunnel2(dun->cent[i].x, dun->cent[i].y, x, y, 2, 2);
                        }
                        else
                        {
                                /* make normal tunnel */
-                               build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x);
+                               if (!build_tunnel(dun->cent[i].y, dun->cent[i].x, y, x)) tunnel_fail_count++;
                        }
 
+                       if (tunnel_fail_count >= 2) return FALSE;
+
                        /* Turn the tunnel into corridor */
                        for (j = 0; j < dun->tunn_n; j++)
                        {
index 655a430..6895d78 100644 (file)
@@ -562,7 +562,7 @@ void set_floor(int x, int y)
  *   outer -- outer room walls
  *   solid -- solid room walls
  */
-void build_tunnel(int row1, int col1, int row2, int col2)
+bool build_tunnel(int row1, int col1, int row2, int col2)
 {
        int y, x;
        int tmp_row, tmp_col;
@@ -585,7 +585,7 @@ void build_tunnel(int row1, int col1, int row2, int col2)
        while ((row1 != row2) || (col1 != col2))
        {
                /* Mega-Hack -- Paranoia -- prevent infinite loops */
-               if (main_loop_count++ > 2000) break;
+               if (main_loop_count++ > 2000) return FALSE;
 
                /* Allow bends in the tunnel */
                if (randint0(100) < dun_tun_chg)
@@ -651,6 +651,7 @@ void build_tunnel(int row1, int col1, int row2, int col2)
                                dun->wall[dun->wall_n].x = col1;
                                dun->wall_n++;
                        }
+                       else return FALSE;
 
                        /* Forbid re-entry near this piercing */
                        for (y = row1 - 1; y <= row1 + 1; y++)
@@ -689,6 +690,7 @@ void build_tunnel(int row1, int col1, int row2, int col2)
                                dun->tunn[dun->tunn_n].x = col1;
                                dun->tunn_n++;
                        }
+                       else return FALSE;
 
                        /* Allow door in next grid */
                        door_flag = FALSE;
@@ -711,6 +713,7 @@ void build_tunnel(int row1, int col1, int row2, int col2)
                                        dun->door[dun->door_n].x = col1;
                                        dun->door_n++;
                                }
+                               else return FALSE;
 
                                /* No door in next grid */
                                door_flag = TRUE;
@@ -732,6 +735,8 @@ void build_tunnel(int row1, int col1, int row2, int col2)
                        }
                }
        }
+
+       return TRUE;
 }
 
 
@@ -767,9 +772,10 @@ static bool set_tunnel(int *x, int *y, bool affectwall)
                        dun->tunn[dun->tunn_n].y = *y;
                        dun->tunn[dun->tunn_n].x = *x;
                        dun->tunn_n++;
-               }
 
-               return TRUE;
+                       return TRUE;
+               }
+               else return FALSE;
        }
 
        if (is_floor_bold(*y, *x))
@@ -787,6 +793,7 @@ static bool set_tunnel(int *x, int *y, bool affectwall)
                        dun->wall[dun->wall_n].x = *x;
                        dun->wall_n++;
                }
+               else return FALSE;
 
                /* Forbid re-entry near this piercing */
                for (j = *y - 1; j <= *y + 1; j++)
@@ -1114,6 +1121,7 @@ bool build_tunnel2(int x1, int y1, int x2, int y2, int type, int cutoff)
                                                dun->door[dun->door_n].x = x3;
                                                dun->door_n++;
                                        }
+                                       else return FALSE;
                                }
                                firstsuccede = TRUE;
                        }
index 1ef7e19..6b1c545 100644 (file)
@@ -256,5 +256,5 @@ extern void rand_dir(int *rdir, int *cdir);
 extern bool get_is_floor(int x, int y);
 extern void set_floor(int x, int y);
 
-extern void build_tunnel(int row1, int col1, int row2, int col2);
+extern bool build_tunnel(int row1, int col1, int row2, int col2);
 extern bool build_tunnel2(int x1, int y1, int x2, int y2, int type, int cutoff);