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