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