Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10761 was 10747, checked in by nicolasc, 18 years ago

cleaned out origList

File size: 5.7 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: 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->init();
41}
42
43Disruptor::Disruptor (const TiXmlElement* root = NULL)
44 : Weapon()
45{
46    // TODO add leftRight to params
47    this->init();
48    if (root != NULL)
49      this->loadParams(root);
50}
51
52/**
53 * Default destructor
54 */
55Disruptor::~Disruptor()
56{
57  for (int i = 0; i < this->getBarrels(); i++)
58  {
59   delete [] this->shootAnim[i];
60   delete [] this->objComp[i];
61  }
62  delete [] this->emissionPoint;
63
64   delete [] this->shootAnim;
65   delete [] this->objComp;
66
67}
68
69void Disruptor::loadParams(const TiXmlElement* root)
70{
71  Weapon::loadParams(root);
72}
73
74void Disruptor::init()
75{
76
77  this->setScaling(.5);
78
79  this->loadModel("models/guns/disruptor.obj", this->getScaling());
80
81
82  this->setStateDuration(WS_SHOOTING, 0.3333);  // 3 Shots per Second
83  this->setStateDuration(WS_RELOADING, 0);
84  this->setStateDuration(WS_ACTIVATING, .5);
85  this->setStateDuration(WS_DEACTIVATING, 1);
86
87  this->setEnergyMax(500);
88  this->increaseEnergy(500);
89  //this->minCharge = 2;
90
91  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
92//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
93  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
94
95  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
96  this->setProjectileTypeC("HBolt");
97  this->prepareProjectiles(10);
98
99  this->setBarrels(1);
100  this->setSegs(1);
101  this->activeBarrel = 0;
102
103
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;
112    this->emissionPoint[i]->setParent(this);  //Parenting emissionPoint to Weapon
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
124  this->emissionPoint[0]->setRelCoor(Vector(1.672, 0.0, 0.0) * this->getScaling());
125
126
127  this->shootAnim[0][0]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
128  this->shootAnim[0][0]->addKeyFrame(Vector(-0.5, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL);
129//   this->shootAnim[0][0]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
130
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
145void Disruptor::fire()
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
155  Vector tmp = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
156
157//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
158  pj->setVelocity((tmp.getNormalized())*130 + VECTOR_RAND(1));
159
160  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
161  pj->setAbsDir(this->getAbsDir());
162  pj->activate();
163
164
165  this->shootAnim[0][0]->replay();
166}
167
168/**
169 *  this activates the weapon
170*/
171void Disruptor::activate()
172{
173}
174
175/**
176 *  this deactivates the weapon
177*/
178void Disruptor::deactivate()
179{
180}
181
182
183void Disruptor::draw() const
184{
185  glPushMatrix();
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 );
192
193    //Base
194    static_cast<StaticModel*>(this->getModel())->draw(1);
195
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();
201  glPopMatrix();
202}
203
204void Disruptor::tick(float dt)
205{
206  if (!Weapon::tickW(dt))
207    return;
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.