Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/world_entities/weapons/rf_cannon.cc @ 10645

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

minor cleanup

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