Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/heavy_blaster.cc @ 10472

Last change on this file since 10472 was 10472, checked in by patrick, 17 years ago

and frag cannon

File size: 8.5 KB
RevLine 
[9972]1#include "heavy_blaster.h"
[9975]2#include "world_entities/projectiles/projectile.h"
[9972]3
[9975]4#include "world_entity.h"
5#include "static_model.h"
6#include "weapon_manager.h"
7#include "util/loading/factory.h"
8
9#include "animation3d.h"
10
11#include "loading/fast_factory.h"
12
13CREATE_FACTORY(HeavyBlaster);
14/**
15 * Standard constructor
16 */
[10152]17HeavyBlaster::HeavyBlaster (int leftRight)
[9975]18 : Weapon()
19{
[10152]20    this->init(leftRight);
[9975]21}
22
[9972]23HeavyBlaster::HeavyBlaster (const TiXmlElement* root = NULL)
24 : Weapon()
[9975]25{
[10152]26    // TODO add leftRight to params
27    this->init(0);
[9972]28    if (root != NULL)
29      this->loadParams(root);
[9975]30}
[9972]31
32/**
33 * Default destructor
34 */
35HeavyBlaster::~HeavyBlaster()
[9975]36{
[10170]37  for (int i = 0; i < this->getBarrels(); i++)
38  {
[10261]39   delete [] this->shootAnim[i];
40   delete [] this->objComp[i];
41  }
42  delete [] this->emissionPoint;
[10415]43
[10281]44   delete [] this->shootAnim;
45   delete [] this->objComp;
[10261]46/*
[10170]47    for(int j = 0; j < this->getSegs(); j++)
48    {
49      delete this->shootAnim[i][j];
50      delete this->objComp[i][j];
51    }
52    delete this->shootAnim[i];
53    delete this->objComp[i];
54    delete this->emissionPoint[i];
[10261]55  }*/
[10170]56
[10261]57//  this->deconstr();
[10152]58     // model will be deleted from WorldEntity-destructor
[9975]59}
[9972]60
[9975]61void HeavyBlaster::loadParams(const TiXmlElement* root)
62{
63  Weapon::loadParams(root);
64}
[9972]65
[10152]66void HeavyBlaster::init(int leftRight)
[9975]67{
[10152]68
69  this->leftRight = leftRight;
[9975]70  //this->registerObject(this, HeavyBlaster::_objectList);
71
72//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
73
[10472]74  this->loadModel("models/guns/frag_cannon.obj", .4);
[9975]75
[10415]76
[9998]77  this->setStateDuration(WS_SHOOTING, 0.5);   // 2 Schuss pro Sekunde
[9975]78  this->setStateDuration(WS_RELOADING, 0);
79  this->setStateDuration(WS_ACTIVATING, .5);
80  this->setStateDuration(WS_DEACTIVATING, 1);
81
[9998]82  this->setEnergyMax(500);
83  this->increaseEnergy(500);
[9975]84  //this->minCharge = 2;
85
[10415]86  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
87  this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
88  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
[9975]89
90  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
[10188]91  this->setProjectileTypeC("HBolt");   // FIXME temp project type until the blaste class exist
[10170]92//   this->setProjectileTypeC("SpikeBall");   // FIXME temp project type until the blaste class exist
[9998]93  this->prepareProjectiles(5);
[9975]94
[10136]95  this->setBarrels(3);
96  this->setSegs(2);
[10152]97  this->activeBarrel = 0;
98//   this->init2();
[10136]99
[10133]100
[10152]101
102  this->objComp = new PNode**[this->getBarrels()];
103  this->emissionPoint = new PNode*[this->getBarrels()];
104  this->shootAnim = new Animation3D**[this->getBarrels()];
105  for (int i = 0; i < this->getBarrels(); i++)
106  {
107    this->objComp[i] = new PNode* [this->getSegs()];
108    this->emissionPoint[i] = new PNode;
109    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
110    this->emissionPoint[i]->setName("EmissionPoint");
111    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
112    this->shootAnim[i] = new Animation3D* [this->getSegs()];
113    for(int j = 0; j < this->getSegs(); j++)
114    {
115      this->objComp[i][j] = new PNode;
116      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
117      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
118    }
119  }
120
[10159]121  if (this->leftRight == W_RIGHT)
122  {
[10152]123    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, 0.06));
124    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, 0.14));
125    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, -.14));
[10159]126  }
127  else {
128    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, -.06));
129    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, -.14));
130    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, 0.14));
131  }
[10152]132
133
134//   Animation3D* animB0Shoot = this->getAnimation(WS_SHOOTING0, this->objComp[0][0]);
[10136]135//   Animation3D* animB1Shoot = this->getAnimation(WS_SHOOTING1, this->objComp2);
136//   Animation3D* animB2Shoot = this->getAnimation(WS_SHOOTING2, this->objComp3);
[10152]137//   Animation3D* animT0Shoot = this->getAnimation(WS_SHOOTING3, this->objComp[0][1]);
[10136]138//   Animation3D* animT1Shoot = this->getAnimation(WS_SHOOTING4, this->objComp5);
139//   Animation3D* animT2Shoot = this->getAnimation(WS_SHOOTING5, this->objComp6);
[10133]140
[10152]141
142//   this->shootAnim[0][0]->setInfinity(ANIM_INF_CONSTANT);
[10136]143//   animB1Shoot->setInfinity(ANIM_INF_CONSTANT);
144//   animB2Shoot->setInfinity(ANIM_INF_CONSTANT);
145//   animT0Shoot->setInfinity(ANIM_INF_CONSTANT);
146//   animT1Shoot->setInfinity(ANIM_INF_CONSTANT);
147//   animT2Shoot->setInfinity(ANIM_INF_CONSTANT);
[10133]148
[10152]149  for (int i = 0; i < this->getBarrels(); i++){
[10159]150    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
151    this->shootAnim[i][0]->addKeyFrame(Vector(-0.3, 0.0, 0.0), Quaternion(), 0.9, ANIM_LINEAR, ANIM_NULL);
152    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.55, ANIM_LINEAR, ANIM_NULL);
[10133]153
[10159]154    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
155    this->shootAnim[i][1]->addKeyFrame(Vector(-0.4, 0.0, 0.0), Quaternion(), 1.2, ANIM_LINEAR, ANIM_NULL);
156    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.25, ANIM_LINEAR, ANIM_NULL);
[10152]157  }
[10133]158
[9975]159  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
160  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
161
162  animation2->setInfinity(ANIM_INF_CONSTANT);
163  animation3->setInfinity(ANIM_INF_CONSTANT);
164
[10152]165//   this->setEmissionPoint(3.8, 1.2, 0, 0);
[9975]166
167  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
168  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
169
170  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
171  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
172}
173
174
175void HeavyBlaster::fire()
176{
177  Projectile* pj =  this->getProjectile();
178  if (pj == NULL)
179    return;
180
181  // set the owner
182  pj->setOwner(this->getOwner());
183  pj->setParent(PNode::getNullParent());
184
[10044]185//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
[10046]186//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
[10044]187  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
[9975]188
[10152]189  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
190//   pj->setAbsCoor(this->getEmissionPoint(0));
[9975]191  pj->setAbsDir(this->getAbsDir());
[10152]192//   pj->toList(OM_GROUP_01_PROJ);
[9975]193  pj->activate();
[10152]194
195  // initiate animation
196  for (int i = 0; i < this->getSegs(); i++)
197    this->shootAnim[this->activeBarrel][i]->replay();
198
199  // switch barrel
200  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
[9975]201}
202
203/**
204 *  this activates the weapon
205*/
206void HeavyBlaster::activate()
207{
208}
209
210/**
211 *  this deactivates the weapon
212*/
213void HeavyBlaster::deactivate()
214{
215}
216
[10152]217
[9975]218void HeavyBlaster::draw() const
219{
[10133]220  glMatrixMode(GL_MODELVIEW);
221  glPushMatrix();
222  glTranslatef (this->getAbsCoor ().x,
223                this->getAbsCoor ().y,
224                this->getAbsCoor ().z);
225
[10152]226  if (this->leftRight == W_LEFT)
227    glScalef(1.0, 1.0, -1.0);
228
[10133]229  static_cast<StaticModel*>(this->getModel())->draw(6);
230
231  glPushMatrix();
[10152]232    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
[10136]233    static_cast<StaticModel*>(this->getModel())->draw(1);
[10152]234  glPopMatrix();
[10136]235
[10133]236  glPushMatrix();
[10286]237    glTranslatef (this->objComp[1][0]->getAbsCoor().x, this->objComp[1][0]->getAbsCoor().y, this->objComp[1][0]->getAbsCoor().z);
238    static_cast<StaticModel*>(this->getModel())->draw(2);
[10133]239  glPopMatrix();
240
241  glPushMatrix();
[10286]242    glTranslatef (this->objComp[2][0]->getAbsCoor().x, this->objComp[2][0]->getAbsCoor().y, this->objComp[2][0]->getAbsCoor().z);
243    static_cast<StaticModel*>(this->getModel())->draw(0);
[10152]244  glPopMatrix();
[10136]245
[10133]246  glPushMatrix();
[10286]247    glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
[10152]248    static_cast<StaticModel*>(this->getModel())->draw(4);
249  glPopMatrix();
250
251  glPushMatrix();
[10286]252    glTranslatef (this->objComp[1][1]->getAbsCoor().x, this->objComp[1][1]->getAbsCoor().y, this->objComp[1][1]->getAbsCoor().z);
253    static_cast<StaticModel*>(this->getModel())->draw(5);
[10133]254  glPopMatrix();
255
256  glPushMatrix();
[10286]257    glTranslatef (this->objComp[2][1]->getAbsCoor().x, this->objComp[2][1]->getAbsCoor().y, this->objComp[2][1]->getAbsCoor().z);
258    static_cast<StaticModel*>(this->getModel())->draw(3);
[10152]259  glPopMatrix();
[10133]260
261  glPopMatrix();
[9975]262}
Note: See TracBrowser for help on using the repository browser.