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