Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/scriptimprovements/src/world_entities/weapons/swarm_launcher.cc @ 10562

Last change on this file since 10562 was 10545, checked in by marcscha, 18 years ago

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