2007-05-27 16:01:53 +00:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2013-12-02 04:27:55 +00:00
|
|
|
// Copyright (C) 2006-2013 SuperTuxKart-Team
|
2007-05-27 16:01:53 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
2008-06-13 00:53:52 +00:00
|
|
|
// as published by the Free Software Foundation; either version 3
|
2007-05-27 16:01:53 +00:00
|
|
|
// 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-03 01:36:48 +00:00
|
|
|
#include "modes/world.hpp"
|
|
|
|
|
2014-02-24 17:14:42 +11:00
|
|
|
#include "achievements/achievement_info.hpp"
|
2010-04-21 17:24:02 +00:00
|
|
|
#include "audio/music_manager.hpp"
|
2008-11-07 04:34:01 +00:00
|
|
|
#include "audio/sfx_base.hpp"
|
2010-07-15 22:41:41 +00:00
|
|
|
#include "audio/sfx_manager.hpp"
|
2014-02-09 23:22:45 +11:00
|
|
|
#include "config/player_manager.hpp"
|
2009-01-22 22:27:13 +00:00
|
|
|
#include "challenges/unlock_manager.hpp"
|
2009-06-11 10:00:43 +00:00
|
|
|
#include "config/user_config.hpp"
|
2009-01-23 05:23:22 +00:00
|
|
|
#include "graphics/camera.hpp"
|
2013-03-14 21:04:48 +00:00
|
|
|
#include "graphics/irr_driver.hpp"
|
2011-07-15 23:38:40 +00:00
|
|
|
#include "graphics/hardware_skinning.hpp"
|
2009-03-12 03:49:31 +00:00
|
|
|
#include "io/file_manager.hpp"
|
2013-02-16 00:52:28 +00:00
|
|
|
#include "input/device_manager.hpp"
|
2008-11-07 04:34:01 +00:00
|
|
|
#include "items/projectile_manager.hpp"
|
2010-02-15 00:54:28 +00:00
|
|
|
#include "karts/controller/player_controller.hpp"
|
|
|
|
#include "karts/controller/end_controller.hpp"
|
2012-05-21 06:57:05 +00:00
|
|
|
#include "karts/controller/skidding_ai.hpp"
|
2013-07-31 18:03:11 +00:00
|
|
|
#include "karts/controller/network_player_controller.hpp"
|
2012-03-19 20:21:11 +00:00
|
|
|
#include "karts/kart.hpp"
|
2008-11-07 04:34:01 +00:00
|
|
|
#include "karts/kart_properties_manager.hpp"
|
2013-01-19 00:46:03 +00:00
|
|
|
#include "modes/overworld.hpp"
|
2011-10-07 09:11:34 +00:00
|
|
|
#include "modes/profile_world.hpp"
|
2009-08-19 13:48:28 +00:00
|
|
|
#include "physics/btKart.hpp"
|
2012-05-08 07:07:15 +00:00
|
|
|
#include "physics/physics.hpp"
|
2011-02-13 00:23:23 +00:00
|
|
|
#include "physics/triangle_mesh.hpp"
|
2009-06-03 01:36:48 +00:00
|
|
|
#include "race/highscore_manager.hpp"
|
|
|
|
#include "race/history.hpp"
|
|
|
|
#include "race/race_manager.hpp"
|
2012-02-28 22:33:49 +00:00
|
|
|
#include "replay/replay_play.hpp"
|
|
|
|
#include "replay/replay_recorder.hpp"
|
2012-06-24 01:39:49 +00:00
|
|
|
#include "states_screens/dialogs/race_paused_dialog.hpp"
|
2010-07-15 22:41:41 +00:00
|
|
|
#include "states_screens/race_gui_base.hpp"
|
2013-01-19 00:46:03 +00:00
|
|
|
#include "states_screens/main_menu_screen.hpp"
|
|
|
|
#include "states_screens/race_gui.hpp"
|
2010-07-15 22:41:41 +00:00
|
|
|
#include "states_screens/race_result_gui.hpp"
|
2013-01-19 00:46:03 +00:00
|
|
|
#include "states_screens/state_manager.hpp"
|
2009-01-22 22:27:13 +00:00
|
|
|
#include "tracks/track.hpp"
|
2009-01-22 12:02:40 +00:00
|
|
|
#include "tracks/track_manager.hpp"
|
2009-01-22 22:27:13 +00:00
|
|
|
#include "utils/constants.hpp"
|
2011-07-10 10:33:42 +00:00
|
|
|
#include "utils/profiler.hpp"
|
2009-01-23 05:23:22 +00:00
|
|
|
#include "utils/translation.hpp"
|
2009-01-28 00:38:28 +00:00
|
|
|
#include "utils/string_utils.hpp"
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2014-02-09 23:22:45 +11:00
|
|
|
#include <algorithm>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctime>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdexcept>
|
2014-09-12 23:22:54 +02:00
|
|
|
|
2014-02-09 23:22:45 +11:00
|
|
|
|
2010-02-11 07:11:52 +00:00
|
|
|
World* World::m_world = NULL;
|
|
|
|
|
2010-02-17 11:59:51 +00:00
|
|
|
/** The main world class is used to handle the track and the karts.
|
|
|
|
* The end of the race is detected in two phases: first the (abstract)
|
|
|
|
* function isRaceOver, which must be implemented by all game modes,
|
2013-05-29 22:04:35 +00:00
|
|
|
* must return true. In which case enterRaceOverState is called. At
|
2010-02-17 11:59:51 +00:00
|
|
|
* this time a winning (or losing) animation can be played. The WorldStatus
|
|
|
|
* class will in its enterRaceOverState switch to DELAY_FINISH_PHASE,
|
|
|
|
* but the remaining AI kart will keep on racing during that time.
|
|
|
|
* After a time period specified in stk_config.xml WorldStatus will
|
|
|
|
* switch to FINISH_PHASE and call terminateRace. Now the finishing status
|
|
|
|
* of all karts is set (i.e. in a normal race the arrival time for karts
|
|
|
|
* will be estimated), highscore is updated, and the race result gui
|
|
|
|
* is being displayed.
|
2013-07-31 18:03:11 +00:00
|
|
|
* Rescuing is handled via the three functions:
|
|
|
|
* getNumberOfRescuePositions() - which returns the number of rescue
|
2013-07-10 22:47:12 +00:00
|
|
|
* positions defined.
|
|
|
|
* getRescuePositionIndex(AbstractKart *kart) - which determines the
|
|
|
|
* index of the rescue position to be used for the given kart.
|
|
|
|
* getRescueTransform(unsigned int index) - which returns the transform
|
|
|
|
* (i.e. position and rotation) for the specified rescue
|
|
|
|
* position.
|
|
|
|
* This allows the world class to do some tests to make sure all rescue
|
|
|
|
* positions are valid (when started with --track-debug). It tries to
|
|
|
|
* place all karts on all rescue positions. If there are any problems
|
|
|
|
* (e.g. a rescue position not over terrain (perhaps because it is too
|
|
|
|
* low); or the rescue position is on a texture which will immediately
|
|
|
|
* trigger another rescue), a warning message will be printed.
|
2010-02-17 11:59:51 +00:00
|
|
|
*/
|
2013-07-10 22:47:12 +00:00
|
|
|
|
2008-09-20 23:45:22 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2009-08-21 00:32:24 +00:00
|
|
|
/** Constructor. Note that in the constructor it is not possible to call any
|
2010-02-17 11:59:51 +00:00
|
|
|
* functions that use World::getWorld(), since this is only defined
|
2013-05-29 22:04:35 +00:00
|
|
|
* after the constructor. Those functions must be called in the init()
|
2009-08-21 00:32:24 +00:00
|
|
|
* function, which is called immediately after the constructor.
|
|
|
|
*/
|
2010-03-27 19:19:09 +00:00
|
|
|
World::World() : WorldStatus(), m_clear_color(255,100,101,140)
|
2008-11-08 02:07:54 +00:00
|
|
|
{
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-04-04 23:09:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
m_magic_number = 0xB01D6543;
|
|
|
|
#endif
|
|
|
|
|
2011-12-20 22:01:45 +00:00
|
|
|
m_physics = NULL;
|
|
|
|
m_race_gui = NULL;
|
|
|
|
m_saved_race_gui = NULL;
|
|
|
|
m_use_highscores = true;
|
|
|
|
m_track = NULL;
|
|
|
|
m_schedule_pause = false;
|
|
|
|
m_schedule_unpause = false;
|
2013-01-19 00:46:03 +00:00
|
|
|
m_schedule_exit_race = false;
|
2012-02-07 01:25:56 +00:00
|
|
|
m_self_destruct = false;
|
2013-02-16 00:52:28 +00:00
|
|
|
m_schedule_tutorial = false;
|
2013-08-21 13:54:50 +00:00
|
|
|
m_is_network_world = false;
|
2014-09-01 20:17:38 +02:00
|
|
|
m_weather = NULL;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2012-11-22 01:07:09 +00:00
|
|
|
m_stop_music_when_dialog_open = true;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-02-09 09:24:45 +00:00
|
|
|
WorldStatus::setClockMode(CLOCK_CHRONO);
|
2013-04-16 11:37:25 +00:00
|
|
|
|
2009-07-12 11:54:21 +00:00
|
|
|
} // World
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2013-05-29 22:04:35 +00:00
|
|
|
/** This function is called after instanciating. The code here can't be moved
|
|
|
|
* to the contructor as child classes must be instanciated, otherwise
|
|
|
|
* polymorphism will fail and the results will be incorrect . Also in init()
|
|
|
|
* functions can be called that use World::getWorld().
|
2009-08-21 00:32:24 +00:00
|
|
|
*/
|
2008-11-08 02:07:54 +00:00
|
|
|
void World::init()
|
2007-05-27 16:01:53 +00:00
|
|
|
{
|
2008-05-08 01:28:07 +00:00
|
|
|
m_faster_music_active = false;
|
|
|
|
m_fastest_kart = 0;
|
|
|
|
m_eliminated_karts = 0;
|
|
|
|
m_eliminated_players = 0;
|
2010-02-11 07:11:52 +00:00
|
|
|
m_num_players = 0;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2009-07-30 02:40:30 +00:00
|
|
|
// Create the race gui before anything else is attached to the scene node
|
2009-08-18 10:59:21 +00:00
|
|
|
// (which happens when the track is loaded). This allows the race gui to
|
2013-04-16 11:37:25 +00:00
|
|
|
// do any rendering on texture. Note that this function can NOT be called
|
|
|
|
// in the World constuctor, since it might be overwritten by a the game
|
|
|
|
// mode class, which would not have been constructed at the time that this
|
|
|
|
// constructor is called, so the wrong race gui would be created.
|
2011-12-31 22:07:49 +00:00
|
|
|
createRaceGUI();
|
2009-07-27 11:56:09 +00:00
|
|
|
|
2007-05-27 16:01:53 +00:00
|
|
|
// Grab the track file
|
2010-10-26 06:14:46 +00:00
|
|
|
m_track = track_manager->getTrack(race_manager->getTrackName());
|
|
|
|
if(!m_track)
|
2007-05-27 16:01:53 +00:00
|
|
|
{
|
2009-01-23 05:23:22 +00:00
|
|
|
std::ostringstream msg;
|
2013-05-29 22:04:35 +00:00
|
|
|
msg << "Track '" << race_manager->getTrackName()
|
2010-10-26 06:14:46 +00:00
|
|
|
<< "' not found.\n";
|
2009-01-23 05:23:22 +00:00
|
|
|
throw std::runtime_error(msg.str());
|
2007-05-27 16:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the physics
|
2008-09-19 06:07:29 +00:00
|
|
|
m_physics = new Physics();
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2010-02-10 11:40:33 +00:00
|
|
|
unsigned int num_karts = race_manager->getNumberOfKarts();
|
2012-05-31 01:32:27 +00:00
|
|
|
//assert(num_karts > 0);
|
2007-05-27 16:01:53 +00:00
|
|
|
|
|
|
|
// Load the track models - this must be done before the karts so that the
|
|
|
|
// karts can be positioned properly on (and not in) the tracks.
|
2012-12-17 00:33:47 +00:00
|
|
|
m_track->loadTrackModel(race_manager->getReverseTrack());
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2010-02-10 11:40:33 +00:00
|
|
|
for(unsigned int i=0; i<num_karts; i++)
|
2007-05-27 16:01:53 +00:00
|
|
|
{
|
2013-05-29 22:04:35 +00:00
|
|
|
std::string kart_ident = history->replayHistory()
|
2012-02-27 05:52:17 +00:00
|
|
|
? history->getKartIdent(i)
|
|
|
|
: race_manager->getKartIdent(i);
|
|
|
|
int local_player_id = race_manager->getKartLocalPlayerId(i);
|
|
|
|
int global_player_id = race_manager->getKartGlobalPlayerId(i);
|
2013-05-29 22:04:35 +00:00
|
|
|
AbstractKart* newkart = createKart(kart_ident, i, local_player_id,
|
|
|
|
global_player_id,
|
2012-02-27 05:52:17 +00:00
|
|
|
race_manager->getKartType(i));
|
2010-02-10 22:59:17 +00:00
|
|
|
m_karts.push_back(newkart);
|
2010-04-09 13:00:40 +00:00
|
|
|
m_track->adjustForFog(newkart->getNode());
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2007-05-27 16:01:53 +00:00
|
|
|
} // for i
|
2013-04-16 11:37:25 +00:00
|
|
|
|
2013-12-02 04:27:55 +00:00
|
|
|
// Now that all models are loaded, apply the overrides
|
|
|
|
irr_driver->applyObjectPassShader();
|
|
|
|
|
2013-04-16 11:37:25 +00:00
|
|
|
// Must be called after all karts are created
|
|
|
|
m_race_gui->init();
|
|
|
|
|
2012-02-28 22:33:49 +00:00
|
|
|
if(ReplayPlay::get())
|
|
|
|
ReplayPlay::get()->Load();
|
2012-02-27 05:52:17 +00:00
|
|
|
|
2010-04-30 01:11:22 +00:00
|
|
|
powerup_manager->updateWeightsForRace(num_karts);
|
2014-08-30 18:08:23 +02:00
|
|
|
|
2014-09-01 19:57:32 +02:00
|
|
|
if (UserConfigParams::m_weather_effects)
|
2014-08-30 18:08:23 +02:00
|
|
|
{
|
2014-09-01 20:17:38 +02:00
|
|
|
m_weather = new Weather(m_track->getWeatherLightning(),
|
2014-09-01 19:57:32 +02:00
|
|
|
m_track->getWeatherSound());
|
2014-08-30 18:08:23 +02:00
|
|
|
}
|
2013-04-03 06:05:34 +00:00
|
|
|
} // init
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-05-29 22:04:35 +00:00
|
|
|
/** This function is called before a race is started (i.e. either after
|
2013-04-03 06:05:34 +00:00
|
|
|
* calling init() when starting a race for the first time, or after
|
|
|
|
* restarting a race, in which case no init() is called.
|
|
|
|
*/
|
|
|
|
void World::reset()
|
|
|
|
{
|
|
|
|
// If m_saved_race_gui is set, it means that the restart was done
|
2013-05-29 22:04:35 +00:00
|
|
|
// when the race result gui was being shown. In this case restore the
|
2013-04-03 06:05:34 +00:00
|
|
|
// race gui (note that the race result gui is cached and so never really
|
|
|
|
// destroyed).
|
|
|
|
if(m_saved_race_gui)
|
|
|
|
{
|
|
|
|
m_race_gui = m_saved_race_gui;
|
|
|
|
m_saved_race_gui = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_schedule_pause = false;
|
|
|
|
m_schedule_unpause = false;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-04-03 06:05:34 +00:00
|
|
|
WorldStatus::reset();
|
|
|
|
m_faster_music_active = false;
|
|
|
|
m_eliminated_karts = 0;
|
|
|
|
m_eliminated_players = 0;
|
2013-08-29 17:57:56 +00:00
|
|
|
m_is_network_world = false;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-04-03 06:05:34 +00:00
|
|
|
for ( KartList::iterator i = m_karts.begin(); i != m_karts.end() ; ++i )
|
|
|
|
{
|
|
|
|
(*i)->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int i=0; i<Camera::getNumCameras(); i++)
|
|
|
|
{
|
|
|
|
Camera::getCamera(i)->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ReplayPlay::get())
|
|
|
|
ReplayPlay::get()->reset();
|
|
|
|
|
|
|
|
resetAllKarts();
|
|
|
|
// Note: track reset must be called after all karts exist, since check
|
|
|
|
// objects need to allocate data structures depending on the number
|
|
|
|
// of karts.
|
|
|
|
m_track->reset();
|
|
|
|
|
2013-04-16 11:37:25 +00:00
|
|
|
// Reset the race gui.
|
|
|
|
m_race_gui->reset();
|
|
|
|
|
2013-04-03 06:05:34 +00:00
|
|
|
// Start music from beginning
|
|
|
|
music_manager->stopMusic();
|
|
|
|
|
|
|
|
// Enable SFX again
|
2014-09-17 21:38:21 +10:00
|
|
|
SFXManager::get()->resumeAll();
|
2013-04-03 06:05:34 +00:00
|
|
|
|
|
|
|
projectile_manager->cleanup();
|
|
|
|
race_manager->reset();
|
|
|
|
// Make sure to overwrite the data from the previous race.
|
|
|
|
if(!history->replayHistory()) history->initRecording();
|
|
|
|
if(ReplayRecorder::get()) ReplayRecorder::get()->init();
|
|
|
|
|
2013-03-14 21:04:48 +00:00
|
|
|
// Reset all data structures that depend on number of karts.
|
|
|
|
irr_driver->reset();
|
2013-04-03 06:05:34 +00:00
|
|
|
|
2013-05-03 06:48:47 +00:00
|
|
|
//Reset the Rubber Ball Collect Time to some negative value.
|
|
|
|
powerup_manager->setBallCollectTime(-100);
|
2013-04-03 06:05:34 +00:00
|
|
|
} // reset
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2011-12-31 22:07:49 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void World::createRaceGUI()
|
|
|
|
{
|
2013-12-02 04:27:55 +00:00
|
|
|
m_race_gui = new RaceGUI();
|
2011-12-31 22:07:49 +00:00
|
|
|
}
|
|
|
|
|
2007-05-27 16:01:53 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2009-08-19 04:03:25 +00:00
|
|
|
/** Creates a kart, having a certain position, starting location, and local
|
|
|
|
* and global player id (if applicable).
|
|
|
|
* \param kart_ident Identifier of the kart to create.
|
|
|
|
* \param index Index of the kart.
|
|
|
|
* \param local_player_id If the kart is a player kart this is the index of
|
|
|
|
* this player on the local machine.
|
2009-11-29 13:04:57 +00:00
|
|
|
* \param global_player_id If the kart is a player kart this is the index of
|
2009-08-19 04:03:25 +00:00
|
|
|
* this player globally (i.e. including network players).
|
|
|
|
*/
|
2012-03-19 20:21:11 +00:00
|
|
|
AbstractKart *World::createKart(const std::string &kart_ident, int index,
|
|
|
|
int local_player_id, int global_player_id,
|
|
|
|
RaceManager::KartType kart_type)
|
2009-08-19 04:03:25 +00:00
|
|
|
{
|
2010-09-23 23:18:53 +00:00
|
|
|
int position = index+1;
|
2010-10-11 21:49:35 +00:00
|
|
|
btTransform init_pos = m_track->getStartTransform(index);
|
2012-03-19 20:21:11 +00:00
|
|
|
AbstractKart *new_kart = new Kart(kart_ident, index, position, init_pos);
|
2013-03-06 22:08:41 +00:00
|
|
|
new_kart->init(race_manager->getKartType(index));
|
2010-02-15 00:54:28 +00:00
|
|
|
Controller *controller = NULL;
|
2012-02-27 05:52:17 +00:00
|
|
|
switch(kart_type)
|
2009-08-19 04:03:25 +00:00
|
|
|
{
|
|
|
|
case RaceManager::KT_PLAYER:
|
2013-05-29 22:04:35 +00:00
|
|
|
controller = new PlayerController(new_kart,
|
2011-09-21 00:43:43 +00:00
|
|
|
StateManager::get()->getActivePlayer(local_player_id),
|
2010-02-15 00:54:28 +00:00
|
|
|
local_player_id);
|
2010-02-11 07:11:52 +00:00
|
|
|
m_num_players ++;
|
2009-08-19 04:03:25 +00:00
|
|
|
break;
|
2010-02-20 02:43:57 +00:00
|
|
|
case RaceManager::KT_NETWORK_PLAYER:
|
2013-07-31 18:03:11 +00:00
|
|
|
controller = new NetworkPlayerController(new_kart,
|
|
|
|
StateManager::get()->getActivePlayer(local_player_id));
|
|
|
|
m_num_players++;
|
|
|
|
break;
|
2009-08-19 04:03:25 +00:00
|
|
|
case RaceManager::KT_AI:
|
2010-09-23 23:18:53 +00:00
|
|
|
controller = loadAIController(new_kart);
|
2009-08-19 04:03:25 +00:00
|
|
|
break;
|
|
|
|
case RaceManager::KT_GHOST:
|
|
|
|
break;
|
|
|
|
case RaceManager::KT_LEADER:
|
|
|
|
break;
|
|
|
|
}
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2011-01-16 01:28:25 +00:00
|
|
|
new_kart->setController(controller);
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-02-15 00:54:28 +00:00
|
|
|
return new_kart;
|
2009-08-19 04:03:25 +00:00
|
|
|
} // createKart
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-15 00:54:28 +00:00
|
|
|
/** Creates an AI controller for the kart.
|
|
|
|
* \param kart The kart to be controlled by an AI.
|
|
|
|
*/
|
2012-03-19 20:21:11 +00:00
|
|
|
Controller* World::loadAIController(AbstractKart *kart)
|
2009-08-19 04:03:25 +00:00
|
|
|
{
|
2010-02-15 00:54:28 +00:00
|
|
|
Controller *controller;
|
2012-10-23 21:46:44 +00:00
|
|
|
int turn=0;
|
|
|
|
// If different AIs should be used, adjust turn (or switch randomly
|
|
|
|
// or dependent on difficulty)
|
2009-11-08 12:19:33 +00:00
|
|
|
switch(turn)
|
2009-08-19 04:03:25 +00:00
|
|
|
{
|
|
|
|
case 0:
|
2012-05-21 06:57:05 +00:00
|
|
|
controller = new SkiddingAI(kart);
|
2009-08-19 04:03:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-02-07 02:17:49 +04:00
|
|
|
Log::warn("[World]", "Unknown AI, using default.");
|
2012-10-23 21:46:44 +00:00
|
|
|
controller = new SkiddingAI(kart);
|
2009-08-19 04:03:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-15 00:54:28 +00:00
|
|
|
return controller;
|
|
|
|
} // loadAIController
|
2009-08-19 04:03:25 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-08-21 00:32:24 +00:00
|
|
|
World::~World()
|
2007-05-27 16:01:53 +00:00
|
|
|
{
|
2014-05-16 19:30:39 -04:00
|
|
|
irr_driver->onUnloadWorld();
|
|
|
|
|
2012-05-20 00:29:03 +00:00
|
|
|
if(ReplayPlay::get())
|
|
|
|
{
|
|
|
|
// Destroy the old replay object, which also stored the ghost
|
|
|
|
// karts, and create a new one (which means that in further
|
|
|
|
// races the usage of ghosts will still be enabled).
|
|
|
|
ReplayPlay::destroy();
|
|
|
|
ReplayPlay::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-03 07:14:04 +00:00
|
|
|
// In case that a race is aborted (e.g. track not found) m_track is 0.
|
|
|
|
if(m_track)
|
|
|
|
m_track->cleanup();
|
|
|
|
|
2010-08-24 23:19:14 +00:00
|
|
|
// Delete the in-race-gui:
|
|
|
|
if(m_saved_race_gui)
|
|
|
|
{
|
|
|
|
// If there is a save race gui, this means that the result gui is
|
|
|
|
// currently being shown. The race result gui is a screen and so
|
|
|
|
// is deleted by the state manager. So we only have to delete
|
|
|
|
// the actual race gui:
|
|
|
|
delete m_saved_race_gui;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No race result gui is shown, so m_race_gui is the in-race
|
|
|
|
// gui and this must be deleted.
|
|
|
|
delete m_race_gui;
|
|
|
|
}
|
2014-08-30 18:08:23 +02:00
|
|
|
|
2014-09-01 20:17:38 +02:00
|
|
|
if (m_weather != NULL)
|
|
|
|
delete m_weather;
|
2007-12-08 13:04:56 +00:00
|
|
|
|
2010-02-10 22:59:17 +00:00
|
|
|
for ( unsigned int i = 0 ; i < m_karts.size() ; i++ )
|
|
|
|
delete m_karts[i];
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2010-02-10 22:59:17 +00:00
|
|
|
m_karts.clear();
|
2013-03-06 22:08:41 +00:00
|
|
|
Camera::removeAllCameras();
|
|
|
|
|
2007-05-27 16:01:53 +00:00
|
|
|
projectile_manager->cleanup();
|
2009-01-15 23:05:50 +00:00
|
|
|
// In case that the track is not found, m_physics is still undefined.
|
|
|
|
if(m_physics)
|
|
|
|
delete m_physics;
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2010-04-21 17:24:02 +00:00
|
|
|
music_manager->stopMusic();
|
2010-02-11 07:11:52 +00:00
|
|
|
m_world = NULL;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2014-08-20 20:38:05 -04:00
|
|
|
irr_driver->getSceneManager()->clear();
|
|
|
|
|
2013-04-04 23:09:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
m_magic_number = 0xDEADBEEF;
|
|
|
|
#endif
|
|
|
|
|
2007-11-03 13:13:26 +00:00
|
|
|
} // ~World
|
2009-07-12 11:54:21 +00:00
|
|
|
|
2010-02-08 12:59:03 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Called when 'go' is being displayed for the first time. Here the brakes
|
|
|
|
* of the karts are released.
|
|
|
|
*/
|
|
|
|
void World::onGo()
|
|
|
|
{
|
2013-05-29 22:04:35 +00:00
|
|
|
// Reset the brakes now that the prestart
|
|
|
|
// phase is over (braking prevents the karts
|
2010-02-08 12:59:03 +00:00
|
|
|
// from sliding downhill)
|
2013-05-29 22:04:35 +00:00
|
|
|
for(unsigned int i=0; i<m_karts.size(); i++)
|
2010-02-08 12:59:03 +00:00
|
|
|
{
|
2012-01-04 21:58:33 +00:00
|
|
|
m_karts[i]->getVehicle()->setAllBrakes(0);
|
2010-02-08 12:59:03 +00:00
|
|
|
}
|
|
|
|
} // onGo
|
|
|
|
|
2008-09-20 23:45:22 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-09 09:24:45 +00:00
|
|
|
/** Called at the end of a race. Updates highscores, pauses the game, and
|
2010-02-17 11:59:51 +00:00
|
|
|
* informs the unlock manager about the finished race. This function must
|
|
|
|
* be called after all other stats were updated from the different game
|
|
|
|
* modes.
|
2010-02-09 09:24:45 +00:00
|
|
|
*/
|
2008-09-20 23:45:22 +00:00
|
|
|
void World::terminateRace()
|
|
|
|
{
|
2010-10-12 22:32:33 +00:00
|
|
|
m_schedule_pause = false;
|
|
|
|
m_schedule_unpause = false;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-02-17 11:59:51 +00:00
|
|
|
// Update the estimated finishing time for all karts that haven't
|
|
|
|
// finished yet.
|
|
|
|
const unsigned int kart_amount = getNumKarts();
|
|
|
|
for(unsigned int i = 0; i < kart_amount ; i++)
|
|
|
|
{
|
|
|
|
if(!m_karts[i]->hasFinishedRace() && !m_karts[i]->isEliminated())
|
|
|
|
{
|
|
|
|
m_karts[i]->finishedRace(estimateFinishTimeForKart(m_karts[i]));
|
|
|
|
|
|
|
|
}
|
|
|
|
} // i<kart_amount
|
2013-05-29 22:04:35 +00:00
|
|
|
|
|
|
|
// Update highscores, and retrieve the best highscore if relevant
|
2011-09-21 00:43:43 +00:00
|
|
|
// to show it in the GUI
|
2011-05-24 01:34:02 +00:00
|
|
|
int best_highscore_rank = -1;
|
|
|
|
int best_finish_time = -1;
|
|
|
|
std::string highscore_who = "";
|
2011-05-25 01:53:15 +00:00
|
|
|
StateManager::ActivePlayer* best_player = NULL;
|
2013-08-21 19:04:46 +00:00
|
|
|
if (!this->isNetworkWorld())
|
|
|
|
{
|
|
|
|
updateHighscores(&best_highscore_rank, &best_finish_time, &highscore_who,
|
2011-09-21 00:43:43 +00:00
|
|
|
&best_player);
|
2013-08-21 19:04:46 +00:00
|
|
|
}
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2014-03-15 15:08:18 +01:00
|
|
|
// Check achievements
|
2014-02-24 17:14:42 +11:00
|
|
|
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_COLUMBUS,
|
|
|
|
getTrack()->getIdent(), 1);
|
2014-03-12 14:01:40 +01:00
|
|
|
if (raceHasLaps())
|
|
|
|
{
|
|
|
|
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_MARATHONER,
|
|
|
|
"laps", race_manager->getNumLaps());
|
|
|
|
}
|
2014-03-29 11:32:04 +01:00
|
|
|
|
2014-03-15 15:08:18 +01:00
|
|
|
Achievement *achiev = PlayerManager::getCurrentAchievementsStatus()->getAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER);
|
|
|
|
if (achiev)
|
|
|
|
{
|
2014-03-17 08:21:49 +01:00
|
|
|
std::string mode_name = getIdent(); // Get the race mode name
|
|
|
|
int winner_position = 1;
|
2014-03-25 20:54:20 +11:00
|
|
|
unsigned int opponents = achiev->getInfo()->getGoalValue("opponents"); // Get the required opponents number
|
2014-03-17 08:21:49 +01:00
|
|
|
if (mode_name == IDENT_FTL)
|
2014-03-15 15:08:18 +01:00
|
|
|
{
|
2014-03-17 08:21:49 +01:00
|
|
|
winner_position = 2;
|
2014-03-15 15:08:18 +01:00
|
|
|
opponents++;
|
|
|
|
}
|
2014-03-17 08:21:49 +01:00
|
|
|
for(unsigned int i = 0; i < kart_amount; i++)
|
2014-03-15 15:08:18 +01:00
|
|
|
{
|
|
|
|
// Retrieve the current player
|
|
|
|
StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer();
|
2014-04-08 08:06:52 +10:00
|
|
|
if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer())
|
2014-03-15 15:08:18 +01:00
|
|
|
{
|
|
|
|
// Check if the player has won
|
2014-03-17 08:21:49 +01:00
|
|
|
if (m_karts[i]->getPosition() == winner_position && kart_amount > opponents )
|
2014-03-15 15:08:18 +01:00
|
|
|
{
|
|
|
|
// Update the achievement
|
2014-03-17 08:21:49 +01:00
|
|
|
mode_name = StringUtils::toLowerCase(mode_name);
|
2014-03-15 15:08:18 +01:00
|
|
|
if (achiev->getValue("opponents") <= 0)
|
|
|
|
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER,
|
|
|
|
"opponents", opponents);
|
|
|
|
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_GOLD_DRIVER,
|
2014-03-17 08:21:49 +01:00
|
|
|
mode_name, 1);
|
2014-03-15 15:08:18 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-29 11:33:43 +01:00
|
|
|
} // for i < kart_amount
|
2014-03-15 15:08:18 +01:00
|
|
|
} // if (achiev)
|
2014-03-29 11:32:04 +01:00
|
|
|
|
2014-03-20 15:30:11 +02:00
|
|
|
Achievement *win = PlayerManager::getCurrentAchievementsStatus()->getAchievement(AchievementInfo::ACHIEVE_UNSTOPPABLE);
|
|
|
|
//if achivement has been unlocked
|
|
|
|
if (win->getValue("wins") < 5 )
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < kart_amount; i++)
|
|
|
|
{
|
|
|
|
// Retrieve the current player
|
|
|
|
StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer();
|
2014-04-08 08:06:52 +10:00
|
|
|
if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer())
|
2014-03-20 15:30:11 +02:00
|
|
|
{
|
|
|
|
// Check if the player has won
|
|
|
|
if (m_karts[i]->getPosition() == 1 )
|
|
|
|
{
|
|
|
|
// Increase number of consecutive wins
|
|
|
|
PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_UNSTOPPABLE,
|
|
|
|
"wins", 1);
|
|
|
|
}
|
|
|
|
else
|
2014-03-29 11:33:43 +01:00
|
|
|
{
|
2014-03-20 15:30:11 +02:00
|
|
|
//Set number of consecutive wins to 0
|
|
|
|
win->reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-08 08:06:52 +10:00
|
|
|
PlayerManager::getCurrentPlayer()->raceFinished();
|
2013-09-06 00:06:59 +00:00
|
|
|
|
2010-07-15 22:41:41 +00:00
|
|
|
if (m_race_gui) m_race_gui->clearAllMessages();
|
2013-05-29 22:04:35 +00:00
|
|
|
// we can't delete the race gui here, since it is needed in case of
|
|
|
|
// a restart: the constructor of it creates some textures which assume
|
|
|
|
// that no scene nodes exist. In case of a restart there are scene nodes,
|
|
|
|
// so we can't create the race gui again, so we keep it around
|
2010-07-19 00:14:06 +00:00
|
|
|
// and save the pointer.
|
|
|
|
assert(m_saved_race_gui==NULL);
|
|
|
|
m_saved_race_gui = m_race_gui;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2011-05-24 01:34:02 +00:00
|
|
|
RaceResultGUI* results = RaceResultGUI::getInstance();
|
|
|
|
m_race_gui = results;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2011-05-24 01:34:02 +00:00
|
|
|
if (best_highscore_rank > 0)
|
|
|
|
{
|
2011-09-21 00:43:43 +00:00
|
|
|
results->setHighscore(highscore_who, best_player, best_highscore_rank,
|
|
|
|
best_finish_time);
|
2011-05-24 01:34:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
results->clearHighscores();
|
|
|
|
}
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2014-09-23 16:43:50 +10:00
|
|
|
results->push();
|
2010-02-17 11:59:51 +00:00
|
|
|
WorldStatus::terminateRace();
|
2010-02-08 12:59:03 +00:00
|
|
|
} // terminateRace
|
|
|
|
|
2007-05-27 16:01:53 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Waits till each kart is resting on the ground
|
|
|
|
*
|
|
|
|
* Does simulation steps still all karts reach the ground, i.e. are not
|
|
|
|
* moving anymore
|
|
|
|
*/
|
|
|
|
void World::resetAllKarts()
|
|
|
|
{
|
2011-12-01 01:14:10 +00:00
|
|
|
// Reset the physics 'remaining' time to 0 so that the number
|
|
|
|
// of timesteps is reproducible if doing a physics-based history run
|
|
|
|
getPhysics()->getPhysicsWorld()->resetLocalTime();
|
|
|
|
|
2010-12-15 22:50:17 +00:00
|
|
|
// If track checking is requested, check all rescue positions if
|
|
|
|
// they are heigh enough.
|
2013-07-10 22:47:12 +00:00
|
|
|
if(UserConfigParams::m_track_debug)
|
2010-12-15 22:50:17 +00:00
|
|
|
{
|
2013-07-10 22:47:12 +00:00
|
|
|
// Loop over all karts, in case that some karts are dfferent
|
2014-09-23 14:41:32 +10:00
|
|
|
for(unsigned int kart_id=0; kart_id<(unsigned int)m_karts.size(); kart_id++)
|
2010-12-15 22:50:17 +00:00
|
|
|
{
|
2013-07-31 18:03:11 +00:00
|
|
|
for(unsigned int rescue_pos=0;
|
2013-07-10 22:47:12 +00:00
|
|
|
rescue_pos<getNumberOfRescuePositions();
|
|
|
|
rescue_pos++)
|
2010-12-15 22:50:17 +00:00
|
|
|
{
|
2013-07-10 22:47:12 +00:00
|
|
|
btTransform t = getRescueTransform(rescue_pos);
|
|
|
|
// This will print out warnings if there is no terrain under
|
|
|
|
// the kart, or the kart is being dropped on a reset texture
|
|
|
|
moveKartTo(m_karts[kart_id], t);
|
2010-12-15 22:50:17 +00:00
|
|
|
|
2013-07-10 22:47:12 +00:00
|
|
|
} // rescue_pos<getNumberOfRescuePositions
|
2010-12-15 22:50:17 +00:00
|
|
|
|
|
|
|
// Reset the karts back to the original start position.
|
|
|
|
// This call is a bit of an overkill, but setting the correct
|
|
|
|
// transforms, positions, motion state is a bit of a hassle.
|
|
|
|
m_karts[kart_id]->reset();
|
2013-07-10 22:47:12 +00:00
|
|
|
} // for kart_id<m_karts.size()
|
2010-12-15 22:50:17 +00:00
|
|
|
|
|
|
|
|
2013-07-10 22:47:12 +00:00
|
|
|
} // if m_track_debug
|
2010-12-15 22:50:17 +00:00
|
|
|
|
2010-10-12 22:32:33 +00:00
|
|
|
m_schedule_pause = false;
|
|
|
|
m_schedule_unpause = false;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2009-08-18 11:05:40 +00:00
|
|
|
//Project karts onto track from above. This will lower each kart so
|
|
|
|
//that at least one of its wheel will be on the surface of the track
|
2010-02-10 22:59:17 +00:00
|
|
|
for ( KartList::iterator i=m_karts.begin(); i!=m_karts.end(); i++)
|
2009-08-18 11:05:40 +00:00
|
|
|
{
|
2013-06-28 23:45:48 +00:00
|
|
|
Vec3 xyz = (*i)->getXYZ();
|
|
|
|
//start projection from top of kart
|
|
|
|
Vec3 up_offset(0, 0.5f * ((*i)->getKartHeight()), 0);
|
|
|
|
(*i)->setXYZ(xyz+up_offset);
|
2009-08-19 13:45:44 +00:00
|
|
|
|
2013-06-06 23:08:52 +00:00
|
|
|
bool kart_over_ground = m_track->findGround(*i);
|
2009-08-18 11:05:40 +00:00
|
|
|
|
|
|
|
if (!kart_over_ground)
|
|
|
|
{
|
2014-02-07 02:17:49 +04:00
|
|
|
Log::error("[World]",
|
2013-07-10 22:47:12 +00:00
|
|
|
"No valid starting position for kart %d on track %s.",
|
|
|
|
(int)(i-m_karts.begin()), m_track->getIdent().c_str());
|
2011-03-02 00:04:13 +00:00
|
|
|
if (UserConfigParams::m_artist_debug_mode)
|
|
|
|
{
|
2014-02-07 02:17:49 +04:00
|
|
|
Log::warn("[World]", "Activating fly mode.");
|
2011-03-02 00:04:13 +00:00
|
|
|
(*i)->flyUp();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exit(-1);
|
|
|
|
}
|
2009-08-18 11:05:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-27 16:01:53 +00:00
|
|
|
bool all_finished=false;
|
2008-02-13 03:42:18 +00:00
|
|
|
// kart->isInRest() is not fully correct, since it only takes the
|
|
|
|
// velocity in count, which might be close to zero when the kart
|
|
|
|
// is just hitting the floor, before being pushed up again by
|
|
|
|
// the suspension. So we just do a longer initial simulation,
|
|
|
|
// which should be long enough for all karts to be firmly on ground.
|
2009-08-18 11:05:40 +00:00
|
|
|
for(int i=0; i<60; i++) m_physics->update(1.f/60.f);
|
2008-07-10 00:41:26 +00:00
|
|
|
|
|
|
|
// Stil wait will all karts are in rest (and handle the case that a kart
|
|
|
|
// fell through the ground, which can happen if a kart falls for a long
|
|
|
|
// time, therefore having a high speed when hitting the ground.
|
2014-05-10 19:26:14 -04:00
|
|
|
int count = 0;
|
2007-05-27 16:01:53 +00:00
|
|
|
while(!all_finished)
|
|
|
|
{
|
2014-05-10 19:26:14 -04:00
|
|
|
if (count++ > 100)
|
|
|
|
{
|
2014-06-25 09:31:10 +10:00
|
|
|
Log::error("World", "Infinite loop waiting for all_finished?");
|
2014-05-10 19:26:14 -04:00
|
|
|
break;
|
|
|
|
}
|
2007-11-22 01:20:57 +00:00
|
|
|
m_physics->update(1.f/60.f);
|
2007-05-27 16:01:53 +00:00
|
|
|
all_finished=true;
|
2010-02-10 22:59:17 +00:00
|
|
|
for ( KartList::iterator i=m_karts.begin(); i!=m_karts.end(); i++)
|
2007-05-27 16:01:53 +00:00
|
|
|
{
|
2009-08-18 10:59:21 +00:00
|
|
|
if(!(*i)->isInRest())
|
2007-05-27 16:01:53 +00:00
|
|
|
{
|
2008-07-10 00:41:26 +00:00
|
|
|
Vec3 normal;
|
2011-02-09 21:56:44 +00:00
|
|
|
Vec3 hit_point;
|
2008-07-10 00:41:26 +00:00
|
|
|
const Material *material;
|
2009-08-18 10:59:21 +00:00
|
|
|
// We can't use (*i)->getXYZ(), since this is only defined
|
2008-07-10 00:41:26 +00:00
|
|
|
// after update() was called. Instead we have to get the
|
|
|
|
// real position of the rigid body.
|
|
|
|
btTransform t;
|
|
|
|
(*i)->getBody()->getMotionState()->getWorldTransform(t);
|
2009-08-18 10:59:21 +00:00
|
|
|
// This test can not be done only once before the loop, since
|
2008-07-10 00:41:26 +00:00
|
|
|
// it can happen that the kart falls through the track later!
|
2011-02-13 00:23:23 +00:00
|
|
|
Vec3 to = t.getOrigin()+Vec3(0, -10000, 0);
|
2013-05-29 22:04:35 +00:00
|
|
|
m_track->getTriangleMesh().castRay(t.getOrigin(), to,
|
2011-02-13 00:23:23 +00:00
|
|
|
&hit_point, &material,
|
|
|
|
&normal);
|
2008-07-10 00:41:26 +00:00
|
|
|
if(!material)
|
|
|
|
{
|
2014-02-07 02:17:49 +04:00
|
|
|
Log::error("[World]",
|
2013-07-10 22:47:12 +00:00
|
|
|
"No valid starting position for kart %d "
|
|
|
|
"on track %s.",
|
|
|
|
(int)(i-m_karts.begin()),
|
|
|
|
m_track->getIdent().c_str());
|
2011-03-02 00:04:13 +00:00
|
|
|
if (UserConfigParams::m_artist_debug_mode)
|
|
|
|
{
|
2014-02-07 02:17:49 +04:00
|
|
|
Log::warn("[World]", "Activating fly mode.");
|
2011-03-02 00:04:13 +00:00
|
|
|
(*i)->flyUp();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exit(-1);
|
|
|
|
}
|
2008-07-10 00:41:26 +00:00
|
|
|
}
|
2007-05-27 16:01:53 +00:00
|
|
|
all_finished=false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // while
|
2008-01-30 04:36:00 +00:00
|
|
|
|
2010-02-10 22:59:17 +00:00
|
|
|
for ( KartList::iterator i=m_karts.begin(); i!=m_karts.end(); i++)
|
2011-09-26 22:11:30 +00:00
|
|
|
{
|
2014-08-20 22:19:26 +10:00
|
|
|
(*i)->kartIsInRestNow();
|
2011-09-26 22:11:30 +00:00
|
|
|
}
|
2013-03-06 22:08:41 +00:00
|
|
|
|
|
|
|
// Initialise the cameras, now that the correct kart positions are set
|
|
|
|
for(unsigned int i=0; i<Camera::getNumCameras(); i++)
|
|
|
|
{
|
|
|
|
Camera::getCamera(i)->setInitialTransform();
|
|
|
|
}
|
2007-05-27 16:01:53 +00:00
|
|
|
} // resetAllKarts
|
|
|
|
|
2013-07-10 22:47:12 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Places a kart that is rescued. It calls getRescuePositionIndex to find
|
|
|
|
* to which rescue position the kart should be moved, then getRescueTransform
|
|
|
|
* to get the position and rotation of this rescue position, and then moves
|
|
|
|
* the kart.
|
|
|
|
* \param kart The kart that is rescued.
|
|
|
|
*/
|
|
|
|
void World::moveKartAfterRescue(AbstractKart* kart)
|
|
|
|
{
|
|
|
|
unsigned int index = getRescuePositionIndex(kart);
|
|
|
|
btTransform t = getRescueTransform(index);
|
|
|
|
moveKartTo(kart, t);
|
|
|
|
} // moveKartAfterRescue
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
/** Places the kart at a given position and rotation.
|
|
|
|
* \param kart The kart to be moved.
|
|
|
|
* \param transform
|
|
|
|
*/
|
|
|
|
void World::moveKartTo(AbstractKart* kart, const btTransform &transform)
|
|
|
|
{
|
|
|
|
btTransform pos(transform);
|
|
|
|
|
|
|
|
// Move the kart
|
|
|
|
Vec3 xyz = pos.getOrigin() + btVector3(0, 0.5f*kart->getKartHeight(),0.0f);
|
|
|
|
|
|
|
|
pos.setOrigin(xyz);
|
|
|
|
kart->setXYZ(xyz);
|
|
|
|
kart->setRotation(pos.getRotation());
|
|
|
|
|
|
|
|
kart->getBody()->setCenterOfMassTransform(pos);
|
|
|
|
|
|
|
|
// Project kart to surface of track
|
2013-07-31 18:03:11 +00:00
|
|
|
// This will set the physics transform
|
2013-07-10 22:47:12 +00:00
|
|
|
m_track->findGround(kart);
|
|
|
|
|
|
|
|
} // moveKartTo
|
|
|
|
|
2011-09-26 22:11:30 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2010-10-12 22:32:33 +00:00
|
|
|
void World::schedulePause(Phase phase)
|
2010-10-11 23:12:30 +00:00
|
|
|
{
|
|
|
|
if (m_schedule_unpause)
|
|
|
|
{
|
|
|
|
m_schedule_unpause = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_schedule_pause = true;
|
|
|
|
m_scheduled_pause_phase = phase;
|
|
|
|
}
|
2011-09-26 22:11:30 +00:00
|
|
|
} // schedulePause
|
2010-10-11 23:12:30 +00:00
|
|
|
|
2011-09-26 22:11:30 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2010-10-12 22:32:33 +00:00
|
|
|
void World::scheduleUnpause()
|
2010-10-11 23:12:30 +00:00
|
|
|
{
|
|
|
|
if (m_schedule_pause)
|
|
|
|
{
|
|
|
|
m_schedule_pause = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_schedule_unpause = true;
|
|
|
|
}
|
2011-09-26 22:11:30 +00:00
|
|
|
} // scheduleUnpause
|
2010-10-11 23:12:30 +00:00
|
|
|
|
2010-02-17 11:59:51 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** This is the main interface to update the world. This function calls
|
2013-05-29 22:04:35 +00:00
|
|
|
* update(), and checks then for the end of the race. Note that race over
|
2010-02-17 11:59:51 +00:00
|
|
|
* handling can not necessarily be done in update(), since not all
|
|
|
|
* data structures might have been updated (e.g.LinearWorld must
|
|
|
|
* call World::update() first, to get updated kart positions. If race
|
|
|
|
* over would be handled in World::update, LinearWorld had no opportunity
|
|
|
|
* to update its data structures before the race is finished).
|
|
|
|
* \param dt Time step size.
|
|
|
|
*/
|
|
|
|
void World::updateWorld(float dt)
|
|
|
|
{
|
2013-04-04 23:09:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
assert(m_magic_number == 0xB01D6543);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-10-11 23:12:30 +00:00
|
|
|
if (m_schedule_pause)
|
|
|
|
{
|
2010-10-12 22:32:33 +00:00
|
|
|
pause(m_scheduled_pause_phase);
|
2010-10-11 23:12:30 +00:00
|
|
|
m_schedule_pause = false;
|
|
|
|
}
|
|
|
|
else if (m_schedule_unpause)
|
|
|
|
{
|
2010-10-12 22:32:33 +00:00
|
|
|
unpause();
|
2010-10-11 23:12:30 +00:00
|
|
|
m_schedule_unpause = false;
|
|
|
|
}
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2012-02-07 01:25:56 +00:00
|
|
|
if (m_self_destruct)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-05-10 23:53:32 +00:00
|
|
|
// Don't update world if a menu is shown or the race is over.
|
2012-05-10 12:57:45 +00:00
|
|
|
if( getPhase() == FINISH_PHASE ||
|
2013-05-29 22:04:35 +00:00
|
|
|
getPhase() == IN_GAME_MENU_PHASE )
|
2010-07-22 22:49:56 +00:00
|
|
|
return;
|
2010-05-10 23:53:32 +00:00
|
|
|
|
2014-07-08 20:10:54 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
update(dt);
|
|
|
|
}
|
|
|
|
catch (AbortWorldUpdateException& e)
|
|
|
|
{
|
2014-08-20 22:19:26 +10:00
|
|
|
(void)e; // avoid compiler warning
|
2014-07-08 20:10:54 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-06-11 19:37:04 -04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
assert(m_magic_number == 0xB01D6543);
|
|
|
|
#endif
|
|
|
|
|
2010-02-17 11:59:51 +00:00
|
|
|
if( (!isFinishPhase()) && isRaceOver())
|
|
|
|
{
|
|
|
|
enterRaceOverState();
|
|
|
|
}
|
2013-04-04 23:09:53 +00:00
|
|
|
else
|
2013-01-19 00:46:03 +00:00
|
|
|
{
|
2013-04-04 23:09:53 +00:00
|
|
|
if (m_schedule_exit_race)
|
2013-01-19 00:46:03 +00:00
|
|
|
{
|
2013-12-17 21:00:56 +00:00
|
|
|
m_schedule_exit_race = false;
|
2013-04-04 23:09:53 +00:00
|
|
|
race_manager->exitRace();
|
|
|
|
race_manager->setAIKartOverride("");
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-04-04 23:09:53 +00:00
|
|
|
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-04-04 23:09:53 +00:00
|
|
|
if (m_schedule_tutorial)
|
2013-02-16 00:52:28 +00:00
|
|
|
{
|
2013-12-17 21:00:56 +00:00
|
|
|
m_schedule_tutorial = false;
|
2013-04-04 23:09:53 +00:00
|
|
|
race_manager->setNumLocalPlayers(1);
|
|
|
|
race_manager->setMajorMode (RaceManager::MAJOR_MODE_SINGLE);
|
|
|
|
race_manager->setMinorMode (RaceManager::MINOR_MODE_TUTORIAL);
|
|
|
|
race_manager->setNumKarts( 1 );
|
|
|
|
race_manager->setTrack( "tutorial" );
|
|
|
|
race_manager->setDifficulty(RaceManager::DIFFICULTY_EASY);
|
2013-12-02 04:27:55 +00:00
|
|
|
race_manager->setReverseTrack(false);
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-04-04 23:09:53 +00:00
|
|
|
// Use keyboard 0 by default (FIXME: let player choose?)
|
|
|
|
InputDevice* device = input_manager->getDeviceList()->getKeyboard(0);
|
|
|
|
|
|
|
|
// Create player and associate player with keyboard
|
2014-04-08 08:06:52 +10:00
|
|
|
StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(),
|
2014-05-31 10:26:02 +10:00
|
|
|
device);
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-07-10 22:47:12 +00:00
|
|
|
if (!kart_properties_manager->getKart(UserConfigParams::m_default_kart))
|
2013-04-04 23:09:53 +00:00
|
|
|
{
|
2014-02-07 02:17:49 +04:00
|
|
|
Log::warn("[World]",
|
2013-07-10 22:47:12 +00:00
|
|
|
"Cannot find kart '%s', will revert to default.",
|
|
|
|
UserConfigParams::m_default_kart.c_str());
|
2013-04-04 23:09:53 +00:00
|
|
|
UserConfigParams::m_default_kart.revertToDefaults();
|
|
|
|
}
|
|
|
|
race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart);
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-04-04 23:09:53 +00:00
|
|
|
// ASSIGN should make sure that only input from assigned devices
|
|
|
|
// is read.
|
|
|
|
input_manager->getDeviceList()->setAssignMode(ASSIGN);
|
|
|
|
input_manager->getDeviceList()
|
|
|
|
->setSinglePlayer( StateManager::get()->getActivePlayer(0) );
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-04-04 23:09:53 +00:00
|
|
|
StateManager::get()->enterGameState();
|
2013-07-07 19:49:51 +00:00
|
|
|
race_manager->setupPlayerKartInfo();
|
2013-07-04 23:56:24 +00:00
|
|
|
race_manager->startNew(true);
|
2013-02-16 00:52:28 +00:00
|
|
|
}
|
2013-04-04 23:09:53 +00:00
|
|
|
else
|
2013-02-16 00:52:28 +00:00
|
|
|
{
|
2013-04-04 23:09:53 +00:00
|
|
|
if (race_manager->raceWasStartedFromOverworld())
|
|
|
|
{
|
|
|
|
OverWorld::enterOverWorld();
|
|
|
|
}
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-02-16 00:52:28 +00:00
|
|
|
}
|
2013-01-19 00:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-17 11:59:51 +00:00
|
|
|
} // updateWorld
|
|
|
|
|
2010-02-24 01:24:48 +00:00
|
|
|
#define MEASURE_FPS 0
|
|
|
|
|
2007-05-27 16:01:53 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2013-04-04 01:15:37 +00:00
|
|
|
|
|
|
|
void World::scheduleTutorial()
|
|
|
|
{
|
|
|
|
m_schedule_exit_race = true;
|
|
|
|
m_schedule_tutorial = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-05-06 23:26:49 +00:00
|
|
|
/** Updates the physics, all karts, the track, and projectile manager.
|
|
|
|
* \param dt Time step size.
|
|
|
|
*/
|
2007-12-12 14:07:26 +00:00
|
|
|
void World::update(float dt)
|
2007-05-27 16:01:53 +00:00
|
|
|
{
|
2013-04-04 23:09:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
assert(m_magic_number == 0xB01D6543);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-07-10 10:33:42 +00:00
|
|
|
PROFILER_PUSH_CPU_MARKER("World::update()", 0x00, 0x7F, 0x00);
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-02-24 01:24:48 +00:00
|
|
|
#if MEASURE_FPS
|
|
|
|
static float time = 0.0f;
|
|
|
|
time += dt;
|
|
|
|
if (time > 5.0f)
|
|
|
|
{
|
|
|
|
time -= 5.0f;
|
|
|
|
printf("%i\n",irr_driver->getVideoDriver()->getFPS());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-07 18:56:21 -04:00
|
|
|
PROFILER_PUSH_CPU_MARKER("World::update (sub-updates)", 0x20, 0x7F, 0x00);
|
2010-05-10 23:53:32 +00:00
|
|
|
history->update(dt);
|
2012-02-28 22:33:49 +00:00
|
|
|
if(ReplayRecorder::get()) ReplayRecorder::get()->update(dt);
|
|
|
|
if(ReplayPlay::get()) ReplayPlay::get()->update(dt);
|
2008-10-06 13:40:11 +00:00
|
|
|
if(history->replayHistory()) dt=history->getNextDelta();
|
2010-02-08 12:59:03 +00:00
|
|
|
WorldStatus::update(dt);
|
2014-09-07 18:54:36 -04:00
|
|
|
PROFILER_POP_CPU_MARKER();
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2013-07-07 19:49:51 +00:00
|
|
|
if (!history->dontDoPhysics())
|
2008-10-06 13:40:11 +00:00
|
|
|
{
|
|
|
|
m_physics->update(dt);
|
|
|
|
}
|
|
|
|
|
2014-09-07 18:56:21 -04:00
|
|
|
PROFILER_PUSH_CPU_MARKER("World::update (AI)", 0x40, 0x7F, 0x00);
|
2014-09-23 16:23:22 +10:00
|
|
|
const int kart_amount = (int)m_karts.size();
|
2014-09-12 23:22:54 +02:00
|
|
|
for (int i = 0 ; i < kart_amount; ++i)
|
|
|
|
{
|
|
|
|
// Update all karts that are not eliminated
|
|
|
|
if(!m_karts[i]->isEliminated()) m_karts[i]->update(dt) ;
|
|
|
|
}
|
2014-09-07 18:54:36 -04:00
|
|
|
PROFILER_POP_CPU_MARKER();
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2014-09-07 18:56:21 -04:00
|
|
|
PROFILER_PUSH_CPU_MARKER("World::update (camera)", 0x60, 0x7F, 0x00);
|
2013-03-06 22:08:41 +00:00
|
|
|
for(unsigned int i=0; i<Camera::getNumCameras(); i++)
|
|
|
|
{
|
|
|
|
Camera::getCamera(i)->update(dt);
|
|
|
|
}
|
2014-09-07 18:54:36 -04:00
|
|
|
PROFILER_POP_CPU_MARKER();
|
|
|
|
|
2014-09-07 18:56:21 -04:00
|
|
|
PROFILER_PUSH_CPU_MARKER("World::update (weather)", 0x80, 0x7F, 0x00);
|
2014-09-01 20:17:38 +02:00
|
|
|
if (UserConfigParams::m_graphical_effects && m_weather)
|
2014-08-30 18:08:23 +02:00
|
|
|
{
|
2014-09-01 20:17:38 +02:00
|
|
|
m_weather->update(dt);
|
2014-08-30 18:08:23 +02:00
|
|
|
}
|
2014-09-07 18:54:36 -04:00
|
|
|
PROFILER_POP_CPU_MARKER();
|
2013-03-06 22:08:41 +00:00
|
|
|
|
2014-09-07 18:56:21 -04:00
|
|
|
PROFILER_PUSH_CPU_MARKER("World::update (projectiles)", 0xa0, 0x7F, 0x00);
|
2007-12-12 14:07:26 +00:00
|
|
|
projectile_manager->update(dt);
|
2014-09-07 18:54:36 -04:00
|
|
|
PROFILER_POP_CPU_MARKER();
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2011-07-10 10:33:42 +00:00
|
|
|
PROFILER_POP_CPU_MARKER();
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-04-04 23:09:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
assert(m_magic_number == 0xB01D6543);
|
|
|
|
#endif
|
2009-04-01 00:55:20 +00:00
|
|
|
} // update
|
|
|
|
|
2010-11-29 22:01:59 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2013-05-29 22:04:35 +00:00
|
|
|
/** Only updates the track. The order in which the various parts of STK are
|
2010-11-29 22:01:59 +00:00
|
|
|
* updated is quite important (i.e. the track can't be updated as part of
|
|
|
|
* the standard update call):
|
|
|
|
* the track must be updated after updating the karts (otherwise the
|
|
|
|
* checklines would be using the previous kart positions to determine
|
|
|
|
* new laps, but linear world which determines distance along track would
|
2013-05-29 22:04:35 +00:00
|
|
|
* be using the new kart positions --> the lap counting line will be
|
2010-11-29 22:01:59 +00:00
|
|
|
* triggered one frame too late, potentially causing strange behaviour of
|
|
|
|
* the icons.
|
|
|
|
* Similarly linear world must update the position of all karts after all
|
|
|
|
* karts have been updated (i.e. World::update() must be called before
|
|
|
|
* updating the position of the karts). The check manager (which is called
|
|
|
|
* from Track::update()) needs the updated distance along track, so track
|
|
|
|
* update has to be called after updating the race position in linear world.
|
|
|
|
* That's why there is a separate call for trackUpdate here.
|
|
|
|
*/
|
|
|
|
void World::updateTrack(float dt)
|
|
|
|
{
|
|
|
|
m_track->update(dt);
|
|
|
|
} // update Track
|
2008-05-20 03:33:48 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-09-29 02:29:33 +00:00
|
|
|
|
2010-03-25 22:29:47 +00:00
|
|
|
Highscores* World::getHighscores() const
|
2008-09-23 01:16:50 +00:00
|
|
|
{
|
2008-09-24 00:13:31 +00:00
|
|
|
if(!m_use_highscores) return NULL;
|
2009-08-18 10:59:21 +00:00
|
|
|
|
2010-03-25 22:29:47 +00:00
|
|
|
const Highscores::HighscoreType type = "HST_" + getIdent();
|
2009-08-18 10:59:21 +00:00
|
|
|
|
2010-03-25 22:29:47 +00:00
|
|
|
Highscores * highscores =
|
|
|
|
highscore_manager->getHighscores(type,
|
|
|
|
getNumKarts(),
|
|
|
|
race_manager->getDifficulty(),
|
|
|
|
race_manager->getTrackName(),
|
2012-03-14 22:37:56 +00:00
|
|
|
race_manager->getNumLaps(),
|
|
|
|
race_manager->getReverseTrack());
|
2009-08-18 10:59:21 +00:00
|
|
|
|
2008-09-23 01:16:50 +00:00
|
|
|
return highscores;
|
2010-02-10 11:40:33 +00:00
|
|
|
} // getHighscores
|
|
|
|
|
2008-09-23 01:16:50 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2011-03-21 06:15:39 +00:00
|
|
|
/** Called at the end of a race. Checks if the current times are worth a new
|
2013-05-29 22:04:35 +00:00
|
|
|
* score, if so it notifies the HighscoreManager so the new score is added
|
2011-03-21 06:15:39 +00:00
|
|
|
* and saved.
|
2008-09-23 01:16:50 +00:00
|
|
|
*/
|
2013-05-29 22:04:35 +00:00
|
|
|
void World::updateHighscores(int* best_highscore_rank, int* best_finish_time,
|
2011-09-21 00:43:43 +00:00
|
|
|
std::string* highscore_who,
|
2011-05-25 01:53:15 +00:00
|
|
|
StateManager::ActivePlayer** best_player)
|
2008-05-20 03:33:48 +00:00
|
|
|
{
|
2011-05-24 01:34:02 +00:00
|
|
|
*best_highscore_rank = -1;
|
2011-05-25 01:53:15 +00:00
|
|
|
*best_player = NULL;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2011-05-24 01:34:02 +00:00
|
|
|
if(!m_use_highscores) return;
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2008-05-20 03:33:48 +00:00
|
|
|
// Add times to highscore list. First compute the order of karts,
|
|
|
|
// so that the timing of the fastest kart is added first (otherwise
|
|
|
|
// someone might get into the highscore list, only to be kicked out
|
|
|
|
// again by a faster kart in the same race), which might be confusing
|
|
|
|
// if we ever decide to display a message (e.g. during a race)
|
2010-02-10 22:59:17 +00:00
|
|
|
unsigned int *index = new unsigned int[m_karts.size()];
|
2008-09-29 15:27:09 +00:00
|
|
|
|
2014-09-23 14:41:32 +10:00
|
|
|
const unsigned int kart_amount = (unsigned int) m_karts.size();
|
2008-09-24 00:43:45 +00:00
|
|
|
for (unsigned int i=0; i<kart_amount; i++ )
|
2008-05-20 03:33:48 +00:00
|
|
|
{
|
2008-09-29 15:27:09 +00:00
|
|
|
index[i] = 999; // first reset the contents of the array
|
2008-10-22 16:05:08 +00:00
|
|
|
}
|
|
|
|
for (unsigned int i=0; i<kart_amount; i++ )
|
|
|
|
{
|
2010-02-10 22:59:17 +00:00
|
|
|
const int pos = m_karts[i]->getPosition()-1;
|
2008-10-24 04:39:52 +00:00
|
|
|
if(pos < 0 || pos >= (int)kart_amount) continue; // wrong position
|
2008-10-22 16:05:08 +00:00
|
|
|
index[pos] = i;
|
2008-05-20 03:33:48 +00:00
|
|
|
}
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2011-05-24 01:34:02 +00:00
|
|
|
for (unsigned int pos=0; pos<kart_amount; pos++)
|
2008-05-20 03:33:48 +00:00
|
|
|
{
|
2008-09-30 01:54:09 +00:00
|
|
|
if(index[pos] == 999)
|
2008-07-14 05:21:37 +00:00
|
|
|
{
|
2008-09-30 01:54:09 +00:00
|
|
|
// no kart claimed to be in this position, most likely means
|
|
|
|
// the kart location data is wrong
|
2009-08-18 10:59:21 +00:00
|
|
|
|
2008-09-30 01:54:09 +00:00
|
|
|
#ifdef DEBUG
|
2014-02-07 02:17:49 +04:00
|
|
|
Log::error("[World]", "Incorrect kart positions:");
|
2010-02-10 22:59:17 +00:00
|
|
|
for (unsigned int i=0; i<m_karts.size(); i++ )
|
2008-07-14 05:21:37 +00:00
|
|
|
{
|
2014-02-07 02:17:49 +04:00
|
|
|
Log::error("[World]", "i=%d position %d.",i,
|
2013-07-10 22:47:12 +00:00
|
|
|
m_karts[i]->getPosition());
|
2008-07-14 05:21:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-09-30 01:54:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-08-18 10:59:21 +00:00
|
|
|
|
2013-05-29 22:04:35 +00:00
|
|
|
// Only record times for player karts and only if
|
2011-09-21 00:43:43 +00:00
|
|
|
// they finished the race
|
2013-05-29 22:04:35 +00:00
|
|
|
if(!m_karts[index[pos]]->getController()->isPlayerController())
|
2011-09-21 00:43:43 +00:00
|
|
|
continue;
|
2010-02-10 22:59:17 +00:00
|
|
|
if (!m_karts[index[pos]]->hasFinishedRace()) continue;
|
2008-05-20 03:33:48 +00:00
|
|
|
|
2010-02-10 22:59:17 +00:00
|
|
|
assert(index[pos] < m_karts.size());
|
2010-02-15 00:54:28 +00:00
|
|
|
Kart *k = (Kart*)m_karts[index[pos]];
|
2008-05-20 03:33:48 +00:00
|
|
|
|
2010-03-25 22:29:47 +00:00
|
|
|
Highscores* highscores = getHighscores();
|
2009-08-18 10:59:21 +00:00
|
|
|
|
2010-02-15 00:54:28 +00:00
|
|
|
PlayerController *controller = (PlayerController*)(k->getController());
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-08-21 13:54:50 +00:00
|
|
|
int highscore_rank = 0;
|
|
|
|
if (controller->getPlayer()->getProfile() != NULL) // if we have the player profile here
|
|
|
|
highscore_rank = highscores->addData(k->getIdent(),
|
2011-09-21 00:43:43 +00:00
|
|
|
controller->getPlayer()->getProfile()->getName(),
|
2011-05-24 01:34:02 +00:00
|
|
|
k->getFinishTime());
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2011-05-24 01:34:02 +00:00
|
|
|
if (highscore_rank > 0)
|
2008-05-20 03:33:48 +00:00
|
|
|
{
|
2013-05-29 22:04:35 +00:00
|
|
|
if (*best_highscore_rank == -1 ||
|
2011-09-21 00:43:43 +00:00
|
|
|
highscore_rank < *best_highscore_rank)
|
2011-05-24 01:34:02 +00:00
|
|
|
{
|
|
|
|
*best_highscore_rank = highscore_rank;
|
2011-05-24 04:56:18 +00:00
|
|
|
*best_finish_time = (int)(k->getFinishTime());
|
2011-05-25 01:53:15 +00:00
|
|
|
*best_player = controller->getPlayer();
|
2011-05-24 01:34:02 +00:00
|
|
|
*highscore_who = k->getIdent();
|
|
|
|
}
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-03-25 22:29:47 +00:00
|
|
|
highscore_manager->saveHighscores();
|
2008-05-20 03:33:48 +00:00
|
|
|
}
|
2008-09-29 15:43:58 +00:00
|
|
|
} // next position
|
2008-05-20 03:33:48 +00:00
|
|
|
delete []index;
|
2009-08-18 10:59:21 +00:00
|
|
|
|
2008-05-20 03:33:48 +00:00
|
|
|
} // updateHighscores
|
2007-05-27 16:01:53 +00:00
|
|
|
|
2010-02-10 11:40:33 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Returns the n-th player kart. Note that this function is O(N), not O(1),
|
|
|
|
* so it shouldn't be called inside of loops.
|
2010-02-10 12:47:18 +00:00
|
|
|
* \param n Index of player kart to return.
|
2010-02-10 11:40:33 +00:00
|
|
|
*/
|
2012-03-19 20:21:11 +00:00
|
|
|
AbstractKart *World::getPlayerKart(unsigned int n) const
|
2010-02-10 11:40:33 +00:00
|
|
|
{
|
2010-02-10 12:47:18 +00:00
|
|
|
unsigned int count=-1;
|
|
|
|
|
2010-02-10 22:59:17 +00:00
|
|
|
for(unsigned int i=0; i<m_karts.size(); i++)
|
2013-07-31 18:03:11 +00:00
|
|
|
if(m_karts[i]->getController()->isPlayerController() ||
|
|
|
|
m_karts[i]->getController()->isNetworkController())
|
2010-02-10 12:47:18 +00:00
|
|
|
{
|
|
|
|
count++;
|
2010-02-15 00:54:28 +00:00
|
|
|
if(count==n) return m_karts[i];
|
2010-02-10 12:47:18 +00:00
|
|
|
}
|
2010-02-10 11:40:33 +00:00
|
|
|
return NULL;
|
|
|
|
} // getPlayerKart
|
|
|
|
|
2010-02-10 12:47:18 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-10-07 09:11:34 +00:00
|
|
|
/** Returns the nth local player kart, i.e. a kart that has a camera.
|
|
|
|
* Note that in profile mode this means a non player kart could be returned
|
|
|
|
* (since an AI kart will have the camera).
|
2010-02-10 12:47:18 +00:00
|
|
|
* \param n Index of player kart to return.
|
|
|
|
*/
|
2012-03-19 20:21:11 +00:00
|
|
|
AbstractKart *World::getLocalPlayerKart(unsigned int n) const
|
2010-02-10 12:47:18 +00:00
|
|
|
{
|
2013-03-06 22:08:41 +00:00
|
|
|
if(n>=Camera::getNumCameras()) return NULL;
|
|
|
|
return Camera::getCamera(n)->getKart();
|
2010-02-10 12:47:18 +00:00
|
|
|
} // getLocalPlayerKart
|
|
|
|
|
2008-04-15 13:57:18 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-25 01:48:32 +00:00
|
|
|
/** Remove (eliminate) a kart from the race */
|
2013-03-06 22:08:41 +00:00
|
|
|
void World::eliminateKart(int kart_id, bool notify_of_elimination)
|
2008-04-15 13:57:18 +00:00
|
|
|
{
|
2013-03-06 22:08:41 +00:00
|
|
|
AbstractKart *kart = m_karts[kart_id];
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2013-03-06 22:08:41 +00:00
|
|
|
// Display a message about the eliminated kart in the race guia
|
2011-09-21 00:43:43 +00:00
|
|
|
if (notify_of_elimination)
|
2009-08-18 10:59:21 +00:00
|
|
|
{
|
2013-03-06 22:08:41 +00:00
|
|
|
for(unsigned int i=0; i<Camera::getNumCameras(); i++)
|
2009-07-12 11:54:21 +00:00
|
|
|
{
|
2013-03-06 22:08:41 +00:00
|
|
|
Camera *camera = Camera::getCamera(i);
|
|
|
|
if(camera->getKart()==kart)
|
|
|
|
m_race_gui->addMessage(_("You have been eliminated!"), kart,
|
2011-09-21 00:43:43 +00:00
|
|
|
2.0f);
|
2010-02-25 01:48:32 +00:00
|
|
|
else
|
2011-09-03 20:23:55 +00:00
|
|
|
m_race_gui->addMessage(_("'%s' has been eliminated.",
|
2013-05-29 22:04:35 +00:00
|
|
|
core::stringw(kart->getName())),
|
2013-03-06 22:08:41 +00:00
|
|
|
camera->getKart(),
|
2011-09-21 00:43:43 +00:00
|
|
|
2.0f);
|
2013-03-06 22:08:41 +00:00
|
|
|
} // for i < number of cameras
|
|
|
|
} // if notify_of_elimination
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-02-15 00:54:28 +00:00
|
|
|
if(kart->getController()->isPlayerController())
|
2008-04-15 13:57:18 +00:00
|
|
|
{
|
2013-03-06 22:08:41 +00:00
|
|
|
for(unsigned int i=0; i<Camera::getNumCameras(); i++)
|
|
|
|
{
|
|
|
|
// Change the camera so that it will be attached to the leader
|
|
|
|
// and facing backwards.
|
|
|
|
Camera *camera = Camera::getCamera(i);
|
|
|
|
if(camera->getKart()==kart)
|
|
|
|
camera->setMode(Camera::CM_LEADER_MODE);
|
|
|
|
}
|
2008-04-15 13:57:18 +00:00
|
|
|
m_eliminated_players++;
|
|
|
|
}
|
2010-02-17 11:59:51 +00:00
|
|
|
|
2009-08-18 10:59:21 +00:00
|
|
|
// The kart can't be really removed from the m_kart array, since otherwise
|
|
|
|
// a race can't be restarted. So it's only marked to be eliminated (and
|
|
|
|
// ignored in all loops). Important:world->getCurrentNumKarts() returns
|
|
|
|
// the number of karts still racing. This value can not be used for loops
|
2008-04-17 00:20:06 +00:00
|
|
|
// over all karts, use race_manager->getNumKarts() instead!
|
2012-04-01 22:57:41 +00:00
|
|
|
kart->eliminate();
|
2008-04-15 13:57:18 +00:00
|
|
|
m_eliminated_karts++;
|
|
|
|
|
2012-08-06 16:54:36 +00:00
|
|
|
} // eliminateKart
|
2009-07-16 12:09:15 +00:00
|
|
|
|
2008-09-22 00:55:27 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2013-05-29 22:04:35 +00:00
|
|
|
/** Called to determine the default collectibles to give each player at the
|
|
|
|
* start for this kind of race. Both parameters are of 'out' type.
|
2011-09-16 01:49:38 +00:00
|
|
|
* \param collectible_type The type of collectible each kart.
|
|
|
|
* \param amount The number of collectibles.
|
|
|
|
*/
|
|
|
|
void World::getDefaultCollectibles(int *collectible_type, int *amount )
|
2008-09-22 00:55:27 +00:00
|
|
|
{
|
2011-09-16 01:49:38 +00:00
|
|
|
*collectible_type = PowerupManager::POWERUP_NOTHING;
|
|
|
|
*amount = 0;
|
|
|
|
} // getDefaultCollectibles
|
|
|
|
|
2007-06-10 01:13:39 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-05-10 23:53:32 +00:00
|
|
|
/** Pauses the music (and then pauses WorldStatus).
|
|
|
|
*/
|
2010-10-12 22:32:33 +00:00
|
|
|
void World::pause(Phase phase)
|
2007-06-10 01:13:39 +00:00
|
|
|
{
|
2012-11-22 01:07:09 +00:00
|
|
|
if (m_stop_music_when_dialog_open)
|
|
|
|
music_manager->pauseMusic();
|
2014-09-17 21:38:21 +10:00
|
|
|
SFXManager::get()->pauseAll();
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-05-10 23:53:32 +00:00
|
|
|
WorldStatus::pause(phase);
|
2010-02-08 12:59:03 +00:00
|
|
|
} // pause
|
2007-06-10 01:13:39 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-10-12 22:32:33 +00:00
|
|
|
void World::unpause()
|
2007-06-10 01:13:39 +00:00
|
|
|
{
|
2012-11-22 01:07:09 +00:00
|
|
|
if (m_stop_music_when_dialog_open)
|
|
|
|
music_manager->resumeMusic();
|
2014-09-17 21:38:21 +10:00
|
|
|
SFXManager::get()->resumeAll();
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-02-08 12:59:03 +00:00
|
|
|
WorldStatus::unpause();
|
2013-05-29 22:04:35 +00:00
|
|
|
|
2010-02-10 22:59:17 +00:00
|
|
|
for(unsigned int i=0; i<m_karts.size(); i++)
|
2010-07-01 00:16:09 +00:00
|
|
|
{
|
|
|
|
// Note that we can not test for isPlayerController here, since
|
|
|
|
// an EndController will also return 'isPlayerController' if the
|
|
|
|
// kart belonged to a player.
|
2013-05-29 22:04:35 +00:00
|
|
|
PlayerController *pc =
|
2011-09-21 00:43:43 +00:00
|
|
|
dynamic_cast<PlayerController*>(m_karts[i]->getController());
|
2010-07-01 00:16:09 +00:00
|
|
|
if(pc)
|
|
|
|
pc->resetInputState();
|
|
|
|
}
|
2010-02-08 12:59:03 +00:00
|
|
|
} // pause
|
2007-06-10 01:13:39 +00:00
|
|
|
|
2012-02-07 01:25:56 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Call when the world needs to be deleted but you can't do it immediately
|
|
|
|
* because you are e.g. within World::update()
|
|
|
|
*/
|
|
|
|
void World::delayedSelfDestruct()
|
|
|
|
{
|
|
|
|
m_self_destruct = true;
|
|
|
|
}
|
|
|
|
|
2012-06-24 01:39:49 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void World::escapePressed()
|
|
|
|
{
|
|
|
|
new RacePausedDialog(0.8f, 0.6f);
|
|
|
|
}
|
|
|
|
|
2014-05-03 20:21:34 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool World::isFogEnabled() const
|
|
|
|
{
|
2014-10-04 01:42:25 +02:00
|
|
|
return !m_force_disable_fog && (m_track != NULL && m_track->isFogEnabled());
|
2014-05-03 20:21:34 -04:00
|
|
|
}
|
|
|
|
|
2007-05-27 16:01:53 +00:00
|
|
|
/* EOF */
|