[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: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef _SpaceShip_H__ |
---|
| 30 | #define _SpaceShip_H__ |
---|
| 31 | |
---|
| 32 | #include "OrxonoxPrereqs.h" |
---|
| 33 | |
---|
[3196] | 34 | #include <string> |
---|
| 35 | #include <LinearMath/btVector3.h> |
---|
[8727] | 36 | |
---|
[7801] | 37 | #include "tools/Timer.h" |
---|
[3196] | 38 | #include "util/Math.h" |
---|
[8727] | 39 | #include "util/OrxAssert.h" |
---|
| 40 | |
---|
[2072] | 41 | #include "Pawn.h" |
---|
| 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
[8727] | 45 | |
---|
| 46 | /** |
---|
| 47 | @brief |
---|
| 48 | The SpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it. |
---|
[10437] | 49 | The feature that you can add @ref orxonox::Engine Engines is new in this class. However adding @ref orxonox::Weapon Weapons is possible because every Spaceship is a Pawn (due to inheritance) and every Pawn can carry @ref orxonox::Weapon Weapons. |
---|
[8727] | 50 | |
---|
| 51 | There are several parameters that define the behavior of the SpaceShip> |
---|
| 52 | - The <b>rotationThrust</b>, specifies the force with which the SpaceShip rotates. |
---|
| 53 | - The <b>boost</b>, there are quite some parameters pertaining to boosting. The boost is a special move of the SpaceShip, where, for a limited amount of time, it can fly considerably faster than usual. The <b>boostPower</b> is the amount of power available for boosting. The <b>boostPowerRate</b> is the rate at which the boost power is replenished. The <b>boostRate</b> is the rate at which boosting uses power. And the <b>boostCooldownDuration</b> is the time the SpaceShip cannot boost, once all the boost power has been used up. Naturally all of these parameters must be non-negative. |
---|
| 54 | - The <b>boost shaking</b>, when the SpaceShip boosts, the camera shakes to create a more immersive effect. Two parameters can be used to adjust the effect. The <b>shakeFrequency</b> is the frequency with which the camera shakes. And the <b>shakeAmplitude</b> is the amount with which the camera shakes. Again these parameters must bee non-negative. |
---|
| 55 | - The <b>lift</b> creates a more natural flight feeling through the addition of a lift force. There are again tow parameters that can be specified. The <b>lift</b> which is the lift force that is applied. And the <b>stallSpeed</b> which is the forward speed after which no more lift is generated. |
---|
| 56 | |
---|
| 57 | As mentioned @ref orxonox::Engine Engines can be mounted on the SpaceShip. Here is a (primitive) example of a SpaceShip defined in XML: |
---|
| 58 | @code |
---|
| 59 | <SpaceShip |
---|
| 60 | rotationThrust = 50 |
---|
| 61 | |
---|
| 62 | lift = 1; |
---|
| 63 | stallSpeed = 220; |
---|
| 64 | |
---|
| 65 | boostPower = 15 |
---|
| 66 | boostPowerRate = 1 |
---|
| 67 | boostRate = 5 |
---|
| 68 | boostCooldownDuration = 10 |
---|
| 69 | |
---|
| 70 | shakeFrequency = 15 |
---|
| 71 | shakeAmplitude = 9 |
---|
| 72 | |
---|
| 73 | collisionType = "dynamic" |
---|
| 74 | mass = 100 |
---|
| 75 | linearDamping = 0.7 |
---|
| 76 | angularDamping = 0.9999999 |
---|
| 77 | > |
---|
| 78 | <engines> |
---|
| 79 | <Engine /> |
---|
| 80 | <Engine /> |
---|
| 81 | </engines> |
---|
| 82 | </SpaceShip> |
---|
| 83 | @endcode |
---|
| 84 | |
---|
| 85 | @author |
---|
| 86 | Fabian 'x3n' Landau |
---|
| 87 | */ |
---|
[2072] | 88 | class _OrxonoxExport SpaceShip : public Pawn |
---|
| 89 | { |
---|
| 90 | public: |
---|
[9667] | 91 | SpaceShip(Context* context); |
---|
[2072] | 92 | virtual ~SpaceShip(); |
---|
| 93 | |
---|
| 94 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
| 95 | virtual void tick(float dt); |
---|
| 96 | void setConfigValues(); |
---|
| 97 | |
---|
[8727] | 98 | /** |
---|
| 99 | @brief Move forward or backward, |
---|
| 100 | @param value A vector whose first component specifies the amount of movement. Positive means forward, negative means backward. |
---|
| 101 | */ |
---|
| 102 | virtual void moveFrontBack(const Vector2& value) |
---|
| 103 | { this->steering_.z -= value.x; } |
---|
| 104 | /** |
---|
| 105 | @brief Move right or left. |
---|
| 106 | @param value A vector whose first component specifies the amount of movement. Positive means right, negative means left. |
---|
| 107 | */ |
---|
| 108 | virtual void moveRightLeft(const Vector2& value) |
---|
| 109 | { this->steering_.x += value.x; } |
---|
| 110 | /** |
---|
| 111 | @brief Move up or down. |
---|
| 112 | @param value A vector whose first component specifies the amount of movement. Positive means up, negative means down. |
---|
| 113 | */ |
---|
| 114 | virtual void moveUpDown(const Vector2& value) |
---|
| 115 | { this->steering_.y += value.x; } |
---|
[2072] | 116 | |
---|
[8727] | 117 | virtual void rotateYaw(const Vector2& value); // Rotate in yaw direction. |
---|
| 118 | virtual void rotatePitch(const Vector2& value); // Rotate in pitch direction. |
---|
| 119 | virtual void rotateRoll(const Vector2& value); // Rotate in roll direction. |
---|
[2072] | 120 | |
---|
| 121 | virtual void fire(); |
---|
[8706] | 122 | virtual void boost(bool bBoost); // Starts or stops boosting. |
---|
[2072] | 123 | |
---|
[8727] | 124 | void addEngine(Engine* engine); // Add an Engine to the SpaceShip. |
---|
| 125 | bool hasEngine(Engine* engine) const; // Check whether the SpaceShip has a particular Engine. |
---|
| 126 | Engine* getEngine(unsigned int i); // Get the i-th Engine of the SpaceShip. |
---|
[10216] | 127 | Engine* getEngineByName(const std::string& name); |
---|
[8727] | 128 | /** |
---|
| 129 | @brief Get the list of all Engines that are mounted on the SpaceShip. |
---|
| 130 | @return Returns a vector of all Engines of the SpaceShip. |
---|
| 131 | */ |
---|
| 132 | inline const std::vector<Engine*>& getEngineList() const |
---|
[8706] | 133 | { return this->engineList_; } |
---|
[8727] | 134 | void removeEngine(Engine* engine); // Remove and destroy all Engines of the SpaceShip. |
---|
| 135 | void removeAllEngines(); // Remove a particular Engine from the SpaceShip. |
---|
[2072] | 136 | |
---|
[8727] | 137 | void addSpeedFactor(float factor); // Add to the speed factor for all engines of the SpaceShip. |
---|
| 138 | void addSpeed(float speed); // Add to the speed of all engines of the SpaceShip. |
---|
| 139 | float getSpeedFactor() const; // Get the mean speed factor over all engines of the SpaceShip. |
---|
| 140 | |
---|
| 141 | float getMaxSpeedFront() const; // Get the largest maximal forward speed over all engines of the SpaceShip. |
---|
| 142 | float getBoostFactor() const; // Get the mean boost factor over all engines of the SpaceShip. |
---|
[8706] | 143 | |
---|
[8727] | 144 | /** |
---|
| 145 | @brief Set the steering direction of the SpaceShip. |
---|
| 146 | This is set through the user input. |
---|
| 147 | @param direction The direction the SpaceShip should steer in. |
---|
| 148 | */ |
---|
[2662] | 149 | inline void setSteeringDirection(const Vector3& direction) |
---|
| 150 | { this->steering_ = direction; } |
---|
[8727] | 151 | /** |
---|
| 152 | @brief Get the steering direction of the SpaceShip. |
---|
| 153 | @return Returns the steering direction of the SpaceShip. The length of the vector is the amount of steering needed. |
---|
| 154 | */ |
---|
[2662] | 155 | inline const Vector3& getSteeringDirection() const |
---|
| 156 | { return this->steering_; } |
---|
[2072] | 157 | |
---|
[8727] | 158 | /** |
---|
| 159 | @brief Check whether the SpaceShip is currently boosting. |
---|
| 160 | @return Returns true if the SpaceShip is boosting, false if not. |
---|
| 161 | */ |
---|
| 162 | inline bool isBoosting() const |
---|
[2662] | 163 | { return this->bBoost_; } |
---|
[8727] | 164 | /** |
---|
| 165 | @brief Check whether the SpaceShip boost is cooling down. |
---|
| 166 | @return Returns true if the SpaceShip is cooling down from boosting. |
---|
| 167 | */ |
---|
| 168 | inline bool isBoostCoolingDown() const |
---|
| 169 | { return bBoostCooldown_; } |
---|
[2662] | 170 | |
---|
[8727] | 171 | /** |
---|
| 172 | @brief Set the initial power available for boosting to the input value. |
---|
| 173 | The current boost power is set to the input value as well. |
---|
| 174 | @param power The initial boost power. Must be non-negative. |
---|
| 175 | */ |
---|
| 176 | inline void setInitialBoostPower(float power) |
---|
| 177 | { OrxAssert(power >= 0.0f, "The boost power must be non-negative."); this->initialBoostPower_ = power; this->boostPower_ = power; } |
---|
| 178 | /** |
---|
| 179 | @brief Set the rate, at which boost power is recharged, to the input value. |
---|
| 180 | @param rate The boost power rate in units per second. Must be non-negative. |
---|
| 181 | */ |
---|
| 182 | inline void setBoostPowerRate(float rate) |
---|
| 183 | { OrxAssert(rate >= 0.0f, "The boost power rate must be non-negative."); this->boostPowerRate_ = rate; } |
---|
| 184 | /** |
---|
| 185 | @brief Set the rate, at which boost power us used up, to the input value. |
---|
| 186 | @param rate The boost rate in units per second. Must be non-negative. |
---|
| 187 | */ |
---|
| 188 | inline void setBoostRate(float rate) |
---|
| 189 | { OrxAssert(rate >= 0.0f, "The boost rate must be non-negative."); this->boostRate_ = rate; } |
---|
| 190 | /** |
---|
| 191 | @brief Set the duration for which boosting, if in cooldown, is not possible. |
---|
| 192 | Cooldown is reached if all boost power is depleted. |
---|
| 193 | @param duration The cooldown duration in seconds. Must be non-negative. |
---|
| 194 | */ |
---|
| 195 | inline void setBoostCooldownDuration(float duration) |
---|
| 196 | { OrxAssert(duration >= 0.0f, "The boost cooldown duration must be non-negative."); this->boostCooldownDuration_ = duration; } |
---|
| 197 | /** |
---|
| 198 | @brief Set the frequency with which the camera shakes during boosting. |
---|
| 199 | @param frequency The frequency in times per second. Must be non-negative. |
---|
| 200 | */ |
---|
| 201 | inline void setShakeFrequency(float frequency) |
---|
| 202 | { OrxAssert(frequency >= 0.0f, "The shake frequency must be non-negative."); this->shakeFrequency_ = frequency; } |
---|
| 203 | /** |
---|
| 204 | @brief Set the amplitude with which the camera shakes during boosting. |
---|
| 205 | @param amplitude The amplitude. Must be non-negative. |
---|
| 206 | */ |
---|
| 207 | inline void setShakeAmplitude(float amplitude) |
---|
| 208 | { OrxAssert(amplitude >= 0.0f, "The shake amplitude must be non-negative."); this->shakeAmplitude_ = amplitude; } |
---|
| 209 | |
---|
| 210 | /** |
---|
| 211 | @brief Get the initial boost power. Is non-negative. |
---|
| 212 | @return Returns the initial boost power. |
---|
| 213 | */ |
---|
| 214 | inline float getInitialBoostPower() const |
---|
| 215 | { return this->initialBoostPower_; } |
---|
| 216 | /** |
---|
| 217 | @brief Get the current boost power. Is non-negative. |
---|
| 218 | @return Returns the current boost power. |
---|
| 219 | */ |
---|
[8706] | 220 | inline float getBoostPower() const |
---|
| 221 | { return this->boostPower_; } |
---|
[8727] | 222 | /** |
---|
| 223 | @brief Get the boost power rate. |
---|
| 224 | @return Returns the boost power rate in units per second. Is non-negative. |
---|
| 225 | */ |
---|
| 226 | inline float getBoostPowerRate() const |
---|
| 227 | { return this->boostPowerRate_; } |
---|
| 228 | /** |
---|
| 229 | @brief Get the boost rate. |
---|
| 230 | @return Returns the boost rate in units per second. Is non-negative. |
---|
| 231 | */ |
---|
| 232 | inline float getBoostRate() const |
---|
| 233 | { return this->boostRate_; } |
---|
| 234 | /** |
---|
| 235 | @brief Get the cooldown duration. |
---|
| 236 | @return Returns the cooldown duration in seconds. Is non-negative. |
---|
| 237 | */ |
---|
| 238 | inline float getBoostCooldownDuration() const |
---|
| 239 | { return this->boostCooldownDuration_; } |
---|
| 240 | /** |
---|
| 241 | @brief Get the shake frequency. |
---|
| 242 | @return Returns the shake frequency in times per seconds. Is non-negative. |
---|
| 243 | */ |
---|
| 244 | inline float getShakeFrequency() const |
---|
| 245 | { return this->shakeFrequency_; } |
---|
| 246 | /** |
---|
| 247 | @brief Get the shake amplitude. |
---|
| 248 | @return Returns the shake amplitude. Is non-negative. |
---|
| 249 | */ |
---|
| 250 | inline float getShakeAmplitude() const |
---|
| 251 | { return this->shakeAmplitude_; } |
---|
[2662] | 252 | |
---|
[2072] | 253 | protected: |
---|
| 254 | bool bInvertYAxis_; |
---|
| 255 | |
---|
[8727] | 256 | Vector3 steering_; //!< The direction and magnitude of the steering action given through user input. |
---|
[2072] | 257 | |
---|
[8727] | 258 | float rotationThrust_; //!< Force with which the SpaceShip rotates. |
---|
| 259 | btVector3 localAngularAcceleration_; //!< The acceleration that accounts for angular movement and is used internally. |
---|
[8706] | 260 | |
---|
[8727] | 261 | bool bBoost_; //!< Whether the SpaceShip is currently boosting. |
---|
| 262 | bool bBoostCooldown_; //!< Whether the SpaceShip is currently in boost cooldown, during which boosting is impossible. |
---|
| 263 | float initialBoostPower_; //!< The initial (and maximal) boost power. |
---|
| 264 | float boostPower_; //!< The current boost power. |
---|
| 265 | float boostPowerRate_; //!< The rate at which the boost power is recharged. |
---|
| 266 | float boostRate_; //!< The rate at which boost power is used up. |
---|
| 267 | float boostCooldownDuration_; //!< The duration for which boost cooldown is in effect. |
---|
| 268 | float shakeFrequency_; //!< The frequency of the shaking of the camera due to boosting. |
---|
| 269 | float shakeAmplitude_; //!< The amplitude of the shaking of the camera due to boosting. |
---|
| 270 | |
---|
| 271 | float lift_; //!< The amount of lift that is added. |
---|
| 272 | float stallSpeed_; //!< The forward speed where no more lift is added. |
---|
| 273 | |
---|
[2662] | 274 | private: |
---|
[7163] | 275 | void registerVariables(); |
---|
[2662] | 276 | virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; |
---|
| 277 | |
---|
[8727] | 278 | void changedEnableMotionBlur(); // Is called when the enableMotionBlur config value has changed. |
---|
| 279 | /** |
---|
| 280 | @brief Callback function. Is called when the boost has cooled down. |
---|
| 281 | */ |
---|
| 282 | void boostCooledDown(void) |
---|
| 283 | { this->bBoostCooldown_ = false; } |
---|
[8706] | 284 | |
---|
[8727] | 285 | void shakeCamera(float dt); // Shake the camera for a given time interval. |
---|
| 286 | void backupCamera(); // Save the original position and orientation of the camera. |
---|
| 287 | void resetCamera(); // Reset the camera to its original position. |
---|
| 288 | |
---|
| 289 | std::vector<Engine*> engineList_; //!< The list of all Engines mounted on this SpaceShip. |
---|
| 290 | |
---|
| 291 | Timer timer_; //!< Timer for the cooldown duration. |
---|
| 292 | float shakeDt_; //!< Temporary variable for the shaking of the camera. |
---|
| 293 | Vector3 cameraOriginalPosition_; //!< The original position of the camera before shaking it. |
---|
| 294 | Quaternion cameraOriginalOrientation_; //!< The original orientation of the camera before shaking it. |
---|
| 295 | |
---|
| 296 | Shader* boostBlur_; //!< A radial blur shader, applied when boosting according to the amount of boosting. |
---|
| 297 | float blurStrength_; //!< The strength of the applied blur. |
---|
| 298 | bool bEnableMotionBlur_; //!< Whether motion blur is enabled or not. |
---|
[8706] | 299 | |
---|
[2072] | 300 | }; |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | #endif /* _SpaceShip_H__ */ |
---|