Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h @ 10854

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

Fixed some bugs, only DivisionController works for now

File size: 7.6 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#include <algorithm>
42#include "worldentities/Actionpoint.h"
43#include "worldentities/pawns/SpaceShip.h"
44
45namespace orxonox
46{
47
48    namespace FormationMode
49    {
50        enum Value
51        {
52            FINGER4, DIAMOND, WALL
53        };
54    }
55    namespace Rank
56    {
57        enum Value
58        { 
59            NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN
60        };
61
62    }
63    namespace Action
64    { 
65        enum Value
66        {
67            NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK
68        };
69       
70    }
71   
72    struct Point {
73        Action::Value action;
74        std::string name;
75        Vector3 position;
76    } ;
77
78
79   
80 
81
82    class _OrxonoxExport CommonController : public Controller, public Tickable
83    {
84
85        public:
86            static const float hardcoded_projectile_speed = 750;
87            static const float ACTION_INTERVAL = 1.0f;
88
89            CommonController(Context* context);
90            virtual ~CommonController();
91
92            virtual void tick(float dt); 
93
94            //----[XML methods]----
95                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
96               
97                    void setFormationModeXML(std::string val);
98                    std::string getFormationModeXML();
99                    void setFormationMode(FormationMode::Value val);
100                    FormationMode::Value getFormationMode() const;
101
102                    void setRank(Rank::Value val);
103                    Rank::Value getRank() const;
104               
105                    void addActionpoint(WorldEntity* waypoint);
106                    WorldEntity* getActionpoint(unsigned int index) const;
107            //----[/XML methods]----
108
109            //----[Interaction with other Controllers]----
110                virtual bool setWingman(CommonController* wingman);
111                virtual bool hasWingman();       
112               
113                bool hasTarget();
114                ControllableEntity* getTarget();
115                     
116                Action::Value getAction ();
117                std::string getActionName();
118
119                void setAction (Action::Value action);
120                void setAction (Action::Value action, ControllableEntity* target);
121                void setAction (Action::Value action, const Vector3& target);
122                void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
123            //----[/Interaction with other Controllers]----
124
125            //----[Helper methods]----
126                float randomInRange(float a, float b);
127                static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
128                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
129                static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
130                static std::string getName( Pawn* entity ) ;
131
132                float squaredDistanceToTarget() const;
133                bool isLookingAtTarget(float angle);
134            //----[/Helper methods]----
135
136             
137                virtual void stayNearProtect();
138                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
139           
140        protected:
141            //----[Flying methods]----
142                void stopMoving();
143                void stopLookingAtTarget();
144                void startLookingAtTarget();
145
146                void moveToPosition(const Vector3& target, float dt);
147                void moveToTargetPosition(float dt);
148
149                void copyOrientation(const Quaternion& orient, float dt);
150                void copyTargetOrientation(float dt);
151
152                void lookAtTarget(float dt);
153
154                void setTargetPosition(const Vector3& target);
155                void setTargetOrientation(const Quaternion& orient);
156                void setTargetOrientation(ControllableEntity* target);
157
158
159            //----[/Flying methods]----
160           
161            //----[Fighting methods]----
162                void setTarget(ControllableEntity* target);
163
164                void setPositionOfTarget(const Vector3& target);
165                void setOrientationOfTarget(const Quaternion& orient);
166
167                void setProtect (ControllableEntity* protect);
168                ControllableEntity* getProtect (); 
169
170                void maneuver();
171                void dodge(Vector3& thisPosition, Vector3& diffUnit);
172                bool canFire();
173                void doFire();
174                void setClosestTarget();
175                Pawn* closestTarget();
176                void startAttackingEnemiesThatAreClose();
177            //----[/Fighting methods]----           
178           
179            //----[where-to-fly information]----
180               
181                bool bHasTargetPosition_;
182                Vector3 targetPosition_;
183                bool bHasTargetOrientation_;
184                Quaternion targetOrientation_;
185               
186            //----[/where-to-fly information]----
187            //----[protect information]----
188                WeakPtr<ControllableEntity> protect_;
189            //----[/protect information]----
190            //----[who-to-kill information]----
191                WeakPtr<ControllableEntity> target_;
192               
193                bool bHasPositionOfTarget_;
194                Vector3 positionOfTarget_;
195                bool bHasOrientationOfTarget_;
196                Quaternion orientationOfTarget_;
197            //----[/who-to-kill information]----
198
199            //----[Actionpoint information]----
200
201                std::vector<WeakPtr<WorldEntity> > actionpoints_;
202                float squaredaccuracy_;
203                std::vector<Point > parsedActionpoints_;
204
205            //----[/Actionpoint information]----
206            //----[Actionpoint methods]----
207                void executeActionpoint();
208                void nextActionpoint();
209            //----[Actionpoint methods]----
210            //----["Private" variables]----
211                FormationMode::Value formationMode_;
212                Rank::Value rank_;
213                std::string protectName_;
214                std::string targetName_;
215                Action::Value action_;
216                int attackRange_;
217                bool bLookAtTarget_;       
218                bool bShooting_;
219                int maneuverCounter_;
220                int tolerance_; 
221                bool bFirstTick_;                       
222            //----[/"Private" variables]----               
223    };
224}
225
226#endif /* _CommonController_H__ */
Note: See TracBrowser for help on using the repository browser.