[9999] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
[10104] | 4 | Copyright (C) 2004-2006 orx |
---|
[9999] | 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 |
---|
[10104] | 12 | main-programmer: Marc Schaerrer |
---|
[9999] | 13 | co-programmer: Benjamin Grauer |
---|
| 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
| 19 | |
---|
| 20 | #include "mbolt.h" |
---|
| 21 | |
---|
| 22 | #include "state.h" |
---|
| 23 | #include "model.h" |
---|
| 24 | |
---|
[10545] | 25 | #include "world_entities/npcs/npc.h" |
---|
| 26 | |
---|
[9999] | 27 | #include "particles/dot_emitter.h" |
---|
| 28 | #include "particles/sprite_particles.h" |
---|
| 29 | |
---|
[10064] | 30 | #include "space_ships/space_ship.h" |
---|
| 31 | |
---|
[9999] | 32 | #include <cassert> |
---|
| 33 | #include "debug.h" |
---|
| 34 | |
---|
[10042] | 35 | #include "static_model.h" |
---|
[9999] | 36 | |
---|
[10081] | 37 | #include "effects/trail.h" |
---|
[10042] | 38 | |
---|
[10081] | 39 | |
---|
[10366] | 40 | |
---|
[10064] | 41 | ObjectListDefinition(MBolt); |
---|
[9999] | 42 | CREATE_FAST_FACTORY_STATIC(MBolt); |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * standard constructor |
---|
| 46 | */ |
---|
| 47 | MBolt::MBolt () : Projectile() |
---|
| 48 | { |
---|
[10064] | 49 | this->registerObject(this, MBolt::_objectList); |
---|
[10113] | 50 | this->loadModel("models/projectiles/mbolt.obj",4); |
---|
[10081] | 51 | |
---|
[10366] | 52 | |
---|
[10042] | 53 | //this->loadModel("models/projectiles/laser.obj"); |
---|
[9999] | 54 | |
---|
[10036] | 55 | this->setMinEnergy(4); |
---|
[9999] | 56 | this->setHealthMax(0); |
---|
[10274] | 57 | this->lifeSpan = 1.5; |
---|
[10042] | 58 | this->angle = 0; |
---|
[9999] | 59 | |
---|
[10064] | 60 | //this->emitter = new DotEmitter(1000, 0, 0); |
---|
[10113] | 61 | this->emitter = new DotEmitter(50, 0, 0); |
---|
[9999] | 62 | this->emitter->setParent(this); |
---|
[10064] | 63 | this->emitter->setSpread(M_PI,M_PI); |
---|
| 64 | this->emitter->setInheritSpeed(this->velocity.len()); |
---|
| 65 | this->emitter->setEmissionRate(500.0); |
---|
| 66 | this->emitter->setEmissionVelocity(this->velocity.len()); |
---|
[10042] | 67 | |
---|
| 68 | this->mat = new Material("mBolt"); |
---|
| 69 | //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); |
---|
| 70 | this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE); |
---|
| 71 | this->mat->setDiffuse(1,1,1); |
---|
[10064] | 72 | this->mat->setDiffuseMap("laser_add.png"); |
---|
[10042] | 73 | this->mat->setDiffuseMap("laser.png",1); |
---|
[10064] | 74 | |
---|
[10366] | 75 | dynamic_cast<StaticModel*>(this->getModel())->addMaterial(*this->mat); |
---|
[10042] | 76 | dynamic_cast<StaticModel*>(this->getModel())->finalize(); |
---|
[10081] | 77 | |
---|
[10113] | 78 | dynamic_cast<StaticModel*>(this->getModel())->rebuild(); |
---|
[10261] | 79 | //this->buildObbTree(4); |
---|
[10366] | 80 | |
---|
[10132] | 81 | this->trail = new Trail(6, 4, .1, this); |
---|
[10095] | 82 | //this->trail->setParent( this); |
---|
[10420] | 83 | this->trail->setTexture( "textures/laser.png"); |
---|
[10113] | 84 | this->trail->setAbsCoor(this->getAbsCoor() - Vector(.7,0,0)); |
---|
[10345] | 85 | |
---|
[9999] | 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | /** |
---|
| 90 | * standard deconstructor |
---|
[10078] | 91 | * |
---|
| 92 | */ |
---|
[9999] | 93 | MBolt::~MBolt () |
---|
| 94 | { |
---|
| 95 | |
---|
| 96 | if (MBolt::explosionParticles != NULL && MBolt::objectList().size() <= 1) |
---|
| 97 | { |
---|
[10042] | 98 | if (ParticleSystem::objectList().exists(MBolt::explosionParticles)) |
---|
| 99 | delete MBolt::explosionParticles; |
---|
[9999] | 100 | MBolt::explosionParticles = NULL; |
---|
[10081] | 101 | PRINTF(1)("Deleting MBolt Explosion Particles\n"); |
---|
[9999] | 102 | } |
---|
[10168] | 103 | |
---|
| 104 | delete this->emitter; |
---|
| 105 | delete this->trail; |
---|
[9999] | 106 | } |
---|
| 107 | |
---|
| 108 | SpriteParticles* MBolt::explosionParticles = NULL; |
---|
| 109 | |
---|
| 110 | void MBolt::activate() |
---|
| 111 | { |
---|
[10345] | 112 | this->origList = this->getOMListNumber(); |
---|
[10274] | 113 | this->toList(OM_ENVIRON); |
---|
[9999] | 114 | if (unlikely(MBolt::explosionParticles == NULL)) |
---|
| 115 | { |
---|
| 116 | MBolt::explosionParticles = new SpriteParticles(1000); |
---|
| 117 | MBolt::explosionParticles->setName("MBoltExplosionParticles"); |
---|
[10113] | 118 | MBolt::explosionParticles->setLifeSpan(.2, .1); |
---|
[9999] | 119 | MBolt::explosionParticles->setRadius(0.0, 10.0); |
---|
| 120 | MBolt::explosionParticles->setRadius(.5, 6.0); |
---|
| 121 | MBolt::explosionParticles->setRadius(1.0, 3.0); |
---|
| 122 | MBolt::explosionParticles->setColor(0.0, 1,1,0,.9); |
---|
| 123 | MBolt::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
| 124 | MBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0); |
---|
| 125 | } |
---|
| 126 | |
---|
[10081] | 127 | this->setPhysDamage(10); |
---|
| 128 | this->setElecDamage(0); |
---|
[9999] | 129 | this->setHealth(0); |
---|
[10042] | 130 | |
---|
[10064] | 131 | this->emitter->setSpread(0); |
---|
[10078] | 132 | this->emitter->setEmissionRate(10.0); |
---|
[10113] | 133 | this->emitter->setEmissionVelocity(50); |
---|
[9999] | 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | void MBolt::deactivate() |
---|
| 138 | { |
---|
| 139 | assert (MBolt::explosionParticles != NULL); |
---|
| 140 | MBolt::explosionParticles->removeEmitter(this->emitter); |
---|
| 141 | this->lifeCycle = 0.0; |
---|
| 142 | |
---|
[10345] | 143 | this->lifeCycle = 0.0; |
---|
| 144 | this->toList(OM_NULL); |
---|
| 145 | //this->toList(OM_DEAD); |
---|
[10117] | 146 | this->removeNode(); |
---|
[9999] | 147 | MBolt::fastFactory->kill(this); |
---|
| 148 | } |
---|
| 149 | |
---|
[10274] | 150 | void MBolt::hit (float damage, WorldEntity* entity ) |
---|
[9999] | 151 | { |
---|
[10113] | 152 | |
---|
[10117] | 153 | if (this->hitEntity != entity) |
---|
| 154 | this->destroy( entity ); |
---|
| 155 | this->hitEntity = entity; |
---|
[10261] | 156 | // dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),this->getElecDamage()); |
---|
[10132] | 157 | //this->destroy(this); |
---|
| 158 | this->deactivate(); |
---|
[10366] | 159 | |
---|
[10117] | 160 | return; |
---|
| 161 | |
---|
[10261] | 162 | } |
---|
[9999] | 163 | |
---|
| 164 | /** |
---|
| 165 | * signal tick, time dependent things will be handled here |
---|
| 166 | * @param dt time since last tick |
---|
| 167 | */ |
---|
| 168 | void MBolt::tick (float dt) |
---|
| 169 | { |
---|
| 170 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
| 171 | Vector v = this->velocity * dt; |
---|
| 172 | this->shiftCoor(v); |
---|
| 173 | |
---|
| 174 | if (this->tickLifeCycle(dt)) |
---|
| 175 | this->deactivate(); |
---|
[10042] | 176 | |
---|
| 177 | this->angle += MBolt::rotationSpeed * dt; |
---|
[10081] | 178 | this->trail->tick(dt); |
---|
[10274] | 179 | |
---|
[10545] | 180 | for( ObjectList<NPC>::const_iterator eIterator = NPC::objectList().begin(); eIterator !=NPC::objectList().end(); eIterator++) |
---|
[10274] | 181 | { |
---|
[10345] | 182 | if( ((*eIterator)->getOMListNumber() != (this->origList -1)) && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8) |
---|
[10274] | 183 | { |
---|
[10545] | 184 | (*eIterator)->destroy(this); //hit (this->getDamage(),this); |
---|
[10274] | 185 | this->deactivate(); |
---|
| 186 | PRINTF(0)("MBolt destroyed\n"); |
---|
| 187 | } |
---|
| 188 | } |
---|
[9999] | 189 | } |
---|
| 190 | |
---|
| 191 | /** |
---|
| 192 | * the function gets called, when the projectile is destroyed |
---|
| 193 | */ |
---|
| 194 | void MBolt::destroy (WorldEntity* killer) |
---|
| 195 | { |
---|
[10117] | 196 | //this->deactivate(); |
---|
[9999] | 197 | Projectile::destroy( killer ); |
---|
| 198 | PRINTF(5)("DESTROY MBolt\n"); |
---|
| 199 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
| 200 | |
---|
| 201 | this->emitter->setSystem(MBolt::explosionParticles); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | void MBolt::draw () const |
---|
| 206 | { |
---|
| 207 | glPushAttrib(GL_ENABLE_BIT); |
---|
| 208 | glDisable(GL_LIGHTING); |
---|
| 209 | |
---|
[10042] | 210 | glPushMatrix(); |
---|
| 211 | float matrix[4][4]; |
---|
| 212 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 213 | glRotatef(this->angle, 1.0f, 0.0f, 0.0f); //spinning missile |
---|
| 214 | this->getAbsDir().matrix (matrix); |
---|
| 215 | glMultMatrixf((float*)matrix); |
---|
| 216 | |
---|
[10113] | 217 | glScalef(0.75/4, 0.7/16, 0.7/16); // no double rescale |
---|
[10042] | 218 | |
---|
| 219 | this->mat->select(); |
---|
| 220 | dynamic_cast<StaticModel*>(this->getModel())->draw(); |
---|
| 221 | this->mat->unselect(); |
---|
[10113] | 222 | glScalef(4/.75,16/.7,16/.7); |
---|
| 223 | glTranslatef(-3,0,0); |
---|
[10081] | 224 | this->trail->draw(); |
---|
[10042] | 225 | glPopMatrix(); |
---|
[9999] | 226 | glPopAttrib(); |
---|
[10042] | 227 | |
---|
[10140] | 228 | } |
---|