Subversion Repositories spk

Rev

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

Rev 35 Rev 39
Line 39... Line 39...
39
	m_iOrgDesc = 0;
39
	m_iOrgDesc = 0;
40
 
40
 
41
	m_iShipyard = SHIPYARD_NONE;
41
	m_iShipyard = SHIPYARD_NONE;
42
}
42
}
43
 
43
 
44
void CXspFile::AddText ( int id, CyString name, CyString desc )
44
void CXspFile::AddText ( int id, const Utils::String &name, const Utils::String &desc )
45
{
45
{
46
	// first check if theres an existing id
46
	// first check if theres an existing id
47
	SText *newtext = NULL;
47
	SText *newtext = NULL;
48
	for ( SText *t = m_lText.First(); t; t = m_lText.Next() )
48
	for ( SText *t = m_lText.First(); t; t = m_lText.Next() )
49
	{
49
	{
Line 78... Line 78...
78
			return;
78
			return;
79
		}
79
		}
80
	}
80
	}
81
}
81
}
82
 
82
 
83
void CXspFile::AddDummy ( CyString section, CyString data )
83
void CXspFile::AddDummy ( const Utils::String &section, const Utils::String &data )
84
{
84
{
85
	SDummy *d = new SDummy;
85
	SDummy *d = new SDummy;
86
	d->sData = data;
86
	d->sData = data;
87
	d->sSection = section;
87
	d->sSection = section;
88
 
88
 
89
	if ( d->sData.Right (1) != ";" )
89
	if ( d->sData.right(1) != ";" )
90
		d->sData += ";";
90
		d->sData += ";";
91
 
91
 
92
	m_lDummy.push_back ( d );
92
	m_lDummy.push_back ( d );
93
 
93
 
94
	m_bChanged = true; 
94
	m_bChanged = true; 
95
}
95
}
96
 
96
 
97
void CXspFile::AddComponent ( CyString section, CyString section2, CyString data )
97
void CXspFile::AddComponent ( const Utils::String &section, const Utils::String &section2, const Utils::String &data )
98
{
98
{
99
	SComponent *c = new SComponent;
99
	SComponent *c = new SComponent;
100
	c->sData = data;
100
	c->sData = data;
101
	c->sSection = section;
101
	c->sSection = section;
102
	c->sSection2 = section2;
102
	c->sSection2 = section2;
103
 
103
 
104
	if ( c->sData.Right (1) != ";" )
104
	if ( c->sData.right(1) != ";" )
105
		c->sData += ";";
105
		c->sData += ";";
106
 
106
 
107
	m_lComponent.push_back ( c );
107
	m_lComponent.push_back ( c );
108
 
108
 
109
	m_bChanged = true; 
109
	m_bChanged = true; 
Line 190... Line 190...
190
			values += (long)wNode->Data()->iGame;
190
			values += (long)wNode->Data()->iGame;
191
			values += ":";
191
			values += ":";
192
			values += (long)wNode->Data()->iMask;
192
			values += (long)wNode->Data()->iMask;
193
		}
193
		}
194
		values += " ";
194
		values += " ";
195
		values += cockpit->sCockpit.ToString() + "\n";
195
		values += cockpit->sCockpit + "\n";
196
	}
196
	}
197
 
197
 
198
	for ( CListNode<SText> *tNode = m_lText.Front(); tNode; tNode = tNode->next() )
198
	for ( CListNode<SText> *tNode = m_lText.Front(); tNode; tNode = tNode->next() )
199
		values += Utils::String("Text: ") + (long)tNode->Data()->iId + "|" + tNode->Data()->sName.FindReplace("|", "<::PiPe::>").ToString() + "|" + tNode->;Data()->sDesc.ToString() + "\n";
199
		values += Utils::String("Text: ") + (long)tNode->Data()->iId + "|" + tNode->Data()->sName.findReplace("|", "<::PiPe::>") + "|" + tNode->;Data()->sDesc + "\n";
200
 
200
 
201
	for ( CListNode<SComponent> *cNode = m_lComponent.Front(); cNode; cNode = cNode->next() )
201
	for ( CListNode<SComponent> *cNode = m_lComponent.Front(); cNode; cNode = cNode->next() )
202
		values += Utils::String(&quot;Component: ") + cNode->Data()->sData.FindReplace("|", "<::PiPe::>").ToString() + "|" + cNode->;Data()->sSection.FindReplace(&quot;|", "<::PiPe::>").ToString() + &quot;|"; + cNode->Data()->sSection2.ToString() + "\n";
202
		values += "Component: &quot; + cNode->Data()->sData.findReplace("|", "<::PiPe::>") + "|" + cNode->;Data()->sSection.findReplace("|&quot;, "<::PiPe::>") + &quot;|"; + cNode->Data()->sSection2 + "\n";
203
 
203
 
204
	for ( CListNode<SDummy> *dNode = m_lDummy.Front(); dNode; dNode = dNode->next() )
204
	for ( CListNode<SDummy> *dNode = m_lDummy.Front(); dNode; dNode = dNode->next() )
205
		values += Utils::String("Dummy: ") + dNode->Data()->sData.FindReplace("|", "&lt;::PiPe::>").ToString() + "|" + dNode->Data()->sSection.ToString() + "\n";
205
		values += "Dummy: " + dNode->Data()->sData.findReplace("|", "&lt;::PiPe::>") + "|" + dNode->Data()->sSection + "\n";
206
 
206
 
207
	for ( CListNode<SWeaponMask> *wNode = m_lWeaponMasks.Front(); wNode; wNode = wNode->next() )
207
	for ( CListNode<SWeaponMask> *wNode = m_lWeaponMasks.Front(); wNode; wNode = wNode->next() )
208
		values += Utils::String("WeaponMask: ") + (long)wNode->Data()->iGame + " " + (long)wNode->Data()->iMask + "\n";
208
		values += Utils::String("WeaponMask: ") + (long)wNode->Data()->iGame + " " + (long)wNode->Data()->iMask + "\n";
209
	for ( CListNode<SWeaponMask> *mNode = m_lMissileMasks.Front(); mNode; mNode = mNode->next() )
209
	for ( CListNode<SWeaponMask> *mNode = m_lMissileMasks.Front(); mNode; mNode = mNode->next() )
210
		values += Utils::String("MissileMask: ") + (long)mNode->Data()->iGame + " " + (long)mNode->Data()->iMask + "\n";
210
		values += Utils::String("MissileMask: ") + (long)mNode->Data()->iGame + " " + (long)mNode->Data()->iMask + "\n";
Line 265... Line 265...
265
	else if ( first == "Text" )
265
	else if ( first == "Text" )
266
	{
266
	{
267
		SText *text = new SText;
267
		SText *text = new SText;
268
		text->iId = rest.token("|", 1);
268
		text->iId = rest.token("|", 1);
269
		text->sName = rest.token("|", 2);
269
		text->sName = rest.token("|", 2);
270
		text->sName = text->sName.FindReplace("<::PiPe::>", "|");
270
		text->sName = text->sName.findReplace("<::PiPe::>", "|");
271
		text->sDesc = rest.tokens( "|", 3);
271
		text->sDesc = rest.tokens( "|", 3);
272
		m_lText.push_back ( text );
272
		m_lText.push_back ( text );
273
	}
273
	}
274
	else if ( first == "Component" )
274
	else if ( first == "Component" )
275
	{
275
	{
276
		SComponent *c = new SComponent;
276
		SComponent *c = new SComponent;
277
		c->sData = rest.token("|", 1);
277
		c->sData = rest.token("|", 1);
278
		c->sData = c->sData.FindReplace ("<::PiPe::>", "|");
278
		c->sData = c->sData.findReplace ("<::PiPe::>", "|");
279
		c->sSection = rest.token("|", 2);
279
		c->sSection = rest.token("|", 2);
280
		c->sSection = c->sSection.FindReplace ("<::PiPe::>", "|");
280
		c->sSection = c->sSection.findReplace ("<::PiPe::>", "|");
281
		c->sSection2 = rest.tokens("|", 3);
281
		c->sSection2 = rest.tokens("|", 3);
282
		m_lComponent.push_back ( c );
282
		m_lComponent.push_back ( c );
283
	}
283
	}
284
	else if ( first == "Dummy" )
284
	else if ( first == "Dummy" )
285
	{
285
	{
286
		SDummy *d = new SDummy;
286
		SDummy *d = new SDummy;
287
		d->sData = rest.token("|", 1);
287
		d->sData = rest.token("|", 1);
288
		d->sData = d->sData.FindReplace ("<::PiPe::>", "|");
288
		d->sData = d->sData.findReplace ("<::PiPe::>", "|");
289
		d->sSection = rest.tokens( "|", 2);
289
		d->sSection = rest.tokens( "|", 2);
290
		m_lDummy.push_back ( d );
290
		m_lDummy.push_back ( d );
291
	}
291
	}
292
	else if ( first == "Comment" )
292
	else if ( first == "Comment" )
293
		m_sDescription = rest.findReplace("<newline>", "<br>");
293
		m_sDescription = rest.findReplace("<newline>", "<br>");
Line 295... Line 295...
295
		return CBaseFile::ParseValueLine(sLine);
295
		return CBaseFile::ParseValueLine(sLine);
296
 
296
 
297
	return true;
297
	return true;
298
}
298
}
299
 
299
 
300
CyString CXspFile::GetShipName(int lang)
300
Utils::String CXspFile::GetShipName(int lang)
301
{
301
{
302
	CyString name;
302
	Utils::String name;
303
	if ( (m_bLanguageText) && (lang) )
303
	if ( (m_bLanguageText) && (lang) )
304
	{
304
	{
305
		for ( SText *text = m_lText.First(); text; text = m_lText.Next() )
305
		for ( SText *text = m_lText.First(); text; text = m_lText.Next() )
306
		{
306
		{
307
			if ( text->iId == lang )
307
			if ( text->iId == lang )
Line 310... Line 310...
310
				break;
310
				break;
311
			}
311
			}
312
		}
312
		}
313
	}
313
	}
314
 
314
 
315
	if ( name.Empty() )
315
	if ( name.empty() )
316
		name = GetLanguageName(lang);
316
		name = GetLanguageName(lang).ToString();
317
 
317
 
318
	return name;
318
	return name;
319
}
319
}
320
 
320
 
-
 
