]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/g_damage.qc
changed radius damage code to check for occlusion, and only do damage if
[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(weapon_translateindextoflag(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
132                                 centerprint(targ, strcat("^1You killed your own dumb self!\n\n\n"));
133
134                         if (deathtype == IT_GRENADE_LAUNCHER)
135                                 bprint ("^1",s, "^1 detonated\n");
136                         else if (deathtype == IT_ELECTRO)
137                                 bprint ("^1",s, "^1 played with plasma\n");
138                         else if (deathtype == IT_ROCKET_LAUNCHER)
139                                 bprint ("^1",s, "^1 exploded\n");
140                         else if (deathtype == DEATH_KILL)
141                                 bprint ("^1",s, "^1 couldn't take it anymore\n");
142                         else if (deathtype == DEATH_ROT)
143                                 bprint ("^1",s, "^1 died\n");
144                         else if (deathtype == DEATH_NOAMMO)
145                         {
146                                 bprint ("^7",s, " ^7committed suicide. What's the point of living without ammo?\n");
147                                 //sound (self, CHAN_BODY, "minstagib/mockery.ogg", 1, ATTN_NONE);
148                         }
149                         else if (deathtype == DEATH_CAMP)
150                                 bprint ("^1",s, "^1 thought he found a nice camping ground\n");
151                         else if (deathtype != DEATH_TEAMCHANGE)
152                                 bprint ("^1",s, "^1 couldn't resist the urge to self-destruct\n");
153
154                         if(deathtype != DEATH_TEAMCHANGE)
155                                 LogDeath("suicide", deathtype, targ, targ);
156
157                         GiveFrags(attacker, targ, -1);
158                         //targ.frags = targ.frags - 1;
159                         if (targ.killcount > 2)
160                                 bprint ("^1",s,"^1 ended it all with a ",ftos(targ.killcount)," kill spree\n");
161                 }
162                 else if (teamplay && attacker.team == targ.team)
163                 {
164                         centerprint(attacker, strcat("^1Moron! You fragged a teammate!\n\n\n"));
165                         bprint ("^1", attacker.netname, "^1 mows down a teammate\n");
166                         GiveFrags(attacker, targ, -1);
167                         //attacker.frags = attacker.frags - 1;
168                         if (targ.killcount > 2)
169                                 bprint ("^1",s,"'s ^1",ftos(targ.killcount)," kill spree was endeded by a teammate!\n");
170                         if (attacker.killcount > 2)
171                                 bprint ("^1",attacker.netname,"^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 if (attacker.classname == "player" || attacker.classname == "gib")
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.ogg", 1, ATTN_NONE);
184                                 bprint("^1",attacker.netname, "^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", attacker.netname, "\n\n\n"));
189
190                         if (deathtype == IT_LASER)
191                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
192                         else if (deathtype == IT_UZI)
193                                 bprint ("^1",s, "^1 was riddled full of holes by ", attacker.netname, "\n");
194                         else if (deathtype == IT_SHOTGUN)
195                                 bprint ("^1",s, "^1 was gunned by ", attacker.netname, "\n");
196                         else if (deathtype == IT_GRENADE_LAUNCHER)
197                                 bprint ("^1", s, "^1 was blasted by ", attacker.netname, "\n");
198                         else if (deathtype == IT_ELECTRO)
199                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
200                         else if (deathtype == IT_CRYLINK)
201                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
202                         else if (deathtype == IT_NEX)
203                                 bprint ("^1",s, "^1 has been vaporized by ", attacker.netname, "\n");
204                         else if (deathtype == IT_HAGAR)
205                                 bprint ("^1",s, "^1 was pummeled by ", attacker.netname, "\n");
206                         else if (deathtype == IT_ROCKET_LAUNCHER)
207                                 bprint ("^1",s, "^1 was blasted by ", attacker.netname, "\n");
208                         else if (deathtype == DEATH_TELEFRAG)
209                                 bprint ("^1",s, "^1 was telefragged by ", attacker.netname, "\n");
210                         else if (deathtype == DEATH_DROWN)
211                                 bprint ("^1",s, "^1 was drowned by ", attacker.netname, "\n");
212                         else if (deathtype == DEATH_SLIME)
213                                 bprint ("^1",s, "^1 was slimed by ", attacker.netname, "\n");
214                         else if (deathtype == DEATH_LAVA)
215                                 bprint ("^1",s, "^1 was cooked by ", attacker.netname, "\n");
216                         else if (deathtype == DEATH_FALL)
217                                 bprint ("^1",s, "^1 was grounded by ", attacker.netname, "\n");
218                         else if (deathtype == DEATH_SHOOTING_STAR)
219                                 bprint ("^1",s, "^1 was shot into space by ", attacker.netname, "\n");
220                         else if (deathtype == DEATH_SWAMP)
221                                 bprint ("^1",s, "^1 was conserved by ", attacker.netname, "\n");
222                         else if (deathtype == DEATH_HURTTRIGGER)
223                                 bprint ("^1",s, "^1 was thrown into a world of hurt by ", attacker.netname, "\n");
224                         else
225                                 bprint ("^1",s, "^1 was fragged by ", attacker.netname, "\n");
226
227                         GiveFrags(attacker, targ, 1);
228                         //attacker.frags = attacker.frags + 1;
229                         if (targ.killcount > 2)
230                                 bprint ("^1",s,"'s ^1", ftos(targ.killcount), " kill spree was ended by ", attacker.netname, "\n");
231                         attacker.killcount = attacker.killcount + 1;
232                         if (attacker.killcount > 2)
233                                 bprint ("^1",attacker.netname,"^1 has ",ftos(attacker.killcount)," frags in a row\n");
234
235                         LogDeath("frag", deathtype, attacker, targ);
236
237                         if (attacker.killcount == 3)
238                         {
239                                 bprint (attacker.netname,"^7 made a ^1TRIPLE FRAG\n");
240                                 stuffcmd(attacker, "play2 announcer/male/03kills.ogg\n");
241                         }
242                         else if (attacker.killcount == 5)
243                         {
244                                 bprint (attacker.netname,"^7 made a ^1FIVE FRAG COMBO\n");
245                                 stuffcmd(attacker, "play2 announcer/male/05kills.ogg\n");
246                         }
247                         else if (attacker.killcount == 10)
248                         {
249                                 bprint (attacker.netname,"^7 is on a ^1RAGE\n");
250                                 stuffcmd(attacker, "play2 announcer/male/10kills.ogg\n");
251                         }
252                         else if (attacker.killcount == 15)
253                         {
254                                 bprint (attacker.netname,"^7 has done a ^1MASSACRE!\n");
255                                 stuffcmd(attacker, "play2 announcer/male/15kills.ogg\n");
256                         }
257                         else if (attacker.killcount == 20)
258                         {
259                                 bprint (attacker.netname,"^7 is ^1UNHUMAN!\n");
260                                 stuffcmd(attacker, "play2 announcer/male/20kills.ogg\n");
261                         }
262                         else if (attacker.killcount == 25)
263                         {
264                                 bprint (attacker.netname,"^7 is a ^1DEATH INCARNATION!\n");
265                                 stuffcmd(attacker, "play2 announcer/male/25kills.ogg\n");
266                         }
267                         else if (attacker.killcount == 30)
268                         {
269                                 bprint (attacker.netname,"^7 is maybe a ^1AIMBOTTER?!\n");
270                                 stuffcmd(attacker, "play2 announcer/male/30kills.ogg\n");
271                         }
272                 }
273                 else
274                 {
275                         centerprint(targ, strcat("^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                                 stuffcmd(targ, "play2 announcer/male/botlike.ogg\n");
295                         }
296
297                         //targ.frags = targ.frags - 1;
298                         if (targ.killcount > 2)
299                                 bprint ("^1",s,"^1 died with a ",ftos(targ.killcount)," kill spree\n");
300
301                         LogDeath("accident", deathtype, targ, targ);
302                 }
303                 targ.death_origin = targ.origin;
304                 if(targ != attacker)
305                         targ.killer_origin = attacker.origin;
306                 // FIXME: this should go in PutClientInServer
307                 if (targ.killcount)
308                         targ.killcount = 0;
309         }
310 }
311
312 // these are updated by each Damage call for use in button triggering and such
313 entity damage_targ;
314 entity damage_inflictor;
315 entity damage_attacker;
316
317 void Damage (entity targ, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
318 {
319         if (gameover || targ.killcount == -666)
320                 return;
321
322         local entity oldself;
323         oldself = self;
324         self = targ;
325         damage_targ = targ;
326         damage_inflictor = inflictor;
327         damage_attacker = attacker;
328         // nullify damage if teamplay is on
329         if (teamplay)
330         if (attacker.team)
331         if (attacker.team == targ.team)
332         if (teamplay == 1 || (teamplay == 3 && attacker != targ))
333                 damage = 0;
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         if(cvar("g_lms"))
342         if(targ.classname == "player")
343         if(attacker.classname == "player")
344         if(attacker != targ)
345         {
346                 targ.lms_traveled_distance = cvar("g_lms_campcheck_distance");
347                 attacker.lms_traveled_distance = cvar("g_lms_campcheck_distance");
348         }
349
350         if(damage > 0 && targ != attacker && clienttype(attacker) == CLIENTTYPE_REAL && targ.classname == "player")
351                 stuffcmd(attacker, "play2 misc/hit.wav\n");
352
353         if (cvar("g_minstagib"))
354         {
355                 if ((deathtype == DEATH_FALL)  ||
356                     (deathtype == DEATH_DROWN) ||
357                     (deathtype == DEATH_SLIME) ||
358                     (deathtype == DEATH_LAVA))
359                         return;
360                 if (targ.extralives && (deathtype == IT_NEX) && damage)
361                 {
362                         targ.extralives -= 1;
363                         centerprint(targ, strcat("^3Remaining extra lives: ",ftos(targ.extralives),"\n"));
364                         damage = 0;
365                         targ.armorvalue = targ.extralives;
366                         if(clienttype(targ) == CLIENTTYPE_REAL) stuffcmd(targ, "play2 misc/hit.wav\n");
367                         //stuffcmd(attacker, "play2 misc/hit.wav\n");
368                 }
369                 else if (deathtype == IT_NEX && targ.items & IT_STRENGTH)
370                 {
371                         if(clienttype(attacker) == CLIENTTYPE_REAL) stuffcmd(attacker, "play2 announcer/male/yoda.ogg\n");
372                 }
373                 if (deathtype == IT_LASER)
374                 {
375                         damage = 0;
376                         if (targ != attacker)
377                         {
378                                 if (targ.classname == "player")
379                                         centerprint(attacker, "Secondary fire inflicts no damage!\n");
380                                 damage = 0;
381                                 force = '0 0 0';
382                                 attacker = targ;
383                         }
384                 }
385         } else {
386                 if (deathtype == IT_NEX && !(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)
387                 {
388                         if(clienttype(attacker) == CLIENTTYPE_REAL)  stuffcmd(attacker, "play2 announcer/male/yoda.ogg\n");
389                 }
390         }
391
392         // apply strength multiplier
393         if (attacker.items & IT_STRENGTH && !cvar("g_minstagib"))
394         {
395                 damage = damage * cvar("g_balance_powerup_strength_damage");
396                 force = force * cvar("g_balance_powerup_strength_force");
397         }
398         // apply invincibility multiplier
399         if (targ.items & IT_INVINCIBLE && !cvar("g_minstagib"))
400                 damage = damage * cvar("g_balance_powerup_invincible_takedamage");
401
402
403         if(cvar("g_runematch"))
404         {
405                 // apply strength rune
406                 if (attacker.runes & RUNE_STRENGTH)
407                 {
408                         if(attacker.runes & CURSE_WEAK) // have both curse & rune
409                         {
410                                 damage = damage * cvar("g_balance_rune_strength_combo_damage");
411                                 force = force * cvar("g_balance_rune_strength_combo_force");
412                         }
413                         else
414                         {
415                                 damage = damage * cvar("g_balance_rune_strength_damage");
416                                 force = force * cvar("g_balance_rune_strength_force");
417                         }
418                 }
419                 else if (attacker.runes & CURSE_WEAK)
420                 {
421                         damage = damage * cvar("g_balance_curse_weak_damage");
422                         force = force * cvar("g_balance_curse_weak_force");
423                 }
424
425                 // apply defense rune
426                 if (targ.runes & RUNE_DEFENSE)
427                 {
428                         if (targ.runes & CURSE_VULNER) // have both curse & rune
429                                 damage = damage * cvar("g_balance_rune_defense_combo_takedamage");
430                         else
431                                 damage = damage * cvar("g_balance_rune_defense_takedamage");
432                 }
433                 else if (targ.runes & CURSE_VULNER)
434                         damage = damage * cvar("g_balance_curse_vulner_takedamage");
435         }
436
437         // apply push
438         if (self.damageforcescale)
439         {
440                 self.velocity = self.velocity + self.damageforcescale * force;
441                 self.flags = self.flags - (self.flags & FL_ONGROUND);
442         }
443         // apply damage
444         if (self.event_damage)
445                 self.event_damage (inflictor, attacker, damage, deathtype, hitloc, force);
446         self = oldself;
447
448         if(targ.classname == "player" && attacker.classname == "player" && attacker != targ && attacker.health > 2)
449         {
450                 // Savage: vampire mode
451                 if(cvar("g_vampire") && !cvar("g_minstagib"))
452                 {
453                         attacker.health += damage;
454                 }
455                 if(cvar("g_runematch"))
456                 {
457                         if (attacker.runes & RUNE_VAMPIRE)
458                         {
459                         // apply vampire rune
460                                 if (attacker.runes & CURSE_EMPATHY) // have the curse too
461                                 {
462                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb");
463                                         attacker.health = bound(
464                                                 cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 40
465                                                 attacker.health + damage * cvar("g_balance_rune_vampire_combo_absorb"),
466                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
467                                 }
468                                 else
469                                 {
470                                         //attacker.health = attacker.health + damage * cvar("g_balance_rune_vampire_absorb");
471                                         attacker.health = bound(
472                                                 attacker.health,        // LA: was 3, but changed so that you can't lose health
473                                                                                         // empathy won't let you gain health in the same way...
474                                                 attacker.health + damage * cvar("g_balance_rune_vampire_absorb"),
475                                                 cvar("g_balance_rune_vampire_maxhealth"));      // LA: was 1000, now 500
476                                         }
477                         }
478                         // apply empathy curse
479                         else if (attacker.runes & CURSE_EMPATHY)
480                         {
481                                 attacker.health = bound(
482                                         cvar("g_balance_curse_empathy_minhealth"), // LA: was 3, now 20
483                                         attacker.health + damage * cvar("g_balance_curse_empathy_takedamage"),
484                                         attacker.health);
485                         }
486                 }
487         }
488 }
489
490 void RadiusDamage (entity inflictor, entity attacker, float coredamage, float edgedamage, float rad, entity ignore, float forceintensity, float deathtype)
491 {
492         entity  targ;
493         float   finaldmg;
494         float   power;
495         vector  blastorigin;
496         vector  force;
497         vector  m1;
498         vector  m2;
499         vector  nearest;
500         vector  diff;
501
502         blastorigin = (inflictor.origin + (inflictor.mins + inflictor.maxs) * 0.5);
503
504         targ = findradius (blastorigin, rad);
505         while (targ)
506         {
507                 if (targ != inflictor)
508                         if (ignore != targ)
509                         {
510                                 // LordHavoc: measure distance to nearest point on target (not origin)
511                                 // (this guarentees 100% damage on a touch impact)
512                                 nearest = blastorigin;
513                                 m1 = targ.origin + targ.mins;
514                                 m2 = targ.origin + targ.maxs;
515                                 if (nearest_x < m1_x) nearest_x = m1_x;
516                                 if (nearest_y < m1_y) nearest_y = m1_y;
517                                 if (nearest_z < m1_z) nearest_z = m1_z;
518                                 if (nearest_x > m2_x) nearest_x = m2_x;
519                                 if (nearest_y > m2_y) nearest_y = m2_y;
520                                 if (nearest_z > m2_z) nearest_z = m2_z;
521                                 diff = nearest - blastorigin;
522                                 // round up a little on the damage to ensure full damage on impacts
523                                 // and turn the distance into a fraction of the radius
524                                 power = 1 - ((vlen (diff) - 2) / rad);
525                                 //bprint(" ");
526                                 //bprint(ftos(power));
527                                 if (power > 0)
528                                 {
529                                         if (power > 1)
530                                                 power = 1;
531                                         finaldmg = coredamage * power + edgedamage * (1 - power);
532                                         if (finaldmg > 0)
533                                         {
534                                                 force = normalize((m1 + m2) * 0.5 - blastorigin) * (finaldmg / coredamage) * forceintensity;
535                                                 if (targ == attacker)
536                                                         finaldmg = finaldmg * cvar("g_balance_selfdamagepercent");      // Partial damage if the attacker hits himself
537                                                 // test line of sight to multiple positions on box,
538                                                 // and do damage if any of them hit
539                                                 local float c;
540                                                 c = ceil(finaldmg / 10);
541                                                 if (c > 20)
542                                                         c = 20;
543                                                 while (c > 0)
544                                                 {
545                                                         c = c - 1;
546                                                         traceline(blastorigin, nearest, TRUE, inflictor);
547                                                         if (trace_fraction == 1 || trace_ent == targ)
548                                                         {
549                                                                 Damage (targ, inflictor, attacker, finaldmg, deathtype, nearest, force);
550                                                                 break;
551                                                         }
552                                                         nearest_x = m1_x + random() * targ.size_x;
553                                                         nearest_y = m1_y + random() * targ.size_y;
554                                                         nearest_z = m1_z + random() * targ.size_z;
555                                                 }
556                                         }
557                                 }
558                         }
559                 targ = targ.chain;
560         }
561 }
562
563 /*
564 entity  multi_ent;
565 float   multi_damage;
566 vector  multi_force;
567
568 void ClearMultiDamage (void)
569 {
570         multi_ent = world;
571         multi_damage = 0;
572         multi_force = '0 0 0';
573 }
574
575 void ApplyMultiDamage (void)
576 {
577         if (!multi_ent)
578                 return;
579
580         Damage (self, multi_ent.origin, multi_ent, 0, multi_damage, multi_force);
581 }
582
583 void AddMultiDamage (entity hit, float damage, vector force)
584 {
585         if (!hit)
586                 return;
587
588         if (hit != multi_ent)
589         {
590                 ApplyMultiDamage ();
591                 ClearMultiDamage ();
592                 multi_ent = hit;
593         }
594         multi_damage = multi_damage + damage;
595         multi_force = multi_force + force;
596 }
597
598 void FireBullets (float shotcount, vector dir, vector spread, float deathtype)
599 {
600         vector  direction;
601         vector  source;
602         vector  vel;
603         vector  org;
604
605         makevectors (self.v_angle);
606
607         source = self.origin + v_forward * 10;  // FIXME
608         source_x = self.absmin_z + self.size_z * 0.7;   // ??? whaddabout view_ofs
609
610         // LordHavoc: better to use normal damage
611         //ClearMultiDamage ();
612         while (shotcount > 0)
613         {
614                 direction = dir + crandom () * spread_x * v_right + crandom () * spread_y * v_up;
615
616                 traceline (source, source + direction * 2048, FALSE, self);
617                 if (trace_fraction != 1.0)
618                 {
619                         vel = normalize (direction + v_up * crandom () + v_right * crandom ());
620                         vel = vel + 2 * trace_plane_normal;
621                         vel = vel * 200;
622
623                         org = trace_endpos - direction * 4;
624
625                         if (!trace_ent.takedamage)
626                                 te_gunshot (org);
627                         // LordHavoc: better to use normal damage
628                         //AddMultiDamage (trace_ent, 4, direction * 4);
629                         Damage (trace_ent, self, self, 4, deathtype, trace_endpos, direction * 4);
630                 }
631
632                 shotcount = shotcount + 1;
633         }
634
635         // LordHavoc: better to use normal damage
636         //ApplyMultiDamage ();
637 }
638 */
639
640
641