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