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

Function truncate_to_map

src/getpos.c:728–748  ·  view source on GitHub ↗

add dx,dy to cx,cy, truncating at map edges */

Source from the content-addressed store, hash-verified

726
727/* add dx,dy to cx,cy, truncating at map edges */
728staticfn void
729truncate_to_map(coordxy *cx, coordxy *cy, schar dx, schar dy)
730{
731 /* diagonal moves complicate this... */
732 if (*cx + dx < 1) {
733 dy -= sgn(dy) * (1 - (*cx + dx));
734 dx = 1 - *cx; /* so that (cx+dx == 1) */
735 } else if (*cx + dx > COLNO - 1) {
736 dy += sgn(dy) * ((COLNO - 1) - (*cx + dx));
737 dx = (COLNO - 1) - *cx;
738 }
739 if (*cy + dy < 0) {
740 dx -= sgn(dx) * (0 - (*cy + dy));
741 dy = 0 - *cy; /* so that (cy+dy == 0) */
742 } else if (*cy + dy > ROWNO - 1) {
743 dx += sgn(dx) * ((ROWNO - 1) - (*cy + dy));
744 dy = (ROWNO - 1) - *cy;
745 }
746 *cx += dx;
747 *cy += dy;
748}
749
750/* called when ^R typed; if '$' is being shown for valid spots, remove that;
751 if alternate background color is being shown for that, redraw it */

Callers 1

getposFunction · 0.85

Calls 1

sgnFunction · 0.85

Tested by

no test coverage detected