SuperTuxKart
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ArenaAI Class Referenceabstract

A base class for AI that use navmesh to work. More...

#include <arena_ai.hpp>

Inheritance diagram for ArenaAI:
Inheritance graph
[legend]

Public Member Functions

 ArenaAI (AbstractKart *kart)
 
virtual void update (int ticks) OVERRIDE
 This is the main entry point for the AI. More...
 
virtual void reset () OVERRIDE
 Resets the AI when a race is restarted.
 
virtual void newLap (int lap) OVERRIDE
 Callback whenever a new lap is triggered. More...
 
- Public Member Functions inherited from AIBaseController
 AIBaseController (AbstractKart *kart)
 
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)
 
- 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 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...
 

Protected Member Functions

void tryCollectItem (Vec3 *aim_point, int *target_node) const
 Try to collect item in arena, if no suitable item is found, like they are swapped, it will follow closest kart instead. More...
 
virtual void findClosestKart (bool consider_difficulty, bool find_sta)=0
 Find the closest kart around this AI, implemented by sub-class. More...
 
- Protected Member Functions inherited from AIBaseController
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...
 

Protected Attributes

ArenaGraphm_graph
 Pointer to the ArenaGraph. More...
 
AbstractKartm_closest_kart
 Pointer to the closest kart around this kart. More...
 
int m_closest_kart_node
 The ArenaNode at which the closest kart located on. More...
 
Vec3 m_closest_kart_point
 The closest kart location. More...
 
RaceManager::Difficulty m_cur_difficulty
 Holds the current difficulty. More...
 
irr::scene::ISceneNode * m_debug_sphere
 For debugging purpose: a sphere indicating where the AI is targeting at. More...
 
irr::scene::ISceneNode * m_debug_sphere_next
 For debugging purpose: a sphere indicating where the first turning corner is located. More...
 
int m_target_node
 The ArenaNode at which the target point located on. More...
 
Vec3 m_target_point
 The coordinates of target point. More...
 
bool m_mini_skid
 True if AI can skid, currently only do when close to target, see doSkiddingTest(). More...
 
- Protected Attributes inherited from AIBaseController
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...
 

Private Member Functions

void configSpeed ()
 Configure a suitable speed depends on current turn radius.
 
void configSteering ()
 This function config the steering (m_steering_angle) of AI.
 
void checkIfStuck (const float dt)
 Determine whether AI is stuck, by checking if it stays on the same node for a long period of time (see m_on_node), or isStuck() is true. More...
 
void determinePath (int forward, std::vector< int > *path)
 Determine if the path to target needs to be changed to avoid bad items, it will also set the turn radius based on the new path if necessary. More...
 
void doSkiddingTest ()
 Determine if AI should skid: When it's close to target, but not straight ahead, in front of it, same steering side and with suitable difficulties which are in expert and supertux only.
 
void doUTurn (const float dt)
 Make AI reverse so that it faces in front of the last target point.
 
bool gettingUnstuck (int ticks)
 Function to let AI get unstuck. More...
 
bool updateAimingPosition (Vec3 *target_point)
 Update aiming position, use path finding if necessary. More...
 
void useItems (const float dt)
 Determine how AI should use its item, different m_cur_difficulty will have a corresponding strategy. More...
 
virtual bool canSkid (float steer_fraction) OVERRIDE
 Return true if AI can skid now. More...
 
virtual void findTarget ()=0
 Find a suitable target for this frame, implemented by sub-class. More...
 
virtual bool forceBraking ()
 If true, AI will always try to brake for this frame. More...
 
virtual int getCurrentNode () const =0
 Return the current ArenaNode the AI located on. More...
 
virtual float getKartDistance (const AbstractKart *kart) const =0
 Return the distance based on graph distance matrix to any kart. More...
 
virtual bool ignorePathFinding ()
 If true, AI will drive directly to target without path finding. More...
 
virtual bool isWaiting () const =0
 If true, AI will stop moving. More...
 
virtual bool isKartOnRoad () const =0
 If true, AI stays on the ArenaNode correctly, otherwise RescueAnimation will be done after sometime. More...
 
virtual void resetAfterStop ()
 Overridden if any action is needed to be done when AI stopped moving or changed driving direction. More...
 

Private Attributes

Vec3 m_target_point_lc
 Local coordinates of current target point. More...
 
Vec3 m_reverse_point
 Save the last target point before reversing, so AI will end reversing until facing in front of it. More...
 
bool m_is_stuck
 Indicates that the kart is currently stuck, and m_ticks_since_reversing is counting down. More...
 
