summaryrefslogtreecommitdiff
path: root/game/shared/tf/tf_item.cpp
blob: 7471b6b37c81f4ea4ee5d9b9d25d3b574239ad01 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//
//=============================================================================//
#include "cbase.h"
#include "tf_item.h"
#include "tf_shareddefs.h"

#ifdef CLIENT_DLL
#include "c_tf_player.h"

// NVNT haptics system interface
#include "haptics/ihaptics.h"
#else
#include "tf_player.h"
#endif

IMPLEMENT_NETWORKCLASS_ALIASED( TFItem, DT_TFItem )

BEGIN_NETWORK_TABLE( CTFItem, DT_TFItem )
END_NETWORK_TABLE()

//-----------------------------------------------------------------------------
// Purpose: Identifier.
//-----------------------------------------------------------------------------
unsigned int CTFItem::GetItemID( void ) const
{ 
	return TF_ITEM_UNDEFINED; 
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFItem::PickUp( CTFPlayer *pPlayer, bool bInvisible )
{
	// SetParent with attachment point - look it up later if need be!
	SetOwnerEntity( pPlayer );
	SetParent( pPlayer );
	SetLocalOrigin( vec3_origin );
	SetLocalAngles( vec3_angle );

	// Make invisible?
	if ( bInvisible )
	{
		AddEffects( EF_NODRAW );
	}

	// Add the item to the player's item inventory.
	pPlayer->SetItem( this );
	// NVNT if this is the client dll and the owner is the local
	//  player notify the haptics system.
#ifdef CLIENT_DLL
	if(pPlayer->IsLocalPlayer())
		haptics->ProcessHapticEvent(2,"Game","ctf_item_start");
#endif
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFItem::Drop( CTFPlayer *pPlayer, bool bVisible, bool bThrown /*= false*/, bool bMessage /*= true*/ )
{
	// Remove the item from the player's item inventory.
	pPlayer->SetItem( NULL );

	// Make visible?
	if ( bVisible )
	{
		RemoveEffects( EF_NODRAW );
	}
	// NVNT if this is the client dll and the owner is the local
	//  player notify the haptics system we are dropping this item.
#ifdef CLIENT_DLL
	if(pPlayer->IsLocalPlayer())
		haptics->ProcessHapticEvent(2,"Game","ctf_item_stop");
#endif

	// Clear the parent.
	SetParent( NULL );
	SetOwnerEntity( NULL );
}

#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CTFItem::ShouldDraw()
{
	// If I'm carrying the flag in 1st person, don't draw it
	if ( ToTFPlayer(GetMoveParent())->InFirstPersonView() )
		return false;

	return BaseClass::ShouldDraw();
}

//-----------------------------------------------------------------------------
// Should this object cast shadows?
//-----------------------------------------------------------------------------
ShadowType_t CTFItem::ShadowCastType()
{
	if ( ToTFPlayer(GetMoveParent())->ShouldDrawThisPlayer() )
	{
		// Using the viewmodel.
		return SHADOWS_NONE;
	}

	return BaseClass::ShadowCastType();
}

#endif