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.

254 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Player for HL1.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TFC_PLAYER_H
  8. #define TFC_PLAYER_H
  9. #pragma once
  10. #include "player.h"
  11. #include "server_class.h"
  12. #include "tfc_playeranimstate.h"
  13. #include "tfc_shareddefs.h"
  14. #include "tfc_player_shared.h"
  15. class CTFCPlayer;
  16. class CTFGoal;
  17. class CTFGoalItem;
  18. // Function table for each player state.
  19. class CPlayerStateInfo
  20. {
  21. public:
  22. TFCPlayerState m_iPlayerState;
  23. const char *m_pStateName;
  24. void (CTFCPlayer::*pfnEnterState)(); // Init and deinit the state.
  25. void (CTFCPlayer::*pfnLeaveState)();
  26. void (CTFCPlayer::*pfnThink)(); // Called every frame.
  27. };
  28. //=============================================================================
  29. // >> CounterStrike player
  30. //=============================================================================
  31. class CTFCPlayer : public CBasePlayer
  32. {
  33. public:
  34. DECLARE_CLASS( CTFCPlayer, CBasePlayer );
  35. DECLARE_SERVERCLASS();
  36. CTFCPlayer();
  37. ~CTFCPlayer();
  38. static CTFCPlayer *CreatePlayer( const char *className, edict_t *ed );
  39. static CTFCPlayer* Instance( int iEnt );
  40. // This passes the event to the client's and server's CPlayerAnimState.
  41. void DoAnimationEvent( PlayerAnimEvent_t event );
  42. virtual void PostThink();
  43. virtual void InitialSpawn();
  44. virtual void Spawn();
  45. virtual void Precache();
  46. virtual bool ClientCommand( const CCommand &args );
  47. virtual void ChangeTeam( int iTeamNum ) OVERRIDE;
  48. virtual int TakeHealth( float flHealth, int bitsDamageType );
  49. virtual void Event_Killed( const CTakeDamageInfo &info );
  50. void ClientHearVox( const char *pSentence );
  51. void DisplayLocalItemStatus( CTFGoal *pGoal );
  52. public:
  53. // Is this entity an ally (on our team)?
  54. bool IsAlly( CBaseEntity *pEnt ) const;
  55. TFCPlayerState State_Get() const; // Get the current state.
  56. void TF_AddFrags( int nFrags );
  57. void ResetMenu();
  58. // On fire..
  59. int GetNumFlames() const;
  60. void SetNumFlames( int nFlames );
  61. void ForceRespawn();
  62. void TeamFortress_SetSpeed();
  63. void TeamFortress_CheckClassStats();
  64. void TeamFortress_SetSkin();
  65. void TeamFortress_RemoveLiveGrenades();
  66. void TeamFortress_RemoveRockets();
  67. void TeamFortress_DetpackStop( void );
  68. BOOL TeamFortress_RemoveDetpacks( void );
  69. void RemovePipebombs( void );
  70. void RemoveOwnedEnt( char *pEntName );
  71. // SPY STUFF
  72. public:
  73. void Spy_RemoveDisguise();
  74. void TeamFortress_SpyCalcName();
  75. void Spy_ResetExternalWeaponModel( void );
  76. // ENGINEER STUFF
  77. public:
  78. void Engineer_RemoveBuildings();
  79. // Building
  80. BOOL is_building; // TRUE for an ENGINEER if they're building something
  81. EHANDLE building; // The building the ENGINEER is using
  82. float building_wait; // Used to prevent using a building again immediately
  83. EHANDLE real_owner;
  84. float has_dispenser; // TRUE if engineer has a dispenser
  85. float has_sentry; // TRUE if engineer has a sentry
  86. float has_entry_teleporter; // TRUE if engineer has an entry teleporter
  87. float has_exit_teleporter; // TRUE if engineer has an exit teleporter
  88. // DEMO STUFF
  89. public:
  90. int m_iPipebombCount;
  91. public:
  92. // Get the class info associated with us.
  93. const CTFCPlayerClassInfo* GetClassInfo() const;
  94. // Helpers to ease porting...
  95. int tp_grenades_1() const { return GetClassInfo()->m_iGrenadeType1; }
  96. int tp_grenades_2() const { return GetClassInfo()->m_iGrenadeType2; }
  97. int no_grenades_1() const { return GetAmmoCount( TFC_AMMO_GRENADES1 ); }
  98. int no_grenades_2() const { return GetAmmoCount( TFC_AMMO_GRENADES2 ); }
  99. public:
  100. CTFCPlayerShared m_Shared;
  101. int item_list; // Used to keep track of which goalitems are
  102. // affecting the player at any time.
  103. // GoalItems use it to keep track of their own
  104. // mask to apply to a player's item_list
  105. float armortype;
  106. //float armorvalue; // Use CBasePlayer::m_ArmorValue.
  107. int armorclass; // Type of armor being worn
  108. float armor_allowed;
  109. float invincible_finished;
  110. float invisible_finished;
  111. float super_damage_finished;
  112. float radsuit_finished;
  113. int lives; // The number of lives you have left
  114. int is_unableto_spy_or_teleport;
  115. BOOL bRemoveGrenade; // removes the primed grenade if set
  116. // Replacement_Model Stuff
  117. string_t replacement_model;
  118. int replacement_model_body;
  119. int replacement_model_skin;
  120. int replacement_model_flags;
  121. // Spy
  122. int undercover_team; // The team the Spy is pretending to be in
  123. int undercover_skin; // The skin the Spy is pretending to have
  124. EHANDLE undercover_target; // The player the Spy is pretending to be
  125. BOOL is_feigning; // TRUE for a SPY if they're feigning death
  126. float immune_to_check;
  127. BOOL is_undercover; // TRUE for a SPY if they're undercover
  128. // TEAMFORTRESS VARIABLES
  129. int no_sentry_message;
  130. int no_dispenser_message;
  131. // teleporter variables
  132. int no_entry_teleporter_message;
  133. int no_exit_teleporter_message;
  134. BOOL is_detpacking; // TRUE for a DEMOMAN if they're setting a detpack
  135. float current_menu; // is set to the number of the current menu, is 0 if they are not in a menu
  136. // State management.
  137. private:
  138. void State_Transition( TFCPlayerState newState );
  139. void State_Enter( TFCPlayerState newState );
  140. void State_Leave();
  141. CPlayerStateInfo* State_LookupInfo( TFCPlayerState state );
  142. CPlayerStateInfo *m_pCurStateInfo;
  143. void State_Enter_WELCOME();
  144. void State_Enter_PICKINGTEAM();
  145. void State_Enter_PICKINGCLASS();
  146. void State_Enter_ACTIVE();
  147. void State_Enter_OBSERVER_MODE();
  148. void State_Enter_DYING();
  149. private:
  150. friend void Bot_Think( CTFCPlayer *pBot );
  151. void HandleCommand_JoinTeam( const char *pTeamName );
  152. void HandleCommand_JoinClass( const char *pClassName );
  153. void GiveDefaultItems();
  154. void TFCPlayerThink();
  155. void PhysObjectSleep();
  156. void PhysObjectWake();
  157. void GetIntoGame();
  158. private:
  159. // Copyed from EyeAngles() so we can send it to the client.
  160. CNetworkQAngle( m_angEyeAngles );
  161. ITFCPlayerAnimState *m_PlayerAnimState;
  162. int m_iLegDamage;
  163. };
  164. inline CTFCPlayer *ToTFCPlayer( CBaseEntity *pEntity )
  165. {
  166. if ( !pEntity || !pEntity->IsPlayer() )
  167. return NULL;
  168. #ifdef _DEBUG
  169. Assert( dynamic_cast<CTFCPlayer*>( pEntity ) != 0 );
  170. #endif
  171. return static_cast< CTFCPlayer* >( pEntity );
  172. }
  173. inline const CTFCPlayerClassInfo* CTFCPlayer::GetClassInfo() const
  174. {
  175. return GetTFCClassInfo( m_Shared.GetPlayerClass() );
  176. }
  177. #endif // TFC_PLAYER_H