annotate src/weapons.c @ 14:b7fe2e0e4b86

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