Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/world_entities/weapons/targeting_turret.cc @ 9716

Last change on this file since 9716 was 9716, checked in by bensch, 18 years ago

more renamings

File size: 4.3 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 "projectiles/projectile.h"
20
21#include "model.h"
22
23#include "animation3d.h"
24
25#include "util/loading/load_param.h"
26#include "util/loading/factory.h"
27
28#include "class_id_DEPRECATED.h"
29ObjectListDefinitionID(TargetingTurret, CL_TARGETING_TURRET);
30CREATE_FACTORY(TargetingTurret);
31
32
33TargetingTurret::TargetingTurret(const TiXmlElement* root)
34  : target(this)
35{
36  this->init();
37  if( root != NULL)
38    this->loadParams(root);
39}
40
41/**
42 *  standard deconstructor
43*/
44TargetingTurret::~TargetingTurret ()
45{
46  // model will be deleted from WorldEntity-destructor
47//  delete this->target;
48}
49
50void TargetingTurret::init()
51{
52  this->registerObject(this, TargetingTurret::_objectList);
53
54  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
55  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
56
57  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
58  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
59  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
60  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
61
62  animation1->setInfinity(ANIM_INF_CONSTANT);
63  animation2->setInfinity(ANIM_INF_CONSTANT);
64
65  this->setStateDuration(WS_SHOOTING, .5);
66  this->setStateDuration(WS_RELOADING, 1.0);
67  this->setStateDuration(WS_ACTIVATING, .4);
68  this->setStateDuration(WS_DEACTIVATING, .4);
69
70  this->setEnergyMax(100);
71  this->increaseEnergy(100);
72
73  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
74  this->setProjectileTypeC("GuidedMissile");
75
76
77  this->setEmissionPoint(1.684, 0.472, 0);
78  //this->getProjectileFactory()->prepare(100);
79
80  this->target.setVisibility(false);
81  this->target.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT | PNODE_PROHIBIT_CHILD_DELETE);
82  this->target.setRange(1000);
83  this->target.setAngle(M_PI_4);
84  this->lockedTarget = &this->target;
85
86  this->lockedTime = 0;
87  this->neededLockTime = 2;
88  this->lockedTarget->setParent(PNode::getNullParent());
89  this->loadModel("models/guns/turret2.obj");
90
91
92  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_3.wav");
93  this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav");
94  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
95}
96
97void TargetingTurret::loadParams(const TiXmlElement* root)
98{
99  Weapon::loadParams(root);
100
101  LoadParam(root, "target-group", &target, Aim, setTargetGroupS);
102
103}
104
105void TargetingTurret::activate()
106{
107  // TODO move this back in
108  //this->target->setVisibility(true);
109}
110
111void TargetingTurret::deactivate()
112{
113  this->target.setVisibility(false);
114}
115
116void TargetingTurret::tick(float dt)
117{
118  if (!Weapon::tickW(dt))
119    return;
120
121  this->target.tick(dt);
122
123  if( lockedTime >= neededLockTime )
124   {
125    lockedTarget = this->target.getParent();
126    lockedTime = 0;
127   }
128
129
130  if(this->target.getParent() == PNode::getNullParent())
131   lockedTime = 0;
132  else
133   lockedTime += dt;
134
135}
136
137void TargetingTurret::fire()
138{
139  Projectile* pj = this->getProjectile();
140  if (pj == NULL)
141    return;
142
143  pj->setVelocity(this->getVelocity() + /*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
144            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
145
146  pj->setTarget(lockedTarget);
147  pj->setParent(PNode::getNullParent());
148  pj->setAbsCoor(this->getEmissionPoint());
149  pj->setAbsDir(this->getAbsDir());
150  pj->activate();
151}
152
153/**
154 * draws the TargetingTurret
155*/
156void TargetingTurret::draw () const
157{
158  /* draw gun body */
159  glMatrixMode(GL_MODELVIEW);
160  glPushMatrix();
161  glTranslatef (this->getAbsCoor ().x,
162                this->getAbsCoor ().y,
163                this->getAbsCoor ().z);
164  Vector tmpRot = this->getAbsDir().getSpacialAxis();
165  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
166  if (this->getModel() != NULL)
167    this->getModel()->draw();
168  glPopMatrix();
169}
170
Note: See TracBrowser for help on using the repository browser.