vehicle.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/vehicle.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 3/25/02 2:18p $*
  29. * *
  30. * $Revision:: 120 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef VEHICLE_H
  36. #define VEHICLE_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef SMARTGAMEOBJ_H
  41. #include "smartgameobj.h"
  42. #endif
  43. #ifndef VECTOR_H
  44. #include "vector.h"
  45. #endif
  46. #ifndef TRANSITION_H
  47. #include "transition.h"
  48. #endif
  49. #ifndef WWSTRING_H
  50. #include "wwstring.h"
  51. #endif
  52. class Sound3DClass;
  53. class VehiclePhysClass;
  54. class SoldierGameObj;
  55. class PersistantSurfaceEmitterClass;
  56. class PersistantSurfaceSoundClass;
  57. /*
  58. **
  59. */
  60. typedef enum {
  61. VEHICLE_TYPE_CAR,
  62. VEHICLE_TYPE_TANK,
  63. VEHICLE_TYPE_BIKE,
  64. VEHICLE_TYPE_FLYING,
  65. VEHICLE_TYPE_TURRET,
  66. } VehicleType;
  67. enum
  68. {
  69. ENGINE_SOUND_STATE_STARTING = 0,
  70. ENGINE_SOUND_STATE_RUNNING,
  71. ENGINE_SOUND_STATE_STOPPING,
  72. ENGINE_SOUND_STATE_OFF,
  73. MAX_ENGINE_SOUND_STATES
  74. };
  75. /*
  76. ** VehicleGameObjDef - Defintion class for a VehicleGameObj
  77. */
  78. class VehicleGameObjDef : public SmartGameObjDef
  79. {
  80. public:
  81. VehicleGameObjDef( void );
  82. virtual ~VehicleGameObjDef( void );
  83. virtual uint32 Get_Class_ID( void ) const;
  84. virtual PersistClass * Create( void ) const ;
  85. virtual bool Save( ChunkSaveClass &csave );
  86. virtual bool Load( ChunkLoadClass &cload );
  87. virtual const PersistFactoryClass & Get_Factory( void ) const;
  88. DECLARE_EDITABLE( VehicleGameObjDef, SmartGameObjDef );
  89. TRANSITION_DATA_LIST * Get_Transition_List( void ) { return &Transitions; }
  90. const TRANSITION_DATA_LIST & Get_Transition_List( void ) const { return Transitions; }
  91. void Free_Transition_List( void );
  92. int Get_Damage_Report(int team) const;
  93. int Get_Destroy_Report(int team) const;
  94. protected:
  95. VehicleType Type;
  96. StringClass TypeName;
  97. StringClass Fire0Anim;
  98. StringClass Fire1Anim;
  99. StringClass Profile;
  100. TRANSITION_DATA_LIST Transitions;
  101. float TurnRadius;
  102. bool OccupantsVisible;
  103. bool SightDownMuzzle;
  104. bool Aim2D;
  105. float EngineSoundMaxPitchFactor;
  106. int EngineSound[MAX_ENGINE_SOUND_STATES];
  107. float SquishVelocity;
  108. int VehicleNameID;
  109. int NumSeats;
  110. int GDIDamageReportID;
  111. int NodDamageReportID;
  112. int GDIDestroyReportID;
  113. int NodDestroyReportID;
  114. friend class VehicleGameObj;
  115. };
  116. /*
  117. **
  118. */
  119. class VehicleGameObj : public SmartGameObj {
  120. public:
  121. VehicleGameObj();
  122. virtual ~VehicleGameObj();
  123. // Definitions
  124. virtual void Init( void );
  125. void Init( const VehicleGameObjDef & definition );
  126. const VehicleGameObjDef & Get_Definition( void ) const ;
  127. // Save / Load / Construction Factory
  128. virtual bool Save( ChunkSaveClass & csave );
  129. virtual bool Load( ChunkLoadClass & cload );
  130. virtual void On_Post_Load( void );
  131. virtual const PersistFactoryClass & Get_Factory( void ) const;
  132. virtual void Startup( void );
  133. // Physics
  134. VehiclePhysClass * Peek_Vehicle_Phys( void ) const;
  135. // Think
  136. virtual void Think( void );
  137. virtual void Post_Think( void );
  138. // Control
  139. virtual void Apply_Control( void );
  140. virtual int Get_Weapon_Control_Owner(void);
  141. // Weapon
  142. virtual bool Set_Targeting( const Vector3 & pos, bool do_tilt = true );
  143. virtual bool Use_2D_Aiming( void ) { return Get_Definition().Aim2D; }
  144. virtual Matrix3D Get_Look_Transform(void);
  145. bool Has_Turret( void) { return TurretBone != 0; }
  146. // Type ID
  147. virtual VehicleGameObj *As_VehicleGameObj() { return this; }
  148. virtual bool Is_Aircraft( void ) { return Get_Definition().Type == VEHICLE_TYPE_FLYING; }
  149. virtual bool Is_Turret( void ) { return Get_Definition().Type == VEHICLE_TYPE_TURRET; }
  150. virtual int Get_Player_Type(void) const;
  151. // Occupants
  152. void Add_Occupant( SoldierGameObj * occupant, int seat_id );
  153. void Add_Occupant( SoldierGameObj * occupant );
  154. void Remove_Occupant( SoldierGameObj * occupant );
  155. bool Contains_Occupant( SoldierGameObj * occupant );
  156. int Get_Occupant_Count(void);
  157. int Find_Seat( SoldierGameObj * occupant );
  158. SoldierGameObj * Get_Driver(void);
  159. SoldierGameObj * Get_Gunner(void);
  160. SoldierGameObj * Get_Actual_Gunner(void);
  161. virtual bool Is_Entry_Permitted(SoldierGameObj * p_soldier);
  162. void Passenger_Entering( void ); // used to begin animation
  163. void Passenger_Exiting( void ); // used to begin animation
  164. void Set_Vehicle_Delivered(void);
  165. // State
  166. virtual void Export_Creation( BitStreamClass & packet );
  167. virtual void Import_Creation( BitStreamClass & packet );
  168. virtual void Export_Rare( BitStreamClass &packet );
  169. virtual void Import_Rare( BitStreamClass &packet );
  170. virtual void Import_Frequent( BitStreamClass & packet );
  171. virtual void Export_Frequent( BitStreamClass & packet );
  172. virtual void Import_State_Cs( BitStreamClass & packet );
  173. virtual void Export_State_Cs( BitStreamClass & packet );
  174. // Profile
  175. const char *Get_Profile( void ) { return Get_Definition().Profile; }
  176. // Velocity
  177. void Get_Velocity(Vector3 & vel);
  178. void Set_Velocity(Vector3 & vel);
  179. //virtual void Get_Extended_Information( StringClass & description );
  180. virtual void Get_Description( StringClass & description );
  181. // Pathfinding
  182. float Get_Turn_Radius (void) const { return Get_Definition ().TurnRadius; }
  183. // Engine control
  184. bool Is_Engine_Enabled (void) const;
  185. void Enable_Engine (bool onoff);
  186. // Wheel Effects
  187. void Init_Wheel_Effects( void );
  188. void Shutdown_Wheel_Effects( void );
  189. void Update_Wheel_Effects( void );
  190. // Damage
  191. virtual void Apply_Damage( const OffenseObjectClass & damager, float scale = 1.0f, int alternate_skin = -1 );
  192. void Update_Damage_Meshes( void );
  193. float Get_Squish_Velocity( void) { return Get_Definition().SquishVelocity; }
  194. // Script enabling of transitions
  195. void Script_Enable_Transitions( bool enable ) { TransitionsEnabled = enable; Create_And_Destroy_Transitions(); }
  196. static void Set_Precision(void);
  197. static bool Toggle_Target_Steering( void );
  198. static void Set_Target_Steering( bool onoff );
  199. static bool Is_Target_Steering( void );
  200. const WCHAR * Get_Vehicle_Name( void );
  201. // Vehicles expire when they are flipped.
  202. virtual ExpirationReactionType Object_Expired( PhysClass * observed_obj );
  203. // Vehicle locking. In network games, a vehicle can be locked for all but the
  204. // owner for a certain amount of time.
  205. // NOTE: for network play, locking a vehicle only works at creation time and only
  206. // if the lock is set up prior to the creation packet being sent.
  207. void Lock_Vehicle( ScriptableGameObj *lockowner, float locktime ) { LockOwner = lockowner, LockTimer = locktime; }
  208. bool Is_Locked(void) { return ((LockOwner.Get_Ptr() != NULL) && (LockTimer > 0.0f)); }
  209. ScriptableGameObj * Get_Lock_Owner(void) { return LockOwner.Get_Ptr(); }
  210. static void Set_Default_Driver_Is_Gunner(bool flag) {DefaultDriverIsGunner = flag;}
  211. bool Get_Driver_Is_Gunner(void) {return DriverIsGunner;}
  212. void Toggle_Driver_Is_Gunner(void) { DriverIsGunner = !DriverIsGunner; }
  213. static void Set_Camera_Locked_To_Turret(bool flag) {CameraLockedToTurret = flag;}
  214. static bool Get_Camera_Locked_To_Turret(void) {return CameraLockedToTurret;}
  215. // Stealth
  216. virtual float Get_Stealth_Fade_Distance(void) const;
  217. virtual float Get_Filter_Distance(void) const;
  218. // Ignore occupants for raycasts
  219. void Ignore_Occupants( void );
  220. void Unignore_Occupants( void );
  221. protected:
  222. Sound3DClass *Sound;
  223. int EngineSoundState;
  224. AudibleSoundClass *CachedEngineSound;
  225. int TurretBone;
  226. int BarrelBone;
  227. float TurretTurn;
  228. float BarrelTilt;
  229. float BarrelOffset; // For Vehicles with offset turrets
  230. bool TransitionsEnabled;
  231. bool HasEnterTransitions;
  232. bool HasExitTransitions;
  233. bool VehicleDelivered;
  234. bool DriverIsGunner;
  235. static bool DefaultDriverIsGunner;
  236. static bool CameraLockedToTurret;
  237. // Wheel Effects
  238. VectorClass<PersistantSurfaceEmitterClass *> WheelSurfaceEmitters;
  239. PersistantSurfaceSoundClass * WheelSurfaceSound;
  240. // Occupants
  241. enum {
  242. DRIVER_SEAT = 0,
  243. GUNNER_SEAT,
  244. };
  245. VectorClass<SoldierGameObj *> SeatOccupants;
  246. int OccupiedSeats;
  247. DynamicVectorClass<TransitionInstanceClass *> TransitionInstances;
  248. // Lock feature. Vehicle can be locked to all but the purchaser for some number of seconds
  249. GameObjReference LockOwner; // who owns the lock for this vehicle?
  250. float LockTimer;
  251. void Remove_Transitions( TransitionDataClass::StyleType transition_type );
  252. void Create_New_Transitions( TransitionDataClass::StyleType transition_type );
  253. void Destroy_Transitions( void );
  254. void Update_Transitions( void );
  255. void Create_And_Destroy_Transitions( void );
  256. // Turrets
  257. void Aquire_Turret_Bones( void );
  258. void Release_Turret_Bones( void );
  259. void Update_Turret( float weapon_turn, float weapon_tilt );
  260. // Sound Effects (wheels, engine)
  261. void Update_Sound_Effects( void );
  262. void Change_Engine_Sound_State( int new_state );
  263. void Update_Engine_Sound_Pitch( void );
  264. };
  265. #endif // VEHICLE_H