SuperTuxKart
Loading...
Searching...
No Matches
ai_base_controller.hpp
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
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_AI_BASE_CONTROLLER_HPP
20#define HEADER_AI_BASE_CONTROLLER_HPP
21
22#include "karts/controller/controller.hpp"
23#include "utils/cpp2011.hpp"
24
25class AIProperties;
26class Track;
27class Vec3;
28
34{
35private:
39 std::vector<int> m_collision_ticks;
40
43 bool m_stuck;
44
45protected:
46 bool m_enabled_network_ai;
47
50
53
56
59
60 static bool m_ai_debug;
61
67 static int m_test_ai;
68
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;
83
84public:
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;
112
113}; // AIBaseController
114
115#endif
116
117/* EOF */
A base class for all AI karts.
Definition: ai_base_controller.hpp:34
virtual bool action(PlayerAction action, int value, bool dry_run=false) OVERRIDE
Default: ignore actions.
Definition: ai_base_controller.hpp:101
float m_kart_width
Cache width of kart.
Definition: ai_base_controller.hpp:52
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 isPlayerController() const OVERRIDE
This function checks if this player is not an AI, i.e.
Definition: ai_base_controller.hpp:99
const AIProperties * m_ai_properties
A pointer to the AI properties for this kart.
Definition: ai_base_controller.hpp:58
bool isStuck() const
This can be called to detect if the kart is stuck (i.e.
Definition: ai_base_controller.hpp:75
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...
Definition: ai_base_controller.cpp:69
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
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 void finishedRace(float time) OVERRIDE
Called whan this controller's kart finishes the last lap.
Definition: ai_base_controller.hpp:95
Track * m_track
Keep a pointer to the track to reduce calls.
Definition: ai_base_controller.hpp:55
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
float normalizeAngle(float angle)
Normalises an angle to be between -pi and _ pi.
Definition: ai_base_controller.cpp:157
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
float steerToPoint(const Vec3 &point)
Computes the steering angle to reach a certain point.
Definition: ai_base_controller.cpp:86
static int m_test_ai
Stores the '–test-ai=n' command line parameter: It indicates which fraction of the AIs are going to b...
Definition: ai_base_controller.hpp:67
virtual void crashed(const Material *m) OVERRIDE
This is called when the kart crashed with the terrain.
Definition: ai_base_controller.cpp:235
virtual bool canSkid(float steer_fraction)=0
Return true if AI can skid now.
float m_kart_length
Length of the kart, storing it here saves many function calls.
Definition: ai_base_controller.hpp:49
A simple class that stores all AI related properties.
Definition: ai_properties.hpp:40
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
This is the base class for kart controller - that can be a player or a a robot.
Definition: controller.hpp:46
Contains the state information of an item, i.e.
Definition: item.hpp:53
Definition: material.hpp:48
Definition: track.hpp:114
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:117