annotate src/weapons.c @ 20:9f180bf494bd default tip

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