Counter Strike : Global Offensive Source Code
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.

138 lines
5.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines a connection (output-to-input) between two entities.
  4. //
  5. // The behavior in-game is as follows:
  6. //
  7. // When the given output in the source entity is triggered, the given
  8. // input in the target entity is called after a specified delay, and
  9. // the parameter override (if any) is passed to the input handler. If
  10. // there is no parameter override, the default parameter is passed.
  11. //
  12. // This behavior will occur a specified number of times before the
  13. // connection between the two entities is removed.
  14. //
  15. //=============================================================================//
  16. #ifndef ENTITYCONNECTION_H
  17. #define ENTITYCONNECTION_H
  18. #ifdef _WIN32
  19. #pragma once
  20. #endif
  21. #include "UtlVector.h"
  22. #include "fgdlib/InputOutput.h"
  23. #include "tier1/utlobjectreference.h"
  24. #define EVENT_FIRE_ALWAYS -1
  25. enum SortDirection_t
  26. {
  27. Sort_Ascending = 0,
  28. Sort_Descending,
  29. };
  30. enum
  31. {
  32. CONNECTION_NONE, // if entity list has no outputs
  33. CONNECTION_GOOD, // if all entity outpus are good
  34. CONNECTION_BAD, // if any entity output is bad
  35. };
  36. class CMapEntity;
  37. typedef CUtlReferenceVector<CMapEntity> CMapEntityList;
  38. class CMapDoc;
  39. class CEntityConnection
  40. {
  41. public:
  42. CEntityConnection(void);
  43. CEntityConnection(const CEntityConnection &Other );
  44. ~CEntityConnection();
  45. CEntityConnection &operator =(const CEntityConnection &Other);
  46. inline bool CompareConnection(CEntityConnection *pConnection);
  47. inline float GetDelay(void) { return(m_fDelay); }
  48. inline void SetDelay(float fDelay) { m_fDelay = fDelay; }
  49. inline const char *GetInputName(void) { return(m_szInput); }
  50. inline void SetInputName(const char *pszName) { lstrcpyn(m_szInput, pszName, sizeof(m_szInput)); }
  51. inline const char *GetOutputName(void) { return(m_szOutput); }
  52. inline void SetOutputName(const char *pszName) { lstrcpyn(m_szOutput, pszName, sizeof(m_szOutput)); }
  53. inline const char *GetTargetName(void) { return(m_szTargetEntity); }
  54. void SetTargetName(const char *pszName);
  55. inline const char *GetSourceName(void) { return(m_szSourceEntity); }
  56. void SetSourceName(const char *pszName);
  57. void LinkSourceEntities();
  58. void LinkTargetEntities();
  59. bool AreAnyTargetEntitiesVisible();
  60. inline CMapEntityList *GetSourceEntityList() { return m_pSourceEntityList; }
  61. inline CMapEntityList *GetTargetEntityList() { return m_pTargetEntityList; }
  62. inline int GetTimesToFire(void) { return(m_nTimesToFire); }
  63. inline void SetTimesToFire(int nTimesToFire) { m_nTimesToFire = nTimesToFire; }
  64. inline const char *GetParam(void) { return(m_szParam); }
  65. inline void SetParam(const char *pszParam) { lstrcpyn(m_szParam, pszParam, sizeof(m_szParam)); }
  66. // Sorting functions
  67. static int CALLBACK CompareDelaysSecondary(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  68. static int CALLBACK CompareDelays(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  69. static int CALLBACK CompareOutputNames(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  70. static int CALLBACK CompareInputNames(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  71. static int CALLBACK CompareSourceNames(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  72. static int CALLBACK CompareTargetNames(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  73. // Validation functions
  74. static bool ValidateOutput(const CMapEntity *pEntity, const char* pszOutput);
  75. static bool ValidateOutput(const CMapEntityList *pEntityList, const char* pszOutput);
  76. static bool ValidateTarget(const CMapEntityList *pEntityList, bool bVisibilityCheck, const char* pszTarget);
  77. static bool ValidateInput( const char *pszTarget, const char *pszInput, bool bVisiblesOnly, CMapDoc *pDoc = NULL );
  78. static int ValidateOutputConnections( CMapEntity *pEntity, bool bVisibilityCheck, bool bIgnoreHiddenTargets=false, bool CheckAllDocuments = false );
  79. static int ValidateInputConnections(CMapEntity *pEntity, bool bVisibilityCheck);
  80. static void FindBadConnections( CMapEntity *pEntity, bool bVisibilityCheck, CUtlVector<CEntityConnection *> &BadConnectionList, bool bIgnoreHiddenTargets=false, bool CheckAllDocuments = false );
  81. static void FixBadConnections(CMapEntity *pEntity, bool bVisibilityCheck);
  82. protected:
  83. char m_szSourceEntity[MAX_ENTITY_NAME_LEN]; // Targetname of the source entity
  84. CMapEntityList *m_pSourceEntityList;
  85. char m_szOutput[MAX_IO_NAME_LEN]; // Name of the output in the source entity.
  86. char m_szTargetEntity[MAX_ENTITY_NAME_LEN]; // Targetname of the target entity.
  87. CMapEntityList *m_pTargetEntityList;
  88. char m_szInput[MAX_IO_NAME_LEN]; // Name of the input to fire in the target entity.
  89. char m_szParam[MAX_IO_NAME_LEN]; // Parameter override, if any.
  90. float m_fDelay; // Delay before firing this outout.
  91. int m_nTimesToFire; // Maximum times to fire this output or EVENT_FIRE_ALWAYS.
  92. };
  93. typedef CUtlVector<CEntityConnection *> CEntityConnectionList;
  94. //-----------------------------------------------------------------------------
  95. // Purpose: Returns true if the given connection is identical to this connection.
  96. // Input : pConnection - Connection to compare.
  97. //-----------------------------------------------------------------------------
  98. bool CEntityConnection::CompareConnection(CEntityConnection *pConnection)
  99. {
  100. // BUGBUG - Why not compare the GetSourceName() values too? Why is this field not relevant?
  101. return((!stricmp(GetOutputName(), pConnection->GetOutputName())) &&
  102. (!stricmp(GetTargetName(), pConnection->GetTargetName())) &&
  103. (!stricmp(GetInputName(), pConnection->GetInputName())) &&
  104. (!stricmp(GetParam(), pConnection->GetParam())) &&
  105. (GetDelay() == pConnection->GetDelay()) &&
  106. (GetTimesToFire() == pConnection->GetTimesToFire()));
  107. }
  108. #endif // ENTITYCONNECTION_H