Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10698 was 10698, checked in by snellen, 17 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 8.2 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_cannon2.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);      //Parenting emissionPoint to Weapons
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  for (int i = 0; i < this->getBarrels(); i++){
159    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
160    this->shootAnim[i][0]->addKeyFrame(Vector(-0.3, 0.0, 0.0), Quaternion(), 0.9, ANIM_LINEAR, ANIM_NULL);
161    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
162
163    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
164    this->shootAnim[i][1]->addKeyFrame(Vector(-0.4, 0.0, 0.0), Quaternion(), 1.2, ANIM_LINEAR, ANIM_NULL);
165    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL);
166  }
167
168  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
169  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
170
171  animation2->setInfinity(ANIM_INF_CONSTANT);
172  animation3->setInfinity(ANIM_INF_CONSTANT);
173
174  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
175  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
176
177  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
178  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
179}
180
181
182void HeavyBlaster::fire()
183{
184  Projectile* pj =  this->getProjectile();
185  if (pj == NULL)
186    return;
187
188  // set the owner
189  pj->setOwner(this->getOwner());
190  pj->setParent(PNode::getNullParent());
191
192  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
193
194  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
195  pj->setAbsDir(this->getAbsDir());
196  pj->activate();
197
198  // initiate animation
199  for (int i = 0; i < this->getSegs(); i++)
200    this->shootAnim[this->activeBarrel][i]->replay();
201
202  // switch barrel
203  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
204}
205
206/**
207 *  this activates the weapon
208*/
209void HeavyBlaster::activate()
210{
211}
212
213/**
214 *  this deactivates the weapon
215*/
216void HeavyBlaster::deactivate()
217{
218}
219
220
221void HeavyBlaster::draw() const
222{
223  glMatrixMode(GL_MODELVIEW);
224  glPushMatrix();
225  glTranslatef (this->getAbsCoor ().x,
226                this->getAbsCoor ().y,
227                this->getAbsCoor ().z);
228    Vector tmpRot = this->getAbsDir().getSpacialAxis();
229    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
230
231  if (this->leftRight == W_LEFT)
232    glScalef(1.0, 1.0, -1.0);
233
234  static_cast<StaticModel*>(this->getModel())->draw(6);
235
236  glPushMatrix();
237    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
238    static_cast<StaticModel*>(this->getModel())->draw(2);
239  glPopMatrix();
240
241  glPushMatrix();
242    glTranslatef (this->objComp[1][0]->getAbsCoor().x, this->objComp[1][0]->getAbsCoor().y, this->objComp[1][0]->getAbsCoor().z);
243    static_cast<StaticModel*>(this->getModel())->draw(3);
244  glPopMatrix();
245
246  glPushMatrix();
247    glTranslatef (this->objComp[2][0]->getAbsCoor().x, this->objComp[2][0]->getAbsCoor().y, this->objComp[2][0]->getAbsCoor().z);
248    static_cast<StaticModel*>(this->getModel())->draw(1);
249  glPopMatrix();
250
251  glPushMatrix();
252    glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
253    static_cast<StaticModel*>(this->getModel())->draw(4);
254  glPopMatrix();
255
256  glPushMatrix();
257    glTranslatef (this->objComp[1][1]->getAbsCoor().x, this->objComp[1][1]->getAbsCoor().y, this->objComp[1][1]->getAbsCoor().z);
258    static_cast<StaticModel*>(this->getModel())->draw(5);
259  glPopMatrix();
260
261  glPushMatrix();
262    glTranslatef (this->objComp[2][1]->getAbsCoor().x, this->objComp[2][1]->getAbsCoor().y, this->objComp[2][1]->getAbsCoor().z);
263    static_cast<StaticModel*>(this->getModel())->draw(0);
264  glPopMatrix();
265
266  glPopMatrix();
267}
268
269void HeavyBlaster::tick(float dt)
270{
271  if (!Weapon::tickW(dt))
272    return;
273  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
274  {
275    this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png");
276    this->setEnergyWidgetInitialized(true);
277  }
278}
Note: See TracBrowser for help on using the repository browser.