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.

137 lines
5.7 KiB

  1. //========= Copyright 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. #define EVENT_FIRE_ALWAYS -1
  24. enum SortDirection_t
  25. {
  26. Sort_Ascending = 0,
  27. Sort_Descending,
  28. };
  29. enum
  30. {
  31. CONNECTION_NONE, // if entity list has no outputs
  32. CONNECTION_GOOD, // if all entity outpus are good
  33. CONNECTION_BAD, // if any entity output is bad
  34. };
  35. class CMapEntity;
  36. typedef CUtlVector<CMapEntity*> CMapEntityList;
  37. class CEntityConnection
  38. {
  39. public:
  40. CEntityConnection(void);
  41. CEntityConnection(const CEntityConnection &Other );
  42. ~CEntityConnection();
  43. CEntityConnection &operator =(const CEntityConnection &Other);
  44. inline bool CompareConnection(CEntityConnection *pConnection);
  45. inline float GetDelay(void) { return(m_fDelay); }
  46. inline void SetDelay(float fDelay) { m_fDelay = fDelay; }
  47. inline const char *GetInputName(void) { return(m_szInput); }
  48. inline void SetInputName(const char *pszName) { lstrcpyn(m_szInput, pszName, sizeof(m_szInput)); }
  49. inline const char *GetOutputName(void) { return(m_szOutput); }
  50. inline void SetOutputName(const char *pszName) { lstrcpyn(m_szOutput, pszName, sizeof(m_szOutput)); }
  51. inline const char *GetTargetName(void) { return(m_szTargetEntity); }
  52. void SetTargetName(const char *pszName);
  53. inline const char *GetSourceName(void) { return(m_szSourceEntity); }
  54. void SetSourceName(const char *pszName);
  55. void LinkSourceEntities();
  56. void LinkTargetEntities();
  57. bool AreAnyTargetEntitiesVisible();
  58. inline CMapEntityList *GetSourceEntityList() { return m_pSourceEntityList; }
  59. inline CMapEntityList *GetTargetEntityList() { return m_pTargetEntityList; }
  60. inline int GetTimesToFire(void) { return(m_nTimesToFire); }
  61. inline void SetTimesToFire(int nTimesToFire) { m_nTimesToFire = nTimesToFire; }
  62. inline const char *GetParam(void) { return(m_szParam); }
  63. inline void SetParam(const char *pszParam) { lstrcpyn(m_szParam, pszParam, sizeof(m_szParam)); }
  64. // Sorting functions
  65. static int CALLBACK CompareDelaysSecondary(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  66. static int CALLBACK CompareDelays(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  67. static int CALLBACK CompareOutputNames(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  68. static int CALLBACK CompareInputNames(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  69. static int CALLBACK CompareSourceNames(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  70. static int CALLBACK CompareTargetNames(CEntityConnection *pConn1, CEntityConnection *pConn2, SortDirection_t eDirection);
  71. // Validation functions
  72. static bool ValidateOutput(CMapEntity *pEntity, const char* pszOutput);
  73. static bool ValidateOutput(const CMapEntityList *pEntityList, const char* pszOutput);
  74. static bool ValidateTarget(const CMapEntityList *pEntityList, bool bVisibilityCheck, const char* pszTarget);
  75. static bool ValidateInput(const char* pszTarget, const char* pszInput, bool bVisiblesOnly);
  76. static int ValidateOutputConnections(CMapEntity *pEntity, bool bVisibilityCheck, bool bIgnoreHiddenTargets=false );
  77. static int ValidateInputConnections(CMapEntity *pEntity, bool bVisibilityCheck);
  78. static void FindBadConnections(CMapEntity *pEntity, bool bVisibilityCheck, CUtlVector<CEntityConnection *> &BadConnectionList, bool bIgnoreHiddenTargets=false);
  79. static void FixBadConnections(CMapEntity *pEntity, bool bVisibilityCheck);
  80. protected:
  81. char m_szSourceEntity[MAX_ENTITY_NAME_LEN]; // Targetname of the source entity
  82. CMapEntityList *m_pSourceEntityList;
  83. char m_szOutput[MAX_IO_NAME_LEN]; // Name of the output in the source entity.
  84. char m_szTargetEntity[MAX_ENTITY_NAME_LEN]; // Targetname of the target entity.
  85. CMapEntityList *m_pTargetEntityList;
  86. char m_szInput[MAX_IO_NAME_LEN]; // Name of the input to fire in the target entity.
  87. char m_szParam[MAX_IO_NAME_LEN]; // Parameter override, if any.
  88. float m_fDelay; // Delay before firing this outout.
  89. int m_nTimesToFire; // Maximum times to fire this output or EVENT_FIRE_ALWAYS.
  90. };
  91. typedef CUtlVector<CEntityConnection *> CEntityConnectionList;
  92. //-----------------------------------------------------------------------------
  93. // Purpose: Returns true if the given connection is identical to this connection.
  94. // Input : pConnection - Connection to compare.
  95. //-----------------------------------------------------------------------------
  96. bool CEntityConnection::CompareConnection(CEntityConnection *pConnection)
  97. {
  98. // BUGBUG - Why not compare the GetSourceName() values too? Why is this field not relevant?
  99. return((!stricmp(GetOutputName(), pConnection->GetOutputName())) &&
  100. (!stricmp(GetTargetName(), pConnection->GetTargetName())) &&
  101. (!stricmp(GetInputName(), pConnection->GetInputName())) &&
  102. (!stricmp(GetParam(), pConnection->GetParam())) &&
  103. (GetDelay() == pConnection->GetDelay()) &&
  104. (GetTimesToFire() == pConnection->GetTimesToFire()));
  105. }
  106. #endif // ENTITYCONNECTION_H