annotate src/detonate.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 2719a89505ba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1 /*--------------------------------------------------------------------------
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
2 NETREK II -- Paradise
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
3
2719a89505ba 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
2719a89505ba 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
2719a89505ba 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
2719a89505ba 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
2719a89505ba 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
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
9 "as is" without express or implied warranty.
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
10
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
11 Xtrek Copyright 1986 Chris Guthrie
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
13 Scott Silvey
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
15 Kurt Olsen
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
16 Brandon Gillespie
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
17 --------------------------------------------------------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
18
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
19
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
20 #include "config.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
21 #include <stdio.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
22 #include <sys/time.h>
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
23 #include "defs.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
24 #include "struct.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
25 #include "data.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
26 #include "shmem.h"
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
27
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
28 /*
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
29 * * Here we have another flaw. Detonating other players torps can be a *
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
30 * very quick way to die. Why? Because you always take some damage. *
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
31 * Experienced players never detonate other players' torps. Balance is *
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
32 * really hard to obtain with this type of function. Technically, a * player
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
33 * could nearly continuously detonate torps (at least faster than * they
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
34 * could be fired) and never be hurt, if I allowed less damage as * a
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
35 * possible result. So here it sits.
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
36 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
37
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
38
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
39
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
40 static struct timeval lasttp;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
41
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
42
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
43 #define UGAP 100000 /* microseconds */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
44
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
45
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
46 /*-----------------------------VISIBLE FUNCTIONS---------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
47
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
48 /*-------------------------------DETOTHERS---------------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
49 /*
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
50 * This function goes through all the torps in the games and detonates the
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
51 * torps that are close enough to det.
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
52 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
53
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
54 void
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
55 detothers()
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
56 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
57 register int h, i; /* looping var */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
58 int dx, dy; /* to find distance */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
59 register struct torp *j; /* to point to torp */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
60 register struct missile *drn; /* to point to torp */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
61
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
62 if (me->p_fuel < myship->s_detcost)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
63 { /* if not enough fuel */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
64 warning("Not enough fuel to detonate"); /* then print warning */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
65 return; /* and get out of dodge */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
66 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
67 if (me->p_flags & PFWEP)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
68 { /* if W-temped then you */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
69 warning("Weapons overheated"); /* cannot det */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
70 return;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
71 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
72
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
73 if (!temporally_spaced(&lasttp, UGAP))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
74 return;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
75
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
76
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
77 me->p_fuel -= myship->s_detcost; /* take fuel away */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
78 me->p_wtemp += myship->s_detcost / 5; /* increase W-temp */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
79 for (h = 0; h < MAXPLAYER; h++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
80 { /* go through all players */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
81 if ((players[h].p_status == PFREE) || (h == me->p_no))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
82 continue; /* do not det own torps */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
83 for (i = h * MAXTORP; i < MAXTORP * (h + 1); i++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
84 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
85 j = &torps[i]; /* get a torp */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
86 if (friendlyTorp(j)) /* if its friendly then */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
87 continue; /* disregard it */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
88 if ((j->t_status == TMOVE) || (j->t_status == TSTRAIGHT))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
89 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
90 dx = j->t_x - me->p_x; /* if torp moving */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
91 dy = j->t_y - me->p_y; /* get delta cords */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
92 #ifdef SHIPDET
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
93 if (ABS(dx) > myship->s_detdist || ABS(dy) > myship->s_detdist)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
94 continue; /* obviously too far away */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
95 if (dx * dx + dy * dy < myship->s_detdist * myship->s_detdist)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
96 { /* close enough? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
97 #elif LARGEDET
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
98 if (ABS(dx) > NEWDETDIST || ABS(dy) > NEWDETDIST)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
99 continue; /* obviously too far away */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
100 if (dx * dx + dy * dy < NEWDETDIST * NEWDETDIST)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
101 { /* close enough? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
102 #else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
103 /*
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
104 * DETDIST is normally set to 1700 unless SHIPDET is set. If SHIPDET
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
105 * is set
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
106 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
107 /*
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
108 * then DETDIST is set as myship->s_detdist in defs.h which will make
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
109 * the
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
110 */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
111 /* det distances settable by ship type */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
112 if (ABS(dx) > DETDIST || ABS(dy) > DETDIST)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
113 continue; /* obviously too far away */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
114 if (dx * dx + dy * dy < DETDIST * DETDIST)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
115 { /* close enough? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
116 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
117 j->t_whodet = me->p_no; /* set who detted it */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
118 j->t_status = TDET; /* change status to det */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
119 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
120 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
121 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
122 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
123
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
124 for (h = 0; h < MAXPLAYER * NPTHINGIES; h++)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
125 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
126 drn = &missiles[h];
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
127
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
128 if (friendlyMissile(drn))
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
129 continue;
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
130
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
131 if (drn->ms_status == TMOVE || drn->ms_status == TSTRAIGHT)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
132 {
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
133 dx = drn->ms_x - me->p_x; /* if torp moving */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
134 dy = drn->ms_y - me->p_y; /* get delta cords */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
135
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
136 #ifdef SHIPDET
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
137 if (ABS(dx) > myship->s_detdist || ABS(dy) > myship->s_detdist)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
138 continue; /* obviously too far away */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
139 if (dx * dx + dy * dy < myship->s_detdist * myship->s_detdist)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
140 { /* close enough? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
141 #elif LARGEDET
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
142 if (ABS(dx) > NEWDETDIST || ABS(dy) > NEWDETDIST)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
143 if (ABS(dx) > NEWDETDIST || ABS(dy) > NEWDETDIST)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
144 continue; /* obviously too far away */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
145 if (dx * dx + dy * dy < NEWDETDIST * NEWDETDIST)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
146 { /* close enough? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
147 #else
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
148 if (ABS(dx) > DETDIST || ABS(dy) > DETDIST)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
149 continue; /* obviously too far away */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
150 if (dx * dx + dy * dy < DETDIST * DETDIST)
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
151 { /* close enough? */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
152 #endif
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
153 drn->ms_whodet = me->p_no; /* set who detted it */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
154 drn->ms_status = TDET; /* change status to det */
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
155 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
156 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
157 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
158 }
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
159
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
160
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
161 /*-------------------------------------------------------------------------*/
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
162
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
163
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
164
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
165
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
166
2719a89505ba First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
167 /*-------END OF FILE------*/