Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/weapons/light_blaster.cc @ 10484

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

tmp xfer

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