2 void W_GiveWeapon (entity e, float wep, string name)
9 e.weapons = e.weapons | W_WeaponBit(wep);
14 if (other.classname == "player")
16 sprint (other, "You got the ^2");
25 void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, float deathtype)
27 local vector hitloc, force, endpoint, dir;
28 local entity ent, endent;
29 local float endq3surfaceflags;
30 //local entity explosion;
32 railgun_start = start;
35 dir = normalize(end - start);
38 // go a little bit into the wall because we need to hit this wall later
41 // trace multiple times until we hit a wall, each obstacle will be made
42 // non-solid so we can hit the next, while doing this we spawn effects and
43 // note down which entities were hit so we can damage them later
46 if(self.antilag_debug)
47 traceline_antilag (self, start, end, FALSE, self, self.antilag_debug);
49 traceline_antilag (self, start, end, FALSE, self, ANTILAG_LATENCY(self));
51 // if it is world we can't hurt it so stop now
52 if (trace_ent == world || trace_fraction == 1)
55 // make the entity non-solid so we can hit the next one
56 trace_ent.railgunhit = TRUE;
57 trace_ent.railgunhitloc = end;
58 trace_ent.railgunhitsolidbackup = trace_ent.solid;
60 // stop if this is a wall
61 if (trace_ent.solid == SOLID_BSP)
64 // make the entity non-solid
65 trace_ent.solid = SOLID_NOT;
68 endpoint = trace_endpos;
70 endq3surfaceflags = trace_dphitq3surfaceflags;
72 // find all the entities the railgun hit and restore their solid state
73 ent = findfloat(world, railgunhit, TRUE);
76 // restore their solid type
77 ent.solid = ent.railgunhitsolidbackup;
78 ent = findfloat(ent, railgunhit, TRUE);
81 // spawn a temporary explosion entity for RadiusDamage calls
82 //explosion = spawn();
84 // find all the entities the railgun hit and hurt them
85 ent = findfloat(world, railgunhit, TRUE);
88 // get the details we need to call the damage function
89 hitloc = ent.railgunhitloc;
90 ent.railgunhitloc = '0 0 0';
91 ent.railgunhitsolidbackup = SOLID_NOT;
92 ent.railgunhit = FALSE;
95 if (ent.takedamage || ent.classname == "case")
96 Damage (ent, self, self, bdamage, deathtype, hitloc, force);
98 // create a small explosion to throw gibs around (if applicable)
99 //setorigin (explosion, hitloc);
100 //RadiusDamage (explosion, self, 10, 0, 50, world, 300, deathtype);
102 // advance to the next entity
103 ent = findfloat(ent, railgunhit, TRUE);
106 // we're done with the explosion entity, remove it
109 trace_endpos = endpoint;
111 trace_dphitq3surfaceflags = endq3surfaceflags;
117 void W_BallisticBullet_Hit (void)
122 org2 = self.origin - 6 * normalize(self.velocity);
123 if (DEATH_ISWEAPON(self.projectiledeathtype, WEP_SHOTGUN))
124 pointparticles(particleeffectnum("shotgun_impact"), org2, normalize(self.velocity) * 1000, 1);
126 pointparticles(particleeffectnum("machinegun_impact"), org2, normalize(self.velocity) * 1000, 1);
128 if(other && other != self.enemy)
130 self.enemy = other; // don't hit the same player twice with the same bullet
132 f = pow(bound(0, vlen(self.velocity) / vlen(self.oldvelocity), 1), 2); // energy multiplier
136 damage_headshotbonus = self.dmg_edge;
137 railgun_start = self.origin - 2 * frametime * self.oldvelocity;
138 railgun_end = self.origin + 2 * frametime * self.oldvelocity;
139 Damage(other, self, self.owner, self.dmg * f, self.projectiledeathtype, self.origin, self.dmg_force * normalize(self.velocity) * f);
140 damage_headshotbonus = 0;
142 if(self.dmg_edge != 0)
145 announce(self.owner, "announcer/male/headshot.wav");
147 announce(self.owner, "announcer/male/yoda.wav");
150 //sound (self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
154 .void(void) W_BallisticBullet_LeaveSolid_think_save;
155 .float W_BallisticBullet_LeaveSolid_nextthink_save;
156 .vector W_BallisticBullet_LeaveSolid_origin;
157 .vector W_BallisticBullet_LeaveSolid_velocity;
159 void W_BallisticBullet_LeaveSolid_think()
163 setorigin(self, self.W_BallisticBullet_LeaveSolid_origin);
164 self.velocity = self.W_BallisticBullet_LeaveSolid_velocity;
166 self.think = self.W_BallisticBullet_LeaveSolid_think_save;
167 self.nextthink = max(time, self.W_BallisticBullet_LeaveSolid_nextthink_save) + 1;
168 self.W_BallisticBullet_LeaveSolid_think_save = SUB_Null;
170 self.flags &~= FL_ONGROUND;
171 self.effects &~= EF_NODRAW;
173 org2 = self.origin + 6 * normalize(self.velocity);
174 if (DEATH_ISWEAPON(self.projectiledeathtype, WEP_SHOTGUN))
175 pointparticles(particleeffectnum("shotgun_impact"), org2, normalize(self.velocity) * 1000, 1);
177 pointparticles(particleeffectnum("machinegun_impact"), org2, normalize(self.velocity) * 1000, 1);
180 // a fake logarithm function
185 if(x > 0.9 && x < 1.1)
187 return 2 * log(sqrt(x));
190 float W_BallisticBullet_LeaveSolid(entity e, vector vel, float constant)
192 // move the entity along its velocity until it's out of solid, then let it resume
194 vector tracevel, org, skiporg, endorg, t;
195 float dt, dst, velfactor, v0, vs;
199 // E(s) = E0 - constant * s, constant = area of bullet circle * material constant / mass
202 E0_m = 0.5 * v0 * v0;
203 maxdist = E0_m / constant;
204 // maxdist = 0.5 * v0 * v0 / constant
205 // dprint("max dist = ", ftos(maxdist), "\n");
210 tracevel = normalize(vel);
213 skiporg = org + tracevel;
214 endorg = org + tracevel * maxdist;
218 traceline(skiporg, endorg, MOVE_NORMAL, self);
223 // good: skiporg is actually in solid
224 traceline(t, skiporg, MOVE_NORMAL, self);
229 // we're stuck inside solid :(
230 // force advance by 1 unit, and retry
231 // CAN we go by 1 unit?
232 if(vlen(skiporg + tracevel - org) < maxdist)
233 skiporg = skiporg + tracevel;
239 // we managed to leave solid
240 // so trace_endpos is good
241 self.W_BallisticBullet_LeaveSolid_origin = t;
247 // bad: skiporg is outside solid. Then imagine it's alright.
248 self.W_BallisticBullet_LeaveSolid_origin = skiporg;
253 dst = vlen(self.W_BallisticBullet_LeaveSolid_origin - org);
254 // E(s) = E0 - constant * s, constant = area of bullet circle * material constant / mass
255 Es_m = E0_m - constant * dst;
258 // roundoff errors got us
264 dt = dst / (0.5 * (v0 + vs));
265 // this is not correct, but the differential equations have no analytic
266 // solution - and these times are very small anyway
267 //print("dt = ", ftos(dt), "\n");
269 self.W_BallisticBullet_LeaveSolid_think_save = self.think;
270 self.W_BallisticBullet_LeaveSolid_nextthink_save = self.nextthink;
271 self.think = W_BallisticBullet_LeaveSolid_think;
272 self.nextthink = time + dt;
274 vel = vel * velfactor;
276 self.velocity = '0 0 0';
277 self.flags |= FL_ONGROUND; // prevent moving
278 self.effects |= EF_NODRAW;
279 self.W_BallisticBullet_LeaveSolid_velocity = vel;
284 void W_BallisticBullet_Touch (void)
286 if(self.think == W_BallisticBullet_LeaveSolid_think) // skip this!
290 W_BallisticBullet_Hit ();
293 if(!W_BallisticBullet_LeaveSolid(self, self.velocity, self.dmg_radius))
299 self.projectiledeathtype |= HITTYPE_BOUNCE;
302 void fireBallisticBullet(vector start, vector dir, float spread, float pSpeed, float lifetime, float damage, float headshotbonus, float force, float dtype, float tracereffects, float gravityfactor, float bulletconstant)
307 proj.solid = SOLID_BBOX;
308 if(gravityfactor > 0)
310 proj.movetype = MOVETYPE_TOSS;
311 proj.gravity = gravityfactor;
314 proj.movetype = MOVETYPE_FLY;
315 proj.think = SUB_Remove;
316 proj.nextthink = time + lifetime; // min(pLifetime, vlen(world.maxs - world.mins) / pSpeed);
317 proj.velocity = (dir + randomvec() * spread) * pSpeed;
318 W_SetupProjectileVelocity(proj);
319 proj.angles = vectoangles(proj.velocity);
320 proj.dmg_radius = cvar("g_ballistics_materialconstant") / bulletconstant;
321 // so: bulletconstant = bullet mass / area of bullet circle
322 setmodel(proj, "models/tracer.mdl");
323 setsize(proj, '0 0 0', '0 0 0');
324 setorigin(proj, start);
325 proj.effects = EF_LOWPRECISION | tracereffects;
326 proj.flags = FL_PROJECTILE;
328 proj.touch = W_BallisticBullet_Touch;
330 proj.dmg_edge = headshotbonus;
331 proj.dmg_force = force;
332 proj.projectiledeathtype = dtype;
334 proj.oldvelocity = proj.velocity;
337 void fireBullet (vector start, vector dir, float spread, float damage, float force, float dtype, float tracer)
342 if(cvar("g_ballistics_force"))
344 if (DEATH_ISWEAPON(dtype, WEP_SHOTGUN))
345 fireBallisticBullet(start, dir, spread, cvar("g_ballistics_force_shotgun_speed"), 5, damage, 0, force, dtype, 0, 1, cvar("g_ballistics_force_shotgun_bulletconstant"));
347 fireBallisticBullet(start, dir, spread, cvar("g_ballistics_force_uzi_speed"), 5, damage, 0, force, dtype, 0, 1, cvar("g_ballistics_force_shotgun_bulletconstant"));
351 dir = dir + randomvec() * spread;
352 end = start + dir * MAX_SHOT_DISTANCE;
353 if(self.antilag_debug)
354 traceline_antilag (self, start, end, FALSE, self, self.antilag_debug);
356 traceline_antilag (self, start, end, FALSE, self, ANTILAG_LATENCY(self));
362 e.movetype = MOVETYPE_FLY;
364 e.think = SUB_Remove;
365 e.nextthink = time + vlen(trace_endpos - start) / 6000;
366 e.velocity = dir * 6000;
367 e.angles = vectoangles(e.velocity);
368 setmodel (e, "models/tracer.mdl"); // precision set below
369 setsize (e, '0 0 0', '0 0 0');
370 setorigin (e, start);
371 e.effects = EF_LOWPRECISION;
372 e.flags = FL_PROJECTILE;
375 if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))
377 if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
379 if (DEATH_ISWEAPON(dtype, WEP_SHOTGUN))
380 pointparticles(particleeffectnum("shotgun_impact"), trace_endpos, trace_plane_normal * 1000, 1);
382 pointparticles(particleeffectnum("machinegun_impact"), trace_endpos, trace_plane_normal * 1000, 1);
384 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * force);
388 void W_PrepareExplosionByDamage(entity attacker, void() explode)
390 self.takedamage = DAMAGE_NO;
391 self.event_damage = SUB_Null;
392 self.owner = attacker;
394 // do not explode NOW but in the NEXT FRAME!
395 // because recursive calls to RadiusDamage are not allowed
396 self.nextthink = time;
397 self.think = explode;