| [4593] | 1 | /* | 
|---|
| [3708] | 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
 | 3 |  | 
|---|
 | 4 |    Copyright (C) 2004 orx | 
|---|
 | 5 |  | 
|---|
 | 6 |    This program is free software; you can redistribute it and/or modify | 
|---|
 | 7 |    it under the terms of the GNU General Public License as published by | 
|---|
 | 8 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
 | 9 |    any later version. | 
|---|
 | 10 |  | 
|---|
 | 11 |    ### File Specific | 
|---|
 | 12 |    main-programmer: Patrick Boenzli | 
|---|
| [5443] | 13 |    co-programmer: Benjamin Grauer | 
|---|
 | 14 |  | 
|---|
| [3708] | 15 | */ | 
|---|
| [5357] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON | 
|---|
| [3708] | 17 |  | 
|---|
| [5456] | 18 | #include "rocket.h" | 
|---|
| [3708] | 19 |  | 
|---|
| [5443] | 20 | #include "state.h" | 
|---|
| [5444] | 21 | #include "class_list.h" | 
|---|
| [5054] | 22 |  | 
|---|
| [6822] | 23 | #include "dot_emitter.h" | 
|---|
| [6621] | 24 | #include "sprite_particles.h" | 
|---|
| [5443] | 25 |  | 
|---|
 | 26 |  | 
|---|
| [3708] | 27 | using namespace std; | 
|---|
 | 28 |  | 
|---|
| [5456] | 29 | CREATE_FAST_FACTORY_STATIC(Rocket, CL_ROCKET); | 
|---|
| [3708] | 30 |  | 
|---|
 | 31 | /** | 
|---|
| [4836] | 32 |  *  standard constructor | 
|---|
| [3708] | 33 | */ | 
|---|
| [5456] | 34 | Rocket::Rocket () : Projectile() | 
|---|
| [3755] | 35 | { | 
|---|
| [6628] | 36 |   this->setClassID(CL_ROCKET, "Rocket"); | 
|---|
| [4597] | 37 |  | 
|---|
| [4948] | 38 |   float modelSize = .3; | 
|---|
| [5499] | 39 |   this->loadModel("models/projectiles/orx-rocket.obj", .3); | 
|---|
| [4948] | 40 |  | 
|---|
| [6431] | 41 |   this->setMinEnergy(1); | 
|---|
| [6700] | 42 |   this->setHealthMax(10); | 
|---|
| [5819] | 43 |   this->lifeSpan = 5; | 
|---|
| [5443] | 44 |  | 
|---|
| [6825] | 45 |   this->emitter = new DotEmitter(100, 5, M_2_PI); | 
|---|
| [5443] | 46 |   this->emitter->setParent(this); | 
|---|
| [5449] | 47 |   this->emitter->setSpread(M_PI, M_PI); | 
|---|
| [3755] | 48 | } | 
|---|
| [3708] | 49 |  | 
|---|
 | 50 |  | 
|---|
 | 51 | /** | 
|---|
| [4836] | 52 |  *  standard deconstructor | 
|---|
| [3708] | 53 | */ | 
|---|
| [5456] | 54 | Rocket::~Rocket () | 
|---|
| [3708] | 55 | { | 
|---|
| [5446] | 56 |   // delete this->emitter; | 
|---|
| [5444] | 57 |  | 
|---|
| [5445] | 58 |   /* this is normaly done by World.cc by deleting the ParticleEngine */ | 
|---|
| [6627] | 59 |   if (Rocket::trailParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1) | 
|---|
| [5447] | 60 |   { | 
|---|
| [6628] | 61 | /*    if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM)) | 
|---|
 | 62 |       delete Rocket::trailParticles;*/ | 
|---|
| [5456] | 63 |     Rocket::trailParticles = NULL; | 
|---|
| [5447] | 64 |   } | 
|---|
| [6627] | 65 |   if (Rocket::explosionParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1) | 
|---|
| [5444] | 66 |   { | 
|---|
| [6628] | 67 | /*    if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM)) | 
|---|
 | 68 |       delete Rocket::explosionParticles;*/ | 
|---|
| [5456] | 69 |     Rocket::explosionParticles = NULL; | 
|---|
| [5444] | 70 |   } | 
|---|
| [5445] | 71 |  | 
|---|
| [3708] | 72 | } | 
|---|
 | 73 |  | 
