Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/nadion_blast.cc @ 10771

Last change on this file since 10771 was 10698, checked in by snellen, 18 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

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