[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" |
---|
[2662] | 33 | #include "MobileEntity.h" |
---|
[2072] | 34 | |
---|
| 35 | namespace orxonox |
---|
| 36 | { |
---|
[2662] | 37 | class _OrxonoxExport ControllableEntity : public MobileEntity |
---|
[2072] | 38 | { |
---|
[3038] | 39 | friend class PlayerInfo; // PlayerInfo uses setPlayer and removePlayer |
---|
| 40 | |
---|
[2072] | 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(); |
---|
[2662] | 48 | void setConfigValues(); |
---|
[2072] | 49 | |
---|
[2839] | 50 | virtual void changedPlayer() {} |
---|
[2662] | 51 | |
---|
[2072] | 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 | |
---|
[2662] | 64 | virtual void rotateYaw(const Vector2& value); |
---|
| 65 | virtual void rotatePitch(const Vector2& value); |
---|
| 66 | virtual void rotateRoll(const Vector2& value); |
---|
[2072] | 67 | |
---|
[2662] | 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)); } |
---|
[2072] | 74 | |
---|
[2662] | 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 | |
---|
[3053] | 82 | virtual void fire(unsigned int firemode) {} |
---|
| 83 | virtual void reload() {} |
---|
[2662] | 84 | |
---|
| 85 | virtual void boost() {} |
---|
[2072] | 86 | virtual void greet() {} |
---|
[3073] | 87 | virtual void useItem() {} |
---|
[2662] | 88 | virtual void dropItems() {} |
---|
[2072] | 89 | virtual void switchCamera(); |
---|
[2662] | 90 | virtual void mouseLook(); |
---|
[2072] | 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 | |
---|
[2662] | 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 | |
---|
[3049] | 130 | inline Controller* getXMLController() const |
---|
| 131 | { return this->xmlcontroller_; } |
---|
| 132 | |
---|
[2072] | 133 | protected: |
---|
[3038] | 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 | |
---|
[2662] | 137 | virtual void startLocalHumanControl(); |
---|
| 138 | virtual void stopLocalHumanControl(); |
---|
[2851] | 139 | virtual void parentChanged(); |
---|
[2072] | 140 | |
---|
| 141 | inline void setHudTemplate(const std::string& name) |
---|
| 142 | { this->hudtemplate_ = name; } |
---|
| 143 | |
---|
| 144 | private: |
---|
[3049] | 145 | void setXMLController(Controller* controller); |
---|
| 146 | |
---|
[2072] | 147 | void overwrite(); |
---|
| 148 | void processOverwrite(); |
---|
| 149 | |
---|
| 150 | void processServerPosition(); |
---|
[2662] | 151 | void processServerLinearVelocity(); |
---|
[2072] | 152 | void processServerOrientation(); |
---|
[2662] | 153 | void processServerAngularVelocity(); |
---|
[2072] | 154 | |
---|
| 155 | void processClientPosition(); |
---|
[2662] | 156 | void processClientLinearVelocity(); |
---|
[2072] | 157 | void processClientOrientation(); |
---|
[2662] | 158 | void processClientAngularVelocity(); |
---|
[2072] | 159 | |
---|
| 160 | void networkcallback_changedplayerID(); |
---|
| 161 | |
---|
[2662] | 162 | // Bullet btMotionState related |
---|
| 163 | void setWorldTransform(const btTransform& worldTrans); |
---|
| 164 | |
---|
[2072] | 165 | unsigned int server_overwrite_; |
---|
| 166 | unsigned int client_overwrite_; |
---|
| 167 | |
---|
[2662] | 168 | bool bHasLocalController_; |
---|
| 169 | bool bHasHumanController_; |
---|
| 170 | bool bDestroyWhenPlayerLeft_; |
---|
[2072] | 171 | |
---|
| 172 | Vector3 server_position_; |
---|
| 173 | Vector3 client_position_; |
---|
[2662] | 174 | Vector3 server_linear_velocity_; |
---|
| 175 | Vector3 client_linear_velocity_; |
---|
[2072] | 176 | Quaternion server_orientation_; |
---|
| 177 | Quaternion client_orientation_; |
---|
[2662] | 178 | Vector3 server_angular_velocity_; |
---|
| 179 | Vector3 client_angular_velocity_; |
---|
[2072] | 180 | |
---|
| 181 | PlayerInfo* player_; |
---|
| 182 | unsigned int playerID_; |
---|
[2662] | 183 | |
---|
[2072] | 184 | std::string hudtemplate_; |
---|
| 185 | OverlayGroup* hud_; |
---|
[2662] | 186 | |
---|
[2072] | 187 | Camera* camera_; |
---|
[2662] | 188 | bool bMouseLook_; |
---|
| 189 | float mouseLookSpeed_; |
---|
| 190 | Ogre::SceneNode* cameraPositionRootNode_; |
---|
[2072] | 191 | std::list<CameraPosition*> cameraPositions_; |
---|
| 192 | std::string cameraPositionTemplate_; |
---|
[3049] | 193 | Controller* xmlcontroller_; |
---|
[2072] | 194 | }; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | #endif /* _ControllableEntity_H__ */ |
---|