[2839] | 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 | |
---|
[8108] | 29 | /** |
---|
| 30 | @file PongAI.h |
---|
| 31 | @brief Declaration of the PongAI class. |
---|
| 32 | @ingroup Pong |
---|
| 33 | */ |
---|
| 34 | |
---|
[2839] | 35 | #ifndef _PongAI_H__ |
---|
| 36 | #define _PongAI_H__ |
---|
| 37 | |
---|
[5725] | 38 | #include "pong/PongPrereqs.h" |
---|
[2839] | 39 | |
---|
[2860] | 40 | #include <list> |
---|
[8108] | 41 | |
---|
[3196] | 42 | #include "util/Math.h" |
---|
[5693] | 43 | #include "tools/interfaces/Tickable.h" |
---|
[8108] | 44 | |
---|
[5735] | 45 | #include "controllers/Controller.h" |
---|
[2839] | 46 | |
---|
| 47 | namespace orxonox |
---|
| 48 | { |
---|
[8108] | 49 | |
---|
| 50 | /** |
---|
| 51 | @brief |
---|
| 52 | The PongAI is an artificial intelligence for the @ref orxonox::Pong "Pong" gametype. |
---|
| 53 | |
---|
| 54 | @author |
---|
| 55 | Fabian 'x3n' Landau |
---|
| 56 | |
---|
| 57 | @ingroup Pong |
---|
| 58 | */ |
---|
[5725] | 59 | class _PongExport PongAI : public Controller, public Tickable |
---|
[2839] | 60 | { |
---|
| 61 | public: |
---|
[8108] | 62 | PongAI(BaseObject* creator); //!< Constructor. Registers and initializes the object. |
---|
[2860] | 63 | virtual ~PongAI(); |
---|
[2839] | 64 | |
---|
[2857] | 65 | void setConfigValues(); |
---|
| 66 | |
---|
[8108] | 67 | virtual void tick(float dt); //!< Implements the behavior of the PongAI (i.e. its intelligence). |
---|
[2839] | 68 | |
---|
[8108] | 69 | /** |
---|
| 70 | @brief Set the ball for the AI. |
---|
| 71 | @param ball A pointer to the ball. |
---|
| 72 | */ |
---|
[2839] | 73 | void setPongBall(PongBall* ball) |
---|
| 74 | { this->ball_ = ball; } |
---|
| 75 | |
---|
| 76 | protected: |
---|
[8108] | 77 | void calculateRandomOffset(); //!< Calculates the random offset, that accounts for random errors the AI makes in order to be beatable. |
---|
| 78 | void calculateBallEndPosition(); //!< Calculate the end position the ball will be in. |
---|
| 79 | void move(char direction, bool bUseDelay); //!< Determine the movement the AI will undertake. |
---|
| 80 | void delayedMove(); //!< Is called, when a delayed move takes effect. |
---|
[2839] | 81 | |
---|
[8895] | 82 | WeakPtr<PongBall> ball_; //!< A weak pointer to the ball. |
---|
[8108] | 83 | Vector2 ballDirection_; //!< Vector to store the (x,z) direction in which the ball is flying. |
---|
| 84 | float ballEndPosition_; //!< The calculated end position of the ball. |
---|
| 85 | float randomOffset_; //!< A random offset to introduce random errors (weighted by the strength of the AI) into the AI's behavior. |
---|
| 86 | bool bChangedRandomOffset_; //!< Helper boolean, to change the random offset more often. |
---|
| 87 | float relHysteresisOffset_; //!< A hysteresis offset. |
---|
| 88 | float strength_; //!< The strength of the AI. Ranging from 0 to 1. |
---|
[2860] | 89 | |
---|
[8108] | 90 | std::list<std::pair<Timer*, char> > reactionTimers_; //!< A list of reaction timers and the directions that take effect when their timer expires. |
---|
| 91 | char movement_; //!< The planned movement. |
---|
| 92 | char oldMove_; //!< The previous movement. |
---|
| 93 | bool bOscillationAvoidanceActive_; //!< Boolean, to avoid oscillations. |
---|
[2839] | 94 | }; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | #endif /* _PongAI_H__ */ |
---|