Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

EOD commit

File size: 4.5 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  // model will be deleted from WorldEntity-destructor
70}
71
72void SpikeLauncher::init()
73{
74  this->registerObject(this, SpikeLauncher::_objectList);
75
76  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
77  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
78
79  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
80  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
81  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
82  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
83
84  animation1->setInfinity(ANIM_INF_CONSTANT);
85  animation2->setInfinity(ANIM_INF_CONSTANT);
86
87  this->setStateDuration(WS_SHOOTING, .6);
88  this->setStateDuration(WS_RELOADING, 1.0f);
89  this->setStateDuration(WS_ACTIVATING, .4);
90  this->setStateDuration(WS_DEACTIVATING, .4);
91
92  this->setEnergyMax(10);
93  this->increaseEnergy(10);
94  //this->minCharge = 2;
95
96  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
97  this->setProjectileTypeC("SpikeBall");
98
99  this->loadModel("models/guns/turret1.obj", 1.0);
100
101  this->setEmissionPoint(1.684, 0.472, 0);
102  this->getProjectileFactory()->prepare(50);
103
104  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_1.wav");
105  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
106  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
107
108}
109
110void SpikeLauncher::loadParams(const TiXmlElement* root)
111{
112  Weapon::loadParams(root);
113}
114
115void SpikeLauncher::activate()
116{
117}
118
119void SpikeLauncher::deactivate()
120{
121}
122
123void SpikeLauncher::tick(float dt)
124{
125  if (!Weapon::tickW(dt))
126    return;
127
128  Quaternion quat;
129  Vector direction;
130  if (this->getDefaultTarget() == NULL)
131    direction = this->getAbsCoor();
132  else
133    direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
134
135  direction.normalize();
136
137  if (likely (this->getParent() != NULL))
138    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
139  else
140    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
141
142  this->setAbsDirSoft(quat, 5);
143}
144
145void SpikeLauncher::fire()
146{
147  bool fired  = false;
148
149  Projectile* pj = NULL;
150  for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++)
151  {
152    if( ((*eIterator)->getOMListNumber() == OM_GROUP_00) && ((*eIterator)->getClassCName() != "Weapon") && ((*eIterator)->getClassCName() != "Projectile") && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 300)
153    {
154      pj  = this->getProjectile();
155      if (pj == NULL)
156        return;
157     
158      fired = true;
159      pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*115.0 + VECTOR_RAND(10)));
160
161      pj->setParent(PNode::getNullParent());
162      pj->setAbsCoor(this->getEmissionPoint());
163      pj->setAbsDir(this->getAbsDir());
164//       dynamic_cast<SpikeProjectile*>(pj)->setTarget( (PNode*)(*eIterator) );
165      pj->toList(OM_GROUP_01_PROJ);
166      pj->activate();
167    }
168  }
169  if( !fired)
170    this->increaseEnergy( this->getProjectile()->getMinEnergy());
171}
Note: See TracBrowser for help on using the repository browser.