Subversion Repositories spk

Rev

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