Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

modular weapons inclusion

File size: 5.9 KB
RevLine 
[10618]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
[10648]17#include "disruptor.h"
[9975]18#include "world_entities/projectiles/projectile.h"
[9972]19
[9975]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
[10516]29#include "elements/glgui_energywidgetvertical.h"
30
[10661]31ObjectListDefinition(Disruptor);
[10648]32CREATE_FACTORY(Disruptor);
[10499]33
[9975]34/**
35 * Standard constructor
36 */
[10648]37Disruptor::Disruptor ()
[9975]38 : Weapon()
39{
[10648]40//     this->registerObject(this, Disruptor::_objectList);
[10499]41
[10648]42    this->init();
[9975]43}
44
[10648]45Disruptor::Disruptor (const TiXmlElement* root = NULL)
[9972]46 : Weapon()
[9975]47{
[10648]48//     this->registerObject(this, Disruptor::_objectList);
[10499]49
[10152]50    // TODO add leftRight to params
[10648]51    this->init();
[9972]52    if (root != NULL)
53      this->loadParams(root);
[9975]54}
[9972]55
56/**
57 * Default destructor
58 */
[10648]59Disruptor::~Disruptor()
[9975]60{
[10170]61  for (int i = 0; i < this->getBarrels(); i++)
62  {
[10261]63   delete [] this->shootAnim[i];
64   delete [] this->objComp[i];
65  }
66  delete [] this->emissionPoint;
[10415]67
[10281]68   delete [] this->shootAnim;
69   delete [] this->objComp;
[10261]70/*
[10170]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];
[10261]79  }*/
[10170]80
[10261]81//  this->deconstr();
[10152]82     // model will be deleted from WorldEntity-destructor
[9975]83}
[9972]84
[10648]85void Disruptor::loadParams(const TiXmlElement* root)
[9975]86{
87  Weapon::loadParams(root);
88}
[9972]89
[10648]90void Disruptor::init()
[9975]91{
[10152]92
[10648]93  this->setScaling(.5);
[9975]94
[10648]95  this->loadModel("models/guns/disruptor.obj", this->getScaling());
[9975]96
97
[10648]98  this->setStateDuration(WS_SHOOTING, 0.3333);  // 3 Shots per Second
[9975]99  this->setStateDuration(WS_RELOADING, 0);
100  this->setStateDuration(WS_ACTIVATING, .5);
101  this->setStateDuration(WS_DEACTIVATING, 1);
102
[9998]103  this->setEnergyMax(500);
104  this->increaseEnergy(500);
[9975]105  //this->minCharge = 2;
106
[10415]107  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
[10516]108//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
[10415]109  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
[9975]110
111  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
[10516]112  this->setProjectileTypeC("HBolt");
[10649]113  this->prepareProjectiles(10);
[9975]114
[10648]115  this->setBarrels(1);
116  this->setSegs(1);
[10152]117  this->activeBarrel = 0;
[10136]118
[10133]119
[10152]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;
[10648]128    this->emissionPoint[i]->setParent(this);  //Parenting emissionPoint to Weapon
[10152]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
[10648]140  this->emissionPoint[0]->setRelCoor(Vector(1.672, 0.0, 0.0) * this->getScaling());
[10152]141
142
[10650]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
[9975]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
[10648]161void Disruptor::fire()
[9975]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
[10044]171  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
[9975]172
[10152]173  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
[9975]174  pj->setAbsDir(this->getAbsDir());
175  pj->activate();
[10152]176
177
[10650]178  this->shootAnim[0][0]->replay();
179
180
[9975]181}
182
183/**
184 *  this activates the weapon
185*/
[10648]186void Disruptor::activate()
[9975]187{
188}
189
190/**
191 *  this deactivates the weapon
192*/
[10648]193void Disruptor::deactivate()
[9975]194{
195}
196
[10152]197
[10648]198void Disruptor::draw() const
[9975]199{
[10133]200  glMatrixMode(GL_MODELVIEW);
201  glPushMatrix();
202  glTranslatef (this->getAbsCoor ().x,
203                this->getAbsCoor ().y,
204                this->getAbsCoor ().z);
[10548]205    Vector tmpRot = this->getAbsDir().getSpacialAxis();
206    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[10133]207
[10650]208  //Base
209  static_cast<StaticModel*>(this->getModel())->draw(1);
[10152]210
[10650]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);
[10152]215  glPopMatrix();
[10650]216
217  glPopMatrix();
[9975]218}
[10516]219
[10648]220void Disruptor::tick(float dt)
[10516]221{
[10539]222  if (!Weapon::tickW(dt))
223    return;
[10516]224  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
225  {
226    this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png");
227    this->setEnergyWidgetInitialized(true);
228  }
229}
Note: See TracBrowser for help on using the repository browser.