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