Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

344 lines
6.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "dod_gamerules.h"
  10. #include "weapon_dodbaserpg.h"
  11. #ifdef CLIENT_DLL
  12. #include "c_dod_player.h"
  13. #include "prediction.h"
  14. #else
  15. #include "dod_player.h"
  16. #endif
  17. IMPLEMENT_NETWORKCLASS_ALIASED( DODBaseRocketWeapon, DT_BaseRocketWeapon )
  18. BEGIN_NETWORK_TABLE( CDODBaseRocketWeapon, DT_BaseRocketWeapon )
  19. #ifdef CLIENT_DLL
  20. RecvPropBool( RECVINFO(m_bDeployed) )
  21. #else
  22. SendPropBool( SENDINFO(m_bDeployed) )
  23. #endif
  24. END_NETWORK_TABLE()
  25. BEGIN_PREDICTION_DATA( CDODBaseRocketWeapon )
  26. END_PREDICTION_DATA()
  27. #ifndef CLIENT_DLL
  28. BEGIN_DATADESC( CDODBaseRocketWeapon )
  29. END_DATADESC()
  30. #endif
  31. LINK_ENTITY_TO_CLASS( weapon_dodbaserpg, CDODBaseRocketWeapon );
  32. CDODBaseRocketWeapon::CDODBaseRocketWeapon()
  33. {
  34. }
  35. void CDODBaseRocketWeapon::Precache()
  36. {
  37. BaseClass::Precache();
  38. }
  39. bool CDODBaseRocketWeapon::Reload( void )
  40. {
  41. CDODPlayer *pPlayer = GetDODPlayerOwner();
  42. if (pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
  43. {
  44. CDODPlayer *pDODPlayer = ToDODPlayer( pPlayer );
  45. pDODPlayer->HintMessage( HINT_AMMO_EXHAUSTED );
  46. return false;
  47. }
  48. Activity actReload;
  49. if( IsDeployed() )
  50. actReload = ACT_VM_RELOAD_DEPLOYED;
  51. else
  52. actReload = ACT_VM_RELOAD;
  53. int iResult = DefaultReload( GetMaxClip1(), GetMaxClip2(), actReload );
  54. if ( !iResult )
  55. return false;
  56. pPlayer->SetAnimation( PLAYER_RELOAD );
  57. // if we don't want the auto-rezoom, undeploy here
  58. if ( !pPlayer->ShouldAutoRezoom() )
  59. {
  60. m_bDeployed = false;
  61. pPlayer->SetBazookaDeployed( m_bDeployed );
  62. }
  63. return true;
  64. }
  65. bool CDODBaseRocketWeapon::ShouldPlayerBeSlow( void )
  66. {
  67. if( IsDeployed() && !m_bInReload )
  68. {
  69. return true;
  70. }
  71. else
  72. return false;
  73. }
  74. void CDODBaseRocketWeapon::Spawn( )
  75. {
  76. WEAPON_FILE_INFO_HANDLE hWpnInfo = LookupWeaponInfoSlot( GetClassname() );
  77. Assert( hWpnInfo != GetInvalidWeaponInfoHandle() );
  78. CDODWeaponInfo *pWeaponInfo = dynamic_cast< CDODWeaponInfo* >( GetFileWeaponInfoFromHandle( hWpnInfo ) );
  79. Assert( pWeaponInfo && "Failed to get CDODWeaponInfo in weapon spawn" );
  80. m_pWeaponInfo = pWeaponInfo;
  81. BaseClass::Spawn();
  82. }
  83. void CDODBaseRocketWeapon::Drop( const Vector &vecVelocity )
  84. {
  85. SetDeployed( false );
  86. BaseClass::Drop( vecVelocity );
  87. }
  88. bool CDODBaseRocketWeapon::Deploy( )
  89. {
  90. return DefaultDeploy( (char*)GetViewModel(), (char*)GetWorldModel(), GetDrawActivity(), (char*)GetAnimPrefix() );
  91. }
  92. Activity CDODBaseRocketWeapon::GetDrawActivity( void )
  93. {
  94. return ACT_VM_DRAW;
  95. }
  96. bool CDODBaseRocketWeapon::CanHolster( void )
  97. {
  98. // can't holster if we are delpoyed and not reloading
  99. if ( IsDeployed() && !m_bInReload )
  100. return false;
  101. return true;
  102. }
  103. bool CDODBaseRocketWeapon::Holster( CBaseCombatWeapon *pSwitchingTo )
  104. {
  105. #ifndef CLIENT_DLL
  106. CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
  107. pPlayer->SetBazookaDeployed( false );
  108. #endif
  109. SetDeployed( false );
  110. return BaseClass::Holster(pSwitchingTo);
  111. }
  112. void CDODBaseRocketWeapon::PrimaryAttack()
  113. {
  114. Assert( m_pWeaponInfo );
  115. CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
  116. // Out of ammo?
  117. if ( m_iClip1 <= 0 )
  118. {
  119. if (m_bFireOnEmpty)
  120. {
  121. PlayEmptySound();
  122. m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
  123. }
  124. return;
  125. }
  126. if( pPlayer->GetWaterLevel() > 2 )
  127. {
  128. PlayEmptySound();
  129. m_flNextPrimaryAttack = gpGlobals->curtime + 1.0;
  130. return;
  131. }
  132. if( IsDeployed() )
  133. {
  134. // player "shoot" animation
  135. pPlayer->SetAnimation( PLAYER_ATTACK1 );
  136. SendWeaponAnim( ACT_VM_PRIMARYATTACK );
  137. FireRocket();
  138. DoFireEffects();
  139. m_iClip1--;
  140. #ifdef CLIENT_DLL
  141. if ( prediction->IsFirstTimePredicted() )
  142. pPlayer->DoRecoil( GetWeaponID(), GetRecoil() );
  143. #endif
  144. if ( m_iClip1 <= 0 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 )
  145. {
  146. Lower();
  147. }
  148. m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration() + 0.5;
  149. m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration() + 0.5; //length of the fire anim!
  150. #ifndef CLIENT_DLL
  151. IGameEvent * event = gameeventmanager->CreateEvent( "dod_stats_weapon_attack" );
  152. if ( event )
  153. {
  154. event->SetInt( "attacker", pPlayer->GetUserID() );
  155. event->SetInt( "weapon", GetStatsWeaponID() );
  156. gameeventmanager->FireEvent( event );
  157. }
  158. #endif //CLIENT_DLL
  159. }
  160. else
  161. {
  162. #ifdef CLIENT_DLL
  163. pPlayer->HintMessage( HINT_SHOULDER_WEAPON, true );
  164. #endif
  165. m_flNextPrimaryAttack = gpGlobals->curtime + 2.0f;
  166. }
  167. }
  168. void CDODBaseRocketWeapon::FireRocket( void )
  169. {
  170. Assert( !"Derived classes must implement this." );
  171. }
  172. void CDODBaseRocketWeapon::DoFireEffects()
  173. {
  174. CBasePlayer *pPlayer = GetPlayerOwner();
  175. if ( pPlayer )
  176. pPlayer->DoMuzzleFlash();
  177. //smoke etc
  178. }
  179. void CDODBaseRocketWeapon::SecondaryAttack()
  180. {
  181. CBasePlayer *pPlayer = GetPlayerOwner();
  182. //if we're underwater, lower it
  183. if( pPlayer->GetWaterLevel() > 2 )
  184. {
  185. if( IsDeployed() )
  186. Lower();
  187. return;
  188. }
  189. if( IsDeployed() )
  190. {
  191. Lower();
  192. }
  193. else
  194. {
  195. if ( CanAttack() )
  196. Raise();
  197. }
  198. }
  199. void CDODBaseRocketWeapon::WeaponIdle()
  200. {
  201. if (m_flTimeWeaponIdle > gpGlobals->curtime)
  202. return;
  203. SendWeaponAnim( GetIdleActivity() );
  204. m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration();
  205. }
  206. Activity CDODBaseRocketWeapon::GetIdleActivity( void )
  207. {
  208. Activity actIdle;
  209. if( IsDeployed() )
  210. actIdle = ACT_VM_IDLE_DEPLOYED;
  211. else
  212. actIdle = ACT_VM_IDLE;
  213. return actIdle;
  214. }
  215. /* Raise the Bazooka to your shoulder */
  216. void CDODBaseRocketWeapon::Raise()
  217. {
  218. //raise to the shoulder
  219. SendWeaponAnim( GetRaiseActivity() );
  220. m_bDeployed = true;
  221. m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration();
  222. m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration();
  223. m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration();
  224. }
  225. /* Lower the bazooka to running position */
  226. bool CDODBaseRocketWeapon::Lower()
  227. {
  228. SendWeaponAnim( GetLowerActivity() );
  229. m_bDeployed = false;
  230. CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
  231. pPlayer->SetBazookaDeployed( m_bDeployed );
  232. m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration();
  233. m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration();
  234. m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration();
  235. return true;
  236. }
  237. Activity CDODBaseRocketWeapon::GetLowerActivity( void )
  238. {
  239. return ACT_VM_UNDEPLOY;
  240. }
  241. Activity CDODBaseRocketWeapon::GetRaiseActivity( void )
  242. {
  243. return ACT_VM_DEPLOY;
  244. }
  245. #ifdef CLIENT_DLL
  246. ConVar deployed_bazooka_sensitivity( "deployed_bazooka_sensitivity", "0.6", FCVAR_CHEAT, "Mouse sensitivity while deploying a bazooka" );
  247. void CDODBaseRocketWeapon::OverrideMouseInput( float *x, float *y )
  248. {
  249. if( m_bDeployed )
  250. {
  251. float flSensitivity = deployed_bazooka_sensitivity.GetFloat();
  252. *x *= flSensitivity;
  253. *y *= flSensitivity;
  254. }
  255. }
  256. #endif