| 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 |  | 
|---|
| 39 | namespace orxonox | 
|---|
| 40 | { | 
|---|
| 41 |     /** | 
|---|
| 42 |     @brief | 
|---|
| 43 |         The ControllableEntity is derived from the @ref orxonox::MobileEntity. ControllableEntities can be controlled by @ref orxonox::Controller Controllers. | 
|---|
| 44 |         A Controller will call (based on user input, AI decision, ...) for example the function @see moveFrontBack or the function @see rotateYaw to | 
|---|
| 45 |         move the ControllableEntity through space. A Controller could also call the @see boost function to tell the ControllableEntity that he wants it to boost. | 
|---|
| 46 |     */ | 
|---|
| 47 |  | 
|---|
| 48 |     class _OrxonoxExport ControllableEntity : public MobileEntity | 
|---|
| 49 |     { | 
|---|
| 50 |         friend class PlayerInfo; // PlayerInfo uses setPlayer and removePlayer | 
|---|
| 51 |  | 
|---|
| 52 |         public: | 
|---|
| 53 |             ControllableEntity(Context* context); | 
|---|
| 54 |             virtual ~ControllableEntity(); | 
|---|
| 55 |  | 
|---|
| 56 |             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; | 
|---|
| 57 |             virtual void tick(float dt) override; | 
|---|
| 58 |             void setConfigValues(); | 
|---|
| 59 |  | 
|---|
| 60 |             virtual void changedPlayer() {} | 
|---|
| 61 |  | 
|---|
| 62 |             inline PlayerInfo* getPlayer() const | 
|---|
| 63 |                 { return this->player_; } | 
|---|
| 64 |             /** | 
|---|
| 65 |             @brief Get the player even after the ControllableEntity has stopped being the players ControllableEntity. | 
|---|
| 66 |             @return Returns the most recent PlayerInfo. | 
|---|
| 67 |             */ | 
|---|
| 68 |             inline PlayerInfo* getFormerPlayer() const | 
|---|
| 69 |                 { return this->formerPlayer_; } | 
|---|
| 70 |  | 
|---|
| 71 |             inline void setDestroyWhenPlayerLeft(bool bDestroy) | 
|---|
| 72 |                 { this->bDestroyWhenPlayerLeft_ = bDestroy; } | 
|---|
| 73 |             inline bool getDestroyWhenPlayerLeft() const | 
|---|
| 74 |                 { return this->bDestroyWhenPlayerLeft_; } | 
|---|
| 75 |  | 
|---|
| 76 |             virtual void moveFrontBack(const Vector2& value) {} | 
|---|
| 77 |             virtual void moveRightLeft(const Vector2& value) {} | 
|---|
| 78 |             virtual void moveUpDown(const Vector2& value) {} | 
|---|
| 79 |  | 
|---|
| 80 |             virtual void rotateYaw(const Vector2& value); | 
|---|
| 81 |             virtual void rotatePitch(const Vector2& value); | 
|---|
| 82 |             virtual void rotateRoll(const Vector2& value); | 
|---|
| 83 |  | 
|---|
| 84 |             inline void moveFrontBack(float value) | 
|---|
| 85 |                 { this->moveFrontBack(Vector2(value, 0)); } | 
|---|
| 86 |             inline void moveRightLeft(float value) | 
|---|
| 87 |                 { this->moveRightLeft(Vector2(value, 0)); } | 
|---|
| 88 |             inline void moveUpDown(float value) | 
|---|
| 89 |                 { this->moveUpDown(Vector2(value, 0)); } | 
|---|
| 90 |  | 
|---|
| 91 |             inline void rotateYaw(float value) | 
|---|
| 92 |                 { this->rotateYaw(Vector2(value, 0)); } | 
|---|
| 93 |             inline void rotatePitch(float value) | 
|---|
| 94 |                 { this->rotatePitch(Vector2(value, 0)); } | 
|---|
| 95 |             inline void rotateRoll(float value) | 
|---|
| 96 |                 { this->rotateRoll(Vector2(value, 0)); } | 
|---|
| 97 |  | 
|---|
| 98 |             void fire(unsigned int firemode); | 
|---|
| 99 |             virtual void fired(unsigned int firemode) {} | 
|---|
| 100 |             virtual void reload() {} | 
|---|
| 101 |  | 
|---|
| 102 |             /** | 
|---|
| 103 |             @brief Tells the ControllableEntity to either start or stop boosting. | 
|---|
| 104 |                    This doesn't mean, that the ControllableEntity will do so, there might be additional restrictions on boosting, but if it can, then it will. | 
|---|
| 105 |             @param bBoost If true the ControllableEntity is told to start boosting, if false it is told to stop. | 
|---|
| 106 |             */ | 
|---|
| 107 |             virtual void boost(bool bBoost) {} | 
|---|
| 108 |  | 
|---|
| 109 |             virtual void greet() {} | 
|---|
| 110 |             virtual void switchCamera(); | 
|---|
| 111 |             virtual void mouseLook(); | 
|---|
| 112 |  | 
|---|
| 113 |             inline const std::string& getHudTemplate() const | 
|---|
| 114 |                 { return this->hudtemplate_; } | 
|---|
| 115 |  | 
|---|
| 116 |             inline Camera* getCamera() const | 
|---|
| 117 |                 { return this->camera_; } | 
|---|
| 118 |             inline OverlayGroup* getHUD() const | 
|---|
| 119 |                 { return this->hud_; } | 
|---|
| 120 |  | 
|---|
| 121 |             void addCameraPosition(CameraPosition* position); | 
|---|
| 122 |             CameraPosition* getCameraPosition(unsigned int index) const; | 
|---|
| 123 |             inline const std::list<StrongPtr<CameraPosition>>& getCameraPositions() const | 
|---|
| 124 |                 { return this->cameraPositions_; } | 
|---|
| 125 |             unsigned int getCurrentCameraIndex() const; | 
|---|
| 126 |             bool setCameraPosition(unsigned int index); | 
|---|
| 127 |  | 
|---|
| 128 |             inline void setCameraPositionTemplate(const std::string& name) | 
|---|
| 129 |                 { this->cameraPositionTemplate_ = name; } | 
|---|
| 130 |             inline const std::string& getCameraPositionTemplate() const | 
|---|
| 131 |                 { return this->cameraPositionTemplate_; } | 
|---|
| 132 |  | 
|---|
| 133 |             inline void setReverseCamera(CameraPosition* camera) | 
|---|
| 134 |                 { this->reverseCamera_ = camera; } | 
|---|
| 135 |             inline CameraPosition* getReverseCamera() const | 
|---|
| 136 |                 { return this->reverseCamera_; } | 
|---|
| 137 |  | 
|---|
| 138 |             using WorldEntity::setPosition; | 
|---|
| 139 |             using WorldEntity::setOrientation; | 
|---|
| 140 |             using MobileEntity::setVelocity; | 
|---|
| 141 |             using MobileEntity::setAngularVelocity; | 
|---|
| 142 |  | 
|---|
| 143 |             virtual void setPosition(const Vector3& position) override; | 
|---|
| 144 |             virtual void setOrientation(const Quaternion& orientation) override; | 
|---|
| 145 |             virtual void setVelocity(const Vector3& velocity) override; | 
|---|
| 146 |             virtual void setAngularVelocity(const Vector3& velocity) override; | 
|---|
| 147 |  | 
|---|
| 148 |             inline bool hasLocalController() const | 
|---|
| 149 |                 { return this->bHasLocalController_; } | 
|---|
| 150 |             inline bool hasHumanController() const | 
|---|
| 151 |                 { return this->bHasHumanController_; } | 
|---|
| 152 |  | 
|---|
| 153 |             inline bool isInMouseLook() const | 
|---|
| 154 |                 { return this->bMouseLook_; } | 
|---|
| 155 |             inline float getMouseLookSpeed() const | 
|---|
| 156 |                 { return this->mouseLookSpeed_; } | 
|---|
| 157 |             inline CameraPosition* getCurrentCameraPosition() | 
|---|
| 158 |                 { return this->currentCameraPosition_; } | 
|---|
| 159 |  | 
|---|
| 160 |             inline Controller* getXMLController() const | 
|---|
| 161 |                 { return this->xmlcontroller_; } | 
|---|
| 162 |  | 
|---|
| 163 |             inline Controller* getController() const | 
|---|
| 164 |                 { return this->controller_; } | 
|---|
| 165 |             void setController(Controller* val); | 
|---|
| 166 |  | 
|---|
| 167 |  | 
|---|
| 168 |             virtual void setTarget( WorldEntity* target ); | 
|---|
| 169 |             virtual WorldEntity* getTarget() | 
|---|
| 170 |                 { return this->target_; } | 
|---|
| 171 |             void setTargetInternal( uint32_t targetID ); | 
|---|
| 172 |  | 
|---|
| 173 |             inline void setTeam(int team) | 
|---|
| 174 |                 { this->team_ = team; } | 
|---|
| 175 |             inline int getTeam() const | 
|---|
| 176 |                 { return this->team_; } | 
|---|
| 177 |  | 
|---|
| 178 |  | 
|---|
| 179 |         protected: | 
|---|
| 180 |             virtual void preDestroy() override; | 
|---|
| 181 |  | 
|---|
| 182 |             virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead | 
|---|
| 183 |             virtual void removePlayer();                // don't call this directly, use friend class PlayerInfo instead | 
|---|
| 184 |  | 
|---|
| 185 |             virtual void startLocalHumanControl(); | 
|---|
| 186 |             virtual void stopLocalHumanControl(); | 
|---|
| 187 |             virtual void parentChanged() override; | 
|---|
| 188 |  | 
|---|
| 189 |             inline void setHudTemplate(const std::string& name) | 
|---|
| 190 |                 { this->hudtemplate_ = name; } | 
|---|
| 191 |             // HACK-ish | 
|---|
| 192 |             void createHud(void); | 
|---|
| 193 |             void destroyHud(void); | 
|---|
| 194 |  | 
|---|
| 195 |             Ogre::SceneNode* cameraPositionRootNode_; | 
|---|
| 196 |  | 
|---|
| 197 |         private: | 
|---|
| 198 |             void registerVariables(); | 
|---|
| 199 |             void setXMLController(Controller* controller); | 
|---|
| 200 |  | 
|---|
| 201 |             void overwrite(); | 
|---|
| 202 |             void processOverwrite(); | 
|---|
| 203 |  | 
|---|
| 204 |             void processServerPosition(); | 
|---|
| 205 |             void processServerLinearVelocity(); | 
|---|
| 206 |             void processServerOrientation(); | 
|---|
| 207 |             void processServerAngularVelocity(); | 
|---|
| 208 |  | 
|---|
| 209 |             void processClientPosition(); | 
|---|
| 210 |             void processClientLinearVelocity(); | 
|---|
| 211 |             void processClientOrientation(); | 
|---|
| 212 |             void processClientAngularVelocity(); | 
|---|
| 213 |  | 
|---|
| 214 |             void networkcallback_changedplayerID(); | 
|---|
| 215 |  | 
|---|
| 216 |             // Bullet btMotionState related | 
|---|
| 217 |             virtual void setWorldTransform(const btTransform& worldTrans) override; | 
|---|
| 218 |  | 
|---|
| 219 |             unsigned int server_overwrite_; | 
|---|
| 220 |             unsigned int client_overwrite_; | 
|---|
| 221 |  | 
|---|
| 222 |             bool bHasLocalController_; | 
|---|
| 223 |             bool bHasHumanController_; | 
|---|
| 224 |             bool bDestroyWhenPlayerLeft_; | 
|---|
| 225 |  | 
|---|
| 226 |             Vector3 server_position_; | 
|---|
| 227 |             Vector3 client_position_; | 
|---|
| 228 |             Vector3 server_linear_velocity_; | 
|---|
| 229 |             Vector3 client_linear_velocity_; | 
|---|
| 230 |             Quaternion server_orientation_; | 
|---|
| 231 |             Quaternion client_orientation_; | 
|---|
| 232 |             Vector3 server_angular_velocity_; | 
|---|
| 233 |             Vector3 client_angular_velocity_; | 
|---|
| 234 |  | 
|---|
| 235 |             PlayerInfo* player_; | 
|---|
| 236 |             PlayerInfo* formerPlayer_; | 
|---|
| 237 |             unsigned int playerID_; | 
|---|
| 238 |  | 
|---|
| 239 |             std::string hudtemplate_; | 
|---|
| 240 |             OverlayGroup* hud_; | 
|---|
| 241 |  | 
|---|
| 242 |             Camera* camera_; | 
|---|
| 243 |             bool bMouseLook_; | 
|---|
| 244 |             float mouseLookSpeed_; | 
|---|
| 245 |             std::list<StrongPtr<CameraPosition>> cameraPositions_; | 
|---|
| 246 |             CameraPosition* currentCameraPosition_; | 
|---|
| 247 |             std::string cameraPositionTemplate_; | 
|---|
| 248 |             Controller* xmlcontroller_; | 
|---|
| 249 |             WeakPtr<Controller> controller_; | 
|---|
| 250 |             CameraPosition* reverseCamera_; | 
|---|
| 251 |             WeakPtr<WorldEntity> target_; | 
|---|
| 252 |  | 
|---|
| 253 |             int team_ ; //<! teamnumber | 
|---|
| 254 |     }; | 
|---|
| 255 | } | 
|---|
| 256 |  | 
|---|
| 257 | #endif /* _ControllableEntity_H__ */ | 
|---|