1 #pragma once 2 #include "dbl.h" 3 #include "cardynamics.h" 4 #include "model_joe03.h" 5 6 #include "cardefs.h" 7 #include "suspensionbump.h" 8 #include "crashdetection.h" 9 10 class BEZIER; 11 namespace protocol { struct CarStatePackage; } 12 class Sound; 13 14 15 class CAR 16 { 17 public: 18 class GAME* pGame; 19 class App* pApp; 20 class CarModel* pCarM; 21 22 CAR(); 23 ~CAR(); 24 25 int numWheels; 26 void SetNumWheels(int n); 27 28 bool Load(class App* pApp1, 29 CONFIGFILE & carconf, const std::string & carname, 30 const MATHVECTOR<float,3> & init_pos, const QUATERNION<float> & init_rot, 31 COLLISION_WORLD & world, bool abs, bool tcs, 32 bool isRemote, int idCar, bool debugmode); 33 34 // will align car relative to track surface, returns false if the car isn't near ground 35 void SetPosition(const MATHVECTOR<float,3> & pos, const QUATERNION<float> & rot); 36 void SetPosition(const MATHVECTOR<Dbl,3> & pos, const QUATERNION<Dbl> & rot); 37 void SetPosition1(const MATHVECTOR<float,3> & pos); 38 39 void Update(double dt); 40 41 GetWheelPosition(const WHEEL_POSITION wpos)42 const MATHVECTOR<float,3> GetWheelPosition(const WHEEL_POSITION wpos) const 43 { 44 MATHVECTOR<float,3> v; 45 v = dynamics.GetWheelPosition(wpos); 46 return v; 47 } 48 GetTireRadius(const WHEEL_POSITION wpos)49 float GetTireRadius(const WHEEL_POSITION wpos) const 50 { 51 return dynamics.GetWheel(wpos).GetRadius(); 52 } 53 GetWheelContact(WHEEL_POSITION wheel_index)54 COLLISION_CONTACT & GetWheelContact(WHEEL_POSITION wheel_index) 55 { 56 return dynamics.GetWheelContact(wheel_index); 57 } 58 59 bool bRemoteCar; 60 void HandleInputs(const std::vector <float> & inputs, float dt); 61 62 GetGear()63 int GetGear() const 64 { return dynamics.GetTransmission().GetGear(); } 65 SetGear(int gear)66 void SetGear(int gear) 67 { dynamics.ShiftGear(gear); } 68 GetClutch()69 float GetClutch() const 70 { return dynamics.GetClutch().GetClutch(); } 71 SetAutoClutch(bool value)72 void SetAutoClutch(bool value) 73 { dynamics.SetAutoClutch(value); } 74 75 SetAutoShift(bool value)76 void SetAutoShift(bool value){ dynamics.SetAutoShift(value); } SetAutoRear(bool value)77 void SetAutoRear(bool value){ dynamics.SetAutoRear(value); } 78 SetABS(const bool active)79 void SetABS(const bool active){ dynamics.SetABS(active); } GetABSEnabled()80 bool GetABSEnabled() const { return dynamics.GetABSEnabled(); } GetABSActive()81 bool GetABSActive() const { return dynamics.GetABSActive(); } 82 SetTCS(const bool active)83 void SetTCS(const bool active){ dynamics.SetTCS(active); } GetTCSEnabled()84 bool GetTCSEnabled() const { return dynamics.GetTCSEnabled(); } GetTCSActive()85 bool GetTCSActive() const { return dynamics.GetTCSActive(); } 86 87 /// return the speedometer reading (based on the driveshaft speed) in m/s GetSpeedometer()88 float GetSpeedometer() const 89 { 90 return dynamics.vtype != V_Car ? 91 dynamics.GetVelocity().Magnitude() : dynamics.GetSpeedMPS(); 92 } 93 GetCarType()94 std::string GetCarType() const { return cartype; } GetCurPatch(unsigned int wheel)95 const BEZIER * GetCurPatch(unsigned int wheel) const 96 { 97 //assert (wheel < 4); 98 return dynamics.GetWheelContact(WHEEL_POSITION(wheel)).GetPatch(); 99 } 100 GetLastSteer()101 float GetLastSteer() const { return last_steer; } GetSpeed()102 float GetSpeed() const { return dynamics.GetSpeed(); } 103 GetSpeedDir()104 float GetSpeedDir() { return dynamics.GetSpeedDir(); } 105 GetTotalAero()106 MATHVECTOR<float,3> GetTotalAero() const 107 { return dynamics.GetTotalAero(); } 108 109 float GetFeedback(); 110 111 // returns a float from 0.0 to 1.0 with the amount of tire squealing going on 112 float GetTireSquealAmount(WHEEL_POSITION i, float* slide=0, float* s1=0, float* s2=0) const; 113 DebugPrint(std::ostream & out,bool p1,bool p2,bool p3,bool p4)114 void DebugPrint(std::ostream & out, bool p1, bool p2, bool p3, bool p4) 115 { 116 dynamics.DebugPrint(out, p1, p2, p3, p4); 117 } 118 GetEngineRPM()119 int GetEngineRPM() const { return dynamics.GetTachoRPM(); } GetEngineStallRPM()120 int GetEngineStallRPM() const{ return dynamics.GetEngine().GetStallRPM(); } 121 GetPosition()122 MATHVECTOR<float,3> GetPosition() const 123 { 124 MATHVECTOR<float,3> pos; 125 pos = dynamics.GetPosition(); 126 return pos; 127 } GetOrientation()128 QUATERNION<float> GetOrientation() const 129 { 130 QUATERNION<float> q; 131 q = dynamics.GetOrientation(); 132 return q; 133 } 134 GetAerodynamicDownforceCoefficient()135 float GetAerodynamicDownforceCoefficient() const 136 { return dynamics.GetAerodynamicDownforceCoefficient(); } 137 GetAeordynamicDragCoefficient()138 float GetAeordynamicDragCoefficient() const 139 { return dynamics.GetAeordynamicDragCoefficient(); } 140 GetMass()141 float GetMass() const { return dynamics.GetMass(); } 142 GetVelocity()143 MATHVECTOR<float,3> GetVelocity() const 144 { 145 MATHVECTOR<float,3> vel; 146 vel = dynamics.GetVelocity(); 147 return vel; 148 } GetAngularVelocity()149 MATHVECTOR<float,3> GetAngularVelocity() const 150 { 151 MATHVECTOR<float,3> vel; 152 vel = dynamics.GetAngularVelocity(); 153 return vel; 154 } 155 156 // Networking 157 protocol::CarStatePackage GetCarStatePackage() const; 158 void UpdateCarState(const protocol::CarStatePackage& state); 159 160 /// new 161 int id; // index of car (same as for carModels) 162 bool bResetPos; 163 void ResetPos(bool fromStart=true); 164 void SavePosAtCheck(); 165 void SetPosRewind(const MATHVECTOR<float,3>& pos, const QUATERNION<float>& rot, const MATHVECTOR<float,3>& vel, const MATHVECTOR<float,3>& angvel); 166 167 public: 168 CARDYNAMICS dynamics; 169 170 std::vector<SUSPENSIONBUMPDETECTION> suspbump; 171 CRASHDETECTION crashdetection2; 172 173 174 /// Sounds --------------- 175 struct CARsounds 176 { 177 Sound* engine; 178 std::vector<Sound*> asphalt, grass, gravel, bump; // tires 179 180 std::vector<Sound*> crash; 181 std::vector<float> crashtime, bumptime, bumpvol; 182 183 Sound* wind, *boost, *scrap,*screech; // cont. 184 Sound* mud, *mud_cont,*water_cont; // fluids 185 std::vector<Sound*> water; 186 bool fluidHitOld; float whMudSpin; ///new vars, for snd 187 188 CARsounds(); 189 void SetNumWheels(int n); 190 void Destroy(); 191 } sounds; 192 193 // internal variables that might change during driving (so, they need to be serialized) 194 float last_steer; 195 float trackPercentCopy; // copy from CarModel for network 196 197 std::string cartype; 198 class SETTINGS* pSet; // for sound vol 199 200 std::vector<const BEZIER*> curpatch; //the last bezier patch that each wheel hit 201 202 float mz_nominalmax; // the nominal maximum Mz force, used to scale force feedback 203 204 void UpdateSounds(float dt); 205 bool LoadSounds(const std::string & carpath); 206 207 208 //------------------------------------------------------------------------------- 209 void GraphsNewVals(double dt); 210 211 212 // for new game reset and goto last checkp. 213 MATHVECTOR<Dbl,3> posAtStart, posLastCheck; 214 QUATERNION<Dbl> rotAtStart, rotLastCheck; 215 float dmgLastCheck, sphYawAtStart; 216 217 // car inputs (new) 218 int iCamNext; 219 bool bLastChk,bLastChkOld, bRewind,bRewindOld; 220 float timeRew; 221 }; 222