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