Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

bump

File size: 3.8 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 "util/loading/factory.h"
28
29#include "class_id_DEPRECATED.h"
30
31ObjectListDefinitionID(SwarmLauncher, CL_SWARM_LAUNCHER);
32CREATE_FACTORY(SwarmLauncher);
33
34/**
35 *  standard constructor
36 *
37 * creates a new SwarmLauncher
38 */
39SwarmLauncher::SwarmLauncher()
40  : Weapon()
41{
42  this->init();
43}
44
45/**
46 * creates a new SwarmLauncher from a TiXmlElement
47 */
48SwarmLauncher::SwarmLauncher(const TiXmlElement* root)
49{
50  this->init();
51  if (root != NULL)
52    this->loadParams(root);
53}
54
55/**
56 *  standard deconstructor
57*/
58SwarmLauncher::~SwarmLauncher ()
59{
60  // model will be deleted from WorldEntity-destructor
61}
62
63void SwarmLauncher::init()
64{
65  this->registerObject(this, SwarmLauncher::_objectList);
66
67  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
68  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
69
70  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
71  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
72  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
73  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
74
75  animation1->setInfinity(ANIM_INF_CONSTANT);
76  animation2->setInfinity(ANIM_INF_CONSTANT);
77
78  this->setStateDuration(WS_SHOOTING, .6);
79  this->setStateDuration(WS_RELOADING, 1.0f);
80  this->setStateDuration(WS_ACTIVATING, .4);
81  this->setStateDuration(WS_DEACTIVATING, .4);
82
83  this->setEnergyMax(10);
84  this->increaseEnergy(10);
85  //this->minCharge = 2;
86
87  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
88  this->setProjectileTypeC("SwarmProjectile");
89
90  this->loadModel("models/guns/turret1.obj", 1.0);
91
92  this->setEmissionPoint(1.684, 0.472, 0);
93  this->getProjectileFactory()->prepare(5);
94
95  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_1.wav");
96  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
97  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
98
99}
100
101void SwarmLauncher::loadParams(const TiXmlElement* root)
102{
103  Weapon::loadParams(root);
104}
105
106void SwarmLauncher::activate()
107{
108}
109
110void SwarmLauncher::deactivate()
111{
112}
113
114void SwarmLauncher::tick(float dt)
115{
116  if (!Weapon::tickW(dt))
117    return;
118
119  Quaternion quat;
120  Vector direction;
121  if (this->getDefaultTarget() == NULL)
122    direction = this->getAbsCoor();
123  else
124    direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
125
126  direction.normalize();
127
128  if (likely (this->getParent() != NULL))
129    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
130  else
131    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
132
133  this->setAbsDirSoft(quat, 5);
134}
135
136void SwarmLauncher::fire()
137{
138  Projectile* pj = this->getProjectile();
139  if (pj == NULL)
140    return;
141
142  pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*165.0 /*+ VECTOR_RAND(13) */
143            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
144
145  pj->setParent(PNode::getNullParent());
146  pj->setAbsCoor(this->getEmissionPoint());
147  pj->setAbsDir(this->getAbsDir());
148  pj->activate();
149}
Note: See TracBrowser for help on using the repository browser.