Debian Codegraph @

src/game/ai.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2015 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef AI_HPP
17 #define AI_HPP
18
19 #include "../common/targetnodebase.hpp"
20 #include <MCVector2d>
21 #include <memory>
22
23 class Car;
24 class Race;
25 class Track;
26 class TrackTile;
27
28 //! Class that implements the artificial intelligence of the computer players.
29 class AI
30 {
31 public:
32 //! Constructor.
33 AI(Car & car, std::shared_ptr<Race> race);
34
35 //! Update.
36 void update(bool isRaceCompleted);
37
38 //! Set the current race track.
39 void setTrack(std::shared_ptr<Track> track);
40
41 //! Get associated car.
42 Car & car() const;
43
44 private:
45 //! Steering logic.
46 void steerControl(TargetNodeBasePtr tnode);
47
48 //! Brake/accelerate logic.
49 void speedControl(TrackTile & currentTile, bool isRaceCompleted);
50
51 void setRandomTolerance();
52
53 Car & m_car;
54
55 std::shared_ptr<Race> m_race;
56
57 std::shared_ptr<Track> m_track;
58
59 float m_lastDiff;
60
61 size_t m_lastTargetNodeIndex;
62
63 MCVector2dF m_randomTolerance;
64 };
65
66 typedef std::shared_ptr<AI> AIPtr;
67
68 #endif // AI_HPP