// $Id: max_speed.cpp 6306 2010-10-18 06:04:05Z hikerstk $ // // SuperTuxKart - a fun racing game with go-kart // Copyright (C) 2010 Joerg Henrichs // // 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 "karts/max_speed.hpp" #include #include #include "karts/kart.hpp" /** This class handles maximum speed for karts. Several factors can influence * the maximum speed a kart can drive, some will decrease the maximum speed, * some will increase the maximum speed. * Slowdowns are specified in fraction of the (kart specific) maximum speed * of that kart. The following categories are defined: * - terrain-specific slow downs * - AI related slow down (low level AIs might drive slower than player) * - end controller related AI (end controller drives slower) * The largest slowdown of all those factors is applied to the maximum * speed of the kart. * Increase of maximum speed is given absolute, i.e. in m/s. The following * circumstances can increase the maximum speed: * - Use of a zipper * - Use of sliptstream * - Use of nitro * The speed increases for all those are added after applying the maximum * slowdown fraction. * At the end the maximum is capped by a value specified in stk_config * (to avoid issues with physics etc). */ MaxSpeed::MaxSpeed(Kart *kart) { m_kart = kart; } // MaxSpeed // ---------------------------------------------------------------------------- /** Reset to prepare for a restart. It just overwrites each entry with a * newly constructed values, i.e. values that don't cause any slowdown * or speedup. */ void MaxSpeed::reset() { m_current_max_speed = m_kart->getKartProperties()->getMaxSpeed(); for(unsigned int i=MS_DECREASE_MIN; i=MS_INCREASE_MIN && category 0) return; // Now we are in the fade out period: decrease time linearly m_current_speedup -= dt*m_max_add_speed/m_fade_out_time; } // SpeedIncrease::update // ---------------------------------------------------------------------------- void MaxSpeed::setSlowdown(unsigned int category, float max_speed_fraction, float fade_in_time) { assert(category>=MS_DECREASE_MIN && category 0) { if (diff * m_fade_in_time > dt) m_current_fraction -= dt/m_fade_in_time; else m_current_fraction = m_max_speed_fraction; } else m_current_fraction = m_max_speed_fraction; } // SpeedDecrease::update // ---------------------------------------------------------------------------- float MaxSpeed::getSpeedIncreaseTimeLeft(unsigned int category) { return m_speed_increase[category].getTimeLeft(); } // getSpeedIncreaseTimeLeft // ---------------------------------------------------------------------------- void MaxSpeed::update(float dt) { // First comput the minimum max-speed fraction, which // determines the overall decrease of maximum speed. // --------------------------------------------------- float f = 1.0f; for(unsigned int i=MS_DECREASE_MIN; igetKartProperties()->getMaxSpeed() * f; // Then add the speed increase from each category // ---------------------------------------------- for(unsigned int i=MS_INCREASE_MIN; icapSpeed(m_current_max_speed); } // update // ----------------------------------------------------------------------------