[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: |
---|
[8706] | 25 | * Simon Miescher |
---|
[2072] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "Pawn.h" |
---|
| 30 | |
---|
[3280] | 31 | #include <algorithm> |
---|
| 32 | |
---|
[3196] | 33 | #include "core/CoreIncludes.h" |
---|
[2896] | 34 | #include "core/GameMode.h" |
---|
[2072] | 35 | #include "core/XMLPort.h" |
---|
[3196] | 36 | #include "network/NetworkFunction.h" |
---|
| 37 | |
---|
[5735] | 38 | #include "infos/PlayerInfo.h" |
---|
[6417] | 39 | #include "controllers/Controller.h" |
---|
[5735] | 40 | #include "gametypes/Gametype.h" |
---|
[5737] | 41 | #include "graphics/ParticleSpawner.h" |
---|
[5735] | 42 | #include "worldentities/ExplosionChunk.h" |
---|
| 43 | #include "worldentities/BigExplosion.h" |
---|
| 44 | #include "weaponsystem/WeaponSystem.h" |
---|
| 45 | #include "weaponsystem/WeaponSlot.h" |
---|
| 46 | #include "weaponsystem/WeaponPack.h" |
---|
| 47 | #include "weaponsystem/WeaponSet.h" |
---|
[9939] | 48 | #include "sound/WorldSound.h" |
---|
[2072] | 49 | |
---|
[9625] | 50 | #include "controllers/FormationController.h" |
---|
| 51 | |
---|
[9997] | 52 | #include "collisionshapes/WorldEntityCollisionShape.h" |
---|
[10001] | 53 | #include <BulletCollision/CollisionShapes/btCollisionShape.h> |
---|
[10002] | 54 | #include <BulletCollision/CollisionShapes/btCompoundShape.h> |
---|
[9997] | 55 | |
---|
[10002] | 56 | |
---|
[2072] | 57 | namespace orxonox |
---|
| 58 | { |
---|
[9667] | 59 | RegisterClass(Pawn); |
---|
[2072] | 60 | |
---|
[9667] | 61 | Pawn::Pawn(Context* context) |
---|
| 62 | : ControllableEntity(context) |
---|
| 63 | , RadarViewable(this, static_cast<WorldEntity*>(this)) |
---|
[2072] | 64 | { |
---|
| 65 | RegisterObject(Pawn); |
---|
| 66 | |
---|
[2662] | 67 | this->bAlive_ = true; |
---|
[3053] | 68 | this->bReload_ = false; |
---|
[2072] | 69 | |
---|
| 70 | this->health_ = 0; |
---|
| 71 | this->maxHealth_ = 0; |
---|
| 72 | this->initialHealth_ = 0; |
---|
[8706] | 73 | |
---|
[7163] | 74 | this->shieldHealth_ = 0; |
---|
[8706] | 75 | this->initialShieldHealth_ = 0; |
---|
| 76 | this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max |
---|
[7163] | 77 | this->shieldAbsorption_ = 0.5; |
---|
[2072] | 78 | |
---|
[8706] | 79 | this->reloadRate_ = 0; |
---|
| 80 | this->reloadWaitTime_ = 1.0f; |
---|
| 81 | this->reloadWaitCountdown_ = 0; |
---|
| 82 | |
---|
[2072] | 83 | this->lastHitOriginator_ = 0; |
---|
| 84 | |
---|
[9348] | 85 | // set damage multiplier to default value 1, meaning nominal damage |
---|
| 86 | this->damageMultiplier_ = 1; |
---|
| 87 | |
---|
[2662] | 88 | this->spawnparticleduration_ = 3.0f; |
---|
[2098] | 89 | |
---|
[6417] | 90 | this->aimPosition_ = Vector3::ZERO; |
---|
| 91 | |
---|
[2896] | 92 | if (GameMode::isMaster()) |
---|
[2662] | 93 | { |
---|
[9667] | 94 | this->weaponSystem_ = new WeaponSystem(this->getContext()); |
---|
[3053] | 95 | this->weaponSystem_->setPawn(this); |
---|
[2662] | 96 | } |
---|
| 97 | else |
---|
| 98 | this->weaponSystem_ = 0; |
---|
| 99 | |
---|
| 100 | this->setRadarObjectColour(ColourValue::Red); |
---|
| 101 | this->setRadarObjectShape(RadarViewable::Dot); |
---|
| 102 | |
---|
[2072] | 103 | this->registerVariables(); |
---|
[3089] | 104 | |
---|
| 105 | this->isHumanShip_ = this->hasLocalController(); |
---|
[8891] | 106 | |
---|
[8329] | 107 | this->setSyncMode(ObjectDirection::Bidirectional); // needed to synchronise e.g. aimposition |
---|
[9939] | 108 | |
---|
| 109 | if (GameMode::isMaster()) |
---|
| 110 | { |
---|
| 111 | this->explosionSound_ = new WorldSound(this->getContext()); |
---|
| 112 | this->explosionSound_->setVolume(1.0f); |
---|
| 113 | } |
---|
| 114 | else |
---|
| 115 | { |
---|
| 116 | this->explosionSound_ = 0; |
---|
| 117 | } |
---|
[2072] | 118 | } |
---|
| 119 | |
---|
| 120 | Pawn::~Pawn() |
---|
| 121 | { |
---|
[2662] | 122 | if (this->isInitialized()) |
---|
| 123 | { |
---|
| 124 | if (this->weaponSystem_) |
---|
[5929] | 125 | this->weaponSystem_->destroy(); |
---|
[2662] | 126 | } |
---|
[2072] | 127 | } |
---|
| 128 | |
---|
| 129 | void Pawn::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 130 | { |
---|
| 131 | SUPER(Pawn, XMLPort, xmlelement, mode); |
---|
| 132 | |
---|
[2662] | 133 | XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100); |
---|
[2072] | 134 | XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200); |
---|
| 135 | XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100); |
---|
[7163] | 136 | |
---|
| 137 | XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0); |
---|
[8706] | 138 | XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0); |
---|
| 139 | XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100); |
---|
[7163] | 140 | XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0); |
---|
| 141 | |
---|
[2662] | 142 | XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode); |
---|
| 143 | XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f); |
---|
| 144 | XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7); |
---|
| 145 | |
---|
[3053] | 146 | XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode); |
---|
| 147 | XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode); |
---|
[6417] | 148 | XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode); |
---|
[8706] | 149 | |
---|
| 150 | XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0); |
---|
| 151 | XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f); |
---|
[9254] | 152 | |
---|
[9939] | 153 | XMLPortParam(Pawn, "explosionSound", setExplosionSound, getExplosionSound, xmlelement, mode); |
---|
| 154 | |
---|
[9257] | 155 | XMLPortParam ( RadarViewable, "radarname", setRadarName, getRadarName, xmlelement, mode ); |
---|
[2072] | 156 | } |
---|
| 157 | |
---|
| 158 | void Pawn::registerVariables() |
---|
| 159 | { |
---|
[7163] | 160 | registerVariable(this->bAlive_, VariableDirection::ToClient); |
---|
| 161 | registerVariable(this->health_, VariableDirection::ToClient); |
---|
[8706] | 162 | registerVariable(this->maxHealth_, VariableDirection::ToClient); |
---|
[7163] | 163 | registerVariable(this->shieldHealth_, VariableDirection::ToClient); |
---|
[8706] | 164 | registerVariable(this->maxShieldHealth_, VariableDirection::ToClient); |
---|
[7163] | 165 | registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); |
---|
| 166 | registerVariable(this->bReload_, VariableDirection::ToServer); |
---|
| 167 | registerVariable(this->aimPosition_, VariableDirection::ToServer); // For the moment this variable gets only transfered to the server |
---|
[2072] | 168 | } |
---|
| 169 | |
---|
| 170 | void Pawn::tick(float dt) |
---|
| 171 | { |
---|
[2809] | 172 | SUPER(Pawn, tick, dt); |
---|
[2072] | 173 | |
---|
[3053] | 174 | this->bReload_ = false; |
---|
[2662] | 175 | |
---|
[8706] | 176 | // TODO: use the existing timer functions instead |
---|
| 177 | if(this->reloadWaitCountdown_ > 0) |
---|
| 178 | { |
---|
| 179 | this->decreaseReloadCountdownTime(dt); |
---|
| 180 | } |
---|
| 181 | else |
---|
| 182 | { |
---|
| 183 | this->addShieldHealth(this->getReloadRate() * dt); |
---|
| 184 | this->resetReloadCountdown(); |
---|
| 185 | } |
---|
| 186 | |
---|
[3084] | 187 | if (GameMode::isMaster()) |
---|
[8706] | 188 | { |
---|
[3087] | 189 | if (this->health_ <= 0 && bAlive_) |
---|
[6864] | 190 | { |
---|
[8706] | 191 | this->fireEvent(); // Event to notify anyone who wants to know about the death. |
---|
[3087] | 192 | this->death(); |
---|
[6864] | 193 | } |
---|
[8706] | 194 | } |
---|
[2072] | 195 | } |
---|
| 196 | |
---|
[7889] | 197 | void Pawn::preDestroy() |
---|
| 198 | { |
---|
| 199 | // yay, multiple inheritance! |
---|
| 200 | this->ControllableEntity::preDestroy(); |
---|
| 201 | this->PickupCarrier::preDestroy(); |
---|
| 202 | } |
---|
| 203 | |
---|
[2826] | 204 | void Pawn::setPlayer(PlayerInfo* player) |
---|
| 205 | { |
---|
| 206 | ControllableEntity::setPlayer(player); |
---|
| 207 | |
---|
| 208 | if (this->getGametype()) |
---|
| 209 | this->getGametype()->playerStartsControllingPawn(player, this); |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | void Pawn::removePlayer() |
---|
| 213 | { |
---|
| 214 | if (this->getGametype()) |
---|
| 215 | this->getGametype()->playerStopsControllingPawn(this->getPlayer(), this); |
---|
| 216 | |
---|
| 217 | ControllableEntity::removePlayer(); |
---|
| 218 | } |
---|
| 219 | |
---|
[8706] | 220 | |
---|
[2072] | 221 | void Pawn::setHealth(float health) |
---|
| 222 | { |
---|
[8706] | 223 | this->health_ = std::min(health, this->maxHealth_); //Health can't be set to a value bigger than maxHealth, otherwise it will be reduced at first hit |
---|
[2072] | 224 | } |
---|
| 225 | |
---|
[8706] | 226 | void Pawn::setShieldHealth(float shieldHealth) |
---|
[2072] | 227 | { |
---|
[8706] | 228 | this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_); |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | void Pawn::setMaxShieldHealth(float maxshieldhealth) |
---|
| 232 | { |
---|
| 233 | this->maxShieldHealth_ = maxshieldhealth; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | void Pawn::setReloadRate(float reloadrate) |
---|
| 237 | { |
---|
| 238 | this->reloadRate_ = reloadrate; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | void Pawn::setReloadWaitTime(float reloadwaittime) |
---|
| 242 | { |
---|
| 243 | this->reloadWaitTime_ = reloadwaittime; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | void Pawn::decreaseReloadCountdownTime(float dt) |
---|
| 247 | { |
---|
| 248 | this->reloadWaitCountdown_ -= dt; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator) |
---|
| 252 | { |
---|
[9348] | 253 | // Applies multiplier given by the DamageBoost Pickup. |
---|
| 254 | if (originator) |
---|
| 255 | damage *= originator->getDamageMultiplier(); |
---|
| 256 | |
---|
[2826] | 257 | if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) |
---|
| 258 | { |
---|
[8706] | 259 | if (shielddamage >= this->getShieldHealth()) |
---|
[7163] | 260 | { |
---|
| 261 | this->setShieldHealth(0); |
---|
[8706] | 262 | this->setHealth(this->health_ - (healthdamage + damage)); |
---|
[7163] | 263 | } |
---|
[8706] | 264 | else |
---|
| 265 | { |
---|
| 266 | this->setShieldHealth(this->shieldHealth_ - shielddamage); |
---|
[7163] | 267 | |
---|
[8706] | 268 | // remove remaining shieldAbsorpton-Part of damage from shield |
---|
| 269 | shielddamage = damage * this->shieldAbsorption_; |
---|
| 270 | shielddamage = std::min(this->getShieldHealth(),shielddamage); |
---|
| 271 | this->setShieldHealth(this->shieldHealth_ - shielddamage); |
---|
[7163] | 272 | |
---|
[8706] | 273 | // set remaining damage to health |
---|
| 274 | this->setHealth(this->health_ - (damage - shielddamage) - healthdamage); |
---|
[7163] | 275 | } |
---|
| 276 | |
---|
[2826] | 277 | this->lastHitOriginator_ = originator; |
---|
| 278 | } |
---|
[2072] | 279 | } |
---|
| 280 | |
---|
[9995] | 281 | void Pawn::customDamage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs) |
---|
| 282 | { |
---|
[10001] | 283 | orxout() << "damage(): Collision detected on " << this->getRadarName() << ", btCS*: " << cs << endl; |
---|
| 284 | |
---|
[9997] | 285 | int collisionShapeIndex = this->isMyCollisionShape(cs); |
---|
| 286 | orxout() << collisionShapeIndex << endl; |
---|
| 287 | |
---|
[9995] | 288 | // Applies multiplier given by the DamageBoost Pickup. |
---|
| 289 | if (originator) |
---|
| 290 | damage *= originator->getDamageMultiplier(); |
---|
| 291 | |
---|
| 292 | if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) |
---|
| 293 | { |
---|
| 294 | if (shielddamage >= this->getShieldHealth()) |
---|
| 295 | { |
---|
| 296 | this->setShieldHealth(0); |
---|
| 297 | this->setHealth(this->health_ - (healthdamage + damage)); |
---|
| 298 | } |
---|
| 299 | else |
---|
| 300 | { |
---|
| 301 | this->setShieldHealth(this->shieldHealth_ - shielddamage); |
---|
| 302 | |
---|
| 303 | // remove remaining shieldAbsorpton-Part of damage from shield |
---|
| 304 | shielddamage = damage * this->shieldAbsorption_; |
---|
| 305 | shielddamage = std::min(this->getShieldHealth(),shielddamage); |
---|
| 306 | this->setShieldHealth(this->shieldHealth_ - shielddamage); |
---|
| 307 | |
---|
| 308 | // set remaining damage to health |
---|
| 309 | this->setHealth(this->health_ - (damage - shielddamage) - healthdamage); |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | this->lastHitOriginator_ = originator; |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | |
---|
[8706] | 316 | // TODO: Still valid? |
---|
| 317 | /* HIT-Funktionen |
---|
| 318 | Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte) |
---|
| 319 | |
---|
| 320 | */ |
---|
| 321 | void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage) |
---|
[2072] | 322 | { |
---|
[6417] | 323 | if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) |
---|
[2826] | 324 | { |
---|
[8706] | 325 | this->damage(damage, healthdamage, shielddamage, originator); |
---|
[2826] | 326 | this->setVelocity(this->getVelocity() + force); |
---|
| 327 | } |
---|
[2072] | 328 | } |
---|
| 329 | |
---|
[9995] | 330 | void Pawn::customHit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage) |
---|
| 331 | { |
---|
| 332 | if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) |
---|
| 333 | { |
---|
| 334 | this->customDamage(damage, healthdamage, shielddamage, originator, cs); |
---|
| 335 | this->setVelocity(this->getVelocity() + force); |
---|
| 336 | } |
---|
| 337 | } |
---|
[8706] | 338 | |
---|
| 339 | void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage) |
---|
[6417] | 340 | { |
---|
| 341 | if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) |
---|
| 342 | { |
---|
[8706] | 343 | this->damage(damage, healthdamage, shielddamage, originator); |
---|
[6417] | 344 | |
---|
| 345 | if ( this->getController() ) |
---|
[8706] | 346 | this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage? |
---|
[6417] | 347 | } |
---|
| 348 | } |
---|
| 349 | |
---|
[9995] | 350 | void Pawn::customHit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage) |
---|
| 351 | { |
---|
| 352 | if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) |
---|
| 353 | { |
---|
| 354 | this->customDamage(damage, healthdamage, shielddamage, originator, cs); |
---|
[8706] | 355 | |
---|
[9995] | 356 | if ( this->getController() ) |
---|
| 357 | this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage? |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | |
---|
[2072] | 362 | void Pawn::kill() |
---|
| 363 | { |
---|
[9945] | 364 | this->damage(this->health_); |
---|
[2072] | 365 | this->death(); |
---|
| 366 | } |
---|
| 367 | |
---|
[2662] | 368 | void Pawn::spawneffect() |
---|
[2072] | 369 | { |
---|
| 370 | // play spawn effect |
---|
[6417] | 371 | if (!this->spawnparticlesource_.empty()) |
---|
[2662] | 372 | { |
---|
[9667] | 373 | ParticleSpawner* effect = new ParticleSpawner(this->getContext()); |
---|
[2662] | 374 | effect->setPosition(this->getPosition()); |
---|
| 375 | effect->setOrientation(this->getOrientation()); |
---|
| 376 | effect->setDestroyAfterLife(true); |
---|
| 377 | effect->setSource(this->spawnparticlesource_); |
---|
| 378 | effect->setLifetime(this->spawnparticleduration_); |
---|
| 379 | } |
---|
[2072] | 380 | } |
---|
| 381 | |
---|
[9625] | 382 | |
---|
[2072] | 383 | void Pawn::death() |
---|
| 384 | { |
---|
[3033] | 385 | this->setHealth(1); |
---|
[2826] | 386 | if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_)) |
---|
| 387 | { |
---|
[9945] | 388 | // Set bAlive_ to false and wait for PawnManager to do the destruction |
---|
[2826] | 389 | this->bAlive_ = false; |
---|
[2662] | 390 | |
---|
[2826] | 391 | this->setDestroyWhenPlayerLeft(false); |
---|
[2662] | 392 | |
---|
[2826] | 393 | if (this->getGametype()) |
---|
| 394 | this->getGametype()->pawnKilled(this, this->lastHitOriginator_); |
---|
[2662] | 395 | |
---|
[3038] | 396 | if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this) |
---|
[9625] | 397 | { |
---|
[9663] | 398 | // Start to control a new entity if you're the master of a formation |
---|
| 399 | if(this->hasSlaves()) |
---|
| 400 | { |
---|
| 401 | Controller* slave = this->getSlave(); |
---|
| 402 | ControllableEntity* entity = slave->getControllableEntity(); |
---|
[2072] | 403 | |
---|
[9625] | 404 | |
---|
[9663] | 405 | if(!entity->hasHumanController()) |
---|
| 406 | { |
---|
[9666] | 407 | // delete the AIController // <-- TODO: delete? nothing is deleted here... should we delete the controller? |
---|
[9663] | 408 | slave->setControllableEntity(0); |
---|
[9625] | 409 | |
---|
[9663] | 410 | // set a new master within the formation |
---|
| 411 | orxonox_cast<FormationController*>(this->getController())->setNewMasterWithinFormation(orxonox_cast<FormationController*>(slave)); |
---|
[9625] | 412 | |
---|
[9663] | 413 | // start to control a slave |
---|
| 414 | this->getPlayer()->startControl(entity); |
---|
| 415 | } |
---|
| 416 | else |
---|
| 417 | { |
---|
| 418 | this->getPlayer()->stopControl(); |
---|
| 419 | } |
---|
[9625] | 420 | |
---|
[9663] | 421 | } |
---|
| 422 | else |
---|
| 423 | { |
---|
| 424 | this->getPlayer()->stopControl(); |
---|
| 425 | } |
---|
[9625] | 426 | } |
---|
[2896] | 427 | if (GameMode::isMaster()) |
---|
[3087] | 428 | { |
---|
| 429 | // this->deathEffect(); |
---|
| 430 | this->goWithStyle(); |
---|
| 431 | } |
---|
[2826] | 432 | } |
---|
[2662] | 433 | } |
---|
[3087] | 434 | void Pawn::goWithStyle() |
---|
| 435 | { |
---|
| 436 | this->bAlive_ = false; |
---|
| 437 | this->setDestroyWhenPlayerLeft(false); |
---|
[2072] | 438 | |
---|
[9949] | 439 | BigExplosion* chunk = new BigExplosion(this->getContext()); |
---|
[3087] | 440 | chunk->setPosition(this->getPosition()); |
---|
[9949] | 441 | chunk->setVelocity(this->getVelocity()); |
---|
[3087] | 442 | |
---|
[9947] | 443 | this->explosionSound_->setPosition(this->getPosition()); |
---|
| 444 | this->explosionSound_->play(); |
---|
[3087] | 445 | } |
---|
[2662] | 446 | void Pawn::deatheffect() |
---|
| 447 | { |
---|
[2072] | 448 | // play death effect |
---|
[2662] | 449 | { |
---|
[9667] | 450 | ParticleSpawner* effect = new ParticleSpawner(this->getContext()); |
---|
[2662] | 451 | effect->setPosition(this->getPosition()); |
---|
| 452 | effect->setOrientation(this->getOrientation()); |
---|
| 453 | effect->setDestroyAfterLife(true); |
---|
| 454 | effect->setSource("Orxonox/explosion2b"); |
---|
| 455 | effect->setLifetime(4.0f); |
---|
| 456 | } |
---|
| 457 | { |
---|
[9667] | 458 | ParticleSpawner* effect = new ParticleSpawner(this->getContext()); |
---|
[2662] | 459 | effect->setPosition(this->getPosition()); |
---|
| 460 | effect->setOrientation(this->getOrientation()); |
---|
| 461 | effect->setDestroyAfterLife(true); |
---|
| 462 | effect->setSource("Orxonox/smoke6"); |
---|
| 463 | effect->setLifetime(4.0f); |
---|
| 464 | } |
---|
| 465 | { |
---|
[9667] | 466 | ParticleSpawner* effect = new ParticleSpawner(this->getContext()); |
---|
[2662] | 467 | effect->setPosition(this->getPosition()); |
---|
| 468 | effect->setOrientation(this->getOrientation()); |
---|
| 469 | effect->setDestroyAfterLife(true); |
---|
| 470 | effect->setSource("Orxonox/sparks"); |
---|
| 471 | effect->setLifetime(4.0f); |
---|
| 472 | } |
---|
| 473 | for (unsigned int i = 0; i < this->numexplosionchunks_; ++i) |
---|
| 474 | { |
---|
[9667] | 475 | ExplosionChunk* chunk = new ExplosionChunk(this->getContext()); |
---|
[2662] | 476 | chunk->setPosition(this->getPosition()); |
---|
| 477 | } |
---|
[2072] | 478 | } |
---|
| 479 | |
---|
[6417] | 480 | void Pawn::fired(unsigned int firemode) |
---|
[2098] | 481 | { |
---|
[6417] | 482 | if (this->weaponSystem_) |
---|
| 483 | this->weaponSystem_->fire(firemode); |
---|
[2098] | 484 | } |
---|
| 485 | |
---|
[3053] | 486 | void Pawn::reload() |
---|
| 487 | { |
---|
| 488 | this->bReload_ = true; |
---|
| 489 | } |
---|
| 490 | |
---|
[2072] | 491 | void Pawn::postSpawn() |
---|
| 492 | { |
---|
| 493 | this->setHealth(this->initialHealth_); |
---|
[2896] | 494 | if (GameMode::isMaster()) |
---|
[2662] | 495 | this->spawneffect(); |
---|
[2072] | 496 | } |
---|
[2662] | 497 | |
---|
[2893] | 498 | /* WeaponSystem: |
---|
| 499 | * functions load Slot, Set, Pack from XML and make sure all parent-pointers are set. |
---|
| 500 | * with setWeaponPack you can not just load a Pack from XML but if a Pack already exists anywhere, you can attach it. |
---|
| 501 | * --> e.g. Pickup-Items |
---|
| 502 | */ |
---|
[3053] | 503 | void Pawn::addWeaponSlot(WeaponSlot * wSlot) |
---|
[2662] | 504 | { |
---|
| 505 | this->attach(wSlot); |
---|
| 506 | if (this->weaponSystem_) |
---|
[3053] | 507 | this->weaponSystem_->addWeaponSlot(wSlot); |
---|
[2662] | 508 | } |
---|
| 509 | |
---|
| 510 | WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const |
---|
| 511 | { |
---|
| 512 | if (this->weaponSystem_) |
---|
[3053] | 513 | return this->weaponSystem_->getWeaponSlot(index); |
---|
[2662] | 514 | else |
---|
| 515 | return 0; |
---|
| 516 | } |
---|
| 517 | |
---|
[3053] | 518 | void Pawn::addWeaponSet(WeaponSet * wSet) |
---|
[2662] | 519 | { |
---|
| 520 | if (this->weaponSystem_) |
---|
[3053] | 521 | this->weaponSystem_->addWeaponSet(wSet); |
---|
[2662] | 522 | } |
---|
| 523 | |
---|
[3053] | 524 | WeaponSet * Pawn::getWeaponSet(unsigned int index) const |
---|
[2662] | 525 | { |
---|
| 526 | if (this->weaponSystem_) |
---|
[3053] | 527 | return this->weaponSystem_->getWeaponSet(index); |
---|
[2662] | 528 | else |
---|
| 529 | return 0; |
---|
| 530 | } |
---|
| 531 | |
---|
[3053] | 532 | void Pawn::addWeaponPack(WeaponPack * wPack) |
---|
[2662] | 533 | { |
---|
| 534 | if (this->weaponSystem_) |
---|
[7163] | 535 | { |
---|
[3053] | 536 | this->weaponSystem_->addWeaponPack(wPack); |
---|
[7163] | 537 | this->addedWeaponPack(wPack); |
---|
| 538 | } |
---|
[2662] | 539 | } |
---|
| 540 | |
---|
[6417] | 541 | void Pawn::addWeaponPackXML(WeaponPack * wPack) |
---|
| 542 | { |
---|
| 543 | if (this->weaponSystem_) |
---|
[7163] | 544 | { |
---|
[6417] | 545 | if (!this->weaponSystem_->addWeaponPack(wPack)) |
---|
| 546 | wPack->destroy(); |
---|
[7163] | 547 | else |
---|
| 548 | this->addedWeaponPack(wPack); |
---|
| 549 | } |
---|
[6417] | 550 | } |
---|
| 551 | |
---|
[3053] | 552 | WeaponPack * Pawn::getWeaponPack(unsigned int index) const |
---|
[2662] | 553 | { |
---|
| 554 | if (this->weaponSystem_) |
---|
[3053] | 555 | return this->weaponSystem_->getWeaponPack(index); |
---|
[2662] | 556 | else |
---|
| 557 | return 0; |
---|
| 558 | } |
---|
| 559 | |
---|
[3089] | 560 | //Tell the Map (RadarViewable), if this is a playership |
---|
| 561 | void Pawn::startLocalHumanControl() |
---|
| 562 | { |
---|
| 563 | // SUPER(ControllableEntity, changedPlayer()); |
---|
| 564 | ControllableEntity::startLocalHumanControl(); |
---|
| 565 | this->isHumanShip_ = true; |
---|
| 566 | } |
---|
[8891] | 567 | |
---|
| 568 | void Pawn::changedVisibility(void) |
---|
| 569 | { |
---|
| 570 | SUPER(Pawn, changedVisibility); |
---|
[9254] | 571 | |
---|
| 572 | // enable proper radarviewability when the visibility is changed |
---|
| 573 | this->RadarViewable::settingsChanged(); |
---|
[8891] | 574 | } |
---|
| 575 | |
---|
[9625] | 576 | |
---|
| 577 | // A function to check if this pawn's controller is the master of any formationcontroller |
---|
| 578 | bool Pawn::hasSlaves() |
---|
| 579 | { |
---|
[9663] | 580 | for (ObjectList<FormationController>::iterator it = |
---|
| 581 | ObjectList<FormationController>::begin(); |
---|
| 582 | it != ObjectList<FormationController>::end(); ++it ) |
---|
| 583 | { |
---|
| 584 | // checks if the pawn's controller has a slave |
---|
| 585 | if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController()) |
---|
| 586 | return true; |
---|
| 587 | } |
---|
| 588 | return false; |
---|
[9625] | 589 | } |
---|
| 590 | |
---|
| 591 | // A function that returns a slave of the pawn's controller |
---|
| 592 | Controller* Pawn::getSlave(){ |
---|
[9663] | 593 | for (ObjectList<FormationController>::iterator it = |
---|
| 594 | ObjectList<FormationController>::begin(); |
---|
| 595 | it != ObjectList<FormationController>::end(); ++it ) |
---|
| 596 | { |
---|
| 597 | if (this->hasHumanController() && it->getMaster() == this->getPlayer()->getController()) |
---|
| 598 | return it->getController(); |
---|
| 599 | } |
---|
| 600 | return 0; |
---|
[9625] | 601 | } |
---|
| 602 | |
---|
| 603 | |
---|
[9939] | 604 | void Pawn::setExplosionSound(const std::string &explosionSound) |
---|
| 605 | { |
---|
| 606 | if(explosionSound_ ) |
---|
| 607 | explosionSound_->setSource(explosionSound); |
---|
| 608 | else |
---|
| 609 | assert(0); // This should never happen, because soundpointer is only available on master |
---|
| 610 | } |
---|
[9625] | 611 | |
---|
[9939] | 612 | const std::string& Pawn::getExplosionSound() |
---|
| 613 | { |
---|
| 614 | if( explosionSound_ ) |
---|
| 615 | return explosionSound_->getSource(); |
---|
| 616 | else |
---|
| 617 | assert(0); |
---|
| 618 | return BLANKSTRING; |
---|
| 619 | } |
---|
| 620 | |
---|
[9997] | 621 | // WIP function that (once I get it working) determines to which attached entity a collisionshape belongs. |
---|
| 622 | // Shame that this doesn't seem to work as intended. It behaves differently (different number of childshapes) every reload. D: |
---|
| 623 | int Pawn::isMyCollisionShape(const btCollisionShape* cs) |
---|
| 624 | { |
---|
| 625 | // This entities WECS |
---|
| 626 | WorldEntityCollisionShape* ownWECS = this->getWorldEntityCollisionShape(); |
---|
[9939] | 627 | |
---|
[9997] | 628 | // e.g. "Box 4: Searching for CS 0x1ad49200" |
---|
[10001] | 629 | orxout() << this->getRadarName() << ": Searching for btCS* " << cs << endl; |
---|
[9997] | 630 | // e.g. "Box 4 is WorldEntityCollisionShape 0x126dd060" |
---|
[10001] | 631 | orxout() << " " << this->getRadarName() << " is WorldEntityCollisionShape* " << ownWECS << endl; |
---|
| 632 | // e.g. "Box 4 is btCollisionShape 0x126dd060" |
---|
| 633 | orxout() << " " << this->getRadarName() << " is btCollisionShape* " << ownWECS->getCollisionShape() << endl; |
---|
[9997] | 634 | // e.g. "Box 4 is objectID 943" |
---|
| 635 | orxout() << " " << this->getRadarName() << " is objectID " << this->getObjectID() << endl; |
---|
| 636 | |
---|
| 637 | // print child shapes of this WECS |
---|
[10001] | 638 | // printChildShapes(ownWECS, 2, 0); |
---|
[10002] | 639 | printBtChildShapes((btCompoundShape*)(ownWECS->getCollisionShape()), 2, 0); |
---|
| 640 | // printChildShapeMap(ownWECS->getShapesMap()); |
---|
[9997] | 641 | |
---|
[10001] | 642 | |
---|
[9997] | 643 | // end |
---|
| 644 | orxout() << " " << this->getRadarName() << ": no matching CS found." << endl; |
---|
| 645 | return -1; |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | void Pawn::printChildShapes(CompoundCollisionShape* cs, int indent, int subshape) |
---|
| 649 | { |
---|
[10001] | 650 | for (int i=0; i < cs->getNumChildShapes(); i++) |
---|
| 651 | { |
---|
| 652 | orxout() << "" << endl; |
---|
| 653 | } |
---|
| 654 | /* |
---|
[9997] | 655 | // e.g. " Childshape 1 (WECS 0x126dc8c0) has 2 childshapes:" |
---|
[10001] | 656 | printSpaces(indent); orxout() << "Childshape " << subshape << " (CS* " << cs << ") has " << cs->getNumChildShapes() << " childshapes:" << endl; |
---|
[9997] | 657 | |
---|
[10001] | 658 | // e.g. "Box 4 is WorldEntityCollisionShape 0x126dd060" |
---|
| 659 | printSpaces(indent); orxout() << "Childshape " << subshape << " is btCollisionShape* " << cs->getCollisionShape() << endl; |
---|
| 660 | |
---|
[9997] | 661 | for (int i=0; i < cs->getNumChildShapes(); i++) |
---|
| 662 | { |
---|
[10001] | 663 | printSpaces(indent+2); orxout() << "- " << i << " - - -" << endl; |
---|
| 664 | printSpaces(indent+2); orxout() << "This Shape is a "; |
---|
| 665 | if (orxonox_cast<WorldEntityCollisionShape*>(cs->getAttachedShape(i))) |
---|
| 666 | orxout() << "WECS "; |
---|
| 667 | if (orxonox_cast<CompoundCollisionShape*>(cs->getAttachedShape(i))) |
---|
| 668 | orxout() << "CCS "; |
---|
| 669 | if (orxonox_cast<CollisionShape*>(cs->getAttachedShape(i))) |
---|
| 670 | orxout() << "CS "; |
---|
| 671 | orxout() << endl; |
---|
| 672 | |
---|
[9997] | 673 | // For each childshape, print: |
---|
[10001] | 674 | |
---|
| 675 | // parentID of the CollisionShape |
---|
| 676 | printSpaces(indent+2); orxout() << "ParentID: " << cs->getAttachedShape(i)->getObjectID() << endl; |
---|
| 677 | |
---|
| 678 | // parentID of the CollisionShape |
---|
| 679 | printSpaces(indent+2); orxout() << "ParentID: " << cs->getAttachedShape(i)->getParentID() << endl; |
---|
| 680 | |
---|
| 681 | // parent of the CollisionShape |
---|
| 682 | printSpaces(indent+2); orxout() << "ParentCCS*: " << cs->getAttachedShape(i)->getParent() << endl; |
---|
| 683 | |
---|
[9997] | 684 | // pointer to the btCollisionShape |
---|
[10001] | 685 | printSpaces(indent+2); orxout() << "btCollisionShape*: " << cs->getAttachedShape(i)->getCollisionShape() << endl; |
---|
[9997] | 686 | |
---|
| 687 | // pointer to the CollisionShape |
---|
[10001] | 688 | printSpaces(indent+2); orxout() << "CollisionShape*: " << cs->getAttachedShape(i) << endl; |
---|
[9997] | 689 | |
---|
[10001] | 690 | if (cs->getAttachedShape(i)->getCollisionShape() != NULL) |
---|
| 691 | { |
---|
| 692 | // pointer to the user of the btCollisionShape |
---|
| 693 | printSpaces(indent+2); orxout() << "bt: getUserPointer: " << cs->getAttachedShape(i)->getCollisionShape()->getUserPointer() << endl; |
---|
[9997] | 694 | |
---|
[10001] | 695 | // |
---|
| 696 | printSpaces(indent+2); orxout() << "bt: isCompound: " << cs->getAttachedShape(i)->getCollisionShape()->isCompound() << endl; |
---|
| 697 | } |
---|
| 698 | |
---|
[9997] | 699 | // if the childshape is a CompoundCollisionShape, print its children. |
---|
| 700 | if (orxonox_cast<CompoundCollisionShape*>(cs->getAttachedShape(i))) |
---|
| 701 | { |
---|
| 702 | printChildShapes((CompoundCollisionShape*)(cs->getAttachedShape(i)), indent+2, i); |
---|
| 703 | } |
---|
[10002] | 704 | |
---|
| 705 | }*/ |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | void Pawn::printBtChildShapes(btCompoundShape* cs, int indent, int subshape) |
---|
| 709 | { |
---|
| 710 | // e.g. " Childshape 1 (WECS 0x126dc8c0) has 2 childshapes:" |
---|
| 711 | printSpaces(indent); orxout() << "Childshape " << subshape << " (btCS* " << cs << ") has " << cs->getNumChildShapes() << " childshapes:" << endl; |
---|
| 712 | |
---|
| 713 | for (int i=0; i < cs->getNumChildShapes(); i++) |
---|
| 714 | { |
---|
| 715 | printSpaces(indent+2); orxout() << "- " << i << " - - -" << endl; |
---|
| 716 | |
---|
| 717 | // For each childshape, print: |
---|
| 718 | |
---|
| 719 | // pointer to the btCollisionShape |
---|
| 720 | printSpaces(indent+2); orxout() << "btCollisionShape*: " << cs->getChildShape(i) << endl; |
---|
| 721 | |
---|
| 722 | // if the childshape is a CompoundCollisionShape, print its children. |
---|
| 723 | if (cs->getChildShape(i)->isCompound()) |
---|
| 724 | { |
---|
| 725 | printSpaces(indent+2); orxout() << "This shape is compound." << endl; |
---|
| 726 | printBtChildShapes((btCompoundShape*)(cs->getChildShape(i)), indent+2, i); |
---|
| 727 | } |
---|
| 728 | |
---|
[9997] | 729 | } |
---|
| 730 | } |
---|
| 731 | |
---|
[10001] | 732 | void Pawn::printChildShapeMap(std::map<CollisionShape*, btCollisionShape*> map) |
---|
| 733 | { |
---|
| 734 | orxout() << endl; |
---|
| 735 | } |
---|
| 736 | |
---|
[10002] | 737 | void Pawn::printSpaces(int num) |
---|
[9997] | 738 | { |
---|
[10002] | 739 | for(int i=0; i<num; i++) |
---|
[9997] | 740 | orxout() << " "; |
---|
| 741 | } |
---|
[2072] | 742 | } |
---|