1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file OrxoBloxAI.h |
---|
31 | @brief Declaration of the OrxoBloxAI class. |
---|
32 | @ingroup OrxoBlox |
---|
33 | */ |
---|
34 | |
---|
35 | #ifndef _OrxoBloxAI_H__ |
---|
36 | #define _OrxoBloxAI_H__ |
---|
37 | |
---|
38 | #include "OrxoBlox/OrxoBloxPrereqs.h" |
---|
39 | |
---|
40 | #include <list> |
---|
41 | |
---|
42 | #include "util/Math.h" |
---|
43 | #include "tools/interfaces/Tickable.h" |
---|
44 | |
---|
45 | #include "controllers/Controller.h" |
---|
46 | #include "OrxoBloxBall.h" |
---|
47 | |
---|
48 | namespace orxonox |
---|
49 | { |
---|
50 | |
---|
51 | /** |
---|
52 | @brief |
---|
53 | The OrxoBloxAI is an artificial intelligence for the @ref orxonox::OrxoBlox "OrxoBlox" gametype. |
---|
54 | |
---|
55 | @author |
---|
56 | Fabian 'x3n' Landau |
---|
57 | |
---|
58 | @ingroup OrxoBlox |
---|
59 | */ |
---|
60 | class _OrxoBloxExport OrxoBloxAI : public Controller, public Tickable |
---|
61 | { |
---|
62 | public: |
---|
63 | OrxoBloxAI(Context* context); //!< Constructor. Registers and initializes the object. |
---|
64 | virtual ~OrxoBloxAI(); |
---|
65 | |
---|
66 | void setConfigValues(); |
---|
67 | |
---|
68 | virtual void tick(float dt) override; //!< Implements the behavior of the OrxoBloxAI (i.e. its intelligence). |
---|
69 | |
---|
70 | /** |
---|
71 | @brief Set the ball for the AI. |
---|
72 | @param ball A pointer to the ball. |
---|
73 | */ |
---|
74 | void setOrxoBloxBall(OrxoBloxBall* ball) |
---|
75 | { this->ball_ = ball; } |
---|
76 | |
---|
77 | protected: |
---|
78 | void calculateRandomOffset(); //!< Calculates the random offset, that accounts for random errors the AI makes in order to be beatable. |
---|
79 | void calculateBallEndPosition(); //!< Calculate the end position the ball will be in. |
---|
80 | void move(char direction, bool bUseDelay); //!< Determine the movement the AI will undertake. |
---|
81 | void delayedMove(); //!< Is called, when a delayed move takes effect. |
---|
82 | |
---|
83 | WeakPtr<OrxoBloxBall> ball_; //!< A weak pointer to the ball. |
---|
84 | Vector2 ballDirection_; //!< Vector to store the (x,z) direction in which the ball is flying. |
---|
85 | float ballEndPosition_; //!< The calculated end position of the ball. |
---|
86 | float randomOffset_; //!< A random offset to introduce random errors (weighted by the strength of the AI) into the AI's behavior. |
---|
87 | bool bChangedRandomOffset_; //!< Helper boolean, to change the random offset more often. |
---|
88 | float relHysteresisOffset_; //!< A hysteresis offset. |
---|
89 | float strength_; //!< The strength of the AI. Ranging from 0 to 1. |
---|
90 | |
---|
91 | std::list<std::pair<Timer*, char>> reactionTimers_; //!< A list of reaction timers and the directions that take effect when their timer expires. |
---|
92 | char movement_; //!< The planned movement. |
---|
93 | char oldMove_; //!< The previous movement. |
---|
94 | bool bOscillationAvoidanceActive_; //!< Boolean, to avoid oscillations. |
---|
95 | }; |
---|
96 | } |
---|
97 | |
---|
98 | #endif /* _OrxoBloxAI_H__ */ |
---|