public void Update(Vehicle vehicle) { if (Gravity < 1) { vehicle.Chassis.Actor.AddForce(new Vector3(0, PhysX.Instance.Gravity * Gravity * 20f, 0), ForceMode.SmoothImpulse); } }
public static ISound Play(int id, Vehicle vehicle, bool is3d) { if (vehicle == null || (vehicle.Driver is CpuDriver && ((CpuDriver)vehicle.Driver).InPlayersView) || vehicle.Driver is PlayerDriver) { ISound instance = _playerInstances.Find(a => a.Id == id); if (instance == null) { instance = CreateInstance(id, is3d); } if (instance != null) { if (is3d) instance.Position = vehicle.Position; instance.Owner = vehicle; instance.Play(false); //GameConsole.WriteEvent("PlaySound " + id.ToString()); } else { } return instance; } else return null; }
public void Reset(Vehicle vehicle) { vehicle.Chassis.Actor.ClearBodyFlag(StillDesign.PhysX.BodyFlag.DisableGravity); vehicle.Audio.SetSound(0); //vehicle.Chassis.Motor.MaxPower = vehicle.Config.EnginePower; //vehicle.Chassis.Body.Mass = vehicle.Config.Mass; //vehicle.Chassis.Body.LinearDamping = 0.0f; //vehicle.Chassis.Body.AngularDamping = 0.05f; }
public Opponent(string carFile, Vector3 position, float direction, CpuDriver driver) { if (driver == null) driver = new CpuDriver(); Driver = driver; Vehicle = new Vehicle(GameVars.BasePath + @"cars\" + carFile, Driver); if (driver is CopDriver) { Vehicle.Chassis.Actor.GlobalPosition = position; Vehicle.Chassis.Actor.GlobalOrientation *= Matrix.CreateRotationY(MathHelper.ToRadians(90)); } else { Vehicle.PlaceOnGrid(position, direction); } SetupVehicle(); }
public void Enter(Vehicle vehicle) { if (Gravity < 1) vehicle.Chassis.Actor.RaiseBodyFlag(StillDesign.PhysX.BodyFlag.DisableGravity); else vehicle.Chassis.Actor.ClearBodyFlag(StillDesign.PhysX.BodyFlag.DisableGravity); vehicle.Audio.SetSound(EngineSoundIndex); //vehicle.Chassis.Motor.MaxPower = vehicle.Config.EnginePower / (Viscosity / 35f); //vehicle.Chassis.Body.LinearDamping = Viscosity / 200f; //vehicle.Chassis.Body.AngularDamping = Viscosity / 80f; //vehicle.Chassis.Body.SetCenterOfMassOffsetLocalPosition(new Vector3(0, 0.25f, 0)); //vehicle.Chassis.Body.Mass = vehicle.Config.Mass * Gravity; if (EntrySoundId > 0) { SoundCache.Play(EntrySoundId, vehicle, true); } }
public VehicleAudio(Vehicle vehicle) { _vehicle = vehicle; if (vehicle.Driver is CpuDriver) return; _engineSounds = new List<ISound>(); foreach (int id in vehicle.Config.EngineSoundIds) { ISound sound = SoundCache.CreateInstance(id, true); if (sound != null) { sound.MinimumDistance = 20; sound.MaximumDistance = 100; _engineSounds.Add(sound); } } if (_engineSounds.Count > 0) _sound = _engineSounds[0]; }
public VehicleChassis(Vehicle vehicle) { Vehicle = vehicle; Wheels = new List<VehicleWheel>(); VehicleFile carFile = vehicle.Config; ActorDescription actorDesc = new ActorDescription(); actorDesc.BodyDescription = new BodyDescription(); actorDesc.BodyDescription.Mass = carFile.Mass; var boxDesc = new BoxShapeDescription(); boxDesc.Size = carFile.BoundingBox.GetSize(); boxDesc.LocalPosition = carFile.BoundingBox.GetCenter(); boxDesc.Name = PhysXConsts.VehicleBody; boxDesc.Flags |= ShapeFlag.PointContactForce; actorDesc.Shapes.Add(boxDesc); foreach (Vector3 extraPoint in carFile.ExtraBoundingBoxPoints) { var extraDesc = new SphereShapeDescription(0.2f); extraDesc.LocalPosition = extraPoint; extraDesc.Mass = 0; actorDesc.Shapes.Add(extraDesc); } using (UtilitiesLibrary lib = new UtilitiesLibrary()) { Vector3 size = carFile.Size; Vector3 inertiaTensor = lib.ComputeBoxInteriaTensor(Vector3.Zero, carFile.Mass, size); //actorDesc.BodyDescription.MassSpaceInertia = inertiaTensor; } TireFunctionDescription lngTFD = new TireFunctionDescription(); lngTFD.ExtremumSlip = 0.1f; lngTFD.ExtremumValue = 4f; lngTFD.AsymptoteSlip = 2.0f; lngTFD.AsymptoteValue = 3.2f; _rearLateralTireFn = new TireFunctionDescription(); _rearLateralTireFn.ExtremumSlip = 0.2f; _rearLateralTireFn.ExtremumValue = 2.1f; _rearLateralTireFn.AsymptoteSlip = 0.0013f * carFile.Mass; _rearLateralTireFn.AsymptoteValue = 0.02f; _frontLateralTireFn = _rearLateralTireFn; _frontLateralTireFn.ExtremumValue = 1.9f; MaterialDescription md = new MaterialDescription(); md.Flags = MaterialFlag.DisableFriction; Material m = PhysX.Instance.Scene.CreateMaterial(md); int wheelIndex = 0; foreach (CWheelActor wheel in carFile.WheelActors) { WheelShapeDescription wheelDesc = new WheelShapeDescription(); wheelDesc.InverseWheelMass = 0.08f; wheelDesc.LongitudalTireForceFunction = lngTFD; wheelDesc.Flags = WheelShapeFlag.ClampedFriction; wheelDesc.Material = m; wheelDesc.Radius = wheel.IsDriven ? carFile.DrivenWheelRadius : carFile.NonDrivenWheelRadius; wheelDesc.SuspensionTravel = (wheel.IsFront ? carFile.SuspensionGiveFront : carFile.SuspensionGiveRear) * 18; float heightModifier = (wheelDesc.SuspensionTravel + wheelDesc.Radius) / wheelDesc.SuspensionTravel; SpringDescription spring = new SpringDescription(); if (carFile.Mass > 3000) spring.SpringCoefficient = 10.5f * heightModifier * carFile.Mass; else spring.SpringCoefficient = 6.5f * heightModifier * Math.Min(1000, carFile.Mass); spring.DamperCoefficient = carFile.SuspensionDamping * 6f; wheelDesc.Suspension = spring; wheelDesc.LocalPosition = wheel.Position; wheelDesc.Name = (wheelIndex).ToString(); wheelIndex++; wheelDesc.LateralTireForceFunction = wheel.IsFront ? _frontLateralTireFn : _rearLateralTireFn; actorDesc.Shapes.Add(wheelDesc); } _physXActor = PhysX.Instance.Scene.CreateActor(actorDesc); _heightOffset = _physXActor.Shapes[0].LocalPosition.Y * -2; if (_heightOffset < 0) _heightOffset = 0; foreach (Shape shape in _physXActor.Shapes) { shape.LocalPosition += new Vector3(0, _heightOffset, 0); if (shape is WheelShape) { wheelIndex = int.Parse(shape.Name); Wheels.Add(new VehicleWheel(this, carFile.WheelActors[wheelIndex], (WheelShape)shape, carFile.WheelActors[wheelIndex].IsLeft ? 0.17f : -0.17f) { Index = wheelIndex }); } } _physXActor.Group = PhysXConsts.VehicleId; _physXActor.UserData = vehicle; _physXActor.WakeUp(60.0f); //_physXActor.RaiseBodyFlag(BodyFlag.DisableGravity); //set center of mass Vector3 massPos = carFile.CenterOfMass; massPos.Y = carFile.WheelActors[0].Position.Y - carFile.NonDrivenWheelRadius + _heightOffset + 0.35f; _massPos = massPos; _physXActor.SetCenterOfMassOffsetLocalPosition(massPos); //a real power curve doesnt work too well :) List<float> power = new List<float>(new float[] { 0.5f, 0.5f, 0.5f, 1f, 1f, 1.0f, 1.0f, 0 }); List<float> ratios = new List<float>(new float[] { 3.227f, 2.360f, 1.685f, 1.312f, 1.000f, 0.793f }); BaseGearbox gearbox = BaseGearbox.Create(false, ratios, 0.4f); Motor = new Motor(power, carFile.EnginePower, 6f, carFile.TopSpeed, gearbox); Motor.Gearbox.CurrentGear = 0; }
private static void PlayGroup(int startId, int endId, ref ISound instance, Vehicle vehicle) { if (instance != null && instance.IsPlaying && instance.Owner != vehicle) { if (vehicle.Driver is PlayerDriver) //priority instance.Reset(); else if (((Vehicle)instance.Owner).Driver is PlayerDriver) { return; //dont steal player's sound } } if (instance == null || !instance.IsPlaying) { int id = Engine.Random.Next(startId, endId+1); instance = Play(id, vehicle, true); } }
public static void PlaySkid(Vehicle vehicle, float factor) { if (factor > 0.35f) PlayGroup(SoundIds.SkidStart, SoundIds.SkidEnd, ref _currentSkid, vehicle); PlayGroup(SoundIds.ScrubStart, SoundIds.ScrubEnd, ref _currentScrub, vehicle); }
public static void PlayScrape(Vehicle vehicle) { PlayGroup(SoundIds.ScrapeStart, SoundIds.ScrapeEnd, ref _currentCrash, vehicle); }
public static void PlayCrash(Vehicle vehicle, float force) { PlayGroup(SoundIds.CrashStart, SoundIds.CrashEnd, ref _currentCrash, vehicle); }
public void OnVehicleEnterSpecVol(SpecialVolume volume, Vehicle vehicle) { int currentVolumeId = vehicle.CurrentSpecialVolume.Count == 0 ? -1 : vehicle.CurrentSpecialVolume.Peek().Id; GameConsole.WriteEvent("Enter specvol - " + vehicle.CurrentSpecialVolume.Count); if (currentVolumeId != volume.Id) { volume.Enter(vehicle); } vehicle.CurrentSpecialVolume.Push(volume); }
public void Exit(Vehicle vehicle) { if (ExitSoundId > 0) SoundCache.Play(ExitSoundId, vehicle, true); }
public Race(string filename, string playerVehicleFile) { Race.Current = this; Logger.Log("Starting race " + Path.GetFileName(filename)); ConfigFile = new RaceFile(filename); foreach (string matFileName in ConfigFile.MaterialFiles) { MatFile matFile = new MatFile(matFileName); ResourceCache.Add(matFile); } foreach (string pixFileName in ConfigFile.PixFiles) { PixFile pixFile = new PixFile(pixFileName); ResourceCache.Add(pixFile); } if (GameVars.Emulation == EmulationMode.Demo) ResourceCache.Add(new CMaterial("drkcurb.mat", 226)); //demo doesn't have this file, I guess the color is hard-coded else ResourceCache.Add(new MatFile("drkcurb.mat")); ResourceCache.ResolveMaterials(); if (filename.Contains("TESTMAP")) //nasty hack... GameVars.Scale.Y *= 0.5f; DatFile modelFile = new DatFile(ConfigFile.ModelFile); ActFile actFile = new ActFile(ConfigFile.ActorFile); _actors = actFile.Hierarchy; _actors.AttachModels(modelFile.Models); _actors.ResolveTransforms(false, ConfigFile.Grooves); if (filename.Contains("TESTMAP")) //nasty hack... GameVars.Scale.Y *= 2f; // link the actors and grooves foreach (BaseGroove g in ConfigFile.Grooves) g.SetActor(_actors.GetByName(g.ActorName)); // link the funks and materials foreach (BaseFunk f in ConfigFile.Funks) { f.Resolve(); } if (ConfigFile.SkyboxTexture != "none") { PixFile horizonPix = new PixFile(ConfigFile.SkyboxTexture); _skybox = SkyboxGenerator.Generate(horizonPix.PixMaps[0].Texture, ConfigFile.SkyboxRepetitionsX - 3f, ConfigFile.DepthCueMode); _skybox.HeightOffset = -220 + ConfigFile.SkyboxPositionY * 1.5f; } Physics.TrackProcessor.GenerateTrackActor(ConfigFile, _actors, out _nonCars); Logger.Log("NonCars: " + _nonCars.Count); GridPlacer.Reset(); List<int> opponentIds = new List<int>(); List<int> pickedNbrs = new List<int>(); for (int i = 0; i < 5; i++) { int index = 0; while (true) { index = Engine.Random.Next(1, OpponentsFile.Instance.Opponents.Count); if (!pickedNbrs.Contains(index)) { pickedNbrs.Add(index); break; } } try { Opponents.Add(new Opponent(OpponentsFile.Instance.Opponents[index].FileName, ConfigFile.GridPosition, ConfigFile.GridDirection)); NbrOpponents++; } catch(Exception ex) { Logger.Log("Error while loading opponent " + OpponentsFile.Instance.Opponents[index].FileName + ", " + ex.Message); } } foreach (CopStartPoint point in ConfigFile.CopStartPoints) { Opponents.Add(new Opponent(point.IsSpecialForces ? "bigapc.txt" : "apc.txt", point.Position, 0, new CopDriver())); } foreach (Opponent o in Opponents) Drivers.Add(o.Driver); OpponentController.Nodes = ConfigFile.OpponentPathNodes; PlayerVehicle = new Vehicle(GameVars.BasePath + @"cars\" + playerVehicleFile, new PlayerDriver()); PlayerVehicle.PlaceOnGrid(ConfigFile.GridPosition, ConfigFile.GridDirection); Drivers.Add(PlayerVehicle.Driver); Peds = new PedestrianController(ConfigFile.Peds); _map = new RaceMap(this); RaceTime = new RaceTimeController(); PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.TrackId, PhysXConsts.VehicleId, ContactPairFlag.Forces | ContactPairFlag.OnStartTouch | ContactPairFlag.OnTouch); PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.VehicleId, PhysXConsts.NonCarId, ContactPairFlag.Forces | ContactPairFlag.OnStartTouch | ContactPairFlag.OnTouch); PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.TrackId, PhysXConsts.NonCarId, ContactPairFlag.OnTouch); PhysX.Instance.Scene.SetActorGroupPairFlags(PhysXConsts.VehicleId, PhysXConsts.VehicleId, ContactPairFlag.Forces | ContactPairFlag.OnTouch | ContactPairFlag.OnStartTouch | ContactPairFlag.OnEndTouch); }
internal void OnCarKilled(Vehicle vehicle) { foreach (Opponent opponent in Opponents) { if (opponent.Vehicle == vehicle) { opponent.Kill(); if (!(opponent.Driver is CopDriver)) NbrDeadOpponents++; break; } } int time = GeneralSettingsFile.Instance.TimePerCarKill[GameVars.SkillLevel]; RaceTime.TimeRemaining += time; MessageRenderer.Instance.PostTimerMessage(time); if (NbrDeadOpponents == Opponents.Count) { GameMode.Current = new RaceCompletedMode(CompletionType.Opponents); } else { MessageRenderer.Instance.PostMainMessage("destroy.pix", 3, 0.7f, 0.003f, 1.4f); } }
public void OnVehicleExitSpecVol(SpecialVolume exitedVolume, Vehicle vehicle) { SpecialVolume vol = vehicle.CurrentSpecialVolume.Pop(); SpecialVolume nextVol = vehicle.CurrentSpecialVolume.Count == 0 ? null : vehicle.CurrentSpecialVolume.Peek(); GameConsole.WriteEvent("Exit specvol - " + vehicle.CurrentSpecialVolume.Count); if (nextVol == null) { //reset exitedVolume.Reset(vehicle); exitedVolume.Exit(vehicle); } else if (nextVol.Id != vol.Id) { nextVol.Enter(vehicle); exitedVolume.Exit(vehicle); } }
public void OnHit(Vehicle vehicle) { IsHit = true; _groundHeight = Position.Y; float speed = Math.Min(140, vehicle.Chassis.Speed); if (speed > 90) { _hitSpinSpeed = speed * Engine.Random.Next(0.07f, 0.13f); if (Engine.Random.Next() % 2 == 0) _hitSpinSpeed *= -1; _hitUpSpeed = speed * 0.10f; _hitSpeed = speed * Behaviour.Acceleration * 10000; if (!IsPowerup) PedestrianGibsController.AddGibs(Position + new Vector3(0, 1.2f, 0), vehicle.Chassis.Actor.LinearVelocity, speed); } else { if (!IsPowerup && speed > 30) PedestrianGibsController.AddGibs(Position + new Vector3(0, 0.5f, 0), vehicle.Chassis.Actor.LinearVelocity, speed); _hitSpeed = speed * Behaviour.Acceleration * 19000; } _direction = Vector3.Normalize(vehicle.Chassis.Actor.LinearVelocity); if (float.IsNaN(_direction.X)) { _direction = Vector3.Zero; } SetAction(Behaviour.FatalImpact, true); if (Behaviour.ExplodingSounds.Length > 0) SoundCache.Play(Behaviour.ExplodingSounds[0], Race.Current.PlayerVehicle, true); }
public void OnPedestrianHit(Pedestrian ped, Vehicle vehicle) { vehicle.LastRunOverPedTime = Engine.TotalSeconds; if (ped.IsHit) { SoundCache.Play(SoundIds.PedSquelch, vehicle, true); return; } NbrDeadPeds++; ped.OnHit(vehicle); if (vehicle == PlayerVehicle) { int time = GeneralSettingsFile.Instance.TimePerPedKill[GameVars.SkillLevel]; RaceTime.TimeRemaining += time; MessageRenderer.Instance.PostTimerMessage(time); } if (NbrDeadPeds == Peds.Count) { GameMode.Current = new RaceCompletedMode(CompletionType.Peds); RaceTime.IsOver = true; } }