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