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