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