SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
LocalPlayerController Class Reference

PlayerKart manages control events from the player and moves them to the Kart. More...

#include <local_player_controller.hpp>

Inheritance diagram for LocalPlayerController:
Inheritance graph
[legend]

Public Member Functions

 LocalPlayerController (AbstractKart *kart, const int local_player_id, HandicapLevel h)
 The constructor for a loca player kart, i.e.
 
 ~LocalPlayerController ()
 Destructor for a player kart.
 
void update (int ticks) OVERRIDE
 Updates the player kart, called once each timestep.
 
bool action (PlayerAction action, int value, bool dry_run=false) OVERRIDE
 This function interprets a kart action and value, and set the corresponding entries in the kart control data structure.
 
void initParticleEmitter ()
 
virtual void handleZipper (bool play_sound) OVERRIDE
 Called when a kart hits or uses a zipper.
 
void collectedItem (const ItemState &item, float previous_energy=0) OVERRIDE
 Called when a kart hits an item.
 
virtual void setPosition (int p) OVERRIDE
 Called just before the kart position is changed.
 
virtual void reset () OVERRIDE
 Resets the player kart for a new or restarted race.
 
virtual void finishedRace (float time) OVERRIDE
 Called when a kart finishes race.
 
virtual void resetInputState () OVERRIDE
 Resets the state of control keys.
 
virtual bool canGetAchievements () const OVERRIDE
 Returns true if the player of this controller can collect achievements.
 
virtual void crashed (const AbstractKart *k) OVERRIDE
 
virtual void crashed (const Material *m) OVERRIDE
 
virtual void rumble (float strength_low, float strength_high, uint16_t duration) OVERRIDE
 
virtual bool isPlayerController () const OVERRIDE
 This function checks if this player is not an AI, i.e.
 
virtual bool isLocalPlayerController () const OVERRIDE
 This function checks if this is a local player.
 
core::stringw getName (bool include_handicap_string=true) const OVERRIDE
 Returns the name of the player profile.
 
- Public Member Functions inherited from PlayerController
 PlayerController (AbstractKart *kart)
 
virtual ~PlayerController ()
 Destructor for a player kart.
 
virtual void update (int ticks) OVERRIDE
 Updates the player kart, called once each timestep.
 
virtual bool action (PlayerAction action, int value, bool dry_run=false) OVERRIDE
 This function interprets a kart action and value, and set the corresponding entries in the kart control data structure.
 
virtual void actionFromNetwork (PlayerAction action, int value, int value_l, int value_r)
 
virtual void skidBonusTriggered () OVERRIDE
 Callback when the skidding bonus is triggered.
 
virtual void reset () OVERRIDE
 Resets the player kart for a new or restarted race.
 
virtual void handleZipper (bool play_sound) OVERRIDE
 Called when a kart hits or uses a zipper.
 
virtual void resetInputState ()
 Resets the state of control keys.
 
virtual bool saveState (BareNetworkString *buffer) const OVERRIDE
 
virtual void rewindTo (BareNetworkString *buffer) OVERRIDE
 
virtual void collectedItem (const ItemState &item, float previous_energy=0) OVERRIDE
 
virtual bool isPlayerController () const OVERRIDE
 This function checks if this player is not an AI, i.e.
 
virtual bool isLocalPlayerController () const OVERRIDE
 This function checks if this is a local player.
 
virtual void setPosition (int p) OVERRIDE
 Called just before the position of the kart is changed.
 
virtual void crashed (const AbstractKart *k) OVERRIDE
 
virtual void crashed (const Material *m) OVERRIDE
 
virtual void newLap (int lap) OVERRIDE
 Callback whenever a new lap is triggered.
 
virtual bool disableSlipstreamBonus () const OVERRIDE
 Player will always be able to get a slipstream bonus.
 
virtual void finishedRace (float time) OVERRIDE
 Called when a race is finished.
 
core::stringw getName (bool include_handicap_string=true) const OVERRIDE
 Returns the name of the player profile.
 
virtual void displayPenaltyWarning ()
 Called when this kart started too early and got a start penalty.
 
- Public Member Functions inherited from Controller
 Controller (AbstractKart *kart)
 Constructor, saves the kart pointer and a pointer to the KartControl of the kart.
 
