]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
autotaunts by MirceaKitsune (using cl_autotaunt cvar)
[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                                         entity oldself = self; // Hackish way to fix taunts, otherwise they play the other way around
300                                         self = attacker;
301                                         PlayerSound(playersound_taunt, CHAN_VOICE, 4);
302                                         self = oldself;
303                                 }
304
305                                 if(sv_gentle) {
306                                         bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
307                                 } else {
308                                         w = DEATH_WEAPONOF(deathtype);
309                                         if(WEP_VALID(w))
310                                         {
311                                                 w_deathtypestring = "was blasted by";
312                                                 w_deathtype = deathtype;
313                                                 weapon_action(w, WR_KILLMESSAGE);
314                                                 p = strstrofs(w_deathtypestring, "#", 0);
315                                                 if(p < 0)
316                                                         bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
317                                                 else
318                                                         bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
319                                         }
320                                         else if (deathtype == DEATH_TELEFRAG)
321                                                 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
322                                         else if (deathtype == DEATH_DROWN)
323                                                 bprint ("^1",s, "^1 was drowned by ", a, "\n");
324                                         else if (deathtype == DEATH_SLIME)
325                                                 bprint ("^1",s, "^1 was slimed by ", a, "\n");
326                                         else if (deathtype == DEATH_LAVA)
327                                                 bprint ("^1",s, "^1 was cooked by ", a, "\n");
328                                         else if (deathtype == DEATH_FALL)
329                                                 bprint ("^1",s, "^1 was grounded by ", a, "\n");
330                                         else if (deathtype == DEATH_SHOOTING_STAR)
331                                                 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
332                                         else if (deathtype == DEATH_SWAMP)
333                                                 bprint ("^1",s, "^1 was conserved by ", a, "\n");
334                                         else if (deathtype == DEATH_HURTTRIGGER && inflictor.message2 != "")
335                                         {
336                                                 p = strstrofs(inflictor.message2, "#", 0);
337                                                 if(p < 0)
338                                                         bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
339                                                 else
340                                                         bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
341                                         }
342                     else if(deathtype == DEATH_TURRET)
343                         bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
344                     else if(deathtype == DEATH_TOUCHEXPLODE)
345                         bprint ("^1",s, "^1 was pushed into an accident by ^1", a, "\n");
346                                         else
347                                                 bprint ("^1",s, "^1 was fragged by ", a, "\n");
348                                 }
349                                 if(g_ctf && targ.flagcarried)
350                                 {
351                                         UpdateFrags(attacker, ctf_score_value("score_kill"));
352                                         PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
353                                         GiveFrags(attacker, targ, 0); // for logging
354                                 }
355                                 else
356                                         GiveFrags(attacker, targ, 1);
357                                 if (targ.killcount > 2) {
358                                         if(sv_gentle)
359                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
360                                         else
361                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
362                                 }
363                                 attacker.killcount = attacker.killcount + 1;
364                                 if (attacker.killcount > 2) {
365                                         if(sv_gentle)
366                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
367                                         else
368                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
369                                 }
370
371                                 LogDeath("frag", deathtype, attacker, targ);
372
373                                 if (attacker.killcount == 3)
374                                 {
375                                         if(sv_gentle) {
376                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
377                                         } else {
378                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
379                                                 announce(attacker, "announcer/male/03kills.wav");
380                                         }
381                                 }
382                                 else if (attacker.killcount == 5)
383                                 {
384                                         if(sv_gentle) {
385                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
386                                         } else {
387                                                 bprint (a,"^7 unleashes ^1RAGE\n");
388                                                 announce(attacker, "announcer/male/05kills.wav");
389                                         }
390                                 }
391                                 else if (attacker.killcount == 10)
392                                 {
393                                         if(sv_gentle) {
394                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
395                                         } else {
396                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");
397                                                 announce(attacker, "announcer/male/10kills.wav");
398                                         }
399                                 }
400                                 else if (attacker.killcount == 15)
401                                 {
402                                         if(sv_gentle) {
403                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
404                                         } else {
405                                                 bprint (a,"^7 executes ^1MAYHEM!\n");
406                                                 announce(attacker, "announcer/male/15kills.wav");
407                                         }
408                                 }
409                                 else if (attacker.killcount == 20)
410                                 {
411                                         if(sv_gentle) {
412                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
413                                         } else {
414                                                 bprint (a,"^7 is a ^1BERSERKER!\n");
415                                                 announce(attacker, "announcer/male/20kills.wav");
416                                         }
417                                 }
418                                 else if (attacker.killcount == 25)
419                                 {
420                                         if(sv_gentle) {
421                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
422                                         } else {
423                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");
424                                                 announce(attacker, "announcer/male/25kills.wav");
425                                         }
426                                 }
427                                 else if (attacker.killcount == 30)
428                                 {
429                                         if(sv_gentle) {
430                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
431                                         } else {
432                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
433                                                 announce(attacker, "announcer/male/30kills.wav");
434                                         }
435                                 }
436                         }
437                 }
438                 else
439                 {
440                         centerprint(targ, "^1Watch your step!\n\n\n");
441                         if (deathtype == DEATH_HURTTRIGGER && inflictor.message != "")
442                                 bprint ("^1",s, "^1 ", inflictor.message, "\n");
443                         else if (deathtype == DEATH_DROWN)
444                                 if(sv_gentle)
445                                         bprint ("^1",s, "^1 was in the water for too long\n");
446                                 else
447                                         bprint ("^1",s, "^1 drowned\n");
448                         else if (deathtype == DEATH_SLIME)
449                                 bprint ("^1",s, "^1 was slimed\n");
450                         else if (deathtype == DEATH_LAVA)
451                                 if(sv_gentle)
452                                         bprint ("^1",s, "^1 found a hot place\n");
453                                 else
454                                         bprint ("^1",s, "^1 turned into hot slag\n");
455                         else if (deathtype == DEATH_FALL)
456                                 if(sv_gentle)
457                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");
458                                 else
459                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");
460                         else if (deathtype == DEATH_SHOOTING_STAR)
461                                 bprint ("^1",s, "^1 became a shooting star\n");
462                         else if (deathtype == DEATH_SWAMP)
463                                 if(sv_gentle)
464                                         bprint ("^1",s, "^1 discovered a swamp\n");
465                                 else
466                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");
467             else if(deathtype == DEATH_TURRET)
468                     bprint ("^1",s, "^1 was mowed down by a turret \n");
469                         else if(deathtype == DEATH_TOUCHEXPLODE)
470                                 bprint ("^1",s, "^1 died in an accident\n");
471                         else
472                                 if(sv_gentle)
473                                         bprint ("^1",s, "^1 needs a restart\n");
474                                 else
475                                         bprint ("^1",s, "^1 died\n");
476                         GiveFrags(targ, targ, -1);
477                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
478                                 announce(targ, "announcer/male/botlike.wav");
479                         }
480
481                         if (targ.killcount > 2)
482                                 if(sv_gentle)
483                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
484                                 else
485                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
486
487                         LogDeath("accident", deathtype, targ, targ);
488                 }
489                 targ.death_origin = targ.origin;
490                 if(targ != attacker)
491                         targ.killer_origin = attacker.origin;
492                 // FIXME: this should go in PutClientInServer
493                 if (targ.killcount)
494                         targ.killcount = 0;
495         }
496 }
497
498 // these are updated by each Damage call for use in button triggering and such
499 entity damage_targ;
500 entity damage_inflictor;
501 entity damage_attacker;
502
503 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
504 {
505         float mirrordamage;
506         float mirrorforce;
507         float teamdamage0;
508         entity attacker_save;
509         mirrordamage = 0;
510         mirrorforce = 0;
511
512         if (gameover || targ.killcount == -666)
513                 return;
514
515         local entity oldself;
516         oldself = self;
517         self = targ;
518         damage_targ = targ;
519         damage_inflictor = inflictor;
520         damage_attacker = attacker;
521                 attacker_save = attacker;
522         
523         if(targ.classname == "player")
524                 if(targ.hook)
525                         if(targ.hook.aiment)
526                                 if(targ.hook.aiment == attacker)
527                                         RemoveGrapplingHook(targ); // STOP THAT, you parasite!
528
529         // special rule: gravity bomb does not hit team mates (other than for disconnecting the hook)
530         if(DEATH_ISWEAPON(deathtype, WEP_HOOK))
531         {
532                 if(targ.classname == "player")
533                         if not(IsDifferentTeam(targ, attacker))
534                         {
535                                 self = oldself;
536                                 return;
537                         }
538         }
539
540         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
541         {
542                 // These are ALWAYS lethal
543                 // No damage modification here
544                 // Instead, prepare the victim for his death...
545                 targ.armorvalue = 0;
546                 targ.spawnshieldtime = 0;
547                 targ.health = 0.9; // this is < 1
548                 targ.flags -= targ.flags & FL_GODMODE;
549                 damage = 100000;
550         }
551         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
552         {
553                 // no processing
554         }
555         else
556         {
557                 if (targ.classname == "player")
558                 if (attacker.classname == "player")
559                 if (!targ.isbot)
560                 if (attacker.isbot)
561                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
562
563                 // nullify damage if teamplay is on
564                 if(deathtype != DEATH_TELEFRAG)
565                 if(attacker.classname == "player")
566                 {
567                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
568                         {
569                                 damage = 0;
570                                 force = '0 0 0';
571                         }
572                         else if(attacker.team == targ.team)
573                         {
574                                 if(teamplay == 1)
575                                         damage = 0;
576                                 else if(attacker != targ)
577                                 {
578                                         if(teamplay == 3)
579                                                 damage = 0;
580                                         else if(teamplay == 4)
581                                         {
582                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
583                                                 {
584                                                         teamdamage0 = max(attacker.dmg_team, cvar("g_teamdamage_threshold"));
585                                                         attacker.dmg_team = attacker.dmg_team + damage;
586                                                         if(attacker.dmg_team > teamdamage0)
587                                                                 mirrordamage = cvar("g_mirrordamage") * (attacker.dmg_team - teamdamage0);
588                                                         mirrorforce = cvar("g_mirrordamage") * vlen(force);
589                                                         if(g_minstagib)
590                                                         {
591                                                                 if(cvar("g_friendlyfire") == 0)
592                                                                         damage = 0;
593                                                         }
594                                                         else
595                                                                 damage = cvar("g_friendlyfire") * damage;
596                                                         // mirrordamage will be used LATER
597                                                 }
598                                                 else
599                                                         damage = 0;
600                                         }
601                                 }
602                         }
603                 }
604
605                 if(targ.classname == "player")
606                 if(attacker.classname == "player")
607                 if(attacker != targ)
608                 {
609                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
610                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
611                 }
612
613                 if (g_minstagib)
614                 {
615                         if ((deathtype == DEATH_FALL)  ||
616                                 (deathtype == DEATH_DROWN) ||
617                                 (deathtype == DEATH_SLIME) ||
618                                 (deathtype == DEATH_LAVA))
619                         {
620                                 self = oldself;
621                                 return;
622                         }
623                         if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
624                         {
625                                 targ.armorvalue -= 1;
626                                 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
627                                 damage = 0;
628                                 targ.hitsound += 1;
629                         }
630                         if (DEATH_ISWEAPON(deathtype, WEP_LASER))
631                         {
632                                 damage = 0;
633                                 if (targ != attacker)
634                                 {
635                                         if (targ.classname == "player")
636                                                 centerprint(attacker, "Secondary fire inflicts no damage!\n");
637                                         damage = 0;
638                                         mirrordamage = 0;
639                                         force = '0 0 0';
640                                         // keep mirrorforce
641                                         attacker = targ;
642                                 }
643                         }
644                 }
645
646                 // apply strength multiplier
647                 if ((attacker.items & IT_STRENGTH) && !g_minstagib)
648                 {
649                         if(targ == attacker)
650                         {
651                                 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
652                                 force = force * cvar("g_balance_powerup_strength_selfforce");
653                         }
654                         else
655                         {
656                                 damage = damage * cvar("g_balance_powerup_strength_damage");
657                                 force = force * cvar("g_balance_powerup_strength_force");
658                         }
659                 }
660
661                 // apply invincibility multiplier
662                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
663                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
664
665                 if (targ == attacker)
666                         damage = damage * cvar("g_balance_selfdamagepercent");  // Partial damage if the attacker hits himself
667
668                 // CTF: reduce damage/force
669                 if(g_ctf)
670                 if(targ == attacker)
671                 if(targ.flagcarried)
672                 {
673                         damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
674                         force = force * cvar("g_ctf_flagcarrier_selfforce");
675                 }
676
677                 if(g_runematch)
678                 {
679                         // apply strength rune
680                         if (attacker.runes & RUNE_STRENGTH)
681                         {
682                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
683                                 {
684                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
685                                         force = force * cvar("g_balance_rune_strength_combo_force");
686                                 }
687                                 else
688                                 {
689                                         damage = damage * cvar("g_balance_rune_strength_damage");
690                                         force = force * cvar("g_balance_rune_strength_force");
691                                 }
692                         }
693                         else if (attacker.runes & CURSE_WEAK)
694                         {
695                                 damage = damage * cvar("g_balance_curse_weak_damage");
696                                 force = force * cvar("g_balance_curse_weak_force");
697                         }
698
699                         // apply defense rune
700                         if (targ.runes & RUNE_DEFENSE)
701                         {
702                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
703                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
704                                 else
705                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
706                         }
707                         else if (targ.runes & CURSE_VULNER)
708                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
709                 }
710
711                 // count the damage
712                 if(attacker)
713                 if(!targ.deadflag)
714                 if(targ.takedamage == DAMAGE_AIM)
715                 if(targ != attacker)
716                 if(targ.classname == "player")
717                 {
718                         if(IsDifferentTeam(targ, attacker))
719                         {
720                                 if(damage > 0)
721                                 {
722                                         if(targ.BUTTON_CHAT)
723                                                 attacker.typehitsound += 1;
724                                         else
725                                                 attacker.hitsound += 1;
726
727                                         damage_goodhits += 1;
728                                         damage_gooddamage += damage;
729
730                                         if not(DEATH_ISSPECIAL(deathtype))
731                                         {
732                                                 if(!g_minstagib)
733                                                 if(IsFlying(targ))
734                                                         yoda = 1;
735
736                                                 if(g_minstagib)
737                                                 if(targ.items & IT_STRENGTH)
738                                                         yoda = 1;
739
740                                                 // HEAD SHOT:
741                                                 // find height of hit on player axis
742                                                 // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
743                                                 vector headmins, headmaxs, org;
744                                                 org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
745                                                 headmins = org + '0.7 0 0' * targ.mins_x + '0 0.7 0' * targ.mins_y + '0 0 1' * targ.view_ofs_z;
746                                                 headmaxs = org + '0.7 0 0' * targ.maxs_x + '0 0.7 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
747                                                 if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
748                                                 {
749                                                         damage *= 1 + damage_headshotbonus;
750                                                         headshot = 1;
751                                                         deathtype |= HITTYPE_HEADSHOT;
752                                                 }
753                                         }
754                                 }
755                         }
756                         else
757                         {
758                                 attacker.typehitsound += 1;
759                                 if(mirrordamage > 0)
760                                         if(time > attacker.teamkill_complain)
761                                         {
762                                                 attacker.teamkill_complain = time + 5;
763                                                 attacker.teamkill_soundtime = time + 0.4;
764                                                 attacker.teamkill_soundsource = targ;
765                                         }
766                         }
767                 }
768         }
769
770         // apply push
771         if (self.damageforcescale)
772         if (vlen(force))
773         {
774                 self.velocity = self.velocity + self.damageforcescale * force;
775                 self.flags = self.flags - (self.flags & FL_ONGROUND);
776         }
777         // apply damage
778         if (damage != 0)
779         if (self.event_damage)
780                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
781         self = oldself;
782
783         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
784         {
785                 // Savage: vampire mode
786                 if (g_vampire)
787                 if (!g_minstagib)
788                 if (time > self.spawnshieldtime)
789                 {
790                         attacker.health += damage;
791                 }
792                 if(g_runematch)
793                 {
794                         if (attacker.runes & RUNE_VAMPIRE)
795                         {
796                         // apply vampire rune
797                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
798                                 {
799                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
800                                         attacker.health = bound(
801                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
802                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
803                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
804                                 }
805                                 else
806                                 {
807                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
808                                         attacker.health = bound(
809                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
810                                                                                         // empathy won't let you gain health in the same way...
811                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
812                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
813                                         }
814                         }
815                         // apply empathy curse
816                         else if (attacker.runes & CURSE_EMPATHY)
817                         {
818                                 attacker.health = bound(
819                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
820                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
821                                         attacker.health);
822                         }
823                 }
824         }
825
826         // apply mirror damage if any
827         if(mirrordamage > 0 || mirrorforce > 0)
828         {
829                 attacker = attacker_save;
830                 if(g_minstagib)
831                         if(mirrordamage > 0)
832                         {
833                                 // just lose extra LIVES, don't kill the player for mirror damage
834                                 if(attacker.armorvalue > 0)
835                                 {
836                                         attacker.armorvalue = attacker.armorvalue - 1;
837                                         centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
838                                         attacker.hitsound += 1;
839                                 }
840                                 mirrordamage = 0;
841                         }
842                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
843                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
844         }
845 }
846
847 vector NearestPointOnBox(entity box, vector org)
848 {
849         vector m1, m2, nearest;
850
851         m1 = box.mins + box.origin;
852         m2 = box.maxs + box.origin;
853
854         nearest_x = bound(m1_x, org_x, m2_x);
855         nearest_y = bound(m1_y, org_y, m2_y);
856         nearest_z = bound(m1_z, org_z, m2_z);
857
858         return nearest;
859 }
860
861 float RadiusDamage_running;
862 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
863 // Returns total damage applies to creatures
864 {
865         entity  targ;
866         float   finaldmg;
867         float   power;
868         vector  blastorigin;
869         vector  force;
870         vector  diff;
871         vector  center;
872         vector  nearest;
873         float   total_damage_to_creatures;
874         entity  next;
875
876         if(RadiusDamage_running)
877         {
878                 string save;
879                 print("RadiusDamage called recursively!\n");
880                 print("Expect stuff to go HORRIBLY wrong.\n");
881                 print("Causing a stack trace...\n");
882                 save = cvar_string("prvm_backtraceforwarnings");
883                 cvar_set("prvm_backtraceforwarnings", "1");
884                 fclose(-1); // calls VM_Warning
885                 cvar_set("prvm_backtraceforwarnings", save);
886                 return 0;
887         }
888
889         RadiusDamage_running = 1;
890
891         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
892         total_damage_to_creatures = 0;
893
894         targ = findradius (blastorigin, rad);
895         while (targ)
896         {
897                 next = targ.chain;
898                 if (targ != inflictor)
899                         if (ignore != targ)
900                         {
901                                 // LordHavoc: measure distance to nearest point on target (not origin)
902                                 // (this guarentees 100% damage on a touch impact)
903                                 nearest = NearestPointOnBox(targ, blastorigin);
904                                 diff = nearest - blastorigin;
905                                 // round up a little on the damage to ensure full damage on impacts
906                                 // and turn the distance into a fraction of the radius
907                                 power = 1 - ((vlen (diff) - 2) / rad);
908                                 //bprint(" ");
909                                 //bprint(ftos(power));
910                                 if (power > 0)
911                                 {
912                                         if (power > 1)
913                                                 power = 1;
914                                         finaldmg = coredamage * power + edgedamage * (1 - power);
915                                         if (finaldmg > 0)
916                                         {
917                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
918                                                 // if it's a player, use the view origin as reference
919                                                 if (targ.classname == "player")
920                                                         center = targ.origin + targ.view_ofs;
921                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
922                                                 // test line of sight to multiple positions on box,
923                                                 // and do damage if any of them hit
924                                                 local float c;
925                                                 c = ceil(finaldmg / 10);
926                                                 if (c > 20)
927                                                         c = 20;
928                                                 while (c > 0)
929                                                 {
930                                                         c = c - 1;
931                                                         traceline(blastorigin, nearest, TRUE, inflictor);
932                                                         if (trace_fraction == 1 || trace_ent == targ
933                                                             || cvar("g_throughfloor"))
934                                                         {
935                                                                 if(targ.iscreature)
936                                                                         total_damage_to_creatures += finaldmg;
937                                                                 if(targ == directhitentity || DEATH_ISSPECIAL(deathtype))
938                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
939                                                                 else
940                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
941                                                                 break;
942                                                         }
943                                                         nearest_x = targ.mins_x + random() * targ.size_x;
944                                                         nearest_y = targ.mins_y + random() * targ.size_y;
945                                                         nearest_z = targ.mins_z + random() * targ.size_z;
946                                                 }
947                                         }
948                                 }
949                         }
950                 targ = next;
951         }
952
953         RadiusDamage_running = 0;
954
955         return total_damage_to_creatures;
956 }