SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
BattleAI Class Reference

The actual battle AI. More...

#include <battle_ai.hpp>

Inheritance diagram for BattleAI:
Inheritance graph
[legend]

Public Member Functions

 BattleAI (AbstractKart *kart)
 
- Public Member Functions inherited from ArenaAI
 ArenaAI (AbstractKart *kart)
 
virtual void update (int ticks) OVERRIDE
 This is the main entry point for the AI.
 
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.
 
- Public Member Functions inherited from AIBaseController
 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.
 

Protected Member Functions

virtual void findClosestKart (bool consider_difficulty, bool find_sta) OVERRIDE
 Find the closest kart around this AI, if consider_difficulty is true, AI will try to follow human players more or less depends on difficulty.
 
virtual int getCurrentNode () const OVERRIDE
 Return the current ArenaNode the AI located on.
 
- 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.
 
virtual void findClosestKart (bool consider_difficulty, bool find_sta)=0
 Find the closest kart around this AI, implemented by sub-class.
 
- 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.
 
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

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

Private Member Functions

virtual void findTarget () OVERRIDE
 Find a suitable target to follow, it will find the closest kart first, it's used as fallback if no item is found.
 
virtual float getKartDistance (const AbstractKart *kart) const OVERRIDE
 Return the distance based on graph distance matrix to any kart.
 
virtual bool isKartOnRoad () const OVERRIDE
 If true, AI stays on the ArenaNode correctly, otherwise RescueAnimation will be done after sometime.
 
virtual bool isWaiting () const OVERRIDE
 If true, AI will stop moving.
 

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.
 

Detailed Description

The actual battle AI.

Member Function Documentation

◆ findClosestKart()

void BattleAI::findClosestKart ( bool  consider_difficulty,
bool  find_sta 
)
protectedvirtual

Find the closest kart around this AI, if consider_difficulty is true, AI will try to follow human players more or less depends on difficulty.

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

Implements ArenaAI.

◆ findTarget()

void BattleAI::findTarget ( )
privatevirtual

Find a suitable target to follow, it will find the closest kart first, it's used as fallback if no item is found.

It takes the current difficulty into account, also collect life from SpareTireAI depends on current difficulty if actually they are spawned:

  • Novice and intermediate - collect them only AI has 1 life only.
  • Expert and supertux - collect them if AI dones't have 3 lives.

Implements ArenaAI.

Reimplemented in SpareTireAI.

◆ getCurrentNode()

int BattleAI::getCurrentNode ( ) const
protectedvirtual

Return the current ArenaNode the AI located on.

Implements ArenaAI.

◆ getKartDistance()

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

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

Parameters
kartAbstractKart to check.

Implements ArenaAI.

◆ isKartOnRoad()

bool BattleAI::isKartOnRoad ( ) const
privatevirtual

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

Implements ArenaAI.

◆ isWaiting()

bool BattleAI::isWaiting ( ) const
privatevirtual

If true, AI will stop moving.

Implements ArenaAI.


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