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

Function worm_cross

src/worm.c:897–942  ·  view source on GitHub ↗

would moving from to involve passing between two consecutive segments of the same worm? */

Source from the content-addressed store, hash-verified

895/* would moving from <x1,y1> to <x2,y2> involve passing between two
896 consecutive segments of the same worm? */
897boolean
898worm_cross(int x1, int y1, int x2, int y2)
899{
900 struct monst *worm;
901 struct wseg *curr, *wnxt;
902
903 /*
904 * With digits representing relative sequence number of the segments,
905 * returns true when testing between @ and ? (passes through worm's
906 * body), false between @ and ! (stays on same side of worm).
907 * .w1?..
908 * ..@2..
909 * .65!3.
910 * ...4..
911 */
912
913 if (distmin(x1, y1, x2, y2) != 1) {
914 impossible("worm_cross checking for non-adjacent location?");
915 return FALSE;
916 }
917 /* attempting to pass between worm segs is only relevant for diagonal */
918 if (x1 == x2 || y1 == y2)
919 return FALSE;
920
921 /* is the same monster at <x1,y2> and at <x2,y1>? */
922 worm = m_at(x1, y2);
923 if (!worm || m_at(x2, y1) != worm)
924 return FALSE;
925
926 /* same monster is at both adjacent spots, so must be a worm; we need
927 to figure out if the two spots are occupied by consecutive segments */
928 for (curr = wtails[worm->wormno]; curr; curr = wnxt) {
929 wnxt = curr->nseg;
930 if (!wnxt)
931 break; /* no next segment; can't continue */
932
933 /* we don't know which of <x1,y2> or <x2,y1> we'll hit first, but
934 whichever it is, they're consecutive iff next seg is the other */
935 if (curr->wx == x1 && curr->wy == y2)
936 return (boolean) (wnxt->wx == x2 && wnxt->wy == y1);
937 if (curr->wx == x2 && curr->wy == y1)
938 return (boolean) (wnxt->wx == x1 && wnxt->wy == y2);
939 }
940 /* should never reach here... */
941 return FALSE;
942}
943
944/* construct an index number for a worm tail segment */
945int

Callers 2

test_moveFunction · 0.85
mfndposFunction · 0.85

Calls 2

distminFunction · 0.85
impossibleFunction · 0.70

Tested by 1

test_moveFunction · 0.68