| [2072] | 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: | 
|---|
| [2662] | 25 |  *      Reto Grieder | 
|---|
| [2072] | 26 |  * | 
|---|
 | 27 |  */ | 
|---|
 | 28 |  | 
|---|
 | 29 | #ifndef _ControllableEntity_H__ | 
|---|
 | 30 | #define _ControllableEntity_H__ | 
|---|
 | 31 |  | 
|---|
 | 32 | #include "OrxonoxPrereqs.h" | 
|---|
| [3196] | 33 |  | 
|---|
 | 34 | #include <list> | 
|---|
 | 35 | #include <string> | 
|---|
 | 36 | #include "util/Math.h" | 
|---|
| [2662] | 37 | #include "MobileEntity.h" | 
|---|
| [2072] | 38 |  | 
|---|
 | 39 | namespace orxonox | 
|---|
 | 40 | { | 
|---|
| [2662] | 41 |     class _OrxonoxExport ControllableEntity : public MobileEntity | 
|---|
| [2072] | 42 |     { | 
|---|
| [3038] | 43 |         friend class PlayerInfo; // PlayerInfo uses setPlayer and removePlayer | 
|---|
 | 44 |  | 
|---|
| [2072] | 45 |         public: | 
|---|
| [9667] | 46 |             ControllableEntity(Context* context); | 
|---|
| [2072] | 47 |             virtual ~ControllableEntity(); | 
|---|
 | 48 |  | 
|---|
 | 49 |             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); | 
|---|
 | 50 |             virtual void tick(float dt); | 
|---|
| [2662] | 51 |             void setConfigValues(); | 
|---|
| [2072] | 52 |  | 
|---|
| [2839] | 53 |             virtual void changedPlayer() {} | 
|---|
| [2662] | 54 |  | 
|---|
| [2072] | 55 |             inline PlayerInfo* getPlayer() const | 
|---|
 | 56 |                 { return this->player_; } | 
|---|
| [7533] | 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_; } | 
|---|
| [2072] | 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 |  | 
|---|
| [2662] | 73 |             virtual void rotateYaw(const Vector2& value); | 
|---|
 | 74 |             virtual void rotatePitch(const Vector2& value); | 
|---|
 | 75 |             virtual void rotateRoll(const Vector2& value); | 
|---|
| [2072] | 76 |  | 
|---|
| [2662] | 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)); } | 
|---|
| [2072] | 83 |  | 
|---|
| [2662] | 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 |  | 
|---|
| [6417] | 91 |             void fire(unsigned int firemode); | 
|---|
 | 92 |             virtual void fired(unsigned int firemode) {} | 
|---|
| [3053] | 93 |             virtual void reload() {} | 
|---|
| [2662] | 94 |  | 
|---|
| [8706] | 95 |             /** | 
|---|
 | 96 |             @brief Tells the ControllableEntity to either start or stop boosting. | 
|---|
 | 97 |                    This doesn't mean, that the ControllableEntity will do so, there might be additional restrictions on boosting, but if it can, then it will. | 
|---|
 | 98 |             @param bBoost If true the ControllableEntity is told to start boosting, if false it is told to stop. | 
|---|
 | 99 |             */ | 
|---|
 | 100 |             virtual void boost(bool bBoost) {} | 
|---|
| [8891] | 101 |  | 
|---|
| [2072] | 102 |             virtual void greet() {} | 
|---|
 | 103 |             virtual void switchCamera(); | 
|---|
| [2662] | 104 |             virtual void mouseLook(); | 
|---|
| [2072] | 105 |  | 
|---|
 | 106 |             inline const std::string& getHudTemplate() const | 
|---|
 | 107 |                 { return this->hudtemplate_; } | 
|---|
 | 108 |  | 
|---|
 | 109 |             inline Camera* getCamera() const | 
|---|
 | 110 |                 { return this->camera_; } | 
|---|
 | 111 |             inline OverlayGroup* getHUD() const | 
|---|
 | 112 |                 { return this->hud_; } | 
|---|
 | 113 |  | 
|---|
 | 114 |             void addCameraPosition(CameraPosition* position); | 
|---|
 | 115 |             CameraPosition* getCameraPosition(unsigned int index) const; | 
|---|
| [5929] | 116 |             inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const | 
|---|
| [2072] | 117 |                 { return this->cameraPositions_; } | 
|---|
| [8706] | 118 |             unsigned int getCurrentCameraIndex() const; | 
|---|
 | 119 |             bool setCameraPosition(unsigned int index); | 
