Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

bump

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