Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10627 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 5.0 KB
RevLine 
[10047]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
[10104]4   Copyright (C) 2004-2006 orx
[10047]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
[10104]12   main-programmer: Nicolas Schlumberger, Marc Schaerrer
[10047]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"
[10545]22#include "world_entities/npcs/npc.h"
[10047]23
24#include "particles/dot_emitter.h"
25#include "particles/sprite_particles.h"
26
27#include <cassert>
28#include "debug.h"
29
[10074]30// #include "effects/billboard.h"
[10079]31#include "space_ships/space_ship.h"
[10366]32#include "npcs/npc.h"
[10047]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
[10072]44  this->loadModel("models/projectiles/hbolt.obj",1.1);
[10047]45
46  this->setMinEnergy(10);
47  this->setHealthMax(0);
[10274]48  this->lifeSpan = 2.0;
[10047]49
50  this->angle = 0;
[10618]51//   this->rotationSpeed = 600;
[10047]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
[10063]59  this->halo = new Billboard();
60  this->halo->setSize(.65, .65);
61  this->halo->setTexture("hbolt_halo2.png");
[10511]62  this->halo->setVisibility(false);
[10345]63
[10047]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{
[10511]89  this->halo->setVisibility(true);
[10345]90  this->origList = this->getOMListNumber();
[10274]91  this->toList(OM_ENVIRON);
[10047]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
[10079]105  this->setPhysDamage(100);
[10047]106  this->setHealth(0);
107}
108
109
110void HBolt::deactivate()
111{
[10511]112  this->halo->setVisibility(false);
[10047]113  assert (HBolt::explosionParticles != NULL);
114  HBolt::explosionParticles->removeEmitter(this->emitter);
115  this->lifeCycle = 0.0;
116
[10274]117  this->toList(OM_DEAD);
[10047]118  this->removeNode();
119  HBolt::fastFactory->kill(this);
[10274]120
[10047]121}
122
[10261]123
[10274]124void HBolt::hit (float damage, WorldEntity* entity )
[10047]125{
[10104]126  printf("Collision with HBolt\n");
[10366]127  if (this->hitEntity != entity && entity->isA(NPC::staticClassID()) || entity == this->target)
[10047]128    this->destroy( entity );
129  this->hitEntity = entity;
[10261]130 // dynamic_cast<SpaceShip*>(entity)->damage( this->getPhysDamage(), this->getElecDamage());
[10109]131  this->deactivate();
[10261]132}
[10047]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
[10618]148  this->angle += HBolt::rotationSpeed * dt;
[10047]149
[10545]150  for( ObjectList<NPC>::const_iterator eIterator = NPC::objectList().begin(); eIterator !=NPC::objectList().end(); eIterator++)
[10274]151  {
[10545]152    if( ((*eIterator)->getOMListNumber() != (this->origList -1))  && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8)
[10274]153    {
[10545]154      (*eIterator)->destroy(this); //hit (this->getDamage(),this);
[10274]155      this->deactivate();
156  PRINTF(0)("HBolt destroyed\n");
157    }
158  }
[10047]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
[10159]177  glPushAttrib(GL_ENABLE_BIT);
178  glDisable(GL_LIGHTING);
[10618]179//   glDisable(GL_FOG);
[10159]180
[10047]181  glMatrixMode(GL_MODELVIEW);
182  glPushMatrix();
183
[10618]184//     float matrix[4][4];
185    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
186    Vector tmpRot = this->getAbsDir().getSpacialAxis();
187    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
188    glRotatef(this->angle, 0.0, 0.0, 1.0);
189//     glMultMatrixf((float*)matrix);
190    this->getModel()->draw();
191    this->halo->draw();
[10047]192
193  glPopMatrix();
[10159]194  glPopAttrib();
195
[10047]196}
Note: See TracBrowser for help on using the repository browser.