Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.h @ 2362

Last change on this file since 2362 was 2362, checked in by landauf, 15 years ago
  • Added Bot (the artifical counterpart to HumanPlayer)
  • Added ArtificialController, the baseclass of all non-human-controllers
  • Added AIController, a simple reimplementation of the old AISpaceShip (but of course without the SpaceShip, just the AI)
  • Added currently empty class ScriptController
  • Some tweaks in PlayerInfo, ControllableEntity and Controller
  • Made Spacetator speed configurable

I don't know where, but there's still an issue in the new code, maybe even caused by the previous commit. The Server seems to crash when a Client disconnects, but only if the Server runs within the debugger.

  • Property svn:eol-style set to native
File size: 7.6 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 _ControllableEntity_H__
30#define _ControllableEntity_H__
31
32#include "OrxonoxPrereqs.h"
33
34#include "WorldEntity.h"
35#include "objects/Tickable.h"
36
37namespace orxonox
38{
39    class _OrxonoxExport ControllableEntity : public WorldEntity, public Tickable
40    {
41        public:
42            ControllableEntity(BaseObject* creator);
43            virtual ~ControllableEntity();
44
45            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
46            virtual void tick(float dt);
47            void registerVariables();
48
49            virtual void setPlayer(PlayerInfo* player);
50            virtual void removePlayer();
51            inline PlayerInfo* getPlayer() const
52                { return this->player_; }
53
54            inline void setDestroyWhenPlayerLeft(bool bDestroy)
55                { this->bDestroyWhenPlayerLeft_ = bDestroy; }
56            inline bool getDestroyWhenPlayerLeft() const
57                { return this->bDestroyWhenPlayerLeft_; }
58
59            virtual void moveFrontBack(const Vector2& value) {}
60            virtual void moveRightLeft(const Vector2& value) {}
61            virtual void moveUpDown(const Vector2& value) {}
62
63            virtual void rotateYaw(const Vector2& value) {}
64            virtual void rotatePitch(const Vector2& value) {}
65            virtual void rotateRoll(const Vector2& value) {}
66
67            inline void moveFrontBack(float value)
68                { this->moveFrontBack(Vector2(value, 0)); }
69            inline void moveRightLeft(float value)
70                { this->moveRightLeft(Vector2(value, 0)); }
71            inline void moveUpDown(float value)
72                { this->moveUpDown(Vector2(value, 0)); }
73
74            inline void rotateYaw(float value)
75                { this->rotateYaw(Vector2(value, 0)); }
76            inline void rotatePitch(float value)
77                { this->rotatePitch(Vector2(value, 0)); }
78            inline void rotateRoll(float value)
79                { this->rotateRoll(Vector2(value, 0)); }
80
81            virtual void fire() {}
82            virtual void altFire() {}
83
84            virtual void boost() {}
85            virtual void greet() {}
86            virtual void use() {}
87            virtual void switchCamera();
88
89            inline const Vector3& getVelocity() const
90                { return this->velocity_; }
91            inline const Vector3& getAcceleration() const
92                { return this->acceleration_; }
93            inline const std::string& getHudTemplate() const
94                { return this->hudtemplate_; }
95
96            using WorldEntity::setPosition;
97            using WorldEntity::translate;
98            using WorldEntity::setOrientation;
99            using WorldEntity::rotate;
100            using WorldEntity::yaw;
101            using WorldEntity::pitch;
102            using WorldEntity::roll;
103            using WorldEntity::lookAt;
104            using WorldEntity::setDirection;
105
106            void setPosition(const Vector3& position);
107            void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
108            void setOrientation(const Quaternion& orientation);
109            void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
110            void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
111            void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
112            void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
113            void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
114            void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
115
116            void setVelocity(const Vector3& velocity);
117            inline void setVelocity(float x, float y, float z)
118                { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }
119
120            inline void setAcceleration(const Vector3& acceleration)
121                { this->acceleration_ = acceleration; }
122            inline void setAcceleration(float x, float y, float z)
123                { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
124
125            inline Camera* getCamera() const
126                { return this->camera_; }
127            inline OverlayGroup* getHUD() const
128                { return this->hud_; }
129
130            void addCameraPosition(CameraPosition* position);
131            CameraPosition* getCameraPosition(unsigned int index) const;
132            inline const std::list<CameraPosition*>& getCameraPositions() const
133                { return this->cameraPositions_; }
134
135            inline void setCameraPositionTemplate(const std::string& name)
136                { this->cameraPositionTemplate_ = name; }
137            inline const std::string& getCameraPositionTemkplate() const
138                { return this->cameraPositionTemplate_; }
139
140            inline bool hasLocalController() const
141                { return this->bHasLocalController_; }
142            inline bool hasHumanController() const
143                { return this->bHasHumanController_; }
144
145        protected:
146            virtual void startLocalHumanControl();
147            virtual void stopLocalHumanControl();
148
149            inline void setHudTemplate(const std::string& name)
150                { this->hudtemplate_ = name; }
151
152            Vector3 acceleration_;
153
154        private:
155            void overwrite();
156            void processOverwrite();
157
158            void processServerPosition();
159            void processServerVelocity();
160            void processServerOrientation();
161
162            void processClientPosition();
163            void processClientVelocity();
164            void processClientOrientation();
165
166            void networkcallback_changedplayerID();
167
168            unsigned int server_overwrite_;
169            unsigned int client_overwrite_;
170
171            Vector3 velocity_;
172
173            bool bHasLocalController_;
174            bool bHasHumanController_;
175
176            Vector3 server_position_;
177            Vector3 client_position_;
178            Vector3 server_velocity_;
179            Vector3 client_velocity_;
180            Quaternion server_orientation_;
181            Quaternion client_orientation_;
182
183            PlayerInfo* player_;
184            unsigned int playerID_;
185            std::string hudtemplate_;
186            OverlayGroup* hud_;
187            Camera* camera_;
188            bool bDestroyWhenPlayerLeft_;
189
190            std::list<CameraPosition*> cameraPositions_;
191            std::string cameraPositionTemplate_;
192    };
193}
194
195#endif /* _ControllableEntity_H__ */
Note: See TracBrowser for help on using the repository browser.