|---|
| [2072] | 120 |  | 
|---|
 | 121 |             inline void setCameraPositionTemplate(const std::string& name) | 
|---|
 | 122 |                 { this->cameraPositionTemplate_ = name; } | 
|---|
| [8706] | 123 |             inline const std::string& getCameraPositionTemplate() const | 
|---|
| [2072] | 124 |                 { return this->cameraPositionTemplate_; } | 
|---|
 | 125 |  | 
|---|
| [3089] | 126 |             inline void setReverseCamera(CameraPosition* camera) | 
|---|
 | 127 |                 { this->reverseCamera_ = camera; } | 
|---|
 | 128 |             inline CameraPosition* getReverseCamera() const | 
|---|
 | 129 |                 { return this->reverseCamera_; } | 
|---|
 | 130 |  | 
|---|
| [2662] | 131 |             using WorldEntity::setPosition; | 
|---|
 | 132 |             using WorldEntity::setOrientation; | 
|---|
 | 133 |             using MobileEntity::setVelocity; | 
|---|
 | 134 |             using MobileEntity::setAngularVelocity; | 
|---|
 | 135 |  | 
|---|
 | 136 |             void setPosition(const Vector3& position); | 
|---|
 | 137 |             void setOrientation(const Quaternion& orientation); | 
|---|
 | 138 |             void setVelocity(const Vector3& velocity); | 
|---|
 | 139 |             void setAngularVelocity(const Vector3& velocity); | 
|---|
 | 140 |  | 
|---|
 | 141 |             inline bool hasLocalController() const | 
|---|
 | 142 |                 { return this->bHasLocalController_; } | 
|---|
 | 143 |             inline bool hasHumanController() const | 
|---|
 | 144 |                 { return this->bHasHumanController_; } | 
|---|
 | 145 |  | 
|---|
 | 146 |             inline bool isInMouseLook() const | 
|---|
 | 147 |                 { return this->bMouseLook_; } | 
|---|
 | 148 |             inline float getMouseLookSpeed() const | 
|---|
 | 149 |                 { return this->mouseLookSpeed_; } | 
|---|
| [7163] | 150 |             inline CameraPosition* getCurrentCameraPosition() | 
|---|
 | 151 |                 { return this->currentCameraPosition_; } | 
|---|
| [2662] | 152 |  | 
|---|
| [3049] | 153 |             inline Controller* getXMLController() const | 
|---|
 | 154 |                 { return this->xmlcontroller_; } | 
|---|
 | 155 |  | 
|---|
| [6417] | 156 |             inline Controller* getController() const | 
|---|
| [8891] | 157 |                 { return this->controller_.get(); } | 
|---|
 | 158 |             void setController(Controller* val); | 
|---|
| [6417] | 159 |  | 
|---|
| [8891] | 160 |  | 
|---|
| [6417] | 161 |             virtual void setTarget( WorldEntity* target ); | 
|---|
 | 162 |             virtual WorldEntity* getTarget() | 
|---|
 | 163 |                 { return this->target_.get(); } | 
|---|
 | 164 |             void setTargetInternal( uint32_t targetID ); | 
|---|
 | 165 |  | 
|---|
| [9348] | 166 |             inline void setTeam(int team) | 
|---|
 | 167 |                 { this->team_ = team; } | 
|---|
 | 168 |             inline int getTeam() const | 
|---|
 | 169 |                 { return this->team_; } | 
|---|
| [9016] | 170 |  | 
|---|
| [2072] | 171 |         protected: | 
|---|
| [7889] | 172 |             virtual void preDestroy(); | 
|---|
 | 173 |  | 
|---|
| [3038] | 174 |             virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead | 
|---|
 | 175 |             virtual void removePlayer();                // don't call this directly, use friend class PlayerInfo instead | 
|---|
 | 176 |  | 
|---|
| [2662] | 177 |             virtual void startLocalHumanControl(); | 
|---|
 | 178 |             virtual void stopLocalHumanControl(); | 
|---|
| [2851] | 179 |             virtual void parentChanged(); | 
|---|
| [2072] | 180 |  | 
|---|
 | 181 |             inline void setHudTemplate(const std::string& name) | 
|---|
 | 182 |                 { this->hudtemplate_ = name; } | 
