Mercurial > ~darius > hgwebdir.cgi > paradise_server
annotate src/weapons.c @ 17:65de6eb6861a
Indenting...
author | darius |
---|---|
date | Wed, 24 Dec 1997 12:37:24 +0000 |
parents | ed82a42ba89d |
children | 9f180bf494bd |
rev | line source |
---|---|
9 | 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 <stdlib.h> | |
23 #include <string.h> | |
24 #include <math.h> | |
25 #include <setjmp.h> | |
26 | |
27 #include "defs.h" | |
28 #include "struct.h" | |
29 #include "data.h" | |
30 #include "daemonII.h" | |
31 #include "weapons.h" | |
32 #include "shmem.h" | |
33 | |
34 | |
35 | |
36 /*------------------------------VISIBLE FUNCTIONS-------------------------*/ | |
37 | |
38 /*---------------------------------HOSTILE_TO-----------------------------*/ | |
39 /* | |
40 * This returns whether an object is hostile to another object. It returns 1 | |
41 * if we are hostile or at war with the object | |
42 */ | |
43 | |
44 | |
45 extern int inflict_damage(); | |
46 int torp_track_opportunity(); | |
47 extern void move_torp(); | |
48 extern void move_missile(); | |
49 | |
50 int | |
51 hostile_to(warmask, team, pl) | |
52 int warmask, team; | |
53 struct player *pl; | |
54 { | |
55 return (warmask & pl->p_team) || (team & (pl->p_swar | pl->p_hostile)); | |
56 } | |
57 | |
58 | |
59 | |
60 | |
61 /*----------------------------------EXPLODE-------------------------------*/ | |
62 /* | |
63 * This function decides which players to inflict damage on when a torp | |
64 * explodes. | |
65 */ | |
66 | |
67 void | |
68 explode_damage(torp, radius, why) | |
69 struct basetorp *torp; | |
70 int radius; | |
71 int why; | |
72 { | |
73 register int i; /* looping var */ | |
74 int dx, dy, dist; /* to calc distance from torp to players */ | |
75 int damage; /* to hold damage inflicted */ | |
76 register struct player *j; /* to point to players */ | |
77 | |
78 for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) | |
79 { | |
80 if (j->p_status != PALIVE) /* no need to check players not alive */ | |
81 continue; | |
82 | |
83 if (j->p_no == torp->bt_owner) /* General Vote, September, 1995. */ | |
84 continue; /* Torps no longer damage owner. */ | |
85 | |
86 if ((torp->bt_status == TDET) /* if torp was detted then */ | |
87 && ((j->p_no == torp->bt_owner) || /* cannot damage firing | |
88 * player */ | |
89 ((j->p_no != torp->bt_whodet) /* cannot damage players on | |
90 * same team */ | |
91 && (j->p_team == players[torp->bt_whodet].p_team))) | |
92 ) /* except the detter */ | |
93 continue; | |
94 | |
95 dx = torp->bt_x - j->p_x; /* calc delta x and y */ | |
96 dy = torp->bt_y - j->p_y; | |
97 if (ABS(dx) > radius || ABS(dy) > radius) | |
98 continue; /* continue if obviously too far */ | |
99 | |
100 dist = dx * dx + dy * dy; /* calc distnace squared */ | |
101 if (dist > radius * radius) /* if not within damage distance */ | |
102 continue; /* then continue */ | |
103 if (dist > EXPDIST * EXPDIST) /* if not direct hit */ | |
104 damage = torp->bt_damage * (radius - sqrt((double) dist)) / | |
105 (radius - EXPDIST); | |
106 else /* else if direct hit */ | |
107 damage = torp->bt_damage; /* do torp damage */ | |
108 | |
109 if (damage > 0) | |
110 { /* if damage was done then */ | |
111 if (players[torp->bt_owner].p_hostile & j->p_team) /* start war if */ | |
112 players[torp->bt_owner].p_swar |= j->p_team; /* necessary */ | |
113 inflict_damage(&players[torp->bt_owner], &players[torp->bt_whodet], | |
114 j, damage, why); | |
115 } | |
116 } | |
117 } | |
118 | |
119 void | |
120 explode(torp) | |
121 struct basetorp *torp; /* pointer to exploding torp's struct */ | |
122 { | |
123 explode_damage(torp, DAMDIST, KTORP); | |
124 torp->bt_status = TEXPLODE; /* set the torp to explode */ | |
125 torp->bt_fuse = 10 / TORPFUSE; | |
126 } | |
127 | |
128 | |
129 /*---------------------------------PEXPLODE-------------------------------*/ | |
130 /* | |
131 * This function does the explosion of a plasma torp. It goes through all | |
132 * players and damages them if they are close enough to get damaged | |
133 */ | |
134 | |
135 void | |
136 pexplode(plasmatorp) | |
137 struct plasmatorp *plasmatorp;/* ptr to plasma to explode */ | |
138 { | |
139 explode_damage(&plasmatorp->pt_base, PLASDAMDIST, KPLASMA); | |
140 plasmatorp->pt_status = PTEXPLODE; /* set the plasma to explode */ | |
141 plasmatorp->pt_fuse = 10 / PLASMAFUSE; | |
142 } | |
143 | |
144 | |
145 /*-------------------------------UDPHASER----------------------------------*/ | |
146 /* | |
147 * This function goes through all players and calcs the damage from a phaser | |
148 * hit if the phaser hit a target. | |
149 */ | |
150 | |
151 void | |
152 udphaser() | |
153 { | |
154 register int i; /* looping var */ | |
155 register struct phaser *j; /* to point to phaser being fired */ | |
156 register struct player *victim; /* to point to the poor victim */ | |
157 | |
158 for (i = 0, j = &phasers[i]; i < MAXPLAYER; i++, j++) | |
159 { /* all players */ | |
160 switch (j->ph_status) | |
161 { /* check player's phaser status */ | |
162 case PHFREE: /* if not beging fired */ | |
163 continue; /* then continue */ | |
164 case PHMISS: /* if it missed */ | |
165 case PHHIT2: /* or ????? */ | |
166 if (j->ph_fuse-- == 1) /* dec count of phaser */ | |
167 j->ph_status = PHFREE; /* free it up if count done */ | |
168 break; | |
169 case PHHIT: /* if it hit someone then */ | |
170 if (j->ph_fuse-- == players[i].p_ship.s_phaser.fuse) | |
171 { | |
172 victim = &players[j->ph_target]; /* get the victim */ | |
173 if (players[i].p_hostile & victim->p_team) /* start war if */ | |
174 players[i].p_swar |= victim->p_team; /* necessary */ | |
175 if (victim->p_status == PALIVE) /* only damage if alive */ | |
176 inflict_damage(&players[i], 0, victim, j->ph_damage, KPHASER); | |
177 } /* end of if phaser hit someone */ | |
178 if (j->ph_fuse == 0) | |
179 j->ph_status = PHFREE; | |
180 break; | |
181 } /* end of switch */ | |
182 } /* end of for loop through players */ | |
183 } | |
184 | |
185 | |
186 | |
187 /*----------------------------WEAP_NEAR_OBJECT-----------------------------*/ | |
188 /* This function checks for objects within *dist* of a weapon. */ | |
189 /* this function will use the space grid */ | |
190 | |
191 int | |
192 weap_near_object(torp, type, dist) | |
193 struct basetorp *torp; | |
194 int type; | |
195 int dist; | |
196 { | |
197 register struct planet *pl; /* to point to the planets */ | |
198 int dx, dy, i; | |
199 | |
200 for (i = 0, pl = &planets[i]; i < NUMPLANETS; i++, pl = &planets[i]) | |
201 { | |
202 if (PL_TYPE(*pl) != type) | |
203 /* if not of the type specified, don't bother */ | |
204 continue; | |
205 dx = torp->bt_x - pl->pl_x; | |
206 dy = torp->bt_y - pl->pl_y; | |
207 if (ABS(dx) > dist || ABS(dy) > dist) | |
208 continue; /* the obvious thing */ | |
209 if (dx * dx + dy * dy < dist * dist) | |
210 return 1; /* yep, it hit. return a 1. */ | |
211 } | |
212 return 0; /* return that it should continue */ | |
213 } | |
214 | |
215 int | |
216 near_player(torp, dist) | |
217 struct basetorp *torp; /* the torp to check for */ | |
218 int dist; | |
219 { | |
220 register int i; /* looping var */ | |
221 int dx, dy; /* to calc torp-player distance */ | |
222 register struct player *j; /* to point to players */ | |
223 | |
224 for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) | |
225 { | |
226 if (j->p_status != PALIVE) | |
227 continue; /* don't check players not alive */ | |
228 if (j->p_no == torp->bt_owner) | |
229 continue; /* no exploding on self */ | |
230 if (!hostile_to(torp->bt_war, torp->bt_team, j)) | |
231 continue; /* disregard if both teams not at war */ | |
232 dx = torp->bt_x - j->p_x; /* calc delta coords */ | |
233 dy = torp->bt_y - j->p_y; | |
234 if (ABS(dx) > dist || ABS(dy) > dist) | |
235 continue; /* disregard if obviously too far */ | |
236 if (dx * dx + dy * dy < dist * dist) | |
237 { | |
238 torp->bt_whodet = i; /* this guy is the detonator */ | |
239 return 1; /* if close enough to explode then return 1 */ | |
240 } | |
241 } | |
242 return 0; /* return that torp should continue */ | |
243 } | |
244 | |
245 | |
246 int | |
247 f_land(mis) /* the fighter landing function */ | |
248 struct missile *mis; /* the fighter to check for */ | |
249 { | |
250 int dx, dy; /* to calc fighter-player distance */ | |
251 register struct player *j; /* to point to players */ | |
252 | |
253 j = &players[mis->ms_owner]; | |
254 | |
255 if (!(j->p_armies < j->p_ship.s_maxarmies)) | |
256 return 0; /* no room! */ | |
257 dx = mis->ms_x - j->p_x; /* calc delta coords */ | |
258 dy = mis->ms_y - j->p_y; | |
259 if (ABS(dx) > EXPDIST || ABS(dy) > EXPDIST) | |
260 return 0; /* obviously too far */ | |
261 if (dx * dx + dy * dy < EXPDIST * EXPDIST) | |
262 return 1; /* if close enough to land then return 1 */ | |
263 | |
264 return 0; /* return that fighter should continue */ | |
265 } | |
266 | |
267 | |
268 /*----------------------------------PNEAR----------------------------------*/ | |
269 /* | |
270 * This function goes through the players and sees if there is a player close | |
271 * enough for a plasma torp to explode on. This function returns a 1 if the | |
272 * plasma should explode and a 0 if it should continue to travel through | |
273 * spac. | |
274 */ | |
275 | |
276 int | |
277 pnear(plasmatorp) | |
278 struct plasmatorp *plasmatorp;/* the plasma torp to check for */ | |
279 { | |
280 return near_player(&plasmatorp->pt_base, EXPDIST); | |
281 } | |
282 | |
283 | |
284 int | |
285 outofbounds(x, y) | |
286 int x, y; | |
287 { | |
288 return x < 0 || x > GWIDTH || y < 0 || y > GWIDTH; | |
289 } | |
290 | |
291 /*--------------------------------UDTORPS----------------------------------*/ | |
292 /* | |
293 * This function updates the torps. It goes through all torps and checks to | |
294 * see if they need to be updated. It they are mving they track toward the | |
295 * nearest target. this function also handles the explosion and makes sure | |
296 * that torps do not go off the edge of the galaxy. | |
297 */ | |
298 | |
299 void | |
300 udtorps() | |
301 { | |
302 register int i; /* looping var--to loop through torps */ | |
303 int turn; /* to get whether to go right or left */ | |
304 int heading; /* to hold torps heading */ | |
305 register struct torp *j; /* to point to torps */ | |
306 | |
307 for (i = 0, j = &torps[i]; i < MAXPLAYER * MAXTORP; i++, j++) | |
308 { | |
309 switch (j->t_status) | |
310 { /* check status of torp */ | |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
311 case TFREE: /* if torp not active then */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
312 continue; /* go on to next torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
313 case TMOVE: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
314 case TSTRAIGHT: /* if torp moving then */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
315 if (j->t_turns > 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
316 { /* if torp can turn then */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
317 turn = torp_track_opportunity |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
318 (&j->t_base, j->t_turns, |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
319 configvals->improved_tracking[SS_PHOTON]); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
320 /* should we go right or left */ |
9 | 321 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
322 if ((terrain_grid[(int) (j->t_x) / TGRID_GRANULARITY * TGRID_SIZE + |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
323 (int) (j->t_y) / TGRID_GRANULARITY].types |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
324 & T_NEBULA) && neb_effect[SS_PHOTON]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
325 if(TORP_NEB_EFF > (lrand48() % 100)) /* Is torp affected? */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
326 turn = (lrand48() % 2); /* Yes */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
327 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
328 if (turn < 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
329 { /* we will go left */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
330 heading = ((int) j->t_dir) - j->t_turns; /* turn left */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
331 if (heading < 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
332 j->t_dir = heading + 256; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
333 /* |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
334 * j->t_dir = ((heading < 0) ? ((unsigned char) (256 + heading)) : |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
335 * ((unsigned char) heading)); * no underflow |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
336 */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
337 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
338 else if (turn > 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
339 { /* we will go right */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
340 heading = ((int) j->t_dir) + j->t_turns; /* turn right */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
341 if (heading > 255) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
342 j->t_dir = heading - 256; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
343 /* |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
344 * j->t_dir = ((heading > 255) ? ((unsigned char) (heading - 256)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
345 * : ((unsigned char) heading)); * no overflow |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
346 */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
347 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
348 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
349 j->t_x += (double) j->t_speed * Cos[j->t_dir] * WARP1; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
350 j->t_y += (double) j->t_speed * Sin[j->t_dir] * WARP1; |
9 | 351 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
352 move_torp(i, j->t_x, j->t_y, 1); |
9 | 353 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
354 if (j->t_status == TMOVE) /* if a TMOVE torp then */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
355 j->t_dir += (lrand48() % 3) - 1; /* make the torp wobble */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
356 if (j->t_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
357 { /* dec torp's life and see if dead */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
358 j->t_status = TFREE; /* dead, free the torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
359 move_torp(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
360 players[j->t_owner].p_ntorp--; /* let player fire another */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
361 break; /* no more torp processing */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
362 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
363 if ((sun_effect[SS_PHOTON] && weap_near_object(&j->t_base, PLSTAR, ORBDIST)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
364 || |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
365 (wh_effect[SS_PHOTON] && weap_near_object(&j->t_base, PLWHOLE, ORBDIST))) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
366 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
367 /* did it hit a star or wormhole? */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
368 j->t_whodet = j->t_owner; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
369 explode(&j->t_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
370 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
371 } |
9 | 372 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
373 if ((terrain_grid[(int) (j->t_x) / TGRID_GRANULARITY * TGRID_SIZE + |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
374 (int) (j->t_y) / TGRID_GRANULARITY].types |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
375 & T_ASTEROIDS) && ast_effect[SS_PHOTON]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
376 if (TORP_HIT_AST > (lrand48() % 100)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
377 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
378 explode(&j->t_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
379 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
380 } |
9 | 381 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
382 if (near_player(&j->t_base, EXPDIST)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
383 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
384 /* if torp near enough to hit */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
385 explode(&j->t_base); /* let torp explode on player */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
386 } |
9 | 387 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
388 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
389 case TDET: /* if torp was detted */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
390 explode(&j->t_base); /* make it explode */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
391 break; /* on to next torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
392 case TEXPLODE: /* if torp exploding */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
393 if (j->t_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
394 { /* dec explosion timer */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
395 j->t_status = TFREE; /* if torp done, free it up */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
396 move_torp(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
397 players[j->t_owner].p_ntorp--; /* let player fire another */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
398 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
399 break; /* on to next torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
400 case TOFF: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
401 j->t_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
402 move_torp(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
403 players[j->t_owner].p_ntorp--; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
404 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
405 default: /* Shouldn't happen */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
406 j->t_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
407 break; |
9 | 408 } /* end of switch */ |
409 } /* end of for */ | |
410 } | |
411 | |
412 void | |
413 udmissiles() | |
414 { | |
415 int i; | |
416 int x, y, turn; | |
417 struct missile *mis; | |
418 struct player *j; | |
419 | |
420 for (i = 0; i < MAXPLAYER * NPTHINGIES; i++) | |
421 { | |
422 mis = &missiles[i]; | |
423 switch (mis->ms_status) | |
424 { | |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
425 case TFREE: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
426 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
427 case TLAND: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
428 j = &players[mis->ms_owner]; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
429 j->p_ship.s_missilestored++; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
430 j->p_armies = (int) (j->p_ship.s_missilestored / FAE_RATE); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
431 mis->ms_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
432 j->p_nthingys--; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
433 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
434 case TRETURN: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
435 case TMOVE: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
436 case TSTRAIGHT: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
437 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
438 if (mis->ms_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
439 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
440 mis->ms_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
441 move_missile(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
442 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
443 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
444 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
445 if (terrain_grid[(int) (mis->ms_x) / TGRID_GRANULARITY * TGRID_SIZE + |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
446 (int) (mis->ms_y) / TGRID_GRANULARITY].types |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
447 & T_ASTEROIDS) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
448 if ((mis->ms_type == FIGHTERTHINGY) && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
449 ast_effect[SS_FIGHTER] && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
450 (FIGHTER_HIT_AST > (lrand48() % 100))) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
451 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
452 mis->ms_whodet = mis->ms_owner; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
453 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
454 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
455 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
456 else if ((MISSILE_HIT_AST > (lrand48() % 100)) && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
457 ast_effect[SS_MISSILE]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
458 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
459 mis->ms_whodet = mis->ms_owner; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
460 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
461 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
462 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
463 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
464 if ((((sun_effect[SS_MISSILE] && mis->ms_type == MISSILETHINGY) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
465 || (sun_effect[SS_FIGHTER] && mis->ms_type == FIGHTERTHINGY)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
466 && weap_near_object(&mis->ms_base, PLSTAR, ORBDIST)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
467 || |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
468 (((wh_effect[SS_MISSILE] && mis->ms_type == MISSILETHINGY) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
469 || (wh_effect[SS_FIGHTER] && mis->ms_type == FIGHTERTHINGY)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
470 && weap_near_object(&mis->ms_base, PLWHOLE, ORBDIST))) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
471 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
472 /* did it hit a star? */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
473 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
474 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
475 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
476 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
477 j = &players[mis->ms_owner]; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
478 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
479 if (mis->ms_type == FIGHTERTHINGY && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
480 !(j->p_ship.s_nflags & SFNHASFIGHTERS)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
481 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
482 mis->ms_type = MISSILETHINGY; /* If the player no longer has em, */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
483 mis->ms_status = TMOVE; /* make his fighters kamikazes */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
484 mis->fi_hasfired = 0; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
485 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
486 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
487 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
488 if ((mis->ms_type == FIGHTERTHINGY) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
489 && ((mis->ms_fuse < .6 * j->p_ship.s_missile.fuse) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
490 || (mis->fi_hasfired)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
491 && mis->ms_status != TRETURN) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
492 mis->ms_status = TRETURN; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
493 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
494 if (mis->ms_turns > 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
495 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
496 if (mis->ms_type == FIGHTERTHINGY) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
497 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
498 turn = fighter_track_target(&mis->ms_base, mis->ms_turns); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
499 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
500 else |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
501 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
502 turn = torp_track_opportunity |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
503 (&mis->ms_base, mis->ms_turns, |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
504 configvals->improved_tracking[SS_MISSILE]); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
505 } |
9 | 506 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
507 if ((terrain_grid[(int) (mis->ms_x) / TGRID_GRANULARITY * TGRID_SIZE + |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
508 (int) (mis->ms_y) / TGRID_GRANULARITY].types |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
509 & T_NEBULA)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
510 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
511 if((mis->ms_type == FIGHTERTHINGY) && neb_effect[SS_FIGHTER]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
512 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
513 if(FIGHTER_NEB_EFF > (lrand48() % 100)) /* Is fighter affected? */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
514 turn = (lrand48() % 2); /* Yes */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
515 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
516 else |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
517 if(neb_effect[SS_MISSILE]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
518 if(MISSILE_NEB_EFF > (lrand48() % 100)) /* Is missile affected? */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
519 turn = (lrand48() % 2); /* Yes */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
520 |
9 | 521 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
522 mis->ms_dir = (unsigned char) (mis->ms_dir + turn * mis->ms_turns); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
523 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
524 x = mis->ms_x + mis->ms_speed * Cos[mis->ms_dir] * WARP1; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
525 y = mis->ms_y + mis->ms_speed * Sin[mis->ms_dir] * WARP1; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
526 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
527 move_missile(i, x, y, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
528 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
529 if (mis->ms_status != TSTRAIGHT) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
530 mis->ms_dir += (lrand48() % 3) - 1; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
531 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
532 if (mis->ms_type == MISSILETHINGY |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
533 && near_player(&mis->ms_base, EXPDIST)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
534 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
535 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
536 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
537 else if (mis->ms_type == FIGHTERTHINGY |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
538 && near_player(&mis->ms_base, FSTRIKEDIST) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
539 && !mis->fi_hasfired) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
540 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
541 if (f_torp(mis)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
542 mis->fi_hasfired = 1; /* if within strike range, fire a torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
543 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
544 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
545 if (mis->ms_status == TRETURN && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
546 f_land(mis)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
547 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
548 mis->ms_status = TLAND; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
549 move_missile(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
550 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
551 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
552 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
553 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
554 case TDET: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
555 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
556 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
557 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
558 case TEXPLODE: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
559 if (mis->ms_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
560 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
561 mis->ms_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
562 players[mis->ms_owner].p_nthingys--; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
563 move_missile(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
564 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
565 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
566 default: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
567 mis->ms_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
568 break; |
9 | 569 } |
570 } | |
571 } | |
572 | |
573 int | |
574 anticipate_impact(w, dx, dy, s, dir) | |
575 int w; /* speed of torp */ | |
576 int dx, dy; /* distance to target */ | |
577 int s, dir; /* speed of target */ | |
578 { | |
579 float sdx, sdy; | |
580 float a, b, c, d; | |
581 float t; | |
582 float tdx, tdy; | |
583 float theta; | |
584 | |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
585 /* mathematically, these affect t, but not |
9 | 586 * the return value */ |
587 s *= WARP1 * TICKSPERSEC; | |
588 w *= WARP1 * TICKSPERSEC; | |
589 | |
590 sdx = s * Cos[dir]; | |
591 sdy = s * Sin[dir]; | |
592 | |
593 a = s * (float) s - w * (float) w; | |
594 b = 2 * (sdx * (float) dx + sdy * (float) dy); | |
595 c = dx * (float) dx + dy * (float) dy; | |
596 | |
597 if (a == 0) | |
598 { | |
599 t = -c / b; | |
600 } | |
601 else | |
602 { | |
603 | |
604 d = b * b - 4 * a * c; | |
605 if (d < 0) | |
606 return -1; | |
607 d = sqrt(d); | |
608 | |
609 if (a < 0) | |
610 { | |
611 a = -a; | |
612 b = -b; | |
613 } | |
614 | |
615 t = (-b - d) / (2 * a); | |
616 | |
617 if (t < 0) | |
618 t = (-b + d) / (2 * a); | |
619 } | |
620 | |
621 if (t < 0) | |
622 return -1; | |
623 | |
624 if (t > 10) | |
625 return -1; | |
626 | |
627 tdx = dx / t + sdx; | |
628 tdy = dy / t + sdy; | |
629 | |
630 theta = atan2(tdx, -tdy); | |
631 return (unsigned char) (int) (theta * 128 / 3.14159); | |
632 } | |
633 | |
634 /*----------------------------TORP_TRACK_OPPORTUNITY----------------------*/ | |
635 /* | |
636 * This function finds the closest ship to a torp and returns -1 if the ship | |
637 * is to the left of the torp on its current heading and a 1 if the ship is | |
638 * to the right. If no target is found then a 0 is return indicating the | |
639 * torp should go straight. | |
640 */ | |
641 | |
642 int | |
643 torp_track_opportunity(torp, turnspeed, smart) | |
644 struct basetorp *torp; /* the torp to check for */ | |
645 int turnspeed; | |
646 int smart; /* which tracking algorithm? */ | |
647 { | |
648 int i; /* looping var */ | |
649 int closest; /* to hold closest player */ | |
650 int clbearing; /* bearing to closest player */ | |
651 int min_distsq; /* to hold closest distance */ | |
652 int war_mask; /* who torp own is at war with */ | |
653 int x, y; /* to hold torps x, y coords */ | |
654 int bearing; /* to get bearing to hit player */ | |
655 int dir; /* to hold torps direction */ | |
656 int range; | |
657 | |
658 closest = -1; /* initialize closest player--no plyr */ | |
659 x = torp->bt_x; /* get the coords of torp */ | |
660 y = torp->bt_y; | |
661 dir = torp->bt_dir; /* get torp's directions */ | |
662 war_mask = torp->bt_war; /* and who he as war with */ | |
663 | |
664 range = torp->bt_fuse * torp->bt_speed * WARP1; | |
665 | |
666 min_distsq = range * range * 4; /* intialize closest player distance */ | |
667 | |
668 for (i = 0; i < MAXPLAYER; i++) | |
669 { /* check all other players */ | |
670 int dx, dy; | |
671 if (!(isAlive(&players[i]) && | |
672 hostile_to(war_mask, torp->bt_team, &players[i]))) | |
673 continue; /* only do if player alive and at war */ | |
674 | |
675 dx = players[i].p_x - x; | |
676 dy = players[i].p_y - y; | |
677 | |
678 if (ABS(dx) > range || ABS(dy) > range) | |
679 continue; /* clearly out of range */ | |
680 | |
681 if (smart) | |
682 { | |
683 bearing = anticipate_impact(torp->bt_speed, dx, dy, | |
684 players[i].p_speed, players[i].p_dir); | |
685 if (bearing < 0) | |
686 bearing = get_bearing(dx, dy, dir); | |
687 else | |
688 bearing = (unsigned char) (bearing - dir); | |
689 } | |
690 else | |
691 { | |
692 bearing = get_bearing(dx, dy, dir); | |
693 } | |
694 /* torps will only track to targets they have a reasonable chance */ | |
695 /* of hitting */ | |
696 if ((turnspeed * torp->bt_fuse > 127) || | |
697 (bearing < ((unsigned char) turnspeed * torp->bt_fuse)) || | |
698 (bearing > ((unsigned char) (256 - turnspeed * torp->bt_fuse)))) | |
699 { | |
700 int distsq; | |
701 distsq = dx * dx + dy * dy; | |
702 if (distsq < min_distsq) | |
703 { /* record it if it is */ | |
704 min_distsq = distsq; /* less than current closest */ | |
705 closest = i; /* player */ | |
706 clbearing = bearing; | |
707 } | |
708 } | |
709 } | |
710 if (closest >= 0) | |
711 { /* if a target found then */ | |
712 if (clbearing > 128) | |
713 return (-1); /* Target is on the left */ | |
714 else | |
715 return (1); /* Target is on the right */ | |
716 } | |
717 return (0); /* No target ... go straight. */ | |
718 } | |
719 | |
720 | |
721 | |
722 | |
723 /*------------------------------UDPLASMATORPS-----------------------------*/ | |
724 /* | |
725 * This function updates the plasma torps. It goes through all the plasma | |
726 * torps and if they are alive it adjusts their heading to track players. It | |
727 * then moves the plasma torp and checks to see if the plasma should explode. | |
728 * It will ensure that a plasma torp explodes when it hits the edge of the | |
729 * galaxy. | |
730 */ | |
731 | |
732 void | |
733 udplasmatorps() | |
734 { | |
735 register int i; /* looping var--loop through plasmas */ | |
736 int turn; /* to get whether to go left or right */ | |
737 int heading; /* to hold plasma heading */ | |
738 struct plasmatorp *j; /* to point to a plasma */ | |
739 | |
740 for (i = 0, j = &plasmatorps[i]; i < MAXPLAYER * MAXPLASMA; i++, j++) | |
741 { | |
742 switch (j->pt_status) | |
743 { /* check torp's status */ | |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
744 case PTFREE: /* if plasma not being fired */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
745 continue; /* go to next plasma */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
746 case PTMOVE: /* if plasma moving */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
747 turn = torp_track_opportunity |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
748 (&j->pt_base, j->pt_turns, |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
749 configvals->improved_tracking[SS_PLASMA]); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
750 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
751 if ((terrain_grid[(int) (j->pt_x) / TGRID_GRANULARITY * TGRID_SIZE + |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
752 (int) (j->pt_y) / TGRID_GRANULARITY].types |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
753 & T_NEBULA) && neb_effect[SS_PLASMA]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
754 if(PLASMA_NEB_EFF > (lrand48() % 100)) /* Is plasma affected? */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
755 turn = (lrand48() % 2); /* Yes */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
756 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
757 /* should we go right or left */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
758 if (turn < 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
759 { /* if left then */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
760 heading = ((int) j->pt_dir) - j->pt_turns; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
761 j->pt_dir = ((heading < 0) ? ((unsigned char) (256 + heading)) : |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
762 ((unsigned char) heading)); /* no rollunder */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
763 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
764 else if (turn > 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
765 { /* else if right */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
766 heading = ((int) j->pt_dir) + j->pt_turns; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
767 j->pt_dir = ((heading > 255) ? ((unsigned char) (heading - 256)) : |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
768 ((unsigned char) heading)); /* no rollover */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
769 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
770 j->pt_x += (double) j->pt_speed * Cos[j->pt_dir] * WARP1; |
9 | 771 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
772 j->pt_y += (double) j->pt_speed * Sin[j->pt_dir] * WARP1; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
773 if (j->pt_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
774 { /* dec the torp fuse. if torp done */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
775 j->pt_status = PTFREE; /* free it up */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
776 players[j->pt_owner].p_nplasmatorp--; /* dec p-torps fired */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
777 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
778 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
779 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
780 if ((terrain_grid[(int) (j->pt_x) / TGRID_GRANULARITY * TGRID_SIZE + |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
781 (int) (j->pt_y) / TGRID_GRANULARITY].types |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
782 & T_ASTEROIDS) && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
783 ast_effect[SS_PLASMA]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
784 if (PLASMA_HIT_AST > (lrand48() % 100)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
785 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
786 pexplode(j); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
787 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
788 } |
9 | 789 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
790 if ((sun_effect[SS_PLASMA] && weap_near_object(&j->pt_base, PLSTAR, ORBDIST)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
791 || |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
792 (sun_effect[SS_PLASMA] && weap_near_object(&j->pt_base, PLWHOLE, ORBDIST)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
793 /* did it hit a star? */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
794 || pnear(j) /* or a player */ ) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
795 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
796 pexplode(j); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
797 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
798 break; /* on to next torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
799 case PTDET: /* if torp was detted */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
800 pexplode(j); /* make it explode */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
801 break; /* on to next torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
802 case PTEXPLODE: /* if torp is exploding */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
803 if (j->pt_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
804 { /* dec the timer until torp dead */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
805 j->pt_status = PTFREE; /* set the torp free is timer zero */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
806 players[j->pt_owner].p_nplasmatorp--; /* dec ptorps fired by player */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
807 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
808 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
809 default: /* Shouldn't happen */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
810 j->pt_status = PTFREE; /* free torp if it got screwed */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
811 break; /* on to next torp */ |
9 | 812 } |
813 } | |
814 } | |
815 | |
816 | |
817 | |
818 /*--------------------------------GET_BEARING------------------------------*/ | |
819 /* | |
820 * This function takes two set of coordinates and a direction. One set of | |
821 * coordinates is the current coords of a trop. The other set is some other | |
822 * coords you want to get a change in direction for. The direction is the | |
823 * current direction of the torp. The function returns the angle that the | |
824 * dir need to be changed by to travel to the new points. | |
825 */ | |
826 | |
827 unsigned char | |
828 get_bearing(dx, dy, dir) | |
829 int dx, dy; /* delta x, y coords */ | |
830 int dir; /* current direction travelling */ | |
831 { | |
832 int phi; /* to hold angle */ | |
833 | |
834 phi = (int) (atan2((double) dx, (double) -dy) / 3.14159 * 128.0); | |
835 if (phi < 0) /* make phi positive */ | |
836 phi = 256 + phi; | |
837 if (phi >= dir) | |
838 return ((unsigned char) (phi - dir)); | |
839 else | |
840 return ((unsigned char) (256 + phi - dir)); | |
841 } | |
842 | |
843 /*------------------------------------------------------------------------*/ | |
844 | |
845 | |
846 | |
847 | |
848 /*------------------------------------------------------------------------*/ | |
849 /*--------------------------FIGHTER_TRACK_TARGET--------------------------*/ | |
850 /* | |
851 * This function finds the closest ship to a fighter and returns -1 if the | |
852 * ship is to the left of the fighter on its current heading and a 1 if the | |
853 * ship is to the right. If no target is found then a 0 is return indicating | |
854 * the fighter should go straight. Also returns fighters to the CV. If the | |
855 * player is locked onto an enemy ship, that's the only ship that gets | |
856 * checked. | |
857 */ | |
858 | |
859 int | |
860 fighter_track_target(mis, turnspeed) | |
861 struct missile *mis; /* the torp to check for */ | |
862 int turnspeed; | |
863 { | |
864 int i; /* looping var */ | |
865 int closest; /* to hold closest player */ | |
866 int min_dist; /* to hold closest distance */ | |
867 int dist; /* temp var to hold distance */ | |
868 int war_mask; /* who fighter own is at war with */ | |
869 int x, y; /* to hold fighters x, y coords */ | |
870 int owner; /* to hold fighters owner */ | |
871 int bearing; /* to get bearing to hit player */ | |
872 int dir; /* to hold fighters direction */ | |
873 int range; | |
874 int dx, dy; | |
875 | |
876 min_dist = GWIDTH * 2; /* intialize closest player distance */ | |
877 closest = -1; /* initialize closest player--no plyr */ | |
878 x = mis->ms_x; /* get the coords of torp */ | |
879 y = mis->ms_y; | |
880 dir = mis->ms_dir; /* get fighter's directions */ | |
881 owner = mis->ms_owner; /* get the fighter's owner */ | |
882 war_mask = mis->ms_war; /* and who he as war with */ | |
883 | |
884 range = mis->ms_fuse * mis->ms_speed * WARP1; | |
885 | |
886 for (i = 0; i < MAXPLAYER; i++) | |
887 { /* check all other players */ | |
888 if (mis->ms_status == TRETURN) | |
889 { | |
890 if (!(isAlive(&players[i])) || (owner != i)) | |
891 continue; | |
892 } /* if returning, only check owning player */ | |
893 else if ((players[owner].p_flags & PFPLOCK) && | |
894 (players[owner].p_playerl != i)) | |
895 continue; /* if player is locked onto a player, only | |
896 * check that player */ | |
897 else if (!(isAlive(&players[i]) && | |
898 hostile_to(war_mask, mis->ms_team, &players[i]))) | |
899 continue; /* only do if player alive and at war */ | |
900 | |
901 dx = players[i].p_x - x; | |
902 dy = players[i].p_y - y; | |
903 | |
904 if (ABS(dx) > range || ABS(dy) > range) | |
905 continue; /* clearly out of range */ | |
906 | |
907 bearing = get_bearing(dx, dy, dir); | |
908 if ((turnspeed * mis->ms_fuse > 127) || | |
909 (bearing < ((unsigned char) turnspeed * mis->ms_fuse)) || | |
910 (bearing > ((unsigned char) (256 - turnspeed * mis->ms_fuse)))) | |
911 { | |
912 dist = ihypot(dx, dy); | |
913 if (dist < min_dist) | |
914 { /* record it if it is */ | |
915 min_dist = dist; /* less than current closest */ | |
916 closest = i; /* player */ | |
917 } | |
918 } | |
919 } | |
920 if (closest >= 0) | |
921 { /* if a target found then */ | |
922 if (get_bearing(players[closest].p_x - x, | |
923 players[closest].p_y - y, dir) > 128) | |
924 { | |
925 return (-1); /* Target is on the left */ | |
926 } | |
927 else | |
928 return (1); /* Target is on the right */ | |
929 } | |
930 return (0); /* No target ... go straight. */ | |
931 } | |
932 | |
933 | |
934 /*--------------------------------------------------------------------------*/ | |
935 /*------------------------------------F_TORP--------------------------------*/ | |
936 /* Checks to see if a valid target is within a certain forward firing angle */ | |
937 /* then fires a torpedo at that target. A return value of 1 indicates firing */ | |
938 | |
939 int | |
940 f_torp(mis) | |
941 struct missile *mis; | |
942 { | |
943 register int i; | |
944 int torp2fire = -1, targetdist = FSTRIKEDIST + 1, tdist, target; | |
945 unsigned char bearing; | |
946 register struct torp *k; | |
947 int dx, dy; | |
948 register struct player *j; /* to point to players */ | |
949 | |
950 for (i = mis->ms_owner * MAXTORP, k = &torps[i]; /* Find a free torp */ | |
951 i < mis->ms_owner * MAXTORP + MAXTORP; i++, k++) | |
952 if (k->t_status == TFREE) | |
953 { | |
954 torp2fire = i; | |
955 break; | |
956 } | |
957 if (torp2fire == -1) | |
958 return 0; | |
959 | |
960 | |
961 for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) | |
962 { | |
963 if (j->p_status != PALIVE) | |
964 continue; /* don't check players not alive */ | |
965 if (j->p_no == mis->ms_owner) | |
966 continue; /* no firing on self */ | |
967 if (!hostile_to(mis->ms_war, mis->ms_team, j)) | |
968 continue; /* disregard if both teams not at war */ | |
969 if ((players[mis->ms_owner].p_flags & PFPLOCK) && | |
970 (players[mis->ms_owner].p_playerl != i)) | |
971 continue; /* ignore if this isn't the target */ | |
972 | |
973 dx = mis->ms_x - j->p_x; /* calc delta coords */ | |
974 dy = mis->ms_y - j->p_y; | |
975 if (ABS(dx) > FSTRIKEDIST || ABS(dy) > FSTRIKEDIST) | |
976 continue; /* disregard if obviously too far */ | |
977 | |
978 tdist = ihypot(dx, dy); | |
979 if (tdist < FSTRIKEDIST) | |
980 { | |
981 bearing = (int) get_bearing(dx, dy, mis->ms_dir); | |
982 targetdist = tdist; /* record the target ship */ | |
983 target = i; | |
984 } | |
985 } | |
986 | |
987 if (targetdist < FSTRIKEDIST) | |
988 { | |
989 j = &players[mis->ms_owner]; | |
990 k = &torps[torp2fire]; | |
991 k->t_no = torp2fire; | |
992 k->t_status = TMOVE; | |
993 k->t_owner = mis->ms_owner; | |
994 k->t_team = mis->ms_team; | |
995 | |
996 move_torp(torp2fire, mis->ms_x, mis->ms_y, 0); | |
997 | |
998 k->t_damage = FTORP_DAMAGE; | |
999 k->t_speed = FTORP_SPEED; | |
1000 k->t_war = j->p_hostile | | |
1001 j->p_swar; | |
1002 k->t_fuse = FTORP_FUSE + (lrand48() % 20); | |
1003 k->t_turns = FTORP_TRACK; | |
1004 | |
1005 /* | |
1006 * here's the biggie -- what angle do I fire this torp at, so I have a | |
1007 * reasonable chance of hitting? Especially since I only get one shot. | |
1008 * But, then, I have a bunch of buddies, too... | |
1009 */ | |
1010 | |
1011 if ((mis->ms_no % MAXPLAYER % 3) == 0) | |
1012 k->t_dir = mis->ms_dir; | |
1013 else if ((mis->ms_no % MAXPLAYER % 3) == 1) | |
1014 k->t_dir = mis->ms_dir - 8; | |
1015 else if ((mis->ms_no % MAXPLAYER % 3) == 2) | |
1016 k->t_dir = mis->ms_dir + 8; | |
1017 return 1; | |
1018 } | |
1019 return 0; | |
1020 } | |
1021 | |
1022 | |
1023 /*----------END OF FILE--------*/ |