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
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.
22 #include "karts/controller/arena_ai.hpp"
24 #include "LinearMath/btTransform.h"
26 #undef BALL_AIM_DEBUG
27 #ifdef BALL_AIM_DEBUG
28 #include "graphics/irr_driver.hpp"
29 #endif
31 class SoccerWorld;
36 class SoccerAI : public ArenaAI
37 {
38 private:
40 #ifdef BALL_AIM_DEBUG
41  irr::scene::ISceneNode *m_red_sphere;
42  irr::scene::ISceneNode *m_blue_sphere;
43 #endif
49  KartTeam m_cur_team;
52  KartTeam m_opp_team;
66  btTransform m_front_transform;
68  // ------------------------------------------------------------------------
70  // ------------------------------------------------------------------------
71  bool determineOvertakePosition(const Vec3& ball_lc, const Vec3& aim_lc,
72  Vec3* overtake_lc);
73  // ------------------------------------------------------------------------
74  bool isOvertakable(const Vec3& ball_lc);
75  // ------------------------------------------------------------------------
76  float rotateSlope(float old_slope, bool rotate_up);
77  // ------------------------------------------------------------------------
78  virtual bool canSkid(float steer_fraction) OVERRIDE
79  { return m_mini_skid && !(m_overtake_ball || m_chasing_ball); }
80  // ------------------------------------------------------------------------
81  virtual void findClosestKart(bool consider_difficulty,
82  bool find_sta) OVERRIDE;
83  // ------------------------------------------------------------------------
84  virtual void findTarget() OVERRIDE;
85  // ------------------------------------------------------------------------
86  virtual bool forceBraking() OVERRIDE { return m_force_brake; }
87  // ------------------------------------------------------------------------
88  virtual int getCurrentNode() const OVERRIDE;
89  // ------------------------------------------------------------------------
90  virtual float getKartDistance(const AbstractKart* kart) const OVERRIDE;
91  // ------------------------------------------------------------------------
92  virtual bool ignorePathFinding() OVERRIDE
93  { return m_overtake_ball || m_chasing_ball; }
94  // ------------------------------------------------------------------------
95  virtual bool isKartOnRoad() const OVERRIDE;
96  // ------------------------------------------------------------------------
97  virtual bool isWaiting() const OVERRIDE;
98  // ------------------------------------------------------------------------
99  virtual void resetAfterStop() OVERRIDE { m_overtake_ball = false; }
101 public:
102  SoccerAI(AbstractKart *kart);
103  ~SoccerAI();
104  virtual void update (int ticks) OVERRIDE;
105  virtual void reset() OVERRIDE;
107 };
109 #endif
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. ...
Definition: soccer_ai.cpp:334
KartTeam m_cur_team
Save the team this AI belongs to.
Definition: soccer_ai.hpp:49
virtual bool isWaiting() const OVERRIDE
If true, AI will stop moving.
Definition: soccer_ai.cpp:501
The actual soccer AI.
Definition: soccer_ai.hpp:36
bool m_overtake_ball
Define which way to handle to ball, either steer with it, or overtake it (Defense).
Definition: soccer_ai.hpp:56
A wrapper around bullets btVector3 to include conventient conversion functions (e.g.
Definition: vec3.hpp:34
virtual void findTarget() OVERRIDE
Find a suitable target to follow, it will first call SoccerWorld::getBallChaser to check if this AI s...
Definition: soccer_ai.cpp:182
virtual bool ignorePathFinding() OVERRIDE
If true, AI will drive directly to target without path finding.
Definition: soccer_ai.hpp:92
virtual int getCurrentNode() const OVERRIDE
Return the current ArenaNode the AI located on.
Definition: soccer_ai.cpp:495
float rotateSlope(float old_slope, bool rotate_up)
Used in determineOvertakePosition to adjust the overtake position which is calculated by slope of lin...
Definition: soccer_ai.cpp:476
KartTeam m_opp_team
Save the opposite team of this AI team.
Definition: soccer_ai.hpp:52
virtual bool canSkid(float steer_fraction) OVERRIDE
Return true if AI can skid now.
Definition: soccer_ai.hpp:78
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 ...
Definition: soccer_ai.cpp:141
SoccerWorld * m_world
Keep a pointer to world.
Definition: soccer_ai.hpp:46
Vec3 determineBallAimingPosition()
Determine the point for aiming when try to steer or overtake the ball.
Definition: soccer_ai.cpp:225
virtual bool isKartOnRoad() const OVERRIDE
If true, AI stays on the ArenaNode correctly, otherwise RescueAnimation will be done after sometime...
Definition: soccer_ai.cpp:514
virtual float getKartDistance(const AbstractKart *kart) const OVERRIDE
Return the distance based on graph distance matrix to any kart.
Definition: soccer_ai.cpp:507
bool m_chasing_ball
True if AI should steer with the ball.
Definition: soccer_ai.hpp:62
virtual void resetAfterStop() OVERRIDE
Overridden if any action is needed to be done when AI stopped moving or changed driving direction...
Definition: soccer_ai.hpp:99
virtual void update(int ticks) OVERRIDE
Update m_front_transform for ball aiming functions, also make AI stop after goal. ...
Definition: soccer_ai.cpp:110
btTransform m_front_transform
The front point of kart with the same rotation of center mass, used to determine point for aiming wit...
Definition: soccer_ai.hpp:66
An implementation of WorldWithRank, to provide the soccer game mode Notice: In soccer world...
Definition: soccer_world.hpp:40
bool isOvertakable(const Vec3 &ball_lc)
Used in determineBallAimingPosition to test if AI can overtake the ball by testing distance...
Definition: soccer_ai.cpp:305
bool m_force_brake
True if forceBraking() is needed to be called.
Definition: soccer_ai.hpp:59
bool m_mini_skid
True if AI can skid, currently only do when close to target, see doSkiddingTest().
Definition: arena_ai.hpp:77
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
A base class for AI that use navmesh to work.
Definition: arena_ai.hpp:41
virtual bool forceBraking() OVERRIDE
If true, AI will always try to brake for this frame.
Definition: soccer_ai.hpp:86
virtual void reset() OVERRIDE
Resets the AI when a race is restarted.
Definition: soccer_ai.cpp:92