2 void W_GiveWeapon (entity e, float wep)
9 e.weapons |= WepSet_FromWeapon(wep);
15 { Send_Notification(NOTIF_ONE, other, MSG_MULTI, ITEM_WEAPON_GOT, wep); }
20 .float railgundistance;
22 void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, float mindist, float maxdist, float halflifedist, float forcehalflifedist, float deathtype)
24 vector hitloc, force, endpoint, dir;
26 float endq3surfaceflags;
33 entity pseudoprojectile;
36 pseudoprojectile = world;
38 dir = normalize(end - start);
39 length = vlen(end - start);
42 // go a little bit into the wall because we need to hit this wall later
47 // trace multiple times until we hit a wall, each obstacle will be made
48 // non-solid so we can hit the next, while doing this we spawn effects and
49 // note down which entities were hit so we can damage them later
53 if(self.antilag_debug)
54 WarpZone_traceline_antilag (self, start, end, FALSE, o, self.antilag_debug);
56 WarpZone_traceline_antilag (self, start, end, FALSE, o, ANTILAG_LATENCY(self));
57 if(o && WarpZone_trace_firstzone)
63 if(trace_ent.solid == SOLID_BSP || trace_ent.solid == SOLID_SLIDEBOX)
64 Damage_DamageInfo(trace_endpos, bdamage, 0, 0, force, deathtype, trace_ent.species, self);
66 // if it is world we can't hurt it so stop now
67 if (trace_ent == world || trace_fraction == 1)
70 // make the entity non-solid so we can hit the next one
71 trace_ent.railgunhit = TRUE;
72 trace_ent.railgunhitloc = end;
73 trace_ent.railgunhitsolidbackup = trace_ent.solid;
74 trace_ent.railgundistance = vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - start);
75 trace_ent.railgunforce = WarpZone_TransformVelocity(WarpZone_trace_transform, force);
77 // stop if this is a wall
78 if (trace_ent.solid == SOLID_BSP)
81 // make the entity non-solid
82 trace_ent.solid = SOLID_NOT;
85 endpoint = trace_endpos;
87 endq3surfaceflags = trace_dphitq3surfaceflags;
89 // find all the entities the railgun hit and restore their solid state
90 ent = findfloat(world, railgunhit, TRUE);
93 // restore their solid type
94 ent.solid = ent.railgunhitsolidbackup;
95 ent = findfloat(ent, railgunhit, TRUE);
98 // spawn a temporary explosion entity for RadiusDamage calls
99 //explosion = spawn();
101 // Find all non-hit players the beam passed close by
102 if(deathtype == WEP_MINSTANEX || deathtype == WEP_NEX)
104 FOR_EACH_REALCLIENT(msg_entity)
105 if(msg_entity != self)
106 if(!msg_entity.railgunhit)
107 if(!(IS_SPEC(msg_entity) && msg_entity.enemy == self)) // we use realclient, so spectators can hear the whoosh too
109 // nearest point on the beam
110 beampos = start + dir * bound(0, (msg_entity.origin - start) * dir, length);
112 f = bound(0, 1 - vlen(beampos - msg_entity.origin) / 512, 1);
116 snd = strcat("weapons/nexwhoosh", ftos(floor(random() * 3) + 1), ".wav");
118 if(!pseudoprojectile)
119 pseudoprojectile = spawn(); // we need this so the sound uses the "entchannel4" volume
120 soundtoat(MSG_ONE, pseudoprojectile, beampos, CH_SHOTS, snd, VOL_BASE * f, ATTEN_NONE);
124 remove(pseudoprojectile);
127 // find all the entities the railgun hit and hurt them
128 ent = findfloat(world, railgunhit, TRUE);
131 // get the details we need to call the damage function
132 hitloc = ent.railgunhitloc;
134 f = ExponentialFalloff(mindist, maxdist, halflifedist, ent.railgundistance);
135 ffs = ExponentialFalloff(mindist, maxdist, forcehalflifedist, ent.railgundistance);
137 if(accuracy_isgooddamage(self.realowner, ent))
138 totaldmg += bdamage * f;
142 Damage (ent, self, self, bdamage * f, deathtype, hitloc, ent.railgunforce * ffs);
144 // create a small explosion to throw gibs around (if applicable)
145 //setorigin (explosion, hitloc);
146 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);
148 ent.railgunhitloc = '0 0 0';
149 ent.railgunhitsolidbackup = SOLID_NOT;
150 ent.railgunhit = FALSE;
151 ent.railgundistance = 0;
153 // advance to the next entity
154 ent = findfloat(ent, railgunhit, TRUE);
157 // calculate hits and fired shots for hitscan
158 accuracy_add(self, self.weapon, 0, min(bdamage, totaldmg));
160 trace_endpos = endpoint;
162 trace_dphitq3surfaceflags = endq3surfaceflags;
165 float fireBullet_trace_callback_eff;
166 entity fireBullet_last_hit;
167 void fireBullet_trace_callback(vector start, vector hit, vector end)
169 if(vlen(hit - start) > 16)
170 trailparticles(world, fireBullet_trace_callback_eff, start, hit);
171 WarpZone_trace_forent = world;
172 fireBullet_last_hit = world;
175 void fireBullet(vector start, vector dir, float spread, float max_solid_penetration, float damage, float force, float dtype, float tracereffects)
177 // TODO antilag takeback
180 dir = normalize(dir + randomvec() * spread);
181 end = start + dir * MAX_SHOT_DISTANCE;
184 fireBullet_last_hit = world;
185 float solid_penetration_left = 1;
186 float total_damage = 0;
188 if(tracereffects & EF_RED)
189 fireBullet_trace_callback_eff = particleeffectnum("tr_rifle");
190 else if(tracereffects & EF_BLUE)
191 fireBullet_trace_callback_eff = particleeffectnum("tr_rifle_weak");
193 fireBullet_trace_callback_eff = particleeffectnum("tr_bullet");
195 float lag = ANTILAG_LATENCY(self);
198 if (!IS_REAL_CLIENT(self))
200 if(autocvar_g_antilag == 0 || self.cvar_cl_noantilag)
201 lag = 0; // only do hitscan, but no antilag
205 antilag_takeback(pl, time - lag);
207 WarpZone_trace_forent = self;
211 // TODO also show effect while tracing
212 WarpZone_TraceBox_ThroughZone(start, '0 0 0', '0 0 0', end, FALSE, WarpZone_trace_forent, world, fireBullet_trace_callback);
213 dir = WarpZone_TransformVelocity(WarpZone_trace_transform, dir);
214 end = WarpZone_TransformOrigin(WarpZone_trace_transform, end);
215 start = trace_endpos;
216 entity hit = trace_ent;
218 // When hitting sky, stop.
219 if (pointcontents(start) == CONTENT_SKY)
222 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
225 // if we hit "weapclip", bail out
227 // rationale of this check:
229 // any shader that is solid, nodraw AND trans is meant to clip weapon
230 // shots and players, but has no other effect!
232 // if it is not trans, it is caulk and should not have this side effect
235 // common/weapclip (intended)
236 // common/noimpact (is supposed to eat projectiles, but is erased anyway)
237 float is_weapclip = 0;
238 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NODRAW)
239 if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NONSOLID))
240 if (!(trace_dphitcontents & DPCONTENTS_OPAQUE))
243 if(!hit || hit.solid == SOLID_BSP || hit.solid == SOLID_SLIDEBOX)
244 Damage_DamageInfo(start, damage * solid_penetration_left, 0, 0, max(1, force) * dir * solid_penetration_left, dtype, hit.species, self);
246 if (hit && hit != WarpZone_trace_forent && hit != fireBullet_last_hit) // Avoid self-damage (except after going through a warp); avoid hitting the same entity twice (engine bug).
248 fireBullet_last_hit = hit;
250 float g = accuracy_isgooddamage(self, hit);
251 Damage(hit, self, self, damage * solid_penetration_left, dtype, start, force * dir * solid_penetration_left);
252 // calculate hits for ballistic weapons
255 // do not exceed 100%
256 float added_damage = min(damage - total_damage, damage * solid_penetration_left);
257 total_damage += damage * solid_penetration_left;
258 accuracy_add(self, self.weapon, 0, added_damage);
266 // outside the world? forget it
267 if(start_x > world.maxs_x || start_y > world.maxs_y || start_z > world.maxs_z || start_x < world.mins_x || start_y < world.mins_y || start_z < world.mins_z)
271 if(max_solid_penetration < 0)
273 else if(hit.ballistics_density < -1)
274 break; // -2: no solid penetration, ever
275 else if(hit.ballistics_density < 0)
276 maxdist = vlen(hit.maxs - hit.mins) + 1; // -1: infinite travel distance
277 else if(hit.ballistics_density == 0)
278 maxdist = max_solid_penetration * solid_penetration_left;
280 maxdist = max_solid_penetration * solid_penetration_left * hit.ballistics_density;
282 if(maxdist <= autocvar_g_ballistics_mindistance)
285 // move the entity along its velocity until it's out of solid, then let it resume
286 // The previously hit entity is ignored here!
287 traceline_inverted (start, start + dir * maxdist, MOVE_NORMAL, WarpZone_trace_forent, TRUE, hit);
288 if(trace_fraction == 1) // 1: we never got out of solid
291 float dist_taken = max(autocvar_g_ballistics_mindistance, vlen(trace_endpos - start));
292 solid_penetration_left *= (dist_taken / maxdist);
294 // Only show effect when going through a player (invisible otherwise)
295 if (hit && (hit.solid != SOLID_BSP))
296 if(vlen(trace_endpos - start) > 4)
297 trailparticles(self, fireBullet_trace_callback_eff, start, trace_endpos);
299 start = trace_endpos;
301 if(hit.solid == SOLID_BSP)
302 Damage_DamageInfo(start, 0, 0, 0, max(1, force) * normalize(dir) * -solid_penetration_left, dtype, 0, self);
311 float W_CheckProjectileDamage(entity inflictor, entity projowner, float deathtype, float exception)
313 float is_from_contents = (deathtype == DEATH_SLIME || deathtype == DEATH_LAVA);
314 float is_from_owner = (inflictor == projowner);
315 float is_from_exception = (exception != -1);
317 //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")));
319 if(autocvar_g_projectiles_damage <= -2)
321 return FALSE; // no damage to projectiles at all, not even with the exceptions
323 else if(autocvar_g_projectiles_damage == -1)
325 if(is_from_exception)
326 return (exception); // if exception is detected, allow it to override
328 return FALSE; // otherwise, no other damage is allowed
330 else if(autocvar_g_projectiles_damage == 0)
332 if(is_from_exception)
333 return (exception); // if exception is detected, allow it to override
334 else if (!is_from_contents)
335 return FALSE; // otherwise, only allow damage from contents
337 else if(autocvar_g_projectiles_damage == 1)
339 if(is_from_exception)
340 return (exception); // if exception is detected, allow it to override
341 else if (!(is_from_contents || is_from_owner))
342 return FALSE; // otherwise, only allow self damage and damage from contents
344 else if(autocvar_g_projectiles_damage == 2) // allow any damage, but override for exceptions
346 if(is_from_exception)
347 return (exception); // if exception is detected, allow it to override
350 return TRUE; // if none of these return, then allow damage anyway.
353 void W_PrepareExplosionByDamage(entity attacker, void() explode)
355 self.takedamage = DAMAGE_NO;
356 self.event_damage = func_null;
358 if(IS_CLIENT(attacker) && !autocvar_g_projectiles_keep_owner)
360 self.owner = attacker;
361 self.realowner = attacker;
364 // do not explode NOW but in the NEXT FRAME!
365 // because recursive calls to RadiusDamage are not allowed
366 self.nextthink = time;
367 self.think = explode;