summaryrefslogtreecommitdiff
path: root/hammer/editgameclass.h
blob: 6c547e2d275a773a8385c2fa6e6625815e247782 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#ifndef EDITGAMECLASS_H
#define EDITGAMECLASS_H
#pragma once

#pragma warning(push, 1)
#pragma warning(disable:4701 4702 4530)
#include <fstream>
#pragma warning(pop)
#include "BlockArray.h"
#include "fgdlib/fgdlib.h"
#include "fgdlib/WCKeyValues.h"
#include "EntityConnection.h"


#define MAX_CLASS_NAME_LEN		64


class CChunkFile;
class CMapClass;
class CSaveInfo;


enum ChunkFileResult_t;


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class CEditGameClass
{
	public:

		CEditGameClass(void);
		~CEditGameClass(void);

		inline bool IsClass(const char *pszClass = NULL);
		inline GDclass *GetClass(void) { return(m_pClass); }
		inline void SetClass(GDclass *pClass) { m_pClass = pClass; }
		inline const char* GetClassName(void) { return(m_szClass); }
		inline bool IsKeyFrameClass(void) { return((m_pClass != NULL) && (m_pClass->IsKeyFrameClass())); }
		inline bool IsMoveClass(void) { return((m_pClass != NULL) && (m_pClass->IsMoveClass())); }
		inline bool IsPointClass(void) { return((m_pClass != NULL) && (m_pClass->IsPointClass())); }
		inline bool IsNPCClass(void) { return((m_pClass != NULL) && (m_pClass->IsNPCClass())); }
		inline bool IsFilterClass(void) { return((m_pClass != NULL) && (m_pClass->IsFilterClass())); }
		inline bool IsSolidClass(void) { return((m_pClass != NULL) && (m_pClass->IsSolidClass())); }
		inline bool IsNodeClass(void) { return((m_pClass != NULL) && (m_pClass->IsNodeClass())); }
		static inline bool IsNodeClass(const char *pszClassName) { return GDclass::IsNodeClass(pszClassName); }

		//
		// Interface to key/value information:
		//
		virtual void SetKeyValue(LPCTSTR pszKey, LPCTSTR pszValue) { m_KeyValues.SetValue(pszKey, pszValue); }
		virtual void DeleteKeyValue(LPCTSTR pszKey) { m_KeyValues.RemoveKey(pszKey); }

		inline void RemoveKey(int nIndex) { m_KeyValues.RemoveKeyAt(nIndex); }
		inline void SetKeyValue(LPCTSTR pszKey, int iValue) { m_KeyValues.SetValue(pszKey, iValue); }
		inline LPCTSTR GetKey(int nIndex) { return(m_KeyValues.GetKey(nIndex)); }
		inline LPCTSTR GetKeyValue(int nIndex) { return(m_KeyValues.GetValue(nIndex)); }
		inline LPCTSTR GetKeyValue(LPCTSTR pszKey, int *piIndex = NULL) { return(m_KeyValues.GetValue(pszKey, piIndex)); }
		
		// Iterate the list of keyvalues.
		inline int GetFirstKeyValue() const			{ return m_KeyValues.GetFirst(); }
		inline int GetNextKeyValue( int i ) const	{ return m_KeyValues.GetNext( i ); }
		static inline int GetInvalidKeyValue()		{ return WCKeyValues::GetInvalidIndex(); }

		//
		// Interface to spawnflags.
		//
		bool GetSpawnFlag(unsigned long nFlag);
		unsigned long GetSpawnFlags(void);
		void SetSpawnFlag(unsigned long nFlag, bool bSet);
		void SetSpawnFlags(unsigned long nFlags);

		//
		// Interface to entity connections.
		//
		void Connections_Add(CEntityConnection *pConnection);
		inline int Connections_GetCount(void);
		inline CEntityConnection *Connections_Get(int nIndex);
		bool Connections_Remove(CEntityConnection *pConnection);
		void Connections_RemoveAll(void);
		void Connections_FixBad(bool bRelink = true);

		//
		// Interface to entity connections.
		//
		void Upstream_Add(CEntityConnection *pConnection);
		inline int Upstream_GetCount(void);
		inline CEntityConnection *Upstream_Get(int nIndex);
		bool Upstream_Remove(CEntityConnection *pConnection);
		void Upstream_RemoveAll(void);
		void Upstream_FixBad();

		//
		// Interface to comments.
		//
		inline const char *GetComments(void);
		inline void SetComments(const char *pszComments);

		//
		// Serialization functions.
		//
		static ChunkFileResult_t LoadConnectionsCallback(CChunkFile *pFile, CEditGameClass *pEditGameClass);
		static ChunkFileResult_t LoadKeyCallback(const char *szKey, const char *szValue, CEditGameClass *pEditGameClass);

		ChunkFileResult_t SaveVMF(CChunkFile *pFile, CSaveInfo *pSaveInfo);

		int SerializeRMF(std::fstream&, BOOL);
		int SerializeMAP(std::fstream&, BOOL);

		virtual void SetClass(LPCTSTR pszClassname, bool bLoading = false);
		CEditGameClass *CopyFrom(CEditGameClass *pFrom);
		void GetDefaultKeys( void );

		virtual void SetAngles(const QAngle &vecAngles);
		virtual void GetAngles(QAngle &vecAngles);

		// Import the old-style yaw only representation of orientation.
		void ImportAngle(int nAngle);

	protected:

		WCKeyValues m_KeyValues;
		GDclass *m_pClass;
		char m_szClass[MAX_CLASS_NAME_LEN];
		char *m_pszComments;		// Comments text, dynamically allocated.

		static char *g_pszEmpty;

		CEntityConnectionList m_Connections;
		CEntityConnectionList m_Upstream;
};


