Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1116 lines
37 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Player for HL1.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CS_PLAYER_H
  8. #define CS_PLAYER_H
  9. #pragma once
  10. #include "basemultiplayerplayer.h"
  11. #include "server_class.h"
  12. #include "cs_playeranimstate.h"
  13. #include "cs_shareddefs.h"
  14. #include "cs_autobuy.h"
  15. #include "utldict.h"
  16. class CWeaponCSBase;
  17. class CMenu;
  18. class CHintMessageQueue;
  19. class CNavArea;
  20. #include "cs_weapon_parse.h"
  21. void UTIL_AwardMoneyToTeam( int iAmount, int iTeam, CBaseEntity *pIgnore );
  22. #define MENU_STRING_BUFFER_SIZE 1024
  23. #define MENU_MSG_TEXTCHUNK_SIZE 50
  24. enum
  25. {
  26. MIN_NAME_CHANGE_INTERVAL = 10, // minimum number of seconds between name changes
  27. NAME_CHANGE_HISTORY_SIZE = 5, // number of times a player can change names in NAME_CHANGE_HISTORY_INTERVAL
  28. NAME_CHANGE_HISTORY_INTERVAL = 600, // no more than NAME_CHANGE_HISTORY_SIZE name changes can be made in this many seconds
  29. };
  30. extern ConVar bot_mimic;
  31. // Function table for each player state.
  32. class CCSPlayerStateInfo
  33. {
  34. public:
  35. CSPlayerState m_iPlayerState;
  36. const char *m_pStateName;
  37. void (CCSPlayer::*pfnEnterState)(); // Init and deinit the state.
  38. void (CCSPlayer::*pfnLeaveState)();
  39. void (CCSPlayer::*pfnPreThink)(); // Do a PreThink() in this state.
  40. };
  41. //=======================================
  42. //Record of either damage taken or given.
  43. //Contains the player name that we hurt or that hurt us,
  44. //and the total damage
  45. //=======================================
  46. class CDamageRecord
  47. {
  48. public:
  49. CDamageRecord( const char *name, int iDamage, int iCounter )
  50. {
  51. Q_strncpy( m_szPlayerName, name, sizeof(m_szPlayerName) );
  52. m_iDamage = iDamage;
  53. m_iNumHits = 1;
  54. m_iLastBulletUpdate = iCounter;
  55. }
  56. void AddDamage( int iDamage, int iCounter )
  57. {
  58. m_iDamage += iDamage;
  59. if ( m_iLastBulletUpdate != iCounter )
  60. m_iNumHits++;
  61. m_iLastBulletUpdate = iCounter;
  62. }
  63. char *GetPlayerName( void ) { return m_szPlayerName; }
  64. int GetDamage( void ) { return m_iDamage; }
  65. int GetNumHits( void ) { return m_iNumHits; }
  66. private:
  67. char m_szPlayerName[MAX_PLAYER_NAME_LENGTH];
  68. int m_iDamage; //how much damage was done
  69. int m_iNumHits; //how many hits
  70. int m_iLastBulletUpdate; // update counter
  71. };
  72. // Message display history (CCSPlayer::m_iDisplayHistoryBits)
  73. // These bits are set when hint messages are displayed, and cleared at
  74. // different times, according to the DHM_xxx bitmasks that follow
  75. #define DHF_ROUND_STARTED ( 1 << 1 )
  76. #define DHF_HOSTAGE_SEEN_FAR ( 1 << 2 )
  77. #define DHF_HOSTAGE_SEEN_NEAR ( 1 << 3 )
  78. #define DHF_HOSTAGE_USED ( 1 << 4 )
  79. #define DHF_HOSTAGE_INJURED ( 1 << 5 )
  80. #define DHF_HOSTAGE_KILLED ( 1 << 6 )
  81. #define DHF_FRIEND_SEEN ( 1 << 7 )
  82. #define DHF_ENEMY_SEEN ( 1 << 8 )
  83. #define DHF_FRIEND_INJURED ( 1 << 9 )
  84. #define DHF_FRIEND_KILLED ( 1 << 10 )
  85. #define DHF_ENEMY_KILLED ( 1 << 11 )
  86. #define DHF_BOMB_RETRIEVED ( 1 << 12 )
  87. #define DHF_AMMO_EXHAUSTED ( 1 << 15 )
  88. #define DHF_IN_TARGET_ZONE ( 1 << 16 )
  89. #define DHF_IN_RESCUE_ZONE ( 1 << 17 )
  90. #define DHF_IN_ESCAPE_ZONE ( 1 << 18 ) // unimplemented
  91. #define DHF_IN_VIPSAFETY_ZONE ( 1 << 19 ) // unimplemented
  92. #define DHF_NIGHTVISION ( 1 << 20 )
  93. #define DHF_HOSTAGE_CTMOVE ( 1 << 21 )
  94. #define DHF_SPEC_DUCK ( 1 << 22 )
  95. // DHF_xxx bits to clear when the round restarts
  96. #define DHM_ROUND_CLEAR ( \
  97. DHF_ROUND_STARTED | \
  98. DHF_HOSTAGE_KILLED | \
  99. DHF_FRIEND_KILLED | \
  100. DHF_BOMB_RETRIEVED )
  101. // DHF_xxx bits to clear when the player is restored
  102. #define DHM_CONNECT_CLEAR ( \
  103. DHF_HOSTAGE_SEEN_FAR | \
  104. DHF_HOSTAGE_SEEN_NEAR | \
  105. DHF_HOSTAGE_USED | \
  106. DHF_HOSTAGE_INJURED | \
  107. DHF_FRIEND_SEEN | \
  108. DHF_ENEMY_SEEN | \
  109. DHF_FRIEND_INJURED | \
  110. DHF_ENEMY_KILLED | \
  111. DHF_AMMO_EXHAUSTED | \
  112. DHF_IN_TARGET_ZONE | \
  113. DHF_IN_RESCUE_ZONE | \
  114. DHF_IN_ESCAPE_ZONE | \
  115. DHF_IN_VIPSAFETY_ZONE | \
  116. DHF_HOSTAGE_CTMOVE | \
  117. DHF_SPEC_DUCK )
  118. // radio messages (these must be kept in sync with actual radio) -------------------------------------
  119. enum RadioType
  120. {
  121. RADIO_INVALID = 0,
  122. RADIO_START_1, ///< radio messages between this and RADIO_START_2 and part of Radio1()
  123. RADIO_COVER_ME,
  124. RADIO_YOU_TAKE_THE_POINT,
  125. RADIO_HOLD_THIS_POSITION,
  126. RADIO_REGROUP_TEAM,
  127. RADIO_FOLLOW_ME,
  128. RADIO_TAKING_FIRE,
  129. RADIO_START_2, ///< radio messages between this and RADIO_START_3 are part of Radio2()
  130. RADIO_GO_GO_GO,
  131. RADIO_TEAM_FALL_BACK,
  132. RADIO_STICK_TOGETHER_TEAM,
  133. RADIO_GET_IN_POSITION_AND_WAIT,
  134. RADIO_STORM_THE_FRONT,
  135. RADIO_REPORT_IN_TEAM,
  136. RADIO_START_3, ///< radio messages above this are part of Radio3()
  137. RADIO_AFFIRMATIVE,
  138. RADIO_ENEMY_SPOTTED,
  139. RADIO_NEED_BACKUP,
  140. RADIO_SECTOR_CLEAR,
  141. RADIO_IN_POSITION,
  142. RADIO_REPORTING_IN,
  143. RADIO_GET_OUT_OF_THERE,
  144. RADIO_NEGATIVE,
  145. RADIO_ENEMY_DOWN,
  146. RADIO_END,
  147. RADIO_NUM_EVENTS
  148. };
  149. extern const char *RadioEventName[ RADIO_NUM_EVENTS+1 ];
  150. /**
  151. * Convert name to RadioType
  152. */
  153. extern RadioType NameToRadioEvent( const char *name );
  154. enum BuyResult_e
  155. {
  156. BUY_BOUGHT,
  157. BUY_ALREADY_HAVE,
  158. BUY_CANT_AFFORD,
  159. BUY_PLAYER_CANT_BUY, // not in the buy zone, is the VIP, is past the timelimit, etc
  160. BUY_NOT_ALLOWED, // weapon is restricted by VIP mode, team, etc
  161. BUY_INVALID_ITEM,
  162. };
  163. //=============================================================================
  164. // HPE_BEGIN:
  165. //=============================================================================
  166. // [tj] The phases for the "Goose Chase" achievement
  167. enum GooseChaseAchievementStep
  168. {
  169. GC_NONE,
  170. GC_SHOT_DURING_DEFUSE,
  171. GC_STOPPED_AFTER_GETTING_SHOT
  172. };
  173. // [tj] The phases for the "Defuse Defense" achievement
  174. enum DefuseDefenseAchivementStep
  175. {
  176. DD_NONE,
  177. DD_STARTED_DEFUSE,
  178. DD_KILLED_TERRORIST
  179. };
  180. //=============================================================================
  181. // HPE_END
  182. //=============================================================================
  183. //=============================================================================
  184. // >> CounterStrike player
  185. //=============================================================================
  186. class CCSPlayer : public CBaseMultiplayerPlayer, public ICSPlayerAnimStateHelpers
  187. {
  188. public:
  189. DECLARE_CLASS( CCSPlayer, CBaseMultiplayerPlayer );
  190. DECLARE_SERVERCLASS();
  191. DECLARE_PREDICTABLE();
  192. DECLARE_DATADESC();
  193. CCSPlayer();
  194. ~CCSPlayer();
  195. static CCSPlayer *CreatePlayer( const char *className, edict_t *ed );
  196. static CCSPlayer* Instance( int iEnt );
  197. virtual void Precache();
  198. virtual void Spawn();
  199. virtual void InitialSpawn( void );
  200. virtual void CheatImpulseCommands( int iImpulse );
  201. virtual void PlayerRunCommand( CUserCmd *ucmd, IMoveHelper *moveHelper );
  202. virtual void PostThink();
  203. virtual int OnTakeDamage( const CTakeDamageInfo &inputInfo );
  204. virtual int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  205. virtual void Event_Killed( const CTakeDamageInfo &info );
  206. //=============================================================================
  207. // HPE_BEGIN:
  208. // [tj] We have a custom implementation so we can check for achievements.
  209. //=============================================================================
  210. virtual void Event_KilledOther( CBaseEntity *pVictim, const CTakeDamageInfo &info );
  211. //=============================================================================
  212. // HPE_END
  213. //=============================================================================
  214. virtual void TraceAttack( const CTakeDamageInfo &inputInfo, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  215. virtual CBaseEntity *GiveNamedItem( const char *pszName, int iSubType = 0 );
  216. virtual bool IsBeingGivenItem() const { return m_bIsBeingGivenItem; }
  217. virtual CBaseEntity *FindUseEntity( void );
  218. virtual bool IsUseableEntity( CBaseEntity *pEntity, unsigned int requiredCaps );
  219. virtual void CreateViewModel( int viewmodelindex = 0 );
  220. virtual void ShowViewPortPanel( const char * name, bool bShow = true, KeyValues *data = NULL );
  221. // This passes the event to the client's and server's CPlayerAnimState.
  222. void DoAnimationEvent( PlayerAnimEvent_t event, int nData = 0 );
  223. // from CBasePlayer
  224. virtual void SetupVisibility( CBaseEntity *pViewEntity, unsigned char *pvs, int pvssize );
  225. virtual int GetNextObserverSearchStartPoint( bool bReverse );
  226. // In shared code.
  227. public:
  228. // ICSPlayerAnimState overrides.
  229. virtual CWeaponCSBase* CSAnim_GetActiveWeapon();
  230. virtual bool CSAnim_CanMove();
  231. virtual float GetPlayerMaxSpeed();
  232. void FireBullet(
  233. Vector vecSrc,
  234. const QAngle &shootAngles,
  235. float flDistance,
  236. int iPenetration,
  237. int iBulletType,
  238. int iDamage,
  239. float flRangeModifier,
  240. CBaseEntity *pevAttacker,
  241. bool bDoEffects,
  242. float xSpread, float ySpread );
  243. void KickBack(
  244. float up_base,
  245. float lateral_base,
  246. float up_modifier,
  247. float lateral_modifier,
  248. float up_max,
  249. float lateral_max,
  250. int direction_change );
  251. void GetBulletTypeParameters(
  252. int iBulletType,
  253. float &fPenetrationPower,
  254. float &flPenetrationDistance );
  255. // Returns true if the player is allowed to move.
  256. bool CanMove() const;
  257. void OnJump( float fImpulse );
  258. void OnLand( float fVelocity );
  259. bool HasC4() const; // Is this player carrying a C4 bomb?
  260. bool IsVIP() const;
  261. int GetClass( void ) const;
  262. void MakeVIP( bool isVIP );
  263. virtual void SetAnimation( PLAYER_ANIM playerAnim );
  264. ICSPlayerAnimState *GetPlayerAnimState() { return m_PlayerAnimState; }
  265. virtual bool StartReplayMode( float fDelay, float fDuration, int iEntity );
  266. virtual void StopReplayMode();
  267. virtual void PlayUseDenySound();
  268. public:
  269. // Simulates a single frame of movement for a player
  270. void RunPlayerMove( const QAngle& viewangles, float forwardmove, float sidemove, float upmove, unsigned short buttons, byte impulse, float frametime );
  271. virtual void HandleAnimEvent( animevent_t *pEvent );
  272. virtual void UpdateStepSound( surfacedata_t *psurface, const Vector &vecOrigin, const Vector &vecVelocity );
  273. virtual void PlayStepSound( Vector &vecOrigin, surfacedata_t *psurface, float fvol, bool force );
  274. // from cbasecombatcharacter
  275. void InitVCollision( const Vector &vecAbsOrigin, const Vector &vecAbsVelocity );
  276. void VPhysicsShadowUpdate( IPhysicsObject *pPhysics );
  277. bool HasShield() const;
  278. bool IsShieldDrawn() const;
  279. void GiveShield( void );
  280. void RemoveShield( void );
  281. bool IsProtectedByShield( void ) const; // returns true if player has a shield and is currently hidden behind it
  282. bool HasPrimaryWeapon( void );
  283. bool HasSecondaryWeapon( void );
  284. bool IsReloading( void ) const; // returns true if current weapon is reloading
  285. void GiveDefaultItems();
  286. void RemoveAllItems( bool removeSuit ); //overridden to remove the defuser
  287. // Reset account, get rid of shield, etc..
  288. void Reset();
  289. void RoundRespawn( void );
  290. void ObserverRoundRespawn( void );
  291. void CheckTKPunishment( void );
  292. // Add money to this player's account.
  293. void AddAccount( int amount, bool bTrackChange=true, bool bItemBought=false, const char *pItemName = NULL );
  294. void HintMessage( const char *pMessage, bool bDisplayIfDead, bool bOverrideClientSettings = false ); // Displays a hint message to the player
  295. CHintMessageQueue *m_pHintMessageQueue;
  296. unsigned int m_iDisplayHistoryBits;
  297. bool m_bShowHints;
  298. float m_flLastAttackedTeammate;
  299. float m_flNextMouseoverUpdate;
  300. void UpdateMouseoverHints();
  301. // mark this player as not receiving money at the start of the next round.
  302. void MarkAsNotReceivingMoneyNextRound();
  303. bool DoesPlayerGetRoundStartMoney(); // self-explanitory :)
  304. void DropC4(); // Get rid of the C4 bomb.
  305. bool HasDefuser(); // Is this player carrying a bomb defuser?
  306. void GiveDefuser(bool bPickedUp = false); // give the player a defuser
  307. void RemoveDefuser(); // remove defuser from the player and remove the model attachment
  308. //=============================================================================
  309. // HPE_BEGIN:
  310. // [dwenger] Added for fun-fact support
  311. //=============================================================================
  312. bool PickedUpDefuser() { return m_bPickedUpDefuser; }
  313. void SetDefusedWithPickedUpKit(bool bDefusedWithPickedUpKit) { m_bDefusedWithPickedUpKit = bDefusedWithPickedUpKit; }
  314. bool GetDefusedWithPickedUpKit() { return m_bDefusedWithPickedUpKit; }
  315. //=============================================================================
  316. // HPE_END
  317. //=============================================================================
  318. //=============================================================================
  319. // HPE_BEGIN
  320. // [sbodenbender] Need a different test for player blindness for the achievements
  321. //=============================================================================
  322. bool IsBlindForAchievement(); // more stringent than IsBlind; more accurately represents when the player can see again
  323. //=============================================================================
  324. // HPE_END
  325. //=============================================================================
  326. bool IsBlind( void ) const; // return true if this player is blind (from a flashbang)
  327. virtual void Blind( float holdTime, float fadeTime, float startingAlpha = 255 ); // player blinded by a flashbang
  328. float m_blindUntilTime;
  329. float m_blindStartTime;
  330. void Deafen( float flDistance ); //make the player deaf / apply dsp preset to muffle sound
  331. void ApplyDeafnessEffect(); // apply the deafness effect for a nearby explosion.
  332. bool IsAutoFollowAllowed( void ) const; // return true if this player will allow bots to auto follow
  333. void InhibitAutoFollow( float duration ); // prevent bots from auto-following for given duration
  334. void AllowAutoFollow( void ); // allow bots to auto-follow immediately
  335. float m_allowAutoFollowTime; // bots can auto-follow after this time
  336. // Have this guy speak a message into his radio.
  337. void Radio( const char *szRadioSound, const char *szRadioText = NULL );
  338. void ConstructRadioFilter( CRecipientFilter& filter );
  339. void EmitPrivateSound( const char *soundName ); ///< emit given sound that only we can hear
  340. CWeaponCSBase* GetActiveCSWeapon() const;
  341. void PreThink();
  342. // This is the think function for the player when they first join the server and have to select a team
  343. void JoiningThink();
  344. virtual bool ClientCommand( const CCommand &args );
  345. bool HandleCommand_JoinClass( int iClass );
  346. bool HandleCommand_JoinTeam( int iTeam );
  347. BuyResult_e HandleCommand_Buy( const char *item );
  348. BuyResult_e HandleCommand_Buy_Internal( const char * item );
  349. void HandleMenu_Radio1( int slot );
  350. void HandleMenu_Radio2( int slot );
  351. void HandleMenu_Radio3( int slot );
  352. float m_flRadioTime;
  353. int m_iRadioMessages;
  354. int iRadioMenu;
  355. void ListPlayers();
  356. bool m_bIgnoreRadio;
  357. // Returns one of the CS_CLASS_ enums.
  358. int PlayerClass() const;
  359. void MoveToNextIntroCamera();
  360. // Used to be GETINTOGAME state.
  361. void GetIntoGame();
  362. CBaseEntity* EntSelectSpawnPoint();
  363. void SetProgressBarTime( int barTime );
  364. virtual void PlayerDeathThink();
  365. void Weapon_Equip( CBaseCombatWeapon *pWeapon );
  366. virtual bool BumpWeapon( CBaseCombatWeapon *pWeapon );
  367. virtual bool Weapon_CanUse( CBaseCombatWeapon *pWeapon );
  368. void ClearFlashbangScreenFade ( void );
  369. bool ShouldDoLargeFlinch( int nHitGroup, CBaseEntity *pAttacker );
  370. void ResetStamina( void );
  371. bool IsArmored( int nHitGroup );
  372. void Pain( bool HasArmour );
  373. void DeathSound( const CTakeDamageInfo &info );
  374. bool Weapon_CanSwitchTo( CBaseCombatWeapon *pWeapon );
  375. void ChangeTeam( int iTeamNum );
  376. void SwitchTeam( int iTeamNum ); // Changes teams without penalty - used for auto team balancing
  377. void ModifyOrAppendPlayerCriteria( AI_CriteriaSet& set );
  378. virtual void OnDamagedByExplosion( const CTakeDamageInfo &info );
  379. // Called whenever this player fires a shot.
  380. void NoteWeaponFired();
  381. virtual bool WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, const CUserCmd *pCmd, const CBitVec<MAX_EDICTS> *pEntityTransmitBits ) const;
  382. // ------------------------------------------------------------------------------------------------ //
  383. // Player state management.
  384. // ------------------------------------------------------------------------------------------------ //
  385. public:
  386. void State_Transition( CSPlayerState newState ); // Cleanup the previous state and enter a new state.
  387. CSPlayerState State_Get() const; // Get the current state.
  388. private:
  389. void State_Enter( CSPlayerState newState ); // Initialize the new state.
  390. void State_Leave(); // Cleanup the previous state.
  391. void State_PreThink(); // Update the current state.
  392. // Find the state info for the specified state.
  393. static CCSPlayerStateInfo* State_LookupInfo( CSPlayerState state );
  394. // This tells us which state the player is currently in (joining, observer, dying, etc).
  395. // Each state has a well-defined set of parameters that go with it (ie: observer is movetype_noclip, nonsolid,
  396. // invisible, etc).
  397. CNetworkVar( CSPlayerState, m_iPlayerState );
  398. CCSPlayerStateInfo *m_pCurStateInfo; // This can be NULL if no state info is defined for m_iPlayerState.
  399. // tells us whether or not this player gets money at the start of the next round.
  400. bool m_receivesMoneyNextRound;
  401. // Specific state handler functions.
  402. void State_Enter_WELCOME();
  403. void State_PreThink_WELCOME();
  404. void State_Enter_PICKINGTEAM();
  405. void State_Enter_PICKINGCLASS();
  406. void State_Enter_ACTIVE();
  407. void State_PreThink_ACTIVE();
  408. void State_Enter_OBSERVER_MODE();
  409. void State_PreThink_OBSERVER_MODE();
  410. void State_Enter_DEATH_WAIT_FOR_KEY();
  411. void State_PreThink_DEATH_WAIT_FOR_KEY();
  412. void State_Enter_DEATH_ANIM();
  413. void State_PreThink_DEATH_ANIM();
  414. int FlashlightIsOn( void );
  415. void FlashlightTurnOn( void );
  416. void FlashlightTurnOff( void );
  417. void UpdateAddonBits();
  418. void UpdateRadar();
  419. public:
  420. void SetDeathPose( const int &iDeathPose ) { m_iDeathPose = iDeathPose; }
  421. void SetDeathPoseFrame( const int &iDeathPoseFrame ) { m_iDeathFrame = iDeathPoseFrame; }
  422. void SelectDeathPose( const CTakeDamageInfo &info );
  423. private:
  424. int m_iDeathPose;
  425. int m_iDeathFrame;
  426. //=============================================================================
  427. // HPE_BEGIN:
  428. // [menglish] Freeze cam function and variable declarations
  429. //=============================================================================
  430. bool m_bAbortFreezeCam;
  431. protected:
  432. void AttemptToExitFreezeCam( void );
  433. //=============================================================================
  434. // HPE_END
  435. //=============================================================================
  436. public:
  437. // Predicted variables.
  438. CNetworkVar( bool, m_bResumeZoom );
  439. CNetworkVar( int , m_iLastZoom ); // after firing a shot, set the FOV to 90, and after showing the animation, bring the FOV back to last zoom level.
  440. CNetworkVar( bool, m_bIsDefusing ); // tracks whether this player is currently defusing a bomb
  441. int m_LastHitGroup; // the last body region that took damage
  442. //=============================================================================
  443. // HPE_BEGIN:
  444. // [menglish] Adding two variables, keeping track of damage to the player
  445. //=============================================================================
  446. int m_LastHitBox; // the last body hitbox that took damage
  447. Vector m_vLastHitLocationObjectSpace; //position where last hit occured in space of the bone associated with the hitbox
  448. EHANDLE m_hDroppedEquipment[DROPPED_COUNT];
  449. // [tj] overriding the base suicides to trash CS specific stuff
  450. virtual void CommitSuicide( bool bExplode = false, bool bForce = false );
  451. virtual void CommitSuicide( const Vector &vecForce, bool bExplode = false, bool bForce = false );
  452. void WieldingKnifeAndKilledByGun( bool bState ) { m_bWieldingKnifeAndKilledByGun = bState; }
  453. bool WasWieldingKnifeAndKilledByGun() { return m_bWieldingKnifeAndKilledByGun; }
  454. // [dwenger] adding tracking for weapon used fun fact
  455. void PlayerUsedFirearm( CBaseCombatWeapon* pBaseWeapon );
  456. int GetNumFirearmsUsed() { return m_WeaponTypesUsed.Count(); }
  457. //=============================================================================
  458. // HPE_END
  459. //=============================================================================
  460. CNetworkVar( bool, m_bHasHelmet ); // Does the player have helmet armor
  461. bool m_bEscaped; // Has this terrorist escaped yet?
  462. // Other variables.
  463. bool m_bIsVIP; // Are we the VIP?
  464. int m_iNumSpawns; // Number of times player has spawned this round
  465. int m_iOldTeam; // Keep what team they were last on so we can allow joining spec and switching back to their real team
  466. bool m_bTeamChanged; // Just allow one team change per round
  467. CNetworkVar( int, m_iAccount ); // How much cash this player has.
  468. int m_iShouldHaveCash;
  469. bool m_bJustKilledTeammate;
  470. bool m_bPunishedForTK;
  471. int m_iTeamKills;
  472. float m_flLastMovement;
  473. int m_iNextTimeCheck; // Next time the player can execute a "timeleft" command
  474. float m_flNameChangeHistory[NAME_CHANGE_HISTORY_SIZE]; // index 0 = most recent change
  475. bool CanChangeName( void ); // Checks if the player can change his name
  476. void ChangeName( const char *pszNewName );
  477. void SetClanTag( const char *pTag );
  478. const char *GetClanTag( void ) const;
  479. CNetworkVar( bool, m_bHasDefuser ); // Does this player have a defuser kit?
  480. CNetworkVar( bool, m_bHasNightVision ); // Does this player have night vision?
  481. CNetworkVar( bool, m_bNightVisionOn ); // Is the NightVision turned on ?
  482. //=============================================================================
  483. // HPE_BEGIN:
  484. // [dwenger] Added for fun-fact support
  485. //=============================================================================
  486. //CNetworkVar( bool, m_bPickedUpDefuser ); // Did player pick up the defuser kit as opposed to buying it?
  487. //CNetworkVar( bool, m_bDefusedWithPickedUpKit); // Did player defuse the bomb with a picked-up defuse kit?
  488. //=============================================================================
  489. // HPE_END
  490. //=============================================================================
  491. float m_flLastRadarUpdateTime;
  492. // last known navigation area of player - NULL if unknown
  493. CNavArea *m_lastNavArea;
  494. // Backup copy of the menu text so the player can change this and the menu knows when to update.
  495. char m_MenuStringBuffer[MENU_STRING_BUFFER_SIZE];
  496. // When the player joins, it cycles their view between trigger_camera entities.
  497. // This is the current camera, and the time that we'll switch to the next one.
  498. EHANDLE m_pIntroCamera;
  499. float m_fIntroCamTime;
  500. // Set to true each frame while in a bomb zone.
  501. // Reset after prediction (in PostThink).
  502. CNetworkVar( bool, m_bInBombZone );
  503. CNetworkVar( bool, m_bInBuyZone );
  504. int m_iBombSiteIndex;
  505. bool IsInBuyZone();
  506. bool CanPlayerBuy( bool display );
  507. CNetworkVar( bool, m_bInHostageRescueZone );
  508. void RescueZoneTouch( inputdata_t &inputdata );
  509. CNetworkVar( float, m_flStamina );
  510. CNetworkVar( int, m_iDirection ); // The current lateral kicking direction; 1 = right, 0 = left
  511. CNetworkVar( int, m_iShotsFired ); // number of shots fired recently
  512. // Make sure to register changes for armor.
  513. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_ArmorValue );
  514. CNetworkVar( float, m_flVelocityModifier );
  515. int m_iHostagesKilled;
  516. void SetShieldDrawnState( bool bState );
  517. void DropShield( void );
  518. char m_szNewName [MAX_PLAYER_NAME_LENGTH]; // not empty if player requested a namechange
  519. char m_szClanTag[MAX_CLAN_TAG_LENGTH];
  520. Vector m_vecTotalBulletForce; //Accumulator for bullet force in a single frame
  521. CNetworkVar( float, m_flFlashDuration );
  522. CNetworkVar( float, m_flFlashMaxAlpha );
  523. CNetworkVar( float, m_flProgressBarStartTime );
  524. CNetworkVar( int, m_iProgressBarDuration );
  525. CNetworkVar( int, m_iThrowGrenadeCounter ); // used to trigger grenade throw animations.
  526. // Tracks our ragdoll entity.
  527. CNetworkHandle( CBaseEntity, m_hRagdoll ); // networked entity handle
  528. // Bots and hostages auto-duck during jumps
  529. bool m_duckUntilOnGround;
  530. Vector m_lastStandingPos; // used by the gamemovement code for finding ladders
  531. void SurpressLadderChecks( const Vector& pos, const Vector& normal );
  532. bool CanGrabLadder( const Vector& pos, const Vector& normal );
  533. CNetworkVar( bool, m_bDetected );
  534. private:
  535. CountdownTimer m_ladderSurpressionTimer;
  536. Vector m_lastLadderNormal;
  537. Vector m_lastLadderPos;
  538. protected:
  539. void CreateRagdollEntity();
  540. bool IsHittingShield( const Vector &vecDirection, trace_t *ptr );
  541. void PhysObjectSleep();
  542. void PhysObjectWake();
  543. bool RunMimicCommand( CUserCmd& cmd );
  544. bool SelectSpawnSpot( const char *pEntClassName, CBaseEntity* &pSpot );
  545. void SetModelFromClass( void );
  546. CNetworkVar( int, m_iClass ); // One of the CS_CLASS_ enums.
  547. bool CSWeaponDrop( CBaseCombatWeapon *pWeapon, bool bDropShield = true, bool bThrow = false );
  548. bool DropRifle( bool fromDeath = false );
  549. bool DropPistol( bool fromDeath = false );
  550. //=============================================================================
  551. // HPE_BEGIN:
  552. // [tj] Added a parameter so we know if it was death that caused the drop
  553. // [menglish] New parameter to always know if this is from death and not just an enemy death
  554. //=============================================================================
  555. void DropWeapons( bool fromDeath, bool friendlyFire );
  556. //=============================================================================
  557. // HPE_END
  558. //=============================================================================
  559. virtual int SpawnArmorValue( void ) const { return ArmorValue(); }
  560. BuyResult_e AttemptToBuyAmmo( int iAmmoType );
  561. BuyResult_e AttemptToBuyAmmoSingle( int iAmmoType );
  562. BuyResult_e AttemptToBuyVest( void );
  563. BuyResult_e AttemptToBuyAssaultSuit( void );
  564. BuyResult_e AttemptToBuyDefuser( void );
  565. BuyResult_e AttemptToBuyNightVision( void );
  566. BuyResult_e AttemptToBuyShield( void );
  567. BuyResult_e BuyAmmo( int nSlot, bool bBlinkMoney );
  568. BuyResult_e BuyGunAmmo( CBaseCombatWeapon *pWeapon, bool bBlinkMoney );
  569. void PushawayThink();
  570. private:
  571. ICSPlayerAnimState *m_PlayerAnimState;
  572. // Aiming heuristics code
  573. float m_flIdleTime; //Amount of time we've been motionless
  574. float m_flMoveTime; //Amount of time we've been in motion
  575. float m_flLastDamageTime; //Last time we took damage
  576. float m_flTargetFindTime;
  577. int m_lastDamageHealth; // Last damage given to our health
  578. int m_lastDamageArmor; // Last damage given to our armor
  579. //=============================================================================
  580. // HPE_BEGIN:
  581. // [dwenger] Added for fun-fact support
  582. //=============================================================================
  583. bool m_bPickedUpDefuser; // Did player pick up the defuser kit as opposed to buying it?
  584. bool m_bDefusedWithPickedUpKit; // Did player defuse the bomb with a picked-up defuse kit?
  585. //=============================================================================
  586. // HPE_END
  587. //=============================================================================
  588. // Last usercmd we shot a bullet on.
  589. int m_iLastWeaponFireUsercmd;
  590. // Copyed from EyeAngles() so we can send it to the client.
  591. CNetworkQAngle( m_angEyeAngles );
  592. bool m_bVCollisionInitted;
  593. // AutoBuy functions.
  594. public:
  595. void AutoBuy(); // this should take into account what the player can afford and should buy the best equipment for them.
  596. bool IsInAutoBuy( void ) { return m_bIsInAutoBuy; }
  597. bool IsInReBuy( void ) { return m_bIsInRebuy; }
  598. private:
  599. bool ShouldExecuteAutoBuyCommand(const AutoBuyInfoStruct *commandInfo, bool boughtPrimary, bool boughtSecondary);
  600. void PostAutoBuyCommandProcessing(const AutoBuyInfoStruct *commandInfo, bool &boughtPrimary, bool &boughtSecondary);
  601. void ParseAutoBuyString(const char *string, bool &boughtPrimary, bool &boughtSecondary);
  602. AutoBuyInfoStruct *GetAutoBuyCommandInfo(const char *command);
  603. void PrioritizeAutoBuyString(char *autobuyString, const char *priorityString); // reorders the tokens in autobuyString based on the order of tokens in the priorityString.
  604. BuyResult_e CombineBuyResults( BuyResult_e prevResult, BuyResult_e newResult );
  605. bool m_bIsInAutoBuy;
  606. bool m_bAutoReload;
  607. //ReBuy functions
  608. public:
  609. void Rebuy();
  610. private:
  611. void BuildRebuyStruct();
  612. BuyResult_e RebuyPrimaryWeapon();
  613. BuyResult_e RebuyPrimaryAmmo();
  614. BuyResult_e RebuySecondaryWeapon();
  615. BuyResult_e RebuySecondaryAmmo();
  616. BuyResult_e RebuyHEGrenade();
  617. BuyResult_e RebuyFlashbang();
  618. BuyResult_e RebuySmokeGrenade();
  619. BuyResult_e RebuyDefuser();
  620. BuyResult_e RebuyNightVision();
  621. BuyResult_e RebuyArmor();
  622. bool m_bIsInRebuy;
  623. RebuyStruct m_rebuyStruct;
  624. bool m_bUsingDefaultPistol;
  625. bool m_bIsBeingGivenItem;
  626. #ifdef CS_SHIELD_ENABLED
  627. CNetworkVar( bool, m_bHasShield );
  628. CNetworkVar( bool, m_bShieldDrawn );
  629. #endif
  630. // This is a combination of the ADDON_ flags in cs_shareddefs.h.
  631. CNetworkVar( int, m_iAddonBits );
  632. // Clients don't know about holstered weapons, so we need to tell them the weapon type here
  633. CNetworkVar( int, m_iPrimaryAddon );
  634. CNetworkVar( int, m_iSecondaryAddon );
  635. //Damage record functions
  636. public:
  637. static void StartNewBulletGroup(); // global function
  638. void RecordDamageTaken( const char *szDamageDealer, int iDamageTaken );
  639. void RecordDamageGiven( const char *szDamageTaker, int iDamageGiven );
  640. void ResetDamageCounters(); //Reset all lists
  641. void OutputDamageTaken( void );
  642. void OutputDamageGiven( void );
  643. void StockPlayerAmmo( CBaseCombatWeapon *pNewWeapon = NULL );
  644. CUtlLinkedList< CDamageRecord *, int >& GetDamageGivenList() {return m_DamageGivenList;}
  645. CUtlLinkedList< CDamageRecord *, int >& GetDamageTakenList() {return m_DamageTakenList;}
  646. private:
  647. //A list of damage given
  648. CUtlLinkedList< CDamageRecord *, int > m_DamageGivenList;
  649. //A list of damage taken
  650. CUtlLinkedList< CDamageRecord *, int > m_DamageTakenList;
  651. protected:
  652. float m_applyDeafnessTime;
  653. int m_currentDeafnessFilter;
  654. bool m_isVIP;
  655. // Command rate limiting.
  656. private:
  657. bool ShouldRunRateLimitedCommand( const CCommand &args );
  658. // This lets us rate limit the commands the players can execute so they don't overflow things like reliable buffers.
  659. CUtlDict<float,int> m_RateLimitLastCommandTimes;
  660. CNetworkVar(int, m_cycleLatch); // Every so often, we are going to transmit our cycle to the client to correct divergence caused by PVS changes
  661. CountdownTimer m_cycleLatchTimer;
  662. //=============================================================================
  663. // HPE_BEGIN:
  664. // [menglish, tj] Achievement-based addition to CS player class.
  665. //=============================================================================
  666. public:
  667. void ResetRoundBasedAchievementVariables();
  668. void OnRoundEnd(int winningTeam, int reason);
  669. void OnPreResetRound();
  670. int GetNumEnemyDamagers();
  671. int GetNumEnemiesDamaged();
  672. CBaseEntity* GetNearestSurfaceBelow(float maxTrace);
  673. // Returns the % of the enemies this player killed in the round
  674. int GetPercentageOfEnemyTeamKilled();
  675. //List of times of recent kills to check for sprees
  676. CUtlVector<float> m_killTimes;
  677. //List of all players killed this round
  678. CUtlVector<CHandle<CCSPlayer> > m_enemyPlayersKilledThisRound;
  679. //List of weapons we have used to kill players with this round
  680. CUtlVector<int> m_killWeapons;
  681. int m_NumEnemiesKilledThisRound;
  682. int m_NumEnemiesAtRoundStart;
  683. int m_KillingSpreeStartTime;
  684. float m_firstKillBlindStartTime; //This is the start time of the blind effect during which we got our most recent kill.
  685. int m_killsWhileBlind;
  686. bool m_bIsRescuing; // tracks whether this player is currently rescuing a hostage
  687. bool m_bInjuredAHostage; // tracks whether this player injured a hostage
  688. int m_iNumFollowers; // Number of hostages following this player
  689. bool m_bSurvivedHeadshotDueToHelmet;
  690. void IncrementNumFollowers() { m_iNumFollowers++; }
  691. void DecrementNumFollowers() { m_iNumFollowers--; if (m_iNumFollowers < 0) m_iNumFollowers = 0; }
  692. int GetNumFollowers() { return m_iNumFollowers; }
  693. void SetIsRescuing(bool in_bRescuing) { m_bIsRescuing = in_bRescuing; }
  694. bool IsRescuing() { return m_bIsRescuing; }
  695. void SetInjuredAHostage(bool in_bInjured) { m_bInjuredAHostage = in_bInjured; }
  696. bool InjuredAHostage() { return m_bInjuredAHostage; }
  697. float GetBombPickuptime() { return m_bombPickupTime; }
  698. void SetBombPickupTime(float time) { m_bombPickupTime = time; }
  699. CCSPlayer* GetLastFlashbangAttacker() { return m_lastFlashBangAttacker; }
  700. void SetLastFlashbangAttacker(CCSPlayer* attacker) { m_lastFlashBangAttacker = attacker; }
  701. static CSWeaponID GetWeaponIdCausingDamange( const CTakeDamageInfo &info );
  702. static void ProcessPlayerDeathAchievements( CCSPlayer *pAttacker, CCSPlayer *pVictim, const CTakeDamageInfo &info );
  703. void OnCanceledDefuse();
  704. void OnStartedDefuse();
  705. GooseChaseAchievementStep m_gooseChaseStep;
  706. DefuseDefenseAchivementStep m_defuseDefenseStep;
  707. CHandle<CCSPlayer> m_pGooseChaseDistractingPlayer;
  708. int m_lastRoundResult; //save the reason for the last round ending.
  709. bool m_bMadeFootstepNoise;
  710. float m_bombPickupTime;
  711. bool m_bMadePurchseThisRound;
  712. int m_roundsWonWithoutPurchase;
  713. bool m_bKilledDefuser;
  714. bool m_bKilledRescuer;
  715. int m_maxGrenadeKills;
  716. int m_grenadeDamageTakenThisRound;
  717. bool GetKilledDefuser() { return m_bKilledDefuser; }
  718. bool GetKilledRescuer() { return m_bKilledRescuer; }
  719. int GetMaxGrenadeKills() { return m_maxGrenadeKills; }
  720. void CheckMaxGrenadeKills(int grenadeKills);
  721. CHandle<CCSPlayer> m_lastFlashBangAttacker;
  722. void SetPlayerDominated( CCSPlayer *pPlayer, bool bDominated );
  723. void SetPlayerDominatingMe( CCSPlayer *pPlayer, bool bDominated );
  724. bool IsPlayerDominated( int iPlayerIndex );
  725. bool IsPlayerDominatingMe( int iPlayerIndex );
  726. bool m_wasNotKilledNaturally; //Set if the player is dead from a kill command or late login
  727. bool WasNotKilledNaturally() { return m_wasNotKilledNaturally; }
  728. //=============================================================================
  729. // [menglish] MVP functions
  730. //=============================================================================
  731. void SetNumMVPs( int iNumMVP );
  732. void IncrementNumMVPs( CSMvpReason_t mvpReason );
  733. int GetNumMVPs();
  734. //=============================================================================
  735. // HPE_END
  736. //=============================================================================
  737. void RemoveNemesisRelationships();
  738. void SetDeathFlags( int iDeathFlags ) { m_iDeathFlags = iDeathFlags; }
  739. int GetDeathFlags() { return m_iDeathFlags; }
  740. private:
  741. CNetworkArray( bool, m_bPlayerDominated, MAX_PLAYERS+1 ); // array of state per other player whether player is dominating other players
  742. CNetworkArray( bool, m_bPlayerDominatingMe, MAX_PLAYERS+1 ); // array of state per other player whether other players are dominating this player
  743. //=============================================================================
  744. // HPE_BEGIN:
  745. //=============================================================================
  746. // [menglish] number of rounds this player has caused to be won for their team
  747. int m_iMVPs;
  748. // [dwenger] adding tracking for fun fact
  749. bool m_bWieldingKnifeAndKilledByGun;
  750. // [dwenger] adding tracking for which weapons this player has used in a round
  751. CUtlVector<CSWeaponID> m_WeaponTypesUsed;
  752. //=============================================================================
  753. // HPE_END
  754. //=============================================================================
  755. int m_iDeathFlags; // Flags holding revenge and domination info about a death
  756. //=============================================================================
  757. // HPE_END
  758. //=============================================================================
  759. };
  760. inline CSPlayerState CCSPlayer::State_Get() const
  761. {
  762. return m_iPlayerState;
  763. }
  764. inline CCSPlayer *ToCSPlayer( CBaseEntity *pEntity )
  765. {
  766. if ( !pEntity || !pEntity->IsPlayer() )
  767. return NULL;
  768. return dynamic_cast<CCSPlayer*>( pEntity );
  769. }
  770. inline bool CCSPlayer::IsReloading( void ) const
  771. {
  772. CBaseCombatWeapon *gun = GetActiveWeapon();
  773. if (gun == NULL)
  774. return false;
  775. return gun->m_bInReload;
  776. }
  777. inline bool CCSPlayer::IsProtectedByShield( void ) const
  778. {
  779. return HasShield() && IsShieldDrawn();
  780. }
  781. inline bool CCSPlayer::IsBlind( void ) const
  782. {
  783. return gpGlobals->curtime < m_blindUntilTime;
  784. }
  785. //=============================================================================
  786. // HPE_BEGIN
  787. // [sbodenbender] Need a different test for player blindness for the achievements
  788. //=============================================================================
  789. inline bool CCSPlayer::IsBlindForAchievement()
  790. {
  791. return (m_blindStartTime + m_flFlashDuration) > gpGlobals->curtime;
  792. }
  793. //=============================================================================
  794. // HPE_END
  795. //=============================================================================
  796. inline bool CCSPlayer::IsAutoFollowAllowed( void ) const
  797. {
  798. return (gpGlobals->curtime > m_allowAutoFollowTime);
  799. }
  800. inline void CCSPlayer::InhibitAutoFollow( float duration )
  801. {
  802. m_allowAutoFollowTime = gpGlobals->curtime + duration;
  803. }
  804. inline void CCSPlayer::AllowAutoFollow( void )
  805. {
  806. m_allowAutoFollowTime = 0.0f;
  807. }
  808. inline int CCSPlayer::GetClass( void ) const
  809. {
  810. return m_iClass;
  811. }
  812. inline const char *CCSPlayer::GetClanTag( void ) const
  813. {
  814. return m_szClanTag;
  815. }
  816. #endif //CS_PLAYER_H