comparison src/util.c @ 8:0836fb919dfa

First entry of Paradise Server 2.9 patch 10 Beta
author darius
date Sat, 06 Dec 1997 04:37:05 +0000
parents
children
comparison
equal deleted inserted replaced
7:814de70c9f67 8:0836fb919dfa
1 /*--------------------------------------------------------------------------
2 NETREK II -- Paradise
3
4 Permission to use, copy, modify, and distribute this software and its
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
6 purpose and without fee is hereby granted, provided that this copyright
7 notice appear in all copies. No representations are made about the
8 suitability of this software for any purpose. This software is provided
9 "as is" without express or implied warranty.
10
11 Xtrek Copyright 1986 Chris Guthrie
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
13 Scott Silvey
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
15 Kurt Olsen
16 Brandon Gillespie
17 --------------------------------------------------------------------------*/
18
19
20 #include "config.h"
21
22 #include <stdio.h>
23 #include <math.h>
24 #include <signal.h>
25 #include <sys/time.h>
26 #include "defs.h"
27 #include "struct.h"
28 #include "data.h"
29 #include "shmem.h"
30
31 struct player *me;
32 struct ship *myship;
33 struct stats *mystats;
34
35
36
37 /*----------------------------VISIBLE FUNCTIONS---------------------------*/
38
39 /*-------------------------------ANGDIST----------------------------------*/
40 /*
41 * This function provides the proper angular distance between two angles. The
42 * angles are expressed as numbers from 0-255.
43 */
44
45 int
46 angdist(x, y)
47 unsigned char x, y;
48 {
49 register unsigned char res; /* temp var */
50
51 res = x - y; /* get abs value of difference */
52 if (res > 128) /* if more than 180 degrees */
53 return (256 - (int) res); /* then choose to go other way around */
54 return ((int) res); /* else its just the difference */
55 }
56
57 /*-------------------------------------------------------------------------*/
58
59
60 /*
61 * this function checks to see if an occurrence is temporally spaced from the
62 * previous one. This is useful in preventing the client from firing torps
63 * and missiles too quickly and to limit detting to a reasonable frequency
64 * (detting too fast burns fuel and increases wtemp without any benefit).
65 */
66
67 int
68 temporally_spaced(lasttime, gap)
69 struct timeval *lasttime;
70 int gap; /* microseconds */
71 {
72 struct timeval curtp;
73
74 gettimeofday(&curtp, (struct timezone *) 0);
75 if ((curtp.tv_sec == lasttime->tv_sec &&
76 curtp.tv_usec < lasttime->tv_usec + gap)
77 || (curtp.tv_sec == lasttime->tv_sec + 1 &&
78 curtp.tv_usec + 1000000 < lasttime->tv_usec + gap))
79 return 0;
80
81 lasttime->tv_sec = curtp.tv_sec;
82 lasttime->tv_usec = curtp.tv_usec;
83 return 1;
84 }
85
86 /*
87 */
88
89 int
90 check_fire_warp()
91 {
92 if (configvals->fireduringwarp || !(me->p_flags & PFWARP))
93 return 1;
94
95 warning("Can not fire while in warp.");
96
97 return 0;
98 }
99
100 int
101 check_fire_warpprep()
102 {
103 if (configvals->fireduringwarpprep || !me->p_warptime)
104 return 1;
105
106 warning("Can not fire while preparing for warp.");
107
108 return 0;
109 }
110
111 int
112 check_fire_docked()
113 {
114 if (configvals->firewhiledocked || !(me->p_flags & PFDOCK))
115 return 1;
116
117 warning("It is unsafe to use weapons while docked.");
118
119 return 0;
120 }
121
122
123 /*-------END OF FILE--------*/