2007-05-27 12:01:53 -04:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// 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 2
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
#include "world.hpp"
|
|
|
|
#include "herring_manager.hpp"
|
|
|
|
#include "projectile_manager.hpp"
|
|
|
|
#include "gui/menu_manager.hpp"
|
2008-02-29 22:18:53 -05:00
|
|
|
#include "file_manager.hpp"
|
2007-05-27 12:01:53 -04:00
|
|
|
#include "player_kart.hpp"
|
|
|
|
#include "auto_kart.hpp"
|
|
|
|
#include "track.hpp"
|
|
|
|
#include "kart_properties_manager.hpp"
|
|
|
|
#include "track_manager.hpp"
|
|
|
|
#include "race_manager.hpp"
|
|
|
|
#include "user_config.hpp"
|
|
|
|
#include "callback_manager.hpp"
|
|
|
|
#include "history.hpp"
|
|
|
|
#include "constants.hpp"
|
|
|
|
#include "sound_manager.hpp"
|
|
|
|
#include "translation.hpp"
|
|
|
|
#include "highscore_manager.hpp"
|
|
|
|
#include "scene.hpp"
|
2007-09-19 06:54:27 -04:00
|
|
|
#include "camera.hpp"
|
2007-05-27 12:01:53 -04:00
|
|
|
#include "robots/default_robot.hpp"
|
2008-03-26 22:38:10 -04:00
|
|
|
#include "unlock_manager.hpp"
|
2007-09-19 05:23:02 -04:00
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
|
|
|
# include "replay_player.hpp"
|
|
|
|
#endif
|
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
|
|
|
# define snprintf _snprintf
|
|
|
|
#endif
|
|
|
|
|
|
|
|
World* world = 0;
|
|
|
|
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
World::World()
|
2007-09-19 05:23:02 -04:00
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
|
|
|
, m_p_replay_player(NULL)
|
|
|
|
#endif
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
|
|
|
delete world;
|
2008-05-07 21:28:07 -04:00
|
|
|
world = this;
|
|
|
|
m_phase = SETUP_PHASE;
|
2008-05-25 04:20:15 -04:00
|
|
|
m_previous_phase = SETUP_PHASE; // initialise it just in case
|
2008-05-07 21:28:07 -04:00
|
|
|
m_track = NULL;
|
|
|
|
m_clock = 0.0f;
|
|
|
|
m_faster_music_active = false;
|
|
|
|
m_fastest_lap = 9999999.9f;
|
|
|
|
m_fastest_kart = 0;
|
|
|
|
m_eliminated_karts = 0;
|
|
|
|
m_eliminated_players = 0;
|
|
|
|
m_leader_intervals = stk_config->m_leader_intervals;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
// Grab the track file
|
|
|
|
try
|
|
|
|
{
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
m_track = track_manager->getTrack(race_manager->getTrackName());
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
catch(std::runtime_error)
|
|
|
|
{
|
|
|
|
char msg[MAX_ERROR_MESSAGE_LENGTH];
|
|
|
|
snprintf(msg, sizeof(msg),
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
"Track '%s' not found.\n",race_manager->getTrackName().c_str());
|
2007-05-27 12:01:53 -04:00
|
|
|
throw std::runtime_error(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the physics
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
m_physics = new Physics(m_track->getGravity());
|
2007-05-27 12:01:53 -04:00
|
|
|
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
assert(race_manager->getNumKarts() > 0);
|
2007-05-27 12:01:53 -04: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.
|
2007-12-12 09:07:26 -05:00
|
|
|
loadTrack() ;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
int playerIndex = 0;
|
2008-04-16 20:20:06 -04:00
|
|
|
for(unsigned int i=0; i<race_manager->getNumKarts(); i++)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-04-16 20:20:06 -04:00
|
|
|
int position = i+1; // position start with 1
|
2007-09-25 23:43:02 -04:00
|
|
|
sgCoord init_pos;
|
2008-04-16 20:20:06 -04:00
|
|
|
m_track->getStartCoords(i, &init_pos);
|
2007-05-27 12:01:53 -04:00
|
|
|
Kart* newkart;
|
2008-04-16 20:20:06 -04:00
|
|
|
const std::string& kart_name=race_manager->getKartName(i);
|
2007-05-27 12:01:53 -04:00
|
|
|
if(user_config->m_profile)
|
|
|
|
{
|
|
|
|
// In profile mode, load only the old kart
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
newkart = new DefaultRobot(kart_name, position, init_pos);
|
|
|
|
// Create a camera for the last kart (since this way more of the
|
|
|
|
// karts can be seen.
|
2008-04-16 20:20:06 -04:00
|
|
|
if(i==race_manager->getNumKarts()-1)
|
2008-02-17 07:58:12 -05:00
|
|
|
{
|
2008-05-05 02:58:42 -04:00
|
|
|
btVector3 startpos(init_pos.xyz[0], init_pos.xyz[1], init_pos.xyz[2]);
|
|
|
|
scene->createCamera(playerIndex, newkart);
|
2008-02-17 07:58:12 -05:00
|
|
|
}
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-16 20:20:06 -04:00
|
|
|
if (race_manager->isPlayer(i))
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
newkart = new PlayerKart(kart_name, position,
|
|
|
|
&(user_config->m_player[playerIndex]),
|
2008-05-05 02:58:42 -04:00
|
|
|
init_pos, playerIndex);
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
m_player_karts.push_back((PlayerKart*)newkart);
|
2007-09-19 06:54:27 -04:00
|
|
|
playerIndex++;
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
newkart = loadRobot(kart_name, position, init_pos);
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
} // if !user_config->m_profile
|
|
|
|
if(user_config->m_replay_history)
|
|
|
|
{
|
2008-04-16 20:20:06 -04:00
|
|
|
history->LoadKartData(newkart, i);
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
2007-12-08 08:04:56 -05:00
|
|
|
newkart -> getModelTransform() -> clrTraversalMaskBits(SSGTRAV_ISECT|SSGTRAV_HOT);
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2007-12-08 08:04:56 -05:00
|
|
|
scene->add ( newkart -> getModelTransform() ) ;
|
2007-05-27 12:01:53 -04:00
|
|
|
m_kart.push_back(newkart);
|
|
|
|
} // for i
|
|
|
|
|
|
|
|
resetAllKarts();
|
|
|
|
|
|
|
|
#ifdef SSG_BACKFACE_COLLISIONS_SUPPORTED
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
//ssgSetBackFaceCollisions ( !not defined! race_manager->mirror ) ;
|
2007-05-27 12:01:53 -04:00
|
|
|
#endif
|
|
|
|
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
Highscores::HighscoreType hst = (race_manager->getRaceMode()==RaceManager::RM_TIME_TRIAL)
|
2007-05-27 12:01:53 -04:00
|
|
|
? Highscores::HST_TIMETRIAL_OVERALL_TIME
|
|
|
|
: Highscores::HST_RACE_OVERALL_TIME;
|
|
|
|
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
m_highscores = highscore_manager->getHighscores(hst);
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
callback_manager->initAll();
|
|
|
|
menu_manager->switchToRace();
|
|
|
|
|
2008-05-07 21:28:07 -04:00
|
|
|
m_track->startMusic();
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-02-12 20:02:02 -05:00
|
|
|
m_phase = user_config->m_profile ? RACE_PHASE : SETUP_PHASE;
|
2007-09-19 05:23:02 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
m_replay_recorder.initRecorder( race_manager->getNumKarts() );
|
2007-09-21 14:02:53 -04:00
|
|
|
|
2007-11-03 09:13:26 -04:00
|
|
|
m_p_replay_player = new ReplayPlayer;
|
2007-09-19 14:28:48 -04:00
|
|
|
if( !loadReplayHumanReadable( "test1" ) )
|
2007-11-03 09:13:26 -04:00
|
|
|
{
|
|
|
|
delete m_p_replay_player;
|
|
|
|
m_p_replay_player = NULL;
|
|
|
|
}
|
|
|
|
if( m_p_replay_player ) m_p_replay_player->showReplayAt( 0.0 );
|
2007-09-19 05:23:02 -04:00
|
|
|
#endif
|
2007-12-08 08:04:56 -05:00
|
|
|
} // World
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
World::~World()
|
|
|
|
{
|
2007-09-19 05:23:02 -04:00
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
|
|
|
saveReplayHumanReadable( "test" );
|
|
|
|
#endif
|
2007-12-12 09:07:26 -05:00
|
|
|
m_track->cleanup();
|
2007-12-08 08:04:56 -05:00
|
|
|
// Clear all callbacks
|
|
|
|
callback_manager->clear(CB_TRACK);
|
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
for ( unsigned int i = 0 ; i < m_kart.size() ; i++ )
|
|
|
|
delete m_kart[i];
|
|
|
|
|
|
|
|
m_kart.clear();
|
|
|
|
projectile_manager->cleanup();
|
|
|
|
delete m_physics;
|
|
|
|
|
|
|
|
sound_manager -> stopMusic();
|
|
|
|
|
|
|
|
sgVec3 sun_pos;
|
|
|
|
sgVec4 ambient_col, specular_col, diffuse_col;
|
|
|
|
sgSetVec3 ( sun_pos, 0.0f, 0.0f, 1.0f );
|
|
|
|
sgSetVec4 ( ambient_col , 0.2f, 0.2f, 0.2f, 1.0f );
|
|
|
|
sgSetVec4 ( specular_col, 1.0f, 1.0f, 1.0f, 1.0f );
|
|
|
|
sgSetVec4 ( diffuse_col , 1.0f, 1.0f, 1.0f, 1.0f );
|
|
|
|
|
|
|
|
ssgGetLight ( 0 ) -> setPosition ( sun_pos ) ;
|
|
|
|
ssgGetLight ( 0 ) -> setColour ( GL_AMBIENT , ambient_col ) ;
|
|
|
|
ssgGetLight ( 0 ) -> setColour ( GL_DIFFUSE , diffuse_col ) ;
|
|
|
|
ssgGetLight ( 0 ) -> setColour ( GL_SPECULAR, specular_col ) ;
|
2007-09-19 05:23:02 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
|
|
|
m_replay_recorder.destroy();
|
2007-11-03 09:13:26 -04:00
|
|
|
if( m_p_replay_player )
|
|
|
|
{
|
|
|
|
m_p_replay_player->destroy();
|
|
|
|
delete m_p_replay_player;
|
|
|
|
m_p_replay_player = NULL;
|
|
|
|
}
|
2007-09-19 05:23:02 -04:00
|
|
|
#endif
|
2007-11-03 09:13:26 -04:00
|
|
|
} // ~World
|
2007-05-27 12:01:53 -04: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()
|
|
|
|
{
|
|
|
|
bool all_finished=false;
|
2008-02-12 22:42:18 -05: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.
|
|
|
|
for(int i=0; i<100; i++) m_physics->update(1.f/60.f);
|
2007-05-27 12:01:53 -04:00
|
|
|
while(!all_finished)
|
|
|
|
{
|
2007-11-21 20:20:57 -05:00
|
|
|
m_physics->update(1.f/60.f);
|
2007-05-27 12:01:53 -04:00
|
|
|
all_finished=true;
|
|
|
|
for ( Karts::iterator i=m_kart.begin(); i!=m_kart.end(); i++)
|
|
|
|
{
|
|
|
|
if(!(*i)->isInRest())
|
|
|
|
{
|
|
|
|
all_finished=false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // while
|
2008-01-29 23:36:00 -05:00
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
} // resetAllKarts
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2007-12-12 09:07:26 -05:00
|
|
|
void World::update(float dt)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2007-12-12 09:07:26 -05:00
|
|
|
if(user_config->m_replay_history) dt=history->GetNextDelta();
|
2008-02-12 20:02:02 -05:00
|
|
|
updateRaceStatus(dt);
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
if( getPhase() == FINISH_PHASE )
|
|
|
|
{
|
2008-04-15 09:57:18 -04:00
|
|
|
if(race_manager->getRaceMode()==RaceManager::RM_FOLLOW_LEADER)
|
|
|
|
{
|
|
|
|
menu_manager->pushMenu(MENUID_LEADERRESULT);
|
2008-04-27 17:48:32 -04:00
|
|
|
unlock_manager->raceFinished();
|
2008-04-15 09:57:18 -04:00
|
|
|
return;
|
|
|
|
}
|
2008-05-19 23:33:48 -04:00
|
|
|
updateHighscores();
|
2007-06-09 21:13:39 -04:00
|
|
|
pause();
|
2007-05-27 12:01:53 -04:00
|
|
|
menu_manager->pushMenu(MENUID_RACERESULT);
|
|
|
|
}
|
2007-12-12 09:07:26 -05:00
|
|
|
if(!user_config->m_replay_history) history->StoreDelta(dt);
|
|
|
|
m_physics->update(dt);
|
2008-04-15 09:57:18 -04:00
|
|
|
for (int i = 0 ; i <(int) m_kart.size(); ++i)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-04-15 09:57:18 -04:00
|
|
|
// Update all karts that are not eliminated
|
|
|
|
if(!race_manager->isEliminated(i)) m_kart[i]->update(dt) ;
|
2007-12-12 09:07:26 -05:00
|
|
|
}
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2007-12-12 09:07:26 -05:00
|
|
|
projectile_manager->update(dt);
|
|
|
|
herring_manager->update(dt);
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
for ( Karts::size_type i = 0 ; i < m_kart.size(); ++i)
|
|
|
|
{
|
2008-04-16 20:20:06 -04:00
|
|
|
if(m_kart[i]->isEliminated()) continue; // ignore eliminated kart
|
2008-05-19 23:33:48 -04:00
|
|
|
if(!m_kart[i]->hasFinishedRace()) updateRacePosition((int)i);
|
2008-04-15 09:57:18 -04:00
|
|
|
if(m_kart[i]->isPlayerKart()) m_kart[i]->addMessages(); // add 'wrong direction'
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Routine stuff we do even when paused */
|
2007-12-12 09:07:26 -05:00
|
|
|
callback_manager->update(dt);
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2007-09-19 05:23:02 -04:00
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
2007-11-03 09:13:26 -04:00
|
|
|
// we start recording after START_PHASE, since during start-phase m_clock is incremented
|
|
|
|
// normally, but after switching to RACE_PHASE m_clock is set back to 0.0
|
2008-02-12 20:02:02 -05:00
|
|
|
if( m_phase == GO_PHASE )
|
2007-11-03 09:13:26 -04:00
|
|
|
{
|
|
|
|
m_replay_recorder.pushFrame();
|
|
|
|
if( m_p_replay_player ) m_p_replay_player->showReplayAt( m_clock );
|
|
|
|
}
|
2007-09-19 05:23:02 -04:00
|
|
|
#endif
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
2008-05-19 23:33:48 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void World::updateHighscores()
|
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
unsigned int *index = new unsigned int[m_kart.size()];
|
|
|
|
for (unsigned int i=0; i<m_kart.size(); i++ )
|
|
|
|
{
|
|
|
|
index[m_kart[i]->getPosition()-1] = i;
|
|
|
|
}
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-05-19 23:33:48 -04:00
|
|
|
for(unsigned int pos=0; pos<m_kart.size(); pos++)
|
|
|
|
{
|
|
|
|
// Only record times for player karts
|
|
|
|
if(!m_kart[index[pos]]->isPlayerKart()) continue;
|
|
|
|
|
|
|
|
PlayerKart *k = (PlayerKart*)m_kart[index[pos]];
|
|
|
|
|
|
|
|
Highscores::HighscoreType hst = (race_manager->getRaceMode()==
|
|
|
|
RaceManager::RM_TIME_TRIAL)
|
|
|
|
? Highscores::HST_TIMETRIAL_OVERALL_TIME
|
|
|
|
: Highscores::HST_RACE_OVERALL_TIME;
|
|
|
|
if(m_highscores->addData(hst, k->getName(),
|
|
|
|
k->getPlayer()->getName(),
|
|
|
|
k->getFinishTime())>0 )
|
|
|
|
{
|
|
|
|
highscore_manager->Save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete []index;
|
|
|
|
} // updateHighscores
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2007-09-19 05:23:02 -04:00
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
|
|
|
bool World::saveReplayHumanReadable( std::string const &filename ) const
|
|
|
|
{
|
|
|
|
std::string path;
|
2008-02-29 22:18:53 -05:00
|
|
|
path = file_manager->getReplayFile(filename+"."+ReplayBase::REPLAY_FILE_EXTENSION_HUMAN_READABLE);
|
2007-09-19 05:23:02 -04:00
|
|
|
|
|
|
|
FILE *fd = fopen( path.c_str(), "w" );
|
|
|
|
if( !fd )
|
|
|
|
{
|
2008-04-20 20:09:23 -04:00
|
|
|
fprintf(stderr, "Error while opening replay file for writing '%s'\n", path.c_str());
|
2007-09-19 05:23:02 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int nKarts = world->getNumKarts();
|
|
|
|
const char *version = "unknown";
|
|
|
|
#ifdef VERSION
|
|
|
|
version = VERSION;
|
|
|
|
#endif
|
|
|
|
fprintf(fd, "Version: %s\n", version);
|
|
|
|
fprintf(fd, "numkarts: %d\n", m_kart.size());
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
fprintf(fd, "numplayers: %d\n", race_manager->getNumPlayers());
|
|
|
|
fprintf(fd, "difficulty: %d\n", race_manager->getDifficulty());
|
2008-02-26 20:11:02 -05:00
|
|
|
fprintf(fd, "track: %s\n", m_track->getIdent().c_str());
|
2007-09-21 14:02:53 -04:00
|
|
|
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
for(int i=0; i<race_manager->getNumKarts(); i++)
|
2007-09-19 05:23:02 -04:00
|
|
|
{
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
fprintf(fd, "model %d: %s\n", i, race_manager->getKartName(i).c_str());
|
2007-09-19 05:23:02 -04:00
|
|
|
}
|
|
|
|
if( !m_replay_recorder.saveReplayHumanReadable( fd ) )
|
|
|
|
{
|
|
|
|
fclose( fd ); fd = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( fd ); fd = NULL;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} // saveReplayHumanReadable
|
|
|
|
#endif // HAVE_GHOST_REPLAY
|
|
|
|
|
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool World::loadReplayHumanReadable( std::string const &filename )
|
|
|
|
{
|
2007-09-19 14:28:48 -04:00
|
|
|
assert( m_p_replay_player );
|
|
|
|
m_p_replay_player->destroy();
|
2007-09-19 05:23:02 -04:00
|
|
|
|
2008-02-29 22:18:53 -05:00
|
|
|
std::string path = file_manager->getReplayFile(filename+"."+
|
2008-02-25 21:30:28 -05:00
|
|
|
ReplayBase::REPLAY_FILE_EXTENSION_HUMAN_READABLE);
|
2007-09-19 05:23:02 -04:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2008-02-29 22:18:53 -05:00
|
|
|
path = file_manager->getPath(path.c_str());
|
2007-09-19 05:23:02 -04:00
|
|
|
}
|
|
|
|
catch(std::runtime_error& e)
|
|
|
|
{
|
2008-04-20 20:09:23 -04:00
|
|
|
fprintf( stderr, "Couldn't find replay-file: '%s'\n", path.c_str() );
|
2007-09-19 05:23:02 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *fd = fopen( path.c_str(), "r" );
|
|
|
|
if( !fd )
|
|
|
|
{
|
2008-04-20 20:09:23 -04:00
|
|
|
fprintf(stderr, "Error while opening replay file for loading '%s'\n", path.c_str());
|
2007-09-19 05:23:02 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-09-21 14:02:53 -04:00
|
|
|
bool blnRet = m_p_replay_player->loadReplayHumanReadable( fd );
|
2007-09-19 05:23:02 -04:00
|
|
|
|
|
|
|
fclose( fd ); fd = NULL;
|
|
|
|
|
|
|
|
return blnRet;
|
|
|
|
} // loadReplayHumanReadable
|
|
|
|
#endif // HAVE_GHOST_REPLAY
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2008-02-12 20:02:02 -05:00
|
|
|
void World::updateRaceStatus(float dt)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-02-12 20:02:02 -05:00
|
|
|
switch (m_phase) {
|
2008-05-19 23:33:48 -04:00
|
|
|
// Note: setup phase must be a separate phase, since the race_manager
|
|
|
|
// checks the phase when updating the camera: in the very first time
|
|
|
|
// step dt is large (it includes loading time), so the camera might
|
|
|
|
// tilt way too much. A separate setup phase for the first frame
|
|
|
|
// simplifies this handling
|
|
|
|
case SETUP_PHASE: m_clock = 0.0f;
|
|
|
|
m_phase = READY_PHASE;
|
|
|
|
sound_manager->playSfx(SOUND_PRESTART);
|
2008-02-12 20:02:02 -05:00
|
|
|
dt = 0.0f; // solves the problem of adding track loading time
|
2008-05-19 23:33:48 -04:00
|
|
|
return; // loading time, don't play sound yet
|
|
|
|
case READY_PHASE: if(m_clock>1.0)
|
2008-02-12 20:02:02 -05:00
|
|
|
{
|
|
|
|
m_phase=SET_PHASE;
|
|
|
|
sound_manager->playSfx(SOUND_PRESTART);
|
|
|
|
}
|
2008-05-19 23:33:48 -04:00
|
|
|
m_clock += dt;
|
|
|
|
return;
|
2008-02-12 20:02:02 -05:00
|
|
|
case SET_PHASE : if(m_clock>2.0)
|
|
|
|
{
|
|
|
|
m_phase=GO_PHASE;
|
2008-04-15 09:57:18 -04:00
|
|
|
if(race_manager->getRaceMode()==RaceManager::RM_FOLLOW_LEADER)
|
|
|
|
m_clock=m_leader_intervals[0];
|
|
|
|
else
|
|
|
|
m_clock=0.0f;
|
2008-02-12 20:02:02 -05:00
|
|
|
sound_manager->playSfx(SOUND_START);
|
|
|
|
// Reset the brakes now that the prestart
|
|
|
|
// phase is over (braking prevents the karts
|
|
|
|
// from sliding downhill)
|
|
|
|
for(unsigned int i=0; i<m_kart.size(); i++)
|
|
|
|
{
|
|
|
|
m_kart[i]->resetBrakes();
|
|
|
|
}
|
2007-09-21 14:02:53 -04:00
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
2008-02-12 20:02:02 -05:00
|
|
|
// push positions at time 0.0 to replay-data
|
|
|
|
m_replay_recorder.pushFrame();
|
2007-09-21 14:02:53 -04:00
|
|
|
#endif
|
2008-02-12 20:02:02 -05:00
|
|
|
}
|
2008-05-19 23:33:48 -04:00
|
|
|
m_clock += dt;
|
|
|
|
return;
|
2008-04-15 09:57:18 -04:00
|
|
|
case GO_PHASE : if(race_manager->getRaceMode()==RaceManager::RM_FOLLOW_LEADER)
|
|
|
|
{
|
|
|
|
// Switch to race if more than 1 second has past
|
|
|
|
if(m_clock<m_leader_intervals[0]-1.0f)
|
|
|
|
m_phase=RACE_PHASE;
|
2008-05-19 23:33:48 -04:00
|
|
|
m_clock -= dt;
|
2008-04-15 09:57:18 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(m_clock>1.0) // how long to display the 'go' message
|
|
|
|
m_phase=RACE_PHASE;
|
2008-05-19 23:33:48 -04:00
|
|
|
m_clock += dt;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case DELAY_FINISH_PHASE :
|
|
|
|
{
|
|
|
|
m_clock += dt;
|
|
|
|
// Nothing more to do if delay time is not over yet
|
2008-05-20 06:01:26 -04:00
|
|
|
if(m_clock - m_finish_delay_start_time
|
|
|
|
< TIME_DELAY_TILL_FINISH) return;
|
2008-05-19 23:33:48 -04:00
|
|
|
|
|
|
|
m_phase = FINISH_PHASE;
|
|
|
|
estimateFinishTimes();
|
|
|
|
unlock_manager->raceFinished();
|
|
|
|
return;
|
2008-04-15 09:57:18 -04:00
|
|
|
}
|
2008-02-12 20:02:02 -05:00
|
|
|
default : break;
|
|
|
|
} // switch
|
2008-05-19 23:33:48 -04:00
|
|
|
|
2008-04-15 09:57:18 -04:00
|
|
|
if(race_manager->getRaceMode()==RaceManager::RM_FOLLOW_LEADER)
|
2008-05-19 23:33:48 -04:00
|
|
|
return updateLeaderMode(dt);
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
|
2008-05-19 23:33:48 -04:00
|
|
|
// The status must now be race mode!
|
|
|
|
// =================================
|
|
|
|
m_clock += dt;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-05-19 23:33:48 -04:00
|
|
|
// 2) A player comes in last, go immediately to finish phase
|
|
|
|
// =========================================================
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
if(race_manager->getFinishedKarts() >= race_manager->getNumKarts() )
|
2008-02-07 23:43:35 -05:00
|
|
|
{
|
|
|
|
m_phase = FINISH_PHASE;
|
2008-05-19 23:33:48 -04:00
|
|
|
if(user_config->m_profile<0) printProfileResultAndExit();
|
|
|
|
unlock_manager->raceFinished();
|
2008-02-17 23:16:57 -05:00
|
|
|
} // if all karts are finished
|
2008-02-07 23:43:35 -05:00
|
|
|
|
2008-05-19 23:33:48 -04:00
|
|
|
// 3) All player karts are finished, but computer still racing
|
|
|
|
// ===========================================================
|
|
|
|
else if(race_manager->allPlayerFinished())
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-05-19 23:33:48 -04:00
|
|
|
// Set delay mode to have time for camera animation, and
|
|
|
|
// to give the AI some time to get non-estimated timings
|
2007-05-27 12:01:53 -04:00
|
|
|
m_phase = DELAY_FINISH_PHASE;
|
2008-05-20 06:01:26 -04:00
|
|
|
m_finish_delay_start_time = m_clock;
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
2008-05-19 23:33:48 -04:00
|
|
|
} // updateRaceStatus
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void World::estimateFinishTimes()
|
|
|
|
{
|
|
|
|
for ( Karts::size_type i = 0; i < m_kart.size(); ++i)
|
|
|
|
{
|
|
|
|
if(!m_kart[i]->hasFinishedRace())
|
|
|
|
{
|
|
|
|
const float est_finish_time = m_kart[i]->estimateFinishTime();
|
|
|
|
m_kart[i]->raceFinished(est_finish_time);
|
|
|
|
} // if !hasFinishedRace
|
|
|
|
} // for i
|
|
|
|
} // estimateFinishTimes
|
2008-02-07 23:43:35 -05:00
|
|
|
|
2008-05-19 23:33:48 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void World::updateLeaderMode(float dt)
|
|
|
|
{
|
|
|
|
// Count 'normal' till race phase has started, then count backwards
|
|
|
|
if(m_phase==RACE_PHASE || m_phase==GO_PHASE)
|
|
|
|
m_clock -=dt;
|
|
|
|
else
|
|
|
|
m_clock +=dt;
|
|
|
|
if(m_clock<0.0f)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-05-19 23:33:48 -04:00
|
|
|
if(m_leader_intervals.size()>1)
|
|
|
|
m_leader_intervals.erase(m_leader_intervals.begin());
|
|
|
|
m_clock=m_leader_intervals[0];
|
|
|
|
int kart_number;
|
|
|
|
// If the leader kart is not the first kart, remove the first
|
|
|
|
// kart, otherwise remove the last kart.
|
|
|
|
int position_to_remove = m_kart[0]->getPosition()==1
|
|
|
|
? getCurrentNumKarts() : 1;
|
|
|
|
for (kart_number=0; kart_number<(int)m_kart.size(); kart_number++)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-05-19 23:33:48 -04:00
|
|
|
if(m_kart[kart_number]->isEliminated()) continue;
|
|
|
|
if(m_kart[kart_number]->getPosition()==position_to_remove)
|
|
|
|
break;
|
|
|
|
}
|
2008-05-25 04:20:15 -04:00
|
|
|
if(kart_number==(int)m_kart.size())
|
2008-05-19 23:33:48 -04:00
|
|
|
{
|
|
|
|
fprintf(stderr,"Problem with removing leader: position %d not found\n",
|
|
|
|
position_to_remove);
|
|
|
|
for(int i=0; i<(int)m_kart.size(); i++)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2008-05-19 23:33:48 -04:00
|
|
|
fprintf(stderr,"kart %d: eliminated %d position %d\n",
|
|
|
|
i,m_kart[i]->isEliminated(), m_kart[i]->getPosition());
|
|
|
|
} // for i
|
|
|
|
} // kart_number==m_kart.size()
|
|
|
|
else
|
|
|
|
{
|
|
|
|
removeKart(kart_number);
|
|
|
|
}
|
|
|
|
// The follow the leader race is over if there is only one kart left,
|
|
|
|
// or if all players have gone
|
|
|
|
if(getCurrentNumKarts()==2 ||getCurrentNumPlayers()==0)
|
|
|
|
{
|
|
|
|
// Add the results for the remaining kart
|
|
|
|
for(int i=1; i<(int)race_manager->getNumKarts(); i++)
|
|
|
|
if(!m_kart[i]->isEliminated())
|
|
|
|
race_manager->RaceFinished(m_kart[i], m_clock);
|
|
|
|
m_phase=FINISH_PHASE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} // m_clock<0
|
|
|
|
return;
|
|
|
|
|
|
|
|
} // updateLeaderMode
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void World::printProfileResultAndExit()
|
|
|
|
{
|
|
|
|
float min_t=999999.9f, max_t=0.0, av_t=0.0;
|
|
|
|
for ( Karts::size_type i = 0; i < m_kart.size(); ++i)
|
|
|
|
{
|
|
|
|
max_t = std::max(max_t, m_kart[i]->getFinishTime());
|
|
|
|
min_t = std::min(min_t, m_kart[i]->getFinishTime());
|
|
|
|
av_t += m_kart[i]->getFinishTime();
|
|
|
|
printf("%s start %d end %d time %f\n",
|
|
|
|
m_kart[i]->getName().c_str(),(int)i,
|
|
|
|
m_kart[i]->getPosition(),
|
|
|
|
m_kart[i]->getFinishTime());
|
|
|
|
}
|
|
|
|
printf("min %f max %f av %f\n",min_t, max_t, av_t/m_kart.size());
|
|
|
|
std::exit(-2);
|
|
|
|
} // printProfileResultAndExit
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-04-15 09:57:18 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/** Called in follow-leader-mode to remove the last kart
|
|
|
|
*/
|
|
|
|
void World::removeKart(int kart_number)
|
|
|
|
{
|
|
|
|
Kart *kart = m_kart[kart_number];
|
|
|
|
// Display a message about the eliminated kart in the race gui
|
|
|
|
RaceGUI* m=(RaceGUI*)menu_manager->getRaceMenu();
|
|
|
|
if(m)
|
|
|
|
{
|
|
|
|
for (std::vector<PlayerKart*>::iterator i = m_player_karts.begin();
|
|
|
|
i != m_player_karts.end(); i++ )
|
|
|
|
{
|
|
|
|
if(*i==kart)
|
|
|
|
{
|
|
|
|
m->addMessage(_("You have been\neliminated!"), *i, 2.0f, 60);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char s[MAX_MESSAGE_LENGTH];
|
|
|
|
snprintf(s, MAX_MESSAGE_LENGTH,_("'%s' has\nbeen eliminated."),
|
|
|
|
kart->getName().c_str());
|
|
|
|
m->addMessage( s, *i, 2.0f, 60);
|
|
|
|
}
|
|
|
|
} // for i in kart
|
|
|
|
} // if raceMenu exist
|
|
|
|
if(kart->isPlayerKart())
|
|
|
|
{
|
|
|
|
// Change the camera so that it will be attached to the leader
|
|
|
|
// and facing backwards.
|
|
|
|
Camera* camera=((PlayerKart*)kart)->getCamera();
|
|
|
|
camera->setMode(Camera::CM_LEADER_MODE);
|
|
|
|
m_eliminated_players++;
|
|
|
|
}
|
2008-04-16 20:20:06 -04:00
|
|
|
projectile_manager->newExplosion(kart->getCoord());
|
|
|
|
// 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
|
|
|
|
// over all karts, use race_manager->getNumKarts() instead!
|
2008-05-19 23:33:48 -04:00
|
|
|
race_manager->RaceFinished(kart, m_clock);
|
2008-04-15 09:57:18 -04:00
|
|
|
race_manager->eliminate(kart_number);
|
|
|
|
kart->eliminate();
|
|
|
|
m_eliminated_karts++;
|
|
|
|
|
|
|
|
} // removeKart
|
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void World::updateRacePosition ( int k )
|
|
|
|
{
|
|
|
|
int p = 1 ;
|
|
|
|
|
|
|
|
/* Find position of kart 'k' */
|
|
|
|
|
|
|
|
for ( Karts::size_type j = 0 ; j < m_kart.size() ; ++j )
|
|
|
|
{
|
2008-04-15 09:57:18 -04:00
|
|
|
if(int(j) == k) continue;
|
2008-04-16 20:20:06 -04:00
|
|
|
if(m_kart[j]->isEliminated()) continue; // eliminated karts
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
// Count karts ahead of the current kart, i.e. kart that are already
|
|
|
|
// finished (the current kart k has not yet finished!!), have done more
|
|
|
|
// laps, or the same number of laps, but a greater distance.
|
2008-05-19 23:33:48 -04:00
|
|
|
if (m_kart[j]->hasFinishedRace() ||
|
2007-05-27 12:01:53 -04:00
|
|
|
m_kart[j]->getLap() > m_kart[k]->getLap() ||
|
|
|
|
(m_kart[j]->getLap() == m_kart[k]->getLap() &&
|
|
|
|
m_kart[j]->getDistanceDownTrack() > m_kart[k]->getDistanceDownTrack()) )
|
|
|
|
p++ ;
|
|
|
|
}
|
|
|
|
|
2008-04-15 09:57:18 -04:00
|
|
|
m_kart[k]->setPosition(p);
|
2008-05-07 21:28:07 -04:00
|
|
|
// Switch on faster music (except in follow leader mode) if not already
|
|
|
|
// done so, and the first kart is doing its last lap, and the estimated
|
|
|
|
// remaining time is less than 30 seconds.
|
|
|
|
if(!m_faster_music_active &&
|
|
|
|
m_kart[k]->getLap()==race_manager->getNumLaps()-1 &&
|
|
|
|
p==1 &&
|
|
|
|
race_manager->getRaceMode()!=RaceManager::RM_FOLLOW_LEADER &&
|
|
|
|
m_kart[k]->estimateFinishTime()-getTime()<30.0f )
|
|
|
|
{
|
|
|
|
sound_manager->switchToFastMusic();
|
|
|
|
m_faster_music_active=true;
|
|
|
|
}
|
2007-05-27 12:01:53 -04:00
|
|
|
} // updateRacePosition
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void World::loadTrack()
|
|
|
|
{
|
|
|
|
// remove old herrings (from previous race), and remove old
|
|
|
|
// track specific herring models
|
|
|
|
herring_manager->cleanup();
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
if(race_manager->getRaceMode()== RaceManager::RM_GRAND_PRIX)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
herring_manager->loadHerringStyle(race_manager->getHerringStyle());
|
2007-05-27 12:01:53 -04:00
|
|
|
}
|
|
|
|
catch(std::runtime_error)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "The cup '%s' contains an invalid herring style '%s'.\n",
|
|
|
|
race_manager->getGrandPrix()->getName().c_str(),
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
race_manager->getHerringStyle().c_str());
|
2007-05-27 12:01:53 -04:00
|
|
|
fprintf(stderr, "Please fix the file '%s'.\n",
|
|
|
|
race_manager->getGrandPrix()->getFilename().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
herring_manager->loadHerringStyle(m_track->getHerringStyle());
|
|
|
|
}
|
|
|
|
catch(std::runtime_error)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "The track '%s' contains an invalid herring style '%s'.\n",
|
|
|
|
m_track->getName(), m_track->getHerringStyle().c_str());
|
|
|
|
fprintf(stderr, "Please fix the file '%s'.\n",
|
|
|
|
m_track->getFilename().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-12 09:07:26 -05:00
|
|
|
m_track->loadTrackModel();
|
2007-05-27 12:01:53 -04:00
|
|
|
} // loadTrack
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void World::restartRace()
|
|
|
|
{
|
2008-05-07 21:28:07 -04:00
|
|
|
m_clock = 0.0f;
|
|
|
|
m_phase = SETUP_PHASE;
|
2008-05-25 04:20:15 -04:00
|
|
|
m_previous_phase = SETUP_PHASE;
|
2008-05-07 21:28:07 -04:00
|
|
|
m_faster_music_active = false;
|
|
|
|
m_eliminated_karts = 0;
|
|
|
|
m_eliminated_players = 0;
|
|
|
|
m_leader_intervals = stk_config->m_leader_intervals;
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
for ( Karts::iterator i = m_kart.begin(); i != m_kart.end() ; ++i )
|
|
|
|
{
|
|
|
|
(*i)->reset();
|
|
|
|
}
|
|
|
|
resetAllKarts();
|
2008-05-07 21:28:07 -04:00
|
|
|
sound_manager->stopMusic(); // Start music from beginning
|
|
|
|
m_track->startMusic();
|
2007-05-27 12:01:53 -04:00
|
|
|
herring_manager->reset();
|
|
|
|
projectile_manager->cleanup();
|
|
|
|
race_manager->reset();
|
2008-02-05 06:56:21 -05:00
|
|
|
callback_manager->reset();
|
2007-09-21 15:17:48 -04:00
|
|
|
|
2008-02-11 19:01:27 -05:00
|
|
|
// Resets the cameras in case that they are pointing too steep up or down
|
|
|
|
scene->reset();
|
2007-09-21 15:17:48 -04:00
|
|
|
#ifdef HAVE_GHOST_REPLAY
|
|
|
|
m_replay_recorder.destroy();
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
m_replay_recorder.initRecorder( race_manager->getNumKarts() );
|
2007-09-21 15:17:48 -04:00
|
|
|
|
2007-11-03 09:13:26 -04:00
|
|
|
if( m_p_replay_player )
|
2007-09-21 15:17:48 -04:00
|
|
|
{
|
|
|
|
m_p_replay_player->reset();
|
|
|
|
m_p_replay_player->showReplayAt( 0.0 );
|
|
|
|
}
|
|
|
|
#endif
|
2008-02-11 19:01:27 -05:00
|
|
|
} // restartRace
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
Kart* World::loadRobot(const std::string& kart_name, int position,
|
|
|
|
sgCoord init_pos)
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
|
|
|
Kart* currentRobot;
|
|
|
|
|
|
|
|
const int NUM_ROBOTS = 1;
|
|
|
|
|
2007-11-03 09:13:26 -04:00
|
|
|
srand((unsigned)std::time(0));
|
2007-05-27 12:01:53 -04:00
|
|
|
|
|
|
|
switch(rand() % NUM_ROBOTS)
|
|
|
|
{
|
|
|
|
case 0:
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
currentRobot = new DefaultRobot(kart_name, position, init_pos);
|
2007-05-27 12:01:53 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cerr << "Warning: Unknown robot, using default." << std::endl;
|
1) Removed race_setup and race_mode data structures. All this
information is now only managed by the race_manager, no
more in-between objects to transfer information along.
2) The scores for grand prix are now defined in the stk_config.dat
file (10, 8, 6, 5, 4, .., 1, 0, 0) points
3) Bugfix: unlock information wasn't saved anymore. Added specific
saving after unlocking, plus re-inserted the 'generic' save
at the end of STK again.
4) bugfix/work around: Visual Studio complains about incompatible
iterators in sdldrv - apparently caused by using erase, and
then keep on using the iterator.
5) Fixed bug when running a race in a GP again (scores/times
were added each time).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1681 178a84e3-b1eb-0310-8ba1-8eac791a3b58
2008-04-09 09:52:48 -04:00
|
|
|
currentRobot = new DefaultRobot(kart_name, position, init_pos);
|
2007-05-27 12:01:53 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentRobot;
|
|
|
|
}
|
|
|
|
|
2007-06-09 21:13:39 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void World::pause()
|
|
|
|
{
|
|
|
|
sound_manager -> pauseMusic() ;
|
2008-05-25 04:20:15 -04:00
|
|
|
m_previous_phase = m_phase;
|
2007-06-09 21:13:39 -04:00
|
|
|
m_phase = LIMBO_PHASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void World::unpause()
|
|
|
|
{
|
2008-05-08 20:14:55 -04:00
|
|
|
sound_manager -> resumeMusic() ;
|
2008-05-25 04:20:15 -04:00
|
|
|
m_phase = m_previous_phase;
|
2007-06-09 21:13:39 -04:00
|
|
|
}
|
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
/* EOF */
|