Subversion Repositories spk

Rev

Rev 98 | Rev 109 | 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
 
35
typedef struct SWeaponMask {
36
	int		iMask;
37
	int		iGame;
38
} SWeaponMask;
39
 
40
typedef struct SText
41
{
42
	int		iId;
39 cycrow 43
	Utils::String sName;
44
	Utils::String sDesc;
1 cycrow 45
} SText;
46
 
47
typedef struct SDummy
48
{
39 cycrow 49
	Utils::String	sSection;
50
	Utils::String sData;
1 cycrow 51
} SDummy;
52
 
53
typedef struct SComponent
54
{
39 cycrow 55
	Utils::String sSection;
56
	Utils::String sSection2;
57
	Utils::String sData;
1 cycrow 58
} SComponent;
59
 
60
typedef struct SCockpit
61
{
39 cycrow 62
	Utils::String	   sCockpit;
1 cycrow 63
	CLinkList<SWeaponMask> lWeaponMask;
64
	int				iIndex;
65
} SCockpit;
66
 
35 cycrow 67
using namespace SPK;
1 cycrow 68
 
69
class SPKEXPORT CXspFile : public CBaseFile
70
{
71
public:
72
	CXspFile ();
73
	~CXspFile () { this->Delete(); }
74
 
75
	static bool ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord);
39 cycrow 76
	static int GetAnimationType(const Utils::String &sType);
1 cycrow 77
 
52 cycrow 78
	bool WriteHeader(CFileIO &file, int iHeader, int iLength);
1 cycrow 79
 
80
	bool IsLanguageText () { return m_bLanguageText; }
81
	bool IsExistingShip () { return m_bExistingShip; }
82
 
83
	int  GetOriginalDescription () { return m_iOrgDesc; }
84
	int  GetShipyards () { return m_iShipyard; }
85
 
14 cycrow 86
	const Utils::String &GetShipID () const { return m_sID; }
87
	const Utils::String &GetShipData () const { return m_sData; }
39 cycrow 88
	Utils::String GetX3ShipData();
89
	Utils::String GetTCShipData();
90
	Utils::String GetShipFilename () 
1 cycrow 91
	{ 
50 cycrow 92
		Utils::String s = this->name() + "-" + this->author(); 
39 cycrow 93
		s = s.remove(' ');
94
		s = s.remove('\\');
95
		s = s.remove('/');
1 cycrow 96
		return s;
97
	}
98
 
99
	SText *FindShipText(int lang);
39 cycrow 100
	Utils::String GetTextName(int lang);
101
	Utils::String GetTextDescription(int lang);
1 cycrow 102
 
50 cycrow 103
	void SetLanguageText		( bool b )   { m_bLanguageText = b; _changed(); }
104
	void SetExistingShip		( bool b )   { m_bExistingShip = b; _changed(); }
105
	void SetOriginalDescription	( int i )	 { m_iOrgDesc = i; _changed();; }
106
	void SetShipID				(const Utils::String &sId ) { m_sID = sId; _changed();; }
107
	void SetShipData			(const Utils::String &sData ) { m_sData = sData; _changed(); }
1 cycrow 108
 
109
	void SetSceneFile ( C_File *f ) { m_pSceneFile = f; }
110
	void SetCockpitFile ( C_File *f ) { m_pCockpitFile = f; }
111
 
112
	void AddAnimation(CyStringList *list);
50 cycrow 113
	void AddAnimation(const Utils::String &data) { m_lAnimations.PushBack(CyString(data), true); _changed(); }
39 cycrow 114
	void AddBodies(const Utils::String &data);
115
	void AddBody(const Utils::String &section, const Utils::String &data);
50 cycrow 116
	void AddCutData(const Utils::String &data) { m_lCutData.PushBack(CyString(data), true); _changed(); }
39 cycrow 117
	void AddText(int id, const Utils::String &name, const Utils::String &desc );
