Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability.old/src/world_entities/projectiles/lbolt.cc @ 10583

Last change on this file since 10583 was 10345, checked in by marcscha, 18 years ago

SegFault prevention hack in fast factory

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