]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
add missing fdecl
[divverent/nexuiz.git] / data / qcsrc / server / g_damage.qc
1 .float dmg;
2 .float dmg_edge;
3 .float dmg_force;
4 .float dmg_radius;
5
6 float Damage_DamageInfo_SendEntity(entity to, float sf)
7 {
8         WriteByte(MSG_ENTITY, ENT_CLIENT_DAMAGEINFO);
9         WriteShort(MSG_ENTITY, self.projectiledeathtype);
10         WriteCoord(MSG_ENTITY, floor(self.origin_x));
11         WriteCoord(MSG_ENTITY, floor(self.origin_y));
12         WriteCoord(MSG_ENTITY, floor(self.origin_z));
13         WriteByte(MSG_ENTITY, bound(1, self.dmg, 255));
14         WriteByte(MSG_ENTITY, bound(0, self.dmg_radius, 255));
15         WriteByte(MSG_ENTITY, bound(1, self.dmg_edge, 255));
16         WriteShort(MSG_ENTITY, self.oldorigin_x);
17         return TRUE;
18 }
19
20 void Damage_DamageInfo(vector org, float coredamage, float edgedamage, float rad, vector force, float deathtype, entity dmgowner)
21 {
22         // TODO maybe call this from non-edgedamage too?
23         // TODO maybe make the client do the particle effects for the weapons and the impact sounds using this info?
24
25         entity e;
26
27         if(!sound_allowed(MSG_BROADCAST, dmgowner))
28                 deathtype |= 0x8000;
29
30         e = spawn();
31         setorigin(e, org);
32         e.projectiledeathtype = deathtype;
33         e.dmg = coredamage;
34         e.dmg_edge = edgedamage;
35         e.dmg_radius = rad;
36         e.dmg_force = vlen(force);
37         e.velocity = force;
38
39         e.oldorigin_x = compressShortVector(e.velocity);
40
41         Net_LinkEntity(e, FALSE, 0.2, Damage_DamageInfo_SendEntity);
42 }
43
44 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
45
46 float checkrules_firstblood;
47
48 float yoda;
49 float damage_goodhits;
50 float damage_gooddamage;
51 float headshot;
52 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
53
54 .float dmg_team;
55 .float teamkill_complain;
56 .float teamkill_soundtime;
57 .entity teamkill_soundsource;
58 .entity pusher;
59 .float taunt_soundtime;
60
61
62 float IsDifferentTeam(entity a, entity b)
63 {
64         if(teams_matter)
65         {
66                 if(a.team == b.team)
67                         return 0;
68         }
69         else
70         {
71                 if(a == b)
72                         return 0;
73         }
74         return 1;
75 }
76
77 float IsFlying(entity a)
78 {
79         if(a.flags & FL_ONGROUND)
80                 return 0;
81         if(a.waterlevel >= WATERLEVEL_SWIMMING)
82                 return 0;
83         traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
84         if(trace_fraction < 1)
85                 return 0;
86         return 1;
87 }
88
89 void UpdateFrags(entity player, float f)
90 {
91         PlayerTeamScore_AddScore(player, f);
92 }
93
94 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
95 void W_SwitchWeapon_Force(entity e, float w);
96 void GiveFrags (entity attacker, entity targ, float f)
97 {
98         // TODO route through PlayerScores instead
99         if(gameover) return;
100
101         if(f < 0)
102         {
103                 if(targ == attacker)
104                 {
105                         // suicide
106                         PlayerScore_Add(attacker, SP_SUICIDES, 1);
107                 }
108                 else
109                 {
110                         // teamkill
111                         PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
112                 }
113         }
114         else
115         {
116                 // regular frag
117                 PlayerScore_Add(attacker, SP_KILLS, 1);
118         }
119
120         PlayerScore_Add(targ, SP_DEATHS, 1);
121
122         if(g_arena)
123                 if(cvar("g_arena_roundbased"))
124                         return;
125
126         if(g_weaponarena_random)
127         {
128                 // after a frag, choose another random weapon set
129                 attacker.weapons = randombits(attacker.weapons, (inWarmupStage ? warmup_start_weapons : start_weapons));
130                 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
131                         W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
132         }
133
134         // FIXME fix the mess this is (we have REAL points now!)
135         if(g_runematch)
136         {
137                 f = RunematchHandleFrags(attacker, targ, f);
138         }
139         else if(g_keyhunt)
140         {
141                 f = kh_HandleFrags(attacker, targ, f);
142         }
143         else if(g_lms)
144         {
145                 // remove a life
146                 float tl;
147                 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
148                 if(tl < lms_lowest_lives)
149                         lms_lowest_lives = tl;
150                 if(tl <= 0)
151                 {
152                         if(!lms_next_place)
153                                 lms_next_place = player_count;
154                         PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
155                         --lms_next_place;
156                 }
157                 f = 0;
158         }
159         else if(g_ctf)
160         {
161                 if(g_ctf_ignore_frags)
162                         f = 0;
163         }
164
165         attacker.totalfrags += f;
166
167         if(f)
168                 UpdateFrags(attacker, f);
169 }
170
171 string AppendItemcodes(string s, entity player)
172 {
173         float w;
174         w = player.weapon;
175         //if(w == 0)
176         //      w = player.switchweapon;
177         if(w == 0)
178                 w = player.cnt; // previous weapon!
179         s = strcat(s, ftos(w));
180         if(time < player.strength_finished)
181                 s = strcat(s, "S");
182         if(time < player.invincible_finished)
183                 s = strcat(s, "I");
184         if(player.flagcarried != world)
185                 s = strcat(s, "F");
186         if(player.BUTTON_CHAT)
187                 s = strcat(s, "T");
188         if(player.kh_next)
189                 s = strcat(s, "K");
190         if(player.runes)
191                 s = strcat(s, "|", ftos(player.runes));
192         return s;
193 }
194
195 void LogDeath(string mode, float deathtype, entity killer, entity killed)
196 {
197         string s;
198         if(!cvar("sv_eventlog"))
199                 return;
200         s = strcat(":kill:", mode);
201         s = strcat(s, ":", ftos(killer.playerid));
202         s = strcat(s, ":", ftos(killed.playerid));
203         s = strcat(s, ":type=", ftos(deathtype));
204         s = strcat(s, ":items=");
205         s = AppendItemcodes(s, killer);
206         if(killed != killer)
207         {
208                 s = strcat(s, ":victimitems=");
209                 s = AppendItemcodes(s, killed);
210         }
211         GameLogEcho(s);
212 }
213
214 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
215 {
216         string  s, a;
217         float p, w;
218
219         if (targ.classname == "player" || targ.classname == "corpse")
220         {
221                 if (targ.classname == "corpse")
222                         s = "A corpse";
223                 else
224                         s = targ.netname;
225                 a = attacker.netname;
226
227                 if (targ == attacker)
228                 {
229                         if (deathtype == DEATH_TEAMCHANGE) {
230                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
231                         } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
232                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
233                                 return;
234                         } else if (deathtype == DEATH_CAMP) {
235                                 if(sv_gentle)
236                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
237                                 else
238                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
239                         } else if (deathtype == DEATH_NOAMMO) {
240                                 if(sv_gentle)
241                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
242                                 else
243                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
244                         } else if (deathtype == DEATH_ROT) {
245                                 if(sv_gentle)
246                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
247                                 else
248                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
249                         } else if (deathtype == DEATH_MIRRORDAMAGE) {
250                                 if(sv_gentle)
251                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
252                                 else
253                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
254                         } else {
255                                 if(sv_gentle)
256                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
257                                 else
258                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
259                         }
260
261                         if(sv_gentle) {
262                                 if (deathtype == DEATH_CAMP)
263                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
264                                 else if (deathtype == DEATH_MIRRORDAMAGE)
265                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
266                                 else
267                                         bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
268
269                                 if(deathtype != DEATH_TEAMCHANGE)
270                                 {
271                                         LogDeath("suicide", deathtype, targ, targ);
272                                         GiveFrags(attacker, targ, -1);
273                                 }
274                                 if (targ.killcount > 2)
275                                         bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
276                         } else {
277                                 w = DEATH_WEAPONOF(deathtype);
278                                 if(WEP_VALID(w))
279                                 {
280                                         w_deathtypestring = "couldn't resist the urge to self-destruct";
281                                         w_deathtype = deathtype;
282                                         weapon_action(w, WR_SUICIDEMESSAGE);
283                                         bprint("^1", s, "^1 ", w_deathtypestring, "\n");
284                                 }
285                                 else if (deathtype == DEATH_KILL)
286                                         bprint ("^1",s, "^1 couldn't take it anymore\n");
287                                 else if (deathtype == DEATH_ROT)
288                                         bprint ("^1",s, "^1 died\n");
289                                 else if (deathtype == DEATH_NOAMMO)
290                                         bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
291                                 else if (deathtype == DEATH_CAMP)
292                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
293                                 else if (deathtype == DEATH_MIRRORDAMAGE)
294                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
295                                 else if (deathtype == DEATH_CHEAT)
296                                         bprint ("^1",s, "^1 unfairly eliminated himself\n");
297                                 else if (deathtype == DEATH_FIRE)
298                                         bprint ("^1",s, "^1 burned to death\n");
299                                 else if (deathtype != DEATH_TEAMCHANGE)
300                                         bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
301
302                                 if(deathtype != DEATH_TEAMCHANGE)
303                                 {
304                                         LogDeath("suicide", deathtype, targ, targ);
305                                         GiveFrags(attacker, targ, -1);
306                                 }
307                                 if (targ.killcount > 2)
308                                         bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
309                         }
310                 }
311                 else if (attacker.classname == "player" || attacker.classname == "gib")
312                 {
313                         if(teams_matter && attacker.team == targ.team)
314                         {
315                                 if(sv_gentle) {
316                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
317                                         bprint ("^1", a, "^1 took action against a team mate\n");
318                                 } else {
319                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
320                                         bprint ("^1", a, "^1 mows down a team mate\n");
321                                 }
322                                 GiveFrags(attacker, targ, -1);
323                                 if (targ.killcount > 2) {
324                                         if(sv_gentle)
325                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
326                                         else
327                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
328                                 }
329                                 if (attacker.killcount > 2) {
330                                         if(sv_gentle)
331                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
332                                         else
333                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
334                                 }
335                                 attacker.killcount = 0;
336
337                                 LogDeath("tk", deathtype, attacker, targ);
338                         }
339                         else
340                         {
341                                 string blood_message, victim_message;
342                                 if (!checkrules_firstblood)
343                                 {
344                                         checkrules_firstblood = TRUE;
345                                         if(sv_gentle)
346                                         {
347                                                 bprint("^1",a, "^1 was the first to score", "\n");
348                                                 blood_message = "^1First point\n";
349                                                 //victim_message = "^1First victim\n";  // or First casualty
350                                         }
351                                         else
352                                         {
353                                                 bprint("^1",a, "^1 drew first blood", "\n");
354                                                 blood_message = "^1First blood\n";
355                                                 victim_message = "^1First victim\n";  // or First casualty
356                                         }
357                                 }
358
359                                 if(sv_gentle > 0) {
360                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s));
361                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7"));
362                                 } else {
363                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s));
364                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a));
365                                         attacker.taunt_soundtime = time + 1;
366                                 }
367
368                                 if(sv_gentle) {
369                                         bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
370                                 } else {
371                                         w = DEATH_WEAPONOF(deathtype);
372                                         if(WEP_VALID(w))
373                                         {
374                                                 w_deathtypestring = "was blasted by";
375                                                 w_deathtype = deathtype;
376                                                 weapon_action(w, WR_KILLMESSAGE);
377                                                 p = strstrofs(w_deathtypestring, "#", 0);
378                                                 if(p < 0)
379                                                         bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
380                                                 else
381                                                         bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
382                                         }
383                                         else if (deathtype == DEATH_TELEFRAG)
384                                                 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
385                                         else if (deathtype == DEATH_DROWN)
386                                                 bprint ("^1",s, "^1 was drowned by ", a, "\n");
387                                         else if (deathtype == DEATH_SLIME)
388                                                 bprint ("^1",s, "^1 was slimed by ", a, "\n");
389                                         else if (deathtype == DEATH_LAVA)
390                                                 bprint ("^1",s, "^1 was cooked by ", a, "\n");
391                                         else if (deathtype == DEATH_FALL)
392                                                 bprint ("^1",s, "^1 was grounded by ", a, "\n");
393                                         else if (deathtype == DEATH_SHOOTING_STAR)
394                                                 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
395                                         else if (deathtype == DEATH_SWAMP)
396                                                 bprint ("^1",s, "^1 was conserved by ", a, "\n");
397                                         else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
398                                         {
399                                                 p = strstrofs(inflictor.message2, "#", 0);
400                                                 if(p < 0)
401                                                         bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
402                                                 else
403                                                         bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
404                                         }
405                                         else if(deathtype == DEATH_TURRET)
406                                                 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
407                                         else if(deathtype == DEATH_TOUCHEXPLODE)
408                                                 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
409                                         else if(deathtype == DEATH_CHEAT)
410                                                 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
411                                         else if (deathtype == DEATH_FIRE)
412                                                 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
413                                         else
414                                                 bprint ("^1",s, "^1 was fragged by ", a, "\n");
415                                 }
416
417                                 if(g_ctf && targ.flagcarried)
418                                 {
419                                         UpdateFrags(attacker, ctf_score_value("score_kill"));
420                                         PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
421                                         GiveFrags(attacker, targ, 0); // for logging
422                                 }
423                                 else
424                                         GiveFrags(attacker, targ, 1);
425
426                                 if (targ.killcount > 2) {
427                                         if(sv_gentle)
428                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
429                                         else
430                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
431                                 }
432
433                                 attacker.killcount = attacker.killcount + 1;
434
435                                 if (attacker.killcount > 2) {
436                                         if(sv_gentle)
437                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
438                                         else
439                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
440                                 }
441
442                                 LogDeath("frag", deathtype, attacker, targ);
443
444                                 if (attacker.killcount == 3)
445                                 {
446                                         if(sv_gentle) {
447                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
448                                         } else {
449                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
450                                                 announce(attacker, "announcer/male/03kills.wav");
451                                         }
452                                 }
453                                 else if (attacker.killcount == 5)
454                                 {
455                                         if(sv_gentle) {
456                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
457                                         } else {
458                                                 bprint (a,"^7 unleashes ^1RAGE\n");
459                                                 announce(attacker, "announcer/male/05kills.wav");
460                                         }
461                                 }
462                                 else if (attacker.killcount == 10)
463                                 {
464                                         if(sv_gentle) {
465                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
466                                         } else {
467                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");
468                                                 announce(attacker, "announcer/male/10kills.wav");
469                                         }
470                                 }
471                                 else if (attacker.killcount == 15)
472                                 {
473                                         if(sv_gentle) {
474                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
475                                         } else {
476                                                 bprint (a,"^7 executes ^1MAYHEM!\n");
477                                                 announce(attacker, "announcer/male/15kills.wav");
478                                         }
479                                 }
480                                 else if (attacker.killcount == 20)
481                                 {
482                                         if(sv_gentle) {
483                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
484                                         } else {
485                                                 bprint (a,"^7 is a ^1BERSERKER!\n");
486                                                 announce(attacker, "announcer/male/20kills.wav");
487                                         }
488                                 }
489                                 else if (attacker.killcount == 25)
490                                 {
491                                         if(sv_gentle) {
492                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
493                                         } else {
494                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");
495                                                 announce(attacker, "announcer/male/25kills.wav");
496                                         }
497                                 }
498                                 else if (attacker.killcount == 30)
499                                 {
500                                         if(sv_gentle) {
501                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
502                                         } else {
503                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
504                                                 announce(attacker, "announcer/male/30kills.wav");
505                                         }
506                                 }
507                         }
508                 }
509                 else
510                 {
511                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
512                         if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
513                                 bprint ("^1",s, "^1 ", inflictor.message, "\n");
514                         else if (deathtype == DEATH_DROWN)
515                                 if(sv_gentle)
516                                         bprint ("^1",s, "^1 was in the water for too long\n");
517                                 else
518                                         bprint ("^1",s, "^1 drowned\n");
519                         else if (deathtype == DEATH_SLIME)
520                                 bprint ("^1",s, "^1 was slimed\n");
521                         else if (deathtype == DEATH_LAVA)
522                                 if(sv_gentle)
523                                         bprint ("^1",s, "^1 found a hot place\n");
524                                 else
525                                         bprint ("^1",s, "^1 turned into hot slag\n");
526                         else if (deathtype == DEATH_FALL)
527                                 if(sv_gentle)
528                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");
529                                 else
530                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");
531                         else if (deathtype == DEATH_SHOOTING_STAR)
532                                 bprint ("^1",s, "^1 became a shooting star\n");
533                         else if (deathtype == DEATH_SWAMP)
534                                 if(sv_gentle)
535                                         bprint ("^1",s, "^1 discovered a swamp\n");
536                                 else
537                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");
538                         else if(deathtype == DEATH_TURRET)
539                                 bprint ("^1",s, "^1 was mowed down by a turret \n");
540                         else if(deathtype == DEATH_TOUCHEXPLODE)
541                                 bprint ("^1",s, "^1 died in an accident\n");
542                         else if(deathtype == DEATH_CHEAT)
543                                 bprint ("^1",s, "^1 was unfairly eliminated\n");
544                         else if(deathtype == DEATH_FIRE)
545                                 if(sv_gentle)
546                                         bprint ("^1",s, "^1 felt a little hot\n");
547                                 else
548                                         bprint ("^1",s, "^1 burnt to death\n");
549                         else
550                                 if(sv_gentle)
551                                         bprint ("^1",s, "^1 needs a restart\n");
552                                 else
553                                         bprint ("^1",s, "^1 died\n");
554                         GiveFrags(targ, targ, -1);
555                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
556                                 announce(targ, "announcer/male/botlike.wav");
557                         }
558
559                         if (targ.killcount > 2)
560                                 if(sv_gentle)
561                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
562                                 else
563                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
564
565                         LogDeath("accident", deathtype, targ, targ);
566                 }
567                 targ.death_origin = targ.origin;
568                 if(targ != attacker)
569                         targ.killer_origin = attacker.origin;
570                 // FIXME: this should go in PutClientInServer
571                 if (targ.killcount)
572                         targ.killcount = 0;
573         }
574 }
575
576 // these are updated by each Damage call for use in button triggering and such
577 entity damage_targ;
578 entity damage_inflictor;
579 entity damage_attacker;
580
581 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
582 {
583         float mirrordamage;
584         float mirrorforce;
585         float teamdamage0;
586         entity attacker_save;
587         mirrordamage = 0;
588         mirrorforce = 0;
589
590         if (gameover || targ.killcount == -666)
591                 return;
592
593         local entity oldself;
594         oldself = self;
595         self = targ;
596         damage_targ = targ;
597         damage_inflictor = inflictor;
598         damage_attacker = attacker;
599                 attacker_save = attacker;
600
601         if(targ.classname == "player")
602                 if(targ.hook)
603                         if(targ.hook.aiment)
604                                 if(targ.hook.aiment == attacker)
605                                         RemoveGrapplingHook(targ); // STOP THAT, you parasite!
606
607         // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
608         if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
609         {
610                 if(targ.classname == "player")
611                         if not(IsDifferentTeam(targ, attacker))
612                         {
613                                 self = oldself;
614                                 return;
615                         }
616         }
617
618         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
619         {
620                 // These are ALWAYS lethal
621                 // No damage modification here
622                 // Instead, prepare the victim for his death...
623                 targ.armorvalue = 0;
624                 targ.spawnshieldtime = 0;
625                 targ.health = 0.9; // this is < 1
626                 targ.flags -= targ.flags & FL_GODMODE;
627                 damage = 100000;
628         }
629         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
630         {
631                 // no processing
632         }
633         else
634         {
635                 if (targ.classname == "player")
636                 if (attacker.classname == "player")
637                 if (!targ.isbot)
638                 if (attacker.isbot)
639                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
640
641                 // nullify damage if teamplay is on
642                 if(deathtype != DEATH_TELEFRAG)
643                 if(attacker.classname == "player")
644                 {
645                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
646                         {
647                                 damage = 0;
648                                 force = '0 0 0';
649                         }
650                         else if(attacker.team == targ.team)
651                         {
652                                 if(teamplay == 1)
653                                         damage = 0;
654                                 else if(attacker != targ)
655                                 {
656                                         if(teamplay == 3)
657                                                 damage = 0;
658                                         else if(teamplay == 4)
659                                         {
660                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
661                                                 {
662                                                         teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
663                                                         attacker.dmg_team = attacker.dmg_team + damage;
664                                                         if(attacker.dmg_team > teamdamage0)
665                                                                 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
666                                                         mirrorforce = cvar("g_mirrordamage") * vlen(force);
667                                                         if(g_minstagib)
668                                                         {
669                                                                 if(cvar("g_friendlyfire") == 0)
670                                                                         damage = 0;
671                                                         }
672                                                         else
673                                                                 damage = cvar("g_friendlyfire") * damage;
674                                                         // mirrordamage will be used LATER
675                                                 }
676                                                 else
677                                                         damage = 0;
678                                         }
679                                 }
680                         }
681                 }
682
683                 if(targ.classname == "player")
684                 if(attacker.classname == "player")
685                 if(attacker != targ)
686                 {
687                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
688                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
689                 }
690
691                 if(targ.classname == "player")
692                 if (g_minstagib)
693                 {
694                         if ((deathtype == DEATH_FALL)  ||
695                                 (deathtype == DEATH_DROWN) ||
696                                 (deathtype == DEATH_SLIME) ||
697                                 (deathtype == DEATH_LAVA))
698                         {
699                                 self = oldself;
700                                 return;
701                         }
702                         if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
703                         {
704                                 targ.armorvalue -= 1;
705                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
706                                 damage = 0;
707                                 targ.hitsound += 1;
708                                 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
709                         }
710                         if (DEATH_ISWEAPON(deathtype, WEP_LASER))
711                         {
712                                 damage = 0;
713                                 if (targ != attacker)
714                                 {
715                                         if (targ.classname == "player")
716                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
717                                         damage = 0;
718                                         mirrordamage = 0;
719                                         force = '0 0 0';
720                                         // keep mirrorforce
721                                         attacker = targ;
722                                 }
723                         }
724                 }
725
726                 if not(DEATH_ISSPECIAL(deathtype))
727                 {
728                         damage *= g_weapondamagefactor;
729                         mirrordamage *= g_weapondamagefactor;
730                         force = force * g_weaponforcefactor;
731                         mirrorforce *= g_weaponforcefactor;
732                 }
733
734                 // apply strength multiplier
735                 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
736                 {
737                         if(targ == attacker)
738                         {
739                                 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
740                                 force = force * cvar("g_balance_powerup_strength_selfforce");
741                         }
742                         else
743                         {
744                                 damage = damage * cvar("g_balance_powerup_strength_damage");
745                                 force = force * cvar("g_balance_powerup_strength_force");
746                         }
747                 }
748
749                 // apply invincibility multiplier
750                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
751                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
752
753                 if (targ == attacker)
754                         damage = damage * cvar("g_balance_selfdamagepercent");  // Partial damage if the attacker hits himself
755
756                 // CTF: reduce damage/force
757                 if(g_ctf)
758                 if(targ == attacker)
759                 if(targ.flagcarried)
760                 {
761                         damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
762                         force = force * cvar("g_ctf_flagcarrier_selfforce");
763                 }
764
765                 if(g_runematch)
766                 {
767                         // apply strength rune
768                         if (attacker.runes & RUNE_STRENGTH)
769                         {
770                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
771                                 {
772                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
773                                         force = force * cvar("g_balance_rune_strength_combo_force");
774                                 }
775                                 else
776                                 {
777                                         damage = damage * cvar("g_balance_rune_strength_damage");
778                                         force = force * cvar("g_balance_rune_strength_force");
779                                 }
780                         }
781                         else if (attacker.runes & CURSE_WEAK)
782                         {
783                                 damage = damage * cvar("g_balance_curse_weak_damage");
784                                 force = force * cvar("g_balance_curse_weak_force");
785                         }
786
787                         // apply defense rune
788                         if (targ.runes & RUNE_DEFENSE)
789                         {
790                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
791                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
792                                 else
793                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
794                         }
795                         else if (targ.runes & CURSE_VULNER)
796                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
797                 }
798
799                 // count the damage
800                 if(attacker)
801                 if(!targ.deadflag)
802                 if(targ.takedamage == DAMAGE_AIM)
803                 if(targ != attacker)
804                 if(targ.classname == "player")
805                 {
806                         if(IsDifferentTeam(targ, attacker))
807                         {
808                                 if(damage > 0)
809                                 {
810                                         if(targ.BUTTON_CHAT)
811                                                 attacker.typehitsound += 1;
812                                         else
813                                                 attacker.hitsound += 1;
814
815                                         damage_goodhits += 1;
816                                         damage_gooddamage += damage;
817
818                                         if not(DEATH_ISSPECIAL(deathtype))
819                                         {
820                                                 if(!g_minstagib)
821                                                 if(IsFlying(targ))
822                                                         yoda = 1;
823
824                                                 if(g_minstagib)
825                                                 if(targ.items & IT_STRENGTH)
826                                                         yoda = 1;
827
828                                                 // HEAD SHOT:
829                                                 // find height of hit on player axis
830                                                 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
831                                                 vector headmins, headmaxs, org;
832                                                 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
833                                                 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * (1.5 * targ.view_ofs_z - 0.5 * targ.maxs_z);
834                                                 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
835                                                 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
836                                                 {
837                                                         damage *= 1 + damage_headshotbonus;
838                                                         headshot = 1;
839                                                         deathtype |= HITTYPE_HEADSHOT;
840                                                 }
841                                         }
842                                 }
843                         }
844                         else
845                         {
846                                 if(deathtype != DEATH_FIRE)
847                                         attacker.typehitsound += 1;
848                                 if(mirrordamage > 0)
849                                         if(time > attacker.teamkill_complain)
850                                         {
851                                                 attacker.teamkill_complain = time + 5;
852                                                 attacker.teamkill_soundtime = time + 0.4;
853                                                 attacker.teamkill_soundsource = targ;
854                                         }
855                         }
856                 }
857         }
858
859         // apply push
860         if (self.damageforcescale)
861         if (vlen(force))
862         {
863                 self.velocity = self.velocity + self.damageforcescale * force;
864                 self.flags &~= FL_ONGROUND;
865                 UpdateCSQCProjectile(self);
866         }
867         // apply damage
868         if (damage != 0 || (self.damageforcescale && vlen(force)))
869         if (self.event_damage)
870                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
871         self = oldself;
872
873         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
874         {
875                 // Savage: vampire mode
876                 if (g_vampire)
877                 if (!g_minstagib)
878                 if (time > self.spawnshieldtime)
879                 {
880                         attacker.health += damage;
881                 }
882                 if(g_runematch)
883                 {
884                         if (attacker.runes & RUNE_VAMPIRE)
885                         {
886                         // apply vampire rune
887                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
888                                 {
889                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
890                                         attacker.health = bound(
891                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
892                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
893                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
894                                 }
895                                 else
896                                 {
897                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
898                                         attacker.health = bound(
899                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
900                                                                                         // empathy won't let you gain health in the same way...
901                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
902                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
903                                         }
904                         }
905                         // apply empathy curse
906                         else if (attacker.runes & CURSE_EMPATHY)
907                         {
908                                 attacker.health = bound(
909                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
910                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
911                                         attacker.health);
912                         }
913                 }
914         }
915
916         // apply mirror damage if any
917         if(mirrordamage > 0 || mirrorforce > 0)
918         {
919                 attacker = attacker_save;
920                 if(g_minstagib)
921                         if(mirrordamage > 0)
922                         {
923                                 // just lose extra LIVES, don't kill the player for mirror damage
924                                 if(attacker.armorvalue > 0)
925                                 {
926                                         attacker.armorvalue = attacker.armorvalue - 1;
927                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
928                                         attacker.hitsound += 1;
929                                 }
930                                 mirrordamage = 0;
931                         }
932                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
933                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
934         }
935 }
936
937 vector NearestPointOnBox(entity box, vector org)
938 {
939         vector m1, m2, nearest;
940
941         m1 = box.mins + box.origin;
942         m2 = box.maxs + box.origin;
943
944         nearest_x = bound(m1_x, org_x, m2_x);
945         nearest_y = bound(m1_y, org_y, m2_y);
946         nearest_z = bound(m1_z, org_z, m2_z);
947
948         return nearest;
949 }
950
951 .float actual_damage[WEP_COUNT]; //amount of damage done
952 .float max_damage[WEP_COUNT]; //the maximum damage of the weapon
953
954 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(actual_damage);
955 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(max_damage);
956
957 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
958 {
959         float weaponid;
960         weaponid = DEATH_WEAPONOF(deathtype);
961         if not(inWarmupStage)
962         if(weaponid)
963         if(clienttype(attacker) == CLIENTTYPE_REAL)
964         {
965                 // Track damage done and update the stat to be sent later in g_world.qc
966                 attacker.actual_damage[weaponid] += damage;
967                 attacker.damage_hits = weaponid + 64 * rint(attacker.actual_damage[weaponid]);
968         }
969 }
970
971 float RadiusDamage_running;
972 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
973 // Returns total damage applies to creatures
974 {
975         entity  targ;
976         float   finaldmg;
977         float   power;
978         vector  blastorigin;
979         vector  force;
980         vector  diff;
981         vector  center;
982         vector  nearest;
983         float   total_damage_to_creatures;
984         entity  next;
985
986         float stat_damagedone;
987         float stat_maxdamage;
988
989         if(RadiusDamage_running)
990         {
991                 string save;
992                 print("RadiusDamage called recursively!\n");
993                 print("Expect stuff to go HORRIBLY wrong.\n");
994                 print("Causing a stack trace...\n");
995                 save = cvar_string("prvm_backtraceforwarnings");
996                 cvar_set("prvm_backtraceforwarnings", "1");
997                 fclose(-1); // calls VM_Warning
998                 cvar_set("prvm_backtraceforwarnings", save);
999                 return 0;
1000         }
1001
1002
1003         RadiusDamage_running = 1;
1004
1005         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1006         total_damage_to_creatures = 0;
1007
1008         if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1009         {
1010                 force = inflictor.velocity;
1011                 if(vlen(force) == 0)
1012                         force = '0 0 -1';
1013                 else
1014                         force = normalize(force);
1015                 if(forceintensity >= 0)
1016                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1017                 else
1018                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1019         }
1020
1021         stat_damagedone = 0;
1022         stat_maxdamage = 0;
1023
1024         targ = findradius (blastorigin, rad);
1025         while (targ)
1026         {
1027                 next = targ.chain;
1028                 if (targ != inflictor)
1029                         if (ignore != targ)
1030                         {
1031                                 // LordHavoc: measure distance to nearest point on target (not origin)
1032                                 // (this guarentees 100% damage on a touch impact)
1033                                 nearest = NearestPointOnBox(targ, blastorigin);
1034                                 diff = nearest - blastorigin;
1035                                 // round up a little on the damage to ensure full damage on impacts
1036                                 // and turn the distance into a fraction of the radius
1037                                 power = 1 - ((vlen (diff) - 2) / rad);
1038                                 //bprint(" ");
1039                                 //bprint(ftos(power));
1040                                 if (power > 0)
1041                                 {
1042                                         if (power > 1)
1043                                                 power = 1;
1044                                         finaldmg = coredamage * power + edgedamage * (1 - power);
1045                                         if (finaldmg > 0)
1046                                         {
1047                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1048                                                 // if it's a player, use the view origin as reference
1049                                                 if (targ.classname == "player")
1050                                                         center = targ.origin + targ.view_ofs;
1051                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
1052                                                 // test line of sight to multiple positions on box,
1053                                                 // and do damage if any of them hit
1054                                                 local float c;
1055                                                 c = ceil(finaldmg / 10);
1056                                                 if (c > 20)
1057                                                         c = 20;
1058                                                 while (c > 0)
1059                                                 {
1060                                                         c = c - 1;
1061                                                         traceline(blastorigin, nearest, TRUE, inflictor);
1062                                                         if (trace_fraction == 1 || trace_ent == targ
1063                                                             || cvar("g_throughfloor"))
1064                                                         {
1065                                                                 if(targ.iscreature)
1066                                                                 {
1067                                                                         total_damage_to_creatures += finaldmg;
1068
1069                                                                         if(targ.flags & FL_CLIENT)
1070                                                                         if(targ.deadflag == DEAD_NO)
1071                                                                         if(targ != attacker)
1072                                                                         if(!teamplay || targ.team != attacker.team)
1073                                                                         {
1074                                                                                 stat_damagedone += finaldmg;
1075                                                                                 stat_maxdamage += coredamage;
1076                                                                         }
1077                                                                 }
1078
1079                                                                 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1080                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1081                                                                 else
1082                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1083                                                                 break;
1084                                                         }
1085                                                         nearest_x = targ.mins_x + random() * targ.size_x;
1086                                                         nearest_y = targ.mins_y + random() * targ.size_y;
1087                                                         nearest_z = targ.mins_z + random() * targ.size_z;
1088                                                 }
1089                                         }
1090                                 }
1091                         }
1092                 targ = next;
1093         }
1094
1095         RadiusDamage_running = 0;
1096
1097         Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1098
1099         return total_damage_to_creatures;
1100 }
1101
1102 .float fire_damagepersec;
1103 .float fire_endtime;
1104 .float fire_deathtype;
1105 .entity fire_owner;
1106 .float fire_hitsound;
1107 .entity fire_burner;
1108
1109 void fireburner_think();
1110
1111 float Fire_IsBurning(entity e)
1112 {
1113         return (time < e.fire_endtime);
1114 }
1115
1116 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1117 {
1118         float dps;
1119         float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1120
1121         if(e.classname != "player")
1122         if(!e.fire_burner)
1123         {
1124                 // print("adding a fire burner to ", e.classname, "\n");
1125                 e.fire_burner = spawn();
1126                 e.fire_burner.classname = "fireburner";
1127                 e.fire_burner.think = fireburner_think;
1128                 e.fire_burner.nextthink = time;
1129                 e.fire_burner.owner = e;
1130         }
1131
1132         t = max(t, 0.1);
1133         dps = d / t;
1134         if(Fire_IsBurning(e))
1135         {
1136                 mintime = e.fire_endtime - time;
1137                 maxtime = max(mintime, t);
1138
1139                 mindps = e.fire_damagepersec;
1140                 maxdps = max(mindps, dps);
1141
1142                 if(maxtime > mintime || maxdps > mindps)
1143                 {
1144                         mindamage = mindps * mintime;
1145                         maxdamage = mindamage + d;
1146
1147                         // interval [mintime, maxtime] * [mindps, maxdps]
1148                         // intersected with
1149                         // [mindamage, maxdamage]
1150                         // maximum of this!
1151
1152                         if(maxdamage >= maxtime * maxdps)
1153                         {
1154                                 totaltime = maxtime;
1155                                 totaldamage = maxtime * maxdps;
1156
1157                                 // this branch increases totaldamage if either t > mintime, or dps > mindps
1158                         }
1159                         else
1160                         {
1161                                 // maxdamage is inside the interval!
1162                                 // first, try to use mindps; only if this fails, increase dps as needed
1163                                 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1164                                 totaldamage = maxdamage;
1165                                 // can totaldamage / totaltime be >= maxdps?
1166                                 // max(mindps, maxdamage / maxtime) >= maxdps?
1167                                 // we know maxdamage < maxtime * maxdps
1168                                 // so it cannot be
1169
1170                                 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1171                         }
1172
1173                         // total conditions for increasing:
1174                         //     maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1175                         // however:
1176                         //     if maxtime = mintime, maxdps = mindps
1177                         // then:
1178                         //     maxdamage = mindamage + d
1179                         //     mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1180                         // so the last condition is not needed
1181
1182                         e.fire_damagepersec = totaldamage / totaltime;
1183                         e.fire_endtime = time + totaltime;
1184                         if(totaldamage > 1.2 * mindamage)
1185                         if(e.fire_owner != o)
1186                         {
1187                                 e.fire_deathtype = dt;
1188                                 e.fire_owner = o;
1189                                 e.fire_hitsound = FALSE;
1190                         }
1191                         return totaldamage - mindamage; // can never be negative
1192                 }
1193                 else
1194                         return 0;
1195         }
1196         else
1197         {
1198                 e.fire_damagepersec = dps;
1199                 e.fire_endtime = time + t;
1200                 e.fire_deathtype = dt;
1201                 e.fire_owner = o;
1202                 e.fire_hitsound = FALSE;
1203                 return d;
1204         }
1205 }
1206
1207 void Fire_ApplyDamage(entity e)
1208 {
1209         float t, d, hi, ty;
1210
1211         if not(Fire_IsBurning(e))
1212                 return;
1213
1214         // water and slime stop fire
1215         if(e.waterlevel)
1216         if(e.watertype != CONTENT_LAVA)
1217                 e.fire_endtime = 0;
1218
1219         t = min(frametime, e.fire_endtime - time);
1220         d = e.fire_damagepersec * t;
1221
1222         hi = e.fire_owner.hitsound;
1223         ty = e.fire_owner.typehitsound;
1224         Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1225         if(e.fire_hitsound && e.fire_owner)
1226         {
1227                 e.fire_owner.hitsound = hi;
1228                 e.fire_owner.typehitsound = ty;
1229         }
1230         e.fire_hitsound = TRUE;
1231
1232         Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1233
1234         if not(IS_INDEPENDENT_PLAYER(e))
1235         FOR_EACH_PLAYER(other) if(e != other)
1236         {
1237                 if(other.classname == "player")
1238                 if(other.deadflag == DEAD_NO)
1239                 if not(IS_INDEPENDENT_PLAYER(other))
1240                 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1241                 {
1242                         t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1243                         d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1244                         Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1245                 }
1246         }
1247 }
1248
1249 void Fire_ApplyEffect(entity e)
1250 {
1251         if(Fire_IsBurning(e))
1252                 e.effects |= EF_FLAME;
1253         else
1254                 e.effects &~= EF_FLAME;
1255 }
1256
1257 void fireburner_think()
1258 {
1259         // for players, this is done in the regular loop
1260         if(wasfreed(self.owner))
1261         {
1262                 remove(self);
1263                 return;
1264         }
1265         Fire_ApplyEffect(self.owner);
1266         if(!Fire_IsBurning(self.owner))
1267         {
1268                 self.owner.fire_burner = world;
1269                 remove(self);
1270                 return;
1271         }
1272         Fire_ApplyDamage(self.owner);
1273         self.nextthink = time;
1274 }