summaryrefslogtreecommitdiff
path: root/game/client/ProxyHealth.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/ProxyHealth.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'game/client/ProxyHealth.cpp')
-rw-r--r--game/client/ProxyHealth.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/game/client/ProxyHealth.cpp b/game/client/ProxyHealth.cpp
new file mode 100644
index 0000000..954c87d
--- /dev/null
+++ b/game/client/ProxyHealth.cpp
@@ -0,0 +1,59 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "cbase.h"
+#include "functionproxy.h"
+#include "toolframework_client.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+// forward declarations
+void ToolFramework_RecordMaterialParams( IMaterial *pMaterial );
+
+//-----------------------------------------------------------------------------
+// Returns the player health (from 0 to 1)
+//-----------------------------------------------------------------------------
+class CProxyHealth : public CResultProxy
+{
+public:
+ bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
+ void OnBind( void *pC_BaseEntity );
+
+private:
+ CFloatInput m_Factor;
+};
+
+bool CProxyHealth::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
+{
+ if (!CResultProxy::Init( pMaterial, pKeyValues ))
+ return false;
+
+ if (!m_Factor.Init( pMaterial, pKeyValues, "scale", 1 ))
+ return false;
+
+ return true;
+}
+
+void CProxyHealth::OnBind( void *pC_BaseEntity )
+{
+ if (!pC_BaseEntity)
+ return;
+
+ C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
+
+ Assert( m_pResult );
+ SetFloatResult( pEntity->HealthFraction() * m_Factor.GetFloat() );
+
+ if ( ToolsEnabled() )
+ {
+ ToolFramework_RecordMaterialParams( GetMaterial() );
+ }
+}
+
+EXPOSE_INTERFACE( CProxyHealth, IMaterialProxy, "Health" IMATERIAL_PROXY_INTERFACE_VERSION );
+
+