Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/world_entities/weapons/heavy_blaster.cc @ 10644

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

update "weapon points"
refined the RFCannon

File size: 8.3 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
[9972]17#include "heavy_blaster.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
[9975]31CREATE_FACTORY(HeavyBlaster);
[10499]32// ObjectListDefinition(HeavyBlaster);
33
34
35
[9975]36/**
37 * Standard constructor
38 */
[10152]39HeavyBlaster::HeavyBlaster (int leftRight)
[9975]40 : Weapon()
41{
[10499]42//     this->registerObject(this, HeavyBlaster::_objectList);
43
[10152]44    this->init(leftRight);
[9975]45}
46
[9972]47HeavyBlaster::HeavyBlaster (const TiXmlElement* root = NULL)
48 : Weapon()
[9975]49{
[10499]50//     this->registerObject(this, HeavyBlaster::_objectList);
51
[10152]52    // TODO add leftRight to params
53    this->init(0);
[9972]54    if (root != NULL)
55      this->loadParams(root);
[9975]56}
[9972]57
58/**
59 * Default destructor
60 */
61HeavyBlaster::~HeavyBlaster()
[9975]62{
[10170]63  for (int i = 0; i < this->getBarrels(); i++)
64  {
[10261]65   delete [] this->shootAnim[i];
66   delete [] this->objComp[i];
67  }
68  delete [] this->emissionPoint;
[10415]69
[10281]70   delete [] this->shootAnim;
71   delete [] this->objComp;
[10261]72/*
[10170]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];
[10261]81  }*/
[10170]82
[10261]83//  this->deconstr();
[10152]84     // model will be deleted from WorldEntity-destructor
[9975]85}
[9972]86
[9975]87void HeavyBlaster::loadParams(const TiXmlElement* root)
88{
89  Weapon::loadParams(root);
90}
[9972]91
[10152]92void HeavyBlaster::init(int leftRight)
[9975]93{
[10152]94
95  this->leftRight = leftRight;
[9975]96  //this->registerObject(this, HeavyBlaster::_objectList);
97
98//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
99
[10472]100  this->loadModel("models/guns/frag_cannon.obj", .4);
[9975]101
[10415]102
[9998]103  this->setStateDuration(WS_SHOOTING, 0.5);   // 2 Schuss pro Sekunde
[9975]104  this->setStateDuration(WS_RELOADING, 0);
105  this->setStateDuration(WS_ACTIVATING, .5);
106  this->setStateDuration(WS_DEACTIVATING, 1);
107
[9998]108  this->setEnergyMax(500);
109  this->increaseEnergy(500);
[9975]110  //this->minCharge = 2;
111
[10415]112  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
[10516]113//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
[10415]114  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
[9975]115
116  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
[10516]117  this->setProjectileTypeC("HBolt");
[9998]118  this->prepareProjectiles(5);
[9975]119
[10136]120  this->setBarrels(3);
121  this->setSegs(2);
[10152]122  this->activeBarrel = 0;
[10136]123
[10133]124
[10152]125
126  this->objComp = new PNode**[this->getBarrels()];
127  this->emissionPoint = new PNode*[this->getBarrels()];
128  this->shootAnim = new Animation3D**[this->getBarrels()];
129  for (int i = 0; i < this->getBarrels(); i++)
130  {
131    this->objComp[i] = new PNode* [this->getSegs()];
132    this->emissionPoint[i] = new PNode;
133    this->emissionPoint[i]->setParent(this);             //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles
134    this->emissionPoint[i]->setName("EmissionPoint");
135    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
136    this->shootAnim[i] = new Animation3D* [this->getSegs()];
137    for(int j = 0; j < this->getSegs(); j++)
138    {
139      this->objComp[i][j] = new PNode;
140      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
141      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
142    }
143  }
144
[10159]145  if (this->leftRight == W_RIGHT)
146  {
[10152]147    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, 0.06));
148    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, 0.14));
149    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, -.14));
[10159]150  }
151  else {
152    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, -.06));
153    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, -.14));
154    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, 0.14));
155  }
[10152]156
157
158  for (int i = 0; i < this->getBarrels(); i++){
[10159]159    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
160    this->shootAnim[i][0]->addKeyFrame(Vector(-0.3, 0.0, 0.0), Quaternion(), 0.9, ANIM_LINEAR, ANIM_NULL);
161    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.55, ANIM_LINEAR, ANIM_NULL);
[10133]162
[10159]163    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
164    this->shootAnim[i][1]->addKeyFrame(Vector(-0.4, 0.0, 0.0), Quaternion(), 1.2, ANIM_LINEAR, ANIM_NULL);
165    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.25, ANIM_LINEAR, ANIM_NULL);
[10152]166  }
[10133]167
[9975]168  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
169  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
170
171  animation2->setInfinity(ANIM_INF_CONSTANT);
172  animation3->setInfinity(ANIM_INF_CONSTANT);
173
174  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
175  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
176
177  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
178  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
179}
180
181
182void HeavyBlaster::fire()
183{
184  Projectile* pj =  this->getProjectile();
185  if (pj == NULL)
186    return;
187
188  // set the owner
189  pj->setOwner(this->getOwner());
190  pj->setParent(PNode::getNullParent());
191
[10044]192  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
[9975]193
[10152]194  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
[9975]195  pj->setAbsDir(this->getAbsDir());
196  pj->activate();
[10152]197
198  // initiate animation
199  for (int i = 0; i < this->getSegs(); i++)
200    this->shootAnim[this->activeBarrel][i]->replay();
201
202  // switch barrel
203  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
[9975]204}
205
206/**
207 *  this activates the weapon
208*/
209void HeavyBlaster::activate()
210{
211}
212
213/**
214 *  this deactivates the weapon
215*/
216void HeavyBlaster::deactivate()
217{
218}
219
[10152]220
[9975]221void HeavyBlaster::draw() const
222{
[10133]223  glMatrixMode(GL_MODELVIEW);
224  glPushMatrix();
225  glTranslatef (this->getAbsCoor ().x,
226                this->getAbsCoor ().y,
227                this->getAbsCoor ().z);
[10548]228    Vector tmpRot = this->getAbsDir().getSpacialAxis();
229    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[10133]230
[10152]231  if (this->leftRight == W_LEFT)
232    glScalef(1.0, 1.0, -1.0);
233
[10133]234  static_cast<StaticModel*>(this->getModel())->draw(6);
235
236  glPushMatrix();
[10152]237    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
[10516]238    static_cast<StaticModel*>(this->getModel())->draw(2);
[10152]239  glPopMatrix();
[10136]240
[10133]241  glPushMatrix();
[10286]242    glTranslatef (this->objComp[1][0]->getAbsCoor().x, this->objComp[1][0]->getAbsCoor().y, this->objComp[1][0]->getAbsCoor().z);
[10516]243    static_cast<StaticModel*>(this->getModel())->draw(3);
[10133]244  glPopMatrix();
245
246  glPushMatrix();
[10286]247    glTranslatef (this->objComp[2][0]->getAbsCoor().x, this->objComp[2][0]->getAbsCoor().y, this->objComp[2][0]->getAbsCoor().z);
[10516]248    static_cast<StaticModel*>(this->getModel())->draw(1);
[10152]249  glPopMatrix();
[10136]250
[10133]251  glPushMatrix();
[10286]252    glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
[10152]253    static_cast<StaticModel*>(this->getModel())->draw(4);
254  glPopMatrix();
255
256  glPushMatrix();
[10286]257    glTranslatef (this->objComp[1][1]->getAbsCoor().x, this->objComp[1][1]->getAbsCoor().y, this->objComp[1][1]->getAbsCoor().z);
258    static_cast<StaticModel*>(this->getModel())->draw(5);
[10133]259  glPopMatrix();
260
261  glPushMatrix();
[10286]262    glTranslatef (this->objComp[2][1]->getAbsCoor().x, this->objComp[2][1]->getAbsCoor().y, this->objComp[2][1]->getAbsCoor().z);
[10516]263    static_cast<StaticModel*>(this->getModel())->draw(0);
[10152]264  glPopMatrix();
[10133]265
266  glPopMatrix();
[9975]267}
[10516]268
269void HeavyBlaster::tick(float dt)
270{
[10539]271  if (!Weapon::tickW(dt))
272    return;
[10516]273  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
274  {
275    this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png");
276    this->setEnergyWidgetInitialized(true);
277  }
278}
Note: See TracBrowser for help on using the repository browser.