Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cleanup/src/world_entities/weapons/acid_launcher.cc

Last change on this file was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 4.2 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 "acid_launcher.h"
18
19#include "weapon_manager.h"
20#include "world_entities/projectiles/acid_splash.h"
21
22#include "model.h"
23
24#include "state.h"
25#include "animation3d.h"
26
27#include <list>
28#include <iterator>
29#include "util/state.h"
30
31#include "util/loading/factory.h"
32
33#include "elements/glgui_energywidgetvertical.h"
34
35
36
37using namespace std;
38
39ObjectListDefinition ( AcidLauncher );
40CREATE_FACTORY ( AcidLauncher );
41
42/**
43 *  standard constructor
44 *
45 * creates a new AcidLauncher
46 */
47AcidLauncher::AcidLauncher()
48    : Weapon()
49{
50  this->init();
51}
52
53/**
54 * creates a new AcidLauncher from a TiXmlElement
55 */
56AcidLauncher::AcidLauncher ( const TiXmlElement* root )
57{
58  this->init();
59  if ( root != NULL )
60    this->loadParams ( root );
61}
62
63/**
64 *  standard deconstructor
65*/
66AcidLauncher::~AcidLauncher ()
67{
68  // model will be deleted from WorldEntity-destructor
69}
70
71void AcidLauncher::init()
72{
73  this->registerObject ( this, AcidLauncher::_objectList );
74  /*
75    Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
76    Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
77
78    animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
79    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
80    animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
81    animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
82
83    animation1->setInfinity(ANIM_INF_CONSTANT);
84    animation2->setInfinity(ANIM_INF_CONSTANT);
85  */
86  this->setStateDuration ( WS_SHOOTING, 1.0f );
87
88  this->setStateDuration ( WS_RELOADING, 1.0f );
89  this->setStateDuration ( WS_ACTIVATING, .4 );
90  this->setStateDuration ( WS_DEACTIVATING, .4 );
91
92  this->setEnergyMax ( 100 );
93  this->increaseEnergy ( 100 );
94  //this->minCharge = 2;
95
96  this->setCapability ( WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT );
97  this->setProjectileTypeC ( "AcidSplash" );
98//   this->loadModel("models/guns/turret1.obj", 1.0);
99
100  this->setEmissionPoint ( 2.0, 0, 0 );
101  this->getProjectileFactory()->prepare ( 10 );
102
103  this->setActionSound ( WA_SHOOT, "sounds/explosions/explosion_1.wav" );
104  this->setActionSound ( WA_ACTIVATE, "sounds/voices/rockets.wav" );
105//   this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav");
106
107}
108
109void AcidLauncher::loadParams ( const TiXmlElement* root )
110{
111  Weapon::loadParams ( root );
112}
113
114void AcidLauncher::activate()
115{}
116
117void AcidLauncher::deactivate()
118{}
119
120void AcidLauncher::tick ( float dt )
121{
122  if ( !Weapon::tickW ( dt ) )
123    return;
124  if ( this->energyWidget != NULL && !this->isEnergyWidgetInitialized ) {
125    this->energyWidget->setDisplayedImage ( "textures/gui/gui_acid.png" );
126    this->isEnergyWidgetInitialized = true;
127  }
128
129
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}
148
149void AcidLauncher::fire()
150{
151  bool fired  = false;
152
153  Projectile* pj = NULL;
154  for ( int i=0; i < 1; i++ ) {
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 ) ) *165.0 + VECTOR_RAND ( 10 ) ) );
161
162    pj->setParent ( PNode::getNullParent() );
163    pj->setAbsCoor ( this->getEmissionPoint() + VECTOR_RAND ( .1 ) );
164    pj->setAbsDir ( this->getAbsDir() +Quaternion ( 0,VECTOR_RAND ( 5 ) ) );
165    pj->activate();
166  }
167}
Note: See TracBrowser for help on using the repository browser.