//-----------------------------------------------------------------------------
// Purpose: Returns the number of input/output connections that this object has.
//-----------------------------------------------------------------------------
int CEditGameClass::Connections_GetCount(void)
{
	return m_Connections.Count();
}


//-----------------------------------------------------------------------------
// Purpose: Returns the number of input/output connections that this object has.
//-----------------------------------------------------------------------------
CEntityConnection *CEditGameClass::Connections_Get(int nIndex)
{
	return m_Connections.Element(nIndex);
}


//-----------------------------------------------------------------------------
// Purpose: Returns the number of input/output connections that this object has.
//-----------------------------------------------------------------------------
int CEditGameClass::Upstream_GetCount(void)
{
	return m_Upstream.Count();
}


//-----------------------------------------------------------------------------
// Purpose: Returns the number of input/output connections that this object has.
//-----------------------------------------------------------------------------
CEntityConnection *CEditGameClass::Upstream_Get(int nIndex)
{
	return m_Upstream.Element(nIndex);
}


//-----------------------------------------------------------------------------
// Purpose: Returns the comments text, NULL if none have been set.
//-----------------------------------------------------------------------------
const char *CEditGameClass::GetComments(void)
{
	if (m_pszComments == NULL)
	{
		return(g_pszEmpty);
	}

	return(m_pszComments);
}


//-----------------------------------------------------------------------------
// Purpose: 
// Input  : NULL - 
// Output : inline bool
//-----------------------------------------------------------------------------
inline bool CEditGameClass::IsClass(const char *pszClass)
{
	if (pszClass == NULL)
	{
		return(m_pClass != NULL);
	}
	return((m_pClass != NULL) && (!stricmp(pszClass, m_szClass)));
}


//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pszComments - 
//-----------------------------------------------------------------------------
void CEditGameClass::SetComments(const char *pszComments)
{
	delete m_pszComments;

	if (pszComments != NULL)
	{
		int nLen = strlen(pszComments);
		if (nLen == 0)
		{
			m_pszComments = NULL;
		}
		else
		{
			m_pszComments = new char [nLen + 1];
			strcpy(m_pszComments, pszComments);
		}
	}
	else
	{
		m_pszComments = NULL;
	}
}


#endif // EDITGAMECLASS_H