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