Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Gani changed something

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