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