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