[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"); |
---|
[10511] | 64 | this->halo->setVisibility(false); |
---|
[10345] | 65 | |
---|
| 66 | |
---|
[10044] | 67 | } |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | * standard deconstructor |
---|
| 72 | */ |
---|
| 73 | LBolt::~LBolt () |
---|
| 74 | { |
---|
| 75 | // delete this->emitter; |
---|
| 76 | |
---|
| 77 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
| 78 | if (LBolt::explosionParticles != NULL && LBolt::objectList().size() <= 1) |
---|
| 79 | { |
---|
| 80 | //if (ClassList::exists(LBolt::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
| 81 | // delete LBolt::explosionParticles; |
---|
| 82 | PRINTF(1)("Deleting LBolt Particles\n"); |
---|
| 83 | LBolt::explosionParticles = NULL; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | SpriteParticles* LBolt::explosionParticles = NULL; |
---|
| 89 | |
---|
| 90 | void LBolt::activate() |
---|
| 91 | { |
---|
[10511] | 92 | this->halo->setVisibility(true); |
---|
[10345] | 93 | this->origList = this->getOMListNumber(); |
---|
[10274] | 94 | this->toList(OM_ENVIRON); |
---|
[10044] | 95 | if (unlikely(LBolt::explosionParticles == NULL)) |
---|
| 96 | { |
---|
| 97 | LBolt::explosionParticles = new SpriteParticles(1000); |
---|
| 98 | LBolt::explosionParticles->setName("BoltExplosionParticles"); |
---|
| 99 | LBolt::explosionParticles->setLifeSpan(.5, .3); |
---|
| 100 | LBolt::explosionParticles->setRadius(0.0, 10.0); |
---|
| 101 | LBolt::explosionParticles->setRadius(.5, 6.0); |
---|
| 102 | LBolt::explosionParticles->setRadius(1.0, 3.0); |
---|
| 103 | LBolt::explosionParticles->setColor(0.0, 1,1,0,.9); |
---|
| 104 | LBolt::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
| 105 | LBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | this->setDamage(5); |
---|
| 109 | this->setHealth(0); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | void LBolt::deactivate() |
---|
| 114 | { |
---|
| 115 | assert (LBolt::explosionParticles != NULL); |
---|
| 116 | LBolt::explosionParticles->removeEmitter(this->emitter); |
---|
[10511] | 117 | this->halo->setVisibility(false); |
---|
[10044] | 118 | this->lifeCycle = 0.0; |
---|
| 119 | |
---|
[10274] | 120 | this->toList(OM_DEAD); |
---|
[10044] | 121 | this->removeNode(); |
---|
| 122 | LBolt::fastFactory->kill(this); |
---|
| 123 | } |
---|
| 124 | |
---|
[10261] | 125 | |
---|
[10274] | 126 | void LBolt::hit (float damage, WorldEntity* entity ) |
---|
[10044] | 127 | { |
---|
[10079] | 128 | PRINTF(0)("Collision with LBolt\n"); |
---|
[10366] | 129 | if (this->hitEntity != entity && entity->isA(NPC::staticClassID())) |
---|
[10044] | 130 | this->destroy( entity ); |
---|
| 131 | this->hitEntity = entity; |
---|
[10261] | 132 | this->deactivate(); |
---|
| 133 | } |
---|
[10044] | 134 | |
---|
| 135 | /** |
---|
| 136 | * signal tick, time dependent things will be handled here |
---|
| 137 | * @param dt time since last tick |
---|
| 138 | */ |
---|
| 139 | void LBolt::tick (float dt) |
---|
| 140 | { |
---|
| 141 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
| 142 | Vector v = this->velocity * dt; |
---|
| 143 | this->shiftCoor(v); |
---|
| 144 | |
---|
| 145 | if (this->tickLifeCycle(dt)) |
---|
| 146 | this->deactivate(); |
---|
| 147 | |
---|
| 148 | angle += rotationSpeed * dt; |
---|
[10274] | 149 | |
---|
| 150 | for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++) |
---|
| 151 | { |
---|
[10345] | 152 | if( ((*eIterator)->getOMListNumber() != (this->origList -1)) && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8) |
---|
[10274] | 153 | { |
---|
| 154 | (*eIterator)->hit (this->getDamage(),this); |
---|
| 155 | this->deactivate(); |
---|
| 156 | PRINTF(0)("LBolt destroyed\n"); |
---|
| 157 | } |
---|
| 158 | } |
---|
[10044] | 159 | } |
---|
| 160 | |
---|
| 161 | /** |
---|
| 162 | * the function gets called, when the projectile is destroyed |
---|
| 163 | */ |
---|
| 164 | void LBolt::destroy (WorldEntity* killer) |
---|
| 165 | { |
---|
| 166 | Projectile::destroy( killer ); |
---|
| 167 | PRINTF(5)("DESTROY LBolt\n"); |
---|
| 168 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
| 169 | |
---|
| 170 | this->emitter->setSystem(LBolt::explosionParticles); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | void LBolt::draw () const |
---|
| 175 | { |
---|
| 176 | glPushAttrib(GL_ENABLE_BIT); |
---|
[10046] | 177 | //glDisable(GL_LIGHTING); |
---|
[10044] | 178 | |
---|
| 179 | glMatrixMode(GL_MODELVIEW); |
---|
| 180 | glPushMatrix(); |
---|
| 181 | |
---|
| 182 | float matrix[4][4]; |
---|
| 183 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
[10063] | 184 | |
---|
[10044] | 185 | glRotatef(angle, 1.0, 0.0, 0.0); |
---|
| 186 | this->getAbsDir().matrix (matrix); |
---|
| 187 | glMultMatrixf((float*)matrix); |
---|
[10063] | 188 | this->getModel()->draw(); |
---|
[10046] | 189 | |
---|
[10063] | 190 | this->halo->draw(); |
---|
| 191 | |
---|
[10044] | 192 | glPopMatrix(); |
---|
| 193 | |
---|
| 194 | glPopAttrib(); |
---|
| 195 | } |
---|
| 196 | |
---|