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