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.

513 lines
17 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Base Object built by a player
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TF_OBJ_H
  8. #define TF_OBJ_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "baseentity.h"
  13. #include "ihasbuildpoints.h"
  14. #include "iscorer.h"
  15. #include "baseobject_shared.h"
  16. #include "utlmap.h"
  17. #include "props_shared.h"
  18. #include "tf_achievementdata.h"
  19. //#include "tf_player.h"
  20. class CTFPlayer;
  21. class CTFTeam;
  22. class CRopeKeyframe;
  23. class CVGuiScreen;
  24. class KeyValues;
  25. class CTFWrench;
  26. class CTFAmmoPack;
  27. class CObjectSapper;
  28. struct animevent_t;
  29. #define WRENCH_DMG_VS_SAPPER 65
  30. #define OBJ_MAX_UPGRADE_LEVEL 3
  31. #define OBJECT_REPAIR_RATE 10 // Health healed per second while repairing
  32. // Construction
  33. #define OBJECT_CONSTRUCTION_INTERVAL 0.1
  34. #define OBJECT_CONSTRUCTION_STARTINGHEALTH 0.1
  35. extern ConVar object_verbose;
  36. extern ConVar obj_child_range_factor;
  37. #if defined( _DEBUG )
  38. #define TRACE_OBJECT( str ) \
  39. if ( object_verbose.GetInt() ) \
  40. { \
  41. Msg( "%s", str ); \
  42. }
  43. #else
  44. #define TRACE_OBJECT( string )
  45. #endif
  46. #define SF_BASEOBJ_INVULN (1<<1)
  47. #define LAST_SF_BASEOBJ SF_BASEOBJ_INVULN
  48. DECLARE_AUTO_LIST( IBaseObjectAutoList );
  49. enum
  50. {
  51. SHIELD_NONE = 0,
  52. SHIELD_NORMAL, // 33% damage taken, no tracking
  53. SHIELD_MAX, // 10% damage taken, tracking
  54. };
  55. #define SHIELD_NORMAL_VALUE 0.33f
  56. #define SHIELD_MAX_VALUE 0.10f
  57. // ------------------------------------------------------------------------ //
  58. // Resupply object that's built by the player
  59. // ------------------------------------------------------------------------ //
  60. class CBaseObject : public CBaseCombatCharacter, public IHasBuildPoints, public IScorer, public IBaseObjectAutoList
  61. {
  62. DECLARE_CLASS( CBaseObject, CBaseCombatCharacter );
  63. public:
  64. CBaseObject();
  65. virtual void UpdateOnRemove( void );
  66. DECLARE_SERVERCLASS();
  67. DECLARE_DATADESC();
  68. virtual bool IsBaseObject( void ) const { return true; }
  69. virtual void BaseObjectThink( void );
  70. //virtual void LostPowerThink( void );
  71. virtual CTFPlayer *GetOwner( void );
  72. // Creation
  73. virtual void Precache();
  74. virtual void Spawn( void );
  75. virtual void FirstSpawn( void );
  76. virtual bool ShouldCollide( int collisionGroup, int contentsMask ) const;
  77. virtual void SetBuilder( CTFPlayer *pBuilder );
  78. virtual void SetType( int iObjectType );
  79. int ObjectType( ) const;
  80. virtual int BloodColor( void ) { return BLOOD_COLOR_MECH; }
  81. // Building
  82. virtual float GetTotalTime( void );
  83. virtual void StartPlacement( CTFPlayer *pPlayer );
  84. void StopPlacement( void );
  85. bool FindNearestBuildPoint( CBaseEntity *pEntity, CBasePlayer *pBuilder, float &flNearestPoint, Vector &vecNearestBuildPoint, bool bIgnoreChecks = false );
  86. bool FindBuildPointOnPlayer( CTFPlayer *pTFPlayer, CBasePlayer *pBuilder, float &flNearestPoint, Vector &vecNearestBuildPoint );
  87. bool VerifyCorner( const Vector &vBottomCenter, float xOffset, float yOffset );
  88. virtual float GetNearbyObjectCheckRadius( void ) { return 30.0; }
  89. bool UpdatePlacement( void );
  90. bool UpdateAttachmentPlacement( CBaseObject *pObjectOverride = NULL );
  91. bool IsValidPlacement( void ) const;
  92. virtual bool IsPlacementPosValid( void );
  93. bool FindSnapToBuildPos( CBaseObject *pObjectOverride = NULL );
  94. void ReattachChildren( void );
  95. // I've finished building the specified object on the specified build point
  96. virtual int FindObjectOnBuildPoint( CBaseObject *pObject );
  97. virtual bool StartBuilding( CBaseEntity *pPlayer );
  98. virtual void SetStartBuildingModel( void ) {}
  99. void BuildingThink( void );
  100. void SetControlPanelsActive( bool bState );
  101. virtual void FinishedBuilding( void );
  102. bool IsBuilding( void ) { return m_bBuilding; }
  103. bool IsPlacing( void ) { return m_bPlacing; }
  104. virtual bool IsUpgrading( void ) const { return false; }
  105. bool MustBeBuiltOnAttachmentPoint( void ) const;
  106. bool IsCarried( void ) const { return m_bCarried; }
  107. virtual void OnEndBeingCarried( CBaseEntity *pBuilder ) {}
  108. // Returns information about the various control panels
  109. virtual void GetControlPanelInfo( int nPanelIndex, const char *&pPanelName );
  110. virtual void GetControlPanelClassName( int nPanelIndex, const char *&pPanelName );
  111. // Client commands sent by clicking on various panels....
  112. // NOTE: pArg->Argv(0) == pCmd, pArg->Argv(1) == the first argument
  113. virtual bool ClientCommand( CTFPlayer *pSender, const CCommand &args );
  114. // Damage
  115. void SetHealth( float flHealth );
  116. float GetHealth() { return m_flHealth; }
  117. virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  118. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  119. bool PassDamageOntoChildren( const CTakeDamageInfo &info, float *flDamageLeftOver );
  120. virtual bool Construct( float flHealth );
  121. void OnConstructionHit( CTFPlayer *pPlayer, CTFWrench *pWrench, Vector hitLoc );
  122. virtual float GetConstructionMultiplier( void );
  123. // Destruction
  124. virtual void DetonateObject( void );
  125. virtual bool ShouldAutoRemove( void );
  126. virtual void Explode( void );
  127. virtual void Killed( const CTakeDamageInfo &info );
  128. virtual void DestroyObject( void ); // Silent cleanup
  129. virtual bool IsDying( void ) { return m_bDying; }
  130. void DestroyScreens( void );
  131. // Data
  132. virtual Class_T Classify( void );
  133. virtual int GetType( void ) const;
  134. virtual CTFPlayer *GetBuilder( void ) const;
  135. CTFTeam *GetTFTeam( void ) { return (CTFTeam*)GetTeam(); };
  136. // ID functions
  137. virtual bool IsAnUpgrade( void ) { return false; }
  138. virtual bool IsHostileUpgrade( void ) { return false; } // Attaches to enemy buildings
  139. // Inputs
  140. void InputSetHealth( inputdata_t &inputdata );
  141. void InputAddHealth( inputdata_t &inputdata );
  142. void InputRemoveHealth( inputdata_t &inputdata );
  143. void InputSetSolidToPlayer( inputdata_t &inputdata );
  144. void InputSetBuilder( inputdata_t &inputdata );
  145. void InputShow( inputdata_t &inputdata );
  146. void InputHide( inputdata_t &inputdata );
  147. virtual void InputEnable( inputdata_t &inputdata );
  148. virtual void InputDisable( inputdata_t &inputdata );
  149. // Wrench hits
  150. virtual bool InputWrenchHit( CTFPlayer *pPlayer, CTFWrench *pWrench, Vector hitLoc );
  151. virtual bool OnWrenchHit( CTFPlayer *pPlayer, CTFWrench *pWrench, Vector hitLoc );
  152. virtual bool CheckUpgradeOnHit( CTFPlayer *pPlayer );
  153. virtual bool Command_Repair( CTFPlayer *pActivator, float flRepairMod );
  154. virtual void DoWrenchHitEffect( Vector hitLoc, bool bRepairHit, bool bUpgradeHit );
  155. virtual bool ShouldBeMiniBuilding( CTFPlayer* pPlayer );
  156. virtual void MakeMiniBuilding( CTFPlayer* pPlayer );
  157. virtual void MakeDisposableBuilding( CTFPlayer *pPlayer );
  158. virtual void ChangeTeam( int iTeamNum ) OVERRIDE; // Assign this entity to a team.
  159. // Handling object inactive
  160. virtual bool ShouldBeActive( void );
  161. // Sappers
  162. CObjectSapper* GetSapper( void );
  163. bool HasSapper( void );
  164. bool IsPlasmaDisabled( void );
  165. void OnAddSapper( void );
  166. void OnRemoveSapper( void );
  167. // Returns the object flags
  168. int GetObjectFlags() const { return m_fObjectFlags; }
  169. void SetObjectFlags( int flags ) { m_fObjectFlags = flags; }
  170. virtual void OnGoActive( void );
  171. virtual void OnGoInactive( void );
  172. // Disabling
  173. bool IsDisabled( void ) { return m_bDisabled || m_bCarried; }
  174. virtual void UpdateDisabledState( void );
  175. void SetDisabled( bool bDisabled );
  176. virtual void OnStartDisabled( void );
  177. virtual void OnEndDisabled( void );
  178. void SetPlasmaDisabled( float flDuration );
  179. // Animation
  180. virtual void PlayStartupAnimation( void );
  181. Activity GetActivity( ) const;
  182. void SetActivity( Activity act );
  183. void SetObjectSequence( int sequence );
  184. // Object points
  185. void SpawnObjectPoints( void );
  186. // Derive to customize an object's attached version
  187. virtual void SetupAttachedVersion( void ) { return; }
  188. virtual int DrawDebugTextOverlays( void );
  189. void RotateBuildAngles( void );
  190. virtual bool ShouldPlayersAvoid( void );
  191. void IncrementKills( void ) { m_iKills++; }
  192. int GetKills() { return m_iKills; }
  193. void IncrementAssists( void ) { m_iAssists++; }
  194. int GetAssists() { return m_iAssists; }
  195. void CreateObjectGibs( void );
  196. CTFAmmoPack* CreateAmmoPack( const char *pchModel, int nMetal );
  197. virtual void SetModel( const char *pModel );
  198. const char *GetResponseRulesModifier( void );
  199. // Map Placed
  200. virtual void Activate( void );
  201. virtual void InitializeMapPlacedObject( void );
  202. bool CannotDie() const { return m_bCannotDie; }
  203. void SetCannotDie( bool bCannotDie ) { m_bCannotDie = bCannotDie; }
  204. // Upgrading
  205. virtual bool CanBeUpgraded( CTFPlayer *pPlayer );
  206. virtual void StartUpgrading( void );
  207. virtual void FinishUpgrading( void );
  208. void UpgradeThink( void );
  209. virtual int GetUpgradeLevel( void ) const { return m_iUpgradeLevel; }
  210. int GetUpgradeMetal( void ) const { return m_iUpgradeMetal; }
  211. int GetHighestUpgradeLevel( void ) { return Min( (int)m_iHighestUpgradeLevel, GetMaxUpgradeLevel() ); }
  212. void SetHighestUpgradeLevel( int nLevel ) { m_iHighestUpgradeLevel = Min( nLevel, GetMaxUpgradeLevel() ); }
  213. void ApplyHealthUpgrade( void );
  214. virtual int GetBaseHealth( void ) = 0;
  215. void DoQuickBuild( bool bForceMax = false );
  216. bool ShouldQuickBuild( void );
  217. void DoReverseBuild( void );
  218. float GetReversesBuildingConstructionSpeed( void );
  219. virtual int GetMaxUpgradeLevel( void ) { return OBJ_MAX_UPGRADE_LEVEL; }
  220. // Carrying
  221. virtual void MakeCarriedObject( CTFPlayer *pCarrier );
  222. virtual void DropCarriedObject( CTFPlayer* pCarrier );
  223. void ForceQuickBuild() { m_bForceQuickBuild = true; }
  224. virtual int GetMiniBuildingStartingHealth( void ) { return 100; }
  225. virtual int GetMaxHealthForCurrentLevel( void );
  226. bool IsUsingReverseBuild( void ){ return ( GetReversesBuildingConstructionSpeed() != 0.0f ); }
  227. void ResetPlacement( void );
  228. virtual bool TestHitboxes( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  229. // IScorer interface
  230. virtual CBasePlayer *GetScorer( void ) { return ( CBasePlayer *)GetBuilder(); }
  231. virtual CBasePlayer *GetAssistant( void ) { return NULL; }
  232. // Achievement tracking
  233. // Achievement data storage
  234. CAchievementData m_AchievementData;
  235. // Client/Server shared build point code
  236. void CreateBuildPoints( void );
  237. void AddAndParseBuildPoint( int iAttachmentNumber, KeyValues *pkvBuildPoint );
  238. virtual int AddBuildPoint( int iAttachmentNum );
  239. virtual void AddValidObjectToBuildPoint( int iPoint, int iObjectType );
  240. virtual CBaseObject *GetBuildPointObject( int iPoint );
  241. bool IsBuiltOnAttachment( void ) { return (m_hBuiltOnEntity.Get() != NULL); }
  242. CBaseEntity *GetBuiltOnObject( void ){ return m_hBuiltOnEntity.Get(); }
  243. void AttachObjectToObject( CBaseEntity *pEntity, int iPoint, Vector &vecOrigin );
  244. virtual void DetachObjectFromObject( void );
  245. CBaseObject *GetParentObject( void );
  246. CBaseEntity *GetParentEntity( void );
  247. virtual void SetObjectMode( int iVal ) { m_iObjectMode = iVal; }
  248. int GetObjectMode( void ) const { return m_iObjectMode; }
  249. float GetConstructionStartTime( void ) { return m_flConstructionStartTime; }
  250. // IHasBuildPoints
  251. virtual int GetNumBuildPoints( void ) const;
  252. virtual bool GetBuildPoint( int iPoint, Vector &vecOrigin, QAngle &vecAngles );
  253. virtual int GetBuildPointAttachmentIndex( int iPoint ) const;
  254. virtual bool CanBuildObjectOnBuildPoint( int iPoint, int iObjectType );
  255. virtual void SetObjectOnBuildPoint( int iPoint, CBaseObject *pObject );
  256. virtual float GetMaxSnapDistance( int iBuildPoint );
  257. virtual bool ShouldCheckForMovement( void ) { return true; }
  258. virtual int GetNumObjectsOnMe();
  259. virtual CBaseEntity *GetFirstFriendlyObjectOnMe( void );
  260. virtual CBaseObject *GetObjectOfTypeOnMe( int iObjectType );
  261. virtual void RemoveAllObjects( void );
  262. // IServerNetworkable.
  263. virtual int UpdateTransmitState( void );
  264. virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo );
  265. virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
  266. bool IsMiniBuilding( void ) const { return m_bMiniBuilding; }
  267. bool IsDisposableBuilding( void ) const { return m_bDisposableBuilding; }
  268. virtual bool ShouldBlockNav() const OVERRIDE { return false; }
  269. bool IsMapPlaced( void ){ return m_bWasMapPlaced; }
  270. virtual int GetShieldLevel() { return SHIELD_NONE; }
  271. virtual bool CanBeRepaired() const { return !IsDisposableBuilding(); }
  272. protected:
  273. virtual bool CanBeUpgraded() const { return !( IsDisposableBuilding() || IsMiniBuilding() ); }
  274. virtual int GetUpgradeMetalRequired();
  275. // Show/hide vgui screens.
  276. bool ShowVGUIScreen( int panelIndex, bool bShow );
  277. // Spawns the various control panels
  278. void SpawnControlPanels();
  279. virtual void DetermineAnimation( void );
  280. virtual void DeterminePlaybackRate( void );
  281. void UpdateDesiredBuildRotation( float flFrameTime );
  282. bool CalculatePlacementPos( void );
  283. bool EstimateValidBuildPos( void );
  284. private:
  285. // Purpose: Spawn any objects specified inside the mdl
  286. void SpawnEntityOnBuildPoint( const char *pEntityName, int iAttachmentNumber );
  287. //bool TestPositionForPlayerBlock( Vector vecBuildOrigin, CBasePlayer *pPlayer );
  288. //void RecursiveTestBuildSpace( int iNode, bool *bNodeClear, bool *bNodeVisited );
  289. protected:
  290. enum OBJSOLIDTYPE
  291. {
  292. SOLID_TO_PLAYER_USE_DEFAULT = 0,
  293. SOLID_TO_PLAYER_YES,
  294. SOLID_TO_PLAYER_NO,
  295. };
  296. bool IsSolidToPlayers( void ) const;
  297. // object flags....
  298. CNetworkVar( int, m_fObjectFlags );
  299. CNetworkHandle( CTFPlayer, m_hBuilder );
  300. // Placement
  301. Vector m_vecBuildOrigin;
  302. Vector m_vecBuildCenterOfMass;
  303. CNetworkVector( m_vecBuildMaxs );
  304. CNetworkVector( m_vecBuildMins );
  305. CNetworkHandle( CBaseEntity, m_hBuiltOnEntity );
  306. int m_iBuiltOnPoint;
  307. bool m_bDying;
  308. // Outputs
  309. COutputEvent m_OnDestroyed;
  310. COutputEvent m_OnDamaged;
  311. COutputEvent m_OnRepaired;
  312. COutputEvent m_OnBecomingDisabled;
  313. COutputEvent m_OnBecomingReenabled;
  314. COutputFloat m_OnObjectHealthChanged;
  315. // Control panel
  316. typedef CHandle<CVGuiScreen> ScreenHandle_t;
  317. CUtlVector<ScreenHandle_t> m_hScreens;
  318. // Map placed objects
  319. CNetworkVar( bool, m_bWasMapPlaced );
  320. float GetCarryDeployTime() { return m_flCarryDeployTime; }
  321. public:
  322. // Upgrade Level ( 1, 2, 3 )
  323. CNetworkVar( int, m_iUpgradeLevel );
  324. CNetworkVar( int, m_iUpgradeMetal );
  325. CNetworkVar( int, m_iUpgradeMetalRequired );
  326. CNetworkVar( int, m_iHighestUpgradeLevel );
  327. int m_nDefaultUpgradeLevel;
  328. float m_flUpgradeCompleteTime; // Time when the upgrade animation will complete
  329. private:
  330. // Make sure we pick up changes to these.
  331. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_iHealth );
  332. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_takedamage );
  333. Activity m_Activity;
  334. CNetworkVar( int, m_iObjectType );
  335. // True if players shouldn't do collision avoidance, but should just collide exactly with the object.
  336. OBJSOLIDTYPE m_SolidToPlayers;
  337. void SetSolidToPlayers( OBJSOLIDTYPE stp, bool force = false );
  338. CNetworkVar( int , m_iObjectMode );
  339. // Disabled
  340. CNetworkVar( bool, m_bDisabled );
  341. // Building
  342. CNetworkVar( bool, m_bPlacing ); // True while the object's being placed
  343. CNetworkVar( bool, m_bBuilding ); // True while the object's still constructing itself
  344. protected:
  345. float m_flConstructionTimeLeft; // Current time left in construction
  346. float m_flTotalConstructionTime; // Total construction time (the value of GetTotalTime() at the time construction
  347. // started, ie, incase you teleport out of a construction yard)
  348. float m_flConstructionStartTime;
  349. protected:
  350. // Carried
  351. CNetworkVar( bool, m_bCarried );
  352. CNetworkVar( bool, m_bCarryDeploy );
  353. CNetworkVar( bool, m_bMiniBuilding );
  354. CNetworkVar( bool, m_bDisposableBuilding );
  355. float m_flPlasmaDisableTime;
  356. CNetworkVar( bool, m_bPlasmaDisable );
  357. private:
  358. int m_iHealthOnPickup;
  359. float m_flCarryDeployTime;
  360. CNetworkVar( float, m_flPercentageConstructed ); // Used to send to client
  361. float m_flHealth; // Health during construction. Needed a float due to small increases in health.
  362. // Sapper on me
  363. CNetworkVar( bool, m_bHasSapper );
  364. // Build points
  365. CUtlVector<BuildPoint_t> m_BuildPoints;
  366. // Maps player ent index to repair expire time
  367. struct constructor_t
  368. {
  369. float flHitTime; // Time this constructor last hit me
  370. float flValue; // Speed value of this constructor. Defaults to 1.0, but some constructors are worth more.
  371. };
  372. CUtlMap<int, constructor_t> m_ConstructorList;
  373. // Result of last placement test
  374. bool m_bPlacementOK; // last placement state
  375. CNetworkVar( int, m_iKills );
  376. CNetworkVar( int, m_iAssists );
  377. CNetworkVar( int, m_iDesiredBuildRotations ); // Number of times we've rotated, used to calc final rotation
  378. float m_flCurrentBuildRotation;
  379. // Gibs.
  380. CUtlVector<breakmodel_t> m_aGibs;
  381. CNetworkVar( bool, m_bServerOverridePlacement );
  382. // for ACHIEVEMENT_TF_ENGINEER_TANK_DAMAGE
  383. int m_iLifetimeDamage;
  384. bool m_bCannotDie;
  385. bool m_bQuickBuild;
  386. // used when calculating the placement position
  387. Vector m_vecBuildForward;
  388. float m_flBuildDistance;
  389. bool m_bForceQuickBuild;
  390. };
  391. extern short g_sModelIndexFireball; // holds the index for the fireball
  392. #endif // TF_OBJ_H