Subversion Repositories spk

Rev

Rev 217 | Go to most recent revision | Details | Compare with Previous | 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"
35 cycrow 6
#include "VirtualFileSystem.h"
1 cycrow 7
 
8
class CCatFile;
9
 
10
#define SHIPYARD_NONE		  0
11
#define SHIPYARD_ARGON		  1
12
#define SHIPYARD_BORON		  2
13
#define SHIPYARD_PARANID	  4
14
#define SHIPYARD_SPLIT		  8
15
#define SHIPYARD_TELADI		 16
16
#define SHIPYARD_PIRATES	 32
17
#define SHIPYARD_FRIEND		 64
18
#define SHIPYARD_XENON		128
19
#define SHIPYARD_TERRAN		256
20
#define SHIPYARD_ATF		512
21
#define SHIPYARD_YAKI		1024
22
 
23
#define SHIPYARD_MAX	SHIPYARD_TERRAN
24
 
25
enum {TAT_NONE, TAT_SINGLE, TAT_3};
26
 
27
#define TSHIPPOS_CLASS		53
28
 
29
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};
30
 
31
int		 SPKEXPORT GetMaxShipyards ();
216 cycrow 32
Utils::WString SPKEXPORT GetShipyardName (int s);
1 cycrow 33
 
109 cycrow 34
typedef struct STypesSection {
216 cycrow 35
	Utils::WString		sSection;
36
	Utils::WStringList	lEntries;
109 cycrow 37
} STypesSection2;
38
 
39
typedef struct SComponentEntry {
216 cycrow 40
	Utils::WString		sSection;
113 cycrow 41
	Utils::CList<STypesSection> lEntries;
109 cycrow 42
} SComponentEntry;
43
 
1 cycrow 44
typedef struct SWeaponMask {
45
	int		iMask;
46
	int		iGame;
47
} SWeaponMask;
48
 
49
typedef struct SText
50
{
51
	int		iId;
216 cycrow 52
	Utils::WString sName;
53
	Utils::WString sDesc;
1 cycrow 54
} SText;
55
 
56
typedef struct SDummy
57
{
216 cycrow 58
	Utils::WString	sSection;
59
	Utils::WString sData;
1 cycrow 60
} SDummy;
61
 
62
typedef struct SComponent
63
{
216 cycrow 64
	Utils::WString sSection;
65
	Utils::WString sSection2;
66
	Utils::WString sData;
1 cycrow 67
} SComponent;
68
 
69
typedef struct SCockpit
70
{
216 cycrow 71
	Utils::WString	   sCockpit;
1 cycrow 72
	CLinkList<SWeaponMask> lWeaponMask;
73
	int				iIndex;
74
} SCockpit;
75
 
35 cycrow 76
using namespace SPK;
1 cycrow 77
 
