Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/world_entities/weapons/disruptor.cc @ 10650

Last change on this file since 10650 was 10650, checked in by nicolasc, 17 years ago

updated disruptor

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