Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/projectiles/hbolt.cc @ 10747

Last change on this file since 10747 was 10747, checked in by nicolasc, 17 years ago

cleaned out origList

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