Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10260 was 10260, checked in by nicolasc, 17 years ago
File size: 4.0 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#include "world_entities/projectiles/spike.h"
23
24#include "model.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 "class_id_DEPRECATED.h"
38
39using namespace std;
40
41ObjectListDefinition(SpikeThrower);
42CREATE_FACTORY(SpikeThrower);
43
44/**
45 *  standard constructor
46 *
47 * creates a new SpikeThrower
48 */
49SpikeThrower::SpikeThrower()
50  : Weapon()
51{
52  this->init();
53}
54
55/**
56 * creates a new SpikeThrower from a TiXmlElement
57 */
58SpikeThrower::SpikeThrower(const TiXmlElement* root)
59{
60  this->init();
61  if (root != NULL)
62    this->loadParams(root);
63}
64
65/**
66 *  standard deconstructor
67*/
68SpikeThrower::~SpikeThrower ()
69{
70
71  // model will be deleted from WorldEntity-destructor
72}
73
74void SpikeThrower::init()
75{
76  this->registerObject(this, SpikeThrower::_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("SpikeBall");
100
101//   this->loadModel("models/guns/turret1.obj", 1.0);
102
103  this->setEmissionPoint(2, 0, 0);
104  this->getProjectileFactory()->prepare(50);
105
106//   this->setActionSound(WA_SHOOT, "sound/explosions/explosion_1.wav");
107//   this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
108//   this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
109
110}
111
112void SpikeThrower::loadParams(const TiXmlElement* root)
113{
114  Weapon::loadParams(root);
115}
116
117void SpikeThrower::activate()
118{
119}
120
121void SpikeThrower::deactivate()
122{
123}
124
125void SpikeThrower::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
147void SpikeThrower::fire()
148{
149  Projectile* pj =  this->getProjectile();
150  if (pj == NULL)
151    return;
152
153  // set the owner
154  pj->setOwner(this->getOwner());
155
156  pj->setParent(PNode::getNullParent());
157
158//   pj->setVelocity(this->getParent()->getAbsDir().apply(Vector(1,0,0))*200 + this->getParent()->getParent()->getVelocity());
159  pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160);
160
161  pj->setAbsCoor(this->getEmissionPoint());
162  pj->setAbsDir(this->getAbsDir());
163  pj->activate();
164}
Note: See TracBrowser for help on using the repository browser.