Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10827 was 10827, checked in by gania, 9 years ago

same as before, a bit of polish up

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