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