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