Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/medium_blaster.cc @ 10580

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

beautification fixes

File size: 5.3 KB
Line 
1#include "medium_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
15//
16//ObjectListDefinition(MediumBlaster);
17CREATE_FACTORY(MediumBlaster);
18/**
19 * Standard constructor
20 */
21MediumBlaster::MediumBlaster ()
22 : Weapon()
23{
24    this->init();
25}
26
27MediumBlaster::MediumBlaster (const TiXmlElement* root = NULL)
28 : Weapon()
29{
30    this->init();
31    if (root != NULL)
32      this->loadParams(root);
33}
34
35/**
36 * Default destructor
37 */
38MediumBlaster::~MediumBlaster()
39{
40      // model will be deleted from WorldEntity-destructor
41  for (int i = 0; i < this->getBarrels(); i++)
42  {
43   delete [] this->shootAnim[i];
44  }
45  delete [] this->shootAnim;
46}
47
48void MediumBlaster::loadParams(const TiXmlElement* root)
49{
50  Weapon::loadParams(root);
51}
52
53void MediumBlaster::init()
54{
55  this->loadModel("models/guns/blaster.obj", .33);
56
57  this->setStateDuration(WS_SHOOTING, 0.2);   // 5 Schuss pro Sekunde
58
59  this->setStateDuration(WS_RELOADING, 0);
60  this->setStateDuration(WS_ACTIVATING, .5); //.5);
61  this->setStateDuration(WS_DEACTIVATING, 1); // 1);
62
63  this->setEnergyMax(500);
64  this->increaseEnergy(500);
65  //this->minCharge = 2;
66
67  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
68  this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
69  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
70
71  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
72  this->setProjectileTypeC("MBolt");   // FIXME temp project type until the blaste class exist
73  this->prepareProjectiles(100);
74
75
76  this->setBarrels(1);
77  this->setSegs(2);
78  this->activeBarrel = 0;
79
80  this->objComp = new PNode**[this->getBarrels()];
81  this->shootAnim = new Animation3D**[this->getBarrels()];
82  for (int i = 0; i < this->getBarrels(); i++)
83  {
84    this->objComp[i] = new PNode* [this->getSegs()];
85    this->shootAnim[i] = new Animation3D* [this->getSegs()];
86    for(int j = 0; j < this->getSegs(); j++)
87    {
88      this->objComp[i][j] = new PNode;
89      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
90      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
91    }
92  }
93
94  for (int i = 0; i < this->getBarrels(); i++){
95    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
96    this->shootAnim[i][0]->addKeyFrame(Vector(-0.333, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
97    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
98
99    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
100    this->shootAnim[i][1]->addKeyFrame(Vector(.166, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
101    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
102  }
103
104  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
105  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
106
107  animation2->setInfinity(ANIM_INF_CONSTANT);
108  animation3->setInfinity(ANIM_INF_CONSTANT);
109
110
111  this->setEmissionPoint(1.3, 0, 0);
112
113  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
114  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
115
116  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
117  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
118}
119
120
121void MediumBlaster::fire()
122{
123  Projectile* pj =  this->getProjectile();
124  if (pj == NULL)
125    return;
126
127  // set the owner
128  pj->setOwner(this->getOwner());
129
130  pj->setParent(PNode::getNullParent());
131
132  pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160);
133
134  pj->setAbsCoor(this->getEmissionPoint());
135  pj->setAbsDir(this->getAbsDir());
136  pj->activate();
137
138  for (int i = 0; i < this->getSegs(); i++)
139    this->shootAnim[this->activeBarrel][i]->replay();
140}
141
142
143/**
144 *  this activates the weapon
145*/
146void MediumBlaster::activate()
147{
148}
149
150/**
151 *  this deactivates the weapon
152*/
153void MediumBlaster::deactivate()
154{
155}
156
157void MediumBlaster::draw() const
158{
159  glMatrixMode(GL_MODELVIEW);
160  glPushMatrix();
161    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
162    Vector tmpRot = this->getAbsDir().getSpacialAxis();
163    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
164    static_cast<StaticModel*>(this->getModel())->draw(0);
165
166  glPushMatrix();
167    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
168    static_cast<StaticModel*>(this->getModel())->draw(1);
169  glPopMatrix();
170
171  glPushMatrix();
172    glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
173    static_cast<StaticModel*>(this->getModel())->draw(2);
174  glPopMatrix();
175
176  glPopMatrix();
177}
178
179void MediumBlaster::tick(float dt)
180{
181  if (!Weapon::tickW(dt))
182    return;
183  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
184  {
185    this->energyWidget->setDisplayedImage("textures/gui/gui_medium_bold.png");
186    this->setEnergyWidgetInitialized(true);
187  }
188}
Note: See TracBrowser for help on using the repository browser.