1 1.4 christos /* $NetBSD: hack.track.c,v 1.4 1997/10/19 16:59:11 christos Exp $ */ 2 1.4 christos 3 1.2 mycroft /* 4 1.2 mycroft * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. 5 1.2 mycroft */ 6 1.2 mycroft 7 1.4 christos #include <sys/cdefs.h> 8 1.2 mycroft #ifndef lint 9 1.4 christos __RCSID("$NetBSD: hack.track.c,v 1.4 1997/10/19 16:59:11 christos Exp $"); 10 1.4 christos #endif /* not lint */ 11 1.1 cgd 12 1.1 cgd #include "hack.h" 13 1.4 christos #include "extern.h" 14 1.1 cgd 15 1.1 cgd #define UTSZ 50 16 1.1 cgd 17 1.4 christos coord utrack[UTSZ]; 18 1.4 christos int utcnt = 0; 19 1.4 christos int utpnt = 0; 20 1.4 christos 21 1.4 christos void 22 1.4 christos initrack() 23 1.4 christos { 24 1.1 cgd utcnt = utpnt = 0; 25 1.1 cgd } 26 1.1 cgd 27 1.1 cgd /* add to track */ 28 1.4 christos void 29 1.4 christos settrack() 30 1.4 christos { 31 1.4 christos if (utcnt < UTSZ) 32 1.4 christos utcnt++; 33 1.4 christos if (utpnt == UTSZ) 34 1.4 christos utpnt = 0; 35 1.1 cgd utrack[utpnt].x = u.ux; 36 1.1 cgd utrack[utpnt].y = u.uy; 37 1.1 cgd utpnt++; 38 1.1 cgd } 39 1.1 cgd 40 1.4 christos coord * 41 1.4 christos gettrack(x, y) 42 1.4 christos int x, y; 43 1.4 christos { 44 1.4 christos int i, cnt, dist; 45 1.4 christos coord tc; 46 1.1 cgd cnt = utcnt; 47 1.4 christos for (i = utpnt - 1; cnt--; i--) { 48 1.4 christos if (i == -1) 49 1.4 christos i = UTSZ - 1; 50 1.1 cgd tc = utrack[i]; 51 1.4 christos dist = (x - tc.x) * (x - tc.x) + (y - tc.y) * (y - tc.y); 52 1.4 christos if (dist < 3) 53 1.4 christos return (dist ? &(utrack[i]) : 0); 54 1.1 cgd } 55 1.4 christos return (0); 56 1.1 cgd } 57