More bug fixes for FTL mode, and started some code simplification.
By now FTL should basically work (i.e. not crash and list karts in the right order at the end), though the reported times are still not correct. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5897 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
7688b613ec
commit
442168e845
@ -74,6 +74,7 @@ Kart::Kart (const std::string& ident, int position,
|
||||
m_kart_properties = kart_properties_manager->getKart(ident);
|
||||
assert(m_kart_properties != NULL);
|
||||
m_initial_position = position;
|
||||
m_race_position = position;
|
||||
m_collected_energy = 0;
|
||||
m_finished_race = false;
|
||||
m_finish_time = 0.0f;
|
||||
@ -92,7 +93,6 @@ Kart::Kart (const std::string& ident, int position,
|
||||
m_saved_controller = NULL;
|
||||
|
||||
m_view_blocked_by_plunger = 0;
|
||||
m_race_position = -1;
|
||||
|
||||
// Initialize custom sound vector (TODO: add back when properly done)
|
||||
// m_custom_sounds.resize(SFXManager::NUM_CUSTOMS);
|
||||
@ -405,7 +405,7 @@ void Kart::reset()
|
||||
m_attachment->clear();
|
||||
m_powerup.reset();
|
||||
|
||||
m_race_position = 9;
|
||||
m_race_position = m_initial_position;
|
||||
m_eliminated = false;
|
||||
m_finished_race = false;
|
||||
m_finish_time = 0.0f;
|
||||
|
@ -50,34 +50,40 @@ void FollowTheLeaderRace::countdownReachedZero()
|
||||
if(m_leader_intervals.size()>1)
|
||||
m_leader_intervals.erase(m_leader_intervals.begin());
|
||||
WorldStatus::setTime(m_leader_intervals[0]);
|
||||
int kart_number;
|
||||
|
||||
// If the leader kart is not the first kart, remove the first
|
||||
// kart, otherwise remove the last kart.
|
||||
int position_to_remove = m_karts[0]->getPosition()==1
|
||||
? getCurrentNumKarts() : 1;
|
||||
const int kart_amount = m_karts.size();
|
||||
for (kart_number=0; kart_number<kart_amount; kart_number++)
|
||||
{
|
||||
if(m_karts[kart_number]->isEliminated()) continue;
|
||||
if(m_karts[kart_number]->getPosition()==position_to_remove)
|
||||
break;
|
||||
}
|
||||
if(kart_number==kart_amount)
|
||||
const Kart *kart = getKartAtPosition(position_to_remove);
|
||||
if(!kart || kart->isEliminated())
|
||||
{
|
||||
fprintf(stderr,"Problem with removing leader: position %d not found\n",
|
||||
position_to_remove);
|
||||
for(int i=0; i<kart_amount; i++)
|
||||
for(unsigned int i=0; i<m_karts.size(); i++)
|
||||
{
|
||||
fprintf(stderr,"kart %d: eliminated %d position %d\n",
|
||||
i,m_karts[i]->isEliminated(), m_karts[i]->getPosition());
|
||||
} // for i
|
||||
} // kart_number==m_kart.size()
|
||||
} //
|
||||
else
|
||||
{
|
||||
// In case that the kart on position 1 was removed, we have to set
|
||||
// the correct position (which equals the remaining number of karts).
|
||||
setKartPosition(kart_number, getCurrentNumKarts());
|
||||
removeKart(kart_number);
|
||||
removeKart(kart->getWorldKartId());
|
||||
|
||||
// In case that the kart on position 1 was removed, we have
|
||||
// to set the correct position (which equals the remaining
|
||||
// number of karts) for the removed kart, as well as recompute
|
||||
// the position for all other karts
|
||||
if(position_to_remove==1)
|
||||
{
|
||||
// We have to add 1 to the number of karts to get the correct
|
||||
// position, since the eliminated kart was already removed
|
||||
// from the value returned by getCurrentNumKarts (and we have
|
||||
// to remove the kart before we can call updateRacePosition).
|
||||
setKartPosition(kart->getWorldKartId(),
|
||||
getCurrentNumKarts()+1);
|
||||
updateRacePosition();
|
||||
}
|
||||
}
|
||||
|
||||
// almost over, use fast music
|
||||
@ -98,8 +104,6 @@ void FollowTheLeaderRace::countdownReachedZero()
|
||||
m_karts[n]->getController()->getPlayer() != NULL) // if player kart
|
||||
{
|
||||
m_karts[n]->finishedRace(getTime());
|
||||
//irr::core::stringw message(_("You won the race!"));
|
||||
//getRaceGUI()->addMessage( message, m_karts[n], 2.0f, 60 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,7 +192,7 @@ void FollowTheLeaderRace::getRaceResultOrder(std::vector<int> *order)
|
||||
|
||||
for(unsigned int i=1; i<num_karts; i++)
|
||||
{
|
||||
setKartPosition((*order)[i], i);
|
||||
//FIXME JOERGH setKartPosition((*order)[i], i);
|
||||
}
|
||||
|
||||
delete []scores;
|
||||
|
@ -620,7 +620,7 @@ void LinearWorld::updateRacePosition()
|
||||
{
|
||||
if(j == kart->getWorldKartId()) continue; // don't compare a kart with itself
|
||||
|
||||
//if(m_karts[j]->isEliminated()) continue; // dismiss eliminated karts
|
||||
if(m_karts[j]->isEliminated()) continue; // dismiss eliminated karts
|
||||
|
||||
if(!kart->hasFinishedRace() && m_karts[j]->hasFinishedRace())
|
||||
{
|
||||
|
@ -26,6 +26,18 @@ void WorldWithRank::init()
|
||||
m_position_index.resize(m_karts.size());
|
||||
} // init
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Returns the kart with a given position.
|
||||
* \param p The position of the kart, 1<=p<=num_karts).
|
||||
*/
|
||||
const Kart* WorldWithRank::getKartAtPosition(unsigned int p) const
|
||||
{
|
||||
if(p<1 || p>m_position_index.size())
|
||||
return NULL;
|
||||
|
||||
return m_karts[m_position_index[p-1]];
|
||||
} // getKartAtPosition
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void WorldWithRank::setKartPosition(unsigned int kart_id,
|
||||
unsigned int position)
|
||||
@ -64,7 +76,7 @@ void WorldWithRank::getRaceResultOrder(std::vector<int> *order)
|
||||
std::cerr << "== TWO KARTS ARE BEING GIVEN THE SAME POSITION!! ==\n";
|
||||
for (unsigned int j=0; j < num_karts; j++)
|
||||
{
|
||||
if ((*order)[j] == -1)
|
||||
if ((*order)[j] == -1)
|
||||
{
|
||||
std::cout << " No kart is yet set at position " << j << std::endl;
|
||||
}
|
||||
|
@ -43,10 +43,7 @@ public:
|
||||
|
||||
void setKartPosition(unsigned int kart_id,
|
||||
unsigned int position);
|
||||
|
||||
/** Returns the kart with position p, 1<=p<=num_karts). */
|
||||
const Kart* getKartAtPosition(unsigned int p) const
|
||||
{ return m_karts[m_position_index[p-1]]; }
|
||||
const Kart* getKartAtPosition(unsigned int p) const;
|
||||
|
||||
/** Called by the race result GUI at the end of the race to know the
|
||||
* final order (fill in the 'order' array) */
|
||||
|
@ -217,10 +217,16 @@ void RaceResultGUI::determineTableLayout()
|
||||
m_font->setMonospaceDigits(true);
|
||||
WorldWithRank *rank_world = (WorldWithRank*)World::getWorld();
|
||||
|
||||
std::vector<int> order;
|
||||
rank_world->getRaceResultOrder(&order);
|
||||
unsigned int first_position = 1;
|
||||
if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER)
|
||||
first_position = 2;
|
||||
|
||||
m_all_row_infos.resize(order.size());
|
||||
// Use only the karts that are supposed to be displayed (and
|
||||
// ignore e.g. the leader in a FTL race).
|
||||
unsigned int num_karts =race_manager->getNumberOfKarts()-first_position+1;
|
||||
|
||||
// In FTL races the leader kart is not displayed
|
||||
m_all_row_infos.resize(num_karts);
|
||||
|
||||
|
||||
// Determine the kart to display in the right order,
|
||||
@ -229,17 +235,14 @@ void RaceResultGUI::determineTableLayout()
|
||||
m_width_kart_name = 0;
|
||||
float max_finish_time = 0;
|
||||
|
||||
// Use only the karts that are supposed to be displayed (and
|
||||
// ignore e.g. the leader in a FTL race).
|
||||
unsigned int num_karts = 0;
|
||||
|
||||
for(unsigned int i=0; i<order.size(); i++)
|
||||
for(unsigned int position=first_position;
|
||||
position<=race_manager->getNumberOfKarts(); position++)
|
||||
{
|
||||
if(order[i]==-1) continue;
|
||||
const Kart *kart = rank_world->getKartAtPosition(position);
|
||||
|
||||
// Save a pointer to the current row_info entry
|
||||
RowInfo *ri = &(m_all_row_infos[num_karts]);
|
||||
num_karts++;
|
||||
Kart *kart = rank_world->getKart(order[i]);
|
||||
RowInfo *ri = &(m_all_row_infos[position-first_position]);
|
||||
ri->m_is_player_kart = kart->getController()->isPlayerController();
|
||||
ri->m_kart_name = kart->getName();
|
||||
|
||||
@ -255,10 +258,8 @@ void RaceResultGUI::determineTableLayout()
|
||||
core::dimension2d<u32> rect = m_font->getDimension(kart->getName().c_str());
|
||||
if(rect.Width > m_width_kart_name)
|
||||
m_width_kart_name = rect.Width;
|
||||
} // for i < order.size()
|
||||
} // for position
|
||||
|
||||
// Make sure the empty rows (due to deleted karts) are not used anymore
|
||||
m_all_row_infos.resize(num_karts);
|
||||
|
||||
std::string max_time = StringUtils::timeToString(max_finish_time);
|
||||
core::stringw string_max_time(max_time.c_str());
|
||||
|
Loading…
x
Reference in New Issue
Block a user