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
This commit is contained in:
auria 2008-12-25 03:33:57 +00:00
parent 727079c330
commit 6f358f52d6
2 changed files with 53 additions and 3 deletions

View File

@ -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

View File

@ -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);