Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/weapons/swarm_missile.cc @ 10022

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

see changelog

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