[3573] | 1 | |
---|
| 2 | |
---|
[4597] | 3 | /* |
---|
[3573] | 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
[4597] | 15 | co-programmer: |
---|
[3573] | 16 | */ |
---|
[5357] | 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3573] | 18 | |
---|
| 19 | #include "projectile.h" |
---|
[3618] | 20 | |
---|
[3573] | 21 | #include "world_entity.h" |
---|
[6434] | 22 | #include "world_entities/weapons/weapon.h" |
---|
[3678] | 23 | #include "model.h" |
---|
[7193] | 24 | #include "util/loading/resource_manager.h" |
---|
[3573] | 25 | |
---|
[8362] | 26 | #include "debug.h" |
---|
[3573] | 27 | |
---|
[9715] | 28 | ObjectListDefinition(Projectile); |
---|
[3573] | 29 | |
---|
[3578] | 30 | /** |
---|
[4836] | 31 | * standard constructor |
---|
[3578] | 32 | */ |
---|
[4932] | 33 | Projectile::Projectile () : WorldEntity() |
---|
[3573] | 34 | { |
---|
[9705] | 35 | this->registerObject(this, Projectile::_objectList); |
---|
[4597] | 36 | |
---|
[4890] | 37 | this->lifeCycle = 0.0; |
---|
[5063] | 38 | this->lifeSpan = 1.0f; /* sec */ |
---|
[6078] | 39 | this->target = NULL; |
---|
[5769] | 40 | this->removeNode(); |
---|
[7084] | 41 | |
---|
[8190] | 42 | /* character attributes */ |
---|
| 43 | this->setHealth(1.0f); |
---|
[9235] | 44 | this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points |
---|
[8190] | 45 | |
---|
[7084] | 46 | this->explosionBuffer = NULL; |
---|
| 47 | this->engineBuffer = NULL; |
---|
[9656] | 48 | |
---|
| 49 | //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[3573] | 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
[3578] | 53 | /** |
---|
[4836] | 54 | * standard deconstructor |
---|
[3578] | 55 | */ |
---|
[4597] | 56 | Projectile::~Projectile () |
---|
[3573] | 57 | { |
---|
[7084] | 58 | if (this->explosionBuffer != NULL) |
---|
| 59 | ResourceManager::getInstance()->unload(this->explosionBuffer); |
---|
| 60 | if (this->engineBuffer != NULL) |
---|
| 61 | ResourceManager::getInstance()->unload(this->engineBuffer); |
---|
[4597] | 62 | /* |
---|
| 63 | do not delete the test projectModel, since it is pnode |
---|
| 64 | and will be cleaned out by world |
---|
[3629] | 65 | */ |
---|
| 66 | //delete this->projectileModel; |
---|
[3573] | 67 | } |
---|
| 68 | |
---|
[3578] | 69 | |
---|
[7221] | 70 | void Projectile::loadExplosionSound(const std::string& explosionSound) |
---|
[7084] | 71 | { |
---|
| 72 | if (this->explosionBuffer != NULL) |
---|
| 73 | ResourceManager::getInstance()->unload(this->explosionBuffer); |
---|
| 74 | |
---|
[7221] | 75 | else if (!explosionSound.empty()) |
---|
[7084] | 76 | { |
---|
[7460] | 77 | this->explosionBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(explosionSound, WAV); |
---|
[7084] | 78 | if (this->explosionBuffer != NULL) |
---|
| 79 | { |
---|
[9406] | 80 | PRINTF(4)("Loaded sound %s to Pickup: %s.\n", explosionSound.c_str(), this->getCName()); |
---|
[7084] | 81 | } |
---|
| 82 | else |
---|
| 83 | { |
---|
[9406] | 84 | PRINTF(2)("Failed to load sound %s to explosion %s.\n.", explosionSound.c_str(), this->getCName()); |
---|
[7084] | 85 | } |
---|
| 86 | } |
---|
| 87 | else |
---|
| 88 | this->explosionBuffer = NULL; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
[7221] | 92 | void Projectile::loadEngineSound(const std::string& engineSound) |
---|
[7084] | 93 | { |
---|
| 94 | if (this->engineBuffer != NULL) |
---|
| 95 | ResourceManager::getInstance()->unload(this->engineBuffer); |
---|
| 96 | |
---|
[7221] | 97 | else if (!engineSound.empty()) |
---|
[7084] | 98 | { |
---|
[7460] | 99 | this->engineBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load(engineSound, WAV); |
---|
[7084] | 100 | if (this->engineBuffer != NULL) |
---|
| 101 | { |
---|
[9406] | 102 | PRINTF(4)("Loaded sound %s to Pickup: %s.\n", engineSound.c_str(), this->getCName()); |
---|
[7084] | 103 | } |
---|
| 104 | else |
---|
| 105 | { |
---|
[9406] | 106 | PRINTF(2)("Failed to load sound %s to engine %s.\n.", engineSound.c_str(), this->getCName()); |
---|
[7084] | 107 | } |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | this->engineBuffer = NULL; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
[6431] | 114 | void Projectile::setMinEnergy(float energyMin) |
---|
[4948] | 115 | { |
---|
| 116 | this->energyMin = energyMin; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
[3578] | 120 | /** |
---|
[4836] | 121 | * this sets the flight direction of the projectile |
---|
| 122 | * @param directin in which to flight |
---|
[3632] | 123 | |
---|
| 124 | this function will calculate a vector out of this to be used in the |
---|
| 125 | tick function |
---|
| 126 | */ |
---|
[4927] | 127 | void Projectile::setFlightDirection(const Quaternion& flightDirection) |
---|
[3632] | 128 | { |
---|
| 129 | Vector v(1, 0, 0); |
---|
[4890] | 130 | this->flightDirection = flightDirection.apply(v); |
---|
| 131 | this->flightDirection.normalize(); |
---|
[3632] | 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
[4836] | 135 | * sets the velocity vector to a spec speed |
---|
| 136 | * @param velocity: vector of the velocity |
---|
[4464] | 137 | */ |
---|
| 138 | void Projectile::setVelocity(const Vector &velocity) |
---|
| 139 | { |
---|
[4955] | 140 | //Vector offsetVel = |
---|
| 141 | this->velocity = velocity; |
---|
| 142 | // offsetVel.normalize(); |
---|
| 143 | //this->velocity += (offsetVel * 50.0); |
---|
[4464] | 144 | } |
---|
| 145 | |
---|
[5766] | 146 | |
---|
| 147 | |
---|
| 148 | void Projectile::setTarget(PNode* target) |
---|
| 149 | { |
---|
[6078] | 150 | if (this->target == NULL) |
---|
[9783] | 151 | this->target = new PNode(target, PNODE_REPARENT_ON_PARENTS_REMOVE | PNODE_REPARENT_TO_NULL | PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[6078] | 152 | else |
---|
| 153 | this->target->setParent(target); |
---|
[5766] | 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
[4464] | 157 | /** |
---|
[4927] | 158 | * signal tick, time dependent things will be handled here |
---|
[6056] | 159 | * @param dt since last tick |
---|
[3578] | 160 | */ |
---|
[6056] | 161 | void Projectile::tick (float dt) |
---|
[3632] | 162 | { |
---|
[6056] | 163 | Vector v = this->velocity * (dt); |
---|
[3686] | 164 | this->shiftCoor(v); |
---|
[3683] | 165 | |
---|
[6056] | 166 | if (this->tickLifeCycle(dt)) |
---|
[9235] | 167 | this->destroy( NULL ); |
---|
[3632] | 168 | } |
---|
[3573] | 169 | |
---|
| 170 | |
---|
[3578] | 171 | /** |
---|
[4836] | 172 | * the function gets called, when the projectile is destroyed |
---|
[3578] | 173 | */ |
---|
[9235] | 174 | void Projectile::destroy (WorldEntity* killer) |
---|
[7084] | 175 | { |
---|
| 176 | if (this->explosionBuffer != NULL) |
---|
| 177 | this->soundSource.play(this->explosionBuffer); |
---|
| 178 | } |
---|
[3573] | 179 | |
---|