Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

data bump

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:  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  Projectile* pj =  this->getProjectile();
129  if (pj == NULL)
130    return;
131
132  // set the owner
133  pj->setOwner(this->getOwner());
134
135  pj->setParent(PNode::getNullParent());
136
137//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*190);
138  Vector tmp = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
139
140  pj->setVelocity(this->getParent()->getVelocity() + (tmp.getNormalized())*190);
141
142  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
143//   pj->setAbsDir(this->getAbsDir());
144//   pj->setAbsDir(Quaternion(tmp.getNormalized(), this->getParent()->getAbsDir().apply(Vector(0,1,0))));
145
146  pj->activate();
147
148  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
149}
150
151/**
152 *  this activates the weapon
153*/
154void RFCannon::activate()
155{
156}
157
158/**
159 *  this deactivates the weapon
160*/
161void RFCannon::deactivate()
162{
163}
164
165void RFCannon::draw() const
166{
167  glPushMatrix();
168    glMatrixMode(GL_MODELVIEW);
169    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
170    Vector tmpRot = this->getAbsDir().getSpacialAxis();
171    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
172    static_cast<StaticModel*>(this->getModel())->draw();
173  glPopMatrix();
174
175}
176
177void RFCannon::tick(float dt)
178{
179  if (!Weapon::tickW(dt))
180    return;
181  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
182  {
183    this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png");
184    this->setEnergyWidgetInitialized(true);
185  }
186}
Note: See TracBrowser for help on using the repository browser.