MCPcopy Index your code
hub / github.com/NetHack/NetHack / in_rooms

Function in_rooms

src/hack.c:3497–3560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3495}
3496
3497char *
3498in_rooms(coordxy x, coordxy y, int typewanted)
3499{
3500 static char buf[5];
3501 char rno = 0, *ptr = &buf[4];
3502 int typefound, min_x, min_y, max_x, max_y_offset, step;
3503 struct rm *lev;
3504
3505#define goodtype(rno) \
3506 (!typewanted \
3507 || (typefound = svr.rooms[rno - ROOMOFFSET].rtype) == typewanted \
3508 || (typewanted == SHOPBASE && typefound > SHOPBASE))
3509
3510 switch (rno = levl[x][y].roomno) {
3511 case NO_ROOM:
3512 return ptr;
3513 case SHARED:
3514 step = 2;
3515 break;
3516 case SHARED_PLUS:
3517 step = 1;
3518 break;
3519 default: /* i.e. a regular room # */
3520 if (goodtype(rno))
3521 *(--ptr) = rno;
3522 return ptr;
3523 }
3524
3525 min_x = x - 1;
3526 max_x = x + 1;
3527 if (x < 1)
3528 min_x += step;
3529 else if (x >= COLNO)
3530 max_x -= step;
3531
3532 min_y = y - 1;
3533 max_y_offset = 2;
3534 if (min_y < 0) {
3535 min_y += step;
3536 max_y_offset -= step;
3537 } else if ((min_y + max_y_offset) >= ROWNO)
3538 max_y_offset -= step;
3539
3540 for (x = min_x; x <= max_x; x += step) {
3541 lev = &levl[x][min_y];
3542 y = 0;
3543 if ((rno = lev[y].roomno) >= ROOMOFFSET && !strchr(ptr, rno)
3544 && goodtype(rno))
3545 *(--ptr) = rno;
3546 y += step;
3547 if (y > max_y_offset)
3548 continue;
3549 if ((rno = lev[y].roomno) >= ROOMOFFSET && !strchr(ptr, rno)
3550 && goodtype(rno))
3551 *(--ptr) = rno;
3552 y += step;
3553 if (y > max_y_offset)
3554 continue;

Callers 15

resetobjsFunction · 0.85
mdrop_objFunction · 0.85
potionhitFunction · 0.85
itemactionsFunction · 0.85
do_attackFunction · 0.85
teledsFunction · 0.85
rlocoFunction · 0.85
u_teleport_monFunction · 0.85
dopushFunction · 0.85
moverock_coreFunction · 0.85
still_chewingFunction · 0.85
monstinroomFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected