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.

166 lines
6.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef PROP_PORTAL_H
  8. #define PROP_PORTAL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "baseanimating.h"
  13. #include "PortalSimulation.h"
  14. // FIX ME
  15. #include "portal_shareddefs.h"
  16. static const char *s_pDelayedPlacementContext = "DelayedPlacementContext";
  17. static const char *s_pTestRestingSurfaceContext = "TestRestingSurfaceContext";
  18. static const char *s_pFizzleThink = "FizzleThink";
  19. class CPhysicsCloneArea;
  20. class CProp_Portal : public CBaseAnimating, public CPortalSimulatorEventCallbacks
  21. {
  22. public:
  23. DECLARE_CLASS( CProp_Portal, CBaseAnimating );
  24. DECLARE_SERVERCLASS();
  25. DECLARE_DATADESC();
  26. CProp_Portal( void );
  27. virtual ~CProp_Portal( void );
  28. CNetworkHandle( CProp_Portal, m_hLinkedPortal ); //the portal this portal is linked to
  29. VMatrix m_matrixThisToLinked; //the matrix that will transform a point relative to this portal, to a point relative to the linked portal
  30. CNetworkVar( bool, m_bActivated ); //a portal can exist and not be active
  31. CNetworkVar( bool, m_bIsPortal2 ); //For teleportation, this doesn't matter, but for drawing and moving, it matters
  32. Vector m_vPrevForward; //used for the indecisive push in find closest passable spaces when portal is moved
  33. bool m_bSharedEnvironmentConfiguration; //this will be set by an instance of CPortal_Environment when two environments are in close proximity
  34. EHANDLE m_hMicrophone; //the microphone for teleporting sound
  35. EHANDLE m_hSpeaker; //the speaker for teleported sound
  36. CSoundPatch *m_pAmbientSound;
  37. Vector m_vAudioOrigin;
  38. Vector m_vDelayedPosition;
  39. QAngle m_qDelayedAngles;
  40. int m_iDelayedFailure;
  41. EHANDLE m_hPlacedBy;
  42. COutputEvent m_OnPlacedSuccessfully; // Output in hammer for when this portal was successfully placed (not attempted and fizzed).
  43. cplane_t m_plane_Origin; //a portal plane on the entity origin
  44. CPhysicsCloneArea *m_pAttachedCloningArea;
  45. bool IsPortal2() const;
  46. void SetIsPortal2( bool bIsPortal2 );
  47. const VMatrix& MatrixThisToLinked() const;
  48. virtual int UpdateTransmitState( void ) // set transmit filter to transmit always
  49. {
  50. return SetTransmitState( FL_EDICT_ALWAYS );
  51. }
  52. virtual void Precache( void );
  53. virtual void CreateSounds( void );
  54. virtual void StopLoopingSounds( void );
  55. virtual void Spawn( void );
  56. virtual void Activate( void );
  57. virtual void OnRestore( void );
  58. virtual void UpdateOnRemove( void );
  59. void DelayedPlacementThink( void );
  60. void TestRestingSurfaceThink ( void );
  61. void FizzleThink( void );
  62. bool IsActivedAndLinked( void ) const;
  63. void WakeNearbyEntities( void ); //wakes all nearby entities in-case there's been a significant change in how they can rest near a portal
  64. void ForceEntityToFitInPortalWall( CBaseEntity *pEntity ); //projects an object's center into the middle of the portal wall hall, and traces back to where it wants to be
  65. void PlacePortal( const Vector &vOrigin, const QAngle &qAngles, float fPlacementSuccess, bool bDelay = false );
  66. void NewLocation( const Vector &vOrigin, const QAngle &qAngles );
  67. void ResetModel( void ); //sets the model and bounding box
  68. void DoFizzleEffect( int iEffect, bool bDelayedPos = true ); //display cool visual effect
  69. void Fizzle( void ); //go inactive
  70. void PunchPenetratingPlayer( CBaseEntity *pPlayer ); // adds outward force to player intersecting the portal plane
  71. void PunchAllPenetratingPlayers( void ); // adds outward force to player intersecting the portal plane
  72. virtual void StartTouch( CBaseEntity *pOther );
  73. virtual void Touch( CBaseEntity *pOther );
  74. virtual void EndTouch( CBaseEntity *pOther );
  75. bool ShouldTeleportTouchingEntity( CBaseEntity *pOther ); //assuming the entity is or was just touching the portal, check for teleportation conditions
  76. void TeleportTouchingEntity( CBaseEntity *pOther );
  77. void InputSetActivatedState( inputdata_t &inputdata );
  78. void InputFizzle( inputdata_t &inputdata );
  79. void InputNewLocation( inputdata_t &inputdata );
  80. void UpdatePortalLinkage( void );
  81. void UpdatePortalTeleportMatrix( void ); //computes the transformation from this portal to the linked portal, and will update the remote matrix as well
  82. //void SendInteractionMessage( CBaseEntity *pEntity, bool bEntering ); //informs clients that the entity is interacting with a portal (mostly used for clip planes)
  83. bool SharedEnvironmentCheck( CBaseEntity *pEntity ); //does all testing to verify that the object is better handled with this portal instead of the other
  84. // The four corners of the portal in worldspace, updated on placement. The four points will be coplanar on the portal plane.
  85. Vector m_vPortalCorners[4];
  86. CPortalSimulator m_PortalSimulator;
  87. //virtual bool CreateVPhysics( void );
  88. //virtual void VPhysicsDestroyObject( void );
  89. virtual bool TestCollision( const Ray_t &ray, unsigned int fContentsMask, trace_t& tr );
  90. virtual void PortalSimulator_TookOwnershipOfEntity( CBaseEntity *pEntity );
  91. virtual void PortalSimulator_ReleasedOwnershipOfEntity( CBaseEntity *pEntity );
  92. private:
  93. unsigned char m_iLinkageGroupID; //a group ID specifying which portals this one can possibly link to
  94. CPhysCollide *m_pCollisionShape;
  95. void RemovePortalMicAndSpeaker(); // Cleans up the portal's internal audio members
  96. void UpdateCorners( void ); // Updates the four corners of this portal on spawn and placement
  97. public:
  98. inline unsigned char GetLinkageGroup( void ) const { return m_iLinkageGroupID; };
  99. void ChangeLinkageGroup( unsigned char iLinkageGroupID );
  100. //find a portal with the designated attributes, or creates one with them, favors active portals over inactive
  101. static CProp_Portal *FindPortal( unsigned char iLinkageGroupID, bool bPortal2, bool bCreateIfNothingFound = false );
  102. static const CUtlVector<CProp_Portal *> *GetPortalLinkageGroup( unsigned char iLinkageGroupID );
  103. };
  104. //-----------------------------------------------------------------------------
  105. // inline state querying methods
  106. //-----------------------------------------------------------------------------
  107. inline bool CProp_Portal::IsPortal2() const
  108. {
  109. return m_bIsPortal2;
  110. }
  111. inline void CProp_Portal::SetIsPortal2( bool bIsPortal2 )
  112. {
  113. m_bIsPortal2 = bIsPortal2;
  114. }
  115. inline const VMatrix& CProp_Portal::MatrixThisToLinked() const
  116. {
  117. return m_matrixThisToLinked;
  118. }
  119. #endif //#ifndef PROP_PORTAL_H