Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/swarm_launcher.cc @ 10535

Last change on this file since 10535 was 10533, checked in by patrick, 18 years ago

rotor flimmer fix

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: Marc Schaerrer
13   co-programmer:
14*/
15//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
16
17#include "swarm_launcher.h"
18
19#include "weapon_manager.h"
20#include "world_entities/projectiles/projectile.h"
21#include "world_entities/projectiles/swarm_projectile.h"
22
23#include "model.h"
24
25#include "state.h"
26#include "animation3d.h"
27
28#include <list>
29#include <iterator>
30#include "util/state.h"
31
32#include "math/quaternion.h"
33
34#include "util/loading/factory.h"
35
36#include "elements/glgui_energywidgetvertical.h"
37
38
39
40using namespace std;
41
42ObjectListDefinition(SwarmLauncher);
43CREATE_FACTORY(SwarmLauncher);
44
45/**
46 *  standard constructor
47 *
48 * creates a new SwarmLauncher
49 */
50SwarmLauncher::SwarmLauncher()
51  : Weapon()
52{
53  this->init();
54}
55
56/**
57 * creates a new SwarmLauncher from a TiXmlElement
58 */
59SwarmLauncher::SwarmLauncher(const TiXmlElement* root)
60{
61  this->init();
62  if (root != NULL)
63    this->loadParams(root);
64}
65
66/**
67 *  standard deconstructor
68*/
69SwarmLauncher::~SwarmLauncher ()
70{
71  // model will be deleted from WorldEntity-destructor
72}
73
74void SwarmLauncher::init()
75{
76  this->registerObject(this, SwarmLauncher::_objectList);
77
78  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
79  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
80
81  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
82  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
83  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
84  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
85
86  animation1->setInfinity(ANIM_INF_CONSTANT);
87  animation2->setInfinity(ANIM_INF_CONSTANT);
88
89  this->setStateDuration(WS_SHOOTING, .6);
90  this->setStateDuration(WS_RELOADING, 1.0f);
91  this->setStateDuration(WS_ACTIVATING, .4);
92  this->setStateDuration(WS_DEACTIVATING, .4);
93
94  this->setEnergyMax(10);
95  this->increaseEnergy(10);
96  //this->minCharge = 2;
97
98  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
99  this->setProjectileTypeC("SwarmProjectile");
100
101  this->loadModel("models/guns/turret1.obj", 1.0);
102
103  this->setEmissionPoint(1.684, 0.472, 0);
104  this->getProjectileFactory()->prepare(50);
105
106  this->setActionSound(WA_SHOOT, "sounds/explosions/explosion_1.wav");
107  this->setActionSound(WA_ACTIVATE, "sounds/voices/rockets.wav");
108  this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav");
109
110}
111
112void SwarmLauncher::loadParams(const TiXmlElement* root)
113{
114  Weapon::loadParams(root);
115}
116
117void SwarmLauncher::activate()
118{
119}
120
121void SwarmLauncher::deactivate()
122{
123}
124
125void SwarmLauncher::tick(float dt)
126{
127  if (!Weapon::tickW(dt))
128    return;
129
130  Quaternion quat;
131  Vector direction;
132  if (this->getDefaultTarget() == NULL)
133    direction = this->getAbsCoor();
134  else
135    direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
136
137  direction.normalize();
138
139  if (likely (this->getParent() != NULL))
140    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
141  else
142    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
143
144  this->setAbsDirSoft(quat, 5);
145
146  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
147  {
148    this->energyWidget->setDisplayedImage("textures/gui/gui_swarm_missiles.png");
149    this->setEnergyWidgetInitialized(true);
150  }
151}
152
153void SwarmLauncher::fire()
154{
155  bool fired  = false;
156
157  PRINTF(0)("fire\n");
158  Projectile* pj = NULL;
159  for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++)
160  {
161    if( ((*eIterator)->getOMListNumber() != (this->getOMListNumber() -1)) && ((*eIterator)->getClassCName() != "Weapon") && ((*eIterator)->getClassCName() != "Projectile") && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 300)
162    {
163      pj  = this->getProjectile();
164      if (pj == NULL)
165        return;
166
167      fired = true;
168      pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*115.0 + VECTOR_RAND(10)));
169
170      pj->setParent(PNode::getNullParent());
171      pj->setAbsCoor(this->getEmissionPoint());
172      pj->setAbsDir(this->getAbsDir());
173      dynamic_cast<SwarmProjectile*>(pj)->setTarget( (PNode*)(*eIterator) );
174      //pj->toList(OM_GROUP_01_PROJ);
175      pj->activate();
176    }
177  }
178  if( !fired)
179    this->increaseEnergy( this->getProjectile()->getMinEnergy());
180}
Note: See TracBrowser for help on using the repository browser.