Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

works for the most part, still need to fix Section and Wingman

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