Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

some minor cleanup

File size: 4.2 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}
58
59void RFCannon::loadParams(const TiXmlElement* root)
60{
61  Weapon::loadParams(root);
62}
63
64void RFCannon::init()
65{
66  this->setScaling(.2);
67
68  this->loadModel("models/guns/rf_cannon.obj", this->getScaling());
69
70
71  this->setStateDuration(WS_SHOOTING, 0.1);  // 10 Schuss pro Sekunde
72  this->setStateDuration(WS_RELOADING, 0);
73  this->setStateDuration(WS_ACTIVATING, .5);
74  this->setStateDuration(WS_DEACTIVATING, 1);
75
76  this->setEnergyMax(500);
77  this->increaseEnergy(500);
78
79  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
80  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
81
82  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
83  this->setProjectileTypeC("PlasmaPulse");
84  this->prepareProjectiles(25);
85
86  this->setBarrels(4);
87//   this->setSegs(1);
88  this->setActiveBarrel(rand() % 4);
89
90
91  this->setEmissionPoint(Vector(4.1, 0.0, 0.75) * this->getScaling(), 0);
92  this->setEmissionPoint(Vector(4.1, 0.45, 0.0) * this->getScaling(), 1);
93  this->setEmissionPoint(Vector(4.1, 0.0, -0.75) * this->getScaling(), 2);
94  this->setEmissionPoint(Vector(4.1, -0.45, 0.0) * this->getScaling(), 3);
95
96  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
97  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
98
99  animation2->setInfinity(ANIM_INF_CONSTANT);
100  animation3->setInfinity(ANIM_INF_CONSTANT);
101
102  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
103  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
104
105  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
106  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
107}
108
109void RFCannon::fire()
110{
111  Projectile* pj =  this->getProjectile();
112  if (pj == NULL)
113    return;
114
115  // set the owner
116  pj->setOwner(this->getOwner());
117
118  pj->setParent(PNode::getNullParent());
119
120//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*190);
121  Vector tmp = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
122
123  pj->setVelocity(this->getParent()->getVelocity() + (tmp.getNormalized())*190);
124
125  pj->setAbsCoor(this->getEmissionPoint());
126  //FIXME pj needs a absDir
127//   pj->setAbsDir(this->getAbsDir());
128//   pj->setAbsDir(Quaternion(tmp.getNormalized(), this->getParent()->getAbsDir().apply(Vector(0,1,0))));
129
130  pj->activate();
131
132  this->cycleBarrel();
133}
134
135/**
136 *  this activates the weapon
137*/
138void RFCannon::activate()
139{
140}
141
142/**
143 *  this deactivates the weapon
144*/
145void RFCannon::deactivate()
146{
147}
148
149void RFCannon::draw() const
150{
151  glPushMatrix();
152    glMatrixMode(GL_MODELVIEW);
153    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
154    Vector tmpRot = this->getAbsDir().getSpacialAxis();
155    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
156    static_cast<StaticModel*>(this->getModel())->draw();
157  glPopMatrix();
158
159}
160
161void RFCannon::tick(float dt)
162{
163  if (!Weapon::tickW(dt))
164    return;
165  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
166  {
167    this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png");
168    this->setEnergyWidgetInitialized(true);
169  }
170}
Note: See TracBrowser for help on using the repository browser.