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)
121 if (DEATH_ISWEAPON(self.projectiledeathtype, WEP_SHOTGUN))
122 pointparticles(particleeffectnum("shotgun_impact"), self.origin, normalize(self.velocity) * 1000, 1);
124 pointparticles(particleeffectnum("machinegun_impact"), self.origin, normalize(self.velocity) * 1000, 1);
126 if(other && other != self.enemy)
128 self.enemy = other; // don't hit the same player twice with the same bullet
130 f = pow(bound(0, vlen(self.velocity) / vlen(self.oldvelocity), 1), 2); // energy multiplier
134 damage_headshotbonus = self.dmg_edge;
135 railgun_start = self.origin - 2 * frametime * self.oldvelocity;
136 railgun_end = self.origin + 2 * frametime * self.oldvelocity;
137 Damage(other, self, self.owner, self.dmg * f, self.projectiledeathtype, self.origin, self.dmg_force * normalize(self.velocity) * f);
138 damage_headshotbonus = 0;
140 if(self.dmg_edge != 0)
143 announce(self.owner, "announcer/male/headshot.wav");
145 announce(self.owner, "announcer/male/yoda.wav");
148 //sound (self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
152 .void(void) W_BallisticBullet_LeaveSolid_think_save;
153 .float W_BallisticBullet_LeaveSolid_nextthink_save;
154 .vector W_BallisticBullet_LeaveSolid_origin;
155 .vector W_BallisticBullet_LeaveSolid_velocity;
157 void W_BallisticBullet_LeaveSolid_think()
159 setorigin(self, self.W_BallisticBullet_LeaveSolid_origin);
160 self.velocity = self.W_BallisticBullet_LeaveSolid_velocity;
162 self.think = self.W_BallisticBullet_LeaveSolid_think_save;
163 self.nextthink = max(time, self.W_BallisticBullet_LeaveSolid_nextthink_save) + 1;
164 self.W_BallisticBullet_LeaveSolid_think_save = SUB_Null;
166 self.flags &~= FL_ONGROUND;
167 self.effects &~= EF_NODRAW;
169 if (DEATH_ISWEAPON(self.projectiledeathtype, WEP_SHOTGUN))
170 pointparticles(particleeffectnum("shotgun_impact"), self.origin, normalize(self.velocity) * 1000, 1);
172 pointparticles(particleeffectnum("machinegun_impact"), self.origin, normalize(self.velocity) * 1000, 1);
175 // a fake logarithm function
180 if(x > 0.9 && x < 1.1)
182 return 2 * log(sqrt(x));
185 float W_BallisticBullet_LeaveSolid(entity e, vector vel, float constant)
187 // move the entity along its velocity until it's out of solid, then let it resume
189 float dt, dst, velfactor, v0, vs;
193 // E(s) = E0 - constant * s, constant = area of bullet circle * material constant / mass
196 E0_m = 0.5 * v0 * v0;
197 maxdist = E0_m / constant;
198 // maxdist = 0.5 * v0 * v0 / constant
199 // dprint("max dist = ", ftos(maxdist), "\n");
204 traceline_inverted (self.origin, self.origin + normalize(vel) * maxdist, MOVE_NORMAL, self);
206 if(trace_fraction == 1) // 1: we never got out of solid
209 self.W_BallisticBullet_LeaveSolid_origin = trace_endpos;
211 dst = vlen(trace_endpos - self.origin);
212 // E(s) = E0 - constant * s, constant = area of bullet circle * material constant / mass
213 Es_m = E0_m - constant * dst;
216 // roundoff errors got us
222 dt = dst / (0.5 * (v0 + vs));
223 // this is not correct, but the differential equations have no analytic
224 // solution - and these times are very small anyway
225 //print("dt = ", ftos(dt), "\n");
227 self.W_BallisticBullet_LeaveSolid_think_save = self.think;
228 self.W_BallisticBullet_LeaveSolid_nextthink_save = self.nextthink;
229 self.think = W_BallisticBullet_LeaveSolid_think;
230 self.nextthink = time + dt;
232 vel = vel * velfactor;
234 self.velocity = '0 0 0';
235 self.flags |= FL_ONGROUND; // prevent moving
236 self.effects |= EF_NODRAW;
237 self.W_BallisticBullet_LeaveSolid_velocity = vel;
242 void W_BallisticBullet_Touch (void)
244 if(self.think == W_BallisticBullet_LeaveSolid_think) // skip this!
248 W_BallisticBullet_Hit ();
251 if(!W_BallisticBullet_LeaveSolid(self, self.velocity, self.dmg_radius))
257 self.projectiledeathtype |= HITTYPE_BOUNCE;
260 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)
265 proj.solid = SOLID_BBOX;
266 if(gravityfactor > 0)
268 proj.movetype = MOVETYPE_TOSS;
269 proj.gravity = gravityfactor;
272 proj.movetype = MOVETYPE_FLY;
273 proj.think = SUB_Remove;
274 proj.nextthink = time + lifetime; // min(pLifetime, vlen(world.maxs - world.mins) / pSpeed);
275 proj.velocity = (dir + randomvec() * spread) * pSpeed;
276 W_SetupProjectileVelocity(proj);
277 proj.angles = vectoangles(proj.velocity);
278 proj.dmg_radius = cvar("g_ballistics_materialconstant") / bulletconstant;
279 // so: bulletconstant = bullet mass / area of bullet circle
280 setmodel(proj, "models/tracer.mdl");
281 setsize(proj, '0 0 0', '0 0 0');
282 setorigin(proj, start);
283 proj.effects = EF_LOWPRECISION | tracereffects;
284 proj.flags = FL_PROJECTILE;
286 proj.touch = W_BallisticBullet_Touch;
288 proj.dmg_edge = headshotbonus;
289 proj.dmg_force = force;
290 proj.projectiledeathtype = dtype;
292 proj.oldvelocity = proj.velocity;
295 void fireBullet (vector start, vector dir, float spread, float damage, float force, float dtype, float tracer)
300 if(cvar("g_ballistics_force"))
302 if (DEATH_ISWEAPON(dtype, WEP_SHOTGUN))
303 fireBallisticBullet(start, dir, spread, cvar("g_ballistics_force_shotgun_speed"), 5, damage, 0, force, dtype, 0, 1, cvar("g_ballistics_force_shotgun_bulletconstant"));
305 fireBallisticBullet(start, dir, spread, cvar("g_ballistics_force_uzi_speed"), 5, damage, 0, force, dtype, 0, 1, cvar("g_ballistics_force_shotgun_bulletconstant"));
309 dir = dir + randomvec() * spread;
310 end = start + dir * MAX_SHOT_DISTANCE;
311 if(self.antilag_debug)
312 traceline_antilag (self, start, end, FALSE, self, self.antilag_debug);
314 traceline_antilag (self, start, end, FALSE, self, ANTILAG_LATENCY(self));
320 e.movetype = MOVETYPE_FLY;
322 e.think = SUB_Remove;
323 e.nextthink = time + vlen(trace_endpos - start) / 6000;
324 e.velocity = dir * 6000;
325 e.angles = vectoangles(e.velocity);
326 setmodel (e, "models/tracer.mdl"); // precision set below
327 setsize (e, '0 0 0', '0 0 0');
328 setorigin (e, start);
329 e.effects = EF_LOWPRECISION;
330 e.flags = FL_PROJECTILE;
333 if ((trace_fraction != 1.0) && (pointcontents (trace_endpos) != CONTENT_SKY))
335 if (trace_ent.solid == SOLID_BSP && !(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
337 if (DEATH_ISWEAPON(dtype, WEP_SHOTGUN))
338 pointparticles(particleeffectnum("shotgun_impact"), trace_endpos, trace_plane_normal * 1000, 1);
340 pointparticles(particleeffectnum("machinegun_impact"), trace_endpos, trace_plane_normal * 1000, 1);
342 Damage (trace_ent, self, self, damage, dtype, trace_endpos, dir * force);
346 void W_PrepareExplosionByDamage(entity attacker, void() explode)
348 self.takedamage = DAMAGE_NO;
349 self.event_damage = SUB_Null;
350 self.owner = attacker;
352 // do not explode NOW but in the NEXT FRAME!
353 // because recursive calls to RadiusDamage are not allowed
354 self.nextthink = time;
355 self.think = explode;