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