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