Subversion Repositories spk

Rev

Rev 134 | Rev 166 | 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
 
85
	static bool ReadAnimations(CyStringList *lIn, CyStringList *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
 
52 cycrow 89
	bool WriteHeader(CFileIO &file, int iHeader, int iLength);
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();
101
	Utils::String GetShipFilename () 
1 cycrow 102
	{ 
50 cycrow 103
		Utils::String s = this->name() + "-" + this->author(); 
39 cycrow 104
		s = s.remove(' ');
105
		s = s.remove('\\');
106
		s = s.remove('/');
1 cycrow 107
		return s;
108
	}
109
 
110
	SText *FindShipText(int lang);
39 cycrow 111
	Utils::String GetTextName(int lang);
112
	Utils::String GetTextDescription(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
 
123
	void AddAnimation(CyStringList *list);
50 cycrow 124
	void AddAnimation(const Utils::String &data) { m_lAnimations.PushBack(CyString(data), true); _changed(); }
39 cycrow 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);
39 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();
14 cycrow 160
	virtual Utils::String CreateValuesLine () const;
161
	virtual bool ParseValueLine(const Utils::String &line);
1 cycrow 162
 
163
	virtual int GetType () { return TYPE_XSP; }
164
 
39 cycrow 165
	Utils::String GetShipName(int lang);
166
	bool ConvertOld(const Utils::String &file);
1 cycrow 167
 
168
	CyStringList *GetAnimations() { return &m_lAnimations; }
165 cycrow 169
	const Utils::CStringList &getCutData() const { return _lCutData; }
1 cycrow 170
	CyStringList *GetBodies() { return &m_lBodies; }
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
 
14 cycrow 182
	void SetCreatedShipData(CShipData *data) { m_sData = data->CreateData().ToString(); }
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(); }
1 cycrow 188
	bool AnyBodies() { return !m_lBodies.Empty(); }
189
	bool AnyAnimations() { return !m_lAnimations.Empty(); }
190
 
165 cycrow 191
	void clearCutData();
192
 
39 cycrow 193
	Utils::String GetShipClass();
35 cycrow 194
	bool UpdateSigned(bool updateFiles) { m_bSigned = false; return false; }
1 cycrow 195
 
196
	// ship extraction
35 cycrow 197
	bool startExtractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *pProgress);
198
	bool extractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *progress);
199
	bool extractSceneFiles(CVirtualFileSystem *pVfs);
200
	void extractComponants(CVirtualFileSystem *pVfs, CyStringList *sceneModels);
42 cycrow 201
	void extractCutData(CVirtualFileSystem *pVfs, CyStringList *sceneModels, bool add);
35 cycrow 202
	void extractDummies(CVirtualFileSystem *pVfs, CyStringList *sceneModels, bool add);
203
	void extractTextures(CVirtualFileSystem *pVfs);
204
	bool extractBodies(CVirtualFileSystem *pVfs, CyStringList *sceneModels);
205
	bool extractCockpits(CVirtualFileSystem *pVfs);
1 cycrow 206
 
109 cycrow 207
	void addComponentsToList(CLinkList<SComponentEntry> &componentList);
113 cycrow 208
	void addDummiesToList(Utils::CList<STypesSection> &list);
209
	void addCutDataToList(Utils::CList<STypesSection> &list);
210
	void addBodiesToList(Utils::CList<STypesSection> &list);
211
	void addAnimationsToList(Utils::CList<STypesSection> &list);
109 cycrow 212
 
35 cycrow 213
	bool processSceneFileSection(int section, CVirtualFileSystem *pVfs, CyStringList *lModels, CProgressInfo *progress);
214
	bool processSceneFiles(CVirtualFileSystem *pVfs, CProgressInfo *progress);
1 cycrow 215
 
216
	void PackAllFiles();
217
	CyStringList *ReadSceneModels();
35 cycrow 218
 
219
	//TODO: convert this
220
	void ExtractTexts(CCatFile *catFile, CCatFile *secondCatFile, int textId);
221
 
1 cycrow 222
	bool GetTextureList(CyStringList *list, const unsigned char *olddata, size_t size);
39 cycrow 223
	bool AddTextFromFile(const Utils::String &file, int textId = -1);
224
	bool ImportBodies(CyStringList *sceneModels, const Utils::String &filename);
225
	bool ImportCockpits(const Utils::String &filename);
226
	Utils::String FormatShipData(CyStringList *cockpits, int *text, int game);
1 cycrow 227
 
134 cycrow 228
	virtual bool LoadPackageData(const Utils::String &sFfirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames, Utils::CStringList &gameAddons, CProgressInfo *progress = NULL) override;
127 cycrow 229
	virtual bool GeneratePackagerScript(bool wildcard, Utils::CStringList *list, int game, const Utils::CStringList &gameAddons, bool datafile = false) override;
109 cycrow 230
	virtual void addGeneratedFiles(HZIP &hz);
1 cycrow 231
 
232
protected:
233
	virtual void Delete ();
234
	virtual void SetDefaults ();
14 cycrow 235
	virtual bool CheckHeader(const Utils::String header) const;
108 cycrow 236
	SCockpit *_findCockpit(const Utils::String &sID);
113 cycrow 237
	void _addSection(Utils::CList<STypesSection> &list, const Utils::String &section, const Utils::String &data);
165 cycrow 238
	void _addDataSection(CyStringList& list, Utils::CList<STypesSection>& sectionList, bool bUseFirst);
239
	void _addDataSection(Utils::CStringList& list, Utils::CList<STypesSection>& sectionList, bool bUseFirst);
118 cycrow 240
	bool _addTextFromFile(CFileIO &F, int textId = -1);
1 cycrow 241
 
109 cycrow 242
protected:
1 cycrow 243
	C_File *m_pSceneFile, *m_pCockpitFile;
244
 
245
	bool m_bLanguageText, m_bExistingShip;
246
 
247
	int m_iOrgDesc;
248
 
14 cycrow 249
	Utils::String m_sID;
250
	Utils::String m_sData;
1 cycrow 251
 
165 cycrow 252
	Utils::CStringList		_lCutData;
1 cycrow 253
	CyStringList			m_lBodies;
254
	CyStringList			m_lAnimations;
255
	CLinkList<SCockpit>		m_lCockpit;
256
	CLinkList<SText>		m_lText;
257
	CLinkList<SComponent>	m_lComponent;
258
	CLinkList<SDummy>		m_lDummy;
259
	CLinkList<SWeaponMask>  m_lWeaponMasks;
260
	CLinkList<SWeaponMask>  m_lMissileMasks;
261
 
262
	int m_iShipyard;
263
};
264
 
265
#endif //_XSPFILE_H__
266