weapons.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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/weapons.h $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 3/25/02 2:08p $*
  29. * *
  30. * $Revision:: 108 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef WEAPONS_H
  36. #define WEAPONS_H
  37. #ifndef ALWAYS_H
  38. #include "always.h"
  39. #endif
  40. #ifndef GAMEOBJREF_H
  41. #include "gameobjref.h"
  42. #endif
  43. #ifndef MATRIX3D_H
  44. #include "matrix3d.h"
  45. #endif
  46. #ifndef WEAPONMANAGER_H
  47. #include "weaponmanager.h"
  48. #endif
  49. #ifndef SIMPLEVEC_H
  50. #include "simplevec.h"
  51. #endif
  52. class BitStreamClass;
  53. class ChunkSaveClass;
  54. class ChunkLoadClass;
  55. class RenderObjClass;
  56. class ArmedGameObj;
  57. class ParticleEmitterClass;
  58. class AudibleSoundClass;
  59. class PhysicalGameObj;
  60. /*
  61. **
  62. */
  63. typedef enum {
  64. WEAPON_HOLD_STYLE_C4 = 0,
  65. WEAPON_HOLD_STYLE_NOT_USED,
  66. WEAPON_HOLD_STYLE_AT_SHOULDER, // 2
  67. WEAPON_HOLD_STYLE_AT_HIP,
  68. WEAPON_HOLD_STYLE_LAUNCHER,
  69. WEAPON_HOLD_STYLE_HANDGUN,
  70. WEAPON_HOLD_STYLE_BEACON,
  71. WEAPON_HOLD_STYLE_EMPTY_HANDS,
  72. WEAPON_HOLD_STYLE_AT_CHEST,
  73. WEAPON_HOLD_STYLE_HANDS_DOWN,
  74. NUM_WEAPON_HOLD_STYLES
  75. } WeaponHoldStyleType;
  76. /*
  77. **
  78. */
  79. typedef enum {
  80. WEAPON_MODEL_UPDATE_WILL_BE_NEEDED,
  81. WEAPON_MODEL_UPDATE_IS_NEEDED,
  82. WEAPON_MODEL_UPDATE_NOT_NEEDED,
  83. } WeaponModelUpdateState;
  84. /*
  85. **
  86. */
  87. typedef enum {
  88. WEAPON_ANIM_NOT_FIRING,
  89. WEAPON_ANIM_FIRING_0,
  90. WEAPON_ANIM_FIRING_1
  91. } WeaponAnimState;
  92. /*
  93. **
  94. */
  95. class MuzzleFlashClass {
  96. public:
  97. MuzzleFlashClass( void );
  98. ~MuzzleFlashClass( void );
  99. void Init( RenderObjClass * robj );
  100. void Update( bool flashA0, bool flashA1 );
  101. private:
  102. int MuzzleA0Bone;
  103. int MuzzleA1Bone;
  104. float Rotation;
  105. RenderObjClass * Model;
  106. bool LastFlashA0;
  107. bool LastFlashA1;
  108. };
  109. /*
  110. **
  111. */
  112. class WeaponClass {
  113. public:
  114. WeaponClass( const WeaponDefinitionClass *weapon_def = NULL );
  115. ~WeaponClass( void );
  116. void Init( const WeaponDefinitionClass *weapon_def );
  117. bool Save( ChunkSaveClass & csave );
  118. bool Load( ChunkLoadClass & cload );
  119. void Set_Model( RenderObjClass *model );
  120. void Set_Owner( ArmedGameObj *owner );
  121. ArmedGameObj *Get_Owner( void ) { return (ArmedGameObj *)Owner.Get_Ptr(); }
  122. enum {
  123. MUZZLE_PRIMARY_0,
  124. MUZZLE_PRIMARY_1,
  125. MUZZLE_SECONDARY_0,
  126. MUZZLE_SECONDARY_1,
  127. };
  128. void Select( void );
  129. void Deselect( void );
  130. void Update( void );
  131. bool Is_Muzzle_Clear( void );
  132. void Compute_Bullet_Start_Point(const Matrix3D & muzzle,Vector3 * set_start_point);
  133. void Next_C4_Detonation_Mode( void ); // Take the weapon to the next state (for C4)
  134. const WeaponDefinitionClass *Get_Definition( void ) { return Definition; }
  135. const char * Get_Name( void ) { return Definition->Get_Name(); }
  136. int Get_ID( void ) { return Definition->Get_ID(); }
  137. const char * Get_HUD_Icon_Texture_Name( void ) { return Definition->HUDIconTextureName; }
  138. const char * Get_Model_Name( void ) { return Definition->Model; }
  139. const char * Get_Back_Model_Name( void ){ return Definition->BackModel; }
  140. const char * Get_Anim_Name( void ) { return (NextAnimState != WEAPON_ANIM_NOT_FIRING) ? Definition->FireAnim : Definition->IdleAnim; }
  141. int Get_Style( void ) { return Definition->Style; }
  142. float Get_Key_Number( void ) { return Definition->KeyNumber; }
  143. bool Get_Can_Snipe( void ) { return Definition->CanSnipe; }
  144. float Get_Rating( void ) { return Definition->Rating; }
  145. float Get_Effective_Range( void ){ return PrimaryAmmoDefinition->EffectiveRange; }
  146. float Get_Primary_Fire_Rate( void ){ return PrimaryAmmoDefinition->RateOfFire; }
  147. const char * Get_First_Person_Model_Name( void ) const { return Definition->FirstPersonModel; }
  148. const Vector3& Get_First_Person_Model_Offset( void ) const { return Definition->FirstPersonOffset; }
  149. float Get_Recoil_Time( void ) { return Definition->RecoilTime; }
  150. float Get_Recoil_Scale( void ) { return Definition->RecoilScale; }
  151. // =========== Ammo
  152. void Set_Total_Rounds( int num );
  153. int Get_Total_Rounds( void );
  154. void Add_Rounds( int num );
  155. void Set_Clip_Rounds( int rounds ) { ClipRounds = rounds; }
  156. int Get_Clip_Rounds( void ) { return ClipRounds; }
  157. void Set_Inventory_Rounds( int rounds ) { InventoryRounds = rounds; }
  158. int Get_Inventory_Rounds( void ) { return InventoryRounds; }
  159. void Do_Reload( void );
  160. void Decrement_Rounds( int rounds = 1 );
  161. bool Is_Ammo_Maxed( void );
  162. bool Is_Loaded( void ) { return (ClipRounds != 0); }
  163. bool Is_Reload_OK( void );
  164. bool Is_Reload_Needed( void ) { return !Is_Loaded() && Is_Reload_OK(); }
  165. float Get_Range( void );
  166. bool Is_Model_Update_Needed( void ) { return (UpdateModel == WEAPON_MODEL_UPDATE_IS_NEEDED); }
  167. void Reset_Model_Update( void ) { UpdateModel = WEAPON_MODEL_UPDATE_NOT_NEEDED; CurrentAnimState = (WeaponAnimState)-1; }
  168. bool Is_Anim_Update_Needed( void ) { return ( NextAnimState != CurrentAnimState ); }
  169. void Reset_Anim_Update( void ) { CurrentAnimState = NextAnimState; }
  170. WeaponAnimState Get_Anim_State( void ) { return CurrentAnimState; }
  171. int Get_Total_Rounds_Fired( void ) { return TotalRoundsFired; }
  172. void Display_Targeting( void );
  173. void Set_Target( const Vector3 &target) { Target = target; }
  174. const Vector3 &Get_Target( void ) { return Target; }
  175. void Set_Target_Object( PhysicalGameObj * obj );
  176. PhysicalGameObj * Get_Target_Object( PhysicalGameObj * obj );
  177. /*
  178. ** Weapons States
  179. */
  180. typedef enum {
  181. STATE_IDLE,
  182. STATE_READY,
  183. STATE_CHARGE,
  184. STATE_FIRE_PRIMARY,
  185. STATE_FIRE_SECONDARY,
  186. STATE_RELOAD,
  187. STATE_START_SWITCH,
  188. STATE_END_SWITCH,
  189. // NUM_STATES,
  190. } WeaponStateType;
  191. WeaponStateType Get_State( void ) { return State; }
  192. bool Is_Firing( void ) { return DidFire; }
  193. bool Is_Reloading( void ) { return (State == STATE_RELOAD); }
  194. bool Is_Switching( void ) { return (State == STATE_START_SWITCH) || (State == STATE_END_SWITCH); }
  195. void Force_Reload( void );
  196. // Trigger State
  197. void Set_Safety( bool saftey ) { SafetySet = saftey; }
  198. bool Is_Safety_Set( void ) { return SafetySet; }
  199. void Set_Primary_Triggered( bool triggered );
  200. void Set_Secondary_Triggered( bool triggered );
  201. bool Is_Triggered( void ) { return IsSecondaryTriggered || IsPrimaryTriggered; }
  202. void Init_Muzzle_Flash( RenderObjClass * robj ) { MuzzleFlash.Init( robj ); }
  203. void Update_Muzzle_Flash( bool flashA0, bool flashA1 ) { MuzzleFlash.Update( flashA0, flashA1 ); }
  204. bool Does_Weapon_Exist( void ) { return WeaponExists; }
  205. void Set_Weapon_Exists( bool exists ) { WeaponExists = exists; }
  206. PhysicalGameObj * Cast_Weapon( const Vector3 & target );
  207. bool Cast_Weapon_Down_Muzzle( Vector3 & hit_pos );
  208. void Make_Shell_Eject( const Matrix3D & tm );
  209. //
  210. // Sound support
  211. //
  212. void Stop_Firing_Sound( void );
  213. private:
  214. void Fire_C4( const AmmoDefinitionClass *ammo_def );
  215. bool Fire_Beacon( const AmmoDefinitionClass *ammo_def );
  216. void Fire_Bullet( const AmmoDefinitionClass *ammo_def, bool primary );
  217. // Weapon Info
  218. const WeaponDefinitionClass *Definition;
  219. GameObjReference Owner; // who gets credit for this weapon's kills?
  220. RenderObjClass *Model;
  221. int C4DetonationMode;
  222. // Ammo Info
  223. const AmmoDefinitionClass *PrimaryAmmoDefinition;
  224. const AmmoDefinitionClass *SecondaryAmmoDefinition;
  225. safe_int ClipRounds;
  226. safe_int InventoryRounds; // -1 for unlimited
  227. safe_float BurstDelayTimer;
  228. safe_int BurstCount;
  229. float BulletBumpTime;
  230. bool WeaponExists; // allows us to have ammo with no weapon
  231. // Weapon States
  232. WeaponStateType State; // The state of the weapon
  233. float StateTimer; // in seconds. Used for switching, reloading, and idle
  234. bool DidFire;
  235. bool LastFrameIsPrimaryTriggered; // is the Trigger pulled
  236. bool LastFrameIsSecondaryTriggered; // is the Trigger pulled
  237. bool IsPrimaryTriggered; // is the Trigger pulled
  238. bool IsSecondaryTriggered; // is the Trigger pulled
  239. int TotalRoundsFired;
  240. bool SafetySet;
  241. bool LockTriggers;
  242. float EmptySoundTimer;
  243. // Weapon Looks
  244. WeaponAnimState NextAnimState; // Which anim should we be on
  245. WeaponAnimState CurrentAnimState; // Which anim are we on
  246. WeaponModelUpdateState UpdateModel; // Does the weapon Model need to be updated
  247. Vector3 Target;
  248. GameObjReference TargetObject;
  249. // Continuous Muzzle Effects (flames)
  250. SimpleVecClass<ParticleEmitterClass *> ContinuousEmitters;
  251. AudibleSoundClass * ContinuousSound;
  252. AudibleSoundClass * FiringSound;
  253. int FiringSoundDefID;
  254. // Functions
  255. const Matrix3D & Get_Muzzle( int index = MUZZLE_PRIMARY_0 );
  256. void Do_Fire( bool primary );
  257. // Weapon State
  258. void Set_State( WeaponStateType new_state );
  259. void Update_State( float dtime );
  260. void Do_Firing_Effects( void );
  261. void Do_Continuous_Effects( bool enable );
  262. // Muzzle Flash
  263. MuzzleFlashClass MuzzleFlash;
  264. void Ignore_Owner( void );
  265. void Unignore_Owner( void );
  266. };
  267. #endif // WEAPONS_H