Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/world_entities/weapons/nadion_laser.cc @ 10678

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

modular weapons inclusion

File size: 4.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004-2006 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific
12   main-programmer: Marc Schaerrer, Nicolas Schlumberger
13   co-programmer:
14
15*/
16
17#include "nadion_laser.h"
18#include "world_entities/projectiles/projectile.h"
19
20#include "world_entity.h"
21#include "static_model.h"
22#include "weapon_manager.h"
23#include "util/loading/factory.h"
24
25#include "animation3d.h"
26
27#include "loading/fast_factory.h"
28
29#include "elements/glgui_energywidgetvertical.h"
30
31//
32ObjectListDefinition(NadionLaser);
33CREATE_FACTORY(NadionLaser);
34/**
35 * Standard constructor
36 */
37NadionLaser::NadionLaser ()
38 : Weapon()
39{
40    this->init();
41}
42
43NadionLaser::NadionLaser (const TiXmlElement* root = NULL)
44 : Weapon()
45{
46    this->init();
47    if (root != NULL)
48      this->loadParams(root);
49}
50
51/**
52 * Default destructor
53 */
54NadionLaser::~NadionLaser()
55{
56      // model will be deleted from WorldEntity-destructor
57  for (int i = 0; i < this->getBarrels(); i++)
58  {
59   delete [] this->shootAnim[i];
60  }
61  delete [] this->shootAnim;
62}
63
64void NadionLaser::loadParams(const TiXmlElement* root)
65{
66  Weapon::loadParams(root);
67}
68
69void NadionLaser::init()
70{
71  this->setScaling(.45);
72
73  this->loadModel("models/guns/nadion_laser.obj", this->getScaling());
74
75  this->setStateDuration(WS_SHOOTING, 0.1666);   // 6 Schuss pro Sekunde
76
77  this->setStateDuration(WS_RELOADING, 0);
78  this->setStateDuration(WS_ACTIVATING, .5);
79  this->setStateDuration(WS_DEACTIVATING, 1);
80
81  this->setEnergyMax(500);
82  this->increaseEnergy(500);
83  //this->minCharge = 2;
84
85  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
86//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
87  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
88
89  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
90  this->setProjectileTypeC("NadionBlast");   // FIXME temp projectile, until nadion_laser_bolt exists.
91  this->prepareProjectiles(20);
92
93
94  this->setBarrels(1);
95  this->setSegs(1);
96  this->activeBarrel = 0;
97
98  this->objComp = new PNode**[this->getBarrels()];
99  this->emissionPoint = new PNode*[this->getBarrels()];
100  this->shootAnim = new Animation3D**[this->getBarrels()];
101  for (int i = 0; i < this->getBarrels(); i++)
102  {
103    this->objComp[i] = new PNode* [this->getSegs()];
104    this->emissionPoint[i] = new PNode;
105    this->emissionPoint[i]->setParent(this);  //Parenting emissionPoint to Weapon
106    this->emissionPoint[i]->setName("EmissionPoint");
107    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
108    this->shootAnim[i] = new Animation3D* [this->getSegs()];
109    for(int j = 0; j < this->getSegs(); j++)
110    {
111      this->objComp[i][j] = new PNode;
112      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
113      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
114    }
115  }
116
117  this->emissionPoint[0]->setRelCoor(Vector(1.680, 0.0, 0.0) * this->getScaling());
118
119  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
120  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
121
122  animation2->setInfinity(ANIM_INF_CONSTANT);
123  animation3->setInfinity(ANIM_INF_CONSTANT);
124
125  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
126  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
127
128  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
129  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
130}
131
132
133void NadionLaser::fire()
134{
135  Projectile* pj =  this->getProjectile();
136  if (pj == NULL)
137    return;
138
139  // set the owner
140  pj->setOwner(this->getOwner());
141
142  pj->setParent(PNode::getNullParent());
143
144  pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160);
145
146  pj->setAbsCoor(this->getEmissionPoint());
147  pj->setAbsDir(this->getAbsDir());
148  pj->activate();
149
150}
151
152
153/**
154 *  this activates the weapon
155*/
156void NadionLaser::activate()
157{
158}
159
160/**
161 *  this deactivates the weapon
162*/
163void NadionLaser::deactivate()
164{
165}
166
167void NadionLaser::draw() const
168{
169  glMatrixMode(GL_MODELVIEW);
170  glPushMatrix();
171    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
172    Vector tmpRot = this->getAbsDir().getSpacialAxis();
173    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
174    static_cast<StaticModel*>(this->getModel())->draw();
175
176
177  glPopMatrix();
178}
179
180void NadionLaser::tick(float dt)
181{
182  if (!Weapon::tickW(dt))
183    return;
184  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
185  {
186    this->energyWidget->setDisplayedImage("textures/gui/gui_medium_bold.png");
187    this->setEnergyWidgetInitialized(true);
188  }
189}
Note: See TracBrowser for help on using the repository browser.