[2072] | 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" |
---|
[3196] | 33 | |
---|
| 34 | #include <string> |
---|
[11052] | 35 | #include <vector> |
---|
[6524] | 36 | #include "interfaces/PickupCarrier.h" |
---|
[3196] | 37 | #include "interfaces/RadarViewable.h" |
---|
[5735] | 38 | #include "worldentities/ControllableEntity.h" |
---|
[11052] | 39 | #include "worldentities/ExplosionPart.h" |
---|
[2072] | 40 | |
---|
[9939] | 41 | |
---|
[6711] | 42 | namespace orxonox // tolua_export |
---|
[10437] | 43 | { |
---|
| 44 | /** |
---|
| 45 | @brief |
---|
[11052] | 46 | Everything in Orxonox that has a health attribute is a Pawn. After a Pawn is spawned its health is set to |
---|
[10437] | 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 | |
---|
[11052] | 50 | Pawns can carry pickups and fire weapons. They can also have shields. |
---|
[10437] | 51 | |
---|
| 52 | Notice that every Pawn is a ControllableEntity. |
---|
| 53 | */ |
---|
| 54 | |
---|
| 55 | // tolua_export |
---|
[6711] | 56 | class _OrxonoxExport Pawn // tolua_export |
---|
| 57 | : public ControllableEntity, public RadarViewable, public PickupCarrier |
---|
| 58 | { // tolua_export |
---|
[3053] | 59 | friend class WeaponSystem; |
---|
| 60 | |
---|
[2072] | 61 | public: |
---|
[9667] | 62 | Pawn(Context* context); |
---|
[2072] | 63 | virtual ~Pawn(); |
---|
| 64 | |
---|
[11071] | 65 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; |
---|
| 66 | virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override; |
---|
| 67 | virtual void tick(float dt) override; |
---|
[2072] | 68 | |
---|
| 69 | inline bool isAlive() const |
---|
| 70 | { return this->bAlive_; } |
---|
| 71 | |
---|
[9016] | 72 | |
---|
[11071] | 73 | void setHealth(float health); |
---|
[2072] | 74 | inline void addHealth(float health) |
---|
| 75 | { this->setHealth(this->health_ + health); } |
---|
| 76 | inline void removeHealth(float health) |
---|
| 77 | { this->setHealth(this->health_ - health); } |
---|
[2662] | 78 | inline float getHealth() const |
---|
[2072] | 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 | |
---|
[11071] | 91 | void setShieldHealth(float shieldHealth); |
---|
[8706] | 92 | |
---|
[7163] | 93 | inline float getShieldHealth() |
---|
[8855] | 94 | { return this->shieldHealth_; } |
---|
[7163] | 95 | |
---|
[8706] | 96 | inline void addShieldHealth(float amount) |
---|
[8855] | 97 | { this->setShieldHealth(this->shieldHealth_ + amount); } |
---|
[8706] | 98 | |
---|
| 99 | inline bool hasShield() |
---|
[8855] | 100 | { return (this->getShieldHealth() > 0); } |
---|
[8706] | 101 | |
---|
[11071] | 102 | void setMaxShieldHealth(float maxshieldhealth); |
---|
[8706] | 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 | |
---|
[7163] | 116 | inline void setShieldAbsorption(float shieldAbsorption) |
---|
[8855] | 117 | { this->shieldAbsorption_ = shieldAbsorption; } |
---|
[7163] | 118 | inline float getShieldAbsorption() |
---|
[8855] | 119 | { return this->shieldAbsorption_; } |
---|
[7163] | 120 | |
---|
[11071] | 121 | void setShieldRechargeRate(float shieldRechargeRate); |
---|
[11052] | 122 | inline float getShieldRechargeRate() const |
---|
| 123 | { return this->shieldRechargeRate_; } |
---|
[8706] | 124 | |
---|
[11071] | 125 | void setShieldRechargeWaitTime(float shieldRechargeWaitTime); |
---|
[11052] | 126 | inline float getShieldRechargeWaitTime() const |
---|
| 127 | { return this->shieldRechargeWaitTime_; } |
---|
[8706] | 128 | |
---|
[11052] | 129 | inline void resetShieldRechargeCountdown() |
---|
| 130 | { this->shieldRechargeWaitCountdown_ = 0; } |
---|
[8706] | 131 | |
---|
[11052] | 132 | inline void startShieldRechargeCountdown() |
---|
| 133 | { this->shieldRechargeWaitCountdown_ = this->getShieldRechargeWaitTime(); } // TODO: Implement in Projectile.cc |
---|
[8706] | 134 | |
---|
[11071] | 135 | void decreaseShieldRechargeCountdownTime(float dt); |
---|
[8706] | 136 | |
---|
[11052] | 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 | |
---|
[2072] | 151 | inline ControllableEntity* getLastHitOriginator() const |
---|
| 152 | { return this->lastHitOriginator_; } |
---|
| 153 | |
---|
[10216] | 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); |
---|
[8706] | 156 | |
---|
[2072] | 157 | virtual void kill(); |
---|
| 158 | |
---|
[11071] | 159 | virtual void fired(unsigned int firemode) override; |
---|
[2072] | 160 | virtual void postSpawn(); |
---|
| 161 | |
---|
[11052] | 162 | void addExplosionPart(ExplosionPart* ePart); |
---|
| 163 | ExplosionPart * getExplosionPart(); |
---|
| 164 | |
---|
[3053] | 165 | void addWeaponSlot(WeaponSlot * wSlot); |
---|
[2662] | 166 | WeaponSlot * getWeaponSlot(unsigned int index) const; |
---|
[3053] | 167 | void addWeaponSet(WeaponSet * wSet); |
---|
[2662] | 168 | WeaponSet * getWeaponSet(unsigned int index) const; |
---|
[3053] | 169 | void addWeaponPack(WeaponPack * wPack); |
---|
[6417] | 170 | void addWeaponPackXML(WeaponPack * wPack); |
---|
[3053] | 171 | WeaponPack * getWeaponPack(unsigned int index) const; |
---|
[2662] | 172 | |
---|
[11052] | 173 | void addMunitionXML(Munition* munition); |
---|
| 174 | Munition* getMunitionXML() const; |
---|
| 175 | |
---|
| 176 | Munition* getMunition(SubclassIdentifier<Munition> * identifier); |
---|
| 177 | |
---|
[7163] | 178 | virtual void addedWeaponPack(WeaponPack* wPack) {} |
---|
| 179 | |
---|
[2662] | 180 | inline void setSpawnParticleSource(const std::string& source) |
---|
| 181 | { this->spawnparticlesource_ = source; } |
---|
| 182 | inline const std::string& getSpawnParticleSource() const |
---|
| 183 | { return this->spawnparticlesource_; } |
---|
| 184 | |
---|
| 185 | inline void setSpawnParticleDuration(float duration) |
---|
| 186 | { this->spawnparticleduration_ = duration; } |
---|
| 187 | inline float getSpawnParticleDuration() const |
---|
| 188 | { return this->spawnparticleduration_; } |
---|
| 189 | |
---|
| 190 | inline void setExplosionChunks(unsigned int chunks) |
---|
| 191 | { this->numexplosionchunks_ = chunks; } |
---|
| 192 | inline unsigned int getExplosionChunks() const |
---|
| 193 | { return this->numexplosionchunks_; } |
---|
| 194 | |
---|
[9348] | 195 | // These are used with the Damage Boost Pickup to use the damage multiplier. |
---|
| 196 | inline void setDamageMultiplier(float multiplier) |
---|
| 197 | { this->damageMultiplier_ = multiplier; } |
---|
| 198 | inline float getDamageMultiplier() const |
---|
| 199 | { return this->damageMultiplier_; } |
---|
| 200 | |
---|
| 201 | |
---|
[11071] | 202 | virtual void startLocalHumanControl() override; |
---|
[2662] | 203 | |
---|
[6417] | 204 | void setAimPosition( Vector3 position ) |
---|
| 205 | { this->aimPosition_ = position; } |
---|
| 206 | Vector3 getAimPosition() |
---|
| 207 | { return this->aimPosition_; } |
---|
[7163] | 208 | |
---|
[11071] | 209 | virtual const Vector3& getCarrierPosition(void) const override |
---|
[6540] | 210 | { return this->getWorldPosition(); }; |
---|
[6417] | 211 | |
---|
[11071] | 212 | virtual void changedVisibility() override; |
---|
[9254] | 213 | |
---|
[9939] | 214 | void setExplosionSound(const std::string& engineSound); |
---|
| 215 | const std::string& getExplosionSound(); |
---|
| 216 | |
---|
[11071] | 217 | inline const WeaponSystem* getWeaponSystem() const |
---|
[11052] | 218 | { return this->weaponSystem_; } |
---|
| 219 | |
---|
[11176] | 220 | static void consoleCommand_debugDrawWeapons(bool bDraw); |
---|
| 221 | |
---|
[2072] | 222 | protected: |
---|
[11071] | 223 | virtual void preDestroy() override; |
---|
[7889] | 224 | |
---|
[11071] | 225 | virtual void setPlayer(PlayerInfo* player) override; |
---|
| 226 | virtual void removePlayer() override; |
---|
[3038] | 227 | |
---|
[2072] | 228 | virtual void death(); |
---|
[9625] | 229 | virtual bool hasSlaves(); |
---|
| 230 | virtual Controller* getSlave(); |
---|
[3087] | 231 | virtual void goWithStyle(); |
---|
[2662] | 232 | virtual void spawneffect(); |
---|
[2072] | 233 | |
---|
[11071] | 234 | virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = nullptr, const btCollisionShape* cs = nullptr); |
---|
[6417] | 235 | |
---|
[2072] | 236 | bool bAlive_; |
---|
[11176] | 237 | bool bVulnerable_; ///< If this is false, then the pawn may not take damage |
---|
[2072] | 238 | |
---|
[11071] | 239 | virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const override |
---|
[6711] | 240 | { return new std::vector<PickupCarrier*>(); } |
---|
[11071] | 241 | virtual PickupCarrier* getCarrierParent(void) const override |
---|
| 242 | { return nullptr; } |
---|
[2662] | 243 | |
---|
[9016] | 244 | |
---|
[2072] | 245 | float health_; |
---|
| 246 | float maxHealth_; |
---|
| 247 | float initialHealth_; |
---|
[8891] | 248 | |
---|
[7163] | 249 | float shieldHealth_; |
---|
[8706] | 250 | float maxShieldHealth_; |
---|
| 251 | float initialShieldHealth_; |
---|
[9348] | 252 | float shieldAbsorption_; ///< Has to be between 0 and 1 |
---|
[11052] | 253 | float shieldRechargeRate_; |
---|
| 254 | float shieldRechargeWaitTime_; |
---|
| 255 | float shieldRechargeWaitCountdown_; |
---|
[2072] | 256 | |
---|
[9348] | 257 | float damageMultiplier_; ///< Used by the Damage Boost Pickup. |
---|
| 258 | |
---|
[7655] | 259 | WeakPtr<Pawn> lastHitOriginator_; |
---|
[2098] | 260 | |
---|
| 261 | WeaponSystem* weaponSystem_; |
---|
[2662] | 262 | |
---|
| 263 | std::string spawnparticlesource_; |
---|
| 264 | float spawnparticleduration_; |
---|
| 265 | unsigned int numexplosionchunks_; |
---|
[3053] | 266 | |
---|
[11052] | 267 | std::vector<ExplosionPart*> explosionPartList_; |
---|
| 268 | |
---|
[3053] | 269 | private: |
---|
[7163] | 270 | void registerVariables(); |
---|
[3053] | 271 | inline void setWeaponSystem(WeaponSystem* weaponsystem) |
---|
| 272 | { this->weaponSystem_ = weaponsystem; } |
---|
[11176] | 273 | void drawWeapons(bool bDraw); |
---|
[6417] | 274 | |
---|
| 275 | Vector3 aimPosition_; |
---|
[9939] | 276 | |
---|
[9948] | 277 | WorldSound* explosionSound_; // TODO: Does this really belong here? Maybe move it to BigExplosion? |
---|
[9939] | 278 | |
---|
[11176] | 279 | std::vector<Model*> debugWeaponSlotModels_; |
---|
| 280 | |
---|
[6711] | 281 | }; // tolua_export |
---|
| 282 | } // tolua_export |
---|
[2072] | 283 | |
---|
| 284 | #endif /* _Pawn_H__ */ |
---|