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