aboutsummaryrefslogtreecommitdiff
path: root/hack/hack.track.c
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2015-05-07 16:32:32 -0400
committerB. Watson <yalhcru@gmail.com>2015-05-07 16:32:32 -0400
commit013ac7742311556022304e8b30ca170d48b3a016 (patch)
tree53faa33e75991363f1a6dcc7edc83a66b70e6995 /hack/hack.track.c
downloadbsd-games-extra-013ac7742311556022304e8b30ca170d48b3a016.tar.gz
initial commit
Diffstat (limited to 'hack/hack.track.c')
-rw-r--r--hack/hack.track.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/hack/hack.track.c b/hack/hack.track.c
new file mode 100644
index 0000000..76a398a
--- /dev/null
+++ b/hack/hack.track.c
@@ -0,0 +1,49 @@
+/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
+/* hack.track.c - version 1.0.2 */
+/* $FreeBSD: src/games/hack/hack.track.c,v 1.4 1999/11/16 10:26:38 marcel Exp $ */
+/* $DragonFly: src/games/hack/hack.track.c,v 1.3 2006/08/21 19:45:32 pavalos Exp $ */
+
+#include "hack.h"
+
+#define UTSZ 50
+
+coord utrack[UTSZ];
+int utcnt = 0;
+int utpnt = 0;
+
+void
+initrack(void)
+{
+ utcnt = utpnt = 0;
+}
+
+/* add to track */
+void
+settrack(void)
+{
+ if (utcnt < UTSZ)
+ utcnt++;
+ if (utpnt == UTSZ)
+ utpnt = 0;
+ utrack[utpnt].x = u.ux;
+ utrack[utpnt].y = u.uy;
+ utpnt++;
+}
+
+coord *
+gettrack(int x, int y)
+{
+ int i, cnt, dst;
+ coord tc;
+
+ cnt = utcnt;
+ for (i = utpnt - 1; cnt--; i--) {
+ if (i == -1)
+ i = UTSZ - 1;
+ tc = utrack[i];
+ dst = (x - tc.x) * (x - tc.x) + (y - tc.y) * (y - tc.y);
+ if (dst < 3)
+ return (dst ? &(utrack[i]) : 0);
+ }
+ return (0);
+}