Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/rf_cannon.cc @ 10766

Last change on this file since 10766 was 10698, checked in by snellen, 18 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 4.7 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:  Nicolas Schlumberger
13   co-programmer:
14
15*/
16
17#include "rf_cannon.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(RFCannon);
33CREATE_FACTORY(RFCannon);
34
35/**
36 * Standard constructor
37 */
38RFCannon::RFCannon ()
39 : Weapon()
40{
41    this->init();
42}
43
44RFCannon::RFCannon (const TiXmlElement* root = NULL)
45 : Weapon()
46{
47    this->init();
48    if (root != NULL)
49      this->loadParams(root);
50}
51
52/**
53 * Default destructor
54 */
55RFCannon::~RFCannon()
56{
57  for (int i = 0; i < this->getBarrels(); i++)
58    delete [] this->objComp[i];
59
60  delete [] this->emissionPoint;
61  delete [] this->objComp;
62}
63
64void RFCannon::loadParams(const TiXmlElement* root)
65{
66  Weapon::loadParams(root);
67}
68
69void RFCannon::init()
70{
71
72  this->setScaling(.2);
73
74  this->loadModel("models/guns/rf_cannon.obj", this->getScaling());
75
76
77  this->setStateDuration(WS_SHOOTING, 0.1);  // 10 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
85  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
86  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
87
88  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
89  this->setProjectileTypeC("PlasmaPulse");
90  this->prepareProjectiles(25);
91
92  this->setBarrels(4);
93  this->setSegs(1);
94  this->activeBarrel = 0;
95
96  this->objComp = new PNode**[this->getBarrels()];
97  this->emissionPoint = new PNode*[this->getBarrels()];
98  for (int i = 0; i < this->getBarrels(); i++) {
99    this->objComp[i] = new PNode* [this->getSegs()];
100    this->emissionPoint[i] = new PNode;
101    this->emissionPoint[i]->setParent(this);
102    this->emissionPoint[i]->setName("EmissionPoint");
103    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
104    for(int j = 0; j < this->getSegs(); j++) {
105      this->objComp[i][j] = new PNode;
106    }
107  }
108
109  this->emissionPoint[0]->setRelCoor(Vector(4.1, 0.0, 0.75) * this->getScaling());
110  this->emissionPoint[1]->setRelCoor(Vector(4.1, 0.45, 0.0) * this->getScaling());
111  this->emissionPoint[2]->setRelCoor(Vector(4.1, 0.0, -0.75) * this->getScaling());
112  this->emissionPoint[3]->setRelCoor(Vector(4.1, -0.45, 0.0) * this->getScaling());
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  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
121  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
122
123  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
124  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
125}
126
127void RFCannon::fire()
128{
129//   for (int i = 0; i < this->getBarrels(); i++){
130    Projectile* pj =  this->getProjectile();
131    if (pj == NULL)
132      return;
133
134    // set the owner
135    pj->setOwner(this->getOwner());
136
137    pj->setParent(PNode::getNullParent());
138
139    pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*190);
140
141    pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
142    pj->setAbsDir(this->getAbsDir());
143    pj->activate();
144
145    this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
146//   }
147}
148
149/**
150 *  this activates the weapon
151*/
152void RFCannon::activate()
153{
154}
155
156/**
157 *  this deactivates the weapon
158*/
159void RFCannon::deactivate()
160{
161}
162
163void RFCannon::draw() const
164{
165  glMatrixMode(GL_MODELVIEW);
166  glPushMatrix();
167    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
168    Vector tmpRot = this->getAbsDir().getSpacialAxis();
169    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
170    static_cast<StaticModel*>(this->getModel())->draw();
171  glPopMatrix();
172
173}
174
175void RFCannon::tick(float dt)
176{
177  if (!Weapon::tickW(dt))
178    return;
179  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
180  {
181    this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png");
182    this->setEnergyWidgetInitialized(true);
183  }
184}
Note: See TracBrowser for help on using the repository browser.