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