Counter Strike : Global Offensive Source Code
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.

133 lines
4.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Team spawnpoint handling
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "entitylist.h"
  9. #include "entityoutput.h"
  10. #include "player.h"
  11. #include "eventqueue.h"
  12. #include "gamerules.h"
  13. #include "team_spawnpoint.h"
  14. #include "team.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. LINK_ENTITY_TO_CLASS( info_player_teamspawn, CTeamSpawnPoint );
  18. BEGIN_DATADESC( CTeamSpawnPoint )
  19. // keys
  20. DEFINE_KEYFIELD( m_iDisabled, FIELD_INTEGER, "StartDisabled" ),
  21. // input functions
  22. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  23. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  24. // outputs
  25. DEFINE_OUTPUT( m_OnPlayerSpawn, "OnPlayerSpawn" ),
  26. END_DATADESC()
  27. //-----------------------------------------------------------------------------
  28. // Purpose: Attach this spawnpoint to it's team
  29. //-----------------------------------------------------------------------------
  30. void CTeamSpawnPoint::Activate( void )
  31. {
  32. BaseClass::Activate();
  33. if ( GetTeamNumber() > 0 && GetTeamNumber() <= MAX_TEAMS )
  34. {
  35. GetGlobalTeam( GetTeamNumber() )->AddSpawnpoint( this );
  36. }
  37. else
  38. {
  39. Warning( "info_player_teamspawn with invalid team number: %d\n", GetTeamNumber() );
  40. UTIL_Remove( this );
  41. }
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Is this spawnpoint ready for a player to spawn in?
  45. //-----------------------------------------------------------------------------
  46. bool CTeamSpawnPoint::IsValid( CBasePlayer *pPlayer )
  47. {
  48. CBaseEntity *ent = NULL;
  49. for ( CEntitySphereQuery sphere( GetAbsOrigin(), 128 ); ( ent = sphere.GetCurrentEntity() ) != NULL; sphere.NextEntity() )
  50. {
  51. // if ent is a client, don't spawn on 'em
  52. CBaseEntity *plent = ent;
  53. if ( plent && plent->IsPlayer() && plent != pPlayer )
  54. return false;
  55. }
  56. return true;
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose:
  60. //-----------------------------------------------------------------------------
  61. void CTeamSpawnPoint::InputEnable( inputdata_t &inputdata )
  62. {
  63. m_iDisabled = FALSE;
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose:
  67. //-----------------------------------------------------------------------------
  68. void CTeamSpawnPoint::InputDisable( inputdata_t &inputdata )
  69. {
  70. m_iDisabled = TRUE;
  71. }
  72. //===========================================================================================================
  73. // VEHICLE SPAWNPOINTS
  74. //===========================================================================================================
  75. LINK_ENTITY_TO_CLASS( info_vehicle_groundspawn, CTeamVehicleSpawnPoint );
  76. BEGIN_DATADESC( CTeamVehicleSpawnPoint )
  77. // outputs
  78. DEFINE_OUTPUT( m_OnVehicleSpawn, "OnVehicleSpawn" ),
  79. END_DATADESC()
  80. //-----------------------------------------------------------------------------
  81. // Purpose: Is this spawnpoint ready for a vehicle to spawn in?
  82. //-----------------------------------------------------------------------------
  83. bool CTeamVehicleSpawnPoint::IsValid( void )
  84. {
  85. CBaseEntity *ent = NULL;
  86. for ( CEntitySphereQuery sphere( GetAbsOrigin(), 128 ); ( ent = sphere.GetCurrentEntity() ) != NULL; sphere.NextEntity() )
  87. {
  88. // if ent is a client, don't spawn on 'em
  89. CBaseEntity *plent = ent;
  90. if ( plent && plent->IsPlayer() )
  91. return false;
  92. }
  93. return true;
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Attach this spawnpoint to it's team
  97. //-----------------------------------------------------------------------------
  98. void CTeamVehicleSpawnPoint::Activate( void )
  99. {
  100. BaseClass::Activate();
  101. if ( GetTeamNumber() > 0 && GetTeamNumber() <= MAX_TEAMS )
  102. {
  103. // Don't add vehicle spawnpoints to the team for now
  104. //GetGlobalTeam( GetTeamNumber() )->AddSpawnpoint( this );
  105. }
  106. else
  107. {
  108. Warning( "info_vehicle_groundspawn with invalid team number: %d\n", GetTeamNumber() );
  109. UTIL_Remove( this );
  110. }
  111. }