]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
changed all te_ effects (except te_bloodshower) to pointparticles()
[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                 if(a.team == b.team)
20                         return 0;
21         return 1;
22 }
23
24 float IsFlying(entity a)
25 {
26         if(a.flags & FL_ONGROUND)
27                 return 0;
28         if(a.waterlevel >= 2)
29                 return 0;
30         traceline(a.origin, a.origin - '0 0 48', MOVE_NORMAL, a);
31         if(trace_fraction < 1)
32                 return 0;
33         return 1;
34 }
35
36 void(entity player, float f) UpdateFrags =
37 {
38         player.frags += f;
39         player.totalfrags += f;
40 }
41
42 void GiveFrags (entity attacker, entity targ, float f)
43 {
44         if(gameover) return;
45
46         if(g_arena)
47                 if(cvar("g_arena_roundbased"))
48                         return;
49
50         if(g_domination)
51         {
52                 if(cvar("g_domination_disable_frags"))
53                         if(f > 0)
54                                 return;
55         }
56         else if(g_runematch)
57         {
58                 if(f > 0)
59                         f = RunematchHandleFrags(attacker, targ, f);
60         }
61         else if(g_keyhunt)
62         {
63                 f = kh_HandleFrags(attacker, targ, f);
64         }
65         else if(g_lms)
66         {
67                 // count remaining lives, not frags in lms
68                 targ.frags -= 1;
69                 // keep track of the worst players lives
70                 if(targ.frags < lms_lowest_lives)
71                         lms_lowest_lives = targ.frags;
72                 // player has no more lives left
73                 if (!targ.frags)
74                 {
75                         if(!lms_next_place)
76                                 lms_next_place = player_count;
77                         targ.frags = -lms_next_place;
78                         lms_next_place -= 1;
79                 }
80                 return;
81         }
82
83         if(f)
84                 UpdateFrags(attacker, f);
85 }
86
87 string AppendItemcodes(string s, entity player)
88 {
89         float w;
90         w = player.weapon;
91         //if(w == 0)
92         //      w = player.switchweapon;
93         if(w == 0)
94                 w = player.cnt; // previous weapon!
95         s = strcat(s, ftos(W_ItemCode(w)));
96         if(time < player.strength_finished)
97                 s = strcat(s, "S");
98         if(time < player.invincible_finished)
99                 s = strcat(s, "I");
100         if(player.flagcarried != world)
101                 s = strcat(s, "F");
102         if(player.buttonchat)
103                 s = strcat(s, "T");
104         if(player.kh_next)
105                 s = strcat(s, "K");
106         if(player.runes)
107                 s = strcat(s, "|", ftos(player.runes));
108         return s;
109 }
110
111 void LogDeath(string mode, float deathtype, entity killer, entity killed)
112 {
113         string s;
114         if(!cvar("sv_eventlog"))
115                 return;
116         s = strcat(":kill:", mode);
117         s = strcat(s, ":", ftos(killer.playerid));
118         s = strcat(s, ":", ftos(killed.playerid));
119         s = strcat(s, ":type=", ftos(deathtype));
120         s = strcat(s, ":items=");
121         s = AppendItemcodes(s, killer);
122         if(killed != killer)
123         {
124                 s = strcat(s, ":victimitems=");
125                 s = AppendItemcodes(s, killed);
126         }
127         GameLogEcho(s, FALSE);
128 }
129
130 void Obituary (entity attacker, entity targ, float deathtype)
131 {
132         string  s, a;
133
134         if (targ.classname == "player" || targ.classname == "corpse")
135         {
136                 if (targ.classname == "corpse")
137                         s = "A corpse";
138                 else
139                         s = targ.netname;
140                 a = attacker.netname;
141
142                 if (targ == attacker)
143                 {
144                         if (deathtype == DEATH_TEAMCHANGE)
145                         {
146                                 centerprint(targ, strcat("You are now on: ", ColoredTeamName(targ.team)));
147                         }
148                         else if (deathtype == DEATH_AUTOTEAMCHANGE)
149                         {
150                                 centerprint(targ, strcat("You have been moved into a different team to improve team balance\nYou are now on: ", ColoredTeamName(targ.team)));
151                                 return;
152                         }
153                         else if (deathtype == DEATH_CAMP)
154                                 centerprint(targ, "^1Die camper!\n\n\n");
155                         else if (deathtype == DEATH_NOAMMO)
156                                 centerprint(targ, "^1You were killed for running out of ammo...\n\n\n");
157                         else if (deathtype == DEATH_ROT)
158                                 centerprint(targ, "^1You grew too old without taking your medicine\n\n\n");
159                         else if (deathtype == DEATH_MIRRORDAMAGE)
160                                 centerprint(targ, "^1Don't shoot your team mates!\n\n\n");
161                         else
162                                 centerprint(targ, "^1You killed your own dumb self!\n\n\n");
163
164                         if (deathtype == IT_GRENADE_LAUNCHER)
165                                 bprint ("^1",s, "^1 detonated\n");
166                         else if (deathtype == IT_ELECTRO)
167                                 bprint ("^1",s, "^1 played with plasma\n");
168                         else if (deathtype == IT_ROCKET_LAUNCHER)
169                                 bprint ("^1",s, "^1 exploded\n");
170                         else if (deathtype == DEATH_KILL)
171                                 bprint ("^1",s, "^1 couldn't take it anymore\n");
172                         else if (deathtype == DEATH_ROT)
173                                 bprint ("^1",s, "^1 died\n");
174                         else if (deathtype == DEATH_NOAMMO)
175                         {
176                                 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
177                                 //sound (self, CHAN_BODY, "minstagib/mockery.wav", 1, ATTN_NONE);
178                         }
179                         else if (deathtype == DEATH_CAMP)
180                                 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
181                         else if (deathtype == DEATH_MIRRORDAMAGE)
182                                 bprint ("^1",s, "^1 didn't become friends with the Lord of Teamplay\n");
183                         else if (deathtype != DEATH_TEAMCHANGE)
184                                 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
185
186                         if(deathtype != DEATH_TEAMCHANGE)
187                         {
188                                 LogDeath("suicide", deathtype, targ, targ);
189                                 GiveFrags(attacker, targ, -1);
190                         }
191                         if (targ.killcount > 2)
192                                 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
193                 }
194                 else if (attacker.classname == "player" || attacker.classname == "gib")
195                 {
196                         if(teamplay && attacker.team == targ.team)
197                         {
198                                 centerprint(attacker, "^1Moron! You fragged a teammate!\n\n\n");
199                                 bprint ("^1", a, "^1 mows down a teammate\n");
200                                 GiveFrags(attacker, targ, -1);
201                                 if (targ.killcount > 2)
202                                         bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was ended by a teammate!\n");
203                                 if (attacker.killcount > 2)
204                                         bprint ("^1",a,"^1 ended a ",ftos(attacker.killcount)," kill spree by killing a teammate\n");
205                                 attacker.killcount = 0;
206
207                                 LogDeath("tk", deathtype, attacker, targ);
208                         }
209                         else
210                         {
211                                 if (!checkrules_firstblood)
212                                 {
213                                         checkrules_firstblood = TRUE;
214                                         //sound(world, CHAN_AUTO, "announcer/firstblood.wav", 1, ATTN_NONE);
215                                         //if (g_minstagib)
216                                                 //sound(world, CHAN_AUTO, "announce/male/mapkill1.wav", 1, ATTN_NONE);
217                                         bprint("^1",a, "^1 drew first blood", "\n");
218                                 }
219
220                                 centerprint(attacker, strcat("^4You fragged ^7", s, "\n\n\n"));
221                                 centerprint(targ, strcat("^1You were fragged by ^7", a, "\n\n\n"));
222
223                                 if (deathtype == IT_LASER)
224                                         bprint ("^1",s, "^1 was blasted by ", a, "\n");
225                                 else if (deathtype == IT_UZI)
226                                         bprint ("^1",s, "^1 was riddled full of holes by ", a, "\n");
227                                 else if (deathtype == IT_SHOTGUN)
228                                         bprint ("^1",s, "^1 was gunned by ", a, "\n");
229                                 else if (deathtype == IT_GRENADE_LAUNCHER)
230                                         bprint ("^1", s, "^1 was blasted by ", a, "\n");
231                                 else if (deathtype == IT_ELECTRO)
232                                         bprint ("^1",s, "^1 was blasted by ", a, "\n");
233                                 else if (deathtype == IT_CRYLINK)
234                                         bprint ("^1",s, "^1 was blasted by ", a, "\n");
235                                 else if (deathtype == IT_NEX)
236                                         bprint ("^1",s, "^1 has been vaporized by ", a, "\n");
237                                 else if (deathtype == IT_HAGAR)
238                                         bprint ("^1",s, "^1 was pummeled by ", a, "\n");
239                                 else if (deathtype == IT_ROCKET_LAUNCHER)
240                                         bprint ("^1",s, "^1 was blasted by ", a, "\n");
241                                 else if (deathtype == DEATH_TELEFRAG)
242                                         bprint ("^1",s, "^1 was telefragged by ", a, "\n");
243                                 else if (deathtype == DEATH_DROWN)
244                                         bprint ("^1",s, "^1 was drowned by ", a, "\n");
245                                 else if (deathtype == DEATH_SLIME)
246                                         bprint ("^1",s, "^1 was slimed by ", a, "\n");
247                                 else if (deathtype == DEATH_LAVA)
248                                         bprint ("^1",s, "^1 was cooked by ", a, "\n");
249                                 else if (deathtype == DEATH_FALL)
250                                         bprint ("^1",s, "^1 was grounded by ", a, "\n");
251                                 else if (deathtype == DEATH_SHOOTING_STAR)
252                                         bprint ("^1",s, "^1 was shot into space by ", a, "\n");
253                                 else if (deathtype == DEATH_SWAMP)
254                                         bprint ("^1",s, "^1 was conserved by ", a, "\n");
255                                 else if (deathtype == DEATH_HURTTRIGGER)
256                                         bprint ("^1",s, "^1 was thrown into a world of hurt by ", a, "\n");
257                                 else
258                                         bprint ("^1",s, "^1 was fragged by ", a, "\n");
259
260                                 GiveFrags(attacker, targ, 1);
261                                 if (targ.killcount > 2)
262                                         bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", a, "\n");
263                                 attacker.killcount = attacker.killcount + 1;
264                                 if (attacker.killcount > 2)
265                                         bprint ("^1",a,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
266
267                                 LogDeath("frag", deathtype, attacker, targ);
268
269                                 if (attacker.killcount == 3)
270                                 {
271                                         bprint (a,"^7 made a ^1TRIPLE FRAG\n");
272                                         announce(attacker, "announcer/male/03kills.ogg");
273                                 }
274                                 else if (attacker.killcount == 5)
275                                 {
276                                         bprint (a,"^7 made a ^1FIVE FRAG COMBO\n");
277                                         announce(attacker, "announcer/male/05kills.ogg");
278                                 }
279                                 else if (attacker.killcount == 10)
280                                 {
281                                         bprint (a,"^7 is on a ^1RAGE\n");
282                                         announce(attacker, "announcer/male/10kills.ogg");
283                                 }
284                                 else if (attacker.killcount == 15)
285                                 {
286                                         bprint (a,"^7 has done a ^1MASSACRE!\n");
287                                         announce(attacker, "announcer/male/15kills.ogg");
288                                 }
289                                 else if (attacker.killcount == 20)
290                                 {
291                                         bprint (a,"^7 is ^1UNHUMAN!\n");
292                                         announce(attacker, "announcer/male/20kills.ogg");
293                                 }
294                                 else if (attacker.killcount == 25)
295                                 {
296                                         bprint (a,"^7 is a ^1DEATH INCARNATION!\n");
297                                         announce(attacker, "announcer/male/25kills.ogg");
298                                 }
299                                 else if (attacker.killcount == 30)
300                                 {
301                                         bprint (a,"^7 is maybe a ^1AIMBOTTER?!\n");
302                                         announce(attacker, "announcer/male/30kills.ogg");
303                                 }
304                         }
305                 }
306                 else
307                 {
308                         centerprint(targ, "^1Watch your step!\n\n\n");
309                         if (deathtype == DEATH_HURTTRIGGER && attacker.message != "")
310                                 bprint ("^1",s, "^1 ", attacker.message, "\n");
311                         else if (deathtype == DEATH_DROWN)
312                                 bprint ("^1",s, "^1 drowned\n");
313                         else if (deathtype == DEATH_SLIME)
314                                 bprint ("^1",s, "^1 was slimed\n");
315                         else if (deathtype == DEATH_LAVA)
316                                 bprint ("^1",s, "^1 turned into hot slag\n");
317                         else if (deathtype == DEATH_FALL)
318                                 bprint ("^1",s, "^1 hit the ground with a crunch\n");
319                         else if (deathtype == DEATH_SHOOTING_STAR)
320                                 bprint ("^1",s, "^1 became a shooting star\n");
321                         else if (deathtype == DEATH_SWAMP)
322                                 bprint ("^1",s, "^1 is now conserved for centuries to come\n");
323                         else
324                                 bprint ("^1",s, "^1 died\n");
325                         GiveFrags(targ, targ, -1);
326                         if(targ.frags == -5) {
327                                 announce(targ, "announcer/male/botlike.ogg");
328                         }
329
330                         if (targ.killcount > 2)
331                                 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
332
333                         LogDeath("accident", deathtype, targ, targ);
334                 }
335                 targ.death_origin = targ.origin;
336                 if(targ != attacker)
337                         targ.killer_origin = attacker.origin;
338                 // FIXME: this should go in PutClientInServer
339                 if (targ.killcount)
340                         targ.killcount = 0;
341         }
342 }
343
344 // these are updated by each Damage call for use in button triggering and such
345 entity damage_targ;
346 entity damage_inflictor;
347 entity damage_attacker;
348
349 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
350 {
351         float mirrordamage;
352         float mirrorforce;
353         entity attacker_save;
354         mirrordamage = 0;
355         mirrorforce = 0;
356
357         if (gameover || targ.killcount == -666)
358                 return;
359
360         local entity oldself;
361         oldself = self;
362         self = targ;
363         damage_targ = targ;
364         damage_inflictor = inflictor;
365         damage_attacker = attacker;
366                 attacker_save = attacker;
367
368         if(deathtype == DEATH_KILL || deathtype == DEATH_TEAMCHANGE || deathtype == DEATH_AUTOTEAMCHANGE)
369         {
370                 // These are ALWAYS lethal
371                 // No damage modification here
372                 // Instead, prepare the victim for his death...
373                 targ.armorvalue = 0;
374                 targ.spawnshieldtime = 0;
375                 targ.health = 1;
376                 targ.flags -= targ.flags & FL_GODMODE;
377                 damage = 100000;
378         }
379         else
380         {
381                 if (targ.classname == "player")
382                 if (attacker.classname == "player")
383                 if (!targ.isbot)
384                 if (attacker.isbot)
385                         damage = damage * bound(0.1, (skill + 5) * 0.1, 1);
386
387                 // nullify damage if teamplay is on
388                 if(deathtype != DEATH_TELEFRAG)
389                 if(attacker.team == targ.team)
390                 if(attacker.classname == "player")
391                 {
392                         if(teamplay == 1)
393                                 damage = 0;
394                         else if(attacker != targ)
395                         {
396                                 if(teamplay == 3)
397                                         damage = 0;
398                                 else if(teamplay == 4)
399                                 {
400                                         if(targ.classname == "player" && targ.deadflag == DEAD_NO)
401                                         {
402                                                 mirrordamage = cvar("g_mirrordamage") * damage;
403                                                 mirrorforce = cvar("g_mirrordamage") * vlen(force);
404                                                 if(g_minstagib)
405                                                 {
406                                                         if(cvar("g_friendlyfire") == 0)
407                                                                 damage = 0;
408                                                 }
409                                                 else
410                                                         damage = cvar("g_friendlyfire") * damage;
411                                                 // mirrordamage will be used LATER
412                                         }
413                                         else
414                                                 damage = 0;
415                                 }
416                         }
417                 }
418
419                 if(g_lms)
420                 if(targ.classname == "player")
421                 if(attacker.classname == "player")
422                 if(attacker != targ)
423                 {
424                         targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
425                         attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
426                 }
427
428                 if(targ != attacker)
429                 if(!targ.deadflag)
430                 if(damage > 0)
431                 if(targ.classname == "player")
432                 if(attacker)
433                         attacker.hitsound += 1;
434
435                 if (g_minstagib)
436                 {
437                         if ((deathtype == DEATH_FALL)  ||
438                                 (deathtype == DEATH_DROWN) ||
439                                 (deathtype == DEATH_SLIME) ||
440                                 (deathtype == DEATH_LAVA))
441                                 return;
442                         if (targ.armorvalue && (deathtype == IT_NEX) && damage)
443                         {
444                                 targ.armorvalue -= 1;
445                                 centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.armorvalue),"\n"));
446                                 damage = 0;
447                                 targ.hitsound += 1;
448                         }
449                         else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
450                         {
451                                 if(clienttype(attacker) == CLIENTTYPE_REAL)
452                                         if(IsDifferentTeam(self, attacker))
453                                                 yoda = 1;
454                         }
455                         if (deathtype == IT_LASER)
456                         {
457                                 damage = 0;
458                                 if (targ != attacker)
459                                 {
460                                         if (targ.classname == "player")
461                                                 centerprint(attacker, "Secondary fire inflicts no damage!\n");
462                                         damage = 0;
463                                         mirrordamage = 0;
464                                         force = '0 0 0';
465                                         // keep mirrorforce
466                                         attacker = targ;
467                                 }
468                         }
469                 } else {
470                         if (!targ.deadflag)
471                                 if(targ.takedamage == DAMAGE_AIM)
472                                         if(IsFlying(targ))
473                                                 if(IsDifferentTeam(self, targ))
474                                                         yoda = 1;
475                 }
476
477                 // apply strength multiplier
478                 if (attacker.items & IT_STRENGTH && !g_minstagib)
479                 {
480                         damage = damage * cvar("g_balance_powerup_strength_damage");
481                         force = force * cvar("g_balance_powerup_strength_force");
482                 }
483                 // apply invincibility multiplier
484                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
485                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
486
487
488                 if(g_runematch)
489                 {
490                         // apply strength rune
491                         if (attacker.runes & RUNE_STRENGTH)
492                         {
493                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
494                                 {
495                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
496                                         force = force * cvar("g_balance_rune_strength_combo_force");
497                                 }
498                                 else
499                                 {
500                                         damage = damage * cvar("g_balance_rune_strength_damage");
501                                         force = force * cvar("g_balance_rune_strength_force");
502                                 }
503                         }
504                         else if (attacker.runes & CURSE_WEAK)
505                         {
506                                 damage = damage * cvar("g_balance_curse_weak_damage");
507                                 force = force * cvar("g_balance_curse_weak_force");
508                         }
509
510                         // apply defense rune
511                         if (targ.runes & RUNE_DEFENSE)
512                         {
513                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
514                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
515                                 else
516                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
517                         }
518                         else if (targ.runes & CURSE_VULNER)
519                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
520                 }
521         }
522
523         // apply push
524         if (self.damageforcescale)
525         {
526                 self.velocity = self.velocity + self.damageforcescale * force;
527                 self.flags = self.flags - (self.flags & FL_ONGROUND);
528         }
529         // apply damage
530         if (self.event_damage)
531                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
532         self = oldself;
533
534         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
535         {
536                 // Savage: vampire mode
537                 if(g_vampire && !g_minstagib)
538                 {
539                         attacker.health += damage;
540                 }
541                 if(g_runematch)
542                 {
543                         if (attacker.runes & RUNE_VAMPIRE)
544                         {
545                         // apply vampire rune
546                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
547                                 {
548                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
549                                         attacker.health = bound(
550                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
551                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
552                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
553                                 }
554                                 else
555                                 {
556                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
557                                         attacker.health = bound(
558                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
559                                                                                         // empathy won't let you gain health in the same way...
560                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
561                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
562                                         }
563                         }
564                         // apply empathy curse
565                         else if (attacker.runes & CURSE_EMPATHY)
566                         {
567                                 attacker.health = bound(
568                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
569                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
570                                         attacker.health);
571                         }
572                 }
573         }
574
575         // apply mirror damage if any
576         if(mirrordamage > 0 || mirrorforce > 0)
577         {
578                 attacker = attacker_save;
579                 if(g_minstagib)
580                         if(mirrordamage > 0)
581                         {
582                                 // just lose extra LIVES, don't kill the player for mirror damage
583                                 if(attacker.armorvalue > 0)
584                                 {
585                                         attacker.armorvalue = attacker.armorvalue - 1;
586                                         centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
587                                         attacker.hitsound += 1;
588                                 }
589                                 mirrordamage = 0;
590                         }
591                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
592                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
593         }
594 }
595
596 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
597 // Returns total damage applies to creatures
598 {
599         entity  targ;
600         float   finaldmg;
601         float   power;
602         vector  blastorigin;
603         vector  force;
604         vector  m1;
605         vector  m2;
606         vector  nearest;
607         vector  diff;
608         vector  center;
609         float   total_damage_to_creatures;
610
611         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
612         total_damage_to_creatures = 0;
613
614         targ = findradius (blastorigin, rad);
615         while (targ)
616         {
617                 if (targ != inflictor)
618                         if (ignore != targ)
619                         {
620                                 // LordHavoc: measure distance to nearest point on target (not origin)
621                                 // (this guarentees 100% damage on a touch impact)
622                                 nearest = blastorigin;
623                                 m1 = targ.origin + targ.mins;
624                                 m2 = targ.origin + targ.maxs;
625                                 if (nearest_x < m1_x) nearest_x = m1_x;
626                                 if (nearest_y < m1_y) nearest_y = m1_y;
627                                 if (nearest_z < m1_z) nearest_z = m1_z;
628                                 if (nearest_x > m2_x) nearest_x = m2_x;
629                                 if (nearest_y > m2_y) nearest_y = m2_y;
630                                 if (nearest_z > m2_z) nearest_z = m2_z;
631                                 diff = nearest - blastorigin;
632                                 // round up a little on the damage to ensure full damage on impacts
633                                 // and turn the distance into a fraction of the radius
634                                 power = 1 - ((vlen (diff) - 2) / rad);
635                                 //bprint(" ");
636                                 //bprint(ftos(power));
637                                 if (power > 0)
638                                 {
639                                         if (power > 1)
640                                                 power = 1;
641                                         finaldmg = coredamage * power + edgedamage * (1 - power);
642                                         if (finaldmg > 0)
643                                         {
644                                                 center = (m1 + m2) * 0.5;
645                                                 // if it's a player, use the view origin as reference
646                                                 if (targ.classname == "player")
647                                                         center = targ.origin + targ.view_ofs;
648                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
649                                                 if (targ == attacker)
650                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
651                                                 // test line of sight to multiple positions on box,
652                                                 // and do damage if any of them hit
653                                                 local float c;
654                                                 c = ceil(finaldmg / 10);
655                                                 if (c > 20)
656                                                         c = 20;
657                                                 while (c > 0)
658                                                 {
659                                                         c = c - 1;
660                                                         traceline(blastorigin, nearest, TRUE, inflictor);
661                                                         if (trace_fraction == 1 || trace_ent == targ
662                                                             || cvar("g_throughfloor"))
663                                                         {
664                                                                 if(targ.iscreature)
665                                                                         total_damage_to_creatures += finaldmg;
666                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
667                                                                 break;
668                                                         }
669                                                         nearest_x = m1_x + random() * targ.size_x;
670                                                         nearest_y = m1_y + random() * targ.size_y;
671                                                         nearest_z = m1_z + random() * targ.size_z;
672                                                 }
673                                         }
674                                 }
675                         }
676                 targ = targ.chain;
677         }
678
679         return total_damage_to_creatures;
680 }