SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
PlayerController Class Reference
Inheritance diagram for PlayerController:
Inheritance graph
[legend]

Public Member Functions

 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.
 

Protected Member Functions

virtual void steer (int ticks, int steer_val)
 Handles steering for a player kart.
 

Protected Attributes

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.
 

Friends

class KartRewinder
 

Member Function Documentation

◆ action()

bool PlayerController::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. This function can be run in two modes: first, if 'dry_run' is set, it will return true if this action will cause a state change. This is sued in networking to avoid sending events to the server (and then to other clients) if they are just (e.g. auto) repeated events/

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 only test if the parameter will trigger a state change. If not set, the appropriate actions (i.e. input state change) will be done.
Returns
If dry_run is set, will return true if this action will cause a state change. If dry_run is not set, will return false.

If dry_run (parameter) is true, this macro tests if this action would trigger a state change in the specified variable (without actually doing it). If it will trigger a state change, the macro will immediatley return to the caller. If dry_run is false, it will only assign the new value to the variable (and not return to the user early). The do-while(0) helps using this macro e.g. in the 'then' clause of an if statement.

Basically the same as the above macro, but is uses getter/setter functions. The name of the setter/getter is set'name'(value) and get'name'().

Implements Controller.

Reimplemented in LocalPlayerController.

◆ collectedItem()

virtual void PlayerController::collectedItem ( const ItemState item,
float  previous_energy = 0 
)
inlinevirtual

Implements Controller.

Reimplemented in LocalPlayerController.

◆ crashed() [1/2]

virtual void PlayerController::crashed ( const AbstractKart k)
inlinevirtual

Implements Controller.

◆ crashed() [2/2]

virtual void PlayerController::crashed ( const Material m)
inlinevirtual

Implements Controller.

◆ disableSlipstreamBonus()

virtual bool PlayerController::disableSlipstreamBonus ( ) const
inlinevirtual

Player will always be able to get a slipstream bonus.

Implements Controller.

◆ displayPenaltyWarning()

void PlayerController::displayPenaltyWarning ( )
virtual

Called when this kart started too early and got a start penalty.

Reimplemented in LocalPlayerController.

◆ finishedRace()

virtual void PlayerController::finishedRace ( float  time)
inlinevirtual

Called when a race is finished.

Implements Controller.

Reimplemented in LocalPlayerController.

◆ getName()

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

Returns the name of the player profile.

Reimplemented from Controller.

◆ handleZipper()

void PlayerController::handleZipper ( bool  play_sound)
virtual

Called when a kart hits or uses a zipper.

Implements Controller.

Reimplemented in LocalPlayerController.

◆ isLocalPlayerController()

virtual bool PlayerController::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.

Implements Controller.

Reimplemented in LocalPlayerController, NetworkAIController, and NetworkPlayerController.

◆ isPlayerController()

virtual bool PlayerController::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.

Implements Controller.

Reimplemented in LocalPlayerController.

◆ newLap()

virtual void PlayerController::newLap ( int  lap)
inlinevirtual

Callback whenever a new lap is triggered.

Used by the AI to trigger a recomputation of the way to use, not used for players.

Implements Controller.

◆ reset()

void PlayerController::reset ( )
virtual

Resets the player kart for a new or restarted race.

Implements Controller.

Reimplemented in LocalPlayerController, and NetworkAIController.

◆ resetInputState()

void PlayerController::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 in LocalPlayerController.

◆ rewindTo()

void PlayerController::rewindTo ( BareNetworkString buffer)
virtual

Implements Controller.

◆ saveState()

bool PlayerController::saveState ( BareNetworkString buffer) const
virtual

Implements Controller.

◆ setPosition()

virtual void PlayerController::setPosition ( int  p)
inlinevirtual

Called just before the position of the kart is changed.

Implements Controller.

Reimplemented in LocalPlayerController.

◆ skidBonusTriggered()

void PlayerController::skidBonusTriggered ( )
virtual

Callback when the skidding bonus is triggered.

The player controller resets the current steering to 0, which makes the kart easier to control.

Implements Controller.

◆ steer()

void PlayerController::steer ( int  ticks,
int  steer_val 
)
protectedvirtual

Handles steering for a player kart.

Reimplemented in LocalPlayerController.

◆ update()

void PlayerController::update ( int  ticks)
virtual

Updates the player kart, called once each timestep.

Implements Controller.

Reimplemented in LocalPlayerController, NetworkAIController, and NetworkPlayerController.


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