Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/weapons/swarm_launcher.cc @ 10078

Last change on this file since 10078 was 10078, checked in by marcscha, 18 years ago

Update in swarm launcher, swarm missile, mbolt

File size: 4.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 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: Benjamin Grauer
13   co-programmer:
14*/
15//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
16
17#include "swarm_launcher.h"
18
19#include "weapon_manager.h"
20#include "world_entities/projectiles/projectile.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 "math/quaternion.h"
32
33#include "util/loading/factory.h"
34
35#include "class_id_DEPRECATED.h"
36
37using namespace std;
38
39ObjectListDefinitionID(SwarmLauncher, CL_SWARM_LAUNCHER);
40CREATE_FACTORY(SwarmLauncher);
41
42/**
43 *  standard constructor
44 *
45 * creates a new SwarmLauncher
46 */
47SwarmLauncher::SwarmLauncher()
48  : Weapon()
49{
50  this->init();
51}
52
53/**
54 * creates a new SwarmLauncher from a TiXmlElement
55 */
56SwarmLauncher::SwarmLauncher(const TiXmlElement* root)
57{
58  this->init();
59  if (root != NULL)
60    this->loadParams(root);
61}
62
63/**
64 *  standard deconstructor
65*/
66SwarmLauncher::~SwarmLauncher ()
67{
68  // model will be deleted from WorldEntity-destructor
69}
70
71void SwarmLauncher::init()
72{
73  this->registerObject(this, SwarmLauncher::_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, .6);
87  this->setStateDuration(WS_RELOADING, 1.0f);
88  this->setStateDuration(WS_ACTIVATING, .4);
89  this->setStateDuration(WS_DEACTIVATING, .4);
90
91  this->setEnergyMax(10);
92  this->increaseEnergy(10);
93  //this->minCharge = 2;
94
95  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
96  this->setProjectileTypeC("SwarmProjectile");
97
98  this->loadModel("models/guns/turret1.obj", 1.0);
99
100  this->setEmissionPoint(1.684, 0.472, 0);
101  this->getProjectileFactory()->prepare(5);
102
103  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_1.wav");
104  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
105  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
106
107}
108
109void SwarmLauncher::loadParams(const TiXmlElement* root)
110{
111  Weapon::loadParams(root);
112}
113
114void SwarmLauncher::activate()
115{
116}
117
118void SwarmLauncher::deactivate()
119{
120}
121
122void SwarmLauncher::tick(float dt)
123{
124  if (!Weapon::tickW(dt))
125    return;
126
127  Quaternion quat;
128  Vector direction;
129  if (this->getDefaultTarget() == NULL)
130    direction = this->getAbsCoor();
131  else
132    direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
133
134  direction.normalize();
135
136  if (likely (this->getParent() != NULL))
137    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
138  else
139    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
140
141  this->setAbsDirSoft(quat, 5);
142}
143
144void SwarmLauncher::fire()
145{
146  Projectile* pj = NULL;
147  for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++)
148  {
149    if( ((*eIterator)->getOMListNumber() == OM_GROUP_00) && ((*eIterator)->getClassCName() != "Weapon") && ((*eIterator)->getClassCName() != "Projectile") && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 100)
150    {
151      pj  = this->getProjectile();
152      if (pj == NULL)
153        return;
154          pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*165.0 + VECTOR_RAND(20)));
155       
156          pj->setParent( PNode::getNullParent());
157          pj->setAbsCoor( this->getEmissionPoint());
158          pj->setAbsDir( this->getAbsDir());
159          pj->setTarget( *eIterator);
160          pj->activate();
161    }
162  }
163}
Note: See TracBrowser for help on using the repository browser.