321
//TODO: split this up
321
bool CXspFile::ConvertOld(CyString file)
322
bool CXspFile::ConvertOld(const Utils::String &file)
322
{
323
{
323
	// open the file
324
	// open the file
324
	FILE *id = fopen(file.c_str(), "rb");
325
	FILE *id = fopen(file.c_str(), "rb");
325
	if ( !id )
326
	if ( !id )
326
		return false;
327
		return false;
Line 353... Line 354...
353
	while ( pos < len )
354
	while ( pos < len )
354
	{
355
	{
355
		while ( compr[pos++] != '\n' && pos < len );
356
		while ( compr[pos++] != '\n' && pos < len );
356
 
357
 
357
		compr[pos - 1] = '\0';
358
		compr[pos - 1] = '\0';
358
		CyString line = (char *)(compr + start);
359
		Utils::String line = (char *)(compr + start);
359
		start = pos;
360
		start = pos;
360
		if ( line.Empty() )
361
		if ( line.empty() )
361
			continue;
362
			continue;
362
		CyString first = line.GetToken(":", 1, 1);
363
		Utils::String first = line.token(":", 1);
363
		CyString rest = line.GetToken(":", 2);
364
		Utils::String rest = line.tokens(":", 2);
364
		rest = rest.RemoveFirstSpace();
365
		rest = rest.removeFirstSpace();
365
 
366
 
366
		// now check each line
367
		// now check each line
367
		if ( first.Compare("Packager") )
368
		if ( first.Compare("Packager") )
368
			packageVersion = rest.ToInt();
369
			packageVersion = rest;
369
		else if ( first.Compare("Shipyard") )
370
		else if ( first.Compare("Shipyard") )
370
		{
371
		{
371
			int max;
372
			int max;
372
			CyString *strs = rest.SplitToken(";", &max);
373
			Utils::String *strs = rest.tokenise(";", &max);
373
			if ( strs && max )
374
			if ( strs && max )
374
			{
375
			{
375
				int cur = 1;
376
				int cur = 1;
376
				for ( int i = 0; i < max; i++, cur *= 2 )
377
				for ( int i = 0; i < max; i++, cur *= 2 )
377
				{
378
				{
Line 381... Line 382...
381
			}
382
			}
382
			CLEANSPLIT(strs, max)
383
			CLEANSPLIT(strs, max)
383
		}
384
		}
384
		else if ( first.Compare("ScreenShot") )
385
		else if ( first.Compare("ScreenShot") )
385
		{
386
		{
386
			int size = rest.GetToken(" ", 1, 1).ToInt();
387
			int size = rest.token(" ", 1);
387
			CyString ext = rest.GetToken(" ", 2, 2);
388
			Utils::String ext = rest.token(" ", 2);
388
 
389
 
389
			C_File *newFile = this->AddFile(CyString(m_sID) + ";_" + CyString::Number(this->CountFiles(FILETYPE_SCREEN) + 1) + "." + ext, "", FILETYPE_SCREEN);
390
			C_File *newFile = this->AddFile(m_sID + ";_" + (long)(this->CountFiles(FILETYPE_SCREEN) + 1) + "." + ext, "", FILETYPE_SCREEN);
390
			newFile->ReadFromData((char *)(compr + pos), size); 
391
			newFile->ReadFromData((char *)(compr + pos), size); 
391
 
392
 
392
			start += (size + 1);
393
			start += (size + 1);
393
		}
394
		}
394
		else if ( first.Compare("SceneFile") )
395
		else if ( first.Compare("SceneFile") )
395
		{
396
		{
396
			CyString file = rest.GetToken(" ", 3);
397
			Utils::String file = rest.tokens(" ", 3);
397
			m_pSceneFile = this->AddFile(CFileIO(file).GetFilename(), CFileIO(file).GetDir(), FILETYPE_SHIPSCENE);
398
			m_pSceneFile = this->AddFile(CFileIO(file).GetFilename(), CFileIO(file).GetDir(), FILETYPE_SHIPSCENE);
398
			m_pSceneFile->SetCreationTime(rest.GetToken(" ", 1, 1).ToLong());
399
			m_pSceneFile->SetCreationTime((long)rest.token(" ", 1));
399
			m_pSceneFile->ReadFromData((char *)(compr + pos), rest.GetToken(" ", 2, 2).ToInt());
400
			m_pSceneFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
400
 
401
 
401
			start += m_pSceneFile->GetDataSize();
402
			start += m_pSceneFile->GetDataSize();
402
		}
403
		}
403
		else if ( first.Compare("CockpitFile") )
404
		else if ( first.Compare("CockpitFile") )
404
		{
405
		{
405
			CyString file = rest.GetToken(" ", 3);
406
			Utils::String file = rest.tokens(" ", 3);
406
			m_pCockpitFile = this->AddFile(CFileIO(file).GetFilename(), CFileIO(file).GetDir(), FILETYPE_COCKPITSCENE);
407
			m_pCockpitFile = this->AddFile(CFileIO(file).GetFilename(), CFileIO(file).GetDir(), FILETYPE_COCKPITSCENE);
407
			m_pCockpitFile->SetCreationTime(rest.GetToken(" ", 1, 1).ToLong());
408
			m_pCockpitFile->SetCreationTime((long)rest.token(" ", 1));
408
			m_pCockpitFile->ReadFromData((char *)(compr + pos), rest.GetToken(" ", 2, 2).ToInt());
409
			m_pCockpitFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
409
 
410
 
410
			start += m_pCockpitFile->GetDataSize();
411
			start += m_pCockpitFile->GetDataSize();
411
		}
412
		}
412
		else if ( first.Compare("Model") )
413
		else if ( first.Compare("Model") )
413
		{
414
		{
414
			CyString file = rest.GetToken(" ", 3);
415
			Utils::String file = rest.tokens(" ", 3);
415
			C_File *newFile= this->AddFile(CFileIO(file).GetFilename(), CFileIO(file).GetDir(), FILETYPE_SHIPMODEL);
416
			C_File *newFile= this->AddFile(CFileIO(file).GetFilename(), CFileIO(file).GetDir(), FILETYPE_SHIPMODEL);
416
			newFile->SetCreationTime(rest.GetToken(" ", 1, 1).ToLong());
417
			newFile->SetCreationTime((long)rest.token(" ", 1));
417
			newFile->ReadFromData((char *)(compr + pos), rest.GetToken(" ", 2, 2).ToInt());
418
			newFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
418
 
419
 
419
			start += (newFile->GetDataSize() + 1);
420
			start += (newFile->GetDataSize() + 1);
420
		}
421
		}
421
		else if ( first.Compare("Files") )
422
		else if ( first.Compare("Files") )
422
		{
423
		{
423
			CyString file = rest.GetToken(" ", 3);
424
			Utils::String file = rest.tokens(" ", 3);
424
 
425
 
425
			C_File *newFile = NULL;
426
			C_File *newFile = NULL;
426
			int special = 0;
427
			int special = 0;
427
			if ( file.Compare("types/CutData.txt") || file.Compare("types/CutData.pck") )
428
			if ( file.Compare("types/CutData.txt") || file.Compare("types/CutData.pck") )
428
			{
429
			{
429
				newFile = new C_File(file);
430
				newFile = new C_File(CyString(file));
430
				special = 1;
431
				special = 1;
431
			}
432
			}
432
			else if ( file.Compare("types/Bodies.txt") || file.Compare("types/Bodies.pck") )
433
			else if ( file.Compare("types/Bodies.txt") || file.Compare("types/Bodies.pck") )
433
			{
434
			{
434
				newFile = new C_File(file);
435
				newFile = new C_File(CyString(file));
435
				special = 2;
436
				special = 2;
436
			}
437
			}
437
			else if ( file.Compare("types/Animations.txt") || file.Compare("types/Animations.pck") )
438
			else if ( file.Compare("types/Animations.txt") || file.Compare("types/Animations.pck") )
438
			{
439
			{
439
				newFile = new C_File(file);
440
				newFile = new C_File(CyString(file));
440
				special = 3;
441
				special = 3;
441
			}
442
			}
442
			else
443
			else
443
			{
444
			{
444
				newFile = this->AddFile(CFileIO(file).GetFilename(), CFileIO(file).GetDir(), FILETYPE_SHIPOTHER);
445
				newFile = this->AddFile(CFileIO(file).GetFilename(), CFileIO(file).GetDir(), FILETYPE_SHIPOTHER);
445
				newFile->SetCreationTime(rest.GetToken(" ", 1, 1).ToLong());
446
				newFile->SetCreationTime((long)rest.token(" ", 1));
446
			}
447
			}
447
			newFile->ReadFromData((char *)(compr + pos), rest.GetToken(" ", 2, 2).ToInt());
448
			newFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
448
			start += (newFile->GetDataSize() + 1);
449
			start += (newFile->GetDataSize() + 1);
449
 
450
 
450
			if ( special )
451
			if ( special )
451
			{
452
			{
452
				if ( newFile->CheckFileExt("pck") )
453
				if ( newFile->CheckFileExt("pck") )
Line 513... Line 514...
513
									break;
514
									break;
514
							}
515
							}
515
						}
516
						}
516
 
517
 
517
						for ( SStringList *strNode = newLines.Head(); strNode; strNode = strNode->next )
518
						for ( SStringList *strNode = newLines.Head(); strNode; strNode = strNode->next )
518
							this->AddCutData(strNode->str);
519
							this->AddCutData(strNode->str.ToString());
519
					}
520
					}
520
					// bodies
521
					// bodies
521
					else if ( special == 2 )
522
					else if ( special == 2 )
522
					{
523
					{
523
						entries = 0;
524
						entries = 0;
524
						CyString section;
525
						Utils::String section;
525
						for ( int i = 0; i < iLines; i++ )
526
						for ( int i = 0; i < iLines; i++ )
526
						{
527
						{
527
							CyString line = sLines[i];
528
							Utils::String line = sLines[i].ToString();
528
							line.RemoveChar(' ');
529
							line.removeChar(' ');
529
							line.RemoveChar(9);
530
							line.removeChar(9);
530
							if ( line.Empty() || line[0] == '/' )
531
							if ( line.empty() || line[0] == '/' )
531
								continue;
532
								continue;
532
							if ( entries <= 0)
533
							if ( entries <= 0)
533
							{
534
							{
534
								section = line.GetToken(";", 1, 1);
535
								section = line.token(";", 1);
535
								entries	= line.GetToken(";", 2, 2).ToInt();
536
								entries	= line.token(";", 2);
536
							}
537
							}
537
							else
538
							else
538
							{
539
							{
539
								if ( !line.IsIn(";") )
540
								if ( !line.isin(";") )
540
									continue;
541
									continue;
541
								if ( line.NumToken(";") <= 2 )
542
								if ( line.countToken(";") <= 2 )
542
								{
543
								{
543
									this->AddBodies(section + ";" + line.GetToken(";", 1, 1) + ";");
544
									this->AddBodies(section + ";" + line.token(";", 1) + ";");
544
									--entries;
545
									--entries;
545
								}
546
								}
546
								else
547
								else
547
								{
548
								{
548
									bool done = false;
549
									bool done = false;
549
									while (!done)
550
									while (!done)
550
									{
551
									{
551
										int num;
552
										int num;
552
										CyString *strs = line.SplitToken(";", &num);
553
										Utils::String *strs = line.tokenise(";", &num);
553
										done = true;
554
										done = true;
554
										for ( int j = 0; j < num; j++ )
555
										for ( int j = 0; j < num; j++ )
555
										{
556
										{
556
											if ( !entries )
557
											if ( !entries )
557
											{
558
											{
558
												line = line.GetToken(";", j + 1);
559
												line = line.tokens(";", j + 1);
559
												if ( !line.Empty() )
560
												if ( !line.empty() )
560
													done = false;
561
													done = false;
561
												break;
562
												break;
562
											}
563
											}
563
 
564
 
564
											if ( strs[j].Empty() )
565
											if ( strs[j].empty() )
565
												continue;
566
												continue;
566
											
567
											
567
											this->AddBodies(section + ";" + strs[j] + ";");
568
											this->AddBodies(section + ";" + strs[j] + ";");
568
											--entries;
569
											--entries;
569
										}
570
										}
570
										//we must be at another section
571
										//we must be at another section
571
										if ( !done )
572
										if ( !done )
572
										{
573
										{
573
											section = line.GetToken(";", 1, 1);
574
											section = line.token(";", 1);
574
											entries	= line.GetToken(";", 2, 2).ToInt();
575
											entries	= line.token(";", 2);
575
											line = line.RemToken(";", 1);
576
											line = line.remToken(";", 1);
576
											line = line.RemToken(";", 1);
577
											line = line.remToken(";", 1);
577
 
578
 
578
											if (line.Empty())
579
											if (line.empty())
579
												done = true;
580
												done = true;
580
										}
581
										}
581
 
582
 
582
										CLEANSPLIT(strs, num)
583
										CLEANSPLIT(strs, num)
583
									}									
584
									}									
Line 604... Line 605...
604
				delete newFile;
605
				delete newFile;
605
			}
606
			}
606
		}
607
		}
607
		else if ( first.Compare("Script") )
608
		else if ( first.Compare("Script") )
608
		{
609
		{
609
			CyString file = rest.GetToken(" ", 3);
610
			Utils::String file = rest.words(3);
610
			C_File *newFile= this->AddFile(file, NullString, FILETYPE_SCRIPT);
611
			C_File *newFile= this->AddFile(file, NullString, FILETYPE_SCRIPT);
611
			newFile->SetCreationTime(rest.GetToken(" ", 1, 1).ToLong());
612
			newFile->SetCreationTime((long)rest.word(1));
612
			newFile->ReadFromData((char *)(compr + pos), rest.GetToken(" ", 2, 2).ToInt());
613
			newFile->ReadFromData((char *)(compr + pos), rest.word(2));
613
 
614
 
614
			start += (newFile->GetDataSize() + 1);
615
			start += (newFile->GetDataSize() + 1);
615
		}
616
		}
616
		else if ( first.Compare("Text") )
617
		else if ( first.Compare("Text") )
617
			this->AddText(rest.GetToken ( ":&quot;, 1, 1 ).ToInt(), rest.GetToken ( ":&quot;, 2, 2 ), rest.GetToken ( ":", 3 ));
618
			this->AddText(rest.token(":&quot;, 1), rest.token(":&quot;, 2), rest.tokens(":", 3));
618
		else if ( first.Compare("Component") )
619
		else if ( first.Compare("Component") )
619
			this->AddComponent(rest.GetToken ( ";&quot;, 1, 1 ), rest.GetToken ( ";", 2, 2 ), rest.GetToken ( ";", 3 ));
620
			this->AddComponent(rest.token(";&quot;, 1), rest.token(";", 2), rest.tokens(";", 3));
620
		else if ( first.Compare("Dummy") )
621
		else if ( first.Compare("Dummy") )
621
		{
622
		{
622
			SDummy *d = new SDummy;
623
			SDummy *d = new SDummy;
623
			d->sData = rest.GetToken ( ";;", 2 );
624
			d->sData = rest.tokens(";;", 2);
624
			d->sSection = rest.GetToken ( ";;", 1, 1 );
625
			d->sSection = rest.token(";;", 1);
625
			m_lDummy.push_back ( d );
626
			m_lDummy.push_back ( d );
626
		}
627
		}
627
		else if ( !this->ParseValueLine(line.ToString()) )
628
		else if ( !this->ParseValueLine(line) )
628
		{
629
		{
629
		//	printf ( "Command: %s, Rest: %s\n", first.c_str(), rest.c_str());
630
		//	printf ( "Command: %s, Rest: %s\n", first.c_str(), rest.c_str());
630
		}
631
		}
631
 
632
 
632
		pos = start;
633
		pos = start;
633
	}
634
	}
634
 
635
 
635
	// assume all old ones are for X3
636
	// assume all old ones are for X3
636
	if ( !m_sData.empty() )
637
	if ( !m_sData.empty() )
637
	{
638
	{
638
		this->AddWeaponMask(GAME_X3 - 1, m_sData.token(";", 19));
639
		this->AddWeaponMask(GAME_X3 - 1, m_sData.token(";", 19));
639
		this->AddMissileMask(GAME_X3 - 1, m_sData.token(";", 25));
640
		this->AddMissileMask(GAME_X3 - 1, m_sData.token(";", 25));
640
	}
641
	}
641
 
642
 
642
	return true;
643
	return true;
643
}
644
}
644
 
645
 
645
 
646
 
646
int GetMaxShipyards() { return (int)SHIPYARD_MAX; }
647
int GetMaxShipyards() { return (int)SHIPYARD_MAX; }
647
 
648
 
648
CyString GetShipyardName (int s)
649
Utils::String GetShipyardName (int s)
649
{
650
{
650
	switch (s)
651
	switch (s)
651
	{
652
	{
652
		case SHIPYARD_ARGON:
653
		case SHIPYARD_ARGON:
653
			return "Argon";
654
			return "Argon";
Line 668... Line 669...
668
		case SHIPYARD_TERRAN:
669
		case SHIPYARD_TERRAN:
669
			return "Terran";
670
			return "Terran";
670
	}
671
	}
671
 
672
 
672
	return "Unknown";
673
	return "Unknown";
673
}
674
}
674
 
675
 
675
bool CXspFile::WriteHeader(FILE *id, int valueheader, int valueComprLen)
676
bool CXspFile::WriteHeader(FILE *id, int valueheader, int valueComprLen)
676
{
677
{
677
	fprintf ( id, "XSPCycrow;%.2f;%d;%d\n", FILEVERSION, valueheader, valueComprLen );
678
	fprintf ( id, "XSPCycrow;%.2f;%d;%d\n", FILEVERSION, valueheader, valueComprLen );
678
	if ( ferror(id) )
679
	if ( ferror(id) )
679
		return false;
680
		return false;
680
	return true;
681
	return true;
681
}
682
}
682
 
683
 
683
bool CXspFile::CheckHeader(const Utils::String header) const
684
bool CXspFile::CheckHeader(const Utils::String header) const
684
{
685
{
685
	if ( header.Compare("XSPCycrow") )
686
	if ( header.Compare("XSPCycrow") )
686
		return true;
687
		return true;
687
	return false;
688
	return false;
688
}
689
}
689
 
690
 
690
void CXspFile::SetLaserMask(int game, int mask)
691
void CXspFile::SetLaserMask(int game, int mask)
691
{
692
{
692
	for ( CListNode<SWeaponMask> *node = m_lWeaponMasks.Front(); node; node = node->next() )
693
	for ( CListNode<SWeaponMask> *node = m_lWeaponMasks.Front(); node; node = node->next() )
693
	{
694
	{
694
		SWeaponMask *m = node->Data();
695
		SWeaponMask *m = node->Data();
695
		if ( m->iGame == game )
696
		if ( m->iGame == game )
696
		{
697
		{
697
			m->iMask = mask;
698
			m->iMask = mask;
698
			return;
699
			return;
699
		}
700
		}
700
	}
701
	}
701
 
702
 
702
	// no found, need to add it
703
	// no found, need to add it
703
	this->AddWeaponMask(game, mask);
704
	this->AddWeaponMask(game, mask);
704
}
705
}
705
 
706
 
706
void CXspFile::SetMissileMask(int game, int mask)
707
void CXspFile::SetMissileMask(int game, int mask)
707
{
708
{
Line 748... Line 749...
748
	}
749
	}
749
 
750
 
750
	return mask;
751
	return mask;
751
}
752
}
752
 
753
 
753
CyString CXspFile::GetShipClass()
754
Utils::String CXspFile::GetShipClass()
754
{
755
{
755
	if ( !m_sData.empty() )
756
	if ( !m_sData.empty() )
756
		return m_sData.token(";", TSHIPPOS_CLASS);
757
		return m_sData.token(";", TSHIPPOS_CLASS);
757
	return "OBJ_SHIP_M5";
758
	return "OBJ_SHIP_M5";
758
}
759
}
Line 813... Line 814...
813
{
814
{
814
	if ( sFirst.Compare("Shipyard") )
815
	if ( sFirst.Compare("Shipyard") )
815
	{
816
	{
816
		for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
817
		for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
817
		{
818
		{
818
			if ( sRest.Compare(GetShipyardName(i).ToString()) )
819
			if ( sRest.Compare(GetShipyardName(i)) )
819
			{
820
			{
820
				this->AddShipyard(i);
821
				this->AddShipyard(i);
821
				break;
822
				break;
822
			}
823
			}
823
		}
824
		}
Line 842... Line 843...
842
 
843
 
843
	return true;
844
	return true;
844
}
845
}
845
 
846
 
846
 
847
 
847
CyString CXspFile::GetX3ShipData()
848
Utils::String CXspFile::GetX3ShipData()
848
{
849
{
849
	CyString data = m_sData;
850
	Utils::String data = m_sData;
850
 
851
 
851
	// change the ship subtype, Reunion uses number, TC uses a define
852
	// change the ship subtype, Reunion uses number, TC uses a define
852
	CyString sSubType = data.GetToken(";", 6, 6);
853
	Utils::String sSubType = data.token(";", 6);
853
	if ( !sSubType.ToInt() && sSubType != "0" )
854
	if ( !((long)sSubType) && sSubType != "0" )
854
		data = data.RepToken(";", 6, CyString::Number(CShipData::ConvertShipSubType(sSubType)));
855
		data = data.replaceToken(";", 6, (long)CShipData::ConvertShipSubType(CyString(sSubType)));
855
 
856
 
856
	CyString sClass = data.GetToken(";", TSHIPPOS_CLASS, TSHIPPOS_CLASS);
857
	Utils::String sClass = data.token(";", TSHIPPOS_CLASS);
857
	if ( !sClass.ToInt() && sClass != "0" )
858
	if ( !((long)sClass) && sClass != "0" )
858
	{
859
	{
859
		int num = 0;
860
		int num = 0;
860
		for ( int i = 0; i < OBJ_SHIP_MAX; i++ )
861
		for ( int i = 0; i < OBJ_SHIP_MAX; i++ )
861
		{
862
		{
862
			if ( sClass.Compare(CShipData::ConvertShipClass(CShipData::GetShipClassFromNum(i))) )
863
			if ( sClass.Compare(CShipData::ConvertShipClass(CShipData::GetShipClassFromNum(i)).ToString()) )
863
			{
864
			{
864
				num = i;
865
				num = i;
865
				break;
866
				break;
866
			}
867
			}
867
		}
868
		}
868
 
869
 
869
		data = data.RepToken(";", TSHIPPOS_CLASS, CyString::Number(num));
870
		data = data.replaceToken(";", TSHIPPOS_CLASS, (long)num);
870
	}
871
	}
871
 
872
 
872
	return data;
873
	return data;
873
}
874
}
874
 
875
 
875
CyString CXspFile::GetTCShipData()
876
Utils::String CXspFile::GetTCShipData()
876
{
877
{
877
	CyString data = m_sData;
878
	Utils::String data = m_sData;
878
 
879
 
879
	CyString sSubType = data.GetToken(";", 6, 6);
880
	Utils::String sSubType = data.token(";", 6);
880
	if ( sSubType.ToInt() || sSubType == "0" )
881
	if ( ((long)sSubType) || sSubType == "0" )
881
		data = data.RepToken(";", 6, CShipData::ConvertShipSubType(sSubType.ToInt()));
882
		data = data.replaceToken(";", 6, CShipData::ConvertShipSubType((long)sSubType).ToString());
882
 
883
 
883
	CyString sClass = data.GetToken(";", TSHIPPOS_CLASS, TSHIPPOS_CLASS);
884
	Utils::String sClass = data.token(";", TSHIPPOS_CLASS);
884
	if ( sClass.ToInt() || sClass == "0" )
885
	if ( ((long)sClass) || sClass == "0" )
885
		data = data.RepToken(";", TSHIPPOS_CLASS, CShipData::ConvertShipClass(sClass.ToInt()));
886
		data = data.replaceToken(";", TSHIPPOS_CLASS, CShipData::ConvertShipClass((long)sClass).ToString());
886
 
887
 
887
	return data;
888
	return data;
888
}
889
}
889
 
890
 
890
bool CXspFile::RemoveCockpit(CyString cockpitid)
891
bool CXspFile::RemoveCockpit(const Utils::String &sCockpitId)
891
{
892
{
-
 
893
	Utils::String cockpitid = sCockpitId;
892
	// if its a whole line, just get the end
894
	// if its a whole line, just get the end
893
	if ( cockpitid.IsIn(";") )
895
	if ( cockpitid.isin(";") )
894
	{
896
	{
895
		cockpitid = cockpitid.GetToken(";", -2);
897
		cockpitid = cockpitid.tokens(";", -2);
896
		while ( cockpitid.Right(1) == ";" )
898
		while ( cockpitid.right(1) == ";" )
897
			cockpitid.Truncate((int)cockpitid.Length() - 1);
899
			cockpitid.truncate(-1);
898
	}
900
	}
899
 
901
 
900
	bool ret = false;
902
	bool ret = false;
901
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
903
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
902
	{
904
	{
903
		CyString id = node->Data()->sCockpit.GetToken(";", 19, 19);
905
		Utils::String id = node->Data()->sCockpit.token(";", 19);
904
		if ( id.Compare(cockpitid) )
906
		if ( id.Compare(cockpitid) )
905
		{
907
		{
906
			node->DeleteData();
908
			node->DeleteData();
907
			ret = true;
909
			ret = true;
908
			break;
910
			break;
Line 912... Line 914...
912
	m_lCockpit.RemoveEmpty();
914
	m_lCockpit.RemoveEmpty();
913
 
915
 
914
	return ret;
916
	return ret;
915
}
917
}
916
 
918
 
917
bool CXspFile::RemoveComponent(CyString section1, CyString section2, CyString data)
919
bool CXspFile::RemoveComponent(const Utils::String &section1, const Utils::String &section2, const Utils::String &data)
918
{
920
{
919
	bool ret = false;
921
	bool ret = false;
920
	for ( CListNode<SComponent> *node = m_lComponent.Front(); node; node = node->next() )
922
	for ( CListNode<SComponent> *node = m_lComponent.Front(); node; node = node->next() )
921
	{
923
	{
922
		if ( node->Data()->sSection.Compare(section1) && node->Data()->sSection2.Compare(section2) && node->Data()->sData.Compare(data) )
924
		if ( node->Data()->sSection.Compare(section1) && node->Data()->sSection2.Compare(section2) && node->Data()->sData.Compare(data) )
Line 928... Line 930...
928
	}
930
	}
929
	m_lComponent.RemoveEmpty();
931
	m_lComponent.RemoveEmpty();
930
	return ret;
932
	return ret;
931
}
933
}
932
 
934
 
933
bool CXspFile::RemoveDummy(CyString section, CyString data)
935
bool CXspFile::RemoveDummy(const Utils::String &section, const Utils::String &data)
934
{
936
{
935
	bool ret = false;
937
	bool ret = false;
936
	for ( CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next() )
938
	for ( CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next() )
937
	{
939
	{
938
		if ( node->Data()->sSection.Compare(section) && node->Data()->sData.Compare(data) )
940
		if ( node->Data()->sSection.Compare(section) && node->Data()->sData.Compare(data) )
Line 945... Line 947...
945
	m_lDummy.RemoveEmpty();
947
	m_lDummy.RemoveEmpty();
946
 
948
 
947
	return ret;
949
	return ret;
948
}
950
}
949
 
951
 
950
CyString CXspFile::GetCockpitData(CyString cid)
952
Utils::String CXspFile::GetCockpitData(const Utils::String &cid)
951
{
953
{
952
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
954
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
953
	{
955
	{
954
		CyString id = node->Data()->sCockpit.GetToken(";", 19, 19);
956
		Utils::String id = node->Data()->sCockpit.token(";", 19);
955
		if ( id.Compare(cid) )
957
		if ( id.Compare(cid) )
956
			return node->Data()->sCockpit;
958
			return node->Data()->sCockpit;
957
	}
959
	}
958
 
960
 
959
	return NullString;
961
	return "";
960
}
962
}
961
 
963
 
962
SCockpit *CXspFile::FindCockpit(CyString cid)
964
SCockpit *CXspFile::FindCockpit(const Utils::String &cid)
963
{
965
{
964
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
966
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
965
	{
967
	{
966
		CyString id = node->Data()->sCockpit.GetToken(";", 19, 19);
968
		Utils::String id = node->Data()->sCockpit.token(";", 19);
967
		if ( id.Compare(cid) )
969
		if ( id.Compare(cid) )
968
			return node->Data();
970
			return node->Data();
969
	}
971
	}
970
 
972
 
971
	return NULL;
973
	return NULL;
972
}
974
}
973
 
975
 
974
void CXspFile::EditCockpit(CyString cid, CyString cockpit)
976
void CXspFile::EditCockpit(const Utils::String &cid, const Utils::String &cockpit)
975
{
977
{
976
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
978
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
977
	{
979
	{
978
		CyString id = node->Data()->sCockpit.GetToken(";", 19, 19);
980
		Utils::String id = node->Data()->sCockpit.token(";", 19);
979
		if ( id.Compare(cid) )
981
		if ( id.Compare(cid) )
980
		{
982
		{
981
			node->Data()->sCockpit = cockpit;
983
			node->Data()->sCockpit = cockpit;
982
			break;
984
			break;
983
		}
985
		}
984
	}
986
	}
985
}
987
}
986
 
988
 
987
void CXspFile::EditCockpit(CyString cid, CyString scene, int mask)
989
void CXspFile::EditCockpit(const Utils::String &cid, const Utils::String &scene, int mask)
988
{
990
{
989
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
991
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
990
	{
992
	{
991
		CyString id = node->Data()->sCockpit.GetToken(";", 19, 19);
993
		Utils::String id = node->Data()->sCockpit.token(";", 19);
992
		if ( id.Compare(cid) )
994
		if ( id.Compare(cid) )
993
		{
995
		{
994
			CyString cockpit = node->Data()->sCockpit;
996
			Utils::String cockpit = node->Data()->sCockpit;
995
			cockpit = cockpit.RepToken(";", 8, scene);
997
			cockpit = cockpit.replaceToken(";", 8, scene);
996
			cockpit = cockpit.RepToken(";", 9, CyString::Number(mask));
998
			cockpit = cockpit.replaceToken(";", 9, (long)mask);
997
			node->Data()->sCockpit = cockpit;
999
			node->Data()->sCockpit = cockpit;
998
			break;
1000
			break;
999
		}
1001
		}
1000
	}
1002
	}
1001
}
1003
}
1002
void CXspFile::NewCockpit(CyString id, CyString scene, int mask)
1004
void CXspFile::NewCockpit(const Utils::String &id, const Utils::String &scene, int mask)
1003
{
1005
{
1004
	CyString cockpit = "0;0;0;0;0;0;0;";
1006
	Utils::String cockpit = "0;0;0;0;0;0;0;";
1005
	cockpit += scene + ";";
1007
	cockpit += scene + ";";
1006
	cockpit += CyString::Number(mask);
1008
	cockpit += (long)mask;
1007
	cockpit += ";0;0;0;0;0;0;-100000;0;0;";
1009
	cockpit += ";0;0;0;0;0;0;-100000;0;0;";
1008
	cockpit += id + ";";
1010
	cockpit += id + ";";
1009
	this->AddCockpit(cockpit, -1);
1011
	this->AddCockpit(cockpit, -1);
1010
}
1012
}
1011
 
1013
 
1012
bool CXspFile::RemoveCutData(CyString cut)
1014
bool CXspFile::RemoveCutData(const Utils::String &cut)
1013
{
1015
{
1014
	bool ret = false;
1016
	bool ret = false;
1015
	for ( SStringList *str = m_lCutData.Head(); str; str = str->next )
1017
	for ( SStringList *str = m_lCutData.Head(); str; str = str->next )
1016
	{
1018
	{
1017
		if ( str->str.GetToken(";", 1, 1).Compare(cut.GetToken(";", 1, 1)) )
1019
		if ( str->str.GetToken(";", 1, 1).Compare(CyString(cut.token(";", 1))) )
1018
		{
1020
		{
1019
			ret = true;
1021
			ret = true;
1020
			str->remove = true;
1022
			str->remove = true;
1021
			break;
1023
			break;
1022
		}
1024
		}
Line 1025... Line 1027...
1025
	m_lCutData.RemoveMarked();
1027
	m_lCutData.RemoveMarked();
1026
 
1028
 
1027
	return ret;
1029
	return ret;
1028
}
1030
}
1029
 
1031
 
1030
bool CXspFile::RemoveBodies(CyString cut)
1032
bool CXspFile::RemoveBodies(const Utils::String &cut)
1031
{
1033
{
1032
	bool ret = false;
1034
	bool ret = false;
1033
	for ( SStringList *str = m_lBodies.Head(); str; str = str->next )
1035
	for ( SStringList *str = m_lBodies.Head(); str; str = str->next )
1034
	{
1036
	{
1035
		if ( str->str.Remove(' ').Compare(cut.Remove(' ')) )
1037
		if ( str->str.Remove(' ').Compare(CyString(cut.remove(' '))) )
1036
		{
1038
		{
1037
			ret = true;
1039
			ret = true;
1038
			str->remove = true;
1040
			str->remove = true;
1039
			break;
1041
			break;
1040
		}
1042
		}
1041
	}
1043
	}
1042
 
1044
 
1043
	m_lBodies.RemoveMarked();
1045
	m_lBodies.RemoveMarked();
1044
 
1046
 
1045
	return ret;
1047
	return ret;
1046
}
1048
}
1047
 
1049
 
1048
bool CXspFile::RemoveAnimation(CyString cut)
1050
bool CXspFile::RemoveAnimation(const Utils::String &cut)
1049
{
1051
{
1050
	bool ret = false;
1052
	bool ret = false;
1051
	for ( SStringList *str = m_lAnimations.Head(); str; str = str->next )
1053
	for ( SStringList *str = m_lAnimations.Head(); str; str = str->next )
1052
	{
1054
	{
1053
		if ( str->str.Remove(' ').Remove('\n').Compare(cut.Remove(' ').Remove(&apos;\n')) )
1055
		if ( str->str.Remove(' ').Remove('\n').Compare(CyString(cut.remove(' ').remove(&apos;\n'))) )
1054
		{
1056
		{
1055
			ret = true;
1057
			ret = true;
1056
			str->remove = true;
1058
			str->remove = true;
1057
			break;
1059
			break;
1058
		}
1060
		}
Line 1061... Line 1063...
1061
	m_lAnimations.RemoveMarked();
1063
	m_lAnimations.RemoveMarked();
1062
 
1064
 
1063
	return ret;
1065
	return ret;
1064
}
1066
}
1065
 
1067
 
1066
void CXspFile::AddCockpit(CyString cockpit, int game, int mask, int index)
1068
void CXspFile::AddCockpit(const Utils::String &cockpit, int game, int mask, int index)
1067
{
1069
{
1068
	SCockpit *pCockpit = NULL;
1070
	SCockpit *pCockpit = NULL;
1069
 
1071
 
1070
	// first search for the cockpit entry
1072
	// first search for the cockpit entry
1071
	CyString cid = cockpit.GetToken(";", 19, 19);
1073
	Utils::String cid = cockpit.token(";", 19);
1072
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1074
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() )
1073
	{
1075
	{
1074
		CyString id = node->Data()->sCockpit.GetToken(";", 19, 19);
1076
		Utils::String id = node->Data()->sCockpit.token(";", 19);
1075
		if ( id.Compare(cid) )
1077
		if ( id.Compare(cid) )
1076
		{
1078
		{
1077
			pCockpit = node->Data();
1079
			pCockpit = node->Data();
1078
			break;
1080
			break;
1079
		}
1081
		}
Line 1102... Line 1104...
1102
				break;
1104
				break;
1103
			}
1105
			}
1104
		}
1106
		}
1105
 
1107
 
1106
		if ( !wm )
1108
		if ( !wm )
1107
		{
1109
		{
1108
			wm = new SWeaponMask;
1110
			wm = new SWeaponMask;
1109
			pCockpit->lWeaponMask.push_back(wm);
1111
			pCockpit->lWeaponMask.push_back(wm);
1110
		}
1112
		}
1111
 
1113
 
1112
		wm->iGame = game;
1114
		wm->iGame = game;
1113
		if ( mask == -1 )
1115
		if ( mask == -1 )
1114
			wm->iMask = cockpit.GetToken(";", 9, 9).ToInt();
1116
			wm->iMask = cockpit.token(";", 9);
1115
		else
1117
		else
1116
			wm->iMask = mask;
1118
			wm->iMask = mask;
1117
	}
1119
	}
1118
	m_bChanged = true; 
1120
	m_bChanged = true; 
1119
}
1121
}
1120
 
1122
 
1121
void CXspFile::AddBody(CyString section, CyString data)
1123
void CXspFile::AddBody(const Utils::String &section, const Utils::String &data)
1122
{
1124
{
1123
	this->AddBodies(section + ";" + data);
1125
	this->AddBodies(section + ";" + data);
1124
	m_bChanged = true; 
1126
	m_bChanged = true; 
1125
}
1127
}
1126
void CXspFile::AddBodies(CyString data)
1128
void CXspFile::AddBodies(const Utils::String &sData)
1127
{
1129
{
-
 
1130
	Utils::String data = sData;
1128
	if ( !data.IsNumber() )
1131
	if ( !data.isNumber() )
1129
	{
1132
	{
1130
		if ( data[(int)(data.Length() - 5)] == '.' )
1133
		if ( data[(int)(data.length() - 5)] == '.' )
1131
			data = data.Left(-5);
1134
			data = data.left(-5);
1132
		else if ( data[(int)(data.Length() - 4)] == '.' )
1135
		else if ( data[(int)(data.length() - 4)] == '.' )
1133
			data = data.Left(-4);
1136
			data = data.left(-4);
1134
		if ( data.Right(1) != ";" )
1137
		if ( data.right(1) != ";" )
1135
			data += ";";
1138
			data += ";";
1136
	}
1139
	}
1137
	m_lBodies.PushBack(data, true);
1140
	m_lBodies.PushBack(CyString(data), true);
1138
	m_bChanged = true; 
1141
	m_bChanged = true; 
1139
}
1142
}
1140
 
1143
 
1141
int CXspFile::GetAnimationType(CyString type)
1144
int CXspFile::GetAnimationType(const Utils::String &type)
1142
{
1145
{
1143
	if ( type.Compare("TAT_TAGSINGLESTEP") )
1146
	if ( type.Compare("TAT_TAGSINGLESTEP") )
1144
		return TAT_SINGLE;
1147
		return TAT_SINGLE;
1145
	else if ( type.Compare("TAT_TAGONESHOT") 
1148
	else if ( type.Compare("TAT_TAGONESHOT") 
1146
				|| type.Compare("TAT_TAGONESHOT_REINIT") 
1149
				|| type.Compare("TAT_TAGONESHOT_REINIT") 
Line 1151... Line 1154...
1151
	return TAT_NONE;
1154
	return TAT_NONE;
1152
}
1155
}
1153
 
1156
 
1154
bool CXspFile::ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord)
1157
bool CXspFile::ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord)
1155
{
1158
{
1156
	CyString lastComment;
1159
	Utils::String lastComment;
1157
	CyString addEntry;
1160
	Utils::String addEntry;
1158
	int remaining = 0;
1161
	int remaining = 0;
1159
	CyString lastType;
1162
	Utils::String lastType;
1160
	int newEntries = 0;
1163
	int newEntries = 0;
1161
	int entries = -1;
1164
	int entries = -1;
1162
	for ( SStringList *strNode = lIn->Head(); strNode; strNode = strNode->next )
1165
	for ( SStringList *strNode = lIn->Head(); strNode; strNode = strNode->next )
1163
	{
1166
	{
1164
		CyString line = strNode->str;
1167
		Utils::String line = strNode->str.ToString();
1165
		line.RemoveChar('\r');
1168
		line.removeChar('\r');
1166
		line.RemoveChar(9);
1169
		line.removeChar(9);
1167
		if ( line.Empty() || line[0] == '/' )
1170
		if ( line.empty() || line[0] == '/' )
1168
			continue;
1171
			continue;
1169
		if ( entries == -1)
1172
		if ( entries == -1)
1170
		{
1173
		{
1171
			entries	= line.GetToken(";", 1, 1).ToInt();
1174
			entries	= line.token(";", 1);
1172
			newEntries = entries - startRecord;
1175
			newEntries = entries - startRecord;
1173
		}
1176
		}
1174
		else
1177
		else
1175
		{
1178
		{
1176
			// remove comments, endspaces and last ;
1179
			// remove comments, endspaces and last ;
1177
			CyString sStriped = line;
1180
			Utils::String sStriped = line;
1178
			if ( sStriped.IsIn("//") )
1181
			if ( sStriped.isin("//") )
1179
			{
1182
			{
1180
				if ( entries <= newEntries )
1183
				if ( entries <= newEntries )
1181
					lastComment = CyString("//") + sStriped.GetToken("//", 2);
1184
					lastComment = "//" + sStriped.tokens("//", 2);
1182
				sStriped = sStriped.GetToken("//", 1, 1);
1185
				sStriped = sStriped.token("//", 1);
1183
			}
1186
			}
1184
			sStriped.RemoveEndSpace();
1187
			sStriped.removeEndSpace();
1185
			if ( sStriped.Right(1) == ";" )
1188
			if ( sStriped.right(1) == ";" )
1186
				sStriped.Truncate(-1);
1189
				sStriped.truncate(-1);
1187
 
1190
 
1188
			CyString sRemainingLeft;
1191
			Utils::String sRemainingLeft;
1189
			if ( remaining > 0 )
1192
			if ( remaining > 0 )
1190
				sRemainingLeft = sStriped;
1193
				sRemainingLeft = sStriped;
1191
			else
1194
			else
1192
			{
1195
			{
1193
				// each line should be a new entry, with some exceptions
1196
				// each line should be a new entry, with some exceptions
1194
				// potection for new lines
1197
				// potection for new lines
1195
				lastType = sStriped.GetToken(";", 1, 1);
1198
				lastType = sStriped.token(";", 1);
1196
 
1199
 
1197
				switch (CXspFile::GetAnimationType(lastType))
1200
				switch (CXspFile::GetAnimationType(lastType))
1198
				{
1201
				{
1199
					case TAT_SINGLE:
1202
					case TAT_SINGLE:
1200
						remaining = sStriped.GetToken(";", 5, 5).ToInt() + 1;
1203
						remaining = (long)sStriped.token(";", 5) + 1;
1201
						sRemainingLeft = sStriped.GetToken(";", 6);
1204
						sRemainingLeft = sStriped.tokens(";", 6);
1202
						if ( entries <= newEntries )
1205
						if ( entries <= newEntries )
1203
							addEntry = sStriped.GetToken(";", 1, 5) + ";";
1206
							addEntry = sStriped.tokens(";", 1, 5) + ";";
1204
						break;
1207
						break;
1205
					case TAT_3:
1208
					case TAT_3:
1206
						remaining = sStriped.GetToken(";", 5, 5).ToInt() + 1;
1209
						remaining = (long)sStriped.token(";", 5) + 1;
1207
						sRemainingLeft = sStriped.GetToken(";", 6);
1210
						sRemainingLeft = sStriped.tokens(";", 6);
1208
						if ( entries <= newEntries )
1211
						if ( entries <= newEntries )
1209
							addEntry = sStriped.GetToken(";", 1, 5) + ";";
1212
							addEntry = sStriped.tokens(";", 1, 5) + ";";
1210
						break;
1213
						break;
1211
 
1214
 
1212
					default:
1215
					default:
1213
						remaining = 0;
1216
						remaining = 0;
1214
						if ( entries <= newEntries )
1217
						if ( entries <= newEntries )
1215
							addEntry = sStriped;
1218
							addEntry = sStriped;
1216
 
1219
 
1217
				}
1220
				}
1218
			}
1221
			}
1219
 
1222
 
1220
			if ( !sRemainingLeft.Empty() )
1223
			if ( !sRemainingLeft.empty() )
1221
			{
1224
			{
1222
				int tatType = CXspFile::GetAnimationType(lastType);
1225
				int tatType = CXspFile::GetAnimationType(lastType);
1223
				if ( tatType == TAT_SINGLE )
1226
				if ( tatType == TAT_SINGLE )
1224
				{
1227
				{
1225
					if ( sRemainingLeft.IsIn(";") )
1228
					if ( sRemainingLeft.isin(";") )
1226
						remaining -= sRemainingLeft.NumToken(";");
1229
						remaining -= sRemainingLeft.countToken(";");
1227
					else if ( !sRemainingLeft.Empty() )
1230
					else if ( !sRemainingLeft.empty() )
1228
						--remaining;
1231
						--remaining;
1229
 
1232
 
1230
					if ( entries <= newEntries )
1233
					if ( entries <= newEntries )
1231
						addEntry += sRemainingLeft + ";";
1234
						addEntry += sRemainingLeft + ";";
1232
				}
1235
				}
1233
				else if ( tatType == TAT_3 )
1236
				else if ( tatType == TAT_3 )
1234
				{
1237
				{
1235
					// last entry
1238
					// last entry
1236
					if ( remaining == 1 )
1239
					if ( remaining == 1 )
1237
						--remaining;
1240
						--remaining;
1238
					else if ( sRemainingLeft.IsIn(";") )
1241
					else if ( sRemainingLeft.isin(";") )
1239
					{
1242
					{
1240
						if ( !sRemainingLeft.IsIn("TATF_COORDS") )
1243
						if ( !sRemainingLeft.isin("TATF_COORDS") )
1241
						{
1244
						{
1242
							int amt = sRemainingLeft.NumToken(";") / 3;
1245
							int amt = sRemainingLeft.countToken(";") / 3;
1243
							remaining -= amt;
1246
							remaining -= amt;
1244
							if ( remaining == 1 && (sRemainingLeft.NumToken(";") - (amt * 3)) == 1 )
1247
							if ( remaining == 1 && (sRemainingLeft.countToken(";") - (amt * 3)) == 1 )
1245
								--remaining;
1248
								--remaining;
1246
						}
1249
						}
1247
						else
1250
						else
1248
						{
1251
						{
1249
							int iRem = sRemainingLeft.NumToken(";");
1252
							int iRem = sRemainingLeft.countToken(";");
1250
							int iPos = 1;
1253
							int iPos = 1;
1251
							while ( iPos < iRem )
1254
							while ( iPos < iRem )
1252
							{
1255
							{
1253
								CyString first = sRemainingLeft.GetToken(";", iPos, iPos);
1256
								Utils::String first = sRemainingLeft.token(";", iPos);
1254
								if ( first.IsIn("TATF_COORDS") )
1257
								if ( first.isin("TATF_COORDS") )
1255
									iPos += 5;
1258
									iPos += 5;
1256
								else
1259
								else
1257
									iPos += 3;
1260
									iPos += 3;
1258
								--remaining;
1261
								--remaining;
1259
							}
1262
							}
Line 1268... Line 1271...
1268
				}
1271
				}
1269
			}
1272
			}
1270
 
1273
 
1271
			if ( remaining <= 0 )
1274
			if ( remaining <= 0 )
1272
			{
1275
			{
1273
				if ( entries <= newEntries && !addEntry.Empty())
1276
				if ( entries <= newEntries && !addEntry.empty())
1274
				{
1277
				{
1275
					if ( addEntry[(int)addEntry.Length() - 1] != ';' )
1278
					if ( addEntry[(int)addEntry.length() - 1] != ';' )
1276
						addEntry += ";";
1279
						addEntry += ";";
1277
					lOut->PushBack(addEntry + lastComment);
1280
					lOut->PushBack(CyString(addEntry + lastComment));
1278
				}
1281
				}
1279
				--entries;
1282
				--entries;
1280
			}
1283
			}
1281
		}
1284
		}
1282
	}
1285
	}
Line 1285... Line 1288...
1285
}
1288
}
1286
 
1289
 
1287
void CXspFile::AddAnimation(CyStringList *list)
1290
void CXspFile::AddAnimation(CyStringList *list)
1288
{
1291
{
1289
	for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->next )
1292
	for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->next )
1290
		this->AddAnimation(strNode->str);
1293
		this->AddAnimation(strNode->str.ToString());
1291
	m_bChanged = true; 
1294
	m_bChanged = true; 
1292
}
1295
}
1293
 
1296
 
1294
SText *CXspFile::FindShipText(int lang)
1297
SText *CXspFile::FindShipText(int lang)
1295
{
1298
{
Line 1321... Line 1324...
1321
		return german;
1324
		return german;
1322
	// otherwise use any we've found (usually first one)
1325
	// otherwise use any we've found (usually first one)
1323
	return found;
1326
	return found;
1324
}
1327
}
1325
 
1328
 
1326
CyString CXspFile::GetTextName(int lang)
1329
Utils::String CXspFile::GetTextName(int lang)
1327
{
1330
{
1328
	SText *t = FindShipText(lang);
1331
	SText *t = FindShipText(lang);
1329
	if ( t )
1332
	if ( t )
1330
	{
1333
	{
1331
		// return the correct language text
1334
		// return the correct language text
1332
		if ( !t->sName.Empty() )
1335
		if ( !t->sName.empty() )
1333
			return t->sName;
1336
			return t->sName;
1334
		// we have found a text, but there is no ship name ??
1337
		// we have found a text, but there is no ship name ??
1335
		else if ( lang != 44 )
1338
		else if ( lang != 44 )
1336
		{
1339
		{
1337
			// reget the english one
1340
			// reget the english one
1338
			t = FindShipText(44);
1341
			t = FindShipText(44);
1339
			if ( t && !t->sName.Empty() )
1342
			if ( t && !t->sName.empty() )
1340
				return t->sName;
1343
				return t->sName;
1341
		}
1344
		}
1342
	}
1345
	}
1343
 
1346
 
1344
	// still not found one, return the ships name
1347
	// still not found one, return the ships name
1345
	return this->GetShipName(lang);
1348
	return this->GetShipName(lang);
1346
}
1349
}
1347
 
1350
 
1348
CyString CXspFile::GetTextDescription(int lang)
1351
Utils::String CXspFile::GetTextDescription(int lang)
1349
{
1352
{
1350
	SText *t = FindShipText(lang);
1353
	SText *t = FindShipText(lang);
1351
	if ( t )
1354
	if ( t )
1352
	{
1355
	{
1353
		// return the correct language text
1356
		// return the correct language text
1354
		if ( !t->sDesc.Empty() )
1357
		if ( !t->sDesc.empty() )
1355
			return t->sDesc;
1358
			return t->sDesc;
1356
		// we have found a text, but there is no ship name ??
1359
		// we have found a text, but there is no ship name ??
1357
		else if ( lang != 44 )
1360
		else if ( lang != 44 )
1358
		{
1361
		{
1359
			// reget the english one
1362
			// reget the english one
1360
			t = FindShipText(44);
1363
			t = FindShipText(44);
1361
			if ( t && !t->sDesc.Empty() )
1364
			if ( t && !t->sDesc.empty() )
1362
				return t->sDesc;
1365
				return t->sDesc;
1363
		}
1366
		}
1364
	}
1367
	}
1365
 
1368
 
1366
	// still not found one, return the ships name
1369
	// still not found one, return the ships name
1367
	if ( !m_sDescription.Empty() )
1370
	if ( !m_sDescription.Empty() )
1368
		return m_sDescription;
1371
		return m_sDescription.ToString();
1369
	return this->GetShipName(lang);
1372
	return this->GetShipName(lang);
1370
}
1373
}
1371
 
1374
 
1372
bool CXspFile::startExtractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *pProgress)
1375
bool CXspFile::startExtractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *pProgress)
1373
{
1376
{
1374
	m_sID = sId.removeChar('\r');
1377
	m_sID = sId.remove('\r');
1375
	while ( m_sID.right(1) == ";" )
1378
	while ( m_sID.right(1) == ";" )
1376
		m_sID.truncate(-1);
1379
		m_sID.truncate(-1);
1377
 
1380
 
1378
	m_sData = pVfs->getTShipsEntry(m_sID);
1381
	m_sData = pVfs->getTShipsEntry(m_sID);
1379
 
1382
 
Line 1504... Line 1507...
1504
	bool extracted = false;
1507
	bool extracted = false;
1505
	if ( pVfs->ExtractGameFile("types/dummies.pck", "tmp") ) {
1508
	if ( pVfs->ExtractGameFile("types/dummies.pck", "tmp") ) {
1506
		CFileIO File("tmp");
1509
		CFileIO File("tmp");
1507
		if ( File.Exists() )
1510
		if ( File.Exists() )
1508
		{
1511
		{
1509
			CyString section;
1512
			Utils::String section;
1510
			int secCount = 0;
1513
			int secCount = 0;
1511
			CyStringList *lines = File.ReadLinesStr();
1514
			CyStringList *lines = File.ReadLinesStr();
1512
			for ( SStringList *node = lines->Head(); node; node = node->next )
1515
			for ( SStringList *node = lines->Head(); node; node = node->next )
1513
			{
1516
			{
1514
				node->str.RemoveFirstSpace();
1517
				node->str.RemoveFirstSpace();
Line 1520... Line 1523...
1520
					continue;
1523
					continue;
1521
 
1524
 
1522
				// not in a section yet
1525
				// not in a section yet
1523
				if ( secCount <= 0 )
1526
				if ( secCount <= 0 )
1524
				{
1527
				{
1525
					section = node->str.GetToken(";", 1, 1);
1528
					section = node->str.GetToken(";", 1, 1).ToString();
1526
					secCount = node->str.GetToken(";", 2, 2).ToInt();
1529
					secCount = node->str.GetToken(";", 2, 2).ToInt();
1527
				}
1530
				}
1528
				else
1531
				else
1529
				{
1532
				{
1530
					CyString first = node->str.GetToken(";", 1, 1);
1533
					Utils::String first = node->str.GetToken(";", 1, 1).ToString();
1531
					if ( sceneModels->FindString(first) )
1534
					if ( sceneModels->FindString(first) )
1532
					{
1535
					{
1533
						this->AddDummy(section, node->str);
1536
						this->AddDummy(section, node->str.ToString());
1534
 
1537
 
1535
						if ( add )
1538
						if ( add )
1536
						{
1539
						{
1537
							int pos = 4;
1540
							int pos = 4;
1538
							int scene = node->str.GetToken(";", 3, 3).ToInt();
1541
							int scene = node->str.GetToken(";", 3, 3).ToInt();
Line 1543... Line 1546...
1543
							}
1546
							}
1544
 
1547
 
1545
							int model = node->str.GetToken(";", pos, pos).ToInt();
1548
							int model = node->str.GetToken(";", pos, pos).ToInt();
1546
							for ( int i = 0; i < model; i++ )
1549
							for ( int i = 0; i < model; i++ )
1547
								sceneModels->PushBack(node->str.GetToken(";", pos + (i * 2) + 1, pos + (i * 2) + 1));
1550
								sceneModels->PushBack(node->str.GetToken(";", pos + (i * 2) + 1, pos + (i * 2) + 1));
1548
						}
1551
						}
1549
					}
1552
					}
1550
					--secCount;
1553
					--secCount;
1551
 
1554
 
1552
				}
1555
				}
1553
			}
1556
			}
1554
 
1557
 
1555
			delete lines;
1558
			delete lines;
1556
			File.Remove();
1559
			File.Remove();
1557
		}
1560
		}
1558
	}
1561
	}
1559
}
1562
}
1560
 
1563
 
1561
void CXspFile::extractComponants(CVirtualFileSystem *pVfs, CyStringList *sceneModels)
1564
void CXspFile::extractComponants(CVirtualFileSystem *pVfs, CyStringList *sceneModels)
1562
{
1565
{
1563
	if ( !sceneModels ) return;
1566
	if ( !sceneModels ) return;
1564
	if ( pVfs->ExtractGameFile("types/components.pck", "tmp") )
1567
	if ( pVfs->ExtractGameFile("types/components.pck", "tmp") )
1565
	{
1568
	{
1566
		CFileIO File("tmp");
1569
		CFileIO File("tmp");
1567
		if ( File.Exists() )
1570
		if ( File.Exists() )
1568
		{
1571
		{
1569
			CyString file;
1572
			Utils::String file;
1570
			CyString section;
1573
			Utils::String section;
1571
			int secCount = 0;
1574
			int secCount = 0;
1572
			int secCount2 = 0;
1575
			int secCount2 = 0;
1573
			CyStringList *lines = File.ReadLinesStr();
1576
			CyStringList *lines = File.ReadLinesStr();
1574
			for ( SStringList *node = lines->Head(); node; node = node->next )
1577
			for ( SStringList *node = lines->Head(); node; node = node->next )
1575
			{
1578
			{
1576
				node->str.RemoveFirstSpace();
1579
				node->str.RemoveFirstSpace();
1577
				node->str.RemoveChar(9);
1580
				node->str.RemoveChar(9);
1578
				node->str.RemoveChar('\r');
1581
				node->str.RemoveChar('\r');
1579
				if ( node->str.Empty() )
1582
				if ( node->str.Empty() )
1580
					continue;
1583
					continue;
1581
				if ( node->str[0] == '/' )
1584
				if ( node->str[0] == '/' )
1582
					continue;
1585
					continue;
1583
 
1586
 
1584
				// not in a section yet
1587
				// not in a section yet
1585
				if ( secCount2 )
1588
				if ( secCount2 )
1586
				{
1589
				{
1587
					if ( sceneModels->FindString(file) )
1590
					if ( sceneModels->FindString(file) )
1588
						this->AddComponent(section, file, node->str);
1591
						this->AddComponent(section, file, node->str.ToString());
1589
					--secCount2;
1592
					--secCount2;
1590
				}
1593
				}
1591
				else if ( secCount <= 0 )
1594
				else if ( secCount <= 0 )
1592
				{
1595
				{
1593
					section = node->str.GetToken(";", 1, 1);
1596
					section = node->str.GetToken(";", 1, 1).ToString();
1594
					secCount = node->str.GetToken(";", 2, 2).ToInt();
1597
					secCount = node->str.GetToken(";", 2, 2).ToInt();
1595
				}
1598
				}
1596
				else
1599
				else
1597
				{
1600
				{
1598
					file = node->str.GetToken(";", 1, 1);
1601
					file = node->str.GetToken(";", 1, 1).ToString();
1599
					secCount2 = node->str.GetToken(";", 2, 2).ToInt();
1602
					secCount2 = node->str.GetToken(";", 2, 2).ToInt();
1600
					--secCount;
1603
					--secCount;
1601
				}
1604
				}
1602
			}
1605
			}
1603
 
1606
 
1604
			delete lines;
1607
			delete lines;
1605
			File.Remove();
1608
			File.Remove();
1606
		}
1609
		}
Line 1652... Line 1655...
1652
					CLEANSPLIT(strs, max)
1655
					CLEANSPLIT(strs, max)
1653
				}
1656
				}
1654
			}
1657
			}
1655
 
1658
 
1656
			startLine = pos + 1;
1659
			startLine = pos + 1;
1657
		}
1660
		}
1658
	}
1661
	}
1659
	
1662
	
1660
	delete [] data;
1663
	delete [] data;
1661
 
1664
 
1662
	return true;
1665
	return true;
Line 1706... Line 1709...
1706
		else 
1709
		else 
1707
			pVfs->extractGameFileToPackage(this, "textures\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER);
1710
			pVfs->extractGameFileToPackage(this, "textures\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER);
1708
	}
1711
	}
1709
}
1712
}
1710
 
1713
 
1711
bool CXspFile::AddTextFromFile(CyString file, int textId)
1714
bool CXspFile::AddTextFromFile(const Utils::String &sFile, int textId)
1712
{
1715
{
-
 
1716
	Utils::String file = sFile;
-
 
1717
 
1713
	bool remove = false;
1718
	bool remove = false;
1714
	if ( CFileIO(file).CheckFileExtension("pck") )
1719
	if ( CFileIO(file).CheckFileExtension("pck") )
1715
	{
1720
	{
1716
		C_File F(file);
1721
		C_File F;
-
 
1722
		F.SetFilename(CyString(file));
1717
		F.UnPCKFile();
1723
		F.UnPCKFile();
1718
		if ( F.WriteToFile("tmp") )
1724
		if ( F.WriteToFile("tmp") )
1719
		{
1725
		{
1720
			remove = true;
1726
			remove = true;
1721
			file = "tmp";
1727
			file = "tmp";
Line 1735... Line 1741...
1735
	}
1741
	}
1736
 
1742
 
1737
	return false;
1743
	return false;
1738
}
1744
}
1739
 
1745
 
1740
bool CXspFile::ImportBodies(CyStringList *sceneModels, CyString filename)
1746
bool CXspFile::ImportBodies(CyStringList *sceneModels, const Utils::String &filename)
1741
{
1747
{
1742
	CFileIO File(filename);
1748
	CFileIO File(filename);
1743
	if ( File.Exists() )
1749
	if ( File.Exists() )
1744
	{
1750
	{
1745
		CyString sSection;
1751
		Utils::String sSection;
1746
		int section = 0;
1752
		int section = 0;
1747
		CyStringList *lines = File.ReadLinesStr();
1753
		CyStringList *lines = File.ReadLinesStr();
1748
		for ( SStringList *node = lines->Head(); node; node = node->next )
1754
		for ( SStringList *node = lines->Head(); node; node = node->next )
1749
		{
1755
		{
1750
			node->str.RemoveChar(9);
1756
			node->str.RemoveChar(9);
Line 1756... Line 1762...
1756
				continue;
1762
				continue;
1757
			
1763
			
1758
			// are we looking for a section
1764
			// are we looking for a section
1759
			if ( section <= 0 )
1765
			if ( section <= 0 )
1760
			{
1766
			{
1761
				sSection = node->str.GetToken(";", 1, 1);
1767
				sSection = node->str.GetToken(";", 1, 1).ToString();
1762
				section = node->str.GetToken(";", 2, 2).ToInt();
1768
				section = node->str.GetToken(";", 2, 2).ToInt();
1763
			}
1769
			}
1764
			else
1770
			else
1765
			{
1771
			{
1766
				int max;
1772
				int max;
Line 1771... Line 1777...
1771
					{
1777
					{
1772
						strs[i].RemoveSpaces();
1778
						strs[i].RemoveSpaces();
1773
						if (strs[i].Empty() )
1779
						if (strs[i].Empty() )
1774
							continue;
1780
							continue;
1775
						if ( sceneModels->FindString(strs[i]) )
1781
						if ( sceneModels->FindString(strs[i]) )
1776
							this->AddBody(sSection, strs[i]);
1782
							this->AddBody(sSection, strs[i].ToString());
1777
						--section;
1783
						--section;
1778
					}
1784
					}
1779
				}
1785
				}
1780
				CLEANSPLIT(strs, max)
1786
				CLEANSPLIT(strs, max)
1781
			}
1787
			}
Line 1785... Line 1791...
1785
	}
1791
	}
1786
 
1792
 
1787
	return false;
1793
	return false;
1788
}
1794
}
1789
 
1795
 
1790
bool CXspFile::ImportCockpits(CyString filename)
1796
bool CXspFile::ImportCockpits(const Utils::String &filename)
1791
{
1797
{
1792
	CFileIO File(filename);
1798
	CFileIO File(filename);
1793
	if ( File.Exists() )
1799
	if ( File.Exists() )
1794
	{
1800
	{
1795
		CyStringList *lines = File.ReadLinesStr();
1801
		CyStringList *lines = File.ReadLinesStr();
Line 1815... Line 1821...
1815
		for ( int i = 0; i < 6; i++ )
1821
		for ( int i = 0; i < 6; i++ )
1816
		{
1822
		{
1817
			int idx = m_sData.token(";", 32 + (i * 2));
1823
			int idx = m_sData.token(";", 32 + (i * 2));
1818
			if ( idx < lines->Count() && idx )
1824
			if ( idx < lines->Count() && idx )
1819
			{
1825
			{
1820
				CyString turret = lines->GetAt(idx)->str;
1826
				Utils::String turret = lines->GetAt(idx)->str.ToString();
1821
				int pos = -1;
1827
				int pos = -1;
1822
				Utils::String id;
1828
				Utils::String id;
1823
				while ( id.empty() && pos > -100 ) id = turret.GetToken(";", pos, pos--).ToString();
1829
				while ( id.empty() && pos > -100 ) id = turret.token(";", pos--);
1824
				m_sData = m_sData.replaceToken(";", 32 + (i * 2), id + "(" + (long)idx + ")");
1830
				m_sData = m_sData.replaceToken(";", 32 + (i * 2), id + "(" + (long)idx + ")");
1825
 
1831
 
1826
				this->AddCockpit(turret, 0);
1832
				this->AddCockpit(turret, 0);
1827
			}
1833
			}
1828
		}
1834
		}
Line 1865... Line 1871...
1865
		textId = m_sData.token(";", 7);
1871
		textId = m_sData.token(";", 7);
1866
 
1872
 
1867
	if ( textId <= 0 )
1873
	if ( textId <= 0 )
1868
		return false;
1874
		return false;
1869
 
1875
 
1870
	CyString line;
1876
	Utils::String line;
1871
	if ( !id )
1877
	if ( !id )
1872
		return false;
1878
		return false;
1873
 
1879
 
1874
	bool added = false;
1880
	bool added = false;
1875
 
1881
 
1876
	CyString shipName;
1882
	Utils::String shipName;
1877
	CyString shipDesc;
1883
	Utils::String shipDesc;
1878
 
1884
 
1879
	int lang = 0;
1885
	int lang = 0;
1880
	bool inpage = false;
1886
	bool inpage = false;
1881
	while ( !feof(id) )
1887
	while ( !feof(id) )
1882
	{
1888
	{
1883
		if ( !shipName.Empty() && !shipDesc.Empty() )
1889
		if ( !shipName.empty() && !shipDesc.empty() )
1884
		{
1890
		{
1885
			added = true;
1891
			added = true;
1886
			break;
1892
			break;
1887
		}
1893
		}
1888
 
1894
 
1889
		line.GetEndOfLine(id, 0, false);
1895
		line.readToEndOfLine(id, 0, false);
1890
		line.RemoveChar(9);
1896
		line.removeChar(9);
1891
		line.RemoveChar('\r');
1897
		line.removeChar('\r');
1892
		line.RemoveFirstSpace();
1898
		line.removeFirstSpace();
1893
 
1899
 
1894
		if ( inpage )
1900
		if ( inpage )
1895
		{
1901
		{
1896
			if ( line.Left(6).Compare("</page") )
1902
			if ( line.left(6).Compare("</page") )
1897
				break;
1903
				break;
1898
 
1904
 
1899
			// find matching id
1905
			// find matching id
1900
			if ( line.Left(6).Compare("<t id=") )
1906
			if ( line.left(6).Compare("<t id=") )
1901
			{
1907
			{
1902
				int pos = line.FindPos("id=\"");
1908
				int pos = line.findPos("id=\"", 0);
1903
				if ( pos != -1 )
1909
				if ( pos != -1 )
1904
				{
1910
				{
1905
					int endpos = line.FindPos("\"", pos + 5);
1911
					int endpos = line.findPos("\"", pos + 5);
1906
					if ( endpos != -1 )
1912
					if ( endpos != -1 )
1907
					{
1913
					{
1908
						int id = line.Mid(pos + 5, endpos).ToInt();
1914
						int id = line.mid(pos + 5, endpos);
1909
						if ( id == textId || id == (textId + 1) )
1915
						if ( id == textId || id == (textId + 1) )
1910
						{
1916
						{
1911
							pos = line.FindPos(">", endpos);
1917
							pos = line.findPos(">", endpos);
1912
							if ( pos != -1 )
1918
							if ( pos != -1 )
1913
							{
1919
							{
1914
								endpos = line.FindPos("</t>", pos);
1920
								endpos = line.findPos("</t>", pos);
1915
								if ( endpos != -1 )
1921
								if ( endpos != -1 )
1916
								{
1922
								{
1917
									if ( id == textId )
1923
									if ( id == textId )
1918
										shipName = line.Mid(pos + 2, endpos - (pos + 1));
1924
										shipName = line.mid(pos + 2, endpos - (pos + 1));
1919
									else
1925
									else
1920
										shipDesc = line.Mid(pos + 2, endpos - (pos + 1));
1926
										shipDesc = line.mid(pos + 2, endpos - (pos + 1));
1921
								}
1927
								}
1922
							}
1928
							}
1923
						}
1929
						}
1924
					}
1930
					}
1925
				}
1931
				}
1926
			}
1932
			}
1927
		}
1933
		}
1928
		else if ( lang ) // search for page 17
1934
		else if ( lang ) // search for page 17
1929
		{
1935
		{
1930
			if ( line.Left(8).Compare("<page id") )
1936
			if ( line.left(8).Compare("<page id") )
1931
			{
1937
			{
1932
				int pos = line.FindPos("id=\"");
1938
				int pos = line.findPos("id=\"");
1933
				if ( pos != -1 )
1939
				if ( pos != -1 )
1934
				{
1940
				{
1935
					int endpos = line.FindPos("\"", pos + 5);
1941
					int endpos = line.findPos("\"", pos + 5);
1936
					if ( endpos != -1 )
1942
					if ( endpos != -1 )
1937
					{
1943
					{
1938
						CyString sId = line.Mid(pos + 5, endpos - (pos + 4));
1944
						Utils::String sId = line.mid(pos + 5, endpos - (pos + 4));
1939
						int id = sId.ToInt();
1945
						int id = sId;
1940
						if ( id == 17 || sId.Right(4).ToInt() == 17 )
1946
						if ( id == 17 || ((int)sId.right(4)) == 17 )
1941
							inpage = true;
1947
							inpage = true;
1942
					}
1948
					}
1943
				}
1949
				}
1944
			}
1950
			}
1945
		}
1951
		}
1946
		else if ( line.Left(12).Compare("<language id") )
1952
		else if ( line.left(12).Compare("<language id") )
1947
		{
1953
		{
1948
			int pos = line.FindPos("id=\"");
1954
			int pos = line.findPos("id=\"");
1949
			if ( pos != -1 )
1955
			if ( pos != -1 )
1950
			{
1956
			{
1951
				int endpos = line.FindPos("\"", pos + 5);
1957
				int endpos = line.findPos("\"", pos + 5);
1952
				if ( endpos != -1 )
1958
				if ( endpos != -1 )
1953
					lang = line.Mid(pos + 5, endpos - (pos + 4)).ToInt();
1959
					lang = line.mid(pos + 5, endpos - (pos + 4));
1954
			}
1960
			}
1955
		}
1961
		}
1956
	}
1962
	}
1957
 
1963
 
1958
	// incase we only found the shipname
1964
	// incase we only found the shipname
1959
	if ( !shipName.Empty() )
1965
	if ( !shipName.empty() )
1960
		added = true;
1966
		added = true;
1961
 
1967
 
1962
	if ( added )
1968
	if ( added )
1963
	{
1969
	{
1964
		if ( lang == 44 || m_sName.Empty())
1970
		if ( lang == 44 || m_sName.Empty())
Line 2117... Line 2123...
2117
	{
2123
	{
2118
		SCockpit *c = node->Data();
2124
		SCockpit *c = node->Data();
2119
		if ( c->iIndex < 0 )
2125
		if ( c->iIndex < 0 )
2120
			continue;
2126
			continue;
2121
 
2127
 
2122
		CyString id = c->sCockpit.GetToken(";", 19, 19);
2128
		Utils::String id = c->sCockpit.token(";", 19);
2123
 
2129
 
2124
		for ( int i = 0; i < 6; i++ )
2130
		for ( int i = 0; i < 6; i++ )
2125
		{
2131
		{
2126
			CyString tId = m_sData.token(";", 32 + (i * 2));
2132
			Utils::String tId = m_sData.token(";", 32 + (i * 2));
2127
			if ( tId.IsNumber() && tId.ToInt() == c->iIndex )
2133
			if ( tId.isNumber() && ((int)tId) == c->iIndex )
2128
				m_sData = m_sData.replaceToken(";", 32 + (i * 2), (id + "(" + CyString::Number(c->iIndex) + ")").c_str());
2134
				m_sData = m_sData.replaceToken(";", 32 + (i * 2), (id + "(" + Utils::String::number(c->iIndex) + ")").c_str());
2129
		}
2135
		}
2130
	}
2136
	}
2131
}
2137
}
2132
 
2138
 
2133
CyString CXspFile::FormatShipData(CyStringList *cockpits, int *text, int game)
2139
Utils::String CXspFile::FormatShipData(CyStringList *cockpits, int *text, int game)
2134
{
2140
{
2135
	CyString data = (game == GAME_X3) ? this->GetX3ShipData() : this->GetTCShipData();
2141
	Utils::String data = (game == GAME_X3) ? this->GetX3ShipData() : this->GetTCShipData();
2136
	// do turrets
2142
	// do turrets
2137
	for ( int t = 0; t < 6; t++ )
2143
	for ( int t = 0; t < 6; t++ )
2138
	{
2144
	{
2139
		int oldPos = 0;
2145
		int oldPos = 0;
2140
		CyString turret = data.GetToken(";", 32 + (t * 2), 32 + (t * 2));
2146
		Utils::String turret = data.token(";", 32 + (t * 2));
2141
		if ( !turret.IsNumber() )
2147
		if ( !turret.isNumber() )
2142
		{
2148
		{
2143
			if ( turret.IsIn("(") )
2149
			if ( turret.isin("(") )
2144
			{
2150
			{
2145
				oldPos = turret.GetToken("(", 2).GetToken(")", 1, 1).ToInt();
2151
				oldPos = turret.tokens("(", 2).token(")", 1);
2146
				turret = turret.GetToken("(", 1, 1);
2152
				turret = turret.token("(", 1);
2147
			}
2153
			}
2148
			int pos = cockpits->FindStringPos(turret);
2154
			int pos = cockpits->FindStringPos(turret);
2149
			if ( pos < 0 )	pos = oldPos;
2155
			if ( pos < 0 )	pos = oldPos;
-
 
2156
			if ( pos >= cockpits->Count() ) pos = 0;
2150
			data = data.RepToken(";", 32 + (t * 2), CyString::Number(pos));
2157
			data = data.replaceToken(";", 32 + (t * 2), (long)pos);
2151
		}
2158
		}
2152
	}
2159
	}
2153
	// adjust the weapons
2160
	// adjust the weapons
2154
	int mask = this->GetLaserMask(game - 1);
2161
	int mask = this->GetLaserMask(game - 1);
2155
	if ( mask != -1 )
2162
	if ( mask != -1 )
2156
		data = data.RepToken(";", 19, CyString::Number(mask));
2163
		data = data.replaceToken(";", 19, (long)mask);
2157
	mask = this->GetMissileMask(game - 1);
2164
	mask = this->GetMissileMask(game - 1);
2158
	if ( mask != -1 )
2165
	if ( mask != -1 )
2159
		data = data.RepToken(";", 25, CyString::Number(mask));
2166
		data = data.replaceToken(";", 25, (long)mask);
2160
 
2167
 
2161
	// fix the ship text
2168
	// fix the ship text
2162
	if ( m_iOrgDesc > 0 )
2169
	if ( m_iOrgDesc > 0 )
2163
		(*text) = m_iOrgDesc;
2170
		(*text) = m_iOrgDesc;
2164
	data = data.RepToken(";", 7, CyString::Number(*text));
2171
	data = data.replaceToken(";", 7, (long)*text);
2165
 
2172
 
2166
	// add the ware id
2173
	// add the ware id
2167
	data.RemoveChar(9);
2174
	data.removeChar(9);
2168
	data.RemoveEndSpace();
2175
	data.removeEndSpace();
2169
	// remove the end ;
2176
	// remove the end ;
2170
	while ( data.Right(1) == ";" ) data.Truncate((int)data.Length() - 1);
2177
	while ( data.right(1) == ";" ) data.truncate(-1);
2171
	data = data.RepToken(";", data.NumToken(";"), this->GetShipID());
2178
	data = data.replaceToken(";", data.countToken(";"), this->GetShipID());
2172
	if ( data.Right(1) != ";" )
2179
	if ( data.right(1) != ";" )
2173
		data += ";";
2180
		data += ";";
2174
 
2181
 
2175
	return data;
2182
	return data;
2176
}
2183
}
2177
 
2184