Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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