Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/weapons/targeting_turret.cc @ 6693

Last change on this file since 6693 was 6693, checked in by patrick, 18 years ago

branches: removed spaceshipcontrol branche

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 "targeting_turret.h"
18
19#include "weapon_manager.h"
20#include "aim.h"
21#include "world_entities/projectiles/projectile.h"
22
23#include "model.h"
24
25#include "animation3d.h"
26
27#include "factory.h"
28
29CREATE_FACTORY(TargetingTurret, CL_TARGETING_TURRET);
30
31using namespace std;
32
33
34/**
35 *  standard constructor
36
37   creates a new weapon
38*/
39TargetingTurret::TargetingTurret ()
40  : Weapon()
41{
42  this->init();
43
44}
45
46
47TargetingTurret::TargetingTurret(const TiXmlElement* root)
48{
49  this->init();
50  if( root != NULL)
51    this->loadParams(root);
52}
53
54/**
55 *  standard deconstructor
56*/
57TargetingTurret::~TargetingTurret ()
58{
59  // model will be deleted from WorldEntity-destructor
60//  delete this->target;
61}
62
63void TargetingTurret::init()
64{
65  this->setClassID(CL_TARGETING_TURRET, "TargetingTurret");
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, .1);
79  this->setStateDuration(WS_RELOADING, .1);
80  this->setStateDuration(WS_ACTIVATING, .4);
81  this->setStateDuration(WS_DEACTIVATING, .4);
82
83  this->setEnergyMax(10000);
84  this->increaseEnergy(100000);
85
86  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
87  this->setProjectileType(CL_GUIDED_MISSILE);
88
89
90  this->setEmissionPoint(1.684, 0.472, 0);
91  //this->getProjectileFactory()->prepare(100);
92
93  this->target = new Aim(this);
94  this->target->setVisibility(false);
95  this->target->setRange(100);
96  this->target->setAngle(M_PI_4/2);
97  this->lockedTime = 0;
98  this->neededLockTime = 2;
99  this->lockedTarget->setParent(PNode::getNullParent());
100  this->loadModel("models/guns/turret2.obj");
101
102
103  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
104  this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav");
105  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
106}
107
108void TargetingTurret::loadParams(const TiXmlElement* root)
109{
110  Weapon::loadParams(root);
111
112}
113
114void TargetingTurret::activate()
115{
116  this->target->setVisibility(true);
117}
118
119void TargetingTurret::deactivate()
120{
121  this->target->setVisibility(false);
122}
123
124void TargetingTurret::tick(float dt)
125{
126  if( lockedTime >= neededLockTime )
127   {
128    lockedTarget = this->target->getParent();
129    lockedTime = 0;
130   }
131
132  this->target->tick(dt);
133
134  if(this->target->getParent() == PNode::getNullParent())
135   lockedTime = 0;
136  else
137   lockedTime += dt;
138
139}
140
141void TargetingTurret::fire()
142{
143  Projectile* pj = this->getProjectile();
144  if (pj == NULL)
145    return;
146
147  pj->setVelocity(this->getVelocity() + /*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
148            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
149
150  pj->setTarget(this->target->getParent());
151  pj->setParent(PNode::getNullParent());
152  pj->setAbsCoor(this->getEmissionPoint());
153  pj->setAbsDir(this->getAbsDir());
154  pj->activate();
155  this->target->searchTarget();
156}
157
158void TargetingTurret::destroy ()
159{}
160
161/**
162 * draws the TargetingTurret
163*/
164void TargetingTurret::draw () const
165{
166  /* draw gun body */
167  glMatrixMode(GL_MODELVIEW);
168  glPushMatrix();
169  glTranslatef (this->getAbsCoor ().x,
170                this->getAbsCoor ().y,
171                this->getAbsCoor ().z);
172  Vector tmpRot = this->getAbsDir().getSpacialAxis();
173  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
174  if (this->getModel() != NULL)
175    this->getModel()->draw();
176  glPopMatrix();
177}
178
Note: See TracBrowser for help on using the repository browser.