home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume15
/
xtb
/
part01
/
common.c
next >
Wrap
C/C++ Source or Header
|
1993-01-27
|
2KB
|
108 lines
/*
* Common code.
*
* $Header: /morpork/home/bmh/xtest2/RCS/common.c,v 1.2 92/10/19 15:34:25 bmh Exp Locker: bmh $
*
* Bernard Hatt
* Camtec Electronics (Ericsson), Leicester, England, LE1 4SA
* bmh@terminus.ericsson.se
*
*/
#include <stdio.h>
#ifdef BSD
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#else
#include <sys/types.h>
#include <sys/timeb.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
#include <math.h>
#include "defs.h"
#include "comms.h"
#ifdef BSD
struct timezone tz={0,0};
struct timeval tv;
long lastsec=0;
/* return time in cs ( will fail if test runs for more than */
/* 240 days (2^31/(60*60*24*100)) */
int
gettime()
{
gettimeofday(&tv,&tz);
if(lastsec==0)
lastsec=tv.tv_sec;
return((tv.tv_sec-lastsec)*100+(tv.tv_usec/10000));
}
#else
struct timeb tb;
long lastsec=0;
int
gettime()
{
ftime(&tb);
if(lastsec==0)
lastsec=tb.time;
return((tb.time-lastsec)*100+tb.millitm/10);
}
#endif
int
rnd(n) /* a random no. between 0 and n-1 */
int n;
{
return((rand()/153)%n);
}
void /* because Ultrix doesn't provide the nice SunOS ualarm() */
myualarm(val)
int val;
{
struct itimerval itv;
itv.it_interval.tv_sec=0;
itv.it_interval.tv_usec=0;
itv.it_value.tv_sec=0;
itv.it_value.tv_usec=val;
setitimer(ITIMER_REAL,&itv,NULL);
}
int
GetAngle(x1,y1,x2,y2) /* return an angle between two points */
int x1,y1,x2,y2;
{
double xc,yc,theta;
int ang;
xc=(double)(x1-x2);
yc=(double)(y1-y2);
if(xc==0.0)
{
if(yc>0)
theta=(PI/2.0);
else
theta=(-PI/2.0);
}
else
{
theta=atan2(yc,xc);
}
theta=(TANKROT*(theta/(2.0*PI)));
ang=(int)(theta+0.5+TANKROT)%TANKROT;
return(ang);
}