| 1 | /* | 
|---|
| 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 | 
|---|
| 13 |    co-programmer: Benjamin Grauer | 
|---|
| 14 |  | 
|---|
| 15 | */ | 
|---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON | 
|---|
| 17 |  | 
|---|
| 18 | #include "rocket.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "fast_factory.h" | 
|---|
| 21 |  | 
|---|
| 22 | #include "state.h" | 
|---|
| 23 | #include "class_list.h" | 
|---|
| 24 |  | 
|---|
| 25 | #include "particle_emitter.h" | 
|---|
| 26 | #include "sprite_particles.h" | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | using namespace std; | 
|---|
| 30 |  | 
|---|
| 31 | CREATE_FAST_FACTORY_STATIC(Rocket, CL_ROCKET); | 
|---|
| 32 |  | 
|---|
| 33 | /** | 
|---|
| 34 |  *  standard constructor | 
|---|
| 35 | */ | 
|---|
| 36 | Rocket::Rocket () : Projectile() | 
|---|
| 37 | { | 
|---|
| 38 |   this->setClassID(CL_ROCKET, "Rocket"); | 
|---|
| 39 |  | 
|---|
| 40 |   float modelSize = .3; | 
|---|
| 41 |   this->loadModel("models/projectiles/orx-rocket.obj", .3); | 
|---|
| 42 |  | 
|---|
| 43 |   this->setMinEnergy(1); | 
|---|
| 44 |   this->setHealthMax(10); | 
|---|
| 45 |   this->lifeSpan = 5; | 
|---|
| 46 |  | 
|---|
| 47 |   this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5); | 
|---|
| 48 |   this->emitter->setParent(this); | 
|---|
| 49 |   this->emitter->setSpread(M_PI, M_PI); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | /** | 
|---|
| 54 |  *  standard deconstructor | 
|---|
| 55 | */ | 
|---|
| 56 | Rocket::~Rocket () | 
|---|
| 57 | { | 
|---|
| 58 |   // delete this->emitter; | 
|---|
| 59 |  | 
|---|
| 60 |   /* this is normaly done by World.cc by deleting the ParticleEngine */ | 
|---|
| 61 |   if (Rocket::trailParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1) | 
|---|
| 62 |   { | 
|---|
| 63 | /*    if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM)) | 
|---|
| 64 |       delete Rocket::trailParticles;*/ | 
|---|
| 65 |     Rocket::trailParticles = NULL; | 
|---|
| 66 |   } | 
|---|
| 67 |   if (Rocket::explosionParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1) | 
|---|
| 68 |   { | 
|---|
| 69 | /*    if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM)) | 
|---|
| 70 |       delete Rocket::explosionParticles;*/ | 
|---|
| 71 |     Rocket::explosionParticles = NULL; | 
|---|
| 72 |   } | 
|---|
| 73 |  | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | SpriteParticles* Rocket::trailParticles = NULL; | 
|---|
| 77 | SpriteParticles* Rocket::explosionParticles = NULL; | 
|---|
| 78 |  | 
|---|
| 79 | void Rocket::activate() | 
|---|
| 80 | { | 
|---|
| 81 |   if (unlikely(Rocket::trailParticles == NULL)) | 
|---|
| 82 |   { | 
|---|
| 83 |     Rocket::trailParticles = new SpriteParticles(2000); | 
|---|
| 84 |     Rocket::trailParticles->setName("RocketTrailParticles"); | 
|---|
| 85 |     Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png"); | 
|---|
| 86 |     Rocket::trailParticles->setLifeSpan(1.0, .3); | 
|---|
| 87 |     Rocket::trailParticles->setRadius(0.0, .5); | 
|---|
| 88 |     Rocket::trailParticles->setRadius(0.2, 2.0); | 
|---|
| 89 |     Rocket::trailParticles->setRadius(.5, .8); | 
|---|
| 90 |     Rocket::trailParticles->setRadius(1.0, .8); | 
|---|
| 91 |     Rocket::trailParticles->setColor(0.0, 1,0,0,.7); | 
|---|
| 92 |     Rocket::trailParticles->setColor(0.2, .8,.8,0,.5); | 
|---|
| 93 |     Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8); | 
|---|
| 94 |     Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0); | 
|---|
| 95 |   } | 
|---|
| 96 |   if (unlikely(Rocket::explosionParticles == NULL)) | 
|---|
| 97 |   { | 
|---|
| 98 |     Rocket::explosionParticles = new SpriteParticles(200); | 
|---|
| 99 |     Rocket::explosionParticles->setName("RocketExplosionParticles"); | 
|---|
| 100 |     Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png"); | 
|---|
| 101 |     Rocket::explosionParticles->setLifeSpan(.5, .3); | 
|---|
| 102 |     Rocket::explosionParticles->setRadius(0.0, 10); | 
|---|
| 103 |     Rocket::explosionParticles->setRadius(.5, 15.0); | 
|---|
| 104 |     Rocket::explosionParticles->setRadius(1.0, 10.0); | 
|---|
| 105 |     Rocket::explosionParticles->setColor(0.0, 0,1,0,1); | 
|---|
| 106 |     Rocket::explosionParticles->setColor(0.5, .8,.8,0,.8); | 
|---|
| 107 |     Rocket::explosionParticles->setColor(0.8, .8,.8,.3,.8); | 
|---|
| 108 |     Rocket::explosionParticles->setColor(1.0, 1,1,1,.0); | 
|---|
| 109 |   } | 
|---|
| 110 |  | 
|---|
| 111 |   this->emitter->setSystem(Rocket::trailParticles); | 
|---|
| 112 |  | 
|---|
| 113 |   this->updateNode(0); | 
|---|
| 114 |   this->emitter->setEmissionRate(45.0); | 
|---|
| 115 |   this->emitter->setEmissionVelocity(0.0); | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 |  | 
|---|
| 119 | void Rocket::deactivate() | 
|---|
| 120 | { | 
|---|
| 121 |   this->emitter->setSystem(NULL); | 
|---|
| 122 |   this->lifeCycle = 0.0; | 
|---|
| 123 |   this->toList(OM_NULL); | 
|---|
| 124 |  | 
|---|
| 125 | //  GarbageCollector::getInstance()->collect(this); | 
|---|
| 126 |   this->toList(OM_DEAD); | 
|---|
| 127 |   Rocket::fastFactory->kill(this); | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | void Rocket::collidesWith(WorldEntity* entity, const Vector& location) | 
|---|
| 132 | { | 
|---|
| 133 |   if (this->hitEntity != entity) | 
|---|
| 134 |     this->destroy(); | 
|---|
| 135 |   this->hitEntity = entity; | 
|---|
| 136 | } | 
|---|
| 137 |  | 
|---|
| 138 | /** | 
|---|
| 139 |  *  signal tick, time dependent things will be handled here | 
|---|
| 140 |  * @param time since last tick | 
|---|
| 141 | */ | 
|---|
| 142 | void Rocket::tick (float dt) | 
|---|
| 143 | { | 
|---|
| 144 |   //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); | 
|---|
| 145 |   Vector v = this->velocity * (dt); | 
|---|
| 146 |   this->shiftCoor(v); | 
|---|
| 147 |  | 
|---|
| 148 |   if(this->tickLifeCycle(dt)) | 
|---|
| 149 |     this->deactivate(); | 
|---|
| 150 | } | 
|---|
| 151 |  | 
|---|
| 152 | /** | 
|---|
| 153 |  *  the function gets called, when the projectile is destroyed | 
|---|
| 154 | */ | 
|---|
| 155 | void Rocket::destroy () | 
|---|
| 156 | { | 
|---|
| 157 |   PRINTF(5)("DESTROY Rocket\n"); | 
|---|
| 158 |   this->lifeCycle = .95; //!< @todo calculate this usefully. | 
|---|
| 159 |   this->emitter->setSystem(Rocket::explosionParticles); | 
|---|
| 160 |  | 
|---|
| 161 |   this->emitter->setEmissionRate(1000.0); | 
|---|
| 162 |   this->emitter->setEmissionVelocity(50.0); | 
|---|
| 163 | //  this->deactivate(); | 
|---|
| 164 |  | 
|---|
| 165 | } | 
|---|
| 166 |  | 
|---|
| 167 |  | 
|---|
| 168 | void Rocket::draw () const | 
|---|
| 169 | { | 
|---|
| 170 |   glMatrixMode(GL_MODELVIEW); | 
|---|
| 171 |   glPushMatrix(); | 
|---|
| 172 |  | 
|---|
| 173 |   float matrix[4][4]; | 
|---|
| 174 |   glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); | 
|---|
| 175 |   this->getAbsDir().matrix (matrix); | 
|---|
| 176 |   glMultMatrixf((float*)matrix); | 
|---|
| 177 |   glScalef(2.0, 2.0, 2.0); | 
|---|
| 178 |   this->getModel()->draw(); | 
|---|
| 179 |  | 
|---|
| 180 |   glPopMatrix(); | 
|---|
| 181 | } | 
|---|
| 182 |  | 
|---|