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