Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/disruptor.cc @ 10771

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

huge diff
cleaned the individual weapons, moved stuff to weapon.{cc,h}
and some minor fixes which popped up then and when

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 "disruptor.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
31ObjectListDefinition(Disruptor);
32CREATE_FACTORY(Disruptor);
33
34/**
35 * Standard constructor
36 */
37Disruptor::Disruptor ()
38 : Weapon()
39{
40    this->init();
41}
42
43Disruptor::Disruptor (const TiXmlElement* root = NULL)
44 : Weapon()
45{
46    // TODO add leftRight to params
47    this->init();
48    if (root != NULL)
49      this->loadParams(root);
50}
51
52/**
53 * Default destructor
54 */
55Disruptor::~Disruptor()
56{
57}
58
59void Disruptor::loadParams(const TiXmlElement* root)
60{
61  Weapon::loadParams(root);
62}
63
64void Disruptor::init()
65{
66
67  this->setScaling(.5);
68
69  this->loadModel("models/guns/disruptor.obj", this->getScaling());
70
71
72  this->setStateDuration(WS_SHOOTING, 0.3333);  // 3 Shots per Second
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  //this->minCharge = 2;
80
81  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
82//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
83  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
84
85  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
86  this->setProjectileTypeC("HBolt");
87  this->prepareProjectiles(10);
88
89  this->setBarrels(1);
90  this->setSegs(1);
91
92  this->setEmissionPoint(Vector(1.672, 0.0, 0.0) * this->getScaling());
93
94  this->getShootAnim(0, 0)->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
95  this->getShootAnim(0, 0)->addKeyFrame(Vector(-0.5, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL);
96//   this->shootAnim[0][0]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
97
98  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
99  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
100
101  animation2->setInfinity(ANIM_INF_CONSTANT);
102  animation3->setInfinity(ANIM_INF_CONSTANT);
103
104  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
105  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
106
107  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
108  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
109}
110
111
112void Disruptor::fire()
113{
114  Projectile* pj =  this->getProjectile();
115  if (pj == NULL)
116    return;
117
118  // set the owner
119  pj->setOwner(this->getOwner());
120  pj->setParent(PNode::getNullParent());
121
122  Vector tmp = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
123
124//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
125  pj->setVelocity((tmp.getNormalized())*130 + VECTOR_RAND(1));
126
127  pj->setAbsCoor(this->getEmissionPoint());
128  pj->setAbsDir(this->getAbsDir());
129  pj->activate();
130
131
132  this->getShootAnim(0, 0)->replay();
133}
134
135/**
136 *  this activates the weapon
137*/
138void Disruptor::activate()
139{
140}
141
142/**
143 *  this deactivates the weapon
144*/
145void Disruptor::deactivate()
146{
147}
148
149
150void Disruptor::draw() const
151{
152  glPushMatrix();
153    glMatrixMode(GL_MODELVIEW);
154    glTranslatef (this->getAbsCoor ().x,
155                  this->getAbsCoor ().y,
156                  this->getAbsCoor ().z);
157      Vector tmpRot = this->getAbsDir().getSpacialAxis();
158      glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
159
160    //Base
161    static_cast<StaticModel*>(this->getModel())->draw(1);
162
163    // Barrel
164    glPushMatrix();
165      glTranslatef(this->getObjCompx(0,0), this->getObjCompy(0,0), this->getObjCompz(0,0));
166      static_cast<StaticModel*>(this->getModel())->draw(0);
167    glPopMatrix();
168
169  glPopMatrix();
170}
171
172void Disruptor::tick(float dt)
173{
174  if (!Weapon::tickW(dt))
175    return;
176  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
177  {
178    this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png");
179    this->setEnergyWidgetInitialized(true);
180  }
181}
Note: See TracBrowser for help on using the repository browser.