bool m_is_uturn
 Indicates that the kart need a uturn to reach a node behind, and m_time_since_uturn is counting down. More...
 
std::set< int > m_on_node
 Holds the unique node ai has driven through, useful to tell if AI is stuck by determine the size of this set. More...
 
float m_time_since_last_shot
 Time an item has been collected and not used. More...
 
float m_ticks_since_reversing
 This is a timer that counts down when the kart is reversing to get unstuck. More...
 
float m_time_since_driving
 This is a timer that counts down when the kart is starting to drive. More...
 
float m_time_since_uturn
 This is a timer that counts down when the kart is doing u-turn. More...
 
int m_ticks_since_off_road
 This is a timer that counts when the kart start going off road. More...
 
float m_turn_radius
 Used to determine braking and nitro usage. More...
 
float m_steering_angle
 Used to determine if skidding can be done. More...
 
Vec3 m_current_forward_point
 The point in front of the AI which distance is m_kart_length, used to compensate the time difference between steering when finding next node. More...
 
int m_current_forward_node
 The ArenaNode at which the forward point located on. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from AIBaseController
static void enableDebug ()
 
static void setTestAI (int n)
 
static int getTestAI ()
 
- Static Protected Attributes inherited from AIBaseController
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...
 

Detailed Description

A base class for AI that use navmesh to work.

Member Function Documentation

◆ canSkid()

virtual bool ArenaAI::canSkid ( float  steer_fraction)
inlineprivatevirtual

Return true if AI can skid now.

Implements AIBaseController.

Reimplemented in SoccerAI.

◆ checkIfStuck()

void ArenaAI::checkIfStuck ( const float  dt)
private

Determine whether AI is stuck, by checking if it stays on the same node for a long period of time (see m_on_node), or isStuck() is true.

Parameters
dtTime step size.
Returns
True if AI is stuck

◆ determinePath()

void ArenaAI::determinePath ( int  forward,
std::vector< int > *  path 
)
private

Determine if the path to target needs to be changed to avoid bad items, it will also set the turn radius based on the new path if necessary.

Parameters
forwardForward node of current AI position.
[in,out]pathDefault path to follow, will be changed if needed.

◆ findClosestKart()

virtual void ArenaAI::findClosestKart ( bool  consider_difficulty,
bool  find_sta 
)
protectedpure virtual

Find the closest kart around this AI, implemented by sub-class.

Parameters
consider_difficultyIf take current difficulty into account.
find_staIf find SpareTireAI only.

Implemented in SoccerAI, and BattleAI.

◆ findTarget()

virtual void ArenaAI::findTarget ( )
privatepure virtual

Find a suitable target for this frame, implemented by sub-class.

Implemented in SoccerAI, BattleAI, and SpareTireAI.

◆ forceBraking()

virtual bool ArenaAI::forceBraking ( )
inlineprivatevirtual

If true, AI will always try to brake for this frame.

Reimplemented in SoccerAI.

◆ getCurrentNode()

virtual int ArenaAI::getCurrentNode ( ) const
privatepure virtual

Return the current ArenaNode the AI located on.

Implemented in SoccerAI, and BattleAI.

◆ getKartDistance()

virtual float ArenaAI::getKartDistance ( const AbstractKart kart) const
privatepure virtual

Return the distance based on graph distance matrix to any kart.

Parameters
kartAbstractKart to check.

Implemented in SoccerAI, and BattleAI.

◆ gettingUnstuck()

bool ArenaAI::gettingUnstuck ( int  ticks)
private

Function to let AI get unstuck.

Parameters
dtTime step size.
Returns
True if getting stuck is needed to be done.

◆ ignorePathFinding()

virtual bool ArenaAI::ignorePathFinding ( )
inlineprivatevirtual

If true, AI will drive directly to target without path finding.

Reimplemented in SoccerAI.

◆ isKartOnRoad()

virtual bool ArenaAI::isKartOnRoad ( ) const
privatepure virtual

If true, AI stays on the ArenaNode correctly, otherwise RescueAnimation will be done after sometime.

Implemented in SoccerAI, and BattleAI.

◆ isWaiting()

virtual bool ArenaAI::isWaiting ( ) const
privatepure virtual

If true, AI will stop moving.

Implemented in SoccerAI, and BattleAI.

◆ newLap()

virtual void ArenaAI::newLap ( int  lap)
inlinevirtual

Callback whenever a new lap is triggered.

Used by the AI to trigger a recomputation of the way to use.

Implements Controller.

◆ resetAfterStop()

virtual void ArenaAI::resetAfterStop ( )
inlineprivatevirtual

