[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" |
---|
| 33 | |
---|
[2662] | 34 | #include "MobileEntity.h" |
---|
| 35 | #include "objects/weaponSystem/WeaponSystem.h" |
---|
[2072] | 36 | |
---|
| 37 | namespace orxonox |
---|
| 38 | { |
---|
[2662] | 39 | class _OrxonoxExport ControllableEntity : public MobileEntity |
---|
[2072] | 40 | { |
---|
[3038] | 41 | friend class PlayerInfo; // PlayerInfo uses setPlayer and removePlayer |
---|
| 42 | |
---|
[2072] | 43 | public: |
---|
| 44 | ControllableEntity(BaseObject* creator); |
---|
| 45 | virtual ~ControllableEntity(); |
---|
| 46 | |
---|
| 47 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
| 48 | virtual void tick(float dt); |
---|
| 49 | void registerVariables(); |
---|
[2662] | 50 | void setConfigValues(); |
---|
[2072] | 51 | |
---|
[2839] | 52 | virtual void changedPlayer() {} |
---|
[2662] | 53 | |
---|
[2072] | 54 | inline PlayerInfo* getPlayer() const |
---|
| 55 | { return this->player_; } |
---|
| 56 | |
---|
| 57 | inline void setDestroyWhenPlayerLeft(bool bDestroy) |
---|
| 58 | { this->bDestroyWhenPlayerLeft_ = bDestroy; } |
---|
| 59 | inline bool getDestroyWhenPlayerLeft() const |
---|
| 60 | { return this->bDestroyWhenPlayerLeft_; } |
---|
| 61 | |
---|
| 62 | virtual void moveFrontBack(const Vector2& value) {} |
---|
| 63 | virtual void moveRightLeft(const Vector2& value) {} |
---|
| 64 | virtual void moveUpDown(const Vector2& value) {} |
---|
| 65 | |
---|
[2662] | 66 | virtual void rotateYaw(const Vector2& value); |
---|
| 67 | virtual void rotatePitch(const Vector2& value); |
---|
| 68 | virtual void rotateRoll(const Vector2& value); |
---|
[2072] | 69 | |
---|
[2662] | 70 | inline void moveFrontBack(float value) |
---|
| 71 | { this->moveFrontBack(Vector2(value, 0)); } |
---|
| 72 | inline void moveRightLeft(float value) |
---|
| 73 | { this->moveRightLeft(Vector2(value, 0)); } |
---|
| 74 | inline void moveUpDown(float value) |
---|
| 75 | { this->moveUpDown(Vector2(value, 0)); } |
---|
[2072] | 76 | |
---|
[2662] | 77 | inline void rotateYaw(float value) |
---|
| 78 | { this->rotateYaw(Vector2(value, 0)); } |
---|
| 79 | inline void rotatePitch(float value) |
---|
| 80 | { this->rotatePitch(Vector2(value, 0)); } |
---|
| 81 | inline void rotateRoll(float value) |
---|
| 82 | { this->rotateRoll(Vector2(value, 0)); } |
---|
| 83 | |
---|
| 84 | virtual void fire(WeaponMode::Enum fireMode) {} |
---|
| 85 | virtual void altFire(WeaponMode::Enum fireMode) {} |
---|
| 86 | |
---|
| 87 | virtual void boost() {} |
---|
[2072] | 88 | virtual void greet() {} |
---|
| 89 | virtual void use() {} |
---|
[2662] | 90 | virtual void dropItems() {} |
---|
[2072] | 91 | virtual void switchCamera(); |
---|
[2662] | 92 | virtual void mouseLook(); |
---|
[2072] | 93 | |
---|
| 94 | inline const std::string& getHudTemplate() const |
---|
| 95 | { return this->hudtemplate_; } |
---|
| 96 | |
---|
| 97 | inline Camera* getCamera() const |
---|
| 98 | { return this->camera_; } |
---|
| 99 | inline OverlayGroup* getHUD() const |
---|
| 100 | { return this->hud_; } |
---|
| 101 | |
---|
| 102 | void addCameraPosition(CameraPosition* position); |
---|
| 103 | CameraPosition* getCameraPosition(unsigned int index) const; |
---|
| 104 | inline const std::list<CameraPosition*>& getCameraPositions() const |
---|
| 105 | { return this->cameraPositions_; } |
---|
| 106 | |
---|
| 107 | inline void setCameraPositionTemplate(const std::string& name) |
---|
| 108 | { this->cameraPositionTemplate_ = name; } |
---|
| 109 | inline const std::string& getCameraPositionTemkplate() const |
---|
| 110 | { return this->cameraPositionTemplate_; } |
---|
| 111 | |
---|
[2662] | 112 | using WorldEntity::setPosition; |
---|
| 113 | using WorldEntity::setOrientation; |
---|
| 114 | using MobileEntity::setVelocity; |
---|
| 115 | using MobileEntity::setAngularVelocity; |
---|
| 116 | |
---|
| 117 | void setPosition(const Vector3& position); |
---|
| 118 | void setOrientation(const Quaternion& orientation); |
---|
| 119 | void setVelocity(const Vector3& velocity); |
---|
| 120 | void setAngularVelocity(const Vector3& velocity); |
---|
| 121 | |
---|
| 122 | inline bool hasLocalController() const |
---|
| 123 | { return this->bHasLocalController_; } |
---|
| 124 | inline bool hasHumanController() const |
---|
| 125 | { return this->bHasHumanController_; } |
---|
| 126 | |
---|
| 127 | inline bool isInMouseLook() const |
---|
| 128 | { return this->bMouseLook_; } |
---|
| 129 | inline float getMouseLookSpeed() const |
---|
| 130 | { return this->mouseLookSpeed_; } |
---|
| 131 | |
---|
[3049] | 132 | inline Controller* getXMLController() const |
---|
| 133 | { return this->xmlcontroller_; } |
---|
| 134 | |
---|
[2072] | 135 | protected: |
---|
[3038] | 136 | virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead |
---|
| 137 | virtual void removePlayer(); // don't call this directly, use friend class PlayerInfo instead |
---|
| 138 | |
---|
[2662] | 139 | virtual void startLocalHumanControl(); |
---|
| 140 | virtual void stopLocalHumanControl(); |
---|
[2851] | 141 | virtual void parentChanged(); |
---|
[2072] | 142 | |
---|
| 143 | inline void setHudTemplate(const std::string& name) |
---|
| 144 | { this->hudtemplate_ = name; } |
---|
| 145 | |
---|
| 146 | private: |
---|
[3049] | 147 | void setXMLController(Controller* controller); |
---|
| 148 | |
---|
[2072] | 149 | void overwrite(); |
---|
| 150 | void processOverwrite(); |
---|
| 151 | |
---|
| 152 | void processServerPosition(); |
---|
[2662] | 153 | void processServerLinearVelocity(); |
---|
[2072] | 154 | void processServerOrientation(); |
---|
[2662] | 155 | void processServerAngularVelocity(); |
---|
[2072] | 156 | |
---|
| 157 | void processClientPosition(); |
---|
[2662] | 158 | void processClientLinearVelocity(); |
---|
[2072] | 159 | void processClientOrientation(); |
---|
[2662] | 160 | void processClientAngularVelocity(); |
---|
[2072] | 161 | |
---|
| 162 | void networkcallback_changedplayerID(); |
---|
| 163 | |
---|
[2662] | 164 | // Bullet btMotionState related |
---|
| 165 | void setWorldTransform(const btTransform& worldTrans); |
---|
| 166 | |
---|
[2072] | 167 | unsigned int server_overwrite_; |
---|
| 168 | unsigned int client_overwrite_; |
---|
| 169 | |
---|
[2662] | 170 | bool bHasLocalController_; |
---|
| 171 | bool bHasHumanController_; |
---|
| 172 | bool bDestroyWhenPlayerLeft_; |
---|
[2072] | 173 | |
---|
| 174 | Vector3 server_position_; |
---|
| 175 | Vector3 client_position_; |
---|
[2662] | 176 | Vector3 server_linear_velocity_; |
---|
| 177 | Vector3 client_linear_velocity_; |
---|
[2072] | 178 | Quaternion server_orientation_; |
---|
| 179 | Quaternion client_orientation_; |
---|
[2662] | 180 | Vector3 server_angular_velocity_; |
---|
| 181 | Vector3 client_angular_velocity_; |
---|
[2072] | 182 | |
---|
| 183 | PlayerInfo* player_; |
---|
| 184 | unsigned int playerID_; |
---|
[2662] | 185 | |
---|
[2072] | 186 | std::string hudtemplate_; |
---|
| 187 | OverlayGroup* hud_; |
---|
[2662] | 188 | |
---|
[2072] | 189 | Camera* camera_; |
---|
[2662] | 190 | bool bMouseLook_; |
---|
| 191 | float mouseLookSpeed_; |
---|
| 192 | Ogre::SceneNode* cameraPositionRootNode_; |
---|
[2072] | 193 | std::list<CameraPosition*> cameraPositions_; |
---|
| 194 | std::string cameraPositionTemplate_; |
---|
[3049] | 195 | Controller* xmlcontroller_; |
---|
[2072] | 196 | }; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | #endif /* _ControllableEntity_H__ */ |
---|