Mercurial > ~darius > hgwebdir.cgi > paradise_server
annotate src/weapons.c @ 20:9f180bf494bd default tip
Made torps and fighter wobbly.
They have a chance of tracking randomly instead of staying straight or seeking
if in nebulous terrain.
Option is turned on when NEBULA_EFFECT contains PHOTON and/or FIGHTER.
author | darius |
---|---|
date | Wed, 24 Dec 1997 12:42:09 +0000 |
parents | ed82a42ba89d |
children |
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; | |
20 | 70 int radius; |
71 int why; | |
9 | 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 */ | |
20 | 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))) | |
9 | 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)) / | |
20 | 105 (radius - EXPDIST); |
9 | 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 */ | |
20 | 112 players[torp->bt_owner].p_swar |= j->p_team; /* necessary */ |
9 | 113 inflict_damage(&players[torp->bt_owner], &players[torp->bt_whodet], |
20 | 114 j, damage, why); |
9 | 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 */ | |
20 | 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; | |
9 | 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; | |
20 | 194 int type; |
195 int dist; | |
9 | 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 */ | |
20 | 218 int dist; |
9 | 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 */ |
20 | 327 |
13
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)) |
20 | 364 ||(wh_effect[SS_PHOTON] && weap_near_object(&j->t_base, PLWHOLE, ORBDIST))) |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
365 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
366 /* 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
|
367 j->t_whodet = j->t_owner; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
368 explode(&j->t_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
369 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
370 } |
9 | 371 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
372 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
|
373 (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
|
374 & T_ASTEROIDS) && ast_effect[SS_PHOTON]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
375 if (TORP_HIT_AST > (lrand48() % 100)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
376 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
377 explode(&j->t_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
378 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
379 } |
9 | 380 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
381 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
|
382 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
383 /* if torp near enough to hit */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
384 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
|
385 } |
9 | 386 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
387 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
388 case TDET: /* if torp was detted */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
389 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
|
390 break; /* on to next torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
391 case TEXPLODE: /* if torp exploding */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
392 if (j->t_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
393 { /* dec explosion timer */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
394 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
|
395 move_torp(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
396 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
|
397 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
398 break; /* on to next torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
399 case TOFF: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
400 j->t_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
401 move_torp(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
402 players[j->t_owner].p_ntorp--; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
403 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
404 default: /* Shouldn't happen */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
405 j->t_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
406 break; |
9 | 407 } /* end of switch */ |
408 } /* end of for */ | |
409 } | |
410 | |
411 void | |
412 udmissiles() | |
413 { | |
414 int i; | |
415 int x, y, turn; | |
416 struct missile *mis; | |
417 struct player *j; | |
418 | |
419 for (i = 0; i < MAXPLAYER * NPTHINGIES; i++) | |
420 { | |
421 mis = &missiles[i]; | |
422 switch (mis->ms_status) | |
423 { | |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
424 case TFREE: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
425 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
426 case TLAND: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
427 j = &players[mis->ms_owner]; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
428 j->p_ship.s_missilestored++; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
429 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
|
430 mis->ms_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
431 j->p_nthingys--; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
432 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
433 case TRETURN: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
434 case TMOVE: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
435 case TSTRAIGHT: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
436 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
437 if (mis->ms_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
438 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
439 mis->ms_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
440 move_missile(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
441 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
442 } |
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 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
|
445 (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
|
446 & T_ASTEROIDS) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
447 if ((mis->ms_type == FIGHTERTHINGY) && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
448 ast_effect[SS_FIGHTER] && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
449 (FIGHTER_HIT_AST > (lrand48() % 100))) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
450 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
451 mis->ms_whodet = mis->ms_owner; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
452 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
453 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
454 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
455 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
|
456 ast_effect[SS_MISSILE]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
457 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
458 mis->ms_whodet = mis->ms_owner; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
459 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
460 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
461 } |
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 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
|
464 || (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
|
465 && 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
|
466 || |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
467 (((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
|
468 || (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
|
469 && 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
|
470 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
471 /* did it hit a star? */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
472 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
473 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
474 } |
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 j = &players[mis->ms_owner]; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
477 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
478 if (mis->ms_type == FIGHTERTHINGY && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
479 !(j->p_ship.s_nflags & SFNHASFIGHTERS)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
480 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
481 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
|
482 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
|
483 mis->fi_hasfired = 0; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
484 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
485 } |
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 if ((mis->ms_type == FIGHTERTHINGY) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
488 && ((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
|
489 || (mis->fi_hasfired)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
490 && mis->ms_status != TRETURN) |
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 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
493 if (mis->ms_turns > 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
494 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
495 if (mis->ms_type == FIGHTERTHINGY) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
496 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
497 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
|
498 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
499 else |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
500 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
501 turn = torp_track_opportunity |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
502 (&mis->ms_base, mis->ms_turns, |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
503 configvals->improved_tracking[SS_MISSILE]); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
504 } |
9 | 505 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
506 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
|
507 (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
|
508 & T_NEBULA)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
509 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
510 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
|
511 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
512 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
|
513 turn = (lrand48() % 2); /* Yes */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
514 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
515 else |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
516 if(neb_effect[SS_MISSILE]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
517 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
|
518 turn = (lrand48() % 2); /* Yes */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
519 |
9 | 520 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
521 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
|
522 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
523 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
|
524 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
|
525 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
526 move_missile(i, x, y, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
527 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
528 if (mis->ms_status != TSTRAIGHT) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
529 mis->ms_dir += (lrand48() % 3) - 1; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
530 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
531 if (mis->ms_type == MISSILETHINGY |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
532 && near_player(&mis->ms_base, EXPDIST)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
533 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
534 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
535 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
536 else if (mis->ms_type == FIGHTERTHINGY |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
537 && near_player(&mis->ms_base, FSTRIKEDIST) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
538 && !mis->fi_hasfired) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
539 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
540 if (f_torp(mis)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
541 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
|
542 } |
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 if (mis->ms_status == TRETURN && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
545 f_land(mis)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
546 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
547 mis->ms_status = TLAND; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
548 move_missile(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
549 } |
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 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
552 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
553 case TDET: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
554 explode(&mis->ms_base); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
555 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
556 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
557 case TEXPLODE: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
558 if (mis->ms_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
559 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
560 mis->ms_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
561 players[mis->ms_owner].p_nthingys--; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
562 move_missile(i, -1, -1, 1); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
563 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
564 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
565 default: |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
566 mis->ms_status = TFREE; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
567 break; |
9 | 568 } |
569 } | |
570 } | |
571 | |
572 int | |
573 anticipate_impact(w, dx, dy, s, dir) | |
574 int w; /* speed of torp */ | |
575 int dx, dy; /* distance to target */ | |
576 int s, dir; /* speed of target */ | |
577 { | |
578 float sdx, sdy; | |
579 float a, b, c, d; | |
580 float t; | |
581 float tdx, tdy; | |
582 float theta; | |
583 | |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
584 /* mathematically, these affect t, but not |
9 | 585 * the return value */ |
586 s *= WARP1 * TICKSPERSEC; | |
587 w *= WARP1 * TICKSPERSEC; | |
588 | |
589 sdx = s * Cos[dir]; | |
590 sdy = s * Sin[dir]; | |
591 | |
592 a = s * (float) s - w * (float) w; | |
593 b = 2 * (sdx * (float) dx + sdy * (float) dy); | |
594 c = dx * (float) dx + dy * (float) dy; | |
595 | |
596 if (a == 0) | |
597 { | |
598 t = -c / b; | |
599 } | |
600 else | |
601 { | |
602 | |
603 d = b * b - 4 * a * c; | |
604 if (d < 0) | |
605 return -1; | |
606 d = sqrt(d); | |
607 | |
608 if (a < 0) | |
609 { | |
610 a = -a; | |
611 b = -b; | |
612 } | |
613 | |
614 t = (-b - d) / (2 * a); | |
615 | |
616 if (t < 0) | |
617 t = (-b + d) / (2 * a); | |
618 } | |
619 | |
620 if (t < 0) | |
621 return -1; | |
622 | |
623 if (t > 10) | |
624 return -1; | |
625 | |
626 tdx = dx / t + sdx; | |
627 tdy = dy / t + sdy; | |
628 | |
629 theta = atan2(tdx, -tdy); | |
630 return (unsigned char) (int) (theta * 128 / 3.14159); | |
631 } | |
632 | |
633 /*----------------------------TORP_TRACK_OPPORTUNITY----------------------*/ | |
634 /* | |
635 * This function finds the closest ship to a torp and returns -1 if the ship | |
636 * is to the left of the torp on its current heading and a 1 if the ship is | |
637 * to the right. If no target is found then a 0 is return indicating the | |
638 * torp should go straight. | |
639 */ | |
640 | |
641 int | |
642 torp_track_opportunity(torp, turnspeed, smart) | |
643 struct basetorp *torp; /* the torp to check for */ | |
644 int turnspeed; | |
645 int smart; /* which tracking algorithm? */ | |
646 { | |
647 int i; /* looping var */ | |
648 int closest; /* to hold closest player */ | |
649 int clbearing; /* bearing to closest player */ | |
650 int min_distsq; /* to hold closest distance */ | |
651 int war_mask; /* who torp own is at war with */ | |
652 int x, y; /* to hold torps x, y coords */ | |
653 int bearing; /* to get bearing to hit player */ | |
654 int dir; /* to hold torps direction */ | |
655 int range; | |
656 | |
657 closest = -1; /* initialize closest player--no plyr */ | |
658 x = torp->bt_x; /* get the coords of torp */ | |
659 y = torp->bt_y; | |
660 dir = torp->bt_dir; /* get torp's directions */ | |
661 war_mask = torp->bt_war; /* and who he as war with */ | |
662 | |
663 range = torp->bt_fuse * torp->bt_speed * WARP1; | |
664 | |
665 min_distsq = range * range * 4; /* intialize closest player distance */ | |
666 | |
667 for (i = 0; i < MAXPLAYER; i++) | |
668 { /* check all other players */ | |
669 int dx, dy; | |
670 if (!(isAlive(&players[i]) && | |
671 hostile_to(war_mask, torp->bt_team, &players[i]))) | |
672 continue; /* only do if player alive and at war */ | |
673 | |
674 dx = players[i].p_x - x; | |
675 dy = players[i].p_y - y; | |
676 | |
677 if (ABS(dx) > range || ABS(dy) > range) | |
678 continue; /* clearly out of range */ | |
679 | |
680 if (smart) | |
681 { | |
682 bearing = anticipate_impact(torp->bt_speed, dx, dy, | |
683 players[i].p_speed, players[i].p_dir); | |
684 if (bearing < 0) | |
685 bearing = get_bearing(dx, dy, dir); | |
686 else | |
687 bearing = (unsigned char) (bearing - dir); | |
688 } | |
689 else | |
690 { | |
691 bearing = get_bearing(dx, dy, dir); | |
692 } | |
693 /* torps will only track to targets they have a reasonable chance */ | |
694 /* of hitting */ | |
695 if ((turnspeed * torp->bt_fuse > 127) || | |
696 (bearing < ((unsigned char) turnspeed * torp->bt_fuse)) || | |
697 (bearing > ((unsigned char) (256 - turnspeed * torp->bt_fuse)))) | |
698 { | |
699 int distsq; | |
700 distsq = dx * dx + dy * dy; | |
701 if (distsq < min_distsq) | |
702 { /* record it if it is */ | |
703 min_distsq = distsq; /* less than current closest */ | |
704 closest = i; /* player */ | |
705 clbearing = bearing; | |
706 } | |
707 } | |
708 } | |
709 if (closest >= 0) | |
710 { /* if a target found then */ | |
711 if (clbearing > 128) | |
712 return (-1); /* Target is on the left */ | |
713 else | |
714 return (1); /* Target is on the right */ | |
715 } | |
716 return (0); /* No target ... go straight. */ | |
717 } | |
718 | |
719 | |
720 | |
721 | |
722 /*------------------------------UDPLASMATORPS-----------------------------*/ | |
723 /* | |
724 * This function updates the plasma torps. It goes through all the plasma | |
725 * torps and if they are alive it adjusts their heading to track players. It | |
726 * then moves the plasma torp and checks to see if the plasma should explode. | |
727 * It will ensure that a plasma torp explodes when it hits the edge of the | |
728 * galaxy. | |
729 */ | |
730 | |
731 void | |
732 udplasmatorps() | |
733 { | |
734 register int i; /* looping var--loop through plasmas */ | |
735 int turn; /* to get whether to go left or right */ | |
736 int heading; /* to hold plasma heading */ | |
737 struct plasmatorp *j; /* to point to a plasma */ | |
738 | |
739 for (i = 0, j = &plasmatorps[i]; i < MAXPLAYER * MAXPLASMA; i++, j++) | |
740 { | |
741 switch (j->pt_status) | |
742 { /* check torp's status */ | |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
743 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
|
744 continue; /* go to next plasma */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
745 case PTMOVE: /* if plasma moving */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
746 turn = torp_track_opportunity |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
747 (&j->pt_base, j->pt_turns, |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
748 configvals->improved_tracking[SS_PLASMA]); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
749 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
750 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
|
751 (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
|
752 & T_NEBULA) && neb_effect[SS_PLASMA]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
753 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
|
754 turn = (lrand48() % 2); /* Yes */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
755 |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
756 /* should we go right or left */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
757 if (turn < 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
758 { /* if left then */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
759 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
|
760 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
|
761 ((unsigned char) heading)); /* no rollunder */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
762 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
763 else if (turn > 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
764 { /* else if right */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
765 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
|
766 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
|
767 ((unsigned char) heading)); /* no rollover */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
768 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
769 j->pt_x += (double) j->pt_speed * Cos[j->pt_dir] * WARP1; |
9 | 770 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
771 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
|
772 if (j->pt_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
773 { /* 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
|
774 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
|
775 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
|
776 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
777 } |
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 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
|
780 (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
|
781 & T_ASTEROIDS) && |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
782 ast_effect[SS_PLASMA]) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
783 if (PLASMA_HIT_AST > (lrand48() % 100)) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
784 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
785 pexplode(j); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
786 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
787 } |
9 | 788 |
13
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
789 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
|
790 || |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
791 (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
|
792 /* did it hit a star? */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
793 || pnear(j) /* or a player */ ) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
794 { |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
795 pexplode(j); |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
796 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
797 break; /* on to next torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
798 case PTDET: /* if torp was detted */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
799 pexplode(j); /* make it explode */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
800 break; /* on to next torp */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
801 case PTEXPLODE: /* if torp is exploding */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
802 if (j->pt_fuse-- <= 0) |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
803 { /* dec the timer until torp dead */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
804 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
|
805 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
|
806 } |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
807 break; |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
808 default: /* Shouldn't happen */ |
ed82a42ba89d
Added code to cause missiles, fighters and plasmas to get confused in
darius
parents:
9
diff
changeset
|
809 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
|
810 break; /* on to next torp */ |
9 | 811 } |
812 } | |
813 } | |
814 | |
815 | |
816 | |
817 /*--------------------------------GET_BEARING------------------------------*/ | |
818 /* | |
819 * This function takes two set of coordinates and a direction. One set of | |
820 * coordinates is the current coords of a trop. The other set is some other | |
821 * coords you want to get a change in direction for. The direction is the | |
822 * current direction of the torp. The function returns the angle that the | |
823 * dir need to be changed by to travel to the new points. | |
824 */ | |
825 | |
826 unsigned char | |
827 get_bearing(dx, dy, dir) | |
828 int dx, dy; /* delta x, y coords */ | |
829 int dir; /* current direction travelling */ | |
830 { | |
831 int phi; /* to hold angle */ | |
832 | |
833 phi = (int) (atan2((double) dx, (double) -dy) / 3.14159 * 128.0); | |
834 if (phi < 0) /* make phi positive */ | |
835 phi = 256 + phi; | |
836 if (phi >= dir) | |
837 return ((unsigned char) (phi - dir)); | |
838 else | |
839 return ((unsigned char) (256 + phi - dir)); | |
840 } | |
841 | |
842 /*------------------------------------------------------------------------*/ | |
843 | |
844 | |
845 | |
846 | |
847 /*------------------------------------------------------------------------*/ | |
848 /*--------------------------FIGHTER_TRACK_TARGET--------------------------*/ | |
849 /* | |
850 * This function finds the closest ship to a fighter and returns -1 if the | |
851 * ship is to the left of the fighter on its current heading and a 1 if the | |
852 * ship is to the right. If no target is found then a 0 is return indicating | |
853 * the fighter should go straight. Also returns fighters to the CV. If the | |
854 * player is locked onto an enemy ship, that's the only ship that gets | |
855 * checked. | |
856 */ | |
857 | |
858 int | |
859 fighter_track_target(mis, turnspeed) | |
860 struct missile *mis; /* the torp to check for */ | |
861 int turnspeed; | |
862 { | |
863 int i; /* looping var */ | |
864 int closest; /* to hold closest player */ | |
865 int min_dist; /* to hold closest distance */ | |
866 int dist; /* temp var to hold distance */ | |
867 int war_mask; /* who fighter own is at war with */ | |
868 int x, y; /* to hold fighters x, y coords */ | |
869 int owner; /* to hold fighters owner */ | |
870 int bearing; /* to get bearing to hit player */ | |
871 int dir; /* to hold fighters direction */ | |
872 int range; | |
873 int dx, dy; | |
874 | |
875 min_dist = GWIDTH * 2; /* intialize closest player distance */ | |
876 closest = -1; /* initialize closest player--no plyr */ | |
877 x = mis->ms_x; /* get the coords of torp */ | |
878 y = mis->ms_y; | |
879 dir = mis->ms_dir; /* get fighter's directions */ | |
880 owner = mis->ms_owner; /* get the fighter's owner */ | |
881 war_mask = mis->ms_war; /* and who he as war with */ | |
882 | |
883 range = mis->ms_fuse * mis->ms_speed * WARP1; | |
884 | |
885 for (i = 0; i < MAXPLAYER; i++) | |
886 { /* check all other players */ | |
887 if (mis->ms_status == TRETURN) | |
888 { | |
889 if (!(isAlive(&players[i])) || (owner != i)) | |
890 continue; | |
891 } /* if returning, only check owning player */ | |
892 else if ((players[owner].p_flags & PFPLOCK) && | |
893 (players[owner].p_playerl != i)) | |
894 continue; /* if player is locked onto a player, only | |
895 * check that player */ | |
896 else if (!(isAlive(&players[i]) && | |
897 hostile_to(war_mask, mis->ms_team, &players[i]))) | |
898 continue; /* only do if player alive and at war */ | |
899 | |
900 dx = players[i].p_x - x; | |
901 dy = players[i].p_y - y; | |
902 | |
903 if (ABS(dx) > range || ABS(dy) > range) | |
904 continue; /* clearly out of range */ | |
905 | |
906 bearing = get_bearing(dx, dy, dir); | |
907 if ((turnspeed * mis->ms_fuse > 127) || | |
908 (bearing < ((unsigned char) turnspeed * mis->ms_fuse)) || | |
909 (bearing > ((unsigned char) (256 - turnspeed * mis->ms_fuse)))) | |
910 { | |
911 dist = ihypot(dx, dy); | |
912 if (dist < min_dist) | |
913 { /* record it if it is */ | |
914 min_dist = dist; /* less than current closest */ | |
915 closest = i; /* player */ | |
916 } | |
917 } | |
918 } | |
919 if (closest >= 0) | |
920 { /* if a target found then */ | |
921 if (get_bearing(players[closest].p_x - x, | |
922 players[closest].p_y - y, dir) > 128) | |
923 { | |
924 return (-1); /* Target is on the left */ | |
925 } | |
926 else | |
927 return (1); /* Target is on the right */ | |
928 } | |
929 return (0); /* No target ... go straight. */ | |
930 } | |
931 | |
932 | |
933 /*--------------------------------------------------------------------------*/ | |
934 /*------------------------------------F_TORP--------------------------------*/ | |
935 /* Checks to see if a valid target is within a certain forward firing angle */ | |
936 /* then fires a torpedo at that target. A return value of 1 indicates firing */ | |
937 | |
938 int | |
939 f_torp(mis) | |
940 struct missile *mis; | |
941 { | |
942 register int i; | |
943 int torp2fire = -1, targetdist = FSTRIKEDIST + 1, tdist, target; | |
944 unsigned char bearing; | |
945 register struct torp *k; | |
946 int dx, dy; | |
947 register struct player *j; /* to point to players */ | |
948 | |
949 for (i = mis->ms_owner * MAXTORP, k = &torps[i]; /* Find a free torp */ | |
950 i < mis->ms_owner * MAXTORP + MAXTORP; i++, k++) | |
951 if (k->t_status == TFREE) | |
952 { | |
953 torp2fire = i; | |
954 break; | |
955 } | |
956 if (torp2fire == -1) | |
957 return 0; | |
958 | |
959 | |
960 for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) | |
961 { | |
962 if (j->p_status != PALIVE) | |
963 continue; /* don't check players not alive */ | |
964 if (j->p_no == mis->ms_owner) | |
965 continue; /* no firing on self */ | |
966 if (!hostile_to(mis->ms_war, mis->ms_team, j)) | |
967 continue; /* disregard if both teams not at war */ | |
968 if ((players[mis->ms_owner].p_flags & PFPLOCK) && | |
969 (players[mis->ms_owner].p_playerl != i)) | |
970 continue; /* ignore if this isn't the target */ | |
971 | |
972 dx = mis->ms_x - j->p_x; /* calc delta coords */ | |
973 dy = mis->ms_y - j->p_y; | |
974 if (ABS(dx) > FSTRIKEDIST || ABS(dy) > FSTRIKEDIST) | |
975 continue; /* disregard if obviously too far */ | |
976 | |
977 tdist = ihypot(dx, dy); | |
978 if (tdist < FSTRIKEDIST) | |
979 { | |
980 bearing = (int) get_bearing(dx, dy, mis->ms_dir); | |
981 targetdist = tdist; /* record the target ship */ | |
982 target = i; | |
983 } | |
984 } | |
985 | |
986 if (targetdist < FSTRIKEDIST) | |
987 { | |
988 j = &players[mis->ms_owner]; | |
989 k = &torps[torp2fire]; | |
990 k->t_no = torp2fire; | |
991 k->t_status = TMOVE; | |
992 k->t_owner = mis->ms_owner; | |
993 k->t_team = mis->ms_team; | |
994 | |
995 move_torp(torp2fire, mis->ms_x, mis->ms_y, 0); | |
996 | |
997 k->t_damage = FTORP_DAMAGE; | |
998 k->t_speed = FTORP_SPEED; | |
999 k->t_war = j->p_hostile | | |
1000 j->p_swar; | |
1001 k->t_fuse = FTORP_FUSE + (lrand48() % 20); | |
1002 k->t_turns = FTORP_TRACK; | |
1003 | |
1004 /* | |
1005 * here's the biggie -- what angle do I fire this torp at, so I have a | |
1006 * reasonable chance of hitting? Especially since I only get one shot. | |
1007 * But, then, I have a bunch of buddies, too... | |
1008 */ | |
1009 | |
1010 if ((mis->ms_no % MAXPLAYER % 3) == 0) | |
1011 k->t_dir = mis->ms_dir; | |
1012 else if ((mis->ms_no % MAXPLAYER % 3) == 1) | |
1013 k->t_dir = mis->ms_dir - 8; | |
1014 else if ((mis->ms_no % MAXPLAYER % 3) == 2) | |
1015 k->t_dir = mis->ms_dir + 8; | |
1016 return 1; | |
1017 } | |
1018 return 0; | |
1019 } | |
1020 | |
1021 | |
1022 /*----------END OF FILE--------*/ |