summaryrefslogtreecommitdiff
path: root/game/server/tf2/info_buildpoint.cpp
blob: 961b4ff12daa3280238b6597a67dfa599a4ec247 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Map entity that allows players to build objects on it
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "EntityOutput.h"
#include "EntityList.h"
#include "tf_team.h"
#include "baseentity.h"
#include "info_buildpoint.h"
#include "tf_gamerules.h"

// Spawnflags
const int SF_BUILDPOINT_ALLOW_ALL_GUNS		= 0x01;	// Allow all manned guns to be built on this point
const int SF_BUILDPOINT_ALLOW_VEHICLES		= 0x02;	// Allow all vehicles to be built on this point

BEGIN_DATADESC( CInfoBuildPoint )

	// keys 
	DEFINE_KEYFIELD_NOT_SAVED( m_iszAllowedObject, FIELD_STRING, "AllowedObject" ),

END_DATADESC()

LINK_ENTITY_TO_CLASS( info_buildpoint, CInfoBuildPoint );

// List of buildpoints
CUtlVector<CInfoBuildPoint*> g_MapDefinedBuildPoints;

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CInfoBuildPoint::Spawn( void )
{
	g_MapDefinedBuildPoints.AddToTail( this );

	m_iAllowedObjectType = -1;
	if ( m_iszAllowedObject != NULL_STRING )
	{
		for ( int i = 0; i < OBJ_LAST; i++ )
		{
			if ( !Q_strcmp( STRING(m_iszAllowedObject), GetObjectInfo(i)->m_pClassName ) )
			{
				m_iAllowedObjectType = i;
				break;
			}
		}
	}

	BaseClass::Spawn();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CInfoBuildPoint::UpdateOnRemove( void )
{
	g_MapDefinedBuildPoints.FindAndRemove( this );
	BaseClass::UpdateOnRemove();
}

//-----------------------------------------------------------------------------
// Purpose: Tell me how many build points you have
//-----------------------------------------------------------------------------
int	CInfoBuildPoint::GetNumBuildPoints( void ) const
{
	return 1;
}

//-----------------------------------------------------------------------------
// Purpose: Give me the origin & angles of the specified build point
//-----------------------------------------------------------------------------
bool CInfoBuildPoint::GetBuildPoint( int iPoint, Vector &vecOrigin, QAngle &vecAngles )
{
	ASSERT( iPoint <= GetNumBuildPoints() );

	vecOrigin = GetAbsOrigin();
	vecAngles = GetAbsAngles();
	return true;
}

int CInfoBuildPoint::GetBuildPointAttachmentIndex( int iPoint ) const
{
	return 0;
}

//-----------------------------------------------------------------------------
// Purpose: Can I build the specified object on the specified build point?
//-----------------------------------------------------------------------------
bool CInfoBuildPoint::CanBuildObjectOnBuildPoint( int iPoint, int iObjectType )
{
	ASSERT( iPoint <= GetNumBuildPoints() );
	if ( m_hObjectBuiltOnMe )
		return false;

	// Manned guns?
	if ( m_spawnflags & SF_BUILDPOINT_ALLOW_ALL_GUNS )
	{
		if ( (iObjectType == OBJ_MANNED_PLASMAGUN) || 
			 (iObjectType == OBJ_MANNED_MISSILELAUNCHER) || 
			 (iObjectType == OBJ_MANNED_SHIELD) ||  
			 (iObjectType == OBJ_SENTRYGUN_PLASMA) )
			return true;
	}

	// Vehicles
	if ( m_spawnflags & SF_BUILDPOINT_ALLOW_VEHICLES )
	{
		if ( IsObjectAVehicle(iObjectType) )
			return true;
	}

	// Check our unique
	if ( m_iAllowedObjectType >= 0 && m_iAllowedObjectType == iObjectType )
		return true;

	return false;
}

//-----------------------------------------------------------------------------
// Purpose: I've finished building the specified object on the specified build point
//-----------------------------------------------------------------------------
void CInfoBuildPoint::SetObjectOnBuildPoint( int iPoint, CBaseObject *pObject )
{
	ASSERT( iPoint <= GetNumBuildPoints() );
	m_hObjectBuiltOnMe = pObject;
}

//-----------------------------------------------------------------------------
// Purpose: Get the number of objects build on this entity
//-----------------------------------------------------------------------------
int	CInfoBuildPoint::GetNumObjectsOnMe( void )
{
	if ( m_hObjectBuiltOnMe )
		return 1;

	return 0;
}

//-----------------------------------------------------------------------------
// Purpose: Get the first object that's built on me
//-----------------------------------------------------------------------------
CBaseEntity	*CInfoBuildPoint::GetFirstObjectOnMe( void )
{
	return m_hObjectBuiltOnMe;
}

//-----------------------------------------------------------------------------
// Purpose: Get the first object of type, return NULL if no such type available
//-----------------------------------------------------------------------------
CBaseObject *CInfoBuildPoint::GetObjectOfTypeOnMe( int iObjectType )
{
	if ( m_hObjectBuiltOnMe )
	{
		if ( m_hObjectBuiltOnMe->ObjectType() == iObjectType )
			return m_hObjectBuiltOnMe;
	}

	return NULL;
}

//-----------------------------------------------------------------------------
// Purpose: Remove all objects built on me
//-----------------------------------------------------------------------------
void CInfoBuildPoint::RemoveAllObjects( void )
{
	UTIL_Remove( m_hObjectBuiltOnMe );
}

//-----------------------------------------------------------------------------
// Purpose: Return the maximum distance that this entity's build points can be snapped to
//-----------------------------------------------------------------------------
float CInfoBuildPoint::GetMaxSnapDistance( int iPoint )
{
	return 64;
}

//-----------------------------------------------------------------------------
// Purpose: Return true if it's possible that build points on this entity may move in local space (i.e. due to animation)
//-----------------------------------------------------------------------------
bool CInfoBuildPoint::ShouldCheckForMovement( void )
{
	return false;
}

//-----------------------------------------------------------------------------
// Purpose: I've finished building the specified object on the specified build point
//-----------------------------------------------------------------------------
int	CInfoBuildPoint::FindObjectOnBuildPoint( CBaseObject *pObject )
{
	return 1;
}

//-----------------------------------------------------------------------------
// Purpose: Returns an exit point for a vehicle built on a build point...
//-----------------------------------------------------------------------------
void CInfoBuildPoint::GetExitPoint( CBaseEntity *pPlayer, int iPoint, Vector *pAbsOrigin, QAngle *pAbsAngles )
{
	// FIXME: In future, we may well want to use specific exit attachments here...
	GetBuildPoint( iPoint, *pAbsOrigin, *pAbsAngles );

	// Move back along the forward direction a bit...
	Vector vecForward;
	AngleVectors( *pAbsAngles, &vecForward );
	*pAbsOrigin -= vecForward * 60;

	// Now select a good spot to drop onto
	Vector vNewPos;
	if ( !EntityPlacementTest(pPlayer, *pAbsOrigin, vNewPos, true) )
	{
		Warning("Can't find valid place to exit object.\n");
		return;
	}

	*pAbsOrigin = vNewPos;
}