Correct wall types so they extend and connect to each other */
| 226 | |
| 227 | /* Correct wall types so they extend and connect to each other */ |
| 228 | void |
| 229 | fix_wall_spines(coordxy x1, coordxy y1, coordxy x2, coordxy y2) |
| 230 | { |
| 231 | uchar type; |
| 232 | coordxy x, y; |
| 233 | struct rm *lev; |
| 234 | int (*loc_f)(coordxy, coordxy); |
| 235 | int bits; |
| 236 | int locale[3][3]; /* rock or wall status surrounding positions */ |
| 237 | |
| 238 | /* |
| 239 | * Value 0 represents a free-standing wall. It could be anything, |
| 240 | * so even though this table says VWALL, we actually leave whatever |
| 241 | * typ was there alone. |
| 242 | */ |
| 243 | static xint16 spine_array[16] = { VWALL, HWALL, HWALL, HWALL, |
| 244 | VWALL, TRCORNER, TLCORNER, TDWALL, |
| 245 | VWALL, BRCORNER, BLCORNER, TUWALL, |
| 246 | VWALL, TLWALL, TRWALL, CROSSWALL }; |
| 247 | |
| 248 | /* sanity check on incoming variables */ |
| 249 | if (x1 < 0 || x2 >= COLNO || x1 > x2 || y1 < 0 || y2 >= ROWNO || y1 > y2) |
| 250 | panic("wall_extends: bad bounds (%d,%d) to (%d,%d)", x1, y1, x2, y2); |
| 251 | |
| 252 | /* set the correct wall type. */ |
| 253 | for (x = x1; x <= x2; x++) |
| 254 | for (y = y1; y <= y2; y++) { |
| 255 | lev = &levl[x][y]; |
| 256 | type = lev->typ; |
| 257 | if (!(IS_WALL(type) && type != DBWALL)) |
| 258 | continue; |
| 259 | |
| 260 | /* set the locations TRUE if rock or wall or out of bounds */ |
| 261 | loc_f = within_bounded_area(x, y, /* for baalz insect */ |
| 262 | gb.bughack.inarea.x1, gb.bughack.inarea.y1, |
| 263 | gb.bughack.inarea.x2, gb.bughack.inarea.y2) |
| 264 | ? iswall |
| 265 | : iswall_or_stone; |
| 266 | locale[0][0] = (*loc_f)(x - 1, y - 1); |
| 267 | locale[1][0] = (*loc_f)(x, y - 1); |
| 268 | locale[2][0] = (*loc_f)(x + 1, y - 1); |
| 269 | |
| 270 | locale[0][1] = (*loc_f)(x - 1, y); |
| 271 | locale[2][1] = (*loc_f)(x + 1, y); |
| 272 | |
| 273 | locale[0][2] = (*loc_f)(x - 1, y + 1); |
| 274 | locale[1][2] = (*loc_f)(x, y + 1); |
| 275 | locale[2][2] = (*loc_f)(x + 1, y + 1); |
| 276 | |
| 277 | /* determine if wall should extend to each direction NSEW */ |
| 278 | bits = (extend_spine(locale, iswall(x, y - 1), 0, -1) << 3) |
| 279 | | (extend_spine(locale, iswall(x, y + 1), 0, 1) << 2) |
| 280 | | (extend_spine(locale, iswall(x + 1, y), 1, 0) << 1) |
| 281 | | extend_spine(locale, iswall(x - 1, y), -1, 0); |
| 282 | |
| 283 | /* don't change typ if wall is free-standing */ |
| 284 | if (bits) |
| 285 | lev->typ = spine_array[bits]; |
no test coverage detected