Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/world_entities/weapons/targeting_turret.cc @ 9558

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

orxonox/proxy: the rockets from the targeting turrets aquire targets as they are supposed, but they do not get fired unless the player is near of them… strangely

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