summaryrefslogtreecommitdiff
path: root/game/server/hl1/hl1_player.h
blob: 03ddf9df5b98853eca536f9e9bfca192ee40c1b2 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:		Player for HL1.
//
// $NoKeywords: $
//=============================================================================//

#ifndef HL1_PLAYER_H
#define HL1_PLAYER_H
#pragma once


#include "player.h"

extern int TrainSpeed(int iSpeed, int iMax);
extern void CopyToBodyQue( CBaseAnimating *pCorpse );

enum HL1PlayerPhysFlag_e
{
	// 1 -- 5 are used by enum PlayerPhysFlag_e in player.h

	PFLAG_ONBARNACLE	= ( 1<<6 )		// player is hangning from the barnalce
};

class IPhysicsPlayerController;


//=============================================================================
//=============================================================================
class CSuitPowerDevice
{
public:
	CSuitPowerDevice( int bitsID, float flDrainRate ) { m_bitsDeviceID = bitsID; m_flDrainRate = flDrainRate; }
private:
	int		m_bitsDeviceID;	// tells what the device is. DEVICE_SPRINT, DEVICE_FLASHLIGHT, etc. BITMASK!!!!!
	float	m_flDrainRate;	// how quickly does this device deplete suit power? ( percent per second )

public:
	int		GetDeviceID( void ) const { return m_bitsDeviceID; }
	float	GetDeviceDrainRate( void ) const { return m_flDrainRate; }
};

//=============================================================================
// >> HL1_PLAYER
//=============================================================================
class CHL1_Player : public CBasePlayer
{
	DECLARE_CLASS( CHL1_Player, CBasePlayer );
	DECLARE_SERVERCLASS();
public:

	DECLARE_DATADESC();

	CHL1_Player();
	~CHL1_Player( void );

	static CHL1_Player *CreatePlayer( const char *className, edict_t *ed )
	{
		CHL1_Player::s_PlayerEdict = ed;
		return (CHL1_Player*)CreateEntityByName( className );
	}

	void		CreateCorpse( void ) { CopyToBodyQue( this ); };

	void		Precache( void );
	void		Spawn(void);
	void		Event_Killed( const CTakeDamageInfo &info );
	void		CheatImpulseCommands( int iImpulse );
	void		PlayerRunCommand( CUserCmd *ucmd, IMoveHelper *moveHelper );
	void		UpdateClientData( void );
	void		OnSave( IEntitySaveUtils *pUtils );
	
	void		CheckTimeBasedDamage( void );

	// from cbasecombatcharacter
	void		InitVCollision( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity );

	Class_T		Classify ( void );
	Class_T		m_nControlClass;			// Class when player is controlling another entity

	// from CBasePlayer
	void				SetupVisibility( CBaseEntity *pViewEntity, unsigned char *pvs, int pvssize );

	// Aiming heuristics accessors
	float		GetIdleTime( void ) const { return ( m_flIdleTime - m_flMoveTime ); }
	float		GetMoveTime( void ) const { return ( m_flMoveTime - m_flIdleTime ); }
	float		GetLastDamageTime( void ) const { return m_flLastDamageTime; }
	bool		IsDucking( void ) const { return !!( GetFlags() & FL_DUCKING ); }

	int			OnTakeDamage( const CTakeDamageInfo &info );
	int			OnTakeDamage_Alive( const CTakeDamageInfo &info );
	void		FindMissTargets( void );
	bool		GetMissPosition( Vector *position );

	void		OnDamagedByExplosion( const CTakeDamageInfo &info ) { };
	void		PlayerPickupObject( CBasePlayer *pPlayer, CBaseEntity *pObject );

	virtual void CreateViewModel( int index /*=0*/ );

	virtual CBaseEntity	*GiveNamedItem( const char *pszName, int iSubType = 0 );

	virtual void OnRestore( void );

	bool		IsPullingObject() { return m_bIsPullingObject; }
	void		StartPullingObject( CBaseEntity *pObject );
	void		StopPullingObject();
	void		UpdatePullingObject();


protected:
	void		PreThink( void );
	bool		HandleInteraction(int interactionType, void *data, CBaseCombatCharacter* sourceEnt);

private:
	Vector		m_vecMissPositions[16];
	int			m_nNumMissPositions;

	// Aiming heuristics code
	float		m_flIdleTime;		//Amount of time we've been motionless
	float		m_flMoveTime;		//Amount of time we've been in motion
	float		m_flLastDamageTime;	//Last time we took damage
	float		m_flTargetFindTime;

	EHANDLE					m_hPullObject;
	IPhysicsConstraint		*m_pPullConstraint;


public:

	// Flashlight Device
	int			FlashlightIsOn( void );
	void		FlashlightTurnOn( void );
	void		FlashlightTurnOff( void );
	float		m_flFlashLightTime;			// Time until next battery draw/Recharge
	CNetworkVar( int, m_nFlashBattery );	// Flashlight Battery Draw

	// For gauss weapon
//	float		m_flStartCharge;
//	float		m_flAmmoStartCharge;
//	float		m_flPlayAftershock;
//	float		m_flNextAmmoBurn;	// while charging, when to absorb another unit of player's ammo?

	CNetworkVar( float, m_flStartCharge );
	CNetworkVar( float, m_flAmmoStartCharge );
	CNetworkVar( float, m_flPlayAftershock );
	CNetworkVar( float, m_flNextAmmoBurn );	// while charging, when to absorb another unit of player's ammo?

	CNetworkVar( bool, m_bHasLongJump );
	CNetworkVar( bool, m_bIsPullingObject );
};


//-----------------------------------------------------------------------------
// Converts an entity to a HL1 player
//-----------------------------------------------------------------------------
inline CHL1_Player *ToHL1Player( CBaseEntity *pEntity )
{
	if ( !pEntity || !pEntity->IsPlayer() )
		return NULL;
#if _DEBUG
	return dynamic_cast<CHL1_Player *>( pEntity );
#else
	return static_cast<CHL1_Player *>( pEntity );
#endif
}

#endif	//HL1_PLAYER_H