pick a location in area (lx, ly, hx, hy) but not in (nlx, nly, nhx, nhy) and place something (based on rtype) in that region */
| 353 | /* pick a location in area (lx, ly, hx, hy) but not in (nlx, nly, nhx, nhy) |
| 354 | and place something (based on rtype) in that region */ |
| 355 | void |
| 356 | place_lregion( |
| 357 | coordxy lx, coordxy ly, coordxy hx, coordxy hy, |
| 358 | coordxy nlx, coordxy nly, coordxy nhx, coordxy nhy, |
| 359 | xint16 rtype, |
| 360 | d_level *lev) |
| 361 | { |
| 362 | int trycnt; |
| 363 | boolean oneshot; |
| 364 | coordxy x, y; |
| 365 | |
| 366 | if (!lx) { /* default to whole level */ |
| 367 | /* |
| 368 | * if there are rooms and this a branch, let place_branch choose |
| 369 | * the branch location (to avoid putting branches in corridors). |
| 370 | */ |
| 371 | if (rtype == LR_BRANCH && svn.nroom) { |
| 372 | place_branch(Is_branchlev(&u.uz), 0, 0); |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | lx = 1; /* column 0 is not used */ |
| 377 | hx = COLNO - 1; |
| 378 | ly = 0; /* 3.6.0 and earlier erroneously had 1 here */ |
| 379 | hy = ROWNO - 1; |
| 380 | } |
| 381 | |
| 382 | /* clamp the area to the map */ |
| 383 | if (lx < 1) |
| 384 | lx = 1; |
| 385 | if (hx > COLNO - 1) |
| 386 | hx = COLNO - 1; |
| 387 | if (ly < 0) |
| 388 | ly = 0; |
| 389 | if (hy > ROWNO - 1) |
| 390 | hy = ROWNO - 1; |
| 391 | |
| 392 | /* first a probabilistic approach */ |
| 393 | |
| 394 | oneshot = (lx == hx && ly == hy); |
| 395 | for (trycnt = 0; trycnt < 200; trycnt++) { |
| 396 | x = rn1((hx - lx) + 1, lx); |
| 397 | y = rn1((hy - ly) + 1, ly); |
| 398 | if (put_lregion_here(x, y, nlx, nly, nhx, nhy, rtype, oneshot, lev)) |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | /* then a deterministic one */ |
| 403 | |
| 404 | for (x = lx; x <= hx; x++) |
| 405 | for (y = ly; y <= hy; y++) |
| 406 | if (put_lregion_here(x, y, nlx, nly, nhx, nhy, rtype, TRUE, lev)) |
| 407 | return; |
| 408 | |
| 409 | impossible("Couldn't place lregion type %d!", rtype); |
| 410 | } |
| 411 | |
| 412 | staticfn boolean |
no test coverage detected