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