| [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: | 
|---|
|  | 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 registerVariables(); | 
|---|
| [2662] | 52 | void setConfigValues(); | 
|---|
| [2072] | 53 |  | 
|---|
| [2839] | 54 | virtual void changedPlayer() {} | 
|---|
| [2662] | 55 |  | 
|---|
| [2072] | 56 | inline PlayerInfo* getPlayer() const | 
|---|
|  | 57 | { return this->player_; } | 
|---|
|  | 58 |  | 
|---|
|  | 59 | inline void setDestroyWhenPlayerLeft(bool bDestroy) | 
|---|
|  | 60 | { this->bDestroyWhenPlayerLeft_ = bDestroy; } | 
|---|
|  | 61 | inline bool getDestroyWhenPlayerLeft() const | 
|---|
|  | 62 | { return this->bDestroyWhenPlayerLeft_; } | 
|---|
|  | 63 |  | 
|---|
|  | 64 | virtual void moveFrontBack(const Vector2& value) {} | 
|---|
|  | 65 | virtual void moveRightLeft(const Vector2& value) {} | 
|---|
|  | 66 | virtual void moveUpDown(const Vector2& value) {} | 
|---|
|  | 67 |  | 
|---|
| [2662] | 68 | virtual void rotateYaw(const Vector2& value); | 
|---|
|  | 69 | virtual void rotatePitch(const Vector2& value); | 
|---|
|  | 70 | virtual void rotateRoll(const Vector2& value); | 
|---|
| [2072] | 71 |  | 
|---|
| [2662] | 72 | inline void moveFrontBack(float value) | 
|---|
|  | 73 | { this->moveFrontBack(Vector2(value, 0)); } | 
|---|
|  | 74 | inline void moveRightLeft(float value) | 
|---|
|  | 75 | { this->moveRightLeft(Vector2(value, 0)); } | 
|---|
|  | 76 | inline void moveUpDown(float value) | 
|---|
|  | 77 | { this->moveUpDown(Vector2(value, 0)); } | 
|---|
| [2072] | 78 |  | 
|---|
| [2662] | 79 | inline void rotateYaw(float value) | 
|---|
|  | 80 | { this->rotateYaw(Vector2(value, 0)); } | 
|---|
|  | 81 | inline void rotatePitch(float value) | 
|---|
|  | 82 | { this->rotatePitch(Vector2(value, 0)); } | 
|---|
|  | 83 | inline void rotateRoll(float value) | 
|---|
|  | 84 | { this->rotateRoll(Vector2(value, 0)); } | 
|---|
|  | 85 |  | 
|---|
| [6417] | 86 | void fire(unsigned int firemode); | 
|---|
|  | 87 | virtual void fired(unsigned int firemode) {} | 
|---|
| [3053] | 88 | virtual void reload() {} | 
|---|
| [2662] | 89 |  | 
|---|
|  | 90 | virtual void boost() {} | 
|---|
| [2072] | 91 | virtual void greet() {} | 
|---|
| [3073] | 92 | virtual void useItem() {} | 
|---|
| [2662] | 93 | virtual void dropItems() {} | 
|---|
| [2072] | 94 | virtual void switchCamera(); | 
|---|
| [2662] | 95 | virtual void mouseLook(); | 
|---|
| [2072] | 96 |  | 
|---|
|  | 97 | inline const std::string& getHudTemplate() const | 
|---|
|  | 98 | { return this->hudtemplate_; } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | inline Camera* getCamera() const | 
|---|
|  | 101 | { return this->camera_; } | 
|---|
|  | 102 | inline OverlayGroup* getHUD() const | 
|---|
|  | 103 | { return this->hud_; } | 
|---|
|  | 104 |  | 
|---|
|  | 105 | void addCameraPosition(CameraPosition* position); | 
|---|
|  | 106 | CameraPosition* getCameraPosition(unsigned int index) const; | 
|---|
| [5929] | 107 | inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const | 
|---|
| [2072] | 108 | { return this->cameraPositions_; } | 
|---|
|  | 109 |  | 
|---|
|  | 110 | inline void setCameraPositionTemplate(const std::string& name) | 
|---|
|  | 111 | { this->cameraPositionTemplate_ = name; } | 
|---|
|  | 112 | inline const std::string& getCameraPositionTemkplate() const | 
|---|
|  | 113 | { return this->cameraPositionTemplate_; } | 
|---|
|  | 114 |  | 
|---|
| [3089] | 115 | inline void setReverseCamera(CameraPosition* camera) | 
|---|
|  | 116 | { this->reverseCamera_ = camera; } | 
|---|
|  | 117 | inline CameraPosition* getReverseCamera() const | 
|---|
|  | 118 | { return this->reverseCamera_; } | 
|---|
|  | 119 |  | 
|---|
| [2662] | 120 | using WorldEntity::setPosition; | 
|---|
|  | 121 | using WorldEntity::setOrientation; | 
|---|
|  | 122 | using MobileEntity::setVelocity; | 
|---|
|  | 123 | using MobileEntity::setAngularVelocity; | 
|---|
|  | 124 |  | 
|---|
|  | 125 | void setPosition(const Vector3& position); | 
|---|
|  | 126 | void setOrientation(const Quaternion& orientation); | 
|---|
|  | 127 | void setVelocity(const Vector3& velocity); | 
|---|
|  | 128 | void setAngularVelocity(const Vector3& velocity); | 
|---|
|  | 129 |  | 
|---|
|  | 130 | inline bool hasLocalController() const | 
|---|
|  | 131 | { return this->bHasLocalController_; } | 
|---|
|  | 132 | inline bool hasHumanController() const | 
|---|
|  | 133 | { return this->bHasHumanController_; } | 
|---|
|  | 134 |  | 
|---|
|  | 135 | inline bool isInMouseLook() const | 
|---|
|  | 136 | { return this->bMouseLook_; } | 
|---|
|  | 137 | inline float getMouseLookSpeed() const | 
|---|
|  | 138 | { return this->mouseLookSpeed_; } | 
|---|
| [6994] | 139 | inline CameraPosition* getCurrentCameraPosition() | 
|---|
|  | 140 | { return this->currentCameraPosition_; } | 
|---|
| [2662] | 141 |  | 
|---|
| [3049] | 142 | inline Controller* getXMLController() const | 
|---|
|  | 143 | { return this->xmlcontroller_; } | 
|---|
|  | 144 |  | 
|---|
| [6417] | 145 | inline Controller* getController() const | 
|---|
|  | 146 | { return this->controller_; } | 
|---|
|  | 147 | inline void setController(Controller* val) | 
|---|
|  | 148 | { this->controller_ = val; } | 
|---|
|  | 149 |  | 
|---|
|  | 150 | virtual void setTarget( WorldEntity* target ); | 
|---|
|  | 151 | virtual WorldEntity* getTarget() | 
|---|
|  | 152 | { return this->target_.get(); } | 
|---|
|  | 153 | void setTargetInternal( uint32_t targetID ); | 
|---|
|  | 154 |  | 
|---|
| [2072] | 155 | protected: | 
|---|
| [3038] | 156 | virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead | 
|---|
|  | 157 | virtual void removePlayer();                // don't call this directly, use friend class PlayerInfo instead | 
|---|
|  | 158 |  | 
|---|
| [2662] | 159 | virtual void startLocalHumanControl(); | 
|---|
|  | 160 | virtual void stopLocalHumanControl(); | 
|---|
| [2851] | 161 | virtual void parentChanged(); | 
|---|
| [2072] | 162 |  | 
|---|
|  | 163 | inline void setHudTemplate(const std::string& name) | 
|---|
|  | 164 | { this->hudtemplate_ = name; } | 
|---|
|  | 165 |  | 
|---|
|  | 166 | private: | 
|---|
| [3049] | 167 | void setXMLController(Controller* controller); | 
|---|
|  | 168 |  | 
|---|
| [2072] | 169 | void overwrite(); | 
|---|
|  | 170 | void processOverwrite(); | 
|---|
|  | 171 |  | 
|---|
|  | 172 | void processServerPosition(); | 
|---|
| [2662] | 173 | void processServerLinearVelocity(); | 
|---|
| [2072] | 174 | void processServerOrientation(); | 
|---|
| [2662] | 175 | void processServerAngularVelocity(); | 
|---|
| [2072] | 176 |  | 
|---|
|  | 177 | void processClientPosition(); | 
|---|
| [2662] | 178 | void processClientLinearVelocity(); | 
|---|
| [2072] | 179 | void processClientOrientation(); | 
|---|
| [2662] | 180 | void processClientAngularVelocity(); | 
|---|
| [2072] | 181 |  | 
|---|
|  | 182 | void networkcallback_changedplayerID(); | 
|---|
|  | 183 |  | 
|---|
| [2662] | 184 | // Bullet btMotionState related | 
|---|
|  | 185 | void setWorldTransform(const btTransform& worldTrans); | 
|---|
|  | 186 |  | 
|---|
| [2072] | 187 | unsigned int server_overwrite_; | 
|---|
|  | 188 | unsigned int client_overwrite_; | 
|---|
|  | 189 |  | 
|---|
| [2662] | 190 | bool bHasLocalController_; | 
|---|
|  | 191 | bool bHasHumanController_; | 
|---|
|  | 192 | bool bDestroyWhenPlayerLeft_; | 
|---|
| [2072] | 193 |  | 
|---|
|  | 194 | Vector3 server_position_; | 
|---|
|  | 195 | Vector3 client_position_; | 
|---|
| [2662] | 196 | Vector3 server_linear_velocity_; | 
|---|
|  | 197 | Vector3 client_linear_velocity_; | 
|---|
| [2072] | 198 | Quaternion server_orientation_; | 
|---|
|  | 199 | Quaternion client_orientation_; | 
|---|
| [2662] | 200 | Vector3 server_angular_velocity_; | 
|---|
|  | 201 | Vector3 client_angular_velocity_; | 
|---|
| [2072] | 202 |  | 
|---|
|  | 203 | PlayerInfo* player_; | 
|---|
|  | 204 | unsigned int playerID_; | 
|---|
| [2662] | 205 |  | 
|---|
| [2072] | 206 | std::string hudtemplate_; | 
|---|
|  | 207 | OverlayGroup* hud_; | 
|---|
| [2662] | 208 |  | 
|---|
| [2072] | 209 | Camera* camera_; | 
|---|
| [2662] | 210 | bool bMouseLook_; | 
|---|
|  | 211 | float mouseLookSpeed_; | 
|---|
|  | 212 | Ogre::SceneNode* cameraPositionRootNode_; | 
|---|
| [5929] | 213 | std::list<SmartPtr<CameraPosition> > cameraPositions_; | 
|---|
| [6417] | 214 | CameraPosition* currentCameraPosition_; | 
|---|
| [2072] | 215 | std::string cameraPositionTemplate_; | 
|---|
| [3049] | 216 | Controller* xmlcontroller_; | 
|---|
| [6417] | 217 | Controller* controller_; | 
|---|
| [3089] | 218 | CameraPosition* reverseCamera_; | 
|---|
| [6417] | 219 | WeakPtr<WorldEntity> target_; | 
|---|
| [2072] | 220 | }; | 
|---|
|  | 221 | } | 
|---|
|  | 222 |  | 
|---|
|  | 223 | #endif /* _ControllableEntity_H__ */ | 
|---|