MCPcopy Create free account
hub / github.com/NetHack/NetHack / dig_corridor

Function dig_corridor

src/sp_lev.c:2548–2663  ·  view source on GitHub ↗

* Dig a corridor between two points, using terrain ftyp. * if nxcor is TRUE, he corridor may be blocked by a boulder, * or just end without reaching the destination. * if not null, npoints has the number of map locations used */

Source from the content-addressed store, hash-verified

2546 * if not null, npoints has the number of map locations used
2547 */
2548boolean
2549dig_corridor(
2550 coord *org, coord *dest,
2551 int *npoints,
2552 boolean nxcor,
2553 schar ftyp, schar btyp)
2554{
2555 int dx = 0, dy = 0, dix, diy, cct;
2556 struct rm *crm;
2557 int tx, ty, xx, yy;
2558
2559 if (npoints)
2560 *npoints = 0;
2561 xx = org->x;
2562 yy = org->y;
2563 tx = dest->x;
2564 ty = dest->y;
2565 if (xx <= 0 || yy <= 0 || tx <= 0 || ty <= 0 || xx > COLNO - 1
2566 || tx > COLNO - 1 || yy > ROWNO - 1 || ty > ROWNO - 1) {
2567 debugpline4("dig_corridor: bad coords <%d,%d> <%d,%d>.",
2568 xx, yy, tx, ty);
2569 return FALSE;
2570 }
2571 if (tx > xx)
2572 dx = 1;
2573 else if (ty > yy)
2574 dy = 1;
2575 else if (tx < xx)
2576 dx = -1;
2577 else
2578 dy = -1;
2579
2580 xx -= dx;
2581 yy -= dy;
2582 cct = 0;
2583 while (xx != tx || yy != ty) {
2584 /* loop: dig corridor at [xx,yy] and find new [xx,yy] */
2585 if (cct++ > 500 || (nxcor && !rn2(35)))
2586 return FALSE;
2587
2588 xx += dx;
2589 yy += dy;
2590
2591 if (xx >= COLNO - 1 || xx <= 0 || yy <= 0 || yy >= ROWNO - 1)
2592 return FALSE; /* impossible */
2593
2594 crm = &levl[xx][yy];
2595 if (crm->typ == btyp) {
2596 if (ftyp == CORR && maybe_sdoor(100)) {
2597 if (npoints)
2598 (*npoints)++;
2599 crm->typ = SCORR;
2600 } else {
2601 if (npoints)
2602 (*npoints)++;
2603 crm->typ = ftyp;
2604 if (nxcor && !rn2(50))
2605 (void) mksobj_at(BOULDER, xx, yy, TRUE, FALSE);

Callers 3

join_mapFunction · 0.85
joinFunction · 0.85
create_corridorFunction · 0.85

Calls 3

rn2Function · 0.85
maybe_sdoorFunction · 0.85
mksobj_atFunction · 0.85

Tested by

no test coverage detected