| 255 | } |
| 256 | |
| 257 | staticfn void |
| 258 | join_map(schar bg_typ, schar fg_typ) |
| 259 | { |
| 260 | struct mkroom *croom, *croom2; |
| 261 | |
| 262 | coordxy x, y, sx, sy; |
| 263 | coord sm, em; |
| 264 | |
| 265 | /* first, use flood filling to find all of the regions that need joining |
| 266 | */ |
| 267 | for (x = 2; x <= WIDTH; x++) |
| 268 | for (y = 1; y < HEIGHT; y++) { |
| 269 | if (levl[x][y].typ == fg_typ && levl[x][y].roomno == NO_ROOM) { |
| 270 | gm.min_rx = gm.max_rx = x; |
| 271 | gm.min_ry = gm.max_ry = y; |
| 272 | gn.n_loc_filled = 0; |
| 273 | flood_fill_rm(x, y, svn.nroom + ROOMOFFSET, FALSE, FALSE); |
| 274 | if (gn.n_loc_filled > 3) { |
| 275 | add_room(gm.min_rx, gm.min_ry, gm.max_rx, gm.max_ry, |
| 276 | FALSE, OROOM, TRUE); |
| 277 | svr.rooms[svn.nroom - 1].irregular = TRUE; |
| 278 | if (svn.nroom >= (MAXNROFROOMS * 2)) |
| 279 | goto joinm; |
| 280 | } else { |
| 281 | /* |
| 282 | * it's a tiny hole; erase it from the map to avoid |
| 283 | * having the player end up here with no way out. |
| 284 | */ |
| 285 | for (sx = gm.min_rx; sx <= gm.max_rx; sx++) |
| 286 | for (sy = gm.min_ry; sy <= gm.max_ry; sy++) |
| 287 | if ((int) levl[sx][sy].roomno |
| 288 | == svn.nroom + ROOMOFFSET) { |
| 289 | levl[sx][sy].typ = bg_typ; |
| 290 | levl[sx][sy].roomno = NO_ROOM; |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | joinm: |
| 297 | /* |
| 298 | * Ok, now we can actually join the regions with fg_typ's. |
| 299 | * The rooms are already sorted due to the previous loop, |
| 300 | * so don't call sort_rooms(), which can screw up the roomno's |
| 301 | * validity in the levl structure. |
| 302 | */ |
| 303 | for (croom = &svr.rooms[0], croom2 = croom + 1; |
| 304 | croom2 < &svr.rooms[svn.nroom]; ) { |
| 305 | /* pick random starting and end locations for "corridor" */ |
| 306 | if (!somexy(croom, &sm) || !somexy(croom2, &em)) { |
| 307 | /* ack! -- the level is going to be busted */ |
| 308 | /* arbitrarily pick centers of both rooms and hope for the best */ |
| 309 | impossible("No start/end room loc in join_map."); |
| 310 | sm.x = croom->lx + ((croom->hx - croom->lx) / 2); |
| 311 | sm.y = croom->ly + ((croom->hy - croom->ly) / 2); |
| 312 | em.x = croom2->lx + ((croom2->hx - croom2->lx) / 2); |
| 313 | em.y = croom2->ly + ((croom2->hy - croom2->ly) / 2); |
| 314 | } |
no test coverage detected