SuperTuxKart
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Attributes | Friends | List of all members
MaxSpeed Class Reference

Classes

class  SpeedDecrease
 An internal class to store and handle speed decrease related data. More...
 
class  SpeedIncrease
 An internal class to store and handle speed increase related data. More...
 

Public Types

enum  {
  MS_INCREASE_MIN , MS_INCREASE_ZIPPER = MS_INCREASE_MIN , MS_INCREASE_SLIPSTREAM , MS_INCREASE_NITRO ,
  MS_INCREASE_RUBBER , MS_INCREASE_SKIDDING , MS_INCREASE_RED_SKIDDING , MS_INCREASE_MAX
}
 The categories to use for increasing the speed of a kart: Increase due to zipper, slipstream, nitro, rubber band, skidding usage.
 
enum  {
  MS_DECREASE_MIN , MS_DECREASE_TERRAIN = MS_DECREASE_MIN , MS_DECREASE_AI , MS_DECREASE_BUBBLE ,
  MS_DECREASE_SQUASH , MS_DECREASE_MAX
}
 The categories to use for decreasing the speed of a kart: Decrease due to terrain, different AI levels and end controller.
 

Public Member Functions

 MaxSpeed (AbstractKart *kart)
 This class handles maximum speed for karts.
 
void increaseMaxSpeed (unsigned int category, float add_speed, float engine_force, int duration, int fade_out_time)
 Sets an increased maximum speed for a category.
 
void instantSpeedIncrease (unsigned int category, float add_speed, float speed_boost, float engine_force, int duration, int fade_out_time)
 This adjusts the top speed using increaseMaxSpeed, but additionally causes an instant speed boost, which can be smaller than add-max-speed.
 
void setSlowdown (unsigned int category, float max_speed_fraction, int fade_in_time, int duration=-1)
 Defines a slowdown, which is in fraction of top speed.
 
int getSpeedIncreaseTicksLeft (unsigned int category)
 Returns how much increased speed time is left over in the given category.
 
int isSpeedIncreaseActive (unsigned int category)
 Returns if increased speed is active in the given category.
 
int isSpeedDecreaseActive (unsigned int category)
 Returns if decreased speed is active in the given category.
 
void update (int ticks)
 Updates all speed increase and decrease objects, and determines the current maximum speed.
 
void reset ()
 Reset to prepare for a restart.
 
void saveState (BareNetworkString *buffer) const
 Saves the speed data in a network string for rewind.
 
void rewindTo (BareNetworkString *buffer)
 Restore a saved state.
 
void setMinSpeed (float s)
 Sets the minimum speed a kart should have.
 
float getCurrentMaxSpeed () const
 Returns the current maximum speed for this kart.
 
float getCurrentAdditionalEngineForce () const
 Returns the additional engine force.
 

Private Attributes

AbstractKartm_kart
 A pointer to the kart to which this speed handling object belongs.
 
float m_current_max_speed
 The current maximum speed.
 
float m_add_engine_force
 Additional engine force, summed from all SpeedIncrease engine forces.
 
float m_min_speed
 If >0 then the minimum speed a kart should have (used for zippers).
 
SpeedDecrease m_speed_decrease [MS_DECREASE_MAX]
 Stores all speed decrease related information for each possible category.
 
SpeedIncrease m_speed_increase [MS_INCREASE_MAX]
 Stores all speed increase related information for each possible category.
 

Friends

class KartRewinder
 

Constructor & Destructor Documentation

◆ MaxSpeed()

MaxSpeed::MaxSpeed ( AbstractKart kart)

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).

Member Function Documentation

◆ getSpeedIncreaseTicksLeft()

int MaxSpeed::getSpeedIncreaseTicksLeft ( unsigned int  category)

Returns how much increased speed time is left over in the given category.

Parameters
categoryWhich category to report on.

◆ increaseMaxSpeed()

void MaxSpeed::increaseMaxSpeed ( unsigned int  category,
float  add_speed,
float  engine_force,
int  duration,
int  fade_out_time 
)

Sets an increased maximum speed for a category.

Parameters
categoryThe category for which to set the higher maximum speed.
add_speedHow much speed (in m/s) is added to the maximum speed.
durationHow long the speed increase will last.
fade_out_timeHow long the maximum speed will fade out linearly.

◆ instantSpeedIncrease()

void MaxSpeed::instantSpeedIncrease ( unsigned int  category,
float  add_max_speed,
float  speed_boost,
float  engine_force,
int  duration,
int  fade_out_time 
)

This adjusts the top speed using increaseMaxSpeed, but additionally causes an instant speed boost, which can be smaller than add-max-speed.

(e.g. a zipper can give an instant boost of 5 m/s, but over time would allow the speed to go up by 10 m/s). Note that bullet does not restrict speed (e.g. by simulating air resistance), so without capping the speed (which is done my this object) the speed would go arbitrary high over time

Parameters
categoryThe category for which the speed is increased.
add_max_speedIncrease of the maximum allowed speed.
speed_boostAn instant speed increase for this kart.
engine_forceAdditional engine force.
durationDuration of the increased speed.
fade_out_timeHow long the maximum speed will fade out linearly.

◆ isSpeedDecreaseActive()

int MaxSpeed::isSpeedDecreaseActive ( unsigned int  category)

Returns if decreased speed is active in the given category.

Parameters
categoryWhich category to report on.

◆ isSpeedIncreaseActive()

int MaxSpeed::isSpeedIncreaseActive ( unsigned int  category)

Returns if increased speed is active in the given category.

Parameters
categoryWhich category to report on.

◆ reset()

void MaxSpeed::reset ( )

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.

◆ rewindTo()

void MaxSpeed::rewindTo ( BareNetworkString buffer)

Restore a saved state.

Parameters
bufferSaved state.

◆ saveState()

void MaxSpeed::saveState ( BareNetworkString buffer) const

Saves the speed data in a network string for rewind.

Parameters
bufferPointer to the network string to store the data.

◆ setMinSpeed()

void MaxSpeed::setMinSpeed ( float  s)
inline

Sets the minimum speed a kart should have.

This is used to guarantee that e.g. zippers on ramps will always fast enough for the karts to reach the other end. If set to a negative number, it will have no effect.

◆ setSlowdown()

void MaxSpeed::setSlowdown ( unsigned int  category,
float  max_speed_fraction,
int  fade_in_ticks,
int  duration = -1 
)

Defines a slowdown, which is in fraction of top speed.

Parameters
categoryThe category for which the speed is increased.
max_speed_fractionFraction of top speed to allow only.
fade_in_timeHow long till maximum speed is capped.
durationHow long the effect will lasts. The value of -1 (default) indicates that this effect stays active forever (i.e. till its value is changed to something else).

◆ update()

void MaxSpeed::update ( int  ticks)

Updates all speed increase and decrease objects, and determines the current maximum speed.

Note that the function can be called with dt=0, in which case the maximum speed will be updated, but no change to any of the speed increase/decrease objects will be done.

Parameters
dtTime step size (dt=0 only updates the current maximum speed).

The documentation for this class was generated from the following files: