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