SuperTuxKart
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. More...
 
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. More...
 
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. More...
 
virtual bool isLocalPlayerController () const OVERRIDE
 This function checks if this is a local player. More...
 
virtual bool action (PlayerAction action, int value, bool dry_run=false) OVERRIDE
 Default: ignore actions. More...
 
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.
 
const std::string & getControllerName () const
 Returns the name of this controller. More...
 
virtual void newLap (int lap)=0
 Callback whenever a new lap is triggered. More...
 
virtual KartControlgetControls ()
 Get a pointer on the kart controls. More...
 
void setControls (KartControl *kc)
 
virtual bool canGetAchievements () const
 Only local players can get achievements. More...
 
virtual core::stringw getName (bool include_handicap_string=true) const
 Display name of the controller. More...
 
AbstractKartgetKart () const
 Returns the kart controlled by this controller. More...
 

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. More...
 
float steerToPoint (const Vec3 &point)
 Computes the steering angle to reach a certain point. More...
 
float normalizeAngle (float angle)
 Normalises an angle to be between -pi and _ pi. More...
 
bool isStuck () const
 This can be called to detect if the kart is stuck (i.e. More...
 
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. More...
 
virtual void setSteering (float angle, float dt)
 Converts the steering angle to a lr steering in the range of -1 to 1. More...
 
virtual bool canSkid (float steer_fraction)=0
 Return true if AI can skid now. More...
 

Protected Attributes

bool m_enabled_network_ai
 
float m_kart_length
 Length of the kart, storing it here saves many function calls. More...
 
float m_kart_width
 Cache width of kart. More...
 
Trackm_track
 Keep a pointer to the track to reduce calls.
 
const AIPropertiesm_ai_properties
 A pointer to the AI properties for this kart. More...
 
- Protected Attributes inherited from Controller
AbstractKartm_kart
 Pointer to the kart that is controlled by this controller. More...
 
KartControlm_controls
 A pointer to the main controller, from which the kart takes it commands. More...
 
std::string m_controller_name
 The name of the controller, mainly used for debugging purposes. More...
 

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

Private Attributes

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

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 SkiddingAI, TestAI, ArenaAI, EndController, and SoccerAI.

◆ crashed()

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.

◆ finishedRace()

virtual void AIBaseController::finishedRace ( float  time)
inlinevirtual

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

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.

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

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

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

Member Data Documentation

◆ m_ai_properties

const AIProperties* AIBaseController::m_ai_properties
protected

A pointer to the AI properties for this kart.

◆ 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_kart_length

float AIBaseController::m_kart_length
protected

Length of the kart, storing it here saves many function calls.

◆ m_kart_width

float AIBaseController::m_kart_width
protected

Cache width of kart.

◆ m_stuck

bool AIBaseController::m_stuck
private

A flag that is set during the physics processing to indicate that this kart is stuck and needs to be rescued.

◆ 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: