Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/disruptor.cc @ 10755

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

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

File size: 5.9 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 "disruptor.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
31ObjectListDefinition(Disruptor);
32CREATE_FACTORY(Disruptor);
33
34/**
35 * Standard constructor
36 */
37Disruptor::Disruptor ()
38 : Weapon()
39{
40//     this->registerObject(this, Disruptor::_objectList);
41
42    this->init();
43}
44
45Disruptor::Disruptor (const TiXmlElement* root = NULL)
46 : Weapon()
47{
48//     this->registerObject(this, Disruptor::_objectList);
49
50    // TODO add leftRight to params
51    this->init();
52    if (root != NULL)
53      this->loadParams(root);
54}
55
56/**
57 * Default destructor
58 */
59Disruptor::~Disruptor()
60{
61  for (int i = 0; i < this->getBarrels(); i++)
62  {
63   delete [] this->shootAnim[i];
64   delete [] this->objComp[i];
65  }
66  delete [] this->emissionPoint;
67
68   delete [] this->shootAnim;
69   delete [] this->objComp;
70/*
71    for(int j = 0; j < this->getSegs(); j++)
72    {
73      delete this->shootAnim[i][j];
74      delete this->objComp[i][j];
75    }
76    delete this->shootAnim[i];
77    delete this->objComp[i];
78    delete this->emissionPoint[i];
79  }*/
80
81//  this->deconstr();
82     // model will be deleted from WorldEntity-destructor
83}
84
85void Disruptor::loadParams(const TiXmlElement* root)
86{
87  Weapon::loadParams(root);
88}
89
90void Disruptor::init()
91{
92
93  this->setScaling(.5);
94
95  this->loadModel("models/guns/disruptor.obj", this->getScaling());
96
97
98  this->setStateDuration(WS_SHOOTING, 0.3333);  // 3 Shots per Second
99  this->setStateDuration(WS_RELOADING, 0);
100  this->setStateDuration(WS_ACTIVATING, .5);
101  this->setStateDuration(WS_DEACTIVATING, 1);
102
103  this->setEnergyMax(500);
104  this->increaseEnergy(500);
105  //this->minCharge = 2;
106
107  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
108//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
109  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
110
111  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
112  this->setProjectileTypeC("HBolt");
113  this->prepareProjectiles(10);
114
115  this->setBarrels(1);
116  this->setSegs(1);
117  this->activeBarrel = 0;
118
119
120
121  this->objComp = new PNode**[this->getBarrels()];
122  this->emissionPoint = new PNode*[this->getBarrels()];
123  this->shootAnim = new Animation3D**[this->getBarrels()];
124  for (int i = 0; i < this->getBarrels(); i++)
125  {
126    this->objComp[i] = new PNode* [this->getSegs()];
127    this->emissionPoint[i] = new PNode;
128    this->emissionPoint[i]->setParent(this);  //Parenting emissionPoint to Weapon
129    this->emissionPoint[i]->setName("EmissionPoint");
130    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
131    this->shootAnim[i] = new Animation3D* [this->getSegs()];
132    for(int j = 0; j < this->getSegs(); j++)
133    {
134      this->objComp[i][j] = new PNode;
135      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
136      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
137    }
138  }
139
140  this->emissionPoint[0]->setRelCoor(Vector(1.672, 0.0, 0.0) * this->getScaling());
141
142
143  this->shootAnim[0][0]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
144  this->shootAnim[0][0]->addKeyFrame(Vector(-0.5, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL);
145//   this->shootAnim[0][0]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
146
147  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
148  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
149
150  animation2->setInfinity(ANIM_INF_CONSTANT);
151  animation3->setInfinity(ANIM_INF_CONSTANT);
152
153  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
154  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
155
156  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
157  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
158}
159
160
161void Disruptor::fire()
162{
163  Projectile* pj =  this->getProjectile();
164  if (pj == NULL)
165    return;
166
167  // set the owner
168  pj->setOwner(this->getOwner());
169  pj->setParent(PNode::getNullParent());
170
171  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
172
173  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
174  pj->setAbsDir(this->getAbsDir());
175  pj->activate();
176
177
178  this->shootAnim[0][0]->replay();
179
180
181}
182
183/**
184 *  this activates the weapon
185*/
186void Disruptor::activate()
187{
188}
189
190/**
191 *  this deactivates the weapon
192*/
193void Disruptor::deactivate()
194{
195}
196
197
198void Disruptor::draw() const
199{
200  glMatrixMode(GL_MODELVIEW);
201  glPushMatrix();
202  glTranslatef (this->getAbsCoor ().x,
203                this->getAbsCoor ().y,
204                this->getAbsCoor ().z);
205    Vector tmpRot = this->getAbsDir().getSpacialAxis();
206    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
207
208  //Base
209  static_cast<StaticModel*>(this->getModel())->draw(1);
210
211  // Barrel  glPushMatrix();
212  glTranslatef
213    (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
214    static_cast<StaticModel*>(this->getModel())->draw(0);
215  glPopMatrix();
216}
217
218void Disruptor::tick(float dt)
219{
220  if (!Weapon::tickW(dt))
221    return;
222  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
223  {
224    this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png");
225    this->setEnergyWidgetInitialized(true);
226  }
227}
Note: See TracBrowser for help on using the repository browser.