]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
improve kickban display
[divverent/nexuiz.git] / data / qcsrc / server / g_damage.qc
1 float checkrules_firstblood;
2
3 float yoda;
4 float damage_goodhits;
5 float damage_gooddamage;
6 float headshot;
7 float damage_headshotbonus; // bonus multiplier for head shots, set to 0 after use
8
9 .float teamkill_complain;
10 .float teamkill_soundtime;
11 .entity teamkill_soundsource;
12 .entity pusher;
13
14
15 float IsDifferentTeam(entity a, entity b)
16 {
17         if(teams_matter)
18         {
19                 if(a.team == b.team)
20                         return 0;
21         }
22         else
23         {
24                 if(a == b)
25                         return 0;
26         }
27         return 1;
28 }
29
30 float IsFlying(entity a)
31 {
32         if(a.flags & FL_ONGROUND)
33                 return 0;
34         if(a.waterlevel >= 2)
35                 return 0;
36         traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
37         if(trace_fraction < 1)
38                 return 0;
39         return 1;
40 }
41
42 void UpdateFrags(entity player, float f)
43 {
44         PlayerTeamScore_AddScore(player, f);
45 }
46
47 // NOTE: f=0 means still count as a (positive) kill, but count no frags for it
48 void GiveFrags (entity attacker, entity targ, float f)
49 {
50         // TODO route through PlayerScores instead
51         if(gameover) return;
52
53         if(f < 0)
54         {
55                 if(targ == attacker)
56                 {
57                         // suicide
58                         PlayerScore_Add(attacker, SP_SUICIDES, 1);
59                 }
60                 else
61                 {
62                         // teamkill
63                         PlayerScore_Add(attacker, SP_KILLS, -1); // or maybe add a teamkills field?
64                 }
65         }
66         else
67         {
68                 // regular frag
69                 PlayerScore_Add(attacker, SP_KILLS, 1);
70         }
71
72         PlayerScore_Add(targ, SP_DEATHS, 1);
73
74         if(g_arena)
75                 if(cvar("g_arena_roundbased"))
76                         return;
77
78         // FIXME fix the mess this is (we have REAL points now!)
79         if(g_runematch)
80         {
81                 f = RunematchHandleFrags(attacker, targ, f);
82         }
83         else if(g_keyhunt)
84         {
85                 f = kh_HandleFrags(attacker, targ, f);
86         }
87         else if(g_lms)
88         {
89                 // remove a life
90                 float tl;
91                 tl = PlayerScore_Add(targ, SP_LMS_LIVES, -1);
92                 if(tl < lms_lowest_lives)
93                         lms_lowest_lives = tl;
94                 if(tl <= 0)
95                 {
96                         if(!lms_next_place)
97                                 lms_next_place = player_count;
98                         PlayerScore_Add(targ, SP_LMS_RANK, lms_next_place); // won't ever spawn again
99                         --lms_next_place;
100                 }
101                 f = 0;
102         }
103         else if(g_ctf)
104         {
105                 if(g_ctf_ignore_frags)
106                         f = 0;
107         }
108
109         attacker.totalfrags += f;
110
111         if(f)
112                 UpdateFrags(attacker, f);
113 }
114
115 string AppendItemcodes(string s, entity player)
116 {
117         float w;
118         w = player.weapon;
119         //if(w == 0)
120         //      w = player.switchweapon;
121         if(w == 0)
122                 w = player.cnt; // previous weapon!
123         s = strcat(s, ftos(w));
124         if(time < player.strength_finished)
125                 s = strcat(s, "S");
126         if(time < player.invincible_finished)
127                 s = strcat(s, "I");
128         if(player.flagcarried != world)
129                 s = strcat(s, "F");
130         if(player.BUTTON_CHAT)
131                 s = strcat(s, "T");
132         if(player.kh_next)
133                 s = strcat(s, "K");
134         if(player.runes)
135                 s = strcat(s, "|", ftos(player.runes));
136         return s;
137 }
138
139 void LogDeath(string mode, float deathtype, entity killer, entity killed)
140 {
141         string s;
142         if(!cvar("sv_eventlog"))
143                 return;
144         s = strcat(":kill:", mode);
145         s = strcat(s, ":", ftos(killer.playerid));
146         s = strcat(s, ":", ftos(killed.playerid));
147         s = strcat(s, ":type=", ftos(deathtype));
148         s = strcat(s, ":items=");
149         s = AppendItemcodes(s, killer);
150         if(killed != killer)
151         {
152                 s = strcat(s, ":victimitems=");
153                 s = AppendItemcodes(s, killed);
154         }
155         GameLogEcho(s);
156 }
157
158 void Obituary (entity attacker, entity inflictor, entity targ, float deathtype)
159 {
160         string  s, a;
161         float p, w;
162
163         if (targ.classname == "player" || targ.classname == "corpse")
164         {
165                 if (targ.classname == "corpse")
166                         s = "A corpse";
167                 else
168                         s = targ.netname;
169                 a = attacker.netname;
170
171                 if (targ == attacker)
172                 {
173                         if (deathtype == DEATH_TEAMCHANGE) {
174                                 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
175                         } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
176                                 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
177                                 return;
178                         } else if (deathtype == DEATH_CAMP) {
179                                 if(sv_gentle)
180                                         centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
181                                 else
182                                         centerprint(targ, "^1Die camper!\n\n\n");
183                         } else if (deathtype == DEATH_NOAMMO) {
184                                 if(sv_gentle)
185                                         centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
186                                 else
187                                         centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
188                         } else if (deathtype == DEATH_ROT) {
189                                 if(sv_gentle)
190                                         centerprint(targ, "^1You need to preserve your health\n\n\n");
191                                 else
192                                         centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
193                         } else if (deathtype == DEATH_MIRRORDAMAGE) {
194                                 if(sv_gentle)
195                                         centerprint(targ, "^1Don't go against team mates!\n\n\n");
196                                 else
197                                         centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
198                         } else {
199                                 if(sv_gentle)
200                                         centerprint(targ, "^1You need to be more careful!\n\n\n");
201                                 else
202                                         centerprint(targ, "^1You killed your own dumb self!\n\n\n");
203                         }
204
205                         if(sv_gentle) {
206                                 if (deathtype == DEATH_CAMP)
207                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
208                                 else if (deathtype == DEATH_MIRRORDAMAGE)
209                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
210                                 else
211                                         bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
212
213                                 if(deathtype != DEATH_TEAMCHANGE)
214                                 {
215                                         LogDeath("suicide", deathtype, targ, targ);
216                                         GiveFrags(attacker, targ, -1);
217                                 }
218                                 if (targ.killcount > 2)
219                                         bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
220                         } else {
221                                 w = DEATH_WEAPONOF(deathtype);
222                                 if(WEP_VALID(w))
223                                 {
224                                         w_deathtypestring = "couldn't resist the urge to self-destruct";
225                                         w_deathtype = deathtype;
226                                         weapon_action(w, WR_SUICIDEMESSAGE);
227                                         bprint("^1", s, "^1 ", w_deathtypestring, "\n");
228                                 }
229                                 else if (deathtype == DEATH_KILL)
230                                         bprint ("^1",s, "^1 couldn't take it anymore\n");
231                                 else if (deathtype == DEATH_ROT)
232                                         bprint ("^1",s, "^1 died\n");
233                                 else if (deathtype == DEATH_NOAMMO)
234                                 {
235                                         bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
236                                 }
237                                 else if (deathtype == DEATH_CAMP)
238                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
239                                 else if (deathtype == DEATH_MIRRORDAMAGE)
240                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
241                                 else if (deathtype != DEATH_TEAMCHANGE)
242                                         bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
243
244                                 if(deathtype != DEATH_TEAMCHANGE)
245                                 {
246                                         LogDeath("suicide", deathtype, targ, targ);
247                                         GiveFrags(attacker, targ, -1);
248                                 }
249                                 if (targ.killcount > 2)
250                                         bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
251                         }
252                 }
253                 else if (attacker.classname == "player" || attacker.classname == "gib")
254                 {
255                         if(teamplay && attacker.team == targ.team)
256                         {
257                                 if(sv_gentle) {
258                                         centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
259                                         bprint ("^1", a, "^1 took action against a teammate\n");
260                                 } else {
261                                         centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
262                                         bprint ("^1", a, "^1 mows down a teammate\n");
263                                 }
264                                 GiveFrags(attacker, targ, -1);
265                                 if (targ.killcount > 2) {
266                                         if(sv_gentle)
267                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
268                                         else
269                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
270                                 }
271                                 if (attacker.killcount > 2) {
272                                         if(sv_gentle)
273                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
274                                         else
275                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
276                                 }
277                                 attacker.killcount = 0;
278
279                                 LogDeath("tk", deathtype, attacker, targ);
280                         }
281                         else
282                         {
283                                 if (!checkrules_firstblood)
284                                 {
285                                         checkrules_firstblood = TRUE;
286                                         if(sv_gentle)
287                                                 bprint("^1",a, "^1 was the first to score", "\n");
288                                         else
289                                                 bprint("^1",a, "^1 drew first blood", "\n");
290                                 }
291
292                                 if(sv_gentle > 0) {
293                                         centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
294                                         centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
295                                 } else {
296                                         centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
297                                         centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
298                                 }
299
300                                 if(sv_gentle) {
301                                         bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
302                                 } else {
303                                         w = DEATH_WEAPONOF(deathtype);
304                                         if(WEP_VALID(w))
305                                         {
306                                                 w_deathtypestring = "was blasted by";
307                                                 w_deathtype = deathtype;
308                                                 weapon_action(w, WR_KILLMESSAGE);
309                                                 p = strstrofs(w_deathtypestring, "#", 0);
310                                                 if(p < 0)
311                                                         bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
312                                                 else
313                                                         bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
314                                         }
315                                         else if (deathtype == DEATH_TELEFRAG)
316                                                 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
317                                         else if (deathtype == DEATH_DROWN)
318                                                 bprint ("^1",s, "^1 was drowned by ", a, "\n");
319                                         else if (deathtype == DEATH_SLIME)
320                                                 bprint ("^1",s, "^1 was slimed by ", a, "\n");
321                                         else if (deathtype == DEATH_LAVA)
322                                                 bprint ("^1",s, "^1 was cooked by ", a, "\n");
323                                         else if (deathtype == DEATH_FALL)
324                                                 bprint ("^1",s, "^1 was grounded by ", a, "\n");
325                                         else if (deathtype == DEATH_SHOOTING_STAR)
326                                                 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
327                                         else if (deathtype == DEATH_SWAMP)
328                                                 bprint ("^1",s, "^1 was conserved by ", a, "\n");
329                                         else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
330                                         {
331                                                 p = strstrofs(inflictor.message2, "#", 0);
332                                                 if(p < 0)
333                                                         bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
334                                                 else
335                                                         bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
336                                         }
337                     else if(deathtype == DEATH_TURRET)
338                         bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
339                     else if(deathtype == DEATH_TOUCHEXPLODE)
340                         bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
341                                         else
342                                                 bprint ("^1",s, "^1 was fragged by ", a, "\n");
343                                 }
344                                 if(g_ctf && targ.flagcarried)
345                                 {
346                                         UpdateFrags(attacker, ctf_score_value("score_kill"));
347                                         PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
348                                         GiveFrags(attacker, targ, 0); // for logging
349                                 }
350                                 else
351                                         GiveFrags(attacker, targ, 1);
352                                 if (targ.killcount > 2) {
353                                         if(sv_gentle)
354                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
355                                         else
356                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
357                                 }
358                                 attacker.killcount = attacker.killcount + 1;
359                                 if (attacker.killcount > 2) {
360                                         if(sv_gentle)
361                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
362                                         else
363                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
364                                 }
365
366                                 LogDeath("frag", deathtype, attacker, targ);
367
368                                 if (attacker.killcount == 3)
369                                 {
370                                         if(sv_gentle) {
371                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
372                                         } else {
373                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
374                                                 announce(attacker, "announcer/male/03kills.wav");
375                                         }
376                                 }
377                                 else if (attacker.killcount == 5)
378                                 {
379                                         if(sv_gentle) {
380                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
381                                         } else {
382                                                 bprint (a,"^7 unleashes ^1RAGE\n");
383                                                 announce(attacker, "announcer/male/05kills.wav");
384                                         }
385                                 }
386                                 else if (attacker.killcount == 10)
387                                 {
388                                         if(sv_gentle) {
389                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
390                                         } else {
391                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");
392                                                 announce(attacker, "announcer/male/10kills.wav");
393                                         }
394                                 }
395                                 else if (attacker.killcount == 15)
396                                 {
397                                         if(sv_gentle) {
398                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
399                                         } else {
400                                                 bprint (a,"^7 executes ^1MAYHEM!\n");
401                                                 announce(attacker, "announcer/male/15kills.wav");
402                                         }
403                                 }
404                                 else if (attacker.killcount == 20)
405                                 {
406                                         if(sv_gentle) {
407                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
408                                         } else {
409                                                 bprint (a,"^7 is a ^1BERSERKER!\n");
410                                                 announce(attacker, "announcer/male/20kills.wav");
411                                         }
412                                 }
413                                 else if (attacker.killcount == 25)
414                                 {
415                                         if(sv_gentle) {
416                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
417                                         } else {
418                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");
419                                                 announce(attacker, "announcer/male/25kills.wav");
420                                         }
421                                 }
422                                 else if (attacker.killcount == 30)
423                                 {
424                                         if(sv_gentle) {
425                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
426                                         } else {
427                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
428                                                 announce(attacker, "announcer/male/30kills.wav");
429                                         }
430                                 }
431                         }
432                 }
433                 else
434                 {
435                         centerprint(targ, "^1Watch your step!\n\n\n");
436                         if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
437                                 bprint ("^1",s, "^1 ", inflictor.message, "\n");
438                         else if (deathtype == DEATH_DROWN)
439                                 if(sv_gentle)
440                                         bprint ("^1",s, "^1 was in the water for too long\n");
441                                 else
442                                         bprint ("^1",s, "^1 drowned\n");
443                         else if (deathtype == DEATH_SLIME)
444                                 bprint ("^1",s, "^1 was slimed\n");
445                         else if (deathtype == DEATH_LAVA)
446                                 if(sv_gentle)
447                                         bprint ("^1",s, "^1 found a hot place\n");
448                                 else
449                                         bprint ("^1",s, "^1 turned into hot slag\n");
450                         else if (deathtype == DEATH_FALL)
451                                 if(sv_gentle)
452                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");
453                                 else
454                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");
455                         else if (deathtype == DEATH_SHOOTING_STAR)
456                                 bprint ("^1",s, "^1 became a shooting star\n");
457                         else if (deathtype == DEATH_SWAMP)
458                                 if(sv_gentle)
459                                         bprint ("^1",s, "^1 discovered a swamp\n");
460                                 else
461                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");
462             else if(deathtype == DEATH_TURRET)
463                     bprint ("^1",s, "^1 was mowed down by a turret \n");
464                         else if(deathtype == DEATH_TOUCHEXPLODE)
465                                 bprint ("^1",s, "^1 died in an accident\n");
466                         else
467                                 if(sv_gentle)
468                                         bprint ("^1",s, "^1 needs a restart\n");
469                                 else
470                                         bprint ("^1",s, "^1 died\n");
471                         GiveFrags(targ, targ, -1);
472                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
473                                 announce(targ, "announcer/male/botlike.wav");
474                         }
475
476                         if (targ.killcount > 2)
477                                 if(sv_gentle)
478                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
479                                 else
480                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
481
482                         LogDeath("accident", deathtype, targ, targ);
483                 }
484                 targ.death_origin = targ.origin;
485                 if(targ != attacker)
486                         targ.killer_origin = attacker.origin;
487                 // FIXME: this should go in PutClientInServer
488                 if (targ.killcount)
489                         targ.killcount = 0;
490         }
491 }
492
493 // these are updated by each Damage call for use in button triggering and such
494 entity damage_targ;
495 entity damage_inflictor;
496 entity damage_attacker;
497
498 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
499 {
500         float mirrordamage;
501         float mirrorforce;
502         entity attacker_save;
503         mirrordamage = 0;
504         mirrorforce = 0;
505
506         if (gameover || targ.killcount == -666)
507                 return;
508
509         local entity oldself;
510         oldself = self;
511         self = targ;
512         damage_targ = targ;
513         damage_inflictor = inflictor;
514         damage_attacker = attacker;
515                 attacker_save = attacker;
516         
517         if(targ.classname == "player")
518                 if(targ.hook)
519                         if(targ.hook.aiment)
520                                 if(targ.hook.aiment == attacker)
521                                         RemoveGrapplingHook(targ); // STOP THAT, you parasite!
522
523         // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
524         if(DEATH_ISWEAPON(deathtype, WEP_HOOK))
525         {
526                 if(targ.classname == "player")
527                         if not(IsDifferentTeam(targ, attacker))
528                         {
529                                 self = oldself;
530                                 return;
531                         }
532         }
533
534         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
535         {
536                 // These are ALWAYS lethal
537                 // No damage modification here
538                 // Instead, prepare the victim for his death...
539                 targ.armorvalue = 0;
540                 targ.spawnshieldtime = 0;
541                 targ.health = 0.9; // this is < 1
542                 targ.flags -= targ.flags & FL_GODMODE;
543                 damage = 100000;
544         }
545         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
546         {
547                 // no processing
548         }
549         else
550         {
551                 if (targ.classname == "player")
552                 if (attacker.classname == "player")
553                 if (!targ.isbot)
554                 if (attacker.isbot)
555                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
556
557                 // nullify damage if teamplay is on
558                 if(deathtype != DEATH_TELEFRAG)
559                 if(attacker.classname == "player")
560                 {
561                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
562                         {
563                                 damage = 0;
564                                 force = '0 0 0';
565                         }
566                         else if(attacker.team == targ.team)
567                         {
568                                 if(teamplay == 1)
569                                         damage = 0;
570                                 else if(attacker != targ)
571                                 {
572                                         if(teamplay == 3)
573                                                 damage = 0;
574                                         else if(teamplay == 4)
575                                         {
576                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
577                                                 {
578                                                         mirrordamage = cvar("g_mirrordamage") * damage;
579                                                         mirrorforce = cvar("g_mirrordamage") * vlen(force);
580                                                         if(g_minstagib)
581                                                         {
582                                                                 if(cvar("g_friendlyfire") == 0)
583                                                                         damage = 0;
584                                                         }
585                                                         else
586                                                                 damage = cvar("g_friendlyfire") * damage;
587                                                         // mirrordamage will be used LATER
588                                                 }
589                                                 else
590                                                         damage = 0;
591                                         }
592                                 }
593                         }
594                 }
595
596                 if(targ.classname == "player")
597                 if(attacker.classname == "player")
598                 if(attacker != targ)
599                 {
600                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
601                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
602                 }
603
604                 if (g_minstagib)
605                 {
606                         if ((deathtype == DEATH_FALL)  ||
607                                 (deathtype == DEATH_DROWN) ||
608                                 (deathtype == DEATH_SLIME) ||
609                                 (deathtype == DEATH_LAVA))
610                         {
611                                 self = oldself;
612                                 return;
613                         }
614                         if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
615                         {
616                                 targ.armorvalue -= 1;
617                                 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
618                                 damage = 0;
619                                 targ.hitsound += 1;
620                         }
621                         if (DEATH_ISWEAPON(deathtype, WEP_LASER))
622                         {
623                                 damage = 0;
624                                 if (targ != attacker)
625                                 {
626                                         if (targ.classname == "player")
627                                                 centerprint(attacker, "Secondary fire inflicts no damage!\n");
628                                         damage = 0;
629                                         mirrordamage = 0;
630                                         force = '0 0 0';
631                                         // keep mirrorforce
632                                         attacker = targ;
633                                 }
634                         }
635                 }
636
637                 // apply strength multiplier
638                 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
639                 {
640                         if(targ == attacker)
641                         {
642                                 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
643                                 force = force * cvar("g_balance_powerup_strength_selfforce");
644                         }
645                         else
646                         {
647                                 damage = damage * cvar("g_balance_powerup_strength_damage");
648                                 force = force * cvar("g_balance_powerup_strength_force");
649                         }
650                 }
651
652                 // apply invincibility multiplier
653                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
654                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
655
656                 if (targ == attacker)
657                         damage = damage * cvar("g_balance_selfdamagepercent");  // Partial damage if the attacker hits himself
658
659                 // CTF: reduce damage/force
660                 if(g_ctf)
661                 if(targ == attacker)
662                 if(targ.flagcarried)
663                 {
664                         damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
665                         force = force * cvar("g_ctf_flagcarrier_selfforce");
666                 }
667
668                 if(g_runematch)
669                 {
670                         // apply strength rune
671                         if (attacker.runes & RUNE_STRENGTH)
672                         {
673                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
674                                 {
675                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
676                                         force = force * cvar("g_balance_rune_strength_combo_force");
677                                 }
678                                 else
679                                 {
680                                         damage = damage * cvar("g_balance_rune_strength_damage");
681                                         force = force * cvar("g_balance_rune_strength_force");
682                                 }
683                         }
684                         else if (attacker.runes & CURSE_WEAK)
685                         {
686                                 damage = damage * cvar("g_balance_curse_weak_damage");
687                                 force = force * cvar("g_balance_curse_weak_force");
688                         }
689
690                         // apply defense rune
691                         if (targ.runes & RUNE_DEFENSE)
692                         {
693                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
694                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
695                                 else
696                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
697                         }
698                         else if (targ.runes & CURSE_VULNER)
699                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
700                 }
701
702                 // count the damage
703                 if(attacker)
704                 if(!targ.deadflag)
705                 if(targ.takedamage == DAMAGE_AIM)
706                 if(targ != attacker)
707                 if(targ.classname == "player")
708                 {
709                         if(IsDifferentTeam(targ, attacker))
710                         {
711                                 if(damage > 0)
712                                 {
713                                         if(targ.BUTTON_CHAT)
714                                                 attacker.typehitsound += 1;
715                                         else
716                                                 attacker.hitsound += 1;
717
718                                         damage_goodhits += 1;
719                                         damage_gooddamage += damage;
720
721                                         if not(DEATH_ISSPECIAL(deathtype))
722                                         {
723                                                 if(!g_minstagib)
724                                                 if(IsFlying(targ))
725                                                         yoda = 1;
726
727                                                 if(g_minstagib)
728                                                 if(targ.items & IT_STRENGTH)
729                                                         yoda = 1;
730
731                                                 // HEAD SHOT:
732                                                 // find height of hit on player axis
733                                                 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
734                                                 vector headmins, headmaxs, org;
735                                                 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
736                                                 headmins = org + '0.5 0 0' * targ.mins_x + '0 0.5 0' * targ.mins_y + '0 0 1' * targ.view_ofs_z;
737                                                 headmaxs = org + '0.5 0 0' * targ.maxs_x + '0 0.5 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
738                                                 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
739                                                 {
740                                                         damage *= 1 + damage_headshotbonus;
741                                                         headshot = 1;
742                                                         deathtype |= HITTYPE_HEADSHOT;
743                                                 }
744                                         }
745                                 }
746                         }
747                         else
748                         {
749                                 attacker.typehitsound += 1; // TODO possibly trigger teamkill complain sound!
750                                 if(time > attacker.teamkill_complain)
751                                 {
752                                         attacker.teamkill_complain = time + 5;
753                                         attacker.teamkill_soundtime = time + 0.4;
754                                         attacker.teamkill_soundsource = targ;
755                                 }
756                         }
757                 }
758         }
759
760         // apply push
761         if (self.damageforcescale)
762         if (vlen(force))
763         {
764                 self.velocity = self.velocity + self.damageforcescale * force;
765                 self.flags = self.flags - (self.flags & FL_ONGROUND);
766         }
767         // apply damage
768         if (damage != 0)
769         if (self.event_damage)
770                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
771         self = oldself;
772
773         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
774         {
775                 // Savage: vampire mode
776                 if (g_vampire)
777                 if (!g_minstagib)
778                 if (time > self.spawnshieldtime)
779                 {
780                         attacker.health += damage;
781                 }
782                 if(g_runematch)
783                 {
784                         if (attacker.runes & RUNE_VAMPIRE)
785                         {
786                         // apply vampire rune
787                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
788                                 {
789                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
790                                         attacker.health = bound(
791                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
792                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
793                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
794                                 }
795                                 else
796                                 {
797                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
798                                         attacker.health = bound(
799                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
800                                                                                         // empathy won't let you gain health in the same way...
801                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
802                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
803                                         }
804                         }
805                         // apply empathy curse
806                         else if (attacker.runes & CURSE_EMPATHY)
807                         {
808                                 attacker.health = bound(
809                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
810                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
811                                         attacker.health);
812                         }
813                 }
814         }
815
816         // apply mirror damage if any
817         if(mirrordamage > 0 || mirrorforce > 0)
818         {
819                 attacker = attacker_save;
820                 if(g_minstagib)
821                         if(mirrordamage > 0)
822                         {
823                                 // just lose extra LIVES, don't kill the player for mirror damage
824                                 if(attacker.armorvalue > 0)
825                                 {
826                                         attacker.armorvalue = attacker.armorvalue - 1;
827                                         centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
828                                         attacker.hitsound += 1;
829                                 }
830                                 mirrordamage = 0;
831                         }
832                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
833                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
834         }
835 }
836
837 vector NearestPointOnBox(entity box, vector org)
838 {
839         vector m1, m2, nearest;
840
841         m1 = box.mins + box.origin;
842         m2 = box.maxs + box.origin;
843
844         nearest_x = bound(m1_x, org_x, m2_x);
845         nearest_y = bound(m1_y, org_y, m2_y);
846         nearest_z = bound(m1_z, org_z, m2_z);
847
848         return nearest;
849 }
850
851 float RadiusDamage_running;
852 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
853 // Returns total damage applies to creatures
854 {
855         entity  targ;
856         float   finaldmg;
857         float   power;
858         vector  blastorigin;
859         vector  force;
860         vector  diff;
861         vector  center;
862         vector  nearest;
863         float   total_damage_to_creatures;
864         entity  next;
865
866         if(RadiusDamage_running)
867         {
868                 string save;
869                 print("RadiusDamage called recursively!\n");
870                 print("Expect stuff to go HORRIBLY wrong.\n");
871                 print("Causing a stack trace...\n");
872                 save = cvar_string("prvm_backtraceforwarnings");
873                 cvar_set("prvm_backtraceforwarnings", "1");
874                 fclose(-1); // calls VM_Warning
875                 cvar_set("prvm_backtraceforwarnings", save);
876                 return 0;
877         }
878
879         RadiusDamage_running = 1;
880
881         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
882         total_damage_to_creatures = 0;
883
884         targ = findradius (blastorigin, rad);
885         while (targ)
886         {
887                 next = targ.chain;
888                 if (targ != inflictor)
889                         if (ignore != targ)
890                         {
891                                 // LordHavoc: measure distance to nearest point on target (not origin)
892                                 // (this guarentees 100% damage on a touch impact)
893                                 nearest = NearestPointOnBox(targ, blastorigin);
894                                 diff = nearest - blastorigin;
895                                 // round up a little on the damage to ensure full damage on impacts
896                                 // and turn the distance into a fraction of the radius
897                                 power = 1 - ((vlen (diff) - 2) / rad);
898                                 //bprint(" ");
899                                 //bprint(ftos(power));
900                                 if (power > 0)
901                                 {
902                                         if (power > 1)
903                                                 power = 1;
904                                         finaldmg = coredamage * power + edgedamage * (1 - power);
905                                         if (finaldmg > 0)
906                                         {
907                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
908                                                 // if it's a player, use the view origin as reference
909                                                 if (targ.classname == "player")
910                                                         center = targ.origin + targ.view_ofs;
911                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
912                                                 // test line of sight to multiple positions on box,
913                                                 // and do damage if any of them hit
914                                                 local float c;
915                                                 c = ceil(finaldmg / 10);
916                                                 if (c > 20)
917                                                         c = 20;
918                                                 while (c > 0)
919                                                 {
920                                                         c = c - 1;
921                                                         traceline(blastorigin, nearest, TRUE, inflictor);
922                                                         if (trace_fraction == 1 || trace_ent == targ
923                                                             || cvar("g_throughfloor"))
924                                                         {
925                                                                 if(targ.iscreature)
926                                                                         total_damage_to_creatures += finaldmg;
927                                                                 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
928                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
929                                                                 else
930                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
931                                                                 break;
932                                                         }
933                                                         nearest_x = targ.mins_x + random() * targ.size_x;
934                                                         nearest_y = targ.mins_y + random() * targ.size_y;
935                                                         nearest_z = targ.mins_z + random() * targ.size_z;
936                                                 }
937                                         }
938                                 }
939                         }
940                 targ = next;
941         }
942
943         RadiusDamage_running = 0;
944
945         return total_damage_to_creatures;
946 }