2008-09-21 21:52:28 -04:00
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2004 SuperTuxKart-Team
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
#include "modes/clock.hpp"
|
|
|
|
#include "modes/world.hpp"
|
|
|
|
#include "audio/sound_manager.hpp"
|
|
|
|
#include "audio/sfx_manager.hpp"
|
|
|
|
#include "audio/sfx_base.hpp"
|
2008-10-04 13:32:40 -04:00
|
|
|
#include "network/network_manager.hpp"
|
|
|
|
#include "network/race_state.hpp"
|
2008-09-21 21:52:28 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-04 13:32:40 -04:00
|
|
|
TimedRace::TimedRace()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
m_mode = CHRONO;
|
|
|
|
m_time = 0.0f;
|
|
|
|
m_auxiliary_timer = 0.0f;
|
|
|
|
m_phase = SETUP_PHASE;
|
|
|
|
m_previous_phase = SETUP_PHASE; // initialise it just in case
|
|
|
|
|
|
|
|
// for profiling AI
|
|
|
|
m_phase = user_config->m_profile ? RACE_PHASE : SETUP_PHASE;
|
|
|
|
|
|
|
|
// FIXME - is it a really good idea to reload and delete the sound every race??
|
|
|
|
m_prestart_sound = sfx_manager->newSFX(SFXManager::SOUND_PRESTART);
|
|
|
|
m_start_sound = sfx_manager->newSFX(SFXManager::SOUND_START);
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-04 13:32:40 -04:00
|
|
|
void TimedRace::reset()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
m_time = 0.0f;
|
|
|
|
m_auxiliary_timer = 0.0f;
|
|
|
|
m_phase = READY_PHASE; // FIXME - unsure
|
|
|
|
m_previous_phase = SETUP_PHASE;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-04 13:32:40 -04:00
|
|
|
TimedRace::~TimedRace()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
sfx_manager->deleteSFX(m_prestart_sound);
|
|
|
|
sfx_manager->deleteSFX(m_start_sound);
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-04 14:50:45 -04:00
|
|
|
void TimedRace::setClockMode(const ClockType mode, const float initial_time)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
m_mode = mode;
|
|
|
|
m_time = initial_time;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-04 13:32:40 -04:00
|
|
|
void TimedRace::enterRaceOverState(const bool delay)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
2008-09-22 08:14:55 -04:00
|
|
|
if(m_phase == DELAY_FINISH_PHASE || m_phase == FINISH_PHASE) return; // we already know
|
2008-09-21 21:52:28 -04:00
|
|
|
|
|
|
|
if(delay)
|
|
|
|
{
|
|
|
|
m_phase = DELAY_FINISH_PHASE;
|
|
|
|
m_auxiliary_timer = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_phase = FINISH_PHASE;
|
2008-10-04 13:32:40 -04:00
|
|
|
|
|
|
|
if(network_manager->getMode()==NetworkManager::NW_SERVER)
|
|
|
|
network_manager->sendRaceResults();
|
2008-09-21 21:52:28 -04:00
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-04 13:32:40 -04:00
|
|
|
void TimedRace::update(const float dt)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
switch(m_phase)
|
|
|
|
{
|
|
|
|
// 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_auxiliary_timer = 0.0f;
|
|
|
|
m_phase = READY_PHASE;
|
|
|
|
m_prestart_sound->play();
|
|
|
|
return; // loading time, don't play sound yet
|
|
|
|
case READY_PHASE:
|
|
|
|
if(m_auxiliary_timer>1.0)
|
|
|
|
{
|
|
|
|
m_phase=SET_PHASE;
|
|
|
|
m_prestart_sound->play();
|
|
|
|
}
|
|
|
|
m_auxiliary_timer += dt;
|
|
|
|
return;
|
|
|
|
case SET_PHASE :
|
|
|
|
if(m_auxiliary_timer>2.0)
|
|
|
|
{
|
|
|
|
// set phase is over, go to the next one
|
|
|
|
m_phase=GO_PHASE;
|
|
|
|
|
|
|
|
m_start_sound->play();
|
|
|
|
|
2008-10-04 13:32:40 -04:00
|
|
|
// event
|
|
|
|
onGo();
|
2008-09-21 21:52:28 -04:00
|
|
|
}
|
|
|
|
m_auxiliary_timer += dt;
|
|
|
|
return;
|
|
|
|
case GO_PHASE :
|
|
|
|
if(m_auxiliary_timer>3.0) // how long to display the 'go' message
|
2008-10-04 14:50:45 -04:00
|
|
|
m_phase=MUSIC_PHASE;
|
|
|
|
m_auxiliary_timer += dt;
|
|
|
|
break;
|
|
|
|
case MUSIC_PHASE:
|
2008-10-06 09:40:11 -04:00
|
|
|
// how long to display the 'music' message
|
|
|
|
if(m_auxiliary_timer>stk_config->m_music_credit_time)
|
2008-10-04 14:50:45 -04:00
|
|
|
m_phase=RACE_PHASE;
|
2008-09-21 21:52:28 -04:00
|
|
|
m_auxiliary_timer += dt;
|
|
|
|
break;
|
|
|
|
case DELAY_FINISH_PHASE :
|
|
|
|
{
|
|
|
|
m_auxiliary_timer += dt;
|
|
|
|
|
|
|
|
// Nothing more to do if delay time is not over yet
|
2008-10-06 09:40:11 -04:00
|
|
|
if(m_auxiliary_timer < stk_config->m_delay_finish_time) break;
|
2008-09-21 21:52:28 -04:00
|
|
|
|
|
|
|
m_phase = FINISH_PHASE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FINISH_PHASE:
|
2008-10-04 13:32:40 -04:00
|
|
|
// event
|
|
|
|
terminateRace();
|
2008-09-21 21:52:28 -04:00
|
|
|
return;
|
2008-10-09 19:33:14 -04:00
|
|
|
default: break; // default for RACE_PHASE, LIMBO_PHASE
|
2008-09-21 21:52:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(m_mode)
|
|
|
|
{
|
|
|
|
case CHRONO:
|
|
|
|
m_time += dt;
|
|
|
|
break;
|
|
|
|
case COUNTDOWN:
|
|
|
|
m_time -= dt;
|
|
|
|
|
|
|
|
if(m_time <= 0.0)
|
|
|
|
{
|
2008-10-04 13:32:40 -04:00
|
|
|
// event
|
|
|
|
countdownReachedZero();
|
2008-09-21 21:52:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-04 13:32:40 -04:00
|
|
|
void TimedRace::setTime(const float time)
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
m_time = time;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-04 13:32:40 -04:00
|
|
|
void TimedRace::pause()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
m_previous_phase = m_phase;
|
|
|
|
m_phase = LIMBO_PHASE;
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-10-04 13:32:40 -04:00
|
|
|
void TimedRace::unpause()
|
2008-09-21 21:52:28 -04:00
|
|
|
{
|
|
|
|
m_phase = m_previous_phase;
|
|
|
|
}
|
|
|
|
|