virtual void reset ()=0
 
virtual void update (int ticks)=0
 
virtual void handleZipper (bool play_sound)=0
 
virtual void collectedItem (const ItemState &item, float previous_energy=0)=0
 
virtual void crashed (const AbstractKart *k)=0
 
virtual void crashed (const Material *m)=0
 
virtual void setPosition (int p)=0
 
virtual bool isLocalPlayerController () const =0
 This function checks if this is a local player.
 
virtual bool isPlayerController () const =0
 This function checks if this player is not an AI, i.e.
 
virtual bool disableSlipstreamBonus () const =0
 
virtual bool saveState (BareNetworkString *buffer) const =0
 
virtual void rewindTo (BareNetworkString *buffer)=0
 
virtual void rumble (float strength_low, float strength_high, uint16_t duration)
 
virtual void setControllerName (const std::string &name)
 Sets the controller name for this controller.
 
const std::string & getControllerName () const
 Returns the name of this controller.
 
virtual bool action (PlayerAction action, int value, bool dry_run=false)=0
 Default: ignore actions.
 
virtual void newLap (int lap)=0
 Callback whenever a new lap is triggered.
 
virtual void skidBonusTriggered ()=0
 
virtual void finishedRace (float time)=0
 Called whan this controller's kart finishes the last lap.
 
virtual KartControlgetControls ()
 Get a pointer on the kart controls.
 
void setControls (KartControl *kc)
 
virtual bool canGetAchievements () const
 Only local players can get achievements.
 
virtual core::stringw getName (bool include_handicap_string=true) const
 Display name of the controller.
 
AbstractKartgetKart () const
 Returns the kart controlled by this controller.
 

Private Member Functions

virtual void steer (int, int) OVERRIDE
 Handles steering for a player kart.
 
virtual void displayPenaltyWarning () OVERRIDE
 Displays a penalty warning for player controlled karts.
 
void nitroNotFullSound ()
 If the nitro level has gone under the nitro goal, play a bad effect sound.
 
void doCrashHaptics ()
 
void setParticleEmitterPosition (const btTransform &t)
 

Private Attributes

StateManager::ActivePlayerm_player
 Stores the active player data structure.
 
bool m_sound_schedule
 
bool m_has_started
 
bool m_is_above_nitro_target
 
std::unique_ptr< ParticleEmitterm_sky_particles_emitter
 
int m_camera_index
 The index of the camera attached to the kart for this controller.
 
int m_last_crash
 
HandicapLevel m_handicap
 
SFXBasem_wee_sound
 
SFXBufferm_bzzt_sound
 
SFXBufferm_ugh_sound
 
SFXBufferm_grab_sound
 
SFXBufferm_full_sound
 
SFXBufferm_unfull_sound
 

Additional Inherited Members

virtual void steer (int ticks, int steer_val)
 Handles steering for a player kart.
 
- Protected Attributes inherited from PlayerController
int m_steer_val
 
int m_steer_val_l
 
int m_steer_val_r
 
uint16_t m_prev_accel
 
bool m_prev_brake
 
bool m_prev_nitro
 
int m_penalty_ticks
 
- Protected Attributes inherited from Controller
AbstractKartm_kart
 Pointer to the kart that is controlled by this controller.
 
KartControlm_controls
 A pointer to the main controller, from which the kart takes it commands.
 
std::string m_controller_name
 The name of the controller, mainly used for debugging purposes.
 

Detailed Description

PlayerKart manages control events from the player and moves them to the Kart.

Constructor & Destructor Documentation

◆ LocalPlayerController()

LocalPlayerController::LocalPlayerController ( AbstractKart kart,
const int  local_player_id,
HandicapLevel  h 
)

The constructor for a loca player kart, i.e.

a player that is playing on this machine (non-local player would be network clients).

Parameters
kart_nameName of the kart.
positionThe starting position (1 to n).
playerThe player to which this kart belongs.
init_posThe start coordinates and heading of the kart.

Member Function Documentation

◆ action()

bool LocalPlayerController::action ( PlayerAction  action,
int  value,
bool  dry_run = false 
)
virtual

This function interprets a kart action and value, and set the corresponding entries in the kart control data structure.

