Subversion Repositories spk

Rev

Rev 108 | Rev 112 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 108 Rev 109
Line 4... Line 4...
4
#include "CatFile.h"
4
#include "CatFile.h"
-
 
5
 
-
 
6
#define ADDSECTIONLIST(T, L) for(CListNode<T> *node = L.Front(); node; node = node->next()) \
-
 
7
		_addSection(list, node->Data()->sSection, node->Data()->sData);
-
 
8
 
-
 
9
#define GENERATESECTION(F, T, L) if ( !L.empty() ) {						\
-
 
10
									type = F;								\
-
 
11
									std::vector<STypesSection *> list;		\
-
 
12
									ADDSECTIONLIST(T, L);					\
-
 
13
									data = CXspFile::TypesListToString(list, true); \
-
 
14
								}
-
 
15
 
-
 
16
#define GENERATESTRINGSECTION(F, L) if ( !L.Empty() ) {						\
-
 
17
									type = F;								\
-
 
18
									std::vector<STypesSection *> list;		\
-
 
19
									_addDataSection(L, list);				\
-
 
20
									data = CXspFile::TypesListToString(list, true); \
-
 
21
								}
-
 
22
 
5
 
23
 
6
CXspFile::CXspFile () : CBaseFile()
24
CXspFile::CXspFile () : CBaseFile()
7
{
25
{
8
	SetDefaults ();
26
	SetDefaults ();
9
}
27
}
Line 58... Line 76...
58
		newtext->iId = id;
76
		newtext->iId = id;
59
		m_lText.push_back ( newtext );
77
		m_lText.push_back ( newtext );
60
	}
78
	}
61
 
79
 
62
	newtext->sName = name;
80
	newtext->sName = name;
63
	newtext->sDesc = desc;
81
	newtext->sDesc = desc;
64
 
82
 
65
	_changed();
83
	_changed();
66
}
84
}
67
 
85
 
68
void CXspFile::RemoveText(int id)
86
void CXspFile::RemoveText(int id)
69
{
87
{
Line 99... Line 117...
99
	c->sSection = section;
117
	c->sSection = section;
100
	c->sSection2 = section2;
118
	c->sSection2 = section2;
101
 
119
 
102
	if ( c->sData.right(1) != ";" )
120
	if ( c->sData.right(1) != ";" )
103
		c->sData += ";";
121
		c->sData += ";";
104
 
122
 
105
	m_lComponent.push_back ( c );
123
	m_lComponent.push_back ( c );
106
 
124
 
107
	_changed();
125
	_changed();
108
}
126
}
109
 
127
 
110
void CXspFile::AddWeaponMask ( int game, int mask )
128
void CXspFile::AddWeaponMask ( int game, int mask )
111
{
129
{
112
	// first check if we have one for the game
130
	// first check if we have one for the game
113
	SWeaponMask *m = NULL;
131
	SWeaponMask *m = NULL;
114
	for ( CListNode<SWeaponMask> *node = m_lWeaponMasks.Front(); node; node = node->next() )
132
	for ( CListNode<SWeaponMask> *node = m_lWeaponMasks.Front(); node; node = node->next() )
115
	{
133
	{
116
		if ( node->Data()->iGame == game )
134
		if ( node->Data()->iGame == game )
117
		{
135
		{
118
			m = node->Data();
136
			m = node->Data();
119
			break;
137
			break;
120
		}
138
		}
121
	}
139
	}
122
 
140
 
123
	// not found, create one
141
	// not found, create one
124
	if ( !m )
142
	if ( !m )
125
	{
143
	{
126
		m = new SWeaponMask;
144
		m = new SWeaponMask;
127
		m_lWeaponMasks.push_back(m);
145
		m_lWeaponMasks.push_back(m);
128
		m->iGame = game;
146
		m->iGame = game;
Line 157... Line 175...
157
}
175
}
158
 
176
 
159
bool CXspFile::IsValid ()
177
bool CXspFile::IsValid ()
160
{
178
{
161
	if ( this->name().empty() )
179
	if ( this->name().empty() )
162
		return false;
180
		return false;
163
	if ( this->author().empty() )
181
	if ( this->author().empty() )
164
		return false;
182
		return false;
165
 
183
 
166
	return true;
184
	return true;
167
}
185
}
Line 625... Line 643...
625
		{
643
		{
626
		//	printf ( "Command: %s, Rest: %s\n", first.c_str(), rest.c_str());
644
		//	printf ( "Command: %s, Rest: %s\n", first.c_str(), rest.c_str());
627
		}
645
		}
628
 
646
 
629
		pos = start;
647
		pos = start;
630
	}
648
	}
631
 
