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