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