Subversion Repositories spk

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#ifndef _XSPFILE_H__
2
#define _XSPFILE_H__
3
 
6 cycrow 4
#include "BaseFile.h"
1 cycrow 5
#include "ShipData.h"
6
#include "StringList.h"
35 cycrow 7
#include "VirtualFileSystem.h"
1 cycrow 8
 
9
class CCatFile;
10
 
11
#define SHIPYARD_NONE		  0
12
#define SHIPYARD_ARGON		  1
13
#define SHIPYARD_BORON		  2
14
#define SHIPYARD_PARANID	  4
15
#define SHIPYARD_SPLIT		  8
16
#define SHIPYARD_TELADI		 16
17
#define SHIPYARD_PIRATES	 32
18
#define SHIPYARD_FRIEND		 64
19
#define SHIPYARD_XENON		128
20
#define SHIPYARD_TERRAN		256
21
#define SHIPYARD_ATF		512
22
#define SHIPYARD_YAKI		1024
23
 
24
#define SHIPYARD_MAX	SHIPYARD_TERRAN
25
 
26
enum {TAT_NONE, TAT_SINGLE, TAT_3};
27
 
28
#define TSHIPPOS_CLASS		53
29
 
30
enum {IMPORTSHIP_NONE, IMPORTSHIP_SCENE, IMPORTSHIP_EXTRACTSCENE, IMPORTSHIP_DUMMIES, IMPORTSHIP_COMPONANT, IMPORTSHIP_MODELS, IMPORTSHIP_TEXTURES, IMPORTSHIP_TEXTS, IMPORTSHIP_BODIES, IMPORTSHIP_COCKPITS, IMPORTSHIP_PACK, IMPORTSHIP_DONE};
31
 
32
int		 SPKEXPORT GetMaxShipyards ();
33
CyString SPKEXPORT GetShipyardName (int s);
34
 
35
typedef struct SWeaponMask {
36
	int		iMask;
37
	int		iGame;
38
} SWeaponMask;
39
 
40
typedef struct SText
41
{
42
	int		iId;
43
	CyString sName;
44
	CyString sDesc;
45
} SText;
46
 
47
typedef struct SDummy
48
{
49
	CyString	sSection;
50
	CyString sData;
51
} SDummy;
52
 
53
typedef struct SComponent
54
{
55
	CyString sSection;
56
	CyString sSection2;
57
	CyString sData;
58
} SComponent;
59
 
60
typedef struct SCockpit
61
{
62
	CyString	   sCockpit;
63
	CLinkList<SWeaponMask> lWeaponMask;
64
	int				iIndex;
65
} SCockpit;
66
 
35 cycrow 67
using namespace SPK;
1 cycrow 68
 
69
class SPKEXPORT CXspFile : public CBaseFile
70
{
71
public:
72
	CXspFile ();
73
	~CXspFile () { this->Delete(); }
74
 
75
	static bool ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord);
76
	static int GetAnimationType(CyString type);
77
 
78
	virtual bool WriteHeader ( FILE *id, int, int );
79
 
80
	bool IsLanguageText () { return m_bLanguageText; }
81
	bool IsExistingShip () { return m_bExistingShip; }
82
 
83
	int  GetOriginalDescription () { return m_iOrgDesc; }
84
	int  GetShipyards () { return m_iShipyard; }
85
 
14 cycrow 86
	const Utils::String &GetShipID () const { return m_sID; }
87
	const Utils::String &GetShipData () const { return m_sData; }
1 cycrow 88
	CyString GetX3ShipData();
89
	CyString GetTCShipData();
90
	CyString GetShipFilename () 
91
	{ 
92
		CyString s = m_sName + "-" + m_sAuthor; 
93
		s = s.Remove ( ' ' );
94
		s = s.Remove ( '\\' );
95
		s = s.Remove ( '/' );
96
		return s;
97
	}
98
 
99
	SText *FindShipText(int lang);
100
	CyString GetTextName(int lang);
101
	CyString GetTextDescription(int lang);
102
 
103
	void SetLanguageText		( bool b )   { m_bLanguageText = b; m_bChanged = true; }
