Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10539 was 10539, checked in by marcscha, 17 years ago

Fixes for weapon systems

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