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 | #include "MobileEntity.h" |
---|
34 | |
---|
35 | namespace orxonox |
---|
36 | { |
---|
37 | class _OrxonoxExport ControllableEntity : public MobileEntity |
---|
38 | { |
---|
39 | friend class PlayerInfo; // PlayerInfo uses setPlayer and removePlayer |
---|
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 | void setConfigValues(); |
---|
49 | |
---|
50 | virtual void changedPlayer() {} |
---|
51 | |
---|
52 | inline PlayerInfo* getPlayer() const |
---|
53 | { return this->player_; } |
---|
54 | |
---|
55 | inline void setDestroyWhenPlayerLeft(bool bDestroy) |
---|
56 | { this->bDestroyWhenPlayerLeft_ = bDestroy; } |
---|
57 | inline bool getDestroyWhenPlayerLeft() const |
---|
58 | { return this->bDestroyWhenPlayerLeft_; } |
---|
59 | |
---|
60 | virtual void moveFrontBack(const Vector2& value) {} |
---|
61 | virtual void moveRightLeft(const Vector2& value) {} |
---|
62 | virtual void moveUpDown(const Vector2& value) {} |
---|
63 | |
---|
64 | virtual void rotateYaw(const Vector2& value); |
---|
65 | virtual void rotatePitch(const Vector2& value); |
---|
66 | virtual void rotateRoll(const Vector2& value); |
---|
67 | |
---|
68 | inline void moveFrontBack(float value) |
---|
69 | { this->moveFrontBack(Vector2(value, 0)); } |
---|
70 | inline void moveRightLeft(float value) |
---|
71 | { this->moveRightLeft(Vector2(value, 0)); } |
---|
72 | inline void moveUpDown(float value) |
---|
73 | { this->moveUpDown(Vector2(value, 0)); } |
---|
74 | |
---|
75 | inline void rotateYaw(float value) |
---|
76 | { this->rotateYaw(Vector2(value, 0)); } |
---|
77 | inline void rotatePitch(float value) |
---|
78 | { this->rotatePitch(Vector2(value, 0)); } |
---|
79 | inline void rotateRoll(float value) |
---|
80 | { this->rotateRoll(Vector2(value, 0)); } |
---|
81 | |
---|
82 | virtual void fire(unsigned int firemode) {} |
---|
83 | virtual void reload() {} |
---|
84 | |
---|
85 | virtual void boost() {} |
---|
86 | virtual void greet() {} |
---|
87 | virtual void use() {} |
---|
88 | virtual void dropItems() {} |
---|
89 | virtual void switchCamera(); |
---|
90 | virtual void mouseLook(); |
---|
91 | |
---|
92 | inline const std::string& getHudTemplate() const |
---|
93 | { return this->hudtemplate_; } |
---|
94 | |
---|
95 | inline Camera* getCamera() const |
---|
96 | { return this->camera_; } |
---|
97 | inline OverlayGroup* getHUD() const |
---|
98 | { return this->hud_; } |
---|
99 | |
---|
100 | void addCameraPosition(CameraPosition* position); |
---|
101 | CameraPosition* getCameraPosition(unsigned int index) const; |
---|
102 | inline const std::list<CameraPosition*>& getCameraPositions() const |
---|
103 | { return this->cameraPositions_; } |
---|
104 | |
---|
105 | inline void setCameraPositionTemplate(const std::string& name) |
---|
106 | { this->cameraPositionTemplate_ = name; } |
---|
107 | inline const std::string& getCameraPositionTemkplate() const |
---|
108 | { return this->cameraPositionTemplate_; } |
---|
109 | |
---|
110 | using WorldEntity::setPosition; |
---|
111 | using WorldEntity::setOrientation; |
---|
112 | using MobileEntity::setVelocity; |
---|
113 | using MobileEntity::setAngularVelocity; |
---|
114 | |
---|
115 | void setPosition(const Vector3& position); |
---|
116 | void setOrientation(const Quaternion& orientation); |
---|
117 | void setVelocity(const Vector3& velocity); |
---|
118 | void setAngularVelocity(const Vector3& velocity); |
---|
119 | |
---|
120 | inline bool hasLocalController() const |
---|
121 | { return this->bHasLocalController_; } |
---|
122 | inline bool hasHumanController() const |
---|
123 | { return this->bHasHumanController_; } |
---|
124 | |
---|
125 | inline bool isInMouseLook() const |
---|
126 | { return this->bMouseLook_; } |
---|
127 | inline float getMouseLookSpeed() const |
---|
128 | { return this->mouseLookSpeed_; } |
---|
129 | |
---|
130 | inline Controller* getXMLController() const |
---|
131 | { return this->xmlcontroller_; } |
---|
132 | |
---|
133 | protected: |
---|
134 | virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead |
---|
135 | virtual void removePlayer(); // don't call this directly, use friend class PlayerInfo instead |
---|
136 | |
---|
137 | virtual void startLocalHumanControl(); |
---|
138 | virtual void stopLocalHumanControl(); |
---|
139 | virtual void parentChanged(); |
---|
140 | |
---|
141 | inline void setHudTemplate(const std::string& name) |
---|
142 | { this->hudtemplate_ = name; } |
---|
143 | |
---|
144 | private: |
---|
145 | void setXMLController(Controller* controller); |
---|
146 | |
---|
147 | void overwrite(); |
---|
148 | void processOverwrite(); |
---|
149 | |
---|
150 | void processServerPosition(); |
---|
151 | void processServerLinearVelocity(); |
---|
152 | void processServerOrientation(); |
---|
153 | void processServerAngularVelocity(); |
---|
154 | |
---|
155 | void processClientPosition(); |
---|
156 | void processClientLinearVelocity(); |
---|
157 | void processClientOrientation(); |
---|
158 | void processClientAngularVelocity(); |
---|
159 | |
---|
160 | void networkcallback_changedplayerID(); |
---|
161 | |
---|
162 | // Bullet btMotionState related |
---|
163 | void setWorldTransform(const btTransform& worldTrans); |
---|
164 | |
---|
165 | unsigned int server_overwrite_; |
---|
166 | unsigned int client_overwrite_; |
---|
167 | |
---|
168 | bool bHasLocalController_; |
---|
169 | bool bHasHumanController_; |
---|
170 | bool bDestroyWhenPlayerLeft_; |
---|
171 | |
---|
172 | Vector3 server_position_; |
---|
173 | Vector3 client_position_; |
---|
174 | Vector3 server_linear_velocity_; |
---|
175 | Vector3 client_linear_velocity_; |
---|
176 | Quaternion server_orientation_; |
---|
177 | Quaternion client_orientation_; |
---|
178 | Vector3 server_angular_velocity_; |
---|
179 | Vector3 client_angular_velocity_; |
---|
180 | |
---|
181 | PlayerInfo* player_; |
---|
182 | unsigned int playerID_; |
---|
183 | |
---|
184 | std::string hudtemplate_; |
---|
185 | OverlayGroup* hud_; |
---|
186 | |
---|
187 | Camera* camera_; |
---|
188 | bool bMouseLook_; |
---|
189 | float mouseLookSpeed_; |
---|
190 | Ogre::SceneNode* cameraPositionRootNode_; |
---|
191 | std::list<CameraPosition*> cameraPositions_; |
---|
192 | std::string cameraPositionTemplate_; |
---|
193 | Controller* xmlcontroller_; |
---|
194 | }; |
---|
195 | } |
---|
196 | |
---|
197 | #endif /* _ControllableEntity_H__ */ |
---|