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 _Pawn_H__ |
---|
30 | #define _Pawn_H__ |
---|
31 | |
---|
32 | #include "OrxonoxPrereqs.h" |
---|
33 | |
---|
34 | #include <string> |
---|
35 | #include <vector> |
---|
36 | #include "interfaces/PickupCarrier.h" |
---|
37 | #include "interfaces/RadarViewable.h" |
---|
38 | #include "worldentities/ControllableEntity.h" |
---|
39 | #include "worldentities/ExplosionPart.h" |
---|
40 | |
---|
41 | |
---|
42 | namespace orxonox // tolua_export |
---|
43 | { |
---|
44 | /** |
---|
45 | @brief |
---|
46 | Everything in Orxonox that has a health attribute is a Pawn. After a Pawn is spawned its health is set to |
---|
47 | its initial health. In every call of the Pawns tick function the game checks whether the pawns health is at |
---|
48 | or below zero. If it is, the pawn gets killed. |
---|
49 | |
---|
50 | Pawns can carry pickups and fire weapons. They can also have shields. |
---|
51 | |
---|
52 | Notice that every Pawn is a ControllableEntity. |
---|
53 | */ |
---|
54 | |
---|
55 | // tolua_export |
---|
56 | class _OrxonoxExport Pawn // tolua_export |
---|
57 | : public ControllableEntity, public RadarViewable, public PickupCarrier |
---|
58 | { // tolua_export |
---|
59 | friend class WeaponSystem; |
---|
60 | |
---|
61 | public: |
---|
62 | Pawn(Context* context); |
---|
63 | virtual ~Pawn(); |
---|
64 | |
---|
65 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
66 | virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); |
---|
67 | virtual void tick(float dt); |
---|
68 | |
---|
69 | inline bool isAlive() const |
---|
70 | { return this->bAlive_; } |
---|
71 | |
---|
72 | |
---|
73 | virtual void setHealth(float health); |
---|
74 | inline void addHealth(float health) |
---|
75 | { this->setHealth(this->health_ + health); } |
---|
76 | inline void removeHealth(float health) |
---|
77 | { this->setHealth(this->health_ - health); } |
---|
78 | inline float getHealth() const |
---|
79 | { return this->health_; } |
---|
80 | |
---|
81 | inline void setMaxHealth(float maxhealth) |
---|
82 | { this->maxHealth_ = maxhealth; this->setHealth(this->health_); } |
---|
83 | inline float getMaxHealth() const |
---|
84 | { return this->maxHealth_; } |
---|
85 | |
---|
86 | inline void setInitialHealth(float initialhealth) |
---|
87 | { this->initialHealth_ = initialhealth; this->setHealth(initialhealth); } |
---|
88 | inline float getInitialHealth() const |
---|
89 | { return this->initialHealth_; } |
---|
90 | |
---|
91 | virtual void setShieldHealth(float shieldHealth); |
---|
92 | |
---|
93 | inline float getShieldHealth() |
---|
94 | { return this->shieldHealth_; } |
---|
95 | |
---|
96 | inline void addShieldHealth(float amount) |
---|
97 | { this->setShieldHealth(this->shieldHealth_ + amount); } |
---|
98 | |
---|
99 | inline bool hasShield() |
---|
100 | { return (this->getShieldHealth() > 0); } |
---|
101 | |
---|
102 | virtual void setMaxShieldHealth(float maxshieldhealth); |
---|
103 | inline float getMaxShieldHealth() const |
---|
104 | { return this->maxShieldHealth_; } |
---|
105 | |
---|
106 | inline void setInitialShieldHealth(float initialshieldhealth) |
---|
107 | { this->initialShieldHealth_ = initialshieldhealth; this->setShieldHealth(initialshieldhealth); } |
---|
108 | inline float getInitialShieldHealth() const |
---|
109 | { return this->initialShieldHealth_; } |
---|
110 | |
---|
111 | inline void restoreInitialShieldHealth() |
---|
112 | { this->setShieldHealth(this->initialShieldHealth_); } |
---|
113 | inline void restoreMaxShieldHealth() |
---|
114 | { this->setShieldHealth(this->maxShieldHealth_); } |
---|
115 | |
---|
116 | inline void setShieldAbsorption(float shieldAbsorption) |
---|
117 | { this->shieldAbsorption_ = shieldAbsorption; } |
---|
118 | inline float getShieldAbsorption() |
---|
119 | { return this->shieldAbsorption_; } |
---|
120 | |
---|
121 | virtual void setShieldRechargeRate(float shieldRechargeRate); |
---|
122 | inline float getShieldRechargeRate() const |
---|
123 | { return this->shieldRechargeRate_; } |
---|
124 | |
---|
125 | virtual void setShieldRechargeWaitTime(float shieldRechargeWaitTime); |
---|
126 | inline float getShieldRechargeWaitTime() const |
---|
127 | { return this->shieldRechargeWaitTime_; } |
---|
128 | |
---|
129 | inline void resetShieldRechargeCountdown() |
---|
130 | { this->shieldRechargeWaitCountdown_ = 0; } |
---|
131 | |
---|
132 | inline void startShieldRechargeCountdown() |
---|
133 | { this->shieldRechargeWaitCountdown_ = this->getShieldRechargeWaitTime(); } // TODO: Implement in Projectile.cc |
---|
134 | |
---|
135 | virtual void decreaseShieldRechargeCountdownTime(float dt); |
---|
136 | |
---|
137 | /** @brief Sets the state of the pawns vulnerability. @param bVulnerable */ |
---|
138 | inline void setVulnerable(bool bVulnerable) |
---|
139 | { |
---|
140 | if (this->bVulnerable_ != bVulnerable) |
---|
141 | { |
---|
142 | this->bVulnerable_ = bVulnerable; |
---|
143 | this->changedVulnerability(); |
---|
144 | } |
---|
145 | } |
---|
146 | /** @brief Returns the state of the pawns vulnerability. @return The state of the vulnerability */ |
---|
147 | inline const bool& isVulnerable() const { return this->bVulnerable_; } |
---|
148 | /** @brief This function gets called if the vulnerability of the pawn changes. */ |
---|
149 | virtual void changedVulnerability(); |
---|
150 | |
---|
151 | inline ControllableEntity* getLastHitOriginator() const |
---|
152 | { return this->lastHitOriginator_; } |
---|
153 | |
---|
154 | virtual void hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); |
---|
155 | virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); |
---|
156 | |
---|
157 | virtual void kill(); |
---|
158 | |
---|
159 | virtual void fired(unsigned int firemode); |
---|
160 | virtual void postSpawn(); |
---|
161 | |
---|
162 | void addExplosionPart(ExplosionPart* ePart); |
---|
163 | ExplosionPart * getExplosionPart(); |
---|
164 | |
---|
165 | void addWeaponSlot(WeaponSlot * wSlot); |
---|
166 | WeaponSlot * getWeaponSlot(unsigned int index) const; |
---|
167 | void addWeaponSet(WeaponSet * wSet); |
---|
168 | WeaponSet * getWeaponSet(unsigned int index) const; |
---|
169 | void addWeaponPack(WeaponPack * wPack); |
---|
170 | void addWeaponPackXML(WeaponPack * wPack); |
---|
171 | WeaponPack * getWeaponPack(unsigned int index) const; |
---|
172 | std::vector<WeaponPack *> * getAllWeaponPacks(); |
---|
173 | |
---|
174 | void addMunitionXML(Munition* munition); |
---|
175 | Munition* getMunitionXML() const; |
---|
176 | |
---|
177 | Munition* getMunition(SubclassIdentifier<Munition> * identifier); |
---|
178 | |
---|
179 | virtual void addedWeaponPack(WeaponPack* wPack) {} |
---|
180 | |
---|
181 | inline void setSpawnParticleSource(const std::string& source) |
---|
182 | { this->spawnparticlesource_ = source; } |
---|
183 | inline const std::string& getSpawnParticleSource() const |
---|
184 | { return this->spawnparticlesource_; } |
---|
185 | |
---|
186 | inline void setSpawnParticleDuration(float duration) |
---|
187 | { this->spawnparticleduration_ = duration; } |
---|
188 | inline float getSpawnParticleDuration() const |
---|
189 | { return this->spawnparticleduration_; } |
---|
190 | |
---|
191 | inline void setExplosionChunks(unsigned int chunks) |
---|
192 | { this->numexplosionchunks_ = chunks; } |
---|
193 | inline unsigned int getExplosionChunks() const |
---|
194 | { return this->numexplosionchunks_; } |
---|
195 | |
---|
196 | // These are used with the Damage Boost Pickup to use the damage multiplier. |
---|
197 | inline void setDamageMultiplier(float multiplier) |
---|
198 | { this->damageMultiplier_ = multiplier; } |
---|
199 | inline float getDamageMultiplier() const |
---|
200 | { return this->damageMultiplier_; } |
---|
201 | |
---|
202 | |
---|
203 | virtual void startLocalHumanControl(); |
---|
204 | |
---|
205 | void setAimPosition( Vector3 position ) |
---|
206 | { this->aimPosition_ = position; } |
---|
207 | Vector3 getAimPosition() |
---|
208 | { return this->aimPosition_; } |
---|
209 | |
---|
210 | virtual const Vector3& getCarrierPosition(void) const |
---|
211 | { return this->getWorldPosition(); }; |
---|
212 | |
---|
213 | virtual void changedVisibility(); |
---|
214 | |
---|
215 | void setExplosionSound(const std::string& engineSound); |
---|
216 | const std::string& getExplosionSound(); |
---|
217 | |
---|
218 | virtual const WeaponSystem* getWeaponSystem() const |
---|
219 | { return this->weaponSystem_; } |
---|
220 | |
---|
221 | protected: |
---|
222 | virtual void preDestroy(); |
---|
223 | |
---|
224 | virtual void setPlayer(PlayerInfo* player); |
---|
225 | virtual void removePlayer(); |
---|
226 | |
---|
227 | virtual void death(); |
---|
228 | virtual bool hasSlaves(); |
---|
229 | virtual Controller* getSlave(); |
---|
230 | virtual void goWithStyle(); |
---|
231 | virtual void spawneffect(); |
---|
232 | |
---|
233 | virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL); |
---|
234 | |
---|
235 | bool bAlive_; |
---|
236 | bool bVulnerable_; ///< If false the pawn may not ged damaged |
---|
237 | |
---|
238 | virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const |
---|
239 | { return new std::vector<PickupCarrier*>(); } |
---|
240 | virtual PickupCarrier* getCarrierParent(void) const |
---|
241 | { return NULL; } |
---|
242 | |
---|
243 | |
---|
244 | float health_; |
---|
245 | float maxHealth_; |
---|
246 | float initialHealth_; |
---|
247 | |
---|
248 | float shieldHealth_; |
---|
249 | float maxShieldHealth_; |
---|
250 | float initialShieldHealth_; |
---|
251 | float shieldAbsorption_; ///< Has to be between 0 and 1 |
---|
252 | float shieldRechargeRate_; |
---|
253 | float shieldRechargeWaitTime_; |
---|
254 | float shieldRechargeWaitCountdown_; |
---|
255 | |
---|
256 | float damageMultiplier_; ///< Used by the Damage Boost Pickup. |
---|
257 | |
---|
258 | WeakPtr<Pawn> lastHitOriginator_; |
---|
259 | |
---|
260 | WeaponSystem* weaponSystem_; |
---|
261 | |
---|
262 | std::string spawnparticlesource_; |
---|
263 | float spawnparticleduration_; |
---|
264 | unsigned int numexplosionchunks_; |
---|
265 | |
---|
266 | std::vector<ExplosionPart*> explosionPartList_; |
---|
267 | |
---|
268 | private: |
---|
269 | void registerVariables(); |
---|
270 | inline void setWeaponSystem(WeaponSystem* weaponsystem) |
---|
271 | { this->weaponSystem_ = weaponsystem; } |
---|
272 | |
---|
273 | Vector3 aimPosition_; |
---|
274 | |
---|
275 | WorldSound* explosionSound_; // TODO: Does this really belong here? Maybe move it to BigExplosion? |
---|
276 | |
---|
277 | }; // tolua_export |
---|
278 | } // tolua_export |
---|
279 | |
---|
280 | #endif /* _Pawn_H__ */ |
---|