annotate src/dutil.c @ 12:8f2256d473fb

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