]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/g_damage.qc
Use a different way to check distance and dragging requirements. This fixes a bug...
[xonotic/xonotic-data.pk3dir.git] / 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 float checkrules_firstblood;
45
46 float yoda;
47 float damage_goodhits;
48 float damage_gooddamage;
49 float headshot;
50 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
51
52 .float dmg_team;
53 .float teamkill_complain;
54 .float teamkill_soundtime;
55 .entity teamkill_soundsource;
56 .entity pusher;
57 .float taunt_soundtime;
58
59
60 float IsDifferentTeam(entity a, entity b)
61 {
62         if(teamplay)
63         {
64                 if(a.team == b.team)
65                         return 0;
66         }
67         else
68         {
69                 if(a == b)
70                         return 0;
71         }
72         return 1;
73 }
74
75 float IsFlying(entity a)
76 {
77         if(a.flags & FL_ONGROUND)
78                 return 0;
79         if(a.waterlevel >= WATERLEVEL_SWIMMING)
80                 return 0;
81         traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
82         if(trace_fraction < 1)
83                 return 0;
84         return 1;
85 }
86
87 vector GetHeadshotMins(entity targ)
88 {
89         return '-0.5 0 0' * PL_HEAD_x + '0 -0.5 0' * PL_HEAD_y + '0 0 1' * (targ.maxs_z - PL_HEAD_z);
90 }
91 vector GetHeadshotMaxs(entity targ)
92 {
93         return '0.5 0 0' * PL_HEAD_x + '0 0.5 0' * PL_HEAD_y + '0 0 1' * targ.maxs_z;
94 }
95
96 void UpdateFrags(entity player, float f)
97 {
98         PlayerTeamScore_AddScore(player, f);
99 }
100
101 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
102 void W_SwitchWeapon_Force(entity e, float w);
103 void GiveFrags (entity attacker, entity targ, float f, float deathtype)
104 {
105         float w;
106
107         // TODO route through PlayerScores instead
108         if(gameover) return;
109
110         if(f < 0)
111         {
112                 if(targ == attacker)
113                 {
114                         // suicide
115                         PlayerScore_Add(attacker, SP_SUICIDES, 1);
116                 }
117                 else
118                 {
119                         // teamkill
120                         PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
121                 }
122         }
123         else
124         {
125                 // regular frag
126                 PlayerScore_Add(attacker, SP_KILLS, 1);
127                 if(targ.playerid)
128                         PlayerStats_Event(attacker, sprintf("kills-%d", targ.playerid), 1);
129         }
130
131         PlayerScore_Add(targ, SP_DEATHS, 1);
132
133         if(g_arena || g_ca)
134                 if(autocvar_g_arena_roundbased)
135                         return;
136
137         if(targ != attacker) // not for suicides
138         if(g_weaponarena_random)
139         {
140                 // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
141                 float culprit;
142                 culprit = DEATH_WEAPONOF(deathtype);
143                 if(!culprit || !(attacker.weapons & W_WeaponBit(culprit)))
144                         culprit = attacker.weapon;
145
146                 if(g_weaponarena_random_with_laser && culprit == WEPBIT_LASER)
147                 {
148                         // no exchange
149                 }
150                 else
151                 {
152                         if(inWarmupStage)
153                                 w = warmup_start_weapons;
154                         else
155                                 w = start_weapons;
156
157                         // all others (including the culprit): remove
158                         w &~= attacker.weapons;
159
160                         // among the remaining ones, choose one by random
161                         w = randombits(w, 1, FALSE);
162                         if(w)
163                         {
164                                 attacker.weapons |= w;
165                                 attacker.weapons &~= W_WeaponBit(culprit);
166                         }
167                 }
168
169                 // after a frag, choose another random weapon set
170                 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
171                         W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
172         }
173
174         // FIXME fix the mess this is (we have REAL points now!)
175         entity oldself;
176         oldself = self;
177         self = attacker;
178         frag_attacker = attacker;
179         frag_target = targ;
180         frag_score = f;
181         if(MUTATOR_CALLHOOK(GiveFragsForKill))
182         {
183                 f = frag_score;
184                 self = oldself;
185         }
186         else
187         {
188                 self = oldself;
189                 if(g_runematch)
190                 {
191                         f = RunematchHandleFrags(attacker, targ, f);
192                 }
193                 else if(g_lms)
194                 {
195                         // remove a life
196                         float tl;
197                         tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
198                         if(tl < lms_lowest_lives)
199                                 lms_lowest_lives = tl;
200                         if(tl <= 0)
201                         {
202                                 if(!lms_next_place)
203                                         lms_next_place = player_count;
204                                 else
205                                         lms_next_place = min(lms_next_place, player_count);
206                                 PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
207                                 --lms_next_place;
208                         }
209                         f = 0;
210                 }
211                 else if(g_ctf)
212                 {
213                         if(g_ctf_ignore_frags)
214                                 f = 0;
215                 }
216         }
217
218         attacker.totalfrags += f;
219
220         if(f)
221                 UpdateFrags(attacker, f);
222 }
223
224 string AppendItemcodes(string s, entity player)
225 {
226         float w;
227         w = player.weapon;
228         //if(w == 0)
229         //      w = player.switchweapon;
230         if(w == 0)
231                 w = player.cnt; // previous weapon!
232         s = strcat(s, ftos(w));
233         if(time < player.strength_finished)
234                 s = strcat(s, "S");
235         if(time < player.invincible_finished)
236                 s = strcat(s, "I");
237         if(player.flagcarried != world)
238                 s = strcat(s, "F");
239         if(player.BUTTON_CHAT)
240                 s = strcat(s, "T");
241         if(player.kh_next)
242                 s = strcat(s, "K");
243         if(player.runes)
244                 s = strcat(s, "|", ftos(player.runes));
245         return s;
246 }
247
248 void LogDeath(string mode, float deathtype, entity killer, entity killed)
249 {
250         string s;
251         if(!autocvar_sv_eventlog)
252                 return;
253         s = strcat(":kill:", mode);
254         s = strcat(s, ":", ftos(killer.playerid));
255         s = strcat(s, ":", ftos(killed.playerid));
256         s = strcat(s, ":type=", ftos(deathtype));
257         s = strcat(s, ":items=");
258         s = AppendItemcodes(s, killer);
259         if(killed != killer)
260         {
261                 s = strcat(s, ":victimitems=");
262                 s = AppendItemcodes(s, killed);
263         }
264         GameLogEcho(s);
265 }
266
267 void Send_KillNotification (string s1, string s2, string s3, float msg, float type)
268 {
269         WriteByte(MSG_ALL, SVC_TEMPENTITY);
270         WriteByte(MSG_ALL, TE_CSQC_KILLNOTIFY);
271         WriteString(MSG_ALL, s1);
272         WriteString(MSG_ALL, s2);
273         WriteString(MSG_ALL, s3);
274         WriteShort(MSG_ALL, msg);
275         WriteByte(MSG_ALL, type);
276 }
277
278 // Function is used to send a generic centerprint whose content CSQC gets to decide (gentle version or not in the below cases)
279 void Send_CSQC_KillCenterprint(entity e, string s1, string s2, float msg, float type)
280 {
281         if (clienttype(e) == CLIENTTYPE_REAL)
282         {
283                 msg_entity = e;
284                 WRITESPECTATABLE_MSG_ONE({
285                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
286                         WriteByte(MSG_ONE, TE_CSQC_KILLCENTERPRINT);
287                         WriteString(MSG_ONE, s1);
288                         WriteString(MSG_ONE, s2);
289                         WriteShort(MSG_ONE, msg);
290                         WriteByte(MSG_ONE, type);
291                 });
292         }
293 }
294
295 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
296 {
297         string  s, a, msg;
298         float w, type;
299
300         if (targ.classname == "player")
301         {
302                 s = targ.netname;
303                 a = attacker.netname;
304
305                 if (targ == attacker) // suicides
306                 {
307                         if (deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
308                                 msg = ColoredTeamName(targ.team); // TODO: check if needed?
309             if(!g_cts) // no "killed your own dumb self" message in CTS
310                 Send_CSQC_KillCenterprint(targ, msg, "", deathtype, MSG_SUICIDE);
311
312                         if(deathtype != DEATH_TEAMCHANGE && deathtype != DEATH_QUIET)
313                         {
314                                 LogDeath("suicide", deathtype, targ, targ);
315                                 GiveFrags(attacker, targ, -1, deathtype);
316                         }
317
318                         if (targ.killcount > 2)
319                                 msg = ftos(targ.killcount);
320                         if(teamplay && deathtype == DEATH_MIRRORDAMAGE)
321                         {
322                                 if(attacker.team == COLOR_TEAM1)
323                                         deathtype = KILL_TEAM_RED;
324                                 else
325                                         deathtype = KILL_TEAM_BLUE;
326                         }
327
328                         Send_KillNotification(s, msg, ftos(w), deathtype, MSG_SUICIDE);
329                 }
330                 else if (attacker.classname == "player")
331                 {
332                         if(!IsDifferentTeam(attacker, targ))
333                         {
334                                 if(attacker.team == COLOR_TEAM1)
335                                         type = KILL_TEAM_RED;
336                                 else
337                                         type = KILL_TEAM_BLUE;
338
339                                 GiveFrags(attacker, targ, -1, deathtype);
340
341                                 Send_CSQC_KillCenterprint(attacker, s, "", type, MSG_KILL);
342
343                                 if (targ.killcount > 2) {
344                                         msg = ftos(targ.killcount);
345                                 }
346
347                                 if (attacker.killcount > 2) {
348                                         msg = ftos(attacker.killcount);
349                                         type = KILL_TEAM_SPREE;
350                                 }
351                                 Send_KillNotification(a, s, msg, type, MSG_KILL);
352
353                                 attacker.killcount = 0;
354
355                                 LogDeath("tk", deathtype, attacker, targ);
356                         }
357                         else
358                         {
359                                 if (!checkrules_firstblood)
360                                 {
361                                         checkrules_firstblood = TRUE;
362                                         Send_KillNotification(a, "", "", KILL_FIRST_BLOOD, MSG_KILL);
363                                         // TODO: make these print a newline if they dont
364                                         Send_CSQC_KillCenterprint(attacker, "", "", KILL_FIRST_BLOOD, MSG_KILL);
365                                         Send_CSQC_KillCenterprint(targ, "", "", KILL_FIRST_VICTIM, MSG_KILL);
366                                         PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_FIRSTBLOOD, 1);
367                                         PlayerStats_Event(targ, PLAYERSTATS_ACHIEVEMENT_FIRSTVICTIM, 1);
368                                 }
369
370                                 if((autocvar_sv_fragmessage_information_typefrag) && (targ.BUTTON_CHAT)) {
371                                         Send_CSQC_KillCenterprint(attacker, s, GetAdvancedDeathReports(targ), KILL_TYPEFRAG, MSG_KILL);
372                                         Send_CSQC_KillCenterprint(targ, a, GetAdvancedDeathReports(attacker), KILL_TYPEFRAGGED, MSG_KILL);
373                                 } else {
374                                         Send_CSQC_KillCenterprint(attacker, s, GetAdvancedDeathReports(targ), KILL_FRAG, MSG_KILL);
375                                         Send_CSQC_KillCenterprint(targ, a, GetAdvancedDeathReports(attacker), KILL_FRAGGED, MSG_KILL);
376                                 }
377
378                                 attacker.taunt_soundtime = time + 1;
379
380                                 // TODO: fix this?
381                                 if (deathtype == DEATH_CUSTOM)
382                                         msg = deathmessage;
383                                 else
384                                         msg = inflictor.message2;
385
386                                 if(strstrofs(msg, "%", 0) < 0)
387                                         msg = strcat("%s ", msg, " by %s");
388
389                                 Send_KillNotification(a, s, msg, deathtype, MSG_KILL);
390
391                                 if(g_ctf && targ.flagcarried)
392                                 {
393                                         UpdateFrags(attacker, ctf_score_value("score_kill"));
394                                         PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
395                                         GiveFrags(attacker, targ, 0, deathtype); // for logging
396                                 }
397                                 else
398                                         GiveFrags(attacker, targ, 1, deathtype);
399
400                                 if (targ.killcount > 2) {
401                                         Send_KillNotification(s, ftos(targ.killcount), a, KILL_END_SPREE, MSG_SPREE);
402                                 }
403
404                                 attacker.killcount = attacker.killcount + 1;
405
406                                 if (attacker.killcount > 2) {
407                                         Send_KillNotification(a, ftos(attacker.killcount), "", KILL_SPREE, MSG_SPREE);
408                                 }
409                                 else if (attacker.killcount == 3)
410                                 {
411                                         Send_KillNotification(a, "", "", KILL_SPREE_3, MSG_SPREE);
412                                         AnnounceTo(attacker, "03kills");
413                                         PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3, 1);
414                                 }
415                                 else if (attacker.killcount == 5)
416                                 {
417                                         Send_KillNotification(a, "", "", KILL_SPREE_5, MSG_SPREE);
418                                         AnnounceTo(attacker, "05kills");
419                                         PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5, 1);
420                                 }
421                                 else if (attacker.killcount == 10)
422                                 {
423                                         Send_KillNotification(a, "", "", KILL_SPREE_10, MSG_SPREE);
424                                         AnnounceTo(attacker, "10kills");
425                                         PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_10, 1);
426                                 }
427                                 else if (attacker.killcount == 15)
428                                 {
429                                         Send_KillNotification(a, "", "", KILL_SPREE_15, MSG_SPREE);
430                                         AnnounceTo(attacker, "15kills");
431                                         PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_15, 1);
432                                 }
433                                 else if (attacker.killcount == 20)
434                                 {
435                                         Send_KillNotification(a, "", "", KILL_SPREE_20, MSG_SPREE);
436                                         AnnounceTo(attacker, "20kills");
437                                         PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_20, 1);
438                                 }
439                                 else if (attacker.killcount == 25)
440                                 {
441                                         Send_KillNotification(a, "", "", KILL_SPREE_25, MSG_SPREE);
442                                         AnnounceTo(attacker, "25kills");
443                                         PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_25, 1);
444                                 }
445                                 else if (attacker.killcount == 30)
446                                 {
447                                         Send_KillNotification(a, "", "", KILL_SPREE_30, MSG_SPREE);
448                                         AnnounceTo(attacker, "30kills");
449                                         PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_30, 1);
450                                 }
451                                 LogDeath("frag", deathtype, attacker, targ);
452                         }
453                 }
454                 else
455                 {
456                         Send_CSQC_KillCenterprint(targ, "", "", deathtype, MSG_KILL_ACTION);
457                         if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
458                                 msg = inflictor.message;
459                         else if (deathtype == DEATH_CUSTOM)
460                                 msg = deathmessage;
461                         if(strstrofs(msg, "%", 0) < 0)
462                                 msg = strcat("%s ", msg);
463
464                         GiveFrags(targ, targ, -1, deathtype);
465                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
466                                 AnnounceTo(targ, "botlike");
467                                 PlayerStats_Event(attacker, PLAYERSTATS_ACHIEVEMENT_BOTLIKE, 1);
468                         }
469                         Send_KillNotification(s, msg, "", deathtype, MSG_KILL_ACTION);
470
471                         if (targ.killcount > 2)
472                                 Send_KillNotification(s, ftos(targ.killcount), "", 0, MSG_KILL_ACTION_SPREE);
473
474                         LogDeath("accident", deathtype, targ, targ);
475                 }
476
477                 targ.death_origin = targ.origin;
478                 if(targ != attacker)
479                         targ.killer_origin = attacker.origin;
480
481                 // FIXME: this should go in PutClientInServer
482                 if (targ.killcount)
483                         targ.killcount = 0;
484         }
485 }
486
487 // these are updated by each Damage call for use in button triggering and such
488 entity damage_targ;
489 entity damage_inflictor;
490 entity damage_attacker;
491
492 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
493 {
494         float mirrordamage;
495         float mirrorforce;
496         float teamdamage0;
497         entity attacker_save;
498         mirrordamage = 0;
499         mirrorforce = 0;
500
501         if (gameover || targ.killcount == -666)
502                 return;
503
504         entity oldself;
505         oldself = self;
506         self = targ;
507         damage_targ = targ;
508         damage_inflictor = inflictor;
509         damage_attacker = attacker;
510                 attacker_save = attacker;
511
512         if(targ.classname == "player")
513                 if(targ.hook)
514                         if(targ.hook.aiment)
515                                 if(targ.hook.aiment == attacker)
516                                         RemoveGrapplingHook(targ); // STOP THAT, you parasite!
517
518         // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
519         if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
520         {
521                 if(targ.classname == "player")
522                         if not(IsDifferentTeam(targ, attacker))
523                         {
524                                 self = oldself;
525                                 return;
526                         }
527         }
528
529         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE || deathtype == DEATH_QUIET)
530         {
531                 // These are ALWAYS lethal
532                 // No damage modification here
533                 // Instead, prepare the victim for his death...
534                 targ.armorvalue = 0;
535                 targ.spawnshieldtime = 0;
536                 targ.health = 0.9; // this is < 1
537                 targ.flags -= targ.flags & FL_GODMODE;
538                 damage = 100000;
539         }
540         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
541         {
542                 // no processing
543         }
544         else
545         {
546                 /*
547                 skill based bot damage? gtfo. (tZork)
548                 if (targ.classname == "player")
549                 if (attacker.classname == "player")
550                 if (!targ.isbot)
551                 if (attacker.isbot)
552                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
553         */
554         
555                 // nullify damage if teamplay is on
556                 if(deathtype != DEATH_TELEFRAG)
557                 if(attacker.classname == "player")
558                 {
559                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
560                         {
561                                 damage = 0;
562                                 force = '0 0 0';
563                         }
564                         else if(!IsDifferentTeam(attacker, targ))
565                         {
566                                 if(autocvar_teamplay_mode == 1)
567                                         damage = 0;
568                                 else if(attacker != targ)
569                                 {
570                                         if(autocvar_teamplay_mode == 3)
571                                                 damage = 0;
572                                         else if(autocvar_teamplay_mode == 4)
573                                         {
574                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
575                                                 {
576                                                         teamdamage0 = max(attacker.dmg_team, autocvar_g_teamdamage_threshold);
577                                                         attacker.dmg_team = attacker.dmg_team + damage;
578                                                         if(attacker.dmg_team > teamdamage0 && !g_ca)
579                                                                 mirrordamage = autocvar_g_mirrordamage * (attacker.dmg_team - teamdamage0);
580                                                         mirrorforce = autocvar_g_mirrordamage * vlen(force);
581                                                         if(g_minstagib)
582                                                         {
583                                                                 if(autocvar_g_friendlyfire == 0)
584                                                                         damage = 0;
585                                                         }
586                                                         else if(g_ca)
587                                                                 damage = 0;
588                                                         else
589                                                                 damage = autocvar_g_friendlyfire * damage;
590                                                         // mirrordamage will be used LATER
591
592                                                         if(autocvar_g_mirrordamage_virtual)
593                                                         {
594                                                                 vector v;
595                                                                 v = healtharmor_applydamage(attacker.armorvalue, autocvar_g_balance_armor_blockpercent, mirrordamage);
596                                                                 attacker.dmg_take += v_x;
597                                                                 attacker.dmg_save += v_y;
598                                                                 attacker.dmg_inflictor = inflictor;
599                                                                 mirrordamage = 0;
600                                                                 mirrorforce = 0;
601                                                         }
602
603                                                         if(autocvar_g_friendlyfire_virtual)
604                                                         {
605                                                                 vector v;
606                                                                 v = healtharmor_applydamage(targ.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
607                                                                 targ.dmg_take += v_x;
608                                                                 targ.dmg_save += v_y;
609                                                                 targ.dmg_inflictor = inflictor;
610                                                                 damage = 0;
611                                 if(!autocvar_g_friendlyfire_virtual_force)
612                                     force = '0 0 0';
613                                                         }
614                                                 }
615                                                 else
616                                                         damage = 0;
617                                         }
618                                 }
619                         }
620                 }
621
622                 if(targ.classname == "player")
623                 if(attacker.classname == "player")
624                 if(attacker != targ)
625                 {
626                         targ.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
627                         attacker.lms_traveled_distance = autocvar_g_lms_campcheck_distance;
628                 }
629
630                 if(targ.classname == "player")
631                 if (g_minstagib)
632                 {
633                         if ((deathtype == DEATH_FALL)  ||
634                                 (deathtype == DEATH_DROWN) ||
635                                 (deathtype == DEATH_SLIME) ||
636                                 (deathtype == DEATH_LAVA)  ||
637                                 (!DEATH_ISWEAPON(deathtype, WEP_LASER) && damage > 0 && damage < 100))
638                         {
639                                 self = oldself;
640                                 return;
641                         }
642                         if(damage > 0)
643                             damage = 10000;
644                         if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
645                         {
646                                 targ.armorvalue -= 1;
647                                 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue)));
648                                 damage = 0;
649                                 targ.hitsound += 1;
650                                 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
651                         }
652                         if (DEATH_ISWEAPON(deathtype, WEP_LASER))
653                         {
654                                 damage = 0;
655                                 mirrordamage = 0;
656                                 if (targ != attacker)
657                                 {
658                                         if ((targ.health >= 1) && (targ.classname == "player"))
659                                                 centerprint(attacker, "Secondary fire inflicts no damage!");
660                                         force = '0 0 0';
661                                         // keep mirrorforce
662                                         attacker = targ;
663                                 }
664                         }
665                 }
666
667                 if not(DEATH_ISSPECIAL(deathtype))
668                 {
669                         damage *= g_weapondamagefactor;
670                         mirrordamage *= g_weapondamagefactor;
671                         force = force * g_weaponforcefactor;
672                         mirrorforce *= g_weaponforcefactor;
673                 }
674                 
675                 // should this be changed at all? If so, in what way?
676                 frag_attacker = attacker;
677                 frag_target = targ;
678                 frag_damage = damage;
679                 frag_force = force;
680         frag_deathtype = deathtype;
681                 MUTATOR_CALLHOOK(PlayerDamage_Calculate);
682                 damage = frag_damage;
683                 force = frag_force;
684                 
685                 // apply strength multiplier
686                 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
687                 {
688                         if(targ == attacker)
689                         {
690                                 damage = damage * autocvar_g_balance_powerup_strength_selfdamage;
691                                 force = force * autocvar_g_balance_powerup_strength_selfforce;
692                         }
693                         else
694                         {
695                                 damage = damage * autocvar_g_balance_powerup_strength_damage;
696                                 force = force * autocvar_g_balance_powerup_strength_force;
697                         }
698                 }
699
700                 // apply invincibility multiplier
701                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
702                         damage = damage * autocvar_g_balance_powerup_invincible_takedamage;
703
704                 if (targ == attacker)
705                 {
706                         if(g_ca || (g_cts && !autocvar_g_cts_selfdamage))
707                                 damage = 0;
708                         else
709                                 damage = damage * autocvar_g_balance_selfdamagepercent; // Partial damage if the attacker hits himself
710                 }
711
712                 // CTF: reduce damage/force
713                 if(g_ctf)
714                 if(targ == attacker)
715                 if(targ.flagcarried)
716                 {
717                         damage = damage * autocvar_g_ctf_flagcarrier_selfdamage;
718                         force = force * autocvar_g_ctf_flagcarrier_selfforce;
719                 }
720
721                 if(g_runematch)
722                 {
723                         // apply strength rune
724                         if (attacker.runes & RUNE_STRENGTH)
725                         {
726                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
727                                 {
728                                         damage = damage * autocvar_g_balance_rune_strength_combo_damage;
729                                         force = force * autocvar_g_balance_rune_strength_combo_force;
730                                 }
731                                 else
732                                 {
733                                         damage = damage * autocvar_g_balance_rune_strength_damage;
734                                         force = force * autocvar_g_balance_rune_strength_force;
735                                 }
736                         }
737                         else if (attacker.runes & CURSE_WEAK)
738                         {
739                                 damage = damage * autocvar_g_balance_curse_weak_damage;
740                                 force = force * autocvar_g_balance_curse_weak_force;
741                         }
742
743                         // apply defense rune
744                         if (targ.runes & RUNE_DEFENSE)
745                         {
746                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
747                                         damage = damage * autocvar_g_balance_rune_defense_combo_takedamage;
748                                 else
749                                         damage = damage * autocvar_g_balance_rune_defense_takedamage;
750                         }
751                         else if (targ.runes & CURSE_VULNER)
752                                 damage = damage * autocvar_g_balance_curse_vulner_takedamage;
753                 }
754
755                 // count the damage
756                 if(attacker)
757                 if(!targ.deadflag)
758                 if(targ.takedamage == DAMAGE_AIM)
759                 if(targ != attacker)
760                 {
761                         if(damage_headshotbonus > 0)
762                         {
763                                 if(targ.classname == "player")
764                                 {
765                                         // HEAD SHOT:
766                                         // find height of hit on player axis
767                                         // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
768                                         vector headmins, headmaxs, org;
769                                         org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
770                                         headmins = org + GetHeadshotMins(targ);
771                                         headmaxs = org + GetHeadshotMaxs(targ);
772                                         if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
773                                         {
774                                                 deathtype |= HITTYPE_HEADSHOT;
775                                         }
776                                 }
777                                 else if(targ.classname == "turret_head")
778                                 {
779                                         deathtype |= HITTYPE_HEADSHOT;
780                                 }
781                                 if(deathtype & HITTYPE_HEADSHOT)
782                                         damage *= 1 + damage_headshotbonus;
783                         }
784
785                         entity victim;
786                         if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner)
787                                 victim = targ.owner;
788                         else
789                                 victim = targ;
790
791                         if(victim.classname == "player" || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
792                         {
793                                 if(IsDifferentTeam(victim, attacker))
794                                 {
795                                         if(damage > 0)
796                                         {
797                                                 if(deathtype != DEATH_FIRE)
798                                                 {
799                                                         if(victim.BUTTON_CHAT)
800                                                                 attacker.typehitsound += 1;
801                                                         else
802                                                                 attacker.hitsound += 1;
803                                                 }
804
805                                                 damage_goodhits += 1;
806                                                 damage_gooddamage += damage;
807
808                                                 if not(DEATH_ISSPECIAL(deathtype))
809                                                 {
810                                                         if(targ.classname == "player") // don't do this for vehicles
811                                                         if(!g_minstagib)
812                                                         if(IsFlying(victim))
813                                                                 yoda = 1;
814
815                                                         if(g_minstagib)
816                                                         if(victim.items & IT_STRENGTH)
817                                                                 yoda = 1;
818
819                                                         if(deathtype & HITTYPE_HEADSHOT)
820                                                                 headshot = 1;
821                                                 }
822                                                 if(g_ca)
823                                                         PlayerScore_Add(attacker, SP_SCORE, damage * autocvar_g_ca_damage2score_multiplier);
824                                         }
825                                 }
826                                 else
827                                 {
828                                         if(deathtype != DEATH_FIRE)
829                                         {
830                                                 attacker.typehitsound += 1;
831                                         }
832                                         if(mirrordamage > 0)
833                                                 if(time > attacker.teamkill_complain)
834                                                 {
835                                                         attacker.teamkill_complain = time + 5;
836                                                         attacker.teamkill_soundtime = time + 0.4;
837                                                         attacker.teamkill_soundsource = targ;
838                                                 }
839                                 }
840                         }
841                 }
842         }
843
844         // apply push
845         if (self.damageforcescale)
846         if (vlen(force))
847         if (self.classname != "player" || time >= self.spawnshieldtime || g_midair)
848         {
849                 self.velocity = self.velocity + damage_explosion_calcpush(self.damageforcescale * force, self.velocity, autocvar_g_balance_damagepush_speedfactor);
850                 self.flags &~= FL_ONGROUND;
851                 UpdateCSQCProjectile(self);
852         }
853         // apply damage
854         if (damage != 0 || (self.damageforcescale && vlen(force)))
855         if (self.event_damage)
856                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
857         self = oldself;
858
859         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
860         {
861                 if(g_runematch)
862                 {
863                         if (attacker.runes & RUNE_VAMPIRE)
864                         {
865                         // apply vampire rune
866                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
867                                 {
868                                         //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb;
869                                         attacker.health = bound(
870                                                 autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 40
871                                                 attacker.health + damage * autocvar_g_balance_rune_vampire_combo_absorb,
872                                                 autocvar_g_balance_rune_vampire_maxhealth);     // LA: was 1000, now 500
873                                 }
874                                 else
875                                 {
876                                         //attacker.health = attacker.health + damage * autocvar_g_balance_rune_vampire_absorb;
877                                         attacker.health = bound(
878                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
879                                                                                         // empathy won't let you gain health in the same way...
880                                                 attacker.health + damage * autocvar_g_balance_rune_vampire_absorb,
881                                                 autocvar_g_balance_rune_vampire_maxhealth);     // LA: was 1000, now 500
882                                         }
883                         }
884                         // apply empathy curse
885                         else if (attacker.runes & CURSE_EMPATHY)
886                         {
887                                 attacker.health = bound(
888                                         autocvar_g_balance_curse_empathy_minhealth, // LA: was 3, now 20
889                                         attacker.health + damage * autocvar_g_balance_curse_empathy_takedamage,
890                                         attacker.health);
891                         }
892                 }
893         }
894
895         // apply mirror damage if any
896         if(mirrordamage > 0 || mirrorforce > 0)
897         {
898                 attacker = attacker_save;
899                 if(g_minstagib)
900                 if(mirrordamage > 0)
901                 {
902                         // just lose extra LIVES, don't kill the player for mirror damage
903                         if(attacker.armorvalue > 0)
904                         {
905                                 attacker.armorvalue = attacker.armorvalue - 1;
906                                 centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue)));
907                                 attacker.hitsound += 1;
908                         }
909                         mirrordamage = 0;
910                 }
911
912                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
913                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
914         }
915 }
916
917 float RadiusDamage_running;
918 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
919 // Returns total damage applies to creatures
920 {
921         entity  targ;
922         float   finaldmg;
923         float   power;
924         vector  blastorigin;
925         vector  force;
926         vector  diff;
927         vector  center;
928         vector  nearest;
929         float   total_damage_to_creatures;
930         entity  next;
931         float   tfloordmg;
932         float   tfloorforce;
933
934         float stat_damagedone;
935
936         if(RadiusDamage_running)
937         {
938                 backtrace("RadiusDamage called recursively! Expect stuff to go HORRIBLY wrong.");
939                 return 0;
940         }
941
942         RadiusDamage_running = 1;
943
944         tfloordmg = autocvar_g_throughfloor_damage;
945         tfloorforce = autocvar_g_throughfloor_force;
946
947         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
948         total_damage_to_creatures = 0;
949
950         if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
951         if(DEATH_WEAPONOF(deathtype) != WEP_TUBA) // do not send tuba damage (bandwidth hog)
952         {
953                 force = inflictor.velocity;
954                 if(vlen(force) == 0)
955                         force = '0 0 -1';
956                 else
957                         force = normalize(force);
958                 if(forceintensity >= 0)
959                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
960                 else
961                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
962         }
963
964         stat_damagedone = 0;
965
966         targ = WarpZone_FindRadius (blastorigin, rad, FALSE);
967         while (targ)
968         {
969                 next = targ.chain;
970                 if (targ != inflictor)
971                         if (ignore != targ) if(targ.takedamage)
972                         {
973                                 // LordHavoc: measure distance to nearest point on target (not origin)
974                                 // (this guarentees 100% damage on a touch impact)
975                                 nearest = targ.WarpZone_findradius_nearest;
976                                 diff = targ.WarpZone_findradius_dist;
977                                 // round up a little on the damage to ensure full damage on impacts
978                                 // and turn the distance into a fraction of the radius
979                                 power = 1 - ((vlen (diff) - 2) / rad);
980                                 //bprint(" ");
981                                 //bprint(ftos(power));
982                                 //if (targ == attacker)
983                                 //      print(ftos(power), "\n");
984                                 if (power > 0)
985                                 {
986                                         if (power > 1)
987                                                 power = 1;
988                                         finaldmg = coredamage * power + edgedamage * (1 - power);
989                                         if (finaldmg > 0)
990                                         {
991                                                 float a;
992                                                 float c;
993                                                 float hits;
994                                                 float total;
995                                                 float hitratio;
996                                                 vector hitloc;
997                                                 vector myblastorigin;
998                                                 myblastorigin = WarpZone_TransformOrigin(targ, blastorigin);
999                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1000                                                 // if it's a player, use the view origin as reference
1001                                                 if (targ.classname == "player")
1002                                                         center = targ.origin + targ.view_ofs;
1003                                                 force = normalize(center - myblastorigin);
1004                                                 force = force * (finaldmg / coredamage) * forceintensity;
1005                                                 // test line of sight to multiple positions on box,
1006                                                 // and do damage if any of them hit
1007                                                 hits = 0;
1008                                                 if (targ.classname == "player")
1009                                                         total = ceil(bound(1, finaldmg, 50));
1010                                                 else
1011                                                         total = ceil(bound(1, finaldmg/10, 5));
1012                                                 hitloc = nearest;
1013                                                 c = 0;
1014                                                 while (c < total)
1015                                                 {
1016                                                         //traceline(targ.WarpZone_findradius_findorigin, nearest, MOVE_NOMONSTERS, inflictor);
1017                                                         WarpZone_TraceLine(blastorigin, WarpZone_UnTransformOrigin(targ, nearest), MOVE_NOMONSTERS, inflictor);
1018                                                         if (trace_fraction == 1 || trace_ent == targ)
1019                                                         {
1020                                                                 hits = hits + 1;
1021                                                                 if (hits > 1)
1022                                                                         hitloc = hitloc + nearest;
1023                                                                 else
1024                                                                         hitloc = nearest;
1025                                                         }
1026                                                         nearest_x = targ.origin_x + targ.mins_x + random() * targ.size_x;
1027                                                         nearest_y = targ.origin_y + targ.mins_y + random() * targ.size_y;
1028                                                         nearest_z = targ.origin_z + targ.mins_z + random() * targ.size_z;
1029                                                         c = c + 1;
1030                                                 }
1031                                                 nearest = hitloc * (1 / max(1, hits));
1032                                                 hitratio = (hits / total);
1033                                                 a = bound(0, tfloordmg + (1-tfloordmg) * hitratio, 1);
1034                                                 finaldmg = finaldmg * a;
1035                                                 a = bound(0, tfloorforce + (1-tfloorforce) * hitratio, 1);
1036                                                 force = force * a;
1037
1038                                                 // laser force adjustments :P
1039                                                 if(DEATH_WEAPONOF(deathtype) == WEP_LASER)
1040                                                 {
1041                             if (targ == attacker)
1042                             {
1043                                 vector vel;
1044
1045                                 float force_zscale;
1046                                 float force_velocitybiasramp;
1047                                 float force_velocitybias;
1048
1049                                 force_velocitybiasramp = autocvar_sv_maxspeed;
1050                                 if(deathtype & HITTYPE_SECONDARY)
1051                                 {
1052                                     force_zscale = autocvar_g_balance_laser_secondary_force_zscale;
1053                                     force_velocitybias = autocvar_g_balance_laser_secondary_force_velocitybias;
1054                                 }
1055                                 else
1056                                 {
1057                                     force_zscale = autocvar_g_balance_laser_primary_force_zscale;
1058                                     force_velocitybias = autocvar_g_balance_laser_primary_force_velocitybias;
1059                                 }
1060
1061                                 vel = targ.velocity;
1062                                 vel_z = 0;
1063                                 vel = normalize(vel) * bound(0, vlen(vel) / force_velocitybiasramp, 1) * force_velocitybias;
1064                                 force =
1065                                     vlen(force)
1066                                     *
1067                                     normalize(normalize(force) + vel);
1068
1069                                 force_z *= force_zscale;
1070                             }
1071                             else
1072                             {
1073                                 if(deathtype & HITTYPE_SECONDARY)
1074                                 {
1075                                     force *= autocvar_g_balance_laser_secondary_force_other_scale;
1076                                 }
1077                                 else
1078                                 {
1079                                     force *= autocvar_g_balance_laser_primary_force_other_scale;
1080                                 }
1081                             }
1082                                                 }
1083
1084                                                 //if (targ == attacker)
1085                                                 //{
1086                                                 //      print("hits ", ftos(hits), " / ", ftos(total));
1087                                                 //      print(" finaldmg ", ftos(finaldmg), " force ", vtos(force));
1088                                                 //      print(" (", ftos(a), ")\n");
1089                                                 //}
1090                                                 if(hits || tfloordmg || tfloorforce)
1091                                                 {
1092                                                         if(targ.iscreature)
1093                                                         {
1094                                                                 total_damage_to_creatures += finaldmg;
1095
1096                                                                 if(accuracy_isgooddamage(attacker, targ))
1097                                                                         stat_damagedone += finaldmg;
1098                                                         }
1099
1100                                                         if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1101                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1102                                                         else
1103                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1104                                                 }
1105                                         }
1106                                 }
1107                         }
1108                 targ = next;
1109         }
1110
1111         RadiusDamage_running = 0;
1112
1113         if(!DEATH_ISSPECIAL(deathtype))
1114                 accuracy_add(attacker, DEATH_WEAPONOFWEAPONDEATH(deathtype), 0, min(coredamage, stat_damagedone));
1115
1116         return total_damage_to_creatures;
1117 }
1118
1119 .float fire_damagepersec;
1120 .float fire_endtime;
1121 .float fire_deathtype;
1122 .entity fire_owner;
1123 .float fire_hitsound;
1124 .entity fire_burner;
1125
1126 void fireburner_think();
1127
1128 float Fire_IsBurning(entity e)
1129 {
1130         return (time < e.fire_endtime);
1131 }
1132
1133 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1134 {
1135         float dps;
1136         float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1137
1138         if(e.classname == "player")
1139         {
1140                 if(e.deadflag)
1141                         return -1;
1142         }
1143         else
1144         {
1145                 if(!e.fire_burner)
1146                 {
1147                         // print("adding a fire burner to ", e.classname, "\n");
1148                         e.fire_burner = spawn();
1149                         e.fire_burner.classname = "fireburner";
1150                         e.fire_burner.think = fireburner_think;
1151                         e.fire_burner.nextthink = time;
1152                         e.fire_burner.owner = e;
1153                 }
1154         }
1155
1156         t = max(t, 0.1);
1157         dps = d / t;
1158         if(Fire_IsBurning(e))
1159         {
1160                 mintime = e.fire_endtime - time;
1161                 maxtime = max(mintime, t);
1162
1163                 mindps = e.fire_damagepersec;
1164                 maxdps = max(mindps, dps);
1165
1166                 if(maxtime > mintime || maxdps > mindps)
1167                 {
1168                         mindamage = mindps * mintime;
1169                         maxdamage = mindamage + d;
1170
1171                         // interval [mintime, maxtime] * [mindps, maxdps]
1172                         // intersected with
1173                         // [mindamage, maxdamage]
1174                         // maximum of this!
1175
1176                         if(maxdamage >= maxtime * maxdps)
1177                         {
1178                                 totaltime = maxtime;
1179                                 totaldamage = maxtime * maxdps;
1180
1181                                 // this branch increases totaldamage if either t > mintime, or dps > mindps
1182                         }
1183                         else
1184                         {
1185                                 // maxdamage is inside the interval!
1186                                 // first, try to use mindps; only if this fails, increase dps as needed
1187                                 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1188                                 totaldamage = maxdamage;
1189                                 // can totaldamage / totaltime be >= maxdps?
1190                                 // max(mindps, maxdamage / maxtime) >= maxdps?
1191                                 // we know maxdamage < maxtime * maxdps
1192                                 // so it cannot be
1193
1194                                 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1195                         }
1196
1197                         // total conditions for increasing:
1198                         //     maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1199                         // however:
1200                         //     if maxtime = mintime, maxdps = mindps
1201                         // then:
1202                         //     maxdamage = mindamage + d
1203                         //     mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1204                         // so the last condition is not needed
1205
1206                         e.fire_damagepersec = totaldamage / totaltime;
1207                         e.fire_endtime = time + totaltime;
1208                         if(totaldamage > 1.2 * mindamage)
1209                         {
1210                                 e.fire_deathtype = dt;
1211                                 if(e.fire_owner != o)
1212                                 {
1213                                         e.fire_owner = o;
1214                                         e.fire_hitsound = FALSE;
1215                                 }
1216                         }
1217                         if(accuracy_isgooddamage(o, e))
1218                                 accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, max(0, totaldamage - mindamage));
1219                         return max(0, totaldamage - mindamage); // can never be negative, but to make sure
1220                 }
1221                 else
1222                         return 0;
1223         }
1224         else
1225         {
1226                 e.fire_damagepersec = dps;
1227                 e.fire_endtime = time + t;
1228                 e.fire_deathtype = dt;
1229                 e.fire_owner = o;
1230                 e.fire_hitsound = FALSE;
1231                 if(accuracy_isgooddamage(o, e))
1232                         accuracy_add(o, DEATH_WEAPONOFWEAPONDEATH(dt), 0, d);
1233                 return d;
1234         }
1235 }
1236
1237 void Fire_ApplyDamage(entity e)
1238 {
1239         float t, d, hi, ty;
1240         entity o;
1241
1242         if not(Fire_IsBurning(e))
1243                 return;
1244
1245         for(t = 0, o = e.owner; o.owner && t < 16; o = o.owner, ++t);
1246         if(clienttype(o) == CLIENTTYPE_NOTACLIENT)
1247                 o = e.fire_owner;
1248
1249         // water and slime stop fire
1250         if(e.waterlevel)
1251         if(e.watertype != CONTENT_LAVA)
1252                 e.fire_endtime = 0;
1253
1254         // ice stops fire
1255         if(e.freezetag_frozen)
1256                 e.fire_endtime = 0;
1257
1258         t = min(frametime, e.fire_endtime - time);
1259         d = e.fire_damagepersec * t;
1260
1261         hi = e.fire_owner.hitsound;
1262         ty = e.fire_owner.typehitsound;
1263         Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1264         if(e.fire_hitsound && e.fire_owner)
1265         {
1266                 e.fire_owner.hitsound = hi;
1267                 e.fire_owner.typehitsound = ty;
1268         }
1269         e.fire_hitsound = TRUE;
1270
1271         if not(IS_INDEPENDENT_PLAYER(e))
1272         FOR_EACH_PLAYER(other) if(e != other)
1273         {
1274                 if(other.classname == "player")
1275                 if(other.deadflag == DEAD_NO)
1276                 if not(IS_INDEPENDENT_PLAYER(other))
1277                 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1278                 {
1279                         t = autocvar_g_balance_firetransfer_time * (e.fire_endtime - time);
1280                         d = autocvar_g_balance_firetransfer_damage * e.fire_damagepersec * t;
1281                         Fire_AddDamage(other, o, d, t, DEATH_FIRE);
1282                 }
1283         }
1284 }
1285
1286 void Fire_ApplyEffect(entity e)
1287 {
1288         if(Fire_IsBurning(e))
1289                 e.effects |= EF_FLAME;
1290         else
1291                 e.effects &~= EF_FLAME;
1292 }
1293
1294 void fireburner_think()
1295 {
1296         // for players, this is done in the regular loop
1297         if(wasfreed(self.owner))
1298         {
1299                 remove(self);
1300                 return;
1301         }
1302         Fire_ApplyEffect(self.owner);
1303         if(!Fire_IsBurning(self.owner))
1304         {
1305                 self.owner.fire_burner = world;
1306                 remove(self);
1307                 return;
1308         }
1309         Fire_ApplyDamage(self.owner);
1310         self.nextthink = time;
1311 }