118
	void AddCockpit(const Utils::String &cockpit, int game, int mask = -1, int index = -1 );
108 cycrow 119
	void AddCockpitWeapon(const Utils::String &cockpit, int game, int mask);
39 cycrow 120
	void NewCockpit(const Utils::String &id, const Utils::String &scene, int mask );
121
	void EditCockpit(const Utils::String &id, const Utils::String &cockpit);
122
	void EditCockpit(const Utils::String &id, const Utils::String &scene, int mask);
123
	Utils::String GetCockpitData(const Utils::String &id);
124
	SCockpit *FindCockpit(const Utils::String &id);
125
	void AddDummy(const Utils::String &section, const Utils::String &data );
126
	void AddComponent(const Utils::String &section, const Utils::String &section2, const Utils::String &data );
127
	void AddWeaponMask(int game, int mask );
128
	void AddMissileMask(int game, int mask );
1 cycrow 129
	void RemoveText(int id);
50 cycrow 130
	void ClearText() { m_lText.MemoryClear(); _changed(); }
1 cycrow 131
 
50 cycrow 132
	void AddShipyard ( int s ) { m_iShipyard |= s; _changed(); }
133
	void RemoveShipyard ( int s ) { m_iShipyard &= ~(s); _changed(); }
1 cycrow 134
	void SetShipyard(int s, bool b) { if ( b ) AddShipyard(s); else RemoveShipyard(s); }
135
	void ToggleShipyard(int s) { if ( this->IsShipyard(s) ) RemoveShipyard(s); else AddShipyard(s); }
136
 
39 cycrow 137
	bool RemoveCutData(const Utils::String &cut);
138
	bool RemoveCockpit(const Utils::String &cockpitid);
139
	bool RemoveComponent(const Utils::String &section1, const Utils::String &section2, const Utils::String &data);
140
	bool RemoveDummy(const Utils::String &section, const Utils::String &data);
141
	bool RemoveBodies(const Utils::String &body);
142
	bool RemoveAnimation(const Utils::String &ani);
1 cycrow 143
 
144
	bool IsSigned() { return false; }
145
	bool IsValid ();
146
	bool IsShipyard(int s) { return (m_iShipyard & s) ? true : false; }
147
	bool AnyShipyards() { return (m_iShipyard > 0) ? true : false; }
148
	void AdjustCockpits();
14 cycrow 149
	virtual Utils::String CreateValuesLine () const;
150
	virtual bool ParseValueLine(const Utils::String &line);
1 cycrow 151
 
152
	virtual int GetType () { return TYPE_XSP; }
153
 
39 cycrow 154
	Utils::String GetShipName(int lang);
155
	bool ConvertOld(const Utils::String &file);
1 cycrow 156
 
157
	CyStringList *GetAnimations() { return &m_lAnimations; }
158
	CyStringList *GetCutData() { return &m_lCutData; }
159
	CyStringList *GetBodies() { return &m_lBodies; }
160
	CLinkList<SWeaponMask> *GetLaserMasks() { return &m_lWeaponMasks; }
161
	CLinkList<SWeaponMask> *GetMissileMasks() { return &m_lMissileMasks; }
162
	CLinkList<SText> *GetTexts() { return &m_lText; }
163
	CLinkList<SDummy> *GetDummies() { return &m_lDummy; }
164
	CLinkList<SComponent> *GetComponents() { return &m_lComponent; }
165
	CLinkList<SCockpit> *GetCockpits() { return &m_lCockpit; }
166
	int GetLaserMask(int game, bool getOnly = false);
167
	int GetMissileMask(int game, bool getOnly = false);
168
	void SetLaserMask(int game, int mask);
169
	void SetMissileMask(int game, int mask);
170
 
14 cycrow 171
	void SetCreatedShipData(CShipData *data) { m_sData = data->CreateData().ToString(); }
1 cycrow 172
	bool AnyTexts() { return !m_lText.empty(); }
173
	bool AnyDummies() { return !m_lDummy.empty(); }
