Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged cleanup into trunk (only improvements)

File size: 5.8 KB
RevLine 
[9999]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
[10104]4   Copyright (C) 2004-2006 orx
[9999]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: Marc Schaerrer
[9999]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
[10545]25#include "world_entities/npcs/npc.h"
26
[9999]27#include "particles/dot_emitter.h"
28#include "particles/sprite_particles.h"
29
[10064]30#include "space_ships/space_ship.h"
31
[9999]32#include <cassert>
33#include "debug.h"
34
[10042]35#include "static_model.h"
[9999]36
[10081]37#include "effects/trail.h"
[10042]38
[10081]39
[10366]40
[10064]41ObjectListDefinition(MBolt);
[9999]42CREATE_FAST_FACTORY_STATIC(MBolt);
43
44/**
45 *  standard constructor
46*/
47MBolt::MBolt () : Projectile()
48{
[10064]49  this->registerObject(this, MBolt::_objectList);
[10113]50  this->loadModel("models/projectiles/mbolt.obj",4);
[10081]51
[10366]52
[10042]53  //this->loadModel("models/projectiles/laser.obj");
[9999]54
[10036]55  this->setMinEnergy(4);
[9999]56  this->setHealthMax(0);
[10274]57  this->lifeSpan = 1.5;
[10042]58  this->angle     = 0;
[9999]59
[10064]60  //this->emitter = new DotEmitter(1000, 0, 0);
[10113]61  this->emitter = new DotEmitter(50, 0, 0);
[9999]62  this->emitter->setParent(this);
[10064]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());
[10042]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);
[10064]72  this->mat->setDiffuseMap("laser_add.png");
[10042]73  this->mat->setDiffuseMap("laser.png",1);
[10064]74
[10366]75  dynamic_cast<StaticModel*>(this->getModel())->addMaterial(*this->mat);
[10042]76  dynamic_cast<StaticModel*>(this->getModel())->finalize();
[10081]77
[10113]78  dynamic_cast<StaticModel*>(this->getModel())->rebuild();
[10261]79  //this->buildObbTree(4);
[10366]80
[10132]81  this->trail = new Trail(6, 4, .1, this);
[10095]82  //this->trail->setParent( this);
[10420]83  this->trail->setTexture( "textures/laser.png");
[10618]84//   this->trail->setAbsCoor(this->getAbsCoor() - Vector(.7,0,0));
85  this->trail->setAbsCoor(this->getAbsCoor() - this->getVelocity().getNormalized() * .7);
[10345]86
[9999]87}
88
89
90/**
91 *  standard deconstructor
[10078]92 *
93 */
[9999]94MBolt::~MBolt ()
95{
96
97  if (MBolt::explosionParticles != NULL && MBolt::objectList().size() <= 1)
98  {
[10042]99    if (ParticleSystem::objectList().exists(MBolt::explosionParticles))
100      delete MBolt::explosionParticles;
[9999]101    MBolt::explosionParticles = NULL;
[10081]102    PRINTF(1)("Deleting MBolt Explosion Particles\n");
[9999]103  }
[10168]104
105  delete this->emitter;
106  delete this->trail;
[9999]107}
108
109SpriteParticles* MBolt::explosionParticles = NULL;
110
111void MBolt::activate()
112{
[10345]113  this->origList = this->getOMListNumber();
[10274]114  this->toList(OM_ENVIRON);
[9999]115  if (unlikely(MBolt::explosionParticles == NULL))
116  {
117    MBolt::explosionParticles = new SpriteParticles(1000);
118    MBolt::explosionParticles->setName("MBoltExplosionParticles");
[10113]119    MBolt::explosionParticles->setLifeSpan(.2, .1);
[9999]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
[10081]128  this->setPhysDamage(10);
129  this->setElecDamage(0);
[9999]130  this->setHealth(0);
[10042]131
[10064]132  this->emitter->setSpread(0);
[10078]133  this->emitter->setEmissionRate(10.0);
[10113]134  this->emitter->setEmissionVelocity(50);
[9999]135}
136
137
138void MBolt::deactivate()
139{
140  assert (MBolt::explosionParticles != NULL);
141  MBolt::explosionParticles->removeEmitter(this->emitter);
142  this->lifeCycle = 0.0;
143
[10345]144  this->lifeCycle = 0.0;
145  this->toList(OM_NULL);
146  //this->toList(OM_DEAD);
[10117]147  this->removeNode();
[9999]148  MBolt::fastFactory->kill(this);
149}
150
[10274]151void MBolt::hit (float damage, WorldEntity* entity )
[9999]152{
[10113]153
[10117]154  if (this->hitEntity != entity)
155    this->destroy( entity );
156  this->hitEntity = entity;
[10261]157 // dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),this->getElecDamage());
[10132]158  //this->destroy(this);
159  this->deactivate();
[10366]160
[10117]161  return;
162
[10261]163}
[9999]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();
[10042]177
178  this->angle += MBolt::rotationSpeed * dt;
[10081]179  this->trail->tick(dt);
[10274]180
[10545]181  for( ObjectList<NPC>::const_iterator eIterator = NPC::objectList().begin(); eIterator !=NPC::objectList().end(); eIterator++)
[10274]182  {
[10345]183    if( ((*eIterator)->getOMListNumber() != (this->origList -1))  && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8)
[10274]184    {
[10545]185      (*eIterator)->destroy(this); //hit (this->getDamage(),this);
[10274]186      this->deactivate();
187      PRINTF(0)("MBolt destroyed\n");
188    }
189  }
[9999]190}
191
192/**
193 *  the function gets called, when the projectile is destroyed
194*/
195void MBolt::destroy (WorldEntity* killer)
196{
[10117]197  //this->deactivate();
[9999]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
[10042]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  this->getAbsDir().matrix (matrix);
216  glMultMatrixf((float*)matrix);
217
[10113]218  glScalef(0.75/4, 0.7/16, 0.7/16);  // no double rescale
[10042]219
220  this->mat->select();
221  dynamic_cast<StaticModel*>(this->getModel())->draw();
222  this->mat->unselect();
[10113]223  glScalef(4/.75,16/.7,16/.7);
224  glTranslatef(-3,0,0);
[10081]225  this->trail->draw();
[10042]226  glPopMatrix();
[9999]227  glPopAttrib();
[10042]228
[10140]229}
Note: See TracBrowser for help on using the repository browser.