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