]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
do not switch weapon after suicide (respawn will do anyway)
[divverent/nexuiz.git] / data / 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 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
45
46 float checkrules_firstblood;
47
48 float yoda;
49 float damage_goodhits;
50 float damage_gooddamage;
51 float headshot;
52 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
53
54 .float dmg_team;
55 .float teamkill_complain;
56 .float teamkill_soundtime;
57 .entity teamkill_soundsource;
58 .entity pusher;
59 .float taunt_soundtime;
60
61
62 float IsDifferentTeam(entity a, entity b)
63 {
64         if(teams_matter)
65         {
66                 if(a.team == b.team)
67                         return 0;
68         }
69         else
70         {
71                 if(a == b)
72                         return 0;
73         }
74         return 1;
75 }
76
77 float IsFlying(entity a)
78 {
79         if(a.flags & FL_ONGROUND)
80                 return 0;
81         if(a.waterlevel >= WATERLEVEL_SWIMMING)
82                 return 0;
83         traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
84         if(trace_fraction < 1)
85                 return 0;
86         return 1;
87 }
88
89 void UpdateFrags(entity player, float f)
90 {
91         PlayerTeamScore_AddScore(player, f);
92 }
93
94 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
95 void W_SwitchWeapon_Force(entity e, float w);
96 void GiveFrags (entity attacker, entity targ, float f)
97 {
98         // TODO route through PlayerScores instead
99         if(gameover) return;
100
101         if(f < 0)
102         {
103                 if(targ == attacker)
104                 {
105                         // suicide
106                         PlayerScore_Add(attacker, SP_SUICIDES, 1);
107                 }
108                 else
109                 {
110                         // teamkill
111                         PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
112                 }
113         }
114         else
115         {
116                 // regular frag
117                 PlayerScore_Add(attacker, SP_KILLS, 1);
118         }
119
120         PlayerScore_Add(targ, SP_DEATHS, 1);
121
122         if(g_arena)
123                 if(cvar("g_arena_roundbased"))
124                         return;
125
126         if(targ != attacker) // not for suicides
127         if(g_weaponarena_random)
128         {
129                 // after a frag, choose another random weapon set
130                 attacker.weapons = randombits((inWarmupStage ? warmup_start_weapons : start_weapons), g_weaponarena_random);
131                 if not(attacker.weapons & W_WeaponBit(attacker.weapon))
132                         W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker));
133         }
134
135         // FIXME fix the mess this is (we have REAL points now!)
136         if(g_runematch)
137         {
138                 f = RunematchHandleFrags(attacker, targ, f);
139         }
140         else if(g_keyhunt)
141         {
142                 f = kh_HandleFrags(attacker, targ, f);
143         }
144         else if(g_lms)
145         {
146                 // remove a life
147                 float tl;
148                 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
149                 if(tl < lms_lowest_lives)
150                         lms_lowest_lives = tl;
151                 if(tl <= 0)
152                 {
153                         if(!lms_next_place)
154                                 lms_next_place = player_count;
155                         PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
156                         --lms_next_place;
157                 }
158                 f = 0;
159         }
160         else if(g_ctf)
161         {
162                 if(g_ctf_ignore_frags)
163                         f = 0;
164         }
165
166         attacker.totalfrags += f;
167
168         if(f)
169                 UpdateFrags(attacker, f);
170 }
171
172 string AppendItemcodes(string s, entity player)
173 {
174         float w;
175         w = player.weapon;
176         //if(w == 0)
177         //      w = player.switchweapon;
178         if(w == 0)
179                 w = player.cnt; // previous weapon!
180         s = strcat(s, ftos(w));
181         if(time < player.strength_finished)
182                 s = strcat(s, "S");
183         if(time < player.invincible_finished)
184                 s = strcat(s, "I");
185         if(player.flagcarried != world)
186                 s = strcat(s, "F");
187         if(player.BUTTON_CHAT)
188                 s = strcat(s, "T");
189         if(player.kh_next)
190                 s = strcat(s, "K");
191         if(player.runes)
192                 s = strcat(s, "|", ftos(player.runes));
193         return s;
194 }
195
196 void LogDeath(string mode, float deathtype, entity killer, entity killed)
197 {
198         string s;
199         if(!cvar("sv_eventlog"))
200                 return;
201         s = strcat(":kill:", mode);
202         s = strcat(s, ":", ftos(killer.playerid));
203         s = strcat(s, ":", ftos(killed.playerid));
204         s = strcat(s, ":type=", ftos(deathtype));
205         s = strcat(s, ":items=");
206         s = AppendItemcodes(s, killer);
207         if(killed != killer)
208         {
209                 s = strcat(s, ":victimitems=");
210                 s = AppendItemcodes(s, killed);
211         }
212         GameLogEcho(s);
213 }
214
215 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
216 {
217         string  s, a;
218         float p, w;
219
220         if (targ.classname == "player" || targ.classname == "corpse")
221         {
222                 if (targ.classname == "corpse")
223                         s = "A corpse";
224                 else
225                         s = targ.netname;
226                 a = attacker.netname;
227
228                 if (targ == attacker)
229                 {
230                         if (deathtype == DEATH_TEAMCHANGE) {
231                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", ColoredTeamName(targ.team)));
232                         } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
233                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
234                                 return;
235                         } else if (deathtype == DEATH_CAMP) {
236                                 if(sv_gentle)
237                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
238                                 else
239                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
240                         } else if (deathtype == DEATH_NOAMMO) {
241                                 if(sv_gentle)
242                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
243                                 else
244                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
245                         } else if (deathtype == DEATH_ROT) {
246                                 if(sv_gentle)
247                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
248                                 else
249                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
250                         } else if (deathtype == DEATH_MIRRORDAMAGE) {
251                                 if(sv_gentle)
252                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
253                                 else
254                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
255                         } else {
256                                 if(sv_gentle)
257                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
258                                 else
259                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
260                         }
261
262                         if(sv_gentle) {
263                                 if (deathtype == DEATH_CAMP)
264                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
265                                 else if (deathtype == DEATH_MIRRORDAMAGE)
266                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
267                                 else
268                                         bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
269
270                                 if(deathtype != DEATH_TEAMCHANGE)
271                                 {
272                                         LogDeath("suicide", deathtype, targ, targ);
273                                         GiveFrags(attacker, targ, -1);
274                                 }
275                                 if (targ.killcount > 2)
276                                         bprint ("^1",s,"^1 faded after a ",ftos(targ.killcount)," point spree\n");
277                         } else {
278                                 w = DEATH_WEAPONOF(deathtype);
279                                 if(WEP_VALID(w))
280                                 {
281                                         w_deathtypestring = "couldn't resist the urge to self-destruct";
282                                         w_deathtype = deathtype;
283                                         weapon_action(w, WR_SUICIDEMESSAGE);
284                                         bprint("^1", s, "^1 ", w_deathtypestring, "\n");
285                                 }
286                                 else if (deathtype == DEATH_KILL)
287                                         bprint ("^1",s, "^1 couldn't take it anymore\n");
288                                 else if (deathtype == DEATH_ROT)
289                                         bprint ("^1",s, "^1 died\n");
290                                 else if (deathtype == DEATH_NOAMMO)
291                                         bprint ("^7",s, "^7 committed suicide. What's the point of living without ammo?\n");
292                                 else if (deathtype == DEATH_CAMP)
293                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
294                                 else if (deathtype == DEATH_MIRRORDAMAGE)
295                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
296                                 else if (deathtype == DEATH_CHEAT)
297                                         bprint ("^1",s, "^1 unfairly eliminated himself\n");
298                                 else if (deathtype == DEATH_FIRE)
299                                         bprint ("^1",s, "^1 burned to death\n");
300                                 else if (deathtype != DEATH_TEAMCHANGE)
301                                         bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
302
303                                 if(deathtype != DEATH_TEAMCHANGE)
304                                 {
305                                         LogDeath("suicide", deathtype, targ, targ);
306                                         GiveFrags(attacker, targ, -1);
307                                 }
308                                 if (targ.killcount > 2)
309                                         bprint ("^1",s,"^1 ended it all after a ",ftos(targ.killcount)," kill spree\n");
310                         }
311                 }
312                 else if (attacker.classname == "player" || attacker.classname == "gib")
313                 {
314                         if(teams_matter && attacker.team == targ.team)
315                         {
316                                 if(sv_gentle) {
317                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against a team mate!"));
318                                         bprint ("^1", a, "^1 took action against a team mate\n");
319                                 } else {
320                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s, ", a team mate!"));
321                                         bprint ("^1", a, "^1 mows down a team mate\n");
322                                 }
323                                 GiveFrags(attacker, targ, -1);
324                                 if (targ.killcount > 2) {
325                                         if(sv_gentle)
326                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a team mate!\n");
327                                         else
328                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a team mate!\n");
329                                 }
330                                 if (attacker.killcount > 2) {
331                                         if(sv_gentle)
332                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a team mate\n");
333                                         else
334                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a team mate\n");
335                                 }
336                                 attacker.killcount = 0;
337
338                                 LogDeath("tk", deathtype, attacker, targ);
339                         }
340                         else
341                         {
342                                 string blood_message, victim_message;
343                                 if (!checkrules_firstblood)
344                                 {
345                                         checkrules_firstblood = TRUE;
346                                         if(sv_gentle)
347                                         {
348                                                 bprint("^1",a, "^1 was the first to score", "\n");
349                                                 blood_message = "^1First point\n";
350                                                 //victim_message = "^1First victim\n";  // or First casualty
351                                         }
352                                         else
353                                         {
354                                                 bprint("^1",a, "^1 drew first blood", "\n");
355                                                 blood_message = "^1First blood\n";
356                                                 victim_message = "^1First victim\n";  // or First casualty
357                                         }
358                                 }
359
360                                 if(sv_gentle > 0) {
361                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s));
362                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, a,"^1 scored against you ^7"));
363                                 } else {
364                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, blood_message, "^4You fragged ^7", s));
365                                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, victim_message, "^1You were fragged by ^7", a));
366                                         attacker.taunt_soundtime = time + 1;
367                                 }
368
369                                 if(sv_gentle) {
370                                         bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
371                                 } else {
372                                         w = DEATH_WEAPONOF(deathtype);
373                                         if(WEP_VALID(w))
374                                         {
375                                                 w_deathtypestring = "was blasted by";
376                                                 w_deathtype = deathtype;
377                                                 weapon_action(w, WR_KILLMESSAGE);
378                                                 p = strstrofs(w_deathtypestring, "#", 0);
379                                                 if(p < 0)
380                                                         bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
381                                                 else
382                                                         bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
383                                         }
384                                         else if (deathtype == DEATH_TELEFRAG)
385                                                 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
386                                         else if (deathtype == DEATH_DROWN)
387                                                 bprint ("^1",s, "^1 was drowned by ", a, "\n");
388                                         else if (deathtype == DEATH_SLIME)
389                                                 bprint ("^1",s, "^1 was slimed by ", a, "\n");
390                                         else if (deathtype == DEATH_LAVA)
391                                                 bprint ("^1",s, "^1 was cooked by ", a, "\n");
392                                         else if (deathtype == DEATH_FALL)
393                                                 bprint ("^1",s, "^1 was grounded by ", a, "\n");
394                                         else if (deathtype == DEATH_SHOOTING_STAR)
395                                                 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
396                                         else if (deathtype == DEATH_SWAMP)
397                                                 bprint ("^1",s, "^1 was conserved by ", a, "\n");
398                                         else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
399                                         {
400                                                 p = strstrofs(inflictor.message2, "#", 0);
401                                                 if(p < 0)
402                                                         bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
403                                                 else
404                                                         bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
405                                         }
406                                         else if(deathtype == DEATH_TURRET)
407                                                 bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
408                                         else if(deathtype == DEATH_TOUCHEXPLODE)
409                                                 bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
410                                         else if(deathtype == DEATH_CHEAT)
411                                                 bprint ("^1",s, "^1 was unfairly eliminated by ^1", a, "\n");
412                                         else if (deathtype == DEATH_FIRE)
413                                                 bprint ("^1",s, "^1 was burnt to death by ^1", a, "\n");
414                                         else
415                                                 bprint ("^1",s, "^1 was fragged by ", a, "\n");
416                                 }
417
418                                 if(g_ctf && targ.flagcarried)
419                                 {
420                                         UpdateFrags(attacker, ctf_score_value("score_kill"));
421                                         PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
422                                         GiveFrags(attacker, targ, 0); // for logging
423                                 }
424                                 else
425                                         GiveFrags(attacker, targ, 1);
426
427                                 if (targ.killcount > 2) {
428                                         if(sv_gentle)
429                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
430                                         else
431                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
432                                 }
433
434                                 attacker.killcount = attacker.killcount + 1;
435
436                                 if (attacker.killcount > 2) {
437                                         if(sv_gentle)
438                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
439                                         else
440                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
441                                 }
442
443                                 LogDeath("frag", deathtype, attacker, targ);
444
445                                 if (attacker.killcount == 3)
446                                 {
447                                         if(sv_gentle) {
448                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
449                                         } else {
450                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
451                                                 announce(attacker, "announcer/male/03kills.wav");
452                                         }
453                                 }
454                                 else if (attacker.killcount == 5)
455                                 {
456                                         if(sv_gentle) {
457                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
458                                         } else {
459                                                 bprint (a,"^7 unleashes ^1RAGE\n");
460                                                 announce(attacker, "announcer/male/05kills.wav");
461                                         }
462                                 }
463                                 else if (attacker.killcount == 10)
464                                 {
465                                         if(sv_gentle) {
466                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
467                                         } else {
468                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");
469                                                 announce(attacker, "announcer/male/10kills.wav");
470                                         }
471                                 }
472                                 else if (attacker.killcount == 15)
473                                 {
474                                         if(sv_gentle) {
475                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
476                                         } else {
477                                                 bprint (a,"^7 executes ^1MAYHEM!\n");
478                                                 announce(attacker, "announcer/male/15kills.wav");
479                                         }
480                                 }
481                                 else if (attacker.killcount == 20)
482                                 {
483                                         if(sv_gentle) {
484                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
485                                         } else {
486                                                 bprint (a,"^7 is a ^1BERSERKER!\n");
487                                                 announce(attacker, "announcer/male/20kills.wav");
488                                         }
489                                 }
490                                 else if (attacker.killcount == 25)
491                                 {
492                                         if(sv_gentle) {
493                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
494                                         } else {
495                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");
496                                                 announce(attacker, "announcer/male/25kills.wav");
497                                         }
498                                 }
499                                 else if (attacker.killcount == 30)
500                                 {
501                                         if(sv_gentle) {
502                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
503                                         } else {
504                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
505                                                 announce(attacker, "announcer/male/30kills.wav");
506                                         }
507                                 }
508                         }
509                 }
510                 else
511                 {
512                         centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
513                         if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
514                                 bprint ("^1",s, "^1 ", inflictor.message, "\n");
515                         else if (deathtype == DEATH_DROWN)
516                                 if(sv_gentle)
517                                         bprint ("^1",s, "^1 was in the water for too long\n");
518                                 else
519                                         bprint ("^1",s, "^1 drowned\n");
520                         else if (deathtype == DEATH_SLIME)
521                                 bprint ("^1",s, "^1 was slimed\n");
522                         else if (deathtype == DEATH_LAVA)
523                                 if(sv_gentle)
524                                         bprint ("^1",s, "^1 found a hot place\n");
525                                 else
526                                         bprint ("^1",s, "^1 turned into hot slag\n");
527                         else if (deathtype == DEATH_FALL)
528                                 if(sv_gentle)
529                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");
530                                 else
531                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");
532                         else if (deathtype == DEATH_SHOOTING_STAR)
533                                 bprint ("^1",s, "^1 became a shooting star\n");
534                         else if (deathtype == DEATH_SWAMP)
535                                 if(sv_gentle)
536                                         bprint ("^1",s, "^1 discovered a swamp\n");
537                                 else
538                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");
539                         else if(deathtype == DEATH_TURRET)
540                                 bprint ("^1",s, "^1 was mowed down by a turret \n");
541                         else if(deathtype == DEATH_TOUCHEXPLODE)
542                                 bprint ("^1",s, "^1 died in an accident\n");
543                         else if(deathtype == DEATH_CHEAT)
544                                 bprint ("^1",s, "^1 was unfairly eliminated\n");
545                         else if(deathtype == DEATH_FIRE)
546                                 if(sv_gentle)
547                                         bprint ("^1",s, "^1 felt a little hot\n");
548                                 else
549                                         bprint ("^1",s, "^1 burnt to death\n");
550                         else
551                                 if(sv_gentle)
552                                         bprint ("^1",s, "^1 needs a restart\n");
553                                 else
554                                         bprint ("^1",s, "^1 died\n");
555                         GiveFrags(targ, targ, -1);
556                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
557                                 announce(targ, "announcer/male/botlike.wav");
558                         }
559
560                         if (targ.killcount > 2)
561                                 if(sv_gentle)
562                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
563                                 else
564                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
565
566                         LogDeath("accident", deathtype, targ, targ);
567                 }
568                 targ.death_origin = targ.origin;
569                 if(targ != attacker)
570                         targ.killer_origin = attacker.origin;
571                 // FIXME: this should go in PutClientInServer
572                 if (targ.killcount)
573                         targ.killcount = 0;
574         }
575 }
576
577 // these are updated by each Damage call for use in button triggering and such
578 entity damage_targ;
579 entity damage_inflictor;
580 entity damage_attacker;
581
582 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
583 {
584         float mirrordamage;
585         float mirrorforce;
586         float teamdamage0;
587         entity attacker_save;
588         mirrordamage = 0;
589         mirrorforce = 0;
590
591         if (gameover || targ.killcount == -666)
592                 return;
593
594         local entity oldself;
595         oldself = self;
596         self = targ;
597         damage_targ = targ;
598         damage_inflictor = inflictor;
599         damage_attacker = attacker;
600                 attacker_save = attacker;
601
602         if(targ.classname == "player")
603                 if(targ.hook)
604                         if(targ.hook.aiment)
605                                 if(targ.hook.aiment == attacker)
606                                         RemoveGrapplingHook(targ); // STOP THAT, you parasite!
607
608         // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
609         if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
610         {
611                 if(targ.classname == "player")
612                         if not(IsDifferentTeam(targ, attacker))
613                         {
614                                 self = oldself;
615                                 return;
616                         }
617         }
618
619         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
620         {
621                 // These are ALWAYS lethal
622                 // No damage modification here
623                 // Instead, prepare the victim for his death...
624                 targ.armorvalue = 0;
625                 targ.spawnshieldtime = 0;
626                 targ.health = 0.9; // this is < 1
627                 targ.flags -= targ.flags & FL_GODMODE;
628                 damage = 100000;
629         }
630         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
631         {
632                 // no processing
633         }
634         else
635         {
636                 if (targ.classname == "player")
637                 if (attacker.classname == "player")
638                 if (!targ.isbot)
639                 if (attacker.isbot)
640                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
641
642                 // nullify damage if teamplay is on
643                 if(deathtype != DEATH_TELEFRAG)
644                 if(attacker.classname == "player")
645                 {
646                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
647                         {
648                                 damage = 0;
649                                 force = '0 0 0';
650                         }
651                         else if(attacker.team == targ.team)
652                         {
653                                 if(teamplay == 1)
654                                         damage = 0;
655                                 else if(attacker != targ)
656                                 {
657                                         if(teamplay == 3)
658                                                 damage = 0;
659                                         else if(teamplay == 4)
660                                         {
661                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
662                                                 {
663                                                         teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
664                                                         attacker.dmg_team = attacker.dmg_team + damage;
665                                                         if(attacker.dmg_team > teamdamage0)
666                                                                 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
667                                                         mirrorforce = cvar("g_mirrordamage") * vlen(force);
668                                                         if(g_minstagib)
669                                                         {
670                                                                 if(cvar("g_friendlyfire") == 0)
671                                                                         damage = 0;
672                                                         }
673                                                         else
674                                                                 damage = cvar("g_friendlyfire") * damage;
675                                                         // mirrordamage will be used LATER
676                                                 }
677                                                 else
678                                                         damage = 0;
679                                         }
680                                 }
681                         }
682                 }
683
684                 if(targ.classname == "player")
685                 if(attacker.classname == "player")
686                 if(attacker != targ)
687                 {
688                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
689                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
690                 }
691
692                 if(targ.classname == "player")
693                 if (g_minstagib)
694                 {
695                         if ((deathtype == DEATH_FALL)  ||
696                                 (deathtype == DEATH_DROWN) ||
697                                 (deathtype == DEATH_SLIME) ||
698                                 (deathtype == DEATH_LAVA))
699                         {
700                                 self = oldself;
701                                 return;
702                         }
703                         if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
704                         {
705                                 targ.armorvalue -= 1;
706                                 centerprint(targ, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(targ.armorvalue)));
707                                 damage = 0;
708                                 targ.hitsound += 1;
709                                 attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
710                         }
711                         if (DEATH_ISWEAPON(deathtype, WEP_LASER))
712                         {
713                                 damage = 0;
714                                 if (targ != attacker)
715                                 {
716                                         if (targ.classname == "player")
717                                                 centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "Secondary fire inflicts no damage!"));
718                                         damage = 0;
719                                         mirrordamage = 0;
720                                         force = '0 0 0';
721                                         // keep mirrorforce
722                                         attacker = targ;
723                                 }
724                         }
725                 }
726
727                 if not(DEATH_ISSPECIAL(deathtype))
728                 {
729                         damage *= g_weapondamagefactor;
730                         mirrordamage *= g_weapondamagefactor;
731                         force = force * g_weaponforcefactor;
732                         mirrorforce *= g_weaponforcefactor;
733                 }
734
735                 // apply strength multiplier
736                 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
737                 {
738                         if(targ == attacker)
739                         {
740                                 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
741                                 force = force * cvar("g_balance_powerup_strength_selfforce");
742                         }
743                         else
744                         {
745                                 damage = damage * cvar("g_balance_powerup_strength_damage");
746                                 force = force * cvar("g_balance_powerup_strength_force");
747                         }
748                 }
749
750                 // apply invincibility multiplier
751                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
752                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
753
754                 if (targ == attacker)
755                         damage = damage * cvar("g_balance_selfdamagepercent");  // Partial damage if the attacker hits himself
756
757                 // CTF: reduce damage/force
758                 if(g_ctf)
759                 if(targ == attacker)
760                 if(targ.flagcarried)
761                 {
762                         damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
763                         force = force * cvar("g_ctf_flagcarrier_selfforce");
764                 }
765
766                 if(g_runematch)
767                 {
768                         // apply strength rune
769                         if (attacker.runes & RUNE_STRENGTH)
770                         {
771                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
772                                 {
773                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
774                                         force = force * cvar("g_balance_rune_strength_combo_force");
775                                 }
776                                 else
777                                 {
778                                         damage = damage * cvar("g_balance_rune_strength_damage");
779                                         force = force * cvar("g_balance_rune_strength_force");
780                                 }
781                         }
782                         else if (attacker.runes & CURSE_WEAK)
783                         {
784                                 damage = damage * cvar("g_balance_curse_weak_damage");
785                                 force = force * cvar("g_balance_curse_weak_force");
786                         }
787
788                         // apply defense rune
789                         if (targ.runes & RUNE_DEFENSE)
790                         {
791                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
792                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
793                                 else
794                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
795                         }
796                         else if (targ.runes & CURSE_VULNER)
797                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
798                 }
799
800                 // count the damage
801                 if(attacker)
802                 if(!targ.deadflag)
803                 if(targ.takedamage == DAMAGE_AIM)
804                 if(targ != attacker)
805                 if(targ.classname == "player")
806                 {
807                         if(IsDifferentTeam(targ, attacker))
808                         {
809                                 if(damage > 0)
810                                 {
811                                         if(targ.BUTTON_CHAT)
812                                                 attacker.typehitsound += 1;
813                                         else
814                                                 attacker.hitsound += 1;
815
816                                         damage_goodhits += 1;
817                                         damage_gooddamage += damage;
818
819                                         if not(DEATH_ISSPECIAL(deathtype))
820                                         {
821                                                 if(!g_minstagib)
822                                                 if(IsFlying(targ))
823                                                         yoda = 1;
824
825                                                 if(g_minstagib)
826                                                 if(targ.items & IT_STRENGTH)
827                                                         yoda = 1;
828
829                                                 // HEAD SHOT:
830                                                 // find height of hit on player axis
831                                                 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
832                                                 vector headmins, headmaxs, org;
833                                                 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
834                                                 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * (1.5 * targ.view_ofs_z - 0.5 * targ.maxs_z);
835                                                 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
836                                                 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
837                                                 {
838                                                         damage *= 1 + damage_headshotbonus;
839                                                         headshot = 1;
840                                                         deathtype |= HITTYPE_HEADSHOT;
841                                                 }
842                                         }
843                                 }
844                         }
845                         else
846                         {
847                                 if(deathtype != DEATH_FIRE)
848                                         attacker.typehitsound += 1;
849                                 if(mirrordamage > 0)
850                                         if(time > attacker.teamkill_complain)
851                                         {
852                                                 attacker.teamkill_complain = time + 5;
853                                                 attacker.teamkill_soundtime = time + 0.4;
854                                                 attacker.teamkill_soundsource = targ;
855                                         }
856                         }
857                 }
858         }
859
860         // apply push
861         if (self.damageforcescale)
862         if (vlen(force))
863         {
864                 self.velocity = self.velocity + self.damageforcescale * force;
865                 self.flags &~= FL_ONGROUND;
866                 UpdateCSQCProjectile(self);
867         }
868         // apply damage
869         if (damage != 0 || (self.damageforcescale && vlen(force)))
870         if (self.event_damage)
871                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
872         self = oldself;
873
874         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
875         {
876                 // Savage: vampire mode
877                 if (g_vampire)
878                 if (!g_minstagib)
879                 if (time > self.spawnshieldtime)
880                 {
881                         attacker.health += damage;
882                 }
883                 if(g_runematch)
884                 {
885                         if (attacker.runes & RUNE_VAMPIRE)
886                         {
887                         // apply vampire rune
888                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
889                                 {
890                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
891                                         attacker.health = bound(
892                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
893                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
894                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
895                                 }
896                                 else
897                                 {
898                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
899                                         attacker.health = bound(
900                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
901                                                                                         // empathy won't let you gain health in the same way...
902                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
903                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
904                                         }
905                         }
906                         // apply empathy curse
907                         else if (attacker.runes & CURSE_EMPATHY)
908                         {
909                                 attacker.health = bound(
910                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
911                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
912                                         attacker.health);
913                         }
914                 }
915         }
916
917         // apply mirror damage if any
918         if(mirrordamage > 0 || mirrorforce > 0)
919         {
920                 attacker = attacker_save;
921                 if(g_minstagib)
922                         if(mirrordamage > 0)
923                         {
924                                 // just lose extra LIVES, don't kill the player for mirror damage
925                                 if(attacker.armorvalue > 0)
926                                 {
927                                         attacker.armorvalue = attacker.armorvalue - 1;
928                                         centerprint(attacker, strcat(DAMAGE_CENTERPRINT_SPACER, "^3Remaining extra lives: ",ftos(attacker.armorvalue)));
929                                         attacker.hitsound += 1;
930                                 }
931                                 mirrordamage = 0;
932                         }
933                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
934                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
935         }
936 }
937
938 vector NearestPointOnBox(entity box, vector org)
939 {
940         vector m1, m2, nearest;
941
942         m1 = box.mins + box.origin;
943         m2 = box.maxs + box.origin;
944
945         nearest_x = bound(m1_x, org_x, m2_x);
946         nearest_y = bound(m1_y, org_y, m2_y);
947         nearest_z = bound(m1_z, org_z, m2_z);
948
949         return nearest;
950 }
951
952 .float actual_damage[WEP_COUNT]; //amount of damage done
953 .float max_damage[WEP_COUNT]; //the maximum damage of the weapon
954
955 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(actual_damage);
956 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(max_damage);
957
958 void Damage_RecordDamage(entity attacker, float deathtype, float damage)
959 {
960         float weaponid;
961         weaponid = DEATH_WEAPONOF(deathtype);
962         if not(inWarmupStage)
963         if(weaponid)
964         if(clienttype(attacker) == CLIENTTYPE_REAL)
965         {
966                 // Track damage done and update the stat to be sent later in g_world.qc
967                 attacker.actual_damage[weaponid] += damage;
968                 attacker.damage_hits = weaponid + 64 * rint(attacker.actual_damage[weaponid]);
969         }
970 }
971
972 float RadiusDamage_running;
973 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
974 // Returns total damage applies to creatures
975 {
976         entity  targ;
977         float   finaldmg;
978         float   power;
979         vector  blastorigin;
980         vector  force;
981         vector  diff;
982         vector  center;
983         vector  nearest;
984         float   total_damage_to_creatures;
985         entity  next;
986
987         float stat_damagedone;
988         float stat_maxdamage;
989
990         if(RadiusDamage_running)
991         {
992                 string save;
993                 print("RadiusDamage called recursively!\n");
994                 print("Expect stuff to go HORRIBLY wrong.\n");
995                 print("Causing a stack trace...\n");
996                 save = cvar_string("prvm_backtraceforwarnings");
997                 cvar_set("prvm_backtraceforwarnings", "1");
998                 fclose(-1); // calls VM_Warning
999                 cvar_set("prvm_backtraceforwarnings", save);
1000                 return 0;
1001         }
1002
1003
1004         RadiusDamage_running = 1;
1005
1006         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
1007         total_damage_to_creatures = 0;
1008
1009         if(deathtype != (WEP_HOOK | HITTYPE_SECONDARY | HITTYPE_BOUNCE)) // only send gravity bomb damage once
1010         {
1011                 force = inflictor.velocity;
1012                 if(vlen(force) == 0)
1013                         force = '0 0 -1';
1014                 else
1015                         force = normalize(force);
1016                 if(forceintensity >= 0)
1017                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, rad, forceintensity * force, deathtype, attacker);
1018                 else
1019                         Damage_DamageInfo(blastorigin, coredamage, edgedamage, -rad, (-forceintensity) * force, deathtype, attacker);
1020         }
1021
1022         stat_damagedone = 0;
1023         stat_maxdamage = 0;
1024
1025         targ = findradius (blastorigin, rad);
1026         while (targ)
1027         {
1028                 next = targ.chain;
1029                 if (targ != inflictor)
1030                         if (ignore != targ)
1031                         {
1032                                 // LordHavoc: measure distance to nearest point on target (not origin)
1033                                 // (this guarentees 100% damage on a touch impact)
1034                                 nearest = NearestPointOnBox(targ, blastorigin);
1035                                 diff = nearest - blastorigin;
1036                                 // round up a little on the damage to ensure full damage on impacts
1037                                 // and turn the distance into a fraction of the radius
1038                                 power = 1 - ((vlen (diff) - 2) / rad);
1039                                 //bprint(" ");
1040                                 //bprint(ftos(power));
1041                                 if (power > 0)
1042                                 {
1043                                         if (power > 1)
1044                                                 power = 1;
1045                                         finaldmg = coredamage * power + edgedamage * (1 - power);
1046                                         if (finaldmg > 0)
1047                                         {
1048                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
1049                                                 // if it's a player, use the view origin as reference
1050                                                 if (targ.classname == "player")
1051                                                         center = targ.origin + targ.view_ofs;
1052                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
1053                                                 // test line of sight to multiple positions on box,
1054                                                 // and do damage if any of them hit
1055                                                 local float c;
1056                                                 c = ceil(finaldmg / 10);
1057                                                 if (c > 20)
1058                                                         c = 20;
1059                                                 while (c > 0)
1060                                                 {
1061                                                         c = c - 1;
1062                                                         traceline(blastorigin, nearest, TRUE, inflictor);
1063                                                         if (trace_fraction == 1 || trace_ent == targ
1064                                                             || cvar("g_throughfloor"))
1065                                                         {
1066                                                                 if(targ.iscreature)
1067                                                                 {
1068                                                                         total_damage_to_creatures += finaldmg;
1069
1070                                                                         if(targ.flags & FL_CLIENT)
1071                                                                         if(targ.deadflag == DEAD_NO)
1072                                                                         if(targ != attacker)
1073                                                                         if(!teamplay || targ.team != attacker.team)
1074                                                                         {
1075                                                                                 stat_damagedone += finaldmg;
1076                                                                                 stat_maxdamage += coredamage;
1077                                                                         }
1078                                                                 }
1079
1080                                                                 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
1081                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
1082                                                                 else
1083                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
1084                                                                 break;
1085                                                         }
1086                                                         nearest_x = targ.mins_x + random() * targ.size_x;
1087                                                         nearest_y = targ.mins_y + random() * targ.size_y;
1088                                                         nearest_z = targ.mins_z + random() * targ.size_z;
1089                                                 }
1090                                         }
1091                                 }
1092                         }
1093                 targ = next;
1094         }
1095
1096         RadiusDamage_running = 0;
1097
1098         Damage_RecordDamage(attacker, deathtype, min(stat_maxdamage, stat_damagedone));
1099
1100         return total_damage_to_creatures;
1101 }
1102
1103 .float fire_damagepersec;
1104 .float fire_endtime;
1105 .float fire_deathtype;
1106 .entity fire_owner;
1107 .float fire_hitsound;
1108 .entity fire_burner;
1109
1110 void fireburner_think();
1111
1112 float Fire_IsBurning(entity e)
1113 {
1114         return (time < e.fire_endtime);
1115 }
1116
1117 float Fire_AddDamage(entity e, entity o, float d, float t, float dt)
1118 {
1119         float dps;
1120         float maxtime, mintime, maxdamage, mindamage, maxdps, mindps, totaldamage, totaltime;
1121
1122         if(e.classname != "player")
1123         if(!e.fire_burner)
1124         {
1125                 // print("adding a fire burner to ", e.classname, "\n");
1126                 e.fire_burner = spawn();
1127                 e.fire_burner.classname = "fireburner";
1128                 e.fire_burner.think = fireburner_think;
1129                 e.fire_burner.nextthink = time;
1130                 e.fire_burner.owner = e;
1131         }
1132
1133         t = max(t, 0.1);
1134         dps = d / t;
1135         if(Fire_IsBurning(e))
1136         {
1137                 mintime = e.fire_endtime - time;
1138                 maxtime = max(mintime, t);
1139
1140                 mindps = e.fire_damagepersec;
1141                 maxdps = max(mindps, dps);
1142
1143                 if(maxtime > mintime || maxdps > mindps)
1144                 {
1145                         mindamage = mindps * mintime;
1146                         maxdamage = mindamage + d;
1147
1148                         // interval [mintime, maxtime] * [mindps, maxdps]
1149                         // intersected with
1150                         // [mindamage, maxdamage]
1151                         // maximum of this!
1152
1153                         if(maxdamage >= maxtime * maxdps)
1154                         {
1155                                 totaltime = maxtime;
1156                                 totaldamage = maxtime * maxdps;
1157
1158                                 // this branch increases totaldamage if either t > mintime, or dps > mindps
1159                         }
1160                         else
1161                         {
1162                                 // maxdamage is inside the interval!
1163                                 // first, try to use mindps; only if this fails, increase dps as needed
1164                                 totaltime = min(maxdamage / mindps, maxtime); // maxdamage / mindps >= mindamage / mindps = mintime
1165                                 totaldamage = maxdamage;
1166                                 // can totaldamage / totaltime be >= maxdps?
1167                                 // max(mindps, maxdamage / maxtime) >= maxdps?
1168                                 // we know maxdamage < maxtime * maxdps
1169                                 // so it cannot be
1170
1171                                 // this branch ALWAYS increases totaldamage, but requires maxdamage < maxtime * maxdps
1172                         }
1173
1174                         // total conditions for increasing:
1175                         //     maxtime > mintime OR maxdps > mindps OR maxtime * maxdps > maxdamage
1176                         // however:
1177                         //     if maxtime = mintime, maxdps = mindps
1178                         // then:
1179                         //     maxdamage = mindamage + d
1180                         //     mindamage = mindps * mintime = maxdps * maxtime < maxdamage!
1181                         // so the last condition is not needed
1182
1183                         e.fire_damagepersec = totaldamage / totaltime;
1184                         e.fire_endtime = time + totaltime;
1185                         if(totaldamage > 1.2 * mindamage)
1186                         if(e.fire_owner != o)
1187                         {
1188                                 e.fire_deathtype = dt;
1189                                 e.fire_owner = o;
1190                                 e.fire_hitsound = FALSE;
1191                         }
1192                         return totaldamage - mindamage; // can never be negative
1193                 }
1194                 else
1195                         return 0;
1196         }
1197         else
1198         {
1199                 e.fire_damagepersec = dps;
1200                 e.fire_endtime = time + t;
1201                 e.fire_deathtype = dt;
1202                 e.fire_owner = o;
1203                 e.fire_hitsound = FALSE;
1204                 return d;
1205         }
1206 }
1207
1208 void Fire_ApplyDamage(entity e)
1209 {
1210         float t, d, hi, ty;
1211
1212         if not(Fire_IsBurning(e))
1213                 return;
1214
1215         // water and slime stop fire
1216         if(e.waterlevel)
1217         if(e.watertype != CONTENT_LAVA)
1218                 e.fire_endtime = 0;
1219
1220         t = min(frametime, e.fire_endtime - time);
1221         d = e.fire_damagepersec * t;
1222
1223         hi = e.fire_owner.hitsound;
1224         ty = e.fire_owner.typehitsound;
1225         Damage(e, e, e.fire_owner, d, e.fire_deathtype, e.origin, '0 0 0');
1226         if(e.fire_hitsound && e.fire_owner)
1227         {
1228                 e.fire_owner.hitsound = hi;
1229                 e.fire_owner.typehitsound = ty;
1230         }
1231         e.fire_hitsound = TRUE;
1232
1233         Damage_RecordDamage(e.fire_owner, e.fire_deathtype, d);
1234
1235         if not(IS_INDEPENDENT_PLAYER(e))
1236         FOR_EACH_PLAYER(other) if(e != other)
1237         {
1238                 if(other.classname == "player")
1239                 if(other.deadflag == DEAD_NO)
1240                 if not(IS_INDEPENDENT_PLAYER(other))
1241                 if(boxesoverlap(e.absmin, e.absmax, other.absmin, other.absmax))
1242                 {
1243                         t = cvar("g_balance_firetransfer_time") * (e.fire_endtime - time);
1244                         d = cvar("g_balance_firetransfer_damage") * e.fire_damagepersec * t;
1245                         Fire_AddDamage(other, e, d, t, DEATH_FIRE);
1246                 }
1247         }
1248 }
1249
1250 void Fire_ApplyEffect(entity e)
1251 {
1252         if(Fire_IsBurning(e))
1253                 e.effects |= EF_FLAME;
1254         else
1255                 e.effects &~= EF_FLAME;
1256 }
1257
1258 void fireburner_think()
1259 {
1260         // for players, this is done in the regular loop
1261         if(wasfreed(self.owner))
1262         {
1263                 remove(self);
1264                 return;
1265         }
1266         Fire_ApplyEffect(self.owner);
1267         if(!Fire_IsBurning(self.owner))
1268         {
1269                 self.owner.fire_burner = world;
1270                 remove(self);
1271                 return;
1272         }
1273         Fire_ApplyDamage(self.owner);
1274         self.nextthink = time;
1275 }