Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

bump

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