2008-09-07 09:25:58 -04:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2006 SuperTuxKart-Team
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2009-06-02 21:36:48 -04:00
|
|
|
#include "race/race_manager.hpp"
|
2008-09-13 03:09:36 -04:00
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
#include <iostream>
|
2010-08-07 21:02:26 -04:00
|
|
|
#include <algorithm>
|
2008-09-07 09:25:58 -04:00
|
|
|
|
2009-01-22 17:27:13 -05:00
|
|
|
#include "challenges/unlock_manager.hpp"
|
2013-05-24 19:38:26 -04:00
|
|
|
#include "config/saved_grand_prix.hpp"
|
2009-06-11 06:00:43 -04:00
|
|
|
#include "config/stk_config.hpp"
|
2013-05-24 19:38:26 -04:00
|
|
|
#include "config/user_config.hpp"
|
2012-05-08 03:07:15 -04:00
|
|
|
#include "graphics/irr_driver.hpp"
|
2009-07-07 20:46:47 -04:00
|
|
|
#include "input/device_manager.hpp"
|
|
|
|
#include "input/input_manager.hpp"
|
2012-03-19 16:21:11 -04:00
|
|
|
#include "karts/abstract_kart.hpp"
|
2012-03-08 17:56:33 -05:00
|
|
|
#include "karts/controller/controller.hpp"
|
2008-11-06 23:34:01 -05:00
|
|
|
#include "karts/kart_properties_manager.hpp"
|
2012-05-30 21:32:27 -04:00
|
|
|
#include "modes/cutscene_world.hpp"
|
2012-05-06 20:10:33 -04:00
|
|
|
#include "modes/demo_world.hpp"
|
2012-12-16 19:33:47 -05:00
|
|
|
#include "modes/easter_egg_hunt.hpp"
|
2008-09-20 19:45:22 -04:00
|
|
|
#include "modes/follow_the_leader.hpp"
|
2011-12-18 21:26:07 -05:00
|
|
|
#include "modes/overworld.hpp"
|
2009-08-20 20:32:24 -04:00
|
|
|
#include "modes/profile_world.hpp"
|
2009-06-02 21:36:48 -04:00
|
|
|
#include "modes/standard_race.hpp"
|
2013-01-13 19:35:44 -05:00
|
|
|
#include "modes/tutorial_world.hpp"
|
2009-06-02 21:36:48 -04:00
|
|
|
#include "modes/world.hpp"
|
2008-10-14 16:20:54 -04:00
|
|
|
#include "modes/three_strikes_battle.hpp"
|
2012-12-21 16:26:53 -05:00
|
|
|
#include "modes/soccer_world.hpp"
|
2009-06-02 21:36:48 -04:00
|
|
|
#include "network/network_manager.hpp"
|
2010-05-30 11:45:44 -04:00
|
|
|
#include "states_screens/grand_prix_lose.hpp"
|
|
|
|
#include "states_screens/grand_prix_win.hpp"
|
2010-02-20 21:22:05 -05:00
|
|
|
#include "states_screens/kart_selection.hpp"
|
|
|
|
#include "states_screens/main_menu_screen.hpp"
|
|
|
|
#include "states_screens/state_manager.hpp"
|
2009-01-22 07:02:40 -05:00
|
|
|
#include "tracks/track_manager.hpp"
|
2011-02-02 17:26:01 -05:00
|
|
|
#include "utils/ptr_vector.hpp"
|
2008-09-07 09:25:58 -04:00
|
|
|
|
|
|
|
RaceManager* race_manager= NULL;
|
|
|
|
|
2008-09-09 09:43:09 -04:00
|
|
|
/** Constructs the race manager.
|
|
|
|
*/
|
2008-09-07 09:25:58 -04:00
|
|
|
RaceManager::RaceManager()
|
|
|
|
{
|
2013-04-11 02:17:46 -04:00
|
|
|
// Several code depends on this, e.g. kart_properties
|
|
|
|
assert(DIFFICULTY_FIRST == 0);
|
2009-06-20 21:10:43 -04:00
|
|
|
m_num_karts = UserConfigParams::m_num_karts;
|
2012-10-21 19:06:33 -04:00
|
|
|
m_difficulty = DIFFICULTY_HARD;
|
2008-09-21 20:55:27 -04:00
|
|
|
m_major_mode = MAJOR_MODE_SINGLE;
|
2009-12-22 16:57:15 -05:00
|
|
|
m_minor_mode = MINOR_MODE_NORMAL_RACE;
|
2012-09-03 20:39:14 -04:00
|
|
|
m_ai_superpower = SUPERPOWER_NONE;
|
2008-09-07 09:25:58 -04:00
|
|
|
m_track_number = 0;
|
|
|
|
m_coin_target = 0;
|
2012-04-01 11:42:44 -04:00
|
|
|
m_started_from_overworld = false;
|
2012-04-01 13:17:36 -04:00
|
|
|
m_have_kart_last_position_on_overworld = false;
|
2012-02-06 16:12:10 -05:00
|
|
|
setReverseTrack(false);
|
2008-11-19 17:30:51 -05:00
|
|
|
setTrack("jungle");
|
2011-07-28 18:56:49 -04:00
|
|
|
m_default_ai_list.clear();
|
2009-07-18 11:21:16 -04:00
|
|
|
setNumLocalPlayers(0);
|
2008-09-07 09:25:58 -04:00
|
|
|
} // RaceManager
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** Destructor for the race manager.
|
|
|
|
*/
|
2008-09-07 09:25:58 -04:00
|
|
|
RaceManager::~RaceManager()
|
|
|
|
{
|
|
|
|
} // ~RaceManager
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** Resets the race manager in preparation for a new race. It sets the
|
|
|
|
* counter of finished karts to zero.
|
|
|
|
*/
|
2008-09-07 09:25:58 -04:00
|
|
|
void RaceManager::reset()
|
|
|
|
{
|
|
|
|
m_num_finished_karts = 0;
|
|
|
|
m_num_finished_players = 0;
|
|
|
|
} // reset
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** \brief Sets a player kart (local and non-local).
|
|
|
|
* \param player_id Id of the player.
|
|
|
|
* \param ki Kart info structure for this player.
|
|
|
|
*/
|
2008-09-07 10:34:04 -04:00
|
|
|
void RaceManager::setPlayerKart(unsigned int player_id, const RemoteKartInfo& ki)
|
2008-09-07 09:25:58 -04:00
|
|
|
{
|
2008-09-07 10:34:04 -04:00
|
|
|
m_player_karts[player_id] = ki;
|
|
|
|
} // setPlayerKart
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** Sets the default list of AI karts to use.
|
|
|
|
* \param ai_kart_list List of the identifier of the karts to use.
|
|
|
|
*/
|
|
|
|
void RaceManager::setDefaultAIKartList(const std::vector<std::string>& ai_list)
|
|
|
|
{
|
|
|
|
for(unsigned int i=0; i<ai_list.size(); i++)
|
|
|
|
{
|
|
|
|
const std::string &name=ai_list[i];
|
|
|
|
const KartProperties *kp = kart_properties_manager->getKart(name);
|
|
|
|
if(!kp)
|
|
|
|
{
|
2013-04-19 02:53:17 -04:00
|
|
|
Log::warn("RaceManager", "Kart '%s' is unknown and therefore ignored.",
|
|
|
|
name.c_str());
|
2011-07-28 18:56:49 -04:00
|
|
|
continue;
|
|
|
|
}
|
2011-12-11 22:49:33 -05:00
|
|
|
// This doesn't work anymore, since this is called when
|
|
|
|
// handling the command line options, at which time the
|
|
|
|
// player (and therefore the current slot) is not defined yet.
|
|
|
|
//if(unlock_manager->getCurrentSlot()->isLocked(name))
|
|
|
|
//{
|
|
|
|
// printf("Kart '%s' is locked and therefore ignored.\n",
|
|
|
|
// name.c_str());
|
|
|
|
// continue;
|
|
|
|
//}
|
2011-07-28 18:56:49 -04:00
|
|
|
m_default_ai_list.push_back(name);
|
|
|
|
}
|
2012-06-28 00:00:40 -04:00
|
|
|
} // setDefaultAIKartList
|
2011-01-03 15:17:44 -05:00
|
|
|
|
2011-07-28 18:56:49 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Sets information about a kart used by a local player (i.e. on this
|
|
|
|
* computer).
|
|
|
|
* \param player_id Id of this player.
|
|
|
|
* \param kart The kart this player uses.
|
|
|
|
*/
|
|
|
|
void RaceManager::setLocalKartInfo(unsigned int player_id,
|
|
|
|
const std::string& kart)
|
2008-09-07 10:34:04 -04:00
|
|
|
{
|
2011-06-12 13:35:13 -04:00
|
|
|
assert(kart.size() > 0);
|
2010-03-07 13:42:04 -05:00
|
|
|
assert(0<=player_id && player_id <m_local_player_karts.size());
|
2010-12-05 11:12:35 -05:00
|
|
|
assert(kart_properties_manager->getKart(kart) != NULL);
|
2008-09-07 10:34:04 -04:00
|
|
|
|
2010-03-07 13:42:04 -05:00
|
|
|
m_local_player_karts[player_id] = RemoteKartInfo(player_id, kart,
|
2010-02-18 16:28:32 -05:00
|
|
|
StateManager::get()->getActivePlayerProfile(player_id)->getName(),
|
2009-07-18 11:21:16 -04:00
|
|
|
network_manager->getMyHostId());
|
2008-09-07 10:34:04 -04:00
|
|
|
} // setLocalKartInfo
|
2008-09-07 09:33:12 -04:00
|
|
|
|
2013-01-26 07:54:31 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Sets additional information for a player to indicate which soccer team it belong to
|
|
|
|
*/
|
|
|
|
void RaceManager::setLocalKartSoccerTeam(unsigned int player_id, SoccerTeam team)
|
|
|
|
{
|
|
|
|
assert(0<=player_id && player_id <m_local_player_karts.size());
|
|
|
|
|
|
|
|
m_local_player_karts[player_id].setSoccerTeam(team);
|
|
|
|
}
|
|
|
|
|
2010-03-07 13:42:04 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** Returns a pointer to the kart which has a given GP rank.
|
|
|
|
* \param n The rank (1 to number of karts) to look for.
|
|
|
|
*/
|
2012-03-19 16:21:11 -04:00
|
|
|
const AbstractKart *RaceManager::getKartWithGPRank(unsigned int n)
|
2010-07-29 19:03:20 -04:00
|
|
|
{
|
|
|
|
for(unsigned int i=0; i<m_kart_status.size(); i++)
|
2010-08-29 20:21:04 -04:00
|
|
|
if(m_kart_status[i].m_gp_rank == (int)n)
|
2010-07-29 19:03:20 -04:00
|
|
|
return World::getWorld()->getKart(i);
|
|
|
|
return NULL;
|
|
|
|
} // getKLartWithGPRank
|
2010-03-07 13:42:04 -05:00
|
|
|
|
2010-07-29 19:03:20 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** Returns the GP rank (between 1 and number of karts) of a local player.
|
|
|
|
* \param player_id Local id of the player.
|
|
|
|
*/
|
|
|
|
int RaceManager::getLocalPlayerGPRank(const int player_id) const
|
2010-03-07 13:42:04 -05:00
|
|
|
{
|
|
|
|
const int amount = m_kart_status.size();
|
|
|
|
for (int n=0; n<amount; n++)
|
|
|
|
{
|
2011-07-28 18:56:49 -04:00
|
|
|
if (m_kart_status[n].m_local_player_id == player_id)
|
2010-03-07 13:42:04 -05:00
|
|
|
{
|
|
|
|
return m_kart_status[n].m_gp_rank;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
2010-07-22 18:51:14 -04:00
|
|
|
} // getLocalPlayerGPRank
|
2010-03-07 13:42:04 -05:00
|
|
|
|
2008-09-07 09:33:12 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** Sets the number of local players, i.e. the number of players on this
|
|
|
|
* computer.
|
|
|
|
* \param n Number of local players.
|
|
|
|
*/
|
2008-09-07 10:34:04 -04:00
|
|
|
void RaceManager::setNumLocalPlayers(unsigned int n)
|
2008-09-07 09:33:12 -04:00
|
|
|
{
|
2010-03-07 13:42:04 -05:00
|
|
|
m_local_player_karts.resize(n);
|
2008-09-07 10:34:04 -04:00
|
|
|
} // setNumLocalPlayers
|
2008-09-07 09:25:58 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-09-09 09:43:09 -04:00
|
|
|
/** Sets the number of players.
|
|
|
|
* \param num Number of players.
|
|
|
|
*/
|
2008-09-07 09:25:58 -04:00
|
|
|
void RaceManager::setNumPlayers(int num)
|
|
|
|
{
|
|
|
|
m_player_karts.resize(num);
|
|
|
|
} // setNumPlayers
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** Sets the difficulty to use.
|
|
|
|
* \param diff The difficulty to use.
|
|
|
|
*/
|
2008-09-07 09:25:58 -04:00
|
|
|
void RaceManager::setDifficulty(Difficulty diff)
|
|
|
|
{
|
2008-11-24 03:22:34 -05:00
|
|
|
m_difficulty = diff;
|
2008-09-07 09:25:58 -04:00
|
|
|
} // setDifficulty
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** Sets a single track to be used in the next race.
|
|
|
|
* \param track The identifier of the track to use.
|
|
|
|
*/
|
2008-09-07 09:25:58 -04:00
|
|
|
void RaceManager::setTrack(const std::string& track)
|
|
|
|
{
|
|
|
|
m_tracks.clear();
|
|
|
|
m_tracks.push_back(track);
|
2010-12-30 21:24:44 -05:00
|
|
|
|
|
|
|
m_coin_target = 0;
|
2008-09-07 09:25:58 -04:00
|
|
|
} // setTrack
|
|
|
|
|
2008-09-07 10:24:40 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-07-28 18:56:49 -04:00
|
|
|
/** \brief Computes the list of random karts to be used for the AI.
|
|
|
|
* If a command line option specifies karts, they will be used first
|
|
|
|
*/
|
2008-09-07 10:24:40 -04:00
|
|
|
void RaceManager::computeRandomKartList()
|
|
|
|
{
|
2008-09-09 09:43:09 -04:00
|
|
|
int n = m_num_karts - m_player_karts.size();
|
2011-07-15 19:39:09 -04:00
|
|
|
if(UserConfigParams::logMisc())
|
2010-03-24 19:52:41 -04:00
|
|
|
std::cout << "AI karts count = " << n << " for m_num_karts="
|
|
|
|
<< m_num_karts << " and m_player_karts.size()="
|
|
|
|
<< m_player_karts.size() << std::endl;
|
|
|
|
|
2008-09-09 09:43:09 -04:00
|
|
|
// If less kart selected than there are player karts, adjust the number of
|
|
|
|
// karts to the minimum
|
|
|
|
if(n<0)
|
|
|
|
{
|
|
|
|
m_num_karts -= n;
|
|
|
|
n = 0;
|
|
|
|
}
|
2011-07-28 18:56:49 -04:00
|
|
|
|
|
|
|
m_ai_kart_list.clear();
|
2011-07-28 21:40:46 -04:00
|
|
|
unsigned int m = std::min( (unsigned) n, (unsigned)m_default_ai_list.size());
|
2011-07-28 18:56:49 -04:00
|
|
|
|
|
|
|
for(unsigned int i=0; i<m; i++)
|
|
|
|
{
|
|
|
|
m_ai_kart_list.push_back(m_default_ai_list[i]);
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(n>0)
|
|
|
|
kart_properties_manager->getRandomKartList(n, m_player_karts,
|
|
|
|
&m_ai_kart_list );
|
2008-09-07 10:24:40 -04:00
|
|
|
|
2012-09-03 16:18:48 -04:00
|
|
|
if (m_ai_kart_override != "")
|
|
|
|
{
|
2012-09-03 18:49:30 -04:00
|
|
|
for (unsigned int n = 0; n < m_ai_kart_list.size(); n++)
|
2012-09-03 16:18:48 -04:00
|
|
|
{
|
|
|
|
m_ai_kart_list[n] = m_ai_kart_override;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-07 10:24:40 -04:00
|
|
|
} // computeRandomKartList
|
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-01-03 15:17:44 -05:00
|
|
|
|
2012-04-01 11:42:44 -04:00
|
|
|
void RaceManager::startNew(bool from_overworld)
|
2008-09-07 09:25:58 -04:00
|
|
|
{
|
2012-04-01 11:42:44 -04:00
|
|
|
m_started_from_overworld = from_overworld;
|
|
|
|
|
2012-03-25 18:15:20 -04:00
|
|
|
if(m_major_mode==MAJOR_MODE_GRAND_PRIX)
|
2008-09-07 09:25:58 -04:00
|
|
|
{
|
2012-03-25 18:15:20 -04:00
|
|
|
// GP: get tracks, laps and reverse info from grand prix
|
2012-11-27 07:09:16 -05:00
|
|
|
m_tracks = m_grand_prix.getTrackNames();
|
|
|
|
m_grand_prix.getLaps(&m_num_laps);
|
|
|
|
m_grand_prix.getReverse(&m_reverse_track);
|
2008-09-07 09:25:58 -04:00
|
|
|
}
|
2012-05-30 21:32:27 -04:00
|
|
|
//assert(m_player_karts.size() > 0);
|
2008-09-07 09:25:58 -04:00
|
|
|
|
|
|
|
// command line parameters: negative numbers=all karts
|
|
|
|
if(m_num_karts < 0 ) m_num_karts = stk_config->m_max_karts;
|
|
|
|
if((size_t)m_num_karts < m_player_karts.size())
|
|
|
|
m_num_karts = (int)m_player_karts.size();
|
2012-05-30 21:32:27 -04:00
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
// Create the kart status data structure to keep track of scores, times, ...
|
|
|
|
// ==========================================================================
|
|
|
|
m_kart_status.clear();
|
2008-09-07 10:24:40 -04:00
|
|
|
|
2013-05-24 19:38:26 -04:00
|
|
|
|
2010-09-21 06:28:30 -04:00
|
|
|
assert((unsigned int)m_num_karts == m_ai_kart_list.size()+m_player_karts.size());
|
2008-09-07 10:24:40 -04:00
|
|
|
// First add the AI karts (randomly chosen)
|
|
|
|
// ----------------------------------------
|
2010-12-19 20:16:03 -05:00
|
|
|
|
|
|
|
// GP ranks start with -1 for the leader.
|
|
|
|
int init_gp_rank =
|
|
|
|
race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER
|
|
|
|
? -1
|
|
|
|
: 0;
|
2010-09-21 03:37:42 -04:00
|
|
|
const unsigned int ai_kart_count = m_ai_kart_list.size();
|
2010-09-20 13:09:25 -04:00
|
|
|
for(unsigned int i=0; i<ai_kart_count; i++)
|
2010-07-29 19:03:20 -04:00
|
|
|
{
|
2010-09-21 03:37:42 -04:00
|
|
|
m_kart_status.push_back(KartStatus(m_ai_kart_list[i], i, -1, -1,
|
2010-07-29 19:03:20 -04:00
|
|
|
init_gp_rank, KT_AI));
|
|
|
|
init_gp_rank ++;
|
2011-03-21 02:15:39 -04:00
|
|
|
if(UserConfigParams::m_ftl_debug)
|
|
|
|
{
|
2013-04-19 02:53:17 -04:00
|
|
|
Log::debug("RaceManager", "[ftl] rank %d ai-kart %s", init_gp_rank,
|
2011-03-21 02:15:39 -04:00
|
|
|
m_ai_kart_list[i].c_str());
|
|
|
|
}
|
2010-07-29 19:03:20 -04:00
|
|
|
}
|
2012-06-04 20:27:34 -04:00
|
|
|
|
2008-09-07 10:24:40 -04:00
|
|
|
// Then the players, which start behind the AI karts
|
|
|
|
// -------------------------------------------------
|
|
|
|
for(int i=m_player_karts.size()-1; i>=0; i--)
|
2008-09-07 09:25:58 -04:00
|
|
|
{
|
2008-09-07 10:24:40 -04:00
|
|
|
KartType kt=(m_player_karts[i].getHostId()==network_manager->getMyHostId())
|
|
|
|
? KT_PLAYER : KT_NETWORK_PLAYER;
|
|
|
|
m_kart_status.push_back(KartStatus(m_player_karts[i].getKartName(), i,
|
|
|
|
m_player_karts[i].getLocalPlayerId(),
|
|
|
|
m_player_karts[i].getGlobalPlayerId(),
|
2010-07-29 19:03:20 -04:00
|
|
|
init_gp_rank, kt
|
2008-09-07 09:25:58 -04:00
|
|
|
) );
|
2011-03-21 02:15:39 -04:00
|
|
|
if(UserConfigParams::m_ftl_debug)
|
|
|
|
{
|
2013-04-19 02:53:17 -04:00
|
|
|
Log::debug("RaceManager", "[ftl] rank %d kart %s", init_gp_rank,
|
2011-03-21 02:15:39 -04:00
|
|
|
m_player_karts[i].getKartName().c_str());
|
|
|
|
}
|
2010-07-29 19:03:20 -04:00
|
|
|
init_gp_rank ++;
|
2008-09-07 10:24:40 -04:00
|
|
|
}
|
2008-09-07 09:25:58 -04:00
|
|
|
|
2013-05-25 20:31:22 -04:00
|
|
|
m_track_number = 0;
|
|
|
|
if(m_major_mode==MAJOR_MODE_GRAND_PRIX)
|
2013-05-24 19:38:26 -04:00
|
|
|
{
|
2013-05-25 20:31:22 -04:00
|
|
|
//We look if Player 1 has a saved version of this GP.
|
|
|
|
// =================================================
|
|
|
|
SavedGrandPrix* gp = SavedGrandPrix::getSavedGP( StateManager::get()
|
|
|
|
->getActivePlayerProfile(0)
|
|
|
|
->getUniqueID(),
|
|
|
|
m_grand_prix.getId(),
|
|
|
|
m_difficulty,
|
|
|
|
m_num_karts,
|
|
|
|
m_player_karts.size());
|
|
|
|
|
|
|
|
// Start the race with the appropriate track
|
|
|
|
// =========================================
|
|
|
|
if(gp != NULL)
|
|
|
|
{
|
|
|
|
m_track_number = gp->getNextTrack();
|
|
|
|
gp->loadKarts(m_kart_status);
|
|
|
|
}
|
2013-05-24 19:38:26 -04:00
|
|
|
}
|
2008-09-07 09:25:58 -04:00
|
|
|
startNextRace();
|
|
|
|
} // startNew
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2011-01-03 15:17:44 -05:00
|
|
|
/** \brief Starts the next (or first) race.
|
|
|
|
* It sorts the kart status data structure
|
2008-09-09 09:43:09 -04:00
|
|
|
* according to the number of points, and then creates the world().
|
|
|
|
*/
|
2008-09-07 09:25:58 -04:00
|
|
|
void RaceManager::startNextRace()
|
|
|
|
{
|
2010-12-08 17:18:55 -05:00
|
|
|
// Uncomment to debug audio leaks
|
|
|
|
// sfx_manager->dump();
|
|
|
|
|
2010-09-15 22:31:20 -04:00
|
|
|
stk_config->getAllScores(&m_score_for_position, m_num_karts);
|
2010-02-22 20:00:21 -05:00
|
|
|
IrrlichtDevice* device = irr_driver->getDevice();
|
|
|
|
GUIEngine::renderLoading();
|
|
|
|
device->getVideoDriver()->endScene();
|
|
|
|
device->getVideoDriver()->beginScene(true, true, video::SColor(255,100,101,140));
|
|
|
|
|
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
m_num_finished_karts = 0;
|
|
|
|
m_num_finished_players = 0;
|
|
|
|
|
|
|
|
// if subsequent race, sort kart status structure
|
|
|
|
// ==============================================
|
|
|
|
if (m_track_number > 0)
|
|
|
|
{
|
|
|
|
// In follow the leader mode do not change the first kart,
|
|
|
|
// since it's always the leader.
|
2008-09-21 20:55:27 -04:00
|
|
|
int offset = (m_minor_mode==MINOR_MODE_FOLLOW_LEADER) ? 1 : 0;
|
2008-09-07 09:25:58 -04:00
|
|
|
|
2012-03-25 12:39:32 -04:00
|
|
|
// Keep players at the end if needed
|
|
|
|
int player_last_offset = 0;
|
|
|
|
if (UserConfigParams::m_gp_player_last)
|
2008-09-07 09:25:58 -04:00
|
|
|
{
|
2012-03-25 12:39:32 -04:00
|
|
|
// Doing this is enough to keep player karts at
|
|
|
|
// the end because of the simple reason that they
|
|
|
|
// are at the end when getting added. Keep them out
|
|
|
|
// of the later sorting and they will stay there.
|
|
|
|
player_last_offset = m_player_karts.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(m_kart_status.begin()+offset,
|
|
|
|
m_kart_status.end() - player_last_offset);
|
|
|
|
// reverse kart order if flagged in user's config
|
|
|
|
if (UserConfigParams::m_gp_most_points_first)
|
|
|
|
{
|
|
|
|
std::reverse(m_kart_status.begin()+offset,
|
|
|
|
m_kart_status.end() - player_last_offset);
|
2008-09-07 09:25:58 -04:00
|
|
|
}
|
|
|
|
} // not first race
|
2012-05-30 21:32:27 -04:00
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
// the constructor assigns this object to the global
|
|
|
|
// variable world. Admittedly a bit ugly, but simplifies
|
|
|
|
// handling of objects which get created in the constructor
|
|
|
|
// and need world to be defined.
|
2012-05-06 20:10:33 -04:00
|
|
|
if(DemoWorld::isDemoMode())
|
|
|
|
World::setWorld(new DemoWorld());
|
|
|
|
else if(ProfileWorld::isProfileMode())
|
2010-02-11 02:11:52 -05:00
|
|
|
World::setWorld(new ProfileWorld());
|
2009-08-20 20:32:24 -04:00
|
|
|
else if(m_minor_mode==MINOR_MODE_FOLLOW_LEADER)
|
2010-02-11 02:11:52 -05:00
|
|
|
World::setWorld(new FollowTheLeaderRace());
|
2009-12-22 16:57:15 -05:00
|
|
|
else if(m_minor_mode==MINOR_MODE_NORMAL_RACE ||
|
2012-01-30 18:35:46 -05:00
|
|
|
m_minor_mode==MINOR_MODE_TIME_TRIAL)
|
2010-02-11 02:11:52 -05:00
|
|
|
World::setWorld(new StandardRace());
|
2013-01-13 19:35:44 -05:00
|
|
|
else if(m_minor_mode==MINOR_MODE_TUTORIAL)
|
|
|
|
World::setWorld(new TutorialWorld());
|
2009-08-20 20:32:24 -04:00
|
|
|
else if(m_minor_mode==MINOR_MODE_3_STRIKES)
|
2010-02-11 02:11:52 -05:00
|
|
|
World::setWorld(new ThreeStrikesBattle());
|
2012-12-21 16:26:53 -05:00
|
|
|
else if(m_minor_mode==MINOR_MODE_SOCCER)
|
|
|
|
World::setWorld(new SoccerWorld());
|
2011-12-18 21:26:07 -05:00
|
|
|
else if(m_minor_mode==MINOR_MODE_OVERWORLD)
|
|
|
|
World::setWorld(new OverWorld());
|
2012-05-30 21:32:27 -04:00
|
|
|
else if(m_minor_mode==MINOR_MODE_CUTSCENE)
|
|
|
|
World::setWorld(new CutsceneWorld());
|
2012-12-16 19:33:47 -05:00
|
|
|
else if(m_minor_mode==MINOR_MODE_EASTER_EGG)
|
|
|
|
World::setWorld(new EasterEggHunt());
|
2009-08-20 20:32:24 -04:00
|
|
|
else
|
|
|
|
{
|
2013-04-19 02:53:17 -04:00
|
|
|
Log::error("RaceManager", "Could not create given race mode.");
|
2009-08-20 20:32:24 -04:00
|
|
|
assert(0);
|
|
|
|
}
|
2012-05-30 21:32:27 -04:00
|
|
|
|
2013-04-03 02:05:34 -04:00
|
|
|
// A second constructor phase is necessary in order to be able to
|
|
|
|
// call functions which are overwritten (otherwise polymorphism
|
|
|
|
// will fail and the results will be incorrect . Also in init() functions
|
|
|
|
// can be called that use World::getWorld().
|
2010-02-11 02:11:52 -05:00
|
|
|
World::getWorld()->init();
|
2013-04-03 02:05:34 -04:00
|
|
|
|
|
|
|
// Now initialise all values that need to be reset from race to race
|
|
|
|
// Calling this here reduces code duplication in init and restartRace()
|
|
|
|
// functions.
|
|
|
|
World::getWorld()->reset();
|
|
|
|
|
2009-08-11 22:55:53 -04:00
|
|
|
// Save the current score and set last time to zero. This is necessary
|
|
|
|
// if someone presses esc after finishing a gp, and selects restart:
|
|
|
|
// The race is rerun, and the points and scores get reset ... but if
|
|
|
|
// a kart hasn't finished the race at this stage, last_score and time
|
|
|
|
// would be undefined.
|
|
|
|
for(int i=0; i<m_num_karts; i++)
|
|
|
|
{
|
|
|
|
m_kart_status[i].m_last_score = m_kart_status[i].m_score;
|
|
|
|
m_kart_status[i].m_last_time = 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
} // startNextRace
|
2010-02-11 02:11:52 -05:00
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-01-03 15:17:44 -05:00
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
void RaceManager::next()
|
2013-04-19 02:53:17 -04:00
|
|
|
{
|
2010-03-01 15:17:31 -05:00
|
|
|
World::deleteWorld();
|
2008-09-07 09:25:58 -04:00
|
|
|
m_num_finished_karts = 0;
|
|
|
|
m_num_finished_players = 0;
|
|
|
|
m_track_number++;
|
|
|
|
if(m_track_number<(int)m_tracks.size())
|
|
|
|
{
|
2013-05-24 19:38:26 -04:00
|
|
|
if(m_major_mode==MAJOR_MODE_GRAND_PRIX)
|
|
|
|
{
|
|
|
|
//Saving GP state
|
|
|
|
//We look if Player 1 has already saved this GP.
|
|
|
|
SavedGrandPrix* gp =
|
|
|
|
SavedGrandPrix::getSavedGP(StateManager::get()
|
|
|
|
->getActivePlayerProfile(0)
|
|
|
|
->getUniqueID(),
|
|
|
|
m_grand_prix.getId(),
|
|
|
|
m_difficulty,
|
|
|
|
m_num_karts,
|
|
|
|
m_player_karts.size());
|
|
|
|
if(gp != NULL)
|
|
|
|
{
|
|
|
|
//if so addept it
|
|
|
|
gp->setKarts(m_kart_status);
|
|
|
|
gp->setNextTrack(m_track_number);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//create a new entry
|
|
|
|
UserConfigParams::m_saved_grand_prix_list.push_back(
|
|
|
|
new SavedGrandPrix(
|
|
|
|
StateManager::get()->getActivePlayerProfile(0)
|
|
|
|
->getUniqueID(),
|
|
|
|
m_grand_prix.getId(),
|
|
|
|
m_difficulty,
|
|
|
|
m_player_karts.size(),
|
|
|
|
m_track_number,
|
|
|
|
m_kart_status
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
user_config->saveConfig();
|
|
|
|
}
|
|
|
|
|
2008-10-01 20:27:39 -04:00
|
|
|
if(network_manager->getMode()==NetworkManager::NW_SERVER)
|
|
|
|
network_manager->beginReadySetGoBarrier();
|
|
|
|
else
|
|
|
|
network_manager->setState(NetworkManager::NS_WAIT_FOR_RACE_DATA);
|
2008-09-07 09:25:58 -04:00
|
|
|
startNextRace();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-01 20:27:39 -04:00
|
|
|
// Back to main menu. Change the state of the state of the
|
|
|
|
// network manager.
|
|
|
|
if(network_manager->getMode()==NetworkManager::NW_SERVER)
|
|
|
|
network_manager->setState(NetworkManager::NS_MAIN_MENU);
|
|
|
|
else
|
|
|
|
network_manager->setState(NetworkManager::NS_WAIT_FOR_AVAILABLE_CHARACTERS);
|
2009-03-26 19:31:00 -04:00
|
|
|
exitRace();
|
2008-09-07 09:25:58 -04:00
|
|
|
}
|
|
|
|
} // next
|
|
|
|
|
2010-03-07 13:42:04 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-01-03 15:17:44 -05:00
|
|
|
|
2011-02-02 17:26:01 -05:00
|
|
|
/** This class is only used in computeGPRanks, but the C++ standard
|
|
|
|
* forbids the usage of local data type in templates, so we have to
|
|
|
|
* declare it outside of the function. This class is used to store
|
|
|
|
* and compare data for determining the GP rank.
|
|
|
|
*/
|
|
|
|
namespace computeGPRanksData
|
|
|
|
{
|
2012-10-21 19:06:33 -04:00
|
|
|
class SortData
|
2011-02-02 17:26:01 -05:00
|
|
|
{
|
2012-10-21 19:06:33 -04:00
|
|
|
public:
|
|
|
|
int m_score;
|
|
|
|
int m_position;
|
|
|
|
float m_race_time;
|
|
|
|
bool operator<(const SortData &a)
|
|
|
|
{
|
|
|
|
return ( (m_score > a.m_score) ||
|
|
|
|
(m_score == a.m_score && m_race_time < a.m_race_time) );
|
|
|
|
}
|
2013-04-18 18:44:18 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
bool operator>(const SortData &a)
|
|
|
|
{
|
|
|
|
return ( (m_score < a.m_score) ||
|
|
|
|
(m_score == a.m_score && m_race_time > a.m_race_time) );
|
|
|
|
}
|
|
|
|
|
2012-10-21 19:06:33 -04:00
|
|
|
}; // SortData
|
2011-02-02 17:26:01 -05:00
|
|
|
} // namespace
|
|
|
|
|
2012-10-21 19:06:33 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Sort karts and update the m_gp_rank KartStatus member, in preparation
|
|
|
|
* for future calls to RaceManager::getKartGPRank or
|
|
|
|
* RaceManager::getKartWithGPRank
|
|
|
|
*/
|
2010-03-07 13:42:04 -05:00
|
|
|
void RaceManager::computeGPRanks()
|
|
|
|
{
|
|
|
|
// calculate the rank of each kart
|
|
|
|
const unsigned int NUM_KARTS = getNumberOfKarts();
|
2011-02-03 17:20:53 -05:00
|
|
|
PtrVector<computeGPRanksData::SortData> sort_data;
|
2011-02-02 17:04:13 -05:00
|
|
|
|
2010-03-07 13:42:04 -05:00
|
|
|
// Ignore the first kart if it's a follow-the-leader race.
|
2010-07-29 19:03:20 -04:00
|
|
|
int start=(race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER);
|
2011-02-02 17:04:13 -05:00
|
|
|
if (start)
|
2010-03-07 13:42:04 -05:00
|
|
|
{
|
|
|
|
// fill values for leader
|
2011-02-02 17:26:01 -05:00
|
|
|
computeGPRanksData::SortData *sd = new computeGPRanksData::SortData();
|
2011-02-02 17:04:13 -05:00
|
|
|
|
|
|
|
sd->m_position = -1;
|
|
|
|
sd->m_score = -1;
|
|
|
|
sd->m_race_time = -1;
|
|
|
|
sort_data.push_back(sd);
|
2010-03-07 13:42:04 -05:00
|
|
|
m_kart_status[0].m_gp_rank = -1;
|
2011-03-21 02:15:39 -04:00
|
|
|
if(UserConfigParams::m_ftl_debug)
|
|
|
|
{
|
2013-04-19 02:53:17 -04:00
|
|
|
Log::debug("Race Manager","[ftl] kart '%s' has position %d.",
|
|
|
|
World::getWorld()->getKart(0)->getIdent().c_str(),
|
|
|
|
sd->m_position);
|
2011-03-21 02:15:39 -04:00
|
|
|
}
|
2010-03-07 13:42:04 -05:00
|
|
|
}
|
2011-02-02 17:04:13 -05:00
|
|
|
for (unsigned int kart_id = start; kart_id < NUM_KARTS; ++kart_id)
|
2010-03-07 13:42:04 -05:00
|
|
|
{
|
2011-02-02 17:26:01 -05:00
|
|
|
computeGPRanksData::SortData *sd = new computeGPRanksData::SortData();
|
2011-02-02 17:04:13 -05:00
|
|
|
sd->m_position = kart_id;
|
2011-03-21 02:15:39 -04:00
|
|
|
sd->m_score = getKartScore(kart_id);
|
|
|
|
sd->m_race_time = getOverallTime(kart_id);
|
2011-02-02 17:04:13 -05:00
|
|
|
sort_data.push_back(sd);
|
2011-03-21 02:15:39 -04:00
|
|
|
if(UserConfigParams::m_ftl_debug)
|
|
|
|
{
|
2013-04-19 02:53:17 -04:00
|
|
|
Log::debug("Race Manager","[ftl] kart '%s' has position %d score %d.",
|
2011-03-21 02:15:39 -04:00
|
|
|
World::getWorld()->getKart(kart_id)->getIdent().c_str(),
|
|
|
|
sd->m_position, sd->m_score);
|
|
|
|
}
|
2011-02-02 17:04:13 -05:00
|
|
|
}
|
2010-03-07 13:42:04 -05:00
|
|
|
|
2011-02-02 17:04:13 -05:00
|
|
|
sort_data.insertionSort(start);
|
2010-03-07 13:42:04 -05:00
|
|
|
for (unsigned int i=start; i < NUM_KARTS; ++i)
|
|
|
|
{
|
2011-03-21 02:15:39 -04:00
|
|
|
if(UserConfigParams::m_ftl_debug)
|
|
|
|
{
|
2012-03-19 16:21:11 -04:00
|
|
|
const AbstractKart *kart =
|
2011-03-21 02:15:39 -04:00
|
|
|
World::getWorld()->getKart(sort_data[i].m_position);
|
2013-04-19 02:53:17 -04:00
|
|
|
Log::debug("Race Manager","[ftl] kart '%s' has now position %d.",
|
2011-03-21 02:15:39 -04:00
|
|
|
kart->getIdent().c_str(),
|
|
|
|
i-start);
|
|
|
|
}
|
|
|
|
|
2011-02-02 17:04:13 -05:00
|
|
|
m_kart_status[sort_data[i].m_position].m_gp_rank = i - start;
|
2010-03-07 13:42:04 -05:00
|
|
|
}
|
2011-02-02 17:04:13 -05:00
|
|
|
} // computeGPRanks
|
2010-03-07 13:42:04 -05:00
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-01-03 15:17:44 -05:00
|
|
|
|
2012-02-06 20:25:56 -05:00
|
|
|
void RaceManager::exitRace(bool delete_world)
|
2008-09-07 09:25:58 -04:00
|
|
|
{
|
|
|
|
// Only display the grand prix result screen if all tracks
|
|
|
|
// were finished, and not when a race is aborted.
|
2009-12-06 11:06:39 -05:00
|
|
|
if (m_major_mode==MAJOR_MODE_GRAND_PRIX && m_track_number==(int)m_tracks.size())
|
2008-09-07 09:25:58 -04:00
|
|
|
{
|
2011-12-05 17:00:42 -05:00
|
|
|
unlock_manager->getCurrentSlot()->grandPrixFinished();
|
2013-05-24 19:38:26 -04:00
|
|
|
if(m_major_mode==MAJOR_MODE_GRAND_PRIX)
|
|
|
|
{
|
|
|
|
//Delete saved GP
|
|
|
|
SavedGrandPrix* gp =
|
|
|
|
SavedGrandPrix::getSavedGP(StateManager::get()
|
|
|
|
->getActivePlayerProfile(0)
|
|
|
|
->getUniqueID(),
|
|
|
|
m_grand_prix.getId(),
|
|
|
|
m_difficulty,
|
|
|
|
m_num_karts,
|
|
|
|
m_player_karts.size());
|
|
|
|
if(gp != NULL) gp->remove();
|
|
|
|
}
|
2010-02-20 21:22:05 -05:00
|
|
|
StateManager::get()->resetAndGoToScreen( MainMenuScreen::getInstance() );
|
2010-05-30 19:20:32 -04:00
|
|
|
|
|
|
|
bool someHumanPlayerWon = false;
|
|
|
|
const unsigned int kartStatusCount = m_kart_status.size();
|
2010-08-07 21:02:26 -04:00
|
|
|
|
2010-10-28 21:39:27 -04:00
|
|
|
const int loserThreshold = 3;
|
2010-08-07 21:02:26 -04:00
|
|
|
|
2010-02-21 18:10:24 -05:00
|
|
|
std::string winners[3];
|
2010-05-30 19:20:32 -04:00
|
|
|
std::vector<std::string> humanLosers; // because we don't care about AIs that lost
|
|
|
|
for (unsigned int i=0; i < kartStatusCount; ++i)
|
2010-02-21 18:10:24 -05:00
|
|
|
{
|
2011-07-15 19:39:09 -04:00
|
|
|
if(UserConfigParams::logMisc())
|
2010-05-30 11:45:44 -04:00
|
|
|
{
|
2010-03-24 19:52:41 -04:00
|
|
|
std::cout << m_kart_status[i].m_ident << " has GP final rank "
|
|
|
|
<< m_kart_status[i].m_gp_rank << std::endl;
|
2010-05-30 11:45:44 -04:00
|
|
|
}
|
2010-03-24 19:52:41 -04:00
|
|
|
|
2010-03-07 13:42:04 -05:00
|
|
|
const int rank = m_kart_status[i].m_gp_rank;
|
2010-08-07 21:02:26 -04:00
|
|
|
if (rank >= 0 && rank < loserThreshold)
|
2010-02-21 18:10:24 -05:00
|
|
|
{
|
|
|
|
winners[rank] = m_kart_status[i].m_ident;
|
2010-05-30 19:20:32 -04:00
|
|
|
if (m_kart_status[i].m_kart_type == KT_PLAYER ||
|
|
|
|
m_kart_status[i].m_kart_type == KT_NETWORK_PLAYER)
|
|
|
|
{
|
|
|
|
someHumanPlayerWon = true;
|
|
|
|
}
|
|
|
|
}
|
2010-08-07 21:02:26 -04:00
|
|
|
else if (rank >= loserThreshold)
|
2010-05-30 19:20:32 -04:00
|
|
|
{
|
|
|
|
if (m_kart_status[i].m_kart_type == KT_PLAYER ||
|
|
|
|
m_kart_status[i].m_kart_type == KT_NETWORK_PLAYER)
|
|
|
|
{
|
|
|
|
humanLosers.push_back(m_kart_status[i].m_ident);
|
|
|
|
}
|
2010-02-21 18:10:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-30 19:20:32 -04:00
|
|
|
if (someHumanPlayerWon)
|
|
|
|
{
|
|
|
|
StateManager::get()->pushScreen( GrandPrixWin::getInstance() );
|
|
|
|
GrandPrixWin::getInstance()->setKarts(winners);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StateManager::get()->pushScreen( GrandPrixLose::getInstance() );
|
|
|
|
|
2010-07-17 14:17:15 -04:00
|
|
|
if (humanLosers.size() >= 1)
|
2010-05-30 19:20:32 -04:00
|
|
|
{
|
2010-07-17 14:17:15 -04:00
|
|
|
GrandPrixLose::getInstance()->setKarts( humanLosers );
|
2010-05-30 19:20:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "RaceManager::exitRace() : what's going on?? no winners and no losers??\n";
|
2010-07-17 14:17:15 -04:00
|
|
|
std::vector<std::string> karts;
|
|
|
|
karts.push_back(UserConfigParams::m_default_kart);
|
|
|
|
GrandPrixLose::getInstance()->setKarts( karts );
|
2010-05-30 19:20:32 -04:00
|
|
|
}
|
|
|
|
}
|
2008-09-07 09:25:58 -04:00
|
|
|
}
|
2009-12-01 14:49:11 -05:00
|
|
|
|
2012-02-06 20:25:56 -05:00
|
|
|
if (delete_world) World::deleteWorld();
|
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
m_track_number = 0;
|
2009-03-26 19:31:00 -04:00
|
|
|
} // exitRace
|
2008-09-07 09:25:58 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-09-09 09:43:09 -04:00
|
|
|
/** A kart has finished the race at the specified time (which can be
|
2010-02-17 06:59:51 -05:00
|
|
|
* different from World::getWorld()->getClock() in case of setting
|
|
|
|
* extrapolated arrival times). This function is only called from
|
|
|
|
* kart::finishedRace()
|
2008-09-09 09:43:09 -04:00
|
|
|
* \param kart The kart that finished the race.
|
|
|
|
* \param time Time at which the kart finished the race.
|
|
|
|
*/
|
2012-03-19 16:21:11 -04:00
|
|
|
void RaceManager::kartFinishedRace(const AbstractKart *kart, float time)
|
2008-09-07 09:25:58 -04:00
|
|
|
{
|
2008-12-19 19:37:45 -05:00
|
|
|
unsigned int id = kart->getWorldKartId();
|
2008-09-07 09:25:58 -04:00
|
|
|
int pos = kart->getPosition();
|
|
|
|
|
2008-10-22 12:05:08 -04:00
|
|
|
assert(pos-1 >= 0);
|
2008-10-24 01:03:12 -04:00
|
|
|
assert(pos-1 < (int)m_kart_status.size());
|
2008-10-22 12:05:08 -04:00
|
|
|
|
2008-12-25 13:16:49 -05:00
|
|
|
m_kart_status[id].m_last_score = m_kart_status[id].m_score;
|
2008-12-19 19:37:45 -05:00
|
|
|
m_kart_status[id].m_score += m_score_for_position[pos-1];
|
|
|
|
m_kart_status[id].m_overall_time += time;
|
|
|
|
m_kart_status[id].m_last_time = time;
|
2008-09-07 09:25:58 -04:00
|
|
|
m_num_finished_karts ++;
|
2010-02-14 19:54:28 -05:00
|
|
|
if(kart->getController()->isPlayerController()) m_num_finished_players++;
|
2010-02-17 06:59:51 -05:00
|
|
|
} // kartFinishedRace
|
2008-09-07 09:25:58 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2011-01-03 15:17:44 -05:00
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
void RaceManager::rerunRace()
|
|
|
|
{
|
|
|
|
// Subtract last score from all karts:
|
|
|
|
for(int i=0; i<m_num_karts; i++)
|
|
|
|
{
|
2008-12-25 13:16:49 -05:00
|
|
|
m_kart_status[i].m_score = m_kart_status[i].m_last_score;
|
2008-09-07 09:25:58 -04:00
|
|
|
m_kart_status[i].m_overall_time -= m_kart_status[i].m_last_time;
|
|
|
|
}
|
2013-04-03 02:05:34 -04:00
|
|
|
World::getWorld()->reset();
|
2008-09-07 09:25:58 -04:00
|
|
|
} // rerunRace
|
|
|
|
|
2011-01-03 14:25:56 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-04-01 11:42:44 -04:00
|
|
|
void RaceManager::startGP(const GrandPrixData* gp, bool from_overworld)
|
2011-01-03 14:25:56 -05:00
|
|
|
{
|
|
|
|
assert(gp != NULL);
|
|
|
|
|
|
|
|
StateManager::get()->enterGameState();
|
|
|
|
setGrandPrix(*gp);
|
|
|
|
setCoinTarget( 0 ); // Might still be set from a previous challenge
|
|
|
|
network_manager->setupPlayerKartInfo();
|
|
|
|
|
|
|
|
setMajorMode(RaceManager::MAJOR_MODE_GRAND_PRIX);
|
2012-04-01 11:42:44 -04:00
|
|
|
startNew(from_overworld);
|
2011-01-03 14:25:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2012-10-21 19:06:33 -04:00
|
|
|
/** \brief Higher-level method to start a GP without having to care about
|
|
|
|
* the exact startup sequence.
|
|
|
|
* \param trackIdent Internal name of the track to race on
|
|
|
|
* \param num_laps Number of laps to race, or -1 if number of laps is
|
|
|
|
* not relevant in current mode
|
|
|
|
*/
|
|
|
|
void RaceManager::startSingleRace(const std::string &track_ident,
|
2012-04-01 11:42:44 -04:00
|
|
|
const int num_laps,
|
|
|
|
bool from_overworld)
|
2011-01-03 14:25:56 -05:00
|
|
|
{
|
|
|
|
StateManager::get()->enterGameState();
|
2012-10-21 19:06:33 -04:00
|
|
|
setTrack(track_ident.c_str());
|
2012-05-30 21:32:27 -04:00
|
|
|
|
2011-01-03 14:25:56 -05:00
|
|
|
if (num_laps != -1) setNumLaps( num_laps );
|
|
|
|
|
|
|
|
setMajorMode(RaceManager::MAJOR_MODE_SINGLE);
|
|
|
|
|
|
|
|
setCoinTarget( 0 ); // Might still be set from a previous challenge
|
|
|
|
network_manager->setupPlayerKartInfo();
|
|
|
|
|
2012-04-01 11:42:44 -04:00
|
|
|
startNew(from_overworld);
|
2011-01-03 14:25:56 -05:00
|
|
|
}
|
|
|
|
|
2008-09-07 09:25:58 -04:00
|
|
|
/* EOF */
|