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.

160 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Client side antlion guard. Used to create dlight for the cave guard.
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "c_ai_basenpc.h"
  8. #include "dlight.h"
  9. #include "iefx.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. #if HL2_EPISODIC
  13. // When enabled, add code to have the antlion bleed profusely as it is badly injured.
  14. #define ANTLIONGUARD_BLOOD_EFFECTS 2
  15. #endif
  16. class C_NPC_AntlionGuard : public C_AI_BaseNPC
  17. {
  18. public:
  19. C_NPC_AntlionGuard() {}
  20. DECLARE_CLASS( C_NPC_AntlionGuard, C_AI_BaseNPC );
  21. DECLARE_CLIENTCLASS();
  22. DECLARE_DATADESC();
  23. virtual void OnDataChanged( DataUpdateType_t type );
  24. virtual void ClientThink();
  25. private:
  26. bool m_bCavernBreed;
  27. bool m_bInCavern;
  28. dlight_t *m_dlight;
  29. #if HL2_EPISODIC
  30. unsigned char m_iBleedingLevel; //< the version coming from the server
  31. unsigned char m_iPerformingBleedingLevel; //< the version we're currently performing (for comparison to one above)
  32. CNewParticleEffect *m_pBleedingFX;
  33. /// update the hemorrhage particle effect
  34. virtual void UpdateBleedingPerformance( void );
  35. #endif
  36. C_NPC_AntlionGuard( const C_NPC_AntlionGuard & );
  37. };
  38. //-----------------------------------------------------------------------------
  39. // Save/restore
  40. //-----------------------------------------------------------------------------
  41. BEGIN_DATADESC( C_NPC_AntlionGuard )
  42. END_DATADESC()
  43. //-----------------------------------------------------------------------------
  44. // Networking
  45. //-----------------------------------------------------------------------------
  46. IMPLEMENT_CLIENTCLASS_DT(C_NPC_AntlionGuard, DT_NPC_AntlionGuard, CNPC_AntlionGuard)
  47. RecvPropBool( RECVINFO( m_bCavernBreed ) ),
  48. RecvPropBool( RECVINFO( m_bInCavern ) ),
  49. #if ANTLIONGUARD_BLOOD_EFFECTS
  50. RecvPropInt( RECVINFO( m_iBleedingLevel ) ),
  51. #endif
  52. END_RECV_TABLE()
  53. //-----------------------------------------------------------------------------
  54. //-----------------------------------------------------------------------------
  55. void C_NPC_AntlionGuard::OnDataChanged( DataUpdateType_t type )
  56. {
  57. BaseClass::OnDataChanged( type );
  58. if ( (type == DATA_UPDATE_CREATED) && m_bCavernBreed && m_bInCavern )
  59. {
  60. SetNextClientThink( CLIENT_THINK_ALWAYS );
  61. }
  62. #if HL2_EPISODIC
  63. if (m_iBleedingLevel != m_iPerformingBleedingLevel)
  64. {
  65. UpdateBleedingPerformance();
  66. }
  67. #endif
  68. }
  69. #if HL2_EPISODIC
  70. //-----------------------------------------------------------------------------
  71. //-----------------------------------------------------------------------------
  72. void C_NPC_AntlionGuard::UpdateBleedingPerformance()
  73. {
  74. // get my particles
  75. CParticleProperty * pProp = ParticleProp();
  76. // squelch the prior effect if it exists
  77. if (m_pBleedingFX)
  78. {
  79. pProp->StopEmission(m_pBleedingFX);
  80. m_pBleedingFX = NULL;
  81. }
  82. // kick off a new effect
  83. switch (m_iBleedingLevel)
  84. {
  85. case 1: // light bleeding
  86. {
  87. m_pBleedingFX = pProp->Create( "blood_antlionguard_injured_light", PATTACH_ABSORIGIN_FOLLOW );
  88. AssertMsg1( m_pBleedingFX, "Particle system couldn't make %s", "blood_antlionguard_injured_light" );
  89. if ( m_pBleedingFX )
  90. {
  91. pProp->AddControlPoint( m_pBleedingFX, 1, this, PATTACH_ABSORIGIN_FOLLOW );
  92. }
  93. }
  94. break;
  95. case 2: // severe bleeding
  96. {
  97. m_pBleedingFX = pProp->Create( "blood_antlionguard_injured_heavy", PATTACH_ABSORIGIN_FOLLOW );
  98. AssertMsg1( m_pBleedingFX, "Particle system couldn't make %s", "blood_antlionguard_injured_heavy" );
  99. if ( m_pBleedingFX )
  100. {
  101. pProp->AddControlPoint( m_pBleedingFX, 1, this, PATTACH_ABSORIGIN_FOLLOW );
  102. }
  103. }
  104. break;
  105. }
  106. m_iPerformingBleedingLevel = m_iBleedingLevel;
  107. }
  108. #endif
  109. //-----------------------------------------------------------------------------
  110. //-----------------------------------------------------------------------------
  111. void C_NPC_AntlionGuard::ClientThink()
  112. {
  113. // update the dlight. (always done because clienthink only exists for cavernguard)
  114. if (!m_dlight)
  115. {
  116. m_dlight = effects->CL_AllocDlight( index );
  117. m_dlight->color.r = 220;
  118. m_dlight->color.g = 255;
  119. m_dlight->color.b = 80;
  120. m_dlight->radius = 180;
  121. m_dlight->minlight = 128.0 / 256.0f;
  122. m_dlight->flags = DLIGHT_NO_MODEL_ILLUMINATION;
  123. }
  124. m_dlight->origin = GetAbsOrigin();
  125. // dl->die = gpGlobals->curtime + 0.1f;
  126. BaseClass::ClientThink();
  127. }