Added the capture-counter and changed the CTF scoreboard to display the caps.
[divverent/nexuiz.git] / data / qcsrc / server / g_damage.qc
1
2 float checkrules_firstblood;
3
4 .float announcetime;
5 float yoda;
6 void announce(entity player, string msg)
7 {
8         if(time > player.announcetime)
9         if(clienttype(player) == CLIENTTYPE_REAL)
10         {
11                 player.announcetime = time + 0.3;
12                 play2(player, msg);
13         }
14 }
15
16 float IsDifferentTeam(entity a, entity b)
17 {
18         if(teams_matter)
19         {
20                 if(a.team == b.team)
21                         return 0;
22         }
23         else
24         {
25                 if(a == b)
26                         return 0;
27         }
28         return 1;
29 }
30
31 float IsFlying(entity a)
32 {
33         if(a.flags & FL_ONGROUND)
34                 return 0;
35         if(a.waterlevel >= 2)
36                 return 0;
37         traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
38         if(trace_fraction < 1)
39                 return 0;
40         return 1;
41 }
42
43 void UpdateFrags(entity player, float f)
44 {
45         player.frags += f;
46         player.totalfrags += f;
47 }
48
49 void GiveFrags (entity attacker, entity targ, float f)
50 {
51         if(gameover) return;
52
53         if(g_arena)
54                 if(cvar("g_arena_roundbased"))
55                         return;
56
57         if(g_domination)
58         {
59                 if(cvar("g_domination_disable_frags"))
60                         if(f > 0)
61                                 return;
62         }
63         else if(g_runematch)
64         {
65                 if(f > 0)
66                         f = RunematchHandleFrags(attacker, targ, f);
67         }
68         else if(g_keyhunt)
69         {
70                 f = kh_HandleFrags(attacker, targ, f);
71         }
72         else if(g_lms)
73         {
74                 // count remaining lives, not frags in lms
75                 targ.frags -= 1;
76                 // keep track of the worst players lives
77                 if(targ.frags < lms_lowest_lives)
78                         lms_lowest_lives = targ.frags;
79                 // player has no more lives left
80                 if (!targ.frags)
81                 {
82                         if(!lms_next_place)
83                                 lms_next_place = player_count;
84                         targ.frags = -lms_next_place;
85                         lms_next_place -= 1;
86                 }
87                 return;
88         }
89
90         if(f)
91                 UpdateFrags(attacker, f);
92 }
93
94 string AppendItemcodes(string s, entity player)
95 {
96         float w;
97         w = player.weapon;
98         //if(w == 0)
99         //      w = player.switchweapon;
100         if(w == 0)
101                 w = player.cnt; // previous weapon!
102         s = strcat(s, ftos(W_ItemCode(w)));
103         if(time < player.strength_finished)
104                 s = strcat(s, "S");
105         if(time < player.invincible_finished)
106                 s = strcat(s, "I");
107         if(player.flagcarried != world)
108                 s = strcat(s, "F");
109         if(player.BUTTON_CHAT)
110                 s = strcat(s, "T");
111         if(player.kh_next)
112                 s = strcat(s, "K");
113         if(player.runes)
114                 s = strcat(s, "|", ftos(player.runes));
115         return s;
116 }
117
118 void LogDeath(string mode, float deathtype, entity killer, entity killed)
119 {
120         string s;
121         if(!cvar("sv_eventlog"))
122                 return;
123         s = strcat(":kill:", mode);
124         s = strcat(s, ":", ftos(killer.playerid));
125         s = strcat(s, ":", ftos(killed.playerid));
126         s = strcat(s, ":type=", ftos(deathtype));
127         s = strcat(s, ":items=");
128         s = AppendItemcodes(s, killer);
129         if(killed != killer)
130         {
131                 s = strcat(s, ":victimitems=");
132                 s = AppendItemcodes(s, killed);
133         }
134         GameLogEcho(s, FALSE);
135 }
136
137 void Obituary (entity attacker, entity targ, float deathtype)
138 {
139         string  s, a;
140
141         if (targ.classname == "player" || targ.classname == "corpse")
142         {
143                 if (targ.classname == "corpse")
144                         s = "A corpse";
145                 else
146                         s = targ.netname;
147                 a = attacker.netname;
148
149                 if (targ == attacker)
150                 {
151                         if (deathtype == DEATH_TEAMCHANGE) {
152                                 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
153                         } else if (deathtype == DEATH_AUTOTEAMCHANGE) {
154                                 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
155                                 return;
156                         } else if (deathtype == DEATH_CAMP) {
157                                 if(sv_gentle)
158                                         centerprint(targ, "^1Reconsider your tactics, camper!\n\n\n");
159                                 else
160                                         centerprint(targ, "^1Die camper!\n\n\n");
161                         } else if (deathtype == DEATH_NOAMMO) {
162                                 if(sv_gentle)
163                                         centerprint(targ, "^1You are reinserted into the game for running out of ammo...\n\n\n");
164                                 else
165                                         centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
166                         } else if (deathtype == DEATH_ROT) {
167                                 if(sv_gentle)
168                                         centerprint(targ, "^1You need to preserve your health\n\n\n");
169                                 else
170                                         centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
171                         } else if (deathtype == DEATH_MIRRORDAMAGE) {
172                                 if(sv_gentle)                           
173                                         centerprint(targ, "^1Don't go against team mates!\n\n\n");
174                                 else
175                                         centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
176                         } else {
177                                 if(sv_gentle)
178                                         centerprint(targ, "^1You need to be more careful!\n\n\n");
179                                 else
180                                         centerprint(targ, "^1You killed your own dumb self!\n\n\n");
181                         }
182
183                         if(sv_gentle) {
184                                 if (deathtype == DEATH_CAMP)
185                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
186                                 else if (deathtype == DEATH_MIRRORDAMAGE)
187                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
188                                 else
189                                         bprint ("^1",s, "^1 will be reinserted into the game due to his own actions\n");
190         
191                                 if(deathtype != DEATH_TEAMCHANGE)
192                                 {
193                                         LogDeath("suicide", deathtype, targ, targ);
194                                         GiveFrags(attacker, targ, -1);
195                                 }
196                                 if (targ.killcount > 2)
197                                         bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," scoring spree\n");
198                         } else {
199
200                                 if (deathtype == IT_GRENADE_LAUNCHER)
201                                         bprint ("^1",s, "^1 detonated\n");
202                                 else if (deathtype == IT_ELECTRO)
203                                         bprint ("^1",s, "^1 played with plasma\n");
204                                 else if (deathtype == IT_ROCKET_LAUNCHER)
205                                         bprint ("^1",s, "^1 exploded\n");
206                                 else if (deathtype == DEATH_KILL)
207                                         bprint ("^1",s, "^1 couldn't take it anymore\n");
208                                 else if (deathtype == DEATH_ROT)
209                                         bprint ("^1",s, "^1 died\n");
210                                 else if (deathtype == DEATH_NOAMMO)
211                                 {
212                                         bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
213                                         //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
214                                 }
215                                 else if (deathtype == DEATH_CAMP)
216                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
217                                 else if (deathtype == DEATH_MIRRORDAMAGE)
218                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
219                                 else if (deathtype != DEATH_TEAMCHANGE)
220                                         bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
221         
222                                 if(deathtype != DEATH_TEAMCHANGE)
223                                 {
224                                         LogDeath("suicide", deathtype, targ, targ);
225                                         GiveFrags(attacker, targ, -1);
226                                 }
227                                 if (targ.killcount > 2)
228                                         bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
229                         }
230                 }
231                 else if (attacker.classname == "player" || attacker.classname == "gib")
232                 {
233                         if(teamplay && attacker.team == targ.team)
234                         {
235                                 if(sv_gentle) {
236                                         centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
237                                         bprint ("^1", a, "^1 took action against a teammate\n");
238                                 } else {                                
239                                         centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
240                                         bprint ("^1", a, "^1 mows down a teammate\n");
241                                 }
242                                 GiveFrags(attacker, targ, -1);
243                                 if (targ.killcount > 2) {
244                                         if(sv_gentle)
245                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
246                                         else
247                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
248                                 }
249                                 if (attacker.killcount > 2) {
250                                         if(sv_gentle)
251                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
252                                         else
253                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
254                                 }
255                                 attacker.killcount = 0;
256
257                                 LogDeath("tk", deathtype, attacker, targ);
258                         }
259                         else
260                         {
261                                 if (!checkrules_firstblood)
262                                 {
263                                         checkrules_firstblood = TRUE;
264                                         //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
265                                         //if (g_minstagib)
266                                                 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
267                                         if(sv_gentle)
268                                                 bprint("^1",a, "^1 was the first to score", "\n");
269                                         else
270                                                 bprint("^1",a, "^1 drew first blood", "\n");
271                                 }
272
273                                 if(sv_gentle > 0) {
274                                         centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
275                                         centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
276                                 } else {
277                                         centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
278                                         centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
279                                 }
280
281                                 if(sv_gentle) {
282                                         bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
283                                 } else {
284                                         if (deathtype == IT_LASER)
285                                                 bprint ("^1",s, "^1 was blasted by ", a, "\n");
286                                         else if (deathtype == IT_UZI)
287                                                 bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
288                                         else if (deathtype == IT_SHOTGUN)
289                                                 bprint ("^1",s, "^1 was gunned by ", a, "\n");
290                                         else if (deathtype == IT_GRENADE_LAUNCHER)
291                                                 bprint ("^1", s, "^1 was blasted by ", a, "\n");
292                                         else if (deathtype == IT_ELECTRO)
293                                                 bprint ("^1",s, "^1 was blasted by ", a, "\n");
294                                         else if (deathtype == IT_CRYLINK)
295                                                 bprint ("^1",s, "^1 was blasted by ", a, "\n");
296                                         else if (deathtype == IT_NEX)
297                                                 bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
298                                         else if (deathtype == IT_HAGAR)
299                                                 bprint ("^1",s, "^1 was pummeled by ", a, "\n");
300                                         else if (deathtype == IT_ROCKET_LAUNCHER)
301                                                 bprint ("^1",s, "^1 was blasted by ", a, "\n");
302                                         else if (deathtype == DEATH_TELEFRAG)
303                                                 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
304                                         else if (deathtype == DEATH_DROWN)
305                                                 bprint ("^1",s, "^1 was drowned by ", a, "\n");
306                                         else if (deathtype == DEATH_SLIME)
307                                                 bprint ("^1",s, "^1 was slimed by ", a, "\n");
308                                         else if (deathtype == DEATH_LAVA)
309                                                 bprint ("^1",s, "^1 was cooked by ", a, "\n");
310                                         else if (deathtype == DEATH_FALL)
311                                                 bprint ("^1",s, "^1 was grounded by ", a, "\n");
312                                         else if (deathtype == DEATH_SHOOTING_STAR)
313                                                 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
314                                         else if (deathtype == DEATH_SWAMP)
315                                                 bprint ("^1",s, "^1 was conserved by ", a, "\n");
316                                         else if (deathtype == DEATH_HURTTRIGGER)
317                                                 bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
318                                         else
319                                                 bprint ("^1",s, "^1 was fragged by ", a, "\n");
320                                 }
321                                 if(g_ctf && targ.flagcarried)
322                                         GiveFrags(attacker, targ, cvar("g_ctf_flagscore_kill"));
323                                 else
324                                         GiveFrags(attacker, targ, 1);
325                                 if (targ.killcount > 2) {
326                                         if(sv_gentle)
327                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
328                                         else
329                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
330                                 }
331                                 attacker.killcount = attacker.killcount + 1;
332                                 if (attacker.killcount > 2) {
333                                         if(sv_gentle)
334                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
335                                         else
336                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
337                                 }
338
339                                 LogDeath("frag", deathtype, attacker, targ);
340
341                                 if (attacker.killcount == 3)
342                                 {
343                                         if(sv_gentle) {
344                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
345                                         } else {
346                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
347                                                 announce(attacker, "announcer/male/03kills.ogg");
348                                         }
349                                 }
350                                 else if (attacker.killcount == 5)
351                                 {
352                                         if(sv_gentle) {
353                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
354                                         } else {
355                                                 bprint (a,"^7 unleashes ^1RAGE\n");
356                                                 announce(attacker, "announcer/male/05kills.ogg");
357                                         }
358                                 }
359                                 else if (attacker.killcount == 10)
360                                 {
361                                         if(sv_gentle) {
362                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
363                                         } else {
364                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");
365                                                 announce(attacker, "announcer/male/10kills.ogg");
366                                         }
367                                 }
368                                 else if (attacker.killcount == 15)
369                                 {
370                                         if(sv_gentle) {
371                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
372                                         } else {
373                                                 bprint (a,"^7 executes ^1MAYHEM!\n");
374                                                 announce(attacker, "announcer/male/15kills.ogg");
375                                         }
376                                 }
377                                 else if (attacker.killcount == 20)
378                                 {
379                                         if(sv_gentle) {
380                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
381                                         } else {
382                                                 bprint (a,"^7 is a ^1BERSERKER!\n");
383                                                 announce(attacker, "announcer/male/20kills.ogg");
384                                         }
385                                 }
386                                 else if (attacker.killcount == 25)
387                                 {
388                                         if(sv_gentle) {
389                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
390                                         } else {
391                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");
392                                                 announce(attacker, "announcer/male/25kills.ogg");
393                                         }
394                                 }
395                                 else if (attacker.killcount == 30)
396                                 {
397                                         if(sv_gentle) {
398                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
399                                         } else {
400                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
401                                                 announce(attacker, "announcer/male/30kills.ogg");
402                                         }
403                                 }
404                         }
405                 }
406                 else
407                 {
408                         centerprint(targ, "^1Watch your step!\n\n\n");
409                         if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
410                                 bprint ("^1",s, "^1 ", attacker.message, "\n");
411                         else if (deathtype == DEATH_DROWN)
412                                 if(sv_gentle)
413                                         bprint ("^1",s, "^1 was in the water for too long\n");
414                                 else
415                                         bprint ("^1",s, "^1 drowned\n");
416                         else if (deathtype == DEATH_SLIME)
417                                 bprint ("^1",s, "^1 was slimed\n");
418                         else if (deathtype == DEATH_LAVA)
419                                 if(sv_gentle)
420                                         bprint ("^1",s, "^1 found a hot place\n");
421                                 else
422                                         bprint ("^1",s, "^1 turned into hot slag\n");
423                         else if (deathtype == DEATH_FALL)
424                                 if(sv_gentle)
425                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");
426                                 else
427                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");
428                         else if (deathtype == DEATH_SHOOTING_STAR)
429                                 bprint ("^1",s, "^1 became a shooting star\n");
430                         else if (deathtype == DEATH_SWAMP)
431                                 if(sv_gentle)
432                                         bprint ("^1",s, "^1 discovered a swamp\n");
433                                 else
434                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");
435                         else
436                                 if(sv_gentle)
437                                         bprint ("^1",s, "^1 needs a restart\n");
438                                 else
439                                         bprint ("^1",s, "^1 died\n");
440                         GiveFrags(targ, targ, -1);
441                         if(targ.frags == -5) {
442                                 announce(targ, "announcer/male/botlike.ogg");
443                         }
444
445                         if (targ.killcount > 2)
446                                 if(sv_gentle)
447                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
448                                 else
449                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
450
451                         LogDeath("accident", deathtype, targ, targ);
452                 }
453                 targ.death_origin = targ.origin;
454                 if(targ != attacker)
455                         targ.killer_origin = attacker.origin;
456                 // FIXME: this should go in PutClientInServer
457                 if (targ.killcount)
458                         targ.killcount = 0;
459         }
460 }
461
462 // these are updated by each Damage call for use in button triggering and such
463 entity damage_targ;
464 entity damage_inflictor;
465 entity damage_attacker;
466
467 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
468 {
469         float mirrordamage;
470         float mirrorforce;
471         entity attacker_save;
472         mirrordamage = 0;
473         mirrorforce = 0;
474
475         if (gameover || targ.killcount == -666)
476                 return;
477
478         local entity oldself;
479         oldself = self;
480         self = targ;
481         damage_targ = targ;
482         damage_inflictor = inflictor;
483         damage_attacker = attacker;
484                 attacker_save = attacker;
485
486         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
487         {
488                 // These are ALWAYS lethal
489                 // No damage modification here
490                 // Instead, prepare the victim for his death...
491                 targ.armorvalue = 0;
492                 targ.spawnshieldtime = 0;
493                 targ.health = 1;
494                 targ.flags -= targ.flags & FL_GODMODE;
495                 damage = 100000;
496         }
497         else
498         {
499                 if (targ.classname == "player")
500                 if (attacker.classname == "player")
501                 if (!targ.isbot)
502                 if (attacker.isbot)
503                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
504
505                 // nullify damage if teamplay is on
506                 if(deathtype != DEATH_TELEFRAG)
507                 if(attacker.team == targ.team)
508                 if(attacker.classname == "player")
509                 {
510                         if(teamplay == 1)
511                                 damage = 0;
512                         else if(attacker != targ)
513                         {
514                                 if(teamplay == 3)
515                                         damage = 0;
516                                 else if(teamplay == 4)
517                                 {
518                                         if(targ.classname == "player" && targ.deadflag == DEAD_NO)
519                                         {
520                                                 mirrordamage = cvar("g_mirrordamage") * damage;
521                                                 mirrorforce = cvar("g_mirrordamage") * vlen(force);
522                                                 if(g_minstagib)
523                                                 {
524                                                         if(cvar("g_friendlyfire") == 0)
525                                                                 damage = 0;
526                                                 }
527                                                 else
528                                                         damage = cvar("g_friendlyfire") * damage;
529                                                 // mirrordamage will be used LATER
530                                         }
531                                         else
532                                                 damage = 0;
533                                 }
534                         }
535                 }
536
537                 if(g_lms)
538                 if(targ.classname == "player")
539                 if(attacker.classname == "player")
540                 if(attacker != targ)
541                 {
542                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
543                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
544                 }
545
546                 if(targ != attacker)
547                 if(!targ.deadflag)
548                 if(damage > 0)
549                 if(targ.classname == "player")
550                 if(attacker)
551                         attacker.hitsound += 1;
552
553                 if (g_minstagib)
554                 {
555                         if ((deathtype == DEATH_FALL)  ||
556                                 (deathtype == DEATH_DROWN) ||
557                                 (deathtype == DEATH_SLIME) ||
558                                 (deathtype == DEATH_LAVA))
559                                 return;
560                         if (targ.armorvalue && (deathtype == IT_NEX) && damage)
561                         {
562                                 targ.armorvalue -= 1;
563                                 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
564                                 damage = 0;
565                                 targ.hitsound += 1;
566                         }
567                         else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
568                         {
569                                 if(clienttype(attacker) == CLIENTTYPE_REAL)
570                                         if(IsDifferentTeam(targ, attacker))
571                                                 yoda = 1;
572                         }
573                         if (deathtype == IT_LASER)
574                         {
575                                 damage = 0;
576                                 if (targ != attacker)
577                                 {
578                                         if (targ.classname == "player")
579                                                 centerprint(attacker, "Secondary fire inflicts no damage!\n");
580                                         damage = 0;
581                                         mirrordamage = 0;
582                                         force = '0 0 0';
583                                         // keep mirrorforce
584                                         attacker = targ;
585                                 }
586                         }
587                 } else {
588                         if (!targ.deadflag)
589                                 if(targ.takedamage == DAMAGE_AIM)
590                                         if(IsFlying(targ))
591                                                 if(IsDifferentTeam(targ, attacker))
592                                                         yoda = 1;
593                 }
594
595                 // apply strength multiplier
596                 if (attacker.items & IT_STRENGTH && !g_minstagib)
597                 {
598                         damage = damage * cvar("g_balance_powerup_strength_damage");
599                         force = force * cvar("g_balance_powerup_strength_force");
600                 }
601                 // apply invincibility multiplier
602                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
603                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
604
605
606                 if(g_runematch)
607                 {
608                         // apply strength rune
609                         if (attacker.runes & RUNE_STRENGTH)
610                         {
611                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
612                                 {
613                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
614                                         force = force * cvar("g_balance_rune_strength_combo_force");
615                                 }
616                                 else
617                                 {
618                                         damage = damage * cvar("g_balance_rune_strength_damage");
619                                         force = force * cvar("g_balance_rune_strength_force");
620                                 }
621                         }
622                         else if (attacker.runes & CURSE_WEAK)
623                         {
624                                 damage = damage * cvar("g_balance_curse_weak_damage");
625                                 force = force * cvar("g_balance_curse_weak_force");
626                         }
627
628                         // apply defense rune
629                         if (targ.runes & RUNE_DEFENSE)
630                         {
631                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
632                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
633                                 else
634                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
635                         }
636                         else if (targ.runes & CURSE_VULNER)
637                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
638                 }
639         }
640
641         // apply push
642         if (self.damageforcescale)
643         if (vlen(force))
644         {
645                 self.velocity = self.velocity + self.damageforcescale * force;
646                 self.flags = self.flags - (self.flags & FL_ONGROUND);
647         }
648         // apply damage
649         if (self.event_damage)
650                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
651         self = oldself;
652
653         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
654         {
655                 // Savage: vampire mode
656                 if (g_vampire)
657                 if (!g_minstagib)
658                 if (!g_instagib)
659                 if (time > self.spawnshieldtime)
660                 {
661                         attacker.health += damage;
662                 }
663                 if(g_runematch)
664                 {
665                         if (attacker.runes & RUNE_VAMPIRE)
666                         {
667                         // apply vampire rune
668                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
669                                 {
670                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
671                                         attacker.health = bound(
672                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
673                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
674                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
675                                 }
676                                 else
677                                 {
678                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
679                                         attacker.health = bound(
680                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
681                                                                                         // empathy won't let you gain health in the same way...
682                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
683                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
684                                         }
685                         }
686                         // apply empathy curse
687                         else if (attacker.runes & CURSE_EMPATHY)
688                         {
689                                 attacker.health = bound(
690                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
691                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
692                                         attacker.health);
693                         }
694                 }
695         }
696
697         // apply mirror damage if any
698         if(mirrordamage > 0 || mirrorforce > 0)
699         {
700                 attacker = attacker_save;
701                 if(g_minstagib)
702                         if(mirrordamage > 0)
703                         {
704                                 // just lose extra LIVES, don't kill the player for mirror damage
705                                 if(attacker.armorvalue > 0)
706                                 {
707                                         attacker.armorvalue = attacker.armorvalue - 1;
708                                         centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
709                                         attacker.hitsound += 1;
710                                 }
711                                 mirrordamage = 0;
712                         }
713                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
714                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
715         }
716 }
717
718 vector NearestPointOnBox(entity box, vector org)
719 {
720         vector m1, m2, nearest;
721
722         m1 = box.mins + box.origin;
723         m2 = box.maxs + box.origin;
724
725         nearest_x = bound(m1_x, org_x, m2_x);
726         nearest_y = bound(m1_y, org_y, m2_y);
727         nearest_z = bound(m1_z, org_z, m2_z);
728
729         return nearest;
730 }
731
732 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
733 // Returns total damage applies to creatures
734 {
735         entity  targ;
736         float   finaldmg;
737         float   power;
738         vector  blastorigin;
739         vector  force;
740         vector  diff;
741         vector  center;
742         vector  nearest;
743         float   total_damage_to_creatures;
744
745         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
746         total_damage_to_creatures = 0;
747
748         targ = findradius (blastorigin, rad);
749         while (targ)
750         {
751                 if (targ != inflictor)
752                         if (ignore != targ)
753                         {
754                                 // LordHavoc: measure distance to nearest point on target (not origin)
755                                 // (this guarentees 100% damage on a touch impact)
756                                 nearest = NearestPointOnBox(targ, blastorigin);
757                                 diff = nearest - blastorigin;
758                                 // round up a little on the damage to ensure full damage on impacts
759                                 // and turn the distance into a fraction of the radius
760                                 power = 1 - ((vlen (diff) - 2) / rad);
761                                 //bprint(" ");
762                                 //bprint(ftos(power));
763                                 if (power > 0)
764                                 {
765                                         if (power > 1)
766                                                 power = 1;
767                                         finaldmg = coredamage * power + edgedamage * (1 - power);
768                                         if (finaldmg > 0)
769                                         {
770                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
771                                                 // if it's a player, use the view origin as reference
772                                                 if (targ.classname == "player")
773                                                         center = targ.origin + targ.view_ofs;
774                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
775                                                 if (targ == attacker)
776                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
777                                                 // test line of sight to multiple positions on box,
778                                                 // and do damage if any of them hit
779                                                 local float c;
780                                                 c = ceil(finaldmg / 10);
781                                                 if (c > 20)
782                                                         c = 20;
783                                                 while (c > 0)
784                                                 {
785                                                         c = c - 1;
786                                                         traceline(blastorigin, nearest, TRUE, inflictor);
787                                                         if (trace_fraction == 1 || trace_ent == targ
788                                                             || cvar("g_throughfloor"))
789                                                         {
790                                                                 if(targ.iscreature)
791                                                                         total_damage_to_creatures += finaldmg;
792                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
793                                                                 break;
794                                                         }
795                                                         nearest_x = targ.mins_x + random() * targ.size_x;
796                                                         nearest_y = targ.mins_y + random() * targ.size_y;
797                                                         nearest_z = targ.mins_z + random() * targ.size_z;
798                                                 }
799                                         }
800                                 }
801                         }
802                 targ = targ.chain;
803         }
804
805         return total_damage_to_creatures;
806 }