[10044] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
[10104] | 4 | Copyright (C) 2004-2006 orx |
---|
[10044] | 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: Nicolas Schlumberger, Marc Schaerrer |
---|
[10044] | 13 | co-programmer: Benjamin Grauer |
---|
| 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
| 19 | |
---|
| 20 | #include "lbolt.h" |
---|
| 21 | |
---|
| 22 | #include "state.h" |
---|
| 23 | #include "model.h" |
---|
| 24 | |
---|
| 25 | #include "particles/dot_emitter.h" |
---|
| 26 | #include "particles/sprite_particles.h" |
---|
| 27 | |
---|
| 28 | #include <cassert> |
---|
| 29 | #include "debug.h" |
---|
| 30 | |
---|
[10079] | 31 | #include "space_ships/space_ship.h" |
---|
[10044] | 32 | |
---|
[10079] | 33 | |
---|
[10044] | 34 | #include "class_id_DEPRECATED.h" |
---|
| 35 | ObjectListDefinition(LBolt); |
---|
| 36 | CREATE_FAST_FACTORY_STATIC(LBolt); |
---|
| 37 | |
---|
| 38 | /** |
---|
| 39 | * standard constructor |
---|
| 40 | */ |
---|
| 41 | LBolt::LBolt () : Projectile() |
---|
| 42 | { |
---|
| 43 | this->registerObject(this, LBolt::_objectList); |
---|
| 44 | |
---|
| 45 | this->loadModel("models/projectiles/lbolt.obj"); |
---|
| 46 | |
---|
| 47 | this->setMinEnergy(1); |
---|
| 48 | this->setHealthMax(0); |
---|
[10274] | 49 | this->lifeSpan = 1.0; |
---|
[10044] | 50 | |
---|
| 51 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
| 52 | this->emitter->setParent(this); |
---|
| 53 | this->emitter->setSpread(M_PI, M_PI); |
---|
| 54 | this->emitter->setEmissionRate(300.0); |
---|
| 55 | this->emitter->setEmissionVelocity(50.0); |
---|
| 56 | |
---|
| 57 | this->angle = 0; |
---|
| 58 | this->rotationSpeed = 130; |
---|
[10046] | 59 | |
---|
[10063] | 60 | this->halo = new Billboard(); |
---|
[10074] | 61 | this->halo->setSize(.35, .35); |
---|
[10063] | 62 | this->halo->setTexture("hbolt_halo.png"); |
---|
[10044] | 63 | } |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | * standard deconstructor |
---|
| 68 | */ |
---|
| 69 | LBolt::~LBolt () |
---|
| 70 | { |
---|
| 71 | // delete this->emitter; |
---|
| 72 | |
---|
| 73 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
| 74 | if (LBolt::explosionParticles != NULL && LBolt::objectList().size() <= 1) |
---|
| 75 | { |
---|
| 76 | //if (ClassList::exists(LBolt::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
| 77 | // delete LBolt::explosionParticles; |
---|
| 78 | PRINTF(1)("Deleting LBolt Particles\n"); |
---|
| 79 | LBolt::explosionParticles = NULL; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | SpriteParticles* LBolt::explosionParticles = NULL; |
---|
| 85 | |
---|
| 86 | void LBolt::activate() |
---|
| 87 | { |
---|
[10274] | 88 | this->toList(OM_ENVIRON); |
---|
[10044] | 89 | if (unlikely(LBolt::explosionParticles == NULL)) |
---|
| 90 | { |
---|
| 91 | LBolt::explosionParticles = new SpriteParticles(1000); |
---|
| 92 | LBolt::explosionParticles->setName("BoltExplosionParticles"); |
---|
| 93 | LBolt::explosionParticles->setLifeSpan(.5, .3); |
---|
| 94 | LBolt::explosionParticles->setRadius(0.0, 10.0); |
---|
| 95 | LBolt::explosionParticles->setRadius(.5, 6.0); |
---|
| 96 | LBolt::explosionParticles->setRadius(1.0, 3.0); |
---|
| 97 | LBolt::explosionParticles->setColor(0.0, 1,1,0,.9); |
---|
| 98 | LBolt::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
| 99 | LBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | this->setDamage(5); |
---|
| 103 | this->setHealth(0); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | void LBolt::deactivate() |
---|
| 108 | { |
---|
| 109 | assert (LBolt::explosionParticles != NULL); |
---|
| 110 | LBolt::explosionParticles->removeEmitter(this->emitter); |
---|
| 111 | this->lifeCycle = 0.0; |
---|
| 112 | |
---|
[10274] | 113 | this->toList(OM_DEAD); |
---|
[10044] | 114 | this->removeNode(); |
---|
| 115 | LBolt::fastFactory->kill(this); |
---|
| 116 | } |
---|
| 117 | |
---|
[10261] | 118 | |
---|
[10274] | 119 | void LBolt::hit (float damage, WorldEntity* entity ) |
---|
[10044] | 120 | { |
---|
[10079] | 121 | PRINTF(0)("Collision with LBolt\n"); |
---|
[10044] | 122 | if (this->hitEntity != entity && entity->isA(CL_NPC)) |
---|
| 123 | this->destroy( entity ); |
---|
| 124 | this->hitEntity = entity; |
---|
[10261] | 125 | this->deactivate(); |
---|
| 126 | } |
---|
[10044] | 127 | |
---|
| 128 | /** |
---|
| 129 | * signal tick, time dependent things will be handled here |
---|
| 130 | * @param dt time since last tick |
---|
| 131 | */ |
---|
| 132 | void LBolt::tick (float dt) |
---|
| 133 | { |
---|
| 134 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
| 135 | Vector v = this->velocity * dt; |
---|
| 136 | this->shiftCoor(v); |
---|
| 137 | |
---|
| 138 | if (this->tickLifeCycle(dt)) |
---|
| 139 | this->deactivate(); |
---|
| 140 | |
---|
| 141 | angle += rotationSpeed * dt; |
---|
[10274] | 142 | |
---|
| 143 | for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++) |
---|
| 144 | { |
---|
| 145 | if( ((*eIterator)->getOMListNumber() == OM_GROUP_00) && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8) |
---|
| 146 | { |
---|
| 147 | (*eIterator)->hit (this->getDamage(),this); |
---|
| 148 | this->deactivate(); |
---|
| 149 | PRINTF(0)("LBolt destroyed\n"); |
---|
| 150 | } |
---|
| 151 | } |
---|
[10044] | 152 | } |
---|
| 153 | |
---|
| 154 | /** |
---|
| 155 | * the function gets called, when the projectile is destroyed |
---|
| 156 | */ |
---|
| 157 | void LBolt::destroy (WorldEntity* killer) |
---|
| 158 | { |
---|
| 159 | Projectile::destroy( killer ); |
---|
| 160 | PRINTF(5)("DESTROY LBolt\n"); |
---|
| 161 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
| 162 | |
---|
| 163 | this->emitter->setSystem(LBolt::explosionParticles); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | void LBolt::draw () const |
---|
| 168 | { |
---|
| 169 | glPushAttrib(GL_ENABLE_BIT); |
---|
[10046] | 170 | //glDisable(GL_LIGHTING); |
---|
[10044] | 171 | |
---|
| 172 | glMatrixMode(GL_MODELVIEW); |
---|
| 173 | glPushMatrix(); |
---|
| 174 | |
---|
| 175 | float matrix[4][4]; |
---|
| 176 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
[10063] | 177 | |
---|
[10044] | 178 | glRotatef(angle, 1.0, 0.0, 0.0); |
---|
| 179 | this->getAbsDir().matrix (matrix); |
---|
| 180 | glMultMatrixf((float*)matrix); |
---|
[10063] | 181 | this->getModel()->draw(); |
---|
[10046] | 182 | |
---|
[10063] | 183 | this->halo->draw(); |
---|
| 184 | |
---|
[10044] | 185 | glPopMatrix(); |
---|
| 186 | |
---|
| 187 | glPopAttrib(); |
---|
| 188 | } |
---|
| 189 | |
---|