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.

176 lines
5.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "tf/tf_shareddefs.h"
  8. #include "entity_tfstart.h"
  9. #include "team_control_point.h"
  10. #include "team_control_point_round.h"
  11. #include "team_objectiveresource.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //=============================================================================
  15. //
  16. // CTFTeamSpawn tables.
  17. //
  18. BEGIN_DATADESC( CTFTeamSpawn )
  19. DEFINE_KEYFIELD( m_bDisabled, FIELD_BOOLEAN, "StartDisabled" ),
  20. DEFINE_KEYFIELD( m_iszControlPointName, FIELD_STRING, "controlpoint" ),
  21. DEFINE_KEYFIELD( m_iszRoundBlueSpawn, FIELD_STRING, "round_bluespawn" ),
  22. DEFINE_KEYFIELD( m_iszRoundRedSpawn, FIELD_STRING, "round_redspawn" ),
  23. DEFINE_KEYFIELD( m_nSpawnMode, FIELD_INTEGER, "SpawnMode" ),
  24. DEFINE_KEYFIELD( m_nMatchSummaryType, FIELD_INTEGER, "MatchSummary" ),
  25. // Inputs.
  26. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  27. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  28. DEFINE_INPUTFUNC( FIELD_VOID, "RoundSpawn", InputRoundSpawn ),
  29. // Outputs.
  30. END_DATADESC()
  31. IMPLEMENT_AUTO_LIST( ITFTeamSpawnAutoList );
  32. LINK_ENTITY_TO_CLASS( info_player_teamspawn, CTFTeamSpawn );
  33. //-----------------------------------------------------------------------------
  34. // Purpose: Constructor.
  35. //-----------------------------------------------------------------------------
  36. CTFTeamSpawn::CTFTeamSpawn()
  37. {
  38. m_bDisabled = false;
  39. m_nMatchSummaryType = PlayerTeamSpawn_MatchSummary_None;
  40. m_bAlreadyUsedForMatchSummary = false;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. //-----------------------------------------------------------------------------
  45. void CTFTeamSpawn::Activate( void )
  46. {
  47. BaseClass::Activate();
  48. Vector mins = VEC_HULL_MIN;
  49. Vector maxs = VEC_HULL_MAX;
  50. trace_t trace;
  51. UTIL_TraceHull( GetAbsOrigin(), GetAbsOrigin(), mins, maxs, MASK_PLAYERSOLID, NULL, COLLISION_GROUP_PLAYER_MOVEMENT, &trace );
  52. bool bClear = ( trace.fraction == 1 && trace.allsolid != 1 && (trace.startsolid != 1) );
  53. if ( !bClear )
  54. {
  55. DevMsg("Spawnpoint at (%.2f %.2f %.2f) is not clear.\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z );
  56. // m_debugOverlays |= OVERLAY_TEXT_BIT;
  57. }
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Purpose:
  61. //-----------------------------------------------------------------------------
  62. void CTFTeamSpawn::InputEnable( inputdata_t &inputdata )
  63. {
  64. m_bDisabled = false;
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. void CTFTeamSpawn::InputDisable( inputdata_t &inputdata )
  70. {
  71. m_bDisabled = true;
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose: Draw any debug text overlays
  75. // Input :
  76. // Output : Current text offset from the top
  77. //-----------------------------------------------------------------------------
  78. int CTFTeamSpawn::DrawDebugTextOverlays(void)
  79. {
  80. int text_offset = BaseClass::DrawDebugTextOverlays();
  81. if (m_debugOverlays & OVERLAY_TEXT_BIT)
  82. {
  83. char tempstr[512];
  84. Q_snprintf(tempstr,sizeof(tempstr),"TeamNumber: %d", GetTeamNumber() );
  85. EntityText(text_offset,tempstr,0);
  86. text_offset++;
  87. color32 teamcolor = g_aTeamColors[ GetTeamNumber() ];
  88. teamcolor.a = 0;
  89. if ( m_bDisabled )
  90. {
  91. Q_snprintf(tempstr,sizeof(tempstr),"DISABLED" );
  92. EntityText(text_offset,tempstr,0);
  93. text_offset++;
  94. teamcolor.a = 255;
  95. }
  96. // Make sure it's empty
  97. Vector mins = VEC_HULL_MIN;
  98. Vector maxs = VEC_HULL_MAX;
  99. Vector vTestMins = GetAbsOrigin() + mins;
  100. Vector vTestMaxs = GetAbsOrigin() + maxs;
  101. // First test the starting origin.
  102. if ( UTIL_IsSpaceEmpty( NULL, vTestMins, vTestMaxs ) )
  103. {
  104. NDebugOverlay::Box( GetAbsOrigin(), mins, maxs, teamcolor.r, teamcolor.g, teamcolor.b, teamcolor.a, 0.1);
  105. }
  106. else
  107. {
  108. NDebugOverlay::Box( GetAbsOrigin(), mins, maxs, 0,255,0, 0, 0.1);
  109. }
  110. if ( m_hControlPoint )
  111. {
  112. NDebugOverlay::Line( GetAbsOrigin(), m_hControlPoint->GetAbsOrigin(), teamcolor.r, teamcolor.g, teamcolor.b, false, 0.1 );
  113. }
  114. }
  115. return text_offset;
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Purpose:
  119. //-----------------------------------------------------------------------------
  120. void CTFTeamSpawn::InputRoundSpawn( inputdata_t &input )
  121. {
  122. if ( m_iszControlPointName != NULL_STRING )
  123. {
  124. // We need to re-find our control point, because they're recreated over round restarts
  125. m_hControlPoint = dynamic_cast<CTeamControlPoint*>( gEntList.FindEntityByName( NULL, m_iszControlPointName ) );
  126. if ( !m_hControlPoint )
  127. {
  128. Warning("%s failed to find control point named '%s'\n", GetClassname(), STRING(m_iszControlPointName) );
  129. }
  130. }
  131. if ( m_iszRoundBlueSpawn != NULL_STRING )
  132. {
  133. // We need to re-find our control point round, because they're recreated over round restarts
  134. m_hRoundBlueSpawn = dynamic_cast<CTeamControlPointRound*>( gEntList.FindEntityByName( NULL, m_iszRoundBlueSpawn ) );
  135. if ( !m_hRoundBlueSpawn )
  136. {
  137. Warning("%s failed to find control point round named '%s'\n", GetClassname(), STRING(m_iszRoundBlueSpawn) );
  138. }
  139. }
  140. if ( m_iszRoundRedSpawn != NULL_STRING )
  141. {
  142. // We need to re-find our control point round, because they're recreated over round restarts
  143. m_hRoundRedSpawn = dynamic_cast<CTeamControlPointRound*>( gEntList.FindEntityByName( NULL, m_iszRoundRedSpawn ) );
  144. if ( !m_hRoundRedSpawn )
  145. {
  146. Warning("%s failed to find control point round named '%s'\n", GetClassname(), STRING(m_iszRoundRedSpawn) );
  147. }
  148. }
  149. }