This function handles esp. cases like 'press left, press right, release right' - in this case after releasing right, the steering must switch to left again. Similarly it handles 'press left, press right, release left' (in which case still right must be selected). Similarly for braking and acceleration.

Parameters
actionThe action to be executed.
valueIf 32768, it indicates a digital value of 'fully set' if between 1 and 32767, it indicates an analog value, and if it's 0 it indicates that the corresponding button was released.
dry_runIf set it will return if this action will trigger a state change or not.
Returns
True if dry_run==true and a state change would be triggered. If dry_run==false, it returns true.

Reimplemented from PlayerController.

◆ canGetAchievements()

bool LocalPlayerController::canGetAchievements ( ) const
virtual

Returns true if the player of this controller can collect achievements.

At the moment only the current player can collect them. TODO: check this, possible all local players should be able to collect achievements - synching to online account will happen next time the account gets online.

Reimplemented from Controller.

◆ collectedItem()

void LocalPlayerController::collectedItem ( const ItemState item_state,
float  old_energy = 0 
)
virtual

Called when a kart hits an item.

It plays certain sfx (e.g. nitro full, or item specific sounds).

Parameters
itemItem that was collected.
old_energyThe previous energy value

Reimplemented from PlayerController.

◆ crashed() [1/2]

void LocalPlayerController::crashed ( const AbstractKart k)
virtual

Reimplemented from PlayerController.

◆ crashed() [2/2]

void LocalPlayerController::crashed ( const Material m)
virtual

Reimplemented from PlayerController.

◆ displayPenaltyWarning()

void LocalPlayerController::displayPenaltyWarning ( )
privatevirtual

Displays a penalty warning for player controlled karts.

Called from LocalPlayerKart::update() if necessary.

Reimplemented from PlayerController.

◆ finishedRace()

void LocalPlayerController::finishedRace ( float  time)
virtual

Called when a kart finishes race.

/param time Finishing time for this kart. d

Reimplemented from PlayerController.

◆ getName()

core::stringw LocalPlayerController::getName ( bool  include_handicap_string = true) const
virtual

Returns the name of the player profile.

Reimplemented from Controller.

◆ handleZipper()

void LocalPlayerController::handleZipper ( bool  play_sound)
virtual

Called when a kart hits or uses a zipper.

Reimplemented from PlayerController.

◆ isLocalPlayerController()

virtual bool LocalPlayerController::isLocalPlayerController ( ) const
inlinevirtual

This function checks if this is a local player.

A local player will get special graphical effects enabled, has a camera, and sound effects will be played with normal volume.

Reimplemented from PlayerController.

◆ isPlayerController()

virtual bool LocalPlayerController::isPlayerController ( ) const
inlinevirtual

This function checks if this player is not an AI, i.e.

it is either a a local or a remote/networked player. This is tested e.g. by the AI for rubber-banding.

Reimplemented from PlayerController.

◆ reset()

void LocalPlayerController::reset ( )
virtual

Resets the player kart for a new or restarted race.

Reimplemented from PlayerController.

◆ resetInputState()

void LocalPlayerController::resetInputState ( )
virtual

Resets the state of control keys.

This is used after the in-game menu to avoid that any keys pressed at the time the menu is opened are still considered to be pressed.

Reimplemented from PlayerController.

◆ rumble()

void LocalPlayerController::rumble ( float  strength_low,
float  strength_high,
uint16_t  duration 
)
virtual

Reimplemented from Controller.

◆ setPosition()

void LocalPlayerController::setPosition ( int  p)
virtual

Called just before the kart position is changed.

It checks if the kart was overtaken, and if so plays a sound from the overtaking kart.

Reimplemented from PlayerController.

◆ steer()

void LocalPlayerController::steer ( int  ticks,
int  steer_val 
)
privatevirtual

Handles steering for a player kart.

Reimplemented from PlayerController.

◆ update()

void LocalPlayerController::update ( int  ticks)
virtual

Updates the player kart, called once each timestep.

Reimplemented from PlayerController.

Member Data Documentation

◆ m_camera_index

int LocalPlayerController::m_camera_index
private

The index of the camera attached to the kart for this controller.

The camera object is managed in the Camera class, so no need to free it.


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