SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
AIBaseController Class Referenceabstract

A base class for all AI karts. More...

#include <ai_base_controller.hpp>

Inheritance diagram for AIBaseController:
Inheritance graph
[legend]

Public Member Functions

 AIBaseController (AbstractKart *kart)
 
virtual void reset () OVERRIDE
 
virtual bool disableSlipstreamBonus () const OVERRIDE
 Certain AI levels will not receive a slipstream bonus in order to be not as hard.
 
virtual void crashed (const Material *m) OVERRIDE
 This is called when the kart crashed with the terrain.
 
virtual void crashed (const AbstractKart *k) OVERRIDE
 
virtual void handleZipper (bool play_sound) OVERRIDE
 
virtual void finishedRace (float time) OVERRIDE
 Called whan this controller's kart finishes the last lap.
 
virtual void collectedItem (const ItemState &item, float previous_energy=0) OVERRIDE
 
virtual void setPosition (int p) 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 bool action (PlayerAction action, int value, bool dry_run=false) OVERRIDE
 Default: ignore actions.
 
virtual void skidBonusTriggered () OVERRIDE
 
virtual bool saveState (BareNetworkString *buffer) const OVERRIDE
 
virtual void rewindTo (BareNetworkString *buffer) OVERRIDE
 
void setNetworkAI (bool val)
 
virtual void update (int ticks) OVERRIDE
 
- 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.
 

Static Public Member Functions

static void enableDebug ()
 
static void setTestAI (int n)
 
static int getTestAI ()
 

Protected Member Functions

void setControllerName (const std::string &name) OVERRIDE
 In debug mode when the user specified –ai-debug on the command line set the name of the controller as on-screen text, so that the different AI controllers can be distinguished.
 
float steerToPoint (const Vec3 &point)
 Computes the steering angle to reach a certain point.
 
float normalizeAngle (float angle)
 Normalises an angle to be between -pi and _ pi.
 
