Mercurial > ~darius > hgwebdir.cgi > paradise_server
comparison src/wander2.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 #include "config.h" | |
20 | |
21 #include <stdio.h> | |
22 #include <malloc.h> | |
23 #include <string.h> | |
24 #include <sys/types.h> | |
25 #include <sys/time.h> | |
26 #include <signal.h> | |
27 #include <setjmp.h> | |
28 #include <sys/file.h> | |
29 #include <math.h> | |
30 #include <sys/ipc.h> | |
31 #include <sys/shm.h> | |
32 #include <errno.h> | |
33 #include <pwd.h> | |
34 #include <ctype.h> | |
35 #include "defs.h" | |
36 #include "struct.h" | |
37 #include "data.h" | |
38 | |
39 extern void (*r_signal()) (); | |
40 | |
41 extern struct planet *planets; | |
42 | |
43 #define COS(x) ((x) >= 0.0 ? Cosine[(int)(x)] : Cosine[(int)(-(x))]) | |
44 #define SIN(x) ((x) >= 0.0 ? Sine[(int)(x)] : -Sine[(int)(-(x))]) | |
45 | |
46 #define PUPDATE 999999 | |
47 | |
48 int pl_home[4]; | |
49 int pl_core[4][10]; | |
50 int pl_dist[4][10]; | |
51 double increment = 0.016; | |
52 double incrementrecip = 62.5; | |
53 float *Cosine, *Sine; | |
54 | |
55 double dpre; | |
56 double fpre; | |
57 double pi = 3.1415926; | |
58 | |
59 int planeti, planetj; | |
60 | |
61 /* call only once */ | |
62 | |
63 | |
64 void | |
65 pinit() | |
66 { | |
67 double dx, dy; | |
68 int i, j; | |
69 | |
70 int pre; | |
71 | |
72 void pmove(); | |
73 | |
74 pre = 3.5 / increment; | |
75 dpre = (double) pre; | |
76 | |
77 Cosine = (float *) calloc(sizeof(float), pre); | |
78 Sine = (float *) calloc(sizeof(float), pre); | |
79 for (i = 0; i < pre; i++) | |
80 { | |
81 Cosine[i] = cos((double) i * increment); | |
82 Sine[i] = sin((double) i * increment); | |
83 } | |
84 | |
85 /* openmem(); */ | |
86 | |
87 pl_home[0] = 0; | |
88 pl_core[0][0] = 5; | |
89 pl_core[0][1] = 7; | |
90 pl_core[0][2] = 8; | |
91 pl_core[0][3] = 9; | |
92 pl_home[1] = 10; | |
93 pl_core[1][0] = 12; | |
94 pl_core[1][1] = 15; | |
95 pl_core[1][2] = 16; | |
96 pl_core[1][3] = 19; | |
97 pl_home[2] = 20; | |
98 pl_core[2][0] = 24; | |
99 pl_core[2][1] = 26; | |
100 pl_core[2][2] = 29; | |
101 pl_core[2][3] = 25; | |
102 pl_home[3] = 30; | |
103 pl_core[3][0] = 34; | |
104 pl_core[3][1] = 37; | |
105 pl_core[3][2] = 38; | |
106 pl_core[3][3] = 39; | |
107 | |
108 for (i = 0; i < 4; i++) | |
109 { | |
110 for (j = 0; j < 4; j++) | |
111 { | |
112 dx = (double) (planets[pl_core[i][j]].pl_x - planets[pl_home[i]].pl_x); | |
113 dy = (double) (planets[pl_home[i]].pl_y - planets[pl_core[i][j]].pl_y); | |
114 pl_dist[i][j] = isqrt(dx * dx + dy * dy); | |
115 /* pl_dist[i][j] = 12000; */ | |
116 } | |
117 } | |
118 | |
119 planeti = 0; | |
120 planetj = 0; | |
121 | |
122 #if 0 | |
123 { | |
124 static struct itimerval udt; | |
125 r_signal(SIGALRM, pmove); | |
126 | |
127 udt.it_interval.tv_sec = 0; | |
128 udt.it_interval.tv_usec = PUPDATE; | |
129 udt.it_value.tv_sec = 0; | |
130 udt.it_value.tv_usec = PUPDATE; | |
131 (void) setitimer(ITIMER_REAL, &udt, (struct itimerval *) 0); | |
132 | |
133 while (1) | |
134 pause(); | |
135 } | |
136 #endif | |
137 } | |
138 | |
139 /* call once per second */ | |
140 void | |
141 pmove() | |
142 { | |
143 int i, j; | |
144 double dir; | |
145 double dx, dy; | |
146 | |
147 /* | |
148 * for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { | |
149 */ | |
150 i = planeti; | |
151 j = planetj; | |
152 planetj = (planetj + 1) % 4; | |
153 if (planetj == 0) | |
154 planeti = (planeti + 1) % 4; | |
155 | |
156 dir = atan2((double) (planets[pl_core[i][j]].pl_y - planets[pl_home[i]].pl_y), | |
157 (double) (planets[pl_core[i][j]].pl_x - planets[pl_home[i]].pl_x)); | |
158 if (dir > pi) | |
159 dir = dir - 2.0 * pi; | |
160 if (dir >= 0.0) | |
161 dir = (dir * incrementrecip + 1.5); | |
162 else | |
163 dir = (dir * incrementrecip + 0.5); | |
164 | |
165 | |
166 planets[pl_core[i][j]].pl_x = | |
167 planets[pl_home[i]].pl_x + | |
168 (int) (pl_dist[i][j] * (dx = COS(dir))); | |
169 planets[pl_core[i][j]].pl_y = | |
170 planets[pl_home[i]].pl_y + | |
171 (int) (pl_dist[i][j] * (dy = SIN(dir))); | |
172 /* | |
173 * dir = atan2((double) (planets[pl_core[i][j]].pl_y - | |
174 * planets[pl_home[i]].pl_y), (double) (planets[pl_core[i][j]].pl_x - | |
175 * planets[pl_home[i]].pl_x)); | |
176 */ | |
177 | |
178 /* planets[pl_core[i][j]].pl_flags |= PLREDRAW; */ | |
179 } | |
180 | |
181 /* | |
182 * } } | |
183 */ | |
184 | |
185 /* | |
186 * usage(string) char *string; { printf("Usage: %s [-dnnn]\n", string); | |
187 * printf(" -dnnn delay nnn 1/10 seconds between frames\n"); } | |
188 * | |
189 * openmem() { extern int errno; int shmemKey = PKEY; int shmid; struct | |
190 * memory *sharedMemory; | |
191 * | |
192 * errno = 0; shmid = shmget(shmemKey, 0, 0); if (shmid < 0) { if (errno != | |
193 * ENOENT) { fprintf(stderr, "shmget\n"); exit(1); } shmid = shmget(shmemKey, | |
194 * 0, 0); if (shmid < 0) { fprintf(stderr, "Daemon not running\n"); exit (1); | |
195 * } } sharedMemory = (struct memory *) shmat(shmid, 0, 0); if (sharedMemory | |
196 * == (struct memory *) -1) { fprintf(stderr, "shared memory\n"); exit (1); } | |
197 * players = sharedMemory->players; torps = sharedMemory->torps; plasmatorps | |
198 * = sharedMemory->plasmatorps; planets = sharedMemory->planets; phasers = | |
199 * sharedMemory->phasers; mctl = sharedMemory->mctl; messages = | |
200 * sharedMemory->messages; teams = sharedMemory->teams; status = | |
201 * sharedMemory->status; } | |
202 */ |