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.

541 lines
13 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #ifdef CLIENT_DLL
  8. #include "iinput.h"
  9. #endif
  10. #include "tf_weapon_pda.h"
  11. #include "in_buttons.h"
  12. #include "tf_gamerules.h"
  13. #include "tf_weaponbase_gun.h"
  14. // Server specific.
  15. #if !defined( CLIENT_DLL )
  16. #include "tf_player.h"
  17. #include "vguiscreen.h"
  18. // Client specific.
  19. #else
  20. #include "c_tf_player.h"
  21. #include <igameevents.h>
  22. #include "tf_hud_menu_engy_build.h"
  23. #include "tf_hud_menu_engy_destroy.h"
  24. #include "tf_hud_menu_spy_disguise.h"
  25. #include "prediction.h"
  26. #ifdef STAGING_ONLY
  27. #include "tf_hud_menu_spy_build.h"
  28. #endif // STAGING_ONLY
  29. #endif
  30. //=============================================================================
  31. //
  32. // TFWeaponBase Melee tables.
  33. //
  34. IMPLEMENT_NETWORKCLASS_ALIASED( TFWeaponPDA, DT_TFWeaponPDA )
  35. BEGIN_NETWORK_TABLE( CTFWeaponPDA, DT_TFWeaponPDA )
  36. END_NETWORK_TABLE()
  37. BEGIN_PREDICTION_DATA( CTFWeaponPDA )
  38. END_PREDICTION_DATA()
  39. // Server specific.
  40. #if !defined( CLIENT_DLL )
  41. BEGIN_DATADESC( CTFWeaponPDA )
  42. END_DATADESC()
  43. #endif
  44. LINK_ENTITY_TO_CLASS( tf_pda_expansion_dispenser, CTFWeaponPDAExpansion_Dispenser );
  45. IMPLEMENT_NETWORKCLASS_ALIASED( TFWeaponPDAExpansion_Dispenser, DT_TFWeaponPDAExpansion_Dispenser )
  46. // Network Table --
  47. BEGIN_NETWORK_TABLE( CTFWeaponPDAExpansion_Dispenser, DT_TFWeaponPDAExpansion_Dispenser )
  48. END_NETWORK_TABLE()
  49. // -- Network Table
  50. // Data Desc --
  51. BEGIN_DATADESC( CTFWeaponPDAExpansion_Dispenser )
  52. END_DATADESC()
  53. //************************************************************************************************
  54. LINK_ENTITY_TO_CLASS( tf_pda_expansion_teleporter, CTFWeaponPDAExpansion_Teleporter );
  55. IMPLEMENT_NETWORKCLASS_ALIASED( TFWeaponPDAExpansion_Teleporter, DT_TFWeaponPDAExpansion_Teleporter )
  56. // Network Table --
  57. BEGIN_NETWORK_TABLE( CTFWeaponPDAExpansion_Teleporter, DT_TFWeaponPDAExpansion_Teleporter )
  58. END_NETWORK_TABLE()
  59. // -- Network Table
  60. // Data Desc --
  61. BEGIN_DATADESC( CTFWeaponPDAExpansion_Teleporter )
  62. END_DATADESC()
  63. CTFWeaponPDA::CTFWeaponPDA()
  64. {
  65. }
  66. void CTFWeaponPDA::Spawn()
  67. {
  68. BaseClass::Spawn();
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose: cancel menu
  72. //-----------------------------------------------------------------------------
  73. void CTFWeaponPDA::PrimaryAttack( void )
  74. {
  75. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  76. if ( !pOwner )
  77. {
  78. return;
  79. }
  80. pOwner->SelectLastItem();
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose: toggle invis
  84. //-----------------------------------------------------------------------------
  85. void CTFWeaponPDA::SecondaryAttack( void )
  86. {
  87. // semi-auto behaviour
  88. if ( m_bInAttack2 )
  89. return;
  90. // Get the player owning the weapon.
  91. CTFPlayer *pPlayer = ToTFPlayer( GetPlayerOwner() );
  92. if ( !pPlayer )
  93. return;
  94. pPlayer->DoClassSpecialSkill();
  95. m_bInAttack2 = true;
  96. m_flNextSecondaryAttack = gpGlobals->curtime + 0.5;
  97. }
  98. #if !defined( CLIENT_DLL )
  99. void CTFWeaponPDA::Precache()
  100. {
  101. BaseClass::Precache();
  102. PrecacheVGuiScreen( GetPanelName() );
  103. }
  104. //-----------------------------------------------------------------------------
  105. // Purpose: Gets info about the control panels
  106. //-----------------------------------------------------------------------------
  107. void CTFWeaponPDA::GetControlPanelInfo( int nPanelIndex, const char *&pPanelName )
  108. {
  109. pPanelName = GetPanelName();
  110. }
  111. #else
  112. float CTFWeaponPDA::CalcViewmodelBob( void )
  113. {
  114. // no bob
  115. return BaseClass::CalcViewmodelBob();
  116. }
  117. #endif
  118. //-----------------------------------------------------------------------------
  119. // Purpose:
  120. // Output : Returns true on success, false on failure.
  121. //-----------------------------------------------------------------------------
  122. bool CTFWeaponPDA::ShouldShowControlPanels( void )
  123. {
  124. return true;
  125. }
  126. #ifdef CLIENT_DLL
  127. void CTFWeaponPDA::OnDataChanged( DataUpdateType_t type )
  128. {
  129. if ( m_iState != m_iOldState && GetOwner() == C_TFPlayer::GetLocalTFPlayer() )
  130. {
  131. // Was active, now not
  132. if ( m_iOldState == WEAPON_IS_ACTIVE && m_iState != m_iOldState )
  133. {
  134. CHudBaseBuildMenu *pBuildMenu = GetBuildMenu();
  135. Assert( pBuildMenu );
  136. if ( pBuildMenu )
  137. {
  138. pBuildMenu->SetBuilderEquipped( false );
  139. }
  140. }
  141. else if ( m_iState == WEAPON_IS_ACTIVE && m_iOldState == WEAPON_IS_CARRIED_BY_PLAYER ) // Was inactive, now is
  142. {
  143. CHudBaseBuildMenu *pBuildMenu = GetBuildMenu();
  144. Assert( pBuildMenu );
  145. if ( pBuildMenu )
  146. {
  147. pBuildMenu->SetBuilderEquipped( true );
  148. }
  149. }
  150. }
  151. BaseClass::OnDataChanged( type );
  152. }
  153. void CTFWeaponPDA::UpdateOnRemove()
  154. {
  155. CHudBaseBuildMenu *pBuildMenu = GetBuildMenu();
  156. Assert( pBuildMenu );
  157. if ( pBuildMenu )
  158. {
  159. pBuildMenu->SetBuilderEquipped( false );
  160. }
  161. return BaseClass::UpdateOnRemove();
  162. }
  163. #endif
  164. //==============================
  165. IMPLEMENT_NETWORKCLASS_ALIASED( TFWeaponPDA_Engineer_Build, DT_TFWeaponPDA_Engineer_Build )
  166. BEGIN_NETWORK_TABLE( CTFWeaponPDA_Engineer_Build, DT_TFWeaponPDA_Engineer_Build )
  167. END_NETWORK_TABLE()
  168. BEGIN_PREDICTION_DATA( CTFWeaponPDA_Engineer_Build )
  169. END_PREDICTION_DATA()
  170. LINK_ENTITY_TO_CLASS( tf_weapon_pda_engineer_build, CTFWeaponPDA_Engineer_Build );
  171. PRECACHE_WEAPON_REGISTER( tf_weapon_pda_engineer_build );
  172. #ifdef CLIENT_DLL
  173. CHudBaseBuildMenu *CTFWeaponPDA_Engineer_Build::GetBuildMenu() const
  174. {
  175. return GET_HUDELEMENT( CHudMenuEngyBuild );
  176. }
  177. #endif // CLIENT_DLL
  178. //==============================
  179. IMPLEMENT_NETWORKCLASS_ALIASED( TFWeaponPDA_Engineer_Destroy, DT_TFWeaponPDA_Engineer_Destroy )
  180. BEGIN_NETWORK_TABLE( CTFWeaponPDA_Engineer_Destroy, DT_TFWeaponPDA_Engineer_Destroy )
  181. END_NETWORK_TABLE()
  182. BEGIN_PREDICTION_DATA( CTFWeaponPDA_Engineer_Destroy )
  183. END_PREDICTION_DATA()
  184. LINK_ENTITY_TO_CLASS( tf_weapon_pda_engineer_destroy, CTFWeaponPDA_Engineer_Destroy );
  185. PRECACHE_WEAPON_REGISTER( tf_weapon_pda_engineer_destroy );
  186. #ifdef CLIENT_DLL
  187. CHudBaseBuildMenu *CTFWeaponPDA_Engineer_Destroy::GetBuildMenu() const
  188. {
  189. return GET_HUDELEMENT( CHudMenuEngyDestroy );
  190. }
  191. #endif // CLIENT_DLL
  192. //==============================
  193. IMPLEMENT_NETWORKCLASS_ALIASED( TFWeaponPDA_Spy, DT_TFWeaponPDA_Spy )
  194. BEGIN_NETWORK_TABLE( CTFWeaponPDA_Spy, DT_TFWeaponPDA_Spy )
  195. END_NETWORK_TABLE()
  196. BEGIN_PREDICTION_DATA( CTFWeaponPDA_Spy )
  197. END_PREDICTION_DATA()
  198. LINK_ENTITY_TO_CLASS( tf_weapon_pda_spy, CTFWeaponPDA_Spy );
  199. PRECACHE_WEAPON_REGISTER( tf_weapon_pda_spy );
  200. #ifdef CLIENT_DLL
  201. CHudBaseBuildMenu *CTFWeaponPDA_Spy::GetBuildMenu() const
  202. {
  203. return GET_HUDELEMENT( CHudMenuSpyDisguise );
  204. }
  205. #endif // CLIENT_DLL
  206. #ifdef STAGING_ONLY
  207. //==============================
  208. IMPLEMENT_NETWORKCLASS_ALIASED( TFWeaponPDA_Spy_Build, DT_TFWeaponPDA_Spy_Build )
  209. BEGIN_NETWORK_TABLE( CTFWeaponPDA_Spy_Build, DT_TFWeaponPDA_Spy_Build )
  210. END_NETWORK_TABLE()
  211. BEGIN_PREDICTION_DATA( CTFWeaponPDA_Spy_Build )
  212. END_PREDICTION_DATA()
  213. LINK_ENTITY_TO_CLASS( tf_weapon_pda_spy_build, CTFWeaponPDA_Spy_Build );
  214. PRECACHE_WEAPON_REGISTER( tf_weapon_pda_spy_build );
  215. #ifdef CLIENT_DLL
  216. CHudBaseBuildMenu *CTFWeaponPDA_Spy_Build::GetBuildMenu() const
  217. {
  218. return GET_HUDELEMENT( CHudMenuSpyBuild );
  219. }
  220. #endif // CLIENT_DLL
  221. #endif // STAGING_ONLY
  222. //==============================
  223. void CTFWeaponPDA_Spy::ItemPreFrame( void )
  224. {
  225. BaseClass::ItemPreFrame();
  226. ProcessDisguiseImpulse();
  227. CheckDisguiseTimer();
  228. }
  229. void CTFWeaponPDA_Spy::ItemBusyFrame( void )
  230. {
  231. BaseClass::ItemBusyFrame();
  232. ProcessDisguiseImpulse();
  233. CheckDisguiseTimer();
  234. }
  235. void CTFWeaponPDA_Spy::ItemHolsterFrame( void )
  236. {
  237. BaseClass::ItemHolsterFrame();
  238. ProcessDisguiseImpulse();
  239. CheckDisguiseTimer();
  240. }
  241. void CTFWeaponPDA_Spy::ProcessDisguiseImpulse( void )
  242. {
  243. CTFPlayer *pPlayer = ToTFPlayer( GetPlayerOwner() );
  244. if ( !pPlayer )
  245. return;
  246. pPlayer->m_Shared.ProcessDisguiseImpulse( pPlayer );
  247. }
  248. void CTFWeaponPDA_Spy::CheckDisguiseTimer( void )
  249. {
  250. /*
  251. // Get the player owning the weapon.
  252. CTFPlayer *pPlayer = ToTFPlayer( GetPlayerOwner() );
  253. if ( !pPlayer )
  254. return;
  255. if ( pPlayer->m_Shared.InCond( TF_COND_DISGUISING ) )
  256. {
  257. if ( gpGlobals->curtime > pPlayer->m_Shared.GetDisguiseCompleteTime() )
  258. {
  259. pPlayer->m_Shared.CompleteDisguise();
  260. }
  261. }
  262. */
  263. }
  264. #ifdef CLIENT_DLL
  265. bool CTFWeaponPDA_Spy::Deploy( void )
  266. {
  267. bool bDeploy = BaseClass::Deploy();
  268. if ( bDeploy )
  269. {
  270. // let the spy pda menu know to reset
  271. IGameEvent *event = gameeventmanager->CreateEvent( "spy_pda_reset" );
  272. if ( event )
  273. {
  274. gameeventmanager->FireEventClientSide( event );
  275. }
  276. }
  277. return bDeploy;
  278. }
  279. #endif
  280. bool CTFWeaponPDA_Spy::CanBeSelected( void )
  281. {
  282. CTFPlayer *pOwner = ToTFPlayer( GetOwner() );
  283. if ( pOwner && !pOwner->CanDisguise() )
  284. {
  285. return false;
  286. }
  287. return BaseClass::CanBeSelected();
  288. }
  289. bool CTFWeaponPDA_Spy::VisibleInWeaponSelection( void )
  290. {
  291. if ( !CanBeSelected() )
  292. return false;
  293. return BaseClass::VisibleInWeaponSelection();
  294. }
  295. //-----------------------------------------------------------------------------
  296. // PDA Expansion Slots
  297. void CTFWeaponPDAExpansion_Dispenser::Equip( CBasePlayer *pOwner )
  298. {
  299. #ifdef GAME_DLL
  300. CTFPlayer *pPlayer = ToTFPlayer( pOwner );
  301. if ( pPlayer )
  302. {
  303. // Detonate
  304. CBaseObject *pObject = pPlayer->GetObjectOfType( OBJ_DISPENSER );
  305. if ( pObject )
  306. {
  307. pObject->DetonateObject();
  308. }
  309. }
  310. #endif
  311. BaseClass::Equip( pOwner );
  312. }
  313. //-----------------------------------------------------------------------------
  314. void CTFWeaponPDAExpansion_Dispenser::UnEquip( CBasePlayer *pOwner )
  315. {
  316. #ifdef GAME_DLL
  317. CTFPlayer *pPlayer = ToTFPlayer( pOwner );
  318. if ( pPlayer )
  319. {
  320. // Detonate
  321. CBaseObject *pObject = pPlayer->GetObjectOfType( OBJ_DISPENSER );
  322. if ( pObject )
  323. {
  324. pObject->DetonateObject();
  325. }
  326. }
  327. #endif
  328. BaseClass::UnEquip( pOwner );
  329. }
  330. //-----------------------------------------------------------------------------
  331. void CTFWeaponPDAExpansion_Teleporter::Equip( CBasePlayer *pOwner )
  332. {
  333. #ifdef GAME_DLL
  334. CTFPlayer *pPlayer = ToTFPlayer( pOwner );
  335. if ( pPlayer )
  336. {
  337. // Detonate entrance and exit
  338. CBaseObject *pObject = pPlayer->GetObjectOfType( OBJ_TELEPORTER, 0 );
  339. if ( pObject )
  340. {
  341. pObject->DetonateObject();
  342. }
  343. pObject = pPlayer->GetObjectOfType( OBJ_TELEPORTER, 1 );
  344. if ( pObject )
  345. {
  346. pObject->DetonateObject();
  347. }
  348. pObject = pPlayer->GetObjectOfType( OBJ_TELEPORTER, 2 );
  349. if ( pObject )
  350. {
  351. pObject->DetonateObject();
  352. }
  353. pObject = pPlayer->GetObjectOfType( OBJ_TELEPORTER, 3 );
  354. if ( pObject )
  355. {
  356. pObject->DetonateObject();
  357. }
  358. }
  359. #endif
  360. BaseClass::Equip( pOwner );
  361. }
  362. //-----------------------------------------------------------------------------
  363. void CTFWeaponPDAExpansion_Teleporter::UnEquip( CBasePlayer *pOwner )
  364. {
  365. #ifdef GAME_DLL
  366. CTFPlayer *pPlayer = ToTFPlayer( pOwner );
  367. if ( pPlayer )
  368. {
  369. // Detonate entrance and exit
  370. CBaseObject *pObject = pPlayer->GetObjectOfType( OBJ_TELEPORTER, 0 );
  371. if ( pObject )
  372. {
  373. pObject->DetonateObject();
  374. }
  375. pObject = pPlayer->GetObjectOfType( OBJ_TELEPORTER, 1 );
  376. if ( pObject )
  377. {
  378. pObject->DetonateObject();
  379. }
  380. pObject = pPlayer->GetObjectOfType( OBJ_TELEPORTER, 2 );
  381. if ( pObject )
  382. {
  383. pObject->DetonateObject();
  384. }
  385. pObject = pPlayer->GetObjectOfType( OBJ_TELEPORTER, 3 );
  386. if ( pObject )
  387. {
  388. pObject->DetonateObject();
  389. }
  390. }
  391. #endif
  392. BaseClass::UnEquip( pOwner );
  393. }
  394. //-----------------------------------------------------------------------------
  395. // Purpose: Check if we should show the "destroy" panel
  396. //-----------------------------------------------------------------------------
  397. bool CTFWeaponPDA_Engineer_Destroy::VisibleInWeaponSelection( void )
  398. {
  399. if ( IsConsole()
  400. #ifdef CLIENT_DLL
  401. || ::input->IsSteamControllerActive()
  402. || tf_build_menu_controller_mode.GetBool()
  403. #endif
  404. )
  405. {
  406. return false;
  407. }
  408. return BaseClass::VisibleInWeaponSelection();
  409. }
  410. #ifdef STAGING_ONLY
  411. //-----------------------------------------------------------------------------
  412. // Purpose:
  413. //-----------------------------------------------------------------------------
  414. bool CTFWeaponPDA_Spy_Build::CanDeploy( void )
  415. {
  416. if ( !TFGameRules() || !TFGameRules()->GameModeUsesUpgrades() )
  417. return false;
  418. CTFPlayer *pPlayer = GetTFPlayerOwner();
  419. if ( !pPlayer || !pPlayer->m_Shared.CanBuildSpyTraps() )
  420. return false;
  421. return BaseClass::CanDeploy();
  422. }
  423. //-----------------------------------------------------------------------------
  424. // Purpose: UI Progress
  425. //-----------------------------------------------------------------------------
  426. float CTFWeaponPDA_Spy_Build::GetProgress( void )
  427. {
  428. CTFPlayer *pPlayer = GetTFPlayerOwner();
  429. if ( !pPlayer )
  430. return 0.f;
  431. return pPlayer->m_Shared.GetRageMeter() / 100.0f;
  432. }
  433. //-----------------------------------------------------------------------------
  434. // Purpose:
  435. //-----------------------------------------------------------------------------
  436. bool CTFWeaponPDA_Spy_Build::VisibleInWeaponSelection( void )
  437. {
  438. if ( !BaseClass::VisibleInWeaponSelection() )
  439. return false;
  440. return TFGameRules() && TFGameRules()->GameModeUsesUpgrades();
  441. }
  442. #endif // STAGING_ONLY