[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 | |
---|
[3053] | 86 | virtual void fire(unsigned int firemode) {} |
---|
| 87 | virtual void reload() {} |
---|
[2662] | 88 | |
---|
| 89 | virtual void boost() {} |
---|
[2072] | 90 | virtual void greet() {} |
---|
[3073] | 91 | virtual void useItem() {} |
---|
[2662] | 92 | virtual void dropItems() {} |
---|
[2072] | 93 | virtual void switchCamera(); |
---|
[2662] | 94 | virtual void mouseLook(); |
---|
[2072] | 95 | |
---|
| 96 | inline const std::string& getHudTemplate() const |
---|
| 97 | { return this->hudtemplate_; } |
---|
| 98 | |
---|
| 99 | inline Camera* getCamera() const |
---|
| 100 | { return this->camera_; } |
---|
| 101 | inline OverlayGroup* getHUD() const |
---|
| 102 | { return this->hud_; } |
---|
| 103 | |
---|
| 104 | void addCameraPosition(CameraPosition* position); |
---|
| 105 | CameraPosition* getCameraPosition(unsigned int index) const; |
---|
| 106 | inline const std::list<CameraPosition*>& getCameraPositions() const |
---|
| 107 | { return this->cameraPositions_; } |
---|
| 108 | |
---|
| 109 | inline void setCameraPositionTemplate(const std::string& name) |
---|
| 110 | { this->cameraPositionTemplate_ = name; } |
---|
| 111 | inline const std::string& getCameraPositionTemkplate() const |
---|
| 112 | { return this->cameraPositionTemplate_; } |
---|
| 113 | |
---|
[3089] | 114 | inline void setReverseCamera(CameraPosition* camera) |
---|
| 115 | { this->reverseCamera_ = camera; } |
---|
| 116 | inline CameraPosition* getReverseCamera() const |
---|
| 117 | { return this->reverseCamera_; } |
---|
| 118 | |
---|
[2662] | 119 | using WorldEntity::setPosition; |
---|
| 120 | using WorldEntity::setOrientation; |
---|
| 121 | using MobileEntity::setVelocity; |
---|
| 122 | using MobileEntity::setAngularVelocity; |
---|
| 123 | |
---|
| 124 | void setPosition(const Vector3& position); |
---|
| 125 | void setOrientation(const Quaternion& orientation); |
---|
| 126 | void setVelocity(const Vector3& velocity); |
---|
| 127 | void setAngularVelocity(const Vector3& velocity); |
---|
| 128 | |
---|
| 129 | inline bool hasLocalController() const |
---|
| 130 | { return this->bHasLocalController_; } |
---|
| 131 | inline bool hasHumanController() const |
---|
| 132 | { return this->bHasHumanController_; } |
---|
| 133 | |
---|
| 134 | inline bool isInMouseLook() const |
---|
| 135 | { return this->bMouseLook_; } |
---|
| 136 | inline float getMouseLookSpeed() const |
---|
| 137 | { return this->mouseLookSpeed_; } |
---|
| 138 | |
---|
[3049] | 139 | inline Controller* getXMLController() const |
---|
| 140 | { return this->xmlcontroller_; } |
---|
| 141 | |
---|
[2072] | 142 | protected: |
---|
[3038] | 143 | virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead |
---|
| 144 | virtual void removePlayer(); // don't call this directly, use friend class PlayerInfo instead |
---|
| 145 | |
---|
[2662] | 146 | virtual void startLocalHumanControl(); |
---|
| 147 | virtual void stopLocalHumanControl(); |
---|
[2851] | 148 | virtual void parentChanged(); |
---|
[2072] | 149 | |
---|
| 150 | inline void setHudTemplate(const std::string& name) |
---|
| 151 | { this->hudtemplate_ = name; } |
---|
| 152 | |
---|
| 153 | private: |
---|
[3049] | 154 | void setXMLController(Controller* controller); |
---|
| 155 | |
---|
[2072] | 156 | void overwrite(); |
---|
| 157 | void processOverwrite(); |
---|
| 158 | |
---|
| 159 | void processServerPosition(); |
---|
[2662] | 160 | void processServerLinearVelocity(); |
---|
[2072] | 161 | void processServerOrientation(); |
---|
[2662] | 162 | void processServerAngularVelocity(); |
---|
[2072] | 163 | |
---|
| 164 | void processClientPosition(); |
---|
[2662] | 165 | void processClientLinearVelocity(); |
---|
[2072] | 166 | void processClientOrientation(); |
---|
[2662] | 167 | void processClientAngularVelocity(); |
---|
[2072] | 168 | |
---|
| 169 | void networkcallback_changedplayerID(); |
---|
| 170 | |
---|
[2662] | 171 | // Bullet btMotionState related |
---|
| 172 | void setWorldTransform(const btTransform& worldTrans); |
---|
| 173 | |
---|
[2072] | 174 | unsigned int server_overwrite_; |
---|
| 175 | unsigned int client_overwrite_; |
---|
| 176 | |
---|
[2662] | 177 | bool bHasLocalController_; |
---|
| 178 | bool bHasHumanController_; |
---|
| 179 | bool bDestroyWhenPlayerLeft_; |
---|
[2072] | 180 | |
---|
| 181 | Vector3 server_position_; |
---|
| 182 | Vector3 client_position_; |
---|
[2662] | 183 | Vector3 server_linear_velocity_; |
---|
| 184 | Vector3 client_linear_velocity_; |
---|
[2072] | 185 | Quaternion server_orientation_; |
---|
| 186 | Quaternion client_orientation_; |
---|
[2662] | 187 | Vector3 server_angular_velocity_; |
---|
| 188 | Vector3 client_angular_velocity_; |
---|
[2072] | 189 | |
---|
| 190 | PlayerInfo* player_; |
---|
| 191 | unsigned int playerID_; |
---|
[2662] | 192 | |
---|
[2072] | 193 | std::string hudtemplate_; |
---|
| 194 | OverlayGroup* hud_; |
---|
[2662] | 195 | |
---|
[2072] | 196 | Camera* camera_; |
---|
[2662] | 197 | bool bMouseLook_; |
---|
| 198 | float mouseLookSpeed_; |
---|
| 199 | Ogre::SceneNode* cameraPositionRootNode_; |
---|
[2072] | 200 | std::list<CameraPosition*> cameraPositions_; |
---|
| 201 | std::string cameraPositionTemplate_; |
---|
[3049] | 202 | Controller* xmlcontroller_; |
---|
[3089] | 203 | CameraPosition* reverseCamera_; |
---|
[2072] | 204 | }; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | #endif /* _ControllableEntity_H__ */ |
---|