Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/blink/src/world_entities/weapons/heavy_blaster.cc @ 10648

Last change on this file since 10648 was 10415, checked in by patrick, 18 years ago

changed the path names to reflect the new data repos

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