From 6f358f52d6f14f5c94207a3a95137bd63b597296 Mon Sep 17 00:00:00 2001 From: auria Date: Thu, 25 Dec 2008 03:33:57 +0000 Subject: [PATCH] fixed Gp challenges only checking last race results (hackish) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2768 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/challenges/challenge_data.cpp | 52 ++++++++++++++++++++++++++++++- src/gui/grand_prix_ending.cpp | 4 +-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/challenges/challenge_data.cpp b/src/challenges/challenge_data.cpp index d6b63445f..f6116ba73 100755 --- a/src/challenges/challenge_data.cpp +++ b/src/challenges/challenge_data.cpp @@ -249,6 +249,7 @@ bool ChallengeData::raceFinished() // ---------------------------------------------------------------------------- bool ChallengeData::grandPrixFinished() { + printf("checking if GP challenge is solved"); if (race_manager->getMajorMode() != RaceManager::MAJOR_MODE_GRAND_PRIX || race_manager->getMinorMode() != m_minor || race_manager->getGrandPrix()->getId() != m_gp_id || @@ -256,7 +257,56 @@ bool ChallengeData::grandPrixFinished() race_manager->getNumKarts() < (unsigned int)m_num_karts || race_manager->getNumPlayers() > 1) return false; + // check if the player came first. Kart* kart = RaceManager::getPlayerKart(0); - if(kart->getPosition()>m_position) return false; + + // FIXME - this code is duplicated from GrandPrixEnding. We should find a cleaner way to solve this. + const unsigned int NUM_KARTS = race_manager->getNumKarts(); + + int *scores = new int[NUM_KARTS]; + int *position = new int[NUM_KARTS]; + double *race_time = new double[NUM_KARTS]; + // Ignore the first kart if it's a follow-the-leader race. + int start=(race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER) ? 1 : 0; + for( unsigned int kart_id = start; kart_id < NUM_KARTS; ++kart_id ) + { + position[kart_id] = kart_id; + scores[kart_id] = race_manager->getKartScore(kart_id); + race_time[kart_id] = race_manager->getOverallTime(kart_id); + } + + //Bubblesort + bool sorted; + do + { + sorted = true; + for( unsigned int i = start; i < NUM_KARTS - 1; ++i ) + { + if( scores[i] < scores[i+1] || (scores[i] == scores[i+1] + && race_time[i] > race_time[i+1])) + { + int tmp_score[2]; + double tmp_time; + + tmp_score[0] = position[i]; + tmp_score[1] = scores[i]; + tmp_time = race_time[i]; + + position[i] = position[i+1]; + scores[i] = scores[i+1]; + race_time[i] = race_time[i+1]; + + position[i+1] = tmp_score[0]; + scores[i+1] = tmp_score[1]; + race_time[i+1] = tmp_time; + + sorted = false; + } + } + } while(!sorted); + + if(kart->getIdent() != race_manager->getKartName(position[start])) return false; // winner is not player return true; + + } // grandPrixFinished diff --git a/src/gui/grand_prix_ending.cpp b/src/gui/grand_prix_ending.cpp index 41d3201b1..2a36e973a 100644 --- a/src/gui/grand_prix_ending.cpp +++ b/src/gui/grand_prix_ending.cpp @@ -108,7 +108,7 @@ GrandPrixEnd::GrandPrixEnd() static char output[MAX_MESSAGE_LENGTH]; snprintf(output, sizeof(output), - _("The winner is %s!"),race_manager->getKartName(position[start]).c_str()); + _("The winner is %s!"),race_manager->getKartName(position[start]).c_str()); // FIXME - uses inner-name and not user name widget_manager->addWgt( WTOK_TITLE, 60, 10); widget_manager->showWgtRect(WTOK_TITLE); widget_manager->showWgtText(WTOK_TITLE); @@ -129,7 +129,7 @@ GrandPrixEnd::GrandPrixEnd() sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %d %s", i + 1-start, race_manager->getKartName(position[i]).c_str(), scores[i], sTime ); - + widget_manager->addWgt(WTOK_FIRSTKART + i, 40, 5); widget_manager->showWgtRect(WTOK_FIRSTKART + i); widget_manager->showWgtText(WTOK_FIRSTKART + i);