Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added nadion blast
fine tuned weapon timing / prepared projectiles

File size: 5.5 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  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
146  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
147
148  animation2->setInfinity(ANIM_INF_CONSTANT);
149  animation3->setInfinity(ANIM_INF_CONSTANT);
150
151  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
152  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
153
154  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
155  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
156}
157
158
159void Disruptor::fire()
160{
161  Projectile* pj =  this->getProjectile();
162  if (pj == NULL)
163    return;
164
165  // set the owner
166  pj->setOwner(this->getOwner());
167  pj->setParent(PNode::getNullParent());
168
169  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
170
171  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
172  pj->setAbsDir(this->getAbsDir());
173  pj->activate();
174
175  // initiate animation
176//   for (int i = 0; i < this->getSegs(); i++)
177//     this->shootAnim[this->activeBarrel][i]->replay();
178
179  // switch barrel
180//   this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
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  static_cast<StaticModel*>(this->getModel())->draw();
209
210  glPopMatrix();
211}
212
213void Disruptor::tick(float dt)
214{
215  if (!Weapon::tickW(dt))
216    return;
217  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
218  {
219    this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png");
220    this->setEnergyWidgetInitialized(true);
221  }
222}
Note: See TracBrowser for help on using the repository browser.