combat.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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/combat.h $*
  25. * *
  26. * $Author:: Bhayes $*
  27. * *
  28. * $Modtime:: 2/17/02 10:27a $*
  29. * *
  30. * $Revision:: 130 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef COMBAT_H
  36. #define COMBAT_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef GAMEOBJREF_H
  41. #include "gameobjref.h"
  42. #endif
  43. #ifndef VECTOR3_H
  44. #include "vector3.h"
  45. #endif
  46. #ifndef WWSTRING_H
  47. #include "wwstring.h"
  48. #endif
  49. /*
  50. **
  51. */
  52. class PhysicsSceneClass;
  53. class CameraClass;
  54. class CCameraClass;
  55. class SmartGameObj;
  56. class ArmedGameObj;
  57. class PhysicalGameObj;
  58. class SimpleSceneClass;
  59. class BaseGameObj;
  60. class VehicleGameObj;
  61. class SoldierGameObj;
  62. class DazzleLayerClass;
  63. class MessageWindowClass;
  64. class SoundEnvironmentClass;
  65. /*
  66. **
  67. */
  68. #define COMBAT_CAMERA CombatManager::Get_Camera()
  69. #define COMBAT_STAR CombatManager::Get_The_Star()
  70. #define COMBAT_SCENE CombatManager::Get_Scene()
  71. #define COMBAT_DAZZLE_LAYER CombatManager::Get_Dazzle_Layer()
  72. /*
  73. ** Collision Groups
  74. */
  75. typedef enum {
  76. DEFAULT_COLLISION_GROUP = 0, // collides with everything
  77. UNCOLLIDEABLE_GROUP, // collides with nothing
  78. TERRAIN_ONLY_COLLISION_GROUP, // collides only with terrain
  79. BULLET_COLLISION_GROUP, // collides with everything but itself
  80. TERRAIN_AND_BULLET_COLLISION_GROUP, // collides with terrain and bullets
  81. BULLET_ONLY_COLLISION_GROUP, // collides only with bullets
  82. SOLDIER_COLLISION_GROUP, // collides with everything (but only soldiers use it)
  83. SOLDIER_GHOST_COLLISION_GROUP, // collides with everything but soldiers
  84. TERRAIN_COLLISION_GROUP = 15, // Terrain must be 15
  85. } Collision_Group_Type;
  86. /*
  87. **
  88. */
  89. class CombatNetworkHandlerClass {
  90. public:
  91. virtual bool Can_Damage(ArmedGameObj * p_armed_damager, PhysicalGameObj * p_phys_victim) = 0;
  92. virtual float Get_Damage_Factor(ArmedGameObj * p_armed_damager, PhysicalGameObj * p_phys_victim) = 0;
  93. virtual void On_Soldier_Kill(SoldierGameObj * p_soldier, SoldierGameObj * p_victim) = 0;
  94. virtual void On_Soldier_Death(SoldierGameObj * p_soldier) = 0;
  95. virtual bool Is_Gameplay_Permitted(void) = 0;
  96. };
  97. /*
  98. **
  99. */
  100. class CombatMiscHandlerClass {
  101. public:
  102. virtual void Mission_Complete( bool success ) = 0;
  103. virtual void Star_Killed( void ) = 0;
  104. };
  105. /*
  106. **
  107. */
  108. class CombatManager {
  109. public:
  110. // Init and Shutdown should be called once per program execution
  111. static void Init( bool render_available = true );
  112. static void Shutdown( void );
  113. // Scene_Init is called by the game, but not the editor
  114. static void Scene_Init( void );
  115. // Level Loading functions get called for each level loaded.
  116. static void Pre_Load_Level( bool render_available = true );
  117. static void Load_Level_Threaded( const char * map_name, bool preload_assets );
  118. static bool Is_Load_Level_Complete( void );
  119. static bool Is_Loading_Level( void );
  120. static void Post_Load_Level( void );
  121. static void Unload_Level( void );
  122. // Main Loop functions
  123. static void Generate_Control( void );
  124. static void Think( void );
  125. static void Render( void );
  126. static void Handle_Input( void );
  127. // Save/Load
  128. static bool Save( ChunkSaveClass &csave );
  129. static bool Load( ChunkLoadClass &cload );
  130. // Client/Server Settings
  131. static void Set_I_Am_Server( bool yes ) { IAmServer = yes; }
  132. static void Set_I_Am_Client( bool yes ) { IAmClient = yes; }
  133. static bool I_Am_Server( void ) { return IAmServer; }
  134. static bool I_Am_Client( void ) { return IAmClient; }
  135. static bool I_Am_Only_Client( void ) { return IAmClient && !IAmServer; }
  136. static bool I_Am_Only_Server( void ) { return IAmServer && !IAmClient; }
  137. static bool I_Am_Client_Server(void) { return IAmClient && IAmServer;}
  138. static void Set_Friendly_Fire_Permitted( bool yes ) { FriendlyFirePermitted = yes; }
  139. static bool Is_Friendly_Fire_Permitted( void ) { return FriendlyFirePermitted; }
  140. static void Set_Beacon_Placement_Ends_Game( bool yes ){ BeaconPlacementEndsGame = yes; }
  141. static bool Does_Beacon_Placement_Ends_Game( void ) { return BeaconPlacementEndsGame; }
  142. static void Set_My_Id( int id ) { MyId = id; }
  143. static int Get_My_Id( void ) { return MyId; }
  144. // Latency support
  145. static void Set_Last_Round_Trip_Ping_Ms( DWORD ping ) { LastRoundTripPingMs = ping; }
  146. static DWORD Get_Last_Round_Trip_Ping_Ms( void ) { return LastRoundTripPingMs; }
  147. static void Set_Avg_Round_Trip_Ping_Ms( DWORD ping ) { AvgRoundTripPingMs = ping; }
  148. static DWORD Get_Avg_Round_Trip_Ping_Ms( void ) { return AvgRoundTripPingMs; }
  149. // Network Handler Functions
  150. static void Set_Combat_Network_Handler( CombatNetworkHandlerClass * handler ) { NetworkHandler = handler; }
  151. static bool Can_Damage(ArmedGameObj * p_armed_damager, PhysicalGameObj * p_phys_victim);
  152. static float Get_Damage_Factor(ArmedGameObj * p_armed_damager, PhysicalGameObj * p_phys_victim);
  153. static void On_Soldier_Kill(SoldierGameObj * p_soldier, SoldierGameObj * p_victim);
  154. static void On_Soldier_Death(SoldierGameObj * p_soldier);
  155. static bool Is_Gameplay_Permitted(void);
  156. // Misc Handler
  157. static void Set_Combat_Misc_Handler( CombatMiscHandlerClass * handler ) { MiscHandler = handler; }
  158. static void Mission_Complete( bool success );
  159. static void Star_Killed( void );
  160. // The Star
  161. static void Set_The_Star( SoldierGameObj *target, bool is_star_determining_target = true );
  162. static SoldierGameObj * Get_The_Star( void ) { return (SoldierGameObj *)TheStar.Get_Ptr(); }
  163. static void Update_Star( void );
  164. static void Update_Star_Targeting( void );
  165. static bool Is_Star_Determining_Target(void) {return IsStarDeterminingTarget;}
  166. static void Set_Is_Star_Determining_Target(bool flag) {IsStarDeterminingTarget = flag;}
  167. // The Scene
  168. static PhysicsSceneClass *Get_Scene( void );
  169. static SimpleSceneClass *Get_Background_Scene( void ) { return BackgroundScene; }
  170. static CCameraClass *Get_Camera( void ) { return MainCamera; }
  171. static SoundEnvironmentClass *Get_Sound_Environment( void ) { return SoundEnvironment; }
  172. static void Set_Camera_Profile( const char * profile_name );
  173. static void Set_Camera_Vehicle( VehicleGameObj * obj, int seat = 0 );
  174. static bool Is_In_Camera_Frustrum(Vector3 & position);
  175. static bool Are_Observers_Active( void ) { return AreObserversActive; }
  176. static void Set_Observers_Active( bool onoff ) { AreObserversActive = onoff; }
  177. static bool Is_First_Load( void ) { return IsFirstLoad; }
  178. static void Set_First_Load( bool onoff ) { IsFirstLoad = onoff; }
  179. static void Do_Skeleton_Slider_Demo( void );
  180. static void Toggle_Skeleton_Slider_Demo( void ) { EnableSkeletonSliderDemo = !EnableSkeletonSliderDemo; }
  181. static bool Is_Skeleton_Slider_Demo_Enabled( void ) { return EnableSkeletonSliderDemo; }
  182. static DazzleLayerClass * Get_Dazzle_Layer(void) { return DazzleLayer; }
  183. // First Person
  184. static void Set_First_Person( bool on_off ) { FirstPerson = on_off; }
  185. static bool Is_First_Person( void ) { return FirstPerson; }
  186. static void Set_First_Person_Default( bool on_off ) { FirstPersonDefault = on_off; }
  187. static bool Get_First_Person_Default( void ) { return FirstPersonDefault; }
  188. // Difficulty
  189. static void Set_Difficulty_Level( int level ) { DifficultyLevel = level; }
  190. static int Get_Difficulty_Level( void ) { return DifficultyLevel; }
  191. static bool Are_Transitions_Automatic( void ) { return AutoTransitions; }
  192. static void Set_Transitions_Automatic( bool state ) { AutoTransitions = state; }
  193. // Message window
  194. static MessageWindowClass * Get_Message_Window (void) { return MessageWindow; }
  195. static void Show_Star_Damage_Direction( int direction ) { StarDamageDirection |= 1 << (direction&7); }
  196. static int Get_Star_Damage_Direction( void ) { return StarDamageDirection; }
  197. static void Clear_Star_Damage_Direction( void ) { StarDamageDirection = 0; }
  198. static int Get_Sync_Time( void ) { return SyncTime; }
  199. static bool Is_Game_Paused( void ) { return IsGamePaused; }
  200. static void Register_Star_Killer( ArmedGameObj * killer );
  201. static const char * Get_Start_Script( void ) { return StartScript; }
  202. static const char * Get_Respawn_Script( void ) { return RespawnScript; }
  203. static void Set_Start_Script( const char * string ) { StartScript = string; }
  204. static void Set_Respawn_Script( const char * string ) { RespawnScript = string; }
  205. static void Request_Autosave( bool state = true ) { AutosaveRequested = state; }
  206. static bool Is_Autosave_Requested( void ) { return AutosaveRequested; }
  207. static int Get_Reload_Count( void ) { return ReloadCount; }
  208. static bool Is_Hit_Reticle_Enabled( void ) { return HitReticleEnabled; }
  209. static void Toggle_Hit_Reticle_Enabled( void ) { HitReticleEnabled = !HitReticleEnabled; }
  210. static const char * Get_Last_LSD_Name( void ) { return LastLSDName; };
  211. static void Set_Last_LSD_Name( const char * name ) { LastLSDName = name; };
  212. static int Get_Load_Progress( void ) { return LoadProgress; };
  213. static void Inc_Load_Progress( void ) { LoadProgress++; };
  214. static void Set_Load_Progress( int set ) { LoadProgress = set; };
  215. private:
  216. static bool IAmServer;
  217. static bool IAmClient;
  218. static bool IAmOnlyClient;
  219. static bool IAmOnlyServer;
  220. static int MyId;
  221. static int SyncTime;
  222. static bool IsGamePaused;
  223. static bool IsLevelInitialized;
  224. static bool FriendlyFirePermitted;
  225. static bool BeaconPlacementEndsGame;
  226. static bool FirstPerson;
  227. static bool FirstPersonDefault;
  228. static CCameraClass * MainCamera;
  229. static SimpleSceneClass * BackgroundScene;
  230. static SoundEnvironmentClass * SoundEnvironment;
  231. static DazzleLayerClass * DazzleLayer;
  232. static MessageWindowClass * MessageWindow;
  233. static GameObjReference TheStar;
  234. static bool IsStarDeterminingTarget;
  235. static bool IsFirstLoad;
  236. static bool AreObserversActive;
  237. static bool EnableSkeletonSliderDemo;
  238. static int DifficultyLevel;
  239. static bool AutoTransitions;
  240. static int StarDamageDirection;
  241. static int StarKillerID;
  242. static CombatNetworkHandlerClass * NetworkHandler;
  243. static CombatMiscHandlerClass * MiscHandler;
  244. static StringClass StartScript;
  245. static StringClass RespawnScript;
  246. static int ReloadCount;
  247. static bool HitReticleEnabled;
  248. static bool IsGameplayPermitted;
  249. /*
  250. ** Combat Mode Management
  251. */
  252. typedef enum {
  253. COMBAT_MODE_NONE,
  254. COMBAT_MODE_FIRST_PERSON,
  255. COMBAT_MODE_THIRD_PERSON,
  256. COMBAT_MODE_SNIPING,
  257. COMBAT_MODE_IN_VEHICLE,
  258. COMBAT_MODE_ON_LADDER,
  259. COMBAT_MODE_DIEING,
  260. COMBAT_MODE_CORPSE,
  261. COMBAT_MODE_SNAP_SHOT,
  262. };
  263. static int CombatMode;
  264. static bool AutosaveRequested;
  265. static void Set_Combat_Mode( int mode );
  266. static void Update_Combat_Mode( void );
  267. /*
  268. ** Latency Support
  269. */
  270. static DWORD LastRoundTripPingMs;
  271. static DWORD AvgRoundTripPingMs;
  272. static StringClass LastLSDName;
  273. static int LoadProgress;
  274. static bool MultiplayRenderingAllowed;
  275. };
  276. #endif