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