Subversion Repositories spk

Rev

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

Rev 1 Rev 242
Line 10... Line 10...
10
 
10
 
11
//////////////////////////////////////////////////////////////////////
11
//////////////////////////////////////////////////////////////////////
12
// Construction/Destruction
12
// Construction/Destruction
13
//////////////////////////////////////////////////////////////////////
13
//////////////////////////////////////////////////////////////////////
14
 
14
 
-
 
15
 
15
CX3Data::CX3Data(CyString &progDir)
16
CX3Data::CX3Data(const Utils::WString &progDir)
16
{
17
{
17
	m_sProgDir = progDir;
18
	m_sProgDir = progDir;
18
	m_iLastUpdate = 0;
19
	m_iLastUpdate = 0;
19
	m_bLocked = false;
20
	m_bLocked = false;
20
 
21
 
Line 26... Line 27...
26
 
27
 
27
}
28
}
28
 
29
 
29
void CX3Data::Reset ()
30
void CX3Data::Reset ()
30
{
31
{
31
	m_sPilot = "No Pilot Found";
32
	m_sPilot = L"No Pilot Found";
32
	m_sGametime = "0";
33
	m_sGametime = L"0";
33
 
34
 
34
	m_iShips = m_iAccount = m_iStations = m_iInsurance = 0;
35
	m_iShips = m_iAccount = m_iStations = m_iInsurance = 0;
35
	m_iHull = m_iShields = m_iLaser = m_iMaxLaser = m_iLaserProgress = 0;
36
	m_iHull = m_iShields = m_iLaser = m_iMaxLaser = m_iLaserProgress = 0;
36
	m_iMissiles = m_iEnemies = m_iEnemies2 = 0;
37
	m_iMissiles = m_iEnemies = m_iEnemies2 = 0;
37
 
38
 
38
	m_sAccount = "0";
39
	m_sAccount = L"0";
39
	m_iVersion = 1;
40
	m_iVersion = 1;
40
 
41
 
41
	m_shipData.Reset();
42
	m_shipData.Reset();
42
	m_targetData.Reset();
43
	m_targetData.Reset();
43
 
44
 
44
	m_lCustomList.Clear();
45
	_lCustomList.clear();
45
 
46
 
46
	m_bLoaded = false;
47
	m_bLoaded = false;
47
 
48
 
48
	int i;
49
	int i;
49
	for ( i = 0; i < MAXSHIPCLASS; i++ )
50
	for ( i = 0; i < MAXSHIPCLASS; i++ )
50
		m_iShipClass[i] = 0;
51
		m_iShipClass[i] = 0;
51
	for ( i = 0; i < MAXRACEREP; i++ )
52
	for ( i = 0; i < MAXRACEREP; i++ )
52
		m_Rep[i].Reset();
53
		m_Rep[i].Reset();
53
}
54
}
54
 
55
 
