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.

204 lines
4.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tf_obj_catapult.h"
  8. #include "tf_player.h"
  9. #include "mathlib/mathlib.h"
  10. #include "in_buttons.h"
  11. #ifdef STAGING_ONLY
  12. #define CATAPULT_THINK_CONTEXT "CatapultContext"
  13. #define CATAPULT_MODEL "models/buildables/teleporter_light.mdl"
  14. const Vector CATAPULT_MINS = Vector( -24, -24, 0 );
  15. const Vector CATAPULT_MAXS = Vector( 24, 24, 12 );
  16. ConVar tf_engineer_catapult_force( "tf_engineer_catapult_force", "1000" );
  17. ConVar tf_engineer_catapult_delay( "tf_engineer_catapult_delay", "0" );
  18. //IMPLEMENT_SERVERCLASS_ST( CObjectCatapult, DT_ObjectCatapult )
  19. //END_SEND_TABLE()
  20. BEGIN_DATADESC( CObjectCatapult )
  21. DEFINE_THINKFUNC( CatapultThink ),
  22. END_DATADESC()
  23. PRECACHE_REGISTER( obj_catapult );
  24. LINK_ENTITY_TO_CLASS( obj_catapult, CObjectCatapult );
  25. CObjectCatapult::CObjectCatapult()
  26. {
  27. int iHealth = GetMaxHealthForCurrentLevel();
  28. SetMaxHealth( iHealth );
  29. SetHealth( iHealth );
  30. UseClientSideAnimation();
  31. SetType( OBJ_CATAPULT );
  32. }
  33. void CObjectCatapult::Spawn()
  34. {
  35. SetSolid( SOLID_BBOX );
  36. SetModel( CATAPULT_MODEL );
  37. int nBodyDir = FindBodygroupByName( "teleporter_direction" );
  38. if ( nBodyDir != -1 )
  39. {
  40. SetBodygroup( nBodyDir, 0 );
  41. }
  42. UTIL_SetSize( this, CATAPULT_MINS, CATAPULT_MAXS );
  43. BaseClass::Spawn();
  44. // HACK: Spin this building 180. The temp model is backwards
  45. RotateBuildAngles();
  46. RotateBuildAngles();
  47. UpdateDesiredBuildRotation( 5.f );
  48. }
  49. void CObjectCatapult::Precache()
  50. {
  51. BaseClass::Precache();
  52. PrecacheModel( CATAPULT_MODEL );
  53. }
  54. void CObjectCatapult::CatapultThink()
  55. {
  56. if ( IsCarried() )
  57. return;
  58. SetContextThink( &CObjectCatapult::CatapultThink, gpGlobals->curtime + 0.1f, CATAPULT_THINK_CONTEXT );
  59. const float flJumpDelay = tf_engineer_catapult_delay.GetFloat();
  60. for ( int i=0; i<m_jumpers.Count(); )
  61. {
  62. const Jumper_t& jumper = m_jumpers[i];
  63. // Cleanup
  64. if( !jumper.m_hJumper )
  65. {
  66. m_jumpers.Remove(i);
  67. continue;
  68. }
  69. CTFPlayer *pPlayer = ToTFPlayer( jumper.m_hJumper );
  70. if ( !pPlayer )
  71. {
  72. m_jumpers.Remove( i );
  73. continue;
  74. }
  75. //pPlayer->m_nButtons |= IN_DUCK;
  76. if ( jumper.flTouchTime + flJumpDelay < gpGlobals->curtime || ( pPlayer->m_nButtons & IN_DUCK ) )
  77. {
  78. Launch( jumper.m_hJumper );
  79. m_jumpers.Remove(i);
  80. }
  81. else
  82. {
  83. ++i;
  84. }
  85. }
  86. }
  87. void CObjectCatapult::OnGoActive()
  88. {
  89. BaseClass::OnGoActive();
  90. SetContextThink( &CObjectCatapult::CatapultThink, gpGlobals->curtime + 0.1, CATAPULT_THINK_CONTEXT );
  91. int nBodyDir = FindBodygroupByName( "teleporter_direction" );
  92. if ( nBodyDir != -1 )
  93. {
  94. SetBodygroup( nBodyDir, 1 );
  95. }
  96. }
  97. bool CObjectCatapult::IsPlacementPosValid( void )
  98. {
  99. bool bResult = BaseClass::IsPlacementPosValid();
  100. if ( !bResult )
  101. {
  102. return false;
  103. }
  104. // m_vecBuildOrigin is the proposed build origin
  105. // start above the teleporter position
  106. Vector vecTestPos = m_vecBuildOrigin;
  107. vecTestPos.z += CATAPULT_MAXS.z;
  108. // make sure we can fit a player on top in this pos
  109. trace_t tr;
  110. UTIL_TraceHull( vecTestPos, vecTestPos, VEC_HULL_MIN, VEC_HULL_MAX, MASK_SOLID | CONTENTS_PLAYERCLIP, this, COLLISION_GROUP_PLAYER_MOVEMENT, &tr );
  111. return ( tr.fraction >= 1.0 );
  112. }
  113. void CObjectCatapult::StartTouch( CBaseEntity *pOther )
  114. {
  115. BaseClass::StartTouch( pOther );
  116. if ( pOther->IsPlayer() )
  117. {
  118. int index = m_jumpers.AddToTail();
  119. Jumper_t& jumper = m_jumpers[index];
  120. jumper.m_hJumper = pOther;
  121. jumper.flTouchTime = gpGlobals->curtime;
  122. }
  123. }
  124. void CObjectCatapult::EndTouch( CBaseEntity *pOther )
  125. {
  126. BaseClass::EndTouch( pOther );
  127. for ( int i=0; i<m_jumpers.Count(); ++i )
  128. {
  129. if ( m_jumpers[i].m_hJumper == pOther )
  130. {
  131. m_jumpers.Remove(i);
  132. return;
  133. }
  134. }
  135. }
  136. void CObjectCatapult::Launch( CBaseEntity* pEnt )
  137. {
  138. CTFPlayer *pPlayer = ToTFPlayer( pEnt );
  139. if ( !pPlayer )
  140. return;
  141. //Vector vForward;
  142. //QAngle qEyeAngle = pEnt->EyeAngles();
  143. //AngleVectors( pEnt->EyeAngles(), &vForward );
  144. //vForward.NormalizeInPlace();
  145. //vForward.z += 2.0f;
  146. //vForward.NormalizeInPlace();
  147. //pPlayer->ApplyAirBlastImpulse( tf_engineer_catapult_force.GetFloat() * vForward );
  148. pPlayer->m_Shared.AddCond( TF_COND_SPEED_BOOST, 5.0f );
  149. }
  150. #endif // STAGING_ONLY