Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed loops

File size: 8.0 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                virtual void boostControl();
159
160
161            //----[/Flying methods]----
162           
163            //----[Fighting methods]----
164                void setTarget(ControllableEntity* target);
165
166                void setPositionOfTarget(const Vector3& target);
167                void setOrientationOfTarget(const Quaternion& orient);
168
169                void setProtect (ControllableEntity* protect);
170                ControllableEntity* getProtect (); 
171
172                void maneuver();
173                void dodge(Vector3& thisPosition, Vector3& diffUnit);
174                bool canFire();
175                void doFire();
176                void setClosestTarget();
177                Pawn* closestTarget();
178                void startAttackingEnemiesThatAreClose();
179            //----[/Fighting methods]----           
180           
181            //----[where-to-fly information]----
182               
183                bool bHasTargetPosition_;
184                Vector3 targetPosition_;
185                bool bHasTargetOrientation_;
186                Quaternion targetOrientation_;
187               
188            //----[/where-to-fly information]----
189            //----[protect information]----
190                WeakPtr<ControllableEntity> protect_;
191            //----[/protect information]----
192            //----[who-to-kill information]----
193                WeakPtr<ControllableEntity> target_;
194               
195                bool bHasPositionOfTarget_;
196                Vector3 positionOfTarget_;
197                bool bHasOrientationOfTarget_;
198                Quaternion orientationOfTarget_;
199            //----[/who-to-kill information]----
200
201            //----[Actionpoint information]----
202
203                std::vector<WeakPtr<WorldEntity> > actionpoints_;
204                float squaredaccuracy_;
205                std::vector<Point > parsedActionpoints_;
206                std::vector<Point > loopActionpoints_;
207
208            //----[/Actionpoint information]----
209            //----[Actionpoint methods]----
210                void executeActionpoint();
211                void nextActionpoint();
212                void fillLoop();
213                void fillLoopReversed();
214                void moveBackToTop();
215            //----[Actionpoint methods]----
216            //----["Private" variables]----
217                FormationMode::Value formationMode_;
218                Rank::Value rank_;
219                std::string protectName_;
220                std::string targetName_;
221                Action::Value action_;
222                int attackRange_;
223                bool bLookAtTarget_;       
224                bool bShooting_;
225                int maneuverCounter_;
226                int tolerance_; 
227                bool bFirstTick_; 
228                bool bInLoop_;
229                bool bLoop_;                   
230            //----[/"Private" variables]----   
231        virtual void takeActionpoints (std::vector<Point > vector, std::vector<Point > loop, bool b);
232           
233    };
234}
235
236#endif /* _CommonController_H__ */
Note: See TracBrowser for help on using the repository browser.