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