Skip to content

Commit

Permalink
Display a finish (survival) time in FTL result screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiker committed Jul 29, 2015
1 parent d27ba5f commit b18d027
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
35 changes: 17 additions & 18 deletions src/modes/follow_the_leader.cpp
Expand Up @@ -53,6 +53,7 @@ FollowTheLeaderRace::FollowTheLeaderRace() : LinearWorld()
*/
void FollowTheLeaderRace::init()
{
m_last_eliminated_time = 0;
LinearWorld::init();
// WorldWithRank determines the score based on getNumKarts(), but since
// we ignore the leader, the points need to be based on number of karts -1
Expand Down Expand Up @@ -114,6 +115,7 @@ float FollowTheLeaderRace::getClockStartTime()
*/
void FollowTheLeaderRace::countdownReachedZero()
{
m_last_eliminated_time += m_leader_intervals[0];
if(m_leader_intervals.size()>1)
m_leader_intervals.erase(m_leader_intervals.begin());
WorldStatus::setTime(m_leader_intervals[0]);
Expand Down Expand Up @@ -162,7 +164,7 @@ void FollowTheLeaderRace::countdownReachedZero()
updateRacePosition();
}
// Time doesn't make any sense in FTL (and it is not displayed)
kart->finishedRace(-1.0f);
kart->finishedRace(m_last_eliminated_time);

// Move any camera for this kart to the leader, facing backwards,
// so that the eliminated player has something to watch.
Expand Down Expand Up @@ -229,34 +231,31 @@ void FollowTheLeaderRace::terminateRace()
// position 1, the leader now position 2, but the point distribution
// depends on the 'first' (non-leader) kart to be on position 2.
// That situation can also occur during the delay after eliminating
// the last kart before the race result is shown.
// To avoid this problem, adjust the position of any kart that is
// ahead of the leader.
// the last kart before the race result is shown (when the leader
// is overtaken during that time). To avoid this problem, adjust the
// position of any kart that is ahead of the leader.
beginSetKartPositions();
for (unsigned int i = 0; i < getNumKarts(); i++)
{
if (!m_karts[i]->hasFinishedRace() && !m_karts[i]->isEliminated())
if (!m_karts[i]->hasFinishedRace() && !m_karts[i]->isEliminated() &&
m_karts[i]->getPosition() < pos_leader)
{
if (m_karts[i]->getPosition() < pos_leader)
{
setKartPosition(i, m_karts[i]->getPosition() + 1);
}
// Update the estimated finishing time for all karts that haven't
// finished yet.
m_karts[i]->finishedRace(0.0f);
setKartPosition(i, m_karts[i]->getPosition() + 1);
}
} // i < number of karts
setKartPosition(/*kart id*/0, /*position*/1);
endSetKartPositions();

// Mark all still racing karts to be finished.
for (unsigned int n = 0; n < m_karts.size(); n++)
for (int i = m_karts.size(); i>0; i--)
{
if (!m_karts[n]->isEliminated() &&
!m_karts[n]->hasFinishedRace())
{
m_karts[n]->finishedRace(getTime());
}
AbstractKart *kart = getKartAtPosition(i);
if (kart->isEliminated() || kart->hasFinishedRace())
continue;
m_last_eliminated_time += m_leader_intervals[0];
if (m_leader_intervals.size() > 1)
m_leader_intervals.erase(m_leader_intervals.begin());
kart->finishedRace(m_last_eliminated_time);
}


Expand Down
3 changes: 3 additions & 0 deletions src/modes/follow_the_leader.hpp
Expand Up @@ -33,6 +33,9 @@ class FollowTheLeaderRace : public LinearWorld
/** A timer used before terminating the race. */
float m_is_over_delay;

/** Time the last kart was eliminated. It is used to assign each
* kart a 'finish' time (i.e. how long they lasted). */
float m_last_eliminated_time;
public:

FollowTheLeaderRace();
Expand Down
30 changes: 15 additions & 15 deletions src/states_screens/race_result_gui.cpp
Expand Up @@ -468,7 +468,9 @@ void RaceResultGUI::determineTableLayout()
kart->getKartProperties()->getIconMaterial()->getTexture();
ri->m_kart_icon = icon;

if (kart->isEliminated())
// FTL karts will get a time assigned, they are not shown as eliminated
if (kart->isEliminated() &&
race_manager->getMinorMode()!=RaceManager::MINOR_MODE_FOLLOW_LEADER)
{
ri->m_finish_time_string = core::stringw(_("Eliminated"));
}
Expand Down Expand Up @@ -830,15 +832,18 @@ void RaceResultGUI::determineGPLayout()
ri->m_player = ri->m_is_player_kart
? kart->getController()->getPlayer() : NULL;

if (!kart->isEliminated())
// In FTL karts do have a time, which is shown even when the kart
// is eliminated
if (kart->isEliminated() &&
race_manager->getMinorMode()!=RaceManager::MINOR_MODE_FOLLOW_LEADER)
{
float time = race_manager->getOverallTime(kart_id);
ri->m_finish_time_string
= StringUtils::timeToString(time).c_str();
ri->m_finish_time_string = core::stringw(_("Eliminated"));
}
else
{
ri->m_finish_time_string = core::stringw(_("Eliminated"));
float time = race_manager->getOverallTime(kart_id);
ri->m_finish_time_string
= StringUtils::timeToString(time).c_str();
}
ri->m_start_at = m_time_between_rows * rank;
ri->m_x_pos = (float)UserConfigParams::m_width;
Expand Down Expand Up @@ -916,15 +921,10 @@ void RaceResultGUI::displayOneEntry(unsigned int x, unsigned int y,
current_x += m_width_kart_name + m_width_column_space;


// Draw the time except in FTL mode
// --------------------------------
if(race_manager->getMinorMode()!=RaceManager::MINOR_MODE_FOLLOW_LEADER)
{
core::recti dest_rect = core::recti(current_x, y, current_x+100, y+10);
m_font->draw(ri->m_finish_time_string, dest_rect, color, false, false,
NULL, true /* ignoreRTL */);
current_x += m_width_finish_time + m_width_column_space;
}
core::recti dest_rect = core::recti(current_x, y, current_x + 100, y + 10);
m_font->draw(ri->m_finish_time_string, dest_rect, color, false, false,
NULL, true /* ignoreRTL */);
current_x += m_width_finish_time + m_width_column_space;

// Only display points in GP mode and when the GP results are displayed.
// =====================================================================
Expand Down

0 comments on commit b18d027

Please sign in to comment.