]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
more sounds by tenshihan: male/impressive, male/airshot, male/headshot, misc/typehit
[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;
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                                 if(deathtype < DEATH_SPECIAL_START && deathtype & DEATH_WEAPONMASK >= WEP_FIRST && deathtype & DEATH_WEAPONMASK <= WEP_LAST)
219                                 {
220                                         w_deathtypestring = "couldn't resist the urge to self-destruct";
221                                         w_deathtype = deathtype;
222                                         weapon_action(deathtype & DEATH_WEAPONMASK, WR_SUICIDEMESSAGE);
223                                         bprint("^1", s, "^1 ", w_deathtypestring, "\n");
224                                 }
225                                 else if (deathtype == DEATH_KILL)
226                                         bprint ("^1",s, "^1 couldn't take it anymore\n");
227                                 else if (deathtype == DEATH_ROT)
228                                         bprint ("^1",s, "^1 died\n");
229                                 else if (deathtype == DEATH_NOAMMO)
230                                 {
231                                         bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
232                                 }
233                                 else if (deathtype == DEATH_CAMP)
234                                         bprint ("^1",s, "^1 thought he found a nice camping ground\n");
235                                 else if (deathtype == DEATH_MIRRORDAMAGE)
236                                         bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
237                                 else if (deathtype != DEATH_TEAMCHANGE)
238                                         bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
239
240                                 if(deathtype != DEATH_TEAMCHANGE)
241                                 {
242                                         LogDeath("suicide", deathtype, targ, targ);
243                                         GiveFrags(attacker, targ, -1);
244                                 }
245                                 if (targ.killcount > 2)
246                                         bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
247                         }
248                 }
249                 else if (attacker.classname == "player" || attacker.classname == "gib")
250                 {
251                         if(teamplay && attacker.team == targ.team)
252                         {
253                                 if(sv_gentle) {
254                                         centerprint(attacker, "^1Moron! You went against a teammate!\n\n\n");
255                                         bprint ("^1", a, "^1 took action against a teammate\n");
256                                 } else {
257                                         centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
258                                         bprint ("^1", a, "^1 mows down a teammate\n");
259                                 }
260                                 GiveFrags(attacker, targ, -1);
261                                 if (targ.killcount > 2) {
262                                         if(sv_gentle)
263                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," scoring spree was ended by a teammate!\n");
264                                         else
265                                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
266                                 }
267                                 if (attacker.killcount > 2) {
268                                         if(sv_gentle)
269                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," scoring spree by going against a teammate\n");
270                                         else
271                                                 bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
272                                 }
273                                 attacker.killcount = 0;
274
275                                 LogDeath("tk", deathtype, attacker, targ);
276                         }
277                         else
278                         {
279                                 if (!checkrules_firstblood)
280                                 {
281                                         checkrules_firstblood = TRUE;
282                                         if(sv_gentle)
283                                                 bprint("^1",a, "^1 was the first to score", "\n");
284                                         else
285                                                 bprint("^1",a, "^1 drew first blood", "\n");
286                                 }
287
288                                 if(sv_gentle > 0) {
289                                         centerprint(attacker, strcat("^4You scored against ^7", s, "\n\n\n"));
290                                         centerprint(targ, strcat(a,"^1 scored against you ^7\n\n\n"));
291                                 } else {
292                                         centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
293                                         centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
294                                 }
295
296                                 if(sv_gentle) {
297                                         bprint ("^1",s, "^1 needs a restart thanks to ", a, "\n");
298                                 } else {
299                                         if(deathtype < DEATH_SPECIAL_START && deathtype & DEATH_WEAPONMASK >= WEP_FIRST && deathtype & DEATH_WEAPONMASK <= WEP_LAST)
300                                         {
301                                                 w_deathtypestring = "was blasted by";
302                                                 w_deathtype = deathtype;
303                                                 weapon_action(deathtype & DEATH_WEAPONMASK, WR_KILLMESSAGE);
304                                                 p = strstrofs(w_deathtypestring, "#", 0);
305                                                 if(p < 0)
306                                                         bprint("^1", s, "^1 ", w_deathtypestring, " ", a, "\n");
307                                                 else
308                                                         bprint("^1", s, "^1 ", substring(w_deathtypestring, 0, p), a, "^1", substring(w_deathtypestring, p+1, strlen(w_deathtypestring) - (p+1)), "\n");
309                                         }
310                                         else if (deathtype == DEATH_TELEFRAG)
311                                                 bprint ("^1",s, "^1 was telefragged by ", a, "\n");
312                                         else if (deathtype == DEATH_DROWN)
313                                                 bprint ("^1",s, "^1 was drowned by ", a, "\n");
314                                         else if (deathtype == DEATH_SLIME)
315                                                 bprint ("^1",s, "^1 was slimed by ", a, "\n");
316                                         else if (deathtype == DEATH_LAVA)
317                                                 bprint ("^1",s, "^1 was cooked by ", a, "\n");
318                                         else if (deathtype == DEATH_FALL)
319                                                 bprint ("^1",s, "^1 was grounded by ", a, "\n");
320                                         else if (deathtype == DEATH_SHOOTING_STAR)
321                                                 bprint ("^1",s, "^1 was shot into space by ", a, "\n");
322                                         else if (deathtype == DEATH_SWAMP)
323                                                 bprint ("^1",s, "^1 was conserved by ", a, "\n");
324                                         else if (deathtype == DEATH_HURTTRIGGER && attacker.message2 != "")
325                                         {
326                                                 p = strstrofs(inflictor.message2, "#", 0);
327                                                 if(p < 0)
328                                                         bprint("^1", s, "^1 ", inflictor.message2, " ", a, "\n");
329                                                 else
330                                                         bprint("^1", s, "^1 ", substring(inflictor.message2, 0, p), a, "^1", substring(inflictor.message2, p+1, strlen(inflictor.message2) - (p+1)), "\n");
331                                         }
332                     else if(deathtype == DEATH_TURRET)
333                         bprint ("^1",s, "^1 was pushed into the line of fire by ^1", a, "\n");
334                                         else
335                                                 bprint ("^1",s, "^1 was fragged by ", a, "\n");
336                                 }
337                                 if(g_ctf && targ.flagcarried)
338                                 {
339                                         UpdateFrags(attacker, ctf_score_value("score_kill"));
340                                         PlayerScore_Add(attacker, SP_CTF_FCKILLS, 1);
341                                         GiveFrags(attacker, targ, 0); // for logging
342                                 }
343                                 else
344                                         GiveFrags(attacker, targ, 1);
345                                 if (targ.killcount > 2) {
346                                         if(sv_gentle)
347                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " scoring spree was ended by ", a, "\n");
348                                         else
349                                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
350                                 }
351                                 attacker.killcount = attacker.killcount + 1;
352                                 if (attacker.killcount > 2) {
353                                         if(sv_gentle)
354                                                 bprint ("^1",a,"^1 made ",ftos(attacker.killcount)," scores in a row\n");
355                                         else
356                                                 bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
357                                 }
358
359                                 LogDeath("frag", deathtype, attacker, targ);
360
361                                 if (attacker.killcount == 3)
362                                 {
363                                         if(sv_gentle) {
364                                                 bprint (a,"^7 made a ^1TRIPLE SCORE\n");
365                                         } else {
366                                                 bprint (a,"^7 made a ^1TRIPLE FRAG\n");
367                                                 announce(attacker, "announcer/male/03kills.ogg");
368                                         }
369                                 }
370                                 else if (attacker.killcount == 5)
371                                 {
372                                         if(sv_gentle) {
373                                                 bprint (a,"^7 unleashes ^1SCORING RAGE\n");
374                                         } else {
375                                                 bprint (a,"^7 unleashes ^1RAGE\n");
376                                                 announce(attacker, "announcer/male/05kills.ogg");
377                                         }
378                                 }
379                                 else if (attacker.killcount == 10)
380                                 {
381                                         if(sv_gentle) {
382                                                 bprint (a,"^7 made ^1TEN SCORES IN A ROW!\n");
383                                         } else {
384                                                 bprint (a,"^7 starts the ^1MASSACRE!\n");
385                                                 announce(attacker, "announcer/male/10kills.ogg");
386                                         }
387                                 }
388                                 else if (attacker.killcount == 15)
389                                 {
390                                         if(sv_gentle) {
391                                                 bprint (a,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
392                                         } else {
393                                                 bprint (a,"^7 executes ^1MAYHEM!\n");
394                                                 announce(attacker, "announcer/male/15kills.ogg");
395                                         }
396                                 }
397                                 else if (attacker.killcount == 20)
398                                 {
399                                         if(sv_gentle) {
400                                                 bprint (a,"^7 made ^1TWENTY SCORES IN A ROW!\n");
401                                         } else {
402                                                 bprint (a,"^7 is a ^1BERSERKER!\n");
403                                                 announce(attacker, "announcer/male/20kills.ogg");
404                                         }
405                                 }
406                                 else if (attacker.killcount == 25)
407                                 {
408                                         if(sv_gentle) {
409                                                 bprint (a,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
410                                         } else {
411                                                 bprint (a,"^7 inflicts ^1CARNAGE!\n");
412                                                 announce(attacker, "announcer/male/25kills.ogg");
413                                         }
414                                 }
415                                 else if (attacker.killcount == 30)
416                                 {
417                                         if(sv_gentle) {
418                                                 bprint (a,"^7 made ^1THIRTY SCORES IN A ROW!\n");
419                                         } else {
420                                                 bprint (a,"^7 unleashes ^1ARMAGEDDON!\n");
421                                                 announce(attacker, "announcer/male/30kills.ogg");
422                                         }
423                                 }
424                         }
425                 }
426                 else
427                 {
428                         centerprint(targ, "^1Watch your step!\n\n\n");
429                         if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
430                                 bprint ("^1",s, "^1 ", attacker.message, "\n");
431                         else if (deathtype == DEATH_DROWN)
432                                 if(sv_gentle)
433                                         bprint ("^1",s, "^1 was in the water for too long\n");
434                                 else
435                                         bprint ("^1",s, "^1 drowned\n");
436                         else if (deathtype == DEATH_SLIME)
437                                 bprint ("^1",s, "^1 was slimed\n");
438                         else if (deathtype == DEATH_LAVA)
439                                 if(sv_gentle)
440                                         bprint ("^1",s, "^1 found a hot place\n");
441                                 else
442                                         bprint ("^1",s, "^1 turned into hot slag\n");
443                         else if (deathtype == DEATH_FALL)
444                                 if(sv_gentle)
445                                         bprint ("^1",s, "^1 tested gravity (and it worked)\n");
446                                 else
447                                         bprint ("^1",s, "^1 hit the ground with a crunch\n");
448                         else if (deathtype == DEATH_SHOOTING_STAR)
449                                 bprint ("^1",s, "^1 became a shooting star\n");
450                         else if (deathtype == DEATH_SWAMP)
451                                 if(sv_gentle)
452                                         bprint ("^1",s, "^1 discovered a swamp\n");
453                                 else
454                                         bprint ("^1",s, "^1 is now conserved for centuries to come\n");
455             else if(deathtype == DEATH_TURRET)
456                     bprint ("^1",s, "^1 was mowed down by a turret \n");
457                         else
458                                 if(sv_gentle)
459                                         bprint ("^1",s, "^1 needs a restart\n");
460                                 else
461                                         bprint ("^1",s, "^1 died\n");
462                         GiveFrags(targ, targ, -1);
463                         if(PlayerScore_Add(targ, SP_SCORE, 0) == -5) {
464                                 announce(targ, "announcer/male/botlike.ogg");
465                         }
466
467                         if (targ.killcount > 2)
468                                 if(sv_gentle)
469                                         bprint ("^1",s,"^1 needs a restart after a ",ftos(targ.killcount)," scoring spree\n");
470                                 else
471                                         bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
472
473                         LogDeath("accident", deathtype, targ, targ);
474                 }
475                 targ.death_origin = targ.origin;
476                 if(targ != attacker)
477                         targ.killer_origin = attacker.origin;
478                 // FIXME: this should go in PutClientInServer
479                 if (targ.killcount)
480                         targ.killcount = 0;
481         }
482 }
483
484 // these are updated by each Damage call for use in button triggering and such
485 entity damage_targ;
486 entity damage_inflictor;
487 entity damage_attacker;
488
489 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
490 {
491         float mirrordamage;
492         float mirrorforce;
493         entity attacker_save;
494         mirrordamage = 0;
495         mirrorforce = 0;
496
497         if (gameover || targ.killcount == -666)
498                 return;
499
500         local entity oldself;
501         oldself = self;
502         self = targ;
503         damage_targ = targ;
504         damage_inflictor = inflictor;
505         damage_attacker = attacker;
506                 attacker_save = attacker;
507
508         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
509         {
510                 // These are ALWAYS lethal
511                 // No damage modification here
512                 // Instead, prepare the victim for his death...
513                 targ.armorvalue = 0;
514                 targ.spawnshieldtime = 0;
515                 targ.health = 0.9; // this is < 1
516                 targ.flags -= targ.flags & FL_GODMODE;
517                 damage = 100000;
518         }
519         else if(deathtype == DEATH_MIRRORDAMAGE || deathtype == DEATH_NOAMMO)
520         {
521                 // no processing
522         }
523         else
524         {
525                 if (targ.classname == "player")
526                 if (attacker.classname == "player")
527                 if (!targ.isbot)
528                 if (attacker.isbot)
529                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
530
531                 // nullify damage if teamplay is on
532                 if(deathtype != DEATH_TELEFRAG)
533                 if(attacker.classname == "player")
534                 {
535                         if(targ.classname == "player" && targ != attacker && (IS_INDEPENDENT_PLAYER(attacker) || IS_INDEPENDENT_PLAYER(targ)))
536                         {
537                                 damage = 0;
538                                 force = '0 0 0';
539                         }
540                         else if(attacker.team == targ.team)
541                         {
542                                 if(teamplay == 1)
543                                         damage = 0;
544                                 else if(attacker != targ)
545                                 {
546                                         if(teamplay == 3)
547                                                 damage = 0;
548                                         else if(teamplay == 4)
549                                         {
550                                                 if(targ.classname == "player" && targ.deadflag == DEAD_NO)
551                                                 {
552                                                         mirrordamage = cvar("g_mirrordamage") * damage;
553                                                         mirrorforce = cvar("g_mirrordamage") * vlen(force);
554                                                         if(g_minstagib)
555                                                         {
556                                                                 if(cvar("g_friendlyfire") == 0)
557                                                                         damage = 0;
558                                                         }
559                                                         else
560                                                                 damage = cvar("g_friendlyfire") * damage;
561                                                         // mirrordamage will be used LATER
562                                                 }
563                                                 else
564                                                         damage = 0;
565                                         }
566                                 }
567                         }
568                 }
569
570                 if(targ.classname == "player")
571                 if(attacker.classname == "player")
572                 if(attacker != targ)
573                 {
574                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
575                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
576                 }
577
578                 if (g_minstagib)
579                 {
580                         if ((deathtype == DEATH_FALL)  ||
581                                 (deathtype == DEATH_DROWN) ||
582                                 (deathtype == DEATH_SLIME) ||
583                                 (deathtype == DEATH_LAVA))
584                         {
585                                 self = oldself;
586                                 return;
587                         }
588                         if (targ.armorvalue && (deathtype == WEP_MINSTANEX) && damage)
589                         {
590                                 targ.armorvalue -= 1;
591                                 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
592                                 damage = 0;
593                                 targ.hitsound += 1;
594                         }
595                         if (deathtype == WEP_LASER)
596                         {
597                                 damage = 0;
598                                 if (targ != attacker)
599                                 {
600                                         if (targ.classname == "player")
601                                                 centerprint(attacker, "Secondary fire inflicts no damage!\n");
602                                         damage = 0;
603                                         mirrordamage = 0;
604                                         force = '0 0 0';
605                                         // keep mirrorforce
606                                         attacker = targ;
607                                 }
608                         }
609                 }
610
611                 // apply strength multiplier
612                 if (attacker.items & IT_STRENGTH && !g_minstagib)
613                 {
614                         if(targ == attacker)
615                         {
616                                 damage = damage * cvar("g_balance_powerup_strength_selfdamage");
617                                 force = force * cvar("g_balance_powerup_strength_selfforce");
618                         }
619                         else
620                         {
621                                 damage = damage * cvar("g_balance_powerup_strength_damage");
622                                 force = force * cvar("g_balance_powerup_strength_force");
623                         }
624                 }
625
626                 // apply invincibility multiplier
627                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
628                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
629
630                 if (targ == attacker)
631                         damage = damage * cvar("g_balance_selfdamagepercent");  // Partial damage if the attacker hits himself
632
633                 // CTF: reduce damage/force
634                 if(g_ctf)
635                 if(targ == attacker)
636                 if(targ.flagcarried)
637                 {
638                         damage = damage * cvar("g_ctf_flagcarrier_selfdamage");
639                         force = force * cvar("g_ctf_flagcarrier_selfforce");
640                 }
641
642                 if(g_runematch)
643                 {
644                         // apply strength rune
645                         if (attacker.runes & RUNE_STRENGTH)
646                         {
647                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
648                                 {
649                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
650                                         force = force * cvar("g_balance_rune_strength_combo_force");
651                                 }
652                                 else
653                                 {
654                                         damage = damage * cvar("g_balance_rune_strength_damage");
655                                         force = force * cvar("g_balance_rune_strength_force");
656                                 }
657                         }
658                         else if (attacker.runes & CURSE_WEAK)
659                         {
660                                 damage = damage * cvar("g_balance_curse_weak_damage");
661                                 force = force * cvar("g_balance_curse_weak_force");
662                         }
663
664                         // apply defense rune
665                         if (targ.runes & RUNE_DEFENSE)
666                         {
667                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
668                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
669                                 else
670                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
671                         }
672                         else if (targ.runes & CURSE_VULNER)
673                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
674                 }
675
676                 // count the damage
677                 if(attacker)
678                 if(!targ.deadflag)
679                 if(targ.takedamage == DAMAGE_AIM)
680                 if(targ != attacker)
681                 if(targ.classname == "player")
682                 {
683                         if(IsDifferentTeam(targ, attacker))
684                         {
685                                 if(damage > 0)
686                                 {
687                                         if(targ.BUTTON_CHAT)
688                                                 attacker.typehitsound += 1;
689                                         else
690                                                 attacker.hitsound += 1;
691
692                                         damage_goodhits += 1;
693                                         damage_gooddamage += damage;
694
695                                         if(!g_minstagib)
696                                         if(IsFlying(targ))
697                                                 yoda = 1;
698
699                                         if(g_minstagib)
700                                         if(targ.items & IT_STRENGTH)
701                                                 yoda = 1;
702
703                                         // HEAD SHOT:
704                                         // find height of hit on player axis
705                                         // if above view_ofs and below maxs, and also in the middle half of the bbox, it is head shot
706                                         vector headmins, headmaxs, org;
707                                         org = antilag_takebackorigin(targ, time - ANTILAG_LATENCY(attacker));
708                                         headmins = org + '0.5 0 0' * targ.mins_x + '0 0.5 0' * targ.mins_y + '0 0 1' * targ.view_ofs_z;
709                                         headmaxs = org + '0.5 0 0' * targ.maxs_x + '0 0.5 0' * targ.maxs_y + '0 0 1' * targ.maxs_z;
710                                         if(trace_hits_box(railgun_start, railgun_end, headmins, headmaxs))
711                                                 headshot = 1;
712                                 }
713                         }
714                         else
715                         {
716                                 attacker.typehitsound += 1; // TODO possibly trigger teamkill complain sound!
717                                 if(time > attacker.teamkill_complain)
718                                 {
719                                         entity oldpusher;
720
721                                         // note: here, self is actually targ!
722                                         oldpusher = self.pusher; self.pusher = attacker;
723                                         VoiceMessage("teamshoot_auto");
724                                         self.pusher = oldpusher;
725
726                                         attacker.teamkill_complain = time + 5;
727                                 }
728                         }
729                 }
730         }
731
732         // apply push
733         if (self.damageforcescale)
734         if (vlen(force))
735         {
736                 self.velocity = self.velocity + self.damageforcescale * force;
737                 self.flags = self.flags - (self.flags & FL_ONGROUND);
738         }
739         // apply damage
740         if (damage != 0)
741         if (self.event_damage)
742                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
743         self = oldself;
744
745         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
746         {
747                 // Savage: vampire mode
748                 if (g_vampire)
749                 if (!g_minstagib)
750                 if (time > self.spawnshieldtime)
751                 {
752                         attacker.health += damage;
753                 }
754                 if(g_runematch)
755                 {
756                         if (attacker.runes & RUNE_VAMPIRE)
757                         {
758                         // apply vampire rune
759                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
760                                 {
761                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
762                                         attacker.health = bound(
763                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
764                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
765                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
766                                 }
767                                 else
768                                 {
769                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
770                                         attacker.health = bound(
771                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
772                                                                                         // empathy won't let you gain health in the same way...
773                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
774                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
775                                         }
776                         }
777                         // apply empathy curse
778                         else if (attacker.runes & CURSE_EMPATHY)
779                         {
780                                 attacker.health = bound(
781                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
782                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
783                                         attacker.health);
784                         }
785                 }
786         }
787
788         // apply mirror damage if any
789         if(mirrordamage > 0 || mirrorforce > 0)
790         {
791                 attacker = attacker_save;
792                 if(g_minstagib)
793                         if(mirrordamage > 0)
794                         {
795                                 // just lose extra LIVES, don't kill the player for mirror damage
796                                 if(attacker.armorvalue > 0)
797                                 {
798                                         attacker.armorvalue = attacker.armorvalue - 1;
799                                         centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
800                                         attacker.hitsound += 1;
801                                 }
802                                 mirrordamage = 0;
803                         }
804                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
805                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
806         }
807 }
808
809 vector NearestPointOnBox(entity box, vector org)
810 {
811         vector m1, m2, nearest;
812
813         m1 = box.mins + box.origin;
814         m2 = box.maxs + box.origin;
815
816         nearest_x = bound(m1_x, org_x, m2_x);
817         nearest_y = bound(m1_y, org_y, m2_y);
818         nearest_z = bound(m1_z, org_z, m2_z);
819
820         return nearest;
821 }
822
823 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype, entity directhitentity)
824 // Returns total damage applies to creatures
825 {
826         entity  targ;
827         float   finaldmg;
828         float   power;
829         vector  blastorigin;
830         vector  force;
831         vector  diff;
832         vector  center;
833         vector  nearest;
834         float   total_damage_to_creatures;
835
836         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
837         total_damage_to_creatures = 0;
838
839         targ = findradius (blastorigin, rad);
840         while (targ)
841         {
842                 if (targ != inflictor)
843                         if (ignore != targ)
844                         {
845                                 // LordHavoc: measure distance to nearest point on target (not origin)
846                                 // (this guarentees 100% damage on a touch impact)
847                                 nearest = NearestPointOnBox(targ, blastorigin);
848                                 diff = nearest - blastorigin;
849                                 // round up a little on the damage to ensure full damage on impacts
850                                 // and turn the distance into a fraction of the radius
851                                 power = 1 - ((vlen (diff) - 2) / rad);
852                                 //bprint(" ");
853                                 //bprint(ftos(power));
854                                 if (power > 0)
855                                 {
856                                         if (power > 1)
857                                                 power = 1;
858                                         finaldmg = coredamage * power + edgedamage * (1 - power);
859                                         if (finaldmg > 0)
860                                         {
861                                                 center = targ.origin + (targ.mins + targ.maxs) * 0.5;
862                                                 // if it's a player, use the view origin as reference
863                                                 if (targ.classname == "player")
864                                                         center = targ.origin + targ.view_ofs;
865                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
866                                                 // test line of sight to multiple positions on box,
867                                                 // and do damage if any of them hit
868                                                 local float c;
869                                                 c = ceil(finaldmg / 10);
870                                                 if (c > 20)
871                                                         c = 20;
872                                                 while (c > 0)
873                                                 {
874                                                         c = c - 1;
875                                                         traceline(blastorigin, nearest, TRUE, inflictor);
876                                                         if (trace_fraction == 1 || trace_ent == targ
877                                                             || cvar("g_throughfloor"))
878                                                         {
879                                                                 if(targ.iscreature)
880                                                                         total_damage_to_creatures += finaldmg;
881                                                                 if(targ == directhitentity)
882                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
883                                                                 else
884                                                                         Damage (targ, inflictor, attacker, finaldmg, deathtype | HITTYPE_SPLASH, nearest, force);
885                                                                 break;
886                                                         }
887                                                         nearest_x = targ.mins_x + random() * targ.size_x;
888                                                         nearest_y = targ.mins_y + random() * targ.size_y;
889                                                         nearest_z = targ.mins_z + random() * targ.size_z;
890                                                 }
891                                         }
892                                 }
893                         }
894                 targ = targ.chain;
895         }
896
897         return total_damage_to_creatures;
898 }