649
 
632
	// assume all old ones are for X3
650
	// assume all old ones are for X3
633
	if ( !m_sData.empty() )
651
	if ( !m_sData.empty() )
634
	{
652
	{
635
		this->AddWeaponMask(GAME_X3 - 1, m_sData.token(";", 19));
653
		this->AddWeaponMask(GAME_X3 - 1, m_sData.token(";", 19));
636
		this->AddMissileMask(GAME_X3 - 1, m_sData.token(";", 25));
654
		this->AddMissileMask(GAME_X3 - 1, m_sData.token(";", 25));
Line 882... Line 900...
882
		if ( !CBaseFile::GeneratePackagerScriptFile(wildcard, list) )
900
		if ( !CBaseFile::GeneratePackagerScriptFile(wildcard, list) )
883
			return false;
901
			return false;
884
	}
902
	}
885
 
903
 
886
	return true;
904
	return true;
-
 
905
}
-
 
906
 
-
 
907
void CXspFile::_addSection(std::vector<STypesSection *> &list, const Utils::String &section, const Utils::String &data)
-
 
908
{
-
 
909
	STypesSection *currentSubSection = NULL;
-
 
910
	for(std::vector<STypesSection *>::iterator itr = list.begin(); itr != list.end(); itr++) {
-
 
911
		if ( (*itr)->sSection.Compare(section) ) {
-
 
912
			currentSubSection = *itr;
-
 
913
			break;
-
 
914
		}
-
 
915
	}
-
 
916
 
-
 
917
	if ( !currentSubSection ) {
-
 
918
		currentSubSection = new STypesSection;
-
 
919
		currentSubSection->sSection = section;
-
 
920
		list.push_back(currentSubSection);
-
 
921
	}
-
 
922
 
-
 
923
	currentSubSection->lEntries.pushBack(data, "");
-
 
924
}
-
 
925
 
-
 
926
void CXspFile::_addDataSection(CyStringList &list, std::vector<STypesSection *> &sectionList)
-
 
927
{
-
 
928
	for(SStringList *str = list.Head(); str; str = str->next) {
-
 
929
		_addSection(sectionList, str->str.ToString(), str->data.ToString());
-
 
930
	}
-
 
931
}
-
 
932
 
-
 
933
void CXspFile::addDummiesToList(std::vector<STypesSection *> &list)
-
 
934
{
-
 
935
	ADDSECTIONLIST(SDummy, m_lDummy);
-
 
936
}
-
 
937
 
-
 
938
void CXspFile::addComponentsToList(CLinkList<SComponentEntry> &componentList)
-
 
939
{
-
 
940
	for(CListNode<SComponent> *node = m_lComponent.Front(); node; node = node->next()) {
-
 
941
		SComponentEntry *currentSection = NULL;
-
 
942
		for(CListNode<SComponentEntry> *cNode = componentList.Front(); cNode; cNode = cNode->next()) {
-
 
943
			if ( cNode->Data()->sSection.Compare(node->Data()->sSection) ) {
-
 
944
				currentSection = cNode->Data();
-
 
945
				break;
-
 
946
			}
-
 
947
		}
-
 
948
 
-
 
949
		if ( !currentSection ) {
-
 
950
			currentSection = new SComponentEntry();
-
 
951
			currentSection->sSection = node->Data()->sSection;
-
 
952
			componentList.push_back(currentSection);
-
 
953
		}
-
 
954
 
-
 
955
		_addSection(currentSection->lEntries, node->Data()->sSection2, node->Data()->sData);
-
 
956
	}
-
 
957
}
-
 
958
 
-
 
959
void CXspFile::addCutDataToList(std::vector<STypesSection *> &list)
-
 
960
{
-
 
961
	_addDataSection(this->m_lCutData, list);
-
 
962
}
-
 
963
 
-
 
964
void CXspFile::addBodiesToList(std::vector<STypesSection *> &list)
-
 
965
{
-
 
966
	_addDataSection(this->m_lBodies, list);
-
 
967
}
-
 
968
 
-
 
969
void CXspFile::addAnimationsToList(std::vector<STypesSection *> &list)
-
 
970
{
-
 
971
	_addDataSection(this->m_lAnimations, list);
-
 
972
}
-
 
973
 
-
 
974
 
-
 
975
void CXspFile::addGeneratedFiles(HZIP &hz)
-
 
