Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability.old/src/world_entities/weapons/medium_blaster.cc @ 10627

Last change on this file since 10627 was 10289, checked in by nicolasc, 18 years ago

clenup

File size: 4.9 KB
Line 
1#include "medium_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 "class_id_DEPRECATED.h"
14//ObjectListDefinition(MediumBlaster);
15CREATE_FACTORY(MediumBlaster);
16/**
17 * Standard constructor
18 */
19MediumBlaster::MediumBlaster ()
20 : Weapon()
21{
22    this->init();
23}
24
25MediumBlaster::MediumBlaster (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 */
36MediumBlaster::~MediumBlaster()
37{
38      // model will be deleted from WorldEntity-destructor
39  for (int i = 0; i < this->getBarrels(); i++)
40  {
41   delete [] this->shootAnim[i];
42  }
43  delete [] this->shootAnim;
44}
45
46void MediumBlaster::loadParams(const TiXmlElement* root)
47{
48  Weapon::loadParams(root);
49}
50
51void MediumBlaster::init()
52{
53  this->loadModel("models/guns/blaster.obj", .33);
54
55  this->setStateDuration(WS_SHOOTING, 0.2);   // 5 Schuss pro Sekunde
56
57  this->setStateDuration(WS_RELOADING, 0);
58  this->setStateDuration(WS_ACTIVATING, .5); //.5);
59  this->setStateDuration(WS_DEACTIVATING, 1); // 1);
60
61  this->setEnergyMax(500);
62  this->increaseEnergy(500);
63  //this->minCharge = 2;
64
65  this->setActionSound(WA_SHOOT, "sound/laser.wav");
66  this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav");
67  this->setActionSound(WA_RELOAD, "sound/spawn/alien_generator.wav");
68
69  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
70  this->setProjectileTypeC("MBolt");   // FIXME temp project type until the blaste class exist
71  this->prepareProjectiles(100);
72
73
74  this->setBarrels(1);
75  this->setSegs(2);
76  this->activeBarrel = 0;
77
78  this->objComp = new PNode**[this->getBarrels()];
79  this->shootAnim = new Animation3D**[this->getBarrels()];
80  for (int i = 0; i < this->getBarrels(); i++)
81  {
82    this->objComp[i] = new PNode* [this->getSegs()];
83    this->shootAnim[i] = new Animation3D* [this->getSegs()];
84    for(int j = 0; j < this->getSegs(); j++)
85    {
86      this->objComp[i][j] = new PNode;
87      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
88      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
89    }
90  }
91
92  for (int i = 0; i < this->getBarrels(); i++){
93    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
94    this->shootAnim[i][0]->addKeyFrame(Vector(-0.333, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
95    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
96
97    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
98    this->shootAnim[i][1]->addKeyFrame(Vector(.166, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
99    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
100  }
101
102  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
103  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
104
105  animation2->setInfinity(ANIM_INF_CONSTANT);
106  animation3->setInfinity(ANIM_INF_CONSTANT);
107
108
109  this->setEmissionPoint(1.3, 0, 0);
110
111  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
112  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
113
114  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
115  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
116}
117
118
119void MediumBlaster::fire()
120{
121  Projectile* pj =  this->getProjectile();
122  if (pj == NULL)
123    return;
124
125  // set the owner
126  pj->setOwner(this->getOwner());
127
128  pj->setParent(PNode::getNullParent());
129
130  pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160);
131
132  pj->setAbsCoor(this->getEmissionPoint());
133  pj->setAbsDir(this->getAbsDir());
134  pj->activate();
135
136  for (int i = 0; i < this->getSegs(); i++)
137    this->shootAnim[this->activeBarrel][i]->replay();
138}
139
140/**
141 *  this activates the weapon
142*/
143void MediumBlaster::activate()
144{
145}
146
147/**
148 *  this deactivates the weapon
149*/
150void MediumBlaster::deactivate()
151{
152}
153
154void MediumBlaster::draw() const
155{
156  glMatrixMode(GL_MODELVIEW);
157  glPushMatrix();
158  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
159
160  static_cast<StaticModel*>(this->getModel())->draw(2);
161
162  glPushMatrix();
163    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
164    static_cast<StaticModel*>(this->getModel())->draw(1);
165  glPopMatrix();
166
167  glPushMatrix();
168    glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
169    static_cast<StaticModel*>(this->getModel())->draw(0);
170  glPopMatrix();
171
172  glPopMatrix();
173}
Note: See TracBrowser for help on using the repository browser.