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