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