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