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