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