1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2010-2015 Joerg Henrichs
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/controller.hpp"
23 #include "utils/cpp2011.hpp"
25 class AIProperties;
26 class Track;
27 class Vec3;
34 {
35 private:
39  std::vector<int> m_collision_ticks;
43  bool m_stuck;
45 protected:
46  bool m_enabled_network_ai;
52  float m_kart_width;
60  static bool m_ai_debug;
67  static int m_test_ai;
69  void setControllerName(const std::string &name) OVERRIDE;
70  float steerToPoint(const Vec3 &point);
71  float normalizeAngle(float angle);
72  // ------------------------------------------------------------------------
75  bool isStuck() const { return m_stuck; }
76  // ------------------------------------------------------------------------
77  void determineTurnRadius(const Vec3 &end, Vec3 *center,
78  float *radius) const;
79  virtual void setSteering (float angle, float dt);
80  // ------------------------------------------------------------------------
82  virtual bool canSkid(float steer_fraction) = 0;
84 public:
86  virtual ~AIBaseController() {};
87  virtual void reset() OVERRIDE;
88  virtual bool disableSlipstreamBonus() const OVERRIDE;
89  virtual void crashed(const Material *m) OVERRIDE;
90  static void enableDebug() {m_ai_debug = true; }
91  static void setTestAI(int n) {m_test_ai = n; }
92  static int getTestAI() { return m_test_ai; }
93  virtual void crashed(const AbstractKart *k) OVERRIDE {};
94  virtual void handleZipper(bool play_sound) OVERRIDE {};
95  virtual void finishedRace(float time) OVERRIDE {};
96  virtual void collectedItem(const ItemState &item,
97  float previous_energy=0) OVERRIDE {};
98  virtual void setPosition(int p) OVERRIDE {};
99  virtual bool isPlayerController() const OVERRIDE { return false; }
100  virtual bool isLocalPlayerController() const OVERRIDE { return false; }
101  virtual bool action(PlayerAction action, int value, bool dry_run=false) OVERRIDE
102  {
103  return true;
104  };
105  virtual void skidBonusTriggered() OVERRIDE {}
106  // ------------------------------------------------------------------------
107  virtual bool saveState(BareNetworkString *buffer) const OVERRIDE;
108  virtual void rewindTo(BareNetworkString *buffer) OVERRIDE;
109  void setNetworkAI(bool val) { m_enabled_network_ai = val; }
110  // ------------------------------------------------------------------------
111  virtual void update(int ticks) OVERRIDE;
113 }; // AIBaseController
115 #endif
117 /* EOF */
float m_kart_length
Length of the kart, storing it here saves many function calls.
Definition: ai_base_controller.hpp:49
virtual void setSteering(float angle, float dt)
Converts the steering angle to a lr steering in the range of -1 to 1.
Definition: ai_base_controller.cpp:185
A base class for all AI karts.
Definition: ai_base_controller.hpp:33
This is the base class for kart controller - that can be a player or a a robot.
Definition: controller.hpp:45
float m_kart_width
Cache width of kart.
Definition: ai_base_controller.hpp:52
A wrapper around bullets btVector3 to include conventient conversion functions (e.g.
Definition: vec3.hpp:34
virtual void crashed(const Material *m) OVERRIDE
This is called when the kart crashed with the terrain.
Definition: ai_base_controller.cpp:235
bool m_stuck
A flag that is set during the physics processing to indicate that this kart is stuck and needs to be ...
Definition: ai_base_controller.hpp:43
virtual bool disableSlipstreamBonus() const OVERRIDE
Certain AI levels will not receive a slipstream bonus in order to be not as hard. ...
Definition: ai_base_controller.cpp:222
types of input events / what actions the players can do
Definition: input.hpp:116
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 a...
Definition: ai_base_controller.cpp:69
static int m_test_ai
Stores the &#39;–test-ai=n&#39; command line parameter: It indicates which fraction of the AIs are going to ...
Definition: ai_base_controller.hpp:67
float steerToPoint(const Vec3 &point)
Computes the steering angle to reach a certain point.
Definition: ai_base_controller.cpp:86
A simple class that stores all AI related properties.
Definition: ai_properties.hpp:39
virtual bool isLocalPlayerController() const OVERRIDE
This function checks if this is a local player.
Definition: ai_base_controller.hpp:100
std::vector< int > m_collision_ticks
Stores the last N times when a collision happened.
Definition: ai_base_controller.hpp:39
virtual bool action(PlayerAction action, int value, bool dry_run=false) OVERRIDE
Default: ignore actions.
Definition: ai_base_controller.hpp:101
bool isStuck() const
This can be called to detect if the kart is stuck (i.e.
Definition: ai_base_controller.hpp:75
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 t...
Definition: ai_base_controller.cpp:299
const AIProperties * m_ai_properties
A pointer to the AI properties for this kart.
Definition: ai_base_controller.hpp:58
float normalizeAngle(float angle)
Normalises an angle to be between -pi and _ pi.
Definition: ai_base_controller.cpp:157
virtual void finishedRace(float time) OVERRIDE
Called whan this controller&#39;s kart finishes the last lap.
Definition: ai_base_controller.hpp:95
virtual bool isPlayerController() const OVERRIDE
This function checks if this player is not an AI, i.e.
Definition: ai_base_controller.hpp:99
Definition: material.hpp:47
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:52
Definition: script_track.cpp:52
Contains the state information of an item, i.e.
Definition: item.hpp:52
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
virtual bool canSkid(float steer_fraction)=0
Return true if AI can skid now.
Track * m_track
Keep a pointer to the track to reduce calls.
Definition: ai_base_controller.hpp:55