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