Mercurial > ~darius > hgwebdir.cgi > paradise_server
annotate src/dutil.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 | 65de6eb6861a |
children |
rev | line source |
---|---|
3 | 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 #include "config.h" | |
20 #include <stdio.h> | |
21 #include <math.h> | |
22 #include <signal.h> | |
23 #include <string.h> | |
24 | |
25 #include "defs.h" | |
26 #include "struct.h" | |
27 #include "data.h" | |
28 #include "daemonII.h" | |
29 #include "shmem.h" | |
30 | |
31 #define friendly(fred, bart) \ | |
32 (!(fred->p_team & (bart->p_swar|bart->p_hostile)) && \ | |
33 !(bart->p_team & (fred->p_swar|fred->p_hostile))) | |
34 | |
35 /*--------------------------------KILLMESS--------------------------------*/ | |
36 | |
37 /* | |
38 * This function prints to the messages who killed who. This function now | |
39 * adds the way of death onto the end of the kill message. | |
40 */ | |
41 | |
42 | |
43 extern void pmessage(); | |
44 int get_explode_views(); | |
45 #ifndef SYSV /* this is barfing on HP/UX */ | |
46 extern int fprintf(); | |
47 #endif | |
48 extern void killerstats(); | |
49 extern void checkmaxkills(); | |
50 #ifdef LEAGUE_SUPPORT | |
51 extern void tlog_plkill(); | |
52 #else | |
53 #define tlog_plkill(a,b,c) | |
54 #endif | |
55 extern void loserstats(); | |
56 | |
57 void | |
58 killmess(victim, killer) | |
59 struct player *victim, *killer; /* killee and killer */ | |
60 { | |
61 char buf[80]; /* to sprintf into */ | |
62 | |
63 sprintf(buf, "%s (%s", victim->p_name, twoletters(victim)); | |
64 | |
65 if (victim->p_armies) | |
66 { | |
67 if ((victim->p_ship.s_nflags & SFNHASFIGHTERS) && (victim->p_ship.s_type != STARBASE)) | |
68 sprintf(buf + strlen(buf), "+%d fighters", | |
69 victim->p_ship.s_missilestored); | |
70 else | |
71 sprintf(buf + strlen(buf), "+%d armies", victim->p_armies); | |
72 } | |
73 strcat(buf, ")"); | |
74 if (killer) | |
75 { | |
76 sprintf(buf + strlen(buf), " was kill %0.2f for %s (%s)", | |
77 killer->p_kills, killer->p_name, | |
78 twoletters(killer)); | |
79 | |
80 if (friendly(victim, killer)) | |
81 strcat(buf, "[no credit]"); | |
82 | |
83 } | |
84 else | |
85 { | |
86 if (victim->p_whydead == KPLANET) | |
87 { | |
88 sprintf(buf + strlen(buf), " was %s by %s (%s)", | |
89 PL_TYPE(planets[victim->p_whodead]) == PLSTAR ? | |
90 "burned to a crisp" : "shot down", | |
91 planets[victim->p_whodead].pl_name, | |
92 teams[planets[victim->p_whodead].pl_owner].shortname); | |
93 } | |
94 else if (victim->p_whydead == KASTEROID) | |
95 sprintf(buf + strlen(buf), " was crushed by an asteroid"); | |
96 else | |
97 { | |
98 strcat(buf, " was killed"); | |
99 } | |
100 } | |
101 switch (victim->p_whydead) | |
102 { /* determine why player died */ | |
103 case KTORP: | |
104 strcat(buf, "[torp]"); | |
105 break; | |
106 case KPHASER: | |
107 strcat(buf, "[phaser]"); | |
108 break; | |
109 case KSHIP: | |
110 strcat(buf, "[explosion]"); | |
111 break; | |
112 case KPLASMA: | |
113 strcat(buf, "[plasma]"); | |
114 break; | |
115 case KASTEROID: | |
116 strcat(buf, "[asteroid]"); | |
117 break; | |
118 case KPLANET: | |
119 switch (PL_TYPE(planets[victim->p_whodead])) | |
120 { | |
121 case PLSTAR: | |
122 strcat(buf, "[star]"); | |
123 break; | |
124 case PLPLANET: | |
125 strcat(buf, "[planet]"); | |
126 break; | |
127 default: | |
128 strcat(buf, "[space rock]"); | |
129 break; | |
130 } | |
131 break; | |
132 default: | |
133 strcat(buf, "[unknown]"); | |
134 } | |
135 pmessage(buf, 0, MALL | MKILLA, "GOD->ALL"); | |
136 } | |
137 | |
138 | |
139 | |
140 | |
141 /*-------------------------------VISIBLE FUNCTIONS------------------------*/ | |
142 | |
143 /*-------------------------------CAUSE_KABOOM------------------------------*/ | |
144 /* | |
145 * This function sets the victim to explode and sets the counter for the | |
146 * explosion views. | |
147 */ | |
148 | |
149 void | |
150 cause_kaboom(victim) | |
151 struct player *victim; /* which ship to blast to tiny fragments */ | |
152 { | |
153 victim->p_status = PEXPLODE; /* set player as exploding */ | |
154 victim->p_explode = (short) get_explode_views(victim->p_ship.s_type); | |
155 } | |
156 | |
157 /*------------------------------GET_EXPLODE_VIEWS--------------------------*/ | |
158 /* returns the number of ship views for the given ship type */ | |
159 | |
160 int | |
161 get_explode_views(stype) | |
162 short stype; | |
163 { | |
164 switch (stype) | |
165 { | |
166 case STARBASE: | |
167 case WARBASE: | |
168 case JUMPSHIP: | |
169 return 2 * SBEXPVIEWS / PLAYERFUSE; /* big kablooey */ | |
170 } | |
171 return 10 / PLAYERFUSE; /* small kablooey */ | |
172 } | |
173 | |
174 /*------------------------------INFLICT_DAMAGE-----------------------------*/ | |
175 /* | |
176 * This function is used to inflict damage on a player. If the player dies | |
177 * as a result he will be made to explode. The function returns a 1 if the | |
178 * victim was killed and a 0 otherwise. If the sp parameter is a zero then | |
179 * the victim was damaged by something other than a ship. It is the | |
180 * responsibil- ity of the caller to set the whydead field of the victim. | |
181 */ | |
182 | |
183 int | |
184 inflict_damage(sp, op, victim, damage, why) | |
185 struct player *sp; /* player that inflicted the damage */ | |
186 struct player *op; /* other player that could be responsible */ | |
187 struct player *victim; /* which ship to victimize */ | |
188 int damage; /* how much damage, should be positive */ | |
189 int why; /* the source of the damage */ | |
190 { | |
191 if (damage < 0) | |
192 { /* should not be called with - damage */ | |
193 fprintf(stderr, "Attempt to inflict negative damage\n"); | |
194 return 0; | |
195 } | |
196 | |
197 if (victim->p_flags & PFSHIELD) | |
198 { /* shields up? */ | |
17 | 199 int penetrated; |
200 float factor; | |
3 | 201 /* |
202 * if the server is configured for damage penetration then the shields | |
203 * will not absorb all the damage | |
204 */ | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
205 |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
206 /* Holds the initial penetration factor */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
207 factor = configvals->penetration; |
17 | 208 |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
209 /* Are we in nebulous terrain? */ |
17 | 210 if ((terrain_grid[(int) (victim->p_x) / TGRID_GRANULARITY * TGRID_SIZE + |
211 (int) (victim->p_y) / TGRID_GRANULARITY].types | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
212 & T_NEBULA) && neb_effect[SS_SHIELD]) |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
213 factor += drand48(); /* Yes - add something to the penetration factor */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
214 |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
215 if(factor > 1) /* Check for overflow */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
216 factor = 1; |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
217 |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
218 penetrated = damage * factor |
3 | 219 * (victim->p_ship.s_maxshield - victim->p_shield) |
220 / (victim->p_ship.s_maxshield); | |
221 damage -= penetrated; | |
222 | |
223 victim->p_shield -= damage; /* damage shields */ | |
224 if (victim->p_shield < 0) | |
225 { /* we punched through the shield */ | |
226 damage = -victim->p_shield; /* excess damage will apply to hull */ | |
227 victim->p_shield = 0; /* and zero the shields */ | |
228 } | |
229 else | |
230 damage = 0; | |
231 damage += penetrated; /* some of the damage got through the shields */ | |
232 } | |
233 if (damage > 0) | |
234 { | |
235 victim->p_damage += damage; /* all damage to hull */ | |
236 if (configvals->erosion > 0) | |
237 { | |
238 float chance = damage * configvals->erosion; | |
239 while (chance >= 0.5) | |
240 { /* no matter how much you suffer there's a | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
241 * chance you can avoid permanent damage */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
242 if (lrand48() & 0x40) |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
243 { |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
244 victim->p_ship.s_maxdamage--; /* apply damage to maximum */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
245 victim->p_damage--; /* instead of current */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
246 } |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
247 chance -= 0.5; |
3 | 248 } |
249 if (drand48() < chance) | |
250 { | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
251 victim->p_ship.s_maxdamage--; /* apply damage to maximum */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
252 victim->p_damage--; /* instead of current */ |
3 | 253 } |
254 } | |
255 } | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
256 |
3 | 257 if (victim->p_damage >= victim->p_ship.s_maxdamage) |
258 { /* victim dead? */ | |
259 cause_kaboom(victim); /* make him explode */ | |
260 if (sp) | |
261 { | |
262 victim->p_whydead = why; | |
263 if (!friendly(sp, victim) | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
264 && sp != victim /* hozers were getting credit for killing |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
265 * themselves because they were at war with |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
266 their own race */ ) |
3 | 267 { |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
268 /* if a hostile player was responsible */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
269 tlog_plkill(victim, sp, op); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
270 if (victim->p_ship.s_type == PATROL) |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
271 sp->p_kills += .5 + ((float) victim->p_armies + victim->p_kills) / 10.0; |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
272 else |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
273 sp->p_kills += 1.0 + ((float) victim->p_armies + victim->p_kills) / 10.0; |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
274 killerstats(sp->p_no, victim); /* adjust everyones stats */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
275 checkmaxkills(sp->p_no); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
276 killmess(victim, sp); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
277 victim->p_whodead = sp->p_no; |
3 | 278 } |
279 else if (op && !friendly(op, victim) && op != victim) | |
280 { | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
281 /* the primary assassin was friendly, check auxiliary killer */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
282 tlog_plkill(victim, op, sp); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
283 |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
284 if (victim->p_ship.s_type == PATROL) |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
285 op->p_kills += .5 + ((float) victim->p_armies + victim->p_kills) / 10.0; |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
286 else |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
287 op->p_kills += 1.0 + ((float) victim->p_armies + victim->p_kills) / 10.0; |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
288 killerstats(op->p_no, victim); /* adjust everyones stats */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
289 checkmaxkills(op->p_no); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
290 killmess(victim, op); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
291 victim->p_whodead = op->p_no; |
3 | 292 } |
293 else | |
294 { | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
295 /* |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
296 * give no credit since it was friendly and the auxiliary murderer |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
297 * was friendly too |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
298 */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
299 tlog_plkill(victim, sp, (struct player *) 0); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
300 killmess(victim, sp); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
301 victim->p_whodead = sp->p_no; |
3 | 302 } |
303 } | |
304 loserstats(victim->p_no); | |
305 return 1; /* victim died */ | |
306 } | |
307 else | |
308 return 0; /* victim lived */ | |
309 } | |
310 | |
311 /*-------------------------------------------------------------------------*/ | |
312 | |
313 | |
314 struct ranksorter | |
315 { | |
316 int pno; | |
317 int rank; | |
318 float di; | |
319 int teammates; | |
320 }; | |
321 | |
322 static struct ranksorter admirals[MAXTEAM]; | |
323 | |
324 int | |
325 enemy_admiral(tno) | |
326 int tno; | |
327 { | |
328 int teammates; | |
329 int pno; | |
330 int i; | |
331 | |
332 for (i = 0; i < MAXTEAM; i++) | |
333 { | |
334 admirals[i].teammates = 0; | |
335 admirals[i].rank = -1; | |
336 } | |
337 | |
338 for (i = 0; i < MAXPLAYER; i++) | |
339 { | |
340 int team; | |
341 struct player *pl; | |
342 pl = &players[i]; | |
343 | |
344 if (pl->p_status == PFREE || | |
345 pl->p_team == tno) | |
346 continue; | |
347 | |
348 team = pl->p_team; | |
349 admirals[team].teammates++; | |
350 | |
351 if (pl->p_stats.st_rank < admirals[team].rank) | |
352 continue; | |
353 if (pl->p_stats.st_rank > admirals[team].rank || | |
354 pl->p_stats.st_di > admirals[team].di) | |
355 { | |
356 admirals[team].pno = i; | |
357 admirals[team].rank = pl->p_stats.st_rank; | |
358 admirals[team].di = pl->p_stats.st_di; | |
359 } | |
360 } | |
361 | |
362 teammates = -1; | |
363 pno = 0; | |
364 for (i = 0; i < MAXTEAM; i++) | |
365 { | |
366 if (admirals[i].teammates > teammates) | |
367 { | |
368 pno = admirals[i].pno; | |
369 teammates = admirals[i].teammates; | |
370 } | |
371 } | |
372 return pno; | |
373 } | |
374 | |
375 | |
376 /*--------END OF FILE-------*/ |