|---|
| [6622] | 74 | SpriteParticles* Rocket::trailParticles = NULL; | 
|---|
 | 75 | SpriteParticles* Rocket::explosionParticles = NULL; | 
|---|
| [5443] | 76 |  | 
|---|
| [5456] | 77 | void Rocket::activate() | 
|---|
| [5443] | 78 | { | 
|---|
| [5456] | 79 |   if (unlikely(Rocket::trailParticles == NULL)) | 
|---|
| [5447] | 80 |   { | 
|---|
| [6621] | 81 |     Rocket::trailParticles = new SpriteParticles(2000); | 
|---|
| [5456] | 82 |     Rocket::trailParticles->setName("RocketTrailParticles"); | 
|---|
| [5471] | 83 |     Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png"); | 
|---|
 | 84 |     Rocket::trailParticles->setLifeSpan(1.0, .3); | 
|---|
| [5456] | 85 |     Rocket::trailParticles->setRadius(0.0, .5); | 
|---|
| [5472] | 86 |     Rocket::trailParticles->setRadius(0.2, 2.0); | 
|---|
 | 87 |     Rocket::trailParticles->setRadius(.5, .8); | 
|---|
| [5471] | 88 |     Rocket::trailParticles->setRadius(1.0, .8); | 
|---|
| [5456] | 89 |     Rocket::trailParticles->setColor(0.0, 1,0,0,.7); | 
|---|
| [5472] | 90 |     Rocket::trailParticles->setColor(0.2, .8,.8,0,.5); | 
|---|
 | 91 |     Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8); | 
|---|
| [5471] | 92 |     Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0); | 
|---|
| [5447] | 93 |   } | 
|---|
| [5456] | 94 |   if (unlikely(Rocket::explosionParticles == NULL)) | 
|---|
| [5443] | 95 |   { | 
|---|
| [6621] | 96 |     Rocket::explosionParticles = new SpriteParticles(200); | 
|---|
| [5456] | 97 |     Rocket::explosionParticles->setName("RocketExplosionParticles"); | 
|---|
| [5471] | 98 |     Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png"); | 
|---|
| [5693] | 99 |     Rocket::explosionParticles->setLifeSpan(.5, .3); | 
|---|
| [5456] | 100 |     Rocket::explosionParticles->setRadius(0.0, 10); | 
|---|
| [5693] | 101 |     Rocket::explosionParticles->setRadius(.5, 15.0); | 
|---|
 | 102 |     Rocket::explosionParticles->setRadius(1.0, 10.0); | 
|---|
| [5465] | 103 |     Rocket::explosionParticles->setColor(0.0, 0,1,0,1); | 
|---|
 | 104 |     Rocket::explosionParticles->setColor(0.5, .8,.8,0,.8); | 
|---|
 | 105 |     Rocket::explosionParticles->setColor(0.8, .8,.8,.3,.8); | 
|---|
| [5456] | 106 |     Rocket::explosionParticles->setColor(1.0, 1,1,1,.0); | 
|---|
| [5443] | 107 |   } | 
|---|
 | 108 |  | 
|---|
| [6619] | 109 |   this->emitter->setSystem(Rocket::trailParticles); | 
|---|
| [5447] | 110 |  | 
|---|
| [5769] | 111 |   this->updateNode(0); | 
|---|
| [5472] | 112 |   this->emitter->setEmissionRate(45.0); | 
|---|
| [5471] | 113 |   this->emitter->setEmissionVelocity(0.0); | 
|---|
| [5443] | 114 | } | 
|---|
 | 115 |  | 
|---|
 | 116 |  | 
