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.

86 lines
2.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tf_shareddefs.h"
  8. #include "zombie.h"
  9. #include "zombie_spawner.h"
  10. LINK_ENTITY_TO_CLASS( tf_zombie_spawner, CZombieSpawner );
  11. BEGIN_DATADESC( CZombieSpawner )
  12. DEFINE_KEYFIELD( m_flZombieLifeTime, FIELD_FLOAT, "zombie_lifetime" ),
  13. DEFINE_KEYFIELD( m_nMaxActiveZombies, FIELD_INTEGER, "max_zombies" ),
  14. DEFINE_KEYFIELD( m_bInfiniteZombies, FIELD_BOOLEAN, "infinite_zombies" ),
  15. DEFINE_KEYFIELD( m_nSkeletonType, FIELD_INTEGER, "zombie_type" ),
  16. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  17. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  18. DEFINE_INPUTFUNC( FIELD_INTEGER, "SetMaxActiveZombies", InputSetMaxActiveZombies ),
  19. END_DATADESC()
  20. CZombieSpawner::CZombieSpawner()
  21. {
  22. m_bEnabled = false;
  23. m_bInfiniteZombies = false;
  24. m_nMaxActiveZombies = 1;
  25. m_flZombieLifeTime = 0;
  26. m_nSkeletonType = 0;
  27. m_nSpawned = 0;
  28. }
  29. void CZombieSpawner::Spawn()
  30. {
  31. BaseClass::Spawn();
  32. SetNextThink( gpGlobals->curtime );
  33. }
  34. void CZombieSpawner::Think()
  35. {
  36. m_activeZombies.FindAndFastRemove( NULL );
  37. if ( m_bEnabled && ( ( m_bInfiniteZombies && m_activeZombies.Count() < m_nMaxActiveZombies ) || ( !m_bInfiniteZombies && m_nSpawned < m_nMaxActiveZombies ) ) )
  38. {
  39. CZombie *pZombie = CZombie::SpawnAtPos( GetAbsOrigin(), m_flZombieLifeTime, TF_TEAM_HALLOWEEN, NULL, (CZombie::SkeletonType_t)m_nSkeletonType );
  40. if ( pZombie )
  41. {
  42. m_nSpawned++;
  43. m_activeZombies.AddToTail( pZombie );
  44. }
  45. SetNextThink( gpGlobals->curtime + RandomFloat( 1.5f, 3.f ) );
  46. return;
  47. }
  48. SetNextThink( gpGlobals->curtime + 0.2f );
  49. }
  50. void CZombieSpawner::InputEnable( inputdata_t &inputdata )
  51. {
  52. m_bEnabled = true;
  53. SetNextThink( gpGlobals->curtime );
  54. }
  55. void CZombieSpawner::InputDisable( inputdata_t &inputdata )
  56. {
  57. m_bEnabled = false;
  58. m_nSpawned = 0;
  59. m_activeZombies.Purge();
  60. SetNextThink( gpGlobals->curtime );
  61. }
  62. void CZombieSpawner::InputSetMaxActiveZombies( inputdata_t &inputdata )
  63. {
  64. m_nMaxActiveZombies = inputdata.value.Int();
  65. }