Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/rf_cannon.cc @ 10701

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

minor improvements, some cleanup

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  this->setScaling(.2);
72
73  this->loadModel("models/guns/rf_cannon.obj", this->getScaling());
74
75
76  this->setStateDuration(WS_SHOOTING, 0.1);  // 10 Schuss pro Sekunde
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
84  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
85  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
86
87  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
88  this->setProjectileTypeC("PlasmaPulse");
89  this->prepareProjectiles(25);
90
91  this->setBarrels(4);
92  this->setSegs(1);
93  this->activeBarrel = (rand() % 4);
94
95  this->objComp = new PNode**[this->getBarrels()];
96  this->emissionPoint = new PNode*[this->getBarrels()];
97  for (int i = 0; i < this->getBarrels(); i++) {
98    this->objComp[i] = new PNode* [this->getSegs()];
99    this->emissionPoint[i] = new PNode;
100    this->emissionPoint[i]->setParent(this);
101    this->emissionPoint[i]->setName("EmissionPoint");
102    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
103    for(int j = 0; j < this->getSegs(); j++) {
104      this->objComp[i][j] = new PNode;
105    }
106  }
107
108  this->emissionPoint[0]->setRelCoor(Vector(4.1, 0.0, 0.75) * this->getScaling());
109  this->emissionPoint[1]->setRelCoor(Vector(4.1, 0.45, 0.0) * this->getScaling());
110  this->emissionPoint[2]->setRelCoor(Vector(4.1, 0.0, -0.75) * this->getScaling());
111  this->emissionPoint[3]->setRelCoor(Vector(4.1, -0.45, 0.0) * this->getScaling());
112
113  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
114  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
115
116  animation2->setInfinity(ANIM_INF_CONSTANT);
117  animation3->setInfinity(ANIM_INF_CONSTANT);
118
119  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
120  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
121
122  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
123  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
124}
125
126void RFCannon::fire()
127{
128//   for (int i = 0; i < this->getBarrels(); i++){
129    Projectile* pj =  this->getProjectile();
130    if (pj == NULL)
131      return;
132
133    // set the owner
134    pj->setOwner(this->getOwner());
135
136    pj->setParent(PNode::getNullParent());
137
138    pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*190);
139
140    pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
141    pj->setAbsDir(this->getAbsDir());
142    pj->activate();
143
144    this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
145//   }
146}
147
148/**
149 *  this activates the weapon
150*/
151void RFCannon::activate()
152{
153}
154
155/**
156 *  this deactivates the weapon
157*/
158void RFCannon::deactivate()
159{
160}
161
162void RFCannon::draw() const
163{
164  glMatrixMode(GL_MODELVIEW);
165  glPushMatrix();
166    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
167    Vector tmpRot = this->getAbsDir().getSpacialAxis();
168    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
169    static_cast<StaticModel*>(this->getModel())->draw();
170  glPopMatrix();
171
172}
173
174void RFCannon::tick(float dt)
175{
176  if (!Weapon::tickW(dt))
177    return;
178  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
179  {
180    this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png");
181    this->setEnergyWidgetInitialized(true);
182  }
183}
Note: See TracBrowser for help on using the repository browser.