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.

234 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef EDITGAMECLASS_H
  7. #define EDITGAMECLASS_H
  8. #pragma once
  9. #pragma warning(push, 1)
  10. #pragma warning(disable:4701 4702 4530)
  11. #include <fstream>
  12. #pragma warning(pop)
  13. #include "BlockArray.h"
  14. #include "fgdlib/fgdlib.h"
  15. #include "fgdlib/WCKeyValues.h"
  16. #include "EntityConnection.h"
  17. #define MAX_CLASS_NAME_LEN 64
  18. class CChunkFile;
  19. class CMapClass;
  20. class CSaveInfo;
  21. enum ChunkFileResult_t;
  22. //-----------------------------------------------------------------------------
  23. // Purpose:
  24. //-----------------------------------------------------------------------------
  25. class CEditGameClass
  26. {
  27. public:
  28. CEditGameClass(void);
  29. ~CEditGameClass(void);
  30. inline bool IsClass(const char *pszClass = NULL);
  31. inline GDclass *GetClass(void) { return(m_pClass); }
  32. inline void SetClass(GDclass *pClass) { m_pClass = pClass; }
  33. inline const char* GetClassName(void) { return(m_szClass); }
  34. inline bool IsKeyFrameClass(void) { return((m_pClass != NULL) && (m_pClass->IsKeyFrameClass())); }
  35. inline bool IsMoveClass(void) { return((m_pClass != NULL) && (m_pClass->IsMoveClass())); }
  36. inline bool IsPointClass(void) { return((m_pClass != NULL) && (m_pClass->IsPointClass())); }
  37. inline bool IsNPCClass(void) { return((m_pClass != NULL) && (m_pClass->IsNPCClass())); }
  38. inline bool IsFilterClass(void) { return((m_pClass != NULL) && (m_pClass->IsFilterClass())); }
  39. inline bool IsSolidClass(void) { return((m_pClass != NULL) && (m_pClass->IsSolidClass())); }
  40. inline bool IsNodeClass(void) { return((m_pClass != NULL) && (m_pClass->IsNodeClass())); }
  41. static inline bool IsNodeClass(const char *pszClassName) { return GDclass::IsNodeClass(pszClassName); }
  42. //
  43. // Interface to key/value information:
  44. //
  45. virtual void SetKeyValue(LPCTSTR pszKey, LPCTSTR pszValue) { m_KeyValues.SetValue(pszKey, pszValue); }
  46. virtual void DeleteKeyValue(LPCTSTR pszKey) { m_KeyValues.RemoveKey(pszKey); }
  47. inline void RemoveKey(int nIndex) { m_KeyValues.RemoveKeyAt(nIndex); }
  48. inline void SetKeyValue(LPCTSTR pszKey, int iValue) { m_KeyValues.SetValue(pszKey, iValue); }
  49. inline LPCTSTR GetKey(int nIndex) { return(m_KeyValues.GetKey(nIndex)); }
  50. inline LPCTSTR GetKeyValue(int nIndex) { return(m_KeyValues.GetValue(nIndex)); }
  51. inline LPCTSTR GetKeyValue(LPCTSTR pszKey, int *piIndex = NULL) { return(m_KeyValues.GetValue(pszKey, piIndex)); }
  52. // Iterate the list of keyvalues.
  53. inline int GetFirstKeyValue() const { return m_KeyValues.GetFirst(); }
  54. inline int GetNextKeyValue( int i ) const { return m_KeyValues.GetNext( i ); }
  55. static inline int GetInvalidKeyValue() { return WCKeyValues::GetInvalidIndex(); }
  56. //
  57. // Interface to spawnflags.
  58. //
  59. bool GetSpawnFlag(unsigned long nFlag);
  60. unsigned long GetSpawnFlags(void);
  61. void SetSpawnFlag(unsigned long nFlag, bool bSet);
  62. void SetSpawnFlags(unsigned long nFlags);
  63. //
  64. // Interface to entity connections.
  65. //
  66. void Connections_Add(CEntityConnection *pConnection);
  67. inline int Connections_GetCount(void);
  68. inline CEntityConnection *Connections_Get(int nIndex);
  69. bool Connections_Remove(CEntityConnection *pConnection);
  70. void Connections_RemoveAll(void);
  71. void Connections_FixBad(bool bRelink = true);
  72. //
  73. // Interface to entity connections.
  74. //
  75. void Upstream_Add(CEntityConnection *pConnection);
  76. inline int Upstream_GetCount(void);
  77. inline CEntityConnection *Upstream_Get(int nIndex);
  78. bool Upstream_Remove(CEntityConnection *pConnection);
  79. void Upstream_RemoveAll(void);
  80. void Upstream_FixBad();
  81. //
  82. // Interface to comments.
  83. //
  84. inline const char *GetComments(void);
  85. inline void SetComments(const char *pszComments);
  86. //
  87. // Serialization functions.
  88. //
  89. static ChunkFileResult_t LoadConnectionsCallback(CChunkFile *pFile, CEditGameClass *pEditGameClass);
  90. static ChunkFileResult_t LoadKeyCallback(const char *szKey, const char *szValue, CEditGameClass *pEditGameClass);
  91. ChunkFileResult_t SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo);
  92. int SerializeRMF(std::fstream&, BOOL);
  93. int SerializeMAP(std::fstream&, BOOL);
  94. virtual void SetClass(LPCTSTR pszClassname, bool bLoading = false);
  95. CEditGameClass *CopyFrom(CEditGameClass *pFrom);
  96. void GetDefaultKeys( void );
  97. virtual void SetAngles(const QAngle &vecAngles);
  98. virtual void GetAngles(QAngle &vecAngles);
  99. // Import the old-style yaw only representation of orientation.
  100. void ImportAngle(int nAngle);
  101. protected:
  102. WCKeyValues m_KeyValues;
  103. GDclass *m_pClass;
  104. char m_szClass[MAX_CLASS_NAME_LEN];
  105. char *m_pszComments; // Comments text, dynamically allocated.
  106. static char *g_pszEmpty;
  107. CEntityConnectionList m_Connections;
  108. CEntityConnectionList m_Upstream;
  109. };
  110. //-----------------------------------------------------------------------------
  111. // Purpose: Returns the number of input/output connections that this object has.
  112. //-----------------------------------------------------------------------------
  113. int CEditGameClass::Connections_GetCount(void)
  114. {
  115. return m_Connections.Count();
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Purpose: Returns the number of input/output connections that this object has.
  119. //-----------------------------------------------------------------------------
  120. CEntityConnection *CEditGameClass::Connections_Get(int nIndex)
  121. {
  122. return m_Connections.Element(nIndex);
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose: Returns the number of input/output connections that this object has.
  126. //-----------------------------------------------------------------------------
  127. int CEditGameClass::Upstream_GetCount(void)
  128. {
  129. return m_Upstream.Count();
  130. }
  131. //-----------------------------------------------------------------------------
  132. // Purpose: Returns the number of input/output connections that this object has.
  133. //-----------------------------------------------------------------------------
  134. CEntityConnection *CEditGameClass::Upstream_Get(int nIndex)
  135. {
  136. return m_Upstream.Element(nIndex);
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose: Returns the comments text, NULL if none have been set.
  140. //-----------------------------------------------------------------------------
  141. const char *CEditGameClass::GetComments(void)
  142. {
  143. if (m_pszComments == NULL)
  144. {
  145. return(g_pszEmpty);
  146. }
  147. return(m_pszComments);
  148. }
  149. //-----------------------------------------------------------------------------
  150. // Purpose:
  151. // Input : NULL -
  152. // Output : inline bool
  153. //-----------------------------------------------------------------------------
  154. inline bool CEditGameClass::IsClass(const char *pszClass)
  155. {
  156. if (pszClass == NULL)
  157. {
  158. return(m_pClass != NULL);
  159. }
  160. return((m_pClass != NULL) && (!stricmp(pszClass, m_szClass)));
  161. }
  162. //-----------------------------------------------------------------------------
  163. // Purpose:
  164. // Input : pszComments -
  165. //-----------------------------------------------------------------------------
  166. void CEditGameClass::SetComments(const char *pszComments)
  167. {
  168. delete m_pszComments;
  169. if (pszComments != NULL)
  170. {
  171. int nLen = strlen(pszComments);
  172. if (nLen == 0)
  173. {
  174. m_pszComments = NULL;
  175. }
  176. else
  177. {
  178. m_pszComments = new char [nLen + 1];
  179. strcpy(m_pszComments, pszComments);
  180. }
  181. }
  182. else
  183. {
  184. m_pszComments = NULL;
  185. }
  186. }
  187. #endif // EDITGAMECLASS_H