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