annotate src/weapons.c @ 11:9fda93e18de5

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