1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004-2006 orx |
---|
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 |
---|
12 | main-programmer: Marc Schaerrer |
---|
13 | co-programmer: Benjamin Grauer |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | |
---|
18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
19 | |
---|
20 | #include "nadion_blast.h" |
---|
21 | |
---|
22 | #include "state.h" |
---|
23 | #include "model.h" |
---|
24 | |
---|
25 | #include "world_entities/npcs/actionbox_enemy.h" |
---|
26 | #include "world_entities/npcs/npc.h" |
---|
27 | |
---|
28 | #include "particles/dot_emitter.h" |
---|
29 | #include "particles/sprite_particles.h" |
---|
30 | |
---|
31 | #include "space_ships/space_ship.h" |
---|
32 | |
---|
33 | #include <cassert> |
---|
34 | #include "debug.h" |
---|
35 | |
---|
36 | #include "static_model.h" |
---|
37 | |
---|
38 | #include "effects/trail.h" |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | ObjectListDefinition(NadionBlast); |
---|
43 | CREATE_FAST_FACTORY_STATIC(NadionBlast); |
---|
44 | |
---|
45 | /** |
---|
46 | * standard constructor |
---|
47 | */ |
---|
48 | NadionBlast::NadionBlast () : Projectile() |
---|
49 | { |
---|
50 | this->registerObject(this, NadionBlast::_objectList); |
---|
51 | this->loadModel("models/projectiles/mbolt.obj",4); |
---|
52 | |
---|
53 | |
---|
54 | //this->loadModel("models/projectiles/laser.obj"); |
---|
55 | |
---|
56 | this->setMinEnergy(4); |
---|
57 | this->setHealthMax(0); |
---|
58 | this->lifeSpan = 2.5; |
---|
59 | this->angle = 0; |
---|
60 | |
---|
61 | //this->emitter = new DotEmitter(1000, 0, 0); |
---|
62 | this->emitter = new DotEmitter(50, 0, 0); |
---|
63 | this->emitter->setParent(this); |
---|
64 | this->emitter->setSpread(M_PI,M_PI); |
---|
65 | this->emitter->setInheritSpeed(this->velocity.len()); |
---|
66 | this->emitter->setEmissionRate(500.0); |
---|
67 | this->emitter->setEmissionVelocity(this->velocity.len()); |
---|
68 | |
---|
69 | this->mat = new Material("NadionBlast"); |
---|
70 | //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); |
---|
71 | this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE); |
---|
72 | this->mat->setDiffuse(1,1,1); |
---|
73 | this->mat->setDiffuseMap("laser_add.png"); |
---|
74 | this->mat->setDiffuseMap("laser2.png",1); |
---|
75 | |
---|
76 | dynamic_cast<StaticModel*>(this->getModel())->addMaterial(*this->mat); |
---|
77 | dynamic_cast<StaticModel*>(this->getModel())->finalize(); |
---|
78 | |
---|
79 | dynamic_cast<StaticModel*>(this->getModel())->rebuild(); |
---|
80 | //this->buildObbTree(4); |
---|
81 | |
---|
82 | // this->trail = new Trail(6, 4, .1, this); |
---|
83 | //this->trail->setParent( this); |
---|
84 | // this->trail->setTexture( "textures/laser.png"); |
---|
85 | // this->trail->setAbsCoor(this->getAbsCoor() - Vector(.7,0,0)); |
---|
86 | // this->trail->setAbsCoor(this->getAbsCoor() - this->getVelocity().getNormalized() * .7); |
---|
87 | |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | /** |
---|
92 | * standard deconstructor |
---|
93 | * |
---|
94 | */ |
---|
95 | NadionBlast::~NadionBlast () |
---|
96 | { |
---|
97 | |
---|
98 | if (NadionBlast::explosionParticles != NULL && NadionBlast::objectList().size() <= 1) |
---|
99 | { |
---|
100 | if (ParticleSystem::objectList().exists(NadionBlast::explosionParticles)) |
---|
101 | delete NadionBlast::explosionParticles; |
---|
102 | NadionBlast::explosionParticles = NULL; |
---|
103 | PRINTF(1)("Deleting NadionBlast Explosion Particles\n"); |
---|
104 | } |
---|
105 | |
---|
106 | delete this->emitter; |
---|
107 | // delete this->trail; |
---|
108 | } |
---|
109 | |
---|
110 | SpriteParticles* NadionBlast::explosionParticles = NULL; |
---|
111 | |
---|
112 | void NadionBlast::activate() |
---|
113 | { |
---|
114 | // this->origList = this->getOMListNumber(); |
---|
115 | // this->toList(OM_ENVIRON); |
---|
116 | if (unlikely(NadionBlast::explosionParticles == NULL)) |
---|
117 | { |
---|
118 | NadionBlast::explosionParticles = new SpriteParticles(1000); |
---|
119 | NadionBlast::explosionParticles->setName("NadionBlastExplosionParticles"); |
---|
120 | NadionBlast::explosionParticles->setLifeSpan(.2, .1); |
---|
121 | NadionBlast::explosionParticles->setRadius(0.0, 10.0); |
---|
122 | NadionBlast::explosionParticles->setRadius(.5, 6.0); |
---|
123 | NadionBlast::explosionParticles->setRadius(1.0, 3.0); |
---|
124 | NadionBlast::explosionParticles->setColor(0.0, 1,1,0,.9); |
---|
125 | NadionBlast::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
126 | NadionBlast::explosionParticles->setColor(1.0, .8,.8,.7,.0); |
---|
127 | } |
---|
128 | |
---|
129 | this->setPhysDamage(10); |
---|
130 | this->setElecDamage(0); |
---|
131 | this->setHealth(0); |
---|
132 | |
---|
133 | this->emitter->setSpread(0); |
---|
134 | this->emitter->setEmissionRate(10.0); |
---|
135 | this->emitter->setEmissionVelocity(50); |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | void NadionBlast::deactivate() |
---|
140 | { |
---|
141 | assert (NadionBlast::explosionParticles != NULL); |
---|
142 | NadionBlast::explosionParticles->removeEmitter(this->emitter); |
---|
143 | this->lifeCycle = 0.0; |
---|
144 | |
---|
145 | this->lifeCycle = 0.0; |
---|
146 | this->toList(OM_NULL); |
---|
147 | //this->toList(OM_DEAD); |
---|
148 | // this->removeNode(); |
---|
149 | NadionBlast::fastFactory->kill(this); |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | // void NadionBlast::hit (float damage, WorldEntity* entity ) |
---|
154 | // { |
---|
155 | // |
---|
156 | // if (this->hitEntity != entity) |
---|
157 | // this->destroy( entity ); |
---|
158 | // this->hitEntity = entity; |
---|
159 | // // dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),this->getElecDamage()); |
---|
160 | // //this->destroy(this); |
---|
161 | // this->deactivate(); |
---|
162 | // |
---|
163 | // return; |
---|
164 | // |
---|
165 | // } |
---|
166 | |
---|
167 | /** |
---|
168 | * signal tick, time dependent things will be handled here |
---|
169 | * @param dt time since last tick |
---|
170 | */ |
---|
171 | void NadionBlast::tick (float dt) |
---|
172 | { |
---|
173 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
174 | Vector v = this->velocity * dt; |
---|
175 | this->shiftCoor(v); |
---|
176 | |
---|
177 | if (this->tickLifeCycle(dt)) |
---|
178 | this->deactivate(); |
---|
179 | |
---|
180 | this->angle += NadionBlast::rotationSpeed * dt; |
---|
181 | // this->trail->tick(dt); |
---|
182 | } |
---|
183 | |
---|
184 | /** |
---|
185 | * the function gets called, when the projectile is destroyed |
---|
186 | */ |
---|
187 | void NadionBlast::destroy (WorldEntity* killer) |
---|
188 | { |
---|
189 | //this->deactivate(); |
---|
190 | Projectile::destroy( killer ); |
---|
191 | PRINTF(5)("DESTROY NadionBlast\n"); |
---|
192 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
193 | |
---|
194 | this->emitter->setSystem(NadionBlast::explosionParticles); |
---|
195 | } |
---|
196 | |
---|
197 | |
---|
198 | void NadionBlast::draw () const |
---|
199 | { |
---|
200 | glPushAttrib(GL_ENABLE_BIT); |
---|
201 | glDisable(GL_LIGHTING); |
---|
202 | |
---|
203 | glPushMatrix(); |
---|
204 | float matrix[4][4]; |
---|
205 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
206 | // glRotatef(this->angle, 1.0f, 0.0f, 0.0f); //spinning missile |
---|
207 | // HACK, need to be removed, once the AbsDir is correct, replace with the one above |
---|
208 | // glRotatef(this->angle, this->flightDirection.x, this->flightDirection.y, this->flightDirection.z); |
---|
209 | this->getAbsDir().matrix (matrix); |
---|
210 | glMultMatrixf((float*)matrix); |
---|
211 | |
---|
212 | glScalef(0.75/6, 0.7/16, 0.7/16); // no double rescale |
---|
213 | |
---|
214 | this->mat->select(); |
---|
215 | dynamic_cast<StaticModel*>(this->getModel())->draw(); |
---|
216 | this->mat->unselect(); |
---|
217 | // glScalef(4/.75,16/.7,16/.7); |
---|
218 | // glTranslatef(-3,0,0); |
---|
219 | // this->trail->draw(); |
---|
220 | glPopMatrix(); |
---|
221 | glPopAttrib(); |
---|
222 | |
---|
223 | } |
---|