[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 | |
---|
[10660] | 65 | //!< functions for XML loading |
---|
[10659] | 66 | inline void setReactor(float output) {this->reactorOutput = output; }; |
---|
| 67 | inline void setShield(float cur, float max, float th, float regen) |
---|
| 68 | { this->shieldCur = cur; this->shieldMax = max; this->shieldTH = th; this->shieldRegen = regen;}; |
---|
| 69 | inline void setArmor(float cur, float max) { this->armorCur = cur; this->armorMax = max; updateHealth(); }; |
---|
| 70 | inline void setElectronic(float cur, float max, float th, float regen) |
---|
| 71 | { this->electronicCur = cur; this->electronicMax = max; this->electronicTH = th; this->electronicRegen = regen; }; |
---|
| 72 | inline void setEngine( float speedBase) {this->engineSpeedBase = speedBase; }; |
---|
| 73 | inline void setEnergyShare(float shield, float weapon, float engine) |
---|
| 74 | { float tmp = shield + weapon + engine; if (unlikely (tmp > 1)) { tmp = 1/tmp; } |
---|
[10661] | 75 | // dirty safety hack, prevents total share being bigger than 1!! |
---|
[10659] | 76 | this->shieldEnergyShare = shield * tmp; |
---|
| 77 | this->weaponEnergyShare = weapon * tmp; |
---|
| 78 | this->engineEnergyShare = engine * tmp; }; |
---|
| 79 | inline void setWeapon(float regen) { this->weaponEnergyRegen = regen; }; |
---|
| 80 | |
---|
| 81 | //!< Resynchonizes armor with health in WE!! |
---|
| 82 | inline void updateHealth() { this->setHealth(this->armorCur); this->setHealthMax(this->armorMax); }; |
---|
| 83 | |
---|
[10661] | 84 | inline void setWMSlotCount(int wm, int slot) { |
---|
| 85 | if (wm == 1) { this->weaponMan.setSlotCount(slot); } |
---|
| 86 | if (wm == 2) { this->secWeaponMan.setSlotCount(slot); } |
---|
| 87 | else return; }; |
---|
| 88 | inline void createWeaponSlot(int wm, int slot, Vector location, long capability) { |
---|
| 89 | if (wm == 1) { |
---|
| 90 | this->weaponMan.setSlotPosition(slot, location); |
---|
| 91 | this->weaponMan.setSlotCapability(slot, capability); } |
---|
| 92 | if (wm == 2) { |
---|
| 93 | this->secWeaponMan.setSlotPosition(slot, location); |
---|
| 94 | this->secWeaponMan.setSlotCapability(slot, capability); } |
---|
| 95 | else return; }; |
---|
| 96 | |
---|
| 97 | void addWeaponToSlot(int wm, int config, int slot, const std::string& weaponName); |
---|
| 98 | |
---|
[10368] | 99 | //Functions for GUI |
---|
| 100 | inline float getShieldCur() { return this->shieldCur; }; //!< returns current shield value |
---|
| 101 | inline float getShieldMax() { return this->shieldMax; }; //!< returns maximum shield value |
---|
| 102 | |
---|
| 103 | inline float getArmorCur() { return this->armorCur; }; //!< returns current armor value |
---|
| 104 | inline float getArmorMax() { return this->armorMax; }; //!< returns current armor value |
---|
| 105 | |
---|
| 106 | inline float getElectronicCur() { return this->electronicCur; }; //!< returns current electronic value |
---|
| 107 | inline float getElectronicMax() { return this->electronicMax; }; //!< returns current electronic value |
---|
| 108 | |
---|
| 109 | inline PNode* getTravelNode() { return this->travelNode; }; |
---|
| 110 | |
---|
| 111 | //damage handler |
---|
| 112 | virtual void damage(float pDamage, float eDamage); //!< pDamage physical damage, eDamage electronic damage |
---|
| 113 | |
---|
| 114 | //included by Michel: |
---|
| 115 | virtual void enterPlaymode(Playable::Playmode playmode); |
---|
| 116 | void setPlaymodeXML(const std::string& playmode); //recieves the playmode from a string (useful for script implementation) |
---|
| 117 | void setActionWidthPercentage(int i); |
---|
[10516] | 118 | void setTravelSpeed(float f); |
---|
[10368] | 119 | void updateTravelDistance(); |
---|
| 120 | virtual void movement (float dt); |
---|
| 121 | |
---|
| 122 | |
---|
[10659] | 123 | |
---|
[10368] | 124 | void nextWeaponConfig(); |
---|
| 125 | void previousWeaponConfig(); |
---|
| 126 | |
---|
| 127 | virtual void hit(float damage, WorldEntity* killer); |
---|
[10659] | 128 | |
---|
[10531] | 129 | void setCameraDistance(float dist); |
---|
[10368] | 130 | |
---|
[7346] | 131 | private: |
---|
| 132 | void init(); |
---|
| 133 | |
---|
[10368] | 134 | //void calculateVelocity(float time); |
---|
[7346] | 135 | |
---|
[10368] | 136 | void regen(float time); //!< handler for shield and electronic regeneration |
---|
| 137 | |
---|
| 138 | void weaponRegen(float time); //!< weapon energy regeneration |
---|
| 139 | |
---|
| 140 | inline bool systemFailure() { return (this->electronicCur < float(rand())/float(RAND_MAX) * this->electronicTH); }; |
---|
| 141 | |
---|
| 142 | void updateElectronicWidget(); |
---|
| 143 | void updateShieldWidget(); |
---|
| 144 | |
---|
| 145 | //WeaponManager weaponMan; //!< the primary weapon manager: managing a list of energy weapons to wepaon-slot mapping |
---|
| 146 | WeaponManager secWeaponMan; //!< the secondary weapon manager: managing a list of special weapons to weapon-slot mapping |
---|
| 147 | short supportedPlaymodes; //!< What Playmodes are Supported in this Playable. |
---|
| 148 | Playable::Playmode playmode; //!< The current playmode. |
---|
| 149 | |
---|
| 150 | //ship atributes |
---|
| 151 | float shieldCur; //!< current shield |
---|
| 152 | float shieldMax; //!< maximum shield |
---|
| 153 | float shieldEnergyShare; //!< percentage of reactor output |
---|
| 154 | float shieldRegen; //!< shield regeneration rate per second |
---|
| 155 | float shieldTH; //!< shield threshhold for reactivation |
---|
| 156 | bool shieldActive; //!< wheather the shield is working |
---|
| 157 | OrxGui::GLGuiEnergyWidgetVertical* shieldWidget; //!< holds the widget that shows the shield bar |
---|
| 158 | |
---|
| 159 | float armorCur; //!< current armor |
---|
| 160 | float armorMax; //!< maximum armor |
---|
| 161 | float armorRegen; //!< armor regeneration per tick (usable on bioships?) |
---|
| 162 | //note that the armor widget is set on the health- widget in world- entity (see in player.cc) |
---|
| 163 | |
---|
| 164 | float electronicCur; //!< current electronic |
---|
| 165 | float electronicMax; //!< maximum electronic |
---|
| 166 | float electronicRegen; //!< electronic regenration rate per tick |
---|
| 167 | float electronicTH; //!< Threshhold for electronic failure |
---|
| 168 | OrxGui::GLGuiEnergyWidgetVertical* electronicWidget; //!< holds the widget that shows the electronic bar |
---|
| 169 | |
---|
| 170 | float engineSpeedCur; //!< speed output for movement = speed base + energy share part |
---|
| 171 | float engineSpeedBase; //!< speed base |
---|
| 172 | int enginePowerConsume; //!< energy needed |
---|
| 173 | float engineEnergyShare; //!< percentage of reactor output |
---|
| 174 | |
---|
| 175 | int weaponEnergySlot; //!< number of energy weapon slots |
---|
| 176 | int weaponEnergyUsed; |
---|
| 177 | float weaponEnergyShare; |
---|
| 178 | float weaponEnergyRegen; |
---|
| 179 | int weaponSpecialSlot; //!< number of special weapon slots |
---|
| 180 | int weaponSpecialUsed; |
---|
| 181 | |
---|
| 182 | float reactorOutput; //!< reactor output |
---|
[10659] | 183 | // float reactorCapacity; //!< reactor capacity |
---|
[10368] | 184 | |
---|
| 185 | int curWeaponPrimary; //!< current primary weapon config |
---|
| 186 | int curWeaponSecondary; //!< current secondary weapon config |
---|
| 187 | |
---|
| 188 | bool bForward; //!< up button pressed. |
---|
| 189 | bool bBackward; //!< down button pressed. |
---|
[7346] | 190 | bool bLeft; //!< left button pressed. |
---|
| 191 | bool bRight; //!< right button pressed. |
---|
| 192 | bool bAscend; //!< ascend button pressed. |
---|
| 193 | bool bDescend; //!< descend button presses. |
---|
| 194 | bool bRollL; //!< rolling button pressed (left) |
---|
| 195 | bool bRollR; //!< rolling button pressed (right) |
---|
[10368] | 196 | bool bSecFire; //!< second fire button pressed |
---|
[7346] | 197 | |
---|
[10368] | 198 | /* |
---|
[7346] | 199 | float xMouse; //!< mouse moved in x-Direction |
---|
| 200 | float yMouse; //!< mouse moved in y-Direction |
---|
| 201 | float mouseSensitivity; //!< the mouse sensitivity |
---|
| 202 | int yInvert; |
---|
| 203 | int controlVelocityX; |
---|
| 204 | int controlVelocityY; |
---|
[10368] | 205 | */ |
---|
[7346] | 206 | |
---|
| 207 | Vector velocity; //!< the velocity of the player. |
---|
[10368] | 208 | Vector oldPos; |
---|
| 209 | |
---|
| 210 | // 2D-traveling |
---|
| 211 | PNode* travelNode; |
---|
| 212 | float travelSpeed; //!< the current speed of the Ship (to make soft movement) |
---|
| 213 | Vector travelVelocity; //!< object internal velocity vector for relative movement to the track node |
---|
| 214 | Vector2D travelDistancePlus; //!< Travel-Distance away from the TravelNode |
---|
| 215 | Vector2D travelDistanceMinus; |
---|
| 216 | bool isTravelDistanceInit; |
---|
| 217 | |
---|
| 218 | float actionWidthPercentage; |
---|
| 219 | |
---|
| 220 | // Camera |
---|
| 221 | PNode cameraNode; |
---|
| 222 | float cameraLook; |
---|
| 223 | float rotation; |
---|
| 224 | float cameraSpeed; |
---|
| 225 | |
---|
[10531] | 226 | |
---|
[10368] | 227 | void setCameraFovy(float fovy); |
---|
| 228 | |
---|
| 229 | /* |
---|
[7346] | 230 | Quaternion mouseDir; //!< the direction where the player wants to fly |
---|
| 231 | Quaternion oldMouseDir; //!< the direction where the player wanted to fly |
---|
| 232 | float shipInertia; //!< the inertia of the ship(how fast the ship reacts to a mouse input) |
---|
| 233 | Quaternion rotQuat; |
---|
| 234 | Quaternion pitchDir; |
---|
[10368] | 235 | float dogdeSpeed; //!< the dogde Speed of the ship. |
---|
| 236 | */ |
---|
[7346] | 237 | |
---|
[10368] | 238 | //Quaternion direction; //!< the direction of the ship. |
---|
| 239 | float acceleration; //!< the acceleration of the ship. |
---|
| 240 | //float airFriction; //!< AirFriction. |
---|
| 241 | //float airViscosity; |
---|
[7346] | 242 | |
---|
| 243 | byte oldMask; //!< used for synchronisation |
---|
[10659] | 244 | /* |
---|
[10368] | 245 | Trail* trail; //!< Burst trail |
---|
| 246 | Trail* trailL; //!< Burst trail |
---|
| 247 | Trail* trailR; //!< Burst trail |
---|
[10659] | 248 | */ |
---|
[10368] | 249 | |
---|
[7346] | 250 | }; |
---|
| 251 | |
---|
| 252 | #endif /* _SPACE_SHIPS_H */ |
---|