Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/weapons/spike_launcher.cc @ 10180

Last change on this file since 10180 was 10180, checked in by nicolasc, 14 years ago

bump

File size: 5.1 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 "spike_launcher.h"
18
19#include "weapon_manager.h"
20#include "world_entities/projectiles/projectile.h"
21#include "world_entities/projectiles/spike_ball.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 "class_id_DEPRECATED.h"
37
38using namespace std;
39
40ObjectListDefinition(SpikeLauncher);
41CREATE_FACTORY(SpikeLauncher);
42
43/**
44 *  standard constructor
45 *
46 * creates a new SpikeLauncher
47 */
48SpikeLauncher::SpikeLauncher()
49  : Weapon()
50{
51  this->init();
52}
53
54/**
55 * creates a new SpikeLauncher from a TiXmlElement
56 */
57SpikeLauncher::SpikeLauncher(const TiXmlElement* root)
58{
59  this->init();
60  if (root != NULL)
61    this->loadParams(root);
62}
63
64/**
65 *  standard deconstructor
66*/
67SpikeLauncher::~SpikeLauncher ()
68{
69  delete this->launcher;
70
71  // model will be deleted from WorldEntity-destructor
72}
73
74void SpikeLauncher::init()
75{
76  this->registerObject(this, SpikeLauncher::_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("Spike");
100
101//   this->loadModel("models/guns/turret1.obj", 1.0);
102  this->size = 2.5;
103
104  this->spikes = 26;
105  this->launcher = new Vector [this->spikes];
106
107  this->launcher[0] = Vector(1.0, 0.0, 0.0);
108  this->launcher[1] = Vector(0.0, 1.0, 0.0);
109  this->launcher[2] = Vector(0.0, 0.0, 1.0);
110
111  this->launcher[3] = Vector(1.0, 1.0, 0.0);
112  this->launcher[4] = Vector(0.0, 1.0, 1.0);
113  this->launcher[5] = Vector(1.0, 0.0, 1.0);
114  this->launcher[6] = Vector(1.0, -1.0, 0.0);
115  this->launcher[7] = Vector(0.0, 1.0, -1.0);
116  this->launcher[8] = Vector(-1.0, 0.0, 1.0);
117
118  this->launcher[9] = Vector(-1.0, 1.0, 1.0);
119  this->launcher[10] = Vector(1.0, 1.0, 1.0);
120  this->launcher[11] = Vector(1.0, -1.0, 1.0);
121  this->launcher[12] = Vector(-1.0, -1.0, 1.0);
122
123  int tmp = this->spikes / 2;
124  for (int i = 0; i < tmp; i++)
125  {
126    this->launcher[i].normalize();
127    this->launcher[tmp + i] =  this->launcher[i] * (-1);
128  }
129
130//   this->setEmissionPoint(1.684, 0.472, 0);
131  this->getProjectileFactory()->prepare(this->spikes);  //we don't need more...
132
133  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_1.wav");
134  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
135  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
136
137}
138
139void SpikeLauncher::loadParams(const TiXmlElement* root)
140{
141  Weapon::loadParams(root);
142}
143
144void SpikeLauncher::activate()
145{
146}
147
148void SpikeLauncher::deactivate()
149{
150}
151
152void SpikeLauncher::tick(float dt)
153{
154  if (!Weapon::tickW(dt))
155    return;
156
157  Quaternion quat;
158  Vector direction;
159  if (this->getDefaultTarget() == NULL)
160    direction = this->getAbsCoor();
161  else
162    direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
163
164  direction.normalize();
165
166  if (likely (this->getParent() != NULL))
167    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
168  else
169    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
170
171  this->setAbsDirSoft(quat, 5);
172}
173
174void SpikeLauncher::fire()
175{
176  Projectile* pj = NULL;
177//   for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++)
178  for (int i = 0; i < this->spikes; i++)
179  {
180    pj  = this->getProjectile();
181    if (pj == NULL) // if true, we do have a problem!!
182      return;
183
184//     pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*115.0 + VECTOR_RAND(10)));
185    pj->setVelocity(this->launcher[i] * 200.0);
186
187    pj->setParent(PNode::getNullParent());
188    pj->setAbsCoor(this->getAbsCoor() + this->launcher[i] * this->size);
189    pj->setAbsDir(Quaternion(this->launcher[i], 0));
190    pj->activate();
191  }
192}
Note: See TracBrowser for help on using the repository browser.