104
	void SetExistingShip		( bool b )   { m_bExistingShip = b; m_bChanged = true; }
105
	void SetOriginalDescription	( int i )	 { m_iOrgDesc = i; m_bChanged = true; }
14 cycrow 106
	void SetShipID				(const Utils::String &sId ) { m_sID = sId; m_bChanged = true; }
107
	void SetShipData			(const Utils::String &sData ) { m_sData = sData; m_bChanged = true; }
1 cycrow 108
 
109
	void SetSceneFile ( C_File *f ) { m_pSceneFile = f; }
110
	void SetCockpitFile ( C_File *f ) { m_pCockpitFile = f; }
111
 
112
	void AddAnimation(CyStringList *list);
113
	void AddAnimation(CyString data) { m_lAnimations.PushBack(data, true); m_bChanged = true; }
114
	void AddBodies(CyString data);
115
	void AddBody(CyString section, CyString data);
116
	void AddCutData(CyString data) { m_lCutData.PushBack(data, true); m_bChanged = true; }
117
	void AddText ( int id, CyString name, CyString desc );
118
	void AddCockpit ( CyString cockpit, int game, int mask = -1, int index = -1 );
119
	void NewCockpit ( CyString id, CyString scene, int mask );
120
	void EditCockpit ( CyString id, CyString cockpit);
121
	void EditCockpit(CyString id, CyString scene, int mask);
122
	CyString GetCockpitData(CyString id);
123
	SCockpit *FindCockpit(CyString id);
124
	void AddDummy ( CyString section, CyString data );
125
	void AddComponent ( CyString section, CyString section2, CyString data );
126
	void AddWeaponMask ( int game, int mask );
127
	void AddMissileMask ( int game, int mask );
128
	void RemoveText(int id);
129
	void ClearText() { m_lText.MemoryClear(); m_bChanged = true; }
130
 
131
	void AddShipyard ( int s ) { m_iShipyard |= s; m_bChanged = true; }
132
	void RemoveShipyard ( int s ) { m_iShipyard &= ~(s); m_bChanged = true; }
133
	void SetShipyard(int s, bool b) { if ( b ) AddShipyard(s); else RemoveShipyard(s); }
134
	void ToggleShipyard(int s) { if ( this->IsShipyard(s) ) RemoveShipyard(s); else AddShipyard(s); }
135
 
136
	bool RemoveCutData(CyString cut);
137
	bool RemoveCockpit(CyString cockpitid);
138
	bool RemoveComponent(CyString section1, CyString section2, CyString data);
139
	bool RemoveDummy(CyString section, CyString data);
140
	bool RemoveBodies(CyString body);
141
	bool RemoveAnimation(CyString ani);
142
 
143
	bool IsSigned() { return false; }
144
	bool IsValid ();
145
	bool IsShipyard(int s) { return (m_iShipyard & s) ? true : false; }
146
	bool AnyShipyards() { return (m_iShipyard > 0) ? true : false; }
147
	void AdjustCockpits();
14 cycrow 148
	virtual Utils::String CreateValuesLine () const;
149
	virtual bool ParseValueLine(const Utils::String &line);
1 cycrow 150
 
151
	virtual int GetType () { return TYPE_XSP; }
152
 
153
	CyString GetShipName(int lang);
154
	bool ConvertOld(CyString file);
155
 
156
	CyStringList *GetAnimations() { return &m_lAnimations; }
157
	CyStringList *GetCutData() { return &m_lCutData; }
158
	CyStringList *GetBodies() { return &m_lBodies; }
159
	CLinkList<SWeaponMask> *GetLaserMasks() { return &m_lWeaponMasks; }
160
	CLinkList<SWeaponMask> *GetMissileMasks() { return &m_lMissileMasks; }
161
	CLinkList<SText> *GetTexts() { return &m_lText; }
162
	CLinkList<SDummy> *GetDummies() { return &m_lDummy; }
163
	CLinkList<SComponent> *GetComponents() { return &m_lComponent; }
164
	CLinkList<SCockpit> *GetCockpits() { return &m_lCockpit; }
