Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/weapons/medium_blaster.cc @ 10286

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

code cleanup, rebuilt spikeball

File size: 5.6 KB
Line 
1#include "medium_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
13//#include "class_id_DEPRECATED.h"
14//ObjectListDefinition(MediumBlaster);
15CREATE_FACTORY(MediumBlaster);
16/**
17 * Standard constructor
18 */
19MediumBlaster::MediumBlaster ()
20 : Weapon()
21{
22    this->init();
23}
24
25MediumBlaster::MediumBlaster (const TiXmlElement* root = NULL)
26 : Weapon()
27{
28    this->init();
29    if (root != NULL)
30      this->loadParams(root);
31}
32
33/**
34 * Default destructor
35 */
36MediumBlaster::~MediumBlaster()
37{
38      // model will be deleted from WorldEntity-destructor
39  for (int i = 0; i < this->getBarrels(); i++)
40  {
41   delete [] this->shootAnim[i];
42//    delete [] this->objComp[i];
43  }
44  delete [] this->shootAnim;
45//   delete [] this->objComp;
46}
47
48void MediumBlaster::loadParams(const TiXmlElement* root)
49{
50  Weapon::loadParams(root);
51}
52
53void MediumBlaster::init()
54{
55  //this->registerObject(this, MediumBlaster::_objectList);
56
57//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
58
59  this->loadModel("models/guns/blaster.obj", .33);
60 
61
62  this->setStateDuration(WS_SHOOTING, 0.2);   // 5 Schuss pro Sekunde
63
64  this->setStateDuration(WS_RELOADING, 0);
65  this->setStateDuration(WS_ACTIVATING, .5); //.5);
66  this->setStateDuration(WS_DEACTIVATING, 1); // 1);
67
68  this->setEnergyMax(500);
69  this->increaseEnergy(500);
70  //this->minCharge = 2;
71
72  this->setActionSound(WA_SHOOT, "sound/laser.wav");
73  this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav");
74  this->setActionSound(WA_RELOAD, "sound/spawn/alien_generator.wav");
75
76  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
77  this->setProjectileTypeC("MBolt");   // FIXME temp project type until the blaste class exist
78  this->prepareProjectiles(100);
79
80
81  this->setBarrels(1);
82  this->setSegs(2);
83  this->activeBarrel = 0;
84
85  this->objComp = new PNode**[this->getBarrels()];
86//   this->emissionPoint = new PNode*[this->getBarrels()];
87  this->shootAnim = new Animation3D**[this->getBarrels()];
88  for (int i = 0; i < this->getBarrels(); i++)
89  {
90    this->objComp[i] = new PNode* [this->getSegs()];
91//     this->emissionPoint[i] = new PNode;
92//     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
93//     this->emissionPoint[i]->setName("EmissionPoint");
94//     this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
95    this->shootAnim[i] = new Animation3D* [this->getSegs()];
96    for(int j = 0; j < this->getSegs(); j++)
97    {
98      this->objComp[i][j] = new PNode;
99      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
100      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
101    }
102  }
103
104  for (int i = 0; i < this->getBarrels(); i++){
105    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
106    this->shootAnim[i][0]->addKeyFrame(Vector(-0.333, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
107    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
108
109    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
110    this->shootAnim[i][1]->addKeyFrame(Vector(.166, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
111    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
112  }
113
114  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
115  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
116
117  animation2->setInfinity(ANIM_INF_CONSTANT);
118  animation3->setInfinity(ANIM_INF_CONSTANT);
119
120
121  this->setEmissionPoint(1.3, 0, 0);
122
123  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
124  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
125
126  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
127  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
128}
129
130
131void MediumBlaster::fire()
132{
133  Projectile* pj =  this->getProjectile();
134  if (pj == NULL)
135    return;
136
137  // set the owner
138  pj->setOwner(this->getOwner());
139
140  pj->setParent(PNode::getNullParent());
141
142  pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160);
143
144  pj->setAbsCoor(this->getEmissionPoint());
145  pj->setAbsDir(this->getAbsDir());
146  pj->activate();
147
148  for (int i = 0; i < this->getSegs(); i++)
149    this->shootAnim[this->activeBarrel][i]->replay();
150}
151
152/**
153 *  this activates the weapon
154*/
155void MediumBlaster::activate()
156{
157}
158
159/**
160 *  this deactivates the weapon
161*/
162void MediumBlaster::deactivate()
163{
164}
165
166void MediumBlaster::draw() const
167{
168  glMatrixMode(GL_MODELVIEW);
169  glPushMatrix();
170  glTranslatef (this->getAbsCoor ().x,
171                this->getAbsCoor ().y,
172                this->getAbsCoor ().z);
173
174  static_cast<StaticModel*>(this->getModel())->draw(2);
175
176  glPushMatrix();
177    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
178    static_cast<StaticModel*>(this->getModel())->draw(1);
179  glPopMatrix();
180
181  glPushMatrix();
182  glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
183  static_cast<StaticModel*>(this->getModel())->draw(0);
184  glPopMatrix();
185
186  glPopMatrix();
187
188  glPopMatrix();
189}
Note: See TracBrowser for help on using the repository browser.