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