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