|---|
| [5456] | 117 | void Rocket::deactivate() | 
|---|
| [5443] | 118 | { | 
|---|
| [6619] | 119 |   this->emitter->setSystem(NULL); | 
|---|
| [5447] | 120 |   this->lifeCycle = 0.0; | 
|---|
| [6142] | 121 |   this->toList(OM_NULL); | 
|---|
| [5443] | 122 |  | 
|---|
| [5447] | 123 | //  GarbageCollector::getInstance()->collect(this); | 
|---|
| [6142] | 124 |   this->toList(OM_DEAD); | 
|---|
| [5456] | 125 |   Rocket::fastFactory->kill(this); | 
|---|
| [5443] | 126 | } | 
|---|
 | 127 |  | 
|---|
 | 128 |  | 
|---|
| [5456] | 129 | void Rocket::collidesWith(WorldEntity* entity, const Vector& location) | 
|---|
| [5257] | 130 | { | 
|---|
| [6433] | 131 |   if (this->hitEntity != entity) | 
|---|
| [5447] | 132 |     this->destroy(); | 
|---|
 | 133 |   this->hitEntity = entity; | 
|---|
| [5257] | 134 | } | 
|---|
| [3708] | 135 |  | 
|---|
 | 136 | /** | 
|---|
| [4836] | 137 |  *  signal tick, time dependent things will be handled here | 
|---|
 | 138 |  * @param time since last tick | 
|---|
| [3708] | 139 | */ | 
|---|
| [6056] | 140 | void Rocket::tick (float dt) | 
|---|
| [3708] | 141 | { | 
|---|
| [4464] | 142 |   //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); | 
|---|
| [6056] | 143 |   Vector v = this->velocity * (dt); | 
|---|
| [3708] | 144 |   this->shiftCoor(v); | 
|---|
 | 145 |  | 
|---|
| [6056] | 146 |   if(this->tickLifeCycle(dt)) | 
|---|
 | 147 |     this->deactivate(); | 
|---|
| [3708] | 148 | } | 
|---|
 | 149 |  | 
|---|
 | 150 | /** | 
|---|
| [4836] | 151 |  *  the function gets called, when the projectile is destroyed | 
|---|
| [3708] | 152 | */ | 
|---|
| [5456] | 153 | void Rocket::destroy () | 
|---|
| [5257] | 154 | { | 
|---|
| [7086] | 155 |   Projectile::destroy(); | 
|---|
 | 156 |  | 
|---|
| [5456] | 157 |   PRINTF(5)("DESTROY Rocket\n"); | 
|---|
| [5448] | 158 |   this->lifeCycle = .95; //!< @todo calculate this usefully. | 
|---|
| [6619] | 159 |   this->emitter->setSystem(Rocket::explosionParticles); | 
|---|
| [3708] | 160 |  | 
|---|
| [5465] | 161 |   this->emitter->setEmissionRate(1000.0); | 
|---|
| [5447] | 162 |   this->emitter->setEmissionVelocity(50.0); | 
|---|
 | 163 | //  this->deactivate(); | 
|---|
| [3708] | 164 |  | 
|---|
| [5257] | 165 | } | 
|---|
 | 166 |  | 
|---|
 | 167 |  | 
|---|
| [5500] | 168 | void Rocket::draw () const | 
|---|
| [3708] | 169 | { | 
|---|
 | 170 |   glMatrixMode(GL_MODELVIEW); | 
|---|
 | 171 |   glPushMatrix(); | 
|---|
 | 172 |  | 
|---|
| [4593] | 173 |   float matrix[4][4]; | 
|---|
| [3708] | 174 |   glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); | 
|---|
 | 175 |   this->getAbsDir().matrix (matrix); | 
|---|
| [4593] | 176 |   glMultMatrixf((float*)matrix); | 
|---|
| [3755] | 177 |   glScalef(2.0, 2.0, 2.0); | 
|---|
| [5994] | 178 |   this->getModel()->draw(); | 
|---|
| [3708] | 179 |  | 
|---|
 | 180 |   glPopMatrix(); | 
|---|
 | 181 | } | 
|---|
 | 182 |  | 
|---|