[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 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "Pawn.h" |
---|
| 31 | |
---|
| 32 | #include "core/CoreIncludes.h" |
---|
| 33 | #include "core/XMLPort.h" |
---|
| 34 | #include "util/Math.h" |
---|
[2369] | 35 | #include "PawnManager.h" |
---|
[2072] | 36 | #include "objects/infos/PlayerInfo.h" |
---|
| 37 | #include "objects/gametypes/Gametype.h" |
---|
[2106] | 38 | #include "objects/weaponSystem/WeaponSystem.h" |
---|
[2414] | 39 | #include "objects/worldentities/ParticleSpawner.h" |
---|
| 40 | #include "objects/worldentities/ExplosionChunk.h" |
---|
[2072] | 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | CreateFactory(Pawn); |
---|
| 45 | |
---|
| 46 | Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator) |
---|
| 47 | { |
---|
| 48 | RegisterObject(Pawn); |
---|
| 49 | |
---|
[2369] | 50 | PawnManager::touch(); |
---|
[2072] | 51 | |
---|
[2369] | 52 | this->bAlive_ = true; |
---|
| 53 | |
---|
[2072] | 54 | this->health_ = 0; |
---|
| 55 | this->maxHealth_ = 0; |
---|
| 56 | this->initialHealth_ = 0; |
---|
| 57 | |
---|
| 58 | this->lastHitOriginator_ = 0; |
---|
[2098] | 59 | this->weaponSystem_ = 0; |
---|
[2072] | 60 | |
---|
[2414] | 61 | this->spawnparticleduration_ = 3.0f; |
---|
| 62 | |
---|
[2098] | 63 | /* |
---|
| 64 | //WeaponSystem |
---|
| 65 | weaponSystem_ = new WeaponSystem(); |
---|
| 66 | WeaponSet * weaponSet1 = new WeaponSet(1); |
---|
| 67 | this->weaponSystem_->attachWeaponSet(weaponSet1); |
---|
| 68 | this->weaponSystem_->getWeaponSetPointer(0)->getWeaponSlotPointer(0)->setAmmoType(true); |
---|
| 69 | */ |
---|
| 70 | |
---|
[2256] | 71 | this->setRadarObjectColour(ColourValue::Red); |
---|
| 72 | this->setRadarObjectShape(RadarViewable::Dot); |
---|
| 73 | |
---|
[2072] | 74 | this->registerVariables(); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | Pawn::~Pawn() |
---|
| 78 | { |
---|
[2369] | 79 | if (this->isInitialized()) |
---|
| 80 | { |
---|
| 81 | for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it) |
---|
| 82 | it->destroyedPawn(this); |
---|
| 83 | } |
---|
[2072] | 84 | } |
---|
| 85 | |
---|
| 86 | void Pawn::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 87 | { |
---|
| 88 | SUPER(Pawn, XMLPort, xmlelement, mode); |
---|
| 89 | |
---|
[2369] | 90 | XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100); |
---|
[2072] | 91 | XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200); |
---|
| 92 | XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100); |
---|
[2414] | 93 | XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode); |
---|
| 94 | XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f); |
---|
| 95 | XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7); |
---|
[2072] | 96 | } |
---|
| 97 | |
---|
| 98 | void Pawn::registerVariables() |
---|
| 99 | { |
---|
[2171] | 100 | REGISTERDATA(this->bAlive_, direction::toclient); |
---|
| 101 | REGISTERDATA(this->health_, direction::toclient); |
---|
[2369] | 102 | REGISTERDATA(this->initialHealth_, direction::toclient); |
---|
[2072] | 103 | } |
---|
| 104 | |
---|
| 105 | void Pawn::tick(float dt) |
---|
| 106 | { |
---|
| 107 | SUPER(Pawn, tick, dt); |
---|
| 108 | |
---|
[2369] | 109 | this->health_ -= 15 * dt * rnd(); |
---|
| 110 | |
---|
[2072] | 111 | if (this->health_ <= 0) |
---|
| 112 | this->death(); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | void Pawn::setHealth(float health) |
---|
| 116 | { |
---|
| 117 | this->health_ = min(health, this->maxHealth_); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | void Pawn::damage(float damage, Pawn* originator) |
---|
| 121 | { |
---|
| 122 | this->setHealth(this->health_ - damage); |
---|
| 123 | this->lastHitOriginator_ = originator; |
---|
| 124 | |
---|
| 125 | // play damage effect |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void Pawn::hit(Pawn* originator, const Vector3& force, float damage) |
---|
| 129 | { |
---|
| 130 | this->damage(damage, originator); |
---|
| 131 | this->setVelocity(this->getVelocity() + force); |
---|
| 132 | |
---|
| 133 | // play hit effect |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | void Pawn::kill() |
---|
| 137 | { |
---|
| 138 | this->damage(this->health_); |
---|
| 139 | this->death(); |
---|
| 140 | } |
---|
| 141 | |
---|
[2414] | 142 | void Pawn::spawneffect() |
---|
[2072] | 143 | { |
---|
| 144 | // play spawn effect |
---|
[2414] | 145 | if (this->spawnparticlesource_ != "") |
---|
| 146 | { |
---|
| 147 | ParticleSpawner* effect = new ParticleSpawner(this); |
---|
| 148 | effect->setPosition(this->getPosition()); |
---|
| 149 | effect->setOrientation(this->getOrientation()); |
---|
| 150 | effect->setDestroyAfterLife(true); |
---|
| 151 | effect->setSource(this->spawnparticlesource_); |
---|
| 152 | effect->setLifetime(this->spawnparticleduration_); |
---|
| 153 | } |
---|
[2072] | 154 | } |
---|
| 155 | |
---|
| 156 | void Pawn::death() |
---|
| 157 | { |
---|
[2369] | 158 | // Set bAlive_ to false and wait for PawnManager to do the destruction |
---|
[2072] | 159 | this->bAlive_ = false; |
---|
[2369] | 160 | |
---|
[2072] | 161 | if (this->getGametype()) |
---|
| 162 | this->getGametype()->pawnKilled(this, this->lastHitOriginator_); |
---|
[2369] | 163 | |
---|
| 164 | this->setDestroyWhenPlayerLeft(false); |
---|
| 165 | |
---|
[2072] | 166 | if (this->getPlayer()) |
---|
| 167 | this->getPlayer()->stopControl(this); |
---|
| 168 | |
---|
[2414] | 169 | this->deatheffect(); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | void Pawn::deatheffect() |
---|
| 173 | { |
---|
[2072] | 174 | // play death effect |
---|
[2414] | 175 | { |
---|
| 176 | ParticleSpawner* effect = new ParticleSpawner(this); |
---|
| 177 | effect->setPosition(this->getPosition()); |
---|
| 178 | effect->setOrientation(this->getOrientation()); |
---|
| 179 | effect->setDestroyAfterLife(true); |
---|
| 180 | effect->setSource("Orxonox/explosion2"); |
---|
| 181 | effect->setLifetime(4.0f); |
---|
| 182 | } |
---|
| 183 | { |
---|
| 184 | ParticleSpawner* effect = new ParticleSpawner(this); |
---|
| 185 | effect->setPosition(this->getPosition()); |
---|
| 186 | effect->setOrientation(this->getOrientation()); |
---|
| 187 | effect->setDestroyAfterLife(true); |
---|
| 188 | effect->setSource("Orxonox/smoke6"); |
---|
| 189 | effect->setLifetime(4.0f); |
---|
| 190 | } |
---|
| 191 | { |
---|
| 192 | ParticleSpawner* effect = new ParticleSpawner(this); |
---|
| 193 | effect->setPosition(this->getPosition()); |
---|
| 194 | effect->setOrientation(this->getOrientation()); |
---|
| 195 | effect->setDestroyAfterLife(true); |
---|
| 196 | effect->setSource("Orxonox/sparks"); |
---|
| 197 | effect->setLifetime(4.0f); |
---|
| 198 | } |
---|
| 199 | for (unsigned int i = 0; i < this->numexplosionchunks_; ++i) |
---|
| 200 | { |
---|
| 201 | ExplosionChunk* chunk = new ExplosionChunk(this); |
---|
| 202 | chunk->setPosition(this->getPosition()); |
---|
| 203 | |
---|
| 204 | } |
---|
[2072] | 205 | } |
---|
| 206 | |
---|
[2098] | 207 | void Pawn::fire() |
---|
| 208 | { |
---|
| 209 | if (this->weaponSystem_) |
---|
| 210 | this->weaponSystem_->fire(); |
---|
| 211 | } |
---|
| 212 | |
---|
[2072] | 213 | void Pawn::postSpawn() |
---|
| 214 | { |
---|
| 215 | this->setHealth(this->initialHealth_); |
---|
[2414] | 216 | this->spawneffect(); |
---|
[2072] | 217 | } |
---|
[2369] | 218 | |
---|
| 219 | /////////////////// |
---|
| 220 | // Pawn Listener // |
---|
| 221 | /////////////////// |
---|
| 222 | PawnListener::PawnListener() |
---|
| 223 | { |
---|
| 224 | RegisterRootObject(PawnListener); |
---|
| 225 | } |
---|
[2072] | 226 | } |
---|