SuperTuxKart
Loading...
Searching...
No Matches
arena_ai.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2016 SuperTuxKart-Team
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_ARENA_AI_HPP
20#define HEADER_ARENA_AI_HPP
21
22#include "karts/controller/ai_base_controller.hpp"
23#include "race/race_manager.hpp"
24
25#undef AI_DEBUG
26#ifdef AI_DEBUG
27#include "graphics/irr_driver.hpp"
28#endif
29
30class ArenaGraph;
31class ItemManager;
32
33namespace irr
34{
35 namespace scene { class ISceneNode; }
36}
37
42{
43protected:
44 ItemManager* m_item_manager;
45
48
51
54
57
60
63 irr::scene::ISceneNode *m_debug_sphere;
64
67 irr::scene::ISceneNode *m_debug_sphere_next;
68
71
74
78
79 // ------------------------------------------------------------------------
80 void tryCollectItem(Vec3* aim_point, int* target_node) const;
81 // ------------------------------------------------------------------------
85 virtual void findClosestKart(bool consider_difficulty, bool find_sta) = 0;
86
87private:
90
94
98
102
105 std::set<int> m_on_node;
106
109
112
115
118
121
124
127
132
135
136 void configSpeed();
137 // ------------------------------------------------------------------------
138 void configSteering();
139 // ------------------------------------------------------------------------
140 void checkIfStuck(const float dt);
141 // ------------------------------------------------------------------------
142 void determinePath(int forward, std::vector<int>* path);
143 // ------------------------------------------------------------------------
144 void doSkiddingTest();
145 // ------------------------------------------------------------------------
146 void doUTurn(const float dt);
147 // ------------------------------------------------------------------------
148 bool gettingUnstuck(int ticks);
149 // ------------------------------------------------------------------------
150 bool updateAimingPosition(Vec3* target_point);
151 // ------------------------------------------------------------------------
152 void useItems(const float dt);
153 // ------------------------------------------------------------------------
154 virtual bool canSkid(float steer_fraction) OVERRIDE
155 { return m_mini_skid; }
156 // ------------------------------------------------------------------------
158 virtual void findTarget() = 0;
159 // ------------------------------------------------------------------------
161 virtual bool forceBraking() { return false; }
162 // ------------------------------------------------------------------------
164 virtual int getCurrentNode() const = 0;
165 // ------------------------------------------------------------------------
168 virtual float getKartDistance(const AbstractKart* kart) const = 0;
169 // ------------------------------------------------------------------------
171 virtual bool ignorePathFinding() { return false; }
172 // ------------------------------------------------------------------------
174 virtual bool isWaiting() const = 0;
175 // ------------------------------------------------------------------------
178 virtual bool isKartOnRoad() const = 0;
179 // ------------------------------------------------------------------------
182 virtual void resetAfterStop() {}
183
184public:
185 ArenaAI(AbstractKart *kart);
186 // ------------------------------------------------------------------------
187 virtual ~ArenaAI() {}
188 // ------------------------------------------------------------------------
189 virtual void update(int ticks) OVERRIDE;
190 // ------------------------------------------------------------------------
191 virtual void reset() OVERRIDE;
192 // ------------------------------------------------------------------------
193 virtual void newLap(int lap) OVERRIDE {}
194
195};
196
197#endif
A base class for all AI karts.
Definition: ai_base_controller.hpp:34
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
A base class for AI that use navmesh to work.
Definition: arena_ai.hpp:42
bool m_is_uturn
Indicates that the kart need a uturn to reach a node behind, and m_time_since_uturn is counting down.
Definition: arena_ai.hpp:101
virtual void findTarget()=0
Find a suitable target for this frame, implemented by sub-class.
irr::scene::ISceneNode * m_debug_sphere_next
For debugging purpose: a sphere indicating where the first turning corner is located.
Definition: arena_ai.hpp:67
AbstractKart * m_closest_kart
Pointer to the closest kart around this kart.
Definition: arena_ai.hpp:50
int m_current_forward_node
The ArenaNode at which the forward point located on.
Definition: arena_ai.hpp:134
void configSteering()
This function config the steering (m_steering_angle) of AI.
Definition: arena_ai.cpp:246
void useItems(const float dt)
Determine how AI should use its item, different m_cur_difficulty will have a corresponding strategy.
Definition: arena_ai.cpp:419
bool m_mini_skid
True if AI can skid, currently only do when close to target, see doSkiddingTest().
Definition: arena_ai.hpp:77
Vec3 m_target_point
The coordinates of target point.
Definition: arena_ai.hpp:73
int m_ticks_since_off_road
This is a timer that counts when the kart start going off road.
Definition: arena_ai.hpp:120
virtual bool canSkid(float steer_fraction) OVERRIDE
Return true if AI can skid now.
Definition: arena_ai.hpp:154
int m_closest_kart_node
The ArenaNode at which the closest kart located on.
Definition: arena_ai.hpp:53
void doSkiddingTest()
Determine if AI should skid: When it's close to target, but not straight ahead, in front of it,...
Definition: arena_ai.cpp:635
virtual bool isWaiting() const =0
If true, AI will stop moving.
float m_time_since_uturn
This is a timer that counts down when the kart is doing u-turn.
Definition: arena_ai.hpp:117
virtual void reset() OVERRIDE
Resets the AI when a race is restarted.
Definition: arena_ai.cpp:47
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 t...
Definition: arena_ai.hpp:105
virtual bool ignorePathFinding()
If true, AI will drive directly to target without path finding.
Definition: arena_ai.hpp:171
virtual bool forceBraking()
If true, AI will always try to brake for this frame.
Definition: arena_ai.hpp:161
virtual void resetAfterStop()
Overridden if any action is needed to be done when AI stopped moving or changed driving direction.
Definition: arena_ai.hpp:182
RaceManager::Difficulty m_cur_difficulty
Holds the current difficulty.
Definition: arena_ai.hpp:59
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 rad...
Definition: arena_ai.cpp:657
virtual void newLap(int lap) OVERRIDE
Callback whenever a new lap is triggered.
Definition: arena_ai.hpp:193
virtual float getKartDistance(const AbstractKart *kart) const =0
Return the distance based on graph distance matrix to any kart.
virtual int getCurrentNode() const =0
Return the current ArenaNode the AI located on.
void configSpeed()
Configure a suitable speed depends on current turn radius.
Definition: arena_ai.cpp:341
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,...
Definition: arena_ai.cpp:581
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 (se...
Definition: arena_ai.cpp:305
bool updateAimingPosition(Vec3 *target_point)
Update aiming position, use path finding if necessary.
Definition: arena_ai.cpp:173
float m_time_since_driving
This is a timer that counts down when the kart is starting to drive.
Definition: arena_ai.hpp:114
float m_turn_radius
Used to determine braking and nitro usage.
Definition: arena_ai.hpp:123
Vec3 m_current_forward_point
The point in front of the AI which distance is m_kart_length, used to compensate the time difference ...
Definition: arena_ai.hpp:131
void doUTurn(const float dt)
Make AI reverse so that it faces in front of the last target point.
Definition: arena_ai.cpp:367
ArenaGraph * m_graph
Pointer to the ArenaGraph.
Definition: arena_ai.hpp:47
float m_steering_angle
Used to determine if skidding can be done.
Definition: arena_ai.hpp:126
Vec3 m_closest_kart_point
The closest kart location.
Definition: arena_ai.hpp:56
virtual void findClosestKart(bool consider_difficulty, bool find_sta)=0
Find the closest kart around this AI, implemented by sub-class.
int m_target_node
The ArenaNode at which the target point located on.
Definition: arena_ai.hpp:70
virtual bool isKartOnRoad() const =0
If true, AI stays on the ArenaNode correctly, otherwise RescueAnimation will be done after sometime.
bool gettingUnstuck(int ticks)
Function to let AI get unstuck.
Definition: arena_ai.cpp:393
irr::scene::ISceneNode * m_debug_sphere
For debugging purpose: a sphere indicating where the AI is targeting at.
Definition: arena_ai.hpp:63
virtual void update(int ticks) OVERRIDE
This is the main entry point for the AI.
Definition: arena_ai.cpp:80
Vec3 m_reverse_point
Save the last target point before reversing, so AI will end reversing until facing in front of it.
Definition: arena_ai.hpp:93
Vec3 m_target_point_lc
Local coordinates of current target point.
Definition: arena_ai.hpp:89
bool m_is_stuck
Indicates that the kart is currently stuck, and m_ticks_since_reversing is counting down.
Definition: arena_ai.hpp:97
float m_time_since_last_shot
Time an item has been collected and not used.
Definition: arena_ai.hpp:108
float m_ticks_since_reversing
This is a timer that counts down when the kart is reversing to get unstuck.
Definition: arena_ai.hpp:111
A graph made from navmesh.
Definition: arena_graph.hpp:35
Definition: item_manager.hpp:47
Difficulty
Game difficulty.
Definition: race_manager.hpp:230
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35