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.

260 lines
7.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines the interface to a game class as defined by the game data
  4. // file (FGD). Each class is type of entity that can be placed in
  5. // the editor and has attributes such as: keys that may be set,
  6. // the default size and color of the entity, inputs and outputs,
  7. // and any default models that are created when the entity is placed.
  8. //
  9. // The game classes support multiple inheritence through aggregation
  10. // of properties.
  11. //
  12. //=============================================================================//
  13. #ifndef GDCLASS_H
  14. #define GDCLASS_H
  15. #ifdef _WIN32
  16. #pragma once
  17. #endif
  18. #include "HelperInfo.h"
  19. #include "TokenReader.h"
  20. #include "GDVar.h"
  21. #include "InputOutput.h"
  22. #include "mathlib/vector.h"
  23. class CHelperInfo;
  24. class GameData;
  25. class GDinputvariable;
  26. const int GD_MAX_VARIABLES = 128;
  27. class GDclass
  28. {
  29. public:
  30. GDclass(void);
  31. ~GDclass(void);
  32. //
  33. // Interface to class information:
  34. //
  35. inline const char *GetName(void) { return(m_szName); }
  36. inline const char *GetDescription(void);
  37. //
  38. // Reading a class from the game data file:
  39. //
  40. BOOL InitFromTokens(TokenReader& tr, GameData*);
  41. //
  42. // Interface to variable information (keys):
  43. //
  44. inline int GetVariableCount(void) { return(m_nVariables); }
  45. GDinputvariable *GetVariableAt(int iIndex);
  46. void GetHelperForGDVar( GDinputvariable *pVar, CUtlVector<const char *> *helperName );
  47. GDinputvariable *VarForName(const char *pszName, int *piIndex = NULL);
  48. BOOL AddVariable(GDinputvariable *pVar, GDclass *pBase, int iBaseIndex, int iVarIndex);
  49. void AddBase(GDclass *pBase);
  50. //
  51. // Interface to input information:
  52. //
  53. inline void AddInput(CClassInput *pInput);
  54. CClassInput *FindInput(const char *szName);
  55. inline int GetInputCount(void) { return(m_Inputs.Count()); }
  56. CClassInput *GetInput(int nIndex);
  57. //
  58. // Interface to output information:
  59. //
  60. inline void AddOutput(CClassOutput *pOutput);
  61. CClassOutput *FindOutput(const char *szName);
  62. inline int GetOutputCount(void) { return(m_Outputs.Count()); }
  63. CClassOutput *GetOutput(int nIndex);
  64. GameData *Parent;
  65. //
  66. // Interface to class attributes:
  67. //
  68. inline bool IsClass(const char *pszClass);
  69. inline bool IsSolidClass(void) { return(m_bSolid); }
  70. inline bool IsBaseClass(void) { return(m_bBase); }
  71. inline bool IsMoveClass(void) { return(m_bMove); }
  72. inline bool IsKeyFrameClass(void) { return(m_bKeyFrame); }
  73. inline bool IsPointClass(void) { return(m_bPoint); }
  74. inline bool IsNPCClass(void) { return(m_bNPC); }
  75. inline bool IsFilterClass(void) { return(m_bFilter); }
  76. inline bool IsNodeClass(void);
  77. static inline bool IsNodeClass(const char *pszClassName);
  78. inline bool ShouldSnapToHalfGrid() { return m_bHalfGridSnap; }
  79. inline void SetNPCClass(bool bNPC) { m_bNPC = bNPC; }
  80. inline void SetFilterClass(bool bFilter) { m_bFilter = bFilter; }
  81. inline void SetPointClass(bool bPoint) { m_bPoint = bPoint; }
  82. inline void SetSolidClass(bool bSolid) { m_bSolid = bSolid; }
  83. inline void SetBaseClass(bool bBase) { m_bBase = bBase; }
  84. inline void SetMoveClass(bool bMove) { m_bMove = bMove; }
  85. inline void SetKeyFrameClass(bool bKeyFrame) { m_bKeyFrame = bKeyFrame; }
  86. inline const Vector &GetMins(void) { return(m_bmins); }
  87. inline const Vector &GetMaxs(void) { return(m_bmaxs); }
  88. BOOL GetBoundBox(Vector& pfMins, Vector& pfMaxs);
  89. bool HasBoundBox() const { return m_bGotSize; }
  90. inline color32 GetColor(void);
  91. //
  92. // Interface to helper information:
  93. //
  94. inline void AddHelper(CHelperInfo *pHelper);
  95. inline int GetHelperCount(void) { return(m_Helpers.Count()); }
  96. CHelperInfo *GetHelper(int nIndex);
  97. protected:
  98. //
  99. // Parsing the game data file:
  100. //
  101. bool ParseInput(TokenReader &tr);
  102. bool ParseInputOutput(TokenReader &tr, CClassInputOutputBase *pInputOutput);
  103. bool ParseOutput(TokenReader &tr);
  104. bool ParseVariable(TokenReader &tr);
  105. private:
  106. bool ParseBase(TokenReader &tr);
  107. bool ParseColor(TokenReader &tr);
  108. bool ParseHelper(TokenReader &tr, char *pszHelperName);
  109. bool ParseSize(TokenReader &tr);
  110. bool ParseSpecifiers(TokenReader &tr);
  111. bool ParseVariables(TokenReader &tr);
  112. color32 m_rgbColor; // Color of entity.
  113. bool m_bBase; // Base only - not available to user.
  114. bool m_bSolid; // Tied to solids only.
  115. bool m_bModel; // Properties of a single model.
  116. bool m_bMove; // Animatable
  117. bool m_bKeyFrame; // Animation keyframe
  118. bool m_bPoint; // Point class, not tied to solids.
  119. bool m_bNPC; // NPC class - used for populating lists of NPC classes.
  120. bool m_bFilter; // filter class - used for populating lists of filters.
  121. bool m_bHalfGridSnap; // Snaps to a 1/2 grid so it can be centered on any geometry. Used for hinges, etc.
  122. bool m_bGotSize; // Just for loading.
  123. bool m_bGotColor;
  124. char m_szName[MAX_IDENT]; // Name of this class.
  125. char *m_pszDescription; // Description of this class, dynamically allocated.
  126. CUtlVector<GDinputvariable *> m_Variables; // Variables for this class.
  127. int m_nVariables; // Count of base & local variables combined.
  128. CUtlVector<GDclass *> m_Bases; // List of base classes this class inherits from.
  129. CClassInputList m_Inputs;
  130. CClassOutputList m_Outputs;
  131. CHelperInfoList m_Helpers; // Helpers for this class.
  132. //
  133. // [0] = base number from Bases, or -1 if not in a base.
  134. // [1] = index into base's variables
  135. //
  136. signed short m_VariableMap[GD_MAX_VARIABLES][2];
  137. Vector m_bmins; // 3D minima of object (pointclass).
  138. Vector m_bmaxs; // 3D maxima of object (pointclass).
  139. };
  140. void GDclass::AddInput(CClassInput *pInput)
  141. {
  142. Assert(pInput != NULL);
  143. if (pInput != NULL)
  144. {
  145. m_Inputs.AddToTail(pInput);
  146. }
  147. }
  148. inline void GDclass::AddOutput(CClassOutput *pOutput)
  149. {
  150. Assert(pOutput != NULL);
  151. if (pOutput != NULL)
  152. {
  153. m_Outputs.AddToTail(pOutput);
  154. }
  155. }
  156. inline void GDclass::AddHelper(CHelperInfo *pHelper)
  157. {
  158. Assert(pHelper != NULL);
  159. if (pHelper != NULL)
  160. {
  161. m_Helpers.AddToTail(pHelper);
  162. }
  163. }
  164. //-----------------------------------------------------------------------------
  165. // Purpose: Returns the render color of this entity class.
  166. //-----------------------------------------------------------------------------
  167. color32 GDclass::GetColor(void)
  168. {
  169. return m_rgbColor;
  170. }
  171. //-----------------------------------------------------------------------------
  172. // Purpose: Returns a description of this entity class, or the entity class name
  173. // if no description exists.
  174. //-----------------------------------------------------------------------------
  175. const char *GDclass::GetDescription(void)
  176. {
  177. if (m_pszDescription == NULL)
  178. {
  179. return(m_szName);
  180. }
  181. return(m_pszDescription);
  182. }
  183. //-----------------------------------------------------------------------------
  184. // Purpose:
  185. // Input : pszClass -
  186. //-----------------------------------------------------------------------------
  187. bool GDclass::IsClass(const char *pszClass)
  188. {
  189. Assert(pszClass != NULL);
  190. return(!stricmp(pszClass, m_szName));
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Purpose: Returns true if the given classname represents an AI node class, false if not.
  194. //-----------------------------------------------------------------------------
  195. bool GDclass::IsNodeClass(const char *pszClassName)
  196. {
  197. return((strnicmp(pszClassName, "info_node", 9) == 0) && (stricmp(pszClassName, "info_node_link") != 0));
  198. }
  199. //-----------------------------------------------------------------------------
  200. // Purpose: Returns true if this is an AI node class, false if not.
  201. //
  202. // HACK: if this is necessary, we should have a new @NodeClass FGD specifier (or something)
  203. //-----------------------------------------------------------------------------
  204. bool GDclass::IsNodeClass(void)
  205. {
  206. return(IsNodeClass(m_szName));
  207. }
  208. #endif // GDCLASS_H