[7346] | 1 | /*! |
---|
| 2 | * @file space_ship.h |
---|
| 3 | * Implements the Control of a Spaceship |
---|
[10368] | 4 | * Space Ships are the core class for all types of ships in Orxonox |
---|
| 5 | * By default is on OM_GROUP_00 |
---|
| 6 | * If player boards the ship, it is moved to OM_GROUP_01 |
---|
[7346] | 7 | */ |
---|
| 8 | |
---|
| 9 | #ifndef _SPACE_SHIP_H |
---|
| 10 | #define _SPACE_SHIP_H |
---|
| 11 | |
---|
| 12 | #include "playable.h" |
---|
| 13 | #include "extendable.h" |
---|
| 14 | |
---|
| 15 | // Forward Declaration |
---|
| 16 | template<class T> class tList; |
---|
| 17 | class Vector; |
---|
| 18 | class Event; |
---|
| 19 | class ParticleEmitter; |
---|
| 20 | class ParticleSystem; |
---|
[10368] | 21 | class Trail; |
---|
| 22 | class Wobblegrid; |
---|
[7346] | 23 | |
---|
| 24 | class SpaceShip : public Playable |
---|
| 25 | { |
---|
[9869] | 26 | ObjectListDeclaration(SpaceShip); |
---|
[7346] | 27 | |
---|
| 28 | public: |
---|
| 29 | SpaceShip(const std::string& fileName); |
---|
| 30 | SpaceShip(const TiXmlElement* root = NULL); |
---|
| 31 | virtual ~SpaceShip(); |
---|
| 32 | |
---|
| 33 | virtual void loadParams(const TiXmlElement* root); |
---|
| 34 | |
---|
| 35 | virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f); |
---|
[10368] | 36 | /* |
---|
| 37 | void setTravelHeight(float travelHeight); |
---|
| 38 | void setTravelDistance(const Vector2D& distance); |
---|
| 39 | void setTravelDistance(float x, float y); |
---|
| 40 | */ |
---|
[7346] | 41 | |
---|
[10368] | 42 | //void setAirFriction(float friction) { this->airFriction = friction; }; |
---|
| 43 | |
---|
[7346] | 44 | virtual void enter(); |
---|
| 45 | virtual void leave(); |
---|
| 46 | |
---|
| 47 | virtual void reset(); |
---|
| 48 | |
---|
| 49 | virtual void postSpawn(); |
---|
| 50 | virtual void leftWorld(); |
---|
[9869] | 51 | |
---|
[9235] | 52 | virtual void destroy(WorldEntity* killer); |
---|
[9008] | 53 | virtual void respawn(); |
---|
[7346] | 54 | |
---|
[10368] | 55 | inline Vector getVelocity() { return this->velocity; }; |
---|
| 56 | |
---|
[7346] | 57 | virtual void tick(float time); |
---|
| 58 | virtual void draw() const; |
---|
| 59 | |
---|
| 60 | virtual void process(const Event &event); |
---|
[10368] | 61 | // virtual void hit (WorldEntity* entity, float damage); |
---|
[7346] | 62 | |
---|
[10368] | 63 | inline WeaponManager& getWeaponManagerSecondary() { return this->secWeaponMan; }; |
---|
| 64 | |
---|
[10659] | 65 | inline void setReactor(float output) {this->reactorOutput = output; }; |
---|
| 66 | inline void setShield(float cur, float max, float th, float regen) |
---|
| 67 | { this->shieldCur = cur; this->shieldMax = max; this->shieldTH = th; this->shieldRegen = regen;}; |
---|
| 68 | inline void setArmor(float cur, float max) { this->armorCur = cur; this->armorMax = max; updateHealth(); }; |
---|
| 69 | inline void setElectronic(float cur, float max, float th, float regen) |
---|
| 70 | { this->electronicCur = cur; this->electronicMax = max; this->electronicTH = th; this->electronicRegen = regen; }; |
---|
| 71 | inline void setEngine( float speedBase) {this->engineSpeedBase = speedBase; }; |
---|
| 72 | inline void setEnergyShare(float shield, float weapon, float engine) |
---|
| 73 | { float tmp = shield + weapon + engine; if (unlikely (tmp > 1)) { tmp = 1/tmp; } |
---|
| 74 | // dirty safty hack, prevents total share being bigger than 1!! |
---|
| 75 | this->shieldEnergyShare = shield * tmp; |
---|
| 76 | this->weaponEnergyShare = weapon * tmp; |
---|
| 77 | this->engineEnergyShare = engine * tmp; }; |
---|
| 78 | inline void setWeapon(float regen) { this->weaponEnergyRegen = regen; }; |
---|
| 79 | |
---|
| 80 | //!< Resynchonizes armor with health in WE!! |
---|
| 81 | inline void updateHealth() { this->setHealth(this->armorCur); this->setHealthMax(this->armorMax); }; |
---|
| 82 | |
---|
[10368] | 83 | //Functions for GUI |
---|
| 84 | inline float getShieldCur() { return this->shieldCur; }; //!< returns current shield value |
---|
| 85 | inline float getShieldMax() { return this->shieldMax; }; //!< returns maximum shield value |
---|
| 86 | |
---|
| 87 | inline float getArmorCur() { return this->armorCur; }; //!< returns current armor value |
---|
| 88 | inline float getArmorMax() { return this->armorMax; }; //!< returns current armor value |
---|
| 89 | |
---|
| 90 | inline float getElectronicCur() { return this->electronicCur; }; //!< returns current electronic value |
---|
| 91 | inline float getElectronicMax() { return this->electronicMax; }; //!< returns current electronic value |
---|
| 92 | |
---|
| 93 | inline PNode* getTravelNode() { return this->travelNode; }; |
---|
| 94 | |
---|
| 95 | //damage handler |
---|
| 96 | virtual void damage(float pDamage, float eDamage); //!< pDamage physical damage, eDamage electronic damage |
---|
| 97 | |
---|
| 98 | //included by Michel: |
---|
| 99 | virtual void enterPlaymode(Playable::Playmode playmode); |
---|
| 100 | void setPlaymodeXML(const std::string& playmode); //recieves the playmode from a string (useful for script implementation) |
---|
| 101 | void setActionWidthPercentage(int i); |
---|
[10516] | 102 | void setTravelSpeed(float f); |
---|
[10368] | 103 | void updateTravelDistance(); |
---|
| 104 | virtual void movement (float dt); |
---|
| 105 | |
---|
| 106 | |
---|
[10659] | 107 | |
---|
[10368] | 108 | void nextWeaponConfig(); |
---|
| 109 | void previousWeaponConfig(); |
---|
| 110 | |
---|
| 111 | virtual void hit(float damage, WorldEntity* killer); |
---|
[10659] | 112 | |
---|
[10531] | 113 | void setCameraDistance(float dist); |
---|
[10368] | 114 | |
---|
[7346] | 115 | private: |
---|
| 116 | void init(); |
---|
| 117 | |
---|
[10368] | 118 | //void calculateVelocity(float time); |
---|
[7346] | 119 | |
---|
[10368] | 120 | void regen(float time); //!< handler for shield and electronic regeneration |
---|
| 121 | |
---|
| 122 | void weaponRegen(float time); //!< weapon energy regeneration |
---|
| 123 | |
---|
| 124 | inline bool systemFailure() { return (this->electronicCur < float(rand())/float(RAND_MAX) * this->electronicTH); }; |
---|
| 125 | |
---|
| 126 | void updateElectronicWidget(); |
---|
| 127 | void updateShieldWidget(); |
---|
| 128 | |
---|
| 129 | //WeaponManager weaponMan; //!< the primary weapon manager: managing a list of energy weapons to wepaon-slot mapping |
---|
| 130 | WeaponManager secWeaponMan; //!< the secondary weapon manager: managing a list of special weapons to weapon-slot mapping |
---|
| 131 | short supportedPlaymodes; //!< What Playmodes are Supported in this Playable. |
---|
| 132 | Playable::Playmode playmode; //!< The current playmode. |
---|
| 133 | |
---|
| 134 | //ship atributes |
---|
| 135 | float shieldCur; //!< current shield |
---|
| 136 | float shieldMax; //!< maximum shield |
---|
| 137 | float shieldEnergyShare; //!< percentage of reactor output |
---|
| 138 | float shieldRegen; //!< shield regeneration rate per second |
---|
| 139 | float shieldTH; //!< shield threshhold for reactivation |
---|
| 140 | bool shieldActive; //!< wheather the shield is working |
---|
| 141 | OrxGui::GLGuiEnergyWidgetVertical* shieldWidget; //!< holds the widget that shows the shield bar |
---|
| 142 | |
---|
| 143 | float armorCur; //!< current armor |
---|
| 144 | float armorMax; //!< maximum armor |
---|
| 145 | float armorRegen; //!< armor regeneration per tick (usable on bioships?) |
---|
| 146 | //note that the armor widget is set on the health- widget in world- entity (see in player.cc) |
---|
| 147 | |
---|
| 148 | float electronicCur; //!< current electronic |
---|
| 149 | float electronicMax; //!< maximum electronic |
---|
| 150 | float electronicRegen; //!< electronic regenration rate per tick |
---|
| 151 | float electronicTH; //!< Threshhold for electronic failure |
---|
| 152 | OrxGui::GLGuiEnergyWidgetVertical* electronicWidget; //!< holds the widget that shows the electronic bar |
---|
| 153 | |
---|
| 154 | float engineSpeedCur; //!< speed output for movement = speed base + energy share part |
---|
| 155 | float engineSpeedBase; //!< speed base |
---|
| 156 | int enginePowerConsume; //!< energy needed |
---|
| 157 | float engineEnergyShare; //!< percentage of reactor output |
---|
| 158 | |
---|
| 159 | int weaponEnergySlot; //!< number of energy weapon slots |
---|
| 160 | int weaponEnergyUsed; |
---|
| 161 | float weaponEnergyShare; |
---|
| 162 | float weaponEnergyRegen; |
---|
| 163 | int weaponSpecialSlot; //!< number of special weapon slots |
---|
| 164 | int weaponSpecialUsed; |
---|
| 165 | |
---|
| 166 | float reactorOutput; //!< reactor output |
---|
[10659] | 167 | // float reactorCapacity; //!< reactor capacity |
---|
[10368] | 168 | |
---|
| 169 | int curWeaponPrimary; //!< current primary weapon config |
---|
| 170 | int curWeaponSecondary; //!< current secondary weapon config |
---|
| 171 | |
---|
| 172 | bool bForward; //!< up button pressed. |
---|
| 173 | bool bBackward; //!< down button pressed. |
---|
[7346] | 174 | bool bLeft; //!< left button pressed. |
---|
| 175 | bool bRight; //!< right button pressed. |
---|
| 176 | bool bAscend; //!< ascend button pressed. |
---|
| 177 | bool bDescend; //!< descend button presses. |
---|
| 178 | bool bRollL; //!< rolling button pressed (left) |
---|
| 179 | bool bRollR; //!< rolling button pressed (right) |
---|
[10368] | 180 | bool bSecFire; //!< second fire button pressed |
---|
[7346] | 181 | |
---|
[10368] | 182 | /* |
---|
[7346] | 183 | float xMouse; //!< mouse moved in x-Direction |
---|
| 184 | float yMouse; //!< mouse moved in y-Direction |
---|
| 185 | float mouseSensitivity; //!< the mouse sensitivity |
---|
| 186 | int yInvert; |
---|
| 187 | int controlVelocityX; |
---|
| 188 | int controlVelocityY; |
---|
[10368] | 189 | */ |
---|
[7346] | 190 | |
---|
| 191 | Vector velocity; //!< the velocity of the player. |
---|
[10368] | 192 | Vector oldPos; |
---|
| 193 | |
---|
| 194 | // 2D-traveling |
---|
| 195 | PNode* travelNode; |
---|
| 196 | float travelSpeed; //!< the current speed of the Ship (to make soft movement) |
---|
| 197 | Vector travelVelocity; //!< object internal velocity vector for relative movement to the track node |
---|
| 198 | Vector2D travelDistancePlus; //!< Travel-Distance away from the TravelNode |
---|
| 199 | Vector2D travelDistanceMinus; |
---|
| 200 | bool isTravelDistanceInit; |
---|
| 201 | |
---|
| 202 | float actionWidthPercentage; |
---|
| 203 | |
---|
| 204 | // Camera |
---|
| 205 | PNode cameraNode; |
---|
| 206 | float cameraLook; |
---|
| 207 | float rotation; |
---|
| 208 | float cameraSpeed; |
---|
| 209 | |
---|
[10531] | 210 | |
---|
[10368] | 211 | void setCameraFovy(float fovy); |
---|
| 212 | |
---|
| 213 | /* |
---|
[7346] | 214 | Quaternion mouseDir; //!< the direction where the player wants to fly |
---|
| 215 | Quaternion oldMouseDir; //!< the direction where the player wanted to fly |
---|
| 216 | float shipInertia; //!< the inertia of the ship(how fast the ship reacts to a mouse input) |
---|
| 217 | Quaternion rotQuat; |
---|
| 218 | Quaternion pitchDir; |
---|
[10368] | 219 | float dogdeSpeed; //!< the dogde Speed of the ship. |
---|
| 220 | */ |
---|
[7346] | 221 | |
---|
[10368] | 222 | //Quaternion direction; //!< the direction of the ship. |
---|
| 223 | float acceleration; //!< the acceleration of the ship. |
---|
| 224 | //float airFriction; //!< AirFriction. |
---|
| 225 | //float airViscosity; |
---|
[7346] | 226 | |
---|
| 227 | byte oldMask; //!< used for synchronisation |
---|
[10659] | 228 | /* |
---|
[10368] | 229 | Trail* trail; //!< Burst trail |
---|
| 230 | Trail* trailL; //!< Burst trail |
---|
| 231 | Trail* trailR; //!< Burst trail |
---|
[10659] | 232 | */ |
---|
[10368] | 233 | |
---|
[7346] | 234 | }; |
---|
| 235 | |
---|
| 236 | #endif /* _SPACE_SHIPS_H */ |
---|