Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

introduced loops

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