Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/mbolt.cc @ 10719

Last change on this file since 10719 was 10698, checked in by snellen, 17 years ago

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

File size: 5.9 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 "mbolt.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(MBolt);
42CREATE_FAST_FACTORY_STATIC(MBolt);
43
44/**
45 *  standard constructor
46*/
47MBolt::MBolt () : Projectile()
48{
49  this->registerObject(this, MBolt::_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 = 1.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("mBolt");
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("laser.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 */
94MBolt::~MBolt ()
95{
96
97  if (MBolt::explosionParticles != NULL && MBolt::objectList().size() <= 1)
98  {
99    if (ParticleSystem::objectList().exists(MBolt::explosionParticles))
100      delete MBolt::explosionParticles;
101    MBolt::explosionParticles = NULL;
102    PRINTF(1)("Deleting MBolt Explosion Particles\n");
103  }
104
105  delete this->emitter;
106  delete this->trail;
107}
108
109SpriteParticles* MBolt::explosionParticles = NULL;
110
111void MBolt::activate()
112{
113  this->origList = this->getOMListNumber();
114  this->toList(OM_ENVIRON);
115  if (unlikely(MBolt::explosionParticles == NULL))
116  {
117    MBolt::explosionParticles = new SpriteParticles(1000);
118    MBolt::explosionParticles->setName("MBoltExplosionParticles");
119    MBolt::explosionParticles->setLifeSpan(.2, .1);
120    MBolt::explosionParticles->setRadius(0.0, 10.0);
121    MBolt::explosionParticles->setRadius(.5, 6.0);
122    MBolt::explosionParticles->setRadius(1.0, 3.0);
123    MBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
124    MBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
125    MBolt::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 MBolt::deactivate()
139{
140  assert (MBolt::explosionParticles != NULL);
141  MBolt::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  MBolt::fastFactory->kill(this);
149}
150
151void MBolt::hit (float damage, WorldEntity* entity )
152{
153
154  if (this->hitEntity != entity)
155    this->destroy( entity );
156  this->hitEntity = entity;
157 // dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),this->getElecDamage());
158  //this->destroy(this);
159  this->deactivate();
160
161  return;
162
163}
164
165/**
166 *  signal tick, time dependent things will be handled here
167 * @param dt time since last tick
168*/
169void MBolt::tick (float dt)
170{
171  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
172  Vector v = this->velocity * dt;
173  this->shiftCoor(v);
174
175  if (this->tickLifeCycle(dt))
176    this->deactivate();
177
178  this->angle += MBolt::rotationSpeed * dt;
179  this->trail->tick(dt);
180
181  for( ObjectList<NPC>::const_iterator eIterator = NPC::objectList().begin(); eIterator !=NPC::objectList().end(); eIterator++)
182  {
183    if( ((*eIterator)->getOMListNumber() != (this->origList -1))  && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8)
184    {
185      (*eIterator)->destroy(this); //hit (this->getDamage(),this);
186      this->deactivate();
187      PRINTF(0)("MBolt destroyed\n");
188    }
189  }
190}
191
192/**
193 *  the function gets called, when the projectile is destroyed
194*/
195void MBolt::destroy (WorldEntity* killer)
196{
197  //this->deactivate();
198  Projectile::destroy( killer );
199  PRINTF(5)("DESTROY MBolt\n");
200  this->lifeCycle = .95; //!< @todo calculate this usefully.
201
202  this->emitter->setSystem(MBolt::explosionParticles);
203}
204
205
206void MBolt::draw () const
207{
208  glPushAttrib(GL_ENABLE_BIT);
209  glDisable(GL_LIGHTING);
210
211  glPushMatrix();
212  float matrix[4][4];
213  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
214//   glRotatef(this->angle, 1.0f, 0.0f, 0.0f); //spinning missile
215  glRotatef(this->angle, this->flightDirection.x, this->flightDirection.y, this->flightDirection.z);
216  this->getAbsDir().matrix (matrix);
217  glMultMatrixf((float*)matrix);
218
219  glScalef(0.75/4, 0.7/16, 0.7/16);  // no double rescale
220
221  this->mat->select();
222  dynamic_cast<StaticModel*>(this->getModel())->draw();
223  this->mat->unselect();
224  glScalef(4/.75,16/.7,16/.7);
225  glTranslatef(-3,0,0);
226  this->trail->draw();
227  glPopMatrix();
228  glPopAttrib();
229
230}
Note: See TracBrowser for help on using the repository browser.