Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

almost all works now, check AITest.oxw

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