Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/weapons/heavy_blaster.cc @ 10271

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

working spikeballs

File size: 8.4 KB
Line 
1#include "heavy_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(HeavyBlaster);
14/**
15 * Standard constructor
16 */
17HeavyBlaster::HeavyBlaster (int leftRight)
18 : Weapon()
19{
20    this->init(leftRight);
21}
22
23HeavyBlaster::HeavyBlaster (const TiXmlElement* root = NULL)
24 : Weapon()
25{
26    // TODO add leftRight to params
27    this->init(0);
28    if (root != NULL)
29      this->loadParams(root);
30}
31
32/**
33 * Default destructor
34 */
35HeavyBlaster::~HeavyBlaster()
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    for(int j = 0; j < this->getSegs(); j++)
47    {
48      delete this->shootAnim[i][j];
49      delete this->objComp[i][j];
50    }
51    delete this->shootAnim[i];
52    delete this->objComp[i];
53    delete this->emissionPoint[i];
54  }*/
55
56//  this->deconstr();
57     // model will be deleted from WorldEntity-destructor
58}
59
60void HeavyBlaster::loadParams(const TiXmlElement* root)
61{
62  Weapon::loadParams(root);
63}
64
65void HeavyBlaster::init(int leftRight)
66{
67
68  this->leftRight = leftRight;
69  //this->registerObject(this, HeavyBlaster::_objectList);
70
71//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
72
73  this->loadModel("models/guns/fragcannon.obj", .4);
74 
75
76  this->setStateDuration(WS_SHOOTING, 0.5);   // 2 Schuss pro Sekunde
77  this->setStateDuration(WS_RELOADING, 0);
78  this->setStateDuration(WS_ACTIVATING, .5);
79  this->setStateDuration(WS_DEACTIVATING, 1);
80
81  this->setEnergyMax(500);
82  this->increaseEnergy(500);
83  //this->minCharge = 2;
84
85  this->setActionSound(WA_SHOOT, "sound/laser.wav");
86  this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav");
87  this->setActionSound(WA_RELOAD, "sound/spawn/alien_generator.wav");
88
89  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
90  this->setProjectileTypeC("HBolt");   // FIXME temp project type until the blaste class exist
91//   this->setProjectileTypeC("SpikeBall");   // FIXME temp project type until the blaste class exist
92  this->prepareProjectiles(5);
93
94  this->setBarrels(3);
95  this->setSegs(2);
96  this->activeBarrel = 0;
97//   this->init2();
98
99
100
101  this->objComp = new PNode**[this->getBarrels()];
102  this->emissionPoint = new PNode*[this->getBarrels()];
103  this->shootAnim = new Animation3D**[this->getBarrels()];
104  for (int i = 0; i < this->getBarrels(); i++)
105  {
106    this->objComp[i] = new PNode* [this->getSegs()];
107    this->emissionPoint[i] = new PNode;
108    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
109    this->emissionPoint[i]->setName("EmissionPoint");
110    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
111    this->shootAnim[i] = new Animation3D* [this->getSegs()];
112    for(int j = 0; j < this->getSegs(); j++)
113    {
114      this->objComp[i][j] = new PNode;
115      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
116      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
117    }
118  }
119
120  if (this->leftRight == W_RIGHT)
121  {
122    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, 0.06));
123    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, 0.14));
124    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, -.14));
125  }
126  else {
127    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, -.06));
128    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, -.14));
129    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, 0.14));
130  }
131
132
133//   Animation3D* animB0Shoot = this->getAnimation(WS_SHOOTING0, this->objComp[0][0]);
134//   Animation3D* animB1Shoot = this->getAnimation(WS_SHOOTING1, this->objComp2);
135//   Animation3D* animB2Shoot = this->getAnimation(WS_SHOOTING2, this->objComp3);
136//   Animation3D* animT0Shoot = this->getAnimation(WS_SHOOTING3, this->objComp[0][1]);
137//   Animation3D* animT1Shoot = this->getAnimation(WS_SHOOTING4, this->objComp5);
138//   Animation3D* animT2Shoot = this->getAnimation(WS_SHOOTING5, this->objComp6);
139
140
141//   this->shootAnim[0][0]->setInfinity(ANIM_INF_CONSTANT);
142//   animB1Shoot->setInfinity(ANIM_INF_CONSTANT);
143//   animB2Shoot->setInfinity(ANIM_INF_CONSTANT);
144//   animT0Shoot->setInfinity(ANIM_INF_CONSTANT);
145//   animT1Shoot->setInfinity(ANIM_INF_CONSTANT);
146//   animT2Shoot->setInfinity(ANIM_INF_CONSTANT);
147
148  for (int i = 0; i < this->getBarrels(); i++){
149    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
150    this->shootAnim[i][0]->addKeyFrame(Vector(-0.3, 0.0, 0.0), Quaternion(), 0.9, ANIM_LINEAR, ANIM_NULL);
151    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.55, ANIM_LINEAR, ANIM_NULL);
152
153    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
154    this->shootAnim[i][1]->addKeyFrame(Vector(-0.4, 0.0, 0.0), Quaternion(), 1.2, ANIM_LINEAR, ANIM_NULL);
155    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.25, ANIM_LINEAR, ANIM_NULL);
156  }
157
158  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
159  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
160
161  animation2->setInfinity(ANIM_INF_CONSTANT);
162  animation3->setInfinity(ANIM_INF_CONSTANT);
163
164//   this->setEmissionPoint(3.8, 1.2, 0, 0);
165
166  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
167  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
168
169  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
170  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
171}
172
173
174void HeavyBlaster::fire()
175{
176  Projectile* pj =  this->getProjectile();
177  if (pj == NULL)
178    return;
179
180  // set the owner
181  pj->setOwner(this->getOwner());
182  pj->setParent(PNode::getNullParent());
183
184//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
185//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
186  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
187
188  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
189//   pj->setAbsCoor(this->getEmissionPoint(0));
190  pj->setAbsDir(this->getAbsDir());
191//   pj->toList(OM_GROUP_01_PROJ);
192  pj->activate();
193
194  // initiate animation
195  for (int i = 0; i < this->getSegs(); i++)
196    this->shootAnim[this->activeBarrel][i]->replay();
197
198  // switch barrel
199  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
200}
201
202/**
203 *  this activates the weapon
204*/
205void HeavyBlaster::activate()
206{
207}
208
209/**
210 *  this deactivates the weapon
211*/
212void HeavyBlaster::deactivate()
213{
214}
215
216
217void HeavyBlaster::draw() const
218{
219  glMatrixMode(GL_MODELVIEW);
220  glPushMatrix();
221  glTranslatef (this->getAbsCoor ().x,
222                this->getAbsCoor ().y,
223                this->getAbsCoor ().z);
224
225  if (this->leftRight == W_LEFT)
226    glScalef(1.0, 1.0, -1.0);
227
228  static_cast<StaticModel*>(this->getModel())->draw(6);
229
230  glPushMatrix();
231    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
232    static_cast<StaticModel*>(this->getModel())->draw(1);
233  glPopMatrix();
234
235  glPushMatrix();
236  glTranslatef (this->objComp[1][0]->getAbsCoor().x, this->objComp[1][0]->getAbsCoor().y, this->objComp[1][0]->getAbsCoor().z);
237  static_cast<StaticModel*>(this->getModel())->draw(2);
238  glPopMatrix();
239
240  glPushMatrix();
241  glTranslatef (this->objComp[2][0]->getAbsCoor().x, this->objComp[2][0]->getAbsCoor().y, this->objComp[2][0]->getAbsCoor().z);
242  static_cast<StaticModel*>(this->getModel())->draw(0);
243  glPopMatrix();
244
245  glPushMatrix();
246  glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
247    static_cast<StaticModel*>(this->getModel())->draw(4);
248  glPopMatrix();
249
250  glPushMatrix();
251  glTranslatef (this->objComp[1][1]->getAbsCoor().x, this->objComp[1][1]->getAbsCoor().y, this->objComp[1][1]->getAbsCoor().z);
252  static_cast<StaticModel*>(this->getModel())->draw(5);
253  glPopMatrix();
254
255  glPushMatrix();
256  glTranslatef (this->objComp[2][1]->getAbsCoor().x, this->objComp[2][1]->getAbsCoor().y, this->objComp[2][1]->getAbsCoor().z);
257  static_cast<StaticModel*>(this->getModel())->draw(3);
258  glPopMatrix();
259
260  glPopMatrix();
261}
Note: See TracBrowser for help on using the repository browser.