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.

173 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "c_ai_basenpc.h"
  8. #include "iviewrender_beams.h"
  9. #include "beam_shared.h"
  10. #include "materialsystem/imaterial.h"
  11. #include "model_types.h"
  12. #include "clienteffectprecachesystem.h"
  13. #include "beamdraw.h"
  14. class C_RollerMine : public C_AI_BaseNPC
  15. {
  16. DECLARE_CLASS( C_RollerMine, C_AI_BaseNPC );
  17. public:
  18. DECLARE_CLIENTCLASS();
  19. C_RollerMine( void ) {}
  20. int DrawModel( int flags );
  21. RenderGroup_t GetRenderGroup( void )
  22. {
  23. if ( m_bIsOpen )
  24. return RENDER_GROUP_TRANSLUCENT_ENTITY;
  25. else
  26. return RENDER_GROUP_OPAQUE_ENTITY;
  27. }
  28. private:
  29. C_RollerMine( const C_RollerMine & ) {}
  30. bool m_bIsOpen;
  31. float m_flActiveTime;
  32. bool m_bHackedByAlyx;
  33. bool m_bPowerDown;
  34. };
  35. IMPLEMENT_CLIENTCLASS_DT( C_RollerMine, DT_RollerMine, CNPC_RollerMine )
  36. RecvPropInt( RECVINFO( m_bIsOpen ) ),
  37. RecvPropFloat( RECVINFO( m_flActiveTime ) ),
  38. RecvPropInt( RECVINFO( m_bHackedByAlyx ) ),
  39. RecvPropInt( RECVINFO( m_bPowerDown ) ),
  40. END_RECV_TABLE()
  41. #define NUM_ATTACHMENTS 11
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. // Input : flags -
  45. // Output : int
  46. //-----------------------------------------------------------------------------
  47. int C_RollerMine::DrawModel( int flags )
  48. {
  49. if ( m_bIsOpen && m_flActiveTime <= gpGlobals->curtime )
  50. {
  51. float scale = random->RandomFloat( 4.0f, 6.0f );
  52. if ( gpGlobals->frametime != 0 )
  53. {
  54. // Inner beams
  55. BeamInfo_t beamInfo;
  56. beamInfo.m_vecStart = GetAbsOrigin();
  57. Vector offset = RandomVector( -6*scale, 2*scale );
  58. offset += Vector(2,2,2) * scale;
  59. beamInfo.m_vecEnd = GetAbsOrigin() + offset;
  60. beamInfo.m_pStartEnt= cl_entitylist->GetEnt( BEAMENT_ENTITY( entindex() ) );
  61. beamInfo.m_pEndEnt = beamInfo.m_pStartEnt;
  62. beamInfo.m_nStartAttachment = random->RandomInt( 0, NUM_ATTACHMENTS );
  63. beamInfo.m_nEndAttachment = random->RandomInt( 0, NUM_ATTACHMENTS );
  64. // Ensure we're not the same point
  65. if ( beamInfo.m_nStartAttachment == beamInfo.m_nEndAttachment )
  66. {
  67. int nextStep = ( random->RandomInt( 0, 1 ) ) ? 1 : -1;
  68. beamInfo.m_nEndAttachment = ( beamInfo.m_nStartAttachment + nextStep ) % NUM_ATTACHMENTS;
  69. }
  70. beamInfo.m_nType = TE_BEAMTESLA;
  71. beamInfo.m_pszModelName = "sprites/lgtning.vmt";
  72. beamInfo.m_flHaloScale = 0.0f;
  73. beamInfo.m_flLife = 0.1f;
  74. beamInfo.m_flWidth = random->RandomFloat( 2.0f, 4.0f );
  75. beamInfo.m_flEndWidth = random->RandomFloat( 0.0f, 1.0f );
  76. beamInfo.m_flFadeLength = 0.0f;
  77. beamInfo.m_flAmplitude = random->RandomFloat( 16, 32 );
  78. beamInfo.m_flBrightness = 255.0;
  79. beamInfo.m_flSpeed = 0.0;
  80. beamInfo.m_nStartFrame = 0.0;
  81. beamInfo.m_flFrameRate = 1.0f;
  82. if ( m_bPowerDown )
  83. {
  84. beamInfo.m_flRed = 255.0f;;
  85. beamInfo.m_flGreen = 64.0f;
  86. beamInfo.m_flBlue = 64.0f;
  87. }
  88. else if ( m_bHackedByAlyx )
  89. {
  90. beamInfo.m_flRed = 240.0f;;
  91. beamInfo.m_flGreen = 200.0f;
  92. beamInfo.m_flBlue = 80.0f;
  93. }
  94. else
  95. {
  96. beamInfo.m_flRed = 255.0f;;
  97. beamInfo.m_flGreen = 255.0f;
  98. beamInfo.m_flBlue = 255.0f;
  99. }
  100. beamInfo.m_nSegments = 4;
  101. beamInfo.m_bRenderable = true;
  102. beamInfo.m_nFlags = 0;
  103. beams->CreateBeamEntPoint( beamInfo );
  104. // Draw the halo
  105. float color[3];
  106. if ( m_bHackedByAlyx )
  107. {
  108. color[0] = 0.25f;
  109. color[1] = 0.05f;
  110. color[2] = 0.0f;
  111. }
  112. else
  113. {
  114. color[0] = color[1] = color[2] = 0.15f;
  115. }
  116. IMaterial *pMaterial = materials->FindMaterial( "effects/rollerglow", NULL, false );
  117. CMatRenderContextPtr pRenderContext( materials );
  118. pRenderContext->Bind( pMaterial );
  119. DrawHalo( pMaterial, GetAbsOrigin(), random->RandomFloat( 6.0f*scale, 6.5f*scale ), color );
  120. if ( m_bPowerDown )
  121. {
  122. color[0] = random->RandomFloat( 0.80f, 1.00f );
  123. color[1] = random->RandomFloat( 0.10f, 0.25f );
  124. color[2] = 0.0f;
  125. }
  126. else if ( m_bHackedByAlyx )
  127. {
  128. color[0] = random->RandomFloat( 0.25f, 0.75f );
  129. color[1] = random->RandomFloat( 0.10f, 0.25f );
  130. color[2] = 0.0f;
  131. }
  132. else
  133. {
  134. color[0] = color[1] = color[2] = random->RandomFloat( 0.25f, 0.5f );
  135. }
  136. Vector attachOrigin;
  137. QAngle attachAngles;
  138. GetAttachment( beamInfo.m_nEndAttachment, attachOrigin, attachAngles );
  139. DrawHalo( pMaterial, attachOrigin, random->RandomFloat( 1.0f*scale, 1.5f*scale ), color );
  140. GetAttachment( beamInfo.m_nStartAttachment, attachOrigin, attachAngles );
  141. DrawHalo( pMaterial, attachOrigin, random->RandomFloat( 1.0f*scale, 1.5f*scale ), color );
  142. }
  143. }
  144. return BaseClass::DrawModel( flags );
  145. }