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
RevLine 
[9972]1#include "heavy_blaster.h"
[9975]2#include "world_entities/projectiles/projectile.h"
[9972]3
[9975]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 */
[10152]17HeavyBlaster::HeavyBlaster (int leftRight)
[9975]18 : Weapon()
19{
[10152]20    this->init(leftRight);
[9975]21}
22
[9972]23HeavyBlaster::HeavyBlaster (const TiXmlElement* root = NULL)
24 : Weapon()
[9975]25{
[10152]26    // TODO add leftRight to params
27    this->init(0);
[9972]28    if (root != NULL)
29      this->loadParams(root);
[9975]30}
[9972]31
32/**
33 * Default destructor
34 */
35HeavyBlaster::~HeavyBlaster()
[9975]36{
[10152]37  this->deconstr();
38     // model will be deleted from WorldEntity-destructor
[9975]39}
[9972]40
[9975]41void HeavyBlaster::loadParams(const TiXmlElement* root)
42{
43  Weapon::loadParams(root);
44}
[9972]45
[10152]46void HeavyBlaster::init(int leftRight)
[9975]47{
[10152]48
49  this->leftRight = leftRight;
[9975]50  //this->registerObject(this, HeavyBlaster::_objectList);
51
52//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
53
[10133]54  this->loadModel("models/guns/fragcannon.obj", .4);
[9975]55 
56
[9998]57  this->setStateDuration(WS_SHOOTING, 0.5);   // 2 Schuss pro Sekunde
[9975]58  this->setStateDuration(WS_RELOADING, 0);
59  this->setStateDuration(WS_ACTIVATING, .5);
60  this->setStateDuration(WS_DEACTIVATING, 1);
61
[9998]62  this->setEnergyMax(500);
63  this->increaseEnergy(500);
[9975]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);
[9979]71  this->setProjectileTypeC("HBolt");   // FIXME temp project type until the blaste class exist
[9998]72  this->prepareProjectiles(5);
[9975]73
[10136]74  this->setBarrels(3);
75  this->setSegs(2);
[10152]76  this->activeBarrel = 0;
77//   this->init2();
[10136]78
[10133]79
[10152]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
[10159]100  if (this->leftRight == W_RIGHT)
101  {
[10152]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));
[10159]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  }
[10152]111
112
113//   Animation3D* animB0Shoot = this->getAnimation(WS_SHOOTING0, this->objComp[0][0]);
[10136]114//   Animation3D* animB1Shoot = this->getAnimation(WS_SHOOTING1, this->objComp2);
115//   Animation3D* animB2Shoot = this->getAnimation(WS_SHOOTING2, this->objComp3);
[10152]116//   Animation3D* animT0Shoot = this->getAnimation(WS_SHOOTING3, this->objComp[0][1]);
[10136]117//   Animation3D* animT1Shoot = this->getAnimation(WS_SHOOTING4, this->objComp5);
118//   Animation3D* animT2Shoot = this->getAnimation(WS_SHOOTING5, this->objComp6);
[10133]119
[10152]120
121//   this->shootAnim[0][0]->setInfinity(ANIM_INF_CONSTANT);
[10136]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);
[10133]127
[10152]128  for (int i = 0; i < this->getBarrels(); i++){
[10159]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);
[10133]132
[10159]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);
[10152]136  }
[10133]137
[9975]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
[10152]144//   this->setEmissionPoint(3.8, 1.2, 0, 0);
[9975]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
[10044]164//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
[10046]165//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
[10044]166  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
[9975]167
[10152]168  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
169//   pj->setAbsCoor(this->getEmissionPoint(0));
[9975]170  pj->setAbsDir(this->getAbsDir());
[10152]171//   pj->toList(OM_GROUP_01_PROJ);
[9975]172  pj->activate();
[10152]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();
[9975]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
[10152]196
[9975]197void HeavyBlaster::draw() const
198{
[10133]199  glMatrixMode(GL_MODELVIEW);
200  glPushMatrix();
201  glTranslatef (this->getAbsCoor ().x,
202                this->getAbsCoor ().y,
203                this->getAbsCoor ().z);
204
[10152]205  if (this->leftRight == W_LEFT)
206    glScalef(1.0, 1.0, -1.0);
207
[10133]208  static_cast<StaticModel*>(this->getModel())->draw(6);
209
210  glPushMatrix();
[10152]211    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
[10136]212    static_cast<StaticModel*>(this->getModel())->draw(1);
[10152]213  glPopMatrix();
[10136]214
[10133]215  glPushMatrix();
[10152]216  glTranslatef (this->objComp[1][0]->getAbsCoor().x, this->objComp[1][0]->getAbsCoor().y, this->objComp[1][0]->getAbsCoor().z);
[10133]217  static_cast<StaticModel*>(this->getModel())->draw(2);
218  glPopMatrix();
219
220  glPushMatrix();
[10152]221  glTranslatef (this->objComp[2][0]->getAbsCoor().x, this->objComp[2][0]->getAbsCoor().y, this->objComp[2][0]->getAbsCoor().z);
[10133]222  static_cast<StaticModel*>(this->getModel())->draw(0);
[10152]223  glPopMatrix();
[10136]224
[10133]225  glPushMatrix();
[10152]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);
[10133]232  static_cast<StaticModel*>(this->getModel())->draw(5);
233  glPopMatrix();
234
235  glPushMatrix();
[10152]236  glTranslatef (this->objComp[2][1]->getAbsCoor().x, this->objComp[2][1]->getAbsCoor().y, this->objComp[2][1]->getAbsCoor().z);
[10133]237  static_cast<StaticModel*>(this->getModel())->draw(3);
[10152]238  glPopMatrix();
[10133]239
240  glPopMatrix();
[9975]241}
Note: See TracBrowser for help on using the repository browser.