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