]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_common.qc
work on restructuring fireBallisticBullet
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_common.qc
1
2 void W_GiveWeapon (entity e, float wep)
3 {
4         entity oldself;
5
6         if (!wep)
7                 return;
8
9         e.weapons |= WepSet_FromWeapon(wep);
10
11         oldself = self;
12         self = e;
13
14         if(IS_PLAYER(other))
15                 { Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_WEAPON_GOT, wep); }
16
17         self = oldself;
18 }
19
20 .float railgundistance;
21 .vector railgunforce;
22 void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, float mindist, float maxdist, float halflifedist, float forcehalflifedist, float deathtype)
23 {
24         vector hitloc, force, endpoint, dir;
25         entity ent, endent;
26         float endq3surfaceflags;
27         float totaldmg;
28         entity o;
29
30         float length;
31         vector beampos;
32         string snd;
33         entity pseudoprojectile;
34         float f, ffs;
35
36         pseudoprojectile = world;
37
38         railgun_start = start;
39         railgun_end = end;
40
41         dir = normalize(end - start);
42         length = vlen(end - start);
43         force = dir * bforce;
44
45         // go a little bit into the wall because we need to hit this wall later
46         end = end + dir;
47
48         totaldmg = 0;
49
50         // trace multiple times until we hit a wall, each obstacle will be made
51         // non-solid so we can hit the next, while doing this we spawn effects and
52         // note down which entities were hit so we can damage them later
53         o = self;
54         while (1)
55         {
56                 if(self.antilag_debug)
57                         WarpZone_traceline_antilag (self, start, end, FALSE, o, self.antilag_debug);
58                 else
59                         WarpZone_traceline_antilag (self, start, end, FALSE, o, ANTILAG_LATENCY(self));
60                 if(o && WarpZone_trace_firstzone)
61                 {
62                         o = world;
63                         continue;
64                 }
65
66                 if(trace_ent.solid == SOLID_BSP || trace_ent.solid == SOLID_SLIDEBOX)
67                         Damage_DamageInfo(trace_endpos, bdamage, 0, 0, force, deathtype, trace_ent.species, self);
68
69                 // if it is world we can't hurt it so stop now
70                 if (trace_ent == world || trace_fraction == 1)
71                         break;
72
73                 // make the entity non-solid so we can hit the next one
74                 trace_ent.railgunhit = TRUE;
75                 trace_ent.railgunhitloc = end;
76                 trace_ent.railgunhitsolidbackup = trace_ent.solid;
77                 trace_ent.railgundistance = vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - start);
78                 trace_ent.railgunforce = WarpZone_TransformVelocity(WarpZone_trace_transform, force);
79
80                 // stop if this is a wall
81                 if (trace_ent.solid == SOLID_BSP)
82                         break;
83
84                 // make the entity non-solid
85                 trace_ent.solid = SOLID_NOT;
86         }
87
88         endpoint = trace_endpos;
89         endent = trace_ent;
90         endq3surfaceflags = trace_dphitq3surfaceflags;
91
92         // find all the entities the railgun hit and restore their solid state
93         ent = findfloat(world, railgunhit, TRUE);
94         while (ent)
95         {
96                 // restore their solid type
97                 ent.solid = ent.railgunhitsolidbackup;
98                 ent = findfloat(ent, railgunhit, TRUE);
99         }
100
101         // spawn a temporary explosion entity for RadiusDamage calls
102         //explosion = spawn();
103
104         // Find all non-hit players the beam passed close by
105         if(deathtype == WEP_MINSTANEX || deathtype == WEP_NEX)
106         {
107                 FOR_EACH_REALCLIENT(msg_entity)
108                 if(msg_entity != self)
109                 if(!msg_entity.railgunhit)
110                 if(!(IS_SPEC(msg_entity) && msg_entity.enemy == self)) // we use realclient, so spectators can hear the whoosh too
111                 {
112                         // nearest point on the beam
113                         beampos = start + dir * bound(0, (msg_entity.origin - start) * dir, length);
114
115                         f = bound(0, 1 - vlen(beampos - msg_entity.origin) / 512, 1);
116                         if(f <= 0)
117                                 continue;
118
119                         snd = strcat("weapons/nexwhoosh", ftos(floor(random() * 3) + 1), ".wav");
120
121                         if(!pseudoprojectile)
122                                 pseudoprojectile = spawn(); // we need this so the sound uses the "entchannel4" volume
123                         soundtoat(MSG_ONE, pseudoprojectile, beampos, CH_SHOTS, snd, VOL_BASE * f, ATTEN_NONE);
124                 }
125
126                 if(pseudoprojectile)
127                         remove(pseudoprojectile);
128         }
129
130         // find all the entities the railgun hit and hurt them
131         ent = findfloat(world, railgunhit, TRUE);
132         while (ent)
133         {
134                 // get the details we need to call the damage function
135                 hitloc = ent.railgunhitloc;
136
137                 f = ExponentialFalloff(mindist, maxdist, halflifedist, ent.railgundistance);
138                 ffs = ExponentialFalloff(mindist, maxdist, forcehalflifedist, ent.railgundistance);
139
140                 if(accuracy_isgooddamage(self.realowner, ent))
141                         totaldmg += bdamage * f;
142
143                 // apply the damage
144                 if (ent.takedamage)
145                         Damage (ent, self, self, bdamage * f, deathtype, hitloc, ent.railgunforce * ffs);
146
147                 // create a small explosion to throw gibs around (if applicable)
148                 //setorigin (explosion, hitloc);
149                 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);
150
151                 ent.railgunhitloc = '0 0 0';
152                 ent.railgunhitsolidbackup = SOLID_NOT;
153                 ent.railgunhit = FALSE;
154                 ent.railgundistance = 0;
155
156                 // advance to the next entity
157                 ent = findfloat(ent, railgunhit, TRUE);
158         }
159
160         // calculate hits and fired shots for hitscan
161         accuracy_add(self, self.weapon, 0, min(bdamage, totaldmg));
162
163         trace_endpos = endpoint;
164         trace_ent = endent;
165         trace_dphitq3surfaceflags = endq3surfaceflags;
166 }
167
168 .float dmg_force;
169 .float dmg_radius;
170 .float dmg_total;
171 //.float last_yoda;
172 void W_BallisticBullet_Hit (void)
173 {
174         float f, q, g;
175
176         f = pow(bound(0, vlen(self.velocity) / vlen(self.oldvelocity), 1), 2); // energy multiplier
177         q = 1 + self.dmg_edge / self.dmg;
178
179         if(other.solid == SOLID_BSP || other.solid == SOLID_SLIDEBOX)
180                 Damage_DamageInfo(self.origin, self.dmg * f, 0, 0, max(1, self.dmg_force) * normalize(self.velocity) * f, self.projectiledeathtype, other.species, self);
181
182         if(other && other != self.enemy)
183         {
184                 endzcurveparticles();
185
186                 yoda = 0;
187                 railgun_start = self.origin - 2 * frametime * self.velocity;
188                 railgun_end = self.origin + 2 * frametime * self.velocity;
189                 g = accuracy_isgooddamage(self.realowner, other);
190                 Damage(other, self, self.realowner, self.dmg * f, self.projectiledeathtype, self.origin, self.dmg_force * normalize(self.velocity) * f);
191
192                 /*if(yoda && (time > (self.last_yoda + 5)))
193                 {
194                         Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_YODA);
195                         self.last_yoda = time;
196                 }*/
197
198                 // calculate hits for ballistic weapons
199                 if(g)
200                 {
201                         // do not exceed 100%
202                         q = min(self.dmg * q, self.dmg_total + f * self.dmg) - self.dmg_total;
203                         self.dmg_total += f * self.dmg;
204                         accuracy_add(self.realowner, self.realowner.weapon, 0, q);
205                 }
206         }
207
208         self.enemy = other; // don't hit the same player twice with the same bullet
209 }
210
211 .void(void) W_BallisticBullet_LeaveSolid_think_save;
212 .float W_BallisticBullet_LeaveSolid_nextthink_save;
213 .vector W_BallisticBullet_LeaveSolid_origin;
214 .vector W_BallisticBullet_LeaveSolid_velocity;
215
216 void W_BallisticBullet_LeaveSolid_think()
217 {
218         setorigin(self, self.W_BallisticBullet_LeaveSolid_origin);
219         self.velocity = self.W_BallisticBullet_LeaveSolid_velocity;
220
221         self.think = self.W_BallisticBullet_LeaveSolid_think_save;
222         self.nextthink = max(time, self.W_BallisticBullet_LeaveSolid_nextthink_save);
223         self.W_BallisticBullet_LeaveSolid_think_save = func_null;
224
225         self.flags &= ~FL_ONGROUND;
226
227         if(self.enemy.solid == SOLID_BSP)
228         {
229                 float f;
230                 f = pow(bound(0, vlen(self.velocity) / vlen(self.oldvelocity), 1), 2); // energy multiplier
231                 Damage_DamageInfo(self.origin, 0, 0, 0, max(1, self.dmg_force) * normalize(self.velocity) * -f, self.projectiledeathtype, 0, self);
232         }
233
234         UpdateCSQCProjectile(self);
235 }
236
237 float W_BallisticBullet_LeaveSolid(float eff)
238 {
239         // move the entity along its velocity until it's out of solid, then let it resume
240         vector vel = self.velocity;
241         float dt, dst, velfactor, v0, vs;
242         float maxdist;
243         float E0_m, Es_m;
244         float constant = self.dmg_radius * (other.ballistics_density ? other.ballistics_density : 1);
245
246         // outside the world? forget it
247         if(self.origin_x > world.maxs_x || self.origin_y > world.maxs_y || self.origin_z > world.maxs_z || self.origin_x < world.mins_x || self.origin_y < world.mins_y || self.origin_z < world.mins_z)
248                 return 0;
249
250         // special case for zero density and zero bullet constant:
251
252         if(self.dmg_radius == 0)
253         {
254                 if(other.ballistics_density < 0)
255                         constant = 0; // infinite travel distance
256                 else
257                         return 0; // no penetration
258         }
259         else
260         {
261                 if(other.ballistics_density < 0)
262                         constant = 0; // infinite travel distance
263                 else if(other.ballistics_density == 0)
264                         constant = self.dmg_radius;
265                 else
266                         constant = self.dmg_radius * other.ballistics_density;
267         }
268
269         // E(s) = E0 - constant * s, constant = area of bullet circle * material constant / mass
270         v0 = vlen(vel);
271
272         E0_m = 0.5 * v0 * v0;
273
274         if(constant)
275         {
276                 maxdist = E0_m / constant;
277                 // maxdist = 0.5 * v0 * v0 / constant
278                 // dprint("max dist = ", ftos(maxdist), "\n");
279
280                 if(maxdist <= autocvar_g_ballistics_mindistance)
281                         return 0;
282         }
283         else
284         {
285                 maxdist = vlen(other.maxs - other.mins) + 1; // any distance, as long as we leave the entity
286         }
287
288         traceline_inverted (self.origin, self.origin + normalize(vel) * maxdist, MOVE_NORMAL, self, TRUE);
289         if(trace_fraction == 1) // 1: we never got out of solid
290                 return 0;
291
292         self.W_BallisticBullet_LeaveSolid_origin = trace_endpos;
293
294         dst = max(autocvar_g_ballistics_mindistance, vlen(trace_endpos - self.origin));
295         // E(s) = E0 - constant * s, constant = area of bullet circle * material constant / mass
296         Es_m = E0_m - constant * dst;
297         if(Es_m <= 0)
298         {
299                 // roundoff errors got us
300                 return 0;
301         }
302         vs = sqrt(2 * Es_m);
303         velfactor = vs / v0;
304
305         dt = dst / (0.5 * (v0 + vs));
306         // this is not correct, but the differential equations have no analytic
307         // solution - and these times are very small anyway
308         //print("dt = ", ftos(dt), "\n");
309
310         self.W_BallisticBullet_LeaveSolid_think_save = self.think;
311         self.W_BallisticBullet_LeaveSolid_nextthink_save = self.nextthink;
312         self.think = W_BallisticBullet_LeaveSolid_think;
313         self.nextthink = time + dt;
314
315         vel = vel * velfactor;
316
317         self.velocity = '0 0 0';
318         self.flags |= FL_ONGROUND; // prevent moving
319         self.W_BallisticBullet_LeaveSolid_velocity = vel;
320
321         if(eff >= 0)
322                 if(vlen(trace_endpos - self.origin) > 4)
323                 {
324                         endzcurveparticles();
325                         trailparticles(self, eff, self.origin, trace_endpos);
326                 }
327
328         return 1;
329 }
330
331 void W_BallisticBullet_Touch (void)
332 {
333         //float density;
334
335         if(self.think == W_BallisticBullet_LeaveSolid_think) // skip this!
336                 return;
337
338         PROJECTILE_TOUCH;
339         W_BallisticBullet_Hit ();
340
341         if(self.dmg_radius < 0) // these NEVER penetrate solid
342         {
343                 remove(self);
344                 return;
345         }
346
347         // if we hit "weapclip", bail out
348         //
349         // rationale of this check:
350         //
351         // any shader that is solid, nodraw AND trans is meant to clip weapon
352         // shots and players, but has no other effect!
353         //
354         // if it is not trans, it is caulk and should not have this side effect
355         //
356         // matching shaders:
357         //   common/weapclip (intended)
358         //   common/noimpact (is supposed to eat projectiles, but is erased farther above)
359         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
360         if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
361         if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
362         {
363                 remove(self);
364                 return;
365         }
366
367         // go through solid!
368         if(!W_BallisticBullet_LeaveSolid(-1))
369         {
370                 remove(self);
371                 return;
372         }
373
374         self.projectiledeathtype |= HITTYPE_BOUNCE;
375 }
376
377 void endFireBallisticBullet()
378 {
379         endzcurveparticles();
380 }
381
382 entity fireBallisticBullet_trace_callback_ent;
383 float fireBallisticBullet_trace_callback_eff;
384 void fireBallisticBullet_trace_callback(vector start, vector hit, vector end)
385 {
386         if(vlen(trace_endpos - fireBallisticBullet_trace_callback_ent.origin) > 16)
387                 zcurveparticles_from_tracetoss(fireBallisticBullet_trace_callback_eff, fireBallisticBullet_trace_callback_ent.origin, trace_endpos, fireBallisticBullet_trace_callback_ent.velocity);
388         WarpZone_trace_forent = world;
389         self.owner = world;
390 }
391
392 void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, float lifetime, float damage, float force, float dtype, float tracereffects, float bulletconstant)
393 {
394         float lag, dt, savetime; //, density;
395         entity pl, oldself;
396
397         entity proj;
398         proj = spawn();
399         proj.classname = "bullet";
400         proj.owner = proj.realowner = self;
401         PROJECTILE_MAKETRIGGER(proj);
402         proj.movetype = MOVETYPE_FLY;
403         proj.think = SUB_Remove;
404         proj.nextthink = time + lifetime; // min(pLifetime, vlen(world.maxs - world.mins) / pSpeed);
405         W_SetupProjectileVelocityEx(proj, dir, v_up, pSpeed, 0, 0, spread, TRUE);
406         proj.angles = vectoangles(proj.velocity);
407         if(bulletconstant > 0)
408                 proj.dmg_radius = autocvar_g_ballistics_materialconstant / bulletconstant;
409         else if(bulletconstant == 0)
410                 proj.dmg_radius = 0;
411         else
412                 proj.dmg_radius = -1;
413         // so: bulletconstant = bullet mass / area of bullet circle
414         setorigin(proj, start);
415         proj.flags = FL_PROJECTILE;
416
417         proj.touch = W_BallisticBullet_Touch;
418         proj.dmg = damage;
419         proj.dmg_force = force;
420         proj.projectiledeathtype = dtype;
421
422         proj.oldvelocity = proj.velocity;
423
424         other = proj; MUTATOR_CALLHOOK(EditProjectile);
425
426         float eff;
427
428         if(tracereffects & EF_RED)
429                 eff = particleeffectnum("tr_rifle");
430         else if(tracereffects & EF_BLUE)
431                 eff = particleeffectnum("tr_rifle_weak");
432         else
433                 eff = particleeffectnum("tr_bullet");
434
435         // NOTE: this may severely throw off weapon balance
436         lag = ANTILAG_LATENCY(self);
437         if(lag < 0.001)
438                 lag = 0;
439         if (!IS_REAL_CLIENT(self))
440                 lag = 0;
441         if(autocvar_g_antilag == 0 || self.cvar_cl_noantilag)
442                 lag = 0; // only do hitscan, but no antilag
443
444         if(lag)
445                 FOR_EACH_PLAYER(pl)
446                         if(pl != self)
447                                 antilag_takeback(pl, time - lag);
448
449         oldself = self;
450         self = proj;
451
452         savetime = frametime;
453         frametime = 0.05;
454
455         for(;;)
456         {
457                 // DP tracetoss is stupid and always traces in 0.05s
458                 // ticks. This makes it trace in 0.05*0.125s ticks
459                 // instead.
460                 vector v0;
461                 v0 = self.velocity;
462                 self.velocity = self.velocity * 0.125;
463                 trace_fraction = 0;
464                 fireBallisticBullet_trace_callback_ent = self;
465                 fireBallisticBullet_trace_callback_eff = eff;
466                 WarpZone_TraceToss_ThroughZone(self, self.owner, world, fireBallisticBullet_trace_callback);
467                 self.velocity = v0;
468
469                 if(trace_fraction == 1)
470                         break;
471                         // won't hit anything anytime soon (DP's
472                         // tracetoss does 200 tics of, here,
473                         // 0.05*0.125s, that is, 1.25 seconds
474
475                 other = trace_ent;
476                 dt = WarpZone_tracetoss_time * 0.125; // this is only approximate!
477                 setorigin(self, trace_endpos);
478                 self.velocity = WarpZone_tracetoss_velocity * (1 / 0.125);
479
480                 if(!SUB_OwnerCheck())
481                 {
482                         if(SUB_NoImpactCheck())
483                                 break;
484
485                         // hit the player
486                         W_BallisticBullet_Hit();
487                 }
488
489                 if(proj.dmg_radius < 0) // these NEVER penetrate solid
490                         break;
491
492                 // if we hit "weapclip", bail out
493                 //
494                 // rationale of this check:
495                 //
496                 // any shader that is solid, nodraw AND trans is meant to clip weapon
497                 // shots and players, but has no other effect!
498                 //
499                 // if it is not trans, it is caulk and should not have this side effect
500                 //
501                 // matching shaders:
502                 //   common/weapclip (intended)
503                 //   common/noimpact (is supposed to eat projectiles, but is erased farther above)
504                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
505                 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
506                 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
507                         break;
508
509                 // go through solid!
510                 if(!W_BallisticBullet_LeaveSolid((other && (other.solid != SOLID_BSP)) ? eff : -1))
511                         break;
512
513                 W_BallisticBullet_LeaveSolid_think();
514
515                 self.projectiledeathtype |= HITTYPE_BOUNCE;
516         }
517         frametime = savetime;
518         self = oldself;
519
520         if(lag)
521                 FOR_EACH_PLAYER(pl)
522                         if(pl != self)
523                                 antilag_restore(pl);
524
525         remove(proj);
526
527         return;
528 }
529
530 void fireBallisticBullet_simple(vector start, vector dir, float spread, float pSpeed, float lifetime, float damage, float force, float dtype, float tracereffects, float bulletconstant)
531 {
532         vector  end;
533
534         dir = normalize(dir + randomvec() * spread);
535         end = start + dir * MAX_SHOT_DISTANCE;
536
537         for (;;)
538         {
539                 // TODO also show effect
540                 if(self.antilag_debug)
541                         WarpZone_traceline_antilag (self, start, end, FALSE, self, self.antilag_debug);
542                 else
543                         WarpZone_traceline_antilag (self, start, end, FALSE, self, ANTILAG_LATENCY(self));
544
545                 if (pointcontents (trace_endpos) != CONTENT_SKY)
546                 {
547                         trace_endpos = end;
548                         return;
549                 }
550
551                 // Avoid self-damage
552                 if (!trace_ent || (trace_ent == self))
553                 {
554                         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
555                                 return;
556
557                         W_BallisticBullet_Hit();  // FIXME
558                 }
559
560                 // if we hit "weapclip", bail out
561                 //
562                 // rationale of this check:
563                 //
564                 // any shader that is solid, nodraw AND trans is meant to clip weapon
565                 // shots and players, but has no other effect!
566                 //
567                 // if it is not trans, it is caulk and should not have this side effect
568                 //
569                 // matching shaders:
570                 //   common/weapclip (intended)
571                 //   common/noimpact (is supposed to eat projectiles, but is erased farther above)
572                 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
573                 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
574                 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
575                         return;
576
577                 // go through solid!
578                 if(!W_BallisticBullet_LeaveSolid((trace_ent && (trace_ent.solid != SOLID_BSP)) ? eff : -1))  // FIXME
579                         return;
580
581                 W_BallisticBullet_LeaveSolid_think();  // FIXME
582         }
583 }
584
585 void fireBullet (vector start, vector dir, float spread, float damage, float force, float dtype, float tracer)
586 {
587         vector  end;
588
589         dir = normalize(dir + randomvec() * spread);
590         end = start + dir * MAX_SHOT_DISTANCE;
591         if(self.antilag_debug)
592                 traceline_antilag (self, start, end, FALSE, self, self.antilag_debug);
593         else
594                 traceline_antilag (self, start, end, FALSE, self, ANTILAG_LATENCY(self));
595
596         end = trace_endpos;
597
598         if (pointcontents (trace_endpos) != CONTENT_SKY)
599         {
600                 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
601                         Damage_DamageInfo(trace_endpos, damage, 0, 0, dir * max(1, force), dtype, trace_ent.species, self);
602
603                 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * force);
604         }
605         trace_endpos = end;
606 }
607
608 float W_CheckProjectileDamage(entity inflictor, entity projowner, float deathtype, float exception)
609 {
610         float is_from_contents = (deathtype == DEATH_SLIME || deathtype == DEATH_LAVA);
611         float is_from_owner = (inflictor == projowner);
612         float is_from_exception = (exception != -1);
613
614         //dprint(strcat("W_CheckProjectileDamage: from_contents ", ftos(is_from_contents), " : from_owner ", ftos(is_from_owner), " : exception ", strcat(ftos(is_from_exception), " (", ftos(exception), "). \n")));
615
616         if(autocvar_g_projectiles_damage <= -2)
617         {
618                 return FALSE; // no damage to projectiles at all, not even with the exceptions
619         }
620         else if(autocvar_g_projectiles_damage == -1)
621         {
622                 if(is_from_exception)
623                         return (exception); // if exception is detected, allow it to override
624                 else
625                         return FALSE; // otherwise, no other damage is allowed
626         }
627         else if(autocvar_g_projectiles_damage == 0)
628         {
629                 if(is_from_exception)
630                         return (exception); // if exception is detected, allow it to override
631                 else if (!is_from_contents)
632                         return FALSE; // otherwise, only allow damage from contents
633         }
634         else if(autocvar_g_projectiles_damage == 1)
635         {
636                 if(is_from_exception)
637                         return (exception); // if exception is detected, allow it to override
638                 else if (!(is_from_contents || is_from_owner))
639                         return FALSE; // otherwise, only allow self damage and damage from contents
640         }
641         else if(autocvar_g_projectiles_damage == 2) // allow any damage, but override for exceptions
642         {
643                 if(is_from_exception)
644                         return (exception); // if exception is detected, allow it to override
645         }
646
647         return TRUE; // if none of these return, then allow damage anyway.
648 }
649
650 void W_PrepareExplosionByDamage(entity attacker, void() explode)
651 {
652         self.takedamage = DAMAGE_NO;
653         self.event_damage = func_null;
654
655         if(IS_CLIENT(attacker) && !autocvar_g_projectiles_keep_owner)
656         {
657                 self.owner = attacker;
658                 self.realowner = attacker;
659         }
660
661         // do not explode NOW but in the NEXT FRAME!
662         // because recursive calls to RadiusDamage are not allowed
663         self.nextthink = time;
664         self.think = explode;
665 }