annotate src/phaser.c @ 16:e246e5730173

Removed useless binaries from repository...
author darius
date Wed, 24 Dec 1997 12:36:02 +0000
parents aa38447a4b21
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1 /*--------------------------------------------------------------------------
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
2 NETREK II -- Paradise
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
3
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
4 Permission to use, copy, modify, and distribute this software and its
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
6 purpose and without fee is hereby granted, provided that this copyright
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
7 notice appear in all copies. No representations are made about the
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
8 suitability of this software for any purpose. This software is provided
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
9 "as is" without express or implied warranty.
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
10
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
11 Xtrek Copyright 1986 Chris Guthrie
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
13 Scott Silvey
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
15 Kurt Olsen
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
16 Brandon Gillespie
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
17 --------------------------------------------------------------------------*/
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
18
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
19 #include "config.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
20 #include <stdio.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
21 #include <math.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
22 #include <signal.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
23 #include "defs.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
24 #include "struct.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
25 #include "data.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
26 #include "weapons.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
27 #include "shmem.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
28
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
29 /*-----------------------------VISIBLE FUNCTIONS---------------------------*/
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
30
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
31 /*----------------------------------PHASER---------------------------------*/
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
32 /*
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
33 * This function shoots a phaser for a player. Various conditions are
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
34 * checked to see if the phaser should be allowed to fire. If the player can
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
35 * fire then, a player is found in the direction the phaser was fired.
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
36 */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
37
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
38
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
39 extern int angdist();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
40
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
41 void
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
42 phaser(course)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
43 unsigned char course;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
44 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
45 int i; /* looping var */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
46 struct player *j, *target = 0;/* to hold player found */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
47 struct plasmatorp *k, *target2 = 0; /* to hold plasma torp found */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
48 struct missile *d, *target3 = 0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
49 struct phaser *mine; /* to pnt to player's phaser */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
50 int whichtarget; /* to hold type of target */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
51 int target_x = 0, target_y = 0; /* target's x and y coords */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
52 unsigned char dir; /* to get direction of phasr */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
53 int range, trange; /* range of target */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
54 int maxangle; /* potential target range */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
55 int myphrange; /* angle to hit potentl targ */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
56 char buf[80]; /* to sprintf warnings into */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
57
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
58 mine = &phasers[me->p_no]; /* get phaser struct */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
59 if (!(myship->s_nflags & SFNHASPHASERS))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
60 { /* do we have phasers? */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
61 warning("Weapons Officer: This ship is not armed with phasers, captain!");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
62 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
63 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
64 if (mine->ph_status != PHFREE)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
65 { /* is phaser currently being */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
66 warning("Phasers have not recharged"); /* fired */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
67 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
68 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
69 if (me->p_fuel < myship->s_phaser.cost)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
70 { /* do we have enough fuel */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
71 warning("Not enough fuel for phaser");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
72 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
73 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
74 if (me->p_flags & PFREPAIR)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
75 { /* cannot fire while in */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
76 warning("Can't fire while repairing"); /* repair mode */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
77 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
78 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
79 if (me->p_flags & PFWEP)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
80 { /* cannot fire while weapon */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
81 warning("Weapons overheated"); /* temped */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
82 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
83 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
84 if ((me->p_cloakphase) && (me->p_ship.s_type != ATT))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
85 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
86 warning("Cannot fire while cloaked"); /* cannot fire while cloaked */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
87 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
88 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
89 if (!check_fire_warp()
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
90 || !check_fire_warpprep()
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
91 || !check_fire_docked())
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
92 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
93
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
94 me->p_fuel -= myship->s_phaser.cost; /* subtract off fuel cost */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
95 me->p_wtemp += myship->s_phaser.wtemp; /* add to w temp */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
96 mine->ph_dir = course; /* get direction of phaser */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
97 whichtarget = 0; /* no target fount yet */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
98 range = 1000000; /* Sufficiently big. */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
99 /* check the players */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
100 for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
101 { /* loop all players */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
102 if (((j->p_status != PALIVE)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
103 #ifdef PFBIRD
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
104 && !(j->p_flags & PFBIRD)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
105 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
106 ) || (j == me)) /* only check alive players */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
107 continue;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
108 if ((!((j->p_swar | j->p_hostile) & me->p_team)) &&
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
109 (!((me->p_swar | me->p_hostile) & j->p_team)) &&
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
110 #ifdef PFBIRD
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
111 !(j->p_flags & PFBIRD)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
112 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
113 )
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
114 continue; /* only check at war with */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
115 dir = (unsigned char) (int) (atan2((double) (j->p_x - me->p_x),
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
116 (double) (me->p_y - j->p_y)) / 3.14159 * 128.);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
117 /* get range of target */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
118 trange = ihypot(j->p_x - me->p_x, j->p_y - me->p_y);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
119 if (trange == 0) /* don't want zero in atan */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
120 trange = 1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
121 maxangle = atan((float) EXPDIST / trange) / 3.14159 * 128.0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
122 if (angdist(dir, course) <= maxangle)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
123 { /* if angle within tolerance */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
124 if (range > trange)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
125 { /* then check to see if */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
126 whichtarget = 1; /* this is the closest target */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
127 target = j; /* found yet */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
128 range = trange; /* record if it is */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
129 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
130 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
131 } /* check the plasmas */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
132 for (i = 0, k = &plasmatorps[i]; i < MAXPLASMA * MAXPLAYER; i++, k++)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
133 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
134 if ((k->pt_status != PTMOVE) || (k->pt_owner == me->p_no))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
135 continue; /* only check live plasmas */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
136 if ((!(k->pt_war & me->p_team)) && /* and unfriendly ones */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
137 (!((me->p_swar | me->p_hostile) & k->pt_team)))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
138 continue;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
139 dir = (unsigned char) (int) (atan2((double) (k->pt_x - me->p_x),
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
140 (double) (me->p_y - k->pt_y)) / 3.14159 * 128.); /* find direction */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
141 trange = ihypot(k->pt_x - me->p_x, k->pt_y - me->p_y);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
142 if (trange == 0) /* no zeroes in math funcs */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
143 trange = 1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
144 maxangle = atan((float) EXPDIST / 4 / trange) / 3.14159 * 128.0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
145 if (angdist(dir, course) <= (maxangle + 1))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
146 { /* if we can hit it */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
147 if (range > trange)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
148 { /* then check to see if this */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
149 target_x = k->pt_x; /* is the closest plasma */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
150 target_y = k->pt_y; /* found yet */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
151 whichtarget = 2; /* and record it if it is */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
152 target2 = k;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
153 range = trange;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
154 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
155 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
156 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
157 /* check the fighters */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
158 for (i = 0, d = &missiles[i]; i < NPTHINGIES * MAXPLAYER; i++, d++)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
159 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
160 if ((d->ms_owner == me->p_no) || (d->ms_type != FIGHTERTHINGY))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
161 continue; /* only check live fighters */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
162 if ((!(d->ms_war & me->p_team)) && /* and unfriendly ones */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
163 (!((me->p_swar | me->p_hostile) & d->ms_team)))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
164 continue;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
165 dir = (unsigned char) (atan2((double) (d->ms_x - me->p_x),
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
166 (double) (me->p_y - d->ms_y))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
167 / 3.14159 * 128.); /* find direction */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
168 trange = ihypot(d->ms_x - me->p_x, d->ms_y - me->p_y);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
169 if (trange == 0) /* no zeroes in math funcs */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
170 trange = 1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
171 maxangle = atan((float) EXPDIST / 8 / trange) / 3.14159 * 128.0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
172 if (angdist(dir, course) <= (maxangle + 1))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
173 { /* if we can hit it */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
174 if (range > trange)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
175 { /* then check to see if this */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
176 target_x = d->ms_x; /* is the closest fighter */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
177 target_y = d->ms_y; /* found yet */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
178 whichtarget = 3; /* and record it if it is */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
179 target3 = d;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
180 range = trange;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
181 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
182 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
183 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
184
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
185 mine->ph_fuse = me->p_ship.s_phaser.fuse; /* set phaser fuse */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
186 myphrange = me->p_ship.s_phaser.speed; /* phaser range */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
187 if ((whichtarget == 0) || /* if no target found or all */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
188 (range > myphrange))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
189 { /* targets too long */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
190 mine->ph_status = PHMISS; /* then we missed */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
191 warning("Phaser missed!!!");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
192 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
193 else if (whichtarget == 2)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
194 { /* if we hit a plasma then */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
195 warning("You destroyed the plasma torpedo!");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
196 mine->ph_x = target_x; /* the set point to shoot at */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
197 mine->ph_y = target_y;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
198 mine->ph_status = PHHIT2; /* we hit a plasma */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
199 target2->pt_status = PTEXPLODE; /* Plasmas hurt everyone */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
200 target2->pt_whodet = me->p_no;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
201 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
202 else if (whichtarget == 3)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
203 { /* if we hit a fighter then */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
204 warning("You shot a fighter!");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
205 mine->ph_x = target_x; /* the set point to shoot at */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
206 mine->ph_y = target_y;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
207 mine->ph_status = PHHIT2; /* we hit the fighter */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
208 target3->ms_status = TDET; /* det the fighter */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
209 target3->ms_whodet = me->p_no;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
210 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
211 else
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
212 { /* else if we hit player */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
213 mine->ph_target = target->p_no; /* set the player number */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
214 mine->ph_damage = me->p_ship.s_phaser.damage * /* get damage */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
215 (1.0 - (range / (float) myphrange));
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
216 if (mine->ph_damage < 0) /* if damage inflicted */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
217 mine->ph_damage = -mine->ph_damage; /* set the phaser damage */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
218 mine->ph_status = PHHIT; /* status is a hit */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
219
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
220 #ifdef PFBIRD
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
221 if (target->p_flags & PFBIRD)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
222 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
223 /* change to PHHIT2 so phaser won't follow bird */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
224 mine->ph_status = PHHIT2;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
225 mine->ph_x = target->p_x;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
226 mine->ph_y = target->p_y;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
227 /* xx: slight misuse of fields here */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
228 target->p_damage = mine->ph_damage;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
229 target->p_whodead = me->p_no;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
230
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
231 (void) sprintf(buf, "\"AAWWK!\"");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
232 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
233 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
234
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
235 (void) sprintf(buf, "Phaser burst hit %s for %d points",
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
236 target->p_name, mine->ph_damage);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
237 warning(buf);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
238 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
239 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
240
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
241 /*------------------------------------------------------------------------*/
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
242
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
243
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
244
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
245
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
246
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
247 /*-------END OF FILE-------*/