78
class SPKEXPORT CXspFile : public CBaseFile
79
{
80
public:
81
	CXspFile ();
82
	~CXspFile () { this->Delete(); }
83
 
212 cycrow 84
	static bool ReadAnimations(const Utils::WStringList& lIn, Utils::WStringList& lOut, int startRecord);
218 cycrow 85
	static int GetAnimationType(const Utils::WString &sType);
216 cycrow 86
	static Utils::WString TypesListToString(Utils::CList<STypesSection> &list, bool deleteAfter = false);
1 cycrow 87
 
175 cycrow 88
	bool writeHeader(CFileIO &file, int iHeader, int iLength) const override;
1 cycrow 89
 
90
	bool IsLanguageText () { return m_bLanguageText; }
91
	bool IsExistingShip () { return m_bExistingShip; }
92
 
93
	int  GetOriginalDescription () { return m_iOrgDesc; }
94
	int  GetShipyards () { return m_iShipyard; }
95
 
217 cycrow 96
	const Utils::WString &shipID () const { return m_sID; }
97
	const Utils::WString &shipData () const { return m_sData; }
98
	Utils::WString getX3ShipData() const;
99
	Utils::WString getTCShipData() const;
203 cycrow 100
	Utils::WString shipFilename() const
1 cycrow 101
	{ 
203 cycrow 102
		Utils::WString s = this->name() + L"-" + this->author();
103
		s = s.remove(L' ');
104
		s = s.remove(L'\\');
105
		s = s.remove(L'/');
1 cycrow 106
		return s;
107
	}
108
 
109
	SText *FindShipText(int lang);
206 cycrow 110
	Utils::WString textName(int lang);
111
	Utils::WString textDescription(int lang);
1 cycrow 112
 
50 cycrow 113
	void SetLanguageText		( bool b )   { m_bLanguageText = b; _changed(); }
114
	void SetExistingShip		( bool b )   { m_bExistingShip = b; _changed(); }
115
	void SetOriginalDescription	( int i )	 { m_iOrgDesc = i; _changed();; }
217 cycrow 116
	void setShipID				(const Utils::WString &sId ) { m_sID = sId; _changed();; }
117
	void setShipData			(const Utils::WString &sData ) { m_sData = sData; _changed(); }
1 cycrow 118
 
119
	void SetSceneFile ( C_File *f ) { m_pSceneFile = f; }
120
	void SetCockpitFile ( C_File *f ) { m_pCockpitFile = f; }
121
 
218 cycrow 122
	void addAnimation(const Utils::WStringList &list);
216 cycrow 123
	void addAnimation(const Utils::WString& data);
124
	void addBodies(const Utils::WString &data);
125
	void addBody(const Utils::WString &section, const Utils::WString &data);
126
	void addCutData(const Utils::WString& data);
127
	void addText(int id, const Utils::WString &name, const Utils::WString &desc);
128
	void addCockpit(const Utils::WString &cockpit, int game, int mask = -1, int index = -1 );
129
	void addCockpitWeapon(const Utils::WString &cockpit, int game, int mask);
218 cycrow 130
	void newCockpit(const Utils::WString &id, const Utils::WString &scene, int mask );
131
	void editCockpit(const Utils::WString &id, const Utils::WString &cockpit);
132
	void editCockpit(const Utils::WString &id, const Utils::WString &scene, int mask);
133
	Utils::WString getCockpitData(const Utils::WString &id);
134
	SCockpit *findCockpit(const Utils::WString &id);
216 cycrow 135
	void addDummy(const Utils::WString &section, const Utils::WString &data );
136
	void addComponent(const Utils::WString &section, const Utils::WString &section2, const Utils::WString &data);
39 cycrow 137
	void AddWeaponMask(int game, int mask );
138
	void AddMissileMask(int game, int mask );
1 cycrow 139
	void RemoveText(int id);
50 cycrow 140
	void ClearText() { m_lText.MemoryClear(); _changed(); }
1 cycrow 141
 
50 cycrow 142
	void AddShipyard ( int s ) { m_iShipyard |= s; _changed(); }
143
	void RemoveShipyard ( int s ) { m_iShipyard &= ~(s); _changed(); }
1 cycrow 144
	void SetShipyard(int s, bool b) { if ( b ) AddShipyard(s); else RemoveShipyard(s); }
145
	void ToggleShipyard(int s) { if ( this->IsShipyard(s) ) RemoveShipyard(s); else AddShipyard(s); }
146
 
216 cycrow 147
	bool removeCutData(const Utils::WString &cut);
148
	bool removeCockpit(const Utils::WString &cockpitid);
149
	bool removeComponent(const Utils::WString &section1, const Utils::WString &section2, const Utils::WString &data);
150
	bool removeDummy(const Utils::WString &section, const Utils::WString &data);
151
	bool removeBodies(const Utils::WString &body);
152
	bool removeAnimation(const Utils::WString &ani);
1 cycrow 153
 
154
	bool IsSigned() { return false; }
155
	bool IsValid ();
156
	bool IsShipyard(int s) { return (m_iShipyard & s) ? true : false; }
157
	bool AnyShipyards() { return (m_iShipyard > 0) ? true : false; }
158
	void AdjustCockpits();
207 cycrow 159
	virtual Utils::WString createValuesLine() const override;
160
	virtual bool parseValueLine(const Utils::WString &line) override;
1 cycrow 161
 
162
	virtual int GetType () { return TYPE_XSP; }
173 cycrow 163
	virtual BaseFileType type() const override { return BaseFileType::TYPE_XSP; }
1 cycrow 164
 
203 cycrow 165
	Utils::WString shipName(int lang);
218 cycrow 166
	bool convertOld(const Utils::WString &file);
1 cycrow 167
 
216 cycrow 168
	const Utils::WStringList &getAnimations() const { return _lAnimations; }
169
	const Utils::WStringList &getCutData() const { return _lCutData; }
170
	const Utils::WStringList &getBodies() const { return _lBodies; }
1 cycrow 171
	CLinkList<SWeaponMask> *GetLaserMasks() { return &m_lWeaponMasks; }
172
	CLinkList<SWeaponMask> *GetMissileMasks() { return &m_lMissileMasks; }
173
	CLinkList<SText> *GetTexts() { return &m_lText; }
174
	CLinkList<SDummy> *GetDummies() { return &m_lDummy; }
175
	CLinkList<SComponent> *GetComponents() { return &m_lComponent; }
176
	CLinkList<SCockpit> *GetCockpits() { return &m_lCockpit; }
177
	int GetLaserMask(int game, bool getOnly = false);
178
	int GetMissileMask(int game, bool getOnly = false);
179
	void SetLaserMask(int game, int mask);
180
	void SetMissileMask(int game, int mask);
181
 
217 cycrow 182
	void setCreatedShipData(CShipData *data) { m_sData = data->createData(); }
1 cycrow 183
	bool AnyTexts() { return !m_lText.empty(); }
184
	bool AnyDummies() { return !m_lDummy.empty(); }
185
	bool AnyComponents() { return !m_lComponent.empty(); }
186
	bool AnyCockpits() { return !m_lCockpit.empty(); }
165 cycrow 187
	bool anyCutData() { return !_lCutData.empty(); }
170 cycrow 188
	bool anyBodies() const { return !_lBodies.empty(); }
189
	bool anyAnimations() const { return !_lAnimations.empty(); }
1 cycrow 190
 
165 cycrow 191
	void clearCutData();
170 cycrow 192
	void clearAnimations();
193
	void clearBodies();
165 cycrow 194
 
217 cycrow 195
	Utils::WString shipClass() const;
175 cycrow 196
	virtual bool computeSigned(bool updateFiles) const override { return false; }
1 cycrow 197
 
198
	// ship extraction
218 cycrow 199
	bool startExtractShip(CVirtualFileSystem *pVfs, const Utils::WString &sId, CProgressInfo *pProgress);
200
	bool extractShip(CVirtualFileSystem *pVfs, const Utils::WString &sId, CProgressInfo *progress);
35 cycrow 201
	bool extractSceneFiles(CVirtualFileSystem *pVfs);
218 cycrow 202
	void extractComponants(CVirtualFileSystem *pVfs, const Utils::WStringList &sceneModels);
203
	void extractCutData(CVirtualFileSystem *pVfs, Utils::WStringList& sceneModels, bool add);
204
	void extractDummies(CVirtualFileSystem *pVfs, Utils::WStringList& sceneModels, bool add);
35 cycrow 205
	void extractTextures(CVirtualFileSystem *pVfs);
218 cycrow 206
	bool extractBodies(CVirtualFileSystem *pVfs, const Utils::WStringList& sceneModels);
35 cycrow 207
	bool extractCockpits(CVirtualFileSystem *pVfs);
1 cycrow 208
 
109 cycrow 209
	void addComponentsToList(CLinkList<SComponentEntry> &componentList);
113 cycrow 210
	void addDummiesToList(Utils::CList<STypesSection> &list);
211
	void addCutDataToList(Utils::CList<STypesSection> &list);
212
	void addBodiesToList(Utils::CList<STypesSection> &list);
213
	void addAnimationsToList(Utils::CList<STypesSection> &list);
109 cycrow 214
 
218 cycrow 215
	bool processSceneFileSection(int section, CVirtualFileSystem *pVfs, Utils::WStringList &lModels, CProgressInfo *progress);
35 cycrow 216
	bool processSceneFiles(CVirtualFileSystem *pVfs, CProgressInfo *progress);
1 cycrow 217
 
218
	void PackAllFiles();
218 cycrow 219
	bool readSceneModels(Utils::WStringList& out);
35 cycrow 220
 
221
	//TODO: convert this
222
	void ExtractTexts(CCatFile *catFile, CCatFile *secondCatFile, int textId);
223
 
197 cycrow 224
	bool getTextureList(Utils::WStringList &list, const unsigned char *olddata, size_t size) const;
225
	bool addTextFromFile(const Utils::WString &file, int textId = -1);
218 cycrow 226
	bool importBodies(const Utils::WStringList &sceneModels, const Utils::WString &filename);
227
	bool ImportCockpits(const Utils::WString &filename);
216 cycrow 228
	Utils::WString formatShipData(const Utils::WStringList &cockpits, int *text, int game);
1 cycrow 229
 
197 cycrow 230
	virtual bool loadPackageData(const Utils::WString &sFirst, const Utils::WString &sRest, const Utils::WString &sMainGame, Utils::WStringList &otherGames, Utils::WStringList &gameAddons, CProgressInfo *progress = NULL) override;
210 cycrow 231
	virtual bool GeneratePackagerScript(bool wildcard, Utils::WStringList *list, int game, const Utils::WStringList &gameAddons, bool datafile = false) override;
109 cycrow 232
	virtual void addGeneratedFiles(HZIP &hz);
1 cycrow 233
 
234
protected:
235
	virtual void Delete ();
236
	virtual void SetDefaults ();
210 cycrow 237
	virtual bool _checkHeader(const Utils::WString &header) const override;
216 cycrow 238
	SCockpit *_findCockpit(const Utils::WString &sID);
239
	void _addSection(Utils::CList<STypesSection> &list, const Utils::WString &section, const Utils::WString &data);
240
	void _addDataSection(Utils::WStringList& list, Utils::CList<STypesSection>& sectionList, bool bUseFirst);
118 cycrow 241
	bool _addTextFromFile(CFileIO &F, int textId = -1);
1 cycrow 242
 
109 cycrow 243
protected:
1 cycrow 244
	C_File *m_pSceneFile, *m_pCockpitFile;
245
 
246
	bool m_bLanguageText, m_bExistingShip;
247
 
248
	int m_iOrgDesc;
249
 
217 cycrow 250
	Utils::WString m_sID;
251
	Utils::WString m_sData;
1 cycrow 252
 
216 cycrow 253
	Utils::WStringList		_lCutData;
254
	Utils::WStringList		_lBodies;
255
	Utils::WStringList		_lAnimations;
1 cycrow 256
	CLinkList<SCockpit>		m_lCockpit;
257
	CLinkList<SText>		m_lText;
258
	CLinkList<SComponent>	m_lComponent;
259
	CLinkList<SDummy>		m_lDummy;
260
	CLinkList<SWeaponMask>  m_lWeaponMasks;
261
	CLinkList<SWeaponMask>  m_lMissileMasks;
262
 
263
	int m_iShipyard;
264
};
265
 
266
#endif //_XSPFILE_H__
267