summaryrefslogtreecommitdiff
path: root/game/server/tf/tf_obj_catapult.cpp
blob: e24d233e962114cd584631e4df7a910894d8ab15 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//
//
//=============================================================================
#include "cbase.h"
#include "tf_obj_catapult.h"
#include "tf_player.h"
#include "mathlib/mathlib.h"
#include "in_buttons.h"

#ifdef STAGING_ONLY

#define CATAPULT_THINK_CONTEXT				"CatapultContext"

#define CATAPULT_MODEL	"models/buildables/teleporter_light.mdl"

const Vector CATAPULT_MINS = Vector( -24, -24, 0 );
const Vector CATAPULT_MAXS = Vector( 24, 24, 12 );

ConVar tf_engineer_catapult_force( "tf_engineer_catapult_force", "1000" );
ConVar tf_engineer_catapult_delay( "tf_engineer_catapult_delay", "0" );


//IMPLEMENT_SERVERCLASS_ST( CObjectCatapult, DT_ObjectCatapult )
//END_SEND_TABLE()

BEGIN_DATADESC( CObjectCatapult )
	DEFINE_THINKFUNC( CatapultThink ),
END_DATADESC()

PRECACHE_REGISTER( obj_catapult );

LINK_ENTITY_TO_CLASS( obj_catapult, CObjectCatapult );


CObjectCatapult::CObjectCatapult()
{
	int iHealth = GetMaxHealthForCurrentLevel();

	SetMaxHealth( iHealth );
	SetHealth( iHealth );
	UseClientSideAnimation();

	SetType( OBJ_CATAPULT );
}


void CObjectCatapult::Spawn()
{
	SetSolid( SOLID_BBOX );

	SetModel( CATAPULT_MODEL );
	int nBodyDir = FindBodygroupByName( "teleporter_direction" );
	if ( nBodyDir != -1 )
	{
		SetBodygroup( nBodyDir, 0 );
	}

	UTIL_SetSize( this, CATAPULT_MINS, CATAPULT_MAXS );

	BaseClass::Spawn();

	// HACK: Spin this building 180.  The temp model is backwards
	RotateBuildAngles();
	RotateBuildAngles();

	UpdateDesiredBuildRotation( 5.f );
}


void CObjectCatapult::Precache()
{
	BaseClass::Precache();

	PrecacheModel( CATAPULT_MODEL );
}


void CObjectCatapult::CatapultThink()
{
	if ( IsCarried() )
		return;

	SetContextThink( &CObjectCatapult::CatapultThink, gpGlobals->curtime + 0.1f, CATAPULT_THINK_CONTEXT );

	const float flJumpDelay = tf_engineer_catapult_delay.GetFloat();
	for ( int i=0; i<m_jumpers.Count(); )
	{
		const Jumper_t& jumper = m_jumpers[i];

		// Cleanup
		if( !jumper.m_hJumper )
		{
			m_jumpers.Remove(i);
			continue;
		}
		
		CTFPlayer *pPlayer = ToTFPlayer( jumper.m_hJumper );
		if ( !pPlayer )
		{
			m_jumpers.Remove( i );
			continue;
		}

		//pPlayer->m_nButtons |= IN_DUCK;
		if ( jumper.flTouchTime + flJumpDelay < gpGlobals->curtime || ( pPlayer->m_nButtons & IN_DUCK ) )
		{
			Launch( jumper.m_hJumper );
			m_jumpers.Remove(i);
		}
		else
		{
			++i;
		}
	}
}


void CObjectCatapult::OnGoActive()
{
	BaseClass::OnGoActive();

	SetContextThink( &CObjectCatapult::CatapultThink, gpGlobals->curtime + 0.1, CATAPULT_THINK_CONTEXT );

	int nBodyDir = FindBodygroupByName( "teleporter_direction" );
	if ( nBodyDir != -1 )
	{
		SetBodygroup( nBodyDir, 1 );
	}

}


bool CObjectCatapult::IsPlacementPosValid( void )
{
	bool bResult = BaseClass::IsPlacementPosValid();

	if ( !bResult )
	{
		return false;
	}

	// m_vecBuildOrigin is the proposed build origin

	// start above the teleporter position
	Vector vecTestPos = m_vecBuildOrigin;
	vecTestPos.z += CATAPULT_MAXS.z;

	// make sure we can fit a player on top in this pos
	trace_t tr;
	UTIL_TraceHull( vecTestPos, vecTestPos, VEC_HULL_MIN, VEC_HULL_MAX, MASK_SOLID | CONTENTS_PLAYERCLIP, this, COLLISION_GROUP_PLAYER_MOVEMENT, &tr );

	return ( tr.fraction >= 1.0 );
}


void CObjectCatapult::StartTouch( CBaseEntity *pOther )
{
	BaseClass::StartTouch( pOther );

	if ( pOther->IsPlayer() )
	{
		int index = m_jumpers.AddToTail();
		Jumper_t& jumper = m_jumpers[index];
		jumper.m_hJumper = pOther;
		jumper.flTouchTime = gpGlobals->curtime;
	}
}


void CObjectCatapult::EndTouch( CBaseEntity *pOther )
{
	BaseClass::EndTouch( pOther );

	for ( int i=0; i<m_jumpers.Count(); ++i )
	{
		if ( m_jumpers[i].m_hJumper == pOther )
		{
			m_jumpers.Remove(i);
			return;
		}
	}
}


void CObjectCatapult::Launch( CBaseEntity* pEnt )
{
	CTFPlayer *pPlayer = ToTFPlayer( pEnt );
	if ( !pPlayer ) 
		return;

	//Vector vForward;
	//QAngle qEyeAngle = pEnt->EyeAngles();
	//AngleVectors( pEnt->EyeAngles(), &vForward );
	//vForward.NormalizeInPlace();
	//vForward.z += 2.0f;
	//vForward.NormalizeInPlace();

	
	//pPlayer->ApplyAirBlastImpulse( tf_engineer_catapult_force.GetFloat() * vForward );
	pPlayer->m_Shared.AddCond( TF_COND_SPEED_BOOST, 5.0f );
}

#endif // STAGING_ONLY