976
{
-
 
977
	TCHAR buf[5000];
-
 
978
 
-
 
979
	CFileIO tmpFile(CPackages::tempDirectory() + "/temp.tmp");
-
 
980
 
-
 
981
	for(int i = 0; i < 5; i++) {
-
 
982
		Utils::String type;
-
 
983
		Utils::String data;
-
 
984
		switch(i) {
-
 
985
			case 0:
-
 
986
				data = "50;1\r\n" + this->m_sData;
-
 
987
				type = "TShips";
-
 
988
				break;
-
 
989
			case 1:
-
 
990
				if ( !this->m_lCockpit.empty() ) {
-
 
991
					data = Utils::String("51;") + (long)this->m_lCockpit.size() + ";\r\n";
-
 
992
					for(CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next()) {
-
 
993
						data += node->Data()->sCockpit + "\r\n";
-
 
994
					}
-
 
995
					type = "TCockpits";
-
 
996
				}
-
 
997
				break;
-
 
998
			case 2:
-
 
999
				if ( !this->m_lComponent.empty() ) {
-
 
1000
					type = "Components";
-
 
1001
					CLinkList<SComponentEntry> componentList;
-
 
1002
					this->addComponentsToList(componentList);
-
 
1003
					for(CListNode<SComponentEntry> *node = componentList.Front(); node; node = node->next()) {
-
 
1004
						data += node->Data()->sSection + "; " + (long)node->Data()->lEntries.size() + ";\r\n";
-
 
1005
						data += CXspFile::TypesListToString(node->Data()->lEntries, true);
-
 
1006
						delete node->Data();
-
 
1007
					}
-
 
1008
				}
-
 
1009
				break;
-
 
1010
			case 3:
-
 
1011
				GENERATESECTION("Dummies", SDummy, this->m_lDummy);
-
 
1012
				break;
-
 
1013
			case 4:
-
 
1014
				GENERATESTRINGSECTION("Bodies", this->m_lBodies);
-
 
1015
				break;
-
 
1016
		}
-
 
1017
 
-
 
1018
		if ( type.empty() ) continue;
-
 
1019
 
-
 
1020
		Utils::String fname = "GENERATED/types/" + type + ".txt";
-
 
1021
		
-
 
1022
		Utils::String fileData = "// Exported " + type + " file, Generated by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2) + "\r\n" + data;
-
 
1023
		if ( tmpFile.startWrite() ) {
-
 
1024
			tmpFile.write(fileData.c_str(), fileData.length());
-
 
1025
			tmpFile.close();
-
 
1026
		}
-
 
1027
 
-
 
1028
		// tships files
-
 
1029
		wsprintf(buf, L"%hs", fname.c_str());
-
 
1030
			
-
 
1031
		if ( tmpFile.startRead() ) {
-
 
1032
			size_t dataSize = 0;
-
 
1033
			unsigned char *data = tmpFile.readAll(&dataSize);
-
 
1034
			ZipAdd(hz, buf, data, dataSize);
-
 
1035
		}
-
 
1036
	}
887
}
1037
}
888
 
1038
 
889
bool CXspFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames)
1039
bool CXspFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames)
890
{
1040
{
891
	if ( sFirst.Compare("Shipyard") )
1041
	if ( sFirst.Compare("Shipyard") )
Line 1252... Line 1402...
1252
				|| type.Compare("TAT_PINGPONG")
1402
				|| type.Compare("TAT_PINGPONG")
1253
				|| type.Compare("TAT_TAGLOOP") )
1403
				|| type.Compare("TAT_TAGLOOP") )
1254
		return TAT_3;
1404
		return TAT_3;
1255
 
1405
 
1256
	return TAT_NONE;
1406
	return TAT_NONE;
-
 
1407
}
-
 
1408
 
-
 
1409
Utils::String CXspFile::TypesListToString(std::vector<STypesSection *> &list, bool deleteAfter)
-
 
1410
{
-
 
1411
	Utils::String data;
-
 
1412
 
-
 
1413
	for(std::vector<STypesSection *>::iterator itr = list.begin(); itr != list.end(); itr++) {
-
 
1414
		data += (*itr)->sSection + "; " + (long)(*itr)->lEntries.size() + ";\r\n";
-
 
1415
		for(Utils::SStringList *str = (*itr)->lEntries.First(); str; str = (*itr)->lEntries.Next()) {
-
 
1416
			data += str->str + "\r\n";
-
 
1417
		}
-
 
1418
 
-
 
1419
		if ( deleteAfter ) {
-
 
1420
			(*itr)->lEntries.MemoryClear();
-
 
1421
			delete *itr;
-
 
1422
		}
-
 
1423
	}
-
 
1424
 
-
 
1425
	return data;
1257
}
1426
}
1258
 
1427
 
1259
bool CXspFile::ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord)
1428
bool CXspFile::ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord)
1260
{
1429
{
1261
	Utils::String lastComment;
1430
	Utils::String lastComment;