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