Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged cleanup into trunk (only improvements)

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