SuperTuxKart
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | Friends | List of all members
Kart Class Reference

The main kart class. More...

#include <kart.hpp>

Inheritance diagram for Kart:
Inheritance graph
[legend]

Classes

struct  btCompoundShapeDeleter
 

Public Member Functions

 Kart (const std::string &ident, unsigned int world_kart_id, int position, const btTransform &init_transform, HandicapLevel handicap, std::shared_ptr< RenderInfo > ri)
 The kart constructor. More...
 
virtual ~Kart ()
 The destructor frees the memory of this kart, but note that the actual kart model is still stored in the kart_properties (m_kart_model variable), so it is not reloaded).
 
virtual void init (RaceManager::KartType type) OVERRIDE
 This is a second initialisation phase, necessary since in the constructor virtual functions are not called for any superclasses. More...
 
virtual void kartIsInRestNow () OVERRIDE
 Computes the transform of the graphical kart chasses with regards to the physical chassis. More...
 
virtual void updateGraphics (float dt) OVERRIDE
 Updates the graphics model. More...
 
virtual void createPhysics ()
 Creates the physical representation of this kart. More...
 
virtual bool isInRest () const OVERRIDE
 Returns true if the kart is 'resting', i.e. More...
 
virtual void applyEngineForce (float force)
 Applies engine power to all the wheels that are traction capable, so other parts of code do not have to be adjusted to simulate different kinds of vehicles in the general case, only if they are trying to simulate traction control, diferentials or multiple independent electric engines, they will have to tweak the power in a per wheel basis.
 
virtual void flyUp () OVERRIDE
 Enter flying mode.
 
virtual void flyDown () OVERRIDE
 
virtual void startEngineSFX () OVERRIDE
 Starts the engine sound effect. More...
 
virtual void collectedItem (ItemState *item) OVERRIDE
 Called when an item is collected. More...
 
virtual float getStartupBoostFromStartTicks (int ticks) const OVERRIDE
 Called the first time a kart accelerates after 'ready'. More...
 
virtual float getStartupBoost () const OVERRIDE
 
virtual void setStartupBoost (float val) OVERRIDE
 
virtual const MaterialgetMaterial () const OVERRIDE
 Returns the current material the kart is on. More...
 
virtual const MaterialgetLastMaterial () const OVERRIDE
 Returns the previous material the kart was one (which might be the same as getMaterial() ). More...
 
virtual float getTerrainPitch (float heading) const OVERRIDE
 Returns the pitch of the terrain depending on the heading. More...
 
virtual void reset () OVERRIDE
 Reset before a new race. More...
 
virtual void handleZipper (const Material *m=NULL, bool play_sound=false) OVERRIDE
 Sets zipper time, and apply one time additional speed boost. More...
 
virtual bool setSquash (float time, float slowdown) OVERRIDE
 Squashes this kart: it will scale the kart in up direction, and causes a slowdown while this kart is squashed. More...
 
void setSquashGraphics ()
 
virtual void unsetSquash () OVERRIDE
 Makes the kart unsquashed again. More...
 
virtual void crashed (AbstractKart *k, bool update_attachments) OVERRIDE
 Called when the kart crashes against another kart. More...
 
virtual void crashed (const Material *m, const Vec3 &normal) OVERRIDE
 Kart hits the track with a given material. More...
 
virtual float getHoT () const OVERRIDE
 Returns the height of the terrain. More...
 
virtual void update (int ticks) OVERRIDE
 Updates the kart in each time step. More...
 
virtual void finishedRace (float time, bool from_server=false) OVERRIDE
 Sets that this kart has finished the race and finishing time. More...
 
virtual void setPosition (int p) OVERRIDE
 Sets the position in race this kart has . More...
 
virtual void beep () OVERRIDE
 Plays a beep sfx.
 
virtual void showZipperFire () OVERRIDE
 Show fire to go with a zipper.
 
virtual bool playCustomSFX (unsigned int type) OVERRIDE
 This function will play a particular character voice for this kart. More...
 
virtual void setController (Controller *controller) OVERRIDE
 Saves the old controller in m_saved_controller and stores a new controller. More...
 
virtual void setXYZ (const Vec3 &a) OVERRIDE
 Sets the XYZ coordinates of the moveable. More...
 
virtual void changeKart (const std::string &new_ident, HandicapLevel handicap, std::shared_ptr< RenderInfo > ri) OVERRIDE
 Change to new kart instancely (used in network live join). More...
 
virtual void adjustSpeed (float f) OVERRIDE
 Multiplies the velocity of the kart by a factor f (both linear and angular). More...
 
virtual void increaseMaxSpeed (unsigned int category, float add_speed, float engine_force, int duration, int fade_out_time) OVERRIDE
 Sets an increased maximum speed for a category. More...
 
virtual void instantSpeedIncrease (unsigned int category, float add_max_speed, float speed_boost, float engine_force, int duration, int fade_out_time) OVERRIDE
 This adjusts the top speed using increaseMaxSpeed, but additionally causes an instant speed boost, which can be smaller than add-max-speed. More...
 
virtual void setSlowdown (unsigned int category, float max_speed_fraction, int fade_in_time) OVERRIDE
 Defines a slowdown, which is in fraction of top speed. More...
 
virtual int getSpeedIncreaseTicksLeft (unsigned int category) const OVERRIDE
 Returns how much increased speed time is left over in the given category. More...
 
virtual float getSpeed () const OVERRIDE
 Returns the speed of the kart in meters/second. More...
 
virtual float getCurrentMaxSpeed () const OVERRIDE
 Returns the current maximum speed for this kart, this includes all bonus and maluses that are currently applied. More...
 
virtual void setSpeed (float s) OVERRIDE
 This is used on the client side only to set the speed of the kart from the server information. More...
 
virtual float getMaxSteerAngle () const OVERRIDE
 Returns the maximum steering angle for this kart, which depends on the speed. More...
 
virtual float getTimeFullSteer (float steer) const OVERRIDE
 Returns the time till full steering is reached for this kart. More...
 
virtual float getSpeedForTurnRadius (float radius) const OVERRIDE
 Returns the (maximum) speed for a given turn radius. More...
 
virtual float getMaxSteerAngle (float speed) const
 Returns the maximum steering angle (depending on speed). More...
 
virtual const SkiddinggetSkidding () const OVERRIDE
 Returns the skidding object for this kart (which can be used to query skidding related values). More...
 
virtual SkiddinggetSkidding () OVERRIDE
 Returns the skidding object for this kart (which can be used to query skidding related values) - non-const. More...
 
virtual float getEnergy () const OVERRIDE
 Returns the remaining collected energy. More...
 
virtual void setEnergy (float val) OVERRIDE
 Sets the energy the kart has collected. More...
 
virtual bool isOnMinNitroTime () const OVERRIDE
 Return whether nitro is being used despite the nitro button not being pressed due to minimal use time requirements.
 
virtual void setPowerup (PowerupManager::PowerupType t, int n) OVERRIDE
 Sets a new powerup. More...
 
virtual void setLastUsedPowerup (PowerupManager::PowerupType t)
 Sets the last used powerup. More...
 
virtual const PowerupgetPowerup () const OVERRIDE
 Returns the current powerup. More...
 
virtual PowerupgetPowerup () OVERRIDE
 Returns the current powerup. More...
 
