SuperTuxKart
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SoccerAI Class Reference

The actual soccer AI. More...

#include <soccer_ai.hpp>

Inheritance diagram for SoccerAI:
Inheritance graph
[legend]

Public Member Functions

 SoccerAI (AbstractKart *kart)
 
virtual void update (int ticks) OVERRIDE
 Update m_front_transform for ball aiming functions, also make AI stop after goal. More...
 
virtual void reset () OVERRIDE
 Resets the AI when a race is restarted.
 
- Public Member Functions inherited from ArenaAI
 ArenaAI (AbstractKart *kart)
 
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...
 

Private Member Functions

Vec3 determineBallAimingPosition ()
 Determine the point for aiming when try to steer or overtake the ball. More...
 
bool determineOvertakePosition (const Vec3 &ball_lc, const Vec3 &aim_lc, Vec3 *overtake_lc)
 Used in determineBallAimingPosition to pick a correct point to overtake the ball. More...
 
bool isOvertakable (const Vec3 &ball_lc)
 Used in determineBallAimingPosition to test if AI can overtake the ball by testing distance. More...
 
float rotateSlope (float old_slope, bool rotate_up)
 Used in determineOvertakePosition to adjust the overtake position which is calculated by slope of line if it's too close. More...
 
virtual bool canSkid (float steer_fraction) OVERRIDE
 Return true if AI can skid now. More...
 
virtual void findClosestKart (bool consider_difficulty, bool find_sta) OVERRIDE
 Find the closest kart around this AI, it won't find the kart with same team, consider_difficulty and find_sta are not used here. More...
 
virtual void findTarget () OVERRIDE
 Find a suitable target to follow, it will first call SoccerWorld::getBallChaser to check if this AI should go chasing the ball and try to score, otherwise it will call tryCollectItem if needed. More...
 
virtual bool forceBraking () OVERRIDE
 If true, AI will always try to brake for this frame. More...
 
virtual int getCurrentNode () const OVERRIDE
 Return the current ArenaNode the AI located on. More...
 
virtual float getKartDistance (const AbstractKart *kart) const OVERRIDE
 Return the distance based on graph distance matrix to any kart. More...
 
virtual bool ignorePathFinding () OVERRIDE
 If true, AI will drive directly to target without path finding. More...
 
virtual bool isKartOnRoad () const OVERRIDE
 If true, AI stays on the ArenaNode correctly, otherwise RescueAnimation will be done after sometime. More...
 
virtual bool isWaiting () const OVERRIDE
 If true, AI will stop moving. More...
 
virtual void resetAfterStop () OVERRIDE
 Overridden if any action is needed to be done when AI stopped moving or changed driving direction. More...
 

Private Attributes

SoccerWorldm_world
 Keep a pointer to world. More...
 
KartTeam m_cur_team
 Save the team this AI belongs to. More...
 
KartTeam m_opp_team
 Save the opposite team of this AI team. More...
 
bool m_overtake_ball
 Define which way to handle to ball, either steer with it, or overtake it (Defense). More...
 
bool m_force_brake
 True if forceBraking() is needed to be called. More...
 
bool m_chasing_ball
 True if AI should steer with the ball. More...
 
btTransform m_front_transform
 The front point of kart with the same rotation of center mass, used to determine point for aiming with ball.
 

Additional Inherited Members

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

The actual soccer AI.

Member Function Documentation

◆ canSkid()

virtual bool SoccerAI::canSkid ( float  steer_fraction)
inlineprivatevirtual

Return true if AI can skid now.

Reimplemented from ArenaAI.

◆ determineBallAimingPosition()

Vec3 SoccerAI::determineBallAimingPosition ( )
private

Determine the point for aiming when try to steer or overtake the ball.

AI will overtake the ball if the aiming position calculated by world is non-reachable.

Returns
The coordinates to aim at.

◆ determineOvertakePosition()

bool SoccerAI::determineOvertakePosition ( const Vec3 ball_lc,
const Vec3 aim_lc,
Vec3 overtake_lc 
)
private

Used in determineBallAimingPosition to pick a correct point to overtake the ball.

Parameters
ball_lcLocal coordinates of the ball.
aim_lcLocal coordinates of the aiming position.
[out]overtake_lcLocal coordinates of the overtaking position.
Returns
True if overtaking is possible.

◆ findClosestKart()

void SoccerAI::findClosestKart ( bool  consider_difficulty,
bool  find_sta 
)
privatevirtual

Find the closest kart around this AI, it won't find the kart with same team, consider_difficulty and find_sta are not used here.

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

Implements ArenaAI.

◆ findTarget()

void SoccerAI::findTarget ( )
privatevirtual

Find a suitable target to follow, it will first call SoccerWorld::getBallChaser to check if this AI should go chasing the ball and try to score, otherwise it will call tryCollectItem if needed.

After that it will call SoccerWorld::getAttacker to see if this AI should attack the kart in opposite team which is chasing the ball, if not go for the closest kart found by findClosestKart.

Implements ArenaAI.

◆ forceBraking()

virtual bool SoccerAI::forceBraking ( )
inlineprivatevirtual

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

Reimplemented from ArenaAI.

◆ getCurrentNode()

int SoccerAI::getCurrentNode ( ) const
privatevirtual

Return the current ArenaNode the AI located on.

Implements ArenaAI.

◆ getKartDistance()

float SoccerAI::getKartDistance ( const AbstractKart kart) const
privatevirtual

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

Parameters
kartAbstractKart to check.

Implements ArenaAI.

◆ ignorePathFinding()

virtual bool SoccerAI::ignorePathFinding ( )
inlineprivatevirtual

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

Reimplemented from ArenaAI.

◆ isKartOnRoad()

bool SoccerAI::isKartOnRoad ( ) const
privatevirtual

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

Implements ArenaAI.

◆ isOvertakable()

bool SoccerAI::isOvertakable ( const Vec3 ball_lc)
private

Used in determineBallAimingPosition to test if AI can overtake the ball by testing distance.

Parameters
ball_lcLocal coordinates of the ball.
Returns
False if the kart is too close to the ball which can't overtake

◆ isWaiting()

bool SoccerAI::isWaiting ( ) const
privatevirtual

If true, AI will stop moving.

Implements ArenaAI.

◆ resetAfterStop()

virtual void SoccerAI::resetAfterStop ( )
inlineprivatevirtual

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

Reimplemented from ArenaAI.

◆ rotateSlope()

float SoccerAI::rotateSlope ( float  old_slope,
bool  rotate_up 
)
private

Used in determineOvertakePosition to adjust the overtake position which is calculated by slope of line if it's too close.

Parameters
old_slopeOld slope calculated.
rotate_upIf adjust the slope upwards.
Returns
A newly calculated slope.

◆ update()

void SoccerAI::update ( int  ticks)
virtual

Update m_front_transform for ball aiming functions, also make AI stop after goal.

Parameters
dtTime step size.

Reimplemented from ArenaAI.

Member Data Documentation

◆ m_chasing_ball

bool SoccerAI::m_chasing_ball
private

True if AI should steer with the ball.

◆ m_cur_team

KartTeam SoccerAI::m_cur_team
private

Save the team this AI belongs to.

◆ m_force_brake

bool SoccerAI::m_force_brake
private

True if forceBraking() is needed to be called.

◆ m_opp_team

KartTeam SoccerAI::m_opp_team
private

Save the opposite team of this AI team.

◆ m_overtake_ball

bool SoccerAI::m_overtake_ball
private

Define which way to handle to ball, either steer with it, or overtake it (Defense).

◆ m_world

SoccerWorld* SoccerAI::m_world
private

Keep a pointer to world.


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