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.

144 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "dod_player.h"
  8. #include "dod_bombtarget.h"
  9. #include "triggers.h"
  10. class CDODBombDispenserMapIcon;
  11. class CDODBombDispenser : public CBaseTrigger
  12. {
  13. public:
  14. DECLARE_CLASS( CDODBombDispenser, CBaseTrigger );
  15. DECLARE_DATADESC();
  16. virtual void Spawn( void );
  17. void EXPORT Touch( CBaseEntity *pOther );
  18. bool IsActive( void ) { return !m_bDisabled; }
  19. private:
  20. void InputEnable( inputdata_t &inputdata );
  21. void InputDisable( inputdata_t &inputdata );
  22. // Which team to give bombs to. TEAM_UNASSIGNED gives to both
  23. int m_iDispenseToTeam;
  24. // Is this area giving out bombs?
  25. bool m_bActive;
  26. };
  27. BEGIN_DATADESC(CDODBombDispenser)
  28. // Touch functions
  29. DEFINE_FUNCTION( Touch ),
  30. // Inputs
  31. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  32. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  33. DEFINE_KEYFIELD( m_iDispenseToTeam, FIELD_INTEGER, "dispense_team" ),
  34. DEFINE_KEYFIELD( m_bDisabled, FIELD_BOOLEAN, "StartDisabled" ),
  35. END_DATADESC();
  36. LINK_ENTITY_TO_CLASS( dod_bomb_dispenser, CDODBombDispenser );
  37. void CDODBombDispenser::Spawn( void )
  38. {
  39. BaseClass::Spawn();
  40. InitTrigger();
  41. SetTouch( &CDODBombDispenser::Touch );
  42. m_bDisabled = false;
  43. // make our map icon entity
  44. #ifdef DBGFLAG_ASSERT
  45. CBaseEntity *pIcon =
  46. #endif
  47. CBaseEntity::Create( "dod_bomb_dispenser_icon", WorldSpaceCenter(), GetAbsAngles(), this );
  48. Assert( pIcon );
  49. }
  50. void CDODBombDispenser::Touch( CBaseEntity *pOther )
  51. {
  52. if ( m_bDisabled )
  53. return;
  54. if( !pOther->IsPlayer() )
  55. return;
  56. if( !pOther->IsAlive() )
  57. return;
  58. if ( m_iDispenseToTeam != TEAM_UNASSIGNED && pOther->GetTeamNumber() != m_iDispenseToTeam )
  59. return;
  60. CDODPlayer *pPlayer = ToDODPlayer( pOther );
  61. pPlayer->HintMessage( HINT_BOMB_PICKUP );
  62. switch( pPlayer->GetTeamNumber() )
  63. {
  64. case TEAM_ALLIES:
  65. case TEAM_AXIS:
  66. {
  67. if ( pPlayer->Weapon_OwnsThisType( "weapon_basebomb" ) == NULL )
  68. {
  69. pPlayer->GiveNamedItem( "weapon_basebomb" );
  70. CPASFilter filter( pPlayer->WorldSpaceCenter() );
  71. pPlayer->EmitSound( filter, pPlayer->entindex(), "Weapon_C4.PickUp" );
  72. }
  73. }
  74. break;
  75. default:
  76. break;
  77. }
  78. }
  79. void CDODBombDispenser::InputEnable( inputdata_t &inputdata )
  80. {
  81. m_bDisabled = false;
  82. }
  83. void CDODBombDispenser::InputDisable( inputdata_t &inputdata )
  84. {
  85. m_bDisabled = true;
  86. }
  87. class CDODBombDispenserMapIcon : public CBaseEntity
  88. {
  89. public:
  90. DECLARE_CLASS( CDODBombDispenserMapIcon, CBaseEntity );
  91. DECLARE_NETWORKCLASS();
  92. virtual int UpdateTransmitState( void )
  93. {
  94. if ( (( CDODBombDispenser * )GetOwnerEntity())->IsActive() )
  95. {
  96. return SetTransmitState( FL_EDICT_ALWAYS );
  97. }
  98. else
  99. {
  100. return SetTransmitState( FL_EDICT_DONTSEND );
  101. }
  102. }
  103. };
  104. IMPLEMENT_SERVERCLASS_ST(CDODBombDispenserMapIcon, DT_DODBombDispenserMapIcon)
  105. END_SEND_TABLE()
  106. LINK_ENTITY_TO_CLASS( dod_bomb_dispenser_icon, CDODBombDispenserMapIcon );