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