|---|
| [8706] | 183 |             // HACK-ish | 
|---|
 | 184 |             void createHud(void); | 
|---|
 | 185 |             void destroyHud(void); | 
|---|
| [2072] | 186 |  | 
|---|
| [7163] | 187 |             Ogre::SceneNode* cameraPositionRootNode_; | 
|---|
 | 188 |  | 
|---|
| [2072] | 189 |         private: | 
|---|
| [7163] | 190 |             void registerVariables(); | 
|---|
| [3049] | 191 |             void setXMLController(Controller* controller); | 
|---|
 | 192 |  | 
|---|
| [2072] | 193 |             void overwrite(); | 
|---|
 | 194 |             void processOverwrite(); | 
|---|
 | 195 |  | 
|---|
 | 196 |             void processServerPosition(); | 
|---|
| [2662] | 197 |             void processServerLinearVelocity(); | 
|---|
| [2072] | 198 |             void processServerOrientation(); | 
|---|
| [2662] | 199 |             void processServerAngularVelocity(); | 
|---|
| [2072] | 200 |  | 
|---|
 | 201 |             void processClientPosition(); | 
|---|
| [2662] | 202 |             void processClientLinearVelocity(); | 
|---|
| [2072] | 203 |             void processClientOrientation(); | 
|---|
| [2662] | 204 |             void processClientAngularVelocity(); | 
|---|
| [2072] | 205 |  | 
|---|
 | 206 |             void networkcallback_changedplayerID(); | 
|---|
 | 207 |  | 
|---|
| [2662] | 208 |             // Bullet btMotionState related | 
|---|
 | 209 |             void setWorldTransform(const btTransform& worldTrans); | 
|---|
 | 210 |  | 
|---|
| [2072] | 211 |             unsigned int server_overwrite_; | 
|---|
 | 212 |             unsigned int client_overwrite_; | 
|---|
 | 213 |  | 
|---|
| [2662] | 214 |             bool bHasLocalController_; | 
|---|
 | 215 |             bool bHasHumanController_; | 
|---|
 | 216 |             bool bDestroyWhenPlayerLeft_; | 
|---|
| [2072] | 217 |  | 
|---|
 | 218 |             Vector3 server_position_; | 
|---|
 | 219 |             Vector3 client_position_; | 
|---|
| [2662] | 220 |             Vector3 server_linear_velocity_; | 
|---|
 | 221 |             Vector3 client_linear_velocity_; | 
|---|
| [2072] | 222 |             Quaternion server_orientation_; | 
|---|
 | 223 |             Quaternion client_orientation_; | 
|---|
| [2662] | 224 |             Vector3 server_angular_velocity_; | 
|---|
 | 225 |             Vector3 client_angular_velocity_; | 
|---|
| [2072] | 226 |  | 
|---|
 | 227 |             PlayerInfo* player_; | 
|---|
| [7533] | 228 |             PlayerInfo* formerPlayer_; | 
|---|
| [2072] | 229 |             unsigned int playerID_; | 
|---|
| [2662] | 230 |  | 
|---|
| [2072] | 231 |             std::string hudtemplate_; | 
|---|
 | 232 |             OverlayGroup* hud_; | 
|---|
| [2662] | 233 |  | 
|---|
| [2072] | 234 |             Camera* camera_; | 
|---|
| [2662] | 235 |             bool bMouseLook_; | 
|---|
 | 236 |             float mouseLookSpeed_; | 
|---|
| [5929] | 237 |             std::list<SmartPtr<CameraPosition> > cameraPositions_; | 
|---|
| [6417] | 238 |             CameraPosition* currentCameraPosition_; | 
|---|
| [2072] | 239 |             std::string cameraPositionTemplate_; | 
|---|
| [3049] | 240 |             Controller* xmlcontroller_; | 
|---|
| [8891] | 241 |             WeakPtr<Controller> controller_; | 
|---|
| [3089] | 242 |             CameraPosition* reverseCamera_; | 
|---|
| [6417] | 243 |             WeakPtr<WorldEntity> target_; | 
|---|
| [9016] | 244 |  | 
|---|
| [9348] | 245 |             int team_ ; //<! teamnumber | 
|---|
| [2072] | 246 |     }; | 
|---|
 | 247 | } | 
|---|
 | 248 |  | 
|---|
 | 249 | #endif /* _ControllableEntity_H__ */ | 
|---|