change all function declarations (except builtins and data types) to ANSI C-like...
[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
322                                 GiveFrags(attacker, targ, 1);
323                                 if (targ.killcount > 2) {
324                                         if(sv_gentle)
325                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
326                                         else
327                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
328                                 }
329                                 attacker.killcount = attacker.killcount + 1;
330                                 if (attacker.killcount > 2) {
331                                         if(sv_gentle)
332                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
333                                         else
334                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
335                                 }
336
337                                 LogDeath("frag", deathtype, attacker, targ);
338
339                                 if (attacker.killcount == 3)
340                                 {
341                                         if(sv_gentle) {
342                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
343                                         } else {
344                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
345                                                 announce(attacker, "announcer/male/03kills.ogg");
346                                         }
347                                 }
348                                 else if (attacker.killcount == 5)
349                                 {
350                                         if(sv_gentle) {
351                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
352                                         } else {
353                                                 bprint (a,"^7 unleashes ^1RAGE\n");
354                                                 announce(attacker, "announcer/male/05kills.ogg");
355                                         }
356                                 }
357                                 else if (attacker.killcount == 10)
358                                 {
359                                         if(sv_gentle) {
360                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
361                                         } else {
362                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");
363                                                 announce(attacker, "announcer/male/10kills.ogg");
364                                         }
365                                 }
366                                 else if (attacker.killcount == 15)
367                                 {
368                                         if(sv_gentle) {
369                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
370                                         } else {
371                                                 bprint (a,"^7 executes ^1MAYHEM!\n");
372                                                 announce(attacker, "announcer/male/15kills.ogg");
373                                         }
374                                 }
375                                 else if (attacker.killcount == 20)
376                                 {
377                                         if(sv_gentle) {
378                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
379                                         } else {
380                                                 bprint (a,"^7 is a ^1BERSERKER!\n");
381                                                 announce(attacker, "announcer/male/20kills.ogg");
382                                         }
383                                 }
384                                 else if (attacker.killcount == 25)
385                                 {
386                                         if(sv_gentle) {
387                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
388                                         } else {
389                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");
390                                                 announce(attacker, "announcer/male/25kills.ogg");
391                                         }
392                                 }
393                                 else if (attacker.killcount == 30)
394                                 {
395                                         if(sv_gentle) {
396                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
397                                         } else {
398                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
399                                                 announce(attacker, "announcer/male/30kills.ogg");
400                                         }
401                                 }
402                         }
403                 }
404                 else
405                 {
406                         centerprint(targ, "^1Watch your step!\n\n\n");
407                         if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
408                                 bprint ("^1",s, "^1 ", attacker.message, "\n");
409                         else if (deathtype == DEATH_DROWN)
410                                 if(sv_gentle)
411                                         bprint ("^1",s, "^1 was in the water for too long\n");
412                                 else
413                                         bprint ("^1",s, "^1 drowned\n");
414                         else if (deathtype == DEATH_SLIME)
415                                 bprint ("^1",s, "^1 was slimed\n");
416                         else if (deathtype == DEATH_LAVA)
417                                 if(sv_gentle)
418                                         bprint ("^1",s, "^1 found a hot place\n");
419                                 else
420                                         bprint ("^1",s, "^1 turned into hot slag\n");
421                         else if (deathtype == DEATH_FALL)
422                                 if(sv_gentle)
423                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");
424                                 else
425                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");
426                         else if (deathtype == DEATH_SHOOTING_STAR)
427                                 bprint ("^1",s, "^1 became a shooting star\n");
428                         else if (deathtype == DEATH_SWAMP)
429                                 if(sv_gentle)
430                                         bprint ("^1",s, "^1 discovered a swamp\n");
431                                 else
432                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");
433                         else
434                                 if(sv_gentle)
435                                         bprint ("^1",s, "^1 needs a restart\n");
436                                 else
437                                         bprint ("^1",s, "^1 died\n");
438                         GiveFrags(targ, targ, -1);
439                         if(targ.frags == -5) {
440                                 announce(targ, "announcer/male/botlike.ogg");
441                         }
442
443                         if (targ.killcount > 2)
444                                 if(sv_gentle)
445                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
446                                 else
447                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
448
449                         LogDeath("accident", deathtype, targ, targ);
450                 }
451                 targ.death_origin = targ.origin;
452                 if(targ != attacker)
453                         targ.killer_origin = attacker.origin;
454                 // FIXME: this should go in PutClientInServer
455                 if (targ.killcount)
456                         targ.killcount = 0;
457         }
458 }
459
460 // these are updated by each Damage call for use in button triggering and such
461 entity damage_targ;
462 entity damage_inflictor;
463 entity damage_attacker;
464
465 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
466 {
467         float mirrordamage;
468         float mirrorforce;
469         entity attacker_save;
470         mirrordamage = 0;
471         mirrorforce = 0;
472
473         if (gameover || targ.killcount == -666)
474                 return;
475
476         local entity oldself;
477         oldself = self;
478         self = targ;
479         damage_targ = targ;
480         damage_inflictor = inflictor;
481         damage_attacker = attacker;
482                 attacker_save = attacker;
483
484         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
485         {
486                 // These are ALWAYS lethal
487                 // No damage modification here
488                 // Instead, prepare the victim for his death...
489                 targ.armorvalue = 0;
490                 targ.spawnshieldtime = 0;
491                 targ.health = 1;
492                 targ.flags -= targ.flags & FL_GODMODE;
493                 damage = 100000;
494         }
495         else
496         {
497                 if (targ.classname == "player")
498                 if (attacker.classname == "player")
499                 if (!targ.isbot)
500                 if (attacker.isbot)
501                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
502
503                 // nullify damage if teamplay is on
504                 if(deathtype != DEATH_TELEFRAG)
505                 if(attacker.team == targ.team)
506                 if(attacker.classname == "player")
507                 {
508                         if(teamplay == 1)
509                                 damage = 0;
510                         else if(attacker != targ)
511                         {
512                                 if(teamplay == 3)
513                                         damage = 0;
514                                 else if(teamplay == 4)
515                                 {
516                                         if(targ.classname == "player" && targ.deadflag == DEAD_NO)
517                                         {
518                                                 mirrordamage = cvar("g_mirrordamage") * damage;
519                                                 mirrorforce = cvar("g_mirrordamage") * vlen(force);
520                                                 if(g_minstagib)
521                                                 {
522                                                         if(cvar("g_friendlyfire") == 0)
523                                                                 damage = 0;
524                                                 }
525                                                 else
526                                                         damage = cvar("g_friendlyfire") * damage;
527                                                 // mirrordamage will be used LATER
528                                         }
529                                         else
530                                                 damage = 0;
531                                 }
532                         }
533                 }
534
535                 if(g_lms)
536                 if(targ.classname == "player")
537                 if(attacker.classname == "player")
538                 if(attacker != targ)
539                 {
540                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
541                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
542                 }
543
544                 if(targ != attacker)
545                 if(!targ.deadflag)
546                 if(damage > 0)
547                 if(targ.classname == "player")
548                 if(attacker)
549                         attacker.hitsound += 1;
550
551                 if (g_minstagib)
552                 {
553                         if ((deathtype == DEATH_FALL)  ||
554                                 (deathtype == DEATH_DROWN) ||
555                                 (deathtype == DEATH_SLIME) ||
556                                 (deathtype == DEATH_LAVA))
557                                 return;
558                         if (targ.armorvalue && (deathtype == IT_NEX) && damage)
559                         {
560                                 targ.armorvalue -= 1;
561                                 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
562                                 damage = 0;
563                                 targ.hitsound += 1;
564                         }
565                         else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
566                         {
567                                 if(clienttype(attacker) == CLIENTTYPE_REAL)
568                                         if(IsDifferentTeam(targ, attacker))
569                                                 yoda = 1;
570                         }
571                         if (deathtype == IT_LASER)
572                         {
573                                 damage = 0;
574                                 if (targ != attacker)
575                                 {
576                                         if (targ.classname == "player")
577                                                 centerprint(attacker, "Secondary fire inflicts no damage!\n");
578                                         damage = 0;
579                                         mirrordamage = 0;
580                                         force = '0 0 0';
581                                         // keep mirrorforce
582                                         attacker = targ;
583                                 }
584                         }
585                 } else {
586                         if (!targ.deadflag)
587                                 if(targ.takedamage == DAMAGE_AIM)
588                                         if(IsFlying(targ))
589                                                 if(IsDifferentTeam(targ, attacker))
590                                                         yoda = 1;
591                 }
592
593                 // apply strength multiplier
594                 if (attacker.items & IT_STRENGTH && !g_minstagib)
595                 {
596                         damage = damage * cvar("g_balance_powerup_strength_damage");
597                         force = force * cvar("g_balance_powerup_strength_force");
598                 }
599                 // apply invincibility multiplier
600                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
601                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
602
603
604                 if(g_runematch)
605                 {
606                         // apply strength rune
607                         if (attacker.runes & RUNE_STRENGTH)
608                         {
609                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
610                                 {
611                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
612                                         force = force * cvar("g_balance_rune_strength_combo_force");
613                                 }
614                                 else
615                                 {
616                                         damage = damage * cvar("g_balance_rune_strength_damage");
617                                         force = force * cvar("g_balance_rune_strength_force");
618                                 }
619                         }
620                         else if (attacker.runes & CURSE_WEAK)
621                         {
622                                 damage = damage * cvar("g_balance_curse_weak_damage");
623                                 force = force * cvar("g_balance_curse_weak_force");
624                         }
625
626                         // apply defense rune
627                         if (targ.runes & RUNE_DEFENSE)
628                         {
629                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
630                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
631                                 else
632                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
633                         }
634                         else if (targ.runes & CURSE_VULNER)
635                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
636                 }
637         }
638
639         // apply push
640         if (self.damageforcescale)
641         if (vlen(force))
642         {
643                 self.velocity = self.velocity + self.damageforcescale * force;
644                 self.flags = self.flags - (self.flags & FL_ONGROUND);
645         }
646         // apply damage
647         if (self.event_damage)
648                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
649         self = oldself;
650
651         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
652         {
653                 // Savage: vampire mode
654                 if (g_vampire)
655                 if (!g_minstagib)
656                 if (!g_instagib)
657                 if (time > self.spawnshieldtime)
658                 {
659                         attacker.health += damage;
660                 }
661                 if(g_runematch)
662                 {
663                         if (attacker.runes & RUNE_VAMPIRE)
664                         {
665                         // apply vampire rune
666                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
667                                 {
668                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
669                                         attacker.health = bound(
670                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
671                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
672                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
673                                 }
674                                 else
675                                 {
676                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
677                                         attacker.health = bound(
678                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
679                                                                                         // empathy won't let you gain health in the same way...
680                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
681                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
682                                         }
683                         }
684                         // apply empathy curse
685                         else if (attacker.runes & CURSE_EMPATHY)
686                         {
687                                 attacker.health = bound(
688                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
689                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
690                                         attacker.health);
691                         }
692                 }
693         }
694
695         // apply mirror damage if any
696         if(mirrordamage > 0 || mirrorforce > 0)
697         {
698                 attacker = attacker_save;
699                 if(g_minstagib)
700                         if(mirrordamage > 0)
701                         {
702                                 // just lose extra LIVES, don't kill the player for mirror damage
703                                 if(attacker.armorvalue > 0)
704                                 {
705                                         attacker.armorvalue = attacker.armorvalue - 1;
706                                         centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
707                                         attacker.hitsound += 1;
708                                 }
709                                 mirrordamage = 0;
710                         }
711                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
712                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
713         }
714 }
715
716 vector NearestPointOnBox(entity box, vector org)
717 {
718         vector m1, m2, nearest;
719
720         m1 = box.mins + box.origin;
721         m2 = box.maxs + box.origin;
722
723         nearest_x = bound(m1_x, org_x, m2_x);
724         nearest_y = bound(m1_y, org_y, m2_y);
725         nearest_z = bound(m1_z, org_z, m2_z);
726
727         return nearest;
728 }
729
730 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
731 // Returns total damage applies to creatures
732 {
733         entity  targ;
734         float   finaldmg;
735         float   power;
736         vector  blastorigin;
737         vector  force;
738         vector  diff;
739         vector  center;
740         vector  nearest;
741         float   total_damage_to_creatures;
742
743         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
744         total_damage_to_creatures = 0;
745
746         targ = findradius (blastorigin, rad);
747         while (targ)
748         {
749                 if (targ != inflictor)
750                         if (ignore != targ)
751                         {
752                                 // LordHavoc: measure distance to nearest point on target (not origin)
753                                 // (this guarentees 100% damage on a touch impact)
754                                 nearest = NearestPointOnBox(targ, blastorigin);
755                                 diff = nearest - blastorigin;
756                                 // round up a little on the damage to ensure full damage on impacts
757                                 // and turn the distance into a fraction of the radius
758                                 power = 1 - ((vlen (diff) - 2) / rad);
759                                 //bprint(" ");
760                                 //bprint(ftos(power));
761                                 if (power > 0)
762                                 {
763                                         if (power > 1)
764                                                 power = 1;
765                                         finaldmg = coredamage * power + edgedamage * (1 - power);
766                                         if (finaldmg > 0)
767                                         {
768                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
769                                                 // if it's a player, use the view origin as reference
770                                                 if (targ.classname == "player")
771                                                         center = targ.origin + targ.view_ofs;
772                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
773                                                 if (targ == attacker)
774                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
775                                                 // test line of sight to multiple positions on box,
776                                                 // and do damage if any of them hit
777                                                 local float c;
778                                                 c = ceil(finaldmg / 10);
779                                                 if (c > 20)
780                                                         c = 20;
781                                                 while (c > 0)
782                                                 {
783                                                         c = c - 1;
784                                                         traceline(blastorigin, nearest, TRUE, inflictor);
785                                                         if (trace_fraction == 1 || trace_ent == targ
786                                                             || cvar("g_throughfloor"))
787                                                         {
788                                                                 if(targ.iscreature)
789                                                                         total_damage_to_creatures += finaldmg;
790                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
791                                                                 break;
792                                                         }
793                                                         nearest_x = targ.mins_x + random() * targ.size_x;
794                                                         nearest_y = targ.mins_y + random() * targ.size_y;
795                                                         nearest_z = targ.mins_z + random() * targ.size_z;
796                                                 }
797                                         }
798                                 }
799                         }
800                 targ = targ.chain;
801         }
802
803         return total_damage_to_creatures;
804 }