Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/light_blaster.cc

Last change on this file was 10698, checked in by snellen, 17 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 5.2 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 "light_blaster.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
[10516]29#include "elements/glgui_energywidgetvertical.h"
30
[9972]31CREATE_FACTORY(LightBlaster);
32/**
33 * Standard constructor
34 */
35LightBlaster::LightBlaster ()
36 : Weapon()
37{
38    this->init();
39}
40
41LightBlaster::LightBlaster (const TiXmlElement* root = NULL)
42 : Weapon()
43{
44    this->init();
45    if (root != NULL)
46      this->loadParams(root);
47}
48
49/**
50 * Default destructor
51 */
52LightBlaster::~LightBlaster()
53{
[10261]54
[10170]55  for (int i = 0; i < this->getBarrels(); i++)
56  {
[10618]57   //delete [] this->shootAnim[i];
[10261]58   delete [] this->objComp[i];
59  }
60  delete [] this->emissionPoint;
[10618]61   //delete [] this->shootAnim;
[10261]62   delete [] this->objComp;
[10170]63
[9972]64}
65
66void LightBlaster::loadParams(const TiXmlElement* root)
67{
68  Weapon::loadParams(root);
69}
70
71void LightBlaster::init()
72{
73
[10471]74  this->loadModel("models/guns/gatling.obj", 0.333);
[9972]75
[10415]76
[9998]77  this->setStateDuration(WS_SHOOTING, 0.05);  // 20 Schuss pro Sekunde
[9972]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);
[9972]84  //this->minCharge = 2;
85
[10415]86  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
[10516]87//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
[10415]88  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
[9972]89
90  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
[10516]91  this->setProjectileTypeC("LBolt");
[10698]92  this->prepareProjectiles(25);
[9972]93
[10152]94  this->setBarrels(3);
95  this->setSegs(1);
96  this->activeBarrel = 0;
97
98  this->objComp = new PNode**[this->getBarrels()];
99  this->emissionPoint = new PNode*[this->getBarrels()];
[10618]100//   this->shootAnim = new Animation3D**[this->getBarrels()];
[10152]101  for (int i = 0; i < this->getBarrels(); i++)
102  {
103    this->objComp[i] = new PNode* [this->getSegs()];
104    this->emissionPoint[i] = new PNode;
[10618]105    this->emissionPoint[i]->setParent(this);
[10152]106    this->emissionPoint[i]->setName("EmissionPoint");
107    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
108    for(int j = 0; j < this->getSegs(); j++)
109    {
110      this->objComp[i][j] = new PNode;
[10618]111//       this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
112//       this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
[10152]113    }
114  }
115
[10618]116  this->emissionPoint[0]->setRelCoor(Vector(2.2, 0.0, 0.1));
117  this->emissionPoint[1]->setRelCoor(Vector(2.2, -0.07, -0.05));
118  this->emissionPoint[2]->setRelCoor(Vector(2.2, 0.07, -0.05));
[10152]119
120//   Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this);
[9972]121  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
122  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
123
[10152]124//   animation1->setInfinity(ANIM_INF_CONSTANT);
[9972]125  animation2->setInfinity(ANIM_INF_CONSTANT);
126  animation3->setInfinity(ANIM_INF_CONSTANT);
127
128
129  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
130  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
131
132  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
133  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
134}
135
136void LightBlaster::fire()
137{
138  Projectile* pj =  this->getProjectile();
139  if (pj == NULL)
140    return;
141
[9975]142  // set the owner
143  pj->setOwner(this->getOwner());
144
[9972]145  pj->setParent(PNode::getNullParent());
146
[10044]147//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
[10046]148  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180);
[9972]149
[10152]150  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
[9972]151  pj->setAbsDir(this->getAbsDir());
[10152]152//   pj->toList(OM_GROUP_01_PROJ);
[9972]153  pj->activate();
[10152]154
[10618]155//   for (int i = 0; i < this->getSegs(); i++)
156//     this->shootAnim[this->activeBarrel][i]->replay();
[10152]157
158  // switch barrel
159  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
[9972]160}
161
162/**
163 *  this activates the weapon
164*/
165void LightBlaster::activate()
166{
167}
168
169/**
170 *  this deactivates the weapon
171*/
172void LightBlaster::deactivate()
173{
[9975]174}
175
176void LightBlaster::draw() const
177{
[10152]178  glMatrixMode(GL_MODELVIEW);
179  glPushMatrix();
180    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
181    Vector tmpRot = this->getAbsDir().getSpacialAxis();
182    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
183    static_cast<StaticModel*>(this->getModel())->draw();
184  glPopMatrix();
[10516]185
[9975]186}
[10516]187
188void LightBlaster::tick(float dt)
189{
[10539]190  if (!Weapon::tickW(dt))
191    return;
[10516]192  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
193  {
194    this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png");
195    this->setEnergyWidgetInitialized(true);
196  }
197}
Note: See TracBrowser for help on using the repository browser.