virtual PowerupManager::PowerupType getLastUsedPowerup () OVERRIDE
 Returns the last used powerup. More...
 
virtual int getNumPowerup () const OVERRIDE
 Returns the number of powerups. More...
 
virtual void setInvulnerableTicks (int ticks) OVERRIDE
 Makes a kart invulnerable for a certain amount of time. More...
 
virtual bool isInvulnerable () const OVERRIDE
 Returns if the kart is invulnerable. More...
 
virtual int getBlockedByPlungerTicks () const OVERRIDE
 Returns true if the kart has a plunger attached to its face. More...
 
virtual void blockViewWithPlunger () OVERRIDE
 Sets the view to blocked by a plunger. More...
 
virtual void setShieldTime (float t) OVERRIDE
 Enables a kart shield protection for a certain amount of time. More...
 
virtual bool isShielded () const OVERRIDE
 Returns if the kart is protected by a shield. More...
 
virtual float getShieldTime () const OVERRIDE
 Returns the remaining time the kart is protected by a shield. More...
 
virtual void decreaseShieldTime () OVERRIDE
 Decreases the kart's shield time. More...
 
virtual bool isSquashed () const OVERRIDE
 Returns if the kart is currently being squashed. More...
 
virtual void setBoostAI (bool boosted) OVERRIDE
 Sets the kart AI boost state. More...
 
virtual bool getBoostAI () const OVERRIDE
 Returns the kart AI boost state. More...
 
virtual ControllergetController () OVERRIDE
 Returns the controller of this kart. More...
 
const ControllergetController () const OVERRIDE
 Returns the controller of this kart (const version). More...
 
virtual const Vec3getFrontXYZ () const OVERRIDE
 Returns the coordinates of the front of the kart. More...
 
virtual btTransform getAlignedTransform (const float customPitch=-1) OVERRIDE
 Returns a bullet transform object located at the kart's position and oriented in the direction the kart is going. More...
 
const btTransform & getResetTransform () const
 Returns the start transform, i.e. More...
 
virtual bool isOnGround () const OVERRIDE
 True if the wheels are touching the ground. More...
 
bool isNearGround () const
 Returns true if the kart is close to the ground, used to dis/enable the upright constraint to allow for more realistic explosions. More...
 
virtual const Vec3getNormal () const OVERRIDE
 Returns the normal of the terrain the kart is over atm. More...
 
virtual const Vec3getPreviousXYZ () const OVERRIDE
 Returns the position 0.25s before.
 
virtual const Vec3getRecentPreviousXYZ () const OVERRIDE
 Returns a more recent different previous position.
 
virtual const float getRecentPreviousXYZTime () const OVERRIDE
 Returns the time at which the recent previous position occured.
 
bool isFlying () const
 For debugging only: check if a kart is flying. More...
 
virtual bool isJumping () const OVERRIDE
 Returns whether this kart is jumping. More...
 
virtual const TerrainInfogetTerrainInfo () const OVERRIDE
 Returns the terrain info oject. More...
 
virtual KartGFXgetKartGFX () OVERRIDE
 Returns a pointer to this kart's graphical effects. More...
 
virtual int getPosition () const OVERRIDE
 Returns the current position of this kart in the race. More...
 
virtual int getInitialPosition () const OVERRIDE
 Returns the initial position of this kart. More...
 
virtual float getFinishTime () const OVERRIDE
 Returns the finished time for a kart. More...
 
virtual bool hasFinishedRace () const OVERRIDE
 Returns true if this kart has finished the race. More...
 
const irr::video::SColor & getColor () const
 Returns the color used for this kart. More...
 
virtual RaceManager::KartType getType () const OVERRIDE
 
virtual btKartgetVehicle () const OVERRIDE
 Returns the bullet vehicle which represents this kart. More...
 
virtual btQuaternion getVisualRotation () const OVERRIDE
 
virtual const SlipStreamgetSlipstream () const OVERRIDE
 Returns the slipstream object of this kart. More...
 
virtual SlipStreamgetSlipstream () OVERRIDE
 Returns the slipstream object of this kart. More...
 
virtual void setSlipstreamEffect (float f) OVERRIDE
 Activates a slipstream effect, atm that is display some nitro. More...
 
virtual bool isEliminated () const OVERRIDE
 Returns true if the kart is eliminated. More...
 
virtual void eliminate () OVERRIDE
 Marks this kart to be eliminated. More...
 
virtual void setOnScreenText (const core::stringw &text) OVERRIDE
 Sets a text that is being displayed on top of a kart. More...
 
virtual bool getRaceResult () const OVERRIDE
 Returns whether this kart wins or loses. More...
 
void setRaceResult ()
 Set this kart race result. More...
 
virtual bool isGhostKart () const OVERRIDE
 Returns whether this kart is a ghost (replay) kart. More...
 
SFXBasegetNextEmitter ()
 
virtual void playSound (SFXBuffer *buffer) OVERRIDE
 
virtual bool isVisible () const OVERRIDE
 
virtual void showStarEffect (float t) OVERRIDE
 Shows the star effect for a certain time. More...
 
virtual StarsgetStarsEffect () const OVERRIDE
 
int getNetworkConfirmedFinishTicks () const OVERRIDE
 Return the confirmed finish ticks (sent by the server) indicating that this kart has really finished the race. More...
 
- Public Member Functions inherited from AbstractKart
 AbstractKart (const std::string &ident, int world_kart_id, int position, const btTransform &init_transform, HandicapLevel handicap, std::shared_ptr< RenderInfo > ri)
 Creates a kart. More...
 
const core::stringw & getName () const
 Returns a name to be displayed for this kart. More...
 
virtual float getSteerPercent () const
 Returns the current steering value for this kart. More...
 
KartControlgetControls ()
 Returns all controls of this kart. More...
 
const KartControlgetControls () const
 Returns all controls of this kart - const version. More...
 
const KartPropertiesgetKartProperties () const
 Returns the kart properties of this kart. More...
 
const HandicapLevel getHandicap () const
 Returns the handicap of this kart. More...
 
void setHandicap (const HandicapLevel h)
 Sets the handicap. More...
 
virtual const std::string & getIdent () const
 Returns a unique identifier for this kart (name of the directory the kart was loaded from). More...
 
const AttachmentgetAttachment () const
 Returns the current attachment. More...
 
AttachmentgetAttachment ()
 Returns the current attachment, non-const version. More...
 
KartModelgetKartModel () const
 Returns this kart's kart model. More...
 
float getKartLength () const
 Returns the length of the kart. More...
 
float getKartHeight () const
 Returns the height of the kart. More...
 
float getKartWidth () const
 Returns the width of the kart. More...
 
float getHighestPoint () const
 Returns the highest point of the kart (coordinate on up axis)
 
virtual float getTimeForDistance (float distance)
 Returns the time at which the kart was at a given distance. More...
 
bool isWheeless () const
 Returns true if this kart has no wheels. More...
 
const Vec3getWheelGraphicsPosition (int i) const
 Returns the position of a wheel relative to the kart. More...
 
AbstractKartAnimationgetKartAnimation ()
 Returns a kart animation (if any), or NULL if currently no kart animation is being shown. More...
 
const AbstractKartAnimationgetKartAnimation () const
 
