Mercurial > ~darius > hgwebdir.cgi > paradise_server
annotate src/dutil.c @ 16:e246e5730173
Removed useless binaries from repository...
author | darius |
---|---|
date | Wed, 24 Dec 1997 12:36:02 +0000 |
parents | d28f3d01043c |
children | 65de6eb6861a |
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? */ | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
199 int penetrated, factor; |
3 | 200 /* |
201 * if the server is configured for damage penetration then the shields | |
202 * will not absorb all the damage | |
203 */ | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
204 |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
205 /* Holds the initial penetration factor */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
206 factor = configvals->penetration; |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
207 |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
208 /* Are we in nebulous terrain? */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
209 if ((terrain_grid[(int) (j->t_x) / TGRID_GRANULARITY * TGRID_SIZE + |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
210 (int) (j->t_y) / TGRID_GRANULARITY].types |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
211 & T_NEBULA) && neb_effect[SS_SHIELD]) |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
212 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
|
213 |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
214 if(factor > 1) /* Check for overflow */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
215 factor = 1; |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
216 |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
217 penetrated = damage * factor |
3 | 218 * (victim->p_ship.s_maxshield - victim->p_shield) |
219 / (victim->p_ship.s_maxshield); | |
220 damage -= penetrated; | |
221 | |
222 victim->p_shield -= damage; /* damage shields */ | |
223 if (victim->p_shield < 0) | |
224 { /* we punched through the shield */ | |
225 damage = -victim->p_shield; /* excess damage will apply to hull */ | |
226 victim->p_shield = 0; /* and zero the shields */ | |
227 } | |
228 else | |
229 damage = 0; | |
230 damage += penetrated; /* some of the damage got through the shields */ | |
231 } | |
232 if (damage > 0) | |
233 { | |
234 victim->p_damage += damage; /* all damage to hull */ | |
235 if (configvals->erosion > 0) | |
236 { | |
237 float chance = damage * configvals->erosion; | |
238 while (chance >= 0.5) | |
239 { /* 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
|
240 * chance you can avoid permanent damage */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
241 if (lrand48() & 0x40) |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
242 { |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
243 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
|
244 victim->p_damage--; /* instead of current */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
245 } |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
246 chance -= 0.5; |
3 | 247 } |
248 if (drand48() < chance) | |
249 { | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
250 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
|
251 victim->p_damage--; /* instead of current */ |
3 | 252 } |
253 } | |
254 } | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
255 |
3 | 256 if (victim->p_damage >= victim->p_ship.s_maxdamage) |
257 { /* victim dead? */ | |
258 cause_kaboom(victim); /* make him explode */ | |
259 if (sp) | |
260 { | |
261 victim->p_whydead = why; | |
262 if (!friendly(sp, victim) | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
263 && sp != victim /* hozers were getting credit for killing |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
264 * themselves because they were at war with |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
265 their own race */ ) |
3 | 266 { |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
267 /* if a hostile player was responsible */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
268 tlog_plkill(victim, sp, op); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
269 if (victim->p_ship.s_type == PATROL) |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
270 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
|
271 else |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
272 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
|
273 killerstats(sp->p_no, victim); /* adjust everyones stats */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
274 checkmaxkills(sp->p_no); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
275 killmess(victim, sp); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
276 victim->p_whodead = sp->p_no; |
3 | 277 } |
278 else if (op && !friendly(op, victim) && op != victim) | |
279 { | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
280 /* the primary assassin was friendly, check auxiliary killer */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
281 tlog_plkill(victim, op, sp); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
282 |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
283 if (victim->p_ship.s_type == PATROL) |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
284 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
|
285 else |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
286 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
|
287 killerstats(op->p_no, victim); /* adjust everyones stats */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
288 checkmaxkills(op->p_no); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
289 killmess(victim, op); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
290 victim->p_whodead = op->p_no; |
3 | 291 } |
292 else | |
293 { | |
15
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
294 /* |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
295 * 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
|
296 * was friendly too |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
297 */ |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
298 tlog_plkill(victim, sp, (struct player *) 0); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
299 killmess(victim, sp); |
d28f3d01043c
Add code to make nebulous terrain increase penetration of sheilds.
darius
parents:
3
diff
changeset
|
300 victim->p_whodead = sp->p_no; |
3 | 301 } |
302 } | |
303 loserstats(victim->p_no); | |
304 return 1; /* victim died */ | |
305 } | |
306 else | |
307 return 0; /* victim lived */ | |
308 } | |
309 | |
310 /*-------------------------------------------------------------------------*/ | |
311 | |
312 | |
313 struct ranksorter | |
314 { | |
315 int pno; | |
316 int rank; | |
317 float di; | |
318 int teammates; | |
319 }; | |
320 | |
321 static struct ranksorter admirals[MAXTEAM]; | |
322 | |
323 int | |
324 enemy_admiral(tno) | |
325 int tno; | |
326 { | |
327 int teammates; | |
328 int pno; | |
329 int i; | |
330 | |
331 for (i = 0; i < MAXTEAM; i++) | |
332 { | |
333 admirals[i].teammates = 0; | |
334 admirals[i].rank = -1; | |
335 } | |
336 | |
337 for (i = 0; i < MAXPLAYER; i++) | |
338 { | |
339 int team; | |
340 struct player *pl; | |
341 pl = &players[i]; | |
342 | |
343 if (pl->p_status == PFREE || | |
344 pl->p_team == tno) | |
345 continue; | |
346 | |
347 team = pl->p_team; | |
348 admirals[team].teammates++; | |
349 | |
350 if (pl->p_stats.st_rank < admirals[team].rank) | |
351 continue; | |
352 if (pl->p_stats.st_rank > admirals[team].rank || | |
353 pl->p_stats.st_di > admirals[team].di) | |
354 { | |
355 admirals[team].pno = i; | |
356 admirals[team].rank = pl->p_stats.st_rank; | |
357 admirals[team].di = pl->p_stats.st_di; | |
358 } | |
359 } | |
360 | |
361 teammates = -1; | |
362 pno = 0; | |
363 for (i = 0; i < MAXTEAM; i++) | |
364 { | |
365 if (admirals[i].teammates > teammates) | |
366 { | |
367 pno = admirals[i].pno; | |
368 teammates = admirals[i].teammates; | |
369 } | |
370 } | |
371 return pno; | |
372 } | |
373 | |
374 | |
375 /*--------END OF FILE-------*/ |