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