Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/world_entities/weapons/targeting_turret.cc @ 10761

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

merged network back to trunk

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