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