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.

112 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "ar2_explosion.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. #define AR2EXPLOSION_ENTITYNAME "ar2explosion"
  11. IMPLEMENT_SERVERCLASS_ST(AR2Explosion, DT_AR2Explosion)
  12. SendPropString( SENDINFO( m_szMaterialName ) ),
  13. END_SEND_TABLE()
  14. LINK_ENTITY_TO_CLASS(ar2explosion, AR2Explosion);
  15. //---------------------------------------------------------
  16. // Save/Restore
  17. //---------------------------------------------------------
  18. BEGIN_DATADESC( AR2Explosion )
  19. DEFINE_AUTO_ARRAY( m_szMaterialName, FIELD_CHARACTER ),
  20. END_DATADESC()
  21. AR2Explosion* AR2Explosion::CreateAR2Explosion(const Vector &pos)
  22. {
  23. CBaseEntity *pEnt = CreateEntityByName(AR2EXPLOSION_ENTITYNAME);
  24. if(pEnt)
  25. {
  26. AR2Explosion *pEffect = dynamic_cast<AR2Explosion*>(pEnt);
  27. if(pEffect && pEffect->edict())
  28. {
  29. pEffect->SetLocalOrigin( pos );
  30. pEffect->Activate();
  31. return pEffect;
  32. }
  33. else
  34. {
  35. UTIL_Remove(pEnt);
  36. }
  37. }
  38. return NULL;
  39. }
  40. //-----------------------------------------------------------------------------
  41. // A lightweight entity for level-designer placed AR2 explosions.
  42. //-----------------------------------------------------------------------------
  43. class CEnvAR2Explosion : public CPointEntity
  44. {
  45. public:
  46. DECLARE_CLASS( CEnvAR2Explosion, CPointEntity );
  47. void Spawn( void );
  48. // Input handlers
  49. void InputExplode( inputdata_t &inputdata );
  50. DECLARE_DATADESC();
  51. private:
  52. string_t m_iszMaterialName;
  53. };
  54. BEGIN_DATADESC( CEnvAR2Explosion )
  55. DEFINE_INPUTFUNC(FIELD_VOID, "Explode", InputExplode),
  56. DEFINE_KEYFIELD(m_iszMaterialName, FIELD_STRING, "material"),
  57. END_DATADESC()
  58. LINK_ENTITY_TO_CLASS( env_ar2explosion, CEnvAR2Explosion );
  59. //-----------------------------------------------------------------------------
  60. // Purpose: So you can see where this function begins and the last one ends.
  61. //-----------------------------------------------------------------------------
  62. void CEnvAR2Explosion::Spawn( void )
  63. {
  64. Precache();
  65. SetSolid( SOLID_NONE );
  66. AddEffects( EF_NODRAW );
  67. SetMoveType( MOVETYPE_NONE );
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose: Creates the explosion effect.
  71. //-----------------------------------------------------------------------------
  72. void CEnvAR2Explosion::InputExplode( inputdata_t &inputdata )
  73. {
  74. AR2Explosion *pExplosion = AR2Explosion::CreateAR2Explosion(GetAbsOrigin());
  75. if (pExplosion)
  76. {
  77. pExplosion->SetLifetime( 10 );
  78. if (m_iszMaterialName != NULL_STRING)
  79. {
  80. pExplosion->SetMaterialName(STRING(m_iszMaterialName));
  81. }
  82. }
  83. }