Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h @ 10826

Last change on this file since 10826 was 10826, checked in by gania, 8 years ago

some comments added

File size: 6.3 KB
Line 
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#ifndef _CommonController_H__
30#define _CommonController_H__
31
32
33#include "controllers/Controller.h"
34#include "worldentities/ControllableEntity.h"
35#include "worldentities/pawns/Pawn.h"
36#include <limits>
37
38
39namespace orxonox
40{
41
42    namespace FormationMode
43    {
44        enum Value
45        {
46            FINGER4, DIAMOND, WALL
47        };
48    }
49    namespace Rank
50    {
51        enum Value
52        { 
53            NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN
54        };
55
56    }
57    namespace Action
58    { 
59        enum Value
60        {
61            FLY, FIGHT, PROTECT
62        };
63    }
64 
65
66    class _OrxonoxExport CommonController : public Controller
67    {
68
69        public:
70            static const float hardcoded_projectile_speed = 750;
71
72            static const float ACTION_INTERVAL = 1.0f;
73
74
75            CommonController(Context* context);
76            virtual ~CommonController();
77
78
79
80
81
82            virtual void setFormationMode(FormationMode::Value val)
83                { this->formationMode_ = val; }
84            inline FormationMode::Value getFormationMode() const
85                { return this->formationMode_; }
86            virtual void setFormationModeXML(std::string val);
87            virtual std::string getFormationModeXML();
88
89            virtual void setRank(Rank::Value val)
90                { this->rank_ = val; }
91            inline Rank::Value getRank() const
92                { return this->rank_; }
93
94            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
95
96
97
98            virtual bool setWingman(CommonController* wingman);
99            virtual bool hasWingman();
100            static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2);
101            void setTarget(ControllableEntity* target);
102            bool hasTarget();
103            ControllableEntity* getTarget();
104            void setTargetOrientation(const Quaternion& orient);
105            void setTargetOrientation(ControllableEntity* target);
106            void setTargetPosition(const Vector3& target);
107
108            /*void spin();
109            void turn180();*/
110            Action::Value getAction ();
111            void setAction (Action::Value action, ControllableEntity* target);
112            void setAction (Action::Value action, const Vector3& target);
113            void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
114
115        protected:
116            void dodge(Vector3& thisPosition, Vector3& diffUnit);
117            int counter;
118            void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll);
119            bool moveAndRoll(float dt);
120
121            void moveToPosition(const Vector3& target, float dt);
122            void moveToTargetPosition(float dt);
123            //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes
124
125            //Mode mode_;
126            void copyOrientation(const Quaternion& orient, float dt);
127            void copyTargetOrientation(float dt);
128
129            static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
130            float squaredDistanceToTarget() const;
131            void doFire();
132            void aimAtTarget();
133            bool isLookingAtTarget(float angle) const;
134            bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle )const;
135
136            //checks if spaceship points at enemy and if there are allies inbetween
137            bool canFire();
138            std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()
139            //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
140            float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
141            void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
142            bool bSetupWorked; //<! If false, setupWeapons() is called.
143            int getFiremode(std::string name);
144
145            float randomInRange(float a, float b);
146            bool bHasTargetPosition_;
147            Vector3 targetPosition_;
148            bool bHasTargetOrientation_;
149            Quaternion targetOrientation_;
150
151            Vector3 destination_;
152            bool bHasDestination;
153
154
155            void stopMoving();
156            void setPositionOfTarget(const Vector3& target);
157            void setOrientationOfTarget(const Quaternion& orient);
158            bool bHasPositionOfTarget_;
159            Vector3 positionOfTarget_;
160            bool bHasOrientationOfTarget_;
161            Quaternion orientationOfTarget_;
162
163
164            WeakPtr<ControllableEntity> target_;
165            //WeakPtr<ControllableEntity> thisEntity_;
166
167           
168
169            Action::Value action_;
170            bool bEngaging_;
171            bool bShooting_;
172            WeakPtr<ControllableEntity> objectiveTarget_;
173
174            void lookAtTarget(float dt);
175            void stopLookingAtTarget();
176            void startLookingAtTarget();
177            bool bLookAtTarget_;
178            void maneuver();
179            void chooseManeuverType();
180            void gunsD();
181            void attack();
182            void scissors();
183            FormationMode::Value formationMode_;
184            Rank::Value rank_;
185       
186            bool executingMoveToPoint_;
187         
188        private:
189           
190               
191    };
192}
193
194#endif /* _CommonController_H__ */
Note: See TracBrowser for help on using the repository browser.