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