Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gani check in before a major change

File size: 7.3 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, public Tickable
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            virtual void tick(float dt); 
81
82            //----[XML data]----
83                virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
84                //----[Action data]----
85                    Action::Value getAction ();
86                    void setAction (Action::Value action);
87                    void setAction (Action::Value action, ControllableEntity* target);
88                    void setAction (Action::Value action, const Vector3& target);
89                    void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
90                    void setActionXML( std::string val);
91                    std::string getActionXML();
92                //----[/Action data]----
93                //----[Formation data]----
94                    virtual void setFormationModeXML(std::string val);
95                    virtual std::string getFormationModeXML();
96                    virtual void setFormationMode(FormationMode::Value val)
97                        { this->formationMode_ = val; }
98                    inline FormationMode::Value getFormationMode() const
99                        { return this->formationMode_; }
100                //----[/Formation data]----
101                //----[Rank data]----
102                    virtual void setRank(Rank::Value val)
103                        { this->rank_ = val; }
104                    inline Rank::Value getRank() const
105                        { return this->rank_; }
106                //----[/Rank data]----
107                //----[Protect data]----
108                    void setProtectXML( std::string val );
109                    std::string getProtectXML ();
110                    void setProtect (ControllableEntity* protect);
111                    ControllableEntity* getProtect ();
112                //----[/Protect data]----
113            //----[/XML data]----
114
115            //----[Interaction with other Controllers]----
116                virtual bool setWingman(CommonController* wingman);
117                virtual bool hasWingman();       
118
119                void setPositionOfTarget(const Vector3& target);
120                void setOrientationOfTarget(const Quaternion& orient);
121
122                void setTarget(ControllableEntity* target);
123                ControllableEntity* getTarget();
124                bool hasTarget();
125
126                void setTargetPosition(const Vector3& target);
127                void setTargetOrientation(const Quaternion& orient);
128                void setTargetOrientation(ControllableEntity* target);
129            //----[/Interaction with other Controllers]----
130
131            //----[Helper functions]----
132                float randomInRange(float a, float b);
133                static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
134                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
135                static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
136
137                float squaredDistanceToTarget() const;
138                bool isLookingAtTarget(float angle) const;
139            //----[/Helper functions]----
140
141        protected:
142            //----[Flying functionality]----
143                void stopMoving();
144
145                void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll);
146                bool moveAndRoll(float dt);
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                void stopLookingAtTarget();
156                void startLookingAtTarget();
157
158                bool bLookAtTarget_;       
159            //----[/Flying functionality]----
160           
161            //----[Fighting functionality]----
162                void maneuver();
163                void dodge(Vector3& thisPosition, Vector3& diffUnit);
164                void aimAtTarget();           
165                bool canFire();
166                void doFire();
167                void setClosestTarget();
168
169                bool bShooting_;
170                int maneuverCounter_;         
171            //----[/Fighting functionality]----           
172           
173            //----[where-to-fly information]----
174                bool bHasTargetPosition_;
175                Vector3 targetPosition_;
176                bool bHasTargetOrientation_;
177                Quaternion targetOrientation_;
178               
179                Vector3 destination_;
180                bool bHasDestination;
181            //----[/where-to-fly information]----
182            //----[protect information]----
183                WeakPtr<ControllableEntity> protect_;
184            //----[/protect information]----
185            //----[who-to-kill information]----
186                WeakPtr<ControllableEntity> target_;
187                WeakPtr<ControllableEntity> enemy_;
188
189                bool bHasPositionOfTarget_;
190                Vector3 positionOfTarget_;
191                bool bHasOrientationOfTarget_;
192                Quaternion orientationOfTarget_;
193            //----[/who-to-kill information]----
194
195            //----["Private" variables]----
196                FormationMode::Value formationMode_;
197                Rank::Value rank_;
198                std::string protectName_;
199                Action::Value action_;
200            //----[/"Private" variables]----               
201    };
202}
203
204#endif /* _CommonController_H__ */
Note: See TracBrowser for help on using the repository browser.