Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/worldentities/ControllableEntity.h @ 7533

Last change on this file since 7533 was 7533, checked in by dafrick, 14 years ago

Documenting in pickups module.
Cleaning up in PickupManager.
Removed some obsolete functions in HumanController and ControllableEntity, which were remenants of the old pickups module.
Fixed a bug.

  • Property svn:eol-style set to native
File size: 8.4 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 *      Reto Grieder
26 *
27 */
28
29#ifndef _ControllableEntity_H__
30#define _ControllableEntity_H__
31
32#include "OrxonoxPrereqs.h"
33
34#include <list>
35#include <string>
36#include "util/Math.h"
37#include "MobileEntity.h"
38
39namespace orxonox
40{
41    class _OrxonoxExport ControllableEntity : public MobileEntity
42    {
43        friend class PlayerInfo; // PlayerInfo uses setPlayer and removePlayer
44
45        public:
46            ControllableEntity(BaseObject* creator);
47            virtual ~ControllableEntity();
48
49            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
50            virtual void tick(float dt);
51            void setConfigValues();
52
53            virtual void changedPlayer() {}
54
55            inline PlayerInfo* getPlayer() const
56                { return this->player_; }
57            /**
58            @brief Get the player even after the ControllableEntity has stopped being the players ControllableEntity.
59            @return Returns the most recent PlayerInfo.
60            */
61            inline PlayerInfo* getFormerPlayer() const
62                { return this->formerPlayer_; }
63
64            inline void setDestroyWhenPlayerLeft(bool bDestroy)
65                { this->bDestroyWhenPlayerLeft_ = bDestroy; }
66            inline bool getDestroyWhenPlayerLeft() const
67                { return this->bDestroyWhenPlayerLeft_; }
68
69            virtual void moveFrontBack(const Vector2& value) {}
70            virtual void moveRightLeft(const Vector2& value) {}
71            virtual void moveUpDown(const Vector2& value) {}
72
73            virtual void rotateYaw(const Vector2& value);
74            virtual void rotatePitch(const Vector2& value);
75            virtual void rotateRoll(const Vector2& value);
76
77            inline void moveFrontBack(float value)
78                { this->moveFrontBack(Vector2(value, 0)); }
79            inline void moveRightLeft(float value)
80                { this->moveRightLeft(Vector2(value, 0)); }
81            inline void moveUpDown(float value)
82                { this->moveUpDown(Vector2(value, 0)); }
83
84            inline void rotateYaw(float value)
85                { this->rotateYaw(Vector2(value, 0)); }
86            inline void rotatePitch(float value)
87                { this->rotatePitch(Vector2(value, 0)); }
88            inline void rotateRoll(float value)
89                { this->rotateRoll(Vector2(value, 0)); }
90
91            void fire(unsigned int firemode);
92            virtual void fired(unsigned int firemode) {}
93            virtual void reload() {}
94
95            virtual void boost() {}
96            virtual void greet() {}
97            virtual void switchCamera();
98            virtual void mouseLook();
99
100            inline const std::string& getHudTemplate() const
101                { return this->hudtemplate_; }
102
103            inline Camera* getCamera() const
104                { return this->camera_; }
105            inline OverlayGroup* getHUD() const
106                { return this->hud_; }
107
108            void addCameraPosition(CameraPosition* position);
109            CameraPosition* getCameraPosition(unsigned int index) const;
110            inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const
111                { return this->cameraPositions_; }
112
113            inline void setCameraPositionTemplate(const std::string& name)
114                { this->cameraPositionTemplate_ = name; }
115            inline const std::string& getCameraPositionTemkplate() const
116                { return this->cameraPositionTemplate_; }
117
118            inline void setReverseCamera(CameraPosition* camera)
119                { this->reverseCamera_ = camera; }
120            inline CameraPosition* getReverseCamera() const
121                { return this->reverseCamera_; }
122
123            using WorldEntity::setPosition;
124            using WorldEntity::setOrientation;
125            using MobileEntity::setVelocity;
126            using MobileEntity::setAngularVelocity;
127
128            void setPosition(const Vector3& position);
129            void setOrientation(const Quaternion& orientation);
130            void setVelocity(const Vector3& velocity);
131            void setAngularVelocity(const Vector3& velocity);
132
133            inline bool hasLocalController() const
134                { return this->bHasLocalController_; }
135            inline bool hasHumanController() const
136                { return this->bHasHumanController_; }
137
138            inline bool isInMouseLook() const
139                { return this->bMouseLook_; }
140            inline float getMouseLookSpeed() const
141                { return this->mouseLookSpeed_; }
142            inline CameraPosition* getCurrentCameraPosition()
143                { return this->currentCameraPosition_; }
144
145            inline Controller* getXMLController() const
146                { return this->xmlcontroller_; }
147
148            inline Controller* getController() const
149                { return this->controller_; }
150            inline void setController(Controller* val)
151                { this->controller_ = val; }
152
153            virtual void setTarget( WorldEntity* target );
154            virtual WorldEntity* getTarget()
155                { return this->target_.get(); }
156            void setTargetInternal( uint32_t targetID );
157
158        protected:
159            virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead
160            virtual void removePlayer();                // don't call this directly, use friend class PlayerInfo instead
161
162            virtual void startLocalHumanControl();
163            virtual void stopLocalHumanControl();
164            virtual void parentChanged();
165
166            inline void setHudTemplate(const std::string& name)
167                { this->hudtemplate_ = name; }
168
169            Ogre::SceneNode* cameraPositionRootNode_;
170
171        private:
172            void registerVariables();
173            void setXMLController(Controller* controller);
174
175            void overwrite();
176            void processOverwrite();
177
178            void processServerPosition();
179            void processServerLinearVelocity();
180            void processServerOrientation();
181            void processServerAngularVelocity();
182
183            void processClientPosition();
184            void processClientLinearVelocity();
185            void processClientOrientation();
186            void processClientAngularVelocity();
187
188            void networkcallback_changedplayerID();
189
190            // Bullet btMotionState related
191            void setWorldTransform(const btTransform& worldTrans);
192
193            unsigned int server_overwrite_;
194            unsigned int client_overwrite_;
195
196            bool bHasLocalController_;
197            bool bHasHumanController_;
198            bool bDestroyWhenPlayerLeft_;
199
200            Vector3 server_position_;
201            Vector3 client_position_;
202            Vector3 server_linear_velocity_;
203            Vector3 client_linear_velocity_;
204            Quaternion server_orientation_;
205            Quaternion client_orientation_;
206            Vector3 server_angular_velocity_;
207            Vector3 client_angular_velocity_;
208
209            PlayerInfo* player_;
210            PlayerInfo* formerPlayer_;
211            unsigned int playerID_;
212
213            std::string hudtemplate_;
214            OverlayGroup* hud_;
215
216            Camera* camera_;
217            bool bMouseLook_;
218            float mouseLookSpeed_;
219            std::list<SmartPtr<CameraPosition> > cameraPositions_;
220            CameraPosition* currentCameraPosition_;
221            std::string cameraPositionTemplate_;
222            Controller* xmlcontroller_;
223            Controller* controller_;
224            CameraPosition* reverseCamera_;
225            WeakPtr<WorldEntity> target_;
226    };
227}
228
229#endif /* _ControllableEntity_H__ */
Note: See TracBrowser for help on using the repository browser.