[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" |
---|
[3683] | 22 | #include "weapon.h" |
---|
[3678] | 23 | #include "model.h" |
---|
[3573] | 24 | |
---|
[4941] | 25 | #include "garbage_collector.h" |
---|
| 26 | |
---|
[3573] | 27 | using namespace std; |
---|
| 28 | |
---|
| 29 | |
---|
[3578] | 30 | /** |
---|
[4836] | 31 | * standard constructor |
---|
[3578] | 32 | */ |
---|
[4932] | 33 | Projectile::Projectile () : WorldEntity() |
---|
[3573] | 34 | { |
---|
[4322] | 35 | this->setClassID(CL_PROJECTILE, "Projectile"); |
---|
[4597] | 36 | |
---|
[4890] | 37 | this->lifeCycle = 0.0; |
---|
[5063] | 38 | this->lifeSpan = 1.0f; /* sec */ |
---|
[6078] | 39 | this->target = NULL; |
---|
[5769] | 40 | this->removeNode(); |
---|
[3573] | 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
[3578] | 44 | /** |
---|
[4836] | 45 | * standard deconstructor |
---|
[3578] | 46 | */ |
---|
[4597] | 47 | Projectile::~Projectile () |
---|
[3573] | 48 | { |
---|
[4597] | 49 | /* |
---|
| 50 | do not delete the test projectModel, since it is pnode |
---|
| 51 | and will be cleaned out by world |
---|
[3629] | 52 | */ |
---|
| 53 | //delete this->projectileModel; |
---|
[3573] | 54 | } |
---|
| 55 | |
---|
[3578] | 56 | |
---|
[4948] | 57 | void Projectile::setEnergies(float energyMin, float energyMax) |
---|
| 58 | { |
---|
| 59 | this->energyMin = energyMin; |
---|
| 60 | if (energyMax <= energyMin) |
---|
| 61 | { |
---|
| 62 | this->bChargeable = false; |
---|
| 63 | this->energyMax = energyMin; |
---|
| 64 | } |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | this->bChargeable = true; |
---|
| 68 | this->energyMax = energyMax; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
[3578] | 73 | /** |
---|
[4836] | 74 | * this sets the flight direction of the projectile |
---|
| 75 | * @param directin in which to flight |
---|
[3632] | 76 | |
---|
| 77 | this function will calculate a vector out of this to be used in the |
---|
| 78 | tick function |
---|
| 79 | */ |
---|
[4927] | 80 | void Projectile::setFlightDirection(const Quaternion& flightDirection) |
---|
[3632] | 81 | { |
---|
| 82 | Vector v(1, 0, 0); |
---|
[4890] | 83 | this->flightDirection = flightDirection.apply(v); |
---|
| 84 | this->flightDirection.normalize(); |
---|
[3632] | 85 | } |
---|
| 86 | |
---|
| 87 | /** |
---|
[4836] | 88 | * sets the velocity vector to a spec speed |
---|
| 89 | * @param velocity: vector of the velocity |
---|
[4464] | 90 | */ |
---|
| 91 | void Projectile::setVelocity(const Vector &velocity) |
---|
| 92 | { |
---|
[4955] | 93 | //Vector offsetVel = |
---|
| 94 | this->velocity = velocity; |
---|
| 95 | // offsetVel.normalize(); |
---|
| 96 | //this->velocity += (offsetVel * 50.0); |
---|
[4464] | 97 | } |
---|
| 98 | |
---|
[5766] | 99 | |
---|
| 100 | |
---|
| 101 | void Projectile::setTarget(PNode* target) |
---|
| 102 | { |
---|
[6078] | 103 | if (this->target == NULL) |
---|
| 104 | this->target = new PNode(target, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_ON_PARENTS_REMOVE); |
---|
| 105 | else |
---|
| 106 | this->target->setParent(target); |
---|
[5766] | 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
[4464] | 110 | /** |
---|
[4927] | 111 | * signal tick, time dependent things will be handled here |
---|
[6056] | 112 | * @param dt since last tick |
---|
[3578] | 113 | */ |
---|
[6056] | 114 | void Projectile::tick (float dt) |
---|
[3632] | 115 | { |
---|
[6056] | 116 | Vector v = this->velocity * (dt); |
---|
[3686] | 117 | this->shiftCoor(v); |
---|
[3683] | 118 | |
---|
[6056] | 119 | if (this->tickLifeCycle(dt)) |
---|
| 120 | this->destroy(); |
---|
[3632] | 121 | } |
---|
[3573] | 122 | |
---|
| 123 | |
---|
[3578] | 124 | /** |
---|
[4836] | 125 | * the function gets called, when the projectile is destroyed |
---|
[3578] | 126 | */ |
---|
[4597] | 127 | void Projectile::destroy () |
---|
[3574] | 128 | {} |
---|
[3573] | 129 | |
---|