Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

bump

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