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

Function somexy

src/mkroom.c:693–740  ·  view source on GitHub ↗

return a coord c inside mkroom croom, but not in a subroom. returns TRUE if any such space found. can return a non-accessible location, eg. inside a wall if a themed room is not irregular, but has some non-room terrain */

Source from the content-addressed store, hash-verified

691 can return a non-accessible location, eg. inside a wall
692 if a themed room is not irregular, but has some non-room terrain */
693boolean
694somexy(struct mkroom *croom, coord *c)
695{
696 int try_cnt = 0;
697 int i;
698
699 if (croom->irregular) {
700 i = (int) ((croom - svr.rooms) + ROOMOFFSET);
701
702 while (try_cnt++ < 100) {
703 c->x = somex(croom);
704 c->y = somey(croom);
705 if (!levl[c->x][c->y].edge && (int) levl[c->x][c->y].roomno == i)
706 return TRUE;
707 }
708 /* try harder; exhaustively search until one is found */
709 for (c->x = croom->lx; c->x <= croom->hx; c->x++)
710 for (c->y = croom->ly; c->y <= croom->hy; c->y++)
711 if (!levl[c->x][c->y].edge
712 && (int) levl[c->x][c->y].roomno == i)
713 return TRUE;
714 return FALSE;
715 }
716
717 if (!croom->nsubrooms) {
718 c->x = somex(croom);
719 c->y = somey(croom);
720 return TRUE;
721 }
722
723 /* Check that coords doesn't fall into a subroom or into a wall */
724
725 while (try_cnt++ < 100) {
726 c->x = somex(croom);
727 c->y = somey(croom);
728 if (IS_WALL(levl[c->x][c->y].typ))
729 continue;
730 for (i = 0; i < croom->nsubrooms; i++)
731 if (inside_room(croom->sbrooms[i], c->x, c->y))
732 goto you_lose;
733 break;
734 you_lose:
735 ;
736 }
737 if (try_cnt >= 100)
738 return FALSE;
739 return TRUE;
740}
741
742/* like somexy(), but returns an accessible location */
743boolean

Callers 5

somexyspaceFunction · 0.85
join_mapFunction · 0.85
mon_arriveFunction · 0.85
get_locationFunction · 0.85
get_room_locFunction · 0.85

Calls 3

somexFunction · 0.85
someyFunction · 0.85
inside_roomFunction · 0.85

Tested by

no test coverage detected