55
bool CX3Data::ReadFile ( CyString logfile, CyString lognumber )
56
bool CX3Data::readFile(const Utils::WString &sLogfile, const Utils::WString &sLogNumber)
56
{
57
{
-
 
58
	Utils::WString logfile = sLogfile;
-
 
59
	Utils::WString lognumber = sLogNumber;
-
 
60
	lognumber.padNumber(5);
57
	if ( !logfile.Empty() )
61
	if ( !logfile.empty() )
58
		logfile += "/";
62
		logfile += L"/";
59
	logfile += "log";
63
	logfile += L"log";
60
	logfile += lognumber.PadNumber(5);
64
	logfile += lognumber;
61
	logfile += ".txt";
65
	logfile += L".txt";
62
 
66
 
63
	logfile = logfile.FindReplace("//", "/");
67
	logfile = logfile.findReplace(L"//", L"/");
64
	logfile = logfile.FindReplace("/", "\\");
68
	logfile = logfile.findReplace(L"/", L"\\");
65
 
69
 
66
	FILE *id = fopen ( logfile.c_str(), ";r" );
70
	FILE *id = _wfopen(logfile.c_str(), L";r");
67
	if ( !id )
71
	if ( !id )
68
		return false;
72
		return false;
69
 
73
 
70
	bool ret = false;
74
	bool ret = false;
71
 
75
 
72
	m_lCustomList.Clear();
76
	_lCustomList.clear();
73
 
77
 
74
	bool noUpdate = false;
78
	bool noUpdate = false;
75
	bool resetCustom = false;
79
	bool resetCustom = false;
76
 
80
 
77
	CyStringList custom;
81
	Utils::WStringList custom;
78
 
82
 
79
	while ( !feof(id) )
83
	while ( !feof(id) )
80
	{
84
	{
81
		CyString line;
85
		Utils::WString line;
82
		line = line.GetEndOfLine ( id, NULL, false );
86
		line = GetEndOfLine ( id, NULL, false );
83
		CyString arg = line.GetToken ( ";:", 1, 1 );
87
		Utils::WString arg = line.token(L";:", 1 );
84
		CyString rest = line.GetToken ( ":", 2 );
88
		Utils::WString rest = line.tokens(L":", 2);
85
		rest.RemoveFirstSpace();
89
		rest.removeFirstSpace();
86
		if ( arg.Compare("PILOT") )
90
		if ( arg.Compare(L"PILOT") )
87
		{
91
		{
88
			m_bLoaded = true;
92
			m_bLoaded = true;
89
			m_sPilot = rest;
93
			m_sPilot = rest;
90
			m_iMissiles = 0;
94
			m_iMissiles = 0;
91
			m_iEnemies = 0;
95
			m_iEnemies = 0;
92
		}
96
		}
93
		else if ( arg.Compare("Version") )
97
		else if ( arg.Compare(L"Version") )
94
			m_iVersion = rest.ToInt();
98
			m_iVersion = rest.toInt();
95
		else if ( arg.Compare("SHIPS") )
99
		else if ( arg.Compare(L"SHIPS") )
96
			m_iShips = rest.ToInt();
100
			m_iShips = rest.toInt();
97
		else if ( arg.Compare("STATIONS") )
101
		else if ( arg.Compare(L"STATIONS") )
98
			m_iStations = rest.ToInt();
102
			m_iStations = rest.toInt();
99
		else if ( arg.Compare("ACCOUNT") )
103
		else if ( arg.Compare(L"ACCOUNT") )
100
		{
104
		{
101
			m_sAccount = rest;
105
			m_sAccount = rest;
102
			m_iAccount = m_sAccount.Remove(",;'").ToInt();
106
			m_iAccount = m_sAccount.removeChar(L",;'").toInt();
103
		}
107
		}
104
		else if ( arg.Compare("TIME") )
108
		else if ( arg.Compare(L"TIME") )
105
		{
109
		{
106
			int time = rest.ToInt();
110
			int time = rest.toInt();
107
			if ( m_iLastUpdate != time )
111
			if ( m_iLastUpdate != time )
108
			{
112
			{
109
				ret = true;
113
				ret = true;
110
				m_iLastUpdate = time;
114
				m_iLastUpdate = time;
111
				resetCustom = true;
115
				resetCustom = true;
112
			}
116
			}
113
			else
117
			else
114
				noUpdate = true;
118
				noUpdate = true;
115
			m_sGametime.ConvertTime(rest.ToLong(), true);
119
			m_sGametime.convertTime(rest.toLong(), true);
116
		}
120
		}
117
		else if ( arg.Compare("ARGON") )
121
		else if ( arg.Compare(L"ARGON") )
118
			SetRaceRep(REP_ARGON, arg, rest, true);
122
			setRaceRep(REP_ARGON, arg, rest, true);
119
		else if ( arg.Compare("BORON") )
123
		else if ( arg.Compare(L"BORON") )
120
			SetRaceRep(REP_BORON, arg, rest, true);
124
			setRaceRep(REP_BORON, arg, rest, true);
121
		else if ( arg.Compare("SPLIT") )
125
		else if ( arg.Compare(L"SPLIT") )
122
			SetRaceRep(REP_SPLIT, arg, rest, true);
126
			setRaceRep(REP_SPLIT, arg, rest, true);
123
		else if ( arg.Compare("PARANID") )
127
		else if ( arg.Compare(L"PARANID") )
124
			SetRaceRep(REP_PARANID, arg, rest, true);
128
			setRaceRep(REP_PARANID, arg, rest, true);
125
		else if ( arg.Compare("TELADI") )
129
		else if ( arg.Compare(L"TELADI") )
126
			SetRaceRep(REP_TELADI, arg, rest, true);
130
			setRaceRep(REP_TELADI, arg, rest, true);
127
		else if ( arg.Compare("GONER") )
131
		else if ( arg.Compare(L"GONER") )
128
			SetRaceRep(REP_GONER, arg, rest, true);
132
			setRaceRep(REP_GONER, arg, rest, true);
129
		else if ( arg.Compare("TERRAN") )
133
		else if ( arg.Compare(L"TERRAN") )
130
			SetRaceRep(REP_TERRAN, arg, rest, true);
134
			setRaceRep(REP_TERRAN, arg, rest, true);
131
		else if ( arg.Compare("ATF") )
135
		else if ( arg.Compare(L"ATF") )
132
			SetRaceRep(REP_ATF, arg, rest, true);
136
			setRaceRep(REP_ATF, arg, rest, true);
133
		else if ( arg.Compare("RACEREP") ) // new race rep
137
		else if ( arg.Compare(L"RACEREP") ) // new race rep
134
			SetRaceRep(rest.GetToken(":", 1, 1).ToInt() + 2, rest.GetToken(":", 2, 2), rest.GetToken(":", 3));
138
			setRaceRep(rest.token(L":", 1).toInt() + 2, rest.token(L":", 2), rest.tokens(L":", 3));
135
		else if ( arg.Compare("COMBAT") )
139
		else if ( arg.Compare(L"COMBAT") )
136
			SetRaceRep(REP_FIGHT, "Combat", rest);
140
			setRaceRep(REP_FIGHT, L"Combat", rest);
137
		else if ( arg.Compare("TRADE") )
141
		else if ( arg.Compare(L"TRADE") )
138
			SetRaceRep(REP_TRADE, "Trade", rest);
142
			setRaceRep(REP_TRADE, L"Trade", rest);
139
		else if ( arg.Compare("SHIPCLASS") )
143
		else if ( arg.Compare(L"SHIPCLASS") )
140
		{
144
		{
141
			int max = 12;
145
			std::vector<Utils::WString> str;
142
			CyString *str = rest.SplitToken ( &apos;:&apos;, &max );
146
			size_t max = rest.tokenise(L";:&quot;, str);
143
			if ( max > 12 ) max = 12;
147
			if ( max > 12 ) max = 12;
144
			for ( int i = 0; i < max; i++ )
148
			for ( int i = 0; i < max; i++ )
145
				m_iShipClass[i] = str[i].ToInt();
149
				m_iShipClass[i] = str[i].toInt();
146
		}
150
		}
147
		else if ( arg.Compare("SHIPNAME") )
151
		else if ( arg.Compare(L"SHIPNAME") )
148
		{
152
		{
149
			m_shipData.sName = rest.GetToken(":", 1, 1);
153
			m_shipData.sName = rest.token(L":", 1);
150
			m_shipData.sClass = rest.GetToken(":", 2, 2);
154
			m_shipData.sClass = rest.token(L":", 2);
151
			m_shipData.sID = rest.GetToken(":", 3, 3);
155
			m_shipData.sID = rest.token(L":", 3);
152
			m_shipData.iSpeed = rest.GetToken(":", 4, 4).ToInt();
156
			m_shipData.iSpeed = rest.token(L":", 4).toInt();
153
		}
157
		}
154
		else if ( arg.Compare("SHIPENV") )
158
		else if ( arg.Compare(L"SHIPENV") )
155
			m_shipData.sEnv = rest;
159
			m_shipData.sEnv = rest;
156
		else if ( arg.Compare("BARS") )
160
		else if ( arg.Compare(L"BARS") )
157
		{
161
		{
158
			m_iHull = rest.GetToken ( 1, &apos;:&apos; ).ToInt();
162
			m_iHull = rest.token (L&quot;:&quot;, 1).toInt();
159
			m_iShields = rest.GetToken ( 2, &apos;:&apos; ).ToInt();
163
			m_iShields = rest.token (L&quot;:&quot;, 2).toInt();
160
			m_iLaser = rest.GetToken ( 3, &apos;:&apos; ).ToInt();
164
			m_iLaser = rest.token (L&quot;:&quot;, 3).toInt();
161
			m_iMaxLaser = rest.GetToken ( 4, &apos;:&apos; ).ToInt();
165
			m_iMaxLaser = rest.token(L&quot;:&quot;, 4).toInt();
162
			m_iLaserProgress = (int)(((float)m_iLaser / (float)m_iMaxLaser) * 100.0f);
166
			m_iLaserProgress = (int)(((float)m_iLaser / (float)m_iMaxLaser) * 100.0f);
163
		}
167
		}
164
		else if ( arg.Compare("TARGET") )
168
		else if ( arg.Compare(L"TARGET") )
165
		{
169
		{
166
			m_targetData.sName		= rest.GetToken( ":", 1, 1);
170
			m_targetData.sName		= rest.token(L":", 1);
167
			m_targetData.iHull		= rest.GetToken( ":", 2, 2).ToInt();
171
			m_targetData.iHull		= rest.token(L":", 2).toInt();
168
			m_targetData.iShields	= rest.GetToken( ":", 3, 3).ToInt();
172
			m_targetData.iShields	= rest.token(L":", 3).toInt();
169
			m_targetData.iSpeed		= rest.GetToken( ":", 4, 4).ToInt();
173
			m_targetData.iSpeed		= rest.token(L":", 4).toInt();
170
			m_targetData.sClass		= rest.GetToken( ":", 5, 5);
174
			m_targetData.sClass		= rest.token(L":", 5);
171
			m_targetData.sID		= rest.GetToken( ":", 6, 6);
175
			m_targetData.sID		= rest.token(L":", 6);
172
			m_targetData.iDist		= rest.GetToken( ":", 7, 7).ToInt();
176
			m_targetData.iDist		= rest.token(L":", 7).toInt();
173
			m_targetData.sRelation	= rest.GetToken( ":", 8, 8);
177
			m_targetData.sRelation	= rest.token(L":", 8);
174
		}
178
		}
175
		else if ( arg.Compare("MISSILES") )
179
		else if ( arg.Compare(L"MISSILES") )
176
			m_iMissiles = rest.ToInt();
180
			m_iMissiles = rest.toInt();
177
		else if ( arg.Compare("ENEMIES") )
181
		else if ( arg.Compare(L"ENEMIES") )
178
			m_iEnemies = rest.ToInt();
182
			m_iEnemies = rest.toInt();
179
		else if ( arg.Compare("COMBAT") )
183
		else if ( arg.Compare(L"COMBAT") )
180
			m_iEnemies2 = rest.GetToken ( 1, &apos;:&apos; ).ToInt();
184
			m_iEnemies2 = rest.token(L&quot;:&quot;, 1).toInt();
181
		else if ( arg.Compare("CUSTOM") )
185
		else if ( arg.Compare(L"CUSTOM") )
182
			custom.PushBack ( rest.GetToken(":", 1, 1), rest.GetToken(":", 2), true );
186
			custom.pushBackUnique(rest.token(L":", 1), rest.tokens(L":", 2));
183
		else if ( arg.Compare("CUSTOMDISPLAY") )
187
		else if ( arg.Compare(L"CUSTOMDISPLAY") )
184
		{
188
		{
185
			if ( !noUpdate )
189
			if ( !noUpdate )
186
				m_lCustomFile.PushBack ( rest.GetToken("|", 1, 1), rest.GetToken("|", 2), false );
190
				_lCustomFile.pushBack(rest.token(L"|", 1), rest.tokens(L"|", 2));
187
		}
191
		}
188
		else if ( arg.Compare("INSURANCE") )
192
		else if ( arg.Compare(L"INSURANCE") )
189
			m_iInsurance = rest.ToInt();
193
			m_iInsurance = rest.toInt();
190
 
194
 
191
	}
195
	}
192
	fclose ( id );
196
	fclose ( id );
193
 
197
 
194
	DATA_LOCKED
198
	DATA_LOCKED
195
	if ( resetCustom || custom.Count() )
199
	if ( resetCustom || custom.size())
196
		m_lCustomList.Clear();
200
		_lCustomList.clear();
197
	for ( SStringList *node = custom.Head(); node; node = node->;next )
201
	for(auto itr = custom.begin(); itr != custom.end(); itr++)
198
		m_lCustomList.PushBack(node->;str, node->data, false);
202
		_lCustomList.pushBack((*itr)->;str, (*itr)->data);
199
	DATA_UNLOCKED
203
	DATA_UNLOCKED
200
 
204
 
201
	if ( noUpdate ) return false;
205
	if ( noUpdate ) return false;
202
 
206
 
203
	return ret;
207
	return ret;
204
}
208
}
205
 
209
 
206
void CX3Data::SetRaceRep(int rep, CyString race, CyString &rest, bool old)
210
void CX3Data::setRaceRep(int rep, const Utils::WString &race, const Utils::WString &rest, bool old)
207
{
211
{
208
	m_Rep[rep].bIncludeRace = true;
212
	m_Rep[rep].bIncludeRace = true;
209
	m_Rep[rep].sRace = race;
213
	m_Rep[rep].sRace = race;
210
	if ( old )
214
	if ( old )
211
		m_Rep[rep].sRank = rest;
215
		m_Rep[rep].sRank = rest;
212
	else
216
	else
213
	{
217
	{
214
		m_Rep[rep].iRep = rest.GetToken(":", 1, 1).ToInt();
218
		m_Rep[rep].iRep = rest.token(L":", 1).toInt();
215
		m_Rep[rep].iRepPct = rest.GetToken(":", 2, 2).ToInt();
219
		m_Rep[rep].iRepPct = rest.token(L":", 2).toInt();
216
	}
220
	}
217
}
221
}
218
 
222
 
219
CyString CX3Data::GetRepPercentage ( CyString &rank )
223
Utils::WString CX3Data::_getRepPercentage (const Utils::WString &rank ) const
220
{
224
{
221
	return rank.GetToken ( 1, &apos;:&apos; );
225
	return rank.token(L&quot;:&quot;, 1);
222
 
226
 
223
	long amt = rank.GetToken ( 2, &apos;:&apos; ).ToLong();
227
	long amt = rank.token(L&quot;:&quot;, 2).toLong();
224
	long upper = 0, lower = -1000000, r = 0;
228
	long upper = 0, lower = -1000000, r = 0;
225
	long checkamt = 0;
229
	long checkamt = 0;
226
	bool breakout= false;
230
	bool breakout= false;
227
	while (1)
231
	while (1)
228
	{
232
	{
Line 287... Line 291...
287
	float a = (float)upper - lower;
291
	float a = (float)upper - lower;
288
	float b = (float)amt - lower;
292
	float b = (float)amt - lower;
289
 
293
 
290
	float p = ((b / a) * 100);
294
	float p = ((b / a) * 100);
291
	int iP = (int)p;
295
	int iP = (int)p;
292
	CyString fullRank = rank.GetToken ( 1, &apos;:&apos; );
296
	Utils::WString fullRank = rank.token(L&quot;:&quot;, 1);
293
	if ( !breakout )
297
	if ( !breakout )
294
	{
298
	{
295
		fullRank += " (";
299
		fullRank += L" (";
296
		fullRank += CyString((long)iP);
300
		fullRank += (long)iP;
297
		fullRank += "%)";
301
		fullRank += L"%)";
298
	}
302
	}
299
	return fullRank;
303
	return fullRank;
300
}
304
}
301
 
305
 
302
CyString CX3Data::GetRankPercentage ( CyString &rank )
306
Utils::WString CX3Data::_getRankPercentage(const Utils::WString &rank) const
303
{
307
{
304
	long amt = rank.GetToken ( 2, &apos;:&apos; ).ToLong();
308
	long amt = rank.token(L&quot;:&quot;, 2).toLong();
305
	long upper = 0, lower = 0, r = 0;
309
	long upper = 0, lower = 0, r = 0;
306
 
310
 
307
	long checkamt = 0;
311
	long checkamt = 0;
308
	while (1)
312
	while (1)
309
	{
313
	{
Line 415... Line 419...
415
	float b = (float)amt - lower;
419
	float b = (float)amt - lower;
416
 
420
 
417
	float p = ((b / a) * 100);
421
	float p = ((b / a) * 100);
418
	int iP = (int)p;
422
	int iP = (int)p;
419
 
423
 
420
	CyString fullRank = rank.GetToken ( 1, &apos;:&apos; );
424
	Utils::WString fullRank = rank.token(L&quot;:&quot;, 1);
421
	if ( checkamt >= 0 )
425
	if ( checkamt >= 0 )
422
	{
426
	{
423
		fullRank += " (";
427
		fullRank += L" (";
424
		fullRank += CyString((long)iP);
428
		fullRank += (long)iP;
425
		fullRank += "%)";
429
		fullRank += L"%)";
426
	}
430
	}
427
	return fullRank;
431
	return fullRank;
428
}
432
}