X-Moto

Tasklist

FS#140 - new cup: sum of times on classical levels

Attached to Project: X-Moto
Opened by Anonymous Submitter - Monday, 27 August 2007, 14:37 GMT
Last edited by the_only_dude (the_only_dude) - Wednesday, 23 July 2008, 12:17 GMT
Task Type Feature Request
Category Game
Status Unconfirmed   Reopened
Assigned To No-one
Operating System All
Severity Very Low
Priority Normal
Reported Version svn
Due in Version 0.4.0
Due Date Undecided
Percent Complete 0%
Votes 1
Private No

Details

Make a cup for the sum of times on all classical levels.
Now, this is hard -- requires changes on the website and in xmoto code+ might need
lots of demo validation. :(
This task depends upon

Comment by the_only_dude (the_only_dude) - Wednesday, 29 August 2007, 14:14 GMT
what's a classical level ?
Comment by AvovA (avova) - Friday, 31 August 2007, 02:57 GMT
You did notplay xmoto for some time, the_only_dude ? ;)
There is "classical" pack of levels
Comment by AvovA (avova) - Saturday, 06 October 2007, 05:58 GMT
maybe you could at least make the statistics tab to print the sum of times...
Comment by AvovA (avova) - Saturday, 06 October 2007, 09:51 GMT
ok, i made a little patch to show it in the statistics tab, I will send it to you guys soon.
Comment by AvovA (avova) - Sunday, 07 October 2007, 01:31 GMT
first what I did is
wrote silly loops using std::ostringstream like this :
// classical levels 1-10
for(int i = 0; i <= 9; i++) {
tmp_name.str("");
tmp_name << "_iL0" << i << "_";
v_result = m_db->readDB("SELECT finishTime FROM webhighscores "
"WHERE id_level=\"" + xmDatabase::protectString(tmp_name.str()) + "\" "
"ORDER BY finishTime LIMIT 1;", nrow);
if (m_db->getResult(v_result, 1, 0, 0) != NULL )
// need to get rid of extra decimal places
v_WR_sum_on_classical += 0.01 * floorf(100*atof(m_db->getResult(v_result, 1, 0, 0)));
else
v_WR_sum_on_classical += 300.0;
}

Using this kind of code I can print sums of classical WR and personal best times in the statistics tab...
but this loop is ugly and it only works for the classical pack.
So I did the second version: I modified GameApp::_CreateLevelPackLevelList to print one extra fake level called "total".
The main loop in this function looks like this in my code :

float player_total = 0.0;
int player_total_defined = 1;
float WR_total = 0.0;
int WR_total_defined = 1;
for(unsigned int i=0; i<nrow; i++) {
if(m_db->getResult(v_result, 4, i, 2) == NULL) {
v_playerHighscore = -1.0;
player_total_defined = 1;
} else {
v_playerHighscore = atof(m_db->getResult(v_result, 4, i, 2));
player_total += 0.01 * floorf(100* atof(m_db->getResult(v_result, 4, i, 2)));
}

if(m_db->getResult(v_result, 4, i, 3) == NULL) {
v_roomHighscore = -1.0;
WR_total_defined = 0;
} else {
v_roomHighscore = atof(m_db->getResult(v_result, 4, i, 3));
WR_total += 0.01 * floorf(100* atof(m_db->getResult(v_result, 4, i, 3)));
}
=================================================
and right after the loop I put

if (WR_total_defined && player_total_defined)
pList->addLevel("","Total", player_total, WR_total);
else if (WR_total_defined)
pList->addLevel("","Total", 0, WR_total);
m_db->read_DB_free(v_result);



PS my code is super ulgy, just a dirty hack really. Plz dont close this feature request
Comment by AvovA (avova) - Sunday, 07 October 2007, 01:41 GMT
should be
if(m_db->getResult(v_result, 4, i, 2) == NULL) {
v_playerHighscore = -1.0;
player_total_defined = 0;

of course.

Comment by Nicolas Adenis-Lamarre (aspegic500) - Sunday, 07 October 2007, 10:49 GMT
avova, can you just tell me what you want to do exactly (mainly what do you want to change in the xmoto code)
because the code is completly ugly.
Comment by AvovA (avova) - Sunday, 07 October 2007, 18:51 GMT
of course its ugly, I am not a programmer at all, I dont even know C++ :)
I just hacked it to show sum of times for all levels in a pack, thats it.
   screen.png (252.6 KiB)

Loading...