/// <summary> /// R_LavaSplash /// </summary> public static void LavaSplash(ref Vector3 org) { Vector3 dir; for (int i = -16; i < 16; i++) { for (int j = -16; j < 16; j++) { for (int k = 0; k < 1; k++) { particle_t p = AllocParticle(); if (p == null) { return; } p.die = (float)(Client.cl.time + 2 + (Sys.Random() & 31) * 0.02); p.color = 224 + (Sys.Random() & 7); p.type = ptype_t.pt_slowgrav; dir.X = j * 8 + (Sys.Random() & 7); dir.Y = i * 8 + (Sys.Random() & 7); dir.Z = 256; p.org = org + dir; p.org.Z += Sys.Random() & 63; Mathlib.Normalize(ref dir); float vel = 50 + (Sys.Random() & 63); p.vel = dir * vel; } } } }
/// <summary> /// SV_AirAccelerate /// </summary> static void AirAccelerate(Vector3 wishveloc) { float wishspd = Mathlib.Normalize(ref wishveloc); if (wishspd > 30) { wishspd = 30; } float currentspeed = Vector3.Dot(Common.ToVector(ref _Player.v.velocity), wishveloc); float addspeed = wishspd - currentspeed; if (addspeed <= 0) { return; } float accelspeed = (float)(_Accelerate.Value * _WishSpeed * Host.FrameTime); if (accelspeed > addspeed) { accelspeed = addspeed; } wishveloc *= accelspeed; _Player.v.velocity.x += wishveloc.X; _Player.v.velocity.y += wishveloc.Y; _Player.v.velocity.z += wishveloc.Z; }
/// <summary> /// R_TeleportSplash /// </summary> public static void TeleportSplash(ref Vector3 org) { for (int i = -16; i < 16; i += 4) { for (int j = -16; j < 16; j += 4) { for (int k = -24; k < 32; k += 4) { particle_t p = AllocParticle(); if (p == null) { return; } p.die = (float)(Client.cl.time + 0.2 + (Sys.Random() & 7) * 0.02); p.color = 7 + (Sys.Random() & 7); p.type = ptype_t.pt_slowgrav; Vector3 dir = new Vector3(j * 8, i * 8, k * 8); p.org = org + new Vector3(i + (Sys.Random() & 3), j + (Sys.Random() & 3), k + (Sys.Random() & 3)); Mathlib.Normalize(ref dir); float vel = 50 + (Sys.Random() & 63); p.vel = dir * vel; } } } }
/* * ================= * PF_normalize * * vector normalize(vector) * ================= */ static unsafe void PF_normalize() { float * value1 = GetVector(OFS.OFS_PARM0); Vector3 tmp; Copy(value1, out tmp); Mathlib.Normalize(ref tmp); ReturnVector(ref tmp); }
static void DropPunchAngle() { Vector3 v = Common.ToVector(ref _Player.v.punchangle); double len = Mathlib.Normalize(ref v) - 10 * Host.FrameTime; if (len < 0) { len = 0; } v *= (float)len; Mathlib.Copy(ref v, out _Player.v.punchangle); }
static bool IsCollinear(float[] prev, float[] cur, float[] next) { Vector3 v1 = new Vector3(cur[0] - prev[0], cur[1] - prev[1], cur[2] - prev[2]); Mathlib.Normalize(ref v1); Vector3 v2 = new Vector3(next[0] - prev[0], next[1] - prev[1], next[2] - prev[2]); Mathlib.Normalize(ref v2); v1 -= v2; return((Math.Abs(v1.X) <= COLINEAR_EPSILON) && (Math.Abs(v1.Y) <= COLINEAR_EPSILON) && (Math.Abs(v1.Z) <= COLINEAR_EPSILON)); }
/// <summary> /// SV_AirMove /// </summary> static void AirMove() { Vector3 pangles = Common.ToVector(ref _Player.v.angles); Mathlib.AngleVectors(ref pangles, out _Forward, out _Right, out _Up); float fmove = _Cmd.forwardmove; float smove = _Cmd.sidemove; // hack to not let you back into teleporter if (sv.time < _Player.v.teleport_time && fmove < 0) { fmove = 0; } Vector3 wishvel = _Forward * fmove + _Right * smove; if ((int)_Player.v.movetype != Movetypes.MOVETYPE_WALK) { wishvel.Z = _Cmd.upmove; } else { wishvel.Z = 0; } _WishDir = wishvel; _WishSpeed = Mathlib.Normalize(ref _WishDir); if (_WishSpeed > _MaxSpeed.Value) { wishvel *= _MaxSpeed.Value / _WishSpeed; _WishSpeed = _MaxSpeed.Value; } if (_Player.v.movetype == Movetypes.MOVETYPE_NOCLIP) { // noclip Mathlib.Copy(ref wishvel, out _Player.v.velocity); } else if (_OnGround) { UserFriction(); Accelerate(); } else { // not on ground, so little effect on velocity AirAccelerate(wishvel); } }
// SND_Spatialize static void Spatialize(channel_t ch) { // anything coming from the view entity will allways be full volume if (ch.entnum == Client.cl.viewentity) { ch.leftvol = ch.master_vol; ch.rightvol = ch.master_vol; return; } // calculate stereo seperation and distance attenuation sfx_t snd = ch.sfx; Vector3 source_vec = ch.origin - _ListenerOrigin; float dist = Mathlib.Normalize(ref source_vec) * ch.dist_mult; float dot = Vector3.Dot(_ListenerRight, source_vec); float rscale, lscale; if (_shm.channels == 1) { rscale = 1.0f; lscale = 1.0f; } else { rscale = 1.0f + dot; lscale = 1.0f - dot; } // add in distance effect float scale = (1.0f - dist) * rscale; ch.rightvol = (int)(ch.master_vol * scale); if (ch.rightvol < 0) { ch.rightvol = 0; } scale = (1.0f - dist) * lscale; ch.leftvol = (int)(ch.master_vol * scale); if (ch.leftvol < 0) { ch.leftvol = 0; } }
// V_ParseDamage public static void ParseDamage() { int armor = Net.Reader.ReadByte(); int blood = Net.Reader.ReadByte(); Vector3 from = Net.Reader.ReadCoords(); float count = blood * 0.5f + armor * 0.5f; if (count < 10) { count = 10; } client_state_t cl = Client.cl; cl.faceanimtime = (float)cl.time + 0.2f; // put sbar face into pain frame cl.cshifts[ColorShift.CSHIFT_DAMAGE].percent += (int)(3 * count); if (cl.cshifts[ColorShift.CSHIFT_DAMAGE].percent < 0) { cl.cshifts[ColorShift.CSHIFT_DAMAGE].percent = 0; } if (cl.cshifts[ColorShift.CSHIFT_DAMAGE].percent > 150) { cl.cshifts[ColorShift.CSHIFT_DAMAGE].percent = 150; } if (armor > blood) { cl.cshifts[ColorShift.CSHIFT_DAMAGE].destcolor[0] = 200; cl.cshifts[ColorShift.CSHIFT_DAMAGE].destcolor[1] = 100; cl.cshifts[ColorShift.CSHIFT_DAMAGE].destcolor[2] = 100; } else if (armor != 0) { cl.cshifts[ColorShift.CSHIFT_DAMAGE].destcolor[0] = 220; cl.cshifts[ColorShift.CSHIFT_DAMAGE].destcolor[1] = 50; cl.cshifts[ColorShift.CSHIFT_DAMAGE].destcolor[2] = 50; } else { cl.cshifts[ColorShift.CSHIFT_DAMAGE].destcolor[0] = 255; cl.cshifts[ColorShift.CSHIFT_DAMAGE].destcolor[1] = 0; cl.cshifts[ColorShift.CSHIFT_DAMAGE].destcolor[2] = 0; } // // calculate view angle kicks // entity_t ent = Client.Entities[cl.viewentity]; from -= ent.origin; // VectorSubtract (from, ent->origin, from); Mathlib.Normalize(ref from); Vector3 forward, right, up; Mathlib.AngleVectors(ref ent.angles, out forward, out right, out up); float side = Vector3.Dot(from, right); _DmgRoll = count * side * _KickRoll.Value; side = Vector3.Dot(from, forward); _DmgPitch = count * side * _KickPitch.Value; _DmgTime = _KickTime.Value; }
/* * ============= * PF_aim * * Pick a vector for the player to shoot along * vector aim(entity, missilespeed) * ============= */ static void PF_aim() { edict_t ent = GetEdict(OFS.OFS_PARM0); float speed = GetFloat(OFS.OFS_PARM1); Vector3 start = Common.ToVector(ref ent.v.origin); start.Z += 20; // try sending a trace straight Vector3 dir; Mathlib.Copy(ref Progs.GlobalStruct.v_forward, out dir); Vector3 end = start + dir * 2048; trace_t tr = Server.Move(ref start, ref Common.ZeroVector, ref Common.ZeroVector, ref end, 0, ent); if (tr.ent != null && tr.ent.v.takedamage == Damages.DAMAGE_AIM && (Host.TeamPlay == 0 || ent.v.team <= 0 || ent.v.team != tr.ent.v.team)) { ReturnVector(ref Progs.GlobalStruct.v_forward); return; } // try all possible entities Vector3 bestdir = dir; float bestdist = Server.Aim; edict_t bestent = null; for (int i = 1; i < Server.sv.num_edicts; i++) { edict_t check = Server.sv.edicts[i]; if (check.v.takedamage != Damages.DAMAGE_AIM) { continue; } if (check == ent) { continue; } if (Host.TeamPlay != 0 && ent.v.team > 0 && ent.v.team == check.v.team) { continue; // don't aim at teammate } v3f tmp; Mathlib.VectorAdd(ref check.v.mins, ref check.v.maxs, out tmp); Mathlib.VectorMA(ref check.v.origin, 0.5f, ref tmp, out tmp); Mathlib.Copy(ref tmp, out end); dir = end - start; Mathlib.Normalize(ref dir); float dist = Vector3.Dot(dir, Common.ToVector(ref Progs.GlobalStruct.v_forward)); if (dist < bestdist) { continue; // to far to turn } tr = Server.Move(ref start, ref Common.ZeroVector, ref Common.ZeroVector, ref end, 0, ent); if (tr.ent == check) { // can shoot at this one bestdist = dist; bestent = check; } } if (bestent != null) { v3f dir2, end2; Mathlib.VectorSubtract(ref bestent.v.origin, ref ent.v.origin, out dir2); float dist = Mathlib.DotProduct(ref dir2, ref Progs.GlobalStruct.v_forward); Mathlib.VectorScale(ref Progs.GlobalStruct.v_forward, dist, out end2); end2.z = dir2.z; Mathlib.Normalize(ref end2); ReturnVector(ref end2); } else { ReturnVector(ref bestdir); } }
// CL_UpdateTEnts static void UpdateTempEntities() { _NumTempEntities = 0; // update lightning for (int i = 0; i < MAX_BEAMS; i++) { beam_t b = _Beams[i]; if (b.model == null || b.endtime < cl.time) { continue; } // if coming from the player, update the start position if (b.entity == cl.viewentity) { b.start = _Entities[cl.viewentity].origin; } // calculate pitch and yaw Vector3 dist = b.end - b.start; float yaw, pitch, forward; if (dist.Y == 0 && dist.X == 0) { yaw = 0; if (dist.Z > 0) { pitch = 90; } else { pitch = 270; } } else { yaw = (int)(Math.Atan2(dist.Y, dist.X) * 180 / Math.PI); if (yaw < 0) { yaw += 360; } forward = (float)Math.Sqrt(dist.X * dist.X + dist.Y * dist.Y); pitch = (int)(Math.Atan2(dist.Z, forward) * 180 / Math.PI); if (pitch < 0) { pitch += 360; } } // add new entities for the lightning Vector3 org = b.start; float d = Mathlib.Normalize(ref dist); while (d > 0) { entity_t ent = NewTempEntity(); if (ent == null) { return; } ent.origin = org; ent.model = b.model; ent.angles.X = pitch; ent.angles.Y = yaw; ent.angles.Z = Sys.Random() % 360; org += dist * 30; // Uze: is this code bug (i is outer loop variable!!!) or what?????????????? //for (i=0 ; i<3 ; i++) // org[i] += dist[i]*30; d -= 30; } } }
/// <summary> /// R_RocketTrail /// </summary> public static void RocketTrail(ref Vector3 start, ref Vector3 end, int type) { Vector3 vec = end - start; float len = Mathlib.Normalize(ref vec); int dec; if (type < 128) { dec = 3; } else { dec = 1; type -= 128; } while (len > 0) { len -= dec; particle_t p = AllocParticle(); if (p == null) { return; } p.vel = Vector3.Zero; p.die = (float)Client.cl.time + 2; switch (type) { case 0: // rocket trail p.ramp = (Sys.Random() & 3); p.color = _Ramp3[(int)p.ramp]; p.type = ptype_t.pt_fire; p.org = new Vector3(start.X + ((Sys.Random() % 6) - 3), start.Y + ((Sys.Random() % 6) - 3), start.Z + ((Sys.Random() % 6) - 3)); break; case 1: // smoke smoke p.ramp = (Sys.Random() & 3) + 2; p.color = _Ramp3[(int)p.ramp]; p.type = ptype_t.pt_fire; p.org = new Vector3(start.X + ((Sys.Random() % 6) - 3), start.Y + ((Sys.Random() % 6) - 3), start.Z + ((Sys.Random() % 6) - 3)); break; case 2: // blood p.type = ptype_t.pt_grav; p.color = 67 + (Sys.Random() & 3); p.org = new Vector3(start.X + ((Sys.Random() % 6) - 3), start.Y + ((Sys.Random() % 6) - 3), start.Z + ((Sys.Random() % 6) - 3)); break; case 3: case 5: // tracer p.die = (float)Client.cl.time + 0.5f; p.type = ptype_t.pt_static; if (type == 3) { p.color = 52 + ((_TracerCount & 4) << 1); } else { p.color = 230 + ((_TracerCount & 4) << 1); } _TracerCount++; p.org = start; if ((_TracerCount & 1) != 0) { p.vel.X = 30 * vec.Y; // Uze: why??? p.vel.Y = 30 * -vec.X; } else { p.vel.X = 30 * -vec.Y; p.vel.Y = 30 * vec.X; } break; case 4: // slight blood p.type = ptype_t.pt_grav; p.color = 67 + (Sys.Random() & 3); p.org = new Vector3(start.X + ((Sys.Random() % 6) - 3), start.Y + ((Sys.Random() % 6) - 3), start.Z + ((Sys.Random() % 6) - 3)); len -= 3; break; case 6: // voor trail p.color = 9 * 16 + 8 + (Sys.Random() & 3); p.type = ptype_t.pt_static; p.die = (float)Client.cl.time + 0.3f; p.org = new Vector3(start.X + ((Sys.Random() % 15) - 8), start.Y + ((Sys.Random() % 15) - 8), start.Z + ((Sys.Random() % 15) - 8)); break; } start += vec; } }
/// <summary> /// SV_WaterMove /// </summary> static void WaterMove() { // // user intentions // Vector3 pangle = Common.ToVector(ref _Player.v.v_angle); Mathlib.AngleVectors(ref pangle, out _Forward, out _Right, out _Up); Vector3 wishvel = _Forward * _Cmd.forwardmove + _Right * _Cmd.sidemove; if (_Cmd.forwardmove == 0 && _Cmd.sidemove == 0 && _Cmd.upmove == 0) { wishvel.Z -= 60; // drift towards bottom } else { wishvel.Z += _Cmd.upmove; } float wishspeed = wishvel.Length; if (wishspeed > _MaxSpeed.Value) { wishvel *= _MaxSpeed.Value / wishspeed; wishspeed = _MaxSpeed.Value; } wishspeed *= 0.7f; // // water friction // float newspeed, speed = Mathlib.Length(ref _Player.v.velocity); if (speed != 0) { newspeed = (float)(speed - Host.FrameTime * speed * _Friction.Value); if (newspeed < 0) { newspeed = 0; } Mathlib.VectorScale(ref _Player.v.velocity, newspeed / speed, out _Player.v.velocity); } else { newspeed = 0; } // // water acceleration // if (wishspeed == 0) { return; } float addspeed = wishspeed - newspeed; if (addspeed <= 0) { return; } Mathlib.Normalize(ref wishvel); float accelspeed = (float)(_Accelerate.Value * wishspeed * Host.FrameTime); if (accelspeed > addspeed) { accelspeed = addspeed; } wishvel *= accelspeed; _Player.v.velocity.x += wishvel.X; _Player.v.velocity.y += wishvel.Y; _Player.v.velocity.z += wishvel.Z; }