]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
oops, forgot team check for minstagib yoda. Fixed.
[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(IsFlying(targ))
472                                         if(IsDifferentTeam(self, targ))
473                                                 yoda = 1;
474                 }
475
476                 // apply strength multiplier
477                 if (attacker.items & IT_STRENGTH && !g_minstagib)
478                 {
479                         damage = damage * cvar("g_balance_powerup_strength_damage");
480                         force = force * cvar("g_balance_powerup_strength_force");
481                 }
482                 // apply invincibility multiplier
483                 if (targ.items & IT_INVINCIBLE && !g_minstagib)
484                         damage = damage * cvar("g_balance_powerup_invincible_takedamage");
485
486
487                 if(g_runematch)
488                 {
489                         // apply strength rune
490                         if (attacker.runes & RUNE_STRENGTH)
491                         {
492                                 if(attacker.runes & CURSE_WEAK) // have both curse & rune
493                                 {
494                                         damage = damage * cvar("g_balance_rune_strength_combo_damage");
495                                         force = force * cvar("g_balance_rune_strength_combo_force");
496                                 }
497                                 else
498                                 {
499                                         damage = damage * cvar("g_balance_rune_strength_damage");
500                                         force = force * cvar("g_balance_rune_strength_force");
501                                 }
502                         }
503                         else if (attacker.runes & CURSE_WEAK)
504                         {
505                                 damage = damage * cvar("g_balance_curse_weak_damage");
506                                 force = force * cvar("g_balance_curse_weak_force");
507                         }
508
509                         // apply defense rune
510                         if (targ.runes & RUNE_DEFENSE)
511                         {
512                                 if (targ.runes & CURSE_VULNER) // have both curse & rune
513                                         damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
514                                 else
515                                         damage = damage * cvar("g_balance_rune_defense_takedamage");
516                         }
517                         else if (targ.runes & CURSE_VULNER)
518                                 damage = damage * cvar("g_balance_curse_vulner_takedamage");
519                 }
520         }
521
522         // apply push
523         if (self.damageforcescale)
524         {
525                 self.velocity = self.velocity + self.damageforcescale * force;
526                 self.flags = self.flags - (self.flags & FL_ONGROUND);
527         }
528         // apply damage
529         if (self.event_damage)
530                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
531         self = oldself;
532
533         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
534         {
535                 // Savage: vampire mode
536                 if(g_vampire && !g_minstagib)
537                 {
538                         attacker.health += damage;
539                 }
540                 if(g_runematch)
541                 {
542                         if (attacker.runes & RUNE_VAMPIRE)
543                         {
544                         // apply vampire rune
545                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
546                                 {
547                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
548                                         attacker.health = bound(
549                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
550                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
551                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
552                                 }
553                                 else
554                                 {
555                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
556                                         attacker.health = bound(
557                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
558                                                                                         // empathy won't let you gain health in the same way...
559                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
560                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
561                                         }
562                         }
563                         // apply empathy curse
564                         else if (attacker.runes & CURSE_EMPATHY)
565                         {
566                                 attacker.health = bound(
567                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
568                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
569                                         attacker.health);
570                         }
571                 }
572         }
573
574         // apply mirror damage if any
575         if(mirrordamage > 0 || mirrorforce > 0)
576         {
577                 attacker = attacker_save;
578                 if(g_minstagib)
579                         if(mirrordamage > 0)
580                         {
581                                 // just lose extra LIVES, don't kill the player for mirror damage
582                                 if(attacker.armorvalue > 0)
583                                 {
584                                         attacker.armorvalue = attacker.armorvalue - 1;
585                                         centerprint(attacker, strcat("^3Remaining extra lives: ",ftos(attacker.armorvalue),"\n"));
586                                         attacker.hitsound += 1;
587                                 }
588                                 mirrordamage = 0;
589                         }
590                 force = normalize(attacker.origin + attacker.view_ofs - hitloc) * mirrorforce;
591                 Damage(attacker, inflictor, attacker, mirrordamage, DEATH_MIRRORDAMAGE, attacker.origin, force);
592         }
593 }
594
595 float RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
596 // Returns total damage applies to creatures
597 {
598         entity  targ;
599         float   finaldmg;
600         float   power;
601         vector  blastorigin;
602         vector  force;
603         vector  m1;
604         vector  m2;
605         vector  nearest;
606         vector  diff;
607         vector  center;
608         float   total_damage_to_creatures;
609
610         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
611         total_damage_to_creatures = 0;
612
613         targ = findradius (blastorigin, rad);
614         while (targ)
615         {
616                 if (targ != inflictor)
617                         if (ignore != targ)
618                         {
619                                 // LordHavoc: measure distance to nearest point on target (not origin)
620                                 // (this guarentees 100% damage on a touch impact)
621                                 nearest = blastorigin;
622                                 m1 = targ.origin + targ.mins;
623                                 m2 = targ.origin + targ.maxs;
624                                 if (nearest_x < m1_x) nearest_x = m1_x;
625                                 if (nearest_y < m1_y) nearest_y = m1_y;
626                                 if (nearest_z < m1_z) nearest_z = m1_z;
627                                 if (nearest_x > m2_x) nearest_x = m2_x;
628                                 if (nearest_y > m2_y) nearest_y = m2_y;
629                                 if (nearest_z > m2_z) nearest_z = m2_z;
630                                 diff = nearest - blastorigin;
631                                 // round up a little on the damage to ensure full damage on impacts
632                                 // and turn the distance into a fraction of the radius
633                                 power = 1 - ((vlen (diff) - 2) / rad);
634                                 //bprint(" ");
635                                 //bprint(ftos(power));
636                                 if (power > 0)
637                                 {
638                                         if (power > 1)
639                                                 power = 1;
640                                         finaldmg = coredamage * power + edgedamage * (1 - power);
641                                         if (finaldmg > 0)
642                                         {
643                                                 center = (m1 + m2) * 0.5;
644                                                 // if it's a player, use the view origin as reference
645                                                 if (targ.classname == "player")
646                                                         center = targ.origin + targ.view_ofs;
647                                                 force = normalize(center - blastorigin) * (finaldmg / coredamage) * forceintensity;
648                                                 if (targ == attacker)
649                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
650                                                 // test line of sight to multiple positions on box,
651                                                 // and do damage if any of them hit
652                                                 local float c;
653                                                 c = ceil(finaldmg / 10);
654                                                 if (c > 20)
655                                                         c = 20;
656                                                 while (c > 0)
657                                                 {
658                                                         c = c - 1;
659                                                         traceline(blastorigin, nearest, TRUE, inflictor);
660                                                         if (trace_fraction == 1 || trace_ent == targ
661                                                             || cvar("g_throughfloor"))
662                                                         {
663                                                                 if(targ.iscreature)
664                                                                         total_damage_to_creatures += finaldmg;
665                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
666                                                                 break;
667                                                         }
668                                                         nearest_x = m1_x + random() * targ.size_x;
669                                                         nearest_y = m1_y + random() * targ.size_y;
670                                                         nearest_z = m1_z + random() * targ.size_z;
671                                                 }
672                                         }
673                                 }
674                         }
675                 targ = targ.chain;
676         }
677
678         return total_damage_to_creatures;
679 }
680
681 /*
682 entity  multi_ent;
683 float   multi_damage;
684 vector  multi_force;
685
686 void ClearMultiDamage (void)
687 {
688         multi_ent = world;
689         multi_damage = 0;
690         multi_force = '0 0 0';
691 }
692
693 void ApplyMultiDamage (void)
694 {
695         if (!multi_ent)
696                 return;
697
698         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
699 }
700
701 void AddMultiDamage (entity hit, float damage, vector force)
702 {
703         if (!hit)
704                 return;
705
706         if (hit != multi_ent)
707         {
708                 ApplyMultiDamage ();
709                 ClearMultiDamage ();
710                 multi_ent = hit;
711         }
712         multi_damage = multi_damage + damage;
713         multi_force = multi_force + force;
714 }
715
716 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
717 {
718         vector  direction;
719         vector  source;
720         vector  vel;
721         vector  org;
722
723         makevectors (self.v_angle);
724
725         source = self.origin + v_forward * 10;  // FIXME
726         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
727
728         // LordHavoc: better to use normal damage
729         //ClearMultiDamage ();
730         while (shotcount > 0)
731         {
732                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
733
734                 traceline (source, source + direction * 2048, FALSE, self);
735                 if (trace_fraction != 1.0)
736                 {
737                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
738                         vel = vel + 2 * trace_plane_normal;
739                         vel = vel * 200;
740
741                         org = trace_endpos - direction * 4;
742
743                         if (!trace_ent.takedamage)
744                                 te_gunshot (org);
745                         // LordHavoc: better to use normal damage
746                         //AddMultiDamage (trace_ent, 4, direction * 4);
747                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
748                 }
749
750                 shotcount = shotcount + 1;
751         }
752
753         // LordHavoc: better to use normal damage
754         //ApplyMultiDamage ();
755 }
756 */
757
758
759