annotate util.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1 /* $Id: util.c,v 1.1.1.1 1997/12/06 05:41:31 darius Exp $ */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
2
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
3 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
4 * util.c
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
5 * added functionality to gettarget() - Bill Dyess 10/6/93
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
6 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
7 #include "copyright.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
8
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
9 #include <stdio.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
10 #include <math.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
11 #include <signal.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
12 #include <stdlib.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
13 #include "Wlib.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
14 #include "defs.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
15 #include "struct.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
16 #include "data.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
17 #include "proto.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
18 #include "gameconf.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
19
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
20 #if 0
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
21 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
22 ** Provide the angular distance between two angles.
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
23 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
24 angdist(x, y)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
25 unsigned char x, y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
26 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
27 register unsigned char res;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
28
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
29 if (x > y)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
30 res = x - y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
31 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
32 res = y - x;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
33 if (res > 128)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
34 return (256 - (int) res);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
35 return ((int) res);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
36 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
37 #endif
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
38
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
39 double
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
40 hypot2(x, y)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
41 double x, y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
42 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
43 return sqrt(x * x + y * y);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
44 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
45
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
46 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
47 * * Find the object nearest mouse. Returns a pointer to an * obtype
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
48 * structure. This is used for info and locking on. *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
49 *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
50 * Because we are never interested in it, this function will * never return
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
51 * your own ship as the target. *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
52 *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
53 * Finally, this only works on the two main windows
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
54 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
55
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
56 static struct obtype _target;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
57
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
58 struct obtype *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
59 gettarget(ww, x, y, targtype)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
60 W_Window ww;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
61 int x, y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
62 int targtype;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
63 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
64 /* now can get the closest friendly/enemy player or planet. Use
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
65 TARG_FRIENDLY or TARG_ENEMY or'd with TARG_PLAYER or TARG_PLANET */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
66 register int i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
67 register struct player *j;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
68 register struct planet *k;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
69 int g_x, g_y, friendly;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
70 double dist, closedist;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
71 int slotnum, width;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
72
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
73 if (ww == mapw) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
74 register gwidth, offsetx, offsety;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
75 if (blk_zoom) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
76 gwidth = blk_gwidth / 2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
77 offsetx = zoom_offset(me->p_x);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
78 offsety = zoom_offset(me->p_y);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
79 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
80 gwidth = blk_gwidth;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
81 offsetx = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
82 offsety = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
83 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
84 g_x = x * (gwidth / WINSIDE) + offsetx;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
85 g_y = y * (gwidth / WINSIDE) + offsety;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
86
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
87 } else if (ww == playerw) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
88 if (targtype & TARG_PLAYER) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
89 W_TranslatePoints(playerw, &x, &y);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
90 y -= 2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
91 if (y < 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
92 y = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
93 if (*playerList == 0 || *playerList == ',') {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
94 if (y > 15)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
95 y = 15;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
96 slotnum = y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
97 width = W_WindowWidth(ww);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
98 if (x > width / 2)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
99 slotnum += 16;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
100 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
101 slotnum = y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
102 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
103 if (slot[slotnum] != -1 &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
104 (paradise || !(players[slot[slotnum]].p_flags & PFCLOAK))) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
105 /* don't show info for cloakers on Bronco servers */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
106 _target.o_type = PLAYERTYPE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
107 _target.o_num = slot[slotnum];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
108 return &_target;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
109 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
110 return NULL; /* no target found */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
111 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
112 g_x = me->p_x + ((x - WINSIDE / 2) * SCALE);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
113 g_y = me->p_y + ((y - WINSIDE / 2) * SCALE);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
114 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
115 } else if (ww) { /* tactical window */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
116 g_x = me->p_x + ((x - WINSIDE / 2) * SCALE);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
117 g_y = me->p_y + ((y - WINSIDE / 2) * SCALE);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
118 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
119 g_x = x;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
120 g_y = y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
121 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
122 closedist = blk_gwidth;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
123
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
124 if (targtype & TARG_ASTRAL) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
125 for (i = 0, k = &planets[0]; i < nplanets; i++, k++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
126 int ptype = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
127 friendly = friendlyPlanet(k);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
128 if (friendly && (targtype & TARG_ENEMY))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
129 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
130 if (!friendly && (targtype & TARG_FRIENDLY))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
131 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
132 if (k->pl_owner != idx_to_mask(me->p_teami) && (targtype & TARG_TEAM))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
133 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
134 switch (PL_TYPE(*k)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
135 case PLPLANET:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
136 ptype = TARG_PLANET;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
137 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
138 case PLSTAR:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
139 ptype = TARG_STAR;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
140 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
141 case PLAST:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
142 ptype = TARG_PLANET;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
143 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
144 case PLNEB:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
145 ptype = TARG_NEBULA;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
146 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
147 case PLBHOLE:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
148 ptype = TARG_BLACKHOLE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
149 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
150 case PLPULSAR:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
151 ptype = TARG_STAR;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
152 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
153 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
154 if (!(ptype & targtype))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
155 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
156 dist = hypot((double) (g_x - k->pl_x), (double) (g_y - k->pl_y));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
157 if (dist < closedist) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
158 _target.o_type = PLANETTYPE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
159 _target.o_num = i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
160 closedist = dist;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
161 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
162 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
163 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
164 if (targtype & TARG_PLAYER) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
165 for (i = 0, j = &players[i]; i < nplayers; i++, j++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
166 if (j->p_status != PALIVE)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
167 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
168 if ((j->p_flags & PFCLOAK) && (!(targtype & TARG_CLOAK)) && j != me)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
169 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
170 if (j == me && !(targtype & TARG_SELF))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
171 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
172 friendly = friendlyPlayer(j);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
173 if (friendly && (targtype & TARG_ENEMY))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
174 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
175 if (!friendly && (targtype & TARG_FRIENDLY))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
176 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
177 if (j->p_teami != me->p_teami && targtype & TARG_TEAM)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
178 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
179 if (!(targtype & (isBase(j->p_ship->s_type)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
180 ? TARG_BASE
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
181 : TARG_SHIP)))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
182 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
183 dist = hypot((double) (g_x - j->p_x), (double) (g_y - j->p_y));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
184 if (dist <= closedist) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
185 _target.o_type = PLAYERTYPE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
186 _target.o_num = i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
187 closedist = dist;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
188 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
189 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
190 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
191 if (closedist == blk_gwidth) { /* Didn't get one. bad news */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
192 _target.o_type = PLAYERTYPE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
193 _target.o_num = me->p_no; /* Return myself. Oh well... */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
194 return (&_target);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
195 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
196 return (&_target);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
197 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
198 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
199
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
200 #ifdef hpux
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
201
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
202 srandom(foo)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
203 int foo;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
204 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
205 rand(foo);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
206 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
207
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
208 random()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
209 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
210 return (rand());
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
211 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
212
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
213 #include <time.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
214 #include <sys/resource.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
215
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
216 #include <sys/signal.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
217
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
218 void (*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
219 signal(sig, funct)) ()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
220 int sig;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
221 void (*funct) ();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
222 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
223 struct sigvec vec, oldvec;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
224
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
225 sigvector(sig, 0, &vec);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
226 vec.sv_handler = funct;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
227 sigvector(sig, &vec, (struct sigvec *) 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
228 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
229 #endif /* hpux */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
230
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
231
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
232 char *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
233 team_bit_string(mask)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
234 int mask;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
235 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
236 static char visitorstring[16]; /* better not have more than 16 teams */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
237 int i;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
238
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
239 for (i = 0; i < number_of_teams; i++) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
240 visitorstring[i] = (mask & (1 << i)) ? teaminfo[i].letter : ' ';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
241 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
242 visitorstring[i] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
243 return visitorstring;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
244 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
245
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
246 /* getTargetID returns an id stuct containing then name of the object, the
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
247 type of object, the number of the object, the
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
248 team the object belongs to, and . Used a lot in the macro code.
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
249 [BDyess] */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
250
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
251 struct id *
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
252 getTargetID(ww, x, y, targtype)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
253 W_Window ww;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
254 int x, y;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
255 int targtype;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
256 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
257 struct obtype *target;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
258 static struct id buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
259 struct player *j;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
260 struct planet *k;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
261
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
262 target = gettarget(ww, x, y, targtype);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
263 if (target->o_type == PLAYERTYPE) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
264 buf.type = PLAYERTYPE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
265 j = &players[target->o_num];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
266 buf.name = j->p_name;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
267 buf.number = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
268 buf.team = j->p_teami;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
269 buf.mapstring[0] = j->p_mapchars[0];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
270 buf.mapstring[1] = j->p_mapchars[1];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
271 buf.mapstring[2] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
272 } else if (target->o_type == PLANETTYPE) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
273 buf.type = PLANETTYPE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
274 k = &planets[target->o_num];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
275 buf.name = k->pl_name;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
276 buf.number = target->o_num;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
277 buf.team = mask_to_idx(k->pl_owner);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
278 if (0 == strncmp(k->pl_name, "New ", 4)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
279 strncpy(buf.mapstring, k->pl_name + 4, 3);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
280 } else if (0 == strncmp(k->pl_name, "Planet ", 7)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
281 strncpy(buf.mapstring, k->pl_name + 7, 3);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
282 } else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
283 strncpy(buf.mapstring, k->pl_name, 3);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
284 buf.mapstring[3] = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
285 } else { /* tried to find something that doesn't exist */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
286 return NULL;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
287 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
288 return &buf;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
289 }