SHARE
TWEET

Untitled

a guest May 19th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.         © 2009 Ham and Jam Team
  3.         ============================================================
  4.         Author: Stephen Swires
  5.         Purpose: Team clip to block off unwanted enemies
  6. */
  7.  
  8. #include "cbase.h"
  9.  
  10. #ifndef CLIENT_DLL
  11. #include "haj_player.h"
  12. #endif
  13.  
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16.  
  17. enum {
  18.     TEAMCLIP_ALLIES = 1,
  19.     TEAMCLIP_AXIS
  20. };
  21.  
  22. #ifdef CLIENT_DLL
  23. #define CTeamClip C_TeamClip
  24. #endif
  25.  
  26. class CTeamClip : public CBaseEntity
  27. {
  28. public:
  29.     DECLARE_CLASS( CTeamClip, CBaseEntity );
  30.     DECLARE_DATADESC();
  31.     DECLARE_NETWORKCLASS();
  32.  
  33.     CTeamClip();
  34.  
  35.     void Spawn();
  36.     bool ShouldCollide( int collisionGroup, int contentsMask ) const;
  37.  
  38. #ifndef CLIENT_DLL
  39.     void StartTouch( CBaseEntity *pOther );
  40.  
  41.     void InputDeactivate( inputdata_t &inputdata );
  42.     void InputActivate( inputdata_t &inputdata );
  43.     void InputSetBlockedTeam( inputdata_t &inputdata );
  44.  
  45. protected:
  46.     COutputEvent m_OnBlockedTouch;
  47. #endif
  48.  
  49. private:
  50.     CNetworkVar( int, m_iTeamContents );
  51.     CNetworkVar( bool, m_bEnabled );
  52. };
  53.  
  54. LINK_ENTITY_TO_CLASS( func_teamclip, CTeamClip );
  55.  
  56. // networking, so the client can predict us
  57. IMPLEMENT_NETWORKCLASS_ALIASED( TeamClip, DT_TeamClip )
  58.  
  59. BEGIN_NETWORK_TABLE( CTeamClip, DT_TeamClip )
  60. #ifdef CLIENT_DLL
  61.     RecvPropInt( RECVINFO( m_iTeamContents ) ),
  62.     RecvPropBool( RECVINFO( m_bEnabled ) ),
  63. #else
  64.     SendPropInt( SENDINFO( m_iTeamContents ), 8, SPROP_UNSIGNED ),
  65.     SendPropBool( SENDINFO( m_bEnabled ) ),
  66. #endif
  67. END_NETWORK_TABLE()
  68.  
  69. // keyvalues :)
  70. BEGIN_DATADESC( CTeamClip )
  71. #ifndef CLIENT_DLL
  72.     DEFINE_KEYFIELD( m_iTeamContents, FIELD_INTEGER, "blockedteam" ),
  73.     DEFINE_KEYFIELD( m_bEnabled, FIELD_BOOLEAN, "StartActivated" ),
  74.  
  75.     DEFINE_INPUTFUNC( FIELD_VOID, "Deactivate", InputDeactivate ),
  76.     DEFINE_INPUTFUNC( FIELD_VOID, "Activate", InputActivate ),
  77.     DEFINE_INPUTFUNC( FIELD_INTEGER, "SetBlockedTeam", InputSetBlockedTeam ),
  78.  
  79.     DEFINE_OUTPUT( m_OnBlockedTouch, "OnBlockedTouch"),
  80. #endif
  81. END_DATADESC()
  82.  
  83.  
  84. CTeamClip::CTeamClip()
  85. {
  86.     m_bEnabled = true;
  87. }
  88.  
  89. void CTeamClip::Spawn()
  90. {
  91.     BaseClass::Spawn();
  92.  
  93.     SetSolid( SOLID_BBOX ); //make it solid
  94.     SetCollisionGroup( COLLISION_GROUP_TEAMCLIP ); // special col group
  95.  
  96.     const char* szModelName = STRING(GetModelName());
  97.     SetModel(szModelName);
  98.  
  99.     SetRenderMode(kRenderNone);
  100. }
  101.  
  102. #ifndef CLIENT_DLL
  103. void CTeamClip::StartTouch( CBaseEntity *pOther )
  104. {
  105.     if( pOther->IsPlayer() )
  106.     {
  107.         CHajPlayer *pPlayer = ToHajPlayer( pOther );
  108.         DevMsg( "Team clip blocking team %d touched by player %s on team %d\n", m_iTeamContents+1, pPlayer->GetPlayerName(), pPlayer->GetTeamNumber() );
  109.  
  110.         if( pPlayer->GetTeamNumber() == ( m_iTeamContents + 1 ) )
  111.         {
  112.             pPlayer->SendHint( "HaJ_Tip_NoEntry" );
  113.             m_OnBlockedTouch.FireOutput( this, pPlayer );
  114.         }
  115.     }
  116.  
  117.     BaseClass::StartTouch( pOther );
  118. }
  119.  
  120. void CTeamClip::InputDeactivate( inputdata_t &inputdata )
  121. {
  122.     m_bEnabled = false;
  123. }
  124.  
  125. void CTeamClip::InputActivate( inputdata_t &inputdata )
  126. {
  127.     m_bEnabled = true;
  128. }
  129.  
  130. void CTeamClip::InputSetBlockedTeam( inputdata_t &inputdata )
  131. {
  132.     m_iTeamContents = inputdata.value.Int();
  133. }
  134. #endif
  135.  
  136. bool CTeamClip::ShouldCollide( int collisionGroup, int contentsMask ) const
  137. {
  138.     if( !m_bEnabled )
  139.         return false;
  140.  
  141.     if( collisionGroup == COLLISION_GROUP_NONE )
  142.         return false;
  143.  
  144.     if ( collisionGroup == COLLISION_GROUP_PLAYER_MOVEMENT || collisionGroup == COLLISION_GROUP_PLAYER )
  145.     {
  146.         if( !( contentsMask & CONTENTS_TEAM1 ) && !( contentsMask & CONTENTS_TEAM2 ) )
  147.             return false;
  148.        
  149.         if( ( contentsMask & CONTENTS_TEAM1 ) && m_iTeamContents == TEAMCLIP_ALLIES )
  150.             return true;
  151.         else if( ( contentsMask & CONTENTS_TEAM2 ) && m_iTeamContents == TEAMCLIP_AXIS )
  152.             return true;
  153.         if ( ( contentsMask & CONTENTS_TEAM1 ) && m_iTeamContents == TEAMCLIP_AXIS )
  154.             return false;
  155.         else if( ( contentsMask & CONTENTS_TEAM2 ) && m_iTeamContents == TEAMCLIP_ALLIES )
  156.             return false;
  157.     }
  158.  
  159.     return BaseClass::ShouldCollide( collisionGroup, contentsMask );
  160. }
RAW Paste Data
Want to get better at C++?
Learn to code C++ in 2017
Top