Overridden if any action is needed to be done when AI stopped moving or changed driving direction.

Reimplemented in SoccerAI.

◆ tryCollectItem()

void ArenaAI::tryCollectItem ( Vec3 aim_point,
int *  target_node 
) const
protected

Try to collect item in arena, if no suitable item is found, like they are swapped, it will follow closest kart instead.

Parameters
[out]aim_pointLocation of item.
[out]target_nodeThe node which item lied on.

◆ update()

void ArenaAI::update ( int  ticks)
virtual

This is the main entry point for the AI.

It is called once per frame for each AI and determines the behaviour of the AI, e.g. steering, accelerating/braking, firing.

Parameters
ticksNumber of physics time steps - should be 1.

Reimplemented from AIBaseController.

Reimplemented in SoccerAI, and SpareTireAI.

◆ updateAimingPosition()

bool ArenaAI::updateAimingPosition ( Vec3 target_point)
private

Update aiming position, use path finding if necessary.

Parameters
[out]target_pointSuitable target point.
Returns
True if found a suitable target point.

◆ useItems()

void ArenaAI::useItems ( const float  dt)
private

Determine how AI should use its item, different m_cur_difficulty will have a corresponding strategy.

Parameters
dtTime step size.

Member Data Documentation

◆ m_closest_kart

AbstractKart* ArenaAI::m_closest_kart
protected

Pointer to the closest kart around this kart.

◆ m_closest_kart_node

int ArenaAI::m_closest_kart_node
protected

The ArenaNode at which the closest kart located on.

◆ m_closest_kart_point

Vec3 ArenaAI::m_closest_kart_point
protected

The closest kart location.

◆ m_cur_difficulty

RaceManager::Difficulty ArenaAI::m_cur_difficulty
protected

Holds the current difficulty.

◆ m_current_forward_node

int ArenaAI::m_current_forward_node
private

The ArenaNode at which the forward point located on.

◆ m_current_forward_point

Vec3 ArenaAI::m_current_forward_point
private

The point in front of the AI which distance is m_kart_length, used to compensate the time difference between steering when finding next node.

◆ m_debug_sphere

irr::scene::ISceneNode* ArenaAI::m_debug_sphere
protected

For debugging purpose: a sphere indicating where the AI is targeting at.

◆ m_debug_sphere_next

irr::scene::ISceneNode* ArenaAI::m_debug_sphere_next
protected

For debugging purpose: a sphere indicating where the first turning corner is located.

◆ m_graph

ArenaGraph* ArenaAI::m_graph
protected

Pointer to the ArenaGraph.

◆ m_is_stuck

bool ArenaAI::m_is_stuck
private

Indicates that the kart is currently stuck, and m_ticks_since_reversing is counting down.

◆ m_is_uturn

bool ArenaAI::m_is_uturn
private

Indicates that the kart need a uturn to reach a node behind, and m_time_since_uturn is counting down.

◆ m_mini_skid

bool ArenaAI::m_mini_skid
protected

True if AI can skid, currently only do when close to target, see doSkiddingTest().

◆ m_on_node

std::set<int> ArenaAI::m_on_node
private

Holds the unique node ai has driven through, useful to tell if AI is stuck by determine the size of this set.

◆ m_reverse_point

Vec3 ArenaAI::m_reverse_point
private

Save the last target point before reversing, so AI will end reversing until facing in front of it.

◆ m_steering_angle

float ArenaAI::m_steering_angle
private

Used to determine if skidding can be done.

◆ m_target_node

int ArenaAI::m_target_node
protected

The ArenaNode at which the target point located on.

◆ m_target_point

Vec3 ArenaAI::m_target_point
protected

The coordinates of target point.

◆ m_target_point_lc

Vec3 ArenaAI::m_target_point_lc
private

Local coordinates of current target point.

◆ m_ticks_since_off_road

int ArenaAI::m_ticks_since_off_road
private

This is a timer that counts when the kart start going off road.

◆ m_ticks_since_reversing

float ArenaAI::m_ticks_since_reversing
private

This is a timer that counts down when the kart is reversing to get unstuck.

◆ m_time_since_driving

float ArenaAI::m_time_since_driving
private

This is a timer that counts down when the kart is starting to drive.

◆ m_time_since_last_shot

float ArenaAI::m_time_since_last_shot
private

Time an item has been collected and not used.

◆ m_time_since_uturn

float ArenaAI::m_time_since_uturn
private

This is a timer that counts down when the kart is doing u-turn.

◆ m_turn_radius

float ArenaAI::m_turn_radius
private

Used to determine braking and nitro usage.


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