virtual void setKartAnimation (AbstractKartAnimation *ka)
 Sets a new kart animation. More...
 
unsigned int getWorldKartId () const
 Returns the index of this kart in world. More...
 
virtual void makeKartRest ()
 Called before go phase to make sure all karts start at the same position in case there is a slope. More...
 
int getLiveJoinUntilTicks () const
 
void setLiveJoinKart (int util_ticks)
 
- Public Member Functions inherited from Moveable
scene::ISceneNode * getNode () const
 Returns the scene node of this moveable. More...
 
void setNode (scene::ISceneNode *n)
 Sets the mesh for this model. More...
 
virtual const btVector3 & getVelocity () const
 
const btVector3 & getVelocityLC () const
 
virtual void setVelocity (const btVector3 &v)
 
const Vec3getXYZ () const
 
float getHeading () const
 Returns the heading between -pi and pi. More...
 
float getPitch () const
 Returns the pitch of the kart, restricted to between -pi/2 and pi/2. More...
 
float getRoll () const
 Returns the roll of the kart between -pi and pi. More...
 
const btQuaternion getRotation () const
 
virtual void stopFlying ()
 
void setRotation (const btMatrix3x3 &m)
 Sets the rotation of the physical body this moveable. More...
 
void setRotation (const btQuaternion &q)
 Sets the rotation of the physical body this moveable. More...
 
btRigidBody * getBody () const
 
void createBody (float mass, btTransform &trans, btCollisionShape *shape, float restitution)
 Creates the bullet rigid body for this moveable. More...
 
const btTransform & getTrans () const
 
void setTrans (const btTransform &t)
 Places this moveable at a certain location and stores this transform in this Moveable, so that it can be accessed easily. More...
 
void updatePosition ()
 Updates the current position and rotation. More...
 
void prepareSmoothing ()
 
void checkSmoothing ()
 
const btTransform & getSmoothedTrans () const
 
const Vec3getSmoothedXYZ () const
 
- Public Member Functions inherited from SmoothNetworkBody
 SmoothNetworkBody (bool enable=false)
 
void reset ()
 
void setEnable (bool val)
 
bool isEnabled () const
 
void setSmoothRotation (bool val)
 
void setAdjustVerticalOffset (bool val)
 
void prepareSmoothing (const btTransform &current_transform, const Vec3 &current_velocity)
 
void checkSmoothing (const btTransform &current_transform, const Vec3 &current_velocity)
 Adds a new error between graphical and physical position/rotation. More...
 
void updateSmoothedGraphics (const btTransform &current_transform, const Vec3 &current_velocity, float dt)
 
void setSmoothedTransform (const btTransform &t)
 
const btTransform & getSmoothedTrans () const
 
const Vec3getSmoothedXYZ () const
 
void setMinAdjustLength (float val)
 
void setMaxAdjustLength (float val)
 
void setMinAdjustSpeed (float val)
 
void setMaxAdjustTime (float val)
 
void setAdjustLengthThreshold (float val)
 

Protected Member Functions

void updatePhysics (int ticks)
 Updates the physics for this kart: computing the driving force, set steering, handles skidding, terrain impact on kart, ... More...
 
void handleMaterialSFX ()
 Plays any terrain specific sound effect.
 
void handleMaterialGFX (float dt)
 Handles material specific GFX, mostly particle effects. More...
 
void updateFlying ()
 Adjusts kart translation if the kart is flying (in debug mode).
 
void updateSliding ()
 Handles sliding, i.e. More...
 
void updateEnginePowerAndBrakes (int ticks)
 Sets the engine power. More...
 
void updateEngineSFX (float dt)
 Adjust the engine sound effect depending on the speed of the kart. More...
 
void updateSpeed ()
 Updates the local speed based on the current physical velocity. More...
 
void updateNitro (int ticks)
 Updates the current nitro status. More...
 
float applyAirFriction (float engine_power)
 Reduces the engine power according to speed. More...
 
float getActualWheelForce ()
 Simulates gears by adjusting the force of the engine. More...
 
void playCrashSFX (const Material *m, AbstractKart *k)
 Common code used when a kart or a material was hit. More...
 
void loadData (RaceManager::KartType type, bool animatedModel)
 Attaches the right model, creates the physics and loads all special effects (particle systems etc.) More...
 
void updateWeight ()
 This method is to be called every time the mass of the kart is updated, which includes attaching an anvil to the kart (and detaching).
 
- Protected Member Functions inherited from Moveable
void updateSmoothedGraphics (float dt)
 
virtual void updateGraphics (const Vec3 &off_xyz=Vec3(0.0f, 0.0f, 0.0f), const btQuaternion &off_rotation=btQuaternion(0.0f, 0.0f, 0.0f, 1.0f))
 Updates the graphics model. More...
 

Protected Attributes

float m_graphical_y_offset
 Offset of the graphical kart chassis from the physical chassis. More...
 
Vec3 m_xyz_front
 The coordinates of the front of the kart, used to determine when a new lap is triggered. More...
 
const float XYZ_HISTORY_TIME = 0.25f
 
int m_xyz_history_size
 
std::vector< Vec3m_previous_xyz
 The coordinates of the XYZ_HISTORY_SIZE previous positions.
 
std::vector< float > m_previous_xyz_times
 The times at which the previous positions occured. More...
 
float m_time_previous_counter
 
bool m_is_jumping
 Is time flying activated.
 
bool m_bubblegum_torque_sign
 The sign of torque to apply after hitting a bubble gum. More...
 
uint8_t m_bounce_back_ticks
 A short time after a collision acceleration is disabled to allow the karts to bounce back.
 
MaxSpeedm_max_speed
 Handles speed increase and capping due to powerup, terrain, ... More...
 
TerrainInfom_terrain_info
 Stores information about the terrain the kart is on. More...
 
Powerupm_powerup
 Handles the powerup of a kart. More...
 
std::unique_ptr< btVehicleRaycaster > m_vehicle_raycaster
 
std::unique_ptr< btKartm_vehicle
 
std::unique_ptr< Skiddingm_skidding
 This object handles all skidding. More...
 
std::unique_ptr< Starsm_stars_effect
 For stars rotating around head effect.
 
std::unique_ptr< Shadowm_shadow
 The shadow of a kart. More...
 
std::unique_ptr< SkidMarksm_skidmarks
 The skidmarks object for this kart. More...
 
std::unique_ptr< KartGFXm_kart_gfx
 All particle effects. More...
 
std::unique_ptr< SlipStreamm_slipstream
 Handles all slipstreaming. More...
 
std::unique_ptr< btCompoundShape, btCompoundShapeDeleterm_kart_chassis
 
ParticleEmitterm_collision_particles
 For collisions.
 
Controllerm_controller
 The main controller of this object, used for driving. More...
 
Controllerm_saved_controller
 This saves the original controller when the end controller is used. More...
 
PowerupManager::PowerupType m_last_used_powerup
 Remember the last used powerup type of a kart for AI purposes. More...
 
bool m_flying
 True if kart is flying (for debug purposes only). More...
 
bool m_has_caught_nolok_bubblegum
 Set when hitting bubblegum.
 
bool m_race_result
 True if the kart wins, false otherwise. More...
 
bool m_eliminated
 True if the kart is eliminated. More...
 
