Subversion Repositories spk

Rev

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