Modified walkfrom() from mkmaze.c */
| 136 | |
| 137 | /* Modified walkfrom() from mkmaze.c */ |
| 138 | staticfn void |
| 139 | miniwalk(coordxy x, coordxy y) |
| 140 | { |
| 141 | int q, dir; |
| 142 | int dirs[4]; |
| 143 | |
| 144 | while (1) { |
| 145 | q = 0; |
| 146 | #define doorhere (gr.r[x][y].doortable) |
| 147 | if (x > 0 && (!(doorhere & XL_LEFT)) |
| 148 | && (!gr.r[x - 1][y].doortable || !rn2(10))) |
| 149 | dirs[q++] = 0; |
| 150 | if (x < 2 && (!(doorhere & XL_RIGHT)) |
| 151 | && (!gr.r[x + 1][y].doortable || !rn2(10))) |
| 152 | dirs[q++] = 1; |
| 153 | if (y > 0 && (!(doorhere & XL_UP)) |
| 154 | && (!gr.r[x][y - 1].doortable || !rn2(10))) |
| 155 | dirs[q++] = 2; |
| 156 | if (y < 2 && (!(doorhere & XL_DOWN)) |
| 157 | && (!gr.r[x][y + 1].doortable || !rn2(10))) |
| 158 | dirs[q++] = 3; |
| 159 | /* Rogue levels aren't just 3 by 3 mazes; they have some extra |
| 160 | * connections, thus that 1/10 chance |
| 161 | */ |
| 162 | if (!q) |
| 163 | return; |
| 164 | dir = dirs[rn2(q)]; |
| 165 | switch (dir) { /* Move in direction */ |
| 166 | case 0: |
| 167 | doorhere |= XL_LEFT; |
| 168 | x--; |
| 169 | doorhere |= XL_RIGHT; |
| 170 | break; |
| 171 | case 1: |
| 172 | doorhere |= XL_RIGHT; |
| 173 | x++; |
| 174 | doorhere |= XL_LEFT; |
| 175 | break; |
| 176 | case 2: |
| 177 | doorhere |= XL_UP; |
| 178 | y--; |
| 179 | doorhere |= XL_DOWN; |
| 180 | break; |
| 181 | case 3: |
| 182 | doorhere |= XL_DOWN; |
| 183 | y++; |
| 184 | doorhere |= XL_UP; |
| 185 | break; |
| 186 | } |
| 187 | miniwalk(x, y); |
| 188 | } |
| 189 | #undef doorhere |
| 190 | } |
| 191 | |
| 192 | void |
| 193 | makeroguerooms(void) |