165
	int GetLaserMask(int game, bool getOnly = false);
166
	int GetMissileMask(int game, bool getOnly = false);
167
	void SetLaserMask(int game, int mask);
168
	void SetMissileMask(int game, int mask);
169
 
14 cycrow 170
	void SetCreatedShipData(CShipData *data) { m_sData = data->CreateData().ToString(); }
1 cycrow 171
	bool AnyTexts() { return !m_lText.empty(); }
172
	bool AnyDummies() { return !m_lDummy.empty(); }
173
	bool AnyComponents() { return !m_lComponent.empty(); }
174
	bool AnyCockpits() { return !m_lCockpit.empty(); }
175
	bool AnyCutData() { return !m_lCutData.Empty(); }
176
	bool AnyBodies() { return !m_lBodies.Empty(); }
177
	bool AnyAnimations() { return !m_lAnimations.Empty(); }
178
 
179
	CyString GetShipClass();
35 cycrow 180
	bool UpdateSigned(bool updateFiles) { m_bSigned = false; return false; }
1 cycrow 181
 
182
	// ship extraction
35 cycrow 183
	bool startExtractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *pProgress);
184
	bool extractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *progress);
185
	bool extractSceneFiles(CVirtualFileSystem *pVfs);
186
	void extractComponants(CVirtualFileSystem *pVfs, CyStringList *sceneModels);
187
	void extractDummies(CVirtualFileSystem *pVfs, CyStringList *sceneModels, bool add);
188
	void extractTextures(CVirtualFileSystem *pVfs);
189
	bool extractBodies(CVirtualFileSystem *pVfs, CyStringList *sceneModels);
190
	bool extractCockpits(CVirtualFileSystem *pVfs);
1 cycrow 191
 
35 cycrow 192
	bool processSceneFileSection(int section, CVirtualFileSystem *pVfs, CyStringList *lModels, CProgressInfo *progress);
193
	bool processSceneFiles(CVirtualFileSystem *pVfs, CProgressInfo *progress);
1 cycrow 194
 
195
	void PackAllFiles();
196
	CyStringList *ReadSceneModels();
35 cycrow 197
 
198
	//TODO: convert this
199
	void ExtractTexts(CCatFile *catFile, CCatFile *secondCatFile, int textId);
200
 
1 cycrow 201
	bool GetTextureList(CyStringList *list, const unsigned char *olddata, size_t size);
202
	bool AddTextFromFile(FILE *id, int textId = -1);
203
	bool AddTextFromFile(CyString file, int textId = -1);
204
	bool ImportBodies(CyStringList *sceneModels, CyString filename);
205
	bool ImportCockpits(CyString filename);
206
	CyString FormatShipData(CyStringList *cockpits, int *text, int game);
207
 
14 cycrow 208
	virtual bool LoadPackageData(const Utils::String &sFfirst, const Utils::String &sRest);
1 cycrow 209
	virtual bool GeneratePackagerScript(bool wildcard, CyStringList *list, bool datafile = false);
210
 
211
protected:
212
	virtual void Delete ();
213
	virtual void SetDefaults ();
14 cycrow 214
	virtual bool CheckHeader(const Utils::String header) const;
1 cycrow 215
 
216
	C_File *m_pSceneFile, *m_pCockpitFile;
217
 
218
	bool m_bLanguageText, m_bExistingShip;
219
 
220
	int m_iOrgDesc;
221
 
14 cycrow 222
	Utils::String m_sID;
223
	Utils::String m_sData;
1 cycrow 224
 
225
	CyStringList			m_lCutData;
226
	CyStringList			m_lBodies;
227
	CyStringList			m_lAnimations;
228
	CLinkList<SCockpit>		m_lCockpit;
229
	CLinkList<SText>		m_lText;
230
	CLinkList<SComponent>	m_lComponent;
231
	CLinkList<SDummy>		m_lDummy;
232
	CLinkList<SWeaponMask>  m_lWeaponMasks;
233
	CLinkList<SWeaponMask>  m_lMissileMasks;
234
 
235
	int m_iShipyard;
236
};
237
 
238
#endif //_XSPFILE_H__
239