174
	bool AnyComponents() { return !m_lComponent.empty(); }
175
	bool AnyCockpits() { return !m_lCockpit.empty(); }
176
	bool AnyCutData() { return !m_lCutData.Empty(); }
177
	bool AnyBodies() { return !m_lBodies.Empty(); }
178
	bool AnyAnimations() { return !m_lAnimations.Empty(); }
179
 
39 cycrow 180
	Utils::String GetShipClass();
35 cycrow 181
	bool UpdateSigned(bool updateFiles) { m_bSigned = false; return false; }
1 cycrow 182
 
183
	// ship extraction
35 cycrow 184
	bool startExtractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *pProgress);
185
	bool extractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *progress);
186
	bool extractSceneFiles(CVirtualFileSystem *pVfs);
187
	void extractComponants(CVirtualFileSystem *pVfs, CyStringList *sceneModels);
42 cycrow 188
	void extractCutData(CVirtualFileSystem *pVfs, CyStringList *sceneModels, bool add);
35 cycrow 189
	void extractDummies(CVirtualFileSystem *pVfs, CyStringList *sceneModels, bool add);
190
	void extractTextures(CVirtualFileSystem *pVfs);
191
	bool extractBodies(CVirtualFileSystem *pVfs, CyStringList *sceneModels);
192
	bool extractCockpits(CVirtualFileSystem *pVfs);
1 cycrow 193
 
35 cycrow 194
	bool processSceneFileSection(int section, CVirtualFileSystem *pVfs, CyStringList *lModels, CProgressInfo *progress);
195
	bool processSceneFiles(CVirtualFileSystem *pVfs, CProgressInfo *progress);
1 cycrow 196
 
197
	void PackAllFiles();
198
	CyStringList *ReadSceneModels();
35 cycrow 199
 
200
	//TODO: convert this
201
	void ExtractTexts(CCatFile *catFile, CCatFile *secondCatFile, int textId);
202
 
1 cycrow 203
	bool GetTextureList(CyStringList *list, const unsigned char *olddata, size_t size);
204
	bool AddTextFromFile(FILE *id, int textId = -1);
39 cycrow 205
	bool AddTextFromFile(const Utils::String &file, int textId = -1);
206
	bool ImportBodies(CyStringList *sceneModels, const Utils::String &filename);
207
	bool ImportCockpits(const Utils::String &filename);
208
	Utils::String FormatShipData(CyStringList *cockpits, int *text, int game);
1 cycrow 209
 
98 cycrow 210
	virtual bool LoadPackageData(const Utils::String &sFfirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames);
1 cycrow 211
	virtual bool GeneratePackagerScript(bool wildcard, CyStringList *list, bool datafile = false);
212
 
213
protected:
214
	virtual void Delete ();
215
	virtual void SetDefaults ();
14 cycrow 216
	virtual bool CheckHeader(const Utils::String header) const;
108 cycrow 217
	SCockpit *_findCockpit(const Utils::String &sID);
1 cycrow 218
 
219
	C_File *m_pSceneFile, *m_pCockpitFile;
220
 
221
	bool m_bLanguageText, m_bExistingShip;
222
 
223
	int m_iOrgDesc;
224
 
14 cycrow 225
	Utils::String m_sID;
226
	Utils::String m_sData;
1 cycrow 227
 
228
	CyStringList			m_lCutData;
229
	CyStringList			m_lBodies;
230
	CyStringList			m_lAnimations;
231
	CLinkList<SCockpit>		m_lCockpit;
232
	CLinkList<SText>		m_lText;
233
	CLinkList<SComponent>	m_lComponent;
234
	CLinkList<SDummy>		m_lDummy;
235
	CLinkList<SWeaponMask>  m_lWeaponMasks;
236
	CLinkList<SWeaponMask>  m_lMissileMasks;
237
 
238
	int m_iShipyard;
239
};
240
 
241
#endif //_XSPFILE_H__
242