annotate src/dutil.c @ 18:1424868939a8

Indenting
author darius
date Wed, 24 Dec 1997 12:38:35 +0000
parents 65de6eb6861a
children
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? */
17
65de6eb6861a Indenting...
darius
parents: 15
diff changeset
199 int penetrated;
65de6eb6861a Indenting...
darius
parents: 15
diff changeset
200 float factor;
3
cafa94d86546 Initial revision
darius
parents:
diff changeset
201 /*
cafa94d86546 Initial revision
darius
parents:
diff changeset
202 * if the server is configured for damage penetration then the shields
cafa94d86546 Initial revision
darius
parents:
diff changeset
203 * will not absorb all the damage
cafa94d86546 Initial revision
darius
parents:
diff changeset
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
65de6eb6861a Indenting...
darius
parents: 15
diff changeset
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
65de6eb6861a Indenting...
darius
parents: 15
diff changeset
210 if ((terrain_grid[(int) (victim->p_x) / TGRID_GRANULARITY * TGRID_SIZE +
65de6eb6861a Indenting...
darius
parents: 15
diff changeset
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
cafa94d86546 Initial revision
darius
parents:
diff changeset
219 * (victim->p_ship.s_maxshield - victim->p_shield)
cafa94d86546 Initial revision
darius
parents:
diff changeset
220 / (victim->p_ship.s_maxshield);
cafa94d86546 Initial revision
darius
parents:
diff changeset
221 damage -= penetrated;
cafa94d86546 Initial revision
darius
parents:
diff changeset
222
cafa94d86546 Initial revision
darius
parents:
diff changeset
223 victim->p_shield -= damage; /* damage shields */
cafa94d86546 Initial revision
darius
parents:
diff changeset
224 if (victim->p_shield < 0)
cafa94d86546 Initial revision
darius
parents:
diff changeset
225 { /* we punched through the shield */
cafa94d86546 Initial revision
darius
parents:
diff changeset
226 damage = -victim->p_shield; /* excess damage will apply to hull */
cafa94d86546 Initial revision
darius
parents:
diff changeset
227 victim->p_shield = 0; /* and zero the shields */
cafa94d86546 Initial revision
darius
parents:
diff changeset
228 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
229 else
cafa94d86546 Initial revision
darius
parents:
diff changeset
230 damage = 0;
cafa94d86546 Initial revision
darius
parents:
diff changeset
231 damage += penetrated; /* some of the damage got through the shields */
cafa94d86546 Initial revision
darius
parents:
diff changeset
232 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
233 if (damage > 0)
cafa94d86546 Initial revision
darius
parents:
diff changeset
234 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
235 victim->p_damage += damage; /* all damage to hull */
cafa94d86546 Initial revision
darius
parents:
diff changeset
236 if (configvals->erosion > 0)
cafa94d86546 Initial revision
darius
parents:
diff changeset
237 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
238 float chance = damage * configvals->erosion;
cafa94d86546 Initial revision
darius
parents:
diff changeset
239 while (chance >= 0.5)
cafa94d86546 Initial revision
darius
parents:
diff changeset
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
cafa94d86546 Initial revision
darius
parents:
diff changeset
248 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
249 if (drand48() < chance)
cafa94d86546 Initial revision
darius
parents:
diff changeset
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
cafa94d86546 Initial revision
darius
parents:
diff changeset
253 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
254 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
255 }
15
d28f3d01043c Add code to make nebulous terrain increase penetration of sheilds.
darius
parents: 3
diff changeset
256
3
cafa94d86546 Initial revision
darius
parents:
diff changeset
257 if (victim->p_damage >= victim->p_ship.s_maxdamage)
cafa94d86546 Initial revision
darius
parents:
diff changeset
258 { /* victim dead? */
cafa94d86546 Initial revision
darius
parents:
diff changeset
259 cause_kaboom(victim); /* make him explode */
cafa94d86546 Initial revision
darius
parents:
diff changeset
260 if (sp)
cafa94d86546 Initial revision
darius
parents:
diff changeset
261 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
262 victim->p_whydead = why;
cafa94d86546 Initial revision
darius
parents:
diff changeset
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
cafa94d86546 Initial revision
darius
parents:
diff changeset
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
cafa94d86546 Initial revision
darius
parents:
diff changeset
278 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
279 else if (op && !friendly(op, victim) && op != victim)
cafa94d86546 Initial revision
darius
parents:
diff changeset
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
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 {
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
cafa94d86546 Initial revision
darius
parents:
diff changeset
302 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
303 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
304 loserstats(victim->p_no);
cafa94d86546 Initial revision
darius
parents:
diff changeset
305 return 1; /* victim died */
cafa94d86546 Initial revision
darius
parents:
diff changeset
306 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
307 else
cafa94d86546 Initial revision
darius
parents:
diff changeset
308 return 0; /* victim lived */
cafa94d86546 Initial revision
darius
parents:
diff changeset
309 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
310
cafa94d86546 Initial revision
darius
parents:
diff changeset
311 /*-------------------------------------------------------------------------*/
cafa94d86546 Initial revision
darius
parents:
diff changeset
312
cafa94d86546 Initial revision
darius
parents:
diff changeset
313
cafa94d86546 Initial revision
darius
parents:
diff changeset
314 struct ranksorter
cafa94d86546 Initial revision
darius
parents:
diff changeset
315 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
316 int pno;
cafa94d86546 Initial revision
darius
parents:
diff changeset
317 int rank;
cafa94d86546 Initial revision
darius
parents:
diff changeset
318 float di;
cafa94d86546 Initial revision
darius
parents:
diff changeset
319 int teammates;
cafa94d86546 Initial revision
darius
parents:
diff changeset
320 };
cafa94d86546 Initial revision
darius
parents:
diff changeset
321
cafa94d86546 Initial revision
darius
parents:
diff changeset
322 static struct ranksorter admirals[MAXTEAM];
cafa94d86546 Initial revision
darius
parents:
diff changeset
323
cafa94d86546 Initial revision
darius
parents:
diff changeset
324 int
cafa94d86546 Initial revision
darius
parents:
diff changeset
325 enemy_admiral(tno)
cafa94d86546 Initial revision
darius
parents:
diff changeset
326 int tno;
cafa94d86546 Initial revision
darius
parents:
diff changeset
327 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
328 int teammates;
cafa94d86546 Initial revision
darius
parents:
diff changeset
329 int pno;
cafa94d86546 Initial revision
darius
parents:
diff changeset
330 int i;
cafa94d86546 Initial revision
darius
parents:
diff changeset
331
cafa94d86546 Initial revision
darius
parents:
diff changeset
332 for (i = 0; i < MAXTEAM; i++)
cafa94d86546 Initial revision
darius
parents:
diff changeset
333 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
334 admirals[i].teammates = 0;
cafa94d86546 Initial revision
darius
parents:
diff changeset
335 admirals[i].rank = -1;
cafa94d86546 Initial revision
darius
parents:
diff changeset
336 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
337
cafa94d86546 Initial revision
darius
parents:
diff changeset
338 for (i = 0; i < MAXPLAYER; i++)
cafa94d86546 Initial revision
darius
parents:
diff changeset
339 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
340 int team;
cafa94d86546 Initial revision
darius
parents:
diff changeset
341 struct player *pl;
cafa94d86546 Initial revision
darius
parents:
diff changeset
342 pl = &players[i];
cafa94d86546 Initial revision
darius
parents:
diff changeset
343
cafa94d86546 Initial revision
darius
parents:
diff changeset
344 if (pl->p_status == PFREE ||
cafa94d86546 Initial revision
darius
parents:
diff changeset
345 pl->p_team == tno)
cafa94d86546 Initial revision
darius
parents:
diff changeset
346 continue;
cafa94d86546 Initial revision
darius
parents:
diff changeset
347
cafa94d86546 Initial revision
darius
parents:
diff changeset
348 team = pl->p_team;
cafa94d86546 Initial revision
darius
parents:
diff changeset
349 admirals[team].teammates++;
cafa94d86546 Initial revision
darius
parents:
diff changeset
350
cafa94d86546 Initial revision
darius
parents:
diff changeset
351 if (pl->p_stats.st_rank < admirals[team].rank)
cafa94d86546 Initial revision
darius
parents:
diff changeset
352 continue;
cafa94d86546 Initial revision
darius
parents:
diff changeset
353 if (pl->p_stats.st_rank > admirals[team].rank ||
cafa94d86546 Initial revision
darius
parents:
diff changeset
354 pl->p_stats.st_di > admirals[team].di)
cafa94d86546 Initial revision
darius
parents:
diff changeset
355 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
356 admirals[team].pno = i;
cafa94d86546 Initial revision
darius
parents:
diff changeset
357 admirals[team].rank = pl->p_stats.st_rank;
cafa94d86546 Initial revision
darius
parents:
diff changeset
358 admirals[team].di = pl->p_stats.st_di;
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 teammates = -1;
cafa94d86546 Initial revision
darius
parents:
diff changeset
363 pno = 0;
cafa94d86546 Initial revision
darius
parents:
diff changeset
364 for (i = 0; i < MAXTEAM; i++)
cafa94d86546 Initial revision
darius
parents:
diff changeset
365 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
366 if (admirals[i].teammates > teammates)
cafa94d86546 Initial revision
darius
parents:
diff changeset
367 {
cafa94d86546 Initial revision
darius
parents:
diff changeset
368 pno = admirals[i].pno;
cafa94d86546 Initial revision
darius
parents:
diff changeset
369 teammates = admirals[i].teammates;
cafa94d86546 Initial revision
darius
parents:
diff changeset
370 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
371 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
372 return pno;
cafa94d86546 Initial revision
darius
parents:
diff changeset
373 }
cafa94d86546 Initial revision
darius
parents:
diff changeset
374
cafa94d86546 Initial revision
darius
parents:
diff changeset
375
cafa94d86546 Initial revision
darius
parents:
diff changeset
376 /*--------END OF FILE-------*/