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.

167 lines
4.1 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "foundryhelpers_server.h"
  8. #include "basetempentity.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. //-----------------------------------------------------------------------------
  12. // Purpose: This just marshalls certain FoundryHelpers_ calls to the client.
  13. //-----------------------------------------------------------------------------
  14. class CTEFoundryHelpers : public CBaseTempEntity
  15. {
  16. public:
  17. DECLARE_CLASS( CTEFoundryHelpers, CBaseTempEntity );
  18. DECLARE_SERVERCLASS();
  19. CTEFoundryHelpers( const char *pName ) :
  20. CBaseTempEntity( pName )
  21. {
  22. }
  23. public:
  24. CNetworkVar( int, m_iEntity ); // -1 means turn the effect off for all entities.
  25. };
  26. IMPLEMENT_SERVERCLASS_ST( CTEFoundryHelpers, DT_TEFoundryHelpers )
  27. SendPropInt( SENDINFO(m_iEntity), 32, 0 ),
  28. END_SEND_TABLE()
  29. // Singleton to fire TEMuzzleFlash objects
  30. static CTEFoundryHelpers g_TEFoundryHelpers( "FoundryHelpers" );
  31. void FoundryHelpers_ClearEntityHighlightEffects()
  32. {
  33. g_TEFoundryHelpers.m_iEntity = -1;
  34. CBroadcastRecipientFilter filter;
  35. g_TEFoundryHelpers.Create( filter, 0 );
  36. }
  37. void FoundryHelpers_AddEntityHighlightEffect( CBaseEntity *pEnt )
  38. {
  39. g_TEFoundryHelpers.m_iEntity = pEnt->entindex();
  40. CBroadcastRecipientFilter filter;
  41. g_TEFoundryHelpers.Create( filter, 0 );
  42. }
  43. CBasePlayer* CheckInFoundryMode()
  44. {
  45. if ( !serverfoundry )
  46. {
  47. Warning( "Not in Foundry mode.\n" );
  48. return NULL;
  49. }
  50. return UTIL_GetListenServerHost();
  51. }
  52. void GetCrosshairOrNamedEntities( const CCommand &args, CUtlVector<CBaseEntity*> &entities )
  53. {
  54. if ( args.ArgC() < 2 )
  55. {
  56. CBasePlayer *pPlayer = UTIL_GetCommandClient();
  57. trace_t tr;
  58. Vector forward;
  59. pPlayer->EyeVectors( &forward );
  60. UTIL_TraceLine(pPlayer->EyePosition(), pPlayer->EyePosition() + forward * MAX_COORD_RANGE,
  61. MASK_SHOT_HULL|CONTENTS_GRATE|CONTENTS_DEBRIS, pPlayer, COLLISION_GROUP_NONE, &tr );
  62. if ( tr.DidHit() && !tr.DidHitWorld() )
  63. {
  64. entities.AddToTail( tr.m_pEnt );
  65. }
  66. }
  67. else
  68. {
  69. CBaseEntity *pEnt = NULL;
  70. while ((pEnt = gEntList.FindEntityGeneric( pEnt, args[1] ) ) != NULL)
  71. {
  72. entities.AddToTail( pEnt );
  73. }
  74. }
  75. }
  76. CON_COMMAND_F( foundry_update_entity, "Updates the entity's position/angles when in edit mode", FCVAR_CHEAT )
  77. {
  78. if ( !CheckInFoundryMode() )
  79. return;
  80. CUtlVector<CBaseEntity*> entities;
  81. GetCrosshairOrNamedEntities( args, entities );
  82. for ( int i=0; i < entities.Count(); i++ )
  83. {
  84. CBaseEntity *pEnt = entities[i];
  85. serverfoundry->MoveEntityTo( pEnt->GetHammerID(), pEnt->GetAbsOrigin(), pEnt->GetAbsAngles() );
  86. }
  87. }
  88. CON_COMMAND_F( foundry_sync_hammer_view, "Move Hammer's 3D view to the same position as the engine's 3D view.", FCVAR_CHEAT )
  89. {
  90. CBasePlayer *pPlayer = CheckInFoundryMode();
  91. if ( !pPlayer )
  92. return;
  93. Vector vPos = pPlayer->EyePosition();
  94. QAngle vAngles = pPlayer->pl.v_angle;
  95. serverfoundry->MoveHammerViewTo( vPos, vAngles );
  96. }
  97. CON_COMMAND_F( foundry_engine_get_mouse_control, "Give the engine control of the mouse.", FCVAR_CHEAT )
  98. {
  99. if ( !CheckInFoundryMode() )
  100. return;
  101. serverfoundry->EngineGetMouseControl();
  102. }
  103. CON_COMMAND_F( foundry_engine_release_mouse_control, "Give the control of the mouse back to Hammer.", FCVAR_CHEAT )
  104. {
  105. if ( !CheckInFoundryMode() )
  106. return;
  107. serverfoundry->EngineReleaseMouseControl();
  108. }
  109. CON_COMMAND_F( foundry_select_entity, "Select the entity under the crosshair or select entities with the specified name.", FCVAR_CHEAT )
  110. {
  111. CBasePlayer *pPlayer = CheckInFoundryMode();
  112. if ( !pPlayer )
  113. return;
  114. CUtlVector<CBaseEntity*> entities;
  115. GetCrosshairOrNamedEntities( args, entities );
  116. CUtlVector<int> hammerIDs;
  117. for ( int i=0; i < entities.Count(); i++ )
  118. {
  119. CBaseEntity *pEnt = entities[i];
  120. hammerIDs.AddToTail( pEnt->GetHammerID() );
  121. }
  122. if ( hammerIDs.Count() == 0 )
  123. {
  124. Vector vPos = pPlayer->EyePosition();
  125. QAngle vAngles = pPlayer->pl.v_angle;
  126. serverfoundry->SelectionClickInCenterOfView( vPos, vAngles );
  127. }
  128. else
  129. {
  130. serverfoundry->SelectEntities( hammerIDs.Base(), hammerIDs.Count() );
  131. }
  132. }