Subversion Repositories spk

Rev

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