summaryrefslogtreecommitdiff
path: root/game/server/tf2/tf_obj_mcv_selection_panel.cpp
blob: c293132d81fe6efa40a3489e7e8340eefff88e2d (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "cbase.h"
#include "tf_obj.h"
#include "tf_shareddefs.h"
#include "vguiscreen.h"
#include "tf_vehicle_teleport_station.h"


#define MCV_SELECTION_MODEL			"models/objects/obj_resupply.mdl"
#define MCV_SELECTION_SCREEN_NAME	"screen_mcv_selection_panel"  


class CObjMCVSelectionPanel : public CBaseObject
{
public:

	DECLARE_CLASS( CObjMCVSelectionPanel, CBaseObject );
	DECLARE_SERVERCLASS();

	CObjMCVSelectionPanel();
	~CObjMCVSelectionPanel();


public:

	virtual void Spawn();
	virtual void Precache();
	virtual void GetControlPanelInfo( int nPanelIndex, const char *&pPanelName );
	virtual bool ClientCommand( CBaseTFPlayer *pPlayer, const char *pCmd, ICommandArguments *pArg );

	virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
};


// This holds all the allocated CObjMCVSelectionPanels.
CUtlLinkedList<CObjMCVSelectionPanel*,int> g_MCVSelectionPanels;


LINK_ENTITY_TO_CLASS( obj_mcv_selection_panel, CObjMCVSelectionPanel );


int SendProxy_TeleportStationCount( const void *pStruct, int objectID )
{
	return CVehicleTeleportStation::GetNumDeployedTeleportStations();
}


void SendProxy_TeleportStationElement( const SendProp *pProp, const void *pStructBase, const void *pData, DVariant *pOut, int iElement, int objectID )
{
	// Get the EHANDLE.
	EHANDLE hEnt;
	hEnt = CVehicleTeleportStation::GetDeployedTeleportStation( iElement );
	
	// Use the standard ehandle-encoding SendProxy to encode it.
	SendProxy_EHandleToInt( pProp, pStructBase, &hEnt, pOut, iElement, objectID );
}


void SignalChangeInMCVSelectionPanels()
{
}


IMPLEMENT_SERVERCLASS_ST( CObjMCVSelectionPanel, DT_MCVSelectionPanel )
	SendPropVirtualArray( 
		SendProxy_TeleportStationCount,
		32, // max # elements we'd ever send
		SendPropEHandle( "teleport_station_element", 0, 0, 0, SendProxy_TeleportStationElement ),
		"teleport_stations" )
END_SEND_TABLE()


CObjMCVSelectionPanel::CObjMCVSelectionPanel()
{
	g_MCVSelectionPanels.AddToTail( this );
}


CObjMCVSelectionPanel::~CObjMCVSelectionPanel()
{
	g_MCVSelectionPanels.FindAndRemove( this );
}


void CObjMCVSelectionPanel::Spawn()
{
	SetModel( MCV_SELECTION_MODEL );
	m_takedamage = DAMAGE_NO;
	SetType( OBJ_MCV_SELECTION_PANEL );

	BaseClass::Spawn();
}


void CObjMCVSelectionPanel::Precache()
{
	PrecacheModel( MCV_SELECTION_MODEL );
	PrecacheVGuiScreen( MCV_SELECTION_SCREEN_NAME );

	BaseClass::Precache();
}


void CObjMCVSelectionPanel::GetControlPanelInfo( int nPanelIndex, const char *&pPanelName )
{
	pPanelName = MCV_SELECTION_SCREEN_NAME;
}


bool CObjMCVSelectionPanel::ClientCommand( CBaseTFPlayer *pPlayer, const char *pCmd, ICommandArguments *pArg )
{
	if ( stricmp( pCmd, "SelectMCV" ) == 0 )
	{
		int mcvID = atoi( pArg->Argv( 1 ) );
		pPlayer->SetSelectedMCV( dynamic_cast< CVehicleTeleportStation* >( CBaseEntity::Instance( mcvID ) ) );
	}

	return BaseClass::ClientCommand( pPlayer, pCmd, pArg );
}


void CObjMCVSelectionPanel::SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways )
{
	BaseClass::SetTransmit( pInfo, bAlways );

	// Force deployed MCVs to be sent to the client too so the client can draw their position on its vgui screen.
	int count = CVehicleTeleportStation::GetNumDeployedTeleportStations();
	for ( int i=0; i < count; i++ )
	{
		CVehicleTeleportStation::GetDeployedTeleportStation( i )->SetTransmit( pInfo, bAlways );
	}
}