bool isStuck () const
 This can be called to detect if the kart is stuck (i.e.
 
void determineTurnRadius (const Vec3 &end, Vec3 *center, float *radius) const
 Determine the center point and radius of a circle given two points on the circle and the tangent at the first point.
 
virtual void setSteering (float angle, float dt)
 Converts the steering angle to a lr steering in the range of -1 to 1.
 
virtual bool canSkid (float steer_fraction)=0
 Return true if AI can skid now.
 

Protected Attributes

bool m_enabled_network_ai
 
float m_kart_length
 Length of the kart, storing it here saves many function calls.
 
float m_kart_width
 Cache width of kart.
 
Trackm_track
 Keep a pointer to the track to reduce calls.
 
const AIPropertiesm_ai_properties
 A pointer to the AI properties for this kart.
 
- 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.
 

Static Protected Attributes

static bool m_ai_debug = false
 
static int m_test_ai = 0
 Stores the '–test-ai=n' command line parameter: It indicates which fraction of the AIs are going to be the test AI: 1 means only to use the TestAI, 2 means every second AI will be test etc.
 

Private Attributes

std::vector< int > m_collision_ticks
 Stores the last N times when a collision happened.
 
bool m_stuck
 A flag that is set during the physics processing to indicate that this kart is stuck and needs to be rescued.
 

Detailed Description

A base class for all AI karts.

This class basically provides some common low level functions.

Member Function Documentation

◆ action()

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

Default: ignore actions.

Only PlayerController get them.

Implements Controller.

Reimplemented in EndController.

◆ canSkid()

virtual bool AIBaseController::canSkid ( float  steer_fraction)
protectedpure virtual

Return true if AI can skid now.

Implemented in EndController, SkiddingAI, TestAI, ArenaAI, and SoccerAI.

◆ collectedItem()

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

Implements Controller.

◆ crashed() [1/2]

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

Implements Controller.

Reimplemented in SpareTireAI.

◆ crashed() [2/2]

void AIBaseController::crashed ( const Material m)
virtual

This is called when the kart crashed with the terrain.

This subroutine tries to detect if the AI is stuck by determining if a certain number of collisions happened in a certain amount of time, and if so rescues the kart. \paran m Pointer to the material that was hit (NULL if no specific material was used for the part of the track that was hit).

Implements Controller.

◆ determineTurnRadius()

void AIBaseController::determineTurnRadius ( const Vec3 end,
Vec3 center,
float *  radius 
) const
protected

Determine the center point and radius of a circle given two points on the circle and the tangent at the first point.

This is done as follows:

  1. Determine the line going through the center point start+end, which is orthogonal to the vector from start to end. This line goes through the center of the circle.
  2. Determine the line going through the first point and is orthogonal to the given tangent.
  3. The intersection of these two lines is the center of the circle.
    Parameters
    [in]endSecond point on circle.
    [out]centerCenter point of the circle (local coordinate).
    [out]radiusRadius of the circle.

◆ disableSlipstreamBonus()

bool AIBaseController::disableSlipstreamBonus ( ) const
virtual

Certain AI levels will not receive a slipstream bonus in order to be not as hard.

Implements Controller.

◆ finishedRace()

virtual void AIBaseController::finishedRace ( float  time)
inlinevirtual

Called whan this controller's kart finishes the last lap.

Implements Controller.

◆ handleZipper()

virtual void AIBaseController::handleZipper ( bool  play_sound)
inlinevirtual

Implements Controller.

◆ isLocalPlayerController()

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

◆ isPlayerController()

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

◆ isStuck()

bool AIBaseController::isStuck ( ) const
inlineprotected

This can be called to detect if the kart is stuck (i.e.

repeatedly hitting part of the track).

◆ normalizeAngle()

float AIBaseController::normalizeAngle ( float  angle)
protected

Normalises an angle to be between -pi and _ pi.

Parameters
angleAngle to normalise.
Returns
Normalised angle.

◆ reset()

void AIBaseController::reset ( )
virtual

Implements Controller.

Reimplemented in SkiddingAI, ArenaAI, SoccerAI, and SpareTireAI.

◆ rewindTo()

void AIBaseController::rewindTo ( BareNetworkString buffer)
virtual

Implements Controller.

◆ saveState()

bool AIBaseController::saveState ( BareNetworkString buffer) const
virtual

Implements Controller.

◆ setControllerName()

void AIBaseController::setControllerName ( const std::string &  name)
protectedvirtual

In debug mode when the user specified –ai-debug on the command line set the name of the controller as on-screen text, so that the different AI controllers can be distinguished.

Parameters
nameName of the controller.

Reimplemented from Controller.

◆ setPosition()

virtual void AIBaseController::setPosition ( int  p)
inlinevirtual

Implements Controller.

◆ setSteering()

void AIBaseController::setSteering ( float  angle,
float  dt 
)
protectedvirtual

Converts the steering angle to a lr steering in the range of -1 to 1.

If the steering angle is too great, it will also trigger skidding. This function uses a 'time till full steer' value specifying the time it takes for the wheel to reach full left/right steering similar to player karts when using a digital input device. The parameter is defined in the kart properties and helps somewhat to make AI karts more 'pushable' (since otherwise the karts counter-steer to fast). It also takes the effect of a plunger into account by restricting the actual steer angle to 50% of the maximum.

Parameters
angleSteering angle.
dtTime step.

Reimplemented in SkiddingAI, and TestAI.

◆ skidBonusTriggered()

virtual void AIBaseController::skidBonusTriggered ( )
inlinevirtual

Implements Controller.

◆ steerToPoint()

float AIBaseController::steerToPoint ( const Vec3 point)
protected

Computes the steering angle to reach a certain point.

The function will request steering by setting the steering angle to maximum steer angle times skidding factor.

Parameters
pointPoint to steer towards.
skidding_factorIncrease factor for steering when skidding.
Returns
Steer angle to use to reach this point.

◆ update()

void AIBaseController::update ( int  ticks)
virtual

Member Data Documentation

◆ m_collision_ticks

std::vector<int> AIBaseController::m_collision_ticks
private

Stores the last N times when a collision happened.

This is used to detect when the AI is stuck, i.e. N collisions happened in a certain period of time.

◆ m_test_ai

int AIBaseController::m_test_ai = 0
staticprotected

Stores the '–test-ai=n' command line parameter: It indicates which fraction of the AIs are going to be the test AI: 1 means only to use the TestAI, 2 means every second AI will be test etc.

Used for AI testing only.


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