Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/light_blaster.cc @ 10415

Last change on this file since 10415 was 10415, checked in by patrick, 17 years ago

changed the path names to reflect the new data repos

File size: 5.4 KB
Line 
1#include "light_blaster.h"
2#include "world_entities/projectiles/projectile.h"
3
4#include "world_entity.h"
5#include "static_model.h"
6#include "weapon_manager.h"
7#include "util/loading/factory.h"
8
9#include "animation3d.h"
10
11#include "loading/fast_factory.h"
12
13CREATE_FACTORY(LightBlaster);
14/**
15 * Standard constructor
16 */
17LightBlaster::LightBlaster ()
18 : Weapon()
19{
20    this->init();
21}
22
23LightBlaster::LightBlaster (const TiXmlElement* root = NULL)
24 : Weapon()
25{
26    this->init();
27    if (root != NULL)
28      this->loadParams(root);
29}
30
31/**
32 * Default destructor
33 */
34LightBlaster::~LightBlaster()
35{
36
37  for (int i = 0; i < this->getBarrels(); i++)
38  {
39   delete [] this->shootAnim[i];
40   delete [] this->objComp[i];
41  }
42  delete [] this->emissionPoint;
43   delete [] this->shootAnim;
44   delete [] this->objComp;
45/*
46    for(int j = 0; j < this->getSegs(); j++)
47    {
48      delete this->shootAnim[i][j];
49      delete this->objComp[i][j];
50    }
51    delete this->shootAnim[i];
52    delete this->objComp[i];
53    delete this->emissionPoint[i];
54  }*/
55
56//  this->deconstr();
57      // model will be deleted from WorldEntity-destructor
58}
59
60void LightBlaster::loadParams(const TiXmlElement* root)
61{
62  Weapon::loadParams(root);
63}
64
65void LightBlaster::init()
66{
67
68  this->loadModel("models/guns/gattling.obj", 0.333);
69
70
71  this->setStateDuration(WS_SHOOTING, 0.05);  // 20 Schuss pro Sekunde
72  this->setStateDuration(WS_RELOADING, 0);
73  this->setStateDuration(WS_ACTIVATING, .5);
74  this->setStateDuration(WS_DEACTIVATING, 1);
75
76  this->setEnergyMax(500);
77  this->increaseEnergy(500);
78  //this->minCharge = 2;
79
80  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
81  this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
82  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
83
84  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
85  //this->setProjectileTypeC("RailProjectile");   // FIXME temp project type until the blaste class exist
86  this->setProjectileTypeC("LBolt");   // Working; FIXME: add textures
87//   this->setProjectileTypeC("Spike");   // Working; FIXME: add textures
88  this->prepareProjectiles(100);
89
90  this->setBarrels(3);
91  this->setSegs(1);
92  this->activeBarrel = 0;
93
94  this->objComp = new PNode**[this->getBarrels()];
95  this->emissionPoint = new PNode*[this->getBarrels()];
96  this->shootAnim = new Animation3D**[this->getBarrels()];
97  for (int i = 0; i < this->getBarrels(); i++)
98  {
99    this->objComp[i] = new PNode* [this->getSegs()];
100    this->emissionPoint[i] = new PNode;
101    this->emissionPoint[i]->setParent(this);             //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles
102    this->emissionPoint[i]->setName("EmissionPoint");
103    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
104    this->shootAnim[i] = new Animation3D* [this->getSegs()];
105    for(int j = 0; j < this->getSegs(); j++)
106    {
107      this->objComp[i][j] = new PNode;
108      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
109      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
110    }
111  }
112
113  for (int i = 0; i < this->getBarrels(); i++ )
114    this->emissionPoint[i]->setRelCoor(Vector(1.19, 0.0, 0.1));
115
116//   Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this);
117  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
118  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
119
120//   animation1->setInfinity(ANIM_INF_CONSTANT);
121  animation2->setInfinity(ANIM_INF_CONSTANT);
122  animation3->setInfinity(ANIM_INF_CONSTANT);
123
124//   this->setEmissionPoint(3.8, 1.2, 0);
125
126  for (int i = 0; i < this->getBarrels(); i++){
127    this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion(i * 120, Vector(1.0, 0.0, 0.0)), 0.049, ANIM_NULL, ANIM_LINEAR);
128    this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion((i+1)*120, Vector(1.0, 0.0, 0.0)), 0.001, ANIM_NULL, ANIM_LINEAR);
129  }
130
131
132  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
133  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
134
135  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
136  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
137}
138
139
140void LightBlaster::fire()
141{
142  Projectile* pj =  this->getProjectile();
143  if (pj == NULL)
144    return;
145
146  // set the owner
147  pj->setOwner(this->getOwner());
148
149  pj->setParent(PNode::getNullParent());
150
151//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
152  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180);
153
154  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
155  pj->setAbsDir(this->getAbsDir());
156//   pj->toList(OM_GROUP_01_PROJ);
157  pj->activate();
158
159  for (int i = 0; i < this->getSegs(); i++)
160    this->shootAnim[this->activeBarrel][i]->replay();
161
162  // switch barrel
163  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
164}
165
166/**
167 *  this activates the weapon
168*/
169void LightBlaster::activate()
170{
171}
172
173/**
174 *  this deactivates the weapon
175*/
176void LightBlaster::deactivate()
177{
178}
179
180void LightBlaster::draw() const
181{
182  glMatrixMode(GL_MODELVIEW);
183  glPushMatrix();
184    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
185    Vector tmpRot = this->getAbsDir().getSpacialAxis();
186    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
187    static_cast<StaticModel*>(this->getModel())->draw();
188  glPopMatrix();
189}
Note: See TracBrowser for help on using the repository browser.