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
RevLine 
[10719]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"
[10759]35#include "worldentities/pawns/Pawn.h"
[10827]36#include "util/Math.h"
37
38#include "tools/Timer.h"
39#include "tools/interfaces/Tickable.h"
[10826]40#include <limits>
[10851]41#include <algorithm>
[10847]42#include "worldentities/Actionpoint.h"
[10854]43#include "worldentities/pawns/SpaceShip.h"
[10719]44
45namespace orxonox
46{
[10759]47
48    namespace FormationMode
49    {
50        enum Value
51        {
[10826]52            FINGER4, DIAMOND, WALL
[10759]53        };
54    }
55    namespace Rank
56    {
57        enum Value
58        { 
59            NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN
60        };
61
62    }
[10805]63    namespace Action
64    { 
65        enum Value
66        {
[10847]67            NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK
[10805]68        };
[10849]69       
[10805]70    }
[10849]71   
72    struct Point {
73        Action::Value action;
74        std::string name;
75        Vector3 position;
76    } ;
77
78
79   
[10826]80 
[10761]81
[10843]82    class _OrxonoxExport CommonController : public Controller, public Tickable
[10719]83    {
[10796]84
[10719]85        public:
[10803]86            static const float hardcoded_projectile_speed = 750;
87            static const float ACTION_INTERVAL = 1.0f;
[10729]88
[10731]89            CommonController(Context* context);
90            virtual ~CommonController();
91
[10840]92            virtual void tick(float dt); 
93
[10851]94            //----[XML methods]----
[10832]95                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
[10851]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               
[10847]105                    void addActionpoint(WorldEntity* waypoint);
106                    WorldEntity* getActionpoint(unsigned int index) const;
[10851]107            //----[/XML methods]----
[10731]108
[10832]109            //----[Interaction with other Controllers]----
110                virtual bool setWingman(CommonController* wingman);
111                virtual bool hasWingman();       
[10851]112               
113                bool hasTarget();
[10832]114                ControllableEntity* getTarget();
[10851]115                     
116                Action::Value getAction ();
117                std::string getActionName();
[10759]118
[10851]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 );
[10832]123            //----[/Interaction with other Controllers]----
[10725]124
[10851]125            //----[Helper methods]----
[10832]126                float randomInRange(float a, float b);
127                static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
[10838]128                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
[10832]129                static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
[10848]130                static std::string getName( Pawn* entity ) ;
[10731]131
[10832]132                float squaredDistanceToTarget() const;
[10851]133                bool isLookingAtTarget(float angle);
134            //----[/Helper methods]----
[10731]135
[10854]136             
137                virtual void stayNearProtect();
138                virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour.
139           
[10719]140        protected:
[10851]141            //----[Flying methods]----
[10832]142                void stopMoving();
[10851]143                void stopLookingAtTarget();
144                void startLookingAtTarget();
[10789]145
[10832]146                void moveToPosition(const Vector3& target, float dt);
147                void moveToTargetPosition(float dt);
[10725]148
[10832]149                void copyOrientation(const Quaternion& orient, float dt);
150                void copyTargetOrientation(float dt);
[10725]151
[10832]152                void lookAtTarget(float dt);
[10737]153
[10851]154                void setTargetPosition(const Vector3& target);
155                void setTargetOrientation(const Quaternion& orient);
156                void setTargetOrientation(ControllableEntity* target);
157
158
159            //----[/Flying methods]----
[10832]160           
[10851]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
[10832]170                void maneuver();
171                void dodge(Vector3& thisPosition, Vector3& diffUnit);
172                bool canFire();
173                void doFire();
174                void setClosestTarget();
[10849]175                Pawn* closestTarget();
[10854]176                void startAttackingEnemiesThatAreClose();
[10851]177            //----[/Fighting methods]----           
[10832]178           
179            //----[where-to-fly information]----
[10851]180               
[10832]181                bool bHasTargetPosition_;
182                Vector3 targetPosition_;
183                bool bHasTargetOrientation_;
184                Quaternion targetOrientation_;
[10838]185               
[10832]186            //----[/where-to-fly information]----
[10838]187            //----[protect information]----
188                WeakPtr<ControllableEntity> protect_;
189            //----[/protect information]----
[10832]190            //----[who-to-kill information]----
191                WeakPtr<ControllableEntity> target_;
[10847]192               
[10832]193                bool bHasPositionOfTarget_;
194                Vector3 positionOfTarget_;
195                bool bHasOrientationOfTarget_;
196                Quaternion orientationOfTarget_;
197            //----[/who-to-kill information]----
[10805]198
[10854]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]----
[10832]210            //----["Private" variables]----
211                FormationMode::Value formationMode_;
212                Rank::Value rank_;
[10840]213                std::string protectName_;
[10848]214                std::string targetName_;
[10832]215                Action::Value action_;
[10847]216                int attackRange_;
[10851]217                bool bLookAtTarget_;       
218                bool bShooting_;
219                int maneuverCounter_;
220                int tolerance_; 
221                bool bFirstTick_;                       
[10832]222            //----[/"Private" variables]----               
[10719]223    };
224}
225
226#endif /* _CommonController_H__ */
Note: See TracBrowser for help on using the repository browser.