Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ai2/src/orxonox/controllers/ArtificialController.h @ 8786

Last change on this file since 8786 was 8786, checked in by jo, 13 years ago

Bots can fetch pickups. Waypointmanagement is unstable yet.

  • Property svn:eol-style set to native
File size: 6.7 KB
RevLine 
[2362]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:
[7163]25 *      Dominik Solenicki
[2362]26 *
27 */
28
29#ifndef _ArtificialController_H__
30#define _ArtificialController_H__
31
32#include "OrxonoxPrereqs.h"
33
[8763]34#include <map>
[7163]35
[3196]36#include "util/Math.h"
[2362]37#include "Controller.h"
[7163]38#include "controllers/NewHumanController.h"
[8723]39#include "weaponsystem/WeaponSystem.h"
[2362]40
41namespace orxonox
42{
[5929]43    class _OrxonoxExport ArtificialController : public Controller
[2362]44    {
45        public:
46            ArtificialController(BaseObject* creator);
47            virtual ~ArtificialController();
[6417]48
[7163]49            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
50
[5929]51            void abandonTarget(Pawn* target);
[2362]52
[7163]53            inline void setTeam(int team)
54                { this->team_ = team; }
55            inline int getTeam() const
56                { return this->team_; }
57
58            inline void setFormationFlight(bool formation)
59                { this->formationFlight_ = formation; }
60            inline bool getFormationFlight() const
61                { return this->formationFlight_; }
62
63            inline void setFormationSize(int size)
64                { this->maxFormationSize_ = size; }
65            inline int getFormationSize() const
66                { return this->maxFormationSize_; }
67
68            inline void setPassive(bool passive)
69                { this->passive_ = passive; }
70            inline bool getPassive() const
71                { return this->passive_; }
72
73            virtual void changedControllableEntity();
74
75            static void formationflight(const bool form);
76            static void masteraction(const int action);
77            static void followme();
78            static void passivebehaviour(const bool passive);
79            static void formationsize(const int size);
80
[8723]81            virtual void doFire();
[8757]82            void setBotLevel(float level=1.0f);
83            inline float getBotLevel() const
[8723]84                { return this->botlevel_; }
85            static void setAllBotLevel(float level);
[8769]86            //WAYPOINT FUNCTIONS
87            void addWaypoint(WorldEntity* waypoint);
88            WorldEntity* getWaypoint(unsigned int index) const;
[8723]89
[8769]90            inline void setAccuracy(float accuracy)
91                { this->squaredaccuracy_ = accuracy*accuracy; }
92            inline float getAccuracy() const
93                { return sqrt(this->squaredaccuracy_); }
94            void updatePointsOfInterest(std::string name, float distance);
[8786]95            void manageWaypoints();
[8769]96
[5929]97        protected:
[2362]98
[7163]99            int team_;
100            bool formationFlight_;
101            bool passive_;
102            unsigned int maxFormationSize_;
103            int freedomCount_;
104            enum State {SLAVE, MASTER, FREE};
105            State state_;
106            std::vector<ArtificialController*> slaves_;
107            ArtificialController *myMaster_;
108            enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
109            SpecificMasterAction specificMasterAction_;
110            int specificMasterActionHoldCount_;
111            float speedCounter_; //for speed adjustment when following
112
[3049]113            void moveToPosition(const Vector3& target);
114            void moveToTargetPosition();
115
[8706]116            virtual void positionReached() {}
117
[7163]118            void removeFromFormation();
119            void unregisterSlave();
120            void searchNewMaster();
121            void commandSlaves();
122            void setNewMasterWithinFormation();
123
124            void freeSlaves();
125            void forceFreeSlaves();
126            void loseMasterState();
127            void forceFreedom();
128            bool forcedFree();
129
130            void specificMasterActionHold();
131            void turn180Init();
132            void turn180();
133            void spinInit();
134            void spin();
135            void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100);
136            void followRandomHumanInit();
137            void follow();
138            void followForSlaves(const Vector3& target);
139
[3049]140            void setTargetPosition(const Vector3& target);
[2362]141            void searchRandomTargetPosition();
[3049]142
143            void setTarget(Pawn* target);
[2362]144            void searchNewTarget();
145            void forgetTarget();
146            void aimAtTarget();
147
148            bool isCloseAtTarget(float distance) const;
149            bool isLookingAtTarget(float angle) const;
150
[7163]151            void targetDied();
152
[3049]153            static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
[8741]154            void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost.
[3049]155
[2362]156            bool bHasTargetPosition_;
157            Vector3 targetPosition_;
[5929]158            WeakPtr<Pawn> target_;
[2362]159            bool bShooting_;
160
[8741]161            float botlevel_; //<! Makes the level of a bot configurable.
[8723]162            enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
163            Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_;
[8757]164            void setPreviousMode();
[8769]165
166            //WEAPONSYSTEM DATA
167            std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons()
168            //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
169            float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
[8735]170            void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
171            bool bSetupWorked; //<! If false, setupWeapons() is called.
[8763]172            int getFiremode(std::string name);
[8769]173
174            //WAYPOINT DATA
175            std::vector<WorldEntity*> waypoints_;
176            size_t currentWaypoint_;
177            float squaredaccuracy_;
[8786]178            WorldEntity* defaultWaypoint_;
[2362]179    };
180}
181
182#endif /* _ArtificialController_H__ */
Note: See TracBrowser for help on using the repository browser.