Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/hbolt.cc @ 10566

Last change on this file since 10566 was 10545, checked in by marcscha, 18 years ago

pirate explosion fix

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