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