Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/heavy_blaster.cc @ 10509

Last change on this file since 10509 was 10499, checked in by patrick, 18 years ago

enable ai and weapon stuff

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