Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/disruptor.cc @ 10733

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

AbsDir fix, quite a hack

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