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.

423 lines
8.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "weapon_dodbipodgun.h"
  8. #if defined( CLIENT_DLL )
  9. #include "c_dod_player.h"
  10. #define CWeapon30cal C_Weapon30cal
  11. #else
  12. #include "dod_player.h"
  13. #endif
  14. class CWeapon30cal : public CDODBipodWeapon
  15. {
  16. public:
  17. DECLARE_CLASS( CWeapon30cal, CDODBipodWeapon );
  18. DECLARE_NETWORKCLASS();
  19. DECLARE_PREDICTABLE();
  20. DECLARE_ACTTABLE();
  21. CWeapon30cal() {}
  22. virtual DODWeaponID GetWeaponID( void ) const { return WEAPON_30CAL; }
  23. // weapon id for stats purposes
  24. virtual DODWeaponID GetStatsWeaponID( void )
  25. {
  26. if ( !IsDeployed() )
  27. return WEAPON_30CAL_UNDEPLOYED;
  28. else
  29. return WEAPON_30CAL;
  30. }
  31. virtual void PrimaryAttack( void );
  32. virtual bool ShouldDrawCrosshair( void ) { return IsDeployed(); }
  33. virtual bool Reload( void );
  34. virtual Activity GetDrawActivity( void );
  35. virtual Activity GetDeployActivity( void );
  36. virtual Activity GetUndeployActivity( void );
  37. virtual Activity GetIdleActivity( void );
  38. virtual Activity GetPrimaryAttackActivity( void );
  39. virtual float GetRecoil( void );
  40. private:
  41. CWeapon30cal( const CWeapon30cal & );
  42. };
  43. IMPLEMENT_NETWORKCLASS_ALIASED( Weapon30cal, DT_Weapon30cal )
  44. BEGIN_NETWORK_TABLE( CWeapon30cal, DT_Weapon30cal )
  45. END_NETWORK_TABLE()
  46. BEGIN_PREDICTION_DATA( CWeapon30cal )
  47. END_PREDICTION_DATA()
  48. LINK_ENTITY_TO_CLASS( weapon_30cal, CWeapon30cal );
  49. PRECACHE_WEAPON_REGISTER( weapon_30cal );
  50. acttable_t CWeapon30cal::m_acttable[] =
  51. {
  52. { ACT_DOD_STAND_AIM, ACT_DOD_STAND_AIM_30CAL, false },
  53. { ACT_DOD_CROUCH_AIM, ACT_DOD_CROUCH_AIM_30CAL, false },
  54. { ACT_DOD_CROUCHWALK_AIM, ACT_DOD_CROUCHWALK_AIM_30CAL, false },
  55. { ACT_DOD_WALK_AIM, ACT_DOD_WALK_AIM_30CAL, false },
  56. { ACT_DOD_RUN_AIM, ACT_DOD_RUN_AIM_30CAL, false },
  57. { ACT_PRONE_IDLE, ACT_DOD_PRONE_AIM_30CAL, false },
  58. { ACT_PRONE_FORWARD, ACT_DOD_PRONEWALK_IDLE_30CAL, false },
  59. { ACT_DOD_STAND_IDLE, ACT_DOD_STAND_IDLE_30CAL, false },
  60. { ACT_DOD_CROUCH_IDLE, ACT_DOD_CROUCH_IDLE_30CAL, false },
  61. { ACT_DOD_CROUCHWALK_IDLE, ACT_DOD_CROUCHWALK_IDLE_30CAL, false },
  62. { ACT_DOD_WALK_IDLE, ACT_DOD_WALK_IDLE_30CAL, false },
  63. { ACT_DOD_RUN_IDLE, ACT_DOD_RUN_IDLE_30CAL, false },
  64. { ACT_SPRINT, ACT_DOD_SPRINT_IDLE_30CAL, false },
  65. { ACT_RANGE_ATTACK1, ACT_DOD_PRIMARYATTACK_30CAL, false },
  66. { ACT_DOD_PRIMARYATTACK_CROUCH, ACT_DOD_PRIMARYATTACK_30CAL, false },
  67. { ACT_DOD_PRIMARYATTACK_PRONE, ACT_DOD_PRIMARYATTACK_PRONE_30CAL, false },
  68. { ACT_DOD_DEPLOYED, ACT_DOD_DEPLOY_30CAL, false },
  69. { ACT_DOD_PRONE_DEPLOYED, ACT_DOD_PRONE_DEPLOY_30CAL, false },
  70. { ACT_DOD_PRIMARYATTACK_DEPLOYED, ACT_DOD_PRIMARYATTACK_DEPLOYED_30CAL, false },
  71. { ACT_DOD_PRIMARYATTACK_PRONE_DEPLOYED, ACT_DOD_PRIMARYATTACK_PRONE_DEPLOYED_30CAL,false },
  72. { ACT_DOD_RELOAD_DEPLOYED, ACT_DOD_RELOAD_DEPLOYED_30CAL, false },
  73. { ACT_DOD_RELOAD_PRONE_DEPLOYED, ACT_DOD_RELOAD_PRONE_DEPLOYED_30CAL, false },
  74. { ACT_DOD_HS_IDLE, ACT_DOD_HS_IDLE_30CAL, false },
  75. { ACT_DOD_HS_CROUCH, ACT_DOD_HS_CROUCH_30CAL, false },
  76. };
  77. IMPLEMENT_ACTTABLE( CWeapon30cal );
  78. bool CWeapon30cal::Reload( void )
  79. {
  80. if( !IsDeployed() )
  81. {
  82. #ifdef CLIENT_DLL
  83. CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
  84. if ( pPlayer )
  85. pPlayer->HintMessage( HINT_MG_DEPLOY_TO_RELOAD );
  86. #endif
  87. return false;
  88. }
  89. return BaseClass::Reload();
  90. }
  91. void CWeapon30cal::PrimaryAttack( void )
  92. {
  93. if ( m_iClip1 <= 0 )
  94. {
  95. if (m_bFireOnEmpty)
  96. {
  97. PlayEmptySound();
  98. m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
  99. }
  100. return;
  101. }
  102. #ifdef CLIENT_DLL
  103. C_DODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
  104. #else
  105. CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
  106. #endif
  107. Assert( pPlayer );
  108. if( !IsDeployed() )
  109. {
  110. #ifdef CLIENT_DLL
  111. pPlayer->HintMessage( HINT_MG_FIRE_UNDEPLOYED );
  112. #endif
  113. pPlayer->m_Shared.SetSlowedTime( 0.2 );
  114. float flStamina = pPlayer->m_Shared.GetStamina();
  115. pPlayer->m_Shared.SetStamina( flStamina - 15 );
  116. }
  117. BaseClass::PrimaryAttack();
  118. }
  119. Activity CWeapon30cal::GetDrawActivity( void )
  120. {
  121. Activity actDraw;
  122. if( m_iClip1 <= 0 )
  123. actDraw = ACT_VM_DRAW_EMPTY;
  124. else
  125. actDraw = ACT_VM_DRAW;
  126. return actDraw;
  127. }
  128. Activity CWeapon30cal::GetDeployActivity( void )
  129. {
  130. Activity actDeploy;
  131. switch ( m_iClip1 )
  132. {
  133. case 8:
  134. actDeploy = ACT_VM_DEPLOY_8;
  135. break;
  136. case 7:
  137. actDeploy = ACT_VM_DEPLOY_7;
  138. break;
  139. case 6:
  140. actDeploy = ACT_VM_DEPLOY_6;
  141. break;
  142. case 5:
  143. actDeploy = ACT_VM_DEPLOY_5;
  144. break;
  145. case 4:
  146. actDeploy = ACT_VM_DEPLOY_4;
  147. break;
  148. case 3:
  149. actDeploy = ACT_VM_DEPLOY_3;
  150. break;
  151. case 2:
  152. actDeploy = ACT_VM_DEPLOY_2;
  153. break;
  154. case 1:
  155. actDeploy = ACT_VM_DEPLOY_1;
  156. break;
  157. case 0:
  158. actDeploy = ACT_VM_DEPLOY_EMPTY;
  159. break;
  160. default:
  161. actDeploy = ACT_VM_DEPLOY;
  162. break;
  163. }
  164. return actDeploy;
  165. }
  166. Activity CWeapon30cal::GetUndeployActivity( void )
  167. {
  168. Activity actUndeploy;
  169. switch ( m_iClip1 )
  170. {
  171. case 8:
  172. actUndeploy = ACT_VM_UNDEPLOY_8;
  173. break;
  174. case 7:
  175. actUndeploy = ACT_VM_UNDEPLOY_7;
  176. break;
  177. case 6:
  178. actUndeploy = ACT_VM_UNDEPLOY_6;
  179. break;
  180. case 5:
  181. actUndeploy = ACT_VM_UNDEPLOY_5;
  182. break;
  183. case 4:
  184. actUndeploy = ACT_VM_UNDEPLOY_4;
  185. break;
  186. case 3:
  187. actUndeploy = ACT_VM_UNDEPLOY_3;
  188. break;
  189. case 2:
  190. actUndeploy = ACT_VM_UNDEPLOY_2;
  191. break;
  192. case 1:
  193. actUndeploy = ACT_VM_UNDEPLOY_1;
  194. break;
  195. case 0:
  196. actUndeploy = ACT_VM_UNDEPLOY_EMPTY;
  197. break;
  198. default:
  199. actUndeploy = ACT_VM_UNDEPLOY;
  200. break;
  201. }
  202. return actUndeploy;
  203. }
  204. Activity CWeapon30cal::GetIdleActivity( void )
  205. {
  206. Activity actIdle;
  207. if( IsDeployed() )
  208. {
  209. switch ( m_iClip1 )
  210. {
  211. case 8:
  212. actIdle = ACT_VM_IDLE_DEPLOYED_8;
  213. break;
  214. case 7:
  215. actIdle = ACT_VM_IDLE_DEPLOYED_7;
  216. break;
  217. case 6:
  218. actIdle = ACT_VM_IDLE_DEPLOYED_6;
  219. break;
  220. case 5:
  221. actIdle = ACT_VM_IDLE_DEPLOYED_5;
  222. break;
  223. case 4:
  224. actIdle = ACT_VM_IDLE_DEPLOYED_4;
  225. break;
  226. case 3:
  227. actIdle = ACT_VM_IDLE_DEPLOYED_3;
  228. break;
  229. case 2:
  230. actIdle = ACT_VM_IDLE_DEPLOYED_2;
  231. break;
  232. case 1:
  233. actIdle = ACT_VM_IDLE_DEPLOYED_1;
  234. break;
  235. case 0:
  236. actIdle = ACT_VM_IDLE_DEPLOYED_EMPTY;
  237. break;
  238. default:
  239. actIdle = ACT_VM_IDLE_DEPLOYED;
  240. break;
  241. }
  242. }
  243. else
  244. {
  245. switch ( m_iClip1 )
  246. {
  247. case 8:
  248. actIdle = ACT_VM_IDLE_8;
  249. break;
  250. case 7:
  251. actIdle = ACT_VM_IDLE_7;
  252. break;
  253. case 6:
  254. actIdle = ACT_VM_IDLE_6;
  255. break;
  256. case 5:
  257. actIdle = ACT_VM_IDLE_5;
  258. break;
  259. case 4:
  260. actIdle = ACT_VM_IDLE_4;
  261. break;
  262. case 3:
  263. actIdle = ACT_VM_IDLE_3;
  264. break;
  265. case 2:
  266. actIdle = ACT_VM_IDLE_2;
  267. break;
  268. case 1:
  269. actIdle = ACT_VM_IDLE_1;
  270. break;
  271. case 0:
  272. actIdle = ACT_VM_IDLE_EMPTY;
  273. break;
  274. default:
  275. actIdle = ACT_VM_IDLE;
  276. break;
  277. }
  278. }
  279. return actIdle;
  280. }
  281. Activity CWeapon30cal::GetPrimaryAttackActivity( void )
  282. {
  283. Activity actPrim;
  284. int maxhax = m_iClip1 + 2;
  285. if( IsDeployed() )
  286. {
  287. switch ( maxhax )
  288. {
  289. case 8:
  290. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED_8;
  291. break;
  292. case 7:
  293. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED_7;
  294. break;
  295. case 6:
  296. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED_6;
  297. break;
  298. case 5:
  299. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED_5;
  300. break;
  301. case 4:
  302. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED_4;
  303. break;
  304. case 3:
  305. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED_3;
  306. break;
  307. case 2:
  308. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED_2;
  309. break;
  310. case 1:
  311. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED_1;
  312. break;
  313. case 0:
  314. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED_EMPTY;
  315. break;
  316. default:
  317. actPrim = ACT_VM_PRIMARYATTACK_DEPLOYED;
  318. break;
  319. }
  320. }
  321. else
  322. {
  323. switch ( maxhax )
  324. {
  325. case 8:
  326. actPrim = ACT_VM_PRIMARYATTACK_8;
  327. break;
  328. case 7:
  329. actPrim = ACT_VM_PRIMARYATTACK_7;
  330. break;
  331. case 6:
  332. actPrim = ACT_VM_PRIMARYATTACK_6;
  333. break;
  334. case 5:
  335. actPrim = ACT_VM_PRIMARYATTACK_5;
  336. break;
  337. case 4:
  338. actPrim = ACT_VM_PRIMARYATTACK_4;
  339. break;
  340. case 3:
  341. actPrim = ACT_VM_PRIMARYATTACK_3;
  342. break;
  343. case 2:
  344. actPrim = ACT_VM_PRIMARYATTACK_2;
  345. break;
  346. case 1:
  347. actPrim = ACT_VM_PRIMARYATTACK_1;
  348. break;
  349. case 0:
  350. actPrim = ACT_VM_PRIMARYATTACK_EMPTY;
  351. break;
  352. default:
  353. actPrim = ACT_VM_PRIMARYATTACK;
  354. break;
  355. }
  356. }
  357. return actPrim;
  358. }
  359. float CWeapon30cal::GetRecoil( void )
  360. {
  361. CDODPlayer *p = ToDODPlayer( GetPlayerOwner() );
  362. if( p && p->m_Shared.IsInMGDeploy() )
  363. {
  364. return 0.0f;
  365. }
  366. return 20;
  367. }