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