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