Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

EOD commit

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