Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/world_entities/space_ships/space_ship.h @ 10661

Last change on this file since 10661 was 10661, checked in by nicolasc, 17 years ago

modular weapons inclusion

File size: 10.6 KB
Line 
1/*!
2 * @file space_ship.h
3 * Implements the Control of a Spaceship
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
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
16template<class T> class tList;
17class Vector;
18class Event;
19class ParticleEmitter;
20class ParticleSystem;
21class Trail;
22class Wobblegrid;
23
24class SpaceShip : public Playable
25{
26  ObjectListDeclaration(SpaceShip);
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);
36    /*
37    void setTravelHeight(float travelHeight);
38    void setTravelDistance(const Vector2D& distance);
39    void setTravelDistance(float x, float y);
40    */
41
42    //void setAirFriction(float friction) { this->airFriction = friction; };
43
44    virtual void enter();
45    virtual void leave();
46
47    virtual void reset();
48
49    virtual void postSpawn();
50    virtual void leftWorld();
51
52    virtual void destroy(WorldEntity* killer);
53    virtual void respawn();
54
55    inline Vector getVelocity() { return this->velocity; };
56
57    virtual void tick(float time);
58    virtual void draw() const;
59
60    virtual void process(const Event &event);
61//    virtual void hit (WorldEntity* entity, float damage);
62
63    inline WeaponManager& getWeaponManagerSecondary() { return this->secWeaponMan; };
64
65    //!< functions for XML loading
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; }
75          // dirty safety hack, prevents total share being bigger than 1!!
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
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
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);
118    void setTravelSpeed(float f);
119    void updateTravelDistance();
120    virtual void movement (float dt);
121
122
123
124    void nextWeaponConfig();
125    void previousWeaponConfig();
126
127    virtual void hit(float damage, WorldEntity* killer);
128
129    void                  setCameraDistance(float dist);
130
131  private:
132    void init();
133
134    //void calculateVelocity(float time);
135
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
183//    float       reactorCapacity;    //!< reactor capacity
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.
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)
196    bool                  bSecFire;           //!< second fire button pressed
197
198    /*
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;
205    */
206
207    Vector                velocity;           //!< the velocity of the player.
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
226
227    void                  setCameraFovy(float fovy);
228
229    /*
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;
235    float                 dogdeSpeed;        //!< the dogde Speed of the ship.
236    */
237
238    //Quaternion            direction;          //!< the direction of the ship.
239    float                 acceleration;       //!< the acceleration of the ship.
240    //float                 airFriction;        //!< AirFriction.
241    //float                 airViscosity;
242
243    byte                  oldMask;            //!< used for synchronisation
244/*
245    Trail*                trail;              //!< Burst trail
246    Trail*                trailL;              //!< Burst trail
247    Trail*                trailR;              //!< Burst trail
248*/
249
250};
251
252#endif /* _SPACE_SHIPS_H */
Note: See TracBrowser for help on using the repository browser.