Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cleanup/src/world_entities/weapons/light_blaster.cc @ 10579

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

fixed some headers
commeted none existing sounds, to remove warnings

File size: 5.6 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: Marc Schaerrer, Nicolas Schlumberger
13   co-programmer:
14
15*/
16
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
29#include "elements/glgui_energywidgetvertical.h"
30
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{
54
55  for (int i = 0; i < this->getBarrels(); i++)
56  {
57   delete [] this->shootAnim[i];
58   delete [] this->objComp[i];
59  }
60  delete [] this->emissionPoint;
61   delete [] this->shootAnim;
62   delete [] this->objComp;
63
64}
65
66void LightBlaster::loadParams(const TiXmlElement* root)
67{
68  Weapon::loadParams(root);
69}
70
71void LightBlaster::init()
72{
73
74  this->loadModel("models/guns/gatling.obj", 0.333);
75
76
77  this->setStateDuration(WS_SHOOTING, 0.05);  // 20 Schuss pro Sekunde
78  this->setStateDuration(WS_RELOADING, 0);
79  this->setStateDuration(WS_ACTIVATING, .5);
80  this->setStateDuration(WS_DEACTIVATING, 1);
81
82  this->setEnergyMax(500);
83  this->increaseEnergy(500);
84  //this->minCharge = 2;
85
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");
89
90  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
91  this->setProjectileTypeC("LBolt");
92  this->prepareProjectiles(100);
93
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()];
100  this->shootAnim = new Animation3D**[this->getBarrels()];
101  for (int i = 0; i < this->getBarrels(); i++)
102  {
103    this->objComp[i] = new PNode* [this->getSegs()];
104    this->emissionPoint[i] = new PNode;
105    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
106    this->emissionPoint[i]->setName("EmissionPoint");
107    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
108    this->shootAnim[i] = new Animation3D* [this->getSegs()];
109    for(int j = 0; j < this->getSegs(); j++)
110    {
111      this->objComp[i][j] = new PNode;
112      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
113      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
114    }
115  }
116
117  for (int i = 0; i < this->getBarrels(); i++ )
118    this->emissionPoint[i]->setRelCoor(Vector(1.19, 0.0, 0.1));
119
120//   Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this);
121  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
122  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
123
124//   animation1->setInfinity(ANIM_INF_CONSTANT);
125  animation2->setInfinity(ANIM_INF_CONSTANT);
126  animation3->setInfinity(ANIM_INF_CONSTANT);
127
128//   this->setEmissionPoint(3.8, 1.2, 0);
129
130  for (int i = 0; i < this->getBarrels(); i++){
131    this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion(i * 120, Vector(1.0, 0.0, 0.0)), 0.049, ANIM_NULL, ANIM_LINEAR);
132    this->shootAnim[i][0]->addKeyFrame(Vector(), Quaternion((i+1)*120, Vector(1.0, 0.0, 0.0)), 0.001, ANIM_NULL, ANIM_LINEAR);
133  }
134
135
136  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
137  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
138
139  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
140  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
141}
142
143void LightBlaster::fire()
144{
145  Projectile* pj =  this->getProjectile();
146  if (pj == NULL)
147    return;
148
149  // set the owner
150  pj->setOwner(this->getOwner());
151
152  pj->setParent(PNode::getNullParent());
153
154//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
155  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180);
156
157  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
158  pj->setAbsDir(this->getAbsDir());
159//   pj->toList(OM_GROUP_01_PROJ);
160  pj->activate();
161
162  for (int i = 0; i < this->getSegs(); i++)
163    this->shootAnim[this->activeBarrel][i]->replay();
164
165  // switch barrel
166  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
167}
168
169/**
170 *  this activates the weapon
171*/
172void LightBlaster::activate()
173{
174}
175
176/**
177 *  this deactivates the weapon
178*/
179void LightBlaster::deactivate()
180{
181}
182
183void LightBlaster::draw() const
184{
185  glMatrixMode(GL_MODELVIEW);
186  glPushMatrix();
187    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
188    Vector tmpRot = this->getAbsDir().getSpacialAxis();
189    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
190    static_cast<StaticModel*>(this->getModel())->draw();
191  glPopMatrix();
192
193}
194
195void LightBlaster::tick(float dt)
196{
197  if (!Weapon::tickW(dt))
198    return;
199  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
200  {
201    this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png");
202    this->setEnergyWidgetInitialized(true);
203  }
204}
Note: See TracBrowser for help on using the repository browser.