Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/heavy_blaster.cc @ 10562

Last change on this file since 10562 was 10548, checked in by nicolasc, 18 years ago

beautification fixes

File size: 8.9 KB
Line 
1#include "heavy_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
13#include "elements/glgui_energywidgetvertical.h"
14
15CREATE_FACTORY(HeavyBlaster);
16// ObjectListDefinition(HeavyBlaster);
17
18
19
20/**
21 * Standard constructor
22 */
23HeavyBlaster::HeavyBlaster (int leftRight)
24 : Weapon()
25{
26//     this->registerObject(this, HeavyBlaster::_objectList);
27
28    this->init(leftRight);
29}
30
31HeavyBlaster::HeavyBlaster (const TiXmlElement* root = NULL)
32 : Weapon()
33{
34//     this->registerObject(this, HeavyBlaster::_objectList);
35
36    // TODO add leftRight to params
37    this->init(0);
38    if (root != NULL)
39      this->loadParams(root);
40}
41
42/**
43 * Default destructor
44 */
45HeavyBlaster::~HeavyBlaster()
46{
47  for (int i = 0; i < this->getBarrels(); i++)
48  {
49   delete [] this->shootAnim[i];
50   delete [] this->objComp[i];
51  }
52  delete [] this->emissionPoint;
53
54   delete [] this->shootAnim;
55   delete [] this->objComp;
56/*
57    for(int j = 0; j < this->getSegs(); j++)
58    {
59      delete this->shootAnim[i][j];
60      delete this->objComp[i][j];
61    }
62    delete this->shootAnim[i];
63    delete this->objComp[i];
64    delete this->emissionPoint[i];
65  }*/
66
67//  this->deconstr();
68     // model will be deleted from WorldEntity-destructor
69}
70
71void HeavyBlaster::loadParams(const TiXmlElement* root)
72{
73  Weapon::loadParams(root);
74}
75
76void HeavyBlaster::init(int leftRight)
77{
78
79  this->leftRight = leftRight;
80  //this->registerObject(this, HeavyBlaster::_objectList);
81
82//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
83
84  this->loadModel("models/guns/frag_cannon.obj", .4);
85
86
87  this->setStateDuration(WS_SHOOTING, 0.5);   // 2 Schuss pro Sekunde
88  this->setStateDuration(WS_RELOADING, 0);
89  this->setStateDuration(WS_ACTIVATING, .5);
90  this->setStateDuration(WS_DEACTIVATING, 1);
91
92  this->setEnergyMax(500);
93  this->increaseEnergy(500);
94  //this->minCharge = 2;
95
96  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
97//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
98  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
99
100  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
101  this->setProjectileTypeC("HBolt");
102  this->prepareProjectiles(5);
103
104  this->setBarrels(3);
105  this->setSegs(2);
106  this->activeBarrel = 0;
107
108
109
110  this->objComp = new PNode**[this->getBarrels()];
111  this->emissionPoint = new PNode*[this->getBarrels()];
112  this->shootAnim = new Animation3D**[this->getBarrels()];
113  for (int i = 0; i < this->getBarrels(); i++)
114  {
115    this->objComp[i] = new PNode* [this->getSegs()];
116    this->emissionPoint[i] = new PNode;
117    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
118    this->emissionPoint[i]->setName("EmissionPoint");
119    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
120    this->shootAnim[i] = new Animation3D* [this->getSegs()];
121    for(int j = 0; j < this->getSegs(); j++)
122    {
123      this->objComp[i][j] = new PNode;
124      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
125      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
126    }
127  }
128
129  if (this->leftRight == W_RIGHT)
130  {
131    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, 0.06));
132    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, 0.14));
133    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, -.14));
134  }
135  else {
136    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, -.06));
137    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, -.14));
138    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, 0.14));
139  }
140
141
142//   Animation3D* animB0Shoot = this->getAnimation(WS_SHOOTING0, this->objComp[0][0]);
143//   Animation3D* animB1Shoot = this->getAnimation(WS_SHOOTING1, this->objComp2);
144//   Animation3D* animB2Shoot = this->getAnimation(WS_SHOOTING2, this->objComp3);
145//   Animation3D* animT0Shoot = this->getAnimation(WS_SHOOTING3, this->objComp[0][1]);
146//   Animation3D* animT1Shoot = this->getAnimation(WS_SHOOTING4, this->objComp5);
147//   Animation3D* animT2Shoot = this->getAnimation(WS_SHOOTING5, this->objComp6);
148
149
150//   this->shootAnim[0][0]->setInfinity(ANIM_INF_CONSTANT);
151//   animB1Shoot->setInfinity(ANIM_INF_CONSTANT);
152//   animB2Shoot->setInfinity(ANIM_INF_CONSTANT);
153//   animT0Shoot->setInfinity(ANIM_INF_CONSTANT);
154//   animT1Shoot->setInfinity(ANIM_INF_CONSTANT);
155//   animT2Shoot->setInfinity(ANIM_INF_CONSTANT);
156
157  for (int i = 0; i < this->getBarrels(); i++){
158    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
159    this->shootAnim[i][0]->addKeyFrame(Vector(-0.3, 0.0, 0.0), Quaternion(), 0.9, ANIM_LINEAR, ANIM_NULL);
160    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.55, ANIM_LINEAR, ANIM_NULL);
161
162    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
163    this->shootAnim[i][1]->addKeyFrame(Vector(-0.4, 0.0, 0.0), Quaternion(), 1.2, ANIM_LINEAR, ANIM_NULL);
164    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.25, ANIM_LINEAR, ANIM_NULL);
165  }
166
167  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
168  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
169
170  animation2->setInfinity(ANIM_INF_CONSTANT);
171  animation3->setInfinity(ANIM_INF_CONSTANT);
172
173//   this->setEmissionPoint(3.8, 1.2, 0, 0);
174
175  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
176  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
177
178  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
179  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
180}
181
182
183void HeavyBlaster::fire()
184{
185  Projectile* pj =  this->getProjectile();
186  if (pj == NULL)
187    return;
188
189  // set the owner
190  pj->setOwner(this->getOwner());
191  pj->setParent(PNode::getNullParent());
192
193//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
194//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
195  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
196
197  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
198//   pj->setAbsCoor(this->getEmissionPoint(0));
199  pj->setAbsDir(this->getAbsDir());
200//   pj->toList(OM_GROUP_01_PROJ);
201  pj->activate();
202
203  // initiate animation
204  for (int i = 0; i < this->getSegs(); i++)
205    this->shootAnim[this->activeBarrel][i]->replay();
206
207  // switch barrel
208  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
209}
210
211/**
212 *  this activates the weapon
213*/
214void HeavyBlaster::activate()
215{
216}
217
218/**
219 *  this deactivates the weapon
220*/
221void HeavyBlaster::deactivate()
222{
223}
224
225
226void HeavyBlaster::draw() const
227{
228  glMatrixMode(GL_MODELVIEW);
229  glPushMatrix();
230  glTranslatef (this->getAbsCoor ().x,
231                this->getAbsCoor ().y,
232                this->getAbsCoor ().z);
233    Vector tmpRot = this->getAbsDir().getSpacialAxis();
234    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
235
236  if (this->leftRight == W_LEFT)
237    glScalef(1.0, 1.0, -1.0);
238
239  static_cast<StaticModel*>(this->getModel())->draw(6);
240
241  glPushMatrix();
242    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
243    static_cast<StaticModel*>(this->getModel())->draw(2);
244  glPopMatrix();
245
246  glPushMatrix();
247    glTranslatef (this->objComp[1][0]->getAbsCoor().x, this->objComp[1][0]->getAbsCoor().y, this->objComp[1][0]->getAbsCoor().z);
248    static_cast<StaticModel*>(this->getModel())->draw(3);
249  glPopMatrix();
250
251  glPushMatrix();
252    glTranslatef (this->objComp[2][0]->getAbsCoor().x, this->objComp[2][0]->getAbsCoor().y, this->objComp[2][0]->getAbsCoor().z);
253    static_cast<StaticModel*>(this->getModel())->draw(1);
254  glPopMatrix();
255
256  glPushMatrix();
257    glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
258    static_cast<StaticModel*>(this->getModel())->draw(4);
259  glPopMatrix();
260
261  glPushMatrix();
262    glTranslatef (this->objComp[1][1]->getAbsCoor().x, this->objComp[1][1]->getAbsCoor().y, this->objComp[1][1]->getAbsCoor().z);
263    static_cast<StaticModel*>(this->getModel())->draw(5);
264  glPopMatrix();
265
266  glPushMatrix();
267    glTranslatef (this->objComp[2][1]->getAbsCoor().x, this->objComp[2][1]->getAbsCoor().y, this->objComp[2][1]->getAbsCoor().z);
268    static_cast<StaticModel*>(this->getModel())->draw(0);
269  glPopMatrix();
270
271  glPopMatrix();
272}
273
274void HeavyBlaster::tick(float dt)
275{
276  if (!Weapon::tickW(dt))
277    return;
278  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
279  {
280    this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png");
281    this->setEnergyWidgetInitialized(true);
282  }
283}
Note: See TracBrowser for help on using the repository browser.