int m_initial_position
 Initial rank of the kart. More...
 
int m_race_position
 Current race position (1-num_karts). More...
 
float m_max_gear_rpm
 Maximum engine rpm's for the current gear. More...
 
int m_brake_ticks
 How long the brake key has been pressed - the longer the harder the kart will brake. More...
 
int16_t m_invulnerable_ticks
 Time a kart is invulnerable. More...
 
int16_t m_bubblegum_ticks
 If > 0 then bubble gum effect is on. More...
 
int16_t m_view_blocked_by_plunger
 When a kart has its view blocked by the plunger, this variable will be

0 the number it contains is the time left before removing plunger.

More...
 
float m_current_lean
 Current leaning of the kart. More...
 
int8_t m_min_nitro_ticks
 To prevent using nitro in too short bursts.
 
bool m_fire_clicked
 True if fire button was pushed and not released.
 
bool m_boosted_ai
 True if the kart has been selected to have a boosted ai.
 
bool m_finished_race
 
float m_finish_time
 
float m_collected_energy
 The amount of energy collected with nitro cans. More...
 
float m_consumption_per_tick
 
float m_energy_to_min_ratio
 
float m_startup_boost
 
float m_falling_time
 
float m_weight
 
float m_speed
 The current speed (i.e. More...
 
float m_last_factor_engine_sound
 For smoothing engine sound.
 
float m_default_suspension_force
 For changeKart.
 
btTransform m_reset_transform
 Reset position. More...
 
std::vector< SFXBase * > m_custom_sounds
 
int m_emitter_id = 0
 
SFXBasem_emitters [EMITTER_COUNT]
 
SFXBasem_engine_sound
 
SFXBasem_terrain_sound
 Sound to be played depending on terrain. More...
 
const Materialm_last_sound_material
 The material for which the last sound effect was played. More...
 
SFXBasem_nitro_sound
 
SFXBasem_previous_terrain_sound
 A pointer to the previous terrain sound needs to be saved so that an 'older' sfx can be finished and an abrupt end of the sfx is avoided. More...
 
SFXBasem_skid_sound
 
SFXBufferm_horn_sound
 
SFXBufferm_crash_sounds [CRASH_SOUND_COUNT]
 
SFXBufferm_goo_sound
 
SFXBufferm_boing_sound
 
int m_ticks_last_crash
 
int m_ticks_last_zipper
 
RaceManager::KartType m_type
 
- Protected Attributes inherited from AbstractKart
btTransform m_starting_transform
 
int m_live_join_util
 
std::unique_ptr< KartPropertiesm_kart_properties
 The kart properties. More...
 
HandicapLevel m_handicap
 The handicap level of this kart. More...
 
std::unique_ptr< KartModelm_kart_model
 This stores a copy of the kart model. More...
 
std::unique_ptr< Attachmentm_attachment
 Handles the attachment the kart might have. More...
 
KartControl m_controls
 The kart controls (e.g. More...
 
AbstractKartAnimationm_kart_animation
 A kart animation object to handle rescue, explosion etc. More...
 
irr::scene::IDummyTransformationSceneNode * m_wheel_box
 Node between wheels and kart. More...
 
- Protected Attributes inherited from Moveable
btTransform m_transform
 The bullet transform of this rigid body. More...
 
UserPointer m_user_pointer
 
scene::ISceneNode * m_node
 
std::unique_ptr< btRigidBody > m_body
 
std::unique_ptr< KartMotionStatem_motion_state
 

Static Protected Attributes

static const int EMITTER_COUNT = 3
 
static const int CRASH_SOUND_COUNT = 3
 

Private Attributes

int m_network_finish_check_ticks
 
int m_network_confirmed_finish_ticks
 

Friends

class Skidding
 

Detailed Description

The main kart class.

All type of karts are of this object, but with different controllers. The controllers are what turn a kart into a player kart (i.e. the controller handle input), or an AI kart (the controller runs the AI code to set steering etc). Kart has two base classes: the most important one is moveable (which is an object that is moved on the track, and has position and rotations) and TerrainInfo, which manages the terrain the kart is on.

Constructor & Destructor Documentation

◆ Kart()

Kart::Kart ( const std::string &  ident,
unsigned int  world_kart_id,
int  position,
const btTransform &  init_transform,
HandicapLevel  handicap,
std::shared_ptr< RenderInfo ri 
)

The kart constructor.

Parameters
identThe identifier for the kart model to use.
positionThe position (or rank) for this kart (between 1 and number of karts). This is used to determine the start position.
init_transformThe initial position and rotation for this kart.

Member Function Documentation

◆ adjustSpeed()

void Kart::adjustSpeed ( float  f)
virtual

Multiplies the velocity of the kart by a factor f (both linear and angular).

This is used by anvils, which suddenly slow down the kart when they are attached.

Implements AbstractKart.

◆ applyAirFriction()

float Kart::applyAirFriction ( float  engine_power)
protected

Reduces the engine power according to speed.

TODO : find where the physics already apply a linear force decrease TODO : While this work fine, it should ideally be in physics However, the function use some kart properties and parachute effect needs to be applied, so keep both working if moving

Parameters
engine_power: the engine power on which to apply the decrease

◆ blockViewWithPlunger()

void Kart::blockViewWithPlunger ( )
virtual

Sets the view to blocked by a plunger.

Sets that the view is blocked by a plunger.

The duration depends on the difficulty, see KartProperties getPlungerInFaceTime.

The duration depends on the difficulty, see KartPorperties getPlungerInFaceTime.

Implements AbstractKart.

◆ changeKart()

void Kart::changeKart ( const std::string &  new_ident,
HandicapLevel  handicap,
std::shared_ptr< RenderInfo ri 
)
virtual

Change to new kart instancely (used in network live join).

Reimplemented from AbstractKart.

◆ collectedItem()

void Kart::collectedItem ( ItemState item_state)
virtual

Called when an item is collected.

It will either adjust the collected energy, or update the attachment or powerup for this kart.

Parameters
item_stateThe item that was hit.

Implements AbstractKart.

Reimplemented in KartWithStats.

◆ crashed() [1/2]

void Kart::crashed ( AbstractKart k,
bool  update_attachments 
)
virtual

Called when the kart crashes against another kart.

Parameters
kThe kart that was hit.
update_attachmentsIf true the attachment of this kart and the other kart hit will be updated (e.g. bombs will be moved)

Implements AbstractKart.

◆ crashed() [2/2]

void Kart::crashed ( const Material m,
const Vec3 normal 
)
virtual

Kart hits the track with a given material.

Parameters
mMaterial hit, can be NULL if no specific material exists.
normalThe normal of the hit (used to push a kart back, which avoids that karts sometimes can get stuck).

If a kart is crashing against the track, the collision is often reported more than once, resulting in a machine gun effect, and too long disabling of the engine. Therefore, this reaction is disabled for 0.5 seconds after a crash.

Implements AbstractKart.

◆ createPhysics()

void Kart::createPhysics ( )
virtual

Creates the physical representation of this kart.

Atm it uses the actual extention of the kart model to determine the size of the collision body.

Reimplemented in GhostKart.

◆ decreaseShieldTime()

void Kart::decreaseShieldTime ( )
virtual

Decreases the kart's shield time.

Parameters
tThe time subtracted from the shield timer. If t == 0.0f, the default amout of time is subtracted.

Implements AbstractKart.

◆ eliminate()

void Kart::eliminate ( )
virtual

Marks this kart to be eliminated.

Implements AbstractKart.

◆ finishedRace()

void Kart::finishedRace ( float  time,
bool  from_server = false 
)
virtual

Sets that this kart has finished the race and finishing time.

It also notifies the race_manager about the race completion for this kart.

Parameters
timeThe finishing time for this kart. It can either be the actual time when the kart finished (in which case time() = world->getTime()), or the estimated time in case that all player kart have finished the race and all AI karts get an estimated finish time set.
from_serverIn a network game, only the server can notify about a kart finishing a race. This parameter is to distinguish between a local detection (which is ignored on clients in a network game), and a server notification.

Implements AbstractKart.

◆ getActualWheelForce()

float Kart::getActualWheelForce ( )
protected

Simulates gears by adjusting the force of the engine.

It also takes the effect of the zipper into account.

◆ getAlignedTransform()

btTransform Kart::getAlignedTransform ( const float  custom_pitch = -1)
virtual

Returns a bullet transform object located at the kart's position and oriented in the direction the kart is going.

Returns a transform that will align an object with the kart: the heading and the pitch will be set appropriately.

Can be useful e.g. to calculate the starting point and direction of projectiles.

A custom pitch value can be specified in order to overwrite the terrain pitch (which would be used otherwise).

Parameters
custom_pitchPitch value to overwrite the terrain pitch. A value of -1 indicates that the custom_pitch value should not be used, instead the actual pitch of the terrain is to be used.

Implements AbstractKart.

◆ getBlockedByPlungerTicks()

virtual int Kart::getBlockedByPlungerTicks ( ) const
inlinevirtual

Returns true if the kart has a plunger attached to its face.

Implements AbstractKart.

◆ getBoostAI()

bool Kart::getBoostAI ( ) const
virtual

Returns the kart AI boost state.

Not pure abstract, since there is no need to implement this e.g. in Ghost.

Implements AbstractKart.

◆ getColor()

const video::SColor & Kart::getColor ( ) const

Returns the color used for this kart.

◆ getController() [1/2]

virtual Controller* Kart::getController ( )
inlinevirtual

Returns the controller of this kart.

Implements AbstractKart.

◆ getController() [2/2]

const Controller* Kart::getController ( ) const
inlinevirtual

Returns the controller of this kart (const version).

Implements AbstractKart.

◆ getCurrentMaxSpeed()

float Kart::getCurrentMaxSpeed ( ) const
virtual

Returns the current maximum speed for this kart, this includes all bonus and maluses that are currently applied.

Implements AbstractKart.

◆ getEnergy()

virtual float Kart::getEnergy ( ) const
inlinevirtual

Returns the remaining collected energy.

Implements AbstractKart.

◆ getFinishTime()

virtual float Kart::getFinishTime ( ) const
inlinevirtual

Returns the finished time for a kart.

Implements AbstractKart.

◆ getFrontXYZ()

virtual const Vec3& Kart::getFrontXYZ ( ) const
inlinevirtual

Returns the coordinates of the front of the kart.

This is used for determining when the lap line is crossed.

Implements AbstractKart.

◆ getHoT()

float Kart::getHoT ( ) const
virtual

Returns the height of the terrain.

we're currently above

Implements AbstractKart.

◆ getInitialPosition()

virtual int Kart::getInitialPosition ( ) const
inlinevirtual

Returns the initial position of this kart.

Implements AbstractKart.

◆ getKartGFX()

virtual KartGFX* Kart::getKartGFX ( )
inlinevirtual

Returns a pointer to this kart's graphical effects.

Implements AbstractKart.

◆ getLastMaterial()

const Material * Kart::getLastMaterial ( ) const
virtual

Returns the previous material the kart was one (which might be the same as getMaterial() ).

Implements AbstractKart.

◆ getLastUsedPowerup()

virtual PowerupManager::PowerupType Kart::getLastUsedPowerup ( )
inlinevirtual

Returns the last used powerup.

Implements AbstractKart.

◆ getMaterial()

const Material * Kart::getMaterial ( ) const
virtual

Returns the current material the kart is on.

Implements AbstractKart.

◆ getMaxSteerAngle() [1/2]

virtual float Kart::getMaxSteerAngle ( ) const
inlinevirtual

Returns the maximum steering angle for this kart, which depends on the speed.

Implements AbstractKart.

◆ getMaxSteerAngle() [2/2]

float Kart::getMaxSteerAngle ( float  speed) const
virtual

Returns the maximum steering angle (depending on speed).

This is proportional to kart length because physics reverse this effect, the results of this function should not be used to determine the real raw steer angle.

◆ getNetworkConfirmedFinishTicks()

int Kart::getNetworkConfirmedFinishTicks ( ) const
inlinevirtual

Return the confirmed finish ticks (sent by the server) indicating that this kart has really finished the race.

Implements AbstractKart.

◆ getNormal()

const Vec3 & Kart::getNormal ( ) const
virtual

Returns the normal of the terrain the kart is over atm.

This is defined even if the kart is flying.

Implements AbstractKart.

◆ getNumPowerup()

int Kart::getNumPowerup ( ) const
virtual

Returns the number of powerups.

Implements AbstractKart.

◆ getPosition()

virtual int Kart::getPosition ( ) const
inlinevirtual

Returns the current position of this kart in the race.

Implements AbstractKart.

◆ getPowerup() [1/2]

virtual const Powerup* Kart::getPowerup ( ) const
inlinevirtual

Returns the current powerup.

Implements AbstractKart.

◆ getPowerup() [2/2]

virtual Powerup* Kart::getPowerup ( )
inlinevirtual

Returns the current powerup.

Implements AbstractKart.

◆ getRaceResult()

virtual bool Kart::getRaceResult ( ) const
inlinevirtual

Returns whether this kart wins or loses.

Implements AbstractKart.

◆ getResetTransform()

const btTransform& Kart::getResetTransform ( ) const
inline

Returns the start transform, i.e.

position and rotation.

◆ getShieldTime()

float Kart::getShieldTime ( ) const
virtual

Returns the remaining time the kart is protected by a shield.

Implements AbstractKart.

◆ getSkidding() [1/2]

virtual const Skidding* Kart::getSkidding ( ) const
inlinevirtual

Returns the skidding object for this kart (which can be used to query skidding related values).

Implements AbstractKart.

◆ getSkidding() [2/2]

virtual Skidding* Kart::getSkidding ( )
inlinevirtual

Returns the skidding object for this kart (which can be used to query skidding related values) - non-const.

Implements AbstractKart.

◆ getSlipstream() [1/2]

virtual const SlipStream* Kart::getSlipstream ( ) const
inlinevirtual

Returns the slipstream object of this kart.

Implements AbstractKart.

◆ getSlipstream() [2/2]

virtual SlipStream* Kart::getSlipstream ( )
inlinevirtual

Returns the slipstream object of this kart.

Implements AbstractKart.

◆ getSpeed()

virtual float Kart::getSpeed ( ) const
inlinevirtual

Returns the speed of the kart in meters/second.

This is not declared pure abstract, since this function is not needed for certain classes, like Ghost.

Implements AbstractKart.

Reimplemented in GhostKart.

◆ getSpeedForTurnRadius()

float Kart::getSpeedForTurnRadius ( float  radius) const
virtual

Returns the (maximum) speed for a given turn radius.

Parameters
radiusThe radius for which the speed needs to be computed.

Implements AbstractKart.

◆ getSpeedIncreaseTicksLeft()

int Kart::getSpeedIncreaseTicksLeft ( unsigned int  category) const
virtual

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

Parameters
categoryWhich category to report on.

Implements AbstractKart.

◆ getStartupBoostFromStartTicks()

float Kart::getStartupBoostFromStartTicks ( int  ticks) const
virtual

Called the first time a kart accelerates after 'ready'.

It searches through the startup times to find the appropriate slot, and returns the speed-boost from the corresponding entry. If the kart started too slow (i.e. slower than the longest time in the startup times list), it returns 0.

Implements AbstractKart.

◆ getTerrainInfo()

virtual const TerrainInfo* Kart::getTerrainInfo ( ) const
inlinevirtual

Returns the terrain info oject.

Implements AbstractKart.

◆ getTerrainPitch()

float Kart::getTerrainPitch ( float  heading) const
virtual

Returns the pitch of the terrain depending on the heading.

Implements AbstractKart.

◆ getTimeFullSteer()

float Kart::getTimeFullSteer ( float  steer) const
virtual

Returns the time till full steering is reached for this kart.

Parameters
steerCurrent steer value (must be >=0), on which the time till full steer depends.

Implements AbstractKart.

◆ getVehicle()

virtual btKart* Kart::getVehicle ( ) const
inlinevirtual

Returns the bullet vehicle which represents this kart.

Implements AbstractKart.

◆ handleMaterialGFX()

void Kart::handleMaterialGFX ( float  dt)
protected

Handles material specific GFX, mostly particle effects.

Particle effects can be triggered by two different situations: either because a kart drives on top of a terrain with a special effect, or because the kart is driving or falling under a surface (e.g. water), and the terrain effect is coming from that surface. Those effects are exclusive - you either get the effect from the terrain you are driving on, or the effect from a surface the kart is (partially) under. The surface effect is triggered, if either the kart is falling, or if the surface the kart is driving on has the 'isBelowSurface' property set. This function is called once per rendered frame from updateGraphics().

Parameters
dtTime step size.

◆ handleZipper()

void Kart::handleZipper ( const Material material = NULL,
bool  play_sound = false 
)
virtual

Sets zipper time, and apply one time additional speed boost.

It can be used with a specific material, in which case the zipper parmaters are taken from this material (parameters that are <0 will be using the kart-specific values from kart-properties.

Parameters
materialIf not NULL, will be used to determine the zipper parameters, otherwise the defaults from kart properties will be used.
play_soundIf true this will cause a sfx to be played even if the terrain hasn't changed. It is used by the zipper powerup.

The additional speed allowed on top of the kart-specific maximum kart speed.

Time the zipper stays activated.

A one time additional speed gain - the kart will instantly add this amount of speed to its current speed.

Time it takes for the zipper advantage to fade out.

Additional engine force.

Implements AbstractKart.

◆ hasFinishedRace()

virtual bool Kart::hasFinishedRace ( ) const
inlinevirtual

Returns true if this kart has finished the race.

Implements AbstractKart.

◆ increaseMaxSpeed()

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

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.
engine_forceAdditional engine force to affect the kart.
durationHow long the speed increase will last.
fade_out_timeHow long the maximum speed will fade out linearly.

Implements AbstractKart.

◆ init()

void Kart::init ( RaceManager::KartType  type)
virtual

This is a second initialisation phase, necessary since in the constructor virtual functions are not called for any superclasses.

Parameters
typeType of the kart.

Implements AbstractKart.

◆ instantSpeedIncrease()

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

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

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.

Implements AbstractKart.

◆ isEliminated()

virtual bool Kart::isEliminated ( ) const
inlinevirtual

Returns true if the kart is eliminated.

Implements AbstractKart.

◆ isFlying()

bool Kart::isFlying ( ) const
inline

For debugging only: check if a kart is flying.

◆ isGhostKart()

virtual bool Kart::isGhostKart ( ) const
inlinevirtual

Returns whether this kart is a ghost (replay) kart.

Implements AbstractKart.

Reimplemented in GhostKart.

◆ isInRest()

bool Kart::isInRest ( ) const
virtual

Returns true if the kart is 'resting', i.e.

(nearly) not moving.

Implements AbstractKart.

◆ isInvulnerable()

virtual bool Kart::isInvulnerable ( ) const
inlinevirtual

Returns if the kart is invulnerable.

Implements AbstractKart.

Reimplemented in GhostKart.

◆ isJumping()

virtual bool Kart::isJumping ( ) const
inlinevirtual

Returns whether this kart is jumping.

Implements AbstractKart.

◆ isNearGround()

bool Kart::isNearGround ( ) const

Returns true if the kart is close to the ground, used to dis/enable the upright constraint to allow for more realistic explosions.

The kart is near the ground, but not necessarily on it (small jumps).

This is used to determine when to stop flying.

◆ isOnGround()

bool Kart::isOnGround ( ) const
virtual

True if the wheels are touching the ground.

The kart is on ground if all 4 wheels touch the ground, and if no special animation (rescue, explosion etc.) is happening).

Implements AbstractKart.

◆ isShielded()

bool Kart::isShielded ( ) const
virtual

Returns if the kart is protected by a shield.

Returns true if the kart is protected by a shield.

Implements AbstractKart.

◆ isSquashed()

bool Kart::isSquashed ( ) const
virtual

Returns if the kart is currently being squashed.

Implements AbstractKart.

◆ kartIsInRestNow()

void Kart::kartIsInRestNow ( )
virtual

Computes the transform of the graphical kart chasses with regards to the physical chassis.

This function is called once the kart comes to rest before the race starts (see World::resetAllKarts). Based on the current physical kart position it computes an (at this stage Y-only) offset by which the graphical chassis is moved so that it appears the way it is designed in blender. This means that the distance of the wheels from the chassis (i.e. suspension) appears as in blender when karts are in rest. See updateGraphics for more details.

Reimplemented from AbstractKart.

Reimplemented in GhostKart.

◆ loadData()

void Kart::loadData ( RaceManager::KartType  type,
bool  is_animated_model 
)
protected

Attaches the right model, creates the physics and loads all special effects (particle systems etc.)

Parameters
typeType of the kart.
is_animated_modelTrue if the model is animated.

◆ playCrashSFX()

void Kart::playCrashSFX ( const Material m,
AbstractKart k 
)
protected

Common code used when a kart or a material was hit.

Parameters
mThe material collided into, or NULL if none
kThe kart collided into, or NULL if none

◆ playCustomSFX()

bool Kart::playCustomSFX ( unsigned int  type)
virtual

This function will play a particular character voice for this kart.

It returns whether or not a character voice sample exists for the particular event. If there is no voice sample, a default can be played instead.

Implements AbstractKart.

◆ reset()

void Kart::reset ( )
virtual

Reset before a new race.

It will remove all attachments, and puts the kart back at its original start position.

Reimplemented from AbstractKart.

Reimplemented in KartWithStats, GhostKart, and KartRewinder.

◆ setBoostAI()

void Kart::setBoostAI ( bool  boosted)
virtual

Sets the kart AI boost state.

Not pure abstract, since there is no need to implement this e.g. in Ghost.

Parameters
boostedTrue if a boost should be applied.

Implements AbstractKart.

◆ setController()

void Kart::setController ( Controller controller)
virtual

Saves the old controller in m_saved_controller and stores a new controller.

The save controller is needed in case of a reset.

Parameters
controllerThe new controller to use (atm it's always an end controller).

Implements AbstractKart.

◆ setEnergy()

virtual void Kart::setEnergy ( float  val)
inlinevirtual

Sets the energy the kart has collected.

Implements AbstractKart.

◆ setInvulnerableTicks()

virtual void Kart::setInvulnerableTicks ( int  ticks)
inlinevirtual

Makes a kart invulnerable for a certain amount of time.

Implements AbstractKart.

◆ setLastUsedPowerup()

void Kart::setLastUsedPowerup ( PowerupManager::PowerupType  t)
virtual

Sets the last used powerup.

Sets the powerup this kart has last used.

Number is always 1.

Parameters
tType of the powerup.

◆ setOnScreenText()

void Kart::setOnScreenText ( const core::stringw &  text)
virtual

Sets a text that is being displayed on top of a kart.

This can be 'leader' for the leader kart in a FTL race, the name of a driver, or even debug output.

Parameters
textThe text to display

Implements AbstractKart.

◆ setPosition()

void Kart::setPosition ( int  p)
virtual

Sets the position in race this kart has .

The position in this race for this kart (1<=p<=n)

Implements AbstractKart.

◆ setPowerup()

void Kart::setPowerup ( PowerupManager::PowerupType  t,
int  n 
)
virtual

Sets a new powerup.

Sets the powerup this kart has collected.

Parameters
tType of the powerup.
nNumber of powerups collected.

Implements AbstractKart.

◆ setRaceResult()

void Kart::setRaceResult ( )

Set this kart race result.

◆ setShieldTime()

void Kart::setShieldTime ( float  t)
virtual

Enables a kart shield protection for a certain amount of time.

Implements AbstractKart.

◆ setSlipstreamEffect()

void Kart::setSlipstreamEffect ( float  f)
virtual

Activates a slipstream effect, atm that is display some nitro.

Activates a slipstream effect.

Implements AbstractKart.

◆ setSlowdown()

void Kart::setSlowdown ( unsigned int  category,
float  max_speed_fraction,
int  fade_in_time 
)
virtual

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.

Implements AbstractKart.

◆ setSpeed()

virtual void Kart::setSpeed ( float  s)
inlinevirtual

This is used on the client side only to set the speed of the kart from the server information.

Implements AbstractKart.

◆ setSquash()

bool Kart::setSquash ( float  time,
float  slowdown 
)
virtual

Squashes this kart: it will scale the kart in up direction, and causes a slowdown while this kart is squashed.

Returns true if the squash is successful, false otherwise.

Parameters
timeHow long the kart will be squashed. A value of 0 will reset the kart to be unsquashed.
slowdownReduction of max speed.

Implements AbstractKart.

◆ setXYZ()

void Kart::setXYZ ( const Vec3 a)
virtual

Sets the XYZ coordinates of the moveable.

Reimplemented from Moveable.

◆ showStarEffect()

void Kart::showStarEffect ( float  t)
virtual

Shows the star effect for a certain time.

Parameters
tTime to show the star effect for.

Implements AbstractKart.

◆ startEngineSFX()

void Kart::startEngineSFX ( )
virtual

Starts the engine sound effect.

Called once the track intro phase is over.

Implements AbstractKart.

◆ unsetSquash()

void Kart::unsetSquash ( )
virtual

Makes the kart unsquashed again.

Implements AbstractKart.

◆ update()

void Kart::update ( int  ticks)
virtual

Updates the kart in each time step.

It updates the physics setting, particle effects, camera position, etc.

Parameters
dtTime step size.

Reimplemented from Moveable.

Reimplemented in KartWithStats, GhostKart, and KartRewinder.

◆ updateEnginePowerAndBrakes()

void Kart::updateEnginePowerAndBrakes ( int  ticks)
protected

Sets the engine power.

It considers the engine specs, items that influence the available power, and braking/steering.

◆ updateEngineSFX()

void Kart::updateEngineSFX ( float  dt)
protected

Adjust the engine sound effect depending on the speed of the kart.

This is called during updateGraphics, i.e. once per rendered frame only.

Parameters
dtTime step size.

◆ updateGraphics()

void Kart::updateGraphics ( float  dt)
virtual

Updates the graphics model.

It is responsible for positioning the graphical chasses at an 'appropriate' position: typically, the physical model has much longer suspension, so if the graphical chassis would be at the same location as the physical chassis, the wheels would be too far away. Instead the default suspension length is saved once the kart have been settled at start up (see World::resetAllKarts, which just runs several physics-only simulation steps so that karts come to a rest). Then at race time, only the difference between the current suspension length and this default suspension length is used. The graphical kart chassis will be offset so that when the kart is in rest, i.e. suspension length == default suspension length, the kart will look the way it was modelled in blender. To explain the various offsets used, here a view from the side focusing on the Y axis only (X/Z position of the graphical chassis is identical to the physical chassis):

Y| | visual kart | physical kart

+----------—COG------------—
:

| +------—low---— : | O : +-----------------------------------------------------------------------— X 'O' : visual wheel ':' : raycast from physics 'low' : lowest Y coordinate of COG : Center of gravity (at bottom of model chassis)

The visual kart is stored so that if it is shown at (0,0,0) it would be the same as in blender. This on the other hand means, if the kart is shown at the position of the physical chassis (which is at COG in the picture above), the kart and its wheels would be floating in the air (exactly by as much as the suspension length), and the wheels would be exactly at the bottom of the physical chassis (i.e. just on the plane going through COG and parallel to the ground). If we want to align the visual chassis to be the same as the physical chassis, we would need to subtract 'low' from the physical position. If the kart is then displayed at COG.y-low, the bottom of the kart (which is at 'low' above ground) would be at COG.y-low + low = COG.y --> visual and physical chassis are identical.

Unfortunately, the suspension length used in the physics is much too high, the karts would be way above their wheels, basically disconneccted (typical physical suspension length is around 0.28, while the distance between wheel and chassis in blender is in the order of 0.10 --> so there would be an additional distance of around 0.18 between wheel chassis as designed in blender and in stk - even more if the kart is driving downhill when the suspension extends further to keep contact with the ground). To make the visuals look closer to what they are in blender, an additional offset is added: before the start of a race the physics simulation is run to find a stable position for each kart (see World::resetAllKarts). Once a kart is stable, we save this suspension length in m_graphical_y_offset. This offset is subtracted from the COG of the kart. So if the kart is in rest (i.e. suspenion == default_suspension == m_graphical_y_offset), The kart is showen exactly at the same height above ground as it is in blender. If the suspension is shorter by DY (because the kart is accelerating, the ground goes up, ...), the visual chassis is lowered by DY as well.

While the above algorithm indeed results in the right position of the visual chassis, in reality the visual chassis is too low. For example, nolok's chassis has its lowest point at the rear at around 0.10 above the ground (and the lowest point overall is 0.05, though this is at the front and so not easily visible), so if the suspension is compressed by more than that, the chassiswill appear to be in the ground. Testing on the sand track shows that the suspension is compressed by 0.12 (and up to 0.16 in some extreme points), which means that the chassis will appear to be in the ground quite easily. Therefore the chassis is actually moved up a bit to avoid this problem. Historically (due to never sorting out that formula properly) the chassis was moved twice as high as its lowest point, e.g. nolok's lowest point is at 0.05, so the whole chassis was raised by 0.05 (this was not done by design, but because of a bug ;) ). Since this visual offset has worked well in the past, the visual chassis is moved by the same amount higher.

Of course this means that the Y position of the wheels (relative to the visual kart chassis) needs to be adjusted: if the kart is in rest, the wheels are exactly on the ground. If the suspension is shorter, that wheel would appear to be partly in the ground, and if the suspension is longer, the wheel would not touch the ground.

The wheels must be offset by how much the current suspension length is longer or shorter than the default (i.e. at rest) suspension length. This is done in KartModel (pos is the position of the wheel relative to the visual kart chassis): pos.Y += m_default_physics_suspension[i]

  • wi.m_raycastInfo.m_suspensionLength But since the chassis is raised an additional 'getLowestPoint' (see desctiption two paragraphs above), the wheels need to be lowered by that amount so that they still touch the ground (the wheel nodes are child of the chassis scene node, so if the chassis is raised by X, the wheels need to be lowered by X). This function also takes additional graphical effects into account, e.g. a (visual only) jump when skidding, and leaning of the kart.

Implements Moveable.

Reimplemented in KartRewinder, and GhostKart.

◆ updateNitro()

void Kart::updateNitro ( int  ticks)
protected

Updates the current nitro status.

Parameters
ticksNumber of physics time steps - should be 1.

◆ updatePhysics()

void Kart::updatePhysics ( int  ticks)
protected

Updates the physics for this kart: computing the driving force, set steering, handles skidding, terrain impact on kart, ...

Parameters
ticksNumber if physics time steps - should be 1.

◆ updateSliding()

void Kart::updateSliding ( )
protected

Handles sliding, i.e.

the kart sliding off terrain that is too steep. Dynamically determine friction so that the kart looses its traction when trying to drive on too steep surfaces. Below angles of 0.25 rad, you have full traction; above 0.5 rad angles you have absolutely none; inbetween there is a linear change in friction. This is done for each wheel individually (since otherwise karts were still able with enough speed to drive on walls - one wheel 'on a wall' would not tilt the kart chassis enough to trigger sliding, but since that wheel had still full friction, give the kart an upwards velocity).

◆ updateSpeed()

void Kart::updateSpeed ( )
protected

Updates the local speed based on the current physical velocity.

The value is smoothed exponentially to avoid camera stuttering (camera distance is dependent on speed)

Member Data Documentation

◆ m_brake_ticks

int Kart::m_brake_ticks
protected

How long the brake key has been pressed - the longer the harder the kart will brake.

◆ m_bubblegum_ticks

int16_t Kart::m_bubblegum_ticks
protected

If > 0 then bubble gum effect is on.

This is the sliding when hitting a gum on the floor, not the shield.

◆ m_bubblegum_torque_sign

bool Kart::m_bubblegum_torque_sign
protected

The sign of torque to apply after hitting a bubble gum.

◆ m_collected_energy

float Kart::m_collected_energy
protected

The amount of energy collected with nitro cans.

Note that it must be float, since dt is subtraced in each timestep.

◆ m_controller

Controller* Kart::m_controller
protected

The main controller of this object, used for driving.

This controller is used to run the kart. It will be replaced with an end kart controller when the kart finishes the race.

◆ m_current_lean

float Kart::m_current_lean
protected

Current leaning of the kart.

◆ m_eliminated

bool Kart::m_eliminated
protected

True if the kart is eliminated.

◆ m_flying

bool Kart::m_flying
protected

True if kart is flying (for debug purposes only).

◆ m_graphical_y_offset

float Kart::m_graphical_y_offset
protected

Offset of the graphical kart chassis from the physical chassis.

◆ m_initial_position

int Kart::m_initial_position
protected

Initial rank of the kart.

◆ m_invulnerable_ticks

int16_t Kart::m_invulnerable_ticks
protected

Time a kart is invulnerable.

◆ m_kart_gfx

std::unique_ptr<KartGFX> Kart::m_kart_gfx
protected

All particle effects.

◆ m_last_sound_material

const Material* Kart::m_last_sound_material
protected

The material for which the last sound effect was played.

◆ m_last_used_powerup

PowerupManager::PowerupType Kart::m_last_used_powerup
protected

Remember the last used powerup type of a kart for AI purposes.

◆ m_max_gear_rpm

float Kart::m_max_gear_rpm
protected

Maximum engine rpm's for the current gear.

◆ m_max_speed

MaxSpeed* Kart::m_max_speed
protected

Handles speed increase and capping due to powerup, terrain, ...

◆ m_powerup

Powerup* Kart::m_powerup
protected

Handles the powerup of a kart.

◆ m_previous_terrain_sound

SFXBase* Kart::m_previous_terrain_sound
protected

A pointer to the previous terrain sound needs to be saved so that an 'older' sfx can be finished and an abrupt end of the sfx is avoided.

◆ m_previous_xyz_times

std::vector<float> Kart::m_previous_xyz_times
protected

The times at which the previous positions occured.

Currently used for finish time computation

◆ m_race_position

int Kart::m_race_position
protected

Current race position (1-num_karts).

◆ m_race_result

bool Kart::m_race_result
protected

True if the kart wins, false otherwise.

◆ m_reset_transform

btTransform Kart::m_reset_transform
protected

Reset position.

◆ m_saved_controller

Controller* Kart::m_saved_controller
protected

This saves the original controller when the end controller is used.

This is an easy solution for restarting the race, since the controller do not need to be reinitialised.

◆ m_shadow

std::unique_ptr<Shadow> Kart::m_shadow
protected

The shadow of a kart.

◆ m_skidding

std::unique_ptr<Skidding> Kart::m_skidding
protected

This object handles all skidding.

◆ m_skidmarks

std::unique_ptr<SkidMarks> Kart::m_skidmarks
protected

The skidmarks object for this kart.

◆ m_slipstream

std::unique_ptr<SlipStream> Kart::m_slipstream
protected

Handles all slipstreaming.

◆ m_speed

float Kart::m_speed
protected

The current speed (i.e.

length of velocity vector) of this kart.

◆ m_terrain_info

TerrainInfo* Kart::m_terrain_info
protected

Stores information about the terrain the kart is on.

◆ m_terrain_sound

SFXBase* Kart::m_terrain_sound
protected

Sound to be played depending on terrain.

◆ m_view_blocked_by_plunger

int16_t Kart::m_view_blocked_by_plunger
protected

When a kart has its view blocked by the plunger, this variable will be

0 the number it contains is the time left before removing plunger.

◆ m_xyz_front

Vec3 Kart::m_xyz_front
protected

The coordinates of the front of the kart, used to determine when a new lap is triggered.


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