summaryrefslogtreecommitdiff
path: root/game/client/tf2/infiltratorcamomaterialproxy.cpp
blob: 9d099febab789d908d2f2f9623464ee144ac081b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "proxyentity.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.h"
#include "materialsystem/imaterialsystem.h"
#include "c_basetfplayer.h"
#include "c_tf_basecombatweapon.h"

class CInfiltratorCamoMaterialProxy : public CEntityMaterialProxy
{
public:
	CInfiltratorCamoMaterialProxy();
	virtual ~CInfiltratorCamoMaterialProxy();
	virtual bool Init( IMaterial *pMaterial, KeyValues* pKeyValues );
	virtual void OnBind( C_BaseEntity *pC_BaseEntity );

private:
	IMaterialVar *m_CamoVar;
};

CInfiltratorCamoMaterialProxy::CInfiltratorCamoMaterialProxy()
{
	m_CamoVar = NULL;
}

CInfiltratorCamoMaterialProxy::~CInfiltratorCamoMaterialProxy()
{
}


bool CInfiltratorCamoMaterialProxy::Init( IMaterial *pMaterial, KeyValues* pKeyValues  )
{
	bool foundVar;

	m_CamoVar = pMaterial->FindVar( "$alpha", &foundVar, false );
	if( !foundVar )
	{
		m_CamoVar = NULL;
		return false;
	}
	return true;
}

void CInfiltratorCamoMaterialProxy::OnBind( C_BaseEntity *pEnt )
{
	if( !m_CamoVar )
		return;

	C_BaseTFPlayer *player = dynamic_cast< C_BaseTFPlayer * >( pEnt );
	if ( player )
	{
		float amount = 1 - player->ComputeCamoEffectAmount();
		m_CamoVar->SetFloatValue( amount );
	}
	else
	{
		// Weapon model?
		C_BaseTFCombatWeapon *pWeapon = dynamic_cast< C_BaseTFCombatWeapon * >( pEnt );
		if ( pWeapon )
		{
			float amount = 1 - ((C_BaseTFPlayer *)pWeapon->GetOwner())->ComputeCamoEffectAmount();
			m_CamoVar->SetFloatValue( amount );
		}
		else
		{
			C_BaseViewModel *pViewmodel = dynamic_cast< C_BaseViewModel * >( pEnt );
			if ( pViewmodel )
			{
				// Get the local player's values
				player = C_BaseTFPlayer::GetLocalPlayer();
				float amount = 1 - player->ComputeCamoEffectAmount();
				m_CamoVar->SetFloatValue( amount );
			}
		}
	}
}

EXPOSE_INTERFACE( CInfiltratorCamoMaterialProxy, IMaterialProxy, "InfiltratorCamo" IMATERIAL_PROXY_INTERFACE_VERSION );