[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" |
---|
[9869] | 24 | #include "sound/resource_sound_buffer.h" |
---|
[10013] | 25 | #include "playable.h" |
---|
[3573] | 26 | |
---|
[8362] | 27 | #include "debug.h" |
---|
[3573] | 28 | |
---|
[9869] | 29 | ObjectListDefinition(Projectile); |
---|
[3573] | 30 | |
---|
[3578] | 31 | /** |
---|
[4836] | 32 | * standard constructor |
---|
[3578] | 33 | */ |
---|
[4932] | 34 | Projectile::Projectile () : WorldEntity() |
---|
[3573] | 35 | { |
---|
[9869] | 36 | this->registerObject(this, Projectile::_objectList); |
---|
[4597] | 37 | |
---|
[4890] | 38 | this->lifeCycle = 0.0; |
---|
[5063] | 39 | this->lifeSpan = 1.0f; /* sec */ |
---|
[6078] | 40 | this->target = NULL; |
---|
[5769] | 41 | this->removeNode(); |
---|
[7084] | 42 | |
---|
[8190] | 43 | /* character attributes */ |
---|
| 44 | this->setHealth(1.0f); |
---|
[9235] | 45 | this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points |
---|
[10013] | 46 | this->subscribeReaction( CoRe::CREngine::CR_PHYSICS_FULL_WALK, Playable::staticClassID()); |
---|
[8190] | 47 | |
---|
[9656] | 48 | //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[3573] | 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
[3578] | 52 | /** |
---|
[4836] | 53 | * standard deconstructor |
---|
[3578] | 54 | */ |
---|
[4597] | 55 | Projectile::~Projectile () |
---|
[3573] | 56 | { |
---|
[4597] | 57 | /* |
---|
| 58 | do not delete the test projectModel, since it is pnode |
---|
| 59 | and will be cleaned out by world |
---|
[3629] | 60 | */ |
---|
| 61 | //delete this->projectileModel; |
---|
[3573] | 62 | } |
---|
| 63 | |
---|
[3578] | 64 | |
---|
[7221] | 65 | void Projectile::loadExplosionSound(const std::string& explosionSound) |
---|
[7084] | 66 | { |
---|
[9869] | 67 | if (!explosionSound.empty()) |
---|
| 68 | this->explosionBuffer = OrxSound::ResourceSoundBuffer(explosionSound); |
---|
[7084] | 69 | else |
---|
[9869] | 70 | this->explosionBuffer = OrxSound::SoundBuffer(); |
---|
[7084] | 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
[7221] | 74 | void Projectile::loadEngineSound(const std::string& engineSound) |
---|
[7084] | 75 | { |
---|
[9869] | 76 | if (!engineSound.empty()) |
---|
| 77 | this->engineBuffer = OrxSound::ResourceSoundBuffer(engineSound); |
---|
[7084] | 78 | else |
---|
[9869] | 79 | this->engineBuffer = OrxSound::SoundBuffer(); |
---|
[7084] | 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
[6431] | 83 | void Projectile::setMinEnergy(float energyMin) |
---|
[4948] | 84 | { |
---|
| 85 | this->energyMin = energyMin; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
[3578] | 89 | /** |
---|
[4836] | 90 | * this sets the flight direction of the projectile |
---|
| 91 | * @param directin in which to flight |
---|
[3632] | 92 | |
---|
| 93 | this function will calculate a vector out of this to be used in the |
---|
| 94 | tick function |
---|
| 95 | */ |
---|
[4927] | 96 | void Projectile::setFlightDirection(const Quaternion& flightDirection) |
---|
[3632] | 97 | { |
---|
| 98 | Vector v(1, 0, 0); |
---|
[4890] | 99 | this->flightDirection = flightDirection.apply(v); |
---|
| 100 | this->flightDirection.normalize(); |
---|
[3632] | 101 | } |
---|
| 102 | |
---|
| 103 | /** |
---|
[4836] | 104 | * sets the velocity vector to a spec speed |
---|
| 105 | * @param velocity: vector of the velocity |
---|
[4464] | 106 | */ |
---|
| 107 | void Projectile::setVelocity(const Vector &velocity) |
---|
| 108 | { |
---|
[4955] | 109 | //Vector offsetVel = |
---|
| 110 | this->velocity = velocity; |
---|
[9869] | 111 | // offsetVel.normalize(); |
---|
[4955] | 112 | //this->velocity += (offsetVel * 50.0); |
---|
[4464] | 113 | } |
---|
| 114 | |
---|
[5766] | 115 | |
---|
| 116 | |
---|
| 117 | void Projectile::setTarget(PNode* target) |
---|
| 118 | { |
---|
[6078] | 119 | if (this->target == NULL) |
---|
[9869] | 120 | this->target = new PNode(target, PNODE_REPARENT_ON_PARENTS_REMOVE | PNODE_REPARENT_TO_NULL | PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[6078] | 121 | else |
---|
| 122 | this->target->setParent(target); |
---|
[5766] | 123 | } |
---|
| 124 | |
---|
| 125 | |
---|
[4464] | 126 | /** |
---|
[4927] | 127 | * signal tick, time dependent things will be handled here |
---|
[6056] | 128 | * @param dt since last tick |
---|
[3578] | 129 | */ |
---|
[6056] | 130 | void Projectile::tick (float dt) |
---|
[3632] | 131 | { |
---|
[6056] | 132 | Vector v = this->velocity * (dt); |
---|
[3686] | 133 | this->shiftCoor(v); |
---|
[3683] | 134 | |
---|
[6056] | 135 | if (this->tickLifeCycle(dt)) |
---|
[9235] | 136 | this->destroy( NULL ); |
---|
[3632] | 137 | } |
---|
[3573] | 138 | |
---|
| 139 | |
---|
[3578] | 140 | /** |
---|
[4836] | 141 | * the function gets called, when the projectile is destroyed |
---|
[3578] | 142 | */ |
---|
[9235] | 143 | void Projectile::destroy (WorldEntity* killer) |
---|
[7084] | 144 | { |
---|
[9869] | 145 | if (this->explosionBuffer.loaded()) |
---|
[7084] | 146 | this->soundSource.play(this->explosionBuffer); |
---|
| 147 | } |
---|
[3573] | 148 | |
---|